@superatomai/sdk-node 0.0.59-dsp → 0.0.60-dsp

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.
package/dist/index.js CHANGED
@@ -24486,6 +24486,7 @@ async function installInstructions(def, ws) {
24486
24486
  logger.warn(`[CodingAgent:${def.id}] no system.md at ${src} \u2014 running without standing instructions`);
24487
24487
  }
24488
24488
  }
24489
+ var REPAIR_TIMEOUT_MS = 3 * 6e4;
24489
24490
  async function pruneRuns(agentDir, keep) {
24490
24491
  if (keep <= 0) return;
24491
24492
  try {
@@ -24650,11 +24651,56 @@ async function runCodingAgent(agentId, options = {}) {
24650
24651
  return record;
24651
24652
  }
24652
24653
  let parsed;
24653
- try {
24654
- parsed = def.output.schema.parse(JSON.parse(raw));
24655
- } catch (err) {
24656
- record.error = `deliverable failed validation: ${err?.message ?? err}`;
24657
- return record;
24654
+ let rawText = raw;
24655
+ let firstError;
24656
+ for (let attempt = 0; ; attempt++) {
24657
+ try {
24658
+ parsed = def.output.schema.parse(JSON.parse(rawText));
24659
+ break;
24660
+ } catch (err) {
24661
+ const message = err?.message ?? String(err);
24662
+ if (attempt > 0 || !result.sessionId) {
24663
+ record.error = firstError ? `deliverable failed validation after a repair attempt: ${message} (first: ${firstError})` : `deliverable failed validation: ${message}`;
24664
+ return record;
24665
+ }
24666
+ firstError = message;
24667
+ logger.warn(`[CodingAgent:${def.id}] deliverable rejected (${message}) \u2014 asking the agent to repair it`);
24668
+ const repair = createCodingAgentSession(def.harness || cfg.harness, {
24669
+ cwd: dir,
24670
+ model: def.model || cfg.model,
24671
+ resumeId: result.sessionId,
24672
+ mcpServers: tools && Object.keys(tools).length ? tools : void 0,
24673
+ ...def.networkAccessEnabled !== void 0 ? { networkAccessEnabled: def.networkAccessEnabled } : {},
24674
+ ...def.sandboxMode ? { sandboxMode: def.sandboxMode } : {}
24675
+ });
24676
+ const repairTimeout = new AbortController();
24677
+ const repairTimer = setTimeout(() => repairTimeout.abort(), REPAIR_TIMEOUT_MS);
24678
+ options.signal?.addEventListener("abort", () => repairTimeout.abort(), { once: true });
24679
+ try {
24680
+ const fixed = await repair.run(
24681
+ `The file you wrote to ${def.output.file} was REJECTED:
24682
+
24683
+ ${message}
24684
+
24685
+ Fix ONLY that, and rewrite the same file at the same path. Do not re-run any query and do not change any figure \u2014 the numbers were accepted, the shape was not.`,
24686
+ // Narration only; the caller is already showing progress.
24687
+ { onNarration: ctx.onNarration, onEvent: ctx.onEvent },
24688
+ repairTimeout.signal
24689
+ );
24690
+ record.usage.inputTokens += fixed.usage.inputTokens;
24691
+ record.usage.outputTokens += fixed.usage.outputTokens;
24692
+ record.usage.toolCalls += fixed.usage.toolCalls;
24693
+ } finally {
24694
+ clearTimeout(repairTimer);
24695
+ repair.dispose();
24696
+ }
24697
+ const reread = await ws.read(def.output.file);
24698
+ if (reread === null) {
24699
+ record.error = `deliverable failed validation: ${message} (and the repair turn wrote no file)`;
24700
+ return record;
24701
+ }
24702
+ rawText = reread;
24703
+ }
24658
24704
  }
24659
24705
  record.output = parsed;
24660
24706
  if (def.apply) {
package/dist/index.mjs CHANGED
@@ -24380,6 +24380,7 @@ async function installInstructions(def, ws) {
24380
24380
  logger.warn(`[CodingAgent:${def.id}] no system.md at ${src} \u2014 running without standing instructions`);
24381
24381
  }
24382
24382
  }
24383
+ var REPAIR_TIMEOUT_MS = 3 * 6e4;
24383
24384
  async function pruneRuns(agentDir, keep) {
24384
24385
  if (keep <= 0) return;
24385
24386
  try {
@@ -24544,11 +24545,56 @@ async function runCodingAgent(agentId, options = {}) {
24544
24545
  return record;
24545
24546
  }
24546
24547
  let parsed;
24547
- try {
24548
- parsed = def.output.schema.parse(JSON.parse(raw));
24549
- } catch (err) {
24550
- record.error = `deliverable failed validation: ${err?.message ?? err}`;
24551
- return record;
24548
+ let rawText = raw;
24549
+ let firstError;
24550
+ for (let attempt = 0; ; attempt++) {
24551
+ try {
24552
+ parsed = def.output.schema.parse(JSON.parse(rawText));
24553
+ break;
24554
+ } catch (err) {
24555
+ const message = err?.message ?? String(err);
24556
+ if (attempt > 0 || !result.sessionId) {
24557
+ record.error = firstError ? `deliverable failed validation after a repair attempt: ${message} (first: ${firstError})` : `deliverable failed validation: ${message}`;
24558
+ return record;
24559
+ }
24560
+ firstError = message;
24561
+ logger.warn(`[CodingAgent:${def.id}] deliverable rejected (${message}) \u2014 asking the agent to repair it`);
24562
+ const repair = createCodingAgentSession(def.harness || cfg.harness, {
24563
+ cwd: dir,
24564
+ model: def.model || cfg.model,
24565
+ resumeId: result.sessionId,
24566
+ mcpServers: tools && Object.keys(tools).length ? tools : void 0,
24567
+ ...def.networkAccessEnabled !== void 0 ? { networkAccessEnabled: def.networkAccessEnabled } : {},
24568
+ ...def.sandboxMode ? { sandboxMode: def.sandboxMode } : {}
24569
+ });
24570
+ const repairTimeout = new AbortController();
24571
+ const repairTimer = setTimeout(() => repairTimeout.abort(), REPAIR_TIMEOUT_MS);
24572
+ options.signal?.addEventListener("abort", () => repairTimeout.abort(), { once: true });
24573
+ try {
24574
+ const fixed = await repair.run(
24575
+ `The file you wrote to ${def.output.file} was REJECTED:
24576
+
24577
+ ${message}
24578
+
24579
+ Fix ONLY that, and rewrite the same file at the same path. Do not re-run any query and do not change any figure \u2014 the numbers were accepted, the shape was not.`,
24580
+ // Narration only; the caller is already showing progress.
24581
+ { onNarration: ctx.onNarration, onEvent: ctx.onEvent },
24582
+ repairTimeout.signal
24583
+ );
24584
+ record.usage.inputTokens += fixed.usage.inputTokens;
24585
+ record.usage.outputTokens += fixed.usage.outputTokens;
24586
+ record.usage.toolCalls += fixed.usage.toolCalls;
24587
+ } finally {
24588
+ clearTimeout(repairTimer);
24589
+ repair.dispose();
24590
+ }
24591
+ const reread = await ws.read(def.output.file);
24592
+ if (reread === null) {
24593
+ record.error = `deliverable failed validation: ${message} (and the repair turn wrote no file)`;
24594
+ return record;
24595
+ }
24596
+ rawText = reread;
24597
+ }
24552
24598
  }
24553
24599
  record.output = parsed;
24554
24600
  if (def.apply) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superatomai/sdk-node",
3
- "version": "0.0.59-dsp",
3
+ "version": "0.0.60-dsp",
4
4
  "description": "Node.js TypeScript SDK for Superatom",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",