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
package/dist/cli.js CHANGED
@@ -2962,9 +2962,8 @@ function createRemoteModel(modelId, config) {
2962
2962
  });
2963
2963
  if (!res.ok) {
2964
2964
  const err = await res.json().catch(() => ({}));
2965
- throw new Error(
2966
- `Remote inference failed (${res.status}): ${err.error || res.statusText}`
2967
- );
2965
+ const detail = formatRemoteError(res.status, modelId, err);
2966
+ throw new Error(detail);
2968
2967
  }
2969
2968
  const result = await res.json();
2970
2969
  return deserializeValue(result);
@@ -2981,9 +2980,8 @@ function createRemoteModel(modelId, config) {
2981
2980
  });
2982
2981
  if (!res.ok) {
2983
2982
  const err = await res.json().catch(() => ({}));
2984
- throw new Error(
2985
- `Remote inference failed (${res.status}): ${err.error || res.statusText}`
2986
- );
2983
+ const detail = formatRemoteError(res.status, modelId, err);
2984
+ throw new Error(detail);
2987
2985
  }
2988
2986
  const reader = res.body.getReader();
2989
2987
  const decoder = new TextDecoder();
@@ -3041,6 +3039,18 @@ function createRemoteModel(modelId, config) {
3041
3039
  }
3042
3040
  };
3043
3041
  }
3042
+ function formatRemoteError(status, modelId, body) {
3043
+ const parts = [`Remote inference failed (${status}) for ${modelId}`];
3044
+ if (body.error) parts.push(body.error);
3045
+ if (body.details) {
3046
+ const d = body.details;
3047
+ if (d.type) parts.push(`type=${d.type}`);
3048
+ if (d.statusCode && d.statusCode !== status) parts.push(`upstream=${d.statusCode}`);
3049
+ if (d.cause) parts.push(`cause: ${d.cause}`);
3050
+ if (d.orderWarnings?.length) parts.push(`prompt issues: ${d.orderWarnings.join("; ")}`);
3051
+ }
3052
+ return parts.join(" \u2014 ");
3053
+ }
3044
3054
 
3045
3055
  // src/agent/model.ts
3046
3056
  init_config();
@@ -7279,6 +7289,7 @@ ${summaryContent}`
7279
7289
  ...messages
7280
7290
  ];
7281
7291
  }
7292
+ messages = repairToolPairing(messages);
7282
7293
  return messages;
7283
7294
  }
7284
7295
  // ---------------------------------------------------------------------------
@@ -7287,25 +7298,43 @@ ${summaryContent}`
7287
7298
  /**
7288
7299
  * Strip non-essential content from messages older than the most recent
7289
7300
  * `recentCount`. Operates in-memory only — does not touch the DB.
7301
+ *
7302
+ * Tracks removed tool-call IDs so matching tool-results are also removed,
7303
+ * preventing orphaned tool_result blocks that providers reject.
7290
7304
  */
7291
7305
  compactOlderMessages(messages, recentCount) {
7292
7306
  if (messages.length <= recentCount) return messages;
7293
7307
  const boundary = messages.length - recentCount;
7294
7308
  const olderMessages = messages.slice(0, boundary);
7295
7309
  const recentMessages = messages.slice(boundary);
7310
+ const removedToolCallIds = /* @__PURE__ */ new Set();
7296
7311
  const compacted = [];
7297
7312
  for (const msg of olderMessages) {
7298
- const processed = this.compactMessage(msg);
7313
+ const processed = this.compactMessage(msg, removedToolCallIds);
7299
7314
  if (processed) compacted.push(processed);
7300
7315
  }
7316
+ if (removedToolCallIds.size > 0) {
7317
+ const cleaned = [];
7318
+ for (const msg of compacted) {
7319
+ const result = stripOrphanedToolResults(msg, removedToolCallIds);
7320
+ if (result) cleaned.push(result);
7321
+ }
7322
+ return [...cleaned, ...recentMessages];
7323
+ }
7301
7324
  return [...compacted, ...recentMessages];
7302
7325
  }
