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.
Files changed (50) hide show
  1. package/README.md +1 -1
  2. package/linkquejs.js +27 -2212
  3. package/package.json +4 -1
  4. package/vendor/linkque-agent-appwrite-integrate/dist/esm/anthropic-messages-B5T6TFD2.js +7172 -0
  5. package/vendor/linkque-agent-appwrite-integrate/dist/esm/azure-openai-responses-S7HNQOSE.js +229 -0
  6. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-2NGJGNYB.js +1765 -0
  7. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-3S3TOEBZ.js +608 -0
  8. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-46SEH6ER.js +78 -0
  9. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-52BVDZQ2.js +60299 -0
  10. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-6MHDOBWO.js +12 -0
  11. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-6WHNFJT4.js +31278 -0
  12. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-7BQRUS4C.js +671 -0
  13. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-7QWAKKTY.js +7054 -0
  14. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-CT4G24PS.js +8 -0
  15. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-DYEQRE6N.js +343 -0
  16. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-E2P6TIFG.js +31 -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-HTG7JBF2.js +38 -0
  19. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-I64V3ICJ.js +11166 -0
  20. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-IKZ25GJD.js +497 -0
  21. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-MKS245OU.js +3570 -0
  22. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-NKEOCGYU.js +76 -0
  23. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-NQM5ZCTR.js +12015 -0
  24. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-OXGCUIKV.js +33 -0
  25. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-RYONFGPP.js +317 -0
  26. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-UEVQXSKG.js +4765 -0
  27. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-UFVAKOTZ.js +17 -0
  28. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-VS2QQHAK.js +46 -0
  29. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-XMVFOHGJ.js +31 -0
  30. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-XUFLSZM4.js +5319 -0
  31. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-Y6UTJIT4.js +23 -0
  32. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-YDKZZ6EH.js +3584 -0
  33. package/vendor/linkque-agent-appwrite-integrate/dist/esm/dist-QD3CV4KC.js +1224 -0
  34. package/vendor/linkque-agent-appwrite-integrate/dist/esm/google-generative-ai-IOXNKFEV.js +412 -0
  35. package/vendor/linkque-agent-appwrite-integrate/dist/esm/google-vertex-U4ZV5IXZ.js +461 -0
  36. package/vendor/linkque-agent-appwrite-integrate/dist/esm/mistral-conversations-G3K7SSWR.js +30344 -0
  37. package/vendor/linkque-agent-appwrite-integrate/dist/esm/multipart-parser-2VJ7LVQD.js +170 -0
  38. package/vendor/linkque-agent-appwrite-integrate/dist/esm/multipart-parser-AJMV6U6H.js +178 -0
  39. package/vendor/linkque-agent-appwrite-integrate/dist/esm/multipart-parser-PULXGNYO.js +368 -0
  40. package/vendor/linkque-agent-appwrite-integrate/dist/esm/openai-codex-responses-4JJLPTCS.js +1308 -0
  41. package/vendor/linkque-agent-appwrite-integrate/dist/esm/openai-completions-PH4WW6E7.js +977 -0
  42. package/vendor/linkque-agent-appwrite-integrate/dist/esm/openai-responses-KGWAX6HR.js +264 -0
  43. package/vendor/linkque-agent-appwrite-integrate/dist/esm/openrouter-images-LMBZZQ76.js +138 -0
  44. package/vendor/linkque-agent-appwrite-integrate/dist/esm/otel-7GSG7QQO.js +6657 -0
  45. package/vendor/linkque-agent-appwrite-integrate/dist/esm/pi-messages-ZX3KUWSZ.js +309 -0
  46. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +2354 -0
  47. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +16 -0
  48. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +17 -0
  49. package/vendor/linkque-agent-appwrite-integrate/dist/esm/src-NGZW4JXI.js +1396 -0
  50. package/vendor/linkque-agent-appwrite-integrate/package.json +1 -0
@@ -0,0 +1,412 @@
1
+ import {
2
+ GoogleGenAI,
3
+ convertMessages,
4
+ convertTools,
5
+ isThinkingPart,
6
+ mapStopReason,
7
+ mapToolChoice,
8
+ retainThoughtSignature
9
+ } from "./chunk-6WHNFJT4.js";
10
+ import "./chunk-2NGJGNYB.js";
11
+ import {
12
+ formatProviderError,
13
+ normalizeProviderError
14
+ } from "./chunk-NKEOCGYU.js";
15
+ import {
16
+ buildBaseOptions
17
+ } from "./chunk-RYONFGPP.js";
18
+ import {
19
+ sanitizeSurrogates
20
+ } from "./chunk-CT4G24PS.js";
21
+ import {
22
+ providerHeadersToRecord
23
+ } from "./chunk-Y6UTJIT4.js";
24
+ import {
25
+ calculateCost,
26
+ clampThinkingLevel
27
+ } from "./chunk-3S3TOEBZ.js";
28
+ import {
29
+ AssistantMessageEventStream
30
+ } from "./chunk-46SEH6ER.js";
31
+ import "./chunk-VS2QQHAK.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
+ };