@xiaoso/dsh-tool-plus 0.1.0-beta.2 → 0.1.0-beta.4
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.en.md +122 -0
- package/README.md +3 -2
- package/THIRD_PARTY_NOTICES.md +4 -35
- package/lib/abort-B7izMMna.mjs +51 -0
- package/lib/abort-D1_Z5Ut5.mjs +51 -0
- package/lib/abort-dIkZBV7Q.mjs +51 -0
- package/lib/amazon-bedrock-B0nxT06F.mjs +917 -0
- package/lib/amazon-bedrock-D-shAr1X.mjs +917 -0
- package/lib/amazon-bedrock-WQhvjHYu.mjs +917 -0
- package/lib/anthropic-BWsZFzU8.mjs +262 -0
- package/lib/anthropic-CJCauvYz.mjs +3115 -0
- package/lib/anthropic-CMT1Qj1t.mjs +3115 -0
- package/lib/anthropic-CZghe_9U.mjs +3115 -0
- package/lib/anthropic-sCMH7JID.mjs +262 -0
- package/lib/anthropic-tTntD8BD.mjs +262 -0
- package/lib/api-key-login-BzqNdM2y.mjs +157 -0
- package/lib/api-key-login-CWVwvHT1.mjs +157 -0
- package/lib/api-key-login-CpzSezsi.mjs +157 -0
- package/lib/aws-credentials-8Mgn5MAy.mjs +867 -0
- package/lib/aws-credentials-CXryMobh.mjs +867 -0
- package/lib/aws-credentials-ChG79ey-.mjs +867 -0
- package/lib/azure-openai-responses-CNkHiLUh.mjs +274 -0
- package/lib/azure-openai-responses-Cgmc-rbL.mjs +274 -0
- package/lib/azure-openai-responses-DuukbD0F.mjs +274 -0
- package/lib/bun-shim.mjs +252 -12
- package/lib/bundled-references-CSuBco5p.mjs +55 -0
- package/lib/bundled-references-Cavaffah.mjs +55 -0
- package/lib/bundled-references-sLN0YdXU.mjs +55 -0
- package/lib/callback-server-BEFNf-jf.mjs +398 -0
- package/lib/callback-server-CQ5Jo8F-.mjs +398 -0
- package/lib/callback-server-DDSrZ6l_.mjs +398 -0
- package/lib/client.js +111 -41
- package/lib/cursor-B3zg7EHj.mjs +273 -0
- package/lib/cursor-B6TUEmgP.mjs +135 -0
- package/lib/cursor-BIQfBC6V.mjs +135 -0
- package/lib/cursor-D8gvtTL3.mjs +135 -0
- package/lib/cursor-DNk6eXDd.mjs +5470 -0
- package/lib/cursor-DkSX2h3H.mjs +5441 -0
- package/lib/cursor-MjSm74IJ.mjs +273 -0
- package/lib/cursor-aJrXeYCb.mjs +273 -0
- package/lib/cursor-mJQwUKXK.mjs +5441 -0
- package/lib/device-code-DBo3B5nh.mjs +51 -0
- package/lib/device-code-DIb0FU-H.mjs +51 -0
- package/lib/device-code-OI_tQcmc.mjs +51 -0
- package/lib/devin-BHZZyMhO.mjs +95 -0
- package/lib/devin-BK7DHeca.mjs +114 -0
- package/lib/devin-CfMp3cXS.mjs +95 -0
- package/lib/devin-CldyPD8K.mjs +95 -0
- package/lib/devin-CzRpTUOA.mjs +114 -0
- package/lib/devin-D9zR5B_R.mjs +542 -0
- package/lib/devin-DXOeNyU7.mjs +542 -0
- package/lib/devin-Q1yem3lp.mjs +114 -0
- package/lib/devin-vNZTNUON.mjs +542 -0
- package/lib/error-B3bevhrs.mjs +1449 -0
- package/lib/error-Dd8DIqs-.mjs +1449 -0
- package/lib/error-yCSG0mGC.mjs +1449 -0
- package/lib/event-stream-BDPi64mK.mjs +151 -0
- package/lib/event-stream-BbFZJy-z.mjs +151 -0
- package/lib/event-stream-loUa0s1T.mjs +151 -0
- package/lib/fs-promises-shim-Bx0fpxuk.mjs +57 -0
- package/lib/github-copilot-4GaMtQmg.mjs +208 -0
- package/lib/github-copilot-B1yiyVRh.mjs +104 -0
- package/lib/github-copilot-B2HGSIJK.mjs +104 -0
- package/lib/github-copilot-BWT3eAOF.mjs +208 -0
- package/lib/github-copilot-CYkjeTi3.mjs +208 -0
- package/lib/github-copilot-jscUZ8Hf.mjs +104 -0
- package/lib/gitlab-duo-CM7Ref1H.mjs +155 -0
- package/lib/gitlab-duo-akICyfeD.mjs +155 -0
- package/lib/gitlab-duo-gubO4FNw.mjs +155 -0
- package/lib/gitlab-duo-workflow-BGAF6JDw.mjs +91 -0
- package/lib/gitlab-duo-workflow-CSEgYk3N.mjs +91 -0
- package/lib/gitlab-duo-workflow-D78tdn8E.mjs +91 -0
- package/lib/google-BS4T25Pn.mjs +30 -0
- package/lib/google-TFe-7-of.mjs +30 -0
- package/lib/google-antigravity-DGmwC2KV.mjs +198 -0
- package/lib/google-antigravity-DNYhgTpA.mjs +198 -0
- package/lib/google-antigravity-Dlkdhahq.mjs +198 -0
- package/lib/google-auth-B6gjsZvg.mjs +232 -0
- package/lib/google-auth-De7_s3eo.mjs +232 -0
- package/lib/google-auth-DhqpOYrX.mjs +232 -0
- package/lib/google-gemini-cli-BG_LRdIV.mjs +850 -0
- package/lib/google-gemini-cli-CWu8HvXW.mjs +211 -0
- package/lib/google-gemini-cli-Cb97bzQc.mjs +850 -0
- package/lib/google-gemini-cli-Cqds_Q5T.mjs +850 -0
- package/lib/google-gemini-cli-Dsztq0N5.mjs +211 -0
- package/lib/google-gemini-cli-zJhiOcND.mjs +211 -0
- package/lib/google-oauth-shared-CuEHaDDj.mjs +147 -0
- package/lib/google-oauth-shared-CwNWYdmR.mjs +147 -0
- package/lib/google-oauth-shared-yqlyqPPC.mjs +147 -0
- package/lib/google-shared-CgKmmdO3.mjs +760 -0
- package/lib/google-shared-Dr-VG-ap.mjs +760 -0
- package/lib/google-shared-DzhCb9b0.mjs +760 -0
- package/lib/google-vertex-BDN2tLaD.mjs +99 -0
- package/lib/google-vertex-DopVOQOG.mjs +99 -0
- package/lib/google-vertex-kscbkyRb.mjs +99 -0
- package/lib/google-zyDOG9x7.mjs +30 -0
- package/lib/identity-Da1GPU9a.mjs +219 -0
- package/lib/identity-DnB63pS7.mjs +219 -0
- package/lib/identity-xRP7_eSR.mjs +219 -0
- package/lib/idle-iterator-Baoyn3Hp.mjs +366 -0
- package/lib/idle-iterator-C6XbWcuB.mjs +366 -0
- package/lib/idle-iterator-DUjKQEGT.mjs +366 -0
- package/lib/index.mjs +4608 -3935
- package/lib/kimi--wUOWER5.mjs +236 -0
- package/lib/kimi-DMVI-zrZ.mjs +236 -0
- package/lib/kimi-Dh0pv3WZ.mjs +236 -0
- package/lib/markit-BL3cH47U.mjs +1417 -0
- package/lib/markit-BNiNY6SE.mjs +1417 -0
- package/lib/markit-M0jhziqU.mjs +1417 -0
- package/lib/minimax-code-BK-3eBbz.mjs +53 -0
- package/lib/minimax-code-DCbuA6Yk.mjs +53 -0
- package/lib/minimax-code-Uq8Qu9LW.mjs +53 -0
- package/lib/models-CfT4coYT.mjs +104660 -0
- package/lib/models-D_XnT6ay.mjs +104660 -0
- package/lib/models-SGASygJ3.mjs +104660 -0
- package/lib/ollama-BQMGPxtV.mjs +589 -0
- package/lib/ollama-DPzBmq89.mjs +589 -0
- package/lib/ollama-DoBz5SFm.mjs +589 -0
- package/lib/openai-codex-Bi-4S4PX.mjs +255 -0
- package/lib/openai-codex-CQL_kvYL.mjs +255 -0
- package/lib/openai-codex-Ch8CkT3p.mjs +255 -0
- package/lib/openai-codex-responses-CvxL_FMF.mjs +3144 -0
- package/lib/openai-codex-responses-Cz-2qpC7.mjs +3144 -0
- package/lib/openai-codex-responses-pejZgdZo.mjs +3144 -0
- package/lib/openai-completions-CF8IyNtP.mjs +1360 -0
- package/lib/openai-completions-DIf361kF.mjs +1360 -0
- package/lib/openai-completions-i8doczAk.mjs +1360 -0
- package/lib/openai-reasoning-fallback-DGVVLgd1.mjs +286 -0
- package/lib/openai-reasoning-fallback-Nj6yB2rY.mjs +286 -0
- package/lib/openai-reasoning-fallback-OdJREP1o.mjs +286 -0
- package/lib/openai-responses-BqXJInHX.mjs +867 -0
- package/lib/openai-responses-DTkBiiy-.mjs +867 -0
- package/lib/openai-responses-Db_a-U4-.mjs +867 -0
- package/lib/opencode-DaJjcUbf.mjs +38 -0
- package/lib/opencode-DhMolSoB.mjs +38 -0
- package/lib/opencode-Rq_Q2vAO.mjs +38 -0
- package/lib/perplexity-9b-RQ0mV.mjs +194 -0
- package/lib/perplexity-C4iLVMUj.mjs +194 -0
- package/lib/perplexity-Uu7Jzg5b.mjs +194 -0
- package/lib/proxy-DDqrmjjC.mjs +190 -0
- package/lib/proxy-ZtUcl6r5.mjs +190 -0
- package/lib/proxy-pM_NIv-H.mjs +190 -0
- package/lib/request-debug-HJMoJncL.mjs +183 -0
- package/lib/sanitize-text-CfcXzw5X.mjs +33 -0
- package/lib/scrapers-BkFfcPHj.mjs +9198 -0
- package/lib/scrapers-CL-WgdU1.mjs +9198 -0
- package/lib/scrapers-CVptboMs.mjs +9198 -0
- package/lib/scrapers-CipyKyCH.mjs +9198 -0
- package/lib/scrapers-DGfrYhtw.mjs +9198 -0
- package/lib/scrapers-DSUPYoUF.mjs +9198 -0
- package/lib/scrapers-DZ2GXmp7.mjs +9198 -0
- package/lib/scrapers-nhQAvc8d.mjs +9198 -0
- package/lib/shell-snapshot-fn-env.sh +67 -43
- package/lib/src-BgpusnsB.mjs +5076 -0
- package/lib/src-DTid0g4K.mjs +5001 -0
- package/lib/src-lDmkSRbm.mjs +5006 -0
- package/lib/stream-BlldLkVq.mjs +10236 -0
- package/lib/stream-CRtexYLe.mjs +10236 -0
- package/lib/stream-C_RAoxJC.mjs +10236 -0
- package/lib/stream-markup-healing-2toHXWXM.mjs +491 -0
- package/lib/stream-markup-healing-DMsxBx1L.mjs +491 -0
- package/lib/stream-markup-healing-KMkiAA00.mjs +491 -0
- package/lib/turndown-DN7ByzEI.mjs +667 -0
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/config/fields.d.ts +1 -1
- package/lib/types/config/settings.d.ts +25 -3
- package/lib/types/config/truncate.d.ts +9 -5
- package/lib/types/tools/bash/background.d.ts +1 -1
- package/lib/types/tools/bash/bash-executor.d.ts +4 -0
- package/lib/types/tools/bash/bash-interceptor.d.ts +10 -8
- package/lib/types/tools/bash/cd-workdir.d.ts +35 -0
- package/lib/types/tools/bash/non-interactive-env.d.ts +2 -0
- package/lib/types/tools/bash/render.d.ts +4 -3
- package/lib/types/tools/bash/sanitize-text.d.ts +5 -0
- package/lib/types/tools/bash/shell-snapshot.d.ts +4 -1
- package/lib/types/tools/bash/shell-tokenize.d.ts +60 -0
- package/lib/types/tools/bash/streaming-output.d.ts +12 -212
- package/lib/types/tools/bash/which.d.ts +20 -0
- package/lib/types/tools/bash/windows-shell.d.ts +31 -0
- package/lib/types/tools/edit/adapter/index.d.ts +25 -3
- package/lib/types/tools/edit/adapter/tools/auto-generated-guard.d.ts +7 -17
- package/lib/types/tools/glob/adapter/index.d.ts +27 -1
- package/lib/types/tools/grep/adapter/index.d.ts +29 -1
- package/lib/types/tools/omp/edit/dispatch.d.ts +43 -0
- package/lib/types/tools/omp/edit/hashline/noop-loop-guard.d.ts +3 -1
- package/lib/types/tools/omp/sdk.d.ts +6 -0
- package/lib/types/tools/omp/tools/auto-generated-guard.d.ts +20 -0
- package/lib/types/tools/omp/tools/fetch.d.ts +2 -0
- package/lib/types/tools/omp/tools/read.d.ts +2 -8
- package/lib/types/tools/omp/tools/write.d.ts +4 -4
- package/lib/types/tools/omp/utils/image-loading.d.ts +10 -36
- package/lib/types/tools/read/adapter/index.d.ts +4 -1
- package/lib/types/tools/read-image/index.d.ts +4 -0
- package/lib/types/tools/shared/auto-generated-guard.dsh.d.ts +16 -4
- package/lib/types/tools/shared/bun-shim.d.ts +39 -3
- package/lib/types/tools/shared/fs-promises-shim.d.ts +3 -1
- package/lib/types/tools/shared/image-bridge.d.ts +98 -0
- package/lib/types/tools/shared/omp-prompt.d.ts +17 -9
- package/lib/types/tools/shared/session-state.d.ts +9 -3
- package/lib/utils-2Wq2eATG.mjs +8119 -0
- package/lib/utils-BnX8O3vi.mjs +12303 -0
- package/lib/utils-Bw139LTz.mjs +8119 -0
- package/lib/utils-CE8N8P4Q.mjs +12315 -0
- package/lib/utils-CZw4tVZQ.mjs +12315 -0
- package/lib/utils-C_MrQ_0z.mjs +12301 -0
- package/lib/utils-CiGN7OHR.mjs +12315 -0
- package/lib/utils-Cp76gCyk.mjs +8119 -0
- package/lib/utils-D0GRDgAr.mjs +12315 -0
- package/lib/utils-D0Z1fyoO.mjs +12299 -0
- package/lib/utils-D2YknRk4.mjs +51 -0
- package/lib/utils-DppGHXQB.mjs +51 -0
- package/lib/utils-DzXZDfYc.mjs +51 -0
- package/lib/utils-W8WdSBpX.mjs +12315 -0
- package/lib/vision-guard-01qSwFpf.mjs +92 -0
- package/lib/vision-guard-BDD4OrKo.mjs +92 -0
- package/lib/vision-guard-DzZGaOga.mjs +92 -0
- package/lib/wafer-CgtPHerf.mjs +17 -0
- package/lib/wafer-DRU0EjZX.mjs +17 -0
- package/lib/wafer-cBtrn6q9.mjs +17 -0
- package/lib/xai-oauth-Buk8XVvM.mjs +446 -0
- package/lib/xai-oauth-CMal8l1O.mjs +446 -0
- package/lib/xai-oauth-DPHDXKD7.mjs +446 -0
- package/lib/xiaomi-CZgwvX2G.mjs +157 -0
- package/lib/xiaomi-D2qT5cAC.mjs +157 -0
- package/lib/xiaomi-Dd87KSg5.mjs +157 -0
- package/lib/zai-7DWMkEqM.mjs +203 -0
- package/lib/zai-C59YnomG.mjs +203 -0
- package/lib/zai-CFeOt-53.mjs +203 -0
- package/lib/zip-Cg9ANN_U.mjs +1316 -0
- package/lib/zip-D36ZKsP8.mjs +1316 -0
- package/lib/zip-D6QXpvaJ.mjs +1316 -0
- package/package.json +14 -10
- package/presets/package.json +1 -1
- package/presets/tool-plus-ptc/preset.yml +1 -1
- package/presets/tool-plus-standard/preset.yml +1 -1
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { r as __exportAll } from "./fs-promises-shim-B-9cMxz5.mjs";
|
|
4
|
+
import { P as $env } from "./src-DTid0g4K.mjs";
|
|
5
|
+
import { B as OpenAIHttpError, g as MissingApiKeyError, l as finalize, n as StreamTimeoutError, s as ProviderResponseError, t as ConfigurationError, v as AbortError } from "./error-B3bevhrs.mjs";
|
|
6
|
+
import { L as sanitizeSchemaForOpenAIResponses, k as toolWireSchema, s as resolveCacheRetention } from "./utils-2Wq2eATG.mjs";
|
|
7
|
+
import { C as applyResponsesReasoningParams, D as buildResponsesInput, K as getOpenAIPromptCacheKey, N as createInitialResponsesAssistantMessage, Q as isOpenAIResponsesProgressEvent, g as applyCommonResponsesSamplingParams, it as parseAzureDeploymentNameMap, n as getEnvApiKey, ot as processResponsesStream, yt as mapToOpenAIResponsesToolChoice } from "./stream-C_RAoxJC.mjs";
|
|
8
|
+
import { t as createAbortSourceTracker } from "./abort-B7izMMna.mjs";
|
|
9
|
+
import { t as AssistantMessageEventStream } from "./event-stream-BDPi64mK.mjs";
|
|
10
|
+
import { n as getOpenAIStreamFirstEventTimeoutMs, o as iterateWithIdleTimeout, r as getOpenAIStreamIdleTimeoutMs } from "./idle-iterator-C6XbWcuB.mjs";
|
|
11
|
+
import { c as postOpenAIStream, r as createOpenAIReasoningEffortFallbackKey, s as resolveOpenAIReasoningEffortFallback, t as applyOpenAIReasoningEffortFallback } from "./openai-reasoning-fallback-DGVVLgd1.mjs";
|
|
12
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/providers/azure-openai-responses.ts
|
|
13
|
+
var azure_openai_responses_exports = /* @__PURE__ */ __exportAll({ streamAzureOpenAIResponses: () => streamAzureOpenAIResponses });
|
|
14
|
+
const DEFAULT_AZURE_API_VERSION = "v1";
|
|
15
|
+
const AZURE_OPENAI_RESPONSES_FIRST_EVENT_TIMEOUT_MESSAGE = "Azure OpenAI responses stream timed out while waiting for the first event";
|
|
16
|
+
function resolveDeploymentName(model, options) {
|
|
17
|
+
if (options?.azureDeploymentName) return options.azureDeploymentName;
|
|
18
|
+
return parseAzureDeploymentNameMap($env.AZURE_OPENAI_DEPLOYMENT_NAME_MAP).get(model.id) ?? model.id;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generate function for Azure OpenAI Responses API
|
|
22
|
+
*/
|
|
23
|
+
const streamAzureOpenAIResponses = (model, context, options) => {
|
|
24
|
+
if (options?.promptCache?.mode === "explicit" && resolveCacheRetention(options.cacheRetention) !== "none") throw new ConfigurationError(`OpenAI explicit prompt caching is unsupported for ${model.provider}/${model.id}; Azure Responses does not emit explicit cache controls.`);
|
|
25
|
+
const stream = new AssistantMessageEventStream();
|
|
26
|
+
(async () => {
|
|
27
|
+
const startTime = performance.now();
|
|
28
|
+
let firstTokenTime;
|
|
29
|
+
const deploymentName = resolveDeploymentName(model, options);
|
|
30
|
+
const output = createInitialResponsesAssistantMessage("azure-openai-responses", model.provider, model.id);
|
|
31
|
+
let rawRequestDump;
|
|
32
|
+
const abortTracker = createAbortSourceTracker(options?.signal);
|
|
33
|
+
const firstEventTimeoutAbortError = new StreamTimeoutError(AZURE_OPENAI_RESPONSES_FIRST_EVENT_TIMEOUT_MESSAGE);
|
|
34
|
+
const { requestAbortController, requestSignal } = abortTracker;
|
|
35
|
+
const onSseEvent = options?.onSseEvent;
|
|
36
|
+
const rawSseObserver = onSseEvent ? (event) => {
|
|
37
|
+
if (!event.event && event.data && event.data !== "[DONE]") try {
|
|
38
|
+
const parsed = JSON.parse(event.data);
|
|
39
|
+
const resolvedEvent = typeof parsed.type === "string" ? parsed.type : typeof parsed.object === "string" ? parsed.object : null;
|
|
40
|
+
if (resolvedEvent) {
|
|
41
|
+
event.event = resolvedEvent;
|
|
42
|
+
event.raw = [`event: ${resolvedEvent}`, ...event.raw];
|
|
43
|
+
}
|
|
44
|
+
} catch {}
|
|
45
|
+
onSseEvent(event, model);
|
|
46
|
+
} : void 0;
|
|
47
|
+
try {
|
|
48
|
+
const { url, headers, baseUrl } = buildAzureResponsesRequest(model, options?.apiKey || getEnvApiKey(model.provider) || "", options);
|
|
49
|
+
const requestModel = modelForAzureEndpoint(model, baseUrl);
|
|
50
|
+
let params = buildParams(requestModel, context, options, deploymentName);
|
|
51
|
+
const replacementPayload = await options?.onPayload?.(params, requestModel);
|
|
52
|
+
if (replacementPayload !== void 0) params = replacementPayload;
|
|
53
|
+
const idleTimeoutMs = options?.streamIdleTimeoutMs ?? getOpenAIStreamIdleTimeoutMs();
|
|
54
|
+
const firstEventTimeoutMs = options?.streamFirstEventTimeoutMs ?? getOpenAIStreamFirstEventTimeoutMs(idleTimeoutMs);
|
|
55
|
+
const requestTimeoutMs = firstEventTimeoutMs !== void 0 && firstEventTimeoutMs > 0 ? firstEventTimeoutMs : void 0;
|
|
56
|
+
rawRequestDump = {
|
|
57
|
+
provider: model.provider,
|
|
58
|
+
api: output.api,
|
|
59
|
+
model: model.id,
|
|
60
|
+
method: "POST",
|
|
61
|
+
url,
|
|
62
|
+
body: params
|
|
63
|
+
};
|
|
64
|
+
const reasoningEffortFallbackKey = createOpenAIReasoningEffortFallbackKey("azure-responses", url, typeof params.model === "string" ? params.model : model.id);
|
|
65
|
+
const attemptedReasoningEffortFallbacks = /* @__PURE__ */ new Set();
|
|
66
|
+
let openaiStream;
|
|
67
|
+
while (true) {
|
|
68
|
+
let requestTimeout;
|
|
69
|
+
if (requestTimeoutMs !== void 0) requestTimeout = setTimeout(() => abortTracker.abortLocally(firstEventTimeoutAbortError), requestTimeoutMs);
|
|
70
|
+
try {
|
|
71
|
+
const headersWithTimeout = { ...headers };
|
|
72
|
+
if (requestTimeoutMs !== void 0) headersWithTimeout["X-Stainless-Timeout"] = Math.floor(requestTimeoutMs / 1e3).toString();
|
|
73
|
+
openaiStream = (await postOpenAIStream({
|
|
74
|
+
url,
|
|
75
|
+
headers: headersWithTimeout,
|
|
76
|
+
body: params,
|
|
77
|
+
signal: requestSignal,
|
|
78
|
+
fetch: options?.fetch,
|
|
79
|
+
onSseEvent: rawSseObserver
|
|
80
|
+
})).events;
|
|
81
|
+
break;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
const capturedErrorResponse = error instanceof OpenAIHttpError ? error.captured : void 0;
|
|
84
|
+
const reasoningEffortFallback = !requestSignal.aborted ? resolveOpenAIReasoningEffortFallback(error, capturedErrorResponse, params) : void 0;
|
|
85
|
+
if (reasoningEffortFallback === void 0) throw error;
|
|
86
|
+
const retryMarker = `${reasoningEffortFallbackKey}:${String(reasoningEffortFallback)}`;
|
|
87
|
+
if (attemptedReasoningEffortFallbacks.has(retryMarker)) throw error;
|
|
88
|
+
attemptedReasoningEffortFallbacks.add(retryMarker);
|
|
89
|
+
applyOpenAIReasoningEffortFallback(params, reasoningEffortFallback);
|
|
90
|
+
rawRequestDump.body = params;
|
|
91
|
+
} finally {
|
|
92
|
+
if (requestTimeout !== void 0) clearTimeout(requestTimeout);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
stream.push({
|
|
96
|
+
type: "start",
|
|
97
|
+
partial: output
|
|
98
|
+
});
|
|
99
|
+
const timedOpenaiStream = iterateWithIdleTimeout(openaiStream, {
|
|
100
|
+
idleTimeoutMs,
|
|
101
|
+
firstItemTimeoutMs: firstEventTimeoutMs,
|
|
102
|
+
firstItemErrorMessage: AZURE_OPENAI_RESPONSES_FIRST_EVENT_TIMEOUT_MESSAGE,
|
|
103
|
+
errorMessage: "Azure OpenAI responses stream stalled while waiting for the next event",
|
|
104
|
+
onIdle: () => requestAbortController.abort(),
|
|
105
|
+
onFirstItemTimeout: () => abortTracker.abortLocally(firstEventTimeoutAbortError),
|
|
106
|
+
abortSignal: options?.signal,
|
|
107
|
+
isProgressItem: isOpenAIResponsesProgressEvent
|
|
108
|
+
});
|
|
109
|
+
let sawTerminalResponseEvent = false;
|
|
110
|
+
await processResponsesStream(timedOpenaiStream, output, stream, model, {
|
|
111
|
+
onFirstToken: () => {
|
|
112
|
+
if (!firstTokenTime) firstTokenTime = performance.now();
|
|
113
|
+
},
|
|
114
|
+
onCompleted: () => {
|
|
115
|
+
sawTerminalResponseEvent = true;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const firstEventTimeoutError = abortTracker.getLocalAbortReason();
|
|
119
|
+
if (firstEventTimeoutError) throw firstEventTimeoutError;
|
|
120
|
+
if (abortTracker.wasCallerAbort()) throw new AbortError();
|
|
121
|
+
if (!sawTerminalResponseEvent) throw new ProviderResponseError("Azure OpenAI responses stream closed before a terminal response event was received", {
|
|
122
|
+
provider: model.provider,
|
|
123
|
+
kind: "incomplete-stream"
|
|
124
|
+
});
|
|
125
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") throw new ProviderResponseError(output.errorMessage ?? "An unknown error occurred", {
|
|
126
|
+
provider: model.provider,
|
|
127
|
+
kind: "output"
|
|
128
|
+
});
|
|
129
|
+
output.duration = performance.now() - startTime;
|
|
130
|
+
if (firstTokenTime) output.ttft = firstTokenTime - startTime;
|
|
131
|
+
stream.push({
|
|
132
|
+
type: "done",
|
|
133
|
+
reason: output.stopReason,
|
|
134
|
+
message: output
|
|
135
|
+
});
|
|
136
|
+
stream.end();
|
|
137
|
+
} catch (error) {
|
|
138
|
+
const result = await finalize(error, {
|
|
139
|
+
api: model.api,
|
|
140
|
+
abortTracker,
|
|
141
|
+
rawRequestDump
|
|
142
|
+
});
|
|
143
|
+
output.stopReason = result.stopReason;
|
|
144
|
+
output.errorStatus = result.status;
|
|
145
|
+
output.errorId = result.id;
|
|
146
|
+
output.errorMessage = result.message;
|
|
147
|
+
output.duration = performance.now() - startTime;
|
|
148
|
+
if (firstTokenTime) output.ttft = firstTokenTime - startTime;
|
|
149
|
+
stream.push({
|
|
150
|
+
type: "error",
|
|
151
|
+
reason: output.stopReason,
|
|
152
|
+
error: output
|
|
153
|
+
});
|
|
154
|
+
stream.end();
|
|
155
|
+
}
|
|
156
|
+
})();
|
|
157
|
+
return stream;
|
|
158
|
+
};
|
|
159
|
+
function resolveAzureConfig(model, options) {
|
|
160
|
+
const apiVersion = options?.azureApiVersion || $env.AZURE_OPENAI_API_VERSION || DEFAULT_AZURE_API_VERSION;
|
|
161
|
+
const baseUrl = options?.azureBaseUrl?.trim() || $env.AZURE_OPENAI_BASE_URL?.trim() || void 0;
|
|
162
|
+
const resourceName = options?.azureResourceName || $env.AZURE_OPENAI_RESOURCE_NAME;
|
|
163
|
+
let resolvedBaseUrl = baseUrl;
|
|
164
|
+
if (!resolvedBaseUrl && resourceName) resolvedBaseUrl = `https://${resourceName}.openai.azure.com/openai/v1`;
|
|
165
|
+
if (!resolvedBaseUrl && model.baseUrl) resolvedBaseUrl = model.baseUrl;
|
|
166
|
+
if (!resolvedBaseUrl) throw new ConfigurationError("Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.");
|
|
167
|
+
return {
|
|
168
|
+
baseUrl: resolvedBaseUrl.replace(/\/+$/, ""),
|
|
169
|
+
apiVersion
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function modelForAzureEndpoint(model, baseUrl) {
|
|
173
|
+
if (model.supportsComputerUseConfig !== void 0 || model.supportsComputerUse !== true) return model;
|
|
174
|
+
try {
|
|
175
|
+
const url = new URL(baseUrl);
|
|
176
|
+
if (url.protocol === "https:" && (url.hostname.endsWith(".openai.azure.com") || url.hostname === "models.inference.ai.azure.com")) return model;
|
|
177
|
+
} catch {}
|
|
178
|
+
return {
|
|
179
|
+
...model,
|
|
180
|
+
supportsComputerUse: false
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Replicates the `AzureOpenAI` SDK client's request shape for `/responses`:
|
|
185
|
+
* a string api key becomes a single `api-key` header (azure.mjs `authHeaders`;
|
|
186
|
+
* never `Authorization: Bearer`), `api-version` rides as a query parameter
|
|
187
|
+
* (azure.mjs constructor `defaultQuery`), and `/responses` is not a
|
|
188
|
+
* deployment-scoped path, so no `/deployments/{model}` URL rewriting applies.
|
|
189
|
+
* Custom model/options headers may override the auth header, matching the SDK's
|
|
190
|
+
* `buildHeaders` precedence.
|
|
191
|
+
*/
|
|
192
|
+
function buildAzureResponsesRequest(model, apiKey, options) {
|
|
193
|
+
if (!apiKey) {
|
|
194
|
+
const envKey = $env.AZURE_OPENAI_API_KEY;
|
|
195
|
+
if (!envKey) throw new MissingApiKeyError(void 0, "Azure OpenAI API key is required. Set AZURE_OPENAI_API_KEY environment variable or pass it as an argument.");
|
|
196
|
+
apiKey = envKey;
|
|
197
|
+
}
|
|
198
|
+
const headers = {
|
|
199
|
+
"api-key": apiKey,
|
|
200
|
+
...model.headers ?? {}
|
|
201
|
+
};
|
|
202
|
+
if (options?.headers) Object.assign(headers, options.headers);
|
|
203
|
+
const { baseUrl, apiVersion } = resolveAzureConfig(model, options);
|
|
204
|
+
return {
|
|
205
|
+
url: `${baseUrl}/responses?api-version=${encodeURIComponent(apiVersion)}`,
|
|
206
|
+
headers,
|
|
207
|
+
baseUrl
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function buildParams(model, context, options, deploymentName) {
|
|
211
|
+
const systemRole = model.reasoning && model.compat.supportsDeveloperRole ? "developer" : "system";
|
|
212
|
+
const params = {
|
|
213
|
+
model: deploymentName,
|
|
214
|
+
input: buildResponsesInput({
|
|
215
|
+
model,
|
|
216
|
+
context,
|
|
217
|
+
strictResponsesPairing: true,
|
|
218
|
+
supportsImageDetailOriginal: model.compat.supportsImageDetailOriginal,
|
|
219
|
+
systemRole,
|
|
220
|
+
nativeHistory: {
|
|
221
|
+
replay: true,
|
|
222
|
+
filterReasoning: false
|
|
223
|
+
},
|
|
224
|
+
includeThinkingSignatures: true,
|
|
225
|
+
developerStringContent: true,
|
|
226
|
+
preserveAssistantMessageIds: true
|
|
227
|
+
}),
|
|
228
|
+
stream: true,
|
|
229
|
+
prompt_cache_key: getOpenAIPromptCacheKey(options),
|
|
230
|
+
store: false
|
|
231
|
+
};
|
|
232
|
+
applyCommonResponsesSamplingParams(params, options, model);
|
|
233
|
+
if (options?.include?.length) params.include = Array.from(new Set(options.include));
|
|
234
|
+
if (context.tools) {
|
|
235
|
+
const serializedTools = [];
|
|
236
|
+
for (const tool of context.tools) {
|
|
237
|
+
if (tool.native?.type === "computer") {
|
|
238
|
+
if (model.supportsComputerUse === true) {
|
|
239
|
+
serializedTools.push({ type: "computer" });
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
} else if (tool.native !== void 0) continue;
|
|
243
|
+
serializedTools.push({
|
|
244
|
+
type: "function",
|
|
245
|
+
name: tool.name,
|
|
246
|
+
description: tool.description || "",
|
|
247
|
+
parameters: sanitizeSchemaForOpenAIResponses(toolWireSchema(tool)),
|
|
248
|
+
strict: false
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
if (serializedTools.length > 0) {
|
|
252
|
+
params.tools = serializedTools;
|
|
253
|
+
if (options?.toolChoice) {
|
|
254
|
+
let toolChoice = mapToOpenAIResponsesToolChoice(options.toolChoice);
|
|
255
|
+
const hasComputerTool = serializedTools.some((tool) => tool.type === "computer");
|
|
256
|
+
if (toolChoice && typeof toolChoice !== "string" && toolChoice.type === "computer" && !hasComputerTool) {
|
|
257
|
+
const computer = context.tools.find((tool) => tool.native?.type === "computer");
|
|
258
|
+
if (computer && serializedTools.some((tool) => tool.type === "function" && tool.name === computer.name)) toolChoice = {
|
|
259
|
+
type: "function",
|
|
260
|
+
name: computer.name
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
if (toolChoice && typeof toolChoice !== "string" && toolChoice.type === "function" && hasComputerTool) {
|
|
264
|
+
if (context.tools.find((tool) => tool.native?.type === "computer")?.name === toolChoice.name) toolChoice = { type: "computer" };
|
|
265
|
+
}
|
|
266
|
+
if (toolChoice && (typeof toolChoice === "string" || toolChoice.type === "computer" && hasComputerTool || toolChoice.type === "function" && serializedTools.some((tool) => tool.type === "function" && tool.name === toolChoice.name))) params.tool_choice = toolChoice;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
applyResponsesReasoningParams(params, model, options);
|
|
271
|
+
return params;
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
export { azure_openai_responses_exports as t };
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { r as __exportAll } from "./fs-promises-shim-B-9cMxz5.mjs";
|
|
4
|
+
import { P as $env } from "./src-lDmkSRbm.mjs";
|
|
5
|
+
import { B as OpenAIHttpError, g as MissingApiKeyError, l as finalize, n as StreamTimeoutError, s as ProviderResponseError, t as ConfigurationError, v as AbortError } from "./error-yCSG0mGC.mjs";
|
|
6
|
+
import { L as sanitizeSchemaForOpenAIResponses, k as toolWireSchema, s as resolveCacheRetention } from "./utils-Bw139LTz.mjs";
|
|
7
|
+
import { C as applyResponsesReasoningParams, D as buildResponsesInput, K as getOpenAIPromptCacheKey, N as createInitialResponsesAssistantMessage, Q as isOpenAIResponsesProgressEvent, g as applyCommonResponsesSamplingParams, it as parseAzureDeploymentNameMap, n as getEnvApiKey, ot as processResponsesStream, yt as mapToOpenAIResponsesToolChoice } from "./stream-BlldLkVq.mjs";
|
|
8
|
+
import { t as createAbortSourceTracker } from "./abort-D1_Z5Ut5.mjs";
|
|
9
|
+
import { t as AssistantMessageEventStream } from "./event-stream-loUa0s1T.mjs";
|
|
10
|
+
import { n as getOpenAIStreamFirstEventTimeoutMs, o as iterateWithIdleTimeout, r as getOpenAIStreamIdleTimeoutMs } from "./idle-iterator-Baoyn3Hp.mjs";
|
|
11
|
+
import { c as postOpenAIStream, r as createOpenAIReasoningEffortFallbackKey, s as resolveOpenAIReasoningEffortFallback, t as applyOpenAIReasoningEffortFallback } from "./openai-reasoning-fallback-OdJREP1o.mjs";
|
|
12
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/providers/azure-openai-responses.ts
|
|
13
|
+
var azure_openai_responses_exports = /* @__PURE__ */ __exportAll({ streamAzureOpenAIResponses: () => streamAzureOpenAIResponses });
|
|
14
|
+
const DEFAULT_AZURE_API_VERSION = "v1";
|
|
15
|
+
const AZURE_OPENAI_RESPONSES_FIRST_EVENT_TIMEOUT_MESSAGE = "Azure OpenAI responses stream timed out while waiting for the first event";
|
|
16
|
+
function resolveDeploymentName(model, options) {
|
|
17
|
+
if (options?.azureDeploymentName) return options.azureDeploymentName;
|
|
18
|
+
return parseAzureDeploymentNameMap($env.AZURE_OPENAI_DEPLOYMENT_NAME_MAP).get(model.id) ?? model.id;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generate function for Azure OpenAI Responses API
|
|
22
|
+
*/
|
|
23
|
+
const streamAzureOpenAIResponses = (model, context, options) => {
|
|
24
|
+
if (options?.promptCache?.mode === "explicit" && resolveCacheRetention(options.cacheRetention) !== "none") throw new ConfigurationError(`OpenAI explicit prompt caching is unsupported for ${model.provider}/${model.id}; Azure Responses does not emit explicit cache controls.`);
|
|
25
|
+
const stream = new AssistantMessageEventStream();
|
|
26
|
+
(async () => {
|
|
27
|
+
const startTime = performance.now();
|
|
28
|
+
let firstTokenTime;
|
|
29
|
+
const deploymentName = resolveDeploymentName(model, options);
|
|
30
|
+
const output = createInitialResponsesAssistantMessage("azure-openai-responses", model.provider, model.id);
|
|
31
|
+
let rawRequestDump;
|
|
32
|
+
const abortTracker = createAbortSourceTracker(options?.signal);
|
|
33
|
+
const firstEventTimeoutAbortError = new StreamTimeoutError(AZURE_OPENAI_RESPONSES_FIRST_EVENT_TIMEOUT_MESSAGE);
|
|
34
|
+
const { requestAbortController, requestSignal } = abortTracker;
|
|
35
|
+
const onSseEvent = options?.onSseEvent;
|
|
36
|
+
const rawSseObserver = onSseEvent ? (event) => {
|
|
37
|
+
if (!event.event && event.data && event.data !== "[DONE]") try {
|
|
38
|
+
const parsed = JSON.parse(event.data);
|
|
39
|
+
const resolvedEvent = typeof parsed.type === "string" ? parsed.type : typeof parsed.object === "string" ? parsed.object : null;
|
|
40
|
+
if (resolvedEvent) {
|
|
41
|
+
event.event = resolvedEvent;
|
|
42
|
+
event.raw = [`event: ${resolvedEvent}`, ...event.raw];
|
|
43
|
+
}
|
|
44
|
+
} catch {}
|
|
45
|
+
onSseEvent(event, model);
|
|
46
|
+
} : void 0;
|
|
47
|
+
try {
|
|
48
|
+
const { url, headers, baseUrl } = buildAzureResponsesRequest(model, options?.apiKey || getEnvApiKey(model.provider) || "", options);
|
|
49
|
+
const requestModel = modelForAzureEndpoint(model, baseUrl);
|
|
50
|
+
let params = buildParams(requestModel, context, options, deploymentName);
|
|
51
|
+
const replacementPayload = await options?.onPayload?.(params, requestModel);
|
|
52
|
+
if (replacementPayload !== void 0) params = replacementPayload;
|
|
53
|
+
const idleTimeoutMs = options?.streamIdleTimeoutMs ?? getOpenAIStreamIdleTimeoutMs();
|
|
54
|
+
const firstEventTimeoutMs = options?.streamFirstEventTimeoutMs ?? getOpenAIStreamFirstEventTimeoutMs(idleTimeoutMs);
|
|
55
|
+
const requestTimeoutMs = firstEventTimeoutMs !== void 0 && firstEventTimeoutMs > 0 ? firstEventTimeoutMs : void 0;
|
|
56
|
+
rawRequestDump = {
|
|
57
|
+
provider: model.provider,
|
|
58
|
+
api: output.api,
|
|
59
|
+
model: model.id,
|
|
60
|
+
method: "POST",
|
|
61
|
+
url,
|
|
62
|
+
body: params
|
|
63
|
+
};
|
|
64
|
+
const reasoningEffortFallbackKey = createOpenAIReasoningEffortFallbackKey("azure-responses", url, typeof params.model === "string" ? params.model : model.id);
|
|
65
|
+
const attemptedReasoningEffortFallbacks = /* @__PURE__ */ new Set();
|
|
66
|
+
let openaiStream;
|
|
67
|
+
while (true) {
|
|
68
|
+
let requestTimeout;
|
|
69
|
+
if (requestTimeoutMs !== void 0) requestTimeout = setTimeout(() => abortTracker.abortLocally(firstEventTimeoutAbortError), requestTimeoutMs);
|
|
70
|
+
try {
|
|
71
|
+
const headersWithTimeout = { ...headers };
|
|
72
|
+
if (requestTimeoutMs !== void 0) headersWithTimeout["X-Stainless-Timeout"] = Math.floor(requestTimeoutMs / 1e3).toString();
|
|
73
|
+
openaiStream = (await postOpenAIStream({
|
|
74
|
+
url,
|
|
75
|
+
headers: headersWithTimeout,
|
|
76
|
+
body: params,
|
|
77
|
+
signal: requestSignal,
|
|
78
|
+
fetch: options?.fetch,
|
|
79
|
+
onSseEvent: rawSseObserver
|
|
80
|
+
})).events;
|
|
81
|
+
break;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
const capturedErrorResponse = error instanceof OpenAIHttpError ? error.captured : void 0;
|
|
84
|
+
const reasoningEffortFallback = !requestSignal.aborted ? resolveOpenAIReasoningEffortFallback(error, capturedErrorResponse, params) : void 0;
|
|
85
|
+
if (reasoningEffortFallback === void 0) throw error;
|
|
86
|
+
const retryMarker = `${reasoningEffortFallbackKey}:${String(reasoningEffortFallback)}`;
|
|
87
|
+
if (attemptedReasoningEffortFallbacks.has(retryMarker)) throw error;
|
|
88
|
+
attemptedReasoningEffortFallbacks.add(retryMarker);
|
|
89
|
+
applyOpenAIReasoningEffortFallback(params, reasoningEffortFallback);
|
|
90
|
+
rawRequestDump.body = params;
|
|
91
|
+
} finally {
|
|
92
|
+
if (requestTimeout !== void 0) clearTimeout(requestTimeout);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
stream.push({
|
|
96
|
+
type: "start",
|
|
97
|
+
partial: output
|
|
98
|
+
});
|
|
99
|
+
const timedOpenaiStream = iterateWithIdleTimeout(openaiStream, {
|
|
100
|
+
idleTimeoutMs,
|
|
101
|
+
firstItemTimeoutMs: firstEventTimeoutMs,
|
|
102
|
+
firstItemErrorMessage: AZURE_OPENAI_RESPONSES_FIRST_EVENT_TIMEOUT_MESSAGE,
|
|
103
|
+
errorMessage: "Azure OpenAI responses stream stalled while waiting for the next event",
|
|
104
|
+
onIdle: () => requestAbortController.abort(),
|
|
105
|
+
onFirstItemTimeout: () => abortTracker.abortLocally(firstEventTimeoutAbortError),
|
|
106
|
+
abortSignal: options?.signal,
|
|
107
|
+
isProgressItem: isOpenAIResponsesProgressEvent
|
|
108
|
+
});
|
|
109
|
+
let sawTerminalResponseEvent = false;
|
|
110
|
+
await processResponsesStream(timedOpenaiStream, output, stream, model, {
|
|
111
|
+
onFirstToken: () => {
|
|
112
|
+
if (!firstTokenTime) firstTokenTime = performance.now();
|
|
113
|
+
},
|
|
114
|
+
onCompleted: () => {
|
|
115
|
+
sawTerminalResponseEvent = true;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const firstEventTimeoutError = abortTracker.getLocalAbortReason();
|
|
119
|
+
if (firstEventTimeoutError) throw firstEventTimeoutError;
|
|
120
|
+
if (abortTracker.wasCallerAbort()) throw new AbortError();
|
|
121
|
+
if (!sawTerminalResponseEvent) throw new ProviderResponseError("Azure OpenAI responses stream closed before a terminal response event was received", {
|
|
122
|
+
provider: model.provider,
|
|
123
|
+
kind: "incomplete-stream"
|
|
124
|
+
});
|
|
125
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") throw new ProviderResponseError(output.errorMessage ?? "An unknown error occurred", {
|
|
126
|
+
provider: model.provider,
|
|
127
|
+
kind: "output"
|
|
128
|
+
});
|
|
129
|
+
output.duration = performance.now() - startTime;
|
|
130
|
+
if (firstTokenTime) output.ttft = firstTokenTime - startTime;
|
|
131
|
+
stream.push({
|
|
132
|
+
type: "done",
|
|
133
|
+
reason: output.stopReason,
|
|
134
|
+
message: output
|
|
135
|
+
});
|
|
136
|
+
stream.end();
|
|
137
|
+
} catch (error) {
|
|
138
|
+
const result = await finalize(error, {
|
|
139
|
+
api: model.api,
|
|
140
|
+
abortTracker,
|
|
141
|
+
rawRequestDump
|
|
142
|
+
});
|
|
143
|
+
output.stopReason = result.stopReason;
|
|
144
|
+
output.errorStatus = result.status;
|
|
145
|
+
output.errorId = result.id;
|
|
146
|
+
output.errorMessage = result.message;
|
|
147
|
+
output.duration = performance.now() - startTime;
|
|
148
|
+
if (firstTokenTime) output.ttft = firstTokenTime - startTime;
|
|
149
|
+
stream.push({
|
|
150
|
+
type: "error",
|
|
151
|
+
reason: output.stopReason,
|
|
152
|
+
error: output
|
|
153
|
+
});
|
|
154
|
+
stream.end();
|
|
155
|
+
}
|
|
156
|
+
})();
|
|
157
|
+
return stream;
|
|
158
|
+
};
|
|
159
|
+
function resolveAzureConfig(model, options) {
|
|
160
|
+
const apiVersion = options?.azureApiVersion || $env.AZURE_OPENAI_API_VERSION || DEFAULT_AZURE_API_VERSION;
|
|
161
|
+
const baseUrl = options?.azureBaseUrl?.trim() || $env.AZURE_OPENAI_BASE_URL?.trim() || void 0;
|
|
162
|
+
const resourceName = options?.azureResourceName || $env.AZURE_OPENAI_RESOURCE_NAME;
|
|
163
|
+
let resolvedBaseUrl = baseUrl;
|
|
164
|
+
if (!resolvedBaseUrl && resourceName) resolvedBaseUrl = `https://${resourceName}.openai.azure.com/openai/v1`;
|
|
165
|
+
if (!resolvedBaseUrl && model.baseUrl) resolvedBaseUrl = model.baseUrl;
|
|
166
|
+
if (!resolvedBaseUrl) throw new ConfigurationError("Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.");
|
|
167
|
+
return {
|
|
168
|
+
baseUrl: resolvedBaseUrl.replace(/\/+$/, ""),
|
|
169
|
+
apiVersion
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function modelForAzureEndpoint(model, baseUrl) {
|
|
173
|
+
if (model.supportsComputerUseConfig !== void 0 || model.supportsComputerUse !== true) return model;
|
|
174
|
+
try {
|
|
175
|
+
const url = new URL(baseUrl);
|
|
176
|
+
if (url.protocol === "https:" && (url.hostname.endsWith(".openai.azure.com") || url.hostname === "models.inference.ai.azure.com")) return model;
|
|
177
|
+
} catch {}
|
|
178
|
+
return {
|
|
179
|
+
...model,
|
|
180
|
+
supportsComputerUse: false
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Replicates the `AzureOpenAI` SDK client's request shape for `/responses`:
|
|
185
|
+
* a string api key becomes a single `api-key` header (azure.mjs `authHeaders`;
|
|
186
|
+
* never `Authorization: Bearer`), `api-version` rides as a query parameter
|
|
187
|
+
* (azure.mjs constructor `defaultQuery`), and `/responses` is not a
|
|
188
|
+
* deployment-scoped path, so no `/deployments/{model}` URL rewriting applies.
|
|
189
|
+
* Custom model/options headers may override the auth header, matching the SDK's
|
|
190
|
+
* `buildHeaders` precedence.
|
|
191
|
+
*/
|
|
192
|
+
function buildAzureResponsesRequest(model, apiKey, options) {
|
|
193
|
+
if (!apiKey) {
|
|
194
|
+
const envKey = $env.AZURE_OPENAI_API_KEY;
|
|
195
|
+
if (!envKey) throw new MissingApiKeyError(void 0, "Azure OpenAI API key is required. Set AZURE_OPENAI_API_KEY environment variable or pass it as an argument.");
|
|
196
|
+
apiKey = envKey;
|
|
197
|
+
}
|
|
198
|
+
const headers = {
|
|
199
|
+
"api-key": apiKey,
|
|
200
|
+
...model.headers ?? {}
|
|
201
|
+
};
|
|
202
|
+
if (options?.headers) Object.assign(headers, options.headers);
|
|
203
|
+
const { baseUrl, apiVersion } = resolveAzureConfig(model, options);
|
|
204
|
+
return {
|
|
205
|
+
url: `${baseUrl}/responses?api-version=${encodeURIComponent(apiVersion)}`,
|
|
206
|
+
headers,
|
|
207
|
+
baseUrl
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function buildParams(model, context, options, deploymentName) {
|
|
211
|
+
const systemRole = model.reasoning && model.compat.supportsDeveloperRole ? "developer" : "system";
|
|
212
|
+
const params = {
|
|
213
|
+
model: deploymentName,
|
|
214
|
+
input: buildResponsesInput({
|
|
215
|
+
model,
|
|
216
|
+
context,
|
|
217
|
+
strictResponsesPairing: true,
|
|
218
|
+
supportsImageDetailOriginal: model.compat.supportsImageDetailOriginal,
|
|
219
|
+
systemRole,
|
|
220
|
+
nativeHistory: {
|
|
221
|
+
replay: true,
|
|
222
|
+
filterReasoning: false
|
|
223
|
+
},
|
|
224
|
+
includeThinkingSignatures: true,
|
|
225
|
+
developerStringContent: true,
|
|
226
|
+
preserveAssistantMessageIds: true
|
|
227
|
+
}),
|
|
228
|
+
stream: true,
|
|
229
|
+
prompt_cache_key: getOpenAIPromptCacheKey(options),
|
|
230
|
+
store: false
|
|
231
|
+
};
|
|
232
|
+
applyCommonResponsesSamplingParams(params, options, model);
|
|
233
|
+
if (options?.include?.length) params.include = Array.from(new Set(options.include));
|
|
234
|
+
if (context.tools) {
|
|
235
|
+
const serializedTools = [];
|
|
236
|
+
for (const tool of context.tools) {
|
|
237
|
+
if (tool.native?.type === "computer") {
|
|
238
|
+
if (model.supportsComputerUse === true) {
|
|
239
|
+
serializedTools.push({ type: "computer" });
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
} else if (tool.native !== void 0) continue;
|
|
243
|
+
serializedTools.push({
|
|
244
|
+
type: "function",
|
|
245
|
+
name: tool.name,
|
|
246
|
+
description: tool.description || "",
|
|
247
|
+
parameters: sanitizeSchemaForOpenAIResponses(toolWireSchema(tool)),
|
|
248
|
+
strict: false
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
if (serializedTools.length > 0) {
|
|
252
|
+
params.tools = serializedTools;
|
|
253
|
+
if (options?.toolChoice) {
|
|
254
|
+
let toolChoice = mapToOpenAIResponsesToolChoice(options.toolChoice);
|
|
255
|
+
const hasComputerTool = serializedTools.some((tool) => tool.type === "computer");
|
|
256
|
+
if (toolChoice && typeof toolChoice !== "string" && toolChoice.type === "computer" && !hasComputerTool) {
|
|
257
|
+
const computer = context.tools.find((tool) => tool.native?.type === "computer");
|
|
258
|
+
if (computer && serializedTools.some((tool) => tool.type === "function" && tool.name === computer.name)) toolChoice = {
|
|
259
|
+
type: "function",
|
|
260
|
+
name: computer.name
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
if (toolChoice && typeof toolChoice !== "string" && toolChoice.type === "function" && hasComputerTool) {
|
|
264
|
+
if (context.tools.find((tool) => tool.native?.type === "computer")?.name === toolChoice.name) toolChoice = { type: "computer" };
|
|
265
|
+
}
|
|
266
|
+
if (toolChoice && (typeof toolChoice === "string" || toolChoice.type === "computer" && hasComputerTool || toolChoice.type === "function" && serializedTools.some((tool) => tool.type === "function" && tool.name === toolChoice.name))) params.tool_choice = toolChoice;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
applyResponsesReasoningParams(params, model, options);
|
|
271
|
+
return params;
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
export { azure_openai_responses_exports as t };
|