linkque-cli-v2 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/linkquejs.js +27 -2212
- package/package.json +4 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/anthropic-messages-B5T6TFD2.js +7172 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/azure-openai-responses-S7HNQOSE.js +229 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-2NGJGNYB.js +1765 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-3S3TOEBZ.js +608 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-46SEH6ER.js +78 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-52BVDZQ2.js +60299 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-6MHDOBWO.js +12 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-6WHNFJT4.js +31278 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-7BQRUS4C.js +671 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-7QWAKKTY.js +7054 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-CT4G24PS.js +8 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-DYEQRE6N.js +343 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-E2P6TIFG.js +31 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-FHNQ6DPF.js +14 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-HTG7JBF2.js +38 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-I64V3ICJ.js +11166 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-IKZ25GJD.js +497 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-MKS245OU.js +3570 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-NKEOCGYU.js +76 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-NQM5ZCTR.js +12015 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-OXGCUIKV.js +33 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-RYONFGPP.js +317 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-UEVQXSKG.js +4765 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-UFVAKOTZ.js +17 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-VS2QQHAK.js +46 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-XMVFOHGJ.js +31 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-XUFLSZM4.js +5319 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-Y6UTJIT4.js +23 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-YDKZZ6EH.js +3584 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/dist-QD3CV4KC.js +1224 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/google-generative-ai-IOXNKFEV.js +412 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/google-vertex-U4ZV5IXZ.js +461 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/mistral-conversations-G3K7SSWR.js +30344 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/multipart-parser-2VJ7LVQD.js +170 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/multipart-parser-AJMV6U6H.js +178 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/multipart-parser-PULXGNYO.js +368 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/openai-codex-responses-4JJLPTCS.js +1308 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/openai-completions-PH4WW6E7.js +977 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/openai-responses-KGWAX6HR.js +264 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/openrouter-images-LMBZZQ76.js +138 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/otel-7GSG7QQO.js +6657 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/pi-messages-ZX3KUWSZ.js +309 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +2354 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +16 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +17 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/src-NGZW4JXI.js +1396 -0
- package/vendor/linkque-agent-appwrite-integrate/package.json +1 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GoogleGenAI,
|
|
3
|
+
ResourceScope,
|
|
4
|
+
ThinkingLevel,
|
|
5
|
+
convertMessages,
|
|
6
|
+
convertTools,
|
|
7
|
+
isThinkingPart,
|
|
8
|
+
mapStopReason,
|
|
9
|
+
mapToolChoice,
|
|
10
|
+
retainThoughtSignature
|
|
11
|
+
} from "./chunk-6WHNFJT4.js";
|
|
12
|
+
import "./chunk-2NGJGNYB.js";
|
|
13
|
+
import {
|
|
14
|
+
formatProviderError,
|
|
15
|
+
normalizeProviderError
|
|
16
|
+
} from "./chunk-NKEOCGYU.js";
|
|
17
|
+
import {
|
|
18
|
+
buildBaseOptions
|
|
19
|
+
} from "./chunk-RYONFGPP.js";
|
|
20
|
+
import {
|
|
21
|
+
sanitizeSurrogates
|
|
22
|
+
} from "./chunk-CT4G24PS.js";
|
|
23
|
+
import {
|
|
24
|
+
providerHeadersToRecord
|
|
25
|
+
} from "./chunk-Y6UTJIT4.js";
|
|
26
|
+
import {
|
|
27
|
+
calculateCost,
|
|
28
|
+
clampThinkingLevel
|
|
29
|
+
} from "./chunk-3S3TOEBZ.js";
|
|
30
|
+
import {
|
|
31
|
+
getProviderEnvValue
|
|
32
|
+
} from "./chunk-OXGCUIKV.js";
|
|
33
|
+
import {
|
|
34
|
+
AssistantMessageEventStream
|
|
35
|
+
} from "./chunk-46SEH6ER.js";
|
|
36
|
+
import "./chunk-VS2QQHAK.js";
|
|
37
|
+
|
|
38
|
+
// ../../node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js
|
|
39
|
+
var API_VERSION = "v1";
|
|
40
|
+
var GCP_VERTEX_CREDENTIALS_MARKER = "gcp-vertex-credentials";
|
|
41
|
+
var THINKING_LEVEL_MAP = {
|
|
42
|
+
THINKING_LEVEL_UNSPECIFIED: ThinkingLevel.THINKING_LEVEL_UNSPECIFIED,
|
|
43
|
+
MINIMAL: ThinkingLevel.MINIMAL,
|
|
44
|
+
LOW: ThinkingLevel.LOW,
|
|
45
|
+
MEDIUM: ThinkingLevel.MEDIUM,
|
|
46
|
+
HIGH: ThinkingLevel.HIGH
|
|
47
|
+
};
|
|
48
|
+
var toolCallCounter = 0;
|
|
49
|
+
var stream = (model, context, options) => {
|
|
50
|
+
const stream2 = new AssistantMessageEventStream();
|
|
51
|
+
(async () => {
|
|
52
|
+
const output = {
|
|
53
|
+
role: "assistant",
|
|
54
|
+
content: [],
|
|
55
|
+
api: "google-vertex",
|
|
56
|
+
provider: model.provider,
|
|
57
|
+
model: model.id,
|
|
58
|
+
usage: {
|
|
59
|
+
input: 0,
|
|
60
|
+
output: 0,
|
|
61
|
+
cacheRead: 0,
|
|
62
|
+
cacheWrite: 0,
|
|
63
|
+
totalTokens: 0,
|
|
64
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
|
|
65
|
+
},
|
|
66
|
+
stopReason: "stop",
|
|
67
|
+
timestamp: Date.now()
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
const apiKey = resolveApiKey(options);
|
|
71
|
+
const client = apiKey ? createClientWithApiKey(model, apiKey, options?.headers) : createClient(model, resolveProject(options), resolveLocation(options), options?.headers, options?.env);
|
|
72
|
+
let params = buildParams(model, context, options);
|
|
73
|
+
const nextParams = await options?.onPayload?.(params, model);
|
|
74
|
+
if (nextParams !== void 0) {
|
|
75
|
+
params = nextParams;
|
|
76
|
+
}
|
|
77
|
+
const googleStream = await client.models.generateContentStream(params);
|
|
78
|
+
stream2.push({ type: "start", partial: output });
|
|
79
|
+
let currentBlock = null;
|
|
80
|
+
const blocks = output.content;
|
|
81
|
+
const blockIndex = () => blocks.length - 1;
|
|
82
|
+
for await (const chunk of googleStream) {
|
|
83
|
+
output.responseId ||= chunk.responseId;
|
|
84
|
+
const candidate = chunk.candidates?.[0];
|
|
85
|
+
if (candidate?.content?.parts) {
|
|
86
|
+
for (const part of candidate.content.parts) {
|
|
87
|
+
if (part.text !== void 0) {
|
|
88
|
+
const isThinking = isThinkingPart(part);
|
|
89
|
+
if (!currentBlock || isThinking && currentBlock.type !== "thinking" || !isThinking && currentBlock.type !== "text") {
|
|
90
|
+
if (currentBlock) {
|
|
91
|
+
if (currentBlock.type === "text") {
|
|
92
|
+
stream2.push({
|
|
93
|
+
type: "text_end",
|
|
94
|
+
contentIndex: blocks.length - 1,
|
|
95
|
+
content: currentBlock.text,
|
|
96
|
+
partial: output
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
stream2.push({
|
|
100
|
+
type: "thinking_end",
|
|
101
|
+
contentIndex: blockIndex(),
|
|
102
|
+
content: currentBlock.thinking,
|
|
103
|
+
partial: output
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (isThinking) {
|
|
108
|
+
currentBlock = { type: "thinking", thinking: "", thinkingSignature: void 0 };
|
|
109
|
+
output.content.push(currentBlock);
|
|
110
|
+
stream2.push({ type: "thinking_start", contentIndex: blockIndex(), partial: output });
|
|
111
|
+
} else {
|
|
112
|
+
currentBlock = { type: "text", text: "" };
|
|
113
|
+
output.content.push(currentBlock);
|
|
114
|
+
stream2.push({ type: "text_start", contentIndex: blockIndex(), partial: output });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (currentBlock.type === "thinking") {
|
|
118
|
+
currentBlock.thinking += part.text;
|
|
119
|
+
currentBlock.thinkingSignature = retainThoughtSignature(currentBlock.thinkingSignature, part.thoughtSignature);
|
|
120
|
+
stream2.push({
|
|
121
|
+
type: "thinking_delta",
|
|
122
|
+
contentIndex: blockIndex(),
|
|
123
|
+
delta: part.text,
|
|
124
|
+
partial: output
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
currentBlock.text += part.text;
|
|
128
|
+
currentBlock.textSignature = retainThoughtSignature(currentBlock.textSignature, part.thoughtSignature);
|
|
129
|
+
stream2.push({
|
|
130
|
+
type: "text_delta",
|
|
131
|
+
contentIndex: blockIndex(),
|
|
132
|
+
delta: part.text,
|
|
133
|
+
partial: output
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (part.functionCall) {
|
|
138
|
+
if (currentBlock) {
|
|
139
|
+
if (currentBlock.type === "text") {
|
|
140
|
+
stream2.push({
|
|
141
|
+
type: "text_end",
|
|
142
|
+
contentIndex: blockIndex(),
|
|
143
|
+
content: currentBlock.text,
|
|
144
|
+
partial: output
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
stream2.push({
|
|
148
|
+
type: "thinking_end",
|
|
149
|
+
contentIndex: blockIndex(),
|
|
150
|
+
content: currentBlock.thinking,
|
|
151
|
+
partial: output
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
currentBlock = null;
|
|
155
|
+
}
|
|
156
|
+
const providedId = part.functionCall.id;
|
|
157
|
+
const needsNewId = !providedId || output.content.some((b) => b.type === "toolCall" && b.id === providedId);
|
|
158
|
+
const toolCallId = needsNewId ? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}` : providedId;
|
|
159
|
+
const toolCall = {
|
|
160
|
+
type: "toolCall",
|
|
161
|
+
id: toolCallId,
|
|
162
|
+
name: part.functionCall.name || "",
|
|
163
|
+
arguments: part.functionCall.args ?? {},
|
|
164
|
+
...part.thoughtSignature && { thoughtSignature: part.thoughtSignature }
|
|
165
|
+
};
|
|
166
|
+
output.content.push(toolCall);
|
|
167
|
+
stream2.push({ type: "toolcall_start", contentIndex: blockIndex(), partial: output });
|
|
168
|
+
stream2.push({
|
|
169
|
+
type: "toolcall_delta",
|
|
170
|
+
contentIndex: blockIndex(),
|
|
171
|
+
delta: JSON.stringify(toolCall.arguments),
|
|
172
|
+
partial: output
|
|
173
|
+
});
|
|
174
|
+
stream2.push({ type: "toolcall_end", contentIndex: blockIndex(), toolCall, partial: output });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (candidate?.finishReason) {
|
|
179
|
+
output.stopReason = mapStopReason(candidate.finishReason);
|
|
180
|
+
if (output.content.some((b) => b.type === "toolCall")) {
|
|
181
|
+
output.stopReason = "toolUse";
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (chunk.usageMetadata) {
|
|
185
|
+
output.usage = {
|
|
186
|
+
input: (chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),
|
|
187
|
+
output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),
|
|
188
|
+
cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,
|
|
189
|
+
cacheWrite: 0,
|
|
190
|
+
reasoning: chunk.usageMetadata.thoughtsTokenCount || 0,
|
|
191
|
+
totalTokens: chunk.usageMetadata.totalTokenCount || 0,
|
|
192
|
+
cost: {
|
|
193
|
+
input: 0,
|
|
194
|
+
output: 0,
|
|
195
|
+
cacheRead: 0,
|
|
196
|
+
cacheWrite: 0,
|
|
197
|
+
total: 0
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
calculateCost(model, output.usage);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (currentBlock) {
|
|
204
|
+
if (currentBlock.type === "text") {
|
|
205
|
+
stream2.push({
|
|
206
|
+
type: "text_end",
|
|
207
|
+
contentIndex: blockIndex(),
|
|
208
|
+
content: currentBlock.text,
|
|
209
|
+
partial: output
|
|
210
|
+
});
|
|
211
|
+
} else {
|
|
212
|
+
stream2.push({
|
|
213
|
+
type: "thinking_end",
|
|
214
|
+
contentIndex: blockIndex(),
|
|
215
|
+
content: currentBlock.thinking,
|
|
216
|
+
partial: output
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (options?.signal?.aborted) {
|
|
221
|
+
throw new Error("Request was aborted");
|
|
222
|
+
}
|
|
223
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") {
|
|
224
|
+
throw new Error("An unknown error occurred");
|
|
225
|
+
}
|
|
226
|
+
stream2.push({ type: "done", reason: output.stopReason, message: output });
|
|
227
|
+
stream2.end();
|
|
228
|
+
} catch (error) {
|
|
229
|
+
for (const block of output.content) {
|
|
230
|
+
if ("index" in block) {
|
|
231
|
+
delete block.index;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
235
|
+
output.errorMessage = formatProviderError(normalizeProviderError(error));
|
|
236
|
+
stream2.push({ type: "error", reason: output.stopReason, error: output });
|
|
237
|
+
stream2.end();
|
|
238
|
+
}
|
|
239
|
+
})();
|
|
240
|
+
return stream2;
|
|
241
|
+
};
|
|
242
|
+
var streamSimple = (model, context, options) => {
|
|
243
|
+
const base = buildBaseOptions(model, context, options, void 0);
|
|
244
|
+
if (!options?.reasoning) {
|
|
245
|
+
return stream(model, context, {
|
|
246
|
+
...base,
|
|
247
|
+
thinking: { enabled: false }
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
const clampedReasoning = clampThinkingLevel(model, options.reasoning);
|
|
251
|
+
const effort = clampedReasoning === "off" ? "high" : clampedReasoning;
|
|
252
|
+
const geminiModel = model;
|
|
253
|
+
if (isGemini3ProModel(geminiModel) || isGemini3FlashModel(geminiModel)) {
|
|
254
|
+
return stream(model, context, {
|
|
255
|
+
...base,
|
|
256
|
+
thinking: {
|
|
257
|
+
enabled: true,
|
|
258
|
+
level: getGemini3ThinkingLevel(effort, geminiModel)
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
return stream(model, context, {
|
|
263
|
+
...base,
|
|
264
|
+
thinking: {
|
|
265
|
+
enabled: true,
|
|
266
|
+
budgetTokens: getGoogleBudget(geminiModel, effort, options.thinkingBudgets)
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
function createClient(model, project, location, optionsHeaders, env) {
|
|
271
|
+
const googleAuthOptions = buildGoogleAuthOptions(env);
|
|
272
|
+
return new GoogleGenAI({
|
|
273
|
+
vertexai: true,
|
|
274
|
+
project,
|
|
275
|
+
location,
|
|
276
|
+
apiVersion: API_VERSION,
|
|
277
|
+
...googleAuthOptions ? { googleAuthOptions } : {},
|
|
278
|
+
httpOptions: buildHttpOptions(model, optionsHeaders)
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
function createClientWithApiKey(model, apiKey, optionsHeaders) {
|
|
282
|
+
return new GoogleGenAI({
|
|
283
|
+
vertexai: true,
|
|
284
|
+
apiKey,
|
|
285
|
+
apiVersion: API_VERSION,
|
|
286
|
+
httpOptions: buildHttpOptions(model, optionsHeaders)
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
function buildHttpOptions(model, optionsHeaders) {
|
|
290
|
+
const httpOptions = {};
|
|
291
|
+
const baseUrl = resolveCustomBaseUrl(model.baseUrl);
|
|
292
|
+
if (baseUrl) {
|
|
293
|
+
httpOptions.baseUrl = baseUrl;
|
|
294
|
+
httpOptions.baseUrlResourceScope = ResourceScope.COLLECTION;
|
|
295
|
+
if (baseUrlIncludesApiVersion(baseUrl)) {
|
|
296
|
+
httpOptions.apiVersion = "";
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const headers = providerHeadersToRecord({ ...model.headers, ...optionsHeaders });
|
|
300
|
+
if (headers) {
|
|
301
|
+
httpOptions.headers = headers;
|
|
302
|
+
}
|
|
303
|
+
return Object.keys(httpOptions).length > 0 ? httpOptions : void 0;
|
|
304
|
+
}
|
|
305
|
+
function resolveCustomBaseUrl(baseUrl) {
|
|
306
|
+
const trimmed = baseUrl.trim();
|
|
307
|
+
if (!trimmed || trimmed.includes("{location}")) {
|
|
308
|
+
return void 0;
|
|
309
|
+
}
|
|
310
|
+
return trimmed;
|
|
311
|
+
}
|
|
312
|
+
function baseUrlIncludesApiVersion(baseUrl) {
|
|
313
|
+
try {
|
|
314
|
+
const url = new URL(baseUrl);
|
|
315
|
+
return url.pathname.split("/").some((part) => /^v\d+(?:beta\d*)?$/.test(part));
|
|
316
|
+
} catch {
|
|
317
|
+
return /(?:^|\/)v\d+(?:beta\d*)?(?:\/|$)/.test(baseUrl);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function buildGoogleAuthOptions(env) {
|
|
321
|
+
const keyFilename = getProviderEnvValue("GOOGLE_APPLICATION_CREDENTIALS", env);
|
|
322
|
+
return keyFilename ? { keyFilename } : void 0;
|
|
323
|
+
}
|
|
324
|
+
function resolveApiKey(options) {
|
|
325
|
+
const apiKey = options?.apiKey?.trim();
|
|
326
|
+
if (!apiKey || apiKey === GCP_VERTEX_CREDENTIALS_MARKER || isPlaceholderApiKey(apiKey)) {
|
|
327
|
+
return void 0;
|
|
328
|
+
}
|
|
329
|
+
return apiKey;
|
|
330
|
+
}
|
|
331
|
+
function isPlaceholderApiKey(apiKey) {
|
|
332
|
+
return /^<[^>]+>$/.test(apiKey);
|
|
333
|
+
}
|
|
334
|
+
function resolveProject(options) {
|
|
335
|
+
const project = options?.project || getProviderEnvValue("GOOGLE_CLOUD_PROJECT", options?.env) || getProviderEnvValue("GCLOUD_PROJECT", options?.env);
|
|
336
|
+
if (!project) {
|
|
337
|
+
throw new Error("Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.");
|
|
338
|
+
}
|
|
339
|
+
return project;
|
|
340
|
+
}
|
|
341
|
+
function resolveLocation(options) {
|
|
342
|
+
const location = options?.location || getProviderEnvValue("GOOGLE_CLOUD_LOCATION", options?.env);
|
|
343
|
+
if (!location) {
|
|
344
|
+
throw new Error("Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.");
|
|
345
|
+
}
|
|
346
|
+
return location;
|
|
347
|
+
}
|
|
348
|
+
function buildParams(model, context, options = {}) {
|
|
349
|
+
const contents = convertMessages(model, context);
|
|
350
|
+
const generationConfig = {};
|
|
351
|
+
if (options.temperature !== void 0) {
|
|
352
|
+
generationConfig.temperature = options.temperature;
|
|
353
|
+
}
|
|
354
|
+
if (options.maxTokens !== void 0) {
|
|
355
|
+
generationConfig.maxOutputTokens = options.maxTokens;
|
|
356
|
+
}
|
|
357
|
+
const config = {
|
|
358
|
+
...Object.keys(generationConfig).length > 0 && generationConfig,
|
|
359
|
+
...context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) },
|
|
360
|
+
...context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }
|
|
361
|
+
};
|
|
362
|
+
if (context.tools && context.tools.length > 0 && options.toolChoice) {
|
|
363
|
+
config.toolConfig = {
|
|
364
|
+
functionCallingConfig: {
|
|
365
|
+
mode: mapToolChoice(options.toolChoice)
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
} else {
|
|
369
|
+
config.toolConfig = void 0;
|
|
370
|
+
}
|
|
371
|
+
if (options.thinking?.enabled && model.reasoning) {
|
|
372
|
+
const thinkingConfig = { includeThoughts: true };
|
|
373
|
+
if (options.thinking.level !== void 0) {
|
|
374
|
+
thinkingConfig.thinkingLevel = THINKING_LEVEL_MAP[options.thinking.level];
|
|
375
|
+
} else if (options.thinking.budgetTokens !== void 0) {
|
|
376
|
+
thinkingConfig.thinkingBudget = options.thinking.budgetTokens;
|
|
377
|
+
}
|
|
378
|
+
config.thinkingConfig = thinkingConfig;
|
|
379
|
+
} else if (model.reasoning && options.thinking && !options.thinking.enabled) {
|
|
380
|
+
config.thinkingConfig = getDisabledThinkingConfig(model);
|
|
381
|
+
}
|
|
382
|
+
if (options.signal) {
|
|
383
|
+
if (options.signal.aborted) {
|
|
384
|
+
throw new Error("Request aborted");
|
|
385
|
+
}
|
|
386
|
+
config.abortSignal = options.signal;
|
|
387
|
+
}
|
|
388
|
+
const params = {
|
|
389
|
+
model: model.id,
|
|
390
|
+
contents,
|
|
391
|
+
config
|
|
392
|
+
};
|
|
393
|
+
return params;
|
|
394
|
+
}
|
|
395
|
+
function isGemini3ProModel(model) {
|
|
396
|
+
return /gemini-3(?:\.\d+)?-pro/.test(model.id.toLowerCase());
|
|
397
|
+
}
|
|
398
|
+
function isGemini3FlashModel(model) {
|
|
399
|
+
const id = model.id.toLowerCase();
|
|
400
|
+
return /gemini-3(?:\.\d+)?-flash/.test(id) || id === "gemini-flash-latest" || id === "gemini-flash-lite-latest";
|
|
401
|
+
}
|
|
402
|
+
function getDisabledThinkingConfig(model) {
|
|
403
|
+
const geminiModel = model;
|
|
404
|
+
if (isGemini3ProModel(geminiModel)) {
|
|
405
|
+
return { thinkingLevel: ThinkingLevel.LOW };
|
|
406
|
+
}
|
|
407
|
+
if (isGemini3FlashModel(geminiModel)) {
|
|
408
|
+
return { thinkingLevel: ThinkingLevel.MINIMAL };
|
|
409
|
+
}
|
|
410
|
+
return { thinkingBudget: 0 };
|
|
411
|
+
}
|
|
412
|
+
function getGemini3ThinkingLevel(effort, model) {
|
|
413
|
+
if (isGemini3ProModel(model)) {
|
|
414
|
+
switch (effort) {
|
|
415
|
+
case "minimal":
|
|
416
|
+
case "low":
|
|
417
|
+
return "LOW";
|
|
418
|
+
case "medium":
|
|
419
|
+
case "high":
|
|
420
|
+
return "HIGH";
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
switch (effort) {
|
|
424
|
+
case "minimal":
|
|
425
|
+
return "MINIMAL";
|
|
426
|
+
case "low":
|
|
427
|
+
return "LOW";
|
|
428
|
+
case "medium":
|
|
429
|
+
return "MEDIUM";
|
|
430
|
+
case "high":
|
|
431
|
+
return "HIGH";
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function getGoogleBudget(model, effort, customBudgets) {
|
|
435
|
+
if (customBudgets?.[effort] !== void 0) {
|
|
436
|
+
return customBudgets[effort];
|
|
437
|
+
}
|
|
438
|
+
if (model.id.includes("2.5-pro")) {
|
|
439
|
+
const budgets = {
|
|
440
|
+
minimal: 128,
|
|
441
|
+
low: 2048,
|
|
442
|
+
medium: 8192,
|
|
443
|
+
high: 32768
|
|
444
|
+
};
|
|
445
|
+
return budgets[effort];
|
|
446
|
+
}
|
|
447
|
+
if (model.id.includes("2.5-flash")) {
|
|
448
|
+
const budgets = {
|
|
449
|
+
minimal: 128,
|
|
450
|
+
low: 2048,
|
|
451
|
+
medium: 8192,
|
|
452
|
+
high: 24576
|
|
453
|
+
};
|
|
454
|
+
return budgets[effort];
|
|
455
|
+
}
|
|
456
|
+
return -1;
|
|
457
|
+
}
|
|
458
|
+
export {
|
|
459
|
+
stream,
|
|
460
|
+
streamSimple
|
|
461
|
+
};
|