@sandagent/runner-cli 0.2.0 → 0.2.1-beta.0
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/bundle.mjs +20 -16
- package/package.json +1 -1
package/dist/bundle.mjs
CHANGED
|
@@ -145,6 +145,7 @@ var AISDKStreamConverter = class {
|
|
|
145
145
|
*/
|
|
146
146
|
async *stream(messageIterator, options) {
|
|
147
147
|
const debugMessages = [];
|
|
148
|
+
const debugDir = options?.cwd ?? process.cwd();
|
|
148
149
|
const debugFile = `ai-sdk-stream-debug-${Date.now()}.json`;
|
|
149
150
|
try {
|
|
150
151
|
for await (const message of messageIterator) {
|
|
@@ -225,7 +226,7 @@ var AISDKStreamConverter = class {
|
|
|
225
226
|
debugMessages.push(error);
|
|
226
227
|
} finally {
|
|
227
228
|
if (debugMessages.length > 0) {
|
|
228
|
-
writeFile(join(
|
|
229
|
+
writeFile(join(debugDir, debugFile), JSON.stringify(debugMessages, null, 2), "utf-8").catch((writeError) => {
|
|
229
230
|
console.error(`[AISDKStream] Failed to write debug file:`, writeError);
|
|
230
231
|
});
|
|
231
232
|
}
|
|
@@ -400,12 +401,17 @@ function setupAbortHandler(queryIterator, signal) {
|
|
|
400
401
|
} else {
|
|
401
402
|
console.error("[ClaudeRunner] No signal provided");
|
|
402
403
|
}
|
|
403
|
-
return
|
|
404
|
+
return () => {
|
|
405
|
+
if (signal) {
|
|
406
|
+
signal.removeEventListener("abort", abortHandler);
|
|
407
|
+
console.error("[ClaudeRunner] Abort listener removed");
|
|
408
|
+
}
|
|
409
|
+
};
|
|
404
410
|
}
|
|
405
411
|
async function* runWithTextOutput(sdk, options, userInput, signal) {
|
|
406
412
|
const sdkOptions = createSDKOptions(options);
|
|
407
413
|
const queryIterator = sdk.query({ prompt: userInput, options: sdkOptions });
|
|
408
|
-
const
|
|
414
|
+
const cleanup = setupAbortHandler(queryIterator, options.abortController?.signal);
|
|
409
415
|
try {
|
|
410
416
|
let resultText = "";
|
|
411
417
|
for await (const message of queryIterator) {
|
|
@@ -418,15 +424,13 @@ async function* runWithTextOutput(sdk, options, userInput, signal) {
|
|
|
418
424
|
}
|
|
419
425
|
yield resultText;
|
|
420
426
|
} finally {
|
|
421
|
-
|
|
422
|
-
signal.removeEventListener("abort", abortHandler);
|
|
423
|
-
}
|
|
427
|
+
cleanup();
|
|
424
428
|
}
|
|
425
429
|
}
|
|
426
430
|
async function* runWithJSONOutput(sdk, options, userInput, signal) {
|
|
427
431
|
const sdkOptions = createSDKOptions(options);
|
|
428
432
|
const queryIterator = sdk.query({ prompt: userInput, options: sdkOptions });
|
|
429
|
-
const
|
|
433
|
+
const cleanup = setupAbortHandler(queryIterator, signal);
|
|
430
434
|
try {
|
|
431
435
|
let resultMessage = null;
|
|
432
436
|
for await (const message of queryIterator) {
|
|
@@ -438,23 +442,19 @@ async function* runWithJSONOutput(sdk, options, userInput, signal) {
|
|
|
438
442
|
yield JSON.stringify(resultMessage) + "\n";
|
|
439
443
|
}
|
|
440
444
|
} finally {
|
|
441
|
-
|
|
442
|
-
signal.removeEventListener("abort", abortHandler);
|
|
443
|
-
}
|
|
445
|
+
cleanup();
|
|
444
446
|
}
|
|
445
447
|
}
|
|
446
448
|
async function* runWithStreamJSONOutput(sdk, options, userInput, signal) {
|
|
447
449
|
const sdkOptions = createSDKOptions(options);
|
|
448
450
|
const queryIterator = sdk.query({ prompt: userInput, options: sdkOptions });
|
|
449
|
-
const
|
|
451
|
+
const cleanup = setupAbortHandler(queryIterator, signal);
|
|
450
452
|
try {
|
|
451
453
|
for await (const message of queryIterator) {
|
|
452
454
|
yield JSON.stringify(message) + "\n";
|
|
453
455
|
}
|
|
454
456
|
} finally {
|
|
455
|
-
|
|
456
|
-
signal.removeEventListener("abort", abortHandler);
|
|
457
|
-
}
|
|
457
|
+
cleanup();
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
460
|
async function* runWithAISDKUIOutput(sdk, options, userInput) {
|
|
@@ -463,8 +463,12 @@ async function* runWithAISDKUIOutput(sdk, options, userInput) {
|
|
|
463
463
|
includePartialMessages: true
|
|
464
464
|
});
|
|
465
465
|
const queryIterator = sdk.query({ prompt: userInput, options: sdkOptions });
|
|
466
|
-
setupAbortHandler(queryIterator, options.abortController?.signal);
|
|
467
|
-
|
|
466
|
+
const cleanup = setupAbortHandler(queryIterator, options.abortController?.signal);
|
|
467
|
+
try {
|
|
468
|
+
yield* streamSDKMessagesToAISDKUI(queryIterator, { cwd: options.cwd });
|
|
469
|
+
} finally {
|
|
470
|
+
cleanup();
|
|
471
|
+
}
|
|
468
472
|
}
|
|
469
473
|
async function* runMockAgent(options, userInput, signal) {
|
|
470
474
|
if (signal?.aborted) {
|
package/package.json
CHANGED