pagegraph 0.13.0 → 0.14.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 (80) hide show
  1. package/README.md +48 -41
  2. package/dist/anthropic-messages-TqKpKmfW.js +1067 -0
  3. package/dist/anthropic-messages-TqKpKmfW.js.map +1 -0
  4. package/dist/audit.d.ts +2 -0
  5. package/dist/audit.js +1 -1
  6. package/dist/audit.js.map +1 -1
  7. package/dist/azure-openai-responses-DJjBLwoI.js +231 -0
  8. package/dist/azure-openai-responses-DJjBLwoI.js.map +1 -0
  9. package/dist/cli.js +10487 -38044
  10. package/dist/cli.js.map +1 -1
  11. package/dist/cloudflare-workers-ai-system-one-f3ZrvNYZ.js +41 -0
  12. package/dist/cloudflare-workers-ai-system-one-f3ZrvNYZ.js.map +1 -0
  13. package/dist/config.d.ts +6 -6
  14. package/dist/config.js.map +1 -1
  15. package/dist/diagnostics-Wt5faNDM.js +108 -0
  16. package/dist/diagnostics-Wt5faNDM.js.map +1 -0
  17. package/dist/dist-cFoAzruL.js +4794 -0
  18. package/dist/dist-cFoAzruL.js.map +1 -0
  19. package/dist/env-api-keys-C-OA0yM-.js +124 -0
  20. package/dist/env-api-keys-C-OA0yM-.js.map +1 -0
  21. package/dist/error-body-CyiejW4b.js +103 -0
  22. package/dist/error-body-CyiejW4b.js.map +1 -0
  23. package/dist/github-copilot-headers-CEpMOpQF.js +24 -0
  24. package/dist/github-copilot-headers-CEpMOpQF.js.map +1 -0
  25. package/dist/google-generative-ai-BxABKIKO.js +330 -0
  26. package/dist/google-generative-ai-BxABKIKO.js.map +1 -0
  27. package/dist/google-shared-0gpM2jFi.js +19471 -0
  28. package/dist/google-shared-0gpM2jFi.js.map +1 -0
  29. package/dist/google-vertex-D8Eb5cbu.js +376 -0
  30. package/dist/google-vertex-D8Eb5cbu.js.map +1 -0
  31. package/dist/hash-Dp7EzZUo.js +18 -0
  32. package/dist/hash-Dp7EzZUo.js.map +1 -0
  33. package/dist/headers-BRNMVpzu.js +19 -0
  34. package/dist/headers-BRNMVpzu.js.map +1 -0
  35. package/dist/json-parse-C10znB7l.js +383 -0
  36. package/dist/json-parse-C10znB7l.js.map +1 -0
  37. package/dist/mistral-conversations-CvaqBWjR.js +690 -0
  38. package/dist/mistral-conversations-CvaqBWjR.js.map +1 -0
  39. package/dist/models-DcT5qOEL.js +1203 -0
  40. package/dist/models-DcT5qOEL.js.map +1 -0
  41. package/dist/node-Ccvru9GE.js +26 -0
  42. package/dist/node-Ccvru9GE.js.map +1 -0
  43. package/dist/node-MEosBOF2.js +2403 -0
  44. package/dist/node-MEosBOF2.js.map +1 -0
  45. package/dist/openai-BCBEd2eO.js +17350 -0
  46. package/dist/openai-BCBEd2eO.js.map +1 -0
  47. package/dist/openai-codex-responses-vJqxeeRC.js +1268 -0
  48. package/dist/openai-codex-responses-vJqxeeRC.js.map +1 -0
  49. package/dist/openai-completions-Cb_fRAbI.js +989 -0
  50. package/dist/openai-completions-Cb_fRAbI.js.map +1 -0
  51. package/dist/openai-prompt-cache-Bc6qNWt0.js +10 -0
  52. package/dist/openai-prompt-cache-Bc6qNWt0.js.map +1 -0
  53. package/dist/openai-responses-sDuh82G5.js +268 -0
  54. package/dist/openai-responses-sDuh82G5.js.map +1 -0
  55. package/dist/openai-responses-shared-mhuo1Jov.js +599 -0
  56. package/dist/openai-responses-shared-mhuo1Jov.js.map +1 -0
  57. package/dist/openrouter-images-CRmBkzpX.js +127 -0
  58. package/dist/openrouter-images-CRmBkzpX.js.map +1 -0
  59. package/dist/pi-D3mMmYey.js +56805 -0
  60. package/dist/pi-D3mMmYey.js.map +1 -0
  61. package/dist/pi-messages-CejiVYvO.js +308 -0
  62. package/dist/pi-messages-CejiVYvO.js.map +1 -0
  63. package/dist/provider-env-t38GK5FF.js +39 -0
  64. package/dist/provider-env-t38GK5FF.js.map +1 -0
  65. package/dist/provider-retry-DzKoh1X7.js +80 -0
  66. package/dist/provider-retry-DzKoh1X7.js.map +1 -0
  67. package/dist/rolldown-runtime-B-lAHAz2.js +37 -0
  68. package/dist/sanitize-unicode-Ds14l9Om.js +28 -0
  69. package/dist/sanitize-unicode-Ds14l9Om.js.map +1 -0
  70. package/dist/sdk-C9_wiO6w.js +12503 -0
  71. package/dist/sdk-C9_wiO6w.js.map +1 -0
  72. package/dist/state-BuJP_3Lr.js +28102 -0
  73. package/dist/state-BuJP_3Lr.js.map +1 -0
  74. package/dist/system-one-shared-Dl10ZF7Z.js +167 -0
  75. package/dist/system-one-shared-Dl10ZF7Z.js.map +1 -0
  76. package/dist/transform-messages-BLJ8EfK6.js +468 -0
  77. package/dist/transform-messages-BLJ8EfK6.js.map +1 -0
  78. package/dist/typesafe-system-one-CwEWMV8P.js +25 -0
  79. package/dist/typesafe-system-one-CwEWMV8P.js.map +1 -0
  80. package/package.json +4 -8
