@autohq/cli 0.1.326 → 0.1.328
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/agent-bridge.js +143 -4
- package/dist/index.js +149 -6
- package/package.json +1 -1
package/dist/agent-bridge.js
CHANGED
|
@@ -23434,7 +23434,7 @@ Object.assign(lookup, {
|
|
|
23434
23434
|
// package.json
|
|
23435
23435
|
var package_default = {
|
|
23436
23436
|
name: "@autohq/cli",
|
|
23437
|
-
version: "0.1.
|
|
23437
|
+
version: "0.1.328",
|
|
23438
23438
|
license: "SEE LICENSE IN README.md",
|
|
23439
23439
|
publishConfig: {
|
|
23440
23440
|
access: "public"
|
|
@@ -42432,6 +42432,7 @@ function providerMetadataField(providerMetadata) {
|
|
|
42432
42432
|
|
|
42433
42433
|
// src/commands/agent-bridge/harness/output-buffer.ts
|
|
42434
42434
|
var AGENT_BRIDGE_OUTPUT_DELTA_FLUSH_MS = 50;
|
|
42435
|
+
var AGENT_BRIDGE_OUTPUT_UI_DELTA_MAX_CHARS = 32768;
|
|
42435
42436
|
var AGENT_BRIDGE_OUTPUT_ACK_RETRY_BACKOFF_MS = [250, 1e3];
|
|
42436
42437
|
var AgentBridgeOutputBuffer = class {
|
|
42437
42438
|
constructor(input) {
|
|
@@ -42443,6 +42444,8 @@ var AgentBridgeOutputBuffer = class {
|
|
|
42443
42444
|
pendingOutputs = /* @__PURE__ */ new Map();
|
|
42444
42445
|
pendingDelta = null;
|
|
42445
42446
|
deltaFlushTimer = null;
|
|
42447
|
+
pendingUiDelta = null;
|
|
42448
|
+
uiDeltaFlushTimer = null;
|
|
42446
42449
|
activeUiMessageAssembler = null;
|
|
42447
42450
|
uiMessagePartTracker = new UiMessagePartTracker();
|
|
42448
42451
|
drainBlocked = false;
|
|
@@ -42452,6 +42455,12 @@ var AgentBridgeOutputBuffer = class {
|
|
|
42452
42455
|
// ---------------------------------------------------------------------------
|
|
42453
42456
|
async emitProjection(context, projection) {
|
|
42454
42457
|
if (projection.type === "ui_message_chunk") {
|
|
42458
|
+
const coalescible = coalescibleUiDeltaChunk(projection);
|
|
42459
|
+
if (coalescible) {
|
|
42460
|
+
await this.bufferUiDeltaChunk(context, coalescible);
|
|
42461
|
+
return;
|
|
42462
|
+
}
|
|
42463
|
+
await this.flushPendingUiDelta();
|
|
42455
42464
|
await this.emitUiMessageChunk(context, projection);
|
|
42456
42465
|
return;
|
|
42457
42466
|
}
|
|
@@ -42459,10 +42468,12 @@ var AgentBridgeOutputBuffer = class {
|
|
|
42459
42468
|
await this.bufferDelta(context, projection.delta);
|
|
42460
42469
|
return;
|
|
42461
42470
|
}
|
|
42471
|
+
await this.flushPendingUiDelta();
|
|
42462
42472
|
await this.flushPendingDelta();
|
|
42463
42473
|
await this.enqueueProjectionAndDrain(context, projection);
|
|
42464
42474
|
}
|
|
42465
42475
|
async replayPendingOutputs() {
|
|
42476
|
+
await this.materializePendingUiDelta();
|
|
42466
42477
|
await this.flushPendingDelta({ force: true });
|
|
42467
42478
|
await this.drainPendingOutputs({ force: true });
|
|
42468
42479
|
}
|
|
@@ -42586,10 +42597,15 @@ var AgentBridgeOutputBuffer = class {
|
|
|
42586
42597
|
this.drainPromise ??= (async () => {
|
|
42587
42598
|
while (true) {
|
|
42588
42599
|
const output = this.nextPendingOutput();
|
|
42589
|
-
if (
|
|
42590
|
-
|
|
42600
|
+
if (output) {
|
|
42601
|
+
await this.emitUntilAcked(output);
|
|
42602
|
+
continue;
|
|
42591
42603
|
}
|
|
42592
|
-
|
|
42604
|
+
if (this.pendingUiDelta) {
|
|
42605
|
+
await this.materializePendingUiDelta();
|
|
42606
|
+
continue;
|
|
42607
|
+
}
|
|
42608
|
+
return;
|
|
42593
42609
|
}
|
|
42594
42610
|
})().catch((error51) => {
|
|
42595
42611
|
this.drainBlocked = true;
|
|
@@ -42600,6 +42616,85 @@ var AgentBridgeOutputBuffer = class {
|
|
|
42600
42616
|
await this.drainPromise;
|
|
42601
42617
|
}
|
|
42602
42618
|
// ---------------------------------------------------------------------------
|
|
42619
|
+
// UI chunk delta coalescing
|
|
42620
|
+
// ---------------------------------------------------------------------------
|
|
42621
|
+
async bufferUiDeltaChunk(context, chunk) {
|
|
42622
|
+
const pending = this.pendingUiDelta;
|
|
42623
|
+
if (pending && canCoalesceUiDelta(pending, context, chunk)) {
|
|
42624
|
+
pending.chunk = mergeUiDeltaChunks(pending.chunk, chunk);
|
|
42625
|
+
if (uiDeltaTextLength(pending.chunk) >= AGENT_BRIDGE_OUTPUT_UI_DELTA_MAX_CHARS) {
|
|
42626
|
+
await this.flushPendingUiDelta();
|
|
42627
|
+
}
|
|
42628
|
+
return;
|
|
42629
|
+
}
|
|
42630
|
+
await this.flushPendingUiDelta();
|
|
42631
|
+
this.pendingUiDelta = { context, chunk: { ...chunk }, createdAt: now2() };
|
|
42632
|
+
this.scheduleUiDeltaFlush();
|
|
42633
|
+
}
|
|
42634
|
+
scheduleUiDeltaFlush() {
|
|
42635
|
+
if (this.uiDeltaFlushTimer !== null) {
|
|
42636
|
+
return;
|
|
42637
|
+
}
|
|
42638
|
+
this.uiDeltaFlushTimer = setTimeout(() => {
|
|
42639
|
+
this.uiDeltaFlushTimer = null;
|
|
42640
|
+
if (!this.pendingUiDelta) {
|
|
42641
|
+
return;
|
|
42642
|
+
}
|
|
42643
|
+
if (this.drainPromise) {
|
|
42644
|
+
this.scheduleUiDeltaFlush();
|
|
42645
|
+
return;
|
|
42646
|
+
}
|
|
42647
|
+
void this.flushPendingUiDelta().catch((error51) => {
|
|
42648
|
+
this.drainBlocked = true;
|
|
42649
|
+
this.input.runtimeLogger?.warn(
|
|
42650
|
+
"agent_bridge_output_buffer_flush_failed",
|
|
42651
|
+
{
|
|
42652
|
+
error: error51 instanceof Error ? error51.message : String(error51),
|
|
42653
|
+
pending_count: this.pendingOutputs.size
|
|
42654
|
+
}
|
|
42655
|
+
);
|
|
42656
|
+
});
|
|
42657
|
+
}, AGENT_BRIDGE_OUTPUT_DELTA_FLUSH_MS);
|
|
42658
|
+
}
|
|
42659
|
+
clearUiDeltaFlushTimer() {
|
|
42660
|
+
if (this.uiDeltaFlushTimer === null) {
|
|
42661
|
+
return;
|
|
42662
|
+
}
|
|
42663
|
+
clearTimeout(this.uiDeltaFlushTimer);
|
|
42664
|
+
this.uiDeltaFlushTimer = null;
|
|
42665
|
+
}
|
|
42666
|
+
async flushPendingUiDelta() {
|
|
42667
|
+
if (!this.pendingUiDelta) {
|
|
42668
|
+
return;
|
|
42669
|
+
}
|
|
42670
|
+
await this.materializePendingUiDelta();
|
|
42671
|
+
await this.drainPendingOutputs();
|
|
42672
|
+
}
|
|
42673
|
+
// Turns the parked coalesced chunk into a queued envelope and applies it to
|
|
42674
|
+
// the part tracker and message assembler, exactly as its source chunks would
|
|
42675
|
+
// have applied one by one (delta chunks never settle a part or complete a
|
|
42676
|
+
// message, so tracker/assembler side effects reduce to text accumulation).
|
|
42677
|
+
// Does not drain: the drain loop calls this mid-loop and keeps pulling.
|
|
42678
|
+
async materializePendingUiDelta() {
|
|
42679
|
+
const pending = this.pendingUiDelta;
|
|
42680
|
+
if (!pending) {
|
|
42681
|
+
return;
|
|
42682
|
+
}
|
|
42683
|
+
this.pendingUiDelta = null;
|
|
42684
|
+
this.clearUiDeltaFlushTimer();
|
|
42685
|
+
this.outputSeq += 1;
|
|
42686
|
+
this.enqueueOutput(
|
|
42687
|
+
buildUiMessageChunkOutputEnvelope({
|
|
42688
|
+
context: pending.context,
|
|
42689
|
+
outputSeq: this.outputSeq,
|
|
42690
|
+
chunk: pending.chunk,
|
|
42691
|
+
createdAt: pending.createdAt
|
|
42692
|
+
})
|
|
42693
|
+
);
|
|
42694
|
+
this.uiMessagePartTracker.append(pending.chunk);
|
|
42695
|
+
await this.appendUiChunkToAssembler(pending.chunk);
|
|
42696
|
+
}
|
|
42697
|
+
// ---------------------------------------------------------------------------
|
|
42603
42698
|
// Delta coalescing
|
|
42604
42699
|
// ---------------------------------------------------------------------------
|
|
42605
42700
|
async bufferDelta(context, delta) {
|
|
@@ -42905,6 +43000,50 @@ function terminalEntryStatus(projection) {
|
|
|
42905
43000
|
}
|
|
42906
43001
|
return "completed";
|
|
42907
43002
|
}
|
|
43003
|
+
function coalescibleUiDeltaChunk(projection) {
|
|
43004
|
+
if (projection.statusText !== void 0 || projection.turnStatus !== void 0 || projection.usage !== void 0 || projection.consumedCommandIds !== void 0) {
|
|
43005
|
+
return null;
|
|
43006
|
+
}
|
|
43007
|
+
const chunk = projection.chunk;
|
|
43008
|
+
switch (chunk.type) {
|
|
43009
|
+
case "text-delta":
|
|
43010
|
+
case "reasoning-delta":
|
|
43011
|
+
return chunk.providerMetadata === void 0 ? chunk : null;
|
|
43012
|
+
case "tool-input-delta":
|
|
43013
|
+
return chunk;
|
|
43014
|
+
default:
|
|
43015
|
+
return null;
|
|
43016
|
+
}
|
|
43017
|
+
}
|
|
43018
|
+
function canCoalesceUiDelta(pending, context, chunk) {
|
|
43019
|
+
if (pending.context.sessionId !== context.sessionId || pending.context.runtimeId !== context.runtimeId || pending.context.bridgeLeaseId !== context.bridgeLeaseId || pending.chunk.type !== chunk.type) {
|
|
43020
|
+
return false;
|
|
43021
|
+
}
|
|
43022
|
+
if (pending.chunk.type === "tool-input-delta" && chunk.type === "tool-input-delta") {
|
|
43023
|
+
return pending.chunk.toolCallId === chunk.toolCallId;
|
|
43024
|
+
}
|
|
43025
|
+
if (pending.chunk.type !== "tool-input-delta" && chunk.type !== "tool-input-delta") {
|
|
43026
|
+
return pending.chunk.id === chunk.id;
|
|
43027
|
+
}
|
|
43028
|
+
return false;
|
|
43029
|
+
}
|
|
43030
|
+
function mergeUiDeltaChunks(pending, chunk) {
|
|
43031
|
+
if (pending.type === "tool-input-delta" && chunk.type === "tool-input-delta") {
|
|
43032
|
+
return {
|
|
43033
|
+
...pending,
|
|
43034
|
+
inputTextDelta: pending.inputTextDelta + chunk.inputTextDelta
|
|
43035
|
+
};
|
|
43036
|
+
}
|
|
43037
|
+
if (pending.type !== "tool-input-delta" && chunk.type !== "tool-input-delta") {
|
|
43038
|
+
return { ...pending, delta: pending.delta + chunk.delta };
|
|
43039
|
+
}
|
|
43040
|
+
throw new Error(
|
|
43041
|
+
`Cannot merge ui delta chunks of kinds ${pending.type} and ${chunk.type}`
|
|
43042
|
+
);
|
|
43043
|
+
}
|
|
43044
|
+
function uiDeltaTextLength(chunk) {
|
|
43045
|
+
return chunk.type === "tool-input-delta" ? chunk.inputTextDelta.length : chunk.delta.length;
|
|
43046
|
+
}
|
|
42908
43047
|
function canCoalesceDelta(pending, context, delta) {
|
|
42909
43048
|
return pending.context.sessionId === context.sessionId && pending.context.runtimeId === context.runtimeId && pending.context.bridgeLeaseId === context.bridgeLeaseId && pending.delta.messageId === delta.messageId && pending.delta.partId === delta.partId && pending.delta.role === delta.role && pending.delta.kind === delta.kind && pending.delta.delta.type === delta.delta.type;
|
|
42910
43049
|
}
|
package/dist/index.js
CHANGED
|
@@ -28558,7 +28558,7 @@ var init_package = __esm({
|
|
|
28558
28558
|
"package.json"() {
|
|
28559
28559
|
package_default = {
|
|
28560
28560
|
name: "@autohq/cli",
|
|
28561
|
-
version: "0.1.
|
|
28561
|
+
version: "0.1.328",
|
|
28562
28562
|
license: "SEE LICENSE IN README.md",
|
|
28563
28563
|
publishConfig: {
|
|
28564
28564
|
access: "public"
|
|
@@ -30165,7 +30165,9 @@ function assertNoDuplicateFacadeField2(input) {
|
|
|
30165
30165
|
}
|
|
30166
30166
|
}
|
|
30167
30167
|
function supportedRemovalTargets() {
|
|
30168
|
-
return ["tools", "triggers"].filter(
|
|
30168
|
+
return ["tools", "triggers", "env"].filter(
|
|
30169
|
+
(key) => AGENT_FIELDS[key]?.remove
|
|
30170
|
+
);
|
|
30169
30171
|
}
|
|
30170
30172
|
var AGENT_FIELDS;
|
|
30171
30173
|
var init_agent_fields = __esm({
|
|
@@ -30189,7 +30191,9 @@ var init_agent_fields = __esm({
|
|
|
30189
30191
|
identity: inlineIdentityField(),
|
|
30190
30192
|
initialPrompt: fileBackedStringField(),
|
|
30191
30193
|
displayTitle: specField(),
|
|
30192
|
-
env
|
|
30194
|
+
// Named map so variants can drop inherited env vars (e.g. a lean variant
|
|
30195
|
+
// removing an imported fragment's secret-backed token) with `remove.env`.
|
|
30196
|
+
env: namedMapField(),
|
|
30193
30197
|
mounts: mountsField(),
|
|
30194
30198
|
triggers: triggersField(),
|
|
30195
30199
|
session: specField(),
|
|
@@ -39562,6 +39566,7 @@ function providerMetadataField(providerMetadata) {
|
|
|
39562
39566
|
|
|
39563
39567
|
// src/commands/agent-bridge/harness/output-buffer.ts
|
|
39564
39568
|
var AGENT_BRIDGE_OUTPUT_DELTA_FLUSH_MS = 50;
|
|
39569
|
+
var AGENT_BRIDGE_OUTPUT_UI_DELTA_MAX_CHARS = 32768;
|
|
39565
39570
|
var AGENT_BRIDGE_OUTPUT_ACK_RETRY_BACKOFF_MS = [250, 1e3];
|
|
39566
39571
|
var AgentBridgeOutputBuffer = class {
|
|
39567
39572
|
constructor(input) {
|
|
@@ -39573,6 +39578,8 @@ var AgentBridgeOutputBuffer = class {
|
|
|
39573
39578
|
pendingOutputs = /* @__PURE__ */ new Map();
|
|
39574
39579
|
pendingDelta = null;
|
|
39575
39580
|
deltaFlushTimer = null;
|
|
39581
|
+
pendingUiDelta = null;
|
|
39582
|
+
uiDeltaFlushTimer = null;
|
|
39576
39583
|
activeUiMessageAssembler = null;
|
|
39577
39584
|
uiMessagePartTracker = new UiMessagePartTracker();
|
|
39578
39585
|
drainBlocked = false;
|
|
@@ -39582,6 +39589,12 @@ var AgentBridgeOutputBuffer = class {
|
|
|
39582
39589
|
// ---------------------------------------------------------------------------
|
|
39583
39590
|
async emitProjection(context, projection) {
|
|
39584
39591
|
if (projection.type === "ui_message_chunk") {
|
|
39592
|
+
const coalescible = coalescibleUiDeltaChunk(projection);
|
|
39593
|
+
if (coalescible) {
|
|
39594
|
+
await this.bufferUiDeltaChunk(context, coalescible);
|
|
39595
|
+
return;
|
|
39596
|
+
}
|
|
39597
|
+
await this.flushPendingUiDelta();
|
|
39585
39598
|
await this.emitUiMessageChunk(context, projection);
|
|
39586
39599
|
return;
|
|
39587
39600
|
}
|
|
@@ -39589,10 +39602,12 @@ var AgentBridgeOutputBuffer = class {
|
|
|
39589
39602
|
await this.bufferDelta(context, projection.delta);
|
|
39590
39603
|
return;
|
|
39591
39604
|
}
|
|
39605
|
+
await this.flushPendingUiDelta();
|
|
39592
39606
|
await this.flushPendingDelta();
|
|
39593
39607
|
await this.enqueueProjectionAndDrain(context, projection);
|
|
39594
39608
|
}
|
|
39595
39609
|
async replayPendingOutputs() {
|
|
39610
|
+
await this.materializePendingUiDelta();
|
|
39596
39611
|
await this.flushPendingDelta({ force: true });
|
|
39597
39612
|
await this.drainPendingOutputs({ force: true });
|
|
39598
39613
|
}
|
|
@@ -39716,10 +39731,15 @@ var AgentBridgeOutputBuffer = class {
|
|
|
39716
39731
|
this.drainPromise ??= (async () => {
|
|
39717
39732
|
while (true) {
|
|
39718
39733
|
const output = this.nextPendingOutput();
|
|
39719
|
-
if (
|
|
39720
|
-
|
|
39734
|
+
if (output) {
|
|
39735
|
+
await this.emitUntilAcked(output);
|
|
39736
|
+
continue;
|
|
39721
39737
|
}
|
|
39722
|
-
|
|
39738
|
+
if (this.pendingUiDelta) {
|
|
39739
|
+
await this.materializePendingUiDelta();
|
|
39740
|
+
continue;
|
|
39741
|
+
}
|
|
39742
|
+
return;
|
|
39723
39743
|
}
|
|
39724
39744
|
})().catch((error51) => {
|
|
39725
39745
|
this.drainBlocked = true;
|
|
@@ -39730,6 +39750,85 @@ var AgentBridgeOutputBuffer = class {
|
|
|
39730
39750
|
await this.drainPromise;
|
|
39731
39751
|
}
|
|
39732
39752
|
// ---------------------------------------------------------------------------
|
|
39753
|
+
// UI chunk delta coalescing
|
|
39754
|
+
// ---------------------------------------------------------------------------
|
|
39755
|
+
async bufferUiDeltaChunk(context, chunk) {
|
|
39756
|
+
const pending = this.pendingUiDelta;
|
|
39757
|
+
if (pending && canCoalesceUiDelta(pending, context, chunk)) {
|
|
39758
|
+
pending.chunk = mergeUiDeltaChunks(pending.chunk, chunk);
|
|
39759
|
+
if (uiDeltaTextLength(pending.chunk) >= AGENT_BRIDGE_OUTPUT_UI_DELTA_MAX_CHARS) {
|
|
39760
|
+
await this.flushPendingUiDelta();
|
|
39761
|
+
}
|
|
39762
|
+
return;
|
|
39763
|
+
}
|
|
39764
|
+
await this.flushPendingUiDelta();
|
|
39765
|
+
this.pendingUiDelta = { context, chunk: { ...chunk }, createdAt: now2() };
|
|
39766
|
+
this.scheduleUiDeltaFlush();
|
|
39767
|
+
}
|
|
39768
|
+
scheduleUiDeltaFlush() {
|
|
39769
|
+
if (this.uiDeltaFlushTimer !== null) {
|
|
39770
|
+
return;
|
|
39771
|
+
}
|
|
39772
|
+
this.uiDeltaFlushTimer = setTimeout(() => {
|
|
39773
|
+
this.uiDeltaFlushTimer = null;
|
|
39774
|
+
if (!this.pendingUiDelta) {
|
|
39775
|
+
return;
|
|
39776
|
+
}
|
|
39777
|
+
if (this.drainPromise) {
|
|
39778
|
+
this.scheduleUiDeltaFlush();
|
|
39779
|
+
return;
|
|
39780
|
+
}
|
|
39781
|
+
void this.flushPendingUiDelta().catch((error51) => {
|
|
39782
|
+
this.drainBlocked = true;
|
|
39783
|
+
this.input.runtimeLogger?.warn(
|
|
39784
|
+
"agent_bridge_output_buffer_flush_failed",
|
|
39785
|
+
{
|
|
39786
|
+
error: error51 instanceof Error ? error51.message : String(error51),
|
|
39787
|
+
pending_count: this.pendingOutputs.size
|
|
39788
|
+
}
|
|
39789
|
+
);
|
|
39790
|
+
});
|
|
39791
|
+
}, AGENT_BRIDGE_OUTPUT_DELTA_FLUSH_MS);
|
|
39792
|
+
}
|
|
39793
|
+
clearUiDeltaFlushTimer() {
|
|
39794
|
+
if (this.uiDeltaFlushTimer === null) {
|
|
39795
|
+
return;
|
|
39796
|
+
}
|
|
39797
|
+
clearTimeout(this.uiDeltaFlushTimer);
|
|
39798
|
+
this.uiDeltaFlushTimer = null;
|
|
39799
|
+
}
|
|
39800
|
+
async flushPendingUiDelta() {
|
|
39801
|
+
if (!this.pendingUiDelta) {
|
|
39802
|
+
return;
|
|
39803
|
+
}
|
|
39804
|
+
await this.materializePendingUiDelta();
|
|
39805
|
+
await this.drainPendingOutputs();
|
|
39806
|
+
}
|
|
39807
|
+
// Turns the parked coalesced chunk into a queued envelope and applies it to
|
|
39808
|
+
// the part tracker and message assembler, exactly as its source chunks would
|
|
39809
|
+
// have applied one by one (delta chunks never settle a part or complete a
|
|
39810
|
+
// message, so tracker/assembler side effects reduce to text accumulation).
|
|
39811
|
+
// Does not drain: the drain loop calls this mid-loop and keeps pulling.
|
|
39812
|
+
async materializePendingUiDelta() {
|
|
39813
|
+
const pending = this.pendingUiDelta;
|
|
39814
|
+
if (!pending) {
|
|
39815
|
+
return;
|
|
39816
|
+
}
|
|
39817
|
+
this.pendingUiDelta = null;
|
|
39818
|
+
this.clearUiDeltaFlushTimer();
|
|
39819
|
+
this.outputSeq += 1;
|
|
39820
|
+
this.enqueueOutput(
|
|
39821
|
+
buildUiMessageChunkOutputEnvelope({
|
|
39822
|
+
context: pending.context,
|
|
39823
|
+
outputSeq: this.outputSeq,
|
|
39824
|
+
chunk: pending.chunk,
|
|
39825
|
+
createdAt: pending.createdAt
|
|
39826
|
+
})
|
|
39827
|
+
);
|
|
39828
|
+
this.uiMessagePartTracker.append(pending.chunk);
|
|
39829
|
+
await this.appendUiChunkToAssembler(pending.chunk);
|
|
39830
|
+
}
|
|
39831
|
+
// ---------------------------------------------------------------------------
|
|
39733
39832
|
// Delta coalescing
|
|
39734
39833
|
// ---------------------------------------------------------------------------
|
|
39735
39834
|
async bufferDelta(context, delta) {
|
|
@@ -40035,6 +40134,50 @@ function terminalEntryStatus(projection) {
|
|
|
40035
40134
|
}
|
|
40036
40135
|
return "completed";
|
|
40037
40136
|
}
|
|
40137
|
+
function coalescibleUiDeltaChunk(projection) {
|
|
40138
|
+
if (projection.statusText !== void 0 || projection.turnStatus !== void 0 || projection.usage !== void 0 || projection.consumedCommandIds !== void 0) {
|
|
40139
|
+
return null;
|
|
40140
|
+
}
|
|
40141
|
+
const chunk = projection.chunk;
|
|
40142
|
+
switch (chunk.type) {
|
|
40143
|
+
case "text-delta":
|
|
40144
|
+
case "reasoning-delta":
|
|
40145
|
+
return chunk.providerMetadata === void 0 ? chunk : null;
|
|
40146
|
+
case "tool-input-delta":
|
|
40147
|
+
return chunk;
|
|
40148
|
+
default:
|
|
40149
|
+
return null;
|
|
40150
|
+
}
|
|
40151
|
+
}
|
|
40152
|
+
function canCoalesceUiDelta(pending, context, chunk) {
|
|
40153
|
+
if (pending.context.sessionId !== context.sessionId || pending.context.runtimeId !== context.runtimeId || pending.context.bridgeLeaseId !== context.bridgeLeaseId || pending.chunk.type !== chunk.type) {
|
|
40154
|
+
return false;
|
|
40155
|
+
}
|
|
40156
|
+
if (pending.chunk.type === "tool-input-delta" && chunk.type === "tool-input-delta") {
|
|
40157
|
+
return pending.chunk.toolCallId === chunk.toolCallId;
|
|
40158
|
+
}
|
|
40159
|
+
if (pending.chunk.type !== "tool-input-delta" && chunk.type !== "tool-input-delta") {
|
|
40160
|
+
return pending.chunk.id === chunk.id;
|
|
40161
|
+
}
|
|
40162
|
+
return false;
|
|
40163
|
+
}
|
|
40164
|
+
function mergeUiDeltaChunks(pending, chunk) {
|
|
40165
|
+
if (pending.type === "tool-input-delta" && chunk.type === "tool-input-delta") {
|
|
40166
|
+
return {
|
|
40167
|
+
...pending,
|
|
40168
|
+
inputTextDelta: pending.inputTextDelta + chunk.inputTextDelta
|
|
40169
|
+
};
|
|
40170
|
+
}
|
|
40171
|
+
if (pending.type !== "tool-input-delta" && chunk.type !== "tool-input-delta") {
|
|
40172
|
+
return { ...pending, delta: pending.delta + chunk.delta };
|
|
40173
|
+
}
|
|
40174
|
+
throw new Error(
|
|
40175
|
+
`Cannot merge ui delta chunks of kinds ${pending.type} and ${chunk.type}`
|
|
40176
|
+
);
|
|
40177
|
+
}
|
|
40178
|
+
function uiDeltaTextLength(chunk) {
|
|
40179
|
+
return chunk.type === "tool-input-delta" ? chunk.inputTextDelta.length : chunk.delta.length;
|
|
40180
|
+
}
|
|
40038
40181
|
function canCoalesceDelta(pending, context, delta) {
|
|
40039
40182
|
return pending.context.sessionId === context.sessionId && pending.context.runtimeId === context.runtimeId && pending.context.bridgeLeaseId === context.bridgeLeaseId && pending.delta.messageId === delta.messageId && pending.delta.partId === delta.partId && pending.delta.role === delta.role && pending.delta.kind === delta.kind && pending.delta.delta.type === delta.delta.type;
|
|
40040
40183
|
}
|