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,33 @@
1
+ import {
2
+ __require
3
+ } from "./chunk-VS2QQHAK.js";
4
+
5
+ // ../../node_modules/@earendil-works/pi-ai/dist/utils/provider-env.js
6
+ var procEnvCache = null;
7
+ function getBunSandboxEnvValue(name) {
8
+ if (typeof process === "undefined" || !process.versions?.bun || Object.keys(process.env).length > 0) {
9
+ return void 0;
10
+ }
11
+ if (procEnvCache === null) {
12
+ procEnvCache = /* @__PURE__ */ new Map();
13
+ try {
14
+ const { readFileSync } = __require("node:fs");
15
+ const data = readFileSync("/proc/self/environ", "utf-8");
16
+ for (const entry of data.split("\0")) {
17
+ const idx = entry.indexOf("=");
18
+ if (idx > 0) {
19
+ procEnvCache.set(entry.slice(0, idx), entry.slice(idx + 1));
20
+ }
21
+ }
22
+ } catch {
23
+ }
24
+ }
25
+ return procEnvCache.get(name);
26
+ }
27
+ function getProviderEnvValue(name, env) {
28
+ return env?.[name] || (typeof process !== "undefined" ? process.env[name] : void 0) || getBunSandboxEnvValue(name) || void 0;
29
+ }
30
+
31
+ export {
32
+ getProviderEnvValue
33
+ };
@@ -0,0 +1,317 @@
1
+ // ../../node_modules/@earendil-works/pi-ai/dist/utils/estimate.js
2
+ var CHARS_PER_TOKEN = 4;
3
+ var ESTIMATED_IMAGE_CHARS = 4800;
4
+ function calculateContextTokens(usage) {
5
+ return usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
6
+ }
7
+ function safeJsonStringify(value) {
8
+ try {
9
+ return JSON.stringify(value) ?? "undefined";
10
+ } catch {
11
+ return "[unserializable]";
12
+ }
13
+ }
14
+ function estimateTextAndImageContentChars(content) {
15
+ if (typeof content === "string")
16
+ return content.length;
17
+ let chars = 0;
18
+ for (const block of content)
19
+ chars += block.type === "text" ? block.text.length : ESTIMATED_IMAGE_CHARS;
20
+ return chars;
21
+ }
22
+ function estimateTextTokens(text) {
23
+ return Math.ceil(text.length / CHARS_PER_TOKEN);
24
+ }
25
+ function estimateTextAndImageContentTokens(content) {
26
+ return Math.ceil(estimateTextAndImageContentChars(content) / CHARS_PER_TOKEN);
27
+ }
28
+ function estimateMessageTokens(message) {
29
+ let chars = 0;
30
+ if (message.role === "user")
31
+ return estimateTextAndImageContentTokens(message.content);
32
+ if (message.role === "toolResult")
33
+ return estimateTextAndImageContentTokens(message.content);
34
+ for (const block of message.content) {
35
+ if (block.type === "text") {
36
+ chars += block.text.length;
37
+ } else if (block.type === "thinking") {
38
+ chars += block.thinking.length;
39
+ } else {
40
+ chars += block.name.length + safeJsonStringify(block.arguments).length;
41
+ }
42
+ }
43
+ return Math.ceil(chars / CHARS_PER_TOKEN);
44
+ }
45
+ function getLastAssistantUsageInfo(messages) {
46
+ let latestPrefixTimestamp = Number.NEGATIVE_INFINITY;
47
+ let usageInfo;
48
+ for (let i = 0; i < messages.length; i++) {
49
+ const message = messages[i];
50
+ if (message.role === "assistant") {
51
+ const assistant = message;
52
+ const usageAppliesToPrefix = assistant.timestamp >= latestPrefixTimestamp;
53
+ if (usageAppliesToPrefix && assistant.stopReason !== "aborted" && assistant.stopReason !== "error" && calculateContextTokens(assistant.usage) > 0) {
54
+ usageInfo = { usage: assistant.usage, index: i };
55
+ }
56
+ }
57
+ latestPrefixTimestamp = Math.max(latestPrefixTimestamp, message.timestamp);
58
+ }
59
+ return usageInfo;
60
+ }
61
+ function estimateMessages(messages) {
62
+ const usageInfo = getLastAssistantUsageInfo(messages);
63
+ if (usageInfo) {
64
+ const usageTokens = calculateContextTokens(usageInfo.usage);
65
+ let trailingTokens = 0;
66
+ for (let i = usageInfo.index + 1; i < messages.length; i++) {
67
+ trailingTokens += estimateMessageTokens(messages[i]);
68
+ }
69
+ return { tokens: usageTokens + trailingTokens, usageTokens, trailingTokens, lastUsageIndex: usageInfo.index };
70
+ }
71
+ let tokens = 0;
72
+ for (const message of messages)
73
+ tokens += estimateMessageTokens(message);
74
+ return { tokens, usageTokens: 0, trailingTokens: tokens, lastUsageIndex: null };
75
+ }
76
+ function estimateToolsTokens(tools) {
77
+ if (!tools || tools.length === 0)
78
+ return 0;
79
+ return estimateTextTokens(safeJsonStringify(tools));
80
+ }
81
+ function isMessageArray(value) {
82
+ return Array.isArray(value);
83
+ }
84
+ function estimateContextTokens(context) {
85
+ if (isMessageArray(context))
86
+ return estimateMessages(context);
87
+ const estimate = estimateMessages(context.messages);
88
+ if (estimate.lastUsageIndex !== null) {
89
+ const addedNames = new Set(context.messages.slice(estimate.lastUsageIndex + 1).filter((message) => message.role === "toolResult").flatMap((message) => message.addedToolNames ?? []));
90
+ const addedToolTokens = estimateToolsTokens(context.tools?.filter((tool) => addedNames.has(tool.name)));
91
+ return {
92
+ tokens: estimate.tokens + addedToolTokens,
93
+ usageTokens: estimate.usageTokens,
94
+ trailingTokens: estimate.trailingTokens + addedToolTokens,
95
+ lastUsageIndex: estimate.lastUsageIndex
96
+ };
97
+ }
98
+ const prefixTokens = (context.systemPrompt ? estimateTextTokens(context.systemPrompt) : 0) + estimateToolsTokens(context.tools);
99
+ return {
100
+ tokens: estimate.tokens + prefixTokens,
101
+ usageTokens: estimate.usageTokens,
102
+ trailingTokens: estimate.trailingTokens + prefixTokens,
103
+ lastUsageIndex: estimate.lastUsageIndex
104
+ };
105
+ }
106
+
107
+ // ../../node_modules/@earendil-works/pi-ai/dist/api/simple-options.js
108
+ var CONTEXT_SAFETY_TOKENS = 4096;
109
+ var MIN_MAX_TOKENS = 1;
110
+ function clampMaxTokensToContext(model, context, maxTokens) {
111
+ if (model.contextWindow <= 0)
112
+ return Math.max(MIN_MAX_TOKENS, maxTokens);
113
+ const available = model.contextWindow - estimateContextTokens(context).tokens - CONTEXT_SAFETY_TOKENS;
114
+ return Math.min(maxTokens, Math.max(MIN_MAX_TOKENS, available));
115
+ }
116
+ function buildBaseOptions(model, context, options, apiKey) {
117
+ return {
118
+ temperature: options?.temperature,
119
+ maxTokens: clampMaxTokensToContext(model, context, options?.maxTokens ?? model.maxTokens),
120
+ signal: options?.signal,
121
+ apiKey: apiKey || options?.apiKey,
122
+ transport: options?.transport,
123
+ cacheRetention: options?.cacheRetention,
124
+ sessionId: options?.sessionId,
125
+ headers: options?.headers,
126
+ onPayload: options?.onPayload,
127
+ onResponse: options?.onResponse,
128
+ timeoutMs: options?.timeoutMs,
129
+ websocketConnectTimeoutMs: options?.websocketConnectTimeoutMs,
130
+ maxRetries: options?.maxRetries,
131
+ maxRetryDelayMs: options?.maxRetryDelayMs,
132
+ metadata: options?.metadata,
133
+ env: options?.env
134
+ };
135
+ }
136
+ function clampReasoning(effort) {
137
+ return effort === "xhigh" || effort === "max" ? "high" : effort;
138
+ }
139
+ function adjustMaxTokensForThinking(baseMaxTokens, modelMaxTokens, reasoningLevel, customBudgets) {
140
+ const defaultBudgets = {
141
+ minimal: 1024,
142
+ low: 2048,
143
+ medium: 8192,
144
+ high: 16384
145
+ };
146
+ const budgets = { ...defaultBudgets, ...customBudgets };
147
+ const minOutputTokens = 1024;
148
+ const level = clampReasoning(reasoningLevel);
149
+ let thinkingBudget = budgets[level];
150
+ const maxTokens = baseMaxTokens === void 0 ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);
151
+ if (maxTokens <= thinkingBudget) {
152
+ thinkingBudget = Math.max(0, maxTokens - minOutputTokens);
153
+ }
154
+ return { maxTokens, thinkingBudget };
155
+ }
156
+
157
+ // ../../node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js
158
+ var NON_VISION_USER_IMAGE_PLACEHOLDER = "(image omitted: model does not support images)";
159
+ var NON_VISION_TOOL_IMAGE_PLACEHOLDER = "(tool image omitted: model does not support images)";
160
+ function replaceImagesWithPlaceholder(content, placeholder) {
161
+ const result = [];
162
+ let previousWasPlaceholder = false;
163
+ for (const block of content) {
164
+ if (block.type === "image") {
165
+ if (!previousWasPlaceholder) {
166
+ result.push({ type: "text", text: placeholder });
167
+ }
168
+ previousWasPlaceholder = true;
169
+ continue;
170
+ }
171
+ result.push(block);
172
+ previousWasPlaceholder = block.text === placeholder;
173
+ }
174
+ return result;
175
+ }
176
+ function downgradeUnsupportedImages(messages, model) {
177
+ if (model.input.includes("image")) {
178
+ return messages;
179
+ }
180
+ return messages.map((msg) => {
181
+ if (msg.role === "user" && Array.isArray(msg.content)) {
182
+ return {
183
+ ...msg,
184
+ content: replaceImagesWithPlaceholder(msg.content, NON_VISION_USER_IMAGE_PLACEHOLDER)
185
+ };
186
+ }
187
+ if (msg.role === "toolResult") {
188
+ return {
189
+ ...msg,
190
+ content: replaceImagesWithPlaceholder(msg.content, NON_VISION_TOOL_IMAGE_PLACEHOLDER)
191
+ };
192
+ }
193
+ return msg;
194
+ });
195
+ }
196
+ function transformMessages(messages, model, normalizeToolCallId) {
197
+ const toolCallIdMap = /* @__PURE__ */ new Map();
198
+ const normalizedMessages = messages.map((msg) => msg.content == null ? { ...msg, content: [] } : msg);
199
+ const imageAwareMessages = downgradeUnsupportedImages(normalizedMessages, model);
200
+ const transformed = imageAwareMessages.map((msg) => {
201
+ if (msg.role === "user") {
202
+ return msg;
203
+ }
204
+ if (msg.role === "toolResult") {
205
+ const normalizedId = toolCallIdMap.get(msg.toolCallId);
206
+ if (normalizedId && normalizedId !== msg.toolCallId) {
207
+ return { ...msg, toolCallId: normalizedId };
208
+ }
209
+ return msg;
210
+ }
211
+ if (msg.role === "assistant") {
212
+ const assistantMsg = msg;
213
+ const isSameModel = assistantMsg.provider === model.provider && assistantMsg.api === model.api && assistantMsg.model === model.id;
214
+ const transformedContent = assistantMsg.content.flatMap((block) => {
215
+ if (block.type === "thinking") {
216
+ if (block.redacted) {
217
+ return isSameModel ? block : [];
218
+ }
219
+ if (isSameModel && block.thinkingSignature)
220
+ return block;
221
+ if (!block.thinking || block.thinking.trim() === "")
222
+ return [];
223
+ if (isSameModel)
224
+ return block;
225
+ return {
226
+ type: "text",
227
+ text: block.thinking
228
+ };
229
+ }
230
+ if (block.type === "text") {
231
+ if (isSameModel)
232
+ return block;
233
+ return {
234
+ type: "text",
235
+ text: block.text
236
+ };
237
+ }
238
+ if (block.type === "toolCall") {
239
+ const toolCall = block;
240
+ let normalizedToolCall = toolCall;
241
+ if (!isSameModel && toolCall.thoughtSignature) {
242
+ normalizedToolCall = { ...toolCall };
243
+ delete normalizedToolCall.thoughtSignature;
244
+ }
245
+ if (!isSameModel && normalizeToolCallId) {
246
+ const normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);
247
+ if (normalizedId !== toolCall.id) {
248
+ toolCallIdMap.set(toolCall.id, normalizedId);
249
+ normalizedToolCall = { ...normalizedToolCall, id: normalizedId };
250
+ }
251
+ }
252
+ return normalizedToolCall;
253
+ }
254
+ return block;
255
+ });
256
+ return {
257
+ ...assistantMsg,
258
+ content: transformedContent
259
+ };
260
+ }
261
+ return msg;
262
+ });
263
+ const result = [];
264
+ let pendingToolCalls = [];
265
+ let existingToolResultIds = /* @__PURE__ */ new Set();
266
+ const insertSyntheticToolResults = () => {
267
+ if (pendingToolCalls.length > 0) {
268
+ for (const tc of pendingToolCalls) {
269
+ if (!existingToolResultIds.has(tc.id)) {
270
+ result.push({
271
+ role: "toolResult",
272
+ toolCallId: tc.id,
273
+ toolName: tc.name,
274
+ content: [{ type: "text", text: "No result provided" }],
275
+ isError: true,
276
+ timestamp: Date.now()
277
+ });
278
+ }
279
+ }
280
+ pendingToolCalls = [];
281
+ existingToolResultIds = /* @__PURE__ */ new Set();
282
+ }
283
+ };
284
+ for (let i = 0; i < transformed.length; i++) {
285
+ const msg = transformed[i];
286
+ if (msg.role === "assistant") {
287
+ insertSyntheticToolResults();
288
+ const assistantMsg = msg;
289
+ if (assistantMsg.stopReason === "error" || assistantMsg.stopReason === "aborted") {
290
+ continue;
291
+ }
292
+ const toolCalls = assistantMsg.content.filter((b) => b.type === "toolCall");
293
+ if (toolCalls.length > 0) {
294
+ pendingToolCalls = toolCalls;
295
+ existingToolResultIds = /* @__PURE__ */ new Set();
296
+ }
297
+ result.push(msg);
298
+ } else if (msg.role === "toolResult") {
299
+ existingToolResultIds.add(msg.toolCallId);
300
+ result.push(msg);
301
+ } else if (msg.role === "user") {
302
+ insertSyntheticToolResults();
303
+ result.push(msg);
304
+ } else {
305
+ result.push(msg);
306
+ }
307
+ }
308
+ insertSyntheticToolResults();
309
+ return result;
310
+ }
311
+
312
+ export {
313
+ clampMaxTokensToContext,
314
+ buildBaseOptions,
315
+ adjustMaxTokensForThinking,
316
+ transformMessages
317
+ };