@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.
Files changed (236) hide show
  1. package/dist/LICENSE +201 -0
  2. package/dist/THIRD-PARTY-NOTICES.md +2319 -0
  3. package/dist/anthropic-messages-WBFOHES5.js +7214 -0
  4. package/dist/azure-openai-responses-NZFH3PO6.js +253 -0
  5. package/dist/chunk-25XSBFX6.js +639 -0
  6. package/dist/chunk-2QBQZGXF.js +110 -0
  7. package/dist/chunk-2ZP2NBW3.js +345 -0
  8. package/dist/chunk-4KA63VNZ.js +2 -0
  9. package/dist/chunk-4M6TXTT5.js +86 -0
  10. package/dist/chunk-4US7ZHT3.js +20 -0
  11. package/dist/chunk-6M3OOCKO.js +11809 -0
  12. package/dist/chunk-7AXAFDPG.js +17 -0
  13. package/dist/chunk-BXA47DTF.js +548 -0
  14. package/dist/chunk-FSBUS2BI.js +26 -0
  15. package/dist/chunk-GKDRAHLI.js +4787 -0
  16. package/dist/chunk-H462EFJP.js +89 -0
  17. package/dist/chunk-IIJQ3DW4.js +35 -0
  18. package/dist/chunk-JQD5EWJY.js +34 -0
  19. package/dist/chunk-K26BVR6O.js +61 -0
  20. package/dist/chunk-KAO7WIXG.js +31 -0
  21. package/dist/chunk-LBKI23CC.js +9810 -0
  22. package/dist/chunk-LKBKZEHT.js +41 -0
  23. package/dist/chunk-MD7TLTXZ.js +18 -0
  24. package/dist/chunk-MPXK7QBL.js +868 -0
  25. package/dist/chunk-NRLGWZJC.js +11 -0
  26. package/dist/chunk-PFEV3HWI.js +1178 -0
  27. package/dist/chunk-QBD6EJ2Z.js +1746 -0
  28. package/dist/chunk-R6I3VKME.js +132 -0
  29. package/dist/chunk-TJON22J4.js +87 -0
  30. package/dist/chunk-ULY36ME4.js +33097 -0
  31. package/dist/chunk-VWEV4LTH.js +25 -0
  32. package/dist/chunk-X7UWW2PN.js +883 -0
  33. package/dist/chunk-XALZLRYK.js +9221 -0
  34. package/dist/chunk-XPQKM3L7.js +57 -0
  35. package/dist/chunk-YH6YJ2IB.js +1773 -0
  36. package/dist/cli.d.ts +0 -2
  37. package/dist/cli.js +13123 -580
  38. package/dist/console/assets/{index-Rtc_B7cs.js → index-B1vGMXKr.js} +11 -11
  39. package/dist/console/assets/{index-Rtc_B7cs.js.map → index-B1vGMXKr.js.map} +1 -1
  40. package/dist/console/index.html +1 -1
  41. package/dist/dist-65MDQA4Q.js +1126 -0
  42. package/dist/dist-KNR2XL6J.js +39 -0
  43. package/dist/execution.d.ts +557 -2
  44. package/dist/execution.js +37 -2
  45. package/dist/faux-runner-worker.js +128 -0
  46. package/dist/google-generative-ai-YMHXZSFE.js +422 -0
  47. package/dist/google-vertex-X6DB3ZQ6.js +471 -0
  48. package/dist/index.d.ts +853 -25
  49. package/dist/index.js +84 -385
  50. package/dist/kernel.d.ts +39 -2
  51. package/dist/kernel.js +21 -2
  52. package/dist/mistral-conversations-TY3MMD6G.js +718 -0
  53. package/dist/multipart-parser-F6M4NJZU.js +373 -0
  54. package/dist/openai-codex-responses-BRDUMLN5.js +1374 -0
  55. package/dist/openai-completions-CX634XN3.js +1139 -0
  56. package/dist/openai-responses-HMCXJIHT.js +300 -0
  57. package/dist/openrouter-images-KTWET2H2.js +148 -0
  58. package/dist/pi-messages-XL5OEC4K.js +307 -0
  59. package/dist/pi-worker.js +671 -0
  60. package/dist/runner-pi.d.ts +342 -2
  61. package/dist/runner-pi.js +46 -2
  62. package/dist/runner-registry-M776E3SE.js +22 -0
  63. package/dist/sqlite.d.ts +446 -2
  64. package/dist/sqlite.js +15 -2
  65. package/dist/src-F2KBSV4T.js +1398 -0
  66. package/dist/supervisor.d.ts +625 -2
  67. package/dist/supervisor.js +39 -2
  68. package/dist/testkit.d.ts +564 -2
  69. package/dist/testkit.js +127 -2
  70. package/dist/transcript.d.ts +84 -2
  71. package/dist/transcript.js +25 -2
  72. package/dist/verification-worker.js +72 -0
  73. package/package.json +2 -26
  74. package/dist/cli.d.ts.map +0 -1
  75. package/dist/cli.js.map +0 -1
  76. package/dist/control.d.ts +0 -106
  77. package/dist/control.d.ts.map +0 -1
  78. package/dist/control.js +0 -242
  79. package/dist/control.js.map +0 -1
  80. package/dist/execution.d.ts.map +0 -1
  81. package/dist/execution.js.map +0 -1
  82. package/dist/index.d.ts.map +0 -1
  83. package/dist/index.js.map +0 -1
  84. package/dist/kernel.d.ts.map +0 -1
  85. package/dist/kernel.js.map +0 -1
  86. package/dist/live-config.d.ts +0 -10
  87. package/dist/live-config.d.ts.map +0 -1
  88. package/dist/live-config.js +0 -44
  89. package/dist/live-config.js.map +0 -1
  90. package/dist/prompt-queue.d.ts +0 -13
  91. package/dist/prompt-queue.d.ts.map +0 -1
  92. package/dist/prompt-queue.js +0 -35
  93. package/dist/prompt-queue.js.map +0 -1
  94. package/dist/runner-pi.d.ts.map +0 -1
  95. package/dist/runner-pi.js.map +0 -1
  96. package/dist/runner-registry.d.ts +0 -8
  97. package/dist/runner-registry.d.ts.map +0 -1
  98. package/dist/runner-registry.js +0 -12
  99. package/dist/runner-registry.js.map +0 -1
  100. package/dist/searchable-select.d.ts +0 -24
  101. package/dist/searchable-select.d.ts.map +0 -1
  102. package/dist/searchable-select.js +0 -61
  103. package/dist/searchable-select.js.map +0 -1
  104. package/dist/secret-input.d.ts +0 -8
  105. package/dist/secret-input.d.ts.map +0 -1
  106. package/dist/secret-input.js +0 -14
  107. package/dist/secret-input.js.map +0 -1
  108. package/dist/setup-wizard.d.ts +0 -22
  109. package/dist/setup-wizard.d.ts.map +0 -1
  110. package/dist/setup-wizard.js +0 -154
  111. package/dist/setup-wizard.js.map +0 -1
  112. package/dist/sqlite.d.ts.map +0 -1
  113. package/dist/sqlite.js.map +0 -1
  114. package/dist/supervisor.d.ts.map +0 -1
  115. package/dist/supervisor.js.map +0 -1
  116. package/dist/testkit.d.ts.map +0 -1
  117. package/dist/testkit.js.map +0 -1
  118. package/dist/thread-inspect.d.ts +0 -47
  119. package/dist/thread-inspect.d.ts.map +0 -1
  120. package/dist/thread-inspect.js +0 -78
  121. package/dist/thread-inspect.js.map +0 -1
  122. package/dist/transcript.d.ts.map +0 -1
  123. package/dist/transcript.js.map +0 -1
  124. package/dist/tui-theme.d.ts +0 -17
  125. package/dist/tui-theme.d.ts.map +0 -1
  126. package/dist/tui-theme.js +0 -19
  127. package/dist/tui-theme.js.map +0 -1
  128. package/dist/tui.d.ts +0 -24
  129. package/dist/tui.d.ts.map +0 -1
  130. package/dist/tui.js +0 -784
  131. package/dist/tui.js.map +0 -1
  132. package/dist/update.d.ts +0 -16
  133. package/dist/update.d.ts.map +0 -1
  134. package/dist/update.js +0 -67
  135. package/dist/update.js.map +0 -1
  136. package/dist/web-console.d.ts +0 -33
  137. package/dist/web-console.d.ts.map +0 -1
  138. package/dist/web-console.js +0 -242
  139. package/dist/web-console.js.map +0 -1
  140. package/dist/welcome.d.ts +0 -30
  141. package/dist/welcome.d.ts.map +0 -1
  142. package/dist/welcome.js +0 -69
  143. package/dist/welcome.js.map +0 -1
  144. package/node_modules/goah-ledger-contract/dist/execution.d.ts +0 -544
  145. package/node_modules/goah-ledger-contract/dist/execution.d.ts.map +0 -1
  146. package/node_modules/goah-ledger-contract/dist/execution.js +0 -52
  147. package/node_modules/goah-ledger-contract/dist/execution.js.map +0 -1
  148. package/node_modules/goah-ledger-contract/dist/index.d.ts +0 -4
  149. package/node_modules/goah-ledger-contract/dist/index.d.ts.map +0 -1
  150. package/node_modules/goah-ledger-contract/dist/index.js +0 -4
  151. package/node_modules/goah-ledger-contract/dist/index.js.map +0 -1
  152. package/node_modules/goah-ledger-contract/dist/kernel.d.ts +0 -37
  153. package/node_modules/goah-ledger-contract/dist/kernel.d.ts.map +0 -1
  154. package/node_modules/goah-ledger-contract/dist/kernel.js +0 -8
  155. package/node_modules/goah-ledger-contract/dist/kernel.js.map +0 -1
  156. package/node_modules/goah-ledger-contract/dist/transcript.d.ts +0 -63
  157. package/node_modules/goah-ledger-contract/dist/transcript.d.ts.map +0 -1
  158. package/node_modules/goah-ledger-contract/dist/transcript.js +0 -115
  159. package/node_modules/goah-ledger-contract/dist/transcript.js.map +0 -1
  160. package/node_modules/goah-ledger-contract/package.json +0 -28
  161. package/node_modules/goah-ledger-sqlite/dist/index.d.ts +0 -86
  162. package/node_modules/goah-ledger-sqlite/dist/index.d.ts.map +0 -1
  163. package/node_modules/goah-ledger-sqlite/dist/index.js +0 -1254
  164. package/node_modules/goah-ledger-sqlite/dist/index.js.map +0 -1
  165. package/node_modules/goah-ledger-sqlite/package.json +0 -26
  166. package/node_modules/goah-runner-pi/dist/configurator.d.ts +0 -20
  167. package/node_modules/goah-runner-pi/dist/configurator.d.ts.map +0 -1
  168. package/node_modules/goah-runner-pi/dist/configurator.js +0 -423
  169. package/node_modules/goah-runner-pi/dist/configurator.js.map +0 -1
  170. package/node_modules/goah-runner-pi/dist/credential-store.d.ts +0 -14
  171. package/node_modules/goah-runner-pi/dist/credential-store.d.ts.map +0 -1
  172. package/node_modules/goah-runner-pi/dist/credential-store.js +0 -163
  173. package/node_modules/goah-runner-pi/dist/credential-store.js.map +0 -1
  174. package/node_modules/goah-runner-pi/dist/env-spec.d.ts +0 -17
  175. package/node_modules/goah-runner-pi/dist/env-spec.d.ts.map +0 -1
  176. package/node_modules/goah-runner-pi/dist/env-spec.js +0 -95
  177. package/node_modules/goah-runner-pi/dist/env-spec.js.map +0 -1
  178. package/node_modules/goah-runner-pi/dist/index.d.ts +0 -76
  179. package/node_modules/goah-runner-pi/dist/index.d.ts.map +0 -1
  180. package/node_modules/goah-runner-pi/dist/index.js +0 -326
  181. package/node_modules/goah-runner-pi/dist/index.js.map +0 -1
  182. package/node_modules/goah-runner-pi/dist/model-provider.d.ts +0 -30
  183. package/node_modules/goah-runner-pi/dist/model-provider.d.ts.map +0 -1
  184. package/node_modules/goah-runner-pi/dist/model-provider.js +0 -96
  185. package/node_modules/goah-runner-pi/dist/model-provider.js.map +0 -1
  186. package/node_modules/goah-runner-pi/dist/pi-worker.d.ts +0 -31
  187. package/node_modules/goah-runner-pi/dist/pi-worker.d.ts.map +0 -1
  188. package/node_modules/goah-runner-pi/dist/pi-worker.js +0 -579
  189. package/node_modules/goah-runner-pi/dist/pi-worker.js.map +0 -1
  190. package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.d.ts +0 -2
  191. package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.d.ts.map +0 -1
  192. package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.js +0 -3
  193. package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.js.map +0 -1
  194. package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.d.ts +0 -2
  195. package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.d.ts.map +0 -1
  196. package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.js +0 -5
  197. package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.js.map +0 -1
  198. package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.d.ts +0 -2
  199. package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.d.ts.map +0 -1
  200. package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.js +0 -5
  201. package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.js.map +0 -1
  202. package/node_modules/goah-runner-pi/dist/test-helpers.d.ts +0 -4
  203. package/node_modules/goah-runner-pi/dist/test-helpers.d.ts.map +0 -1
  204. package/node_modules/goah-runner-pi/dist/test-helpers.js +0 -13
  205. package/node_modules/goah-runner-pi/dist/test-helpers.js.map +0 -1
  206. package/node_modules/goah-runner-pi/dist/verification-worker.d.ts +0 -2
  207. package/node_modules/goah-runner-pi/dist/verification-worker.d.ts.map +0 -1
  208. package/node_modules/goah-runner-pi/dist/verification-worker.js +0 -46
  209. package/node_modules/goah-runner-pi/dist/verification-worker.js.map +0 -1
  210. package/node_modules/goah-runner-pi/package.json +0 -28
  211. package/node_modules/goah-supervisor/dist/context-view.d.ts +0 -30
  212. package/node_modules/goah-supervisor/dist/context-view.d.ts.map +0 -1
  213. package/node_modules/goah-supervisor/dist/context-view.js +0 -58
  214. package/node_modules/goah-supervisor/dist/context-view.js.map +0 -1
  215. package/node_modules/goah-supervisor/dist/index.d.ts +0 -96
  216. package/node_modules/goah-supervisor/dist/index.d.ts.map +0 -1
  217. package/node_modules/goah-supervisor/dist/index.js +0 -1075
  218. package/node_modules/goah-supervisor/dist/index.js.map +0 -1
  219. package/node_modules/goah-supervisor/dist/roles.d.ts +0 -4
  220. package/node_modules/goah-supervisor/dist/roles.d.ts.map +0 -1
  221. package/node_modules/goah-supervisor/dist/roles.js +0 -29
  222. package/node_modules/goah-supervisor/dist/roles.js.map +0 -1
  223. package/node_modules/goah-supervisor/dist/verification.d.ts +0 -61
  224. package/node_modules/goah-supervisor/dist/verification.d.ts.map +0 -1
  225. package/node_modules/goah-supervisor/dist/verification.js +0 -135
  226. package/node_modules/goah-supervisor/dist/verification.js.map +0 -1
  227. package/node_modules/goah-supervisor/package.json +0 -26
  228. package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts +0 -2
  229. package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts.map +0 -1
  230. package/node_modules/goah-testkit/dist/faux-runner-worker.js +0 -82
  231. package/node_modules/goah-testkit/dist/faux-runner-worker.js.map +0 -1
  232. package/node_modules/goah-testkit/dist/index.d.ts +0 -49
  233. package/node_modules/goah-testkit/dist/index.d.ts.map +0 -1
  234. package/node_modules/goah-testkit/dist/index.js +0 -96
  235. package/node_modules/goah-testkit/dist/index.js.map +0 -1
  236. 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
+ };