@copilotkit/react-core 2.0.0-rc.42 → 2.0.0-rc.44

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 (91) hide show
  1. package/dist/{MarkdownRendererContext-BL8ct_3U.d.mts → MarkdownRendererContext-QFCldfW_.d.cts} +1 -1
  2. package/dist/{MarkdownRendererContext-BL8ct_3U.d.mts.map → MarkdownRendererContext-QFCldfW_.d.cts.map} +1 -1
  3. package/dist/{MarkdownRendererContext-C2J_lgqF.d.cts → MarkdownRendererContext-aK63ZFd-.d.mts} +1 -1
  4. package/dist/{MarkdownRendererContext-C2J_lgqF.d.cts.map → MarkdownRendererContext-aK63ZFd-.d.mts.map} +1 -1
  5. package/dist/MarkdownSurfaces-Do948N1P.cjs +141 -0
  6. package/dist/MarkdownSurfaces-Do948N1P.cjs.map +1 -0
  7. package/dist/MarkdownSurfaces-rtE9wRUP.mjs +135 -0
  8. package/dist/MarkdownSurfaces-rtE9wRUP.mjs.map +1 -0
  9. package/dist/{MarkdownSurfaces-D2Ck-cbb.cjs → ProviderMarkdown-D0eI0aPo.cjs} +26 -136
  10. package/dist/ProviderMarkdown-D0eI0aPo.cjs.map +1 -0
  11. package/dist/{MarkdownSurfaces-Byz821bg.mjs → ProviderMarkdown-epL7F3Vt.mjs} +22 -132
  12. package/dist/ProviderMarkdown-epL7F3Vt.mjs.map +1 -0
  13. package/dist/accessibility-BLK-gE0R.mjs +129 -0
  14. package/dist/accessibility-BLK-gE0R.mjs.map +1 -0
  15. package/dist/accessibility-GnodqxkH.cjs +228 -0
  16. package/dist/accessibility-GnodqxkH.cjs.map +1 -0
  17. package/dist/{chat-Bf0vVdo7.mjs → chat-B1zczXUD.mjs} +21 -145
  18. package/dist/chat-B1zczXUD.mjs.map +1 -0
  19. package/dist/chat-BZ_bvAkg.d.mts +38 -0
  20. package/dist/chat-BZ_bvAkg.d.mts.map +1 -0
  21. package/dist/{chat-D3fxo6Ah.cjs → chat-CkFZMo5E.cjs} +29 -234
  22. package/dist/chat-CkFZMo5E.cjs.map +1 -0
  23. package/dist/chat-CpZVyF_t.d.cts +38 -0
  24. package/dist/chat-CpZVyF_t.d.cts.map +1 -0
  25. package/dist/context.cjs +2 -2
  26. package/dist/context.cjs.map +1 -1
  27. package/dist/context.d.cts +2 -2
  28. package/dist/context.d.mts +2 -2
  29. package/dist/context.mjs +2 -2
  30. package/dist/context.mjs.map +1 -1
  31. package/dist/generative-ui/map.cjs +26 -0
  32. package/dist/generative-ui/map.cjs.map +1 -0
  33. package/dist/generative-ui/map.d.cts +23 -0
  34. package/dist/generative-ui/map.d.cts.map +1 -0
  35. package/dist/generative-ui/map.d.mts +23 -0
  36. package/dist/generative-ui/map.d.mts.map +1 -0
  37. package/dist/generative-ui/map.mjs +24 -0
  38. package/dist/generative-ui/map.mjs.map +1 -0
  39. package/dist/generative-ui/native.cjs +9 -8
  40. package/dist/generative-ui/native.cjs.map +1 -1
  41. package/dist/generative-ui/native.d.cts +3 -2
  42. package/dist/generative-ui/native.d.cts.map +1 -1
  43. package/dist/generative-ui/native.d.mts +3 -2
  44. package/dist/generative-ui/native.d.mts.map +1 -1
  45. package/dist/generative-ui/native.mjs +4 -3
  46. package/dist/generative-ui/native.mjs.map +1 -1
  47. package/dist/generative-ui.cjs +11 -5767
  48. package/dist/generative-ui.cjs.map +1 -1
  49. package/dist/generative-ui.d.cts +5 -4
  50. package/dist/generative-ui.d.cts.map +1 -1
  51. package/dist/generative-ui.d.mts +6 -5
  52. package/dist/generative-ui.d.mts.map +1 -1
  53. package/dist/generative-ui.mjs +8 -5764
  54. package/dist/generative-ui.mjs.map +1 -1
  55. package/dist/{hooks-BRYonCVu.d.mts → hooks-D2H3iL0N.d.mts} +3 -3
  56. package/dist/{hooks-BRYonCVu.d.mts.map → hooks-D2H3iL0N.d.mts.map} +1 -1
  57. package/dist/{hooks-2Ur8NQhj.d.cts → hooks-Dy8HeEdr.d.cts} +2 -2
  58. package/dist/{hooks-2Ur8NQhj.d.cts.map → hooks-Dy8HeEdr.d.cts.map} +1 -1
  59. package/dist/index.cjs +183 -700
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.cts +11 -103
  62. package/dist/index.d.cts.map +1 -1
  63. package/dist/index.d.mts +11 -103
  64. package/dist/index.d.mts.map +1 -1
  65. package/dist/index.mjs +66 -425
  66. package/dist/index.mjs.map +1 -1
  67. package/dist/index.umd.js +6157 -799
  68. package/dist/index.umd.js.map +1 -1
  69. package/dist/{refs-BIUfn1wb.cjs → refs-B5Dn59Pn.cjs} +2 -2
  70. package/dist/{refs-BIUfn1wb.cjs.map → refs-B5Dn59Pn.cjs.map} +1 -1
  71. package/dist/{refs-CMrRm3ta.mjs → refs-BW15wX_V.mjs} +1 -1
  72. package/dist/{refs-CMrRm3ta.mjs.map → refs-BW15wX_V.mjs.map} +1 -1
  73. package/dist/{chat-DgP2N7bD.d.mts → runtime-context-B7f4M85q.d.mts} +21 -39
  74. package/dist/runtime-context-B7f4M85q.d.mts.map +1 -0
  75. package/dist/{chat-DtHs4alO.d.cts → runtime-context-CIkZS0ap.d.cts} +21 -39
  76. package/dist/runtime-context-CIkZS0ap.d.cts.map +1 -0
  77. package/dist/standard-CSBR4FhM.mjs +5800 -0
  78. package/dist/standard-CSBR4FhM.mjs.map +1 -0
  79. package/dist/standard-DBjcBGyd.cjs +5796 -0
  80. package/dist/standard-DBjcBGyd.cjs.map +1 -0
  81. package/dist/{use-generative-ui-root-C12htqbK.cjs → use-generative-ui-root-CIp0ytE6.cjs} +3 -3
  82. package/dist/{use-generative-ui-root-C12htqbK.cjs.map → use-generative-ui-root-CIp0ytE6.cjs.map} +1 -1
  83. package/dist/{use-generative-ui-root-CVgsDy1f.mjs → use-generative-ui-root-oBqPa6uy.mjs} +3 -2
  84. package/dist/{use-generative-ui-root-CVgsDy1f.mjs.map → use-generative-ui-root-oBqPa6uy.mjs.map} +1 -1
  85. package/package.json +14 -10
  86. package/dist/MarkdownSurfaces-Byz821bg.mjs.map +0 -1
  87. package/dist/MarkdownSurfaces-D2Ck-cbb.cjs.map +0 -1
  88. package/dist/chat-Bf0vVdo7.mjs.map +0 -1
  89. package/dist/chat-D3fxo6Ah.cjs.map +0 -1
  90. package/dist/chat-DgP2N7bD.d.mts.map +0 -1
  91. package/dist/chat-DtHs4alO.d.cts.map +0 -1
