{"version":3,"file":"openai.cjs","names":["isOpenAIDataBlock","convertToV1FromOpenAIDataBlock","_isObject","_isArray","_isString","_isContentBlock","iife"],"sources":["../../../src/messages/block_translators/openai.ts"],"sourcesContent":["import type { ContentBlock } from \"../content/index.js\";\nimport type { AIMessageChunk, AIMessage } from \"../ai.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { convertToV1FromOpenAIDataBlock, isOpenAIDataBlock } from \"./data.js\";\nimport {\n  _isArray,\n  _isContentBlock,\n  _isObject,\n  _isString,\n  iife,\n} from \"./utils.js\";\n\n/**\n * Converts a ChatOpenAICompletions message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from ChatOpenAICompletions API format\n * and converts it to the standardized v1 content block format. It handles both\n * string content and structured content blocks, as well as tool calls.\n *\n * @param message - The AI message containing ChatOpenAICompletions formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage(\"Hello world\");\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns: [{ type: \"text\", text: \"Hello world\" }]\n * ```\n *\n * @example\n * ```typescript\n * const message = new AIMessage([\n *   { type: \"text\", text: \"Hello\" },\n *   { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ]);\n * message.tool_calls = [\n *   { id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns:\n * // [\n * //   { type: \"text\", text: \"Hello\" },\n * //   { type: \"image\", url: \"https://example.com/image.png\" },\n * //   { type: \"tool_call\", id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletions(\n  message: AIMessage\n): Array<ContentBlock.Standard> {\n  const blocks: Array<ContentBlock.Standard> = [];\n  if (typeof message.content === \"string\") {\n    // Only add text block if content is non-empty\n    if (message.content.length > 0) {\n      blocks.push({\n        type: \"text\",\n        text: message.content,\n      });\n    }\n  } else {\n    blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n  }\n  for (const toolCall of message.tool_calls ?? []) {\n    blocks.push({\n      type: \"tool_call\",\n      id: toolCall.id,\n      name: toolCall.name,\n      args: toolCall.args,\n    });\n  }\n  return blocks;\n}\n\n/**\n * Converts a ChatOpenAICompletions message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk from OpenAI's chat completions API and converts\n * it to the standardized v1 content block format. It handles both string and array content,\n * as well as tool calls that may be present in the chunk.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage(\"Hello\");\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns: [{ type: \"text\", text: \"Hello\" }]\n * ```\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage([\n *   { type: \"text\", text: \"Processing...\" }\n * ]);\n * chunk.tool_calls = [\n *   { id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns:\n * // [\n * //   { type: \"text\", text: \"Processing...\" },\n * //   { type: \"tool_call\", id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsChunk(\n  message: AIMessage\n): Array<ContentBlock.Standard> {\n  const blocks: Array<ContentBlock.Standard> = [];\n  if (typeof message.content === \"string\") {\n    // Only add text block if content is non-empty\n    if (message.content.length > 0) {\n      blocks.push({\n        type: \"text\",\n        text: message.content,\n      });\n    }\n  } else {\n    blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n  }\n\n  // TODO: parse chunk position information\n  for (const toolCall of message.tool_calls ?? []) {\n    blocks.push({\n      type: \"tool_call\",\n      id: toolCall.id,\n      name: toolCall.name,\n      args: toolCall.args,\n    });\n  }\n  return blocks;\n}\n\n/**\n * Converts an array of ChatOpenAICompletions content blocks to v1 standard content blocks.\n *\n * This function processes content blocks from OpenAI's Chat Completions API format\n * and converts them to the standardized v1 content block format. It handles both\n * OpenAI-specific data blocks (which require conversion) and standard blocks\n * (which are passed through with type assertion).\n *\n * @param blocks - Array of content blocks in ChatOpenAICompletions format\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const openaiBlocks = [\n *   { type: \"text\", text: \"Hello world\" },\n *   { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsInput(openaiBlocks);\n * // Returns:\n * // [\n * //   { type: \"text\", text: \"Hello world\" },\n * //   { type: \"image\", url: \"https://example.com/image.png\" }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsInput(\n  blocks: Array<ContentBlock>\n): Array<ContentBlock.Standard> {\n  const convertedBlocks: Array<ContentBlock.Standard> = [];\n  for (const block of blocks) {\n    if (isOpenAIDataBlock(block)) {\n      convertedBlocks.push(convertToV1FromOpenAIDataBlock(block));\n    } else {\n      convertedBlocks.push(block as ContentBlock.Standard);\n    }\n  }\n  return convertedBlocks;\n}\n\nfunction convertResponsesAnnotation(\n  annotation: ContentBlock\n): ContentBlock | ContentBlock.Citation {\n  if (annotation.type === \"url_citation\") {\n    const { url, title, start_index, end_index } = annotation;\n    return {\n      type: \"citation\",\n      url,\n      title,\n      startIndex: start_index,\n      endIndex: end_index,\n    };\n  }\n  if (annotation.type === \"file_citation\") {\n    const { file_id, filename, index } = annotation;\n    return {\n      type: \"citation\",\n      title: filename,\n      startIndex: index,\n      endIndex: index,\n      fileId: file_id,\n    };\n  }\n  return annotation;\n}\n\n/**\n * Converts a ChatOpenAIResponses message to an array of v1 standard content blocks.\n *\n * This function processes an AI message containing OpenAI Responses-specific content blocks\n * and converts them to the standardized v1 content block format. It handles reasoning summaries,\n * text content with annotations, tool calls, and various tool outputs including code interpreter,\n * web search, file search, computer calls, and MCP-related blocks.\n *\n * @param message - The AI message containing OpenAI Responses-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage({\n *   content: [{ type: \"text\", text: \"Hello world\", annotations: [] }],\n *   tool_calls: [{ id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } }],\n *   additional_kwargs: {\n *     reasoning: { summary: [{ text: \"Let me calculate this...\" }] },\n *     tool_outputs: [\n *       {\n *         type: \"code_interpreter_call\",\n *         code: \"print('hello')\",\n *         outputs: [{ type: \"logs\", logs: \"hello\" }]\n *       }\n *     ]\n *   }\n * });\n *\n * const standardBlocks = convertToV1FromResponses(message);\n * // Returns:\n * // [\n * //   { type: \"reasoning\", reasoning: \"Let me calculate this...\" },\n * //   { type: \"text\", text: \"Hello world\", annotations: [] },\n * //   { type: \"tool_call\", id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } },\n * //   { type: \"code_interpreter_call\", code: \"print('hello')\" },\n * //   { type: \"code_interpreter_result\", output: [{ type: \"code_interpreter_output\", returnCode: 0, stdout: \"hello\" }] }\n * // ]\n * ```\n */\nexport function convertToV1FromResponses(\n  message: AIMessage\n): Array<ContentBlock.Standard> {\n  function* iterateContent(): Iterable<ContentBlock.Standard> {\n    if (\n      _isObject(message.additional_kwargs?.reasoning) &&\n      _isArray(message.additional_kwargs.reasoning.summary)\n    ) {\n      const summary =\n        message.additional_kwargs.reasoning.summary.reduce<string>(\n          (acc, item) => {\n            if (_isObject(item) && _isString(item.text)) {\n              return `${acc}${item.text}`;\n            }\n            return acc;\n          },\n          \"\"\n        );\n      yield {\n        type: \"reasoning\",\n        reasoning: summary,\n      };\n    }\n    const content =\n      typeof message.content === \"string\"\n        ? [{ type: \"text\", text: message.content }]\n        : message.content;\n    for (const block of content) {\n      if (_isContentBlock(block, \"text\")) {\n        const {\n          text,\n          annotations,\n          phase,\n          extras: existingExtras,\n          ...rest\n        } = block;\n        const extras: Record<string, unknown> = _isObject(existingExtras)\n          ? { ...(existingExtras as Record<string, unknown>) }\n          : {};\n        if (_isString(phase)) {\n          extras.phase = phase;\n        }\n        const extrasSpread = Object.keys(extras).length > 0 ? { extras } : {};\n        if (Array.isArray(annotations)) {\n          yield {\n            ...rest,\n            ...extrasSpread,\n            type: \"text\",\n            text: String(text),\n            annotations: annotations.map(convertResponsesAnnotation),\n          };\n        } else {\n          yield {\n            ...rest,\n            ...extrasSpread,\n            type: \"text\",\n            text: String(text),\n          };\n        }\n      }\n    }\n    for (const toolCall of message.tool_calls ?? []) {\n      yield {\n        type: \"tool_call\",\n        id: toolCall.id,\n        name: toolCall.name,\n        args: toolCall.args,\n      };\n    }\n    if (\n      _isObject(message.additional_kwargs) &&\n      _isArray(message.additional_kwargs.tool_outputs)\n    ) {\n      for (const toolOutput of message.additional_kwargs.tool_outputs) {\n        if (_isContentBlock(toolOutput, \"web_search_call\")) {\n          /**\n           * Build args from available action data.\n           * The ResponseFunctionWebSearch base type only has id, status, type.\n           * The action field (with query, sources, etc.) may be present at\n           * runtime when the `include` parameter includes \"web_search_call.action.sources\".\n           */\n          const webSearchArgs: Record<string, unknown> = {};\n          if (\n            _isObject(toolOutput.action) &&\n            _isString(toolOutput.action.query)\n          ) {\n            webSearchArgs.query = toolOutput.action.query;\n          }\n          yield {\n            id: toolOutput.id,\n            type: \"server_tool_call\",\n            name: \"web_search\",\n            args: webSearchArgs,\n          };\n          // Emit a server_tool_call_result when the search has completed or failed\n          if (\n            toolOutput.status === \"completed\" ||\n            toolOutput.status === \"failed\"\n          ) {\n            const output: Record<string, unknown> = {};\n            if (_isObject(toolOutput.action)) {\n              output.action = toolOutput.action;\n            }\n            yield {\n              type: \"server_tool_call_result\",\n              toolCallId: _isString(toolOutput.id) ? toolOutput.id : \"\",\n              status: toolOutput.status === \"completed\" ? \"success\" : \"error\",\n              output,\n            };\n          }\n          continue;\n        } else if (_isContentBlock(toolOutput, \"file_search_call\")) {\n          yield {\n            id: toolOutput.id,\n            type: \"server_tool_call\",\n            name: \"file_search\",\n            args: {\n              queries: _isArray(toolOutput.queries) ? toolOutput.queries : [],\n            },\n          };\n          // Emit a server_tool_call_result when results are available\n          if (\n            toolOutput.status === \"completed\" ||\n            toolOutput.status === \"failed\"\n          ) {\n            yield {\n              type: \"server_tool_call_result\",\n              toolCallId: _isString(toolOutput.id) ? toolOutput.id : \"\",\n              status: toolOutput.status === \"completed\" ? \"success\" : \"error\",\n              output: _isArray(toolOutput.results)\n                ? { results: toolOutput.results }\n                : {},\n            };\n          }\n          continue;\n        } else if (_isContentBlock(toolOutput, \"computer_call\")) {\n          yield { type: \"non_standard\", value: toolOutput };\n          continue;\n        } else if (_isContentBlock(toolOutput, \"code_interpreter_call\")) {\n          if (_isString(toolOutput.code)) {\n            yield {\n              id: toolOutput.id,\n              type: \"server_tool_call\",\n              name: \"code_interpreter\",\n              args: { code: toolOutput.code },\n            };\n          }\n          if (_isArray(toolOutput.outputs)) {\n            const returnCode = iife(() => {\n              if (toolOutput.status === \"in_progress\") return undefined;\n              if (toolOutput.status === \"completed\") return 0;\n              if (toolOutput.status === \"incomplete\") return 127;\n              if (toolOutput.status === \"interpreting\") return undefined;\n              if (toolOutput.status === \"failed\") return 1;\n              return undefined;\n            });\n            for (const output of toolOutput.outputs) {\n              if (_isContentBlock(output, \"logs\")) {\n                yield {\n                  type: \"server_tool_call_result\",\n                  toolCallId: toolOutput.id ?? \"\",\n                  status: \"success\",\n                  output: {\n                    type: \"code_interpreter_output\",\n                    returnCode: returnCode ?? 0,\n                    stderr: [0, undefined].includes(returnCode)\n                      ? undefined\n                      : String(output.logs),\n                    stdout: [0, undefined].includes(returnCode)\n                      ? String(output.logs)\n                      : undefined,\n                  },\n                };\n                continue;\n              }\n            }\n          }\n          continue;\n        } else if (_isContentBlock(toolOutput, \"mcp_call\")) {\n          yield {\n            id: toolOutput.id,\n            type: \"server_tool_call\",\n            name: \"mcp_call\",\n            args: toolOutput.input,\n          };\n          continue;\n        } else if (_isContentBlock(toolOutput, \"mcp_list_tools\")) {\n          yield {\n            id: toolOutput.id,\n            type: \"server_tool_call\",\n            name: \"mcp_list_tools\",\n            args: toolOutput.input,\n          };\n          continue;\n        } else if (_isContentBlock(toolOutput, \"mcp_approval_request\")) {\n          yield { type: \"non_standard\", value: toolOutput };\n          continue;\n        } else if (_isContentBlock(toolOutput, \"tool_search_call\")) {\n          const toolSearchArgs: Record<string, unknown> = {};\n          if (_isObject(toolOutput.arguments)) {\n            Object.assign(toolSearchArgs, toolOutput.arguments);\n          }\n          const toolSearchCallExtras: Record<string, unknown> = {};\n          if (_isString(toolOutput.execution)) {\n            toolSearchCallExtras.execution = toolOutput.execution;\n          }\n          if (_isString(toolOutput.status)) {\n            toolSearchCallExtras.status = toolOutput.status;\n          }\n          if (_isString(toolOutput.call_id)) {\n            toolSearchCallExtras.call_id = toolOutput.call_id;\n          }\n          yield {\n            id: _isString(toolOutput.id) ? toolOutput.id : \"\",\n            type: \"server_tool_call\",\n            name: \"tool_search\",\n            args: toolSearchArgs,\n            ...(Object.keys(toolSearchCallExtras).length > 0\n              ? { extras: toolSearchCallExtras }\n              : {}),\n          };\n          continue;\n        } else if (_isContentBlock(toolOutput, \"tool_search_output\")) {\n          const toolSearchOutputExtras: Record<string, unknown> = {\n            name: \"tool_search\",\n          };\n          if (_isString(toolOutput.execution)) {\n            toolSearchOutputExtras.execution = toolOutput.execution;\n          }\n          yield {\n            type: \"server_tool_call_result\",\n            toolCallId: _isString(toolOutput.id) ? toolOutput.id : \"\",\n            status:\n              toolOutput.status === \"completed\"\n                ? \"success\"\n                : toolOutput.status === \"failed\"\n                  ? \"error\"\n                  : \"success\",\n            output: {\n              tools: _isArray(toolOutput.tools) ? toolOutput.tools : [],\n            },\n            extras: toolSearchOutputExtras,\n          };\n          continue;\n        } else if (_isContentBlock(toolOutput, \"image_generation_call\")) {\n          // Convert image_generation_call to proper image content block if result is available\n          if (_isString(toolOutput.result)) {\n            yield {\n              type: \"image\",\n              mimeType: \"image/png\",\n              data: toolOutput.result,\n              id: _isString(toolOutput.id) ? toolOutput.id : undefined,\n              metadata: {\n                status: _isString(toolOutput.status)\n                  ? toolOutput.status\n                  : undefined,\n              },\n            };\n          }\n          // Also yield as non_standard for backwards compatibility\n          yield { type: \"non_standard\", value: toolOutput };\n          continue;\n        }\n        if (_isObject(toolOutput)) {\n          yield { type: \"non_standard\", value: toolOutput };\n        }\n      }\n    }\n  }\n  return Array.from(iterateContent());\n}\n\n/**\n * Converts a ChatOpenAIResponses message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk containing OpenAI-specific content blocks\n * and converts them to the standardized v1 content block format. It handles both the\n * regular message content and tool call chunks that are specific to streaming responses.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const messageChunk = new AIMessageChunk({\n *   content: [{ type: \"text\", text: \"Hello\" }],\n *   tool_call_chunks: [\n *     { id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n *   ]\n * });\n *\n * const standardBlocks = convertToV1FromResponsesChunk(messageChunk);\n * // Returns:\n * // [\n * //   { type: \"text\", text: \"Hello\" },\n * //   { type: \"tool_call_chunk\", id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * // ]\n * ```\n */\nexport function convertToV1FromResponsesChunk(\n  message: AIMessageChunk\n): Array<ContentBlock.Standard> {\n  function* iterateContent(): Iterable<ContentBlock.Standard> {\n    yield* convertToV1FromResponses(message);\n    for (const toolCallChunk of message.tool_call_chunks ?? []) {\n      yield {\n        type: \"tool_call_chunk\",\n        id: toolCallChunk.id,\n        name: toolCallChunk.name,\n        args: toolCallChunk.args,\n      };\n    }\n  }\n  return Array.from(iterateContent());\n}\n\nexport const ChatOpenAITranslator: StandardContentBlockTranslator = {\n  translateContent: (message) => {\n    if (typeof message.content === \"string\") {\n      return convertToV1FromChatCompletions(message);\n    }\n    return convertToV1FromResponses(message);\n  },\n  translateContentChunk: (message) => {\n    if (typeof message.content === \"string\") {\n      return convertToV1FromChatCompletionsChunk(message);\n    }\n    return convertToV1FromResponsesChunk(message);\n  },\n};\n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