openfox 2.0.70 → 2.0.72

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 (68) hide show
  1. package/dist/{chat-handler-K3DWIGHG.js → chat-handler-LK5RUAGO.js} +19 -19
  2. package/dist/{chunk-64GN6OPR.js → chunk-2DCJERYX.js} +8 -8
  3. package/dist/chunk-2M6JM7OR.js +7 -0
  4. package/dist/{chunk-XDWV5CYV.js → chunk-4LBSC4R3.js} +15 -20
  5. package/dist/{chunk-TFDK6VSG.js → chunk-6XKM25OT.js} +13 -13
  6. package/dist/{chunk-E4POUD2M.js → chunk-6XOA2WPU.js} +2 -2
  7. package/dist/{chunk-YQ3MEZJL.js → chunk-CHPRGEY5.js} +3 -3
  8. package/dist/{chunk-C3VLGVSQ.js → chunk-DJASQ2ZB.js} +11 -2
  9. package/dist/{chunk-4QBDV6LX.js → chunk-E5LLEO3C.js} +2 -2
  10. package/dist/{chunk-JHGKXQBO.js → chunk-EZK7CGJ7.js} +87 -30
  11. package/dist/{chunk-ZZ5JPVBT.js → chunk-FILRB5QX.js} +259 -300
  12. package/dist/{chunk-PVWAE43V.js → chunk-GMF36EZ3.js} +123 -106
  13. package/dist/{chunk-GMXKJGJ2.js → chunk-I4RWK2L2.js} +8 -4
  14. package/dist/{chunk-PK2RMVMB.js → chunk-I72ACQ6R.js} +19 -18
  15. package/dist/{chunk-F4PMNP7S.js → chunk-NOU2QIL5.js} +3 -2
  16. package/dist/{chunk-UTSSFPYA.js → chunk-O2BE7KVQ.js} +8 -8
  17. package/dist/{chunk-7OW6X764.js → chunk-OHGQILRF.js} +15 -4
  18. package/dist/{chunk-TFCHWMOJ.js → chunk-PYB2UEC3.js} +11 -5
  19. package/dist/{chunk-XUPKS5FL.js → chunk-QNKXZH3Z.js} +2 -2
  20. package/dist/{chunk-X5DOUA3Z.js → chunk-S7O77CVO.js} +2 -2
  21. package/dist/{chunk-46OR4W3L.js → chunk-TK4BZIXA.js} +45 -31
  22. package/dist/{chunk-KXVFHMSM.js → chunk-UV3EMWL4.js} +2 -2
  23. package/dist/chunk-X2Y3AJPP.js +216 -0
  24. package/dist/{chunk-QFSDJIUS.js → chunk-XWBNYU2L.js} +3 -3
  25. package/dist/cli/dev.js +1 -1
  26. package/dist/cli/index.js +1 -1
  27. package/dist/{client-63U5CTPE.js → client-SC6X65GY.js} +3 -3
  28. package/dist/{client-pure-XHH4RRLB.js → client-pure-NMLDKRDN.js} +6 -4
  29. package/dist/{compactor-IPMMFFHM.js → compactor-4UKYWC5F.js} +9 -9
  30. package/dist/{events-CDQ4HASP.js → events-AEQ6GQXI.js} +4 -4
  31. package/dist/{folding-V2K34EGN.js → folding-ONH3D4OK.js} +2 -2
  32. package/dist/{inspect-proxy-OVEFBJ26.js → inspect-proxy-PHVZBZUO.js} +4 -4
  33. package/dist/{manager-JXYRGR6B.js → manager-24C2AXVF.js} +6 -6
  34. package/dist/{orchestrator-PUV4WG77.js → orchestrator-RTZVMWQV.js} +18 -18
  35. package/dist/package.json +2 -2
  36. package/dist/{platform-AB3GIEGO.js → platform-XQ7BS3KQ.js} +4 -4
  37. package/dist/{processor-O2QW27BD.js → processor-3O26I7DO.js} +19 -19
  38. package/dist/{project-creator-EMGRSPYS.js → project-creator-FQRBN3RG.js} +3 -3
  39. package/dist/{projects-7HSBZY2D.js → projects-LHRNCUGW.js} +3 -3
  40. package/dist/{protocol-CTNE3ANP.js → protocol-4QFU7WAI.js} +2 -2
  41. package/dist/{protocol-DIhV-tAc.d.ts → protocol-DGQWVFcP.d.ts} +1 -1
  42. package/dist/provider/index.d.ts +4 -4
  43. package/dist/{provider-IBIWR4AI.js → provider-OJUCZ5RN.js} +4 -4
  44. package/dist/{provider-manager-7C3JVOLW.js → provider-manager-MAKXSL6L.js} +4 -4
  45. package/dist/{pwa-T6JRAYJB.js → pwa-SEWCVKZX.js} +7 -8
  46. package/dist/{serve-NOHD22CT.js → serve-6PSAQ2YH.js} +26 -24
  47. package/dist/server/index.d.ts +12 -22
  48. package/dist/server/index.js +23 -22
  49. package/dist/server-G2J4RAXL.js +38 -0
  50. package/dist/{service-6DL3MJZD.js → service-2PW2V25M.js} +6 -1
  51. package/dist/{settings-6ZPWOBWL.js → settings-PFXRYXZU.js} +3 -3
  52. package/dist/shared/index.d.ts +3 -3
  53. package/dist/{store-FXTCHBI4.js → store-SARB6V2N.js} +2 -2
  54. package/dist/{tools-CALGWIV2.js → tools-X52DFUS6.js} +17 -17
  55. package/dist/{types-BsfYpEai.d.ts → types-C4cG9CtC.d.ts} +3 -2
  56. package/dist/{types-CBC6lLqc.d.ts → types-DSZhFA8O.d.ts} +1 -1
  57. package/dist/update-I2M2RG4Q.js +40 -0
  58. package/dist/web/assets/index-C7SW16F7.js +305 -0
  59. package/dist/web/assets/{index-BVTG7SRG.css → index-CmechlaK.css} +1 -1
  60. package/dist/web/index.html +2 -2
  61. package/dist/web/sw.js +1 -1
  62. package/dist/workspace-ET3FHZYN.js +32 -0
  63. package/package.json +2 -2
  64. package/dist/chunk-VLV3XWZS.js +0 -191
  65. package/dist/cli/update.sh +0 -16
  66. package/dist/server-RLNPHLY2.js +0 -38
  67. package/dist/web/assets/index-CtWMMQ_X.js +0 -305
  68. package/dist/worktree-6U45P63P.js +0 -30
