sparkecoder 0.1.44 → 0.1.46

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 (184) hide show
  1. package/README.md +1 -1
  2. package/dist/agent/index.d.ts +2 -2
  3. package/dist/agent/index.js +153 -4
  4. package/dist/agent/index.js.map +1 -1
  5. package/dist/cli.js +209 -22
  6. package/dist/cli.js.map +1 -1
  7. package/dist/db/index.js +11 -3
  8. package/dist/db/index.js.map +1 -1
  9. package/dist/{index-D2eLXP9V.d.ts → index-DJ5qNs1Z.d.ts} +9 -5
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +210 -21
  12. package/dist/index.js.map +1 -1
  13. package/dist/{search-D3Wtf7TJ.d.ts → search-BOYIUmDp.d.ts} +1 -1
  14. package/dist/server/index.js +208 -21
  15. package/dist/server/index.js.map +1 -1
  16. package/dist/tools/index.d.ts +2 -2
  17. package/dist/tools/index.js +11 -3
  18. package/dist/tools/index.js.map +1 -1
  19. package/package.json +1 -1
  20. package/web/.next/BUILD_ID +1 -1
  21. package/web/.next/standalone/web/.next/BUILD_ID +1 -1
  22. package/web/.next/standalone/web/.next/build-manifest.json +2 -2
  23. package/web/.next/standalone/web/.next/prerender-manifest.json +3 -3
  24. package/web/.next/standalone/web/.next/server/app/(main)/page.js.nft.json +1 -1
  25. package/web/.next/standalone/web/.next/server/app/(main)/page_client-reference-manifest.js +1 -1
  26. package/web/.next/standalone/web/.next/server/app/(main)/session/[id]/page.js.nft.json +1 -1
  27. package/web/.next/standalone/web/.next/server/app/(main)/session/[id]/page_client-reference-manifest.js +1 -1
  28. package/web/.next/standalone/web/.next/server/app/_global-error.html +2 -2
  29. package/web/.next/standalone/web/.next/server/app/_global-error.rsc +1 -1
  30. package/web/.next/standalone/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  31. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  32. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  33. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  34. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  35. package/web/.next/standalone/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  36. package/web/.next/standalone/web/.next/server/app/_not-found.html +1 -1
  37. package/web/.next/standalone/web/.next/server/app/_not-found.rsc +3 -3
  38. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
  39. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  40. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_index.segment.rsc +3 -3
  41. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  42. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  43. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  44. package/web/.next/standalone/web/.next/server/app/docs/installation/page_client-reference-manifest.js +1 -1
  45. package/web/.next/standalone/web/.next/server/app/docs/installation.html +2 -2
  46. package/web/.next/standalone/web/.next/server/app/docs/installation.rsc +4 -4
  47. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_full.segment.rsc +4 -4
  48. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_head.segment.rsc +1 -1
  49. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_index.segment.rsc +3 -3
  50. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_tree.segment.rsc +2 -2
  51. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs/installation/__PAGE__.segment.rsc +2 -2
  52. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs/installation.segment.rsc +1 -1
  53. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs.segment.rsc +2 -2
  54. package/web/.next/standalone/web/.next/server/app/docs/page_client-reference-manifest.js +1 -1
  55. package/web/.next/standalone/web/.next/server/app/docs/skills/page_client-reference-manifest.js +1 -1
  56. package/web/.next/standalone/web/.next/server/app/docs/skills.html +2 -2
  57. package/web/.next/standalone/web/.next/server/app/docs/skills.rsc +4 -4
  58. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_full.segment.rsc +4 -4
  59. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_head.segment.rsc +1 -1
  60. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_index.segment.rsc +3 -3
  61. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_tree.segment.rsc +2 -2
  62. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs/skills/__PAGE__.segment.rsc +1 -1
  63. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs/skills.segment.rsc +1 -1
  64. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs.segment.rsc +2 -2
  65. package/web/.next/standalone/web/.next/server/app/docs/tools/page_client-reference-manifest.js +1 -1
  66. package/web/.next/standalone/web/.next/server/app/docs/tools.html +2 -2
  67. package/web/.next/standalone/web/.next/server/app/docs/tools.rsc +4 -4
  68. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_full.segment.rsc +4 -4
  69. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_head.segment.rsc +1 -1
  70. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_index.segment.rsc +3 -3
  71. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_tree.segment.rsc +2 -2
  72. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs/tools/__PAGE__.segment.rsc +2 -2
  73. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs/tools.segment.rsc +1 -1
  74. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs.segment.rsc +2 -2
  75. package/web/.next/standalone/web/.next/server/app/docs.html +2 -2
  76. package/web/.next/standalone/web/.next/server/app/docs.rsc +4 -4
  77. package/web/.next/standalone/web/.next/server/app/docs.segments/_full.segment.rsc +4 -4
  78. package/web/.next/standalone/web/.next/server/app/docs.segments/_head.segment.rsc +1 -1
  79. package/web/.next/standalone/web/.next/server/app/docs.segments/_index.segment.rsc +3 -3
  80. package/web/.next/standalone/web/.next/server/app/docs.segments/_tree.segment.rsc +2 -2
  81. package/web/.next/standalone/web/.next/server/app/docs.segments/docs/__PAGE__.segment.rsc +2 -2
  82. package/web/.next/standalone/web/.next/server/app/docs.segments/docs.segment.rsc +2 -2
  83. package/web/.next/standalone/web/.next/server/app/embed/[id]/page.js.nft.json +1 -1
  84. package/web/.next/standalone/web/.next/server/app/embed/[id]/page_client-reference-manifest.js +1 -1
  85. package/web/.next/standalone/web/.next/server/app/index.html +1 -1
  86. package/web/.next/standalone/web/.next/server/app/index.rsc +5 -5
  87. package/web/.next/standalone/web/.next/server/app/index.segments/!KG1haW4p/__PAGE__.segment.rsc +2 -2
  88. package/web/.next/standalone/web/.next/server/app/index.segments/!KG1haW4p.segment.rsc +2 -2
  89. package/web/.next/standalone/web/.next/server/app/index.segments/_full.segment.rsc +5 -5
  90. package/web/.next/standalone/web/.next/server/app/index.segments/_head.segment.rsc +1 -1
  91. package/web/.next/standalone/web/.next/server/app/index.segments/_index.segment.rsc +3 -3
  92. package/web/.next/standalone/web/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  93. package/web/.next/standalone/web/.next/server/chunks/[root-of-the-server]__36edac7c._.js +1 -1
  94. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_85c176b8._.js → 2374f_13da7b2a._.js} +1 -1
  95. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_3eca1553._.js → 2374f_1de2f628._.js} +1 -1
  96. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_8b8baaa3._.js → 2374f_2bfcd3a2._.js} +1 -1
  97. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_0146c9df._.js → 2374f_40c1da73._.js} +1 -1
  98. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_b30bed04._.js → 2374f_41d07cce._.js} +1 -1
  99. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_4d1accac._.js → 2374f_6d8e5e94._.js} +1 -1
  100. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_c99180da._.js → 2374f_88aa1671._.js} +1 -1
  101. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_147b1db0._.js → 2374f_9f2fae06._.js} +1 -1
  102. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_98432ce4._.js → 2374f_ac79ddf4._.js} +1 -1
  103. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_36dd81aa._.js → 2374f_c8f8a326._.js} +1 -1
  104. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_bcffd98c._.js → 2374f_dd21a4e9._.js} +1 -1
  105. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_dde5cdd9._.js → 2374f_e5142825._.js} +1 -1
  106. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_4b3676c4._.js → 2374f_ec658806._.js} +1 -1
  107. package/web/.next/standalone/web/.next/server/chunks/ssr/{2374f_f5998fca._.js → 2374f_f3c65774._.js} +1 -1
  108. package/web/.next/standalone/web/.next/server/chunks/ssr/[root-of-the-server]__43405ad6._.js +3 -0
  109. package/web/.next/standalone/web/.next/server/chunks/ssr/{[root-of-the-server]__adf39cf8._.js → [root-of-the-server]__a87e1c27._.js} +6 -4
  110. package/web/.next/standalone/web/.next/server/chunks/ssr/[root-of-the-server]__be5e2967._.js +1 -1
  111. package/web/.next/standalone/web/.next/server/chunks/ssr/[root-of-the-server]__de76483d._.js +1 -1
  112. package/web/.next/standalone/web/.next/server/chunks/ssr/{web_76f53fe7._.js → web_273500a6._.js} +2 -2
  113. package/web/.next/standalone/web/.next/server/chunks/ssr/{web_76ccf09f._.js → web_2b3a5919._.js} +2 -2
  114. package/web/.next/standalone/web/.next/server/chunks/ssr/{web_633d8a33._.js → web_329773d1._.js} +2 -2
  115. package/web/.next/standalone/web/.next/server/chunks/ssr/{web_248fc1f2._.js → web_38156da8._.js} +2 -2
  116. package/web/.next/standalone/web/.next/server/chunks/ssr/web_8305f089._.js +7 -0
  117. package/web/.next/standalone/web/.next/server/chunks/ssr/web_src_app_(main)_page_tsx_5ac4794b._.js +1 -1
  118. package/web/.next/standalone/web/.next/server/chunks/ssr/web_src_components_sessions-sidebar_tsx_92510070._.js +1 -1
  119. package/web/.next/standalone/web/.next/server/pages/404.html +1 -1
  120. package/web/.next/standalone/web/.next/server/pages/500.html +2 -2
  121. package/web/.next/standalone/web/.next/server/server-reference-manifest.js +1 -1
  122. package/web/.next/standalone/web/.next/server/server-reference-manifest.json +1 -1
  123. package/web/.next/standalone/web/.next/static/{static/chunks/194b3ed8e8d9c0e9.js → chunks/294ebe8457006bce.js} +3 -3
  124. package/web/.next/standalone/web/.next/static/chunks/{23aa98f6e3d7e0e4.js → 7e48d04fbd6dd7a6.js} +5 -3
  125. package/web/.next/standalone/web/.next/static/{static/chunks/1e9fdac31c7fd474.js → chunks/81685e5e8be4eac9.js} +3 -3
  126. package/web/.next/{static/chunks/3425251cd978da61.js → standalone/web/.next/static/chunks/8d3efc76109d2efc.js} +1 -1
  127. package/web/.next/standalone/web/.next/static/chunks/96ec96279ada0efe.js +1 -0
  128. package/web/.next/standalone/web/.next/static/chunks/b31b0765abe0c427.js +1 -0
  129. package/web/.next/standalone/web/.next/static/{static/chunks/c06faa5848e3b0b3.js → chunks/b7d722dab2a7ecc0.js} +1 -1
  130. package/web/.next/standalone/web/.next/static/chunks/cc6d43f798bbe415.js +5 -0
  131. package/web/.next/standalone/web/.next/static/chunks/de300ff10b63be85.css +1 -0
  132. package/web/.next/standalone/web/.next/static/chunks/de71e63276f488bb.js +7 -0
  133. package/web/.next/standalone/web/.next/static/{chunks/194b3ed8e8d9c0e9.js → static/chunks/294ebe8457006bce.js} +3 -3
  134. package/web/.next/standalone/web/.next/static/static/chunks/{23aa98f6e3d7e0e4.js → 7e48d04fbd6dd7a6.js} +5 -3
  135. package/web/.next/{static/chunks/1e9fdac31c7fd474.js → standalone/web/.next/static/static/chunks/81685e5e8be4eac9.js} +3 -3
  136. package/web/.next/standalone/web/.next/static/{chunks/3425251cd978da61.js → static/chunks/8d3efc76109d2efc.js} +1 -1
  137. package/web/.next/standalone/web/.next/static/static/chunks/96ec96279ada0efe.js +1 -0
  138. package/web/.next/standalone/web/.next/static/static/chunks/b31b0765abe0c427.js +1 -0
  139. package/web/.next/{static/chunks/c06faa5848e3b0b3.js → standalone/web/.next/static/static/chunks/b7d722dab2a7ecc0.js} +1 -1
  140. package/web/.next/standalone/web/.next/static/static/chunks/cc6d43f798bbe415.js +5 -0
  141. package/web/.next/standalone/web/.next/static/static/chunks/de300ff10b63be85.css +1 -0
  142. package/web/.next/standalone/web/.next/static/static/chunks/de71e63276f488bb.js +7 -0
  143. package/web/.next/standalone/web/src/app/(main)/page.tsx +2 -2
  144. package/web/.next/standalone/web/src/app/api/config/route.ts +3 -2
  145. package/web/.next/standalone/web/src/components/chat-interface.tsx +324 -37
  146. package/web/.next/standalone/web/src/components/sessions-sidebar.tsx +1 -1
  147. package/web/.next/standalone/web/src/lib/api.ts +3 -0
  148. package/web/.next/standalone/web/src/lib/config.ts +2 -1
  149. package/web/.next/static/chunks/{194b3ed8e8d9c0e9.js → 294ebe8457006bce.js} +3 -3
  150. package/web/.next/static/chunks/{23aa98f6e3d7e0e4.js → 7e48d04fbd6dd7a6.js} +5 -3
  151. package/web/.next/{standalone/web/.next/static/chunks/1e9fdac31c7fd474.js → static/chunks/81685e5e8be4eac9.js} +3 -3
  152. package/web/.next/{standalone/web/.next/static/static/chunks/3425251cd978da61.js → static/chunks/8d3efc76109d2efc.js} +1 -1
  153. package/web/.next/static/chunks/96ec96279ada0efe.js +1 -0
  154. package/web/.next/static/chunks/b31b0765abe0c427.js +1 -0
  155. package/web/.next/{standalone/web/.next/static/chunks/c06faa5848e3b0b3.js → static/chunks/b7d722dab2a7ecc0.js} +1 -1
  156. package/web/.next/static/chunks/cc6d43f798bbe415.js +5 -0
  157. package/web/.next/static/chunks/de300ff10b63be85.css +1 -0
  158. package/web/.next/static/chunks/de71e63276f488bb.js +7 -0
  159. package/web/.next/standalone/web/.next/server/chunks/ssr/[root-of-the-server]__9d3fe3b4._.js +0 -3
  160. package/web/.next/standalone/web/.next/server/chunks/ssr/web_631133e0._.js +0 -7
  161. package/web/.next/standalone/web/.next/static/chunks/2110d26bc24ed542.js +0 -1
  162. package/web/.next/standalone/web/.next/static/chunks/4fe97b7866eacdcf.js +0 -7
  163. package/web/.next/standalone/web/.next/static/chunks/7c000de1a1357775.css +0 -1
  164. package/web/.next/standalone/web/.next/static/chunks/a895d50f76a48e6e.js +0 -1
  165. package/web/.next/standalone/web/.next/static/chunks/dccaa0e6b27241a5.js +0 -5
  166. package/web/.next/standalone/web/.next/static/static/chunks/2110d26bc24ed542.js +0 -1
  167. package/web/.next/standalone/web/.next/static/static/chunks/4fe97b7866eacdcf.js +0 -7
  168. package/web/.next/standalone/web/.next/static/static/chunks/7c000de1a1357775.css +0 -1
  169. package/web/.next/standalone/web/.next/static/static/chunks/a895d50f76a48e6e.js +0 -1
  170. package/web/.next/standalone/web/.next/static/static/chunks/dccaa0e6b27241a5.js +0 -5
  171. package/web/.next/static/chunks/2110d26bc24ed542.js +0 -1
  172. package/web/.next/static/chunks/4fe97b7866eacdcf.js +0 -7
  173. package/web/.next/static/chunks/7c000de1a1357775.css +0 -1
  174. package/web/.next/static/chunks/a895d50f76a48e6e.js +0 -1
  175. package/web/.next/static/chunks/dccaa0e6b27241a5.js +0 -5
  176. /package/web/.next/standalone/web/.next/static/{mUwpFRyqjpPrLQ3DS2i5G → _0-MmiObGsO5iLpf0Qgmw}/_buildManifest.js +0 -0
  177. /package/web/.next/standalone/web/.next/static/{mUwpFRyqjpPrLQ3DS2i5G → _0-MmiObGsO5iLpf0Qgmw}/_clientMiddlewareManifest.json +0 -0
  178. /package/web/.next/standalone/web/.next/static/{mUwpFRyqjpPrLQ3DS2i5G → _0-MmiObGsO5iLpf0Qgmw}/_ssgManifest.js +0 -0
  179. /package/web/.next/standalone/web/.next/static/static/{mUwpFRyqjpPrLQ3DS2i5G → _0-MmiObGsO5iLpf0Qgmw}/_buildManifest.js +0 -0
  180. /package/web/.next/standalone/web/.next/static/static/{mUwpFRyqjpPrLQ3DS2i5G → _0-MmiObGsO5iLpf0Qgmw}/_clientMiddlewareManifest.json +0 -0
  181. /package/web/.next/standalone/web/.next/static/static/{mUwpFRyqjpPrLQ3DS2i5G → _0-MmiObGsO5iLpf0Qgmw}/_ssgManifest.js +0 -0
  182. /package/web/.next/static/{mUwpFRyqjpPrLQ3DS2i5G → _0-MmiObGsO5iLpf0Qgmw}/_buildManifest.js +0 -0
  183. /package/web/.next/static/{mUwpFRyqjpPrLQ3DS2i5G → _0-MmiObGsO5iLpf0Qgmw}/_clientMiddlewareManifest.json +0 -0
  184. /package/web/.next/static/{mUwpFRyqjpPrLQ3DS2i5G → _0-MmiObGsO5iLpf0Qgmw}/_ssgManifest.js +0 -0
