@copilotkit/react-core 1.83.0 → 1.84.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 (46) hide show
  1. package/dist/{MarkdownSurfaces-DGpjmPaB.mjs → MarkdownSurfaces-DV9P0Gi9.mjs} +55 -13
  2. package/dist/MarkdownSurfaces-DV9P0Gi9.mjs.map +1 -0
  3. package/dist/{MarkdownSurfaces-FF5za2kU.cjs → MarkdownSurfaces-IUaWSJ0E.cjs} +54 -12
  4. package/dist/MarkdownSurfaces-IUaWSJ0E.cjs.map +1 -0
  5. package/dist/{copilotkit-BuIuo-Z1.cjs → copilotkit-BOTf5RHF.cjs} +296 -291
  6. package/dist/copilotkit-BOTf5RHF.cjs.map +1 -0
  7. package/dist/{copilotkit-wqaNanhw.d.cts → copilotkit-C3mvJexb.d.cts} +31 -8
  8. package/dist/copilotkit-C3mvJexb.d.cts.map +1 -0
  9. package/dist/{copilotkit-DyxwF9wL.mjs → copilotkit-CKnD8GeM.mjs} +300 -295
  10. package/dist/copilotkit-CKnD8GeM.mjs.map +1 -0
  11. package/dist/{copilotkit-C765tOUi.d.mts → copilotkit-CnYo662V.d.mts} +31 -8
  12. package/dist/copilotkit-CnYo662V.d.mts.map +1 -0
  13. package/dist/index.cjs +2 -2
  14. package/dist/index.d.cts +1 -1
  15. package/dist/index.d.mts +1 -1
  16. package/dist/index.mjs +2 -2
  17. package/dist/index.umd.js +199 -289
  18. package/dist/index.umd.js.map +1 -1
  19. package/dist/v2/generative-ui.cjs +33 -54
  20. package/dist/v2/generative-ui.cjs.map +1 -1
  21. package/dist/v2/generative-ui.d.cts +64 -64
  22. package/dist/v2/generative-ui.d.mts +64 -64
  23. package/dist/v2/generative-ui.mjs +33 -54
  24. package/dist/v2/generative-ui.mjs.map +1 -1
  25. package/dist/v2/headless.cjs +32 -16
  26. package/dist/v2/headless.cjs.map +1 -1
  27. package/dist/v2/headless.d.cts +2 -0
  28. package/dist/v2/headless.d.cts.map +1 -1
  29. package/dist/v2/headless.d.mts +2 -0
  30. package/dist/v2/headless.d.mts.map +1 -1
  31. package/dist/v2/headless.mjs +33 -17
  32. package/dist/v2/headless.mjs.map +1 -1
  33. package/dist/v2/index.cjs +14 -2
  34. package/dist/v2/index.css +1 -1
  35. package/dist/v2/index.d.cts +2 -2
  36. package/dist/v2/index.d.mts +2 -2
  37. package/dist/v2/index.mjs +3 -3
  38. package/dist/v2/index.umd.js +359 -300
  39. package/dist/v2/index.umd.js.map +1 -1
  40. package/package.json +8 -8
  41. package/dist/MarkdownSurfaces-DGpjmPaB.mjs.map +0 -1
  42. package/dist/MarkdownSurfaces-FF5za2kU.cjs.map +0 -1
  43. package/dist/copilotkit-BuIuo-Z1.cjs.map +0 -1
  44. package/dist/copilotkit-C765tOUi.d.mts.map +0 -1
  45. package/dist/copilotkit-DyxwF9wL.mjs.map +0 -1
  46. package/dist/copilotkit-wqaNanhw.d.cts.map +0 -1
@@ -242,6 +242,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
242
242
  chatToggleOpenLabel: "Open chat",
243
243
  chatToggleCloseLabel: "Close chat",
244
244
  chatScrollToBottomLabel: "Scroll to bottom",
245
+ chatConnectingLabel: "Loading conversation",
245
246
  modalHeaderTitle: "CopilotKit Chat",
246
247
  welcomeMessageText: "How can I help you today?",
247
248
  reasoningMessageThinkingLabel: "Thinking…",
@@ -1824,7 +1825,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
1824
1825
 
1825
1826
  //#endregion
1826
1827
  //#region package.json
1827
- var version = "1.83.0";
1828
+ var version = "1.84.0";
1828
1829
 
1829
1830
  //#endregion
1830
1831
  //#region src/v2/components/CopilotKitInspector.tsx
@@ -3629,6 +3630,35 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
3629
3630
  }]));
3630
3631
  }
3631
3632
  /**
3633
+ * The manifest of a catalog, with no React runtime: the components of `ui`,
3634
+ * the built-in functions (minus the names the app declares) and
3635
+ * `options.functions`, the chat target and `options.targets`, and
3636
+ * `options.surfaces`. `buildGenerativeUIManifest` builds the per-run
3637
+ * manifest with it; tools that run outside React use it directly.
3638
+ *
3639
+ * @example
3640
+ * ```ts
3641
+ * const manifest = buildCatalogManifest(standardUI);
3642
+ * manifest.targets; // [{ id: "chat", kind: "chat" }]
3643
+ * ```
3644
+ */
3645
+ function buildCatalogManifest(ui, options = {}) {
3646
+ return {
3647
+ catalogId: ui.id,
3648
+ catalogIds: catalogIdsOf(ui),
3649
+ components: (0, _copilotkit_shared.applyDescriptionOverrides)({ components: ui.manifestComponents }, (0, _copilotkit_shared.defaultGenerativeUIPromptSpec)().descriptions).manifest.components,
3650
+ functions: {
3651
+ ...Object.fromEntries(Object.entries(builtInFunctionManifests()).filter(([name]) => !ui.functions.has(name))),
3652
+ ...options.functions
3653
+ },
3654
+ targets: [{
3655
+ id: _copilotkit_shared.GENERATIVE_UI_CHAT_TARGET,
3656
+ kind: "chat"
3657
+ }, ...options.targets ?? []],
3658
+ surfaces: options.surfaces ?? {}
3659
+ };
3660
+ }
3661
+ /**
3632
3662
  * Builds the per-run manifest. Never contains handlers or renderers.
3633
3663
  *
3634
3664
  * - `functions`: the built-in functions, then the declared functions with
@@ -3643,20 +3673,11 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
3643
3673
  kind: "inline",
3644
3674
  ...rest
3645
3675
  }));
3646
- return {
3647
- catalogId: ui.id,
3648
- catalogIds: catalogIdsOf(ui),
3649
- components: ui.manifestComponents,
3650
- functions: {
3651
- ...Object.fromEntries(Object.entries(builtInFunctionManifests()).filter(([name]) => !ui.functions.has(name))),
3652
- ...dispatcher.listExposed()
3653
- },
3654
- targets: [{
3655
- id: _copilotkit_shared.GENERATIVE_UI_CHAT_TARGET,
3656
- kind: "chat"
3657
- }, ...inlineTargets],
3676
+ return buildCatalogManifest(ui, {
3677
+ functions: dispatcher.listExposed(),
3678
+ targets: inlineTargets,
3658
3679
  surfaces: threadId ? manager.describeSurfaces(threadId) : {}
3659
- };
3680
+ });
3660
3681
  }
3661
3682
  /**
3662
3683
  * Builds the envelope that a run sends as `forwardedProps.copilotkit.ui`,
@@ -3679,7 +3700,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
3679
3700
  * includeCatalog: true,
3680
3701
  * contextSent: false,
3681
3702
  * });
3682
- * envelope["v1.0"].supportedCatalogIds; // [runtime.ui.id]
3703
+ * envelope["1.0"].supportedCatalogIds; // [runtime.ui.id]
3683
3704
  * ```
3684
3705
  */
