@copilotkit/react-core 2.0.0-rc.37 → 2.0.0-rc.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MarkdownRendererContext-BL8ct_3U.d.mts +34 -0
- package/dist/MarkdownRendererContext-BL8ct_3U.d.mts.map +1 -0
- package/dist/MarkdownRendererContext-C2J_lgqF.d.cts +34 -0
- package/dist/MarkdownRendererContext-C2J_lgqF.d.cts.map +1 -0
- package/dist/MarkdownSurfaces-Byz821bg.mjs +324 -0
- package/dist/MarkdownSurfaces-Byz821bg.mjs.map +1 -0
- package/dist/MarkdownSurfaces-D2Ck-cbb.cjs +378 -0
- package/dist/MarkdownSurfaces-D2Ck-cbb.cjs.map +1 -0
- package/dist/{MarkdownSurfaces-BQ1HGCzB.mjs → chat-Bf0vVdo7.mjs} +642 -484
- package/dist/chat-Bf0vVdo7.mjs.map +1 -0
- package/dist/{MarkdownSurfaces-BFoO6wSB.cjs → chat-D3fxo6Ah.cjs} +663 -529
- package/dist/chat-D3fxo6Ah.cjs.map +1 -0
- package/dist/{MarkdownRendererContext-CPfNVyde.d.mts → chat-DgP2N7bD.d.mts} +31 -39
- package/dist/chat-DgP2N7bD.d.mts.map +1 -0
- package/dist/{MarkdownRendererContext-iOl2pj9l.d.cts → chat-DtHs4alO.d.cts} +31 -39
- package/dist/chat-DtHs4alO.d.cts.map +1 -0
- package/dist/generative-ui/native.cjs +66 -0
- package/dist/generative-ui/native.cjs.map +1 -0
- package/dist/generative-ui/native.d.cts +155 -0
- package/dist/generative-ui/native.d.cts.map +1 -0
- package/dist/generative-ui/native.d.mts +155 -0
- package/dist/generative-ui/native.d.mts.map +1 -0
- package/dist/generative-ui/native.mjs +24 -0
- package/dist/generative-ui/native.mjs.map +1 -0
- package/dist/generative-ui.cjs +45 -70
- package/dist/generative-ui.cjs.map +1 -1
- package/dist/generative-ui.d.cts +72 -144
- package/dist/generative-ui.d.cts.map +1 -1
- package/dist/generative-ui.d.mts +72 -144
- package/dist/generative-ui.d.mts.map +1 -1
- package/dist/generative-ui.mjs +4 -29
- package/dist/generative-ui.mjs.map +1 -1
- package/dist/headless.d.cts +58 -153
- package/dist/headless.d.cts.map +1 -1
- package/dist/hooks-2Ur8NQhj.d.cts +84 -0
- package/dist/hooks-2Ur8NQhj.d.cts.map +1 -0
- package/dist/hooks-BRYonCVu.d.mts +84 -0
- package/dist/hooks-BRYonCVu.d.mts.map +1 -0
- package/dist/index.cjs +82 -430
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -353
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +645 -140
- package/dist/index.umd.js.map +1 -1
- package/dist/refs-BIUfn1wb.cjs +43 -0
- package/dist/refs-BIUfn1wb.cjs.map +1 -0
- package/dist/refs-CMrRm3ta.mjs +31 -0
- package/dist/refs-CMrRm3ta.mjs.map +1 -0
- package/dist/use-generative-ui-root-C12htqbK.cjs +390 -0
- package/dist/use-generative-ui-root-C12htqbK.cjs.map +1 -0
- package/dist/use-generative-ui-root-CVgsDy1f.mjs +385 -0
- package/dist/use-generative-ui-root-CVgsDy1f.mjs.map +1 -0
- package/package.json +14 -10
- package/dist/MarkdownRendererContext-CPfNVyde.d.mts.map +0 -1
- package/dist/MarkdownRendererContext-iOl2pj9l.d.cts.map +0 -1
- package/dist/MarkdownSurfaces-BFoO6wSB.cjs.map +0 -1
- package/dist/MarkdownSurfaces-BQ1HGCzB.mjs.map +0 -1
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
const require_chat = require('./chat-D3fxo6Ah.cjs');
|
|
2
|
+
let _copilotkit_core = require("@copilotkit/core");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
react = require_chat.__toESM(react);
|
|
5
|
+
let _copilotkit_markdown_react = require("@copilotkit/markdown/react");
|
|
6
|
+
let _copilotkit_markdown = require("@copilotkit/markdown");
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
let _copilotkit_shared = require("@copilotkit/shared");
|
|
9
|
+
let _copilotkit_core_generative_ui = require("@copilotkit/core/generative-ui");
|
|
10
|
+
|
|
11
|
+
//#region src/components/chat/StreamingMarkdownDefaultRenderer.tsx
|
|
12
|
+
/**
|
|
13
|
+
* react-core's built-in default markdown renderer — a thin adapter over
|
|
14
|
+
* `@copilotkit/markdown`'s streaming renderer. Maps the pluggable
|
|
15
|
+
* renderer contract (`{ content, isStreaming, className }`) onto the streaming
|
|
16
|
+
* renderer for streaming-safe incremental rendering + per-token animation.
|
|
17
|
+
* Still overridable via the slot/provider pluggable interface.
|
|
18
|
+
*/
|
|
19
|
+
function StreamingMarkdownDefaultRenderer({ content, isStreaming, className, nodeRenderers, caret, options, onLinkClick, onCitationClick }) {
|
|
20
|
+
if (!content) return null;
|
|
21
|
+
(0, _copilotkit_markdown.warnUnsupportedRichSyntaxOnce)(content);
|
|
22
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_copilotkit_markdown_react.StreamingMarkdownRenderer, {
|
|
23
|
+
className,
|
|
24
|
+
isComplete: !isStreaming,
|
|
25
|
+
caret: caret ?? !!isStreaming,
|
|
26
|
+
nodeRenderers,
|
|
27
|
+
nodeClassNames: _copilotkit_markdown.CHAT_MARKDOWN_NODE_CLASS_NAMES,
|
|
28
|
+
options,
|
|
29
|
+
onLinkClick,
|
|
30
|
+
onCitationClick,
|
|
31
|
+
children: content
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
StreamingMarkdownDefaultRenderer.displayName = "StreamingMarkdownDefaultRenderer";
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/components/icons/CopilotIcon.tsx
|
|
38
|
+
/** Turns SVG attribute names such as `stroke-width` into React's `strokeWidth`. */
|
|
39
|
+
function toReactAttributes(attributes) {
|
|
40
|
+
return Object.fromEntries(Object.entries(attributes).map(([key, value]) => [key.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase()), value]));
|
|
41
|
+
}
|
|
42
|
+
const svgDefaults = toReactAttributes(_copilotkit_core.ɵcopilotIconSvgAttributes);
|
|
43
|
+
/** True when the props give the icon an accessible name or role. */
|
|
44
|
+
function hasAccessibleProp(props) {
|
|
45
|
+
return Object.keys(props).some((key) => key.startsWith("aria-") || key === "role" || key === "title");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Internal. Draws a Lucide icon from its node data, the way Lucide's React package
|
|
49
|
+
* does: Lucide's default SVG attributes, the `lucide lucide-<name>` classes,
|
|
50
|
+
* and `aria-hidden="true"` when no `aria-*`, `role` or `title` prop names it.
|
|
51
|
+
*/
|
|
52
|
+
const IconSvg = (0, react.forwardRef)(function IconSvg({ lucideName, nodes, size = 24, color = "currentColor", strokeWidth = 2, className, children, ...props }, ref) {
|
|
53
|
+
const isDecorative = !children && !hasAccessibleProp(props);
|
|
54
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
55
|
+
ref,
|
|
56
|
+
...svgDefaults,
|
|
57
|
+
width: size,
|
|
58
|
+
height: size,
|
|
59
|
+
stroke: color,
|
|
60
|
+
strokeWidth,
|
|
61
|
+
className: (0, _copilotkit_core.ɵcn)("lucide", `lucide-${lucideName}`, className),
|
|
62
|
+
"aria-hidden": isDecorative || void 0,
|
|
63
|
+
...props,
|
|
64
|
+
children: [nodes.map((node, index) => (0, react.createElement)(node.tag, {
|
|
65
|
+
key: index,
|
|
66
|
+
...node.attributes
|
|
67
|
+
})), children]
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* Draws one of the chat icons as an inline `<svg>`.
|
|
72
|
+
*
|
|
73
|
+
* The `<svg>` has the classes `lucide lucide-<icon name>`, so CSS that selects
|
|
74
|
+
* them (for example `svg.lucide-arrow-up`) keeps working. The icon is hidden
|
|
75
|
+
* from screen readers unless you give it an `aria-label`, `role` or `title`.
|
|
76
|
+
*
|
|
77
|
+
* @param props.name - The chat icon, for example `"ArrowUp"` or `"X"`.
|
|
78
|
+
* @param props.size - Width and height. Defaults to `24`.
|
|
79
|
+
* @param props.strokeWidth - Line width. Defaults to `2`.
|
|
80
|
+
* @param props.color - Line color. Defaults to `currentColor`.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* <CopilotIcon name="ArrowUp" className="cpk-chat-input-send-icon" />
|
|
85
|
+
* <CopilotIcon name="X" aria-label="Close" />
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
const CopilotIcon = (0, react.forwardRef)(function CopilotIcon({ name, ...props }, ref) {
|
|
89
|
+
const icon = _copilotkit_core.ɵcopilotIcons[name];
|
|
90
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconSvg, {
|
|
91
|
+
ref,
|
|
92
|
+
lucideName: icon.name,
|
|
93
|
+
nodes: icon.nodes,
|
|
94
|
+
...props
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/lib/slots.tsx
|
|
100
|
+
/**
|
|
101
|
+
* Check if a value is a React component type (function, class, forwardRef, memo, etc.)
|
|
102
|
+
*/
|
|
103
|
+
function isReactComponentType(value) {
|
|
104
|
+
if (typeof value === "function") return true;
|
|
105
|
+
if (value && typeof value === "object" && "$$typeof" in value && !react.default.isValidElement(value)) return true;
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Internal function to render a slot value as a React element (non-memoized).
|
|
110
|
+
*/
|
|
111
|
+
function renderSlotElement(slot, DefaultComponent, props) {
|
|
112
|
+
if (typeof slot === "string") {
|
|
113
|
+
const existingClassName = props.className;
|
|
114
|
+
return react.default.createElement(DefaultComponent, {
|
|
115
|
+
...props,
|
|
116
|
+
className: (0, _copilotkit_core.ɵcn)(existingClassName, slot)
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (isReactComponentType(slot)) return react.default.createElement(slot, props);
|
|
120
|
+
if (slot && typeof slot === "object" && !react.default.isValidElement(slot)) return react.default.createElement(DefaultComponent, {
|
|
121
|
+
...props,
|
|
122
|
+
...slot
|
|
123
|
+
});
|
|
124
|
+
return react.default.createElement(DefaultComponent, props);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Internal memoized wrapper component for renderSlot.
|
|
128
|
+
* Uses forwardRef to support ref forwarding.
|
|
129
|
+
*/
|
|
130
|
+
const MemoizedSlotWrapper = react.default.memo(react.default.forwardRef(function MemoizedSlotWrapper(props, ref) {
|
|
131
|
+
const { $slot, $component, ...rest } = props;
|
|
132
|
+
return renderSlotElement($slot, $component, ref !== null ? {
|
|
133
|
+
...rest,
|
|
134
|
+
ref
|
|
135
|
+
} : rest);
|
|
136
|
+
}), (prev, next) => {
|
|
137
|
+
if (prev.$slot !== next.$slot) return false;
|
|
138
|
+
if (prev.$component !== next.$component) return false;
|
|
139
|
+
const { $slot: _ps, $component: _pc, ...prevRest } = prev;
|
|
140
|
+
const { $slot: _ns, $component: _nc, ...nextRest } = next;
|
|
141
|
+
return require_chat.shallowEqual(prevRest, nextRest);
|
|
142
|
+
});
|
|
143
|
+
/**
|
|
144
|
+
* Renders a slot value as a memoized React element.
|
|
145
|
+
* Automatically prevents unnecessary re-renders using shallow prop comparison.
|
|
146
|
+
* Supports ref forwarding.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* renderSlot(customInput, CopilotChatInput, { onSubmit: handleSubmit })
|
|
150
|
+
*/
|
|
151
|
+
function renderSlot(slot, DefaultComponent, props) {
|
|
152
|
+
return react.default.createElement(MemoizedSlotWrapper, {
|
|
153
|
+
...props,
|
|
154
|
+
$slot: slot,
|
|
155
|
+
$component: DefaultComponent
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/providers/MarkdownRendererContext.tsx
|
|
161
|
+
const MarkdownRendererContext = (0, react.createContext)(void 0);
|
|
162
|
+
const MarkdownRendererProvider = ({ renderer, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MarkdownRendererContext.Provider, {
|
|
163
|
+
value: renderer,
|
|
164
|
+
children
|
|
165
|
+
});
|
|
166
|
+
/**
|
|
167
|
+
* The markdown renderer set at the provider level, or `undefined` when none was
|
|
168
|
+
* supplied. Message components fall back to the built-in
|
|
169
|
+
* `StreamingMarkdownDefaultRenderer` (via `CopilotChatAssistantMessage.MarkdownRenderer`)
|
|
170
|
+
* when this is `undefined`.
|
|
171
|
+
*/
|
|
172
|
+
function useMarkdownRenderer() {
|
|
173
|
+
return (0, react.useContext)(MarkdownRendererContext);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/generative-ui/markdown/ProviderMarkdown.tsx
|
|
178
|
+
/**
|
|
179
|
+
* Markdown prose inside generative UI, rendered like the chat text around
|
|
180
|
+
* it: the renderer set on the provider when there is one, else the built-in
|
|
181
|
+
* streaming renderer. Config passed here wins over provider config.
|
|
182
|
+
*/
|
|
183
|
+
function ProviderMarkdown({ content, isStreaming, className, ...config }) {
|
|
184
|
+
const renderer = useMarkdownRenderer();
|
|
185
|
+
if (renderer && isReactComponentType(renderer)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(renderer, {
|
|
186
|
+
content,
|
|
187
|
+
isStreaming,
|
|
188
|
+
className
|
|
189
|
+
});
|
|
190
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamingMarkdownDefaultRenderer, {
|
|
191
|
+
...renderer,
|
|
192
|
+
...config,
|
|
193
|
+
content,
|
|
194
|
+
isStreaming,
|
|
195
|
+
className
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/generative-ui/markdown/MarkdownSurfaces.tsx
|
|
201
|
+
const FADE_STYLE_ID = "a2ui-markdown-fade";
|
|
202
|
+
/**
|
|
203
|
+
* Components fade in as they stream: each element that appears under a
|
|
204
|
+
* markdown surface runs the keyframes once on mount. React keeps the keys
|
|
205
|
+
* stable per component id, so an element that is already there never
|
|
206
|
+
* animates again. SVG internals are left out: a chart library re-creates
|
|
207
|
+
* its nodes on each render, and a fade on each of them would read as the
|
|
208
|
+
* chart flashing whenever a sibling arrives. The fade runs under reduced
|
|
209
|
+
* motion too, because it moves nothing.
|
|
210
|
+
*/
|
|
211
|
+
const FADE_CSS = ["@keyframes a2ui-fade-in{from{opacity:0}}", "[data-a2ui-markdown-surface] .a2ui-surface *:not(svg):not(svg *){animation:a2ui-fade-in .35s ease-out backwards}"].join("\n");
|
|
212
|
+
const noEffect = () => {};
|
|
213
|
+
const useInjectEffect = typeof document === "undefined" ? noEffect : react.useInsertionEffect;
|
|
214
|
+
function useFadeStyles() {
|
|
215
|
+
useInjectEffect(() => {
|
|
216
|
+
if (document.getElementById(FADE_STYLE_ID)) return;
|
|
217
|
+
const style = document.createElement("style");
|
|
218
|
+
style.id = FADE_STYLE_ID;
|
|
219
|
+
style.textContent = FADE_CSS;
|
|
220
|
+
document.head.appendChild(style);
|
|
221
|
+
}, []);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* The default wrapper of a chat surface in the markdown transport. It draws
|
|
225
|
+
* no box: a surface sits in the flow of the reply like a paragraph, and a
|
|
226
|
+
* Card draws its own box when it is interactive. Nothing shows while the
|
|
227
|
+
* surface streams. A rejected operation gets one line.
|
|
228
|
+
*/
|
|
229
|
+
function DefaultMarkdownChatSurface({ surfaceId, error, children }) {
|
|
230
|
+
useFadeStyles();
|
|
231
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
232
|
+
"data-generative-ui-chat-surface": surfaceId,
|
|
233
|
+
"data-a2ui-markdown-surface": surfaceId,
|
|
234
|
+
className: "cpk-markdown-chat-surface",
|
|
235
|
+
children: [children, error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
236
|
+
role: "alert",
|
|
237
|
+
className: "cpk-markdown-chat-surface-error",
|
|
238
|
+
children: "Part of this UI couldn't be shown."
|
|
239
|
+
})]
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* One chat surface in the chat wrapper. Nothing renders until the surface
|
|
244
|
+
* has its root component, so a half-streamed fence shows no empty card.
|
|
245
|
+
*/
|
|
246
|
+
function ChatSurface({ runtime, threadId, surfaceId, Wrapper }) {
|
|
247
|
+
const surface = runtime.manager.getSurface(threadId, surfaceId) ?? runtime.manager.getFailedSurface(threadId, surfaceId);
|
|
248
|
+
const root = surface?.model.componentsModel.get(_copilotkit_shared.GENERATIVE_UI_ROOT_ID);
|
|
249
|
+
if (!surface || !root && !surface.failed) return null;
|
|
250
|
+
const rejected = [...surface.serverRejected, ...surface.clientRejected];
|
|
251
|
+
const error = rejected.length ? new Error(`${rejected.length} UI update(s) could not be shown`, { cause: rejected }) : void 0;
|
|
252
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Wrapper, {
|
|
253
|
+
surfaceId,
|
|
254
|
+
isStreaming: surface.status === "streaming",
|
|
255
|
+
error,
|
|
256
|
+
rejected,
|
|
257
|
+
children: surface.failed ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_chat.SurfaceView, { surface })
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
/** The blocks of one fence: lifted prose and chat surfaces, in order. */
|
|
261
|
+
function FenceBlocks({ blocks, runtime, threadId, isStreaming, markdownProps }) {
|
|
262
|
+
const Wrapper = (0, react.useContext)(require_chat.GenerativeUIChatSlotContext) ?? DefaultMarkdownChatSurface;
|
|
263
|
+
let surfaceCount = 0;
|
|
264
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: blocks.map((block, index) => {
|
|
265
|
+
if (block.kind === "markdown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProviderMarkdown, {
|
|
266
|
+
...markdownProps,
|
|
267
|
+
content: block.markdown,
|
|
268
|
+
isStreaming: isStreaming && index === blocks.length - 1
|
|
269
|
+
}, `md-${surfaceCount}`);
|
|
270
|
+
surfaceCount++;
|
|
271
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChatSurface, {
|
|
272
|
+
runtime,
|
|
273
|
+
threadId,
|
|
274
|
+
surfaceId: block.surfaceId,
|
|
275
|
+
Wrapper
|
|
276
|
+
}, block.surfaceId);
|
|
277
|
+
}) });
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Experimental. Renders an assistant message of the markdown transport.
|
|
281
|
+
* Prose renders as markdown. In place of each ```a2ui fence:
|
|
282
|
+
*
|
|
283
|
+
* - the fence that created a chat surface renders that surface (and the
|
|
284
|
+
* prose lifted out of it) in the chat wrapper;
|
|
285
|
+
* - every other fence renders nothing: a fence that updates the surface of
|
|
286
|
+
* an earlier fence, or a fence for a named target, which
|
|
287
|
+
* `<GenerativeUISurface id>` renders.
|
|
288
|
+
*
|
|
289
|
+
* Use it inside `<CopilotKitProvider generativeUI={{ ui, transport: "markdown" }}>`.
|
|
290
|
+
* `CopilotChatAssistantMessage` uses it there on its own.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```tsx
|
|
294
|
+
* <MarkdownSurfaces content={message.content} messageId={message.id} />
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
function MarkdownSurfaces({ content, messageId, isStreaming = false, ...markdownProps }) {
|
|
298
|
+
const runtime = require_chat.useRequiredGenerativeUIRuntime();
|
|
299
|
+
const chatThreadId = require_chat.useCopilotChatConfiguration()?.threadId;
|
|
300
|
+
require_chat.useManagerVersion(runtime);
|
|
301
|
+
const segments = (0, react.useMemo)(() => (0, _copilotkit_core.splitA2UIMarkdown)(content), [content]);
|
|
302
|
+
const threadId = chatThreadId ?? runtime.manager.getActiveThread();
|
|
303
|
+
const source = (0, _copilotkit_core_generative_ui.getMarkdownSurfaceSource)(runtime);
|
|
304
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: segments.map((segment, index) => {
|
|
305
|
+
const isLast = index === segments.length - 1;
|
|
306
|
+
if (segment.type === "markdown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProviderMarkdown, {
|
|
307
|
+
...markdownProps,
|
|
308
|
+
content: segment.text,
|
|
309
|
+
isStreaming: isStreaming && isLast
|
|
310
|
+
}, `md-${index}`);
|
|
311
|
+
const blocks = threadId ? source.getFenceBlocks(threadId, messageId, segment.index) : void 0;
|
|
312
|
+
if (!threadId || !blocks) return null;
|
|
313
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FenceBlocks, {
|
|
314
|
+
blocks,
|
|
315
|
+
runtime,
|
|
316
|
+
threadId,
|
|
317
|
+
isStreaming: isStreaming && isLast,
|
|
318
|
+
markdownProps
|
|
319
|
+
}, `a2ui-${segment.index}`);
|
|
320
|
+
}) });
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
//#endregion
|
|
324
|
+
Object.defineProperty(exports, 'CopilotIcon', {
|
|
325
|
+
enumerable: true,
|
|
326
|
+
get: function () {
|
|
327
|
+
return CopilotIcon;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
Object.defineProperty(exports, 'IconSvg', {
|
|
331
|
+
enumerable: true,
|
|
332
|
+
get: function () {
|
|
333
|
+
return IconSvg;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
Object.defineProperty(exports, 'MarkdownRendererProvider', {
|
|
337
|
+
enumerable: true,
|
|
338
|
+
get: function () {
|
|
339
|
+
return MarkdownRendererProvider;
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
Object.defineProperty(exports, 'MarkdownSurfaces', {
|
|
343
|
+
enumerable: true,
|
|
344
|
+
get: function () {
|
|
345
|
+
return MarkdownSurfaces;
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
Object.defineProperty(exports, 'ProviderMarkdown', {
|
|
349
|
+
enumerable: true,
|
|
350
|
+
get: function () {
|
|
351
|
+
return ProviderMarkdown;
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
Object.defineProperty(exports, 'StreamingMarkdownDefaultRenderer', {
|
|
355
|
+
enumerable: true,
|
|
356
|
+
get: function () {
|
|
357
|
+
return StreamingMarkdownDefaultRenderer;
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
Object.defineProperty(exports, 'isReactComponentType', {
|
|
361
|
+
enumerable: true,
|
|
362
|
+
get: function () {
|
|
363
|
+
return isReactComponentType;
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
Object.defineProperty(exports, 'renderSlot', {
|
|
367
|
+
enumerable: true,
|
|
368
|
+
get: function () {
|
|
369
|
+
return renderSlot;
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
Object.defineProperty(exports, 'useMarkdownRenderer', {
|
|
373
|
+
enumerable: true,
|
|
374
|
+
get: function () {
|
|
375
|
+
return useMarkdownRenderer;
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
//# sourceMappingURL=MarkdownSurfaces-D2Ck-cbb.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkdownSurfaces-D2Ck-cbb.cjs","names":["StreamingMarkdownRenderer","CHAT_MARKDOWN_NODE_CLASS_NAMES","ɵcopilotIconSvgAttributes","ɵcopilotIcons","React","shallowEqual","useInsertionEffect","GENERATIVE_UI_ROOT_ID","SurfaceView","GenerativeUIChatSlotContext","useRequiredGenerativeUIRuntime","useCopilotChatConfiguration"],"sources":["../src/components/chat/StreamingMarkdownDefaultRenderer.tsx","../src/components/icons/CopilotIcon.tsx","../src/lib/slots.tsx","../src/providers/MarkdownRendererContext.tsx","../src/generative-ui/markdown/ProviderMarkdown.tsx","../src/generative-ui/markdown/MarkdownSurfaces.tsx"],"sourcesContent":["\"use client\";\n\nimport React from \"react\";\nimport { StreamingMarkdownRenderer } from \"@copilotkit/markdown/react\";\nimport {\n CHAT_MARKDOWN_NODE_CLASS_NAMES,\n warnUnsupportedRichSyntaxOnce,\n} from \"@copilotkit/markdown\";\nimport type {\n DefaultMarkdownRendererProps,\n MarkdownRendererProps,\n} from \"../../providers/MarkdownRendererContext\";\n\n/**\n * react-core's built-in default markdown renderer — a thin adapter over\n * `@copilotkit/markdown`'s streaming renderer. Maps the pluggable\n * renderer contract (`{ content, isStreaming, className }`) onto the streaming\n * renderer for streaming-safe incremental rendering + per-token animation.\n * Still overridable via the slot/provider pluggable interface.\n */\nexport function StreamingMarkdownDefaultRenderer({\n content,\n isStreaming,\n className,\n nodeRenderers,\n caret,\n options,\n onLinkClick,\n onCitationClick,\n}: MarkdownRendererProps & DefaultMarkdownRendererProps) {\n if (!content) return null;\n // Dev-only: nudge upgraders from the bundled Streamdown default when their\n // content needs math/syntax highlighting the built-in renderer doesn't do.\n warnUnsupportedRichSyntaxOnce(content);\n return (\n <StreamingMarkdownRenderer\n className={className}\n isComplete={!isStreaming}\n caret={caret ?? !!isStreaming}\n nodeRenderers={nodeRenderers}\n nodeClassNames={CHAT_MARKDOWN_NODE_CLASS_NAMES}\n options={options}\n onLinkClick={onLinkClick}\n onCitationClick={onCitationClick}\n >\n {content}\n </StreamingMarkdownRenderer>\n );\n}\n\nStreamingMarkdownDefaultRenderer.displayName =\n \"StreamingMarkdownDefaultRenderer\";\n","import React, { createElement, forwardRef } from \"react\";\nimport { ɵcopilotIcons, ɵcopilotIconSvgAttributes } from \"@copilotkit/core\";\nimport type { CopilotIconName } from \"@copilotkit/core\";\nimport { cn } from \"../../lib/utils\";\n\n/** One SVG child element of an icon, such as a `<path>` or a `<circle>`. */\nexport interface IconSvgNode {\n readonly tag: string;\n readonly attributes: Readonly<Record<string, string | number>>;\n}\n\n/** Turns SVG attribute names such as `stroke-width` into React's `strokeWidth`. */\nfunction toReactAttributes(attributes: Readonly<Record<string, string>>) {\n return Object.fromEntries(\n Object.entries(attributes).map(([key, value]) => [\n key.replace(/-([a-z])/g, (_match, letter: string) =>\n letter.toUpperCase(),\n ),\n value,\n ]),\n );\n}\n\nconst svgDefaults = toReactAttributes(ɵcopilotIconSvgAttributes);\n\n/** True when the props give the icon an accessible name or role. */\nfunction hasAccessibleProp(props: object) {\n return Object.keys(props).some(\n (key) => key.startsWith(\"aria-\") || key === \"role\" || key === \"title\",\n );\n}\n\ntype SvgProps = React.ComponentPropsWithoutRef<\"svg\">;\n\n/** Props of `IconSvg` and `CopilotIcon` that change how the icon is drawn. */\ninterface IconDrawProps extends SvgProps {\n /** Width and height of the icon. Defaults to `24`. */\n size?: number | string;\n}\n\ninterface IconSvgProps extends IconDrawProps {\n /** The Lucide icon name in kebab case, for the `lucide-<name>` class. */\n lucideName: string;\n nodes: readonly IconSvgNode[];\n}\n\n/**\n * Internal. Draws a Lucide icon from its node data, the way Lucide's React package\n * does: Lucide's default SVG attributes, the `lucide lucide-<name>` classes,\n * and `aria-hidden=\"true\"` when no `aria-*`, `role` or `title` prop names it.\n */\nexport const IconSvg = forwardRef<SVGSVGElement, IconSvgProps>(function IconSvg(\n {\n lucideName,\n nodes,\n size = 24,\n color = \"currentColor\",\n strokeWidth = 2,\n className,\n children,\n ...props\n },\n ref,\n) {\n const isDecorative = !children && !hasAccessibleProp(props);\n return (\n <svg\n ref={ref}\n {...svgDefaults}\n width={size}\n height={size}\n stroke={color}\n strokeWidth={strokeWidth}\n className={cn(\"lucide\", `lucide-${lucideName}`, className)}\n aria-hidden={isDecorative || undefined}\n {...props}\n >\n {nodes.map((node, index) =>\n createElement(node.tag, { key: index, ...node.attributes }),\n )}\n {children}\n </svg>\n );\n});\n\n/** Props of `CopilotIcon`. Any other SVG prop goes on the `<svg>`. */\nexport interface CopilotIconProps extends IconDrawProps {\n /** The chat icon to draw, for example `\"ArrowUp\"`. */\n name: CopilotIconName;\n}\n\n/**\n * Draws one of the chat icons as an inline `<svg>`.\n *\n * The `<svg>` has the classes `lucide lucide-<icon name>`, so CSS that selects\n * them (for example `svg.lucide-arrow-up`) keeps working. The icon is hidden\n * from screen readers unless you give it an `aria-label`, `role` or `title`.\n *\n * @param props.name - The chat icon, for example `\"ArrowUp\"` or `\"X\"`.\n * @param props.size - Width and height. Defaults to `24`.\n * @param props.strokeWidth - Line width. Defaults to `2`.\n * @param props.color - Line color. Defaults to `currentColor`.\n *\n * @example\n * ```tsx\n * <CopilotIcon name=\"ArrowUp\" className=\"cpk-chat-input-send-icon\" />\n * <CopilotIcon name=\"X\" aria-label=\"Close\" />\n * ```\n */\nexport const CopilotIcon = forwardRef<SVGSVGElement, CopilotIconProps>(\n function CopilotIcon({ name, ...props }, ref) {\n const icon = ɵcopilotIcons[name];\n return (\n <IconSvg ref={ref} lucideName={icon.name} nodes={icon.nodes} {...props} />\n );\n },\n);\n","import React from \"react\";\nimport { cn } from \"./utils\";\nimport { shallowEqual, useShallowStableRef } from \"./shallow-stable-ref\";\n\n// Reference-stability helpers moved to ./shallow-stable-ref (a leaf module) so\n// the lean @copilotkit/react-core/headless entry can reach them without\n// pulling in this module (issue #4893). Re-exported here to preserve this\n// module's public surface for existing importers (e.g. CopilotChat).\nexport { shallowEqual, useShallowStableRef };\n\n/** Existing union (unchanged) */\nexport type SlotValue<C extends React.ComponentType<any>> =\n | C\n | string\n | Partial<React.ComponentProps<C>>;\n\n/** Utility: concrete React elements for every slot */\ntype SlotElements<S> = { [K in keyof S]: React.ReactElement };\n\nexport type WithSlots<\n S extends Record<string, React.ComponentType<any>>,\n Rest = {},\n> = {\n /** Per‑slot overrides */\n [K in keyof S]?: SlotValue<S[K]>;\n} & {\n children?: (props: SlotElements<S> & Rest) => React.ReactNode;\n} & Omit<Rest, \"children\">;\n\n/**\n * Check if a value is a React component type (function, class, forwardRef, memo, etc.)\n */\nexport function isReactComponentType(\n value: unknown,\n): value is React.ComponentType<any> {\n if (typeof value === \"function\") {\n return true;\n }\n // forwardRef, memo, lazy have $$typeof but are not valid elements\n if (\n value &&\n typeof value === \"object\" &&\n \"$$typeof\" in value &&\n !React.isValidElement(value)\n ) {\n return true;\n }\n return false;\n}\n\n/**\n * Internal function to render a slot value as a React element (non-memoized).\n */\nfunction renderSlotElement(\n slot: SlotValue<React.ComponentType<any>> | undefined,\n DefaultComponent: React.ComponentType<any>,\n props: Record<string, unknown>,\n): React.ReactElement {\n if (typeof slot === \"string\") {\n // When slot is a string, treat it as a className and merge with existing className\n const existingClassName = props.className as string | undefined;\n return React.createElement(DefaultComponent, {\n ...props,\n className: cn(existingClassName, slot),\n });\n }\n\n // Check if slot is a React component type (function, forwardRef, memo, etc.)\n if (isReactComponentType(slot)) {\n return React.createElement(slot, props);\n }\n\n // If slot is a plain object (not a React element), treat it as props override\n if (slot && typeof slot === \"object\" && !React.isValidElement(slot)) {\n return React.createElement(DefaultComponent, {\n ...props,\n ...slot,\n });\n }\n\n return React.createElement(DefaultComponent, props);\n}\n\n/**\n * Internal memoized wrapper component for renderSlot.\n * Uses forwardRef to support ref forwarding.\n */\nconst MemoizedSlotWrapper = React.memo(\n React.forwardRef<unknown, any>(function MemoizedSlotWrapper(props, ref) {\n const { $slot, $component, ...rest } = props;\n const propsWithRef: Record<string, unknown> =\n ref !== null ? { ...rest, ref } : rest;\n return renderSlotElement($slot, $component, propsWithRef);\n }),\n (prev: any, next: any) => {\n // Compare slot and component references\n if (prev.$slot !== next.$slot) return false;\n if (prev.$component !== next.$component) return false;\n\n // Shallow compare remaining props (ref is handled separately by React)\n const { $slot: _ps, $component: _pc, ...prevRest } = prev;\n const { $slot: _ns, $component: _nc, ...nextRest } = next;\n return shallowEqual(\n prevRest as Record<string, unknown>,\n nextRest as Record<string, unknown>,\n );\n },\n);\n\n/**\n * Renders a slot value as a memoized React element.\n * Automatically prevents unnecessary re-renders using shallow prop comparison.\n * Supports ref forwarding.\n *\n * @example\n * renderSlot(customInput, CopilotChatInput, { onSubmit: handleSubmit })\n */\nexport function renderSlot<\n C extends React.ComponentType<any>,\n P = React.ComponentProps<C>,\n>(\n slot: SlotValue<C> | undefined,\n DefaultComponent: C,\n props: P,\n): React.ReactElement {\n return React.createElement(MemoizedSlotWrapper, {\n ...props,\n $slot: slot,\n $component: DefaultComponent,\n } as any);\n}\n","\"use client\";\n\nimport React, { createContext, useContext } from \"react\";\nimport type { StreamingMarkdownRendererProps } from \"@copilotkit/markdown/react\";\n\n/** Props every markdown renderer (built-in or plugged-in) receives. */\nexport interface MarkdownRendererProps {\n /** Raw, possibly-partial (streaming) markdown string. */\n content: string;\n /** Hint that the message is still streaming, for cursor/affordance use. */\n isStreaming?: boolean;\n className?: string;\n}\n\n/**\n * Config for the built-in default renderer. Pass this (instead of a component)\n * as `markdownRenderer` to configure the built-in renderer without writing a\n * wrapper — e.g. `markdownRenderer={{ nodeRenderers: { codeBlock: Shiki } }}`.\n */\nexport type DefaultMarkdownRendererProps = Pick<\n StreamingMarkdownRendererProps,\n | \"nodeRenderers\"\n | \"caret\"\n | \"options\"\n | \"className\"\n | \"onLinkClick\"\n | \"onCitationClick\"\n>;\n\n/** A markdown renderer: a component, OR config for the built-in default. */\nexport type MarkdownRenderer =\n | React.ComponentType<MarkdownRendererProps>\n | DefaultMarkdownRendererProps;\n\nconst MarkdownRendererContext = createContext<MarkdownRenderer | undefined>(\n undefined,\n);\n\nexport const MarkdownRendererProvider: React.FC<{\n renderer?: MarkdownRenderer;\n children: React.ReactNode;\n}> = ({ renderer, children }) => (\n <MarkdownRendererContext.Provider value={renderer}>\n {children}\n </MarkdownRendererContext.Provider>\n);\n\n/**\n * The markdown renderer set at the provider level, or `undefined` when none was\n * supplied. Message components fall back to the built-in\n * `StreamingMarkdownDefaultRenderer` (via `CopilotChatAssistantMessage.MarkdownRenderer`)\n * when this is `undefined`.\n */\nexport function useMarkdownRenderer(): MarkdownRenderer | undefined {\n return useContext(MarkdownRendererContext);\n}\n","\"use client\";\n\nimport React from \"react\";\nimport { StreamingMarkdownDefaultRenderer } from \"../../components/chat/StreamingMarkdownDefaultRenderer\";\nimport { isReactComponentType } from \"../../lib/slots\";\nimport { useMarkdownRenderer } from \"../../providers/MarkdownRendererContext\";\nimport type {\n DefaultMarkdownRendererProps,\n MarkdownRendererProps,\n} from \"../../providers/MarkdownRendererContext\";\n\n/**\n * Markdown prose inside generative UI, rendered like the chat text around\n * it: the renderer set on the provider when there is one, else the built-in\n * streaming renderer. Config passed here wins over provider config.\n */\nexport function ProviderMarkdown({\n content,\n isStreaming,\n className,\n ...config\n}: MarkdownRendererProps & DefaultMarkdownRendererProps) {\n const renderer = useMarkdownRenderer();\n if (renderer && isReactComponentType(renderer)) {\n const Renderer = renderer;\n return (\n <Renderer\n content={content}\n isStreaming={isStreaming}\n className={className}\n />\n );\n }\n return (\n <StreamingMarkdownDefaultRenderer\n {...(renderer as DefaultMarkdownRendererProps | undefined)}\n {...config}\n content={content}\n isStreaming={isStreaming}\n className={className}\n />\n );\n}\n","import React, { useContext, useInsertionEffect, useMemo } from \"react\";\nimport type { ComponentType } from \"react\";\nimport { splitA2UIMarkdown } from \"@copilotkit/core\";\nimport { GENERATIVE_UI_ROOT_ID } from \"@copilotkit/shared\";\nimport { useCopilotChatConfiguration } from \"../../providers/CopilotChatConfigurationProvider\";\nimport { GenerativeUIChatSlotContext } from \"../chat\";\nimport type { GenerativeUIChatSurfaceProps } from \"../chat\";\nimport { useManagerVersion } from \"../hooks\";\nimport { useRequiredGenerativeUIRuntime } from \"../runtime-context\";\nimport type { GenerativeUIRuntime } from \"../runtime-context\";\nimport { SurfaceView } from \"../SurfaceView\";\nimport type { DefaultMarkdownRendererProps } from \"../../providers/MarkdownRendererContext\";\nimport { ProviderMarkdown } from \"./ProviderMarkdown\";\nimport { getMarkdownSurfaceSource } from \"@copilotkit/core/generative-ui\";\nimport type { MarkdownFenceBlock } from \"@copilotkit/core/generative-ui\";\n\n/** Config for the built-in markdown renderer, plus `className`. */\ntype MarkdownProps = DefaultMarkdownRendererProps;\n\nconst FADE_STYLE_ID = \"a2ui-markdown-fade\";\n/**\n * Components fade in as they stream: each element that appears under a\n * markdown surface runs the keyframes once on mount. React keeps the keys\n * stable per component id, so an element that is already there never\n * animates again. SVG internals are left out: a chart library re-creates\n * its nodes on each render, and a fade on each of them would read as the\n * chart flashing whenever a sibling arrives. The fade runs under reduced\n * motion too, because it moves nothing.\n */\nconst FADE_CSS = [\n // Opacity only, so it also runs when the user asks for reduced motion:\n // that setting is about movement, and a short fade is not movement.\n // The keyframes give only the start, so each element fades to its own\n // opacity (a disabled control to its dimmed one), and no fill holds the\n // end: a finished fade must not pin opacity, or an element that hides\n // itself with opacity (the map's zoom hint) stays visible forever.\n \"@keyframes a2ui-fade-in{from{opacity:0}}\",\n \"[data-a2ui-markdown-surface] .a2ui-surface *:not(svg):not(svg *){animation:a2ui-fade-in .35s ease-out backwards}\",\n].join(\"\\n\");\n\n// There is no document on the server, so nothing is added there.\nconst noEffect: typeof useInsertionEffect = () => {};\nconst useInjectEffect =\n typeof document === \"undefined\" ? noEffect : useInsertionEffect;\n\nfunction useFadeStyles() {\n useInjectEffect(() => {\n if (document.getElementById(FADE_STYLE_ID)) return;\n const style = document.createElement(\"style\");\n style.id = FADE_STYLE_ID;\n style.textContent = FADE_CSS;\n document.head.appendChild(style);\n }, []);\n}\n\n/**\n * The default wrapper of a chat surface in the markdown transport. It draws\n * no box: a surface sits in the flow of the reply like a paragraph, and a\n * Card draws its own box when it is interactive. Nothing shows while the\n * surface streams. A rejected operation gets one line.\n */\nexport function DefaultMarkdownChatSurface({\n surfaceId,\n error,\n children,\n}: GenerativeUIChatSurfaceProps) {\n useFadeStyles();\n return (\n <div\n data-generative-ui-chat-surface={surfaceId}\n data-a2ui-markdown-surface={surfaceId}\n className=\"cpk-markdown-chat-surface\"\n >\n {children}\n {error && (\n <div role=\"alert\" className=\"cpk-markdown-chat-surface-error\">\n Part of this UI couldn't be shown.\n </div>\n )}\n </div>\n );\n}\n\nexport type MarkdownSurfacesProps = MarkdownProps & {\n /** The text of the assistant message, complete or still streaming. */\n content: string;\n /** The id of the message. The fences of the message are found by it. */\n messageId: string;\n /** Whether the message is still streaming. Only its last prose shows the caret. */\n isStreaming?: boolean;\n};\n\n/**\n * One chat surface in the chat wrapper. Nothing renders until the surface\n * has its root component, so a half-streamed fence shows no empty card.\n */\nfunction ChatSurface({\n runtime,\n threadId,\n surfaceId,\n Wrapper,\n}: {\n runtime: GenerativeUIRuntime;\n threadId: string;\n surfaceId: string;\n Wrapper: ComponentType<GenerativeUIChatSurfaceProps>;\n}) {\n // A surface whose createSurface was rejected shows only the error.\n const surface =\n runtime.manager.getSurface(threadId, surfaceId) ??\n runtime.manager.getFailedSurface(threadId, surfaceId);\n const root = surface?.model.componentsModel.get(GENERATIVE_UI_ROOT_ID);\n if (!surface || (!root && !surface.failed)) return null;\n const rejected = [...surface.serverRejected, ...surface.clientRejected];\n const error = rejected.length\n ? new Error(`${rejected.length} UI update(s) could not be shown`, {\n cause: rejected,\n })\n : undefined;\n return (\n <Wrapper\n surfaceId={surfaceId}\n isStreaming={surface.status === \"streaming\"}\n error={error}\n rejected={rejected}\n >\n {surface.failed ? null : <SurfaceView surface={surface} />}\n </Wrapper>\n );\n}\n\n/** The blocks of one fence: lifted prose and chat surfaces, in order. */\nfunction FenceBlocks({\n blocks,\n runtime,\n threadId,\n isStreaming,\n markdownProps,\n}: {\n blocks: MarkdownFenceBlock[];\n runtime: GenerativeUIRuntime;\n threadId: string;\n isStreaming: boolean;\n markdownProps: MarkdownProps;\n}) {\n const Wrapper =\n useContext(GenerativeUIChatSlotContext) ?? DefaultMarkdownChatSurface;\n let surfaceCount = 0;\n return (\n <>\n {blocks.map((block, index) => {\n // Keys follow the surfaces, so a surface keeps its element when\n // prose splits off around it during streaming.\n if (block.kind === \"markdown\") {\n return (\n <ProviderMarkdown\n key={`md-${surfaceCount}`}\n {...markdownProps}\n content={block.markdown}\n isStreaming={isStreaming && index === blocks.length - 1}\n />\n );\n }\n surfaceCount++;\n return (\n <ChatSurface\n key={block.surfaceId}\n runtime={runtime}\n threadId={threadId}\n surfaceId={block.surfaceId}\n Wrapper={Wrapper}\n />\n );\n })}\n </>\n );\n}\n\n/**\n * Experimental. Renders an assistant message of the markdown transport.\n * Prose renders as markdown. In place of each ```a2ui fence:\n *\n * - the fence that created a chat surface renders that surface (and the\n * prose lifted out of it) in the chat wrapper;\n * - every other fence renders nothing: a fence that updates the surface of\n * an earlier fence, or a fence for a named target, which\n * `<GenerativeUISurface id>` renders.\n *\n * Use it inside `<CopilotKitProvider generativeUI={{ ui, transport: \"markdown\" }}>`.\n * `CopilotChatAssistantMessage` uses it there on its own.\n *\n * @example\n * ```tsx\n * <MarkdownSurfaces content={message.content} messageId={message.id} />\n * ```\n */\nexport function MarkdownSurfaces({\n content,\n messageId,\n isStreaming = false,\n ...markdownProps\n}: MarkdownSurfacesProps) {\n const runtime = useRequiredGenerativeUIRuntime();\n const chatThreadId = useCopilotChatConfiguration()?.threadId;\n useManagerVersion(runtime);\n const segments = useMemo(() => splitA2UIMarkdown(content), [content]);\n const threadId = chatThreadId ?? runtime.manager.getActiveThread();\n const source = getMarkdownSurfaceSource(runtime);\n\n return (\n <>\n {segments.map((segment, index) => {\n const isLast = index === segments.length - 1;\n if (segment.type === \"markdown\") {\n return (\n <ProviderMarkdown\n key={`md-${index}`}\n {...markdownProps}\n content={segment.text}\n isStreaming={isStreaming && isLast}\n />\n );\n }\n const blocks = threadId\n ? source.getFenceBlocks(threadId, messageId, segment.index)\n : undefined;\n if (!threadId || !blocks) return null;\n return (\n <FenceBlocks\n key={`a2ui-${segment.index}`}\n blocks={blocks}\n runtime={runtime}\n threadId={threadId}\n isStreaming={isStreaming && isLast}\n markdownProps={markdownProps}\n />\n );\n })}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,SAAgB,iCAAiC,EAC/C,SACA,aACA,WACA,eACA,OACA,SACA,aACA,mBACuD;AACvD,KAAI,CAAC,QAAS,QAAO;AAGrB,yDAA8B,QAAQ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