@@ -2,37 +2,37 @@ import {
2
2
  buildRunChatTurnParams,
3
3
  finalizeTurnCompletion,
4
4
  generateSessionNameForSession
5
- } from "./chunk-64GN6OPR.js";
5
+ } from "./chunk-2DCJERYX.js";
6
6
  import {
7
7
  runChatTurn
8
- } from "./chunk-UTSSFPYA.js";
9
- import "./chunk-PVWAE43V.js";
10
- import "./chunk-QFSDJIUS.js";
11
- import "./chunk-4QBDV6LX.js";
12
- import "./chunk-KXVFHMSM.js";
13
- import "./chunk-TFCHWMOJ.js";
14
- import "./chunk-PK2RMVMB.js";
8
+ } from "./chunk-O2BE7KVQ.js";
9
+ import "./chunk-GMF36EZ3.js";
10
+ import "./chunk-X2Y3AJPP.js";
11
+ import "./chunk-WGMJCFCE.js";
12
+ import "./chunk-EU3WWTFH.js";
13
+ import "./chunk-XWBNYU2L.js";
14
+ import "./chunk-E5LLEO3C.js";
15
+ import "./chunk-UV3EMWL4.js";
16
+ import "./chunk-PYB2UEC3.js";
17
+ import "./chunk-I72ACQ6R.js";
15
18
  import "./chunk-NWO6GRYE.js";
16
19
  import "./chunk-UN26GIQG.js";
17
- import "./chunk-VLV3XWZS.js";
18
- import "./chunk-WGMJCFCE.js";
19
20
  import {
20
21
  getEventStore
21
- } from "./chunk-TFDK6VSG.js";
22
- import "./chunk-C3VLGVSQ.js";
22
+ } from "./chunk-6XKM25OT.js";
23
+ import "./chunk-DJASQ2ZB.js";
23
24
  import {
24
25
  createChatMessageMessage,
25
26
  createPhaseChangedMessage,
26
27
  createSessionRunningMessage
27
- } from "./chunk-F4PMNP7S.js";
28
- import "./chunk-X5DOUA3Z.js";
29
- import "./chunk-XUPKS5FL.js";
30
- import "./chunk-GMXKJGJ2.js";
31
- import "./chunk-EU3WWTFH.js";
28
+ } from "./chunk-NOU2QIL5.js";
29
+ import "./chunk-S7O77CVO.js";
30
+ import "./chunk-QNKXZH3Z.js";
31
+ import "./chunk-I4RWK2L2.js";
32
32
  import "./chunk-J2GP3J3X.js";
