{"version":3,"file":"responses.cjs","names":["generateToolCallId","generateId","calculateDelay","delay","flattenHeaders","getContext","getTestId","matchFixtureDiagnostic","recordMatchOptions","applyChaos","resolveStrictMode","strictNoMatchMessage","strictNoMatchLogLine","strictOverrideField","proxyAndRecord","resolveResponse","isErrorResponse","serializeErrorResponse","isContentWithToolCallsResponse","extractOverrides","resolveReasoningForModel","createInterruptionSignal","isTextResponse","isToolCallResponse"],"sources":["../src/responses.ts"],"sourcesContent":["/**\n * OpenAI Responses API support for aimock.\n *\n * Translates incoming /v1/responses requests into the ChatCompletionRequest\n * format used by the fixture router, and converts fixture responses back into\n * the Responses API streaming (or non-streaming) format expected by @ai-sdk/openai.\n */\n\nimport type * as http from \"node:http\";\nimport type {\n  ChatCompletionRequest,\n  ChatMessage,\n  Fixture,\n  HandlerDefaults,\n  ResponseOverrides,\n  StreamingProfile,\n  ToolCall,\n  ToolDefinition,\n} from \"./types.js\";\nimport {\n  generateId,\n  generateToolCallId,\n  extractOverrides,\n  isTextResponse,\n  isToolCallResponse,\n  isContentWithToolCallsResponse,\n  isErrorResponse,\n  serializeErrorResponse,\n  flattenHeaders,\n  getTestId,\n  resolveResponse,\n  resolveStrictMode,\n  resolveReasoningForModel,\n  strictOverrideField,\n  getContext,\n  strictNoMatchMessage,\n  strictNoMatchLogLine,\n} from \"./helpers.js\";\nimport { matchFixtureDiagnostic, recordMatchOptions } from \"./router.js\";\nimport { writeErrorResponse, delay, calculateDelay } from \"./sse-writer.js\";\nimport { createInterruptionSignal } from \"./interruption.js\";\nimport type { RecordedTimings } from \"./types.js\";\nimport type { Journal } from \"./journal.js\";\nimport { applyChaos } from \"./chaos.js\";\nimport { proxyAndRecord } from \"./recorder.js\";\n\n// ─── Responses API request types ────────────────────────────────────────────\n\ninterface ResponsesInputItem {\n  role?: string;\n  type?: string;\n  content?: string | ResponsesContentPart[];\n  call_id?: string;\n  name?: string;\n  arguments?: string;\n  output?: string;\n  id?: string;\n}\n\ninterface ResponsesContentPart {\n  type: string;\n  text?: string;\n}\n\ninterface ResponsesRequest {\n  model: string;\n  input: string | ResponsesInputItem[];\n  instructions?: string;\n  tools?: ResponsesToolDef[];\n  tool_choice?: string | object;\n  stream?: boolean;\n  temperature?: number;\n  max_output_tokens?: number;\n  response_format?: { type: string; [key: string]: unknown };\n  [key: string]: unknown;\n}\n\ninterface ResponsesToolDef {\n  type: \"function\";\n  name: string;\n  description?: string;\n  parameters?: object;\n  strict?: boolean;\n}\n\n// ─── Input conversion: Responses → ChatCompletions messages ─────────────────\n\nfunction extractTextContent(content: string | ResponsesContentPart[] | undefined): string {\n  if (!content) return \"\";\n  if (typeof content === \"string\") return content;\n  return content\n    .filter((p) => p.type === \"input_text\" || p.type === \"output_text\")\n    .map((p) => p.text ?? \"\")\n    .join(\"\");\n}\n\nexport function responsesInputToMessages(req: ResponsesRequest): ChatMessage[] {\n  const messages: ChatMessage[] = [];\n  // Track item_reference placeholders so we can upgrade or clean them up\n  const itemReferencePlaceholders = new WeakSet<ChatMessage>();\n\n  // instructions field → system message\n  if (req.instructions) {\n    messages.push({ role: \"system\", content: req.instructions });\n  }\n\n  // The OpenAI Responses API accepts either a plain string or an array of input items.\n  // When a string is passed, treat it as a single user message.\n  if (typeof req.input === \"string\") {\n    messages.push({ role: \"user\", content: req.input });\n    return messages;\n  }\n\n  for (const item of req.input) {\n    if (item.role === \"system\" || item.role === \"developer\") {\n      messages.push({ role: \"system\", content: extractTextContent(item.content) });\n    } else if (item.role === \"user\") {\n      messages.push({ role: \"user\", content: extractTextContent(item.content) });\n    } else if (item.role === \"assistant\") {\n      messages.push({ role: \"assistant\", content: extractTextContent(item.content) });\n    } else if (item.type === \"function_call\") {\n      // Previous assistant tool call — emit as assistant message with tool_calls\n      messages.push({\n        role: \"assistant\",\n        content: null,\n        tool_calls: [\n          {\n            id: item.call_id ?? generateToolCallId(),\n            type: \"function\",\n            function: { name: item.name ?? \"\", arguments: item.arguments ?? \"\" },\n          },\n        ],\n      });\n    } else if (item.type === \"function_call_output\") {\n      // Bug 1 fix: If there's no preceding assistant message with a matching\n      // tool_call for this call_id, synthesize one. This happens when the AI SDK\n      // sends [user, item_reference, function_call_output] — the item_reference\n      // placeholder (see below) has no tool_calls, so we need a real assistant\n      // message with the tool_call for turnIndex counting.\n      const hasMatchingToolCall = messages.some(\n        (m) => m.role === \"assistant\" && m.tool_calls?.some((tc) => tc.id === item.call_id),\n      );\n      if (!hasMatchingToolCall) {\n        // Check if the last message is an item_reference placeholder — if so,\n        // upgrade it to carry the tool_call instead of synthesizing a duplicate.\n        const lastMsg = messages[messages.length - 1];\n        if (\n          lastMsg &&\n          lastMsg.role === \"assistant\" &&\n          itemReferencePlaceholders.has(lastMsg) &&\n          !lastMsg.tool_calls\n        ) {\n          lastMsg.content = null;\n          lastMsg.tool_calls = [\n            {\n              id: item.call_id ?? generateToolCallId(),\n              type: \"function\",\n              function: { name: \"\", arguments: \"\" },\n            },\n          ];\n          itemReferencePlaceholders.delete(lastMsg);\n        } else {\n          // Multi-fco case: look for a recent assistant with tool_calls that\n          // belongs to the same turn. After the first fco upgrades a placeholder,\n          // subsequent fco's see [assistant(call_A), tool(call_A)] — the last\n          // assistant with tool_calls (right before the trailing tool messages)\n          // is the correct target.\n          let appended = false;\n          for (let k = messages.length - 1; k >= 0; k--) {\n            const m = messages[k];\n            if (m.role === \"assistant\" && m.tool_calls) {\n              m.tool_calls.push({\n                id: item.call_id ?? generateToolCallId(),\n                type: \"function\",\n                function: { name: \"\", arguments: \"\" },\n              });\n              appended = true;\n              break;\n            }\n            // Stop scanning if we hit a user message — different turn\n            if (m.role === \"user\") break;\n          }\n          if (!appended) {\n            messages.push({\n              role: \"assistant\",\n              content: null,\n              tool_calls: [\n                {\n                  id: item.call_id ?? generateToolCallId(),\n                  type: \"function\",\n                  function: { name: \"\", arguments: \"\" },\n                },\n              ],\n            });\n          }\n        }\n      }\n      messages.push({\n        role: \"tool\",\n        content: item.output ?? \"\",\n        tool_call_id: item.call_id,\n      });\n    } else if (item.type === \"item_reference\") {\n      // Bug 6 fix: item_reference items represent prior assistant turns (text\n      // or function_call). Push a placeholder so they count in assistantCount.\n      // If a subsequent function_call_output arrives, the handler above will\n      // upgrade this placeholder to carry tool_calls (avoiding double-count).\n      const placeholder: ChatMessage = { role: \"assistant\", content: \"\" };\n      itemReferencePlaceholders.add(placeholder);\n      messages.push(placeholder);\n    } else {\n      // Skip local_shell_call, mcp_list_tools, etc. — not needed for fixture\n      // matching.\n    }\n  }\n\n  return messages;\n}\n\nfunction responsesToolsToCompletionsTools(\n  tools?: ResponsesToolDef[],\n): ToolDefinition[] | undefined {\n  if (!tools || tools.length === 0) return undefined;\n  return tools\n    .filter((t) => t.type === \"function\")\n    .map((t) => ({\n      type: \"function\" as const,\n      function: { name: t.name, description: t.description, parameters: t.parameters },\n    }));\n}\n\nexport function responsesToCompletionRequest(req: ResponsesRequest): ChatCompletionRequest {\n  return {\n    model: req.model,\n    messages: responsesInputToMessages(req),\n    stream: req.stream,\n    temperature: req.temperature,\n    max_tokens: req.max_output_tokens,\n    tools: responsesToolsToCompletionsTools(req.tools),\n    tool_choice: req.tool_choice,\n    response_format: req.response_format,\n  };\n}\n\n// ─── Response building: fixture → Responses API format ──────────────────────\n\nfunction responsesStatus(finishReason: string | undefined, defaultStatus: string): string {\n  if (!finishReason) return defaultStatus;\n  if (finishReason === \"stop\") return \"completed\";\n  if (finishReason === \"tool_calls\") return \"completed\";\n  if (finishReason === \"length\") return \"incomplete\";\n  if (finishReason === \"content_filter\") return \"failed\";\n  return finishReason;\n}\n\nfunction responsesUsage(overrides?: ResponseOverrides): {\n  input_tokens: number;\n  output_tokens: number;\n  total_tokens: number;\n} {\n  if (!overrides?.usage) return { input_tokens: 0, output_tokens: 0, total_tokens: 0 };\n  const input = overrides.usage.input_tokens ?? overrides.usage.prompt_tokens ?? 0;\n  const output = overrides.usage.output_tokens ?? overrides.usage.completion_tokens ?? 0;\n  return {\n    input_tokens: input,\n    output_tokens: output,\n    total_tokens: overrides.usage.total_tokens ?? input + output,\n  };\n}\n\nfunction responseId(): string {\n  return generateId(\"resp\");\n}\n\nfunction itemId(): string {\n  return generateId(\"msg\");\n}\n\n// Streaming events for Responses API\n\nexport interface ResponsesSSEEvent {\n  type: string;\n  [key: string]: unknown;\n}\n\nexport function buildTextStreamEvents(\n  content: string,\n  model: string,\n  chunkSize: number,\n  reasoning?: string,\n  webSearches?: string[],\n  overrides?: ResponseOverrides,\n): ResponsesSSEEvent[] {\n  const { respId, created, events, prefixOutputItems, nextOutputIndex } = buildResponsePreamble(\n    model,\n    chunkSize,\n    reasoning,\n    webSearches,\n    overrides,\n  );\n\n  const { events: msgEvents, msgItem } = buildMessageOutputEvents(\n    content,\n    chunkSize,\n    nextOutputIndex,\n  );\n  events.push(...msgEvents);\n\n  events.push({\n    type: \"response.completed\",\n    response: {\n      id: respId,\n      object: \"response\",\n      created_at: created,\n      model: overrides?.model ?? model,\n      status: responsesStatus(overrides?.finishReason, \"completed\"),\n      output: [...prefixOutputItems, msgItem],\n      usage: responsesUsage(overrides),\n    },\n  });\n\n  return events;\n}\n\nexport function buildToolCallStreamEvents(\n  toolCalls: ToolCall[],\n  model: string,\n  chunkSize: number,\n  reasoning?: string,\n  webSearches?: string[],\n  overrides?: ResponseOverrides,\n): ResponsesSSEEvent[] {\n  const { respId, created, events, prefixOutputItems, nextOutputIndex } = buildResponsePreamble(\n    model,\n    chunkSize,\n    reasoning,\n    webSearches,\n    overrides,\n  );\n\n  const fcOutputItems: object[] = [];\n\n  for (let idx = 0; idx < toolCalls.length; idx++) {\n    const tc = toolCalls[idx];\n    const callId = tc.id || generateToolCallId();\n    const fcId = generateId(\"fc\");\n    const outputIndex = nextOutputIndex + idx;\n\n    // output_item.added (function_call)\n    events.push({\n      type: \"response.output_item.added\",\n      output_index: outputIndex,\n      item: {\n        type: \"function_call\",\n        id: fcId,\n        call_id: callId,\n        name: tc.name,\n        arguments: \"\",\n        status: \"in_progress\",\n      },\n    });\n\n    // function_call_arguments.delta\n    const args = tc.arguments;\n    for (let i = 0; i < args.length; i += chunkSize) {\n      const slice = args.slice(i, i + chunkSize);\n      events.push({\n        type: \"response.function_call_arguments.delta\",\n        item_id: fcId,\n        output_index: outputIndex,\n        delta: slice,\n      });\n    }\n\n    // function_call_arguments.done\n    events.push({\n      type: \"response.function_call_arguments.done\",\n      item_id: fcId,\n      output_index: outputIndex,\n      arguments: args,\n    });\n\n    const doneItem = {\n      type: \"function_call\",\n      id: fcId,\n      call_id: callId,\n      name: tc.name,\n      arguments: args,\n      status: \"completed\",\n    };\n\n    // output_item.done\n    events.push({\n      type: \"response.output_item.done\",\n      output_index: outputIndex,\n      item: doneItem,\n    });\n\n    fcOutputItems.push(doneItem);\n  }\n\n  // response.completed\n  events.push({\n    type: \"response.completed\",\n    response: {\n      id: respId,\n      object: \"response\",\n      created_at: created,\n      model: overrides?.model ?? model,\n      status: responsesStatus(overrides?.finishReason, \"completed\"),\n      output: [...prefixOutputItems, ...fcOutputItems],\n      usage: responsesUsage(overrides),\n    },\n  });\n\n  return events;\n}\n\nfunction buildReasoningStreamEvents(\n  reasoning: string,\n  model: string,\n  chunkSize: number,\n): ResponsesSSEEvent[] {\n  const reasoningId = generateId(\"rs\");\n  const events: ResponsesSSEEvent[] = [];\n\n  events.push({\n    type: \"response.output_item.added\",\n    output_index: 0,\n    item: {\n      type: \"reasoning\",\n      id: reasoningId,\n      summary: [],\n    },\n  });\n\n  events.push({\n    type: \"response.reasoning_summary_part.added\",\n    item_id: reasoningId,\n    output_index: 0,\n    summary_index: 0,\n    part: { type: \"summary_text\", text: \"\" },\n  });\n\n  for (let i = 0; i < reasoning.length; i += chunkSize) {\n    const slice = reasoning.slice(i, i + chunkSize);\n    events.push({\n      type: \"response.reasoning_summary_text.delta\",\n      item_id: reasoningId,\n      output_index: 0,\n      summary_index: 0,\n      delta: slice,\n    });\n  }\n\n  events.push({\n    type: \"response.reasoning_summary_text.done\",\n    item_id: reasoningId,\n    output_index: 0,\n    summary_index: 0,\n    text: reasoning,\n  });\n\n  events.push({\n    type: \"response.reasoning_summary_part.done\",\n    item_id: reasoningId,\n    output_index: 0,\n    summary_index: 0,\n    part: { type: \"summary_text\", text: reasoning },\n  });\n\n  events.push({\n    type: \"response.output_item.done\",\n    output_index: 0,\n    item: {\n      type: \"reasoning\",\n      id: reasoningId,\n      summary: [{ type: \"summary_text\", text: reasoning }],\n    },\n  });\n\n  return events;\n}\n\nfunction buildWebSearchStreamEvents(\n  queries: string[],\n  startOutputIndex: number,\n): ResponsesSSEEvent[] {\n  const events: ResponsesSSEEvent[] = [];\n\n  for (let i = 0; i < queries.length; i++) {\n    const searchId = generateId(\"ws\");\n    const outputIndex = startOutputIndex + i;\n\n    events.push({\n      type: \"response.output_item.added\",\n      output_index: outputIndex,\n      item: {\n        type: \"web_search_call\",\n        id: searchId,\n        status: \"in_progress\",\n        action: { type: \"search\", query: queries[i] },\n      },\n    });\n\n    events.push({\n      type: \"response.output_item.done\",\n      output_index: outputIndex,\n      item: {\n        type: \"web_search_call\",\n        id: searchId,\n        status: \"completed\",\n        action: { type: \"search\", query: queries[i] },\n      },\n    });\n  }\n\n  return events;\n}\n\n// ─── Shared streaming helpers ────────────────────────────────────────────────\n\ninterface PreambleResult {\n  respId: string;\n  created: number;\n  events: ResponsesSSEEvent[];\n  prefixOutputItems: object[];\n  nextOutputIndex: number;\n}\n\nfunction buildResponsePreamble(\n  model: string,\n  chunkSize: number,\n  reasoning?: string,\n  webSearches?: string[],\n  overrides?: ResponseOverrides,\n): PreambleResult {\n  const respId = overrides?.id ?? responseId();\n  const created = overrides?.created ?? Math.floor(Date.now() / 1000);\n  const effectiveModel = overrides?.model ?? model;\n  const events: ResponsesSSEEvent[] = [];\n  const prefixOutputItems: object[] = [];\n  let nextOutputIndex = 0;\n\n  events.push({\n    type: \"response.created\",\n    response: {\n      id: respId,\n      object: \"response\",\n      created_at: created,\n      model: effectiveModel,\n      status: \"in_progress\",\n      output: [],\n    },\n  });\n  events.push({\n    type: \"response.in_progress\",\n    response: {\n      id: respId,\n      object: \"response\",\n      created_at: created,\n      model: effectiveModel,\n      status: \"in_progress\",\n      output: [],\n    },\n  });\n\n  if (reasoning) {\n    const reasoningEvents = buildReasoningStreamEvents(reasoning, model, chunkSize);\n    events.push(...reasoningEvents);\n    const doneEvent = reasoningEvents.find(\n      (e) =>\n        e.type === \"response.output_item.done\" &&\n        (e.item as { type: string })?.type === \"reasoning\",\n    );\n    if (doneEvent) prefixOutputItems.push(doneEvent.item as object);\n    nextOutputIndex++;\n  }\n\n  if (webSearches && webSearches.length > 0) {\n    const searchEvents = buildWebSearchStreamEvents(webSearches, nextOutputIndex);\n    events.push(...searchEvents);\n    const doneEvents = searchEvents.filter(\n      (e) =>\n        e.type === \"response.output_item.done\" &&\n        (e.item as { type: string })?.type === \"web_search_call\",\n    );\n    for (const de of doneEvents) prefixOutputItems.push(de.item as object);\n    nextOutputIndex += webSearches.length;\n  }\n\n  return { respId, created, events, prefixOutputItems, nextOutputIndex };\n}\n\ninterface MessageBlockResult {\n  events: ResponsesSSEEvent[];\n  msgItem: object;\n}\n\nfunction buildMessageOutputEvents(\n  content: string,\n  chunkSize: number,\n  outputIndex: number,\n): MessageBlockResult {\n  const msgId = itemId();\n  const events: ResponsesSSEEvent[] = [];\n\n  events.push({\n    type: \"response.output_item.added\",\n    output_index: outputIndex,\n    item: { type: \"message\", id: msgId, status: \"in_progress\", role: \"assistant\", content: [] },\n  });\n  events.push({\n    type: \"response.content_part.added\",\n    item_id: msgId,\n    output_index: outputIndex,\n    content_index: 0,\n    part: { type: \"output_text\", text: \"\", annotations: [] },\n  });\n\n  for (let i = 0; i < content.length; i += chunkSize) {\n    events.push({\n      type: \"response.output_text.delta\",\n      item_id: msgId,\n      output_index: outputIndex,\n      content_index: 0,\n      delta: content.slice(i, i + chunkSize),\n    });\n  }\n\n  events.push({\n    type: \"response.output_text.done\",\n    item_id: msgId,\n    output_index: outputIndex,\n    content_index: 0,\n    text: content,\n  });\n  events.push({\n    type: \"response.content_part.done\",\n    item_id: msgId,\n    output_index: outputIndex,\n    content_index: 0,\n    part: { type: \"output_text\", text: content, annotations: [] },\n  });\n\n  const msgItem = {\n    type: \"message\",\n    id: msgId,\n    status: \"completed\",\n    role: \"assistant\",\n    content: [{ type: \"output_text\", text: content, annotations: [] }],\n  };\n\n  events.push({ type: \"response.output_item.done\", output_index: outputIndex, item: msgItem });\n\n  return { events, msgItem };\n}\n\n// ─── Non-streaming response builders ────────────────────────────────────────\n\nfunction buildOutputPrefix(content: string, reasoning?: string, webSearches?: string[]): object[] {\n  const output: object[] = [];\n\n  if (reasoning) {\n    output.push({\n      type: \"reasoning\",\n      id: generateId(\"rs\"),\n      summary: [{ type: \"summary_text\", text: reasoning }],\n    });\n  }\n\n  if (webSearches && webSearches.length > 0) {\n    for (const query of webSearches) {\n      output.push({\n        type: \"web_search_call\",\n        id: generateId(\"ws\"),\n        status: \"completed\",\n        action: { type: \"search\", query },\n      });\n    }\n  }\n\n  output.push({\n    type: \"message\",\n    id: itemId(),\n    status: \"completed\",\n    role: \"assistant\",\n    content: [{ type: \"output_text\", text: content, annotations: [] }],\n  });\n\n  return output;\n}\n\nfunction buildResponseEnvelope(\n  model: string,\n  output: object[],\n  overrides?: ResponseOverrides,\n): object {\n  return {\n    id: overrides?.id ?? responseId(),\n    object: \"response\",\n    created_at: overrides?.created ?? Math.floor(Date.now() / 1000),\n    model: overrides?.model ?? model,\n    status: responsesStatus(overrides?.finishReason, \"completed\"),\n    output,\n    usage: responsesUsage(overrides),\n  };\n}\n\nfunction buildTextResponse(\n  content: string,\n  model: string,\n  reasoning?: string,\n  webSearches?: string[],\n  overrides?: ResponseOverrides,\n): object {\n  return buildResponseEnvelope(\n    model,\n    buildOutputPrefix(content, reasoning, webSearches),\n    overrides,\n  );\n}\n\nfunction buildToolCallResponse(\n  toolCalls: ToolCall[],\n  model: string,\n  reasoning?: string,\n  webSearches?: string[],\n  overrides?: ResponseOverrides,\n): object {\n  const output: object[] = [];\n  if (reasoning) {\n    output.push({\n      type: \"reasoning\",\n      id: generateId(\"rs\"),\n      summary: [{ type: \"summary_text\", text: reasoning }],\n    });\n  }\n  if (webSearches && webSearches.length > 0) {\n    for (const query of webSearches) {\n      output.push({\n        type: \"web_search_call\",\n        id: generateId(\"ws\"),\n        status: \"completed\",\n        action: { type: \"search\", query },\n      });\n    }\n  }\n  for (const tc of toolCalls) {\n    output.push({\n      type: \"function_call\",\n      id: generateId(\"fc\"),\n      call_id: tc.id || generateToolCallId(),\n      name: tc.name,\n      arguments: tc.arguments,\n      status: \"completed\",\n    });\n  }\n  return buildResponseEnvelope(model, output, overrides);\n}\n\nexport function buildContentWithToolCallsStreamEvents(\n  content: string,\n  toolCalls: ToolCall[],\n  model: string,\n  chunkSize: number,\n  reasoning?: string,\n  webSearches?: string[],\n  overrides?: ResponseOverrides,\n): ResponsesSSEEvent[] {\n  const { respId, created, events, prefixOutputItems, nextOutputIndex } = buildResponsePreamble(\n    model,\n    chunkSize,\n    reasoning,\n    webSearches,\n    overrides,\n  );\n\n  const { events: msgEvents, msgItem } = buildMessageOutputEvents(\n    content,\n    chunkSize,\n    nextOutputIndex,\n  );\n  events.push(...msgEvents);\n\n  const fcOutputItems: object[] = [];\n  for (let idx = 0; idx < toolCalls.length; idx++) {\n    const tc = toolCalls[idx];\n    const callId = tc.id || generateToolCallId();\n    const fcId = generateId(\"fc\");\n    const fcOutputIndex = nextOutputIndex + 1 + idx;\n    const args = tc.arguments;\n\n    events.push({\n      type: \"response.output_item.added\",\n      output_index: fcOutputIndex,\n      item: {\n        type: \"function_call\",\n        id: fcId,\n        call_id: callId,\n        name: tc.name,\n        arguments: \"\",\n        status: \"in_progress\",\n      },\n    });\n\n    for (let i = 0; i < args.length; i += chunkSize) {\n      events.push({\n        type: \"response.function_call_arguments.delta\",\n        item_id: fcId,\n        output_index: fcOutputIndex,\n        delta: args.slice(i, i + chunkSize),\n      });\n    }\n\n    events.push({\n      type: \"response.function_call_arguments.done\",\n      item_id: fcId,\n      output_index: fcOutputIndex,\n      arguments: args,\n    });\n\n    const doneItem = {\n      type: \"function_call\",\n      id: fcId,\n      call_id: callId,\n      name: tc.name,\n      arguments: args,\n      status: \"completed\",\n    };\n    events.push({ type: \"response.output_item.done\", output_index: fcOutputIndex, item: doneItem });\n    fcOutputItems.push(doneItem);\n  }\n\n  events.push({\n    type: \"response.completed\",\n    response: {\n      id: respId,\n      object: \"response\",\n      created_at: created,\n      model: overrides?.model ?? model,\n      status: responsesStatus(overrides?.finishReason, \"completed\"),\n      output: [...prefixOutputItems, msgItem, ...fcOutputItems],\n      usage: responsesUsage(overrides),\n    },\n  });\n\n  return events;\n}\n\nfunction buildContentWithToolCallsResponse(\n  content: string,\n  toolCalls: ToolCall[],\n  model: string,\n  reasoning?: string,\n  webSearches?: string[],\n  overrides?: ResponseOverrides,\n): object {\n  const output = buildOutputPrefix(content, reasoning, webSearches);\n  for (const tc of toolCalls) {\n    output.push({\n      type: \"function_call\",\n      id: generateId(\"fc\"),\n      call_id: tc.id || generateToolCallId(),\n      name: tc.name,\n      arguments: tc.arguments,\n      status: \"completed\",\n    });\n  }\n  return buildResponseEnvelope(model, output, overrides);\n}\n\n// ─── SSE writer for Responses API ───────────────────────────────────────────\n\ninterface ResponsesStreamOptions {\n  latency?: number;\n  streamingProfile?: StreamingProfile;\n  recordedTimings?: RecordedTimings;\n  replaySpeed?: number;\n  signal?: AbortSignal;\n  onChunkSent?: () => void;\n}\n\nasync function writeResponsesSSEStream(\n  res: http.ServerResponse,\n  events: ResponsesSSEEvent[],\n  optionsOrLatency?: number | ResponsesStreamOptions,\n): Promise<boolean> {\n  const opts: ResponsesStreamOptions =\n    typeof optionsOrLatency === \"number\" ? { latency: optionsOrLatency } : (optionsOrLatency ?? {});\n  const latency = opts.latency ?? 0;\n  const profile = opts.streamingProfile;\n  const { recordedTimings, replaySpeed } = opts;\n  const signal = opts.signal;\n  const onChunkSent = opts.onChunkSent;\n\n  if (res.writableEnded) return true;\n  res.setHeader(\"Content-Type\", \"text/event-stream\");\n  res.setHeader(\"Cache-Control\", \"no-cache\");\n  res.setHeader(\"Connection\", \"keep-alive\");\n\n  let chunkIndex = 0;\n  for (const event of events) {\n    const chunkDelay = calculateDelay(chunkIndex, profile, latency, recordedTimings, replaySpeed);\n    if (chunkDelay > 0) await delay(chunkDelay, signal);\n    if (signal?.aborted) return false;\n    if (res.writableEnded) return true;\n    res.write(`event: ${event.type}\\ndata: ${JSON.stringify(event)}\\n\\n`);\n    onChunkSent?.();\n    if (signal?.aborted) return false;\n    chunkIndex++;\n  }\n\n  if (!res.writableEnded) {\n    res.end();\n  }\n  return true;\n}\n\n// ─── Request handler ────────────────────────────────────────────────────────\n\nexport async function handleResponses(\n  req: http.IncomingMessage,\n  res: http.ServerResponse,\n  raw: string,\n  fixtures: Fixture[],\n  journal: Journal,\n  defaults: HandlerDefaults,\n  setCorsHeaders: (res: http.ServerResponse) => void,\n): Promise<void> {\n  setCorsHeaders(res);\n\n  let responsesReq: ResponsesRequest;\n  try {\n    responsesReq = JSON.parse(raw) as ResponsesRequest;\n  } catch (parseErr) {\n    const detail = parseErr instanceof Error ? parseErr.message : \"unknown\";\n    journal.add({\n      method: req.method ?? \"POST\",\n      path: req.url ?? \"/v1/responses\",\n      headers: flattenHeaders(req.headers),\n      body: null,\n      response: { status: 400, fixture: null },\n    });\n    writeErrorResponse(\n      res,\n      400,\n      JSON.stringify({\n        error: {\n          message: `Malformed JSON: ${detail}`,\n          type: \"invalid_request_error\",\n          code: \"invalid_json\",\n        },\n      }),\n    );\n    return;\n  }\n\n  // Convert to ChatCompletionRequest for fixture matching\n  const completionReq = responsesToCompletionRequest(responsesReq);\n  completionReq._endpointType = \"chat\";\n  completionReq._context = getContext(req);\n\n  const testId = getTestId(req);\n  const { fixture, skippedBySequenceOrTurn } = matchFixtureDiagnostic(\n    fixtures,\n    completionReq,\n    journal.getFixtureMatchCountsForTest(testId),\n    defaults.requestTransform,\n    // Record mode proxies on a miss to capture a fresh turn (see record gate\n    // below), so keep turnIndex strict to prevent an earlier-turn fixture from\n    // shadowing a longer request and skipping the new turn's recording.\n    recordMatchOptions(!!defaults.record, defaults.logger),\n  );\n\n  if (fixture) {\n    defaults.logger.debug(\n      `Responses fixture matched for ${req.method ?? \"POST\"} ${req.url ?? \"/v1/responses\"}`,\n    );\n    journal.incrementFixtureMatchCount(fixture, fixtures, testId);\n  } else {\n    defaults.logger.debug(\n      `No responses fixture matched for ${req.method ?? \"POST\"} ${req.url ?? \"/v1/responses\"}`,\n    );\n  }\n\n  if (\n    applyChaos(\n      res,\n      fixture,\n      defaults.chaos,\n      req.headers,\n      journal,\n      {\n        method: req.method ?? \"POST\",\n        path: req.url ?? \"/v1/responses\",\n        headers: flattenHeaders(req.headers),\n        body: completionReq,\n      },\n      fixture ? \"fixture\" : \"proxy\",\n      defaults.registry,\n      defaults.logger,\n    )\n  )\n    return;\n\n  if (!fixture) {\n    const effectiveStrict = resolveStrictMode(defaults.strict, req.headers);\n    if (effectiveStrict) {\n      const strictStatus = 503;\n      const strictMessage = strictNoMatchMessage(skippedBySequenceOrTurn);\n      defaults.logger.error(\n        strictNoMatchLogLine(\n          req.method ?? \"POST\",\n          req.url ?? \"/v1/responses\",\n          skippedBySequenceOrTurn,\n        ),\n      );\n      journal.add({\n        method: req.method ?? \"POST\",\n        path: req.url ?? \"/v1/responses\",\n        headers: flattenHeaders(req.headers),\n        body: completionReq,\n        response: {\n          status: strictStatus,\n          fixture: null,\n          ...strictOverrideField(defaults.strict, req.headers),\n        },\n      });\n      writeErrorResponse(\n        res,\n        strictStatus,\n        JSON.stringify({\n          error: {\n            message: strictMessage,\n            type: \"invalid_request_error\",\n            code: \"no_fixture_match\",\n          },\n        }),\n      );\n      return;\n    }\n    if (defaults.record) {\n      const outcome = await proxyAndRecord(\n        req,\n        res,\n        completionReq,\n        \"openai\",\n        req.url ?? \"/v1/responses\",\n        fixtures,\n        defaults,\n        raw,\n      );\n      if (outcome === \"handled_by_hook\") return;\n      if (outcome !== \"not_configured\") {\n        journal.add({\n          method: req.method ?? \"POST\",\n          path: req.url ?? \"/v1/responses\",\n          headers: flattenHeaders(req.headers),\n          body: completionReq,\n          response: { status: res.statusCode ?? 200, fixture: null, source: \"proxy\" },\n        });\n        return;\n      }\n    }\n    journal.add({\n      method: req.method ?? \"POST\",\n      path: req.url ?? \"/v1/responses\",\n      headers: flattenHeaders(req.headers),\n      body: completionReq,\n      response: {\n        status: 404,\n        fixture: null,\n        ...strictOverrideField(defaults.strict, req.headers),\n      },\n    });\n    writeErrorResponse(\n      res,\n      404,\n      JSON.stringify({\n        error: {\n          message: \"No fixture matched\",\n          type: \"invalid_request_error\",\n          code: \"no_fixture_match\",\n        },\n      }),\n    );\n    return;\n  }\n\n  const response = await resolveResponse(fixture, completionReq);\n  const latency = fixture.latency ?? defaults.latency;\n  const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);\n  const fixtureTimings = fixture.recordedTimings;\n  const effectiveReplaySpeed = fixture.replaySpeed ?? defaults.replaySpeed;\n\n  // Error response\n  if (isErrorResponse(response)) {\n    const status = response.status ?? 500;\n    journal.add({\n      method: req.method ?? \"POST\",\n      path: req.url ?? \"/v1/responses\",\n      headers: flattenHeaders(req.headers),\n      body: completionReq,\n      response: { status, fixture },\n    });\n    writeErrorResponse(res, status, serializeErrorResponse(response), {\n      retryAfter: response.retryAfter,\n    });\n    return;\n  }\n\n  // Combined content + tool calls response\n  if (isContentWithToolCallsResponse(response)) {\n    const overrides = extractOverrides(response);\n    // Gate reasoning emission on the requested model's capability (aimock#254).\n    const effectiveStrict = resolveStrictMode(defaults.strict, req.headers);\n    const effReasoning = resolveReasoningForModel(\n      response.reasoning,\n      completionReq.model,\n      effectiveStrict,\n      defaults.logger,\n    );\n    const journalEntry = journal.add({\n      method: req.method ?? \"POST\",\n      path: req.url ?? \"/v1/responses\",\n      headers: flattenHeaders(req.headers),\n      body: completionReq,\n      response: { status: 200, fixture },\n    });\n    if (responsesReq.stream !== true) {\n      const body = buildContentWithToolCallsResponse(\n        response.content,\n        response.toolCalls,\n        completionReq.model,\n        effReasoning,\n        response.webSearches,\n        overrides,\n      );\n      res.writeHead(200, { \"Content-Type\": \"application/json\" });\n      res.end(JSON.stringify(body));\n    } else {\n      const events = buildContentWithToolCallsStreamEvents(\n        response.content,\n        response.toolCalls,\n        completionReq.model,\n        chunkSize,\n        effReasoning,\n        response.webSearches,\n        overrides,\n      );\n      const interruption = createInterruptionSignal(fixture);\n      const completed = await writeResponsesSSEStream(res, events, {\n        latency,\n        streamingProfile: fixture.streamingProfile,\n        recordedTimings: fixtureTimings,\n        replaySpeed: effectiveReplaySpeed,\n        signal: interruption?.signal,\n        onChunkSent: interruption?.tick,\n      });\n      if (!completed) {\n        if (!res.writableEnded) res.destroy();\n        journalEntry.response.interrupted = true;\n        journalEntry.response.interruptReason = interruption?.reason();\n      }\n      interruption?.cleanup();\n    }\n    return;\n  }\n\n  // Text response\n  if (isTextResponse(response)) {\n    const overrides = extractOverrides(response);\n    // Gate reasoning emission on the requested model's capability (aimock#254).\n    const effectiveStrict = resolveStrictMode(defaults.strict, req.headers);\n    const effReasoning = resolveReasoningForModel(\n      response.reasoning,\n      completionReq.model,\n      effectiveStrict,\n      defaults.logger,\n    );\n    const journalEntry = journal.add({\n      method: req.method ?? \"POST\",\n      path: req.url ?? \"/v1/responses\",\n      headers: flattenHeaders(req.headers),\n      body: completionReq,\n      response: { status: 200, fixture },\n    });\n    if (responsesReq.stream !== true) {\n      const body = buildTextResponse(\n        response.content,\n        completionReq.model,\n        effReasoning,\n        response.webSearches,\n        overrides,\n      );\n      res.writeHead(200, { \"Content-Type\": \"application/json\" });\n      res.end(JSON.stringify(body));\n    } else {\n      const events = buildTextStreamEvents(\n        response.content,\n        completionReq.model,\n        chunkSize,\n        effReasoning,\n        response.webSearches,\n        overrides,\n      );\n      const interruption = createInterruptionSignal(fixture);\n      const completed = await writeResponsesSSEStream(res, events, {\n        latency,\n        streamingProfile: fixture.streamingProfile,\n        recordedTimings: fixtureTimings,\n        replaySpeed: effectiveReplaySpeed,\n        signal: interruption?.signal,\n        onChunkSent: interruption?.tick,\n      });\n      if (!completed) {\n        if (!res.writableEnded) res.destroy();\n        journalEntry.response.interrupted = true;\n        journalEntry.response.interruptReason = interruption?.reason();\n      }\n      interruption?.cleanup();\n    }\n    return;\n  }\n\n  // Tool call response\n  if (isToolCallResponse(response)) {\n    const overrides = extractOverrides(response);\n    // Gate reasoning emission on the requested model's capability (aimock#254).\n    const effectiveStrict = resolveStrictMode(defaults.strict, req.headers);\n    const effReasoning = resolveReasoningForModel(\n      response.reasoning,\n      completionReq.model,\n      effectiveStrict,\n      defaults.logger,\n    );\n    const journalEntry = journal.add({\n      method: req.method ?? \"POST\",\n      path: req.url ?? \"/v1/responses\",\n      headers: flattenHeaders(req.headers),\n      body: completionReq,\n      response: { status: 200, fixture },\n    });\n    if (responsesReq.stream !== true) {\n      const body = buildToolCallResponse(\n        response.toolCalls,\n        completionReq.model,\n        effReasoning,\n        response.webSearches,\n        overrides,\n      );\n      res.writeHead(200, { \"Content-Type\": \"application/json\" });\n      res.end(JSON.stringify(body));\n    } else {\n      const events = buildToolCallStreamEvents(\n        response.toolCalls,\n        completionReq.model,\n        chunkSize,\n        effReasoning,\n        response.webSearches,\n        overrides,\n      );\n      const interruption = createInterruptionSignal(fixture);\n      const completed = await writeResponsesSSEStream(res, events, {\n        latency,\n        streamingProfile: fixture.streamingProfile,\n        recordedTimings: fixtureTimings,\n        replaySpeed: effectiveReplaySpeed,\n        signal: interruption?.signal,\n        onChunkSent: interruption?.tick,\n      });\n      if (!completed) {\n        if (!res.writableEnded) res.destroy();\n        journalEntry.response.interrupted = true;\n        journalEntry.response.interruptReason = interruption?.reason();\n      }\n      interruption?.cleanup();\n    }\n    return;\n  }\n\n  // Unknown response type\n  journal.add({\n    method: req.method ?? \"POST\",\n    path: req.url ?? \"/v1/responses\",\n    headers: flattenHeaders(req.headers),\n    body: completionReq,\n    response: { status: 500, fixture },\n  });\n  writeErrorResponse(\n    res,\n    500,\n    JSON.stringify({\n      error: { message: \"Fixture response did not match any known type\", type: \"server_error\" },\n    }),\n  );\n}\n"],"mappings":";;;;;;;;AAuFA,SAAS,mBAAmB,SAA8D;AACxF,KAAI,CAAC,QAAS,QAAO;AACrB,KAAI,OAAO,YAAY,SAAU,QAAO;AACxC,QAAO,QACJ,QAAQ,MAAM,EAAE,SAAS,gBAAgB,EAAE,SAAS,cAAc,CAClE,KAAK,MAAM,EAAE,QAAQ,GAAG,CACxB,KAAK,GAAG;;AAGb,SAAgB,yBAAyB,KAAsC;CAC7E,MAAM,WAA0B,EAAE;CAElC,MAAM,4CAA4B,IAAI,SAAsB;AAG5D,KAAI,IAAI,aACN,UAAS,KAAK;EAAE,MAAM;EAAU,SAAS,IAAI;EAAc,CAAC;AAK9D,KAAI,OAAO,IAAI,UAAU,UAAU;AACjC,WAAS,KAAK;GAAE,MAAM;GAAQ,SAAS,IAAI;GAAO,CAAC;AACnD,SAAO;;AAGT,MAAK,MAAM,QAAQ,IAAI,MACrB,KAAI,KAAK,SAAS,YAAY,KAAK,SAAS,YAC1C,UAAS,KAAK;EAAE,MAAM;EAAU,SAAS,mBAAmB,KAAK,QAAQ;EAAE,CAAC;UACnE,KAAK,SAAS,OACvB,UAAS,KAAK;EAAE,MAAM;EAAQ,SAAS,mBAAmB,KAAK,QAAQ;EAAE,CAAC;UACjE,KAAK,SAAS,YACvB,UAAS,KAAK;EAAE,MAAM;EAAa,SAAS,mBAAmB,KAAK,QAAQ;EAAE,CAAC;UACtE,KAAK,SAAS,gBAEvB,UAAS,KAAK;EACZ,MAAM;EACN,SAAS;EACT,YAAY,CACV;GACE,IAAI,KAAK,WAAWA,oCAAoB;GACxC,MAAM;GACN,UAAU;IAAE,MAAM,KAAK,QAAQ;IAAI,WAAW,KAAK,aAAa;IAAI;GACrE,CACF;EACF,CAAC;UACO,KAAK,SAAS,wBAAwB;AAS/C,MAAI,CAHwB,SAAS,MAClC,MA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