@sweny-ai/core 0.1.109 → 0.1.111

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 (2) hide show
  1. package/dist/claude.js +28 -2
  2. package/package.json +2 -2
package/dist/claude.js CHANGED
@@ -202,6 +202,11 @@ export class ClaudeClient {
202
202
  .join("\n\n");
203
203
  const env = this.buildEnv();
204
204
  let response = "";
205
+ // CC-08: when the SDK populates typed structured output (because we passed
206
+ // an `outputFormat`), prefer it over re-parsing JSON out of the free-text
207
+ // result. Left undefined when the SDK didn't provide it, so the
208
+ // tryParseJSON heuristic remains the fallback (e.g. mocks, older results).
209
+ let structuredOutput;
205
210
  // Timeout / abort wiring (back-compat: only armed when requested).
206
211
  // A single AbortController drives both an optional caller signal and an
207
212
  // optional timeout timer. The SDK aborts the subprocess when this fires.
@@ -225,6 +230,11 @@ export class ClaudeClient {
225
230
  ...(effectiveModel ? { model: effectiveModel } : {}),
226
231
  ...(Object.keys(allMcpServers).length > 0 ? { mcpServers: allMcpServers } : {}),
227
232
  ...(disallowedTools && disallowedTools.length > 0 ? { disallowedTools } : {}),
233
+ // CC-08: ask the SDK to produce validated structured output when the
234
+ // node declares an output schema. The SDK then returns the parsed
235
+ // value on `result.structured_output`, which we prefer over the
236
+ // text-scan heuristic below.
237
+ ...(outputSchema ? { outputFormat: { type: "json_schema", schema: outputSchema } } : {}),
228
238
  },
229
239
  });
230
240
  for await (const message of stream) {
@@ -315,12 +325,22 @@ export class ClaudeClient {
315
325
  };
316
326
  }
317
327
  response = resultMsg.result;
328
+ // CC-08: capture the SDK's typed structured output when present.
329
+ if ("structured_output" in resultMsg && resultMsg.structured_output !== undefined) {
330
+ structuredOutput = resultMsg.structured_output;
331
+ }
318
332
  }
319
333
  else if ("errors" in resultMsg) {
320
334
  const errors = resultMsg.errors;
335
+ // CC-08: surface the structured-output failure subtype explicitly
336
+ // so a schema the model can't satisfy fails loudly instead of
337
+ // silently producing empty data.
338
+ const prefix = resultMsg.subtype === "error_max_structured_output_retries"
339
+ ? "Claude could not produce output matching the schema: "
340
+ : "";
321
341
  return {
322
342
  status: "failed",
323
- data: { error: errors?.join("\n") ?? "Execution failed" },
343
+ data: { error: prefix + (errors?.join("\n") ?? "Execution failed") },
324
344
  toolCalls,
325
345
  };
326
346
  }
@@ -347,9 +367,15 @@ export class ClaudeClient {
347
367
  abort?.clear();
348
368
  await interruptStream(stream);
349
369
  }
370
+ // CC-08: prefer the SDK's validated structured output when it gave us an
371
+ // object. Fall back to the free-text JSON heuristic when it's absent
372
+ // (no schema requested, mocked result, or an older SDK that didn't set it).
373
+ const parsedData = structuredOutput && typeof structuredOutput === "object" && !Array.isArray(structuredOutput)
374
+ ? structuredOutput
375
+ : tryParseJSON(response, outputSchema, this.logger);
350
376
  return {
351
377
  status: "success",
352
- data: { summary: response, ...tryParseJSON(response, outputSchema, this.logger) },
378
+ data: { summary: response, ...parsedData },
353
379
  toolCalls,
354
380
  };
355
381
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sweny-ai/core",
3
- "version": "0.1.109",
3
+ "version": "0.1.111",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "sweny": "./dist/cli/main.js"
@@ -61,7 +61,7 @@
61
61
  "@clack/prompts": "^1.2.0",
62
62
  "chalk": "^5",
63
63
  "commander": "^13",
64
- "yaml": "^2",
64
+ "yaml": "^2.9.0",
65
65
  "zod": "^3.25.76"
66
66
  },
67
67
  "devDependencies": {