@copilotkit/react-core 1.83.0 → 2.0.0-rc.0

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 (75) hide show
  1. package/dist/{runtime-context-CrHq-iTf.d.mts → MarkdownRendererContext-B4Us6mwL.d.cts} +127 -97
  2. package/dist/MarkdownRendererContext-B4Us6mwL.d.cts.map +1 -0
  3. package/dist/{runtime-context-D3NcP9oE.d.cts → MarkdownRendererContext-CRKFzsEB.d.mts} +127 -97
  4. package/dist/MarkdownRendererContext-CRKFzsEB.d.mts.map +1 -0
  5. package/dist/{MarkdownSurfaces-FF5za2kU.cjs → MarkdownSurfaces-C2XZISKn.cjs} +203 -55
  6. package/dist/MarkdownSurfaces-C2XZISKn.cjs.map +1 -0
  7. package/dist/{MarkdownSurfaces-DGpjmPaB.mjs → MarkdownSurfaces-ChSlVYOk.mjs} +171 -47
  8. package/dist/MarkdownSurfaces-ChSlVYOk.mjs.map +1 -0
  9. package/dist/{v2/context.cjs → context.cjs} +2 -2
  10. package/dist/context.cjs.map +1 -0
  11. package/dist/{v2/context.d.cts → context.d.cts} +5 -5
  12. package/dist/context.d.cts.map +1 -0
  13. package/dist/{v2/context.d.mts → context.d.mts} +5 -5
  14. package/dist/context.d.mts.map +1 -0
  15. package/dist/{v2/context.mjs → context.mjs} +2 -2
  16. package/dist/context.mjs.map +1 -0
  17. package/dist/{v2/generative-ui.cjs → generative-ui.cjs} +40 -43
  18. package/dist/generative-ui.cjs.map +1 -0
  19. package/dist/{v2/generative-ui.d.cts → generative-ui.d.cts} +14 -12
  20. package/dist/generative-ui.d.cts.map +1 -0
  21. package/dist/{v2/generative-ui.d.mts → generative-ui.d.mts} +14 -12
  22. package/dist/generative-ui.d.mts.map +1 -0
  23. package/dist/{v2/generative-ui.mjs → generative-ui.mjs} +40 -43
  24. package/dist/generative-ui.mjs.map +1 -0
  25. package/dist/{v2/headless.cjs → headless.cjs} +68 -53
  26. package/dist/headless.cjs.map +1 -0
  27. package/dist/{v2/headless.d.cts → headless.d.cts} +24 -23
  28. package/dist/headless.d.cts.map +1 -0
  29. package/dist/{v2/headless.d.mts → headless.d.mts} +21 -20
  30. package/dist/headless.d.mts.map +1 -0
  31. package/dist/{v2/headless.mjs → headless.mjs} +51 -36
  32. package/dist/headless.mjs.map +1 -0
  33. package/dist/index.cjs +15391 -1862
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.css +2 -0
  36. package/dist/index.d.cts +3252 -1370
  37. package/dist/index.d.cts.map +1 -1
  38. package/dist/index.d.mts +3234 -1369
  39. package/dist/index.d.mts.map +1 -1
  40. package/dist/index.mjs +13733 -1815
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/index.umd.js +11944 -5481
  43. package/dist/index.umd.js.map +1 -1
  44. package/package.json +21 -30
  45. package/dist/MarkdownSurfaces-DGpjmPaB.mjs.map +0 -1
  46. package/dist/MarkdownSurfaces-FF5za2kU.cjs.map +0 -1
  47. package/dist/copilotkit-BuIuo-Z1.cjs +0 -16531
  48. package/dist/copilotkit-BuIuo-Z1.cjs.map +0 -1
  49. package/dist/copilotkit-C765tOUi.d.mts +0 -4112
  50. package/dist/copilotkit-C765tOUi.d.mts.map +0 -1
  51. package/dist/copilotkit-DyxwF9wL.mjs +0 -16025
  52. package/dist/copilotkit-DyxwF9wL.mjs.map +0 -1
  53. package/dist/copilotkit-wqaNanhw.d.cts +0 -4129
  54. package/dist/copilotkit-wqaNanhw.d.cts.map +0 -1
  55. package/dist/runtime-context-CrHq-iTf.d.mts.map +0 -1
  56. package/dist/runtime-context-D3NcP9oE.d.cts.map +0 -1
  57. package/dist/v2/context.cjs.map +0 -1
  58. package/dist/v2/context.d.cts.map +0 -1
  59. package/dist/v2/context.d.mts.map +0 -1
  60. package/dist/v2/context.mjs.map +0 -1
  61. package/dist/v2/generative-ui.cjs.map +0 -1
  62. package/dist/v2/generative-ui.d.cts.map +0 -1
  63. package/dist/v2/generative-ui.d.mts.map +0 -1
  64. package/dist/v2/generative-ui.mjs.map +0 -1
  65. package/dist/v2/headless.cjs.map +0 -1
  66. package/dist/v2/headless.d.cts.map +0 -1
  67. package/dist/v2/headless.d.mts.map +0 -1
  68. package/dist/v2/headless.mjs.map +0 -1
  69. package/dist/v2/index.cjs +0 -1635
  70. package/dist/v2/index.css +0 -2
  71. package/dist/v2/index.d.cts +0 -4
  72. package/dist/v2/index.d.mts +0 -4
  73. package/dist/v2/index.mjs +0 -8
  74. package/dist/v2/index.umd.js +0 -20695
  75. package/dist/v2/index.umd.js.map +0 -1
