@copilotkit/core 2.0.0-rc.19 → 2.0.0-rc.20

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 CHANGED
@@ -12261,6 +12261,152 @@ function ɵresolveThreadsLicense(context) {
12261
12261
  licensePending: status === null
12262
12262
  };
12263
12263
  }
12264
+ const PRICING_URL = "https://copilotkit.ai/pricing";
12265
+ const DASHBOARD_URL = "https://dashboard.operations.copilotkit.ai";
12266
+ /**
12267
+ * What one license banner shows: its severity, text, and link. React, Vue,
12268
+ * and Angular render it with {@link ɵLICENSE_BANNER_STYLE}.
12269
+ *
12270
+ * @param type - The banner type, for example from
12271
+ * {@link ɵresolveLicenseState}'s `bannerType`.
12272
+ * @param labels - The chat labels in effect, so apps can translate the text.
12273
+ * @param details - The feature name, expiry date, or days left.
12274
+ *
12275
+ * @example
12276
+ * ```ts
12277
+ * const spec = ɵgetLicenseBannerSpec("expiring", labels, { graceRemaining: 3 });
12278
+ * // { severity: "warning", message: "… expires in 3 days …", actionLabel: "Renew", … }
12279
+ * ```
12280
+ */
12281
+ function ɵgetLicenseBannerSpec(type, labels, { featureName, expiryDate, graceRemaining } = {}) {
12282
+ switch (type) {
12283
+ case "no_license": return bannerSpec("info", labels.licensePoweredByText, labels.licenseGetLicenseLabel, PRICING_URL);
12284
+ case "feature_unlicensed": return bannerSpec("warning", ɵformatLabel(labels.licenseFeatureUnlicensedText, { feature: featureName ?? "" }), labels.licenseGetLicenseLabel, PRICING_URL);
12285
+ case "expiring": return bannerSpec("warning", expiringMessage(labels, graceRemaining), labels.licenseRenewLabel, DASHBOARD_URL);
12286
+ case "expired": return bannerSpec("critical", expiryDate ? ɵformatLabel(labels.licenseExpiredOnDateText, { date: expiryDate }) : labels.licenseExpiredText, labels.licenseRenewNowLabel, PRICING_URL);
12287
+ case "invalid": return bannerSpec("critical", labels.licenseInvalidText, labels.licenseGetLicenseLabel, PRICING_URL);
12288
+ }
12289
+ }
12290
+ const bannerSpec = (severity, message, actionLabel, actionUrl) => ({
12291
+ severity,
12292
+ message,
12293
+ actionLabel,
12294
+ actionUrl
12295
+ });
12296
+ /**
12297
+ * The "expires soon" text. Without a day count it says "soon", never "in
12298
+ * undefined days".
12299
+ */
12300
+ function expiringMessage(labels, graceRemaining) {
12301
+ if (graceRemaining === void 0) return labels.licenseExpiringText;
12302
+ return ɵformatLabel(graceRemaining === 1 ? labels.licenseExpiringInDaysOne : labels.licenseExpiringInDaysOther, { days: graceRemaining });
12303
+ }
12304
+ const FONT_FAMILY = "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif";
12305
+ /**
12306
+ * Inline styles of the fixed license banner, in camelCase, for React `style`
12307
+ * and Vue `:style`. `base` is the layout; `severity` holds the colours.
12308
+ */
12309
+ const ɵLICENSE_BANNER_STYLE = {
12310
+ base: {
12311
+ position: "fixed",
12312
+ bottom: "8px",
12313
+ left: "50%",
12314
+ transform: "translateX(-50%)",
12315
+ zIndex: 99999,
12316
+ display: "inline-flex",
12317
+ alignItems: "center",
12318
+ gap: "12px",
12319
+ whiteSpace: "nowrap",
12320
+ padding: "8px 16px",
12321
+ fontSize: "13px",
12322
+ fontFamily: FONT_FAMILY,
12323
+ borderRadius: "6px",
12324
+ boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
12325
+ },
12326
+ severity: {
12327
+ info: {
12328
+ backgroundColor: "#eff6ff",
12329
+ border: "1px solid #93c5fd",
12330
+ color: "#1e40af"
12331
+ },
12332
+ warning: {
12333
+ backgroundColor: "#fffbeb",
12334
+ border: "1px solid #fbbf24",
12335
+ color: "#92400e"
12336
+ },
12337
+ critical: {
12338
+ backgroundColor: "#fef2f2",
12339
+ border: "1px solid #fca5a5",
12340
+ color: "#991b1b"
12341
+ }
12342
+ },
12343
+ actions: {
12344
+ display: "flex",
12345
+ gap: "8px",
12346
+ alignItems: "center"
12347
+ },
12348
+ link: {
12349
+ fontWeight: 600,
12350
+ textDecoration: "underline",
12351
+ color: "inherit"
12352
+ },
12353
+ dismiss: {
12354
+ background: "none",
12355
+ border: "none",
12356
+ cursor: "pointer",
12357
+ color: "inherit",
12358
+ fontSize: "16px"
12359
+ }
12360
+ };
12361
+ /**
12362
+ * The bottom space the fixed banner takes: banner height (~36px) + bottom
12363
+ * offset (8px) + gap above the chat input (~8px). The chat input reads it
12364
+ * through `padding-bottom: var(--copilotkit-license-banner-offset)`.
12365
+ */
12366
+ const ɵLICENSE_BANNER_OFFSET = {
12367
+ cssVar: "--copilotkit-license-banner-offset",
12368
+ px: 52
12369
+ };
12370
+ /**
12371
+ * Publishes {@link ɵLICENSE_BANNER_OFFSET} on the root element while a
12372
+ * banner shows. Does nothing without a document (SSR).
12373
+ *
12374
+ * @returns A function that removes the offset again.
12375
+ */
12376
+ function ɵreserveLicenseBannerOffset() {
12377
+ if (typeof document === "undefined") return () => {};
12378
+ const root = document.documentElement;
12379
+ root.style.setProperty(ɵLICENSE_BANNER_OFFSET.cssVar, `${ɵLICENSE_BANNER_OFFSET.px}px`);
12380
+ return () => root.style.removeProperty(ɵLICENSE_BANNER_OFFSET.cssVar);
12381
+ }
12382
+ /**
12383
+ * What the inline warning shows when a chat component needs a license it
12384
+ * does not have: the `licenseFeatureUnlicensedText` label and a pricing
12385
+ * link. Render it with {@link ɵINLINE_FEATURE_WARNING_STYLE}.
12386
+ */
12387
+ function ɵgetInlineFeatureWarningSpec(featureName, labels) {
12388
+ return {
12389
+ message: ɵformatLabel(labels.licenseFeatureUnlicensedText, { feature: featureName }),
12390
+ actionLabel: "Get one at copilotkit.ai/pricing",
12391
+ actionUrl: PRICING_URL
12392
+ };
12393
+ }
12394
+ /** Inline styles of the inline feature warning, in camelCase. */
12395
+ const ɵINLINE_FEATURE_WARNING_STYLE = {
12396
+ container: {
12397
+ padding: "8px 12px",
12398
+ backgroundColor: "#fffbeb",
12399
+ border: "1px solid #fbbf24",
12400
+ borderRadius: "6px",
12401
+ fontSize: "13px",
12402
+ color: "#92400e",
12403
+ fontFamily: FONT_FAMILY
12404
+ },
12405
+ link: {
12406
+ color: "#b45309",
12407
+ textDecoration: "underline"
12408
+ }
12409
+ };
12264
12410
 
12265
12411
  //#endregion
12266
12412
  //#region src/chat/icons.ts
@@ -12489,6 +12635,880 @@ const ɵcopilotIconSvgAttributes = {
12489
12635
  "stroke-linejoin": "round"
12490
12636
  };
12491
12637
 
