openfox 1.6.13 → 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.
Files changed (41) hide show
  1. package/dist/{ask-JQQNGB5K.js → ask-3RK5YJZE.js} +2 -2
  2. package/dist/{auto-compaction-QPFQEWJG.js → auto-compaction-JZIM73ZY.js} +6 -6
  3. package/dist/{chat-handler-FDHHTHS3.js → chat-handler-F2A2IMQB.js} +27 -57
  4. package/dist/{chunk-5LDTVERY.js → chunk-22CTURMH.js} +1 -3
  5. package/dist/{chunk-WQ4W5H6A.js → chunk-2KP34IDL.js} +163 -205
  6. package/dist/{chunk-POJO7A5H.js → chunk-3WHZ47PY.js} +511 -793
  7. package/dist/{chunk-XFXOSPYH.js → chunk-55N6FAAZ.js} +1 -1
  8. package/dist/{chunk-ZRDRYL6W.js → chunk-6L3X7T4K.js} +82 -160
  9. package/dist/{chunk-QDEKU5RL.js → chunk-F54ZJN4X.js} +38 -2
  10. package/dist/{chunk-7T2CA2C6.js → chunk-G4E72ST3.js} +117 -242
  11. package/dist/{chunk-AKFLBPPY.js → chunk-IN5EP4ZB.js} +2 -2
  12. package/dist/{chunk-HCZT5BDI.js → chunk-JFKYCGZ5.js} +6 -6
  13. package/dist/{chunk-ZHGP4PBJ.js → chunk-KOUMYBYM.js} +53 -112
  14. package/dist/{chunk-E6FCNB3B.js → chunk-OVLFEBRR.js} +76 -94
  15. package/dist/chunk-SN7OBEVL.js +44 -0
  16. package/dist/{chunk-LMIBGLOB.js → chunk-YM6VHAPM.js} +4 -4
  17. package/dist/{chunk-TXQNRBMZ.js → chunk-ZDNXCVW4.js} +2 -2
  18. package/dist/cli/dev.js +1 -1
  19. package/dist/cli/index.js +1 -1
  20. package/dist/{config-TUA644W4.js → config-67AX6CNS.js} +5 -5
  21. package/dist/{events-EILPWKYE.js → events-2ETDOE5B.js} +3 -3
  22. package/dist/{folding-NZYOXNKK.js → folding-M7FMUBOL.js} +6 -4
  23. package/dist/{orchestrator-YKQJI3PH.js → orchestrator-SRSG2SIZ.js} +7 -7
  24. package/dist/package.json +14 -3
  25. package/dist/{processor-JU7MSV4F.js → processor-H5BQ5HQM.js} +24 -49
  26. package/dist/{provider-FNSGWDIW.js → provider-DKGBQHUS.js} +7 -7
  27. package/dist/{serve-O62TKFVA.js → serve-5AY7GMN7.js} +13 -13
  28. package/dist/server/index.d.ts +2 -0
  29. package/dist/server/index.js +11 -11
  30. package/dist/{tools-JWAF3MAR.js → tools-VOWNOP6V.js} +6 -6
  31. package/dist/{vision-fallback-BWCKA2FZ.js → vision-fallback-ADYRFFD4.js} +2 -2
  32. package/dist/web/assets/{index-MCWDS5UQ.css → index-CNeIjdxm.css} +1 -1
  33. package/dist/web/assets/index-mBLhctLW.js +150 -0
  34. package/dist/web/index.html +2 -2
  35. package/dist/web/sw.js +1 -1
  36. package/package.json +14 -3
  37. package/dist/web/assets/index-Cp8gfbgP.js +0 -150
  38. /package/dist/{command-defaults → server/commands/defaults}/commit-push.command.md +0 -0
  39. /package/dist/{command-defaults → server/commands/defaults}/init.command.md +0 -0
  40. /package/dist/{command-defaults → server/commands/defaults}/test-ui.command.md +0 -0
  41. /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-TUA644W4.js");
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-AKFLBPPY.js.map
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-TUA644W4.js");
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-TUA644W4.js");
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-FNSGWDIW.js");
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-TUA644W4.js");
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-O62TKFVA.js");
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-HCZT5BDI.js.map
170
+ //# sourceMappingURL=chunk-JFKYCGZ5.js.map
@@ -4,40 +4,61 @@ import {
4
4
  detectBackend,
5
5
  detectModel,
6
6
  setLlmStatus
7
- } from "./chunk-E6FCNB3B.js";
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
- async function fetchAvailableModelsFromBackend(baseUrl, apiKey) {
14
- const url = baseUrl.includes("/v1") ? `${baseUrl}/models` : `${baseUrl}/v1/models`;
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 headers = {
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) => m.id).filter(Boolean);
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 from backend", { url, error: error instanceof Error ? error.message : String(error) });
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
- let url;
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
- try {
57
- const headers = {
58
- "Content-Type": "application/json"
59
- };
60
- if (apiKey) {
61
- headers["Authorization"] = `Bearer ${apiKey}`;
62
- }
63
- const response = await fetch(url, {
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, userModels: userModels.map((m) => ({ id: m.id, contextWindow: m.contextWindow })) });
214
+ logger.debug("activateProvider", { providerId, backendModelsCount: modelsWithContext.length, userModelsCount: userModels.length });
223
215
  if (modelsWithContext.length > 0) {
224
- const updatedModels = modelsWithContext.map((m) => {
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
- const allModelsBefore = provider.models.map((m) => ({ id: m.id, contextWindow: m.contextWindow, source: m.source }));
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.map((m) => {
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 = normalize(currentModel);
451
- const matchedModel = updatedModels.find((m) => normalize(m.id) === normalizedCurrentModel);
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-ZHGP4PBJ.js.map
409
+ //# sourceMappingURL=chunk-KOUMYBYM.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  describeImageFromDataUrl,
3
3
  ensureVisionFallbackConfigLoaded
4
- } from "./chunk-AKFLBPPY.js";
4
+ } from "./chunk-IN5EP4ZB.js";
5
5
  import {
6
6
  logger
7
7
  } from "./chunk-PNBH3RAX.js";
@@ -281,8 +281,6 @@ var OpenFoxError = class extends Error {
281
281
  this.details = details;
282
282
  this.name = "OpenFoxError";
283
283
  }
284
- code;
285
- details;
286
284
  };
287
285
  var SessionNotFoundError = class extends OpenFoxError {
288
286
  constructor(sessionId) {
@@ -495,6 +493,37 @@ function getModelProfile(modelName) {
495
493
  }
496
494
 
497
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
+ }
498
527
  function convertAttachmentSync(attachment, modelSupportsVision) {
499
528
  if (modelSupportsVision) {
500
529
  return {
@@ -507,6 +536,13 @@ function convertAttachmentSync(attachment, modelSupportsVision) {
507
536
  text: `[Image: ${attachment.filename || "image"}] (vision not supported, cannot describe)`
508
537
  };
509
538
  }
539
+ function createAttachmentForConversion(data, filename, id) {
540
+ return {
541
+ data,
542
+ ...filename !== void 0 && { filename },
543
+ ...id !== void 0 && { id }
544
+ };
545
+ }
510
546
  async function convertAttachmentWithFallback(attachment, options) {
511
547
  logger.debug("[VisionFallback] convertAttachmentWithFallback called", { filename: attachment.filename, id: attachment.id, hasCallbacks: !!options.onVisionFallbackStart });
512
548
  if (options.modelSupportsVision) {
@@ -536,6 +572,20 @@ async function convertAttachmentWithFallback(attachment, options) {
536
572
  text: `[Image: ${attachment.filename || "image"}] ${description}`
537
573
  };
538
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
+ }
539
589
  function convertMessages(messages, options) {
540
590
  const filtered = messages.filter((msg) => {
541
591
  return !(msg.role === "assistant" && !msg.content?.trim() && (!msg.toolCalls || msg.toolCalls.length === 0));
@@ -543,13 +593,7 @@ function convertMessages(messages, options) {
543
593
  return filtered.map((msg) => {
544
594
  if (msg.role === "tool") {
545
595
  if (msg.attachments && msg.attachments.length > 0) {
546
- const content = [];
547
- if (msg.content?.trim()) {
548
- content.push({ type: "text", text: msg.content });
549
- }
550
- for (const attachment of msg.attachments) {
551
- content.push(convertAttachmentSync(attachment, options.modelSupportsVision));
552
- }
596
+ const content = buildAttachmentContent(msg.content, msg.attachments, options.modelSupportsVision);
553
597
  return {
554
598
  role: "tool",
555
599
  content,
@@ -566,24 +610,11 @@ function convertMessages(messages, options) {
566
610
  return {
567
611
  role: "assistant",
568
612
  content: msg.content || null,
569
- tool_calls: msg.toolCalls.map((toolCall) => ({
570
- id: toolCall.id,
571
- type: "function",
572
- function: {
573
- name: toolCall.name,
574
- arguments: JSON.stringify(toolCall.arguments)
575
- }
576
- }))
613
+ tool_calls: convertToolCalls(msg.toolCalls)
577
614
  };
578
615
  }
579
616
  if (msg.role === "user" && msg.attachments && msg.attachments.length > 0) {
580
- const content = [];
581
- if (msg.content?.trim()) {
582
- content.push({ type: "text", text: msg.content });
583
- }
584
- for (const attachment of msg.attachments) {
585
- content.push(convertAttachmentSync(attachment, options.modelSupportsVision));
586
- }
617
+ const content = buildAttachmentContent(msg.content, msg.attachments, options.modelSupportsVision);
587
618
  return {
588
619
  role: "user",
589
620
  content
@@ -604,17 +635,7 @@ async function convertMessagesWithFallback(messages, options) {
604
635
  for (const msg of filtered) {
605
636
  if (msg.role === "tool") {
606
637
  if (msg.attachments && msg.attachments.length > 0) {
607
- const content = [];
608
- if (msg.content?.trim()) {
609
- content.push({ type: "text", text: msg.content });
610
- }
611
- for (const attachment of msg.attachments) {
612
- const convertedContent = await convertAttachmentWithFallback(
613
- { data: attachment.data, filename: attachment.filename, id: attachment.id },
614
- options
615
- );
616
- content.push(convertedContent);
617
- }
638
+ const content = await buildAttachmentContentWithFallback(msg.content, msg.attachments, options);
618
639
  converted.push({
619
640
  role: "tool",
620
641
  content,
@@ -633,29 +654,12 @@ async function convertMessagesWithFallback(messages, options) {
633
654
  converted.push({
634
655
  role: "assistant",
635
656
  content: msg.content || null,
636
- tool_calls: msg.toolCalls.map((toolCall) => ({
637
- id: toolCall.id,
638
- type: "function",
639
- function: {
640
- name: toolCall.name,
641
- arguments: JSON.stringify(toolCall.arguments)
642
- }
643
- }))
657
+ tool_calls: convertToolCalls(msg.toolCalls)
644
658
  });
645
659
  continue;
646
660
  }
647
661
  if (msg.role === "user" && msg.attachments && msg.attachments.length > 0) {
648
- const content = [];
649
- if (msg.content?.trim()) {
650
- content.push({ type: "text", text: msg.content });
651
- }
652
- for (const attachment of msg.attachments) {
653
- const convertedContent = await convertAttachmentWithFallback(
654
- { data: attachment.data, filename: attachment.filename, id: attachment.id },
655
- options
656
- );
657
- content.push(convertedContent);
658
- }
662
+ const content = await buildAttachmentContentWithFallback(msg.content, msg.attachments, options);
659
663
  converted.push({
660
664
  role: "user",
661
665
  content
@@ -692,18 +696,15 @@ function needsVisionFallback(messages, modelSupportsVision, visionFallbackEnable
692
696
  });
693
697
  return result;
694
698
  }
695
- async function buildNonStreamingCreateParams(input) {
696
- const { model, request, profile, capabilities, disableThinking, visionFallbackEnabled = false, onVisionFallbackStart, onVisionFallbackDone } = input;
697
- const messages = request.messages;
698
- const modelSupportsVision = profile.supportsVision ?? false;
699
- const options = {
700
- modelSupportsVision,
699
+ async function buildChatCompletionCreateParams(model, request, profile, capabilities, disableThinking, visionFallbackEnabled, isStreaming, onVisionFallbackStart, onVisionFallbackDone) {
700
+ const convertedMessages = await convertMessagesWithOptions(
701
+ request.messages,
702
+ profile,
701
703
  visionFallbackEnabled,
702
- signal: request.signal,
704
+ request.signal,
703
705
  onVisionFallbackStart,
704
706
  onVisionFallbackDone
705
- };
706
- const convertedMessages = needsVisionFallback(messages, modelSupportsVision, visionFallbackEnabled) ? await convertMessagesWithFallback(messages, options) : convertMessages(messages, { modelSupportsVision, visionFallbackEnabled: false });
707
+ );
707
708
  const params = {
708
709
  model,
709
710
  messages: convertedMessages,
@@ -712,45 +713,26 @@ async function buildNonStreamingCreateParams(input) {
712
713
  temperature: request.temperature ?? profile.temperature,
713
714
  max_tokens: request.maxTokens ?? profile.defaultMaxTokens,
714
715
  top_p: profile.topP,
715
- stream: false
716
+ stream: isStreaming,
717
+ ...isStreaming ? { stream_options: { include_usage: true } } : {}
716
718
  };
717
719
  if (capabilities.supportsTopK && profile.topK !== void 0) {
718
720
  ;
719
721
  params["top_k"] = profile.topK;
720
722
  }
721
- if (capabilities.supportsChatTemplateKwargs && profile.supportsReasoning && disableThinking) {
723
+ const shouldDisableThinking = isStreaming ? disableThinking || request.disableThinking : disableThinking;
724
+ if (capabilities.supportsChatTemplateKwargs && profile.supportsReasoning && shouldDisableThinking) {
722
725
  ;
723
726
  params["chat_template_kwargs"] = { enable_thinking: false };
724
727
  }
725
728
  return params;
726
729
  }
727
- async function buildStreamingCreateParams(input) {
730
+ async function buildCreateParamsFromInput(input, isStreaming) {
728
731
  const { model, request, profile, capabilities, disableThinking, visionFallbackEnabled = false, onVisionFallbackStart, onVisionFallbackDone } = input;
729
- const messages = request.messages;
730
- const modelSupportsVision = profile.supportsVision ?? false;
731
- const options = { modelSupportsVision, visionFallbackEnabled, signal: request.signal, onVisionFallbackStart, onVisionFallbackDone };
732
- const convertedMessages = needsVisionFallback(messages, modelSupportsVision, visionFallbackEnabled) ? await convertMessagesWithFallback(messages, options) : convertMessages(messages, { modelSupportsVision, visionFallbackEnabled: false });
733
- const params = {
734
- model,
735
- messages: convertedMessages,
736
- ...request.tools ? { tools: convertTools(request.tools) } : {},
737
- ...request.toolChoice ? { tool_choice: request.toolChoice } : {},
738
- temperature: request.temperature ?? profile.temperature,
739
- max_tokens: request.maxTokens ?? profile.defaultMaxTokens,
740
- top_p: profile.topP,
741
- stream: true,
742
- stream_options: { include_usage: true }
743
- };
744
- if (capabilities.supportsTopK && profile.topK !== void 0) {
745
- ;
746
- params["top_k"] = profile.topK;
747
- }
748
- if (capabilities.supportsChatTemplateKwargs && profile.supportsReasoning && (disableThinking || request.disableThinking)) {
749
- ;
750
- params["chat_template_kwargs"] = { enable_thinking: false };
751
- }
752
- return params;
732
+ return buildChatCompletionCreateParams(model, request, profile, capabilities, !!disableThinking, visionFallbackEnabled, isStreaming, onVisionFallbackStart, onVisionFallbackDone);
753
733
  }
734
+ var buildNonStreamingCreateParams = (input) => buildCreateParamsFromInput(input, false);
735
+ var buildStreamingCreateParams = (input) => buildCreateParamsFromInput(input, true);
754
736
  function mapFinishReason(reason) {
755
737
  switch (reason) {
756
738
  case "stop":
@@ -830,7 +812,7 @@ function createLLMClient(config, initialBackend = "unknown") {
830
812
  try {
831
813
  const shouldDisableThinking = disableThinking || request.disableThinking === true;
832
814
  await ensureVisionFallbackConfigLoaded();
833
- const { isVisionFallbackEnabled } = await import("./vision-fallback-BWCKA2FZ.js");
815
+ const { isVisionFallbackEnabled } = await import("./vision-fallback-ADYRFFD4.js");
834
816
  const paramsOptions = {
835
817
  model,
836
818
  request,
@@ -908,7 +890,7 @@ function createLLMClient(config, initialBackend = "unknown") {
908
890
  });
909
891
  try {
910
892
  await ensureVisionFallbackConfigLoaded();
911
- const { isVisionFallbackEnabled } = await import("./vision-fallback-BWCKA2FZ.js");
893
+ const { isVisionFallbackEnabled } = await import("./vision-fallback-ADYRFFD4.js");
912
894
  const shouldDisableThinking = disableThinking || request.disableThinking === true;
913
895
  const createParams = await buildStreamingCreateParams({
914
896
  model,
@@ -1124,4 +1106,4 @@ export {
1124
1106
  setLlmStatus,
1125
1107
  clearModelCache
1126
1108
  };
1127
- //# sourceMappingURL=chunk-E6FCNB3B.js.map
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-POJO7A5H.js";
16
+ } from "./chunk-3WHZ47PY.js";
17
17
  import {
18
18
  getCurrentContextWindowId,
19
19
  getEventStore
20
- } from "./chunk-ZRDRYL6W.js";
20
+ } from "./chunk-6L3X7T4K.js";
21
21
  import {
22
22
  buildSnapshotFromSessionState
23
- } from "./chunk-WQ4W5H6A.js";
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-LMIBGLOB.js.map
296
+ //# sourceMappingURL=chunk-YM6VHAPM.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  detectBackend,
3
3
  detectModel
4
- } from "./chunk-E6FCNB3B.js";
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-TXQNRBMZ.js.map
383
+ //# sourceMappingURL=chunk-ZDNXCVW4.js.map
package/dist/cli/dev.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  runCli
4
- } from "../chunk-HCZT5BDI.js";
4
+ } from "../chunk-JFKYCGZ5.js";
5
5
  import {
6
6
  logger
7
7
  } from "../chunk-PNBH3RAX.js";