@copilotkit/react-core 2.0.0-rc.4 → 2.0.0-rc.41

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.
Files changed (80) hide show
  1. package/README.md +1 -1
  2. package/dist/MarkdownRendererContext-BL8ct_3U.d.mts +34 -0
  3. package/dist/MarkdownRendererContext-BL8ct_3U.d.mts.map +1 -0
  4. package/dist/MarkdownRendererContext-C2J_lgqF.d.cts +34 -0
  5. package/dist/MarkdownRendererContext-C2J_lgqF.d.cts.map +1 -0
  6. package/dist/MarkdownSurfaces-Byz821bg.mjs +324 -0
  7. package/dist/MarkdownSurfaces-Byz821bg.mjs.map +1 -0
  8. package/dist/MarkdownSurfaces-D2Ck-cbb.cjs +378 -0
  9. package/dist/MarkdownSurfaces-D2Ck-cbb.cjs.map +1 -0
  10. package/dist/chat-Bf0vVdo7.mjs +1600 -0
  11. package/dist/chat-Bf0vVdo7.mjs.map +1 -0
  12. package/dist/chat-D3fxo6Ah.cjs +1784 -0
  13. package/dist/chat-D3fxo6Ah.cjs.map +1 -0
  14. package/dist/chat-DgP2N7bD.d.mts +233 -0
  15. package/dist/chat-DgP2N7bD.d.mts.map +1 -0
  16. package/dist/chat-DtHs4alO.d.cts +233 -0
  17. package/dist/chat-DtHs4alO.d.cts.map +1 -0
  18. package/dist/context.cjs +75 -63
  19. package/dist/context.cjs.map +1 -1
  20. package/dist/context.d.cts +62 -107
  21. package/dist/context.d.cts.map +1 -1
  22. package/dist/context.d.mts +62 -107
  23. package/dist/context.d.mts.map +1 -1
  24. package/dist/context.mjs +76 -64
  25. package/dist/context.mjs.map +1 -1
  26. package/dist/generative-ui/native.cjs +66 -0
  27. package/dist/generative-ui/native.cjs.map +1 -0
  28. package/dist/generative-ui/native.d.cts +155 -0
  29. package/dist/generative-ui/native.d.cts.map +1 -0
  30. package/dist/generative-ui/native.d.mts +155 -0
  31. package/dist/generative-ui/native.d.mts.map +1 -0
  32. package/dist/generative-ui/native.mjs +24 -0
  33. package/dist/generative-ui/native.mjs.map +1 -0
  34. package/dist/generative-ui.cjs +757 -3056
  35. package/dist/generative-ui.cjs.map +1 -1
  36. package/dist/generative-ui.d.cts +2470 -4788
  37. package/dist/generative-ui.d.cts.map +1 -1
  38. package/dist/generative-ui.d.mts +2470 -4788
  39. package/dist/generative-ui.d.mts.map +1 -1
  40. package/dist/generative-ui.mjs +327 -2636
  41. package/dist/generative-ui.mjs.map +1 -1
  42. package/dist/headless.cjs +289 -1054
  43. package/dist/headless.cjs.map +1 -1
  44. package/dist/headless.d.cts +146 -371
  45. package/dist/headless.d.cts.map +1 -1
  46. package/dist/headless.d.mts +120 -236
  47. package/dist/headless.d.mts.map +1 -1
  48. package/dist/headless.mjs +283 -1054
  49. package/dist/headless.mjs.map +1 -1
  50. package/dist/hooks-2Ur8NQhj.d.cts +84 -0
  51. package/dist/hooks-2Ur8NQhj.d.cts.map +1 -0
  52. package/dist/hooks-BRYonCVu.d.mts +84 -0
  53. package/dist/hooks-BRYonCVu.d.mts.map +1 -0
  54. package/dist/index.cjs +9003 -13047
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.d.cts +352 -834
  57. package/dist/index.d.cts.map +1 -1
  58. package/dist/index.d.mts +349 -831
  59. package/dist/index.d.mts.map +1 -1
  60. package/dist/index.mjs +1904 -7583
  61. package/dist/index.mjs.map +1 -1
  62. package/dist/index.umd.js +10629 -15765
  63. package/dist/index.umd.js.map +1 -1
  64. package/dist/refs-BIUfn1wb.cjs +43 -0
  65. package/dist/refs-BIUfn1wb.cjs.map +1 -0
  66. package/dist/refs-CMrRm3ta.mjs +31 -0
  67. package/dist/refs-CMrRm3ta.mjs.map +1 -0
  68. package/dist/use-generative-ui-root-C12htqbK.cjs +390 -0
  69. package/dist/use-generative-ui-root-C12htqbK.cjs.map +1 -0
  70. package/dist/use-generative-ui-root-CVgsDy1f.mjs +385 -0
  71. package/dist/use-generative-ui-root-CVgsDy1f.mjs.map +1 -0
  72. package/package.json +45 -23
  73. package/dist/MarkdownRendererContext-B4Us6mwL.d.cts +0 -954
  74. package/dist/MarkdownRendererContext-B4Us6mwL.d.cts.map +0 -1
  75. package/dist/MarkdownRendererContext-CRKFzsEB.d.mts +0 -954
  76. package/dist/MarkdownRendererContext-CRKFzsEB.d.mts.map +0 -1
  77. package/dist/MarkdownSurfaces-Bd--93O1.mjs +0 -3676
  78. package/dist/MarkdownSurfaces-Bd--93O1.mjs.map +0 -1
  79. package/dist/MarkdownSurfaces-S4wfUl3J.cjs +0 -3991
  80. package/dist/MarkdownSurfaces-S4wfUl3J.cjs.map +0 -1