@@ -18,7 +18,7 @@ declare function createBashTool(options: BashToolOptions): ai.Tool<{
18
18
  command?: string | undefined;
19
19
  kill?: boolean | undefined;
20
20
  tail?: number | undefined;
21
- key?: "y" | "Enter" | "Escape" | "Up" | "Down" | "Left" | "Right" | "Tab" | "C-c" | "C-d" | "n" | undefined;
21
+ key?: "Enter" | "Escape" | "Up" | "Down" | "Left" | "Right" | "Tab" | "C-c" | "C-d" | "y" | "n" | undefined;
22
22
  }, {
23
23
  success: boolean;
24
24
  id: string;
@@ -84,7 +84,7 @@ var init_types = __esm({
84
84
  }).optional();
85
85
  SparkcoderConfigSchema = z.object({
86
86
  // Default model to use (Vercel AI Gateway format)
87
- defaultModel: z.string().default("anthropic/claude-opus-4-5"),
87
+ defaultModel: z.string().default("anthropic/claude-opus-4-6"),
88
88
  // Working directory for file operations
89
89
  workingDirectory: z.string().optional(),
90
90
  // Tool approval settings
@@ -479,12 +479,16 @@ function closeRemoteDatabase() {
479
479
  authKey = null;
480
480
  }
481
481
  var DATE_FIELDS = ["createdAt", "updatedAt", "startedAt", "completedAt", "stoppedAt", "finishedAt", "loadedAt", "indexedAt", "lastFullIndex", "lastIncrementalIndex"];
482
+ var MODEL_MESSAGE_FIELDS = ["modelMessage", "modelMessages"];
482
483
  function parseDates(obj) {
483
484
  if (obj === null || obj === void 0) return obj;
484
485
  if (Array.isArray(obj)) return obj.map(parseDates);
485
- if (typeof obj !== "object") return obj;
486
+ if (typeof obj !== "object" || obj instanceof Date) return obj;
486
487
  const result = { ...obj };
487
488
  for (const key of Object.keys(result)) {
489
+ if (MODEL_MESSAGE_FIELDS.includes(key)) {
490
+ continue;
491
+ }
488
492
  if (DATE_FIELDS.includes(key) && typeof result[key] === "string") {
489
493
  result[key] = new Date(result[key]);
490
494
  } else if (typeof result[key] === "object") {
@@ -517,7 +521,11 @@ async function api(path, options = {}) {
517
521
  if (!text || text === "null") {
518
522
  return null;
519
523
  }
520
- return parseDates(JSON.parse(text));
524
+ const parsed = JSON.parse(text);
525
+ if (options.skipParseDates) {
526
+ return parsed;
527
+ }
528
+ return parseDates(parsed);
521
529
  }
522
530
  var remoteSessionQueries = {
523
531
  create(data) {
@@ -557,7 +565,7 @@ var remoteMessageQueries = {
557
565
  return api(`/messages/session/${sessionId}`);
558
566
  },
559
567
  getModelMessages(sessionId) {
560
- return api(`/messages/session/${sessionId}/model-messages`);
568
+ return api(`/messages/session/${sessionId}/model-messages`, { skipParseDates: true });
561
569
  },
562
570
  async getRecentBySession(sessionId, limit = 50) {
563
571
  const messages = await api(`/messages/session/${sessionId}`);
@@ -4465,6 +4473,142 @@ ${conversationHistory}
4465
4473
  Summary:`;
4466
4474
  }
4467
4475
 
4476
+ // src/utils/sanitize-messages.ts
4477
+ import { modelMessageSchema } from "ai";
4478
+ function convertDatesToStrings(value) {
4479
+ if (value === null || value === void 0) return value;
4480
+ if (value instanceof Date) return value.toISOString();
4481
+ if (Array.isArray(value)) return value.map(convertDatesToStrings);
4482
+ if (typeof value === "object") {
4483
+ const result = {};
4484
+ for (const [k, v] of Object.entries(value)) {
4485
+ result[k] = convertDatesToStrings(v);
4486
+ }
4487
+ return result;
4488
+ }
4489
+ return value;
4490
+ }
4491
+ function sanitizeMessage(msg) {
4492
+ if (msg === null || msg === void 0 || typeof msg !== "object") return msg;
4493
+ const message = msg;
4494
+ if (!message.role || typeof message.role !== "string") return msg;
4495
+ return convertDatesToStrings(message);
4496
+ }
4497
+ function mergeUserContent(a, b) {
4498
+ const aIsString = typeof a === "string";
4499
+ const bIsString = typeof b === "string";
4500
+ if (aIsString && bIsString) {
4501
+ return `${a}
4502
+
4503
+ ${b}`;
4504
+ }
4505
+ const aParts = aIsString ? [{ type: "text", text: a }] : Array.isArray(a) ? a : [];
4506
+ const bParts = bIsString ? [{ type: "text", text: b }] : Array.isArray(b) ? b : [];
4507
+ return [...aParts, ...bParts];
4508
+ }
4509
+ function mergeConsecutiveSameRole(messages) {
4510
+ if (messages.length <= 1) return messages;
4511
+ const merged = [];
4512
+ for (const msg of messages) {
4513
+ const prev = merged[merged.length - 1];
4514
+ if (!prev || prev.role !== msg.role) {
4515
+ merged.push(msg);
4516
+ continue;
4517
+ }
4518
+ const role = msg.role;
4519
+ if (role === "user") {
4520
+ const mergedContent = mergeUserContent(prev.content, msg.content);
4521
+ merged[merged.length - 1] = { role: "user", content: mergedContent };
4522
+ console.warn("[sanitize-messages] Merged consecutive user messages");
4523
+ } else if (role === "assistant") {
4524
+ const prevParts = typeof prev.content === "string" ? [{ type: "text", text: prev.content }] : Array.isArray(prev.content) ? prev.content : [];
4525
+ const curParts = typeof msg.content === "string" ? [{ type: "text", text: msg.content }] : Array.isArray(msg.content) ? msg.content : [];
4526
+ merged[merged.length - 1] = { role: "assistant", content: [...prevParts, ...curParts] };
4527
+ console.warn("[sanitize-messages] Merged consecutive assistant messages");
4528
+ } else if (role === "tool") {
4529
+ const prevContent = Array.isArray(prev.content) ? prev.content : [];
4530
+ const curContent = Array.isArray(msg.content) ? msg.content : [];
4531
+ merged[merged.length - 1] = { role: "tool", content: [...prevContent, ...curContent] };
4532
+ console.warn("[sanitize-messages] Merged consecutive tool messages");
4533
+ } else {
4534
+ merged.push(msg);
4535
+ }
4536
+ }
4537
+ return merged;
4538
+ }
4539
+ function sanitizeModelMessages(messages) {
4540
+ let allValid = true;
4541
+ for (const msg of messages) {
4542
+ try {
4543
+ modelMessageSchema.parse(msg);
4544
+ } catch {
4545
+ allValid = false;
4546
+ break;
4547
+ }
4548
+ }
4549
+ let result;
4550
+ if (allValid) {
4551
+ result = messages;
4552
+ } else {
4553
+ console.warn("[sanitize-messages] Detected invalid messages, attempting self-repair...");
4554
+ const sanitized = [];
4555
+ let repairCount = 0;
4556
+ for (let i = 0; i < messages.length; i++) {
4557
+ const msg = messages[i];
4558
+ try {
4559
+ modelMessageSchema.parse(msg);
4560
+ sanitized.push(msg);
4561
+ continue;
4562
+ } catch {
4563
+ }
4564
+ const fixed = sanitizeMessage(msg);
4565
+ try {
4566
+ modelMessageSchema.parse(fixed);
4567
+ sanitized.push(fixed);
4568
+ repairCount++;
4569
+ console.warn(`[sanitize-messages] Repaired message ${i} (role=${msg.role}) - converted Date objects to strings`);
4570
+ continue;
4571
+ } catch {
4572
+ }
4573
+ if (msg.role === "tool" && Array.isArray(msg.content)) {
4574
+ const fixedContent = msg.content.map((part) => {
4575
+ if (part.type === "tool-result" && part.output !== void 0) {
4576
+ const output = convertDatesToStrings(part.output);
4577
+ if (output && typeof output === "object" && !output.type) {
4578
+ return { ...part, output: { type: "json", value: output } };
4579
+ }
4580
+ const knownTypes = ["text", "json", "execution-denied", "error-text", "error-json", "content"];
4581
+ if (output && typeof output === "object" && !knownTypes.includes(output.type)) {
4582
+ return { ...part, output: { type: "json", value: output } };
4583
+ }
4584
+ return { ...part, output };
4585
+ }
4586
+ return convertDatesToStrings(part);
4587
+ });
4588
+ const wrappedMsg = { ...msg, content: fixedContent };
4589
+ try {
4590
+ modelMessageSchema.parse(wrappedMsg);
4591
+ sanitized.push(wrappedMsg);
4592
+ repairCount++;
4593
+ console.warn(`[sanitize-messages] Repaired message ${i} (role=tool) - wrapped raw output in json type`);
4594
+ continue;
4595
+ } catch {
4596
+ }
4597
+ }
4598
+ console.error(
4599
+ `[sanitize-messages] Could not repair message ${i} (role=${msg.role}). Message will be included as-is. Content keys: ${JSON.stringify(Object.keys(msg))}`
4600
+ );
4601
+ sanitized.push(msg);
4602
+ }
4603
+ if (repairCount > 0) {
4604
+ console.warn(`[sanitize-messages] Self-repair complete: fixed ${repairCount}/${messages.length} messages`);
4605
+ }
4606
+ result = sanitized;
4607
+ }
4608
+ result = mergeConsecutiveSameRole(result);
4609
+ return result;
4610
+ }
4611
+
4468
4612
  // src/agent/context.ts
4469
4613
  var ContextManager = class {
4470
4614
  sessionId;
@@ -4481,9 +4625,14 @@ var ContextManager = class {
4481
4625
  /**
4482
4626
  * Get messages for the current context
4483
4627
  * Returns ModelMessage[] that can be passed directly to streamText/generateText
4628
+ *
4629
+ * Includes self-repair: if messages from the database have been corrupted
4630
+ * (e.g., Date objects in tool outputs from parseDates), they are automatically
4631
+ * sanitized to conform to the AI SDK's ModelMessage schema.
4484
4632
  */
4485
4633
  async getMessages() {
4486
4634
  let modelMessages = await messageQueries.getModelMessages(this.sessionId);
4635
+ modelMessages = sanitizeModelMessages(modelMessages);
4487
4636
  const contextSize = calculateContextSize(modelMessages);
4488
4637
  if (this.autoSummarize && contextSize > this.maxContextChars) {
4489
4638
  modelMessages = await this.summarizeContext(modelMessages);
@@ -4910,10 +5059,27 @@ ${prompt}` });
4910
5059
  }
4911
5060
  };
4912
5061
 
5062
+ // src/server/devtools-store.ts
5063
+ var devtoolsContextStore = /* @__PURE__ */ new Map();
5064
+ function setDevtoolsContext(sessionId, context) {
5065
+ devtoolsContextStore.set(sessionId, context);
5066
+ }
5067
+ function getDevtoolsContext(sessionId) {
5068
+ cleanupStaleContexts();
5069
+ return devtoolsContextStore.get(sessionId) || null;
5070
+ }
5071
+ function cleanupStaleContexts() {
5072
+ const now = Date.now();
5073
+ for (const [sessionId, ctx] of devtoolsContextStore) {
5074
+ if (now - ctx.lastHeartbeat.getTime() > 30 * 1e3) {
5075
+ devtoolsContextStore.delete(sessionId);
5076
+ }
5077
+ }
5078
+ }
5079
+
4913
5080
  // src/server/routes/sessions.ts
4914
5081
  var sessions = new Hono();
4915
5082
  var pendingInputStore = /* @__PURE__ */ new Map();
4916
- var devtoolsContextStore = /* @__PURE__ */ new Map();
4917
5083
  function cleanupPendingInputs() {
4918
5084
  const now = Date.now();
4919
5085
  for (const [sessionId, entry] of pendingInputStore) {
@@ -4922,14 +5088,6 @@ function cleanupPendingInputs() {
4922
5088
  }
4923
5089
  }
4924
5090
  }
4925
- function cleanupDevtoolsContexts() {
4926
- const now = Date.now();
4927
- for (const [sessionId, ctx] of devtoolsContextStore) {
4928
- if (now - ctx.lastHeartbeat.getTime() > 30 * 1e3) {
4929
- devtoolsContextStore.delete(sessionId);
4930
- }
4931
- }
4932
- }
4933
5091
  var createSessionSchema = z12.object({
4934
5092
  name: z12.string().optional(),
4935
5093
  workingDirectory: z12.string().optional(),
@@ -5188,7 +5346,10 @@ sessions.get("/:id/pending-input", async (c) => {
5188
5346
  var devtoolsContextSchema = z12.object({
5189
5347
  url: z12.string(),
5190
5348
  path: z12.string(),
5191
- pageName: z12.string().optional()
5349
+ pageName: z12.string().optional(),
5350
+ screenWidth: z12.number().optional(),
5351
+ screenHeight: z12.number().optional(),
5352
+ devicePixelRatio: z12.number().optional()
5192
5353
  });
5193
5354
  sessions.post(
5194
5355
  "/:id/devtools-context",
@@ -5196,20 +5357,21 @@ sessions.post(
5196
5357
  async (c) => {
5197
5358
  const id = c.req.param("id");
5198
5359
  const body = c.req.valid("json");
5199
- devtoolsContextStore.set(id, {
5360
+ setDevtoolsContext(id, {
5200
5361
  url: body.url,
5201
5362
  path: body.path,
5202
5363
  pageName: body.pageName || body.path,
5364
+ screenWidth: body.screenWidth,
5365
+ screenHeight: body.screenHeight,
5366
+ devicePixelRatio: body.devicePixelRatio,
5203
5367
  lastHeartbeat: /* @__PURE__ */ new Date()
5204
5368
  });
5205
- cleanupDevtoolsContexts();
5206
5369
  return c.json({ success: true, sessionId: id });
5207
5370
  }
5208
5371
  );
5209
5372
  sessions.get("/:id/devtools-context", async (c) => {
5210
5373
  const id = c.req.param("id");
5211
- cleanupDevtoolsContexts();
5212
- const ctx = devtoolsContextStore.get(id);
5374
+ const ctx = getDevtoolsContext(id);
5213
5375
  if (!ctx) {
5214
5376
  return c.json({ connected: false, context: null });
5215
5377
  }
@@ -5219,6 +5381,9 @@ sessions.get("/:id/devtools-context", async (c) => {
5219
5381
  url: ctx.url,
5220
5382
  path: ctx.path,
5221
5383
  pageName: ctx.pageName,
5384
+ screenWidth: ctx.screenWidth,
5385
+ screenHeight: ctx.screenHeight,
5386
+ devicePixelRatio: ctx.devicePixelRatio,
5222
5387
  lastHeartbeat: ctx.lastHeartbeat.toISOString()
5223
5388
  }
5224
5389
  });
@@ -5799,6 +5964,25 @@ async function emitSyntheticToolStreaming(writeSSE, toolCallStarts, toolCallId,
5799
5964
  await new Promise((resolve10) => setTimeout(resolve10, 0));
5800
5965
  }
5801
5966
  }
5967
+ function buildDevtoolsContextXml(sessionId) {
5968
+ const ctx = getDevtoolsContext(sessionId);
5969
+ if (!ctx) return "";
5970
+ const parts = [];
5971
+ parts.push(`<devtools-context>`);
5972
+ parts.push(` <page url="${ctx.url}" path="${ctx.path}" name="${ctx.pageName}" />`);
5973
+ if (ctx.screenWidth && ctx.screenHeight) {
5974
+ parts.push(` <viewport width="${ctx.screenWidth}" height="${ctx.screenHeight}"${ctx.devicePixelRatio ? ` dpr="${ctx.devicePixelRatio}"` : ""} />`);
5975
+ }
5976
+ parts.push(`</devtools-context>`);
5977
+ return parts.join("\n");
5978
+ }
5979
+ function enrichPromptWithDevtoolsContext(sessionId, prompt) {
5980
+ const xml = buildDevtoolsContextXml(sessionId);
5981
+ if (!xml) return prompt;
5982
+ return `${xml}
5983
+
5984
+ ${prompt}`;
5985
+ }
5802
5986
  var agents = new Hono2();
5803
5987
  var attachmentSchema = z13.object({
5804
5988
  type: z13.enum(["image", "file"]),
@@ -6134,7 +6318,8 @@ agents.post(
6134
6318
  zValidator2("json", runPromptSchema),
6135
6319
  async (c) => {
6136
6320
  const id = c.req.param("id");
6137
- const { prompt, attachments } = c.req.valid("json");
6321
+ const { prompt: rawPrompt, attachments } = c.req.valid("json");
6322
+ const prompt = enrichPromptWithDevtoolsContext(id, rawPrompt);
6138
6323
  const session = await sessionQueries.getById(id);
6139
6324
  if (!session) {
6140
6325
  return c.json({ error: "Session not found" }, 404);
@@ -6279,7 +6464,8 @@ agents.post(
6279
6464
  zValidator2("json", runPromptSchema),
6280
6465
  async (c) => {
6281
6466
  const id = c.req.param("id");
6282
- const { prompt } = c.req.valid("json");
6467
+ const { prompt: rawPrompt } = c.req.valid("json");
6468
+ const prompt = enrichPromptWithDevtoolsContext(id, rawPrompt);
6283
6469
  const session = await sessionQueries.getById(id);
6284
6470
  if (!session) {
6285
6471
  return c.json({ error: "Session not found" }, 404);
@@ -6394,6 +6580,7 @@ agents.post(
6394
6580
  sessionConfig: body.toolApprovals ? { toolApprovals: body.toolApprovals } : void 0
6395
6581
  });
6396
6582
  const session = agent.getSession();
6583
+ const enrichedPrompt = enrichPromptWithDevtoolsContext(session.id, body.prompt);
6397
6584
  const streamId = `stream_${session.id}_${nanoid5(10)}`;
6398
6585
  await createCheckpoint(session.id, session.workingDirectory, 0);
6399
6586
  await activeStreamQueries.create(session.id, streamId);
@@ -6443,7 +6630,7 @@ agents.post(
6443
6630
  let textId = `text_${Date.now()}`;
6444
6631
  let textStarted = false;
6445
6632
  const result = await agent.stream({
6446
- prompt: body.prompt,
6633
+ prompt: enrichedPrompt,
6447
6634
  abortSignal: abortController.signal,
6448
6635
  // Use our managed abort controller, NOT client signal
6449
6636
  onToolProgress: async (progress) => {