offhands 0.1.3 → 0.1.4
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/daemon.mjs +58 -59
- package/package.json +1 -1
package/dist/daemon.mjs
CHANGED
|
@@ -5308,30 +5308,47 @@ function mapOpenCodeEvent(value) {
|
|
|
5308
5308
|
if (typeof value !== "object" || value === null) return [];
|
|
5309
5309
|
const v2 = value;
|
|
5310
5310
|
const type = typeof v2.type === "string" ? v2.type : "";
|
|
5311
|
-
const
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
const
|
|
5311
|
+
const part = v2.part ?? {};
|
|
5312
|
+
const partType = typeof part.type === "string" ? part.type : "";
|
|
5313
|
+
if (type === "text") {
|
|
5314
|
+
const text = typeof part.text === "string" ? part.text : "";
|
|
5315
|
+
return text ? [{ type: "text", chunk: text }] : [];
|
|
5316
|
+
}
|
|
5317
|
+
if (type === "thinking" || partType === "thinking") {
|
|
5318
|
+
const thinking = typeof part.thinking === "string" ? part.thinking : typeof part.text === "string" ? part.text : "";
|
|
5319
|
+
return thinking ? [{ type: "thinking", chunk: thinking }] : [];
|
|
5320
|
+
}
|
|
5321
|
+
if (type === "tool_call" || partType === "tool_call") {
|
|
5322
|
+
const name = firstString2(part, "toolName", "name", "tool") ?? "tool";
|
|
5323
|
+
const input = part.input;
|
|
5324
|
+
const summary = input ? firstString2(input, "command", "path", "file", "summary", "description", "query") ?? "" : "";
|
|
5323
5325
|
return [{ type: "tool", name, summary: summary ? `${name}: ${truncate3(summary, 120)}` : name }];
|
|
5324
5326
|
}
|
|
5325
|
-
if (type === "
|
|
5327
|
+
if (type === "step_start" || partType === "step-start") {
|
|
5326
5328
|
return [];
|
|
5327
5329
|
}
|
|
5328
|
-
if (type === "
|
|
5329
|
-
const
|
|
5330
|
-
const
|
|
5331
|
-
const
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5330
|
+
if (type === "step_finish" || partType === "step-finish") {
|
|
5331
|
+
const reason = typeof part.reason === "string" ? part.reason : "stop";
|
|
5332
|
+
const isError = reason === "error" || reason === "failed";
|
|
5333
|
+
const usage = extractUsageFromPart(part);
|
|
5334
|
+
if (isError) {
|
|
5335
|
+
const message = typeof part.error === "string" ? part.error : "run failed";
|
|
5336
|
+
const events2 = [{ type: "error", message }];
|
|
5337
|
+
if (usage) events2.push(usage);
|
|
5338
|
+
return events2;
|
|
5339
|
+
}
|
|
5340
|
+
const events = [{ type: "done", summary: "" }];
|
|
5341
|
+
if (usage) events.push(usage);
|
|
5342
|
+
return events;
|
|
5343
|
+
}
|
|
5344
|
+
if (type === "permission_request" || type === "permission.request") {
|
|
5345
|
+
const partData = part.data;
|
|
5346
|
+
const id = firstString2(partData, "id", "permissionId", "id") ?? crypto.randomUUID();
|
|
5347
|
+
const action = firstString2(partData, "toolName", "action", "command") ?? "action";
|
|
5348
|
+
const detail = firstString2(partData, "detail", "description", "message") ?? "";
|
|
5349
|
+
const risk = firstString2(partData, "risk") === "high" ? "high" : "low";
|
|
5350
|
+
const preview = firstString2(partData, "preview", "diff", "command") ?? void 0;
|
|
5351
|
+
const question = partData?.question ? mapQuestion(partData.question) : void 0;
|
|
5335
5352
|
return [{
|
|
5336
5353
|
type: "approval",
|
|
5337
5354
|
id,
|
|
@@ -5342,26 +5359,11 @@ function mapOpenCodeEvent(value) {
|
|
|
5342
5359
|
question
|
|
5343
5360
|
}];
|
|
5344
5361
|
}
|
|
5345
|
-
if (type === "
|
|
5346
|
-
const
|
|
5347
|
-
const text = firstString2(v2, "result", "text", "summary", "message") ?? "";
|
|
5348
|
-
if (isError) {
|
|
5349
|
-
return [{ type: "error", message: text || `run failed (${String(v2.subtype ?? v2.type ?? "unknown")})` }];
|
|
5350
|
-
}
|
|
5351
|
-
const events = [{ type: "done", summary: text }];
|
|
5352
|
-
const usage = extractUsage(v2, data);
|
|
5353
|
-
if (usage) events.push(usage);
|
|
5354
|
-
return events;
|
|
5355
|
-
}
|
|
5356
|
-
if (type === "error" || type === "failed") {
|
|
5357
|
-
const message = firstString2(v2, "message", "error", "detail", "result") ?? "unknown error";
|
|
5362
|
+
if (type === "error") {
|
|
5363
|
+
const message = firstString2(v2, "message", "error", "detail", "result") ?? firstString2(part, "message", "error") ?? "unknown error";
|
|
5358
5364
|
return [{ type: "error", message }];
|
|
5359
5365
|
}
|
|
5360
|
-
if (type === "
|
|
5361
|
-
const usage = extractUsage(v2, data);
|
|
5362
|
-
return usage ? [usage] : [];
|
|
5363
|
-
}
|
|
5364
|
-
if (type === "session.created" || type === "session.updated") {
|
|
5366
|
+
if (type === "session_created" || type === "session.updated" || type === "session.created") {
|
|
5365
5367
|
return [];
|
|
5366
5368
|
}
|
|
5367
5369
|
return [];
|
|
@@ -5369,8 +5371,22 @@ function mapOpenCodeEvent(value) {
|
|
|
5369
5371
|
function extractOpenCodeSessionId(value) {
|
|
5370
5372
|
if (typeof value !== "object" || value === null) return null;
|
|
5371
5373
|
const v2 = value;
|
|
5372
|
-
const
|
|
5373
|
-
return firstString2(v2, "sessionId", "session_id", "id") ?? firstString2(
|
|
5374
|
+
const part = v2.part ?? {};
|
|
5375
|
+
return firstString2(v2, "sessionId", "session_id", "sessionID", "id") ?? firstString2(part, "sessionId", "session_id", "sessionID", "id") ?? null;
|
|
5376
|
+
}
|
|
5377
|
+
function extractUsageFromPart(part) {
|
|
5378
|
+
const tokens = part.tokens;
|
|
5379
|
+
const costUsd = typeof part.cost === "number" ? part.cost : typeof part.costUsd === "number" ? part.costUsd : void 0;
|
|
5380
|
+
if (!tokens && costUsd === void 0) return null;
|
|
5381
|
+
const n2 = (k2) => typeof tokens?.[k2] === "number" ? tokens[k2] : 0;
|
|
5382
|
+
const contextTokens = n2("total") + n2("input") + n2("inputTokens") + n2("input_tokens") + n2("cacheReadInputTokens") + n2("cache_read_input_tokens") + n2("cacheCreationInputTokens") + n2("cache_creation_input_tokens") + n2("output") + n2("outputTokens") + n2("output_tokens") + n2("reasoning") + n2("reasoningTokens") + n2("reasoning_tokens");
|
|
5383
|
+
if (contextTokens <= 0 && costUsd === void 0) return null;
|
|
5384
|
+
return {
|
|
5385
|
+
type: "usage",
|
|
5386
|
+
contextTokens,
|
|
5387
|
+
contextWindow: 2e5,
|
|
5388
|
+
...costUsd !== void 0 ? { costUsd } : {}
|
|
5389
|
+
};
|
|
5374
5390
|
}
|
|
5375
5391
|
function mapQuestion(q2) {
|
|
5376
5392
|
if (typeof q2 !== "object" || q2 === null) return void 0;
|
|
@@ -5384,24 +5400,6 @@ function mapQuestion(q2) {
|
|
|
5384
5400
|
if (!text && options.length === 0) return void 0;
|
|
5385
5401
|
return { text, options, multiSelect };
|
|
5386
5402
|
}
|
|
5387
|
-
function extractUsage(v2, data) {
|
|
5388
|
-
const usage = v2.usage ?? data.usage;
|
|
5389
|
-
const costUsd = typeof v2.costUsd === "number" ? v2.costUsd : typeof data.costUsd === "number" ? data.costUsd : typeof v2.total_cost_usd === "number" ? v2.total_cost_usd : void 0;
|
|
5390
|
-
if (!usage && costUsd === void 0) return null;
|
|
5391
|
-
const n2 = (k2) => {
|
|
5392
|
-
const val = usage?.[k2] ?? data[k2];
|
|
5393
|
-
return typeof val === "number" ? val : 0;
|
|
5394
|
-
};
|
|
5395
|
-
const contextTokens = n2("inputTokens") + n2("input_tokens") + n2("cacheReadInputTokens") + n2("cache_read_input_tokens") + n2("cacheCreationInputTokens") + n2("cache_creation_input_tokens") + n2("outputTokens") + n2("output_tokens") + n2("reasoningTokens") + n2("reasoning_tokens");
|
|
5396
|
-
if (contextTokens <= 0 && costUsd === void 0) return null;
|
|
5397
|
-
return {
|
|
5398
|
-
type: "usage",
|
|
5399
|
-
contextTokens,
|
|
5400
|
-
contextWindow: 2e5,
|
|
5401
|
-
// OpenCode doesn't expose window; use reasonable default
|
|
5402
|
-
...costUsd !== void 0 ? { costUsd } : {}
|
|
5403
|
-
};
|
|
5404
|
-
}
|
|
5405
5403
|
function firstString2(obj, ...keys) {
|
|
5406
5404
|
for (const k2 of keys) {
|
|
5407
5405
|
const val = obj[k2];
|
|
@@ -5538,7 +5536,6 @@ var OpenCodeRunner = class {
|
|
|
5538
5536
|
const args2 = [
|
|
5539
5537
|
...cmd.slice(1),
|
|
5540
5538
|
"run",
|
|
5541
|
-
run.prompt,
|
|
5542
5539
|
"--format",
|
|
5543
5540
|
"json",
|
|
5544
5541
|
"--no-color"
|
|
@@ -5570,6 +5567,8 @@ var OpenCodeRunner = class {
|
|
|
5570
5567
|
}
|
|
5571
5568
|
}
|
|
5572
5569
|
args2.push("--dir", run.workspace);
|
|
5570
|
+
const promptArg = process.platform === "win32" ? `"${run.prompt.replace(/"/g, '\\"')}"` : run.prompt;
|
|
5571
|
+
args2.push(promptArg);
|
|
5573
5572
|
try {
|
|
5574
5573
|
child = spawn4(cmd[0], args2, {
|
|
5575
5574
|
cwd: run.workspace,
|