@@ -25,17 +25,55 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  }) : target, mod));
26
26
 
27
27
  //#endregion
28
+ let _copilotkit_core = require("@copilotkit/core");
28
29
  let react = require("react");
29
30
  react = __toESM(react);
30
- let _copilotkit_core = require("@copilotkit/core");
31
- let _copilotkit_shared = require("@copilotkit/shared");
32
- let _copilotkit_react_core_v2_context = require("@copilotkit/react-core/v2/context");
33
31
  let react_jsx_runtime = require("react/jsx-runtime");
34
- let streamdown = require("streamdown");
32
+ let _copilotkit_markdown_renderer_react = require("@copilotkit/markdown-renderer/react");
33
+ let _copilotkit_markdown_renderer = require("@copilotkit/markdown-renderer");
34
+ let tailwind_merge = require("tailwind-merge");
35
+ let _copilotkit_shared = require("@copilotkit/shared");
36
+ let _copilotkit_react_core_context = require("@copilotkit/react-core/context");
35
37
  let zod = require("zod");
36
38
  let zod_to_json_schema = require("zod-to-json-schema");
37
39
 
38
- //#region src/v2/lib/shallow-stable-ref.ts
40
+ //#region src/components/chat/StreamingMarkdownDefaultRenderer.tsx
41
+ const defaultNodeRenderers = (0, _copilotkit_markdown_renderer_react.createStreamingMarkdownNodeRenderers)({ codeBlock: ({ node }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
42
+ className: "cpk:overflow-x-auto cpk:rounded-lg cpk:bg-muted cpk:text-foreground cpk:p-3",
43
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
44
+ "data-code-info": node.info ?? void 0,
45
+ children: node.text
46
+ })
47
+ }) });
48
+ /**
49
+ * react-core's built-in default markdown renderer — a thin adapter over
50
+ * `@copilotkit/markdown-renderer`'s streaming renderer. Maps the pluggable
51
+ * renderer contract (`{ content, isStreaming, className }`) onto the streaming
52
+ * renderer for streaming-safe incremental rendering + per-token animation.
53
+ * Still overridable via the slot/provider pluggable interface.
54
+ */
55
+ function StreamingMarkdownDefaultRenderer({ content, isStreaming, className, nodeRenderers, caret, options, onLinkClick, onCitationClick }) {
56
+ const mergedNodeRenderers = (0, react.useMemo)(() => nodeRenderers ? (0, _copilotkit_markdown_renderer_react.createStreamingMarkdownNodeRenderers)({
57
+ ...defaultNodeRenderers,
58
+ ...nodeRenderers
59
+ }) : defaultNodeRenderers, [nodeRenderers]);
60
+ if (!content) return null;
61
+ (0, _copilotkit_markdown_renderer.warnUnsupportedRichSyntaxOnce)(content);
62
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_copilotkit_markdown_renderer_react.StreamingMarkdownRenderer, {
63
+ className,
64
+ isComplete: !isStreaming,
65
+ caret: caret ?? !!isStreaming,
66
+ nodeRenderers: mergedNodeRenderers,
67
+ options,
68
+ onLinkClick,
69
+ onCitationClick,
70
+ children: content
71
+ });
72
+ }
73
+ StreamingMarkdownDefaultRenderer.displayName = "StreamingMarkdownDefaultRenderer";
74
+
75
+ //#endregion
76
+ //#region src/lib/shallow-stable-ref.ts
39
77
  /**
40
78
  * Shallow equality comparison for objects.
41
79
  */
