@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
package/dist/approval-ui.d.ts
CHANGED
|
@@ -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/approval-ui.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
\r `.includes(e[t]);)t++};return m()},we=ee;w.parse=we});var d=(e,a)=>{let o=document.createElement(e);return a&&(o.className=a),o};var J=Se(te(),1);var z=e=>{if(e===null)return"null";if(e===void 0)return"";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}};var re=()=>{},ae=e=>{re=e.webMcpToolTitle},X=e=>re(e);var K=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"M4.929 4.929 19.07 19.071"}]];var H=[["path",{d:"m6 9 6 6 6-6"}]];var $=[["path",{d:"m18 15-6-6-6 6"}]];var Z=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"M12 8v4"}],["path",{d:"M12 16h.01"}]];var q=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m9 12 2 2 4-4"}]];var W=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m14.5 9.5-5 5"}],["path",{d:"m9.5 9.5 5 5"}]];var R=(e,a=24,o="currentColor",t=2)=>{if(!Array.isArray(e))return null;let r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.setAttribute("width",String(a)),r.setAttribute("height",String(a)),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("fill","none"),r.setAttribute("stroke",o),r.setAttribute("stroke-width",String(t)),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round"),r.setAttribute("aria-hidden","true"),e.forEach(p=>{if(!Array.isArray(p)||p.length<2)return;let m=p[0],S=p[1];if(!S)return;let i=document.createElementNS("http://www.w3.org/2000/svg",m);Object.entries(S).forEach(([y,P])=>{y!=="stroke"&&i.setAttribute(y,String(P))}),r.appendChild(i)}),r};var U="webmcp:";var I=e=>{let o=(e.startsWith(U)?e.slice(U.length):e).replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[_\-\s.]+/).filter(Boolean);if(o.length===0)return e;let t=o.join(" ").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},oe=e=>e?.approval!==!1?e?.approval:void 0,fe=(e,a,o)=>{let t=oe(o)?.detailsDisplay??"collapsed";return a.get(e)??t==="expanded"},le=(e,a,o)=>{let t=oe(o);e.setAttribute("aria-expanded",a?"true":"false");let r=e.querySelector("[data-approval-details-label]");r&&(r.textContent=a?t?.hideDetailsLabel??"Hide details":t?.showDetailsLabel??"Show details");let p=e.querySelector("[data-approval-details-chevron]");if(p){p.innerHTML="";let m=R(a?$:H,14,"currentColor",2);m&&p.appendChild(m)}},se=(e,a,o,t=new Map)=>{let r=a.querySelector('button[data-bubble-type="approval"]'),p=a.querySelector("[data-approval-details]");if(!r||!p)return;let m=fe(e,t,o);le(r,m,o),p.style.display=m?"":"none"};var de=(e,a,o=new Map)=>{let t=e.approval,r=a?.approval!==!1?a?.approval:void 0,p=t?.status==="pending",m=d("div",["persona-approval-bubble","persona-w-full","persona-rounded-2xl","persona-border","persona-shadow-sm","persona-overflow-hidden"].join(" "));if(m.id=`bubble-${e.id}`,m.setAttribute("data-message-id",e.id),m.style.backgroundColor=r?.backgroundColor??"var(--persona-approval-bg)",m.style.borderColor=r?.borderColor??"var(--persona-approval-border)",m.style.boxShadow=r?.shadow!==void 0?r.shadow.trim()===""?"none":r.shadow:"var(--persona-approval-shadow)",!t)return m;let S=d("div","persona-flex persona-items-start persona-gap-3 persona-px-4 persona-py-3"),i=d("div","persona-flex-shrink-0 persona-mt-0.5");i.setAttribute("data-approval-icon","true");let y=t.status==="denied"?W:t.status==="timeout"?Z:q,P=t.status==="approved"?"var(--persona-feedback-success, var(--persona-palette-colors-success-600))":t.status==="denied"?"var(--persona-feedback-error, var(--persona-palette-colors-error-600))":t.status==="timeout"?"var(--persona-feedback-warning, var(--persona-palette-colors-warning-600))":r?.titleColor??"currentColor",T=R(y,20,P,2);T&&i.appendChild(T);let s=d("div","persona-flex-1 persona-min-w-0"),n=d("div","persona-flex persona-items-center persona-gap-2"),C=d("span","persona-text-sm persona-font-medium persona-text-persona-primary");if(r?.titleColor&&(C.style.color=r.titleColor),C.textContent=r?.title??"Approval Required",n.appendChild(C),!p){let u=d("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded-full persona-text-xs persona-font-medium");u.setAttribute("data-approval-status",t.status),t.status==="approved"?(u.style.backgroundColor="var(--persona-palette-colors-success-100)",u.style.color="var(--persona-palette-colors-success-700)",u.textContent="Approved"):t.status==="denied"?(u.style.backgroundColor="var(--persona-palette-colors-error-100)",u.style.color="var(--persona-palette-colors-error-700)",u.textContent="Denied"):t.status==="timeout"&&(u.style.backgroundColor="var(--persona-palette-colors-warning-100)",u.style.color="var(--persona-palette-colors-warning-700)",u.textContent="Timeout"),n.appendChild(u)}s.appendChild(n);let A=t.toolType==="webmcp"||t.toolName.startsWith(U)?X(t.toolName):void 0,c=r?.formatDescription?.({toolName:t.toolName,toolType:t.toolType,description:t.description,parameters:t.parameters,...A?{displayTitle:A}:{},...t.reason?{reason:t.reason}:{}}),L=!t.toolName,v=c||(L?t.description:`The assistant wants to use \u201C${A??I(t.toolName)}\u201D.`),k=d("p","persona-text-sm persona-mt-0.5 persona-text-persona-muted");if(k.setAttribute("data-approval-summary","true"),r?.descriptionColor&&(k.style.color=r.descriptionColor),k.textContent=v,s.appendChild(k),t.reason){let u=d("p","persona-text-sm persona-mt-1 persona-text-persona-muted");u.setAttribute("data-approval-reason","true"),r?.reasonColor?u.style.color=r.reasonColor:r?.descriptionColor&&(u.style.color=r.descriptionColor);let l=d("span","persona-font-medium");l.textContent=`${r?.reasonLabel??"Agent's stated reason:"} `,u.appendChild(l),u.appendChild(document.createTextNode(t.reason)),s.appendChild(u)}let O=r?.detailsDisplay??"collapsed",D=!!t.description&&!L,B=D||!!t.parameters;if(O!=="hidden"&&B){let u=fe(e.id,o,a),l=d("button","persona-inline-flex persona-items-center persona-gap-1 persona-mt-1 persona-p-0 persona-border-none persona-bg-transparent persona-text-xs persona-font-medium persona-cursor-pointer persona-text-persona-muted");l.type="button",l.setAttribute("data-expand-header","true"),l.setAttribute("data-bubble-type","approval"),r?.descriptionColor&&(l.style.color=r.descriptionColor);let x=d("span");x.setAttribute("data-approval-details-label","true");let b=d("span","persona-inline-flex persona-items-center");b.setAttribute("data-approval-details-chevron","true"),l.append(x,b),le(l,u,a),s.appendChild(l);let h=d("div");if(h.setAttribute("data-approval-details","true"),h.style.display=u?"":"none",D){let g=d("p","persona-text-sm persona-mt-1 persona-text-persona-muted");r?.descriptionColor&&(g.style.color=r.descriptionColor),g.textContent=t.description,h.appendChild(g)}if(t.parameters){let g=d("pre","persona-mt-2 persona-text-xs persona-p-2 persona-rounded persona-overflow-x-auto persona-max-h-32 persona-bg-persona-container persona-text-persona-primary");r?.parameterBackgroundColor&&(g.style.backgroundColor=r.parameterBackgroundColor),r?.parameterTextColor&&(g.style.color=r.parameterTextColor),g.style.fontSize="0.75rem",g.style.lineHeight="1rem",g.textContent=z(t.parameters),h.appendChild(g)}s.appendChild(h)}if(p){let u=d("div","persona-flex persona-gap-2 persona-mt-2");u.setAttribute("data-approval-buttons","true");let l=d("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-border-none persona-cursor-pointer");l.type="button",l.style.backgroundColor=r?.approveButtonColor??"var(--persona-approval-approve-bg)",l.style.color=r?.approveButtonTextColor??"var(--persona-button-primary-fg)",l.setAttribute("data-approval-action","approve");let x=R(q,14,r?.approveButtonTextColor??"var(--persona-button-primary-fg)",2);x&&(x.style.marginRight="4px",l.appendChild(x));let b=document.createTextNode(r?.approveLabel??"Approve");l.appendChild(b);let h=d("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-cursor-pointer");h.type="button",h.style.backgroundColor=r?.denyButtonColor??"transparent",h.style.color=r?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",h.style.border=`1px solid ${r?.denyButtonTextColor?r.denyButtonTextColor:"var(--persona-palette-colors-error-200)"}`,h.setAttribute("data-approval-action","deny");let g=R(W,14,r?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",2);g&&(g.style.marginRight="4px",h.appendChild(g));let E=document.createTextNode(r?.denyLabel??"Deny");h.appendChild(E),u.append(l,h),s.appendChild(u)}return S.append(i,s),m.appendChild(S),m};function Te(e){let a=e.getRootNode?.();return a instanceof ShadowRoot?a:(e.ownerDocument??document).body}function ue(e){let{anchor:a,content:o,placement:t="bottom-start",offset:r=6,matchAnchorWidth:p=!1,horizontalOffset:m,verticalOffset:S,zIndex:i=2147483e3,onOpen:y,onDismiss:P}=e,T=e.container??Te(a),s=!1,n=null,C=()=>{if(!s)return;let c=a.getBoundingClientRect();o.style.position="fixed",p&&(o.style.minWidth=`${c.width}px`),m&&(o.style.maxWidth=`${c.width}px`);let L=o.getBoundingClientRect(),v=S?.()??null,k=v!=null?c.top+v:c.top,O=t==="top-start"||t==="top-end"?k-r-L.height:c.bottom+r,B=t==="bottom-end"||t==="top-end"?c.right-L.width:c.left,u=m?.()??null;if(u!=null){let l=Math.max(c.left,c.right-L.width);B=Math.min(Math.max(c.left+u,c.left),l)}o.style.top=`${O}px`,o.style.left=`${B}px`},F=()=>{s&&(s=!1,n&&(n(),n=null),o.remove())},A=()=>{if(s)return;s=!0,i!=null&&(o.style.zIndex=String(i)),T.appendChild(o),C();let c=(a.ownerDocument??document).defaultView??window,L=a.ownerDocument??document,v=()=>{if(!a.isConnected){F(),P?.("anchor-removed");return}C()},k=D=>{let B=typeof D.composedPath=="function"?D.composedPath():[];B.includes(o)||B.includes(a)||(F(),P?.("outside"))},O=c.setTimeout(()=>{L.addEventListener("pointerdown",k,!0)},0);c.addEventListener("scroll",v,!0),c.addEventListener("resize",v),n=()=>{c.clearTimeout(O),L.removeEventListener("pointerdown",k,!0),c.removeEventListener("scroll",v,!0),c.removeEventListener("resize",v)},y?.()};return{get isOpen(){return s},open:A,close:F,toggle:()=>s?F():A(),reposition:C,destroy:F}}function ne(e){return(typeof e.composedPath=="function"?e.composedPath():[]).some(o=>o instanceof HTMLElement&&(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))}var Me=()=>({keyHandlers:new Map,popovers:new Map,pendingOrder:[],latestPendingApprovalId:null}),pe=(e,a)=>{let o=e.keyHandlers.get(a);o&&(document.removeEventListener("keydown",o),e.keyHandlers.delete(a));let t=e.popovers.get(a);t&&(t.destroy(),e.popovers.delete(a))},N=(e,a)=>{pe(e,a);let o=e.pendingOrder.indexOf(a);o!==-1&&e.pendingOrder.splice(o,1),e.latestPendingApprovalId===a&&(e.latestPendingApprovalId=e.pendingOrder.length?e.pendingOrder[e.pendingOrder.length-1]:null)},Pe=e=>e?.approval!==!1?e?.approval:void 0,ke=(e,a,o)=>{let t=o?.detailsDisplay??"collapsed";return a.get(e)??t==="expanded"},Q=e=>{let a=d("span","persona-approval-kbd");return a.textContent=e,a},ve=(e,a)=>{let o=d("span","persona-approval-title");a?.titleColor&&(o.style.color=a.titleColor);let r=e.toolType==="webmcp"||e.toolName.startsWith(U)?X(e.toolName):void 0,p=a?.formatDescription?.({toolName:e.toolName,toolType:e.toolType,description:e.description??"",parameters:e.parameters,...r?{displayTitle:r}:{},...e.reason?{reason:e.reason}:{}});if(p)return o.textContent=p,o;let m=r??I(e.toolName),S=e.toolType&&e.toolType!=="webmcp"?e.toolType:null;o.append("The assistant wants to use ");let i=document.createElement("strong");if(i.textContent=m,o.appendChild(i),S){o.append(" from ");let y=document.createElement("strong");y.textContent=S,o.appendChild(y)}return o},Le=e=>{let a=d("div","persona-approval-resolved"),o=R(K,15,"currentColor",2);o&&a.appendChild(o);let t=d("span","persona-approval-resolved-name");return t.textContent=e.toolName?I(e.toolName):"Tool",a.append(t,document.createTextNode(e.status==="timeout"?" timed out":" denied")),a},Be=(e,a,o,t,r,p,m,S)=>{let i=d("div","persona-approval-card persona-shadow-sm");i.id=`bubble-${o.id}`,i.setAttribute("data-message-id",o.id),i.setAttribute("data-bubble-type","approval"),r?.backgroundColor&&(i.style.background=r.backgroundColor),r?.borderColor&&(i.style.borderColor=r.borderColor),r?.shadow!==void 0&&(i.style.boxShadow=r.shadow.trim()===""?"none":r.shadow);let y=r?.detailsDisplay??"collapsed",P=!!t.description&&y!=="hidden",T=t.parameters!=null&&y!=="hidden",s=P||T,n=s&&ke(o.id,a,r),C=r?.showDetailsLabel??"Show details",F=r?.hideDetailsLabel??"Hide details",A=d("button","persona-approval-head");A.type="button",s?(A.setAttribute("data-action","toggle-params"),A.setAttribute("aria-expanded",n?"true":"false"),A.setAttribute("aria-label",n?F:C)):A.setAttribute("data-static","true");let c=d("span","persona-approval-logo"),L=R(q,16,"currentColor",2);L&&c.appendChild(L),A.appendChild(c);let v=ve(t,r);if(s){let l=d("span","persona-approval-toggle");l.setAttribute("aria-hidden","true");let x=R(H,14,"currentColor",2);x&&l.appendChild(x),v.append(" "),v.appendChild(l)}A.appendChild(v),i.appendChild(A);let k=d("div","persona-approval-body");if(s){let l=d("div","persona-approval-details");if(l.setAttribute("data-role","params"),l.hidden=!n,P){let x=d("p","persona-approval-desc");r?.descriptionColor&&(x.style.color=r.descriptionColor),x.textContent=t.description,l.appendChild(x)}if(T){let x=d("pre","persona-approval-params");r?.parameterBackgroundColor&&(x.style.background=r.parameterBackgroundColor),r?.parameterTextColor&&(x.style.color=r.parameterTextColor),x.textContent=z(t.parameters),l.appendChild(x)}k.appendChild(l)}if(t.reason){let l=d("p","persona-approval-reason");r?.reasonColor?l.style.color=r.reasonColor:r?.descriptionColor&&(l.style.color=r.descriptionColor);let x=d("span","persona-approval-reason-label");x.textContent=`${r?.reasonLabel??"Agent's stated reason:"} `,l.append(x,document.createTextNode(t.reason)),k.appendChild(l)}let O=d("div","persona-approval-actions"),D=null,B=l=>{r?.approveButtonColor&&(l.style.background=r.approveButtonColor),r?.approveButtonTextColor&&(l.style.color=r.approveButtonTextColor)},u=d("button","persona-approval-deny");if(u.type="button",u.setAttribute("data-action","deny"),r?.denyButtonColor&&(u.style.background=r.denyButtonColor),r?.denyButtonTextColor&&(u.style.color=r.denyButtonTextColor),u.append(r?.denyLabel??"Deny"),S){let l=d("div","persona-approval-split"),x=d("button","persona-approval-primary");x.type="button",x.setAttribute("data-action","always"),B(x),x.append(r?.approveLabel??"Always allow",Q("\u23CE"));let b=d("button","persona-approval-caret");b.type="button",b.setAttribute("data-action","toggle-menu"),b.setAttribute("aria-label","More options"),B(b);let h=R(H,15,"currentColor",2);h&&b.appendChild(h),l.append(x,b),O.append(l,u),u.append(Q("Esc"));let g=d("div","persona-approval-menu"),E=d("button","persona-approval-menu-item");E.type="button",E.append("Allow once",Q("\u2318\u23CE")),g.appendChild(E),D=ue({anchor:l,content:g,placement:"bottom-start",matchAnchorWidth:!0}),e.popovers.set(o.id,D),E.addEventListener("click",()=>{N(e,o.id),p()})}else{let l=d("button","persona-approval-primary persona-approval-primary--solo");l.type="button",l.setAttribute("data-action","allow"),B(l),l.append(r?.approveLabel??"Allow"),O.append(l,u)}return k.appendChild(O),i.appendChild(k),i.addEventListener("click",l=>{let x=l.target instanceof Element?l.target.closest("[data-action]"):null;if(!x)return;let b=x.getAttribute("data-action");if(b==="toggle-params"){let h=i.querySelector('[data-role="params"]');if(h){let g=h.hidden;h.hidden=!g,A.setAttribute("aria-expanded",g?"true":"false"),A.setAttribute("aria-label",g?F:C),a.set(o.id,g)}return}if(b==="toggle-menu"){D?.toggle();return}if(b==="always"){N(e,o.id),p({remember:!0});return}if(b==="allow"){N(e,o.id),p();return}if(b==="deny"){N(e,o.id),m();return}}),i},ie=(e=new Map)=>{let a=Me();return{plugin:{id:"persona-built-in-approval",renderApproval:({message:r,approve:p,deny:m,config:S})=>{let i=r?.approval;if(!i)return null;let y=Pe(S);if(i.status!=="pending"){if(N(a,r.id),i.status==="approved"){let s=document.createElement("div");return s.style.display="none",s}return Le(i)}pe(a,r.id);let P=y?.enableAlwaysAllow===!0,T=Be(a,e,r,i,y,p,m,P);if(P){a.pendingOrder.includes(r.id)||a.pendingOrder.push(r.id),a.latestPendingApprovalId=a.pendingOrder[a.pendingOrder.length-1];let s=n=>{ne(n)||r.id===a.latestPendingApprovalId&&(n.key!=="Escape"&&n.key!=="Enter"||(n.preventDefault(),n.stopImmediatePropagation(),N(a,r.id),n.key==="Escape"?m():n.metaKey||n.ctrlKey?p():p({remember:!0})))};a.keyHandlers.set(r.id,s),document.addEventListener("keydown",s)}return T}},teardown:()=>{for(let r of[...a.keyHandlers.keys(),...a.popovers.keys()])N(a,r);a.latestPendingApprovalId=null}}};export{de as createApprovalBubble,ie as createBuiltInApprovalPlugin,I as humanizeToolName,ae as initApprovalUi,se as updateApprovalDetailsUI};
|
|
1
|
+
var xe=Object.create;var j=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var ee=(e,a)=>()=>(a||e((a={exports:{}}).exports,a),a.exports);var Se=(e,a,o,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of ge(a))!Ce.call(e,r)&&r!==o&&j(e,r,{get:()=>a[r],enumerable:!(t=ce(a,r))||t.enumerable});return e};var ye=(e,a,o)=>(o=e!=null?xe(he(e)):{},Se(a||!e||!e.__esModule?j(o,"default",{value:e,enumerable:!0}):o,e));var J=ee(f=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0});f.Allow=f.ALL=f.COLLECTION=f.ATOM=f.SPECIAL=f.INF=f._INFINITY=f.INFINITY=f.NAN=f.BOOL=f.NULL=f.OBJ=f.ARR=f.NUM=f.STR=void 0;f.STR=1;f.NUM=2;f.ARR=4;f.OBJ=8;f.NULL=16;f.BOOL=32;f.NAN=64;f.INFINITY=128;f._INFINITY=256;f.INF=f.INFINITY|f._INFINITY;f.SPECIAL=f.NULL|f.BOOL|f.INF|f.NAN;f.ATOM=f.STR|f.NUM|f.SPECIAL;f.COLLECTION=f.ARR|f.OBJ;f.ALL=f.ATOM|f.COLLECTION;f.Allow={STR:f.STR,NUM:f.NUM,ARR:f.ARR,OBJ:f.OBJ,NULL:f.NULL,BOOL:f.BOOL,NAN:f.NAN,INFINITY:f.INFINITY,_INFINITY:f._INFINITY,INF:f.INF,SPECIAL:f.SPECIAL,ATOM:f.ATOM,COLLECTION:f.COLLECTION,ALL:f.ALL};f.default=f.Allow});var re=ee(w=>{"use strict";var Ae=w&&w.__createBinding||(Object.create?(function(e,a,o,t){t===void 0&&(t=o);var r=Object.getOwnPropertyDescriptor(a,o);(!r||("get"in r?!a.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return a[o]}}),Object.defineProperty(e,t,r)}):(function(e,a,o,t){t===void 0&&(t=o),e[t]=a[o]})),be=w&&w.__exportStar||function(e,a){for(var o in e)o!=="default"&&!Object.prototype.hasOwnProperty.call(a,o)&&Ae(a,e,o)};Object.defineProperty(w,"__esModule",{value:!0});w.Allow=w.MalformedJSON=w.PartialJSON=w.parseJSON=w.parse=void 0;var T=J();Object.defineProperty(w,"Allow",{enumerable:!0,get:function(){return T.Allow}});be(J(),w);var z=class extends Error{};w.PartialJSON=z;var X=class extends Error{};w.MalformedJSON=X;function te(e,a=T.Allow.ALL){if(typeof e!="string")throw new TypeError(`expecting str, got ${typeof e}`);if(!e.trim())throw new Error(`${e} is empty`);return we(e.trim(),a)}w.parseJSON=te;var we=(e,a)=>{let o=e.length,t=0,r=s=>{throw new z(`${s} at position ${t}`)},u=s=>{throw new X(`${s} at position ${t}`)},c=()=>(b(),t>=o&&r("Unexpected end of input"),e[t]==='"'?A():e[t]==="{"?S():e[t]==="["?C():e.substring(t,t+4)==="null"||T.Allow.NULL&a&&o-t<4&&"null".startsWith(e.substring(t))?(t+=4,null):e.substring(t,t+4)==="true"||T.Allow.BOOL&a&&o-t<4&&"true".startsWith(e.substring(t))?(t+=4,!0):e.substring(t,t+5)==="false"||T.Allow.BOOL&a&&o-t<5&&"false".startsWith(e.substring(t))?(t+=5,!1):e.substring(t,t+8)==="Infinity"||T.Allow.INFINITY&a&&o-t<8&&"Infinity".startsWith(e.substring(t))?(t+=8,1/0):e.substring(t,t+9)==="-Infinity"||T.Allow._INFINITY&a&&1<o-t&&o-t<9&&"-Infinity".startsWith(e.substring(t))?(t+=9,-1/0):e.substring(t,t+3)==="NaN"||T.Allow.NAN&a&&o-t<3&&"NaN".startsWith(e.substring(t))?(t+=3,NaN):M()),A=()=>{let s=t,n=!1;for(t++;t<o&&(e[t]!=='"'||n&&e[t-1]==="\\");)n=e[t]==="\\"?!n:!1,t++;if(e.charAt(t)=='"')try{return JSON.parse(e.substring(s,++t-Number(n)))}catch(g){u(String(g))}else if(T.Allow.STR&a)try{return JSON.parse(e.substring(s,t-Number(n))+'"')}catch{return JSON.parse(e.substring(s,e.lastIndexOf("\\"))+'"')}r("Unterminated string literal")},S=()=>{t++,b();let s={};try{for(;e[t]!=="}";){if(b(),t>=o&&T.Allow.OBJ&a)return s;let n=A();b(),t++;try{let g=c();s[n]=g}catch(g){if(T.Allow.OBJ&a)return s;throw g}b(),e[t]===","&&t++}}catch{if(T.Allow.OBJ&a)return s;r("Expected '}' at end of object")}return t++,s},C=()=>{t++;let s=[];try{for(;e[t]!=="]";)s.push(c()),b(),e[t]===","&&t++}catch{if(T.Allow.ARR&a)return s;r("Expected ']' at end of array")}return t++,s},M=()=>{if(t===0){e==="-"&&u("Not sure what '-' is");try{return JSON.parse(e)}catch(n){if(T.Allow.NUM&a)try{return JSON.parse(e.substring(0,e.lastIndexOf("e")))}catch{}u(String(n))}}let s=t;for(e[t]==="-"&&t++;e[t]&&",]}".indexOf(e[t])===-1;)t++;t==o&&!(T.Allow.NUM&a)&&r("Unterminated number literal");try{return JSON.parse(e.substring(s,t))}catch{e.substring(s,t)==="-"&&r("Not sure what '-' is");try{return JSON.parse(e.substring(s,e.lastIndexOf("e")))}catch(g){u(String(g))}}},b=()=>{for(;t<o&&`
|
|
2
|
+
\r `.includes(e[t]);)t++};return c()},Te=te;w.parse=Te});var l=(e,a)=>{let o=document.createElement(e);return a&&(o.className=a),o};var K=ye(re(),1);var W=e=>{if(e===null)return"null";if(e===void 0)return"";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}};var ae=()=>{},oe=e=>{ae=e.webMcpToolTitle},_=e=>ae(e);var $=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"M4.929 4.929 19.07 19.071"}]];var H=[["path",{d:"m6 9 6 6 6-6"}]];var Z=[["path",{d:"m18 15-6-6-6 6"}]];var Q=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"M12 8v4"}],["path",{d:"M12 16h.01"}]];var q=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m9 12 2 2 4-4"}]];var G=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m14.5 9.5-5 5"}],["path",{d:"m9.5 9.5 5 5"}]];var R=(e,a=24,o="currentColor",t=2)=>{if(!Array.isArray(e))return null;let r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.setAttribute("width",String(a)),r.setAttribute("height",String(a)),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("fill","none"),r.setAttribute("stroke",o),r.setAttribute("stroke-width",String(t)),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round"),r.setAttribute("aria-hidden","true"),e.forEach(u=>{if(!Array.isArray(u)||u.length<2)return;let c=u[0],A=u[1];if(!A)return;let S=document.createElementNS("http://www.w3.org/2000/svg",c);Object.entries(A).forEach(([C,M])=>{C!=="stroke"&&S.setAttribute(C,String(M))}),r.appendChild(S)}),r};var U="webmcp:";var I=e=>{let o=(e.startsWith(U)?e.slice(U.length):e).replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[_\-\s.]+/).filter(Boolean);if(o.length===0)return e;let t=o.join(" ").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},fe=e=>e?.approval!==!1?e?.approval:void 0,le=(e,a,o)=>{let t=fe(o)?.detailsDisplay??"collapsed";return a.get(e)??t==="expanded"},se=(e,a,o)=>{let t=fe(o);e.setAttribute("aria-expanded",a?"true":"false");let r=e.querySelector("[data-approval-details-label]");r&&(r.textContent=a?t?.hideDetailsLabel??"Hide details":t?.showDetailsLabel??"Show details");let u=e.querySelector("[data-approval-details-chevron]");if(u){u.innerHTML="";let c=R(a?Z:H,14,"currentColor",2);c&&u.appendChild(c)}},de=(e,a,o,t=new Map)=>{let r=a.querySelector('button[data-bubble-type="approval"]'),u=a.querySelector("[data-approval-details]");if(!r||!u)return;let c=le(e,t,o);se(r,c,o),u.style.display=c?"":"none"};var ue=(e,a,o=new Map)=>{let t=e.approval,r=a?.approval!==!1?a?.approval:void 0,u=t?.status==="pending",c=l("div",["persona-approval-bubble","persona-w-full","persona-rounded-2xl","persona-border","persona-shadow-sm","persona-overflow-hidden"].join(" "));if(c.id=`bubble-${e.id}`,c.setAttribute("data-message-id",e.id),c.style.backgroundColor=r?.backgroundColor??"var(--persona-approval-bg)",c.style.borderColor=r?.borderColor??"var(--persona-approval-border)",c.style.boxShadow=r?.shadow!==void 0?r.shadow.trim()===""?"none":r.shadow:"var(--persona-approval-shadow)",!t)return c;let A=l("div","persona-flex persona-items-start persona-gap-3 persona-px-4 persona-py-3"),S=l("div","persona-flex-shrink-0 persona-mt-0.5");S.setAttribute("data-approval-icon","true");let C=t.status==="denied"?G:t.status==="timeout"?Q:q,M=t.status==="approved"?"var(--persona-feedback-success, var(--persona-palette-colors-success-600))":t.status==="denied"?"var(--persona-feedback-error, var(--persona-palette-colors-error-600))":t.status==="timeout"?"var(--persona-feedback-warning, var(--persona-palette-colors-warning-600))":r?.titleColor??"currentColor",b=R(C,20,M,2);b&&S.appendChild(b);let s=l("div","persona-flex-1 persona-min-w-0"),n=l("div","persona-flex persona-items-center persona-gap-2"),g=l("span","persona-text-sm persona-font-medium persona-text-persona-primary");if(r?.titleColor&&(g.style.color=r.titleColor),g.textContent=r?.title??"Approval Required",n.appendChild(g),!u){let p=l("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded-full persona-text-xs persona-font-medium");p.setAttribute("data-approval-status",t.status),t.status==="approved"?(p.style.backgroundColor="var(--persona-palette-colors-success-100)",p.style.color="var(--persona-palette-colors-success-700)",p.textContent="Approved"):t.status==="denied"?(p.style.backgroundColor="var(--persona-palette-colors-error-100)",p.style.color="var(--persona-palette-colors-error-700)",p.textContent="Denied"):t.status==="timeout"&&(p.style.backgroundColor="var(--persona-palette-colors-warning-100)",p.style.color="var(--persona-palette-colors-warning-700)",p.textContent="Timeout"),n.appendChild(p)}s.appendChild(n);let O=t.toolType==="webmcp"||t.toolName.startsWith(U)?_(t.toolName):void 0,m=r?.formatDescription?.({toolName:t.toolName,toolType:t.toolType,description:t.description,parameters:t.parameters,...O?{displayTitle:O}:{},...t.reason?{reason:t.reason}:{}}),k=!t.toolName,v=m||(k?t.description:`The assistant wants to use \u201C${O??I(t.toolName)}\u201D.`),P=l("p","persona-text-sm persona-mt-0.5 persona-text-persona-muted");if(P.setAttribute("data-approval-summary","true"),r?.descriptionColor&&(P.style.color=r.descriptionColor),P.textContent=v,s.appendChild(P),t.reason){let p=l("p","persona-text-sm persona-mt-1 persona-text-persona-muted");p.setAttribute("data-approval-reason","true"),r?.reasonColor?p.style.color=r.reasonColor:r?.descriptionColor&&(p.style.color=r.descriptionColor);let h=l("span","persona-font-medium");h.textContent=`${r?.reasonLabel??"Agent's stated reason:"} `,p.appendChild(h),p.appendChild(document.createTextNode(t.reason)),s.appendChild(p)}let L=r?.detailsDisplay??"collapsed",D=!!t.description&&!k,B=D||!!t.parameters;if(L!=="hidden"&&B){let p=le(e.id,o,a),h=l("button","persona-inline-flex persona-items-center persona-gap-1 persona-mt-1 persona-p-0 persona-border-none persona-bg-transparent persona-text-xs persona-font-medium persona-cursor-pointer persona-text-persona-muted");h.type="button",h.setAttribute("data-expand-header","true"),h.setAttribute("data-bubble-type","approval"),r?.descriptionColor&&(h.style.color=r.descriptionColor);let d=l("span");d.setAttribute("data-approval-details-label","true");let x=l("span","persona-inline-flex persona-items-center");x.setAttribute("data-approval-details-chevron","true"),h.append(d,x),se(h,p,a),s.appendChild(h);let i=l("div");if(i.setAttribute("data-approval-details","true"),i.style.display=p?"":"none",D){let y=l("p","persona-text-sm persona-mt-1 persona-text-persona-muted");r?.descriptionColor&&(y.style.color=r.descriptionColor),y.textContent=t.description,i.appendChild(y)}if(t.parameters){let y=l("pre","persona-mt-2 persona-text-xs persona-p-2 persona-rounded persona-overflow-x-auto persona-max-h-32 persona-bg-persona-container persona-text-persona-primary");r?.parameterBackgroundColor&&(y.style.backgroundColor=r.parameterBackgroundColor),r?.parameterTextColor&&(y.style.color=r.parameterTextColor),y.style.fontSize="0.75rem",y.style.lineHeight="1rem",y.textContent=W(t.parameters),i.appendChild(y)}s.appendChild(i)}if(u){let p=l("div","persona-flex persona-gap-2 persona-mt-2");p.setAttribute("data-approval-buttons","true");let h=l("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-border-none persona-cursor-pointer");h.type="button",h.style.backgroundColor=r?.approveButtonColor??"var(--persona-approval-approve-bg)",h.style.color=r?.approveButtonTextColor??"var(--persona-button-primary-fg)",h.setAttribute("data-approval-action","approve");let d=R(q,14,r?.approveButtonTextColor??"var(--persona-button-primary-fg)",2);d&&(d.style.marginRight="4px",h.appendChild(d));let x=document.createTextNode(r?.approveLabel??"Approve");h.appendChild(x);let i=l("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-cursor-pointer");i.type="button",i.style.backgroundColor=r?.denyButtonColor??"transparent",i.style.color=r?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",i.style.border=`1px solid ${r?.denyButtonTextColor?r.denyButtonTextColor:"var(--persona-palette-colors-error-200)"}`,i.setAttribute("data-approval-action","deny");let y=R(G,14,r?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",2);y&&(y.style.marginRight="4px",i.appendChild(y));let N=document.createTextNode(r?.denyLabel??"Deny");i.appendChild(N),p.append(h,i),s.appendChild(p)}return A.append(S,s),c.appendChild(A),c};function Me(e){let a=e.getRootNode?.();return a instanceof ShadowRoot?a:(e.ownerDocument??document).body}function ne(e){let{anchor:a,content:o,placement:t="bottom-start",offset:r=6,matchAnchorWidth:u=!1,horizontalOffset:c,verticalOffset:A,zIndex:S=2147483e3,onOpen:C,onDismiss:M}=e,b=e.container??Me(a),s=!1,n=null,g=()=>{if(!s)return;let m=a.getBoundingClientRect();o.style.position="fixed",u&&(o.style.minWidth=`${m.width}px`),c&&(o.style.maxWidth=`${m.width}px`);let k=o.getBoundingClientRect(),v=A?.()??null,P=v!=null?m.top+v:m.top,L=t==="top-start"||t==="top-end"?P-r-k.height:m.bottom+r,B=t==="bottom-end"||t==="top-end"?m.right-k.width:m.left,p=c?.()??null;if(p!=null){let h=Math.max(m.left,m.right-k.width);B=Math.min(Math.max(m.left+p,m.left),h)}o.style.top=`${L}px`,o.style.left=`${B}px`},F=()=>{s&&(s=!1,n&&(n(),n=null),o.remove())},O=()=>{if(s)return;s=!0,S!=null&&(o.style.zIndex=String(S)),b.appendChild(o),g();let m=(a.ownerDocument??document).defaultView??window,k=a.ownerDocument??document,v=()=>{if(!a.isConnected){F(),M?.("anchor-removed");return}g()},P=D=>{let B=typeof D.composedPath=="function"?D.composedPath():[];B.includes(o)||B.includes(a)||(F(),M?.("outside"))},L=m.setTimeout(()=>{k.addEventListener("pointerdown",P,!0)},0);m.addEventListener("scroll",v,!0),m.addEventListener("resize",v),n=()=>{m.clearTimeout(L),k.removeEventListener("pointerdown",P,!0),m.removeEventListener("scroll",v,!0),m.removeEventListener("resize",v)},C?.()};return{get isOpen(){return s},open:O,close:F,toggle:()=>s?F():O(),reposition:g,destroy:F}}function pe(e){return(typeof e.composedPath=="function"?e.composedPath():[]).some(o=>o instanceof HTMLElement&&(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))}var Pe=()=>({keyHandlers:new Map,popovers:new Map,pendingOrder:[],latestPendingApprovalId:null}),ie=(e,a)=>{let o=e.keyHandlers.get(a);o&&(document.removeEventListener("keydown",o),e.keyHandlers.delete(a));let t=e.popovers.get(a);t&&(t.destroy(),e.popovers.delete(a))},E=(e,a)=>{ie(e,a);let o=e.pendingOrder.indexOf(a);o!==-1&&e.pendingOrder.splice(o,1),e.latestPendingApprovalId===a&&(e.latestPendingApprovalId=e.pendingOrder.length?e.pendingOrder[e.pendingOrder.length-1]:null)},ke=e=>e?.approval!==!1?e?.approval:void 0,ve=(e,a,o)=>{let t=o?.detailsDisplay??"collapsed";return a.get(e)??t==="expanded"},Y=e=>{let a=l("span","persona-approval-kbd");return a.textContent=e,a},Le=(e,a)=>{let o=l("span","persona-approval-title");a?.titleColor&&(o.style.color=a.titleColor);let r=e.toolType==="webmcp"||e.toolName.startsWith(U)?_(e.toolName):void 0,u=a?.formatDescription?.({toolName:e.toolName,toolType:e.toolType,description:e.description??"",parameters:e.parameters,...r?{displayTitle:r}:{},...e.reason?{reason:e.reason}:{}});if(u)return o.textContent=u,o;let c=r??I(e.toolName),A=e.toolType&&e.toolType!=="webmcp"?e.toolType:null;o.append("The assistant wants to use ");let S=document.createElement("strong");if(S.textContent=c,o.appendChild(S),A){o.append(" from ");let C=document.createElement("strong");C.textContent=A,o.appendChild(C)}return o},Be=e=>{let a=l("div","persona-approval-resolved"),o=R($,15,"currentColor",2);o&&a.appendChild(o);let t=l("span","persona-approval-resolved-name");return t.textContent=e.toolName?I(e.toolName):"Tool",a.append(t,document.createTextNode(e.status==="timeout"?" timed out":" denied")),a},De=(e,a,o,t,r,u,c,A,S=!1)=>{let C=l("div","persona-approval-card persona-shadow-sm");C.id=`bubble-${o.id}`,C.setAttribute("data-message-id",o.id),C.setAttribute("data-bubble-type","approval"),r?.backgroundColor&&(C.style.background=r.backgroundColor),r?.borderColor&&(C.style.borderColor=r.borderColor),r?.shadow!==void 0&&(C.style.boxShadow=r.shadow.trim()===""?"none":r.shadow);let M=r?.detailsDisplay??"collapsed",b=!!t.description&&M!=="hidden",s=t.parameters!=null&&M!=="hidden"&&!S,n=b||s,g=n&&ve(o.id,a,r),F=r?.showDetailsLabel??"Show details",O=r?.hideDetailsLabel??"Hide details",m=l("button","persona-approval-head");m.type="button",n?(m.setAttribute("data-action","toggle-params"),m.setAttribute("aria-expanded",g?"true":"false"),m.setAttribute("aria-label",g?O:F)):m.setAttribute("data-static","true");let k=l("span","persona-approval-logo"),v=R(q,16,"currentColor",2);v&&k.appendChild(v),m.appendChild(k);let P=Le(t,r);if(n){let d=l("span","persona-approval-toggle");d.setAttribute("aria-hidden","true");let x=R(H,14,"currentColor",2);x&&d.appendChild(x),P.append(" "),P.appendChild(d)}m.appendChild(P),C.appendChild(m);let L=l("div","persona-approval-body");if(n){let d=l("div","persona-approval-details");if(d.setAttribute("data-role","params"),d.hidden=!g,b){let x=l("p","persona-approval-desc");r?.descriptionColor&&(x.style.color=r.descriptionColor),x.textContent=t.description,d.appendChild(x)}if(s){let x=l("pre","persona-approval-params");r?.parameterBackgroundColor&&(x.style.background=r.parameterBackgroundColor),r?.parameterTextColor&&(x.style.color=r.parameterTextColor),x.textContent=W(t.parameters),d.appendChild(x)}L.appendChild(d)}if(S){let d=l("div","persona-approval-call");d.setAttribute("data-role","raw-call");let x=l("code","persona-approval-tool-name");if(x.textContent=t.toolName,d.appendChild(x),t.parameters!=null){let i=l("pre","persona-approval-params");r?.parameterBackgroundColor&&(i.style.background=r.parameterBackgroundColor),r?.parameterTextColor&&(i.style.color=r.parameterTextColor),i.textContent=W(t.parameters),d.appendChild(i)}L.appendChild(d)}if(t.reason){let d=l("p","persona-approval-reason");r?.reasonColor?d.style.color=r.reasonColor:r?.descriptionColor&&(d.style.color=r.descriptionColor);let x=l("span","persona-approval-reason-label");x.textContent=`${r?.reasonLabel??"Agent's stated reason:"} `,d.append(x,document.createTextNode(t.reason)),L.appendChild(d)}let D=l("div","persona-approval-actions"),B=null,p=d=>{r?.approveButtonColor&&(d.style.background=r.approveButtonColor),r?.approveButtonTextColor&&(d.style.color=r.approveButtonTextColor)},h=l("button","persona-approval-deny");if(h.type="button",h.setAttribute("data-action","deny"),r?.denyButtonColor&&(h.style.background=r.denyButtonColor),r?.denyButtonTextColor&&(h.style.color=r.denyButtonTextColor),h.append(r?.denyLabel??"Deny"),A){let d=l("div","persona-approval-split"),x=l("button","persona-approval-primary");x.type="button",x.setAttribute("data-action","always"),p(x),x.append(r?.approveLabel??"Always allow",Y("\u23CE"));let i=l("button","persona-approval-caret");i.type="button",i.setAttribute("data-action","toggle-menu"),i.setAttribute("aria-label","More options"),p(i);let y=R(H,15,"currentColor",2);y&&i.appendChild(y),d.append(x,i),D.append(d,h),h.append(Y("Esc"));let N=l("div","persona-approval-menu"),V=l("button","persona-approval-menu-item");V.type="button",V.append("Allow once",Y("\u2318\u23CE")),N.appendChild(V),B=ne({anchor:d,content:N,placement:"bottom-start",matchAnchorWidth:!0}),e.popovers.set(o.id,B),V.addEventListener("click",()=>{E(e,o.id),u()})}else{let d=l("button","persona-approval-primary persona-approval-primary--solo");d.type="button",d.setAttribute("data-action","allow"),p(d),d.append(r?.approveLabel??"Allow"),D.append(d,h)}return L.appendChild(D),C.appendChild(L),C.addEventListener("click",d=>{let x=d.target instanceof Element?d.target.closest("[data-action]"):null;if(!x)return;let i=x.getAttribute("data-action");if(i==="toggle-params"){let y=C.querySelector('[data-role="params"]');if(y){let N=y.hidden;y.hidden=!N,m.setAttribute("aria-expanded",N?"true":"false"),m.setAttribute("aria-label",N?O:F),a.set(o.id,N)}return}if(i==="toggle-menu"){B?.toggle();return}if(i==="always"){E(e,o.id),u({remember:!0});return}if(i==="allow"){E(e,o.id),u();return}if(i==="deny"){E(e,o.id),c();return}}),C},me=(e=new Map)=>{let a=Pe();return{plugin:{id:"persona-built-in-approval",renderApproval:({message:r,approve:u,deny:c,config:A})=>{let S=r?.approval;if(!S)return null;let C=ke(A);if(S.status!=="pending"){if(E(a,r.id),S.status==="approved"){let n=document.createElement("div");return n.style.display="none",n}return Be(S)}ie(a,r.id);let M=!!A?.clientToken,b=C?.enableAlwaysAllow===!0,s=De(a,e,r,S,C,u,c,b,M);if(b){a.pendingOrder.includes(r.id)||a.pendingOrder.push(r.id),a.latestPendingApprovalId=a.pendingOrder[a.pendingOrder.length-1];let n=g=>{pe(g)||r.id===a.latestPendingApprovalId&&(g.key!=="Escape"&&g.key!=="Enter"||(g.preventDefault(),g.stopImmediatePropagation(),E(a,r.id),g.key==="Escape"?c():g.metaKey||g.ctrlKey?u():u({remember:!0})))};a.keyHandlers.set(r.id,n),document.addEventListener("keydown",n)}return s}},teardown:()=>{for(let r of[...a.keyHandlers.keys(),...a.popovers.keys()])E(a,r);a.latestPendingApprovalId=null}}};export{ue as createApprovalBubble,me as createBuiltInApprovalPlugin,I as humanizeToolName,oe as initApprovalUi,de as updateApprovalDetailsUI};
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
lucide/dist/esm/icons/ban.mjs:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as
|
|
1
|
+
import{b as nt,c as ot,d as rt,e as at,f as it,g as st,i as V,j as ge,k as Te,l as lt,n as ct,o as dt}from"./chunk-QRKGQPU7.js";import{b as tt}from"./chunk-ZC66NAIR.js";import"./chunk-2ANTRKTV.js";import{a as ye}from"./chunk-7NQ4ZTHF.js";import{a as m,b as Qe,d as et}from"./chunk-76IELU7F.js";function oe(e){let t=String(e).split(/[\\/]/);return t[t.length-1]??""}function ft(e){let t=oe(e),n=t.lastIndexOf(".");return n<=0?"":t.slice(n+1).toLowerCase()}function ke(e){if(typeof e!="string")return"";let t=e.indexOf(`
|
|
2
2
|
`);if(t===-1||!e.slice(0,t).startsWith("```"))return e;let r=e.slice(t+1),o=r.lastIndexOf(`
|
|
3
3
|
`);return(o===-1?r:r.slice(0,o)).split("`\u200B``").join("```")}function fe(e){let t=ft(e.path);if(t)return t==="html"||t==="htm"?"html":t==="svg"?"svg":t==="md"||t==="mdx"?"markdown":"other";let n=(e.mimeType||"").toLowerCase();return n.includes("html")?"html":n.includes("svg")?"svg":n.includes("markdown")?"markdown":"other"}function ce(e){switch(fe(e)){case"html":return"HTML";case"svg":return"SVG";case"markdown":return"Markdown";default:{let t=ft(e.path);return t?t.toUpperCase():"File"}}}function Se(e){let t=e.markdown??"";return e.file?{filename:oe(e.file.path)||"artifact",mime:e.file.mimeType||"application/octet-stream",content:ke(t)}:{filename:`${e.title||"artifact"}.md`,mime:"text/markdown",content:t}}function Ee(e){let t=new Blob([e.content],{type:e.mime}),n=URL.createObjectURL(t),r=document.createElement("a");r.href=n,r.download=e.filename,r.click(),URL.revokeObjectURL(n)}var Pe="persona-artifact-custom-action-btn";function be(e,t){let n=t?.documentChrome??!1,r;if(typeof e.icon=="function"){if(e.showLabel){let o="persona-label-btn persona-label-btn--sm "+Pe+(n?" persona-artifact-doc-copy-btn":"");r=m("button",o)}else{let o="persona-icon-btn "+Pe+(n?" persona-artifact-doc-icon-btn":"");r=m("button",o)}r.type="button",r.setAttribute("aria-label",e.label),r.title=e.label;try{let o=e.icon();o&&r.appendChild(o)}catch{}if(e.showLabel){let o=m("span");o.textContent=e.label,r.appendChild(o)}}else e.showLabel||!e.icon?r=ge({icon:e.icon,label:e.label,className:Pe+(n?" persona-artifact-doc-copy-btn":"")}):r=V({icon:e.icon,label:e.label,className:Pe+(n?" persona-artifact-doc-icon-btn":"")});return t?.onClick&&r.addEventListener("click",t.onClick),r}function ve(e){if(!e)return null;let t={artifactId:e.id,title:e.title??"",artifactType:e.artifactType};return e.artifactType==="markdown"?(t.markdown=e.markdown??"",e.file&&(t.file=e.file)):t.jsonPayload=JSON.stringify({component:e.component,props:e.props},null,2),t}var Ne="http://www.w3.org/2000/svg";function pt(e){let t=document.createElementNS(Ne,"svg");t.setAttribute("class",et("persona-spinner",e)),t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("aria-hidden","true"),t.setAttribute("focusable","false");let n=document.createElementNS(Ne,"circle");n.setAttribute("class","persona-spinner-track"),n.setAttribute("cx","12"),n.setAttribute("cy","12"),n.setAttribute("r","9");let r=document.createElementNS(Ne,"circle");return r.setAttribute("class","persona-spinner-arc"),r.setAttribute("cx","12"),r.setAttribute("cy","12"),r.setAttribute("r","9"),t.appendChild(n),t.appendChild(r),t}function ut(e,t,n){let r=n?.loadingAnimation??"shimmer",o=n?.loadingAnimationDuration??2e3;if(r==="none"){e.textContent=t;return}if(r==="pulse"){e.setAttribute("data-preserve-animation","true"),e.classList.add("persona-tool-loading-pulse"),e.style.setProperty("--persona-tool-anim-duration",`${o}ms`),e.textContent=t;return}e.setAttribute("data-preserve-animation","true"),e.classList.add(`persona-tool-loading-${r}`),e.style.setProperty("--persona-tool-anim-duration",`${o}ms`),r==="shimmer-color"&&(n?.loadingAnimationColor&&e.style.setProperty("--persona-tool-anim-color",n.loadingAnimationColor),n?.loadingAnimationSecondaryColor&&e.style.setProperty("--persona-tool-anim-secondary-color",n.loadingAnimationSecondaryColor)),ct(e,t,0)}var Ve="persona-artifact-status-label",mt="persona-artifact-status-detail",yt="data-artifact-status-label",ze=new Map,gt=()=>typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now();function he(e){e&&ze.delete(e)}function Ot(e){let t=e.artifactType==="markdown"?e.file:void 0;return t?ce(t):e.artifactType==="component"?"Component":"Document"}function we(e,t,n){let r=Ot(e),o=`Generating ${r.toLowerCase()}...`,s=t?.statusLabel;if(typeof s=="string")return{label:s};if(typeof s!="function")return{label:o};let i=e.id,l=ze.get(i);e.status!=="complete"&&l===void 0&&(l=gt(),ze.set(i,l));let A=l===void 0?0:Math.max(0,gt()-l),h=e.artifactType==="component",f=!h&&typeof e.markdown=="string"?e.markdown:"",p=h?0:f.length,u=h||f===""?0:f.split(`
|
|
4
4
|
`).length,c=e.artifactType==="markdown"?e.file:void 0,y={artifactId:i,artifactType:e.artifactType,title:e.title,typeLabel:r,file:c,chars:p,lines:u,elapsedMs:A,content:()=>h?"":f,surface:n};try{let g=s(y);return typeof g=="string"?{label:g}:g&&typeof g=="object"&&typeof g.label=="string"?{label:g.label,detail:typeof g.detail=="string"?g.detail:void 0}:{label:o}}catch{return{label:o}}}function Ft(e){e.className=Ve,e.removeAttribute("data-preserve-animation"),e.style.removeProperty("--persona-tool-anim-duration"),e.style.removeProperty("--persona-tool-anim-color"),e.style.removeProperty("--persona-tool-anim-secondary-color"),e.replaceChildren()}function pe(e,t,n){let r=e.querySelector(`:scope > .${Ve}`);r||(r=m("span",Ve),e.appendChild(r)),r.getAttribute(yt)!==t.label&&(Ft(r),ut(r,t.label,n),r.setAttribute(yt,t.label));let o=e.querySelector(`:scope > .${mt}`),s=t.detail;s?(o||(o=m("span",mt),e.appendChild(o)),o.textContent!==s&&(o.textContent=s)):o&&o.remove()}var _t={keyword:"persona-code-token-keyword",string:"persona-code-token-string",comment:"persona-code-token-comment",number:"persona-code-token-number",tag:"persona-code-token-tag",attr:"persona-code-token-attr",property:"persona-code-token-property"},Dt=15e4,Me={html:"html",htm:"html",xhtml:"html",xml:"html",svg:"html",css:"css",js:"js",jsx:"js",mjs:"js",cjs:"js",ts:"js",tsx:"js",mts:"js",cts:"js",javascript:"js",typescript:"js",ecmascript:"js",json:"json",jsonc:"json",json5:"json"};function jt(e,t){let n=(e||"").trim().toLowerCase();if(n&&Me[n])return Me[n];if(t){let r=t.lastIndexOf(".");if(r>=0){let o=t.slice(r+1).toLowerCase();if(Me[o])return Me[o]}}return null}function Re(e,t){let n=[],r=0,o=0,s=i=>{i>o&&n.push({type:"plain",value:e.slice(o,i)})};for(;r<e.length;){let i=!1;for(let l of t){l.re.lastIndex=r;let A=l.re.exec(e);if(A&&A.index===r&&A[0].length>0){s(r);let h=l.map?l.map(A[0]):l.type;n.push({type:h,value:A[0]}),r+=A[0].length,o=r,i=!0;break}}i||(r+=1)}return s(e.length),n}var Nt=new Set(["abstract","any","as","async","await","boolean","break","case","catch","class","const","continue","debugger","declare","default","delete","do","else","enum","export","extends","false","finally","for","from","function","get","if","implements","import","in","instanceof","interface","keyof","let","namespace","never","new","null","number","object","of","private","protected","public","readonly","return","satisfies","set","static","string","super","switch","symbol","this","throw","true","try","type","typeof","undefined","unknown","var","void","while","yield"]),Vt=[{type:"comment",re:/\/\/[^\n]*/y},{type:"comment",re:/\/\*[\s\S]*?\*\//y},{type:"string",re:/`(?:\\[\s\S]|[^\\`])*`/y},{type:"string",re:/"(?:\\.|[^"\\\n])*"/y},{type:"string",re:/'(?:\\.|[^'\\\n])*'/y},{type:"number",re:/0[xX][0-9a-fA-F]+|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y},{type:"plain",re:/[A-Za-z_$][\w$]*/y,map:e=>Nt.has(e)?"keyword":"plain"}];function bt(e){return Re(e,Vt)}var zt=[{type:"string",re:/"(?:\\.|[^"\\])*"/y},{type:"number",re:/-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y},{type:"plain",re:/[A-Za-z_]\w*/y,map:e=>e==="true"||e==="false"||e==="null"?"keyword":"plain"}];function Wt(e){let t=Re(e,zt);for(let n=0;n<t.length;n+=1){if(t[n].type!=="string")continue;let r=n+1;for(;r<t.length&&t[r].value.trim()==="";)r+=1;let o=t[r];o&&o.value.replace(/^\s*/,"").startsWith(":")&&(t[n].type="property")}return t}var Ut=[{type:"comment",re:/\/\*[\s\S]*?\*\//y},{type:"string",re:/"(?:\\.|[^"\\\n])*"/y},{type:"string",re:/'(?:\\.|[^'\\\n])*'/y},{type:"keyword",re:/@[A-Za-z-]+/y},{type:"number",re:/#[0-9a-fA-F]{3,8}\b/y},{type:"number",re:/-?(?:\d+\.?\d*|\.\d+)(?:[a-z%]+)?/y},{type:"plain",re:/[A-Za-z_-][\w-]*/y}];function ht(e){let t=Re(e,Ut),n="";for(let r=0;r<t.length;r+=1){let o=t[r];if(o.type==="plain"&&/^[A-Za-z_-][\w-]*$/.test(o.value)){let i=r+1;for(;i<t.length&&t[i].value.trim()==="";)i+=1;let l=t[i];l&&l.value.replace(/^\s*/,"").startsWith(":")&&(n===""||n==="{"||n==="}"||n===";"||n===",")&&(o.type="property")}let s=o.value.replace(/\s+$/,"");s&&(n=s[s.length-1])}return t}var $t=[{type:"tag",re:/<\/?\s*[A-Za-z][\w:-]*/y},{type:"string",re:/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'/y},{type:"attr",re:/[A-Za-z_:@][\w:.-]*(?=\s*=)/y},{type:"attr",re:/[A-Za-z_:@][\w:.-]*/y},{type:"tag",re:/\/?>/y}];function qt(e){let t=[],n=(s,i)=>{i&&t.push({type:s,value:i})},r=e.length,o=0;for(;o<r;){if(e.startsWith("<!--",o)){let i=e.indexOf("-->",o+4),l=i===-1?r:i+3;n("comment",e.slice(o,l)),o=l;continue}if(e[o]==="<"&&e[o+1]==="!"){let i=e.indexOf(">",o),l=i===-1?r:i+1;n("tag",e.slice(o,l)),o=l;continue}if(e[o]==="<"&&/[A-Za-z/]/.test(e[o+1]||"")){let i=e.indexOf(">",o),l=i===-1?r:i+1,A=e.slice(o,l);for(let f of Re(A,$t))t.push(f);o=l;let h=/^<\s*(script|style)\b/i.exec(A);if(h&&!/\/>\s*$/.test(A)){let f=h[1].toLowerCase(),u=new RegExp("</\\s*"+f+"\\s*>","i").exec(e.slice(o)),c=u?o+u.index:r,y=e.slice(o,c),g=f==="script"?bt(y):ht(y);for(let S of g)t.push(S);o=c}continue}let s=e.indexOf("<",o);if(s===o)n("plain",e[o]),o+=1;else{let i=s===-1?r:s;n("plain",e.slice(o,i)),o=i}}return t}function Gt(e,t){switch(t){case"html":return qt(e);case"css":return ht(e);case"js":return bt(e);case"json":return Wt(e)}}function Kt(e){let t=Qe(),n=m("span","persona-code-line"),r=(o,s)=>{if(!s)return;let i=_t[o];if(i){let l=m("span",i);l.textContent=s,n.appendChild(l)}else n.appendChild(document.createTextNode(s))};for(let o of e){let s=o.value.split(`
|