@mastra/playground-ui 72.0.0-alpha.0 → 72.0.0-alpha.2
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/{combobox-Db8NtklU.js → combobox-BCB51kuy.js} +58 -12
- package/dist/combobox-BCB51kuy.js.map +1 -0
- package/dist/{combobox-Cg-KVjdt.cjs → combobox-CtEvUaJc.cjs} +58 -12
- package/dist/combobox-CtEvUaJc.cjs.map +1 -0
- package/dist/components/Combobox.cjs.js +1 -1
- package/dist/components/Combobox.es.js +1 -1
- package/dist/components/DataList.cjs.js +1 -1
- package/dist/components/DataList.es.js +1 -1
- package/dist/components/PropertyFilter.cjs.js +1 -1
- package/dist/components/PropertyFilter.es.js +1 -1
- package/dist/domains/agents/agent-combobox.cjs.js +1 -1
- package/dist/domains/agents/agent-combobox.es.js +1 -1
- package/dist/domains/chat/tools/connect-prompt-tool.cjs.js +112 -76
- package/dist/domains/chat/tools/connect-prompt-tool.cjs.js.map +1 -1
- package/dist/domains/chat/tools/connect-prompt-tool.es.js +113 -77
- package/dist/domains/chat/tools/connect-prompt-tool.es.js.map +1 -1
- package/dist/domains/connect/use-user-connect.cjs.js +1 -0
- package/dist/domains/connect/use-user-connect.cjs.js.map +1 -1
- package/dist/domains/connect/use-user-connect.es.js +1 -0
- package/dist/domains/connect/use-user-connect.es.js.map +1 -1
- package/dist/domains/datasets/components/dataset-combobox.cjs.js +1 -1
- package/dist/domains/datasets/components/dataset-combobox.es.js +1 -1
- package/dist/domains/datasets/components/dataset-detail/dataset-tags-editor.cjs.js +1 -1
- package/dist/domains/datasets/components/dataset-detail/dataset-tags-editor.es.js +1 -1
- package/dist/domains/datasets/components/dataset-versions.cjs.js +1 -1
- package/dist/domains/datasets/components/dataset-versions.es.js +1 -1
- package/dist/domains/datasets/components/experiment-trigger/scorer-selector.cjs.js +1 -1
- package/dist/domains/datasets/components/experiment-trigger/scorer-selector.es.js +1 -1
- package/dist/domains/experiments/components/experiment-results-tag-picker.cjs.js +1 -1
- package/dist/domains/experiments/components/experiment-results-tag-picker.es.js +1 -1
- package/dist/domains/prompt-blocks/prompt-block-version-combobox.cjs.js +1 -1
- package/dist/domains/prompt-blocks/prompt-block-version-combobox.es.js +1 -1
- package/dist/domains/scores/components/span-scoring.cjs.js +1 -1
- package/dist/domains/scores/components/span-scoring.es.js +1 -1
- package/dist/domains/traces/components/trace-columns-menu.cjs.js +1 -1
- package/dist/domains/traces/components/trace-columns-menu.es.js +1 -1
- package/dist/domains/workflows/components/workflow-combobox.cjs.js +1 -1
- package/dist/domains/workflows/components/workflow-combobox.es.js +1 -1
- package/dist/layout/tabbed-container.cjs.js +1 -1
- package/dist/layout/tabbed-container.es.js +1 -1
- package/dist/{tabbed-container-DiHt3VX3.js → tabbed-container-CRPiA3RI.js} +2 -2
- package/dist/{tabbed-container-DiHt3VX3.js.map → tabbed-container-CRPiA3RI.js.map} +1 -1
- package/dist/{tabbed-container-DbgPRklc.cjs → tabbed-container-DLntsyso.cjs} +2 -2
- package/dist/{tabbed-container-DbgPRklc.cjs.map → tabbed-container-DLntsyso.cjs.map} +1 -1
- package/package.json +7 -7
- package/dist/combobox-Cg-KVjdt.cjs.map +0 -1
- package/dist/combobox-Db8NtklU.js.map +0 -1
|
@@ -9,6 +9,7 @@ const require_data_list = require("../../../data-list-BXe_ULaL.cjs");
|
|
|
9
9
|
const require_Notice = require("../../../Notice-CS_aUxIi.cjs");
|
|
10
10
|
const require_Txt = require("../../../Txt-_00wWxTd.cjs");
|
|
11
11
|
const require_icons_central_IconCheckmark2Medium = require("../../../icons/central/IconCheckmark2Medium.cjs.js");
|
|
12
|
+
const require_icons_central_IconCrossMedium = require("../../../icons/central/IconCrossMedium.cjs.js");
|
|
12
13
|
const require_icons_Icon = require("../../../icons/Icon.cjs.js");
|
|
13
14
|
const require_domains_chat_tools_connect_prompt_tool_id = require("./connect-prompt-tool-id.cjs.js");
|
|
14
15
|
let react = require("react");
|
|
@@ -31,16 +32,25 @@ function connectPromptFor({ toolName, toolCallId, output, metadata }) {
|
|
|
31
32
|
}
|
|
32
33
|
/** The resume tool's schema accepts; longer failure reasons are cut to fit. */
|
|
33
34
|
var MAX_RESUME_ERROR_LENGTH = 500;
|
|
35
|
+
/** What the agent is told when the user cancels the prompt. */
|
|
36
|
+
var CONNECT_PROMPT_CANCELLED_ERROR = "The user cancelled connecting.";
|
|
37
|
+
/** Marks the user cancelling the prompt as the outcome the call was resumed with. */
|
|
38
|
+
var CANCELLED = Symbol("cancelled");
|
|
34
39
|
/**
|
|
35
|
-
* What to resume the paused call with: the
|
|
36
|
-
* connect session couldn't even be created (e.g. the
|
|
40
|
+
* What to resume the paused call with: the user cancelling, the settled flow,
|
|
41
|
+
* or a failure when the connect session couldn't even be created (e.g. the
|
|
42
|
+
* connection limit).
|
|
37
43
|
*/
|
|
38
|
-
function connectPromptResumeFor(payload, settled, createError) {
|
|
44
|
+
function connectPromptResumeFor(payload, cancelled, settled, createError) {
|
|
39
45
|
const failed = (provider, error) => ({
|
|
40
46
|
provider,
|
|
41
47
|
status: "failed",
|
|
42
48
|
error: error.slice(0, MAX_RESUME_ERROR_LENGTH)
|
|
43
49
|
});
|
|
50
|
+
if (cancelled) {
|
|
51
|
+
const provider = payload.requestedProvider ?? payload.providers[0]?.id;
|
|
52
|
+
return provider ? failed(provider, CONNECT_PROMPT_CANCELLED_ERROR) : void 0;
|
|
53
|
+
}
|
|
44
54
|
if (createError) {
|
|
45
55
|
const provider = payload.requestedProvider ?? payload.providers[0]?.id;
|
|
46
56
|
return provider ? failed(provider, createError.message) : void 0;
|
|
@@ -81,23 +91,26 @@ var ConnectPromptTool = ({ toolName, toolCallId, output, metadata, readOnly = fa
|
|
|
81
91
|
});
|
|
82
92
|
};
|
|
83
93
|
var ConnectPromptCard = ({ toolCallId, payload, paused, readOnly }) => {
|
|
84
|
-
const { pending, connect, connectedProviders, isCreating, createError, settled } = require_domains_connect_use_user_connect.usePendingConnect();
|
|
94
|
+
const { pending, connect, cancel, connectedProviders, isCreating, createError, settled } = require_domains_connect_use_user_connect.usePendingConnect();
|
|
85
95
|
const { approveToolcall, isRunning, toolCallApprovals } = require_domains_chat_context_tool_call_context.useToolCall();
|
|
96
|
+
const [cancelled, setCancelled] = (0, react.useState)(false);
|
|
86
97
|
const resumedRef = (0, react.useRef)(null);
|
|
87
98
|
const alreadyResumed = toolCallApprovals[toolCallId] !== void 0;
|
|
99
|
+
const canCancel = !readOnly && paused && !alreadyResumed && !cancelled;
|
|
88
100
|
const errorMessage = createError?.message ?? (settled?.status === "failed" ? settled.message ?? "The connection was not completed. Try connecting again." : null);
|
|
89
101
|
(0, react.useEffect)(() => {
|
|
90
102
|
if (readOnly || !paused || alreadyResumed || isRunning) return;
|
|
91
|
-
const outcome = createError ?? settled;
|
|
103
|
+
const outcome = cancelled ? CANCELLED : createError ?? settled;
|
|
92
104
|
if (!outcome || resumedRef.current === outcome) return;
|
|
93
105
|
resumedRef.current = outcome;
|
|
94
|
-
const resume = connectPromptResumeFor(payload, settled, createError);
|
|
106
|
+
const resume = connectPromptResumeFor(payload, cancelled, settled, createError);
|
|
95
107
|
if (resume) approveToolcall(toolCallId, resume);
|
|
96
108
|
}, [
|
|
97
109
|
readOnly,
|
|
98
110
|
paused,
|
|
99
111
|
alreadyResumed,
|
|
100
112
|
isRunning,
|
|
113
|
+
cancelled,
|
|
101
114
|
settled,
|
|
102
115
|
createError,
|
|
103
116
|
payload,
|
|
@@ -107,79 +120,102 @@ var ConnectPromptCard = ({ toolCallId, payload, paused, readOnly }) => {
|
|
|
107
120
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
108
121
|
"aria-label": "Connect an account",
|
|
109
122
|
className: "my-2 space-y-3",
|
|
110
|
-
children: [
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
123
|
+
children: [
|
|
124
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_data_list.DataList, {
|
|
125
|
+
columns: "minmax(0, 1fr)",
|
|
126
|
+
fit: "container",
|
|
127
|
+
scrollable: false,
|
|
128
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_data_list.DataList.Subheader, {
|
|
129
|
+
className: "flex items-center justify-between gap-3",
|
|
130
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Txt.Txt, {
|
|
131
|
+
as: "h4",
|
|
132
|
+
variant: "subheading",
|
|
133
|
+
tone: "ink",
|
|
134
|
+
children: "Connect an account"
|
|
135
|
+
}), canCancel ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Button.Button, {
|
|
136
|
+
variant: "ghost",
|
|
137
|
+
size: "icon-sm",
|
|
138
|
+
"aria-label": "Cancel",
|
|
139
|
+
tooltip: "Cancel",
|
|
140
|
+
onClick: () => {
|
|
141
|
+
cancel();
|
|
142
|
+
setCancelled(true);
|
|
143
|
+
},
|
|
144
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_icons_central_IconCrossMedium.IconCrossMedium, { "aria-hidden": true })
|
|
145
|
+
}) : null]
|
|
146
|
+
}), payload.providers.map((provider) => {
|
|
147
|
+
const isConnected = provider.connected || connectedProviders.has(provider.id);
|
|
148
|
+
const isPending = pending?.provider === provider.id;
|
|
149
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_data_list.DataList.RowStatic, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_data_list.DataList.Cell, {
|
|
150
|
+
className: "col-span-full py-2",
|
|
151
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
152
|
+
className: "flex flex-wrap items-center justify-between gap-3",
|
|
153
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
154
|
+
className: "flex min-w-0 flex-1 items-center gap-2",
|
|
155
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_domains_connect_provider_logo.ProviderLogo, { logoUrl: provider.logoUrl }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Txt.Txt, {
|
|
139
156
|
as: "span",
|
|
140
157
|
variant: "body-sm",
|
|
141
|
-
tone: "
|
|
142
|
-
|
|
143
|
-
children:
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
tone: "ink",
|
|
159
|
+
className: "truncate",
|
|
160
|
+
children: provider.displayName ?? provider.id
|
|
161
|
+
})]
|
|
162
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
163
|
+
className: "flex flex-wrap items-center gap-3",
|
|
164
|
+
children: [
|
|
165
|
+
isPending ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Txt.Txt, {
|
|
166
|
+
as: "span",
|
|
167
|
+
variant: "body-sm",
|
|
168
|
+
tone: "muted",
|
|
169
|
+
role: "status",
|
|
170
|
+
children: "Waiting for authorization…"
|
|
171
|
+
}) : null,
|
|
172
|
+
isPending && pending?.fallbackUrl ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
173
|
+
href: pending.fallbackUrl,
|
|
174
|
+
target: "_blank",
|
|
175
|
+
rel: "noreferrer",
|
|
176
|
+
className: "text-ui-md underline underline-offset-2",
|
|
177
|
+
children: "Open the connect window"
|
|
178
|
+
}) : null,
|
|
179
|
+
isConnected ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Txt.Txt, {
|
|
180
|
+
as: "span",
|
|
181
|
+
variant: "body-sm",
|
|
182
|
+
tone: "muted",
|
|
183
|
+
className: "flex min-w-24 items-center justify-center gap-1",
|
|
184
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_icons_Icon.Icon, {
|
|
185
|
+
size: "sm",
|
|
186
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_icons_central_IconCheckmark2Medium.IconCheckmark2Medium, { "aria-hidden": true })
|
|
187
|
+
}), "Connected"]
|
|
188
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Button.Button, {
|
|
189
|
+
variant: "primary",
|
|
158
190
|
size: "sm",
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Notice.Notice
|
|
181
|
-
|
|
182
|
-
|
|
191
|
+
className: "min-w-24",
|
|
192
|
+
disabled: readOnly || isCreating,
|
|
193
|
+
loading: isPending,
|
|
194
|
+
onClick: () => connect(provider),
|
|
195
|
+
children: "Connect"
|
|
196
|
+
})
|
|
197
|
+
]
|
|
198
|
+
})]
|
|
199
|
+
})
|
|
200
|
+
}) }, provider.id);
|
|
201
|
+
})]
|
|
202
|
+
}),
|
|
203
|
+
cancelled && isRunning && !alreadyResumed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Txt.Txt, {
|
|
204
|
+
as: "p",
|
|
205
|
+
variant: "body-sm",
|
|
206
|
+
tone: "muted",
|
|
207
|
+
role: "status",
|
|
208
|
+
children: "Cancelled. The agent continues once its current response finishes."
|
|
209
|
+
}) : null,
|
|
210
|
+
errorMessage ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
211
|
+
role: "alert",
|
|
212
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Notice.Notice, {
|
|
213
|
+
variant: "destructive",
|
|
214
|
+
title: "Couldn't connect",
|
|
215
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Notice.Notice.Message, { children: errorMessage })
|
|
216
|
+
})
|
|
217
|
+
}) : null
|
|
218
|
+
]
|
|
183
219
|
});
|
|
184
220
|
};
|
|
185
221
|
exports.CONNECT_PROMPT_TOOL_NAME = require_domains_chat_tools_connect_prompt_tool_id.CONNECT_PROMPT_TOOL_NAME;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect-prompt-tool.cjs.js","names":["isConnectPromptPayload","toolInteraction","usePendingConnect","useToolCall","useRef","DataList","Txt","ProviderLogo","Icon","IconCheckmark2Medium","Button","Notice"],"sources":["../../../../src/domains/chat/tools/connect-prompt-tool.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { MessageMetadata } from '../messages/message-metadata';\nimport { toolInteraction } from './tool-card-kind';\nimport { useToolCall } from '@/domains/chat/context/tool-call-context';\nimport type { ConnectPromptPayload, ConnectPromptResume, SettledConnect } from '@/domains/connect';\nimport { isConnectPromptPayload, ProviderLogo, usePendingConnect } from '@/domains/connect';\nimport { Button } from '@/ds/components/Button';\nimport { DataList } from '@/ds/components/DataList';\nimport { Notice } from '@/ds/components/Notice';\nimport { Txt } from '@/ds/components/Txt';\nimport { IconCheckmark2Medium } from '@/ds/icons/central/IconCheckmark2Medium';\nimport { Icon } from '@/ds/icons/Icon';\n\nexport { CONNECT_PROMPT_TOOL_NAME } from './connect-prompt-tool-id';\n\nexport interface ConnectPromptToolProps {\n toolName: string;\n toolCallId: string;\n output: unknown;\n metadata?: MessageMetadata;\n /** Historical rendering: show the card but suppress the connect action. */\n readOnly?: boolean;\n}\n\n/**\n * The prompt this card renders: the finished call's result, or the payload\n * the run paused with while it waits for the user to connect.\n */\nfunction connectPromptFor({\n toolName,\n toolCallId,\n output,\n metadata,\n}: Pick<ConnectPromptToolProps, 'toolName' | 'toolCallId' | 'output' | 'metadata'>):\n | { payload: ConnectPromptPayload; paused: boolean }\n | undefined {\n if (isConnectPromptPayload(output)) return { payload: output, paused: false };\n const suspendPayload = toolInteraction(metadata, toolName, toolCallId).suspended?.suspendPayload;\n if (isConnectPromptPayload(suspendPayload)) return { payload: suspendPayload, paused: true };\n return undefined;\n}\n\n/** The resume tool's schema accepts; longer failure reasons are cut to fit. */\nconst MAX_RESUME_ERROR_LENGTH = 500;\n\n/**\n * What to resume the paused call with: the settled flow, or a failure when the\n * connect session couldn't even be created (e.g. the connection limit).\n */\nfunction connectPromptResumeFor(\n payload: ConnectPromptPayload,\n settled: SettledConnect | null,\n createError: Error | null,\n): ConnectPromptResume | undefined {\n const failed = (provider: string, error: string): ConnectPromptResume => ({\n provider,\n status: 'failed',\n error: error.slice(0, MAX_RESUME_ERROR_LENGTH),\n });\n if (createError) {\n const provider = payload.requestedProvider ?? payload.providers[0]?.id;\n return provider ? failed(provider, createError.message) : undefined;\n }\n if (!settled) return undefined;\n if (settled.status === 'active') return { provider: settled.provider, status: 'active' };\n return failed(settled.provider, settled.message ?? 'The connection was not completed.');\n}\n\n/**\n * Chat card for the built-in `request_connection` tool: the agent surfaces it\n * when provider tools are unavailable because the caller has no connection.\n * Each provider row offers a Connect action that creates a connect session on\n * the mounted `/connect` routes, drives the OAuth flow in a popup through the\n * server's launch gate (which verifies this browser owns the pending session\n * before redirecting to the vendor), and polls until the connection settles.\n *\n * The tool pauses the agent run while the card is up. Once the connection\n * settles, the card resumes the paused call with the outcome — connected, or\n * the reason it failed — so the agent continues from the tool's result rather\n * than a chat message.\n */\nexport const ConnectPromptTool = ({\n toolName,\n toolCallId,\n output,\n metadata,\n readOnly = false,\n}: ConnectPromptToolProps) => {\n const prompt = connectPromptFor({ toolName, toolCallId, output, metadata });\n if (!prompt) return null;\n return (\n <ConnectPromptCard toolCallId={toolCallId} payload={prompt.payload} paused={prompt.paused} readOnly={readOnly} />\n );\n};\n\ninterface ConnectPromptCardProps {\n toolCallId: string;\n payload: ConnectPromptPayload;\n /** The run is waiting on this call, so an activation resumes it. */\n paused: boolean;\n readOnly: boolean;\n}\n\nconst ConnectPromptCard = ({ toolCallId, payload, paused, readOnly }: ConnectPromptCardProps) => {\n const { pending, connect, connectedProviders, isCreating, createError, settled } = usePendingConnect();\n const { approveToolcall, isRunning, toolCallApprovals } = useToolCall();\n // The outcome (settled flow or session-creation error) this call was resumed with.\n const resumedRef = useRef<SettledConnect | Error | null>(null);\n const alreadyResumed = toolCallApprovals[toolCallId] !== undefined;\n\n const errorMessage =\n createError?.message ??\n (settled?.status === 'failed'\n ? (settled.message ?? 'The connection was not completed. Try connecting again.')\n : null);\n\n // Resume once per outcome, success or failure, so the agent sees what\n // happened in the tool result. A run that is still streaming can't be\n // resumed yet, so an outcome that lands mid-run waits for it to stop.\n useEffect(() => {\n if (readOnly || !paused || alreadyResumed || isRunning) return;\n const outcome = createError ?? settled;\n if (!outcome || resumedRef.current === outcome) return;\n resumedRef.current = outcome;\n const resume = connectPromptResumeFor(payload, settled, createError);\n if (resume) approveToolcall(toolCallId, resume);\n }, [readOnly, paused, alreadyResumed, isRunning, settled, createError, payload, approveToolcall, toolCallId]);\n\n return (\n <section aria-label=\"Connect an account\" className=\"my-2 space-y-3\">\n <DataList columns=\"minmax(0, 1fr)\" fit=\"container\" scrollable={false}>\n <DataList.Subheader>\n <Txt as=\"h4\" variant=\"subheading\" tone=\"ink\">\n Connect an account\n </Txt>\n </DataList.Subheader>\n {payload.providers.map(provider => {\n const isConnected = provider.connected || connectedProviders.has(provider.id);\n const isPending = pending?.provider === provider.id;\n return (\n <DataList.RowStatic key={provider.id}>\n <DataList.Cell className=\"col-span-full py-2\">\n <div className=\"flex flex-wrap items-center justify-between gap-3\">\n <div className=\"flex min-w-0 flex-1 items-center gap-2\">\n <ProviderLogo logoUrl={provider.logoUrl} />\n <Txt as=\"span\" variant=\"body-sm\" tone=\"ink\" className=\"truncate\">\n {provider.displayName ?? provider.id}\n </Txt>\n </div>\n <div className=\"flex flex-wrap items-center gap-3\">\n {isPending ? (\n <Txt as=\"span\" variant=\"body-sm\" tone=\"muted\" role=\"status\">\n Waiting for authorization…\n </Txt>\n ) : null}\n {isPending && pending?.fallbackUrl ? (\n <a\n href={pending.fallbackUrl}\n target=\"_blank\"\n rel=\"noreferrer\"\n className=\"text-ui-md underline underline-offset-2\"\n >\n Open the connect window\n </a>\n ) : null}\n {isConnected ? (\n <Txt\n as=\"span\"\n variant=\"body-sm\"\n tone=\"muted\"\n className=\"flex min-w-24 items-center justify-center gap-1\"\n >\n <Icon size=\"sm\">\n <IconCheckmark2Medium aria-hidden />\n </Icon>\n Connected\n </Txt>\n ) : (\n <Button\n variant=\"primary\"\n size=\"sm\"\n className=\"min-w-24\"\n disabled={readOnly || isCreating}\n loading={isPending}\n onClick={() => connect(provider)}\n >\n Connect\n </Button>\n )}\n </div>\n </div>\n </DataList.Cell>\n </DataList.RowStatic>\n );\n })}\n </DataList>\n {errorMessage ? (\n <div role=\"alert\">\n <Notice variant=\"destructive\" title=\"Couldn't connect\">\n <Notice.Message>{errorMessage}</Notice.Message>\n </Notice>\n </div>\n ) : null}\n </section>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4BA,SAAS,iBAAiB,EACxB,UACA,YACA,QACA,YAGY;CACZ,IAAIA,8BAAAA,uBAAuB,MAAM,GAAG,OAAO;EAAE,SAAS;EAAQ,QAAQ;CAAM;CAC5E,MAAM,iBAAiBC,0CAAAA,gBAAgB,UAAU,UAAU,UAAU,CAAC,CAAC,WAAW;CAClF,IAAID,8BAAAA,uBAAuB,cAAc,GAAG,OAAO;EAAE,SAAS;EA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ompt-tool.cjs.js","names":["isConnectPromptPayload","toolInteraction","usePendingConnect","useToolCall","useState","useRef","DataList","Txt","Button","IconCrossMedium","ProviderLogo","Icon","IconCheckmark2Medium","Notice"],"sources":["../../../../src/domains/chat/tools/connect-prompt-tool.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport type { MessageMetadata } from '../messages/message-metadata';\nimport { toolInteraction } from './tool-card-kind';\nimport { useToolCall } from '@/domains/chat/context/tool-call-context';\nimport type { ConnectPromptPayload, ConnectPromptResume, SettledConnect } from '@/domains/connect';\nimport { isConnectPromptPayload, ProviderLogo, usePendingConnect } from '@/domains/connect';\nimport { Button } from '@/ds/components/Button';\nimport { DataList } from '@/ds/components/DataList';\nimport { Notice } from '@/ds/components/Notice';\nimport { Txt } from '@/ds/components/Txt';\nimport { IconCheckmark2Medium } from '@/ds/icons/central/IconCheckmark2Medium';\nimport { IconCrossMedium } from '@/ds/icons/central/IconCrossMedium';\nimport { Icon } from '@/ds/icons/Icon';\n\nexport { CONNECT_PROMPT_TOOL_NAME } from './connect-prompt-tool-id';\n\nexport interface ConnectPromptToolProps {\n toolName: string;\n toolCallId: string;\n output: unknown;\n metadata?: MessageMetadata;\n /** Historical rendering: show the card but suppress the connect action. */\n readOnly?: boolean;\n}\n\n/**\n * The prompt this card renders: the finished call's result, or the payload\n * the run paused with while it waits for the user to connect.\n */\nfunction connectPromptFor({\n toolName,\n toolCallId,\n output,\n metadata,\n}: Pick<ConnectPromptToolProps, 'toolName' | 'toolCallId' | 'output' | 'metadata'>):\n | { payload: ConnectPromptPayload; paused: boolean }\n | undefined {\n if (isConnectPromptPayload(output)) return { payload: output, paused: false };\n const suspendPayload = toolInteraction(metadata, toolName, toolCallId).suspended?.suspendPayload;\n if (isConnectPromptPayload(suspendPayload)) return { payload: suspendPayload, paused: true };\n return undefined;\n}\n\n/** The resume tool's schema accepts; longer failure reasons are cut to fit. */\nconst MAX_RESUME_ERROR_LENGTH = 500;\n\n/** What the agent is told when the user cancels the prompt. */\nconst CONNECT_PROMPT_CANCELLED_ERROR = 'The user cancelled connecting.';\n\n/** Marks the user cancelling the prompt as the outcome the call was resumed with. */\nconst CANCELLED = Symbol('cancelled');\n\n/**\n * What to resume the paused call with: the user cancelling, the settled flow,\n * or a failure when the connect session couldn't even be created (e.g. the\n * connection limit).\n */\nfunction connectPromptResumeFor(\n payload: ConnectPromptPayload,\n cancelled: boolean,\n settled: SettledConnect | null,\n createError: Error | null,\n): ConnectPromptResume | undefined {\n const failed = (provider: string, error: string): ConnectPromptResume => ({\n provider,\n status: 'failed',\n error: error.slice(0, MAX_RESUME_ERROR_LENGTH),\n });\n if (cancelled) {\n const provider = payload.requestedProvider ?? payload.providers[0]?.id;\n return provider ? failed(provider, CONNECT_PROMPT_CANCELLED_ERROR) : undefined;\n }\n if (createError) {\n const provider = payload.requestedProvider ?? payload.providers[0]?.id;\n return provider ? failed(provider, createError.message) : undefined;\n }\n if (!settled) return undefined;\n if (settled.status === 'active') return { provider: settled.provider, status: 'active' };\n return failed(settled.provider, settled.message ?? 'The connection was not completed.');\n}\n\n/**\n * Chat card for the built-in `request_connection` tool: the agent surfaces it\n * when provider tools are unavailable because the caller has no connection.\n * Each provider row offers a Connect action that creates a connect session on\n * the mounted `/connect` routes, drives the OAuth flow in a popup through the\n * server's launch gate (which verifies this browser owns the pending session\n * before redirecting to the vendor), and polls until the connection settles.\n *\n * The tool pauses the agent run while the card is up. Once the connection\n * settles, the card resumes the paused call with the outcome — connected, or\n * the reason it failed — so the agent continues from the tool's result rather\n * than a chat message.\n */\nexport const ConnectPromptTool = ({\n toolName,\n toolCallId,\n output,\n metadata,\n readOnly = false,\n}: ConnectPromptToolProps) => {\n const prompt = connectPromptFor({ toolName, toolCallId, output, metadata });\n if (!prompt) return null;\n return (\n <ConnectPromptCard toolCallId={toolCallId} payload={prompt.payload} paused={prompt.paused} readOnly={readOnly} />\n );\n};\n\ninterface ConnectPromptCardProps {\n toolCallId: string;\n payload: ConnectPromptPayload;\n /** The run is waiting on this call, so an activation resumes it. */\n paused: boolean;\n readOnly: boolean;\n}\n\nconst ConnectPromptCard = ({ toolCallId, payload, paused, readOnly }: ConnectPromptCardProps) => {\n const { pending, connect, cancel, connectedProviders, isCreating, createError, settled } = usePendingConnect();\n const { approveToolcall, isRunning, toolCallApprovals } = useToolCall();\n const [cancelled, setCancelled] = useState(false);\n // The outcome (cancel, settled flow or session-creation error) this call was resumed with.\n const resumedRef = useRef<typeof CANCELLED | SettledConnect | Error | null>(null);\n const alreadyResumed = toolCallApprovals[toolCallId] !== undefined;\n // A paused call holds the run until it is resumed, so the user can always back out of it.\n const canCancel = !readOnly && paused && !alreadyResumed && !cancelled;\n\n const errorMessage =\n createError?.message ??\n (settled?.status === 'failed'\n ? (settled.message ?? 'The connection was not completed. Try connecting again.')\n : null);\n\n // Resume once per outcome, success or failure, so the agent sees what\n // happened in the tool result. A run that is still streaming can't be\n // resumed yet, so an outcome that lands mid-run waits for it to stop.\n useEffect(() => {\n if (readOnly || !paused || alreadyResumed || isRunning) return;\n const outcome = cancelled ? CANCELLED : (createError ?? settled);\n if (!outcome || resumedRef.current === outcome) return;\n resumedRef.current = outcome;\n const resume = connectPromptResumeFor(payload, cancelled, settled, createError);\n if (resume) approveToolcall(toolCallId, resume);\n }, [\n readOnly,\n paused,\n alreadyResumed,\n isRunning,\n cancelled,\n settled,\n createError,\n payload,\n approveToolcall,\n toolCallId,\n ]);\n\n return (\n <section aria-label=\"Connect an account\" className=\"my-2 space-y-3\">\n <DataList columns=\"minmax(0, 1fr)\" fit=\"container\" scrollable={false}>\n <DataList.Subheader className=\"flex items-center justify-between gap-3\">\n <Txt as=\"h4\" variant=\"subheading\" tone=\"ink\">\n Connect an account\n </Txt>\n {canCancel ? (\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n aria-label=\"Cancel\"\n tooltip=\"Cancel\"\n onClick={() => {\n cancel();\n setCancelled(true);\n }}\n >\n <IconCrossMedium aria-hidden />\n </Button>\n ) : null}\n </DataList.Subheader>\n {payload.providers.map(provider => {\n const isConnected = provider.connected || connectedProviders.has(provider.id);\n const isPending = pending?.provider === provider.id;\n return (\n <DataList.RowStatic key={provider.id}>\n <DataList.Cell className=\"col-span-full py-2\">\n <div className=\"flex flex-wrap items-center justify-between gap-3\">\n <div className=\"flex min-w-0 flex-1 items-center gap-2\">\n <ProviderLogo logoUrl={provider.logoUrl} />\n <Txt as=\"span\" variant=\"body-sm\" tone=\"ink\" className=\"truncate\">\n {provider.displayName ?? provider.id}\n </Txt>\n </div>\n <div className=\"flex flex-wrap items-center gap-3\">\n {isPending ? (\n <Txt as=\"span\" variant=\"body-sm\" tone=\"muted\" role=\"status\">\n Waiting for authorization…\n </Txt>\n ) : null}\n {isPending && pending?.fallbackUrl ? (\n <a\n href={pending.fallbackUrl}\n target=\"_blank\"\n rel=\"noreferrer\"\n className=\"text-ui-md underline underline-offset-2\"\n >\n Open the connect window\n </a>\n ) : null}\n {isConnected ? (\n <Txt\n as=\"span\"\n variant=\"body-sm\"\n tone=\"muted\"\n className=\"flex min-w-24 items-center justify-center gap-1\"\n >\n <Icon size=\"sm\">\n <IconCheckmark2Medium aria-hidden />\n </Icon>\n Connected\n </Txt>\n ) : (\n <Button\n variant=\"primary\"\n size=\"sm\"\n className=\"min-w-24\"\n disabled={readOnly || isCreating}\n loading={isPending}\n onClick={() => connect(provider)}\n >\n Connect\n </Button>\n )}\n </div>\n </div>\n </DataList.Cell>\n </DataList.RowStatic>\n );\n })}\n </DataList>\n {cancelled && isRunning && !alreadyResumed ? (\n <Txt as=\"p\" variant=\"body-sm\" tone=\"muted\" role=\"status\">\n Cancelled. The agent continues once its current response finishes.\n </Txt>\n ) : null}\n {errorMessage ? (\n <div role=\"alert\">\n <Notice variant=\"destructive\" title=\"Couldn't connect\">\n <Notice.Message>{errorMessage}</Notice.Message>\n </Notice>\n </div>\n ) : null}\n </section>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA6BA,SAAS,iBAA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cACC,iBAAA,GAAA,kBAAA,KAAA,CAACA,YAAAA,KAAD;UACE,IAAG;UACH,SAAQ;UACR,MAAK;UACL,WAAU;UAJZ,UAAA,CAME,iBAAA,GAAA,kBAAA,IAAA,CAACI,mBAAAA,MAAD;WAAM,MAAK;WACT,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,2CAAAA,sBAAD,EAAsB,eAAA,KAAa,CAAA;UAC/B,CAAA,GAAC,WAEJ;SAEL,CAAA,IAAA,iBAAA,GAAA,kBAAA,IAAA,CAACJ,eAAAA,QAAD;UACE,SAAQ;UACR,MAAK;UACL,WAAU;UACV,UAAU,YAAY;UACtB,SAAS;UACT,eAAe,QAAQ,QAAQ;UAChC,UAAA;SAEO,CAAA;QAEP;OACF,CAAA,CAAA;;KACQ,CAAA,EACG,GApDK,SAAS,EAoDd;IAExB,CAAC,CACO;;GACT,aAAa,aAAa,CAAC,iBAC1B,iBAAA,GAAA,kBAAA,IAAA,CAACD,YAAAA,KAAD;IAAK,IAAG;IAAI,SAAQ;IAAU,MAAK;IAAQ,MAAK;IAAS,UAAA;GAEpD,CAAA,IACH;GACH,eACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,MAAK;IACR,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACM,eAAAA,QAAD;KAAQ,SAAQ;KAAc,OAAM;KAClC,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACA,eAAAA,OAAO,SAAR,EAAA,UAAiB,aAA6B,CAAA;IACxC,CAAA;GACL,CAAA,IACH;EACG;;AAEb"}
|
|
@@ -8,9 +8,10 @@ import { t as DataList } from "../../../data-list-BV-YCOhk.js";
|
|
|
8
8
|
import { t as Notice } from "../../../Notice-BdfIyUok.js";
|
|
9
9
|
import { t as Txt } from "../../../Txt-5efBsb2p.js";
|
|
10
10
|
import { IconCheckmark2Medium } from "../../../icons/central/IconCheckmark2Medium.es.js";
|
|
11
|
+
import { IconCrossMedium } from "../../../icons/central/IconCrossMedium.es.js";
|
|
11
12
|
import { Icon } from "../../../icons/Icon.es.js";
|
|
12
13
|
import { CONNECT_PROMPT_TOOL_NAME } from "./connect-prompt-tool-id.es.js";
|
|
13
|
-
import { useEffect, useRef } from "react";
|
|
14
|
+
import { useEffect, useRef, useState } from "react";
|
|
14
15
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
16
|
// src/domains/chat/tools/connect-prompt-tool.tsx
|
|
16
17
|
/**
|
|
@@ -30,16 +31,25 @@ function connectPromptFor({ toolName, toolCallId, output, metadata }) {
|
|
|
30
31
|
}
|
|
31
32
|
/** The resume tool's schema accepts; longer failure reasons are cut to fit. */
|
|
32
33
|
var MAX_RESUME_ERROR_LENGTH = 500;
|
|
34
|
+
/** What the agent is told when the user cancels the prompt. */
|
|
35
|
+
var CONNECT_PROMPT_CANCELLED_ERROR = "The user cancelled connecting.";
|
|
36
|
+
/** Marks the user cancelling the prompt as the outcome the call was resumed with. */
|
|
37
|
+
var CANCELLED = Symbol("cancelled");
|
|
33
38
|
/**
|
|
34
|
-
* What to resume the paused call with: the
|
|
35
|
-
* connect session couldn't even be created (e.g. the
|
|
39
|
+
* What to resume the paused call with: the user cancelling, the settled flow,
|
|
40
|
+
* or a failure when the connect session couldn't even be created (e.g. the
|
|
41
|
+
* connection limit).
|
|
36
42
|
*/
|
|
37
|
-
function connectPromptResumeFor(payload, settled, createError) {
|
|
43
|
+
function connectPromptResumeFor(payload, cancelled, settled, createError) {
|
|
38
44
|
const failed = (provider, error) => ({
|
|
39
45
|
provider,
|
|
40
46
|
status: "failed",
|
|
41
47
|
error: error.slice(0, MAX_RESUME_ERROR_LENGTH)
|
|
42
48
|
});
|
|
49
|
+
if (cancelled) {
|
|
50
|
+
const provider = payload.requestedProvider ?? payload.providers[0]?.id;
|
|
51
|
+
return provider ? failed(provider, CONNECT_PROMPT_CANCELLED_ERROR) : void 0;
|
|
52
|
+
}
|
|
43
53
|
if (createError) {
|
|
44
54
|
const provider = payload.requestedProvider ?? payload.providers[0]?.id;
|
|
45
55
|
return provider ? failed(provider, createError.message) : void 0;
|
|
@@ -80,23 +90,26 @@ var ConnectPromptTool = ({ toolName, toolCallId, output, metadata, readOnly = fa
|
|
|
80
90
|
});
|
|
81
91
|
};
|
|
82
92
|
var ConnectPromptCard = ({ toolCallId, payload, paused, readOnly }) => {
|
|
83
|
-
const { pending, connect, connectedProviders, isCreating, createError, settled } = usePendingConnect();
|
|
93
|
+
const { pending, connect, cancel, connectedProviders, isCreating, createError, settled } = usePendingConnect();
|
|
84
94
|
const { approveToolcall, isRunning, toolCallApprovals } = useToolCall();
|
|
95
|
+
const [cancelled, setCancelled] = useState(false);
|
|
85
96
|
const resumedRef = useRef(null);
|
|
86
97
|
const alreadyResumed = toolCallApprovals[toolCallId] !== void 0;
|
|
98
|
+
const canCancel = !readOnly && paused && !alreadyResumed && !cancelled;
|
|
87
99
|
const errorMessage = createError?.message ?? (settled?.status === "failed" ? settled.message ?? "The connection was not completed. Try connecting again." : null);
|
|
88
100
|
useEffect(() => {
|
|
89
101
|
if (readOnly || !paused || alreadyResumed || isRunning) return;
|
|
90
|
-
const outcome = createError ?? settled;
|
|
102
|
+
const outcome = cancelled ? CANCELLED : createError ?? settled;
|
|
91
103
|
if (!outcome || resumedRef.current === outcome) return;
|
|
92
104
|
resumedRef.current = outcome;
|
|
93
|
-
const resume = connectPromptResumeFor(payload, settled, createError);
|
|
105
|
+
const resume = connectPromptResumeFor(payload, cancelled, settled, createError);
|
|
94
106
|
if (resume) approveToolcall(toolCallId, resume);
|
|
95
107
|
}, [
|
|
96
108
|
readOnly,
|
|
97
109
|
paused,
|
|
98
110
|
alreadyResumed,
|
|
99
111
|
isRunning,
|
|
112
|
+
cancelled,
|
|
100
113
|
settled,
|
|
101
114
|
createError,
|
|
102
115
|
payload,
|
|
@@ -106,79 +119,102 @@ var ConnectPromptCard = ({ toolCallId, payload, paused, readOnly }) => {
|
|
|
106
119
|
return /* @__PURE__ */ jsxs("section", {
|
|
107
120
|
"aria-label": "Connect an account",
|
|
108
121
|
className: "my-2 space-y-3",
|
|
109
|
-
children: [
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
122
|
+
children: [
|
|
123
|
+
/* @__PURE__ */ jsxs(DataList, {
|
|
124
|
+
columns: "minmax(0, 1fr)",
|
|
125
|
+
fit: "container",
|
|
126
|
+
scrollable: false,
|
|
127
|
+
children: [/* @__PURE__ */ jsxs(DataList.Subheader, {
|
|
128
|
+
className: "flex items-center justify-between gap-3",
|
|
129
|
+
children: [/* @__PURE__ */ jsx(Txt, {
|
|
130
|
+
as: "h4",
|
|
131
|
+
variant: "subheading",
|
|
132
|
+
tone: "ink",
|
|
133
|
+
children: "Connect an account"
|
|
134
|
+
}), canCancel ? /* @__PURE__ */ jsx(Button, {
|
|
135
|
+
variant: "ghost",
|
|
136
|
+
size: "icon-sm",
|
|
137
|
+
"aria-label": "Cancel",
|
|
138
|
+
tooltip: "Cancel",
|
|
139
|
+
onClick: () => {
|
|
140
|
+
cancel();
|
|
141
|
+
setCancelled(true);
|
|
142
|
+
},
|
|
143
|
+
children: /* @__PURE__ */ jsx(IconCrossMedium, { "aria-hidden": true })
|
|
144
|
+
}) : null]
|
|
145
|
+
}), payload.providers.map((provider) => {
|
|
146
|
+
const isConnected = provider.connected || connectedProviders.has(provider.id);
|
|
147
|
+
const isPending = pending?.provider === provider.id;
|
|
148
|
+
return /* @__PURE__ */ jsx(DataList.RowStatic, { children: /* @__PURE__ */ jsx(DataList.Cell, {
|
|
149
|
+
className: "col-span-full py-2",
|
|
150
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
151
|
+
className: "flex flex-wrap items-center justify-between gap-3",
|
|
152
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
153
|
+
className: "flex min-w-0 flex-1 items-center gap-2",
|
|
154
|
+
children: [/* @__PURE__ */ jsx(ProviderLogo, { logoUrl: provider.logoUrl }), /* @__PURE__ */ jsx(Txt, {
|
|
138
155
|
as: "span",
|
|
139
156
|
variant: "body-sm",
|
|
140
|
-
tone: "
|
|
141
|
-
|
|
142
|
-
children:
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
+
tone: "ink",
|
|
158
|
+
className: "truncate",
|
|
159
|
+
children: provider.displayName ?? provider.id
|
|
160
|
+
})]
|
|
161
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
162
|
+
className: "flex flex-wrap items-center gap-3",
|
|
163
|
+
children: [
|
|
164
|
+
isPending ? /* @__PURE__ */ jsx(Txt, {
|
|
165
|
+
as: "span",
|
|
166
|
+
variant: "body-sm",
|
|
167
|
+
tone: "muted",
|
|
168
|
+
role: "status",
|
|
169
|
+
children: "Waiting for authorization…"
|
|
170
|
+
}) : null,
|
|
171
|
+
isPending && pending?.fallbackUrl ? /* @__PURE__ */ jsx("a", {
|
|
172
|
+
href: pending.fallbackUrl,
|
|
173
|
+
target: "_blank",
|
|
174
|
+
rel: "noreferrer",
|
|
175
|
+
className: "text-ui-md underline underline-offset-2",
|
|
176
|
+
children: "Open the connect window"
|
|
177
|
+
}) : null,
|
|
178
|
+
isConnected ? /* @__PURE__ */ jsxs(Txt, {
|
|
179
|
+
as: "span",
|
|
180
|
+
variant: "body-sm",
|
|
181
|
+
tone: "muted",
|
|
182
|
+
className: "flex min-w-24 items-center justify-center gap-1",
|
|
183
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
184
|
+
size: "sm",
|
|
185
|
+
children: /* @__PURE__ */ jsx(IconCheckmark2Medium, { "aria-hidden": true })
|
|
186
|
+
}), "Connected"]
|
|
187
|
+
}) : /* @__PURE__ */ jsx(Button, {
|
|
188
|
+
variant: "primary",
|
|
157
189
|
size: "sm",
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
children: /* @__PURE__ */ jsx(Notice
|
|
180
|
-
|
|
181
|
-
|
|
190
|
+
className: "min-w-24",
|
|
191
|
+
disabled: readOnly || isCreating,
|
|
192
|
+
loading: isPending,
|
|
193
|
+
onClick: () => connect(provider),
|
|
194
|
+
children: "Connect"
|
|
195
|
+
})
|
|
196
|
+
]
|
|
197
|
+
})]
|
|
198
|
+
})
|
|
199
|
+
}) }, provider.id);
|
|
200
|
+
})]
|
|
201
|
+
}),
|
|
202
|
+
cancelled && isRunning && !alreadyResumed ? /* @__PURE__ */ jsx(Txt, {
|
|
203
|
+
as: "p",
|
|
204
|
+
variant: "body-sm",
|
|
205
|
+
tone: "muted",
|
|
206
|
+
role: "status",
|
|
207
|
+
children: "Cancelled. The agent continues once its current response finishes."
|
|
208
|
+
}) : null,
|
|
209
|
+
errorMessage ? /* @__PURE__ */ jsx("div", {
|
|
210
|
+
role: "alert",
|
|
211
|
+
children: /* @__PURE__ */ jsx(Notice, {
|
|
212
|
+
variant: "destructive",
|
|
213
|
+
title: "Couldn't connect",
|
|
214
|
+
children: /* @__PURE__ */ jsx(Notice.Message, { children: errorMessage })
|
|
215
|
+
})
|
|
216
|
+
}) : null
|
|
217
|
+
]
|
|
182
218
|
});
|
|
183
219
|
};
|
|
184
220
|
export { CONNECT_PROMPT_TOOL_NAME, ConnectPromptTool };
|