@@ -31,4 +31,4 @@ declare const MarkdownRendererProvider: React.FC<{
31
31
  declare function useMarkdownRenderer(): MarkdownRenderer | undefined;
32
32
  //#endregion
33
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
34
+ //# sourceMappingURL=MarkdownRendererContext-QFCldfW_.d.cts.map
@@ -1 +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"}
1
+ {"version":3,"file":"MarkdownRendererContext-QFCldfW_.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"}
@@ -31,4 +31,4 @@ declare const MarkdownRendererProvider: React.FC<{
31
31
  declare function useMarkdownRenderer(): MarkdownRenderer | undefined;
32
32
  //#endregion
33
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
34
+ //# sourceMappingURL=MarkdownRendererContext-aK63ZFd-.d.mts.map
@@ -1 +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"}
1
+ {"version":3,"file":"MarkdownRendererContext-aK63ZFd-.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,141 @@
1
+ const require_accessibility = require('./accessibility-GnodqxkH.cjs');
2
+ const require_ProviderMarkdown = require('./ProviderMarkdown-D0eI0aPo.cjs');
3
+ const require_chat = require('./chat-CkFZMo5E.cjs');
4
+ let _copilotkit_core = require("@copilotkit/core");
5
+ let react = require("react");
6
+ react = require_accessibility.__toESM(react);
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/generative-ui/markdown/MarkdownSurfaces.tsx
12
+ const FADE_STYLE_ID = "a2ui-markdown-fade";
13
+ /**
14
+ * Components fade in as they stream: each element that appears under a
15
+ * markdown surface runs the keyframes once on mount. React keeps the keys
16
+ * stable per component id, so an element that is already there never
17
+ * animates again. SVG internals are left out: a chart library re-creates
18
+ * its nodes on each render, and a fade on each of them would read as the
19
+ * chart flashing whenever a sibling arrives. The fade runs under reduced
20
+ * motion too, because it moves nothing.
21
+ */
22
+ 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");
23
+ const noEffect = () => {};
24
+ const useInjectEffect = typeof document === "undefined" ? noEffect : react.useInsertionEffect;
25
+ function useFadeStyles() {
26
+ useInjectEffect(() => {
27
+ if (document.getElementById(FADE_STYLE_ID)) return;
28
+ const style = document.createElement("style");
29
+ style.id = FADE_STYLE_ID;
30
+ style.textContent = FADE_CSS;
31
+ document.head.appendChild(style);
32
+ }, []);
33
+ }
34
+ /**
35
+ * The default wrapper of a chat surface in the markdown transport. It draws
36
+ * no box: a surface sits in the flow of the reply like a paragraph, and a
37
+ * Card draws its own box when it is interactive. Nothing shows while the
38
+ * surface streams. A rejected operation gets one line.
39
+ */
40
+ function DefaultMarkdownChatSurface({ surfaceId, error, children }) {
41
+ useFadeStyles();
42
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
43
+ "data-generative-ui-chat-surface": surfaceId,
44
+ "data-a2ui-markdown-surface": surfaceId,
45
+ className: "cpk-markdown-chat-surface",
46
+ children: [children, error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
47
+ role: "alert",
48
+ className: "cpk-markdown-chat-surface-error",
49
+ children: "Part of this UI couldn't be shown."
50
+ })]
51
+ });
52
+ }
53
+ /**
54
+ * One chat surface in the chat wrapper. Nothing renders until the surface
55
+ * has its root component, so a half-streamed fence shows no empty card.
56
+ */
57
+ function ChatSurface({ runtime, threadId, surfaceId, Wrapper }) {
58
+ const surface = runtime.manager.getSurface(threadId, surfaceId) ?? runtime.manager.getFailedSurface(threadId, surfaceId);
59
+ const root = surface?.model.componentsModel.get(_copilotkit_shared.GENERATIVE_UI_ROOT_ID);
60
+ if (!surface || !root && !surface.failed) return null;
61
+ const rejected = [...surface.serverRejected, ...surface.clientRejected];
62
+ const error = rejected.length ? new Error(`${rejected.length} UI update(s) could not be shown`, { cause: rejected }) : void 0;
63
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Wrapper, {
64
+ surfaceId,
65
+ isStreaming: surface.status === "streaming",
66
+ error,
67
+ rejected,
68
+ children: surface.failed ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_chat.SurfaceView, { surface })
69
+ });
70
+ }
71
+ /** The blocks of one fence: lifted prose and chat surfaces, in order. */
72
+ function FenceBlocks({ blocks, runtime, threadId, isStreaming, markdownProps }) {
73
+ const Wrapper = (0, react.useContext)(require_chat.GenerativeUIChatSlotContext) ?? DefaultMarkdownChatSurface;
74
+ let surfaceCount = 0;
75
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: blocks.map((block, index) => {
76
+ if (block.kind === "markdown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ProviderMarkdown.ProviderMarkdown, {
77
+ ...markdownProps,
78
+ content: block.markdown,
79
+ isStreaming: isStreaming && index === blocks.length - 1
80
+ }, `md-${surfaceCount}`);
81
+ surfaceCount++;
82
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChatSurface, {
83
+ runtime,
84
+ threadId,
85
+ surfaceId: block.surfaceId,
86
+ Wrapper
87
+ }, block.surfaceId);
88
+ }) });
89
+ }
90
+ /**
91
+ * Experimental. Renders an assistant message of the markdown transport.
92
+ * Prose renders as markdown. In place of each ```a2ui fence:
93
+ *
94
+ * - the fence that created a chat surface renders that surface (and the
95
+ * prose lifted out of it) in the chat wrapper;
96
+ * - every other fence renders nothing: a fence that updates the surface of
97
+ * an earlier fence, or a fence for a named target, which
98
+ * `<GenerativeUISurface id>` renders.
99
+ *
100
+ * Use it inside `<CopilotKitProvider generativeUI={{ ui, transport: "markdown" }}>`.
101
+ * `CopilotChatAssistantMessage` uses it there on its own.
102
+ *
103
+ * @example
104
+ * ```tsx
105
+ * <MarkdownSurfaces content={message.content} messageId={message.id} />
106
+ * ```
107
+ */
108
+ function MarkdownSurfaces({ content, messageId, isStreaming = false, ...markdownProps }) {
109
+ const runtime = require_accessibility.useRequiredGenerativeUIRuntime();
110
+ const chatThreadId = require_chat.useCopilotChatConfiguration()?.threadId;
111
+ require_chat.useManagerVersion(runtime);
112
+ const segments = (0, react.useMemo)(() => (0, _copilotkit_core.splitA2UIMarkdown)(content), [content]);
113
+ const threadId = chatThreadId ?? runtime.manager.getActiveThread();
114
+ const source = (0, _copilotkit_core_generative_ui.getMarkdownSurfaceSource)(runtime);
115
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: segments.map((segment, index) => {
116
+ const isLast = index === segments.length - 1;
117
+ if (segment.type === "markdown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ProviderMarkdown.ProviderMarkdown, {
118
+ ...markdownProps,
119
+ content: segment.text,
120
+ isStreaming: isStreaming && isLast
121
+ }, `md-${index}`);
122
+ const blocks = threadId ? source.getFenceBlocks(threadId, messageId, segment.index) : void 0;
123
+ if (!threadId || !blocks) return null;
124
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FenceBlocks, {
125
+ blocks,
126
+ runtime,
127
+ threadId,
128
+ isStreaming: isStreaming && isLast,
129
+ markdownProps
130
+ }, `a2ui-${segment.index}`);
131
+ }) });
132
+ }
133
+
134
+ //#endregion
135
+ Object.defineProperty(exports, 'MarkdownSurfaces', {
136
+ enumerable: true,
137
+ get: function () {
138
+ return MarkdownSurfaces;
139
+ }
140
+ });
141
+ //# sourceMappingURL=MarkdownSurfaces-Do948N1P.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarkdownSurfaces-Do948N1P.cjs","names":["useInsertionEffect","GENERATIVE_UI_ROOT_ID","SurfaceView","GenerativeUIChatSlotContext","ProviderMarkdown","useRequiredGenerativeUIRuntime","useCopilotChatConfiguration"],"sources":["../src/generative-ui/markdown/MarkdownSurfaces.tsx"],"sourcesContent":["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":";;;;;;;;;;;AAmBA,MAAM,gBAAgB;;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E,2CAACC;GAEC,GAAI;GACJ,SAAS,MAAM;GACf,aAAa,eAAe,UAAU,OAAO,SAAS;KAHjD,MAAM,eAIX;AAGN;AACA,SACE,2CAAC;GAEU;GACC;GACV,WAAW,MAAM;GACR;KAJJ,MAAM,UAKX;GAEJ,GACD;;;;;;;;;;;;;;;;;;;;AAsBP,SAAgB,iBAAiB,EAC/B,SACA,WACA,cAAc,OACd,GAAG,iBACqB;CACxB,MAAM,UAAUC,sDAAgC;CAChD,MAAM,eAAeC,0CAA6B,EAAE;AACpD,gCAAkB,QAAQ;CAC1B,MAAM,4EAA2C,QAAQ,EAAE,CAAC,QAAQ,CAAC;CACrE,MAAM,WAAW,gBAAgB,QAAQ,QAAQ,iBAAiB;CAClE,MAAM,sEAAkC,QAAQ;AAEhD,QACE,mFACG,SAAS,KAAK,SAAS,UAAU;EAChC,MAAM,SAAS,UAAU,SAAS,SAAS;AAC3C,MAAI,QAAQ,SAAS,WACnB,QACE,2CAACF;GAEC,GAAI;GACJ,SAAS,QAAQ;GACjB,aAAa,eAAe;KAHvB,MAAM,QAIX;EAGN,MAAM,SAAS,WACX,OAAO,eAAe,UAAU,WAAW,QAAQ,MAAM,GACzD;AACJ,MAAI,CAAC,YAAY,CAAC,OAAQ,QAAO;AACjC,SACE,2CAAC;GAES;GACC;GACC;GACV,aAAa,eAAe;GACb;KALV,QAAQ,QAAQ,QAMrB;GAEJ,GACD"}
@@ -0,0 +1,135 @@
1
+ import { t as ProviderMarkdown } from "./ProviderMarkdown-epL7F3Vt.mjs";
2
+ import { m as useRequiredGenerativeUIRuntime } from "./accessibility-BLK-gE0R.mjs";
3
+ import { g as useManagerVersion, n as GenerativeUIChatSlotContext, o as SurfaceView, y as useCopilotChatConfiguration } from "./chat-B1zczXUD.mjs";
4
+ import { splitA2UIMarkdown } from "@copilotkit/core";
5
+ import React, { useContext, useInsertionEffect, useMemo } from "react";
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/generative-ui/markdown/MarkdownSurfaces.tsx
11
+ const FADE_STYLE_ID = "a2ui-markdown-fade";
12
+ /**
13
+ * Components fade in as they stream: each element that appears under a
14
+ * markdown surface runs the keyframes once on mount. React keeps the keys
15
+ * stable per component id, so an element that is already there never
16
+ * animates again. SVG internals are left out: a chart library re-creates
17
+ * its nodes on each render, and a fade on each of them would read as the
18
+ * chart flashing whenever a sibling arrives. The fade runs under reduced
19
+ * motion too, because it moves nothing.
20
+ */
21
+ 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");
22
+ const noEffect = () => {};
23
+ const useInjectEffect = typeof document === "undefined" ? noEffect : useInsertionEffect;
24
+ function useFadeStyles() {
25
+ useInjectEffect(() => {
26
+ if (document.getElementById(FADE_STYLE_ID)) return;
27
+ const style = document.createElement("style");
28
+ style.id = FADE_STYLE_ID;
29
+ style.textContent = FADE_CSS;
30
+ document.head.appendChild(style);
31
+ }, []);
32
+ }
33
+ /**
34
+ * The default wrapper of a chat surface in the markdown transport. It draws
35
+ * no box: a surface sits in the flow of the reply like a paragraph, and a
36
+ * Card draws its own box when it is interactive. Nothing shows while the
37
+ * surface streams. A rejected operation gets one line.
38
+ */
39
+ function DefaultMarkdownChatSurface({ surfaceId, error, children }) {
40
+ useFadeStyles();
41
+ return /* @__PURE__ */ jsxs("div", {
42
+ "data-generative-ui-chat-surface": surfaceId,
43
+ "data-a2ui-markdown-surface": surfaceId,
44
+ className: "cpk-markdown-chat-surface",
45
+ children: [children, error && /* @__PURE__ */ jsx("div", {
46
+ role: "alert",
47
+ className: "cpk-markdown-chat-surface-error",
48
+ children: "Part of this UI couldn't be shown."
49
+ })]
50
+ });
51
+ }
52
+ /**
53
+ * One chat surface in the chat wrapper. Nothing renders until the surface
54
+ * has its root component, so a half-streamed fence shows no empty card.
55
+ */
56
+ function ChatSurface({ runtime, threadId, surfaceId, Wrapper }) {
57
+ const surface = runtime.manager.getSurface(threadId, surfaceId) ?? runtime.manager.getFailedSurface(threadId, surfaceId);
58
+ const root = surface?.model.componentsModel.get(GENERATIVE_UI_ROOT_ID);
59
+ if (!surface || !root && !surface.failed) return null;
60
+ const rejected = [...surface.serverRejected, ...surface.clientRejected];
61
+ const error = rejected.length ? new Error(`${rejected.length} UI update(s) could not be shown`, { cause: rejected }) : void 0;
62
+ return /* @__PURE__ */ jsx(Wrapper, {
63
+ surfaceId,
64
+ isStreaming: surface.status === "streaming",
65
+ error,
66
+ rejected,
67
+ children: surface.failed ? null : /* @__PURE__ */ jsx(SurfaceView, { surface })
68
+ });
69
+ }
70
+ /** The blocks of one fence: lifted prose and chat surfaces, in order. */
71
+ function FenceBlocks({ blocks, runtime, threadId, isStreaming, markdownProps }) {
72
+ const Wrapper = useContext(GenerativeUIChatSlotContext) ?? DefaultMarkdownChatSurface;
73
+ let surfaceCount = 0;
74
+ return /* @__PURE__ */ jsx(Fragment$1, { children: blocks.map((block, index) => {
75
+ if (block.kind === "markdown") return /* @__PURE__ */ jsx(ProviderMarkdown, {
76
+ ...markdownProps,
77
+ content: block.markdown,
78
+ isStreaming: isStreaming && index === blocks.length - 1
79
+ }, `md-${surfaceCount}`);
80
+ surfaceCount++;
81
+ return /* @__PURE__ */ jsx(ChatSurface, {
82
+ runtime,
83
+ threadId,
84
+ surfaceId: block.surfaceId,
85
+ Wrapper
86
+ }, block.surfaceId);
87
+ }) });
88
+ }
89
+ /**
90
+ * Experimental. Renders an assistant message of the markdown transport.
91
+ * Prose renders as markdown. In place of each ```a2ui fence:
92
+ *
93
+ * - the fence that created a chat surface renders that surface (and the
94
+ * prose lifted out of it) in the chat wrapper;
95
+ * - every other fence renders nothing: a fence that updates the surface of
96
+ * an earlier fence, or a fence for a named target, which
97
+ * `<GenerativeUISurface id>` renders.
98
+ *
99
+ * Use it inside `<CopilotKitProvider generativeUI={{ ui, transport: "markdown" }}>`.
100
+ * `CopilotChatAssistantMessage` uses it there on its own.
101
+ *
102
+ * @example
103
+ * ```tsx
104
+ * <MarkdownSurfaces content={message.content} messageId={message.id} />
105
+ * ```
106
+ */
107
+ function MarkdownSurfaces({ content, messageId, isStreaming = false, ...markdownProps }) {
108
+ const runtime = useRequiredGenerativeUIRuntime();
109
+ const chatThreadId = useCopilotChatConfiguration()?.threadId;
110
+ useManagerVersion(runtime);
111
+ const segments = useMemo(() => splitA2UIMarkdown(content), [content]);
112
+ const threadId = chatThreadId ?? runtime.manager.getActiveThread();
113
+ const source = getMarkdownSurfaceSource(runtime);
114
+ return /* @__PURE__ */ jsx(Fragment$1, { children: segments.map((segment, index) => {
115
+ const isLast = index === segments.length - 1;
116
+ if (segment.type === "markdown") return /* @__PURE__ */ jsx(ProviderMarkdown, {
117
+ ...markdownProps,
118
+ content: segment.text,
119
+ isStreaming: isStreaming && isLast
120
+ }, `md-${index}`);
121
+ const blocks = threadId ? source.getFenceBlocks(threadId, messageId, segment.index) : void 0;
122
+ if (!threadId || !blocks) return null;
123
+ return /* @__PURE__ */ jsx(FenceBlocks, {
124
+ blocks,
125
+ runtime,
126
+ threadId,
127
+ isStreaming: isStreaming && isLast,
128
+ markdownProps
129
+ }, `a2ui-${segment.index}`);
130
+ }) });
131
+ }
132
+
133
+ //#endregion
134
+ export { MarkdownSurfaces as t };
135
+ //# sourceMappingURL=MarkdownSurfaces-rtE9wRUP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarkdownSurfaces-rtE9wRUP.mjs","names":[],"sources":["../src/generative-ui/markdown/MarkdownSurfaces.tsx"],"sourcesContent":["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":";;;;;;;;;;AAmBA,MAAM,gBAAgB;;;;;;;;;;AAUtB,MAAM,WAAW,CAOf,4CACA,mHACD,CAAC,KAAK,KAAK;AAGZ,MAAM,iBAA4C;AAClD,MAAM,kBACJ,OAAO,aAAa,cAAc,WAAW;AAE/C,SAAS,gBAAgB;AACvB,uBAAsB;AACpB,MAAI,SAAS,eAAe,cAAc,CAAE;EAC5C,MAAM,QAAQ,SAAS,cAAc,QAAQ;AAC7C,QAAM,KAAK;AACX,QAAM,cAAc;AACpB,WAAS,KAAK,YAAY,MAAM;IAC/B,EAAE,CAAC;;;;;;;;AASR,SAAgB,2BAA2B,EACzC,WACA,OACA,YAC+B;AAC/B,gBAAe;AACf,QACE,qBAAC;EACC,mCAAiC;EACjC,8BAA4B;EAC5B,WAAU;aAET,UACA,SACC,oBAAC;GAAI,MAAK;GAAQ,WAAU;aAAkC;IAExD;GAEJ;;;;;;AAiBV,SAAS,YAAY,EACnB,SACA,UACA,WACA,WAMC;CAED,MAAM,UACJ,QAAQ,QAAQ,WAAW,UAAU,UAAU,IAC/C,QAAQ,QAAQ,iBAAiB,UAAU,UAAU;CACvD,MAAM,OAAO,SAAS,MAAM,gBAAgB,IAAI,sBAAsB;AACtE,KAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,QAAQ,OAAS,QAAO;CACnD,MAAM,WAAW,CAAC,GAAG,QAAQ,gBAAgB,GAAG,QAA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ACV,aAAa,eAAe;GACb;KALV,QAAQ,QAAQ,QAMrB;GAEJ,GACD"}
@@ -1,12 +1,10 @@
1
- const require_chat = require('./chat-D3fxo6Ah.cjs');
1
+ const require_accessibility = require('./accessibility-GnodqxkH.cjs');
2
2
  let _copilotkit_core = require("@copilotkit/core");
