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