@goah/cli 0.11.5 → 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 (242) 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 +13148 -506
  38. package/dist/console/assets/index-3sYrDMmt.css +1 -0
  39. package/dist/console/assets/index-B1vGMXKr.js +52 -0
  40. package/dist/console/assets/index-B1vGMXKr.js.map +1 -0
  41. package/dist/console/index.html +2 -2
  42. package/dist/dist-65MDQA4Q.js +1126 -0
  43. package/dist/dist-KNR2XL6J.js +39 -0
  44. package/dist/execution.d.ts +557 -2
  45. package/dist/execution.js +37 -2
  46. package/dist/faux-runner-worker.js +128 -0
  47. package/dist/google-generative-ai-YMHXZSFE.js +422 -0
  48. package/dist/google-vertex-X6DB3ZQ6.js +471 -0
  49. package/dist/index.d.ts +855 -44
  50. package/dist/index.js +84 -257
  51. package/dist/kernel.d.ts +39 -2
  52. package/dist/kernel.js +21 -2
  53. package/dist/mistral-conversations-TY3MMD6G.js +718 -0
  54. package/dist/multipart-parser-F6M4NJZU.js +373 -0
  55. package/dist/openai-codex-responses-BRDUMLN5.js +1374 -0
  56. package/dist/openai-completions-CX634XN3.js +1139 -0
  57. package/dist/openai-responses-HMCXJIHT.js +300 -0
  58. package/dist/openrouter-images-KTWET2H2.js +148 -0
  59. package/dist/pi-messages-XL5OEC4K.js +307 -0
  60. package/dist/pi-worker.js +671 -0
  61. package/dist/runner-pi.d.ts +342 -2
  62. package/dist/runner-pi.js +46 -2
  63. package/dist/runner-registry-M776E3SE.js +22 -0
  64. package/dist/sqlite.d.ts +446 -2
  65. package/dist/sqlite.js +15 -2
  66. package/dist/src-F2KBSV4T.js +1398 -0
  67. package/dist/supervisor.d.ts +625 -2
  68. package/dist/supervisor.js +39 -2
  69. package/dist/testkit.d.ts +564 -2
  70. package/dist/testkit.js +127 -2
  71. package/dist/transcript.d.ts +84 -0
  72. package/dist/transcript.js +25 -0
  73. package/dist/verification-worker.js +72 -0
  74. package/package.json +3 -28
  75. package/dist/cli.d.ts.map +0 -1
  76. package/dist/cli.js.map +0 -1
  77. package/dist/console/assets/index-BJTGvlCH.js +0 -52
  78. package/dist/console/assets/index-BJTGvlCH.js.map +0 -1
  79. package/dist/console/assets/index-msBn41Cl.css +0 -1
  80. package/dist/control.d.ts +0 -106
  81. package/dist/control.d.ts.map +0 -1
  82. package/dist/control.js +0 -215
  83. package/dist/control.js.map +0 -1
  84. package/dist/execution.d.ts.map +0 -1
  85. package/dist/execution.js.map +0 -1
  86. package/dist/index.d.ts.map +0 -1
  87. package/dist/index.js.map +0 -1
  88. package/dist/inspect.d.ts +0 -61
  89. package/dist/inspect.d.ts.map +0 -1
  90. package/dist/inspect.js +0 -110
  91. package/dist/inspect.js.map +0 -1
  92. package/dist/kernel.d.ts.map +0 -1
  93. package/dist/kernel.js.map +0 -1
  94. package/dist/live-config.d.ts +0 -10
  95. package/dist/live-config.d.ts.map +0 -1
  96. package/dist/live-config.js +0 -44
  97. package/dist/live-config.js.map +0 -1
  98. package/dist/metrics.d.ts +0 -2
  99. package/dist/metrics.d.ts.map +0 -1
  100. package/dist/metrics.js +0 -2
  101. package/dist/metrics.js.map +0 -1
  102. package/dist/prompt-queue.d.ts +0 -13
  103. package/dist/prompt-queue.d.ts.map +0 -1
  104. package/dist/prompt-queue.js +0 -30
  105. package/dist/prompt-queue.js.map +0 -1
  106. package/dist/runner-pi.d.ts.map +0 -1
  107. package/dist/runner-pi.js.map +0 -1
  108. package/dist/runner-registry.d.ts +0 -8
  109. package/dist/runner-registry.d.ts.map +0 -1
  110. package/dist/runner-registry.js +0 -12
  111. package/dist/runner-registry.js.map +0 -1
  112. package/dist/searchable-select.d.ts +0 -24
  113. package/dist/searchable-select.d.ts.map +0 -1
  114. package/dist/searchable-select.js +0 -61
  115. package/dist/searchable-select.js.map +0 -1
  116. package/dist/secret-input.d.ts +0 -8
  117. package/dist/secret-input.d.ts.map +0 -1
  118. package/dist/secret-input.js +0 -14
  119. package/dist/secret-input.js.map +0 -1
  120. package/dist/session.d.ts +0 -2
  121. package/dist/session.d.ts.map +0 -1
  122. package/dist/session.js +0 -2
  123. package/dist/session.js.map +0 -1
  124. package/dist/setup-wizard.d.ts +0 -11
  125. package/dist/setup-wizard.d.ts.map +0 -1
  126. package/dist/setup-wizard.js +0 -130
  127. package/dist/setup-wizard.js.map +0 -1
  128. package/dist/sqlite.d.ts.map +0 -1
  129. package/dist/sqlite.js.map +0 -1
  130. package/dist/supervisor.d.ts.map +0 -1
  131. package/dist/supervisor.js.map +0 -1
  132. package/dist/testkit.d.ts.map +0 -1
  133. package/dist/testkit.js.map +0 -1
  134. package/dist/tui-theme.d.ts +0 -16
  135. package/dist/tui-theme.d.ts.map +0 -1
  136. package/dist/tui-theme.js +0 -18
  137. package/dist/tui-theme.js.map +0 -1
  138. package/dist/tui.d.ts +0 -18
  139. package/dist/tui.d.ts.map +0 -1
  140. package/dist/tui.js +0 -583
  141. package/dist/tui.js.map +0 -1
  142. package/dist/update.d.ts +0 -15
  143. package/dist/update.d.ts.map +0 -1
  144. package/dist/update.js +0 -59
  145. package/dist/update.js.map +0 -1
  146. package/dist/web-console.d.ts +0 -33
  147. package/dist/web-console.d.ts.map +0 -1
  148. package/dist/web-console.js +0 -252
  149. package/dist/web-console.js.map +0 -1
  150. package/dist/welcome.d.ts +0 -30
  151. package/dist/welcome.d.ts.map +0 -1
  152. package/dist/welcome.js +0 -81
  153. package/dist/welcome.js.map +0 -1
  154. package/node_modules/goah-ledger-contract/dist/execution.d.ts +0 -402
  155. package/node_modules/goah-ledger-contract/dist/execution.d.ts.map +0 -1
  156. package/node_modules/goah-ledger-contract/dist/execution.js +0 -40
  157. package/node_modules/goah-ledger-contract/dist/execution.js.map +0 -1
  158. package/node_modules/goah-ledger-contract/dist/index.d.ts +0 -5
  159. package/node_modules/goah-ledger-contract/dist/index.d.ts.map +0 -1
  160. package/node_modules/goah-ledger-contract/dist/index.js +0 -5
  161. package/node_modules/goah-ledger-contract/dist/index.js.map +0 -1
  162. package/node_modules/goah-ledger-contract/dist/kernel.d.ts +0 -37
  163. package/node_modules/goah-ledger-contract/dist/kernel.d.ts.map +0 -1
  164. package/node_modules/goah-ledger-contract/dist/kernel.js +0 -8
  165. package/node_modules/goah-ledger-contract/dist/kernel.js.map +0 -1
  166. package/node_modules/goah-ledger-contract/dist/metrics.d.ts +0 -40
  167. package/node_modules/goah-ledger-contract/dist/metrics.d.ts.map +0 -1
  168. package/node_modules/goah-ledger-contract/dist/metrics.js +0 -25
  169. package/node_modules/goah-ledger-contract/dist/metrics.js.map +0 -1
  170. package/node_modules/goah-ledger-contract/dist/session.d.ts +0 -63
  171. package/node_modules/goah-ledger-contract/dist/session.d.ts.map +0 -1
  172. package/node_modules/goah-ledger-contract/dist/session.js +0 -115
  173. package/node_modules/goah-ledger-contract/dist/session.js.map +0 -1
  174. package/node_modules/goah-ledger-contract/package.json +0 -29
  175. package/node_modules/goah-ledger-sqlite/dist/index.d.ts +0 -77
  176. package/node_modules/goah-ledger-sqlite/dist/index.d.ts.map +0 -1
  177. package/node_modules/goah-ledger-sqlite/dist/index.js +0 -884
  178. package/node_modules/goah-ledger-sqlite/dist/index.js.map +0 -1
  179. package/node_modules/goah-ledger-sqlite/package.json +0 -26
  180. package/node_modules/goah-runner-pi/dist/configurator.d.ts +0 -20
  181. package/node_modules/goah-runner-pi/dist/configurator.d.ts.map +0 -1
  182. package/node_modules/goah-runner-pi/dist/configurator.js +0 -267
  183. package/node_modules/goah-runner-pi/dist/configurator.js.map +0 -1
  184. package/node_modules/goah-runner-pi/dist/credential-store.d.ts +0 -12
  185. package/node_modules/goah-runner-pi/dist/credential-store.d.ts.map +0 -1
  186. package/node_modules/goah-runner-pi/dist/credential-store.js +0 -69
  187. package/node_modules/goah-runner-pi/dist/credential-store.js.map +0 -1
  188. package/node_modules/goah-runner-pi/dist/env-spec.d.ts +0 -17
  189. package/node_modules/goah-runner-pi/dist/env-spec.d.ts.map +0 -1
  190. package/node_modules/goah-runner-pi/dist/env-spec.js +0 -95
  191. package/node_modules/goah-runner-pi/dist/env-spec.js.map +0 -1
  192. package/node_modules/goah-runner-pi/dist/index.d.ts +0 -64
  193. package/node_modules/goah-runner-pi/dist/index.d.ts.map +0 -1
  194. package/node_modules/goah-runner-pi/dist/index.js +0 -241
  195. package/node_modules/goah-runner-pi/dist/index.js.map +0 -1
  196. package/node_modules/goah-runner-pi/dist/model-provider.d.ts +0 -30
  197. package/node_modules/goah-runner-pi/dist/model-provider.d.ts.map +0 -1
  198. package/node_modules/goah-runner-pi/dist/model-provider.js +0 -96
  199. package/node_modules/goah-runner-pi/dist/model-provider.js.map +0 -1
  200. package/node_modules/goah-runner-pi/dist/pi-worker.d.ts +0 -29
  201. package/node_modules/goah-runner-pi/dist/pi-worker.d.ts.map +0 -1
  202. package/node_modules/goah-runner-pi/dist/pi-worker.js +0 -428
  203. package/node_modules/goah-runner-pi/dist/pi-worker.js.map +0 -1
  204. package/node_modules/goah-runner-pi/dist/test-helpers.d.ts +0 -4
  205. package/node_modules/goah-runner-pi/dist/test-helpers.d.ts.map +0 -1
  206. package/node_modules/goah-runner-pi/dist/test-helpers.js +0 -11
  207. package/node_modules/goah-runner-pi/dist/test-helpers.js.map +0 -1
  208. package/node_modules/goah-runner-pi/dist/verification-worker.d.ts +0 -2
  209. package/node_modules/goah-runner-pi/dist/verification-worker.d.ts.map +0 -1
  210. package/node_modules/goah-runner-pi/dist/verification-worker.js +0 -48
  211. package/node_modules/goah-runner-pi/dist/verification-worker.js.map +0 -1
  212. package/node_modules/goah-runner-pi/package.json +0 -28
  213. package/node_modules/goah-supervisor/dist/context-view.d.ts +0 -31
  214. package/node_modules/goah-supervisor/dist/context-view.d.ts.map +0 -1
  215. package/node_modules/goah-supervisor/dist/context-view.js +0 -71
  216. package/node_modules/goah-supervisor/dist/context-view.js.map +0 -1
  217. package/node_modules/goah-supervisor/dist/index.d.ts +0 -94
  218. package/node_modules/goah-supervisor/dist/index.d.ts.map +0 -1
  219. package/node_modules/goah-supervisor/dist/index.js +0 -888
  220. package/node_modules/goah-supervisor/dist/index.js.map +0 -1
  221. package/node_modules/goah-supervisor/dist/roles.d.ts +0 -3
  222. package/node_modules/goah-supervisor/dist/roles.d.ts.map +0 -1
  223. package/node_modules/goah-supervisor/dist/roles.js +0 -14
  224. package/node_modules/goah-supervisor/dist/roles.js.map +0 -1
  225. package/node_modules/goah-supervisor/dist/verification.d.ts +0 -82
  226. package/node_modules/goah-supervisor/dist/verification.d.ts.map +0 -1
  227. package/node_modules/goah-supervisor/dist/verification.js +0 -110
  228. package/node_modules/goah-supervisor/dist/verification.js.map +0 -1
  229. package/node_modules/goah-supervisor/package.json +0 -26
  230. package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts +0 -2
  231. package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts.map +0 -1
  232. package/node_modules/goah-testkit/dist/faux-runner-worker.js +0 -75
  233. package/node_modules/goah-testkit/dist/faux-runner-worker.js.map +0 -1
  234. package/node_modules/goah-testkit/dist/index.d.ts +0 -52
  235. package/node_modules/goah-testkit/dist/index.d.ts.map +0 -1
  236. package/node_modules/goah-testkit/dist/index.js +0 -113
  237. package/node_modules/goah-testkit/dist/index.js.map +0 -1
  238. package/node_modules/goah-testkit/dist/mock-connector-worker.d.ts +0 -2
  239. package/node_modules/goah-testkit/dist/mock-connector-worker.d.ts.map +0 -1
  240. package/node_modules/goah-testkit/dist/mock-connector-worker.js +0 -29
  241. package/node_modules/goah-testkit/dist/mock-connector-worker.js.map +0 -1
  242. package/node_modules/goah-testkit/package.json +0 -29
