src/vs/platform/agentHost/node/codex/codexUserInputMapper.ts
87 LOC · 87 covered · 0 uncovered · 17 ranges · 33 concepts · 7 introducers · 17 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
codexUserInputMapper.ts ×4
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ChatInputAnswerState, ChatInputAnswerValueKind, ChatInputQuestionKind, ChatInputResponseKind, type ChatInputAnswer, type ChatInputQuestion, type ChatInputRequest } from '../../common/state/sessionState.js';
import type { ToolRequestUserInputAnswer } from './protocol/generated/v2/ToolRequestUserInputAnswer.js';
import type { ToolRequestUserInputQuestion } from './protocol/generated/v2/ToolRequestUserInputQuestion.js';
import type { ToolRequestUserInputResponse } from './protocol/generated/v2/ToolRequestUserInputResponse.js';
/**
* Translate codex `request_user_input` (the model's `ask_user`) questions into
* an agent-host {@link ChatInputRequest}. Questions with options become a
* single-select (with freeform allowed when codex marks `isOther`); option-less
* questions become a free text question. Codex options have no stable id, so
* the option label doubles as the id.
*/
export function buildUserInputRequest(requestId: string, questions: readonly ToolRequestUserInputQuestion[]): ChatInputRequest {
id: requestId,
questions: questions.map((q): ChatInputQuestion => {
if (q.options && q.options.length > 0) {
return {
kind: ChatInputQuestionKind.SingleSelect,
id: q.id,
title: q.header,
message: q.question,
required: true,
options: q.options.map(o => ({ id: o.label, label: o.label, description: o.description || undefined })),
allowFreeformInput: q.isOther,
};
}
return {
kind: ChatInputQuestionKind.Text,
id: q.id,
title: q.header,
message: q.question,
required: true,
};
}),
};
}
/**
* Build the codex `request_user_input` response from the client's answers.
* Codex expects an answer (a string array) per question id; a declined/cancelled
* request or a skipped/missing answer yields an empty array for that question.
*/
export function userInputResponseFromAnswers(
response: ChatInputResponseKind,
answers: Record<string, ChatInputAnswer> | undefined,
): ToolRequestUserInputResponse {
const out: Record<string, ToolRequestUserInputAnswer> = {};
for (const q of questions) {
out[q.id] = { answers: answerStrings(answers?.[q.id], response) };
}
return { answers: out };
}
/** Response with empty answers for every question (used when there is no session to ask). */
export function emptyUserInputResponse(questions: readonly ToolRequestUserInputQuestion[]): ToolRequestUserInputResponse {
for (const q of questions) {
out[q.id] = { answers: [] };
}
return { answers: out };
}
/** Flatten a single chat input answer into the string array codex expects. */
export function answerStrings(answer: ChatInputAnswer | undefined, response: ChatInputResponseKind): string[] {
if (response !== ChatInputResponseKind.Accept || !answer || answer.state === ChatInputAnswerState.Skipped) {
codexUserInputMapper.ts ×5
}
switch (value.kind) {
case ChatInputAnswerValueKind.Text:
return [value.value];
case ChatInputAnswerValueKind.Boolean:
}