sparkecoder 0.1.73 → 0.1.74

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 (89) hide show
  1. package/dist/agent/index.d.ts +1 -1
  2. package/dist/agent/index.js +84 -10
  3. package/dist/agent/index.js.map +1 -1
  4. package/dist/cli.js +84 -10
  5. package/dist/cli.js.map +1 -1
  6. package/dist/{index-dbWF1hyW.d.ts → index-DT1l57s0.d.ts} +6 -0
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.js +84 -10
  9. package/dist/index.js.map +1 -1
  10. package/dist/server/index.js +84 -10
  11. package/dist/server/index.js.map +1 -1
  12. package/dist/tools/index.js +16 -6
  13. package/dist/tools/index.js.map +1 -1
  14. package/package.json +1 -1
  15. package/web/.next/BUILD_ID +1 -1
  16. package/web/.next/standalone/web/.next/BUILD_ID +1 -1
  17. package/web/.next/standalone/web/.next/build-manifest.json +2 -2
  18. package/web/.next/standalone/web/.next/prerender-manifest.json +3 -3
  19. package/web/.next/standalone/web/.next/server/app/_global-error.html +2 -2
  20. package/web/.next/standalone/web/.next/server/app/_global-error.rsc +1 -1
  21. package/web/.next/standalone/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  22. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  23. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  24. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  25. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  26. package/web/.next/standalone/web/.next/server/app/_not-found.html +1 -1
  27. package/web/.next/standalone/web/.next/server/app/_not-found.rsc +1 -1
  28. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  29. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  30. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  31. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  32. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  33. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  34. package/web/.next/standalone/web/.next/server/app/docs/installation.html +2 -2
  35. package/web/.next/standalone/web/.next/server/app/docs/installation.rsc +1 -1
  36. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_full.segment.rsc +1 -1
  37. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_head.segment.rsc +1 -1
  38. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_index.segment.rsc +1 -1
  39. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_tree.segment.rsc +1 -1
  40. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs/installation/__PAGE__.segment.rsc +1 -1
  41. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs/installation.segment.rsc +1 -1
  42. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs.segment.rsc +1 -1
  43. package/web/.next/standalone/web/.next/server/app/docs/skills.html +2 -2
  44. package/web/.next/standalone/web/.next/server/app/docs/skills.rsc +1 -1
  45. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_full.segment.rsc +1 -1
  46. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_head.segment.rsc +1 -1
  47. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_index.segment.rsc +1 -1
  48. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_tree.segment.rsc +1 -1
  49. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs/skills/__PAGE__.segment.rsc +1 -1
  50. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs/skills.segment.rsc +1 -1
  51. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs.segment.rsc +1 -1
  52. package/web/.next/standalone/web/.next/server/app/docs/tools.html +2 -2
  53. package/web/.next/standalone/web/.next/server/app/docs/tools.rsc +1 -1
  54. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_full.segment.rsc +1 -1
  55. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_head.segment.rsc +1 -1
  56. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_index.segment.rsc +1 -1
  57. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_tree.segment.rsc +1 -1
  58. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs/tools/__PAGE__.segment.rsc +1 -1
  59. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs/tools.segment.rsc +1 -1
  60. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs.segment.rsc +1 -1
  61. package/web/.next/standalone/web/.next/server/app/docs.html +2 -2
  62. package/web/.next/standalone/web/.next/server/app/docs.rsc +1 -1
  63. package/web/.next/standalone/web/.next/server/app/docs.segments/_full.segment.rsc +1 -1
  64. package/web/.next/standalone/web/.next/server/app/docs.segments/_head.segment.rsc +1 -1
  65. package/web/.next/standalone/web/.next/server/app/docs.segments/_index.segment.rsc +1 -1
  66. package/web/.next/standalone/web/.next/server/app/docs.segments/_tree.segment.rsc +1 -1
  67. package/web/.next/standalone/web/.next/server/app/docs.segments/docs/__PAGE__.segment.rsc +1 -1
  68. package/web/.next/standalone/web/.next/server/app/docs.segments/docs.segment.rsc +1 -1
  69. package/web/.next/standalone/web/.next/server/app/index.html +1 -1
  70. package/web/.next/standalone/web/.next/server/app/index.rsc +1 -1
  71. package/web/.next/standalone/web/.next/server/app/index.segments/!KG1haW4p/__PAGE__.segment.rsc +1 -1
  72. package/web/.next/standalone/web/.next/server/app/index.segments/!KG1haW4p.segment.rsc +1 -1
  73. package/web/.next/standalone/web/.next/server/app/index.segments/_full.segment.rsc +1 -1
  74. package/web/.next/standalone/web/.next/server/app/index.segments/_head.segment.rsc +1 -1
  75. package/web/.next/standalone/web/.next/server/app/index.segments/_index.segment.rsc +1 -1
  76. package/web/.next/standalone/web/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  77. package/web/.next/standalone/web/.next/server/pages/404.html +1 -1
  78. package/web/.next/standalone/web/.next/server/pages/500.html +2 -2
  79. package/web/.next/standalone/web/.next/server/server-reference-manifest.js +1 -1
  80. package/web/.next/standalone/web/.next/server/server-reference-manifest.json +1 -1
  81. /package/web/.next/standalone/web/.next/static/{2xYE9FvjZmf0tU0NF5Jvj → _Xl7dVMD-6ghn4EberTUE}/_buildManifest.js +0 -0
  82. /package/web/.next/standalone/web/.next/static/{2xYE9FvjZmf0tU0NF5Jvj → _Xl7dVMD-6ghn4EberTUE}/_clientMiddlewareManifest.json +0 -0
  83. /package/web/.next/standalone/web/.next/static/{2xYE9FvjZmf0tU0NF5Jvj → _Xl7dVMD-6ghn4EberTUE}/_ssgManifest.js +0 -0
  84. /package/web/.next/standalone/web/.next/static/static/{2xYE9FvjZmf0tU0NF5Jvj → _Xl7dVMD-6ghn4EberTUE}/_buildManifest.js +0 -0
  85. /package/web/.next/standalone/web/.next/static/static/{2xYE9FvjZmf0tU0NF5Jvj → _Xl7dVMD-6ghn4EberTUE}/_clientMiddlewareManifest.json +0 -0
  86. /package/web/.next/standalone/web/.next/static/static/{2xYE9FvjZmf0tU0NF5Jvj → _Xl7dVMD-6ghn4EberTUE}/_ssgManifest.js +0 -0
  87. /package/web/.next/static/{2xYE9FvjZmf0tU0NF5Jvj → _Xl7dVMD-6ghn4EberTUE}/_buildManifest.js +0 -0
  88. /package/web/.next/static/{2xYE9FvjZmf0tU0NF5Jvj → _Xl7dVMD-6ghn4EberTUE}/_clientMiddlewareManifest.json +0 -0
  89. /package/web/.next/static/{2xYE9FvjZmf0tU0NF5Jvj → _Xl7dVMD-6ghn4EberTUE}/_ssgManifest.js +0 -0