12638
+ //#endregion
12639
+ //#region src/chat/message-feedback.ts
12640
+ /** Trajectory event name for a rating of one assistant message. */
12641
+ const ɵMESSAGE_FEEDBACK_EVENT_NAME = "message.feedback";
12642
+ /** Longest comment kept, in characters; the rest is cut so the event stays small. */
12643
+ const ɵMESSAGE_FEEDBACK_MAX_COMMENT_LENGTH = 1e3;
12644
+ /** Longest excerpt of the rated response sent with the rating, in characters. */
12645
+ const RESPONSE_EXCERPT_LENGTH = 500;
12646
+ /**
12647
+ * How long the pointer may be away from the rating and its comment before the
12648
+ * comment closes: enough to cross the gap between them, short enough that
12649
+ * passing over a rating does not leave it open.
12650
+ */
12651
+ const ɵFEEDBACK_COMMENT_CLOSE_DELAY_MS = 150;
12652
+ const ratings = /* @__PURE__ */ new Map();
12653
+ const listeners = /* @__PURE__ */ new Map();
12654
+ const threadKey = (agentId, threadId) => JSON.stringify([agentId, threadId]);
12655
+ const messageKey = (agentId, threadId, messageId) => JSON.stringify([
12656
+ agentId,
12657
+ threadId,
12658
+ messageId
12659
+ ]);
12660
+ /** Cuts `text` to `max` characters without splitting a surrogate pair. */
12661
+ const clip = (text, max) => {
12662
+ const characters = Array.from(text);
12663
+ return characters.length > max ? characters.slice(0, max).join("") : text;
12664
+ };
12665
+ /** The comment as kept and sent: trimmed and capped, or none. */
12666
+ const normalizeComment = (comment) => {
12667
+ if (comment === void 0) return void 0;
12668
+ const text = clip(comment.trim(), ɵMESSAGE_FEEDBACK_MAX_COMMENT_LENGTH);
12669
+ return text === "" ? void 0 : text;
12670
+ };
12671
+ /** The rating this page gave one message, if any. */
12672
+ function ɵgetMessageFeedback(agentId, threadId, messageId) {
12673
+ return ratings.get(messageKey(agentId, threadId, messageId));
12674
+ }
12675
+ /** Calls `listener` whenever a rating in this Thread changes. */
12676
+ function ɵsubscribeToMessageFeedback(agentId, threadId, listener) {
12677
+ const key = threadKey(agentId, threadId);
12678
+ let set = listeners.get(key);
12679
+ if (set === void 0) {
12680
+ set = /* @__PURE__ */ new Set();
12681
+ listeners.set(key, set);
12682
+ }
12683
+ const subscribed = set;
12684
+ subscribed.add(listener);
12685
+ return () => {
12686
+ subscribed.delete(listener);
12687
+ if (subscribed.size === 0) listeners.delete(key);
12688
+ };
12689
+ }
12690
+ /**
12691
+ * Sets (or, with `null`, clears) this page's rating of one message and sends
12692
+ * it to the active Trajectory. Every change is a new event; the newest event
12693
+ * for a `feedbackId` is the current one. Like any Trajectory event, a change
12694
+ * made while no Trajectory captures, for example during a reconnect, is not
12695
+ * sent; the page still shows it.
12696
+ */
12697
+ function ɵsetMessageFeedback(params) {
12698
+ const { copilotkit, agentId, threadId, message } = params;
12699
+ const comment = normalizeComment(params.feedback?.comment);
12700
+ const feedback = params.feedback && {
12701
+ rating: params.feedback.rating,
12702
+ ...comment ? { comment } : {}
12703
+ };
12704
+ const key = messageKey(agentId, threadId, message.id);
12705
+ if (feedback) ratings.set(key, feedback);
12706
+ else ratings.delete(key);
12707
+ const threadListeners = listeners.get(threadKey(agentId, threadId)) ?? [];
12708
+ for (const listener of threadListeners) listener();
12709
+ const runId = copilotkit.getRunIdForMessage(agentId, threadId, message.id);
12710
+ copilotkit.emitTrajectoryEvent(ɵMESSAGE_FEEDBACK_EVENT_NAME, {
12711
+ feedbackId: `${threadId}:${message.id}`,
12712
+ threadId,
12713
+ messageId: message.id,
12714
+ agentId,
12715
+ ...runId ? { runId } : {},
12716
+ rating: feedback?.rating ?? null,
12717
+ ...feedback?.comment ? { comment: feedback.comment } : {},
12718
+ ...copilotkit.ɵlearningCapturesAgentText ? { response: clip(message.content ?? "", RESPONSE_EXCERPT_LENGTH) } : {}
12719
+ });
12720
+ }
12721
+ /** @internal Forgets every rating, so each test starts empty. */
12722
+ function ɵresetMessageFeedbackCache() {
12723
+ ratings.clear();
12724
+ }
12725
+ const capturedCores = /* @__PURE__ */ new WeakSet();
12726
+ const rememberCapture = (copilotkit) => {
12727
+ if (capturedCores.has(copilotkit)) return;
12728
+ capturedCores.add(copilotkit);
12729
+ const unsubscribe = copilotkit.ɵsubscribeToLearningConfigured(() => {
12730
+ if (copilotkit.ɵlearningConfigured) return;
12731
+ capturedCores.delete(copilotkit);
12732
+ unsubscribe();
12733
+ });
12734
+ };
12735
+ /**
12736
+ * Whether the thumbs record feedback for Learning. True once a Trajectory of
12737
+ * this Core has started and as long as Learning stays configured, also while
12738
+ * capture reconnects or is stopped, so the buttons do not flicker. Ratings
12739
+ * given meanwhile still show but, like any Trajectory event, are not sent. A
12740
+ * capture that never starts (for example without a license) leaves it false.
12741
+ *
12742
+ * Re-read it when {@link ɵsubscribeToLearningFeedbackEnabled} notifies.
12743
+ */
12744
+ function ɵisLearningFeedbackEnabled(copilotkit) {
12745
+ const capturing = copilotkit.trajectoryId !== null;
12746
+ if (capturing) rememberCapture(copilotkit);
12747
+ return copilotkit.ɵlearningConfigured && (capturing || capturedCores.has(copilotkit));
12748
+ }
12749
+ /**
12750
+ * Calls `listener` when {@link ɵisLearningFeedbackEnabled} may have changed:
12751
+ * when Learning is configured or removed, and when the Trajectory changes.
12752
+ * Returns the unsubscribe function.
12753
+ */
12754
+ function ɵsubscribeToLearningFeedbackEnabled(copilotkit, listener) {
12755
+ const unsubscribeConfigured = copilotkit.ɵsubscribeToLearningConfigured(listener);
12756
+ const subscription = copilotkit.subscribe({ onTrajectoryChanged: listener });
12757
+ return () => {
12758
+ unsubscribeConfigured();
12759
+ subscription.unsubscribe();
12760
+ };
12761
+ }
12762
+ /**
12763
+ * The feedback this page gave `message` in `scope`, and how to change it.
12764
+ * Read it again when {@link ɵsubscribeToMessageFeedback} notifies for the
12765
+ * scope's Thread.
12766
+ */
12767
+ function ɵgetMessageFeedbackControls(scope, message) {
12768
+ const feedback = ɵgetMessageFeedback(scope.agentId, scope.threadId, message.id);
12769
+ const save = (next) => ɵsetMessageFeedback({
12770
+ ...scope,
12771
+ message,
12772
+ feedback: next
12773
+ });
12774
+ return {
12775
+ feedback,
12776
+ rate: (rating) => {
12777
+ if (feedback?.rating !== rating) save({ rating });
12778
+ },
12779
+ clear: () => {
12780
+ if (feedback) save(null);
12781
+ },
12782
+ comment: (comment) => {
12783
+ if (feedback) save({
12784
+ rating: feedback.rating,
12785
+ comment
12786
+ });
12787
+ }
12788
+ };
12789
+ }
12790
+ /**
12791
+ * Drives the comment popover of a rated message.
12792
+ *
12793
+ * It opens when a rating is given and whenever the pointer or keyboard focus
12794
+ * reaches the chosen thumb, with the saved comment in the field. It closes by
12795
+ * itself shortly after the pointer leaves the thumb and the popover, unless
12796
+ * focus is in the field: then it stays until focus moves away, Enter, or
12797
+ * Escape. Closing saves a changed comment; Escape, a click on a thumb, and
12798
+ * removing the rating discard it.
12799
+ *
12800
+ * Frameworks render from `getSnapshot()` and re-render when `subscribe()`
12801
+ * notifies. Call `dispose()` on unmount: it keeps an unsaved edit, for a
12802
+ * message that scrolls out of a virtual list. The controller stays usable
12803
+ * after `dispose()`, so a remount (React Strict Mode) can keep it.
12804
+ *
12805
+ * @example
12806
+ * ```ts
12807
+ * const comment = new ɵFeedbackCommentController({ getControls: () => controls });
12808
+ * comment.subscribe(() => render(comment.getSnapshot()));
12809
+ * comment.show({ comment: "", focus: false });
12810
+ * // On unmount:
12811
+ * comment.dispose();
12812
+ * ```
12813
+ */
12814
+ var ɵFeedbackCommentController = class {
12815
+ #getControls;
12816
+ #closeDelayMs;
12817
+ #listeners = /* @__PURE__ */ new Set();
12818
+ #state = {
12819
+ open: false,
12820
+ draft: "",
12821
+ focusRequest: 0
12822
+ };
12823
+ #timer;
12824
+ #editing = false;
12825
+ #focusWaiting = false;
12826
+ #pointerOver = false;
12827
+ #returning = false;
12828
+ constructor(options) {
12829
+ this.#getControls = options.getControls;
12830
+ this.#closeDelayMs = options.closeDelayMs ?? ɵFEEDBACK_COMMENT_CLOSE_DELAY_MS;
12831
+ }
12832
+ /** The current state. The same object until something changes. */
12833
+ getSnapshot = () => this.#state;
12834
+ /** Calls `listener` when the state changes. Returns the unsubscribe function. */
12835
+ subscribe = (listener) => {
12836
+ this.#listeners.add(listener);
12837
+ return () => {
12838
+ this.#listeners.delete(listener);
12839
+ };
12840
+ };
12841
+ /** Sets the comment being edited. */
12842
+ setDraft = (draft) => {
12843
+ this.#update({ draft });
12844
+ };
12845
+ /** Whether a focus request waits; reading it answers the request. */
12846
+ takeFocusRequest = () => {
12847
+ const waiting = this.#focusWaiting;
12848
+ this.#focusWaiting = false;
12849
+ return waiting;
12850
+ };
12851
+ /** Opens with `comment` in the field. */
12852
+ show = ({ comment, focus }) => {
12853
+ this.#cancelClose();
12854
+ if (focus) this.#focusWaiting = true;
12855
+ this.#update({
12856
+ open: true,
12857
+ draft: comment,
12858
+ focusRequest: this.#state.focusRequest + (focus ? 1 : 0)
12859
+ });
12860
+ };
12861
+ /** The pointer or focus reached the rating or the popover. */
12862
+ enter = (via = "focus") => {
12863
+ this.#cancelClose();
12864
+ if (via === "pointer") this.#pointerOver = true;
12865
+ if (this.#returning) return;
12866
+ if (!this.#state.open && this.#getControls()?.feedback) this.show({
12867
+ comment: this.#savedComment(),
12868
+ focus: false
12869
+ });
12870
+ };
12871
+ /**
12872
+ * It left them: close soon, unless the user is editing the comment or, when
12873
+ * focus left, the pointer is still on the rating or the popover.
12874
+ */
12875
+ leave = (via = "focus") => {
12876
+ if (via === "pointer") this.#pointerOver = false;
12877
+ else if (this.#pointerOver) return;
12878
+ this.#cancelClose();
12879
+ this.#timer = setTimeout(() => {
12880
+ this.#timer = void 0;
12881
+ if (!this.#editing) this.close();
12882
+ }, this.#closeDelayMs);
12883
+ };
12884
+ /** Tracks whether focus is in the comment form. */
12885
+ setEditing = (editing) => {
12886
+ this.#editing = editing;
12887
+ };
12888
+ /** Closes, saving a changed comment unless `save` is false. */
12889
+ close = ({ save = true } = {}) => {
12890
+ this.#cancelClose();
12891
+ this.#focusWaiting = false;
12892
+ this.#pointerOver = false;
12893
+ if (!this.#state.open) return;
12894
+ if (save) this.#saveDraft();
12895
+ this.#editing = false;
12896
+ this.#update({ open: false });
12897
+ };
12898
+ /** Moves focus back to the thumb without opening the comment again. */
12899
+ returnFocus = (target) => {
12900
+ this.#returning = true;
12901
+ try {
12902
+ target?.focus();
12903
+ } finally {
12904
+ this.#returning = false;
12905
+ }
12906
+ };
12907
+ /** Stops the close timer and saves a changed comment that is still open. */
12908
+ dispose = () => {
12909
+ this.#cancelClose();
12910
+ if (this.#state.open) this.#saveDraft();
12911
+ };
12912
+ #savedComment() {
12913
+ return this.#getControls()?.feedback?.comment ?? "";
12914
+ }
12915
+ #saveDraft() {
12916
+ const controls = this.#getControls();
12917
+ const draft = this.#state.draft;
12918
+ if (controls?.feedback && draft.trim() !== this.#savedComment()) controls.comment(draft);
12919
+ }
12920
+ #cancelClose() {
12921
+ if (this.#timer === void 0) return;
12922
+ clearTimeout(this.#timer);
12923
+ this.#timer = void 0;
12924
+ }
12925
+ #update(patch) {
12926
+ const next = {
12927
+ ...this.#state,
12928
+ ...patch
12929
+ };
12930
+ if (next.open === this.#state.open && next.draft === this.#state.draft && next.focusRequest === this.#state.focusRequest) return;
12931
+ this.#state = next;
12932
+ for (const listener of this.#listeners) listener();
12933
+ }
12934
+ };
12935
+
12936
+ //#endregion
12937
+ //#region src/chat/viewport.ts
12938
+ const AUTO_SCROLL_MODES = [
12939
+ "pin-to-bottom",
12940
+ "pin-to-send",
12941
+ "none"
12942
+ ];
12943
+ const isAutoScrollMode = (value) => AUTO_SCROLL_MODES.includes(value);
12944
+ /**
12945
+ * Turns the `autoScroll` prop into a mode. `true` and a missing value mean
12946
+ * `"pin-to-bottom"`, `false` means `"none"`, and an unknown string falls back
12947
+ * to `"pin-to-bottom"`.
12948
+ */
12949
+ function ɵnormalizeAutoScroll(value) {
12950
+ if (value === false) return "none";
12951
+ if (value === void 0 || value === true) return "pin-to-bottom";
12952
+ return isAutoScrollMode(value) ? value : "pin-to-bottom";
12953
+ }
12954
+ /**
12955
+ * Media query for the mobile range, where the threads drawer and the chat
12956
+ * modal are mutually exclusive.
12957
+ */
12958
+ const ɵMOBILE_MAX_WIDTH_QUERY = "(max-width: 767px)";
12959
+ /** `window.matchMedia` for the mobile query, or `null` without a DOM. */
12960
+ const mobileMediaQuery = () => {
12961
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia(ɵMOBILE_MAX_WIDTH_QUERY) : null;
12962
+ };
12963
+ /**
12964
+ * Whether the viewport is in the mobile range (`<768px`). `false` during SSR
12965
+ * and where `window.matchMedia` is missing (some test runners and webviews).
12966
+ */
12967
+ function ɵisMobileViewport() {
12968
+ return mobileMediaQuery()?.matches ?? false;
12969
+ }
12970
+ /**
12971
+ * Calls `listener` with {@link ɵisMobileViewport} now and each time the
12972
+ * viewport enters or leaves the mobile range. Does nothing without
12973
+ * `window.matchMedia`. Returns the unsubscribe function.
12974
+ */
12975
+ function ɵwatchMobileViewport(listener) {
12976
+ const query = mobileMediaQuery();
12977
+ if (query === null) return () => {};
12978
+ const update = () => listener(query.matches);
12979
+ update();
12980
+ query.addEventListener("change", update);
12981
+ return () => query.removeEventListener("change", update);
12982
+ }
12983
+ /**
12984
+ * The on-screen keyboard is treated as open once it covers more than this
12985
+ * many pixels of the layout viewport.
12986
+ */
12987
+ const ɵKEYBOARD_OPEN_THRESHOLD_PX = 150;
12988
+ /**
12989
+ * Reads the keyboard state with the Visual Viewport API: the keyboard height
12990
+ * is `innerHeight - visualViewport.height`, clamped to 0. Without the API (or
12991
+ * during SSR) it reports a closed keyboard and the full window height.
12992
+ */
12993
+ function ɵreadKeyboardState() {
12994
+ if (typeof window === "undefined") return closedKeyboard(0);
12995
+ const visualViewport = window.visualViewport;
12996
+ if (!visualViewport) return closedKeyboard(window.innerHeight);
12997
+ const layoutHeight = window.innerHeight;
12998
+ const keyboardHeight = Math.max(0, layoutHeight - visualViewport.height);
12999
+ return {
13000
+ isKeyboardOpen: keyboardHeight > ɵKEYBOARD_OPEN_THRESHOLD_PX,
13001
+ keyboardHeight,
13002
+ availableHeight: visualViewport.height,
13003
+ viewportHeight: layoutHeight
13004
+ };
13005
+ }
13006
+ const closedKeyboard = (height) => ({
13007
+ isKeyboardOpen: false,
13008
+ keyboardHeight: 0,
13009
+ availableHeight: height,
13010
+ viewportHeight: height
13011
+ });
13012
+ /**
13013
+ * The state for the first render, before {@link ɵwatchKeyboardState} reads
13014
+ * the visual viewport: a closed keyboard over the full window height (0
13015
+ * during SSR).
13016
+ */
13017
+ function ɵinitialKeyboardState() {
13018
+ return closedKeyboard(typeof window === "undefined" ? 0 : window.innerHeight);
13019
+ }
13020
+ /**
13021
+ * Calls `listener` with {@link ɵreadKeyboardState} now and on each visual
13022
+ * viewport resize or scroll. Does nothing during SSR or without the Visual
13023
+ * Viewport API. Returns the unsubscribe function.
13024
+ */
13025
+ function ɵwatchKeyboardState(listener) {
13026
+ if (typeof window === "undefined") return () => {};
13027
+ const visualViewport = window.visualViewport;
13028
+ if (!visualViewport) return () => {};
13029
+ const update = () => listener(ɵreadKeyboardState());
13030
+ update();
13031
+ visualViewport.addEventListener("resize", update);
13032
+ visualViewport.addEventListener("scroll", update);
13033
+ return () => {
13034
+ visualViewport.removeEventListener("resize", update);
13035
+ visualViewport.removeEventListener("scroll", update);
13036
+ };
13037
+ }
13038
+ /** Escapes `id` for a CSS attribute selector, also without `CSS.escape`. */
13039
+ const escapeSelectorValue = (id) => typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(id) : id.replace(/[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g, "\\$&");
13040
+ /**
13041
+ * Offset of `el` from the top of `stopAt`'s content, including `stopAt`'s
13042
+ * scroll. Uses `getBoundingClientRect`, so it works for any CSS position.
13043
+ */
13044
+ const offsetTopWithin = (el, stopAt) => el.getBoundingClientRect().top - stopAt.getBoundingClientRect().top + stopAt.scrollTop;
13045
+ /**
13046
+ * Pins a sent message to the top of the chat: sizes the spacer so the
13047
+ * message bubble can scroll to `topOffset` from the viewport top, scrolls
13048
+ * there on the next frame, and then shrinks the spacer as the reply below
13049
+ * grows, so the bubble stays put.
13050
+ *
13051
+ * The message element's top padding is scrolled off-screen: the bubble, not
13052
+ * its padded box, is pinned. Does nothing when no element in `contentEl` has
13053
+ * `data-message-id` equal to `messageId`. Skips the scroll without
13054
+ * `requestAnimationFrame` and the spacer updates without `ResizeObserver`.
13055
+ *
13056
+ * @returns A function that cancels the scroll and stops the spacer updates.
13057
+ * It returns `false` when it cancelled a scroll that had not run yet, so the
13058
+ * caller can pin the same send again. React's StrictMode tears an effect
13059
+ * down before the next frame, so the first run never scrolls.
13060
+ *
13061
+ * @example
13062
+ * ```ts
13063
+ * const unpin = ɵpinMessageToTop({ scrollEl, contentEl, spacerEl, messageId });
13064
+ * // On the next send or on unmount:
13065
+ * unpin();
13066
+ * ```
13067
+ */
13068
+ function ɵpinMessageToTop({ scrollEl, contentEl, spacerEl, messageId, topOffset = 16 }) {
13069
+ const targetEl = contentEl.querySelector(`[data-message-id="${escapeSelectorValue(messageId)}"]`);
13070
+ if (!targetEl) return () => true;
13071
+ const viewportHeight = scrollEl.clientHeight;
13072
+ const userMessageHeight = targetEl.getBoundingClientRect().height;
13073
+ const paddingTop = parseFloat(getComputedStyle(targetEl).paddingTop) || 0;
13074
+ const bubbleHeight = Math.max(0, userMessageHeight - paddingTop);
13075
+ const spacerHeight = Math.max(0, viewportHeight - bubbleHeight - topOffset);
13076
+ spacerEl.style.height = `${spacerHeight}px`;
13077
+ let scrolled = false;
13078
+ const frame = typeof requestAnimationFrame === "function" ? requestAnimationFrame(() => {
13079
+ scrolled = true;
13080
+ const targetTop = offsetTopWithin(targetEl, scrollEl) + paddingTop - topOffset;
13081
+ scrollEl.scrollTo({
13082
+ top: Math.max(0, targetTop),
13083
+ behavior: "smooth"
13084
+ });
13085
+ }) : null;
13086
+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => {
13087
+ const consumedBelow = contentEl.getBoundingClientRect().height - offsetTopWithin(targetEl, contentEl) - userMessageHeight;
13088
+ const remaining = Math.max(0, spacerHeight - consumedBelow);
13089
+ spacerEl.style.height = `${remaining}px`;
13090
+ });
13091
+ observer?.observe(contentEl);
13092
+ return () => {
13093
+ if (frame !== null && typeof cancelAnimationFrame === "function") cancelAnimationFrame(frame);
13094
+ observer?.disconnect();
13095
+ return frame === null || scrolled;
13096
+ };
13097
+ }
13098
+
13099
+ //#endregion
13100
+ //#region src/chat/message-display.ts
13101
+ /**
13102
+ * How long the model reasoned, as label text: "a few seconds", "4 seconds",
13103
+ * "2 minutes", or "1m 5s".
13104
+ *
13105
+ * @param seconds - The elapsed time in seconds. It may have a fraction.
13106
+ * @param labels - The chat labels that hold the duration texts.
13107
+ */
13108
+ function ɵformatReasoningDurationLabel(seconds, labels) {
13109
+ const duration = formatReasoningDuration(seconds);
13110
+ switch (duration.unit) {
13111
+ case "fewSeconds": return labels.reasoningMessageDurationFewSeconds;
13112
+ case "seconds": return ɵformatLabel(labels.reasoningMessageDurationSeconds, { count: duration.seconds });
13113
+ case "minutes": return ɵformatCountLabel(duration.minutes, {
13114
+ one: labels.reasoningMessageDurationMinutesOne,
13115
+ other: labels.reasoningMessageDurationMinutesOther
13116
+ });
13117
+ case "minutesSeconds": return ɵformatLabel(labels.reasoningMessageDurationMinutesSeconds, {
13118
+ minutes: duration.minutes,
13119
+ seconds: duration.seconds
13120
+ });
13121
+ }
13122
+ }
13123
+ /**
13124
+ * The text of the work summary line at the top of a reply in the `"turn"`
13125
+ * tool-call display.
13126
+ *
13127
+ * - While working: `label` is "Working" and `detail` the live timer ("4s"),
13128
+ * or `null` when the elapsed time is not known.
13129
+ * - When done with a known time: `label` is "Worked for 9s" (at least 1s)
13130
+ * and `detail` the tool count ("7 tools").
13131
+ * - When done without a time: `label` is "Used 7 tools" and `detail` `null`.
13132
+ * - `failed` is "2 failed" when tool calls failed, otherwise `null`. It is
13133
+ * always `null` while working.
13134
+ */
13135
+ function ɵgetWorkSummaryText({ isWorking, calls, elapsedMs, workingSince, now, labels }) {
13136
+ if (isWorking) {
13137
+ const isTimed = elapsedMs !== void 0 && workingSince !== void 0;
13138
+ return {
13139
+ label: labels.workSummaryWorkingLabel,
13140
+ detail: isTimed ? formatWorkDuration(elapsedMs + Math.max(0, now - workingSince)) : null,
13141
+ failed: null
13142
+ };
13143
+ }
13144
+ const failedCount = countFailedToolCalls(calls);
13145
+ const failed = failedCount > 0 ? ɵformatLabel(labels.toolCallFailedCountLabel, { count: failedCount }) : null;
13146
+ if (elapsedMs === void 0) return {
13147
+ label: ɵformatCountLabel(calls.length, {
13148
+ one: labels.toolCallUsedToolsOne,
13149
+ other: labels.toolCallUsedToolsOther
13150
+ }),
13151
+ detail: null,
13152
+ failed
13153
+ };
13154
+ const duration = formatWorkDuration(Math.max(1e3, elapsedMs));
13155
+ return {
13156
+ label: ɵformatLabel(labels.workSummaryWorkedForLabel, { duration }),
13157
+ detail: ɵformatCountLabel(calls.length, {
13158
+ one: labels.toolCallToolCountOne,
13159
+ other: labels.toolCallToolCountOther
13160
+ }),
13161
+ failed
13162
+ };
13163
+ }
13164
+ /**
13165
+ * The text of a user message: the string content, or its text parts joined
13166
+ * by newlines. Parts that are not text, and malformed parts from untyped
13167
+ * data, add nothing.
13168
+ */
13169
+ function ɵflattenUserMessageContent(content) {
13170
+ if (!content) return "";
13171
+ if (typeof content === "string") return content;
13172
+ return content.map((part) => part?.type === "text" && typeof part.text === "string" ? part.text : "").filter((text) => text.length > 0).join("\n");
13173
+ }
13174
+ const isMediaPart = (part) => part?.type === "image" || part?.type === "audio" || part?.type === "video" || part?.type === "document";
13175
+ /** The image, audio, video, and document parts of a user message. */
13176
+ function ɵgetUserMessageMediaParts(content) {
13177
+ if (!content || typeof content === "string") return [];
13178
+ return content.filter(isMediaPart);
13179
+ }
13180
+ /** The file name stored in an attachment's `metadata.filename`, if any. */
13181
+ function ɵgetUserMessageMediaFilename(part) {
13182
+ const meta = part.metadata;
13183
+ return meta != null && typeof meta === "object" && "filename" in meta && typeof meta.filename === "string" ? meta.filename : void 0;
13184
+ }
13185
+ /**
13186
+ * Whether a user message shows its branch navigation and which arrows work.
13187
+ * It shows only with more than one branch and a switch handler: without the
13188
+ * handler the arrows would do nothing.
13189
+ */
13190
+ function ɵgetBranchNavState({ branchIndex, numberOfBranches, canSwitch }) {
13191
+ const show = canSwitch && numberOfBranches > 1;
13192
+ return {
13193
+ show,
13194
+ canGoPrev: show && branchIndex > 0,
13195
+ canGoNext: show && branchIndex < numberOfBranches - 1
13196
+ };
13197
+ }
13198
+ /** Whether an assistant message has text beyond whitespace. */
13199
+ function ɵhasAssistantMessageText(content) {
13200
+ return !!content && content.trim().length > 0;
13201
+ }
13202
+ /**
13203
+ * Whether an assistant message shows its toolbar: when toolbars are on, the
13204
+ * message has text or the Inspector shortcut shows, and the message is not
13205
+ * the one still streaming (the latest while the agent runs).
13206
+ */
13207
+ function ɵshouldShowAssistantToolbar({ toolbarVisible, hasContent, showInspectorShortcut, isRunning, isLatest }) {
13208
+ return toolbarVisible && (hasContent || showInspectorShortcut) && !(isRunning && isLatest);
13209
+ }
13210
+ /** How long a copy button shows its "copied" check mark, in ms. */
13211
+ const ɵCOPY_FEEDBACK_RESET_MS = 2e3;
13212
+ /**
13213
+ * The "copied" state of a copy button. After a copy it is `true` for
13214
+ * {@link ɵCOPY_FEEDBACK_RESET_MS}; another copy in that time restarts the
13215
+ * wait, so rapid clicks do not flicker.
13216
+ *
13217
+ * Frameworks render from `getSnapshot()` and re-render when `subscribe()`
13218
+ * notifies. Call `dispose()` on unmount. The controller stays usable after
13219
+ * `dispose()`, so a remount (React Strict Mode) can keep it.
13220
+ *
13221
+ * @example
13222
+ * ```ts
13223
+ * const feedback = new ɵCopyFeedback();
13224
+ * feedback.subscribe(() => render(feedback.getSnapshot()));
13225
+ * await feedback.copy(text);
13226
+ * ```
13227
+ */
13228
+ var ɵCopyFeedback = class {
13229
+ #listeners = /* @__PURE__ */ new Set();
13230
+ #resetMs;
13231
+ #copied = false;
13232
+ #timer;
13233
+ constructor({ resetMs = ɵCOPY_FEEDBACK_RESET_MS } = {}) {
13234
+ this.#resetMs = resetMs;
13235
+ }
13236
+ /** Whether the check mark shows. */
13237
+ getSnapshot = () => this.#copied;
13238
+ /** Calls `listener` when the state changes. Returns the unsubscribe function. */
13239
+ subscribe = (listener) => {
13240
+ this.#listeners.add(listener);
13241
+ return () => {
13242
+ this.#listeners.delete(listener);
13243
+ };
13244
+ };
13245
+ /** Shows the check mark, or keeps it for the full time again. */
13246
+ markCopied = () => {
13247
+ this.#clearTimer();
13248
+ this.#set(true);
13249
+ this.#timer = setTimeout(() => {
13250
+ this.#timer = void 0;
13251
+ this.#set(false);
13252
+ }, this.#resetMs);
13253
+ };
13254
+ /**
13255
+ * Copies `text` to the clipboard and shows the check mark on success.
13256
+ * Empty text copies nothing.
13257
+ *
13258
+ * @returns Whether the text was copied.
13259
+ */
13260
+ copy = async (text) => {
13261
+ if (!text) return false;
13262
+ const copied = await (0, _copilotkit_shared.copyToClipboard)(text);
13263
+ if (copied) this.markCopied();
13264
+ return copied;
13265
+ };
13266
+ /** Stops the reset timer. */
13267
+ dispose = () => {
13268
+ this.#clearTimer();
13269
+ };
13270
+ #clearTimer() {
13271
+ if (this.#timer === void 0) return;
13272
+ clearTimeout(this.#timer);
13273
+ this.#timer = void 0;
13274
+ }
13275
+ #set(copied) {
13276
+ if (copied === this.#copied) return;
13277
+ this.#copied = copied;
13278
+ for (const listener of this.#listeners) listener();
13279
+ }
13280
+ };
13281
+
13282
+ //#endregion
13283
+ //#region src/chat/inspector-button.ts
13284
+ let shortcutsHidden = false;
13285
+ const shortcutListeners = /* @__PURE__ */ new Set();
13286
+ const notifyShortcutListeners = () => {
13287
+ for (const listener of shortcutListeners) listener();
13288
+ };
13289
+ /**
13290
+ * Whether the user hid the Inspector shortcuts in the message toolbars
13291
+ * ("Hide this icon"). It lasts until the page reloads and applies to every
13292
+ * chat on the page.
13293
+ *
13294
+ * @example
13295
+ * ```ts
13296
+ * ɵinspectorShortcuts.subscribe(() => render(ɵinspectorShortcuts.hidden));
13297
+ * ɵinspectorShortcuts.hide();
13298
+ * ```
13299
+ */
13300
+ const ɵinspectorShortcuts = {
13301
+ get hidden() {
13302
+ return shortcutsHidden;
13303
+ },
13304
+ hide() {
13305
+ if (shortcutsHidden) return;
13306
+ shortcutsHidden = true;
13307
+ notifyShortcutListeners();
13308
+ },
13309
+ subscribe(listener) {
13310
+ shortcutListeners.add(listener);
13311
+ return () => {
13312
+ shortcutListeners.delete(listener);
13313
+ };
13314
+ },
13315
+ reset() {
13316
+ if (!shortcutsHidden) return;
13317
+ shortcutsHidden = false;
13318
+ notifyShortcutListeners();
13319
+ }
13320
+ };
13321
+ const kiteStroke = (d, stroke, strokeWidth) => ({
13322
+ d,
13323
+ stroke,
13324
+ strokeWidth,
13325
+ strokeLinecap: "round"
13326
+ });
13327
+ /**
13328
+ * The Inspector kite artwork as data, as in
13329
+ * `web-inspector/src/assets/inspector-logo-kite.svg`. Render an `<svg>` with
13330
+ * `viewBox` and `fill="none"`, one `<path>` per entry of `paths`, and a
13331
+ * `<linearGradient gradientUnits="userSpaceOnUse">` per entry of `gradients`
13332
+ * in `<defs>`. Give each gradient the id `${prefix}-${gradient.id}` with a
13333
+ * prefix unique to the icon, and fill paths with
13334
+ * {@link ɵinspectorKiteFill}.
13335
+ */
13336
+ const ɵinspectorKiteIcon = {
13337
+ viewBox: "4.57 3.36 17.8 17.8",
13338
+ paths: [
13339
+ {
13340
+ d: "M6.36084 10.9855C8.34277 8.393 9.98843 5.82939 10.6204 3.75914C10.6382 3.70281 10.7043 3.67888 10.7534 3.7114C12.9536 5.16894 16.9635 6.12833 20.5086 6.15085C20.5703 6.15124 20.6124 6.2114 20.5895 6.26829C19.4109 9.25938 17.9705 14.6189 17.9148 20.7392C17.9148 20.8301 17.7873 20.8627 17.7419 20.7837C15.7236 17.2522 9.26021 12.2898 6.39414 11.1186C6.34112 11.0968 6.32556 11.0313 6.36084 10.9855Z",
13341
+ fillGradient: "paint0_linear"
13342
+ },
13343
+ {
13344
+ d: "M13.0475 9.39974C9.95016 10.3806 7.11935 10.9259 6.44331 11.0498C6.40027 11.0577 6.39115 11.1172 6.43152 11.134C9.3203 12.3347 15.7516 17.2826 17.7511 20.7998C17.7551 20.8075 17.7647 20.8103 17.7728 20.8068C17.7809 20.803 17.7853 20.793 17.7819 20.7844L13.0475 9.39974Z",
13345
+ fillGradient: "paint1_linear"
13346
+ },
13347
+ {
13348
+ d: "M10.762 3.705C13.4137 5.15161 16.4787 5.80132 20.545 6.14367C20.5703 6.14585 20.5787 6.18008 20.5557 6.19197C20.0359 6.45923 17.0574 7.97512 14.8455 8.78701C14.2524 9.00453 13.6564 9.20632 13.0692 9.39249C13.0562 9.39656 13.0419 9.39015 13.0369 9.37774L10.7005 3.75979C10.6849 3.72196 10.7257 3.68538 10.762 3.705Z",
13349
+ fillGradient: "paint2_linear"
13350
+ },
13351
+ kiteStroke("M10.7145 3.79041L17.8305 20.7659", "#513C9F", "0.17284"),
13352
+ kiteStroke("M6.44531 11.0476C6.44531 11.0476 10.375 10.3422 14.0686 9.06804C17.7623 7.7939 20.5122 6.23373 20.5122 6.23373", "#513C9F", "0.17284"),
13353
+ kiteStroke("M11.6914 5.93518L9.05534 14.7068M9.05534 14.7068H15.3203M9.05534 14.7068L0.15625 26.3646", "#ABABAB", "0.302474"),
13354
+ {
13355
+ d: "M6.02539 23.9646L4.85806 24.1287C5.46272 25.7287 6.70381 26.4276 8.18528 26.4276C11.8147 26.4276 10.707 22.3227 12.8103 22.3227C14.3358 22.3227 13.7155 25.6498 16.9992 25.6498C19.0029 25.6498 19.2028 23.631 18.8607 22.7625C18.8589 22.7572 18.8568 22.7524 18.8538 22.7476L18.3166 21.9253C18.2817 21.8706 18.1968 21.8912 18.1907 21.9562L18.0908 22.9529C18.0838 23.0222 18.0857 23.0913 18.0936 23.1605C18.1764 23.8491 18.2291 25.5202 16.9992 25.5202C15.7015 25.5202 15.3895 22.2362 12.8103 22.2362C9.78393 22.2362 10.1726 26.298 8.31487 26.298C7.08938 26.298 6.15447 24.9153 6.02539 23.9646Z",
13356
+ fillGradient: "paint3_linear"
13357
+ }
13358
+ ],
13359
+ gradients: [
13360
+ {
13361
+ id: "paint0_linear",
13362
+ x1: "15.5372",
13363
+ y1: "5.0278",
13364
+ x2: "12.0802",
13365
+ y2: "14.534",
13366
+ stops: [{ color: "#6430AB" }, {
13367
+ offset: "1",
13368
+ color: "#AA89D8"
13369
+ }]
13370
+ },
13371
+ {
13372
+ id: "paint1_linear",
13373
+ x1: "12.8583",
13374
+ y1: "10.3858",
13375
+ x2: "8.40764",
13376
+ y2: "18.9846",
13377
+ stops: [{ color: "#005DBB" }, {
13378
+ offset: "1",
13379
+ color: "#3D92E8"
13380
+ }]
13381
+ },
13382
+ {
13383
+ id: "paint2_linear",
13384
+ x1: "14.8452",
13385
+ y1: "5.02774",
13386
+ x2: "13.5047",
13387
+ y2: "9.21911",
13388
+ stops: [{ color: "#1B70C4" }, {
13389
+ offset: "1",
13390
+ color: "#54A4F2"
13391
+ }]
13392
+ },
13393
+ {
13394
+ id: "paint3_linear",
13395
+ x1: "4.85806",
13396
+ y1: "24.2455",
13397
+ x2: "18.9963",
13398
+ y2: "24.2455",
13399
+ stops: [
13400
+ { color: "#4497EA" },
13401
+ {
13402
+ offset: "0.254755",
13403
+ color: "#1463B2"
13404
+ },
13405
+ {
13406
+ offset: "0.498725",
13407
+ color: "#0A437D"
13408
+ },
13409
+ {
13410
+ offset: "0.666667",
13411
+ color: "#2476C8"
13412
+ },
13413
+ {
13414
+ offset: "0.972542",
13415
+ color: "#0C549A"
13416
+ }
13417
+ ]
13418
+ }
13419
+ ]
13420
+ };
13421
+ /**
13422
+ * The `fill` of a kite path: its gradient under the icon's id `prefix`, or
13423
+ * `undefined` for a stroke-only path.
13424
+ */
13425
+ function ɵinspectorKiteFill(prefix, path) {
13426
+ return path.fillGradient === void 0 ? void 0 : `url(#${prefix}-${path.fillGradient})`;
13427
+ }
13428
+ /** How long a hover-opened menu stays after the pointer leaves, in ms. */
13429
+ const ɵHOVER_MENU_CLOSE_DELAY_MS = 180;
13430
+ /**
13431
+ * The open state of a menu that opens when the pointer reaches its trigger,
13432
+ * like the Inspector shortcut's menu.
13433
+ *
13434
+ * - A mouse or pen over the trigger opens it; touch does not.
13435
+ * - Leaving the trigger or the menu closes it after `closeDelayMs`, unless
13436
+ * the pointer comes back first or the keyboard has used the menu since.
13437
+ * - Opening reads whether the trigger is inside a `.dark` element, so a menu
13438
+ * in a portal can match the theme.
13439
+ *
13440
+ * Frameworks render from `getSnapshot()` and re-render when `subscribe()`
13441
+ * notifies. Call `dispose()` on unmount; the controller stays usable.
13442
+ */
13443
+ var ɵHoverMenuController = class {
13444
+ #closeDelayMs;
13445
+ #listeners = /* @__PURE__ */ new Set();
13446
+ #state = {
13447
+ open: false,
13448
+ dark: false
13449
+ };
13450
+ #timer;
13451
+ #openedByHover = false;
13452
+ constructor({ closeDelayMs = ɵHOVER_MENU_CLOSE_DELAY_MS } = {}) {
13453
+ this.#closeDelayMs = closeDelayMs;
13454
+ }
13455
+ /** The current state. The same object until something changes. */
13456
+ getSnapshot = () => this.#state;
13457
+ /** Calls `listener` when the state changes. Returns the unsubscribe function. */
13458
+ subscribe = (listener) => {
13459
+ this.#listeners.add(listener);
13460
+ return () => {
13461
+ this.#listeners.delete(listener);
13462
+ };
13463
+ };
13464
+ /** Whether the pointer opened the menu and the keyboard has not used it. */
13465
+ get openedByHover() {
13466
+ return this.#openedByHover;
13467
+ }
13468
+ /**
13469
+ * Opens or closes the menu and stops a pending close. `trigger` is read on
13470
+ * open for the dark theme.
13471
+ */
13472
+ setOpen = (open, trigger) => {
13473
+ this.cancelClose();
13474
+ const dark = open ? !!trigger?.closest(".dark") : this.#state.dark;
13475
+ if (open === this.#state.open && dark === this.#state.dark) return;
13476
+ this.#state = {
13477
+ open,
13478
+ dark
13479
+ };
13480
+ for (const listener of this.#listeners) listener();
13481
+ };
13482
+ /** The pointer reached the trigger: opens, except for touch or disabled. */
13483
+ pointerEnter = ({ pointerType, disabled = false, trigger }) => {
13484
+ if (disabled || pointerType === "touch") return;
13485
+ this.#openedByHover = true;
13486
+ this.setOpen(true, trigger);
13487
+ };
13488
+ /** The keyboard used the trigger or the menu: keep it open on leave. */
13489
+ keyboardUsed = () => {
13490
+ this.#openedByHover = false;
13491
+ };
13492
+ /** The pointer left the trigger or the menu: close soon if hover opened it. */
13493
+ scheduleClose = () => {
13494
+ this.cancelClose();
13495
+ this.#timer = setTimeout(() => {
13496
+ this.#timer = void 0;
13497
+ if (this.#openedByHover) this.setOpen(false);
13498
+ }, this.#closeDelayMs);
13499
+ };
13500
+ /** The pointer came back: keep the menu open. */
13501
+ cancelClose = () => {
13502
+ if (this.#timer === void 0) return;
13503
+ clearTimeout(this.#timer);
13504
+ this.#timer = void 0;
13505
+ };
13506
+ /** Stops a pending close. */
13507
+ dispose = () => {
13508
+ this.cancelClose();
13509
+ };
13510
+ };
13511
+
12492
13512
  //#endregion
12493
13513
  //#region src/open-generative-ui/content.ts
12494
13514
  /**
@@ -12915,6 +13935,28 @@ var OpenGenerativeUIController = class {
12915
13935
  }
12916
13936
  };
12917
13937
 
13938
+ //#endregion
13939
+ //#region src/utils/class-names.ts
13940
+ /**
13941
+ * Joins class names, skipping falsy values. Takes the same inputs as `clsx`.
13942
+ * Classes are not merged: every rule CopilotKit ships sits in `:where()`, so a
13943
+ * class the app adds wins without removing ours.
13944
+ */
13945
+ function cn(...inputs) {
13946
+ const out = [];
13947
+ for (const input of inputs) {
13948
+ if (!input) continue;
13949
+ if (typeof input === "string" || typeof input === "number" || typeof input === "bigint") out.push(String(input));
13950
+ else if (Array.isArray(input)) {
13951
+ const nested = cn(...input);
13952
+ if (nested) out.push(nested);
13953
+ } else if (typeof input === "object") {
13954
+ for (const key in input) if (input[key]) out.push(key);
13955
+ }
13956
+ }
13957
+ return out.join(" ");
13958
+ }
13959
+
12918
13960
  //#endregion
12919
13961
  exports.A2UI_FENCE_LANGUAGE = A2UI_FENCE_LANGUAGE;
12920
13962
  exports.AgentRegistry = AgentRegistry;
@@ -12977,12 +14019,26 @@ exports.segmentSurfaceProse = segmentSurfaceProse;
12977
14019
  exports.select = select;
12978
14020
  exports.splitA2UIMarkdown = splitA2UIMarkdown;
12979
14021
  exports.ɵCOPILOTKIT_FEATURES = ɵCOPILOTKIT_FEATURES;
14022
+ exports.ɵCOPY_FEEDBACK_RESET_MS = ɵCOPY_FEEDBACK_RESET_MS;
14023
+ exports.ɵCopyFeedback = ɵCopyFeedback;
14024
+ exports.ɵFEEDBACK_COMMENT_CLOSE_DELAY_MS = ɵFEEDBACK_COMMENT_CLOSE_DELAY_MS;
14025
+ exports.ɵFeedbackCommentController = ɵFeedbackCommentController;
14026
+ exports.ɵHOVER_MENU_CLOSE_DELAY_MS = ɵHOVER_MENU_CLOSE_DELAY_MS;
14027
+ exports.ɵHoverMenuController = ɵHoverMenuController;
14028
+ exports.ɵINLINE_FEATURE_WARNING_STYLE = ɵINLINE_FEATURE_WARNING_STYLE;
12980
14029
  exports.ɵInterruptState = ɵInterruptState;
14030
+ exports.ɵKEYBOARD_OPEN_THRESHOLD_PX = ɵKEYBOARD_OPEN_THRESHOLD_PX;
14031
+ exports.ɵLICENSE_BANNER_OFFSET = ɵLICENSE_BANNER_OFFSET;
14032
+ exports.ɵLICENSE_BANNER_STYLE = ɵLICENSE_BANNER_STYLE;
12981
14033
  exports.ɵMAX_SOCKET_RETRIES = ɵMAX_SOCKET_RETRIES;
14034
+ exports.ɵMESSAGE_FEEDBACK_EVENT_NAME = ɵMESSAGE_FEEDBACK_EVENT_NAME;
14035
+ exports.ɵMESSAGE_FEEDBACK_MAX_COMMENT_LENGTH = ɵMESSAGE_FEEDBACK_MAX_COMMENT_LENGTH;
14036
+ exports.ɵMOBILE_MAX_WIDTH_QUERY = ɵMOBILE_MAX_WIDTH_QUERY;
12982
14037
  exports.ɵOpenGenerativeUIController = OpenGenerativeUIController;
12983
14038
  exports.ɵRUNTIME_PROBE_TIMEOUT_MS = ɵRUNTIME_PROBE_TIMEOUT_MS;
12984
14039
  exports.ɵTHREAD_REQUEST_TIMEOUT_MS = ɵTHREAD_REQUEST_TIMEOUT_MS;
12985
14040
  exports.ɵclearAgentInterruptState = ɵclearAgentInterruptState;
14041
+ exports.ɵcn = cn;
12986
14042
  exports.ɵcomposerButtonState = ɵcomposerButtonState;
12987
14043
  exports.ɵcopilotIconSvgAttributes = ɵcopilotIconSvgAttributes;
12988
14044
  exports.ɵcopilotIcons = ɵcopilotIcons;
@@ -12992,23 +14048,40 @@ exports.ɵcreateThreadSelectors = ɵcreateThreadSelectors;
12992
14048
  exports.ɵcreateThreadStore = createThreadStore;
12993
14049
  exports.ɵdeduplicateMessages = ɵdeduplicateMessages;
12994
14050
  exports.ɵextractCompleteStyles = extractCompleteStyles;
14051
+ exports.ɵflattenUserMessageContent = ɵflattenUserMessageContent;
12995
14052
  exports.ɵformatCountLabel = ɵformatCountLabel;
12996
14053
  exports.ɵformatLabel = ɵformatLabel;
12997
14054
  exports.ɵformatReasoningDuration = formatReasoningDuration;
14055
+ exports.ɵformatReasoningDurationLabel = ɵformatReasoningDurationLabel;
12998
14056
  exports.ɵformatToolNames = formatToolNames;
12999
14057
  exports.ɵformatWorkDuration = formatWorkDuration;
13000
14058
  exports.ɵgetAgentInterruptState = ɵgetAgentInterruptState;
13001
14059
  exports.ɵgetArgumentPreview = getArgumentPreview;
14060
+ exports.ɵgetBranchNavState = ɵgetBranchNavState;
14061
+ exports.ɵgetInlineFeatureWarningSpec = ɵgetInlineFeatureWarningSpec;
13002
14062
  exports.ɵgetLatestTurnKey = getLatestTurnKey;
14063
+ exports.ɵgetLicenseBannerSpec = ɵgetLicenseBannerSpec;
14064
+ exports.ɵgetMessageFeedback = ɵgetMessageFeedback;
14065
+ exports.ɵgetMessageFeedbackControls = ɵgetMessageFeedbackControls;
13003
14066
  exports.ɵgetToolCallLayouts = getToolCallLayouts;
13004
14067
  exports.ɵgetToolCallPreview = getToolCallPreview;
13005
14068
  exports.ɵgetToolCallRendererNames = getToolCallRendererNames;
13006
14069
  exports.ɵgetToolCallRowStatus = getToolCallRowStatus;
13007
14070
  exports.ɵgetToolResults = getToolResults;
13008
14071
  exports.ɵgetTurnWork = getTurnWork;
14072
+ exports.ɵgetUserMessageMediaFilename = ɵgetUserMessageMediaFilename;
14073
+ exports.ɵgetUserMessageMediaParts = ɵgetUserMessageMediaParts;
13009
14074
  exports.ɵgetWorkOpenState = getWorkOpenState;
14075
+ exports.ɵgetWorkSummaryText = ɵgetWorkSummaryText;
14076
+ exports.ɵhasAssistantMessageText = ɵhasAssistantMessageText;
14077
+ exports.ɵinitialKeyboardState = ɵinitialKeyboardState;
14078
+ exports.ɵinspectorKiteFill = ɵinspectorKiteFill;
14079
+ exports.ɵinspectorKiteIcon = ɵinspectorKiteIcon;
14080
+ exports.ɵinspectorShortcuts = ɵinspectorShortcuts;
13010
14081
  exports.ɵisCopilotKitFeature = ɵisCopilotKitFeature;
13011
14082
  exports.ɵisHttpAgent = ɵisHttpAgent;
14083
+ exports.ɵisLearningFeedbackEnabled = ɵisLearningFeedbackEnabled;
14084
+ exports.ɵisMobileViewport = ɵisMobileViewport;
13012
14085
  exports.ɵisRetryableMemoryStatus = isRetryableStatus;
13013
14086
  exports.ɵisTurnWorkOpen = isTurnWorkOpen;
13014
14087
  exports.ɵisTurnWorking = isTurnWorking;
@@ -13020,15 +14093,20 @@ exports.ɵmemoryDomainEvents = ɵmemoryDomainEvents;
13020
14093
  exports.ɵmemoryReducer = ɵmemoryReducer;
13021
14094
  exports.ɵmemoryRestEvents = ɵmemoryRestEvents;
13022
14095
  exports.ɵmessagesFingerprint = ɵmessagesFingerprint;
14096
+ exports.ɵnormalizeAutoScroll = ɵnormalizeAutoScroll;
13023
14097
  exports.ɵobservePhoenixEvent$ = ɵobservePhoenixEvent$;
13024
14098
  exports.ɵobservePhoenixJoinOutcome$ = ɵobservePhoenixJoinOutcome$;
13025
14099
  exports.ɵobservePhoenixSocketHealth$ = ɵobservePhoenixSocketHealth$;
13026
14100
  exports.ɵobservePhoenixSocketSignals$ = ɵobservePhoenixSocketSignals$;
13027
14101
  exports.ɵphoenixChannel$ = ɵphoenixChannel$;
13028
14102
  exports.ɵphoenixSocket$ = ɵphoenixSocket$;
14103
+ exports.ɵpinMessageToTop = ɵpinMessageToTop;
13029
14104
  exports.ɵpluralize = pluralize;
13030
14105
  exports.ɵprocessPartialHtml = processPartialHtml;
14106
+ exports.ɵreadKeyboardState = ɵreadKeyboardState;
13031
14107
  exports.ɵrecordWorkTime = recordWorkTime;
14108
+ exports.ɵreserveLicenseBannerOffset = ɵreserveLicenseBannerOffset;
14109
+ exports.ɵresetMessageFeedbackCache = ɵresetMessageFeedbackCache;
13032
14110
  exports.ɵresolveActivityRenderer = ɵresolveActivityRenderer;
13033
14111
  exports.ɵresolveComposerKey = ɵresolveComposerKey;
13034
14112
  exports.ɵresolveCustomMessageRenderers = ɵresolveCustomMessageRenderers;
@@ -13048,9 +14126,16 @@ exports.ɵselectMemoriesRealtimeStatus = ɵselectMemoriesRealtimeStatus;
13048
14126
  exports.ɵselectThreads = ɵselectThreads;
13049
14127
  exports.ɵselectThreadsError = ɵselectThreadsError;
13050
14128
  exports.ɵselectThreadsIsLoading = ɵselectThreadsIsLoading;
14129
+ exports.ɵsetMessageFeedback = ɵsetMessageFeedback;
14130
+ exports.ɵshallowEqualRecord = shallowEqualRecord;
14131
+ exports.ɵshouldShowAssistantToolbar = ɵshouldShowAssistantToolbar;
13051
14132
  exports.ɵstringifyToolCallPayload = stringifyToolCallPayload;
14133
+ exports.ɵsubscribeToLearningFeedbackEnabled = ɵsubscribeToLearningFeedbackEnabled;
14134
+ exports.ɵsubscribeToMessageFeedback = ɵsubscribeToMessageFeedback;
13052
14135
  exports.ɵthreadAdapterEvents = ɵthreadAdapterEvents;
13053
14136
  exports.ɵtranscribeAudio = ɵtranscribeAudio;
13054
14137
  exports.ɵtranscriptionErrorMessageKey = ɵtranscriptionErrorMessageKey;
14138
+ exports.ɵwatchKeyboardState = ɵwatchKeyboardState;
14139
+ exports.ɵwatchMobileViewport = ɵwatchMobileViewport;
13055
14140
  exports.ɵwithHeaderDefaults = ɵwithHeaderDefaults;
13056
14141
  //# sourceMappingURL=index.cjs.map