package/README.md CHANGED
@@ -122,7 +122,7 @@ const modifiedConfig = copilotKitCustomizeConfig(config, {
122
122
  },
123
123
  ],
124
124
  });
125
- const response = await ChatOpenAI({ model: "gpt-4o" }).invoke(
125
+ const response = await ChatOpenAI({ model: "gpt-6-luna" }).invoke(
126
126
  messages,
127
127
  modifiedConfig,
128
128
  );
@@ -0,0 +1,34 @@
1
+ import React from "react";
2
+ import { StreamingMarkdownRendererProps } from "@copilotkit/markdown/react";
3
+
4
+ //#region src/providers/MarkdownRendererContext.d.ts
5
+ /** Props every markdown renderer (built-in or plugged-in) receives. */
6
+ interface MarkdownRendererProps {
7
+ /** Raw, possibly-partial (streaming) markdown string. */
8
+ content: string;
9
+ /** Hint that the message is still streaming, for cursor/affordance use. */
10
+ isStreaming?: boolean;
11
+ className?: string;
12
+ }
13
+ /**
14
+ * Config for the built-in default renderer. Pass this (instead of a component)
15
+ * as `markdownRenderer` to configure the built-in renderer without writing a
16
+ * wrapper — e.g. `markdownRenderer={{ nodeRenderers: { codeBlock: Shiki } }}`.
17
+ */
18
+ type DefaultMarkdownRendererProps = Pick<StreamingMarkdownRendererProps, "nodeRenderers" | "caret" | "options" | "className" | "onLinkClick" | "onCitationClick">;
19
+ /** A markdown renderer: a component, OR config for the built-in default. */
20
+ type MarkdownRenderer = React.ComponentType<MarkdownRendererProps> | DefaultMarkdownRendererProps;
21
+ declare const MarkdownRendererProvider: React.FC<{
22
+ renderer?: MarkdownRenderer;
23
+ children: React.ReactNode;
24
+ }>;
25
+ /**
26
+ * The markdown renderer set at the provider level, or `undefined` when none was
27
+ * supplied. Message components fall back to the built-in
28
+ * `StreamingMarkdownDefaultRenderer` (via `CopilotChatAssistantMessage.MarkdownRenderer`)
29
+ * when this is `undefined`.
30
+ */
31
+ declare function useMarkdownRenderer(): MarkdownRenderer | undefined;
32
+ //#endregion
33
+ export { useMarkdownRenderer as a, MarkdownRendererProvider as i, MarkdownRenderer as n, MarkdownRendererProps as r, DefaultMarkdownRendererProps as t };
34
+ //# sourceMappingURL=MarkdownRendererContext-BL8ct_3U.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarkdownRendererContext-BL8ct_3U.d.mts","names":[],"sources":["../src/providers/MarkdownRendererContext.tsx"],"mappings":";;;;;UAMiB,qBAAA;EAAA;EAEf,OAAA;;EAEA,WAAA;EACA,SAAA;AAAA;;;;AAQF;;KAAY,4BAAA,GAA+B,IAAA,CACzC,8BAAA;;KAUU,gBAAA,GACR,KAAA,CAAM,aAAA,CAAc,qBAAA,IACpB,4BAAA;AAAA,cAMS,wBAAA,EAA0B,KAAA,CAAM,EAAA;EAC3C,QAAA,GAAW,gBAAA;EACX,QAAA,EAAU,KAAA,CAAM,SAAA;AAAA;;;;;;;iBAaF,mBAAA,CAAA,GAAuB,gBAAA"}
@@ -0,0 +1,34 @@
1
+ import React from "react";
2
+ import { StreamingMarkdownRendererProps } from "@copilotkit/markdown/react";
3
+
4
+ //#region src/providers/MarkdownRendererContext.d.ts
5
+ /** Props every markdown renderer (built-in or plugged-in) receives. */
6
+ interface MarkdownRendererProps {
7
+ /** Raw, possibly-partial (streaming) markdown string. */
8
+ content: string;
9
+ /** Hint that the message is still streaming, for cursor/affordance use. */
10
+ isStreaming?: boolean;
11
+ className?: string;
12
+ }
13
+ /**
14
+ * Config for the built-in default renderer. Pass this (instead of a component)
15
+ * as `markdownRenderer` to configure the built-in renderer without writing a
16
+ * wrapper — e.g. `markdownRenderer={{ nodeRenderers: { codeBlock: Shiki } }}`.
17
+ */
18
+ type DefaultMarkdownRendererProps = Pick<StreamingMarkdownRendererProps, "nodeRenderers" | "caret" | "options" | "className" | "onLinkClick" | "onCitationClick">;
19
+ /** A markdown renderer: a component, OR config for the built-in default. */
20
+ type MarkdownRenderer = React.ComponentType<MarkdownRendererProps> | DefaultMarkdownRendererProps;
21
+ declare const MarkdownRendererProvider: React.FC<{
22
+ renderer?: MarkdownRenderer;
23
+ children: React.ReactNode;
24
+ }>;
25
+ /**
26
+ * The markdown renderer set at the provider level, or `undefined` when none was
27
+ * supplied. Message components fall back to the built-in
28
+ * `StreamingMarkdownDefaultRenderer` (via `CopilotChatAssistantMessage.MarkdownRenderer`)
29
+ * when this is `undefined`.
30
+ */
31
+ declare function useMarkdownRenderer(): MarkdownRenderer | undefined;
32
+ //#endregion
33
+ export { useMarkdownRenderer as a, MarkdownRendererProvider as i, MarkdownRenderer as n, MarkdownRendererProps as r, DefaultMarkdownRendererProps as t };
34
+ //# sourceMappingURL=MarkdownRendererContext-C2J_lgqF.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarkdownRendererContext-C2J_lgqF.d.cts","names":[],"sources":["../src/providers/MarkdownRendererContext.tsx"],"mappings":";;;;;UAMiB,qBAAA;EAAA;EAEf,OAAA;;EAEA,WAAA;EACA,SAAA;AAAA;;;;AAQF;;KAAY,4BAAA,GAA+B,IAAA,CACzC,8BAAA;;KAUU,gBAAA,GACR,KAAA,CAAM,aAAA,CAAc,qBAAA,IACpB,4BAAA;AAAA,cAMS,wBAAA,EAA0B,KAAA,CAAM,EAAA;EAC3C,QAAA,GAAW,gBAAA;EACX,QAAA,EAAU,KAAA,CAAM,SAAA;AAAA;;;;;;;iBAaF,mBAAA,CAAA,GAAuB,gBAAA"}
@@ -0,0 +1,324 @@
1
+ import { A as shallowEqual, T as useRequiredGenerativeUIRuntime, k as useCopilotChatConfiguration, n as GenerativeUIChatSlotContext, o as SurfaceView, x as useManagerVersion } from "./chat-Bf0vVdo7.mjs";
2
+ import { splitA2UIMarkdown, ɵcn as cn, ɵcopilotIconSvgAttributes, ɵcopilotIcons } from "@copilotkit/core";
3
+ import React, { createContext, createElement, forwardRef, useContext, useInsertionEffect, useMemo } from "react";
4
+ import { StreamingMarkdownRenderer } from "@copilotkit/markdown/react";
5
+ import { CHAT_MARKDOWN_NODE_CLASS_NAMES, warnUnsupportedRichSyntaxOnce } from "@copilotkit/markdown";
6
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
+ import { GENERATIVE_UI_ROOT_ID } from "@copilotkit/shared";
8
+ import { getMarkdownSurfaceSource } from "@copilotkit/core/generative-ui";
9
+
10
+ //#region src/components/chat/StreamingMarkdownDefaultRenderer.tsx
11
+ /**
12
+ * react-core's built-in default markdown renderer — a thin adapter over
13
+ * `@copilotkit/markdown`'s streaming renderer. Maps the pluggable
14
+ * renderer contract (`{ content, isStreaming, className }`) onto the streaming
15
+ * renderer for streaming-safe incremental rendering + per-token animation.
16
+ * Still overridable via the slot/provider pluggable interface.
17
+ */
18
+ function StreamingMarkdownDefaultRenderer({ content, isStreaming, className, nodeRenderers, caret, options, onLinkClick, onCitationClick }) {
19
+ if (!content) return null;
20
+ warnUnsupportedRichSyntaxOnce(content);
21
+ return /* @__PURE__ */ jsx(StreamingMarkdownRenderer, {
22
+ className,
23
+ isComplete: !isStreaming,
24
+ caret: caret ?? !!isStreaming,
25
+ nodeRenderers,
26
+ nodeClassNames: CHAT_MARKDOWN_NODE_CLASS_NAMES,
27
+ options,
28
+ onLinkClick,
29
+ onCitationClick,
30
+ children: content
31
+ });
32
+ }
33
+ StreamingMarkdownDefaultRenderer.displayName = "StreamingMarkdownDefaultRenderer";
34
+
35
+ //#endregion
36
+ //#region src/components/icons/CopilotIcon.tsx
37
+ /** Turns SVG attribute names such as `stroke-width` into React's `strokeWidth`. */
38
+ function toReactAttributes(attributes) {
39
+ return Object.fromEntries(Object.entries(attributes).map(([key, value]) => [key.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase()), value]));
40
+ }
41
+ const svgDefaults = toReactAttributes(ɵcopilotIconSvgAttributes);
42
+ /** True when the props give the icon an accessible name or role. */
43
+ function hasAccessibleProp(props) {
44
+ return Object.keys(props).some((key) => key.startsWith("aria-") || key === "role" || key === "title");
45
+ }
46
+ /**
47
+ * Internal. Draws a Lucide icon from its node data, the way Lucide's React package
48
+ * does: Lucide's default SVG attributes, the `lucide lucide-<name>` classes,
49
+ * and `aria-hidden="true"` when no `aria-*`, `role` or `title` prop names it.
50
+ */
51
+ const IconSvg = forwardRef(function IconSvg({ lucideName, nodes, size = 24, color = "currentColor", strokeWidth = 2, className, children, ...props }, ref) {
52
+ const isDecorative = !children && !hasAccessibleProp(props);
53
+ return /* @__PURE__ */ jsxs("svg", {
54
+ ref,
55
+ ...svgDefaults,
56
+ width: size,
57
+ height: size,
58
+ stroke: color,
59
+ strokeWidth,
60
+ className: cn("lucide", `lucide-${lucideName}`, className),
61
+ "aria-hidden": isDecorative || void 0,
62
+ ...props,
63
+ children: [nodes.map((node, index) => createElement(node.tag, {
64
+ key: index,
65
+ ...node.attributes
66
+ })), children]
67
+ });
68
+ });
69
+ /**
70
+ * Draws one of the chat icons as an inline `<svg>`.
71
+ *
72
+ * The `<svg>` has the classes `lucide lucide-<icon name>`, so CSS that selects
73
+ * them (for example `svg.lucide-arrow-up`) keeps working. The icon is hidden
74
+ * from screen readers unless you give it an `aria-label`, `role` or `title`.
75
+ *
76
+ * @param props.name - The chat icon, for example `"ArrowUp"` or `"X"`.
77
+ * @param props.size - Width and height. Defaults to `24`.
78
+ * @param props.strokeWidth - Line width. Defaults to `2`.
79
+ * @param props.color - Line color. Defaults to `currentColor`.
80
+ *
81
+ * @example
82
+ * ```tsx
83
+ * <CopilotIcon name="ArrowUp" className="cpk-chat-input-send-icon" />
84
+ * <CopilotIcon name="X" aria-label="Close" />
85
+ * ```
86
+ */
87
+ const CopilotIcon = forwardRef(function CopilotIcon({ name, ...props }, ref) {
88
+ const icon = ɵcopilotIcons[name];
89
+ return /* @__PURE__ */ jsx(IconSvg, {
90
+ ref,
91
+ lucideName: icon.name,
92
+ nodes: icon.nodes,
93
+ ...props
94
+ });
95
+ });
96
+
97
+ //#endregion
98
+ //#region src/lib/slots.tsx
99
+ /**
100
+ * Check if a value is a React component type (function, class, forwardRef, memo, etc.)
101
+ */
102
+ function isReactComponentType(value) {
103
+ if (typeof value === "function") return true;
104
+ if (value && typeof value === "object" && "$$typeof" in value && !React.isValidElement(value)) return true;
105
+ return false;
106
+ }
107
+ /**
108
+ * Internal function to render a slot value as a React element (non-memoized).
109
+ */
110
+ function renderSlotElement(slot, DefaultComponent, props) {
111
+ if (typeof slot === "string") {
112
+ const existingClassName = props.className;
113
+ return React.createElement(DefaultComponent, {
114
+ ...props,
115
+ className: cn(existingClassName, slot)
116
+ });
117
+ }
118
+ if (isReactComponentType(slot)) return React.createElement(slot, props);
119
+ if (slot && typeof slot === "object" && !React.isValidElement(slot)) return React.createElement(DefaultComponent, {
120
+ ...props,
121
+ ...slot
122
+ });
123
+ return React.createElement(DefaultComponent, props);
124
+ }
125
+ /**
126
+ * Internal memoized wrapper component for renderSlot.
127
+ * Uses forwardRef to support ref forwarding.
128
+ */
129
+ const MemoizedSlotWrapper = React.memo(React.forwardRef(function MemoizedSlotWrapper(props, ref) {
130
+ const { $slot, $component, ...rest } = props;
131
+ return renderSlotElement($slot, $component, ref !== null ? {
132
+ ...rest,
133
+ ref
134
+ } : rest);
135
+ }), (prev, next) => {
136
+ if (prev.$slot !== next.$slot) return false;
137
+ if (prev.$component !== next.$component) return false;
138
+ const { $slot: _ps, $component: _pc, ...prevRest } = prev;
139
+ const { $slot: _ns, $component: _nc, ...nextRest } = next;
140
+ return shallowEqual(prevRest, nextRest);
141
+ });
142
+ /**
143
+ * Renders a slot value as a memoized React element.
144
+ * Automatically prevents unnecessary re-renders using shallow prop comparison.
145
+ * Supports ref forwarding.
146
+ *
147
+ * @example
148
+ * renderSlot(customInput, CopilotChatInput, { onSubmit: handleSubmit })
149
+ */
150
+ function renderSlot(slot, DefaultComponent, props) {
151
+ return React.createElement(MemoizedSlotWrapper, {
152
+ ...props,
153
+ $slot: slot,
154
+ $component: DefaultComponent
155
+ });
156
+ }
157
+
158
+ //#endregion
159
+ //#region src/providers/MarkdownRendererContext.tsx
160
+ const MarkdownRendererContext = createContext(void 0);
161
+ const MarkdownRendererProvider = ({ renderer, children }) => /* @__PURE__ */ jsx(MarkdownRendererContext.Provider, {
162
+ value: renderer,
163
+ children
164
+ });
165
+ /**
166
+ * The markdown renderer set at the provider level, or `undefined` when none was
167
+ * supplied. Message components fall back to the built-in
168
+ * `StreamingMarkdownDefaultRenderer` (via `CopilotChatAssistantMessage.MarkdownRenderer`)
169
+ * when this is `undefined`.
170
+ */
171
+ function useMarkdownRenderer() {
172
+ return useContext(MarkdownRendererContext);
173
+ }
174
+
175
+ //#endregion
176
+ //#region src/generative-ui/markdown/ProviderMarkdown.tsx
177
+ /**
178
+ * Markdown prose inside generative UI, rendered like the chat text around
179
+ * it: the renderer set on the provider when there is one, else the built-in
180
+ * streaming renderer. Config passed here wins over provider config.
181
+ */
182
+ function ProviderMarkdown({ content, isStreaming, className, ...config }) {
183
+ const renderer = useMarkdownRenderer();
184
+ if (renderer && isReactComponentType(renderer)) return /* @__PURE__ */ jsx(renderer, {
185
+ content,
186
+ isStreaming,
187
+ className
188
+ });
189
+ return /* @__PURE__ */ jsx(StreamingMarkdownDefaultRenderer, {
190
+ ...renderer,
191
+ ...config,
192
+ content,
193
+ isStreaming,
194
+ className
195
+ });
196
+ }
197
+
198
+ //#endregion
199
+ //#region src/generative-ui/markdown/MarkdownSurfaces.tsx
200
+ const FADE_STYLE_ID = "a2ui-markdown-fade";
201
+ /**
202
+ * Components fade in as they stream: each element that appears under a
203
+ * markdown surface runs the keyframes once on mount. React keeps the keys
204
+ * stable per component id, so an element that is already there never
205
+ * animates again. SVG internals are left out: a chart library re-creates
206
+ * its nodes on each render, and a fade on each of them would read as the
207
+ * chart flashing whenever a sibling arrives. The fade runs under reduced
208
+ * motion too, because it moves nothing.
209
+ */
210
+ 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");
211
+ const noEffect = () => {};
212
+ const useInjectEffect = typeof document === "undefined" ? noEffect : useInsertionEffect;
213
+ function useFadeStyles() {
214
+ useInjectEffect(() => {
215
+ if (document.getElementById(FADE_STYLE_ID)) return;
216
+ const style = document.createElement("style");
217
+ style.id = FADE_STYLE_ID;
218
+ style.textContent = FADE_CSS;
219
+ document.head.appendChild(style);
220
+ }, []);
221
+ }
222
+ /**
223
+ * The default wrapper of a chat surface in the markdown transport. It draws
224
+ * no box: a surface sits in the flow of the reply like a paragraph, and a
225
+ * Card draws its own box when it is interactive. Nothing shows while the
226
+ * surface streams. A rejected operation gets one line.
227
+ */
228
+ function DefaultMarkdownChatSurface({ surfaceId, error, children }) {
229
+ useFadeStyles();
230
+ return /* @__PURE__ */ jsxs("div", {
231
+ "data-generative-ui-chat-surface": surfaceId,
232
+ "data-a2ui-markdown-surface": surfaceId,
233
+ className: "cpk-markdown-chat-surface",
234
+ children: [children, error && /* @__PURE__ */ jsx("div", {
235
+ role: "alert",
236
+ className: "cpk-markdown-chat-surface-error",
237
+ children: "Part of this UI couldn't be shown."
238
+ })]
239
+ });
240
+ }
241
+ /**
242
+ * One chat surface in the chat wrapper. Nothing renders until the surface
243
+ * has its root component, so a half-streamed fence shows no empty card.
244
+ */
245
+ function ChatSurface({ runtime, threadId, surfaceId, Wrapper }) {
246
+ const surface = runtime.manager.getSurface(threadId, surfaceId) ?? runtime.manager.getFailedSurface(threadId, surfaceId);
247
+ const root = surface?.model.componentsModel.get(GENERATIVE_UI_ROOT_ID);
248
+ if (!surface || !root && !surface.failed) return null;
249
+ const rejected = [...surface.serverRejected, ...surface.clientRejected];
250
+ const error = rejected.length ? new Error(`${rejected.length} UI update(s) could not be shown`, { cause: rejected }) : void 0;
251
+ return /* @__PURE__ */ jsx(Wrapper, {
252
+ surfaceId,
253
+ isStreaming: surface.status === "streaming",
254
+ error,
255
+ rejected,
256
+ children: surface.failed ? null : /* @__PURE__ */ jsx(SurfaceView, { surface })
257
+ });
258
+ }
259
+ /** The blocks of one fence: lifted prose and chat surfaces, in order. */
260
+ function FenceBlocks({ blocks, runtime, threadId, isStreaming, markdownProps }) {
261
+ const Wrapper = useContext(GenerativeUIChatSlotContext) ?? DefaultMarkdownChatSurface;
262
+ let surfaceCount = 0;
263
+ return /* @__PURE__ */ jsx(Fragment$1, { children: blocks.map((block, index) => {
264
+ if (block.kind === "markdown") return /* @__PURE__ */ jsx(ProviderMarkdown, {
265
+ ...markdownProps,
266
+ content: block.markdown,
267
+ isStreaming: isStreaming && index === blocks.length - 1
268
+ }, `md-${surfaceCount}`);
269
+ surfaceCount++;
270
+ return /* @__PURE__ */ jsx(ChatSurface, {
271
+ runtime,
272
+ threadId,
273
+ surfaceId: block.surfaceId,
274
+ Wrapper
275
+ }, block.surfaceId);
276
+ }) });
277
+ }
278
+ /**
279
+ * Experimental. Renders an assistant message of the markdown transport.
280
+ * Prose renders as markdown. In place of each ```a2ui fence:
281
+ *
282
+ * - the fence that created a chat surface renders that surface (and the
283
+ * prose lifted out of it) in the chat wrapper;
284
+ * - every other fence renders nothing: a fence that updates the surface of
285
+ * an earlier fence, or a fence for a named target, which
286
+ * `<GenerativeUISurface id>` renders.
287
+ *
288
+ * Use it inside `<CopilotKitProvider generativeUI={{ ui, transport: "markdown" }}>`.
289
+ * `CopilotChatAssistantMessage` uses it there on its own.
290
+ *
291
+ * @example
292
+ * ```tsx
293
+ * <MarkdownSurfaces content={message.content} messageId={message.id} />
294
+ * ```
295
+ */
296
+ function MarkdownSurfaces({ content, messageId, isStreaming = false, ...markdownProps }) {
297
+ const runtime = useRequiredGenerativeUIRuntime();
298
+ const chatThreadId = useCopilotChatConfiguration()?.threadId;
299
+ useManagerVersion(runtime);
300
+ const segments = useMemo(() => splitA2UIMarkdown(content), [content]);
301
+ const threadId = chatThreadId ?? runtime.manager.getActiveThread();
302
+ const source = getMarkdownSurfaceSource(runtime);
303
+ return /* @__PURE__ */ jsx(Fragment$1, { children: segments.map((segment, index) => {
304
+ const isLast = index === segments.length - 1;
305
+ if (segment.type === "markdown") return /* @__PURE__ */ jsx(ProviderMarkdown, {
306
+ ...markdownProps,
307
+ content: segment.text,
308
+ isStreaming: isStreaming && isLast
309
+ }, `md-${index}`);
310
+ const blocks = threadId ? source.getFenceBlocks(threadId, messageId, segment.index) : void 0;
311
+ if (!threadId || !blocks) return null;
312
+ return /* @__PURE__ */ jsx(FenceBlocks, {
313
+ blocks,
314
+ runtime,
315
+ threadId,
316
+ isStreaming: isStreaming && isLast,
317
+ markdownProps
318
+ }, `a2ui-${segment.index}`);
319
+ }) });
320
+ }
321
+
322
+ //#endregion
323
+ export { isReactComponentType as a, IconSvg as c, useMarkdownRenderer as i, cn as l, ProviderMarkdown as n, renderSlot as o, MarkdownRendererProvider as r, CopilotIcon as s, MarkdownSurfaces as t, StreamingMarkdownDefaultRenderer as u };
324
+ //# sourceMappingURL=MarkdownSurfaces-Byz821bg.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarkdownSurfaces-Byz821bg.mjs","names":[],"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,+BAA8B,QAAQ;AACtC,QACE,oBAAC;EACY;EACX,YAAY,CAAC;EACb,OAAO,SAAS,CAAC,CAAC;EACH;EACf,gBAAgB;EACP;EACI;EACI;YAEhB;GACyB;;AAIhC,iCAAiC,cAC/B;;;;;ACvCF,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