3685
3706
  function buildGenerativeUIEnvelope(runtime, threadId, options) {
@@ -3688,7 +3709,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
3688
3709
  const instructions = options.instructions ?? (transport === "markdown" ? (0, _copilotkit_shared.buildGenerativeUIMarkdownGuidelines)((0, _copilotkit_shared.generativeUIGuideFeatures)(manifest)) : void 0);
3689
3710
  const omitComponents = transport === "markdown" && !includeCatalog;
3690
3711
  return {
3691
- "v1.0": {
3712
+ "1.0": {
3692
3713
  supportedCatalogIds: manifest.catalogIds ?? [manifest.catalogId],
3693
3714
  inlineCatalogs: [{
3694
3715
  catalogId: manifest.catalogId,
@@ -3709,258 +3730,6 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
3709
3730
  };
3710
3731
  }
3711
3732
 
3712
- //#endregion
3713
- //#region src/v2/generative-ui/is-record.ts
3714
- /** True for a plain object: not null, not an array. Internal, not exported. */
3715
- function isRecord(value) {
3716
- return typeof value === "object" && value !== null && !Array.isArray(value);
3717
- }
3718
-
3719
- //#endregion
3720
- //#region src/v2/generative-ui/markdown/context.ts
3721
- /** Objects nested deeper than this show as `object`. */
3722
- const MAX_OBJECT_DEPTH = 2;
3723
- /** A prop must appear verbatim in at least this many components to be hoisted. */
3724
- const COMMON_PROP_MIN_COMPONENTS = 8;
3725
- /** A JSON Schema of a list of schemas (`anyOf`, `oneOf`), else an empty list. */
3726
- function schemaList(value) {
3727
- return Array.isArray(value) ? value.filter(isRecord) : [];
3728
- }
3729
- /**
3730
- * Puts a top-level union in parentheses, so that `[]` applies to all of
3731
- * it. A union inside braces needs none.
3732
- */
3733
- function asArrayItem(type) {
3734
- let outside = type;
3735
- for (let inner = outside.replace(/\{[^{}]*\}/g, ""); inner !== outside;) {
3736
- outside = inner;
3737
- inner = outside.replace(/\{[^{}]*\}/g, "");
3738
- }
3739
- return outside.includes(" | ") ? `(${type})[]` : `${type}[]`;
3740
- }
3741
- /**
3742
- * A JSON Schema as a short TypeScript-like type, for example
3743
- * `{ label: string; size?: "sm" | "md" }`.
3744
- */
3745
- function compactType(schema, depth) {
3746
- const ref = (0, _copilotkit_shared.childRefKind)(schema);
3747
- if (ref === "single") return "componentId";
3748
- if (ref === "multiple") return "componentId[] | { componentId: string; path: string }";
3749
- if ("const" in schema) return JSON.stringify(schema.const);
3750
- if (Array.isArray(schema.enum)) return schema.enum.map((value) => JSON.stringify(value)).join(" | ");
3751
- const variants = [...schemaList(schema.anyOf), ...schemaList(schema.oneOf)];
3752
- if (variants.length > 0) return variants.map((variant) => compactType(variant, depth)).join(" | ");
3753
- return (Array.isArray(schema.type) ? schema.type : [schema.type]).map((type) => {
3754
- switch (type) {
3755
- case "string":
3756
- case "boolean":
3757
- case "null": return type;
3758
- case "number":
3759
- case "integer": return "number";
3760
- case "array": return isRecord(schema.items) ? asArrayItem(compactType(schema.items, depth)) : "unknown[]";
3761
- case "object": return compactObject(schema, depth);
3762
- default: return "unknown";
3763
- }
3764
- }).join(" | ");
3765
- }
3766
- /** An object schema as `{ key: type; other?: type }`. */
3767
- function compactObject(schema, depth) {
3768
- const properties = isRecord(schema.properties) ? schema.properties : {};
3769
- const entries = Object.entries(properties);
3770
- if (entries.length === 0) return isRecord(schema.additionalProperties) ? `Record<string, ${compactType(schema.additionalProperties, depth + 1)}>` : "object";
3771
- if (depth >= MAX_OBJECT_DEPTH) return "object";
3772
- const required = Array.isArray(schema.required) ? schema.required : [];
3773
- return `{ ${entries.map(([key, value]) => {
3774
- const type = isRecord(value) ? compactType(value, depth + 1) : "unknown";
3775
- return `${key}${required.includes(key) ? "" : "?"}: ${type}`;
3776
- }).join("; ")} }`;
3777
- }
3778
- /** A schema as its type, with its description after `//`. */
3779
- function describedType(schema, depth) {
3780
- const type = compactType(schema, depth);
3781
- return typeof schema.description === "string" ? `${type} // ${schema.description}` : type;
3782
- }
3783
- /** The props of a component: `{ "label": "string", "size?": "..." }`. */
3784
- function compactProps(schema) {
3785
- const properties = isRecord(schema.properties) ? schema.properties : {};
3786
- const required = Array.isArray(schema.required) ? schema.required : [];
3787
- const props = {};
3788
- for (const [key, value] of Object.entries(properties)) {
3789
- if (!isRecord(value)) continue;
3790
- const name = required.includes(key) ? key : `${key}?`;
3791
- props[name] = describedType(value, 1);
3792
- }
3793
- return props;
3794
- }
3795
- /**
3796
- * The prop set worth listing once. Candidates are (key, type) pairs that at
3797
- * least {@link COMMON_PROP_MIN_COMPONENTS} components carry verbatim. The
3798
- * candidate subset of each component is a possible common set, scored by
3799
- * the characters it saves (set size times the components that contain all
3800
- * of it). `undefined` when no set is shared by enough components.
3801
- */
3802
- function findCommonProps(propsList) {
3803
- const pairKey = (key, type) => `${key}\u0000${type}`;
3804
- const counts = /* @__PURE__ */ new Map();
3805
- for (const props of propsList) for (const [key, type] of Object.entries(props)) {
3806
- const id = pairKey(key, type);
3807
- counts.set(id, (counts.get(id) ?? 0) + 1);
3808
- }
3809
- let best;
3810
- let bestScore = 0;
3811
- const seen = /* @__PURE__ */ new Set();
3812
- for (const props of propsList) {
3813
- const subset = Object.entries(props).filter(([key, type]) => (counts.get(pairKey(key, type)) ?? 0) >= COMMON_PROP_MIN_COMPONENTS);
3814
- if (subset.length < 2) continue;
3815
- const signature = subset.map(([key, type]) => pairKey(key, type)).join("\n");
3816
- if (seen.has(signature)) continue;
3817
- seen.add(signature);
3818
- const members = propsList.filter((other) => subset.every(([key, type]) => other[key] === type)).length;
3819
- if (members < COMMON_PROP_MIN_COMPONENTS) continue;
3820
- const score = subset.reduce((total, [key, type]) => total + key.length + type.length, 0) * (members - 1);
3821
- if (score > bestScore) {
3822
- bestScore = score;
3823
- best = Object.fromEntries(subset);
3824
- }
3825
- }
3826
- return best;
3827
- }
3828
- /**
3829
- * The component schema of the markdown transport, from the per-run
3830
- * manifest. It is smaller than the manifest: each prop is one short type,
3831
- * and the props that many components share verbatim (the layout props of
3832
- * the containers) are listed once in `commonProps`; a component that takes
3833
- * them is flagged `includesCommonProps`.
3834
- * It has the catalog id, the targets with their descriptions and their
3835
- * component lists, the functions with their parameters, the components
3836
- * with their props, events and slots, and the surfaces of the thread. A surface lists the
3837
- * values that the user set and the operations that the client dropped.
3838
- *
3839
- * @param manifest - The manifest from `buildGenerativeUIManifest`.
3840
- * @returns A JSON-ready object.
3841
- *
3842
- * @example
3843
- * ```ts
3844
- * const value = JSON.stringify(
3845
- * buildCompactGenerativeUISchema(buildGenerativeUIManifest(runtime, threadId)),
3846
- * );
3847
- * ```
3848
- */
3849
- function buildCompactGenerativeUISchema(manifest) {
3850
- const components = {};
3851
- for (const [name, component] of Object.entries(manifest.components)) {
3852
- const events = Object.entries(component.events ?? {}).map(([event, definition]) => [event, definition.description ?? compactType(definition.parameters, 0)]);
3853
- components[name] = {
3854
- ...component.description ? { description: component.description } : {},
3855
- props: compactProps(component.props),
3856
- ...events.length > 0 ? { events: Object.fromEntries(events) } : {},
3857
- ...component.slots ? { slots: component.slots } : {}
3858
- };
3859
- }
3860
- const common = findCommonProps(Object.values(components).map((component) => component.props));
3861
- if (common) {
3862
- const commonKeys = Object.keys(common);
3863
- for (const component of Object.values(components)) {
3864
- if (!commonKeys.every((key) => component.props[key] === common[key])) continue;
3865
- component.includesCommonProps = true;
3866
- component.props = Object.fromEntries(Object.entries(component.props).filter(([key]) => !(key in common)));
3867
- }
3868
- }
3869
- const functions = Object.fromEntries(Object.entries(manifest.functions).map(([name, fn]) => {
3870
- const signature = fn.parameters.description;
3871
- const hasSignature = typeof signature === "string" && signature.startsWith("{") && Object.keys(fn.parameters).length === 2;
3872
- const callers = (0, _copilotkit_shared.functionCallers)(fn);
3873
- return [name, {
3874
- ...fn.description ? { description: fn.description } : {},
3875
- parameters: hasSignature ? signature : compactType(fn.parameters, 0),
3876
- ...callers.agent && _copilotkit_shared.GENERATIVE_UI_AGENT_FUNCTION_CALLS ? { callers: callers.renderer ? "UI or agent" : "agent only" } : {}
3877
- }];
3878
- }));
3879
- return {
3880
- catalogId: manifest.catalogId,
3881
- targets: manifest.targets,
3882
- functions,
3883
- ...common ? { commonProps: common } : {},
3884
- components,
3885
- surfaces: manifest.surfaces
3886
- };
3887
- }
3888
- /**
3889
- * Registers the two context entries of the markdown transport: the compact
3890
- * component schema and the fence guideline. Both go only to `agentIds`.
3891
- *
3892
- * The schema is built again at each run start and when a
3893
- * `<GenerativeUISurface>` mounts, unmounts, or changes its description or
3894
- * its components, so its targets, functions, and surfaces stay current. The surfaces are those of the running thread.
3895
- *
3896
- * @param copilotkit - The CopilotKit core of the provider.
3897
- * @param runtime - The generative UI runtime parts, or null without one.
3898
- * @param options - `enabled` and `agentIds`.
3899
- *
3900
- * @example
3901
- * ```ts
3902
- * useGenerativeUIMarkdownContext(copilotkit, core, {
3903
- * enabled: config?.transport === "markdown" && config.sendContext !== false,
3904
- * agentIds: config?.agentIds,
3905
- * });
3906
- * ```
3907
- */
3908
- function useGenerativeUIMarkdownContext(copilotkit, runtime, options) {
3909
- const { enabled, agentIds } = options;
3910
- const agentIdsKey = agentIds === void 0 ? "" : JSON.stringify(agentIds);
3911
- (0, react.useEffect)(() => {
3912
- if (!runtime || !enabled) return;
3913
- const scopedAgentIds = agentIdsKey ? JSON.parse(agentIdsKey) : void 0;
3914
- const scope = scopedAgentIds ? { agentIds: scopedAgentIds } : {};
3915
- let guidelineId;
3916
- let guidelineValue;
3917
- let schemaId;
3918
- let schemaValue;
3919
- const refreshSchema = (threadId) => {
3920
- const manifest = buildGenerativeUIManifest(runtime, threadId);
3921
- const guideline = (0, _copilotkit_shared.buildGenerativeUIMarkdownGuidelines)((0, _copilotkit_shared.generativeUIGuideFeatures)(manifest));
3922
- if (guideline !== guidelineValue) {
3923
- if (guidelineId !== void 0) copilotkit.removeContext(guidelineId);
3924
- guidelineValue = guideline;
3925
- guidelineId = copilotkit.addContext({
3926
- description: _copilotkit_shared.GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION,
3927
- value: guideline,
3928
- ...scope
3929
- });
3930
- }
3931
- const value = JSON.stringify(buildCompactGenerativeUISchema(manifest));
3932
- if (value === schemaValue) return;
3933
- if (schemaId !== void 0) copilotkit.removeContext(schemaId);
3934
- schemaValue = value;
3935
- schemaId = copilotkit.addContext({
3936
- description: _copilotkit_shared.GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION,
3937
- value,
3938
- ...scope
3939
- });
3940
- };
3941
- refreshSchema(runtime.manager.getActiveThread());
3942
- let targetsKey = JSON.stringify(runtime.manager.getMountedTargets());
3943
- const unsubscribeManager = runtime.manager.subscribe(() => {
3944
- const nextKey = JSON.stringify(runtime.manager.getMountedTargets());
3945
- if (nextKey === targetsKey) return;
3946
- targetsKey = nextKey;
3947
- refreshSchema(runtime.manager.getActiveThread());
3948
- });
3949
- const subscription = copilotkit.subscribe({ onAgentRunStarted: ({ agent }) => refreshSchema(agent.threadId) });
3950
- return () => {
3951
- subscription.unsubscribe();
3952
- unsubscribeManager();
3953
- if (guidelineId !== void 0) copilotkit.removeContext(guidelineId);
3954
- if (schemaId !== void 0) copilotkit.removeContext(schemaId);
3955
- };
3956
- }, [
3957
- copilotkit,
3958
- runtime,
3959
- enabled,
3960
- agentIdsKey
3961
- ]);
3962
- }
3963
-
3964
3733
  //#endregion
3965
3734
  //#region src/v2/generative-ui/debug-source.ts
3966
3735
  /**
@@ -3993,7 +3762,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
3993
3762
  }]
3994
3763
  };
3995
3764
  const guideline = (0, _copilotkit_shared.buildGenerativeUIMarkdownGuidelines)((0, _copilotkit_shared.generativeUIGuideFeatures)(manifest));
3996
- const schema = JSON.stringify(buildCompactGenerativeUISchema(manifest));
3765
+ const schema = (0, _copilotkit_shared.renderGenerativeUISchema)(manifest, (0, _copilotkit_shared.defaultGenerativeUIPromptSpec)().schema.markdown);
3997
3766
  return {
3998
3767
  envelope,
3999
3768
  prompt: [{
@@ -4485,6 +4254,91 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
4485
4254
  };
4486
4255
  }
4487
4256
 
4257
+ //#endregion
4258
+ //#region src/v2/generative-ui/markdown/context.ts
4259
+ /**
4260
+ * Registers the two context entries of the markdown transport: the compact
4261
+ * component schema and the fence guideline. Both go only to `agentIds`.
4262
+ *
4263
+ * The schema is built again at each run start and when a
4264
+ * `<GenerativeUISurface>` mounts, unmounts, or changes its description or
4265
+ * its components, so its targets, functions, and surfaces stay current. The surfaces are those of the running thread.
4266
+ *
4267
+ * @param copilotkit - The CopilotKit core of the provider.
4268
+ * @param runtime - The generative UI runtime parts, or null without one.
4269
+ * @param options - `enabled` and `agentIds`.
4270
+ *
4271
+ * @example
4272
+ * ```ts
4273
+ * useGenerativeUIMarkdownContext(copilotkit, core, {
4274
+ * enabled: config?.transport === "markdown" && config.sendContext !== false,
4275
+ * agentIds: config?.agentIds,
4276
+ * });
4277
+ * ```
4278
+ */
4279
+ function useGenerativeUIMarkdownContext(copilotkit, runtime, options) {
4280
+ const { enabled, agentIds } = options;
4281
+ const agentIdsKey = agentIds === void 0 ? "" : JSON.stringify(agentIds);
4282
+ (0, react.useEffect)(() => {
4283
+ if (!runtime || !enabled) return;
4284
+ const scopedAgentIds = agentIdsKey ? JSON.parse(agentIdsKey) : void 0;
4285
+ const scope = scopedAgentIds ? { agentIds: scopedAgentIds } : {};
4286
+ let guidelineId;
4287
+ let guidelineValue;
4288
+ let schemaId;
4289
+ let schemaValue;
4290
+ const refreshSchema = (threadId) => {
4291
+ const manifest = buildGenerativeUIManifest(runtime, threadId);
4292
+ const guideline = (0, _copilotkit_shared.buildGenerativeUIMarkdownGuidelines)((0, _copilotkit_shared.generativeUIGuideFeatures)(manifest));
4293
+ if (guideline !== guidelineValue) {
4294
+ if (guidelineId !== void 0) copilotkit.removeContext(guidelineId);
4295
+ guidelineValue = guideline;
4296
+ guidelineId = copilotkit.addContext({
4297
+ description: _copilotkit_shared.GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION,
4298
+ value: guideline,
4299
+ ...scope
4300
+ });
4301
+ }
4302
+ const value = (0, _copilotkit_shared.renderGenerativeUISchema)(manifest, (0, _copilotkit_shared.defaultGenerativeUIPromptSpec)().schema.markdown);
4303
+ if (value === schemaValue) return;
4304
+ if (schemaId !== void 0) copilotkit.removeContext(schemaId);
4305
+ schemaValue = value;
4306
+ schemaId = copilotkit.addContext({
4307
+ description: _copilotkit_shared.GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION,
4308
+ value,
4309
+ ...scope
4310
+ });
4311
+ };
4312
+ refreshSchema(runtime.manager.getActiveThread());
4313
+ let targetsKey = JSON.stringify(runtime.manager.getMountedTargets());
4314
+ const unsubscribeManager = runtime.manager.subscribe(() => {
4315
+ const nextKey = JSON.stringify(runtime.manager.getMountedTargets());
4316
+ if (nextKey === targetsKey) return;
4317
+ targetsKey = nextKey;
4318
+ refreshSchema(runtime.manager.getActiveThread());
4319
+ });
4320
+ const subscription = copilotkit.subscribe({ onAgentRunStarted: ({ agent }) => refreshSchema(agent.threadId) });
4321
+ return () => {
4322
+ subscription.unsubscribe();
4323
+ unsubscribeManager();
4324
+ if (guidelineId !== void 0) copilotkit.removeContext(guidelineId);
4325
+ if (schemaId !== void 0) copilotkit.removeContext(schemaId);
4326
+ };
4327
+ }, [
4328
+ copilotkit,
4329
+ runtime,
4330
+ enabled,
4331
+ agentIdsKey
4332
+ ]);
4333
+ }
4334
+
4335
+ //#endregion
4336
+ //#region src/v2/generative-ui/is-record.ts
4337
+ /** True for a plain object: not null, not an array. Internal, not exported. */
4338
+ function isRecord(value) {
4339
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4340
+ }
4341
+
4488
4342
  //#endregion
4489
4343
  //#region src/v2/generative-ui/markdown/source.ts
4490
4344
  /**
@@ -5133,6 +4987,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
5133
4987
  "*",
5134
4988
  "/",
5135
4989
  "%",
4990
+ "^",
5136
4991
  "(",
5137
4992
  ")",
5138
4993
  ",",
@@ -5219,7 +5074,29 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
5219
5074
  round: ([x, decimals = 0]) => {
5220
5075
  const factor = 10 ** Math.trunc(decimals);
5221
5076
  return Math.round(x * factor) / factor;
5222
- }
5077
+ },
5078
+ pow: ([x, y]) => x ** y,
5079
+ sqrt: ([x]) => Math.sqrt(x),
5080
+ exp: ([x]) => Math.exp(x),
5081
+ ln: ([x]) => Math.log(x),
5082
+ log10: ([x]) => Math.log10(x)
5083
+ };
5084
+ /** How many args a function takes, at least and at most; min and max take any. */
5085
+ const ARITY = {
5086
+ abs: [1, 1],
5087
+ floor: [1, 1],
5088
+ ceil: [1, 1],
5089
+ round: [1, 2],
5090
+ pow: [2, 2],
5091
+ sqrt: [1, 1],
5092
+ exp: [1, 1],
5093
+ ln: [1, 1],
5094
+ log10: [1, 1]
5095
+ };
5096
+ /** Named constants, when no arg of the same name is passed. */
5097
+ const CONSTANTS = {
5098
+ pi: Math.PI,
5099
+ e: Math.E
5223
5100
  };
5224
5101
  var CalcParser = class {
5225
5102
  constructor(tokens, scope, source) {
@@ -5354,7 +5231,20 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
5354
5231
  this.pos++;
5355
5232
  return !truthOf(this.unary());
5356
5233
  }
5357
- return this.primary();
5234
+ return this.power();
5235
+ }
5236
+ /** `a ^ b`: binds tighter than `*` and unary minus, right to left. */
5237
+ power() {
5238
+ const base = this.primary();
5239
+ if (!this.peekOp("^")) return base;
5240
+ this.pos++;
5241
+ const exponent = this.unary();
5242
+ if (this.skipDepth > 0) return null;
5243
+ return this.finite(this.num(base, "the left side of ^") ** this.num(exponent, "the right side of ^"), "^");
5244
+ }
5245
+ finite(value, what) {
5246
+ if (!Number.isFinite(value)) this.fail(`${what} has no finite result`);
5247
+ return value;
5358
5248
  }
5359
5249
  primary() {
5360
5250
  const token = this.tokens[this.pos++];
@@ -5389,10 +5279,15 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
5389
5279
  const fn = Object.prototype.hasOwnProperty.call(MATH, name) ? MATH[name] : void 0;
5390
5280
  if (!fn) this.fail(`unknown function ${name}`);
5391
5281
  if (args.length === 0) this.fail(`${name} needs an argument`);
5392
- return fn(args);
5282
+ const [least, most] = ARITY[name] ?? [1, Infinity];
5283
+ if (args.length < least || args.length > most) this.fail(`${name} takes ${least === most ? least : `${least} or ${most}`} argument${most === 1 ? "" : "s"}`);
5284
+ return this.finite(fn(args), name);
5393
5285
  }
5394
5286
  if (this.skipDepth > 0) return null;
5395
- if (!Object.prototype.hasOwnProperty.call(this.scope, name)) this.fail(`unknown name ${name}; pass it as an arg`);
5287
+ if (!Object.prototype.hasOwnProperty.call(this.scope, name)) {
5288
+ if (Object.prototype.hasOwnProperty.call(CONSTANTS, name)) return CONSTANTS[name];
5289
+ this.fail(`unknown name ${name}; pass it as an arg`);
5290
+ }
5396
5291
  const value = this.scope[name];
5397
5292
  if (value !== null && typeof value !== "number" && typeof value !== "string" && typeof value !== "boolean") this.fail(`${name} is not a number, text or boolean (${describe(value)})`);
5398
5293
  return value;
@@ -10072,6 +9967,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
10072
9967
 
10073
9968
  //#endregion
10074
9969
  //#region src/v2/hooks/use-interrupt.tsx
9970
+ /** Recognize thenables returned by interrupt preprocessing handlers. */
10075
9971
  function isPromiseLike(value) {
10076
9972
  return (typeof value === "object" || typeof value === "function") && value !== null && typeof Reflect.get(value, "then") === "function";
10077
9973
  }
@@ -10122,7 +10018,6 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
10122
10018
  const [handlerResult, setHandlerResult] = (0, react.useState)(null);
10123
10019
  const interruptStateRef = (0, react.useRef)(new _copilotkit_core.ɵInterruptState());
10124
10020
  (0, react.useEffect)(() => {
10125
- const interruptState = interruptStateRef.current;
10126
10021
  let localLegacy = null;
10127
10022
  let localStandard = null;
10128
10023
  const subscription = agent.subscribe({
@@ -10135,19 +10030,21 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
10135
10030
  onRunFinishedEvent: (params) => {
10136
10031
  if (params.outcome === "interrupt") localStandard = params.interrupts;
10137
10032
  },
10138
- onRunStartedEvent: () => {
10033
+ onRunStartedEvent: (params) => {
10034
+ if (!agent.pendingInterrupts?.length || params?.input?.resume !== void 0) (0, _copilotkit_core.ɵclearAgentInterruptState)(agent);
10139
10035
  localLegacy = null;
10140
10036
  localStandard = null;
10141
- interruptState.clear();
10037
+ interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
10142
10038
  setPending(null);
10143
10039
  },
10144
10040
  onRunFinalized: () => {
10145
10041
  if (localStandard && localStandard.length > 0) {
10146
- interruptState.setStandard(localStandard);
10147
- setPending(interruptState.pending);
10042
+ interruptStateRef.current = (0, _copilotkit_core.ɵgetAgentInterruptState)(agent, localStandard);
10043
+ setPending(interruptStateRef.current.pending);
10148
10044
  } else if (localLegacy) {
10149
- interruptState.setLegacy(localLegacy);
10150
- setPending(interruptState.pending);
10045
+ interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
10046
+ interruptStateRef.current.setLegacy(localLegacy);
10047
+ setPending(interruptStateRef.current.pending);
10151
10048
  }
10152
10049
  localLegacy = null;
10153
10050
  localStandard = null;
@@ -10155,20 +10052,27 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
10155
10052
  onRunFailed: () => {
10156
10053
  localLegacy = null;
10157
10054
  localStandard = null;
10158
- interruptState.clear();
10055
+ interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
10159
10056
  setPending(null);
10160
10057
  }
10161
10058
  });
10059
+ interruptStateRef.current = agent.pendingInterrupts?.length ? (0, _copilotkit_core.ɵgetAgentInterruptState)(agent) : new _copilotkit_core.ɵInterruptState();
10060
+ setPending(interruptStateRef.current.pending);
10162
10061
  return () => {
10163
10062
  subscription.unsubscribe();
10164
- interruptState.clear();
10063
+ interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
10165
10064
  };
10166
10065
  }, [agent]);
10066
+ /** Record an explicit answer and resume once the complete batch is addressed. */
10167
10067
  const resolve = (0, react.useCallback)(async (payload, interruptId) => {
10168
10068
  const current = pendingRef.current;
10169
10069
  if (!current) return;
10170
10070
  if (current.kind === "standard" && current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
10171
- const decision = interruptStateRef.current.resolve(payload, interruptId);
10071
+ if (interruptStateRef.current.isCompletedToolCall(interruptId, agent.messages)) {
10072
+ console.warn("[CopilotKit] useInterrupt: ignoring an answer for an already completed frontend tool call.");
10073
+ return;
10074
+ }
10075
+ const decision = interruptStateRef.current.resolve(payload, interruptId, agent.messages);
10172
10076
  if (decision.kind === "legacy-resume") try {
10173
10077
  return await copilotkit.runAgent({
10174
10078
  agent,
@@ -10184,7 +10088,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
10184
10088
  }
10185
10089
  if (decision.kind === "expired") {
10186
10090
  console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
10187
- interruptStateRef.current.clear();
10091
+ interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
10188
10092
  setPending(null);
10189
10093
  return;
10190
10094
  }
@@ -10202,25 +10106,30 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
10202
10106
  });
10203
10107
  } catch (err) {
10204
10108
  console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
10205
- interruptStateRef.current.clear();
10109
+ interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
10206
10110
  setPending(null);
10207
10111
  throw err;
10208
10112
  }
10209
10113
  }, [agent, copilotkit]);
10114
+ /** Cancel a standard interrupt or dismiss a legacy interrupt locally. */
10210
10115
  const cancel = (0, react.useCallback)(async (interruptId) => {
10211
10116
  const current = pendingRef.current;
10212
10117
  if (!current) return;
10213
10118
  if (current.kind === "standard" && current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
10214
- const decision = interruptStateRef.current.cancel(interruptId);
10119
+ if (interruptStateRef.current.isCompletedToolCall(interruptId, agent.messages)) {
10120
+ console.warn("[CopilotKit] useInterrupt: ignoring an answer for an already completed frontend tool call.");
10121
+ return;
10122
+ }
10123
+ const decision = interruptStateRef.current.cancel(interruptId, agent.messages);
10215
10124
  if (decision.kind === "dismiss") {
10216
10125
  console.warn("[CopilotKit] useInterrupt: cancel() is not supported for legacy on_interrupt interrupts; dismissing.");
10217
- interruptStateRef.current.clear();
10126
+ interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
10218
10127
  setPending(null);
10219
10128
  return;
10220
10129
  }
10221
10130
  if (decision.kind === "expired") {
10222
10131
  console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
10223
- interruptStateRef.current.clear();
10132
+ interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
10224
10133
  setPending(null);
10225
10134
  return;
10226
10135
  }
@@ -10238,7 +10147,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
10238
10147
  });
10239
10148
  } catch (err) {
10240
10149
  console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
10241
- interruptStateRef.current.clear();
10150
+ interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
10242
10151
  setPending(null);
10243
10152
  throw err;
10244
10153
  }
@@ -10253,6 +10162,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
10253
10162
  resolveRef.current = resolve;
10254
10163
  const cancelRef = (0, react.useRef)(cancel);
10255
10164
  cancelRef.current = cancel;
10165
+ /** Evaluate the consumer filter, logging failures and disabling their UI. */
10256
10166
  const isEnabled = (event) => {
10257
10167
  const predicate = enabledRef.current;
10258
10168
  if (!predicate) return true;
@@ -13970,10 +13880,13 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13970
13880
  total: 0,
13971
13881
  sizes: /* @__PURE__ */ new Map()
13972
13882
  });
13883
+ const resizeAnchorRef = react.default.useRef(null);
13884
+ const restoringVisibilityRef = react.default.useRef(false);
13973
13885
  const firstMessageId = deduplicatedMessages[0]?.id;
13974
13886
  const measuredThreadRef = react.default.useRef(firstMessageId);
13975
13887
  if (measuredThreadRef.current !== firstMessageId) {
13976
13888
  measuredThreadRef.current = firstMessageId;
13889
+ resizeAnchorRef.current = null;
13977
13890
  measuredRef.current = {
13978
13891
  total: 0,
13979
13892
  sizes: /* @__PURE__ */ new Map()
@@ -13983,7 +13896,28 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13983
13896
  const { total, sizes } = measuredRef.current;
13984
13897
  return sizes.size > 0 ? Math.max(1, Math.round(total / sizes.size)) : 100;
13985
13898
  }, []);
13986
- const measureRowElement = react.default.useCallback((el) => {
13899
+ const isPinnedToBottomRef = react.default.useRef(isPinnedToBottom);
13900
+ const measuredWidthRef = react.default.useRef(null);
13901
+ const captureResizeAnchor = react.default.useCallback((instance) => {
13902
+ const width = instance.scrollElement?.clientWidth;
13903
+ if (!width || instance.scrollElement?.clientHeight === 0 || restoringVisibilityRef.current || isPinnedToBottomRef.current || instance.options.count === 0 || measuredWidthRef.current === null || width === measuredWidthRef.current) return;
13904
+ if (resizeAnchorRef.current) {
13905
+ if (resizeAnchorRef.current.ready) resizeAnchorRef.current = {
13906
+ ...resizeAnchorRef.current,
13907
+ ready: false
13908
+ };
13909
+ return;
13910
+ }
13911
+ const offset = instance.scrollElement?.scrollTop ?? 0;
13912
+ const anchor = instance.getVirtualItemForOffset(offset);
13913
+ if (anchor) resizeAnchorRef.current = {
13914
+ index: anchor.index,
13915
+ offset: offset - anchor.start,
13916
+ ready: false
13917
+ };
13918
+ }, []);
13919
+ const measureRowElement = react.default.useCallback((el, _entry, instance) => {
13920
+ captureResizeAnchor(instance);
13987
13921
  const height = el?.getBoundingClientRect().height ?? 0;
13988
13922
  const index = Number(el?.dataset?.index);
13989
13923
  if (height > 0 && Number.isInteger(index)) {
@@ -13992,16 +13926,70 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13992
13926
  sizes.set(index, height);
13993
13927
  }
13994
13928
  return height > 0 ? height : measuredRef.current.sizes.get(index) ?? 100;
13995
- }, []);
13996
- const isPinnedToBottomRef = react.default.useRef(isPinnedToBottom);
13929
+ }, [captureResizeAnchor]);
13997
13930
  const shouldAdjustScrollOnResize = react.default.useCallback((item, _delta, instance) => {
13998
- if (isPinnedToBottomRef.current) return false;
13931
+ if (isPinnedToBottomRef.current || resizeAnchorRef.current || restoringVisibilityRef.current) return false;
13999
13932
  const scrollAdjustments = instance.scrollAdjustments ?? 0;
14000
13933
  return item.start < (instance.scrollOffset ?? 0) + scrollAdjustments;
14001
13934
  }, []);
13935
+ const observeScrollRect = react.default.useCallback((instance, notify) => {
13936
+ let frame;
13937
+ let pendingRect;
13938
+ const disconnect = (0, _tanstack_react_virtual.observeElementRect)(instance, (rect) => {
13939
+ if (instance.scrollElement?.clientHeight === 0) {
13940
+ restoringVisibilityRef.current = true;
13941
+ resizeAnchorRef.current = null;
13942
+ if (frame !== void 0) cancelAnimationFrame(frame);
13943
+ frame = void 0;
13944
+ pendingRect = void 0;
13945
+ notify(rect);
13946
+ return;
13947
+ }
13948
+ const width = instance.scrollElement?.clientWidth ?? rect.width;
13949
+ const previousWidth = measuredWidthRef.current;
13950
+ if (width > 0 && width !== previousWidth) {
13951
+ captureResizeAnchor(instance);
13952
+ if (previousWidth !== null) {
13953
+ pendingRect = rect;
13954
+ if (frame === void 0) frame = requestAnimationFrame(() => {
13955
+ frame = void 0;
13956
+ const nextRect = pendingRect;
13957
+ pendingRect = void 0;
13958
+ if (!instance.scrollElement?.clientHeight) return;
13959
+ measuredWidthRef.current = instance.scrollElement?.clientWidth ?? nextRect.width;
13960
+ if (resizeAnchorRef.current) resizeAnchorRef.current.ready = true;
13961
+ instance.getTotalSize();
13962
+ measuredRef.current = {
13963
+ total: 0,
13964
+ sizes: /* @__PURE__ */ new Map()
13965
+ };
13966
+ instance.elementsCache.forEach((element) => {
13967
+ measureRowElement(element, void 0, instance);
13968
+ });
13969
+ instance.measure();
13970
+ instance.getTotalSize();
13971
+ instance.elementsCache.forEach((element) => {
13972
+ instance.measureElement(element);
13973
+ });
13974
+ notify(nextRect);
13975
+ });
13976
+ return;
13977
+ }
13978
+ measuredWidthRef.current = width;
13979
+ }
13980
+ if (pendingRect) pendingRect = rect;
13981
+ else notify(rect);
13982
+ });
13983
+ return () => {
13984
+ disconnect?.();
13985
+ if (frame !== void 0) cancelAnimationFrame(frame);
13986
+ resizeAnchorRef.current = null;
13987
+ };
13988
+ }, [captureResizeAnchor, measureRowElement]);
14002
13989
  const virtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
14003
13990
  count: shouldVirtualize ? rows.length : 0,
14004
13991
  getScrollElement: () => shouldVirtualize ? scrollElement : null,
13992
+ observeElementRect: observeScrollRect,
14005
13993
  estimateSize: estimateRowSize,
14006
13994
  overscan: 5,
14007
13995
  measureElement: measureRowElement,
@@ -14012,6 +14000,19 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14012
14000
  });
14013
14001
  isPinnedToBottomRef.current = isPinnedToBottom;
14014
14002
  virtualizer.shouldAdjustScrollPositionOnItemSizeChange = shouldAdjustScrollOnResize;
14003
+ (0, react.useLayoutEffect)(() => {
14004
+ const anchor = resizeAnchorRef.current;
14005
+ if (!anchor?.ready || restoringVisibilityRef.current) return;
14006
+ const position = virtualizer.getOffsetForIndex(anchor.index, "start");
14007
+ if (position && !isPinnedToBottomRef.current) {
14008
+ const target = position[0] + anchor.offset;
14009
+ if (Math.abs((scrollElement?.scrollTop ?? 0) - target) > .5) virtualizer.scrollToOffset(target);
14010
+ }
14011
+ const frame = requestAnimationFrame(() => {
14012
+ if (resizeAnchorRef.current === anchor) resizeAnchorRef.current = null;
14013
+ });
14014
+ return () => cancelAnimationFrame(frame);
14015
+ });
14015
14016
  const lastEndAlignedFirstMessageRef = react.default.useRef(void 0);
14016
14017
  (0, react.useLayoutEffect)(() => {
14017
14018
  if (!shouldVirtualize || !rows.length) return;
@@ -14120,22 +14121,33 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14120
14121
  const observer = new ResizeObserver(() => {
14121
14122
  if (element.clientHeight === 0) {
14122
14123
  suspended = true;
14124
+ restoringVisibilityRef.current = true;
14125
+ resizeAnchorRef.current = null;
14123
14126
  cancelAnimationFrame(frame);
14124
14127
  return;
14125
14128
  }
14126
14129
  if (!suspended || !anchor) {
14127
14130
  suspended = false;
14131
+ restoringVisibilityRef.current = false;
14128
14132
  remember();
14129
14133
  return;
14130
14134
  }
14135
+ cancelAnimationFrame(frame);
14131
14136
  let attempts = 0;
14132
14137
  let stableFrames = 0;
14133
14138
  const restore = () => {
14134
14139
  if (!anchor || element.clientHeight === 0) return;
14140
+ if (isPinnedToBottomRef.current) {
14141
+ anchor = null;
14142
+ suspended = false;
14143
+ restoringVisibilityRef.current = false;
14144
+ return;
14145
+ }
14135
14146
  const index = rowKeysRef.current.indexOf(anchor.key);
14136
14147
  if (index < 0) {
14137
14148
  anchor = null;
14138
14149
  suspended = false;
14150
+ restoringVisibilityRef.current = false;
14139
14151
  return;
14140
14152
  }
14141
14153
  const row = visibleRows().find((row) => row.dataset.scrollAnchor === anchor.key);
@@ -14151,6 +14163,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14151
14163
  if (++attempts < 60 && stableFrames < 3) frame = requestAnimationFrame(restore);
14152
14164
  else {
14153
14165
  suspended = false;
14166
+ restoringVisibilityRef.current = false;
14154
14167
  remember();
14155
14168
  }
14156
14169
  };
@@ -14160,6 +14173,8 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14160
14173
  cancelAnimationFrame(frame);
14161
14174
  anchor = null;
14162
14175
  suspended = false;
14176
+ restoringVisibilityRef.current = false;
14177
+ resizeAnchorRef.current = null;
14163
14178
  };
14164
14179
  element.addEventListener("scroll", remember, { passive: true });
14165
14180
  element.addEventListener("wheel", interrupt, { passive: true });
@@ -14170,6 +14185,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14170
14185
  return () => {
14171
14186
  cancelAnimationFrame(frame);
14172
14187
  observer.disconnect();
14188
+ restoringVisibilityRef.current = false;
14173
14189
  element.removeEventListener("scroll", remember);
14174
14190
  element.removeEventListener("wheel", interrupt);
14175
14191
  element.removeEventListener("touchstart", interrupt);
@@ -14213,7 +14229,8 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14213
14229
  shouldVirtualize ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
14214
14230
  style: {
14215
14231
  height: virtualizer.getTotalSize(),
14216
- position: "relative"
14232
+ position: "relative",
14233
+ overflowAnchor: "none"
14217
14234
  },
14218
14235
  children: virtualizer.getVirtualItems().map((virtualItem) => {
14219
14236
  const row = rows[virtualItem.index];
@@ -14572,6 +14589,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14572
14589
  const lastNonceRef = (0, react.useRef)(-1);
14573
14590
  (0, react.useEffect)(() => {
14574
14591
  if (sendNonce === lastNonceRef.current) return;
14592
+ const previousNonce = lastNonceRef.current;
14575
14593
  lastNonceRef.current = sendNonce;
14576
14594
  if (!id) return;
14577
14595
  const scrollEl = scrollRef.current;
@@ -14587,7 +14605,9 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14587
14605
  const bubbleHeight = Math.max(0, userMessageHeight - paddingTop);
14588
14606
  const spacerHeight = Math.max(0, viewportHeight - bubbleHeight - topOffset);
14589
14607
  spacerEl.style.height = `${spacerHeight}px`;
14608
+ let pinned = false;
14590
14609
  const raf = requestAnimationFrame(() => {
14610
+ pinned = true;
14591
14611
  const targetTop = computeOffsetTop(targetEl, scrollEl) + paddingTop - topOffset;
14592
14612
  scrollEl.scrollTo({
14593
14613
  top: Math.max(0, targetTop),
@@ -14604,6 +14624,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14604
14624
  return () => {
14605
14625
  cancelAnimationFrame(raf);
14606
14626
  ro.disconnect();
14627
+ if (!pinned) lastNonceRef.current = previousNonce;
14607
14628
  };
14608
14629
  }, [
14609
14630
  id,
@@ -14635,7 +14656,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14635
14656
  })
14636
14657
  });
14637
14658
  }
14638
- function CopilotChatView({ messageView, input, scrollView, suggestionView, welcomeScreen, messages = [], autoScroll = true, isRunning = false, suggestions, suggestionLoadingIndexes, onSelectSuggestion, onSubmitMessage, onStop, inputMode, inputValue, onInputChange, onStartTranscribe, onCancelTranscribe, onFinishTranscribe, onFinishTranscribeWithAudio, attachments, onRemoveAttachment, onAddFile, dragOver, onDragOver, onDragLeave, onDrop, isConnecting = false, hasExplicitThreadId = false, disclaimer, intelligenceIndicator, children, className, ...props }) {
14659
+ function CopilotChatView({ messageView, input, scrollView, suggestionView, welcomeScreen, messages = [], autoScroll = true, isRunning = false, suggestions, suggestionLoadingIndexes, onSelectSuggestion, onSubmitMessage, onStop, inputMode, inputValue, onInputChange, onStartTranscribe, onCancelTranscribe, onFinishTranscribe, onFinishTranscribeWithAudio, attachments, onRemoveAttachment, onAddFile, dragOver, onDragOver, onDragLeave, onDrop, isConnecting = false, connectingIndicator, hasExplicitThreadId = false, disclaimer, intelligenceIndicator, children, className, ...props }) {
14639
14660
  const configuredThreadId = useCopilotChatConfiguration()?.threadId;
14640
14661
  const [fallbackThreadId, setFallbackThreadId] = (0, react.useState)(messages[0]?.id);
14641
14662
  const previousMessageIds = (0, react.useRef)(/* @__PURE__ */ new Set());
@@ -14710,6 +14731,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14710
14731
  onSelectSuggestion,
14711
14732
  className: "cpk:mb-3 cpk:lg:ml-4 cpk:lg:mr-4 cpk:ml-0 cpk:mr-0"
14712
14733
  }) : null;
14734
+ const BoundConnectingIndicator = isConnecting && messages.length === 0 && connectingIndicator !== false ? renderSlot(connectingIndicator === true ? void 0 : connectingIndicator, CopilotChatView.ConnectingIndicator, {}) : null;
14713
14735
  const BoundScrollView = renderSlot(scrollView, CopilotChatView.ScrollView, {
14714
14736
  autoScroll,
14715
14737
  scrollThreadId,
@@ -14720,10 +14742,14 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14720
14742
  style: { paddingBottom: `${inputContainerHeight + (hasSuggestions ? 4 : 32)}px` },
14721
14743
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
14722
14744
  className: "cpk:max-w-3xl cpk:mx-auto",
14723
- children: [BoundMessageView, hasSuggestions ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
14724
- className: "cpk:pl-0 cpk:pr-4 cpk:@3xl:px-0 cpk:mt-4",
14725
- children: BoundSuggestionView
14726
- }) : null]
14745
+ children: [
14746
+ BoundConnectingIndicator,
14747
+ BoundMessageView,
14748
+ hasSuggestions ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
14749
+ className: "cpk:pl-0 cpk:pr-4 cpk:@3xl:px-0 cpk:mt-4",
14750
+ children: BoundSuggestionView
14751
+ }) : null
14752
+ ]
14727
14753
  })
14728
14754
  })
14729
14755
  });
@@ -14761,6 +14787,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14761
14787
  "data-copilotkit": true,
14762
14788
  "data-testid": "copilot-chat",
14763
14789
  "data-copilot-running": isRunning ? "true" : "false",
14790
+ "data-copilot-connecting": isConnecting ? "true" : "false",
14764
14791
  onDragOver,
14765
14792
  onDragLeave,
14766
14793
  onDrop,
@@ -14771,6 +14798,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14771
14798
  }
14772
14799
  if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
14773
14800
  "data-copilotkit": true,
14801
+ "data-copilot-connecting": isConnecting ? "true" : "false",
14774
14802
  style: { display: "contents" },
14775
14803
  children: children({
14776
14804
  messageView: BoundMessageView,
@@ -14783,6 +14811,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14783
14811
  "data-copilotkit": true,
14784
14812
  "data-testid": "copilot-chat",
14785
14813
  "data-copilot-running": isRunning ? "true" : "false",
14814
+ "data-copilot-connecting": isConnecting ? "true" : "false",
14786
14815
  onDragOver,
14787
14816
  onDragLeave,
14788
14817
  onDrop,
@@ -14998,13 +15027,15 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
14998
15027
  if (mode === "pin-to-bottom") return;
14999
15028
  const scrollElement = nonAutoScrollEl;
15000
15029
  if (!scrollElement) return;
15030
+ const contentElement = contentRef.current;
15001
15031
  const checkScroll = () => {
15002
- setShowScrollButton(!(scrollElement.scrollHeight - scrollElement.scrollTop - scrollElement.clientHeight < 10));
15032
+ setShowScrollButton((contentElement ? contentElement.getBoundingClientRect().bottom - scrollElement.getBoundingClientRect().bottom : scrollElement.scrollHeight - scrollElement.scrollTop - scrollElement.clientHeight) >= 10);
15003
15033
  };
15004
15034
  checkScroll();
15005
15035
  scrollElement.addEventListener("scroll", checkScroll);
15006
15036
  const resizeObserver = new ResizeObserver(checkScroll);
15007
15037
  resizeObserver.observe(scrollElement);
15038
+ if (contentElement) resizeObserver.observe(contentElement);
15008
15039
  return () => {
15009
15040
  scrollElement.removeEventListener("scroll", checkScroll);
15010
15041
  resizeObserver.disconnect();
@@ -15087,6 +15118,22 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
15087
15118
  className,
15088
15119
  ...props
15089
15120
  });
15121
+ _CopilotChatView.ConnectingIndicator = ({ className, ...props }) => {
15122
+ const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
15123
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
15124
+ "data-testid": "copilot-connecting-indicator",
15125
+ role: "status",
15126
+ className: cn("cpk:flex cpk:justify-center cpk:py-8", className),
15127
+ ...props,
15128
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2, {
15129
+ "aria-hidden": "true",
15130
+ className: "cpk:size-6 cpk:animate-spin cpk:text-muted-foreground"
15131
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
15132
+ className: "cpk:sr-only",
15133
+ children: labels.chatConnectingLabel
15134
+ })]
15135
+ });
15136
+ };
15090
15137
  _CopilotChatView.WelcomeMessage = ({ className, ...props }) => {
15091
15138
  const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
15092
15139
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", {
@@ -20487,6 +20534,12 @@ Object.defineProperty(exports, 'ɵTHREAD_REQUEST_TIMEOUT_MS', {
20487
20534
  return _copilotkit_core.ɵTHREAD_REQUEST_TIMEOUT_MS;
20488
20535
  }
20489
20536
  });
20537
+ Object.defineProperty(exports, 'ɵclearAgentInterruptState', {
20538
+ enumerable: true,
20539
+ get: function () {
20540
+ return _copilotkit_core.ɵclearAgentInterruptState;
20541
+ }
20542
+ });
20490
20543
  Object.defineProperty(exports, 'ɵcreateMemoryStore', {
20491
20544
  enumerable: true,
20492
20545
  get: function () {
@@ -20505,6 +20558,12 @@ Object.defineProperty(exports, 'ɵcreateThreadStore', {
20505
20558
  return _copilotkit_core.ɵcreateThreadStore;
20506
20559
  }
20507
20560
  });
20561
+ Object.defineProperty(exports, 'ɵgetAgentInterruptState', {
20562
+ enumerable: true,
20563
+ get: function () {
20564
+ return _copilotkit_core.ɵgetAgentInterruptState;
20565
+ }
20566
+ });
20508
20567
  Object.defineProperty(exports, 'ɵisCopilotKitFeature', {
20509
20568
  enumerable: true,
20510
20569
  get: function () {