@@ -314,6 +314,9 @@ interface ContextManagerOptions {
314
314
  * via a cheap/fast model (gemini-3-flash-preview).
315
315
  * Phase 3 – Roll summaries: when accumulated summaries exceed their budget
316
316
  * (~15 % of rolling target), re-summarize them into one.
317
+ *
318
+ * A final repair pass ensures all tool-call / tool-result pairs are matched
319
+ * before the messages leave the context manager.
317
320
  */
318
321
  declare class ContextManager {
319
322
  private sessionId;
@@ -330,6 +333,9 @@ declare class ContextManager {
330
333
  /**
331
334
  * Strip non-essential content from messages older than the most recent
332
335
  * `recentCount`. Operates in-memory only — does not touch the DB.
336
+ *
337
+ * Tracks removed tool-call IDs so matching tool-results are also removed,
338
+ * preventing orphaned tool_result blocks that providers reject.
333
339
  */
334
340
  compactOlderMessages(messages: ModelMessage[], recentCount: number): ModelMessage[];
335
341
  private compactMessage;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as ResolvedConfig } from './index-dbWF1hyW.js';
2
- export { A as Agent, a as AgentOptions, b as AgentRunOptions, c as AgentStreamResult, S as SparkcoderConfig, T as ToolApprovalConfig } from './index-dbWF1hyW.js';
1
+ import { R as ResolvedConfig } from './index-DT1l57s0.js';
2
+ export { A as Agent, a as AgentOptions, b as AgentRunOptions, c as AgentStreamResult, S as SparkcoderConfig, T as ToolApprovalConfig } from './index-DT1l57s0.js';
3
3
  export { ServerOptions, createApp, startServer, stopServer } from './server/index.js';
4
4
  export { checkpointQueries, closeDatabase, fileBackupQueries, getDb, initDatabase, messageQueries, sessionQueries, skillQueries, todoQueries, toolExecutionQueries } from './db/index.js';
5
5
  import { F as FileBackup, C as Checkpoint } from './schema-XcP0dedO.js';
package/dist/index.js CHANGED
@@ -2162,9 +2162,8 @@ function createRemoteModel(modelId, config) {
2162
2162
  });
2163
2163
  if (!res.ok) {
2164
2164
  const err = await res.json().catch(() => ({}));
2165
- throw new Error(
2166
- `Remote inference failed (${res.status}): ${err.error || res.statusText}`
2167
- );
2165
+ const detail = formatRemoteError(res.status, modelId, err);
2166
+ throw new Error(detail);
2168
2167
  }
2169
2168
  const result = await res.json();
2170
2169
  return deserializeValue(result);
@@ -2181,9 +2180,8 @@ function createRemoteModel(modelId, config) {
2181
2180
  });
