@copilotkit/react-core 2.0.0-rc.2 → 2.0.0-rc.20

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 (47) hide show
  1. package/dist/{MarkdownRendererContext-B4Us6mwL.d.cts → MarkdownRendererContext-Bsl28Gmn.d.mts} +17 -33
  2. package/dist/MarkdownRendererContext-Bsl28Gmn.d.mts.map +1 -0
  3. package/dist/{MarkdownRendererContext-CRKFzsEB.d.mts → MarkdownRendererContext-CBppkb5j.d.cts} +17 -33
  4. package/dist/MarkdownRendererContext-CBppkb5j.d.cts.map +1 -0
  5. package/dist/{MarkdownSurfaces-Bd--93O1.mjs → MarkdownSurfaces-Bt7TD_U1.mjs} +177 -136
  6. package/dist/MarkdownSurfaces-Bt7TD_U1.mjs.map +1 -0
  7. package/dist/{MarkdownSurfaces-S4wfUl3J.cjs → MarkdownSurfaces-CoUoPhR9.cjs} +198 -156
  8. package/dist/MarkdownSurfaces-CoUoPhR9.cjs.map +1 -0
  9. package/dist/context.cjs +28 -26
  10. package/dist/context.cjs.map +1 -1
  11. package/dist/context.d.cts +38 -98
  12. package/dist/context.d.cts.map +1 -1
  13. package/dist/context.d.mts +38 -98
  14. package/dist/context.d.mts.map +1 -1
  15. package/dist/context.mjs +28 -26
  16. package/dist/context.mjs.map +1 -1
  17. package/dist/generative-ui.cjs +570 -567
  18. package/dist/generative-ui.cjs.map +1 -1
  19. package/dist/generative-ui.d.cts +2137 -4178
  20. package/dist/generative-ui.d.cts.map +1 -1
  21. package/dist/generative-ui.d.mts +2137 -4178
  22. package/dist/generative-ui.d.mts.map +1 -1
  23. package/dist/generative-ui.mjs +75 -73
  24. package/dist/generative-ui.mjs.map +1 -1
  25. package/dist/headless.cjs +55 -84
  26. package/dist/headless.cjs.map +1 -1
  27. package/dist/headless.d.cts +78 -253
  28. package/dist/headless.d.cts.map +1 -1
  29. package/dist/headless.d.mts +56 -202
  30. package/dist/headless.d.mts.map +1 -1
  31. package/dist/headless.mjs +48 -82
  32. package/dist/headless.mjs.map +1 -1
  33. package/dist/index.cjs +1628 -2398
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +203 -540
  36. package/dist/index.d.cts.map +1 -1
  37. package/dist/index.d.mts +202 -539
  38. package/dist/index.d.mts.map +1 -1
  39. package/dist/index.mjs +965 -2248
  40. package/dist/index.mjs.map +1 -1
  41. package/dist/index.umd.js +1776 -2466
  42. package/dist/index.umd.js.map +1 -1
  43. package/package.json +17 -18
  44. package/dist/MarkdownRendererContext-B4Us6mwL.d.cts.map +0 -1
  45. package/dist/MarkdownRendererContext-CRKFzsEB.d.mts.map +0 -1
  46. package/dist/MarkdownSurfaces-Bd--93O1.mjs.map +0 -1
  47. package/dist/MarkdownSurfaces-S4wfUl3J.cjs.map +0 -1
