@goah/cli 0.13.0 → 0.13.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/dist/LICENSE +201 -0
- package/dist/THIRD-PARTY-NOTICES.md +2319 -0
- package/dist/anthropic-messages-WBFOHES5.js +7214 -0
- package/dist/azure-openai-responses-NZFH3PO6.js +253 -0
- package/dist/chunk-25XSBFX6.js +639 -0
- package/dist/chunk-2QBQZGXF.js +110 -0
- package/dist/chunk-2ZP2NBW3.js +345 -0
- package/dist/chunk-4KA63VNZ.js +2 -0
- package/dist/chunk-4M6TXTT5.js +86 -0
- package/dist/chunk-4US7ZHT3.js +20 -0
- package/dist/chunk-6M3OOCKO.js +11809 -0
- package/dist/chunk-7AXAFDPG.js +17 -0
- package/dist/chunk-BXA47DTF.js +548 -0
- package/dist/chunk-FSBUS2BI.js +26 -0
- package/dist/chunk-GKDRAHLI.js +4787 -0
- package/dist/chunk-H462EFJP.js +89 -0
- package/dist/chunk-IIJQ3DW4.js +35 -0
- package/dist/chunk-JQD5EWJY.js +34 -0
- package/dist/chunk-K26BVR6O.js +61 -0
- package/dist/chunk-KAO7WIXG.js +31 -0
- package/dist/chunk-LBKI23CC.js +9810 -0
- package/dist/chunk-LKBKZEHT.js +41 -0
- package/dist/chunk-MD7TLTXZ.js +18 -0
- package/dist/chunk-MPXK7QBL.js +868 -0
- package/dist/chunk-NRLGWZJC.js +11 -0
- package/dist/chunk-PFEV3HWI.js +1178 -0
- package/dist/chunk-QBD6EJ2Z.js +1746 -0
- package/dist/chunk-R6I3VKME.js +132 -0
- package/dist/chunk-TJON22J4.js +87 -0
- package/dist/chunk-ULY36ME4.js +33097 -0
- package/dist/chunk-VWEV4LTH.js +25 -0
- package/dist/chunk-X7UWW2PN.js +883 -0
- package/dist/chunk-XALZLRYK.js +9221 -0
- package/dist/chunk-XPQKM3L7.js +57 -0
- package/dist/chunk-YH6YJ2IB.js +1773 -0
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +13123 -580
- package/dist/console/assets/{index-Rtc_B7cs.js → index-B1vGMXKr.js} +11 -11
- package/dist/console/assets/{index-Rtc_B7cs.js.map → index-B1vGMXKr.js.map} +1 -1
- package/dist/console/index.html +1 -1
- package/dist/dist-65MDQA4Q.js +1126 -0
- package/dist/dist-KNR2XL6J.js +39 -0
- package/dist/execution.d.ts +557 -2
- package/dist/execution.js +37 -2
- package/dist/faux-runner-worker.js +128 -0
- package/dist/google-generative-ai-YMHXZSFE.js +422 -0
- package/dist/google-vertex-X6DB3ZQ6.js +471 -0
- package/dist/index.d.ts +853 -25
- package/dist/index.js +84 -385
- package/dist/kernel.d.ts +39 -2
- package/dist/kernel.js +21 -2
- package/dist/mistral-conversations-TY3MMD6G.js +718 -0
- package/dist/multipart-parser-F6M4NJZU.js +373 -0
- package/dist/openai-codex-responses-BRDUMLN5.js +1374 -0
- package/dist/openai-completions-CX634XN3.js +1139 -0
- package/dist/openai-responses-HMCXJIHT.js +300 -0
- package/dist/openrouter-images-KTWET2H2.js +148 -0
- package/dist/pi-messages-XL5OEC4K.js +307 -0
- package/dist/pi-worker.js +671 -0
- package/dist/runner-pi.d.ts +342 -2
- package/dist/runner-pi.js +46 -2
- package/dist/runner-registry-M776E3SE.js +22 -0
- package/dist/sqlite.d.ts +446 -2
- package/dist/sqlite.js +15 -2
- package/dist/src-F2KBSV4T.js +1398 -0
- package/dist/supervisor.d.ts +625 -2
- package/dist/supervisor.js +39 -2
- package/dist/testkit.d.ts +564 -2
- package/dist/testkit.js +127 -2
- package/dist/transcript.d.ts +84 -2
- package/dist/transcript.js +25 -2
- package/dist/verification-worker.js +72 -0
- package/package.json +2 -26
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/control.d.ts +0 -106
- package/dist/control.d.ts.map +0 -1
- package/dist/control.js +0 -242
- package/dist/control.js.map +0 -1
- package/dist/execution.d.ts.map +0 -1
- package/dist/execution.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/kernel.d.ts.map +0 -1
- package/dist/kernel.js.map +0 -1
- package/dist/live-config.d.ts +0 -10
- package/dist/live-config.d.ts.map +0 -1
- package/dist/live-config.js +0 -44
- package/dist/live-config.js.map +0 -1
- package/dist/prompt-queue.d.ts +0 -13
- package/dist/prompt-queue.d.ts.map +0 -1
- package/dist/prompt-queue.js +0 -35
- package/dist/prompt-queue.js.map +0 -1
- package/dist/runner-pi.d.ts.map +0 -1
- package/dist/runner-pi.js.map +0 -1
- package/dist/runner-registry.d.ts +0 -8
- package/dist/runner-registry.d.ts.map +0 -1
- package/dist/runner-registry.js +0 -12
- package/dist/runner-registry.js.map +0 -1
- package/dist/searchable-select.d.ts +0 -24
- package/dist/searchable-select.d.ts.map +0 -1
- package/dist/searchable-select.js +0 -61
- package/dist/searchable-select.js.map +0 -1
- package/dist/secret-input.d.ts +0 -8
- package/dist/secret-input.d.ts.map +0 -1
- package/dist/secret-input.js +0 -14
- package/dist/secret-input.js.map +0 -1
- package/dist/setup-wizard.d.ts +0 -22
- package/dist/setup-wizard.d.ts.map +0 -1
- package/dist/setup-wizard.js +0 -154
- package/dist/setup-wizard.js.map +0 -1
- package/dist/sqlite.d.ts.map +0 -1
- package/dist/sqlite.js.map +0 -1
- package/dist/supervisor.d.ts.map +0 -1
- package/dist/supervisor.js.map +0 -1
- package/dist/testkit.d.ts.map +0 -1
- package/dist/testkit.js.map +0 -1
- package/dist/thread-inspect.d.ts +0 -47
- package/dist/thread-inspect.d.ts.map +0 -1
- package/dist/thread-inspect.js +0 -78
- package/dist/thread-inspect.js.map +0 -1
- package/dist/transcript.d.ts.map +0 -1
- package/dist/transcript.js.map +0 -1
- package/dist/tui-theme.d.ts +0 -17
- package/dist/tui-theme.d.ts.map +0 -1
- package/dist/tui-theme.js +0 -19
- package/dist/tui-theme.js.map +0 -1
- package/dist/tui.d.ts +0 -24
- package/dist/tui.d.ts.map +0 -1
- package/dist/tui.js +0 -784
- package/dist/tui.js.map +0 -1
- package/dist/update.d.ts +0 -16
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js +0 -67
- package/dist/update.js.map +0 -1
- package/dist/web-console.d.ts +0 -33
- package/dist/web-console.d.ts.map +0 -1
- package/dist/web-console.js +0 -242
- package/dist/web-console.js.map +0 -1
- package/dist/welcome.d.ts +0 -30
- package/dist/welcome.d.ts.map +0 -1
- package/dist/welcome.js +0 -69
- package/dist/welcome.js.map +0 -1
- package/node_modules/goah-ledger-contract/dist/execution.d.ts +0 -544
- package/node_modules/goah-ledger-contract/dist/execution.d.ts.map +0 -1
- package/node_modules/goah-ledger-contract/dist/execution.js +0 -52
- package/node_modules/goah-ledger-contract/dist/execution.js.map +0 -1
- package/node_modules/goah-ledger-contract/dist/index.d.ts +0 -4
- package/node_modules/goah-ledger-contract/dist/index.d.ts.map +0 -1
- package/node_modules/goah-ledger-contract/dist/index.js +0 -4
- package/node_modules/goah-ledger-contract/dist/index.js.map +0 -1
- package/node_modules/goah-ledger-contract/dist/kernel.d.ts +0 -37
- package/node_modules/goah-ledger-contract/dist/kernel.d.ts.map +0 -1
- package/node_modules/goah-ledger-contract/dist/kernel.js +0 -8
- package/node_modules/goah-ledger-contract/dist/kernel.js.map +0 -1
- package/node_modules/goah-ledger-contract/dist/transcript.d.ts +0 -63
- package/node_modules/goah-ledger-contract/dist/transcript.d.ts.map +0 -1
- package/node_modules/goah-ledger-contract/dist/transcript.js +0 -115
- package/node_modules/goah-ledger-contract/dist/transcript.js.map +0 -1
- package/node_modules/goah-ledger-contract/package.json +0 -28
- package/node_modules/goah-ledger-sqlite/dist/index.d.ts +0 -86
- package/node_modules/goah-ledger-sqlite/dist/index.d.ts.map +0 -1
- package/node_modules/goah-ledger-sqlite/dist/index.js +0 -1254
- package/node_modules/goah-ledger-sqlite/dist/index.js.map +0 -1
- package/node_modules/goah-ledger-sqlite/package.json +0 -26
- package/node_modules/goah-runner-pi/dist/configurator.d.ts +0 -20
- package/node_modules/goah-runner-pi/dist/configurator.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/configurator.js +0 -423
- package/node_modules/goah-runner-pi/dist/configurator.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/credential-store.d.ts +0 -14
- package/node_modules/goah-runner-pi/dist/credential-store.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/credential-store.js +0 -163
- package/node_modules/goah-runner-pi/dist/credential-store.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/env-spec.d.ts +0 -17
- package/node_modules/goah-runner-pi/dist/env-spec.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/env-spec.js +0 -95
- package/node_modules/goah-runner-pi/dist/env-spec.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/index.d.ts +0 -76
- package/node_modules/goah-runner-pi/dist/index.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/index.js +0 -326
- package/node_modules/goah-runner-pi/dist/index.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/model-provider.d.ts +0 -30
- package/node_modules/goah-runner-pi/dist/model-provider.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/model-provider.js +0 -96
- package/node_modules/goah-runner-pi/dist/model-provider.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/pi-worker.d.ts +0 -31
- package/node_modules/goah-runner-pi/dist/pi-worker.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/pi-worker.js +0 -579
- package/node_modules/goah-runner-pi/dist/pi-worker.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.d.ts +0 -2
- package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.js +0 -3
- package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.d.ts +0 -2
- package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.js +0 -5
- package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.d.ts +0 -2
- package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.js +0 -5
- package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/test-helpers.d.ts +0 -4
- package/node_modules/goah-runner-pi/dist/test-helpers.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/test-helpers.js +0 -13
- package/node_modules/goah-runner-pi/dist/test-helpers.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/verification-worker.d.ts +0 -2
- package/node_modules/goah-runner-pi/dist/verification-worker.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/verification-worker.js +0 -46
- package/node_modules/goah-runner-pi/dist/verification-worker.js.map +0 -1
- package/node_modules/goah-runner-pi/package.json +0 -28
- package/node_modules/goah-supervisor/dist/context-view.d.ts +0 -30
- package/node_modules/goah-supervisor/dist/context-view.d.ts.map +0 -1
- package/node_modules/goah-supervisor/dist/context-view.js +0 -58
- package/node_modules/goah-supervisor/dist/context-view.js.map +0 -1
- package/node_modules/goah-supervisor/dist/index.d.ts +0 -96
- package/node_modules/goah-supervisor/dist/index.d.ts.map +0 -1
- package/node_modules/goah-supervisor/dist/index.js +0 -1075
- package/node_modules/goah-supervisor/dist/index.js.map +0 -1
- package/node_modules/goah-supervisor/dist/roles.d.ts +0 -4
- package/node_modules/goah-supervisor/dist/roles.d.ts.map +0 -1
- package/node_modules/goah-supervisor/dist/roles.js +0 -29
- package/node_modules/goah-supervisor/dist/roles.js.map +0 -1
- package/node_modules/goah-supervisor/dist/verification.d.ts +0 -61
- package/node_modules/goah-supervisor/dist/verification.d.ts.map +0 -1
- package/node_modules/goah-supervisor/dist/verification.js +0 -135
- package/node_modules/goah-supervisor/dist/verification.js.map +0 -1
- package/node_modules/goah-supervisor/package.json +0 -26
- package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts +0 -2
- package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts.map +0 -1
- package/node_modules/goah-testkit/dist/faux-runner-worker.js +0 -82
- package/node_modules/goah-testkit/dist/faux-runner-worker.js.map +0 -1
- package/node_modules/goah-testkit/dist/index.d.ts +0 -49
- package/node_modules/goah-testkit/dist/index.d.ts.map +0 -1
- package/node_modules/goah-testkit/dist/index.js +0 -96
- package/node_modules/goah-testkit/dist/index.js.map +0 -1
- package/node_modules/goah-testkit/package.json +0 -29
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { createRequire as __goahCreateRequire } from "node:module";
|
|
2
|
+
const require = __goahCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
convertResponsesMessages,
|
|
5
|
+
convertResponsesTools,
|
|
6
|
+
processResponsesStream
|
|
7
|
+
} from "./chunk-25XSBFX6.js";
|
|
8
|
+
import {
|
|
9
|
+
clampOpenAIPromptCacheKey
|
|
10
|
+
} from "./chunk-7AXAFDPG.js";
|
|
11
|
+
import "./chunk-4US7ZHT3.js";
|
|
12
|
+
import {
|
|
13
|
+
AzureOpenAI
|
|
14
|
+
} from "./chunk-LBKI23CC.js";
|
|
15
|
+
import {
|
|
16
|
+
formatProviderError,
|
|
17
|
+
normalizeProviderError
|
|
18
|
+
} from "./chunk-H462EFJP.js";
|
|
19
|
+
import {
|
|
20
|
+
buildBaseOptions,
|
|
21
|
+
createGrammarToolInputProperties
|
|
22
|
+
} from "./chunk-BXA47DTF.js";
|
|
23
|
+
import {
|
|
24
|
+
retryProviderRequest
|
|
25
|
+
} from "./chunk-4M6TXTT5.js";
|
|
26
|
+
import "./chunk-NRLGWZJC.js";
|
|
27
|
+
import {
|
|
28
|
+
headersToRecord
|
|
29
|
+
} from "./chunk-FSBUS2BI.js";
|
|
30
|
+
import {
|
|
31
|
+
getProviderEnvValue
|
|
32
|
+
} from "./chunk-IIJQ3DW4.js";
|
|
33
|
+
import "./chunk-2ZP2NBW3.js";
|
|
34
|
+
import {
|
|
35
|
+
clampThinkingLevel
|
|
36
|
+
} from "./chunk-MPXK7QBL.js";
|
|
37
|
+
import {
|
|
38
|
+
AssistantMessageEventStream
|
|
39
|
+
} from "./chunk-2QBQZGXF.js";
|
|
40
|
+
import "./chunk-XPQKM3L7.js";
|
|
41
|
+
|
|
42
|
+
// ../../node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js
|
|
43
|
+
var DEFAULT_AZURE_API_VERSION = "v1";
|
|
44
|
+
var AZURE_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "openai-codex", "opencode", "azure-openai-responses"]);
|
|
45
|
+
var OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;
|
|
46
|
+
function parseDeploymentNameMap(value) {
|
|
47
|
+
const map = /* @__PURE__ */ new Map();
|
|
48
|
+
if (!value)
|
|
49
|
+
return map;
|
|
50
|
+
for (const entry of value.split(",")) {
|
|
51
|
+
const trimmed = entry.trim();
|
|
52
|
+
if (!trimmed)
|
|
53
|
+
continue;
|
|
54
|
+
const [modelId, deploymentName] = trimmed.split("=", 2);
|
|
55
|
+
if (!modelId || !deploymentName)
|
|
56
|
+
continue;
|
|
57
|
+
map.set(modelId.trim(), deploymentName.trim());
|
|
58
|
+
}
|
|
59
|
+
return map;
|
|
60
|
+
}
|
|
61
|
+
function resolveDeploymentName(model, options) {
|
|
62
|
+
if (options?.azureDeploymentName) {
|
|
63
|
+
return options.azureDeploymentName;
|
|
64
|
+
}
|
|
65
|
+
const mappedDeployment = parseDeploymentNameMap(getProviderEnvValue("AZURE_OPENAI_DEPLOYMENT_NAME_MAP", options?.env)).get(model.id);
|
|
66
|
+
return mappedDeployment || model.id;
|
|
67
|
+
}
|
|
68
|
+
function formatAzureOpenAIError(error) {
|
|
69
|
+
return formatProviderError(normalizeProviderError(error), "Azure OpenAI API error");
|
|
70
|
+
}
|
|
71
|
+
var stream = (model, context, options) => {
|
|
72
|
+
const stream2 = new AssistantMessageEventStream();
|
|
73
|
+
(async () => {
|
|
74
|
+
const deploymentName = resolveDeploymentName(model, options);
|
|
75
|
+
const output = {
|
|
76
|
+
role: "assistant",
|
|
77
|
+
content: [],
|
|
78
|
+
api: "azure-openai-responses",
|
|
79
|
+
provider: model.provider,
|
|
80
|
+
model: model.id,
|
|
81
|
+
usage: {
|
|
82
|
+
input: 0,
|
|
83
|
+
output: 0,
|
|
84
|
+
cacheRead: 0,
|
|
85
|
+
cacheWrite: 0,
|
|
86
|
+
totalTokens: 0,
|
|
87
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
|
|
88
|
+
},
|
|
89
|
+
stopReason: "pending",
|
|
90
|
+
timestamp: Date.now()
|
|
91
|
+
};
|
|
92
|
+
try {
|
|
93
|
+
const apiKey = options?.apiKey;
|
|
94
|
+
if (!apiKey) {
|
|
95
|
+
throw new Error(`No API key for provider: ${model.provider}`);
|
|
96
|
+
}
|
|
97
|
+
const client = createClient(model, apiKey, options);
|
|
98
|
+
const grammarToolInputProperties = createGrammarToolInputProperties(context.tools, model.compat?.supportsOpenAIGrammarTools ?? false);
|
|
99
|
+
let params = buildParams(model, context, options, deploymentName, grammarToolInputProperties);
|
|
100
|
+
const nextParams = await options?.onPayload?.(params, model);
|
|
101
|
+
if (nextParams !== void 0) {
|
|
102
|
+
params = nextParams;
|
|
103
|
+
}
|
|
104
|
+
const requestOptions = {
|
|
105
|
+
...options?.signal ? { signal: options.signal } : {},
|
|
106
|
+
...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
|
|
107
|
+
maxRetries: 0
|
|
108
|
+
};
|
|
109
|
+
const { data: openaiStream, response } = await retryProviderRequest(() => client.responses.create(params, requestOptions).withResponse(), {
|
|
110
|
+
maxRetries: options?.maxRetries,
|
|
111
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
112
|
+
signal: options?.signal
|
|
113
|
+
});
|
|
114
|
+
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
|
|
115
|
+
stream2.push({ type: "start", partial: output });
|
|
116
|
+
await processResponsesStream(openaiStream, output, stream2, model, { grammarToolInputProperties });
|
|
117
|
+
if (options?.signal?.aborted) {
|
|
118
|
+
throw new Error("Request was aborted");
|
|
119
|
+
}
|
|
120
|
+
if (output.stopReason === "pending") {
|
|
121
|
+
throw new Error("Azure OpenAI Responses stream ended without a stop reason");
|
|
122
|
+
}
|
|
123
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") {
|
|
124
|
+
throw new Error(output.errorMessage || "An unknown error occurred");
|
|
125
|
+
}
|
|
126
|
+
stream2.push({ type: "done", reason: output.stopReason, message: output });
|
|
127
|
+
stream2.end();
|
|
128
|
+
} catch (error) {
|
|
129
|
+
for (const block of output.content) {
|
|
130
|
+
delete block.index;
|
|
131
|
+
delete block.partialJson;
|
|
132
|
+
delete block.customInput;
|
|
133
|
+
}
|
|
134
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
135
|
+
output.errorMessage = formatAzureOpenAIError(error);
|
|
136
|
+
stream2.push({ type: "error", reason: output.stopReason, error: output });
|
|
137
|
+
stream2.end();
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
return stream2;
|
|
141
|
+
};
|
|
142
|
+
var streamSimple = (model, context, options) => {
|
|
143
|
+
const apiKey = options?.apiKey;
|
|
144
|
+
if (!apiKey) {
|
|
145
|
+
throw new Error(`No API key for provider: ${model.provider}`);
|
|
146
|
+
}
|
|
147
|
+
const base = buildBaseOptions(model, context, options, apiKey);
|
|
148
|
+
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
|
|
149
|
+
const reasoningEffort = clampedReasoning === "off" ? void 0 : clampedReasoning;
|
|
150
|
+
return stream(model, context, {
|
|
151
|
+
...base,
|
|
152
|
+
reasoningEffort
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
function normalizeAzureBaseUrl(baseUrl) {
|
|
156
|
+
const trimmed = baseUrl.trim().replace(/\/+$/, "");
|
|
157
|
+
let url;
|
|
158
|
+
try {
|
|
159
|
+
url = new URL(trimmed);
|
|
160
|
+
} catch {
|
|
161
|
+
throw new Error(`Invalid Azure OpenAI base URL: ${baseUrl}`);
|
|
162
|
+
}
|
|
163
|
+
const isAzureHost = url.hostname.endsWith(".openai.azure.com") || url.hostname.endsWith(".cognitiveservices.azure.com") || url.hostname.endsWith(".ai.azure.com");
|
|
164
|
+
const normalizedPath = url.pathname.replace(/\/+$/, "");
|
|
165
|
+
if (isAzureHost && (normalizedPath === "" || normalizedPath === "/" || normalizedPath === "/openai" || normalizedPath === "/openai/v1/responses")) {
|
|
166
|
+
url.pathname = "/openai/v1";
|
|
167
|
+
url.search = "";
|
|
168
|
+
}
|
|
169
|
+
return url.toString().replace(/\/+$/, "");
|
|
170
|
+
}
|
|
171
|
+
function buildDefaultBaseUrl(resourceName) {
|
|
172
|
+
return `https://${resourceName}.openai.azure.com/openai/v1`;
|
|
173
|
+
}
|
|
174
|
+
function resolveAzureConfig(model, options) {
|
|
175
|
+
const apiVersion = options?.azureApiVersion || getProviderEnvValue("AZURE_OPENAI_API_VERSION", options?.env) || DEFAULT_AZURE_API_VERSION;
|
|
176
|
+
const baseUrl = options?.azureBaseUrl?.trim() || getProviderEnvValue("AZURE_OPENAI_BASE_URL", options?.env)?.trim() || void 0;
|
|
177
|
+
const resourceName = options?.azureResourceName || getProviderEnvValue("AZURE_OPENAI_RESOURCE_NAME", options?.env);
|
|
178
|
+
let resolvedBaseUrl = baseUrl;
|
|
179
|
+
if (!resolvedBaseUrl && resourceName) {
|
|
180
|
+
resolvedBaseUrl = buildDefaultBaseUrl(resourceName);
|
|
181
|
+
}
|
|
182
|
+
if (!resolvedBaseUrl && model.baseUrl) {
|
|
183
|
+
resolvedBaseUrl = model.baseUrl;
|
|
184
|
+
}
|
|
185
|
+
if (!resolvedBaseUrl) {
|
|
186
|
+
throw new Error("Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.");
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
baseUrl: normalizeAzureBaseUrl(resolvedBaseUrl),
|
|
190
|
+
apiVersion
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function createClient(model, apiKey, options) {
|
|
194
|
+
const headers = { ...model.headers };
|
|
195
|
+
if (options?.headers) {
|
|
196
|
+
Object.assign(headers, options.headers);
|
|
197
|
+
}
|
|
198
|
+
const { baseUrl, apiVersion } = resolveAzureConfig(model, options);
|
|
199
|
+
return new AzureOpenAI({
|
|
200
|
+
apiKey,
|
|
201
|
+
apiVersion,
|
|
202
|
+
dangerouslyAllowBrowser: true,
|
|
203
|
+
fetch: options?.fetch,
|
|
204
|
+
defaultHeaders: headers,
|
|
205
|
+
baseURL: baseUrl
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function buildParams(model, context, options, deploymentName, grammarToolInputProperties = createGrammarToolInputProperties(context.tools, model.compat?.supportsOpenAIGrammarTools ?? false)) {
|
|
209
|
+
const messages = convertResponsesMessages(model, context, AZURE_TOOL_CALL_PROVIDERS, {
|
|
210
|
+
grammarToolInputProperties
|
|
211
|
+
});
|
|
212
|
+
const params = {
|
|
213
|
+
model: deploymentName,
|
|
214
|
+
input: messages,
|
|
215
|
+
stream: true,
|
|
216
|
+
prompt_cache_key: clampOpenAIPromptCacheKey(options?.sessionId),
|
|
217
|
+
store: false
|
|
218
|
+
};
|
|
219
|
+
if (options?.maxTokens) {
|
|
220
|
+
params.max_output_tokens = Math.max(options.maxTokens, OPENAI_RESPONSES_MIN_OUTPUT_TOKENS);
|
|
221
|
+
}
|
|
222
|
+
if (options?.temperature !== void 0) {
|
|
223
|
+
params.temperature = options?.temperature;
|
|
224
|
+
}
|
|
225
|
+
if (context.tools && context.tools.length > 0) {
|
|
226
|
+
params.tools = convertResponsesTools(context.tools, {
|
|
227
|
+
supportsStrictMode: model.compat?.supportsStrictMode ?? true,
|
|
228
|
+
supportsOpenAIGrammarTools: model.compat?.supportsOpenAIGrammarTools ?? false
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
if (model.reasoning) {
|
|
232
|
+
if (options?.reasoningEffort || options?.reasoningSummary) {
|
|
233
|
+
const effort = options?.reasoningEffort ? model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort : "medium";
|
|
234
|
+
params.reasoning = {
|
|
235
|
+
effort,
|
|
236
|
+
summary: options?.reasoningSummary || "auto"
|
|
237
|
+
};
|
|
238
|
+
params.include = ["reasoning.encrypted_content"];
|
|
239
|
+
} else if (model.thinkingLevelMap?.off !== null) {
|
|
240
|
+
params.reasoning = {
|
|
241
|
+
effort: model.thinkingLevelMap?.off ?? "none"
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (options?.samplingParams) {
|
|
246
|
+
Object.assign(params, options.samplingParams);
|
|
247
|
+
}
|
|
248
|
+
return params;
|
|
249
|
+
}
|
|
250
|
+
export {
|
|
251
|
+
stream,
|
|
252
|
+
streamSimple
|
|
253
|
+
};
|