@runtypelabs/persona 4.25.0 → 4.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animations/glyph-cycle.d.cts +1 -1
- package/dist/animations/glyph-cycle.d.ts +1 -1
- package/dist/animations/{types-Db61aI9J.d.cts → types-BwKTZhg9.d.cts} +14 -0
- package/dist/animations/{types-Db61aI9J.d.ts → types-BwKTZhg9.d.ts} +14 -0
- package/dist/animations/wipe.d.cts +1 -1
- package/dist/animations/wipe.d.ts +1 -1
- package/dist/animations-extra.d.cts +14 -0
- package/dist/animations-extra.d.ts +14 -0
- package/dist/approval-ui-QAKWNFNM.js +1 -0
- package/dist/approval-ui.cjs +2 -2
- package/dist/approval-ui.d.cts +186 -8
- package/dist/approval-ui.d.ts +186 -8
- package/dist/approval-ui.js +2 -2
- package/dist/{artifacts-ui-IGB5YKLO.js → artifacts-ui-NJGMM27I.js} +1 -1
- package/dist/artifacts-ui.cjs +4 -4
- package/dist/artifacts-ui.d.cts +186 -8
- package/dist/artifacts-ui.d.ts +186 -8
- package/dist/artifacts-ui.js +5 -5
- package/dist/chunk-2ANTRKTV.js +1 -0
- package/dist/chunk-4HPTPUC6.js +1 -0
- package/dist/chunk-6V3MNEKB.js +1 -0
- package/dist/chunk-GKPCIQPB.js +1 -0
- package/dist/chunk-HGUCGM3K.js +9 -0
- package/dist/chunk-IO5VVUKP.js +3 -0
- package/dist/chunk-J4J3Y2P2.js +1 -0
- package/dist/chunk-K6HKIP5K.js +1 -0
- package/dist/chunk-K7NA7G7J.js +1 -0
- package/dist/chunk-MXUTS3LB.js +1 -0
- package/dist/chunk-PDPVORUF.js +1 -0
- package/dist/chunk-QRKGQPU7.js +1 -0
- package/dist/chunk-S6PBWE75.js +1 -0
- package/dist/chunk-T7QM7YMF.js +1 -0
- package/dist/chunk-TR2H475E.js +1 -0
- package/dist/chunk-UPO4GUFC.js +1 -0
- package/dist/chunk-ZC66NAIR.js +1 -0
- package/dist/client-history-GOZWBDA5.js +1 -0
- package/dist/client-history.js +1 -0
- package/dist/client-stream-42FOI3EC.js +4 -0
- package/dist/client-stream.js +5 -0
- package/dist/codegen.cjs +1 -1
- package/dist/codegen.js +1 -1
- package/dist/context-mentions-E7HJYWO6.js +161 -0
- package/dist/{context-mentions-inline-I2RDEBAK.js → context-mentions-inline-QVESLW55.js} +1 -1
- package/dist/context-mentions.cjs +7 -7
- package/dist/context-mentions.d.cts +186 -8
- package/dist/context-mentions.d.ts +186 -8
- package/dist/context-mentions.js +8 -8
- package/dist/event-stream-view-FOIJHFQO.js +1 -0
- package/dist/event-stream-view.cjs +1 -1
- package/dist/event-stream-view.d.cts +189 -31
- package/dist/event-stream-view.d.ts +189 -31
- package/dist/event-stream-view.js +1 -1
- package/dist/forms-ui.d.cts +227 -667
- package/dist/forms-ui.d.ts +227 -667
- package/dist/history-shell-QDQ44PSE.js +3 -0
- package/dist/history-shell.js +3 -0
- package/dist/{history-view-BD6OXLNA.js → history-view-NCFBI5GR.js} +2 -2
- package/dist/history-view.cjs +2 -2
- package/dist/history-view.d.cts +35 -1
- package/dist/history-view.d.ts +35 -1
- package/dist/history-view.js +2 -2
- package/dist/index.cjs +80 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +233 -738
- package/dist/index.d.ts +233 -738
- package/dist/index.global.js +3 -215
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +81 -75
- 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 +3 -67
- package/dist/launcher.global.js.map +1 -1
- package/dist/markdown-parsers.js +22 -22
- package/dist/runtype-tts-entry-NFBVWR7N.js +1 -0
- package/dist/runtype-tts.js +1 -1
- package/dist/session-actions-ISSKSI66.js +1 -0
- package/dist/session-actions.js +1 -0
- package/dist/session-reconnect.d.cts +186 -8
- package/dist/session-reconnect.d.ts +186 -8
- package/dist/smart-dom-reader.cjs +13 -13
- package/dist/smart-dom-reader.d.cts +186 -8
- package/dist/smart-dom-reader.d.ts +186 -8
- package/dist/smart-dom-reader.js +11 -11
- package/dist/theme-editor-preview.cjs +116 -98
- package/dist/theme-editor-preview.d.cts +188 -8
- package/dist/theme-editor-preview.d.ts +188 -8
- package/dist/theme-editor-preview.js +49 -54
- package/dist/theme-editor.cjs +2 -2
- package/dist/theme-editor.d.cts +187 -23
- package/dist/theme-editor.d.ts +187 -23
- package/dist/theme-editor.js +2 -2
- package/dist/theme-reference.d.cts +14 -0
- package/dist/theme-reference.d.ts +14 -0
- package/dist/ui-extras-entry-WAYFKVNW.js +3 -0
- package/dist/ui-extras.js +72 -0
- package/dist/voice-runtime-XLU6YK2N.js +17 -0
- package/dist/voice-runtime.cjs +17 -1
- package/dist/voice-runtime.d.cts +11656 -232
- package/dist/voice-runtime.d.ts +11656 -232
- package/dist/voice-runtime.js +17 -1
- package/dist/voice-worklet-player.cjs +19 -4
- package/dist/voice-worklet-player.d.cts +9 -10
- package/dist/voice-worklet-player.d.ts +9 -10
- package/dist/voice-worklet-player.js +19 -4
- package/dist/webmcp-polyfill.js +1 -1
- package/dist/webmcp-runtime-V6ZWW3PI.js +6 -0
- package/dist/webmcp-runtime.cjs +2 -2
- package/dist/webmcp-runtime.d.cts +1 -33
- package/dist/webmcp-runtime.d.ts +1 -33
- package/dist/webmcp-runtime.js +2 -2
- package/dist/widget.css +1 -1
- package/package.json +11 -5
- package/src/approval-paused-tool-settle.test.ts +325 -0
- package/src/client-approve.test.ts +311 -0
- package/src/client-history-eager.ts +9 -0
- package/src/client-history-loader.ts +23 -0
- package/src/client-history.ts +579 -0
- package/src/client-resume.ts +177 -0
- package/src/client-stream-eager.ts +12 -0
- package/src/client-stream-loader.ts +25 -0
- package/src/client-stream.ts +1880 -0
- package/src/client.test.ts +31 -1
- package/src/client.ts +293 -2607
- package/src/components/approval-actions.test.ts +27 -0
- package/src/components/approval-actions.ts +27 -3
- package/src/components/message-bubble.test.ts +19 -0
- package/src/components/message-bubble.ts +2 -0
- package/src/components/registry.ts +6 -6
- package/src/components/tool-bubble.test.ts +9 -0
- package/src/components/tool-bubble.ts +1 -0
- package/src/history-shell-bundle.test.ts +54 -0
- package/src/history-shell-eager.ts +12 -0
- package/src/history-shell-loader.ts +27 -0
- package/src/history-shell.ts +2362 -0
- package/src/history-view-loader.ts +2 -0
- package/src/history-view.ts +3 -0
- package/src/index-core.ts +6 -0
- package/src/index-global.ts +90 -248
- package/src/index.ts +13 -0
- package/src/install.ts +6 -4
- package/src/internal/runtype-history-provider.test.ts +1 -0
- package/src/internal/runtype-history-provider.ts +28 -13
- package/src/plugins/registry.ts +8 -8
- package/src/session-actions-chunk.test.ts +55 -0
- package/src/session-actions-eager.ts +11 -0
- package/src/session-actions-loader.ts +37 -0
- package/src/session-actions.ts +909 -0
- package/src/session-history.test.ts +3 -1
- package/src/session.ts +895 -1538
- package/src/session.voice.test.ts +1171 -5
- package/src/styles/widget.css +58 -0
- package/src/theme-editor/state.ts +91 -91
- package/src/types.ts +204 -5
- package/src/ui-ask-user-sheet.ts +382 -0
- package/src/ui-extras-eager.ts +10 -0
- package/src/ui-extras-entry.ts +9 -0
- package/src/ui-extras-loader.ts +26 -0
- package/src/ui.artifact-rail-resize.test.ts +2 -1
- package/src/ui.ask-user-chunk.test.ts +93 -0
- package/src/ui.history-chunk.test.ts +2 -1
- package/src/ui.history-config-provider.test.ts +2 -1
- package/src/ui.history-confirm-fallback.test.ts +142 -0
- package/src/ui.history-controller.test.ts +2 -1
- package/src/ui.history-lifecycle.test.ts +2 -1
- package/src/ui.history-render-hooks.test.ts +2 -1
- package/src/ui.history-shell.test.ts +2 -1
- package/src/ui.rail-overlay.test.ts +2 -1
- package/src/ui.rail-resize.test.ts +2 -1
- package/src/ui.rail-trigger-pending.test.ts +2 -1
- package/src/ui.ts +340 -2770
- package/src/utils/attachment-manager.ts +67 -67
- package/src/utils/constants.ts +3 -0
- package/src/utils/context-mention-controller.ts +323 -323
- package/src/utils/context-mention-manager.ts +40 -40
- package/src/utils/context-mention-orchestrator.ts +28 -0
- package/src/utils/event-stream-buffer.ts +50 -50
- package/src/utils/event-stream-store.ts +43 -43
- package/src/utils/throughput-tracker.ts +34 -34
- package/src/utils/virtual-scroller.ts +67 -67
- package/src/utils/visitor-store.test.ts +50 -0
- package/src/utils/visitor-store.ts +23 -5
- package/src/voice/__fixtures__/voice-wire/README.md +1 -0
- package/src/voice/__fixtures__/voice-wire/client/cancel.json +3 -0
- package/src/voice/__fixtures__/voice-wire/client/context.json +4 -0
- package/src/voice/__fixtures__/voice-wire/client/delegation_result.json +6 -0
- package/src/voice/__fixtures__/voice-wire/client/delegation_update.json +6 -0
- package/src/voice/__fixtures__/voice-wire/client/ping.json +3 -0
- package/src/voice/__fixtures__/voice-wire/client/playback_progress.json +5 -0
- package/src/voice/__fixtures__/voice-wire/client/start.json +3 -0
- package/src/voice/__fixtures__/voice-wire/server/artifact.json +11 -0
- package/src/voice/__fixtures__/voice-wire/server/attached.json +4 -0
- package/src/voice/__fixtures__/voice-wire/server/audio_clear.json +4 -0
- package/src/voice/__fixtures__/voice-wire/server/audio_end.json +3 -0
- package/src/voice/__fixtures__/voice-wire/server/delegation_cancelled.json +5 -0
- package/src/voice/__fixtures__/voice-wire/server/delegation_completed.json +8 -0
- package/src/voice/__fixtures__/voice-wire/server/delegation_started.json +15 -0
- package/src/voice/__fixtures__/voice-wire/server/error.json +6 -0
- package/src/voice/__fixtures__/voice-wire/server/metrics.json +10 -0
- package/src/voice/__fixtures__/voice-wire/server/pong.json +3 -0
- package/src/voice/__fixtures__/voice-wire/server/session_config.json +16 -0
- package/src/voice/__fixtures__/voice-wire/server/transcript_final.json +7 -0
- package/src/voice/__fixtures__/voice-wire/server/transcript_interim.json +4 -0
- package/src/voice/__fixtures__/voice-wire/server/transcript_partial.json +6 -0
- package/src/voice/__fixtures__/voice-wire/server/transcript_update.json +10 -0
- package/src/voice/__fixtures__/voice-wire/server/warning.json +5 -0
- package/src/voice/audio-playback-manager.test.ts +57 -0
- package/src/voice/audio-playback-manager.ts +120 -98
- package/src/voice/browser-voice-provider.ts +37 -37
- package/src/voice/fallback-speech-engine.ts +22 -16
- package/src/voice/keyed-voice-transcript.ts +314 -0
- package/src/voice/mic-state-styles.ts +182 -0
- package/src/voice/read-aloud-controller.ts +46 -44
- package/src/voice/runtype-speech-engine.ts +35 -33
- package/src/voice/runtype-voice-provider.ts +680 -189
- package/src/voice/session-voice-wiring.ts +266 -0
- package/src/voice/voice-delegation.test.ts +71 -0
- package/src/voice/voice-delegation.ts +364 -0
- package/src/voice/voice-turn-tracker.ts +6 -6
- package/src/voice/voice.test.ts +1060 -8
- package/src/voice/worklet-playback-engine.test.ts +81 -0
- package/src/voice/worklet-playback-engine.ts +21 -3
- package/src/voice-runtime-loader.ts +4 -1
- package/src/voice-runtime.ts +7 -0
- package/src/webmcp-runtime-entry.ts +41 -39
- package/dist/approval-ui-3NMYNXBD.js +0 -1
- package/dist/chunk-5EIIHQLQ.js +0 -1
- package/dist/chunk-7CO4T5KB.js +0 -1
- package/dist/chunk-EFJBUH5F.js +0 -1
- package/dist/chunk-R2TMIMDI.js +0 -3
- package/dist/chunk-UTVLOTWB.js +0 -9
- package/dist/context-mentions-45MODWOY.js +0 -161
- package/dist/event-stream-view-GL3ADRY2.js +0 -1
- package/dist/runtype-tts-entry-UJAEF7NZ.js +0 -1
- package/dist/voice-runtime-7DA7MJH4.js +0 -1
- package/dist/webmcp-runtime-JI7T4QYF.js +0 -6
|
@@ -6719,6 +6719,45 @@ type AgentWidgetVoiceRecognitionConfig = {
|
|
|
6719
6719
|
* @default 30000
|
|
6720
6720
|
*/
|
|
6721
6721
|
attachIdleMs?: number;
|
|
6722
|
+
/**
|
|
6723
|
+
* Full-duplex (speech-to-speech, e.g. GPT-Live) calls: run the turns the
|
|
6724
|
+
* voice model hands off to the agent through this widget's normal chat
|
|
6725
|
+
* pipeline. The spoken request becomes the user message, and the answer
|
|
6726
|
+
* renders as a regular assistant message (streaming, tool and approval
|
|
6727
|
+
* UI, WebMCP page tools, persistence) that the voice model then reads
|
|
6728
|
+
* aloud. Only takes effect when the server supports it (it confirms in
|
|
6729
|
+
* `session_config`); otherwise the agent turn runs on the server and its
|
|
6730
|
+
* spoken reply is transcribed, as before. Set `false` to always keep the
|
|
6731
|
+
* agent turn on the server.
|
|
6732
|
+
* @default true
|
|
6733
|
+
*/
|
|
6734
|
+
clientDelegation?: boolean;
|
|
6735
|
+
/**
|
|
6736
|
+
* Full-duplex calls: extra context for the voice model (for example the
|
|
6737
|
+
* page the visitor is on), sent after the chat history as of call start.
|
|
6738
|
+
* The frame goes out once, when the visitor finishes their first
|
|
6739
|
+
* utterance (or at the first agent hand-off). A function is
|
|
6740
|
+
* called at call start and may be async. This text is capped at 4000 characters and the whole frame
|
|
6741
|
+
* (history included) at 8000. Sent only to servers that accept call
|
|
6742
|
+
* context (they announce it in `session_config`).
|
|
6743
|
+
*/
|
|
6744
|
+
callContext?: string | (() => string | Promise<string>);
|
|
6745
|
+
/**
|
|
6746
|
+
* Full-duplex calls with client delegation: how long a tool approval
|
|
6747
|
+
* that a spoken request raised may wait before it is declined as
|
|
6748
|
+
* expired (and the voice model says so). Server-side approval gates
|
|
6749
|
+
* keep their own timeout too. Hanging up never declines it: the
|
|
6750
|
+
* approval card in the chat stays usable. Capped at 540000 (9 minutes),
|
|
6751
|
+
* under the server's 10-minute delegation deadline.
|
|
6752
|
+
* @default 300000
|
|
6753
|
+
*/
|
|
6754
|
+
approvalTimeoutMs?: number;
|
|
6755
|
+
/**
|
|
6756
|
+
* Speech-to-speech calls: the one-line notice shown in the composer
|
|
6757
|
+
* status area when the call starts. `false` hides it.
|
|
6758
|
+
* @default "You're talking to an AI assistant. Voice is processed by OpenAI."
|
|
6759
|
+
*/
|
|
6760
|
+
disclosureText?: string | false;
|
|
6722
6761
|
/** @deprecated No-op on the realtime path: the server's STT owns turn-taking. */
|
|
6723
6762
|
pauseDuration?: number;
|
|
6724
6763
|
/** @deprecated No-op on the realtime path: the server's STT owns turn-taking. */
|
|
@@ -6948,6 +6987,13 @@ interface VoicePlaybackEngine {
|
|
|
6948
6987
|
onFinished(callback: () => void): void;
|
|
6949
6988
|
/** Release all audio resources. */
|
|
6950
6989
|
destroy(): Promise<void> | void;
|
|
6990
|
+
/**
|
|
6991
|
+
* Optional. Speech-to-speech calls stream reply audio with no end-of-stream
|
|
6992
|
+
* marker, so an engine that holds audio below a prebuffer waterline must, while
|
|
6993
|
+
* continuous, release that held tail on its own (e.g. after a short input gap)
|
|
6994
|
+
* instead of waiting for {@link markStreamEnd}. Engines without a prebuffer can omit it.
|
|
6995
|
+
*/
|
|
6996
|
+
setContinuousMode?(enabled: boolean): void;
|
|
6951
6997
|
}
|
|
6952
6998
|
/**
|
|
6953
6999
|
* A {@link VoicePlaybackEngine} that also supports pause/resume. Returned by
|
|
@@ -6991,14 +7037,23 @@ interface VoiceProvider {
|
|
|
6991
7037
|
* Register a callback for incremental transcript updates during a voice turn.
|
|
6992
7038
|
* `isFinal=false` is a live interim update (user partials, or assistant deltas
|
|
6993
7039
|
* on providers that stream them); `isFinal=true` finalizes that role's text.
|
|
6994
|
-
* On the realtime `runtype` path, interim updates fire for the `user`
|
|
6995
|
-
* the `assistant` arrives as a single final
|
|
6996
|
-
*
|
|
6997
|
-
*
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
7040
|
+
* On the classic realtime `runtype` path, interim updates fire for the `user`
|
|
7041
|
+
* only and the `assistant` arrives as a single final; without a turnId the
|
|
7042
|
+
* session assumes strictly alternating turns, and providers must discard
|
|
7043
|
+
* cancelled output before emitting the next user final.
|
|
7044
|
+
*
|
|
7045
|
+
* When `metadata.turnId` is present (full-duplex / speech-to-speech, e.g.
|
|
7046
|
+
* GPT-Live), the session reconciles by `(turnId, role)`: each pair owns one
|
|
7047
|
+
* bubble that later updates replace in place, turns may overlap or arrive in
|
|
7048
|
+
* any order, and no empty assistant placeholder is injected. User and
|
|
7049
|
+
* assistant may share a turnId (a late user bubble then renders above its
|
|
7050
|
+
* reply) or use distinct ones. `metadata.startMs` (call-relative ms when the
|
|
7051
|
+
* utterance began) orders a new bubble among the call's other keyed bubbles;
|
|
7052
|
+
* without it bubbles order by first arrival. After a stop, keyed providers
|
|
7053
|
+
* must drop the cancelled reply's output until the server acknowledges the
|
|
7054
|
+
* cancel: the session renders every reply it receives.
|
|
7055
|
+
*/
|
|
7056
|
+
onTranscript?(callback: (role: 'user' | 'assistant', text: string, isFinal: boolean, metadata?: VoiceTranscriptMetadata) => void): void;
|
|
7002
7057
|
/** Register a callback for per-turn latency metrics (realtime path). */
|
|
7003
7058
|
onMetrics?(callback: (metrics: VoiceMetrics) => void): void;
|
|
7004
7059
|
/**
|
|
@@ -7026,6 +7081,115 @@ interface VoiceProvider {
|
|
|
7026
7081
|
* repeatedly; throttle as needed.
|
|
7027
7082
|
*/
|
|
7028
7083
|
prewarm?(): void;
|
|
7084
|
+
/**
|
|
7085
|
+
* Called by the session once after construction with the chat-side surface
|
|
7086
|
+
* a full-duplex provider uses to hand agent turns to the chat pipeline
|
|
7087
|
+
* ({@link VoiceSessionBridge}). Providers without client delegation omit it.
|
|
7088
|
+
*/
|
|
7089
|
+
setSessionBridge?(bridge: VoiceSessionBridge): void;
|
|
7090
|
+
/** The AI-disclosure notice for the live call, if one should show (speech-to-speech). */
|
|
7091
|
+
getDisclosure?(): string | null;
|
|
7092
|
+
}
|
|
7093
|
+
/** Metadata on a {@link VoiceProvider.onTranscript} update. */
|
|
7094
|
+
type VoiceTranscriptMetadata = {
|
|
7095
|
+
/** Groups updates that belong to one utterance bubble (full duplex). */
|
|
7096
|
+
turnId?: string;
|
|
7097
|
+
/** Call-relative ms when the utterance began; orders late bubbles. */
|
|
7098
|
+
startMs?: number;
|
|
7099
|
+
/** Call-relative ms of the latest audio this update covers. */
|
|
7100
|
+
endMs?: number;
|
|
7101
|
+
/**
|
|
7102
|
+
* The bubble only captions speech (see `AgentWidgetMessage.voiceCaption`).
|
|
7103
|
+
* The chat pipeline owns the conversation, as with client delegation.
|
|
7104
|
+
*/
|
|
7105
|
+
caption?: boolean;
|
|
7106
|
+
};
|
|
7107
|
+
/** An agent turn a full-duplex voice model handed to the widget. */
|
|
7108
|
+
type VoiceDelegationRequest = {
|
|
7109
|
+
/** The voice model's delegation id (`delegation_started.delegationId`). */
|
|
7110
|
+
delegationId: string;
|
|
7111
|
+
/** What the visitor asked, as the voice model heard it. */
|
|
7112
|
+
userText: string;
|
|
7113
|
+
/**
|
|
7114
|
+
* The user transcript utterances `userText` joins, oldest first (the last
|
|
7115
|
+
* is the one it came from). May be empty.
|
|
7116
|
+
*/
|
|
7117
|
+
userUtteranceIds: string[];
|
|
7118
|
+
/** The voice model's view of the conversation it delegated from. */
|
|
7119
|
+
messages: Array<{
|
|
7120
|
+
role: string;
|
|
7121
|
+
content: unknown;
|
|
7122
|
+
}>;
|
|
7123
|
+
};
|
|
7124
|
+
/**
|
|
7125
|
+
* How a delegated turn ended, or that it waits on an approval (contract
|
|
7126
|
+
* Amendment 5). `pending_approval` is the only non-terminal status. Open:
|
|
7127
|
+
* a receiver treats an unknown terminal status as `failed`.
|
|
7128
|
+
* - `completed`: the work ran.
|
|
7129
|
+
* - `denied`: the visitor said no (Deny tap, or a spoken decline).
|
|
7130
|
+
* - `timeout`: the approval lapsed (`approvalTimeoutMs`, or the server's own timeout).
|
|
7131
|
+
* - `cancelled`: replaced by a newer request, or abandoned by the system.
|
|
7132
|
+
* - `failed`: an error.
|
|
7133
|
+
*/
|
|
7134
|
+
type VoiceDelegationStatus = 'completed' | 'pending_approval' | 'denied' | 'timeout' | 'cancelled' | 'failed' | (string & {});
|
|
7135
|
+
/** The terminal result of a turn that parked on approvals. */
|
|
7136
|
+
type VoiceDelegationFollowUp = {
|
|
7137
|
+
status: VoiceDelegationStatus;
|
|
7138
|
+
/** What to read aloud (Markdown allowed). May be empty: nothing more to say. */
|
|
7139
|
+
text: string;
|
|
7140
|
+
};
|
|
7141
|
+
/** The delegated turn's answer, sent back for the voice model to read aloud. */
|
|
7142
|
+
type VoiceDelegationResult = {
|
|
7143
|
+
/** `pending_approval` when `followUp` is set; otherwise terminal. */
|
|
7144
|
+
status: VoiceDelegationStatus;
|
|
7145
|
+
/** The assistant text (Markdown allowed). */
|
|
7146
|
+
text: string;
|
|
7147
|
+
/**
|
|
7148
|
+
* `false` when no chat message carries this answer (it is only spoken), so
|
|
7149
|
+
* the voice model's read-back of it stays visible as a caption.
|
|
7150
|
+
* @default true
|
|
7151
|
+
*/
|
|
7152
|
+
inChat?: boolean;
|
|
7153
|
+
/**
|
|
7154
|
+
* Set when the turn parked on approvals (`text` then asks for the decision).
|
|
7155
|
+
* Resolves with the terminal result once the visitor decides (or the
|
|
7156
|
+
* approval is replaced, declined by voice, or unanswered for
|
|
7157
|
+
* `approvalTimeoutMs`) and the resumed turn finishes; `null` only when
|
|
7158
|
+
* `signal` aborts first (hang-up, or the server cancelled the delegation).
|
|
7159
|
+
*/
|
|
7160
|
+
followUp?: (options: {
|
|
7161
|
+
signal: AbortSignal;
|
|
7162
|
+
approvalTimeoutMs?: number;
|
|
7163
|
+
/** `false`: run only the approval bookkeeping (expiry, supersede); nothing will be read back. @default true */
|
|
7164
|
+
readBack?: boolean;
|
|
7165
|
+
/** The resumed turn stopped on another approval: ask for it too (`text` is its approval script). */
|
|
7166
|
+
onUpdate?: (text: string) => void;
|
|
7167
|
+
}) => Promise<VoiceDelegationFollowUp | null>;
|
|
7168
|
+
};
|
|
7169
|
+
/**
|
|
7170
|
+
* Chat-side surface the session hands a full-duplex provider: the visible
|
|
7171
|
+
* history (for the call-start context) and a way to run a delegated turn
|
|
7172
|
+
* through the normal chat pipeline.
|
|
7173
|
+
*/
|
|
7174
|
+
interface VoiceSessionBridge {
|
|
7175
|
+
/** Visible user/assistant messages, oldest first. */
|
|
7176
|
+
getHistory(): Array<{
|
|
7177
|
+
role: 'user' | 'assistant';
|
|
7178
|
+
content: string;
|
|
7179
|
+
}>;
|
|
7180
|
+
/**
|
|
7181
|
+
* Submit the turn as the visitor's message (reusing its transcript bubble)
|
|
7182
|
+
* and resolve with the assistant's final answer once the turn settles.
|
|
7183
|
+
* Waits for any chat turn already in flight first. Never rejects.
|
|
7184
|
+
*/
|
|
7185
|
+
runDelegatedTurn(request: VoiceDelegationRequest): Promise<VoiceDelegationResult>;
|
|
7186
|
+
/**
|
|
7187
|
+
* The server dropped this delegation's result (cancelled it, or refused a
|
|
7188
|
+
* late result): its chat answer is no longer spoken, so browser TTS may read it.
|
|
7189
|
+
* `expired`: the server's deadline passed, so its pending approvals are
|
|
7190
|
+
* declined too, as the approval TTL would.
|
|
7191
|
+
*/
|
|
7192
|
+
dropDelegation?(delegationId: string, expired?: boolean): void;
|
|
7029
7193
|
}
|
|
7030
7194
|
/**
|
|
7031
7195
|
* Extra context for an approval decision, surfaced to `onDecision` and to the
|
|
@@ -9622,6 +9786,11 @@ type AgentWidgetToolCall = {
|
|
|
9622
9786
|
startedAt?: number;
|
|
9623
9787
|
completedAt?: number;
|
|
9624
9788
|
durationMs?: number;
|
|
9789
|
+
/**
|
|
9790
|
+
* The call paused for an approval that was granted, and the agent re-ran it
|
|
9791
|
+
* as a new tool call: that later call carries the result, this one has none.
|
|
9792
|
+
*/
|
|
9793
|
+
superseded?: boolean;
|
|
9625
9794
|
};
|
|
9626
9795
|
/**
|
|
9627
9796
|
* Represents a tool approval request in the chat conversation.
|
|
@@ -9643,6 +9812,8 @@ type AgentWidgetApproval = {
|
|
|
9643
9812
|
*/
|
|
9644
9813
|
reason?: string;
|
|
9645
9814
|
parameters?: unknown;
|
|
9815
|
+
/** The paused tool call this approval gates (`approval_start.toolCallId`). */
|
|
9816
|
+
toolCallId?: string;
|
|
9646
9817
|
resolvedAt?: number;
|
|
9647
9818
|
};
|
|
9648
9819
|
type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool" | "approval";
|
|
@@ -9742,6 +9913,13 @@ type AgentWidgetMessage = {
|
|
|
9742
9913
|
* }
|
|
9743
9914
|
*/
|
|
9744
9915
|
voiceProcessing?: boolean;
|
|
9916
|
+
/**
|
|
9917
|
+
* Display-only caption of full-duplex voice speech, such as the voice
|
|
9918
|
+
* model's own words, or something the visitor said that wasn't submitted
|
|
9919
|
+
* as a chat turn. It renders in the transcript but is never sent to the
|
|
9920
|
+
* model as conversation.
|
|
9921
|
+
*/
|
|
9922
|
+
voiceCaption?: boolean;
|
|
9745
9923
|
/**
|
|
9746
9924
|
* Raw structured payload for this message (e.g., JSON action response).
|
|
9747
9925
|
* Populated automatically when structured parsers run.
|
package/dist/context-mentions.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var T=(r,e)=>{let t=document.createElement(r);return e&&(t.className=e),t};var M=(r,e={},...t)=>{let o=document.createElement(r);if(e.className&&(o.className=e.className),e.text!==void 0&&(o.textContent=e.text),e.attrs)for(let[s,n]of Object.entries(e.attrs))o.setAttribute(s,n);if(e.style){let s=o.style,n=e.style;for(let i of Object.keys(n)){let f=n[i];f!=null&&(s[i]=f)}}let a=t.filter(s=>s!=null);return a.length>0&&o.append(...a),o};var ee=[["path",{d:"m21 21-4.34-4.34"}],["circle",{cx:"11",cy:"11",r:"8"}]];var te=[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]];var V=(r,e=24,t="currentColor",o=2)=>{if(!Array.isArray(r))return null;let a=document.createElementNS("http://www.w3.org/2000/svg","svg");return a.setAttribute("width",String(e)),a.setAttribute("height",String(e)),a.setAttribute("viewBox","0 0 24 24"),a.setAttribute("fill","none"),a.setAttribute("stroke",t),a.setAttribute("stroke-width",String(o)),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),a.setAttribute("aria-hidden","true"),r.forEach(s=>{if(!Array.isArray(s)||s.length<2)return;let n=s[0],i=s[1];if(!i)return;let f=document.createElementNS("http://www.w3.org/2000/svg",n);Object.entries(i).forEach(([l,
|
|
2
|
-
`)){let o=/^ {0,3}(`+)/.exec(t);o&&o[1].length>e&&(e=o[1].length)}return e}function oe(r,e){let t="`".repeat(Math.max(3,
|
|
1
|
+
var T=(r,e)=>{let t=document.createElement(r);return e&&(t.className=e),t};var M=(r,e={},...t)=>{let o=document.createElement(r);if(e.className&&(o.className=e.className),e.text!==void 0&&(o.textContent=e.text),e.attrs)for(let[s,n]of Object.entries(e.attrs))o.setAttribute(s,n);if(e.style){let s=o.style,n=e.style;for(let i of Object.keys(n)){let f=n[i];f!=null&&(s[i]=f)}}let a=t.filter(s=>s!=null);return a.length>0&&o.append(...a),o};var ee=[["path",{d:"m21 21-4.34-4.34"}],["circle",{cx:"11",cy:"11",r:"8"}]];var te=[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]];var V=(r,e=24,t="currentColor",o=2)=>{if(!Array.isArray(r))return null;let a=document.createElementNS("http://www.w3.org/2000/svg","svg");return a.setAttribute("width",String(e)),a.setAttribute("height",String(e)),a.setAttribute("viewBox","0 0 24 24"),a.setAttribute("fill","none"),a.setAttribute("stroke",t),a.setAttribute("stroke-width",String(o)),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),a.setAttribute("aria-hidden","true"),r.forEach(s=>{if(!Array.isArray(s)||s.length<2)return;let n=s[0],i=s[1];if(!i)return;let f=document.createElementNS("http://www.w3.org/2000/svg",n);Object.entries(i).forEach(([l,d])=>{l!=="stroke"&&f.setAttribute(l,String(d))}),a.appendChild(f)}),a};var fe=null,le=r=>{fe=r},K=(r,e,t,o)=>fe?.(r,e,t,o)??null;function ie(r){let{ref:e,config:t,onRemove:o}=r;if(t.renderMentionChip){let x="resolving",v,k=t.renderMentionChip({ref:e,status:x,payload:v,remove:o});return{get el(){return k},setStatus:(g,A)=>{if(g===x&&A===v)return;x=g,v=A;let P=t.renderMentionChip({ref:e,status:x,payload:v,remove:o});k.replaceWith(P),k=P}}}let a=e.iconName??t.chipIconName??"at-sign",s=M("div",{className:"persona-mention-chip",attrs:{"data-persona-mention-chip":"","data-status":"resolving",title:e.label}}),n=T("span","persona-mention-chip-icon"),i=x=>{n.replaceChildren();let v=K(x,13,"currentColor",2);v&&n.appendChild(v)};i(a);let f=T("span","persona-mention-chip-spinner"),l=M("span",{className:"persona-mention-chip-label",text:e.label}),d=M("button",{className:"persona-mention-chip-remove",attrs:{type:"button","aria-label":`Remove ${e.label} context`}}),c=V(te,11,"currentColor",2.5);return c?d.appendChild(c):d.textContent="\xD7",d.addEventListener("click",x=>{x.preventDefault(),x.stopPropagation(),o()}),s.appendChild(f),s.appendChild(l),s.appendChild(d),{el:s,setStatus:x=>{s.setAttribute("data-status",x),x==="resolving"?(f.parentNode!==s&&s.insertBefore(f,l),n.parentNode===s&&n.remove(),s.setAttribute("title",e.label)):(f.parentNode===s&&f.remove(),n.parentNode!==s&&s.insertBefore(n,l),x==="error"?(i("triangle-alert"),s.setAttribute("title",`Couldn't add ${e.label} to context`)):(i(a),s.setAttribute("title",e.label)))}}}function ue(r){r.style.display=r.childElementCount>0?"flex":"none"}function we(r){let e=0;for(let t of r.split(`
|
|
2
|
+
`)){let o=/^ {0,3}(`+)/.exec(t);o&&o[1].length>e&&(e=o[1].length)}return e}function oe(r,e){let t="`".repeat(Math.max(3,we(e)+1));return`${t}${r}
|
|
3
3
|
${e}
|
|
4
|
-
${t}`}function
|
|
4
|
+
${t}`}function Ae(r,e,t){return e.includes("</document_content>")?oe(r,e):`<document index="${t+1}">
|
|
5
5
|
<source>${r}</source>
|
|
6
6
|
<document_content>
|
|
7
7
|
${e}
|
|
8
8
|
</document_content>
|
|
9
|
-
</document>`}function de(r,e,t="fenced"){if(typeof t=="function")try{return t(r,e)}catch(o){return console.warn("[persona] contextMentions.llmFormat threw; falling back to the fenced format for this mention",o),oe(r.label,r.text)}return t==="document"?
|
|
9
|
+
</document>`}function de(r,e,t="fenced"){if(typeof t=="function")try{return t(r,e)}catch(o){return console.warn("[persona] contextMentions.llmFormat threw; falling back to the fenced format for this mention",o),oe(r.label,r.text)}return t==="document"?Ae(r.label,r.text,e):oe(r.label,r.text)}function X(r,e){return{sourceId:r.id,itemId:e.id,label:e.label,iconName:e.iconName,color:e.color}}var pe=(r,e)=>`${r}\0${e}`,$=class{constructor(e){this.mentions=[];this.#e=e,this.#s()}#e;get#i(){return this.#e.mentionConfig.maxMentions??8}hasMentions(){return this.mentions.length>0}add(e,t,o=""){let a=pe(e.id,t.id);if(this.mentions.some(i=>i.key===a))return this.#r(e,t,"duplicate");if(this.atLimit())return this.#r(e,t,"limit");let s=X(e,t),n={key:a,source:e,item:t,ref:s,status:"resolving",args:o};return n.chip=ie({ref:s,config:this.#e.mentionConfig,onRemove:()=>this.remove(a)}),n.chip.el.setAttribute("data-persona-chip-enter",""),n.chip.el.addEventListener("animationend",()=>n.chip?.el.removeAttribute("data-persona-chip-enter"),{once:!0}),this.#e.contextRow.appendChild(n.chip.el),this.#m(n),this.#s(),!0}atLimit(){return this.mentions.length>=this.#i}admit(e,t){return this.atLimit()?this.#r(e,t,"limit"):!0}track(e,t,o,a="",s){let n={key:e,source:t,item:o,ref:X(t,o),status:"resolving",args:a,reportStatus:s};this.#m(n)}#r(e,t,o){return this.#e.mentionConfig.onMentionRejected?.(t,o),this.#e.emit?.("rejected",{sourceId:e.id,itemId:t.id,reason:o}),!1}#m(e){this.mentions.push(e),e.source.resolveOn==="submit"?(e.status="ready",e.chip?.setStatus("ready"),e.reportStatus?.("resolved")):e.resolvePromise=this.#n(e),this.#e.announce(`Added ${e.ref.label} to context`)}#h(e,t,o=this.#e.getComposerText()){return{messages:this.#e.getMessages(),config:this.#e.getConfig(),composerText:o,args:t,signal:e}}async#n(e){let t=new AbortController;e.abort=t;try{let o=await e.source.resolve(e.item,this.#h(t.signal,e.args));if(t.signal.aborted)return;e.payload=o,e.status="ready",e.chip?.setStatus("ready",o),e.reportStatus?.("resolved")}catch(o){if(t.signal.aborted)return;e.status="error",e.chip?.setStatus("error"),e.reportStatus?.("error"),(this.#e.announceError??this.#e.announce)(`Couldn't attach ${e.ref.label} to context`),this.#e.mentionConfig.onMentionResolveError?.(e.item,o),this.#e.emit?.("resolve-error",{sourceId:e.source.id,itemId:e.item.id})}}remove(e){let t=this.mentions.findIndex(a=>a.key===e);if(t===-1)return;let[o]=this.mentions.splice(t,1);o.abort?.abort(),o.chip?.el.remove(),this.#s(),this.#e.announce(`Removed ${o.ref.label} from context`)}getRefs(){return this.mentions.map(e=>e.ref)}removeLast(){let e=this.mentions[this.mentions.length-1];return e?(this.remove(e.key),!0):!1}clear(){for(let e of this.mentions)e.abort?.abort(),e.chip?.el.remove();this.mentions.length=0,this.#s()}collectForSubmit(){let e=[...this.mentions],t=e.map(s=>s.ref),o=this.#e.getComposerText();for(let s of e)s.chip?.el.remove();return this.mentions.length=0,this.#s(),{refs:t,finalize:async()=>{let s=await Promise.all(e.map(async d=>{try{return d.source.resolveOn==="submit"?await d.source.resolve(d.item,this.#h(new AbortController().signal,d.args,o)):(d.resolvePromise&&await d.resolvePromise,d.payload??null)}catch(c){try{this.#e.mentionConfig.onMentionResolveError?.(d.item,c)}catch(p){typeof console<"u"&&console.warn("[Persona] onMentionResolveError callback threw",p)}return this.#e.emit?.("resolve-error",{sourceId:d.source.id,itemId:d.item.id}),null}})),n=[],i=[],f={},l=new Set;for(let d=0;d<e.length;d++){let c=e[d],p=s[d];if(!p)continue;let x=pe(c.source.id,c.item.id);if(!l.has(x)){if(l.add(x),p.llmAppend&&p.llmAppend.trim())try{n.push(de({label:c.ref.label,text:p.llmAppend,ref:c.ref,item:c.item},n.length,this.#e.mentionConfig.llmFormat))}catch(v){typeof console<"u"&&console.warn("[Persona] context-mention llmFormat threw",v)}p.contentParts?.length&&i.push(...p.contentParts),p.context&&((f[c.source.id]??={})[c.item.id]=p.context)}}return{blocks:n,contentParts:i,context:f}}}}#s(){ue(this.#e.contextRow)}};var _=r=>r.nodeType===Node.DOCUMENT_NODE,xe=r=>r.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&r.host!==void 0;function me(r){let e=r.getRootNode?.();return e&&xe(e)||e&&_(e)?e:r.ownerDocument??document}function Z(r,e,t){let o=_(r)?r.head:r,a=e.replace(/["\\]/g,"\\$&");if(o.querySelector(`style[data-persona-plugin-style="${a}"]`))return;let n=(_(r)?r:r.ownerDocument??document).createElement("style");n.setAttribute("data-persona-plugin-style",e),n.textContent=t,o.appendChild(n)}function ce(r,e,t){if(_(r)||xe(r)){Z(r,e,t);return}let o=r;if(o.isConnected){Z(me(o),e,t);return}let a=o.ownerDocument??document;Z(a,e,t),queueMicrotask(()=>{let s=me(o);s!==a&&Z(s,e,t)})}function Pe(r){let e=r.getRootNode?.();return e instanceof ShadowRoot?e:(r.ownerDocument??document).body}function ge(r){let{anchor:e,content:t,placement:o="bottom-start",offset:a=6,matchAnchorWidth:s=!1,horizontalOffset:n,verticalOffset:i,zIndex:f=2147483e3,onOpen:l,onDismiss:d}=r,c=r.container??Pe(e),p=!1,x=null,v=()=>{if(!p)return;let g=e.getBoundingClientRect();t.style.position="fixed",s&&(t.style.minWidth=`${g.width}px`),n&&(t.style.maxWidth=`${g.width}px`);let A=t.getBoundingClientRect(),P=i?.()??null,O=P!=null?g.top+P:g.top,N=o==="top-start"||o==="top-end"?O-a-A.height:g.bottom+a,W=o==="bottom-end"||o==="top-end"?g.right-A.width:g.left,J=n?.()??null;if(J!=null){let se=Math.max(g.left,g.right-A.width);W=Math.min(Math.max(g.left+J,g.left),se)}t.style.top=`${N}px`,t.style.left=`${W}px`},k=()=>{p&&(p=!1,x&&(x(),x=null),t.remove())},E=()=>{if(p)return;p=!0,f!=null&&(t.style.zIndex=String(f)),c.appendChild(t),v();let g=(e.ownerDocument??document).defaultView??window,A=e.ownerDocument??document,P=()=>{if(!e.isConnected){k(),d?.("anchor-removed");return}v()},O=G=>{let W=typeof G.composedPath=="function"?G.composedPath():[];W.includes(t)||W.includes(e)||(k(),d?.("outside"))},N=g.setTimeout(()=>{A.addEventListener("pointerdown",O,!0)},0);g.addEventListener("scroll",P,!0),g.addEventListener("resize",P),x=()=>{g.clearTimeout(N),A.removeEventListener("pointerdown",O,!0),g.removeEventListener("scroll",P,!0),g.removeEventListener("resize",P)},l?.()};return{get isOpen(){return p},open:E,close:k,toggle:()=>p?k():E(),reposition:v,destroy:k}}var he=`
|
|
10
10
|
.persona-mention-menu {
|
|
11
11
|
box-sizing: border-box;
|
|
12
12
|
display: flex;
|
|
@@ -164,11 +164,11 @@ ${e}
|
|
|
164
164
|
min-height: 36px;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
`;var Ce=/\s/;function
|
|
168
|
-
`:o===""||Ce.test(o)}function Re(r,e,t="@",o="anywhere",a=!1){if(!t||e<=0||e>r.length)return null;let s=e-1;for(;s>=0;){let n=r[s];if(n===t)return
|
|
169
|
-
`||n==="\uFFFC"||!a&&Ce.test(n))return null;s--}return null}function re(r,e,t){for(let o of t){let a=Re(r,e,o.trigger,o.position??"anywhere",o.allowSpaces??!1);if(a)return{channel:o,match:a}}return null}function Se(r,e,t){return{value:r.slice(0,e.triggerIndex)+r.slice(t),caret:e.triggerIndex}}function Me(r){let e={trigger:r.trigger??"@",position:r.triggerPosition??"anywhere",allowSpaces:!1,sources:Array.isArray(r.sources)?r.sources:[],searchPlaceholder:r.searchPlaceholder,showButton:r.showButton!==!1,buttonIconName:r.buttonIconName,buttonTooltipText:r.buttonTooltipText},t=(r.triggers??[]).map(o=>({trigger:o.trigger,position:o.triggerPosition??"anywhere",allowSpaces:o.allowSpaces??!1,sources:Array.isArray(o.sources)?o.sources:[],searchPlaceholder:o.searchPlaceholder,showButton:o.showButton===!0,buttonIconName:o.buttonIconName,buttonTooltipText:o.buttonTooltipText}));return[e,...t]}function _(r){let e=r.replace(/^\s+/,""),t=e.search(/\s/);return t===-1?{name:e,args:""}:{name:e.slice(0,t),args:e.slice(t+1).trim()}}var ve=new Map,Te=(r,e,t)=>{let o=`${r}|${e}|${t}`,a=ve.get(o);return a===void 0&&(a=K(r,e,"currentColor",t),ve.set(o,a)),a?a.cloneNode(!0):null};function be(r){let{config:e,listboxId:t}=r,o=M("div",{className:"persona-mention-menu",attrs:{"data-persona-mention-menu":""}}),a=M("div",{className:"persona-mention-search",style:{display:"none"}}),s=T("span","persona-mention-search-icon"),n=V(ee,15,"currentColor",2);n&&s.appendChild(n);let i=M("input",{className:"persona-mention-search-input",attrs:{type:"text",role:"combobox","aria-autocomplete":"list","aria-expanded":"false","aria-controls":t,"aria-label":e.searchPlaceholder??"Search context",placeholder:e.searchPlaceholder??"Search context\u2026",autocomplete:"off",autocapitalize:"off",spellcheck:"false"}});a.append(s,i),i.addEventListener("input",()=>r.onSearchInput?.(i.value)),i.addEventListener("keydown",u=>r.onSearchKeydown?.(u));let f=M("div",{className:"persona-mention-list",attrs:{role:"listbox",id:t,"aria-label":"Context mentions"}});o.append(a,f);let l=[],h=[],p=-1,m=new Map,d=(u,x)=>`${u}\0${x}`,b=u=>`${t}-opt-${u}`,w=u=>`${t}-grp-${u}`,O=(u,x)=>{let C=l[u];C&&(x?C.setAttribute("data-active","true"):C.removeAttribute("data-active"),C.setAttribute("aria-selected",x?"true":"false"),h[u]?.(x))},c=(u,x=!0)=>{p>=0&&p!==u&&O(p,!1),p=u;let C=l[u];C?(O(u,!0),x&&C.scrollIntoView?.({block:"nearest"}),f.setAttribute("aria-activedescendant",C.id),i.setAttribute("aria-activedescendant",C.id)):(f.removeAttribute("aria-activedescendant"),i.removeAttribute("aria-activedescendant"))},k=(u,x)=>{let C=w(x),v=M("div",{className:"persona-mention-group",attrs:{role:"group","aria-labelledby":C}});return v.appendChild(M("div",{className:"persona-mention-group-header",attrs:{id:C},text:u})),v},P=()=>{let u=M("div",{className:"persona-mention-option",attrs:{role:"option","aria-selected":"false"}}),x=T("span","persona-mention-option-icon");u.appendChild(x);let C="",v=T("span","persona-mention-option-text"),I=T("span","persona-mention-option-labelline"),R=T("span","persona-mention-option-label");I.appendChild(R),v.appendChild(I),u.appendChild(v);let A=null,y=null,S={el:u,index:0,update:(g,q,F)=>{S.index=q,u.id=b(q),u.setAttribute("aria-setsize",String(F)),u.setAttribute("aria-posinset",String(q+1)),u.removeAttribute("data-active"),u.setAttribute("aria-selected","false");let L=g.iconName??e.chipIconName??"at-sign";if(L!==C){C=L;let H=Te(L,15,2);x.replaceChildren(...H?[H]:[])}R.textContent!==g.label&&(R.textContent=g.label);let B=g.commandArgsPlaceholder?`\u2039${g.commandArgsPlaceholder}\u203A`:null;B?(A||(A=T("span","persona-mention-option-arghint"),I.appendChild(A)),A.textContent!==B&&(A.textContent=B)):A&&(A.remove(),A=null),g.description?(y||(y=T("span","persona-mention-option-desc"),v.appendChild(y)),y.textContent!==g.description&&(y.textContent=g.description)):y&&(y.remove(),y=null)}};return u.addEventListener("mousedown",g=>{g.button===0&&(g.preventDefault(),r.onSelectIndex(S.index))}),u.addEventListener("mouseenter",()=>r.onHoverIndex(S.index)),S},E=(u,x,C,v,I)=>{let R=M("div",{className:"persona-mention-option",attrs:{role:"option",id:b(v),"aria-selected":"false","aria-setsize":String(I),"aria-posinset":String(v+1)}}),A=y=>{R.replaceChildren(e.renderMentionItem({item:u,source:x,query:C,active:y,index:v}))};return A(!1),R.addEventListener("mousedown",y=>{y.button===0&&(y.preventDefault(),r.onSelectIndex(v))}),R.addEventListener("mouseenter",()=>r.onHoverIndex(v)),{el:R,paint:A}},N=u=>{let x=M("div",{className:"persona-mention-status persona-mention-error"});if(x.appendChild(M("span",{className:"persona-mention-error-text",text:`Couldn't load ${u.label}`})),r.onRetry){let C=M("button",{className:"persona-mention-retry",attrs:{type:"button"},text:"Retry"});C.addEventListener("mousedown",v=>v.preventDefault()),C.addEventListener("click",v=>{v.preventDefault(),r.onRetry(u.id)}),x.appendChild(C)}return x};return{el:o,render:u=>{f.replaceChildren(),l=[],h=[],p=-1;let x=new Set,C=0,v=0,I=0,R=0,A=0,y=u.groups.reduce((S,g)=>g.status==="ready"?S+g.items.length:S,0);for(let S of u.groups)if(S.status==="loading"){I++;let g=k(S.source.label,A++);g.appendChild(M("div",{className:"persona-mention-status persona-mention-loading",attrs:{role:"presentation"},text:"Loading\u2026"})),f.appendChild(g)}else if(S.status==="error"){R++;let g=k(S.source.label,A++);g.appendChild(N(S.source)),f.appendChild(g)}else if(S.status==="ready"&&S.items.length>0){let g=new Map;for(let F of S.items){let L=F.group??S.source.label,B=g.get(L);B?B.push(F):g.set(L,[F])}let q=Array.from(g.entries());q.forEach(([F,L],B)=>{let H=k(F,A++);for(let Y of L){let ne=C++,z;if(e.renderMentionItem){let D=E(Y,S.source,u.query,ne,y);z=D.el,h.push(D.paint)}else{let D=d(S.source.id,Y.id),U=x.has(D)?void 0:m.get(D);U||(U=P(),x.has(D)||m.set(D,U)),x.add(D),U.update(Y,ne,y),z=U.el,h.push(null)}l.push(z),H.appendChild(z),v++}S.truncated&&B===q.length-1&&H.appendChild(M("div",{className:"persona-mention-hint",attrs:{role:"presentation"},text:"Keep typing to narrow\u2026"})),f.appendChild(H)})}for(let S of m.keys())x.has(S)||m.delete(S);v===0&&I===0&&R===0&&f.appendChild(M("div",{className:"persona-mention-empty",attrs:{role:"presentation"},text:"No matches"})),l.length>0?c(Math.min(Math.max(0,u.activeIndex),l.length-1)):(f.removeAttribute("aria-activedescendant"),i.removeAttribute("aria-activedescendant"))},setActiveIndex:c,destroy:()=>{f.replaceChildren(),l=[],m.clear(),o.remove()},showSearch:(u,x)=>{i.value=u,x&&(i.placeholder=x),a.style.display="",i.setAttribute("aria-expanded","true"),i.focus(),typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{a.style.display!=="none"&&i.focus()})},hideSearch:()=>{a.style.display="none",i.value="",i.setAttribute("aria-expanded","false"),i.removeAttribute("aria-activedescendant")}}}var Ie=r=>!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function",Le=0,j=class{constructor(e){this.popover=null;this.resizeObserver=null;this.isOpenState=!1;this.query="";this.triggerMatch=null;this.activeIndex=0;this.activeKey=null;this.pickerMode=!1;this.pickerTrigger=null;this.groups=[];this.flat=[];this.searchToken=0;this.searchAbort=null;this.debounceTimer=null;this.knownAsync=new Set;this.invokedForToken=new Set;this.lastAnnouncedCount=-1;this.triggerAnchorOffset=null;this.measuredTriggerIndex=null;this.opts=e;let t=e.mentionConfig,o=Me(t),a=o.filter(n=>n.sources.length>0);this.channels=a.length>0?a:[o[0]],this.activeChannel=this.channels[0],this.maxPerGroup=t.maxItemsPerGroup??6,this.debounceMs=t.searchDebounceMs??150,this.listboxId=`persona-mention-listbox-${++Le}`,this.menu=e.mentionConfig.renderMentionMenu?this.createHostMenu():be({config:e.mentionConfig,listboxId:this.listboxId,onSelectIndex:n=>this.selectIndex(n),onHoverIndex:n=>this.setActiveIndex(n,!1),onRetry:n=>this.retrySource(n),onSearchInput:n=>this.setQuery(n),onSearchKeydown:n=>{this.handleKeydown(n)}});let s=e.composerInput.element;s.setAttribute("aria-haspopup","listbox"),s.setAttribute("aria-controls",this.listboxId)}get input(){return this.opts.composerInput}createHostMenu(){let e=document.createElement("div");e.setAttribute("data-persona-mention-menu",""),e.setAttribute("role","listbox"),e.id=this.listboxId;let t=()=>{let o=this.opts.mentionConfig.renderMentionMenu({query:this.query,groups:this.groups.map(a=>({source:a.source,items:a.items})),status:Object.fromEntries(this.groups.map(a=>[a.source.id,a.status])),activeIndex:this.activeIndex,select:a=>{let s=this.groups.find(n=>n.items.includes(a));s&&this.commit(s.source,a)},close:()=>this.close()});e.replaceChildren(o)};return{el:e,render:t,setActiveIndex:t,destroy:()=>e.remove()}}isOpen(){return this.isOpenState}openFromButton(e){let t=e&&this.channels.find(n=>n.trigger===e)||this.channels[0],o=this.input.getSelection().start,a=re(this.input.getLogicalText(),o,[t]);if(a){this.pickerMode=!1,this.triggerMatch=a.match,this.isOpenState?(this.switchChannel(t),this.setQuery(a.match.query)):this.open(a.match.query,t),this.input.focus();return}let s=this.pickerTrigger;this.pickerMode=!0,this.pickerTrigger=t.trigger,this.triggerMatch=null,this.isOpenState?(s&&s!==t.trigger&&this.opts.onPickerOpenChange?.(!1,s,this.listboxId),this.switchChannel(t),this.setQuery("")):this.open("",t),this.menu.showSearch?this.menu.showSearch("",t.searchPlaceholder):this.input.focus(),this.opts.onPickerOpenChange?.(!0,t.trigger,this.listboxId)}onInput(){let e=this.input.getSelection().start,t=re(this.input.getLogicalText(),e,this.channels);if(!t){this.isOpenState&&this.close();return}if(this.isInlineArgTail(t.channel,t.match.query)){this.triggerMatch=null,this.isOpenState&&this.close(!1);return}this.triggerMatch=t.match,this.isOpenState?(this.switchChannel(t.channel),this.measuredTriggerIndex!==t.match.triggerIndex&&this.updateTriggerAnchor(),this.setQuery(t.match.query)):this.open(t.match.query,t.channel)}switchChannel(e){e!==this.activeChannel&&(this.activeChannel=e,this.groups=[],this.activeIndex=0)}open(e,t){if(this.isOpenState=!0,this.activeChannel=t,this.groups=[],this.activeIndex=0,this.lastAnnouncedCount=-1,!this.popover){let o=this.canAnchorMenu();if(this.popover=ge({anchor:this.opts.anchor,content:this.menu.el,placement:"top-start",matchAnchorWidth:!o,offset:6,container:this.opts.popoverContainer,horizontalOffset:o?()=>this.triggerAnchorOffset?.x??null:void 0,verticalOffset:o?()=>this.triggerAnchorOffset?.y??null:void 0,onDismiss:()=>this.close(!1)}),o){let a=this.opts.anchor.getBoundingClientRect().width;this.menu.el.style.minWidth=`${Math.min(220,a)}px`}}this.updateTriggerAnchor(),this.popover.open(),ce(this.menu.el,"persona-mention-menu",he),this.observeComposerResize(),this.opts.emit?.("opened",{trigger:t.trigger}),this.setQuery(e)}observeComposerResize(){typeof ResizeObserver>"u"||this.resizeObserver||(this.resizeObserver=new ResizeObserver(()=>{this.isOpenState&&(this.updateTriggerAnchor(),this.popover?.reposition())}),this.resizeObserver.observe(this.opts.anchor))}disconnectComposerResize(){this.resizeObserver?.disconnect(),this.resizeObserver=null}canAnchorMenu(){return this.isInlineDisplay()&&!!this.input.getLogicalRangeRect}updateTriggerAnchor(){let e=this.triggerMatch,t=this.input.getLogicalRangeRect;if(this.measuredTriggerIndex=e?.triggerIndex??null,this.triggerAnchorOffset=null,!e||!t)return;let o=t(e.triggerIndex,e.triggerIndex+1);if(!o)return;let a=this.opts.anchor.getBoundingClientRect(),s=o.top-a.top,n=this.input.element,i=typeof getComputedStyle=="function"&&getComputedStyle(n).direction==="rtl";this.triggerAnchorOffset={x:i?null:o.left-a.left,y:s}}close(e=!0){this.isOpenState&&(this.isOpenState=!1,this.disconnectComposerResize(),this.debounceTimer&&clearTimeout(this.debounceTimer),this.searchAbort?.abort(),this.searchToken++,this.popover?.close(),this.input.element.removeAttribute("aria-activedescendant"),this.pickerMode&&(this.pickerMode=!1,this.menu.hideSearch?.(),this.opts.onPickerOpenChange?.(!1,this.pickerTrigger??this.activeChannel.trigger,this.listboxId),this.pickerTrigger=null,e&&this.input.focus()))}setQuery(e){this.query=e,this.activeIndex=0,this.activeKey=null;let t=++this.searchToken;this.invokedForToken.clear(),this.searchAbort?.abort(),this.searchAbort=new AbortController;for(let o of this.activeChannel.sources)this.knownAsync.has(o.id)?this.setGroupStatus(o.id,"loading"):(this.invokedForToken.add(o.id),this.invokeSource(o,t));this.render(),this.debounceTimer&&clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(()=>{if(t===this.searchToken)for(let o of this.activeChannel.sources)this.knownAsync.has(o.id)&&!this.invokedForToken.has(o.id)&&this.invokeSource(o,t)},this.debounceMs)}invokeSource(e,t){let o={messages:this.opts.getMessages(),config:this.opts.getConfig(),signal:this.searchAbort.signal},a;try{a=e.search(this.query,o)}catch{this.setGroupStatus(e.id,"error"),this.render();return}Ie(a)?(this.knownAsync.add(e.id),this.setGroupStatus(e.id,"loading"),a.then(s=>{t===this.searchToken&&(this.setGroupItems(e.id,s),this.render())}).catch(()=>{t===this.searchToken&&(this.setGroupStatus(e.id,"error"),this.render())})):this.setGroupItems(e.id,a)}getOrCreateGroup(e){let t=this.groups.find(o=>o.source.id===e.id);if(!t){t={source:e,items:[],status:"loading",truncated:!1};let o=this.activeChannel.sources;this.groups.push(t),this.groups.sort((a,s)=>o.findIndex(n=>n.id===a.source.id)-o.findIndex(n=>n.id===s.source.id))}return t}setGroupStatus(e,t){let o=this.activeChannel.sources.find(a=>a.id===e);o&&(this.getOrCreateGroup(o).status=t)}setGroupItems(e,t){let o=this.activeChannel.sources.find(s=>s.id===e);if(!o)return;let a=this.getOrCreateGroup(o);a.truncated=t.length>this.maxPerGroup,a.items=t.slice(0,this.maxPerGroup),a.status=a.items.length===0?"empty":"ready"}keyOf(e){return JSON.stringify([e.source.id,e.item.id])}rebuildFlat(){this.flat=[];for(let e of this.groups)if(e.status==="ready")for(let t of e.items)this.flat.push({source:e.source,item:t});if(this.activeKey){let e=this.flat.findIndex(t=>this.keyOf(t)===this.activeKey);this.activeIndex=e>=0?e:Math.min(this.activeIndex,Math.max(0,this.flat.length-1))}else this.activeIndex>=this.flat.length&&(this.activeIndex=Math.max(0,this.flat.length-1))}viewModel(){return{query:this.query,groups:this.groups,activeIndex:this.activeIndex}}render(){this.rebuildFlat(),this.menu.render(this.viewModel()),this.syncActiveDescendant(),this.popover?.reposition();let e=this.groups.some(t=>t.status==="loading");this.flat.length===0&&e||this.flat.length!==this.lastAnnouncedCount&&(this.lastAnnouncedCount=this.flat.length,this.opts.announce(this.flat.length===0?"No matches":this.flat.length===1?"1 result":`${this.flat.length} results`),this.opts.emit?.("searched",{query:this.query,results:this.flat.length}))}setActiveIndex(e,t=!0){e<0||e>=this.flat.length||(this.activeIndex=e,this.activeKey=this.keyOf(this.flat[e]),this.menu.setActiveIndex(e,t),this.syncActiveDescendant())}syncActiveDescendant(){this.isOpenState&&!this.pickerMode&&this.activeIndex>=0&&this.activeIndex<this.flat.length?this.input.element.setAttribute("aria-activedescendant",`${this.listboxId}-opt-${this.activeIndex}`):this.input.element.removeAttribute("aria-activedescendant")}retrySource(e){let t=this.activeChannel.sources.find(o=>o.id===e);!t||!this.searchAbort||(this.setGroupStatus(e,"loading"),this.render(),this.invokeSource(t,this.searchToken),this.render())}handleKeydown(e){if(!this.isOpenState)return!1;switch(e.key){case"ArrowDown":return this.flat.length===0||(e.preventDefault(),this.setActiveIndex((this.activeIndex+1)%this.flat.length)),!0;case"ArrowUp":return this.flat.length===0||(e.preventDefault(),this.setActiveIndex((this.activeIndex-1+this.flat.length)%this.flat.length)),!0;case"Home":return this.flat.length===0||(e.preventDefault(),this.setActiveIndex(0)),!0;case"End":return this.flat.length===0||(e.preventDefault(),this.setActiveIndex(this.flat.length-1)),!0;case"Enter":case"Tab":return this.flat.length===0?(this.close(),!1):(e.preventDefault(),this.selectIndex(this.activeIndex),!0);case"Escape":return e.preventDefault(),this.close(),!0;case"Backspace":return this.query.length===0&&this.close(),!1;default:return!1}}selectIndex(e){let t=this.flat[e];t&&this.commit(t.source,t.item)}deriveArgs(e){return _(e).args}isInlineCommand(e){return e.command==="server"||e.commandArgsPlaceholder!=null}commit(e,t){let o=t.command;if(this.isInlineCommand(t)){this.completeCommandInline(e,t);return}if(o==="action"){let s=this.deriveArgs(this.query);this.stripQuery(),this.close(),this.runAction(t,s),this.opts.emit?.("command",{sourceId:e.id,itemId:t.id,kind:"action",args:s}),this.input.focus();return}if(o==="prompt"){let s=this.deriveArgs(this.query),n=this.captureStripTarget();this.close(),this.runPromptMacro(e,t,s,n),this.opts.emit?.("command",{sourceId:e.id,itemId:t.id,kind:"prompt",args:s});return}if(this.isInlineDisplay()){this.commitInlineMention(e,t);return}this.opts.onSelect(e,t,"")&&(this.stripQuery(),this.opts.emit?.("selected",{sourceId:e.id,itemId:t.id,label:t.label})),this.close(),this.input.focus()}isInlineDisplay(){return this.opts.mentionConfig.display==="inline"&&!!this.opts.onInsertMention&&!!this.input.insertMentionAtTrigger}commitInlineMention(e,t){if(this.opts.admitMention&&!this.opts.admitMention(e,t)){this.close(),this.input.focus();return}let o=X(e,t),a=this.triggerMatch?this.input.insertMentionAtTrigger(o,this.triggerMatch):this.input.insertMentionAtSelection?.(o)??null;a?(this.opts.onInsertMention(a,e,t,""),this.opts.emit?.("selected",{sourceId:e.id,itemId:t.id,label:t.label})):(this.opts.mentionConfig.onMentionRejected?.(t,"stale"),this.opts.emit?.("rejected",{sourceId:e.id,itemId:t.id,reason:"stale"})),this.triggerMatch=null,this.close(),this.input.focus()}completeCommandInline(e,t){let o=`${this.activeChannel.trigger}${t.label} `,a=this.input.getSelection().start,s=this.triggerMatch?this.triggerMatch.triggerIndex:a;if(this.input.replaceLogicalRange)this.input.replaceLogicalRange(s,a,o);else{let n=this.input.getValue();this.input.setValueWithCaret(n.slice(0,s)+o+n.slice(a),s+o.length)}this.triggerMatch=null,this.close(),this.opts.emit?.("command",{sourceId:e.id,itemId:t.id,kind:t.command??"prompt",phase:"armed"}),this.input.dispatchInput(),this.input.focus()}isInlineArgTail(e,t){let{name:o}=_(t);return!o||t.length<=o.length?!1:e.sources.some(a=>{let s=a.matchCommand?.(o);return!!s&&this.isInlineCommand(s)})}matchInlineCommand(e){for(let t of this.channels){if(!t.trigger)continue;let o=t.position==="anywhere"?[e]:t.position==="line-start"?e.split(`
|
|
167
|
+
`;var Ce=/\s/;function ke(r,e,t){if(t==="input-start")return e===0;let o=e>0?r[e-1]:"";return t==="line-start"?o===""||o===`
|
|
168
|
+
`:o===""||Ce.test(o)}function Re(r,e,t="@",o="anywhere",a=!1){if(!t||e<=0||e>r.length)return null;let s=e-1;for(;s>=0;){let n=r[s];if(n===t)return ke(r,s,o)?{triggerIndex:s,query:r.slice(s+1,e)}:null;if(n===`
|
|
169
|
+
`||n==="\uFFFC"||!a&&Ce.test(n))return null;s--}return null}function re(r,e,t){for(let o of t){let a=Re(r,e,o.trigger,o.position??"anywhere",o.allowSpaces??!1);if(a)return{channel:o,match:a}}return null}function Se(r,e,t){return{value:r.slice(0,e.triggerIndex)+r.slice(t),caret:e.triggerIndex}}function Me(r){let e={trigger:r.trigger??"@",position:r.triggerPosition??"anywhere",allowSpaces:!1,sources:Array.isArray(r.sources)?r.sources:[],searchPlaceholder:r.searchPlaceholder,showButton:r.showButton!==!1,buttonIconName:r.buttonIconName,buttonTooltipText:r.buttonTooltipText},t=(r.triggers??[]).map(o=>({trigger:o.trigger,position:o.triggerPosition??"anywhere",allowSpaces:o.allowSpaces??!1,sources:Array.isArray(o.sources)?o.sources:[],searchPlaceholder:o.searchPlaceholder,showButton:o.showButton===!0,buttonIconName:o.buttonIconName,buttonTooltipText:o.buttonTooltipText}));return[e,...t]}function Q(r){let e=r.replace(/^\s+/,""),t=e.search(/\s/);return t===-1?{name:e,args:""}:{name:e.slice(0,t),args:e.slice(t+1).trim()}}var be=new Map,Te=(r,e,t)=>{let o=`${r}|${e}|${t}`,a=be.get(o);return a===void 0&&(a=K(r,e,"currentColor",t),be.set(o,a)),a?a.cloneNode(!0):null};function ve(r){let{config:e,listboxId:t}=r,o=M("div",{className:"persona-mention-menu",attrs:{"data-persona-mention-menu":""}}),a=M("div",{className:"persona-mention-search",style:{display:"none"}}),s=T("span","persona-mention-search-icon"),n=V(ee,15,"currentColor",2);n&&s.appendChild(n);let i=M("input",{className:"persona-mention-search-input",attrs:{type:"text",role:"combobox","aria-autocomplete":"list","aria-expanded":"false","aria-controls":t,"aria-label":e.searchPlaceholder??"Search context",placeholder:e.searchPlaceholder??"Search context\u2026",autocomplete:"off",autocapitalize:"off",spellcheck:"false"}});a.append(s,i),i.addEventListener("input",()=>r.onSearchInput?.(i.value)),i.addEventListener("keydown",u=>r.onSearchKeydown?.(u));let f=M("div",{className:"persona-mention-list",attrs:{role:"listbox",id:t,"aria-label":"Context mentions"}});o.append(a,f);let l=[],d=[],c=-1,p=new Map,x=(u,m)=>`${u}\0${m}`,v=u=>`${t}-opt-${u}`,k=u=>`${t}-grp-${u}`,E=(u,m)=>{let C=l[u];C&&(m?C.setAttribute("data-active","true"):C.removeAttribute("data-active"),C.setAttribute("aria-selected",m?"true":"false"),d[u]?.(m))},g=(u,m=!0)=>{c>=0&&c!==u&&E(c,!1),c=u;let C=l[u];C?(E(u,!0),m&&C.scrollIntoView?.({block:"nearest"}),f.setAttribute("aria-activedescendant",C.id),i.setAttribute("aria-activedescendant",C.id)):(f.removeAttribute("aria-activedescendant"),i.removeAttribute("aria-activedescendant"))},A=(u,m)=>{let C=k(m),b=M("div",{className:"persona-mention-group",attrs:{role:"group","aria-labelledby":C}});return b.appendChild(M("div",{className:"persona-mention-group-header",attrs:{id:C},text:u})),b},P=()=>{let u=M("div",{className:"persona-mention-option",attrs:{role:"option","aria-selected":"false"}}),m=T("span","persona-mention-option-icon");u.appendChild(m);let C="",b=T("span","persona-mention-option-text"),L=T("span","persona-mention-option-labelline"),R=T("span","persona-mention-option-label");L.appendChild(R),b.appendChild(L),u.appendChild(b);let w=null,y=null,S={el:u,index:0,update:(h,q,F)=>{S.index=q,u.id=v(q),u.setAttribute("aria-setsize",String(F)),u.setAttribute("aria-posinset",String(q+1)),u.removeAttribute("data-active"),u.setAttribute("aria-selected","false");let B=h.iconName??e.chipIconName??"at-sign";if(B!==C){C=B;let H=Te(B,15,2);m.replaceChildren(...H?[H]:[])}R.textContent!==h.label&&(R.textContent=h.label);let I=h.commandArgsPlaceholder?`\u2039${h.commandArgsPlaceholder}\u203A`:null;I?(w||(w=T("span","persona-mention-option-arghint"),L.appendChild(w)),w.textContent!==I&&(w.textContent=I)):w&&(w.remove(),w=null),h.description?(y||(y=T("span","persona-mention-option-desc"),b.appendChild(y)),y.textContent!==h.description&&(y.textContent=h.description)):y&&(y.remove(),y=null)}};return u.addEventListener("mousedown",h=>{h.button===0&&(h.preventDefault(),r.onSelectIndex(S.index))}),u.addEventListener("mouseenter",()=>r.onHoverIndex(S.index)),S},O=(u,m,C,b,L)=>{let R=M("div",{className:"persona-mention-option",attrs:{role:"option",id:v(b),"aria-selected":"false","aria-setsize":String(L),"aria-posinset":String(b+1)}}),w=y=>{R.replaceChildren(e.renderMentionItem({item:u,source:m,query:C,active:y,index:b}))};return w(!1),R.addEventListener("mousedown",y=>{y.button===0&&(y.preventDefault(),r.onSelectIndex(b))}),R.addEventListener("mouseenter",()=>r.onHoverIndex(b)),{el:R,paint:w}},N=u=>{let m=M("div",{className:"persona-mention-status persona-mention-error"});if(m.appendChild(M("span",{className:"persona-mention-error-text",text:`Couldn't load ${u.label}`})),r.onRetry){let C=M("button",{className:"persona-mention-retry",attrs:{type:"button"},text:"Retry"});C.addEventListener("mousedown",b=>b.preventDefault()),C.addEventListener("click",b=>{b.preventDefault(),r.onRetry(u.id)}),m.appendChild(C)}return m};return{el:o,render:u=>{f.replaceChildren(),l=[],d=[],c=-1;let m=new Set,C=0,b=0,L=0,R=0,w=0,y=u.groups.reduce((S,h)=>h.status==="ready"?S+h.items.length:S,0);for(let S of u.groups)if(S.status==="loading"){L++;let h=A(S.source.label,w++);h.appendChild(M("div",{className:"persona-mention-status persona-mention-loading",attrs:{role:"presentation"},text:"Loading\u2026"})),f.appendChild(h)}else if(S.status==="error"){R++;let h=A(S.source.label,w++);h.appendChild(N(S.source)),f.appendChild(h)}else if(S.status==="ready"&&S.items.length>0){let h=new Map;for(let F of S.items){let B=F.group??S.source.label,I=h.get(B);I?I.push(F):h.set(B,[F])}let q=Array.from(h.entries());q.forEach(([F,B],I)=>{let H=A(F,w++);for(let Y of B){let ne=C++,z;if(e.renderMentionItem){let D=O(Y,S.source,u.query,ne,y);z=D.el,d.push(D.paint)}else{let D=x(S.source.id,Y.id),U=m.has(D)?void 0:p.get(D);U||(U=P(),m.has(D)||p.set(D,U)),m.add(D),U.update(Y,ne,y),z=U.el,d.push(null)}l.push(z),H.appendChild(z),b++}S.truncated&&I===q.length-1&&H.appendChild(M("div",{className:"persona-mention-hint",attrs:{role:"presentation"},text:"Keep typing to narrow\u2026"})),f.appendChild(H)})}for(let S of p.keys())m.has(S)||p.delete(S);b===0&&L===0&&R===0&&f.appendChild(M("div",{className:"persona-mention-empty",attrs:{role:"presentation"},text:"No matches"})),l.length>0?g(Math.min(Math.max(0,u.activeIndex),l.length-1)):(f.removeAttribute("aria-activedescendant"),i.removeAttribute("aria-activedescendant"))},setActiveIndex:g,destroy:()=>{f.replaceChildren(),l=[],p.clear(),o.remove()},showSearch:(u,m)=>{i.value=u,m&&(i.placeholder=m),a.style.display="",i.setAttribute("aria-expanded","true"),i.focus(),typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{a.style.display!=="none"&&i.focus()})},hideSearch:()=>{a.style.display="none",i.value="",i.setAttribute("aria-expanded","false"),i.removeAttribute("aria-activedescendant")}}}var Le=r=>!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function",Be=0,j=class{#e;#i;#r;#m;#h;#n;#s;#d=null;#C=null;#f=!1;#u="";#o=null;#a=0;#y=null;#S=!1;#w=null;#l=[];#t=[];#x=0;#c=null;#p=null;#P=new Set;#k=new Set;#R=-1;#A=null;#F=null;constructor(e){this.#e=e;let t=e.mentionConfig,o=Me(t),a=o.filter(n=>n.sources.length>0);this.#i=a.length>0?a:[o[0]],this.#r=this.#i[0],this.#m=t.maxItemsPerGroup??6,this.#h=t.searchDebounceMs??150,this.#s=`persona-mention-listbox-${++Be}`,this.#n=e.mentionConfig.renderMentionMenu?this.#$():ve({config:e.mentionConfig,listboxId:this.#s,onSelectIndex:n=>this.#N(n),onHoverIndex:n=>this.#v(n,!1),onRetry:n=>this.#J(n),onSearchInput:n=>this.#M(n),onSearchKeydown:n=>{this.handleKeydown(n)}});let s=e.composerInput.element;s.setAttribute("aria-haspopup","listbox"),s.setAttribute("aria-controls",this.#s)}get input(){return this.#e.composerInput}#$(){let e=document.createElement("div");e.setAttribute("data-persona-mention-menu",""),e.setAttribute("role","listbox"),e.id=this.#s;let t=()=>{let o=this.#e.mentionConfig.renderMentionMenu({query:this.#u,groups:this.#l.map(a=>({source:a.source,items:a.items})),status:Object.fromEntries(this.#l.map(a=>[a.source.id,a.status])),activeIndex:this.#a,select:a=>{let s=this.#l.find(n=>n.items.includes(a));s&&this.#G(s.source,a)},close:()=>this.close()});e.replaceChildren(o)};return{el:e,render:t,setActiveIndex:t,destroy:()=>e.remove()}}isOpen(){return this.#f}openFromButton(e){let t=e&&this.#i.find(n=>n.trigger===e)||this.#i[0],o=this.input.getSelection().start,a=re(this.input.getLogicalText(),o,[t]);if(a){this.#S=!1,this.#o=a.match,this.#f?(this.#T(t),this.#M(a.match.query)):this.#L(a.match.query,t),this.input.focus();return}let s=this.#w;this.#S=!0,this.#w=t.trigger,this.#o=null,this.#f?(s&&s!==t.trigger&&this.#e.onPickerOpenChange?.(!1,s,this.#s),this.#T(t),this.#M("")):this.#L("",t),this.#n.showSearch?this.#n.showSearch("",t.searchPlaceholder):this.input.focus(),this.#e.onPickerOpenChange?.(!0,t.trigger,this.#s)}onInput(){let e=this.input.getSelection().start,t=re(this.input.getLogicalText(),e,this.#i);if(!t){this.#f&&this.close();return}if(this.#te(t.channel,t.match.query)){this.#o=null,this.#f&&this.close(!1);return}this.#o=t.match,this.#f?(this.#T(t.channel),this.#F!==t.match.triggerIndex&&this.#B(),this.#M(t.match.query)):this.#L(t.match.query,t.channel)}#T(e){e!==this.#r&&(this.#r=e,this.#l=[],this.#a=0)}#L(e,t){if(this.#f=!0,this.#r=t,this.#l=[],this.#a=0,this.#R=-1,!this.#d){let o=this.#_();if(this.#d=ge({anchor:this.#e.anchor,content:this.#n.el,placement:"top-start",matchAnchorWidth:!o,offset:6,container:this.#e.popoverContainer,horizontalOffset:o?()=>this.#A?.x??null:void 0,verticalOffset:o?()=>this.#A?.y??null:void 0,onDismiss:()=>this.close(!1)}),o){let a=this.#e.anchor.getBoundingClientRect().width;this.#n.el.style.minWidth=`${Math.min(220,a)}px`}}this.#B(),this.#d.open(),ce(this.#n.el,"persona-mention-menu",he),this.#Z(),this.#e.emit?.("opened",{trigger:t.trigger}),this.#M(e)}#Z(){typeof ResizeObserver>"u"||this.#C||(this.#C=new ResizeObserver(()=>{this.#f&&(this.#B(),this.#d?.reposition())}),this.#C.observe(this.#e.anchor))}#E(){this.#C?.disconnect(),this.#C=null}#_(){return this.#z()&&!!this.input.getLogicalRangeRect}#B(){let e=this.#o,t=this.input.getLogicalRangeRect;if(this.#F=e?.triggerIndex??null,this.#A=null,!e||!t)return;let o=t(e.triggerIndex,e.triggerIndex+1);if(!o)return;let a=this.#e.anchor.getBoundingClientRect(),s=o.top-a.top,n=this.input.element,i=typeof getComputedStyle=="function"&&getComputedStyle(n).direction==="rtl";this.#A={x:i?null:o.left-a.left,y:s}}close(e=!0){this.#f&&(this.#f=!1,this.#E(),this.#p&&clearTimeout(this.#p),this.#c?.abort(),this.#x++,this.#d?.close(),this.input.element.removeAttribute("aria-activedescendant"),this.#S&&(this.#S=!1,this.#n.hideSearch?.(),this.#e.onPickerOpenChange?.(!1,this.#w??this.#r.trigger,this.#s),this.#w=null,e&&this.input.focus()))}#M(e){this.#u=e,this.#a=0,this.#y=null;let t=++this.#x;this.#k.clear(),this.#c?.abort(),this.#c=new AbortController;for(let o of this.#r.sources)this.#P.has(o.id)?this.#b(o.id,"loading"):(this.#k.add(o.id),this.#I(o,t));this.#g(),this.#p&&clearTimeout(this.#p),this.#p=setTimeout(()=>{if(t===this.#x)for(let o of this.#r.sources)this.#P.has(o.id)&&!this.#k.has(o.id)&&this.#I(o,t)},this.#h)}#I(e,t){let o={messages:this.#e.getMessages(),config:this.#e.getConfig(),signal:this.#c.signal},a;try{a=e.search(this.#u,o)}catch{this.#b(e.id,"error"),this.#g();return}Le(a)?(this.#P.add(e.id),this.#b(e.id,"loading"),a.then(s=>{t===this.#x&&(this.#W(e.id,s),this.#g())}).catch(()=>{t===this.#x&&(this.#b(e.id,"error"),this.#g())})):this.#W(e.id,a)}#O(e){let t=this.#l.find(o=>o.source.id===e.id);if(!t){t={source:e,items:[],status:"loading",truncated:!1};let o=this.#r.sources;this.#l.push(t),this.#l.sort((a,s)=>o.findIndex(n=>n.id===a.source.id)-o.findIndex(n=>n.id===s.source.id))}return t}#b(e,t){let o=this.#r.sources.find(a=>a.id===e);o&&(this.#O(o).status=t)}#W(e,t){let o=this.#r.sources.find(s=>s.id===e);if(!o)return;let a=this.#O(o);a.truncated=t.length>this.#m,a.items=t.slice(0,this.#m),a.status=a.items.length===0?"empty":"ready"}#q(e){return JSON.stringify([e.source.id,e.item.id])}#Q(){this.#t=[];for(let e of this.#l)if(e.status==="ready")for(let t of e.items)this.#t.push({source:e.source,item:t});if(this.#y){let e=this.#t.findIndex(t=>this.#q(t)===this.#y);this.#a=e>=0?e:Math.min(this.#a,Math.max(0,this.#t.length-1))}else this.#a>=this.#t.length&&(this.#a=Math.max(0,this.#t.length-1))}#j(){return{query:this.#u,groups:this.#l,activeIndex:this.#a}}#g(){this.#Q(),this.#n.render(this.#j()),this.#H(),this.#d?.reposition();let e=this.#l.some(t=>t.status==="loading");this.#t.length===0&&e||this.#t.length!==this.#R&&(this.#R=this.#t.length,this.#e.announce(this.#t.length===0?"No matches":this.#t.length===1?"1 result":`${this.#t.length} results`),this.#e.emit?.("searched",{query:this.#u,results:this.#t.length}))}#v(e,t=!0){e<0||e>=this.#t.length||(this.#a=e,this.#y=this.#q(this.#t[e]),this.#n.setActiveIndex(e,t),this.#H())}#H(){this.#f&&!this.#S&&this.#a>=0&&this.#a<this.#t.length?this.input.element.setAttribute("aria-activedescendant",`${this.#s}-opt-${this.#a}`):this.input.element.removeAttribute("aria-activedescendant")}#J(e){let t=this.#r.sources.find(o=>o.id===e);!t||!this.#c||(this.#b(e,"loading"),this.#g(),this.#I(t,this.#x),this.#g())}handleKeydown(e){if(!this.#f)return!1;switch(e.key){case"ArrowDown":return this.#t.length===0||(e.preventDefault(),this.#v((this.#a+1)%this.#t.length)),!0;case"ArrowUp":return this.#t.length===0||(e.preventDefault(),this.#v((this.#a-1+this.#t.length)%this.#t.length)),!0;case"Home":return this.#t.length===0||(e.preventDefault(),this.#v(0)),!0;case"End":return this.#t.length===0||(e.preventDefault(),this.#v(this.#t.length-1)),!0;case"Enter":case"Tab":return this.#t.length===0?(this.close(),!1):(e.preventDefault(),this.#N(this.#a),!0);case"Escape":return e.preventDefault(),this.close(),!0;case"Backspace":return this.#u.length===0&&this.close(),!1;default:return!1}}#N(e){let t=this.#t[e];t&&this.#G(t.source,t.item)}#U(e){return Q(e).args}#D(e){return e.command==="server"||e.commandArgsPlaceholder!=null}#G(e,t){let o=t.command;if(this.#D(t)){this.#ee(e,t);return}if(o==="action"){let s=this.#U(this.#u);this.#X(),this.close(),this.#K(t,s),this.#e.emit?.("command",{sourceId:e.id,itemId:t.id,kind:"action",args:s}),this.input.focus();return}if(o==="prompt"){let s=this.#U(this.#u),n=this.#re();this.close(),this.#ae(e,t,s,n),this.#e.emit?.("command",{sourceId:e.id,itemId:t.id,kind:"prompt",args:s});return}if(this.#z()){this.#Y(e,t);return}this.#e.onSelect(e,t,"")&&(this.#X(),this.#e.emit?.("selected",{sourceId:e.id,itemId:t.id,label:t.label})),this.close(),this.input.focus()}#z(){return this.#e.mentionConfig.display==="inline"&&!!this.#e.onInsertMention&&!!this.input.insertMentionAtTrigger}#Y(e,t){if(this.#e.admitMention&&!this.#e.admitMention(e,t)){this.close(),this.input.focus();return}let o=X(e,t),a=this.#o?this.input.insertMentionAtTrigger(o,this.#o):this.input.insertMentionAtSelection?.(o)??null;a?(this.#e.onInsertMention(a,e,t,""),this.#e.emit?.("selected",{sourceId:e.id,itemId:t.id,label:t.label})):(this.#e.mentionConfig.onMentionRejected?.(t,"stale"),this.#e.emit?.("rejected",{sourceId:e.id,itemId:t.id,reason:"stale"})),this.#o=null,this.close(),this.input.focus()}#ee(e,t){let o=`${this.#r.trigger}${t.label} `,a=this.input.getSelection().start,s=this.#o?this.#o.triggerIndex:a;if(this.input.replaceLogicalRange)this.input.replaceLogicalRange(s,a,o);else{let n=this.input.getValue();this.input.setValueWithCaret(n.slice(0,s)+o+n.slice(a),s+o.length)}this.#o=null,this.close(),this.#e.emit?.("command",{sourceId:e.id,itemId:t.id,kind:t.command??"prompt",phase:"armed"}),this.input.dispatchInput(),this.input.focus()}#te(e,t){let{name:o}=Q(t);return!o||t.length<=o.length?!1:e.sources.some(a=>{let s=a.matchCommand?.(o);return!!s&&this.#D(s)})}#oe(e){for(let t of this.#i){if(!t.trigger)continue;let o=t.position==="anywhere"?[e]:t.position==="line-start"?e.split(`
|
|
170
170
|
`):[e.split(`
|
|
171
|
-
`)[0]];for(let a of o){if(!a.startsWith(t.trigger))continue;let{name:s,args:n}=
|
|
171
|
+
`)[0]];for(let a of o){if(!a.startsWith(t.trigger))continue;let{name:s,args:n}=Q(a.slice(t.trigger.length));if(s)for(let i of t.sources){let f=i.matchCommand?.(s);if(f&&this.#D(f))return{source:i,item:f,args:n}}}}return null}async dispatchInlineCommand(e){let t=this.#oe(e);if(!t)return null;let{source:o,item:a,args:s}=t,n=a.command??"prompt";if(this.#e.emit?.("command",{sourceId:o.id,itemId:a.id,kind:n,args:s}),n==="action")return this.#K(a,s),{kind:"action"};if(n==="prompt"){let f;try{f=await o.resolve(a,this.#V(s,e))}catch(l){return typeof console<"u"&&console.warn("[Persona] inline prompt command resolve failed",l),null}return{kind:"prompt",sendText:f.insertText??f.llmAppend??e}}return{kind:"server",mentions:{refs:[],finalize:async()=>{let f=await o.resolve(a,this.#V(s,e)),l={};return f.context&&(l[o.id]={[a.id]:f.context}),{blocks:[],contentParts:f.contentParts??[],context:l}}}}}#V(e,t){return{messages:this.#e.getMessages(),config:this.#e.getConfig(),composerText:t,args:e,signal:new AbortController().signal}}#K(e,t){if(e.action)try{Promise.resolve(e.action({args:t,config:this.#e.getConfig(),messages:this.#e.getMessages(),composer:this.input})).catch(o=>{typeof console<"u"&&console.warn("[Persona] context-mention command action failed",o)})}catch(o){typeof console<"u"&&console.warn("[Persona] context-mention command action failed",o)}}#re(){return this.#o?{value:this.input.getValue(),start:this.#o.triggerIndex,end:this.input.getSelection().start}:null}async#ae(e,t,o,a){let s=this.input,n;try{n=await e.resolve(t,{messages:this.#e.getMessages(),config:this.#e.getConfig(),composerText:s.getValue(),args:o,signal:new AbortController().signal})}catch(f){typeof console<"u"&&console.warn("[Persona] context-mention prompt resolve failed",f);return}let i=n.insertText??n.llmAppend??"";t.insertMode==="insert-at-caret"&&a?s.replaceLogicalRange?(s.replaceLogicalRange(a.start,a.end,i),s.dispatchInput()):s.setValue(a.value.slice(0,a.start)+i+a.value.slice(a.end)):s.setValue(i),t.submitOnSelect&&s.submit()}#X(){if(!this.#o)return;let e=this.input.getSelection().start;if(this.input.replaceLogicalRange)this.input.replaceLogicalRange(this.#o.triggerIndex,e,"");else{let t=Se(this.input.getValue(),this.#o,e);this.input.setValueWithCaret(t.value,t.caret)}this.input.dispatchInput(),this.#o=null}destroy(){this.#E(),this.#p&&clearTimeout(this.#p),this.#c?.abort(),this.#d?.destroy(),this.#n.destroy();let e=this.input.element;e.removeAttribute("aria-haspopup"),e.removeAttribute("aria-controls"),e.removeAttribute("aria-activedescendant")}};function Ie(r){r&&(typeof r.requestSubmit=="function"?r.requestSubmit():r.dispatchEvent(new Event("submit",{bubbles:!0,cancelable:!0})))}function ye(r){let e=()=>{r.dispatchEvent(new Event("input",{bubbles:!0}))};return{element:r,getValue:()=>r.value,getLogicalText:()=>r.value,getSelection:()=>({start:r.selectionStart??0,end:r.selectionEnd??0}),setSelection:(t,o=t)=>{r.setSelectionRange(t,o)},setValueWithCaret:(t,o)=>{r.value=t,r.setSelectionRange(o,o)},setValue:t=>{r.value=t,r.setSelectionRange(t.length,t.length),e(),r.focus()},submit:()=>Ie(r.form),dispatchInput:e,focus:()=>r.focus()}}var De={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:"0",overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(50%)",whiteSpace:"nowrap",border:"0"};function ae(r,e){let t=document.createElement("div");t.className="persona-sr-only",t.setAttribute("aria-live",r),t.setAttribute("aria-atomic","true"),t.setAttribute("role",r==="assertive"?"alert":"status"),t.setAttribute("data-persona-mention-live-region","");let o=e.getRootNode();typeof ShadowRoot<"u"&&o instanceof ShadowRoot?(Object.assign(t.style,De),document.body.appendChild(t)):e.appendChild(t);let s;return{announce:n=>{s!==void 0&&clearTimeout(s),t.textContent="",s=setTimeout(()=>{s=void 0,t.textContent=n},0)},destroy:()=>{s!==void 0&&clearTimeout(s),t.remove()}}}function Fe(r){let e=r.composerInput??ye(r.textarea),t=ae("polite",r.liveRegionHost),o=ae("assertive",r.liveRegionHost),a=l=>t.announce(l),s=l=>o.announce(l),n=new $({mentionConfig:r.mentionConfig,contextRow:r.contextRow,getMessages:r.getMessages,getConfig:r.getConfig,getComposerText:()=>e.getValue(),announce:a,announceError:s,emit:r.emit}),i=()=>new j({mentionConfig:r.mentionConfig,composerInput:e,anchor:r.anchor,getMessages:r.getMessages,getConfig:r.getConfig,onSelect:(l,d,c)=>n.add(l,d,c),onInsertMention:(l,d,c,p)=>n.track(l,d,c,p,x=>e.setMentionStatus?.(l,x)),admitMention:(l,d)=>n.admit(l,d),announce:a,popoverContainer:r.popoverContainer,onPickerOpenChange:r.onPickerOpenChange,emit:r.emit}),f=i();return{openMenu:l=>f.openFromButton(l),isMenuOpen:()=>f.isOpen(),handleInput:()=>f.onInput(),handleKeydown:l=>f.handleKeydown(l),hasMentions:()=>n.hasMentions(),getMentionRefs:()=>n.getRefs(),removeLastChip:()=>n.removeLast(),dispatchInlineCommand:l=>f.dispatchInlineCommand(l),collectForSubmit:()=>n.hasMentions()?n.collectForSubmit():null,untrackMention:l=>n.remove(l),rebindComposer:l=>{l!==e&&(f.destroy(),e=l,f=i())},clear:()=>n.clear(),destroy:()=>{f.destroy(),n.clear(),t.destroy(),o.destroy()}}}export{Fe as mountContextMentions,le as setMentionIconRenderer};
|
|
172
172
|
/*! Bundled license information:
|
|
173
173
|
|
|
174
174
|
lucide/dist/esm/icons/search.mjs:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as De,d as $e,e as Ve,f as We}from"./chunk-VK6JOIYJ.js";import{a as _}from"./chunk-7NQ4ZTHF.js";import{a as l}from"./chunk-76IELU7F.js";import{Check as Je,ChevronDown as at,ChevronRight as it,Clipboard as Ue,ClipboardCopy as je,Search as lt,X as qe}from"lucide";function Z(t,e){e&&e.split(/\s+/).forEach(n=>n&&t.classList.add(n))}var z={flow_:{bg:"var(--persona-event-badge-flow-bg, #dcfce7)",text:"var(--persona-event-badge-flow-fg, #15803d)"},step_:{bg:"var(--persona-event-badge-step-bg, #f5f5f5)",text:"var(--persona-event-badge-step-fg, #0a0a0a)"},reasoning_:{bg:"var(--persona-event-badge-reasoning-bg, #fef9c3)",text:"var(--persona-event-badge-reasoning-fg, #a16207)"},tool_:{bg:"var(--persona-event-badge-tool-bg, #f3e8ff)",text:"var(--persona-event-badge-tool-fg, #6b21a8)"},agent_:{bg:"var(--persona-event-badge-agent-bg, #ccfbf1)",text:"var(--persona-event-badge-agent-fg, #115e59)"},error:{bg:"var(--persona-event-badge-error-bg, #fee2e2)",text:"var(--persona-event-badge-error-fg, #b91c1c)"}};z.execution_error=z.error;z.execution_=z.flow_;z.turn_=z.agent_;z.text_=z.agent_;var pt={bg:"var(--persona-event-badge-default-bg, #f3f4f6)",text:"var(--persona-event-badge-default-fg, #4b5563)"},ut=["flowName","stepName","reasoningText","text","name","tool","toolName"],ct=100;function ze(t,e){if(e[t])return e[t];for(let n of Object.keys(e))if(n.endsWith("_")&&t.startsWith(n))return e[n]}function dt(t,e){return(e&&ze(t,e))??ze(t,z)??pt}function ft(t){return/^#[0-9a-fA-F]{6}$/.test(t)?`${t}50`:`color-mix(in srgb, ${t} 31%, transparent)`}function ht(t,e){return`+${((t-e)/1e3).toFixed(3)}s`}function mt(t){let e=new Date(t),n=String(e.getHours()).padStart(2,"0"),r=String(e.getMinutes()).padStart(2,"0"),i=String(e.getSeconds()).padStart(2,"0"),a=String(e.getMilliseconds()).padStart(3,"0");return`${n}:${r}:${i}.${a}`}function gt(t,e){try{let n=JSON.parse(t);if(typeof n!="object"||n===null)return null;for(let r of e){let i=r.split("."),a=n;for(let u of i)if(a&&typeof a=="object"&&a!==null)a=a[u];else{a=void 0;break}if(typeof a=="string"&&a.trim())return a.trim()}}catch{}return null}function vt(t){return navigator.clipboard?.writeText?navigator.clipboard.writeText(t):new Promise(e=>{let n=document.createElement("textarea");n.value=t,n.style.position="fixed",n.style.opacity="0",document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),e()})}function yt(t){let e;try{e=JSON.parse(t.payload)}catch{e=t.payload}return JSON.stringify({type:t.type,timestamp:new Date(t.timestamp).toISOString(),payload:e},null,2)}function bt(t){return t.tokensPerSecond===void 0||!Number.isFinite(t.tokensPerSecond)?"-- tok/s":`${t.tokensPerSecond.toFixed(1)} tok/s`}function xt(t){let e=[];return t.outputTokens!==void 0&&e.push(`${t.outputTokens.toLocaleString()} tok`),t.durationMs!==void 0&&e.push(`${(t.durationMs/1e3).toFixed(2)}s`),t.source&&e.push(t.source),e.join(" \xB7 ")}function St(t,e,n){let r,i;try{i=JSON.parse(t.payload),r=JSON.stringify(i,null,2)}catch{i=t.payload,r=t.payload}let a=e.find(g=>g.renderEventStreamPayload);if(a?.renderEventStreamPayload&&n){let g=a.renderEventStreamPayload({event:t,config:n,defaultRenderer:()=>u(),parsedPayload:i});if(g)return g}return u();function u(){let g=l("div","persona-bg-persona-container persona-border-t persona-border-persona-divider persona-px-3 persona-py-2 persona-ml-4 persona-mr-3 persona-mb-1 persona-rounded-b persona-overflow-auto persona-max-h-[300px]"),b=l("pre","persona-m-0 persona-whitespace-pre-wrap persona-break-all persona-text-[11px] persona-text-persona-secondary persona-font-mono");return b.textContent=r,g.appendChild(b),g}}function xe(t,e,n,r,i,a,u,g){let b=i.has(t.id),x=l("div","persona-border-b persona-border-persona-divider persona-text-xs");Z(x,r.classNames?.eventRow);let pe=u.find(L=>L.renderEventStreamRow);if(pe?.renderEventStreamRow&&g){let L=pe.renderEventStreamRow({event:t,index:e,config:g,defaultRenderer:()=>D(),isExpanded:b,onToggleExpand:()=>a(t.id)});if(L)return x.appendChild(L),x}return x.appendChild(D()),x;function D(){let L=l("div",""),H=l("div","persona-flex persona-items-center persona-gap-2 persona-px-3 persona-py-3 hover:persona-bg-persona-container persona-cursor-pointer persona-group");H.setAttribute("data-event-id",t.id);let ee=l("span","persona-flex-shrink-0 persona-text-persona-muted persona-w-4 persona-text-center persona-flex persona-items-center persona-justify-center"),M=_(b?at:it,"14px","currentColor",2);M&&ee.appendChild(M);let F=l("span","persona-text-[11px] persona-text-persona-muted persona-whitespace-nowrap persona-flex-shrink-0 persona-font-mono persona-w-[70px]"),S=r.timestampFormat??"relative";F.textContent=S==="relative"?ht(t.timestamp,n):mt(t.timestamp);let A=null;r.showSequenceNumbers!==!1&&(A=l("span","persona-text-[11px] persona-text-persona-muted persona-font-mono persona-flex-shrink-0 persona-w-[28px] persona-text-right"),A.textContent=String(e+1));let R=dt(t.type,r.badgeColors),P=l("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded persona-text-[11px] persona-font-mono persona-font-medium persona-whitespace-nowrap persona-flex-shrink-0 persona-border");P.style.backgroundColor=R.bg,P.style.color=R.text,P.style.borderColor=ft(R.text),P.textContent=t.type;let te=r.descriptionFields??ut,Y=gt(t.payload,te),$=null;Y&&($=l("span","persona-text-[11px] persona-text-persona-secondary persona-truncate persona-min-w-0"),$.textContent=Y);let C=l("div","persona-flex-1 persona-min-w-0"),w=l("button","persona-text-persona-muted hover:persona-text-persona-primary persona-cursor-pointer persona-flex-shrink-0 persona-border-none persona-bg-transparent persona-p-0"),ne=_(Ue,"12px","currentColor",1.5);return ne&&w.appendChild(ne),w.addEventListener("click",async X=>{X.stopPropagation(),await vt(yt(t)),w.innerHTML="";let I=_(Je,"12px","currentColor",1.5);I&&w.appendChild(I),setTimeout(()=>{w.innerHTML="";let Q=_(Ue,"12px","currentColor",1.5);Q&&w.appendChild(Q)},1500)}),H.appendChild(ee),H.appendChild(F),A&&H.appendChild(A),H.appendChild(P),$&&H.appendChild($),H.appendChild(C),H.appendChild(w),L.appendChild(H),b&&L.appendChild(St(t,u,g)),L}}function Ge(t){let{buffer:e,getFullHistory:n,onClose:r,config:i,plugins:a=[],getThroughput:u}=t,g=t.renderIconByName??(()=>null),b=i?.features?.scrollToBottom,x=b?.enabled!==!1,pe=b?.iconName??"arrow-down",D=b?.label??"",L=i?.features?.eventStream??{},H=a.find(M=>M.renderEventStreamView);if(H?.renderEventStreamView&&i){let M=H.renderEventStreamView({config:i,events:e.getAll(),defaultRenderer:()=>ee().element,onClose:r});if(M)return{element:M,update:()=>{},destroy:()=>{}}}return ee();function ee(){let M=L.classNames,F=l("div","persona-event-stream-view persona-flex persona-flex-col persona-flex-1 persona-min-h-0");Z(F,M?.panel);let S=[],A="",R="",P=null,te=[],Y={},$=0,C=De(),w=0,ne=0,X=!1,I=null,Q=!1,Ee=0,J=new Set,N=new Map,Ce="",we="",K=null,v,m,y,B,re=null,O=null,V=null;function ge(){let o=l("div","persona-event-toolbar persona-relative persona-flex persona-flex-col persona-flex-shrink-0"),s=l("div","persona-flex persona-items-center persona-gap-2 persona-px-4 persona-py-3 persona-pb-0 persona-border-persona-divider persona-bg-persona-surface persona-overflow-hidden");if(Z(s,M?.headerBar),u){O=l("div","persona-relative persona-flex persona-items-center persona-gap-1.5 persona-whitespace-nowrap"),O.style.cursor="help",re=l("span","persona-text-[11px] persona-font-mono persona-bg-persona-container persona-text-persona-muted persona-px-2 persona-py-0.5 persona-rounded persona-border persona-border-persona-border persona-tabular-nums"),re.textContent="-- tok/s",V=l("div","persona-absolute persona-z-50 persona-whitespace-nowrap persona-rounded persona-border persona-border-persona-border persona-bg-persona-container persona-text-persona-primary persona-text-[11px] persona-font-mono persona-px-2 persona-py-1 persona-shadow"),V.style.display="none",V.style.pointerEvents="none";let q=O,le=V,ot=()=>{if(!le.textContent)return;let Oe=q.getBoundingClientRect(),_e=o.getBoundingClientRect();le.style.left=`${Oe.left-_e.left}px`,le.style.top=`${Oe.bottom-_e.top+4}px`,le.style.display="block"},st=()=>{le.style.display="none"};O.addEventListener("mouseenter",ot),O.addEventListener("mouseleave",st),O.appendChild(re)}let p=l("div","persona-flex-1");v=l("select","persona-text-xs persona-bg-persona-surface persona-border persona-border-persona-border persona-rounded persona-px-2.5 persona-py-1 persona-text-persona-primary persona-cursor-pointer");let E=l("option","");E.value="",E.textContent="All events (0)",v.appendChild(E),m=l("button","persona-inline-flex persona-items-center persona-gap-1.5 persona-rounded persona-text-xs persona-text-persona-muted hover:persona-bg-persona-container hover:persona-text-persona-primary persona-cursor-pointer persona-border persona-border-persona-border persona-bg-persona-surface persona-flex-shrink-0 persona-px-2.5 persona-py-1"),m.type="button",m.title="Copy All";let U=_(je,"12px","currentColor",1.5);U&&m.appendChild(U);let j=l("span","persona-event-copy-all persona-text-xs");j.textContent="Copy All",m.appendChild(j),O&&s.appendChild(O),s.appendChild(p),s.appendChild(v),s.appendChild(m);let c=l("div","persona-relative persona-px-4 persona-py-2.5 persona-border-b persona-border-persona-divider persona-bg-persona-surface");Z(c,M?.searchBar);let d=_(lt,"14px","var(--persona-muted, #9ca3af)",1.5),h=l("span","persona-absolute persona-left-6 persona-top-1/2 persona--translate-y-1/2 persona-pointer-events-none persona-flex persona-items-center");d&&h.appendChild(d),y=l("input","persona-text-sm persona-bg-persona-surface persona-border persona-border-persona-border persona-rounded-md persona-pl-8 persona-pr-3 persona-py-1 persona-w-full persona-text-persona-primary"),Z(y,M?.searchInput),y.type="text",y.placeholder="Search event payloads...",B=l("button","persona-absolute persona-right-5 persona-top-1/2 persona--translate-y-1/2 persona-text-persona-muted hover:persona-text-persona-primary persona-cursor-pointer persona-border-none persona-bg-transparent persona-p-0 persona-leading-none"),B.type="button",B.style.display="none";let k=_(qe,"12px","currentColor",2);return k&&B.appendChild(k),c.appendChild(h),c.appendChild(y),c.appendChild(B),o.appendChild(s),o.appendChild(c),V&&o.appendChild(V),o}let ve,Te=a.find(o=>o.renderEventStreamToolbar);Te?.renderEventStreamToolbar&&i?ve=Te.renderEventStreamToolbar({config:i,defaultRenderer:()=>ge(),eventCount:e.getSize(),filteredCount:0,onFilterChange:s=>{A=s,ie(),G()},onSearchChange:s=>{R=s,ie(),G()}})??ge():ve=ge();let oe=l("div","persona-text-xs persona-text-persona-muted persona-text-center persona-py-0.5 persona-px-4 persona-bg-persona-container persona-border-b persona-border-persona-divider persona-italic persona-flex-shrink-0");oe.style.display="none";function Ze(){if(!u||!re||!O)return;let o=u(),s=bt(o);re.textContent=s;let p=xt(o);V&&(V.textContent=p,p||(V.style.display="none")),O.setAttribute("aria-label",p?`Throughput: ${s}, ${p}`:`Throughput: ${s}`)}let ue=l("div","persona-flex-1 persona-min-h-0 persona-relative"),f=l("div","persona-event-stream-list persona-overflow-y-auto persona-min-h-0");f.style.height="100%";let T=l("div","persona-scroll-to-bottom-indicator persona-absolute persona-bottom-3 persona-left-1/2 persona-transform persona--translate-x-1/2 persona-cursor-pointer persona-z-10 persona-text-xs");Z(T,M?.scrollIndicator),T.style.display="none",T.setAttribute("data-persona-scroll-to-bottom-has-label",D?"true":"false");let ke=g(pe,"14px","currentColor",2);ke&&T.appendChild(ke);let se=l("span","");se.textContent=D,T.appendChild(se);let ae=l("div","persona-flex persona-items-center persona-justify-center persona-h-full persona-text-sm persona-text-persona-muted");ae.style.display="none",ue.appendChild(f),ue.appendChild(ae),ue.appendChild(T),F.setAttribute("tabindex","0"),F.appendChild(ve),F.appendChild(oe),F.appendChild(ue);function et(){let o=e.getAll(),s={};for(let c of o)s[c.type]=(s[c.type]||0)+1;let p=Object.keys(s).sort(),E=p.length!==te.length||!p.every((c,d)=>c===te[d]),W=!E&&p.some(c=>s[c]!==Y[c]),U=o.length!==Object.values(Y).reduce((c,d)=>c+d,0);if(!E&&!W&&!U||(te=p,Y=s,!v))return;let j=v.value;if(v.options[0].textContent=`All events (${o.length})`,E){for(;v.options.length>1;)v.remove(1);for(let c of p){let d=l("option","");d.value=c,d.textContent=`${c} (${s[c]||0})`,v.appendChild(d)}j&&p.includes(j)?v.value=j:j&&(v.value="",A="")}else for(let c=1;c<v.options.length;c++){let d=v.options[c];d.textContent=`${d.value} (${s[d.value]||0})`}}function tt(){let o=e.getAll();if(A&&(o=o.filter(s=>s.type===A)),R){let s=R.toLowerCase();o=o.filter(p=>p.type.toLowerCase().includes(s)||p.payload.toLowerCase().includes(s))}return o}function ye(){return A!==""||R!==""}function ie(){$=0,w=0,C.resume(),T.style.display="none"}function ce(o){J.has(o)?J.delete(o):J.add(o),K=o;let s=f.scrollTop,p=C.isFollowing();Q=!0,C.pause(),G(),f.scrollTop=s,p&&C.resume(),Q=!1}function Re(){return $e(f,50)}function G(){ne=Date.now(),X=!1,Ze(),et();let o=e.getEvictedCount();o>0?(oe.textContent=`${o.toLocaleString()} older events truncated`,oe.style.display=""):oe.style.display="none",S=tt();let s=S.length,p=e.getSize()>0;s===0&&p&&ye()?(ae.textContent=R?`No events matching '${R}'`:"No events matching filter",ae.style.display="",f.style.display="none"):(ae.style.display="none",f.style.display=""),m&&(m.title=ye()?`Copy Filtered (${s})`:"Copy All"),x&&!C.isFollowing()&&s>$&&(w+=s-$,se.textContent=D?`${D}${w>0?` (${w})`:""}`:"",T.style.display=""),$=s;let E=e.getAll(),W=E.length>0?E[0].timestamp:0,U=new Set(S.map(d=>d.id));for(let d of J)U.has(d)||J.delete(d);let j=A!==Ce||R!==we,c=N.size===0&&S.length>0;if(j||c||S.length===0){f.innerHTML="",N.clear();let d=document.createDocumentFragment();for(let h=0;h<S.length;h++){let k=xe(S[h],h,W,L,J,ce,a,i);N.set(S[h].id,k),d.appendChild(k)}f.appendChild(d),Ce=A,we=R,K=null}else{if(K!==null){let h=N.get(K);if(h&&h.parentNode===f){let k=S.findIndex(q=>q.id===K);if(k>=0){let q=xe(S[k],k,W,L,J,ce,a,i);f.insertBefore(q,h),h.remove(),N.set(K,q)}}K=null}let d=new Set(S.map(h=>h.id));for(let[h,k]of N)d.has(h)||(k.remove(),N.delete(h));for(let h=0;h<S.length;h++){let k=S[h];if(!N.has(k.id)){let q=xe(k,h,W,L,J,ce,a,i);N.set(k.id,q),f.appendChild(q)}}}C.isFollowing()&&(f.scrollTop=f.scrollHeight)}function nt(){if(Date.now()-ne>=ct){I!==null&&(cancelAnimationFrame(I),I=null),G();return}X||(X=!0,I=requestAnimationFrame(()=>{I=null,G()}))}let Le=(o,s)=>{if(!m)return;m.innerHTML="";let p=_(o,"12px","currentColor",1.5);p&&m.appendChild(p);let E=l("span","persona-text-xs");E.textContent="Copy All",m.appendChild(E),setTimeout(()=>{m.innerHTML="";let W=_(je,"12px","currentColor",1.5);W&&m.appendChild(W);let U=l("span","persona-text-xs");U.textContent="Copy All",m.appendChild(U),m.disabled=!1},s)},Me=async()=>{if(m){m.disabled=!0;try{let o;ye()?o=S:n?(o=await n(),o.length===0&&(o=e.getAll())):o=e.getAll();let s=o.map(p=>{try{return JSON.parse(p.payload)}catch{return p.payload}});await navigator.clipboard.writeText(JSON.stringify(s,null,2)),Le(Je,1500)}catch{Le(qe,1500)}}},Ae=()=>{v&&(A=v.value,ie(),G())},Pe=()=>{!y||!B||(B.style.display=y.value?"":"none",P&&clearTimeout(P),P=setTimeout(()=>{R=y.value,ie(),G()},150))},be=()=>{!y||!B||(y.value="",R="",B.style.display="none",P&&clearTimeout(P),ie(),G())},Be=()=>{if(Q)return;let o=f.scrollTop,{action:s,nextLastScrollTop:p}=Ve({following:C.isFollowing(),currentScrollTop:o,lastScrollTop:Ee,nearBottom:Re(),userScrollThreshold:1,resumeRequiresDownwardScroll:!0});Ee=p,s==="resume"?(C.resume(),w=0,T.style.display="none"):s==="pause"&&(C.pause(),x&&(se.textContent=D,T.style.display=""))},He=o=>{let s=We({following:C.isFollowing(),deltaY:o.deltaY,nearBottom:Re(),resumeWhenNearBottom:!0});s==="pause"?(C.pause(),x&&(se.textContent=D,T.style.display="")):s==="resume"&&(C.resume(),w=0,T.style.display="none")},Fe=()=>{x&&(f.scrollTop=f.scrollHeight,C.resume(),w=0,T.style.display="none")},Ie=o=>{let s=o.target;if(!s||s.closest("button"))return;let p=s.closest("[data-event-id]");if(!p)return;let E=p.getAttribute("data-event-id");E&&ce(E)},Ne=o=>{if((o.metaKey||o.ctrlKey)&&o.key==="f"){o.preventDefault(),y?.focus(),y?.select();return}o.key==="Escape"&&(y&&document.activeElement===y?(be(),y.blur(),F.focus()):r&&r())};m&&m.addEventListener("click",Me),v&&v.addEventListener("change",Ae),y&&y.addEventListener("input",Pe),B&&B.addEventListener("click",be),f.addEventListener("scroll",Be),f.addEventListener("wheel",He,{passive:!0}),f.addEventListener("click",Ie),T.addEventListener("click",Fe),F.addEventListener("keydown",Ne);function rt(){P&&clearTimeout(P),I!==null&&(cancelAnimationFrame(I),I=null),X=!1,N.clear(),m&&m.removeEventListener("click",Me),v&&v.removeEventListener("change",Ae),y&&y.removeEventListener("input",Pe),B&&B.removeEventListener("click",be),f.removeEventListener("scroll",Be),f.removeEventListener("wheel",He),f.removeEventListener("click",Ie),T.removeEventListener("click",Fe),F.removeEventListener("keydown",Ne)}return{element:F,update:nt,destroy:rt}}}var de=class{#e;#t=0;#r=0;#o=0;#a=new Set;#n;#s;constructor(e=2e3,n=null){this.#n=e,this.#e=new Array(e),this.#s=n}push(e){this.#e[this.#t]=e,this.#t=(this.#t+1)%this.#n,this.#r<this.#n&&this.#r++,this.#o++,this.#a.add(e.type),this.#s?.put(e)}getAll(){return this.#r===0?[]:this.#r<this.#n?this.#e.slice(0,this.#r):[...this.#e.slice(this.#t,this.#n),...this.#e.slice(0,this.#t)]}async restore(){if(!this.#s)return 0;let e=await this.#s.getAll();if(e.length===0)return 0;let n=e.length>this.#n?e.slice(e.length-this.#n):e;for(let r of n)this.#e[this.#t]=r,this.#t=(this.#t+1)%this.#n,this.#r<this.#n&&this.#r++,this.#a.add(r.type);return this.#o=e.length,n.length}getAllFromStore(){return this.#s?this.#s.getAll():Promise.resolve(this.getAll())}getRecent(e){let n=this.getAll();return e>=n.length?n:n.slice(n.length-e)}getSize(){return this.#r}getTotalCaptured(){return this.#o}getEvictedCount(){return this.#o-this.#r}clear(){this.#e=new Array(this.#n),this.#t=0,this.#r=0,this.#o=0,this.#a.clear(),this.#s?.clear()}destroy(){this.#e=[],this.#t=0,this.#r=0,this.#o=0,this.#a.clear(),this.#s?.destroy()}getEventTypes(){return Array.from(this.#a)}};var fe=class{#e=null;#t=[];#r=!1;#o=!1;#a;#n;constructor(e="persona-event-stream",n="events"){this.#a=e,this.#n=n}open(){return new Promise((e,n)=>{try{let r=indexedDB.open(this.#a,1);r.onupgradeneeded=()=>{let i=r.result;i.objectStoreNames.contains(this.#n)||i.createObjectStore(this.#n,{keyPath:"id"}).createIndex("timestamp","timestamp",{unique:!1})},r.onsuccess=()=>{this.#e=r.result,e()},r.onerror=()=>{n(r.error)}}catch(r){n(r)}})}put(e){!this.#e||this.#o||(this.#t.push(e),this.#r||(this.#r=!0,queueMicrotask(()=>this.#s())))}putBatch(e){if(!(!this.#e||this.#o||e.length===0))try{let r=this.#e.transaction(this.#n,"readwrite").objectStore(this.#n);for(let i of e)r.put(i)}catch{}}getAll(){return new Promise((e,n)=>{if(!this.#e){e([]);return}try{let u=this.#e.transaction(this.#n,"readonly").objectStore(this.#n).index("timestamp").getAll();u.onsuccess=()=>{e(u.result)},u.onerror=()=>{n(u.error)}}catch(r){n(r)}})}getCount(){return new Promise((e,n)=>{if(!this.#e){e(0);return}try{let a=this.#e.transaction(this.#n,"readonly").objectStore(this.#n).count();a.onsuccess=()=>{e(a.result)},a.onerror=()=>{n(a.error)}}catch(r){n(r)}})}clear(){return new Promise((e,n)=>{if(!this.#e){e();return}this.#t=[];try{let a=this.#e.transaction(this.#n,"readwrite").objectStore(this.#n).clear();a.onsuccess=()=>{e()},a.onerror=()=>{n(a.error)}}catch(r){n(r)}})}close(){this.#e&&(this.#e.close(),this.#e=null)}destroy(){return this.#o=!0,this.#t=[],this.close(),new Promise((e,n)=>{try{let r=indexedDB.deleteDatabase(this.#a);r.onsuccess=()=>{e()},r.onerror=()=>{n(r.error)}}catch(r){n(r)}})}#s(){if(this.#r=!1,!this.#e||this.#o||this.#t.length===0)return;let e=this.#t;this.#t=[];try{let r=this.#e.transaction(this.#n,"readwrite").objectStore(this.#n);for(let i of e)r.put(i)}catch{}}};var Et=new Set(["step_start","turn_start"]),Ct=new Set(["step_complete","turn_complete"]),Xe=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Qe=t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,Ke=(t,e)=>{let n=t[e];return Xe(n)?n:void 0};function Se(t){return t>0?Math.max(1,Math.ceil(t/4)):0}function he(t,e){if(!(t<=0||e===void 0||e<250))return t/(e/1e3)}function wt(t,e){return typeof e.type=="string"?e.type:t}function Ye(t){let e=Ke(t,"tokens")??Ke(t,"totalTokens");return e?Qe(e.output):void 0}function Tt(t){return Qe(t.durationMs)}function kt(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var me=class{#e={status:"idle"};#t=null;constructor(e=kt){this.now=e}getMetric(){let e=this.#t;if(e&&this.#e.status==="running"&&e.firstDeltaAt!==void 0&&this.#e.outputTokens!==void 0){let n=this.now()-e.firstDeltaAt;return{...this.#e,durationMs:n,tokensPerSecond:he(this.#e.outputTokens,n)}}return this.#e}reset(){this.#t=null,this.#e={status:"idle"}}#r(e){this.#t={startedAt:e,visibleCharCount:0,exactOutputTokens:0},this.#e={status:"running"}}processEvent(e,n){if(!Xe(n)){e==="execution_error"&&this.#t&&(this.#t=null,this.#e={status:"error"});return}let r=wt(e,n),i=this.now();if(r==="execution_start"){this.#r(i);return}if(Et.has(r)){this.#t||this.#r(i);return}if(r==="text_delta"){let a=typeof n.delta=="string"?n.delta:"";if(!a)return;this.#t||this.#r(i);let u=this.#t;u.firstDeltaAt??=i,u.visibleCharCount+=a.length;let g=u.exactOutputTokens+Se(u.visibleCharCount),b=i-u.firstDeltaAt;this.#e={status:"running",tokensPerSecond:he(g,b),outputTokens:g,durationMs:b,source:u.exactOutputTokens>0?"usage":"estimate"};return}if(Ct.has(r)){if(!this.#t)return;let a=this.#t,u=Ye(n);u!==void 0&&(a.exactOutputTokens+=u,a.visibleCharCount=0);let g=a.exactOutputTokens>0,b=a.exactOutputTokens+Se(a.visibleCharCount),x=this.#o(a,n,i);this.#e={status:"running",tokensPerSecond:he(b,x),outputTokens:b,durationMs:x,source:g?"usage":"estimate"};return}if(r==="execution_complete"){if(!this.#t)return;let a=this.#t,u=Ye(n),g=u??a.exactOutputTokens+Se(a.visibleCharCount),b=u!==void 0||a.exactOutputTokens>0?"usage":"estimate",x=this.#o(a,n,i);this.#e={status:"complete",tokensPerSecond:he(g,x),outputTokens:g,durationMs:x,source:b},this.#t=null;return}if(r==="execution_error"||r==="error"&&n.recoverable===!1){if(!this.#t)return;this.#t=null,this.#e={status:"error"}}}#o(e,n,r){let i=e.firstDeltaAt!==void 0?r-e.firstDeltaAt:void 0;return i!==void 0&&i>=250?i:Tt(n)??r-e.startedAt}};export{de as EventStreamBuffer,fe as EventStreamStore,me as ThroughputTracker,Ge as createEventStreamView};
|