@@ -1,12 +1,11 @@
1
- import { extractFenceOperations, flattenInformationalCards, getMarkdownOperationSurfaceId, prepareSurfaceOperations, segmentSurfaceProse, splitA2UIMarkdown } from "@copilotkit/core";
2
- import React, { Component, createContext, memo, useCallback, useContext, useEffect, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
1
+ import { CopilotChatDefaultLabels, extractFenceOperations, flattenInformationalCards, getMarkdownOperationSurfaceId, prepareSurfaceOperations, segmentSurfaceProse, splitA2UIMarkdown, ɵcn as cn, ɵcopilotIconSvgAttributes, ɵcopilotIcons, ɵshallowEqualRecord } from "@copilotkit/core";
2
+ import React, { Component, createContext, createElement, forwardRef, memo, useCallback, useContext, useEffect, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
3
+ import { StreamingMarkdownRenderer, createStreamingMarkdownNodeRenderers } from "@copilotkit/markdown/react";
4
+ import { warnUnsupportedRichSyntaxOnce } from "@copilotkit/markdown";
3
5
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
4
- import { StreamingMarkdownRenderer, createStreamingMarkdownNodeRenderers } from "@copilotkit/markdown-renderer/react";
5
- import { warnUnsupportedRichSyntaxOnce } from "@copilotkit/markdown-renderer";
6
- import { A2UI_COMPONENT_ENVELOPE_KEYS, A2UI_INDEX_FUNCTION, A2UI_VERSION, DEFAULT_AGENT_ID, GENERATIVE_UI_ACTIVITY_TYPE, GENERATIVE_UI_CHAT_TARGET, GENERATIVE_UI_FUNCTIONS, GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE, GENERATIVE_UI_RENDER_TOOL, GENERATIVE_UI_ROOT_ID, applyChildRefMarks, childIdsAtRefs, collectChildRefs, functionCallers, getOperationKind, hasBoundChildRef, isActionBinding, isCallBinding, isPathBinding, isValidationResult, mapAtChildRef, randomUUID, schemaToJsonSchema, validateOperation } from "@copilotkit/shared";
6
+ import { A2UI_COMPONENT_ENVELOPE_KEYS, A2UI_INDEX_FUNCTION, A2UI_VERSION, DEFAULT_AGENT_ID, GENERATIVE_UI_ACTIVITY_TYPE, GENERATIVE_UI_CHAT_TARGET, GENERATIVE_UI_FUNCTIONS, GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE, GENERATIVE_UI_RENDER_TOOL, GENERATIVE_UI_ROOT_ID, applyChildRefMarks, childIdsAtRefs, collectChildRefs, functionCallers, getOperationKind, hasBoundChildRef, isActionBinding, isCallBinding, isPathBinding, isValidationResult, mapAtChildRef, randomUUID, schemaToJsonSchema, validateOperation, ɵanySchema } from "@copilotkit/shared";
7
7
  import { CopilotKitContext, useCopilotKit, useDefaultAgentId } from "@copilotkit/react-core/context";
8
- import { z } from "zod";
9
- import { zodToJsonSchema } from "zod-to-json-schema";
8
+ import * as z from "zod";
10
9
 
11
10
  //#region src/components/chat/StreamingMarkdownDefaultRenderer.tsx
12
11
  const defaultNodeRenderers = createStreamingMarkdownNodeRenderers({ codeBlock: ({ node }) => /* @__PURE__ */ jsx("pre", {
@@ -18,7 +17,7 @@ const defaultNodeRenderers = createStreamingMarkdownNodeRenderers({ codeBlock: (
18
17
  }) });
19
18
  /**
20
19
  * react-core's built-in default markdown renderer — a thin adapter over
21
- * `@copilotkit/markdown-renderer`'s streaming renderer. Maps the pluggable
20
+ * `@copilotkit/markdown`'s streaming renderer. Maps the pluggable
22
21
  * renderer contract (`{ content, isStreaming, className }`) onto the streaming
23
22
  * renderer for streaming-safe incremental rendering + per-token animation.
24
23
  * Still overridable via the slot/provider pluggable interface.
@@ -43,17 +42,76 @@ function StreamingMarkdownDefaultRenderer({ content, isStreaming, className, nod
43
42
  }
44
43
  StreamingMarkdownDefaultRenderer.displayName = "StreamingMarkdownDefaultRenderer";
45
44
 
45
+ //#endregion
46
+ //#region src/components/icons/CopilotIcon.tsx
47
+ /** Turns SVG attribute names such as `stroke-width` into React's `strokeWidth`. */
48
+ function toReactAttributes(attributes) {
49
+ return Object.fromEntries(Object.entries(attributes).map(([key, value]) => [key.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase()), value]));
50
+ }
51
+ const svgDefaults = toReactAttributes(ɵcopilotIconSvgAttributes);
52
+ /** True when the props give the icon an accessible name or role. */
53
+ function hasAccessibleProp(props) {
54
+ return Object.keys(props).some((key) => key.startsWith("aria-") || key === "role" || key === "title");
55
+ }
56
+ /**
57
+ * Internal. Draws a Lucide icon from its node data, the way Lucide's React package
58
+ * does: Lucide's default SVG attributes, the `lucide lucide-<name>` classes,
59
+ * and `aria-hidden="true"` when no `aria-*`, `role` or `title` prop names it.
60
+ */
61
+ const IconSvg = forwardRef(function IconSvg({ lucideName, nodes, size = 24, color = "currentColor", strokeWidth = 2, className, children, ...props }, ref) {
62
+ const isDecorative = !children && !hasAccessibleProp(props);
63
+ return /* @__PURE__ */ jsxs("svg", {
64
+ ref,
65
+ ...svgDefaults,
66
+ width: size,
67
+ height: size,
68
+ stroke: color,
69
+ strokeWidth,
70
+ className: cn("lucide", `lucide-${lucideName}`, className),
71
+ "aria-hidden": isDecorative || void 0,
72
+ ...props,
73
+ children: [nodes.map((node, index) => createElement(node.tag, {
74
+ key: index,
75
+ ...node.attributes
76
+ })), children]
77
+ });
78
+ });
79
+ /**
80
+ * Draws one of the chat icons as an inline `<svg>`.
81
+ *
82
+ * The `<svg>` has the classes `lucide lucide-<icon name>`, so CSS that selects
83
+ * them (for example `svg.lucide-arrow-up`) keeps working. The icon is hidden
84
+ * from screen readers unless you give it an `aria-label`, `role` or `title`.
85
+ *
86
+ * @param props.name - The chat icon, for example `"ArrowUp"` or `"X"`.
87
+ * @param props.size - Width and height. Defaults to `24`.
88
+ * @param props.strokeWidth - Line width. Defaults to `2`.
89
+ * @param props.color - Line color. Defaults to `currentColor`.
90
+ *
91
+ * @example
92
+ * ```tsx
93
+ * <CopilotIcon name="ArrowUp" className="cpk-chat-input-send-icon" />
94
+ * <CopilotIcon name="X" aria-label="Close" />
95
+ * ```
96
+ */
97
+ const CopilotIcon = forwardRef(function CopilotIcon({ name, ...props }, ref) {
98
+ const icon = ɵcopilotIcons[name];
99
+ return /* @__PURE__ */ jsx(IconSvg, {
100
+ ref,
101
+ lucideName: icon.name,
102
+ nodes: icon.nodes,
103
+ ...props
104
+ });
105
+ });
106
+
46
107
  //#endregion
47
108
  //#region src/lib/shallow-stable-ref.ts
48
109
  /**
49
- * Shallow equality comparison for objects.
110
+ * Shallow equality comparison for objects: same own keys, each holding the
111
+ * same value (`Object.is`). Core's `ɵshallowEqualRecord` holds the rule.
50
112
  */
51
113
  function shallowEqual(obj1, obj2) {
52
- const keys1 = Object.keys(obj1);
53
- const keys2 = Object.keys(obj2);
54
- if (keys1.length !== keys2.length) return false;
55
- for (const key of keys1) if (obj1[key] !== obj2[key]) return false;
56
- return true;
114
+ return ɵshallowEqualRecord(obj1, obj2);
57
115
  }
58
116
  /**
59
117
  * Returns true only for plain JS objects (`{}`), excluding arrays, Dates,
@@ -87,51 +145,6 @@ function useShallowStableRef(value) {
87
145
 
88
146
  //#endregion
89
147
  //#region src/providers/CopilotChatConfigurationProvider.tsx
90
- const CopilotChatDefaultLabels = {
91
- chatInputPlaceholder: "Type a message...",
92
- chatInputToolbarStartTranscribeButtonLabel: "Transcribe",
93
- chatInputToolbarCancelTranscribeButtonLabel: "Cancel",
94
- chatInputToolbarFinishTranscribeButtonLabel: "Finish",
95
- chatInputToolbarAddButtonLabel: "Add attachments",
96
- chatInputToolbarToolsButtonLabel: "Tools",
97
- chatInputToolbarSendButtonLabel: "Send message",
98
- chatInputToolbarStopButtonLabel: "Stop",
99
- assistantMessageToolbarCopyCodeLabel: "Copy",
100
- assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
101
- assistantMessageToolbarCopyMessageLabel: "Copy",
102
- assistantMessageToolbarInspectorLabel: "View in Inspector",
103
- assistantMessageToolbarInspectorDescription: "Open this message in the Inspector",
104
- assistantMessageToolbarInspectorLocalOnlyLabel: "Local only",
105
- assistantMessageToolbarInspectorLocalOnlyDescription: "Only visible on localhost or loopback hosts in development. Never shown in production.",
106
- assistantMessageToolbarInspectorTitle: "CopilotKit Inspector",
107
- assistantMessageToolbarInspectorHideLabel: "Hide this icon",
108
- assistantMessageToolbarInspectorHideDescription: "Until you reload this page",
109
- assistantMessageToolbarThumbsUpLabel: "Good response",
110
- assistantMessageToolbarThumbsDownLabel: "Bad response",
111
- assistantMessageFeedbackCommentPlaceholder: "Add a comment (optional)",
112
- assistantMessageFeedbackCommentSubmitLabel: "Send comment",
113
- assistantMessageToolbarReadAloudLabel: "Read aloud",
114
- assistantMessageToolbarRegenerateLabel: "Regenerate",
115
- userMessageToolbarCopyMessageLabel: "Copy",
116
- userMessageToolbarEditMessageLabel: "Edit",
117
- userMessageToolbarPreviousBranchLabel: "Previous branch",
118
- userMessageToolbarNextBranchLabel: "Next branch",
119
- chatDisclaimerText: "AI can make mistakes. Please verify important information.",
120
- chatToggleOpenLabel: "Open chat",
121
- chatToggleCloseLabel: "Close chat",
122
- chatScrollToBottomLabel: "Scroll to bottom",
123
- modalHeaderTitle: "CopilotKit Chat",
124
- welcomeMessageText: "How can I help you today?",
125
- reasoningMessageThinkingLabel: "Thinking…",
126
- chatInputSlashMenuLabel: "Slash commands",
127
- chatInputSlashMenuEmptyText: "No commands found",
128
- attachmentRemoveButtonLabel: "Remove attachment",
129
- attachmentPlayVideoButtonLabel: "Play video",
130
- attachmentPreviewCloseButtonLabel: "Close preview",
131
- modalHeaderCloseButtonLabel: "Close",
132
- modalHeaderThreadsButtonLabel: "Open threads",
133
- sidebarLabel: "Copilot chat sidebar"
134
- };
135
148
  /**
136
149
  * Mobile breakpoint below which the chat modal and the thread-list drawer are
137
150
  * mutually exclusive. At or above this width both surfaces may coexist. This
@@ -388,28 +401,6 @@ const ControlledModalOpenScope = ({ children, open, onOpenChange }) => {
388
401
  };
389
402
  ControlledModalOpenScope.displayName = "ControlledModalOpenScope";
390
403
 
391
- //#endregion
392
- //#region src/lib/utils.ts
393
- /**
394
- * Joins class names, skipping falsy values. Takes the same inputs as `clsx`.
395
- * Classes are not merged: every rule CopilotKit ships sits in `:where()`, so a
396
- * class the app adds wins without removing ours.
397
- */
398
- function cn(...inputs) {
399
- const out = [];
400
- for (const input of inputs) {
401
- if (!input) continue;
402
- if (typeof input === "string" || typeof input === "number" || typeof input === "bigint") out.push(String(input));
403
- else if (Array.isArray(input)) {
404
- const nested = cn(...input);
405
- if (nested) out.push(nested);
406
- } else if (typeof input === "object") {
407
- for (const key in input) if (input[key]) out.push(key);
408
- }
409
- }
410
- return out.join(" ");
411
- }
412
-
413
404
  //#endregion
414
405
  //#region src/lib/slots.tsx
415
406
  /**
@@ -491,7 +482,7 @@ function useMarkdownRenderer() {
491
482
  //#endregion
492
483
  //#region src/types/defineToolCallRenderer.ts
493
484
  function defineToolCallRenderer(def) {
494
- const argsSchema = def.name === "*" && !def.args ? z.any() : def.args;
485
+ const argsSchema = def.name === "*" && !def.args ? ɵanySchema : def.args;
495
486
  return {
496
487
  name: def.name,
497
488
  args: argsSchema,
@@ -504,12 +495,11 @@ function defineToolCallRenderer(def) {
504
495
  //#endregion
505
496
  //#region src/generative-ui/json-schema.ts
506
497
  /**
507
- * JSON Schema for a Standard Schema (zod v3 via zod-to-json-schema),
508
- * inlined, no `$schema`. A prop marked by `child()` or `childList()`
498
+ * JSON Schema for a Standard Schema, without `$schema`. A prop marked by `child()` or `childList()`
509
499
  * becomes an A2UI `$ref` to `ComponentId` or `ChildList`.
510
500
  */
511
501
  function toJsonSchema(schema) {
512
- const { $schema: _omit, ...rest } = schemaToJsonSchema(schema, { zodToJsonSchema: (s) => zodToJsonSchema(s, { $refStrategy: "none" }) });
502
+ const { $schema: _omit, ...rest } = schemaToJsonSchema(schema);
513
503
  return applyChildRefMarks(rest);
514
504
  }
515
505
 
@@ -816,16 +806,10 @@ function toManifest(definition, modelProps, modelEvents) {
816
806
  return manifest;
817
807
  }
818
808
 
819
- //#endregion
820
- //#region src/generative-ui/is-record.ts
821
- /** True for a plain object: not null, not an array. Internal, not exported. */
822
- function isRecord(value) {
823
- return typeof value === "object" && value !== null && !Array.isArray(value);
824
- }
825
-
826
809
  //#endregion
827
810
  //#region src/generative-ui/errors.ts
828
811
  var GenerativeUIError = class extends Error {
812
+ code;
829
813
  constructor(code, message) {
830
814
  super(message);
831
815
  this.name = "GenerativeUIError";
@@ -925,6 +909,7 @@ function formatDatePattern(date, pattern) {
925
909
  case "m": return pad(date.getMinutes(), 2);
926
910
  case "s": return pad(date.getSeconds(), 2);
927
911
  case "a": return date.getHours() < 12 ? "AM" : "PM";
912
+ case void 0:
928
913
  default: return token;
929
914
  }
930
915
  });
@@ -1028,6 +1013,13 @@ function givesValidationResult(name) {
1028
1013
  return GENERATIVE_UI_FUNCTIONS[name]?.returnType === "validationResult";
1029
1014
  }
1030
1015
 
1016
+ //#endregion
1017
+ //#region src/generative-ui/is-record.ts
1018
+ /** True for a plain object: not null, not an array. Internal, not exported. */
1019
+ function isRecord(value) {
1020
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1021
+ }
1022
+
1031
1023
  //#endregion
1032
1024
  //#region src/generative-ui/markdown/source.ts
1033
1025
  /**
@@ -1035,10 +1027,8 @@ function givesValidationResult(name) {
1035
1027
  * is dropped at the end of that build, so the cache does not grow.
1036
1028
  */
1037
1029
  var BuildMemo = class {
1038
- constructor() {
1039
- this.previous = /* @__PURE__ */ new Map();
1040
- this.current = /* @__PURE__ */ new Map();
1041
- }
1030
+ previous = /* @__PURE__ */ new Map();
1031
+ current = /* @__PURE__ */ new Map();
1042
1032
  /**
1043
1033
  * The value of `key`. It is computed when no earlier value is there, or
1044
1034
  * when `isFresh` says that the earlier value is out of date.
@@ -1056,12 +1046,11 @@ var BuildMemo = class {
1056
1046
  };
1057
1047
  /** The results of the builds of one thread. See `BuildMarkdownSurfacesOptions.cache`. */
1058
1048
  var MarkdownBuildCache = class {
1059
- constructor() {
1060
- this.segments = new BuildMemo();
1061
- this.fences = new BuildMemo();
1062
- this.drafts = new BuildMemo();
1063
- this.readdressed = /* @__PURE__ */ new WeakMap();
1064
- }
1049
+ segments = new BuildMemo();
1050
+ fences = new BuildMemo();
1051
+ drafts = new BuildMemo();
1052
+ /** The copies of an operation for other surface ids, by operation. */
1053
+ readdressed = /* @__PURE__ */ new WeakMap();
1065
1054
  endBuild() {
1066
1055
  this.segments.endBuild();
1067
1056
  this.fences.endBuild();
@@ -1572,13 +1561,18 @@ function removalContent(surfaceId, catalogId) {
1572
1561
  * that each fence renders.
1573
1562
  */
1574
1563
  var MarkdownSurfaceSource = class {
1564
+ functions;
1565
+ /** By thread: the blocks of each fence, from the latest sync. */
1566
+ fences = /* @__PURE__ */ new Map();
1567
+ /** By thread, then surface: the operations last ingested, as JSON. */
1568
+ ingested = /* @__PURE__ */ new Map();
1569
+ /** By thread, then surface: the content last ingested. */
1570
+ contents = /* @__PURE__ */ new Map();
1571
+ /** By thread: the results of the earlier builds. */
1572
+ caches = /* @__PURE__ */ new Map();
1575
1573
  constructor(manager, ui) {
1576
1574
  this.manager = manager;
1577
1575
  this.ui = ui;
1578
- this.fences = /* @__PURE__ */ new Map();
1579
- this.ingested = /* @__PURE__ */ new Map();
1580
- this.contents = /* @__PURE__ */ new Map();
1581
- this.caches = /* @__PURE__ */ new Map();
1582
1576
  this.functions = declaredFunctions(ui);
1583
1577
  }
1584
1578
  /**
@@ -1676,6 +1670,7 @@ const OPERATORS = [
1676
1670
  "*",
1677
1671
  "/",
1678
1672
  "%",
1673
+ "^",
1679
1674
  "(",
1680
1675
  ")",
1681
1676
  ",",
@@ -1756,27 +1751,58 @@ function describe(value) {
1756
1751
  const MATH = {
1757
1752
  min: (args) => Math.min(...args),
1758
1753
  max: (args) => Math.max(...args),
1759
- abs: ([x]) => Math.abs(x),
1760
- floor: ([x]) => Math.floor(x),
1761
- ceil: ([x]) => Math.ceil(x),
1762
- round: ([x, decimals = 0]) => {
1754
+ abs: ([x = NaN]) => Math.abs(x),
1755
+ floor: ([x = NaN]) => Math.floor(x),
1756
+ ceil: ([x = NaN]) => Math.ceil(x),
1757
+ round: ([x = NaN, decimals = 0]) => {
1763
1758
  const factor = 10 ** Math.trunc(decimals);
1764
1759
  return Math.round(x * factor) / factor;
1765
- }
1760
+ },
1761
+ pow: ([x = NaN, y = NaN]) => x ** y,
1762
+ sqrt: ([x = NaN]) => Math.sqrt(x),
1763
+ exp: ([x = NaN]) => Math.exp(x),
1764
+ ln: ([x = NaN]) => Math.log(x),
1765
+ log10: ([x = NaN]) => Math.log10(x)
1766
+ };
1767
+ /** How many args a function takes, at least and at most; min and max take any. */
1768
+ const ARITY = {
1769
+ abs: [1, 1],
1770
+ floor: [1, 1],
1771
+ ceil: [1, 1],
1772
+ round: [1, 2],
1773
+ pow: [2, 2],
1774
+ sqrt: [1, 1],
1775
+ exp: [1, 1],
1776
+ ln: [1, 1],
1777
+ log10: [1, 1]
1778
+ };
1779
+ /** Named constants, when no arg of the same name is passed. */
1780
+ const CONSTANTS = {
1781
+ pi: Math.PI,
1782
+ e: Math.E
1766
1783
  };
1767
1784
  var CalcParser = class {
1785
+ pos = 0;
1768
1786
  constructor(tokens, scope, source) {
1769
1787
  this.tokens = tokens;
1770
1788
  this.scope = scope;
1771
1789
  this.source = source;
1772
- this.pos = 0;
1773
- this.skipDepth = 0;
1774
1790
  }
1775
1791
  parse() {
1776
1792
  const value = this.ternary();
1777
- if (this.tokens[this.pos].kind !== "end") this.fail(`unexpected "${this.text(this.tokens[this.pos])}"`);
1793
+ const token = this.peek();
1794
+ if (token.kind !== "end") this.fail(`unexpected "${this.text(token)}"`);
1778
1795
  return value;
1779
1796
  }
1797
+ /**
1798
+ * The token at `pos`. The parser never moves past the "end" token, which
1799
+ * `tokenize` always adds last, so there is always one.
1800
+ */
1801
+ peek() {
1802
+ const token = this.tokens[this.pos];
1803
+ if (token === void 0) throw new Error(`calc: no token at ${this.pos} in "${this.source}"`);
1804
+ return token;
1805
+ }
1780
1806
  fail(what) {
1781
1807
  throw new ExpressionError(`calc: ${what} in "${this.source}"`);
1782
1808
  }
@@ -1784,11 +1810,11 @@ var CalcParser = class {
1784
1810
  return token.kind === "end" ? "end" : String(token.value);
1785
1811
  }
1786
1812
  peekOp(...ops) {
1787
- const token = this.tokens[this.pos];
1813
+ const token = this.peek();
1788
1814
  return token.kind === "op" && ops.includes(token.value) ? token.value : void 0;
1789
1815
  }
1790
1816
  expectOp(op) {
1791
- if (this.peekOp(op) === void 0) this.fail(`expected "${op}" but found "${this.text(this.tokens[this.pos])}"`);
1817
+ if (this.peekOp(op) === void 0) this.fail(`expected "${op}" but found "${this.text(this.peek())}"`);
1792
1818
  this.pos++;
1793
1819
  }
1794
1820
  /**
@@ -1807,6 +1833,8 @@ var CalcParser = class {
1807
1833
  }
1808
1834
  return null;
1809
1835
  }
1836
+ /** Above 0 while parsing a part whose value is not needed. */
1837
+ skipDepth = 0;
1810
1838
  /** The number of a value, or 0 while skipping. */
1811
1839
  num(value, what) {
1812
1840
  return this.skipDepth > 0 ? 0 : numberOf(value, what);
@@ -1897,10 +1925,24 @@ var CalcParser = class {
1897
1925
  this.pos++;
1898
1926
  return !truthOf(this.unary());
1899
1927
  }
1900
- return this.primary();
1928
+ return this.power();
1929
+ }
1930
+ /** `a ^ b`: binds tighter than `*` and unary minus, right to left. */
1931
+ power() {
1932
+ const base = this.primary();
1933
+ if (!this.peekOp("^")) return base;
1934
+ this.pos++;
1935
+ const exponent = this.unary();
1936
+ if (this.skipDepth > 0) return null;
1937
+ return this.finite(this.num(base, "the left side of ^") ** this.num(exponent, "the right side of ^"), "^");
1938
+ }
1939
+ finite(value, what) {
1940
+ if (!Number.isFinite(value)) this.fail(`${what} has no finite result`);
1941
+ return value;
1901
1942
  }
1902
1943
  primary() {
1903
- const token = this.tokens[this.pos++];
1944
+ const token = this.peek();
1945
+ this.pos++;
1904
1946
  switch (token.kind) {
1905
1947
  case "number": return token.value;
1906
1948
  case "string": return token.value;
@@ -1932,10 +1974,15 @@ var CalcParser = class {
1932
1974
  const fn = Object.prototype.hasOwnProperty.call(MATH, name) ? MATH[name] : void 0;
1933
1975
  if (!fn) this.fail(`unknown function ${name}`);
1934
1976
  if (args.length === 0) this.fail(`${name} needs an argument`);
1935
- return fn(args);
1977
+ const [least, most] = ARITY[name] ?? [1, Infinity];
1978
+ if (args.length < least || args.length > most) this.fail(`${name} takes ${least === most ? least : `${least} or ${most}`} argument${most === 1 ? "" : "s"}`);
1979
+ return this.finite(fn(args), name);
1936
1980
  }
1937
1981
  if (this.skipDepth > 0) return null;
1938
- if (!Object.prototype.hasOwnProperty.call(this.scope, name)) this.fail(`unknown name ${name}; pass it as an arg`);
1982
+ if (!Object.prototype.hasOwnProperty.call(this.scope, name)) {
1983
+ if (Object.prototype.hasOwnProperty.call(CONSTANTS, name)) return CONSTANTS[name];
1984
+ this.fail(`unknown name ${name}; pass it as an arg`);
1985
+ }
1939
1986
  const value = this.scope[name];
1940
1987
  if (value !== null && typeof value !== "number" && typeof value !== "string" && typeof value !== "boolean") this.fail(`${name} is not a number, text or boolean (${describe(value)})`);
1941
1988
  return value;
@@ -2175,10 +2222,10 @@ const IDENTIFIER = /@?[A-Za-z_][A-Za-z0-9_-]*/y;
2175
2222
  const NUMBER = /-?\d+(?:\.\d+)?/y;
2176
2223
  const PATH_SEGMENT = /[^\s,():'"]+/y;
2177
2224
  var ExpressionParser = class {
2225
+ pos = 0;
2178
2226
  constructor(source, state) {
2179
2227
  this.source = source;
2180
2228
  this.state = state;
2181
- this.pos = 0;
2182
2229
  }
2183
2230
  parse() {
2184
2231
  const value = this.expression();
@@ -2480,14 +2527,10 @@ function NodePlaceholder(_props) {
2480
2527
  }
2481
2528
  /** Per-node boundary. Resets on retry or a new agent revision, not on data ticks. */
2482
2529
  var NodeBoundary = class extends Component {
2483
- constructor(..._args) {
2484
- super(..._args);
2485
- this.state = {
2486
- error: null,
2487
- revision: this.props.revision
2488
- };
2489
- this.retry = () => this.setState({ error: null });
2490
- }
2530
+ state = {
2531
+ error: null,
2532
+ revision: this.props.revision
2533
+ };
2491
2534
  static getDerivedStateFromError(error) {
2492
2535
  return { error };
2493
2536
  }
@@ -2506,6 +2549,7 @@ var NodeBoundary = class extends Component {
2506
2549
  error
2507
2550
  });
2508
2551
  }
2552
+ retry = () => this.setState({ error: null });
2509
2553
  render() {
2510
2554
  const { error } = this.state;
2511
2555
  if (!error) return this.props.children;
@@ -2525,10 +2569,7 @@ var NodeBoundary = class extends Component {
2525
2569
  };
2526
2570
  /** Outer boundary: a failure here must not reach the chat or the host page. */
2527
2571
  var SurfaceBoundary = class extends Component {
2528
- constructor(..._args2) {
2529
- super(..._args2);
2530
- this.state = { error: null };
2531
- }
2572
+ state = { error: null };
2532
2573
  static getDerivedStateFromError(error) {
2533
2574
  return { error };
2534
2575
  }
@@ -3463,7 +3504,7 @@ const ContentSchema = z.object({
3463
3504
  index: z.number(),
3464
3505
  reason: z.string()
3465
3506
  })).default([])
3466
- }).passthrough();
3507
+ }).loose();
3467
3508
  function GenerativeUIChatActivity({ content, agent }) {
3468
3509
  const runtime = useGenerativeUIRuntime();
3469
3510
  const threadId = useCopilotChatConfiguration()?.threadId ?? agent?.threadId;
@@ -3672,5 +3713,5 @@ function MarkdownSurfaces({ content, messageId, isStreaming = false, ...markdown
3672
3713
  }
3673
3714
 
3674
3715
  //#endregion
3675
- export { GenerativeUIError as A, renderSlot as B, issueKey as C, getMarkdownSurfaceSource as D, containsDynamicValue as E, toJsonSchema as F, useCopilotChatConfiguration as G, ControlledModalOpenScope as H, defineToolCallRenderer as I, useShallowStableRef as K, MarkdownRendererProvider as L, catalogIdsOf as M, componentCatalogIds as N, BASIC_FUNCTIONS as O, createGenerativeUI as P, useMarkdownRenderer as R, isAsyncIssue as S, withoutRejectedNulls as T, CopilotChatConfigurationProvider as U, cn as V, CopilotChatDefaultLabels as W, GenerativeUINodeContext as _, GenerativeUIToolCallRenderer as a, useRequiredGenerativeUIRuntime as b, SurfaceView as c, namedRole as d, useGenerativeUIAccessibility as f, useManagerVersion as g, useGenerativeUIState as h, GenerativeUIChatSlotContext as i, isRecord as j, ExpressionError as k, DARK_THEME_CSS as l, useGenerativeUIFunction as m, ProviderMarkdown as n, createGenerativeUIActivityRenderer as o, wrapperAria as p, StreamingMarkdownDefaultRenderer as q, DefaultGenerativeUIChatCard as r, createGenerativeUIFunctionCallActivityRenderer as s, MarkdownSurfaces as t, controlAria as u, GenerativeUIRuntimeContext as v, validateSchemaSync as w, formatIssues as x, useGenerativeUIRuntime as y, isReactComponentType as z };
3676
- //# sourceMappingURL=MarkdownSurfaces-Bd--93O1.mjs.map
3716
+ export { ExpressionError as A, renderSlot as B, issueKey as C, getMarkdownSurfaceSource as D, containsDynamicValue as E, toJsonSchema as F, CopilotIcon as G, CopilotChatConfigurationProvider as H, defineToolCallRenderer as I, StreamingMarkdownDefaultRenderer as J, IconSvg as K, MarkdownRendererProvider as L, catalogIdsOf as M, componentCatalogIds as N, isRecord as O, createGenerativeUI as P, useMarkdownRenderer as R, isAsyncIssue as S, withoutRejectedNulls as T, useCopilotChatConfiguration as U, ControlledModalOpenScope as V, useShallowStableRef as W, GenerativeUINodeContext as _, GenerativeUIToolCallRenderer as a, useRequiredGenerativeUIRuntime as b, SurfaceView as c, namedRole as d, useGenerativeUIAccessibility as f, useManagerVersion as g, useGenerativeUIState as h, GenerativeUIChatSlotContext as i, GenerativeUIError as j, BASIC_FUNCTIONS as k, DARK_THEME_CSS as l, useGenerativeUIFunction as m, ProviderMarkdown as n, createGenerativeUIActivityRenderer as o, wrapperAria as p, cn as q, DefaultGenerativeUIChatCard as r, createGenerativeUIFunctionCallActivityRenderer as s, MarkdownSurfaces as t, controlAria as u, GenerativeUIRuntimeContext as v, validateSchemaSync as w, formatIssues as x, useGenerativeUIRuntime as y, isReactComponentType as z };
3717
+ //# sourceMappingURL=MarkdownSurfaces-Bt7TD_U1.mjs.map