@code-yeongyu/senpi-ai 2026.8.24 → 2026.8.26
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/dist/api/anthropic-messages.d.ts +1 -5
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +25 -13
- 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 +2 -1
- 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 +91 -5
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/google-generative-ai.d.ts.map +1 -1
- package/dist/api/google-generative-ai.js +4 -2
- package/dist/api/google-generative-ai.js.map +1 -1
- package/dist/api/google-vertex.d.ts.map +1 -1
- package/dist/api/google-vertex.js +4 -2
- package/dist/api/google-vertex.js.map +1 -1
- package/dist/api/mistral-conversations.d.ts.map +1 -1
- package/dist/api/mistral-conversations.js +2 -0
- package/dist/api/mistral-conversations.js.map +1 -1
- package/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/api/openai-completions.js +93 -54
- package/dist/api/openai-completions.js.map +1 -1
- package/dist/api/openai-responses.js +2 -5
- package/dist/api/openai-responses.js.map +1 -1
- package/dist/api/transform-messages.js +1 -1
- package/dist/api/transform-messages.js.map +1 -1
- package/dist/auth/oauth/github-copilot.d.ts.map +1 -1
- package/dist/auth/oauth/github-copilot.js +97 -46
- package/dist/auth/oauth/github-copilot.js.map +1 -1
- package/dist/auth/oauth/kimi-coding.d.ts.map +1 -1
- package/dist/auth/oauth/kimi-coding.js +1 -14
- package/dist/auth/oauth/kimi-coding.js.map +1 -1
- package/dist/auth/pool/slots.d.ts +50 -0
- package/dist/auth/pool/slots.d.ts.map +1 -0
- package/dist/auth/pool/slots.js +129 -0
- package/dist/auth/pool/slots.js.map +1 -0
- package/dist/auth/resolve.d.ts.map +1 -1
- package/dist/auth/resolve.js +3 -1
- package/dist/auth/resolve.js.map +1 -1
- package/dist/models.d.ts +8 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +16 -3
- package/dist/models.js.map +1 -1
- package/dist/providers/cloudflare-ai-gateway.d.ts +3 -1
- package/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -1
- package/dist/providers/cloudflare-ai-gateway.js +10 -1
- package/dist/providers/cloudflare-ai-gateway.js.map +1 -1
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/anthropic.json +1 -1
- package/dist/providers/data/azure-openai-responses.json +1 -1
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/providers/data/huggingface.json +1 -1
- package/dist/providers/data/nvidia.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/opengateway.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/providers/data/zai.json +1 -1
- package/dist/providers/faux.d.ts +1 -0
- package/dist/providers/faux.d.ts.map +1 -1
- package/dist/providers/faux.js +1 -0
- package/dist/providers/faux.js.map +1 -1
- package/dist/providers/kimi-coding.d.ts.map +1 -1
- package/dist/providers/kimi-coding.js +4 -0
- package/dist/providers/kimi-coding.js.map +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/overflow.d.ts +16 -0
- package/dist/utils/overflow.d.ts.map +1 -1
- package/dist/utils/overflow.js +17 -1
- package/dist/utils/overflow.js.map +1 -1
- package/dist/utils/retry-profile/backoff.d.ts +14 -0
- package/dist/utils/retry-profile/backoff.d.ts.map +1 -0
- package/dist/utils/retry-profile/backoff.js +24 -0
- package/dist/utils/retry-profile/backoff.js.map +1 -0
- package/dist/utils/retry-profile/classifiers.d.ts +36 -0
- package/dist/utils/retry-profile/classifiers.d.ts.map +1 -0
- package/dist/utils/retry-profile/classifiers.js +109 -0
- package/dist/utils/retry-profile/classifiers.js.map +1 -0
- package/dist/utils/retry-profile/failure.d.ts +12 -0
- package/dist/utils/retry-profile/failure.d.ts.map +1 -0
- package/dist/utils/retry-profile/failure.js +109 -0
- package/dist/utils/retry-profile/failure.js.map +1 -0
- package/dist/utils/retry-profile/index.d.ts +9 -0
- package/dist/utils/retry-profile/index.d.ts.map +1 -0
- package/dist/utils/retry-profile/index.js +6 -0
- package/dist/utils/retry-profile/index.js.map +1 -0
- package/dist/utils/retry-profile/planner.d.ts +46 -0
- package/dist/utils/retry-profile/planner.d.ts.map +1 -0
- package/dist/utils/retry-profile/planner.js +41 -0
- package/dist/utils/retry-profile/planner.js.map +1 -0
- package/dist/utils/retry-profile/profiles.d.ts +4 -0
- package/dist/utils/retry-profile/profiles.d.ts.map +1 -0
- package/dist/utils/retry-profile/profiles.js +93 -0
- package/dist/utils/retry-profile/profiles.js.map +1 -0
- package/dist/utils/retry-profile/types.d.ts +121 -0
- package/dist/utils/retry-profile/types.d.ts.map +1 -0
- package/dist/utils/retry-profile/types.js +11 -0
- package/dist/utils/retry-profile/types.js.map +1 -0
- package/dist/utils/retry.d.ts +12 -0
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +25 -5
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/sleep.d.ts +2 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +15 -0
- package/dist/utils/sleep.js.map +1 -0
- package/package.json +19 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"azure-openai-responses.d.ts","sourceRoot":"","sources":["../../src/api/azure-openai-responses.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AAE7F,OAAO,KAAK,EAKX,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"azure-openai-responses.d.ts","sourceRoot":"","sources":["../../src/api/azure-openai-responses.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AAE7F,OAAO,KAAK,EAKX,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,MAAM,aAAa,CAAC;AA6CrB,MAAM,WAAW,2BAA4B,SAAQ,aAAa;IACjE,eAAe,CAAC,EAAE,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;IAC1E,UAAU,CAAC,EAAE,6BAA6B,CAAC,aAAa,CAAC,CAAC;IAC1D,gBAAgB,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,IAAI,CAAC;IAC1D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,wBAAwB,EAAE,2BAA2B,CA2FxF,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,wBAAwB,EAAE,mBAAmB,CA4BtF,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { clampThinkingLevel, supportsMax } from "../models.js";
|
|
|
3
3
|
import { formatProviderError, normalizeProviderError } from "../utils/error-body.js";
|
|
4
4
|
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
5
5
|
import { headersToRecord } from "../utils/headers.js";
|
|
6
|
+
import { getPiUserAgent } from "../utils/pi-user-agent.js";
|
|
6
7
|
import { getProviderEnvValue } from "../utils/provider-env.js";
|
|
7
8
|
import { retryProviderRequest } from "../utils/provider-retry.js";
|
|
8
9
|
import { createGrammarToolInputProperties } from "./constrained-sampling.js";
|
|
@@ -188,7 +189,7 @@ function resolveAzureConfig(model, options) {
|
|
|
188
189
|
};
|
|
189
190
|
}
|
|
190
191
|
function createClient(model, apiKey, options) {
|
|
191
|
-
const headers = { ...model.headers };
|
|
192
|
+
const headers = { "User-Agent": getPiUserAgent(), ...model.headers };
|
|
192
193
|
if (options?.headers) {
|
|
193
194
|
Object.assign(headers, options.headers);
|
|
194
195
|
}
|
|
@@ -1 +1 @@
|
|
|
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,WAAW,EAAE,MAAM,cAAc,CAAC;AAU/D,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,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACvH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,yBAAyB,GAAG,IAAI,CAAC;AACvC,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,wBAAwB,CAAC,CAAC,CAAC;AAC5G,wGAAwG;AACxG,MAAM,kCAAkC,GAAG,EAAE,CAAC;AAE9C,SAAS,sBAAsB,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AC5D,0BAA0B,EAAE,KAAK,CAAC,MAAM,EAAE,0BAA0B,IAAI,KAAK;SAC7E,CAAC,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,EAAE,UAAU,KAAK,SAAS,EAAE,CAAC;QACvC,MAAM,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IACzC,CAAC;IAED,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;QACrB,IAAI,kBAAkB,EAAE,CAAC;YACxB,MAAM,CAAC,SAAS,GAAG;gBAClB,MAAM,EAAE,eAAiE;gBACzE,GAAG,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,IAAI,MAAM,EAAE,CAAC;aAC/F,CAAC;YACF,MAAM,CAAC,OAAO,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAClD,CAAC;aAAM,IAAI,CAAC,oBAAoB,IAAI,KAAK,CAAC,gBAAgB,EAAE,GAAG,KAAK,IAAI,EAAE,CAAC;YAC1E,MAAM,CAAC,SAAS,GAAG;gBAClB,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,GAAG,IAAI,MAAM,CAAmD;aACjG,CAAC;QACH,CAAC;IACF,CAAC;IAED,yDAAyD;IACzD,IAAI,OAAO,EAAE,cAAc,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { AzureOpenAI } from \"openai\";\nimport type { ResponseCreateParamsStreaming } from \"openai/resources/responses/responses.js\";\nimport { clampThinkingLevel, supportsMax } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n} 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 { getProviderEnvValue } from \"../utils/provider-env.ts\";\nimport { retryProviderRequest } from \"../utils/provider-retry.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 } from \"./simple-options.ts\";\n\nconst DEFAULT_AZURE_API_VERSION = \"v1\";\nconst AZURE_TOOL_CALL_PROVIDERS = new Set([\"openai\", \"openai-codex\", \"opencode\", \"azure-openai-responses\"]);\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 parseDeploymentNameMap(value: string | undefined): Map<string, string> {\n\tconst map = new Map<string, string>();\n\tif (!value) return map;\n\tfor (const entry of value.split(\",\")) {\n\t\tconst trimmed = entry.trim();\n\t\tif (!trimmed) continue;\n\t\tconst [modelId, deploymentName] = trimmed.split(\"=\", 2);\n\t\tif (!modelId || !deploymentName) continue;\n\t\tmap.set(modelId.trim(), deploymentName.trim());\n\t}\n\treturn map;\n}\n\nfunction resolveDeploymentName(model: Model<\"azure-openai-responses\">, options?: AzureOpenAIResponsesOptions): string {\n\tif (options?.azureDeploymentName) {\n\t\treturn options.azureDeploymentName;\n\t}\n\tconst mappedDeployment = parseDeploymentNameMap(\n\t\tgetProviderEnvValue(\"AZURE_OPENAI_DEPLOYMENT_NAME_MAP\", options?.env),\n\t).get(model.id);\n\treturn mappedDeployment || model.id;\n}\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 StreamOptions {\n\treasoningEffort?: \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\" | \"max\";\n\ttoolChoice?: ResponseCreateParamsStreaming[\"tool_choice\"];\n\treasoningSummary?: \"auto\" | \"detailed\" | \"concise\" | null;\n\tazureApiVersion?: string;\n\tazureResourceName?: string;\n\tazureBaseUrl?: string;\n\tazureDeploymentName?: string;\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: Context,\n\toptions?: AzureOpenAIResponsesOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\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\tcontext.tools,\n\t\t\t\tmodel.compat?.supportsOpenAIGrammarTools ?? false,\n\t\t\t);\n\t\t\tlet params = buildParams(model, context, 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, { grammarToolInputProperties });\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: Context,\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 =\n\t\tclampedReasoning === \"off\"\n\t\t\t? undefined\n\t\t\t: clampedReasoning === \"max\" && supportsMax(model)\n\t\t\t\t? \"max\"\n\t\t\t\t: clampedReasoning === \"max\"\n\t\t\t\t\t? \"high\"\n\t\t\t\t\t: clampedReasoning;\n\n\treturn stream(model, context, {\n\t\t...base,\n\t\treasoningEffort,\n\t} satisfies AzureOpenAIResponsesOptions);\n};\n\nfunction normalizeAzureBaseUrl(baseUrl: string): string {\n\tconst trimmed = baseUrl.trim().replace(/\\/+$/, \"\");\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(trimmed);\n\t} catch {\n\t\tthrow new Error(`Invalid Azure OpenAI base URL: ${baseUrl}`);\n\t}\n\n\tconst isAzureHost =\n\t\turl.hostname.endsWith(\".openai.azure.com\") ||\n\t\turl.hostname.endsWith(\".cognitiveservices.azure.com\") ||\n\t\turl.hostname.endsWith(\".ai.azure.com\");\n\tconst normalizedPath = url.pathname.replace(/\\/+$/, \"\");\n\n\t// Ensure Azure hosts have /openai/v1 as base path so the AzureOpenAI SDK\n\t// can append /deployments/<model>/... and ?api-version=v1 correctly.\n\tif (\n\t\tisAzureHost &&\n\t\t(normalizedPath === \"\" ||\n\t\t\tnormalizedPath === \"/\" ||\n\t\t\tnormalizedPath === \"/openai\" ||\n\t\t\tnormalizedPath === \"/openai/v1/responses\")\n\t) {\n\t\turl.pathname = \"/openai/v1\";\n\t\turl.search = \"\";\n\t}\n\n\treturn url.toString().replace(/\\/+$/, \"\");\n}\n\nfunction buildDefaultBaseUrl(resourceName: string): string {\n\treturn `https://${resourceName}.openai.azure.com/openai/v1`;\n}\n\nfunction resolveAzureConfig(\n\tmodel: Model<\"azure-openai-responses\">,\n\toptions?: AzureOpenAIResponsesOptions,\n): { baseUrl: string; apiVersion: string } {\n\tconst apiVersion =\n\t\toptions?.azureApiVersion ||\n\t\tgetProviderEnvValue(\"AZURE_OPENAI_API_VERSION\", options?.env) ||\n\t\tDEFAULT_AZURE_API_VERSION;\n\n\tconst baseUrl =\n\t\toptions?.azureBaseUrl?.trim() || getProviderEnvValue(\"AZURE_OPENAI_BASE_URL\", options?.env)?.trim() || undefined;\n\tconst resourceName = options?.azureResourceName || getProviderEnvValue(\"AZURE_OPENAI_RESOURCE_NAME\", options?.env);\n\n\tlet resolvedBaseUrl = baseUrl;\n\n\tif (!resolvedBaseUrl && resourceName) {\n\t\tresolvedBaseUrl = buildDefaultBaseUrl(resourceName);\n\t}\n\n\tif (!resolvedBaseUrl && model.baseUrl) {\n\t\tresolvedBaseUrl = model.baseUrl;\n\t}\n\n\tif (!resolvedBaseUrl) {\n\t\tthrow new Error(\n\t\t\t\"Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.\",\n\t\t);\n\t}\n\n\treturn {\n\t\tbaseUrl: normalizeAzureBaseUrl(resolvedBaseUrl),\n\t\tapiVersion,\n\t};\n}\n\nfunction createClient(model: Model<\"azure-openai-responses\">, apiKey: string, options?: AzureOpenAIResponsesOptions) {\n\tconst headers = { ...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: Context,\n\toptions: AzureOpenAIResponsesOptions | undefined,\n\tdeploymentName: string,\n\tgrammarToolInputProperties: ReadonlyMap<string, string> = createGrammarToolInputProperties(\n\t\tcontext.tools,\n\t\tmodel.compat?.supportsOpenAIGrammarTools ?? false,\n\t),\n) {\n\tconst requestedReasoningEffort = options?.reasoningEffort ?? (options?.reasoningSummary ? \"medium\" : undefined);\n\tconst mappedReasoningEffort =\n\t\trequestedReasoningEffort === undefined ? undefined : model.thinkingLevelMap?.[requestedReasoningEffort];\n\tconst reasoningEffort = mappedReasoningEffort === undefined ? requestedReasoningEffort : mappedReasoningEffort;\n\tconst reasoningRequested = reasoningEffort !== undefined && reasoningEffort !== null;\n\tconst reasoningUnavailable = reasoningEffort === null;\n\tconst messages = convertResponsesMessages(model, context, AZURE_TOOL_CALL_PROVIDERS, {\n\t\tgrammarToolInputProperties,\n\t});\n\n\tconst params: ResponseCreateParamsStreaming = {\n\t\tmodel: deploymentName,\n\t\tinput: messages,\n\t\tstream: true,\n\t\t...((options?.cacheRetention ?? model.cacheRetention) === \"none\"\n\t\t\t? {}\n\t\t\t: { prompt_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 (context.tools && context.tools.length > 0) {\n\t\tparams.tools = convertResponsesTools(context.tools, {\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\tif (model.reasoning) {\n\t\tif (reasoningRequested) {\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: reasoningEffort as NonNullable<typeof params.reasoning>[\"effort\"],\n\t\t\t\t...(options?.reasoningSummary === null ? {} : { summary: options?.reasoningSummary || \"auto\" }),\n\t\t\t};\n\t\t\tparams.include = [\"reasoning.encrypted_content\"];\n\t\t} else if (!reasoningUnavailable && 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 custom keys override the named request fields.\n\tif (options?.samplingParams) {\n\t\tObject.assign(params, options.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,WAAW,EAAE,MAAM,cAAc,CAAC;AAU/D,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,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,0B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;IACzD,IAAI,OAAO,EAAE,cAAc,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { AzureOpenAI } from \"openai\";\nimport type { ResponseCreateParamsStreaming } from \"openai/resources/responses/responses.js\";\nimport { clampThinkingLevel, supportsMax } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n} 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 { getProviderEnvValue } from \"../utils/provider-env.ts\";\nimport { retryProviderRequest } from \"../utils/provider-retry.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 } from \"./simple-options.ts\";\n\nconst DEFAULT_AZURE_API_VERSION = \"v1\";\nconst AZURE_TOOL_CALL_PROVIDERS = new Set([\"openai\", \"openai-codex\", \"opencode\", \"azure-openai-responses\"]);\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 parseDeploymentNameMap(value: string | undefined): Map<string, string> {\n\tconst map = new Map<string, string>();\n\tif (!value) return map;\n\tfor (const entry of value.split(\",\")) {\n\t\tconst trimmed = entry.trim();\n\t\tif (!trimmed) continue;\n\t\tconst [modelId, deploymentName] = trimmed.split(\"=\", 2);\n\t\tif (!modelId || !deploymentName) continue;\n\t\tmap.set(modelId.trim(), deploymentName.trim());\n\t}\n\treturn map;\n}\n\nfunction resolveDeploymentName(model: Model<\"azure-openai-responses\">, options?: AzureOpenAIResponsesOptions): string {\n\tif (options?.azureDeploymentName) {\n\t\treturn options.azureDeploymentName;\n\t}\n\tconst mappedDeployment = parseDeploymentNameMap(\n\t\tgetProviderEnvValue(\"AZURE_OPENAI_DEPLOYMENT_NAME_MAP\", options?.env),\n\t).get(model.id);\n\treturn mappedDeployment || model.id;\n}\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 StreamOptions {\n\treasoningEffort?: \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\" | \"max\";\n\ttoolChoice?: ResponseCreateParamsStreaming[\"tool_choice\"];\n\treasoningSummary?: \"auto\" | \"detailed\" | \"concise\" | null;\n\tazureApiVersion?: string;\n\tazureResourceName?: string;\n\tazureBaseUrl?: string;\n\tazureDeploymentName?: string;\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: Context,\n\toptions?: AzureOpenAIResponsesOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\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\tcontext.tools,\n\t\t\t\tmodel.compat?.supportsOpenAIGrammarTools ?? false,\n\t\t\t);\n\t\t\tlet params = buildParams(model, context, 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, { grammarToolInputProperties });\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: Context,\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 =\n\t\tclampedReasoning === \"off\"\n\t\t\t? undefined\n\t\t\t: clampedReasoning === \"max\" && supportsMax(model)\n\t\t\t\t? \"max\"\n\t\t\t\t: clampedReasoning === \"max\"\n\t\t\t\t\t? \"high\"\n\t\t\t\t\t: clampedReasoning;\n\n\treturn stream(model, context, {\n\t\t...base,\n\t\treasoningEffort,\n\t} satisfies AzureOpenAIResponsesOptions);\n};\n\nfunction normalizeAzureBaseUrl(baseUrl: string): string {\n\tconst trimmed = baseUrl.trim().replace(/\\/+$/, \"\");\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(trimmed);\n\t} catch {\n\t\tthrow new Error(`Invalid Azure OpenAI base URL: ${baseUrl}`);\n\t}\n\n\tconst isAzureHost =\n\t\turl.hostname.endsWith(\".openai.azure.com\") ||\n\t\turl.hostname.endsWith(\".cognitiveservices.azure.com\") ||\n\t\turl.hostname.endsWith(\".ai.azure.com\");\n\tconst normalizedPath = url.pathname.replace(/\\/+$/, \"\");\n\n\t// Ensure Azure hosts have /openai/v1 as base path so the AzureOpenAI SDK\n\t// can append /deployments/<model>/... and ?api-version=v1 correctly.\n\tif (\n\t\tisAzureHost &&\n\t\t(normalizedPath === \"\" ||\n\t\t\tnormalizedPath === \"/\" ||\n\t\t\tnormalizedPath === \"/openai\" ||\n\t\t\tnormalizedPath === \"/openai/v1/responses\")\n\t) {\n\t\turl.pathname = \"/openai/v1\";\n\t\turl.search = \"\";\n\t}\n\n\treturn url.toString().replace(/\\/+$/, \"\");\n}\n\nfunction buildDefaultBaseUrl(resourceName: string): string {\n\treturn `https://${resourceName}.openai.azure.com/openai/v1`;\n}\n\nfunction resolveAzureConfig(\n\tmodel: Model<\"azure-openai-responses\">,\n\toptions?: AzureOpenAIResponsesOptions,\n): { baseUrl: string; apiVersion: string } {\n\tconst apiVersion =\n\t\toptions?.azureApiVersion ||\n\t\tgetProviderEnvValue(\"AZURE_OPENAI_API_VERSION\", options?.env) ||\n\t\tDEFAULT_AZURE_API_VERSION;\n\n\tconst baseUrl =\n\t\toptions?.azureBaseUrl?.trim() || getProviderEnvValue(\"AZURE_OPENAI_BASE_URL\", options?.env)?.trim() || undefined;\n\tconst resourceName = options?.azureResourceName || getProviderEnvValue(\"AZURE_OPENAI_RESOURCE_NAME\", options?.env);\n\n\tlet resolvedBaseUrl = baseUrl;\n\n\tif (!resolvedBaseUrl && resourceName) {\n\t\tresolvedBaseUrl = buildDefaultBaseUrl(resourceName);\n\t}\n\n\tif (!resolvedBaseUrl && model.baseUrl) {\n\t\tresolvedBaseUrl = model.baseUrl;\n\t}\n\n\tif (!resolvedBaseUrl) {\n\t\tthrow new Error(\n\t\t\t\"Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.\",\n\t\t);\n\t}\n\n\treturn {\n\t\tbaseUrl: normalizeAzureBaseUrl(resolvedBaseUrl),\n\t\tapiVersion,\n\t};\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: Context,\n\toptions: AzureOpenAIResponsesOptions | undefined,\n\tdeploymentName: string,\n\tgrammarToolInputProperties: ReadonlyMap<string, string> = createGrammarToolInputProperties(\n\t\tcontext.tools,\n\t\tmodel.compat?.supportsOpenAIGrammarTools ?? false,\n\t),\n) {\n\tconst requestedReasoningEffort = options?.reasoningEffort ?? (options?.reasoningSummary ? \"medium\" : undefined);\n\tconst mappedReasoningEffort =\n\t\trequestedReasoningEffort === undefined ? undefined : model.thinkingLevelMap?.[requestedReasoningEffort];\n\tconst reasoningEffort = mappedReasoningEffort === undefined ? requestedReasoningEffort : mappedReasoningEffort;\n\tconst reasoningRequested = reasoningEffort !== undefined && reasoningEffort !== null;\n\tconst reasoningUnavailable = reasoningEffort === null;\n\tconst messages = convertResponsesMessages(model, context, AZURE_TOOL_CALL_PROVIDERS, {\n\t\tgrammarToolInputProperties,\n\t});\n\n\tconst params: ResponseCreateParamsStreaming = {\n\t\tmodel: deploymentName,\n\t\tinput: messages,\n\t\tstream: true,\n\t\t...((options?.cacheRetention ?? model.cacheRetention) === \"none\"\n\t\t\t? {}\n\t\t\t: { prompt_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 (context.tools && context.tools.length > 0) {\n\t\tparams.tools = convertResponsesTools(context.tools, {\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\tif (model.reasoning) {\n\t\tif (reasoningRequested) {\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: reasoningEffort as NonNullable<typeof params.reasoning>[\"effort\"],\n\t\t\t\t...(options?.reasoningSummary === null ? {} : { summary: options?.reasoningSummary || \"auto\" }),\n\t\t\t};\n\t\t\tparams.include = [\"reasoning.encrypted_content\"];\n\t\t} else if (!reasoningUnavailable && 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 custom keys override the named request fields.\n\tif (options?.samplingParams) {\n\t\tObject.assign(params, options.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":"AA8BA,OAAO,KAAK,EASX,mBAAmB,EAEnB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I,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;AAcD,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,yBAAyB,EAAE,cAAc,CAuO5E,CAAC;AAmLF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,yBAAyB,EAAE,mBAAmB,CAiDvF,CAAC"}
|
|
@@ -18,6 +18,8 @@ import { adjustMaxTokensForThinking, applyExtraBody, BEDROCK_RESERVED_BODY_KEYS,
|
|
|
18
18
|
import { transformMessages } from "./transform-messages.js";
|
|
19
19
|
export { supportsPromptCaching } from "../utils/prompt-cache-ttl.js";
|
|
20
20
|
const EMPTY_TEXT_PLACEHOLDER = "<empty>";
|
|
21
|
+
/** Matches the placeholder the Anthropic API path uses for redacted thinking. */
|
|
22
|
+
const REDACTED_THINKING_PLACEHOLDER = "[Reasoning redacted]";
|
|
21
23
|
export const stream = (model, context, options = {}) => {
|
|
22
24
|
const stream = new AssistantMessageEventStream();
|
|
23
25
|
(async () => {
|
|
@@ -219,14 +221,15 @@ export const stream = (model, context, options = {}) => {
|
|
|
219
221
|
if (output.stopReason === "error" || output.stopReason === "aborted") {
|
|
220
222
|
throw new Error(output.errorMessage || "An unknown error occurred");
|
|
221
223
|
}
|
|
224
|
+
// A stream can settle without stopping every block, so finalize here too.
|
|
225
|
+
for (const block of output.content)
|
|
226
|
+
finalizeStreamingBlock(block);
|
|
222
227
|
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
223
228
|
stream.end();
|
|
224
229
|
}
|
|
225
230
|
catch (error) {
|
|
226
231
|
for (const block of output.content) {
|
|
227
|
-
|
|
228
|
-
// partialJson is only a streaming scratch buffer; never persist it.
|
|
229
|
-
delete block.partialJson;
|
|
232
|
+
finalizeStreamingBlock(block);
|
|
230
233
|
}
|
|
231
234
|
output.stopReason = options.signal?.aborted ? "aborted" : "error";
|
|
232
235
|
output.errorMessage = formatBedrockError(error);
|
|
@@ -484,13 +487,54 @@ function handleContentBlockDelta(event, blocks, output, stream) {
|
|
|
484
487
|
partial: output,
|
|
485
488
|
});
|
|
486
489
|
}
|
|
487
|
-
|
|
490
|
+
// `thinkingSignature` holds either an Anthropic signature or an opaque redacted
|
|
491
|
+
// payload, never both: mixing them would corrupt whichever arrived first.
|
|
492
|
+
if (delta.reasoningContent.signature && !thinkingBlock.redacted) {
|
|
488
493
|
thinkingBlock.thinkingSignature =
|
|
489
494
|
(thinkingBlock.thinkingSignature || "") + delta.reasoningContent.signature;
|
|
490
495
|
}
|
|
496
|
+
if (delta.reasoningContent.redactedContent?.length) {
|
|
497
|
+
// Encrypted reasoning from non-Anthropic models on Bedrock (e.g. OpenAI GPT-5.6).
|
|
498
|
+
// The payload is opaque, so keep it verbatim in `thinkingSignature` the way the
|
|
499
|
+
// Anthropic path stores redacted thinking, and replay it on the next turn.
|
|
500
|
+
if (!thinkingBlock.redacted) {
|
|
501
|
+
thinkingBlock.redacted = true;
|
|
502
|
+
thinkingBlock.thinkingSignature = "";
|
|
503
|
+
thinkingBlock.thinking += REDACTED_THINKING_PLACEHOLDER;
|
|
504
|
+
stream.push({
|
|
505
|
+
type: "thinking_delta",
|
|
506
|
+
contentIndex: thinkingIndex,
|
|
507
|
+
delta: REDACTED_THINKING_PLACEHOLDER,
|
|
508
|
+
partial: output,
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
thinkingBlock.redactedChunks ??= [];
|
|
512
|
+
thinkingBlock.redactedChunks.push(delta.reasoningContent.redactedContent);
|
|
513
|
+
}
|
|
491
514
|
}
|
|
492
515
|
}
|
|
493
516
|
}
|
|
517
|
+
/**
|
|
518
|
+
* Encodes buffered encrypted reasoning into `thinkingSignature` and drops the scratch
|
|
519
|
+
* buffer, which must never reach a persisted message: `Uint8Array` serializes to an
|
|
520
|
+
* index-keyed object roughly ten times the size of the base64 payload.
|
|
521
|
+
*/
|
|
522
|
+
function flushRedactedContent(block) {
|
|
523
|
+
if (block.type !== "thinking" || !block.redactedChunks)
|
|
524
|
+
return;
|
|
525
|
+
block.thinkingSignature = bytesToBase64(block.redactedChunks);
|
|
526
|
+
delete block.redactedChunks;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Strips every streaming scratch field. Runs from the terminal paths as well as
|
|
530
|
+
* `contentBlockStop`, because a stream can settle without stopping each block.
|
|
531
|
+
*/
|
|
532
|
+
function finalizeStreamingBlock(block) {
|
|
533
|
+
delete block.index;
|
|
534
|
+
// partialJson is only a streaming scratch buffer; never persist it.
|
|
535
|
+
delete block.partialJson;
|
|
536
|
+
flushRedactedContent(block);
|
|
537
|
+
}
|
|
494
538
|
function handleMetadata(event, model, output) {
|
|
495
539
|
if (event.usage) {
|
|
496
540
|
output.usage.input = event.usage.inputTokens || 0;
|
|
@@ -512,6 +556,7 @@ function handleContentBlockStop(event, blocks, output, stream) {
|
|
|
512
556
|
stream.push({ type: "text_end", contentIndex: index, content: block.text, partial: output });
|
|
513
557
|
break;
|
|
514
558
|
case "thinking":
|
|
559
|
+
flushRedactedContent(block);
|
|
515
560
|
stream.push({ type: "thinking_end", contentIndex: index, content: block.thinking, partial: output });
|
|
516
561
|
break;
|
|
517
562
|
case "toolCall":
|
|
@@ -731,6 +776,15 @@ function convertMessages(context, model, cacheRetention, options = {}) {
|
|
|
731
776
|
});
|
|
732
777
|
break;
|
|
733
778
|
case "thinking": {
|
|
779
|
+
// Encrypted reasoning is opaque: replay the stored payload as the
|
|
780
|
+
// `redactedContent` member instead of lowering it to reasoning text.
|
|
781
|
+
if (c.redacted) {
|
|
782
|
+
const redactedContent = decodeRedactedContent(c.thinkingSignature);
|
|
783
|
+
if (redactedContent?.length) {
|
|
784
|
+
contentBlocks.push({ reasoningContent: { redactedContent } });
|
|
785
|
+
}
|
|
786
|
+
continue;
|
|
787
|
+
}
|
|
734
788
|
// Skip empty thinking blocks
|
|
735
789
|
const thinking = sanitizeSurrogates(c.thinking);
|
|
736
790
|
if (thinking.trim().length === 0)
|
|
@@ -997,11 +1051,43 @@ function createImageBlock(mimeType, data) {
|
|
|
997
1051
|
default:
|
|
998
1052
|
throw new Error(`Unknown image type: ${mimeType}`);
|
|
999
1053
|
}
|
|
1054
|
+
return { source: { bytes: base64ToBytes(data) }, format };
|
|
1055
|
+
}
|
|
1056
|
+
function base64ToBytes(data) {
|
|
1000
1057
|
const binaryString = atob(data);
|
|
1001
1058
|
const bytes = new Uint8Array(binaryString.length);
|
|
1002
1059
|
for (let i = 0; i < binaryString.length; i++) {
|
|
1003
1060
|
bytes[i] = binaryString.charCodeAt(i);
|
|
1004
1061
|
}
|
|
1005
|
-
return
|
|
1062
|
+
return bytes;
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Decodes a stored redacted payload. The AWS SDK hands the blob over as bytes, but a
|
|
1066
|
+
* persisted session carries it as base64. A hand-edited or externally produced session
|
|
1067
|
+
* can hold a signature that is not base64; drop that block instead of failing the
|
|
1068
|
+
* whole request.
|
|
1069
|
+
*/
|
|
1070
|
+
function decodeRedactedContent(signature) {
|
|
1071
|
+
if (!signature)
|
|
1072
|
+
return undefined;
|
|
1073
|
+
try {
|
|
1074
|
+
return base64ToBytes(signature);
|
|
1075
|
+
}
|
|
1076
|
+
catch {
|
|
1077
|
+
return undefined;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
function bytesToBase64(chunks) {
|
|
1081
|
+
// Encrypted reasoning runs to tens of KB, so build the binary string in slices
|
|
1082
|
+
// rather than one concatenation per byte. The window stays under the engine's
|
|
1083
|
+
// argument-count limit for spread calls.
|
|
1084
|
+
const WINDOW = 0x8000;
|
|
1085
|
+
let binary = "";
|
|
1086
|
+
for (const chunk of chunks) {
|
|
1087
|
+
for (let i = 0; i < chunk.length; i += WINDOW) {
|
|
1088
|
+
binary += String.fromCharCode(...chunk.subarray(i, i + WINDOW));
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
return btoa(binary);
|
|
1006
1092
|
}
|
|
1007
1093
|
//# sourceMappingURL=bedrock-converse-stream.js.map
|