@runtypelabs/persona 4.34.0 → 4.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/dist/activity-ui.d.cts +3 -3
  2. package/dist/activity-ui.d.ts +3 -3
  3. package/dist/animations/glyph-cycle.d.cts +1 -1
  4. package/dist/animations/glyph-cycle.d.ts +1 -1
  5. package/dist/animations/wipe.d.cts +1 -1
  6. package/dist/animations/wipe.d.ts +1 -1
  7. package/dist/approval-ui.d.cts +3 -3
  8. package/dist/approval-ui.d.ts +3 -3
  9. package/dist/artifacts-ui.d.cts +3 -3
  10. package/dist/artifacts-ui.d.ts +3 -3
  11. package/dist/background-runtime.d.cts +1 -1
  12. package/dist/background-runtime.d.ts +1 -1
  13. package/dist/{chunk-CxNPSY-b.js → chunk-B1P8w9_X.js} +1 -1
  14. package/dist/{chunk-CV8EPIhT.js → chunk-B30Jdgg6.js} +1 -1
  15. package/dist/{chunk-6CUrH_jm.js → chunk-Bzo9GaAi.js} +1 -1
  16. package/dist/chunk-CNBMBx-Y.js +2 -0
  17. package/dist/chunk-Cd8mp8Sv.js +1 -0
  18. package/dist/chunk-CsfE8WRG.js +1 -0
  19. package/dist/{chunk-Co3VVwGe.js → chunk-D2pHRNEq.js} +0 -0
  20. package/dist/chunk-D3kZO8u-.js +1 -0
  21. package/dist/chunk-DAthf5H3.js +1 -0
  22. package/dist/{chunk-YMkMvAsa.js → chunk-DZ_aillY.js} +1 -1
  23. package/dist/{chunk-6C23QQdP.js → chunk-DgJV9zbK.js} +1 -1
  24. package/dist/chunk-Dv6KtIT1.js +1 -0
  25. package/dist/chunk-Dws8IrdR.js +1 -0
  26. package/dist/{chunk-DsWv3EGF.js → chunk-ThxxD8oK.js} +1 -1
  27. package/dist/client-dispatch.js +1 -1
  28. package/dist/client-history.js +1 -1
  29. package/dist/codegen.cjs +1 -1
  30. package/dist/codegen.js +1 -1
  31. package/dist/composer-actions-runtime.cjs +1 -1
  32. package/dist/composer-actions-runtime.d.cts +3 -3
  33. package/dist/composer-actions-runtime.d.ts +3 -3
  34. package/dist/composer-actions-runtime.js +1 -1
  35. package/dist/{composer-input-i_FiUp6J.d.cts → composer-input-BSDNPOqV.d.cts} +1 -1
  36. package/dist/{composer-input-i_FiUp6J.d.ts → composer-input-BSDNPOqV.d.ts} +1 -1
  37. package/dist/{composer-store-DhGNgG7Z.d.cts → composer-store-DC-gAjtN.d.cts} +1 -1
  38. package/dist/{composer-store-DhGNgG7Z.d.ts → composer-store-DC-gAjtN.d.ts} +1 -1
  39. package/dist/{context-mention-manager-DL-xwGfL.d.cts → context-mention-manager-CCpeoGL2.d.cts} +2 -2
  40. package/dist/{context-mention-manager-DL-xwGfL.d.ts → context-mention-manager-CCpeoGL2.d.ts} +2 -2
  41. package/dist/context-mentions-inline.d.cts +2 -2
  42. package/dist/context-mentions-inline.d.ts +2 -2
  43. package/dist/context-mentions.cjs +1 -1
  44. package/dist/context-mentions.d.cts +3 -3
  45. package/dist/context-mentions.d.ts +3 -3
  46. package/dist/context-mentions.js +1 -1
  47. package/dist/{defaults-Bga2Xrsp.d.cts → defaults-tj5RcN8r.d.cts} +1 -1
  48. package/dist/{defaults-Bga2Xrsp.d.ts → defaults-tj5RcN8r.d.ts} +1 -1
  49. package/dist/dictation-runtime.d.cts +2 -2
  50. package/dist/dictation-runtime.d.ts +2 -2
  51. package/dist/event-stream-view.d.cts +1 -1
  52. package/dist/event-stream-view.d.ts +1 -1
  53. package/dist/{fallback-speech-engine-kLdyPcmk.d.cts → fallback-speech-engine-gkhbjLiZ.d.cts} +1 -1
  54. package/dist/{fallback-speech-engine-kLdyPcmk.d.ts → fallback-speech-engine-gkhbjLiZ.d.ts} +1 -1
  55. package/dist/{feature-preferences-CmwZGKrf.d.cts → feature-preferences-CerDWGZ7.d.cts} +1 -1
  56. package/dist/{feature-preferences-CmwZGKrf.d.ts → feature-preferences-CerDWGZ7.d.ts} +1 -1
  57. package/dist/forms-ui.d.cts +2 -2
  58. package/dist/forms-ui.d.ts +2 -2
  59. package/dist/{history-confirm-dialog-i46-lPN_.d.cts → history-confirm-dialog-CrkSB3Ra.d.cts} +1 -1
  60. package/dist/{history-confirm-dialog-i46-lPN_.d.ts → history-confirm-dialog-CrkSB3Ra.d.ts} +1 -1
  61. package/dist/history-shell.d.cts +6 -6
  62. package/dist/history-shell.d.ts +6 -6
  63. package/dist/history-view.d.cts +1 -1
  64. package/dist/history-view.d.ts +1 -1
  65. package/dist/index.cjs +32 -32
  66. package/dist/index.cjs.map +1 -1
  67. package/dist/index.d.cts +8 -8
  68. package/dist/index.d.ts +8 -8
  69. package/dist/index.global.js +1 -1
  70. package/dist/index.global.js.map +1 -1
  71. package/dist/index.js +40 -40
  72. package/dist/index.js.map +1 -1
  73. package/dist/install.global.js +1 -1
  74. package/dist/launcher.global.js +1 -1
  75. package/dist/{loading-label-runtime-loader-Ccr3ETd3.d.cts → loading-label-runtime-loader-fWIRrhUF.d.cts} +1 -1
  76. package/dist/{loading-label-runtime-loader-Ccr3ETd3.d.ts → loading-label-runtime-loader-fWIRrhUF.d.ts} +1 -1
  77. package/dist/loading-label-runtime.d.cts +1 -1
  78. package/dist/loading-label-runtime.d.ts +1 -1
  79. package/dist/{message-bubble-C6AVaH7f.d.cts → message-bubble-Czc0lOHr.d.cts} +1 -1
  80. package/dist/{message-bubble-C6AVaH7f.d.ts → message-bubble-Czc0lOHr.d.ts} +1 -1
  81. package/dist/{plugin-kit-BVggqE3C.d.cts → plugin-kit-C30jE-cw.d.cts} +3 -1
  82. package/dist/{plugin-kit-BVggqE3C.d.ts → plugin-kit-C30jE-cw.d.ts} +3 -1
  83. package/dist/plugin-kit.cjs +1 -1
  84. package/dist/plugin-kit.d.cts +1 -1
  85. package/dist/plugin-kit.d.ts +1 -1
  86. package/dist/plugin-kit.js +1 -1
  87. package/dist/preferences-runtime.d.cts +1 -1
  88. package/dist/preferences-runtime.d.ts +1 -1
  89. package/dist/{preview-BMdRffo4.d.cts → preview-D-osV3FU.d.cts} +2 -2
  90. package/dist/{preview-BMdRffo4.d.ts → preview-D-osV3FU.d.ts} +2 -2
  91. package/dist/{registry-B16l8s1b.d.cts → registry-B6w91tx0.d.cts} +1 -1
  92. package/dist/{registry-B16l8s1b.d.ts → registry-B6w91tx0.d.ts} +1 -1
  93. package/dist/{session-CtZHe7fc.d.cts → session-BUQrs3Of.d.cts} +10 -9
  94. package/dist/{session-CtZHe7fc.d.ts → session-BUQrs3Of.d.ts} +10 -9
  95. package/dist/session-reconnect.d.cts +2 -2
  96. package/dist/session-reconnect.d.ts +2 -2
  97. package/dist/smart-dom-reader.d.cts +1 -1
  98. package/dist/smart-dom-reader.d.ts +1 -1
  99. package/dist/theme-editor-preview.cjs +43 -43
  100. package/dist/theme-editor-preview.d.cts +1 -1
  101. package/dist/theme-editor-preview.d.ts +1 -1
  102. package/dist/theme-editor-preview.js +3 -3
  103. package/dist/theme-editor.d.cts +2 -2
  104. package/dist/theme-editor.d.ts +2 -2
  105. package/dist/theme-reference.d.cts +2 -2
  106. package/dist/theme-reference.d.ts +2 -2
  107. package/dist/{tool-loading-animation-D2cyFvmM.d.cts → tool-loading-animation-B7XUf8TN.d.cts} +1 -1
  108. package/dist/{tool-loading-animation-D2cyFvmM.d.ts → tool-loading-animation-B7XUf8TN.d.ts} +1 -1
  109. package/dist/{turn-activity-ui-Do1Nd-Ow.d.cts → turn-activity-ui-CohuNMHT.d.cts} +2 -2
  110. package/dist/{turn-activity-ui-Do1Nd-Ow.d.ts → turn-activity-ui-CohuNMHT.d.ts} +2 -2
  111. package/dist/turn-activity-ui.d.cts +1 -1
  112. package/dist/turn-activity-ui.d.ts +1 -1
  113. package/dist/{types-BC7MRxO5.d.cts → types-9i0xcAMT.d.cts} +52 -0
  114. package/dist/{types-BC7MRxO5.d.ts → types-9i0xcAMT.d.ts} +52 -0
  115. package/dist/voice-client-tools.d.cts +1 -1
  116. package/dist/voice-client-tools.d.ts +1 -1
  117. package/dist/voice-runtime.cjs +1 -1
  118. package/dist/voice-runtime.d.cts +2 -2
  119. package/dist/voice-runtime.d.ts +2 -2
  120. package/dist/voice-runtime.js +1 -1
  121. package/dist/voice-worklet-player.d.cts +2 -2
  122. package/dist/voice-worklet-player.d.ts +2 -2
  123. package/dist/{webmcp-runtime-entry-B8g46vS0.d.ts → webmcp-runtime-entry-XNaXa-9h.d.cts} +9 -1
  124. package/dist/{webmcp-runtime-entry-B8g46vS0.d.cts → webmcp-runtime-entry-XNaXa-9h.d.ts} +9 -1
  125. package/dist/webmcp-runtime.cjs +1 -1
  126. package/dist/webmcp-runtime.d.cts +1 -1
  127. package/dist/webmcp-runtime.d.ts +1 -1
  128. package/dist/webmcp-runtime.js +1 -1
  129. package/package.json +2 -2
  130. package/src/client-dispatch.ts +13 -0
  131. package/src/client.ts +37 -2
  132. package/src/client.webmcp-require-confirm.test.ts +212 -0
  133. package/src/components/composer-model-picker.ts +0 -14
  134. package/src/components/composer-overflow-menu.ts +0 -15
  135. package/src/components/composer-tokens.ts +0 -20
  136. package/src/generated/runtype-openapi-contract.ts +13 -0
  137. package/src/plugin-kit.test.ts +101 -0
  138. package/src/plugin-kit.ts +29 -1
  139. package/src/session.ts +6 -2
  140. package/src/session.webmcp.test.ts +32 -0
  141. package/src/types.ts +35 -0
  142. package/src/ui.composer-models.test.ts +5 -7
  143. package/src/ui.composer-overflow.test.ts +14 -21
  144. package/src/utils/context-mention-controller.test.ts +56 -0
  145. package/src/webmcp-bridge.test.ts +102 -0
  146. package/src/webmcp-runtime-entry.ts +29 -1
  147. package/dist/chunk-BAkaTZpd.js +0 -1
  148. package/dist/chunk-BEDTp-dm.js +0 -1
  149. package/dist/chunk-C-rux8Q9.js +0 -1
  150. package/dist/chunk-CNhThrLX.js +0 -1
  151. package/dist/chunk-CzLEhoB_.js +0 -2
  152. package/dist/chunk-Dqa_GOcj.js +0 -1
  153. package/dist/chunk-NUNdcnAZ.js +0 -1
@@ -1,6 +1,6 @@
1
- import { Ct as AgentWidgetMessage, ja as renderLucideIcon, k as AgentWidgetConfig } from "./types-BC7MRxO5.cjs";
2
- import { a as hasExplicitThemeStyle$1, c as updateActivityElapsed, i as getExplicitLegacyStyle$1, n as TurnActivityRuntime, o as groupToolRows, s as ActivityKind } from "./turn-activity-ui-Do1Nd-Ow.cjs";
3
- import { t as LoadingLabelRuntime } from "./loading-label-runtime-loader-Ccr3ETd3.cjs";
1
+ import { Ct as AgentWidgetMessage, ja as renderLucideIcon, k as AgentWidgetConfig } from "./types-9i0xcAMT.cjs";
2
+ import { a as hasExplicitThemeStyle$1, c as updateActivityElapsed, i as getExplicitLegacyStyle$1, n as TurnActivityRuntime, o as groupToolRows, s as ActivityKind } from "./turn-activity-ui-CohuNMHT.cjs";
3
+ import { t as LoadingLabelRuntime } from "./loading-label-runtime-loader-fWIRrhUF.cjs";
4
4
  export declare const updateToolBubbleUI: (messageId: string, bubble: HTMLElement, expansionState: Set<string>, config?: AgentWidgetConfig) => void;
5
5
  export declare const createToolBubble: (message: AgentWidgetMessage, config?: AgentWidgetConfig, expansionState?: Set<string>) => HTMLElement;
6
6
  export declare const updateReasoningBubbleUI: (messageId: string, bubble: HTMLElement, expansionState: Set<string>, config?: AgentWidgetConfig) => void;
@@ -1,6 +1,6 @@
1
- import { Ct as AgentWidgetMessage, ja as renderLucideIcon, k as AgentWidgetConfig } from "./types-BC7MRxO5.js";
2
- import { a as hasExplicitThemeStyle$1, c as updateActivityElapsed, i as getExplicitLegacyStyle$1, n as TurnActivityRuntime, o as groupToolRows, s as ActivityKind } from "./turn-activity-ui-Do1Nd-Ow.js";
3
- import { t as LoadingLabelRuntime } from "./loading-label-runtime-loader-Ccr3ETd3.js";
1
+ import { Ct as AgentWidgetMessage, ja as renderLucideIcon, k as AgentWidgetConfig } from "./types-9i0xcAMT.js";
2
+ import { a as hasExplicitThemeStyle$1, c as updateActivityElapsed, i as getExplicitLegacyStyle$1, n as TurnActivityRuntime, o as groupToolRows, s as ActivityKind } from "./turn-activity-ui-CohuNMHT.js";
3
+ import { t as LoadingLabelRuntime } from "./loading-label-runtime-loader-fWIRrhUF.js";
4
4
  export declare const updateToolBubbleUI: (messageId: string, bubble: HTMLElement, expansionState: Set<string>, config?: AgentWidgetConfig) => void;
5
5
  export declare const createToolBubble: (message: AgentWidgetMessage, config?: AgentWidgetConfig, expansionState?: Set<string>) => HTMLElement;
6
6
  export declare const updateReasoningBubbleUI: (messageId: string, bubble: HTMLElement, expansionState: Set<string>, config?: AgentWidgetConfig) => void;
@@ -1,4 +1,4 @@
1
- import { Qi as StreamAnimationPlugin } from "../types-BC7MRxO5.cjs";
1
+ import { Qi as StreamAnimationPlugin } from "../types-9i0xcAMT.cjs";
2
2
  export declare const glyphCycle: StreamAnimationPlugin;
3
3
  export { glyphCycle as default };
4
4
  export {}
@@ -1,4 +1,4 @@
1
- import { Qi as StreamAnimationPlugin } from "../types-BC7MRxO5.js";
1
+ import { Qi as StreamAnimationPlugin } from "../types-9i0xcAMT.js";
2
2
  export declare const glyphCycle: StreamAnimationPlugin;
3
3
  export { glyphCycle as default };
4
4
  export {}
@@ -1,4 +1,4 @@
1
- import { Qi as StreamAnimationPlugin } from "../types-BC7MRxO5.cjs";
1
+ import { Qi as StreamAnimationPlugin } from "../types-9i0xcAMT.cjs";
2
2
  export declare const wipe: StreamAnimationPlugin;
3
3
  export { wipe as default };
4
4
  export {}
@@ -1,4 +1,4 @@
1
- import { Qi as StreamAnimationPlugin } from "../types-BC7MRxO5.js";
1
+ import { Qi as StreamAnimationPlugin } from "../types-9i0xcAMT.js";
2
2
  export declare const wipe: StreamAnimationPlugin;
3
3
  export { wipe as default };
4
4
  export {}
@@ -1,6 +1,6 @@
1
- import { Ct as AgentWidgetMessage, Ro as AgentWidgetPlugin, ja as renderLucideIcon, k as AgentWidgetConfig } from "./types-BC7MRxO5.cjs";
2
- import { i as MessageTransform } from "./message-bubble-C6AVaH7f.cjs";
3
- import { i as createPopover, s as isEditableEventTarget } from "./plugin-kit-BVggqE3C.cjs";
1
+ import { Ct as AgentWidgetMessage, Ro as AgentWidgetPlugin, ja as renderLucideIcon, k as AgentWidgetConfig } from "./types-9i0xcAMT.cjs";
2
+ import { i as MessageTransform } from "./message-bubble-Czc0lOHr.cjs";
3
+ import { i as createPopover, s as isEditableEventTarget } from "./plugin-kit-C30jE-cw.cjs";
4
4
  import { IconNode } from "lucide";
