{"version":3,"file":"openai.cjs","names":["isOpenAIDataBlock","convertToV1FromOpenAIDataBlock","_isArray","_isObject","_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/** Builds a reasoning content block, including id/encrypted_content when present. */\nfunction mapReasoningItemToV1(\n  item: Record<string, unknown>\n): ContentBlock.Standard | undefined {\n  if (!_isArray(item.summary)) return undefined;\n  const summary = item.summary.reduce<string>((acc, part) => {\n    if (_isObject(part) && _isString(part.text)) {\n      return `${acc}${part.text}`;\n    }\n    return acc;\n  }, \"\");\n  return {\n    type: \"reasoning\",\n    reasoning: summary,\n    ...(_isString(item.id) ? { id: item.id } : {}),\n    ...(_isString(item.encrypted_content)\n      ? { encrypted_content: item.encrypted_content }\n      : {}),\n  } as ContentBlock.Standard;\n}\n\n// Converts a single built-in tool call/result entry into v1 content blocks.\nfunction* mapToolOutputToV1Blocks(\n  toolOutput: unknown\n): Iterable<ContentBlock.Standard> {\n  if (_isContentBlock(toolOutput, \"web_search_call\")) {\n    const webSearchArgs: Record<string, unknown> = {};\n    if (_isObject(toolOutput.action) && _isString(toolOutput.action.query)) {\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 (toolOutput.status === \"completed\" || toolOutput.status === \"failed\") {\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    return;\n  }\n  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 (toolOutput.status === \"completed\" || toolOutput.status === \"failed\") {\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    return;\n  }\n  if (_isContentBlock(toolOutput, \"computer_call\")) {\n    yield { type: \"non_standard\", value: toolOutput };\n    return;\n  }\n  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        }\n      }\n    }\n    return;\n  }\n  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    return;\n  }\n  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    return;\n  }\n  if (_isContentBlock(toolOutput, \"mcp_approval_request\")) {\n    yield { type: \"non_standard\", value: toolOutput };\n    return;\n  }\n  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    return;\n  }\n  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    return;\n  }\n  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) ? toolOutput.status : undefined,\n        },\n      };\n    }\n    // Also yield as non_standard for backwards compatibility\n    yield { type: \"non_standard\", value: toolOutput };\n    return;\n  }\n  if (_isObject(toolOutput)) {\n    yield { type: \"non_standard\", value: toolOutput };\n  }\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 * A response can hold more than one reasoning item (e.g. multiple tool calls\n * in one turn, common on GPT-5.6-class models). When `response_metadata.output`\n * is available, each item's own `id`/`encrypted_content` is preserved and\n * blocks are sorted back into original order, so replay under Zero Data\n * Retention interleaves reasoning and tool calls correctly. Without it (e.g.\n * a hand-built message), falls back to a single reasoning block from\n * `additional_kwargs.reasoning`, as before.\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: \"server_tool_call\", name: \"code_interpreter\", args: { code: \"print('hello')\" } },\n * //   { type: \"server_tool_call_result\", toolCallId: \"\", status: \"success\", output: { type: \"code_interpreter_output\", returnCode: 0, stdout: \"hello\" } }\n * // ]\n * ```\n */\nexport function convertToV1FromResponses(\n  message: AIMessage\n): Array<ContentBlock.Standard> {\n  const rawOutput = message.response_metadata?.output;\n  const hasRawOutput = _isArray(rawOutput) && rawOutput.length > 0;\n\n  // Maps a per-item key (namespaced by type, since ids aren't globally unique) to its original response.output position.\n  const positionByKey = new Map<string, number>();\n  let messageItemCount = 0;\n  let onlyMessageItemIndex: number | undefined;\n  if (hasRawOutput) {\n    (rawOutput as unknown[]).forEach((rawItem, index) => {\n      if (!_isObject(rawItem) || !_isString(rawItem.type)) return;\n      if (rawItem.type === \"reasoning\" && _isString(rawItem.id)) {\n        positionByKey.set(`reasoning:${rawItem.id}`, index);\n      } else if (\n        // These three types all become tool_call blocks keyed by call_id.\n        (rawItem.type === \"function_call\" ||\n          rawItem.type === \"custom_tool_call\" ||\n          rawItem.type === \"computer_call\") &&\n        _isString(rawItem.call_id)\n      ) {\n        positionByKey.set(`tool_call:${rawItem.call_id}`, index);\n      } else if (rawItem.type === \"message\") {\n        messageItemCount += 1;\n        onlyMessageItemIndex = index;\n      } else if (_isString(rawItem.id)) {\n        positionByKey.set(`other:${rawItem.type}:${rawItem.id}`, index);\n      }\n    });\n  }\n  // Text isn't keyed to a specific \"message\" item, so only position it when exactly one exists (an unambiguous match).\n  const textBlockKey =\n    messageItemCount === 1 && onlyMessageItemIndex != null\n      ? `message:${onlyMessageItemIndex}`\n      : undefined;\n  if (textBlockKey != null) {\n    positionByKey.set(textBlockKey, onlyMessageItemIndex as number);\n  }\n\n  function* iterateContent(): Iterable<\n    [block: ContentBlock.Standard, key: string | undefined]\n  > {\n    if (hasRawOutput) {\n      for (const rawItem of rawOutput as unknown[]) {\n        if (_isObject(rawItem) && rawItem.type === \"reasoning\") {\n          const block = mapReasoningItemToV1(rawItem);\n          if (block) {\n            yield [\n              block,\n              _isString(rawItem.id) ? `reasoning:${rawItem.id}` : undefined,\n            ];\n          }\n        }\n      }\n    } else if (\n      _isObject(message.additional_kwargs?.reasoning) &&\n      _isArray(message.additional_kwargs.reasoning.summary)\n    ) {\n      const block = mapReasoningItemToV1(message.additional_kwargs.reasoning);\n      if (block) yield [block, undefined];\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        yield [\n          {\n            ...rest,\n            ...extrasSpread,\n            type: \"text\",\n            text: String(text),\n            ...(Array.isArray(annotations)\n              ? { annotations: annotations.map(convertResponsesAnnotation) }\n              : {}),\n          },\n          textBlockKey,\n        ];\n      }\n    }\n    for (const toolCall of message.tool_calls ?? []) {\n      yield [\n        {\n          type: \"tool_call\",\n          id: toolCall.id,\n          name: toolCall.name,\n          args: toolCall.args,\n        },\n        toolCall.id ? `tool_call:${toolCall.id}` : undefined,\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        // All blocks from one tool output share this key -- fine since the API returns a call and its result as one item.\n        const key =\n          _isObject(toolOutput) &&\n          _isString(toolOutput.type) &&\n          _isString(toolOutput.id)\n            ? `other:${toolOutput.type}:${toolOutput.id}`\n            : undefined;\n        for (const block of mapToolOutputToV1Blocks(toolOutput)) {\n          yield [block, key];\n        }\n      }\n    }\n  }\n\n  const withKeys = Array.from(iterateContent());\n  if (!hasRawOutput) {\n    return withKeys.map(([block]) => block);\n  }\n  // Stable sort by original position; unkeyed blocks sort last, in push order.\n  return withKeys\n    .map(([block, key], pushIndex) => ({\n      block,\n      pushIndex,\n      position: key != null ? positionByKey.get(key) : undefined,\n    }))\n    .sort((a, b) => {\n      const aPos = a.position ?? Number.POSITIVE_INFINITY;\n      const bPos = b.position ?? Number.POSITIVE_INFINITY;\n      if (aPos !== bPos) return aPos - bPos;\n      return a.pushIndex - b.pushIndex;\n    })\n    .map((entry) => entry.block);\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,+BACd,SAC8B;CAC9B,MAAM,SAAuC,CAAC;CAC9C,IAAI,OAAO,QAAQ,YAAY,UAEzB;MAAA,QAAQ,QAAQ,SAAS,GAC3B,OAAO,KAAK;GACV,MAAM;GACN,MAAM,QAAQ;EAChB,CAAC;CAAA,OAGH,OAAO,KAAK,GAAG,oCAAoC,QAAQ,OAAO,CAAC;CAErE,KAAK,MAAM,YAAY,QAAQ,cAAc,CAAC,GAC5C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,S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