@tanstack/ai 0.44.0 → 0.44.1

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.
@@ -142,6 +142,8 @@ var TextEngine = class {
142
142
  streamStartTime = 0;
143
143
  totalChunkCount = 0;
144
144
  currentMessageId = null;
145
+ currentMessageCreatedAt = null;
146
+ streamIdentityCaptured = false;
145
147
  accumulatedContent = "";
146
148
  accumulatedThinking = [];
147
149
  currentThinkingContent = "";
@@ -444,6 +446,8 @@ var TextEngine = class {
444
446
  }
445
447
  async beginIteration() {
446
448
  this.currentMessageId = this.createId("msg");
449
+ this.currentMessageCreatedAt = /* @__PURE__ */ new Date();
450
+ this.streamIdentityCaptured = false;
447
451
  this.accumulatedContent = "";
448
452
  this.accumulatedThinking = [];
449
453
  this.currentThinkingContent = "";
@@ -533,6 +537,9 @@ var TextEngine = class {
533
537
  }
534
538
  handleStreamChunk(chunk) {
535
539
  switch (chunk.type) {
540
+ case "TEXT_MESSAGE_START":
541
+ if (typeof chunk.messageId === "string" && chunk.messageId !== "") this.captureStreamMessageIdentity(chunk.messageId);
542
+ break;
536
543
  case "TEXT_MESSAGE_CONTENT":
537
544
  this.handleTextMessageContentEvent(chunk);
538
545
  break;
@@ -571,7 +578,16 @@ var TextEngine = class {
571
578
  else this.accumulatedContent += chunk.delta;
572
579
  this.middlewareCtx.accumulatedContent = this.accumulatedContent;
573
580
  }
581
+ captureStreamMessageIdentity(messageId) {
582
+ this.currentMessageId = messageId;
583
+ this.middlewareCtx.currentMessageId = messageId;
584
+ if (!this.streamIdentityCaptured) {
585
+ this.currentMessageCreatedAt = /* @__PURE__ */ new Date();
586
+ this.streamIdentityCaptured = true;
587
+ }
588
+ }
574
589
  handleToolCallStartEvent(chunk) {
590
+ if (typeof chunk.parentMessageId === "string" && chunk.parentMessageId !== "") this.captureStreamMessageIdentity(chunk.parentMessageId);
575
591
  this.toolCallManager.addToolCallStartEvent(chunk);
576
592
  }
577
593
  handleToolCallArgsEvent(chunk) {
@@ -808,6 +824,8 @@ var TextEngine = class {
808
824
  role: "assistant",
809
825
  content: this.accumulatedContent || null,
810
826
  toolCalls,
827
+ id: this.currentMessageId ?? void 0,
828
+ createdAt: this.currentMessageCreatedAt ?? void 0,
811
829
  ...this.accumulatedThinking.length > 0 && { thinking: this.accumulatedThinking }
812
830
  }];
813
831
  this.middlewareCtx.messages = this.messages;