5
5
  /**
6
6
  * Turn a wire tool name into a user-facing label: strips the `webmcp:`
@@ -1,6 +1,6 @@
1
- import { Ct as AgentWidgetMessage, Ro as AgentWidgetPlugin, ja as renderLucideIcon, k as AgentWidgetConfig } from "./types-BC7MRxO5.js";
2
- import { i as MessageTransform } from "./message-bubble-C6AVaH7f.js";
3
- import { i as createPopover, s as isEditableEventTarget } from "./plugin-kit-BVggqE3C.js";
1
+ import { Ct as AgentWidgetMessage, Ro as AgentWidgetPlugin, ja as renderLucideIcon, k as AgentWidgetConfig } from "./types-9i0xcAMT.js";
2
+ import { i as MessageTransform } from "./message-bubble-Czc0lOHr.js";
3
+ import { i as createPopover, s as isEditableEventTarget } from "./plugin-kit-C30jE-cw.js";
4
4
  import { IconNode } from "lucide";
5
5
  /**
6
6
  * Turn a wire tool name into a user-facing label: strips the `webmcp:`
@@ -1,6 +1,6 @@
1
- import { T as provideMarkdownParsers, f as buttons_d_exports, r as ComponentRenderer, t as ComponentContext } from "./registry-B16l8s1b.cjs";
2
- import { Li as PersonaArtifactRecord, Mi as PersonaArtifactFileMeta, Oi as PersonaArtifactCustomAction, k as AgentWidgetConfig } from "./types-BC7MRxO5.cjs";
3
- import { t as LoadingLabelRuntime } from "./loading-label-runtime-loader-Ccr3ETd3.cjs";
1
+ import { T as provideMarkdownParsers, f as buttons_d_exports, r as ComponentRenderer, t as ComponentContext } from "./registry-B6w91tx0.cjs";
2
+ import { Li as PersonaArtifactRecord, Mi as PersonaArtifactFileMeta, Oi as PersonaArtifactCustomAction, k as AgentWidgetConfig } from "./types-9i0xcAMT.cjs";
3
+ import { t as LoadingLabelRuntime } from "./loading-label-runtime-loader-fWIRrhUF.cjs";
4
4
  import { IconNode } from "lucide";
5
5
  type ArtifactPaneApi = {
6
6
  element: HTMLElement;
@@ -1,6 +1,6 @@
1
- import { T as provideMarkdownParsers, f as buttons_d_exports, r as ComponentRenderer, t as ComponentContext } from "./registry-B16l8s1b.js";
2
- import { Li as PersonaArtifactRecord, Mi as PersonaArtifactFileMeta, Oi as PersonaArtifactCustomAction, k as AgentWidgetConfig } from "./types-BC7MRxO5.js";
3
- import { t as LoadingLabelRuntime } from "./loading-label-runtime-loader-Ccr3ETd3.js";
1
+ import { T as provideMarkdownParsers, f as buttons_d_exports, r as ComponentRenderer, t as ComponentContext } from "./registry-B6w91tx0.js";
2
+ import { Li as PersonaArtifactRecord, Mi as PersonaArtifactFileMeta, Oi as PersonaArtifactCustomAction, k as AgentWidgetConfig } from "./types-9i0xcAMT.js";
3
+ import { t as LoadingLabelRuntime } from "./loading-label-runtime-loader-fWIRrhUF.js";
4
4
  import { IconNode } from "lucide";
5
5
  type ArtifactPaneApi = {
6
6
  element: HTMLElement;
@@ -1,4 +1,4 @@
1
- import { Ct as AgentWidgetMessage, Li as PersonaArtifactRecord, Ui as ResumableHandle, Wr as ConversationExecutionState, Xn as BackgroundConversationAdapter, mn as AgentWidgetStreamCheckpoint } from "./types-BC7MRxO5.cjs";
1
+ import { Ct as AgentWidgetMessage, Li as PersonaArtifactRecord, Ui as ResumableHandle, Wr as ConversationExecutionState, Xn as BackgroundConversationAdapter, mn as AgentWidgetStreamCheckpoint } from "./types-9i0xcAMT.cjs";
2
2
  type BackgroundCheckpoint = {
3
3
  conversationId: string;
4
4
  handle: ResumableHandle;
@@ -1,4 +1,4 @@
1
- import { Ct as AgentWidgetMessage, Li as PersonaArtifactRecord, Ui as ResumableHandle, Wr as ConversationExecutionState, Xn as BackgroundConversationAdapter, mn as AgentWidgetStreamCheckpoint } from "./types-BC7MRxO5.js";
1
+ import { Ct as AgentWidgetMessage, Li as PersonaArtifactRecord, Ui as ResumableHandle, Wr as ConversationExecutionState, Xn as BackgroundConversationAdapter, mn as AgentWidgetStreamCheckpoint } from "./types-9i0xcAMT.js";
2
2
  type BackgroundCheckpoint = {
3
3
  conversationId: string;
4
4
  handle: ResumableHandle;
@@ -1 +1 @@
1
- import{t as e}from"./chunk-Dqa_GOcj.js";const t=32768,n=49152,r=e=>{let t=e??{},n=typeof t.targetId==`string`?t.targetId:null;return{id:typeof t.id==`string`?t.id:``,title:typeof t.title==`string`?t.title:``,targetId:n,preview:typeof t.preview==`string`?t.preview:null,messageCount:typeof t.messageCount==`number`?t.messageCount:0,createdAt:typeof t.createdAt==`string`?t.createdAt:``,updatedAt:typeof t.updatedAt==`string`?t.updatedAt:``}},i=`The identity proof was not admitted; account history is unavailable`,a=`The identity proof was rejected`,o=`The request carried no visitor credential`,s=`The stored visitor belongs to a different signed-in user`;function c(e,t,n){let r=new URLSearchParams;for(let[e,t]of Object.entries(n))t!==void 0&&t!==``&&r.set(e,String(t));let i=r.toString();return`${e.clientApiBase()}/v1/client/${t}${i?`?${i}`:``}`}function l(e,t){return t||e.config.features?.history?.scope||(e.config.getIdentityProof?`verified-user`:`browser`)}async function u(e,t,n){let r=e.config.getIdentityProof;if(!r)return n&&e.setHistoryIdentityStatus(e.browserOnlyStatus()),null;n&&e.setHistoryIdentityStatus({state:`verifying`});let i;try{i=await r()??null}catch{throw n&&e.setHistoryIdentityStatus({state:`identity_provider_failed`}),new e.HistoryClientError(`identity_provider_failed`,`The identity proof provider failed`)}if(i)return i;if(t.visitor?.endUserId!=null)throw n&&e.setHistoryIdentityStatus({state:`authentication_required`,reason:`proof_unavailable_after_binding`}),new e.HistoryClientError(`authentication_required`,`This browser is bound to a signed-in user and needs a fresh identity proof`);return n&&e.setHistoryIdentityStatus({state:`browser_only`,reason:`proof_unavailable_before_binding`}),null}async function d(e,t,n,r){if(t.visitor?.endUserId!=null)return t;let a=await e.reinitWithProof(n);if(a.visitor?.identityStatus!==`admitted`||a.visitor?.endUserId==null)throw r&&e.setHistoryIdentityStatus({state:`configuration_error`,reason:`proof_not_admitted`}),new e.HistoryClientError(`proof_not_admitted`,i);return a}async function f(e,t){let n=await t.json().catch(()=>({}));return typeof n.error==`string`?n.error:typeof n.message==`string`?n.message:``}async function p(e,t,n,r){let i=t.toLowerCase();if(i.includes(`invalid_identity_proof`))throw r&&e.setHistoryIdentityStatus({state:`authentication_required`,reason:`invalid_identity_proof`}),new e.HistoryClientError(`invalid_identity_proof`,a);if(i.includes(`visitor token required`))throw new e.HistoryClientError(`visitor_token_missing`,o);if(i.includes(`visitor_identity_mismatch`)){if(!n)throw r&&e.setHistoryIdentityStatus({state:`authentication_required`,reason:`proof_unavailable_after_binding`}),new e.HistoryClientError(`visitor_identity_mismatch`,s);return e.reinitWithProof(n)}if(i.includes(`expired`)||i.includes(`not found`))return e.clearClientSession(),e.initSession();throw new e.HistoryClientError(`unauthorized`,t||`History request was not authorized`)}async function m(e,t,n){let r=await f(e,t);if(t.status===404)return new e.HistoryClientError(`not_found`,`Conversation not found`);if(t.status===429){let n=Number.parseInt(t.headers.get(`Retry-After`)??``,10);return new e.HistoryClientError(`rate_limited`,`Too many history requests`,{...Number.isFinite(n)?{retryAfterSeconds:n}:{}})}if(t.status===503&&r.includes(`identity_proof_not_admitted`))return n&&e.setHistoryIdentityStatus({state:`configuration_error`,reason:`proof_not_admitted`}),new e.HistoryClientError(`proof_not_admitted`,i);if(t.status===401){let t=r.toLowerCase();return t.includes(`invalid_identity_proof`)?(n&&e.setHistoryIdentityStatus({state:`authentication_required`,reason:`invalid_identity_proof`}),new e.HistoryClientError(`invalid_identity_proof`,a)):t.includes(`visitor token required`)?new e.HistoryClientError(`visitor_token_missing`,o):t.includes(`visitor_identity_mismatch`)?new e.HistoryClientError(`visitor_identity_mismatch`,s):new e.HistoryClientError(`unauthorized`,r||`History request was not authorized`)}return new e.HistoryClientError(`request_failed`,r||`History request failed (${t.status})`)}function h(e,t,n,r){let i=t?.toLowerCase()??null;if(n){if(i===`admitted`){r&&e.setHistoryIdentityStatus({state:`verified`});return}throw r&&e.setHistoryIdentityStatus({state:`configuration_error`,reason:`proof_not_admitted`}),i===`ignored`?new e.HistoryClientError(`identity_contract_violation`,`Server reported an ignored identity proof on a success response`):new e.HistoryClientError(`proof_not_admitted`,`The response did not acknowledge the identity proof this request sent`)}if(i===`admitted`)throw new e.HistoryClientError(`identity_contract_violation`,`Server admitted an identity proof that was never sent`);r&&e.setHistoryIdentityStatus(e.browserOnlyStatus())}async function g(t,n,r){_(t);let i=r.trackIdentity!==!1,a=await t.initSession(),o=null;l(t,r.scope)===`verified-user`&&(o=await u(t,a,i),o&&(a=await d(t,a,o,i)));let s=t.historyInternals.visitorStore,g=!1;for(;;){let l=s?.revision()??0,u=await t.readVisitorToken();if(!u&&!r.visitorTokenOptional)throw new t.HistoryClientError(`visitor_token_missing`,`No visitor credential is stored for this browser`);let d=await fetch(c(t,n,{...r.query,sessionId:a.sessionId}),{method:r.method,headers:{"X-Persona-Version":e,...u?{"X-Visitor-Token":u}:{},...o?{"X-Identity-Proof":o}:{},...r.body===void 0?{}:{"Content-Type":`application/json`}},...r.body===void 0?{}:{body:JSON.stringify(r.body)},...r.keepalive?{keepalive:!0}:{}});if(d.status===401&&!g){g=!0,a=await p(t,await f(t,d),o,i);continue}if(!d.ok)throw await m(t,d,i);let _=d.headers.get(`X-History-Identity-Status`),v=await d.json().catch(()=>void 0);if(s&&s.revision()!==l)throw new t.HistoryClientError(`credential_changed`,`The visitor credential changed while the request was in flight`);return h(t,_,o!==null,i),v}}function _(e){if(!e.isClientTokenMode())throw Error(`Conversation history is only available in client token mode`);if(!e.isHistoryCapable())throw new e.HistoryClientError(`history_disabled`,`Visitor history is disabled for this surface`)}async function v(e,t){let n=await g(e,`conversations`,{method:`GET`,query:{...t?.cursor?{cursor:t.cursor}:{},...t?.limit===void 0?{}:{limit:t.limit},...t?.targetId?{targetId:t.targetId}:{}},...t?.scope?{scope:t.scope}:{}});return{data:(Array.isArray(n?.data)?n.data:[]).map(r),nextCursor:typeof n?.nextCursor==`string`?n.nextCursor:null}}async function y(e,t,n){let i=await g(e,`conversations/${encodeURIComponent(t)}`,{method:`GET`,query:{...n?.messageCursor?{messageCursor:n.messageCursor}:{}},...n?.scope?{scope:n.scope}:{}});return{summary:r(i),messages:Array.isArray(i?.messages)?i.messages:[],nextMessageCursor:typeof i?.nextMessageCursor==`string`?i.nextMessageCursor:null,conversationRevision:typeof i?.conversationRevision==`string`?i.conversationRevision:null}}async function b(e,r,i){_(e);let a=0;for(let n of i){let r=n.displayContent.length;if(r>t)throw new e.HistoryClientError(`payload_too_large`,`displayContent exceeds the ${t} character limit`);a+=r}if(a>n)throw new e.HistoryClientError(`payload_too_large`,`Display projection batch exceeds the ${n} character limit`);await e.initSession();let o=e.historyInternals.visitorStore,s=o?.revision()??0,c=await g(e,`conversations/${encodeURIComponent(r)}/display-projections`,{method:`PATCH`,body:{messages:i},scope:`browser`,keepalive:a<=n,trackIdentity:!1}),l=typeof c?.conversationRevision==`string`?c.conversationRevision:null;return l&&e.clientSession?.conversationId===r&&(o?.revision()??0)===s&&e.historyInternals.setStoredConversationRevision?.(l),{conversationRevision:l}}async function x(e,t,n){let r=await g(e,`conversations/${encodeURIComponent(t)}`,{method:`DELETE`,...n?.scope?{scope:n.scope}:{}});return{deleted:typeof r?.deleted==`number`?r.deleted:0}}async function S(e,t){let n=await g(e,`conversations`,{method:`DELETE`,query:{...t?.targetId===void 0?{}:{targetId:t.targetId}},...t?.scope?{scope:t.scope}:{}});return{deleted:typeof n?.deleted==`number`?n.deleted:0}}async function C(e){_(e),e.setHistoryIdentityStatus({state:`resetting`});try{await g(e,`visitor/reset`,{method:`POST`,scope:`browser`,visitorTokenOptional:!0})}finally{await e.historyInternals.visitorStore?.clear(),e.setHistoryIdentityStatus(e.derivedBrowserOnly())}return{reset:!0}}export{S as deleteAllConversations,x as deleteConversation,b as finalizeDisplayProjections,y as getConversation,m as historyErrorFor,v as listConversations,f as readErrorCode,p as recoverFromUnauthorized,C as resetVisitor};
1
+ import{t as e}from"./chunk-DAthf5H3.js";const t=32768,n=49152,r=e=>{let t=e??{},n=typeof t.targetId==`string`?t.targetId:null;return{id:typeof t.id==`string`?t.id:``,title:typeof t.title==`string`?t.title:``,targetId:n,preview:typeof t.preview==`string`?t.preview:null,messageCount:typeof t.messageCount==`number`?t.messageCount:0,createdAt:typeof t.createdAt==`string`?t.createdAt:``,updatedAt:typeof t.updatedAt==`string`?t.updatedAt:``}},i=`The identity proof was not admitted; account history is unavailable`,a=`The identity proof was rejected`,o=`The request carried no visitor credential`,s=`The stored visitor belongs to a different signed-in user`;function c(e,t,n){let r=new URLSearchParams;for(let[e,t]of Object.entries(n))t!==void 0&&t!==``&&r.set(e,String(t));let i=r.toString();return`${e.clientApiBase()}/v1/client/${t}${i?`?${i}`:``}`}function l(e,t){return t||e.config.features?.history?.scope||(e.config.getIdentityProof?`verified-user`:`browser`)}async function u(e,t,n){let r=e.config.getIdentityProof;if(!r)return n&&e.setHistoryIdentityStatus(e.browserOnlyStatus()),null;n&&e.setHistoryIdentityStatus({state:`verifying`});let i;try{i=await r()??null}catch{throw n&&e.setHistoryIdentityStatus({state:`identity_provider_failed`}),new e.HistoryClientError(`identity_provider_failed`,`The identity proof provider failed`)}if(i)return i;if(t.visitor?.endUserId!=null)throw n&&e.setHistoryIdentityStatus({state:`authentication_required`,reason:`proof_unavailable_after_binding`}),new e.HistoryClientError(`authentication_required`,`This browser is bound to a signed-in user and needs a fresh identity proof`);return n&&e.setHistoryIdentityStatus({state:`browser_only`,reason:`proof_unavailable_before_binding`}),null}async function d(e,t,n,r){if(t.visitor?.endUserId!=null)return t;let a=await e.reinitWithProof(n);if(a.visitor?.identityStatus!==`admitted`||a.visitor?.endUserId==null)throw r&&e.setHistoryIdentityStatus({state:`configuration_error`,reason:`proof_not_admitted`}),new e.HistoryClientError(`proof_not_admitted`,i);return a}async function f(e,t){let n=await t.json().catch(()=>({}));return typeof n.error==`string`?n.error:typeof n.message==`string`?n.message:``}async function p(e,t,n,r){let i=t.toLowerCase();if(i.includes(`invalid_identity_proof`))throw r&&e.setHistoryIdentityStatus({state:`authentication_required`,reason:`invalid_identity_proof`}),new e.HistoryClientError(`invalid_identity_proof`,a);if(i.includes(`visitor token required`))throw new e.HistoryClientError(`visitor_token_missing`,o);if(i.includes(`visitor_identity_mismatch`)){if(!n)throw r&&e.setHistoryIdentityStatus({state:`authentication_required`,reason:`proof_unavailable_after_binding`}),new e.HistoryClientError(`visitor_identity_mismatch`,s);return e.reinitWithProof(n)}if(i.includes(`expired`)||i.includes(`not found`))return e.clearClientSession(),e.initSession();throw new e.HistoryClientError(`unauthorized`,t||`History request was not authorized`)}async function m(e,t,n){let r=await f(e,t);if(t.status===404)return new e.HistoryClientError(`not_found`,`Conversation not found`);if(t.status===429){let n=Number.parseInt(t.headers.get(`Retry-After`)??``,10);return new e.HistoryClientError(`rate_limited`,`Too many history requests`,{...Number.isFinite(n)?{retryAfterSeconds:n}:{}})}if(t.status===503&&r.includes(`identity_proof_not_admitted`))return n&&e.setHistoryIdentityStatus({state:`configuration_error`,reason:`proof_not_admitted`}),new e.HistoryClientError(`proof_not_admitted`,i);if(t.status===401){let t=r.toLowerCase();return t.includes(`invalid_identity_proof`)?(n&&e.setHistoryIdentityStatus({state:`authentication_required`,reason:`invalid_identity_proof`}),new e.HistoryClientError(`invalid_identity_proof`,a)):t.includes(`visitor token required`)?new e.HistoryClientError(`visitor_token_missing`,o):t.includes(`visitor_identity_mismatch`)?new e.HistoryClientError(`visitor_identity_mismatch`,s):new e.HistoryClientError(`unauthorized`,r||`History request was not authorized`)}return new e.HistoryClientError(`request_failed`,r||`History request failed (${t.status})`)}function h(e,t,n,r){let i=t?.toLowerCase()??null;if(n){if(i===`admitted`){r&&e.setHistoryIdentityStatus({state:`verified`});return}throw r&&e.setHistoryIdentityStatus({state:`configuration_error`,reason:`proof_not_admitted`}),i===`ignored`?new e.HistoryClientError(`identity_contract_violation`,`Server reported an ignored identity proof on a success response`):new e.HistoryClientError(`proof_not_admitted`,`The response did not acknowledge the identity proof this request sent`)}if(i===`admitted`)throw new e.HistoryClientError(`identity_contract_violation`,`Server admitted an identity proof that was never sent`);r&&e.setHistoryIdentityStatus(e.browserOnlyStatus())}async function g(t,n,r){_(t);let i=r.trackIdentity!==!1,a=await t.initSession(),o=null;l(t,r.scope)===`verified-user`&&(o=await u(t,a,i),o&&(a=await d(t,a,o,i)));let s=t.historyInternals.visitorStore,g=!1;for(;;){let l=s?.revision()??0,u=await t.readVisitorToken();if(!u&&!r.visitorTokenOptional)throw new t.HistoryClientError(`visitor_token_missing`,`No visitor credential is stored for this browser`);let d=await fetch(c(t,n,{...r.query,sessionId:a.sessionId}),{method:r.method,headers:{"X-Persona-Version":e,...u?{"X-Visitor-Token":u}:{},...o?{"X-Identity-Proof":o}:{},...r.body===void 0?{}:{"Content-Type":`application/json`}},...r.body===void 0?{}:{body:JSON.stringify(r.body)},...r.keepalive?{keepalive:!0}:{}});if(d.status===401&&!g){g=!0,a=await p(t,await f(t,d),o,i);continue}if(!d.ok)throw await m(t,d,i);let _=d.headers.get(`X-History-Identity-Status`),v=await d.json().catch(()=>void 0);if(s&&s.revision()!==l)throw new t.HistoryClientError(`credential_changed`,`The visitor credential changed while the request was in flight`);return h(t,_,o!==null,i),v}}function _(e){if(!e.isClientTokenMode())throw Error(`Conversation history is only available in client token mode`);if(!e.isHistoryCapable())throw new e.HistoryClientError(`history_disabled`,`Visitor history is disabled for this surface`)}async function v(e,t){let n=await g(e,`conversations`,{method:`GET`,query:{...t?.cursor?{cursor:t.cursor}:{},...t?.limit===void 0?{}:{limit:t.limit},...t?.targetId?{targetId:t.targetId}:{}},...t?.scope?{scope:t.scope}:{}});return{data:(Array.isArray(n?.data)?n.data:[]).map(r),nextCursor:typeof n?.nextCursor==`string`?n.nextCursor:null}}async function y(e,t,n){let i=await g(e,`conversations/${encodeURIComponent(t)}`,{method:`GET`,query:{...n?.messageCursor?{messageCursor:n.messageCursor}:{}},...n?.scope?{scope:n.scope}:{}});return{summary:r(i),messages:Array.isArray(i?.messages)?i.messages:[],nextMessageCursor:typeof i?.nextMessageCursor==`string`?i.nextMessageCursor:null,conversationRevision:typeof i?.conversationRevision==`string`?i.conversationRevision:null}}async function b(e,r,i){_(e);let a=0;for(let n of i){let r=n.displayContent.length;if(r>t)throw new e.HistoryClientError(`payload_too_large`,`displayContent exceeds the ${t} character limit`);a+=r}if(a>n)throw new e.HistoryClientError(`payload_too_large`,`Display projection batch exceeds the ${n} character limit`);await e.initSession();let o=e.historyInternals.visitorStore,s=o?.revision()??0,c=await g(e,`conversations/${encodeURIComponent(r)}/display-projections`,{method:`PATCH`,body:{messages:i},scope:`browser`,keepalive:a<=n,trackIdentity:!1}),l=typeof c?.conversationRevision==`string`?c.conversationRevision:null;return l&&e.clientSession?.conversationId===r&&(o?.revision()??0)===s&&e.historyInternals.setStoredConversationRevision?.(l),{conversationRevision:l}}async function x(e,t,n){let r=await g(e,`conversations/${encodeURIComponent(t)}`,{method:`DELETE`,...n?.scope?{scope:n.scope}:{}});return{deleted:typeof r?.deleted==`number`?r.deleted:0}}async function S(e,t){let n=await g(e,`conversations`,{method:`DELETE`,query:{...t?.targetId===void 0?{}:{targetId:t.targetId}},...t?.scope?{scope:t.scope}:{}});return{deleted:typeof n?.deleted==`number`?n.deleted:0}}async function C(e){_(e),e.setHistoryIdentityStatus({state:`resetting`});try{await g(e,`visitor/reset`,{method:`POST`,scope:`browser`,visitorTokenOptional:!0})}finally{await e.historyInternals.visitorStore?.clear(),e.setHistoryIdentityStatus(e.derivedBrowserOnly())}return{reset:!0}}export{S as deleteAllConversations,x as deleteConversation,b as finalizeDisplayProjections,y as getConversation,m as historyErrorFor,v as listConversations,f as readErrorCode,p as recoverFromUnauthorized,C as resetVisitor};
@@ -1,3 +1,3 @@
1
- import{I as e,T as t,n,t as r,w as i}from"./chunk-DsWv3EGF.js";import{r as a}from"./chunk-D5BxWOFB.js";import{a as o,c as s,d as c,f as l,i as u,l as d,n as f,o as p,p as m}from"./chunk-Dj2a9f9w.js";import{n as h,t as g}from"./chunk-Di5V0tA0.js";import{t as _}from"./chunk-D3NN94Ru.js";const v=e=>{let{mount:t,overlay:n,sessionRef:r}=e,i=(i,a,o)=>{let s=a.trim();if(!s||!r.current)return;let c=i.getAttribute(`data-tool-call-id`)??``,u=o.source===`free-text`;t.dispatchEvent(new CustomEvent(`persona:askUserQuestion:answered`,{detail:{instanceId:e.instanceId,toolUseId:c,answer:s,answers:o.structured,values:o.values??(o.source===`multi`?s.split(`, `):[s]),isFreeText:u,source:o.source},bubbles:!0,composed:!0})),l(n,c);let d=r.current.getMessages().find(e=>e.toolCall?.id===c);d?.agentMetadata?.awaitingLocalTool?r.current.resolveAskUserQuestion(d,o.structured??s):r.current.sendMessage(s)},a=e=>{let t=r.current;if(!t)return;let n=e.getAttribute(`data-tool-call-id`)??``,i=t.getMessages().find(e=>e.toolCall?.id===n);i&&t.persistAskUserQuestionProgress(i,{answers:f(e,i),currentIndex:u(e)})},h=e=>Object.entries(e).map(([e,t])=>`${e}: ${Array.isArray(t)?t.join(`, `):t}`).join(` | `),g=t=>{if(e.config().features?.askUserQuestion?.groupedAutoAdvance===!1)return;let n=u(t);if(n>=o(t)-1)return;let i=r.current?.getMessages().find(e=>e.toolCall?.id===t.getAttribute(`data-tool-call-id`));i&&(d(t,i,e.config(),n+1),a(t))};return{click:_=>{let v=_.target.closest(`[data-ask-user-action]`);if(!v)return;let y=v.closest(`[data-persona-ask-sheet-for]`);if(!y)return;let b=v.getAttribute(`data-ask-user-action`);if(_.preventDefault(),_.stopPropagation(),b===`dismiss`){let i=y.getAttribute(`data-tool-call-id`)??``;t.dispatchEvent(new CustomEvent(`persona:askUserQuestion:dismissed`,{detail:{instanceId:e.instanceId,toolUseId:i},bubbles:!0,composed:!0})),l(n,i);let a=r.current?.getMessages().find(e=>e.toolCall?.id===i);a?.agentMetadata?.awaitingLocalTool&&(r.current?.markAskUserQuestionResolved(a),r.current?.resolveAskUserQuestion(a,`(dismissed)`))}else if(b===`pick`){let e=v.getAttribute(`data-option-label`);if(!e)return;let t=y.getAttribute(`data-multi-select`)===`true`,n=s(y);if(n&&t){let t=c(y)[u(y)],n=new Set(Array.isArray(t)?t:[]);n.has(e)?n.delete(e):n.add(e),m(y,Array.from(n)),a(y);return}if(n){m(y,e),a(y),g(y);return}if(t){let e=v.getAttribute(`aria-pressed`)===`true`;v.setAttribute(`aria-pressed`,e?`false`:`true`),v.classList.toggle(`persona-ask-pill-selected`,!e);let t=y.querySelector(`[data-ask-user-action="submit-multi"]`);t&&(t.disabled=p(y).length===0);return}i(y,e,{source:`pick`,values:[e]})}else if(b===`submit-multi`){let e=p(y);if(e.length===0)return;i(y,e.join(`, `),{source:`multi`,values:e})}else if(b===`open-free-text`){let e=y.querySelector(`[data-ask-free-text-row="true"]`);e&&(e.classList.remove(`persona-hidden`),e.querySelector(`[data-ask-free-text-input="true"]`)?.focus())}else if(b===`focus-free-text`)y.querySelector(`[data-ask-free-text-input="true"]`)?.focus();else if(b===`submit-free-text`){let e=y.querySelector(`[data-ask-free-text-input="true"]`)?.value??``;if(!e.trim())return;if(s(y)){m(y,e.trim()),a(y),g(y);return}i(y,e,{source:`free-text`})}else if(b===`next`||b===`back`){if(!r.current)return;let t=y.getAttribute(`data-tool-call-id`)??``,n=r.current.getMessages().find(e=>e.toolCall?.id===t);if(!n)return;let i=y.querySelector(`[data-ask-free-text-input="true"]`)?.value?.trim()??``;if(i){let e=c(y)[u(y)];(typeof e!=`string`||e!==i)&&m(y,i)}let o=b===`next`?1:-1,s=u(y)+o;d(y,n,e.config(),s),a(y)}else if(b===`submit-all`){if(!r.current)return;let e=y.getAttribute(`data-tool-call-id`)??``,t=r.current.getMessages().find(t=>t.toolCall?.id===e);if(!t)return;let n=y.querySelector(`[data-ask-free-text-input="true"]`)?.value?.trim()??``;n&&m(y,n);let a=f(y,t);r.current.persistAskUserQuestionProgress(t,{answers:a,currentIndex:u(y)});let o=h(a);i(y,o||`(submitted)`,{source:`submit-all`,structured:a})}else if(b===`skip`){if(!r.current)return;let c=y.getAttribute(`data-tool-call-id`)??``,p=r.current.getMessages().find(e=>e.toolCall?.id===c);if(!p)return;let g=s(y),_=u(y),v=_>=o(y)-1;if(!g){t.dispatchEvent(new CustomEvent(`persona:askUserQuestion:dismissed`,{detail:{instanceId:e.instanceId,toolUseId:c},bubbles:!0,composed:!0})),l(n,c),p.agentMetadata?.awaitingLocalTool&&(r.current.markAskUserQuestionResolved(p),r.current.resolveAskUserQuestion(p,`(dismissed)`));return}m(y,``);let b=y.querySelector(`[data-ask-free-text-input="true"]`);if(b&&(b.value=``),v){let e=f(y,p),t=h(e);i(y,t||`(skipped)`,{source:`submit-all`,structured:e});return}d(y,p,e.config(),_+1),a(y)}},keydown:e=>{if(e.key!==`Enter`)return;let t=e.target;if(!t.matches?.(`[data-ask-free-text-input="true"]`))return;let n=t.closest(`[data-persona-ask-sheet-for]`);if(!n)return;e.preventDefault();let r=t.value;r.trim()&&(s(n)?(m(n,r.trim()),a(n),g(n)):i(n,r,{source:`free-text`}))}}},y={loadContextMentions:()=>t(),loadContextMentionsInline:()=>i(),renderLucideIcon:(...t)=>e(...t),createMentionButton:(...e)=>n(...e)};function b(e){let{loadContextMentions:t,loadContextMentionsInline:n,renderLucideIcon:i,createMentionButton:o}=e.deps??y,s=e.config.contextMentions;if(!s?.enabled)return null;let c=_(s).filter(e=>e.sources.length>0);if(c.length===0)return typeof console<`u`&&console.warn(`[Persona] contextMentions.enabled is true but no sources were provided; mentions are disabled.`),null;let l=c.filter(e=>e.sources.some(e=>typeof e.matchCommand==`function`)),u=e=>l.some(t=>t.trigger?t.position===`line-start`?e.split(`
1
+ import{I as e,T as t,n,t as r,w as i}from"./chunk-ThxxD8oK.js";import{r as a}from"./chunk-D5BxWOFB.js";import{a as o,c as s,d as c,f as l,i as u,l as d,n as f,o as p,p as m}from"./chunk-Dj2a9f9w.js";import{n as h,t as g}from"./chunk-Di5V0tA0.js";import{t as _}from"./chunk-D3NN94Ru.js";const v=e=>{let{mount:t,overlay:n,sessionRef:r}=e,i=(i,a,o)=>{let s=a.trim();if(!s||!r.current)return;let c=i.getAttribute(`data-tool-call-id`)??``,u=o.source===`free-text`;t.dispatchEvent(new CustomEvent(`persona:askUserQuestion:answered`,{detail:{instanceId:e.instanceId,toolUseId:c,answer:s,answers:o.structured,values:o.values??(o.source===`multi`?s.split(`, `):[s]),isFreeText:u,source:o.source},bubbles:!0,composed:!0})),l(n,c);let d=r.current.getMessages().find(e=>e.toolCall?.id===c);d?.agentMetadata?.awaitingLocalTool?r.current.resolveAskUserQuestion(d,o.structured??s):r.current.sendMessage(s)},a=e=>{let t=r.current;if(!t)return;let n=e.getAttribute(`data-tool-call-id`)??``,i=t.getMessages().find(e=>e.toolCall?.id===n);i&&t.persistAskUserQuestionProgress(i,{answers:f(e,i),currentIndex:u(e)})},h=e=>Object.entries(e).map(([e,t])=>`${e}: ${Array.isArray(t)?t.join(`, `):t}`).join(` | `),g=t=>{if(e.config().features?.askUserQuestion?.groupedAutoAdvance===!1)return;let n=u(t);if(n>=o(t)-1)return;let i=r.current?.getMessages().find(e=>e.toolCall?.id===t.getAttribute(`data-tool-call-id`));i&&(d(t,i,e.config(),n+1),a(t))};return{click:_=>{let v=_.target.closest(`[data-ask-user-action]`);if(!v)return;let y=v.closest(`[data-persona-ask-sheet-for]`);if(!y)return;let b=v.getAttribute(`data-ask-user-action`);if(_.preventDefault(),_.stopPropagation(),b===`dismiss`){let i=y.getAttribute(`data-tool-call-id`)??``;t.dispatchEvent(new CustomEvent(`persona:askUserQuestion:dismissed`,{detail:{instanceId:e.instanceId,toolUseId:i},bubbles:!0,composed:!0})),l(n,i);let a=r.current?.getMessages().find(e=>e.toolCall?.id===i);a?.agentMetadata?.awaitingLocalTool&&(r.current?.markAskUserQuestionResolved(a),r.current?.resolveAskUserQuestion(a,`(dismissed)`))}else if(b===`pick`){let e=v.getAttribute(`data-option-label`);if(!e)return;let t=y.getAttribute(`data-multi-select`)===`true`,n=s(y);if(n&&t){let t=c(y)[u(y)],n=new Set(Array.isArray(t)?t:[]);n.has(e)?n.delete(e):n.add(e),m(y,Array.from(n)),a(y);return}if(n){m(y,e),a(y),g(y);return}if(t){let e=v.getAttribute(`aria-pressed`)===`true`;v.setAttribute(`aria-pressed`,e?`false`:`true`),v.classList.toggle(`persona-ask-pill-selected`,!e);let t=y.querySelector(`[data-ask-user-action="submit-multi"]`);t&&(t.disabled=p(y).length===0);return}i(y,e,{source:`pick`,values:[e]})}else if(b===`submit-multi`){let e=p(y);if(e.length===0)return;i(y,e.join(`, `),{source:`multi`,values:e})}else if(b===`open-free-text`){let e=y.querySelector(`[data-ask-free-text-row="true"]`);e&&(e.classList.remove(`persona-hidden`),e.querySelector(`[data-ask-free-text-input="true"]`)?.focus())}else if(b===`focus-free-text`)y.querySelector(`[data-ask-free-text-input="true"]`)?.focus();else if(b===`submit-free-text`){let e=y.querySelector(`[data-ask-free-text-input="true"]`)?.value??``;if(!e.trim())return;if(s(y)){m(y,e.trim()),a(y),g(y);return}i(y,e,{source:`free-text`})}else if(b===`next`||b===`back`){if(!r.current)return;let t=y.getAttribute(`data-tool-call-id`)??``,n=r.current.getMessages().find(e=>e.toolCall?.id===t);if(!n)return;let i=y.querySelector(`[data-ask-free-text-input="true"]`)?.value?.trim()??``;if(i){let e=c(y)[u(y)];(typeof e!=`string`||e!==i)&&m(y,i)}let o=b===`next`?1:-1,s=u(y)+o;d(y,n,e.config(),s),a(y)}else if(b===`submit-all`){if(!r.current)return;let e=y.getAttribute(`data-tool-call-id`)??``,t=r.current.getMessages().find(t=>t.toolCall?.id===e);if(!t)return;let n=y.querySelector(`[data-ask-free-text-input="true"]`)?.value?.trim()??``;n&&m(y,n);let a=f(y,t);r.current.persistAskUserQuestionProgress(t,{answers:a,currentIndex:u(y)});let o=h(a);i(y,o||`(submitted)`,{source:`submit-all`,structured:a})}else if(b===`skip`){if(!r.current)return;let c=y.getAttribute(`data-tool-call-id`)??``,p=r.current.getMessages().find(e=>e.toolCall?.id===c);if(!p)return;let g=s(y),_=u(y),v=_>=o(y)-1;if(!g){t.dispatchEvent(new CustomEvent(`persona:askUserQuestion:dismissed`,{detail:{instanceId:e.instanceId,toolUseId:c},bubbles:!0,composed:!0})),l(n,c),p.agentMetadata?.awaitingLocalTool&&(r.current.markAskUserQuestionResolved(p),r.current.resolveAskUserQuestion(p,`(dismissed)`));return}m(y,``);let b=y.querySelector(`[data-ask-free-text-input="true"]`);if(b&&(b.value=``),v){let e=f(y,p),t=h(e);i(y,t||`(skipped)`,{source:`submit-all`,structured:e});return}d(y,p,e.config(),_+1),a(y)}},keydown:e=>{if(e.key!==`Enter`)return;let t=e.target;if(!t.matches?.(`[data-ask-free-text-input="true"]`))return;let n=t.closest(`[data-persona-ask-sheet-for]`);if(!n)return;e.preventDefault();let r=t.value;r.trim()&&(s(n)?(m(n,r.trim()),a(n),g(n)):i(n,r,{source:`free-text`}))}}},y={loadContextMentions:()=>t(),loadContextMentionsInline:()=>i(),renderLucideIcon:(...t)=>e(...t),createMentionButton:(...e)=>n(...e)};function b(e){let{loadContextMentions:t,loadContextMentionsInline:n,renderLucideIcon:i,createMentionButton:o}=e.deps??y,s=e.config.contextMentions;if(!s?.enabled)return null;let c=_(s).filter(e=>e.sources.length>0);if(c.length===0)return typeof console<`u`&&console.warn(`[Persona] contextMentions.enabled is true but no sources were provided; mentions are disabled.`),null;let l=c.filter(e=>e.sources.some(e=>typeof e.matchCommand==`function`)),u=e=>l.some(t=>t.trigger?t.position===`line-start`?e.split(`
2
2
  `).some(e=>e.startsWith(t.trigger)):(t.position===`anywhere`?e:e.split(`
3
3
  `)[0]).startsWith(t.trigger):!1),d=(t,n)=>{if(typeof window<`u`)try{window.dispatchEvent(new CustomEvent(`persona:mention:${t}`,{detail:{...n,instanceId:e.textarea.closest(`[data-persona-instance]`)?.dataset.personaInstance}}))}catch{}},f=!e.chipRow,p=e.chipRow??a(`div`,{className:`persona-mention-context-row`,attrs:{"data-persona-mention-context-row":``}}),m=null,v=null,b=e.textarea,x=null,S=null,C=null,w=null,T=()=>{if(m)return Promise.resolve(m);if(v)return v;let n=t().then(t=>(t.setMentionIconRenderer(i),m=t.mountContextMentions({mentionConfig:s,textarea:e.textarea,composerInput:x??void 0,anchor:e.anchor,contextRow:p,getMessages:e.getMessages,getConfig:()=>e.config,liveRegionHost:e.liveRegionHost,popoverContainer:e.popoverContainer,onPickerOpenChange:O,emit:d}),m)).catch(e=>(typeof console<`u`&&console.warn(`[Persona] Failed to load context mentions runtime`,e),v===n&&(v=null),null));return v=n,n};s.display===`inline`&&n().then(t=>{let n=t.mountInlineComposer({textarea:e.textarea,renderToken:e=>r(e,{render:s.renderMentionToken}),onMentionRemoved:e=>m?.untrackMention(e)});x=n.input,S=n.destroy;let i=b;i.replaceWith(n.element),b=n.element,w={next:n.element,prev:i},C?.(n.element,i),m?m.rebindComposer(n.input):v&&v.then(e=>e?.rebindComposer(n.input))}).catch(e=>{typeof console<`u`&&console.warn(`[Persona] Failed to load inline mention composer`,e)});let E=[],D=/* @__PURE__ */ new Map;for(let e of c){if(!e.showButton)continue;let t=o({config:{...s,buttonIconName:e.buttonIconName,buttonTooltipText:e.buttonTooltipText},onOpen:()=>{T().then(t=>t?.openMenu(e.trigger))}});E.push(t),D.set(e.trigger,t.button)}let O=(e,t,n)=>{let r=D.get(t);r&&(r.setAttribute(`aria-expanded`,e?`true`:`false`),e?r.setAttribute(`aria-controls`,n):r.removeAttribute(`aria-controls`))};return{affordanceButtons:E.map(e=>e.wrapper),contextRow:p,handleInput:e=>{if(m){m.handleInput();return}if(!g(e))return;let t=b,n=t.selectionStart??0;h(t.value,n,c)&&T().then(e=>e?.handleInput())},handleKeydown:e=>{if(m?.isMenuOpen())return m.handleKeydown(e);if(e.key===`Backspace`&&m?.hasMentions()&&!w){let t=b,n=t.selectionStart===0&&t.selectionEnd===0;if((t.value.length===0||n)&&m.removeLastChip())return e.preventDefault(),!0}return!1},isMenuOpen:()=>m?.isMenuOpen()??!1,hasMentions:()=>m?.hasMentions()??!1,getMentionRefs:()=>m?.getMentionRefs()??[],captureDraft:()=>m?.captureDraft()??[],restoreDraft:e=>m?.restoreDraft(e),getInlineInput:()=>x,collectForSubmit:()=>m?.collectForSubmit()??null,takeInlineCommand:async e=>u(e)?(m??await T())?.dispatchInlineCommand(e)??null:null,clear:()=>m?.clear(),prefetch:()=>{t().catch(()=>{})},onComposerSwap:e=>{C=e,w&&e(w.next,w.prev)},destroy:()=>{m?.destroy(),S?.();for(let e of E)e.wrapper.remove();f&&p.remove()}}}export{v as createAskUserSheetHandlers,b as createContextMentionOrchestrator};