2182
2181
  if (!res.ok) {
2183
2182
  const err = await res.json().catch(() => ({}));
2184
- throw new Error(
2185
- `Remote inference failed (${res.status}): ${err.error || res.statusText}`
2186
- );
2183
+ const detail = formatRemoteError(res.status, modelId, err);
2184
+ throw new Error(detail);
2187
2185
  }
2188
2186
  const reader = res.body.getReader();
2189
2187
  const decoder = new TextDecoder();
@@ -2241,6 +2239,18 @@ function createRemoteModel(modelId, config) {
2241
2239
  }
2242
2240
  };
2243
2241
  }
2242
+ function formatRemoteError(status, modelId, body) {
2243
+ const parts = [`Remote inference failed (${status}) for ${modelId}`];
2244
+ if (body.error) parts.push(body.error);
2245
+ if (body.details) {
2246
+ const d = body.details;
2247
+ if (d.type) parts.push(`type=${d.type}`);
2248
+ if (d.statusCode && d.statusCode !== status) parts.push(`upstream=${d.statusCode}`);
2249
+ if (d.cause) parts.push(`cause: ${d.cause}`);
2250
+ if (d.orderWarnings?.length) parts.push(`prompt issues: ${d.orderWarnings.join("; ")}`);
2251
+ }
2252
+ return parts.join(" \u2014 ");
2253
+ }
2244
2254
 
2245
2255
  // src/agent/model.ts
2246
2256
  init_config();
@@ -6496,6 +6506,7 @@ ${summaryContent}`
6496
6506
  ...messages
6497
6507
  ];
6498
6508
  }
6509
+ messages = repairToolPairing(messages);
6499
6510
  return messages;
6500
6511
  }
6501
6512
  // ---------------------------------------------------------------------------
@@ -6504,25 +6515,43 @@ ${summaryContent}`
6504
6515
  /**
6505
6516
  * Strip non-essential content from messages older than the most recent
6506
6517
  * `recentCount`. Operates in-memory only — does not touch the DB.
6518
+ *
6519
+ * Tracks removed tool-call IDs so matching tool-results are also removed,
6520
+ * preventing orphaned tool_result blocks that providers reject.
6507
6521
  */
6508
6522
  compactOlderMessages(messages, recentCount) {
6509
6523
  if (messages.length <= recentCount) return messages;
6510
6524
  const boundary = messages.length - recentCount;
6511
6525
  const olderMessages = messages.slice(0, boundary);
6512
6526
  const recentMessages = messages.slice(boundary);
6527
+ const removedToolCallIds = /* @__PURE__ */ new Set();
6513
6528
  const compacted = [];
6514
6529
  for (const msg of olderMessages) {
6515
- const processed = this.compactMessage(msg);
6530
+ const processed = this.compactMessage(msg, removedToolCallIds);
6516
6531
  if (processed) compacted.push(processed);
6517
6532
  }
6533
+ if (removedToolCallIds.size > 0) {
6534
+ const cleaned = [];
6535
+ for (const msg of compacted) {
6536
+ const result = stripOrphanedToolResults(msg, removedToolCallIds);
6537
+ if (result) cleaned.push(result);
6538
+ }
6539
+ return [...cleaned, ...recentMessages];
6540
+ }
6518
6541
  return [...compacted, ...recentMessages];
6519
6542
  }
