@runtypelabs/persona 4.21.1 → 4.22.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-B_JdVK9o.d.cts → types-9Vxm-PPz.d.cts} +136 -6
- package/dist/animations/{types-B_JdVK9o.d.ts → types-9Vxm-PPz.d.ts} +136 -6
- package/dist/animations/wipe.d.cts +1 -1
- package/dist/animations/wipe.d.ts +1 -1
- package/dist/animations-extra.d.cts +136 -6
- package/dist/animations-extra.d.ts +136 -6
- package/dist/{approval-ui-RNNBR5R3.js → approval-ui-K7R5Q5OC.js} +1 -1
- package/dist/approval-ui.cjs +2 -2
- package/dist/approval-ui.d.cts +221 -16
- package/dist/approval-ui.d.ts +221 -16
- package/dist/approval-ui.js +2 -2
- package/dist/artifacts-ui-F4N6VMKF.js +7 -0
- package/dist/artifacts-ui.cjs +1 -1
- package/dist/artifacts-ui.d.cts +221 -16
- package/dist/artifacts-ui.d.ts +221 -16
- package/dist/artifacts-ui.js +1 -1
- package/dist/chunk-NQLDCJAP.js +4 -0
- package/dist/codegen.cjs +1 -1
- package/dist/codegen.js +1 -1
- package/dist/context-mentions.d.cts +221 -16
- package/dist/context-mentions.d.ts +221 -16
- package/dist/event-stream-view-GL3ADRY2.js +1 -0
- package/dist/event-stream-view.cjs +1 -1
- package/dist/event-stream-view.d.cts +221 -16
- package/dist/event-stream-view.d.ts +221 -16
- package/dist/event-stream-view.js +1 -1
- package/dist/forms-ui.d.cts +234 -25
- package/dist/forms-ui.d.ts +234 -25
- package/dist/history-view.d.cts +136 -6
- package/dist/history-view.d.ts +136 -6
- package/dist/index.cjs +70 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +302 -32
- package/dist/index.d.ts +302 -32
- package/dist/index.global.js +54 -54
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +69 -69
- package/dist/index.js.map +1 -1
- package/dist/launcher.global.js +2 -2
- package/dist/launcher.global.js.map +1 -1
- package/dist/session-reconnect.d.cts +221 -16
- package/dist/session-reconnect.d.ts +221 -16
- package/dist/smart-dom-reader.d.cts +221 -16
- package/dist/smart-dom-reader.d.ts +221 -16
- package/dist/testing.cjs +3 -3
- package/dist/testing.d.cts +3 -4
- package/dist/testing.d.ts +3 -4
- package/dist/testing.js +3 -3
- package/dist/theme-editor-preview.cjs +73 -73
- package/dist/theme-editor-preview.d.cts +221 -16
- package/dist/theme-editor-preview.d.ts +221 -16
- package/dist/theme-editor-preview.js +51 -51
- package/dist/theme-editor.cjs +4 -4
- package/dist/theme-editor.d.cts +221 -16
- package/dist/theme-editor.d.ts +221 -16
- package/dist/theme-editor.js +2 -2
- package/dist/theme-reference.cjs +1 -1
- package/dist/theme-reference.d.cts +65 -1
- package/dist/theme-reference.d.ts +65 -1
- package/dist/theme-reference.js +1 -1
- package/dist/voice-runtime.d.cts +6 -2
- package/dist/voice-runtime.d.ts +6 -2
- package/dist/webmcp-polyfill.js +1 -4
- package/dist/webmcp-runtime-JI7T4QYF.js +6 -0
- package/dist/webmcp-runtime.cjs +2 -2
- package/dist/webmcp-runtime.d.cts +34 -2
- package/dist/webmcp-runtime.d.ts +34 -2
- package/dist/webmcp-runtime.js +2 -2
- package/package.json +2 -2
- package/src/ask-user-question-tool.ts +1 -1
- package/src/client-history-rest.test.ts +2 -1
- package/src/client-visitor-history.test.ts +20 -4
- package/src/client.composer-options.test.ts +1 -1
- package/src/client.interrupt.test.ts +2 -2
- package/src/client.test.ts +477 -915
- package/src/client.ts +134 -494
- package/src/client.unified-tools.test.ts +76 -0
- package/src/components/artifact-preview.ts +5 -0
- package/src/components/event-stream-badge-theming.test.ts +162 -0
- package/src/components/event-stream-view.test.ts +76 -76
- package/src/components/event-stream-view.ts +55 -20
- package/src/components/tool-bubble.test.ts +12 -0
- package/src/components/tool-bubble.ts +13 -2
- package/src/event-stream-view-bundle.test.ts +2 -2
- package/src/generated/runtype-openapi-contract.ts +137 -1
- package/src/index-core.ts +2 -0
- package/src/internal/runtype-history-provider.test.ts +2 -2
- package/src/runtime/init.registry.test.ts +56 -0
- package/src/runtime/init.ts +17 -0
- package/src/session-history.test.ts +1 -1
- package/src/session.quote.test.ts +1 -1
- package/src/session.resubmit-from.test.ts +1 -1
- package/src/session.test.ts +5 -5
- package/src/session.ts +95 -36
- package/src/suggest-replies-tool.ts +1 -1
- package/src/testing/mock-stream.test.ts +37 -16
- package/src/testing/mock-stream.ts +14 -9
- package/src/types/theme.ts +41 -1
- package/src/types.ts +57 -15
- package/src/ui.ask-user-question-plugin.test.ts +7 -7
- package/src/ui.composer-defer-one.test.ts +6 -34
- package/src/ui.composer-draft-persistence.test.ts +1 -1
- package/src/ui.composer-quote.test.ts +1 -1
- package/src/ui.message-history-actions.test.ts +1 -1
- package/src/ui.reasoning-display.test.ts +136 -2
- package/src/ui.streaming-coalescing.test.ts +10 -13
- package/src/ui.ts +101 -35
- package/src/ui.typing-indicator.test.ts +216 -0
- package/src/ui.voice-custom-provider.test.ts +211 -0
- package/src/utils/__snapshots__/tokens-parity.test.ts.snap +1740 -0
- package/src/utils/event-stream-buffer.test.ts +13 -13
- package/src/utils/event-stream-capture.test.ts +20 -20
- package/src/utils/formatting.ts +22 -0
- package/src/utils/theme.ts +16 -0
- package/src/utils/throughput-tracker.test.ts +100 -142
- package/src/utils/throughput-tracker.ts +18 -132
- package/src/utils/tokens.ts +59 -0
- package/src/utils/voice-support.ts +18 -1
- package/src/voice/voice-turn-tracker.ts +18 -0
- package/src/webmcp-bridge.test.ts +132 -23
- package/src/webmcp-bridge.ts +27 -3
- package/src/webmcp-runtime-entry.ts +71 -11
- package/dist/artifacts-ui-J6AKUGTS.js +0 -7
- package/dist/chunk-HBE7LFNT.js +0 -4
- package/dist/event-stream-view-73NWKWVQ.js +0 -1
- package/dist/webmcp-runtime-P3CHZRHF.js +0 -6
- package/src/utils/__fixtures__/unified-translator.oracle.ts +0 -717
package/dist/approval-ui.d.ts
CHANGED
|
@@ -619,7 +619,11 @@ interface ColorPalette {
|
|
|
619
619
|
warning: ColorShade;
|
|
620
620
|
error: ColorShade;
|
|
621
621
|
info: ColorShade;
|
|
622
|
-
|
|
622
|
+
/** Event-stream tool badge family. */
|
|
623
|
+
purple?: ColorShade;
|
|
624
|
+
/** Event-stream agent badge family. */
|
|
625
|
+
teal?: ColorShade;
|
|
626
|
+
[key: string]: ColorShade | undefined;
|
|
623
627
|
}
|
|
624
628
|
interface SpacingScale {
|
|
625
629
|
0: string;
|
|
@@ -1191,6 +1195,38 @@ interface ToolBubbleTokens {
|
|
|
1191
1195
|
interface ReasoningBubbleTokens {
|
|
1192
1196
|
shadow: string;
|
|
1193
1197
|
}
|
|
1198
|
+
/** One event-stream badge chip: fill + text pair. The chip border derives
|
|
1199
|
+
* from `foreground` at ~31% alpha. */
|
|
1200
|
+
interface EventStreamBadgePairTokens {
|
|
1201
|
+
background: TokenReference<'color'>;
|
|
1202
|
+
foreground: TokenReference<'color'>;
|
|
1203
|
+
}
|
|
1204
|
+
/**
|
|
1205
|
+
* Event-stream inspector badge chips (`features.eventStream`), one pair per
|
|
1206
|
+
* unified event family. Materialized into every theme and emitted as
|
|
1207
|
+
* `--persona-event-badge-<family>-{bg,fg}`, with scheme-appropriate defaults:
|
|
1208
|
+
* light themes pair a 100-tone fill with a 700-tone text, the built-in dark
|
|
1209
|
+
* layer flips to a 900-tone fill with a 300-tone text. `badge.default` colors
|
|
1210
|
+
* event types no family matches.
|
|
1211
|
+
*/
|
|
1212
|
+
interface EventStreamTokens {
|
|
1213
|
+
badge: {
|
|
1214
|
+
/** `flow_*` events. */
|
|
1215
|
+
flow: EventStreamBadgePairTokens;
|
|
1216
|
+
/** `step_*` events. */
|
|
1217
|
+
step: EventStreamBadgePairTokens;
|
|
1218
|
+
/** `reasoning_*` events. */
|
|
1219
|
+
reasoning: EventStreamBadgePairTokens;
|
|
1220
|
+
/** `tool_*` events. */
|
|
1221
|
+
tool: EventStreamBadgePairTokens;
|
|
1222
|
+
/** `agent_*` events. */
|
|
1223
|
+
agent: EventStreamBadgePairTokens;
|
|
1224
|
+
/** `error` / `execution_error` events. */
|
|
1225
|
+
error: EventStreamBadgePairTokens;
|
|
1226
|
+
/** Any event type no other family matches. */
|
|
1227
|
+
default: EventStreamBadgePairTokens;
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1194
1230
|
/** Scrollbar appearance shared by every scroller in the widget. */
|
|
1195
1231
|
interface ScrollbarTokens {
|
|
1196
1232
|
/** Thumb color. @default semantic.colors.border */
|
|
@@ -1539,6 +1575,8 @@ interface ComponentTokens {
|
|
|
1539
1575
|
attachment: AttachmentTokens;
|
|
1540
1576
|
toolBubble: ToolBubbleTokens;
|
|
1541
1577
|
reasoningBubble: ReasoningBubbleTokens;
|
|
1578
|
+
/** Event-stream inspector badge chips. */
|
|
1579
|
+
eventStream?: EventStreamTokens;
|
|
1542
1580
|
composer: ComposerChromeTokens;
|
|
1543
1581
|
/** Shared motion timing for composer chrome animation. */
|
|
1544
1582
|
motion?: MotionTokens;
|
|
@@ -1656,6 +1694,11 @@ type RuntypeExecutionStreamEvent = ({
|
|
|
1656
1694
|
iteration?: number;
|
|
1657
1695
|
role: "user" | "assistant" | "system";
|
|
1658
1696
|
seq: number;
|
|
1697
|
+
subagent?: {
|
|
1698
|
+
agentName?: string;
|
|
1699
|
+
parentToolCallId?: string;
|
|
1700
|
+
toolName: string;
|
|
1701
|
+
};
|
|
1659
1702
|
turnIndex?: number;
|
|
1660
1703
|
type: "turn_start";
|
|
1661
1704
|
}) | ({
|
|
@@ -1690,12 +1733,61 @@ type RuntypeExecutionStreamEvent = ({
|
|
|
1690
1733
|
role: "user" | "assistant" | "system";
|
|
1691
1734
|
seq: number;
|
|
1692
1735
|
stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
|
|
1736
|
+
subagent?: {
|
|
1737
|
+
agentName?: string;
|
|
1738
|
+
parentToolCallId?: string;
|
|
1739
|
+
toolName: string;
|
|
1740
|
+
};
|
|
1693
1741
|
tokens?: {
|
|
1694
1742
|
input: number;
|
|
1695
1743
|
output: number;
|
|
1696
1744
|
};
|
|
1697
1745
|
type: "turn_complete";
|
|
1698
1746
|
}) | {
|
|
1747
|
+
executionId: string;
|
|
1748
|
+
id: string;
|
|
1749
|
+
iteration?: number;
|
|
1750
|
+
model?: string;
|
|
1751
|
+
ordinal: number;
|
|
1752
|
+
provider?: string;
|
|
1753
|
+
seq: number;
|
|
1754
|
+
startedAt?: string;
|
|
1755
|
+
stepId?: string;
|
|
1756
|
+
subagent?: {
|
|
1757
|
+
agentName?: string;
|
|
1758
|
+
parentToolCallId?: string;
|
|
1759
|
+
toolName: string;
|
|
1760
|
+
};
|
|
1761
|
+
turnId?: string;
|
|
1762
|
+
type: "model_call_start";
|
|
1763
|
+
} | {
|
|
1764
|
+
completedAt?: string;
|
|
1765
|
+
cost?: number;
|
|
1766
|
+
durationMs?: number;
|
|
1767
|
+
executionId: string;
|
|
1768
|
+
finishReason?: string;
|
|
1769
|
+
id: string;
|
|
1770
|
+
iteration?: number;
|
|
1771
|
+
model?: string;
|
|
1772
|
+
ordinal: number;
|
|
1773
|
+
provider?: string;
|
|
1774
|
+
responseModel?: string;
|
|
1775
|
+
seq: number;
|
|
1776
|
+
subagent?: {
|
|
1777
|
+
agentName?: string;
|
|
1778
|
+
parentToolCallId?: string;
|
|
1779
|
+
toolName: string;
|
|
1780
|
+
};
|
|
1781
|
+
success?: boolean;
|
|
1782
|
+
tokens?: {
|
|
1783
|
+
cacheRead?: number;
|
|
1784
|
+
cacheWrite?: number;
|
|
1785
|
+
input: number;
|
|
1786
|
+
output: number;
|
|
1787
|
+
};
|
|
1788
|
+
turnId?: string;
|
|
1789
|
+
type: "model_call_complete";
|
|
1790
|
+
} | {
|
|
1699
1791
|
executionId: string;
|
|
1700
1792
|
id: string;
|
|
1701
1793
|
index?: number;
|
|
@@ -1704,6 +1796,11 @@ type RuntypeExecutionStreamEvent = ({
|
|
|
1704
1796
|
seq: number;
|
|
1705
1797
|
startedAt?: string;
|
|
1706
1798
|
stepType?: string;
|
|
1799
|
+
subagent?: {
|
|
1800
|
+
agentName?: string;
|
|
1801
|
+
parentToolCallId?: string;
|
|
1802
|
+
toolName: string;
|
|
1803
|
+
};
|
|
1707
1804
|
totalSteps?: number;
|
|
1708
1805
|
type: "step_start";
|
|
1709
1806
|
} | ({
|
|
@@ -1731,6 +1828,11 @@ type RuntypeExecutionStreamEvent = ({
|
|
|
1731
1828
|
seq: number;
|
|
1732
1829
|
stepType?: string;
|
|
1733
1830
|
stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
|
|
1831
|
+
subagent?: {
|
|
1832
|
+
agentName?: string;
|
|
1833
|
+
parentToolCallId?: string;
|
|
1834
|
+
toolName: string;
|
|
1835
|
+
};
|
|
1734
1836
|
success?: boolean;
|
|
1735
1837
|
tokensUsed?: number;
|
|
1736
1838
|
type: "step_complete";
|
|
@@ -1753,6 +1855,11 @@ type RuntypeExecutionStreamEvent = ({
|
|
|
1753
1855
|
role?: "user" | "assistant" | "system";
|
|
1754
1856
|
seq: number;
|
|
1755
1857
|
stepId?: string;
|
|
1858
|
+
subagent?: {
|
|
1859
|
+
agentName?: string;
|
|
1860
|
+
parentToolCallId?: string;
|
|
1861
|
+
toolName: string;
|
|
1862
|
+
};
|
|
1756
1863
|
turnId?: string;
|
|
1757
1864
|
type: "text_start";
|
|
1758
1865
|
}) | {
|
|
@@ -1760,11 +1867,21 @@ type RuntypeExecutionStreamEvent = ({
|
|
|
1760
1867
|
executionId: string;
|
|
1761
1868
|
id: string;
|
|
1762
1869
|
seq: number;
|
|
1870
|
+
subagent?: {
|
|
1871
|
+
agentName?: string;
|
|
1872
|
+
parentToolCallId?: string;
|
|
1873
|
+
toolName: string;
|
|
1874
|
+
};
|
|
1763
1875
|
type: "text_delta";
|
|
1764
1876
|
} | {
|
|
1765
1877
|
executionId: string;
|
|
1766
1878
|
id: string;
|
|
1767
1879
|
seq: number;
|
|
1880
|
+
subagent?: {
|
|
1881
|
+
agentName?: string;
|
|
1882
|
+
parentToolCallId?: string;
|
|
1883
|
+
toolName: string;
|
|
1884
|
+
};
|
|
1768
1885
|
text?: string;
|
|
1769
1886
|
type: "text_complete";
|
|
1770
1887
|
} | ({
|
|
@@ -1773,18 +1890,33 @@ type RuntypeExecutionStreamEvent = ({
|
|
|
1773
1890
|
parentToolCallId?: string;
|
|
1774
1891
|
scope?: "turn" | "loop";
|
|
1775
1892
|
seq: number;
|
|
1893
|
+
subagent?: {
|
|
1894
|
+
agentName?: string;
|
|
1895
|
+
parentToolCallId?: string;
|
|
1896
|
+
toolName: string;
|
|
1897
|
+
};
|
|
1776
1898
|
type: "reasoning_start";
|
|
1777
1899
|
}) | {
|
|
1778
1900
|
delta: string;
|
|
1779
1901
|
executionId: string;
|
|
1780
1902
|
id: string;
|
|
1781
1903
|
seq: number;
|
|
1904
|
+
subagent?: {
|
|
1905
|
+
agentName?: string;
|
|
1906
|
+
parentToolCallId?: string;
|
|
1907
|
+
toolName: string;
|
|
1908
|
+
};
|
|
1782
1909
|
type: "reasoning_delta";
|
|
1783
1910
|
} | ({
|
|
1784
1911
|
executionId: string;
|
|
1785
1912
|
id: string;
|
|
1786
1913
|
scope?: "turn" | "loop";
|
|
1787
1914
|
seq: number;
|
|
1915
|
+
subagent?: {
|
|
1916
|
+
agentName?: string;
|
|
1917
|
+
parentToolCallId?: string;
|
|
1918
|
+
toolName: string;
|
|
1919
|
+
};
|
|
1788
1920
|
text?: string;
|
|
1789
1921
|
type: "reasoning_complete";
|
|
1790
1922
|
}) | ({
|
|
@@ -1877,6 +2009,11 @@ type RuntypeExecutionStreamEvent = ({
|
|
|
1877
2009
|
seq: number;
|
|
1878
2010
|
startedAt?: string;
|
|
1879
2011
|
stepId?: string;
|
|
2012
|
+
subagent?: {
|
|
2013
|
+
agentName?: string;
|
|
2014
|
+
parentToolCallId?: string;
|
|
2015
|
+
toolName: string;
|
|
2016
|
+
};
|
|
1880
2017
|
toolCallId: string;
|
|
1881
2018
|
toolName: string;
|
|
1882
2019
|
toolType: string;
|
|
@@ -1885,6 +2022,11 @@ type RuntypeExecutionStreamEvent = ({
|
|
|
1885
2022
|
delta: string;
|
|
1886
2023
|
executionId: string;
|
|
1887
2024
|
seq: number;
|
|
2025
|
+
subagent?: {
|
|
2026
|
+
agentName?: string;
|
|
2027
|
+
parentToolCallId?: string;
|
|
2028
|
+
toolName: string;
|
|
2029
|
+
};
|
|
1888
2030
|
toolCallId: string;
|
|
1889
2031
|
type: "tool_input_delta";
|
|
1890
2032
|
} | {
|
|
@@ -1892,6 +2034,11 @@ type RuntypeExecutionStreamEvent = ({
|
|
|
1892
2034
|
hiddenParameterNames?: Array<string>;
|
|
1893
2035
|
parameters: Record<string, unknown>;
|
|
1894
2036
|
seq: number;
|
|
2037
|
+
subagent?: {
|
|
2038
|
+
agentName?: string;
|
|
2039
|
+
parentToolCallId?: string;
|
|
2040
|
+
toolName: string;
|
|
2041
|
+
};
|
|
1895
2042
|
toolCallId: string;
|
|
1896
2043
|
toolName?: string;
|
|
1897
2044
|
type: "tool_input_complete";
|
|
@@ -1909,6 +2056,11 @@ type RuntypeExecutionStreamEvent = ({
|
|
|
1909
2056
|
result?: unknown;
|
|
1910
2057
|
seq: number;
|
|
1911
2058
|
stepId?: string;
|
|
2059
|
+
subagent?: {
|
|
2060
|
+
agentName?: string;
|
|
2061
|
+
parentToolCallId?: string;
|
|
2062
|
+
toolName: string;
|
|
2063
|
+
};
|
|
1912
2064
|
success: boolean;
|
|
1913
2065
|
toolCallId: string;
|
|
1914
2066
|
toolCost?: number;
|
|
@@ -1988,6 +2140,19 @@ type RuntypeExecutionStreamEvent = ({
|
|
|
1988
2140
|
recoverable?: boolean;
|
|
1989
2141
|
seq: number;
|
|
1990
2142
|
type: "error";
|
|
2143
|
+
}) | ({
|
|
2144
|
+
epoch: number;
|
|
2145
|
+
executionId: string;
|
|
2146
|
+
kind: "compaction";
|
|
2147
|
+
outcome?: "ok" | "failed" | "gap" | "skipped";
|
|
2148
|
+
phase: "start" | "complete";
|
|
2149
|
+
reason: "threshold" | "overflow" | "manual" | "surface_policy" | "provider_mismatch";
|
|
2150
|
+
seq: number;
|
|
2151
|
+
strategy: "provider_native" | "summary";
|
|
2152
|
+
tier: number;
|
|
2153
|
+
tokensAfter?: number;
|
|
2154
|
+
tokensBefore?: number;
|
|
2155
|
+
type: "context_notice";
|
|
1991
2156
|
}) | {
|
|
1992
2157
|
executionId: string;
|
|
1993
2158
|
seq: number;
|
|
@@ -2919,6 +3084,14 @@ type ClientToolDefinition = {
|
|
|
2919
3084
|
readOnlyHint?: boolean;
|
|
2920
3085
|
untrustedContentHint?: boolean;
|
|
2921
3086
|
};
|
|
3087
|
+
/**
|
|
3088
|
+
* Hoisted copy of `annotations.untrustedContentHint`. This is the field the
|
|
3089
|
+
* server actually acts on (`InlineClientToolSchema`): it spotlights the
|
|
3090
|
+
* tool's output before the model reads it, so instructions embedded in
|
|
3091
|
+
* page-provided content (reviews, comments, emails) are not treated as
|
|
3092
|
+
* instructions. `annotations` itself is trace/dashboard metadata only.
|
|
3093
|
+
*/
|
|
3094
|
+
untrustedContentHint?: boolean;
|
|
2922
3095
|
};
|
|
2923
3096
|
/**
|
|
2924
3097
|
* Information passed to the confirm-bubble handler before a `webmcp:*` tool
|
|
@@ -3039,15 +3212,15 @@ type AgentMessageMetadata = {
|
|
|
3039
3212
|
*/
|
|
3040
3213
|
parentStepId?: string;
|
|
3041
3214
|
/**
|
|
3042
|
-
* Set to `true` on a tool-variant message produced from
|
|
3215
|
+
* Set to `true` on a tool-variant message produced from an `await`
|
|
3043
3216
|
* event (`awaitReason: "local_tool_required"`). Signals to UI code that
|
|
3044
3217
|
* the tool call is a LOCAL tool and the server is paused waiting for a
|
|
3045
3218
|
* `POST /v1/dispatch/resume` with the user's answer keyed by tool name.
|
|
3046
3219
|
*/
|
|
3047
3220
|
awaitingLocalTool?: boolean;
|
|
3048
3221
|
/**
|
|
3049
|
-
* The provider per-call id (`toolu_…`) carried on the `
|
|
3050
|
-
*
|
|
3222
|
+
* The provider per-call id (`toolu_…`) carried on the `await`
|
|
3223
|
+
* event for a LOCAL tool (core#3878). Present only when the
|
|
3051
3224
|
* server emits it. Two PARALLEL calls to the same tool in one turn share a
|
|
3052
3225
|
* `toolName` (and a collapsed `toolId`) but get DISTINCT `webMcpToolCallId`s,
|
|
3053
3226
|
* so this is the key the widget batches a single `/resume` on: preferred
|
|
@@ -4110,6 +4283,16 @@ type AgentWidgetToolCallDisplayFeature = {
|
|
|
4110
4283
|
* @default "stack"
|
|
4111
4284
|
*/
|
|
4112
4285
|
groupedMode?: "stack" | "summary";
|
|
4286
|
+
/**
|
|
4287
|
+
* What happens to a tool call row once it completes.
|
|
4288
|
+
*
|
|
4289
|
+
* - `"kept"` (default): the finished row stays in the transcript.
|
|
4290
|
+
* - `"removed"`: no row is rendered at all, so the transcript gap closes with
|
|
4291
|
+
* it. The tool call stays on the message and in `getMessages()`.
|
|
4292
|
+
*
|
|
4293
|
+
* @default "kept"
|
|
4294
|
+
*/
|
|
4295
|
+
completedVisibility?: AgentWidgetToolCallCompletedVisibility;
|
|
4113
4296
|
/**
|
|
4114
4297
|
* When false, tool call bubbles show only the collapsed summary with no
|
|
4115
4298
|
* expand/collapse toggle. Users see tool awareness without full details.
|
|
@@ -4127,6 +4310,8 @@ type AgentWidgetToolCallDisplayFeature = {
|
|
|
4127
4310
|
*/
|
|
4128
4311
|
loadingAnimation?: AgentWidgetToolCallLoadingAnimation;
|
|
4129
4312
|
};
|
|
4313
|
+
/** See `features.toolCallDisplay.completedVisibility`. */
|
|
4314
|
+
type AgentWidgetToolCallCompletedVisibility = "kept" | "removed";
|
|
4130
4315
|
type AgentWidgetReasoningDisplayFeature = {
|
|
4131
4316
|
/**
|
|
4132
4317
|
* When true, active collapsed reasoning rows can render a lightweight preview block.
|
|
@@ -4172,13 +4357,26 @@ type AgentWidgetReasoningDisplayFeature = {
|
|
|
4172
4357
|
* - `"kept"` (default): the finished row stays in the transcript.
|
|
4173
4358
|
* - `"removed"`: no row is rendered at all, so the transcript gap closes with
|
|
4174
4359
|
* it. The reasoning text stays on the message and in `getMessages()`.
|
|
4360
|
+
* - `"removed-when-short"`: behaves as `"removed"` when the completed trace
|
|
4361
|
+
* is short (see `shortThinkThreshold`), and as `"kept"` otherwise.
|
|
4175
4362
|
*
|
|
4176
4363
|
* @default "kept"
|
|
4177
4364
|
*/
|
|
4178
4365
|
completedVisibility?: AgentWidgetReasoningCompletedVisibility;
|
|
4366
|
+
/**
|
|
4367
|
+
* Thresholds used by `completedVisibility: "removed-when-short"` to decide
|
|
4368
|
+
* whether a completed trace counts as short. Duration is checked first when
|
|
4369
|
+
* the reasoning reports one; the character count is a fallback for traces
|
|
4370
|
+
* with no reported duration.
|
|
4371
|
+
* @default { durationMs: 15000, chars: 1200 }
|
|
4372
|
+
*/
|
|
4373
|
+
shortThinkThreshold?: {
|
|
4374
|
+
durationMs?: number;
|
|
4375
|
+
chars?: number;
|
|
4376
|
+
};
|
|
4179
4377
|
};
|
|
4180
4378
|
/** See `features.reasoningDisplay.completedVisibility`. */
|
|
4181
|
-
type AgentWidgetReasoningCompletedVisibility = "kept" | "removed";
|
|
4379
|
+
type AgentWidgetReasoningCompletedVisibility = "kept" | "removed" | "removed-when-short";
|
|
4182
4380
|
/**
|
|
4183
4381
|
* Reveal animation applied to assistant message text while it is streaming.
|
|
4184
4382
|
*
|
|
@@ -5172,7 +5370,7 @@ type EventStreamConfig = {
|
|
|
5172
5370
|
/**
|
|
5173
5371
|
* Custom badge color mappings by event type prefix or exact type.
|
|
5174
5372
|
* Keys are matched as exact match first, then prefix match (keys ending with "_").
|
|
5175
|
-
* @example { "
|
|
5373
|
+
* @example { "execution_": { bg: "#dcfce7", text: "#166534" }, "error": { bg: "#fecaca", text: "#991b1b" } }
|
|
5176
5374
|
*/
|
|
5177
5375
|
badgeColors?: Record<string, EventStreamBadgeColor>;
|
|
5178
5376
|
/**
|
|
@@ -6593,9 +6791,13 @@ interface VoiceProvider {
|
|
|
6593
6791
|
* `isFinal=false` is a live interim update (user partials, or assistant deltas
|
|
6594
6792
|
* on providers that stream them); `isFinal=true` finalizes that role's text.
|
|
6595
6793
|
* On the realtime `runtype` path, interim updates fire for the `user` only and
|
|
6596
|
-
* the `assistant` arrives as a single final.
|
|
6794
|
+
* the `assistant` arrives as a single final. Providers with overlapping turns
|
|
6795
|
+
* must include the same turnId on user and assistant finals; without IDs,
|
|
6796
|
+
* providers must discard cancelled output before emitting the next user final.
|
|
6597
6797
|
*/
|
|
6598
|
-
onTranscript?(callback: (role: 'user' | 'assistant', text: string, isFinal: boolean
|
|
6798
|
+
onTranscript?(callback: (role: 'user' | 'assistant', text: string, isFinal: boolean, metadata?: {
|
|
6799
|
+
turnId?: string;
|
|
6800
|
+
}) => void): void;
|
|
6599
6801
|
/** Register a callback for per-turn latency metrics (realtime path). */
|
|
6600
6802
|
onMetrics?(callback: (metrics: VoiceMetrics) => void): void;
|
|
6601
6803
|
/**
|
|
@@ -8908,16 +9110,16 @@ type AgentWidgetConfig = {
|
|
|
8908
9110
|
*
|
|
8909
9111
|
* @example
|
|
8910
9112
|
* ```typescript
|
|
8911
|
-
* // For Runtype
|
|
9113
|
+
* // For a custom backend (Runtype unified events are handled natively)
|
|
8912
9114
|
* config: {
|
|
8913
9115
|
* parseSSEEvent: (data) => {
|
|
8914
|
-
* if (
|
|
8915
|
-
* return { text: data.
|
|
9116
|
+
* if (data.type === 'token' && typeof data.value === 'string') {
|
|
9117
|
+
* return { text: data.value };
|
|
8916
9118
|
* }
|
|
8917
|
-
* if (data.type === '
|
|
9119
|
+
* if (data.type === 'done') {
|
|
8918
9120
|
* return { done: true };
|
|
8919
9121
|
* }
|
|
8920
|
-
* if (data.type === '
|
|
9122
|
+
* if (data.type === 'failure') {
|
|
8921
9123
|
* return { error: data.error };
|
|
8922
9124
|
* }
|
|
8923
9125
|
* return null; // Ignore other events
|
|
@@ -9108,7 +9310,7 @@ type AgentWidgetReasoning = {
|
|
|
9108
9310
|
/**
|
|
9109
9311
|
* Reasoning channel scope (wire spec). `"turn"` is ordinary per-turn
|
|
9110
9312
|
* thinking; `"loop"` is a cross-iteration agent reflection (the fold that
|
|
9111
|
-
* replaced the legacy `agent_reflection` event).
|
|
9313
|
+
* replaced the legacy `agent_reflection` event). Optional when the stream does not specify a scope.
|
|
9112
9314
|
*/
|
|
9113
9315
|
scope?: "turn" | "loop";
|
|
9114
9316
|
startedAt?: number;
|
|
@@ -9122,6 +9324,9 @@ type AgentWidgetToolCall = {
|
|
|
9122
9324
|
args?: unknown;
|
|
9123
9325
|
chunks?: string[];
|
|
9124
9326
|
result?: unknown;
|
|
9327
|
+
/** Whether the tool succeeded; failure does not necessarily end the execution. */
|
|
9328
|
+
success?: boolean;
|
|
9329
|
+
error?: string;
|
|
9125
9330
|
duration?: number;
|
|
9126
9331
|
startedAt?: number;
|
|
9127
9332
|
completedAt?: number;
|
|
@@ -9152,7 +9357,7 @@ type AgentWidgetApproval = {
|
|
|
9152
9357
|
type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool" | "approval";
|
|
9153
9358
|
/**
|
|
9154
9359
|
* Per-turn / per-step stop reason emitted by the runtime on
|
|
9155
|
-
* `
|
|
9360
|
+
* `turn_complete` and `step_complete` SSE events. The vocabulary is
|
|
9156
9361
|
* owned by the upstream Runtype API: do not extend without coordination.
|
|
9157
9362
|
*
|
|
9158
9363
|
* - `end_turn`: natural completion (no affordance needed)
|
|
@@ -9283,7 +9488,7 @@ type AgentWidgetMessage = {
|
|
|
9283
9488
|
*/
|
|
9284
9489
|
agentMetadata?: AgentMessageMetadata;
|
|
9285
9490
|
/**
|
|
9286
|
-
* Per-turn stop reason reported by the runtime on `
|
|
9491
|
+
* Per-turn stop reason reported by the runtime on `turn_complete`
|
|
9287
9492
|
* (agent-loop path) or the last `step_complete` for a prompt step
|
|
9288
9493
|
* (dispatch / flow path). Absent when the API did not report a value.
|
|
9289
9494
|
*
|
package/dist/approval-ui.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var me=Object.create;var Y=Object.defineProperty;var xe=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var ge=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty;var j=(t,a)=>()=>(a||t((a={exports:{}}).exports,a),a.exports);var Ce=(t,a,r,e)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of ce(a))!he.call(t,f)&&f!==r&&Y(t,f,{get:()=>a[f],enumerable:!(e=xe(a,f))||e.enumerable});return t};var Se=(t,a,r)=>(r=t!=null?me(ge(t)):{},Ce(a||!t||!t.__esModule?Y(r,"default",{value:t,enumerable:!0}):r,t));var
|
|
2
|
-
\r `.includes(t[e]);)e++};return C()},we=ee;P.parse=we});var d=(t,a)=>{let r=document.createElement(t);return a&&(r.className=a),r};var K=Se(te(),1);var z=t=>{if(t===null)return"null";if(t===void 0)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t,null,2)}catch{return String(t)}};var re=()=>{},ae=t=>{re=t.webMcpToolTitle},X=t=>re(t);var _=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"M4.929 4.929 19.07 19.071"}]];var N=[["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 D=(t,a=24,r="currentColor",e=2)=>{if(!Array.isArray(t))return null;let f=document.createElementNS("http://www.w3.org/2000/svg","svg");return f.setAttribute("width",String(a)),f.setAttribute("height",String(a)),f.setAttribute("viewBox","0 0 24 24"),f.setAttribute("fill","none"),f.setAttribute("stroke",r),f.setAttribute("stroke-width",String(e)),f.setAttribute("stroke-linecap","round"),f.setAttribute("stroke-linejoin","round"),f.setAttribute("aria-hidden","true"),t.forEach(p=>{if(!Array.isArray(p)||p.length<2)return;let C=p[0],n=p[1];if(!n)return;let y=document.createElementNS("http://www.w3.org/2000/svg",C);Object.entries(n).forEach(([A,k])=>{A!=="stroke"&&y.setAttribute(A,String(k))}),f.appendChild(y)}),f};var H="webmcp:";var U=new Map,I=t=>{let r=(t.startsWith(H)?t.slice(H.length):t).replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[_\-\s.]+/).filter(Boolean);if(r.length===0)return t;let e=r.join(" ").toLowerCase();return e.charAt(0).toUpperCase()+e.slice(1)},oe=t=>t?.approval!==!1?t?.approval:void 0,fe=(t,a)=>{let r=oe(a)?.detailsDisplay??"collapsed";return U.get(t)??r==="expanded"},le=(t,a,r)=>{let e=oe(r);t.setAttribute("aria-expanded",a?"true":"false");let f=t.querySelector("[data-approval-details-label]");f&&(f.textContent=a?e?.hideDetailsLabel??"Hide details":e?.showDetailsLabel??"Show details");let p=t.querySelector("[data-approval-details-chevron]");if(p){p.innerHTML="";let C=D(a?$:N,14,"currentColor",2);C&&p.appendChild(C)}},se=(t,a,r)=>{let e=a.querySelector('button[data-bubble-type="approval"]'),f=a.querySelector("[data-approval-details]");if(!e||!f)return;let p=fe(t,r);le(e,p,r),f.style.display=p?"":"none"};var de=(t,a)=>{let r=t.approval,e=a?.approval!==!1?a?.approval:void 0,f=r?.status==="pending",p=d("div",["persona-approval-bubble","persona-w-full","persona-rounded-2xl","persona-border","persona-shadow-sm","persona-overflow-hidden"].join(" "));if(p.id=`bubble-${t.id}`,p.setAttribute("data-message-id",t.id),p.style.backgroundColor=e?.backgroundColor??"var(--persona-approval-bg, #fefce8)",p.style.borderColor=e?.borderColor??"var(--persona-approval-border, #fef08a)",p.style.boxShadow=e?.shadow!==void 0?e.shadow.trim()===""?"none":e.shadow:"var(--persona-approval-shadow, 0 5px 15px rgba(15, 23, 42, 0.08))",!r)return p;let C=d("div","persona-flex persona-items-start persona-gap-3 persona-px-4 persona-py-3"),n=d("div","persona-flex-shrink-0 persona-mt-0.5");n.setAttribute("data-approval-icon","true");let y=r.status==="denied"?W:r.status==="timeout"?Z:q,A=r.status==="approved"?"var(--persona-feedback-success, #16a34a)":r.status==="denied"?"var(--persona-feedback-error, #dc2626)":r.status==="timeout"?"var(--persona-feedback-warning, #ca8a04)":e?.titleColor??"currentColor",k=D(y,20,A,2);k&&n.appendChild(k);let m=d("div","persona-flex-1 persona-min-w-0"),s=d("div","persona-flex persona-items-center persona-gap-2"),x=d("span","persona-text-sm persona-font-medium persona-text-persona-primary");if(e?.titleColor&&(x.style.color=e.titleColor),x.textContent=e?.title??"Approval Required",s.appendChild(x),!f){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",r.status),r.status==="approved"?(u.style.backgroundColor="var(--persona-palette-colors-success-100, #dcfce7)",u.style.color="var(--persona-palette-colors-success-700, #15803d)",u.textContent="Approved"):r.status==="denied"?(u.style.backgroundColor="var(--persona-palette-colors-error-100, #fee2e2)",u.style.color="var(--persona-palette-colors-error-700, #b91c1c)",u.textContent="Denied"):r.status==="timeout"&&(u.style.backgroundColor="var(--persona-palette-colors-warning-100, #fef3c7)",u.style.color="var(--persona-palette-colors-warning-700, #b45309)",u.textContent="Timeout"),s.appendChild(u)}m.appendChild(s);let S=r.toolType==="webmcp"||r.toolName.startsWith(H)?X(r.toolName):void 0,F=e?.formatDescription?.({toolName:r.toolName,toolType:r.toolType,description:r.description,parameters:r.parameters,...S?{displayTitle:S}:{},...r.reason?{reason:r.reason}:{}}),c=!r.toolName,L=F||(c?r.description:`The assistant wants to use \u201C${S??I(r.toolName)}\u201D.`),w=d("p","persona-text-sm persona-mt-0.5 persona-text-persona-muted");if(w.setAttribute("data-approval-summary","true"),e?.descriptionColor&&(w.style.color=e.descriptionColor),w.textContent=L,m.appendChild(w),r.reason){let u=d("p","persona-text-sm persona-mt-1 persona-text-persona-muted");u.setAttribute("data-approval-reason","true"),e?.reasonColor?u.style.color=e.reasonColor:e?.descriptionColor&&(u.style.color=e.descriptionColor);let l=d("span","persona-font-medium");l.textContent=`${e?.reasonLabel??"Agent's stated reason:"} `,u.appendChild(l),u.appendChild(document.createTextNode(r.reason)),m.appendChild(u)}let v=e?.detailsDisplay??"collapsed",B=!!r.description&&!c,R=B||!!r.parameters;if(v!=="hidden"&&R){let u=fe(t.id,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"),e?.descriptionColor&&(l.style.color=e.descriptionColor);let i=d("span");i.setAttribute("data-approval-details-label","true");let T=d("span","persona-inline-flex persona-items-center");T.setAttribute("data-approval-details-chevron","true"),l.append(i,T),le(l,u,a),m.appendChild(l);let h=d("div");if(h.setAttribute("data-approval-details","true"),h.style.display=u?"":"none",B){let g=d("p","persona-text-sm persona-mt-1 persona-text-persona-muted");e?.descriptionColor&&(g.style.color=e.descriptionColor),g.textContent=r.description,h.appendChild(g)}if(r.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");e?.parameterBackgroundColor&&(g.style.backgroundColor=e.parameterBackgroundColor),e?.parameterTextColor&&(g.style.color=e.parameterTextColor),g.style.fontSize="0.75rem",g.style.lineHeight="1rem",g.textContent=z(r.parameters),h.appendChild(g)}m.appendChild(h)}if(f){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=e?.approveButtonColor??"var(--persona-approval-approve-bg, #22c55e)",l.style.color=e?.approveButtonTextColor??"#ffffff",l.setAttribute("data-approval-action","approve");let i=D(q,14,e?.approveButtonTextColor??"#ffffff",2);i&&(i.style.marginRight="4px",l.appendChild(i));let T=document.createTextNode(e?.approveLabel??"Approve");l.appendChild(T);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=e?.denyButtonColor??"transparent",h.style.color=e?.denyButtonTextColor??"var(--persona-feedback-error, #dc2626)",h.style.border=`1px solid ${e?.denyButtonTextColor?e.denyButtonTextColor:"var(--persona-palette-colors-error-200, #fca5a5)"}`,h.setAttribute("data-approval-action","deny");let g=D(W,14,e?.denyButtonTextColor??"var(--persona-feedback-error, #dc2626)",2);g&&(g.style.marginRight="4px",h.appendChild(g));let E=document.createTextNode(e?.denyLabel??"Deny");h.appendChild(E),u.append(l,h),m.appendChild(u)}return C.append(n,m),p.appendChild(C),p};function Te(t){let a=t.getRootNode?.();return a instanceof ShadowRoot?a:(t.ownerDocument??document).body}function ue(t){let{anchor:a,content:r,placement:e="bottom-start",offset:f=6,matchAnchorWidth:p=!1,horizontalOffset:C,verticalOffset:n,zIndex:y=2147483e3,onOpen:A,onDismiss:k}=t,m=t.container??Te(a),s=!1,x=null,b=()=>{if(!s)return;let c=a.getBoundingClientRect();r.style.position="fixed",p&&(r.style.minWidth=`${c.width}px`),C&&(r.style.maxWidth=`${c.width}px`);let L=r.getBoundingClientRect(),w=n?.()??null,v=w!=null?c.top+w:c.top,B=e==="top-start"||e==="top-end"?v-f-L.height:c.bottom+f,u=e==="bottom-end"||e==="top-end"?c.right-L.width:c.left,l=C?.()??null;if(l!=null){let i=Math.max(c.left,c.right-L.width);u=Math.min(Math.max(c.left+l,c.left),i)}r.style.top=`${B}px`,r.style.left=`${u}px`},S=()=>{s&&(s=!1,x&&(x(),x=null),r.remove())},F=()=>{if(s)return;s=!0,y!=null&&(r.style.zIndex=String(y)),m.appendChild(r),b();let c=(a.ownerDocument??document).defaultView??window,L=a.ownerDocument??document,w=()=>{if(!a.isConnected){S(),k?.("anchor-removed");return}b()},v=R=>{let u=typeof R.composedPath=="function"?R.composedPath():[];u.includes(r)||u.includes(a)||(S(),k?.("outside"))},B=c.setTimeout(()=>{L.addEventListener("pointerdown",v,!0)},0);c.addEventListener("scroll",w,!0),c.addEventListener("resize",w),x=()=>{c.clearTimeout(B),L.removeEventListener("pointerdown",v,!0),c.removeEventListener("scroll",w,!0),c.removeEventListener("resize",w)},A?.()};return{get isOpen(){return s},open:F,close:S,toggle:()=>s?S():F(),reposition:b,destroy:S}}function pe(t){return(typeof t.composedPath=="function"?t.composedPath():[]).some(r=>r instanceof HTMLElement&&(r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable))}var Pe=()=>({keyHandlers:new Map,popovers:new Map,pendingOrder:[],latestPendingApprovalId:null}),ne=(t,a)=>{let r=t.keyHandlers.get(a);r&&(document.removeEventListener("keydown",r),t.keyHandlers.delete(a));let e=t.popovers.get(a);e&&(e.destroy(),t.popovers.delete(a))},O=(t,a)=>{ne(t,a);let r=t.pendingOrder.indexOf(a);r!==-1&&t.pendingOrder.splice(r,1),t.latestPendingApprovalId===a&&(t.latestPendingApprovalId=t.pendingOrder.length?t.pendingOrder[t.pendingOrder.length-1]:null)},Me=t=>t?.approval!==!1?t?.approval:void 0,ke=(t,a)=>{let r=a?.detailsDisplay??"collapsed";return U.get(t)??r==="expanded"},Q=t=>{let a=d("span","persona-approval-kbd");return a.textContent=t,a},Le=(t,a)=>{let r=d("span","persona-approval-title");a?.titleColor&&(r.style.color=a.titleColor);let f=t.toolType==="webmcp"||t.toolName.startsWith(H)?X(t.toolName):void 0,p=a?.formatDescription?.({toolName:t.toolName,toolType:t.toolType,description:t.description??"",parameters:t.parameters,...f?{displayTitle:f}:{},...t.reason?{reason:t.reason}:{}});if(p)return r.textContent=p,r;let C=f??I(t.toolName),n=t.toolType&&t.toolType!=="webmcp"?t.toolType:null;r.append("The assistant wants to use ");let y=document.createElement("strong");if(y.textContent=C,r.appendChild(y),n){r.append(" from ");let A=document.createElement("strong");A.textContent=n,r.appendChild(A)}return r},ve=t=>{let a=d("div","persona-approval-resolved"),r=D(_,15,"currentColor",2);r&&a.appendChild(r);let e=d("span","persona-approval-resolved-name");return e.textContent=t.toolName?I(t.toolName):"Tool",a.append(e,document.createTextNode(t.status==="timeout"?" timed out":" denied")),a},Be=(t,a,r,e,f,p,C)=>{let n=d("div","persona-approval-card persona-shadow-sm");n.id=`bubble-${a.id}`,n.setAttribute("data-message-id",a.id),n.setAttribute("data-bubble-type","approval"),e?.backgroundColor&&(n.style.background=e.backgroundColor),e?.borderColor&&(n.style.borderColor=e.borderColor),e?.shadow!==void 0&&(n.style.boxShadow=e.shadow.trim()===""?"none":e.shadow);let y=e?.detailsDisplay??"collapsed",A=!!r.description&&y!=="hidden",k=r.parameters!=null&&y!=="hidden",m=A||k,s=m&&ke(a.id,e),x=e?.showDetailsLabel??"Show details",b=e?.hideDetailsLabel??"Hide details",S=d("button","persona-approval-head");S.type="button",m?(S.setAttribute("data-action","toggle-params"),S.setAttribute("aria-expanded",s?"true":"false"),S.setAttribute("aria-label",s?b:x)):S.setAttribute("data-static","true");let F=d("span","persona-approval-logo"),c=D(q,16,"currentColor",2);c&&F.appendChild(c),S.appendChild(F);let L=Le(r,e);if(m){let l=d("span","persona-approval-toggle");l.setAttribute("aria-hidden","true");let i=D(N,14,"currentColor",2);i&&l.appendChild(i),L.append(" "),L.appendChild(l)}S.appendChild(L),n.appendChild(S);let w=d("div","persona-approval-body");if(m){let l=d("div","persona-approval-details");if(l.setAttribute("data-role","params"),l.hidden=!s,A){let i=d("p","persona-approval-desc");e?.descriptionColor&&(i.style.color=e.descriptionColor),i.textContent=r.description,l.appendChild(i)}if(k){let i=d("pre","persona-approval-params");e?.parameterBackgroundColor&&(i.style.background=e.parameterBackgroundColor),e?.parameterTextColor&&(i.style.color=e.parameterTextColor),i.textContent=z(r.parameters),l.appendChild(i)}w.appendChild(l)}if(r.reason){let l=d("p","persona-approval-reason");e?.reasonColor?l.style.color=e.reasonColor:e?.descriptionColor&&(l.style.color=e.descriptionColor);let i=d("span","persona-approval-reason-label");i.textContent=`${e?.reasonLabel??"Agent's stated reason:"} `,l.append(i,document.createTextNode(r.reason)),w.appendChild(l)}let v=d("div","persona-approval-actions"),B=null,R=l=>{e?.approveButtonColor&&(l.style.background=e.approveButtonColor),e?.approveButtonTextColor&&(l.style.color=e.approveButtonTextColor)},u=d("button","persona-approval-deny");if(u.type="button",u.setAttribute("data-action","deny"),e?.denyButtonColor&&(u.style.background=e.denyButtonColor),e?.denyButtonTextColor&&(u.style.color=e.denyButtonTextColor),u.append(e?.denyLabel??"Deny"),C){let l=d("div","persona-approval-split"),i=d("button","persona-approval-primary");i.type="button",i.setAttribute("data-action","always"),R(i),i.append(e?.approveLabel??"Always allow",Q("\u23CE"));let T=d("button","persona-approval-caret");T.type="button",T.setAttribute("data-action","toggle-menu"),T.setAttribute("aria-label","More options"),R(T);let h=D(N,15,"currentColor",2);h&&T.appendChild(h),l.append(i,T),v.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),B=ue({anchor:l,content:g,placement:"bottom-start",matchAnchorWidth:!0}),t.popovers.set(a.id,B),E.addEventListener("click",()=>{O(t,a.id),f()})}else{let l=d("button","persona-approval-primary persona-approval-primary--solo");l.type="button",l.setAttribute("data-action","allow"),R(l),l.append(e?.approveLabel??"Allow"),v.append(l,u)}return w.appendChild(v),n.appendChild(w),n.addEventListener("click",l=>{let i=l.target instanceof Element?l.target.closest("[data-action]"):null;if(!i)return;let T=i.getAttribute("data-action");if(T==="toggle-params"){let h=n.querySelector('[data-role="params"]');if(h){let g=h.hidden;h.hidden=!g,S.setAttribute("aria-expanded",g?"true":"false"),S.setAttribute("aria-label",g?b:x),U.set(a.id,g)}return}if(T==="toggle-menu"){B?.toggle();return}if(T==="always"){O(t,a.id),f({remember:!0});return}if(T==="allow"){O(t,a.id),f();return}if(T==="deny"){O(t,a.id),p();return}}),n},ie=()=>{let t=Pe();return{plugin:{id:"persona-built-in-approval",renderApproval:({message:e,approve:f,deny:p,config:C})=>{let n=e?.approval;if(!n)return null;let y=Me(C);if(n.status!=="pending"){if(O(t,e.id),n.status==="approved"){let m=document.createElement("div");return m.style.display="none",m}return ve(n)}ne(t,e.id);let A=y?.enableAlwaysAllow===!0,k=Be(t,e,n,y,f,p,A);if(A){t.pendingOrder.includes(e.id)||t.pendingOrder.push(e.id),t.latestPendingApprovalId=t.pendingOrder[t.pendingOrder.length-1];let m=s=>{pe(s)||e.id===t.latestPendingApprovalId&&(s.key!=="Escape"&&s.key!=="Enter"||(s.preventDefault(),s.stopImmediatePropagation(),O(t,e.id),s.key==="Escape"?p():s.metaKey||s.ctrlKey?f():f({remember:!0})))};t.keyHandlers.set(e.id,m),document.addEventListener("keydown",m)}return k}},teardown:()=>{for(let e of[...t.keyHandlers.keys(),...t.popovers.keys()])O(t,e);t.latestPendingApprovalId=null}}};export{U as approvalDetailsExpansionState,de as createApprovalBubble,ie as createBuiltInApprovalPlugin,I as humanizeToolName,ae as initApprovalUi,se as updateApprovalDetailsUI};
|
|
1
|
+
var me=Object.create;var Y=Object.defineProperty;var xe=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var ge=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty;var j=(t,a)=>()=>(a||t((a={exports:{}}).exports,a),a.exports);var Ce=(t,a,r,e)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of ce(a))!he.call(t,f)&&f!==r&&Y(t,f,{get:()=>a[f],enumerable:!(e=xe(a,f))||e.enumerable});return t};var Se=(t,a,r)=>(r=t!=null?me(ge(t)):{},Ce(a||!t||!t.__esModule?Y(r,"default",{value:t,enumerable:!0}):r,t));var _=j(o=>{"use strict";Object.defineProperty(o,"__esModule",{value:!0});o.Allow=o.ALL=o.COLLECTION=o.ATOM=o.SPECIAL=o.INF=o._INFINITY=o.INFINITY=o.NAN=o.BOOL=o.NULL=o.OBJ=o.ARR=o.NUM=o.STR=void 0;o.STR=1;o.NUM=2;o.ARR=4;o.OBJ=8;o.NULL=16;o.BOOL=32;o.NAN=64;o.INFINITY=128;o._INFINITY=256;o.INF=o.INFINITY|o._INFINITY;o.SPECIAL=o.NULL|o.BOOL|o.INF|o.NAN;o.ATOM=o.STR|o.NUM|o.SPECIAL;o.COLLECTION=o.ARR|o.OBJ;o.ALL=o.ATOM|o.COLLECTION;o.Allow={STR:o.STR,NUM:o.NUM,ARR:o.ARR,OBJ:o.OBJ,NULL:o.NULL,BOOL:o.BOOL,NAN:o.NAN,INFINITY:o.INFINITY,_INFINITY:o._INFINITY,INF:o.INF,SPECIAL:o.SPECIAL,ATOM:o.ATOM,COLLECTION:o.COLLECTION,ALL:o.ALL};o.default=o.Allow});var te=j(M=>{"use strict";var ye=M&&M.__createBinding||(Object.create?(function(t,a,r,e){e===void 0&&(e=r);var f=Object.getOwnPropertyDescriptor(a,r);(!f||("get"in f?!a.__esModule:f.writable||f.configurable))&&(f={enumerable:!0,get:function(){return a[r]}}),Object.defineProperty(t,e,f)}):(function(t,a,r,e){e===void 0&&(e=r),t[e]=a[r]})),Ae=M&&M.__exportStar||function(t,a){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(a,r)&&ye(a,t,r)};Object.defineProperty(M,"__esModule",{value:!0});M.Allow=M.MalformedJSON=M.PartialJSON=M.parseJSON=M.parse=void 0;var P=_();Object.defineProperty(M,"Allow",{enumerable:!0,get:function(){return P.Allow}});Ae(_(),M);var G=class extends Error{};M.PartialJSON=G;var V=class extends Error{};M.MalformedJSON=V;function ee(t,a=P.Allow.ALL){if(typeof t!="string")throw new TypeError(`expecting str, got ${typeof t}`);if(!t.trim())throw new Error(`${t} is empty`);return be(t.trim(),a)}M.parseJSON=ee;var be=(t,a)=>{let r=t.length,e=0,f=s=>{throw new G(`${s} at position ${e}`)},p=s=>{throw new V(`${s} at position ${e}`)},C=()=>(m(),e>=r&&f("Unexpected end of input"),t[e]==='"'?n():t[e]==="{"?y():t[e]==="["?A():t.substring(e,e+4)==="null"||P.Allow.NULL&a&&r-e<4&&"null".startsWith(t.substring(e))?(e+=4,null):t.substring(e,e+4)==="true"||P.Allow.BOOL&a&&r-e<4&&"true".startsWith(t.substring(e))?(e+=4,!0):t.substring(e,e+5)==="false"||P.Allow.BOOL&a&&r-e<5&&"false".startsWith(t.substring(e))?(e+=5,!1):t.substring(e,e+8)==="Infinity"||P.Allow.INFINITY&a&&r-e<8&&"Infinity".startsWith(t.substring(e))?(e+=8,1/0):t.substring(e,e+9)==="-Infinity"||P.Allow._INFINITY&a&&1<r-e&&r-e<9&&"-Infinity".startsWith(t.substring(e))?(e+=9,-1/0):t.substring(e,e+3)==="NaN"||P.Allow.NAN&a&&r-e<3&&"NaN".startsWith(t.substring(e))?(e+=3,NaN):k()),n=()=>{let s=e,x=!1;for(e++;e<r&&(t[e]!=='"'||x&&t[e-1]==="\\");)x=t[e]==="\\"?!x:!1,e++;if(t.charAt(e)=='"')try{return JSON.parse(t.substring(s,++e-Number(x)))}catch(b){p(String(b))}else if(P.Allow.STR&a)try{return JSON.parse(t.substring(s,e-Number(x))+'"')}catch{return JSON.parse(t.substring(s,t.lastIndexOf("\\"))+'"')}f("Unterminated string literal")},y=()=>{e++,m();let s={};try{for(;t[e]!=="}";){if(m(),e>=r&&P.Allow.OBJ&a)return s;let x=n();m(),e++;try{let b=C();s[x]=b}catch(b){if(P.Allow.OBJ&a)return s;throw b}m(),t[e]===","&&e++}}catch{if(P.Allow.OBJ&a)return s;f("Expected '}' at end of object")}return e++,s},A=()=>{e++;let s=[];try{for(;t[e]!=="]";)s.push(C()),m(),t[e]===","&&e++}catch{if(P.Allow.ARR&a)return s;f("Expected ']' at end of array")}return e++,s},k=()=>{if(e===0){t==="-"&&p("Not sure what '-' is");try{return JSON.parse(t)}catch(x){if(P.Allow.NUM&a)try{return JSON.parse(t.substring(0,t.lastIndexOf("e")))}catch{}p(String(x))}}let s=e;for(t[e]==="-"&&e++;t[e]&&",]}".indexOf(t[e])===-1;)e++;e==r&&!(P.Allow.NUM&a)&&f("Unterminated number literal");try{return JSON.parse(t.substring(s,e))}catch{t.substring(s,e)==="-"&&f("Not sure what '-' is");try{return JSON.parse(t.substring(s,t.lastIndexOf("e")))}catch(b){p(String(b))}}},m=()=>{for(;e<r&&`
|
|
2
|
+
\r `.includes(t[e]);)e++};return C()},we=ee;M.parse=we});var d=(t,a)=>{let r=document.createElement(t);return a&&(r.className=a),r};var J=Se(te(),1);var z=t=>{if(t===null)return"null";if(t===void 0)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t,null,2)}catch{return String(t)}};var re=()=>{},ae=t=>{re=t.webMcpToolTitle},X=t=>re(t);var K=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"M4.929 4.929 19.07 19.071"}]];var N=[["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 H=[["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 D=(t,a=24,r="currentColor",e=2)=>{if(!Array.isArray(t))return null;let f=document.createElementNS("http://www.w3.org/2000/svg","svg");return f.setAttribute("width",String(a)),f.setAttribute("height",String(a)),f.setAttribute("viewBox","0 0 24 24"),f.setAttribute("fill","none"),f.setAttribute("stroke",r),f.setAttribute("stroke-width",String(e)),f.setAttribute("stroke-linecap","round"),f.setAttribute("stroke-linejoin","round"),f.setAttribute("aria-hidden","true"),t.forEach(p=>{if(!Array.isArray(p)||p.length<2)return;let C=p[0],n=p[1];if(!n)return;let y=document.createElementNS("http://www.w3.org/2000/svg",C);Object.entries(n).forEach(([A,k])=>{A!=="stroke"&&y.setAttribute(A,String(k))}),f.appendChild(y)}),f};var q="webmcp:";var U=new Map,I=t=>{let r=(t.startsWith(q)?t.slice(q.length):t).replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[_\-\s.]+/).filter(Boolean);if(r.length===0)return t;let e=r.join(" ").toLowerCase();return e.charAt(0).toUpperCase()+e.slice(1)},oe=t=>t?.approval!==!1?t?.approval:void 0,fe=(t,a)=>{let r=oe(a)?.detailsDisplay??"collapsed";return U.get(t)??r==="expanded"},le=(t,a,r)=>{let e=oe(r);t.setAttribute("aria-expanded",a?"true":"false");let f=t.querySelector("[data-approval-details-label]");f&&(f.textContent=a?e?.hideDetailsLabel??"Hide details":e?.showDetailsLabel??"Show details");let p=t.querySelector("[data-approval-details-chevron]");if(p){p.innerHTML="";let C=D(a?$:N,14,"currentColor",2);C&&p.appendChild(C)}},se=(t,a,r)=>{let e=a.querySelector('button[data-bubble-type="approval"]'),f=a.querySelector("[data-approval-details]");if(!e||!f)return;let p=fe(t,r);le(e,p,r),f.style.display=p?"":"none"};var de=(t,a)=>{let r=t.approval,e=a?.approval!==!1?a?.approval:void 0,f=r?.status==="pending",p=d("div",["persona-approval-bubble","persona-w-full","persona-rounded-2xl","persona-border","persona-shadow-sm","persona-overflow-hidden"].join(" "));if(p.id=`bubble-${t.id}`,p.setAttribute("data-message-id",t.id),p.style.backgroundColor=e?.backgroundColor??"var(--persona-approval-bg, #fefce8)",p.style.borderColor=e?.borderColor??"var(--persona-approval-border, #fef08a)",p.style.boxShadow=e?.shadow!==void 0?e.shadow.trim()===""?"none":e.shadow:"var(--persona-approval-shadow, 0 5px 15px rgba(15, 23, 42, 0.08))",!r)return p;let C=d("div","persona-flex persona-items-start persona-gap-3 persona-px-4 persona-py-3"),n=d("div","persona-flex-shrink-0 persona-mt-0.5");n.setAttribute("data-approval-icon","true");let y=r.status==="denied"?W:r.status==="timeout"?Z:H,A=r.status==="approved"?"var(--persona-feedback-success, #16a34a)":r.status==="denied"?"var(--persona-feedback-error, #dc2626)":r.status==="timeout"?"var(--persona-feedback-warning, #ca8a04)":e?.titleColor??"currentColor",k=D(y,20,A,2);k&&n.appendChild(k);let m=d("div","persona-flex-1 persona-min-w-0"),s=d("div","persona-flex persona-items-center persona-gap-2"),x=d("span","persona-text-sm persona-font-medium persona-text-persona-primary");if(e?.titleColor&&(x.style.color=e.titleColor),x.textContent=e?.title??"Approval Required",s.appendChild(x),!f){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",r.status),r.status==="approved"?(u.style.backgroundColor="var(--persona-palette-colors-success-100, #dcfce7)",u.style.color="var(--persona-palette-colors-success-700, #15803d)",u.textContent="Approved"):r.status==="denied"?(u.style.backgroundColor="var(--persona-palette-colors-error-100, #fee2e2)",u.style.color="var(--persona-palette-colors-error-700, #b91c1c)",u.textContent="Denied"):r.status==="timeout"&&(u.style.backgroundColor="var(--persona-palette-colors-warning-100, #fef3c7)",u.style.color="var(--persona-palette-colors-warning-700, #b45309)",u.textContent="Timeout"),s.appendChild(u)}m.appendChild(s);let S=r.toolType==="webmcp"||r.toolName.startsWith(q)?X(r.toolName):void 0,F=e?.formatDescription?.({toolName:r.toolName,toolType:r.toolType,description:r.description,parameters:r.parameters,...S?{displayTitle:S}:{},...r.reason?{reason:r.reason}:{}}),c=!r.toolName,L=F||(c?r.description:`The assistant wants to use \u201C${S??I(r.toolName)}\u201D.`),w=d("p","persona-text-sm persona-mt-0.5 persona-text-persona-muted");if(w.setAttribute("data-approval-summary","true"),e?.descriptionColor&&(w.style.color=e.descriptionColor),w.textContent=L,m.appendChild(w),r.reason){let u=d("p","persona-text-sm persona-mt-1 persona-text-persona-muted");u.setAttribute("data-approval-reason","true"),e?.reasonColor?u.style.color=e.reasonColor:e?.descriptionColor&&(u.style.color=e.descriptionColor);let l=d("span","persona-font-medium");l.textContent=`${e?.reasonLabel??"Agent's stated reason:"} `,u.appendChild(l),u.appendChild(document.createTextNode(r.reason)),m.appendChild(u)}let v=e?.detailsDisplay??"collapsed",B=!!r.description&&!c,R=B||!!r.parameters;if(v!=="hidden"&&R){let u=fe(t.id,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"),e?.descriptionColor&&(l.style.color=e.descriptionColor);let i=d("span");i.setAttribute("data-approval-details-label","true");let T=d("span","persona-inline-flex persona-items-center");T.setAttribute("data-approval-details-chevron","true"),l.append(i,T),le(l,u,a),m.appendChild(l);let h=d("div");if(h.setAttribute("data-approval-details","true"),h.style.display=u?"":"none",B){let g=d("p","persona-text-sm persona-mt-1 persona-text-persona-muted");e?.descriptionColor&&(g.style.color=e.descriptionColor),g.textContent=r.description,h.appendChild(g)}if(r.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");e?.parameterBackgroundColor&&(g.style.backgroundColor=e.parameterBackgroundColor),e?.parameterTextColor&&(g.style.color=e.parameterTextColor),g.style.fontSize="0.75rem",g.style.lineHeight="1rem",g.textContent=z(r.parameters),h.appendChild(g)}m.appendChild(h)}if(f){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=e?.approveButtonColor??"var(--persona-approval-approve-bg, #22c55e)",l.style.color=e?.approveButtonTextColor??"#ffffff",l.setAttribute("data-approval-action","approve");let i=D(H,14,e?.approveButtonTextColor??"#ffffff",2);i&&(i.style.marginRight="4px",l.appendChild(i));let T=document.createTextNode(e?.approveLabel??"Approve");l.appendChild(T);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=e?.denyButtonColor??"transparent",h.style.color=e?.denyButtonTextColor??"var(--persona-feedback-error, #dc2626)",h.style.border=`1px solid ${e?.denyButtonTextColor?e.denyButtonTextColor:"var(--persona-palette-colors-error-200, #fca5a5)"}`,h.setAttribute("data-approval-action","deny");let g=D(W,14,e?.denyButtonTextColor??"var(--persona-feedback-error, #dc2626)",2);g&&(g.style.marginRight="4px",h.appendChild(g));let E=document.createTextNode(e?.denyLabel??"Deny");h.appendChild(E),u.append(l,h),m.appendChild(u)}return C.append(n,m),p.appendChild(C),p};function Te(t){let a=t.getRootNode?.();return a instanceof ShadowRoot?a:(t.ownerDocument??document).body}function ue(t){let{anchor:a,content:r,placement:e="bottom-start",offset:f=6,matchAnchorWidth:p=!1,horizontalOffset:C,verticalOffset:n,zIndex:y=2147483e3,onOpen:A,onDismiss:k}=t,m=t.container??Te(a),s=!1,x=null,b=()=>{if(!s)return;let c=a.getBoundingClientRect();r.style.position="fixed",p&&(r.style.minWidth=`${c.width}px`),C&&(r.style.maxWidth=`${c.width}px`);let L=r.getBoundingClientRect(),w=n?.()??null,v=w!=null?c.top+w:c.top,B=e==="top-start"||e==="top-end"?v-f-L.height:c.bottom+f,u=e==="bottom-end"||e==="top-end"?c.right-L.width:c.left,l=C?.()??null;if(l!=null){let i=Math.max(c.left,c.right-L.width);u=Math.min(Math.max(c.left+l,c.left),i)}r.style.top=`${B}px`,r.style.left=`${u}px`},S=()=>{s&&(s=!1,x&&(x(),x=null),r.remove())},F=()=>{if(s)return;s=!0,y!=null&&(r.style.zIndex=String(y)),m.appendChild(r),b();let c=(a.ownerDocument??document).defaultView??window,L=a.ownerDocument??document,w=()=>{if(!a.isConnected){S(),k?.("anchor-removed");return}b()},v=R=>{let u=typeof R.composedPath=="function"?R.composedPath():[];u.includes(r)||u.includes(a)||(S(),k?.("outside"))},B=c.setTimeout(()=>{L.addEventListener("pointerdown",v,!0)},0);c.addEventListener("scroll",w,!0),c.addEventListener("resize",w),x=()=>{c.clearTimeout(B),L.removeEventListener("pointerdown",v,!0),c.removeEventListener("scroll",w,!0),c.removeEventListener("resize",w)},A?.()};return{get isOpen(){return s},open:F,close:S,toggle:()=>s?S():F(),reposition:b,destroy:S}}function pe(t){return(typeof t.composedPath=="function"?t.composedPath():[]).some(r=>r instanceof HTMLElement&&(r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable))}var Me=()=>({keyHandlers:new Map,popovers:new Map,pendingOrder:[],latestPendingApprovalId:null}),ne=(t,a)=>{let r=t.keyHandlers.get(a);r&&(document.removeEventListener("keydown",r),t.keyHandlers.delete(a));let e=t.popovers.get(a);e&&(e.destroy(),t.popovers.delete(a))},O=(t,a)=>{ne(t,a);let r=t.pendingOrder.indexOf(a);r!==-1&&t.pendingOrder.splice(r,1),t.latestPendingApprovalId===a&&(t.latestPendingApprovalId=t.pendingOrder.length?t.pendingOrder[t.pendingOrder.length-1]:null)},Pe=t=>t?.approval!==!1?t?.approval:void 0,ke=(t,a)=>{let r=a?.detailsDisplay??"collapsed";return U.get(t)??r==="expanded"},Q=t=>{let a=d("span","persona-approval-kbd");return a.textContent=t,a},Le=(t,a)=>{let r=d("span","persona-approval-title");a?.titleColor&&(r.style.color=a.titleColor);let f=t.toolType==="webmcp"||t.toolName.startsWith(q)?X(t.toolName):void 0,p=a?.formatDescription?.({toolName:t.toolName,toolType:t.toolType,description:t.description??"",parameters:t.parameters,...f?{displayTitle:f}:{},...t.reason?{reason:t.reason}:{}});if(p)return r.textContent=p,r;let C=f??I(t.toolName),n=t.toolType&&t.toolType!=="webmcp"?t.toolType:null;r.append("The assistant wants to use ");let y=document.createElement("strong");if(y.textContent=C,r.appendChild(y),n){r.append(" from ");let A=document.createElement("strong");A.textContent=n,r.appendChild(A)}return r},ve=t=>{let a=d("div","persona-approval-resolved"),r=D(K,15,"currentColor",2);r&&a.appendChild(r);let e=d("span","persona-approval-resolved-name");return e.textContent=t.toolName?I(t.toolName):"Tool",a.append(e,document.createTextNode(t.status==="timeout"?" timed out":" denied")),a},Be=(t,a,r,e,f,p,C)=>{let n=d("div","persona-approval-card persona-shadow-sm");n.id=`bubble-${a.id}`,n.setAttribute("data-message-id",a.id),n.setAttribute("data-bubble-type","approval"),e?.backgroundColor&&(n.style.background=e.backgroundColor),e?.borderColor&&(n.style.borderColor=e.borderColor),e?.shadow!==void 0&&(n.style.boxShadow=e.shadow.trim()===""?"none":e.shadow);let y=e?.detailsDisplay??"collapsed",A=!!r.description&&y!=="hidden",k=r.parameters!=null&&y!=="hidden",m=A||k,s=m&&ke(a.id,e),x=e?.showDetailsLabel??"Show details",b=e?.hideDetailsLabel??"Hide details",S=d("button","persona-approval-head");S.type="button",m?(S.setAttribute("data-action","toggle-params"),S.setAttribute("aria-expanded",s?"true":"false"),S.setAttribute("aria-label",s?b:x)):S.setAttribute("data-static","true");let F=d("span","persona-approval-logo"),c=D(H,16,"currentColor",2);c&&F.appendChild(c),S.appendChild(F);let L=Le(r,e);if(m){let l=d("span","persona-approval-toggle");l.setAttribute("aria-hidden","true");let i=D(N,14,"currentColor",2);i&&l.appendChild(i),L.append(" "),L.appendChild(l)}S.appendChild(L),n.appendChild(S);let w=d("div","persona-approval-body");if(m){let l=d("div","persona-approval-details");if(l.setAttribute("data-role","params"),l.hidden=!s,A){let i=d("p","persona-approval-desc");e?.descriptionColor&&(i.style.color=e.descriptionColor),i.textContent=r.description,l.appendChild(i)}if(k){let i=d("pre","persona-approval-params");e?.parameterBackgroundColor&&(i.style.background=e.parameterBackgroundColor),e?.parameterTextColor&&(i.style.color=e.parameterTextColor),i.textContent=z(r.parameters),l.appendChild(i)}w.appendChild(l)}if(r.reason){let l=d("p","persona-approval-reason");e?.reasonColor?l.style.color=e.reasonColor:e?.descriptionColor&&(l.style.color=e.descriptionColor);let i=d("span","persona-approval-reason-label");i.textContent=`${e?.reasonLabel??"Agent's stated reason:"} `,l.append(i,document.createTextNode(r.reason)),w.appendChild(l)}let v=d("div","persona-approval-actions"),B=null,R=l=>{e?.approveButtonColor&&(l.style.background=e.approveButtonColor),e?.approveButtonTextColor&&(l.style.color=e.approveButtonTextColor)},u=d("button","persona-approval-deny");if(u.type="button",u.setAttribute("data-action","deny"),e?.denyButtonColor&&(u.style.background=e.denyButtonColor),e?.denyButtonTextColor&&(u.style.color=e.denyButtonTextColor),u.append(e?.denyLabel??"Deny"),C){let l=d("div","persona-approval-split"),i=d("button","persona-approval-primary");i.type="button",i.setAttribute("data-action","always"),R(i),i.append(e?.approveLabel??"Always allow",Q("\u23CE"));let T=d("button","persona-approval-caret");T.type="button",T.setAttribute("data-action","toggle-menu"),T.setAttribute("aria-label","More options"),R(T);let h=D(N,15,"currentColor",2);h&&T.appendChild(h),l.append(i,T),v.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),B=ue({anchor:l,content:g,placement:"bottom-start",matchAnchorWidth:!0}),t.popovers.set(a.id,B),E.addEventListener("click",()=>{O(t,a.id),f()})}else{let l=d("button","persona-approval-primary persona-approval-primary--solo");l.type="button",l.setAttribute("data-action","allow"),R(l),l.append(e?.approveLabel??"Allow"),v.append(l,u)}return w.appendChild(v),n.appendChild(w),n.addEventListener("click",l=>{let i=l.target instanceof Element?l.target.closest("[data-action]"):null;if(!i)return;let T=i.getAttribute("data-action");if(T==="toggle-params"){let h=n.querySelector('[data-role="params"]');if(h){let g=h.hidden;h.hidden=!g,S.setAttribute("aria-expanded",g?"true":"false"),S.setAttribute("aria-label",g?b:x),U.set(a.id,g)}return}if(T==="toggle-menu"){B?.toggle();return}if(T==="always"){O(t,a.id),f({remember:!0});return}if(T==="allow"){O(t,a.id),f();return}if(T==="deny"){O(t,a.id),p();return}}),n},ie=()=>{let t=Me();return{plugin:{id:"persona-built-in-approval",renderApproval:({message:e,approve:f,deny:p,config:C})=>{let n=e?.approval;if(!n)return null;let y=Pe(C);if(n.status!=="pending"){if(O(t,e.id),n.status==="approved"){let m=document.createElement("div");return m.style.display="none",m}return ve(n)}ne(t,e.id);let A=y?.enableAlwaysAllow===!0,k=Be(t,e,n,y,f,p,A);if(A){t.pendingOrder.includes(e.id)||t.pendingOrder.push(e.id),t.latestPendingApprovalId=t.pendingOrder[t.pendingOrder.length-1];let m=s=>{pe(s)||e.id===t.latestPendingApprovalId&&(s.key!=="Escape"&&s.key!=="Enter"||(s.preventDefault(),s.stopImmediatePropagation(),O(t,e.id),s.key==="Escape"?p():s.metaKey||s.ctrlKey?f():f({remember:!0})))};t.keyHandlers.set(e.id,m),document.addEventListener("keydown",m)}return k}},teardown:()=>{for(let e of[...t.keyHandlers.keys(),...t.popovers.keys()])O(t,e);t.latestPendingApprovalId=null}}};export{U as approvalDetailsExpansionState,de as createApprovalBubble,ie as createBuiltInApprovalPlugin,I as humanizeToolName,ae as initApprovalUi,se as updateApprovalDetailsUI};
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
lucide/dist/esm/icons/ban.mjs:
|