@@ -1,4 +1,4 @@
1
- import{n as e}from"./chunk-BnfM7-qg.js";import{t}from"./chunk-CnxIZOzx.js";import{a as n,d as r,g as i,l as a,n as o,p as s,t as c,u as l,v as u,y as d}from"./chunk-D1G8tgYc.js";import{i as f,n as p,t as m}from"./chunk-D5BxWOFB.js";import{n as h}from"./chunk-CNhThrLX.js";import{r as g,t as _}from"./chunk-Cve3IfG4.js";import{Check as v,ChevronDown as y,FileText as ee,Maximize as b,Minimize as x}from"lucide";var S=`[data-persona-root] .persona-artifact-split-root{gap:var(--persona-artifact-split-gap,.5rem)}[data-persona-root] .persona-artifact-toolbar-document .persona-artifact-doc-icon-btn,[data-persona-root] .persona-artifact-inline-chrome-actions .persona-artifact-doc-icon-btn{padding:var(--persona-artifact-toolbar-icon-padding,.25rem);border-radius:var(--persona-artifact-toolbar-icon-radius,var(--persona-radius-md,.375rem));border:var(--persona-artifact-toolbar-icon-border,1px solid var(--persona-border,#e5e7eb));background:var(--persona-artifact-toolbar-icon-bg,var(--persona-surface,#fff));color:var(--persona-artifact-doc-toolbar-icon-color,var(--persona-text,#111827));cursor:pointer;justify-content:center;align-items:center;line-height:1;display:inline-flex}[data-persona-root] .persona-artifact-toolbar-document .persona-artifact-doc-icon-btn:hover,[data-persona-root] .persona-artifact-inline-chrome-actions .persona-artifact-doc-icon-btn:hover{color:var(--persona-artifact-toolbar-icon-hover-color,inherit);background:var(--persona-artifact-toolbar-icon-hover-bg,var(--persona-icon-btn-hover-bg,var(--persona-container,#f3f4f6)))}[data-persona-root] .persona-artifact-toolbar-document .persona-artifact-doc-icon-btn[aria-pressed=true],[data-persona-root] .persona-artifact-inline-chrome-actions .persona-artifact-doc-icon-btn[aria-pressed=true]{background:var(--persona-artifact-doc-toggle-active-bg,var(--persona-icon-btn-active-bg,var(--persona-container,#f3f4f6)));border-color:var(--persona-artifact-doc-toggle-active-border,var(--persona-icon-btn-active-border,var(--persona-border,#e5e7eb)));color:var(--persona-artifact-doc-toggle-active-color,var(--persona-artifact-doc-toolbar-icon-color,var(--persona-text,#111827)))}[data-persona-root] .persona-artifact-toolbar-document .persona-artifact-doc-copy-btn,[data-persona-root] .persona-artifact-inline-chrome-actions .persona-artifact-doc-copy-btn{padding:var(--persona-artifact-toolbar-copy-padding,.25rem .5rem);border-radius:var(--persona-artifact-toolbar-copy-radius,var(--persona-radius-md,.375rem));border:var(--persona-artifact-toolbar-copy-border,1px solid var(--persona-border,#e5e7eb));background:var(--persona-artifact-toolbar-copy-bg,var(--persona-surface,#fff));color:var(--persona-artifact-toolbar-copy-color,var(--persona-artifact-doc-toolbar-icon-color,var(--persona-text,#111827)));cursor:pointer;align-items:center;gap:.35rem;font-size:.75rem;line-height:1.25;display:inline-flex}[data-persona-root] .persona-artifact-toolbar-document .persona-artifact-doc-copy-btn:hover,[data-persona-root] .persona-artifact-inline-chrome-actions .persona-artifact-doc-copy-btn:hover{background:var(--persona-artifact-toolbar-icon-hover-bg,var(--persona-icon-btn-hover-bg,var(--persona-container,#f3f4f6)))}[data-persona-root] .persona-artifact-toolbar-document .persona-split-btn,[data-persona-root] .persona-artifact-inline-chrome-actions .persona-split-btn{--persona-split-radius:var(--persona-artifact-toolbar-copy-radius,var(--persona-radius-md,.375rem));border:var(--persona-artifact-toolbar-copy-border,1px solid var(--persona-border,#e5e7eb));background:var(--persona-artifact-toolbar-copy-bg,var(--persona-surface,#fff))}[data-persona-root] .persona-artifact-tab{background:var(--persona-artifact-tab-bg,transparent);border-radius:var(--persona-artifact-tab-radius,.5rem);color:var(--persona-artifact-tab-color,inherit);white-space:nowrap;max-width:var(--persona-artifact-tab-max-width,12rem);text-overflow:ellipsis;overflow:hidden}[data-persona-root] .persona-artifact-tab.persona-bg-persona-container{background:var(--persona-artifact-tab-active-bg,var(--persona-container,#f3f4f6));border-color:var(--persona-artifact-tab-active-border,var(--persona-border,#e5e7eb))}[data-persona-root] .persona-artifact-toolbar{background:var(--persona-artifact-toolbar-bg,var(--persona-surface,#fff))}[data-persona-root] .persona-artifact-tab:hover{background:var(--persona-artifact-tab-hover-bg,var(--persona-container,#f3f4f6))}[data-persona-root] .persona-artifact-tab:focus-visible{outline:2px solid var(--persona-accent,#171717);outline-offset:2px}[data-persona-root] .persona-artifact-list{background:var(--persona-artifact-tab-list-bg,transparent);border-bottom-color:var(--persona-artifact-tab-list-border-color,var(--persona-border,#e5e7eb));padding:var(--persona-artifact-tab-list-padding,.5rem);scrollbar-width:thin;scroll-behavior:smooth}[data-persona-root] .persona-artifact-list::-webkit-scrollbar{height:6px}[data-persona-root] .persona-artifact-list::-webkit-scrollbar-thumb{background:var(--persona-artifact-tab-list-scrollbar,var(--persona-scrollbar-thumb,var(--persona-border,#e5e7eb)));border-radius:9999px}[data-persona-root] .persona-artifact-toolbar-document{border-bottom:var(--persona-artifact-toolbar-border,1px solid var(--persona-border,#e5e7eb))}[data-persona-root] .persona-artifact-card{background:var(--persona-artifact-card-bg,var(--persona-surface,#fff));border:var(--persona-artifact-card-border,1px solid var(--persona-border,#e5e7eb));border-radius:var(--persona-artifact-card-radius,var(--persona-message-assistant-radius,var(--persona-radius-lg,.5rem)));cursor:pointer;transition:background-color .15s,border-color .15s}[data-persona-root] .persona-artifact-card:hover{background:var(--persona-artifact-card-hover-bg,#f3f4f6);border-color:var(--persona-artifact-card-hover-border,var(--persona-border,#e5e7eb))}[data-persona-root] .persona-artifact-card:focus-visible{outline:2px solid var(--persona-accent,#171717);outline-offset:2px}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group{gap:var(--persona-artifact-toolbar-toggle-group-gap,2px);padding:var(--persona-artifact-toolbar-toggle-group-padding,2px);border:var(--persona-artifact-toolbar-toggle-group-border,1px solid var(--persona-border,#e5e7eb));border-radius:var(--persona-artifact-toolbar-toggle-group-radius,var(--persona-artifact-toolbar-icon-radius,var(--persona-icon-btn-radius,var(--persona-radius-md,.375rem))));background:var(--persona-artifact-toolbar-toggle-group-bg,var(--persona-surface,#fff))}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group>.persona-icon-btn{padding:calc(var(--persona-artifact-toolbar-icon-padding,var(--persona-icon-btn-padding,.25rem)) - var(--persona-artifact-toolbar-toggle-group-padding,2px));border-radius:var(--persona-artifact-toolbar-toggle-radius,calc(var(--persona-artifact-toolbar-icon-radius,var(--persona-icon-btn-radius,var(--persona-radius-md,.375rem))) - 2px));background:0 0;border:none}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group>.persona-icon-btn:hover{background:var(--persona-artifact-toolbar-icon-hover-bg,var(--persona-icon-btn-hover-bg,var(--persona-container,#f3f4f6)))}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group>.persona-icon-btn[aria-pressed=true]{background:var(--persona-artifact-doc-toggle-active-bg,var(--persona-icon-btn-active-bg,var(--persona-container,#f3f4f6)));box-shadow:inset 0 0 0 1px var(--persona-artifact-doc-toggle-active-border,transparent);color:var(--persona-artifact-doc-toggle-active-color,var(--persona-artifact-doc-toolbar-icon-color,var(--persona-text,#111827)))}@supports selector(:has(*)){[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group{position:relative}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group:before{content:"";top:var(--persona-artifact-toolbar-toggle-group-padding,2px);bottom:var(--persona-artifact-toolbar-toggle-group-padding,2px);left:var(--persona-artifact-toolbar-toggle-group-padding,2px);width:calc(50% - var(--persona-artifact-toolbar-toggle-group-padding,2px) - (var(--persona-artifact-toolbar-toggle-group-gap,2px) / 2));border-radius:var(--persona-artifact-toolbar-toggle-radius,calc(var(--persona-artifact-toolbar-icon-radius,var(--persona-icon-btn-radius,var(--persona-radius-md,.375rem))) - 2px));background:var(--persona-artifact-doc-toggle-active-bg,var(--persona-icon-btn-active-bg,var(--persona-container,#f3f4f6)));box-shadow:inset 0 0 0 1px var(--persona-artifact-doc-toggle-active-border,transparent);pointer-events:none;transition:transform .18s;position:absolute}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group:has(>.persona-icon-btn:last-child[aria-pressed=true]):before{transform:translateX(calc(100% + var(--persona-artifact-toolbar-toggle-group-gap,2px)))}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group>.persona-icon-btn{position:relative}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group>.persona-icon-btn[aria-pressed=true]{box-shadow:none;background:0 0}@media (prefers-reduced-motion:reduce){[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group:before{transition:none}}}[data-persona-root].persona-artifact-narrow-host .persona-artifact-split-handle{display:none!important}@media (max-width:640px){[data-persona-root] .persona-artifact-split-handle{display:none!important}}@media (min-width:641px){[data-persona-root] .persona-artifact-pane{width:var(--persona-artifact-pane-width,40%);max-width:var(--persona-artifact-pane-max-width,28rem);min-width:var(--persona-artifact-pane-min-width,0);box-shadow:var(--persona-artifact-pane-shadow,none);flex-shrink:0}[data-persona-root].persona-artifact-expanded .persona-artifact-split-root>:first-child{display:none}[data-persona-root].persona-artifact-expanded .persona-artifact-pane{width:100%;max-width:none}[data-persona-root].persona-artifact-expanded .persona-artifact-split-handle{display:none!important}}@media (max-width:640px){[data-persona-root] .persona-artifact-expand-btn{display:none!important}}[data-persona-root].persona-artifact-narrow-host .persona-artifact-expand-btn{display:none!important}[data-persona-root] .persona-artifact-frame{background:var(--persona-artifact-frame-bg,#fff);width:100%;height:100%;position:relative}[data-persona-root] .persona-artifact-iframe{--lightningcss-light:initial;--lightningcss-dark: ;color-scheme:light;background:var(--persona-artifact-frame-bg,#fff);border:0;width:100%;height:100%;display:block}[data-persona-root] .persona-artifact-frame-loading{background:var(--persona-artifact-frame-bg,#fff);opacity:1;transition:opacity var(--persona-artifact-frame-loading-fade,.2s) ease;justify-content:center;align-items:center;display:flex;position:absolute;inset:0}[data-persona-root] .persona-artifact-frame-loading--out{opacity:0}[data-persona-root] .persona-artifact-frame-loading-indicator{flex-direction:column;align-items:center;gap:.625rem;display:flex}[data-persona-root] .persona-artifact-frame-loading-text{color:var(--persona-artifact-frame-loading-color,var(--persona-text-muted,#6b7280));opacity:0;font-size:.8125rem;font-weight:500;transition:opacity .24s}[data-persona-root] .persona-artifact-frame-loading-text--visible{opacity:1}@media (prefers-reduced-motion:reduce){[data-persona-root] .persona-artifact-frame-loading-text{transition:none}}[data-persona-root] .persona-artifact-content{width:100%;min-width:0;max-width:100%}[data-persona-root] .persona-artifact-content>.persona-artifact-preview-body>*{min-width:0;max-width:100%}[data-persona-root] .persona-artifact-preview-body{display:contents}[data-persona-root] .persona-artifact-content-flush{padding:0}[data-persona-root] .persona-artifact-content-flush .persona-code-pre{border-radius:0;min-height:100%;padding:.5rem .75rem .5rem 0}[data-persona-root] .persona-artifact-inline{border:var(--persona-artifact-inline-border,1px solid var(--persona-border,#e5e7eb));border-radius:var(--persona-artifact-inline-radius,var(--persona-message-assistant-radius,var(--persona-radius-lg,.5rem)));background:var(--persona-artifact-inline-bg,var(--persona-surface,#fff));overflow:hidden}[data-persona-root] .persona-artifact-inline.persona-artifact-inline--card{background:0 0;border:none;border-radius:0;overflow:visible}[data-persona-root] .persona-artifact-inline-chrome{background:var(--persona-artifact-inline-chrome-bg,var(--persona-surface,#fff));border-bottom:1px solid var(--persona-artifact-inline-chrome-border,var(--persona-border,#e5e7eb));align-items:center;gap:.5rem;padding:.5rem .75rem;display:flex}[data-persona-root] .persona-artifact-inline-chrome-lead{min-width:0;color:var(--persona-artifact-inline-title-color,var(--persona-text,#111827));flex:auto;align-items:center;gap:.5rem;font-size:.8125rem;font-weight:500;display:flex}[data-persona-root] .persona-artifact-inline-chrome-lead .persona-artifact-inline-type,[data-persona-root] .persona-artifact-inline-chrome-lead .persona-artifact-inline-status{color:var(--persona-artifact-inline-muted-color,var(--persona-text-muted,#6b7280));font-weight:400}[data-persona-root] .persona-artifact-inline-chrome-lead .persona-artifact-inline-status{white-space:nowrap;text-overflow:ellipsis;min-width:0;overflow:hidden}[data-persona-root] .persona-artifact-status-detail{color:var(--persona-artifact-inline-muted-color,var(--persona-text-muted,#6b7280));font-variant-numeric:tabular-nums;margin-left:.375rem}[data-persona-root] .persona-artifact-inline-chrome-actions{flex:none;align-items:center;gap:.25rem;display:flex}[data-persona-root] .persona-artifact-inline-body{padding:.75rem}[data-persona-root] .persona-artifact-inline .persona-artifact-frame{height:var(--persona-artifact-inline-body-height,var(--persona-artifact-inline-frame-height,320px))}[data-persona-root] .persona-artifact-inline-body.persona-artifact-content-flush{padding:0}[data-persona-root] .persona-artifact-inline-body--sized{height:var(--persona-artifact-inline-body-height,auto)}[data-persona-root] .persona-artifact-inline-body--sized .persona-artifact-source-window--fixed,[data-persona-root] .persona-artifact-inline-body--sized .persona-artifact-frame{height:100%}[data-persona-root] .persona-artifact-inline-body--sized .persona-artifact-status-view{min-height:100%}[data-persona-root] .persona-artifact-source-window{min-width:0}[data-persona-root] .persona-artifact-source-window--fixed{overflow-y:auto}[data-persona-root] .persona-artifact-source-window--clip{overflow:hidden}[data-persona-root] .persona-artifact-fade-top:not(.persona-artifact-fade-bottom){-webkit-mask-image:linear-gradient(to bottom, transparent 0, #000 var(--persona-artifact-fade-size,40px));-webkit-mask-image:linear-gradient(to bottom, transparent 0, #000 var(--persona-artifact-fade-size,40px));mask-image:linear-gradient(to bottom, transparent 0, #000 var(--persona-artifact-fade-size,40px))}[data-persona-root] .persona-artifact-fade-bottom:not(.persona-artifact-fade-top){-webkit-mask-image:linear-gradient(to top, transparent 0, #000 var(--persona-artifact-fade-size,40px));-webkit-mask-image:linear-gradient(to top, transparent 0, #000 var(--persona-artifact-fade-size,40px));mask-image:linear-gradient(to top, transparent 0, #000 var(--persona-artifact-fade-size,40px))}[data-persona-root] .persona-artifact-fade-top.persona-artifact-fade-bottom{-webkit-mask-image:linear-gradient(to bottom, transparent 0, #000 var(--persona-artifact-fade-size,40px), #000 calc(100% - var(--persona-artifact-fade-size,40px)), transparent 100%);-webkit-mask-image:linear-gradient(to bottom, transparent 0, #000 var(--persona-artifact-fade-size,40px), #000 calc(100% - var(--persona-artifact-fade-size,40px)), transparent 100%);mask-image:linear-gradient(to bottom, transparent 0, #000 var(--persona-artifact-fade-size,40px), #000 calc(100% - var(--persona-artifact-fade-size,40px)), transparent 100%)}[data-persona-root] .persona-artifact-tab-fade-start:not(.persona-artifact-tab-fade-end){-webkit-mask-image:linear-gradient(to right, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px));-webkit-mask-image:linear-gradient(to right, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px));mask-image:linear-gradient(to right, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px))}[data-persona-root] .persona-artifact-tab-fade-end:not(.persona-artifact-tab-fade-start){-webkit-mask-image:linear-gradient(to left, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px));-webkit-mask-image:linear-gradient(to left, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px));mask-image:linear-gradient(to left, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px))}[data-persona-root] .persona-artifact-tab-fade-start.persona-artifact-tab-fade-end{-webkit-mask-image:linear-gradient(to right, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px), #000 calc(100% - var(--persona-artifact-tab-fade-size,24px)), transparent 100%);-webkit-mask-image:linear-gradient(to right, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px), #000 calc(100% - var(--persona-artifact-tab-fade-size,24px)), transparent 100%);mask-image:linear-gradient(to right, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px), #000 calc(100% - var(--persona-artifact-tab-fade-size,24px)), transparent 100%)}[data-persona-root] .persona-artifact-status-view{min-height:var(--persona-artifact-inline-body-height,160px);justify-content:center;align-items:center;display:flex}[data-persona-root] .persona-artifact-inline-body--cap{max-height:var(--persona-artifact-inline-body-height,none);overflow-y:auto}[data-persona-root] .persona-artifact-pane{border-radius:var(--persona-artifact-pane-radius,0);background-color:var(--persona-artifact-pane-bg,var(--persona-components-artifact-pane-background,var(--persona-surface,#fff)));overflow:hidden}[data-persona-root].persona-artifact-appearance-seamless .persona-artifact-split-root{position:relative;gap:0!important}[data-persona-root].persona-artifact-appearance-seamless .persona-artifact-pane{background-color:var(--persona-artifact-pane-bg,var(--persona-components-artifact-pane-background,var(--persona-container,#f8fafc)));box-shadow:none!important;border-left-width:0!important;border-left-color:#0000!important}[data-persona-root].persona-artifact-border-full .persona-artifact-pane{border:var(--persona-artifact-pane-border)!important}[data-persona-root].persona-artifact-border-left .persona-artifact-pane{border-top:none!important;border-bottom:none!important;border-right:none!important;border-left:var(--persona-artifact-pane-border-left)!important}[data-persona-root].persona-artifact-appearance-seamless.persona-artifact-border-left .persona-artifact-pane{border-left:var(--persona-artifact-pane-border-left)!important}[data-persona-root].persona-artifact-appearance-seamless.persona-artifact-border-full .persona-artifact-pane{border:var(--persona-artifact-pane-border)!important}[data-persona-root].persona-artifact-appearance-detached .persona-artifact-split-root{background:var(--persona-panel-canvas-bg)}@media (min-width:641px){[data-persona-root]:not(.persona-artifact-narrow-host).persona-artifact-appearance-detached .persona-artifact-pane{border-radius:var(--persona-artifact-pane-radius,var(--persona-panel-radius,var(--persona-radius-xl,.75rem)));border:var(--persona-panel-border,1px solid var(--persona-border,#e5e7eb));box-shadow:var(--persona-artifact-pane-shadow,var(--persona-panel-shadow,var(--persona-palette-shadows-xl,0 25px 50px -12px #00000040)))}[data-persona-root]:not(.persona-artifact-narrow-host).persona-artifact-chat-flush .persona-artifact-pane{margin-top:var(--persona-panel-inset);margin-right:var(--persona-panel-inset);margin-bottom:var(--persona-panel-inset)}[data-persona-root]:not(.persona-artifact-narrow-host).persona-artifact-welded-split .persona-artifact-split-root{position:relative}[data-persona-root]:not(.persona-artifact-narrow-host).persona-artifact-welded-split .persona-widget-container{overflow:hidden;border-top-right-radius:0!important;border-bottom-right-radius:0!important}[data-persona-root]:not(.persona-artifact-narrow-host).persona-artifact-welded-split .persona-artifact-pane{overflow:hidden;border-top-left-radius:0!important;border-bottom-left-radius:0!important;border-top-right-radius:var(--persona-artifact-welded-outer-radius,var(--persona-panel-radius,var(--persona-radius-xl,.75rem)))!important;border-bottom-right-radius:var(--persona-artifact-welded-outer-radius,var(--persona-panel-radius,var(--persona-radius-xl,.75rem)))!important}[data-persona-root]:not(.persona-artifact-narrow-host).persona-artifact-welded-split.persona-artifact-appearance-panel .persona-artifact-pane{border-left:1px solid var(--persona-border,#e5e7eb)}}[data-persona-root].persona-artifact-narrow-host .persona-artifact-backdrop{z-index:55!important;position:absolute!important;inset:0!important}@media (min-width:641px){[data-persona-root].persona-artifact-narrow-host .persona-artifact-pane{z-index:60;transition:transform .2s;position:absolute;top:0;bottom:0;right:0;transform:translate(100%);box-shadow:-4px 0 24px #0000001f;width:min(100%, var(--persona-artifact-drawer-width,min(calc(100% - 1rem), 22rem)))!important;max-width:var(--persona-artifact-drawer-width,22rem)!important}[data-persona-root].persona-artifact-narrow-host .persona-artifact-pane.persona-artifact-drawer-open{transform:translate(0)}}@media (max-width:640px){[data-persona-root] .persona-artifact-pane{width:min(100vw, var(--persona-artifact-drawer-width,min(100vw - 1.5rem, 22rem)));z-index:60;transition:transform .2s;position:fixed;top:0;bottom:0;right:0;transform:translate(100%);box-shadow:-4px 0 24px #0000001f}[data-persona-root] .persona-artifact-pane.persona-artifact-drawer-open{transform:translate(0)}}`;const C=e=>h(e,`artifacts`,S);function w(e){let t=String(e).split(/[\\/]/);return t[t.length-1]??``}function T(e){let t=w(e),n=t.lastIndexOf(`.`);return n<=0?``:t.slice(n+1).toLowerCase()}function E(e){if(typeof e!=`string`)return``;let t=e.indexOf(`
1
+ import{n as e}from"./chunk-BnfM7-qg.js";import{t}from"./chunk-CnxIZOzx.js";import{a as n,d as r,g as i,l as a,n as o,p as s,t as c,u as l,v as u,y as d}from"./chunk-D1G8tgYc.js";import{i as f,n as p,t as m}from"./chunk-D5BxWOFB.js";import{n as h}from"./chunk-Cd8mp8Sv.js";import{r as g,t as _}from"./chunk-Cve3IfG4.js";import{Check as v,ChevronDown as y,FileText as ee,Maximize as b,Minimize as x}from"lucide";var S=`[data-persona-root] .persona-artifact-split-root{gap:var(--persona-artifact-split-gap,.5rem)}[data-persona-root] .persona-artifact-toolbar-document .persona-artifact-doc-icon-btn,[data-persona-root] .persona-artifact-inline-chrome-actions .persona-artifact-doc-icon-btn{padding:var(--persona-artifact-toolbar-icon-padding,.25rem);border-radius:var(--persona-artifact-toolbar-icon-radius,var(--persona-radius-md,.375rem));border:var(--persona-artifact-toolbar-icon-border,1px solid var(--persona-border,#e5e7eb));background:var(--persona-artifact-toolbar-icon-bg,var(--persona-surface,#fff));color:var(--persona-artifact-doc-toolbar-icon-color,var(--persona-text,#111827));cursor:pointer;justify-content:center;align-items:center;line-height:1;display:inline-flex}[data-persona-root] .persona-artifact-toolbar-document .persona-artifact-doc-icon-btn:hover,[data-persona-root] .persona-artifact-inline-chrome-actions .persona-artifact-doc-icon-btn:hover{color:var(--persona-artifact-toolbar-icon-hover-color,inherit);background:var(--persona-artifact-toolbar-icon-hover-bg,var(--persona-icon-btn-hover-bg,var(--persona-container,#f3f4f6)))}[data-persona-root] .persona-artifact-toolbar-document .persona-artifact-doc-icon-btn[aria-pressed=true],[data-persona-root] .persona-artifact-inline-chrome-actions .persona-artifact-doc-icon-btn[aria-pressed=true]{background:var(--persona-artifact-doc-toggle-active-bg,var(--persona-icon-btn-active-bg,var(--persona-container,#f3f4f6)));border-color:var(--persona-artifact-doc-toggle-active-border,var(--persona-icon-btn-active-border,var(--persona-border,#e5e7eb)));color:var(--persona-artifact-doc-toggle-active-color,var(--persona-artifact-doc-toolbar-icon-color,var(--persona-text,#111827)))}[data-persona-root] .persona-artifact-toolbar-document .persona-artifact-doc-copy-btn,[data-persona-root] .persona-artifact-inline-chrome-actions .persona-artifact-doc-copy-btn{padding:var(--persona-artifact-toolbar-copy-padding,.25rem .5rem);border-radius:var(--persona-artifact-toolbar-copy-radius,var(--persona-radius-md,.375rem));border:var(--persona-artifact-toolbar-copy-border,1px solid var(--persona-border,#e5e7eb));background:var(--persona-artifact-toolbar-copy-bg,var(--persona-surface,#fff));color:var(--persona-artifact-toolbar-copy-color,var(--persona-artifact-doc-toolbar-icon-color,var(--persona-text,#111827)));cursor:pointer;align-items:center;gap:.35rem;font-size:.75rem;line-height:1.25;display:inline-flex}[data-persona-root] .persona-artifact-toolbar-document .persona-artifact-doc-copy-btn:hover,[data-persona-root] .persona-artifact-inline-chrome-actions .persona-artifact-doc-copy-btn:hover{background:var(--persona-artifact-toolbar-icon-hover-bg,var(--persona-icon-btn-hover-bg,var(--persona-container,#f3f4f6)))}[data-persona-root] .persona-artifact-toolbar-document .persona-split-btn,[data-persona-root] .persona-artifact-inline-chrome-actions .persona-split-btn{--persona-split-radius:var(--persona-artifact-toolbar-copy-radius,var(--persona-radius-md,.375rem));border:var(--persona-artifact-toolbar-copy-border,1px solid var(--persona-border,#e5e7eb));background:var(--persona-artifact-toolbar-copy-bg,var(--persona-surface,#fff))}[data-persona-root] .persona-artifact-tab{background:var(--persona-artifact-tab-bg,transparent);border-radius:var(--persona-artifact-tab-radius,.5rem);color:var(--persona-artifact-tab-color,inherit);white-space:nowrap;max-width:var(--persona-artifact-tab-max-width,12rem);text-overflow:ellipsis;overflow:hidden}[data-persona-root] .persona-artifact-tab.persona-bg-persona-container{background:var(--persona-artifact-tab-active-bg,var(--persona-container,#f3f4f6));border-color:var(--persona-artifact-tab-active-border,var(--persona-border,#e5e7eb))}[data-persona-root] .persona-artifact-toolbar{background:var(--persona-artifact-toolbar-bg,var(--persona-surface,#fff))}[data-persona-root] .persona-artifact-tab:hover{background:var(--persona-artifact-tab-hover-bg,var(--persona-container,#f3f4f6))}[data-persona-root] .persona-artifact-tab:focus-visible{outline:2px solid var(--persona-accent,#171717);outline-offset:2px}[data-persona-root] .persona-artifact-list{background:var(--persona-artifact-tab-list-bg,transparent);border-bottom-color:var(--persona-artifact-tab-list-border-color,var(--persona-border,#e5e7eb));padding:var(--persona-artifact-tab-list-padding,.5rem);scrollbar-width:thin;scroll-behavior:smooth}[data-persona-root] .persona-artifact-list::-webkit-scrollbar{height:6px}[data-persona-root] .persona-artifact-list::-webkit-scrollbar-thumb{background:var(--persona-artifact-tab-list-scrollbar,var(--persona-scrollbar-thumb,var(--persona-border,#e5e7eb)));border-radius:9999px}[data-persona-root] .persona-artifact-toolbar-document{border-bottom:var(--persona-artifact-toolbar-border,1px solid var(--persona-border,#e5e7eb))}[data-persona-root] .persona-artifact-card{background:var(--persona-artifact-card-bg,var(--persona-surface,#fff));border:var(--persona-artifact-card-border,1px solid var(--persona-border,#e5e7eb));border-radius:var(--persona-artifact-card-radius,var(--persona-message-assistant-radius,var(--persona-radius-lg,.5rem)));cursor:pointer;transition:background-color .15s,border-color .15s}[data-persona-root] .persona-artifact-card:hover{background:var(--persona-artifact-card-hover-bg,#f3f4f6);border-color:var(--persona-artifact-card-hover-border,var(--persona-border,#e5e7eb))}[data-persona-root] .persona-artifact-card:focus-visible{outline:2px solid var(--persona-accent,#171717);outline-offset:2px}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group{gap:var(--persona-artifact-toolbar-toggle-group-gap,2px);padding:var(--persona-artifact-toolbar-toggle-group-padding,2px);border:var(--persona-artifact-toolbar-toggle-group-border,1px solid var(--persona-border,#e5e7eb));border-radius:var(--persona-artifact-toolbar-toggle-group-radius,var(--persona-artifact-toolbar-icon-radius,var(--persona-icon-btn-radius,var(--persona-radius-md,.375rem))));background:var(--persona-artifact-toolbar-toggle-group-bg,var(--persona-surface,#fff))}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group>.persona-icon-btn{padding:calc(var(--persona-artifact-toolbar-icon-padding,var(--persona-icon-btn-padding,.25rem)) - var(--persona-artifact-toolbar-toggle-group-padding,2px));border-radius:var(--persona-artifact-toolbar-toggle-radius,calc(var(--persona-artifact-toolbar-icon-radius,var(--persona-icon-btn-radius,var(--persona-radius-md,.375rem))) - 2px));background:0 0;border:none}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group>.persona-icon-btn:hover{background:var(--persona-artifact-toolbar-icon-hover-bg,var(--persona-icon-btn-hover-bg,var(--persona-container,#f3f4f6)))}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group>.persona-icon-btn[aria-pressed=true]{background:var(--persona-artifact-doc-toggle-active-bg,var(--persona-icon-btn-active-bg,var(--persona-container,#f3f4f6)));box-shadow:inset 0 0 0 1px var(--persona-artifact-doc-toggle-active-border,transparent);color:var(--persona-artifact-doc-toggle-active-color,var(--persona-artifact-doc-toolbar-icon-color,var(--persona-text,#111827)))}@supports selector(:has(*)){[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group{position:relative}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group:before{content:"";top:var(--persona-artifact-toolbar-toggle-group-padding,2px);bottom:var(--persona-artifact-toolbar-toggle-group-padding,2px);left:var(--persona-artifact-toolbar-toggle-group-padding,2px);width:calc(50% - var(--persona-artifact-toolbar-toggle-group-padding,2px) - (var(--persona-artifact-toolbar-toggle-group-gap,2px) / 2));border-radius:var(--persona-artifact-toolbar-toggle-radius,calc(var(--persona-artifact-toolbar-icon-radius,var(--persona-icon-btn-radius,var(--persona-radius-md,.375rem))) - 2px));background:var(--persona-artifact-doc-toggle-active-bg,var(--persona-icon-btn-active-bg,var(--persona-container,#f3f4f6)));box-shadow:inset 0 0 0 1px var(--persona-artifact-doc-toggle-active-border,transparent);pointer-events:none;transition:transform .18s;position:absolute}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group:has(>.persona-icon-btn:last-child[aria-pressed=true]):before{transform:translateX(calc(100% + var(--persona-artifact-toolbar-toggle-group-gap,2px)))}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group>.persona-icon-btn{position:relative}[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group>.persona-icon-btn[aria-pressed=true]{box-shadow:none;background:0 0}@media (prefers-reduced-motion:reduce){[data-persona-root] .persona-toggle-group.persona-artifact-toggle-group:before{transition:none}}}[data-persona-root].persona-artifact-narrow-host .persona-artifact-split-handle{display:none!important}@media (max-width:640px){[data-persona-root] .persona-artifact-split-handle{display:none!important}}@media (min-width:641px){[data-persona-root] .persona-artifact-pane{width:var(--persona-artifact-pane-width,40%);max-width:var(--persona-artifact-pane-max-width,28rem);min-width:var(--persona-artifact-pane-min-width,0);box-shadow:var(--persona-artifact-pane-shadow,none);flex-shrink:0}[data-persona-root].persona-artifact-expanded .persona-artifact-split-root>:first-child{display:none}[data-persona-root].persona-artifact-expanded .persona-artifact-pane{width:100%;max-width:none}[data-persona-root].persona-artifact-expanded .persona-artifact-split-handle{display:none!important}}@media (max-width:640px){[data-persona-root] .persona-artifact-expand-btn{display:none!important}}[data-persona-root].persona-artifact-narrow-host .persona-artifact-expand-btn{display:none!important}[data-persona-root] .persona-artifact-frame{background:var(--persona-artifact-frame-bg,#fff);width:100%;height:100%;position:relative}[data-persona-root] .persona-artifact-iframe{--lightningcss-light:initial;--lightningcss-dark: ;color-scheme:light;background:var(--persona-artifact-frame-bg,#fff);border:0;width:100%;height:100%;display:block}[data-persona-root] .persona-artifact-frame-loading{background:var(--persona-artifact-frame-bg,#fff);opacity:1;transition:opacity var(--persona-artifact-frame-loading-fade,.2s) ease;justify-content:center;align-items:center;display:flex;position:absolute;inset:0}[data-persona-root] .persona-artifact-frame-loading--out{opacity:0}[data-persona-root] .persona-artifact-frame-loading-indicator{flex-direction:column;align-items:center;gap:.625rem;display:flex}[data-persona-root] .persona-artifact-frame-loading-text{color:var(--persona-artifact-frame-loading-color,var(--persona-text-muted,#6b7280));opacity:0;font-size:.8125rem;font-weight:500;transition:opacity .24s}[data-persona-root] .persona-artifact-frame-loading-text--visible{opacity:1}@media (prefers-reduced-motion:reduce){[data-persona-root] .persona-artifact-frame-loading-text{transition:none}}[data-persona-root] .persona-artifact-content{width:100%;min-width:0;max-width:100%}[data-persona-root] .persona-artifact-content>.persona-artifact-preview-body>*{min-width:0;max-width:100%}[data-persona-root] .persona-artifact-preview-body{display:contents}[data-persona-root] .persona-artifact-content-flush{padding:0}[data-persona-root] .persona-artifact-content-flush .persona-code-pre{border-radius:0;min-height:100%;padding:.5rem .75rem .5rem 0}[data-persona-root] .persona-artifact-inline{border:var(--persona-artifact-inline-border,1px solid var(--persona-border,#e5e7eb));border-radius:var(--persona-artifact-inline-radius,var(--persona-message-assistant-radius,var(--persona-radius-lg,.5rem)));background:var(--persona-artifact-inline-bg,var(--persona-surface,#fff));overflow:hidden}[data-persona-root] .persona-artifact-inline.persona-artifact-inline--card{background:0 0;border:none;border-radius:0;overflow:visible}[data-persona-root] .persona-artifact-inline-chrome{background:var(--persona-artifact-inline-chrome-bg,var(--persona-surface,#fff));border-bottom:1px solid var(--persona-artifact-inline-chrome-border,var(--persona-border,#e5e7eb));align-items:center;gap:.5rem;padding:.5rem .75rem;display:flex}[data-persona-root] .persona-artifact-inline-chrome-lead{min-width:0;color:var(--persona-artifact-inline-title-color,var(--persona-text,#111827));flex:auto;align-items:center;gap:.5rem;font-size:.8125rem;font-weight:500;display:flex}[data-persona-root] .persona-artifact-inline-chrome-lead .persona-artifact-inline-type,[data-persona-root] .persona-artifact-inline-chrome-lead .persona-artifact-inline-status{color:var(--persona-artifact-inline-muted-color,var(--persona-text-muted,#6b7280));font-weight:400}[data-persona-root] .persona-artifact-inline-chrome-lead .persona-artifact-inline-status{white-space:nowrap;text-overflow:ellipsis;min-width:0;overflow:hidden}[data-persona-root] .persona-artifact-status-detail{color:var(--persona-artifact-inline-muted-color,var(--persona-text-muted,#6b7280));font-variant-numeric:tabular-nums;margin-left:.375rem}[data-persona-root] .persona-artifact-inline-chrome-actions{flex:none;align-items:center;gap:.25rem;display:flex}[data-persona-root] .persona-artifact-inline-body{padding:.75rem}[data-persona-root] .persona-artifact-inline .persona-artifact-frame{height:var(--persona-artifact-inline-body-height,var(--persona-artifact-inline-frame-height,320px))}[data-persona-root] .persona-artifact-inline-body.persona-artifact-content-flush{padding:0}[data-persona-root] .persona-artifact-inline-body--sized{height:var(--persona-artifact-inline-body-height,auto)}[data-persona-root] .persona-artifact-inline-body--sized .persona-artifact-source-window--fixed,[data-persona-root] .persona-artifact-inline-body--sized .persona-artifact-frame{height:100%}[data-persona-root] .persona-artifact-inline-body--sized .persona-artifact-status-view{min-height:100%}[data-persona-root] .persona-artifact-source-window{min-width:0}[data-persona-root] .persona-artifact-source-window--fixed{overflow-y:auto}[data-persona-root] .persona-artifact-source-window--clip{overflow:hidden}[data-persona-root] .persona-artifact-fade-top:not(.persona-artifact-fade-bottom){-webkit-mask-image:linear-gradient(to bottom, transparent 0, #000 var(--persona-artifact-fade-size,40px));-webkit-mask-image:linear-gradient(to bottom, transparent 0, #000 var(--persona-artifact-fade-size,40px));mask-image:linear-gradient(to bottom, transparent 0, #000 var(--persona-artifact-fade-size,40px))}[data-persona-root] .persona-artifact-fade-bottom:not(.persona-artifact-fade-top){-webkit-mask-image:linear-gradient(to top, transparent 0, #000 var(--persona-artifact-fade-size,40px));-webkit-mask-image:linear-gradient(to top, transparent 0, #000 var(--persona-artifact-fade-size,40px));mask-image:linear-gradient(to top, transparent 0, #000 var(--persona-artifact-fade-size,40px))}[data-persona-root] .persona-artifact-fade-top.persona-artifact-fade-bottom{-webkit-mask-image:linear-gradient(to bottom, transparent 0, #000 var(--persona-artifact-fade-size,40px), #000 calc(100% - var(--persona-artifact-fade-size,40px)), transparent 100%);-webkit-mask-image:linear-gradient(to bottom, transparent 0, #000 var(--persona-artifact-fade-size,40px), #000 calc(100% - var(--persona-artifact-fade-size,40px)), transparent 100%);mask-image:linear-gradient(to bottom, transparent 0, #000 var(--persona-artifact-fade-size,40px), #000 calc(100% - var(--persona-artifact-fade-size,40px)), transparent 100%)}[data-persona-root] .persona-artifact-tab-fade-start:not(.persona-artifact-tab-fade-end){-webkit-mask-image:linear-gradient(to right, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px));-webkit-mask-image:linear-gradient(to right, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px));mask-image:linear-gradient(to right, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px))}[data-persona-root] .persona-artifact-tab-fade-end:not(.persona-artifact-tab-fade-start){-webkit-mask-image:linear-gradient(to left, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px));-webkit-mask-image:linear-gradient(to left, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px));mask-image:linear-gradient(to left, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px))}[data-persona-root] .persona-artifact-tab-fade-start.persona-artifact-tab-fade-end{-webkit-mask-image:linear-gradient(to right, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px), #000 calc(100% - var(--persona-artifact-tab-fade-size,24px)), transparent 100%);-webkit-mask-image:linear-gradient(to right, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px), #000 calc(100% - var(--persona-artifact-tab-fade-size,24px)), transparent 100%);mask-image:linear-gradient(to right, transparent 0, #000 var(--persona-artifact-tab-fade-size,24px), #000 calc(100% - var(--persona-artifact-tab-fade-size,24px)), transparent 100%)}[data-persona-root] .persona-artifact-status-view{min-height:var(--persona-artifact-inline-body-height,160px);justify-content:center;align-items:center;display:flex}[data-persona-root] .persona-artifact-inline-body--cap{max-height:var(--persona-artifact-inline-body-height,none);overflow-y:auto}[data-persona-root] .persona-artifact-pane{border-radius:var(--persona-artifact-pane-radius,0);background-color:var(--persona-artifact-pane-bg,var(--persona-components-artifact-pane-background,var(--persona-surface,#fff)));overflow:hidden}[data-persona-root].persona-artifact-appearance-seamless .persona-artifact-split-root{position:relative;gap:0!important}[data-persona-root].persona-artifact-appearance-seamless .persona-artifact-pane{background-color:var(--persona-artifact-pane-bg,var(--persona-components-artifact-pane-background,var(--persona-container,#f8fafc)));box-shadow:none!important;border-left-width:0!important;border-left-color:#0000!important}[data-persona-root].persona-artifact-border-full .persona-artifact-pane{border:var(--persona-artifact-pane-border)!important}[data-persona-root].persona-artifact-border-left .persona-artifact-pane{border-top:none!important;border-bottom:none!important;border-right:none!important;border-left:var(--persona-artifact-pane-border-left)!important}[data-persona-root].persona-artifact-appearance-seamless.persona-artifact-border-left .persona-artifact-pane{border-left:var(--persona-artifact-pane-border-left)!important}[data-persona-root].persona-artifact-appearance-seamless.persona-artifact-border-full .persona-artifact-pane{border:var(--persona-artifact-pane-border)!important}[data-persona-root].persona-artifact-appearance-detached .persona-artifact-split-root{background:var(--persona-panel-canvas-bg)}@media (min-width:641px){[data-persona-root]:not(.persona-artifact-narrow-host).persona-artifact-appearance-detached .persona-artifact-pane{border-radius:var(--persona-artifact-pane-radius,var(--persona-panel-radius,var(--persona-radius-xl,.75rem)));border:var(--persona-panel-border,1px solid var(--persona-border,#e5e7eb));box-shadow:var(--persona-artifact-pane-shadow,var(--persona-panel-shadow,var(--persona-palette-shadows-xl,0 25px 50px -12px #00000040)))}[data-persona-root]:not(.persona-artifact-narrow-host).persona-artifact-chat-flush .persona-artifact-pane{margin-top:var(--persona-panel-inset);margin-right:var(--persona-panel-inset);margin-bottom:var(--persona-panel-inset)}[data-persona-root]:not(.persona-artifact-narrow-host).persona-artifact-welded-split .persona-artifact-split-root{position:relative}[data-persona-root]:not(.persona-artifact-narrow-host).persona-artifact-welded-split .persona-widget-container{overflow:hidden;border-top-right-radius:0!important;border-bottom-right-radius:0!important}[data-persona-root]:not(.persona-artifact-narrow-host).persona-artifact-welded-split .persona-artifact-pane{overflow:hidden;border-top-left-radius:0!important;border-bottom-left-radius:0!important;border-top-right-radius:var(--persona-artifact-welded-outer-radius,var(--persona-panel-radius,var(--persona-radius-xl,.75rem)))!important;border-bottom-right-radius:var(--persona-artifact-welded-outer-radius,var(--persona-panel-radius,var(--persona-radius-xl,.75rem)))!important}[data-persona-root]:not(.persona-artifact-narrow-host).persona-artifact-welded-split.persona-artifact-appearance-panel .persona-artifact-pane{border-left:1px solid var(--persona-border,#e5e7eb)}}[data-persona-root].persona-artifact-narrow-host .persona-artifact-backdrop{z-index:55!important;position:absolute!important;inset:0!important}@media (min-width:641px){[data-persona-root].persona-artifact-narrow-host .persona-artifact-pane{z-index:60;transition:transform .2s;position:absolute;top:0;bottom:0;right:0;transform:translate(100%);box-shadow:-4px 0 24px #0000001f;width:min(100%, var(--persona-artifact-drawer-width,min(calc(100% - 1rem), 22rem)))!important;max-width:var(--persona-artifact-drawer-width,22rem)!important}[data-persona-root].persona-artifact-narrow-host .persona-artifact-pane.persona-artifact-drawer-open{transform:translate(0)}}@media (max-width:640px){[data-persona-root] .persona-artifact-pane{width:min(100vw, var(--persona-artifact-drawer-width,min(100vw - 1.5rem, 22rem)));z-index:60;transition:transform .2s;position:fixed;top:0;bottom:0;right:0;transform:translate(100%);box-shadow:-4px 0 24px #0000001f}[data-persona-root] .persona-artifact-pane.persona-artifact-drawer-open{transform:translate(0)}}`;const C=e=>h(e,`artifacts`,S);function w(e){let t=String(e).split(/[\\/]/);return t[t.length-1]??``}function T(e){let t=w(e),n=t.lastIndexOf(`.`);return n<=0?``:t.slice(n+1).toLowerCase()}function E(e){if(typeof e!=`string`)return``;let t=e.indexOf(`
2
2
  `);if(t===-1||!e.slice(0,t).startsWith("```"))return e;let n=e.slice(t+1),r=n.lastIndexOf(`
3
3
  `);return(r===-1?n:n.slice(0,r)).split("`​``").join("```")}function te(e){let t=T(e.path);if(t)return t===`html`||t===`htm`?`html`:t===`svg`?`svg`:t===`md`||t===`mdx`?`markdown`:`other`;let n=(e.mimeType||``).toLowerCase();return n.includes(`html`)?`html`:n.includes(`svg`)?`svg`:n.includes(`markdown`)?`markdown`:`other`}function D(e){switch(te(e)){case`html`:return`HTML`;case`svg`:return`SVG`;case`markdown`:return`Markdown`;default:{let t=T(e.path);return t?t.toUpperCase():`File`}}}function O(e){let t=e.markdown??``;return e.file?{filename:w(e.file.path)||`artifact`,mime:e.file.mimeType||`application/octet-stream`,content:E(t)}:{filename:`${e.title||`artifact`}.md`,mime:`text/markdown`,content:t}}function k(e){let t=new Blob([e.content],{type:e.mime}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=e.filename,r.click(),URL.revokeObjectURL(n)}let A=null;const j=e=>{A=e.componentRegistry,g(e.loadingLabels),e.buttons&&(N=e.buttons)},M=()=>A;let N;const P=()=>{if(!N)throw Error(`Artifact UI must be initialized with core button factories before rendering.`);return N},F=(...e)=>P().createIconButton(...e),I=(...e)=>P().createLabelButton(...e),L=(...e)=>P().createSplitButton(...e),ne=(...e)=>P().createToggleGroup(...e),R=`persona-artifact-custom-action-btn`;function re(e,t){let n=t?.documentChrome??!1,r;if(typeof e.icon==`function`){r=e.showLabel?m(`button`,`persona-label-btn persona-label-btn--sm `+R+(n?` persona-artifact-doc-copy-btn`:``)):m(`button`,`persona-icon-btn `+R+(n?` persona-artifact-doc-icon-btn`:``)),r.type=`button`,r.setAttribute(`aria-label`,e.label),r.title=e.label;try{let t=e.icon();t&&r.appendChild(t)}catch{}if(e.showLabel){let t=m(`span`);t.textContent=e.label,r.appendChild(t)}}else r=e.showLabel||!e.icon?I({icon:e.icon,label:e.label,className:R+(n?` persona-artifact-doc-copy-btn`:``)}):F({icon:e.icon,label:e.label,className:R+(n?` persona-artifact-doc-icon-btn`:``)});return t?.onClick&&r.addEventListener(`click`,t.onClick),r}function z(e){if(!e)return null;let t={artifactId:e.id,title:e.title??``,artifactType:e.artifactType};return e.artifactType===`markdown`?(t.markdown=e.markdown??``,e.file&&(t.file=e.file)):t.jsonPayload=JSON.stringify({component:e.component,props:e.props},null,2),t}const B=`http://www.w3.org/2000/svg`;function V(e){let t=document.createElementNS(B,`svg`);t.setAttribute(`class`,f(`persona-spinner`,e)),t.setAttribute(`viewBox`,`0 0 24 24`),t.setAttribute(`aria-hidden`,`true`),t.setAttribute(`focusable`,`false`);let n=document.createElementNS(B,`circle`);n.setAttribute(`class`,`persona-spinner-track`),n.setAttribute(`cx`,`12`),n.setAttribute(`cy`,`12`),n.setAttribute(`r`,`9`);let r=document.createElementNS(B,`circle`);return r.setAttribute(`class`,`persona-spinner-arc`),r.setAttribute(`cx`,`12`),r.setAttribute(`cy`,`12`),r.setAttribute(`r`,`9`),t.appendChild(n),t.appendChild(r),t}function H(e,t,n){e.textContent=t,_(e,{animation:n?.loadingAnimation??`shimmer`,duration:`${n?.loadingAnimationDuration??2e3}ms`,color:n?.loadingAnimationColor,secondaryColor:n?.loadingAnimationSecondaryColor})}const U=`persona-artifact-status-label`,ie=`persona-artifact-status-detail`,ae=`data-artifact-status-label`,oe=/* @__PURE__ */ new Map,se=()=>typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now();function ce(e){e&&oe.delete(e)}function le(e){let t=e.artifactType===`markdown`?e.file:void 0;return t?D(t):e.artifactType===`component`?`Component`:`Document`}function W(e,t,n){let r=le(e),i=`Generating ${r.toLowerCase()}...`,a=t?.statusLabel;if(typeof a==`string`)return{label:a};if(typeof a!=`function`)return{label:i};let o=e.id,s=oe.get(o);e.status!==`complete`&&s===void 0&&(s=se(),oe.set(o,s));let c=s===void 0?0:Math.max(0,se()-s),l=e.artifactType===`component`,u=!l&&typeof e.markdown==`string`?e.markdown:``,d=l?0:u.length,f=l||u===``?0:u.split(`
4
4
  `).length,p=e.artifactType===`markdown`?e.file:void 0,m={artifactId:o,artifactType:e.artifactType,title:e.title,typeLabel:r,file:p,chars:d,lines:f,elapsedMs:c,content:()=>l?``:u,surface:n};try{let e=a(m);return typeof e==`string`?{label:e}:e&&typeof e==`object`&&typeof e.label==`string`?{label:e.label,detail:typeof e.detail==`string`?e.detail:void 0}:{label:i}}catch{return{label:i}}}function ue(e){e.className=U,e.removeAttribute(`data-preserve-animation`),e.style.removeProperty(`--persona-tool-anim-duration`),e.style.removeProperty(`--persona-tool-anim-color`),e.style.removeProperty(`--persona-tool-anim-secondary-color`),e.replaceChildren()}function G(e,t,n){let r=e.querySelector(`:scope > .${U}`);r||(r=m(`span`,U),e.appendChild(r)),r.getAttribute(ae)!==t.label&&(ue(r),H(r,t.label,n),r.setAttribute(ae,t.label));let i=e.querySelector(`:scope > .${ie}`),a=t.detail;a?(i||(i=m(`span`,ie),e.appendChild(i)),i.textContent!==a&&(i.textContent=a)):i&&i.remove()}const K={keyword:`persona-code-token-keyword`,string:`persona-code-token-string`,comment:`persona-code-token-comment`,number:`persona-code-token-number`,tag:`persona-code-token-tag`,attr:`persona-code-token-attr`,property:`persona-code-token-property`},q={html:`html`,htm:`html`,xhtml:`html`,xml:`html`,svg:`html`,css:`css`,js:`js`,jsx:`js`,mjs:`js`,cjs:`js`,ts:`js`,tsx:`js`,mts:`js`,cts:`js`,javascript:`js`,typescript:`js`,ecmascript:`js`,json:`json`,jsonc:`json`,json5:`json`};function J(e,t){let n=(e||``).trim().toLowerCase();if(n&&q[n])return q[n];if(t){let e=t.lastIndexOf(`.`);if(e>=0){let n=t.slice(e+1).toLowerCase();if(q[n])return q[n]}}return null}function de(e,t){let n=[],r=0,i=0,a=t=>{t>i&&n.push({type:`plain`,value:e.slice(i,t)})};for(;r<e.length;){let o=!1;for(let s of t){s.re.lastIndex=r;let t=s.re.exec(e);if(t&&t.index===r&&t[0].length>0){a(r);let e=s.map?s.map(t[0]):s.type;n.push({type:e,value:t[0]}),r+=t[0].length,i=r,o=!0;break}}o||(r+=1)}return a(e.length),n}const fe=/* @__PURE__ */ new Set(/* @__PURE__ */ `abstract.any.as.async.await.boolean.break.case.catch.class.const.continue.debugger.declare.default.delete.do.else.enum.export.extends.false.finally.for.from.function.get.if.implements.import.in.instanceof.interface.keyof.let.namespace.never.new.null.number.object.of.private.protected.public.readonly.return.satisfies.set.static.string.super.switch.symbol.this.throw.true.try.type.typeof.undefined.unknown.var.void.while.yield`.split(`.`)),pe=[{type:`comment`,re:/\/\/[^\n]*/y},{type:`comment`,re:/\/\*[\s\S]*?\*\//y},{type:`string`,re:/`(?:\\[\s\S]|[^\\`])*`/y},{type:`string`,re:/"(?:\\.|[^"\\\n])*"/y},{type:`string`,re:/'(?:\\.|[^'\\\n])*'/y},{type:`number`,re:/0[xX][0-9a-fA-F]+|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y},{type:`plain`,re:/[A-Za-z_$][\w$]*/y,map:e=>fe.has(e)?`keyword`:`plain`}];function me(e){return de(e,pe)}const Y=[{type:`string`,re:/"(?:\\.|[^"\\])*"/y},{type:`number`,re:/-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y},{type:`plain`,re:/[A-Za-z_]\w*/y,map:e=>e===`true`||e===`false`||e===`null`?`keyword`:`plain`}];function he(e){let t=de(e,Y);for(let e=0;e<t.length;e+=1){if(t[e].type!==`string`)continue;let n=e+1;for(;n<t.length&&t[n].value.trim()===``;)n+=1;let r=t[n];r&&r.value.replace(/^\s*/,``).startsWith(`:`)&&(t[e].type=`property`)}return t}const ge=[{type:`comment`,re:/\/\*[\s\S]*?\*\//y},{type:`string`,re:/"(?:\\.|[^"\\\n])*"/y},{type:`string`,re:/'(?:\\.|[^'\\\n])*'/y},{type:`keyword`,re:/@[A-Za-z-]+/y},{type:`number`,re:/#[0-9a-fA-F]{3,8}\b/y},{type:`number`,re:/-?(?:\d+\.?\d*|\.\d+)(?:[a-z%]+)?/y},{type:`plain`,re:/[A-Za-z_-][\w-]*/y}];function _e(e){let t=de(e,ge),n=``;for(let e=0;e<t.length;e+=1){let r=t[e];if(r.type===`plain`&&/^[A-Za-z_-][\w-]*$/.test(r.value)){let i=e+1;for(;i<t.length&&t[i].value.trim()===``;)i+=1;let a=t[i];a&&a.value.replace(/^\s*/,``).startsWith(`:`)&&(n===``||n===`{`||n===`}`||n===`;`||n===`,`)&&(r.type=`property`)}let i=r.value.replace(/\s+$/,``);i&&(n=i[i.length-1])}return t}const X=[{type:`tag`,re:/<\/?\s*[A-Za-z][\w:-]*/y},{type:`string`,re:/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'/y},{type:`attr`,re:/[A-Za-z_:@][\w:.-]*(?=\s*=)/y},{type:`attr`,re:/[A-Za-z_:@][\w:.-]*/y},{type:`tag`,re:/\/?>/y}];function Z(e){let t=[],n=(e,n)=>{n&&t.push({type:e,value:n})},r=e.length,i=0;for(;i<r;){if(e.startsWith(`<!--`,i)){let t=e.indexOf(`-->`,i+4),a=t===-1?r:t+3;n(`comment`,e.slice(i,a)),i=a;continue}if(e[i]===`<`&&e[i+1]===`!`){let t=e.indexOf(`>`,i),a=t===-1?r:t+1;n(`tag`,e.slice(i,a)),i=a;continue}if(e[i]===`<`&&/[A-Za-z/]/.test(e[i+1]||``)){let n=e.indexOf(`>`,i),a=n===-1?r:n+1,o=e.slice(i,a);for(let e of de(o,X))t.push(e);i=a;let s=/^<\s*(script|style)\b/i.exec(o);if(s&&!/\/>\s*$/.test(o)){let n=s[1].toLowerCase(),a=RegExp(`</\\s*`+n+`\\s*>`,`i`).exec(e.slice(i)),o=a?i+a.index:r,c=e.slice(i,o),l=n===`script`?me(c):_e(c);for(let e of l)t.push(e);i=o}continue}let a=e.indexOf(`<`,i);if(a===i)n(`plain`,e[i]),i+=1;else{let t=a===-1?r:a;n(`plain`,e.slice(i,t)),i=t}}return t}function ve(e,t){switch(t){case`html`:return Z(e);case`css`:return _e(e);case`js`:return me(e);case`json`:return he(e)}}function ye(e){let t=p(),n=m(`span`,`persona-code-line`),r=(e,t)=>{if(!t)return;let r=K[e];if(r){let e=m(`span`,r);e.textContent=t,n.appendChild(e)}else n.appendChild(document.createTextNode(t))};for(let i of e){let e=i.value.split(`
@@ -0,0 +1,2 @@
1
+ const e=(e,t)=>({ok:!1,reason:e,message:t}),t=e=>e.startsWith(`webmcp:`)?e.slice(7):e,n={warn(e,...t){typeof console<`u`&&typeof console.warn==`function`&&console.warn(`[Persona/WebMCP] ${e}`,...t)}};var r=class{#e;#t;#n=!1;#r=null;#i=!1;#a;constructor(e,t){this.config=e,this.#a=t,this.#e=e.onConfirm??null,this.#t=3e4}setConfirmHandler(e){this.#e=e}isOperational(){return this.config.enabled!==!0||!this.#n?!1:this.#l()!==null}async snapshotForDispatch(){if(await this.#s(),this.config.enabled!==!0)return[];let e=this.#l();if(!e)return[];let t;try{t=(await e.getTools()).filter(h)}catch(e){return n.warn(`getTools() threw: shipping an empty WebMCP snapshot.`,e),[]}this.#a.recordToolDisplayTitles(t);let r=typeof location<`u`?location.origin:``;return t.filter(e=>this.#f(e.name)).map(e=>{let t=o(e.annotations);return{name:e.name,description:e.description,parametersSchema:s(e.inputSchema),origin:`webmcp`,...r?{pageOrigin:r}:{},...t?{annotations:t}:{},...t?.untrustedContentHint===!0?{untrustedContentHint:!0}:{}}})}async executeToolCall(e,t,n,r){let i=await this.#o(e,t,n,!1,r);return i.ok?c(i.raw):u(i.message)}async executeVoiceToolCall(e,t,n={}){let r=await this.#o(e,t,n.signal,n.autoConfirmReadOnly===!0);return r.ok?f(r.raw):{status:r.reason===`aborted`?`failed`:r.reason,error:{message:r.message}}}watchToolChanges(e){let t=!1,n=null;return this.#s().then(()=>{if(t||this.config.enabled!==!0)return;let r=this.#l();r&&typeof r.addEventListener==`function`&&(n=r,n.addEventListener(`toolchange`,e))}),()=>{t=!0,n?.removeEventListener(`toolchange`,e),n=null}}async#o(n,r,i,a,s){if(await this.#s(),this.config.enabled!==!0)return e(`failed`,`WebMCP is not enabled on this widget.`);let c=this.#l();if(!c){let t=typeof document<`u`&&!!document.modelContext;return e(`failed`,t?`WebMCP is not operational: document.modelContext is present but does not expose the strict getTools()/executeTool() surface (likely a different or older WebMCP polyfill).`:`WebMCP bridge is not operational on this page (document.modelContext not available).`)}let u=t(n),d;try{d=(await c.getTools()).filter(h)}catch(t){let n=t instanceof Error?t.message:String(t);return e(`failed`,`Failed to read WebMCP registry: ${n}`)}this.#a.recordToolDisplayTitles(d);let f=d.find(e=>e.name===u);if(!f)return e(`stale`,`WebMCP tool not registered on this page: ${u}`);if(!this.#f(u))return e(`stale`,`WebMCP tool not allowed by client allowlist: ${u}`);if(i?.aborted)return e(`aborted`,`Aborted by cancel()`);let p=this.#a.getToolDisplayTitle(u),m=o(f.annotations),g={toolName:u,...s?{toolCallId:s}:{},args:r,description:f.description,...m?{annotations:m}:{},...p?{title:p}:{},...i?{signal:i}:{},reason:`gate`},_=this.#d(u);if(_&&(g.confirmRequired=!0),(_||!a||m?.readOnlyHint!==!0)&&!await this.#u(g))return e(`denied`,`User declined the tool call.`);if(i?.aborted)return e(`aborted`,`Aborted by cancel()`);let v=new AbortController,y=!1,b=setTimeout(()=>{y=!0,v.abort()},this.#t),x=()=>v.abort();i&&(i.aborted?v.abort():i.addEventListener(`abort`,x,{once:!0}));try{return{ok:!0,raw:await c.executeTool(f,l(r),{signal:v.signal})}}catch(t){if(y)return e(`timeout`,`WebMCP tool '${u}' timed out after ${this.#t}ms`);if(i?.aborted)return e(`aborted`,`Aborted by cancel()`);let n=t instanceof Error?t.message:String(t);return e(`failed`,n)}finally{clearTimeout(b),i&&i.removeEventListener(`abort`,x)}}#s(){return this.config.enabled===!0?(this.#r||=this.#c(),this.#r):Promise.resolve()}async#c(){try{if(this.#l()){this.#n=!0;return}let e=await this.#a.loadPolyfill();`initializeWebMCPPolyfill`in e?e.initializeWebMCPPolyfill():e.installWebMCP(),this.#n=!0}catch(e){n.warn(`Failed to load @mcp-b/webmcp-polyfill: WebMCP consumption disabled.`,e),this.#n=!1}}#l(){if(typeof document>`u`)return null;let e=document.modelContext;if(!e||typeof e!=`object`)return null;let t=e;return typeof t.getTools!=`function`||typeof t.executeTool!=`function`?(this.#i||(this.#i=!0,n.warn(`document.modelContext is present but does not expose getTools()/executeTool(): WebMCP consumption is disabled. Another (incompatible or older) WebMCP polyfill likely installed document.modelContext before Persona. Remove it, or use a polyfill implementing the strict standard surface (e.g. @mcp-b/webmcp-polyfill).`)),null):e}async#u(e){let t=this.#e??p;try{return await t(e)}catch(t){return n.warn(`Confirm handler threw for WebMCP tool '${e.toolName}'; declining.`,t),!1}}#d(e){let t;try{t=this.#a.getRequireConfirmFor?.()}catch{t=null}if(t===null)return!0;let n=t=>Array.isArray(t)&&t.some(t=>typeof t==`string`&&i(e,t));return n(this.config.requireConfirmFor)||n(t)}#f(e){let t=this.config.allowlist;return!t||t.length===0||t.some(t=>i(e,t))}};const i=(e,t)=>{if(t===`*`)return!0;let n=t.replace(/[.+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`^`+n.replace(/\*/g,`.*`)+`$`).test(e)},a={type:`object`,properties:{}},o=e=>{if(!e||typeof e!=`object`)return;let t={};for(let n of[`readOnlyHint`,`destructiveHint`,`consequentialHint`,`untrustedContentHint`,`idempotentHint`,`openWorldHint`,`debugging`]){let r=e[n];typeof r==`boolean`&&(t[n]=r)}return Object.keys(t).length>0?t:void 0},s=e=>{if(e===void 0||e===``)return{...a};if(typeof e==`object`)return e!==null&&!Array.isArray(e)?e:{...a};try{let t=JSON.parse(e);return typeof t==`object`&&t&&!Array.isArray(t)?t:{...a}}catch{return{...a}}},c=e=>{if(e==null)return{content:[{type:`text`,text:``}]};let t;try{t=JSON.parse(e)}catch{return{content:[{type:`text`,text:e}]}}return typeof t==`object`&&t&&Array.isArray(t.content)?t:{content:[{type:`text`,text:typeof t==`string`?t:g(t)}]}},l=e=>{let t;try{t=JSON.stringify(e)??`{}`}catch{t=`{}`}let n=JSON.parse(t);if(typeof n!=`object`||!n)throw TypeError(`WebMCP tool arguments must be an object or array.`);return Object.defineProperty(n,Symbol.toPrimitive,{value:()=>t}),n},u=e=>({isError:!0,content:[{type:`text`,text:e}]}),d=e=>Array.isArray(e)?e.map(e=>e&&typeof e==`object`&&typeof e.text==`string`?e.text:``).filter(Boolean).join(`
2
+ `):``,f=e=>{if(e==null)return{status:`completed`};let t;try{t=JSON.parse(e)}catch{return{status:`completed`,result:e}}return typeof t==`object`&&t&&t.isError===!0?{status:`failed`,error:{message:d(t.content)||`The page tool reported an error.`}}:t===void 0?{status:`completed`}:{status:`completed`,result:t}},p=async e=>{if(typeof window>`u`||typeof window.confirm!=`function`)return!1;let t=m(e.args),n=`Allow the AI to call ${e.toolName}`+(t?`\n\nArguments:\n${t}`:``)+(e.description?`\n\n${e.description}`:``);return window.confirm(n)},m=e=>{if(e==null)return``;try{let t=JSON.stringify(e,null,2);return t.length>500?t.slice(0,500)+`…`:t}catch{return String(e)}},h=e=>(e.window===void 0||typeof window<`u`&&e.window===window)&&(e.origin===void 0||typeof location<`u`&&e.origin===location.origin),g=e=>{if(e===void 0)return``;try{return JSON.stringify(e)}catch{return String(e)}};export{r as WebMcpBridge};
@@ -0,0 +1 @@
1
+ const e=e=>e.nodeType===Node.DOCUMENT_NODE,t=e=>e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&e.host!==void 0;function n(n){let r=n.getRootNode?.();return r&&t(r)||r&&e(r)?r:n.ownerDocument??document}function r(t,n,r){let i=e(t)?t.head:t,a=n.replace(/["\\]/g,`\\$&`);if(i.querySelector(`style[data-persona-plugin-style="${a}"]`))return;let o=(e(t)?t:t.ownerDocument??document).createElement(`style`);o.setAttribute(`data-persona-plugin-style`,n),o.textContent=r,i.appendChild(o)}function i(i,a,o){if(e(i)||t(i)){r(i,a,o);return}let s=i;if(s.isConnected){r(n(s),a,o);return}let c=s.ownerDocument??document;r(c,a,o),queueMicrotask(()=>{let e=n(s);e!==c&&r(e,a,o)})}function a(e){let t=e.getRootNode?.();return t instanceof ShadowRoot?t:e.closest(`dialog[open]`)??(e.ownerDocument??document).body}function o(e){let{anchor:t,content:n,placement:r=`bottom-start`,offset:i=6,matchAnchorWidth:o=!1,horizontalOffset:s,verticalOffset:c,zIndex:l=2147483e3,onOpen:u,onDismiss:d}=e,f=()=>e.container??a(t),p=!1,m=null,h=[],g=()=>{let e=t.closest(`[data-persona-root]`);if(!e||e.contains(n))return;let{style:r}=e;for(let e of h)r.getPropertyValue(e)||n.style.removeProperty(e);h=Array.from(r).filter(e=>e.startsWith(`--`));for(let e of h)n.style.setProperty(e,r.getPropertyValue(e));for(let t of[`data-persona-color-scheme`,`data-persona-defaults`]){let r=e.getAttribute(t);r?n.setAttribute(t,r):n.removeAttribute(t)}},_=()=>{if(!p)return;let a=f();if(n.parentNode!==a){let e=n.contains(n.ownerDocument.activeElement)?n.ownerDocument.activeElement:null;a.appendChild(n),g(),e?.focus({preventScroll:!0})}let l=e.getAnchorRect?.()??t.getBoundingClientRect();n.style.position=`fixed`,o&&(n.style.minWidth=`${l.width}px`),s&&(n.style.maxWidth=`${l.width}px`);let u=n.getBoundingClientRect(),d=c?.()??null,m=d==null?l.top:l.top+d,h=e.getPlacement?.()??r,_=h===`top-start`||h===`top-end`?m-i-u.height:l.bottom+i,v=h===`bottom-end`||h===`top-end`?l.right-u.width:l.left,y=s?.()??null;if(y!=null){let e=Math.max(l.left,l.right-u.width);v=Math.min(Math.max(l.left+y,l.left),e)}if(e.viewportPadding!==void 0){let n=e.viewportPadding,r=t.ownerDocument.defaultView,a=r?.innerHeight??0,o=r?.innerWidth??0,s=m-i-n,c=a-l.bottom-i-n;_=(h.startsWith(`top`)?s>=u.height||s>=c:!(c>=u.height||c>=s))?m-i-u.height:l.bottom+i,_=Math.max(n,Math.min(_,a-n-u.height)),v=Math.max(n,Math.min(v,o-n-u.width))}n.style.top=`${_}px`,n.style.left=`${v}px`},v=()=>{p&&(p=!1,m&&=(m(),null),n.remove())},y=()=>{if(p)return;p=!0,l!=null&&(n.style.zIndex=String(l)),_();let r=(t.ownerDocument??document).defaultView??window,i=t.ownerDocument??document,a=()=>{t.isConnected?_():(v(),d?.(`anchor-removed`))},o=e=>{let r=typeof e.composedPath==`function`?e.composedPath():[];r.includes(n)||r.includes(t)||(v(),d?.(`outside`))},s=e.viewportPadding!==void 0&&r.ResizeObserver?new r.ResizeObserver(a):null;s?.observe(n),s?.observe(t);let c=r.setTimeout(()=>{i.addEventListener(`pointerdown`,o,!0)},0);r.addEventListener(`scroll`,a,!0),r.addEventListener(`resize`,a);let f=t.closest(`[data-persona-root]`);f?.addEventListener(`persona:internal:host-moved`,a);let h;f&&r.MutationObserver&&(h=new r.MutationObserver(g),h.observe(f,{attributeFilter:[`style`,`data-persona-color-scheme`]})),m=()=>{s?.disconnect(),h?.disconnect(),r.clearTimeout(c),i.removeEventListener(`pointerdown`,o,!0),r.removeEventListener(`scroll`,a,!0),r.removeEventListener(`resize`,a),f?.removeEventListener(`persona:internal:host-moved`,a)},u?.()};return{get isOpen(){return p},open:y,close:v,toggle:()=>p?v():y(),reposition:_,destroy:v}}function s(e){return(typeof e.composedPath==`function`?e.composedPath():[]).some(e=>e instanceof HTMLElement&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable))}export{i as n,s as r,o as t};
@@ -0,0 +1 @@
1
+ import{i as e,r as t,t as n}from"./chunk-D5BxWOFB.js";import{n as r,t as i}from"./chunk-Cd8mp8Sv.js";import{n as a,r as o,t as s}from"./chunk-Dv6KtIT1.js";var c=`.persona-composer-overflow-menu{gap:var(--persona-components-composer-overflowMenu-rowGap,2px);min-width:min(var(--persona-components-composer-overflowMenu-minWidth,180px), calc(100vw - 16px));box-sizing:border-box;max-width:calc(100vw - 16px);max-height:min(var(--persona-components-composer-overflowMenu-maxHeight,320px), calc(100vh - 16px));padding:var(--persona-components-composer-overflowMenu-padding,4px);border-radius:var(--persona-components-composer-overflowMenu-borderRadius,var(--persona-radius-lg,.5rem));border:1px solid var(--persona-components-composer-overflowMenu-borderColor,var(--persona-border,#e5e7eb));background:var(--persona-components-composer-overflowMenu-background,var(--persona-surface,#fff));color:var(--persona-components-composer-overflowMenu-foreground,var(--persona-text,#111827));box-shadow:var(--persona-components-composer-overflowMenu-shadow,var(--persona-shadow-md,0 8px 24px #0000001f));font-family:var(--persona-font-family,inherit);line-height:var(--persona-components-composer-overflowMenu-lineHeight,1.35);flex-direction:column;display:flex;overflow-y:auto}.persona-composer-overflow-menu__item{align-items:center;gap:var(--persona-components-composer-overflowMenu-iconGap,8px);width:100%;padding:var(--persona-components-composer-overflowMenu-rowPadding,6px 8px);border-radius:var(--persona-components-composer-overflowMenu-rowBorderRadius,var(--persona-radius-md,.375rem));color:inherit;font-family:inherit;font-size:var(--persona-components-composer-overflowMenu-fontSize,13px);text-align:start;cursor:pointer;background:0 0;border:none;display:flex}.persona-composer-overflow-menu__item:hover:not(:disabled){background:var(--persona-components-composer-overflowMenu-hoverBackground,var(--persona-button-ghost-hover-bg,#0000000d))}.persona-composer-overflow-menu__item:focus-visible{background:var(--persona-components-composer-overflowMenu-focusBackground,var(--persona-button-ghost-hover-bg,#0000000d))}.persona-composer-overflow-menu__item[aria-pressed=true]{background:var(--persona-button-ghost-hover-bg,#0000000d);font-weight:600}.persona-composer-overflow-menu__item:disabled{opacity:.5;cursor:default}.persona-composer-overflow-menu__item[aria-busy=true]{opacity:.6;cursor:progress}.persona-composer-overflow-menu__icon{width:var(--persona-components-composer-overflowMenu-iconSize,16px);height:var(--persona-components-composer-overflowMenu-iconSize,16px);flex:none;align-items:center;display:inline-flex}.persona-composer-overflow-menu__content{display:contents}.persona-composer-overflow-menu__text{flex-direction:column;min-width:0;display:flex}.persona-composer-overflow-menu__icon>svg{width:100%;height:100%}.persona-composer-overflow-menu__description{color:var(--persona-components-composer-overflowMenu-descriptionColor,var(--persona-text-muted,#6b7280));font-size:var(--persona-components-composer-overflowMenu-descriptionFontSize,12px);line-height:var(--persona-components-composer-overflowMenu-lineHeight,1.35);white-space:normal;display:block}.persona-composer-overflow-menu[data-persona-menu-description-layout=inline] .persona-composer-overflow-menu__text,.persona-composer-overflow-menu[data-persona-menu-description-layout=inline] .persona-composer-overflow-menu__slot>.persona-composer-overflow-menu__label{align-items:baseline;gap:0 var(--persona-components-composer-overflowMenu-iconGap,8px);flex-flow:wrap;display:flex}.persona-composer-overflow-menu__divider{border-top:1px solid var(--persona-components-composer-overflowMenu-dividerColor,var(--persona-border,#e5e7eb));margin:var(--persona-components-composer-overflowMenu-dividerSpacing,4px 0);flex-shrink:0}.persona-composer-overflow-menu__label{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.persona-composer-overflow-menu__slot{align-items:center;gap:var(--persona-components-composer-overflowMenu-iconGap,8px);width:100%;padding:var(--persona-components-composer-overflowMenu-rowPadding,6px 8px);border-radius:var(--persona-components-composer-overflowMenu-rowBorderRadius,var(--persona-radius-md,.375rem));font-size:var(--persona-components-composer-overflowMenu-fontSize,13px);text-align:start;cursor:pointer;display:flex}.persona-composer-overflow-menu__slot:hover{background:var(--persona-components-composer-overflowMenu-hoverBackground,var(--persona-button-ghost-hover-bg,#0000000d))}.persona-composer-overflow-menu__slot[data-persona-menu-focus]{background:var(--persona-components-composer-overflowMenu-focusBackground,var(--persona-button-ghost-hover-bg,#0000000d))}.persona-composer-overflow-menu__slot .persona-send-button-wrapper{display:contents}.persona-composer-overflow-menu__slot .persona-composer-control{width:var(--persona-components-composer-overflowMenu-iconSize,16px);height:var(--persona-components-composer-overflowMenu-iconSize,16px);min-width:var(--persona-components-composer-overflowMenu-iconSize,16px);min-height:var(--persona-components-composer-overflowMenu-iconSize,16px);box-shadow:none;color:inherit;cursor:inherit;background:0 0;border:none;border-radius:0;flex:none;padding:0;line-height:1;overflow:hidden}.persona-composer-overflow-menu__slot .persona-composer-control>svg{width:var(--persona-components-composer-overflowMenu-iconSize,16px);height:var(--persona-components-composer-overflowMenu-iconSize,16px)}.persona-composer-overflow-menu__slot .persona-composer-control:focus-visible{outline:none}.persona-composer-overflow-menu__slot .persona-control-tooltip{display:none}.persona-composer-segmented{align-items:center;gap:var(--persona-components-composer-segmented-gap,2px);padding:var(--persona-components-composer-segmented-padding,2px);border-radius:var(--persona-components-composer-segmented-trackBorderRadius,9999px);background:var(--persona-components-composer-segmented-trackBackground,var(--persona-container,#f3f4f6));flex:none;display:inline-flex}.persona-composer-segmented-item{cursor:pointer;white-space:nowrap;box-shadow:none;font-family:inherit;font-size:var(--persona-components-composer-segmented-fontSize,var(--persona-composer-font-size,.875rem));line-height:var(--persona-components-composer-segmented-lineHeight,var(--persona-composer-line-height,1.25rem));font-weight:var(--persona-components-composer-segmented-fontWeight,normal);min-height:var(--persona-components-composer-segmented-minHeight,0px);padding:var(--persona-components-composer-segmented-itemPadding,.25rem .625rem);border-radius:var(--persona-components-composer-segmented-trackBorderRadius,9999px);color:var(--persona-components-composer-segmented-inactiveForeground,var(--persona-muted,#6b7280));background:0 0;border:none;align-items:center;gap:.375rem;display:inline-flex}.persona-composer-segmented-item[aria-pressed=true]{background:var(--persona-components-composer-segmented-activeBackground,var(--persona-surface,#fff));color:var(--persona-components-composer-segmented-activeForeground,var(--persona-text,#111827));box-shadow:var(--persona-components-composer-segmented-activeShadow,0 1px 2px 0 #0f172a1f)}.persona-composer-segmented-item svg{flex:none}@media (pointer:coarse){.persona-composer-segmented-item{min-height:36px}}.persona-composer-model-picker-wrapper{align-items:center;display:inline-grid}.persona-composer-model-picker-wrapper>*{grid-area:1/1}[data-persona-root] .persona-composer-model-picker{max-width:10rem;height:var(--persona-components-composer-modelPicker-height,var(--persona-composer-control-size,40px));min-height:var(--persona-components-composer-modelPicker-height,var(--persona-composer-control-size,40px));width:auto;min-width:var(--persona-components-composer-modelPicker-minWidth,0px);line-height:var(--persona-components-composer-modelPicker-height,var(--persona-composer-control-size,40px));padding-block:0;padding-inline:.625rem 1.75rem;padding-inline:var(--persona-components-composer-modelPicker-paddingInline,.625rem 1.75rem);border-radius:var(--persona-components-composer-modelPicker-borderRadius,var(--persona-button-ghost-radius,var(--persona-radius-md,.375rem)));background-color:var(--persona-components-composer-modelPicker-background,var(--persona-button-ghost-bg,transparent));color:var(--persona-components-composer-modelPicker-labelColor,var(--persona-button-ghost-fg,var(--persona-text,#111827)));box-shadow:inset 0 0 0 1px var(--persona-components-composer-modelPicker-borderColor,transparent);font-family:inherit;font-size:var(--persona-components-composer-modelPicker-fontSize,.8125rem);font-weight:var(--persona-components-composer-modelPicker-fontWeight,normal);cursor:pointer;appearance:none;text-overflow:ellipsis;white-space:nowrap;text-align:start;border:none;overflow:hidden}.persona-composer-model-picker-chevron{pointer-events:none;background-color:var(--persona-components-composer-modelPicker-labelColor,var(--persona-button-ghost-fg,var(--persona-text,#111827)));justify-self:end;width:.875rem;height:.875rem;margin-inline-end:.625rem;-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");-webkit-mask-position:50%;mask-position:50%;-webkit-mask-size:contain;mask-size:contain;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat}[data-persona-root] .persona-composer-model-picker option{line-height:normal}@media (pointer:coarse){[data-persona-root] .persona-composer-model-picker{min-width:40px;min-height:40px}}[data-persona-root] .persona-composer-model-picker:hover:not(:disabled){background-color:var(--persona-components-composer-modelPicker-hoverBackground,var(--persona-button-ghost-hover-bg,#0000000d))}[data-persona-root] .persona-composer-model-picker:disabled{opacity:.5;cursor:default}[data-persona-root] .persona-composer-model-picker-trigger{align-items:center;gap:.25rem;display:inline-flex}.persona-composer-model-picker-label{text-overflow:ellipsis;white-space:nowrap;color:var(--persona-components-composer-modelPicker-labelColor,inherit);overflow:hidden}.persona-composer-model-picker-suffix{color:var(--persona-components-composer-modelPicker-suffixColor,var(--persona-muted,#6b7280));flex:none}.persona-composer-model-picker-suffix:empty{display:none}.persona-composer-model-menu{border-radius:var(--persona-components-composer-modelPicker-menuBorderRadius,var(--persona-radius-lg,.5rem));border:1px solid var(--persona-border,#e5e7eb);background:var(--persona-components-composer-modelPicker-menuBackground,var(--persona-surface,#fff));min-width:220px;max-height:320px;color:var(--persona-text,#111827);box-shadow:var(--persona-shadow-md,0 8px 24px #0000001f);font-family:var(--persona-font-family,inherit);flex-direction:column;gap:2px;padding:4px;display:flex;overflow-y:auto}.persona-composer-model-option{border-radius:var(--persona-radius-md,.375rem);width:100%;color:inherit;text-align:start;cursor:pointer;background:0 0;border:none;align-items:flex-start;gap:8px;padding:6px 8px;font-family:inherit;font-size:13px;display:flex}.persona-composer-model-option:hover,.persona-composer-model-option:focus{background:var(--persona-components-composer-modelPicker-rowHoverBackground,var(--persona-button-ghost-hover-bg,#0000000d));outline:none}.persona-composer-model-option-icon,.persona-composer-model-option-check{flex:none;align-items:center;margin-top:1px;display:inline-flex}.persona-composer-model-option-check{visibility:hidden}.persona-composer-model-option[aria-selected=true] .persona-composer-model-option-check{visibility:visible}.persona-composer-model-option-body{flex-direction:column;flex:auto;gap:2px;min-width:0;display:flex}.persona-composer-model-option-label{color:var(--persona-components-composer-modelPicker-labelColor,inherit)}.persona-composer-model-option-description{color:var(--persona-components-composer-modelPicker-descriptionColor,var(--persona-muted,#6b7280));font-size:12px;line-height:1.35}.persona-composer-mode-chip{background:var(--persona-mode-chip-bg,var(--persona-container,#f3f4f6));border-color:var(--persona-mode-chip-border,var(--persona-border,#e5e7eb));color:var(--persona-mode-chip-fg,var(--persona-text,#111827))}[data-persona-composer-expanded] .persona-widget-composer:not(.persona-pill-composer) :is(.persona-widget-composer__actions,.persona-widget-composer__left-actions,.persona-widget-composer__right-actions,.persona-composer-segmented){flex-wrap:wrap;min-width:0;max-width:100%}[data-persona-composer-expanded] .persona-widget-composer:not(.persona-pill-composer) :is(.persona-composer-control,.persona-composer-model-picker,.persona-composer-segmented-item){max-width:100%}[data-persona-composer-expanded] .persona-widget-composer:not(.persona-pill-composer) :is(.persona-composer-action-button,.persona-composer-model-picker,.persona-composer-segmented-item){text-overflow:ellipsis;overflow:hidden}[data-persona-composer-crowded] .persona-widget-composer:not(.persona-pill-composer) .persona-composer-model-picker-wrapper{max-width:min(100%,16rem)}`;const l=e=>r(e,`composer-actions`,c),u=`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`,d=`data-persona-menu-focus`,f=/* @__PURE__ */ new Set([`ArrowDown`,`ArrowUp`,`Home`,`End`]);function p(e){return e.getAttribute(`role`)===`menuitem`?e:e.querySelector(u)??e}const m=e=>e.disabled===!0||e.getAttribute(`aria-disabled`)===`true`;function h(e){let{renderLucideIcon:r,attachTooltip:o}=e.deps,c=e.label,h=!1,g=!1,_=!1,v=!1,y=!0,b=n(`div`,`persona-send-button-wrapper`),x=t(`button`,{className:`persona-rounded-button persona-flex persona-items-center persona-justify-center persona-cursor-pointer persona-composer-action-button persona-composer-overflow-trigger ${s} ${a}`,attrs:{type:`button`,"aria-haspopup":`menu`,"aria-expanded":`false`,"data-persona-composer-overflow-trigger":``}});b.appendChild(x);let S=t(`div`,{className:`persona-composer-overflow-menu`,attrs:{role:`menu`,tabindex:`-1`,"data-persona-composer-overflow-menu":``}}),C=()=>{let t=e.getButtonSize?.()??``;x.style.width=t,x.style.height=t,x.style.minWidth=t,x.style.minHeight=t,x.style.lineHeight=`1`,x.replaceChildren();let n=r((B()?e.getConfig?.()?.openTriggerIconName:void 0)??e.getConfig?.()?.triggerIconName??`plus`,24,`currentColor`,1.5);n?x.appendChild(n):x.textContent=`+`},ee=()=>{x.setAttribute(`aria-label`,c),S.setAttribute(`aria-label`,c)};ee();let w=o({anchor:x,trigger:b,text:()=>x.getAttribute(`aria-expanded`)===`true`?``:c}),T=[],E=-1,D=!1,O=()=>{let e=S.getRootNode().activeElement;return e instanceof HTMLElement?e:null},k=()=>{let e=O();for(let t of T){let n=!!e&&p(t)===e;t.toggleAttribute(d,n&&D)}},A=()=>T.filter(e=>e.isConnected||S.contains(e)).map(p).filter(e=>!m(e)),j=(e,t)=>{e.forEach((e,n)=>{e.setAttribute(`tabindex`,n===t?`0`:`-1`)})},M=e=>{let t=A();if(t.length===0)return;let n=(e%t.length+t.length)%t.length;E=n,j(t,n),t[n].focus(),k()},N=()=>b.ownerDocument??document,P=null,F=null,I=null,te=()=>{P&&=(N().removeEventListener(`focusin`,P,!0),null)},L=()=>{F&&=(S.removeEventListener(`focusin`,F),null),I&&=(S.removeEventListener(`pointerdown`,I,!0),null)},R=null,z=()=>(R||=i({anchor:x,getAnchorRect:()=>{if(e.getConfig?.()?.width===`composer`){let t=e.getComposer?.()?.getBoundingClientRect();if(t)return S.style.width=`${t.width}px`,t}return x.getBoundingClientRect()},content:S,placement:`top-start`,getPlacement:()=>e.getConfig?.()?.placement===`below`?`bottom-start`:`top-start`,viewportPadding:8,offset:6,onDismiss:()=>{ne()}}),R),B=()=>R?.isOpen===!0,ne=()=>{v=!0,g=!1,x.setAttribute(`aria-expanded`,`false`),te(),L(),E=-1,D=!1;for(let e of T)e.removeAttribute(d);try{e.onClose?.()}finally{v=!1}C()},V=(e=!1)=>{(B()||g)&&(R?.close(),ne(),e&&!h&&x.focus())},H=()=>{S.setAttribute(`data-persona-menu-description-layout`,e.getConfig?.()?.descriptionLayout??`stacked`);let t=e.getConfig?.()?.width;S.style.width=t===`composer`?`${e.getComposer?.()?.getBoundingClientRect().width??0}px`:t&&t!==`content`?t:``,C(),R?.reposition()};C();let U=(t=0,n=!1)=>{if(h||_||v||B())return;l(x),w.hide(),g=!0,_=!0;let r;try{r=e.beforeOpen?.()}finally{_=!1}if(r===!1||!g||h)g&&V();else{if(D=n,H(),z().open(),g=!1,x.setAttribute(`aria-expanded`,`true`),C(),y){let e=A();j(e,-1),M(t<0?e.length-1:t),e.length||S.focus()}else(Array.from(S.querySelectorAll(u)).find(e=>!m(e)&&!e.closest(`[hidden]`))??S).focus();B()&&!h&&(P=e=>{let t=typeof e.composedPath==`function`?e.composedPath():[];t.includes(S)||t.includes(b)||V()},N().addEventListener(`focusin`,P,!0),F=()=>k(),S.addEventListener(`focusin`,F),I=()=>{D=!1},S.addEventListener(`pointerdown`,I,!0))}},W=e=>{e.preventDefault(),e.stopPropagation(),B()?V(!0):U(0)},G=e=>{e.key===`ArrowDown`||e.key===`Enter`||e.key===` `?(e.preventDefault(),D=!0,B()?y?M(0):S.focus():U(0,!0)):e.key===`ArrowUp`&&(e.preventDefault(),D=!0,B()?y?M(-1):S.focus():U(-1,!0))},K=e=>{if(!y)e.key===`Escape`&&!e.defaultPrevented&&(e.preventDefault(),e.stopPropagation(),V(!0));else switch(f.has(e.key)&&(D=!0),e.key){case`ArrowDown`:e.preventDefault(),M(E+1);return;case`ArrowUp`:e.preventDefault(),M(E-1);return;case`Home`:e.preventDefault(),M(0);return;case`End`:e.preventDefault(),M(A().length-1);return;case`Escape`:e.preventDefault(),e.stopPropagation(),V(!0);return;case`Tab`:V(!0);return}};return x.addEventListener(`click`,W),x.addEventListener(`keydown`,G),S.addEventListener(`keydown`,K),{trigger:b,triggerButton:x,panel:S,setItems:e=>{for(let t of T)e.includes(t)||t.removeAttribute(d);if(T=[...e],!B()||!y)return;let t=A();j(t,Math.min(E,t.length-1)),k()},isOpen:B,open:()=>U(0),close:V,setLabel:e=>{e!==c&&(c=e,ee(),w.isOpen&&(w.hide(),w.show()))},applyButtonSize:C,refresh:H,setContentMode:(e,t)=>{let n=t&&!y&&B();y=t,S.setAttribute(`role`,e),x.setAttribute(`aria-haspopup`,e),n&&M(0)},destroy:()=>{h=!0,V(),w.destroy(),te(),L(),x.removeEventListener(`click`,W),x.removeEventListener(`keydown`,G),S.removeEventListener(`keydown`,K),R?.destroy(),R=null,b.remove(),S.remove(),T=[]}}}function g(e,t,n,r){return e<=0?r:e>=t+n*2+120+(r?0:16)}const _=e=>Number.parseFloat(e)||0;function v(e,t){let n=t.getComputedStyle(e);if(n.display===`none`)return 0;let r=Array.from(e.children).filter(e=>{if(!(e instanceof t.HTMLElement))return!1;let n=t.getComputedStyle(e);return n.display!==`none`&&![`absolute`,`fixed`].includes(n.position)});return r.reduce((e,n)=>{let r=t.getComputedStyle(n);return e+(r.display===`contents`?v(n,t):Math.max(n.getBoundingClientRect().width,n.scrollWidth))+_(r.marginLeft)+_(r.marginRight)},0)+Math.max(0,r.length-1)*_(n.columnGap)+_(n.paddingLeft)+_(n.paddingRight)}function y(e){let t=null,n=null,r=null,i=null,a=0,o=!0,s=!1,c=!1,l=()=>{i!==null&&t?.form.ownerDocument.defaultView?.cancelAnimationFrame(i),i=null,n?.disconnect(),r?.disconnect(),n=null,r=null,t?.form.ownerDocument.defaultView?.removeEventListener(`resize`,u)},u=()=>{if(c||i!==null)return;let n=t?.form.ownerDocument.defaultView;n&&(i=n.requestAnimationFrame(()=>{i=null,c||e.onMeasure()}))};return{measure:()=>{if(c)return o;let i=e.getSurface();if(i?.form!==t?.form||i?.input!==t?.input||i?.start!==t?.start||i?.end!==t?.end){l(),t=i,o=!0,s=!1,a=0;let e=t?.form.ownerDocument.defaultView;if(t&&e){if(e.addEventListener(`resize`,u),e.ResizeObserver!==void 0){n=new e.ResizeObserver(u);let r=[t.form,t.start,t.end,t.input];for(let e of r)n.observe(e)}e.MutationObserver!==void 0&&(r=new e.MutationObserver(e=>{e.some(e=>e.target!==t?.input||e.type!==`attributes`)&&u()}),r.observe(t.form,{subtree:!0,childList:!0,characterData:!0,attributes:!0,attributeFilter:[`class`,`style`,`hidden`]}))}}t&&i&&(t.resizeInput=i.resizeInput);let d=t?.form.ownerDocument.defaultView;if(!t||!d)return!0;if(!t.form.clientWidth)return o;let f=d.getComputedStyle(t.form),p=Math.max(1,t.form.clientWidth-_(f.paddingLeft)-_(f.paddingRight)),m=v(t.start,d)+v(t.end,d),h=_(f.columnGap);s=m+h+(s?16:0)>p,o=g(p,m,h,o);let y=t.input.getBoundingClientRect().width;if(t.resizeInput!==!1&&y>0&&y!==a&&t.input.tagName===`TEXTAREA`){a=y,t.input.style.height=`auto`;let e=_(d.getComputedStyle(t.input).maxHeight)||1/0,n=Math.min(t.input.scrollHeight,e);t.input.style.height=`${n}px`}return o},toolbarCrowded:()=>s,refresh:u,destroy:()=>{c=!0,l(),t=null}}}function b(e){if(e.available<=0)return new Set(e.previous);let t=t=>{let n={start:{...e.slots.start},end:{...e.slots.end}};for(let r of e.actions){if(t.has(r.id))continue;let e=n[r.placement];e.width+=r.width,e.count+=1}return(e.hasMenu||t.size)&&(n.start.width+=e.triggerWidth,n.start.count+=1),n.start.width+n.end.width+Math.max(0,n.start.count-1)*e.gaps.start+Math.max(0,n.end.count-1)*e.gaps.end+(n.start.count&&n.end.count?e.clusterGap:0)},n=/* @__PURE__ */ new Set,r=t(n),i=e.available-(e.previous.size?16:0),a=e.actions.filter(e=>e.auto).sort((e,t)=>t.order-e.order||t.sequence-e.sequence);for(let e of a){if(t(n)<=i)break;n.add(e.id)}return!e.hasMenu&&t(n)>=r?/* @__PURE__ */ new Set:n}function x(e){let t=e.ownerDocument.defaultView;if(!t)return 0;let n=t.getComputedStyle(e);if(n.display===`none`||[`absolute`,`fixed`].includes(n.position))return 0;let r=e=>Number.parseFloat(e)||0;return(n.display===`contents`?Array.from(e.children).reduce((e,n)=>e+(n instanceof t.HTMLElement?x(n):0),0):Math.max(e.getBoundingClientRect().width,e.scrollWidth))+r(n.marginLeft)+r(n.marginRight)}const S={mention:100,attachment:200,mic:800,overflow:900,send:1e3,custom:500},C=`data-persona-composer-action`,ee=`data-persona-composer-disable-when-streaming`,w=`core:overflow`,T=e=>e===`core:attachment`?`attachments`:e.startsWith(`core:mention`)?`mentions`:null;function E(e,t){if(e===void 0)return null;if(typeof e==`number`)return Number.isFinite(e)?e:null;let r=Number.parseFloat(e);if(/^\s*-?\d*\.?\d+(px)?\s*$/.test(e)&&Number.isFinite(r))return r;let i=n(`div`);i.style.position=`absolute`,i.style.visibility=`hidden`,i.style.pointerEvents=`none`,i.style.height=`0`,i.style.width=e,t.appendChild(i);let a=i.getBoundingClientRect().width;return i.remove(),Number.isFinite(a)&&a>0?a:Number.isFinite(r)?r:null}function D(e){let t=e.clientWidth;if(!t)return 0;let n=e.ownerDocument?.defaultView;if(!n?.getComputedStyle)return t;let r=n.getComputedStyle(e),i=(Number.parseFloat(r.paddingLeft)||0)+(Number.parseFloat(r.paddingRight)||0);return Math.max(0,t-i)}const O=(e,t)=>{e&&typeof console<`u`&&console.warn(t)},k=(e,t)=>t.includes(`:`)?t:`${e}:${t}`;function A(e){let{debug:t}=e,n=[],r=/* @__PURE__ */ new Map,i=0,a=e=>{let i=r.get(e.id);i?O(t,`[Persona] composer action "${e.id}" is already contributed by ${j(i)}; the ${j(e)} copy is ignored.`):(r.set(e.id,e),n.push(e))};for(let t of e.builtIns)a({id:t.id,placement:t.placement,presentation:`bar`,order:t.order,sequence:i++,source:`core`,builtIn:t});let o=(e,n,r)=>{let o=r?k(r,e.id):e.id,s=e.order??S.custom;e.placement===`end`&&s>=S.send&&(O(t,`[Persona] composer action "${o}" ordered at ${s} would render after send; clamped to ${S.send-1}.`),s=S.send-1),a({id:o,placement:e.placement,presentation:e.presentation??`bar`,order:s,sequence:i++,source:n,pluginId:r,action:e})};for(let t of e.configActions??[])o(t,`config`);for(let t of e.plugins){if(!t.contributeComposerActions)continue;let n;try{n=t.contributeComposerActions(e.contributionContext)}catch(e){typeof console<`u`&&console.error(`[Persona] plugin "${t.id}" contributeComposerActions failed:`,e);continue}for(let e of n??[])o(e,`plugin`,t.id)}return n.sort((e,t)=>e.order===t.order?e.sequence-t.sequence:e.order-t.order)}const j=e=>e.source===`plugin`?`plugin "${e.pluginId}"`:e.source===`config`?`composer.actions`:`a core built-in`,M=(e,t,n)=>e===void 0?n:typeof e==`function`?e(t)===!0:e===!0,N=e=>e.phase===`streaming`||e.text.trim().length>0||e.attachments.length>0;function P(e,t){if(!e||e===`always`)return!0;let n=N(t);return e===`when-text`?n:!n}const F=e=>e.kind===`custom`,I=e=>e instanceof HTMLButtonElement?e:e.querySelector(`button`)??e,te=e=>{let t=I(e);return t.getAttribute(`aria-label`)?.trim()||t.getAttribute(`title`)?.trim()||``};function L(e){let t=``,n=e=>{if(e.nodeType===Node.TEXT_NODE){t+=e.nodeValue??``;return}if(e.nodeType!==Node.ELEMENT_NODE)return;let r=e;typeof r.matches==`function`&&r.matches(`.persona-control-tooltip, [role="tooltip"], .persona-sr-only, [hidden], [aria-hidden="true"]`)||e.childNodes.forEach(n)};return n(e),t.trim()}const R=e=>L(e).length===0,z=e=>!e||typeof e!=`object`?e:Object.freeze(Array.isArray(e)?e.map(z):Object.fromEntries(Object.entries(e).map(([e,t])=>[e,z(t)])));function B(r){let{renderLucideIcon:i,attachTooltip:c,hideTooltipFor:u}=r.deps,d=/* @__PURE__ */ new Map,f=[],m=!1,g=null,_=[],v=[],y=n(`div`,`persona-composer-overflow-menu__content`),O=()=>r.getButtonSize?.(),k=(e,a)=>{let o=e.button;if(!o)return;o.setAttribute(`role`,`menuitem`),o.setAttribute(`tabindex`,`-1`),o.className=`persona-composer-overflow-menu__item`;for(let e of[`width`,`height`,`minWidth`,`minHeight`,`fontSize`,`color`,`backgroundColor`])o.style[e]=``;o.style.lineHeight=``,a.showTooltip!==!1&&a.tooltipText?o.setAttribute(`title`,a.tooltipText):o.removeAttribute(`title`),o.replaceChildren();let s=n(`span`,`persona-composer-overflow-menu__icon`);if(a.iconName){let e=i(a.iconName,16,`currentColor`,1.5);e&&s.appendChild(e)}let c=n(`span`,`persona-composer-overflow-menu__label`),l=r.getOverflow?.()?.menu?.items?.[e.resolved.id];c.textContent=l?.label??a.shortLabel??a.label;let u=n(`span`,`persona-composer-overflow-menu__text`);u.appendChild(c);let d=l?.description??a.description;o.setAttribute(`aria-label`,l?.label??a.label),d?o.setAttribute(`aria-description`,d):o.removeAttribute(`aria-description`),d&&u.appendChild(t(`span`,{className:`persona-composer-overflow-menu__description`,text:d})),o.append(s,u)},j=(t,r)=>{let o=t.button;if(!o)return;if(o.setAttribute(`aria-label`,r.label),r.pressed===void 0?o.removeAttribute(`aria-pressed`):o.setAttribute(`aria-pressed`,r.pressed?`true`:`false`),o.toggleAttribute(ee,r.disableWhenStreaming===!0),t.mode===`menu`){t.tooltip?.destroy(),t.tooltip=void 0,k(t,r);return}o.removeAttribute(`role`),o.removeAttribute(`tabindex`),o.removeAttribute(`aria-description`),o.removeAttribute(`title`);let l=O(),u=!!r.shortLabel||!r.iconName;if(o.className=e(`persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer persona-composer-action-button`,s,a,u&&`persona-composer-action-button--text persona-gap-1 persona-text-sm`),o.style.width=l&&!u?l:``,o.style.height=l??``,o.style.minWidth=l&&!u?l:``,o.style.minHeight=l??``,o.style.fontSize=u?``:`18px`,o.style.lineHeight=`1`,o.style.color=r.iconColor??``,o.style.backgroundColor=r.backgroundColor??``,o.replaceChildren(),r.iconName){let e=i(r.iconName,24,`currentColor`,1.5);e&&(r.iconName===`voice-bars`&&r.iconAnimation===`voice`&&e.classList.add(`persona-voice-bars--animated`),o.appendChild(e))}if(u){let e=n(`span`,`persona-composer-action-button__label`);e.textContent=r.shortLabel??r.label,o.appendChild(e)}if(r.trailingIconName&&u){let e=i(r.trailingIconName,24,`currentColor`,1.5);e&&o.appendChild(e)}o.firstChild||(o.textContent=r.label),t.tooltip?.destroy(),t.tooltip=c({anchor:o,trigger:t.element,text:()=>r.tooltipText??r.label,enabled:r.showTooltip??(!u||!!r.tooltipText)})},N=(e,t)=>{if(m||d.get(e.resolved.id)!==e||e.busy)return!1;let n=e.resolved.action,i=r.getState();if(!e.visible||n&&(!M(n.visible,i,!0)||!P(n.visibility,i)||M(n.disabled,i,!1)||n.disableWhenStreaming===!0&&i.phase===`streaming`))return!1;let a=I(e.element);if(a.disabled||a.getAttribute(`aria-disabled`)===`true`)return!1;if((e.mode===`menu`||W?.isOpen())&&(g=e.resolved.id,W?.close(!0)),!n||F(n))return a.click(),!0;let o;try{o=n.onSelect(r.actionContext,t)}catch(t){return r.reportError(t,{actionId:e.resolved.id}),!0}return o&&typeof o.then==`function`&&(e.busy=!0,e.button?.setAttribute(`aria-busy`,`true`),o.catch(t=>r.reportError(t,{actionId:e.resolved.id})).finally(()=>{e.busy=!1,e.button?.removeAttribute(`aria-busy`),!m&&d.get(e.resolved.id)===e&&ke()})),!0},L=(e,r)=>{let i=e.action,a=t(`button`,{attrs:{type:`button`}}),o=a;if(r===`bar`){let e=n(`div`,`persona-send-button-wrapper`);e.appendChild(a),o=e}o.setAttribute(C,e.id);let s={resolved:e,element:o,button:a,owned:!0,managed:!0,busy:!1,visible:!0,mode:r},c=e=>{e.preventDefault(),e.stopPropagation(),N(s,e)};return a.addEventListener(`click`,c),s.detach=()=>a.removeEventListener(`click`,c),j(s,i),s},B=e=>{let t=e.action,n;try{n=t.render({...r.actionContext,id:e.id,action:t})}catch(t){return r.reportError(t,{actionId:e.id}),null}return n?.element?(n.element.setAttribute(C,e.id),n.element.toggleAttribute(ee,t.disableWhenStreaming===!0),{resolved:e,element:n.element,owned:!0,managed:!0,destroy:n.destroy,busy:!1,visible:!0,mode:`bar`}):null},ne=(e,t)=>{if(e.builtIn){let t=e.builtIn.element;return t?{resolved:e,element:t,owned:!1,managed:e.builtIn.managed===!0,busy:!1,visible:!0,mode:`bar`}:null}let n=e.action;return n?F(n)?B(e):L(e,t):null},V=e=>{if(e.detach?.(),e.tooltip?.destroy(),e.detachMenuSlot?.(),e.detachMenuSlot=void 0,e.menuLabel?.remove(),e.menuLabel=void 0,e.menuSlot?.remove(),e.menuSlot=void 0,e.owned){try{e.destroy?.()}catch(t){r.reportError(t,{actionId:e.resolved.id})}e.element.remove()}},H=(e,t)=>{let n=null;for(let r=t.length-1;r>=0;r--){let i=t[r];i.managed?(n?(i.element.parentElement!==e||i.element.nextSibling!==n)&&e.insertBefore(i.element,n):e.lastChild!==i.element&&e.appendChild(i.element),n=i.element):i.element.parentElement===e&&(n=i.element)}},U=(e,t)=>{if(e.button){e.button.disabled=t;return}if(!e.owned)return;let n=e.element;n.toggleAttribute(`data-disabled`,t),n.setAttribute(`aria-disabled`,t?`true`:`false`);let r=n instanceof HTMLButtonElement||n instanceof HTMLSelectElement||n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement?n:n.querySelector(`button, select, input, textarea`);r&&(r.disabled=t)},W=null,G=null,K=null,q=0,J=null,Y=null,X=null,re=0,Z=/* @__PURE__ */ new Set,ie=/* @__PURE__ */ new Map,ae=()=>{re+=1,oe()},oe=()=>{if(m||Y!==null||!G)return;let e=G.ownerDocument.defaultView;e&&(Y=e.requestAnimationFrame(()=>{Y=null,ke()}))},se=()=>{Y!==null&&G?.ownerDocument.defaultView?.cancelAnimationFrame(Y),Y=null,J?.disconnect(),J=null,G?.ownerDocument.defaultView?.removeEventListener(`resize`,oe),G?.ownerDocument.fonts?.removeEventListener(`loadingdone`,ae),X=null},ce=()=>{let e=r.getOverflow?.();return e?.enabled===!0?e:void 0},Q=null,le=null,ue=null,de,$=!0,fe=!1,pe=!1,me=e=>r.reportError(e,{actionId:w}),he=e=>{try{e?.destroy?.()}catch(e){me(e)}},ge=()=>{let e=Q,t=le;Q=null,le=null,ue=null,de=void 0,fe=!1,e?.abort(),he(t),W?.panel.replaceChildren(y),W?.setContentMode(`menu`,!0),$=!0},_e=e=>{let t=e.resolved.action,n=ce()?.menu?.items?.[e.resolved.id],i=I(e.element),a=r.getState();return Object.freeze({id:e.resolved.id,kind:t?F(t)?`custom`:`button`:`builtin`,label:n?.label??(t?(F(t)?void 0:t.shortLabel)??t.label:te(e.element)),description:n?.description??t?.description,group:n?.group??t?.group,iconName:t&&!F(t)?t.iconName:void 0,disabled:!!(i.disabled||i.getAttribute(`aria-disabled`)===`true`||t&&(M(t.disabled,a,!1)||t.disableWhenStreaming===!0&&a.phase===`streaming`)),busy:e.busy,pressed:t&&!F(t)?t.pressed:void 0})},ve=e=>{let t=()=>!m&&Q===e&&!e.signal.aborted;return Object.freeze({config:z(ce()?.menu??{}),state:z(r.getState()),items:Object.freeze(v.map(_e)),signal:e.signal,actions:Object.freeze({invoke:e=>{if(!t()||!W?.isOpen())return!1;let n=d.get(e);return!n||n.mode!==`menu`||!v.includes(n)?!1:N(n,new Event(`click`,{bubbles:!0,cancelable:!0}))},openAttachmentPicker:()=>{if(!t()||!W?.isOpen())return;let e=d.get(`core:attachment`);e&&N(e,new Event(`click`,{bubbles:!0,cancelable:!0}))},close:()=>{t()&&W?.close(!0)},requestUpdate:()=>{t()&&!fe&&(fe=!0,Promise.resolve().then(()=>{t()&&(fe=!1,Ae())}))}}),defaultRenderer:()=>({element:y,role:`menu`})})},ye=()=>{let e=new AbortController;Q=e;let t=ve(e);for(let n of _){if(e.signal.aborted||Q!==e||m)return!1;if(!n.renderComposerMenu)continue;let r;try{r=n.renderComposerMenu(t)}catch(e){me(e);continue}if(!r)continue;let i=r instanceof HTMLElement?{element:r}:r;if(e.signal.aborted||Q!==e||m)return he(i),!1;if(!(i.element instanceof HTMLElement))he(i);else return le=i,ue=n,de=n.renderComposerMenu,$=i.element===y,W?.panel.replaceChildren(i.element),W?.setContentMode(i.role??($?`menu`:`dialog`),$),!0}return e.signal.aborted||m?!1:($=!0,W?.panel.replaceChildren(y),W?.setContentMode(`menu`,!0),!0)},be=()=>{if(!Q||Q.signal.aborted||!W?.isOpen())return;if(ue&&!_.some(e=>e.id===ue?.id&&e.renderComposerMenu===de)){W.close();return}if(pe)return;let e=Q,t=le;pe=!0;try{t?.update?.(ve(e))}catch(n){if(me(n),Q===e){if(Q=null,le=null,e.abort(),he(t),m||!W?.isOpen()||Q)return;Q=new AbortController,ue=null,de=void 0,$=!0,W.panel.replaceChildren(y),W.setContentMode(`menu`,!0)}}finally{pe=!1}W?.refresh()},xe=()=>(W?W.setLabel(r.getOverflowLabel?.()??`More actions`):W=h({deps:r.deps,label:r.getOverflowLabel?.()??`More actions`,getButtonSize:O,getConfig:()=>ce()?.menu,getComposer:()=>r.getBindings()?.form,beforeOpen:ye,onClose:ge}),W),Se=(e,t)=>{let n=e.footer;if(!(G===n&&(t?X===e.form:X===null))){if(se(),K?.disconnect(),G=n,q=D(n),t){X=e.form;let t=n.ownerDocument.defaultView;t?.addEventListener(`resize`,oe),n.ownerDocument.fonts?.addEventListener(`loadingdone`,ae),t?.MutationObserver&&(J=new t.MutationObserver(n=>{n.some(n=>{if(W?.trigger.contains(n.target)||n.target===e.input&&n.type===`attributes`)return!1;let r=[...Array.from(n.addedNodes),...Array.from(n.removedNodes)];return!(r.length&&r.every(e=>e instanceof t.HTMLElement&&e.hasAttribute(`data-persona-composer-measure`)))})&&oe()}),J.observe(n,{subtree:!0,childList:!0,characterData:!0,attributes:!0,attributeFilter:[`class`,`style`,`hidden`,`data-persona-composer-layout`,`data-persona-composer-compact`]}))}typeof ResizeObserver<`u`&&(K=new ResizeObserver(e=>{if(t){oe();return}let r=e[e.length-1]?.contentRect?.width??D(n);r!==q&&(q=r,ke())}),K.observe(n),t&&(K.observe(e.form),K.observe(e.actionsStart),K.observe(e.actionsEnd)))}},Ce=(e,t)=>{let n=E(e.collapseAutoActionsBelow,t);if(n===null)return!1;let r=q||D(t);return r>0&&r<n},we=(e,t,n)=>{if(!t)return`bar`;if(e.resolved.builtIn){let n=T(e.resolved.id);return n&&t.includeBuiltIns?.includes(n)?`menu`:`bar`}let r=e.resolved.presentation;return r===`overflow`||r===`auto`&&n?`menu`:`bar`},Te=e=>{let r=e.menuSlot;if(!r)return;let i=ce()?.menu?.items?.[e.resolved.id],a=i?.description??e.resolved.action?.description;if(!i?.label&&!a&&!R(e.element)){e.menuLabel?.remove(),e.menuLabel=void 0;return}let o=i?.label??te(e.element);o?(e.menuLabel||=n(`span`,`persona-composer-overflow-menu__label`),e.menuLabel.replaceChildren(t(`span`,{text:o})),a&&e.menuLabel.appendChild(t(`span`,{className:`persona-composer-overflow-menu__description`,text:a})),e.menuLabel.parentElement!==r&&r.appendChild(e.menuLabel)):(e.menuLabel?.remove(),e.menuLabel=void 0)},Ee=(e,r)=>{if(e.mode===r)return e;let i=e.resolved.action;if(i&&!F(i)){let t=e.element;return r===`menu`?e.element=e.button:(e.element=n(`div`,`persona-send-button-wrapper`),e.element.appendChild(e.button),e.button.removeAttribute(C)),t!==e.element&&t!==e.button&&t.remove(),e.element.setAttribute(C,e.resolved.id),e.mode=r,j(e,i),e}if(r===`menu`){let n=t(`div`,{className:`persona-composer-overflow-menu__slot`,attrs:{role:`none`,[o]:``}});n.appendChild(e.element),u(I(e.element)),e.menuSlot=n;let r=t=>{let n=I(e.element);if(n.disabled)return;let r=t.target===n||n.contains(t.target);g=e.resolved.id,W?.close(!0),r||n.click()};n.addEventListener(`click`,r,!0),e.detachMenuSlot=()=>n.removeEventListener(`click`,r,!0),e.managed=!0,Te(e)}else e.detachMenuSlot?.(),e.detachMenuSlot=void 0,e.menuLabel?.remove(),e.menuLabel=void 0,e.menuSlot?.remove(),e.menuSlot=void 0;return e.mode=r,e},De=(e,n)=>{let r=Array.from(e.querySelectorAll(`.persona-composer-overflow-menu__divider`)),i=0,a=[];for(n.forEach((e,o)=>{let s=_e(e).group;o&&s!==_e(n[o-1]).group&&a.push(r[i++]??t(`div`,{className:`persona-composer-overflow-menu__divider`,attrs:{role:`separator`}})),a.push(e.menuSlot??e.element)}),a.forEach((t,n)=>{let r=e.children[n];r!==t&&(r?e.insertBefore(t,r):e.appendChild(t))});e.children.length>a.length;)e.lastElementChild?.remove()},Oe=(e,t,n)=>{let r=D(e.form);if(!r)return Z;let i=e.form.ownerDocument.defaultView,a=i.getComputedStyle(e.form),o=e=>Number.parseFloat(e)||0,s=o(a.columnGap),c=e.footer.getAttribute(`data-persona-composer-layout`)===`single-row`&&e.footer.hasAttribute(`data-persona-composer-compact`),l=[a.fontFamily,a.fontSize,a.getPropertyValue(`--persona-composer-font-size`),a.getPropertyValue(`--persona-composer-control-size`),a.getPropertyValue(`--persona-composer-control-icon-size`),O(),re].join(`|`),u={start:e.actionsStart,end:e.actionsEnd},d={start:{width:0,count:0},end:{width:0,count:0}},f={start:0,end:0};for(let e of[`start`,`end`]){f[e]=o(i.getComputedStyle(u[e]).columnGap);for(let n of Array.from(u[e].children)){if(!(n instanceof i.HTMLElement)||n===W?.trigger||t.some(e=>e.element===n))continue;let r=x(n);r&&(d[e].width+=r,d[e].count+=1)}}let p=[],m=!1;for(let e of t){if(we(e,n,!1)===`menu`){m=!0;continue}let t=e.resolved.action,r=`${l}|${t&&!F(t)?[t.label,t.shortLabel,t.iconName,t.trailingIconName,t.pressed].join(`|`):`custom`}`,a=e.mode===`bar`?x(e.element):0,o=ie.get(e.resolved.id);if(!a&&o?.key===r&&(a=o.width),!a&&t&&!F(t)){let t=L(e.resolved,`bar`);t.element.setAttribute(`data-persona-composer-measure`,``),t.element.style.cssText=`position:absolute;visibility:hidden;width:max-content;pointer-events:none`,u[e.resolved.placement].appendChild(t.element),a=x(t.button),V(t)}if(!a&&t&&F(t)&&(a=o?.width??0),a&&ie.set(e.resolved.id,{key:r,width:a}),!a&&i.getComputedStyle(e.element).display!==`none`)return Z;a&&p.push({id:e.resolved.id,placement:e.resolved.placement,width:a,order:e.resolved.order,sequence:e.resolved.sequence,auto:e.resolved.presentation===`auto`})}let h=o(a.getPropertyValue(`--persona-composer-control-size`))||40,g=W?x(W.trigger):0;return b({available:Math.max(1,r-(c?120+s*2:0)),actions:p,slots:d,gaps:f,clusterGap:c?0:s,triggerWidth:g||o(O()??``)||h,hasMenu:m,previous:Z})},ke=()=>{if(m)return;let e=r.getBindings();if(e&&l(e.form),!e)return;let t=r.getState(),n=t.phase===`streaming`,i=ce(),a=i?.collapseAutoActions===`fit`;i?Se(e,a):(se(),K?.disconnect(),G=null);let o=i&&!a?Ce(i,e.footer):!1,s=e.footer.getRootNode(),c=s.activeElement,u=c===W?.triggerButton,h=c?Array.from(d.values()).find(e=>e.element.contains(c)):void 0,_=h?.mode;if(a){let n=f.map(e=>d.get(e.id)).filter(e=>!!e).filter(e=>!e.resolved.action||M(e.resolved.action.visible,t,!0)&&P(e.resolved.action.visibility,t));for(let t of n){if(!t.managed||t.mode!==`bar`)continue;let n=t.resolved.placement===`start`?e.actionsStart:e.actionsEnd;t.element.parentElement!==n&&n.appendChild(t.element)}Z=Oe(e,n,i)}else Z.clear();let b={start:[],end:[]},x=[];for(let e of f){let r=d.get(e.id);if(!r)continue;let s=e.action,c=!s||M(s.visible,t,!0)&&P(s.visibility,t);if(r.visible!==c&&(r.visible=c,!c&&r.managed&&(r.menuSlot??r.element).remove()),!c)continue;let l=we(r,i,o);if(r=Ee(r,l===`menu`||a&&e.presentation===`auto`&&Z.has(e.id)?`menu`:`bar`),s){let e=M(s.disabled,t,!1)||s.disableWhenStreaming===!0&&n;U(r,e),!F(s)&&s.pressed!==void 0&&r.button?.setAttribute(`aria-pressed`,s.pressed?`true`:`false`)}r.mode===`menu`?(Te(r),x.push(r)):b[e.placement].push(r)}if(v=x,x.length>0){let e=xe();Q||e.panel.replaceChildren(y),De(y,x);for(let e of x){let t=e.resolved.action;t&&!F(t)&&k(e,t)}e.setItems(x.map(e=>e.menuSlot??e.element)),e.refresh(),be();let t=Number.isFinite(i?.order)?i?.order:S.overflow,n=b.start.findIndex(e=>e.resolved.order>t),r={resolved:{id:w,placement:`start`,presentation:`bar`,order:t,sequence:-1,source:`core`},element:e.trigger,owned:!1,managed:!0,busy:!1,visible:!0,mode:`bar`};b.start.splice(n<0?b.start.length:n,0,r)}else W&&(W.close(),W.trigger.remove(),W.setItems([]));if(H(e.actionsStart,b.start),H(e.actionsEnd,b.end),h&&c&&h.visible&&(!c.isConnected||h.mode!==_||s.activeElement!==c))h.mode===`bar`?(W?.close(),p(h.element).focus()):W?.isOpen()&&$?p(h.menuSlot??h.element).focus():W?.triggerButton.focus();else if(u&&!x.length){let t=g?d.get(g):void 0;t?.visible&&t.mode===`bar`?p(t.element).focus():e.input.focus()}g=null},Ae=()=>{if(m)return;let e=r.collect();_=e.plugins;let t=A(e),n=new Set(t.map(e=>e.id));for(let[e,t]of d)n.has(e)||(V(t),d.delete(e),ie.delete(e));for(let e of t){let t=d.get(e.id);if(!t){let t=ne(e,`bar`);t&&d.set(e.id,t);continue}let n=t.resolved.action,r=e.action;if(!!n!=!!r||n&&r&&F(n)!==F(r)||n&&r&&F(n)&&F(r)&&n.render!==r.render){V(t),d.delete(e.id),ie.delete(e.id);let n=ne(e,t.mode);n&&d.set(e.id,n)}else t.resolved=e,e.builtIn?(t.managed=e.builtIn.managed===!0||t.mode===`menu`,e.builtIn.element&&t.mode===`bar`&&(t.element=e.builtIn.element)):r&&!F(r)?j(t,r):r&&t.element.toggleAttribute(ee,r.disableWhenStreaming===!0)}f=t,ke()};return{resolve:Ae,sync:ke,getResolved:()=>f,getOverflowMenu:()=>W,destroy:()=>{if(!m){m=!0,se(),K?.disconnect(),K=null,G=null,W?.close(),ge();for(let e of d.values())V(e);d.clear(),W?.destroy(),W=null,f=[]}}}}const ne=e=>`core:mode:${e}`,V=e=>Math.min(300+e,499),H=e=>`core:mode-group:${e}`;function U(e,t){return e?t?.find(t=>t.id===e)?.presentation===`segmented`:!1}function W(e,t){return e?t?.find(t=>t.id===e)?.chipVisibility===`hidden`:!1}function G(e,t,n=!1){return e?.length?e.filter(e=>!U(e.groupId,t)&&!W(e.groupId,t)&&(!n||e.presentation===`overflow`||t?.find(t=>t.id===e.groupId)?.chipVisibility===`auto`)):[]}const K=(e,t)=>e.groupId?t?.find(t=>t.id===e.groupId)?.selection??null:null;function q(e,t,n,r){let i=n.find(e=>e.id===t);if(!i)return[...e];let a=e.includes(t),o=new Set(e);if(a)o.delete(t);else{if(K(i,r)===`single`){let e=n.filter(e=>e.groupId===i.groupId).map(e=>e.id);o=new Set([...o].filter(t=>!e.includes(t)))}o.add(t)}return n.filter(e=>o.has(e.id)).map(e=>e.id)}function J(e,t){return t?.length?t.filter(t=>e.includes(t.id)).map(e=>e.id):[]}function Y(e,t){return t?.length?t.filter(t=>e.includes(t.id)&&(t.persistence??`sticky`)!==`once`).map(e=>e.id):[]}function X(e,t){if(t?.length&&e.length!==0)return t.find(t=>e.includes(t.id)&&t.placeholder)?.placeholder}function re(e,t,n){let r=[];for(let i of e)r.includes(i)||(r=q(r,i,t,n));return r}export{V as a,X as c,C as d,S as f,l as h,H as i,re as l,y as m,Y as n,U as o,B as p,ne as r,J as s,G as t,q as u};
@@ -0,0 +1 @@
1
+ import{n as e}from"./chunk-BAdIgC5d.js";import{t}from"./chunk-DAthf5H3.js";import{t as n}from"./chunk-i4qGOJAL.js";import{n as r}from"./chunk-DTDHeUsG.js";const i=e=>e.replace(/[^a-zA-Z0-9_]/g,`_`).toLowerCase().replace(/_+/g,`_`).replace(/^_|_$/g,``),a=e=>typeof e==`object`&&!!e&&!Array.isArray(e),o=e=>{if(e.variant!==`tool`)return null;let t=e.agentMetadata?.clientToolAnswer;if(!t||!t.toolCallId||t.result===void 0)return null;let n=i(t.toolName);return n?{call:{toolCallId:t.toolCallId,toolName:n,args:a(t.args)?t.args:{}},result:{toolCallId:t.toolCallId,toolName:n,result:t.result}}:null},s=(e,t)=>{let n=[],r=[],i=[],a=``,s,c=()=>{r.length!==0&&(n.push({role:`assistant`,content:``,createdAt:a,toolCalls:r},{role:`tool`,content:``,createdAt:a,toolResults:i}),r=[],i=[])};for(let l of e){let e=o(l);if(e){let t=l.agentMetadata?.clientToolAnswer?.batch;r.length>0&&(t===void 0||t!==s)&&c(),r.length===0&&(a=l.createdAt,s=t),r.some(t=>t.toolCallId===e.call.toolCallId)||(r.push(e.call),i.push(e.result));continue}let u=t(l);u&&(c(),n.push(u))}return c(),n},c=e=>e.voiceCaption||r(e)?!1:!!(e.contentParts&&e.contentParts.length>0||e.llmContent&&e.llmContent.trim().length>0||e.rawContent&&e.rawContent.trim().length>0||e.content&&e.content.trim().length>0),l=e=>typeof e==`string`?!0:Array.isArray(e)?e.every(e=>{if(!e||typeof e!=`object`)return!1;switch(e.type){case`text`:return typeof e.text==`string`;case`image`:return typeof e.image==`string`;case`audio`:return typeof e.audio==`string`;case`video`:return typeof e.video==`string`;case`file`:return typeof e.data==`string`&&typeof e.mimeType==`string`&&typeof e.filename==`string`;default:return!1}}):!1,u=e=>e.slice().sort((e,t)=>new Date(e.createdAt).getTime()-new Date(t.createdAt).getTime()),d=e=>{let t=e.agentMetadata?.providerPhase??e.agentMetadata?.phase;return e.role===`assistant`&&(t===`commentary`||t===`partial_answer`||t===`final_answer`)?{phase:t}:{}},f=e=>({role:e.role,content:e.contentParts??e.llmContent??e.rawContent??e.content,createdAt:e.createdAt,...d(e)});var p=class{constructor(e){this.host=e}async initializeSession(){await this.host.historyInternals.historyBootstrapReady;let e=this.host.config.getStoredConversationId?.()||null,t=this.host.historyInternals.shouldResumeDurableConversation?.()===!0;if(!this.host.isHistoryCapable()&&!t)return this.#e(e,!1);let n=await this.host.readVisitorToken();if(e&&n)try{let n=await this.createClientSession({conversationId:e,durableResume:t});return t&&n.durableRecovery?.enabled!==!0&&this.host.historyInternals.setStoredResumableHandle?.(null),this.host.finishInit(n,e,!1)}catch(n){if(!(n instanceof this.host.HistoryClientError&&n.code===`not_found`)&&!(n instanceof this.host.HistoryClientError&&n.code===`visitor_required`)&&!(n instanceof this.host.HistoryClientError&&n.code===`history_disabled`))throw n;return t&&this.host.historyInternals.setStoredResumableHandle?.(null),this.#e(e,!0)}return this.#e(e,!1)}async#e(e,t){let n=this.host.historyInternals.visitorStore;return n&&!await this.host.readVisitorToken()?n.withFirstInitLock(()=>this.#t(e,t)):this.#t(e,t)}async#t(e,t){let n=this.host.config.getStoredSessionId?.()||null,r=await this.createClientSession({storedSessionId:n}),i=await this.#n(r);return this.host.finishInit(i,e,t)}async#n(e){if(!e.visitor?.token||this.host.claimInFlight||!this.host.isHistoryCapable()&&e.durableRecovery?.enabled!==!0)return e;this.host.claimInFlight=!0;try{return await this.createClientSession({storedSessionId:e.sessionId})}catch{return e}finally{this.host.claimInFlight=!1}}async sendWithClientToolsDiff(t,n,r,i){let a=!!(n&&n.length>0),o=a?e(n):void 0,s=this.host.clientToolsFingerprintSessionId===t,c=a&&s&&this.host.lastSentClientToolsFingerprint===o,l=!a&&i?.emptyMeansReplace===!0&&this.host.sentNonEmptyClientToolsSessionId===t,u=!1,d;for(let e=0;d=await r({...a&&(u||!c)&&n?{clientTools:n}:{},...l?{clientTools:[]}:{},...o?{clientToolsFingerprint:o}:{}}),d.status===409&&e===0&&a&&(await d.clone().json().catch(()=>null))?.error===`client_tools_resend_required`;e++)u=!0,this.host.lastSentClientToolsFingerprint=null;return{response:d,commit:()=>{this.host.lastSentClientToolsFingerprint=o??null,this.host.clientToolsFingerprintSessionId=t,a?this.host.sentNonEmptyClientToolsSessionId=t:l&&(this.host.sentNonEmptyClientToolsSessionId=null)}}}async createClientSession(e){let n=this.host.isHistoryCapable()&&!e.omitVisitorFields,r=!e.omitVisitorFields,i=null;(n||r)&&(await this.host.historyInternals.historyBootstrapReady,i=await this.host.readVisitorToken());let a=this.host.routing(),o=a.agentId??a.flowId,s=n||e.durableResume?e.conversationId:void 0,c={token:this.host.config.clientToken,...o&&{flowId:o},...n&&{visitorHistory:!0},...r&&{durableRecovery:!0},...(n||r)&&i?{visitorToken:i}:{},...n&&e.identityProof?{identityProof:e.identityProof}:{},...s?{conversationId:s}:e.storedSessionId?{sessionId:e.storedSessionId}:{}};e.signal?.throwIfAborted();let l=await fetch(this.host.getClientApiUrl(`init`),{method:`POST`,headers:{"Content-Type":`application/json`,"X-Persona-Version":t},body:JSON.stringify(c),signal:e.signal});if(!l.ok){let t=await l.json().catch(()=>({error:`Session initialization failed`}));if(n&&l.status===403&&t.error===`visitor_history_disabled`){if(this.host.markHistoryUnavailable(),s)throw new this.host.HistoryClientError(`history_disabled`,`Visitor history is disabled for this surface`);return this.createClientSession({...e,omitVisitorFields:!0})}throw l.status===403&&t.error===`durable_recovery_disabled`?new this.host.HistoryClientError(`history_disabled`,`Durable recovery is disabled for this surface`):(n||e.durableResume)&&l.status===401&&t.error===`visitor_required`?new this.host.HistoryClientError(`visitor_required`,`Visitor credential no longer resolves`):s&&l.status===404?new this.host.HistoryClientError(`not_found`,`Conversation not found`):l.status===401?Error(`Invalid client token: ${t.hint||t.error}`):l.status===403?Error(`Origin not allowed: ${t.hint||t.error}`):Error(t.error||`Failed to initialize session`)}let u=await l.json();return u.visitor?.token&&await this.host.historyInternals.visitorStore?.set(u.visitor.token),{sessionId:u.sessionId,expiresAt:new Date(u.expiresAt),flow:u.flow,...u.conversationId?{conversationId:u.conversationId}:{},...u.targetId?{targetId:u.targetId}:{},...u.conversationRevision?{conversationRevision:u.conversationRevision}:{},...u.durableRecovery?{durableRecovery:u.durableRecovery}:{},...u.visitor?{visitor:u.visitor}:{},config:{welcomeMessage:u.config.welcomeMessage,placeholder:u.config.placeholder,theme:u.config.theme,...m(u.config)}}}async sendFeedback(e){if([`upvote`,`downvote`,`copy`].includes(e.type)&&!e.messageId)throw Error(`messageId is required for ${e.type} feedback type`);if(e.type===`csat`&&(e.rating===void 0||e.rating<1||e.rating>5))throw Error(`CSAT rating must be between 1 and 5`);if(e.type===`nps`&&(e.rating===void 0||e.rating<0||e.rating>10))throw Error(`NPS rating must be between 0 and 10`);this.host.debug&&console.debug(`[AgentWidgetClient] sending feedback`,e);let n={...e,...this.host.config.clientToken&&{token:this.host.config.clientToken}},r=await fetch(`${this.host.clientApiBase()}/v1/client/feedback`,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Persona-Version":t},body:JSON.stringify(n)});if(!r.ok){let e=await r.json().catch(()=>({error:`Feedback submission failed`}));throw r.status===401?(this.host.clientSession=null,this.host.resetSessionWarmLatch(),this.host.config.onSessionExpired?.(),Error(`Session expired. Please refresh to continue.`)):Error(e.error||`Failed to submit feedback`)}}async dispatchClientToken(e,r,i){let{HistoryClientError:a}=this.host,o=()=>this.host.isCurrentTurn(i),s=e=>{o()&&r(e)};try{let r=()=>{if(e.signal?.throwIfAborted(),!o())throw new DOMException(`Turn superseded`,`AbortError`)},c=this.host.clientSession??await this.host.initSession();r();let l=async()=>{r();let t=c,n=t.durableRecovery?.enabled===!0;if(n&&(!t.conversationId||!await this.host.readVisitorToken()))throw Error(`Renewing this conversation requires its visitor credential.`);r();let i=await this.host.createClientSession({...n||this.host.isHistoryCapable()?{conversationId:t.conversationId,durableResume:n}:{storedSessionId:t.sessionId},signal:e.signal});if(r(),t.conversationId&&i.conversationId!==t.conversationId||n&&i.durableRecovery?.enabled!==!0)throw Error(`Session renewal did not preserve this conversation.`);c=this.host.finishInit(i,t.conversationId??null,!1),this.host.clientSession=c,this.host.resetSessionWarmLatch(),this.host.resetClientToolsFingerprint(),this.host.config.onSessionInit?.(c)};Date.now()>=c.expiresAt.getTime()-6e4&&await l();let d=new Map(u(e.messages).map(e=>[e,this.#s(e)])),f=await this.#l(e.messages,void 0,d),p=f.metadata?Object.fromEntries(Object.entries(f.metadata).filter(([e])=>e!==`sessionId`&&e!==`session_id`)):void 0,m=this.host.isHistoryCapable(),h={sessionId:c.sessionId,messages:u(e.messages).flatMap(e=>{let t=d.get(e);if(!t)return[];let r=m?n(e,t.content):void 0;return[{id:e.id,role:t.role,content:t.content,...r!==void 0&&{displayContent:r}}]}),...e.assistantMessageId&&{assistantMessageId:e.assistantMessageId},...p&&Object.keys(p).length>0&&{metadata:p},...f.inputs&&Object.keys(f.inputs).length>0&&{inputs:f.inputs},...f.context&&{context:f.context},turnId:i,...e.interrupt&&{submitMode:`interrupt`},...e.voiceSpoken&&{voice:{spoken:!0,...e.voicePriorToolResults?.length&&{priorToolResults:e.voicePriorToolResults}}}},g=async()=>{r();let n=c.durableRecovery?.enabled===!0?await this.host.readVisitorToken():null;return r(),this.host.sendWithClientToolsDiff(c.sessionId,f.clientTools,async i=>{r();let a=await this.host.resolveChatIdentityProof(e.signal);r();let o={...h,sessionId:c.sessionId,...i,...a&&{identityProof:a}};return this.host.debug&&console.debug(`[AgentWidgetClient] client token dispatch`,{...o,...a&&{identityProof:{provider:a.provider,token:`[REDACTED]`}}}),fetch(this.host.getClientApiUrl(`chat`),{method:`POST`,headers:{"Content-Type":`application/json`,"X-Persona-Version":t,...n?{"X-Visitor-Token":n}:{}},body:JSON.stringify(o),signal:e.signal})})},_=await g();if(r(),_.response.status===401){let e=await _.response.clone().json().catch(()=>null);r(),e?.error===`Session not found or expired`&&(await l(),_=await g(),r())}let{response:v,commit:y}=_;if(!v.ok){let e=await v.json().catch(()=>({error:`Chat request failed`}));if(v.status===401&&e.error===`invalid_identity_proof`){let e=new a(`invalid_identity_proof`,`The identity proof was rejected`);throw s({type:`error`,error:e}),e}if(v.status===401){this.host.clearClientSession(),this.host.config.onSessionExpired?.();let e=/* @__PURE__ */ Error(`Session expired. Please refresh to continue.`);throw s({type:`error`,error:e}),e}if(v.status===429){let t=Error(e.hint||`Message limit reached for this session.`);throw s({type:`error`,error:t}),t}if(v.status===410&&e.error===`conversation_deleted`){let e=new a(`conversation_deleted`,`This conversation was deleted`);throw s({type:`error`,error:e}),e}let t=Error(e.error||`Failed to send message`);throw s({type:`error`,error:t}),t}if(!v.body){let e=/* @__PURE__ */ Error(`No response body received`);throw s({type:`error`,error:e}),e}y(),s({type:`status`,status:`connected`});try{await this.host.streamResponse(v.body,s,e.assistantMessageId,void 0,e.signal)}finally{s({type:`status`,status:`idle`})}}catch(e){let t=e instanceof Error?e:Error(String(e));throw t instanceof a||t.message.includes(`Session expired`)||t.message.includes(`Message limit`)||s({type:`error`,error:t}),t}}async dispatchProxy(e,t){let n=await this.#l(e.messages,e.composerOptions);this.host.debug&&console.debug(`[AgentWidgetClient] dispatch payload`,n);let r={...this.host.headers};if(this.host.getHeaders)try{let e=await this.host.getHeaders();r={...r,...e}}catch(e){typeof console<`u`&&console.error(`[AgentWidget] getHeaders error:`,e)}let i;if(this.host.customFetch)try{i=await this.host.customFetch(this.host.apiUrl,{method:`POST`,headers:r,body:JSON.stringify(n),signal:e.signal},n)}catch(e){let n=e instanceof Error?e:Error(String(e));throw t({type:`error`,error:n}),n}else i=await fetch(this.host.apiUrl,{method:`POST`,headers:r,body:JSON.stringify(n),signal:e.signal});if(!i.ok||!i.body){let e=/* @__PURE__ */ Error(`Chat backend request failed: ${i.status} ${i.statusText}`);throw t({type:`error`,error:e}),e}t({type:`status`,status:`connected`});try{await this.host.streamResponse(i.body,t,void 0,void 0,e.signal)}finally{t({type:`status`,status:`idle`})}}async dispatchAgent(e,t){let n=await this.#c(e.messages,e.composerOptions);this.host.debug&&console.debug(`[AgentWidgetClient] agent dispatch payload`,n);let r={...this.host.headers};if(this.host.getHeaders)try{let e=await this.host.getHeaders();r={...r,...e}}catch(e){typeof console<`u`&&console.error(`[AgentWidget] getHeaders error:`,e)}let i;if(this.host.customFetch)try{i=await this.host.customFetch(this.host.apiUrl,{method:`POST`,headers:r,body:JSON.stringify(n),signal:e.signal},n)}catch(e){let n=e instanceof Error?e:Error(String(e));throw t({type:`error`,error:n}),n}else i=await fetch(this.host.apiUrl,{method:`POST`,headers:r,body:JSON.stringify(n),signal:e.signal});if(!i.ok||!i.body){let e=/* @__PURE__ */ Error(`Agent execution request failed: ${i.status} ${i.statusText}`);throw t({type:`error`,error:e}),e}t({type:`status`,status:`connected`});try{await this.host.streamResponse(i.body,t,e.assistantMessageId,void 0,e.signal)}finally{t({type:`status`,status:`idle`})}}#r(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.role===`user`)return n.mentionContext&&Object.keys(n.mentionContext).length>0?{mentions:n.mentionContext}:null}return null}async#i(e){let t={};this.host.contextProviders.length&&await Promise.all(this.host.contextProviders.map(async n=>{try{let r=await n({messages:e,config:this.host.config});r&&typeof r==`object`&&Object.assign(t,r)}catch(e){typeof console<`u`&&console.warn(`[AgentWidget] Context provider failed:`,e)}}));let n=this.#r(e);return n&&Object.assign(t,n),Object.keys(t).length?t:null}#a(e){if(!e)return;let t={};return e.selectedModelId&&(t.selectedModelId=e.selectedModelId),e.activeModeIds?.length&&(t.activeModeIds=[...e.activeModeIds]),Object.keys(t).length>0?t:void 0}#o(e,t){let n=t?.selectedModelId;return!n||!(`model`in e)?e:this.host.config.composer?.models?.some(e=>e.id===n)?{...e,model:n}:e}#s(e){if(!c(e))return null;let t=e.contentParts??e.llmContent??e.rawContent??e.content,n=e.role===`operator`?null:f(e),r=this.host.config.modelMessageTransform;if(!r)return n;let i=r({message:e,content:t,modelMessage:n});if(i===null)return null;if(!i||typeof i!=`object`||![`user`,`assistant`,`system`].includes(i.role)||!l(i.content)||typeof i.createdAt!=`string`)throw TypeError(`modelMessageTransform must return a supported model message or null`);return{role:i.role,content:i.content,createdAt:i.createdAt,...i.role===`assistant`&&i.phase&&{phase:i.phase}}}async#c(e,t){let n=this.host.routing().agentId;if(!this.host.config.agent&&!n)throw Error(`Agent configuration required for agent mode`);let r=s(u(e),e=>!e.variant||e.variant===`assistant`?this.#s(e):null),i=this.#a(t),a={agent:this.#o(this.host.config.agent??{agentId:n},i),messages:r,options:{streamResponse:!0,recordMode:`virtual`,...this.host.config.agentOptions}};i&&(a.composerOptions=i);let o=[...this.host.builtInClientTools(this.host.config),...await(await this.host.getWebMcpBridge())?.snapshotForDispatch()??[]];o.length>0&&(a.clientTools=o);let c=await this.#i(e);return c&&(a.context=c),a}async#l(e,t,n){let r=s(u(e),e=>n?n.get(e)??null:this.#s(e)),i=this.host.routing(),a={messages:r,...i.agentId?{agent:{agentId:i.agentId}}:i.flowId?{flowId:i.flowId}:{}};if(i.targetPayload)for(let[e,t]of Object.entries(i.targetPayload))e!==`messages`&&(a[e]=t);let o=[...this.host.builtInClientTools(this.host.config),...await(await this.host.getWebMcpBridge())?.snapshotForDispatch()??[]];o.length>0&&(a.clientTools=o);let c=await this.#i(e);c&&(a.context=c);let l=this.#a(t);if(l&&(a.composerOptions=l),this.host.requestMiddleware)try{let e=await this.host.requestMiddleware({payload:{...a},config:this.host.config});if(e&&typeof e==`object`){let t=e;return a.clientTools!==void 0&&!(`clientTools`in t)&&(t.clientTools=a.clientTools),t}}catch(e){typeof console<`u`&&console.error(`[AgentWidget] Request middleware error:`,e)}return a}};const m=e=>{let t=e.webmcp?.requireConfirmFor;return Array.isArray(t)&&t.length?{webmcp:{requireConfirmFor:t}}:{}};export{p as ClientDispatch};
@@ -0,0 +1 @@
1
+ const e=`4.35.1`;export{e as t};
@@ -1,4 +1,4 @@
1
- import{t as e}from"./chunk-Dqa_GOcj.js";import{t}from"./chunk-DqbzUVEI.js";const n=16e3,r=/* @__PURE__ */ new Map([[`idle_timeout`,`Voice call ended after a quiet period.`],[`max_duration`,`This voice call reached its time limit.`],[`provider_ended`,`The voice session ended.`],[`quota`,`Voice is unavailable right now.`],[`auth_expired`,`Voice session expired. Tap the mic to reconnect.`]]),i=[`provider_error`,`server_restart`],a=`Voice connection lost.`;function o(e,t){let n=t.slice(0,4e3).trim(),r=8e3-(n?n.length+2:0)-20,i=[];for(let t of e.slice(-12).reverse()){let e=t.content.replace(/\s+/g,` `).trim();if(!e)continue;e.length>2e3&&(e=`${e.slice(0,1999)}…`);let n=`${t.role===`user`?`User`:`Assistant`}: ${e}`;if(n.length+1>r)break;r-=n.length+1,i.unshift(n)}let a=i.length>0?[`Conversation so far:\n${i.join(`
1
+ import{t as e}from"./chunk-DAthf5H3.js";import{t}from"./chunk-DqbzUVEI.js";const n=16e3,r=/* @__PURE__ */ new Map([[`idle_timeout`,`Voice call ended after a quiet period.`],[`max_duration`,`This voice call reached its time limit.`],[`provider_ended`,`The voice session ended.`],[`quota`,`Voice is unavailable right now.`],[`auth_expired`,`Voice session expired. Tap the mic to reconnect.`]]),i=[`provider_error`,`server_restart`],a=`Voice connection lost.`;function o(e,t){let n=t.slice(0,4e3).trim(),r=8e3-(n?n.length+2:0)-20,i=[];for(let t of e.slice(-12).reverse()){let e=t.content.replace(/\s+/g,` `).trim();if(!e)continue;e.length>2e3&&(e=`${e.slice(0,1999)}…`);let n=`${t.role===`user`?`User`:`Assistant`}: ${e}`;if(n.length+1>r)break;r-=n.length+1,i.unshift(n)}let a=i.length>0?[`Conversation so far:\n${i.join(`
2
2
  `)}`]:[];return n&&a.push(n),a.join(`
3
3
 
4
4
  `)}function s(e){return e.byteLength>=44&&new DataView(e).getUint32(0,!1)===1380533830?new Uint8Array(e,44):new Uint8Array(e)}function c(e){let t=e.replace(/\/+$/,``);return/^wss?:\/\//i.test(t)?t:/^https?:\/\//i.test(t)?t.replace(/^http/i,`ws`):`${typeof window<`u`&&window.location?.protocol===`https:`?`wss:`:`ws:`}//${t}`}function l(e){return c(e).replace(/^ws/i,`http`)}function u(e){return typeof e!=`number`||!Number.isFinite(e)?3e4:Math.min(6e5,Math.max(3e4,Math.round(e)))}var d=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S;#C;#w;#T;#E;#D;#O;#k;#A;#j;#M;#N;#P;#F;#I;#L;#R;#z;#B;#V;#H;#U;#W;#G;#K;#q;#J;#Y;constructor(e){this.config=e,this.type=`runtype`,this.#e=null,this.#t=null,this.#n=[],this.#r=null,this.#i=null,this.#a=null,this.#o=[],this.#s=0,this.#c=null,this.#l=!1,this.#u=!1,this.#d=0,this.#f=!1,this.#p=-1/0,this.#m=null,this.#h=!1,this.#g=!1,this.#_=0,this.#v=0,this.#b=!1,this.bridge=null,this.#x=!1,this.#S=/* @__PURE__ */ new Set,this.#C=/* @__PURE__ */ new Map,this.#w=/* @__PURE__ */ new Set,this.#E=null,this.#D=null,this.#k=!1,this.#A=!1,this.#j=!1,this.#M=null,this.#N=null,this.#P=Promise.resolve(),this.#F=/* @__PURE__ */ new Set,this.#I=/* @__PURE__ */ new Set,this.#L=null,this.#R=!1,this.#z=/* @__PURE__ */ new Set,this.#B=/* @__PURE__ */ new Set,this.#V=null,this.#H=/* @__PURE__ */ new Set,this.#U=null,this.#W=/* @__PURE__ */ new Map,this.#G=[],this.#K=[],this.#q=[],this.#J=[],this.#Y=[]}async connect(){}setSessionBridge(e){this.bridge=e}prewarm(){if(this.#l||this.#m)return;let e=this.config?.agentId,t=this.config?.clientToken,n=this.config?.host;if(!e||!t||!n)return;let r=Date.now();if(!(r-this.#p<3e4)){this.#p=r;try{this.config?.prewarmMode===`attach`?this.#Z(n,e,t):this.#X(n,e,t)}catch{}}}#X(e,t,n){if(typeof fetch!=`function`)return;let r=`${l(e)}/v1/client/agents/${encodeURIComponent(t)}/voice/prewarm`;fetch(r,{method:`POST`,headers:{Authorization:`Bearer ${n}`},keepalive:!0}).catch(()=>{})}#Z(e,t,n){let r=new URLSearchParams,i=this.config?.attachIdleMs,a=u(i);i!==void 0&&r.set(`attachIdleMs`,String(a));let o=new WebSocket(this.#te(e,t,r),[`runtype.bearer`,`runtype.attach`,n]);o.binaryType=`arraybuffer`;let s=()=>{},c={ws:o,state:`connecting`,ready:new Promise(e=>{s=e}),settle:s,openedAt:0,idleTimer:void 0};this.#m=c,o.onopen=()=>{this.#m===c&&(c.state=o.protocol===`runtype.attach`?`attached`:`live`,c.openedAt=Date.now(),this.#Q(c,a),c.state===`attached`&&o.send(`{"type":"ping"}`),c.settle())},o.onmessage=e=>{if(this.#m!==c||typeof e.data!=`string`)return;let t;try{t=JSON.parse(e.data)}catch{return}t.type===`attached`&&typeof t.idleMs==`number`&&this.#Q(c,t.idleMs-(Date.now()-c.openedAt))},o.onerror=()=>{},o.onclose=()=>{this.#m===c&&this.#$()}}#Q(e,t){clearTimeout(e.idleTimer),e.idleTimer=setTimeout(()=>{this.#m===e&&this.#$()},Math.max(0,t))}#$(){let e=this.#m;if(!e)return;this.#m=null,clearTimeout(e.idleTimer);let{ws:t}=e;if(t.onopen=null,t.onmessage=null,t.onerror=null,t.onclose=null,e.settle(),t.readyState===WebSocket.CONNECTING||t.readyState===WebSocket.OPEN)try{t.close(1e3,`prewarm released`)}catch{}}async#ee(){let e=this.#m;if(!e)return null;if(e.state===`connecting`){let t;await Promise.race([e.ready,new Promise(e=>{t=setTimeout(e,5e3)})]),clearTimeout(t)}return this.#m===e?e.state===`connecting`||e.ws.readyState!==WebSocket.OPEN?(this.#$(),null):(this.#m=null,clearTimeout(e.idleTimer),{ws:e.ws,live:e.state===`live`}):null}#te(t,n,r){let i=`partial_transcript,context`;this.bridge&&this.config?.clientDelegation!==!1&&(i+=`,client_delegation,delegation_update,delegation_read_back,delegation_stream`,this.bridge.clientTools?.()&&(i+=`,client_tools,prior_tool_results`)),r&&(i=`attach,${i}`);let a=new URLSearchParams({voiceProtocol:`runtype-browser-v1`,clientVersion:`persona/${e}`,voiceCapabilities:`full-duplex-v1`,clientCapabilities:i});return r?.forEach((e,t)=>a.set(t,e)),`${c(t)}/ws/agents/${encodeURIComponent(n)}/voice?${a}`}async startListening(){if(this.#l)return;let e=this.#A;e||(this.#k=!1,this.#D=null),this.#A=!1;let r=this.config?.agentId,i=this.config?.clientToken,o=this.config?.host;if(!r)throw Error(`Runtype voice requires an agentId`);if(!i)throw Error(`Runtype voice requires a clientToken`);if(!o)throw Error(`Runtype voice requires a host (or widget apiUrl)`);let s=++this.#d;this.#f=!1,this.#l=!0;try{let c=await navigator.mediaDevices.getUserMedia({audio:{sampleRate:n,channelCount:1,echoCancellation:!0}});if(s!==this.#d){c.getTracks().forEach(e=>e.stop());return}this.#r=c;let l=new(window.AudioContext||window.webkitAudioContext)({sampleRate:n});if(this.#t=l,l.state===`suspended`){if(await Promise.race([l.resume().catch(()=>{}),new Promise(t=>setTimeout(t,e?500:1e3))]),s!==this.#d)return;if(l.state!==`running`)throw Error(e?this.#D=`${a} Tap the mic to reconnect.`:`Audio blocked until a tap`)}let u=this.config?.createPlaybackEngine?await this.config.createPlaybackEngine():new t(24e3);if(s!==this.#d){u.destroy(),c.getTracks().forEach(e=>e.stop()),l.close().catch(()=>{});return}this.#c=u,this.#he(),this.#ie(l,c,s);let d=await this.#ee();if(s!==this.#d){d?.ws.close(1e3,`client ended call`);return}if(d){let{ws:e}=d;this.#e=e,this.#ne(e,s),d.live||e.send(`{"type":"start"}`),this.#ae(e),this.#be(`listening`);return}let f=new WebSocket(this.#te(o,r),[`runtype.bearer`,i]);f.binaryType=`arraybuffer`,this.#e=f,f.onopen=()=>{s===this.#d&&(this.#ae(f),this.#be(`listening`))},this.#ne(f,s)}catch(e){throw this.#ye(),this.#xe(e),this.#be(`error`),e}}#ne(e,t){e.onmessage=e=>this.#oe(e,t),e.onerror=()=>{t!==this.#d||this.#E||(this.#xe(/* @__PURE__ */ Error(`Voice connection failed`)),this.#be(`error`),this.#ye())},e.onclose=e=>{if(this.#f){this.#f=!1;return}if(t!==this.#d)return;let n=this.#E??(e.code===4408?{reason:`idle_timeout`}:null);if(n)this.#re(n.reason,n.message);else{if(e.code!==1e3){let t=e.code?` (code ${e.code})`:``;this.#xe(/* @__PURE__ */ Error(`Voice connection closed${t}`)),this.#be(`error`)}else this.#be(`idle`);this.#ye()}}}#re(e,t){let n=i.includes(e)&&!this.#k;if(this.#ye(),n)this.#k=!0,this.#l=!0,this.#D=e===`provider_error`?`${a} Reconnecting…`:`Reconnecting…`,this.#O=setTimeout(()=>{this.#l=!1,this.#A=!0,this.startListening().catch(()=>{})},1e3+Math.random()*1e3),this.#be(`idle`);else{if(i.includes(e))return this.#D=a,this.#xe(/* @__PURE__ */ Error(a)),this.#be(`error`);if(e===`error`)return this.#be(`error`);this.#D=e===`quota`&&t||r.get(e)||null,this.#be(`idle`)}}takeNotice(){let e=this.#D;return this.#D=null,e}getDisclosure(){let e=this.config?.disclosureText;return this.#l&&this.#h&&e!==!1?e||`You're talking to an AI assistant. Voice is processed by OpenAI.`:null}async stopListening(){this.#ye(),this.#be(`idle`)}async disconnect(){this.#ye(),this.#be(`disconnected`),this.#G=[],this.#K=[],this.#q=[],this.#J=[],this.#Y=[]}stopPlayback(){this.#ve();let e=this.#e;e&&e.readyState===WebSocket.OPEN&&(this.#h&&(this.#_=Date.now()+2e3,e.send(`{"type":"cancel"}`)),this.#be(`listening`))}getInterruptionMode(){return`barge-in`}isBargeInActive(){return this.#l}onLevel(e){this.#n.push(e)}async deactivateBargeIn(){this.#ye(),this.#be(`idle`)}#ie(e,t,n){let r=e.createMediaStreamSource(t);this.#i=r;let i=e.createScriptProcessor(4096,1,1);this.#a=i,i.onaudioprocess=e=>{if(n!==this.#d)return;let t=this.#e,r=t?.readyState===WebSocket.OPEN;if(t&&!r&&t.readyState!==WebSocket.CONNECTING)return;let i=e.inputBuffer.getChannelData(0),a=new Int16Array(i.length),o=0;for(let e=0;e<i.length;e++){let t=Math.max(-1,Math.min(1,i[e]));o+=t*t,a[e]=t<0?t*32768:t*32767}if(t&&r)this.#ae(t),t.send(a.buffer);else for(this.#o.push(a.buffer),this.#s+=a.byteLength;this.#s>256e3;)this.#s-=this.#o.shift().byteLength;if(this.#n.length>0){let e=Math.sqrt(o/i.length),t=Math.max(0,Math.min(1,e*4));for(let e of this.#n)e(t)}},r.connect(i),i.connect(e.destination)}#ae(e){for(let t of this.#o)e.send(t);this.#o=[],this.#s=0}#oe(e,t){if(t!==this.#d)return;if(e.data instanceof ArrayBuffer){this.#pe(e.data,t);return}let n;try{n=JSON.parse(e.data)}catch{return}switch(n.type){case`session_config`:n.speechMode&&(this.#h=n.speechMode===`speech_to_speech`,this.#c?.setContinuousMode?.(this.#h)),Array.isArray(n.capabilities)&&(this.#S=new Set(n.capabilities)),typeof n.callId==`string`&&(this.#T=n.callId),this.#x=this.#h&&this.#S.has(`client_delegation`)&&!!this.bridge,this.#h&&!this.#u&&this.#be(`listening`),this.#S.has(`context`)&&!this.#j&&(this.#j=!0,this.#M=this.#se()),this.#x&&this.#S.has(`client_tools`)&&!this.#V&&(this.#V=this.bridge.clientTools?.()?.open({send:e=>{let n=this.#e;return t!==this.#d||n?.readyState!==WebSocket.OPEN?!1:(n.send(JSON.stringify(e)),!0)},cancelled:e=>this.#w.has(e)}).catch(()=>null)??null);break;case`client_tool_call`:{let e=String(n.delegationId);this.#V&&!this.#W.has(e)&&(this.#W.set(e,this.#U),this.#F.add(e)),this.#V?.then(e=>e?.call(n));break}case`transcript_update`:{let e=n.role===`assistant`?`assistant`:`user`,r=n.utteranceId??n.turnId;if(!r||e===`assistant`&&this.#me())break;let i=String(r);if(e===`user`)n.final===!0&&(this.#ce(t),this.#U={id:i,text:String(n.text??``)}),this.#R=!1;else{if(this.#S.has(`delegation_read_back`)){let e=n.delegationId;(typeof e==`string`&&this.#F.has(e)&&!this.#z.has(i)||this.#R&&!this.#z.has(i))&&(this.#B.add(i),this.#R=!1)}else this.#R&&!this.#z.has(i)&&(this.#B.add(i),this.#R=!1);if(this.#z.add(i),this.#B.has(i))break}this.#Se(e,n.text??``,n.final===!0,{turnId:i,...typeof n.startMs==`number`&&{startMs:n.startMs},...typeof n.endMs==`number`&&{endMs:n.endMs},...this.#x&&{caption:!0}});break}case`delegation_started`:case`delegation_completed`:{let e=String(n.delegationId??n.turnId);if(n.type===`delegation_started`){this.#ce(t),this.#H.add(e),this.#F.delete(e),this.#W.delete(e)&&this.#V?.then(t=>t?.abort(e));let r=n.input;this.#x&&r&&this.#fe(e,{delegationId:e,userText:String(r.text??``),userUtteranceIds:Array.isArray(r.userUtteranceIds)?r.userUtteranceIds.filter(e=>typeof e==`string`):[],messages:Array.isArray(r.messages)?r.messages:[],priorToolResults:r.priorToolResults},t)}else if(n.route===`direct`&&this.#V&&!this.#H.has(e)){let t=this.#W.get(e)??this.#U;this.#W.delete(e),this.#H.add(e),this.#F.add(e),this.bridge?.recordDirectTurn?.({delegationId:e,userText:t?.text??``,userUtteranceIds:t?[t.id]:[],assistantText:typeof n.text==`string`?n.text:``})}n.type===`delegation_completed`&&n.speak!==!1&&this.#F.has(e)&&!this.#I.delete(e)&&!this.#S.has(`delegation_read_back`)&&this.#ue(e),this.#g=n.type===`delegation_started`,!this.#u&&!this.#me()&&this.#be(this.#g?`processing`:`listening`);break}case`delegation_progress`:{let e=String(n.delegationId);this.#F.has(e)&&!this.#I.has(e)&&!this.#w.has(e)&&(this.#I.add(e),this.#ue(e));break}case`delegation_cancelled`:this.#de(String(n.delegationId),n.reason!==`session_ending`&&n.reason!==`provider_cancelled`);break;case`warning`:console.warn(`[Persona voice] ${n.code}: ${n.message??``}`,this.#T??``),n.delegationId&&(n.code===`UNKNOWN_DELEGATION`||n.code===`LATE_RESULT_LIMIT`)&&this.#de(String(n.delegationId));break;case`audio_clear`:this.#ve(),this.#_=0,this.#be(`listening`);break;case`transcript_interim`:this.#be(`listening`),this.#Se(`user`,n.text??``,!1);break;case`transcript_final`:{let e=n.role===`assistant`?`assistant`:`user`;this.#be(e===`user`?`processing`:`speaking`),this.#Se(e,n.text??``,!0);break}case`audio_end`:this.#c?this.#c.markStreamEnd():(this.#u=!1,this.#be(`listening`));break;case`metrics`:this.#Ce({llmMs:n.llm_ms,ttsMs:n.tts_ms,firstAudioMs:n.first_audio_ms,totalMs:n.total_ms});break;case`error`:this.#xe(Error(n.error||`Voice error`)),this.#be(`error`);break;case`session_end`:this.#E={reason:String(n.reason),...typeof n.message==`string`&&{message:n.message}}}}async#se(){let e=this.bridge?.getHistory()??[],t=``;try{let e=this.config?.callContext;t=String((typeof e==`function`?await e():e)??``)}catch{}return o(e,t)}#ce(e){let t=this.#M;if(!t)return;this.#M=null;let n=!1,r=t.then(t=>{let r=this.#e;!n&&t&&e===this.#d&&r?.readyState===WebSocket.OPEN&&r.send(JSON.stringify({type:`context`,text:t}))});this.#N={done:r,drop:()=>n=!0}}async#le(){let e=this.#N;if(!e)return;let t,n=await Promise.race([e.done.then(()=>!1),new Promise(e=>{t=setTimeout(()=>e(!0),2e3)})]);clearTimeout(t),n&&e.drop()}#ue(e){this.#R=!0,this.#L=e}#de(e,t=!1){this.#w.add(e),this.#L===e&&(this.#R=!1),this.#I.delete(e),this.#H.has(e)||this.#F.delete(e),this.#V?.then(t=>t?.abort(e)),this.bridge?.dropDelegation?.(e,t),this.#C.get(e)?.abort()}#fe(e,t,n){let r=this.bridge,i=({type:t,...r})=>{let i=this.#e;return n!==this.#d||i?.readyState!==WebSocket.OPEN||this.#w.has(e)?!1:(i.send(JSON.stringify({type:t,delegationId:e,...r})),!0)},a=(e,t,n,r=0)=>i({type:e,status:t,text:n,...r>0&&{streamedChars:r}});this.#P=this.#P.then(async()=>{if(n!==this.#d||this.#w.has(e))return;let o=null,s=this.#S.has(`delegation_stream`)&&this.#S.has(`delegation_read_back`),c=t=>{o=(o??this.#le()).then(()=>{i({type:`delegation_delta`,text:t})&&this.#F.add(e)})},l=await r.runDelegatedTurn(s?{...t,stream:c}:t).catch(()=>({status:`failed`,text:``}));await this.#le(),await o;let u=s?l.streamedChars??0:0,d=!!l.followUp,f=d&&this.#S.has(`delegation_update`);if(!a(f?`delegation_update`:`delegation_result`,d&&!f?`completed`:l.status,l.text,u)||(l.status!==`failed`&&l.inChat!==!1&&this.#F.add(e),!l.followUp))return;let p=new AbortController;this.#C.set(e,p),l.followUp({signal:p.signal,approvalTimeoutMs:this.config?.approvalTimeoutMs&&Math.min(this.config.approvalTimeoutMs,54e4),readBack:f,onUpdate:e=>a(`delegation_update`,`pending_approval`,e)}).then(t=>{this.#C.delete(e),f&&t&&!p.signal.aborted&&a(`delegation_result`,t.status,t.text)})})}#pe(e,t){if(t!==this.#d||!this.#c||this.#me())return;let n=s(e);n.length!==0&&(this.#u||(this.#u=!0,this.#be(`speaking`)),this.#he(),this.#c.enqueue(n),this.#h&&this.#ge(n.length))}#me(){return Date.now()<this.#_}#he(){if(this.#b||!this.#c)return;this.#b=!0;let e=this.#d;this.#c.onFinished(()=>{e===this.#d&&(this.#b=!1,this.#_e())})}#ge(e){let t=Date.now();this.#v=Math.max(t,this.#v)+e/48,clearTimeout(this.#y),this.#y=setTimeout(()=>this.#_e(),this.#v-t+300)}#_e(){this.#u=!1,this.#v=0,this.#e&&this.#e.readyState===WebSocket.OPEN&&this.#be(this.#g?`processing`:`listening`)}#ve(){this.#c?.flush(),this.#b=!1,this.#he(),this.#u=!1,this.#v=0,clearTimeout(this.#y)}#ye(){this.#d+=1,this.#l=!1,this.#u=!1,this.#$(),this.#h=!1,this.#g=!1,this.#x=!1,this.#S=/* @__PURE__ */ new Set;for(let e of this.#C.values())e.abort();if(this.#C.clear(),this.#w.clear(),this.#T=void 0,this.#E=null,clearTimeout(this.#O),this.#j=!1,this.#M=null,this.#N=null,this.#P=Promise.resolve(),this.#F.clear(),this.#I.clear(),this.#L=null,this.#R=!1,this.#z.clear(),this.#B.clear(),this.#V?.then(e=>e?.close()),this.#V=null,this.#H.clear(),this.#W.clear(),this.#U=null,this.#b=!1,this.#_=0,this.#v=0,clearTimeout(this.#y),this.#o=[],this.#s=0,this.#a&&=(this.#a.onaudioprocess=null,this.#a.disconnect(),null),this.#i&&=(this.#i.disconnect(),null),this.#r&&=(this.#r.getTracks().forEach(e=>e.stop()),null),this.#t&&=(this.#t.close().catch(()=>{}),null),this.#c&&=(this.#c.destroy(),null),this.#e){this.#f=!0;try{this.#e.close(1e3,`client ended call`)}catch{}this.#e=null}}onResult(e){this.#G.push(e)}onError(e){this.#K.push(e)}onStatusChange(e){this.#q.push(e)}onTranscript(e){this.#J.push(e)}onMetrics(e){this.#Y.push(e)}#be(e){this.#q.forEach(t=>t(e))}#xe(e){this.#K.forEach(t=>t(e))}#Se(e,t,n,r){this.#J.forEach(i=>i(e,t,n,r))}#Ce(e){this.#Y.forEach(t=>t(e))}},f=class{#e;#t;#n;#r;#i;#a;constructor(e={}){this.config=e,this.type=`browser`,this.#e=null,this.#t=[],this.#n=[],this.#r=[],this.#i=!1,this.#a=typeof window<`u`?window:void 0}async connect(){this.#r.forEach(e=>e(`connected`))}async startListening(){try{if(this.#i)throw Error(`Already listening`);if(!this.#a)throw Error(`Window object not available`);let e=this.#a.SpeechRecognition||this.#a.webkitSpeechRecognition;if(!e)throw Error(`Browser speech recognition not supported`);this.#e=new e,this.#e.lang=this.config?.language||`en-US`,this.#e.continuous=this.config?.continuous||!1,this.#e.interimResults=!0,this.#e.onresult=e=>{let t=Array.from(e.results).map(e=>e[0]).map(e=>e.transcript).join(``),n=e.results[e.results.length-1].isFinal;this.#t.forEach(e=>e({text:t,confidence:n?.8:.5,provider:`browser`})),n&&!this.config?.continuous&&this.stopListening()},this.#e.onerror=e=>{this.#n.forEach(t=>t(Error(e.error))),this.#r.forEach(e=>e(`error`))},this.#e.onstart=()=>{this.#i=!0,this.#r.forEach(e=>e(`listening`))},this.#e.onend=()=>{this.#i=!1,this.#r.forEach(e=>e(`idle`))},this.#e.start()}catch(e){throw this.#n.forEach(t=>t(e)),this.#r.forEach(e=>e(`error`)),e}}async stopListening(){this.#e&&=(this.#e.stop(),null),this.#i=!1,this.#r.forEach(e=>e(`idle`))}onResult(e){this.#t.push(e)}onError(e){this.#n.push(e)}onStatusChange(e){this.#r.push(e)}async disconnect(){await this.stopListening(),this.#r.forEach(e=>e(`disconnected`))}static isSupported(){return`SpeechRecognition`in window||`webkitSpeechRecognition`in window}};function p(e){switch(e.type){case`runtype`:if(!e.runtype)throw Error(`Runtype voice provider requires configuration`);return new d(e.runtype);case`browser`:if(!f.isSupported())throw Error(`Browser speech recognition not supported`);return new f(e.browser||{});case`custom`:{let t=e.custom;if(!t)throw Error("Custom voice provider requires a `custom` provider instance or factory");let n=typeof t==`function`?t():t;if(!n||typeof n.startListening!=`function`)throw Error("Custom voice provider `custom` must be a VoiceProvider (or a factory returning one)");return n}default:throw Error(`Unknown voice provider type: ${e.type}`)}}function m(e){if(e?.type===`custom`&&e.custom)return p({type:`custom`,custom:e.custom});if(e?.type===`runtype`&&e.runtype)return p({type:`runtype`,runtype:e.runtype});if(f.isSupported())return p({type:`browser`,browser:e?.browser||{language:`en-US`}});throw Error(`No supported voice providers available`)}function h(e){try{return m(e),!0}catch{return!1}}const g=e=>e.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,``);var _=class{constructor(e){this.host=e,this.turns=/* @__PURE__ */ new Map,this.latestId=null,this.cancelled=/* @__PURE__ */ new Set}apply(e,t,n,r,i,a){let o=this.host;t=t.trim();let s=this.turns.get(r);if(s||(s={},this.turns.set(r,s),this.latestId=r),e===`user`){s.userFinal=n;let e=s.userId?o.find(s.userId):void 0;if(e){let r=s.userStartMs===void 0&&i!==void 0;r&&(s.userStartMs=i),o.upsert({...e,content:t,voiceProcessing:!n,...r&&this.placeBefore(this.startedAfter(i))})}else{s.userStartMs=i;let e=s.assistantId?o.find(s.assistantId):void 0;s.userId=o.inject({role:`user`,content:t,streaming:!1,voiceProcessing:!n,voiceCaption:a,...this.placeBefore(this.startedAfter(i)??e)}).id}}else if(!this.cancelled.has(r)){s.assistantFinal=n;let e=s.assistantId?o.find(s.assistantId):void 0;if(e){let r=s.assistantStartMs===void 0&&i!==void 0;r&&(s.assistantStartMs=i),o.upsert({...e,content:t,streaming:!n,voiceProcessing:!n,...r&&this.placeBefore(this.startedAfter(i))})}else t&&(s.assistantStartMs=i,s.assistantId=o.inject({role:`assistant`,content:t,streaming:!n,voiceProcessing:!n,voiceCaption:a,...this.placeBefore(this.startedAfter(i))}).id);n&&s.assistantId&&o.markSpoken(s.assistantId)}this.sync()}claimUserTurn(e,t=[]){let n=t[t.length-1];for(let e of t)e!==n&&(this.turns.has(e)||this.turns.set(e,{}),this.turns.get(e).claimed=!0);let r;if(n){if(r=this.turns.get(n),r||(r={},this.turns.set(n,r)),r.claimed)return null;r.userId&&this.host.find(r.userId)||(r.userFinal=!0,r.userId=this.host.inject({role:`user`,content:e.trim()}).id)}else{let t=g(e),n=[...this.turns.values()].reverse().flatMap(e=>{let t=e.userId&&!e.claimed?this.host.find(e.userId):void 0;return t?[{turn:e,text:g(t.content)}]:[]}).filter(({text:e})=>e&&t);r=(n.find(({text:e})=>e===t)??n.find(({text:e})=>e.startsWith(t)||t.startsWith(e)))?.turn}return r?(r.claimed=!0,r.userId):null}cancel(){let e=this.inFlight();if(e.length===0){let t=this.awaiting();if(!t)return;e=[t]}for(let t of e)this.cancelled.add(t);this.closeReplies(e),this.sync()}fail(e){let t=this.awaiting(),n=this.inFlight();if(!t&&n.length===0)return;for(let e of n)this.turns.get(e).assistantFinal=!0;this.closeReplies(n);let r=this.host.inject({role:`assistant`,content:e,streaming:!1,voiceProcessing:!1}),i=t?this.turns.get(t):void 0;i&&(i.assistantId=r.id,i.assistantFinal=!0),this.sync()}settle(){if(this.turns.size===0)return;let e=this.pending(),t=/* @__PURE__ */ new Set;for(let e of this.turns.values())e.userId&&t.add(e.userId),e.assistantId&&(t.add(e.assistantId),this.host.markSpoken(e.assistantId));this.turns.clear(),this.latestId=null,this.host.settle(t),e&&this.host.setStreaming(!1)}startedAfter(e){if(e===void 0)return;let t;for(let n of this.turns.values())for(let[r,i]of[[n.userId,n.userStartMs],[n.assistantId,n.assistantStartMs]])r&&i!==void 0&&i>e&&(!t||i<t.start)&&(t={start:i,id:r});return t&&this.host.find(t.id)}placeBefore(e){if(!e)return;let t=e.sequence??0,n=t-1;for(let r of this.turns.values())for(let i of[r.userId,r.assistantId]){let r=i?this.host.find(i):void 0,a=r?.sequence;r?.createdAt===e.createdAt&&a!==void 0&&a>n&&a<t&&(n=a)}return{createdAt:e.createdAt,sequence:(n+t)/2}}closeReplies(e){let t=/* @__PURE__ */ new Set;for(let n of e){let e=this.turns.get(n)?.assistantId;e&&(t.add(e),this.host.markSpoken(e))}t.size>0&&this.host.settle(t)}inFlight(){let e=[];for(let[t,n]of this.turns)n.assistantId&&!n.assistantFinal&&!this.cancelled.has(t)&&e.push(t);return e}awaiting(){let e=this.latestId;if(!e)return null;let t=this.turns.get(e);return t?.userFinal&&!t.assistantId&&!t.claimed&&!this.cancelled.has(e)?e:null}pending(){return this.awaiting()!==null||this.inFlight().length>0}sync(){this.host.setStreaming(this.pending())}};const v=/* @__PURE__ */ new Set(/* @__PURE__ */ `mr,mrs,ms,dr,prof,sr,jr,st,mt,vs,etc,approx,inc,ltd,co,corp,no,nos,fig,ft,dept,est,min,max,e.g,i.e,a.m,p.m,u.s,u.k`.split(`,`)),y=/([.!?]+|[,;:])(["'”’)\]*_]*)(\s+)|\n\s*/g;function b(e){let t=/(\S+)$/.exec(e)?.[1];if(!t)return!1;let n=t.replace(/^[("'“‘[*_]+/,``).toLowerCase();if(v.has(n)||/^[a-z](?:\.[a-z])*$/.test(n))return!0;if(/^\d+$/.test(t)){let n=e.length-t.length;return n===0||/\n\s*$/.test(e.slice(0,n))}return!1}function*x(e,t){let n=new RegExp(y.source,`g`);for(let r=n.exec(e);r;r=n.exec(e)){let n=r[1];if(!e.slice(0,r.index+(n?.length??0)).trim()||n!==void 0&&(/^[,;:]$/.test(n)&&!t||n===`.`&&b(e.slice(0,r.index))))continue;let i=r.index+r[0].length;i<e.length&&(yield i)}}function S(e,t){let n=e.slice(0,t),r=0;for(let e of n.matchAll(/\s+/g))n.slice(0,e.index).trim()&&(r=e.index+e[0].length);return r}function C(e){let t=0;for(let n of x(e.slice(0,220),!0))t=n;if(t)return t;let n=S(e,220);if(n)return n;let r=e.charCodeAt(219);return r>=55296&&r<=56319?219:220}var w=class{#e=``;#t=!0;push(e){return this.#e+=e,this.#n()}flush(){let e=this.#n(),t=this.#e;if(this.#e=``,t.trim()){for(let n=0;n<t.length;){let r=t.slice(n),i=r.length>220?C(r):r.length;e.push(r.slice(0,i)),n+=i}this.#t=!1}return e}idle(){let e=this.#e;if(!e.trim()||!/(?:[.!?…]["'”’)\]*_]*|\n)\s*$/.test(e))return[];this.#e=``,this.#t=!1;let t=[];for(let n=0;n<e.length;){let r=e.slice(n),i=r.length>220?C(r):r.length;t.push(r.slice(0,i)),n+=i}return t}#n(){let e=[];for(let t=this.#r();t>0;t=this.#r())e.push(this.#e.slice(0,t)),this.#e=this.#e.slice(t),this.#t=!1;return e}#r(){let e=this.#e;if(!e.trim())return 0;let t=x(e,this.#t).next().value??0;if(t&&t<=220)return t;let n=/[.!?]["'”’)\]*_]*$/.test(e);if(this.#t&&!n){let t=e.match(/\S+\s+/g)?.length??0;if(e.trim().length>=30||t>=6){let t=S(e,220);if(t)return t}}return e.length>220?C(e):0}};const T=(e,t)=>{let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n+=1;return n},E=`no|nope|never ?mind|decline(?: it| that)?|cancel(?: it| that| this)?(?: (?:the|my|that|this) (?:[a-z]+ )?(?:order|request))?|don'?t (?:do|place) (?:it|that|the (?:[a-z]+ )?order)`,D=RegExp(`^(?:${E})(?: (?:${E}))?(?: thanks| thank you)?$`),O=e=>D.test(e.toLowerCase().replace(/[^a-z' ]+/g,` `).replace(/\s+/g,` `).trim()),k=()=>new Promise(e=>setTimeout(e,50)),A=(e,t)=>e.length>t?`${e.slice(0,t-1).trimEnd()}…`:e,j=e=>e.replace(/^webmcp:/,``).replace(/([a-z\d])([A-Z])/g,`$1 $2`).replace(/[_\-.]+/g,` `).trim().toLowerCase();function M(e,t=0){if(e==null||e===``)return``;if(typeof e!=`object`)return String(e);if(t>2)return``;if(Array.isArray(e))return e.map(e=>M(e,t+1)).filter(Boolean).join(`, `);let n=e,r=n.quantity??n.qty??n.count,i=n.name??n.item??n.product??n.title;return r!=null&&i!=null&&typeof i!=`object`?`${r} ${i}`:Object.entries(n).filter(([e])=>!e.startsWith(`_`)).map(([e,n])=>{let r=M(n,t+1);return r&&(t?`${j(e)} ${r}`:`${j(e)}: ${r}`)}).filter(Boolean).join(t?`, `:`; `)}function N(e){let t=e.length>1?`These actions need the user's approval in the chat before they happen:`:`This action needs the user's approval in the chat before it happens:`,n=1e3-t.length-119-2;return`${t}\n${e.map(t=>{let r=[j(t.toolName)];t.description&&r.push(`(${A(t.description.trim(),160)})`);let i=M(t.parameters);return i&&r.push(`with ${i}`),t.reason&&r.push(`because: ${A(t.reason.trim(),160)}`),A(`- ${r.join(` `)}`,Math.floor(n/e.length)-1)}).join(`