33
33
  import "./chunk-V4IE7HJY.js";
34
34
  import "./chunk-YHEQTVFV.js";
35
- import "./chunk-JHGKXQBO.js";
35
+ import "./chunk-EZK7CGJ7.js";
36
36
  import "./chunk-K44MW7JJ.js";
37
37
  import "./chunk-YD6NDTKF.js";
38
38
  import "./chunk-WGAAQASA.js";
@@ -158,4 +158,4 @@ export {
158
158
  startChatSession,
159
159
  stopSessionExecution
160
160
  };
161
- //# sourceMappingURL=chat-handler-K3DWIGHG.js.map
161
+ //# sourceMappingURL=chat-handler-LK5RUAGO.js.map
@@ -1,19 +1,19 @@
1
+ import {
2
+ getPendingQuestionsForSession
3
+ } from "./chunk-EU3WWTFH.js";
1
4
  import {
2
5
  getEventStore,
3
6
  getRuntimeConfig,
4
7
  updateSessionMetadata
5
- } from "./chunk-TFDK6VSG.js";
8
+ } from "./chunk-6XKM25OT.js";
6
9
  import {
7
10
  buildMessagesFromStoredEvents,
8
11
  foldPendingConfirmations
9
- } from "./chunk-C3VLGVSQ.js";
12
+ } from "./chunk-DJASQ2ZB.js";
10
13
  import {
11
14
  createContextStateMessage,
12
15
  createSessionStateMessage
13
- } from "./chunk-F4PMNP7S.js";
14
- import {
15
- getPendingQuestionsForSession
16
- } from "./chunk-EU3WWTFH.js";
16
+ } from "./chunk-NOU2QIL5.js";
17
17
  import {
18
18
  logger
19
19
  } from "./chunk-K44MW7JJ.js";
