@runtypelabs/persona 4.25.0 → 4.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 +180 -8
- package/dist/approval-ui.d.ts +180 -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 +180 -8
- package/dist/artifacts-ui.d.ts +180 -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-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-QPPJUSZH.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-YPEG45Q4.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 +180 -8
- package/dist/context-mentions.d.ts +180 -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 +183 -31
- package/dist/event-stream-view.d.ts +183 -31
- package/dist/event-stream-view.js +1 -1
- package/dist/forms-ui.d.cts +221 -667
- package/dist/forms-ui.d.ts +221 -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 +227 -738
- package/dist/index.d.ts +227 -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 +180 -8
- package/dist/session-reconnect.d.ts +180 -8
- package/dist/smart-dom-reader.cjs +13 -13
- package/dist/smart-dom-reader.d.cts +180 -8
- package/dist/smart-dom-reader.d.ts +180 -8
- package/dist/smart-dom-reader.js +11 -11
- package/dist/theme-editor-preview.cjs +116 -98
- package/dist/theme-editor-preview.d.cts +182 -8
- package/dist/theme-editor-preview.d.ts +182 -8
- package/dist/theme-editor-preview.js +49 -54
- package/dist/theme-editor.cjs +2 -2
- package/dist/theme-editor.d.cts +181 -23
- package/dist/theme-editor.d.ts +181 -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-UOQOFAFY.js +17 -0
- package/dist/voice-runtime.cjs +17 -1
- package/dist/voice-runtime.d.cts +11650 -232
- package/dist/voice-runtime.d.ts +11650 -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 +221 -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 +852 -1536
- package/src/session.voice.test.ts +1170 -5
- package/src/styles/widget.css +58 -0
- package/src/theme-editor/state.ts +91 -91
- package/src/types.ts +198 -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 +670 -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 +981 -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,109 @@ 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
|
+
* Set when the turn parked on approvals (`text` then asks for the decision).
|
|
7149
|
+
* Resolves with the terminal result once the visitor decides (or the
|
|
7150
|
+
* approval is replaced, declined by voice, or unanswered for
|
|
7151
|
+
* `approvalTimeoutMs`) and the resumed turn finishes; `null` only when
|
|
7152
|
+
* `signal` aborts first (hang-up, or the server cancelled the delegation).
|
|
7153
|
+
*/
|
|
7154
|
+
followUp?: (options: {
|
|
7155
|
+
signal: AbortSignal;
|
|
7156
|
+
approvalTimeoutMs?: number;
|
|
7157
|
+
/** `false`: run only the approval bookkeeping (expiry, supersede); nothing will be read back. @default true */
|
|
7158
|
+
readBack?: boolean;
|
|
7159
|
+
/** The resumed turn stopped on another approval: ask for it too (`text` is its approval script). */
|
|
7160
|
+
onUpdate?: (text: string) => void;
|
|
7161
|
+
}) => Promise<VoiceDelegationFollowUp | null>;
|
|
7162
|
+
};
|
|
7163
|
+
/**
|
|
7164
|
+
* Chat-side surface the session hands a full-duplex provider: the visible
|
|
7165
|
+
* history (for the call-start context) and a way to run a delegated turn
|
|
7166
|
+
* through the normal chat pipeline.
|
|
7167
|
+
*/
|
|
7168
|
+
interface VoiceSessionBridge {
|
|
7169
|
+
/** Visible user/assistant messages, oldest first. */
|
|
7170
|
+
getHistory(): Array<{
|
|
7171
|
+
role: 'user' | 'assistant';
|
|
7172
|
+
content: string;
|
|
7173
|
+
}>;
|
|
7174
|
+
/**
|
|
7175
|
+
* Submit the turn as the visitor's message (reusing its transcript bubble)
|
|
7176
|
+
* and resolve with the assistant's final answer once the turn settles.
|
|
7177
|
+
* Waits for any chat turn already in flight first. Never rejects.
|
|
7178
|
+
*/
|
|
7179
|
+
runDelegatedTurn(request: VoiceDelegationRequest): Promise<VoiceDelegationResult>;
|
|
7180
|
+
/**
|
|
7181
|
+
* The server dropped this delegation's result (cancelled it, or refused a
|
|
7182
|
+
* late result): its chat answer is no longer spoken, so browser TTS may read it.
|
|
7183
|
+
* `expired`: the server's deadline passed, so its pending approvals are
|
|
7184
|
+
* declined too, as the approval TTL would.
|
|
7185
|
+
*/
|
|
7186
|
+
dropDelegation?(delegationId: string, expired?: boolean): void;
|
|
7029
7187
|
}
|
|
7030
7188
|
/**
|
|
7031
7189
|
* Extra context for an approval decision, surfaced to `onDecision` and to the
|
|
@@ -9622,6 +9780,11 @@ type AgentWidgetToolCall = {
|
|
|
9622
9780
|
startedAt?: number;
|
|
9623
9781
|
completedAt?: number;
|
|
9624
9782
|
durationMs?: number;
|
|
9783
|
+
/**
|
|
9784
|
+
* The call paused for an approval that was granted, and the agent re-ran it
|
|
9785
|
+
* as a new tool call: that later call carries the result, this one has none.
|
|
9786
|
+
*/
|
|
9787
|
+
superseded?: boolean;
|
|
9625
9788
|
};
|
|
9626
9789
|
/**
|
|
9627
9790
|
* Represents a tool approval request in the chat conversation.
|
|
@@ -9643,6 +9806,8 @@ type AgentWidgetApproval = {
|
|
|
9643
9806
|
*/
|
|
9644
9807
|
reason?: string;
|
|
9645
9808
|
parameters?: unknown;
|
|
9809
|
+
/** The paused tool call this approval gates (`approval_start.toolCallId`). */
|
|
9810
|
+
toolCallId?: string;
|
|
9646
9811
|
resolvedAt?: number;
|
|
9647
9812
|
};
|
|
9648
9813
|
type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool" | "approval";
|
|
@@ -9742,6 +9907,13 @@ type AgentWidgetMessage = {
|
|
|
9742
9907
|
* }
|
|
9743
9908
|
*/
|
|
9744
9909
|
voiceProcessing?: boolean;
|
|
9910
|
+
/**
|
|
9911
|
+
* Display-only caption of full-duplex voice speech, such as the voice
|
|
9912
|
+
* model's own words, or something the visitor said that wasn't submitted
|
|
9913
|
+
* as a chat turn. It renders in the transcript but is never sent to the
|
|
9914
|
+
* model as conversation.
|
|
9915
|
+
*/
|
|
9916
|
+
voiceCaption?: boolean;
|
|
9745
9917
|
/**
|
|
9746
9918
|
* Raw structured payload for this message (e.g., JSON action response).
|
|
9747
9919
|
* Populated automatically when structured parsers run.
|
|
@@ -9820,12 +9992,7 @@ type PersonaArtifactRecord = {
|
|
|
9820
9992
|
};
|
|
9821
9993
|
|
|
9822
9994
|
declare class EventStreamStore {
|
|
9823
|
-
private
|
|
9824
|
-
private pendingWrites;
|
|
9825
|
-
private flushScheduled;
|
|
9826
|
-
private isDestroyed;
|
|
9827
|
-
private readonly dbName;
|
|
9828
|
-
private readonly storeName;
|
|
9995
|
+
#private;
|
|
9829
9996
|
constructor(dbName?: string, storeName?: string);
|
|
9830
9997
|
open(): Promise<void>;
|
|
9831
9998
|
put(event: SSEEventRecord): void;
|
|
@@ -9835,17 +10002,10 @@ declare class EventStreamStore {
|
|
|
9835
10002
|
clear(): Promise<void>;
|
|
9836
10003
|
close(): void;
|
|
9837
10004
|
destroy(): Promise<void>;
|
|
9838
|
-
private flushWrites;
|
|
9839
10005
|
}
|
|
9840
10006
|
|
|
9841
10007
|
declare class EventStreamBuffer {
|
|
9842
|
-
private
|
|
9843
|
-
private head;
|
|
9844
|
-
private count;
|
|
9845
|
-
private totalCaptured;
|
|
9846
|
-
private eventTypesSet;
|
|
9847
|
-
private readonly maxSize;
|
|
9848
|
-
private readonly store;
|
|
10008
|
+
#private;
|
|
9849
10009
|
constructor(maxSize?: number, store?: EventStreamStore | null);
|
|
9850
10010
|
push(event: SSEEventRecord): void;
|
|
9851
10011
|
getAll(): SSEEventRecord[];
|
|
@@ -9878,21 +10038,13 @@ interface ThroughputMetric {
|
|
|
9878
10038
|
* event via {@link processEvent}; read the current state via {@link getMetric}.
|
|
9879
10039
|
*/
|
|
9880
10040
|
declare class ThroughputTracker {
|
|
9881
|
-
private
|
|
9882
|
-
private run;
|
|
10041
|
+
#private;
|
|
9883
10042
|
private readonly now;
|
|
9884
10043
|
constructor(now?: () => number);
|
|
9885
10044
|
getMetric(): ThroughputMetric;
|
|
9886
10045
|
/** Reset back to idle (e.g. when the chat is cleared). */
|
|
9887
10046
|
reset(): void;
|
|
9888
|
-
private startRun;
|
|
9889
10047
|
processEvent(eventType: string, payload: unknown): void;
|
|
9890
|
-
/**
|
|
9891
|
-
* Prefer the streamed visible-output window when it clears the minimum
|
|
9892
|
-
* threshold; otherwise fall back to provider execution time, then to the
|
|
9893
|
-
* whole-request duration.
|
|
9894
|
-
*/
|
|
9895
|
-
private resolveDuration;
|
|
9896
10048
|
}
|
|
9897
10049
|
|
|
9898
10050
|
type EventStreamViewOptions = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var u=(t,e)=>{let r=document.createElement(t);return e&&(r.className=e),r};var ie=[["path",{d:"M20 6 9 17l-5-5"}]];var ke=[["path",{d:"m6 9 6 6 6-6"}]];var Te=[["path",{d:"m9 18 6-6-6-6"}]];var me=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4"}],["path",{d:"M21 14H11"}],["path",{d:"m15 10-4 4 4 4"}]];var xe=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"}]];var Ae=[["path",{d:"m21 21-4.34-4.34"}],["circle",{cx:"11",cy:"11",r:"8"}]];var ce=[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]];var N=(t,e=24,r="currentColor",a=2)=>{if(!Array.isArray(t))return null;let o=document.createElementNS("http://www.w3.org/2000/svg","svg");return o.setAttribute("width",String(e)),o.setAttribute("height",String(e)),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none"),o.setAttribute("stroke",r),o.setAttribute("stroke-width",String(a)),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"),o.setAttribute("aria-hidden","true"),t.forEach(f=>{if(!Array.isArray(f)||f.length<2)return;let n=f[0],p=f[1];if(!p)return;let x=document.createElementNS("http://www.w3.org/2000/svg",n);Object.entries(p).forEach(([C,v])=>{C!=="stroke"&&x.setAttribute(C,String(v))}),o.appendChild(x)}),o};function Ke(t=!0){let e=t;return{isFollowing:()=>e,pause:()=>e?(e=!1,!0):!1,resume:()=>e?!1:(e=!0,!0)}}function nt(t){return Math.max(0,t.scrollHeight-t.clientHeight)}function _e(t,e){return nt(t)-t.scrollTop<=e}function Ze(t){let{following:e,currentScrollTop:r,lastScrollTop:a,nearBottom:o,userScrollThreshold:f,isAutoScrolling:n=!1,pauseOnUpwardScroll:p=!1,pauseWhenAwayFromBottom:x=!0,resumeRequiresDownwardScroll:C=!1}=t,v=r-a;return n||Math.abs(v)<f?{action:"none",delta:v,nextLastScrollTop:r}:!e&&o&&(!C||v>0)?{action:"resume",delta:v,nextLastScrollTop:r}:e&&p&&v<0?{action:"pause",delta:v,nextLastScrollTop:r}:e&&x&&!o?{action:"pause",delta:v,nextLastScrollTop:r}:{action:"none",delta:v,nextLastScrollTop:r}}function $e(t){let{following:e,deltaY:r,nearBottom:a=!1,resumeWhenNearBottom:o=!1}=t;return e&&r<0?"pause":!e&&o&&r>0&&a?"resume":"none"}function ee(t,e){e&&e.split(/\s+/).forEach(r=>r&&t.classList.add(r))}var _={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)"}};_.execution_error=_.error;_.execution_=_.flow_;_.turn_=_.agent_;_.text_=_.agent_;var dt={bg:"var(--persona-event-badge-default-bg, #f3f4f6)",text:"var(--persona-event-badge-default-fg, #4b5563)"},pt=["flowName","stepName","reasoningText","text","name","tool","toolName"],it=100;function Je(t,e){if(e[t])return e[t];for(let r of Object.keys(e))if(r.endsWith("_")&&t.startsWith(r))return e[r]}function mt(t,e){return(e&&Je(t,e))??Je(t,_)??dt}function xt(t){return/^#[0-9a-fA-F]{6}$/.test(t)?`${t}50`:`color-mix(in srgb, ${t} 31%, transparent)`}function ct(t,e){return`+${((t-e)/1e3).toFixed(3)}s`}function ht(t){let e=new Date(t),r=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0"),o=String(e.getSeconds()).padStart(2,"0"),f=String(e.getMilliseconds()).padStart(3,"0");return`${r}:${a}:${o}.${f}`}function gt(t,e){try{let r=JSON.parse(t);if(typeof r!="object"||r===null)return null;for(let a of e){let o=a.split("."),f=r;for(let n of o)if(f&&typeof f=="object"&&f!==null)f=f[n];else{f=void 0;break}if(typeof f=="string"&&f.trim())return f.trim()}}catch{}return null}function Ct(t){return navigator.clipboard?.writeText?navigator.clipboard.writeText(t):new Promise(e=>{let r=document.createElement("textarea");r.value=t,r.style.position="fixed",r.style.opacity="0",document.body.appendChild(r),r.select(),document.execCommand("copy"),document.body.removeChild(r),e()})}function St(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 wt(t){return t.tokensPerSecond===void 0||!Number.isFinite(t.tokensPerSecond)?"-- tok/s":`${t.tokensPerSecond.toFixed(1)} tok/s`}function bt(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 yt(t,e,r){let a,o;try{o=JSON.parse(t.payload),a=JSON.stringify(o,null,2)}catch{o=t.payload,a=t.payload}let f=e.find(p=>p.renderEventStreamPayload);if(f?.renderEventStreamPayload&&r){let p=f.renderEventStreamPayload({event:t,config:r,defaultRenderer:()=>n(),parsedPayload:o});if(p)return p}return n();function n(){let p=u("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]"),x=u("pre","persona-m-0 persona-whitespace-pre-wrap persona-break-all persona-text-[11px] persona-text-persona-secondary persona-font-mono");return x.textContent=a,p.appendChild(x),p}}function Pe(t,e,r,a,o,f,n,p){let x=o.has(t.id),C=u("div","persona-border-b persona-border-persona-divider persona-text-xs");ee(C,a.classNames?.eventRow);let v=n.find(B=>B.renderEventStreamRow);if(v?.renderEventStreamRow&&p){let B=v.renderEventStreamRow({event:t,index:e,config:p,defaultRenderer:()=>I(),isExpanded:x,onToggleExpand:()=>f(t.id)});if(B)return C.appendChild(B),C}return C.appendChild(I()),C;function I(){let B=u("div",""),D=u("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");D.setAttribute("data-event-id",t.id);let te=u("span","persona-flex-shrink-0 persona-text-persona-muted persona-w-4 persona-text-center persona-flex persona-items-center persona-justify-center"),L=N(x?ke:Te,"14px","currentColor",2);L&&te.appendChild(L);let H=u("span","persona-text-[11px] persona-text-persona-muted persona-whitespace-nowrap persona-flex-shrink-0 persona-font-mono persona-w-[70px]"),b=a.timestampFormat??"relative";H.textContent=b==="relative"?ct(t.timestamp,r):ht(t.timestamp);let F=null;a.showSequenceNumbers!==!1&&(F=u("span","persona-text-[11px] persona-text-persona-muted persona-font-mono persona-flex-shrink-0 persona-w-[28px] persona-text-right"),F.textContent=String(e+1));let M=mt(t.type,a.badgeColors),R=u("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");R.style.backgroundColor=M.bg,R.style.color=M.text,R.style.borderColor=xt(M.text),R.textContent=t.type;let re=a.descriptionFields??pt,j=gt(t.payload,re),W=null;j&&(W=u("span","persona-text-[11px] persona-text-persona-secondary persona-truncate persona-min-w-0"),W.textContent=j);let k=u("div","persona-flex-1 persona-min-w-0"),T=u("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"),ae=N(xe,"12px","currentColor",1.5);return ae&&T.appendChild(ae),T.addEventListener("click",async Q=>{Q.stopPropagation(),await Ct(St(t)),T.innerHTML="";let q=N(ie,"12px","currentColor",1.5);q&&T.appendChild(q),setTimeout(()=>{T.innerHTML="";let Y=N(xe,"12px","currentColor",1.5);Y&&T.appendChild(Y)},1500)}),D.appendChild(te),D.appendChild(H),F&&D.appendChild(F),D.appendChild(R),W&&D.appendChild(W),D.appendChild(k),D.appendChild(T),B.appendChild(D),x&&B.appendChild(yt(t,n,p)),B}}function je(t){let{buffer:e,getFullHistory:r,onClose:a,config:o,plugins:f=[],getThroughput:n}=t,p=t.renderIconByName??(()=>null),x=o?.features?.scrollToBottom,C=x?.enabled!==!1,v=x?.iconName??"arrow-down",I=x?.label??"",B=o?.features?.eventStream??{},D=f.find(L=>L.renderEventStreamView);if(D?.renderEventStreamView&&o){let L=D.renderEventStreamView({config:o,events:e.getAll(),defaultRenderer:()=>te().element,onClose:a});if(L)return{element:L,update:()=>{},destroy:()=>{}}}return te();function te(){let L=B.classNames,H=u("div","persona-event-stream-view persona-flex persona-flex-col persona-flex-1 persona-min-h-0");ee(H,L?.panel);let b=[],F="",M="",R=null,re=[],j={},W=0,k=Ke(),T=0,ae=0,Q=!1,q=null,Y=!1,Be=0,Z=new Set,O=new Map,Le="",Fe="",J=null,S,g,w,E,oe=null,U=null,V=null;function we(){let s=u("div","persona-event-toolbar persona-relative persona-flex persona-flex-col persona-flex-shrink-0"),l=u("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(ee(l,L?.headerBar),n){U=u("div","persona-relative persona-flex persona-items-center persona-gap-1.5 persona-whitespace-nowrap"),U.style.cursor="help",oe=u("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"),oe.textContent="-- tok/s",V=u("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 K=U,ne=V,lt=()=>{if(!ne.textContent)return;let ze=K.getBoundingClientRect(),Xe=s.getBoundingClientRect();ne.style.left=`${ze.left-Xe.left}px`,ne.style.top=`${ze.bottom-Xe.top+4}px`,ne.style.display="block"},ut=()=>{ne.style.display="none"};U.addEventListener("mouseenter",lt),U.addEventListener("mouseleave",ut),U.appendChild(oe)}let d=u("div","persona-flex-1");S=u("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 y=u("option","");y.value="",y.textContent="All events (0)",S.appendChild(y),g=u("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"),g.type="button",g.title="Copy All";let z=N(me,"12px","currentColor",1.5);z&&g.appendChild(z);let X=u("span","persona-event-copy-all persona-text-xs");X.textContent="Copy All",g.appendChild(X),U&&l.appendChild(U),l.appendChild(d),l.appendChild(S),l.appendChild(g);let i=u("div","persona-relative persona-px-4 persona-py-2.5 persona-border-b persona-border-persona-divider persona-bg-persona-surface");ee(i,L?.searchBar);let m=N(Ae,"14px","var(--persona-muted, #9ca3af)",1.5),h=u("span","persona-absolute persona-left-6 persona-top-1/2 persona--translate-y-1/2 persona-pointer-events-none persona-flex persona-items-center");m&&h.appendChild(m),w=u("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"),ee(w,L?.searchInput),w.type="text",w.placeholder="Search event payloads...",E=u("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"),E.type="button",E.style.display="none";let P=N(ce,"12px","currentColor",2);return P&&E.appendChild(P),i.appendChild(h),i.appendChild(w),i.appendChild(E),s.appendChild(l),s.appendChild(i),V&&s.appendChild(V),s}let be,Re=f.find(s=>s.renderEventStreamToolbar);Re?.renderEventStreamToolbar&&o?be=Re.renderEventStreamToolbar({config:o,defaultRenderer:()=>we(),eventCount:e.getSize(),filteredCount:0,onFilterChange:l=>{F=l,ue(),$()},onSearchChange:l=>{M=l,ue(),$()}})??we():be=we();let fe=u("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");fe.style.display="none";function rt(){if(!n||!oe||!U)return;let s=n(),l=wt(s);oe.textContent=l;let d=bt(s);V&&(V.textContent=d,d||(V.style.display="none")),U.setAttribute("aria-label",d?`Throughput: ${l}, ${d}`:`Throughput: ${l}`)}let de=u("div","persona-flex-1 persona-min-h-0 persona-relative"),c=u("div","persona-event-stream-list persona-overflow-y-auto persona-min-h-0");c.style.height="100%";let A=u("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");ee(A,L?.scrollIndicator),A.style.display="none",A.setAttribute("data-persona-scroll-to-bottom-has-label",I?"true":"false");let Ee=p(v,"14px","currentColor",2);Ee&&A.appendChild(Ee);let se=u("span","");se.textContent=I,A.appendChild(se);let le=u("div","persona-flex persona-items-center persona-justify-center persona-h-full persona-text-sm persona-text-persona-muted");le.style.display="none",de.appendChild(c),de.appendChild(le),de.appendChild(A),H.setAttribute("tabindex","0"),H.appendChild(be),H.appendChild(fe),H.appendChild(de);function at(){let s=e.getAll(),l={};for(let i of s)l[i.type]=(l[i.type]||0)+1;let d=Object.keys(l).sort(),y=d.length!==re.length||!d.every((i,m)=>i===re[m]),G=!y&&d.some(i=>l[i]!==j[i]),z=s.length!==Object.values(j).reduce((i,m)=>i+m,0);if(!y&&!G&&!z||(re=d,j=l,!S))return;let X=S.value;if(S.options[0].textContent=`All events (${s.length})`,y){for(;S.options.length>1;)S.remove(1);for(let i of d){let m=u("option","");m.value=i,m.textContent=`${i} (${l[i]||0})`,S.appendChild(m)}X&&d.includes(X)?S.value=X:X&&(S.value="",F="")}else for(let i=1;i<S.options.length;i++){let m=S.options[i];m.textContent=`${m.value} (${l[m.value]||0})`}}function ot(){let s=e.getAll();if(F&&(s=s.filter(l=>l.type===F)),M){let l=M.toLowerCase();s=s.filter(d=>d.type.toLowerCase().includes(l)||d.payload.toLowerCase().includes(l))}return s}function ye(){return F!==""||M!==""}function ue(){W=0,T=0,k.resume(),A.style.display="none"}function pe(s){Z.has(s)?Z.delete(s):Z.add(s),J=s;let l=c.scrollTop,d=k.isFollowing();Y=!0,k.pause(),$(),c.scrollTop=l,d&&k.resume(),Y=!1}function De(){return _e(c,50)}function $(){ae=Date.now(),Q=!1,rt(),at();let s=e.getEvictedCount();s>0?(fe.textContent=`${s.toLocaleString()} older events truncated`,fe.style.display=""):fe.style.display="none",b=ot();let l=b.length,d=e.getSize()>0;l===0&&d&&ye()?(le.textContent=M?`No events matching '${M}'`:"No events matching filter",le.style.display="",c.style.display="none"):(le.style.display="none",c.style.display=""),g&&(g.title=ye()?`Copy Filtered (${l})`:"Copy All"),C&&!k.isFollowing()&&l>W&&(T+=l-W,se.textContent=I?`${I}${T>0?` (${T})`:""}`:"",A.style.display=""),W=l;let y=e.getAll(),G=y.length>0?y[0].timestamp:0,z=new Set(b.map(m=>m.id));for(let m of Z)z.has(m)||Z.delete(m);let X=F!==Le||M!==Fe,i=O.size===0&&b.length>0;if(X||i||b.length===0){c.innerHTML="",O.clear();let m=document.createDocumentFragment();for(let h=0;h<b.length;h++){let P=Pe(b[h],h,G,B,Z,pe,f,o);O.set(b[h].id,P),m.appendChild(P)}c.appendChild(m),Le=F,Fe=M,J=null}else{if(J!==null){let h=O.get(J);if(h&&h.parentNode===c){let P=b.findIndex(K=>K.id===J);if(P>=0){let K=Pe(b[P],P,G,B,Z,pe,f,o);c.insertBefore(K,h),h.remove(),O.set(J,K)}}J=null}let m=new Set(b.map(h=>h.id));for(let[h,P]of O)m.has(h)||(P.remove(),O.delete(h));for(let h=0;h<b.length;h++){let P=b[h];if(!O.has(P.id)){let K=Pe(P,h,G,B,Z,pe,f,o);O.set(P.id,K),c.appendChild(K)}}}k.isFollowing()&&(c.scrollTop=c.scrollHeight)}function ft(){if(Date.now()-ae>=it){q!==null&&(cancelAnimationFrame(q),q=null),$();return}Q||(Q=!0,q=requestAnimationFrame(()=>{q=null,$()}))}let He=(s,l)=>{if(!g)return;g.innerHTML="";let d=N(s,"12px","currentColor",1.5);d&&g.appendChild(d);let y=u("span","persona-text-xs");y.textContent="Copy All",g.appendChild(y),setTimeout(()=>{g.innerHTML="";let G=N(me,"12px","currentColor",1.5);G&&g.appendChild(G);let z=u("span","persona-text-xs");z.textContent="Copy All",g.appendChild(z),g.disabled=!1},l)},qe=async()=>{if(g){g.disabled=!0;try{let s;ye()?s=b:r?(s=await r(),s.length===0&&(s=e.getAll())):s=e.getAll();let l=s.map(d=>{try{return JSON.parse(d.payload)}catch{return d.payload}});await navigator.clipboard.writeText(JSON.stringify(l,null,2)),He(ie,1500)}catch{He(ce,1500)}}},Oe=()=>{S&&(F=S.value,ue(),$())},Ue=()=>{!w||!E||(E.style.display=w.value?"":"none",R&&clearTimeout(R),R=setTimeout(()=>{M=w.value,ue(),$()},150))},ve=()=>{!w||!E||(w.value="",M="",E.style.display="none",R&&clearTimeout(R),ue(),$())},Ne=()=>{if(Y)return;let s=c.scrollTop,{action:l,nextLastScrollTop:d}=Ze({following:k.isFollowing(),currentScrollTop:s,lastScrollTop:Be,nearBottom:De(),userScrollThreshold:1,resumeRequiresDownwardScroll:!0});Be=d,l==="resume"?(k.resume(),T=0,A.style.display="none"):l==="pause"&&(k.pause(),C&&(se.textContent=I,A.style.display=""))},Ie=s=>{let l=$e({following:k.isFollowing(),deltaY:s.deltaY,nearBottom:De(),resumeWhenNearBottom:!0});l==="pause"?(k.pause(),C&&(se.textContent=I,A.style.display="")):l==="resume"&&(k.resume(),T=0,A.style.display="none")},We=()=>{C&&(c.scrollTop=c.scrollHeight,k.resume(),T=0,A.style.display="none")},Ve=s=>{let l=s.target;if(!l||l.closest("button"))return;let d=l.closest("[data-event-id]");if(!d)return;let y=d.getAttribute("data-event-id");y&&pe(y)},Ge=s=>{if((s.metaKey||s.ctrlKey)&&s.key==="f"){s.preventDefault(),w?.focus(),w?.select();return}s.key==="Escape"&&(w&&document.activeElement===w?(ve(),w.blur(),H.focus()):a&&a())};g&&g.addEventListener("click",qe),S&&S.addEventListener("change",Oe),w&&w.addEventListener("input",Ue),E&&E.addEventListener("click",ve),c.addEventListener("scroll",Ne),c.addEventListener("wheel",Ie,{passive:!0}),c.addEventListener("click",Ve),A.addEventListener("click",We),H.addEventListener("keydown",Ge);function st(){R&&clearTimeout(R),q!==null&&(cancelAnimationFrame(q),q=null),Q=!1,O.clear(),g&&g.removeEventListener("click",qe),S&&S.removeEventListener("change",Oe),w&&w.removeEventListener("input",Ue),E&&E.removeEventListener("click",ve),c.removeEventListener("scroll",Ne),c.removeEventListener("wheel",Ie),c.removeEventListener("click",Ve),A.removeEventListener("click",We),H.removeEventListener("keydown",Ge)}return{element:H,update:ft,destroy:st}}}var he=class{constructor(e=2e3,r=null){this.head=0;this.count=0;this.totalCaptured=0;this.eventTypesSet=new Set;this.maxSize=e,this.buffer=new Array(e),this.store=r}push(e){this.buffer[this.head]=e,this.head=(this.head+1)%this.maxSize,this.count<this.maxSize&&this.count++,this.totalCaptured++,this.eventTypesSet.add(e.type),this.store?.put(e)}getAll(){return this.count===0?[]:this.count<this.maxSize?this.buffer.slice(0,this.count):[...this.buffer.slice(this.head,this.maxSize),...this.buffer.slice(0,this.head)]}async restore(){if(!this.store)return 0;let e=await this.store.getAll();if(e.length===0)return 0;let r=e.length>this.maxSize?e.slice(e.length-this.maxSize):e;for(let a of r)this.buffer[this.head]=a,this.head=(this.head+1)%this.maxSize,this.count<this.maxSize&&this.count++,this.eventTypesSet.add(a.type);return this.totalCaptured=e.length,r.length}getAllFromStore(){return this.store?this.store.getAll():Promise.resolve(this.getAll())}getRecent(e){let r=this.getAll();return e>=r.length?r:r.slice(r.length-e)}getSize(){return this.count}getTotalCaptured(){return this.totalCaptured}getEvictedCount(){return this.totalCaptured-this.count}clear(){this.buffer=new Array(this.maxSize),this.head=0,this.count=0,this.totalCaptured=0,this.eventTypesSet.clear(),this.store?.clear()}destroy(){this.buffer=[],this.head=0,this.count=0,this.totalCaptured=0,this.eventTypesSet.clear(),this.store?.destroy()}getEventTypes(){return Array.from(this.eventTypesSet)}};var ge=class{constructor(e="persona-event-stream",r="events"){this.db=null;this.pendingWrites=[];this.flushScheduled=!1;this.isDestroyed=!1;this.dbName=e,this.storeName=r}open(){return new Promise((e,r)=>{try{let a=indexedDB.open(this.dbName,1);a.onupgradeneeded=()=>{let o=a.result;o.objectStoreNames.contains(this.storeName)||o.createObjectStore(this.storeName,{keyPath:"id"}).createIndex("timestamp","timestamp",{unique:!1})},a.onsuccess=()=>{this.db=a.result,e()},a.onerror=()=>{r(a.error)}}catch(a){r(a)}})}put(e){!this.db||this.isDestroyed||(this.pendingWrites.push(e),this.flushScheduled||(this.flushScheduled=!0,queueMicrotask(()=>this.flushWrites())))}putBatch(e){if(!(!this.db||this.isDestroyed||e.length===0))try{let a=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName);for(let o of e)a.put(o)}catch{}}getAll(){return new Promise((e,r)=>{if(!this.db){e([]);return}try{let n=this.db.transaction(this.storeName,"readonly").objectStore(this.storeName).index("timestamp").getAll();n.onsuccess=()=>{e(n.result)},n.onerror=()=>{r(n.error)}}catch(a){r(a)}})}getCount(){return new Promise((e,r)=>{if(!this.db){e(0);return}try{let f=this.db.transaction(this.storeName,"readonly").objectStore(this.storeName).count();f.onsuccess=()=>{e(f.result)},f.onerror=()=>{r(f.error)}}catch(a){r(a)}})}clear(){return new Promise((e,r)=>{if(!this.db){e();return}this.pendingWrites=[];try{let f=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).clear();f.onsuccess=()=>{e()},f.onerror=()=>{r(f.error)}}catch(a){r(a)}})}close(){this.db&&(this.db.close(),this.db=null)}destroy(){return this.isDestroyed=!0,this.pendingWrites=[],this.close(),new Promise((e,r)=>{try{let a=indexedDB.deleteDatabase(this.dbName);a.onsuccess=()=>{e()},a.onerror=()=>{r(a.error)}}catch(a){r(a)}})}flushWrites(){if(this.flushScheduled=!1,!this.db||this.isDestroyed||this.pendingWrites.length===0)return;let e=this.pendingWrites;this.pendingWrites=[];try{let a=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName);for(let o of e)a.put(o)}catch{}}};var vt=new Set(["step_start","turn_start"]),kt=new Set(["step_complete","turn_complete"]),et=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),tt=t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,Qe=(t,e)=>{let r=t[e];return et(r)?r:void 0};function Me(t){return t>0?Math.max(1,Math.ceil(t/4)):0}function Ce(t,e){if(!(t<=0||e===void 0||e<250))return t/(e/1e3)}function Tt(t,e){return typeof e.type=="string"?e.type:t}function Ye(t){let e=Qe(t,"tokens")??Qe(t,"totalTokens");return e?tt(e.output):void 0}function At(t){return tt(t.durationMs)}function Pt(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Se=class{constructor(e=Pt){this.metric={status:"idle"};this.run=null;this.now=e}getMetric(){let e=this.run;if(e&&this.metric.status==="running"&&e.firstDeltaAt!==void 0&&this.metric.outputTokens!==void 0){let r=this.now()-e.firstDeltaAt;return{...this.metric,durationMs:r,tokensPerSecond:Ce(this.metric.outputTokens,r)}}return this.metric}reset(){this.run=null,this.metric={status:"idle"}}startRun(e){this.run={startedAt:e,visibleCharCount:0,exactOutputTokens:0},this.metric={status:"running"}}processEvent(e,r){if(!et(r)){e==="execution_error"&&this.run&&(this.run=null,this.metric={status:"error"});return}let a=Tt(e,r),o=this.now();if(a==="execution_start"){this.startRun(o);return}if(vt.has(a)){this.run||this.startRun(o);return}if(a==="text_delta"){let f=typeof r.delta=="string"?r.delta:"";if(!f)return;this.run||this.startRun(o);let n=this.run;n.firstDeltaAt??(n.firstDeltaAt=o),n.visibleCharCount+=f.length;let p=n.exactOutputTokens+Me(n.visibleCharCount),x=o-n.firstDeltaAt;this.metric={status:"running",tokensPerSecond:Ce(p,x),outputTokens:p,durationMs:x,source:n.exactOutputTokens>0?"usage":"estimate"};return}if(kt.has(a)){if(!this.run)return;let f=this.run,n=Ye(r);n!==void 0&&(f.exactOutputTokens+=n,f.visibleCharCount=0);let p=f.exactOutputTokens>0,x=f.exactOutputTokens+Me(f.visibleCharCount),C=this.resolveDuration(f,r,o);this.metric={status:"running",tokensPerSecond:Ce(x,C),outputTokens:x,durationMs:C,source:p?"usage":"estimate"};return}if(a==="execution_complete"){if(!this.run)return;let f=this.run,n=Ye(r),p=n??f.exactOutputTokens+Me(f.visibleCharCount),x=n!==void 0||f.exactOutputTokens>0?"usage":"estimate",C=this.resolveDuration(f,r,o);this.metric={status:"complete",tokensPerSecond:Ce(p,C),outputTokens:p,durationMs:C,source:x},this.run=null;return}if(a==="execution_error"||a==="error"&&r.recoverable===!1){if(!this.run)return;this.run=null,this.metric={status:"error"}}}resolveDuration(e,r,a){let o=e.firstDeltaAt!==void 0?a-e.firstDeltaAt:void 0;return o!==void 0&&o>=250?o:At(r)??a-e.startedAt}};export{he as EventStreamBuffer,ge as EventStreamStore,Se as ThroughputTracker,je as createEventStreamView};
|
|
1
|
+
var u=(t,e)=>{let r=document.createElement(t);return e&&(r.className=e),r};var ie=[["path",{d:"M20 6 9 17l-5-5"}]];var ve=[["path",{d:"m6 9 6 6 6-6"}]];var Te=[["path",{d:"m9 18 6-6-6-6"}]];var me=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4"}],["path",{d:"M21 14H11"}],["path",{d:"m15 10-4 4 4 4"}]];var xe=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"}]];var Ae=[["path",{d:"m21 21-4.34-4.34"}],["circle",{cx:"11",cy:"11",r:"8"}]];var ce=[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]];var I=(t,e=24,r="currentColor",o=2)=>{if(!Array.isArray(t))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",r),a.setAttribute("stroke-width",String(o)),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),a.setAttribute("aria-hidden","true"),t.forEach(f=>{if(!Array.isArray(f)||f.length<2)return;let n=f[0],p=f[1];if(!p)return;let x=document.createElementNS("http://www.w3.org/2000/svg",n);Object.entries(p).forEach(([C,k])=>{C!=="stroke"&&x.setAttribute(C,String(k))}),a.appendChild(x)}),a};function Ke(t=!0){let e=t;return{isFollowing:()=>e,pause:()=>e?(e=!1,!0):!1,resume:()=>e?!1:(e=!0,!0)}}function nt(t){return Math.max(0,t.scrollHeight-t.clientHeight)}function _e(t,e){return nt(t)-t.scrollTop<=e}function Ze(t){let{following:e,currentScrollTop:r,lastScrollTop:o,nearBottom:a,userScrollThreshold:f,isAutoScrolling:n=!1,pauseOnUpwardScroll:p=!1,pauseWhenAwayFromBottom:x=!0,resumeRequiresDownwardScroll:C=!1}=t,k=r-o;return n||Math.abs(k)<f?{action:"none",delta:k,nextLastScrollTop:r}:!e&&a&&(!C||k>0)?{action:"resume",delta:k,nextLastScrollTop:r}:e&&p&&k<0?{action:"pause",delta:k,nextLastScrollTop:r}:e&&x&&!a?{action:"pause",delta:k,nextLastScrollTop:r}:{action:"none",delta:k,nextLastScrollTop:r}}function $e(t){let{following:e,deltaY:r,nearBottom:o=!1,resumeWhenNearBottom:a=!1}=t;return e&&r<0?"pause":!e&&a&&r>0&&o?"resume":"none"}function ee(t,e){e&&e.split(/\s+/).forEach(r=>r&&t.classList.add(r))}var _={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)"}};_.execution_error=_.error;_.execution_=_.flow_;_.turn_=_.agent_;_.text_=_.agent_;var dt={bg:"var(--persona-event-badge-default-bg, #f3f4f6)",text:"var(--persona-event-badge-default-fg, #4b5563)"},pt=["flowName","stepName","reasoningText","text","name","tool","toolName"],it=100;function Je(t,e){if(e[t])return e[t];for(let r of Object.keys(e))if(r.endsWith("_")&&t.startsWith(r))return e[r]}function mt(t,e){return(e&&Je(t,e))??Je(t,_)??dt}function xt(t){return/^#[0-9a-fA-F]{6}$/.test(t)?`${t}50`:`color-mix(in srgb, ${t} 31%, transparent)`}function ct(t,e){return`+${((t-e)/1e3).toFixed(3)}s`}function ht(t){let e=new Date(t),r=String(e.getHours()).padStart(2,"0"),o=String(e.getMinutes()).padStart(2,"0"),a=String(e.getSeconds()).padStart(2,"0"),f=String(e.getMilliseconds()).padStart(3,"0");return`${r}:${o}:${a}.${f}`}function gt(t,e){try{let r=JSON.parse(t);if(typeof r!="object"||r===null)return null;for(let o of e){let a=o.split("."),f=r;for(let n of a)if(f&&typeof f=="object"&&f!==null)f=f[n];else{f=void 0;break}if(typeof f=="string"&&f.trim())return f.trim()}}catch{}return null}function Ct(t){return navigator.clipboard?.writeText?navigator.clipboard.writeText(t):new Promise(e=>{let r=document.createElement("textarea");r.value=t,r.style.position="fixed",r.style.opacity="0",document.body.appendChild(r),r.select(),document.execCommand("copy"),document.body.removeChild(r),e()})}function St(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 wt(t){return t.tokensPerSecond===void 0||!Number.isFinite(t.tokensPerSecond)?"-- tok/s":`${t.tokensPerSecond.toFixed(1)} tok/s`}function yt(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 bt(t,e,r){let o,a;try{a=JSON.parse(t.payload),o=JSON.stringify(a,null,2)}catch{a=t.payload,o=t.payload}let f=e.find(p=>p.renderEventStreamPayload);if(f?.renderEventStreamPayload&&r){let p=f.renderEventStreamPayload({event:t,config:r,defaultRenderer:()=>n(),parsedPayload:a});if(p)return p}return n();function n(){let p=u("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]"),x=u("pre","persona-m-0 persona-whitespace-pre-wrap persona-break-all persona-text-[11px] persona-text-persona-secondary persona-font-mono");return x.textContent=o,p.appendChild(x),p}}function Pe(t,e,r,o,a,f,n,p){let x=a.has(t.id),C=u("div","persona-border-b persona-border-persona-divider persona-text-xs");ee(C,o.classNames?.eventRow);let k=n.find(B=>B.renderEventStreamRow);if(k?.renderEventStreamRow&&p){let B=k.renderEventStreamRow({event:t,index:e,config:p,defaultRenderer:()=>N(),isExpanded:x,onToggleExpand:()=>f(t.id)});if(B)return C.appendChild(B),C}return C.appendChild(N()),C;function N(){let B=u("div",""),D=u("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");D.setAttribute("data-event-id",t.id);let te=u("span","persona-flex-shrink-0 persona-text-persona-muted persona-w-4 persona-text-center persona-flex persona-items-center persona-justify-center"),L=I(x?ve:Te,"14px","currentColor",2);L&&te.appendChild(L);let H=u("span","persona-text-[11px] persona-text-persona-muted persona-whitespace-nowrap persona-flex-shrink-0 persona-font-mono persona-w-[70px]"),y=o.timestampFormat??"relative";H.textContent=y==="relative"?ct(t.timestamp,r):ht(t.timestamp);let F=null;o.showSequenceNumbers!==!1&&(F=u("span","persona-text-[11px] persona-text-persona-muted persona-font-mono persona-flex-shrink-0 persona-w-[28px] persona-text-right"),F.textContent=String(e+1));let M=mt(t.type,o.badgeColors),R=u("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");R.style.backgroundColor=M.bg,R.style.color=M.text,R.style.borderColor=xt(M.text),R.textContent=t.type;let re=o.descriptionFields??pt,j=gt(t.payload,re),W=null;j&&(W=u("span","persona-text-[11px] persona-text-persona-secondary persona-truncate persona-min-w-0"),W.textContent=j);let v=u("div","persona-flex-1 persona-min-w-0"),T=u("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"),oe=I(xe,"12px","currentColor",1.5);return oe&&T.appendChild(oe),T.addEventListener("click",async Q=>{Q.stopPropagation(),await Ct(St(t)),T.innerHTML="";let q=I(ie,"12px","currentColor",1.5);q&&T.appendChild(q),setTimeout(()=>{T.innerHTML="";let Y=I(xe,"12px","currentColor",1.5);Y&&T.appendChild(Y)},1500)}),D.appendChild(te),D.appendChild(H),F&&D.appendChild(F),D.appendChild(R),W&&D.appendChild(W),D.appendChild(v),D.appendChild(T),B.appendChild(D),x&&B.appendChild(bt(t,n,p)),B}}function je(t){let{buffer:e,getFullHistory:r,onClose:o,config:a,plugins:f=[],getThroughput:n}=t,p=t.renderIconByName??(()=>null),x=a?.features?.scrollToBottom,C=x?.enabled!==!1,k=x?.iconName??"arrow-down",N=x?.label??"",B=a?.features?.eventStream??{},D=f.find(L=>L.renderEventStreamView);if(D?.renderEventStreamView&&a){let L=D.renderEventStreamView({config:a,events:e.getAll(),defaultRenderer:()=>te().element,onClose:o});if(L)return{element:L,update:()=>{},destroy:()=>{}}}return te();function te(){let L=B.classNames,H=u("div","persona-event-stream-view persona-flex persona-flex-col persona-flex-1 persona-min-h-0");ee(H,L?.panel);let y=[],F="",M="",R=null,re=[],j={},W=0,v=Ke(),T=0,oe=0,Q=!1,q=null,Y=!1,Be=0,Z=new Set,O=new Map,Le="",Fe="",J=null,S,g,w,E,ae=null,U=null,V=null;function we(){let s=u("div","persona-event-toolbar persona-relative persona-flex persona-flex-col persona-flex-shrink-0"),l=u("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(ee(l,L?.headerBar),n){U=u("div","persona-relative persona-flex persona-items-center persona-gap-1.5 persona-whitespace-nowrap"),U.style.cursor="help",ae=u("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"),ae.textContent="-- tok/s",V=u("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 K=U,ne=V,lt=()=>{if(!ne.textContent)return;let ze=K.getBoundingClientRect(),Xe=s.getBoundingClientRect();ne.style.left=`${ze.left-Xe.left}px`,ne.style.top=`${ze.bottom-Xe.top+4}px`,ne.style.display="block"},ut=()=>{ne.style.display="none"};U.addEventListener("mouseenter",lt),U.addEventListener("mouseleave",ut),U.appendChild(ae)}let d=u("div","persona-flex-1");S=u("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 b=u("option","");b.value="",b.textContent="All events (0)",S.appendChild(b),g=u("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"),g.type="button",g.title="Copy All";let z=I(me,"12px","currentColor",1.5);z&&g.appendChild(z);let X=u("span","persona-event-copy-all persona-text-xs");X.textContent="Copy All",g.appendChild(X),U&&l.appendChild(U),l.appendChild(d),l.appendChild(S),l.appendChild(g);let i=u("div","persona-relative persona-px-4 persona-py-2.5 persona-border-b persona-border-persona-divider persona-bg-persona-surface");ee(i,L?.searchBar);let m=I(Ae,"14px","var(--persona-muted, #9ca3af)",1.5),h=u("span","persona-absolute persona-left-6 persona-top-1/2 persona--translate-y-1/2 persona-pointer-events-none persona-flex persona-items-center");m&&h.appendChild(m),w=u("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"),ee(w,L?.searchInput),w.type="text",w.placeholder="Search event payloads...",E=u("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"),E.type="button",E.style.display="none";let P=I(ce,"12px","currentColor",2);return P&&E.appendChild(P),i.appendChild(h),i.appendChild(w),i.appendChild(E),s.appendChild(l),s.appendChild(i),V&&s.appendChild(V),s}let ye,Re=f.find(s=>s.renderEventStreamToolbar);Re?.renderEventStreamToolbar&&a?ye=Re.renderEventStreamToolbar({config:a,defaultRenderer:()=>we(),eventCount:e.getSize(),filteredCount:0,onFilterChange:l=>{F=l,ue(),$()},onSearchChange:l=>{M=l,ue(),$()}})??we():ye=we();let fe=u("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");fe.style.display="none";function rt(){if(!n||!ae||!U)return;let s=n(),l=wt(s);ae.textContent=l;let d=yt(s);V&&(V.textContent=d,d||(V.style.display="none")),U.setAttribute("aria-label",d?`Throughput: ${l}, ${d}`:`Throughput: ${l}`)}let de=u("div","persona-flex-1 persona-min-h-0 persona-relative"),c=u("div","persona-event-stream-list persona-overflow-y-auto persona-min-h-0");c.style.height="100%";let A=u("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");ee(A,L?.scrollIndicator),A.style.display="none",A.setAttribute("data-persona-scroll-to-bottom-has-label",N?"true":"false");let Ee=p(k,"14px","currentColor",2);Ee&&A.appendChild(Ee);let se=u("span","");se.textContent=N,A.appendChild(se);let le=u("div","persona-flex persona-items-center persona-justify-center persona-h-full persona-text-sm persona-text-persona-muted");le.style.display="none",de.appendChild(c),de.appendChild(le),de.appendChild(A),H.setAttribute("tabindex","0"),H.appendChild(ye),H.appendChild(fe),H.appendChild(de);function ot(){let s=e.getAll(),l={};for(let i of s)l[i.type]=(l[i.type]||0)+1;let d=Object.keys(l).sort(),b=d.length!==re.length||!d.every((i,m)=>i===re[m]),G=!b&&d.some(i=>l[i]!==j[i]),z=s.length!==Object.values(j).reduce((i,m)=>i+m,0);if(!b&&!G&&!z||(re=d,j=l,!S))return;let X=S.value;if(S.options[0].textContent=`All events (${s.length})`,b){for(;S.options.length>1;)S.remove(1);for(let i of d){let m=u("option","");m.value=i,m.textContent=`${i} (${l[i]||0})`,S.appendChild(m)}X&&d.includes(X)?S.value=X:X&&(S.value="",F="")}else for(let i=1;i<S.options.length;i++){let m=S.options[i];m.textContent=`${m.value} (${l[m.value]||0})`}}function at(){let s=e.getAll();if(F&&(s=s.filter(l=>l.type===F)),M){let l=M.toLowerCase();s=s.filter(d=>d.type.toLowerCase().includes(l)||d.payload.toLowerCase().includes(l))}return s}function be(){return F!==""||M!==""}function ue(){W=0,T=0,v.resume(),A.style.display="none"}function pe(s){Z.has(s)?Z.delete(s):Z.add(s),J=s;let l=c.scrollTop,d=v.isFollowing();Y=!0,v.pause(),$(),c.scrollTop=l,d&&v.resume(),Y=!1}function De(){return _e(c,50)}function $(){oe=Date.now(),Q=!1,rt(),ot();let s=e.getEvictedCount();s>0?(fe.textContent=`${s.toLocaleString()} older events truncated`,fe.style.display=""):fe.style.display="none",y=at();let l=y.length,d=e.getSize()>0;l===0&&d&&be()?(le.textContent=M?`No events matching '${M}'`:"No events matching filter",le.style.display="",c.style.display="none"):(le.style.display="none",c.style.display=""),g&&(g.title=be()?`Copy Filtered (${l})`:"Copy All"),C&&!v.isFollowing()&&l>W&&(T+=l-W,se.textContent=N?`${N}${T>0?` (${T})`:""}`:"",A.style.display=""),W=l;let b=e.getAll(),G=b.length>0?b[0].timestamp:0,z=new Set(y.map(m=>m.id));for(let m of Z)z.has(m)||Z.delete(m);let X=F!==Le||M!==Fe,i=O.size===0&&y.length>0;if(X||i||y.length===0){c.innerHTML="",O.clear();let m=document.createDocumentFragment();for(let h=0;h<y.length;h++){let P=Pe(y[h],h,G,B,Z,pe,f,a);O.set(y[h].id,P),m.appendChild(P)}c.appendChild(m),Le=F,Fe=M,J=null}else{if(J!==null){let h=O.get(J);if(h&&h.parentNode===c){let P=y.findIndex(K=>K.id===J);if(P>=0){let K=Pe(y[P],P,G,B,Z,pe,f,a);c.insertBefore(K,h),h.remove(),O.set(J,K)}}J=null}let m=new Set(y.map(h=>h.id));for(let[h,P]of O)m.has(h)||(P.remove(),O.delete(h));for(let h=0;h<y.length;h++){let P=y[h];if(!O.has(P.id)){let K=Pe(P,h,G,B,Z,pe,f,a);O.set(P.id,K),c.appendChild(K)}}}v.isFollowing()&&(c.scrollTop=c.scrollHeight)}function ft(){if(Date.now()-oe>=it){q!==null&&(cancelAnimationFrame(q),q=null),$();return}Q||(Q=!0,q=requestAnimationFrame(()=>{q=null,$()}))}let He=(s,l)=>{if(!g)return;g.innerHTML="";let d=I(s,"12px","currentColor",1.5);d&&g.appendChild(d);let b=u("span","persona-text-xs");b.textContent="Copy All",g.appendChild(b),setTimeout(()=>{g.innerHTML="";let G=I(me,"12px","currentColor",1.5);G&&g.appendChild(G);let z=u("span","persona-text-xs");z.textContent="Copy All",g.appendChild(z),g.disabled=!1},l)},qe=async()=>{if(g){g.disabled=!0;try{let s;be()?s=y:r?(s=await r(),s.length===0&&(s=e.getAll())):s=e.getAll();let l=s.map(d=>{try{return JSON.parse(d.payload)}catch{return d.payload}});await navigator.clipboard.writeText(JSON.stringify(l,null,2)),He(ie,1500)}catch{He(ce,1500)}}},Oe=()=>{S&&(F=S.value,ue(),$())},Ue=()=>{!w||!E||(E.style.display=w.value?"":"none",R&&clearTimeout(R),R=setTimeout(()=>{M=w.value,ue(),$()},150))},ke=()=>{!w||!E||(w.value="",M="",E.style.display="none",R&&clearTimeout(R),ue(),$())},Ie=()=>{if(Y)return;let s=c.scrollTop,{action:l,nextLastScrollTop:d}=Ze({following:v.isFollowing(),currentScrollTop:s,lastScrollTop:Be,nearBottom:De(),userScrollThreshold:1,resumeRequiresDownwardScroll:!0});Be=d,l==="resume"?(v.resume(),T=0,A.style.display="none"):l==="pause"&&(v.pause(),C&&(se.textContent=N,A.style.display=""))},Ne=s=>{let l=$e({following:v.isFollowing(),deltaY:s.deltaY,nearBottom:De(),resumeWhenNearBottom:!0});l==="pause"?(v.pause(),C&&(se.textContent=N,A.style.display="")):l==="resume"&&(v.resume(),T=0,A.style.display="none")},We=()=>{C&&(c.scrollTop=c.scrollHeight,v.resume(),T=0,A.style.display="none")},Ve=s=>{let l=s.target;if(!l||l.closest("button"))return;let d=l.closest("[data-event-id]");if(!d)return;let b=d.getAttribute("data-event-id");b&&pe(b)},Ge=s=>{if((s.metaKey||s.ctrlKey)&&s.key==="f"){s.preventDefault(),w?.focus(),w?.select();return}s.key==="Escape"&&(w&&document.activeElement===w?(ke(),w.blur(),H.focus()):o&&o())};g&&g.addEventListener("click",qe),S&&S.addEventListener("change",Oe),w&&w.addEventListener("input",Ue),E&&E.addEventListener("click",ke),c.addEventListener("scroll",Ie),c.addEventListener("wheel",Ne,{passive:!0}),c.addEventListener("click",Ve),A.addEventListener("click",We),H.addEventListener("keydown",Ge);function st(){R&&clearTimeout(R),q!==null&&(cancelAnimationFrame(q),q=null),Q=!1,O.clear(),g&&g.removeEventListener("click",qe),S&&S.removeEventListener("change",Oe),w&&w.removeEventListener("input",Ue),E&&E.removeEventListener("click",ke),c.removeEventListener("scroll",Ie),c.removeEventListener("wheel",Ne),c.removeEventListener("click",Ve),A.removeEventListener("click",We),H.removeEventListener("keydown",Ge)}return{element:H,update:ft,destroy:st}}}var he=class{#e;#t=0;#o=0;#a=0;#s=new Set;#r;#f;constructor(e=2e3,r=null){this.#r=e,this.#e=new Array(e),this.#f=r}push(e){this.#e[this.#t]=e,this.#t=(this.#t+1)%this.#r,this.#o<this.#r&&this.#o++,this.#a++,this.#s.add(e.type),this.#f?.put(e)}getAll(){return this.#o===0?[]:this.#o<this.#r?this.#e.slice(0,this.#o):[...this.#e.slice(this.#t,this.#r),...this.#e.slice(0,this.#t)]}async restore(){if(!this.#f)return 0;let e=await this.#f.getAll();if(e.length===0)return 0;let r=e.length>this.#r?e.slice(e.length-this.#r):e;for(let o of r)this.#e[this.#t]=o,this.#t=(this.#t+1)%this.#r,this.#o<this.#r&&this.#o++,this.#s.add(o.type);return this.#a=e.length,r.length}getAllFromStore(){return this.#f?this.#f.getAll():Promise.resolve(this.getAll())}getRecent(e){let r=this.getAll();return e>=r.length?r:r.slice(r.length-e)}getSize(){return this.#o}getTotalCaptured(){return this.#a}getEvictedCount(){return this.#a-this.#o}clear(){this.#e=new Array(this.#r),this.#t=0,this.#o=0,this.#a=0,this.#s.clear(),this.#f?.clear()}destroy(){this.#e=[],this.#t=0,this.#o=0,this.#a=0,this.#s.clear(),this.#f?.destroy()}getEventTypes(){return Array.from(this.#s)}};var ge=class{#e=null;#t=[];#o=!1;#a=!1;#s;#r;constructor(e="persona-event-stream",r="events"){this.#s=e,this.#r=r}open(){return new Promise((e,r)=>{try{let o=indexedDB.open(this.#s,1);o.onupgradeneeded=()=>{let a=o.result;a.objectStoreNames.contains(this.#r)||a.createObjectStore(this.#r,{keyPath:"id"}).createIndex("timestamp","timestamp",{unique:!1})},o.onsuccess=()=>{this.#e=o.result,e()},o.onerror=()=>{r(o.error)}}catch(o){r(o)}})}put(e){!this.#e||this.#a||(this.#t.push(e),this.#o||(this.#o=!0,queueMicrotask(()=>this.#f())))}putBatch(e){if(!(!this.#e||this.#a||e.length===0))try{let o=this.#e.transaction(this.#r,"readwrite").objectStore(this.#r);for(let a of e)o.put(a)}catch{}}getAll(){return new Promise((e,r)=>{if(!this.#e){e([]);return}try{let n=this.#e.transaction(this.#r,"readonly").objectStore(this.#r).index("timestamp").getAll();n.onsuccess=()=>{e(n.result)},n.onerror=()=>{r(n.error)}}catch(o){r(o)}})}getCount(){return new Promise((e,r)=>{if(!this.#e){e(0);return}try{let f=this.#e.transaction(this.#r,"readonly").objectStore(this.#r).count();f.onsuccess=()=>{e(f.result)},f.onerror=()=>{r(f.error)}}catch(o){r(o)}})}clear(){return new Promise((e,r)=>{if(!this.#e){e();return}this.#t=[];try{let f=this.#e.transaction(this.#r,"readwrite").objectStore(this.#r).clear();f.onsuccess=()=>{e()},f.onerror=()=>{r(f.error)}}catch(o){r(o)}})}close(){this.#e&&(this.#e.close(),this.#e=null)}destroy(){return this.#a=!0,this.#t=[],this.close(),new Promise((e,r)=>{try{let o=indexedDB.deleteDatabase(this.#s);o.onsuccess=()=>{e()},o.onerror=()=>{r(o.error)}}catch(o){r(o)}})}#f(){if(this.#o=!1,!this.#e||this.#a||this.#t.length===0)return;let e=this.#t;this.#t=[];try{let o=this.#e.transaction(this.#r,"readwrite").objectStore(this.#r);for(let a of e)o.put(a)}catch{}}};var kt=new Set(["step_start","turn_start"]),vt=new Set(["step_complete","turn_complete"]),et=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),tt=t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,Qe=(t,e)=>{let r=t[e];return et(r)?r:void 0};function Me(t){return t>0?Math.max(1,Math.ceil(t/4)):0}function Ce(t,e){if(!(t<=0||e===void 0||e<250))return t/(e/1e3)}function Tt(t,e){return typeof e.type=="string"?e.type:t}function Ye(t){let e=Qe(t,"tokens")??Qe(t,"totalTokens");return e?tt(e.output):void 0}function At(t){return tt(t.durationMs)}function Pt(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Se=class{#e={status:"idle"};#t=null;constructor(e=Pt){this.now=e}getMetric(){let e=this.#t;if(e&&this.#e.status==="running"&&e.firstDeltaAt!==void 0&&this.#e.outputTokens!==void 0){let r=this.now()-e.firstDeltaAt;return{...this.#e,durationMs:r,tokensPerSecond:Ce(this.#e.outputTokens,r)}}return this.#e}reset(){this.#t=null,this.#e={status:"idle"}}#o(e){this.#t={startedAt:e,visibleCharCount:0,exactOutputTokens:0},this.#e={status:"running"}}processEvent(e,r){if(!et(r)){e==="execution_error"&&this.#t&&(this.#t=null,this.#e={status:"error"});return}let o=Tt(e,r),a=this.now();if(o==="execution_start"){this.#o(a);return}if(kt.has(o)){this.#t||this.#o(a);return}if(o==="text_delta"){let f=typeof r.delta=="string"?r.delta:"";if(!f)return;this.#t||this.#o(a);let n=this.#t;n.firstDeltaAt??=a,n.visibleCharCount+=f.length;let p=n.exactOutputTokens+Me(n.visibleCharCount),x=a-n.firstDeltaAt;this.#e={status:"running",tokensPerSecond:Ce(p,x),outputTokens:p,durationMs:x,source:n.exactOutputTokens>0?"usage":"estimate"};return}if(vt.has(o)){if(!this.#t)return;let f=this.#t,n=Ye(r);n!==void 0&&(f.exactOutputTokens+=n,f.visibleCharCount=0);let p=f.exactOutputTokens>0,x=f.exactOutputTokens+Me(f.visibleCharCount),C=this.#a(f,r,a);this.#e={status:"running",tokensPerSecond:Ce(x,C),outputTokens:x,durationMs:C,source:p?"usage":"estimate"};return}if(o==="execution_complete"){if(!this.#t)return;let f=this.#t,n=Ye(r),p=n??f.exactOutputTokens+Me(f.visibleCharCount),x=n!==void 0||f.exactOutputTokens>0?"usage":"estimate",C=this.#a(f,r,a);this.#e={status:"complete",tokensPerSecond:Ce(p,C),outputTokens:p,durationMs:C,source:x},this.#t=null;return}if(o==="execution_error"||o==="error"&&r.recoverable===!1){if(!this.#t)return;this.#t=null,this.#e={status:"error"}}}#a(e,r,o){let a=e.firstDeltaAt!==void 0?o-e.firstDeltaAt:void 0;return a!==void 0&&a>=250?a:At(r)??o-e.startedAt}};export{he as EventStreamBuffer,ge as EventStreamStore,Se as ThroughputTracker,je as createEventStreamView};
|
|
2
2
|
/*! Bundled license information:
|
|
3
3
|
|
|
4
4
|
lucide/dist/esm/icons/check.mjs:
|