@@ -0,0 +1,376 @@
1
+ import { t as getProviderEnvValue } from "./provider-env-t38GK5FF.js";
2
+ import { a as AssistantMessageEventStream } from "./diagnostics-Wt5faNDM.js";
3
+ import { S as getSystemMessageText, d as getCurrentTools, n as clampThinkingLevel, o as collapseSystemMessages, p as getInitialSystemMessage, t as calculateCost } from "./models-DcT5qOEL.js";
4
+ import { n as providerHeadersToRecord } from "./headers-BRNMVpzu.js";
5
+ import { p as getPiUserAgent, r as buildBaseOptions } from "./transform-messages-BLJ8EfK6.js";
6
+ import { t as sanitizeSurrogates } from "./sanitize-unicode-Ds14l9Om.js";
7
+ import { n as normalizeProviderError, t as formatProviderError } from "./error-body-CyiejW4b.js";
8
+ import { a as mapStopReason, c as retainThoughtSignature, d as toGoogleSdkThinkingLevel, f as toGoogleThinkingLevel, h as ResourceScope, i as isThinkingPart, l as retryGoogleRequest, m as GoogleGenAI, n as convertTools, o as resolveGoogleFunctionCallingMode, p as usesGoogleThinkingLevel, r as getDisabledGoogleThinkingConfig, s as resolveGoogleThinkingLevel, t as convertMessages, u as supportsGoogleStrictToolSampling } from "./google-shared-0gpM2jFi.js";
9
+ //#region node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js
10
+ const API_VERSION = "v1";
11
+ const GCP_VERTEX_CREDENTIALS_MARKER = "gcp-vertex-credentials";
12
+ let toolCallCounter = 0;
13
+ const stream = (model, context, options) => {
14
+ const stream = new AssistantMessageEventStream();
15
+ const normalizedContext = collapseSystemMessages(context);
16
+ (async () => {
17
+ const output = {
18
+ role: "assistant",
19
+ content: [],
20
+ api: "google-vertex",
21
+ provider: model.provider,
22
+ model: model.id,
23
+ usage: {
24
+ input: 0,
25
+ output: 0,
26
+ cacheRead: 0,
27
+ cacheWrite: 0,
28
+ totalTokens: 0,
29
+ cost: {
30
+ input: 0,
31
+ output: 0,
32
+ cacheRead: 0,
33
+ cacheWrite: 0,
34
+ total: 0
35
+ }
36
+ },
37
+ stopReason: "pending",
38
+ timestamp: Date.now()
39
+ };
40
+ try {
41
+ if (options?.fetch && options.fetch !== globalThis.fetch) throw new Error("Custom fetch is not supported by the Google Vertex adapter");
42
+ const apiKey = resolveApiKey(options);
43
+ const client = apiKey ? createClientWithApiKey(model, apiKey, options?.headers) : createClient(model, resolveProject(options), resolveLocation(options), options?.headers, options?.env);
44
+ let params = buildParams(model, normalizedContext, options);
45
+ const nextParams = await options?.onPayload?.(params, model);
46
+ if (nextParams !== void 0) params = nextParams;
47
+ const googleStream = await retryGoogleRequest(() => client.models.generateContentStream(params), options);
48
+ stream.push({
49
+ type: "start",
50
+ partial: output
51
+ });
52
+ let currentBlock = null;
53
+ const blocks = output.content;
54
+ const blockIndex = () => blocks.length - 1;
55
+ for await (const chunk of googleStream) {
56
+ await options?.onProviderStreamEvent?.(chunk, model);
57
+ output.responseId ||= chunk.responseId;
58
+ const candidate = chunk.candidates?.[0];
59
+ if (candidate?.content?.parts) for (const part of candidate.content.parts) {
60
+ if (part.text !== void 0) {
61
+ const isThinking = isThinkingPart(part);
62
+ if (!currentBlock || isThinking && currentBlock.type !== "thinking" || !isThinking && currentBlock.type !== "text") {
63
+ if (currentBlock) if (currentBlock.type === "text") stream.push({
64
+ type: "text_end",
65
+ contentIndex: blocks.length - 1,
66
+ content: currentBlock.text,
67
+ partial: output
68
+ });
69
+ else stream.push({
70
+ type: "thinking_end",
71
+ contentIndex: blockIndex(),
72
+ content: currentBlock.thinking,
73
+ partial: output
74
+ });
75
+ if (isThinking) {
76
+ currentBlock = {
77
+ type: "thinking",
78
+ thinking: "",
79
+ thinkingSignature: void 0
80
+ };
81
+ output.content.push(currentBlock);
82
+ stream.push({
83
+ type: "thinking_start",
84
+ contentIndex: blockIndex(),
85
+ partial: output
86
+ });
87
+ } else {
88
+ currentBlock = {
89
+ type: "text",
90
+ text: ""
91
+ };
92
+ output.content.push(currentBlock);
93
+ stream.push({
94
+ type: "text_start",
95
+ contentIndex: blockIndex(),
96
+ partial: output
97
+ });
98
+ }
99
+ }
100
+ if (currentBlock.type === "thinking") {
101
+ currentBlock.thinking += part.text;
102
+ currentBlock.thinkingSignature = retainThoughtSignature(currentBlock.thinkingSignature, part.thoughtSignature);
103
+ stream.push({
104
+ type: "thinking_delta",
105
+ contentIndex: blockIndex(),
106
+ delta: part.text,
107
+ partial: output
108
+ });
109
+ } else {
110
+ currentBlock.text += part.text;
111
+ currentBlock.textSignature = retainThoughtSignature(currentBlock.textSignature, part.thoughtSignature);
112
+ stream.push({
113
+ type: "text_delta",
114
+ contentIndex: blockIndex(),
115
+ delta: part.text,
116
+ partial: output
117
+ });
118
+ }
119
+ }
120
+ if (part.functionCall) {
121
+ if (currentBlock) {
122
+ if (currentBlock.type === "text") stream.push({
123
+ type: "text_end",
124
+ contentIndex: blockIndex(),
125
+ content: currentBlock.text,
126
+ partial: output
127
+ });
128
+ else stream.push({
129
+ type: "thinking_end",
130
+ contentIndex: blockIndex(),
131
+ content: currentBlock.thinking,
132
+ partial: output
133
+ });
134
+ currentBlock = null;
135
+ }
136
+ const providedId = part.functionCall.id;
137
+ const toolCall = {
138
+ type: "toolCall",
139
+ id: !providedId || output.content.some((b) => b.type === "toolCall" && b.id === providedId) ? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}` : providedId,
140
+ name: part.functionCall.name || "",
141
+ arguments: part.functionCall.args ?? {},
142
+ ...part.thoughtSignature && { thoughtSignature: part.thoughtSignature }
143
+ };
144
+ output.content.push(toolCall);
145
+ stream.push({
146
+ type: "toolcall_start",
147
+ contentIndex: blockIndex(),
148
+ partial: output
149
+ });
150
+ stream.push({
151
+ type: "toolcall_delta",
152
+ contentIndex: blockIndex(),
153
+ delta: JSON.stringify(toolCall.arguments),
154
+ partial: output
155
+ });
156
+ stream.push({
157
+ type: "toolcall_end",
158
+ contentIndex: blockIndex(),
159
+ toolCall,
160
+ partial: output
161
+ });
162
+ }
163
+ }
164
+ if (candidate?.finishReason) {
165
+ output.rawStopReason = candidate.finishReason;
166
+ output.stopReason = mapStopReason(candidate.finishReason);
167
+ if (output.content.some((b) => b.type === "toolCall") && output.stopReason === "stop") output.stopReason = "toolUse";
168
+ }
169
+ if (chunk.usageMetadata) {
170
+ output.usage = {
171
+ input: (chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),
172
+ output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),
173
+ cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,
174
+ cacheWrite: 0,
175
+ reasoning: chunk.usageMetadata.thoughtsTokenCount || 0,
176
+ totalTokens: chunk.usageMetadata.totalTokenCount || 0,
177
+ cost: {
178
+ input: 0,
179
+ output: 0,
180
+ cacheRead: 0,
181
+ cacheWrite: 0,
182
+ total: 0
183
+ }
184
+ };
185
+ calculateCost(model, output.usage);
186
+ }
187
+ }
188
+ if (currentBlock) if (currentBlock.type === "text") stream.push({
189
+ type: "text_end",
190
+ contentIndex: blockIndex(),
191
+ content: currentBlock.text,
192
+ partial: output
193
+ });
194
+ else stream.push({
195
+ type: "thinking_end",
196
+ contentIndex: blockIndex(),
197
+ content: currentBlock.thinking,
198
+ partial: output
199
+ });
200
+ if (options?.signal?.aborted) throw new Error("Request was aborted");
201
+ if (output.stopReason === "pending") throw new Error("Google Vertex stream ended without a finish reason");
202
+ if (output.stopReason === "aborted" || output.stopReason === "error") {
203
+ const errorMessage = output.rawStopReason ? `Provider stopped with: ${output.rawStopReason}` : "An unknown error occurred";
204
+ throw new Error(errorMessage);
205
+ }
206
+ stream.push({
207
+ type: "done",
208
+ reason: output.stopReason,
209
+ message: output
210
+ });
211
+ stream.end();
212
+ } catch (error) {
213
+ for (const block of output.content) if ("index" in block) delete block.index;
214
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
215
+ output.errorMessage = formatProviderError(normalizeProviderError(error));
216
+ stream.push({
217
+ type: "error",
218
+ reason: output.stopReason,
219
+ error: output
220
+ });
221
+ stream.end();
222
+ }
223
+ })();
224
+ return stream;
225
+ };
226
+ const streamSimple = (model, context, options) => {
227
+ const base = {
228
+ ...buildBaseOptions(model, context, options, void 0),
229
+ toolChoice: options?.toolChoice
230
+ };
231
+ if (!options?.reasoning) return stream(model, context, {
232
+ ...base,
233
+ thinking: { enabled: false }
234
+ });
235
+ const clampedReasoning = clampThinkingLevel(model, options.reasoning);
236
+ if (clampedReasoning === "off") return stream(model, context, {
237
+ ...base,
238
+ thinking: { enabled: false }
239
+ });
240
+ const resolvedLevel = resolveGoogleThinkingLevel(model, clampedReasoning);
241
+ if (usesGoogleThinkingLevel(model)) return stream(model, context, {
242
+ ...base,
243
+ thinking: {
244
+ enabled: true,
245
+ level: toGoogleThinkingLevel(resolvedLevel)
246
+ }
247
+ });
248
+ return stream(model, context, {
249
+ ...base,
250
+ thinking: {
251
+ enabled: true,
252
+ budgetTokens: getGoogleBudget(model, resolvedLevel, options.thinkingBudgets)
253
+ }
254
+ });
255
+ };
256
+ function createClient(model, project, location, optionsHeaders, env) {
257
+ const googleAuthOptions = buildGoogleAuthOptions(env);
258
+ return new GoogleGenAI({
259
+ vertexai: true,
260
+ project,
261
+ location,
262
+ apiVersion: API_VERSION,
263
+ ...googleAuthOptions ? { googleAuthOptions } : {},
264
+ httpOptions: buildHttpOptions(model, optionsHeaders)
265
+ });
266
+ }
267
+ function createClientWithApiKey(model, apiKey, optionsHeaders) {
268
+ return new GoogleGenAI({
269
+ vertexai: true,
270
+ apiKey,
271
+ apiVersion: API_VERSION,
272
+ httpOptions: buildHttpOptions(model, optionsHeaders)
273
+ });
274
+ }
275
+ function buildHttpOptions(model, optionsHeaders) {
276
+ const httpOptions = {};
277
+ const baseUrl = resolveCustomBaseUrl(model.baseUrl);
278
+ if (baseUrl) {
279
+ httpOptions.baseUrl = baseUrl;
280
+ httpOptions.baseUrlResourceScope = ResourceScope.COLLECTION;
281
+ if (baseUrlIncludesApiVersion(baseUrl)) httpOptions.apiVersion = "";
282
+ }
283
+ const headers = providerHeadersToRecord({
284
+ "User-Agent": getPiUserAgent(),
285
+ ...model.headers,
286
+ ...optionsHeaders
287
+ });
288
+ if (headers) httpOptions.headers = headers;
289
+ return Object.keys(httpOptions).length > 0 ? httpOptions : void 0;
290
+ }
291
+ function resolveCustomBaseUrl(baseUrl) {
292
+ const trimmed = baseUrl.trim();
293
+ if (!trimmed || trimmed.includes("{location}")) return;
294
+ return trimmed;
295
+ }
296
+ function baseUrlIncludesApiVersion(baseUrl) {
297
+ try {
298
+ return new URL(baseUrl).pathname.split("/").some((part) => /^v\d+(?:beta\d*)?$/.test(part));
299
+ } catch {
300
+ return /(?:^|\/)v\d+(?:beta\d*)?(?:\/|$)/.test(baseUrl);
301
+ }
302
+ }
303
+ function buildGoogleAuthOptions(env) {
304
+ const keyFilename = getProviderEnvValue("GOOGLE_APPLICATION_CREDENTIALS", env);
305
+ return keyFilename ? { keyFilename } : void 0;
306
+ }
307
+ function resolveApiKey(options) {
308
+ const apiKey = options?.apiKey?.trim();
309
+ if (!apiKey || apiKey === GCP_VERTEX_CREDENTIALS_MARKER || isPlaceholderApiKey(apiKey)) return;
310
+ return apiKey;
311
+ }
312
+ function isPlaceholderApiKey(apiKey) {
313
+ return /^<[^>]+>$/.test(apiKey);
314
+ }
315
+ function resolveProject(options) {
316
+ const project = options?.project || getProviderEnvValue("GOOGLE_CLOUD_PROJECT", options?.env) || getProviderEnvValue("GCLOUD_PROJECT", options?.env);
317
+ if (!project) throw new Error("Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.");
318
+ return project;
319
+ }
320
+ function resolveLocation(options) {
321
+ const location = options?.location || getProviderEnvValue("GOOGLE_CLOUD_LOCATION", options?.env);
322
+ if (!location) throw new Error("Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.");
323
+ return location;
324
+ }
325
+ function buildParams(model, context, options = {}) {
326
+ const contents = convertMessages(model, context);
327
+ const initialSystemMessage = getInitialSystemMessage(context.messages);
328
+ const currentTools = getCurrentTools(context.messages);
329
+ const generationConfig = {};
330
+ if (options.temperature !== void 0) generationConfig.temperature = options.temperature;
331
+ if (options.maxTokens !== void 0) generationConfig.maxOutputTokens = options.maxTokens;
332
+ const supportsStrictMode = supportsGoogleStrictToolSampling(model.id);
333
+ const functionCallingMode = currentTools.length > 0 ? resolveGoogleFunctionCallingMode(currentTools, options.toolChoice, supportsStrictMode) : void 0;
334
+ const systemInstruction = initialSystemMessage ? getSystemMessageText(initialSystemMessage) : "";
335
+ const config = {
336
+ ...Object.keys(generationConfig).length > 0 && generationConfig,
337
+ ...systemInstruction && { systemInstruction: sanitizeSurrogates(systemInstruction) },
338
+ ...currentTools.length > 0 && { tools: convertTools(currentTools, false, supportsStrictMode) },
339
+ ...functionCallingMode !== void 0 && { toolConfig: { functionCallingConfig: { mode: functionCallingMode } } }
340
+ };
341
+ if (options.thinking?.enabled && model.reasoning) {
342
+ const thinkingConfig = { includeThoughts: true };
343
+ if (options.thinking.level !== void 0) thinkingConfig.thinkingLevel = toGoogleSdkThinkingLevel(options.thinking.level);
344
+ else if (options.thinking.budgetTokens !== void 0) thinkingConfig.thinkingBudget = options.thinking.budgetTokens;
345
+ config.thinkingConfig = thinkingConfig;
346
+ } else if (model.reasoning && options.thinking && !options.thinking.enabled) config.thinkingConfig = getDisabledGoogleThinkingConfig(model);
347
+ if (options.signal) {
348
+ if (options.signal.aborted) throw new Error("Request aborted");
349
+ config.abortSignal = options.signal;
350
+ }
351
+ return {
352
+ model: model.id,
353
+ contents,
354
+ config
355
+ };
356
+ }
357
+ function getGoogleBudget(model, level, customBudgets) {
358
+ if (customBudgets?.[level] !== void 0) return customBudgets[level];
359
+ if (model.id.includes("2.5-pro")) return {
360
+ minimal: 128,
361
+ low: 2048,
362
+ medium: 8192,
363
+ high: 32768
364
+ }[level];
365
+ if (model.id.includes("2.5-flash")) return {
366
+ minimal: 128,
367
+ low: 2048,
368
+ medium: 8192,
369
+ high: 24576
370
+ }[level];
371
+ return -1;
372
+ }
373
+ //#endregion
374
+ export { stream, streamSimple };
375
+
376
+ //# sourceMappingURL=google-vertex-D8Eb5cbu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-vertex-D8Eb5cbu.js","names":[],"sources":["../node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js"],"sourcesContent":["import { GoogleGenAI, ResourceScope, } from \"@google/genai\";\nimport { calculateCost, clampThinkingLevel } from \"../models.js\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.js\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.js\";\nimport { providerHeadersToRecord } from \"../utils/headers.js\";\nimport { getPiUserAgent } from \"../utils/pi-user-agent.js\";\nimport { getProviderEnvValue } from \"../utils/provider-env.js\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.js\";\nimport { getSystemMessageText } from \"../utils/text.js\";\nimport { collapseSystemMessages, getCurrentTools, getInitialSystemMessage } from \"../utils/transcript.js\";\nimport { convertMessages, convertTools, getDisabledGoogleThinkingConfig, isThinkingPart, mapStopReason, resolveGoogleFunctionCallingMode, resolveGoogleThinkingLevel, retainThoughtSignature, retryGoogleRequest, supportsGoogleStrictToolSampling, toGoogleSdkThinkingLevel, toGoogleThinkingLevel, usesGoogleThinkingLevel, } from \"./google-shared.js\";\nimport { buildBaseOptions } from \"./simple-options.js\";\nconst API_VERSION = \"v1\";\nconst GCP_VERTEX_CREDENTIALS_MARKER = \"gcp-vertex-credentials\";\n// Counter for generating unique tool call IDs\nlet toolCallCounter = 0;\nexport const stream = (model, context, options) => {\n const stream = new AssistantMessageEventStream();\n const normalizedContext = collapseSystemMessages(context);\n (async () => {\n const output = {\n role: \"assistant\",\n content: [],\n api: \"google-vertex\",\n provider: model.provider,\n model: model.id,\n usage: {\n input: 0,\n output: 0,\n cacheRead: 0,\n cacheWrite: 0,\n totalTokens: 0,\n cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n },\n stopReason: \"pending\",\n timestamp: Date.now(),\n };\n try {\n if (options?.fetch && options.fetch !== globalThis.fetch) {\n throw new Error(\"Custom fetch is not supported by the Google Vertex adapter\");\n }\n const apiKey = resolveApiKey(options);\n // Create the client using either a Vertex API key, if provided, or ADC with project and location\n const client = apiKey\n ? createClientWithApiKey(model, apiKey, options?.headers)\n : createClient(model, resolveProject(options), resolveLocation(options), options?.headers, options?.env);\n let params = buildParams(model, normalizedContext, options);\n const nextParams = await options?.onPayload?.(params, model);\n if (nextParams !== undefined) {\n params = nextParams;\n }\n const googleStream = await retryGoogleRequest(() => client.models.generateContentStream(params), options);\n stream.push({ type: \"start\", partial: output });\n let currentBlock = null;\n const blocks = output.content;\n const blockIndex = () => blocks.length - 1;\n for await (const chunk of googleStream) {\n await options?.onProviderStreamEvent?.(chunk, model);\n // Vertex uses the same @google/genai GenerateContentResponse type as Gemini.\n // responseId is documented there as an output-only identifier for each response.\n output.responseId ||= chunk.responseId;\n const candidate = chunk.candidates?.[0];\n if (candidate?.content?.parts) {\n for (const part of candidate.content.parts) {\n if (part.text !== undefined) {\n const isThinking = isThinkingPart(part);\n if (!currentBlock ||\n (isThinking && currentBlock.type !== \"thinking\") ||\n (!isThinking && currentBlock.type !== \"text\")) {\n if (currentBlock) {\n if (currentBlock.type === \"text\") {\n stream.push({\n type: \"text_end\",\n contentIndex: blocks.length - 1,\n content: currentBlock.text,\n partial: output,\n });\n }\n else {\n stream.push({\n type: \"thinking_end\",\n contentIndex: blockIndex(),\n content: currentBlock.thinking,\n partial: output,\n });\n }\n }\n if (isThinking) {\n currentBlock = { type: \"thinking\", thinking: \"\", thinkingSignature: undefined };\n output.content.push(currentBlock);\n stream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n }\n else {\n currentBlock = { type: \"text\", text: \"\" };\n output.content.push(currentBlock);\n stream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n }\n }\n if (currentBlock.type === \"thinking\") {\n currentBlock.thinking += part.text;\n currentBlock.thinkingSignature = retainThoughtSignature(currentBlock.thinkingSignature, part.thoughtSignature);\n stream.push({\n type: \"thinking_delta\",\n contentIndex: blockIndex(),\n delta: part.text,\n partial: output,\n });\n }\n else {\n currentBlock.text += part.text;\n currentBlock.textSignature = retainThoughtSignature(currentBlock.textSignature, part.thoughtSignature);\n stream.push({\n type: \"text_delta\",\n contentIndex: blockIndex(),\n delta: part.text,\n partial: output,\n });\n }\n }\n if (part.functionCall) {\n if (currentBlock) {\n if (currentBlock.type === \"text\") {\n stream.push({\n type: \"text_end\",\n contentIndex: blockIndex(),\n content: currentBlock.text,\n partial: output,\n });\n }\n else {\n stream.push({\n type: \"thinking_end\",\n contentIndex: blockIndex(),\n content: currentBlock.thinking,\n partial: output,\n });\n }\n currentBlock = null;\n }\n const providedId = part.functionCall.id;\n const needsNewId = !providedId || output.content.some((b) => b.type === \"toolCall\" && b.id === providedId);\n const toolCallId = needsNewId\n ? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`\n : providedId;\n const toolCall = {\n type: \"toolCall\",\n id: toolCallId,\n name: part.functionCall.name || \"\",\n arguments: part.functionCall.args ?? {},\n ...(part.thoughtSignature && { thoughtSignature: part.thoughtSignature }),\n };\n output.content.push(toolCall);\n stream.push({ type: \"toolcall_start\", contentIndex: blockIndex(), partial: output });\n stream.push({\n type: \"toolcall_delta\",\n contentIndex: blockIndex(),\n delta: JSON.stringify(toolCall.arguments),\n partial: output,\n });\n stream.push({ type: \"toolcall_end\", contentIndex: blockIndex(), toolCall, partial: output });\n }\n }\n }\n if (candidate?.finishReason) {\n output.rawStopReason = candidate.finishReason;\n output.stopReason = mapStopReason(candidate.finishReason);\n if (output.content.some((b) => b.type === \"toolCall\") && output.stopReason === \"stop\") {\n output.stopReason = \"toolUse\";\n }\n }\n if (chunk.usageMetadata) {\n output.usage = {\n input: (chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),\n output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),\n cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,\n cacheWrite: 0,\n reasoning: chunk.usageMetadata.thoughtsTokenCount || 0,\n totalTokens: chunk.usageMetadata.totalTokenCount || 0,\n cost: {\n input: 0,\n output: 0,\n cacheRead: 0,\n cacheWrite: 0,\n total: 0,\n },\n };\n calculateCost(model, output.usage);\n }\n }\n if (currentBlock) {\n if (currentBlock.type === \"text\") {\n stream.push({\n type: \"text_end\",\n contentIndex: blockIndex(),\n content: currentBlock.text,\n partial: output,\n });\n }\n else {\n stream.push({\n type: \"thinking_end\",\n contentIndex: blockIndex(),\n content: currentBlock.thinking,\n partial: output,\n });\n }\n }\n if (options?.signal?.aborted) {\n throw new Error(\"Request was aborted\");\n }\n if (output.stopReason === \"pending\") {\n throw new Error(\"Google Vertex stream ended without a finish reason\");\n }\n if (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n const errorMessage = output.rawStopReason\n ? `Provider stopped with: ${output.rawStopReason}`\n : \"An unknown error occurred\";\n throw new Error(errorMessage);\n }\n stream.push({ type: \"done\", reason: output.stopReason, message: output });\n stream.end();\n }\n catch (error) {\n // Remove internal index property used during streaming\n for (const block of output.content) {\n if (\"index\" in block) {\n delete block.index;\n }\n }\n output.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n output.errorMessage = formatProviderError(normalizeProviderError(error));\n stream.push({ type: \"error\", reason: output.stopReason, error: output });\n stream.end();\n }\n })();\n return stream;\n};\nexport const streamSimple = (model, context, options) => {\n const base = {\n ...buildBaseOptions(model, context, options, undefined),\n toolChoice: options?.toolChoice,\n };\n if (!options?.reasoning) {\n return stream(model, context, {\n ...base,\n thinking: { enabled: false },\n });\n }\n const clampedReasoning = clampThinkingLevel(model, options.reasoning);\n if (clampedReasoning === \"off\") {\n return stream(model, context, {\n ...base,\n thinking: { enabled: false },\n });\n }\n const resolvedLevel = resolveGoogleThinkingLevel(model, clampedReasoning);\n if (usesGoogleThinkingLevel(model)) {\n return stream(model, context, {\n ...base,\n thinking: {\n enabled: true,\n level: toGoogleThinkingLevel(resolvedLevel),\n },\n });\n }\n return stream(model, context, {\n ...base,\n thinking: {\n enabled: true,\n budgetTokens: getGoogleBudget(model, resolvedLevel, options.thinkingBudgets),\n },\n });\n};\nfunction createClient(model, project, location, optionsHeaders, env) {\n const googleAuthOptions = buildGoogleAuthOptions(env);\n return new GoogleGenAI({\n vertexai: true,\n project,\n location,\n apiVersion: API_VERSION,\n ...(googleAuthOptions ? { googleAuthOptions } : {}),\n httpOptions: buildHttpOptions(model, optionsHeaders),\n });\n}\nfunction createClientWithApiKey(model, apiKey, optionsHeaders) {\n return new GoogleGenAI({\n vertexai: true,\n apiKey,\n apiVersion: API_VERSION,\n httpOptions: buildHttpOptions(model, optionsHeaders),\n });\n}\nfunction buildHttpOptions(model, optionsHeaders) {\n const httpOptions = {};\n const baseUrl = resolveCustomBaseUrl(model.baseUrl);\n if (baseUrl) {\n httpOptions.baseUrl = baseUrl;\n httpOptions.baseUrlResourceScope = ResourceScope.COLLECTION;\n if (baseUrlIncludesApiVersion(baseUrl)) {\n httpOptions.apiVersion = \"\";\n }\n }\n const headers = providerHeadersToRecord({ \"User-Agent\": getPiUserAgent(), ...model.headers, ...optionsHeaders });\n if (headers) {\n httpOptions.headers = headers;\n }\n return Object.keys(httpOptions).length > 0 ? httpOptions : undefined;\n}\nfunction resolveCustomBaseUrl(baseUrl) {\n const trimmed = baseUrl.trim();\n if (!trimmed || trimmed.includes(\"{location}\")) {\n return undefined;\n }\n return trimmed;\n}\nfunction baseUrlIncludesApiVersion(baseUrl) {\n try {\n const url = new URL(baseUrl);\n return url.pathname.split(\"/\").some((part) => /^v\\d+(?:beta\\d*)?$/.test(part));\n }\n catch {\n return /(?:^|\\/)v\\d+(?:beta\\d*)?(?:\\/|$)/.test(baseUrl);\n }\n}\nfunction buildGoogleAuthOptions(env) {\n const keyFilename = getProviderEnvValue(\"GOOGLE_APPLICATION_CREDENTIALS\", env);\n return keyFilename ? { keyFilename } : undefined;\n}\nfunction resolveApiKey(options) {\n const apiKey = options?.apiKey?.trim();\n if (!apiKey || apiKey === GCP_VERTEX_CREDENTIALS_MARKER || isPlaceholderApiKey(apiKey)) {\n return undefined;\n }\n return apiKey;\n}\nfunction isPlaceholderApiKey(apiKey) {\n return /^<[^>]+>$/.test(apiKey);\n}\nfunction resolveProject(options) {\n const project = options?.project ||\n getProviderEnvValue(\"GOOGLE_CLOUD_PROJECT\", options?.env) ||\n getProviderEnvValue(\"GCLOUD_PROJECT\", options?.env);\n if (!project) {\n throw new Error(\"Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.\");\n }\n return project;\n}\nfunction resolveLocation(options) {\n const location = options?.location || getProviderEnvValue(\"GOOGLE_CLOUD_LOCATION\", options?.env);\n if (!location) {\n throw new Error(\"Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.\");\n }\n return location;\n}\nfunction buildParams(model, context, options = {}) {\n const contents = convertMessages(model, context);\n const initialSystemMessage = getInitialSystemMessage(context.messages);\n const currentTools = getCurrentTools(context.messages);\n const generationConfig = {};\n if (options.temperature !== undefined) {\n generationConfig.temperature = options.temperature;\n }\n if (options.maxTokens !== undefined) {\n generationConfig.maxOutputTokens = options.maxTokens;\n }\n const supportsStrictMode = supportsGoogleStrictToolSampling(model.id);\n const functionCallingMode = currentTools.length > 0\n ? resolveGoogleFunctionCallingMode(currentTools, options.toolChoice, supportsStrictMode)\n : undefined;\n const systemInstruction = initialSystemMessage ? getSystemMessageText(initialSystemMessage) : \"\";\n const config = {\n ...(Object.keys(generationConfig).length > 0 && generationConfig),\n ...(systemInstruction && { systemInstruction: sanitizeSurrogates(systemInstruction) }),\n ...(currentTools.length > 0 && {\n tools: convertTools(currentTools, false, supportsStrictMode),\n }),\n ...(functionCallingMode !== undefined && {\n toolConfig: { functionCallingConfig: { mode: functionCallingMode } },\n }),\n };\n if (options.thinking?.enabled && model.reasoning) {\n const thinkingConfig = { includeThoughts: true };\n if (options.thinking.level !== undefined) {\n thinkingConfig.thinkingLevel = toGoogleSdkThinkingLevel(options.thinking.level);\n }\n else if (options.thinking.budgetTokens !== undefined) {\n thinkingConfig.thinkingBudget = options.thinking.budgetTokens;\n }\n config.thinkingConfig = thinkingConfig;\n }\n else if (model.reasoning && options.thinking && !options.thinking.enabled) {\n config.thinkingConfig = getDisabledGoogleThinkingConfig(model);\n }\n if (options.signal) {\n if (options.signal.aborted) {\n throw new Error(\"Request aborted\");\n }\n config.abortSignal = options.signal;\n }\n const params = {\n model: model.id,\n contents,\n config,\n };\n return params;\n}\nfunction getGoogleBudget(model, level, customBudgets) {\n if (customBudgets?.[level] !== undefined) {\n return customBudgets[level];\n }\n if (model.id.includes(\"2.5-pro\")) {\n const budgets = {\n minimal: 128,\n low: 2048,\n medium: 8192,\n high: 32768,\n };\n return budgets[level];\n }\n if (model.id.includes(\"2.5-flash\")) {\n const budgets = {\n minimal: 128,\n low: 2048,\n medium: 8192,\n high: 24576,\n };\n return budgets[level];\n }\n return -1;\n}\n//# sourceMappingURL=google-vertex.js.map"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;AAYA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GAO3B,OAAO;EALH,SAAS;EACT,KAAK;EACL,QAAQ;EACR,MAAM;CAEG,EAAE;CAEnB,IAAI,MAAM,GAAG,SAAS,WAAW,GAO7B,OAAO;EALH,SAAS;EACT,KAAK;EACL,QAAQ;EACR,MAAM;CAEG,EAAE;CAEnB,OAAO;AACX"}
@@ -0,0 +1,18 @@
1
+ //#region node_modules/@earendil-works/pi-ai/dist/utils/hash.js
2
+ /** Fast deterministic hash to shorten long strings */
3
+ function shortHash(str) {
4
+ let h1 = 3735928559;
5
+ let h2 = 1103547991;
6
+ for (let i = 0; i < str.length; i++) {
7
+ const ch = str.charCodeAt(i);
8
+ h1 = Math.imul(h1 ^ ch, 2654435761);
9
+ h2 = Math.imul(h2 ^ ch, 1597334677);
10
+ }
11
+ h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
12
+ h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
13
+ return (h2 >>> 0).toString(36) + (h1 >>> 0).toString(36);
14
+ }
15
+ //#endregion
16
+ export { shortHash as t };
17
+
18
+ //# sourceMappingURL=hash-Dp7EzZUo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-Dp7EzZUo.js","names":[],"sources":["../node_modules/@earendil-works/pi-ai/dist/utils/hash.js"],"sourcesContent":["/** Fast deterministic hash to shorten long strings */\nexport function shortHash(str) {\n let h1 = 0xdeadbeef;\n let h2 = 0x41c6ce57;\n for (let i = 0; i < str.length; i++) {\n const ch = str.charCodeAt(i);\n h1 = Math.imul(h1 ^ ch, 2654435761);\n h2 = Math.imul(h2 ^ ch, 1597334677);\n }\n h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);\n h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);\n return (h2 >>> 0).toString(36) + (h1 >>> 0).toString(36);\n}\n//# sourceMappingURL=hash.js.map"],"x_google_ignoreList":[0],"mappings":";;AACA,SAAgB,UAAU,KAAK;CAC3B,IAAI,KAAK;CACT,IAAI,KAAK;CACT,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;EACjC,MAAM,KAAK,IAAI,WAAW,CAAC;EAC3B,KAAK,KAAK,KAAK,KAAK,IAAI,UAAU;EAClC,KAAK,KAAK,KAAK,KAAK,IAAI,UAAU;CACtC;CACA,KAAK,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU,IAAI,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU;CACrF,KAAK,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU,IAAI,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU;CACrF,QAAQ,OAAO,EAAA,CAAG,SAAS,EAAE,KAAK,OAAO,EAAA,CAAG,SAAS,EAAE;AAC3D"}
@@ -0,0 +1,19 @@
1
+ //#region node_modules/@earendil-works/pi-ai/dist/utils/headers.js
2
+ function headersToRecord(headers) {
3
+ const result = {};
4
+ for (const [key, value] of headers.entries()) result[key] = value;
5
+ return result;
6
+ }
7
+ function providerHeadersToRecord(...headerSources) {
8
+ const merged = /* @__PURE__ */ new Map();
9
+ for (const source of headerSources) for (const [name, value] of Object.entries(source ?? {})) {
10
+ const normalizedName = name.toLowerCase();
11
+ merged.delete(normalizedName);
12
+ if (value !== null) merged.set(normalizedName, [name, value]);
13
+ }
14
+ return merged.size > 0 ? Object.fromEntries(merged.values()) : void 0;
15
+ }
16
+ //#endregion
17
+ export { providerHeadersToRecord as n, headersToRecord as t };
18
+
19
+ //# sourceMappingURL=headers-BRNMVpzu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers-BRNMVpzu.js","names":[],"sources":["../node_modules/@earendil-works/pi-ai/dist/utils/headers.js"],"sourcesContent":["export function headersToRecord(headers) {\n const result = {};\n for (const [key, value] of headers.entries()) {\n result[key] = value;\n }\n return result;\n}\nexport function providerHeadersToRecord(...headerSources) {\n const merged = new Map();\n for (const source of headerSources) {\n for (const [name, value] of Object.entries(source ?? {})) {\n const normalizedName = name.toLowerCase();\n merged.delete(normalizedName);\n if (value !== null)\n merged.set(normalizedName, [name, value]);\n }\n }\n return merged.size > 0 ? Object.fromEntries(merged.values()) : undefined;\n}\n//# sourceMappingURL=headers.js.map"],"x_google_ignoreList":[0],"mappings":";AAAA,SAAgB,gBAAgB,SAAS;CACrC,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,CAAC,KAAK,UAAU,QAAQ,QAAQ,GACvC,OAAO,OAAO;CAElB,OAAO;AACX;AACA,SAAgB,wBAAwB,GAAG,eAAe;CACtD,MAAM,yBAAS,IAAI,IAAI;CACvB,KAAK,MAAM,UAAU,eACjB,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,UAAU,CAAC,CAAC,GAAG;EACtD,MAAM,iBAAiB,KAAK,YAAY;EACxC,OAAO,OAAO,cAAc;EAC5B,IAAI,UAAU,MACV,OAAO,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC;CAChD;CAEJ,OAAO,OAAO,OAAO,IAAI,OAAO,YAAY,OAAO,OAAO,CAAC,IAAI,KAAA;AACnE"}