@@ -77,7 +115,7 @@ function useShallowStableRef(value) {
77
115
  }
78
116
 
79
117
  //#endregion
80
- //#region src/v2/providers/CopilotChatConfigurationProvider.tsx
118
+ //#region src/providers/CopilotChatConfigurationProvider.tsx
81
119
  const CopilotChatDefaultLabels = {
82
120
  chatInputPlaceholder: "Type a message...",
83
121
  chatInputToolbarStartTranscribeButtonLabel: "Transcribe",
@@ -151,7 +189,7 @@ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId,
151
189
  ...parentConfig?.labels,
152
190
  ...stableLabels
153
191
  }), [stableLabels, parentConfig?.labels]);
154
- const providerAgentId = (0, _copilotkit_react_core_v2_context.useDefaultAgentId)();
192
+ const providerAgentId = (0, _copilotkit_react_core_context.useDefaultAgentId)();
155
193
  const resolvedAgentId = agentId ?? parentConfig?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
156
194
  const threadIdPropIsAuthoritative = threadId !== void 0 && hasExplicitThreadId !== false;
157
195
  const isThreadIdControlled = threadIdPropIsAuthoritative;
@@ -168,7 +206,7 @@ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId,
168
206
  parentConfig?.threadId,
169
207
  activeThreadOverride
170
208
  ]);
171
- const copilotkit = (0, react.useContext)(_copilotkit_react_core_v2_context.CopilotKitContext)?.copilotkit;
209
+ const copilotkit = (0, react.useContext)(_copilotkit_react_core_context.CopilotKitContext)?.copilotkit;
172
210
  const openThreadRef = (0, react.useRef)(null);
173
211
  const latestThreadIdRef = (0, react.useRef)(resolvedThreadId);
174
212
  latestThreadIdRef.current = resolvedThreadId;