6520
- compactMessage(msg) {
6543
+ compactMessage(msg, removedToolCallIds) {
6521
6544
  if (!Array.isArray(msg.content)) return msg;
6522
6545
  const parts = [];
6523
6546
  for (const part of msg.content) {
6524
- if (part.type === "tool-call" && part.toolName === "todo") continue;
6525
- if (part.type === "tool-result" && part.toolName === "todo") continue;
6547
+ if (part.type === "tool-call" && part.toolName === "todo") {
6548
+ if (part.toolCallId) removedToolCallIds.add(part.toolCallId);
6549
+ continue;
6550
+ }
6551
+ if (part.type === "tool-result" && part.toolName === "todo") {
6552
+ if (part.toolCallId) removedToolCallIds.add(part.toolCallId);
6553
+ continue;
6554
+ }
6526
6555
  if (part.type === "reasoning" || part.type === "thinking") continue;
6527
6556
  if (part.type === "tool-result" && COMPACTABLE_TOOLS.has(part.toolName)) {
6528
6557
  parts.push(this.trimToolResult(part));
@@ -6672,6 +6701,51 @@ ${summaryContent}`
6672
6701
  this.summaries = [];
6673
6702
  }
6674
6703
  };
6704
+ function stripOrphanedToolResults(msg, removedIds) {
6705
+ if (!Array.isArray(msg.content)) return msg;
6706
+ const parts = msg.content.filter((part) => {
6707
+ if (part.type === "tool-result" && removedIds.has(part.toolCallId)) return false;
6708
+ if (part.type === "tool-call" && removedIds.has(part.toolCallId)) return false;
6709
+ return true;
6710
+ });
6711
+ if (parts.length === 0) return null;
6712
+ return { ...msg, content: parts };
6713
+ }
6714
+ function repairToolPairing(messages) {
6715
+ const toolCallIds = /* @__PURE__ */ new Set();
6716
+ const toolResultIds = /* @__PURE__ */ new Set();
6717
+ for (const msg of messages) {
6718
+ if (!Array.isArray(msg.content)) continue;
6719
+ for (const part of msg.content) {
6720
+ if (part.type === "tool-call" && part.toolCallId) toolCallIds.add(part.toolCallId);
6721
+ if (part.type === "tool-result" && part.toolCallId) toolResultIds.add(part.toolCallId);
6722
+ }
6723
+ }
6724
+ const orphanedCalls = new Set([...toolCallIds].filter((id) => !toolResultIds.has(id)));
6725
+ const orphanedResults = new Set([...toolResultIds].filter((id) => !toolCallIds.has(id)));
6726
+ if (orphanedCalls.size === 0 && orphanedResults.size === 0) return messages;
6727
+ if (orphanedCalls.size > 0) {
6728
+ console.warn(`[tool-repair] Removing ${orphanedCalls.size} orphaned tool-call(s) with no matching result`);
6729
+ }
6730
+ if (orphanedResults.size > 0) {
6731
+ console.warn(`[tool-repair] Removing ${orphanedResults.size} orphaned tool-result(s) with no matching call`);
6732
+ }
6733
+ const repaired = [];
6734
+ for (const msg of messages) {
6735
+ if (!Array.isArray(msg.content)) {
6736
+ repaired.push(msg);
6737
+ continue;
6738
+ }
6739
+ const parts = msg.content.filter((part) => {
6740
+ if (part.type === "tool-call" && orphanedCalls.has(part.toolCallId)) return false;
6741
+ if (part.type === "tool-result" && orphanedResults.has(part.toolCallId)) return false;
6742
+ return true;
6743
+ });
6744
+ if (parts.length === 0) continue;
6745
+ repaired.push({ ...msg, content: parts });
6746
+ }
6747
+ return repaired;
6748
+ }
6675
6749
 
6676
6750
  // src/agent/index.ts
6677
6751
  init_webhook();