linkque-cli-v2 1.0.2-beta.2 → 1.0.2-beta.2026091502

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 (59) hide show
  1. package/README.md +2 -4
  2. package/linkquejs.js +35731 -24242
  3. package/package.json +5 -2
  4. package/vendor/linkque-agent-appwrite-integrate/dist/esm/anthropic-messages-EL2IU4YU.js +7172 -0
  5. package/vendor/linkque-agent-appwrite-integrate/dist/esm/azure-openai-responses-A4XURCOX.js +229 -0
  6. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-2ESYSVXG.js +48 -0
  7. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-46SEH6ER.js +78 -0
  8. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-5LYUFB4C.js +23196 -0
  9. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-6MHDOBWO.js +12 -0
  10. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-737ZCGB2.js +12289 -0
  11. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-7QWAKKTY.js +7054 -0
  12. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-B5XRGKYX.js +33 -0
  13. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-CT4G24PS.js +8 -0
  14. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-E2P6TIFG.js +31 -0
  15. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-ETG6PNHQ.js +1765 -0
  16. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-FC7MJHC3.js +671 -0
  17. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-FHNQ6DPF.js +14 -0
  18. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-G64JTU26.js +20 -0
  19. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-GAYNLDWK.js +11166 -0
  20. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-GQ4TD3EQ.js +31278 -0
  21. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-HM7KNEG3.js +1639 -0
  22. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-HTG7JBF2.js +38 -0
  23. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-IWOFD643.js +3570 -0
  24. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-M235KAEK.js +30 -0
  25. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-NKEOCGYU.js +76 -0
  26. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-PXCGFBV5.js +3584 -0
  27. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-Q2Y6LMNC.js +497 -0
  28. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-RR2GJPNV.js +4765 -0
  29. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-RYONFGPP.js +317 -0
  30. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-UFVAKOTZ.js +17 -0
  31. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-WJHOHUET.js +343 -0
  32. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-XMVFOHGJ.js +31 -0
  33. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-XUFLSZM4.js +5319 -0
  34. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-Y3G4J3TB.js +609 -0
  35. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-Y6UTJIT4.js +23 -0
  36. package/vendor/linkque-agent-appwrite-integrate/dist/esm/dist-TGBYXSBU.js +1224 -0
  37. package/vendor/linkque-agent-appwrite-integrate/dist/esm/getMachineId-bsd-H2ZLZRGB.js +40 -0
  38. package/vendor/linkque-agent-appwrite-integrate/dist/esm/getMachineId-darwin-HUKYR46U.js +39 -0
  39. package/vendor/linkque-agent-appwrite-integrate/dist/esm/getMachineId-linux-M5ZADHBA.js +33 -0
  40. package/vendor/linkque-agent-appwrite-integrate/dist/esm/getMachineId-unsupported-BM5RZZVM.js +23 -0
  41. package/vendor/linkque-agent-appwrite-integrate/dist/esm/getMachineId-win-BQPUF5TW.js +42 -0
  42. package/vendor/linkque-agent-appwrite-integrate/dist/esm/google-generative-ai-ENBYCHYT.js +412 -0
  43. package/vendor/linkque-agent-appwrite-integrate/dist/esm/google-vertex-RIGAEYLC.js +461 -0
  44. package/vendor/linkque-agent-appwrite-integrate/dist/esm/mistral-conversations-TQA2MPJJ.js +30344 -0
  45. package/vendor/linkque-agent-appwrite-integrate/dist/esm/multipart-parser-BXFNUG5H.js +178 -0
  46. package/vendor/linkque-agent-appwrite-integrate/dist/esm/multipart-parser-TAD6XL3Q.js +368 -0
  47. package/vendor/linkque-agent-appwrite-integrate/dist/esm/multipart-parser-ZRVTGJCT.js +170 -0
  48. package/vendor/linkque-agent-appwrite-integrate/dist/esm/openai-codex-responses-WLREQPZK.js +1308 -0
  49. package/vendor/linkque-agent-appwrite-integrate/dist/esm/openai-completions-U6LUBY4P.js +977 -0
  50. package/vendor/linkque-agent-appwrite-integrate/dist/esm/openai-responses-SFZAU5JA.js +264 -0
  51. package/vendor/linkque-agent-appwrite-integrate/dist/esm/openrouter-images-VSKAO4O5.js +138 -0
  52. package/vendor/linkque-agent-appwrite-integrate/dist/esm/otel-RXJWJ2TU.js +5728 -0
  53. package/vendor/linkque-agent-appwrite-integrate/dist/esm/pi-messages-QQA6ZGV2.js +309 -0
  54. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +46018 -0
  55. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +20 -0
  56. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +13 -0
  57. package/vendor/linkque-agent-appwrite-integrate/dist/esm/src-JSJTYJV5.js +1396 -0
  58. package/vendor/linkque-agent-appwrite-integrate/package.json +1 -0
  59. package/worker.js +124589 -104664
