MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / outcomeToQuestionAnswer

Function outcomeToQuestionAnswer

packages/acp-adapter/src/question.ts:81–99  ·  view source on GitHub ↗
(
  question: QuestionItem,
  response: RequestPermissionResponse,
)

Source from the content-addressed store, hash-verified

79 * options surfaced by the client.
80 */
81export function outcomeToQuestionAnswer(
82 question: QuestionItem,
83 response: RequestPermissionResponse,
84): QuestionAnswers | null {
85 if (response.outcome.outcome === 'cancelled') return null;
86 const optionId = response.outcome.optionId;
87 // Skip — explicit dismissal path; treat the same as `cancelled`.
88 if (optionId === skipOptionId(0)) return null;
89 // Selected option — parse the `q0_opt_<i>` shape and look up the
90 // matching label. Reject anything that does not match the namespace
91 // (or whose index is out of bounds) defensively rather than crashing.
92 const match = /^q0_opt_(\d+)$/.exec(optionId);
93 if (!match) return null;
94 const optionIndex = Number(match[1]);
95 if (!Number.isInteger(optionIndex) || optionIndex < 0) return null;
96 const selected = question.options[optionIndex];
97 if (!selected) return null;
98 return { [question.question]: selected.label };
99}

Callers 2

question.test.tsFile · 0.90
handleQuestionMethod · 0.90

Calls 2

skipOptionIdFunction · 0.85
execMethod · 0.65

Tested by

no test coverage detected