@copilotkit/react-core 2.0.0-rc.8 → 2.0.0-rc.9

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 (29) hide show
  1. package/dist/{MarkdownRendererContext-DAuVISwv.d.cts → MarkdownRendererContext-CS35epe1.d.mts} +5 -5
  2. package/dist/{MarkdownRendererContext-DAuVISwv.d.cts.map → MarkdownRendererContext-CS35epe1.d.mts.map} +1 -1
  3. package/dist/{MarkdownRendererContext-XWC2OXD5.d.mts → MarkdownRendererContext-CfTh92vk.d.cts} +5 -5
  4. package/dist/{MarkdownRendererContext-XWC2OXD5.d.mts.map → MarkdownRendererContext-CfTh92vk.d.cts.map} +1 -1
  5. package/dist/{MarkdownSurfaces-DQZM4lSI.cjs → MarkdownSurfaces-Ije2ZQh0.cjs} +16 -17
  6. package/dist/MarkdownSurfaces-Ije2ZQh0.cjs.map +1 -0
  7. package/dist/{MarkdownSurfaces-BXaxgpm_.mjs → MarkdownSurfaces-iFKorV2w.mjs} +5 -7
  8. package/dist/MarkdownSurfaces-iFKorV2w.mjs.map +1 -0
  9. package/dist/generative-ui.cjs +507 -506
  10. package/dist/generative-ui.cjs.map +1 -1
  11. package/dist/generative-ui.d.cts +2137 -4178
  12. package/dist/generative-ui.d.cts.map +1 -1
  13. package/dist/generative-ui.d.mts +2137 -4178
  14. package/dist/generative-ui.d.mts.map +1 -1
  15. package/dist/generative-ui.mjs +3 -3
  16. package/dist/generative-ui.mjs.map +1 -1
  17. package/dist/index.cjs +102 -335
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +13 -51
  20. package/dist/index.d.cts.map +1 -1
  21. package/dist/index.d.mts +13 -51
  22. package/dist/index.d.mts.map +1 -1
  23. package/dist/index.mjs +31 -307
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/index.umd.js +118 -351
  26. package/dist/index.umd.js.map +1 -1
  27. package/package.json +14 -14
  28. package/dist/MarkdownSurfaces-BXaxgpm_.mjs.map +0 -1
  29. package/dist/MarkdownSurfaces-DQZM4lSI.cjs.map +0 -1
package/dist/index.umd.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
 
