{"version":3,"file":"ws-realtime.cjs","names":["generateToolCallId","generateId","DEFAULT_TEST_ID","matchFixture","isErrorResponse","isTextResponse","createInterruptionSignal","delay","isToolCallResponse"],"sources":["../src/ws-realtime.ts"],"sourcesContent":["/**\n * WebSocket handler for OpenAI Realtime API.\n *\n * Accepts Realtime API messages (session.update, conversation.item.create,\n * response.create) over WebSocket and sends back Realtime API events as\n * individual WebSocket text frames.\n */\n\nimport type { ChatCompletionRequest, ChatMessage, Fixture } from \"./types.js\";\nimport { matchFixture } from \"./router.js\";\nimport {\n  generateId,\n  generateToolCallId,\n  isTextResponse,\n  isToolCallResponse,\n  isErrorResponse,\n} from \"./helpers.js\";\nimport { createInterruptionSignal } from \"./interruption.js\";\nimport { delay } from \"./sse-writer.js\";\nimport { DEFAULT_TEST_ID, type Journal } from \"./journal.js\";\nimport type { Logger } from \"./logger.js\";\nimport type { WebSocketConnection } from \"./ws-framing.js\";\n\n// ─── Realtime protocol types ────────────────────────────────────────────────\n\ninterface RealtimeItem {\n  type: \"message\" | \"function_call\" | \"function_call_output\";\n  id?: string;\n  role?: \"user\" | \"assistant\" | \"system\";\n  content?: Array<{ type: string; text?: string }>;\n  name?: string;\n  call_id?: string;\n  arguments?: string;\n  output?: string;\n}\n\ninterface SessionConfig {\n  model: string;\n  modalities: string[];\n  instructions: string;\n  tools: unknown[];\n  voice: string | null;\n  input_audio_format: string | null;\n  output_audio_format: string | null;\n  turn_detection: unknown | null;\n  temperature: number;\n}\n\ninterface RealtimeMessage {\n  type: string;\n  event_id?: string;\n  session?: Partial<SessionConfig>;\n  item?: RealtimeItem;\n  response?: {\n    modalities?: string[];\n    instructions?: string;\n    [key: string]: unknown;\n  };\n}\n\n// ─── Conversion helpers ─────────────────────────────────────────────────────\n\nexport function realtimeItemsToMessages(\n  items: RealtimeItem[],\n  instructions?: string,\n  logger?: Logger,\n): ChatMessage[] {\n  const messages: ChatMessage[] = [];\n\n  if (instructions) {\n    messages.push({ role: \"system\", content: instructions });\n  }\n\n  for (const item of items) {\n    if (item.type === \"message\") {\n      const text = item.content?.[0]?.text ?? \"\";\n      const role =\n        item.role === \"assistant\" ? \"assistant\" : item.role === \"system\" ? \"system\" : \"user\";\n      messages.push({ role, content: text });\n    } else if (item.type === \"function_call\") {\n      if (!item.name) {\n        logger?.warn(\"Realtime function_call item missing 'name'\");\n      }\n      messages.push({\n        role: \"assistant\",\n        content: null,\n        tool_calls: [\n          {\n            id: item.call_id ?? generateToolCallId(),\n            type: \"function\",\n            function: {\n              name: item.name ?? \"\",\n              arguments: item.arguments ?? \"\",\n            },\n          },\n        ],\n      });\n    } else if (item.type === \"function_call_output\") {\n      if (!item.output) {\n        logger?.warn(\"Realtime function_call_output item missing 'output'\");\n      }\n      messages.push({\n        role: \"tool\",\n        content: item.output ?? \"\",\n        tool_call_id: item.call_id,\n      });\n    }\n  }\n\n  return messages;\n}\n\n// ─── Event builders ─────────────────────────────────────────────────────────\n\nfunction evt(type: string, extra: Record<string, unknown> = {}): string {\n  return JSON.stringify({ type, event_id: generateId(\"evt\"), ...extra });\n}\n\nfunction buildErrorRealtimeEvent(\n  message: string,\n  type = \"invalid_request_error\",\n  code?: string,\n): string {\n  return evt(\"error\", { error: { message, type, code } });\n}\n\n// ─── Main handler ───────────────────────────────────────────────────────────\n\nexport function handleWebSocketRealtime(\n  ws: WebSocketConnection,\n  fixtures: Fixture[],\n  journal: Journal,\n  defaults: {\n    latency: number;\n    chunkSize: number;\n    model: string;\n    logger: Logger;\n    strict?: boolean;\n    requestTransform?: (req: ChatCompletionRequest) => ChatCompletionRequest;\n    testId?: string;\n  },\n): void {\n  const { logger } = defaults;\n  const sessionId = generateId(\"sess\");\n\n  const session: SessionConfig = {\n    model: defaults.model,\n    modalities: [\"text\"],\n    instructions: \"\",\n    tools: [],\n    voice: null,\n    input_audio_format: null,\n    output_audio_format: null,\n    turn_detection: null,\n    temperature: 0.8,\n  };\n\n  const conversationItems: RealtimeItem[] = [];\n\n  // Send session.created immediately on connect\n  ws.send(evt(\"session.created\", { session: { id: sessionId, ...session } }));\n\n  // Serialize message processing to prevent event interleaving\n  let pending = Promise.resolve();\n  ws.on(\"message\", (raw: string) => {\n    pending = pending.then(() =>\n      processMessage(raw, ws, fixtures, journal, defaults, session, conversationItems).catch(\n        (err: unknown) => {\n          const msg = err instanceof Error ? err.message : \"Internal error\";\n          logger.error(`WebSocket realtime error: ${msg}`);\n          try {\n            ws.send(buildErrorRealtimeEvent(msg, \"server_error\"));\n          } catch {\n            // Connection already gone — original error already logged above\n          }\n        },\n      ),\n    );\n  });\n}\n\nasync function processMessage(\n  raw: string,\n  ws: WebSocketConnection,\n  fixtures: Fixture[],\n  journal: Journal,\n  defaults: {\n    latency: number;\n    chunkSize: number;\n    model: string;\n    logger: Logger;\n    strict?: boolean;\n    requestTransform?: (req: ChatCompletionRequest) => ChatCompletionRequest;\n    testId?: string;\n  },\n  session: SessionConfig,\n  conversationItems: RealtimeItem[],\n): Promise<void> {\n  let parsed: RealtimeMessage;\n  try {\n    parsed = JSON.parse(raw) as RealtimeMessage;\n  } catch {\n    ws.send(buildErrorRealtimeEvent(\"Malformed JSON\", \"invalid_request_error\", \"invalid_json\"));\n    return;\n  }\n\n  const msgType = parsed.type;\n\n  // ── session.update ────────────────────────────────────────────────────\n  if (msgType === \"session.update\") {\n    if (parsed.session) {\n      if (parsed.session.instructions !== undefined) {\n        session.instructions = parsed.session.instructions;\n      }\n      if (parsed.session.tools !== undefined) {\n        session.tools = parsed.session.tools;\n      }\n      if (parsed.session.modalities !== undefined) {\n        session.modalities = parsed.session.modalities;\n      }\n      if (parsed.session.model !== undefined) {\n        session.model = parsed.session.model;\n      }\n      if (parsed.session.temperature !== undefined) {\n        session.temperature = parsed.session.temperature;\n      }\n    }\n    ws.send(evt(\"session.updated\", { session: { ...session } }));\n    return;\n  }\n\n  // ── conversation.item.create ──────────────────────────────────────────\n  if (msgType === \"conversation.item.create\") {\n    if (!parsed.item) {\n      ws.send(\n        buildErrorRealtimeEvent(\n          \"Missing 'item' in conversation.item.create\",\n          \"invalid_request_error\",\n        ),\n      );\n      return;\n    }\n    const item = parsed.item;\n    if (!item.id) {\n      item.id = generateId(\"item\");\n    }\n    conversationItems.push(item);\n    ws.send(evt(\"conversation.item.created\", { item }));\n    return;\n  }\n\n  // ── response.create ───────────────────────────────────────────────────\n  if (msgType === \"response.create\") {\n    await handleResponseCreate(ws, fixtures, journal, defaults, session, conversationItems);\n    return;\n  }\n\n  // Unknown message type — ignore silently (matches OpenAI behavior)\n}\n\nasync function handleResponseCreate(\n  ws: WebSocketConnection,\n  fixtures: Fixture[],\n  journal: Journal,\n  defaults: {\n    latency: number;\n    chunkSize: number;\n    model: string;\n    logger: Logger;\n    strict?: boolean;\n    requestTransform?: (req: ChatCompletionRequest) => ChatCompletionRequest;\n    testId?: string;\n  },\n  session: SessionConfig,\n  conversationItems: RealtimeItem[],\n): Promise<void> {\n  const instructions = session.instructions || undefined;\n  const messages = realtimeItemsToMessages(conversationItems, instructions, defaults.logger);\n\n  const completionReq: ChatCompletionRequest = {\n    model: session.model,\n    messages,\n  };\n\n  const testId = defaults.testId ?? DEFAULT_TEST_ID;\n  const fixture = matchFixture(\n    fixtures,\n    completionReq,\n    journal.getFixtureMatchCountsForTest(testId),\n    defaults.requestTransform,\n  );\n  const responseId = generateId(\"resp\");\n\n  if (fixture) {\n    journal.incrementFixtureMatchCount(fixture, fixtures, testId);\n  }\n\n  if (!fixture) {\n    if (defaults.strict) {\n      defaults.logger.warn(`STRICT: No fixture matched for WebSocket message`);\n      ws.close(1008, \"Strict mode: no fixture matched\");\n      return;\n    }\n    journal.add({\n      method: \"WS\",\n      path: \"/v1/realtime\",\n      headers: {},\n      body: completionReq,\n      response: { status: 404, fixture: null },\n    });\n    // Send response.created with failed status then response.done with error\n    ws.send(\n      evt(\"response.created\", {\n        response: { id: responseId, status: \"failed\", output: [] },\n      }),\n    );\n    ws.send(\n      evt(\"response.done\", {\n        response: {\n          id: responseId,\n          status: \"failed\",\n          output: [],\n          status_details: {\n            type: \"error\",\n            error: {\n              message: \"No fixture matched\",\n              type: \"invalid_request_error\",\n              code: \"no_fixture_match\",\n            },\n          },\n        },\n      }),\n    );\n    return;\n  }\n\n  const response = fixture.response;\n  const latency = fixture.latency ?? defaults.latency;\n  const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);\n\n  // ── Error fixture ───────────────────────────────────────────────────\n  if (isErrorResponse(response)) {\n    const status = response.status ?? 500;\n    journal.add({\n      method: \"WS\",\n      path: \"/v1/realtime\",\n      headers: {},\n      body: completionReq,\n      response: { status, fixture },\n    });\n    ws.send(\n      evt(\"response.created\", {\n        response: { id: responseId, status: \"failed\", output: [] },\n      }),\n    );\n    ws.send(\n      evt(\"response.done\", {\n        response: {\n          id: responseId,\n          status: \"failed\",\n          output: [],\n          status_details: {\n            type: \"error\",\n            error: {\n              message: response.error.message,\n              type: response.error.type,\n              code: response.error.code,\n            },\n          },\n        },\n      }),\n    );\n    return;\n  }\n\n  // ── Text response ───────────────────────────────────────────────────\n  if (isTextResponse(response)) {\n    const journalEntry = journal.add({\n      method: \"WS\",\n      path: \"/v1/realtime\",\n      headers: {},\n      body: completionReq,\n      response: { status: 200, fixture },\n    });\n\n    const itemId = generateId(\"item\");\n    const contentIndex = 0;\n    const outputIndex = 0;\n\n    const outputItem = {\n      id: itemId,\n      type: \"message\",\n      role: \"assistant\",\n      content: [{ type: \"text\", text: response.content }],\n    };\n\n    // response.created\n    ws.send(\n      evt(\"response.created\", {\n        response: { id: responseId, status: \"in_progress\", output: [] },\n      }),\n    );\n\n    // response.output_item.added\n    ws.send(\n      evt(\"response.output_item.added\", {\n        response_id: responseId,\n        output_index: outputIndex,\n        item: { id: itemId, type: \"message\", role: \"assistant\", content: [] },\n      }),\n    );\n\n    // response.content_part.added\n    ws.send(\n      evt(\"response.content_part.added\", {\n        response_id: responseId,\n        item_id: itemId,\n        output_index: outputIndex,\n        content_index: contentIndex,\n        part: { type: \"text\", text: \"\" },\n      }),\n    );\n\n    // response.text.delta (chunked)\n    const content = response.content;\n    const interruption = createInterruptionSignal(fixture);\n    let interrupted = false;\n\n    for (let i = 0; i < content.length; i += chunkSize) {\n      if (ws.isClosed) break;\n      if (latency > 0) await delay(latency, interruption?.signal);\n      if (interruption?.signal.aborted) {\n        interrupted = true;\n        break;\n      }\n      if (ws.isClosed) break;\n      const chunk = content.slice(i, i + chunkSize);\n      ws.send(\n        evt(\"response.text.delta\", {\n          response_id: responseId,\n          item_id: itemId,\n          output_index: outputIndex,\n          content_index: contentIndex,\n          delta: chunk,\n        }),\n      );\n      interruption?.tick();\n      if (interruption?.signal.aborted) {\n        interrupted = true;\n        break;\n      }\n    }\n\n    if (interrupted) {\n      ws.destroy();\n      journalEntry.response.interrupted = true;\n      journalEntry.response.interruptReason = interruption?.reason();\n      interruption?.cleanup();\n      return;\n    }\n\n    interruption?.cleanup();\n\n    if (ws.isClosed) return;\n\n    // response.text.done\n    ws.send(\n      evt(\"response.text.done\", {\n        response_id: responseId,\n        item_id: itemId,\n        output_index: outputIndex,\n        content_index: contentIndex,\n        text: content,\n      }),\n    );\n\n    // response.content_part.done\n    ws.send(\n      evt(\"response.content_part.done\", {\n        response_id: responseId,\n        item_id: itemId,\n        output_index: outputIndex,\n        content_index: contentIndex,\n        part: { type: \"text\", text: content },\n      }),\n    );\n\n    // response.output_item.done\n    ws.send(\n      evt(\"response.output_item.done\", {\n        response_id: responseId,\n        output_index: outputIndex,\n        item: outputItem,\n      }),\n    );\n\n    // response.done\n    ws.send(\n      evt(\"response.done\", {\n        response: { id: responseId, status: \"completed\", output: [outputItem] },\n      }),\n    );\n\n    // Accumulate assistant response into conversation for multi-turn\n    conversationItems.push({\n      type: \"message\",\n      id: itemId,\n      role: \"assistant\",\n      content: [{ type: \"text\", text: content }],\n    });\n    return;\n  }\n\n  // ── Tool call response ──────────────────────────────────────────────\n  if (isToolCallResponse(response)) {\n    const journalEntry = journal.add({\n      method: \"WS\",\n      path: \"/v1/realtime\",\n      headers: {},\n      body: completionReq,\n      response: { status: 200, fixture },\n    });\n\n    // response.created\n    ws.send(\n      evt(\"response.created\", {\n        response: { id: responseId, status: \"in_progress\", output: [] },\n      }),\n    );\n\n    const outputItems: unknown[] = [];\n    const interruption = createInterruptionSignal(fixture);\n    let interrupted = false;\n\n    for (let tcIdx = 0; tcIdx < response.toolCalls.length; tcIdx++) {\n      const tc = response.toolCalls[tcIdx];\n      const callId = tc.id ?? generateToolCallId();\n      const itemId = generateId(\"item\");\n\n      const outputItem = {\n        id: itemId,\n        type: \"function_call\",\n        call_id: callId,\n        name: tc.name,\n        arguments: tc.arguments,\n      };\n\n      // response.output_item.added\n      ws.send(\n        evt(\"response.output_item.added\", {\n          response_id: responseId,\n          output_index: tcIdx,\n          item: {\n            id: itemId,\n            type: \"function_call\",\n            call_id: callId,\n            name: tc.name,\n            arguments: \"\",\n          },\n        }),\n      );\n\n      // response.function_call_arguments.delta (chunked)\n      const args = tc.arguments;\n      for (let i = 0; i < args.length; i += chunkSize) {\n        if (ws.isClosed) break;\n        if (latency > 0) await delay(latency, interruption?.signal);\n        if (interruption?.signal.aborted) {\n          interrupted = true;\n          break;\n        }\n        if (ws.isClosed) break;\n        const chunk = args.slice(i, i + chunkSize);\n        ws.send(\n          evt(\"response.function_call_arguments.delta\", {\n            response_id: responseId,\n            item_id: itemId,\n            output_index: tcIdx,\n            call_id: callId,\n            delta: chunk,\n          }),\n        );\n        interruption?.tick();\n        if (interruption?.signal.aborted) {\n          interrupted = true;\n          break;\n        }\n      }\n\n      if (interrupted) break;\n\n      // response.function_call_arguments.done\n      ws.send(\n        evt(\"response.function_call_arguments.done\", {\n          response_id: responseId,\n          item_id: itemId,\n          output_index: tcIdx,\n          call_id: callId,\n          arguments: args,\n        }),\n      );\n\n      // response.output_item.done\n      ws.send(\n        evt(\"response.output_item.done\", {\n          response_id: responseId,\n          output_index: tcIdx,\n          item: outputItem,\n        }),\n      );\n\n      outputItems.push(outputItem);\n    }\n\n    if (interrupted) {\n      ws.destroy();\n      journalEntry.response.interrupted = true;\n      journalEntry.response.interruptReason = interruption?.reason();\n      interruption?.cleanup();\n      return;\n    }\n\n    interruption?.cleanup();\n\n    if (ws.isClosed) return;\n\n    // response.done\n    ws.send(\n      evt(\"response.done\", {\n        response: { id: responseId, status: \"completed\", output: outputItems },\n      }),\n    );\n\n    // Accumulate assistant tool calls into conversation for multi-turn\n    // Reuse outputItems (which already have the correct call_id) to avoid generating divergent IDs\n    for (const item of outputItems) {\n      conversationItems.push(item as RealtimeItem);\n    }\n    return;\n  }\n\n  // Unknown response type\n  journal.add({\n    method: \"WS\",\n    path: \"/v1/realtime\",\n    headers: {},\n    body: completionReq,\n    response: { status: 500, fixture },\n  });\n  ws.send(buildErrorRealtimeEvent(\"Fixture response did not match any known type\", \"server_error\"));\n}\n"],"mappings":";;;;;;;AA8DA,SAAgB,wBACd,OACA,cACA,QACe;CACf,MAAM,WAA0B,EAAE;AAElC,KAAI,aACF,UAAS,KAAK;EAAE,MAAM;EAAU,SAAS;EAAc,CAAC;AAG1D,MAAK,MAAM,QAAQ,MACjB,KAAI,KAAK,SAAS,WAAW;EAC3B,MAAM,OAAO,KAAK,UAAU,IAAI,QAAQ;EACxC,MAAM,OACJ,KAAK,SAAS,cAAc,cAAc,KAAK,SAAS,WAAW,WAAW;AAChF,WAAS,KAAK;GAAE;GAAM,SAAS;GAAM,CAAC;YAC7B,KAAK,SAAS,iBAAiB;AACxC,MAAI,CAAC,KAAK,KACR,SAAQ,KAAK,6CAA6C;AAE5D,WAAS,KAAK;GACZ,MAAM;GACN,SAAS;GACT,YAAY,CACV;IACE,IAAI,KAAK,WAAWA,oCAAoB;IACxC,MAAM;IACN,UAAU;KACR,MAAM,KAAK,QAAQ;KACnB,WAAW,KAAK,aAAa;KAC9B;IACF,CACF;GACF,CAAC;YACO,KAAK,SAAS,wBAAwB;AAC/C,MAAI,CAAC,KAAK,OACR,SAAQ,KAAK,sDAAsD;AAErE,WAAS,KAAK;GACZ,MAAM;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