@@ -0,0 +1,471 @@
1
+ import { createRequire as __goahCreateRequire } from "node:module";
2
+ const require = __goahCreateRequire(import.meta.url);
3
+ import {
4
+ GoogleGenAI,
5
+ ResourceScope,
6
+ ThinkingLevel,
7
+ convertMessages,
8
+ convertTools,
9
+ isThinkingPart,
10
+ mapStopReason,
11
+ resolveGoogleFunctionCallingMode,
12
+ retainThoughtSignature,
13
+ retryGoogleRequest,
14
+ supportsGoogleStrictToolSampling
15
+ } from "./chunk-ULY36ME4.js";
16
+ import {
17
+ formatProviderError,
18
+ normalizeProviderError
19
+ } from "./chunk-H462EFJP.js";
20
+ import {
21
+ buildBaseOptions
22
+ } from "./chunk-BXA47DTF.js";
23
+ import "./chunk-4M6TXTT5.js";
24
+ import {
25
+ sanitizeSurrogates
26
+ } from "./chunk-NRLGWZJC.js";
27
+ import {
28
+ providerHeadersToRecord
29
+ } from "./chunk-FSBUS2BI.js";
30
+ import {
31
+ getProviderEnvValue
32
+ } from "./chunk-IIJQ3DW4.js";
33
+ import {
34
+ calculateCost,
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/google-vertex.js
43
+ var API_VERSION = "v1";
44
+ var GCP_VERTEX_CREDENTIALS_MARKER = "gcp-vertex-credentials";
45
+ var THINKING_LEVEL_MAP = {
46
+ THINKING_LEVEL_UNSPECIFIED: ThinkingLevel.THINKING_LEVEL_UNSPECIFIED,
47
+ MINIMAL: ThinkingLevel.MINIMAL,
48
+ LOW: ThinkingLevel.LOW,
49
+ MEDIUM: ThinkingLevel.MEDIUM,
50
+ HIGH: ThinkingLevel.HIGH
51
+ };
52
+ var toolCallCounter = 0;
53
+ var stream = (model, context, options) => {
54
+ const stream2 = new AssistantMessageEventStream();
55
+ (async () => {
56
+ const output = {
57
+ role: "assistant",
58
+ content: [],
59
+ api: "google-vertex",
60
+ provider: model.provider,
61
+ model: model.id,
62
+ usage: {
63
+ input: 0,
64
+ output: 0,
65
+ cacheRead: 0,
66
+ cacheWrite: 0,
67
+ totalTokens: 0,
68
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
69
+ },
70
+ stopReason: "pending",
71
+ timestamp: Date.now()
72
+ };
73
+ try {
74
+ if (options?.fetch && options.fetch !== globalThis.fetch) {
75
+ throw new Error("Custom fetch is not supported by the Google Vertex adapter");
76
+ }
77
+ const apiKey = resolveApiKey(options);
78
+ const client = apiKey ? createClientWithApiKey(model, apiKey, options?.headers) : createClient(model, resolveProject(options), resolveLocation(options), options?.headers, options?.env);
79
+ let params = buildParams(model, context, options);
80
+ const nextParams = await options?.onPayload?.(params, model);
81
+ if (nextParams !== void 0) {
82
+ params = nextParams;
83
+ }
84
+ const googleStream = await retryGoogleRequest(() => client.models.generateContentStream(params), options);
85
+ stream2.push({ type: "start", partial: output });
86
+ let currentBlock = null;
87
+ const blocks = output.content;
88
+ const blockIndex = () => blocks.length - 1;
89
+ for await (const chunk of googleStream) {
90
+ output.responseId ||= chunk.responseId;
91
+ const candidate = chunk.candidates?.[0];
92
+ if (candidate?.content?.parts) {
93
+ for (const part of candidate.content.parts) {
94
+ if (part.text !== void 0) {
95
+ const isThinking = isThinkingPart(part);
96
+ if (!currentBlock || isThinking && currentBlock.type !== "thinking" || !isThinking && currentBlock.type !== "text") {
97
+ if (currentBlock) {
98
+ if (currentBlock.type === "text") {
99
+ stream2.push({
100
+ type: "text_end",
101
+ contentIndex: blocks.length - 1,
102
+ content: currentBlock.text,
103
+ partial: output
104
+ });
105
+ } else {
106
+ stream2.push({
107
+ type: "thinking_end",
108
+ contentIndex: blockIndex(),
109
+ content: currentBlock.thinking,
110
+ partial: output
111
+ });
112
+ }
113
+ }
114
+ if (isThinking) {
115
+ currentBlock = { type: "thinking", thinking: "", thinkingSignature: void 0 };
116
+ output.content.push(currentBlock);
117
+ stream2.push({ type: "thinking_start", contentIndex: blockIndex(), partial: output });
118
+ } else {
119
+ currentBlock = { type: "text", text: "" };
120
+ output.content.push(currentBlock);
121
+ stream2.push({ type: "text_start", contentIndex: blockIndex(), partial: output });
122
+ }
123
+ }
124
+ if (currentBlock.type === "thinking") {
125
+ currentBlock.thinking += part.text;
126
+ currentBlock.thinkingSignature = retainThoughtSignature(currentBlock.thinkingSignature, part.thoughtSignature);
127
+ stream2.push({
128
+ type: "thinking_delta",
129
+ contentIndex: blockIndex(),
130
+ delta: part.text,
131
+ partial: output
132
+ });
133
+ } else {
134
+ currentBlock.text += part.text;
135
+ currentBlock.textSignature = retainThoughtSignature(currentBlock.textSignature, part.thoughtSignature);
136
+ stream2.push({
137
+ type: "text_delta",
138
+ contentIndex: blockIndex(),
139
+ delta: part.text,
140
+ partial: output
141
+ });
142
+ }
143
+ }
144
+ if (part.functionCall) {
145
+ if (currentBlock) {
146
+ if (currentBlock.type === "text") {
147
+ stream2.push({
148
+ type: "text_end",
149
+ contentIndex: blockIndex(),
150
+ content: currentBlock.text,
151
+ partial: output
152
+ });
153
+ } else {
154
+ stream2.push({
155
+ type: "thinking_end",
156
+ contentIndex: blockIndex(),
157
+ content: currentBlock.thinking,
158
+ partial: output
159
+ });
160
+ }
161
+ currentBlock = null;
162
+ }
163
+ const providedId = part.functionCall.id;
164
+ const needsNewId = !providedId || output.content.some((b) => b.type === "toolCall" && b.id === providedId);
165
+ const toolCallId = needsNewId ? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}` : providedId;
166
+ const toolCall = {
167
+ type: "toolCall",
168
+ id: toolCallId,
169
+ name: part.functionCall.name || "",
170
+ arguments: part.functionCall.args ?? {},
171
+ ...part.thoughtSignature && { thoughtSignature: part.thoughtSignature }
172
+ };
173
+ output.content.push(toolCall);
174
+ stream2.push({ type: "toolcall_start", contentIndex: blockIndex(), partial: output });
175
+ stream2.push({
176
+ type: "toolcall_delta",
177
+ contentIndex: blockIndex(),
178
+ delta: JSON.stringify(toolCall.arguments),
179
+ partial: output
180
+ });
181
+ stream2.push({ type: "toolcall_end", contentIndex: blockIndex(), toolCall, partial: output });
182
+ }
183
+ }
184
+ }
185
+ if (candidate?.finishReason) {
186
+ output.rawStopReason = candidate.finishReason;
187
+ output.stopReason = mapStopReason(candidate.finishReason);
188
+ if (output.content.some((b) => b.type === "toolCall") && output.stopReason === "stop") {
189
+ output.stopReason = "toolUse";
190
+ }
191
+ }
192
+ if (chunk.usageMetadata) {
193
+ output.usage = {
194
+ input: (chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),
195
+ output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),
196
+ cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,
197
+ cacheWrite: 0,
198
+ reasoning: chunk.usageMetadata.thoughtsTokenCount || 0,
199
+ totalTokens: chunk.usageMetadata.totalTokenCount || 0,
200
+ cost: {
201
+ input: 0,
202
+ output: 0,
203
+ cacheRead: 0,
204
+ cacheWrite: 0,
205
+ total: 0
206
+ }
207
+ };
208
+ calculateCost(model, output.usage);
209
+ }
210
+ }
211
+ if (currentBlock) {
212
+ if (currentBlock.type === "text") {
213
+ stream2.push({
214
+ type: "text_end",
215
+ contentIndex: blockIndex(),
216
+ content: currentBlock.text,
217
+ partial: output
218
+ });
219
+ } else {
220
+ stream2.push({
221
+ type: "thinking_end",
222
+ contentIndex: blockIndex(),
223
+ content: currentBlock.thinking,
224
+ partial: output
225
+ });
226
+ }
227
+ }
228
+ if (options?.signal?.aborted) {
229
+ throw new Error("Request was aborted");
230
+ }
231
+ if (output.stopReason === "pending") {
232
+ throw new Error("Google Vertex stream ended without a finish reason");
233
+ }
234
+ if (output.stopReason === "aborted" || output.stopReason === "error") {
235
+ const errorMessage = output.rawStopReason ? `Provider stopped with: ${output.rawStopReason}` : "An unknown error occurred";
236
+ throw new Error(errorMessage);
237
+ }
238
+ stream2.push({ type: "done", reason: output.stopReason, message: output });
239
+ stream2.end();
240
+ } catch (error) {
241
+ for (const block of output.content) {
242
+ if ("index" in block) {
243
+ delete block.index;
244
+ }
245
+ }
246
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
247
+ output.errorMessage = formatProviderError(normalizeProviderError(error));
248
+ stream2.push({ type: "error", reason: output.stopReason, error: output });
249
+ stream2.end();
250
+ }
251
+ })();
252
+ return stream2;
253
+ };
254
+ var streamSimple = (model, context, options) => {
255
+ const base = buildBaseOptions(model, context, options, void 0);
256
+ if (!options?.reasoning) {
257
+ return stream(model, context, {
258
+ ...base,
259
+ thinking: { enabled: false }
260
+ });
261
+ }
262
+ const clampedReasoning = clampThinkingLevel(model, options.reasoning);
263
+ const effort = clampedReasoning === "off" ? "high" : clampedReasoning;
264
+ const geminiModel = model;
265
+ if (isGemini3ProModel(geminiModel) || isGemini3FlashModel(geminiModel)) {
266
+ return stream(model, context, {
267
+ ...base,
268
+ thinking: {
269
+ enabled: true,
270
+ level: getGemini3ThinkingLevel(effort, geminiModel)
271
+ }
272
+ });
273
+ }
274
+ return stream(model, context, {
275
+ ...base,
276
+ thinking: {
277
+ enabled: true,
278
+ budgetTokens: getGoogleBudget(geminiModel, effort, options.thinkingBudgets)
279
+ }
280
+ });
281
+ };
282
+ function createClient(model, project, location, optionsHeaders, env) {
283
+ const googleAuthOptions = buildGoogleAuthOptions(env);
284
+ return new GoogleGenAI({
285
+ vertexai: true,
286
+ project,
287
+ location,
288
+ apiVersion: API_VERSION,
289
+ ...googleAuthOptions ? { googleAuthOptions } : {},
290
+ httpOptions: buildHttpOptions(model, optionsHeaders)
291
+ });
292
+ }
293
+ function createClientWithApiKey(model, apiKey, optionsHeaders) {
294
+ return new GoogleGenAI({
295
+ vertexai: true,
296
+ apiKey,
297
+ apiVersion: API_VERSION,
298
+ httpOptions: buildHttpOptions(model, optionsHeaders)
299
+ });
300
+ }
301
+ function buildHttpOptions(model, optionsHeaders) {
302
+ const httpOptions = {};
303
+ const baseUrl = resolveCustomBaseUrl(model.baseUrl);
304
+ if (baseUrl) {
305
+ httpOptions.baseUrl = baseUrl;
306
+ httpOptions.baseUrlResourceScope = ResourceScope.COLLECTION;
307
+ if (baseUrlIncludesApiVersion(baseUrl)) {
308
+ httpOptions.apiVersion = "";
309
+ }
310
+ }
311
+ const headers = providerHeadersToRecord({ ...model.headers, ...optionsHeaders });
312
+ if (headers) {
313
+ httpOptions.headers = headers;
314
+ }
315
+ return Object.keys(httpOptions).length > 0 ? httpOptions : void 0;
316
+ }
317
+ function resolveCustomBaseUrl(baseUrl) {
318
+ const trimmed = baseUrl.trim();
319
+ if (!trimmed || trimmed.includes("{location}")) {
320
+ return void 0;
321
+ }
322
+ return trimmed;
323
+ }
324
+ function baseUrlIncludesApiVersion(baseUrl) {
325
+ try {
326
+ const url = new URL(baseUrl);
327
+ return url.pathname.split("/").some((part) => /^v\d+(?:beta\d*)?$/.test(part));
328
+ } catch {
329
+ return /(?:^|\/)v\d+(?:beta\d*)?(?:\/|$)/.test(baseUrl);
330
+ }
331
+ }
332
+ function buildGoogleAuthOptions(env) {
333
+ const keyFilename = getProviderEnvValue("GOOGLE_APPLICATION_CREDENTIALS", env);
334
+ return keyFilename ? { keyFilename } : void 0;
335
+ }
336
+ function resolveApiKey(options) {
337
+ const apiKey = options?.apiKey?.trim();
338
+ if (!apiKey || apiKey === GCP_VERTEX_CREDENTIALS_MARKER || isPlaceholderApiKey(apiKey)) {
339
+ return void 0;
340
+ }
341
+ return apiKey;
342
+ }
343
+ function isPlaceholderApiKey(apiKey) {
344
+ return /^<[^>]+>$/.test(apiKey);
345
+ }
346
+ function resolveProject(options) {
347
+ const project = options?.project || getProviderEnvValue("GOOGLE_CLOUD_PROJECT", options?.env) || getProviderEnvValue("GCLOUD_PROJECT", options?.env);
348
+ if (!project) {
349
+ throw new Error("Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.");
350
+ }
351
+ return project;
352
+ }
353
+ function resolveLocation(options) {
354
+ const location = options?.location || getProviderEnvValue("GOOGLE_CLOUD_LOCATION", options?.env);
355
+ if (!location) {
356
+ throw new Error("Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.");
357
+ }
358
+ return location;
359
+ }
360
+ function buildParams(model, context, options = {}) {
361
+ const contents = convertMessages(model, context);
362
+ const generationConfig = {};
363
+ if (options.temperature !== void 0) {
364
+ generationConfig.temperature = options.temperature;
365
+ }
366
+ if (options.maxTokens !== void 0) {
367
+ generationConfig.maxOutputTokens = options.maxTokens;
368
+ }
369
+ const supportsStrictMode = supportsGoogleStrictToolSampling(model.id);
370
+ const functionCallingMode = context.tools?.length ? resolveGoogleFunctionCallingMode(context.tools, options.toolChoice, supportsStrictMode) : void 0;
371
+ const config = {
372
+ ...Object.keys(generationConfig).length > 0 && generationConfig,
373
+ ...context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) },
374
+ ...context.tools && context.tools.length > 0 && {
375
+ tools: convertTools(context.tools, false, supportsStrictMode)
376
+ },
377
+ ...functionCallingMode !== void 0 && {
378
+ toolConfig: { functionCallingConfig: { mode: functionCallingMode } }
379
+ }
380
+ };
381
+ if (options.thinking?.enabled && model.reasoning) {
382
+ const thinkingConfig = { includeThoughts: true };
383
+ if (options.thinking.level !== void 0) {
384
+ thinkingConfig.thinkingLevel = THINKING_LEVEL_MAP[options.thinking.level];
385
+ } else if (options.thinking.budgetTokens !== void 0) {
386
+ thinkingConfig.thinkingBudget = options.thinking.budgetTokens;
387
+ }
388
+ config.thinkingConfig = thinkingConfig;
389
+ } else if (model.reasoning && options.thinking && !options.thinking.enabled) {
390
+ config.thinkingConfig = getDisabledThinkingConfig(model);
391
+ }
392
+ if (options.signal) {
393
+ if (options.signal.aborted) {
394
+ throw new Error("Request aborted");
395
+ }
396
+ config.abortSignal = options.signal;
397
+ }
398
+ const params = {
399
+ model: model.id,
400
+ contents,
401
+ config
402
+ };
403
+ return params;
404
+ }
405
+ function isGemini3ProModel(model) {
406
+ return /gemini-3(?:\.\d+)?-pro/.test(model.id.toLowerCase());
407
+ }
408
+ function isGemini3FlashModel(model) {
409
+ const id = model.id.toLowerCase();
410
+ return /gemini-3(?:\.\d+)?-flash/.test(id) || id === "gemini-flash-latest" || id === "gemini-flash-lite-latest";
411
+ }
412
+ function getDisabledThinkingConfig(model) {
413
+ const geminiModel = model;
414
+ if (isGemini3ProModel(geminiModel)) {
415
+ return { thinkingLevel: ThinkingLevel.LOW };
416
+ }
417
+ if (isGemini3FlashModel(geminiModel)) {
418
+ return { thinkingLevel: ThinkingLevel.MINIMAL };
419
+ }
420
+ return { thinkingBudget: 0 };
421
+ }
422
+ function getGemini3ThinkingLevel(effort, model) {
423
+ if (isGemini3ProModel(model)) {
424
+ switch (effort) {
425
+ case "minimal":
426
+ case "low":
427
+ return "LOW";
428
+ case "medium":
429
+ case "high":
430
+ return "HIGH";
431
+ }
432
+ }
433
+ switch (effort) {
434
+ case "minimal":
435
+ return "MINIMAL";
436
+ case "low":
437
+ return "LOW";
438
+ case "medium":
439
+ return "MEDIUM";
440
+ case "high":
441
+ return "HIGH";
442
+ }
443
+ }
444
+ function getGoogleBudget(model, effort, customBudgets) {
445
+ if (customBudgets?.[effort] !== void 0) {
446
+ return customBudgets[effort];
447
+ }
448
+ if (model.id.includes("2.5-pro")) {
449
+ const budgets = {
450
+ minimal: 128,
451
+ low: 2048,
452
+ medium: 8192,
453
+ high: 32768
454
+ };
455
+ return budgets[effort];
456
+ }
457
+ if (model.id.includes("2.5-flash")) {
458
+ const budgets = {
459
+ minimal: 128,
460
+ low: 2048,
461
+ medium: 8192,
462
+ high: 24576
463
+ };
464
+ return budgets[effort];
465
+ }
466
+ return -1;
467
+ }
468
+ export {
469
+ stream,
470
+ streamSimple
471
+ };