@assistant-ui/react 0.10.33 → 0.10.34

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.
@@ -0,0 +1,182 @@
1
+ import { type ComponentType, type FC, PropsWithChildren } from "react";
2
+ import type { Unstable_AudioMessagePartComponent, EmptyMessagePartComponent, TextMessagePartComponent, ImageMessagePartComponent, SourceMessagePartComponent, ToolCallMessagePartComponent, ToolCallMessagePartProps, FileMessagePartComponent, ReasoningMessagePartComponent } from "../../types/MessagePartComponentTypes";
3
+ type MessagePartGroup = {
4
+ groupKey: string | undefined;
5
+ indices: number[];
6
+ };
7
+ export type GroupingFunction = (parts: readonly any[]) => MessagePartGroup[];
8
+ export declare namespace MessagePrimitiveUnstable_PartsGrouped {
9
+ type Props = {
10
+ /**
11
+ * Function that takes an array of message parts and returns an array of groups.
12
+ * Each group contains a key (for identification) and an array of indices.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * // Group by parent ID (default behavior)
17
+ * groupingFunction={(parts) => {
18
+ * const groups = new Map<string, number[]>();
19
+ * parts.forEach((part, i) => {
20
+ * const key = part.parentId ?? `__ungrouped_${i}`;
21
+ * const indices = groups.get(key) ?? [];
22
+ * indices.push(i);
23
+ * groups.set(key, indices);
24
+ * });
25
+ * return Array.from(groups.entries()).map(([key, indices]) => ({
26
+ * key: key.startsWith("__ungrouped_") ? undefined : key,
27
+ * indices
28
+ * }));
29
+ * }}
30
+ * ```
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * // Group by tool name
35
+ * import { groupMessagePartsByToolName } from "@assistant-ui/react";
36
+ *
37
+ * <MessagePrimitive.Unstable_PartsGrouped
38
+ * groupingFunction={groupMessagePartsByToolName}
39
+ * components={{
40
+ * Group: ({ key, indices, children }) => {
41
+ * if (!key) return <>{children}</>;
42
+ * return (
43
+ * <div className="tool-group">
44
+ * <h4>Tool: {key}</h4>
45
+ * {children}
46
+ * </div>
47
+ * );
48
+ * }
49
+ * }}
50
+ * />
51
+ * ```
52
+ */
53
+ groupingFunction: GroupingFunction;
54
+ /**
55
+ * Component configuration for rendering different types of message content.
56
+ *
57
+ * You can provide custom components for each content type (text, image, file, etc.)
58
+ * and configure tool rendering behavior. If not provided, default components will be used.
59
+ */
60
+ components: {
61
+ /** Component for rendering empty messages */
62
+ Empty?: EmptyMessagePartComponent | undefined;
63
+ /** Component for rendering text content */
64
+ Text?: TextMessagePartComponent | undefined;
65
+ /** Component for rendering reasoning content (typically hidden) */
66
+ Reasoning?: ReasoningMessagePartComponent | undefined;
67
+ /** Component for rendering source content */
68
+ Source?: SourceMessagePartComponent | undefined;
69
+ /** Component for rendering image content */
70
+ Image?: ImageMessagePartComponent | undefined;
71
+ /** Component for rendering file content */
72
+ File?: FileMessagePartComponent | undefined;
73
+ /** Component for rendering audio content (experimental) */
74
+ Unstable_Audio?: Unstable_AudioMessagePartComponent | undefined;
75
+ /** Configuration for tool call rendering */
76
+ tools?: {
77
+ /** Map of tool names to their specific components */
78
+ by_name?: Record<string, ToolCallMessagePartComponent | undefined> | undefined;
79
+ /** Fallback component for unregistered tools */
80
+ Fallback?: ComponentType<ToolCallMessagePartProps> | undefined;
81
+ } | {
82
+ /** Override component that handles all tool calls */
83
+ Override: ComponentType<ToolCallMessagePartProps>;
84
+ } | undefined;
85
+ /**
86
+ * Component for rendering grouped message parts.
87
+ *
88
+ * When provided, this component will automatically wrap message parts that share
89
+ * the same group key as determined by the groupingFunction.
90
+ *
91
+ * The component receives:
92
+ * - `groupKey`: The group key (or undefined for ungrouped parts)
93
+ * - `indices`: Array of indices for the parts in this group
94
+ * - `children`: The rendered message part components
95
+ *
96
+ * @example
97
+ * ```tsx
98
+ * // Collapsible group
99
+ * Group: ({ groupKey, indices, children }) => {
100
+ * if (!groupKey) return <>{children}</>;
101
+ * return (
102
+ * <details className="message-group">
103
+ * <summary>
104
+ * Group {groupKey} ({indices.length} parts)
105
+ * </summary>
106
+ * <div className="group-content">
107
+ * {children}
108
+ * </div>
109
+ * </details>
110
+ * );
111
+ * }
112
+ * ```
113
+ *
114
+ * @param groupKey - The group key (undefined for ungrouped parts)
115
+ * @param indices - Array of indices for the parts in this group
116
+ * @param children - Rendered message part components to display within the group
117
+ */
118
+ Group?: ComponentType<PropsWithChildren<{
119
+ groupKey: string | undefined;
120
+ indices: number[];
121
+ }>>;
122
+ } | undefined;
123
+ };
124
+ }
125
+ /**
126
+ * Renders the parts of a message grouped by a custom grouping function.
127
+ *
128
+ * This component allows you to group message parts based on any criteria you define.
129
+ * The grouping function receives all message parts and returns an array of groups,
130
+ * where each group has a key and an array of part indices.
131
+ *
132
+ * @example
133
+ * ```tsx
134
+ * // Group by parent ID (default behavior)
135
+ * <MessagePrimitive.Unstable_PartsGrouped
136
+ * components={{
137
+ * Text: ({ text }) => <p className="message-text">{text}</p>,
138
+ * Image: ({ image }) => <img src={image} alt="Message image" />,
139
+ * Group: ({ groupKey, indices, children }) => {
140
+ * if (!groupKey) return <>{children}</>;
141
+ * return (
142
+ * <div className="parent-group border rounded p-4">
143
+ * <h4>Parent ID: {groupKey}</h4>
144
+ * {children}
145
+ * </div>
146
+ * );
147
+ * }
148
+ * }}
149
+ * />
150
+ * ```
151
+ *
152
+ * @example
153
+ * ```tsx
154
+ * // Group by tool name
155
+ * import { groupMessagePartsByToolName } from "@assistant-ui/react";
156
+ *
157
+ * <MessagePrimitive.Unstable_PartsGrouped
158
+ * groupingFunction={groupMessagePartsByToolName}
159
+ * components={{
160
+ * Group: ({ groupKey, indices, children }) => {
161
+ * if (!groupKey) return <>{children}</>;
162
+ * return (
163
+ * <div className="tool-group">
164
+ * <h4>Tool: {groupKey}</h4>
165
+ * {children}
166
+ * </div>
167
+ * );
168
+ * }
169
+ * }}
170
+ * />
171
+ * ```
172
+ */
173
+ export declare const MessagePrimitiveUnstable_PartsGrouped: FC<MessagePrimitiveUnstable_PartsGrouped.Props>;
174
+ /**
175
+ * Renders the parts of a message grouped by their parent ID.
176
+ * This is a convenience wrapper around Unstable_PartsGrouped with parent ID grouping.
177
+ *
178
+ * @deprecated Use MessagePrimitive.Unstable_PartsGrouped instead for more flexibility
179
+ */
180
+ export declare const MessagePrimitiveUnstable_PartsGroupedByParentId: FC<Omit<MessagePrimitiveUnstable_PartsGrouped.Props, "groupingFunction">>;
181
+ export {};
182
+ //# sourceMappingURL=MessagePartsGrouped.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MessagePartsGrouped.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessagePartsGrouped.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,EAAE,EAEP,iBAAiB,EAElB,MAAM,OAAO,CAAC;AAcf,OAAO,KAAK,EACV,kCAAkC,EAClC,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EACxB,wBAAwB,EACxB,6BAA6B,EAC9B,MAAM,uCAAuC,CAAC;AAI/C,KAAK,gBAAgB,GAAG;IACtB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,EAAE,KAAK,gBAAgB,EAAE,CAAC;AAmD7E,yBAAiB,qCAAqC,CAAC;IACrD,KAAY,KAAK,GAAG;QAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA0CG;QACH,gBAAgB,EAAE,gBAAgB,CAAC;QAEnC;;;;;WAKG;QACH,UAAU,EACN;YACE,6CAA6C;YAC7C,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,2CAA2C;YAC3C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,mEAAmE;YACnE,SAAS,CAAC,EAAE,6BAA6B,GAAG,SAAS,CAAC;YACtD,6CAA6C;YAC7C,MAAM,CAAC,EAAE,0BAA0B,GAAG,SAAS,CAAC;YAChD,4CAA4C;YAC5C,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,2CAA2C;YAC3C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,2DAA2D;YAC3D,cAAc,CAAC,EAAE,kCAAkC,GAAG,SAAS,CAAC;YAChE,4CAA4C;YAC5C,KAAK,CAAC,EACF;gBACE,qDAAqD;gBACrD,OAAO,CAAC,EACJ,MAAM,CAAC,MAAM,EAAE,4BAA4B,GAAG,SAAS,CAAC,GACxD,SAAS,CAAC;gBACd,gDAAgD;gBAChD,QAAQ,CAAC,EAAE,aAAa,CAAC,wBAAwB,CAAC,GAAG,SAAS,CAAC;aAChE,GACD;gBACE,qDAAqD;gBACrD,QAAQ,EAAE,aAAa,CAAC,wBAAwB,CAAC,CAAC;aACnD,GACD,SAAS,CAAC;YAEd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAgCG;YACH,KAAK,CAAC,EAAE,aAAa,CACnB,iBAAiB,CAAC;gBAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;gBAC7B,OAAO,EAAE,MAAM,EAAE,CAAC;aACnB,CAAC,CACH,CAAC;SACH,GACD,SAAS,CAAC;KACf,CAAC;CACH;AA4JD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,eAAO,MAAM,qCAAqC,EAAE,EAAE,CACpD,qCAAqC,CAAC,KAAK,CAgC5C,CAAC;AAKF;;;;;GAKG;AACH,eAAO,MAAM,+CAA+C,EAAE,EAAE,CAC9D,IAAI,CAAC,qCAAqC,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAStE,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- // src/primitives/message/MessagePartsGroupedByParentId.tsx
3
+ // src/primitives/message/MessagePartsGrouped.tsx
4
4
  import {
5
5
  memo,
6
6
  useMemo
@@ -32,19 +32,19 @@ var groupMessagePartsByParentId = (parts) => {
32
32
  }
33
33
  const groups = [];
34
34
  for (const [groupId, indices] of groupMap) {
35
- const parentId = groupId.startsWith("__ungrouped_") ? void 0 : groupId;
36
- groups.push({ parentId, indices });
35
+ const groupKey = groupId.startsWith("__ungrouped_") ? void 0 : groupId;
36
+ groups.push({ groupKey, indices });
37
37
  }
38
38
  return groups;
39
39
  };
