@runtypelabs/persona 4.32.1 → 4.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activity-ui.d.cts +3 -3
- package/dist/activity-ui.d.ts +3 -3
- package/dist/animations/glyph-cycle.d.cts +1 -1
- package/dist/animations/glyph-cycle.d.ts +1 -1
- package/dist/animations/wipe.d.cts +1 -1
- package/dist/animations/wipe.d.ts +1 -1
- package/dist/approval-ui.d.cts +2 -2
- package/dist/approval-ui.d.ts +2 -2
- package/dist/artifacts-ui.d.cts +3 -3
- package/dist/artifacts-ui.d.ts +3 -3
- package/dist/background-runtime.d.cts +1 -1
- package/dist/background-runtime.d.ts +1 -1
- package/dist/{chunk-BbXc58OA.js → chunk-6CUrH_jm.js} +1 -1
- package/dist/{chunk-B_H0l3u2.js → chunk-BRM3bHcJ.js} +1 -1
- package/dist/chunk-CEPM3FOp.js +1 -0
- package/dist/{chunk-CumoXK3u.js → chunk-CXQJG7pb.js} +1 -1
- package/dist/{chunk-UWMfWW2a.js → chunk-D1G8tgYc.js} +1 -1
- package/dist/{chunk-BpjtKnGI.js → chunk-D6U0E82p.js} +1 -1
- package/dist/{chunk-2FnmZ9AA.js → chunk-DOZmcve8.js} +1 -1
- package/dist/chunk-DVgzoVCB.js +1 -0
- package/dist/{chunk-C9uOhfk5.js → chunk-DW7Vg_l2.js} +1 -1
- package/dist/{chunk-B3l7TOOv.js → chunk-DbGLjU2P.js} +1 -1
- package/dist/{chunk-DTGvDx8o.js → chunk-Dj2a9f9w.js} +1 -1
- package/dist/{chunk-DgZZqy14.js → chunk-d54BJdKd.js} +1 -1
- package/dist/chunk-dLJWKfOb.js +1 -0
- package/dist/{chunk-DNdeIFJ6.js → chunk-gu34lr-P.js} +1 -1
- package/dist/chunk-i4qGOJAL.js +1 -0
- package/dist/{chunk-DVZ8ri1z.js → chunk-ql5N2I_t.js} +1 -1
- package/dist/client-dispatch.js +1 -1
- package/dist/client-history.js +1 -1
- package/dist/codegen.cjs +1 -1
- package/dist/codegen.js +1 -1
- package/dist/composer-actions-runtime.d.cts +2 -2
- package/dist/composer-actions-runtime.d.ts +2 -2
- package/dist/{composer-input-dwg_o9Z-.d.cts → composer-input-DnqGCXZz.d.cts} +1 -1
- package/dist/{composer-input-dwg_o9Z-.d.ts → composer-input-DnqGCXZz.d.ts} +1 -1
- package/dist/{composer-store-Dw7Zbqxr.d.cts → composer-store-6Iwy6WLI.d.cts} +1 -1
- package/dist/{composer-store-Dw7Zbqxr.d.ts → composer-store-6Iwy6WLI.d.ts} +1 -1
- package/dist/{context-mention-manager-D2p0-JH-.d.cts → context-mention-manager-B-rHF98n.d.cts} +2 -2
- package/dist/{context-mention-manager-D2p0-JH-.d.ts → context-mention-manager-B-rHF98n.d.ts} +2 -2
- package/dist/context-mentions-inline.d.cts +2 -2
- package/dist/context-mentions-inline.d.ts +2 -2
- package/dist/context-mentions.d.cts +3 -3
- package/dist/context-mentions.d.ts +3 -3
- package/dist/{defaults-CjX0kKzb.d.ts → defaults-BuOjqUAG.d.cts} +2 -1
- package/dist/{defaults-CjX0kKzb.d.cts → defaults-BuOjqUAG.d.ts} +2 -1
- package/dist/dictation-runtime.d.cts +2 -2
- package/dist/dictation-runtime.d.ts +2 -2
- package/dist/event-stream-view.d.cts +1 -1
- package/dist/event-stream-view.d.ts +1 -1
- package/dist/{fallback-speech-engine-DmF7MczI.d.cts → fallback-speech-engine-SqEfkGda.d.cts} +1 -1
- package/dist/{fallback-speech-engine-DmF7MczI.d.ts → fallback-speech-engine-SqEfkGda.d.ts} +1 -1
- package/dist/{feature-preferences-CVFDt9Xf.d.cts → feature-preferences-DqAmje-2.d.cts} +1 -1
- package/dist/{feature-preferences-CVFDt9Xf.d.ts → feature-preferences-DqAmje-2.d.ts} +1 -1
- package/dist/forms-ui.d.cts +2 -2
- package/dist/forms-ui.d.ts +2 -2
- package/dist/{history-confirm-dialog-DJEXsTyE.d.cts → history-confirm-dialog-B3L7QNcO.d.cts} +1 -1
- package/dist/{history-confirm-dialog-DJEXsTyE.d.ts → history-confirm-dialog-B3L7QNcO.d.ts} +1 -1
- package/dist/history-shell.cjs +1 -1
- package/dist/history-shell.d.cts +6 -6
- package/dist/history-shell.d.ts +6 -6
- package/dist/history-shell.js +1 -1
- package/dist/history-view.d.cts +1 -1
- package/dist/history-view.d.ts +1 -1
- package/dist/index.cjs +38 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +52 -52
- package/dist/index.js.map +1 -1
- package/dist/install.global.js +1 -1
- package/dist/install.global.js.map +1 -1
- package/dist/launcher.global.js +2 -2
- package/dist/launcher.global.js.map +1 -1
- package/dist/{loading-label-runtime-loader-CPxnoaoi.d.cts → loading-label-runtime-loader-JecjOfJS.d.cts} +1 -1
- package/dist/{loading-label-runtime-loader-CPxnoaoi.d.ts → loading-label-runtime-loader-JecjOfJS.d.ts} +1 -1
- package/dist/loading-label-runtime.d.cts +1 -1
- package/dist/loading-label-runtime.d.ts +1 -1
- package/dist/{message-bubble-CkZGlCLC.d.ts → message-bubble-CBYtpDsT.d.cts} +2 -2
- package/dist/{message-bubble-CkZGlCLC.d.cts → message-bubble-CBYtpDsT.d.ts} +2 -2
- package/dist/preferences-runtime.d.cts +1 -1
- package/dist/preferences-runtime.d.ts +1 -1
- package/dist/{preview-DdUvoLb4.d.cts → preview-_UJwwt2L.d.cts} +2 -2
- package/dist/{preview-DdUvoLb4.d.ts → preview-_UJwwt2L.d.ts} +2 -2
- package/dist/{registry-Dz4iHNST.d.cts → registry-B5ZV3K-h.d.cts} +1 -1
- package/dist/{registry-Dz4iHNST.d.ts → registry-B5ZV3K-h.d.ts} +1 -1
- package/dist/{session-Baxp9iRK.d.cts → session-Bys8_XuB.d.cts} +10 -9
- package/dist/{session-Baxp9iRK.d.ts → session-Bys8_XuB.d.ts} +10 -9
- package/dist/session-reconnect.d.cts +2 -2
- package/dist/session-reconnect.d.ts +2 -2
- package/dist/smart-dom-reader.d.cts +1 -1
- package/dist/smart-dom-reader.d.ts +1 -1
- package/dist/theme-editor-preview.cjs +31 -31
- package/dist/theme-editor-preview.d.cts +1 -1
- package/dist/theme-editor-preview.d.ts +1 -1
- package/dist/theme-editor-preview.js +19 -19
- package/dist/theme-editor.cjs +1 -1
- package/dist/theme-editor.d.cts +2 -2
- package/dist/theme-editor.d.ts +2 -2
- package/dist/theme-editor.js +1 -1
- package/dist/theme-reference.cjs +1 -1
- package/dist/theme-reference.d.cts +4 -2
- package/dist/theme-reference.d.ts +4 -2
- package/dist/theme-reference.js +1 -1
- package/dist/{tool-loading-animation-un3kA5Ur.d.cts → tool-loading-animation-d5qAQcwv.d.cts} +1 -1
- package/dist/{tool-loading-animation-un3kA5Ur.d.ts → tool-loading-animation-d5qAQcwv.d.ts} +1 -1
- package/dist/{turn-activity-ui-BGNhtMcH.d.cts → turn-activity-ui-q6fHVnx-.d.cts} +2 -2
- package/dist/{turn-activity-ui-BGNhtMcH.d.ts → turn-activity-ui-q6fHVnx-.d.ts} +2 -2
- package/dist/turn-activity-ui.d.cts +1 -1
- package/dist/turn-activity-ui.d.ts +1 -1
- package/dist/{types-BOZHQIk0.d.cts → types-B_mj21jg.d.cts} +91 -7
- package/dist/{types-BOZHQIk0.d.ts → types-B_mj21jg.d.ts} +91 -7
- package/dist/voice-client-tools.d.cts +1 -1
- package/dist/voice-client-tools.d.ts +1 -1
- package/dist/voice-runtime.cjs +1 -1
- package/dist/voice-runtime.d.cts +2 -2
- package/dist/voice-runtime.d.ts +2 -2
- package/dist/voice-runtime.js +1 -1
- package/dist/voice-worklet-player.d.cts +2 -2
- package/dist/voice-worklet-player.d.ts +2 -2
- package/dist/{webmcp-runtime-entry-DuAG1_yF.d.cts → webmcp-runtime-entry-ClEO3qdI.d.cts} +1 -1
- package/dist/{webmcp-runtime-entry-DuAG1_yF.d.ts → webmcp-runtime-entry-ClEO3qdI.d.ts} +1 -1
- package/dist/webmcp-runtime.d.cts +1 -1
- package/dist/webmcp-runtime.d.ts +1 -1
- package/dist/widget.css +1 -1
- package/package.json +1 -1
- package/src/client-dispatch.ts +69 -16
- package/src/client.operator-role.test.ts +217 -0
- package/src/components/message-bubble.test.ts +169 -0
- package/src/components/message-bubble.ts +97 -28
- package/src/defaults-parity.test.ts +14 -0
- package/src/index-core.ts +7 -0
- package/src/index-global.ts +2 -1
- package/src/install.test.ts +6 -5
- package/src/install.ts +2 -2
- package/src/launcher-global.ts +2 -1
- package/src/session.resubmit-from.test.ts +27 -0
- package/src/session.test.ts +51 -0
- package/src/session.ts +22 -12
- package/src/styles/widget.css +23 -1
- package/src/theme-reference.ts +3 -1
- package/src/types/theme.ts +21 -0
- package/src/types.ts +71 -6
- package/src/ui.ask-user-question-plugin.test.ts +154 -0
- package/src/ui.operator-role.test.ts +336 -0
- package/src/ui.ts +37 -12
- package/src/utils/__snapshots__/tokens-parity.test.ts.snap +236 -0
- package/src/utils/brand.test.ts +14 -0
- package/src/utils/brand.ts +8 -4
- package/src/utils/cdn-release.test.ts +20 -0
- package/src/utils/cdn-release.ts +14 -0
- package/src/utils/history-messages.test.ts +30 -0
- package/src/utils/history-messages.ts +26 -8
- package/src/utils/message-fingerprint.ts +4 -0
- package/src/utils/resubmit-turn.test.ts +13 -0
- package/src/utils/resubmit-turn.ts +12 -1
- package/src/utils/tokens.ts +31 -0
- package/src/welcome.test.ts +16 -0
- package/src/welcome.ts +10 -2
- package/dist/chunk-BkOYJ11B.js +0 -1
- package/dist/chunk-Bz9jAgba.js +0 -1
- package/dist/chunk-CdpVP6LZ.js +0 -1
- package/dist/chunk-DM-OJt5q.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ai as PersonaArtifactDisplayModeInput, Li as PersonaArtifactRecord, Oa as WidgetPreferenceSlice, Pi as PersonaArtifactKind, _ as AgentWidgetArtifactsFeature, k as AgentWidgetConfig, ki as PersonaArtifactDisplayMode, nt as AgentWidgetFeatureFlags } from "./types-B_mj21jg.cjs";
|
|
2
2
|
//#region src/utils/artifact-display.d.ts
|
|
3
3
|
/** Canonicalize the deprecated `"card"` alias to `"collapsed"`. */
|
|
4
4
|
declare function canonicalArtifactDisplayMode(mode: PersonaArtifactDisplayModeInput): PersonaArtifactDisplayMode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ai as PersonaArtifactDisplayModeInput, Li as PersonaArtifactRecord, Oa as WidgetPreferenceSlice, Pi as PersonaArtifactKind, _ as AgentWidgetArtifactsFeature, k as AgentWidgetConfig, ki as PersonaArtifactDisplayMode, nt as AgentWidgetFeatureFlags } from "./types-B_mj21jg.js";
|
|
2
2
|
//#region src/utils/artifact-display.d.ts
|
|
3
3
|
/** Canonicalize the deprecated `"card"` alias to `"collapsed"`. */
|
|
4
4
|
declare function canonicalArtifactDisplayMode(mode: PersonaArtifactDisplayModeInput): PersonaArtifactDisplayMode;
|
package/dist/forms-ui.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Ct as AgentWidgetMessage, k as AgentWidgetConfig } from "./types-
|
|
2
|
-
import { t as AgentWidgetSession } from "./session-
|
|
1
|
+
import { Ct as AgentWidgetMessage, k as AgentWidgetConfig } from "./types-B_mj21jg.cjs";
|
|
2
|
+
import { t as AgentWidgetSession } from "./session-Bys8_XuB.cjs";
|
|
3
3
|
//#region src/components/forms.d.ts
|
|
4
4
|
export declare const formDefinitions: Record<string, {
|
|
5
5
|
title: string;
|
package/dist/forms-ui.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Ct as AgentWidgetMessage, k as AgentWidgetConfig } from "./types-
|
|
2
|
-
import { t as AgentWidgetSession } from "./session-
|
|
1
|
+
import { Ct as AgentWidgetMessage, k as AgentWidgetConfig } from "./types-B_mj21jg.js";
|
|
2
|
+
import { t as AgentWidgetSession } from "./session-Bys8_XuB.js";
|
|
3
3
|
//#region src/components/forms.d.ts
|
|
4
4
|
export declare const formDefinitions: Record<string, {
|
|
5
5
|
title: string;
|
package/dist/{history-confirm-dialog-DJEXsTyE.d.cts → history-confirm-dialog-B3L7QNcO.d.cts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fa as HistoryOperationContext, Ra as HistoryProvider, ct as AgentWidgetHistoryListAction, li as HistoryIdentityStatus, lt as AgentWidgetHistoryRenderActions, ot as AgentWidgetHistoryCopy, si as HistoryConversationSummary } from "./types-B_mj21jg.cjs";
|
|
2
2
|
import { n as TooltipOptions, t as TooltipHandle } from "./tooltip-BkW-8MnD.cjs";
|
|
3
3
|
//#region src/components/history-view/copy.d.ts
|
|
4
4
|
type HistoryViewCopyInput = AgentWidgetHistoryCopy;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fa as HistoryOperationContext, Ra as HistoryProvider, ct as AgentWidgetHistoryListAction, li as HistoryIdentityStatus, lt as AgentWidgetHistoryRenderActions, ot as AgentWidgetHistoryCopy, si as HistoryConversationSummary } from "./types-B_mj21jg.js";
|
|
2
2
|
import { n as TooltipOptions, t as TooltipHandle } from "./tooltip-BkW-8MnD.js";
|
|
3
3
|
//#region src/components/history-view/copy.d.ts
|
|
4
4
|
type HistoryViewCopyInput = AgentWidgetHistoryCopy;
|
package/dist/history-shell.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=e=>e?.layout?.embedded===!0&&e.launcher?.enabled===!1&&!e.launcher.sidebarMode&&(e.launcher.mountMode??`floating`)===`floating`,t=t=>t?.layout?.showHeader??!e(t),n=/* @__PURE__ */ `viewTitle.openHistoryLabel.openHistoryBusyLabel.newConversationLabel.expandLabel.collapseLabel.resizeLabel.showEarlierMessagesLabel.openConversationLoadingLabel.openConversationErrorTitle.openConversationRetryLabel.openConversationBackLabel.confirmCancelLabel.deleteConversationConfirmTitle.deleteConversationConfirm.deleteConversationConfirmLabel.clearHistoryConfirmTitle.clearHistoryConfirm.clearHistoryVerifiedConfirm.clearHistoryConfirmLabel.resetIdentityConfirmTitle.resetIdentityConfirm.resetIdentityConfirmLabel.conversationDeletedNotice.identityResetNotice.identityResetUnconfirmedNotice`.split(`.`),r={viewTitle:`Messages`,openHistoryLabel:`Messages`,openHistoryBusyLabel:`Messages, available once the reply finishes`,newConversationLabel:`New conversation`,expandLabel:`Expand conversation list`,collapseLabel:`Collapse conversation list`,resizeLabel:`Resize conversation list`,showEarlierMessagesLabel:`Show earlier messages`,openConversationLoadingLabel:`Loading conversation`,openConversationErrorTitle:`Could not open the conversation.`,openConversationRetryLabel:`Try again`,openConversationBackLabel:`Back to messages`,confirmCancelLabel:`Cancel`,deleteConversationConfirmTitle:`Delete conversation`,deleteConversationConfirm:`Delete this conversation? This cannot be undone.`,deleteConversationConfirmLabel:`Delete`,clearHistoryConfirmTitle:`Delete all conversations`,clearHistoryConfirm:`Delete all conversations for this assistant on this browser? This cannot be undone.`,clearHistoryVerifiedConfirm:`Delete all conversations for this assistant and signed-in user? This cannot be undone.`,clearHistoryConfirmLabel:`Delete all`,resetIdentityConfirmTitle:`Forget this device`,resetIdentityConfirm:`Forget this device? All Persona data stored in this browser is cleared. Records are not deleted elsewhere.`,resetIdentityConfirmLabel:`Forget this device`,conversationDeletedNotice:`That conversation was deleted. You are now in a new conversation.`,identityResetNotice:`This device was forgotten.`,identityResetUnconfirmedNotice:`This device was cleared here, but the server could not confirm it.`};function i(e){if(!e)return r;let t={...r};for(let r of n){let n=e[r];typeof n==`string`&&n.length>0&&(t[r]=n)}return t}const a=(e,t)=>{console.warn(`[persona] ${e} threw`,t)},o=e=>Object.freeze({...e}),s=e=>Object.freeze({id:e.id,title:e.title,targetId:e.targetId,preview:e.preview,messageCount:e.messageCount,createdAt:e.createdAt,updatedAt:e.updatedAt}),c=e=>e?o(e):null;function l(e){let{plugins:t,config:n}=e,r=!1,i=!1,l=!1,u=!1,d=null,f=[],p=()=>{for(let e of f.splice(0))try{e()}catch(e){a(`renderHistoryView cleanup`,e)}},m=(e,n)=>{for(let r of t){let t=r[e];if(t)try{let e=t(n);if(e)return e}catch(t){a(e,t)}}return null},h=()=>({presentation:e.getPresentation(),config:n}),g={header:t=>u?m(`renderHistoryHeader`,Object.freeze({...h(),returnSurface:e.getReturnSurface(),identityStatus:o(t.identityStatus),pendingAction:c(t.pendingAction),copy:o(t.copy),actions:Object.freeze({close:y.close,startNewConversation:y.startNewConversation}),defaultRenderer:t.defaultRenderer})):null,conversation:e=>u?m(`renderHistoryConversation`,Object.freeze({...h(),conversation:s(e.conversation),active:e.active,pending:e.pending,open:e.open,requestDelete:e.requestDelete,defaultRenderer:e.defaultRenderer})):null,state:e=>u?m(`renderHistoryState`,Object.freeze({...h(),state:o(e.state),identityStatus:o(e.identityStatus),copy:o(e.copy),...e.retry?{retry:e.retry}:{},...e.startNewConversation?{startNewConversation:e.startNewConversation}:{},defaultRenderer:e.defaultRenderer})):null},_=t.flatMap(t=>(t.railSections??[]).map(t=>({...t,placement:t.placement??`above-conversations`,items:[],render:n=>t.render(Object.freeze({collapsed:n,presentation:e.getPresentation(),actions:y}))}))),v=e.createView({slots:g,renderDom:!1,onModelChange:()=>C(),railSections:_}),y=Object.freeze({...v.operations,close:e.close}),b=()=>(u=!0,v.setDomRenderEnabled(!0),v.element),x=t=>Object.freeze({conversations:Object.freeze(t.conversations.map(s)),activeConversationId:t.activeConversationId,state:o(t.state),pendingAction:c(t.pendingAction),identityStatus:o(t.identityStatus),nextCursor:t.nextCursor,presentation:e.getPresentation(),returnSurface:e.getReturnSurface(),config:n,copy:o(v.copy),actions:y,defaultRenderer:b,requestRender:()=>C(),onCleanup:e=>{f.push(e)}}),S=()=>{u=!1;let e=null;for(let n of t)if(n.renderHistoryView){try{e=n.renderHistoryView(x(v.getModel()))}catch(t){a(`renderHistoryView`,t),e=null}if(e)break}let n=!e||e.contains(v.element);return u=n,v.setDomRenderEnabled(n),e??v.element};function C(){if(!(!l||r||i)){i=!0;try{p();let t=S();if(t===d)return;let n=d;d=t,e.onElementChanged(t,n)}finally{i=!1}}}return l=!0,C(),{view:v,get element(){return d??v.element},requestRender:C,dispose:()=>{r=!0,p()}}}const u=(e,t)=>{let n=document.createElement(e);return t&&(n.className=t),n},d=(e,t={},...n)=>{let r=document.createElement(e);if(t.className&&(r.className=t.className),t.text!==void 0&&(r.textContent=t.text),t.attrs)for(let[e,n]of Object.entries(t.attrs))r.setAttribute(e,n);if(t.style){let e=r.style,n=t.style;for(let t of Object.keys(n)){let r=n[t];r!=null&&(e[t]=r)}}let i=n.filter(e=>e!=null);return i.length>0&&r.append(...i),r},f=(...e)=>e.filter(Boolean).join(` `);function p(e){return typeof e==`string`?e:e.filter(e=>e.type===`text`).map(e=>e.text).join(``)}function m(e){return typeof e!=`string`&&e.some(e=>e.type===`image`)}function h(e){return{type:`text`,text:e}}function g(e,t){return{type:`image`,image:e,...t?.mimeType&&{mimeType:t.mimeType},...t?.alt&&{alt:t.alt}}}const _=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`image/svg+xml`,`image/bmp`],v=[`application/pdf`,`text/plain`,`text/markdown`,`text/csv`,`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/json`];[..._,...v];function y(e,t,n){return{type:`file`,data:e,mimeType:t,filename:n}}const b=[`user`,`assistant`,`system`];function x(e){if(typeof e!=`string`||e===``)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function S(e){return typeof e==`string`?e:void 0}function C(e){if(typeof e!=`object`||!e)return null;let t=e;switch(t.type){case`text`:return typeof t.text==`string`?h(t.text):null;case`image`:return typeof t.image==`string`?g(t.image,{mimeType:S(t.mimeType),alt:S(t.alt)}):null;case`file`:return typeof t.data==`string`&&typeof t.mimeType==`string`&&typeof t.filename==`string`?y(t.data,t.mimeType,t.filename):null;case`audio`:return typeof t.audio==`string`?{type:`audio`,audio:t.audio,...S(t.mimeType)!==void 0&&{mimeType:t.mimeType}}:null;case`video`:return typeof t.video==`string`?{type:`video`,video:t.video,...S(t.mimeType)!==void 0&&{mimeType:t.mimeType}}:null;default:return null}}function ee(e,t){let n=x(t),r=e.map(e=>x(e.timestamp)),i=Array(e.length),a=0;for(;a<r.length;){let e=r[a];if(e!==null){i[a]=e,a+=1;continue}let t=a;for(;t+1<r.length&&r[t+1]===null;)t+=1;let o=t-a+1,s=a>0?i[a-1]:null,c=t+1<r.length?r[t+1]:null,l=c!==null&&n!==null?Math.min(c,n):c??n;for(let e=0;e<o;e+=1)i[a+e]=l===null?s===null?0+e:s+e+1:l-(o-e);a=t+1}return i.map(e=>new Date(e).toISOString())}function w(e,t){let n=ee(e,t?.beforeCreatedAt),r=[];return e.forEach((e,t)=>{if(typeof e?.id!=`string`||e.id===``||!b.includes(e.role))return;let i=e.role,a=n[t];if(e.displayAvailable===!1)r.push({id:e.id,role:i,content:``,createdAt:a,agentMetadata:{historyDisplayUnavailable:!0}});else if(typeof e.displayContent==`string`)r.push({id:e.id,role:i,content:e.displayContent,createdAt:a});else if(typeof e.content==`string`)r.push({id:e.id,role:i,content:e.content,createdAt:a});else if(Array.isArray(e.content)){let t=e.content.map(C).filter(e=>e!==null),n=p(t);r.push({id:e.id,role:i,content:n||(m(t)?`[Image]`:``),createdAt:a,...t.length>0&&{contentParts:t}})}else r.push({id:e.id,role:i,content:``,createdAt:a})}),r}function te(e,t){let n=/* @__PURE__ */ new Map;for(let t of e)n.set(t.id,t);for(let e of t)n.set(e.id,e);return[...n.values()].sort((e,t)=>{let n=new Date(e.createdAt).getTime(),r=new Date(t.createdAt).getTime();if(!Number.isNaN(n)&&!Number.isNaN(r)&&n!==r)return n-r;let i=e.sequence??0,a=t.sequence??0;return i===a?e.id.localeCompare(t.id):i-a})}const ne=/* @__PURE__ */ new Map([[`not_found`,`not_found`],[`conversation_deleted`,`not_found`],[`rate_limited`,`rate_limited`],[`authentication_required`,`authentication_required`],[`invalid_identity_proof`,`authentication_required`],[`visitor_identity_mismatch`,`authentication_required`],[`visitor_required`,`authentication_required`],[`identity_provider_failed`,`identity_provider_failed`],[`proof_not_admitted`,`proof_not_admitted`],[`identity_contract_violation`,`proof_not_admitted`],[`unauthorized`,`authentication_failed`],[`visitor_token_missing`,`authentication_failed`],[`conversation_credential_missing`,`authentication_failed`]]),re=/* @__PURE__ */ new Map([[`not_found`,`That conversation is no longer available.`],[`rate_limited`,`Too many history requests.`],[`authentication_failed`,`History access was not authorized.`],[`authentication_required`,`Sign in again to view account history.`],[`identity_provider_failed`,`The identity provider did not respond.`],[`proof_not_admitted`,`Account history is not available for this configuration.`],[`unsupported_scope`,`This history scope is not supported.`],[`unavailable`,`Conversation history is unavailable right now.`]]),T=e=>re.get(e)??`Conversation history is unavailable right now.`;function ie(e,{HistoryClientError:t,HistoryProviderError:n}){if(e instanceof n)return e;if(e instanceof t){let t=ne.get(e.code)??`unavailable`;return new n(t,T(t),{...e.retryAfterSeconds===void 0?{}:{retryAfterSeconds:e.retryAfterSeconds}})}return new n(`unavailable`,T(`unavailable`))}function ae(e){let{HistoryProviderError:t}=e.errors,n=()=>e.getClient?.()??e.client,r=e.getIdentityProofConfigured()?[`browser`,`verified-user`]:[`browser`],i={scopes:r},a=e=>{if(!r.includes(e))throw new t(`unsupported_scope`,T(`unsupported_scope`))},o=async(t,n)=>{a(t);try{return await n()}catch(t){throw ie(t,e.errors)}},s=t=>{let n=!1;return{conversationId:t.session.conversationId??``,conversationRevision:t.session.conversationRevision??``,async commit(){n||(n=!0,t.commit(),await e.onActivationCommitted(t.session))},discard(){n||(n=!0,t.discard())}}};return{capabilities:i,getIdentityStatus(){return n().getHistoryIdentityStatus()},subscribeIdentityStatus(e){return n().subscribeHistoryIdentityStatus(e)},subscribeAvailability(e){return n().subscribeHistoryAvailability(e)},async list(e){return o(e.context.scope,async()=>{let t=await n().listConversations({...e.cursor?{cursor:e.cursor}:{},...e.limit===void 0?{}:{limit:e.limit},...e.targetId?{targetId:e.targetId}:{},scope:e.context.scope});return{items:t.data,nextCursor:t.nextCursor}})},async getPage(e,t){return o(t.context.scope,async()=>{let r=await n().getConversation(e,{...t.cursor?{messageCursor:t.cursor}:{},scope:t.context.scope}),i=w(r.messages,{...t.beforeCreatedAt?{beforeCreatedAt:t.beforeCreatedAt}:{}});return{summary:r.summary,messages:te([],i),conversationRevision:r.conversationRevision??``,nextCursor:r.nextMessageCursor}})},async prepareOpen(e,t){return o(t.context.scope,async()=>s(await n().prepareConversationSession(e)))},async prepareStartNew(e){return o(e.context.scope,async()=>s(await n().prepareNewConversationSession()))},async delete(e,t){await o(t.context.scope,()=>n().deleteConversation(e,{scope:t.context.scope}))},async deleteAll(e){return o(e.context.scope,()=>n().deleteAllConversations({...e.targetId===void 0?{}:{targetId:e.targetId},scope:e.context.scope}))},async resetDevice(){try{return await n().resetVisitor(),{remoteRevocationConfirmed:!0}}catch{return{remoteRevocationConfirmed:!1}}}}}const oe=e=>{let n=i(e.config.features?.history?.copy),r=null,a=!1,o=null,s=null,c=`conversation`,p=null,m=null,h=null,g=null,_=0,v=null,y=null,b=null,x=`persona-history-${Math.random().toString(36).slice(2,8)}`,S=()=>e.historyFeatureEnabled()&&!!r&&!a,C=()=>{let t=e.session.getStatus();return e.isStreaming||t===`paused`||t===`resuming`},ee=()=>{let t=e.config.features?.history?.scope;if(t)return t;let n=e.config.getIdentityProof?`verified-user`:`browser`,i=r?.capabilities.scopes;return!i||i.includes(n)?n:i[0]??n},w=()=>s?.scope??ee(),te=()=>e.session.getClientSession()?.targetId??null,ne=e=>`${e.state}:${`reason`in e?e.reason:``}`,re=t=>{let n=ne(t);n!==g&&(g=n,e.eventBus.emit(`history:identityStatusChanged`,{status:t,timestamp:Date.now()}))},T=null,ie=null,oe=()=>{if(!e.historyFeatureEnabled())return null;let t=e.getHistoryProviderFactory();if(t)return t();let n=e.config.features?.history?.provider;return n?typeof n==`function`?(T!==n&&(T=n,ie=n()),ie):n:e.session.isClientTokenMode()?ae({errors:e.historyErrors,client:e.session.getClient(),getIdentityProofConfigured:()=>typeof e.config.getIdentityProof==`function`,onActivationCommitted:t=>e.session.bindActivatedSession(t),getClient:()=>e.session.getClient()}):null},se=()=>{y?.(),y=null,b?.(),b=null,a=!1;let t=r;r=oe(),t&&t!==r&&e.discardConversationContinuity();let n={...e.historyInternals};r?n.historyProvider=r:delete n.historyProvider,e.historyInternals=n,e.session.setHistoryInternals(e.historyInternals),r&&(y=r.subscribeAvailability?.(e=>{a=!e,e||q({restoreFocus:!1}),$()})??null,b=r.subscribeIdentityStatus(e=>re(e)),g=ne(r.getIdentityStatus()))},ce=()=>{let t=e.config.features?.history?.presentation??`panel`;if(t===`panel`||t===`auto`&&e.launcherEnabled&&!e.isDockedMountMode(e.config))return`panel`;let n=e.artifactSplitRoot??e.container;return(n.getBoundingClientRect().width||n.clientWidth)>=720?`rail`:`panel`},E=(e,t)=>{t?(e.setAttribute(`aria-hidden`,`true`),e.setAttribute(`inert`,``)):(e.removeAttribute(`aria-hidden`),e.removeAttribute(`inert`))},le=`data-persona-history-suppressed`,D=null,O=null,k=null,ue=null,de=null,fe=``,pe=()=>e.header===de?fe:t(e.config)?``:`none`,me=()=>e.historyPresentation===`panel`&&!!k&&ue===k.element&&t(e.config)&&pe()!==`none`,he=()=>{for(let t of Array.from(e.header.children))t!==D&&t.setAttribute(le,``)},ge=()=>{for(let t of Array.from(e.container.querySelectorAll(`[${le}]`)))t.removeAttribute(le)},_e=()=>{let t=k;if(!t)return;if(Array.from(e.header.children).some(e=>e!==D&&!e.hasAttribute(le))){O&&O!==e.header&&(O.style.removeProperty(`min-height`),O=null);let t=e.header.offsetHeight;t>0&&(e.header.style.minHeight=`${t}px`,O=e.header)}D||=u(`div`,`persona-history-header-host`),t.setHeaderPlacement(`external`);let n=t.getHeaderElement();n.parentNode!==D&&D.replaceChildren(n),D.parentNode!==e.header&&e.header.appendChild(D),he()},ve=()=>{O&&=(O.style.removeProperty(`min-height`),null),D&&(k?.setHeaderPlacement(`inline`),D.remove(),D=null,ge())},ye=null,be=()=>{ye&&(e.body.style.display=`none`,E(e.body,!0),e.footer.hidden=!0,E(e.footer,!0),e.panelSuggestions.style.display=`none`,E(e.panelSuggestions,!0),e.panelSuggestionsFade.style.display=`none`,me()?(_e(),e.header.style.display=pe(),E(e.header,!1)):(ve(),e.header.style.display=`none`,E(e.header,!0)))};e.reapplyHistoryHostChrome=be;let xe=n=>{let r=e.body.style.display,i=e.footer.hidden,a=e.panelSuggestions.style.display,o=e.panelSuggestionsFade.style.display,s=e.footer,c=e.header,l=e.header.style.display;de=c,fe=l,ye=()=>{ye=null,ve(),de=null,e.body.style.display=r,E(e.body,!1),e.panelSuggestions.style.display=a,E(e.panelSuggestions,!1),e.panelSuggestionsFade.style.display=o,s.hidden=i,E(s,!1),e.footer!==s&&(e.footer.hidden=!1,E(e.footer,!1)),c.style.display=l,E(c,!1),e.header!==c&&(e.header.style.display=t(e.config)?``:`none`,E(e.header,!1))},e.container.insertBefore(n,e.footer.parentNode===e.container?e.footer:e.panelSuggestions),be()},A=null,j=null,Se=null,M=null,Ce=()=>[e.header,e.panelElements.closeButtonWrapper,e.panelElements.clearChatButtonWrapper,e.body,e.footer,e.scrollToBottomButton],we=()=>e.config.features?.history?.rail?.collapsible!==!1,N=()=>e.config.features?.history?.rail?.side===`right`?`right`:`left`,Te=e=>Math.min(400,Math.max(200,Math.round(e))),Ee=()=>e.config.features?.history?.rail?.resizable===!0,P,De=()=>{if(P===void 0&&(P=null,e.config.persistState!==!1))try{let t=Number(window.localStorage.getItem(`${e.currentKeyPrefix()}rail-width`));t&&(P=t)}catch{}return P},F=()=>Te(De()??e.config.features?.history?.rail?.width??260),Oe=t=>{if(P=t,e.config.persistState!==!1)try{window.localStorage.setItem(`${e.currentKeyPrefix()}rail-width`,String(t))}catch{}},ke=()=>we()&&e.config.features?.history?.rail?.collapsedBehavior===`overlay`,I=!1,Ae=e=>{let t=u(`img`);return t.src=e,t.alt=``,t.setAttribute(`aria-hidden`,`true`),t},je=()=>{let t=e.config.features?.history?.rail?.brand;if(!t)return;let n=!1,r;return i=>{if(t.render)try{return t.render({collapsed:i})??null}catch(e){return n||(n=!0,console.warn(`[persona] history rail brand threw`,e)),null}return r===void 0&&(r=t.iconUrl?Ae(t.iconUrl):t.icon?e.renderLucideIcon(t.icon,20):null),r?r.cloneNode(!0):null}},Me=()=>e.config.features?.history?.rail?.sections?.map(t=>{let n=!1,r=e=>{n||(n=!0,console.warn(`[persona] history rail section threw`,t.id,e))};return{id:t.id,title:t.title,placement:t.placement??`above-conversations`,items:t.items.map(t=>{let n;return{id:t.id,label:t.label,badge:t.badge,iconNode:()=>{if(n!==void 0)return n;try{n=t.renderIcon?t.renderIcon()??null:t.iconUrl?Ae(t.iconUrl):t.icon?e.renderLucideIcon(t.icon,20):null}catch(e){r(e),n=null}return n},onSelect:()=>{try{t.onSelect()}catch(e){r(e)}}}})}})??[],Ne=e=>{let t=Me();for(let n of e)t.some(e=>e.id===n.id)?console.warn(`[persona] duplicate history rail section id`,n.id):t.push(n);return t.length?t:void 0},L=null,Pe=()=>`${e.currentKeyPrefix()}rail-collapsed`,Fe=()=>{if(L===null&&(L=e.config.features?.history?.rail?.defaultCollapsed===!0,e.config.persistState!==!1))try{let e=window.localStorage.getItem(Pe());e&&(L=e===`1`)}catch{}return L},Ie=t=>{if(L=t,e.config.persistState!==!1)try{window.localStorage.setItem(Pe(),t?`1`:`0`)}catch{}},R=()=>e.historyPresentation===`rail`&&we()&&!ke()&&Fe(),Le=()=>{},Re=()=>{ke()?Le():(Ie(!Fe()),o?.view.setCollapsed(R()),e.applyRailChrome(),e.repinAnchoredMessage())},ze=()=>{let t=e.config.features?.history?.rail?.collapseShortcut;return!t||!e.parseCombo(t)?null:{combo:t,hint:e.formatCombo(t),aria:e.ariaCombo(t)}},Be=`var(--persona-history-overlay-margin,8px)`,z=null,B=null,Ve=0,V=null,H=null,U=!1,He=0,Ue=()=>window.matchMedia?.(`(pointer: coarse)`).matches===!0,W=()=>S()&&ke()&&(e.historyPresentation??ce())===`rail`,We=()=>e.historyVisible&&!I,G=()=>{H!==null&&clearTimeout(H),H=null},Ge=()=>{e.loadHistoryView().catch(()=>{})},Ke=()=>{G(),I&&(H=setTimeout(()=>{H=null,!U&&I&&(V?.contains(document.activeElement)||q({restoreFocus:!1}))},300))},qe=(e,t)=>{let n=V?.getBoundingClientRect();if(!n)return!1;let r=z?.getBoundingClientRect(),i=r?Math.min(r.top,n.top):n.top;return e>=n.left&&e<=n.right&&t>=i&&t<=n.bottom||!!r&&e>=r.left&&e<=r.right&&t>=r.top&&t<=r.bottom},Je=e=>{I&&(U=qe(e.clientX,e.clientY),U?G():H===null&&Ke())},Ye=t=>{!e.historyVisible&&W()&&(I=!0,gt({invoker:z,keyboard:t?.keyboard===!0}).then(()=>{e.historyVisible?!U&&document.activeElement!==z&&q():I=!1}))},Xe=()=>{let e=ue?.querySelector(`[data-persona-history-focus="collapse"]`);e&&(e.setAttribute(`aria-label`,I?n.expandLabel:n.collapseLabel),e.setAttribute(`aria-expanded`,I?`false`:`true`))},Ze=()=>{Ie(!1);let t=o;if(!I||!t){gt({invoker:z});return}let n=document.activeElement===z;I=!1,ut(),t.element.remove(),ft(t.element),Xe(),n&&ht(),e.repinAnchoredMessage(),$()},Qe=()=>{Ie(!0),q()};Le=()=>{!e.historyVisible||I?Ze():Qe()};let $e=()=>{let t=ze(),r=e.createHeaderIconButton({ariaLabel:n.expandLabel,iconName:`panel-left`,wrapperClassName:`persona-relative persona-inline-flex persona-items-center persona-justify-center`,extraClassName:`persona-rail-trigger`,tooltip:!1,attrs:{"data-persona-rail-trigger":``,"aria-controls":x,...t?{"aria-keyshortcuts":t.aria}:{}}}),i=r.button;i.addEventListener(`mouseenter`,()=>{U=!0,G(),!(Ue()||Date.now()<He)&&Ye()}),i.addEventListener(`mouseleave`,()=>{U=!1,He=0,Ke()}),i.addEventListener(`focus`,()=>{e.historyVisible||Ge()}),i.addEventListener(`click`,t=>{S()&&(t.detail!==0&&Ue()&&!e.historyVisible?Ye():Ze())}),z=i,B=r.wrapper},et=()=>{if(B&&!B.isConnected&&(B=null,z=null),!W()){B?.remove(),B=null,z=null;return}z||$e();let t=B,r=z;if(!t||!r)return;let i=N()===`right`?null:e.header.firstChild;(i??e.header.lastChild)!==t&&e.header.insertBefore(t,i),t.style.display=We()||Ve>0?`none`:``,r.setAttribute(`aria-label`,n.expandLabel),r.setAttribute(`aria-expanded`,e.historyVisible?`true`:`false`),V&&e.applyRailChrome()},tt=e=>{if(!I)return;let t=e.target;t instanceof Node&&(V?.contains(t)||B?.contains(t)||t instanceof Element&&t.closest(`.persona-dropdown-menu,[role="alertdialog"]`)||q({restoreFocus:!1}))};document.addEventListener(`pointerdown`,tt,!0),e.destroyCallbacks.push(()=>{document.removeEventListener(`pointerdown`,tt,!0),document.removeEventListener(`pointermove`,Je),K?.(),G()});let nt=null,K=null,rt=t=>{Oe(Te(t)),e.applyRailChrome(),e.repinAnchoredMessage()},it=()=>{let t=u(`div`,`persona-rail-resizer`);return t.tabIndex=0,t.setAttribute(`role`,`separator`),t.setAttribute(`aria-orientation`,`vertical`),t.setAttribute(`aria-valuemin`,`200`),t.setAttribute(`aria-valuemax`,`400`),t.addEventListener(`pointerdown`,n=>{let r=j;if(!r||n.button!==0)return;n.preventDefault(),K?.();let i=n.clientX,a=r.getBoundingClientRect().width||F(),o=N()===`right`?-1:1,s=a,c=e.mount.ownerDocument;r.style.transition=`none`;let l=e=>{s=Te(a+o*(e.clientX-i)),r.style.flex=`0 0 ${s}px`,t.setAttribute(`aria-valuenow`,String(s))},u=()=>{K=null,c.removeEventListener(`pointermove`,l),c.removeEventListener(`pointerup`,u),c.removeEventListener(`pointercancel`,u),r.style.removeProperty(`transition`);try{t.releasePointerCapture(n.pointerId)}catch{}rt(s)};K=u,c.addEventListener(`pointermove`,l),c.addEventListener(`pointerup`,u),c.addEventListener(`pointercancel`,u);try{t.setPointerCapture(n.pointerId)}catch{}}),t.addEventListener(`keydown`,e=>{let t=N()===`right`?-16:16,n=F(),r=e.key===`ArrowRight`?n+t:e.key===`ArrowLeft`?n-t:e.key===`Home`?200:e.key===`End`?400:null;r!==null&&(e.preventDefault(),rt(r))}),t},at=(e,t)=>{if(!Ee()||R()){K?.(),nt?.remove();return}let r=nt??it();nt=r,r.setAttribute(`aria-label`,n.resizeLabel),r.setAttribute(`aria-valuenow`,String(F())),r.nextElementSibling!==t&&e.insertBefore(r,t)};e.applyRailChrome=()=>{o?.view.setRailSide(N());let t=N()===`right`,n=V;if(n){let r=z?z.getBoundingClientRect().bottom-e.container.getBoundingClientRect().top:0;n.style.top=`calc(${Math.max(0,Math.round(r))}px + ${Be})`,n.style.width=`${F()}px`,n.style.left=t?``:Be,n.style.right=t?Be:``}let r=j,i=A,a=Se;if(!r||!i||!a)return;r.style.flex=`0 0 ${R()?52:F()}px`;let s=`1px solid var(--persona-divider,#e5e7eb)`;r.style.borderRight=t?``:s,r.style.borderLeft=t?s:``;let c=t?a:r;i.firstElementChild!==c&&i.append(c,t?r:a),at(i,t?r:a)};let ot=t=>{if(M&&j){M.replaceWith(t),M=null,e.applyRailChrome();return}let n=u(`div`,`persona-history-rail-shell`);n.style.cssText=`display:flex;flex-direction:row;flex:1 1 auto;min-height:0`;let r=u(`div`,`persona-history-rail-conversation`);r.style.cssText=`display:flex;flex-direction:column;flex:1 1 auto;min-width:0;min-height:0;position:relative`;let i=u(`div`,`persona-history-rail-host`);i.style.cssText=`display:flex;min-height:0;overflow:hidden`,e.container.insertBefore(n,e.header.parentNode===e.container?e.header:e.body);for(let t of Ce())t?.parentNode===e.container&&r.appendChild(t);n.append(i,r),i.appendChild(t),A=n,j=i,Se=r,e.applyRailChrome()},st=()=>{if(A)return;let t=u(`div`,`persona-history-rail-placeholder`);t.style.cssText=`flex:1 1 auto;min-height:0`,M=t,ot(t),e.repinAnchoredMessage()},ct=()=>{M&&(ut(),e.repinAnchoredMessage())},lt=t=>{let n=u(`div`,`persona-history-rail-overlay`);n.style.cssText=`position:absolute;bottom:${Be};display:flex;overflow:hidden;z-index:100000;border-radius:var(--persona-history-overlay-radius,16px);background:var(--persona-history-overlay-bg,var(--persona-container,#f7f7f8));box-shadow:var(--persona-history-overlay-shadow,0 12px 40px rgba(0,0,0,0.25))`,e.container.style.position=`relative`,e.container.appendChild(n),n.appendChild(t),document.addEventListener(`pointermove`,Je),V=n,e.applyRailChrome(),Xe()},ut=()=>{ye?.(),V&&=(U&&(He=Date.now()+150),document.removeEventListener(`pointermove`,Je),V.remove(),null);let t=A;if(t){K?.();for(let n of Ce())if(n&&t.contains(n)){let r=n===e.scrollToBottomButton?e.panelSuggestions:t;e.container.insertBefore(n,r)}t.remove(),A=null,j=null,Se=null,M=null}},dt=e=>{ue=e,e.id=x,e.style.flex=`1 1 auto`,e.style.minHeight=`0`},ft=t=>{dt(t),(e.historyPresentation!==`rail`||I)&&ct(),e.historyPresentation===`rail`?I?lt(t):ot(t):xe(t)},pt=()=>{if(et(),Vt(),!e.historyVisible||!o)return;let t=ce();if(t===e.historyPresentation)return;let n=document.activeElement,r=n instanceof HTMLElement&&(o.element.contains(n)||D?.contains(n)===!0)?n:null;ut(),o.element.remove(),o.view.setHeaderPlacement(`inline`),e.historyPresentation=t,o.view.setPresentation(t),o.view.setCollapsed(R()),o.requestRender(),o.element.isConnected||ft(o.element),r?.isConnected?r.focus():ht(),e.syncScrollToBottomButton(),e.repinAnchoredMessage(),$()},mt=(e,t)=>D?.querySelector(t)??e.querySelector(t),ht=()=>{let e=o?.element??ue;if(!e)return;let t=mt(e,`[data-persona-history-focus="close"],[data-persona-history-focus="collapse"]`);if(t){t.focus();return}let n=mt(e,`.persona-history-title`)??e;n.tabIndex=-1,n.focus()},gt=async i=>{if(!S()||e.historyVisible)return;let a=r;if(!a)return;if(!I&&W()&&Fe()){et();return}_t();let u=++_;c=i?.returnSurface??`conversation`,p=i?.invoker??m;let d=W()&&!I;d&&(Ve+=1,et(),st());let f;try{f=await e.loadHistoryView()}catch{e.announceHistory(n.openHistoryLabel),d&&(--Ve,u===_&&(ct(),et()));return}if(d&&--Ve,u!==_||e.historyVisible)return;s={scope:ee()},e.historyPresentation=ce(),e.historyVisible=!0;let h=e.historyPresentation===`panel`&&t(e.config)&&e.header.style.display!==`none`?`external`:`inline`,g=e.config.features?.history?.rowAvatar,v=ze(),y=v?{hint:v.hint,aria:v.aria}:null,b={provider:a,context:s,targetId:te(),presentation:e.historyPresentation,collapsible:we(),collapsed:R(),railSide:N(),renderRailHeader:e.config.features?.history?.rail?.renderHeader,railBrand:je(),onToggleCollapse:Re,...y?{collapseShortcut:y}:{},headerPlacement:h,showScopeStatus:e.config.features?.history?.showScopeStatus!==!1,showDelete:e.config.features?.history?.showDelete!==!1,showDeleteAll:e.config.features?.history?.showDeleteAll!==!1,...e.config.features?.history?.listActions?.length?{listActions:e.config.features.history.listActions}:{},rowAvatar:g===!1?!1:typeof g==`string`?g:e.config.launcher?.iconUrl,activeConversationId:e.session.getActiveConversationId(),...e.config.features?.history?.grouping?{grouping:e.config.features.history.grouping}:{},...e.config.features?.history?.copy?{copy:e.config.features.history.copy}:{},...e.config.features?.history?.pageSize===void 0?{}:{pageSize:e.config.features.history.pageSize},onSelect:e=>kt(e,{focusComposer:!0}).catch(()=>{}),onActiveConversationChange:t=>e.setActiveConversationSummary(t),attachTooltip:e.attachTooltip,onStartNew:()=>At({focusComposer:!0}),onClose:()=>q(),onRequestDeleteConversation:e=>Lt(e),onRequestClearHistory:()=>Rt(),...a.resetDevice?{onRequestResetIdentity:()=>zt()}:{}};o=l({plugins:e.plugins,config:e.config,getPresentation:()=>e.historyPresentation??`panel`,getReturnSurface:()=>c,close:()=>q(),createView:({slots:t,renderDom:n,onModelChange:r,railSections:i})=>(k=f.createHistoryView({...b,railSections:Ne(i),slots:t,renderDom:n,onModelChange:r,onAnnounce:e.announceHistory}),k),onElementChanged:(e,t)=>{if(!t?.isConnected)return ft(e);dt(e),t.replaceWith(e),be()}}),o.view.setNewConversationRequired(e.historySessionState.recovery===`new_conversation_required`),i?.focus!==!1&&(e.historyPresentation!==`rail`||i?.keyboard===!0)&&ht(),e.syncScrollToBottomButton(),e.repinAnchoredMessage(),$(),e.eventBus.emit(`history:opened`,{presentation:e.historyPresentation,returnSurface:c,timestamp:Date.now()})},_t=()=>{},q=t=>{if(!e.historyVisible)return;_+=1;let n=c,r=p,i=o,a=t?.restoreFocus!==!1;e.historyVisible=!1;let l=!1,u=null,d=()=>{if(!l){if(l=!0,_t=()=>{},u!==null&&clearTimeout(u),I=!1,G(),ut(),i?.dispose(),i?.view.destroy(),i?.element.remove(),o===i&&(o=null,k=null,ue=null,e.historyPresentation=null,s=null,p=null),e.syncScrollToBottomButton(),e.repinAnchoredMessage(),$(),a){let t=r??m;t?.isConnected?t.focus():e.maybeFocusInput()}e.eventBus.emit(`history:closed`,{returnSurface:n,timestamp:Date.now()})}},f=i&&i.element===i.view.element?i.view.playExit():null;f?(_t=d,u=setTimeout(d,250),f.then(d)):d()},vt=t=>{if(t.key===`Escape`&&e.historyVisible&&o){if(e.historyPresentation===`rail`){let e=t.target;if(!(e instanceof Node)||!(o.element.contains(e)||I&&B?.contains(e)===!0))return}t.preventDefault(),t.stopPropagation(),q()}};e.container.addEventListener(`keydown`,vt),e.destroyCallbacks.push(()=>e.container.removeEventListener(`keydown`,vt));let yt=0,J=null,bt=null,Y=()=>{bt&&clearTimeout(bt),bt=null};e.destroyCallbacks.push(Y);let xt=()=>{Y();let t=e.conversationOpenPendingEl;t&&(e.conversationOpenTakeover=!0,t.hidden=!1,e.messagesWrapper.style.display=`none`,e.updateWelcome())},X=()=>{yt+=1,Y(),J?.remove(),J=null,e.conversationOpenPendingEl&&(e.conversationOpenPendingEl.remove(),e.conversationOpenPendingEl=null,e.conversationOpenTakeover=!1,e.messagesWrapper.style.removeProperty(`display`),E(e.footer,!1),e.updateWelcome())},St=()=>{try{if(window.matchMedia?.(`(prefers-reduced-motion: reduce)`)?.matches)return;e.messagesWrapper.animate([{opacity:0},{opacity:1}],{duration:150,easing:`ease-out`})}catch{}},Ct=t=>{let n=e.config.layout?.messages?.layout??`bubble`,r=d(`div`,{className:`persona-flex`,attrs:{"aria-hidden":`true`}});e.applyMessageRowLayout(r,t);let i=d(`div`,{className:f(e.getBubbleClasses(t,n).join(` `),`persona-conversation-loading-bubble`),attrs:{"data-persona-theme-zone":`${t}-message`},style:{width:t===`user`?`64%`:`100%`,backgroundColor:n===`flat`?`transparent`:`var(--persona-message-${t}-bg, var(--persona-${t===`user`?`accent`:`container`}))`,color:`var(--persona-message-${t}-text, ${t===`user`&&n!==`flat`?`white`:`var(--persona-text)`})`}},...[`94%`,...t===`assistant`?[`86%`]:[],`62%`].map(e=>d(`div`,{className:`persona-conversation-loading-line`,style:{width:e}})));return e.applyBubbleGeometry(i,t,n,{...e.resolveThemeDefaults(e.config.future).components.message[t],...e.config.theme?.components?.message?.[t],...e.config.darkTheme?.components?.message?.[t]}),r.appendChild(i),r},wt=()=>d(`div`,{className:`persona-conversation-loading-body`,style:{gap:e.messagesWrapper.style.gap}},Ct(`user`),Ct(`assistant`),Ct(`user`),Ct(`assistant`)),Tt=()=>e.config.loadingIndicator?.conversationOpenVariant===`skeleton`?wt():d(`div`,{className:`persona-conversation-loading-spinner`,attrs:{"aria-hidden":`true`}},d(`span`,{className:`persona-conversation-loading-ring`})),Et=t=>{e.conversationOpenPendingEl?.remove(),e.conversationOpenPendingEl=t,t.hidden=!e.conversationOpenTakeover,e.body.insertBefore(t,e.messagesWrapper),Y(),e.conversationOpenTakeover||(bt=setTimeout(xt,250)),E(e.footer,!0)},Dt=()=>{let t={config:e.config,streaming:!1,location:`conversation-open`,defaultRenderer:Tt},r=null,i=e.plugins.find(e=>e.renderLoadingIndicator);i?.renderLoadingIndicator&&(r=i.renderLoadingIndicator(t)),r===null&&e.config.loadingIndicator?.render&&(r=e.config.loadingIndicator.render(t));let a=r??Tt();Et(d(`div`,{className:f(`persona-conversation-loading`,a.classList.contains(`persona-conversation-loading-spinner`)&&`persona-conversation-loading--centered`),attrs:{role:`status`,"aria-label":n.openConversationLoadingLabel},style:{maxWidth:e.messagesWrapper.style.maxWidth||`none`}},a))},Ot=t=>{let r=()=>{kt(t,{focusComposer:!0}).catch(()=>{})},i=S()?()=>{X(),gt()}:void 0,a=(e,t)=>{let n=d(`button`,{className:`persona-conversation-loading-error-action`,attrs:{type:`button`},text:e});return n.addEventListener(`click`,t),n},o=()=>d(`div`,{className:`persona-conversation-loading-error-body`},d(`p`,{className:`persona-conversation-loading-error-title`,text:n.openConversationErrorTitle}),d(`div`,{className:`persona-conversation-loading-error-actions`},a(n.openConversationRetryLabel,r),i?a(n.openConversationBackLabel,i):null)),s=Object.freeze({conversationId:t,config:e.config,copy:Object.freeze({title:n.openConversationErrorTitle,retryLabel:n.openConversationRetryLabel,backLabel:n.openConversationBackLabel}),retry:r,...i?{back:i}:{},defaultRenderer:o}),c=null;for(let t of e.plugins)if(t.renderHistoryOpenError){try{c=t.renderHistoryOpenError(s)}catch(e){console.warn(`[persona] renderHistoryOpenError threw`,e),c=null}if(c)break}if(J?.remove(),J=d(`div`,{className:`persona-conversation-loading-error`,attrs:{role:`alert`}},c??o()),!e.session.getActiveConversationId()&&e.session.getMessages().length===0&&!e.composerStore.getState().text&&!e.attachmentManager?.hasAttachments()){let e=J;J=null,Et(e),xt()}else e.body.insertBefore(J,e.messagesWrapper);e.announceHistory(n.openConversationErrorTitle)};e.eventBus.on(`history:closed`,()=>{e.conversationOpenPendingEl&&E(e.footer,!0)});let kt=async(t,{focusComposer:n=!1,busy:r=`reject`}={})=>{let i=w();if(r===`background`&&(e.session.assertBackgroundSwitchable(),e.composerStore.getState().phase===`preparing`))throw new e.SessionHistoryError(`conversation_busy`,`Finish preparing this turn before switching conversations`);if(r===`reject`&&(e.session.isStreaming()||[`paused`,`resuming`].includes(e.session.getStatus())||e.composerStore.getState().phase===`preparing`))throw new e.SessionHistoryError(`conversation_busy`,`Finish or stop the current turn before switching conversations`);r===`stop`&&(++e.composerConversationGeneration,e.submissionAbort?.abort(),e.submissionAbort=null,e.composerStore.setPreparing(!1),e.session.cancel());let a=e.conversationStateKey();(!e.conversationOpenPendingEl||e.pendingConversationReading?.key!==a)&&(e.pendingConversationReading={key:a,reading:e.captureConversationReading()});let s=null,c=!!o;o?.view.setActiveConversationId(t),X();let l=yt;Dt(),e.historyVisible&&(e.historyPresentation===`panel`||I)&&q({restoreFocus:!1}),e.suppressScrollSend=!0;try{await e.session.openConversation(t,{scope:i,busy:r,onBeforeCommit:()=>{e.saveConversationContinuity(),s=e.composerConversationGeneration,e.conversationPersistenceOwner=s},onCommitted:()=>{e.restoreConversationContinuity(),e.conversationPersistenceOwner===s&&(e.conversationPersistenceOwner=null),e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),e.persistState()}})}catch(n){if(e.conversationPersistenceOwner===s&&(e.conversationPersistenceOwner=null),s===e.composerConversationGeneration&&e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),l===yt){let n=e.pendingConversationReading?.reading;X(),n&&e.restoreConversationReading(n),e.pendingConversationReading=null,o?.view.setActiveConversationId(e.session.getActiveConversationId()),Ot(t),e.suppressScrollSend=!1}throw n}finally{(l===yt||!e.conversationOpenPendingEl)&&(e.suppressScrollSend=!1)}l===yt&&(X(),e.pendingConversationReading=null,e.messageCache.clear(),St(),Q(),c||e.setActiveConversationSummary(null),e.eventBus.emit(`history:conversationOpened`,{conversationId:t,title:e.activeConversationTitle,scope:i,timestamp:Date.now()}),n&&e.maybeFocusInput())},At=async({focusComposer:t=!1}={})=>{X();let n=null;try{await e.session.startNewConversation({scope:w(),onBeforeCommit:()=>{e.saveConversationContinuity(),n=e.composerConversationGeneration,e.conversationPersistenceOwner=n},onCommitted:()=>{e.restoreConversationContinuity(!0),e.conversationPersistenceOwner===n&&(e.conversationPersistenceOwner=null),e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),e.persistState(),e.pendingConversationReading=null}})}catch(t){throw e.conversationPersistenceOwner===n&&(e.conversationPersistenceOwner=null),n===e.composerConversationGeneration&&e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),t}e.setActiveConversationSummary(null),e.messageCache.clear(),e.resetAnchorState(),e.resumeAutoScroll(),e.jumpToBottomInstant(),Q();let r=e.session.getActiveConversationId();o?.view.setActiveConversationId(r),e.eventBus.emit(`history:conversationStarted`,{conversationId:r,timestamp:Date.now()}),e.historyVisible&&(e.historyPresentation===`panel`||I)&&q({restoreFocus:!1}),t&&e.maybeFocusInput()},jt=async(t,n)=>{let r=await e.session.updateConversation(t,{...n,...n.title===void 0?{}:{title:n.title.trim()}});return o?.view.applyConversationSummary(r),!o&&t===e.session.getActiveConversationId()&&e.setActiveConversationSummary(r),r},Mt=async t=>{let n=w(),r=e.session.getActiveConversationId()===t;await e.session.deleteConversation(t,{scope:n}),e.discardConversationContinuity(t),r&&(e.attachmentManager?.destroy({release:!0}),e.attachmentManager=null,e.restoreConversationContinuity(!0)),o?.view.removeConversationSummary(t),r&&(e.setActiveConversationSummary(null),e.messageCache.clear(),e.resetAnchorState(),e.resumeAutoScroll(),Q()),e.eventBus.emit(`history:conversationDeleted`,{conversationId:t,scope:n,wasActive:r,timestamp:Date.now()})},Nt=async t=>{let n=t?.scope??w(),r=t?.allTargets?null:t?.targetId??te(),i=await e.session.clearConversationHistory({...r?{targetId:r}:{},scope:n});return e.discardConversationContinuity(),e.setActiveConversationSummary(null),e.messageCache.clear(),e.resetAnchorState(),e.resumeAutoScroll(),Q(),e.eventBus.emit(`history:cleared`,{deleted:i.deleted,scope:n,targetId:r,timestamp:Date.now()}),i},Pt=async()=>{if(!r?.resetDevice)throw Error(`[Persona] resetHistoryIdentity() requires a history provider that can reset this device`);let t=!1;try{t=(await e.session.resetHistoryDevice()).remoteRevocationConfirmed}finally{e.discardConversationContinuity(),X(),e.setActiveConversationSummary(null),e.session.clearArtifacts(),e.messageCache.clear(),e.lastAppliedMessages=null,e.config.clearStoredSessionId?.(),e.config.clearStoredConversationId?.(),e.persistentMetadata={},e.actionManager.syncFromMetadata(),e.clearPersistedDraft();let t=e.storageAdapter;t?.clear&&e.runStorageMutation(()=>t.clear(),`[AgentWidget] Failed to clear storage adapter:`),e.resetAnchorState(),e.resumeAutoScroll(),Q(),q({restoreFocus:!1}),e.maybeFocusInput(),e.open||e.launcherSurfaceInstance?.launcher.element.focus()}return e.announceHistory(t?n.identityResetNotice:n.identityResetUnconfirmedNotice),e.eventBus.emit(`history:identityReset`,{remoteRevocationConfirmed:t,timestamp:Date.now()}),{remoteRevocationConfirmed:t}},Ft=()=>e.artifactSplitRoot?e.panel:e.container,It=async t=>{let n=await e.loadHistoryView().catch(()=>null);return typeof n?.showHistoryConfirm==`function`?n.showHistoryConfirm(t):window.confirm(`${t.title}\n\n${t.description}`)},Lt=async e=>await It({host:Ft(),title:n.deleteConversationConfirmTitle,description:n.deleteConversationConfirm,confirmLabel:n.deleteConversationConfirmLabel,cancelLabel:n.confirmCancelLabel})?(await Mt(e),`deleted`):`cancelled`,Rt=async()=>{let e=w()===`verified-user`;return await It({host:Ft(),title:n.clearHistoryConfirmTitle,description:e?n.clearHistoryVerifiedConfirm:n.clearHistoryConfirm,confirmLabel:n.clearHistoryConfirmLabel,cancelLabel:n.confirmCancelLabel})?(await Nt(),`cleared`):`cancelled`},zt=async()=>{if(!await It({host:Ft(),title:n.resetIdentityConfirmTitle,description:n.resetIdentityConfirm,confirmLabel:n.resetIdentityConfirmLabel,cancelLabel:n.confirmCancelLabel}))return{outcome:`cancelled`};let{remoteRevocationConfirmed:e}=await Pt();return{outcome:`reset`,remoteRevocationConfirmed:e}},Z=u(`button`,`persona-history-earlier`);Z.type=`button`,Z.textContent=n.showEarlierMessagesLabel,Z.setAttribute(`data-persona-history-earlier`,``),Object.assign(Z.style,{alignSelf:`center`,minHeight:`44px`,padding:`0 16px`,borderRadius:`999px`,border:`1px solid var(--persona-border, rgba(0,0,0,0.12))`,background:`transparent`,color:`inherit`,font:`inherit`,cursor:`pointer`,flexShrink:`0`});let Q=()=>{S()&&e.historySessionState.nextMessageCursor&&e.session.getActiveConversationId()?(Z.textContent=n.showEarlierMessagesLabel,Z.parentNode!==e.body&&e.body.insertBefore(Z,e.body.firstChild)):Z.remove()};Z.addEventListener(`click`,()=>{let t=e.session.getActiveConversationId(),n=e.historySessionState.nextMessageCursor;if(!t||!n||Z.disabled)return;Z.disabled=!0;let r=e.body.scrollHeight,i=e.body.scrollTop;e.session.loadOlderMessages(t,n,{scope:w()}).then(()=>{e.body.scrollTop=i+(e.body.scrollHeight-r),e.repinAnchoredMessage()}).catch(()=>{}).finally(()=>{Z.disabled=!1,Q()})});let Bt=()=>{let t=e.createHeaderIconButton({ariaLabel:n.openHistoryLabel,iconName:`history`,wrapperClassName:`persona-relative persona-inline-flex persona-items-center persona-justify-center`,extraClassName:`persona-history-toggle`,attrs:{"data-persona-history-toggle":``}});return t.button.addEventListener(`click`,n=>{S()&&!C()&&(e.historyVisible?q():gt({invoker:t.button,keyboard:n.detail===0}))}),t},Vt=()=>{if(!S()){h?.remove(),m=null,h=null;return}if(h&&!h.isConnected&&(m=null,h=null),!m&&e.header){let t=Bt();m=t.button,h=t.wrapper;let n=e.panelElements.clearChatButtonWrapper||e.panelElements.closeButtonWrapper;n?.parentNode&&e.header.contains(n)?n.parentNode.insertBefore(h,n):e.header.appendChild(h)}if(!m||!h)return;let t=W()||e.historyVisible&&e.historyPresentation===`rail`;if(h.style.display=t?`none`:``,t){document.activeElement===m&&ht();return}let r=C();m.disabled=r,m.setAttribute(`aria-disabled`,r?`true`:`false`);let i=r?n.openHistoryBusyLabel:n.openHistoryLabel;m.setAttribute(`aria-label`,i),(e.config.features?.history?.presentation??`panel`)===`panel`?(m.removeAttribute(`aria-expanded`),m.removeAttribute(`aria-controls`)):(m.setAttribute(`aria-expanded`,e.historyVisible?`true`:`false`),m.setAttribute(`aria-controls`,x))},Ht=!1,Ut=()=>{let t=e.panelElements.clearChatButton;t&&(S()?(Ht||=(v=t.getAttribute(`aria-label`)??``,!0),t.setAttribute(`aria-label`,n.newConversationLabel),t.removeAttribute(`title`)):Ht&&(Ht=!1,v&&t.setAttribute(`aria-label`,v)))},$=()=>{n=i(e.config.features?.history?.copy),Vt(),et(),Ut(),Q()};return e.historyChromeSync=$,se(),$(),e.destroyCallbacks.push(()=>{y?.(),b?.(),_+=1,_t(),o?.dispose(),o?.view.destroy(),o=null}),{clearConversationOpenPending:X,cancelConversationOpenTakeover:Y,historyOperationScope:w,discardConversationContinuity:e.discardConversationContinuity,historyAvailable:S,historyScope:ee,installHistoryProvider:se,syncHistoryChromeImpl:$,syncHistoryPresentation:pt,syncEarlierMessagesPill:Q,openHistory:gt,closeHistory:q,openHistoryConversation:kt,startNewConversation:At,updateHistoryConversation:jt,deleteHistoryConversation:Mt,requestDeleteConversation:Lt,clearConversationHistory:Nt,resetHistoryIdentity:Pt,railCollapseShortcut:ze,railCollapsible:we,railTriggerApplies:W,railOverlayMode:ke,toggleRailCollapsed:Re,toggleRailPinned:()=>Le(),get historyProvider(){return r},get historySurface(){return o},get railShell(){return A},get railHost(){return j},get railColumn(){return Se}}};exports.createHistoryShell=oe;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=e=>e?.layout?.embedded===!0&&e.launcher?.enabled===!1&&!e.launcher.sidebarMode&&(e.launcher.mountMode??`floating`)===`floating`,t=t=>t?.layout?.showHeader??!e(t),n=/* @__PURE__ */ `viewTitle.openHistoryLabel.openHistoryBusyLabel.newConversationLabel.expandLabel.collapseLabel.resizeLabel.showEarlierMessagesLabel.openConversationLoadingLabel.openConversationErrorTitle.openConversationRetryLabel.openConversationBackLabel.confirmCancelLabel.deleteConversationConfirmTitle.deleteConversationConfirm.deleteConversationConfirmLabel.clearHistoryConfirmTitle.clearHistoryConfirm.clearHistoryVerifiedConfirm.clearHistoryConfirmLabel.resetIdentityConfirmTitle.resetIdentityConfirm.resetIdentityConfirmLabel.conversationDeletedNotice.identityResetNotice.identityResetUnconfirmedNotice`.split(`.`),r={viewTitle:`Messages`,openHistoryLabel:`Messages`,openHistoryBusyLabel:`Messages, available once the reply finishes`,newConversationLabel:`New conversation`,expandLabel:`Expand conversation list`,collapseLabel:`Collapse conversation list`,resizeLabel:`Resize conversation list`,showEarlierMessagesLabel:`Show earlier messages`,openConversationLoadingLabel:`Loading conversation`,openConversationErrorTitle:`Could not open the conversation.`,openConversationRetryLabel:`Try again`,openConversationBackLabel:`Back to messages`,confirmCancelLabel:`Cancel`,deleteConversationConfirmTitle:`Delete conversation`,deleteConversationConfirm:`Delete this conversation? This cannot be undone.`,deleteConversationConfirmLabel:`Delete`,clearHistoryConfirmTitle:`Delete all conversations`,clearHistoryConfirm:`Delete all conversations for this assistant on this browser? This cannot be undone.`,clearHistoryVerifiedConfirm:`Delete all conversations for this assistant and signed-in user? This cannot be undone.`,clearHistoryConfirmLabel:`Delete all`,resetIdentityConfirmTitle:`Forget this device`,resetIdentityConfirm:`Forget this device? All Persona data stored in this browser is cleared. Records are not deleted elsewhere.`,resetIdentityConfirmLabel:`Forget this device`,conversationDeletedNotice:`That conversation was deleted. You are now in a new conversation.`,identityResetNotice:`This device was forgotten.`,identityResetUnconfirmedNotice:`This device was cleared here, but the server could not confirm it.`};function i(e){if(!e)return r;let t={...r};for(let r of n){let n=e[r];typeof n==`string`&&n.length>0&&(t[r]=n)}return t}const a=(e,t)=>{console.warn(`[persona] ${e} threw`,t)},o=e=>Object.freeze({...e}),s=e=>Object.freeze({id:e.id,title:e.title,targetId:e.targetId,preview:e.preview,messageCount:e.messageCount,createdAt:e.createdAt,updatedAt:e.updatedAt}),c=e=>e?o(e):null;function l(e){let{plugins:t,config:n}=e,r=!1,i=!1,l=!1,u=!1,d=null,f=[],p=()=>{for(let e of f.splice(0))try{e()}catch(e){a(`renderHistoryView cleanup`,e)}},m=(e,n)=>{for(let r of t){let t=r[e];if(t)try{let e=t(n);if(e)return e}catch(t){a(e,t)}}return null},h=()=>({presentation:e.getPresentation(),config:n}),g={header:t=>u?m(`renderHistoryHeader`,Object.freeze({...h(),returnSurface:e.getReturnSurface(),identityStatus:o(t.identityStatus),pendingAction:c(t.pendingAction),copy:o(t.copy),actions:Object.freeze({close:y.close,startNewConversation:y.startNewConversation}),defaultRenderer:t.defaultRenderer})):null,conversation:e=>u?m(`renderHistoryConversation`,Object.freeze({...h(),conversation:s(e.conversation),active:e.active,pending:e.pending,open:e.open,requestDelete:e.requestDelete,defaultRenderer:e.defaultRenderer})):null,state:e=>u?m(`renderHistoryState`,Object.freeze({...h(),state:o(e.state),identityStatus:o(e.identityStatus),copy:o(e.copy),...e.retry?{retry:e.retry}:{},...e.startNewConversation?{startNewConversation:e.startNewConversation}:{},defaultRenderer:e.defaultRenderer})):null},_=t.flatMap(t=>(t.railSections??[]).map(t=>({...t,placement:t.placement??`above-conversations`,items:[],render:n=>t.render(Object.freeze({collapsed:n,presentation:e.getPresentation(),actions:y}))}))),v=e.createView({slots:g,renderDom:!1,onModelChange:()=>C(),railSections:_}),y=Object.freeze({...v.operations,close:e.close}),b=()=>(u=!0,v.setDomRenderEnabled(!0),v.element),x=t=>Object.freeze({conversations:Object.freeze(t.conversations.map(s)),activeConversationId:t.activeConversationId,state:o(t.state),pendingAction:c(t.pendingAction),identityStatus:o(t.identityStatus),nextCursor:t.nextCursor,presentation:e.getPresentation(),returnSurface:e.getReturnSurface(),config:n,copy:o(v.copy),actions:y,defaultRenderer:b,requestRender:()=>C(),onCleanup:e=>{f.push(e)}}),S=()=>{u=!1;let e=null;for(let n of t)if(n.renderHistoryView){try{e=n.renderHistoryView(x(v.getModel()))}catch(t){a(`renderHistoryView`,t),e=null}if(e)break}let n=!e||e.contains(v.element);return u=n,v.setDomRenderEnabled(n),e??v.element};function C(){if(!(!l||r||i)){i=!0;try{p();let t=S();if(t===d)return;let n=d;d=t,e.onElementChanged(t,n)}finally{i=!1}}}return l=!0,C(),{view:v,get element(){return d??v.element},requestRender:C,dispose:()=>{r=!0,p()}}}const u=(e,t)=>{let n=document.createElement(e);return t&&(n.className=t),n},d=(e,t={},...n)=>{let r=document.createElement(e);if(t.className&&(r.className=t.className),t.text!==void 0&&(r.textContent=t.text),t.attrs)for(let[e,n]of Object.entries(t.attrs))r.setAttribute(e,n);if(t.style){let e=r.style,n=t.style;for(let t of Object.keys(n)){let r=n[t];r!=null&&(e[t]=r)}}let i=n.filter(e=>e!=null);return i.length>0&&r.append(...i),r},f=(...e)=>e.filter(Boolean).join(` `);function p(e){return typeof e==`string`?e:e.filter(e=>e.type===`text`).map(e=>e.text).join(``)}function m(e){return typeof e!=`string`&&e.some(e=>e.type===`image`)}function h(e){return{type:`text`,text:e}}function g(e,t){return{type:`image`,image:e,...t?.mimeType&&{mimeType:t.mimeType},...t?.alt&&{alt:t.alt}}}const _=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`image/svg+xml`,`image/bmp`],v=[`application/pdf`,`text/plain`,`text/markdown`,`text/csv`,`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/json`];[..._,...v];function y(e,t,n){return{type:`file`,data:e,mimeType:t,filename:n}}const b=[`user`,`assistant`,`system`,`operator`];function x(e){if(typeof e!=`string`||e===``)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function S(e){return typeof e==`string`?e:void 0}function C(e){if(typeof e!=`object`||!e)return null;let t=e;switch(t.type){case`text`:return typeof t.text==`string`?h(t.text):null;case`image`:return typeof t.image==`string`?g(t.image,{mimeType:S(t.mimeType),alt:S(t.alt)}):null;case`file`:return typeof t.data==`string`&&typeof t.mimeType==`string`&&typeof t.filename==`string`?y(t.data,t.mimeType,t.filename):null;case`audio`:return typeof t.audio==`string`?{type:`audio`,audio:t.audio,...S(t.mimeType)!==void 0&&{mimeType:t.mimeType}}:null;case`video`:return typeof t.video==`string`?{type:`video`,video:t.video,...S(t.mimeType)!==void 0&&{mimeType:t.mimeType}}:null;default:return null}}function ee(e,t){let n=x(t),r=e.map(e=>x(e.timestamp)),i=Array(e.length),a=0;for(;a<r.length;){let e=r[a];if(e!==null){i[a]=e,a+=1;continue}let t=a;for(;t+1<r.length&&r[t+1]===null;)t+=1;let o=t-a+1,s=a>0?i[a-1]:null,c=t+1<r.length?r[t+1]:null,l=c!==null&&n!==null?Math.min(c,n):c??n;for(let e=0;e<o;e+=1)i[a+e]=l===null?s===null?0+e:s+e+1:l-(o-e);a=t+1}return i.map(e=>new Date(e).toISOString())}function w(e,t){let n=ee(e,t?.beforeCreatedAt),r=[];return e.forEach((e,t)=>{if(typeof e?.id!=`string`||e.id===``||!b.includes(e.role))return;let i=e.role,a=n[t],o=e.author,s=o&&typeof o==`object`?{...typeof o.id==`string`&&{id:o.id},...typeof o.displayName==`string`&&{displayName:o.displayName},...[`human`,`ai`,`system`].includes(o.kind??``)&&{kind:o.kind}}:void 0;if(e.displayAvailable===!1){let t={historyDisplayUnavailable:!0};r.push({id:e.id,role:i,...s&&{author:s},content:``,createdAt:a,agentMetadata:t})}else if(typeof e.displayContent==`string`)r.push({id:e.id,role:i,...s&&{author:s},content:e.displayContent,createdAt:a});else if(typeof e.content==`string`)r.push({id:e.id,role:i,...s&&{author:s},content:e.content,createdAt:a});else if(Array.isArray(e.content)){let t=e.content.map(C).filter(e=>e!==null),n=p(t);r.push({id:e.id,role:i,...s&&{author:s},content:n||(m(t)?`[Image]`:``),createdAt:a,...t.length>0&&{contentParts:t}})}else r.push({id:e.id,role:i,...s&&{author:s},content:``,createdAt:a})}),r}function te(e,t){let n=/* @__PURE__ */ new Map;for(let t of e)n.set(t.id,t);for(let e of t)n.set(e.id,e);return[...n.values()].sort((e,t)=>{let n=new Date(e.createdAt).getTime(),r=new Date(t.createdAt).getTime();if(!Number.isNaN(n)&&!Number.isNaN(r)&&n!==r)return n-r;let i=e.sequence??0,a=t.sequence??0;return i===a?e.id.localeCompare(t.id):i-a})}const ne=/* @__PURE__ */ new Map([[`not_found`,`not_found`],[`conversation_deleted`,`not_found`],[`rate_limited`,`rate_limited`],[`authentication_required`,`authentication_required`],[`invalid_identity_proof`,`authentication_required`],[`visitor_identity_mismatch`,`authentication_required`],[`visitor_required`,`authentication_required`],[`identity_provider_failed`,`identity_provider_failed`],[`proof_not_admitted`,`proof_not_admitted`],[`identity_contract_violation`,`proof_not_admitted`],[`unauthorized`,`authentication_failed`],[`visitor_token_missing`,`authentication_failed`],[`conversation_credential_missing`,`authentication_failed`]]),re=/* @__PURE__ */ new Map([[`not_found`,`That conversation is no longer available.`],[`rate_limited`,`Too many history requests.`],[`authentication_failed`,`History access was not authorized.`],[`authentication_required`,`Sign in again to view account history.`],[`identity_provider_failed`,`The identity provider did not respond.`],[`proof_not_admitted`,`Account history is not available for this configuration.`],[`unsupported_scope`,`This history scope is not supported.`],[`unavailable`,`Conversation history is unavailable right now.`]]),T=e=>re.get(e)??`Conversation history is unavailable right now.`;function ie(e,{HistoryClientError:t,HistoryProviderError:n}){if(e instanceof n)return e;if(e instanceof t){let t=ne.get(e.code)??`unavailable`;return new n(t,T(t),{...e.retryAfterSeconds===void 0?{}:{retryAfterSeconds:e.retryAfterSeconds}})}return new n(`unavailable`,T(`unavailable`))}function ae(e){let{HistoryProviderError:t}=e.errors,n=()=>e.getClient?.()??e.client,r=e.getIdentityProofConfigured()?[`browser`,`verified-user`]:[`browser`],i={scopes:r},a=e=>{if(!r.includes(e))throw new t(`unsupported_scope`,T(`unsupported_scope`))},o=async(t,n)=>{a(t);try{return await n()}catch(t){throw ie(t,e.errors)}},s=t=>{let n=!1;return{conversationId:t.session.conversationId??``,conversationRevision:t.session.conversationRevision??``,async commit(){n||(n=!0,t.commit(),await e.onActivationCommitted(t.session))},discard(){n||(n=!0,t.discard())}}};return{capabilities:i,getIdentityStatus(){return n().getHistoryIdentityStatus()},subscribeIdentityStatus(e){return n().subscribeHistoryIdentityStatus(e)},subscribeAvailability(e){return n().subscribeHistoryAvailability(e)},async list(e){return o(e.context.scope,async()=>{let t=await n().listConversations({...e.cursor?{cursor:e.cursor}:{},...e.limit===void 0?{}:{limit:e.limit},...e.targetId?{targetId:e.targetId}:{},scope:e.context.scope});return{items:t.data,nextCursor:t.nextCursor}})},async getPage(e,t){return o(t.context.scope,async()=>{let r=await n().getConversation(e,{...t.cursor?{messageCursor:t.cursor}:{},scope:t.context.scope}),i=w(r.messages,{...t.beforeCreatedAt?{beforeCreatedAt:t.beforeCreatedAt}:{}});return{summary:r.summary,messages:te([],i),conversationRevision:r.conversationRevision??``,nextCursor:r.nextMessageCursor}})},async prepareOpen(e,t){return o(t.context.scope,async()=>s(await n().prepareConversationSession(e)))},async prepareStartNew(e){return o(e.context.scope,async()=>s(await n().prepareNewConversationSession()))},async delete(e,t){await o(t.context.scope,()=>n().deleteConversation(e,{scope:t.context.scope}))},async deleteAll(e){return o(e.context.scope,()=>n().deleteAllConversations({...e.targetId===void 0?{}:{targetId:e.targetId},scope:e.context.scope}))},async resetDevice(){try{return await n().resetVisitor(),{remoteRevocationConfirmed:!0}}catch{return{remoteRevocationConfirmed:!1}}}}}const oe=e=>{let n=i(e.config.features?.history?.copy),r=null,a=!1,o=null,s=null,c=`conversation`,p=null,m=null,h=null,g=null,_=0,v=null,y=null,b=null,x=`persona-history-${Math.random().toString(36).slice(2,8)}`,S=()=>e.historyFeatureEnabled()&&!!r&&!a,C=()=>{let t=e.session.getStatus();return e.isStreaming||t===`paused`||t===`resuming`},ee=()=>{let t=e.config.features?.history?.scope;if(t)return t;let n=e.config.getIdentityProof?`verified-user`:`browser`,i=r?.capabilities.scopes;return!i||i.includes(n)?n:i[0]??n},w=()=>s?.scope??ee(),te=()=>e.session.getClientSession()?.targetId??null,ne=e=>`${e.state}:${`reason`in e?e.reason:``}`,re=t=>{let n=ne(t);n!==g&&(g=n,e.eventBus.emit(`history:identityStatusChanged`,{status:t,timestamp:Date.now()}))},T=null,ie=null,oe=()=>{if(!e.historyFeatureEnabled())return null;let t=e.getHistoryProviderFactory();if(t)return t();let n=e.config.features?.history?.provider;return n?typeof n==`function`?(T!==n&&(T=n,ie=n()),ie):n:e.session.isClientTokenMode()?ae({errors:e.historyErrors,client:e.session.getClient(),getIdentityProofConfigured:()=>typeof e.config.getIdentityProof==`function`,onActivationCommitted:t=>e.session.bindActivatedSession(t),getClient:()=>e.session.getClient()}):null},se=()=>{y?.(),y=null,b?.(),b=null,a=!1;let t=r;r=oe(),t&&t!==r&&e.discardConversationContinuity();let n={...e.historyInternals};r?n.historyProvider=r:delete n.historyProvider,e.historyInternals=n,e.session.setHistoryInternals(e.historyInternals),r&&(y=r.subscribeAvailability?.(e=>{a=!e,e||q({restoreFocus:!1}),$()})??null,b=r.subscribeIdentityStatus(e=>re(e)),g=ne(r.getIdentityStatus()))},ce=()=>{let t=e.config.features?.history?.presentation??`panel`;if(t===`panel`||t===`auto`&&e.launcherEnabled&&!e.isDockedMountMode(e.config))return`panel`;let n=e.artifactSplitRoot??e.container;return(n.getBoundingClientRect().width||n.clientWidth)>=720?`rail`:`panel`},E=(e,t)=>{t?(e.setAttribute(`aria-hidden`,`true`),e.setAttribute(`inert`,``)):(e.removeAttribute(`aria-hidden`),e.removeAttribute(`inert`))},le=`data-persona-history-suppressed`,D=null,O=null,k=null,ue=null,de=null,fe=``,pe=()=>e.header===de?fe:t(e.config)?``:`none`,me=()=>e.historyPresentation===`panel`&&!!k&&ue===k.element&&t(e.config)&&pe()!==`none`,he=()=>{for(let t of Array.from(e.header.children))t!==D&&t.setAttribute(le,``)},ge=()=>{for(let t of Array.from(e.container.querySelectorAll(`[${le}]`)))t.removeAttribute(le)},_e=()=>{let t=k;if(!t)return;if(Array.from(e.header.children).some(e=>e!==D&&!e.hasAttribute(le))){O&&O!==e.header&&(O.style.removeProperty(`min-height`),O=null);let t=e.header.offsetHeight;t>0&&(e.header.style.minHeight=`${t}px`,O=e.header)}D||=u(`div`,`persona-history-header-host`),t.setHeaderPlacement(`external`);let n=t.getHeaderElement();n.parentNode!==D&&D.replaceChildren(n),D.parentNode!==e.header&&e.header.appendChild(D),he()},ve=()=>{O&&=(O.style.removeProperty(`min-height`),null),D&&(k?.setHeaderPlacement(`inline`),D.remove(),D=null,ge())},ye=null,be=()=>{ye&&(e.body.style.display=`none`,E(e.body,!0),e.footer.hidden=!0,E(e.footer,!0),e.panelSuggestions.style.display=`none`,E(e.panelSuggestions,!0),e.panelSuggestionsFade.style.display=`none`,me()?(_e(),e.header.style.display=pe(),E(e.header,!1)):(ve(),e.header.style.display=`none`,E(e.header,!0)))};e.reapplyHistoryHostChrome=be;let xe=n=>{let r=e.body.style.display,i=e.footer.hidden,a=e.panelSuggestions.style.display,o=e.panelSuggestionsFade.style.display,s=e.footer,c=e.header,l=e.header.style.display;de=c,fe=l,ye=()=>{ye=null,ve(),de=null,e.body.style.display=r,E(e.body,!1),e.panelSuggestions.style.display=a,E(e.panelSuggestions,!1),e.panelSuggestionsFade.style.display=o,s.hidden=i,E(s,!1),e.footer!==s&&(e.footer.hidden=!1,E(e.footer,!1)),c.style.display=l,E(c,!1),e.header!==c&&(e.header.style.display=t(e.config)?``:`none`,E(e.header,!1))},e.container.insertBefore(n,e.footer.parentNode===e.container?e.footer:e.panelSuggestions),be()},A=null,j=null,Se=null,M=null,Ce=()=>[e.header,e.panelElements.closeButtonWrapper,e.panelElements.clearChatButtonWrapper,e.body,e.footer,e.scrollToBottomButton],we=()=>e.config.features?.history?.rail?.collapsible!==!1,N=()=>e.config.features?.history?.rail?.side===`right`?`right`:`left`,Te=e=>Math.min(400,Math.max(200,Math.round(e))),Ee=()=>e.config.features?.history?.rail?.resizable===!0,P,De=()=>{if(P===void 0&&(P=null,e.config.persistState!==!1))try{let t=Number(window.localStorage.getItem(`${e.currentKeyPrefix()}rail-width`));t&&(P=t)}catch{}return P},F=()=>Te(De()??e.config.features?.history?.rail?.width??260),Oe=t=>{if(P=t,e.config.persistState!==!1)try{window.localStorage.setItem(`${e.currentKeyPrefix()}rail-width`,String(t))}catch{}},ke=()=>we()&&e.config.features?.history?.rail?.collapsedBehavior===`overlay`,I=!1,Ae=e=>{let t=u(`img`);return t.src=e,t.alt=``,t.setAttribute(`aria-hidden`,`true`),t},je=()=>{let t=e.config.features?.history?.rail?.brand;if(!t)return;let n=!1,r;return i=>{if(t.render)try{return t.render({collapsed:i})??null}catch(e){return n||(n=!0,console.warn(`[persona] history rail brand threw`,e)),null}return r===void 0&&(r=t.iconUrl?Ae(t.iconUrl):t.icon?e.renderLucideIcon(t.icon,20):null),r?r.cloneNode(!0):null}},Me=()=>e.config.features?.history?.rail?.sections?.map(t=>{let n=!1,r=e=>{n||(n=!0,console.warn(`[persona] history rail section threw`,t.id,e))};return{id:t.id,title:t.title,placement:t.placement??`above-conversations`,items:t.items.map(t=>{let n;return{id:t.id,label:t.label,badge:t.badge,iconNode:()=>{if(n!==void 0)return n;try{n=t.renderIcon?t.renderIcon()??null:t.iconUrl?Ae(t.iconUrl):t.icon?e.renderLucideIcon(t.icon,20):null}catch(e){r(e),n=null}return n},onSelect:()=>{try{t.onSelect()}catch(e){r(e)}}}})}})??[],Ne=e=>{let t=Me();for(let n of e)t.some(e=>e.id===n.id)?console.warn(`[persona] duplicate history rail section id`,n.id):t.push(n);return t.length?t:void 0},L=null,Pe=()=>`${e.currentKeyPrefix()}rail-collapsed`,Fe=()=>{if(L===null&&(L=e.config.features?.history?.rail?.defaultCollapsed===!0,e.config.persistState!==!1))try{let e=window.localStorage.getItem(Pe());e&&(L=e===`1`)}catch{}return L},Ie=t=>{if(L=t,e.config.persistState!==!1)try{window.localStorage.setItem(Pe(),t?`1`:`0`)}catch{}},R=()=>e.historyPresentation===`rail`&&we()&&!ke()&&Fe(),Le=()=>{},Re=()=>{ke()?Le():(Ie(!Fe()),o?.view.setCollapsed(R()),e.applyRailChrome(),e.repinAnchoredMessage())},ze=()=>{let t=e.config.features?.history?.rail?.collapseShortcut;return!t||!e.parseCombo(t)?null:{combo:t,hint:e.formatCombo(t),aria:e.ariaCombo(t)}},Be=`var(--persona-history-overlay-margin,8px)`,z=null,B=null,Ve=0,V=null,H=null,U=!1,He=0,Ue=()=>window.matchMedia?.(`(pointer: coarse)`).matches===!0,W=()=>S()&&ke()&&(e.historyPresentation??ce())===`rail`,We=()=>e.historyVisible&&!I,G=()=>{H!==null&&clearTimeout(H),H=null},Ge=()=>{e.loadHistoryView().catch(()=>{})},Ke=()=>{G(),I&&(H=setTimeout(()=>{H=null,!U&&I&&(V?.contains(document.activeElement)||q({restoreFocus:!1}))},300))},qe=(e,t)=>{let n=V?.getBoundingClientRect();if(!n)return!1;let r=z?.getBoundingClientRect(),i=r?Math.min(r.top,n.top):n.top;return e>=n.left&&e<=n.right&&t>=i&&t<=n.bottom||!!r&&e>=r.left&&e<=r.right&&t>=r.top&&t<=r.bottom},Je=e=>{I&&(U=qe(e.clientX,e.clientY),U?G():H===null&&Ke())},Ye=t=>{!e.historyVisible&&W()&&(I=!0,gt({invoker:z,keyboard:t?.keyboard===!0}).then(()=>{e.historyVisible?!U&&document.activeElement!==z&&q():I=!1}))},Xe=()=>{let e=ue?.querySelector(`[data-persona-history-focus="collapse"]`);e&&(e.setAttribute(`aria-label`,I?n.expandLabel:n.collapseLabel),e.setAttribute(`aria-expanded`,I?`false`:`true`))},Ze=()=>{Ie(!1);let t=o;if(!I||!t){gt({invoker:z});return}let n=document.activeElement===z;I=!1,ut(),t.element.remove(),ft(t.element),Xe(),n&&ht(),e.repinAnchoredMessage(),$()},Qe=()=>{Ie(!0),q()};Le=()=>{!e.historyVisible||I?Ze():Qe()};let $e=()=>{let t=ze(),r=e.createHeaderIconButton({ariaLabel:n.expandLabel,iconName:`panel-left`,wrapperClassName:`persona-relative persona-inline-flex persona-items-center persona-justify-center`,extraClassName:`persona-rail-trigger`,tooltip:!1,attrs:{"data-persona-rail-trigger":``,"aria-controls":x,...t?{"aria-keyshortcuts":t.aria}:{}}}),i=r.button;i.addEventListener(`mouseenter`,()=>{U=!0,G(),!(Ue()||Date.now()<He)&&Ye()}),i.addEventListener(`mouseleave`,()=>{U=!1,He=0,Ke()}),i.addEventListener(`focus`,()=>{e.historyVisible||Ge()}),i.addEventListener(`click`,t=>{S()&&(t.detail!==0&&Ue()&&!e.historyVisible?Ye():Ze())}),z=i,B=r.wrapper},et=()=>{if(B&&!B.isConnected&&(B=null,z=null),!W()){B?.remove(),B=null,z=null;return}z||$e();let t=B,r=z;if(!t||!r)return;let i=N()===`right`?null:e.header.firstChild;(i??e.header.lastChild)!==t&&e.header.insertBefore(t,i),t.style.display=We()||Ve>0?`none`:``,r.setAttribute(`aria-label`,n.expandLabel),r.setAttribute(`aria-expanded`,e.historyVisible?`true`:`false`),V&&e.applyRailChrome()},tt=e=>{if(!I)return;let t=e.target;t instanceof Node&&(V?.contains(t)||B?.contains(t)||t instanceof Element&&t.closest(`.persona-dropdown-menu,[role="alertdialog"]`)||q({restoreFocus:!1}))};document.addEventListener(`pointerdown`,tt,!0),e.destroyCallbacks.push(()=>{document.removeEventListener(`pointerdown`,tt,!0),document.removeEventListener(`pointermove`,Je),K?.(),G()});let nt=null,K=null,rt=t=>{Oe(Te(t)),e.applyRailChrome(),e.repinAnchoredMessage()},it=()=>{let t=u(`div`,`persona-rail-resizer`);return t.tabIndex=0,t.setAttribute(`role`,`separator`),t.setAttribute(`aria-orientation`,`vertical`),t.setAttribute(`aria-valuemin`,`200`),t.setAttribute(`aria-valuemax`,`400`),t.addEventListener(`pointerdown`,n=>{let r=j;if(!r||n.button!==0)return;n.preventDefault(),K?.();let i=n.clientX,a=r.getBoundingClientRect().width||F(),o=N()===`right`?-1:1,s=a,c=e.mount.ownerDocument;r.style.transition=`none`;let l=e=>{s=Te(a+o*(e.clientX-i)),r.style.flex=`0 0 ${s}px`,t.setAttribute(`aria-valuenow`,String(s))},u=()=>{K=null,c.removeEventListener(`pointermove`,l),c.removeEventListener(`pointerup`,u),c.removeEventListener(`pointercancel`,u),r.style.removeProperty(`transition`);try{t.releasePointerCapture(n.pointerId)}catch{}rt(s)};K=u,c.addEventListener(`pointermove`,l),c.addEventListener(`pointerup`,u),c.addEventListener(`pointercancel`,u);try{t.setPointerCapture(n.pointerId)}catch{}}),t.addEventListener(`keydown`,e=>{let t=N()===`right`?-16:16,n=F(),r=e.key===`ArrowRight`?n+t:e.key===`ArrowLeft`?n-t:e.key===`Home`?200:e.key===`End`?400:null;r!==null&&(e.preventDefault(),rt(r))}),t},at=(e,t)=>{if(!Ee()||R()){K?.(),nt?.remove();return}let r=nt??it();nt=r,r.setAttribute(`aria-label`,n.resizeLabel),r.setAttribute(`aria-valuenow`,String(F())),r.nextElementSibling!==t&&e.insertBefore(r,t)};e.applyRailChrome=()=>{o?.view.setRailSide(N());let t=N()===`right`,n=V;if(n){let r=z?z.getBoundingClientRect().bottom-e.container.getBoundingClientRect().top:0;n.style.top=`calc(${Math.max(0,Math.round(r))}px + ${Be})`,n.style.width=`${F()}px`,n.style.left=t?``:Be,n.style.right=t?Be:``}let r=j,i=A,a=Se;if(!r||!i||!a)return;r.style.flex=`0 0 ${R()?52:F()}px`;let s=`1px solid var(--persona-divider,#e5e7eb)`;r.style.borderRight=t?``:s,r.style.borderLeft=t?s:``;let c=t?a:r;i.firstElementChild!==c&&i.append(c,t?r:a),at(i,t?r:a)};let ot=t=>{if(M&&j){M.replaceWith(t),M=null,e.applyRailChrome();return}let n=u(`div`,`persona-history-rail-shell`);n.style.cssText=`display:flex;flex-direction:row;flex:1 1 auto;min-height:0`;let r=u(`div`,`persona-history-rail-conversation`);r.style.cssText=`display:flex;flex-direction:column;flex:1 1 auto;min-width:0;min-height:0;position:relative`;let i=u(`div`,`persona-history-rail-host`);i.style.cssText=`display:flex;min-height:0;overflow:hidden`,e.container.insertBefore(n,e.header.parentNode===e.container?e.header:e.body);for(let t of Ce())t?.parentNode===e.container&&r.appendChild(t);n.append(i,r),i.appendChild(t),A=n,j=i,Se=r,e.applyRailChrome()},st=()=>{if(A)return;let t=u(`div`,`persona-history-rail-placeholder`);t.style.cssText=`flex:1 1 auto;min-height:0`,M=t,ot(t),e.repinAnchoredMessage()},ct=()=>{M&&(ut(),e.repinAnchoredMessage())},lt=t=>{let n=u(`div`,`persona-history-rail-overlay`);n.style.cssText=`position:absolute;bottom:${Be};display:flex;overflow:hidden;z-index:100000;border-radius:var(--persona-history-overlay-radius,16px);background:var(--persona-history-overlay-bg,var(--persona-container,#f7f7f8));box-shadow:var(--persona-history-overlay-shadow,0 12px 40px rgba(0,0,0,0.25))`,e.container.style.position=`relative`,e.container.appendChild(n),n.appendChild(t),document.addEventListener(`pointermove`,Je),V=n,e.applyRailChrome(),Xe()},ut=()=>{ye?.(),V&&=(U&&(He=Date.now()+150),document.removeEventListener(`pointermove`,Je),V.remove(),null);let t=A;if(t){K?.();for(let n of Ce())if(n&&t.contains(n)){let r=n===e.scrollToBottomButton?e.panelSuggestions:t;e.container.insertBefore(n,r)}t.remove(),A=null,j=null,Se=null,M=null}},dt=e=>{ue=e,e.id=x,e.style.flex=`1 1 auto`,e.style.minHeight=`0`},ft=t=>{dt(t),(e.historyPresentation!==`rail`||I)&&ct(),e.historyPresentation===`rail`?I?lt(t):ot(t):xe(t)},pt=()=>{if(et(),Vt(),!e.historyVisible||!o)return;let t=ce();if(t===e.historyPresentation)return;let n=document.activeElement,r=n instanceof HTMLElement&&(o.element.contains(n)||D?.contains(n)===!0)?n:null;ut(),o.element.remove(),o.view.setHeaderPlacement(`inline`),e.historyPresentation=t,o.view.setPresentation(t),o.view.setCollapsed(R()),o.requestRender(),o.element.isConnected||ft(o.element),r?.isConnected?r.focus():ht(),e.syncScrollToBottomButton(),e.repinAnchoredMessage(),$()},mt=(e,t)=>D?.querySelector(t)??e.querySelector(t),ht=()=>{let e=o?.element??ue;if(!e)return;let t=mt(e,`[data-persona-history-focus="close"],[data-persona-history-focus="collapse"]`);if(t){t.focus();return}let n=mt(e,`.persona-history-title`)??e;n.tabIndex=-1,n.focus()},gt=async i=>{if(!S()||e.historyVisible)return;let a=r;if(!a)return;if(!I&&W()&&Fe()){et();return}_t();let u=++_;c=i?.returnSurface??`conversation`,p=i?.invoker??m;let d=W()&&!I;d&&(Ve+=1,et(),st());let f;try{f=await e.loadHistoryView()}catch{e.announceHistory(n.openHistoryLabel),d&&(--Ve,u===_&&(ct(),et()));return}if(d&&--Ve,u!==_||e.historyVisible)return;s={scope:ee()},e.historyPresentation=ce(),e.historyVisible=!0;let h=e.historyPresentation===`panel`&&t(e.config)&&e.header.style.display!==`none`?`external`:`inline`,g=e.config.features?.history?.rowAvatar,v=ze(),y=v?{hint:v.hint,aria:v.aria}:null,b={provider:a,context:s,targetId:te(),presentation:e.historyPresentation,collapsible:we(),collapsed:R(),railSide:N(),renderRailHeader:e.config.features?.history?.rail?.renderHeader,railBrand:je(),onToggleCollapse:Re,...y?{collapseShortcut:y}:{},headerPlacement:h,showScopeStatus:e.config.features?.history?.showScopeStatus!==!1,showDelete:e.config.features?.history?.showDelete!==!1,showDeleteAll:e.config.features?.history?.showDeleteAll!==!1,...e.config.features?.history?.listActions?.length?{listActions:e.config.features.history.listActions}:{},rowAvatar:g===!1?!1:typeof g==`string`?g:e.config.launcher?.iconUrl,activeConversationId:e.session.getActiveConversationId(),...e.config.features?.history?.grouping?{grouping:e.config.features.history.grouping}:{},...e.config.features?.history?.copy?{copy:e.config.features.history.copy}:{},...e.config.features?.history?.pageSize===void 0?{}:{pageSize:e.config.features.history.pageSize},onSelect:e=>kt(e,{focusComposer:!0}).catch(()=>{}),onActiveConversationChange:t=>e.setActiveConversationSummary(t),attachTooltip:e.attachTooltip,onStartNew:()=>At({focusComposer:!0}),onClose:()=>q(),onRequestDeleteConversation:e=>Lt(e),onRequestClearHistory:()=>Rt(),...a.resetDevice?{onRequestResetIdentity:()=>zt()}:{}};o=l({plugins:e.plugins,config:e.config,getPresentation:()=>e.historyPresentation??`panel`,getReturnSurface:()=>c,close:()=>q(),createView:({slots:t,renderDom:n,onModelChange:r,railSections:i})=>(k=f.createHistoryView({...b,railSections:Ne(i),slots:t,renderDom:n,onModelChange:r,onAnnounce:e.announceHistory}),k),onElementChanged:(e,t)=>{if(!t?.isConnected)return ft(e);dt(e),t.replaceWith(e),be()}}),o.view.setNewConversationRequired(e.historySessionState.recovery===`new_conversation_required`),i?.focus!==!1&&(e.historyPresentation!==`rail`||i?.keyboard===!0)&&ht(),e.syncScrollToBottomButton(),e.repinAnchoredMessage(),$(),e.eventBus.emit(`history:opened`,{presentation:e.historyPresentation,returnSurface:c,timestamp:Date.now()})},_t=()=>{},q=t=>{if(!e.historyVisible)return;_+=1;let n=c,r=p,i=o,a=t?.restoreFocus!==!1;e.historyVisible=!1;let l=!1,u=null,d=()=>{if(!l){if(l=!0,_t=()=>{},u!==null&&clearTimeout(u),I=!1,G(),ut(),i?.dispose(),i?.view.destroy(),i?.element.remove(),o===i&&(o=null,k=null,ue=null,e.historyPresentation=null,s=null,p=null),e.syncScrollToBottomButton(),e.repinAnchoredMessage(),$(),a){let t=r??m;t?.isConnected?t.focus():e.maybeFocusInput()}e.eventBus.emit(`history:closed`,{returnSurface:n,timestamp:Date.now()})}},f=i&&i.element===i.view.element?i.view.playExit():null;f?(_t=d,u=setTimeout(d,250),f.then(d)):d()},vt=t=>{if(t.key===`Escape`&&e.historyVisible&&o){if(e.historyPresentation===`rail`){let e=t.target;if(!(e instanceof Node)||!(o.element.contains(e)||I&&B?.contains(e)===!0))return}t.preventDefault(),t.stopPropagation(),q()}};e.container.addEventListener(`keydown`,vt),e.destroyCallbacks.push(()=>e.container.removeEventListener(`keydown`,vt));let yt=0,J=null,bt=null,Y=()=>{bt&&clearTimeout(bt),bt=null};e.destroyCallbacks.push(Y);let xt=()=>{Y();let t=e.conversationOpenPendingEl;t&&(e.conversationOpenTakeover=!0,t.hidden=!1,e.messagesWrapper.style.display=`none`,e.updateWelcome())},X=()=>{yt+=1,Y(),J?.remove(),J=null,e.conversationOpenPendingEl&&(e.conversationOpenPendingEl.remove(),e.conversationOpenPendingEl=null,e.conversationOpenTakeover=!1,e.messagesWrapper.style.removeProperty(`display`),E(e.footer,!1),e.updateWelcome())},St=()=>{try{if(window.matchMedia?.(`(prefers-reduced-motion: reduce)`)?.matches)return;e.messagesWrapper.animate([{opacity:0},{opacity:1}],{duration:150,easing:`ease-out`})}catch{}},Ct=t=>{let n=e.config.layout?.messages?.layout??`bubble`,r=d(`div`,{className:`persona-flex`,attrs:{"aria-hidden":`true`}});e.applyMessageRowLayout(r,t);let i=d(`div`,{className:f(e.getBubbleClasses(t,n).join(` `),`persona-conversation-loading-bubble`),attrs:{"data-persona-theme-zone":`${t}-message`},style:{width:t===`user`?`64%`:`100%`,backgroundColor:n===`flat`?`transparent`:`var(--persona-message-${t}-bg, var(--persona-${t===`user`?`accent`:`container`}))`,color:`var(--persona-message-${t}-text, ${t===`user`&&n!==`flat`?`white`:`var(--persona-text)`})`}},...[`94%`,...t===`assistant`?[`86%`]:[],`62%`].map(e=>d(`div`,{className:`persona-conversation-loading-line`,style:{width:e}})));return e.applyBubbleGeometry(i,t,n,{...e.resolveThemeDefaults(e.config.future).components.message[t],...e.config.theme?.components?.message?.[t],...e.config.darkTheme?.components?.message?.[t]}),r.appendChild(i),r},wt=()=>d(`div`,{className:`persona-conversation-loading-body`,style:{gap:e.messagesWrapper.style.gap}},Ct(`user`),Ct(`assistant`),Ct(`user`),Ct(`assistant`)),Tt=()=>e.config.loadingIndicator?.conversationOpenVariant===`skeleton`?wt():d(`div`,{className:`persona-conversation-loading-spinner`,attrs:{"aria-hidden":`true`}},d(`span`,{className:`persona-conversation-loading-ring`})),Et=t=>{e.conversationOpenPendingEl?.remove(),e.conversationOpenPendingEl=t,t.hidden=!e.conversationOpenTakeover,e.body.insertBefore(t,e.messagesWrapper),Y(),e.conversationOpenTakeover||(bt=setTimeout(xt,250)),E(e.footer,!0)},Dt=()=>{let t={config:e.config,streaming:!1,location:`conversation-open`,defaultRenderer:Tt},r=null,i=e.plugins.find(e=>e.renderLoadingIndicator);i?.renderLoadingIndicator&&(r=i.renderLoadingIndicator(t)),r===null&&e.config.loadingIndicator?.render&&(r=e.config.loadingIndicator.render(t));let a=r??Tt();Et(d(`div`,{className:f(`persona-conversation-loading`,a.classList.contains(`persona-conversation-loading-spinner`)&&`persona-conversation-loading--centered`),attrs:{role:`status`,"aria-label":n.openConversationLoadingLabel},style:{maxWidth:e.messagesWrapper.style.maxWidth||`none`}},a))},Ot=t=>{let r=()=>{kt(t,{focusComposer:!0}).catch(()=>{})},i=S()?()=>{X(),gt()}:void 0,a=(e,t)=>{let n=d(`button`,{className:`persona-conversation-loading-error-action`,attrs:{type:`button`},text:e});return n.addEventListener(`click`,t),n},o=()=>d(`div`,{className:`persona-conversation-loading-error-body`},d(`p`,{className:`persona-conversation-loading-error-title`,text:n.openConversationErrorTitle}),d(`div`,{className:`persona-conversation-loading-error-actions`},a(n.openConversationRetryLabel,r),i?a(n.openConversationBackLabel,i):null)),s=Object.freeze({conversationId:t,config:e.config,copy:Object.freeze({title:n.openConversationErrorTitle,retryLabel:n.openConversationRetryLabel,backLabel:n.openConversationBackLabel}),retry:r,...i?{back:i}:{},defaultRenderer:o}),c=null;for(let t of e.plugins)if(t.renderHistoryOpenError){try{c=t.renderHistoryOpenError(s)}catch(e){console.warn(`[persona] renderHistoryOpenError threw`,e),c=null}if(c)break}if(J?.remove(),J=d(`div`,{className:`persona-conversation-loading-error`,attrs:{role:`alert`}},c??o()),!e.session.getActiveConversationId()&&e.session.getMessages().length===0&&!e.composerStore.getState().text&&!e.attachmentManager?.hasAttachments()){let e=J;J=null,Et(e),xt()}else e.body.insertBefore(J,e.messagesWrapper);e.announceHistory(n.openConversationErrorTitle)};e.eventBus.on(`history:closed`,()=>{e.conversationOpenPendingEl&&E(e.footer,!0)});let kt=async(t,{focusComposer:n=!1,busy:r=`reject`}={})=>{let i=w();if(r===`background`&&(e.session.assertBackgroundSwitchable(),e.composerStore.getState().phase===`preparing`))throw new e.SessionHistoryError(`conversation_busy`,`Finish preparing this turn before switching conversations`);if(r===`reject`&&(e.session.isStreaming()||[`paused`,`resuming`].includes(e.session.getStatus())||e.composerStore.getState().phase===`preparing`))throw new e.SessionHistoryError(`conversation_busy`,`Finish or stop the current turn before switching conversations`);r===`stop`&&(++e.composerConversationGeneration,e.submissionAbort?.abort(),e.submissionAbort=null,e.composerStore.setPreparing(!1),e.session.cancel());let a=e.conversationStateKey();(!e.conversationOpenPendingEl||e.pendingConversationReading?.key!==a)&&(e.pendingConversationReading={key:a,reading:e.captureConversationReading()});let s=null,c=!!o;o?.view.setActiveConversationId(t),X();let l=yt;Dt(),e.historyVisible&&(e.historyPresentation===`panel`||I)&&q({restoreFocus:!1}),e.suppressScrollSend=!0;try{await e.session.openConversation(t,{scope:i,busy:r,onBeforeCommit:()=>{e.saveConversationContinuity(),s=e.composerConversationGeneration,e.conversationPersistenceOwner=s},onCommitted:()=>{e.restoreConversationContinuity(),e.conversationPersistenceOwner===s&&(e.conversationPersistenceOwner=null),e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),e.persistState()}})}catch(n){if(e.conversationPersistenceOwner===s&&(e.conversationPersistenceOwner=null),s===e.composerConversationGeneration&&e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),l===yt){let n=e.pendingConversationReading?.reading;X(),n&&e.restoreConversationReading(n),e.pendingConversationReading=null,o?.view.setActiveConversationId(e.session.getActiveConversationId()),Ot(t),e.suppressScrollSend=!1}throw n}finally{(l===yt||!e.conversationOpenPendingEl)&&(e.suppressScrollSend=!1)}l===yt&&(X(),e.pendingConversationReading=null,e.messageCache.clear(),St(),Q(),c||e.setActiveConversationSummary(null),e.eventBus.emit(`history:conversationOpened`,{conversationId:t,title:e.activeConversationTitle,scope:i,timestamp:Date.now()}),n&&e.maybeFocusInput())},At=async({focusComposer:t=!1}={})=>{X();let n=null;try{await e.session.startNewConversation({scope:w(),onBeforeCommit:()=>{e.saveConversationContinuity(),n=e.composerConversationGeneration,e.conversationPersistenceOwner=n},onCommitted:()=>{e.restoreConversationContinuity(!0),e.conversationPersistenceOwner===n&&(e.conversationPersistenceOwner=null),e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),e.persistState(),e.pendingConversationReading=null}})}catch(t){throw e.conversationPersistenceOwner===n&&(e.conversationPersistenceOwner=null),n===e.composerConversationGeneration&&e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),t}e.setActiveConversationSummary(null),e.messageCache.clear(),e.resetAnchorState(),e.resumeAutoScroll(),e.jumpToBottomInstant(),Q();let r=e.session.getActiveConversationId();o?.view.setActiveConversationId(r),e.eventBus.emit(`history:conversationStarted`,{conversationId:r,timestamp:Date.now()}),e.historyVisible&&(e.historyPresentation===`panel`||I)&&q({restoreFocus:!1}),t&&e.maybeFocusInput()},jt=async(t,n)=>{let r=await e.session.updateConversation(t,{...n,...n.title===void 0?{}:{title:n.title.trim()}});return o?.view.applyConversationSummary(r),!o&&t===e.session.getActiveConversationId()&&e.setActiveConversationSummary(r),r},Mt=async t=>{let n=w(),r=e.session.getActiveConversationId()===t;await e.session.deleteConversation(t,{scope:n}),e.discardConversationContinuity(t),r&&(e.attachmentManager?.destroy({release:!0}),e.attachmentManager=null,e.restoreConversationContinuity(!0)),o?.view.removeConversationSummary(t),r&&(e.setActiveConversationSummary(null),e.messageCache.clear(),e.resetAnchorState(),e.resumeAutoScroll(),Q()),e.eventBus.emit(`history:conversationDeleted`,{conversationId:t,scope:n,wasActive:r,timestamp:Date.now()})},Nt=async t=>{let n=t?.scope??w(),r=t?.allTargets?null:t?.targetId??te(),i=await e.session.clearConversationHistory({...r?{targetId:r}:{},scope:n});return e.discardConversationContinuity(),e.setActiveConversationSummary(null),e.messageCache.clear(),e.resetAnchorState(),e.resumeAutoScroll(),Q(),e.eventBus.emit(`history:cleared`,{deleted:i.deleted,scope:n,targetId:r,timestamp:Date.now()}),i},Pt=async()=>{if(!r?.resetDevice)throw Error(`[Persona] resetHistoryIdentity() requires a history provider that can reset this device`);let t=!1;try{t=(await e.session.resetHistoryDevice()).remoteRevocationConfirmed}finally{e.discardConversationContinuity(),X(),e.setActiveConversationSummary(null),e.session.clearArtifacts(),e.messageCache.clear(),e.lastAppliedMessages=null,e.config.clearStoredSessionId?.(),e.config.clearStoredConversationId?.(),e.persistentMetadata={},e.actionManager.syncFromMetadata(),e.clearPersistedDraft();let t=e.storageAdapter;t?.clear&&e.runStorageMutation(()=>t.clear(),`[AgentWidget] Failed to clear storage adapter:`),e.resetAnchorState(),e.resumeAutoScroll(),Q(),q({restoreFocus:!1}),e.maybeFocusInput(),e.open||e.launcherSurfaceInstance?.launcher.element.focus()}return e.announceHistory(t?n.identityResetNotice:n.identityResetUnconfirmedNotice),e.eventBus.emit(`history:identityReset`,{remoteRevocationConfirmed:t,timestamp:Date.now()}),{remoteRevocationConfirmed:t}},Ft=()=>e.artifactSplitRoot?e.panel:e.container,It=async t=>{let n=await e.loadHistoryView().catch(()=>null);return typeof n?.showHistoryConfirm==`function`?n.showHistoryConfirm(t):window.confirm(`${t.title}\n\n${t.description}`)},Lt=async e=>await It({host:Ft(),title:n.deleteConversationConfirmTitle,description:n.deleteConversationConfirm,confirmLabel:n.deleteConversationConfirmLabel,cancelLabel:n.confirmCancelLabel})?(await Mt(e),`deleted`):`cancelled`,Rt=async()=>{let e=w()===`verified-user`;return await It({host:Ft(),title:n.clearHistoryConfirmTitle,description:e?n.clearHistoryVerifiedConfirm:n.clearHistoryConfirm,confirmLabel:n.clearHistoryConfirmLabel,cancelLabel:n.confirmCancelLabel})?(await Nt(),`cleared`):`cancelled`},zt=async()=>{if(!await It({host:Ft(),title:n.resetIdentityConfirmTitle,description:n.resetIdentityConfirm,confirmLabel:n.resetIdentityConfirmLabel,cancelLabel:n.confirmCancelLabel}))return{outcome:`cancelled`};let{remoteRevocationConfirmed:e}=await Pt();return{outcome:`reset`,remoteRevocationConfirmed:e}},Z=u(`button`,`persona-history-earlier`);Z.type=`button`,Z.textContent=n.showEarlierMessagesLabel,Z.setAttribute(`data-persona-history-earlier`,``),Object.assign(Z.style,{alignSelf:`center`,minHeight:`44px`,padding:`0 16px`,borderRadius:`999px`,border:`1px solid var(--persona-border, rgba(0,0,0,0.12))`,background:`transparent`,color:`inherit`,font:`inherit`,cursor:`pointer`,flexShrink:`0`});let Q=()=>{S()&&e.historySessionState.nextMessageCursor&&e.session.getActiveConversationId()?(Z.textContent=n.showEarlierMessagesLabel,Z.parentNode!==e.body&&e.body.insertBefore(Z,e.body.firstChild)):Z.remove()};Z.addEventListener(`click`,()=>{let t=e.session.getActiveConversationId(),n=e.historySessionState.nextMessageCursor;if(!t||!n||Z.disabled)return;Z.disabled=!0;let r=e.body.scrollHeight,i=e.body.scrollTop;e.session.loadOlderMessages(t,n,{scope:w()}).then(()=>{e.body.scrollTop=i+(e.body.scrollHeight-r),e.repinAnchoredMessage()}).catch(()=>{}).finally(()=>{Z.disabled=!1,Q()})});let Bt=()=>{let t=e.createHeaderIconButton({ariaLabel:n.openHistoryLabel,iconName:`history`,wrapperClassName:`persona-relative persona-inline-flex persona-items-center persona-justify-center`,extraClassName:`persona-history-toggle`,attrs:{"data-persona-history-toggle":``}});return t.button.addEventListener(`click`,n=>{S()&&!C()&&(e.historyVisible?q():gt({invoker:t.button,keyboard:n.detail===0}))}),t},Vt=()=>{if(!S()){h?.remove(),m=null,h=null;return}if(h&&!h.isConnected&&(m=null,h=null),!m&&e.header){let t=Bt();m=t.button,h=t.wrapper;let n=e.panelElements.clearChatButtonWrapper||e.panelElements.closeButtonWrapper;n?.parentNode&&e.header.contains(n)?n.parentNode.insertBefore(h,n):e.header.appendChild(h)}if(!m||!h)return;let t=W()||e.historyVisible&&e.historyPresentation===`rail`;if(h.style.display=t?`none`:``,t){document.activeElement===m&&ht();return}let r=C();m.disabled=r,m.setAttribute(`aria-disabled`,r?`true`:`false`);let i=r?n.openHistoryBusyLabel:n.openHistoryLabel;m.setAttribute(`aria-label`,i),(e.config.features?.history?.presentation??`panel`)===`panel`?(m.removeAttribute(`aria-expanded`),m.removeAttribute(`aria-controls`)):(m.setAttribute(`aria-expanded`,e.historyVisible?`true`:`false`),m.setAttribute(`aria-controls`,x))},Ht=!1,Ut=()=>{let t=e.panelElements.clearChatButton;t&&(S()?(Ht||=(v=t.getAttribute(`aria-label`)??``,!0),t.setAttribute(`aria-label`,n.newConversationLabel),t.removeAttribute(`title`)):Ht&&(Ht=!1,v&&t.setAttribute(`aria-label`,v)))},$=()=>{n=i(e.config.features?.history?.copy),Vt(),et(),Ut(),Q()};return e.historyChromeSync=$,se(),$(),e.destroyCallbacks.push(()=>{y?.(),b?.(),_+=1,_t(),o?.dispose(),o?.view.destroy(),o=null}),{clearConversationOpenPending:X,cancelConversationOpenTakeover:Y,historyOperationScope:w,discardConversationContinuity:e.discardConversationContinuity,historyAvailable:S,historyScope:ee,installHistoryProvider:se,syncHistoryChromeImpl:$,syncHistoryPresentation:pt,syncEarlierMessagesPill:Q,openHistory:gt,closeHistory:q,openHistoryConversation:kt,startNewConversation:At,updateHistoryConversation:jt,deleteHistoryConversation:Mt,requestDeleteConversation:Lt,clearConversationHistory:Nt,resetHistoryIdentity:Pt,railCollapseShortcut:ze,railCollapsible:we,railTriggerApplies:W,railOverlayMode:ke,toggleRailCollapsed:Re,toggleRailPinned:()=>Le(),get historyProvider(){return r},get historySurface(){return o},get railShell(){return A},get railHost(){return j},get railColumn(){return Se}}};exports.createHistoryShell=oe;
|
package/dist/history-shell.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as applyBubbleGeometry, u as getBubbleClasses } from "./message-bubble-
|
|
3
|
-
import { Ct as AttachmentManager, h as PanelElements, i as SessionHistoryState, nn as HistoryClientError, r as SessionHistoryError, t as AgentWidgetSession, vt as isDockedMountMode } from "./session-
|
|
4
|
-
import { p as resolveThemeDefaults } from "./defaults-
|
|
1
|
+
import { Ct as AgentWidgetMessage, Go as ariaCombo, Hi as ResolvedHistoryPresentation, Ko as formatCombo, Ra as HistoryProvider, Ro as AgentWidgetPlugin, Ta as WidgetHistoryInternals, di as HistoryReturnSurface, fi as HistoryScope, ja as renderLucideIcon, k as AgentWidgetConfig, oi as HistoryConversationPatch, on as AgentWidgetStorageAdapter, q as AgentWidgetControllerEventMap, qo as parseCombo, si as HistoryConversationSummary, za as HistoryProviderError } from "./types-B_mj21jg.cjs";
|
|
2
|
+
import { a as applyBubbleGeometry, u as getBubbleClasses } from "./message-bubble-CBYtpDsT.cjs";
|
|
3
|
+
import { Ct as AttachmentManager, h as PanelElements, i as SessionHistoryState, nn as HistoryClientError, r as SessionHistoryError, t as AgentWidgetSession, vt as isDockedMountMode } from "./session-Bys8_XuB.cjs";
|
|
4
|
+
import { p as resolveThemeDefaults } from "./defaults-BuOjqUAG.cjs";
|
|
5
5
|
import { r as attachTooltip } from "./tooltip-BkW-8MnD.cjs";
|
|
6
|
-
import { t as createComposerStore } from "./composer-store-
|
|
7
|
-
import { n as HistoryViewHandle, r as HistoryViewOptions, t as showHistoryConfirm } from "./history-confirm-dialog-
|
|
6
|
+
import { t as createComposerStore } from "./composer-store-6Iwy6WLI.cjs";
|
|
7
|
+
import { n as HistoryViewHandle, r as HistoryViewOptions, t as showHistoryConfirm } from "./history-confirm-dialog-B3L7QNcO.cjs";
|
|
8
8
|
//#region src/components/launcher.d.ts
|
|
9
9
|
interface LauncherButton {
|
|
10
10
|
element: HTMLButtonElement;
|
package/dist/history-shell.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as applyBubbleGeometry, u as getBubbleClasses } from "./message-bubble-
|
|
3
|
-
import { Ct as AttachmentManager, h as PanelElements, i as SessionHistoryState, nn as HistoryClientError, r as SessionHistoryError, t as AgentWidgetSession, vt as isDockedMountMode } from "./session-
|
|
4
|
-
import { p as resolveThemeDefaults } from "./defaults-
|
|
1
|
+
import { Ct as AgentWidgetMessage, Go as ariaCombo, Hi as ResolvedHistoryPresentation, Ko as formatCombo, Ra as HistoryProvider, Ro as AgentWidgetPlugin, Ta as WidgetHistoryInternals, di as HistoryReturnSurface, fi as HistoryScope, ja as renderLucideIcon, k as AgentWidgetConfig, oi as HistoryConversationPatch, on as AgentWidgetStorageAdapter, q as AgentWidgetControllerEventMap, qo as parseCombo, si as HistoryConversationSummary, za as HistoryProviderError } from "./types-B_mj21jg.js";
|
|
2
|
+
import { a as applyBubbleGeometry, u as getBubbleClasses } from "./message-bubble-CBYtpDsT.js";
|
|
3
|
+
import { Ct as AttachmentManager, h as PanelElements, i as SessionHistoryState, nn as HistoryClientError, r as SessionHistoryError, t as AgentWidgetSession, vt as isDockedMountMode } from "./session-Bys8_XuB.js";
|
|
4
|
+
import { p as resolveThemeDefaults } from "./defaults-BuOjqUAG.js";
|
|
5
5
|
import { r as attachTooltip } from "./tooltip-BkW-8MnD.js";
|
|
6
|
-
import { t as createComposerStore } from "./composer-store-
|
|
7
|
-
import { n as HistoryViewHandle, r as HistoryViewOptions, t as showHistoryConfirm } from "./history-confirm-dialog-
|
|
6
|
+
import { t as createComposerStore } from "./composer-store-6Iwy6WLI.js";
|
|
7
|
+
import { n as HistoryViewHandle, r as HistoryViewOptions, t as showHistoryConfirm } from "./history-confirm-dialog-B3L7QNcO.js";
|
|
8
8
|
//#region src/components/launcher.d.ts
|
|
9
9
|
interface LauncherButton {
|
|
10
10
|
element: HTMLButtonElement;
|
package/dist/history-shell.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}};const t=e=>e?.layout?.embedded===!0&&e.launcher?.enabled===!1&&!e.launcher.sidebarMode&&(e.launcher.mountMode??`floating`)===`floating`,n=e=>e?.layout?.showHeader??!t(e);function r(e){if(!e)return a;let t={...a};for(let n of i){let r=e[n];typeof r==`string`&&r.length>0&&(t[n]=r)}return t}var i,a;e((()=>{i=/* @__PURE__ */ `viewTitle.openHistoryLabel.openHistoryBusyLabel.newConversationLabel.expandLabel.collapseLabel.resizeLabel.showEarlierMessagesLabel.openConversationLoadingLabel.openConversationErrorTitle.openConversationRetryLabel.openConversationBackLabel.confirmCancelLabel.deleteConversationConfirmTitle.deleteConversationConfirm.deleteConversationConfirmLabel.clearHistoryConfirmTitle.clearHistoryConfirm.clearHistoryVerifiedConfirm.clearHistoryConfirmLabel.resetIdentityConfirmTitle.resetIdentityConfirm.resetIdentityConfirmLabel.conversationDeletedNotice.identityResetNotice.identityResetUnconfirmedNotice`.split(`.`),a={viewTitle:`Messages`,openHistoryLabel:`Messages`,openHistoryBusyLabel:`Messages, available once the reply finishes`,newConversationLabel:`New conversation`,expandLabel:`Expand conversation list`,collapseLabel:`Collapse conversation list`,resizeLabel:`Resize conversation list`,showEarlierMessagesLabel:`Show earlier messages`,openConversationLoadingLabel:`Loading conversation`,openConversationErrorTitle:`Could not open the conversation.`,openConversationRetryLabel:`Try again`,openConversationBackLabel:`Back to messages`,confirmCancelLabel:`Cancel`,deleteConversationConfirmTitle:`Delete conversation`,deleteConversationConfirm:`Delete this conversation? This cannot be undone.`,deleteConversationConfirmLabel:`Delete`,clearHistoryConfirmTitle:`Delete all conversations`,clearHistoryConfirm:`Delete all conversations for this assistant on this browser? This cannot be undone.`,clearHistoryVerifiedConfirm:`Delete all conversations for this assistant and signed-in user? This cannot be undone.`,clearHistoryConfirmLabel:`Delete all`,resetIdentityConfirmTitle:`Forget this device`,resetIdentityConfirm:`Forget this device? All Persona data stored in this browser is cleared. Records are not deleted elsewhere.`,resetIdentityConfirmLabel:`Forget this device`,conversationDeletedNotice:`That conversation was deleted. You are now in a new conversation.`,identityResetNotice:`This device was forgotten.`,identityResetUnconfirmedNotice:`This device was cleared here, but the server could not confirm it.`}}))();const o=(e,t)=>{console.warn(`[persona] ${e} threw`,t)},s=e=>Object.freeze({...e}),c=e=>Object.freeze({id:e.id,title:e.title,targetId:e.targetId,preview:e.preview,messageCount:e.messageCount,createdAt:e.createdAt,updatedAt:e.updatedAt}),l=e=>e?s(e):null;function u(e){let{plugins:t,config:n}=e,r=!1,i=!1,a=!1,u=!1,d=null,f=[],p=()=>{for(let e of f.splice(0))try{e()}catch(e){o(`renderHistoryView cleanup`,e)}},m=(e,n)=>{for(let r of t){let t=r[e];if(t)try{let e=t(n);if(e)return e}catch(t){o(e,t)}}return null},h=()=>({presentation:e.getPresentation(),config:n}),g={header:t=>u?m(`renderHistoryHeader`,Object.freeze({...h(),returnSurface:e.getReturnSurface(),identityStatus:s(t.identityStatus),pendingAction:l(t.pendingAction),copy:s(t.copy),actions:Object.freeze({close:y.close,startNewConversation:y.startNewConversation}),defaultRenderer:t.defaultRenderer})):null,conversation:e=>u?m(`renderHistoryConversation`,Object.freeze({...h(),conversation:c(e.conversation),active:e.active,pending:e.pending,open:e.open,requestDelete:e.requestDelete,defaultRenderer:e.defaultRenderer})):null,state:e=>u?m(`renderHistoryState`,Object.freeze({...h(),state:s(e.state),identityStatus:s(e.identityStatus),copy:s(e.copy),...e.retry?{retry:e.retry}:{},...e.startNewConversation?{startNewConversation:e.startNewConversation}:{},defaultRenderer:e.defaultRenderer})):null},_=t.flatMap(t=>(t.railSections??[]).map(t=>({...t,placement:t.placement??`above-conversations`,items:[],render:n=>t.render(Object.freeze({collapsed:n,presentation:e.getPresentation(),actions:y}))}))),v=e.createView({slots:g,renderDom:!1,onModelChange:()=>C(),railSections:_}),y=Object.freeze({...v.operations,close:e.close}),b=()=>(u=!0,v.setDomRenderEnabled(!0),v.element),x=t=>Object.freeze({conversations:Object.freeze(t.conversations.map(c)),activeConversationId:t.activeConversationId,state:s(t.state),pendingAction:l(t.pendingAction),identityStatus:s(t.identityStatus),nextCursor:t.nextCursor,presentation:e.getPresentation(),returnSurface:e.getReturnSurface(),config:n,copy:s(v.copy),actions:y,defaultRenderer:b,requestRender:()=>C(),onCleanup:e=>{f.push(e)}}),S=()=>{u=!1;let e=null;for(let n of t)if(n.renderHistoryView){try{e=n.renderHistoryView(x(v.getModel()))}catch(t){o(`renderHistoryView`,t),e=null}if(e)break}let n=!e||e.contains(v.element);return u=n,v.setDomRenderEnabled(n),e??v.element};function C(){if(!(!a||r||i)){i=!0;try{p();let t=S();if(t===d)return;let n=d;d=t,e.onElementChanged(t,n)}finally{i=!1}}}return a=!0,C(),{view:v,get element(){return d??v.element},requestRender:C,dispose:()=>{r=!0,p()}}}var d,f,p,m=e((()=>{d=(e,t)=>{let n=document.createElement(e);return t&&(n.className=t),n},f=(e,t={},...n)=>{let r=document.createElement(e);if(t.className&&(r.className=t.className),t.text!==void 0&&(r.textContent=t.text),t.attrs)for(let[e,n]of Object.entries(t.attrs))r.setAttribute(e,n);if(t.style){let e=r.style,n=t.style;for(let t of Object.keys(n)){let r=n[t];r!=null&&(e[t]=r)}}let i=n.filter(e=>e!=null);return i.length>0&&r.append(...i),r},p=(...e)=>e.filter(Boolean).join(` `)})),h,g=e((()=>{h=100001}));function _(e){return typeof e==`string`?e:e.filter(e=>e.type===`text`).map(e=>e.text).join(``)}function v(e){return typeof e!=`string`&&e.some(e=>e.type===`image`)}function y(e){return{type:`text`,text:e}}function b(e,t){return{type:`image`,image:e,...t?.mimeType&&{mimeType:t.mimeType},...t?.alt&&{alt:t.alt}}}function x(e,t,n){return{type:`file`,data:e,mimeType:t,filename:n}}var S,C,ee=e((()=>{S=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`image/svg+xml`,`image/bmp`],C=[`application/pdf`,`text/plain`,`text/markdown`,`text/csv`,`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/json`],[...S,...C]}));function w(e){if(typeof e!=`string`||e===``)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function T(e){return typeof e==`string`?e:void 0}function te(e){if(typeof e!=`object`||!e)return null;let t=e;switch(t.type){case`text`:return typeof t.text==`string`?y(t.text):null;case`image`:return typeof t.image==`string`?b(t.image,{mimeType:T(t.mimeType),alt:T(t.alt)}):null;case`file`:return typeof t.data==`string`&&typeof t.mimeType==`string`&&typeof t.filename==`string`?x(t.data,t.mimeType,t.filename):null;case`audio`:return typeof t.audio==`string`?{type:`audio`,audio:t.audio,...T(t.mimeType)!==void 0&&{mimeType:t.mimeType}}:null;case`video`:return typeof t.video==`string`?{type:`video`,video:t.video,...T(t.mimeType)!==void 0&&{mimeType:t.mimeType}}:null;default:return null}}function ne(e,t){let n=w(t),r=e.map(e=>w(e.timestamp)),i=Array(e.length),a=0;for(;a<r.length;){let e=r[a];if(e!==null){i[a]=e,a+=1;continue}let t=a;for(;t+1<r.length&&r[t+1]===null;)t+=1;let o=t-a+1,s=a>0?i[a-1]:null,c=t+1<r.length?r[t+1]:null,l=c!==null&&n!==null?Math.min(c,n):c??n;for(let e=0;e<o;e+=1)i[a+e]=l===null?s===null?oe+e:s+e+1:l-(o-e);a=t+1}return i.map(e=>new Date(e).toISOString())}function re(e,t){let n=ne(e,t?.beforeCreatedAt),r=[];return e.forEach((e,t)=>{if(typeof e?.id!=`string`||e.id===``||!ae.includes(e.role))return;let i=e.role,a=n[t];if(e.displayAvailable===!1)r.push({id:e.id,role:i,content:``,createdAt:a,agentMetadata:{historyDisplayUnavailable:!0}});else if(typeof e.displayContent==`string`)r.push({id:e.id,role:i,content:e.displayContent,createdAt:a});else if(typeof e.content==`string`)r.push({id:e.id,role:i,content:e.content,createdAt:a});else if(Array.isArray(e.content)){let t=e.content.map(te).filter(e=>e!==null),n=_(t);r.push({id:e.id,role:i,content:n||(v(t)?`[Image]`:``),createdAt:a,...t.length>0&&{contentParts:t}})}else r.push({id:e.id,role:i,content:``,createdAt:a})}),r}function ie(e,t){let n=/* @__PURE__ */ new Map;for(let t of e)n.set(t.id,t);for(let e of t)n.set(e.id,e);return[...n.values()].sort((e,t)=>{let n=new Date(e.createdAt).getTime(),r=new Date(t.createdAt).getTime();if(!Number.isNaN(n)&&!Number.isNaN(r)&&n!==r)return n-r;let i=e.sequence??0,a=t.sequence??0;return i===a?e.id.localeCompare(t.id):i-a})}var ae,oe,se=e((()=>{ee(),ae=[`user`,`assistant`,`system`],oe=0}));m(),g(),se();const ce=/* @__PURE__ */ new Map([[`not_found`,`not_found`],[`conversation_deleted`,`not_found`],[`rate_limited`,`rate_limited`],[`authentication_required`,`authentication_required`],[`invalid_identity_proof`,`authentication_required`],[`visitor_identity_mismatch`,`authentication_required`],[`visitor_required`,`authentication_required`],[`identity_provider_failed`,`identity_provider_failed`],[`proof_not_admitted`,`proof_not_admitted`],[`identity_contract_violation`,`proof_not_admitted`],[`unauthorized`,`authentication_failed`],[`visitor_token_missing`,`authentication_failed`],[`conversation_credential_missing`,`authentication_failed`]]),E=/* @__PURE__ */ new Map([[`not_found`,`That conversation is no longer available.`],[`rate_limited`,`Too many history requests.`],[`authentication_failed`,`History access was not authorized.`],[`authentication_required`,`Sign in again to view account history.`],[`identity_provider_failed`,`The identity provider did not respond.`],[`proof_not_admitted`,`Account history is not available for this configuration.`],[`unsupported_scope`,`This history scope is not supported.`],[`unavailable`,`Conversation history is unavailable right now.`]]),D=e=>E.get(e)??`Conversation history is unavailable right now.`;function O(e,{HistoryClientError:t,HistoryProviderError:n}){if(e instanceof n)return e;if(e instanceof t){let t=ce.get(e.code)??`unavailable`;return new n(t,D(t),{...e.retryAfterSeconds===void 0?{}:{retryAfterSeconds:e.retryAfterSeconds}})}return new n(`unavailable`,D(`unavailable`))}function le(e){let{HistoryProviderError:t}=e.errors,n=()=>e.getClient?.()??e.client,r=e.getIdentityProofConfigured()?[`browser`,`verified-user`]:[`browser`],i={scopes:r},a=e=>{if(!r.includes(e))throw new t(`unsupported_scope`,D(`unsupported_scope`))},o=async(t,n)=>{a(t);try{return await n()}catch(t){throw O(t,e.errors)}},s=t=>{let n=!1;return{conversationId:t.session.conversationId??``,conversationRevision:t.session.conversationRevision??``,async commit(){n||(n=!0,t.commit(),await e.onActivationCommitted(t.session))},discard(){n||(n=!0,t.discard())}}};return{capabilities:i,getIdentityStatus(){return n().getHistoryIdentityStatus()},subscribeIdentityStatus(e){return n().subscribeHistoryIdentityStatus(e)},subscribeAvailability(e){return n().subscribeHistoryAvailability(e)},async list(e){return o(e.context.scope,async()=>{let t=await n().listConversations({...e.cursor?{cursor:e.cursor}:{},...e.limit===void 0?{}:{limit:e.limit},...e.targetId?{targetId:e.targetId}:{},scope:e.context.scope});return{items:t.data,nextCursor:t.nextCursor}})},async getPage(e,t){return o(t.context.scope,async()=>{let r=await n().getConversation(e,{...t.cursor?{messageCursor:t.cursor}:{},scope:t.context.scope}),i=re(r.messages,{...t.beforeCreatedAt?{beforeCreatedAt:t.beforeCreatedAt}:{}});return{summary:r.summary,messages:ie([],i),conversationRevision:r.conversationRevision??``,nextCursor:r.nextMessageCursor}})},async prepareOpen(e,t){return o(t.context.scope,async()=>s(await n().prepareConversationSession(e)))},async prepareStartNew(e){return o(e.context.scope,async()=>s(await n().prepareNewConversationSession()))},async delete(e,t){await o(t.context.scope,()=>n().deleteConversation(e,{scope:t.context.scope}))},async deleteAll(e){return o(e.context.scope,()=>n().deleteAllConversations({...e.targetId===void 0?{}:{targetId:e.targetId},scope:e.context.scope}))},async resetDevice(){try{return await n().resetVisitor(),{remoteRevocationConfirmed:!0}}catch{return{remoteRevocationConfirmed:!1}}}}}const k=e=>{let t=r(e.config.features?.history?.copy),i=null,a=!1,o=null,s=null,c=`conversation`,l=null,m=null,g=null,_=null,v=0,y=null,b=null,x=null,S=`persona-history-${Math.random().toString(36).slice(2,8)}`,C=()=>e.historyFeatureEnabled()&&!!i&&!a,ee=()=>{let t=e.session.getStatus();return e.isStreaming||t===`paused`||t===`resuming`},w=()=>{let t=e.config.features?.history?.scope;if(t)return t;let n=e.config.getIdentityProof?`verified-user`:`browser`,r=i?.capabilities.scopes;return!r||r.includes(n)?n:r[0]??n},T=()=>s?.scope??w(),te=()=>e.session.getClientSession()?.targetId??null,ne=e=>`${e.state}:${`reason`in e?e.reason:``}`,re=t=>{let n=ne(t);n!==_&&(_=n,e.eventBus.emit(`history:identityStatusChanged`,{status:t,timestamp:Date.now()}))},ie=null,ae=null,oe=()=>{if(!e.historyFeatureEnabled())return null;let t=e.getHistoryProviderFactory();if(t)return t();let n=e.config.features?.history?.provider;return n?typeof n==`function`?(ie!==n&&(ie=n,ae=n()),ae):n:e.session.isClientTokenMode()?le({errors:e.historyErrors,client:e.session.getClient(),getIdentityProofConfigured:()=>typeof e.config.getIdentityProof==`function`,onActivationCommitted:t=>e.session.bindActivatedSession(t),getClient:()=>e.session.getClient()}):null},se=()=>{b?.(),b=null,x?.(),x=null,a=!1;let t=i;i=oe(),t&&t!==i&&e.discardConversationContinuity();let n={...e.historyInternals};i?n.historyProvider=i:delete n.historyProvider,e.historyInternals=n,e.session.setHistoryInternals(e.historyInternals),i&&(b=i.subscribeAvailability?.(e=>{a=!e,e||q({restoreFocus:!1}),$()})??null,x=i.subscribeIdentityStatus(e=>re(e)),_=ne(i.getIdentityStatus()))},ce=()=>{let t=e.config.features?.history?.presentation??`panel`;if(t===`panel`||t===`auto`&&e.launcherEnabled&&!e.isDockedMountMode(e.config))return`panel`;let n=e.artifactSplitRoot??e.container;return(n.getBoundingClientRect().width||n.clientWidth)>=720?`rail`:`panel`},E=(e,t)=>{t?(e.setAttribute(`aria-hidden`,`true`),e.setAttribute(`inert`,``)):(e.removeAttribute(`aria-hidden`),e.removeAttribute(`inert`))},D=`data-persona-history-suppressed`,O=null,k=null,A=null,ue=null,de=null,fe=``,pe=()=>e.header===de?fe:n(e.config)?``:`none`,me=()=>e.historyPresentation===`panel`&&!!A&&ue===A.element&&n(e.config)&&pe()!==`none`,he=()=>{for(let t of Array.from(e.header.children))t!==O&&t.setAttribute(D,``)},ge=()=>{for(let t of Array.from(e.container.querySelectorAll(`[${D}]`)))t.removeAttribute(D)},_e=()=>{let t=A;if(!t)return;if(Array.from(e.header.children).some(e=>e!==O&&!e.hasAttribute(D))){k&&k!==e.header&&(k.style.removeProperty(`min-height`),k=null);let t=e.header.offsetHeight;t>0&&(e.header.style.minHeight=`${t}px`,k=e.header)}O||=d(`div`,`persona-history-header-host`),t.setHeaderPlacement(`external`);let n=t.getHeaderElement();n.parentNode!==O&&O.replaceChildren(n),O.parentNode!==e.header&&e.header.appendChild(O),he()},ve=()=>{k&&=(k.style.removeProperty(`min-height`),null),O&&(A?.setHeaderPlacement(`inline`),O.remove(),O=null,ge())},ye=null,be=()=>{ye&&(e.body.style.display=`none`,E(e.body,!0),e.footer.hidden=!0,E(e.footer,!0),e.panelSuggestions.style.display=`none`,E(e.panelSuggestions,!0),e.panelSuggestionsFade.style.display=`none`,me()?(_e(),e.header.style.display=pe(),E(e.header,!1)):(ve(),e.header.style.display=`none`,E(e.header,!0)))};e.reapplyHistoryHostChrome=be;let xe=t=>{let r=e.body.style.display,i=e.footer.hidden,a=e.panelSuggestions.style.display,o=e.panelSuggestionsFade.style.display,s=e.footer,c=e.header,l=e.header.style.display;de=c,fe=l,ye=()=>{ye=null,ve(),de=null,e.body.style.display=r,E(e.body,!1),e.panelSuggestions.style.display=a,E(e.panelSuggestions,!1),e.panelSuggestionsFade.style.display=o,s.hidden=i,E(s,!1),e.footer!==s&&(e.footer.hidden=!1,E(e.footer,!1)),c.style.display=l,E(c,!1),e.header!==c&&(e.header.style.display=n(e.config)?``:`none`,E(e.header,!1))},e.container.insertBefore(t,e.footer.parentNode===e.container?e.footer:e.panelSuggestions),be()},j=null,M=null,Se=null,N=null,Ce=()=>[e.header,e.panelElements.closeButtonWrapper,e.panelElements.clearChatButtonWrapper,e.body,e.footer,e.scrollToBottomButton],we=()=>e.config.features?.history?.rail?.collapsible!==!1,P=()=>e.config.features?.history?.rail?.side===`right`?`right`:`left`,Te=e=>Math.min(400,Math.max(200,Math.round(e))),Ee=()=>e.config.features?.history?.rail?.resizable===!0,F,De=()=>{if(F===void 0&&(F=null,e.config.persistState!==!1))try{let t=Number(window.localStorage.getItem(`${e.currentKeyPrefix()}rail-width`));t&&(F=t)}catch{}return F},I=()=>Te(De()??e.config.features?.history?.rail?.width??260),Oe=t=>{if(F=t,e.config.persistState!==!1)try{window.localStorage.setItem(`${e.currentKeyPrefix()}rail-width`,String(t))}catch{}},ke=()=>we()&&e.config.features?.history?.rail?.collapsedBehavior===`overlay`,L=!1,Ae=e=>{let t=d(`img`);return t.src=e,t.alt=``,t.setAttribute(`aria-hidden`,`true`),t},je=()=>{let t=e.config.features?.history?.rail?.brand;if(!t)return;let n=!1,r;return i=>{if(t.render)try{return t.render({collapsed:i})??null}catch(e){return n||(n=!0,console.warn(`[persona] history rail brand threw`,e)),null}return r===void 0&&(r=t.iconUrl?Ae(t.iconUrl):t.icon?e.renderLucideIcon(t.icon,20):null),r?r.cloneNode(!0):null}},Me=()=>e.config.features?.history?.rail?.sections?.map(t=>{let n=!1,r=e=>{n||(n=!0,console.warn(`[persona] history rail section threw`,t.id,e))};return{id:t.id,title:t.title,placement:t.placement??`above-conversations`,items:t.items.map(t=>{let n;return{id:t.id,label:t.label,badge:t.badge,iconNode:()=>{if(n!==void 0)return n;try{n=t.renderIcon?t.renderIcon()??null:t.iconUrl?Ae(t.iconUrl):t.icon?e.renderLucideIcon(t.icon,20):null}catch(e){r(e),n=null}return n},onSelect:()=>{try{t.onSelect()}catch(e){r(e)}}}})}})??[],Ne=e=>{let t=Me();for(let n of e)t.some(e=>e.id===n.id)?console.warn(`[persona] duplicate history rail section id`,n.id):t.push(n);return t.length?t:void 0},R=null,Pe=()=>`${e.currentKeyPrefix()}rail-collapsed`,Fe=()=>{if(R===null&&(R=e.config.features?.history?.rail?.defaultCollapsed===!0,e.config.persistState!==!1))try{let e=window.localStorage.getItem(Pe());e&&(R=e===`1`)}catch{}return R},Ie=t=>{if(R=t,e.config.persistState!==!1)try{window.localStorage.setItem(Pe(),t?`1`:`0`)}catch{}},z=()=>e.historyPresentation===`rail`&&we()&&!ke()&&Fe(),Le=()=>{},Re=()=>{ke()?Le():(Ie(!Fe()),o?.view.setCollapsed(z()),e.applyRailChrome(),e.repinAnchoredMessage())},ze=()=>{let t=e.config.features?.history?.rail?.collapseShortcut;return!t||!e.parseCombo(t)?null:{combo:t,hint:e.formatCombo(t),aria:e.ariaCombo(t)}},Be=`var(--persona-history-overlay-margin,8px)`,B=null,V=null,Ve=0,H=null,U=null,W=!1,He=0,Ue=()=>window.matchMedia?.(`(pointer: coarse)`).matches===!0,G=()=>C()&&ke()&&(e.historyPresentation??ce())===`rail`,We=()=>e.historyVisible&&!L,Ge=()=>{U!==null&&clearTimeout(U),U=null},Ke=()=>{e.loadHistoryView().catch(()=>{})},qe=()=>{Ge(),L&&(U=setTimeout(()=>{U=null,!W&&L&&(H?.contains(document.activeElement)||q({restoreFocus:!1}))},300))},Je=(e,t)=>{let n=H?.getBoundingClientRect();if(!n)return!1;let r=B?.getBoundingClientRect(),i=r?Math.min(r.top,n.top):n.top;return e>=n.left&&e<=n.right&&t>=i&&t<=n.bottom||!!r&&e>=r.left&&e<=r.right&&t>=r.top&&t<=r.bottom},Ye=e=>{L&&(W=Je(e.clientX,e.clientY),W?Ge():U===null&&qe())},Xe=t=>{!e.historyVisible&&G()&&(L=!0,_t({invoker:B,keyboard:t?.keyboard===!0}).then(()=>{e.historyVisible?!W&&document.activeElement!==B&&q():L=!1}))},Ze=()=>{let e=ue?.querySelector(`[data-persona-history-focus="collapse"]`);e&&(e.setAttribute(`aria-label`,L?t.expandLabel:t.collapseLabel),e.setAttribute(`aria-expanded`,L?`false`:`true`))},Qe=()=>{Ie(!1);let t=o;if(!L||!t){_t({invoker:B});return}let n=document.activeElement===B;L=!1,dt(),t.element.remove(),pt(t.element),Ze(),n&>(),e.repinAnchoredMessage(),$()},$e=()=>{Ie(!0),q()};Le=()=>{!e.historyVisible||L?Qe():$e()};let et=()=>{let n=ze(),r=e.createHeaderIconButton({ariaLabel:t.expandLabel,iconName:`panel-left`,wrapperClassName:`persona-relative persona-inline-flex persona-items-center persona-justify-center`,extraClassName:`persona-rail-trigger`,tooltip:!1,attrs:{"data-persona-rail-trigger":``,"aria-controls":S,...n?{"aria-keyshortcuts":n.aria}:{}}}),i=r.button;i.addEventListener(`mouseenter`,()=>{W=!0,Ge(),!(Ue()||Date.now()<He)&&Xe()}),i.addEventListener(`mouseleave`,()=>{W=!1,He=0,qe()}),i.addEventListener(`focus`,()=>{e.historyVisible||Ke()}),i.addEventListener(`click`,t=>{C()&&(t.detail!==0&&Ue()&&!e.historyVisible?Xe():Qe())}),B=i,V=r.wrapper},tt=()=>{if(V&&!V.isConnected&&(V=null,B=null),!G()){V?.remove(),V=null,B=null;return}B||et();let n=V,r=B;if(!n||!r)return;let i=P()===`right`?null:e.header.firstChild;(i??e.header.lastChild)!==n&&e.header.insertBefore(n,i),n.style.display=We()||Ve>0?`none`:``,r.setAttribute(`aria-label`,t.expandLabel),r.setAttribute(`aria-expanded`,e.historyVisible?`true`:`false`),H&&e.applyRailChrome()},nt=e=>{if(!L)return;let t=e.target;t instanceof Node&&(H?.contains(t)||V?.contains(t)||t instanceof Element&&t.closest(`.persona-dropdown-menu,[role="alertdialog"]`)||q({restoreFocus:!1}))};document.addEventListener(`pointerdown`,nt,!0),e.destroyCallbacks.push(()=>{document.removeEventListener(`pointerdown`,nt,!0),document.removeEventListener(`pointermove`,Ye),K?.(),Ge()});let rt=null,K=null,it=t=>{Oe(Te(t)),e.applyRailChrome(),e.repinAnchoredMessage()},at=()=>{let t=d(`div`,`persona-rail-resizer`);return t.tabIndex=0,t.setAttribute(`role`,`separator`),t.setAttribute(`aria-orientation`,`vertical`),t.setAttribute(`aria-valuemin`,`200`),t.setAttribute(`aria-valuemax`,`400`),t.addEventListener(`pointerdown`,n=>{let r=M;if(!r||n.button!==0)return;n.preventDefault(),K?.();let i=n.clientX,a=r.getBoundingClientRect().width||I(),o=P()===`right`?-1:1,s=a,c=e.mount.ownerDocument;r.style.transition=`none`;let l=e=>{s=Te(a+o*(e.clientX-i)),r.style.flex=`0 0 ${s}px`,t.setAttribute(`aria-valuenow`,String(s))},u=()=>{K=null,c.removeEventListener(`pointermove`,l),c.removeEventListener(`pointerup`,u),c.removeEventListener(`pointercancel`,u),r.style.removeProperty(`transition`);try{t.releasePointerCapture(n.pointerId)}catch{}it(s)};K=u,c.addEventListener(`pointermove`,l),c.addEventListener(`pointerup`,u),c.addEventListener(`pointercancel`,u);try{t.setPointerCapture(n.pointerId)}catch{}}),t.addEventListener(`keydown`,e=>{let t=P()===`right`?-16:16,n=I(),r=e.key===`ArrowRight`?n+t:e.key===`ArrowLeft`?n-t:e.key===`Home`?200:e.key===`End`?400:null;r!==null&&(e.preventDefault(),it(r))}),t},ot=(e,n)=>{if(!Ee()||z()){K?.(),rt?.remove();return}let r=rt??at();rt=r,r.setAttribute(`aria-label`,t.resizeLabel),r.setAttribute(`aria-valuenow`,String(I())),r.nextElementSibling!==n&&e.insertBefore(r,n)};e.applyRailChrome=()=>{o?.view.setRailSide(P());let t=P()===`right`,n=H;if(n){let r=B?B.getBoundingClientRect().bottom-e.container.getBoundingClientRect().top:0;n.style.top=`calc(${Math.max(0,Math.round(r))}px + ${Be})`,n.style.width=`${I()}px`,n.style.left=t?``:Be,n.style.right=t?Be:``}let r=M,i=j,a=Se;if(!r||!i||!a)return;r.style.flex=`0 0 ${z()?52:I()}px`;let s=`1px solid var(--persona-divider,#e5e7eb)`;r.style.borderRight=t?``:s,r.style.borderLeft=t?s:``;let c=t?a:r;i.firstElementChild!==c&&i.append(c,t?r:a),ot(i,t?r:a)};let st=t=>{if(N&&M){N.replaceWith(t),N=null,e.applyRailChrome();return}let n=d(`div`,`persona-history-rail-shell`);n.style.cssText=`display:flex;flex-direction:row;flex:1 1 auto;min-height:0`;let r=d(`div`,`persona-history-rail-conversation`);r.style.cssText=`display:flex;flex-direction:column;flex:1 1 auto;min-width:0;min-height:0;position:relative`;let i=d(`div`,`persona-history-rail-host`);i.style.cssText=`display:flex;min-height:0;overflow:hidden`,e.container.insertBefore(n,e.header.parentNode===e.container?e.header:e.body);for(let t of Ce())t?.parentNode===e.container&&r.appendChild(t);n.append(i,r),i.appendChild(t),j=n,M=i,Se=r,e.applyRailChrome()},ct=()=>{if(j)return;let t=d(`div`,`persona-history-rail-placeholder`);t.style.cssText=`flex:1 1 auto;min-height:0`,N=t,st(t),e.repinAnchoredMessage()},lt=()=>{N&&(dt(),e.repinAnchoredMessage())},ut=t=>{let n=d(`div`,`persona-history-rail-overlay`);n.style.cssText=`position:absolute;bottom:${Be};display:flex;overflow:hidden;z-index:${h-1};border-radius:var(--persona-history-overlay-radius,16px);background:var(--persona-history-overlay-bg,var(--persona-container,#f7f7f8));box-shadow:var(--persona-history-overlay-shadow,0 12px 40px rgba(0,0,0,0.25))`,e.container.style.position=`relative`,e.container.appendChild(n),n.appendChild(t),document.addEventListener(`pointermove`,Ye),H=n,e.applyRailChrome(),Ze()},dt=()=>{ye?.(),H&&=(W&&(He=Date.now()+150),document.removeEventListener(`pointermove`,Ye),H.remove(),null);let t=j;if(t){K?.();for(let n of Ce())if(n&&t.contains(n)){let r=n===e.scrollToBottomButton?e.panelSuggestions:t;e.container.insertBefore(n,r)}t.remove(),j=null,M=null,Se=null,N=null}},ft=e=>{ue=e,e.id=S,e.style.flex=`1 1 auto`,e.style.minHeight=`0`},pt=t=>{ft(t),(e.historyPresentation!==`rail`||L)&<(),e.historyPresentation===`rail`?L?ut(t):st(t):xe(t)},mt=()=>{if(tt(),Ht(),!e.historyVisible||!o)return;let t=ce();if(t===e.historyPresentation)return;let n=document.activeElement,r=n instanceof HTMLElement&&(o.element.contains(n)||O?.contains(n)===!0)?n:null;dt(),o.element.remove(),o.view.setHeaderPlacement(`inline`),e.historyPresentation=t,o.view.setPresentation(t),o.view.setCollapsed(z()),o.requestRender(),o.element.isConnected||pt(o.element),r?.isConnected?r.focus():gt(),e.syncScrollToBottomButton(),e.repinAnchoredMessage(),$()},ht=(e,t)=>O?.querySelector(t)??e.querySelector(t),gt=()=>{let e=o?.element??ue;if(!e)return;let t=ht(e,`[data-persona-history-focus="close"],[data-persona-history-focus="collapse"]`);if(t){t.focus();return}let n=ht(e,`.persona-history-title`)??e;n.tabIndex=-1,n.focus()},_t=async r=>{if(!C()||e.historyVisible)return;let a=i;if(!a)return;if(!L&&G()&&Fe()){tt();return}vt();let d=++v;c=r?.returnSurface??`conversation`,l=r?.invoker??m;let f=G()&&!L;f&&(Ve+=1,tt(),ct());let p;try{p=await e.loadHistoryView()}catch{e.announceHistory(t.openHistoryLabel),f&&(--Ve,d===v&&(lt(),tt()));return}if(f&&--Ve,d!==v||e.historyVisible)return;s={scope:w()},e.historyPresentation=ce(),e.historyVisible=!0;let h=e.historyPresentation===`panel`&&n(e.config)&&e.header.style.display!==`none`?`external`:`inline`,g=e.config.features?.history?.rowAvatar,_=ze(),y=_?{hint:_.hint,aria:_.aria}:null,b={provider:a,context:s,targetId:te(),presentation:e.historyPresentation,collapsible:we(),collapsed:z(),railSide:P(),renderRailHeader:e.config.features?.history?.rail?.renderHeader,railBrand:je(),onToggleCollapse:Re,...y?{collapseShortcut:y}:{},headerPlacement:h,showScopeStatus:e.config.features?.history?.showScopeStatus!==!1,showDelete:e.config.features?.history?.showDelete!==!1,showDeleteAll:e.config.features?.history?.showDeleteAll!==!1,...e.config.features?.history?.listActions?.length?{listActions:e.config.features.history.listActions}:{},rowAvatar:g===!1?!1:typeof g==`string`?g:e.config.launcher?.iconUrl,activeConversationId:e.session.getActiveConversationId(),...e.config.features?.history?.grouping?{grouping:e.config.features.history.grouping}:{},...e.config.features?.history?.copy?{copy:e.config.features.history.copy}:{},...e.config.features?.history?.pageSize===void 0?{}:{pageSize:e.config.features.history.pageSize},onSelect:e=>At(e,{focusComposer:!0}).catch(()=>{}),onActiveConversationChange:t=>e.setActiveConversationSummary(t),attachTooltip:e.attachTooltip,onStartNew:()=>jt({focusComposer:!0}),onClose:()=>q(),onRequestDeleteConversation:e=>Rt(e),onRequestClearHistory:()=>zt(),...a.resetDevice?{onRequestResetIdentity:()=>Bt()}:{}};o=u({plugins:e.plugins,config:e.config,getPresentation:()=>e.historyPresentation??`panel`,getReturnSurface:()=>c,close:()=>q(),createView:({slots:t,renderDom:n,onModelChange:r,railSections:i})=>(A=p.createHistoryView({...b,railSections:Ne(i),slots:t,renderDom:n,onModelChange:r,onAnnounce:e.announceHistory}),A),onElementChanged:(e,t)=>{if(!t?.isConnected)return pt(e);ft(e),t.replaceWith(e),be()}}),o.view.setNewConversationRequired(e.historySessionState.recovery===`new_conversation_required`),r?.focus!==!1&&(e.historyPresentation!==`rail`||r?.keyboard===!0)&>(),e.syncScrollToBottomButton(),e.repinAnchoredMessage(),$(),e.eventBus.emit(`history:opened`,{presentation:e.historyPresentation,returnSurface:c,timestamp:Date.now()})},vt=()=>{},q=t=>{if(!e.historyVisible)return;v+=1;let n=c,r=l,i=o,a=t?.restoreFocus!==!1;e.historyVisible=!1;let u=!1,d=null,f=()=>{if(!u){if(u=!0,vt=()=>{},d!==null&&clearTimeout(d),L=!1,Ge(),dt(),i?.dispose(),i?.view.destroy(),i?.element.remove(),o===i&&(o=null,A=null,ue=null,e.historyPresentation=null,s=null,l=null),e.syncScrollToBottomButton(),e.repinAnchoredMessage(),$(),a){let t=r??m;t?.isConnected?t.focus():e.maybeFocusInput()}e.eventBus.emit(`history:closed`,{returnSurface:n,timestamp:Date.now()})}},p=i&&i.element===i.view.element?i.view.playExit():null;p?(vt=f,d=setTimeout(f,250),p.then(f)):f()},yt=t=>{if(t.key===`Escape`&&e.historyVisible&&o){if(e.historyPresentation===`rail`){let e=t.target;if(!(e instanceof Node)||!(o.element.contains(e)||L&&V?.contains(e)===!0))return}t.preventDefault(),t.stopPropagation(),q()}};e.container.addEventListener(`keydown`,yt),e.destroyCallbacks.push(()=>e.container.removeEventListener(`keydown`,yt));let bt=0,J=null,xt=null,Y=()=>{xt&&clearTimeout(xt),xt=null};e.destroyCallbacks.push(Y);let St=()=>{Y();let t=e.conversationOpenPendingEl;t&&(e.conversationOpenTakeover=!0,t.hidden=!1,e.messagesWrapper.style.display=`none`,e.updateWelcome())},X=()=>{bt+=1,Y(),J?.remove(),J=null,e.conversationOpenPendingEl&&(e.conversationOpenPendingEl.remove(),e.conversationOpenPendingEl=null,e.conversationOpenTakeover=!1,e.messagesWrapper.style.removeProperty(`display`),E(e.footer,!1),e.updateWelcome())},Ct=()=>{try{if(window.matchMedia?.(`(prefers-reduced-motion: reduce)`)?.matches)return;e.messagesWrapper.animate([{opacity:0},{opacity:1}],{duration:150,easing:`ease-out`})}catch{}},wt=t=>{let n=e.config.layout?.messages?.layout??`bubble`,r=f(`div`,{className:`persona-flex`,attrs:{"aria-hidden":`true`}});e.applyMessageRowLayout(r,t);let i=f(`div`,{className:p(e.getBubbleClasses(t,n).join(` `),`persona-conversation-loading-bubble`),attrs:{"data-persona-theme-zone":`${t}-message`},style:{width:t===`user`?`64%`:`100%`,backgroundColor:n===`flat`?`transparent`:`var(--persona-message-${t}-bg, var(--persona-${t===`user`?`accent`:`container`}))`,color:`var(--persona-message-${t}-text, ${t===`user`&&n!==`flat`?`white`:`var(--persona-text)`})`}},...[`94%`,...t===`assistant`?[`86%`]:[],`62%`].map(e=>f(`div`,{className:`persona-conversation-loading-line`,style:{width:e}})));return e.applyBubbleGeometry(i,t,n,{...e.resolveThemeDefaults(e.config.future).components.message[t],...e.config.theme?.components?.message?.[t],...e.config.darkTheme?.components?.message?.[t]}),r.appendChild(i),r},Tt=()=>f(`div`,{className:`persona-conversation-loading-body`,style:{gap:e.messagesWrapper.style.gap}},wt(`user`),wt(`assistant`),wt(`user`),wt(`assistant`)),Et=()=>e.config.loadingIndicator?.conversationOpenVariant===`skeleton`?Tt():f(`div`,{className:`persona-conversation-loading-spinner`,attrs:{"aria-hidden":`true`}},f(`span`,{className:`persona-conversation-loading-ring`})),Dt=t=>{e.conversationOpenPendingEl?.remove(),e.conversationOpenPendingEl=t,t.hidden=!e.conversationOpenTakeover,e.body.insertBefore(t,e.messagesWrapper),Y(),e.conversationOpenTakeover||(xt=setTimeout(St,250)),E(e.footer,!0)},Ot=()=>{let n={config:e.config,streaming:!1,location:`conversation-open`,defaultRenderer:Et},r=null,i=e.plugins.find(e=>e.renderLoadingIndicator);i?.renderLoadingIndicator&&(r=i.renderLoadingIndicator(n)),r===null&&e.config.loadingIndicator?.render&&(r=e.config.loadingIndicator.render(n));let a=r??Et();Dt(f(`div`,{className:p(`persona-conversation-loading`,a.classList.contains(`persona-conversation-loading-spinner`)&&`persona-conversation-loading--centered`),attrs:{role:`status`,"aria-label":t.openConversationLoadingLabel},style:{maxWidth:e.messagesWrapper.style.maxWidth||`none`}},a))},kt=n=>{let r=()=>{At(n,{focusComposer:!0}).catch(()=>{})},i=C()?()=>{X(),_t()}:void 0,a=(e,t)=>{let n=f(`button`,{className:`persona-conversation-loading-error-action`,attrs:{type:`button`},text:e});return n.addEventListener(`click`,t),n},o=()=>f(`div`,{className:`persona-conversation-loading-error-body`},f(`p`,{className:`persona-conversation-loading-error-title`,text:t.openConversationErrorTitle}),f(`div`,{className:`persona-conversation-loading-error-actions`},a(t.openConversationRetryLabel,r),i?a(t.openConversationBackLabel,i):null)),s=Object.freeze({conversationId:n,config:e.config,copy:Object.freeze({title:t.openConversationErrorTitle,retryLabel:t.openConversationRetryLabel,backLabel:t.openConversationBackLabel}),retry:r,...i?{back:i}:{},defaultRenderer:o}),c=null;for(let t of e.plugins)if(t.renderHistoryOpenError){try{c=t.renderHistoryOpenError(s)}catch(e){console.warn(`[persona] renderHistoryOpenError threw`,e),c=null}if(c)break}if(J?.remove(),J=f(`div`,{className:`persona-conversation-loading-error`,attrs:{role:`alert`}},c??o()),!e.session.getActiveConversationId()&&e.session.getMessages().length===0&&!e.composerStore.getState().text&&!e.attachmentManager?.hasAttachments()){let e=J;J=null,Dt(e),St()}else e.body.insertBefore(J,e.messagesWrapper);e.announceHistory(t.openConversationErrorTitle)};e.eventBus.on(`history:closed`,()=>{e.conversationOpenPendingEl&&E(e.footer,!0)});let At=async(t,{focusComposer:n=!1,busy:r=`reject`}={})=>{let i=T();if(r===`background`&&(e.session.assertBackgroundSwitchable(),e.composerStore.getState().phase===`preparing`))throw new e.SessionHistoryError(`conversation_busy`,`Finish preparing this turn before switching conversations`);if(r===`reject`&&(e.session.isStreaming()||[`paused`,`resuming`].includes(e.session.getStatus())||e.composerStore.getState().phase===`preparing`))throw new e.SessionHistoryError(`conversation_busy`,`Finish or stop the current turn before switching conversations`);r===`stop`&&(++e.composerConversationGeneration,e.submissionAbort?.abort(),e.submissionAbort=null,e.composerStore.setPreparing(!1),e.session.cancel());let a=e.conversationStateKey();(!e.conversationOpenPendingEl||e.pendingConversationReading?.key!==a)&&(e.pendingConversationReading={key:a,reading:e.captureConversationReading()});let s=null,c=!!o;o?.view.setActiveConversationId(t),X();let l=bt;Ot(),e.historyVisible&&(e.historyPresentation===`panel`||L)&&q({restoreFocus:!1}),e.suppressScrollSend=!0;try{await e.session.openConversation(t,{scope:i,busy:r,onBeforeCommit:()=>{e.saveConversationContinuity(),s=e.composerConversationGeneration,e.conversationPersistenceOwner=s},onCommitted:()=>{e.restoreConversationContinuity(),e.conversationPersistenceOwner===s&&(e.conversationPersistenceOwner=null),e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),e.persistState()}})}catch(n){if(e.conversationPersistenceOwner===s&&(e.conversationPersistenceOwner=null),s===e.composerConversationGeneration&&e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),l===bt){let n=e.pendingConversationReading?.reading;X(),n&&e.restoreConversationReading(n),e.pendingConversationReading=null,o?.view.setActiveConversationId(e.session.getActiveConversationId()),kt(t),e.suppressScrollSend=!1}throw n}finally{(l===bt||!e.conversationOpenPendingEl)&&(e.suppressScrollSend=!1)}l===bt&&(X(),e.pendingConversationReading=null,e.messageCache.clear(),Ct(),Q(),c||e.setActiveConversationSummary(null),e.eventBus.emit(`history:conversationOpened`,{conversationId:t,title:e.activeConversationTitle,scope:i,timestamp:Date.now()}),n&&e.maybeFocusInput())},jt=async({focusComposer:t=!1}={})=>{X();let n=null;try{await e.session.startNewConversation({scope:T(),onBeforeCommit:()=>{e.saveConversationContinuity(),n=e.composerConversationGeneration,e.conversationPersistenceOwner=n},onCommitted:()=>{e.restoreConversationContinuity(!0),e.conversationPersistenceOwner===n&&(e.conversationPersistenceOwner=null),e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),e.persistState(),e.pendingConversationReading=null}})}catch(t){throw e.conversationPersistenceOwner===n&&(e.conversationPersistenceOwner=null),n===e.composerConversationGeneration&&e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),t}e.setActiveConversationSummary(null),e.messageCache.clear(),e.resetAnchorState(),e.resumeAutoScroll(),e.jumpToBottomInstant(),Q();let r=e.session.getActiveConversationId();o?.view.setActiveConversationId(r),e.eventBus.emit(`history:conversationStarted`,{conversationId:r,timestamp:Date.now()}),e.historyVisible&&(e.historyPresentation===`panel`||L)&&q({restoreFocus:!1}),t&&e.maybeFocusInput()},Mt=async(t,n)=>{let r=await e.session.updateConversation(t,{...n,...n.title===void 0?{}:{title:n.title.trim()}});return o?.view.applyConversationSummary(r),!o&&t===e.session.getActiveConversationId()&&e.setActiveConversationSummary(r),r},Nt=async t=>{let n=T(),r=e.session.getActiveConversationId()===t;await e.session.deleteConversation(t,{scope:n}),e.discardConversationContinuity(t),r&&(e.attachmentManager?.destroy({release:!0}),e.attachmentManager=null,e.restoreConversationContinuity(!0)),o?.view.removeConversationSummary(t),r&&(e.setActiveConversationSummary(null),e.messageCache.clear(),e.resetAnchorState(),e.resumeAutoScroll(),Q()),e.eventBus.emit(`history:conversationDeleted`,{conversationId:t,scope:n,wasActive:r,timestamp:Date.now()})},Pt=async t=>{let n=t?.scope??T(),r=t?.allTargets?null:t?.targetId??te(),i=await e.session.clearConversationHistory({...r?{targetId:r}:{},scope:n});return e.discardConversationContinuity(),e.setActiveConversationSummary(null),e.messageCache.clear(),e.resetAnchorState(),e.resumeAutoScroll(),Q(),e.eventBus.emit(`history:cleared`,{deleted:i.deleted,scope:n,targetId:r,timestamp:Date.now()}),i},Ft=async()=>{if(!i?.resetDevice)throw Error(`[Persona] resetHistoryIdentity() requires a history provider that can reset this device`);let n=!1;try{n=(await e.session.resetHistoryDevice()).remoteRevocationConfirmed}finally{e.discardConversationContinuity(),X(),e.setActiveConversationSummary(null),e.session.clearArtifacts(),e.messageCache.clear(),e.lastAppliedMessages=null,e.config.clearStoredSessionId?.(),e.config.clearStoredConversationId?.(),e.persistentMetadata={},e.actionManager.syncFromMetadata(),e.clearPersistedDraft();let t=e.storageAdapter;t?.clear&&e.runStorageMutation(()=>t.clear(),`[AgentWidget] Failed to clear storage adapter:`),e.resetAnchorState(),e.resumeAutoScroll(),Q(),q({restoreFocus:!1}),e.maybeFocusInput(),e.open||e.launcherSurfaceInstance?.launcher.element.focus()}return e.announceHistory(n?t.identityResetNotice:t.identityResetUnconfirmedNotice),e.eventBus.emit(`history:identityReset`,{remoteRevocationConfirmed:n,timestamp:Date.now()}),{remoteRevocationConfirmed:n}},It=()=>e.artifactSplitRoot?e.panel:e.container,Lt=async t=>{let n=await e.loadHistoryView().catch(()=>null);return typeof n?.showHistoryConfirm==`function`?n.showHistoryConfirm(t):window.confirm(`${t.title}\n\n${t.description}`)},Rt=async e=>await Lt({host:It(),title:t.deleteConversationConfirmTitle,description:t.deleteConversationConfirm,confirmLabel:t.deleteConversationConfirmLabel,cancelLabel:t.confirmCancelLabel})?(await Nt(e),`deleted`):`cancelled`,zt=async()=>{let e=T()===`verified-user`;return await Lt({host:It(),title:t.clearHistoryConfirmTitle,description:e?t.clearHistoryVerifiedConfirm:t.clearHistoryConfirm,confirmLabel:t.clearHistoryConfirmLabel,cancelLabel:t.confirmCancelLabel})?(await Pt(),`cleared`):`cancelled`},Bt=async()=>{if(!await Lt({host:It(),title:t.resetIdentityConfirmTitle,description:t.resetIdentityConfirm,confirmLabel:t.resetIdentityConfirmLabel,cancelLabel:t.confirmCancelLabel}))return{outcome:`cancelled`};let{remoteRevocationConfirmed:e}=await Ft();return{outcome:`reset`,remoteRevocationConfirmed:e}},Z=d(`button`,`persona-history-earlier`);Z.type=`button`,Z.textContent=t.showEarlierMessagesLabel,Z.setAttribute(`data-persona-history-earlier`,``),Object.assign(Z.style,{alignSelf:`center`,minHeight:`44px`,padding:`0 16px`,borderRadius:`999px`,border:`1px solid var(--persona-border, rgba(0,0,0,0.12))`,background:`transparent`,color:`inherit`,font:`inherit`,cursor:`pointer`,flexShrink:`0`});let Q=()=>{C()&&e.historySessionState.nextMessageCursor&&e.session.getActiveConversationId()?(Z.textContent=t.showEarlierMessagesLabel,Z.parentNode!==e.body&&e.body.insertBefore(Z,e.body.firstChild)):Z.remove()};Z.addEventListener(`click`,()=>{let t=e.session.getActiveConversationId(),n=e.historySessionState.nextMessageCursor;if(!t||!n||Z.disabled)return;Z.disabled=!0;let r=e.body.scrollHeight,i=e.body.scrollTop;e.session.loadOlderMessages(t,n,{scope:T()}).then(()=>{e.body.scrollTop=i+(e.body.scrollHeight-r),e.repinAnchoredMessage()}).catch(()=>{}).finally(()=>{Z.disabled=!1,Q()})});let Vt=()=>{let n=e.createHeaderIconButton({ariaLabel:t.openHistoryLabel,iconName:`history`,wrapperClassName:`persona-relative persona-inline-flex persona-items-center persona-justify-center`,extraClassName:`persona-history-toggle`,attrs:{"data-persona-history-toggle":``}});return n.button.addEventListener(`click`,t=>{C()&&!ee()&&(e.historyVisible?q():_t({invoker:n.button,keyboard:t.detail===0}))}),n},Ht=()=>{if(!C()){g?.remove(),m=null,g=null;return}if(g&&!g.isConnected&&(m=null,g=null),!m&&e.header){let t=Vt();m=t.button,g=t.wrapper;let n=e.panelElements.clearChatButtonWrapper||e.panelElements.closeButtonWrapper;n?.parentNode&&e.header.contains(n)?n.parentNode.insertBefore(g,n):e.header.appendChild(g)}if(!m||!g)return;let n=G()||e.historyVisible&&e.historyPresentation===`rail`;if(g.style.display=n?`none`:``,n){document.activeElement===m&>();return}let r=ee();m.disabled=r,m.setAttribute(`aria-disabled`,r?`true`:`false`);let i=r?t.openHistoryBusyLabel:t.openHistoryLabel;m.setAttribute(`aria-label`,i),(e.config.features?.history?.presentation??`panel`)===`panel`?(m.removeAttribute(`aria-expanded`),m.removeAttribute(`aria-controls`)):(m.setAttribute(`aria-expanded`,e.historyVisible?`true`:`false`),m.setAttribute(`aria-controls`,S))},Ut=!1,Wt=()=>{let n=e.panelElements.clearChatButton;n&&(C()?(Ut||=(y=n.getAttribute(`aria-label`)??``,!0),n.setAttribute(`aria-label`,t.newConversationLabel),n.removeAttribute(`title`)):Ut&&(Ut=!1,y&&n.setAttribute(`aria-label`,y)))},$=()=>{t=r(e.config.features?.history?.copy),Ht(),tt(),Wt(),Q()};return e.historyChromeSync=$,se(),$(),e.destroyCallbacks.push(()=>{b?.(),x?.(),v+=1,vt(),o?.dispose(),o?.view.destroy(),o=null}),{clearConversationOpenPending:X,cancelConversationOpenTakeover:Y,historyOperationScope:T,discardConversationContinuity:e.discardConversationContinuity,historyAvailable:C,historyScope:w,installHistoryProvider:se,syncHistoryChromeImpl:$,syncHistoryPresentation:mt,syncEarlierMessagesPill:Q,openHistory:_t,closeHistory:q,openHistoryConversation:At,startNewConversation:jt,updateHistoryConversation:Mt,deleteHistoryConversation:Nt,requestDeleteConversation:Rt,clearConversationHistory:Pt,resetHistoryIdentity:Ft,railCollapseShortcut:ze,railCollapsible:we,railTriggerApplies:G,railOverlayMode:ke,toggleRailCollapsed:Re,toggleRailPinned:()=>Le(),get historyProvider(){return i},get historySurface(){return o},get railShell(){return j},get railHost(){return M},get railColumn(){return Se}}};export{k as createHistoryShell};
|
|
1
|
+
var e=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}};const t=e=>e?.layout?.embedded===!0&&e.launcher?.enabled===!1&&!e.launcher.sidebarMode&&(e.launcher.mountMode??`floating`)===`floating`,n=e=>e?.layout?.showHeader??!t(e);function r(e){if(!e)return a;let t={...a};for(let n of i){let r=e[n];typeof r==`string`&&r.length>0&&(t[n]=r)}return t}var i,a;e((()=>{i=/* @__PURE__ */ `viewTitle.openHistoryLabel.openHistoryBusyLabel.newConversationLabel.expandLabel.collapseLabel.resizeLabel.showEarlierMessagesLabel.openConversationLoadingLabel.openConversationErrorTitle.openConversationRetryLabel.openConversationBackLabel.confirmCancelLabel.deleteConversationConfirmTitle.deleteConversationConfirm.deleteConversationConfirmLabel.clearHistoryConfirmTitle.clearHistoryConfirm.clearHistoryVerifiedConfirm.clearHistoryConfirmLabel.resetIdentityConfirmTitle.resetIdentityConfirm.resetIdentityConfirmLabel.conversationDeletedNotice.identityResetNotice.identityResetUnconfirmedNotice`.split(`.`),a={viewTitle:`Messages`,openHistoryLabel:`Messages`,openHistoryBusyLabel:`Messages, available once the reply finishes`,newConversationLabel:`New conversation`,expandLabel:`Expand conversation list`,collapseLabel:`Collapse conversation list`,resizeLabel:`Resize conversation list`,showEarlierMessagesLabel:`Show earlier messages`,openConversationLoadingLabel:`Loading conversation`,openConversationErrorTitle:`Could not open the conversation.`,openConversationRetryLabel:`Try again`,openConversationBackLabel:`Back to messages`,confirmCancelLabel:`Cancel`,deleteConversationConfirmTitle:`Delete conversation`,deleteConversationConfirm:`Delete this conversation? This cannot be undone.`,deleteConversationConfirmLabel:`Delete`,clearHistoryConfirmTitle:`Delete all conversations`,clearHistoryConfirm:`Delete all conversations for this assistant on this browser? This cannot be undone.`,clearHistoryVerifiedConfirm:`Delete all conversations for this assistant and signed-in user? This cannot be undone.`,clearHistoryConfirmLabel:`Delete all`,resetIdentityConfirmTitle:`Forget this device`,resetIdentityConfirm:`Forget this device? All Persona data stored in this browser is cleared. Records are not deleted elsewhere.`,resetIdentityConfirmLabel:`Forget this device`,conversationDeletedNotice:`That conversation was deleted. You are now in a new conversation.`,identityResetNotice:`This device was forgotten.`,identityResetUnconfirmedNotice:`This device was cleared here, but the server could not confirm it.`}}))();const o=(e,t)=>{console.warn(`[persona] ${e} threw`,t)},s=e=>Object.freeze({...e}),c=e=>Object.freeze({id:e.id,title:e.title,targetId:e.targetId,preview:e.preview,messageCount:e.messageCount,createdAt:e.createdAt,updatedAt:e.updatedAt}),l=e=>e?s(e):null;function u(e){let{plugins:t,config:n}=e,r=!1,i=!1,a=!1,u=!1,d=null,f=[],p=()=>{for(let e of f.splice(0))try{e()}catch(e){o(`renderHistoryView cleanup`,e)}},m=(e,n)=>{for(let r of t){let t=r[e];if(t)try{let e=t(n);if(e)return e}catch(t){o(e,t)}}return null},h=()=>({presentation:e.getPresentation(),config:n}),g={header:t=>u?m(`renderHistoryHeader`,Object.freeze({...h(),returnSurface:e.getReturnSurface(),identityStatus:s(t.identityStatus),pendingAction:l(t.pendingAction),copy:s(t.copy),actions:Object.freeze({close:y.close,startNewConversation:y.startNewConversation}),defaultRenderer:t.defaultRenderer})):null,conversation:e=>u?m(`renderHistoryConversation`,Object.freeze({...h(),conversation:c(e.conversation),active:e.active,pending:e.pending,open:e.open,requestDelete:e.requestDelete,defaultRenderer:e.defaultRenderer})):null,state:e=>u?m(`renderHistoryState`,Object.freeze({...h(),state:s(e.state),identityStatus:s(e.identityStatus),copy:s(e.copy),...e.retry?{retry:e.retry}:{},...e.startNewConversation?{startNewConversation:e.startNewConversation}:{},defaultRenderer:e.defaultRenderer})):null},_=t.flatMap(t=>(t.railSections??[]).map(t=>({...t,placement:t.placement??`above-conversations`,items:[],render:n=>t.render(Object.freeze({collapsed:n,presentation:e.getPresentation(),actions:y}))}))),v=e.createView({slots:g,renderDom:!1,onModelChange:()=>C(),railSections:_}),y=Object.freeze({...v.operations,close:e.close}),b=()=>(u=!0,v.setDomRenderEnabled(!0),v.element),x=t=>Object.freeze({conversations:Object.freeze(t.conversations.map(c)),activeConversationId:t.activeConversationId,state:s(t.state),pendingAction:l(t.pendingAction),identityStatus:s(t.identityStatus),nextCursor:t.nextCursor,presentation:e.getPresentation(),returnSurface:e.getReturnSurface(),config:n,copy:s(v.copy),actions:y,defaultRenderer:b,requestRender:()=>C(),onCleanup:e=>{f.push(e)}}),S=()=>{u=!1;let e=null;for(let n of t)if(n.renderHistoryView){try{e=n.renderHistoryView(x(v.getModel()))}catch(t){o(`renderHistoryView`,t),e=null}if(e)break}let n=!e||e.contains(v.element);return u=n,v.setDomRenderEnabled(n),e??v.element};function C(){if(!(!a||r||i)){i=!0;try{p();let t=S();if(t===d)return;let n=d;d=t,e.onElementChanged(t,n)}finally{i=!1}}}return a=!0,C(),{view:v,get element(){return d??v.element},requestRender:C,dispose:()=>{r=!0,p()}}}var d,f,p,m=e((()=>{d=(e,t)=>{let n=document.createElement(e);return t&&(n.className=t),n},f=(e,t={},...n)=>{let r=document.createElement(e);if(t.className&&(r.className=t.className),t.text!==void 0&&(r.textContent=t.text),t.attrs)for(let[e,n]of Object.entries(t.attrs))r.setAttribute(e,n);if(t.style){let e=r.style,n=t.style;for(let t of Object.keys(n)){let r=n[t];r!=null&&(e[t]=r)}}let i=n.filter(e=>e!=null);return i.length>0&&r.append(...i),r},p=(...e)=>e.filter(Boolean).join(` `)})),h,g=e((()=>{h=100001}));function _(e){return typeof e==`string`?e:e.filter(e=>e.type===`text`).map(e=>e.text).join(``)}function v(e){return typeof e!=`string`&&e.some(e=>e.type===`image`)}function y(e){return{type:`text`,text:e}}function b(e,t){return{type:`image`,image:e,...t?.mimeType&&{mimeType:t.mimeType},...t?.alt&&{alt:t.alt}}}function x(e,t,n){return{type:`file`,data:e,mimeType:t,filename:n}}var S,C,ee=e((()=>{S=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`image/svg+xml`,`image/bmp`],C=[`application/pdf`,`text/plain`,`text/markdown`,`text/csv`,`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/json`],[...S,...C]}));function w(e){if(typeof e!=`string`||e===``)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function T(e){return typeof e==`string`?e:void 0}function te(e){if(typeof e!=`object`||!e)return null;let t=e;switch(t.type){case`text`:return typeof t.text==`string`?y(t.text):null;case`image`:return typeof t.image==`string`?b(t.image,{mimeType:T(t.mimeType),alt:T(t.alt)}):null;case`file`:return typeof t.data==`string`&&typeof t.mimeType==`string`&&typeof t.filename==`string`?x(t.data,t.mimeType,t.filename):null;case`audio`:return typeof t.audio==`string`?{type:`audio`,audio:t.audio,...T(t.mimeType)!==void 0&&{mimeType:t.mimeType}}:null;case`video`:return typeof t.video==`string`?{type:`video`,video:t.video,...T(t.mimeType)!==void 0&&{mimeType:t.mimeType}}:null;default:return null}}function ne(e,t){let n=w(t),r=e.map(e=>w(e.timestamp)),i=Array(e.length),a=0;for(;a<r.length;){let e=r[a];if(e!==null){i[a]=e,a+=1;continue}let t=a;for(;t+1<r.length&&r[t+1]===null;)t+=1;let o=t-a+1,s=a>0?i[a-1]:null,c=t+1<r.length?r[t+1]:null,l=c!==null&&n!==null?Math.min(c,n):c??n;for(let e=0;e<o;e+=1)i[a+e]=l===null?s===null?oe+e:s+e+1:l-(o-e);a=t+1}return i.map(e=>new Date(e).toISOString())}function re(e,t){let n=ne(e,t?.beforeCreatedAt),r=[];return e.forEach((e,t)=>{if(typeof e?.id!=`string`||e.id===``||!ae.includes(e.role))return;let i=e.role,a=n[t],o=e.author,s=o&&typeof o==`object`?{...typeof o.id==`string`&&{id:o.id},...typeof o.displayName==`string`&&{displayName:o.displayName},...[`human`,`ai`,`system`].includes(o.kind??``)&&{kind:o.kind}}:void 0;if(e.displayAvailable===!1){let t={historyDisplayUnavailable:!0};r.push({id:e.id,role:i,...s&&{author:s},content:``,createdAt:a,agentMetadata:t})}else if(typeof e.displayContent==`string`)r.push({id:e.id,role:i,...s&&{author:s},content:e.displayContent,createdAt:a});else if(typeof e.content==`string`)r.push({id:e.id,role:i,...s&&{author:s},content:e.content,createdAt:a});else if(Array.isArray(e.content)){let t=e.content.map(te).filter(e=>e!==null),n=_(t);r.push({id:e.id,role:i,...s&&{author:s},content:n||(v(t)?`[Image]`:``),createdAt:a,...t.length>0&&{contentParts:t}})}else r.push({id:e.id,role:i,...s&&{author:s},content:``,createdAt:a})}),r}function ie(e,t){let n=/* @__PURE__ */ new Map;for(let t of e)n.set(t.id,t);for(let e of t)n.set(e.id,e);return[...n.values()].sort((e,t)=>{let n=new Date(e.createdAt).getTime(),r=new Date(t.createdAt).getTime();if(!Number.isNaN(n)&&!Number.isNaN(r)&&n!==r)return n-r;let i=e.sequence??0,a=t.sequence??0;return i===a?e.id.localeCompare(t.id):i-a})}var ae,oe,se=e((()=>{ee(),ae=[`user`,`assistant`,`system`,`operator`],oe=0}));m(),g(),se();const ce=/* @__PURE__ */ new Map([[`not_found`,`not_found`],[`conversation_deleted`,`not_found`],[`rate_limited`,`rate_limited`],[`authentication_required`,`authentication_required`],[`invalid_identity_proof`,`authentication_required`],[`visitor_identity_mismatch`,`authentication_required`],[`visitor_required`,`authentication_required`],[`identity_provider_failed`,`identity_provider_failed`],[`proof_not_admitted`,`proof_not_admitted`],[`identity_contract_violation`,`proof_not_admitted`],[`unauthorized`,`authentication_failed`],[`visitor_token_missing`,`authentication_failed`],[`conversation_credential_missing`,`authentication_failed`]]),E=/* @__PURE__ */ new Map([[`not_found`,`That conversation is no longer available.`],[`rate_limited`,`Too many history requests.`],[`authentication_failed`,`History access was not authorized.`],[`authentication_required`,`Sign in again to view account history.`],[`identity_provider_failed`,`The identity provider did not respond.`],[`proof_not_admitted`,`Account history is not available for this configuration.`],[`unsupported_scope`,`This history scope is not supported.`],[`unavailable`,`Conversation history is unavailable right now.`]]),D=e=>E.get(e)??`Conversation history is unavailable right now.`;function O(e,{HistoryClientError:t,HistoryProviderError:n}){if(e instanceof n)return e;if(e instanceof t){let t=ce.get(e.code)??`unavailable`;return new n(t,D(t),{...e.retryAfterSeconds===void 0?{}:{retryAfterSeconds:e.retryAfterSeconds}})}return new n(`unavailable`,D(`unavailable`))}function le(e){let{HistoryProviderError:t}=e.errors,n=()=>e.getClient?.()??e.client,r=e.getIdentityProofConfigured()?[`browser`,`verified-user`]:[`browser`],i={scopes:r},a=e=>{if(!r.includes(e))throw new t(`unsupported_scope`,D(`unsupported_scope`))},o=async(t,n)=>{a(t);try{return await n()}catch(t){throw O(t,e.errors)}},s=t=>{let n=!1;return{conversationId:t.session.conversationId??``,conversationRevision:t.session.conversationRevision??``,async commit(){n||(n=!0,t.commit(),await e.onActivationCommitted(t.session))},discard(){n||(n=!0,t.discard())}}};return{capabilities:i,getIdentityStatus(){return n().getHistoryIdentityStatus()},subscribeIdentityStatus(e){return n().subscribeHistoryIdentityStatus(e)},subscribeAvailability(e){return n().subscribeHistoryAvailability(e)},async list(e){return o(e.context.scope,async()=>{let t=await n().listConversations({...e.cursor?{cursor:e.cursor}:{},...e.limit===void 0?{}:{limit:e.limit},...e.targetId?{targetId:e.targetId}:{},scope:e.context.scope});return{items:t.data,nextCursor:t.nextCursor}})},async getPage(e,t){return o(t.context.scope,async()=>{let r=await n().getConversation(e,{...t.cursor?{messageCursor:t.cursor}:{},scope:t.context.scope}),i=re(r.messages,{...t.beforeCreatedAt?{beforeCreatedAt:t.beforeCreatedAt}:{}});return{summary:r.summary,messages:ie([],i),conversationRevision:r.conversationRevision??``,nextCursor:r.nextMessageCursor}})},async prepareOpen(e,t){return o(t.context.scope,async()=>s(await n().prepareConversationSession(e)))},async prepareStartNew(e){return o(e.context.scope,async()=>s(await n().prepareNewConversationSession()))},async delete(e,t){await o(t.context.scope,()=>n().deleteConversation(e,{scope:t.context.scope}))},async deleteAll(e){return o(e.context.scope,()=>n().deleteAllConversations({...e.targetId===void 0?{}:{targetId:e.targetId},scope:e.context.scope}))},async resetDevice(){try{return await n().resetVisitor(),{remoteRevocationConfirmed:!0}}catch{return{remoteRevocationConfirmed:!1}}}}}const k=e=>{let t=r(e.config.features?.history?.copy),i=null,a=!1,o=null,s=null,c=`conversation`,l=null,m=null,g=null,_=null,v=0,y=null,b=null,x=null,S=`persona-history-${Math.random().toString(36).slice(2,8)}`,C=()=>e.historyFeatureEnabled()&&!!i&&!a,ee=()=>{let t=e.session.getStatus();return e.isStreaming||t===`paused`||t===`resuming`},w=()=>{let t=e.config.features?.history?.scope;if(t)return t;let n=e.config.getIdentityProof?`verified-user`:`browser`,r=i?.capabilities.scopes;return!r||r.includes(n)?n:r[0]??n},T=()=>s?.scope??w(),te=()=>e.session.getClientSession()?.targetId??null,ne=e=>`${e.state}:${`reason`in e?e.reason:``}`,re=t=>{let n=ne(t);n!==_&&(_=n,e.eventBus.emit(`history:identityStatusChanged`,{status:t,timestamp:Date.now()}))},ie=null,ae=null,oe=()=>{if(!e.historyFeatureEnabled())return null;let t=e.getHistoryProviderFactory();if(t)return t();let n=e.config.features?.history?.provider;return n?typeof n==`function`?(ie!==n&&(ie=n,ae=n()),ae):n:e.session.isClientTokenMode()?le({errors:e.historyErrors,client:e.session.getClient(),getIdentityProofConfigured:()=>typeof e.config.getIdentityProof==`function`,onActivationCommitted:t=>e.session.bindActivatedSession(t),getClient:()=>e.session.getClient()}):null},se=()=>{b?.(),b=null,x?.(),x=null,a=!1;let t=i;i=oe(),t&&t!==i&&e.discardConversationContinuity();let n={...e.historyInternals};i?n.historyProvider=i:delete n.historyProvider,e.historyInternals=n,e.session.setHistoryInternals(e.historyInternals),i&&(b=i.subscribeAvailability?.(e=>{a=!e,e||q({restoreFocus:!1}),$()})??null,x=i.subscribeIdentityStatus(e=>re(e)),_=ne(i.getIdentityStatus()))},ce=()=>{let t=e.config.features?.history?.presentation??`panel`;if(t===`panel`||t===`auto`&&e.launcherEnabled&&!e.isDockedMountMode(e.config))return`panel`;let n=e.artifactSplitRoot??e.container;return(n.getBoundingClientRect().width||n.clientWidth)>=720?`rail`:`panel`},E=(e,t)=>{t?(e.setAttribute(`aria-hidden`,`true`),e.setAttribute(`inert`,``)):(e.removeAttribute(`aria-hidden`),e.removeAttribute(`inert`))},D=`data-persona-history-suppressed`,O=null,k=null,A=null,ue=null,de=null,fe=``,pe=()=>e.header===de?fe:n(e.config)?``:`none`,me=()=>e.historyPresentation===`panel`&&!!A&&ue===A.element&&n(e.config)&&pe()!==`none`,he=()=>{for(let t of Array.from(e.header.children))t!==O&&t.setAttribute(D,``)},ge=()=>{for(let t of Array.from(e.container.querySelectorAll(`[${D}]`)))t.removeAttribute(D)},_e=()=>{let t=A;if(!t)return;if(Array.from(e.header.children).some(e=>e!==O&&!e.hasAttribute(D))){k&&k!==e.header&&(k.style.removeProperty(`min-height`),k=null);let t=e.header.offsetHeight;t>0&&(e.header.style.minHeight=`${t}px`,k=e.header)}O||=d(`div`,`persona-history-header-host`),t.setHeaderPlacement(`external`);let n=t.getHeaderElement();n.parentNode!==O&&O.replaceChildren(n),O.parentNode!==e.header&&e.header.appendChild(O),he()},ve=()=>{k&&=(k.style.removeProperty(`min-height`),null),O&&(A?.setHeaderPlacement(`inline`),O.remove(),O=null,ge())},ye=null,be=()=>{ye&&(e.body.style.display=`none`,E(e.body,!0),e.footer.hidden=!0,E(e.footer,!0),e.panelSuggestions.style.display=`none`,E(e.panelSuggestions,!0),e.panelSuggestionsFade.style.display=`none`,me()?(_e(),e.header.style.display=pe(),E(e.header,!1)):(ve(),e.header.style.display=`none`,E(e.header,!0)))};e.reapplyHistoryHostChrome=be;let xe=t=>{let r=e.body.style.display,i=e.footer.hidden,a=e.panelSuggestions.style.display,o=e.panelSuggestionsFade.style.display,s=e.footer,c=e.header,l=e.header.style.display;de=c,fe=l,ye=()=>{ye=null,ve(),de=null,e.body.style.display=r,E(e.body,!1),e.panelSuggestions.style.display=a,E(e.panelSuggestions,!1),e.panelSuggestionsFade.style.display=o,s.hidden=i,E(s,!1),e.footer!==s&&(e.footer.hidden=!1,E(e.footer,!1)),c.style.display=l,E(c,!1),e.header!==c&&(e.header.style.display=n(e.config)?``:`none`,E(e.header,!1))},e.container.insertBefore(t,e.footer.parentNode===e.container?e.footer:e.panelSuggestions),be()},j=null,M=null,Se=null,N=null,Ce=()=>[e.header,e.panelElements.closeButtonWrapper,e.panelElements.clearChatButtonWrapper,e.body,e.footer,e.scrollToBottomButton],we=()=>e.config.features?.history?.rail?.collapsible!==!1,P=()=>e.config.features?.history?.rail?.side===`right`?`right`:`left`,Te=e=>Math.min(400,Math.max(200,Math.round(e))),Ee=()=>e.config.features?.history?.rail?.resizable===!0,F,De=()=>{if(F===void 0&&(F=null,e.config.persistState!==!1))try{let t=Number(window.localStorage.getItem(`${e.currentKeyPrefix()}rail-width`));t&&(F=t)}catch{}return F},I=()=>Te(De()??e.config.features?.history?.rail?.width??260),Oe=t=>{if(F=t,e.config.persistState!==!1)try{window.localStorage.setItem(`${e.currentKeyPrefix()}rail-width`,String(t))}catch{}},ke=()=>we()&&e.config.features?.history?.rail?.collapsedBehavior===`overlay`,L=!1,Ae=e=>{let t=d(`img`);return t.src=e,t.alt=``,t.setAttribute(`aria-hidden`,`true`),t},je=()=>{let t=e.config.features?.history?.rail?.brand;if(!t)return;let n=!1,r;return i=>{if(t.render)try{return t.render({collapsed:i})??null}catch(e){return n||(n=!0,console.warn(`[persona] history rail brand threw`,e)),null}return r===void 0&&(r=t.iconUrl?Ae(t.iconUrl):t.icon?e.renderLucideIcon(t.icon,20):null),r?r.cloneNode(!0):null}},Me=()=>e.config.features?.history?.rail?.sections?.map(t=>{let n=!1,r=e=>{n||(n=!0,console.warn(`[persona] history rail section threw`,t.id,e))};return{id:t.id,title:t.title,placement:t.placement??`above-conversations`,items:t.items.map(t=>{let n;return{id:t.id,label:t.label,badge:t.badge,iconNode:()=>{if(n!==void 0)return n;try{n=t.renderIcon?t.renderIcon()??null:t.iconUrl?Ae(t.iconUrl):t.icon?e.renderLucideIcon(t.icon,20):null}catch(e){r(e),n=null}return n},onSelect:()=>{try{t.onSelect()}catch(e){r(e)}}}})}})??[],Ne=e=>{let t=Me();for(let n of e)t.some(e=>e.id===n.id)?console.warn(`[persona] duplicate history rail section id`,n.id):t.push(n);return t.length?t:void 0},R=null,Pe=()=>`${e.currentKeyPrefix()}rail-collapsed`,Fe=()=>{if(R===null&&(R=e.config.features?.history?.rail?.defaultCollapsed===!0,e.config.persistState!==!1))try{let e=window.localStorage.getItem(Pe());e&&(R=e===`1`)}catch{}return R},Ie=t=>{if(R=t,e.config.persistState!==!1)try{window.localStorage.setItem(Pe(),t?`1`:`0`)}catch{}},z=()=>e.historyPresentation===`rail`&&we()&&!ke()&&Fe(),Le=()=>{},Re=()=>{ke()?Le():(Ie(!Fe()),o?.view.setCollapsed(z()),e.applyRailChrome(),e.repinAnchoredMessage())},ze=()=>{let t=e.config.features?.history?.rail?.collapseShortcut;return!t||!e.parseCombo(t)?null:{combo:t,hint:e.formatCombo(t),aria:e.ariaCombo(t)}},Be=`var(--persona-history-overlay-margin,8px)`,B=null,V=null,Ve=0,H=null,U=null,W=!1,He=0,Ue=()=>window.matchMedia?.(`(pointer: coarse)`).matches===!0,G=()=>C()&&ke()&&(e.historyPresentation??ce())===`rail`,We=()=>e.historyVisible&&!L,Ge=()=>{U!==null&&clearTimeout(U),U=null},Ke=()=>{e.loadHistoryView().catch(()=>{})},qe=()=>{Ge(),L&&(U=setTimeout(()=>{U=null,!W&&L&&(H?.contains(document.activeElement)||q({restoreFocus:!1}))},300))},Je=(e,t)=>{let n=H?.getBoundingClientRect();if(!n)return!1;let r=B?.getBoundingClientRect(),i=r?Math.min(r.top,n.top):n.top;return e>=n.left&&e<=n.right&&t>=i&&t<=n.bottom||!!r&&e>=r.left&&e<=r.right&&t>=r.top&&t<=r.bottom},Ye=e=>{L&&(W=Je(e.clientX,e.clientY),W?Ge():U===null&&qe())},Xe=t=>{!e.historyVisible&&G()&&(L=!0,_t({invoker:B,keyboard:t?.keyboard===!0}).then(()=>{e.historyVisible?!W&&document.activeElement!==B&&q():L=!1}))},Ze=()=>{let e=ue?.querySelector(`[data-persona-history-focus="collapse"]`);e&&(e.setAttribute(`aria-label`,L?t.expandLabel:t.collapseLabel),e.setAttribute(`aria-expanded`,L?`false`:`true`))},Qe=()=>{Ie(!1);let t=o;if(!L||!t){_t({invoker:B});return}let n=document.activeElement===B;L=!1,dt(),t.element.remove(),pt(t.element),Ze(),n&>(),e.repinAnchoredMessage(),$()},$e=()=>{Ie(!0),q()};Le=()=>{!e.historyVisible||L?Qe():$e()};let et=()=>{let n=ze(),r=e.createHeaderIconButton({ariaLabel:t.expandLabel,iconName:`panel-left`,wrapperClassName:`persona-relative persona-inline-flex persona-items-center persona-justify-center`,extraClassName:`persona-rail-trigger`,tooltip:!1,attrs:{"data-persona-rail-trigger":``,"aria-controls":S,...n?{"aria-keyshortcuts":n.aria}:{}}}),i=r.button;i.addEventListener(`mouseenter`,()=>{W=!0,Ge(),!(Ue()||Date.now()<He)&&Xe()}),i.addEventListener(`mouseleave`,()=>{W=!1,He=0,qe()}),i.addEventListener(`focus`,()=>{e.historyVisible||Ke()}),i.addEventListener(`click`,t=>{C()&&(t.detail!==0&&Ue()&&!e.historyVisible?Xe():Qe())}),B=i,V=r.wrapper},tt=()=>{if(V&&!V.isConnected&&(V=null,B=null),!G()){V?.remove(),V=null,B=null;return}B||et();let n=V,r=B;if(!n||!r)return;let i=P()===`right`?null:e.header.firstChild;(i??e.header.lastChild)!==n&&e.header.insertBefore(n,i),n.style.display=We()||Ve>0?`none`:``,r.setAttribute(`aria-label`,t.expandLabel),r.setAttribute(`aria-expanded`,e.historyVisible?`true`:`false`),H&&e.applyRailChrome()},nt=e=>{if(!L)return;let t=e.target;t instanceof Node&&(H?.contains(t)||V?.contains(t)||t instanceof Element&&t.closest(`.persona-dropdown-menu,[role="alertdialog"]`)||q({restoreFocus:!1}))};document.addEventListener(`pointerdown`,nt,!0),e.destroyCallbacks.push(()=>{document.removeEventListener(`pointerdown`,nt,!0),document.removeEventListener(`pointermove`,Ye),K?.(),Ge()});let rt=null,K=null,it=t=>{Oe(Te(t)),e.applyRailChrome(),e.repinAnchoredMessage()},at=()=>{let t=d(`div`,`persona-rail-resizer`);return t.tabIndex=0,t.setAttribute(`role`,`separator`),t.setAttribute(`aria-orientation`,`vertical`),t.setAttribute(`aria-valuemin`,`200`),t.setAttribute(`aria-valuemax`,`400`),t.addEventListener(`pointerdown`,n=>{let r=M;if(!r||n.button!==0)return;n.preventDefault(),K?.();let i=n.clientX,a=r.getBoundingClientRect().width||I(),o=P()===`right`?-1:1,s=a,c=e.mount.ownerDocument;r.style.transition=`none`;let l=e=>{s=Te(a+o*(e.clientX-i)),r.style.flex=`0 0 ${s}px`,t.setAttribute(`aria-valuenow`,String(s))},u=()=>{K=null,c.removeEventListener(`pointermove`,l),c.removeEventListener(`pointerup`,u),c.removeEventListener(`pointercancel`,u),r.style.removeProperty(`transition`);try{t.releasePointerCapture(n.pointerId)}catch{}it(s)};K=u,c.addEventListener(`pointermove`,l),c.addEventListener(`pointerup`,u),c.addEventListener(`pointercancel`,u);try{t.setPointerCapture(n.pointerId)}catch{}}),t.addEventListener(`keydown`,e=>{let t=P()===`right`?-16:16,n=I(),r=e.key===`ArrowRight`?n+t:e.key===`ArrowLeft`?n-t:e.key===`Home`?200:e.key===`End`?400:null;r!==null&&(e.preventDefault(),it(r))}),t},ot=(e,n)=>{if(!Ee()||z()){K?.(),rt?.remove();return}let r=rt??at();rt=r,r.setAttribute(`aria-label`,t.resizeLabel),r.setAttribute(`aria-valuenow`,String(I())),r.nextElementSibling!==n&&e.insertBefore(r,n)};e.applyRailChrome=()=>{o?.view.setRailSide(P());let t=P()===`right`,n=H;if(n){let r=B?B.getBoundingClientRect().bottom-e.container.getBoundingClientRect().top:0;n.style.top=`calc(${Math.max(0,Math.round(r))}px + ${Be})`,n.style.width=`${I()}px`,n.style.left=t?``:Be,n.style.right=t?Be:``}let r=M,i=j,a=Se;if(!r||!i||!a)return;r.style.flex=`0 0 ${z()?52:I()}px`;let s=`1px solid var(--persona-divider,#e5e7eb)`;r.style.borderRight=t?``:s,r.style.borderLeft=t?s:``;let c=t?a:r;i.firstElementChild!==c&&i.append(c,t?r:a),ot(i,t?r:a)};let st=t=>{if(N&&M){N.replaceWith(t),N=null,e.applyRailChrome();return}let n=d(`div`,`persona-history-rail-shell`);n.style.cssText=`display:flex;flex-direction:row;flex:1 1 auto;min-height:0`;let r=d(`div`,`persona-history-rail-conversation`);r.style.cssText=`display:flex;flex-direction:column;flex:1 1 auto;min-width:0;min-height:0;position:relative`;let i=d(`div`,`persona-history-rail-host`);i.style.cssText=`display:flex;min-height:0;overflow:hidden`,e.container.insertBefore(n,e.header.parentNode===e.container?e.header:e.body);for(let t of Ce())t?.parentNode===e.container&&r.appendChild(t);n.append(i,r),i.appendChild(t),j=n,M=i,Se=r,e.applyRailChrome()},ct=()=>{if(j)return;let t=d(`div`,`persona-history-rail-placeholder`);t.style.cssText=`flex:1 1 auto;min-height:0`,N=t,st(t),e.repinAnchoredMessage()},lt=()=>{N&&(dt(),e.repinAnchoredMessage())},ut=t=>{let n=d(`div`,`persona-history-rail-overlay`);n.style.cssText=`position:absolute;bottom:${Be};display:flex;overflow:hidden;z-index:${h-1};border-radius:var(--persona-history-overlay-radius,16px);background:var(--persona-history-overlay-bg,var(--persona-container,#f7f7f8));box-shadow:var(--persona-history-overlay-shadow,0 12px 40px rgba(0,0,0,0.25))`,e.container.style.position=`relative`,e.container.appendChild(n),n.appendChild(t),document.addEventListener(`pointermove`,Ye),H=n,e.applyRailChrome(),Ze()},dt=()=>{ye?.(),H&&=(W&&(He=Date.now()+150),document.removeEventListener(`pointermove`,Ye),H.remove(),null);let t=j;if(t){K?.();for(let n of Ce())if(n&&t.contains(n)){let r=n===e.scrollToBottomButton?e.panelSuggestions:t;e.container.insertBefore(n,r)}t.remove(),j=null,M=null,Se=null,N=null}},ft=e=>{ue=e,e.id=S,e.style.flex=`1 1 auto`,e.style.minHeight=`0`},pt=t=>{ft(t),(e.historyPresentation!==`rail`||L)&<(),e.historyPresentation===`rail`?L?ut(t):st(t):xe(t)},mt=()=>{if(tt(),Ht(),!e.historyVisible||!o)return;let t=ce();if(t===e.historyPresentation)return;let n=document.activeElement,r=n instanceof HTMLElement&&(o.element.contains(n)||O?.contains(n)===!0)?n:null;dt(),o.element.remove(),o.view.setHeaderPlacement(`inline`),e.historyPresentation=t,o.view.setPresentation(t),o.view.setCollapsed(z()),o.requestRender(),o.element.isConnected||pt(o.element),r?.isConnected?r.focus():gt(),e.syncScrollToBottomButton(),e.repinAnchoredMessage(),$()},ht=(e,t)=>O?.querySelector(t)??e.querySelector(t),gt=()=>{let e=o?.element??ue;if(!e)return;let t=ht(e,`[data-persona-history-focus="close"],[data-persona-history-focus="collapse"]`);if(t){t.focus();return}let n=ht(e,`.persona-history-title`)??e;n.tabIndex=-1,n.focus()},_t=async r=>{if(!C()||e.historyVisible)return;let a=i;if(!a)return;if(!L&&G()&&Fe()){tt();return}vt();let d=++v;c=r?.returnSurface??`conversation`,l=r?.invoker??m;let f=G()&&!L;f&&(Ve+=1,tt(),ct());let p;try{p=await e.loadHistoryView()}catch{e.announceHistory(t.openHistoryLabel),f&&(--Ve,d===v&&(lt(),tt()));return}if(f&&--Ve,d!==v||e.historyVisible)return;s={scope:w()},e.historyPresentation=ce(),e.historyVisible=!0;let h=e.historyPresentation===`panel`&&n(e.config)&&e.header.style.display!==`none`?`external`:`inline`,g=e.config.features?.history?.rowAvatar,_=ze(),y=_?{hint:_.hint,aria:_.aria}:null,b={provider:a,context:s,targetId:te(),presentation:e.historyPresentation,collapsible:we(),collapsed:z(),railSide:P(),renderRailHeader:e.config.features?.history?.rail?.renderHeader,railBrand:je(),onToggleCollapse:Re,...y?{collapseShortcut:y}:{},headerPlacement:h,showScopeStatus:e.config.features?.history?.showScopeStatus!==!1,showDelete:e.config.features?.history?.showDelete!==!1,showDeleteAll:e.config.features?.history?.showDeleteAll!==!1,...e.config.features?.history?.listActions?.length?{listActions:e.config.features.history.listActions}:{},rowAvatar:g===!1?!1:typeof g==`string`?g:e.config.launcher?.iconUrl,activeConversationId:e.session.getActiveConversationId(),...e.config.features?.history?.grouping?{grouping:e.config.features.history.grouping}:{},...e.config.features?.history?.copy?{copy:e.config.features.history.copy}:{},...e.config.features?.history?.pageSize===void 0?{}:{pageSize:e.config.features.history.pageSize},onSelect:e=>At(e,{focusComposer:!0}).catch(()=>{}),onActiveConversationChange:t=>e.setActiveConversationSummary(t),attachTooltip:e.attachTooltip,onStartNew:()=>jt({focusComposer:!0}),onClose:()=>q(),onRequestDeleteConversation:e=>Rt(e),onRequestClearHistory:()=>zt(),...a.resetDevice?{onRequestResetIdentity:()=>Bt()}:{}};o=u({plugins:e.plugins,config:e.config,getPresentation:()=>e.historyPresentation??`panel`,getReturnSurface:()=>c,close:()=>q(),createView:({slots:t,renderDom:n,onModelChange:r,railSections:i})=>(A=p.createHistoryView({...b,railSections:Ne(i),slots:t,renderDom:n,onModelChange:r,onAnnounce:e.announceHistory}),A),onElementChanged:(e,t)=>{if(!t?.isConnected)return pt(e);ft(e),t.replaceWith(e),be()}}),o.view.setNewConversationRequired(e.historySessionState.recovery===`new_conversation_required`),r?.focus!==!1&&(e.historyPresentation!==`rail`||r?.keyboard===!0)&>(),e.syncScrollToBottomButton(),e.repinAnchoredMessage(),$(),e.eventBus.emit(`history:opened`,{presentation:e.historyPresentation,returnSurface:c,timestamp:Date.now()})},vt=()=>{},q=t=>{if(!e.historyVisible)return;v+=1;let n=c,r=l,i=o,a=t?.restoreFocus!==!1;e.historyVisible=!1;let u=!1,d=null,f=()=>{if(!u){if(u=!0,vt=()=>{},d!==null&&clearTimeout(d),L=!1,Ge(),dt(),i?.dispose(),i?.view.destroy(),i?.element.remove(),o===i&&(o=null,A=null,ue=null,e.historyPresentation=null,s=null,l=null),e.syncScrollToBottomButton(),e.repinAnchoredMessage(),$(),a){let t=r??m;t?.isConnected?t.focus():e.maybeFocusInput()}e.eventBus.emit(`history:closed`,{returnSurface:n,timestamp:Date.now()})}},p=i&&i.element===i.view.element?i.view.playExit():null;p?(vt=f,d=setTimeout(f,250),p.then(f)):f()},yt=t=>{if(t.key===`Escape`&&e.historyVisible&&o){if(e.historyPresentation===`rail`){let e=t.target;if(!(e instanceof Node)||!(o.element.contains(e)||L&&V?.contains(e)===!0))return}t.preventDefault(),t.stopPropagation(),q()}};e.container.addEventListener(`keydown`,yt),e.destroyCallbacks.push(()=>e.container.removeEventListener(`keydown`,yt));let bt=0,J=null,xt=null,Y=()=>{xt&&clearTimeout(xt),xt=null};e.destroyCallbacks.push(Y);let St=()=>{Y();let t=e.conversationOpenPendingEl;t&&(e.conversationOpenTakeover=!0,t.hidden=!1,e.messagesWrapper.style.display=`none`,e.updateWelcome())},X=()=>{bt+=1,Y(),J?.remove(),J=null,e.conversationOpenPendingEl&&(e.conversationOpenPendingEl.remove(),e.conversationOpenPendingEl=null,e.conversationOpenTakeover=!1,e.messagesWrapper.style.removeProperty(`display`),E(e.footer,!1),e.updateWelcome())},Ct=()=>{try{if(window.matchMedia?.(`(prefers-reduced-motion: reduce)`)?.matches)return;e.messagesWrapper.animate([{opacity:0},{opacity:1}],{duration:150,easing:`ease-out`})}catch{}},wt=t=>{let n=e.config.layout?.messages?.layout??`bubble`,r=f(`div`,{className:`persona-flex`,attrs:{"aria-hidden":`true`}});e.applyMessageRowLayout(r,t);let i=f(`div`,{className:p(e.getBubbleClasses(t,n).join(` `),`persona-conversation-loading-bubble`),attrs:{"data-persona-theme-zone":`${t}-message`},style:{width:t===`user`?`64%`:`100%`,backgroundColor:n===`flat`?`transparent`:`var(--persona-message-${t}-bg, var(--persona-${t===`user`?`accent`:`container`}))`,color:`var(--persona-message-${t}-text, ${t===`user`&&n!==`flat`?`white`:`var(--persona-text)`})`}},...[`94%`,...t===`assistant`?[`86%`]:[],`62%`].map(e=>f(`div`,{className:`persona-conversation-loading-line`,style:{width:e}})));return e.applyBubbleGeometry(i,t,n,{...e.resolveThemeDefaults(e.config.future).components.message[t],...e.config.theme?.components?.message?.[t],...e.config.darkTheme?.components?.message?.[t]}),r.appendChild(i),r},Tt=()=>f(`div`,{className:`persona-conversation-loading-body`,style:{gap:e.messagesWrapper.style.gap}},wt(`user`),wt(`assistant`),wt(`user`),wt(`assistant`)),Et=()=>e.config.loadingIndicator?.conversationOpenVariant===`skeleton`?Tt():f(`div`,{className:`persona-conversation-loading-spinner`,attrs:{"aria-hidden":`true`}},f(`span`,{className:`persona-conversation-loading-ring`})),Dt=t=>{e.conversationOpenPendingEl?.remove(),e.conversationOpenPendingEl=t,t.hidden=!e.conversationOpenTakeover,e.body.insertBefore(t,e.messagesWrapper),Y(),e.conversationOpenTakeover||(xt=setTimeout(St,250)),E(e.footer,!0)},Ot=()=>{let n={config:e.config,streaming:!1,location:`conversation-open`,defaultRenderer:Et},r=null,i=e.plugins.find(e=>e.renderLoadingIndicator);i?.renderLoadingIndicator&&(r=i.renderLoadingIndicator(n)),r===null&&e.config.loadingIndicator?.render&&(r=e.config.loadingIndicator.render(n));let a=r??Et();Dt(f(`div`,{className:p(`persona-conversation-loading`,a.classList.contains(`persona-conversation-loading-spinner`)&&`persona-conversation-loading--centered`),attrs:{role:`status`,"aria-label":t.openConversationLoadingLabel},style:{maxWidth:e.messagesWrapper.style.maxWidth||`none`}},a))},kt=n=>{let r=()=>{At(n,{focusComposer:!0}).catch(()=>{})},i=C()?()=>{X(),_t()}:void 0,a=(e,t)=>{let n=f(`button`,{className:`persona-conversation-loading-error-action`,attrs:{type:`button`},text:e});return n.addEventListener(`click`,t),n},o=()=>f(`div`,{className:`persona-conversation-loading-error-body`},f(`p`,{className:`persona-conversation-loading-error-title`,text:t.openConversationErrorTitle}),f(`div`,{className:`persona-conversation-loading-error-actions`},a(t.openConversationRetryLabel,r),i?a(t.openConversationBackLabel,i):null)),s=Object.freeze({conversationId:n,config:e.config,copy:Object.freeze({title:t.openConversationErrorTitle,retryLabel:t.openConversationRetryLabel,backLabel:t.openConversationBackLabel}),retry:r,...i?{back:i}:{},defaultRenderer:o}),c=null;for(let t of e.plugins)if(t.renderHistoryOpenError){try{c=t.renderHistoryOpenError(s)}catch(e){console.warn(`[persona] renderHistoryOpenError threw`,e),c=null}if(c)break}if(J?.remove(),J=f(`div`,{className:`persona-conversation-loading-error`,attrs:{role:`alert`}},c??o()),!e.session.getActiveConversationId()&&e.session.getMessages().length===0&&!e.composerStore.getState().text&&!e.attachmentManager?.hasAttachments()){let e=J;J=null,Dt(e),St()}else e.body.insertBefore(J,e.messagesWrapper);e.announceHistory(t.openConversationErrorTitle)};e.eventBus.on(`history:closed`,()=>{e.conversationOpenPendingEl&&E(e.footer,!0)});let At=async(t,{focusComposer:n=!1,busy:r=`reject`}={})=>{let i=T();if(r===`background`&&(e.session.assertBackgroundSwitchable(),e.composerStore.getState().phase===`preparing`))throw new e.SessionHistoryError(`conversation_busy`,`Finish preparing this turn before switching conversations`);if(r===`reject`&&(e.session.isStreaming()||[`paused`,`resuming`].includes(e.session.getStatus())||e.composerStore.getState().phase===`preparing`))throw new e.SessionHistoryError(`conversation_busy`,`Finish or stop the current turn before switching conversations`);r===`stop`&&(++e.composerConversationGeneration,e.submissionAbort?.abort(),e.submissionAbort=null,e.composerStore.setPreparing(!1),e.session.cancel());let a=e.conversationStateKey();(!e.conversationOpenPendingEl||e.pendingConversationReading?.key!==a)&&(e.pendingConversationReading={key:a,reading:e.captureConversationReading()});let s=null,c=!!o;o?.view.setActiveConversationId(t),X();let l=bt;Ot(),e.historyVisible&&(e.historyPresentation===`panel`||L)&&q({restoreFocus:!1}),e.suppressScrollSend=!0;try{await e.session.openConversation(t,{scope:i,busy:r,onBeforeCommit:()=>{e.saveConversationContinuity(),s=e.composerConversationGeneration,e.conversationPersistenceOwner=s},onCommitted:()=>{e.restoreConversationContinuity(),e.conversationPersistenceOwner===s&&(e.conversationPersistenceOwner=null),e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),e.persistState()}})}catch(n){if(e.conversationPersistenceOwner===s&&(e.conversationPersistenceOwner=null),s===e.composerConversationGeneration&&e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),l===bt){let n=e.pendingConversationReading?.reading;X(),n&&e.restoreConversationReading(n),e.pendingConversationReading=null,o?.view.setActiveConversationId(e.session.getActiveConversationId()),kt(t),e.suppressScrollSend=!1}throw n}finally{(l===bt||!e.conversationOpenPendingEl)&&(e.suppressScrollSend=!1)}l===bt&&(X(),e.pendingConversationReading=null,e.messageCache.clear(),Ct(),Q(),c||e.setActiveConversationSummary(null),e.eventBus.emit(`history:conversationOpened`,{conversationId:t,title:e.activeConversationTitle,scope:i,timestamp:Date.now()}),n&&e.maybeFocusInput())},jt=async({focusComposer:t=!1}={})=>{X();let n=null;try{await e.session.startNewConversation({scope:T(),onBeforeCommit:()=>{e.saveConversationContinuity(),n=e.composerConversationGeneration,e.conversationPersistenceOwner=n},onCommitted:()=>{e.restoreConversationContinuity(!0),e.conversationPersistenceOwner===n&&(e.conversationPersistenceOwner=null),e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),e.persistState(),e.pendingConversationReading=null}})}catch(t){throw e.conversationPersistenceOwner===n&&(e.conversationPersistenceOwner=null),n===e.composerConversationGeneration&&e.usesSessionVoiceForConfig(e.config)&&e.session.setupVoice(),t}e.setActiveConversationSummary(null),e.messageCache.clear(),e.resetAnchorState(),e.resumeAutoScroll(),e.jumpToBottomInstant(),Q();let r=e.session.getActiveConversationId();o?.view.setActiveConversationId(r),e.eventBus.emit(`history:conversationStarted`,{conversationId:r,timestamp:Date.now()}),e.historyVisible&&(e.historyPresentation===`panel`||L)&&q({restoreFocus:!1}),t&&e.maybeFocusInput()},Mt=async(t,n)=>{let r=await e.session.updateConversation(t,{...n,...n.title===void 0?{}:{title:n.title.trim()}});return o?.view.applyConversationSummary(r),!o&&t===e.session.getActiveConversationId()&&e.setActiveConversationSummary(r),r},Nt=async t=>{let n=T(),r=e.session.getActiveConversationId()===t;await e.session.deleteConversation(t,{scope:n}),e.discardConversationContinuity(t),r&&(e.attachmentManager?.destroy({release:!0}),e.attachmentManager=null,e.restoreConversationContinuity(!0)),o?.view.removeConversationSummary(t),r&&(e.setActiveConversationSummary(null),e.messageCache.clear(),e.resetAnchorState(),e.resumeAutoScroll(),Q()),e.eventBus.emit(`history:conversationDeleted`,{conversationId:t,scope:n,wasActive:r,timestamp:Date.now()})},Pt=async t=>{let n=t?.scope??T(),r=t?.allTargets?null:t?.targetId??te(),i=await e.session.clearConversationHistory({...r?{targetId:r}:{},scope:n});return e.discardConversationContinuity(),e.setActiveConversationSummary(null),e.messageCache.clear(),e.resetAnchorState(),e.resumeAutoScroll(),Q(),e.eventBus.emit(`history:cleared`,{deleted:i.deleted,scope:n,targetId:r,timestamp:Date.now()}),i},Ft=async()=>{if(!i?.resetDevice)throw Error(`[Persona] resetHistoryIdentity() requires a history provider that can reset this device`);let n=!1;try{n=(await e.session.resetHistoryDevice()).remoteRevocationConfirmed}finally{e.discardConversationContinuity(),X(),e.setActiveConversationSummary(null),e.session.clearArtifacts(),e.messageCache.clear(),e.lastAppliedMessages=null,e.config.clearStoredSessionId?.(),e.config.clearStoredConversationId?.(),e.persistentMetadata={},e.actionManager.syncFromMetadata(),e.clearPersistedDraft();let t=e.storageAdapter;t?.clear&&e.runStorageMutation(()=>t.clear(),`[AgentWidget] Failed to clear storage adapter:`),e.resetAnchorState(),e.resumeAutoScroll(),Q(),q({restoreFocus:!1}),e.maybeFocusInput(),e.open||e.launcherSurfaceInstance?.launcher.element.focus()}return e.announceHistory(n?t.identityResetNotice:t.identityResetUnconfirmedNotice),e.eventBus.emit(`history:identityReset`,{remoteRevocationConfirmed:n,timestamp:Date.now()}),{remoteRevocationConfirmed:n}},It=()=>e.artifactSplitRoot?e.panel:e.container,Lt=async t=>{let n=await e.loadHistoryView().catch(()=>null);return typeof n?.showHistoryConfirm==`function`?n.showHistoryConfirm(t):window.confirm(`${t.title}\n\n${t.description}`)},Rt=async e=>await Lt({host:It(),title:t.deleteConversationConfirmTitle,description:t.deleteConversationConfirm,confirmLabel:t.deleteConversationConfirmLabel,cancelLabel:t.confirmCancelLabel})?(await Nt(e),`deleted`):`cancelled`,zt=async()=>{let e=T()===`verified-user`;return await Lt({host:It(),title:t.clearHistoryConfirmTitle,description:e?t.clearHistoryVerifiedConfirm:t.clearHistoryConfirm,confirmLabel:t.clearHistoryConfirmLabel,cancelLabel:t.confirmCancelLabel})?(await Pt(),`cleared`):`cancelled`},Bt=async()=>{if(!await Lt({host:It(),title:t.resetIdentityConfirmTitle,description:t.resetIdentityConfirm,confirmLabel:t.resetIdentityConfirmLabel,cancelLabel:t.confirmCancelLabel}))return{outcome:`cancelled`};let{remoteRevocationConfirmed:e}=await Ft();return{outcome:`reset`,remoteRevocationConfirmed:e}},Z=d(`button`,`persona-history-earlier`);Z.type=`button`,Z.textContent=t.showEarlierMessagesLabel,Z.setAttribute(`data-persona-history-earlier`,``),Object.assign(Z.style,{alignSelf:`center`,minHeight:`44px`,padding:`0 16px`,borderRadius:`999px`,border:`1px solid var(--persona-border, rgba(0,0,0,0.12))`,background:`transparent`,color:`inherit`,font:`inherit`,cursor:`pointer`,flexShrink:`0`});let Q=()=>{C()&&e.historySessionState.nextMessageCursor&&e.session.getActiveConversationId()?(Z.textContent=t.showEarlierMessagesLabel,Z.parentNode!==e.body&&e.body.insertBefore(Z,e.body.firstChild)):Z.remove()};Z.addEventListener(`click`,()=>{let t=e.session.getActiveConversationId(),n=e.historySessionState.nextMessageCursor;if(!t||!n||Z.disabled)return;Z.disabled=!0;let r=e.body.scrollHeight,i=e.body.scrollTop;e.session.loadOlderMessages(t,n,{scope:T()}).then(()=>{e.body.scrollTop=i+(e.body.scrollHeight-r),e.repinAnchoredMessage()}).catch(()=>{}).finally(()=>{Z.disabled=!1,Q()})});let Vt=()=>{let n=e.createHeaderIconButton({ariaLabel:t.openHistoryLabel,iconName:`history`,wrapperClassName:`persona-relative persona-inline-flex persona-items-center persona-justify-center`,extraClassName:`persona-history-toggle`,attrs:{"data-persona-history-toggle":``}});return n.button.addEventListener(`click`,t=>{C()&&!ee()&&(e.historyVisible?q():_t({invoker:n.button,keyboard:t.detail===0}))}),n},Ht=()=>{if(!C()){g?.remove(),m=null,g=null;return}if(g&&!g.isConnected&&(m=null,g=null),!m&&e.header){let t=Vt();m=t.button,g=t.wrapper;let n=e.panelElements.clearChatButtonWrapper||e.panelElements.closeButtonWrapper;n?.parentNode&&e.header.contains(n)?n.parentNode.insertBefore(g,n):e.header.appendChild(g)}if(!m||!g)return;let n=G()||e.historyVisible&&e.historyPresentation===`rail`;if(g.style.display=n?`none`:``,n){document.activeElement===m&>();return}let r=ee();m.disabled=r,m.setAttribute(`aria-disabled`,r?`true`:`false`);let i=r?t.openHistoryBusyLabel:t.openHistoryLabel;m.setAttribute(`aria-label`,i),(e.config.features?.history?.presentation??`panel`)===`panel`?(m.removeAttribute(`aria-expanded`),m.removeAttribute(`aria-controls`)):(m.setAttribute(`aria-expanded`,e.historyVisible?`true`:`false`),m.setAttribute(`aria-controls`,S))},Ut=!1,Wt=()=>{let n=e.panelElements.clearChatButton;n&&(C()?(Ut||=(y=n.getAttribute(`aria-label`)??``,!0),n.setAttribute(`aria-label`,t.newConversationLabel),n.removeAttribute(`title`)):Ut&&(Ut=!1,y&&n.setAttribute(`aria-label`,y)))},$=()=>{t=r(e.config.features?.history?.copy),Ht(),tt(),Wt(),Q()};return e.historyChromeSync=$,se(),$(),e.destroyCallbacks.push(()=>{b?.(),x?.(),v+=1,vt(),o?.dispose(),o?.view.destroy(),o=null}),{clearConversationOpenPending:X,cancelConversationOpenTakeover:Y,historyOperationScope:T,discardConversationContinuity:e.discardConversationContinuity,historyAvailable:C,historyScope:w,installHistoryProvider:se,syncHistoryChromeImpl:$,syncHistoryPresentation:mt,syncEarlierMessagesPill:Q,openHistory:_t,closeHistory:q,openHistoryConversation:At,startNewConversation:jt,updateHistoryConversation:Mt,deleteHistoryConversation:Nt,requestDeleteConversation:Rt,clearConversationHistory:Pt,resetHistoryIdentity:Ft,railCollapseShortcut:ze,railCollapsible:we,railTriggerApplies:G,railOverlayMode:ke,toggleRailCollapsed:Re,toggleRailPinned:()=>Le(),get historyProvider(){return i},get historySurface(){return o},get railShell(){return j},get railHost(){return M},get railColumn(){return Se}}};export{k as createHistoryShell};
|
package/dist/history-view.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as HistoryViewPresentation, c as HistoryListState, d as ResolvedHistoryViewCopy, f as resolveHistoryViewCopy, i as HistoryViewPendingAction, l as HISTORY_VIEW_COPY_DEFAULTS, n as HistoryViewHandle, o as createHistoryView, r as HistoryViewOptions, s as HistoryListErrorReason, t as showHistoryConfirm, u as HistoryViewCopyInput } from "./history-confirm-dialog-
|
|
1
|
+
import { a as HistoryViewPresentation, c as HistoryListState, d as ResolvedHistoryViewCopy, f as resolveHistoryViewCopy, i as HistoryViewPendingAction, l as HISTORY_VIEW_COPY_DEFAULTS, n as HistoryViewHandle, o as createHistoryView, r as HistoryViewOptions, s as HistoryListErrorReason, t as showHistoryConfirm, u as HistoryViewCopyInput } from "./history-confirm-dialog-B3L7QNcO.cjs";
|
|
2
2
|
export { HISTORY_VIEW_COPY_DEFAULTS, type HistoryListErrorReason, type HistoryListState, type HistoryViewCopyInput, type HistoryViewHandle, type HistoryViewOptions, type HistoryViewPendingAction, type HistoryViewPresentation, type ResolvedHistoryViewCopy, createHistoryView, resolveHistoryViewCopy, showHistoryConfirm };
|
|
3
3
|
export {}
|
package/dist/history-view.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as HistoryViewPresentation, c as HistoryListState, d as ResolvedHistoryViewCopy, f as resolveHistoryViewCopy, i as HistoryViewPendingAction, l as HISTORY_VIEW_COPY_DEFAULTS, n as HistoryViewHandle, o as createHistoryView, r as HistoryViewOptions, s as HistoryListErrorReason, t as showHistoryConfirm, u as HistoryViewCopyInput } from "./history-confirm-dialog-
|
|
1
|
+
import { a as HistoryViewPresentation, c as HistoryListState, d as ResolvedHistoryViewCopy, f as resolveHistoryViewCopy, i as HistoryViewPendingAction, l as HISTORY_VIEW_COPY_DEFAULTS, n as HistoryViewHandle, o as createHistoryView, r as HistoryViewOptions, s as HistoryListErrorReason, t as showHistoryConfirm, u as HistoryViewCopyInput } from "./history-confirm-dialog-B3L7QNcO.js";
|
|
2
2
|
export { HISTORY_VIEW_COPY_DEFAULTS, type HistoryListErrorReason, type HistoryListState, type HistoryViewCopyInput, type HistoryViewHandle, type HistoryViewOptions, type HistoryViewPendingAction, type HistoryViewPresentation, type ResolvedHistoryViewCopy, createHistoryView, resolveHistoryViewCopy, showHistoryConfirm };
|
|
3
3
|
export {}
|