3
3
  let react = require("react");
4
- react = require_chat.__toESM(react);
4
+ react = require_accessibility.__toESM(react);
5
5
  let _copilotkit_markdown_react = require("@copilotkit/markdown/react");
6
6
  let _copilotkit_markdown = require("@copilotkit/markdown");
7
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
8
 
11
9
  //#region src/components/chat/StreamingMarkdownDefaultRenderer.tsx
12
10
  /**
@@ -33,6 +31,22 @@ function StreamingMarkdownDefaultRenderer({ content, isStreaming, className, nod
33
31
  }
34
32
  StreamingMarkdownDefaultRenderer.displayName = "StreamingMarkdownDefaultRenderer";
35
33
 
34
+ //#endregion
35
+ //#region src/lib/use-latest-ref.ts
36
+ const useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
37
+ /**
38
+ * A ref that holds the latest `value`, for callbacks that run after render
39
+ * (event handlers, controller callbacks). The ref changes in a layout effect,
40
+ * not during render, so a render that React throws away leaves it alone.
41
+ */
42
+ function useLatestRef(value) {
43
+ const ref = (0, react.useRef)(value);
44
+ useIsomorphicLayoutEffect(() => {
45
+ ref.current = value;
46
+ });
47
+ return ref;
48
+ }
49
+
36
50
  //#endregion