@@ -135,7 +135,7 @@ async function generateSessionNameForSession(sessionId, userMessage, deps, signa
135
135
  client = deps.getLLMClient();
136
136
  client.setModel(providerConfig.model);
137
137
  } else if (providerConfig) {
138
- const { createLLMClient } = await import("./client-63U5CTPE.js");
138
+ const { createLLMClient } = await import("./client-SC6X65GY.js");
139
139
  client = createLLMClient({
140
140
  llm: {
141
141
  baseUrl: providerConfig.baseUrl,
@@ -184,4 +184,4 @@ export {
184
184
  buildRunChatTurnParams,
185
185
  generateSessionNameForSession
186
186
  };
187
- //# sourceMappingURL=chunk-64GN6OPR.js.map
187
+ //# sourceMappingURL=chunk-2DCJERYX.js.map
@@ -0,0 +1,7 @@
1
+ // src/constants.ts
2
+ var VERSION = "2.0.72";
3
+
4
+ export {
5
+ VERSION
6
+ };
7
+ //# sourceMappingURL=chunk-2M6JM7OR.js.map
@@ -7,9 +7,6 @@ import {
7
7
 
8
8
  // src/cli/main.ts
9
9
  import { parseArgs } from "util";
10
- import { spawnSync } from "child_process";
11
- import { fileURLToPath } from "url";
12
- import { dirname, join } from "path";
13
10
  import { generateKeyPairSync } from "crypto";
14
11
  import { writeFile } from "fs/promises";
15
12
  function printHelp() {
@@ -28,7 +25,7 @@ Commands:
28
25
  provider remove Remove a provider
29
26
  service Manage the systemd service (install, start, stop, status, logs, uninstall)
30
27
  pwa Manage the PWA installation (install, uninstall, launch, update, status)
31
- update Update OpenFox to the latest version (see update.sh)
28
+ update Update OpenFox to the latest version
32
29
 
33
30
  Options:
34
31
  -p, --port <number> Specify port (default: 10369 for prod, 10469 for dev)
@@ -145,11 +142,11 @@ async function runCli(options) {
145
142
  const [command] = positionals;
146
143
  if (values.version && !command) {
147
144
  const { readFileSync } = await import("fs");
148
- const { fileURLToPath: fileURLToPath2 } = await import("url");
149
- const { dirname: dirname2, join: join2 } = await import("path");
150
- const __filename = fileURLToPath2(import.meta.url);
151
- const __dirname = dirname2(__filename);
152
- const packageJsonPath = join2(__dirname, "../package.json");
145
+ const { fileURLToPath } = await import("url");
146
+ const { dirname, join } = await import("path");
147
+ const __filename = fileURLToPath(import.meta.url);
148
+ const __dirname = dirname(__filename);
149
+ const packageJsonPath = join(__dirname, "../package.json");
153
150
  const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
154
151
  console.log(packageJson.version);
155
152
  process.exit(0);
@@ -164,13 +161,13 @@ async function runCli(options) {
164
161
  break;
165
162
  }
166
163
  case "provider": {
167
- const { runProviderCommand } = await import("./provider-IBIWR4AI.js");
164
+ const { runProviderCommand } = await import("./provider-OJUCZ5RN.js");
168
165
  const [, subcommand] = positionals;
169
166
  await runProviderCommand(mode, subcommand);
170
167
  break;
171
168
  }
172
169
  case "service": {
173
- const { runServiceCommand } = await import("./service-6DL3MJZD.js");
170
+ const { runServiceCommand } = await import("./service-2PW2V25M.js");
174
171
  const [, subcommand, ...serviceArgs] = positionals;
175
172
  if (values.follow) {
176
173
  serviceArgs.push("-f");
@@ -183,7 +180,7 @@ async function runCli(options) {
183
180
  break;
184
181
  }
185
182
  case "pwa": {
186
- const { runPwaCommand, printPwaHelp } = await import("./pwa-T6JRAYJB.js");
183
+ const { runPwaCommand, printPwaHelp } = await import("./pwa-SEWCVKZX.js");
187
184
  const [, subcommand] = positionals;
188
185
  if (subcommand === "--help" || subcommand === "-h" || values.help) {
189
186
  printPwaHelp();
@@ -193,12 +190,10 @@ async function runCli(options) {
193
190
  break;
194
191
  }
195
192
  case "update": {
196
- const __filename = fileURLToPath(import.meta.url);
197
- const __dirname = dirname(__filename);
198
- const updateScriptPath = join(__dirname, "cli", "update.sh");
199
- const result = spawnSync(updateScriptPath, [], { shell: true, stdio: "inherit", windowsHide: true });
200
- if (result.status !== 0) {
201
- process.exit(result.status ?? 1);
193
+ const { runUpdate } = await import("./update-I2M2RG4Q.js");
194
+ const code = runUpdate();
195
+ if (code !== 0) {
196
+ process.exit(code);
202
197
  }
203
198
  break;
204
199
  }
@@ -208,7 +203,7 @@ async function runCli(options) {
208
203
  if (!configExists) {
209
204
  await runNetworkSetup(mode);
210
205
  }
211
- const { runServe } = await import("./serve-NOHD22CT.js");
206
+ const { runServe } = await import("./serve-6PSAQ2YH.js");
212
207
  const serveOptions = { mode };
213
208
  if (values.port) serveOptions.port = parseInt(values.port);
214
209
  if (values["no-browser"] === true) serveOptions.openBrowser = false;
@@ -220,4 +215,4 @@ async function runCli(options) {
220
215
  export {
221
216
  runCli
222
217
  };
223
- //# sourceMappingURL=chunk-XDWV5CYV.js.map
218
+ //# sourceMappingURL=chunk-4LBSC4R3.js.map
@@ -5,10 +5,10 @@ import {
5
5
  foldContextState,
6
6
  foldSessionState,
7
7
  spreadOptionalMessageFields
8
- } from "./chunk-C3VLGVSQ.js";
8
+ } from "./chunk-DJASQ2ZB.js";
9
9
  import {
10
10
  getDatabase
11
- } from "./chunk-GMXKJGJ2.js";
11
+ } from "./chunk-I4RWK2L2.js";
12
12
  import {
13
13
  logger
14
14
  } from "./chunk-K44MW7JJ.js";
@@ -680,21 +680,21 @@ function getProjectDangerLevel(projectId) {
680
680
  return "normal";
681
681
  }
682
682
  }
683
- function createSession(projectId, workdir, title, providerId, providerModel, worktree) {
683
+ function createSession(projectId, workdir, title, providerId, providerModel, workspace) {
684
684
  const db = getDatabase();
685
685
  const now = (/* @__PURE__ */ new Date()).toISOString();
686
686
  const id = crypto.randomUUID();
687
687
  const dangerLevel = getProjectDangerLevel(projectId);
688
688
  db.prepare(
689
689
  `
690
- INSERT INTO sessions (id, project_id, workdir, worktree, phase, mode, workflow_phase, is_running, created_at, updated_at, title, provider_id, provider_model, danger_level)
690
+ INSERT INTO sessions (id, project_id, workdir, workspace, phase, mode, workflow_phase, is_running, created_at, updated_at, title, provider_id, provider_model, danger_level)
691
691
  VALUES (?, ?, ?, ?, 'idle', 'planner', 'plan', 0, ?, ?, ?, ?, ?, ?)
692
692
  `
693
693
  ).run(
694
694
  id,
695
695
  projectId,
696
696
  workdir,
697
- worktree ?? null,
697
+ workspace ?? null,
698
698
  now,
699
699
  now,
700
700
  title ?? null,
@@ -706,7 +706,7 @@ function createSession(projectId, workdir, title, providerId, providerModel, wor
706
706
  id,
707
707
  projectId,
708
708
  workdir,
709
- ...worktree ? { worktree } : {},
709
+ ...workspace ? { workspace } : {},
710
710
  mode: "planner",
711
711
  phase: "plan",
712
712
  isRunning: false,
@@ -855,7 +855,7 @@ function listSessions() {
855
855
  s.id,
856
856
  s.project_id,
857
857
  s.workdir,
858
- s.worktree,
858
+ s.workspace,
859
859
  s.mode,
860
860
  s.workflow_phase,
861
861
  s.is_running,
@@ -879,7 +879,7 @@ function listSessionsByProject(projectId, limit = 20, offset = 0) {
879
879
  s.id,
880
880
  s.project_id,
881
881
  s.workdir,
882
- s.worktree,
882
+ s.workspace,
883
883
  s.mode,
884
884
  s.workflow_phase,
885
885
  s.is_running,
@@ -899,12 +899,12 @@ function listSessionsByProject(projectId, limit = 20, offset = 0) {
899
899
  const sessions = rows.slice(0, limit).map(mapSessionSummaryRow);
900
900
  return { sessions, hasMore };
901
901
  }
902
- function updateSessionWorkdir(id, workdir, worktree) {
902
+ function updateSessionWorkdir(id, workdir, workspace) {
903
903
  const db = getDatabase();
904
904
  const now = (/* @__PURE__ */ new Date()).toISOString();
905
- db.prepare("UPDATE sessions SET workdir = ?, worktree = ?, updated_at = ? WHERE id = ?").run(
905
+ db.prepare("UPDATE sessions SET workdir = ?, workspace = ?, updated_at = ? WHERE id = ?").run(
906
906
  workdir,
907
- worktree,
907
+ workspace,
908
908
  now,
909
909
  id
910
910
  );
@@ -918,7 +918,7 @@ function mapSessionBase(row) {
918
918
  id: row.id,
919
919
  projectId: row.project_id,
920
920
  workdir: row.workdir,
921
- ...row.worktree ? { worktree: row.worktree } : {},
921
+ ...row.workspace ? { workspace: row.workspace } : {},
922
922
  mode: row.mode ?? "planner",
923
923
  phase: row.workflow_phase ?? "plan",
924
924
  isRunning: Boolean(row.is_running),
@@ -1460,4 +1460,4 @@ export {
1460
1460
  truncateSessionMessages,
1461
1461
  getRecentUserPromptsForSession
1462
1462
  };
1463
- //# sourceMappingURL=chunk-TFDK6VSG.js.map
1463
+ //# sourceMappingURL=chunk-6XKM25OT.js.map
@@ -13,7 +13,7 @@ import {
13
13
  getThinking,
14
14
  mapFinishReason,
15
15
  parseToolArguments
16
- } from "./chunk-JHGKXQBO.js";
16
+ } from "./chunk-EZK7CGJ7.js";
17
17
  import {
18
18
  LLMError,
19
19
  OpenAIHttpClient
@@ -265,4 +265,4 @@ function createLLMClient(config, initialBackend = "unknown") {
265
265
  export {
266
266
  createLLMClient
267
267
  };
268
- //# sourceMappingURL=chunk-E4POUD2M.js.map
268
+ //# sourceMappingURL=chunk-6XOA2WPU.js.map
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  COMPACTION_PROMPT,
3
3
  createMessageStartEvent
4
- } from "./chunk-QFSDJIUS.js";
4
+ } from "./chunk-XWBNYU2L.js";
5
5
  import {
6
6
  getCurrentWindowMessageOptions
7
- } from "./chunk-TFDK6VSG.js";
7
+ } from "./chunk-6XKM25OT.js";
8
8
 
9
9
  // src/server/context/compactor.ts
10
10
  function appendCompactionPrompt(sessionId, append) {
@@ -31,4 +31,4 @@ export {
31
31
  shouldCompact,
32
32
  getCompactionTarget
33
33
  };
34
- //# sourceMappingURL=chunk-YQ3MEZJL.js.map
34
+ //# sourceMappingURL=chunk-CHPRGEY5.js.map
@@ -409,7 +409,16 @@ Error: ${data.result.error}` : `Error: ${data.result.error}`
409
409
  }
410
410
  ];
411
411
  }
412
- messages.push(toolMsg);
412
+ const parentIdx = messages.findIndex((m) => m.id === data.messageId);
413
+ if (parentIdx >= 0) {
414
+ let insertIdx = parentIdx + 1;
415
+ while (insertIdx < messages.length && messages[insertIdx].role === "tool" && messages[insertIdx].toolCallId) {
416
+ insertIdx++;
417
+ }
418
+ messages.splice(insertIdx, 0, toolMsg);
419
+ } else {
420
+ messages.push(toolMsg);
421
+ }
413
422
  }
414
423
  }
415
424
  function stripOrphanedToolCalls(messages, fulfilledToolCallIds) {
@@ -867,4 +876,4 @@ export {
867
876
  buildSnapshot,
868
877
  buildSnapshotFromSessionState
869
878
  };
870
- //# sourceMappingURL=chunk-C3VLGVSQ.js.map
879
+ //# sourceMappingURL=chunk-DJASQ2ZB.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getProjectByWorkdir
3
- } from "./chunk-KXVFHMSM.js";
3
+ } from "./chunk-UV3EMWL4.js";
4
4
  import {
5
5
  logger
6
6
  } from "./chunk-K44MW7JJ.js";
@@ -343,4 +343,4 @@ export {
343
343
  startInspectProxy,
344
344
  stopAllInspectProxies
345
345
  };
346
- //# sourceMappingURL=chunk-4QBDV6LX.js.map
346
+ //# sourceMappingURL=chunk-E5LLEO3C.js.map
@@ -1,3 +1,16 @@
1
+ // src/shared/constants.ts
2
+ var TEXT_MIME_PREFIXES = ["text/"];
3
+ var TEXT_MIME_EXACT = [
4
+ "application/json",
5
+ "application/xml",
6
+ "application/yaml",
7
+ "application/x-yaml",
8
+ "application/javascript",
9
+ "application/xhtml+xml",
10
+ "application/x-sh",
11
+ "image/svg+xml"
12
+ ];
13
+
1
14
  // src/server/tools/types.ts
2
15
  var OUTPUT_LIMITS = {
3
16
  read_file: {
@@ -83,18 +96,76 @@ ${pageText}`);
83
96
  return { text, pageCount, title, author };
84
97
  }
85
98
 
86
- // src/shared/constants.ts
87
- var TEXT_MIME_PREFIXES = ["text/"];
88
- var TEXT_MIME_EXACT = [
89
- "application/json",
90
- "application/xml",
91
- "application/yaml",
92
- "application/x-yaml",
93
- "application/javascript",
94
- "application/xhtml+xml",
95
- "application/x-sh",
96
- "image/svg+xml"
97
- ];
99
+ // src/server/llm/resolve-attachments.ts
100
+ function decodeDataUrlToText(data) {
101
+ const match = data.match(/^data:.*?;base64,(.+)$/);
102
+ if (match?.[1]) {
103
+ return Buffer.from(match[1], "base64").toString("utf8");
104
+ }
105
+ return data;
106
+ }
107
+ async function extractPdfFromDataUrl(data, filename) {
108
+ const base64Match = data.match(/^data:.*?;base64,(.+)$/);
109
+ if (base64Match?.[1]) {
110
+ try {
111
+ const buffer = Buffer.from(base64Match[1], "base64");
112
+ const result = await extractPdfText(buffer);
113
+ return `[PDF: ${filename}]
114
+ ${result.text}`;
115
+ } catch {
116
+ return `[PDF: ${filename}] (could not extract text)`;
117
+ }
118
+ }
119
+ return `[PDF: ${filename}] (could not extract text)`;
120
+ }
121
+ async function resolveAttachmentToText(attachment, supportsVision) {
122
+ const mimeType = attachment.mimeType;
123
+ if (TEXT_MIME_EXACT.includes(mimeType) || TEXT_MIME_PREFIXES.some((p) => mimeType.startsWith(p))) {
124
+ const text = decodeDataUrlToText(attachment.data);
125
+ return `[File: ${attachment.filename || "file"}]
126
+ ${text}`;
127
+ }
128
+ if (mimeType === "application/pdf") {
129
+ return extractPdfFromDataUrl(attachment.data, attachment.filename || "document.pdf");
130
+ }
131
+ if (supportsVision) {
132
+ return `[File: ${attachment.filename || "file"} (unsupported type: ${mimeType})]`;
133
+ }
134
+ if (attachment.description) {
135
+ return `[Image: ${attachment.filename || "image"} - description: ${attachment.description}]`;
136
+ }
137
+ return `[Image: ${attachment.filename || "image"}] (vision not supported, cannot describe)`;
138
+ }
139
+ async function resolveAttachmentsInMessages(messages, supportsVision) {
140
+ const result = [];
141
+ for (const msg of messages) {
142
+ if (!msg.attachments || msg.attachments.length === 0) {
143
+ result.push(msg);
144
+ continue;
145
+ }
146
+ if (supportsVision && msg.attachments.every((a) => a.mimeType.startsWith("image/"))) {
147
+ result.push(msg);
148
+ continue;
149
+ }
150
+ const parts = [];
151
+ if (msg.content?.trim()) parts.push(msg.content);
152
+ const remainingImageAttachments = [];
153
+ for (const attachment of msg.attachments) {
154
+ if (supportsVision && attachment.mimeType.startsWith("image/")) {
155
+ remainingImageAttachments.push(attachment);
156
+ continue;
157
+ }
158
+ const text = await resolveAttachmentToText(attachment, supportsVision);
159
+ if (text) parts.push(text);
160
+ }
161
+ result.push({
162
+ ...msg,
163
+ content: parts.join("\n\n"),
164
+ attachments: remainingImageAttachments
165
+ });
166
+ }
167
+ return result;
168
+ }
98
169
 
99
170
  // src/server/llm/client-pure.ts
100
171
  function parseToolArguments(raw, _meta) {
@@ -171,23 +242,8 @@ ${attachment.data}`
171
242
  };
172
243
  }
173
244
  if (mimeType === "application/pdf") {
174
- try {
175
- const base64Match = attachment.data.match(/^data:.*?;base64,(.+)$/);
176
- if (base64Match?.[1]) {
177
- const buffer = Buffer.from(base64Match[1], "base64");
178
- const result = await extractPdfText(buffer);
179
- return {
180
- type: "text",
181
- text: `[PDF: ${attachment.filename || "document.pdf"}]
182
- ${result.text}`
183
- };
184
- }
185
- } catch {
186
- }
187
- return {
188
- type: "text",
189
- text: `[PDF: ${attachment.filename || "document.pdf"}] (could not extract text)`
190
- };
245
+ const text = await extractPdfFromDataUrl(attachment.data, attachment.filename || "document.pdf");
246
+ return { type: "text", text };
191
247
  }
192
248
  if (modelSupportsVision) {
193
249
  return {
@@ -343,6 +399,7 @@ export {
343
399
  formatPdfErrorMessage,
344
400
  processPdfContent,
345
401
  extractPdfText,
402
+ resolveAttachmentsInMessages,
346
403
  parseToolArguments,
347
404
  buildModelParams,
348
405
  getThinking,
@@ -352,4 +409,4 @@ export {
352
409
  buildStreamingCreateParams,
353
410
  mapFinishReason
354
411
  };
355
- //# sourceMappingURL=chunk-JHGKXQBO.js.map
412
+ //# sourceMappingURL=chunk-EZK7CGJ7.js.map