openfox 1.6.14 → 1.6.15
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/dist/{auto-compaction-C4PMBB24.js → auto-compaction-JZIM73ZY.js} +5 -5
- package/dist/{chat-handler-US3QOOE4.js → chat-handler-F2A2IMQB.js} +26 -56
- package/dist/{chunk-7HLRI6JM.js → chunk-2KP34IDL.js} +161 -204
- package/dist/{chunk-N25QUEPO.js → chunk-3WHZ47PY.js} +506 -786
- package/dist/{chunk-XFXOSPYH.js → chunk-55N6FAAZ.js} +1 -1
- package/dist/{chunk-5GE3QJSZ.js → chunk-6L3X7T4K.js} +82 -160
- package/dist/{chunk-QDEKU5RL.js → chunk-F54ZJN4X.js} +38 -2
- package/dist/{chunk-3JU6H6A4.js → chunk-G4E72ST3.js} +116 -241
- package/dist/{chunk-UL4JYQKK.js → chunk-IN5EP4ZB.js} +2 -2
- package/dist/{chunk-PCOG5FQD.js → chunk-JFKYCGZ5.js} +6 -6
- package/dist/{chunk-OOIRCXAY.js → chunk-KOUMYBYM.js} +53 -112
- package/dist/{chunk-3XZ23PXM.js → chunk-OVLFEBRR.js} +76 -92
- package/dist/chunk-SN7OBEVL.js +44 -0
- package/dist/{chunk-H22VHHQ4.js → chunk-YM6VHAPM.js} +4 -4
- package/dist/{chunk-J2DHVXRX.js → chunk-ZDNXCVW4.js} +2 -2
- package/dist/cli/dev.js +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/{config-DEM6ASQM.js → config-67AX6CNS.js} +5 -5
- package/dist/{events-VDAC7E7K.js → events-2ETDOE5B.js} +3 -3
- package/dist/{folding-NDFQCISZ.js → folding-M7FMUBOL.js} +6 -4
- package/dist/{orchestrator-KZI7B5IS.js → orchestrator-SRSG2SIZ.js} +6 -6
- package/dist/package.json +13 -3
- package/dist/{processor-KBSF2HFD.js → processor-H5BQ5HQM.js} +24 -49
- package/dist/{provider-K3PHZO27.js → provider-DKGBQHUS.js} +7 -7
- package/dist/{serve-DERN4AB6.js → serve-5AY7GMN7.js} +12 -12
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +10 -10
- package/dist/{tools-PLVK22CF.js → tools-VOWNOP6V.js} +5 -5
- package/dist/{vision-fallback-NOC3YYIB.js → vision-fallback-ADYRFFD4.js} +2 -2
- package/dist/web/assets/{index-MCWDS5UQ.css → index-CNeIjdxm.css} +1 -1
- package/dist/web/assets/index-mBLhctLW.js +150 -0
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +1 -1
- package/package.json +13 -3
- package/dist/web/assets/index-Ccy2Csbl.js +0 -150
- /package/dist/{command-defaults → server/commands/defaults}/commit-push.command.md +0 -0
- /package/dist/{command-defaults → server/commands/defaults}/init.command.md +0 -0
- /package/dist/{command-defaults → server/commands/defaults}/test-ui.command.md +0 -0
- /package/dist/{skill-defaults → server/skills/defaults}/browser.skill.md +0 -0
|
@@ -29,7 +29,7 @@ function isVisionFallbackEnabled() {
|
|
|
29
29
|
async function ensureVisionFallbackConfigLoaded() {
|
|
30
30
|
if (configLoaded) return;
|
|
31
31
|
try {
|
|
32
|
-
const { loadGlobalConfig, getVisionFallback } = await import("./config-
|
|
32
|
+
const { loadGlobalConfig, getVisionFallback } = await import("./config-67AX6CNS.js");
|
|
33
33
|
const { getRuntimeConfig } = await import("./runtime-config-2XJJIMSC.js");
|
|
34
34
|
const runtimeConfig = getRuntimeConfig();
|
|
35
35
|
const mode = runtimeConfig.mode ?? "production";
|
|
@@ -135,4 +135,4 @@ export {
|
|
|
135
135
|
describeImage,
|
|
136
136
|
describeImageFromDataUrl
|
|
137
137
|
};
|
|
138
|
-
//# sourceMappingURL=chunk-
|
|
138
|
+
//# sourceMappingURL=chunk-IN5EP4ZB.js.map
|
|
@@ -27,7 +27,7 @@ Options:
|
|
|
27
27
|
}
|
|
28
28
|
async function runNetworkSetup(mode) {
|
|
29
29
|
const { loadAuthConfig, saveAuthConfig, encryptPassword } = await import("./auth-JF2HDJ6P.js");
|
|
30
|
-
const { saveGlobalConfig } = await import("./config-
|
|
30
|
+
const { saveGlobalConfig } = await import("./config-67AX6CNS.js");
|
|
31
31
|
const { getAuthKeyPath } = await import("./paths-ZRI56O63.js");
|
|
32
32
|
const existingAuth = await loadAuthConfig(mode);
|
|
33
33
|
if (existingAuth) {
|
|
@@ -88,7 +88,7 @@ async function runNetworkSetup(mode) {
|
|
|
88
88
|
console.log("\u2713 Configuration saved!\n");
|
|
89
89
|
}
|
|
90
90
|
async function runConfig(mode) {
|
|
91
|
-
const { loadGlobalConfig, getActiveProvider, getDefaultModel } = await import("./config-
|
|
91
|
+
const { loadGlobalConfig, getActiveProvider, getDefaultModel } = await import("./config-67AX6CNS.js");
|
|
92
92
|
const { getGlobalConfigPath } = await import("./paths-ZRI56O63.js");
|
|
93
93
|
const config = await loadGlobalConfig(mode);
|
|
94
94
|
const configPath = getGlobalConfigPath(mode);
|
|
@@ -143,18 +143,18 @@ async function runCli(options) {
|
|
|
143
143
|
break;
|
|
144
144
|
}
|
|
145
145
|
case "provider": {
|
|
146
|
-
const { runProviderCommand } = await import("./provider-
|
|
146
|
+
const { runProviderCommand } = await import("./provider-DKGBQHUS.js");
|
|
147
147
|
const [, subcommand] = positionals;
|
|
148
148
|
await runProviderCommand(mode, subcommand);
|
|
149
149
|
break;
|
|
150
150
|
}
|
|
151
151
|
default: {
|
|
152
|
-
const { configFileExists } = await import("./config-
|
|
152
|
+
const { configFileExists } = await import("./config-67AX6CNS.js");
|
|
153
153
|
const configExists = await configFileExists(mode);
|
|
154
154
|
if (!configExists) {
|
|
155
155
|
await runNetworkSetup(mode);
|
|
156
156
|
}
|
|
157
|
-
const { runServe } = await import("./serve-
|
|
157
|
+
const { runServe } = await import("./serve-5AY7GMN7.js");
|
|
158
158
|
await runServe({
|
|
159
159
|
mode,
|
|
160
160
|
port: values.port ? parseInt(values.port) : void 0,
|
|
@@ -167,4 +167,4 @@ async function runCli(options) {
|
|
|
167
167
|
export {
|
|
168
168
|
runCli
|
|
169
169
|
};
|
|
170
|
-
//# sourceMappingURL=chunk-
|
|
170
|
+
//# sourceMappingURL=chunk-JFKYCGZ5.js.map
|
|
@@ -4,40 +4,61 @@ import {
|
|
|
4
4
|
detectBackend,
|
|
5
5
|
detectModel,
|
|
6
6
|
setLlmStatus
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-OVLFEBRR.js";
|
|
8
8
|
import {
|
|
9
9
|
logger
|
|
10
10
|
} from "./chunk-PNBH3RAX.js";
|
|
11
11
|
|
|
12
12
|
// src/server/provider-manager.ts
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
function normalizeModelId(s) {
|
|
14
|
+
return s.toLowerCase().replace(/[-_\s:.]+/g, "");
|
|
15
|
+
}
|
|
16
|
+
async function fetchModelsFromBackend(url, apiKey) {
|
|
17
|
+
const headers = { "Content-Type": "application/json" };
|
|
18
|
+
if (apiKey) {
|
|
19
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
20
|
+
}
|
|
15
21
|
try {
|
|
16
|
-
const
|
|
17
|
-
"Content-Type": "application/json"
|
|
18
|
-
};
|
|
19
|
-
if (apiKey) {
|
|
20
|
-
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
21
|
-
}
|
|
22
|
-
const response = await fetch(url, {
|
|
23
|
-
method: "GET",
|
|
24
|
-
headers,
|
|
25
|
-
signal: AbortSignal.timeout(1e4)
|
|
26
|
-
});
|
|
22
|
+
const response = await fetch(url, { method: "GET", headers, signal: AbortSignal.timeout(1e4) });
|
|
27
23
|
if (!response.ok) {
|
|
28
24
|
logger.debug("Failed to fetch models", { url, status: response.status });
|
|
29
25
|
return [];
|
|
30
26
|
}
|
|
31
27
|
const data = await response.json();
|
|
32
28
|
if (data.data && Array.isArray(data.data)) {
|
|
33
|
-
return data.data.map((m) =>
|
|
29
|
+
return data.data.map((m) => ({
|
|
30
|
+
id: m.id,
|
|
31
|
+
contextWindow: m.max_model_len ?? void 0
|
|
32
|
+
}));
|
|
34
33
|
}
|
|
35
34
|
return [];
|
|
36
35
|
} catch (error) {
|
|
37
|
-
logger.debug("Error fetching models
|
|
36
|
+
logger.debug("Error fetching models", { url, error: error instanceof Error ? error.message : String(error) });
|
|
38
37
|
return [];
|
|
39
38
|
}
|
|
40
39
|
}
|
|
40
|
+
function mergeModelsWithUserOverrides(backendModels, userModels) {
|
|
41
|
+
const normalizedUserIdMap = new Map(userModels.map((m) => [normalizeModelId(m.id), m]));
|
|
42
|
+
const updatedModels = backendModels.map((backendModel) => {
|
|
43
|
+
const existingUserModel = normalizedUserIdMap.get(normalizeModelId(backendModel.id));
|
|
44
|
+
if (existingUserModel) {
|
|
45
|
+
return { ...existingUserModel, id: backendModel.id };
|
|
46
|
+
}
|
|
47
|
+
return backendModel;
|
|
48
|
+
});
|
|
49
|
+
const normalizedBackendIds = new Set(backendModels.map((m) => normalizeModelId(m.id)));
|
|
50
|
+
for (const userModel of userModels) {
|
|
51
|
+
if (!normalizedBackendIds.has(normalizeModelId(userModel.id))) {
|
|
52
|
+
updatedModels.push(userModel);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return updatedModels;
|
|
56
|
+
}
|
|
57
|
+
async function fetchAvailableModelsFromBackend(baseUrl, apiKey) {
|
|
58
|
+
const url = baseUrl.includes("/v1") ? `${baseUrl}/models` : `${baseUrl}/v1/models`;
|
|
59
|
+
const models = await fetchModelsFromBackend(url, apiKey);
|
|
60
|
+
return models.map((m) => m.id);
|
|
61
|
+
}
|
|
41
62
|
async function fetchModelsWithContext(baseUrl, apiKey, backend) {
|
|
42
63
|
logger.info("fetchModelsWithContext called", { baseUrl, apiKey: !!apiKey, backend });
|
|
43
64
|
if (backend === "ollama") {
|
|
@@ -45,44 +66,16 @@ async function fetchModelsWithContext(baseUrl, apiKey, backend) {
|
|
|
45
66
|
return fetchOllamaModelsWithContext(baseUrl, apiKey);
|
|
46
67
|
}
|
|
47
68
|
const isOpenCodeGo = baseUrl.includes("opencode.ai/zen/go");
|
|
48
|
-
|
|
49
|
-
if (isOpenCodeGo) {
|
|
50
|
-
url = baseUrl.replace("/zen/go", "/zen").replace(/\/v1$/, "") + "/v1/models";
|
|
51
|
-
logger.info("OpenCode Go detected, using alternate models endpoint", { original: baseUrl, modelsUrl: url });
|
|
52
|
-
} else {
|
|
53
|
-
url = baseUrl.includes("/v1") ? `${baseUrl}/models` : `${baseUrl}/v1/models`;
|
|
54
|
-
}
|
|
69
|
+
const url = isOpenCodeGo ? baseUrl.replace("/zen/go", "/zen").replace(/\/v1$/, "") + "/v1/models" : baseUrl.includes("/v1") ? `${baseUrl}/models` : `${baseUrl}/v1/models`;
|
|
55
70
|
logger.info("Fetching models via /v1/models", { url });
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
method: "GET",
|
|
65
|
-
headers,
|
|
66
|
-
signal: AbortSignal.timeout(1e4)
|
|
67
|
-
});
|
|
68
|
-
if (!response.ok) {
|
|
69
|
-
logger.debug("Failed to fetch models with context", { url, status: response.status });
|
|
70
|
-
return [];
|
|
71
|
-
}
|
|
72
|
-
const data = await response.json();
|
|
73
|
-
if (data.data && Array.isArray(data.data)) {
|
|
74
|
-
logger.info("Fetched models from /v1/models", { count: data.data.length, models: data.data.map((m) => m.id) });
|
|
75
|
-
return data.data.map((m) => ({
|
|
76
|
-
id: m.id,
|
|
77
|
-
contextWindow: m.max_model_len ?? 2e5,
|
|
78
|
-
source: m.max_model_len ? "backend" : "default"
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
|
-
return [];
|
|
82
|
-
} catch (error) {
|
|
83
|
-
logger.debug("Error fetching models with context", { url, error: error instanceof Error ? error.message : String(error) });
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
71
|
+
const models = await fetchModelsFromBackend(url, apiKey);
|
|
72
|
+
if (models.length === 0) return [];
|
|
73
|
+
logger.info("Fetched models from /v1/models", { count: models.length });
|
|
74
|
+
return models.map((m) => ({
|
|
75
|
+
id: m.id,
|
|
76
|
+
contextWindow: m.contextWindow ?? 2e5,
|
|
77
|
+
source: m.contextWindow ? "backend" : "default"
|
|
78
|
+
}));
|
|
86
79
|
}
|
|
87
80
|
async function fetchOllamaModelsWithContext(baseUrl, apiKey) {
|
|
88
81
|
const tagsUrl = `${baseUrl}/api/tags`;
|
|
@@ -217,34 +210,10 @@ function createProviderManager(config) {
|
|
|
217
210
|
const backend = provider.backend;
|
|
218
211
|
logger.info("activateProvider fetching models", { providerId, providerName: provider.name, url, backend });
|
|
219
212
|
const modelsWithContext = await fetchModelsWithContext(url, provider.apiKey, backend);
|
|
220
|
-
const normalize = (s) => s.toLowerCase().replace(/[-_\s:.]+/g, "");
|
|
221
213
|
const userModels = provider.models.filter((m) => m.source === "user");
|
|
222
|
-
logger.debug("activateProvider", { providerId, backendModelsCount: modelsWithContext.length, userModelsCount: userModels.length
|
|
214
|
+
logger.debug("activateProvider", { providerId, backendModelsCount: modelsWithContext.length, userModelsCount: userModels.length });
|
|
223
215
|
if (modelsWithContext.length > 0) {
|
|
224
|
-
const updatedModels = modelsWithContext
|
|
225
|
-
let existingModel = provider.models.find((pm) => pm.id === m.id);
|
|
226
|
-
if (!existingModel) {
|
|
227
|
-
const normalizedId = normalize(m.id);
|
|
228
|
-
existingModel = provider.models.find((pm) => {
|
|
229
|
-
if (pm.source !== "user") return false;
|
|
230
|
-
return normalize(pm.id) === normalizedId;
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
if (existingModel && existingModel.source === "user") {
|
|
234
|
-
return { ...existingModel, id: m.id };
|
|
235
|
-
}
|
|
236
|
-
return m;
|
|
237
|
-
});
|
|
238
|
-
for (const userModel of userModels) {
|
|
239
|
-
const normalizedUserId = normalize(userModel.id);
|
|
240
|
-
const matchedInUpdated = updatedModels.some((m) => {
|
|
241
|
-
const normalizedBackendId = normalize(m.id);
|
|
242
|
-
return normalizedBackendId === normalizedUserId;
|
|
243
|
-
});
|
|
244
|
-
if (!matchedInUpdated) {
|
|
245
|
-
updatedModels.push(userModel);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
216
|
+
const updatedModels = mergeModelsWithUserOverrides(modelsWithContext, userModels);
|
|
248
217
|
providers = providers.map((p) => p.id === providerId ? { ...p, models: updatedModels } : p);
|
|
249
218
|
} else if (userModels.length > 0) {
|
|
250
219
|
logger.debug("Backend unavailable during provider switch, preserving user models", { providerId, userModelsCount: userModels.length });
|
|
@@ -403,52 +372,24 @@ function createProviderManager(config) {
|
|
|
403
372
|
const backend = provider.backend;
|
|
404
373
|
logger.info("refreshProviderModels fetching models", { providerId, providerName: provider.name, url, backend });
|
|
405
374
|
const modelsWithContext = await fetchModelsWithContext(url, provider.apiKey, backend);
|
|
406
|
-
const normalize = (s) => s.toLowerCase().replace(/[-_\s:.]+/g, "");
|
|
407
375
|
const userModels = provider.models.filter((m) => m.source === "user");
|
|
408
|
-
|
|
409
|
-
logger.info("refreshProviderModels", { providerId, userModelsCount: userModels.length, backendModelsCount: modelsWithContext.length, userModels: userModels.map((m) => ({ id: m.id, contextWindow: m.contextWindow, source: m.source })), allModelsBefore, backendModels: modelsWithContext });
|
|
376
|
+
logger.info("refreshProviderModels", { providerId, userModelsCount: userModels.length, backendModelsCount: modelsWithContext.length });
|
|
410
377
|
if (modelsWithContext.length === 0) {
|
|
411
378
|
setLlmStatus("disconnected");
|
|
412
379
|
if (userModels.length > 0) {
|
|
413
380
|
logger.debug("Backend unavailable, preserving user models", { providerId, userModels: userModels.map((m) => ({ id: m.id, contextWindow: m.contextWindow })) });
|
|
414
381
|
providers = providers.map((p) => p.id === providerId ? { ...p, models: userModels } : p);
|
|
415
|
-
const preservedProvider = providers.find((p) => p.id === providerId);
|
|
416
|
-
logger.debug("After preservation", { providerId, models: preservedProvider?.models.map((m) => ({ id: m.id, contextWindow: m.contextWindow, source: m.source })) });
|
|
417
382
|
return { success: true };
|
|
418
383
|
}
|
|
419
384
|
return { success: false, error: "No models returned from backend" };
|
|
420
385
|
}
|
|
421
386
|
setLlmStatus("connected");
|
|
422
|
-
const updatedModels = modelsWithContext
|
|
423
|
-
let existingModel = provider.models.find((pm) => pm.id === m.id);
|
|
424
|
-
if (!existingModel) {
|
|
425
|
-
const normalizedId = normalize(m.id);
|
|
426
|
-
existingModel = provider.models.find((pm) => {
|
|
427
|
-
if (pm.source !== "user") return false;
|
|
428
|
-
return normalize(pm.id) === normalizedId;
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
if (existingModel && existingModel.source === "user") {
|
|
432
|
-
return { ...existingModel, id: m.id };
|
|
433
|
-
}
|
|
434
|
-
return m;
|
|
435
|
-
});
|
|
436
|
-
for (const userModel of userModels) {
|
|
437
|
-
const normalizedUserId = normalize(userModel.id);
|
|
438
|
-
const matchedInUpdated = updatedModels.some((m) => {
|
|
439
|
-
const normalizedBackendId = normalize(m.id);
|
|
440
|
-
return normalizedBackendId === normalizedUserId;
|
|
441
|
-
});
|
|
442
|
-
logger.debug("User model match check", { userModelId: userModel.id, normalizedUserId, matchedInUpdated, updatedModelsIds: updatedModels.map((m) => m.id) });
|
|
443
|
-
if (!matchedInUpdated) {
|
|
444
|
-
updatedModels.push(userModel);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
387
|
+
const updatedModels = mergeModelsWithUserOverrides(modelsWithContext, userModels);
|
|
447
388
|
providers = providers.map((p) => p.id === providerId ? { ...p, models: updatedModels } : p);
|
|
448
389
|
const { providerId: currentProviderId, model: currentModel } = parseDefaultModelSelection(defaultModelSelection);
|
|
449
390
|
if (currentProviderId === providerId && currentModel) {
|
|
450
|
-
const normalizedCurrentModel =
|
|
451
|
-
const matchedModel = updatedModels.find((m) =>
|
|
391
|
+
const normalizedCurrentModel = normalizeModelId(currentModel);
|
|
392
|
+
const matchedModel = updatedModels.find((m) => normalizeModelId(m.id) === normalizedCurrentModel);
|
|
452
393
|
if (matchedModel && matchedModel.id !== currentModel) {
|
|
453
394
|
defaultModelSelection = `${providerId}/${matchedModel.id}`;
|
|
454
395
|
logger.debug("Updated defaultModelSelection after fuzzy match", { from: currentModel, to: matchedModel.id });
|
|
@@ -465,4 +406,4 @@ export {
|
|
|
465
406
|
parseDefaultModelSelection,
|
|
466
407
|
createProviderManager
|
|
467
408
|
};
|
|
468
|
-
//# sourceMappingURL=chunk-
|
|
409
|
+
//# sourceMappingURL=chunk-KOUMYBYM.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
describeImageFromDataUrl,
|
|
3
3
|
ensureVisionFallbackConfigLoaded
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-IN5EP4ZB.js";
|
|
5
5
|
import {
|
|
6
6
|
logger
|
|
7
7
|
} from "./chunk-PNBH3RAX.js";
|
|
@@ -493,6 +493,37 @@ function getModelProfile(modelName) {
|
|
|
493
493
|
}
|
|
494
494
|
|
|
495
495
|
// src/server/llm/client-pure.ts
|
|
496
|
+
function buildAttachmentContent(msgContent, attachments, modelSupportsVision) {
|
|
497
|
+
const content = [];
|
|
498
|
+
if (msgContent?.trim()) {
|
|
499
|
+
content.push({ type: "text", text: msgContent });
|
|
500
|
+
}
|
|
501
|
+
for (const attachment of attachments) {
|
|
502
|
+
content.push(convertAttachmentSync(attachment, modelSupportsVision));
|
|
503
|
+
}
|
|
504
|
+
return content;
|
|
505
|
+
}
|
|
506
|
+
async function convertMessagesWithOptions(messages, profile, visionFallbackEnabled, signal, onVisionFallbackStart, onVisionFallbackDone) {
|
|
507
|
+
const modelSupportsVision = profile.supportsVision ?? false;
|
|
508
|
+
const options = {
|
|
509
|
+
modelSupportsVision,
|
|
510
|
+
visionFallbackEnabled,
|
|
511
|
+
signal,
|
|
512
|
+
onVisionFallbackStart,
|
|
513
|
+
onVisionFallbackDone
|
|
514
|
+
};
|
|
515
|
+
return needsVisionFallback(messages, modelSupportsVision, visionFallbackEnabled) ? await convertMessagesWithFallback(messages, options) : convertMessages(messages, { modelSupportsVision, visionFallbackEnabled: false });
|
|
516
|
+
}
|
|
517
|
+
function convertToolCalls(toolCalls) {
|
|
518
|
+
return toolCalls.map((toolCall) => ({
|
|
519
|
+
id: toolCall.id,
|
|
520
|
+
type: "function",
|
|
521
|
+
function: {
|
|
522
|
+
name: toolCall.name,
|
|
523
|
+
arguments: JSON.stringify(toolCall.arguments)
|
|
524
|
+
}
|
|
525
|
+
}));
|
|
526
|
+
}
|
|
496
527
|
function convertAttachmentSync(attachment, modelSupportsVision) {
|
|
497
528
|
if (modelSupportsVision) {
|
|
498
529
|
return {
|
|
@@ -505,6 +536,13 @@ function convertAttachmentSync(attachment, modelSupportsVision) {
|
|
|
505
536
|
text: `[Image: ${attachment.filename || "image"}] (vision not supported, cannot describe)`
|
|
506
537
|
};
|
|
507
538
|
}
|
|
539
|
+
function createAttachmentForConversion(data, filename, id) {
|
|
540
|
+
return {
|
|
541
|
+
data,
|
|
542
|
+
...filename !== void 0 && { filename },
|
|
543
|
+
...id !== void 0 && { id }
|
|
544
|
+
};
|
|
545
|
+
}
|
|
508
546
|
async function convertAttachmentWithFallback(attachment, options) {
|
|
509
547
|
logger.debug("[VisionFallback] convertAttachmentWithFallback called", { filename: attachment.filename, id: attachment.id, hasCallbacks: !!options.onVisionFallbackStart });
|
|
510
548
|
if (options.modelSupportsVision) {
|
|
@@ -534,6 +572,20 @@ async function convertAttachmentWithFallback(attachment, options) {
|
|
|
534
572
|
text: `[Image: ${attachment.filename || "image"}] ${description}`
|
|
535
573
|
};
|
|
536
574
|
}
|
|
575
|
+
async function buildAttachmentContentWithFallback(msgContent, attachments, options) {
|
|
576
|
+
const content = [];
|
|
577
|
+
if (msgContent?.trim()) {
|
|
578
|
+
content.push({ type: "text", text: msgContent });
|
|
579
|
+
}
|
|
580
|
+
for (const attachment of attachments) {
|
|
581
|
+
const convertedContent = await convertAttachmentWithFallback(
|
|
582
|
+
createAttachmentForConversion(attachment.data, attachment.filename, attachment.id),
|
|
583
|
+
options
|
|
584
|
+
);
|
|
585
|
+
content.push(convertedContent);
|
|
586
|
+
}
|
|
587
|
+
return content;
|
|
588
|
+
}
|
|
537
589
|
function convertMessages(messages, options) {
|
|
538
590
|
const filtered = messages.filter((msg) => {
|
|
539
591
|
return !(msg.role === "assistant" && !msg.content?.trim() && (!msg.toolCalls || msg.toolCalls.length === 0));
|
|
@@ -541,13 +593,7 @@ function convertMessages(messages, options) {
|
|
|
541
593
|
return filtered.map((msg) => {
|
|
542
594
|
if (msg.role === "tool") {
|
|
543
595
|
if (msg.attachments && msg.attachments.length > 0) {
|
|
544
|
-
const content =
|
|
545
|
-
if (msg.content?.trim()) {
|
|
546
|
-
content.push({ type: "text", text: msg.content });
|
|
547
|
-
}
|
|
548
|
-
for (const attachment of msg.attachments) {
|
|
549
|
-
content.push(convertAttachmentSync(attachment, options.modelSupportsVision));
|
|
550
|
-
}
|
|
596
|
+
const content = buildAttachmentContent(msg.content, msg.attachments, options.modelSupportsVision);
|
|
551
597
|
return {
|
|
552
598
|
role: "tool",
|
|
553
599
|
content,
|
|
@@ -564,24 +610,11 @@ function convertMessages(messages, options) {
|
|
|
564
610
|
return {
|
|
565
611
|
role: "assistant",
|
|
566
612
|
content: msg.content || null,
|
|
567
|
-
tool_calls: msg.toolCalls
|
|
568
|
-
id: toolCall.id,
|
|
569
|
-
type: "function",
|
|
570
|
-
function: {
|
|
571
|
-
name: toolCall.name,
|
|
572
|
-
arguments: JSON.stringify(toolCall.arguments)
|
|
573
|
-
}
|
|
574
|
-
}))
|
|
613
|
+
tool_calls: convertToolCalls(msg.toolCalls)
|
|
575
614
|
};
|
|
576
615
|
}
|
|
577
616
|
if (msg.role === "user" && msg.attachments && msg.attachments.length > 0) {
|
|
578
|
-
const content =
|
|
579
|
-
if (msg.content?.trim()) {
|
|
580
|
-
content.push({ type: "text", text: msg.content });
|
|
581
|
-
}
|
|
582
|
-
for (const attachment of msg.attachments) {
|
|
583
|
-
content.push(convertAttachmentSync(attachment, options.modelSupportsVision));
|
|
584
|
-
}
|
|
617
|
+
const content = buildAttachmentContent(msg.content, msg.attachments, options.modelSupportsVision);
|
|
585
618
|
return {
|
|
586
619
|
role: "user",
|
|
587
620
|
content
|
|
@@ -602,17 +635,7 @@ async function convertMessagesWithFallback(messages, options) {
|
|
|
602
635
|
for (const msg of filtered) {
|
|
603
636
|
if (msg.role === "tool") {
|
|
604
637
|
if (msg.attachments && msg.attachments.length > 0) {
|
|
605
|
-
const content =
|
|
606
|
-
if (msg.content?.trim()) {
|
|
607
|
-
content.push({ type: "text", text: msg.content });
|
|
608
|
-
}
|
|
609
|
-
for (const attachment of msg.attachments) {
|
|
610
|
-
const convertedContent = await convertAttachmentWithFallback(
|
|
611
|
-
{ data: attachment.data, filename: attachment.filename, id: attachment.id },
|
|
612
|
-
options
|
|
613
|
-
);
|
|
614
|
-
content.push(convertedContent);
|
|
615
|
-
}
|
|
638
|
+
const content = await buildAttachmentContentWithFallback(msg.content, msg.attachments, options);
|
|
616
639
|
converted.push({
|
|
617
640
|
role: "tool",
|
|
618
641
|
content,
|
|
@@ -631,29 +654,12 @@ async function convertMessagesWithFallback(messages, options) {
|
|
|
631
654
|
converted.push({
|
|
632
655
|
role: "assistant",
|
|
633
656
|
content: msg.content || null,
|
|
634
|
-
tool_calls: msg.toolCalls
|
|
635
|
-
id: toolCall.id,
|
|
636
|
-
type: "function",
|
|
637
|
-
function: {
|
|
638
|
-
name: toolCall.name,
|
|
639
|
-
arguments: JSON.stringify(toolCall.arguments)
|
|
640
|
-
}
|
|
641
|
-
}))
|
|
657
|
+
tool_calls: convertToolCalls(msg.toolCalls)
|
|
642
658
|
});
|
|
643
659
|
continue;
|
|
644
660
|
}
|
|
645
661
|
if (msg.role === "user" && msg.attachments && msg.attachments.length > 0) {
|
|
646
|
-
const content =
|
|
647
|
-
if (msg.content?.trim()) {
|
|
648
|
-
content.push({ type: "text", text: msg.content });
|
|
649
|
-
}
|
|
650
|
-
for (const attachment of msg.attachments) {
|
|
651
|
-
const convertedContent = await convertAttachmentWithFallback(
|
|
652
|
-
{ data: attachment.data, filename: attachment.filename, id: attachment.id },
|
|
653
|
-
options
|
|
654
|
-
);
|
|
655
|
-
content.push(convertedContent);
|
|
656
|
-
}
|
|
662
|
+
const content = await buildAttachmentContentWithFallback(msg.content, msg.attachments, options);
|
|
657
663
|
converted.push({
|
|
658
664
|
role: "user",
|
|
659
665
|
content
|
|
@@ -690,18 +696,15 @@ function needsVisionFallback(messages, modelSupportsVision, visionFallbackEnable
|
|
|
690
696
|
});
|
|
691
697
|
return result;
|
|
692
698
|
}
|
|
693
|
-
async function
|
|
694
|
-
const
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
const options = {
|
|
698
|
-
modelSupportsVision,
|
|
699
|
+
async function buildChatCompletionCreateParams(model, request, profile, capabilities, disableThinking, visionFallbackEnabled, isStreaming, onVisionFallbackStart, onVisionFallbackDone) {
|
|
700
|
+
const convertedMessages = await convertMessagesWithOptions(
|
|
701
|
+
request.messages,
|
|
702
|
+
profile,
|
|
699
703
|
visionFallbackEnabled,
|
|
700
|
-
|
|
704
|
+
request.signal,
|
|
701
705
|
onVisionFallbackStart,
|
|
702
706
|
onVisionFallbackDone
|
|
703
|
-
|
|
704
|
-
const convertedMessages = needsVisionFallback(messages, modelSupportsVision, visionFallbackEnabled) ? await convertMessagesWithFallback(messages, options) : convertMessages(messages, { modelSupportsVision, visionFallbackEnabled: false });
|
|
707
|
+
);
|
|
705
708
|
const params = {
|
|
706
709
|
model,
|
|
707
710
|
messages: convertedMessages,
|
|
@@ -710,45 +713,26 @@ async function buildNonStreamingCreateParams(input) {
|
|
|
710
713
|
temperature: request.temperature ?? profile.temperature,
|
|
711
714
|
max_tokens: request.maxTokens ?? profile.defaultMaxTokens,
|
|
712
715
|
top_p: profile.topP,
|
|
713
|
-
stream:
|
|
716
|
+
stream: isStreaming,
|
|
717
|
+
...isStreaming ? { stream_options: { include_usage: true } } : {}
|
|
714
718
|
};
|
|
715
719
|
if (capabilities.supportsTopK && profile.topK !== void 0) {
|
|
716
720
|
;
|
|
717
721
|
params["top_k"] = profile.topK;
|
|
718
722
|
}
|
|
719
|
-
|
|
723
|
+
const shouldDisableThinking = isStreaming ? disableThinking || request.disableThinking : disableThinking;
|
|
724
|
+
if (capabilities.supportsChatTemplateKwargs && profile.supportsReasoning && shouldDisableThinking) {
|
|
720
725
|
;
|
|
721
726
|
params["chat_template_kwargs"] = { enable_thinking: false };
|
|
722
727
|
}
|
|
723
728
|
return params;
|
|
724
729
|
}
|
|
725
|
-
async function
|
|
730
|
+
async function buildCreateParamsFromInput(input, isStreaming) {
|
|
726
731
|
const { model, request, profile, capabilities, disableThinking, visionFallbackEnabled = false, onVisionFallbackStart, onVisionFallbackDone } = input;
|
|
727
|
-
|
|
728
|
-
const modelSupportsVision = profile.supportsVision ?? false;
|
|
729
|
-
const options = { modelSupportsVision, visionFallbackEnabled, signal: request.signal, onVisionFallbackStart, onVisionFallbackDone };
|
|
730
|
-
const convertedMessages = needsVisionFallback(messages, modelSupportsVision, visionFallbackEnabled) ? await convertMessagesWithFallback(messages, options) : convertMessages(messages, { modelSupportsVision, visionFallbackEnabled: false });
|
|
731
|
-
const params = {
|
|
732
|
-
model,
|
|
733
|
-
messages: convertedMessages,
|
|
734
|
-
...request.tools ? { tools: convertTools(request.tools) } : {},
|
|
735
|
-
...request.toolChoice ? { tool_choice: request.toolChoice } : {},
|
|
736
|
-
temperature: request.temperature ?? profile.temperature,
|
|
737
|
-
max_tokens: request.maxTokens ?? profile.defaultMaxTokens,
|
|
738
|
-
top_p: profile.topP,
|
|
739
|
-
stream: true,
|
|
740
|
-
stream_options: { include_usage: true }
|
|
741
|
-
};
|
|
742
|
-
if (capabilities.supportsTopK && profile.topK !== void 0) {
|
|
743
|
-
;
|
|
744
|
-
params["top_k"] = profile.topK;
|
|
745
|
-
}
|
|
746
|
-
if (capabilities.supportsChatTemplateKwargs && profile.supportsReasoning && (disableThinking || request.disableThinking)) {
|
|
747
|
-
;
|
|
748
|
-
params["chat_template_kwargs"] = { enable_thinking: false };
|
|
749
|
-
}
|
|
750
|
-
return params;
|
|
732
|
+
return buildChatCompletionCreateParams(model, request, profile, capabilities, !!disableThinking, visionFallbackEnabled, isStreaming, onVisionFallbackStart, onVisionFallbackDone);
|
|
751
733
|
}
|
|
734
|
+
var buildNonStreamingCreateParams = (input) => buildCreateParamsFromInput(input, false);
|
|
735
|
+
var buildStreamingCreateParams = (input) => buildCreateParamsFromInput(input, true);
|
|
752
736
|
function mapFinishReason(reason) {
|
|
753
737
|
switch (reason) {
|
|
754
738
|
case "stop":
|
|
@@ -828,7 +812,7 @@ function createLLMClient(config, initialBackend = "unknown") {
|
|
|
828
812
|
try {
|
|
829
813
|
const shouldDisableThinking = disableThinking || request.disableThinking === true;
|
|
830
814
|
await ensureVisionFallbackConfigLoaded();
|
|
831
|
-
const { isVisionFallbackEnabled } = await import("./vision-fallback-
|
|
815
|
+
const { isVisionFallbackEnabled } = await import("./vision-fallback-ADYRFFD4.js");
|
|
832
816
|
const paramsOptions = {
|
|
833
817
|
model,
|
|
834
818
|
request,
|
|
@@ -906,7 +890,7 @@ function createLLMClient(config, initialBackend = "unknown") {
|
|
|
906
890
|
});
|
|
907
891
|
try {
|
|
908
892
|
await ensureVisionFallbackConfigLoaded();
|
|
909
|
-
const { isVisionFallbackEnabled } = await import("./vision-fallback-
|
|
893
|
+
const { isVisionFallbackEnabled } = await import("./vision-fallback-ADYRFFD4.js");
|
|
910
894
|
const shouldDisableThinking = disableThinking || request.disableThinking === true;
|
|
911
895
|
const createParams = await buildStreamingCreateParams({
|
|
912
896
|
model,
|
|
@@ -1122,4 +1106,4 @@ export {
|
|
|
1122
1106
|
setLlmStatus,
|
|
1123
1107
|
clearModelCache
|
|
1124
1108
|
};
|
|
1125
|
-
//# sourceMappingURL=chunk-
|
|
1109
|
+
//# sourceMappingURL=chunk-OVLFEBRR.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEventStore
|
|
3
|
+
} from "./chunk-6L3X7T4K.js";
|
|
4
|
+
import {
|
|
5
|
+
createContextStateMessage
|
|
6
|
+
} from "./chunk-NJWPSSRW.js";
|
|
7
|
+
|
|
8
|
+
// src/server/utils/session-utils.ts
|
|
9
|
+
function getSessionMessageCount(sessionId) {
|
|
10
|
+
const eventStore = getEventStore();
|
|
11
|
+
const events = eventStore.getEvents(sessionId);
|
|
12
|
+
let count = 0;
|
|
13
|
+
for (const event of events) {
|
|
14
|
+
if (event.type === "message.start") {
|
|
15
|
+
const data = event.data;
|
|
16
|
+
if (data.role === "user") {
|
|
17
|
+
count++;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return count;
|
|
22
|
+
}
|
|
23
|
+
function finalizeTurnCompletion(sessionId, sessionManager, broadcastForSession) {
|
|
24
|
+
sessionManager.setRunning(sessionId, false);
|
|
25
|
+
const contextState = sessionManager.getContextState(sessionId);
|
|
26
|
+
broadcastForSession(sessionId, createContextStateMessage(contextState));
|
|
27
|
+
}
|
|
28
|
+
function buildRunChatTurnParams(params) {
|
|
29
|
+
return {
|
|
30
|
+
sessionManager: params.sessionManager,
|
|
31
|
+
sessionId: params.sessionId,
|
|
32
|
+
llmClient: params.llmClient,
|
|
33
|
+
signal: params.signal,
|
|
34
|
+
onMessage: params.onMessage,
|
|
35
|
+
...params.statsIdentity ? { statsIdentity: params.statsIdentity } : {}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
getSessionMessageCount,
|
|
41
|
+
finalizeTurnCompletion,
|
|
42
|
+
buildRunChatTurnParams
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=chunk-SN7OBEVL.js.map
|
|
@@ -13,14 +13,14 @@ import {
|
|
|
13
13
|
getToolRegistryForAgent,
|
|
14
14
|
loadAllAgentsDefault,
|
|
15
15
|
runTopLevelAgentLoop
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-3WHZ47PY.js";
|
|
17
17
|
import {
|
|
18
18
|
getCurrentContextWindowId,
|
|
19
19
|
getEventStore
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-6L3X7T4K.js";
|
|
21
21
|
import {
|
|
22
22
|
buildSnapshotFromSessionState
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-2KP34IDL.js";
|
|
24
24
|
import {
|
|
25
25
|
logger
|
|
26
26
|
} from "./chunk-PNBH3RAX.js";
|
|
@@ -293,4 +293,4 @@ export {
|
|
|
293
293
|
runBuilderTurn,
|
|
294
294
|
runVerifierTurn
|
|
295
295
|
};
|
|
296
|
-
//# sourceMappingURL=chunk-
|
|
296
|
+
//# sourceMappingURL=chunk-YM6VHAPM.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
detectBackend,
|
|
3
3
|
detectModel
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-OVLFEBRR.js";
|
|
5
5
|
import {
|
|
6
6
|
getGlobalConfigPath
|
|
7
7
|
} from "./chunk-R4HADRYO.js";
|
|
@@ -380,4 +380,4 @@ export {
|
|
|
380
380
|
activateProvider,
|
|
381
381
|
mergeConfigs
|
|
382
382
|
};
|
|
383
|
-
//# sourceMappingURL=chunk-
|
|
383
|
+
//# sourceMappingURL=chunk-ZDNXCVW4.js.map
|
package/dist/cli/dev.js
CHANGED