40
- var useMessagePartsGroupedByParentId = () => {
40
+ var useMessagePartsGrouped = (groupingFunction) => {
41
41
  const parts = useMessage((m) => m.content);
42
42
  return useMemo(() => {
43
43
  if (parts.length === 0) {
44
44
  return [];
45
45
  }
46
- return groupMessagePartsByParentId(parts);
47
- }, [parts]);
46
+ return groupingFunction(parts);
47
+ }, [parts, groupingFunction]);
48
48
  };
49
49
  var ToolUIDisplay = ({
50
50
  Fallback,
@@ -140,9 +140,9 @@ var EmptyParts = memo(
140
140
  EmptyPartsImpl,
141
141
  (prev, next) => prev.components?.Empty === next.components?.Empty && prev.components?.Text === next.components?.Text
142
142
  );
143
- var MessagePrimitiveUnstable_PartsGroupedByParentId = ({ components }) => {
143
+ var MessagePrimitiveUnstable_PartsGrouped = ({ groupingFunction, components }) => {
144
144
  const contentLength = useMessage((s) => s.content.length);
145
- const messageGroups = useMessagePartsGroupedByParentId();
145
+ const messageGroups = useMessagePartsGrouped(groupingFunction);
146
146
  const partsElements = useMemo(() => {
147
147
  if (contentLength === 0) {
148
148
  return /* @__PURE__ */ jsx(EmptyParts, { components });
@@ -152,7 +152,7 @@ var MessagePrimitiveUnstable_PartsGroupedByParentId = ({ components }) => {
152
152
  return /* @__PURE__ */ jsx(
153
153
  GroupComponent,
154
154
  {
155
- parentId: group.parentId,
155
+ groupKey: group.groupKey,
156
156
  indices: group.indices,
157
157
  children: group.indices.map((partIndex) => /* @__PURE__ */ jsx(
158
158
  MessagePart,
@@ -163,14 +163,26 @@ var MessagePrimitiveUnstable_PartsGroupedByParentId = ({ components }) => {
163
163
  partIndex
164
164
  ))
165
165
  },
166
- `group-${groupIndex}-${group.parentId ?? "ungrouped"}`
166
+ `group-${groupIndex}-${group.groupKey ?? "ungrouped"}`
167
167
  );
168
168
  });
169
169
  }, [messageGroups, components, contentLength]);
170
170
  return /* @__PURE__ */ jsx(Fragment, { children: partsElements });
171
171
  };
172
+ MessagePrimitiveUnstable_PartsGrouped.displayName = "MessagePrimitive.Unstable_PartsGrouped";
173
+ var MessagePrimitiveUnstable_PartsGroupedByParentId = ({ components, ...props }) => {
174
+ return /* @__PURE__ */ jsx(
175
+ MessagePrimitiveUnstable_PartsGrouped,
176
+ {
177
+ ...props,
178
+ components,
179
+ groupingFunction: groupMessagePartsByParentId
180
+ }
181
+ );
182
+ };
172
183
  MessagePrimitiveUnstable_PartsGroupedByParentId.displayName = "MessagePrimitive.Unstable_PartsGroupedByParentId";
173
184
  export {
185
+ MessagePrimitiveUnstable_PartsGrouped,
174
186
  MessagePrimitiveUnstable_PartsGroupedByParentId
175
187
  };
176
- //# sourceMappingURL=MessagePartsGroupedByParentId.js.map
188
+ //# sourceMappingURL=MessagePartsGrouped.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/primitives/message/MessagePartsGrouped.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type FC,\n memo,\n PropsWithChildren,\n useMemo,\n} from \"react\";\nimport {\n TextMessagePartProvider,\n useMessagePart,\n useMessagePartRuntime,\n useToolUIs,\n} from \"../../context\";\nimport {\n useMessage,\n useMessageRuntime,\n} from \"../../context/react/MessageContext\";\nimport { MessagePartRuntimeProvider } from \"../../context/providers/MessagePartRuntimeProvider\";\nimport { MessagePartPrimitiveText } from \"../messagePart/MessagePartText\";\nimport { MessagePartPrimitiveImage } from \"../messagePart/MessagePartImage\";\nimport type {\n Unstable_AudioMessagePartComponent,\n EmptyMessagePartComponent,\n TextMessagePartComponent,\n ImageMessagePartComponent,\n SourceMessagePartComponent,\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n FileMessagePartComponent,\n ReasoningMessagePartComponent,\n} from \"../../types/MessagePartComponentTypes\";\nimport { MessagePartPrimitiveInProgress } from \"../messagePart/MessagePartInProgress\";\nimport { MessagePartStatus } from \"../../types/AssistantTypes\";\n\ntype MessagePartGroup = {\n groupKey: string | undefined;\n indices: number[];\n};\n\nexport type GroupingFunction = (parts: readonly any[]) => MessagePartGroup[];\n\n/**\n * Groups message parts by their parent ID.\n * Parts without a parent ID appear in their chronological position as individual groups.\n * Parts with the same parent ID are grouped together at the position of their first occurrence.\n */\nconst groupMessagePartsByParentId: GroupingFunction = (\n parts: readonly any[],\n): MessagePartGroup[] => {\n // Map maintains insertion order, so groups appear in order of first occurrence\n const groupMap = new Map<string, number[]>();\n\n // Process each part in order\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i];\n const parentId = part?.parentId as string | undefined;\n\n // For parts without parentId, assign a unique group ID to maintain their position\n const groupId = parentId ?? `__ungrouped_${i}`;\n\n // Get or create the indices array for this group\n const indices = groupMap.get(groupId) ?? [];\n indices.push(i);\n groupMap.set(groupId, indices);\n }\n\n // Convert map to array of groups\n const groups: MessagePartGroup[] = [];\n for (const [groupId, indices] of groupMap) {\n // Extract parentId (undefined for ungrouped parts)\n const groupKey = groupId.startsWith(\"__ungrouped_\") ? undefined : groupId;\n groups.push({ groupKey, indices });\n }\n\n return groups;\n};\n\nconst useMessagePartsGrouped = (\n groupingFunction: GroupingFunction,\n): MessagePartGroup[] => {\n const parts = useMessage((m) => m.content);\n\n return useMemo(() => {\n if (parts.length === 0) {\n return [];\n }\n return groupingFunction(parts);\n }, [parts, groupingFunction]);\n};\n\nexport namespace MessagePrimitiveUnstable_PartsGrouped {\n export type Props = {\n /**\n * Function that takes an array of message parts and returns an array of groups.\n * Each group contains a key (for identification) and an array of indices.\n *\n * @example\n * ```tsx\n * // Group by parent ID (default behavior)\n * groupingFunction={(parts) => {\n * const groups = new Map<string, number[]>();\n * parts.forEach((part, i) => {\n * const key = part.parentId ?? `__ungrouped_${i}`;\n * const indices = groups.get(key) ?? [];\n * indices.push(i);\n * groups.set(key, indices);\n * });\n * return Array.from(groups.entries()).map(([key, indices]) => ({\n * key: key.startsWith(\"__ungrouped_\") ? undefined : key,\n * indices\n * }));\n * }}\n * ```\n *\n * @example\n * ```tsx\n * // Group by tool name\n * import { groupMessagePartsByToolName } from \"@assistant-ui/react\";\n *\n * <MessagePrimitive.Unstable_PartsGrouped\n * groupingFunction={groupMessagePartsByToolName}\n * components={{\n * Group: ({ key, indices, children }) => {\n * if (!key) return <>{children}</>;\n * return (\n * <div className=\"tool-group\">\n * <h4>Tool: {key}</h4>\n * {children}\n * </div>\n * );\n * }\n * }}\n * />\n * ```\n */\n groupingFunction: GroupingFunction;\n\n /**\n * Component configuration for rendering different types of message content.\n *\n * You can provide custom components for each content type (text, image, file, etc.)\n * and configure tool rendering behavior. If not provided, default components will be used.\n */\n components:\n | {\n /** Component for rendering empty messages */\n Empty?: EmptyMessagePartComponent | undefined;\n /** Component for rendering text content */\n Text?: TextMessagePartComponent | undefined;\n /** Component for rendering reasoning content (typically hidden) */\n Reasoning?: ReasoningMessagePartComponent | undefined;\n /** Component for rendering source content */\n Source?: SourceMessagePartComponent | undefined;\n /** Component for rendering image content */\n Image?: ImageMessagePartComponent | undefined;\n /** Component for rendering file content */\n File?: FileMessagePartComponent | undefined;\n /** Component for rendering audio content (experimental) */\n Unstable_Audio?: Unstable_AudioMessagePartComponent | undefined;\n /** Configuration for tool call rendering */\n tools?:\n | {\n /** Map of tool names to their specific components */\n by_name?:\n | Record<string, ToolCallMessagePartComponent | undefined>\n | undefined;\n /** Fallback component for unregistered tools */\n Fallback?: ComponentType<ToolCallMessagePartProps> | undefined;\n }\n | {\n /** Override component that handles all tool calls */\n Override: ComponentType<ToolCallMessagePartProps>;\n }\n | undefined;\n\n /**\n * Component for rendering grouped message parts.\n *\n * When provided, this component will automatically wrap message parts that share\n * the same group key as determined by the groupingFunction.\n *\n * The component receives:\n * - `groupKey`: The group key (or undefined for ungrouped parts)\n * - `indices`: Array of indices for the parts in this group\n * - `children`: The rendered message part components\n *\n * @example\n * ```tsx\n * // Collapsible group\n * Group: ({ groupKey, indices, children }) => {\n * if (!groupKey) return <>{children}</>;\n * return (\n * <details className=\"message-group\">\n * <summary>\n * Group {groupKey} ({indices.length} parts)\n * </summary>\n * <div className=\"group-content\">\n * {children}\n * </div>\n * </details>\n * );\n * }\n * ```\n *\n * @param groupKey - The group key (undefined for ungrouped parts)\n * @param indices - Array of indices for the parts in this group\n * @param children - Rendered message part components to display within the group\n */\n Group?: ComponentType<\n PropsWithChildren<{\n groupKey: string | undefined;\n indices: number[];\n }>\n >;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallMessagePartComponent | undefined;\n} & ToolCallMessagePartProps) => {\n const Render = useToolUIs((s) => s.getToolUI(props.toolName)) ?? Fallback;\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <MessagePartPrimitiveText />\n <MessagePartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </MessagePartPrimitiveInProgress>\n </p>\n ),\n Reasoning: () => null,\n Source: () => null,\n Image: () => <MessagePartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n Group: ({ children }) => children,\n} satisfies MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n\ntype MessagePartComponentProps = {\n components: MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n};\n\nconst MessagePartComponent: FC<MessagePartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Reasoning = defaultComponents.Reasoning,\n Image = defaultComponents.Image,\n Source = defaultComponents.Source,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n tools = {},\n } = {},\n}) => {\n const MessagePartRuntime = useMessagePartRuntime();\n\n const part = useMessagePart();\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = (result: any) => MessagePartRuntime.addToolResult(result);\n if (\"Override\" in tools)\n return <tools.Override {...part} addResult={addResult} />;\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return <ToolUIDisplay {...part} Fallback={Tool} addResult={addResult} />;\n }\n\n if (part.status.type === \"requires-action\")\n throw new Error(\"Encountered unexpected requires-action status\");\n\n switch (type) {\n case \"text\":\n return <Text {...part} />;\n\n case \"reasoning\":\n return <Reasoning {...part} />;\n\n case \"source\":\n return <Source {...part} />;\n\n case \"image\":\n // eslint-disable-next-line jsx-a11y/alt-text\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n default:\n const unhandledType: never = type;\n throw new Error(`Unknown message part type: ${unhandledType}`);\n }\n};\n\ntype MessagePartProps = {\n partIndex: number;\n components: MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n};\n\nconst MessagePartImpl: FC<MessagePartProps> = ({ partIndex, components }) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getMessagePartByIndex(partIndex),\n [messageRuntime, partIndex],\n );\n\n return (\n <MessagePartRuntimeProvider runtime={runtime}>\n <MessagePartComponent components={components} />\n </MessagePartRuntimeProvider>\n );\n};\n\nconst MessagePart = memo(\n MessagePartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\n prev.components?.Reasoning === next.components?.Reasoning &&\n prev.components?.Source === next.components?.Source &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.File === next.components?.File &&\n prev.components?.Unstable_Audio === next.components?.Unstable_Audio &&\n prev.components?.tools === next.components?.tools &&\n prev.components?.Group === next.components?.Group,\n);\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyPartFallback: FC<{\n status: MessagePartStatus;\n component: TextMessagePartComponent;\n}> = ({ status, component: Component }) => {\n return (\n <TextMessagePartProvider text=\"\" isRunning={status.type === \"running\"}>\n <Component type=\"text\" text=\"\" status={status} />\n </TextMessagePartProvider>\n );\n};\n\nconst EmptyPartsImpl: FC<MessagePartComponentProps> = ({ components }) => {\n const status =\n useMessage((s) => s.status as MessagePartStatus) ?? COMPLETE_STATUS;\n\n if (components?.Empty) return <components.Empty status={status} />;\n\n return (\n <EmptyPartFallback\n status={status}\n component={components?.Text ?? defaultComponents.Text}\n />\n );\n};\n\nconst EmptyParts = memo(\n EmptyPartsImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\n/**\n * Renders the parts of a message grouped by a custom grouping function.\n *\n * This component allows you to group message parts based on any criteria you define.\n * The grouping function receives all message parts and returns an array of groups,\n * where each group has a key and an array of part indices.\n *\n * @example\n * ```tsx\n * // Group by parent ID (default behavior)\n * <MessagePrimitive.Unstable_PartsGrouped\n * components={{\n * Text: ({ text }) => <p className=\"message-text\">{text}</p>,\n * Image: ({ image }) => <img src={image} alt=\"Message image\" />,\n * Group: ({ groupKey, indices, children }) => {\n * if (!groupKey) return <>{children}</>;\n * return (\n * <div className=\"parent-group border rounded p-4\">\n * <h4>Parent ID: {groupKey}</h4>\n * {children}\n * </div>\n * );\n * }\n * }}\n * />\n * ```\n *\n * @example\n * ```tsx\n * // Group by tool name\n * import { groupMessagePartsByToolName } from \"@assistant-ui/react\";\n *\n * <MessagePrimitive.Unstable_PartsGrouped\n * groupingFunction={groupMessagePartsByToolName}\n * components={{\n * Group: ({ groupKey, indices, children }) => {\n * if (!groupKey) return <>{children}</>;\n * return (\n * <div className=\"tool-group\">\n * <h4>Tool: {groupKey}</h4>\n * {children}\n * </div>\n * );\n * }\n * }}\n * />\n * ```\n */\nexport const MessagePrimitiveUnstable_PartsGrouped: FC<\n MessagePrimitiveUnstable_PartsGrouped.Props\n> = ({ groupingFunction, components }) => {\n const contentLength = useMessage((s) => s.content.length);\n const messageGroups = useMessagePartsGrouped(groupingFunction);\n\n const partsElements = useMemo(() => {\n if (contentLength === 0) {\n return <EmptyParts components={components} />;\n }\n\n return messageGroups.map((group, groupIndex) => {\n const GroupComponent = components?.Group ?? defaultComponents.Group;\n\n return (\n <GroupComponent\n key={`group-${groupIndex}-${group.groupKey ?? \"ungrouped\"}`}\n groupKey={group.groupKey}\n indices={group.indices}\n >\n {group.indices.map((partIndex) => (\n <MessagePart\n key={partIndex}\n partIndex={partIndex}\n components={components}\n />\n ))}\n </GroupComponent>\n );\n });\n }, [messageGroups, components, contentLength]);\n\n return <>{partsElements}</>;\n};\n\nMessagePrimitiveUnstable_PartsGrouped.displayName =\n \"MessagePrimitive.Unstable_PartsGrouped\";\n\n/**\n * Renders the parts of a message grouped by their parent ID.\n * This is a convenience wrapper around Unstable_PartsGrouped with parent ID grouping.\n *\n * @deprecated Use MessagePrimitive.Unstable_PartsGrouped instead for more flexibility\n */\nexport const MessagePrimitiveUnstable_PartsGroupedByParentId: FC<\n Omit<MessagePrimitiveUnstable_PartsGrouped.Props, \"groupingFunction\">\n> = ({ components, ...props }) => {\n return (\n <MessagePrimitiveUnstable_PartsGrouped\n {...props}\n components={components}\n groupingFunction={groupMessagePartsByParentId}\n />\n );\n};\n\nMessagePrimitiveUnstable_PartsGroupedByParentId.displayName =\n \"MessagePrimitive.Unstable_PartsGroupedByParentId\";\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAY1C,SAAS,sCAAsC;AAoMtC,SAkOA,UAlOA,KAKL,YALK;AArLT,IAAM,8BAAgD,CACpD,UACuB;AAEvB,QAAM,WAAW,oBAAI,IAAsB;AAG3C,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ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M,wCAET,CAAC,EAAE,kBAAkB,WAAW,MAAM;AACxC,QAAM,gBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,MAAM;AACxD,QAAM,gBAAgB,uBAAuB,gBAAgB;AAE7D,QAAM,gBAAgB,QAAQ,MAAM;AAClC,QAAI,kBAAkB,GAAG;AACvB,aAAO,oBAAC,cAAW,YAAwB;AAAA,IAC7C;AAEA,WAAO,cAAc,IAAI,CAAC,OAAO,eAAe;AAC9C,YAAM,iBAAiB,YAAY,SAAS,kBAAkB;AAE9D,aACE;AAAA,QAAC;AAAA;AAAA,UAEC,UAAU,MAAM;AAAA,UAChB,SAAS,MAAM;AAAA,UAEd,gBAAM,QAAQ,IAAI,CAAC,cAClB;AAAA,YAAC;AAAA;AAAA,cAEC;AAAA,cACA;AAAA;AAAA,YAFK;AAAA,UAGP,CACD;AAAA;AAAA,QAVI,SAAS,UAAU,IAAI,MAAM,YAAY,WAAW;AAAA,MAW3D;AAAA,IAEJ,CAAC;AAAA,EACH,GAAG,CAAC,eAAe,YAAY,aAAa,CAAC;AAE7C,SAAO,gCAAG,yBAAc;AAC1B;AAEA,sCAAsC,cACpC;AAQK,IAAM,kDAET,CAAC,EAAE,YAAY,GAAG,MAAM,MAAM;AAChC,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA,MACA,kBAAkB;AAAA;AAAA,EACpB;AAEJ;AAEA,gDAAgD,cAC9C;","names":[]}
@@ -4,5 +4,5 @@ export { MessagePrimitiveParts as Content } from "./MessageParts";
4
4
  export { MessagePrimitiveIf as If } from "./MessageIf";
5
5
  export { MessagePrimitiveAttachments as Attachments } from "./MessageAttachments";
6
6
  export { MessagePrimitiveError as Error } from "./MessageError";
7
- export { MessagePrimitiveUnstable_PartsGroupedByParentId as Unstable_PartsGroupedByParentId } from "./MessagePartsGroupedByParentId";
7
+ export { MessagePrimitiveUnstable_PartsGrouped as Unstable_PartsGrouped, MessagePrimitiveUnstable_PartsGroupedByParentId as Unstable_PartsGroupedByParentId, } from "./MessagePartsGrouped";
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,qBAAqB,IAAI,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,qBAAqB,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,kBAAkB,IAAI,EAAE,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,2BAA2B,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,qBAAqB,IAAI,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,+CAA+C,IAAI,+BAA+B,EAAE,MAAM,iCAAiC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,qBAAqB,IAAI,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,qBAAqB,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,kBAAkB,IAAI,EAAE,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,2BAA2B,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,qBAAqB,IAAI,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EACL,qCAAqC,IAAI,qBAAqB,EAC9D,+CAA+C,IAAI,+BAA+B,GACnF,MAAM,uBAAuB,CAAC"}
@@ -5,7 +5,10 @@ import { MessagePrimitiveParts as MessagePrimitiveParts2 } from "./MessageParts.
5
5
  import { MessagePrimitiveIf } from "./MessageIf.js";
6
6
  import { MessagePrimitiveAttachments } from "./MessageAttachments.js";
7
7
  import { MessagePrimitiveError } from "./MessageError.js";
8
- import { MessagePrimitiveUnstable_PartsGroupedByParentId } from "./MessagePartsGroupedByParentId.js";
8
+ import {
9
+ MessagePrimitiveUnstable_PartsGrouped,
10
+ MessagePrimitiveUnstable_PartsGroupedByParentId
11
+ } from "./MessagePartsGrouped.js";
9
12
  export {
10
13
  MessagePrimitiveAttachments as Attachments,
11
14
  MessagePrimitiveParts2 as Content,
@@ -13,6 +16,7 @@ export {
13
16
  MessagePrimitiveIf as If,
14
17
  MessagePrimitiveParts as Parts,
15
18
  MessagePrimitiveRoot as Root,
19
+ MessagePrimitiveUnstable_PartsGrouped as Unstable_PartsGrouped,
16
20
  MessagePrimitiveUnstable_PartsGroupedByParentId as Unstable_PartsGroupedByParentId
17
21
  };
18
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/message/index.ts"],"sourcesContent":["export { MessagePrimitiveRoot as Root } from \"./MessageRoot\";\nexport { MessagePrimitiveParts as Parts } from \"./MessageParts\";\nexport { MessagePrimitiveParts as Content } from \"./MessageParts\";\nexport { MessagePrimitiveIf as If } from \"./MessageIf\";\nexport { MessagePrimitiveAttachments as Attachments } from \"./MessageAttachments\";\nexport { MessagePrimitiveError as Error } from \"./MessageError\";\nexport { MessagePrimitiveUnstable_PartsGroupedByParentId as Unstable_PartsGroupedByParentId } from \"./MessagePartsGroupedByParentId\";\n"],"mappings":";AAAA,SAAiC,4BAAY;AAC7C,SAAkC,6BAAa;AAC/C,SAAkC,yBAAzBA,8BAAwC;AACjD,SAA+B,0BAAU;AACzC,SAAwC,mCAAmB;AAC3D,SAAkC,6BAAa;AAC/C,SAA4D,uDAAuC;","names":["MessagePrimitiveParts"]}
1
+ {"version":3,"sources":["../../../src/primitives/message/index.ts"],"sourcesContent":["export { MessagePrimitiveRoot as Root } from \"./MessageRoot\";\nexport { MessagePrimitiveParts as Parts } from \"./MessageParts\";\nexport { MessagePrimitiveParts as Content } from \"./MessageParts\";\nexport { MessagePrimitiveIf as If } from \"./MessageIf\";\nexport { MessagePrimitiveAttachments as Attachments } from \"./MessageAttachments\";\nexport { MessagePrimitiveError as Error } from \"./MessageError\";\nexport {\n MessagePrimitiveUnstable_PartsGrouped as Unstable_PartsGrouped,\n MessagePrimitiveUnstable_PartsGroupedByParentId as Unstable_PartsGroupedByParentId,\n} from \"./MessagePartsGrouped\";\n"],"mappings":";AAAA,SAAiC,4BAAY;AAC7C,SAAkC,6BAAa;AAC/C,SAAkC,yBAAzBA,8BAAwC;AACjD,SAA+B,0BAAU;AACzC,SAAwC,mCAAmB;AAC3D,SAAkC,6BAAa;AAC/C;AAAA,EAC2C;AAAA,EACU;AAAA,OAC9C;","names":["MessagePrimitiveParts"]}
@@ -115,7 +115,7 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
115
115
  );
116
116
  }
117
117
  if (messages.length > 0) this.ensureInitialized();
118
- if (oldStore?.isRunning ?? false !== store.isRunning ?? false) {
118
+ if ((oldStore?.isRunning ?? false) !== (store.isRunning ?? false)) {
119
119
  if (store.isRunning) {
120
120
  this._notifyEventSubscribers("run-start");
121
121
  } else {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx"],"sourcesContent":["import {\n AddToolResultOptions,\n StartRunConfig,\n ThreadSuggestion,\n} from \"../core/ThreadRuntimeCore\";\n\nimport { AppendMessage, ThreadMessage } from \"../../types\";\nimport { ExternalStoreAdapter } from \"./ExternalStoreAdapter\";\nimport {\n getExternalStoreMessage,\n symbolInnerMessage,\n} from \"./getExternalStoreMessage\";\nimport { ThreadMessageConverter } from \"./ThreadMessageConverter\";\nimport { getAutoStatus, isAutoStatus } from \"./auto-status\";\nimport { fromThreadMessageLike } from \"./ThreadMessageLike\";\nimport { getThreadMessageText } from \"../../utils/getThreadMessageText\";\nimport {\n RuntimeCapabilities,\n ThreadRuntimeCore,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { ModelContextProvider } from \"../../model-context\";\n\nconst EMPTY_ARRAY = Object.freeze([]);\n\nexport const hasUpcomingMessage = (\n isRunning: boolean,\n messages: readonly ThreadMessage[],\n) => {\n return isRunning && messages[messages.length - 1]?.role !== \"assistant\";\n};\n\nexport class ExternalStoreThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n private assistantOptimisticId: string | null = null;\n\n private _capabilities: RuntimeCapabilities = {\n switchToBranch: false,\n edit: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n public get capabilities() {\n return this._capabilities;\n }\n\n private _messages!: readonly ThreadMessage[];\n public isDisabled!: boolean;\n public get isLoading() {\n return this._store.isLoading ?? false;\n }\n\n public override get messages() {\n return this._messages;\n }\n\n public get adapters() {\n return this._store.adapters;\n }\n\n public suggestions: readonly ThreadSuggestion[] = [];\n public extras: unknown = undefined;\n\n private _converter = new ThreadMessageConverter();\n\n private _store!: ExternalStoreAdapter<any>;\n\n public override beginEdit(messageId: string) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing.\");\n\n super.beginEdit(messageId);\n }\n\n constructor(\n contextProvider: ModelContextProvider,\n store: ExternalStoreAdapter<any>,\n ) {\n super(contextProvider);\n this.__internal_setAdapter(store);\n }\n\n public __internal_setAdapter(store: ExternalStoreAdapter<any>) {\n if (this._store === store) return;\n\n const isRunning = store.isRunning ?? false;\n this.isDisabled = store.isDisabled ?? false;\n\n const oldStore = this._store as ExternalStoreAdapter<any> | undefined;\n this._store = store;\n this.extras = store.extras;\n this.suggestions = store.suggestions ?? EMPTY_ARRAY;\n this._capabilities = {\n switchToBranch: this._store.setMessages !== undefined,\n edit: this._store.onEdit !== undefined,\n reload: this._store.onReload !== undefined,\n cancel: this._store.onCancel !== undefined,\n speech: this._store.adapters?.speech !== undefined,\n unstable_copy: this._store.unstable_capabilities?.copy !== false, // default true\n attachments: !!this._store.adapters?.attachments,\n feedback: !!this._store.adapters?.feedback,\n };\n\n let messages: readonly ThreadMessage[];\n\n if (store.messageRepository) {\n // Handle messageRepository\n if (\n oldStore &&\n oldStore.isRunning === store.isRunning &&\n oldStore.messageRepository === store.messageRepository\n ) {\n this._notifySubscribers();\n return;\n }\n\n // Clear and import the message repository\n this.repository.clear();\n this.assistantOptimisticId = null;\n this.repository.import(store.messageRepository);\n\n messages = this.repository.getMessages();\n } else if (store.messages) {\n // Handle messages array\n\n if (oldStore) {\n // flush the converter cache when the convertMessage prop changes\n if (oldStore.convertMessage !== store.convertMessage) {\n this._converter = new ThreadMessageConverter();\n } else if (\n oldStore.isRunning === store.isRunning &&\n oldStore.messages === store.messages\n ) {\n this._notifySubscribers();\n // no conversion update\n return;\n }\n }\n\n messages = !store.convertMessage\n ? store.messages\n : this._converter.convertMessages(store.messages, (cache, m, idx) => {\n if (!store.convertMessage) return m;\n\n const isLast = idx === store.messages!.length - 1;\n const autoStatus = getAutoStatus(isLast, isRunning);\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n )\n return cache;\n\n const messageLike = store.convertMessage(m, idx);\n const newMessage = fromThreadMessageLike(\n messageLike,\n idx.toString(),\n autoStatus,\n );\n (newMessage as any)[symbolInnerMessage] = m;\n return newMessage;\n });\n\n for (let i = 0; i < messages.length; i++) {\n const message = messages[i]!;\n const parent = messages[i - 1];\n this.repository.addOrUpdateMessage(parent?.id ?? null, message);\n }\n } else {\n throw new Error(\n \"ExternalStoreAdapter must provide either 'messages' or 'messageRepository'\",\n );\n }\n\n // Common logic for both paths\n if (messages.length > 0) this.ensureInitialized();\n\n if (oldStore?.isRunning ?? false !== store.isRunning ?? false) {\n if (store.isRunning) {\n this._notifyEventSubscribers(\"run-start\");\n } else {\n this._notifyEventSubscribers(\"run-end\");\n }\n }\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n if (hasUpcomingMessage(isRunning, messages)) {\n this.assistantOptimisticId = this.repository.appendOptimisticMessage(\n messages.at(-1)?.id ?? null,\n {\n role: \"assistant\",\n content: [],\n },\n );\n }\n\n this.repository.resetHead(\n this.assistantOptimisticId ?? messages.at(-1)?.id ?? null,\n );\n\n this._messages = this.repository.getMessages();\n this._notifySubscribers();\n }\n\n public override switchToBranch(branchId: string): void {\n if (!this._store.setMessages)\n throw new Error(\"Runtime does not support switching branches.\");\n\n this.repository.switchToBranch(branchId);\n this.updateMessages(this.repository.getMessages());\n }\n\n public async append(message: AppendMessage): Promise<void> {\n if (message.parentId !== (this.messages.at(-1)?.id ?? null)) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing messages.\");\n await this._store.onEdit(message);\n } else {\n await this._store.onNew(message);\n }\n }\n\n public async startRun(config: StartRunConfig): Promise<void> {\n if (!this._store.onReload)\n throw new Error(\"Runtime does not support reloading messages.\");\n\n await this._store.onReload(config.parentId, config);\n }\n\n public async resumeRun(): Promise<void> {\n throw new Error(\"Runtime does not support resuming runs.\");\n }\n\n public cancelRun(): void {\n if (!this._store.onCancel)\n throw new Error(\"Runtime does not support cancelling runs.\");\n\n this._store.onCancel();\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n let messages = this.repository.getMessages();\n const previousMessage = messages[messages.length - 1];\n if (\n previousMessage?.role === \"user\" &&\n previousMessage.id === messages.at(-1)?.id // ensure the previous message is a leaf node\n ) {\n this.repository.deleteMessage(previousMessage.id);\n if (!this.composer.text.trim()) {\n this.composer.setText(getThreadMessageText(previousMessage));\n }\n\n messages = this.repository.getMessages();\n } else {\n this._notifySubscribers();\n }\n\n // resync messages (for reloading, to restore the previous branch)\n setTimeout(() => {\n this.updateMessages(messages);\n }, 0);\n }\n\n public addToolResult(options: AddToolResultOptions) {\n if (!this._store.onAddToolResult && !this._store.onAddToolResult)\n throw new Error(\"Runtime does not support tool results.\");\n this._store.onAddToolResult?.(options);\n }\n\n private updateMessages = (messages: readonly ThreadMessage[]) => {\n const hasConverter = this._store.convertMessage !== undefined;\n if (hasConverter) {\n this._store.setMessages?.(\n messages.flatMap(getExternalStoreMessage).filter((m) => m != null),\n );\n } else {\n // TODO mark this as readonly in v0.8.0\n this._store.setMessages?.(messages as ThreadMessage[]);\n }\n };\n}\n"],"mappings":";AAQA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AACvC,SAAS,eAAe,oBAAoB;AAC5C,SAAS,6BAA6B;AACtC,SAAS,4BAA4B;AAKrC,SAAS,6BAA6B;AAGtC,IAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AAE7B,IAAM,qBAAqB,CAChC,WACA,aACG;AACH,SAAO,aAAa,SAAS,SAAS,SAAS,CAAC,GAAG,SAAS;AAC9D;AAEO,IAAM,iCAAN,cACG,sBAEV;AAAA,EACU,wBAAuC;AAAA,EAEvC,gBAAqC;AAAA,IAC3C,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEA,IAAW,eAAe;AACxB,WAAO,KAAK;AAAA,EACd;AAAA,EAEQ;AAAA,EACD;AAAA,EACP,IAAW,YAAY;AACrB,WAAO,KAAK,OAAO,aAAa;AAAA,EAClC;AAAA,EAEA,IAAoB,WAAW;AAC7B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,WAAW;AACpB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEO,cAA2C,CAAC;AAAA,EAC5C,SAAkB;AAAA,EAEjB,aAAa,IAAI,uBAAuB;AA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BAAiB,SAAS,UAC1B,gBAAgB,OAAO,SAAS,GAAG,EAAE,GAAG,IACxC;AACA,WAAK,WAAW,cAAc,gBAAgB,EAAE;AAChD,UAAI,CAAC,KAAK,SAAS,KAAK,KAAK,GAAG;AAC9B,aAAK,SAAS,QAAQ,qBAAqB,eAAe,CAAC;AAAA,MAC7D;AAEA,iBAAW,KAAK,WAAW,YAAY;AAAA,IACzC,OAAO;AACL,WAAK,mBAAmB;AAAA,IAC1B;AAGA,eAAW,MAAM;AACf,WAAK,eAAe,QAAQ;AAAA,IAC9B,GAAG,CAAC;AAAA,EACN;AAAA,EAEO,cAAc,SAA+B;AAClD,QAAI,CAAC,KAAK,OAAO,mBAAmB,CAAC,KAAK,OAAO;AAC/C,YAAM,IAAI,MAAM,wCAAwC;AAC1D,SAAK,OAAO,kBAAkB,OAAO;AAAA,EACvC;AAAA,EAEQ,iBAAiB,CAAC,aAAuC;AAC/D,UAAM,eAAe,KAAK,OAAO,mBAAmB;AACpD,QAAI,cAAc;AAChB,WAAK,OAAO;AAAA,QACV,SAAS,QAAQ,uBAAuB,EAAE,OAAO,CAAC,MAAM,KAAK,IAAI;AAAA,MACnE;AAAA,IACF,OAAO;AAEL,WAAK,OAAO,cAAc,QAA2B;AAAA,IACvD;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx"],"sourcesContent":["import {\n AddToolResultOptions,\n StartRunConfig,\n ThreadSuggestion,\n} from \"../core/ThreadRuntimeCore\";\n\nimport { AppendMessage, ThreadMessage } from \"../../types\";\nimport { ExternalStoreAdapter } from \"./ExternalStoreAdapter\";\nimport {\n getExternalStoreMessage,\n symbolInnerMessage,\n} from \"./getExternalStoreMessage\";\nimport { ThreadMessageConverter } from \"./ThreadMessageConverter\";\nimport { getAutoStatus, isAutoStatus } from \"./auto-status\";\nimport { fromThreadMessageLike } from \"./ThreadMessageLike\";\nimport { getThreadMessageText } from \"../../utils/getThreadMessageText\";\nimport {\n RuntimeCapabilities,\n ThreadRuntimeCore,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { ModelContextProvider } from \"../../model-context\";\n\nconst EMPTY_ARRAY = Object.freeze([]);\n\nexport const hasUpcomingMessage = (\n isRunning: boolean,\n messages: readonly ThreadMessage[],\n) => {\n return isRunning && messages[messages.length - 1]?.role !== \"assistant\";\n};\n\nexport class ExternalStoreThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n private assistantOptimisticId: string | null = null;\n\n private _capabilities: RuntimeCapabilities = {\n switchToBranch: false,\n edit: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n public get capabilities() {\n return this._capabilities;\n }\n\n private _messages!: readonly ThreadMessage[];\n public isDisabled!: boolean;\n public get isLoading() {\n return this._store.isLoading ?? false;\n }\n\n public override get messages() {\n return this._messages;\n }\n\n public get adapters() {\n return this._store.adapters;\n }\n\n public suggestions: readonly ThreadSuggestion[] = [];\n public extras: unknown = undefined;\n\n private _converter = new ThreadMessageConverter();\n\n private _store!: ExternalStoreAdapter<any>;\n\n public override beginEdit(messageId: string) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing.\");\n\n super.beginEdit(messageId);\n }\n\n constructor(\n contextProvider: ModelContextProvider,\n store: ExternalStoreAdapter<any>,\n ) {\n super(contextProvider);\n this.__internal_setAdapter(store);\n }\n\n public __internal_setAdapter(store: ExternalStoreAdapter<any>) {\n if (this._store === store) return;\n\n const isRunning = store.isRunning ?? false;\n this.isDisabled = store.isDisabled ?? false;\n\n const oldStore = this._store as ExternalStoreAdapter<any> | undefined;\n this._store = store;\n this.extras = store.extras;\n this.suggestions = store.suggestions ?? EMPTY_ARRAY;\n this._capabilities = {\n switchToBranch: this._store.setMessages !== undefined,\n edit: this._store.onEdit !== undefined,\n reload: this._store.onReload !== undefined,\n cancel: this._store.onCancel !== undefined,\n speech: this._store.adapters?.speech !== undefined,\n unstable_copy: this._store.unstable_capabilities?.copy !== false, // default true\n attachments: !!this._store.adapters?.attachments,\n feedback: !!this._store.adapters?.feedback,\n };\n\n let messages: readonly ThreadMessage[];\n\n if (store.messageRepository) {\n // Handle messageRepository\n if (\n oldStore &&\n oldStore.isRunning === store.isRunning &&\n oldStore.messageRepository === store.messageRepository\n ) {\n this._notifySubscribers();\n return;\n }\n\n // Clear and import the message repository\n this.repository.clear();\n this.assistantOptimisticId = null;\n this.repository.import(store.messageRepository);\n\n messages = this.repository.getMessages();\n } else if (store.messages) {\n // Handle messages array\n\n if (oldStore) {\n // flush the converter cache when the convertMessage prop changes\n if (oldStore.convertMessage !== store.convertMessage) {\n this._converter = new ThreadMessageConverter();\n } else if (\n oldStore.isRunning === store.isRunning &&\n oldStore.messages === store.messages\n ) {\n this._notifySubscribers();\n // no conversion update\n return;\n }\n }\n\n messages = !store.convertMessage\n ? store.messages\n : this._converter.convertMessages(store.messages, (cache, m, idx) => {\n if (!store.convertMessage) return m;\n\n const isLast = idx === store.messages!.length - 1;\n const autoStatus = getAutoStatus(isLast, isRunning);\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n )\n return cache;\n\n const messageLike = store.convertMessage(m, idx);\n const newMessage = fromThreadMessageLike(\n messageLike,\n idx.toString(),\n autoStatus,\n );\n (newMessage as any)[symbolInnerMessage] = m;\n return newMessage;\n });\n\n for (let i = 0; i < messages.length; i++) {\n const message = messages[i]!;\n const parent = messages[i - 1];\n this.repository.addOrUpdateMessage(parent?.id ?? null, message);\n }\n } else {\n throw new Error(\n \"ExternalStoreAdapter must provide either 'messages' or 'messageRepository'\",\n );\n }\n\n // Common logic for both paths\n if (messages.length > 0) this.ensureInitialized();\n\n if ((oldStore?.isRunning ?? false) !== (store.isRunning ?? false)) {\n if (store.isRunning) {\n this._notifyEventSubscribers(\"run-start\");\n } else {\n this._notifyEventSubscribers(\"run-end\");\n }\n }\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n if (hasUpcomingMessage(isRunning, messages)) {\n this.assistantOptimisticId = this.repository.appendOptimisticMessage(\n messages.at(-1)?.id ?? null,\n {\n role: \"assistant\",\n content: [],\n },\n );\n }\n\n this.repository.resetHead(\n this.assistantOptimisticId ?? messages.at(-1)?.id ?? null,\n );\n\n this._messages = this.repository.getMessages();\n this._notifySubscribers();\n }\n\n public override switchToBranch(branchId: string): void {\n if (!this._store.setMessages)\n throw new Error(\"Runtime does not support switching branches.\");\n\n this.repository.switchToBranch(branchId);\n this.updateMessages(this.repository.getMessages());\n }\n\n public async append(message: AppendMessage): Promise<void> {\n if (message.parentId !== (this.messages.at(-1)?.id ?? null)) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing messages.\");\n await this._store.onEdit(message);\n } else {\n await this._store.onNew(message);\n }\n }\n\n public async startRun(config: StartRunConfig): Promise<void> {\n if (!this._store.onReload)\n throw new Error(\"Runtime does not support reloading messages.\");\n\n await this._store.onReload(config.parentId, config);\n }\n\n public async resumeRun(): Promise<void> {\n throw new Error(\"Runtime does not support resuming runs.\");\n }\n\n public cancelRun(): void {\n if (!this._store.onCancel)\n throw new Error(\"Runtime does not support cancelling runs.\");\n\n this._store.onCancel();\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n let messages = this.repository.getMessages();\n const previousMessage = messages[messages.length - 1];\n if (\n previousMessage?.role === \"user\" &&\n previousMessage.id === messages.at(-1)?.id // ensure the previous message is a leaf node\n ) {\n this.repository.deleteMessage(previousMessage.id);\n if (!this.composer.text.trim()) {\n this.composer.setText(getThreadMessageText(previousMessage));\n }\n\n messages = this.repository.getMessages();\n } else {\n this._notifySubscribers();\n }\n\n // resync messages (for reloading, to restore the previous branch)\n setTimeout(() => {\n this.updateMessages(messages);\n }, 0);\n }\n\n public addToolResult(options: AddToolResultOptions) {\n if (!this._store.onAddToolResult && !this._store.onAddToolResult)\n throw new Error(\"Runtime does not support tool results.\");\n this._store.onAddToolResult?.(options);\n }\n\n private updateMessages = (messages: readonly ThreadMessage[]) => {\n const hasConverter = this._store.convertMessage !== undefined;\n if (hasConverter) {\n this._store.setMessages?.(\n messages.flatMap(getExternalStoreMessage).filter((m) => m != null),\n );\n } else {\n // TODO mark this as readonly in v0.8.0\n this._store.setMessages?.(messages as ThreadMessage[]);\n }\n };\n}\n"],"mappings":";AAQA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AACvC,SAAS,eAAe,oBAAoB;AAC5C,SAAS,6BAA6B;AACtC,SAAS,4BAA4B;AAKrC,SAAS,6BAA6B;AAGtC,IAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AAE7B,IAAM,qBAAqB,CAChC,WACA,aACG;AACH,SAAO,aAAa,SAAS,SAAS,SAAS,CAAC,GAAG,SAAS;AAC9D;AAEO,IAAM,iCAAN,cACG,sBAEV;AAAA,EACU,wBAAuC;AAAA,EAEvC,gBAAqC;AAAA,IAC3C,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEA,IAAW,eAAe;AACxB,WAAO,KAAK;AAAA,EACd;AAAA,EAEQ;AAAA,EACD;AAAA,EACP,IAAW,YAAY;AACrB,WAAO,KAAK,OAAO,aAAa;AAAA,EAClC;AAAA,EAEA,IAAoB,WAAW;AAC7B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,WAAW;AACpB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEO,cAA2C,CAAC;AAAA,EAC5C,SAAkB;AAAA,EAEjB,aAAa,IAAI,uBAAuB;AAAA,EAExC;AA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,UAC1B,gBAAgB,OAAO,SAAS,GAAG,EAAE,GAAG,IACxC;AACA,WAAK,WAAW,cAAc,gBAAgB,EAAE;AAChD,UAAI,CAAC,KAAK,SAAS,KAAK,KAAK,GAAG;AAC9B,aAAK,SAAS,QAAQ,qBAAqB,eAAe,CAAC;AAAA,MAC7D;AAEA,iBAAW,KAAK,WAAW,YAAY;AAAA,IACzC,OAAO;AACL,WAAK,mBAAmB;AAAA,IAC1B;AAGA,eAAW,MAAM;AACf,WAAK,eAAe,QAAQ;AAAA,IAC9B,GAAG,CAAC;AAAA,EACN;AAAA,EAEO,cAAc,SAA+B;AAClD,QAAI,CAAC,KAAK,OAAO,mBAAmB,CAAC,KAAK,OAAO;AAC/C,YAAM,IAAI,MAAM,wCAAwC;AAC1D,SAAK,OAAO,kBAAkB,OAAO;AAAA,EACvC;AAAA,EAEQ,iBAAiB,CAAC,aAAuC;AAC/D,UAAM,eAAe,KAAK,OAAO,mBAAmB;AACpD,QAAI,cAAc;AAChB,WAAK,OAAO;AAAA,QACV,SAAS,QAAQ,uBAAuB,EAAE,OAAO,CAAC,MAAM,KAAK,IAAI;AAAA,MACnE;AAAA,IACF,OAAO;AAEL,WAAK,OAAO,cAAc,QAA2B;AAAA,IACvD;AAAA,EACF;AACF;","names":[]}
@@ -1,10 +1,10 @@
1
- // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.0.4_jiti@2.4.2_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
1
+ // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.1.0_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
2
2
  import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers } from "@vitest/expect.js";
