@autohq/cli 0.1.292 → 0.1.294

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.
@@ -23399,7 +23399,7 @@ Object.assign(lookup, {
23399
23399
  // package.json
23400
23400
  var package_default = {
23401
23401
  name: "@autohq/cli",
23402
- version: "0.1.292",
23402
+ version: "0.1.294",
23403
23403
  license: "SEE LICENSE IN README.md",
23404
23404
  publishConfig: {
23405
23405
  access: "public"
@@ -28434,6 +28434,9 @@ var UsageEventSchema = external_exports.object({
28434
28434
  });
28435
28435
  var UsageEventRecordSchema = UsageEventSchema.extend({
28436
28436
  id: external_exports.string().trim().min(1),
28437
+ // Set on append-only correction rows: this row replaces the pointed-at row's
28438
+ // amounts, and ledger readers exclude any row another row supersedes.
28439
+ supersedesUsageEventId: external_exports.string().trim().min(1).nullable().default(null),
28437
28440
  createdAt: external_exports.string().datetime()
28438
28441
  });
28439
28442
  var UsageTotalsSchema = external_exports.object({
@@ -36694,6 +36697,295 @@ var _a21;
36694
36697
  _a21 = symbol21;
36695
36698
  var defaultDownload2 = createDownload();
36696
36699
 
36700
+ // src/commands/agent-bridge/harness/ui-message-part-tracker.ts
36701
+ var UiMessagePartTracker = class {
36702
+ messageId = null;
36703
+ messageMetadata;
36704
+ metadataEmitted = false;
36705
+ parts = [];
36706
+ textPartIndexById = /* @__PURE__ */ new Map();
36707
+ reasoningPartIndexById = /* @__PURE__ */ new Map();
36708
+ toolPartIndexByCallId = /* @__PURE__ */ new Map();
36709
+ dataPartIndexById = /* @__PURE__ */ new Map();
36710
+ append(chunk) {
36711
+ switch (chunk.type) {
36712
+ case "start": {
36713
+ this.reset();
36714
+ const messageId = chunk.messageId?.trim();
36715
+ this.messageId = messageId && messageId !== UNKNOWN_MESSAGE_ID ? messageId : null;
36716
+ this.messageMetadata = chunk.messageMetadata;
36717
+ return [];
36718
+ }
36719
+ case "finish":
36720
+ case "error":
36721
+ case "abort": {
36722
+ this.reset();
36723
+ return [];
36724
+ }
36725
+ case "text-start": {
36726
+ const index = this.pushPart({
36727
+ type: "text",
36728
+ text: "",
36729
+ state: "streaming",
36730
+ ...providerMetadataField(chunk.providerMetadata)
36731
+ });
36732
+ this.textPartIndexById.set(chunk.id, index);
36733
+ return [];
36734
+ }
36735
+ case "text-delta": {
36736
+ const part = this.partById(this.textPartIndexById, chunk.id);
36737
+ if (part) {
36738
+ part.text = String(part.text ?? "") + chunk.delta;
36739
+ }
36740
+ return [];
36741
+ }
36742
+ case "text-end": {
36743
+ const index = this.textPartIndexById.get(chunk.id);
36744
+ const part = this.partById(this.textPartIndexById, chunk.id);
36745
+ this.textPartIndexById.delete(chunk.id);
36746
+ if (!part || index === void 0) {
36747
+ return [];
36748
+ }
36749
+ part.state = "done";
36750
+ if (chunk.providerMetadata !== void 0) {
36751
+ part.providerMetadata = chunk.providerMetadata;
36752
+ }
36753
+ return this.persistable(index);
36754
+ }
36755
+ case "reasoning-start": {
36756
+ const index = this.pushPart({
36757
+ type: "reasoning",
36758
+ text: "",
36759
+ state: "streaming",
36760
+ ...providerMetadataField(chunk.providerMetadata)
36761
+ });
36762
+ this.reasoningPartIndexById.set(chunk.id, index);
36763
+ return [];
36764
+ }
36765
+ case "reasoning-delta": {
36766
+ const part = this.partById(this.reasoningPartIndexById, chunk.id);
36767
+ if (part) {
36768
+ part.text = String(part.text ?? "") + chunk.delta;
36769
+ if (chunk.providerMetadata !== void 0) {
36770
+ part.providerMetadata = chunk.providerMetadata;
36771
+ }
36772
+ }
36773
+ return [];
36774
+ }
36775
+ case "reasoning-end": {
36776
+ const index = this.reasoningPartIndexById.get(chunk.id);
36777
+ const part = this.partById(this.reasoningPartIndexById, chunk.id);
36778
+ this.reasoningPartIndexById.delete(chunk.id);
36779
+ if (!part || index === void 0) {
36780
+ return [];
36781
+ }
36782
+ part.state = "done";
36783
+ if (chunk.providerMetadata !== void 0) {
36784
+ part.providerMetadata = chunk.providerMetadata;
36785
+ }
36786
+ return this.persistable(index);
36787
+ }
36788
+ case "tool-input-start": {
36789
+ const index = this.pushPart(
36790
+ toolPartShape({
36791
+ toolCallId: chunk.toolCallId,
36792
+ toolName: chunk.toolName,
36793
+ dynamic: chunk.dynamic,
36794
+ state: "input-streaming"
36795
+ })
36796
+ );
36797
+ this.toolPartIndexByCallId.set(chunk.toolCallId, index);
36798
+ return [];
36799
+ }
36800
+ case "tool-input-available": {
36801
+ const index = this.upsertToolPart(chunk.toolCallId, {
36802
+ ...toolPartShape({
36803
+ toolCallId: chunk.toolCallId,
36804
+ toolName: chunk.toolName,
36805
+ dynamic: chunk.dynamic,
36806
+ state: "input-available"
36807
+ }),
36808
+ input: chunk.input,
36809
+ ...chunk.providerExecuted !== void 0 ? { providerExecuted: chunk.providerExecuted } : {},
36810
+ ...chunk.providerMetadata !== void 0 ? { callProviderMetadata: chunk.providerMetadata } : {}
36811
+ });
36812
+ return this.persistable(index);
36813
+ }
36814
+ case "tool-input-error": {
36815
+ const index = this.upsertToolPart(chunk.toolCallId, {
36816
+ ...toolPartShape({
36817
+ toolCallId: chunk.toolCallId,
36818
+ toolName: chunk.toolName,
36819
+ dynamic: chunk.dynamic,
36820
+ state: "output-error"
36821
+ }),
36822
+ input: chunk.input,
36823
+ errorText: chunk.errorText
36824
+ });
36825
+ return this.persistable(index);
36826
+ }
36827
+ case "tool-output-available": {
36828
+ const part = this.partById(
36829
+ this.toolPartIndexByCallId,
36830
+ chunk.toolCallId
36831
+ );
36832
+ const index = this.toolPartIndexByCallId.get(chunk.toolCallId);
36833
+ if (!part || index === void 0) {
36834
+ return [];
36835
+ }
36836
+ part.state = "output-available";
36837
+ part.output = chunk.output;
36838
+ part.preliminary = chunk.preliminary;
36839
+ return this.persistable(index);
36840
+ }
36841
+ case "tool-output-error": {
36842
+ const part = this.partById(
36843
+ this.toolPartIndexByCallId,
36844
+ chunk.toolCallId
36845
+ );
36846
+ const index = this.toolPartIndexByCallId.get(chunk.toolCallId);
36847
+ if (!part || index === void 0) {
36848
+ return [];
36849
+ }
36850
+ part.state = "output-error";
36851
+ part.errorText = chunk.errorText;
36852
+ return this.persistable(index);
36853
+ }
36854
+ case "start-step": {
36855
+ const index = this.pushPart({ type: "step-start" });
36856
+ return this.persistable(index);
36857
+ }
36858
+ case "finish-step": {
36859
+ this.textPartIndexById.clear();
36860
+ this.reasoningPartIndexById.clear();
36861
+ return [];
36862
+ }
36863
+ case "file": {
36864
+ const index = this.pushPart({
36865
+ type: "file",
36866
+ mediaType: chunk.mediaType,
36867
+ url: chunk.url
36868
+ });
36869
+ return this.persistable(index);
36870
+ }
36871
+ case "source-url": {
36872
+ const index = this.pushPart({
36873
+ type: "source-url",
36874
+ sourceId: chunk.sourceId,
36875
+ url: chunk.url,
36876
+ ...chunk.title !== void 0 ? { title: chunk.title } : {}
36877
+ });
36878
+ return this.persistable(index);
36879
+ }
36880
+ case "source-document": {
36881
+ const index = this.pushPart({
36882
+ type: "source-document",
36883
+ sourceId: chunk.sourceId,
36884
+ mediaType: chunk.mediaType,
36885
+ title: chunk.title,
36886
+ ...chunk.filename !== void 0 ? { filename: chunk.filename } : {}
36887
+ });
36888
+ return this.persistable(index);
36889
+ }
36890
+ default: {
36891
+ return this.appendDataChunk(chunk);
36892
+ }
36893
+ }
36894
+ }
36895
+ appendDataChunk(chunk) {
36896
+ if (!chunk.type.startsWith("data-") || chunk.type === "data-auto-question") {
36897
+ return [];
36898
+ }
36899
+ const dataChunk = chunk;
36900
+ if (dataChunk.transient) {
36901
+ return [];
36902
+ }
36903
+ const part = {
36904
+ type: dataChunk.type,
36905
+ ...dataChunk.id !== void 0 ? { id: dataChunk.id } : {},
36906
+ data: dataChunk.data
36907
+ };
36908
+ const dataKey = dataChunk.id ? `${dataChunk.type}:${dataChunk.id}` : null;
36909
+ const existingIndex = dataKey ? this.dataPartIndexById.get(dataKey) : void 0;
36910
+ if (existingIndex !== void 0) {
36911
+ this.parts[existingIndex] = part;
36912
+ return this.persistable(existingIndex);
36913
+ }
36914
+ const index = this.pushPart(part);
36915
+ if (dataKey) {
36916
+ this.dataPartIndexById.set(dataKey, index);
36917
+ }
36918
+ return this.persistable(index);
36919
+ }
36920
+ upsertToolPart(toolCallId, part) {
36921
+ const existingIndex = this.toolPartIndexByCallId.get(toolCallId);
36922
+ if (existingIndex !== void 0) {
36923
+ this.parts[existingIndex] = part;
36924
+ return existingIndex;
36925
+ }
36926
+ const index = this.pushPart(part);
36927
+ this.toolPartIndexByCallId.set(toolCallId, index);
36928
+ return index;
36929
+ }
36930
+ persistable(partIndex) {
36931
+ const part = this.parts[partIndex];
36932
+ if (!this.messageId || !part) {
36933
+ return [];
36934
+ }
36935
+ const includeMetadata = !this.metadataEmitted && this.messageMetadata !== void 0;
36936
+ if (includeMetadata) {
36937
+ this.metadataEmitted = true;
36938
+ }
36939
+ return [
36940
+ {
36941
+ messageId: this.messageId,
36942
+ partIndex,
36943
+ part: toJsonValue(part),
36944
+ ...includeMetadata ? { messageMetadata: toJsonValue(this.messageMetadata) } : {}
36945
+ }
36946
+ ];
36947
+ }
36948
+ pushPart(part) {
36949
+ this.parts.push(part);
36950
+ return this.parts.length - 1;
36951
+ }
36952
+ partById(indexById, id) {
36953
+ const index = indexById.get(id);
36954
+ if (index === void 0) {
36955
+ return null;
36956
+ }
36957
+ return this.parts[index] ?? null;
36958
+ }
36959
+ reset() {
36960
+ this.messageId = null;
36961
+ this.messageMetadata = void 0;
36962
+ this.metadataEmitted = false;
36963
+ this.parts = [];
36964
+ this.textPartIndexById = /* @__PURE__ */ new Map();
36965
+ this.reasoningPartIndexById = /* @__PURE__ */ new Map();
36966
+ this.toolPartIndexByCallId = /* @__PURE__ */ new Map();
36967
+ this.dataPartIndexById = /* @__PURE__ */ new Map();
36968
+ }
36969
+ };
36970
+ function toolPartShape(input) {
36971
+ if (input.dynamic) {
36972
+ return {
36973
+ type: "dynamic-tool",
36974
+ toolName: input.toolName,
36975
+ toolCallId: input.toolCallId,
36976
+ state: input.state
36977
+ };
36978
+ }
36979
+ return {
36980
+ type: `tool-${input.toolName}`,
36981
+ toolCallId: input.toolCallId,
36982
+ state: input.state
36983
+ };
36984
+ }
36985
+ function providerMetadataField(providerMetadata) {
36986
+ return providerMetadata !== void 0 ? { providerMetadata } : {};
36987
+ }
36988
+
36697
36989
  // src/commands/agent-bridge/harness/output-buffer.ts
36698
36990
  var AGENT_BRIDGE_OUTPUT_DELTA_FLUSH_MS = 50;
36699
36991
  var AgentBridgeOutputBuffer = class {
@@ -36707,6 +36999,7 @@ var AgentBridgeOutputBuffer = class {
36707
36999
  pendingDelta = null;
36708
37000
  deltaFlushTimer = null;
36709
37001
  activeUiMessageAssembler = null;
37002
+ uiMessagePartTracker = new UiMessagePartTracker();
36710
37003
  drainBlocked = false;
36711
37004
  drainPromise = null;
36712
37005
  // ---------------------------------------------------------------------------
@@ -36747,6 +37040,9 @@ var AgentBridgeOutputBuffer = class {
36747
37040
  }
36748
37041
  await this.flushPendingDelta();
36749
37042
  await this.emitLiveUiMessageChunk(context, projection.chunk);
37043
+ await this.emitUiMessagePartSnapshots(context, projection.chunk, {
37044
+ coveredSeq: this.outputSeq
37045
+ });
36750
37046
  const completedMessage = await this.appendUiChunkToAssembler(
36751
37047
  projection.chunk
36752
37048
  );
@@ -36805,6 +37101,25 @@ var AgentBridgeOutputBuffer = class {
36805
37101
  this.enqueueOutput(output);
36806
37102
  await this.drainPendingOutputs();
36807
37103
  }
37104
+ async emitUiMessagePartSnapshots(context, chunk, input) {
37105
+ const snapshots = this.uiMessagePartTracker.append(chunk);
37106
+ if (snapshots.length === 0) {
37107
+ return;
37108
+ }
37109
+ for (const snapshot of snapshots) {
37110
+ this.outputSeq += 1;
37111
+ this.enqueueOutput(
37112
+ buildUiMessagePartOutputEnvelope({
37113
+ context,
37114
+ outputSeq: this.outputSeq,
37115
+ coveredSeq: input.coveredSeq,
37116
+ snapshot,
37117
+ createdAt: now2()
37118
+ })
37119
+ );
37120
+ }
37121
+ await this.drainPendingOutputs();
37122
+ }
36808
37123
  // ---------------------------------------------------------------------------
36809
37124
  // Transport emit
36810
37125
  // ---------------------------------------------------------------------------
@@ -37117,6 +37432,23 @@ function buildUiMessageChunkOutputEnvelope(input) {
37117
37432
  createdAt: input.createdAt
37118
37433
  });
37119
37434
  }
37435
+ function buildUiMessagePartOutputEnvelope(input) {
37436
+ const { context, snapshot } = input;
37437
+ return RuntimeBridgeOutputEnvelopeSchema.parse({
37438
+ type: "ui.message.part",
37439
+ sessionId: context.sessionId,
37440
+ runtimeId: context.runtimeId,
37441
+ bridgeLeaseId: context.bridgeLeaseId,
37442
+ outputSeq: input.outputSeq,
37443
+ messageId: snapshot.messageId,
37444
+ role: "assistant",
37445
+ partIndex: snapshot.partIndex,
37446
+ part: snapshot.part,
37447
+ coveredSeq: input.coveredSeq,
37448
+ ...snapshot.messageMetadata !== void 0 ? { messageMetadata: snapshot.messageMetadata } : {},
37449
+ createdAt: input.createdAt
37450
+ });
37451
+ }
37120
37452
  function buildUiMessageCompletedOutputEnvelope(input) {
37121
37453
  const { context } = input;
37122
37454
  return RuntimeBridgeOutputEnvelopeSchema.parse({
package/dist/index.js CHANGED
@@ -20336,6 +20336,9 @@ var init_usage = __esm({
20336
20336
  });
20337
20337
  UsageEventRecordSchema = UsageEventSchema.extend({
20338
20338
  id: external_exports.string().trim().min(1),
20339
+ // Set on append-only correction rows: this row replaces the pointed-at row's
20340
+ // amounts, and ledger readers exclude any row another row supersedes.
20341
+ supersedesUsageEventId: external_exports.string().trim().min(1).nullable().default(null),
20339
20342
  createdAt: external_exports.string().datetime()
20340
20343
  });
20341
20344
  UsageTotalsSchema = external_exports.object({
@@ -23182,7 +23185,7 @@ var init_package = __esm({
23182
23185
  "package.json"() {
23183
23186
  package_default = {
23184
23187
  name: "@autohq/cli",
23185
- version: "0.1.292",
23188
+ version: "0.1.294",
23186
23189
  license: "SEE LICENSE IN README.md",
23187
23190
  publishConfig: {
23188
23191
  access: "public"
@@ -33712,6 +33715,298 @@ init_src();
33712
33715
  // src/commands/agent-bridge/harness/output-buffer.ts
33713
33716
  init_src();
33714
33717
  import { readUIMessageStream } from "ai";
33718
+
33719
+ // src/commands/agent-bridge/harness/ui-message-part-tracker.ts
33720
+ init_src();
33721
+ var UiMessagePartTracker = class {
33722
+ messageId = null;
33723
+ messageMetadata;
33724
+ metadataEmitted = false;
33725
+ parts = [];
33726
+ textPartIndexById = /* @__PURE__ */ new Map();
33727
+ reasoningPartIndexById = /* @__PURE__ */ new Map();
33728
+ toolPartIndexByCallId = /* @__PURE__ */ new Map();
33729
+ dataPartIndexById = /* @__PURE__ */ new Map();
33730
+ append(chunk) {
33731
+ switch (chunk.type) {
33732
+ case "start": {
33733
+ this.reset();
33734
+ const messageId = chunk.messageId?.trim();
33735
+ this.messageId = messageId && messageId !== UNKNOWN_MESSAGE_ID ? messageId : null;
33736
+ this.messageMetadata = chunk.messageMetadata;
33737
+ return [];
33738
+ }
33739
+ case "finish":
33740
+ case "error":
33741
+ case "abort": {
33742
+ this.reset();
33743
+ return [];
33744
+ }
33745
+ case "text-start": {
33746
+ const index = this.pushPart({
33747
+ type: "text",
33748
+ text: "",
33749
+ state: "streaming",
33750
+ ...providerMetadataField(chunk.providerMetadata)
33751
+ });
33752
+ this.textPartIndexById.set(chunk.id, index);
33753
+ return [];
33754
+ }
33755
+ case "text-delta": {
33756
+ const part = this.partById(this.textPartIndexById, chunk.id);
33757
+ if (part) {
33758
+ part.text = String(part.text ?? "") + chunk.delta;
33759
+ }
33760
+ return [];
33761
+ }
33762
+ case "text-end": {
33763
+ const index = this.textPartIndexById.get(chunk.id);
33764
+ const part = this.partById(this.textPartIndexById, chunk.id);
33765
+ this.textPartIndexById.delete(chunk.id);
33766
+ if (!part || index === void 0) {
33767
+ return [];
33768
+ }
33769
+ part.state = "done";
33770
+ if (chunk.providerMetadata !== void 0) {
33771
+ part.providerMetadata = chunk.providerMetadata;
33772
+ }
33773
+ return this.persistable(index);
33774
+ }
33775
+ case "reasoning-start": {
33776
+ const index = this.pushPart({
33777
+ type: "reasoning",
33778
+ text: "",
33779
+ state: "streaming",
33780
+ ...providerMetadataField(chunk.providerMetadata)
33781
+ });
33782
+ this.reasoningPartIndexById.set(chunk.id, index);
33783
+ return [];
33784
+ }
33785
+ case "reasoning-delta": {
33786
+ const part = this.partById(this.reasoningPartIndexById, chunk.id);
33787
+ if (part) {
33788
+ part.text = String(part.text ?? "") + chunk.delta;
33789
+ if (chunk.providerMetadata !== void 0) {
33790
+ part.providerMetadata = chunk.providerMetadata;
33791
+ }
33792
+ }
33793
+ return [];
33794
+ }
33795
+ case "reasoning-end": {
33796
+ const index = this.reasoningPartIndexById.get(chunk.id);
33797
+ const part = this.partById(this.reasoningPartIndexById, chunk.id);
33798
+ this.reasoningPartIndexById.delete(chunk.id);
33799
+ if (!part || index === void 0) {
33800
+ return [];
33801
+ }
33802
+ part.state = "done";
33803
+ if (chunk.providerMetadata !== void 0) {
33804
+ part.providerMetadata = chunk.providerMetadata;
33805
+ }
33806
+ return this.persistable(index);
33807
+ }
33808
+ case "tool-input-start": {
33809
+ const index = this.pushPart(
33810
+ toolPartShape({
33811
+ toolCallId: chunk.toolCallId,
33812
+ toolName: chunk.toolName,
33813
+ dynamic: chunk.dynamic,
33814
+ state: "input-streaming"
33815
+ })
33816
+ );
33817
+ this.toolPartIndexByCallId.set(chunk.toolCallId, index);
33818
+ return [];
33819
+ }
33820
+ case "tool-input-available": {
33821
+ const index = this.upsertToolPart(chunk.toolCallId, {
33822
+ ...toolPartShape({
33823
+ toolCallId: chunk.toolCallId,
33824
+ toolName: chunk.toolName,
33825
+ dynamic: chunk.dynamic,
33826
+ state: "input-available"
33827
+ }),
33828
+ input: chunk.input,
33829
+ ...chunk.providerExecuted !== void 0 ? { providerExecuted: chunk.providerExecuted } : {},
33830
+ ...chunk.providerMetadata !== void 0 ? { callProviderMetadata: chunk.providerMetadata } : {}
33831
+ });
33832
+ return this.persistable(index);
33833
+ }
33834
+ case "tool-input-error": {
33835
+ const index = this.upsertToolPart(chunk.toolCallId, {
33836
+ ...toolPartShape({
33837
+ toolCallId: chunk.toolCallId,
33838
+ toolName: chunk.toolName,
33839
+ dynamic: chunk.dynamic,
33840
+ state: "output-error"
33841
+ }),
33842
+ input: chunk.input,
33843
+ errorText: chunk.errorText
33844
+ });
33845
+ return this.persistable(index);
33846
+ }
33847
+ case "tool-output-available": {
33848
+ const part = this.partById(
33849
+ this.toolPartIndexByCallId,
33850
+ chunk.toolCallId
33851
+ );
33852
+ const index = this.toolPartIndexByCallId.get(chunk.toolCallId);
33853
+ if (!part || index === void 0) {
33854
+ return [];
33855
+ }
33856
+ part.state = "output-available";
33857
+ part.output = chunk.output;
33858
+ part.preliminary = chunk.preliminary;
33859
+ return this.persistable(index);
33860
+ }
33861
+ case "tool-output-error": {
33862
+ const part = this.partById(
33863
+ this.toolPartIndexByCallId,
33864
+ chunk.toolCallId
33865
+ );
33866
+ const index = this.toolPartIndexByCallId.get(chunk.toolCallId);
33867
+ if (!part || index === void 0) {
33868
+ return [];
33869
+ }
33870
+ part.state = "output-error";
33871
+ part.errorText = chunk.errorText;
33872
+ return this.persistable(index);
33873
+ }
33874
+ case "start-step": {
33875
+ const index = this.pushPart({ type: "step-start" });
33876
+ return this.persistable(index);
33877
+ }
33878
+ case "finish-step": {
33879
+ this.textPartIndexById.clear();
33880
+ this.reasoningPartIndexById.clear();
33881
+ return [];
33882
+ }
33883
+ case "file": {
33884
+ const index = this.pushPart({
33885
+ type: "file",
33886
+ mediaType: chunk.mediaType,
33887
+ url: chunk.url
33888
+ });
33889
+ return this.persistable(index);
33890
+ }
33891
+ case "source-url": {
33892
+ const index = this.pushPart({
33893
+ type: "source-url",
33894
+ sourceId: chunk.sourceId,
33895
+ url: chunk.url,
33896
+ ...chunk.title !== void 0 ? { title: chunk.title } : {}
33897
+ });
33898
+ return this.persistable(index);
33899
+ }
33900
+ case "source-document": {
33901
+ const index = this.pushPart({
33902
+ type: "source-document",
33903
+ sourceId: chunk.sourceId,
33904
+ mediaType: chunk.mediaType,
33905
+ title: chunk.title,
33906
+ ...chunk.filename !== void 0 ? { filename: chunk.filename } : {}
33907
+ });
33908
+ return this.persistable(index);
33909
+ }
33910
+ default: {
33911
+ return this.appendDataChunk(chunk);
33912
+ }
33913
+ }
33914
+ }
33915
+ appendDataChunk(chunk) {
33916
+ if (!chunk.type.startsWith("data-") || chunk.type === "data-auto-question") {
33917
+ return [];
33918
+ }
33919
+ const dataChunk = chunk;
33920
+ if (dataChunk.transient) {
33921
+ return [];
33922
+ }
33923
+ const part = {
33924
+ type: dataChunk.type,
33925
+ ...dataChunk.id !== void 0 ? { id: dataChunk.id } : {},
33926
+ data: dataChunk.data
33927
+ };
33928
+ const dataKey = dataChunk.id ? `${dataChunk.type}:${dataChunk.id}` : null;
33929
+ const existingIndex = dataKey ? this.dataPartIndexById.get(dataKey) : void 0;
33930
+ if (existingIndex !== void 0) {
33931
+ this.parts[existingIndex] = part;
33932
+ return this.persistable(existingIndex);
33933
+ }
33934
+ const index = this.pushPart(part);
33935
+ if (dataKey) {
33936
+ this.dataPartIndexById.set(dataKey, index);
33937
+ }
33938
+ return this.persistable(index);
33939
+ }
33940
+ upsertToolPart(toolCallId, part) {
33941
+ const existingIndex = this.toolPartIndexByCallId.get(toolCallId);
33942
+ if (existingIndex !== void 0) {
33943
+ this.parts[existingIndex] = part;
33944
+ return existingIndex;
33945
+ }
33946
+ const index = this.pushPart(part);
33947
+ this.toolPartIndexByCallId.set(toolCallId, index);
33948
+ return index;
33949
+ }
33950
+ persistable(partIndex) {
33951
+ const part = this.parts[partIndex];
33952
+ if (!this.messageId || !part) {
33953
+ return [];
33954
+ }
33955
+ const includeMetadata = !this.metadataEmitted && this.messageMetadata !== void 0;
33956
+ if (includeMetadata) {
33957
+ this.metadataEmitted = true;
33958
+ }
33959
+ return [
33960
+ {
33961
+ messageId: this.messageId,
33962
+ partIndex,
33963
+ part: toJsonValue(part),
33964
+ ...includeMetadata ? { messageMetadata: toJsonValue(this.messageMetadata) } : {}
33965
+ }
33966
+ ];
33967
+ }
33968
+ pushPart(part) {
33969
+ this.parts.push(part);
33970
+ return this.parts.length - 1;
33971
+ }
33972
+ partById(indexById, id) {
33973
+ const index = indexById.get(id);
33974
+ if (index === void 0) {
33975
+ return null;
33976
+ }
33977
+ return this.parts[index] ?? null;
33978
+ }
33979
+ reset() {
33980
+ this.messageId = null;
33981
+ this.messageMetadata = void 0;
33982
+ this.metadataEmitted = false;
33983
+ this.parts = [];
33984
+ this.textPartIndexById = /* @__PURE__ */ new Map();
33985
+ this.reasoningPartIndexById = /* @__PURE__ */ new Map();
33986
+ this.toolPartIndexByCallId = /* @__PURE__ */ new Map();
33987
+ this.dataPartIndexById = /* @__PURE__ */ new Map();
33988
+ }
33989
+ };
33990
+ function toolPartShape(input) {
33991
+ if (input.dynamic) {
33992
+ return {
33993
+ type: "dynamic-tool",
33994
+ toolName: input.toolName,
33995
+ toolCallId: input.toolCallId,
33996
+ state: input.state
33997
+ };
33998
+ }
33999
+ return {
34000
+ type: `tool-${input.toolName}`,
34001
+ toolCallId: input.toolCallId,
34002
+ state: input.state
34003
+ };
34004
+ }
34005
+ function providerMetadataField(providerMetadata) {
34006
+ return providerMetadata !== void 0 ? { providerMetadata } : {};
34007
+ }
34008
+
34009
+ // src/commands/agent-bridge/harness/output-buffer.ts
33715
34010
  var AGENT_BRIDGE_OUTPUT_DELTA_FLUSH_MS = 50;
33716
34011
  var AgentBridgeOutputBuffer = class {
33717
34012
  constructor(input) {
@@ -33724,6 +34019,7 @@ var AgentBridgeOutputBuffer = class {
33724
34019
  pendingDelta = null;
33725
34020
  deltaFlushTimer = null;
33726
34021
  activeUiMessageAssembler = null;
34022
+ uiMessagePartTracker = new UiMessagePartTracker();
33727
34023
  drainBlocked = false;
33728
34024
  drainPromise = null;
33729
34025
  // ---------------------------------------------------------------------------
@@ -33764,6 +34060,9 @@ var AgentBridgeOutputBuffer = class {
33764
34060
  }
33765
34061
  await this.flushPendingDelta();
33766
34062
  await this.emitLiveUiMessageChunk(context, projection.chunk);
34063
+ await this.emitUiMessagePartSnapshots(context, projection.chunk, {
34064
+ coveredSeq: this.outputSeq
34065
+ });
33767
34066
  const completedMessage = await this.appendUiChunkToAssembler(
33768
34067
  projection.chunk
33769
34068
  );
@@ -33822,6 +34121,25 @@ var AgentBridgeOutputBuffer = class {
33822
34121
  this.enqueueOutput(output);
33823
34122
  await this.drainPendingOutputs();
33824
34123
  }
34124
+ async emitUiMessagePartSnapshots(context, chunk, input) {
34125
+ const snapshots = this.uiMessagePartTracker.append(chunk);
34126
+ if (snapshots.length === 0) {
34127
+ return;
34128
+ }
34129
+ for (const snapshot of snapshots) {
34130
+ this.outputSeq += 1;
34131
+ this.enqueueOutput(
34132
+ buildUiMessagePartOutputEnvelope({
34133
+ context,
34134
+ outputSeq: this.outputSeq,
34135
+ coveredSeq: input.coveredSeq,
34136
+ snapshot,
34137
+ createdAt: now2()
34138
+ })
34139
+ );
34140
+ }
34141
+ await this.drainPendingOutputs();
34142
+ }
33825
34143
  // ---------------------------------------------------------------------------
33826
34144
  // Transport emit
33827
34145
  // ---------------------------------------------------------------------------
@@ -34134,6 +34452,23 @@ function buildUiMessageChunkOutputEnvelope(input) {
34134
34452
  createdAt: input.createdAt
34135
34453
  });
34136
34454
  }
34455
+ function buildUiMessagePartOutputEnvelope(input) {
34456
+ const { context, snapshot } = input;
34457
+ return RuntimeBridgeOutputEnvelopeSchema.parse({
34458
+ type: "ui.message.part",
34459
+ sessionId: context.sessionId,
34460
+ runtimeId: context.runtimeId,
34461
+ bridgeLeaseId: context.bridgeLeaseId,
34462
+ outputSeq: input.outputSeq,
34463
+ messageId: snapshot.messageId,
34464
+ role: "assistant",
34465
+ partIndex: snapshot.partIndex,
34466
+ part: snapshot.part,
34467
+ coveredSeq: input.coveredSeq,
34468
+ ...snapshot.messageMetadata !== void 0 ? { messageMetadata: snapshot.messageMetadata } : {},
34469
+ createdAt: input.createdAt
34470
+ });
34471
+ }
34137
34472
  function buildUiMessageCompletedOutputEnvelope(input) {
34138
34473
  const { context } = input;
34139
34474
  return RuntimeBridgeOutputEnvelopeSchema.parse({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autohq/cli",
3
- "version": "0.1.292",
3
+ "version": "0.1.294",
4
4
  "license": "SEE LICENSE IN README.md",
5
5
  "publishConfig": {
6
6
  "access": "public"