@sandagent/runner-cli 0.2.1 → 0.2.3
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 +14 -7
- package/package.json +1 -1
package/dist/bundle.mjs
CHANGED
|
@@ -20,6 +20,9 @@ function convertUsageToAISDK(usage) {
|
|
|
20
20
|
const outputTokens = usage.output_tokens ?? 0;
|
|
21
21
|
const cacheWrite = usage.cache_creation_input_tokens ?? 0;
|
|
22
22
|
const cacheRead = usage.cache_read_input_tokens ?? 0;
|
|
23
|
+
const usageAny = usage;
|
|
24
|
+
const textTokens = typeof usageAny.text_tokens === "number" ? usageAny.text_tokens : void 0;
|
|
25
|
+
const reasoningTokens = typeof usageAny.reasoning_tokens === "number" ? usageAny.reasoning_tokens : void 0;
|
|
23
26
|
return {
|
|
24
27
|
inputTokens: {
|
|
25
28
|
total: inputTokens + cacheWrite + cacheRead,
|
|
@@ -27,7 +30,11 @@ function convertUsageToAISDK(usage) {
|
|
|
27
30
|
cacheRead,
|
|
28
31
|
cacheWrite
|
|
29
32
|
},
|
|
30
|
-
outputTokens: {
|
|
33
|
+
outputTokens: {
|
|
34
|
+
total: outputTokens,
|
|
35
|
+
text: textTokens,
|
|
36
|
+
reasoning: reasoningTokens
|
|
37
|
+
},
|
|
31
38
|
raw: usage
|
|
32
39
|
};
|
|
33
40
|
}
|
|
@@ -145,8 +152,6 @@ var AISDKStreamConverter = class {
|
|
|
145
152
|
*/
|
|
146
153
|
async *stream(messageIterator, options) {
|
|
147
154
|
const debugMessages = [];
|
|
148
|
-
const debugDir = options?.cwd ?? process.cwd();
|
|
149
|
-
const debugFile = `ai-sdk-stream-debug-${Date.now()}.json`;
|
|
150
155
|
try {
|
|
151
156
|
for await (const message of messageIterator) {
|
|
152
157
|
debugMessages.push(message);
|
|
@@ -214,7 +219,8 @@ var AISDKStreamConverter = class {
|
|
|
214
219
|
type: "finish",
|
|
215
220
|
finishReason: mapFinishReason(resultMsg.subtype, resultMsg.is_error),
|
|
216
221
|
messageMetadata: {
|
|
217
|
-
usage: convertUsageToAISDK(resultMsg.usage ?? {})
|
|
222
|
+
usage: convertUsageToAISDK(resultMsg.usage ?? {}),
|
|
223
|
+
sessionId: this.sessionId
|
|
218
224
|
}
|
|
219
225
|
});
|
|
220
226
|
console.error(`[AISDKStream] Emitting finish event at ${(/* @__PURE__ */ new Date()).toISOString()}`);
|
|
@@ -225,12 +231,13 @@ var AISDKStreamConverter = class {
|
|
|
225
231
|
} catch (error) {
|
|
226
232
|
debugMessages.push(error);
|
|
227
233
|
} finally {
|
|
228
|
-
if (debugMessages.length > 0) {
|
|
229
|
-
|
|
234
|
+
if (debugMessages.length > 0 && process.env.DEBUG === "true") {
|
|
235
|
+
const debugDir = options?.cwd ?? process.cwd();
|
|
236
|
+
const debugFile = join(debugDir, `claude-message-stream-debug.json`);
|
|
237
|
+
writeFile(debugFile, JSON.stringify(debugMessages, null, 2), "utf-8").catch((writeError) => {
|
|
230
238
|
console.error(`[AISDKStream] Failed to write debug file:`, writeError);
|
|
231
239
|
});
|
|
232
240
|
}
|
|
233
|
-
options?.onCleanup?.();
|
|
234
241
|
yield `data: [DONE]
|
|
235
242
|
|
|
236
243
|
`;
|
package/package.json
CHANGED