3
3
  import { getCurrentTest } from "@vitest/runner.js";
4
4
  import { getNames, getTestName } from "@vitest/runner/utils.js";
5
5
  import * as chai$1 from "chai.js";
6
6
 
7
- // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.0.4_jiti@2.4.2_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/utils.XdZDrNZV.js
7
+ // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.1.0_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/utils.XdZDrNZV.js
8
8
  import { getSafeTimers } from "@vitest/utils.js";
9
9
  var NAME_WORKER_STATE = "__vitest_worker__";
10
10
  function getWorkerState() {
@@ -53,22 +53,22 @@ async function waitForImportsToResolve() {
53
53
  await waitForImportsToResolve();
54
54
  }
55
55
 
56
- // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.0.4_jiti@2.4.2_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
56
+ // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.1.0_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
57
57
  import { getSafeTimers as getSafeTimers2, assertTypes, createSimpleStackTrace } from "@vitest/utils.js";
58
58
 
59
- // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.0.4_jiti@2.4.2_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.js
59
+ // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.1.0_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.js
60
60
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
61
61
  function getDefaultExportFromCjs(x) {
62
62
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
63
63
  }
64
64
 
65
- // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.0.4_jiti@2.4.2_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
65
+ // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.1.0_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
66
66
  import { stripSnapshotIndentation, addSerializer, SnapshotClient } from "@vitest/snapshot.js";
67
67
  import "@vitest/utils/error.js";
68
68
  import { fn, spyOn, mocks, isMockFunction } from "@vitest/spy.js";
69
69
  import { parseSingleStack } from "@vitest/utils/source-map.js";
70
70
 
71
- // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.0.4_jiti@2.4.2_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js
71
+ // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.1.0_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js
72
72
  var RealDate = Date;
73
73
  var now = null;
74
74
  var MockDate = class _MockDate extends RealDate {
@@ -116,7 +116,7 @@ function resetDate() {
116
116
  globalThis.Date = RealDate;
117
117
  }
118
118
 
119
- // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.0.4_jiti@2.4.2_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
119
+ // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.1.0_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
120
120
  var unsupported = [
121
121
  "matchSnapshot",
122
122
  "toMatchSnapshot",
@@ -2800,7 +2800,7 @@ function getImporter(name) {
2800
2800
  return stack?.file || "";
2801
2801
  }
2802
2802
 
2803
- // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.0.4_jiti@2.4.2_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/index.js
2803
+ // ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.1.0_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.3/node_modules/vitest/dist/index.js
2804
2804
  import { expectTypeOf } from "expect-type.js";
2805
2805
  import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from "@vitest/runner.js";
2806
2806
  import * as chai2 from "chai.js";