@copilotkit/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.
- package/dist/index.cjs +434 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +160 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +160 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +428 -3
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +880 -7
- package/dist/index.umd.js.map +1 -1
- package/package.json +6 -6
- package/tsdown.config.ts +4 -1
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,6 @@ let _copilotkit_shared = require("@copilotkit/shared");
|
|
|
5
5
|
let rxjs = require("rxjs");
|
|
6
6
|
let rxjs_operators = require("rxjs/operators");
|
|
7
7
|
let phoenix = require("phoenix");
|
|
8
|
-
let zod_to_json_schema = require("zod-to-json-schema");
|
|
9
8
|
let _copilotkit_learning = require("@copilotkit/learning");
|
|
10
9
|
|
|
11
10
|
//#region src/utils/http-agent.ts
|
|
@@ -3713,7 +3712,7 @@ const EMPTY_TOOL_SCHEMA = {
|
|
|
3713
3712
|
*/
|
|
3714
3713
|
function createToolSchema(tool) {
|
|
3715
3714
|
if (!tool.parameters) return { ...EMPTY_TOOL_SCHEMA };
|
|
3716
|
-
const rawSchema = (0, _copilotkit_shared.schemaToJsonSchema)(tool.parameters
|
|
3715
|
+
const rawSchema = (0, _copilotkit_shared.schemaToJsonSchema)(tool.parameters);
|
|
3717
3716
|
if (!rawSchema || typeof rawSchema !== "object") return { ...EMPTY_TOOL_SCHEMA };
|
|
3718
3717
|
const { $schema: _$schema, ...schema } = rawSchema;
|
|
3719
3718
|
if (typeof schema.type !== "string") schema.type = "object";
|
|
@@ -12400,6 +12399,432 @@ const ɵcopilotIconSvgAttributes = {
|
|
|
12400
12399
|
"stroke-linejoin": "round"
|
|
12401
12400
|
};
|
|
12402
12401
|
|
|
12402
|
+
//#endregion
|
|
12403
|
+
//#region src/open-generative-ui/content.ts
|
|
12404
|
+
/**
|
|
12405
|
+
* Open Generative UI content: the activity the agent streams while it
|
|
12406
|
+
* generates a sandboxed UI, and the rules for when a new snapshot must reach
|
|
12407
|
+
* the sandbox at once.
|
|
12408
|
+
*/
|
|
12409
|
+
/** The activity type of Open Generative UI messages. */
|
|
12410
|
+
const OPEN_GENERATIVE_UI_ACTIVITY_TYPE = "open-generative-ui";
|
|
12411
|
+
/** The name of the frontend tool the agent calls to generate a sandboxed UI. */
|
|
12412
|
+
const GENERATE_SANDBOXED_UI_TOOL_NAME = "generateSandboxedUi";
|
|
12413
|
+
/** The design guidance sent to the agent when no `designSkill` is set. */
|
|
12414
|
+
const DEFAULT_OPEN_GENERATIVE_UI_DESIGN_SKILL = `When generating UI with generateSandboxedUi, follow these design principles inspired by shadcn/ui:
|
|
12415
|
+
|
|
12416
|
+
- Use a minimal, flat aesthetic. Avoid drop shadows and gradients — rely on subtle borders (1px solid, light gray like #e5e7eb) to define surfaces.
|
|
12417
|
+
- Neutral base palette: white backgrounds, zinc/slate gray text (#09090b for headings, #71717a for secondary text). One accent color for interactive elements.
|
|
12418
|
+
- Use system font stacks (system-ui, -apple-system, sans-serif) at readable sizes (14px body, 600 weight for headings). Tight line-heights.
|
|
12419
|
+
- Small, consistent border-radius (6–8px). Cards and containers use border, not shadow, for separation.
|
|
12420
|
+
- Buttons: solid fill for primary (dark bg, white text), outline for secondary (border + transparent bg). Subtle hover state (slight opacity or background shift).
|
|
12421
|
+
- Use CSS Grid or Flexbox for layout. Ensure the UI looks good at any width.
|
|
12422
|
+
- Minimal transitions (150ms) for hover/focus states only. No decorative animations.
|
|
12423
|
+
- Keep the UI focused and dense — avoid excessive padding. Use compact spacing (8–12px gaps, 10–14px padding in controls).`;
|
|
12424
|
+
/** `true` when the content has HTML that a preview or final sandbox shows. */
|
|
12425
|
+
function hasRenderableContent(content) {
|
|
12426
|
+
if (!content) return false;
|
|
12427
|
+
const hasHtml = !!content.html?.join("").trim();
|
|
12428
|
+
const hasFinalHtml = content.htmlComplete && hasHtml;
|
|
12429
|
+
const hasPreviewHtml = content.cssComplete && !content.htmlComplete && hasHtml;
|
|
12430
|
+
return !!hasFinalHtml || !!hasPreviewHtml;
|
|
12431
|
+
}
|
|
12432
|
+
/**
|
|
12433
|
+
* `true` when `next` must replace `previous` at once instead of waiting for
|
|
12434
|
+
* the throttle window: the UI restarts, a stage completes, or new JavaScript
|
|
12435
|
+
* arrives.
|
|
12436
|
+
*/
|
|
12437
|
+
function shouldFlushImmediately(previous, next) {
|
|
12438
|
+
if (hasRenderableContent(previous) && !hasRenderableContent(next)) return true;
|
|
12439
|
+
if (next.cssComplete && !previous?.cssComplete) return true;
|
|
12440
|
+
if (next.htmlComplete) return true;
|
|
12441
|
+
if (next.generating === false) return true;
|
|
12442
|
+
if (next.jsFunctions && !previous?.jsFunctions) return true;
|
|
12443
|
+
if ((next.jsExpressions?.length ?? 0) > (previous?.jsExpressions?.length ?? 0)) return true;
|
|
12444
|
+
if (next.html?.length && !previous?.html?.length) return true;
|
|
12445
|
+
return false;
|
|
12446
|
+
}
|
|
12447
|
+
|
|
12448
|
+
//#endregion
|
|
12449
|
+
//#region src/open-generative-ui/html.ts
|
|
12450
|
+
/**
|
|
12451
|
+
* Pure string helpers that turn streamed HTML into sandbox content.
|
|
12452
|
+
* No DOM access.
|
|
12453
|
+
*/
|
|
12454
|
+
/**
|
|
12455
|
+
* Extracts all complete `<style>` blocks from the raw HTML.
|
|
12456
|
+
* Returns the concatenated style tags, suitable for injection into `<head>`.
|
|
12457
|
+
*/
|
|
12458
|
+
function extractCompleteStyles(html) {
|
|
12459
|
+
const matches = html.match(/<style\b[^>]*>[\s\S]*?<\/style>/gi);
|
|
12460
|
+
return matches ? matches.join("") : "";
|
|
12461
|
+
}
|
|
12462
|
+
/**
|
|
12463
|
+
* Processes raw accumulated HTML for safe preview via innerHTML injection.
|
|
12464
|
+
*
|
|
12465
|
+
* Pipeline (order matters):
|
|
12466
|
+
* 1. Strip incomplete tag at end
|
|
12467
|
+
* 2. Strip complete <style>, <script>, and <head> blocks
|
|
12468
|
+
* 3. Strip incomplete <style>/<script>/<head> blocks
|
|
12469
|
+
* 4. Strip incomplete HTML entities
|
|
12470
|
+
* 5. Extract body content (or use full string if no <body>)
|
|
12471
|
+
*/
|
|
12472
|
+
function processPartialHtml(html) {
|
|
12473
|
+
let result = html;
|
|
12474
|
+
result = result.replace(/<[^>]*$/, "");
|
|
12475
|
+
result = result.replace(/<(style|script|head)\b[^>]*>[\s\S]*?<\/\1>/gi, "");
|
|
12476
|
+
result = result.replace(/<(style|script|head)\b[^>]*>[\s\S]*$/gi, "");
|
|
12477
|
+
result = result.replace(/&[a-zA-Z0-9#]*$/, "");
|
|
12478
|
+
const bodyMatch = result.match(/<body[^>]*>([\s\S]*)/i);
|
|
12479
|
+
if (bodyMatch) {
|
|
12480
|
+
result = bodyMatch[1];
|
|
12481
|
+
result = result.replace(/<\/body>[\s\S]*/i, "");
|
|
12482
|
+
}
|
|
12483
|
+
return result;
|
|
12484
|
+
}
|
|
12485
|
+
/** Builds the final sandbox document: the HTML with the CSS in its `<head>`. */
|
|
12486
|
+
function buildFinalFrameContent(html, css) {
|
|
12487
|
+
const withCss = css ? injectCssIntoHtml(html, css) : html;
|
|
12488
|
+
return /<head[\s>]/i.test(withCss) ? withCss : `<head></head>${withCss}`;
|
|
12489
|
+
}
|
|
12490
|
+
function injectCssIntoHtml(html, css) {
|
|
12491
|
+
const headCloseIdx = html.indexOf("</head>");
|
|
12492
|
+
if (headCloseIdx !== -1) return html.slice(0, headCloseIdx) + `<style>${css}</style>` + html.slice(headCloseIdx);
|
|
12493
|
+
return `<head><style>${css}</style></head>${html}`;
|
|
12494
|
+
}
|
|
12495
|
+
|
|
12496
|
+
//#endregion
|
|
12497
|
+
//#region src/open-generative-ui/websandbox.ts
|
|
12498
|
+
/**
|
|
12499
|
+
* Imports `@jetbrains/websandbox` on demand. The import is dynamic because
|
|
12500
|
+
* the package touches `self` when it loads, which breaks server rendering.
|
|
12501
|
+
*/
|
|
12502
|
+
const loadWebsandbox = async () => {
|
|
12503
|
+
const defaultExport = (await import("@jetbrains/websandbox")).default;
|
|
12504
|
+
return "default" in defaultExport ? defaultExport.default : defaultExport;
|
|
12505
|
+
};
|
|
12506
|
+
|
|
12507
|
+
//#endregion
|
|
12508
|
+
//#region src/open-generative-ui/controller.ts
|
|
12509
|
+
/** Non-immediate content updates reach the sandbox at most this often. */
|
|
12510
|
+
const OPEN_GENERATIVE_UI_THROTTLE_MS = 1e3;
|
|
12511
|
+
const DEFAULT_HEIGHT = 200;
|
|
12512
|
+
const HIDE_SCROLLBARS = `
|
|
12513
|
+
var s = document.createElement('style');
|
|
12514
|
+
s.textContent = 'html, body { overflow: hidden !important; }';
|
|
12515
|
+
document.head.appendChild(s);
|
|
12516
|
+
`;
|
|
12517
|
+
const HIDE_SCROLLBARS_STYLE = "<style>html, body { overflow: hidden !important; }</style>";
|
|
12518
|
+
const MEASURE_HEIGHT = `
|
|
12519
|
+
(function() {
|
|
12520
|
+
var s = document.createElement('style');
|
|
12521
|
+
s.textContent = 'body { height: auto !important; min-height: 0 !important; }';
|
|
12522
|
+
document.head.appendChild(s);
|
|
12523
|
+
var h = document.body.scrollHeight;
|
|
12524
|
+
var cs = getComputedStyle(document.body);
|
|
12525
|
+
h += parseFloat(cs.marginTop) || 0;
|
|
12526
|
+
h += parseFloat(cs.marginBottom) || 0;
|
|
12527
|
+
s.remove();
|
|
12528
|
+
parent.postMessage({ type: "__ck_resize", height: Math.ceil(h) }, "*");
|
|
12529
|
+
})();
|
|
12530
|
+
`;
|
|
12531
|
+
function deriveContent(content) {
|
|
12532
|
+
const html = content.html?.join("") || void 0;
|
|
12533
|
+
const css = content.cssComplete ? content.css : void 0;
|
|
12534
|
+
if (content.htmlComplete) return {
|
|
12535
|
+
fullHtml: html,
|
|
12536
|
+
css,
|
|
12537
|
+
previewStyles: ""
|
|
12538
|
+
};
|
|
12539
|
+
const previewBody = html && content.cssComplete ? processPartialHtml(html) : void 0;
|
|
12540
|
+
return {
|
|
12541
|
+
css,
|
|
12542
|
+
previewBody: previewBody?.trim() ? previewBody : void 0,
|
|
12543
|
+
previewStyles: html ? extractCompleteStyles(html) : ""
|
|
12544
|
+
};
|
|
12545
|
+
}
|
|
12546
|
+
function prepareIframe(iframe, testId) {
|
|
12547
|
+
iframe.setAttribute("data-testid", testId);
|
|
12548
|
+
iframe.style.width = "100%";
|
|
12549
|
+
iframe.style.height = "100%";
|
|
12550
|
+
iframe.style.border = "none";
|
|
12551
|
+
iframe.style.backgroundColor = "transparent";
|
|
12552
|
+
}
|
|
12553
|
+
function logLoadError(error) {
|
|
12554
|
+
console.error("[OpenGenerativeUI] Failed to load sandbox module:", error);
|
|
12555
|
+
}
|
|
12556
|
+
function sameFunctions(a, b) {
|
|
12557
|
+
return a.length === b.length && a.every((fn, i) => fn.name === b[i].name && fn.handler === b[i].handler);
|
|
12558
|
+
}
|
|
12559
|
+
/**
|
|
12560
|
+
* Runs Open Generative UI content in websandbox iframes inside a host element.
|
|
12561
|
+
*
|
|
12562
|
+
* Give it content snapshots with `setContent()` and a host element with
|
|
12563
|
+
* `setHost()`. It throttles the snapshots, streams a preview while HTML
|
|
12564
|
+
* arrives, swaps in the final sandbox once HTML is complete, runs
|
|
12565
|
+
* `jsFunctions` and `jsExpressions` in it once each, and measures the final
|
|
12566
|
+
* height. Frameworks render the container from `getState()` and re-render
|
|
12567
|
+
* when `subscribe()` notifies.
|
|
12568
|
+
*
|
|
12569
|
+
* @example
|
|
12570
|
+
* ```ts
|
|
12571
|
+
* const controller = new ɵOpenGenerativeUIController();
|
|
12572
|
+
* controller.subscribe(() => render(controller.getState()));
|
|
12573
|
+
* controller.setContent(content);
|
|
12574
|
+
* controller.setHost(containerElement);
|
|
12575
|
+
* // On unmount:
|
|
12576
|
+
* controller.destroy();
|
|
12577
|
+
* ```
|
|
12578
|
+
*/
|
|
12579
|
+
var OpenGenerativeUIController = class {
|
|
12580
|
+
#load;
|
|
12581
|
+
#listeners = /* @__PURE__ */ new Set();
|
|
12582
|
+
#content;
|
|
12583
|
+
#latest;
|
|
12584
|
+
#derived = { previewStyles: "" };
|
|
12585
|
+
#timer;
|
|
12586
|
+
#host = null;
|
|
12587
|
+
#functions = [];
|
|
12588
|
+
#localApi = {};
|
|
12589
|
+
#preview;
|
|
12590
|
+
#final;
|
|
12591
|
+
#measuredHeight;
|
|
12592
|
+
#state = {
|
|
12593
|
+
phase: "placeholder",
|
|
12594
|
+
generating: true,
|
|
12595
|
+
height: DEFAULT_HEIGHT
|
|
12596
|
+
};
|
|
12597
|
+
constructor(options = {}) {
|
|
12598
|
+
this.#load = options.loadWebsandbox ?? loadWebsandbox;
|
|
12599
|
+
}
|
|
12600
|
+
/** The current state. The same object until something changes. */
|
|
12601
|
+
getState = () => this.#state;
|
|
12602
|
+
/** Calls `listener` when the state changes. Returns the unsubscribe function. */
|
|
12603
|
+
subscribe = (listener) => {
|
|
12604
|
+
this.#listeners.add(listener);
|
|
12605
|
+
return () => {
|
|
12606
|
+
this.#listeners.delete(listener);
|
|
12607
|
+
};
|
|
12608
|
+
};
|
|
12609
|
+
/**
|
|
12610
|
+
* Sets the latest content snapshot. The first snapshot and snapshots that
|
|
12611
|
+
* finish a stage apply at once; others apply at most once per second.
|
|
12612
|
+
*/
|
|
12613
|
+
setContent(content) {
|
|
12614
|
+
this.#latest = content;
|
|
12615
|
+
if (this.#content === void 0 || shouldFlushImmediately(this.#content, content)) {
|
|
12616
|
+
this.#clearTimer();
|
|
12617
|
+
this.#commit(content);
|
|
12618
|
+
return;
|
|
12619
|
+
}
|
|
12620
|
+
if (content === this.#content || this.#timer !== void 0) return;
|
|
12621
|
+
this.#timer = setTimeout(() => {
|
|
12622
|
+
this.#timer = void 0;
|
|
12623
|
+
if (this.#latest) this.#commit(this.#latest);
|
|
12624
|
+
}, OPEN_GENERATIVE_UI_THROTTLE_MS);
|
|
12625
|
+
}
|
|
12626
|
+
/** Sets the element the sandbox iframes go into. `null` removes them. */
|
|
12627
|
+
setHost(host) {
|
|
12628
|
+
if (host === this.#host) return;
|
|
12629
|
+
this.#destroyPreview();
|
|
12630
|
+
this.#destroyFinal();
|
|
12631
|
+
this.#host = host;
|
|
12632
|
+
this.#reconcile();
|
|
12633
|
+
}
|
|
12634
|
+
/**
|
|
12635
|
+
* Sets the host functions sandboxed code can call. A change recreates the
|
|
12636
|
+
* final sandbox.
|
|
12637
|
+
*/
|
|
12638
|
+
setSandboxFunctions(functions) {
|
|
12639
|
+
if (sameFunctions(functions, this.#functions)) return;
|
|
12640
|
+
this.#functions = functions;
|
|
12641
|
+
const localApi = {};
|
|
12642
|
+
for (const fn of functions) localApi[fn.name] = fn.handler;
|
|
12643
|
+
this.#localApi = localApi;
|
|
12644
|
+
this.#reconcile();
|
|
12645
|
+
}
|
|
12646
|
+
/**
|
|
12647
|
+
* Removes the sandboxes and stops pending work. A later `setHost()`
|
|
12648
|
+
* starts again from the current content.
|
|
12649
|
+
*/
|
|
12650
|
+
destroy() {
|
|
12651
|
+
this.#clearTimer();
|
|
12652
|
+
this.#destroyPreview();
|
|
12653
|
+
this.#destroyFinal();
|
|
12654
|
+
this.#host = null;
|
|
12655
|
+
}
|
|
12656
|
+
#commit(content) {
|
|
12657
|
+
if (content === this.#content) return;
|
|
12658
|
+
this.#content = content;
|
|
12659
|
+
this.#derived = deriveContent(content);
|
|
12660
|
+
this.#reconcile();
|
|
12661
|
+
}
|
|
12662
|
+
#reconcile() {
|
|
12663
|
+
const host = this.#host;
|
|
12664
|
+
const content = this.#content;
|
|
12665
|
+
const derived = this.#derived;
|
|
12666
|
+
if (host && content) if (derived.fullHtml) {
|
|
12667
|
+
this.#destroyPreview();
|
|
12668
|
+
const frameContent = buildFinalFrameContent(derived.fullHtml, derived.css);
|
|
12669
|
+
let final = this.#final;
|
|
12670
|
+
if (final?.frameContent !== frameContent || final.localApi !== this.#localApi) {
|
|
12671
|
+
this.#destroyFinal();
|
|
12672
|
+
final = this.#final = this.#createFinal(host, frameContent);
|
|
12673
|
+
}
|
|
12674
|
+
this.#runScripts(final, content);
|
|
12675
|
+
} else {
|
|
12676
|
+
this.#destroyFinal();
|
|
12677
|
+
if (derived.previewBody) {
|
|
12678
|
+
this.#preview ??= this.#createPreview(host);
|
|
12679
|
+
this.#writePreview();
|
|
12680
|
+
} else this.#destroyPreview();
|
|
12681
|
+
}
|
|
12682
|
+
this.#updateState();
|
|
12683
|
+
}
|
|
12684
|
+
#createPreview(host) {
|
|
12685
|
+
const slot = {
|
|
12686
|
+
ready: false,
|
|
12687
|
+
cancelled: false
|
|
12688
|
+
};
|
|
12689
|
+
this.#load().then((Websandbox) => {
|
|
12690
|
+
if (slot.cancelled) return;
|
|
12691
|
+
const sandbox = Websandbox.create({}, {
|
|
12692
|
+
frameContainer: host,
|
|
12693
|
+
frameContent: "<head></head><body></body>",
|
|
12694
|
+
allowAdditionalAttributes: ""
|
|
12695
|
+
});
|
|
12696
|
+
slot.sandbox = sandbox;
|
|
12697
|
+
prepareIframe(sandbox.iframe, "open-generative-ui-preview-sandbox");
|
|
12698
|
+
sandbox.promise.then(() => {
|
|
12699
|
+
if (slot.cancelled) return;
|
|
12700
|
+
slot.ready = true;
|
|
12701
|
+
this.#writePreview();
|
|
12702
|
+
});
|
|
12703
|
+
}).catch(logLoadError);
|
|
12704
|
+
return slot;
|
|
12705
|
+
}
|
|
12706
|
+
#writePreview() {
|
|
12707
|
+
const slot = this.#preview;
|
|
12708
|
+
if (!slot?.sandbox || !slot.ready) return;
|
|
12709
|
+
const { css, previewStyles, previewBody } = this.#derived;
|
|
12710
|
+
const head = HIDE_SCROLLBARS_STYLE + (css ? `<style>${css}</style>` : "") + previewStyles;
|
|
12711
|
+
if (head !== slot.head) {
|
|
12712
|
+
slot.head = head;
|
|
12713
|
+
slot.sandbox.run(`document.head.innerHTML = ${JSON.stringify(head)}`);
|
|
12714
|
+
}
|
|
12715
|
+
if (previewBody && previewBody !== slot.body) {
|
|
12716
|
+
slot.body = previewBody;
|
|
12717
|
+
slot.sandbox.run(`document.body.innerHTML = ${JSON.stringify(previewBody)}`);
|
|
12718
|
+
}
|
|
12719
|
+
}
|
|
12720
|
+
#createFinal(host, frameContent) {
|
|
12721
|
+
const slot = {
|
|
12722
|
+
frameContent,
|
|
12723
|
+
localApi: this.#localApi,
|
|
12724
|
+
ready: false,
|
|
12725
|
+
cancelled: false,
|
|
12726
|
+
queue: [],
|
|
12727
|
+
jsFunctionsInjected: false,
|
|
12728
|
+
executedExpressions: 0,
|
|
12729
|
+
heightRequested: false
|
|
12730
|
+
};
|
|
12731
|
+
this.#load().then((Websandbox) => {
|
|
12732
|
+
if (slot.cancelled) return;
|
|
12733
|
+
const sandbox = Websandbox.create(slot.localApi, {
|
|
12734
|
+
frameContainer: host,
|
|
12735
|
+
frameContent,
|
|
12736
|
+
allowAdditionalAttributes: ""
|
|
12737
|
+
});
|
|
12738
|
+
slot.sandbox = sandbox;
|
|
12739
|
+
prepareIframe(sandbox.iframe, "open-generative-ui-final-sandbox");
|
|
12740
|
+
sandbox.promise.then(() => {
|
|
12741
|
+
if (slot.cancelled) return;
|
|
12742
|
+
slot.ready = true;
|
|
12743
|
+
sandbox.run(HIDE_SCROLLBARS);
|
|
12744
|
+
const queue = slot.queue;
|
|
12745
|
+
slot.queue = [];
|
|
12746
|
+
for (const code of queue) sandbox.run(code);
|
|
12747
|
+
});
|
|
12748
|
+
}).catch(logLoadError);
|
|
12749
|
+
return slot;
|
|
12750
|
+
}
|
|
12751
|
+
/** Runs new `jsFunctions`, new `jsExpressions`, and the height measurement. */
|
|
12752
|
+
#runScripts(slot, content) {
|
|
12753
|
+
if (content.jsFunctions && !slot.jsFunctionsInjected) {
|
|
12754
|
+
slot.jsFunctionsInjected = true;
|
|
12755
|
+
this.#runOrQueue(slot, content.jsFunctions);
|
|
12756
|
+
}
|
|
12757
|
+
const expressions = content.jsExpressions ?? [];
|
|
12758
|
+
if (expressions.length > slot.executedExpressions) {
|
|
12759
|
+
const newExpressions = expressions.slice(slot.executedExpressions);
|
|
12760
|
+
slot.executedExpressions = expressions.length;
|
|
12761
|
+
const sandbox = slot.sandbox;
|
|
12762
|
+
if (slot.ready && sandbox) (async () => {
|
|
12763
|
+
for (const expression of newExpressions) await sandbox.run(expression);
|
|
12764
|
+
})();
|
|
12765
|
+
else slot.queue.push(...newExpressions);
|
|
12766
|
+
}
|
|
12767
|
+
if (content.generating === false && !slot.heightRequested) {
|
|
12768
|
+
slot.heightRequested = true;
|
|
12769
|
+
this.#listenForHeight(slot);
|
|
12770
|
+
this.#runOrQueue(slot, MEASURE_HEIGHT);
|
|
12771
|
+
}
|
|
12772
|
+
}
|
|
12773
|
+
#runOrQueue(slot, code) {
|
|
12774
|
+
if (slot.ready && slot.sandbox) slot.sandbox.run(code);
|
|
12775
|
+
else slot.queue.push(code);
|
|
12776
|
+
}
|
|
12777
|
+
#listenForHeight(slot) {
|
|
12778
|
+
if (typeof window === "undefined") return;
|
|
12779
|
+
const onMessage = (event) => {
|
|
12780
|
+
const data = event.data;
|
|
12781
|
+
if (!slot.sandbox || event.source !== slot.sandbox.iframe.contentWindow || data?.type !== "__ck_resize" || typeof data.height !== "number") return;
|
|
12782
|
+
slot.stopHeightListener?.();
|
|
12783
|
+
this.#measuredHeight = data.height;
|
|
12784
|
+
this.#updateState();
|
|
12785
|
+
};
|
|
12786
|
+
window.addEventListener("message", onMessage);
|
|
12787
|
+
slot.stopHeightListener = () => {
|
|
12788
|
+
window.removeEventListener("message", onMessage);
|
|
12789
|
+
slot.stopHeightListener = void 0;
|
|
12790
|
+
};
|
|
12791
|
+
}
|
|
12792
|
+
#destroyPreview() {
|
|
12793
|
+
const slot = this.#preview;
|
|
12794
|
+
if (!slot) return;
|
|
12795
|
+
slot.cancelled = true;
|
|
12796
|
+
slot.sandbox?.destroy();
|
|
12797
|
+
this.#preview = void 0;
|
|
12798
|
+
}
|
|
12799
|
+
#destroyFinal() {
|
|
12800
|
+
const slot = this.#final;
|
|
12801
|
+
if (!slot) return;
|
|
12802
|
+
slot.cancelled = true;
|
|
12803
|
+
slot.stopHeightListener?.();
|
|
12804
|
+
slot.sandbox?.destroy();
|
|
12805
|
+
this.#final = void 0;
|
|
12806
|
+
this.#measuredHeight = void 0;
|
|
12807
|
+
}
|
|
12808
|
+
#clearTimer() {
|
|
12809
|
+
if (this.#timer === void 0) return;
|
|
12810
|
+
clearTimeout(this.#timer);
|
|
12811
|
+
this.#timer = void 0;
|
|
12812
|
+
}
|
|
12813
|
+
#updateState() {
|
|
12814
|
+
const content = this.#content ?? {};
|
|
12815
|
+
const derived = this.#derived;
|
|
12816
|
+
const next = {
|
|
12817
|
+
phase: derived.fullHtml ? "final" : derived.previewBody ? "preview" : "placeholder",
|
|
12818
|
+
generating: content.generating !== false,
|
|
12819
|
+
height: this.#measuredHeight ?? content.initialHeight ?? DEFAULT_HEIGHT
|
|
12820
|
+
};
|
|
12821
|
+
const current = this.#state;
|
|
12822
|
+
if (next.phase === current.phase && next.generating === current.generating && next.height === current.height) return;
|
|
12823
|
+
this.#state = next;
|
|
12824
|
+
for (const listener of this.#listeners) listener();
|
|
12825
|
+
}
|
|
12826
|
+
};
|
|
12827
|
+
|
|
12403
12828
|
//#endregion
|
|
12404
12829
|
exports.A2UI_FENCE_LANGUAGE = A2UI_FENCE_LANGUAGE;
|
|
12405
12830
|
exports.AgentRegistry = AgentRegistry;
|
|
@@ -12410,11 +12835,14 @@ exports.CopilotKitCore = CopilotKitCore;
|
|
|
12410
12835
|
exports.CopilotKitCoreErrorCode = CopilotKitCoreErrorCode;
|
|
12411
12836
|
exports.CopilotKitCoreRuntimeConnectionStatus = CopilotKitCoreRuntimeConnectionStatus;
|
|
12412
12837
|
exports.CopilotKitHeaderResolutionError = CopilotKitHeaderResolutionError;
|
|
12838
|
+
exports.DEFAULT_OPEN_GENERATIVE_UI_DESIGN_SKILL = DEFAULT_OPEN_GENERATIVE_UI_DESIGN_SKILL;
|
|
12839
|
+
exports.GENERATE_SANDBOXED_UI_TOOL_NAME = GENERATE_SANDBOXED_UI_TOOL_NAME;
|
|
12413
12840
|
exports.INSPECTOR_THREAD_BRIDGE_PLUGIN_ID = INSPECTOR_THREAD_BRIDGE_PLUGIN_ID;
|
|
12414
12841
|
exports.INTERRUPT_EVENT_NAME = INTERRUPT_EVENT_NAME;
|
|
12415
12842
|
exports.IntelligenceAgent = IntelligenceAgent;
|
|
12416
12843
|
exports.MEMORY_ERROR_REGISTRY = MEMORY_ERROR_REGISTRY;
|
|
12417
12844
|
exports.MemoryError = MemoryError;
|
|
12845
|
+
exports.OPEN_GENERATIVE_UI_ACTIVITY_TYPE = OPEN_GENERATIVE_UI_ACTIVITY_TYPE;
|
|
12418
12846
|
exports.ProxiedCopilotRuntimeAgent = ProxiedCopilotRuntimeAgent;
|
|
12419
12847
|
exports.RunHandler = RunHandler;
|
|
12420
12848
|
exports.StateManager = StateManager;
|
|
@@ -12461,6 +12889,7 @@ exports.splitA2UIMarkdown = splitA2UIMarkdown;
|
|
|
12461
12889
|
exports.ɵCOPILOTKIT_FEATURES = ɵCOPILOTKIT_FEATURES;
|
|
12462
12890
|
exports.ɵInterruptState = ɵInterruptState;
|
|
12463
12891
|
exports.ɵMAX_SOCKET_RETRIES = ɵMAX_SOCKET_RETRIES;
|
|
12892
|
+
exports.ɵOpenGenerativeUIController = OpenGenerativeUIController;
|
|
12464
12893
|
exports.ɵRUNTIME_PROBE_TIMEOUT_MS = ɵRUNTIME_PROBE_TIMEOUT_MS;
|
|
12465
12894
|
exports.ɵTHREAD_REQUEST_TIMEOUT_MS = ɵTHREAD_REQUEST_TIMEOUT_MS;
|
|
12466
12895
|
exports.ɵclearAgentInterruptState = ɵclearAgentInterruptState;
|
|
@@ -12472,6 +12901,7 @@ exports.ɵcreateMemoryStore = createMemoryStore;
|
|
|
12472
12901
|
exports.ɵcreateThreadSelectors = ɵcreateThreadSelectors;
|
|
12473
12902
|
exports.ɵcreateThreadStore = createThreadStore;
|
|
12474
12903
|
exports.ɵdeduplicateMessages = ɵdeduplicateMessages;
|
|
12904
|
+
exports.ɵextractCompleteStyles = extractCompleteStyles;
|
|
12475
12905
|
exports.ɵformatCountLabel = ɵformatCountLabel;
|
|
12476
12906
|
exports.ɵformatLabel = ɵformatLabel;
|
|
12477
12907
|
exports.ɵformatReasoningDuration = formatReasoningDuration;
|
|
@@ -12493,6 +12923,7 @@ exports.ɵisRetryableMemoryStatus = isRetryableStatus;
|
|
|
12493
12923
|
exports.ɵisTurnWorkOpen = isTurnWorkOpen;
|
|
12494
12924
|
exports.ɵisTurnWorking = isTurnWorking;
|
|
12495
12925
|
exports.ɵjoinPhoenixChannel$ = ɵjoinPhoenixChannel$;
|
|
12926
|
+
exports.ɵloadWebsandbox = loadWebsandbox;
|
|
12496
12927
|
exports.ɵmapMemoryMetadataEvent = ɵmapMemoryMetadataEvent;
|
|
12497
12928
|
exports.ɵmemoryAdapterEvents = ɵmemoryAdapterEvents;
|
|
12498
12929
|
exports.ɵmemoryDomainEvents = ɵmemoryDomainEvents;
|
|
@@ -12506,6 +12937,7 @@ exports.ɵobservePhoenixSocketSignals$ = ɵobservePhoenixSocketSignals$;
|
|
|
12506
12937
|
exports.ɵphoenixChannel$ = ɵphoenixChannel$;
|
|
12507
12938
|
exports.ɵphoenixSocket$ = ɵphoenixSocket$;
|
|
12508
12939
|
exports.ɵpluralize = pluralize;
|
|
12940
|
+
exports.ɵprocessPartialHtml = processPartialHtml;
|
|
12509
12941
|
exports.ɵrecordWorkTime = recordWorkTime;
|
|
12510
12942
|
exports.ɵresolveActivityRenderer = ɵresolveActivityRenderer;
|
|
12511
12943
|
exports.ɵresolveComposerKey = ɵresolveComposerKey;
|