@@ -0,0 +1,40 @@
1
+ import {
2
+ require_execAsync
3
+ } from "./chunk-G64JTU26.js";
4
+ import {
5
+ esm_exports,
6
+ init_esm
7
+ } from "./chunk-HM7KNEG3.js";
8
+ import {
9
+ __commonJS,
10
+ __require,
11
+ __toCommonJS
12
+ } from "./chunk-2ESYSVXG.js";
13
+
14
+ // ../../node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/getMachineId-bsd.js
15
+ var require_getMachineId_bsd = __commonJS({
16
+ "../../node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/getMachineId-bsd.js"(exports) {
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.getMachineId = void 0;
19
+ var fs_1 = __require("fs");
20
+ var execAsync_1 = require_execAsync();
21
+ var api_1 = (init_esm(), __toCommonJS(esm_exports));
22
+ async function getMachineId() {
23
+ try {
24
+ const result = await fs_1.promises.readFile("/etc/hostid", { encoding: "utf8" });
25
+ return result.trim();
26
+ } catch (e) {
27
+ api_1.diag.debug(`error reading machine id: ${e}`);
28
+ }
29
+ try {
30
+ const result = await (0, execAsync_1.execAsync)("kenv -q smbios.system.uuid");
31
+ return result.stdout.trim();
32
+ } catch (e) {
33
+ api_1.diag.debug(`error reading machine id: ${e}`);
34
+ }
35
+ return void 0;
36
+ }
37
+ exports.getMachineId = getMachineId;
38
+ }
39
+ });
40
+ export default require_getMachineId_bsd();
@@ -0,0 +1,39 @@
1
+ import {
2
+ require_execAsync
3
+ } from "./chunk-G64JTU26.js";
4
+ import {
5
+ esm_exports,
6
+ init_esm
7
+ } from "./chunk-HM7KNEG3.js";
8
+ import {
9
+ __commonJS,
10
+ __toCommonJS
11
+ } from "./chunk-2ESYSVXG.js";
12
+
13
+ // ../../node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/getMachineId-darwin.js
14
+ var require_getMachineId_darwin = __commonJS({
15
+ "../../node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/getMachineId-darwin.js"(exports) {
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.getMachineId = void 0;
18
+ var execAsync_1 = require_execAsync();
19
+ var api_1 = (init_esm(), __toCommonJS(esm_exports));
20
+ async function getMachineId() {
21
+ try {
22
+ const result = await (0, execAsync_1.execAsync)('ioreg -rd1 -c "IOPlatformExpertDevice"');
23
+ const idLine = result.stdout.split("\n").find((line) => line.includes("IOPlatformUUID"));
24
+ if (!idLine) {
25
+ return void 0;
26
+ }
27
+ const parts = idLine.split('" = "');
28
+ if (parts.length === 2) {
29
+ return parts[1].slice(0, -1);
30
+ }
31
+ } catch (e) {
32
+ api_1.diag.debug(`error reading machine id: ${e}`);
33
+ }
34
+ return void 0;
35
+ }
36
+ exports.getMachineId = getMachineId;
37
+ }
38
+ });
39
+ export default require_getMachineId_darwin();
@@ -0,0 +1,33 @@
1
+ import {
2
+ esm_exports,
3
+ init_esm
4
+ } from "./chunk-HM7KNEG3.js";
5
+ import {
6
+ __commonJS,
7
+ __require,
8
+ __toCommonJS
9
+ } from "./chunk-2ESYSVXG.js";
10
+
11
+ // ../../node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/getMachineId-linux.js
12
+ var require_getMachineId_linux = __commonJS({
13
+ "../../node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/getMachineId-linux.js"(exports) {
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getMachineId = void 0;
16
+ var fs_1 = __require("fs");
17
+ var api_1 = (init_esm(), __toCommonJS(esm_exports));
18
+ async function getMachineId() {
19
+ const paths = ["/etc/machine-id", "/var/lib/dbus/machine-id"];
20
+ for (const path of paths) {
21
+ try {
22
+ const result = await fs_1.promises.readFile(path, { encoding: "utf8" });
23
+ return result.trim();
24
+ } catch (e) {
25
+ api_1.diag.debug(`error reading machine id: ${e}`);
26
+ }
27
+ }
28
+ return void 0;
29
+ }
30
+ exports.getMachineId = getMachineId;
31
+ }
32
+ });
33
+ export default require_getMachineId_linux();
@@ -0,0 +1,23 @@
1
+ import {
2
+ esm_exports,
3
+ init_esm
4
+ } from "./chunk-HM7KNEG3.js";
5
+ import {
6
+ __commonJS,
7
+ __toCommonJS
8
+ } from "./chunk-2ESYSVXG.js";
9
+
10
+ // ../../node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/getMachineId-unsupported.js
11
+ var require_getMachineId_unsupported = __commonJS({
12
+ "../../node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/getMachineId-unsupported.js"(exports) {
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.getMachineId = void 0;
15
+ var api_1 = (init_esm(), __toCommonJS(esm_exports));
16
+ async function getMachineId() {
17
+ api_1.diag.debug("could not read machine-id: unsupported platform");
18
+ return void 0;
19
+ }
20
+ exports.getMachineId = getMachineId;
21
+ }
22
+ });
23
+ export default require_getMachineId_unsupported();
@@ -0,0 +1,42 @@
1
+ import {
2
+ require_execAsync
3
+ } from "./chunk-G64JTU26.js";
4
+ import {
5
+ esm_exports,
6
+ init_esm
7
+ } from "./chunk-HM7KNEG3.js";
8
+ import {
9
+ __commonJS,
10
+ __require,
11
+ __toCommonJS
12
+ } from "./chunk-2ESYSVXG.js";
13
+
14
+ // ../../node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/getMachineId-win.js
15
+ var require_getMachineId_win = __commonJS({
16
+ "../../node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/getMachineId-win.js"(exports) {
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.getMachineId = void 0;
19
+ var process = __require("process");
20
+ var execAsync_1 = require_execAsync();
21
+ var api_1 = (init_esm(), __toCommonJS(esm_exports));
22
+ async function getMachineId() {
23
+ const args = "QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid";
24
+ let command = "%windir%\\System32\\REG.exe";
25
+ if (process.arch === "ia32" && "PROCESSOR_ARCHITEW6432" in process.env) {
26
+ command = "%windir%\\sysnative\\cmd.exe /c " + command;
27
+ }
28
+ try {
29
+ const result = await (0, execAsync_1.execAsync)(`${command} ${args}`);
30
+ const parts = result.stdout.split("REG_SZ");
31
+ if (parts.length === 2) {
32
+ return parts[1].trim();
33
+ }
34
+ } catch (e) {
35
+ api_1.diag.debug(`error reading machine id: ${e}`);
36
+ }
37
+ return void 0;
38
+ }
39
+ exports.getMachineId = getMachineId;
40
+ }
41
+ });
42
+ export default require_getMachineId_win();
@@ -0,0 +1,412 @@
1
+ import {
2
+ GoogleGenAI,
3
+ convertMessages,
4
+ convertTools,
5
+ isThinkingPart,
6
+ mapStopReason,
7
+ mapToolChoice,
8
+ retainThoughtSignature
9
+ } from "./chunk-GQ4TD3EQ.js";
10
+ import {
11
+ formatProviderError,
12
+ normalizeProviderError
13
+ } from "./chunk-NKEOCGYU.js";
14
+ import {
15
+ buildBaseOptions
16
+ } from "./chunk-RYONFGPP.js";
17
+ import {
18
+ sanitizeSurrogates
19
+ } from "./chunk-CT4G24PS.js";
20
+ import {
21
+ providerHeadersToRecord
22
+ } from "./chunk-Y6UTJIT4.js";
23
+ import {
24
+ calculateCost,
25
+ clampThinkingLevel
26
+ } from "./chunk-Y3G4J3TB.js";
27
+ import {
28
+ AssistantMessageEventStream
29
+ } from "./chunk-46SEH6ER.js";
30
+ import "./chunk-ETG6PNHQ.js";
31
+ import "./chunk-2ESYSVXG.js";
32
+
33
+ // ../../node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js
34
+ var toolCallCounter = 0;
35
+ var stream = (model, context, options) => {
36
+ const stream2 = new AssistantMessageEventStream();
37
+ (async () => {
38
+ const output = {
39
+ role: "assistant",
40
+ content: [],
41
+ api: "google-generative-ai",
42
+ provider: model.provider,
43
+ model: model.id,
44
+ usage: {
45
+ input: 0,
46
+ output: 0,
47
+ cacheRead: 0,
48
+ cacheWrite: 0,
49
+ totalTokens: 0,
50
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
51
+ },
52
+ stopReason: "stop",
53
+ timestamp: Date.now()
54
+ };
55
+ try {
56
+ const apiKey = options?.apiKey;
57
+ if (!apiKey) {
58
+ throw new Error(`No API key for provider: ${model.provider}`);
59
+ }
60
+ const client = createClient(model, apiKey, options?.headers);
61
+ let params = buildParams(model, context, options);
62
+ const nextParams = await options?.onPayload?.(params, model);
63
+ if (nextParams !== void 0) {
64
+ params = nextParams;
65
+ }
66
+ const googleStream = await client.models.generateContentStream(params);
67
+ stream2.push({ type: "start", partial: output });
68
+ let currentBlock = null;
69
+ const blocks = output.content;
70
+ const blockIndex = () => blocks.length - 1;
71
+ for await (const chunk of googleStream) {
72
+ output.responseId ||= chunk.responseId;
73
+ const candidate = chunk.candidates?.[0];
74
+ if (candidate?.content?.parts) {
75
+ for (const part of candidate.content.parts) {
76
+ if (part.text !== void 0) {
77
+ const isThinking = isThinkingPart(part);
78
+ if (!currentBlock || isThinking && currentBlock.type !== "thinking" || !isThinking && currentBlock.type !== "text") {
79
+ if (currentBlock) {
80
+ if (currentBlock.type === "text") {
81
+ stream2.push({
82
+ type: "text_end",
83
+ contentIndex: blocks.length - 1,
84
+ content: currentBlock.text,
85
+ partial: output
86
+ });
87
+ } else {
88
+ stream2.push({
89
+ type: "thinking_end",
90
+ contentIndex: blockIndex(),
91
+ content: currentBlock.thinking,
92
+ partial: output
93
+ });
94
+ }
95
+ }
96
+ if (isThinking) {
97
+ currentBlock = { type: "thinking", thinking: "", thinkingSignature: void 0 };
98
+ output.content.push(currentBlock);
99
+ stream2.push({ type: "thinking_start", contentIndex: blockIndex(), partial: output });
100
+ } else {
101
+ currentBlock = { type: "text", text: "" };
102
+ output.content.push(currentBlock);
103
+ stream2.push({ type: "text_start", contentIndex: blockIndex(), partial: output });
104
+ }
105
+ }
106
+ if (currentBlock.type === "thinking") {
107
+ currentBlock.thinking += part.text;
108
+ currentBlock.thinkingSignature = retainThoughtSignature(currentBlock.thinkingSignature, part.thoughtSignature);
109
+ stream2.push({
110
+ type: "thinking_delta",
111
+ contentIndex: blockIndex(),
112
+ delta: part.text,
113
+ partial: output
114
+ });
115
+ } else {
116
+ currentBlock.text += part.text;
117
+ currentBlock.textSignature = retainThoughtSignature(currentBlock.textSignature, part.thoughtSignature);
118
+ stream2.push({
119
+ type: "text_delta",
120
+ contentIndex: blockIndex(),
121
+ delta: part.text,
122
+ partial: output
123
+ });
124
+ }
125
+ }
126
+ if (part.functionCall) {
127
+ if (currentBlock) {
128
+ if (currentBlock.type === "text") {
129
+ stream2.push({
130
+ type: "text_end",
131
+ contentIndex: blockIndex(),
132
+ content: currentBlock.text,
133
+ partial: output
134
+ });
135
+ } else {
136
+ stream2.push({
137
+ type: "thinking_end",
138
+ contentIndex: blockIndex(),
139
+ content: currentBlock.thinking,
140
+ partial: output
141
+ });
142
+ }
143
+ currentBlock = null;
144
+ }
145
+ const providedId = part.functionCall.id;
146
+ const needsNewId = !providedId || output.content.some((b) => b.type === "toolCall" && b.id === providedId);
147
+ const toolCallId = needsNewId ? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}` : providedId;
148
+ const toolCall = {
149
+ type: "toolCall",
150
+ id: toolCallId,
151
+ name: part.functionCall.name || "",
152
+ arguments: part.functionCall.args ?? {},
153
+ ...part.thoughtSignature && { thoughtSignature: part.thoughtSignature }
154
+ };
155
+ output.content.push(toolCall);
156
+ stream2.push({ type: "toolcall_start", contentIndex: blockIndex(), partial: output });
157
+ stream2.push({
158
+ type: "toolcall_delta",
159
+ contentIndex: blockIndex(),
160
+ delta: JSON.stringify(toolCall.arguments),
161
+ partial: output
162
+ });
163
+ stream2.push({ type: "toolcall_end", contentIndex: blockIndex(), toolCall, partial: output });
164
+ }
165
+ }
166
+ }
167
+ if (candidate?.finishReason) {
168
+ output.stopReason = mapStopReason(candidate.finishReason);
169
+ if (output.content.some((b) => b.type === "toolCall")) {
170
+ output.stopReason = "toolUse";
171
+ }
172
+ }
173
+ if (chunk.usageMetadata) {
174
+ output.usage = {
175
+ input: (chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),
176
+ output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),
177
+ cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,
178
+ cacheWrite: 0,
179
+ reasoning: chunk.usageMetadata.thoughtsTokenCount || 0,
180
+ totalTokens: chunk.usageMetadata.totalTokenCount || 0,
181
+ cost: {
182
+ input: 0,
183
+ output: 0,
184
+ cacheRead: 0,
185
+ cacheWrite: 0,
186
+ total: 0
187
+ }
188
+ };
189
+ calculateCost(model, output.usage);
190
+ }
191
+ }
192
+ if (currentBlock) {
193
+ if (currentBlock.type === "text") {
194
+ stream2.push({
195
+ type: "text_end",
196
+ contentIndex: blockIndex(),
197
+ content: currentBlock.text,
198
+ partial: output
199
+ });
200
+ } else {
201
+ stream2.push({
202
+ type: "thinking_end",
203
+ contentIndex: blockIndex(),
204
+ content: currentBlock.thinking,
205
+ partial: output
206
+ });
207
+ }
208
+ }
209
+ if (options?.signal?.aborted) {
210
+ throw new Error("Request was aborted");
211
+ }
212
+ if (output.stopReason === "aborted" || output.stopReason === "error") {
213
+ throw new Error("An unknown error occurred");
214
+ }
215
+ stream2.push({ type: "done", reason: output.stopReason, message: output });
216
+ stream2.end();
217
+ } catch (error) {
218
+ for (const block of output.content) {
219
+ if ("index" in block) {
220
+ delete block.index;
221
+ }
222
+ }
223
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
224
+ output.errorMessage = formatProviderError(normalizeProviderError(error));
225
+ stream2.push({ type: "error", reason: output.stopReason, error: output });
226
+ stream2.end();
227
+ }
228
+ })();
229
+ return stream2;
230
+ };
231
+ var streamSimple = (model, context, options) => {
232
+ const apiKey = options?.apiKey;
233
+ if (!apiKey) {
234
+ throw new Error(`No API key for provider: ${model.provider}`);
235
+ }
236
+ const base = buildBaseOptions(model, context, options, apiKey);
237
+ if (!options?.reasoning) {
238
+ return stream(model, context, { ...base, thinking: { enabled: false } });
239
+ }
240
+ const clampedReasoning = clampThinkingLevel(model, options.reasoning);
241
+ const effort = clampedReasoning === "off" ? "high" : clampedReasoning;
242
+ const googleModel = model;
243
+ if (isGemini3ProModel(googleModel) || isGemini3FlashModel(googleModel) || isGemma4Model(googleModel)) {
244
+ return stream(model, context, {
245
+ ...base,
246
+ thinking: {
247
+ enabled: true,
248
+ level: getThinkingLevel(effort, googleModel)
249
+ }
250
+ });
251
+ }
252
+ return stream(model, context, {
253
+ ...base,
254
+ thinking: {
255
+ enabled: true,
256
+ budgetTokens: getGoogleBudget(googleModel, effort, options.thinkingBudgets)
257
+ }
258
+ });
259
+ };
260
+ function createClient(model, apiKey, optionsHeaders) {
261
+ const httpOptions = {};
262
+ if (model.baseUrl) {
263
+ httpOptions.baseUrl = model.baseUrl;
264
+ httpOptions.apiVersion = "";
265
+ }
266
+ const headers = providerHeadersToRecord({ ...model.headers, ...optionsHeaders });
267
+ if (headers) {
268
+ httpOptions.headers = headers;
269
+ }
270
+ return new GoogleGenAI({
271
+ apiKey,
272
+ httpOptions: Object.keys(httpOptions).length > 0 ? httpOptions : void 0
273
+ });
274
+ }
275
+ function buildParams(model, context, options = {}) {
276
+ const contents = convertMessages(model, context);
277
+ const generationConfig = {};
278
+ if (options.temperature !== void 0) {
279
+ generationConfig.temperature = options.temperature;
280
+ }
281
+ if (options.maxTokens !== void 0) {
282
+ generationConfig.maxOutputTokens = options.maxTokens;
283
+ }
284
+ const config = {
285
+ ...Object.keys(generationConfig).length > 0 && generationConfig,
286
+ ...context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) },
287
+ ...context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }
288
+ };
289
+ if (context.tools && context.tools.length > 0 && options.toolChoice) {
290
+ config.toolConfig = {
291
+ functionCallingConfig: {
292
+ mode: mapToolChoice(options.toolChoice)
293
+ }
294
+ };
295
+ } else {
296
+ config.toolConfig = void 0;
297
+ }
298
+ if (options.thinking?.enabled && model.reasoning) {
299
+ const thinkingConfig = { includeThoughts: true };
300
+ if (options.thinking.level !== void 0) {
301
+ thinkingConfig.thinkingLevel = options.thinking.level;
302
+ } else if (options.thinking.budgetTokens !== void 0) {
303
+ thinkingConfig.thinkingBudget = options.thinking.budgetTokens;
304
+ }
305
+ config.thinkingConfig = thinkingConfig;
306
+ } else if (model.reasoning && options.thinking && !options.thinking.enabled) {
307
+ config.thinkingConfig = getDisabledThinkingConfig(model);
308
+ }
309
+ if (options.signal) {
310
+ if (options.signal.aborted) {
311
+ throw new Error("Request aborted");
312
+ }
313
+ config.abortSignal = options.signal;
314
+ }
315
+ const params = {
316
+ model: model.id,
317
+ contents,
318
+ config
319
+ };
320
+ return params;
321
+ }
322
+ function isGemma4Model(model) {
323
+ return /gemma-?4/.test(model.id.toLowerCase());
324
+ }
325
+ function isGemini3ProModel(model) {
326
+ return /gemini-3(?:\.\d+)?-pro/.test(model.id.toLowerCase());
327
+ }
328
+ function isGemini3FlashModel(model) {
329
+ const id = model.id.toLowerCase();
330
+ return /gemini-3(?:\.\d+)?-flash/.test(id) || id === "gemini-flash-latest" || id === "gemini-flash-lite-latest";
331
+ }
332
+ function getDisabledThinkingConfig(model) {
333
+ if (isGemini3ProModel(model)) {
334
+ return { thinkingLevel: "LOW" };
335
+ }
336
+ if (isGemini3FlashModel(model)) {
337
+ return { thinkingLevel: "MINIMAL" };
338
+ }
339
+ if (isGemma4Model(model)) {
340
+ return { thinkingLevel: "MINIMAL" };
341
+ }
342
+ return { thinkingBudget: 0 };
343
+ }
344
+ function getThinkingLevel(effort, model) {
345
+ if (isGemini3ProModel(model)) {
346
+ switch (effort) {
347
+ case "minimal":
348
+ case "low":
349
+ return "LOW";
350
+ case "medium":
351
+ case "high":
352
+ return "HIGH";
353
+ }
354
+ }
355
+ if (isGemma4Model(model)) {
356
+ switch (effort) {
357
+ case "minimal":
358
+ case "low":
359
+ return "MINIMAL";
360
+ case "medium":
361
+ case "high":
362
+ return "HIGH";
363
+ }
364
+ }
365
+ switch (effort) {
366
+ case "minimal":
367
+ return "MINIMAL";
368
+ case "low":
369
+ return "LOW";
370
+ case "medium":
371
+ return "MEDIUM";
372
+ case "high":
373
+ return "HIGH";
374
+ }
375
+ }
376
+ function getGoogleBudget(model, effort, customBudgets) {
377
+ if (customBudgets?.[effort] !== void 0) {
378
+ return customBudgets[effort];
379
+ }
380
+ if (model.id.includes("2.5-pro")) {
381
+ const budgets = {
382
+ minimal: 128,
383
+ low: 2048,
384
+ medium: 8192,
385
+ high: 32768
386
+ };
387
+ return budgets[effort];
388
+ }
389
+ if (model.id.includes("2.5-flash-lite")) {
390
+ const budgets = {
391
+ minimal: 512,
392
+ low: 2048,
393
+ medium: 8192,
394
+ high: 24576
395
+ };
396
+ return budgets[effort];
397
+ }
398
+ if (model.id.includes("2.5-flash")) {
399
+ const budgets = {
400
+ minimal: 128,
401
+ low: 2048,
402
+ medium: 8192,
403
+ high: 24576
404
+ };
405
+ return budgets[effort];
406
+ }
407
+ return -1;
408
+ }
409
+ export {
410
+ stream,
411
+ streamSimple
412
+ };