@@ -380,26 +418,85 @@ const ControlledModalOpenScope = ({ children, open, onOpenChange }) => {
380
418
  ControlledModalOpenScope.displayName = "ControlledModalOpenScope";
381
419
 
382
420
  //#endregion
383
- //#region src/v2/hooks/useKatexStyles.ts
384
- let injected = false;
421
+ //#region src/lib/slots.tsx
385
422
  /**
386
- * Dynamically injects KaTeX CSS at runtime to avoid the Next.js
387
- * "Global CSS cannot be imported from within node_modules" build error.
388
- *
389
- * Uses a singleton flag so the stylesheet is only injected once.
423
+ * Check if a value is a React component type (function, class, forwardRef, memo, etc.)
390
424
  */
391
- function useKatexStyles() {
392
- (0, react.useEffect)(() => {
393
- if (injected || typeof document === "undefined") return;
394
- injected = true;
395
- import("katex/dist/katex.min.css").catch(() => {
396
- console.warn("[CopilotKit] Failed to load katex styles — math content may render without formatting");
425
+ function isReactComponentType(value) {
426
+ if (typeof value === "function") return true;
427
+ if (value && typeof value === "object" && "$$typeof" in value && !react.default.isValidElement(value)) return true;
428
+ return false;
429
+ }
430
+ /**
431
+ * Internal function to render a slot value as a React element (non-memoized).
432
+ */
433
+ function renderSlotElement(slot, DefaultComponent, props) {
434
+ if (typeof slot === "string") {
435
+ const existingClassName = props.className;
436
+ return react.default.createElement(DefaultComponent, {
437
+ ...props,
438
+ className: (0, tailwind_merge.twMerge)(existingClassName, slot)
397
439
  });
398
- }, []);
440
+ }
441
+ if (isReactComponentType(slot)) return react.default.createElement(slot, props);
442
+ if (slot && typeof slot === "object" && !react.default.isValidElement(slot)) return react.default.createElement(DefaultComponent, {
443
+ ...props,
444
+ ...slot
445
+ });
446
+ return react.default.createElement(DefaultComponent, props);
447
+ }
448
+ /**
449
+ * Internal memoized wrapper component for renderSlot.
450
+ * Uses forwardRef to support ref forwarding.
451
+ */
452
+ const MemoizedSlotWrapper = react.default.memo(react.default.forwardRef(function MemoizedSlotWrapper(props, ref) {
453
+ const { $slot, $component, ...rest } = props;
454
+ return renderSlotElement($slot, $component, ref !== null ? {
455
+ ...rest,
456
+ ref
457
+ } : rest);
458
+ }), (prev, next) => {
459
+ if (prev.$slot !== next.$slot) return false;
460
+ if (prev.$component !== next.$component) return false;
461
+ const { $slot: _ps, $component: _pc, ...prevRest } = prev;
462
+ const { $slot: _ns, $component: _nc, ...nextRest } = next;
463
+ return shallowEqual(prevRest, nextRest);
464
+ });
465
+ /**
466
+ * Renders a slot value as a memoized React element.
467
+ * Automatically prevents unnecessary re-renders using shallow prop comparison.
468
+ * Supports ref forwarding.
469
+ *
470
+ * @example
471
+ * renderSlot(customInput, CopilotChatInput, { onSubmit: handleSubmit })
472
+ */
473
+ function renderSlot(slot, DefaultComponent, props) {
474
+ return react.default.createElement(MemoizedSlotWrapper, {
475
+ ...props,
476
+ $slot: slot,
477
+ $component: DefaultComponent
478
+ });
479
+ }
480
+
481
+ //#endregion
482
+ //#region src/providers/MarkdownRendererContext.tsx
483
+ const MarkdownRendererContext = (0, react.createContext)(void 0);
484
+ const MarkdownRendererProvider = ({ renderer, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MarkdownRendererContext.Provider, {
485
+ value: renderer,
486
+ children
487
+ });
488
+ /**
489
+ * The markdown renderer set at the provider level, or `undefined` when none was
490
+ * supplied. Message components fall back to the built-in
491
+ * `StreamingMarkdownDefaultRenderer` (via `CopilotChatAssistantMessage.MarkdownRenderer`)
492
+ * when this is `undefined`.
493
+ */
494
+ function useMarkdownRenderer() {
495
+ return (0, react.useContext)(MarkdownRendererContext);
399
496
  }
400
497
 
401
498
  //#endregion
402
- //#region src/v2/types/defineToolCallRenderer.ts
499
+ //#region src/types/defineToolCallRenderer.ts
403
500
  function defineToolCallRenderer(def) {
404
501
  const argsSchema = def.name === "*" && !def.args ? zod.z.any() : def.args;
405
502
  return {
@@ -412,7 +509,7 @@ function defineToolCallRenderer(def) {
412
509
  }
413
510
 
414
511
  //#endregion
415
- //#region src/v2/generative-ui/json-schema.ts
512
+ //#region src/generative-ui/json-schema.ts
416
513
  /**
417
514
  * JSON Schema for a Standard Schema (zod v3 via zod-to-json-schema),
418
515
  * inlined, no `$schema`. A prop marked by `child()` or `childList()`
@@ -424,7 +521,7 @@ function toJsonSchema(schema) {
424
521
  }
425
522
 
426
523
  //#endregion
427
- //#region src/v2/generative-ui/catalog.ts
524
+ //#region src/generative-ui/catalog.ts
428
525
  /** The A2UI component envelope: `id`, `component`, `catalogId`, `accessibility`, `metadata`. */
429
526
  const RESERVED_KEYS = new Set([
430
527
  "id",
@@ -727,14 +824,14 @@ function toManifest(definition, modelProps, modelEvents) {
727
824
  }
728
825
 
729
826
  //#endregion
730
- //#region src/v2/generative-ui/is-record.ts
827
+ //#region src/generative-ui/is-record.ts
731
828
  /** True for a plain object: not null, not an array. Internal, not exported. */
732
829
  function isRecord(value) {
733
830
  return typeof value === "object" && value !== null && !Array.isArray(value);
734
831
  }
735
832
 
736
833
  //#endregion
737
- //#region src/v2/generative-ui/errors.ts
834
+ //#region src/generative-ui/errors.ts
738
835
  var GenerativeUIError = class extends Error {
739
836
  constructor(code, message) {
740
837
  super(message);
@@ -744,7 +841,7 @@ var GenerativeUIError = class extends Error {
744
841
  };
745
842
 
746
843
  //#endregion
747
- //#region src/v2/generative-ui/functions.ts
844
+ //#region src/generative-ui/functions.ts
748
845
  /**
749
846
  * The renderer-side functions of the A2UI 1.0 basic catalog. Each one takes
750
847
  * resolved args (no bindings left in them) and gives a plain value. They
@@ -939,7 +1036,7 @@ function givesValidationResult(name) {
939
1036
  }
940
1037
 
941
1038
  //#endregion
942
- //#region src/v2/generative-ui/markdown/source.ts
1039
+ //#region src/generative-ui/markdown/source.ts
943
1040
  /**
944
1041
  * Values by key, from the latest build. A value that a build does not use
945
1042
  * is dropped at the end of that build, so the cache does not grow.
@@ -1570,7 +1667,7 @@ function getMarkdownSurfaceSource(runtime) {
1570
1667
  }
1571
1668
 
1572
1669
  //#endregion
1573
- //#region src/v2/generative-ui/calc.ts
1670
+ //#region src/generative-ui/calc.ts
1574
1671
  const MAX_SERIES = 1e3;
1575
1672
  const OPERATORS = [
1576
1673
  "&&",
@@ -1905,7 +2002,7 @@ function series(args) {
1905
2002
  }
1906
2003
 
1907
2004
  //#endregion
1908
- //#region src/v2/generative-ui/resolve.ts
2005
+ //#region src/generative-ui/resolve.ts
1909
2006
  BASIC_FUNCTIONS.calc = calc;
1910
2007
  BASIC_FUNCTIONS.series = series;
1911
2008
  const NO_DATA = { get: () => void 0 };
@@ -2176,7 +2273,7 @@ var ExpressionParser = class {
2176
2273
  };
2177
2274
 
2178
2275
  //#endregion
2179
- //#region src/v2/generative-ui/schema.ts
2276
+ //#region src/generative-ui/schema.ts
2180
2277
  const ASYNC_ISSUE = { message: "the schema validates asynchronously; component props and state need a schema that validates synchronously" };
2181
2278
  function toResult(result) {
2182
2279
  return result.issues ? {
@@ -2242,7 +2339,7 @@ function formatIssues(issues, fallback = "props") {
2242
2339
  }
2243
2340
 
2244
2341
  //#endregion
2245
- //#region src/v2/generative-ui/runtime-context.ts
2342
+ //#region src/generative-ui/runtime-context.ts
2246
2343
  const GenerativeUIRuntimeContext = (0, react.createContext)(null);
2247
2344
  function useGenerativeUIRuntime() {
2248
2345
  return (0, react.useContext)(GenerativeUIRuntimeContext);
@@ -2265,7 +2362,7 @@ function reportErrorSafely(runtime, info) {
2265
2362
  const GenerativeUINodeContext = (0, react.createContext)(null);
2266
2363
 
2267
2364
  //#endregion
2268
- //#region src/v2/generative-ui/hooks.ts
2365
+ //#region src/generative-ui/hooks.ts
2269
2366
  const noopSubscribe$1 = () => () => {};
2270
2367
  const zero = () => 0;
2271
2368
  /** Re-renders on any surface-manager change. */
@@ -2352,7 +2449,7 @@ function useGenerativeUIFunction(ui, name, handler) {
2352
2449
  }
2353
2450
 
2354
2451
  //#endregion
2355
- //#region src/v2/generative-ui/boundaries.tsx
2452
+ //#region src/generative-ui/boundaries.tsx
2356
2453
  function DefaultNodeFallback({ message, componentId, retry }) {
2357
2454
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2358
2455
  role: "alert",
@@ -2459,7 +2556,7 @@ var SurfaceBoundary = class extends react.Component {
2459
2556
  };
2460
2557
 
2461
2558
  //#endregion
2462
- //#region src/v2/generative-ui/accessibility.ts
2559
+ //#region src/generative-ui/accessibility.ts
2463
2560
  const LIVE = new Set([
2464
2561
  "off",
2465
2562
  "polite",
@@ -2554,7 +2651,7 @@ function wrapperAria(aria) {
2554
2651
  }
2555
2652
 
2556
2653
  //#endregion
2557
- //#region src/v2/generative-ui/events.ts
2654
+ //#region src/generative-ui/events.ts
2558
2655
  /**
2559
2656
  * The context of a running event binding: it reads the surface data model
2560
2657
  * and resolves relative paths against the template item of the component.
@@ -2670,7 +2767,7 @@ function invokeMatchedEvent(params) {
2670
2767
  }
2671
2768
 
2672
2769
  //#endregion
2673
- //#region src/v2/generative-ui/theme.ts
2770
+ //#region src/generative-ui/theme.ts
2674
2771
  /**
2675
2772
  * The built-in dark values. The light values are the fallbacks in the
2676
2773
  * components, so a surface is light when no variable is set.
@@ -2780,7 +2877,7 @@ function themeStyleSheet(theme) {
2780
2877
  }
2781
2878
 
2782
2879
  //#endregion
2783
- //#region src/v2/generative-ui/SurfaceView.tsx
2880
+ //#region src/generative-ui/SurfaceView.tsx
2784
2881
  const NO_ANCESTORS = [];
2785
2882
  const ROOT_STYLE = { display: "contents" };
2786
2883
  const undefinedSnapshot = () => void 0;
@@ -3346,7 +3443,7 @@ function ResolvedNode({ surface, componentId, definition, properties, runtime, b
3346
3443
  }
3347
3444
 
3348
3445
  //#endregion
3349
- //#region src/v2/generative-ui/chat.tsx
3446
+ //#region src/generative-ui/chat.tsx
3350
3447
  const GenerativeUIChatSlotContext = (0, react.createContext)(void 0);
3351
3448
  function DefaultGenerativeUIChatCard({ surfaceId, isStreaming, error, children }) {
3352
3449
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -3421,7 +3518,7 @@ function createGenerativeUIFunctionCallActivityRenderer() {
3421
3518
  }
3422
3519
  /** Hides the raw `render_ui` tool call; the surface activity owns the UX. */
3423
3520
  function GenerativeUIToolCallRenderer() {
3424
- const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
3521
+ const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
3425
3522
  (0, react.useEffect)(() => {
3426
3523
  const renderer = defineToolCallRenderer({
3427
3524
  name: _copilotkit_shared.GENERATIVE_UI_RENDER_TOOL,
@@ -3435,7 +3532,30 @@ function GenerativeUIToolCallRenderer() {
3435
3532
  }
3436
3533
 
3437
3534
  //#endregion
3438
- //#region src/v2/generative-ui/markdown/MarkdownSurfaces.tsx
3535
+ //#region src/generative-ui/markdown/ProviderMarkdown.tsx
3536
+ /**
3537
+ * Markdown prose inside generative UI, rendered like the chat text around
3538
+ * it: the renderer set on the provider when there is one, else the built-in
3539
+ * streaming renderer. Config passed here wins over provider config.
3540
+ */
3541
+ function ProviderMarkdown({ content, isStreaming, className, ...config }) {
3542
+ const renderer = useMarkdownRenderer();
3543
+ if (renderer && isReactComponentType(renderer)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(renderer, {
3544
+ content,
3545
+ isStreaming,
3546
+ className
3547
+ });
3548
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamingMarkdownDefaultRenderer, {
3549
+ ...renderer,
3550
+ ...config,
3551
+ content,
3552
+ isStreaming,
3553
+ className
3554
+ });
3555
+ }
3556
+
3557
+ //#endregion
3558
+ //#region src/generative-ui/markdown/MarkdownSurfaces.tsx
3439
3559
  const FADE_STYLE_ID = "a2ui-markdown-fade";
3440
3560
  /**
3441
3561
  * Components fade in as they stream: each element that appears under a
@@ -3496,13 +3616,14 @@ function ChatSurface({ runtime, threadId, surfaceId, Wrapper }) {
3496
3616
  });
3497
3617
  }
3498
3618
  /** The blocks of one fence: lifted prose and chat surfaces, in order. */
3499
- function FenceBlocks({ blocks, runtime, threadId, markdownProps }) {
3619
+ function FenceBlocks({ blocks, runtime, threadId, isStreaming, markdownProps }) {
3500
3620
  const Wrapper = (0, react.useContext)(GenerativeUIChatSlotContext) ?? DefaultMarkdownChatSurface;
3501
3621
  let surfaceCount = 0;
3502
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: blocks.map((block) => {
3503
- if (block.kind === "markdown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(streamdown.Streamdown, {
3622
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: blocks.map((block, index) => {
3623
+ if (block.kind === "markdown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProviderMarkdown, {
3504
3624
  ...markdownProps,
3505
- children: block.markdown
3625
+ content: block.markdown,
3626
+ isStreaming: isStreaming && index === blocks.length - 1
3506
3627
  }, `md-${surfaceCount}`);
3507
3628
  surfaceCount++;
3508
3629
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChatSurface, {
@@ -3531,7 +3652,7 @@ function FenceBlocks({ blocks, runtime, threadId, markdownProps }) {
3531
3652
  * <MarkdownSurfaces content={message.content} messageId={message.id} />
3532
3653
  * ```
3533
3654
  */
3534
- function MarkdownSurfaces({ content, messageId, ...markdownProps }) {
3655
+ function MarkdownSurfaces({ content, messageId, isStreaming = false, ...markdownProps }) {
3535
3656
  const runtime = useRequiredGenerativeUIRuntime();
3536
3657
  const chatThreadId = useCopilotChatConfiguration()?.threadId;
3537
3658
  useManagerVersion(runtime);
@@ -3539,9 +3660,11 @@ function MarkdownSurfaces({ content, messageId, ...markdownProps }) {
3539
3660
  const threadId = chatThreadId ?? runtime.manager.getActiveThread();
3540
3661
  const source = getMarkdownSurfaceSource(runtime);
3541
3662
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: segments.map((segment, index) => {
3542
- if (segment.type === "markdown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(streamdown.Streamdown, {
3663
+ const isLast = index === segments.length - 1;
3664
+ if (segment.type === "markdown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProviderMarkdown, {
3543
3665
  ...markdownProps,
3544
- children: segment.text
3666
+ content: segment.text,
3667
+ isStreaming: isStreaming && isLast
3545
3668
  }, `md-${index}`);
3546
3669
  const blocks = threadId ? source.getFenceBlocks(threadId, messageId, segment.index) : void 0;
3547
3670
  if (!threadId || !blocks) return null;
@@ -3549,6 +3672,7 @@ function MarkdownSurfaces({ content, messageId, ...markdownProps }) {
3549
3672
  blocks,
3550
3673
  runtime,
3551
3674
  threadId,
3675
+ isStreaming: isStreaming && isLast,
3552
3676
  markdownProps
3553
3677
  }, `a2ui-${segment.index}`);
3554
3678
  }) });
@@ -3627,12 +3751,30 @@ Object.defineProperty(exports, 'GenerativeUIToolCallRenderer', {
3627
3751
  return GenerativeUIToolCallRenderer;
3628
3752
  }
3629
3753
  });
3754
+ Object.defineProperty(exports, 'MarkdownRendererProvider', {
3755
+ enumerable: true,
3756
+ get: function () {
3757
+ return MarkdownRendererProvider;
3758
+ }
3759
+ });
3630
3760
  Object.defineProperty(exports, 'MarkdownSurfaces', {
3631
3761
  enumerable: true,
3632
3762
  get: function () {
3633
3763
  return MarkdownSurfaces;
3634
3764
  }
3635
3765
  });
3766
+ Object.defineProperty(exports, 'ProviderMarkdown', {
3767
+ enumerable: true,
3768
+ get: function () {
3769
+ return ProviderMarkdown;
3770
+ }
3771
+ });
3772
+ Object.defineProperty(exports, 'StreamingMarkdownDefaultRenderer', {
3773
+ enumerable: true,
3774
+ get: function () {
3775
+ return StreamingMarkdownDefaultRenderer;
3776
+ }
3777
+ });
3636
3778
  Object.defineProperty(exports, 'SurfaceView', {
3637
3779
  enumerable: true,
3638
3780
  get: function () {
@@ -3711,6 +3853,12 @@ Object.defineProperty(exports, 'isAsyncIssue', {
3711
3853
  return isAsyncIssue;
3712
3854
  }
3713
3855
  });
3856
+ Object.defineProperty(exports, 'isReactComponentType', {
3857
+ enumerable: true,
3858
+ get: function () {
3859
+ return isReactComponentType;
3860
+ }
3861
+ });
3714
3862
  Object.defineProperty(exports, 'isRecord', {
3715
3863
  enumerable: true,
3716
3864
  get: function () {
@@ -3729,10 +3877,10 @@ Object.defineProperty(exports, 'namedRole', {
3729
3877
  return namedRole;
3730
3878
  }
3731
3879
  });
3732
- Object.defineProperty(exports, 'shallowEqual', {
3880
+ Object.defineProperty(exports, 'renderSlot', {
3733
3881
  enumerable: true,
3734
3882
  get: function () {
3735
- return shallowEqual;
3883
+ return renderSlot;
3736
3884
  }
3737
3885
  });
3738
3886
  Object.defineProperty(exports, 'toJsonSchema', {
@@ -3771,16 +3919,16 @@ Object.defineProperty(exports, 'useGenerativeUIState', {
3771
3919
  return useGenerativeUIState;
3772
3920
  }
3773
3921
  });
3774
- Object.defineProperty(exports, 'useKatexStyles', {
3922
+ Object.defineProperty(exports, 'useManagerVersion', {
3775
3923
  enumerable: true,
3776
3924
  get: function () {
3777
- return useKatexStyles;
3925
+ return useManagerVersion;
3778
3926
  }
3779
3927
  });
3780
- Object.defineProperty(exports, 'useManagerVersion', {
3928
+ Object.defineProperty(exports, 'useMarkdownRenderer', {
3781
3929
  enumerable: true,
3782
3930
  get: function () {
3783
- return useManagerVersion;
3931
+ return useMarkdownRenderer;
3784
3932
  }
3785
3933
  });
3786
3934
  Object.defineProperty(exports, 'useRequiredGenerativeUIRuntime', {
@@ -3813,4 +3961,4 @@ Object.defineProperty(exports, 'wrapperAria', {
3813
3961
  return wrapperAria;
3814
3962
  }
3815
3963
  });
3816
- //# sourceMappingURL=MarkdownSurfaces-FF5za2kU.cjs.map
3964
+ //# sourceMappingURL=MarkdownSurfaces-C2XZISKn.cjs.map