@assistant-ui/react-ag-ui 0.0.68 → 0.0.70

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.
@@ -30,28 +30,33 @@ export type AgUiMessage = {
30
30
  role: "user";
31
31
  content: string | InputContent[];
32
32
  name?: string;
33
+ metadata?: Record<string, unknown>;
33
34
  } | {
34
35
  id: string;
35
36
  role: "assistant";
36
37
  content: string;
37
38
  name?: string;
38
39
  toolCalls?: AgUiToolCall[];
40
+ metadata?: Record<string, unknown>;
39
41
  } | {
40
42
  id: string;
41
43
  role: "system" | "developer";
42
44
  content: string;
43
45
  name?: string;
46
+ metadata?: Record<string, unknown>;
44
47
  } | {
45
48
  id: string;
46
49
  role: "reasoning";
47
50
  content: string;
48
51
  encryptedValue?: string;
52
+ metadata?: Record<string, unknown>;
49
53
  } | {
50
54
  id: string;
51
55
  role: "tool";
52
56
  content: string;
53
57
  toolCallId: string;
54
58
  error?: string;
59
+ metadata?: Record<string, unknown>;
55
60
  };
56
61
  export type FromAgUiMessagesOptions = {
57
62
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"conversions.d.ts","sourceRoot":"","sources":["../../../src/runtime/adapter/conversions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,KAAK,EACV,iBAAiB,IAAI,qBAAqB,EAG3C,MAAM,oBAAoB,CAAC;AAQ5B,OAAO,EAAE,KAAK,IAAI,EAAqB,MAAM,kBAAkB,CAAC;AAsBhE,YAAY,EAAE,YAAY,EAAE,CAAC;AAE7B,KAAK,cAAc,GAAG;IACpB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,OAAO,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,CAAC;CAC1C,CAAC;AAEF,KAAK,iBAAiB,GAAG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AAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GACD;IACE,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,CAAC;AA61BN,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,OAAO,CAAC,EAAE,uBAAuB,GAChC,qBAAqB,EAAE,CA6YzB;AAuJD,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,SAAS,iBAAiB,EAAE,GACrC,WAAW,EAAE,CAwFf;AAED,KAAK,QAAQ,GAAG,WAAW,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,SAAS,GACtC,QAAQ,EAAE,CASZ"}
@@ -12,6 +12,68 @@ const getString = (record, key) => {
12
12
  const value = record[key];
13
13
  return typeof value === "string" ? value : void 0;
14
14
  };
15
+ function toAgUiWireMetadata(metadata) {
16
+ return isObject(metadata) ? { ...metadata } : void 0;
17
+ }
18
+ function readLegacyAgUiNamespace(metadata) {
19
+ if (!isObject(metadata) || !isObject(metadata.custom)) return {};
20
+ const namespaced = metadata.custom[AG_UI_METADATA_NAMESPACE];
21
+ if (!isObject(namespaced)) return {};
22
+ return "interrupts" in namespaced ? { interrupts: namespaced.interrupts } : {};
23
+ }
24
+ function withoutPersistedInterrupts(wire) {
25
+ if (!isObject(wire.custom)) return wire;
26
+ const namespaced = wire.custom[AG_UI_METADATA_NAMESPACE];
27
+ if (!isObject(namespaced) || !("interrupts" in namespaced)) return wire;
28
+ const { interrupts: _interrupts, ...remainingNamespace } = namespaced;
29
+ const { [AG_UI_METADATA_NAMESPACE]: _namespace, ...remainingCustom } = wire.custom;
30
+ if (Object.keys(remainingNamespace).length > 0) remainingCustom[AG_UI_METADATA_NAMESPACE] = remainingNamespace;
31
+ const { custom: _custom, ...remainingWire } = wire;
32
+ return Object.keys(remainingCustom).length > 0 ? {
33
+ ...remainingWire,
34
+ custom: remainingCustom
35
+ } : remainingWire;
36
+ }
37
+ function toSnapshotCustom(metadata, state = {}) {
38
+ const wire = withoutPersistedInterrupts(toAgUiWireMetadata(metadata) ?? {});
39
+ const needsWireSlot = isObject(metadata) && (Object.keys(metadata).length === 0 || "agui" in wire);
40
+ const namespaced = {
41
+ ...readLegacyAgUiNamespace(metadata),
42
+ ...state,
43
+ ...needsWireSlot ? { messageMetadata: wire } : {}
44
+ };
45
+ return {
46
+ ...wire,
47
+ ...Object.keys(namespaced).length > 0 ? { [AG_UI_METADATA_NAMESPACE]: namespaced } : {}
48
+ };
49
+ }
50
+ function toAgUiMessageMetadata(metadata) {
51
+ const custom = readCustomMetadata(metadata);
52
+ const namespaced = readNamespacedMetadata(metadata);
53
+ if (isObject(namespaced.messageMetadata)) return { ...namespaced.messageMetadata };
54
+ const { [AG_UI_METADATA_NAMESPACE]: _state, ...wire } = custom;
55
+ return Object.keys(wire).length > 0 ? wire : void 0;
56
+ }
57
+ function withAgUiMessageMetadata(metadata) {
58
+ const messageMetadata = toAgUiMessageMetadata(metadata);
59
+ return messageMetadata !== void 0 ? { metadata: messageMetadata } : {};
60
+ }
61
+ function withAgUiPartMessageMetadata(providerMetadata, messageMetadata) {
62
+ if (!messageMetadata) return providerMetadata ?? {};
63
+ const existing = providerMetadata ?? {};
64
+ const namespaced = isObject(existing["agui"]) ? existing[AG_UI_METADATA_NAMESPACE] : {};
65
+ return {
66
+ ...existing,
67
+ [AG_UI_METADATA_NAMESPACE]: {
68
+ ...namespaced,
69
+ messageMetadata
70
+ }
71
+ };
72
+ }
73
+ function readAgUiPartMessageMetadata(providerMetadata) {
74
+ const namespaced = readAgUiNamespace(providerMetadata);
75
+ return namespaced && isObject(namespaced.messageMetadata) ? toAgUiWireMetadata(namespaced.messageMetadata) : void 0;
76
+ }
15
77
  const getToolCallId = (record) => getString(record, "toolCallId") ?? getString(record, "tool_call_id");
16
78
  const readAgUiNamespace = (providerMetadata) => {
17
79
  if (!isObject(providerMetadata)) return void 0;
@@ -23,7 +85,8 @@ const readAgUiReasoningMeta = (providerMetadata) => {
23
85
  if (!namespaced) return {};
24
86
  return {
25
87
  encryptedValue: getString(namespaced, "encryptedValue"),
26
- reasoningId: getString(namespaced, "reasoningId")
88
+ reasoningId: getString(namespaced, "reasoningId"),
89
+ messageMetadata: toAgUiWireMetadata(namespaced.messageMetadata)
27
90
  };
28
91
  };
29
92
  const buildInputMetadata = (part, filename) => {
@@ -356,9 +419,11 @@ function readOpaqueReasoning(metadata) {
356
419
  const id = getString(entry, "id");
357
420
  const encryptedValue = getString(entry, "encryptedValue");
358
421
  if (!id?.trim() || !encryptedValue?.trim()) return [];
422
+ const metadata = toAgUiWireMetadata(entry.metadata);
359
423
  return [{
360
424
  id,
361
425
  encryptedValue,
426
+ ...metadata ? { metadata } : {},
362
427
  ...entry.after === true ? { after: true } : {}
363
428
  }];
364
429
  });
@@ -383,7 +448,8 @@ function withOpaqueReasoning(message, opaqueReasoning) {
383
448
  }
384
449
  function toAssistantSnapshotMessage(rawMessage) {
385
450
  const text = extractText(rawMessage.content);
386
- const interrupts = readPersistedInterrupts(rawMessage.metadata);
451
+ const custom = toSnapshotCustom(rawMessage.metadata);
452
+ const interrupts = readPersistedInterrupts({ custom });
387
453
  const restoredToolCalls = extractAssistantToolCalls(rawMessage);
388
454
  const approvals = projectAgUiToolApprovals(interrupts, new Set(restoredToolCalls.map((part) => part.toolCallId).filter((id) => !!id)));
389
455
  const toolCallParts = restoredToolCalls.map((part) => {
@@ -398,16 +464,23 @@ function toAssistantSnapshotMessage(rawMessage) {
398
464
  text
399
465
  }] : [], ...toolCallParts];
400
466
  const messageName = getString(rawMessage, "name");
467
+ const namespaced = isObject(custom["agui"]) ? { ...custom[AG_UI_METADATA_NAMESPACE] } : {};
468
+ if (interrupts) namespaced.interrupts = interrupts;
469
+ else delete namespaced.interrupts;
470
+ const messageCustom = { ...custom };
471
+ if (Object.keys(namespaced).length > 0) messageCustom[AG_UI_METADATA_NAMESPACE] = namespaced;
472
+ else delete messageCustom[AG_UI_METADATA_NAMESPACE];
401
473
  return {
402
474
  id: getString(rawMessage, "id") ?? generateId(),
403
475
  role: "assistant",
404
476
  content: assistantContent.length > 0 ? assistantContent : "",
405
477
  ...messageName !== void 0 ? { name: messageName } : {},
406
- ...interrupts ? { metadata: { custom: { [AG_UI_METADATA_NAMESPACE]: { interrupts } } } } : {}
478
+ ...Object.keys(messageCustom).length > 0 ? { metadata: { custom: messageCustom } } : {}
407
479
  };
408
480
  }
409
481
  function toUserOrSystemSnapshotMessage(role, rawMessage) {
410
482
  const messageName = getString(rawMessage, "name");
483
+ const custom = toSnapshotCustom(rawMessage.metadata, role === "developer" ? { role: "developer" } : {});
411
484
  const attachments = role === "user" ? toSnapshotAttachments(rawMessage.content) : [];
412
485
  return {
413
486
  id: getString(rawMessage, "id") ?? generateId(),
@@ -415,7 +488,7 @@ function toUserOrSystemSnapshotMessage(role, rawMessage) {
415
488
  content: extractText(rawMessage.content),
416
489
  ...messageName !== void 0 ? { name: messageName } : {},
417
490
  ...attachments.length > 0 ? { attachments } : {},
418
- ...role === "developer" ? { metadata: { custom: { [AG_UI_METADATA_NAMESPACE]: { role: "developer" } } } } : {}
491
+ ...Object.keys(custom).length > 0 ? { metadata: { custom } } : {}
419
492
  };
420
493
  }
421
494
  function attachA2uiSurfaces(message, state) {
@@ -540,6 +613,7 @@ function fromAgUiMessages(messages, options) {
540
613
  const isError = typeof rawMessage.error === "string" || rawMessage.isError === true || rawMessage.status === "error" ? true : rawMessage.isError === false ? false : void 0;
541
614
  const mcpAppUri = readMcpAppResourceUri(mcpResult?._meta);
542
615
  const mcpApp = mcpAppUri !== void 0 ? { resourceUri: mcpAppUri } : void 0;
616
+ const messageMetadata = toAgUiWireMetadata(rawMessage.metadata);
543
617
  let updated = false;
544
618
  for (let messageIndex = converted.length - 1; messageIndex >= 0 && !updated; messageIndex--) {
545
619
  const message = converted[messageIndex];
@@ -554,7 +628,8 @@ function fromAgUiMessages(messages, options) {
554
628
  ...mcpModelContent ? { modelContent: mcpModelContent } : {},
555
629
  ...isError !== void 0 ? { isError } : {},
556
630
  ...toolMessageId !== void 0 ? { unstable_toolMessageId: toolMessageId } : {},
557
- ...mcpApp ? { mcp: { app: mcpApp } } : {}
631
+ ...mcpApp ? { mcp: { app: mcpApp } } : {},
632
+ ...messageMetadata ? { providerMetadata: withAgUiPartMessageMetadata(part.providerMetadata, messageMetadata) } : {}
558
633
  };
559
634
  const updatedContent = message.content.map((contentPart, index) => index === partIndex ? updatedPart : contentPart);
560
635
  converted[messageIndex] = {
@@ -581,7 +656,8 @@ function fromAgUiMessages(messages, options) {
581
656
  ...mcpModelContent ? { modelContent: mcpModelContent } : {},
582
657
  ...isError !== void 0 ? { isError } : {},
583
658
  ...toolMessageId !== void 0 ? { unstable_toolMessageId: toolMessageId } : {},
584
- ...mcpApp ? { mcp: { app: mcpApp } } : {}
659
+ ...mcpApp ? { mcp: { app: mcpApp } } : {},
660
+ ...messageMetadata ? { providerMetadata: withAgUiPartMessageMetadata(void 0, messageMetadata) } : {}
585
661
  }]
586
662
  });
587
663
  continue;
@@ -657,6 +733,7 @@ function fromAgUiMessages(messages, options) {
657
733
  if (role === "reasoning") {
658
734
  const text = extractText(rawMessage.content);
659
735
  const encryptedValue = getString(rawMessage, "encryptedValue");
736
+ const messageMetadata = toAgUiWireMetadata(rawMessage.metadata);
660
737
  if (text.trim().length === 0) {
661
738
  const opaqueId = getString(rawMessage, "id");
662
739
  if (opaqueId?.trim() && encryptedValue?.trim()) {
@@ -664,6 +741,7 @@ function fromAgUiMessages(messages, options) {
664
741
  opaqueReasoning.push({
665
742
  id: opaqueId,
666
743
  encryptedValue,
744
+ ...messageMetadata ? { metadata: messageMetadata } : {},
667
745
  anchor: converted.length
668
746
  });
669
747
  }
@@ -674,6 +752,7 @@ function fromAgUiMessages(messages, options) {
674
752
  if (hiddenId?.trim() && encryptedValue?.trim()) opaqueReasoning.push({
675
753
  id: hiddenId,
676
754
  encryptedValue,
755
+ ...messageMetadata ? { metadata: messageMetadata } : {},
677
756
  anchor: converted.length
678
757
  });
679
758
  continue;
@@ -682,7 +761,8 @@ function fromAgUiMessages(messages, options) {
682
761
  const reasoningId = rawReasoningId?.trim() ? rawReasoningId : void 0;
683
762
  const meta = {
684
763
  ...reasoningId !== void 0 ? { reasoningId } : {},
685
- ...encryptedValue !== void 0 ? { encryptedValue } : {}
764
+ ...encryptedValue !== void 0 ? { encryptedValue } : {},
765
+ ...messageMetadata ? { messageMetadata } : {}
686
766
  };
687
767
  pendingReasoning.push({
688
768
  id: reasoningId,
@@ -744,12 +824,13 @@ function convertAssistantMessage(message, converted) {
744
824
  if (!isObject(part) || part.type !== "reasoning") continue;
745
825
  const text = getString(part, "text") ?? "";
746
826
  if (text.trim().length === 0) continue;
747
- const { encryptedValue, reasoningId } = readAgUiReasoningMeta(part.providerMetadata);
827
+ const { encryptedValue, reasoningId, messageMetadata } = readAgUiReasoningMeta(part.providerMetadata);
748
828
  converted.push({
749
829
  id: reasoningId?.trim() ? reasoningId : shellIsDropped && reasoningIndex === 0 ? message.id : `${message.id}:reasoning-${reasoningIndex}`,
750
830
  role: "reasoning",
751
831
  content: text,
752
- ...encryptedValue !== void 0 ? { encryptedValue } : {}
832
+ ...encryptedValue !== void 0 ? { encryptedValue } : {},
833
+ ...messageMetadata ? { metadata: messageMetadata } : {}
753
834
  });
754
835
  reasoningIndex++;
755
836
  }
@@ -767,6 +848,7 @@ function convertAssistantMessage(message, converted) {
767
848
  role: "assistant",
768
849
  content,
769
850
  ...message.name ? { name: message.name } : {},
851
+ ...withAgUiMessageMetadata(message.metadata),
770
852
  ...toolCalls.length + nestedToolCalls.length > 0 ? { toolCalls: [...toolCalls, ...nestedToolCalls].map((entry) => entry.call) } : {}
771
853
  });
772
854
  for (const { id: toolCallId, part } of toolCalls) emitToolResult(toolCallId, part, converted);
@@ -778,12 +860,14 @@ function convertAssistantMessage(message, converted) {
778
860
  function emitToolResult(toolCallId, part, converted) {
779
861
  if (part.result === void 0) return;
780
862
  const resultContent = part.modelContent !== void 0 ? extractText(part.modelContent) : typeof part.result === "string" ? part.result : JSON.stringify(part.result);
863
+ const messageMetadata = readAgUiPartMessageMetadata(part.providerMetadata);
781
864
  converted.push({
782
865
  id: part.unstable_toolMessageId ?? `${toolCallId}:tool`,
783
866
  role: "tool",
784
867
  content: resultContent,
785
868
  toolCallId,
786
- ...part.isError ? { error: resultContent } : {}
869
+ ...part.isError ? { error: resultContent } : {},
870
+ ...messageMetadata ? { metadata: messageMetadata } : {}
787
871
  });
788
872
  }
789
873
  function convertToolMessage(message, converted) {
@@ -794,7 +878,8 @@ function convertToolMessage(message, converted) {
794
878
  role: "tool",
795
879
  content,
796
880
  toolCallId,
797
- ...typeof message.error === "string" ? { error: message.error } : {}
881
+ ...typeof message.error === "string" ? { error: message.error } : {},
882
+ ...withAgUiMessageMetadata(message.metadata)
798
883
  });
799
884
  }
800
885
  function toAgUiMessages(messages) {
@@ -809,7 +894,8 @@ function toAgUiMessages(messages) {
809
894
  id: entry.id,
810
895
  role: "reasoning",
811
896
  content: "",
812
- encryptedValue: entry.encryptedValue
897
+ encryptedValue: entry.encryptedValue,
898
+ ...entry.metadata ? { metadata: entry.metadata } : {}
813
899
  });
814
900
  for (const entry of opaqueReasoning) if (entry.after !== true) converted.push(toOpaqueRecord(entry));
815
901
  const flushTrailingOpaqueReasoning = () => {
@@ -830,7 +916,8 @@ function toAgUiMessages(messages) {
830
916
  id: message.id,
831
917
  role: "user",
832
918
  content: buildUserContent(message),
833
- ...message.name ? { name: message.name } : {}
919
+ ...message.name ? { name: message.name } : {},
920
+ ...withAgUiMessageMetadata(message.metadata)
834
921
  });
835
922
  flushTrailingOpaqueReasoning();
836
923
  continue;
@@ -843,7 +930,8 @@ function toAgUiMessages(messages) {
843
930
  id: message.id,
844
931
  role: wireRole,
845
932
  content: extractText(message.content),
846
- ...message.name ? { name: message.name } : {}
933
+ ...message.name ? { name: message.name } : {},
934
+ ...withAgUiMessageMetadata(message.metadata)
847
935
  });
848
936
  flushTrailingOpaqueReasoning();
849
937
  continue;
@@ -852,7 +940,8 @@ function toAgUiMessages(messages) {
852
940
  converted.push({
853
941
  id: message.id,
854
942
  role: "reasoning",
855
- content: extractText(message.content)
943
+ content: extractText(message.content),
944
+ ...withAgUiMessageMetadata(message.metadata)
856
945
  });
857
946
  flushTrailingOpaqueReasoning();
858
947
  continue;