3
3
  (function(global, factory) {
4
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@copilotkit/core'), require('@ag-ui/client'), require('react'), require('@copilotkit/markdown-renderer/react'), require('@copilotkit/markdown-renderer'), require('react/jsx-runtime'), require('@copilotkit/shared'), require('@radix-ui/react-tooltip'), require('@radix-ui/react-dropdown-menu'), require('@ag-ui/core'), require('@copilotkit/mcp-apps-renderer/activity'), require('zod'), require('@copilotkit/a2ui-renderer'), require('zod-to-json-schema'), require('@a2ui/web_core/v0_9'), require('@copilotkit/core/styles'), require('@radix-ui/react-popover'), require('react-dom'), require('@tanstack/react-virtual'), require('use-stick-to-bottom'), require('@copilotkit/web-components/threads-drawer')) :
5
- typeof define === 'function' && define.amd ? define(['exports', '@copilotkit/core', '@ag-ui/client', 'react', '@copilotkit/markdown-renderer/react', '@copilotkit/markdown-renderer', 'react/jsx-runtime', '@copilotkit/shared', '@radix-ui/react-tooltip', '@radix-ui/react-dropdown-menu', '@ag-ui/core', '@copilotkit/mcp-apps-renderer/activity', 'zod', '@copilotkit/a2ui-renderer', 'zod-to-json-schema', '@a2ui/web_core/v0_9', '@copilotkit/core/styles', '@radix-ui/react-popover', 'react-dom', '@tanstack/react-virtual', 'use-stick-to-bottom', '@copilotkit/web-components/threads-drawer'], factory) :
6
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitReactCore = {}), global.CopilotKitCore,global.AgUIClient,global.React,global.CopilotKitMarkdownRendererReact,global.CopilotKitMarkdownRenderer,global.ReactJsxRuntime,global.CopilotKitShared,global.RadixReactTooltip,global.RadixReactDropdownMenu,global.AgUICore,global.CopilotKitMcpAppsRendererActivity,global.Zod,global.CopilotKitA2UIRenderer,global.zod_to_json_schema,global._a2ui_web_core_v0_9,global._copilotkit_core_styles,global._radix_ui_react_popover,global.ReactDOM,global._tanstack_react_virtual,global.useStickToBottom,global._copilotkit_web_components_threads_drawer));
7
- })(this, function(exports, _copilotkit_core, _ag_ui_client, react, _copilotkit_markdown_renderer_react, _copilotkit_markdown_renderer, react_jsx_runtime, _copilotkit_shared, _radix_ui_react_tooltip, _radix_ui_react_dropdown_menu, _ag_ui_core, _copilotkit_mcp_apps_renderer_activity, zod, _copilotkit_a2ui_renderer, zod_to_json_schema, _a2ui_web_core_v0_9, _copilotkit_core_styles, _radix_ui_react_popover, react_dom, _tanstack_react_virtual, use_stick_to_bottom, _copilotkit_web_components_threads_drawer) {
4
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@copilotkit/core'), require('@ag-ui/client'), require('react'), require('@copilotkit/markdown-renderer/react'), require('@copilotkit/markdown-renderer'), require('react/jsx-runtime'), require('@copilotkit/shared'), require('@radix-ui/react-tooltip'), require('@radix-ui/react-dropdown-menu'), require('@ag-ui/core'), require('@copilotkit/mcp-apps-renderer/activity'), require('zod'), require('@copilotkit/a2ui-renderer'), require('@a2ui/web_core/v0_9'), require('@copilotkit/core/styles'), require('@radix-ui/react-popover'), require('react-dom'), require('@tanstack/react-virtual'), require('use-stick-to-bottom'), require('@copilotkit/web-components/threads-drawer')) :
5
+ typeof define === 'function' && define.amd ? define(['exports', '@copilotkit/core', '@ag-ui/client', 'react', '@copilotkit/markdown-renderer/react', '@copilotkit/markdown-renderer', 'react/jsx-runtime', '@copilotkit/shared', '@radix-ui/react-tooltip', '@radix-ui/react-dropdown-menu', '@ag-ui/core', '@copilotkit/mcp-apps-renderer/activity', 'zod', '@copilotkit/a2ui-renderer', '@a2ui/web_core/v0_9', '@copilotkit/core/styles', '@radix-ui/react-popover', 'react-dom', '@tanstack/react-virtual', 'use-stick-to-bottom', '@copilotkit/web-components/threads-drawer'], factory) :
6
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitReactCore = {}), global.CopilotKitCore,global.AgUIClient,global.React,global.CopilotKitMarkdownRendererReact,global.CopilotKitMarkdownRenderer,global.ReactJsxRuntime,global.CopilotKitShared,global.RadixReactTooltip,global.RadixReactDropdownMenu,global.AgUICore,global.CopilotKitMcpAppsRendererActivity,global.Zod,global.CopilotKitA2UIRenderer,global._a2ui_web_core_v0_9,global._copilotkit_core_styles,global._radix_ui_react_popover,global.ReactDOM,global._tanstack_react_virtual,global.useStickToBottom,global._copilotkit_web_components_threads_drawer));
7
+ })(this, function(exports, _copilotkit_core, _ag_ui_client, react, _copilotkit_markdown_renderer_react, _copilotkit_markdown_renderer, react_jsx_runtime, _copilotkit_shared, _radix_ui_react_tooltip, _radix_ui_react_dropdown_menu, _ag_ui_core, _copilotkit_mcp_apps_renderer_activity, zod, _copilotkit_a2ui_renderer, _a2ui_web_core_v0_9, _copilotkit_core_styles, _radix_ui_react_popover, react_dom, _tanstack_react_virtual, use_stick_to_bottom, _copilotkit_web_components_threads_drawer) {
8
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
9
9
  //#region \0rolldown/runtime.js
10
10
  var __create = Object.create;
@@ -36,6 +36,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
36
36
  react = __toESM(react);
37
37
  _radix_ui_react_tooltip = __toESM(_radix_ui_react_tooltip);
38
38
  _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
39
+ zod = __toESM(zod);
39
40
  _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
40
41
 
41
42
  //#region src/components/chat/StreamingMarkdownDefaultRenderer.tsx
@@ -1881,7 +1882,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
1881
1882
 
1882
1883
  //#endregion
1883
1884
  //#region package.json
1884
- var version$1 = "2.0.0-rc.8";
1885
+ var version$1 = "2.0.0-rc.9";
1885
1886
 
1886
1887
  //#endregion
1887
1888
  //#region src/components/CopilotKitInspector.tsx
@@ -2271,324 +2272,63 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
2271
2272
  return (0, react.useContext)(SandboxFunctionsContext);
2272
2273
  }
2273
2274
 
2274
- //#endregion
2275
- //#region src/lib/processPartialHtml.ts
2276
- /**
2277
- * Extracts all complete `<style>` blocks from the raw HTML.
2278
- * Returns the concatenated style tags, suitable for injection into `<head>`.
2279
- */
2280
- function extractCompleteStyles(html) {
2281
- const matches = html.match(/<style\b[^>]*>[\s\S]*?<\/style>/gi);
2282
- return matches ? matches.join("") : "";
2283
- }
2284
- /**
2285
- * Processes raw accumulated HTML for safe preview via innerHTML injection.
2286
- * Pure function, no DOM dependencies.
2287
- *
2288
- * Pipeline (order matters):
2289
- * 1. Strip incomplete tag at end
2290
- * 2. Strip complete <style>, <script>, and <head> blocks
2291
- * 3. Strip incomplete <style>/<script>/<head> blocks
2292
- * 4. Strip incomplete HTML entities
2293
- * 5. Extract body content (or use full string if no <body>)
2294
- */
2295
- function processPartialHtml(html) {
2296
- let result = html;
2297
- result = result.replace(/<[^>]*$/, "");
2298
- result = result.replace(/<(style|script|head)\b[^>]*>[\s\S]*?<\/\1>/gi, "");
2299
- result = result.replace(/<(style|script|head)\b[^>]*>[\s\S]*$/gi, "");
2300
- result = result.replace(/&[a-zA-Z0-9#]*$/, "");
2301
- const bodyMatch = result.match(/<body[^>]*>([\s\S]*)/i);
2302
- if (bodyMatch) {
2303
- result = bodyMatch[1];
2304
- result = result.replace(/<\/body>[\s\S]*/i, "");
2305
- }
2306
- return result;
2307
- }
2308
-
2309
2275
  //#endregion
2310
2276
  //#region src/components/OpenGenerativeUIRenderer.tsx
2311
- const OpenGenerativeUIActivityType = "open-generative-ui";
2312
- const OpenGenerativeUIContentSchema = zod.z.object({
2313
- initialHeight: zod.z.number().optional(),
2314
- generating: zod.z.boolean().optional(),
2315
- css: zod.z.string().optional(),
2316
- cssComplete: zod.z.boolean().optional(),
2317
- html: zod.z.array(zod.z.string()).optional(),
2318
- htmlComplete: zod.z.boolean().optional(),
2319
- jsFunctions: zod.z.string().optional(),
2320
- jsFunctionsComplete: zod.z.boolean().optional(),
2321
- jsExpressions: zod.z.array(zod.z.string()).optional(),
2322
- jsExpressionsComplete: zod.z.boolean().optional()
2277
+ const OpenGenerativeUIActivityType = _copilotkit_core.OPEN_GENERATIVE_UI_ACTIVITY_TYPE;
2278
+ const OpenGenerativeUIContentSchema = zod.object({
2279
+ initialHeight: zod.number().optional(),
2280
+ generating: zod.boolean().optional(),
2281
+ css: zod.string().optional(),
2282
+ cssComplete: zod.boolean().optional(),
2283
+ html: zod.array(zod.string()).optional(),
2284
+ htmlComplete: zod.boolean().optional(),
2285
+ jsFunctions: zod.string().optional(),
2286
+ jsFunctionsComplete: zod.boolean().optional(),
2287
+ jsExpressions: zod.array(zod.string()).optional(),
2288
+ jsExpressionsComplete: zod.boolean().optional()
2323
2289
  });
2324
2290
  /**
2325
2291
  * Schema for the generateSandboxedUi tool call arguments.
2326
2292
  * Used by the frontend tool renderer to display placeholder messages.
2327
2293
  */
2328
- const GenerateSandboxedUiArgsSchema = zod.z.object({
2329
- initialHeight: zod.z.number().optional(),
2330
- placeholderMessages: zod.z.array(zod.z.string()).optional(),
2331
- css: zod.z.string().optional(),
2332
- html: zod.z.string().optional(),
2333
- jsFunctions: zod.z.string().optional(),
2334
- jsExpressions: zod.z.array(zod.z.string()).optional()
2294
+ const GenerateSandboxedUiArgsSchema = zod.object({
2295
+ initialHeight: zod.number().optional(),
2296
+ placeholderMessages: zod.array(zod.string()).optional(),
2297
+ css: zod.string().optional(),
2298
+ html: zod.string().optional(),
2299
+ jsFunctions: zod.string().optional(),
2300
+ jsExpressions: zod.array(zod.string()).optional()
2335
2301
  });
2336
- const THROTTLE_MS = 1e3;
2337
2302
  /**
2338
- * Returns true when the inner component should re-render immediately
2339
- * (no throttle delay).
2340
- */
2341
- function shouldFlushImmediately(prev, next) {
2342
- if (next.cssComplete && (!prev || !prev.cssComplete)) return true;
2343
- if (next.htmlComplete) return true;
2344
- if (next.generating === false) return true;
2345
- if (next.jsFunctions && (!prev || !prev.jsFunctions)) return true;
2346
- if ((next.jsExpressions?.length ?? 0) > (prev?.jsExpressions?.length ?? 0)) return true;
2347
- if (next.html?.length && (!prev || !prev.html?.length)) return true;
2348
- return false;
2349
- }
2350
- /**
2351
- * Outer wrapper — absorbs every parent re-render but only forwards
2352
- * throttled content snapshots to the memoized inner component.
2303
+ * Renders an Open Generative UI activity. The core controller throttles the
2304
+ * content and runs the websandbox iframes inside the container div.
2353
2305
  */
2354
2306
  const OpenGenerativeUIActivityRenderer = function OpenGenerativeUIActivityRenderer({ content }) {
2355
- const latestContentRef = (0, react.useRef)(content);
2356
- latestContentRef.current = content;
2357
- const [throttledContent, setThrottledContent] = (0, react.useState)(content);
2358
- const throttledContentRef = (0, react.useRef)(throttledContent);
2359
- const timerRef = (0, react.useRef)(null);
2360
- if (throttledContentRef.current !== content) {
2361
- if (shouldFlushImmediately(throttledContentRef.current, content)) {
2362
- if (timerRef.current !== null) {
2363
- clearTimeout(timerRef.current);
2364
- timerRef.current = null;
2365
- }
2366
- throttledContentRef.current = content;
2367
- setThrottledContent(content);
2368
- }
2369
- }
2370
- const flush = (0, react.useCallback)(() => {
2371
- timerRef.current = null;
2372
- const latest = latestContentRef.current;
2373
- throttledContentRef.current = latest;
2374
- setThrottledContent(latest);
2375
- }, []);
2376
- (0, react.useEffect)(() => {
2377
- if (throttledContentRef.current === content) return;
2378
- if (timerRef.current === null) timerRef.current = setTimeout(flush, THROTTLE_MS);
2379
- }, [content, flush]);
2380
- (0, react.useEffect)(() => {
2381
- return () => {
2382
- if (timerRef.current !== null) clearTimeout(timerRef.current);
2383
- };
2384
- }, []);
2385
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OpenGenerativeUIActivityRendererInner, { content: throttledContent });
2386
- };
2387
- function ensureHead(html) {
2388
- if (/<head[\s>]/i.test(html)) return html;
2389
- return `<head></head>${html}`;
2390
- }
2391
- function injectCssIntoHtml(html, css) {
2392
- const headCloseIdx = html.indexOf("</head>");
2393
- if (headCloseIdx !== -1) return html.slice(0, headCloseIdx) + `<style>${css}</style>` + html.slice(headCloseIdx);
2394
- return `<head><style>${css}</style></head>${html}`;
2395
- }
2396
- const OpenGenerativeUIActivityRendererInner = react.default.memo(function OpenGenerativeUIActivityRendererInner({ content }) {
2397
- const initialHeight = content.initialHeight ?? 200;
2398
- const [autoHeight, setAutoHeight] = (0, react.useState)(null);
2307
+ const [controller] = (0, react.useState)(() => {
2308
+ const created = new _copilotkit_core.ɵOpenGenerativeUIController();
2309
+ created.setContent(content);
2310
+ return created;
2311
+ });
2399
2312
  const sandboxFunctions = useSandboxFunctions();
2400
- const localApi = (0, react.useMemo)(() => {
2401
- const api = {};
2402
- for (const fn of sandboxFunctions) api[fn.name] = fn.handler;
2403
- return api;
2404
- }, [sandboxFunctions]);
2405
- const fullHtml = content.htmlComplete && content.html?.length ? content.html.join("") : void 0;
2406
- const css = content.cssComplete ? content.css : void 0;
2407
- const cssReady = !!content.cssComplete;
2408
- const partialHtml = !content.htmlComplete && content.html?.length ? content.html.join("") : void 0;
2409
- const previewBody = partialHtml ? processPartialHtml(partialHtml) : void 0;
2410
- const previewStyles = partialHtml ? extractCompleteStyles(partialHtml) : "";
2411
- const hasPreview = cssReady && !!previewBody?.trim();
2412
- const hasVisibleSandbox = !!fullHtml || hasPreview;
2413
2313
  const containerRef = (0, react.useRef)(null);
2414
- const sandboxRef = (0, react.useRef)(null);
2415
- const previewSandboxRef = (0, react.useRef)(null);
2416
- const previewReadyRef = (0, react.useRef)(false);
2417
- const sandboxReadyRef = (0, react.useRef)(false);
2418
- const executedIndexRef = (0, react.useRef)(0);
2419
- const pendingQueueRef = (0, react.useRef)([]);
2420
- const jsFunctionsInjectedRef = (0, react.useRef)(false);
2314
+ const state = (0, react.useSyncExternalStore)(controller.subscribe, controller.getState, controller.getState);
2421
2315
  (0, react.useEffect)(() => {
2422
- const container = containerRef.current;
2423
- if (!container || fullHtml || !hasPreview || previewSandboxRef.current) return;
2424
- let cancelled = false;
2425
- import("@jetbrains/websandbox").then((mod) => {
2426
- if (cancelled) return;
2427
- const sandbox = (mod.default?.default ?? mod.default).create({}, {
2428
- frameContainer: container,
2429
- frameContent: "<head></head><body></body>",
2430
- allowAdditionalAttributes: ""
2431
- });
2432
- previewSandboxRef.current = sandbox;
2433
- sandbox.iframe.style.width = "100%";
2434
- sandbox.iframe.style.height = "100%";
2435
- sandbox.iframe.style.border = "none";
2436
- sandbox.iframe.style.backgroundColor = "transparent";
2437
- sandbox.promise.then(() => {
2438
- if (cancelled) return;
2439
- previewReadyRef.current = true;
2440
- sandbox.run(`
2441
- var s = document.createElement('style');
2442
- s.textContent = 'html, body { overflow: hidden !important; }';
2443
- document.head.appendChild(s);
2444
- `);
2445
- const headParts = [];
2446
- if (css) headParts.push(`<style>${css}</style>`);
2447
- if (previewStyles) headParts.push(previewStyles);
2448
- if (headParts.length) sandbox.run(`document.head.innerHTML = ${JSON.stringify(headParts.join(""))}`);
2449
- if (previewBody) sandbox.run(`document.body.innerHTML = ${JSON.stringify(previewBody)}`);
2450
- });
2451
- }).catch((err) => {
2452
- console.error("[OpenGenerativeUI] Failed to load sandbox module:", err);
2453
- });
2454
- return () => {
2455
- cancelled = true;
2456
- };
2457
- }, [hasPreview, fullHtml]);
2316
+ controller.setSandboxFunctions(sandboxFunctions);
2317
+ }, [controller, sandboxFunctions]);
2458
2318
  (0, react.useEffect)(() => {
2459
- if (!previewSandboxRef.current || !previewReadyRef.current) return;
2460
- const headParts = [];
2461
- if (css) headParts.push(`<style>${css}</style>`);
2462
- if (previewStyles) headParts.push(previewStyles);
2463
- if (headParts.length) previewSandboxRef.current.run(`document.head.innerHTML = ${JSON.stringify(headParts.join(""))}`);
2464
- if (!previewBody) return;
2465
- previewSandboxRef.current.run(`document.body.innerHTML = ${JSON.stringify(previewBody)}`);
2466
- }, [
2467
- previewBody,
2468
- previewStyles,
2469
- css
2470
- ]);
2319
+ controller.setContent(content);
2320
+ }, [controller, content]);
2471
2321
  (0, react.useEffect)(() => {
2472
- const container = containerRef.current;
2473
- if (!container || !fullHtml) return;
2474
- if (previewSandboxRef.current) {
2475
- previewSandboxRef.current.destroy();
2476
- previewSandboxRef.current = null;
2477
- previewReadyRef.current = false;
2478
- }
2479
- let cancelled = false;
2480
- executedIndexRef.current = 0;
2481
- jsFunctionsInjectedRef.current = false;
2482
- sandboxReadyRef.current = false;
2483
- pendingQueueRef.current = [];
2484
- const htmlContent = css ? injectCssIntoHtml(fullHtml, css) : fullHtml;
2485
- import("@jetbrains/websandbox").then((mod) => {
2486
- if (cancelled) return;
2487
- const sandbox = (mod.default?.default ?? mod.default).create(localApi, {
2488
- frameContainer: container,
2489
- frameContent: ensureHead(htmlContent),
2490
- allowAdditionalAttributes: ""
2491
- });
2492
- sandboxRef.current = sandbox;
2493
- sandbox.iframe.style.width = "100%";
2494
- sandbox.iframe.style.height = "100%";
2495
- sandbox.iframe.style.border = "none";
2496
- sandbox.iframe.style.backgroundColor = "transparent";
2497
- sandbox.promise.then(() => {
2498
- if (cancelled) return;
2499
- sandboxReadyRef.current = true;
2500
- sandbox.run(`
2501
- var s = document.createElement('style');
2502
- s.textContent = 'html, body { overflow: hidden !important; }';
2503
- document.head.appendChild(s);
2504
- `);
2505
- const queue = pendingQueueRef.current;
2506
- pendingQueueRef.current = [];
2507
- for (const code of queue) sandbox.run(code);
2508
- });
2509
- }).catch((err) => {
2510
- console.error("[OpenGenerativeUI] Failed to load sandbox module:", err);
2511
- });
2512
- return () => {
2513
- cancelled = true;
2514
- if (previewSandboxRef.current) {
2515
- previewSandboxRef.current.destroy();
2516
- previewSandboxRef.current = null;
2517
- previewReadyRef.current = false;
2518
- }
2519
- if (sandboxRef.current) {
2520
- sandboxRef.current.destroy();
2521
- sandboxRef.current = null;
2522
- }
2523
- sandboxReadyRef.current = false;
2524
- setAutoHeight(null);
2525
- };
2526
- }, [
2527
- fullHtml,
2528
- css,
2529
- localApi
2530
- ]);
2531
- (0, react.useEffect)(() => {
2532
- if (!content.jsFunctions || jsFunctionsInjectedRef.current) return;
2533
- jsFunctionsInjectedRef.current = true;
2534
- const sandbox = sandboxRef.current;
2535
- if (sandboxReadyRef.current && sandbox) sandbox.run(content.jsFunctions);
2536
- else pendingQueueRef.current.push(content.jsFunctions);
2537
- }, [content.jsFunctions]);
2538
- (0, react.useEffect)(() => {
2539
- const expressions = content.jsExpressions;
2540
- if (!expressions || expressions.length === 0) return;
2541
- const startIndex = executedIndexRef.current;
2542
- if (startIndex >= expressions.length) return;
2543
- const newExprs = expressions.slice(startIndex);
2544
- executedIndexRef.current = expressions.length;
2545
- const sandbox = sandboxRef.current;
2546
- if (sandboxReadyRef.current && sandbox) (async () => {
2547
- for (const expr of newExprs) await sandbox.run(expr);
2548
- })();
2549
- else pendingQueueRef.current.push(...newExprs);
2550
- }, [content.jsExpressions?.length]);
2551
- const generationDone = content.generating === false;
2552
- (0, react.useEffect)(() => {
2553
- const sandbox = sandboxRef.current;
2554
- if (!generationDone || !sandbox) return;
2555
- let handled = false;
2556
- const onMessage = (e) => {
2557
- if (handled) return;
2558
- if (e.source === sandbox.iframe.contentWindow && e.data?.type === "__ck_resize") {
2559
- handled = true;
2560
- setAutoHeight(e.data.height);
2561
- window.removeEventListener("message", onMessage);
2562
- }
2563
- };
2564
- window.addEventListener("message", onMessage);
2565
- const measureOnce = `
2566
- (function() {
2567
- var s = document.createElement('style');
2568
- s.textContent = 'body { height: auto !important; min-height: 0 !important; }';
2569
- document.head.appendChild(s);
2570
- var h = document.body.scrollHeight;
2571
- var cs = getComputedStyle(document.body);
2572
- h += parseFloat(cs.marginTop) || 0;
2573
- h += parseFloat(cs.marginBottom) || 0;
2574
- s.remove();
2575
- parent.postMessage({ type: "__ck_resize", height: Math.ceil(h) }, "*");
2576
- })();
2577
- `;
2578
- if (sandboxReadyRef.current) sandbox.run(measureOnce);
2579
- else pendingQueueRef.current.push(measureOnce);
2580
- return () => {
2581
- window.removeEventListener("message", onMessage);
2582
- };
2583
- }, [generationDone]);
2584
- const height = autoHeight ?? initialHeight;
2585
- const isGenerating = content.generating !== false;
2322
+ controller.setHost(containerRef.current);
2323
+ return () => controller.destroy();
2324
+ }, [controller]);
2325
+ const hasVisibleSandbox = state.phase !== "placeholder";
2586
2326
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2587
2327
  ref: containerRef,
2588
2328
  style: {
2589
2329
  position: "relative",
2590
2330
  width: "100%",
2591
- height: `${height}px`,
2331
+ height: `${state.height}px`,
2592
2332
  borderRadius: "8px",
2593
2333
  backgroundColor: hasVisibleSandbox ? "transparent" : "#f5f5f5",
2594
2334
  border: hasVisibleSandbox ? "none" : "1px solid #e0e0e0",
@@ -2597,7 +2337,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
2597
2337
  justifyContent: hasVisibleSandbox ? void 0 : "center",
2598
2338
  overflow: "hidden"
2599
2339
  },
2600
- children: isGenerating && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2340
+ children: state.generating && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2601
2341
  style: {
2602
2342
  position: "absolute",
2603
2343
  inset: 0,
@@ -2629,7 +2369,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
2629
2369
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: `@keyframes ck-spin { to { transform: rotate(360deg) } }` })]
2630
2370
  })
