@copilotkit/react-core 1.86.0 → 1.87.1
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.
- package/dist/{copilotkit-B1OLgEU8.mjs → copilotkit-BJ-6BoJ_.mjs} +127 -28
- package/dist/copilotkit-BJ-6BoJ_.mjs.map +1 -0
- package/dist/{copilotkit-C7G95NO-.d.mts → copilotkit-BNPEXnEE.d.mts} +8 -3
- package/dist/{copilotkit-C7G95NO-.d.mts.map → copilotkit-BNPEXnEE.d.mts.map} +1 -1
- package/dist/{copilotkit-DwD7D6jJ.d.cts → copilotkit-Bop-sY6y.d.cts} +8 -3
- package/dist/{copilotkit-DwD7D6jJ.d.cts.map → copilotkit-Bop-sY6y.d.cts.map} +1 -1
- package/dist/{copilotkit-Ca0IcTZU.cjs → copilotkit-DFxtDD2N.cjs} +126 -27
- package/dist/copilotkit-DFxtDD2N.cjs.map +1 -0
- package/dist/{hooks-DMSkcNOl.d.cts → hooks-CEFWIeKR.d.cts} +4 -4
- package/dist/{hooks-DMSkcNOl.d.cts.map → hooks-CEFWIeKR.d.cts.map} +1 -1
- package/dist/{hooks-EwGvqYsW.d.mts → hooks-DFgYRjj3.d.mts} +4 -4
- package/dist/{hooks-EwGvqYsW.d.mts.map → hooks-DFgYRjj3.d.mts.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +125 -26
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/generative-ui/native.d.cts +1 -1
- package/dist/v2/generative-ui/native.d.mts +1 -1
- package/dist/v2/generative-ui.d.cts +166 -166
- package/dist/v2/generative-ui.d.cts.map +1 -1
- package/dist/v2/generative-ui.d.mts +166 -166
- package/dist/v2/generative-ui.d.mts.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.d.cts +1 -1
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +125 -26
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +8 -8
- package/dist/copilotkit-B1OLgEU8.mjs.map +0 -1
- package/dist/copilotkit-Ca0IcTZU.cjs.map +0 -1
|
@@ -1326,7 +1326,7 @@ function useRenderToolCall() {
|
|
|
1326
1326
|
|
|
1327
1327
|
//#endregion
|
|
1328
1328
|
//#region package.json
|
|
1329
|
-
var version = "1.
|
|
1329
|
+
var version = "1.87.1";
|
|
1330
1330
|
|
|
1331
1331
|
//#endregion
|
|
1332
1332
|
//#region src/v2/components/CopilotKitInspector.tsx
|
|
@@ -2554,7 +2554,7 @@ function describeOperationKinds(operations) {
|
|
|
2554
2554
|
function warnAboutUnpaintedSurfaces(grouped) {
|
|
2555
2555
|
for (const [surfaceId, operations] of grouped) {
|
|
2556
2556
|
if (surfaceHasRenderableContent(operations)) continue;
|
|
2557
|
-
const cause = operations.
|
|
2557
|
+
const cause = operations.flatMap(getOperationComponents).length === 0 ? "no updateComponents operation arrived, so the surface was never given anything to draw" : "its components address their values by \"path\" and no updateDataModel carried a non-empty value, so every bound component drew empty";
|
|
2558
2558
|
console.warn(`[CopilotKit] A2UI surface "${surfaceId}" received operations and never painted after ${String(PAINT_FALLBACK_MS)}ms: ${cause}. Operations received: ${describeOperationKinds(operations)}. The payload was accepted, so check what the agent sent rather than the client wiring. This warning is development-only.`);
|
|
2559
2559
|
}
|
|
2560
2560
|
}
|
|
@@ -2567,13 +2567,9 @@ function warnAboutUnpaintedSurfaces(grouped) {
|
|
|
2567
2567
|
*/
|
|
2568
2568
|
function describeComponentIds(operations) {
|
|
2569
2569
|
const ids = [];
|
|
2570
|
-
for (const operation of operations) {
|
|
2571
|
-
const
|
|
2572
|
-
if (!
|
|
2573
|
-
for (const component of components) {
|
|
2574
|
-
const id = component?.id;
|
|
2575
|
-
if (typeof id === "string" && !ids.includes(id)) ids.push(id);
|
|
2576
|
-
}
|
|
2570
|
+
for (const operation of operations) for (const component of getOperationComponents(operation)) {
|
|
2571
|
+
const id = component?.id;
|
|
2572
|
+
if (typeof id === "string" && !ids.includes(id)) ids.push(id);
|
|
2577
2573
|
}
|
|
2578
2574
|
return ids.length === 0 ? "none" : ids.map((id) => `"${id}"`).join(", ");
|
|
2579
2575
|
}
|
|
@@ -2600,9 +2596,9 @@ function describeComponentIds(operations) {
|
|
|
2600
2596
|
*/
|
|
2601
2597
|
function warnAboutUnresolvedRoot(surfaceId, operations, surface) {
|
|
2602
2598
|
if (surface?.componentsModel?.get?.(_copilotkit_a2ui_renderer.ROOT_COMPONENT_ID)) return;
|
|
2603
|
-
const
|
|
2604
|
-
if (
|
|
2605
|
-
const cause =
|
|
2599
|
+
const components = operations.flatMap(getOperationComponents);
|
|
2600
|
+
if (components.length === 0) return;
|
|
2601
|
+
const cause = components.some((c) => c?.id === _copilotkit_a2ui_renderer.ROOT_COMPONENT_ID) ? `a component with id "${_copilotkit_a2ui_renderer.ROOT_COMPONENT_ID}" WAS sent, so the components did not reach the surface's model — check for an A2UI render error above, or a catalog that took none of them` : `the components it received are named ${describeComponentIds(operations)}, and none of them is "${_copilotkit_a2ui_renderer.ROOT_COMPONENT_ID}" — rename the entry-point component to "${_copilotkit_a2ui_renderer.ROOT_COMPONENT_ID}", and make every other component reachable from it through child/children`;
|
|
2606
2602
|
console.warn(`[CopilotKit] A2UI surface "${surfaceId}" has no "${_copilotkit_a2ui_renderer.ROOT_COMPONENT_ID}" component ${String(PAINT_FALLBACK_MS)}ms after its last operations were processed, so it is showing the placeholder for a component that has not arrived yet and will keep showing it: ${cause}. Operations received: ${describeOperationKinds(operations)}. This warning is development-only.`);
|
|
2607
2603
|
}
|
|
2608
2604
|
function createA2UIMessageRenderer(options) {
|
|
@@ -2768,7 +2764,10 @@ function ReactSurfaceHost({ surfaceId, operations, theme, agent, copilotkit, cat
|
|
|
2768
2764
|
surfaceId,
|
|
2769
2765
|
operations,
|
|
2770
2766
|
onReady
|
|
2771
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UISurfaceOrError, {
|
|
2767
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UISurfaceOrError, {
|
|
2768
|
+
surfaceId,
|
|
2769
|
+
onReady
|
|
2770
|
+
})]
|
|
2772
2771
|
})
|
|
2773
2772
|
});
|
|
2774
2773
|
}
|
|
@@ -2776,15 +2775,60 @@ function ReactSurfaceHost({ surfaceId, operations, theme, agent, copilotkit, cat
|
|
|
2776
2775
|
* Renders the A2UI surface, or an error message if processing failed.
|
|
2777
2776
|
* Must be a child of A2UIProvider to access the error state.
|
|
2778
2777
|
*/
|
|
2779
|
-
function A2UISurfaceOrError({ surfaceId }) {
|
|
2778
|
+
function A2UISurfaceOrError({ surfaceId, onReady }) {
|
|
2780
2779
|
const error = (0, _copilotkit_a2ui_renderer.useA2UIError)();
|
|
2781
|
-
|
|
2780
|
+
(0, react.useEffect)(() => {
|
|
2781
|
+
if (error) onReady?.();
|
|
2782
|
+
}, [error, onReady]);
|
|
2783
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [error && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2784
|
+
role: "alert",
|
|
2782
2785
|
className: "cpk:rounded-lg cpk:border cpk:border-red-200 cpk:bg-red-50 cpk:p-3 cpk:text-sm cpk:text-red-700",
|
|
2783
2786
|
children: ["A2UI render error: ", error]
|
|
2784
|
-
})
|
|
2785
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_copilotkit_a2ui_renderer.A2UIRenderer, {
|
|
2787
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_copilotkit_a2ui_renderer.A2UIRenderer, {
|
|
2786
2788
|
surfaceId,
|
|
2787
2789
|
className: "cpk:flex cpk:flex-1"
|
|
2790
|
+
})] });
|
|
2791
|
+
}
|
|
2792
|
+
/**
|
|
2793
|
+
* Full activity snapshots repeat creation. Native 1.0 can carry the current
|
|
2794
|
+
* components and data inline there, so replay changed initialization data and
|
|
2795
|
+
* components as updates for an existing surface. Compare against the previous
|
|
2796
|
+
* wire snapshot, rather than the SDK's mutable data model, to retain local edits.
|
|
2797
|
+
* Retain invalid or version-changing creates for the
|
|
2798
|
+
* provider/SDK to reject, instead of sanitizing them while replaying.
|
|
2799
|
+
*/
|
|
2800
|
+
function replaySnapshotOperations(operations, existing, previousOperations) {
|
|
2801
|
+
if (!existing) return operations;
|
|
2802
|
+
let nativeSurfaceDeleted = false;
|
|
2803
|
+
return operations.flatMap((operation) => {
|
|
2804
|
+
if (operation?.version === "1.0" && operation.deleteSurface?.surfaceId === existing.id) nativeSurfaceDeleted = true;
|
|
2805
|
+
if (nativeSurfaceDeleted) return [operation];
|
|
2806
|
+
if (!operation?.createSurface) return [operation];
|
|
2807
|
+
const version = String(operation.version ?? "v0.9").replace(/^v/, "");
|
|
2808
|
+
if (version !== String(existing.protocolVersion).replace(/^v/, "")) return [operation];
|
|
2809
|
+
if (version === "0.9") return [];
|
|
2810
|
+
if (operation.version !== "1.0") return [operation];
|
|
2811
|
+
const validation = _copilotkit_a2ui_renderer.CreateSurfaceMessageSchemaV1.safeParse(operation);
|
|
2812
|
+
if (!validation.success) return [operation];
|
|
2813
|
+
const create = validation.data.createSurface;
|
|
2814
|
+
if (create.catalogId !== void 0 && create.catalogId !== existing.catalog?.id) return [operation];
|
|
2815
|
+
const updates = [];
|
|
2816
|
+
const previousCreate = previousOperations.find((previous) => previous?.version === "1.0" && previous.createSurface?.surfaceId === create.surfaceId)?.createSurface;
|
|
2817
|
+
if (Object.hasOwn(create, "dataModel") && (!previousCreate || !Object.hasOwn(previousCreate, "dataModel") || JSON.stringify(create.dataModel) !== JSON.stringify(previousCreate.dataModel))) updates.push({
|
|
2818
|
+
version: "1.0",
|
|
2819
|
+
updateDataModel: {
|
|
2820
|
+
surfaceId: create.surfaceId,
|
|
2821
|
+
value: create.dataModel
|
|
2822
|
+
}
|
|
2823
|
+
});
|
|
2824
|
+
if (Object.hasOwn(create, "components")) updates.push({
|
|
2825
|
+
version: "1.0",
|
|
2826
|
+
updateComponents: {
|
|
2827
|
+
surfaceId: create.surfaceId,
|
|
2828
|
+
components: create.components
|
|
2829
|
+
}
|
|
2830
|
+
});
|
|
2831
|
+
return updates;
|
|
2788
2832
|
});
|
|
2789
2833
|
}
|
|
2790
2834
|
/**
|
|
@@ -2797,10 +2841,11 @@ function SurfaceMessageProcessor({ surfaceId, operations, onReady }) {
|
|
|
2797
2841
|
(0, react.useEffect)(() => {
|
|
2798
2842
|
const hash = JSON.stringify(operations);
|
|
2799
2843
|
if (hash === lastHashRef.current) return;
|
|
2844
|
+
const previousOperations = lastHashRef.current ? JSON.parse(lastHashRef.current) : [];
|
|
2800
2845
|
lastHashRef.current = hash;
|
|
2801
|
-
const ops = getSurface(surfaceId)
|
|
2846
|
+
const ops = replaySnapshotOperations(operations, getSurface(surfaceId), previousOperations);
|
|
2802
2847
|
processMessages(ops.map(stripRoutingSurfaceId));
|
|
2803
|
-
if (onReady && surfaceHasRenderableContent(operations)) onReady();
|
|
2848
|
+
if (onReady && getSurface(surfaceId)?.componentsModel.get(_copilotkit_a2ui_renderer.ROOT_COMPONENT_ID) && surfaceHasRenderableContent(operations)) onReady();
|
|
2804
2849
|
if (!IS_DEVELOPMENT) return;
|
|
2805
2850
|
if (!getSurface(surfaceId)) {
|
|
2806
2851
|
const missingSurfaceCheck = setTimeout(() => {
|
|
@@ -2830,15 +2875,26 @@ function SurfaceMessageProcessor({ surfaceId, operations, onReady }) {
|
|
|
2830
2875
|
* arrival rather than a fixed delay. (OSS-162)
|
|
2831
2876
|
*/
|
|
2832
2877
|
function surfaceHasRenderableContent(operations) {
|
|
2833
|
-
const
|
|
2834
|
-
if (!
|
|
2835
|
-
|
|
2878
|
+
const components = operations.flatMap(getOperationComponents);
|
|
2879
|
+
if (!components.length) return false;
|
|
2880
|
+
const serialized = JSON.stringify(components);
|
|
2881
|
+
if (!(serialized.includes("\"path\"") || serialized.includes("\"@path\""))) return true;
|
|
2836
2882
|
return operations.some((o) => {
|
|
2837
|
-
const v = o?.updateDataModel?.value;
|
|
2883
|
+
const v = o?.updateDataModel?.value ?? (o?.version === "1.0" ? o?.createSurface?.dataModel : void 0);
|
|
2884
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
2885
|
+
const path = o?.updateDataModel?.path ?? "/";
|
|
2886
|
+
const key = o?.version === "1.0" ? "@path" : "path";
|
|
2887
|
+
return v !== "" && serialized.includes(JSON.stringify({ [key]: path }));
|
|
2888
|
+
}
|
|
2838
2889
|
if (!v || typeof v !== "object") return false;
|
|
2839
2890
|
return Object.values(v).some((x) => Array.isArray(x) ? x.length > 0 : x !== null && x !== void 0 && x !== "");
|
|
2840
2891
|
});
|
|
2841
2892
|
}
|
|
2893
|
+
/** Component definitions can arrive in an update or a native inline create. */
|
|
2894
|
+
function getOperationComponents(operation) {
|
|
2895
|
+
const components = operation?.updateComponents?.components ?? (operation?.version === "1.0" ? operation?.createSurface?.components : void 0);
|
|
2896
|
+
return Array.isArray(components) ? components : [];
|
|
2897
|
+
}
|
|
2842
2898
|
const V0_9_ACTION_KEYS = [
|
|
2843
2899
|
"createSurface",
|
|
2844
2900
|
"updateComponents",
|
|
@@ -2861,7 +2917,7 @@ const V0_9_ACTION_KEYS = [
|
|
|
2861
2917
|
* message, otherwise the operation unchanged.
|
|
2862
2918
|
*/
|
|
2863
2919
|
function stripRoutingSurfaceId(operation) {
|
|
2864
|
-
if (!operation || typeof operation !== "object" || !("surfaceId" in operation) || !V0_9_ACTION_KEYS.some((key) => key in operation)) return operation;
|
|
2920
|
+
if (!operation || typeof operation !== "object" || !(operation.version === void 0 || operation.version === "v0.9") || !("surfaceId" in operation) || !V0_9_ACTION_KEYS.some((key) => key in operation)) return operation;
|
|
2865
2921
|
const { surfaceId: _routingId, ...message } = operation;
|
|
2866
2922
|
return message;
|
|
2867
2923
|
}
|
|
@@ -2921,6 +2977,47 @@ function A2UIBuiltInToolCallRenderer() {
|
|
|
2921
2977
|
return null;
|
|
2922
2978
|
}
|
|
2923
2979
|
|
|
2980
|
+
//#endregion
|
|
2981
|
+
//#region src/v2/a2ui/generation-guidelines.ts
|
|
2982
|
+
/** Native 1.0 tool guidance. Structural template paths retain their own syntax. */
|
|
2983
|
+
const A2UI_V1_GENERATION_GUIDELINES = `Generate A2UI 1.0 JSON.
|
|
2984
|
+
|
|
2985
|
+
Call render_a2ui with a unique surfaceId, the required components array, and optional
|
|
2986
|
+
root data object. Use only component names, properties and functions declared in
|
|
2987
|
+
the supplied catalog. Match its protocolVersion, catalogId and schemas.
|
|
2988
|
+
|
|
2989
|
+
Every component has a unique id and a component type. Exactly one component has
|
|
2990
|
+
id="root", the surface entry point. All other components must be reachable from
|
|
2991
|
+
root through child/children; never reference the same component as its own child,
|
|
2992
|
+
and never create a cycle.
|
|
2993
|
+
|
|
2994
|
+
Use literal values unless the property's catalog schema permits a dynamic value.
|
|
2995
|
+
Native value binding uses { "@path": "/form/name" }. A plain property schema does
|
|
2996
|
+
not accept a binding object. Pre-fill editable values via the data argument:
|
|
2997
|
+
"data": { "form": { "name": "Alice" } }
|
|
2998
|
+
"value": { "@path": "/form/name" }
|
|
2999
|
+
|
|
3000
|
+
Native function expressions use { "@call": "functionName", "args": { ... } },
|
|
3001
|
+
with only the parameters declared by the catalog; do not add returnType.
|
|
3002
|
+
|
|
3003
|
+
REPEATING CONTENT uses a structural children format, distinct from value binding:
|
|
3004
|
+
children: { componentId: "card-id", path: "/items" }
|
|
3005
|
+
The structural key remains path. Initialize its data array with real items before
|
|
3006
|
+
expecting a visible list. Components inside a template use relative value bindings:
|
|
3007
|
+
"text": { "@path": "name" }
|
|
3008
|
+
An absolute binding such as { "@path": "/name" } reads from the root instead.
|
|
3009
|
+
|
|
3010
|
+
Buttons send nested event actions, with bound context to capture edited values:
|
|
3011
|
+
"action": { "event": { "name": "submit", "context": { "name": { "@path": "/form/name" } } } }
|
|
3012
|
+
Local function actions use { "functionCall": { "@call": "functionName", "args": { ... } } }.
|
|
3013
|
+
Do not rename literal objects' path keys: only @path denotes native value binding.
|
|
3014
|
+
Keep an existing surface's protocol and catalog when updating it; create a new
|
|
3015
|
+
surface to use a different protocol.`;
|
|
3016
|
+
/** Preserve legacy prompt text exactly unless the selected catalog opts into 1.0. */
|
|
3017
|
+
function a2uiGenerationGuidelines(protocolVersion) {
|
|
3018
|
+
return protocolVersion === "1.0" ? A2UI_V1_GENERATION_GUIDELINES : _copilotkit_shared.A2UI_DEFAULT_GENERATION_GUIDELINES;
|
|
3019
|
+
}
|
|
3020
|
+
|
|
2924
3021
|
//#endregion
|
|
2925
3022
|
//#region src/v2/a2ui/A2UICatalogContext.tsx
|
|
2926
3023
|
/**
|
|
@@ -2940,6 +3037,7 @@ function A2UICatalogContext({ catalog, includeSchema }) {
|
|
|
2940
3037
|
const capabilitiesValue = (0, react.useMemo)(() => (0, _copilotkit_a2ui_renderer.buildCatalogContextValue)(catalog, { includeSchema: includeSchema !== false }), [catalog, includeSchema]);
|
|
2941
3038
|
const schemaValue = (0, react.useMemo)(() => includeSchema !== false ? JSON.stringify((0, _copilotkit_a2ui_renderer.extractCatalogComponentSchemas)(catalog)) : null, [catalog, includeSchema]);
|
|
2942
3039
|
const a2uiAgentsKey = copilotkit?.a2uiAgents?.join(",");
|
|
3040
|
+
const generationGuidelines = a2uiGenerationGuidelines(catalog?.protocolVersion);
|
|
2943
3041
|
(0, react.useLayoutEffect)(() => {
|
|
2944
3042
|
if (!copilotkit) return;
|
|
2945
3043
|
const agentIds = copilotkit.a2uiAgents;
|
|
@@ -2958,7 +3056,7 @@ function A2UICatalogContext({ catalog, includeSchema }) {
|
|
|
2958
3056
|
}));
|
|
2959
3057
|
ids.push(copilotkit.addContext({
|
|
2960
3058
|
description: "A2UI generation guidelines — protocol rules, tool arguments, path rules, data model format, and form/two-way-binding instructions.",
|
|
2961
|
-
value:
|
|
3059
|
+
value: generationGuidelines,
|
|
2962
3060
|
...scope
|
|
2963
3061
|
}));
|
|
2964
3062
|
ids.push(copilotkit.addContext({
|
|
@@ -2974,7 +3072,8 @@ function A2UICatalogContext({ catalog, includeSchema }) {
|
|
|
2974
3072
|
copilotkit,
|
|
2975
3073
|
capabilitiesValue,
|
|
2976
3074
|
schemaValue,
|
|
2977
|
-
a2uiAgentsKey
|
|
3075
|
+
a2uiAgentsKey,
|
|
3076
|
+
generationGuidelines
|
|
2978
3077
|
]);
|
|
2979
3078
|
return null;
|
|
2980
3079
|
}
|
|
@@ -14894,4 +14993,4 @@ Object.defineProperty(exports, 'useToast', {
|
|
|
14894
14993
|
return useToast;
|
|
14895
14994
|
}
|
|
14896
14995
|
});
|
|
14897
|
-
//# sourceMappingURL=copilotkit-
|
|
14996
|
+
//# sourceMappingURL=copilotkit-DFxtDD2N.cjs.map
|