7303
- compactMessage(msg) {
7326
+ compactMessage(msg, removedToolCallIds) {
7304
7327
  if (!Array.isArray(msg.content)) return msg;
7305
7328
  const parts = [];
7306
7329
  for (const part of msg.content) {
7307
- if (part.type === "tool-call" && part.toolName === "todo") continue;
7308
- if (part.type === "tool-result" && part.toolName === "todo") continue;
7330
+ if (part.type === "tool-call" && part.toolName === "todo") {
7331
+ if (part.toolCallId) removedToolCallIds.add(part.toolCallId);
7332
+ continue;
7333
+ }
7334
+ if (part.type === "tool-result" && part.toolName === "todo") {
7335
+ if (part.toolCallId) removedToolCallIds.add(part.toolCallId);
7336
+ continue;
7337
+ }
7309
7338
  if (part.type === "reasoning" || part.type === "thinking") continue;
7310
7339
  if (part.type === "tool-result" && COMPACTABLE_TOOLS.has(part.toolName)) {
7311
7340
  parts.push(this.trimToolResult(part));
@@ -7455,6 +7484,51 @@ ${summaryContent}`
7455
7484
  this.summaries = [];
7456
7485
  }
7457
7486
  };
7487
+ function stripOrphanedToolResults(msg, removedIds) {
7488
+ if (!Array.isArray(msg.content)) return msg;
7489
+ const parts = msg.content.filter((part) => {
7490
+ if (part.type === "tool-result" && removedIds.has(part.toolCallId)) return false;
7491
+ if (part.type === "tool-call" && removedIds.has(part.toolCallId)) return false;
7492
+ return true;
7493
+ });
7494
+ if (parts.length === 0) return null;
7495
+ return { ...msg, content: parts };
7496
+ }
7497
+ function repairToolPairing(messages) {
7498
+ const toolCallIds = /* @__PURE__ */ new Set();
7499
+ const toolResultIds = /* @__PURE__ */ new Set();
7500
+ for (const msg of messages) {
7501
+ if (!Array.isArray(msg.content)) continue;
7502
+ for (const part of msg.content) {
7503
+ if (part.type === "tool-call" && part.toolCallId) toolCallIds.add(part.toolCallId);
7504
+ if (part.type === "tool-result" && part.toolCallId) toolResultIds.add(part.toolCallId);
7505
+ }
7506
+ }
7507
+ const orphanedCalls = new Set([...toolCallIds].filter((id) => !toolResultIds.has(id)));
7508
+ const orphanedResults = new Set([...toolResultIds].filter((id) => !toolCallIds.has(id)));
7509
+ if (orphanedCalls.size === 0 && orphanedResults.size === 0) return messages;
7510
+ if (orphanedCalls.size > 0) {
7511
+ console.warn(`[tool-repair] Removing ${orphanedCalls.size} orphaned tool-call(s) with no matching result`);
7512
+ }
7513
+ if (orphanedResults.size > 0) {
7514
+ console.warn(`[tool-repair] Removing ${orphanedResults.size} orphaned tool-result(s) with no matching call`);
7515
+ }
7516
+ const repaired = [];
7517
+ for (const msg of messages) {
7518
+ if (!Array.isArray(msg.content)) {
7519
+ repaired.push(msg);
7520
+ continue;
7521
+ }
7522
+ const parts = msg.content.filter((part) => {
7523
+ if (part.type === "tool-call" && orphanedCalls.has(part.toolCallId)) return false;
7524
+ if (part.type === "tool-result" && orphanedResults.has(part.toolCallId)) return false;
7525
+ return true;
7526
+ });
7527
+ if (parts.length === 0) continue;
7528
+ repaired.push({ ...msg, content: parts });
7529
+ }
7530
+ return repaired;
7531
+ }
7458
7532
 
7459
7533
  // src/agent/index.ts
7460
7534
  init_webhook();