agentbox-sdk 0.1.310 → 0.1.312
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/agents/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
createNormalizedEvent,
|
|
3
3
|
normalizeRawAgentEvent,
|
|
4
4
|
toAISDKStream
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-A52XCBGW.js";
|
|
6
6
|
import {
|
|
7
7
|
AgentBoxError,
|
|
8
8
|
AsyncQueue,
|
|
@@ -1670,6 +1670,7 @@ function buildClaudeQueryOptions(params) {
|
|
|
1670
1670
|
settings: params.settingsPath,
|
|
1671
1671
|
extraArgs,
|
|
1672
1672
|
includePartialMessages: true,
|
|
1673
|
+
forwardSubagentText: true,
|
|
1673
1674
|
includeHookEvents,
|
|
1674
1675
|
thinking: { type: "adaptive", display: "summarized" },
|
|
1675
1676
|
...provider?.additionalDirectories?.length ? { additionalDirectories: provider.additionalDirectories } : {},
|
|
@@ -299,6 +299,21 @@ var OpenCodeLogAssembler = class {
|
|
|
299
299
|
userMessageIds = /* @__PURE__ */ new Set();
|
|
300
300
|
textByPartId = /* @__PURE__ */ new Map();
|
|
301
301
|
byPartId = /* @__PURE__ */ new Map();
|
|
302
|
+
// Sub-agent (`task` tool) linkage. opencode multiplexes the parent task
|
|
303
|
+
// tool's `state.metadata.sessionId` update and the child session's first
|
|
304
|
+
// stream events onto the same SSE bus with no ordering guarantee, so
|
|
305
|
+
// child events frequently arrive before the parent has published its
|
|
306
|
+
// child sessionID. We bind FIFO instead: every task tool we see goes
|
|
307
|
+
// onto a queue; the first non-main sessionID that lacks an explicit
|
|
308
|
+
// binding gets paired with the queue head. Once a binding is established
|
|
309
|
+
// we stamp every emitted snapshot for that child session with
|
|
310
|
+
// `parentTaskCallId` on the part so consumers don't have to re-derive
|
|
311
|
+
// the linkage from snapshots.
|
|
312
|
+
mainSessionID = null;
|
|
313
|
+
pendingTaskCallIds = [];
|
|
314
|
+
childSessionToTaskCallId = /* @__PURE__ */ new Map();
|
|
315
|
+
childMessageIdToTaskCallId = /* @__PURE__ */ new Map();
|
|
316
|
+
messageIdToSessionId = /* @__PURE__ */ new Map();
|
|
302
317
|
process(event) {
|
|
303
318
|
if (!isRecord(event)) {
|
|
304
319
|
return [];
|
|
@@ -306,10 +321,48 @@ var OpenCodeLogAssembler = class {
|
|
|
306
321
|
const type = typeof event.type === "string" ? event.type : "";
|
|
307
322
|
const properties = isRecord(event.properties) ? event.properties : {};
|
|
308
323
|
const info = isRecord(properties.info) ? properties.info : null;
|
|
324
|
+
const eventPart = isRecord(properties.part) ? properties.part : isRecord(event.part) ? event.part : null;
|
|
325
|
+
if (this.mainSessionID === null) {
|
|
326
|
+
const candidate = (typeof info?.sessionID === "string" ? info.sessionID : null) ?? (eventPart && typeof eventPart.sessionID === "string" ? eventPart.sessionID : null) ?? (typeof properties.sessionID === "string" ? properties.sessionID : null);
|
|
327
|
+
if (candidate) this.mainSessionID = candidate;
|
|
328
|
+
}
|
|
329
|
+
if (info && typeof info.id === "string" && typeof info.sessionID === "string") {
|
|
330
|
+
this.messageIdToSessionId.set(info.id, info.sessionID);
|
|
331
|
+
}
|
|
332
|
+
if (eventPart && typeof eventPart.id === "string" && typeof eventPart.messageID === "string" && typeof eventPart.sessionID === "string") {
|
|
333
|
+
this.messageIdToSessionId.set(eventPart.messageID, eventPart.sessionID);
|
|
334
|
+
}
|
|
335
|
+
if (eventPart && this.isTaskToolPart(eventPart)) {
|
|
336
|
+
const callId = typeof eventPart.callID === "string" ? eventPart.callID : typeof eventPart.id === "string" ? eventPart.id : null;
|
|
337
|
+
if (callId) {
|
|
338
|
+
const metaSid = this.extractTaskMetadataSessionId(eventPart);
|
|
339
|
+
if (metaSid && !this.childSessionToTaskCallId.has(metaSid)) {
|
|
340
|
+
this.childSessionToTaskCallId.set(metaSid, callId);
|
|
341
|
+
this.pendingTaskCallIds = this.pendingTaskCallIds.filter(
|
|
342
|
+
(id) => id !== callId
|
|
343
|
+
);
|
|
344
|
+
} else if (!metaSid) {
|
|
345
|
+
const alreadyBound = this.taskCallIdAlreadyBound(callId);
|
|
346
|
+
if (!alreadyBound && !this.pendingTaskCallIds.includes(callId)) {
|
|
347
|
+
this.pendingTaskCallIds.push(callId);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const effectiveSid = this.extractSessionID(properties, eventPart, info);
|
|
353
|
+
if (effectiveSid && effectiveSid !== this.mainSessionID && !this.childSessionToTaskCallId.has(effectiveSid) && this.pendingTaskCallIds.length > 0) {
|
|
354
|
+
const taskCallId = this.pendingTaskCallIds.shift();
|
|
355
|
+
this.childSessionToTaskCallId.set(effectiveSid, taskCallId);
|
|
356
|
+
}
|
|
309
357
|
if (type === "message.updated" && typeof info?.id === "string" && info.role === "user") {
|
|
310
358
|
this.userMessageIds.add(info.id);
|
|
311
359
|
return [clone(event)];
|
|
312
360
|
}
|
|
361
|
+
const parentTaskCallId = this.resolveParentTaskCallId(
|
|
362
|
+
effectiveSid,
|
|
363
|
+
eventPart,
|
|
364
|
+
info
|
|
365
|
+
);
|
|
313
366
|
if (type === "message.part.delta") {
|
|
314
367
|
const partId = typeof properties.partID === "string" ? properties.partID : null;
|
|
315
368
|
const messageId = typeof properties.messageID === "string" ? properties.messageID : null;
|
|
@@ -317,32 +370,50 @@ var OpenCodeLogAssembler = class {
|
|
|
317
370
|
if (!partId || !delta || properties.field !== "text" || messageId && this.userMessageIds.has(messageId)) {
|
|
318
371
|
return [];
|
|
319
372
|
}
|
|
373
|
+
if (messageId && effectiveSid) {
|
|
374
|
+
this.messageIdToSessionId.set(messageId, effectiveSid);
|
|
375
|
+
}
|
|
320
376
|
const text = (this.textByPartId.get(partId) ?? "") + delta;
|
|
321
377
|
this.textByPartId.set(partId, text);
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
378
|
+
const part = {
|
|
379
|
+
id: partId,
|
|
380
|
+
messageID: messageId ?? void 0,
|
|
381
|
+
type: "text",
|
|
382
|
+
text
|
|
383
|
+
};
|
|
384
|
+
if (parentTaskCallId) {
|
|
385
|
+
part.parentTaskCallId = parentTaskCallId;
|
|
386
|
+
if (messageId) {
|
|
387
|
+
this.childMessageIdToTaskCallId.set(messageId, parentTaskCallId);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return [this.upsertPart(partId, part)];
|
|
330
391
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
if (part.messageID && this.userMessageIds.has(String(part.messageID))) {
|
|
392
|
+
if (eventPart && typeof eventPart.id === "string") {
|
|
393
|
+
if (eventPart.messageID && this.userMessageIds.has(String(eventPart.messageID))) {
|
|
334
394
|
return [];
|
|
335
395
|
}
|
|
336
|
-
const previous = this.byPartId.get(
|
|
337
|
-
if (
|
|
396
|
+
const previous = this.byPartId.get(eventPart.id);
|
|
397
|
+
if (eventPart.type === "text" && previous && isRecord(previous.properties?.part)) {
|
|
338
398
|
const previousPart = previous.properties.part;
|
|
339
399
|
const previousText = typeof previousPart.text === "string" ? previousPart.text : "";
|
|
340
|
-
const nextText = typeof
|
|
400
|
+
const nextText = typeof eventPart.text === "string" ? eventPart.text : "";
|
|
341
401
|
if (nextText.length < previousText.length) {
|
|
342
402
|
return [clone(previous)];
|
|
343
403
|
}
|
|
344
404
|
}
|
|
345
|
-
|
|
405
|
+
const enriched = clone(event);
|
|
406
|
+
if (parentTaskCallId) {
|
|
407
|
+
this.stampParentTaskCallId(enriched, parentTaskCallId);
|
|
408
|
+
if (typeof eventPart.messageID === "string") {
|
|
409
|
+
this.childMessageIdToTaskCallId.set(
|
|
410
|
+
eventPart.messageID,
|
|
411
|
+
parentTaskCallId
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
this.byPartId.set(eventPart.id, enriched);
|
|
416
|
+
return [clone(enriched)];
|
|
346
417
|
}
|
|
347
418
|
return [clone(event)];
|
|
348
419
|
}
|
|
@@ -350,11 +421,23 @@ var OpenCodeLogAssembler = class {
|
|
|
350
421
|
this.userMessageIds.clear();
|
|
351
422
|
this.textByPartId.clear();
|
|
352
423
|
this.byPartId.clear();
|
|
424
|
+
this.mainSessionID = null;
|
|
425
|
+
this.pendingTaskCallIds = [];
|
|
426
|
+
this.childSessionToTaskCallId.clear();
|
|
427
|
+
this.childMessageIdToTaskCallId.clear();
|
|
428
|
+
this.messageIdToSessionId.clear();
|
|
353
429
|
for (const snapshot of snapshots) {
|
|
354
430
|
if (!isRecord(snapshot)) continue;
|
|
355
431
|
const type = typeof snapshot.type === "string" ? snapshot.type : "";
|
|
356
432
|
const properties = isRecord(snapshot.properties) ? snapshot.properties : {};
|
|
357
433
|
const info = isRecord(properties.info) ? properties.info : null;
|
|
434
|
+
if (this.mainSessionID === null) {
|
|
435
|
+
const candidate = (typeof info?.sessionID === "string" ? info.sessionID : null) ?? (typeof properties.sessionID === "string" ? properties.sessionID : null);
|
|
436
|
+
if (candidate) this.mainSessionID = candidate;
|
|
437
|
+
}
|
|
438
|
+
if (info && typeof info.id === "string" && typeof info.sessionID === "string") {
|
|
439
|
+
this.messageIdToSessionId.set(info.id, info.sessionID);
|
|
440
|
+
}
|
|
358
441
|
if (type === "message.updated" && typeof info?.id === "string" && info.role === "user") {
|
|
359
442
|
this.userMessageIds.add(info.id);
|
|
360
443
|
continue;
|
|
@@ -365,9 +448,88 @@ var OpenCodeLogAssembler = class {
|
|
|
365
448
|
if (typeof part.text === "string") {
|
|
366
449
|
this.textByPartId.set(part.id, part.text);
|
|
367
450
|
}
|
|
451
|
+
if (typeof part.messageID === "string" && typeof part.sessionID === "string") {
|
|
452
|
+
this.messageIdToSessionId.set(part.messageID, part.sessionID);
|
|
453
|
+
}
|
|
454
|
+
if (typeof part.parentTaskCallId === "string") {
|
|
455
|
+
if (typeof part.sessionID === "string" && !this.childSessionToTaskCallId.has(part.sessionID)) {
|
|
456
|
+
this.childSessionToTaskCallId.set(
|
|
457
|
+
part.sessionID,
|
|
458
|
+
part.parentTaskCallId
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
if (typeof part.messageID === "string") {
|
|
462
|
+
this.childMessageIdToTaskCallId.set(
|
|
463
|
+
part.messageID,
|
|
464
|
+
part.parentTaskCallId
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (this.isTaskToolPart(part)) {
|
|
469
|
+
const callId = typeof part.callID === "string" ? part.callID : typeof part.id === "string" ? part.id : null;
|
|
470
|
+
const metaSid = this.extractTaskMetadataSessionId(part);
|
|
471
|
+
if (callId && metaSid && !this.childSessionToTaskCallId.has(metaSid)) {
|
|
472
|
+
this.childSessionToTaskCallId.set(metaSid, callId);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
368
475
|
}
|
|
369
476
|
}
|
|
370
477
|
}
|
|
478
|
+
isTaskToolPart(part) {
|
|
479
|
+
if (part.type !== "tool") return false;
|
|
480
|
+
const tool = typeof part.tool === "string" ? part.tool.toLowerCase() : "";
|
|
481
|
+
return tool === "task";
|
|
482
|
+
}
|
|
483
|
+
taskCallIdAlreadyBound(callId) {
|
|
484
|
+
for (const v of this.childSessionToTaskCallId.values()) {
|
|
485
|
+
if (v === callId) return true;
|
|
486
|
+
}
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
extractTaskMetadataSessionId(part) {
|
|
490
|
+
const state = isRecord(part.state) ? part.state : null;
|
|
491
|
+
const metadata = state && isRecord(state.metadata) ? state.metadata : null;
|
|
492
|
+
if (!metadata) return null;
|
|
493
|
+
if (typeof metadata.sessionId === "string") return metadata.sessionId;
|
|
494
|
+
if (typeof metadata.sessionID === "string") return metadata.sessionID;
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
extractSessionID(properties, part, info) {
|
|
498
|
+
if (typeof properties.sessionID === "string") return properties.sessionID;
|
|
499
|
+
if (part && typeof part.sessionID === "string") return part.sessionID;
|
|
500
|
+
if (info && typeof info.sessionID === "string") return info.sessionID;
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
resolveParentTaskCallId(sessionID, part, info) {
|
|
504
|
+
if (sessionID && this.childSessionToTaskCallId.has(sessionID)) {
|
|
505
|
+
return this.childSessionToTaskCallId.get(sessionID) ?? null;
|
|
506
|
+
}
|
|
507
|
+
const candidateMessageIds = [];
|
|
508
|
+
if (part && typeof part.messageID === "string") {
|
|
509
|
+
candidateMessageIds.push(part.messageID);
|
|
510
|
+
}
|
|
511
|
+
if (info && typeof info.id === "string") {
|
|
512
|
+
candidateMessageIds.push(info.id);
|
|
513
|
+
}
|
|
514
|
+
for (const messageId of candidateMessageIds) {
|
|
515
|
+
const cached = this.childMessageIdToTaskCallId.get(messageId);
|
|
516
|
+
if (cached) return cached;
|
|
517
|
+
const mappedSid = this.messageIdToSessionId.get(messageId);
|
|
518
|
+
if (mappedSid && this.childSessionToTaskCallId.has(mappedSid)) {
|
|
519
|
+
const tcid = this.childSessionToTaskCallId.get(mappedSid);
|
|
520
|
+
this.childMessageIdToTaskCallId.set(messageId, tcid);
|
|
521
|
+
return tcid;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
stampParentTaskCallId(snapshot, parentTaskCallId) {
|
|
527
|
+
const properties = isRecord(snapshot.properties) ? snapshot.properties : null;
|
|
528
|
+
const part = properties && isRecord(properties.part) ? properties.part : isRecord(snapshot.part) ? snapshot.part : null;
|
|
529
|
+
if (part) {
|
|
530
|
+
part.parentTaskCallId = parentTaskCallId;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
371
533
|
upsertPart(partId, part) {
|
|
372
534
|
const next = {
|
|
373
535
|
type: "message.part.updated",
|
|
@@ -387,6 +549,7 @@ var ClaudeCodeLogAssembler = class {
|
|
|
387
549
|
currentMessageId = null;
|
|
388
550
|
textByMessageId = /* @__PURE__ */ new Map();
|
|
389
551
|
thinkingByMessageId = /* @__PURE__ */ new Map();
|
|
552
|
+
parentToolUseIdByMessageId = /* @__PURE__ */ new Map();
|
|
390
553
|
byMessageId = /* @__PURE__ */ new Map();
|
|
391
554
|
// Per-message tool_use / image / other non-text-non-thinking content blocks.
|
|
392
555
|
// Tracked persistently so any `upsertMessage` call (including those from a
|
|
@@ -407,6 +570,7 @@ var ClaudeCodeLogAssembler = class {
|
|
|
407
570
|
const id = message && typeof message.id === "string" ? message.id : null;
|
|
408
571
|
if (!id) return [];
|
|
409
572
|
this.currentMessageId = id;
|
|
573
|
+
this.setParentToolUseId(id, event);
|
|
410
574
|
if (!this.textByMessageId.has(id)) this.textByMessageId.set(id, "");
|
|
411
575
|
if (!this.thinkingByMessageId.has(id))
|
|
412
576
|
this.thinkingByMessageId.set(id, "");
|
|
@@ -437,6 +601,7 @@ var ClaudeCodeLogAssembler = class {
|
|
|
437
601
|
if (!id || !message) {
|
|
438
602
|
return [clone(event)];
|
|
439
603
|
}
|
|
604
|
+
this.setParentToolUseId(id, event);
|
|
440
605
|
const final = extractClaudeAssistantContent(message);
|
|
441
606
|
this.textByMessageId.set(id, final.text);
|
|
442
607
|
if (final.thinking) {
|
|
@@ -453,6 +618,7 @@ var ClaudeCodeLogAssembler = class {
|
|
|
453
618
|
this.currentMessageId = null;
|
|
454
619
|
this.textByMessageId.clear();
|
|
455
620
|
this.thinkingByMessageId.clear();
|
|
621
|
+
this.parentToolUseIdByMessageId.clear();
|
|
456
622
|
this.byMessageId.clear();
|
|
457
623
|
this.extraBlocksByMessageId.clear();
|
|
458
624
|
for (const snapshot of snapshots) {
|
|
@@ -461,6 +627,8 @@ var ClaudeCodeLogAssembler = class {
|
|
|
461
627
|
const messageId = typeof snapshot.messageId === "string" ? snapshot.messageId : null;
|
|
462
628
|
if (!messageId) continue;
|
|
463
629
|
this.byMessageId.set(messageId, clone(snapshot));
|
|
630
|
+
const parentToolUseId = typeof snapshot.parent_tool_use_id === "string" ? snapshot.parent_tool_use_id : null;
|
|
631
|
+
this.parentToolUseIdByMessageId.set(messageId, parentToolUseId);
|
|
464
632
|
const message = isRecord(snapshot.message) ? snapshot.message : null;
|
|
465
633
|
const content = message && Array.isArray(message.content) ? message.content : [];
|
|
466
634
|
let text = "";
|
|
@@ -495,6 +663,15 @@ var ClaudeCodeLogAssembler = class {
|
|
|
495
663
|
map.set(key, clone(block));
|
|
496
664
|
}
|
|
497
665
|
}
|
|
666
|
+
setParentToolUseId(messageId, event) {
|
|
667
|
+
if (event.parent_tool_use_id === null) {
|
|
668
|
+
this.parentToolUseIdByMessageId.set(messageId, null);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
if (typeof event.parent_tool_use_id === "string") {
|
|
672
|
+
this.parentToolUseIdByMessageId.set(messageId, event.parent_tool_use_id);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
498
675
|
upsertMessage(messageId) {
|
|
499
676
|
const text = this.textByMessageId.get(messageId) ?? "";
|
|
500
677
|
const thinking = this.thinkingByMessageId.get(messageId) ?? "";
|
|
@@ -508,6 +685,7 @@ var ClaudeCodeLogAssembler = class {
|
|
|
508
685
|
const next = {
|
|
509
686
|
type: "message.updated",
|
|
510
687
|
messageId,
|
|
688
|
+
parent_tool_use_id: this.parentToolUseIdByMessageId.get(messageId) ?? null,
|
|
511
689
|
message: {
|
|
512
690
|
id: messageId,
|
|
513
691
|
role: "assistant",
|
package/dist/events/index.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
Agent,
|
|
3
3
|
agentboxRoot,
|
|
4
4
|
getAgentLayout
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-3M5SPIRD.js";
|
|
6
6
|
import {
|
|
7
7
|
ProviderLogAssembler,
|
|
8
8
|
createNormalizedEvent,
|
|
9
9
|
normalizeRawAgentEvent,
|
|
10
10
|
toAISDKEvent,
|
|
11
11
|
toAISDKStream
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-A52XCBGW.js";
|
|
13
13
|
import {
|
|
14
14
|
Sandbox,
|
|
15
15
|
SandboxAdapter,
|