linkque-cli-v2 1.0.5 → 1.0.7
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 +23 -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-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-FJ2BZPIM.js +60308 -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-IAT272TH.js +12121 -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-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 +2348 -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
- package/worker.js +16 -6
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import {
|
|
2
|
+
convertResponsesMessages,
|
|
3
|
+
convertResponsesTools,
|
|
4
|
+
processResponsesStream
|
|
5
|
+
} from "./chunk-IKZ25GJD.js";
|
|
6
|
+
import "./chunk-UFVAKOTZ.js";
|
|
7
|
+
import {
|
|
8
|
+
AzureOpenAI
|
|
9
|
+
} from "./chunk-7QWAKKTY.js";
|
|
10
|
+
import {
|
|
11
|
+
clampOpenAIPromptCacheKey
|
|
12
|
+
} from "./chunk-FHNQ6DPF.js";
|
|
13
|
+
import {
|
|
14
|
+
formatProviderError,
|
|
15
|
+
normalizeProviderError
|
|
16
|
+
} from "./chunk-NKEOCGYU.js";
|
|
17
|
+
import {
|
|
18
|
+
buildBaseOptions
|
|
19
|
+
} from "./chunk-RYONFGPP.js";
|
|
20
|
+
import "./chunk-CT4G24PS.js";
|
|
21
|
+
import {
|
|
22
|
+
headersToRecord
|
|
23
|
+
} from "./chunk-Y6UTJIT4.js";
|
|
24
|
+
import {
|
|
25
|
+
clampThinkingLevel
|
|
26
|
+
} from "./chunk-3S3TOEBZ.js";
|
|
27
|
+
import {
|
|
28
|
+
getProviderEnvValue
|
|
29
|
+
} from "./chunk-OXGCUIKV.js";
|
|
30
|
+
import "./chunk-DYEQRE6N.js";
|
|
31
|
+
import {
|
|
32
|
+
AssistantMessageEventStream
|
|
33
|
+
} from "./chunk-46SEH6ER.js";
|
|
34
|
+
import "./chunk-VS2QQHAK.js";
|
|
35
|
+
|
|
36
|
+
// ../../node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js
|
|
37
|
+
var DEFAULT_AZURE_API_VERSION = "v1";
|
|
38
|
+
var AZURE_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "openai-codex", "opencode", "azure-openai-responses"]);
|
|
39
|
+
var OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;
|
|
40
|
+
function parseDeploymentNameMap(value) {
|
|
41
|
+
const map = /* @__PURE__ */ new Map();
|
|
42
|
+
if (!value)
|
|
43
|
+
return map;
|
|
44
|
+
for (const entry of value.split(",")) {
|
|
45
|
+
const trimmed = entry.trim();
|
|
46
|
+
if (!trimmed)
|
|
47
|
+
continue;
|
|
48
|
+
const [modelId, deploymentName] = trimmed.split("=", 2);
|
|
49
|
+
if (!modelId || !deploymentName)
|
|
50
|
+
continue;
|
|
51
|
+
map.set(modelId.trim(), deploymentName.trim());
|
|
52
|
+
}
|
|
53
|
+
return map;
|
|
54
|
+
}
|
|
55
|
+
function resolveDeploymentName(model, options) {
|
|
56
|
+
if (options?.azureDeploymentName) {
|
|
57
|
+
return options.azureDeploymentName;
|
|
58
|
+
}
|
|
59
|
+
const mappedDeployment = parseDeploymentNameMap(getProviderEnvValue("AZURE_OPENAI_DEPLOYMENT_NAME_MAP", options?.env)).get(model.id);
|
|
60
|
+
return mappedDeployment || model.id;
|
|
61
|
+
}
|
|
62
|
+
function formatAzureOpenAIError(error) {
|
|
63
|
+
return formatProviderError(normalizeProviderError(error), "Azure OpenAI API error");
|
|
64
|
+
}
|
|
65
|
+
var stream = (model, context, options) => {
|
|
66
|
+
const stream2 = new AssistantMessageEventStream();
|
|
67
|
+
(async () => {
|
|
68
|
+
const deploymentName = resolveDeploymentName(model, options);
|
|
69
|
+
const output = {
|
|
70
|
+
role: "assistant",
|
|
71
|
+
content: [],
|
|
72
|
+
api: "azure-openai-responses",
|
|
73
|
+
provider: model.provider,
|
|
74
|
+
model: model.id,
|
|
75
|
+
usage: {
|
|
76
|
+
input: 0,
|
|
77
|
+
output: 0,
|
|
78
|
+
cacheRead: 0,
|
|
79
|
+
cacheWrite: 0,
|
|
80
|
+
totalTokens: 0,
|
|
81
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
|
|
82
|
+
},
|
|
83
|
+
stopReason: "stop",
|
|
84
|
+
timestamp: Date.now()
|
|
85
|
+
};
|
|
86
|
+
try {
|
|
87
|
+
const apiKey = options?.apiKey;
|
|
88
|
+
if (!apiKey) {
|
|
89
|
+
throw new Error(`No API key for provider: ${model.provider}`);
|
|
90
|
+
}
|
|
91
|
+
const client = createClient(model, apiKey, options);
|
|
92
|
+
let params = buildParams(model, context, options, deploymentName);
|
|
93
|
+
const nextParams = await options?.onPayload?.(params, model);
|
|
94
|
+
if (nextParams !== void 0) {
|
|
95
|
+
params = nextParams;
|
|
96
|
+
}
|
|
97
|
+
const requestOptions = {
|
|
98
|
+
...options?.signal ? { signal: options.signal } : {},
|
|
99
|
+
...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
|
|
100
|
+
maxRetries: options?.maxRetries ?? 0
|
|
101
|
+
};
|
|
102
|
+
const { data: openaiStream, response } = await client.responses.create(params, requestOptions).withResponse();
|
|
103
|
+
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
|
|
104
|
+
stream2.push({ type: "start", partial: output });
|
|
105
|
+
await processResponsesStream(openaiStream, output, stream2, model);
|
|
106
|
+
if (options?.signal?.aborted) {
|
|
107
|
+
throw new Error("Request was aborted");
|
|
108
|
+
}
|
|
109
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") {
|
|
110
|
+
throw new Error("An unknown error occurred");
|
|
111
|
+
}
|
|
112
|
+
stream2.push({ type: "done", reason: output.stopReason, message: output });
|
|
113
|
+
stream2.end();
|
|
114
|
+
} catch (error) {
|
|
115
|
+
for (const block of output.content) {
|
|
116
|
+
delete block.index;
|
|
117
|
+
delete block.partialJson;
|
|
118
|
+
}
|
|
119
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
120
|
+
output.errorMessage = formatAzureOpenAIError(error);
|
|
121
|
+
stream2.push({ type: "error", reason: output.stopReason, error: output });
|
|
122
|
+
stream2.end();
|
|
123
|
+
}
|
|
124
|
+
})();
|
|
125
|
+
return stream2;
|
|
126
|
+
};
|
|
127
|
+
var streamSimple = (model, context, options) => {
|
|
128
|
+
const apiKey = options?.apiKey;
|
|
129
|
+
if (!apiKey) {
|
|
130
|
+
throw new Error(`No API key for provider: ${model.provider}`);
|
|
131
|
+
}
|
|
132
|
+
const base = buildBaseOptions(model, context, options, apiKey);
|
|
133
|
+
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
|
|
134
|
+
const reasoningEffort = clampedReasoning === "off" ? void 0 : clampedReasoning;
|
|
135
|
+
return stream(model, context, {
|
|
136
|
+
...base,
|
|
137
|
+
reasoningEffort
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
function normalizeAzureBaseUrl(baseUrl) {
|
|
141
|
+
const trimmed = baseUrl.trim().replace(/\/+$/, "");
|
|
142
|
+
let url;
|
|
143
|
+
try {
|
|
144
|
+
url = new URL(trimmed);
|
|
145
|
+
} catch {
|
|
146
|
+
throw new Error(`Invalid Azure OpenAI base URL: ${baseUrl}`);
|
|
147
|
+
}
|
|
148
|
+
const isAzureHost = url.hostname.endsWith(".openai.azure.com") || url.hostname.endsWith(".cognitiveservices.azure.com") || url.hostname.endsWith(".ai.azure.com");
|
|
149
|
+
const normalizedPath = url.pathname.replace(/\/+$/, "");
|
|
150
|
+
if (isAzureHost && (normalizedPath === "" || normalizedPath === "/" || normalizedPath === "/openai" || normalizedPath === "/openai/v1/responses")) {
|
|
151
|
+
url.pathname = "/openai/v1";
|
|
152
|
+
url.search = "";
|
|
153
|
+
}
|
|
154
|
+
return url.toString().replace(/\/+$/, "");
|
|
155
|
+
}
|
|
156
|
+
function buildDefaultBaseUrl(resourceName) {
|
|
157
|
+
return `https://${resourceName}.openai.azure.com/openai/v1`;
|
|
158
|
+
}
|
|
159
|
+
function resolveAzureConfig(model, options) {
|
|
160
|
+
const apiVersion = options?.azureApiVersion || getProviderEnvValue("AZURE_OPENAI_API_VERSION", options?.env) || DEFAULT_AZURE_API_VERSION;
|
|
161
|
+
const baseUrl = options?.azureBaseUrl?.trim() || getProviderEnvValue("AZURE_OPENAI_BASE_URL", options?.env)?.trim() || void 0;
|
|
162
|
+
const resourceName = options?.azureResourceName || getProviderEnvValue("AZURE_OPENAI_RESOURCE_NAME", options?.env);
|
|
163
|
+
let resolvedBaseUrl = baseUrl;
|
|
164
|
+
if (!resolvedBaseUrl && resourceName) {
|
|
165
|
+
resolvedBaseUrl = buildDefaultBaseUrl(resourceName);
|
|
166
|
+
}
|
|
167
|
+
if (!resolvedBaseUrl && model.baseUrl) {
|
|
168
|
+
resolvedBaseUrl = model.baseUrl;
|
|
169
|
+
}
|
|
170
|
+
if (!resolvedBaseUrl) {
|
|
171
|
+
throw new Error("Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.");
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
baseUrl: normalizeAzureBaseUrl(resolvedBaseUrl),
|
|
175
|
+
apiVersion
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function createClient(model, apiKey, options) {
|
|
179
|
+
const headers = { ...model.headers };
|
|
180
|
+
if (options?.headers) {
|
|
181
|
+
Object.assign(headers, options.headers);
|
|
182
|
+
}
|
|
183
|
+
const { baseUrl, apiVersion } = resolveAzureConfig(model, options);
|
|
184
|
+
return new AzureOpenAI({
|
|
185
|
+
apiKey,
|
|
186
|
+
apiVersion,
|
|
187
|
+
dangerouslyAllowBrowser: true,
|
|
188
|
+
defaultHeaders: headers,
|
|
189
|
+
baseURL: baseUrl
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function buildParams(model, context, options, deploymentName) {
|
|
193
|
+
const messages = convertResponsesMessages(model, context, AZURE_TOOL_CALL_PROVIDERS);
|
|
194
|
+
const params = {
|
|
195
|
+
model: deploymentName,
|
|
196
|
+
input: messages,
|
|
197
|
+
stream: true,
|
|
198
|
+
prompt_cache_key: clampOpenAIPromptCacheKey(options?.sessionId),
|
|
199
|
+
store: false
|
|
200
|
+
};
|
|
201
|
+
if (options?.maxTokens) {
|
|
202
|
+
params.max_output_tokens = Math.max(options.maxTokens, OPENAI_RESPONSES_MIN_OUTPUT_TOKENS);
|
|
203
|
+
}
|
|
204
|
+
if (options?.temperature !== void 0) {
|
|
205
|
+
params.temperature = options?.temperature;
|
|
206
|
+
}
|
|
207
|
+
if (context.tools && context.tools.length > 0) {
|
|
208
|
+
params.tools = convertResponsesTools(context.tools);
|
|
209
|
+
}
|
|
210
|
+
if (model.reasoning) {
|
|
211
|
+
if (options?.reasoningEffort || options?.reasoningSummary) {
|
|
212
|
+
const effort = options?.reasoningEffort ? model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort : "medium";
|
|
213
|
+
params.reasoning = {
|
|
214
|
+
effort,
|
|
215
|
+
summary: options?.reasoningSummary || "auto"
|
|
216
|
+
};
|
|
217
|
+
params.include = ["reasoning.encrypted_content"];
|
|
218
|
+
} else if (model.thinkingLevelMap?.off !== null) {
|
|
219
|
+
params.reasoning = {
|
|
220
|
+
effort: model.thinkingLevelMap?.off ?? "none"
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return params;
|
|
225
|
+
}
|
|
226
|
+
export {
|
|
227
|
+
stream,
|
|
228
|
+
streamSimple
|
|
229
|
+
};
|