@fractaal/pi-ai 0.86.9 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -45
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +180 -141
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/azure-openai-responses.d.ts.map +1 -1
- package/dist/api/azure-openai-responses.js +8 -10
- package/dist/api/azure-openai-responses.js.map +1 -1
- package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/dist/api/bedrock-converse-stream.js +130 -96
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/classifier-shared.d.ts +21 -0
- package/dist/api/classifier-shared.d.ts.map +1 -0
- package/dist/api/classifier-shared.js +99 -0
- package/dist/api/classifier-shared.js.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.d.ts.map +1 -1
- package/dist/api/cloudflare-workers-ai-system-one.js +10 -1
- package/dist/api/cloudflare-workers-ai-system-one.js.map +1 -1
- package/dist/api/constrained-sampling.d.ts +11 -1
- package/dist/api/constrained-sampling.d.ts.map +1 -1
- package/dist/api/constrained-sampling.js +33 -18
- package/dist/api/constrained-sampling.js.map +1 -1
- package/dist/api/google-generative-ai.d.ts.map +1 -1
- package/dist/api/google-generative-ai.js +4 -10
- package/dist/api/google-generative-ai.js.map +1 -1
- package/dist/api/google-shared.d.ts +2 -1
- package/dist/api/google-shared.d.ts.map +1 -1
- package/dist/api/google-shared.js +60 -3
- package/dist/api/google-shared.js.map +1 -1
- package/dist/api/google-vertex.d.ts.map +1 -1
- package/dist/api/google-vertex.js +9 -15
- package/dist/api/google-vertex.js.map +1 -1
- package/dist/api/lazy.d.ts +7 -2
- package/dist/api/lazy.d.ts.map +1 -1
- package/dist/api/lazy.js +28 -8
- package/dist/api/lazy.js.map +1 -1
- package/dist/api/llama-cpp-classify.d.ts.map +1 -1
- package/dist/api/llama-cpp-classify.js +4 -1
- package/dist/api/llama-cpp-classify.js.map +1 -1
- package/dist/api/mistral-conversations.d.ts.map +1 -1
- package/dist/api/mistral-conversations.js +50 -60
- package/dist/api/mistral-conversations.js.map +1 -1
- package/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/api/openai-codex-responses.js +23 -14
- package/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/api/openai-completions.js +83 -87
- package/dist/api/openai-completions.js.map +1 -1
- package/dist/api/openai-decisions.d.ts +4 -0
- package/dist/api/openai-decisions.d.ts.map +1 -0
- package/dist/api/openai-decisions.js +162 -0
- package/dist/api/openai-decisions.js.map +1 -0
- package/dist/api/openai-decisions.lazy.d.ts +3 -0
- package/dist/api/openai-decisions.lazy.d.ts.map +1 -0
- package/dist/api/openai-decisions.lazy.js +4 -0
- package/dist/api/openai-decisions.lazy.js.map +1 -0
- package/dist/api/openai-responses-shared.d.ts +26 -0
- package/dist/api/openai-responses-shared.d.ts.map +1 -1
- package/dist/api/openai-responses-shared.js +132 -66
- package/dist/api/openai-responses-shared.js.map +1 -1
- package/dist/api/openai-responses.d.ts.map +1 -1
- package/dist/api/openai-responses.js +38 -19
- package/dist/api/openai-responses.js.map +1 -1
- package/dist/api/openrouter-images.d.ts.map +1 -1
- package/dist/api/openrouter-images.js +5 -3
- package/dist/api/openrouter-images.js.map +1 -1
- package/dist/api/pi-messages.d.ts +2 -0
- package/dist/api/pi-messages.d.ts.map +1 -1
- package/dist/api/pi-messages.js +18 -12
- package/dist/api/pi-messages.js.map +1 -1
- package/dist/api/simple-options.d.ts.map +1 -1
- package/dist/api/simple-options.js +2 -1
- package/dist/api/simple-options.js.map +1 -1
- package/dist/api/system-one-shared.d.ts +29 -3
- package/dist/api/system-one-shared.d.ts.map +1 -1
- package/dist/api/system-one-shared.js +54 -86
- package/dist/api/system-one-shared.js.map +1 -1
- package/dist/api/transform-messages.d.ts +16 -1
- package/dist/api/transform-messages.d.ts.map +1 -1
- package/dist/api/transform-messages.js +28 -15
- package/dist/api/transform-messages.js.map +1 -1
- package/dist/api/typesafe-system-one.d.ts.map +1 -1
- package/dist/api/typesafe-system-one.js +12 -1
- package/dist/api/typesafe-system-one.js.map +1 -1
- package/dist/auth/oauth/anthropic.d.ts.map +1 -1
- package/dist/auth/oauth/anthropic.js +14 -6
- package/dist/auth/oauth/anthropic.js.map +1 -1
- package/dist/auth/oauth/openai-chatgpt.js +1 -1
- package/dist/auth/oauth/openai-chatgpt.js.map +1 -1
- package/dist/auth/oauth/openai-codex.d.ts.map +1 -1
- package/dist/auth/oauth/openai-codex.js +4 -4
- package/dist/auth/oauth/openai-codex.js.map +1 -1
- package/dist/auth/types.d.ts +9 -0
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/compat/extension-oauth-types.d.ts +4 -0
- package/dist/compat/extension-oauth-types.d.ts.map +1 -1
- package/dist/compat/extension-oauth-types.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +9 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +23 -7
- package/dist/models.js.map +1 -1
- package/dist/providers/compat-schema.d.ts +509 -0
- package/dist/providers/compat-schema.d.ts.map +1 -0
- package/dist/providers/compat-schema.js +396 -0
- package/dist/providers/compat-schema.js.map +1 -0
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/providers/data/anthropic.json +1 -1
- package/dist/providers/data/azure.json +1 -1
- package/dist/providers/data/baseten.json +1 -1
- package/dist/providers/data/cerebras.json +1 -1
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/dist/providers/data/fireworks.json +1 -1
- package/dist/providers/data/github-copilot.json +1 -1
- package/dist/providers/data/google-vertex.json +1 -1
- package/dist/providers/data/google.json +1 -1
- package/dist/providers/data/groq.json +1 -1
- package/dist/providers/data/huggingface.json +1 -1
- package/dist/providers/data/kimi-coding.json +1 -1
- package/dist/providers/data/meta.json +1 -1
- package/dist/providers/data/minimax-cn.json +1 -1
- package/dist/providers/data/minimax.json +1 -1
- package/dist/providers/data/mistral.json +1 -1
- package/dist/providers/data/moonshotai-cn.json +1 -1
- package/dist/providers/data/moonshotai.json +1 -1
- package/dist/providers/data/nvidia.json +1 -1
- package/dist/providers/data/openai-codex.json +1 -1
- package/dist/providers/data/openai.json +1 -1
- package/dist/providers/data/opencode-go.json +1 -1
- package/dist/providers/data/opencode.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/providers/data/radius.json +1 -1
- package/dist/providers/data/together.json +1 -1
- package/dist/providers/data/typesafe.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/data/xai.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
- package/dist/providers/data/xiaomi.json +1 -1
- package/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/providers/faux.d.ts.map +1 -1
- package/dist/providers/faux.js +31 -9
- package/dist/providers/faux.js.map +1 -1
- package/dist/providers/kimi-coding.d.ts +1 -1
- package/dist/providers/kimi-coding.js +3 -3
- package/dist/providers/kimi-coding.js.map +1 -1
- package/dist/providers/model-schema.d.ts +91 -0
- package/dist/providers/model-schema.d.ts.map +1 -0
- package/dist/providers/model-schema.js +57 -0
- package/dist/providers/model-schema.js.map +1 -0
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +12 -3
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/opencode-go.d.ts +3 -1
- package/dist/providers/opencode-go.d.ts.map +1 -1
- package/dist/providers/opencode-go.js +2 -0
- package/dist/providers/opencode-go.js.map +1 -1
- package/dist/providers/openrouter-api.d.ts +40 -0
- package/dist/providers/openrouter-api.d.ts.map +1 -0
- package/dist/providers/openrouter-api.js +41 -0
- package/dist/providers/openrouter-api.js.map +1 -0
- package/dist/providers/openrouter.d.ts +11 -1
- package/dist/providers/openrouter.d.ts.map +1 -1
- package/dist/providers/openrouter.js +52 -1
- package/dist/providers/openrouter.js.map +1 -1
- package/dist/providers/radius-config.d.ts.map +1 -1
- package/dist/providers/radius-config.js +2 -1
- package/dist/providers/radius-config.js.map +1 -1
- package/dist/providers/radius.d.ts.map +1 -1
- package/dist/providers/radius.js +4 -12
- package/dist/providers/radius.js.map +1 -1
- package/dist/telemetry.d.ts +288 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +192 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/types.d.ts +44 -307
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/error-body.d.ts.map +1 -1
- package/dist/utils/error-body.js +2 -1
- package/dist/utils/error-body.js.map +1 -1
- package/dist/utils/estimate.js +1 -1
- package/dist/utils/estimate.js.map +1 -1
- package/dist/utils/event-stream.d.ts +10 -1
- package/dist/utils/event-stream.d.ts.map +1 -1
- package/dist/utils/event-stream.js +25 -0
- package/dist/utils/event-stream.js.map +1 -1
- package/dist/utils/identity.d.ts +65 -0
- package/dist/utils/identity.d.ts.map +1 -0
- package/dist/utils/identity.js +141 -0
- package/dist/utils/identity.js.map +1 -0
- package/dist/utils/json-parse.d.ts +10 -0
- package/dist/utils/json-parse.d.ts.map +1 -1
- package/dist/utils/json-parse.js +26 -1
- package/dist/utils/json-parse.js.map +1 -1
- package/dist/utils/model-operations.d.ts +3 -1
- package/dist/utils/model-operations.d.ts.map +1 -1
- package/dist/utils/model-operations.js +6 -0
- package/dist/utils/model-operations.js.map +1 -1
- package/dist/utils/openrouter-cost.d.ts +24 -0
- package/dist/utils/openrouter-cost.d.ts.map +1 -0
- package/dist/utils/openrouter-cost.js +34 -0
- package/dist/utils/openrouter-cost.js.map +1 -0
- package/dist/utils/overflow.d.ts +1 -0
- package/dist/utils/overflow.d.ts.map +1 -1
- package/dist/utils/overflow.js +6 -1
- package/dist/utils/overflow.js.map +1 -1
- package/dist/utils/provider-retry.d.ts +2 -0
- package/dist/utils/provider-retry.d.ts.map +1 -1
- package/dist/utils/provider-retry.js +2 -0
- package/dist/utils/provider-retry.js.map +1 -1
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +26 -10
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/streaming-json.d.ts +84 -0
- package/dist/utils/streaming-json.d.ts.map +1 -0
- package/dist/utils/streaming-json.js +513 -0
- package/dist/utils/streaming-json.js.map +1 -0
- package/dist/utils/text.d.ts +7 -0
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js +9 -0
- package/dist/utils/text.js.map +1 -1
- package/dist/utils/transcript.d.ts +22 -8
- package/dist/utils/transcript.d.ts.map +1 -1
- package/dist/utils/transcript.js +29 -18
- package/dist/utils/transcript.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +3 -0
- package/dist/utils/validation.js.map +1 -1
- package/dist/utils/version.d.ts +2 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +3 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +3 -3
- package/dist/utils/assistant-message-frame.d.ts +0 -77
- package/dist/utils/assistant-message-frame.d.ts.map +0 -1
- package/dist/utils/assistant-message-frame.js +0 -425
- package/dist/utils/assistant-message-frame.js.map +0 -1
- package/dist/utils/pi-user-agent.d.ts +0 -2
- package/dist/utils/pi-user-agent.d.ts.map +0 -1
- package/dist/utils/pi-user-agent.js +0 -12
- package/dist/utils/pi-user-agent.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"azure-openai-responses.js","sourceRoot":"","sources":["../../src/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BAA6B,CAAC,CAAC;QAClD,CAAC;aAAM,IAAI,KAAK,CAAC,gBAAgB,EAAE,GAAG,KAAK,IAAI,EAAE,CAAC;YACjD,MAAM,CAAC,SAAS,GAAG;gBAClB,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,GAAG,IAAI,MAAM,CAAmD;aACjG,CAAC;QACH,CAAC;IACF,CAAC;IAED,+EAA+E;IAC/E,MAAM,cAAc,GAAG,qBAAqB,CAAC,KAAK,EAAE,eAAe,IAAI,KAAK,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IACvG,IAAI,cAAc,EAAE,CAAC;QACpB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { AzureOpenAI } from \"openai\";\nimport type { ResponseCreateParamsStreaming } from \"openai/resources/responses/responses.js\";\nimport { clampThinkingLevel } from \"../models.ts\";\nimport type { Api, AssistantMessage, Model, SimpleStreamOptions, StreamFunction, TranscriptContext } from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { headersToRecord } from \"../utils/headers.ts\";\nimport { getPiUserAgent } from \"../utils/pi-user-agent.ts\";\nimport { retryProviderRequest } from \"../utils/provider-retry.ts\";\nimport { getDeclaredTools, resolveTranscript, resolveTranscriptTools } from \"../utils/transcript.ts\";\nimport { type AzureEndpointOptions, resolveAzureConfig, resolveDeploymentName } from \"./azure-openai-config.ts\";\nimport { createGrammarToolInputProperties } from \"./constrained-sampling.ts\";\nimport { clampOpenAIPromptCacheKey } from \"./openai-prompt-cache.ts\";\nimport { convertResponsesMessages, convertResponsesTools, processResponsesStream } from \"./openai-responses-shared.ts\";\nimport { buildBaseOptions, resolveSamplingParams } from \"./simple-options.ts\";\n\nconst AZURE_TOOL_CALL_PROVIDERS = new Set([\"openai\", \"openai-codex\", \"opencode\", \"azure\"]);\n// OpenAI Responses rejects max_output_tokens below 16: https://github.com/earendil-works/pi/issues/6265\nconst OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;\n\nfunction formatAzureOpenAIError(error: unknown): string {\n\treturn formatProviderError(normalizeProviderError(error), \"Azure OpenAI API error\");\n}\n\n// Azure OpenAI Responses-specific options\nexport interface AzureOpenAIResponsesOptions extends AzureEndpointOptions {\n\treasoningEffort?: \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\" | \"max\";\n\ttoolChoice?: ResponseCreateParamsStreaming[\"tool_choice\"];\n\treasoningSummary?: \"auto\" | \"detailed\" | \"concise\" | null;\n}\n\n/**\n * Generate function for Azure OpenAI Responses API\n */\nexport const stream: StreamFunction<\"azure-openai-responses\", AzureOpenAIResponsesOptions> = (\n\tmodel: Model<\"azure-openai-responses\">,\n\tcontext: TranscriptContext,\n\toptions?: AzureOpenAIResponsesOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\tconst normalizedContext = resolveTranscript(context, model.compat?.supportsMidConvoSystemMessages);\n\n\t// Start async processing\n\t(async () => {\n\t\tconst deploymentName = resolveDeploymentName(model, options);\n\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: \"azure-openai-responses\" as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"pending\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\ttry {\n\t\t\t// Create Azure OpenAI client\n\t\t\tconst apiKey = options?.apiKey;\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t\t\t}\n\t\t\tconst client = createClient(model, apiKey, options);\n\t\t\tconst grammarToolInputProperties = createGrammarToolInputProperties(\n\t\t\t\tgetDeclaredTools(normalizedContext.messages),\n\t\t\t\tmodel.compat?.supportsOpenAIGrammarTools ?? false,\n\t\t\t);\n\t\t\tlet params = buildParams(model, normalizedContext, options, deploymentName, grammarToolInputProperties);\n\t\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\t\tif (nextParams !== undefined) {\n\t\t\t\tparams = nextParams as ResponseCreateParamsStreaming;\n\t\t\t}\n\t\t\tconst requestOptions = {\n\t\t\t\t...(options?.signal ? { signal: options.signal } : {}),\n\t\t\t\t...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),\n\t\t\t\tmaxRetries: 0,\n\t\t\t};\n\t\t\tconst { data: openaiStream, response } = await retryProviderRequest(\n\t\t\t\t() => client.responses.create(params, requestOptions).withResponse(),\n\t\t\t\t{\n\t\t\t\t\tmaxRetries: options?.maxRetries,\n\t\t\t\t\tmaxRetryDelayMs: options?.maxRetryDelayMs,\n\t\t\t\t\tsignal: options?.signal,\n\t\t\t\t},\n\t\t\t);\n\t\t\tawait options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);\n\t\t\tstream.push({ type: \"start\", partial: output });\n\n\t\t\tawait processResponsesStream(openaiStream, output, stream, model, {\n\t\t\t\tonProviderStreamEvent: options?.onProviderStreamEvent,\n\t\t\t\tgrammarToolInputProperties,\n\t\t\t});\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"pending\") {\n\t\t\t\tthrow new Error(\"Azure OpenAI Responses stream ended without a stop reason\");\n\t\t\t}\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(output.errorMessage || \"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\tfor (const block of output.content) {\n\t\t\t\tdelete (block as { index?: number }).index;\n\t\t\t\t// Streaming scratch buffers are only used during parsing; never persist them.\n\t\t\t\tdelete (block as { partialJson?: string }).partialJson;\n\t\t\t\tdelete (block as { customInput?: unknown }).customInput;\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = formatAzureOpenAIError(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nexport const streamSimple: StreamFunction<\"azure-openai-responses\", SimpleStreamOptions> = (\n\tmodel: Model<\"azure-openai-responses\">,\n\tcontext: TranscriptContext,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst apiKey = options?.apiKey;\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\n\tconst base = {\n\t\t...buildBaseOptions(model, context, options, apiKey),\n\t\ttoolChoice: options?.toolChoice,\n\t} satisfies AzureOpenAIResponsesOptions;\n\tconst clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : undefined;\n\tconst reasoningEffort = clampedReasoning === \"off\" ? undefined : clampedReasoning;\n\n\treturn stream(model, context, {\n\t\t...base,\n\t\treasoningEffort,\n\t} satisfies AzureOpenAIResponsesOptions);\n};\n\nfunction createClient(model: Model<\"azure-openai-responses\">, apiKey: string, options?: AzureOpenAIResponsesOptions) {\n\tconst headers = { \"User-Agent\": getPiUserAgent(), ...model.headers };\n\n\tif (options?.headers) {\n\t\tObject.assign(headers, options.headers);\n\t}\n\n\tconst { baseUrl, apiVersion } = resolveAzureConfig(model, options);\n\n\treturn new AzureOpenAI({\n\t\tapiKey,\n\t\tapiVersion,\n\t\tdangerouslyAllowBrowser: true,\n\t\tfetch: options?.fetch,\n\t\tdefaultHeaders: headers,\n\t\tbaseURL: baseUrl,\n\t});\n}\n\nfunction buildParams(\n\tmodel: Model<\"azure-openai-responses\">,\n\tcontext: TranscriptContext,\n\toptions: AzureOpenAIResponsesOptions | undefined,\n\tdeploymentName: string,\n\tgrammarToolInputProperties: ReadonlyMap<string, string> = createGrammarToolInputProperties(\n\t\tgetDeclaredTools(context.messages),\n\t\tmodel.compat?.supportsOpenAIGrammarTools ?? false,\n\t),\n) {\n\tconst supportsAdditionalTools = model.compat?.supportsAdditionalTools ?? false;\n\tconst supportsToolSearch = model.compat?.supportsToolSearch ?? false;\n\tconst transcriptTools = resolveTranscriptTools(context.messages, supportsAdditionalTools || supportsToolSearch);\n\tconst messages = convertResponsesMessages(model, context, AZURE_TOOL_CALL_PROVIDERS, {\n\t\tgrammarToolInputProperties,\n\t\tsupportsMidConvoSystemMessages: model.compat?.supportsMidConvoSystemMessages ?? false,\n\t\tsupportsAdditionalTools,\n\t\tsupportsToolSearch,\n\t\ttoolOptions: {\n\t\t\tsupportsStrictMode: model.compat?.supportsStrictMode ?? true,\n\t\t\tsupportsOpenAIGrammarTools: model.compat?.supportsOpenAIGrammarTools ?? false,\n\t\t},\n\t});\n\n\tconst params: ResponseCreateParamsStreaming = {\n\t\tmodel: deploymentName,\n\t\tinput: messages,\n\t\tstream: true,\n\t\tprompt_cache_key: clampOpenAIPromptCacheKey(options?.sessionId),\n\t\tstore: false,\n\t};\n\n\tif (options?.maxTokens) {\n\t\tparams.max_output_tokens = Math.max(options.maxTokens, OPENAI_RESPONSES_MIN_OUTPUT_TOKENS);\n\t}\n\n\tif (options?.temperature !== undefined) {\n\t\tparams.temperature = options?.temperature;\n\t}\n\n\tif (transcriptTools.requestTools.length > 0) {\n\t\tparams.tools = convertResponsesTools(transcriptTools.requestTools, {\n\t\t\tsupportsStrictMode: model.compat?.supportsStrictMode ?? true,\n\t\t\tsupportsOpenAIGrammarTools: model.compat?.supportsOpenAIGrammarTools ?? false,\n\t\t});\n\t}\n\tif (options?.toolChoice !== undefined) {\n\t\tparams.tool_choice = options.toolChoice;\n\t}\n\n\tconst reasoningEffort = options?.reasoningEffort ?? (options?.reasoningSummary ? \"medium\" : undefined);\n\tif (model.reasoning) {\n\t\tif (reasoningEffort) {\n\t\t\tconst effort = options?.reasoningEffort\n\t\t\t\t? (model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort)\n\t\t\t\t: reasoningEffort;\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: effort as NonNullable<typeof params.reasoning>[\"effort\"],\n\t\t\t\tsummary: options?.reasoningSummary || \"auto\",\n\t\t\t};\n\t\t\tparams.include = [\"reasoning.encrypted_content\"];\n\t\t} else if (model.thinkingLevelMap?.off !== null) {\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: (model.thinkingLevelMap?.off ?? \"none\") as NonNullable<typeof params.reasoning>[\"effort\"],\n\t\t\t};\n\t\t}\n\t}\n\n\t// Last so model and request sampling parameters override named request fields.\n\tconst samplingParams = resolveSamplingParams(model, reasoningEffort ?? \"off\", options?.samplingParams);\n\tif (samplingParams) {\n\t\tObject.assign(params, samplingParams);\n\t}\n\n\treturn params;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"azure-openai-responses.js","sourceRoot":"","sources":["../../src/api/azure-openai-responses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,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} from \"openai\";\nimport type { ResponseCreateParamsStreaming } from \"openai/resources/responses/responses.js\";\nimport { clampThinkingLevel } from \"../models.ts\";\nimport type { Api, AssistantMessage, Model, SimpleStreamOptions, StreamFunction, TranscriptContext } from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { headersToRecord } from \"../utils/headers.ts\";\nimport { getIdentityHeaders } from \"../utils/identity.ts\";\nimport { retryProviderRequest } from \"../utils/provider-retry.ts\";\nimport { getDeclaredTools, resolveTranscript, resolveTranscriptTools } from \"../utils/transcript.ts\";\nimport { type AzureEndpointOptions, resolveAzureConfig, resolveDeploymentName } from \"./azure-openai-config.ts\";\nimport { createGrammarToolInputProperties } from \"./constrained-sampling.ts\";\nimport { clampOpenAIPromptCacheKey } from \"./openai-prompt-cache.ts\";\nimport {\n\tconvertResponsesMessages,\n\tconvertResponsesTools,\n\tgetResponsesToolSupport,\n\tprocessResponsesStream,\n} from \"./openai-responses-shared.ts\";\nimport { buildBaseOptions, resolveSamplingParams } from \"./simple-options.ts\";\n\nconst AZURE_TOOL_CALL_PROVIDERS = new Set([\"openai\", \"openai-codex\", \"opencode\", \"azure\"]);\n// OpenAI Responses rejects max_output_tokens below 16: https://github.com/earendil-works/pi/issues/6265\nconst OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;\n\nfunction formatAzureOpenAIError(error: unknown): string {\n\treturn formatProviderError(normalizeProviderError(error), \"Azure OpenAI API error\");\n}\n\n// Azure OpenAI Responses-specific options\nexport interface AzureOpenAIResponsesOptions extends AzureEndpointOptions {\n\treasoningEffort?: \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\" | \"max\";\n\ttoolChoice?: ResponseCreateParamsStreaming[\"tool_choice\"];\n\treasoningSummary?: \"auto\" | \"detailed\" | \"concise\" | null;\n}\n\n/**\n * Generate function for Azure OpenAI Responses API\n */\nexport const stream: StreamFunction<\"azure-openai-responses\", AzureOpenAIResponsesOptions> = (\n\tmodel: Model<\"azure-openai-responses\">,\n\tcontext: TranscriptContext,\n\toptions?: AzureOpenAIResponsesOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\tconst normalizedContext = resolveTranscript(context, model.compat?.supportsMidConvoSystemMessages);\n\n\t// Start async processing\n\t(async () => {\n\t\tconst deploymentName = resolveDeploymentName(model, options);\n\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: \"azure-openai-responses\" as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"pending\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\ttry {\n\t\t\t// Create Azure OpenAI client\n\t\t\tconst apiKey = options?.apiKey;\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t\t\t}\n\t\t\tconst client = createClient(model, apiKey, options);\n\t\t\tconst grammarToolInputProperties = createGrammarToolInputProperties(\n\t\t\t\tgetDeclaredTools(normalizedContext.messages),\n\t\t\t\tmodel.compat?.supportsOpenAIGrammarTools ?? false,\n\t\t\t);\n\t\t\tlet params = buildParams(model, normalizedContext, options, deploymentName, grammarToolInputProperties);\n\t\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\t\tif (nextParams !== undefined) {\n\t\t\t\tparams = nextParams as ResponseCreateParamsStreaming;\n\t\t\t}\n\t\t\tconst requestOptions = {\n\t\t\t\t...(options?.signal ? { signal: options.signal } : {}),\n\t\t\t\t...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),\n\t\t\t\tmaxRetries: 0,\n\t\t\t};\n\t\t\tconst { data: openaiStream, response } = await retryProviderRequest(\n\t\t\t\t() => client.responses.create(params, requestOptions).withResponse(),\n\t\t\t\t{\n\t\t\t\t\tmaxRetries: options?.maxRetries,\n\t\t\t\t\tmaxRetryDelayMs: options?.maxRetryDelayMs,\n\t\t\t\t\tsignal: options?.signal,\n\t\t\t\t},\n\t\t\t);\n\t\t\tawait options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);\n\t\t\tstream.push({ type: \"start\", partial: output });\n\n\t\t\tawait processResponsesStream(openaiStream, output, stream, model, {\n\t\t\t\tonProviderStreamEvent: options?.onProviderStreamEvent,\n\t\t\t\tgrammarToolInputProperties,\n\t\t\t});\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"pending\") {\n\t\t\t\tthrow new Error(\"Azure OpenAI Responses stream ended without a stop reason\");\n\t\t\t}\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(output.errorMessage || \"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = formatAzureOpenAIError(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nexport const streamSimple: StreamFunction<\"azure-openai-responses\", SimpleStreamOptions> = (\n\tmodel: Model<\"azure-openai-responses\">,\n\tcontext: TranscriptContext,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst apiKey = options?.apiKey;\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\n\tconst base = {\n\t\t...buildBaseOptions(model, context, options, apiKey),\n\t\ttoolChoice: options?.toolChoice,\n\t} satisfies AzureOpenAIResponsesOptions;\n\tconst clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : undefined;\n\tconst reasoningEffort = clampedReasoning === \"off\" ? undefined : clampedReasoning;\n\n\treturn stream(model, context, {\n\t\t...base,\n\t\treasoningEffort,\n\t} satisfies AzureOpenAIResponsesOptions);\n};\n\nfunction createClient(model: Model<\"azure-openai-responses\">, apiKey: string, options?: AzureOpenAIResponsesOptions) {\n\tconst headers = { ...getIdentityHeaders(model, options?.identity), ...model.headers };\n\n\tif (options?.headers) {\n\t\tObject.assign(headers, options.headers);\n\t}\n\n\tconst { baseUrl, apiVersion } = resolveAzureConfig(model, options);\n\n\treturn new AzureOpenAI({\n\t\tapiKey,\n\t\tapiVersion,\n\t\tdangerouslyAllowBrowser: true,\n\t\tfetch: options?.fetch,\n\t\tdefaultHeaders: headers,\n\t\tbaseURL: baseUrl,\n\t});\n}\n\nfunction buildParams(\n\tmodel: Model<\"azure-openai-responses\">,\n\tcontext: TranscriptContext,\n\toptions: AzureOpenAIResponsesOptions | undefined,\n\tdeploymentName: string,\n\tgrammarToolInputProperties: ReadonlyMap<string, string> = createGrammarToolInputProperties(\n\t\tgetDeclaredTools(context.messages),\n\t\tmodel.compat?.supportsOpenAIGrammarTools ?? false,\n\t),\n) {\n\tconst supportsAdditionalTools = model.compat?.supportsAdditionalTools ?? false;\n\tconst supportsToolSearch = model.compat?.supportsToolSearch ?? false;\n\tconst transcriptTools = resolveTranscriptTools(\n\t\tcontext.messages,\n\t\tgetResponsesToolSupport({\n\t\t\tsupportsMidConvoSystemMessages: model.compat?.supportsMidConvoSystemMessages ?? false,\n\t\t\tsupportsAdditionalTools,\n\t\t\tsupportsToolSearch,\n\t\t}),\n\t);\n\tconst messages = convertResponsesMessages(model, context, AZURE_TOOL_CALL_PROVIDERS, {\n\t\tgrammarToolInputProperties,\n\t\tsupportsMidConvoSystemMessages: model.compat?.supportsMidConvoSystemMessages ?? false,\n\t\tsupportsAdditionalTools,\n\t\tsupportsToolSearch,\n\t\ttoolOptions: {\n\t\t\tsupportsStrictMode: model.compat?.supportsStrictMode ?? true,\n\t\t\tsupportsOpenAIGrammarTools: model.compat?.supportsOpenAIGrammarTools ?? false,\n\t\t},\n\t});\n\n\tconst params: ResponseCreateParamsStreaming = {\n\t\tmodel: deploymentName,\n\t\tinput: messages,\n\t\tstream: true,\n\t\tprompt_cache_key: clampOpenAIPromptCacheKey(options?.sessionId),\n\t\tstore: false,\n\t};\n\n\tif (options?.maxTokens) {\n\t\tparams.max_output_tokens = Math.max(options.maxTokens, OPENAI_RESPONSES_MIN_OUTPUT_TOKENS);\n\t}\n\n\tif (options?.temperature !== undefined) {\n\t\tparams.temperature = options?.temperature;\n\t}\n\n\tif (transcriptTools.requestTools.length > 0) {\n\t\tparams.tools = convertResponsesTools(transcriptTools.requestTools, {\n\t\t\tsupportsStrictMode: model.compat?.supportsStrictMode ?? true,\n\t\t\tsupportsOpenAIGrammarTools: model.compat?.supportsOpenAIGrammarTools ?? false,\n\t\t});\n\t}\n\tif (options?.toolChoice !== undefined) {\n\t\tparams.tool_choice = options.toolChoice;\n\t}\n\n\tconst reasoningEffort = options?.reasoningEffort ?? (options?.reasoningSummary ? \"medium\" : undefined);\n\tif (model.reasoning) {\n\t\tif (reasoningEffort) {\n\t\t\tconst effort = options?.reasoningEffort\n\t\t\t\t? (model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort)\n\t\t\t\t: reasoningEffort;\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: effort as NonNullable<typeof params.reasoning>[\"effort\"],\n\t\t\t\tsummary: options?.reasoningSummary || \"auto\",\n\t\t\t};\n\t\t\tparams.include = [\"reasoning.encrypted_content\"];\n\t\t} else if (model.thinkingLevelMap?.off !== null) {\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: (model.thinkingLevelMap?.off ?? \"none\") as NonNullable<typeof params.reasoning>[\"effort\"],\n\t\t\t};\n\t\t}\n\t}\n\n\t// Last so model and request sampling parameters override named request fields.\n\tconst samplingParams = resolveSamplingParams(model, reasoningEffort ?? \"off\", options?.samplingParams);\n\tif (samplingParams) {\n\t\tObject.assign(params, samplingParams);\n\t}\n\n\treturn params;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bedrock-converse-stream.d.ts","sourceRoot":"","sources":["../../src/api/bedrock-converse-stream.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAUX,mBAAmB,EAEnB,cAAc,EACd,aAAa,EAEb,eAAe,
|
|
1
|
+
{"version":3,"file":"bedrock-converse-stream.d.ts","sourceRoot":"","sources":["../../src/api/bedrock-converse-stream.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAUX,mBAAmB,EAEnB,cAAc,EACd,aAAa,EAEb,eAAe,EACf,aAAa,EAGb,MAAM,aAAa,CAAC;AA2BrB,MAAM,MAAM,sBAAsB,GAAG,YAAY,GAAG,SAAS,CAAC;AAE9D,MAAM,WAAW,cAAe,SAAQ,aAAa;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAEtE,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,sBAAsB,CAAC;IACzC;;;sGAGkG;IAClG,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC;;;;yGAIqG;IACrG,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAsBD,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,yBAAyB,EAAE,cAAc,CA2O5E,CAAC;AAkLF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,yBAAyB,EAAE,mBAAmB,CAiDvF,CAAC"}
|
|
@@ -7,15 +7,16 @@ import { appendAssistantMessageDiagnostic } from "../utils/diagnostics.js";
|
|
|
7
7
|
import { normalizeProviderError } from "../utils/error-body.js";
|
|
8
8
|
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
9
9
|
import { providerHeadersToRecord } from "../utils/headers.js";
|
|
10
|
-
import {
|
|
10
|
+
import { getClientVersion } from "../utils/identity.js";
|
|
11
11
|
import { resolveHttpProxyUrlForTarget } from "../utils/node-http-proxy.js";
|
|
12
12
|
import { getProviderEnvValue } from "../utils/provider-env.js";
|
|
13
13
|
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
14
|
+
import { ToolCallArgumentsStream } from "../utils/streaming-json.js";
|
|
14
15
|
import { getSystemMessageText } from "../utils/text.js";
|
|
15
16
|
import { collapseSystemMessages, getCurrentTools, getInitialSystemMessage, withoutInitialSystemMessage, } from "../utils/transcript.js";
|
|
16
17
|
import { getJsonSchemaToolParameters, resolveJsonSchemaStrictSampling } from "./constrained-sampling.js";
|
|
17
18
|
import { adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToContext, clampReasoning, } from "./simple-options.js";
|
|
18
|
-
import { transformMessages } from "./transform-messages.js";
|
|
19
|
+
import { splitErrorToolResultImages, transformMessages } from "./transform-messages.js";
|
|
19
20
|
const EMPTY_TEXT_PLACEHOLDER = "<empty>";
|
|
20
21
|
const THINKING_BINDING_CONTROLS_BETA = "thinking-binding-controls-2026-08-01";
|
|
21
22
|
/** Matches the placeholder the Anthropic API path uses for redacted thinking. */
|
|
@@ -42,7 +43,7 @@ export const stream = (model, context, options = {}) => {
|
|
|
42
43
|
stopReason: "pending",
|
|
43
44
|
timestamp: Date.now(),
|
|
44
45
|
};
|
|
45
|
-
const
|
|
46
|
+
const openBlocks = new Map();
|
|
46
47
|
// A profile explicitly configured through pi's auth flow (the `profile`
|
|
47
48
|
// option or scoped `AWS_PROFILE` on the stored credential's env) must win
|
|
48
49
|
// over ambient AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY. The SDK default
|
|
@@ -51,6 +52,7 @@ export const stream = (model, context, options = {}) => {
|
|
|
51
52
|
const optionsProfile = options.profile || options.env?.AWS_PROFILE;
|
|
52
53
|
const config = {
|
|
53
54
|
profile: optionsProfile || getProviderEnvValue("AWS_PROFILE", options.env),
|
|
55
|
+
customUserAgent: bedrockUserAgent(options.identity),
|
|
54
56
|
};
|
|
55
57
|
const configuredRegion = getConfiguredBedrockRegion(options);
|
|
56
58
|
const hasAmbientConfiguredProfile = Boolean(getProviderEnvValue("AWS_PROFILE"));
|
|
@@ -178,13 +180,13 @@ export const stream = (model, context, options = {}) => {
|
|
|
178
180
|
stream.push({ type: "start", partial: output });
|
|
179
181
|
}
|
|
180
182
|
else if (item.contentBlockStart) {
|
|
181
|
-
handleContentBlockStart(item.contentBlockStart,
|
|
183
|
+
handleContentBlockStart(item.contentBlockStart, openBlocks, output, stream);
|
|
182
184
|
}
|
|
183
185
|
else if (item.contentBlockDelta) {
|
|
184
|
-
handleContentBlockDelta(item.contentBlockDelta,
|
|
186
|
+
handleContentBlockDelta(item.contentBlockDelta, openBlocks, output, stream);
|
|
185
187
|
}
|
|
186
188
|
else if (item.contentBlockStop) {
|
|
187
|
-
handleContentBlockStop(item.contentBlockStop,
|
|
189
|
+
handleContentBlockStop(item.contentBlockStop, openBlocks, output, stream);
|
|
188
190
|
}
|
|
189
191
|
else if (item.messageStop) {
|
|
190
192
|
output.rawStopReason = item.messageStop.stopReason;
|
|
@@ -223,15 +225,12 @@ export const stream = (model, context, options = {}) => {
|
|
|
223
225
|
throw new Error(output.errorMessage || "An unknown error occurred");
|
|
224
226
|
}
|
|
225
227
|
// A stream can settle without stopping every block, so finalize here too.
|
|
226
|
-
|
|
227
|
-
finalizeStreamingBlock(block);
|
|
228
|
+
flushOpenBlocks(openBlocks, output);
|
|
228
229
|
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
229
230
|
stream.end();
|
|
230
231
|
}
|
|
231
232
|
catch (error) {
|
|
232
|
-
|
|
233
|
-
finalizeStreamingBlock(block);
|
|
234
|
-
}
|
|
233
|
+
flushOpenBlocks(openBlocks, output);
|
|
235
234
|
output.stopReason = options.signal?.aborted ? "aborted" : "error";
|
|
236
235
|
output.errorMessage = formatBedrockError(error);
|
|
237
236
|
if (output.stopReason === "error") {
|
|
@@ -337,6 +336,16 @@ function isReservedHeader(key) {
|
|
|
337
336
|
const lower = key.toLowerCase();
|
|
338
337
|
return lower.startsWith("x-amz-") || RESERVED_HEADER_EXACT.has(lower);
|
|
339
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* The client identity as AWS SDK user agent pairs. The SDK appends them to its own `User-Agent` and escapes characters
|
|
341
|
+
* that are not valid in a user agent token, so the detailed form is reduced to name and version.
|
|
342
|
+
*/
|
|
343
|
+
function bedrockUserAgent(identity) {
|
|
344
|
+
const mode = identity?.userAgent ?? "detailed";
|
|
345
|
+
if (typeof mode === "object")
|
|
346
|
+
return mode.custom;
|
|
347
|
+
return mode === "short" ? [["pi"]] : [["pi", getClientVersion(identity)]];
|
|
348
|
+
}
|
|
340
349
|
/**
|
|
341
350
|
* Attach caller-supplied headers to the outgoing Bedrock request via a Smithy
|
|
342
351
|
* `build`-step middleware. The `build` step runs after request serialisation but
|
|
@@ -424,59 +433,60 @@ export const streamSimple = (model, context, options) => {
|
|
|
424
433
|
thinkingBudgets: options.thinkingBudgets,
|
|
425
434
|
});
|
|
426
435
|
};
|
|
427
|
-
function handleContentBlockStart(event,
|
|
428
|
-
const index = event.contentBlockIndex;
|
|
436
|
+
function handleContentBlockStart(event, openBlocks, output, stream) {
|
|
429
437
|
const start = event.start;
|
|
430
438
|
if (start?.toolUse) {
|
|
431
|
-
|
|
439
|
+
output.content.push({
|
|
432
440
|
type: "toolCall",
|
|
433
441
|
id: start.toolUse.toolUseId || "",
|
|
434
442
|
name: start.toolUse.name || "",
|
|
435
443
|
arguments: {},
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
stream.push({ type: "toolcall_start", contentIndex: blocks.length - 1, partial: output });
|
|
444
|
+
});
|
|
445
|
+
const contentIndex = output.content.length - 1;
|
|
446
|
+
openBlocks.set(event.contentBlockIndex, { contentIndex, arguments: new ToolCallArgumentsStream() });
|
|
447
|
+
stream.push({ type: "toolcall_start", contentIndex, partial: output });
|
|
441
448
|
}
|
|
442
449
|
}
|
|
443
|
-
function handleContentBlockDelta(event,
|
|
450
|
+
function handleContentBlockDelta(event, openBlocks, output, stream) {
|
|
444
451
|
const contentBlockIndex = event.contentBlockIndex;
|
|
445
452
|
const delta = event.delta;
|
|
446
|
-
let
|
|
447
|
-
let block =
|
|
453
|
+
let open = openBlocks.get(contentBlockIndex);
|
|
454
|
+
let block = open === undefined ? undefined : output.content[open.contentIndex];
|
|
448
455
|
if (delta?.text !== undefined) {
|
|
449
456
|
// If no text block exists yet, create one, as `handleContentBlockStart` is not sent for text blocks
|
|
450
|
-
if (!
|
|
451
|
-
|
|
452
|
-
output.content.
|
|
453
|
-
|
|
454
|
-
block =
|
|
455
|
-
stream.push({ type: "text_start", contentIndex:
|
|
457
|
+
if (!open) {
|
|
458
|
+
output.content.push({ type: "text", text: "" });
|
|
459
|
+
open = { contentIndex: output.content.length - 1 };
|
|
460
|
+
openBlocks.set(contentBlockIndex, open);
|
|
461
|
+
block = output.content[open.contentIndex];
|
|
462
|
+
stream.push({ type: "text_start", contentIndex: open.contentIndex, partial: output });
|
|
456
463
|
}
|
|
457
|
-
if (block
|
|
464
|
+
if (block?.type === "text") {
|
|
458
465
|
block.text += delta.text;
|
|
459
|
-
stream.push({ type: "text_delta", contentIndex:
|
|
466
|
+
stream.push({ type: "text_delta", contentIndex: open.contentIndex, delta: delta.text, partial: output });
|
|
460
467
|
}
|
|
461
468
|
}
|
|
462
|
-
else if (delta?.toolUse && block?.type === "toolCall") {
|
|
463
|
-
block.
|
|
464
|
-
|
|
465
|
-
|
|
469
|
+
else if (delta?.toolUse && block?.type === "toolCall" && open?.arguments !== undefined) {
|
|
470
|
+
block.arguments = open.arguments.append(delta.toolUse.input || "");
|
|
471
|
+
stream.push({
|
|
472
|
+
type: "toolcall_delta",
|
|
473
|
+
contentIndex: open.contentIndex,
|
|
474
|
+
delta: delta.toolUse.input || "",
|
|
475
|
+
partial: output,
|
|
476
|
+
});
|
|
466
477
|
}
|
|
467
478
|
else if (delta?.reasoningContent) {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
output.content.
|
|
473
|
-
|
|
474
|
-
thinkingBlock = blocks[thinkingIndex];
|
|
475
|
-
stream.push({ type: "thinking_start", contentIndex: thinkingIndex, partial: output });
|
|
479
|
+
if (!open) {
|
|
480
|
+
output.content.push({ type: "thinking", thinking: "", thinkingSignature: "" });
|
|
481
|
+
open = { contentIndex: output.content.length - 1 };
|
|
482
|
+
openBlocks.set(contentBlockIndex, open);
|
|
483
|
+
block = output.content[open.contentIndex];
|
|
484
|
+
stream.push({ type: "thinking_start", contentIndex: open.contentIndex, partial: output });
|
|
476
485
|
}
|
|
477
|
-
if (
|
|
486
|
+
if (block?.type === "thinking") {
|
|
487
|
+
const thinkingIndex = open.contentIndex;
|
|
478
488
|
if (delta.reasoningContent.text) {
|
|
479
|
-
|
|
489
|
+
block.thinking += delta.reasoningContent.text;
|
|
480
490
|
stream.push({
|
|
481
491
|
type: "thinking_delta",
|
|
482
492
|
contentIndex: thinkingIndex,
|
|
@@ -486,18 +496,17 @@ function handleContentBlockDelta(event, blocks, output, stream) {
|
|
|
486
496
|
}
|
|
487
497
|
// `thinkingSignature` holds either an Anthropic signature or an opaque redacted
|
|
488
498
|
// payload, never both: mixing them would corrupt whichever arrived first.
|
|
489
|
-
if (delta.reasoningContent.signature && !
|
|
490
|
-
|
|
491
|
-
(thinkingBlock.thinkingSignature || "") + delta.reasoningContent.signature;
|
|
499
|
+
if (delta.reasoningContent.signature && !block.redacted) {
|
|
500
|
+
block.thinkingSignature = (block.thinkingSignature || "") + delta.reasoningContent.signature;
|
|
492
501
|
}
|
|
493
502
|
if (delta.reasoningContent.redactedContent?.length) {
|
|
494
503
|
// Encrypted reasoning from non-Anthropic models on Bedrock (e.g. OpenAI GPT-5.6).
|
|
495
504
|
// The payload is opaque, so keep it verbatim in `thinkingSignature` the way the
|
|
496
505
|
// Anthropic path stores redacted thinking, and replay it on the next turn.
|
|
497
|
-
if (!
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
506
|
+
if (!block.redacted) {
|
|
507
|
+
block.redacted = true;
|
|
508
|
+
block.thinkingSignature = "";
|
|
509
|
+
block.thinking += REDACTED_THINKING_PLACEHOLDER;
|
|
501
510
|
stream.push({
|
|
502
511
|
type: "thinking_delta",
|
|
503
512
|
contentIndex: thinkingIndex,
|
|
@@ -505,32 +514,29 @@ function handleContentBlockDelta(event, blocks, output, stream) {
|
|
|
505
514
|
partial: output,
|
|
506
515
|
});
|
|
507
516
|
}
|
|
508
|
-
|
|
509
|
-
|
|
517
|
+
open.redactedChunks ??= [];
|
|
518
|
+
open.redactedChunks.push(delta.reasoningContent.redactedContent);
|
|
510
519
|
}
|
|
511
520
|
}
|
|
512
521
|
}
|
|
513
522
|
}
|
|
514
523
|
/**
|
|
515
|
-
* Encodes buffered encrypted reasoning into `thinkingSignature
|
|
516
|
-
*
|
|
517
|
-
*
|
|
524
|
+
* Encodes buffered encrypted reasoning into `thinkingSignature`. The chunks stay in the stream state, never on the
|
|
525
|
+
* block: `Uint8Array` is not JSON and serializes to an index-keyed object roughly ten times the size of the base64
|
|
526
|
+
* payload.
|
|
518
527
|
*/
|
|
519
|
-
function flushRedactedContent(
|
|
520
|
-
|
|
528
|
+
function flushRedactedContent(open, output) {
|
|
529
|
+
const block = output.content[open.contentIndex];
|
|
530
|
+
if (block?.type !== "thinking" || !open.redactedChunks)
|
|
521
531
|
return;
|
|
522
|
-
block.thinkingSignature = bytesToBase64(
|
|
523
|
-
|
|
532
|
+
block.thinkingSignature = bytesToBase64(open.redactedChunks);
|
|
533
|
+
open.redactedChunks = undefined;
|
|
524
534
|
}
|
|
525
|
-
/**
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
delete block.index;
|
|
531
|
-
// partialJson is only a streaming scratch buffer; never persist it.
|
|
532
|
-
delete block.partialJson;
|
|
533
|
-
flushRedactedContent(block);
|
|
535
|
+
/** Ends the stream state of blocks a stream settled without stopping. */
|
|
536
|
+
function flushOpenBlocks(openBlocks, output) {
|
|
537
|
+
for (const open of openBlocks.values())
|
|
538
|
+
flushRedactedContent(open, output);
|
|
539
|
+
openBlocks.clear();
|
|
534
540
|
}
|
|
535
541
|
function handleMetadata(event, model, output) {
|
|
536
542
|
if (event.usage) {
|
|
@@ -543,25 +549,24 @@ function handleMetadata(event, model, output) {
|
|
|
543
549
|
calculateCost(model, output.usage);
|
|
544
550
|
}
|
|
545
551
|
}
|
|
546
|
-
function handleContentBlockStop(event,
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
if (!block)
|
|
552
|
+
function handleContentBlockStop(event, openBlocks, output, stream) {
|
|
553
|
+
const open = openBlocks.get(event.contentBlockIndex);
|
|
554
|
+
if (!open)
|
|
550
555
|
return;
|
|
551
|
-
delete
|
|
556
|
+
openBlocks.delete(event.contentBlockIndex);
|
|
557
|
+
const index = open.contentIndex;
|
|
558
|
+
const block = output.content[index];
|
|
552
559
|
switch (block.type) {
|
|
553
560
|
case "text":
|
|
554
561
|
stream.push({ type: "text_end", contentIndex: index, content: block.text, partial: output });
|
|
555
562
|
break;
|
|
556
563
|
case "thinking":
|
|
557
|
-
flushRedactedContent(
|
|
564
|
+
flushRedactedContent(open, output);
|
|
558
565
|
stream.push({ type: "thinking_end", contentIndex: index, content: block.thinking, partial: output });
|
|
559
566
|
break;
|
|
560
567
|
case "toolCall":
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
// carries parsed arguments.
|
|
564
|
-
delete block.partialJson;
|
|
568
|
+
if (open.arguments !== undefined)
|
|
569
|
+
Object.assign(block, open.arguments.finish());
|
|
565
570
|
stream.push({ type: "toolcall_end", contentIndex: index, toolCall: block, partial: output });
|
|
566
571
|
break;
|
|
567
572
|
}
|
|
@@ -586,6 +591,7 @@ function supportsAdaptiveThinking(modelId, modelName) {
|
|
|
586
591
|
s.includes("opus-5") ||
|
|
587
592
|
s.includes("sonnet-4-6") ||
|
|
588
593
|
s.includes("sonnet-5") ||
|
|
594
|
+
s.includes("haiku-5") ||
|
|
589
595
|
s.includes("fable-5"));
|
|
590
596
|
}
|
|
591
597
|
function supportsNativeXhighEffort(model) {
|
|
@@ -594,6 +600,7 @@ function supportsNativeXhighEffort(model) {
|
|
|
594
600
|
s.includes("opus-4-8") ||
|
|
595
601
|
s.includes("opus-5") ||
|
|
596
602
|
s.includes("sonnet-5") ||
|
|
603
|
+
s.includes("haiku-5") ||
|
|
597
604
|
s.includes("fable-5"));
|
|
598
605
|
}
|
|
599
606
|
/**
|
|
@@ -606,6 +613,7 @@ function supportsThinkingBlockBinding(model) {
|
|
|
606
613
|
s.includes("opus-4-8") ||
|
|
607
614
|
s.includes("opus-5") ||
|
|
608
615
|
s.includes("sonnet-5") ||
|
|
616
|
+
s.includes("haiku-5") ||
|
|
609
617
|
s.includes("fable-5"));
|
|
610
618
|
}
|
|
611
619
|
function mapThinkingLevelToEffort(model, level) {
|
|
@@ -675,8 +683,8 @@ function supportsPromptCaching(model, env) {
|
|
|
675
683
|
return true;
|
|
676
684
|
return false;
|
|
677
685
|
}
|
|
678
|
-
// Claude 5 models (fable-5, opus-5, sonnet-5)
|
|
679
|
-
if (candidates.some((s) => s.includes("fable-5") || s.includes("opus-5") || s.includes("sonnet-5")))
|
|
686
|
+
// Claude 5 models (fable-5, opus-5, sonnet-5, haiku-5)
|
|
687
|
+
if (candidates.some((s) => s.includes("fable-5") || s.includes("opus-5") || s.includes("sonnet-5") || s.includes("haiku-5")))
|
|
680
688
|
return true;
|
|
681
689
|
// Claude 4.x models (opus-4, sonnet-4, haiku-4)
|
|
682
690
|
if (candidates.some((s) => s.includes("-4-")))
|
|
@@ -867,30 +875,28 @@ function convertMessages(context, model, cacheRetention, env) {
|
|
|
867
875
|
// Collect all consecutive toolResult messages into a single user message
|
|
868
876
|
// Bedrock requires all tool results to be in one message
|
|
869
877
|
const toolResults = [];
|
|
870
|
-
//
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
content: convertToolResultContent(m.content),
|
|
875
|
-
status: m.isError ? ToolResultStatus.ERROR : ToolResultStatus.SUCCESS,
|
|
876
|
-
},
|
|
877
|
-
});
|
|
878
|
-
// Look ahead for consecutive toolResult messages
|
|
879
|
-
let j = i + 1;
|
|
878
|
+
// Claude rejects error tool results that contain anything but text, so for Claude their
|
|
879
|
+
// images follow all tool results of the turn (#10794). Other models keep them in place.
|
|
880
|
+
const errorImages = [];
|
|
881
|
+
let j = i;
|
|
880
882
|
while (j < transformedMessages.length && transformedMessages[j].role === "toolResult") {
|
|
881
|
-
const
|
|
883
|
+
const toolMsg = transformedMessages[j];
|
|
884
|
+
const split = isAnthropicClaudeModel(model) ? splitErrorToolResultImages(toolMsg) : undefined;
|
|
882
885
|
toolResults.push({
|
|
883
886
|
toolResult: {
|
|
884
|
-
toolUseId:
|
|
885
|
-
content: convertToolResultContent(
|
|
886
|
-
status:
|
|
887
|
+
toolUseId: toolMsg.toolCallId,
|
|
888
|
+
content: convertToolResultContent(split?.content ?? toolMsg.content),
|
|
889
|
+
status: toolMsg.isError ? ToolResultStatus.ERROR : ToolResultStatus.SUCCESS,
|
|
887
890
|
},
|
|
888
891
|
});
|
|
892
|
+
if (split) {
|
|
893
|
+
errorImages.push({ text: split.caption }, ...split.images.map((image) => ({ image: createImageBlock(image.mimeType, image.data) })));
|
|
894
|
+
}
|
|
889
895
|
j++;
|
|
890
896
|
}
|
|
891
897
|
// Skip the messages we've already processed
|
|
892
898
|
i = j - 1;
|
|
893
|
-
result.push({ role: ConversationRole.USER, content: toolResults });
|
|
899
|
+
result.push({ role: ConversationRole.USER, content: [...toolResults, ...errorImages] });
|
|
894
900
|
break;
|
|
895
901
|
}
|
|
896
902
|
default:
|
|
@@ -1053,8 +1059,36 @@ function buildAdditionalModelRequestFields(model, options) {
|
|
|
1053
1059
|
}
|
|
1054
1060
|
return result;
|
|
1055
1061
|
}
|
|
1062
|
+
const candidates = getModelMatchCandidates(model.id, model.name);
|
|
1063
|
+
if (candidates.some((s) => s.includes("gpt-oss"))) {
|
|
1064
|
+
return { reasoning_effort: OPENAI_GPT_OSS_EFFORT[options.reasoning] };
|
|
1065
|
+
}
|
|
1066
|
+
if (candidates.some((s) => s.includes("gpt-"))) {
|
|
1067
|
+
const mapped = model.thinkingLevelMap?.[options.reasoning];
|
|
1068
|
+
return {
|
|
1069
|
+
reasoning: { effort: typeof mapped === "string" ? mapped : OPENAI_GPT_EFFORT[options.reasoning] },
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1056
1072
|
return undefined;
|
|
1057
1073
|
}
|
|
1074
|
+
/** OpenAI GPT models (GPT-5.x, GPT-6) take a nested `reasoning.effort` and reject `minimal`. */
|
|
1075
|
+
const OPENAI_GPT_EFFORT = {
|
|
1076
|
+
minimal: "low",
|
|
1077
|
+
low: "low",
|
|
1078
|
+
medium: "medium",
|
|
1079
|
+
high: "high",
|
|
1080
|
+
xhigh: "xhigh",
|
|
1081
|
+
max: "max",
|
|
1082
|
+
};
|
|
1083
|
+
/** gpt-oss takes a flat `reasoning_effort` and only accepts low, medium and high. */
|
|
1084
|
+
const OPENAI_GPT_OSS_EFFORT = {
|
|
1085
|
+
minimal: "low",
|
|
1086
|
+
low: "low",
|
|
1087
|
+
medium: "medium",
|
|
1088
|
+
high: "high",
|
|
1089
|
+
xhigh: "high",
|
|
1090
|
+
max: "high",
|
|
1091
|
+
};
|
|
1058
1092
|
function createImageBlock(mimeType, data) {
|
|
1059
1093
|
let format;
|
|
1060
1094
|
switch (mimeType) {
|