37
51
  //#region src/components/icons/CopilotIcon.tsx
38
52
  /** Turns SVG attribute names such as `stroke-width` into React's `strokeWidth`. */
@@ -138,7 +152,7 @@ const MemoizedSlotWrapper = react.default.memo(react.default.forwardRef(function
138
152
  if (prev.$component !== next.$component) return false;
139
153
  const { $slot: _ps, $component: _pc, ...prevRest } = prev;
140
154
  const { $slot: _ns, $component: _nc, ...nextRest } = next;
141
- return require_chat.shallowEqual(prevRest, nextRest);
155
+ return require_accessibility.shallowEqual(prevRest, nextRest);
142
156
  });
143
157
  /**
144
158
  * Renders a slot value as a memoized React element.
@@ -196,130 +210,6 @@ function ProviderMarkdown({ content, isStreaming, className, ...config }) {
196
210
  });
197
211
  }
198
212
 
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
213
  //#endregion
324
214
  Object.defineProperty(exports, 'CopilotIcon', {
325
215
  enumerable: true,
@@ -339,12 +229,6 @@ Object.defineProperty(exports, 'MarkdownRendererProvider', {
339
229
  return MarkdownRendererProvider;
340
230
  }
341
231
  });
342
- Object.defineProperty(exports, 'MarkdownSurfaces', {
343
- enumerable: true,
344
- get: function () {
345
- return MarkdownSurfaces;
346
- }
347
- });
348
232
  Object.defineProperty(exports, 'ProviderMarkdown', {
349
233
  enumerable: true,
350
234
  get: function () {
@@ -369,10 +253,16 @@ Object.defineProperty(exports, 'renderSlot', {
369
253
  return renderSlot;
370
254
  }
371
255
  });
256
+ Object.defineProperty(exports, 'useLatestRef', {
257
+ enumerable: true,
258
+ get: function () {
259
+ return useLatestRef;
260
+ }
261
+ });
372
262
  Object.defineProperty(exports, 'useMarkdownRenderer', {
373
263
  enumerable: true,
374
264
  get: function () {
375
265
  return useMarkdownRenderer;
376
266
  }
377
267
  });
378
- //# sourceMappingURL=MarkdownSurfaces-D2Ck-cbb.cjs.map
268
+ //# sourceMappingURL=ProviderMarkdown-D0eI0aPo.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProviderMarkdown-D0eI0aPo.cjs","names":["StreamingMarkdownRenderer","CHAT_MARKDOWN_NODE_CLASS_NAMES","useEffect","useLayoutEffect","ɵcopilotIconSvgAttributes","ɵcopilotIcons","React","shallowEqual"],"sources":["../src/components/chat/StreamingMarkdownDefaultRenderer.tsx","../src/lib/use-latest-ref.ts","../src/components/icons/CopilotIcon.tsx","../src/lib/slots.tsx","../src/providers/MarkdownRendererContext.tsx","../src/generative-ui/markdown/ProviderMarkdown.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 { useEffect, useLayoutEffect, useRef } from \"react\";\nimport type { MutableRefObject } from \"react\";\n\n// A layout effect does nothing on the server, and React 18 warns about it.\nconst useIsomorphicLayoutEffect =\n typeof window === \"undefined\" ? useEffect : useLayoutEffect;\n\n/**\n * A ref that holds the latest `value`, for callbacks that run after render\n * (event handlers, controller callbacks). The ref changes in a layout effect,\n * not during render, so a render that React throws away leaves it alone.\n */\nexport function useLatestRef<T>(value: T): MutableRefObject<T> {\n const ref = useRef(value);\n useIsomorphicLayoutEffect(() => {\n ref.current = value;\n });\n return ref;\n}\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"],"mappings":";;;;;;;;;;;;;;;;AAoBA,SAAgB,iCAAiC,EAC/C,SACA,aACA,WACA,eACA,OACA,SACA,aACA,mBACuD;AACvD,KAAI,CAAC,QAAS,QAAO;AAGrB,yDAA8B,QAAQ;AACtC,QACE,2CAACA;EACY;EACX,YAAY,CAAC;EACb,OAAO,SAAS,CAAC,CAAC;EACH;EACf,gBAAgBC;EACP;EACI;EACI;YAEhB;GACyB;;AAIhC,iCAAiC,cAC/B;;;;AC/CF,MAAM,4BACJ,OAAO,WAAW,cAAcC,kBAAYC;;;;;;AAO9C,SAAgB,aAAgB,OAA+B;CAC7D,MAAM,wBAAa,MAAM;AACzB,iCAAgC;AAC9B,MAAI,UAAU;GACd;AACF,QAAO;;;;;;ACLT,SAAS,kBAAkB,YAA8C;AACvE,QAAO,OAAO,YACZ,OAAO,QAAQ,WAAW,CAAC,KAAK,CAAC,KAAK,WAAW,CAC/C,IAAI,QAAQ,cAAc,QAAQ,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