1
>
/*---------------------------------------------------------------------------------------------
codexElicitationMapper.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { hasKey } from '../../../../base/common/types.js';
7
>
import { ChatInputAnswerState, ChatInputAnswerValueKind, ChatInputQuestionKind, ChatInputResponseKind, type ChatInputAnswer, type ChatInputOption, type ChatInputQuestion, type ChatInputRequest } from '../../common/state/sessionState.js';
8
>
import type { JsonValue } from './protocol/generated/serde_json/JsonValue.js';
9
>
import type { McpElicitationPrimitiveSchema } from './protocol/generated/v2/McpElicitationPrimitiveSchema.js';
10
>
import type { McpServerElicitationRequestParams } from './protocol/generated/v2/McpServerElicitationRequestParams.js';
11
>
import type { McpServerElicitationRequestResponse } from './protocol/generated/v2/McpServerElicitationRequestResponse.js';
12
>
13
>
/**
14
>
* Translate a codex `mcpServer/elicitation/request` into an agent-host
15
>
* {@link ChatInputRequest}. Three modes are supported, mirroring the MCP
16
>
* elicitation spec:
17
>
*
18
>
* - `form` — projects each field of the requested JSON schema into a
19
>
* {@link ChatInputQuestion} (text / number / boolean / single- or
20
>
* multi-select), reusing the same chat-input surface as the model's
21
>
* `ask_user` tool.
22
>
* - `openai/form` — carries an opaque, OpenAI-specific form schema we
23
>
* cannot project into typed questions; surfaces the message only so the
24
>
* user can still accept or decline.
25
>
* - `url` — surfaces the URL the server wants the user to open via
26
>
* {@link ChatInputRequest.url} with no questions.
27
>
*
28
>
* MCP field names are used directly as the stable question id (the key
29
>
* the answer map is later read back by).
30
>
*/
31
>
export function buildElicitationRequest(requestId: string, params: McpServerElicitationRequestParams): ChatInputRequest {
32
if (params.mode === 'url') {
33
const request: ChatInputRequest = { id: requestId, message: params.message };