2631
2371
  });
2632
- }, (prev, next) => prev.content === next.content);
2372
+ };
2633
2373
  /**
2634
2374
  * Frontend tool renderer for generateSandboxedUi.
2635
2375
  * Displays placeholder messages while the UI is being generated.
@@ -2666,22 +2406,22 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
2666
2406
  //#region src/a2ui/A2UIRecoveryStates.tsx
2667
2407
  /**
2668
2408
  * The pre-paint lifecycle fields the middleware stamps onto the `a2ui-surface`
2669
- * activity content (alongside `a2ui_operations` on paint). `.passthrough()` keeps
2409
+ * activity content (alongside `a2ui_operations` on paint). `.loose()` keeps
2670
2410
  * `a2ui_operations` and any future fields intact.
2671
2411
  */
2672
2412
  const A2UILifecycleFields = {
2673
- status: zod.z.enum([
2413
+ status: zod.enum([
2674
2414
  "building",
2675
2415
  "retrying",
2676
2416
  "failed"
2677
2417
  ]).optional(),
2678
- attempt: zod.z.number().optional(),
2679
- maxAttempts: zod.z.number().optional(),
2680
- progressTokens: zod.z.number().optional(),
2681
- error: zod.z.string().optional(),
2682
- errors: zod.z.array(zod.z.any()).optional(),
2683
- attempts: zod.z.array(zod.z.any()).optional(),
2684
- debugExposure: zod.z.enum([
2418
+ attempt: zod.number().optional(),
2419
+ maxAttempts: zod.number().optional(),
2420
+ progressTokens: zod.number().optional(),
2421
+ error: zod.string().optional(),
2422
+ errors: zod.array(zod.any()).optional(),
2423
+ attempts: zod.array(zod.any()).optional(),
2424
+ debugExposure: zod.enum([
2685
2425
  "hidden",
2686
2426
  "collapsed",
2687
2427
  "verbose"
@@ -3072,12 +2812,12 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
3072
2812
  * stable messageId (OSS-162): pre-paint `status` ("building" | "retrying" |
3073
2813
  * "failed") with recovery detail, then `a2ui_operations` on paint. The states
3074
2814
  * swap in place, so the painted surface replaces the skeleton with no extra
3075
- * coordination. `.passthrough()` preserves operations + any future fields.
2815
+ * coordination. `.loose()` preserves operations + any future fields.
3076
2816
  */
3077
- const A2UISurfaceContentSchema = zod.z.object({
3078
- a2ui_operations: zod.z.array(zod.z.any()).optional(),
2817
+ const A2UISurfaceContentSchema = zod.object({
2818
+ a2ui_operations: zod.array(zod.any()).optional(),
3079
2819
  ...A2UILifecycleFields
3080
- }).passthrough();
2820
+ }).loose();
3081
2821
  const IS_DEVELOPMENT = process.env.NODE_ENV !== "production";
3082
2822
  /**
3083
2823
  * How long to wait for a surface to report its first paint before giving up on
@@ -3461,7 +3201,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
3461
3201
  (0, react.useEffect)(() => {
3462
3202
  const renderer = defineToolCallRenderer({
3463
3203
  name: RENDER_A2UI_TOOL_NAME,
3464
- args: zod.z.any(),
3204
+ args: zod.any(),
3465
3205
  render: () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {})
3466
3206
  });
3467
3207
  const existing = copilotkit._renderToolCalls ?? [];
@@ -3632,12 +3372,11 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
3632
3372
  //#endregion
3633
3373
  //#region src/generative-ui/json-schema.ts
3634
3374
  /**
3635
- * JSON Schema for a Standard Schema (zod v3 via zod-to-json-schema),
3636
- * inlined, no `$schema`. A prop marked by `child()` or `childList()`
3375
+ * JSON Schema for a Standard Schema, without `$schema`. A prop marked by `child()` or `childList()`
3637
3376
  * becomes an A2UI `$ref` to `ComponentId` or `ChildList`.
3638
3377
  */
3639
3378
  function toJsonSchema(schema) {
3640
- const { $schema: _omit, ...rest } = (0, _copilotkit_shared.schemaToJsonSchema)(schema, { zodToJsonSchema: (s) => (0, zod_to_json_schema.zodToJsonSchema)(s, { $refStrategy: "none" }) });
3379
+ const { $schema: _omit, ...rest } = (0, _copilotkit_shared.schemaToJsonSchema)(schema);
3641
3380
  return (0, _copilotkit_shared.applyChildRefMarks)(rest);
3642
3381
  }
3643
3382
 
@@ -5910,7 +5649,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
5910
5649
  this.getState = () => this.state;
5911
5650
  this.webCoreCatalog = new _a2ui_web_core_v0_9.Catalog(ui.id, [...ui.components.keys()].map((name) => ({
5912
5651
  name,
5913
- schema: zod.z.any()
5652
+ schema: zod.any()
5914
5653
  })), []);
5915
5654
  }
5916
5655
  notify() {
@@ -7899,21 +7638,21 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
7899
7638
  })]
7900
7639
  });
7901
7640
  }
7902
- const ContentSchema = zod.z.object({
7903
- surfaceId: zod.z.string(),
7904
- target: zod.z.string(),
7905
- catalogId: zod.z.string(),
7906
- operations: zod.z.array(zod.z.any()),
7907
- status: zod.z.enum([
7641
+ const ContentSchema = zod.object({
7642
+ surfaceId: zod.string(),
7643
+ target: zod.string(),
7644
+ catalogId: zod.string(),
7645
+ operations: zod.array(zod.any()),
7646
+ status: zod.enum([
7908
7647
  "streaming",
7909
7648
  "ready",
7910
7649
  "error"
7911
7650
  ]),
7912
- rejected: zod.z.array(zod.z.object({
7913
- index: zod.z.number(),
7914
- reason: zod.z.string()
7651
+ rejected: zod.array(zod.object({
7652
+ index: zod.number(),
7653
+ reason: zod.string()
7915
7654
  })).default([])
7916
- }).passthrough();
7655
+ }).loose();
7917
7656
  function GenerativeUIChatActivity({ content, agent }) {
7918
7657
  const runtime = useGenerativeUIRuntime();
7919
7658
  const threadId = useCopilotChatConfiguration()?.threadId ?? agent?.threadId;
@@ -7955,7 +7694,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
7955
7694
  function createGenerativeUIFunctionCallActivityRenderer() {
7956
7695
  return {
7957
7696
  activityType: _copilotkit_shared.GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE,
7958
- content: zod.z.unknown(),
7697
+ content: zod.unknown(),
7959
7698
  render: () => null
7960
7699
  };
7961
7700
  }
@@ -7965,7 +7704,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
7965
7704
  (0, react.useEffect)(() => {
7966
7705
  const renderer = defineToolCallRenderer({
7967
7706
  name: _copilotkit_shared.GENERATIVE_UI_RENDER_TOOL,
7968
- args: zod.z.any(),
7707
+ args: zod.any(),
7969
7708
  render: () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {})
7970
7709
  });
7971
7710
  const existing = copilotkit._renderToolCalls ?? [];
@@ -8013,10 +7752,6 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
8013
7752
 
8014
7753
  //#endregion
8015
7754
  //#region src/providers/CopilotKitProvider.tsx
8016
- const zodToJsonSchemaAdapter = (schema, options) => {
8017
- const refStrategy = options?.$refStrategy;
8018
- return (0, zod_to_json_schema.zodToJsonSchema)(schema, refStrategy === "root" || refStrategy === "relative" || refStrategy === "none" || refStrategy === "seen" ? { $refStrategy: refStrategy } : {});
8019
- };
8020
7755
  const HEADER_NAME = "X-CopilotCloud-Public-Api-Key";
8021
7756
  const COPILOT_CLOUD_CHAT_URL = "https://api.cloud.copilotkit.ai/copilotkit/v1";
8022
7757
  const EMPTY_HEADERS = Object.freeze({});
@@ -8025,16 +7760,6 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
8025
7760
  /** Registration name of a catch-all tool: handles any otherwise-unhandled call. */
8026
7761
  const WILDCARD_TOOL_NAME$1 = "*";
8027
7762
  const HUMAN_IN_THE_LOOP_ABORTED_MESSAGE = "Human-in-the-loop interaction aborted";
8028
- const DEFAULT_DESIGN_SKILL = `When generating UI with generateSandboxedUi, follow these design principles inspired by shadcn/ui:
8029
-
8030
- - Use a minimal, flat aesthetic. Avoid drop shadows and gradients — rely on subtle borders (1px solid, light gray like #e5e7eb) to define surfaces.
8031
- - Neutral base palette: white backgrounds, zinc/slate gray text (#09090b for headings, #71717a for secondary text). One accent color for interactive elements.
8032
- - Use system font stacks (system-ui, -apple-system, sans-serif) at readable sizes (14px body, 600 weight for headings). Tight line-heights.
8033
- - Small, consistent border-radius (6–8px). Cards and containers use border, not shadow, for separation.
8034
- - Buttons: solid fill for primary (dark bg, white text), outline for secondary (border + transparent bg). Subtle hover state (slight opacity or background shift).
8035
- - Use CSS Grid or Flexbox for layout. Ensure the UI looks good at any width.
8036
- - Minimal transitions (150ms) for hover/focus states only. No decorative animations.
8037
- - Keep the UI focused and dense — avoid excessive padding. Use compact spacing (8–12px gaps, 10–14px padding in controls).`;
8038
7763
  /** The MCP Apps renderer with `mcpApps.allowSameOriginFallback` applied. */
8039
7764
  const SameOriginMCPAppsActivityRenderer = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MCPAppsActivityRenderer, {
8040
7765
  ...props,
@@ -8245,7 +7970,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
8245
7970
  const builtInFrontendTools = (0, react.useMemo)(() => {
8246
7971
  if (!openGenUIActive) return [];
8247
7972
  return [{
8248
- name: "generateSandboxedUi",
7973
+ name: _copilotkit_core.GENERATE_SANDBOXED_UI_TOOL_NAME,
8249
7974
  description: _copilotkit_shared.GENERATE_SANDBOXED_UI_DESCRIPTION,
8250
7975
  parameters: GenerateSandboxedUiArgsSchema,
8251
7976
  handler: async () => "UI generated",
@@ -8470,7 +8195,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
8470
8195
  (0, react.useEffect)(() => {
8471
8196
  copilotkit.setDefaultThrottleMs(defaultThrottleMs);
8472
8197
  }, [copilotkit, defaultThrottleMs]);
8473
- const designSkill = openGenerativeUI?.designSkill ?? DEFAULT_DESIGN_SKILL;
8198
+ const designSkill = openGenerativeUI?.designSkill ?? _copilotkit_core.DEFAULT_OPEN_GENERATIVE_UI_DESIGN_SKILL;
8474
8199
  (0, react.useLayoutEffect)(() => {
8475
8200
  if (!copilotkit || !openGenUIActive) return;
8476
8201
  const id = copilotkit.addContext({
@@ -8490,7 +8215,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
8490
8215
  return JSON.stringify(sandboxFunctionsList.map((fn) => ({
8491
8216
  name: fn.name,
8492
8217
  description: fn.description,
8493
- parameters: (0, _copilotkit_shared.schemaToJsonSchema)(fn.parameters, { zodToJsonSchema: zodToJsonSchemaAdapter })
8218
+ parameters: (0, _copilotkit_shared.schemaToJsonSchema)(fn.parameters)
8494
8219
  })));
8495
8220
  }, [sandboxFunctionsList]);
8496
8221
  (0, react.useLayoutEffect)(() => {
@@ -17002,6 +16727,12 @@ Object.defineProperty(exports, 'CustomEventSchema', {
17002
16727
  return _ag_ui_core_schemas.CustomEventSchema;
17003
16728
  }
17004
16729
  });
16730
+ Object.defineProperty(exports, 'DEFAULT_OPEN_GENERATIVE_UI_DESIGN_SKILL', {
16731
+ enumerable: true,
16732
+ get: function () {
16733
+ return _copilotkit_core.DEFAULT_OPEN_GENERATIVE_UI_DESIGN_SKILL;
16734
+ }
16735
+ });
17005
16736
  Object.defineProperty(exports, 'DataSourceSchema', {
17006
16737
  enumerable: true,
17007
16738
  get: function () {
@@ -17092,6 +16823,12 @@ Object.defineProperty(exports, 'FunctionMiddleware', {
17092
16823
  return _ag_ui_client.FunctionMiddleware;
17093
16824
  }
17094
16825
  });
16826
+ Object.defineProperty(exports, 'GENERATE_SANDBOXED_UI_TOOL_NAME', {
16827
+ enumerable: true,
16828
+ get: function () {
16829
+ return _copilotkit_core.GENERATE_SANDBOXED_UI_TOOL_NAME;
16830
+ }
16831
+ });
17095
16832
  exports.GenerateSandboxedUiArgsSchema = GenerateSandboxedUiArgsSchema;
17096
16833
  Object.defineProperty(exports, 'HttpAgent', {
17097
16834
  enumerable: true,
@@ -17278,6 +17015,12 @@ Object.defineProperty(exports, 'MultimodalOutputCapabilitiesSchema', {
17278
17015
  return _ag_ui_core_schemas.MultimodalOutputCapabilitiesSchema;
17279
17016
  }
17280
17017
  });
17018
+ Object.defineProperty(exports, 'OPEN_GENERATIVE_UI_ACTIVITY_TYPE', {
17019
+ enumerable: true,
17020
+ get: function () {
17021
+ return _copilotkit_core.OPEN_GENERATIVE_UI_ACTIVITY_TYPE;
17022
+ }
17023
+ });
17281
17024
  exports.OpenGenerativeUIActivityRenderer = OpenGenerativeUIActivityRenderer;
17282
17025
  exports.OpenGenerativeUIActivityType = OpenGenerativeUIActivityType;
17283
17026
  exports.OpenGenerativeUIContentSchema = OpenGenerativeUIContentSchema;
@@ -18168,6 +17911,12 @@ Object.defineProperty(exports, 'ɵMAX_SOCKET_RETRIES', {
18168
17911
  return _copilotkit_core.ɵMAX_SOCKET_RETRIES;
18169
17912
  }
18170
17913
  });
17914
+ Object.defineProperty(exports, 'ɵOpenGenerativeUIController', {
17915
+ enumerable: true,
17916
+ get: function () {
17917
+ return _copilotkit_core.ɵOpenGenerativeUIController;
17918
+ }
17919
+ });
18171
17920
  Object.defineProperty(exports, 'ɵRUNTIME_PROBE_TIMEOUT_MS', {
18172
17921
  enumerable: true,
18173
17922
  get: function () {
@@ -18234,6 +17983,12 @@ Object.defineProperty(exports, 'ɵdeduplicateMessages', {
18234
17983
  return _copilotkit_core.ɵdeduplicateMessages;
18235
17984
  }
18236
17985
  });
17986
+ Object.defineProperty(exports, 'ɵextractCompleteStyles', {
17987
+ enumerable: true,
17988
+ get: function () {
17989
+ return _copilotkit_core.ɵextractCompleteStyles;
17990
+ }
17991
+ });
18237
17992
  Object.defineProperty(exports, 'ɵformatCountLabel', {
18238
17993
  enumerable: true,
18239
17994
  get: function () {
@@ -18360,6 +18115,12 @@ Object.defineProperty(exports, 'ɵjoinPhoenixChannel$', {
18360
18115
  return _copilotkit_core.ɵjoinPhoenixChannel$;
18361
18116
  }
18362
18117
  });
18118
+ Object.defineProperty(exports, 'ɵloadWebsandbox', {
18119
+ enumerable: true,
18120
+ get: function () {
18121
+ return _copilotkit_core.ɵloadWebsandbox;
18122
+ }
18123
+ });
18363
18124
  Object.defineProperty(exports, 'ɵmapMemoryMetadataEvent', {
18364
18125
  enumerable: true,
18365
18126
  get: function () {
@@ -18438,6 +18199,12 @@ Object.defineProperty(exports, 'ɵpluralize', {
18438
18199
  return _copilotkit_core.ɵpluralize;
18439
18200
  }
18440
18201
  });
18202
+ Object.defineProperty(exports, 'ɵprocessPartialHtml', {
18203
+ enumerable: true,
18204
+ get: function () {
18205
+ return _copilotkit_core.ɵprocessPartialHtml;
18206
+ }
18207
+ });
18441
18208
  Object.defineProperty(exports, 'ɵrecordWorkTime', {
18442
18209
  enumerable: true,
18443
18210
  get: function () {