@blade-hq/agent-react 2612.0.0-beta.9 → 2612.0.0-beta.90

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.
Files changed (185) hide show
  1. package/README.md +56 -0
  2. package/dist/SessionPluginConfigForm-FROO3XEW.js +9 -0
  3. package/dist/SessionPluginConfigForm-FROO3XEW.js.map +1 -0
  4. package/dist/chat/AgentLoopBlock.d.ts +0 -2
  5. package/dist/chat/AskUserQuestionBlock.d.ts +3 -20
  6. package/dist/chat/AssistantTurnBlock.d.ts +3 -10
  7. package/dist/chat/AttachmentPreviewDialog.d.ts +0 -1
  8. package/dist/chat/ChatLoadingIndicator.d.ts +15 -0
  9. package/dist/chat/ChatPanel.d.ts +3 -1
  10. package/dist/chat/ContextAttachmentPills.d.ts +4 -0
  11. package/dist/chat/CurrentPlanPanel.d.ts +0 -3
  12. package/dist/chat/FileDeliveryCards.d.ts +12 -10
  13. package/dist/chat/FinalArtifactCards.d.ts +0 -1
  14. package/dist/chat/ImageLightbox.d.ts +1 -1
  15. package/dist/chat/LiteMessageList.d.ts +5 -3
  16. package/dist/chat/MessageFileAttachmentList.d.ts +0 -5
  17. package/dist/chat/QuestionnaireQuestionBlock.d.ts +11 -0
  18. package/dist/chat/SessionReplayBar.d.ts +0 -1
  19. package/dist/chat/TextAttachmentPills.d.ts +0 -3
  20. package/dist/chat/TurnNavRail.d.ts +1 -7
  21. package/dist/chat/WorkflowRunBlock.d.ts +21 -4
  22. package/dist/chat/ai-elements/shimmer.d.ts +2 -2
  23. package/dist/chat/chat-column-width.d.ts +21 -0
  24. package/dist/chat/customization.d.ts +1 -1
  25. package/dist/chat/index.d.ts +6 -3
  26. package/dist/chat/markdown/ExternalAnchor.d.ts +2 -2
  27. package/dist/chat/message-list-blocks.d.ts +0 -1
  28. package/dist/chat/runtime/actions.d.ts +7 -3
  29. package/dist/chat/runtime/background-task-dismissals.d.ts +0 -1
  30. package/dist/chat/runtime/composer-channels.d.ts +0 -3
  31. package/dist/chat/runtime/environment.d.ts +2 -0
  32. package/dist/chat/runtime/input-cache-reset.d.ts +0 -5
  33. package/dist/chat/runtime/input-services.d.ts +10 -0
  34. package/dist/chat/runtime/session-source.d.ts +0 -5
  35. package/dist/chat/runtime/use-chat-actions.d.ts +1 -5
  36. package/dist/chat/turn-locate-channel.d.ts +53 -0
  37. package/dist/chat.css +23 -18
  38. package/dist/chunk-2GP2S3IR.js +9629 -0
  39. package/dist/chunk-2GP2S3IR.js.map +1 -0
  40. package/dist/{chunk-4OG6AJXY.js → chunk-3XWKS2YP.js} +3955 -26107
  41. package/dist/chunk-3XWKS2YP.js.map +1 -0
  42. package/dist/{chunk-HJ7KNUWM.js → chunk-5FK33U4M.js} +4181 -16595
  43. package/dist/chunk-5FK33U4M.js.map +1 -0
  44. package/dist/chunk-A5WYUMNB.js +1340 -0
  45. package/dist/chunk-A5WYUMNB.js.map +1 -0
  46. package/dist/chunk-JBVJMUJA.js +805 -0
  47. package/dist/chunk-JBVJMUJA.js.map +1 -0
  48. package/dist/chunk-NRAHM3CD.js +14861 -0
  49. package/dist/chunk-NRAHM3CD.js.map +1 -0
  50. package/dist/chunk-NS55ESUC.js +9488 -0
  51. package/dist/chunk-NS55ESUC.js.map +1 -0
  52. package/dist/chunk-PRDGUQTE.js +4157 -0
  53. package/dist/chunk-PRDGUQTE.js.map +1 -0
  54. package/dist/chunk-T42PKMOI.js +2417 -0
  55. package/dist/chunk-T42PKMOI.js.map +1 -0
  56. package/dist/chunk-WMWYGB2C.js +964 -0
  57. package/dist/chunk-WMWYGB2C.js.map +1 -0
  58. package/dist/components/AccountConnectorRules.d.ts +7 -0
  59. package/dist/components/AccountConnectors.d.ts +13 -0
  60. package/dist/components/ActionApprovals.d.ts +16 -0
  61. package/dist/components/BrowserConnectionDialog.d.ts +8 -0
  62. package/dist/components/ChatInput.d.ts +1 -15
  63. package/dist/components/ConfigConnection.d.ts +16 -0
  64. package/dist/components/ConnectorAuthorizationProgress.d.ts +6 -0
  65. package/dist/components/ConnectorConnection.d.ts +4 -0
  66. package/dist/components/ConnectorDetail.d.ts +46 -0
  67. package/dist/components/ConnectorPanel.d.ts +3 -1
  68. package/dist/components/ConnectorRulesPanel.d.ts +10 -0
  69. package/dist/components/ConnectorRuntimeDiagnostics.d.ts +5 -0
  70. package/dist/components/DeviceConnection.d.ts +17 -0
  71. package/dist/components/FeishuCapabilitySelection.d.ts +14 -0
  72. package/dist/components/FeishuPermissionStatus.d.ts +7 -0
  73. package/dist/components/LlmAdvancedSettings.d.ts +0 -1
  74. package/dist/components/ManagedConnection.d.ts +12 -0
  75. package/dist/components/McpAppFrame.d.ts +17 -0
  76. package/dist/components/PackEventNotice.d.ts +3 -0
  77. package/dist/components/PlanUpdateBlock.d.ts +0 -1
  78. package/dist/components/SessionPluginConfigForm.d.ts +4 -1
  79. package/dist/components/SessionPluginIcon.d.ts +1 -0
  80. package/dist/components/action-approval-format.d.ts +35 -0
  81. package/dist/components/plugin-connector.d.ts +1 -0
  82. package/dist/connectors.d.ts +6 -0
  83. package/dist/connectors.js +19 -0
  84. package/dist/connectors.js.map +1 -0
  85. package/dist/embed/blade-chat-element.d.ts +0 -8
  86. package/dist/embed/entry.d.ts +21 -19
  87. package/dist/hooks/use-capabilities.d.ts +3 -0
  88. package/dist/hooks/use-message-pin.d.ts +1 -1
  89. package/dist/hooks/use-turn-navigation.d.ts +19 -0
  90. package/dist/index.d.ts +9 -0
  91. package/dist/index.js +31 -3
  92. package/dist/internal.d.ts +7 -4
  93. package/dist/internal.js +671 -103
  94. package/dist/internal.js.map +1 -1
  95. package/dist/lib/message-shortcuts.d.ts +5 -0
  96. package/dist/questions.d.ts +7 -0
  97. package/dist/questions.js +910 -0
  98. package/dist/questions.js.map +1 -0
  99. package/dist/rich-input/ChatInput.d.ts +1 -1
  100. package/dist/rich-input/ConnectButton.d.ts +7 -5
  101. package/dist/rich-input/FileCompletionMenu.d.ts +1 -2
  102. package/dist/rich-input/InputActionSubmenu.d.ts +10 -0
  103. package/dist/rich-input/ModelSelector.d.ts +3 -1
  104. package/dist/rich-input/SkillActionMenu.d.ts +10 -0
  105. package/dist/rich-input/SkillStatusBar.d.ts +0 -6
  106. package/dist/rich-input/extensions/skill-mention.d.ts +3 -20
  107. package/dist/rich-input/index.d.ts +3 -2
  108. package/dist/rich-input/lib/composer-content.d.ts +5 -1
  109. package/dist/rich-input/lib/plugin-suggestions.d.ts +4 -4
  110. package/dist/rich-input/lib/reference-candidates.d.ts +0 -1
  111. package/dist/rich-input/lib/skill-suggestions.d.ts +1 -1
  112. package/dist/rich-input/lib/user-home.d.ts +0 -17
  113. package/dist/rich-input/model/resolve-model.d.ts +2 -2
  114. package/dist/rich-input/services.d.ts +1 -1
  115. package/dist/rich-input/voice/VoiceWaveform.d.ts +0 -3
  116. package/dist/rich-input.js +1711 -2140
  117. package/dist/rich-input.js.map +1 -1
  118. package/dist/style.css +16 -55
  119. package/dist/style.full.css +41 -77
  120. package/dist/tool-details.d.ts +8 -0
  121. package/dist/tool-details.js +25 -0
  122. package/dist/tool-details.js.map +1 -0
  123. package/node_modules/@modelcontextprotocol/ext-apps/LICENSE +216 -0
  124. package/node_modules/@modelcontextprotocol/ext-apps/README.md +284 -0
  125. package/node_modules/@modelcontextprotocol/ext-apps/dist/docs/patterns.d.ts +9 -0
  126. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.d.ts +1348 -0
  127. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.examples.d.ts +9 -0
  128. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.js +39 -0
  129. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.test.d.ts +1 -0
  130. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-with-deps.js +82 -0
  131. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.d.ts +1214 -0
  132. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.examples.d.ts +9 -0
  133. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.js +39 -0
  134. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.test.d.ts +1 -0
  135. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/constants.d.ts +65 -0
  136. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/events.d.ts +47 -0
  137. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/events.test.d.ts +1 -0
  138. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/generated/schema.d.ts +1047 -0
  139. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/generated/schema.json +6170 -0
  140. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/generated/schema.test.d.ts +41 -0
  141. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/interop-v1.test.d.ts +1 -0
  142. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/legacy-handlers.d.ts +66 -0
  143. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/legacy-handlers.test.d.ts +1 -0
  144. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/message-transport.d.ts +126 -0
  145. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/message-transport.examples.d.ts +9 -0
  146. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/message-transport.test.d.ts +1 -0
  147. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/index.d.ts +37 -0
  148. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/index.examples.d.ts +6 -0
  149. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/index.js +39 -0
  150. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/react-with-deps.js +82 -0
  151. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useApp.d.ts +115 -0
  152. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useApp.examples.d.ts +6 -0
  153. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useAutoResize.d.ts +54 -0
  154. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useAutoResize.examples.d.ts +6 -0
  155. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useDocumentTheme.d.ts +44 -0
  156. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useDocumentTheme.examples.d.ts +6 -0
  157. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useHostStyles.d.ts +113 -0
  158. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useHostStyles.examples.d.ts +6 -0
  159. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.d.ts +381 -0
  160. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.examples.d.ts +9 -0
  161. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.js +1 -0
  162. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.test.d.ts +1 -0
  163. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/spec.types.d.ts +698 -0
  164. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/standard-schema.d.ts +23 -0
  165. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/styles.d.ts +184 -0
  166. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/styles.examples.d.ts +9 -0
  167. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/types.d.ts +33 -0
  168. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/wire-compat.test.d.ts +1 -0
  169. package/node_modules/@modelcontextprotocol/ext-apps/package.json +144 -0
  170. package/node_modules/@standard-schema/spec/LICENSE +21 -0
  171. package/node_modules/@standard-schema/spec/README.md +198 -0
  172. package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
  173. package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
  174. package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
  175. package/node_modules/@standard-schema/spec/dist/index.js +0 -0
  176. package/node_modules/@standard-schema/spec/package.json +52 -0
  177. package/package.json +19 -3
  178. package/public-api.md +100 -4
  179. package/dist/chat-OCLOVB3H.css +0 -175
  180. package/dist/chunk-3DRBRQXN.js +0 -258
  181. package/dist/chunk-3DRBRQXN.js.map +0 -1
  182. package/dist/chunk-4OG6AJXY.js.map +0 -1
  183. package/dist/chunk-HJ7KNUWM.js.map +0 -1
  184. package/dist/lib/agent-computer-command.d.ts +0 -32
  185. package/dist/rich-input/extensions/workflow-mention.d.ts +0 -10
@@ -0,0 +1,805 @@
1
+ import {
2
+ PluginConnectorList,
3
+ SessionPluginIcon,
4
+ catalogToConnectorItems,
5
+ filterConnectorItems,
6
+ useSessionPluginActivation
7
+ } from "./chunk-A5WYUMNB.js";
8
+ import {
9
+ ConnectorConnection
10
+ } from "./chunk-T42PKMOI.js";
11
+ import {
12
+ AccountConnectorRules,
13
+ BrowserConnectionDialog
14
+ } from "./chunk-PRDGUQTE.js";
15
+ import {
16
+ ConfigConnection,
17
+ Dialog,
18
+ DialogContent,
19
+ DialogTitle
20
+ } from "./chunk-2GP2S3IR.js";
21
+ import {
22
+ Check,
23
+ LoaderCircle,
24
+ Pencil,
25
+ Plug,
26
+ RefreshCw,
27
+ Search,
28
+ Trash2
29
+ } from "./chunk-WMWYGB2C.js";
30
+
31
+ // src/chat/runtime/composer-channels.ts
32
+ import { normalizeTopicAssetRefs } from "@blade-hq/agent-client";
33
+ import { useSyncExternalStore } from "react";
34
+ function buildSignalId() {
35
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
36
+ return crypto.randomUUID();
37
+ }
38
+ return `bridge-${Date.now()}-${Math.random().toString(36).slice(2)}`;
39
+ }
40
+ function withoutKey(record, key) {
41
+ if (!(key in record)) return record;
42
+ const next = { ...record };
43
+ delete next[key];
44
+ return next;
45
+ }
46
+ var state = {
47
+ topicAssetReferences: {},
48
+ pendingContexts: {},
49
+ draftAppends: {},
50
+ sendRequests: {},
51
+ modelDrafts: {},
52
+ rewindDrafts: {}
53
+ };
54
+ var listeners = /* @__PURE__ */ new Set();
55
+ function setState(update) {
56
+ const next = update(state);
57
+ if (next === state) return;
58
+ state = next;
59
+ for (const listener of [...listeners]) listener();
60
+ }
61
+ function consume(key, sessionId) {
62
+ const signals = state[key][sessionId] ?? [];
63
+ if (signals.length === 0) return [];
64
+ setState((current) => ({ ...current, [key]: withoutKey(current[key], sessionId) }));
65
+ return signals;
66
+ }
67
+ var composerChannels = {
68
+ getState: () => state,
69
+ addTopicAssetReference(sessionId, ref) {
70
+ setState((current) => ({ ...current, topicAssetReferences: { ...current.topicAssetReferences, [sessionId]: normalizeTopicAssetRefs([...current.topicAssetReferences[sessionId] ?? [], ref]) } }));
71
+ },
72
+ consumeTopicAssetReferences: (sessionId) => consume("topicAssetReferences", sessionId),
73
+ subscribe(listener) {
74
+ listeners.add(listener);
75
+ return () => {
76
+ listeners.delete(listener);
77
+ };
78
+ },
79
+ addPendingContext(sessionId, context) {
80
+ setState((current) => ({
81
+ ...current,
82
+ pendingContexts: {
83
+ ...current.pendingContexts,
84
+ [sessionId]: [
85
+ ...current.pendingContexts[sessionId] ?? [],
86
+ { id: buildSignalId(), label: context.label, content: context.content, imageUrl: context.imageUrl }
87
+ ]
88
+ }
89
+ }));
90
+ },
91
+ removePendingContext(sessionId, contextId) {
92
+ setState((current) => {
93
+ const contexts = current.pendingContexts[sessionId];
94
+ if (!contexts?.length) return current;
95
+ const next = contexts.filter((context) => context.id !== contextId);
96
+ if (next.length === contexts.length) return current;
97
+ return {
98
+ ...current,
99
+ pendingContexts: next.length > 0 ? { ...current.pendingContexts, [sessionId]: next } : withoutKey(current.pendingContexts, sessionId)
100
+ };
101
+ });
102
+ },
103
+ consumePendingContexts: (sessionId) => consume("pendingContexts", sessionId),
104
+ clearPendingContexts(sessionId) {
105
+ setState((current) => ({ ...current, pendingContexts: withoutKey(current.pendingContexts, sessionId) }));
106
+ },
107
+ addDraftAppend(sessionId, text, separate) {
108
+ setState((current) => ({
109
+ ...current,
110
+ draftAppends: {
111
+ ...current.draftAppends,
112
+ [sessionId]: [...current.draftAppends[sessionId] ?? [], { id: buildSignalId(), text, separate }]
113
+ }
114
+ }));
115
+ },
116
+ consumeDraftAppends: (sessionId) => consume("draftAppends", sessionId),
117
+ clearDraftAppends(sessionId) {
118
+ setState((current) => ({ ...current, draftAppends: withoutKey(current.draftAppends, sessionId) }));
119
+ },
120
+ addSendRequest(sessionId) {
121
+ setState((current) => ({
122
+ ...current,
123
+ sendRequests: {
124
+ ...current.sendRequests,
125
+ [sessionId]: [...current.sendRequests[sessionId] ?? [], { id: buildSignalId() }]
126
+ }
127
+ }));
128
+ },
129
+ consumeSendRequests: (sessionId) => consume("sendRequests", sessionId),
130
+ clearSendRequests(sessionId) {
131
+ setState((current) => ({ ...current, sendRequests: withoutKey(current.sendRequests, sessionId) }));
132
+ },
133
+ setModelDraft(sessionId, model) {
134
+ setState(
135
+ (current) => current.modelDrafts[sessionId] === model ? current : { ...current, modelDrafts: { ...current.modelDrafts, [sessionId]: model } }
136
+ );
137
+ },
138
+ clearModelDraft(sessionId) {
139
+ setState((current) => ({ ...current, modelDrafts: withoutKey(current.modelDrafts, sessionId) }));
140
+ },
141
+ setRewindDraft(sessionId, text) {
142
+ setState(
143
+ (current) => text === null ? { ...current, rewindDrafts: withoutKey(current.rewindDrafts, sessionId) } : { ...current, rewindDrafts: { ...current.rewindDrafts, [sessionId]: text } }
144
+ );
145
+ },
146
+ clearSession(sessionId) {
147
+ setState((current) => ({
148
+ ...current,
149
+ topicAssetReferences: withoutKey(current.topicAssetReferences, sessionId),
150
+ pendingContexts: withoutKey(current.pendingContexts, sessionId),
151
+ draftAppends: withoutKey(current.draftAppends, sessionId),
152
+ sendRequests: withoutKey(current.sendRequests, sessionId)
153
+ }));
154
+ },
155
+ reset() {
156
+ setState(() => ({ topicAssetReferences: {}, pendingContexts: {}, draftAppends: {}, sendRequests: {}, modelDrafts: {}, rewindDrafts: {} }));
157
+ }
158
+ };
159
+ function useComposerChannels(selector) {
160
+ return useSyncExternalStore(
161
+ composerChannels.subscribe,
162
+ () => selector(state),
163
+ () => selector(state)
164
+ );
165
+ }
166
+
167
+ // src/chat/lib/skill-name.ts
168
+ function skillDisplayName(skill) {
169
+ const displayName = (skill.display_name ?? skill.displayName ?? "").trim();
170
+ if (displayName) {
171
+ return displayName;
172
+ }
173
+ return (skill.skill_id ?? skill.skillId ?? "").trim();
174
+ }
175
+
176
+ // src/chat/runtime/background-task-dismissals.ts
177
+ import { useSyncExternalStore as useSyncExternalStore2 } from "react";
178
+ var state2 = {};
179
+ var listeners2 = /* @__PURE__ */ new Set();
180
+ var NO_IDS = [];
181
+ function emit() {
182
+ for (const listener of [...listeners2]) listener();
183
+ }
184
+ var backgroundTaskDismissals = {
185
+ getState: () => state2,
186
+ subscribe(listener) {
187
+ listeners2.add(listener);
188
+ return () => {
189
+ listeners2.delete(listener);
190
+ };
191
+ },
192
+ dismiss(sessionId, taskId) {
193
+ const existing = state2[sessionId] ?? [];
194
+ if (existing.includes(taskId)) return;
195
+ state2 = { ...state2, [sessionId]: [...existing, taskId] };
196
+ emit();
197
+ },
198
+ reset() {
199
+ state2 = {};
200
+ emit();
201
+ }
202
+ };
203
+ function useDismissedBackgroundTasks(sessionId) {
204
+ return useSyncExternalStore2(
205
+ backgroundTaskDismissals.subscribe,
206
+ () => state2[sessionId] ?? NO_IDS,
207
+ () => state2[sessionId] ?? NO_IDS
208
+ );
209
+ }
210
+
211
+ // src/chat/lib/skill-visibility.ts
212
+ function visibleSkills(skills, mode) {
213
+ return mode === "developer" ? skills : skills.filter((skill) => !skill.builtin);
214
+ }
215
+ function visibleSkillIds(ids, catalog, mode) {
216
+ if (mode === "developer") return [...ids];
217
+ if (!catalog) return [];
218
+ const builtins = new Set(catalog.filter((skill) => skill.builtin).map((skill) => skill.skill_id));
219
+ return ids.filter((id) => !builtins.has(id));
220
+ }
221
+
222
+ // src/components/connector-panel-types.ts
223
+ function selectionFromItem(item) {
224
+ return {
225
+ name: item.name,
226
+ displayName: item.display_name ?? null,
227
+ icon: item.icon,
228
+ iconSource: item.iconSource
229
+ };
230
+ }
231
+ var TRIGGER_ICON_LIMIT = 3;
232
+ function triggerSummary(items) {
233
+ const visible = items.slice(0, TRIGGER_ICON_LIMIT);
234
+ return {
235
+ visible,
236
+ overflow: items.length - visible.length,
237
+ total: items.length
238
+ };
239
+ }
240
+
241
+ // src/components/AccountConnectors.tsx
242
+ import { isLocalConnectorName } from "@blade-hq/agent-client/internal";
243
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
244
+ import { Suspense, lazy } from "react";
245
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
246
+ var SessionPluginConfigForm = lazy(() => import("./SessionPluginConfigForm-FROO3XEW.js").then((module) => ({ default: module.SessionPluginConfigForm })));
247
+ var actionBaseClass = "inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--background))] text-xs font-medium text-[hsl(var(--foreground))] transition-colors hover:bg-[hsl(var(--accent))] focus-visible:outline-2 focus-visible:outline-offset-2 disabled:pointer-events-none disabled:opacity-50";
248
+ var actionClass = `${actionBaseClass} px-3`;
249
+ var iconActionClass = `${actionBaseClass} w-8 p-0`;
250
+ async function failureMessage(error) {
251
+ const response = error?.response;
252
+ if (response) {
253
+ try {
254
+ const body = await response.json();
255
+ if (typeof body.detail === "string") return body.detail;
256
+ if (typeof body.detail?.message === "string") return body.detail.message;
257
+ } catch {
258
+ }
259
+ }
260
+ return "\u64CD\u4F5C\u672A\u5B8C\u6210\uFF0C\u8BF7\u91CD\u8BD5";
261
+ }
262
+ function DeviceDialog({ client, connector, onChanged, onClose }) {
263
+ const [rulesRefresh, setRulesRefresh] = useState(0);
264
+ return /* @__PURE__ */ jsx(Dialog, { open: true, onOpenChange: (open) => {
265
+ if (!open) onClose();
266
+ }, children: /* @__PURE__ */ jsxs(DialogContent, { "aria-describedby": void 0, className: "max-h-[85dvh] overflow-y-auto sm:max-w-[640px]", children: [
267
+ /* @__PURE__ */ jsxs(DialogTitle, { className: "sr-only", children: [
268
+ "\u8FDE\u63A5 ",
269
+ connector.display_name || connector.name
270
+ ] }),
271
+ /* @__PURE__ */ jsx(ConnectorConnection, { detail: { name: connector.name, title: connector.display_name || connector.name, icon: /* @__PURE__ */ jsx(SessionPluginIcon, { client, sessionId: null, plugin: connector, size: 44 }), rules: /* @__PURE__ */ jsx(AccountConnectorRules, { client, name: connector.name, refresh: rulesRefresh }) }, type: connector.authorization?.type === "managed" ? "managed" : "device", read: () => client.connectors.authorization(connector.name), act: (action, options) => client.connectors.authorize(connector.name, action, void 0, options), plan: (capabilities) => client.connectors.authorizationPlan(connector.name, capabilities), diagnostics: () => client.connectors.diagnostics(connector.name), onChanged: async () => {
272
+ await onChanged();
273
+ setRulesRefresh((value) => value + 1);
274
+ }, onDisable: () => client.connectors.disconnect(connector.name) }),
275
+ /* @__PURE__ */ jsx("button", { type: "button", className: actionClass, onClick: onClose, children: "\u8FD4\u56DE\u8FDE\u63A5\u5668" })
276
+ ] }) });
277
+ }
278
+ function ConnectionDialog({ client, connector, onConnected, onChanged, onClose }) {
279
+ const [view, setView] = useState(null);
280
+ const [failure, setFailure] = useState(null);
281
+ const [submitting, setSubmitting] = useState(false);
282
+ const [editing, setEditing] = useState(false);
283
+ const [rulesRefresh, setRulesRefresh] = useState(0);
284
+ const connectionRequest = useRef(null);
285
+ const alive = useRef(false);
286
+ useEffect(() => {
287
+ alive.current = true;
288
+ const abort = new AbortController();
289
+ client.connectors.read(connector.name, { signal: abort.signal }).then((value) => {
290
+ if (!abort.signal.aborted) setView(value);
291
+ }).catch(async (error) => {
292
+ const message = await failureMessage(error);
293
+ if (!abort.signal.aborted) setFailure(message);
294
+ });
295
+ return () => {
296
+ alive.current = false;
297
+ abort.abort();
298
+ connectionRequest.current?.abort();
299
+ };
300
+ }, [client, connector.name]);
301
+ async function submit(draft) {
302
+ if (!view || submitting) return;
303
+ setSubmitting(true);
304
+ setFailure(null);
305
+ const request = new AbortController();
306
+ connectionRequest.current = request;
307
+ try {
308
+ const next = await client.connectors.connect(connector.name, { expected_revision: view.config.revision, ...draft }, { signal: request.signal });
309
+ if (request.signal.aborted) return;
310
+ setView(next);
311
+ setEditing(false);
312
+ setRulesRefresh((value) => value + 1);
313
+ try {
314
+ await onConnected();
315
+ } catch {
316
+ if (!request.signal.aborted) setFailure("\u5DF2\u8FDE\u63A5\uFF0C\u4F46\u5217\u8868\u6216\u5BF9\u8BDD\u72B6\u6001\u672A\u80FD\u5237\u65B0\u3002\u8BF7\u8FD4\u56DE\u540E\u91CD\u8BD5\u5237\u65B0\u6216\u542F\u7528\u3002");
317
+ }
318
+ } catch (error) {
319
+ if (request.signal.aborted) return;
320
+ setFailure(await failureMessage(error));
321
+ try {
322
+ const next = await client.connectors.read(connector.name);
323
+ if (!request.signal.aborted) setView(next);
324
+ } catch {
325
+ }
326
+ } finally {
327
+ if (!request.signal.aborted) setSubmitting(false);
328
+ }
329
+ }
330
+ const form = view && /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("output", { children: "\u6B63\u5728\u8BFB\u53D6\u8FDE\u63A5\u8868\u5355\u2026" }), children: /* @__PURE__ */ jsx(SessionPluginConfigForm, { collapseHelp: true, config: view.config, submitting, errors: [], failure, submitLabel: editing ? "\u4FDD\u5B58\u5E76\u8FDE\u63A5" : "\u8FDE\u63A5\u5E76\u9A8C\u8BC1", submittingLabel: "\u6B63\u5728\u8FDE\u63A5\u2026", onCancel: () => editing ? setEditing(false) : onClose(), onSubmit: (draft) => void submit(draft) }) });
331
+ const current = view?.connection ?? connector.connection;
332
+ return /* @__PURE__ */ jsx(Dialog, { open: true, onOpenChange: (open) => {
333
+ if (!open && !submitting) onClose();
334
+ }, children: /* @__PURE__ */ jsxs(DialogContent, { "aria-describedby": void 0, className: "max-h-[85dvh] overflow-y-auto sm:max-w-[640px]", onEscapeKeyDown: (event) => {
335
+ if (submitting) event.preventDefault();
336
+ }, onInteractOutside: (event) => {
337
+ if (submitting) event.preventDefault();
338
+ }, children: [
339
+ /* @__PURE__ */ jsxs(DialogTitle, { className: "sr-only", children: [
340
+ "\u8FDE\u63A5 ",
341
+ connector.display_name || connector.name
342
+ ] }),
343
+ /* @__PURE__ */ jsx(ConfigConnection, { detail: { title: connector.display_name || connector.name, icon: /* @__PURE__ */ jsx(SessionPluginIcon, { client, sessionId: null, plugin: connector, size: 44 }), rules: /* @__PURE__ */ jsx(AccountConnectorRules, { client, name: connector.name, refresh: rulesRefresh }) }, status: current.status, account: current.account_label, verifiedAt: current.verified_at, busy: submitting, connection: view ? form : /* @__PURE__ */ jsx("output", { children: failure || "\u6B63\u5728\u83B7\u53D6\u8BA4\u8BC1\u8868\u5355\u2026" }), onEdit: () => setEditing(true), onDisconnect: async () => {
344
+ setSubmitting(true);
345
+ try {
346
+ const next = await client.connectors.disconnect(connector.name);
347
+ if (alive.current) {
348
+ setView(next);
349
+ setRulesRefresh((value) => value + 1);
350
+ }
351
+ await onChanged();
352
+ } finally {
353
+ if (alive.current) setSubmitting(false);
354
+ }
355
+ }, onVerify: async () => {
356
+ const next = await client.connectors.verify(connector.name);
357
+ if (alive.current) setView(next);
358
+ } }),
359
+ failure && current.status === "connected" && /* @__PURE__ */ jsx("p", { role: "alert", children: failure }),
360
+ editing && /* @__PURE__ */ jsx(Dialog, { open: true, onOpenChange: (open) => {
361
+ if (!open && !submitting) setEditing(false);
362
+ }, children: /* @__PURE__ */ jsxs(DialogContent, { "aria-describedby": void 0, className: "max-h-[85dvh] overflow-y-auto", onEscapeKeyDown: (event) => {
363
+ if (submitting) event.preventDefault();
364
+ }, onInteractOutside: (event) => {
365
+ if (submitting) event.preventDefault();
366
+ }, children: [
367
+ /* @__PURE__ */ jsx(DialogTitle, { children: "\u66F4\u6362\u8D26\u53F7" }),
368
+ /* @__PURE__ */ jsx("p", { children: "\u4FDD\u5B58\u540E\u65E7\u8D26\u53F7\u8FDE\u63A5\u4F1A\u88AB\u66FF\u6362\uFF0C\u4F7F\u7528\u89C4\u5219\u4FDD\u7559\u3002" }),
369
+ form
370
+ ] }) }),
371
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: submitting, className: actionClass, onClick: onClose, children: "\u8FD4\u56DE\u8FDE\u63A5\u5668" })
372
+ ] }) });
373
+ }
374
+ function AccountConnectors({ client, query = "", sessionId = null, pending, onUse, onSelectedChange, disabledReason, catalog = false, manage = false, onEdit }) {
375
+ const [items, setItems] = useState([]);
376
+ const [editing, setEditing] = useState(null);
377
+ const [failure, setFailure] = useState(null);
378
+ const [loading, setLoading] = useState(true);
379
+ const deleteDialog = useRef(null);
380
+ const [deleting, setDeleting] = useState(null);
381
+ const [busy, setBusy] = useState(false);
382
+ useEffect(() => {
383
+ if (!deleting) return;
384
+ const element = deleteDialog.current;
385
+ element?.showModal();
386
+ return () => element?.close();
387
+ }, [deleting]);
388
+ const lifetime = useRef(null);
389
+ const load = useCallback((signal) => sessionId ? client.connectors.listForSession(sessionId, { signal }) : client.connectors.list({ signal }), [client, sessionId]);
390
+ const reload = useCallback(async () => {
391
+ const scope = lifetime.current;
392
+ const result = await load(scope?.signal);
393
+ if (scope === lifetime.current && !scope?.signal.aborted) {
394
+ setItems(result.connectors);
395
+ setFailure(null);
396
+ }
397
+ }, [load]);
398
+ useEffect(() => {
399
+ const abort = new AbortController();
400
+ lifetime.current = abort;
401
+ setItems([]);
402
+ setEditing(null);
403
+ setLoading(true);
404
+ setFailure(null);
405
+ load(abort.signal).then((value) => {
406
+ if (!abort.signal.aborted) setItems(value.connectors);
407
+ }).catch(async (error) => {
408
+ const message = await failureMessage(error);
409
+ if (!abort.signal.aborted) setFailure(message);
410
+ }).finally(() => {
411
+ if (!abort.signal.aborted) setLoading(false);
412
+ });
413
+ return () => abort.abort();
414
+ }, [load]);
415
+ const visible = useMemo(() => {
416
+ const result = items.map((item) => ({ ...item, active: sessionId ? item.active : Boolean(pending?.has(item.name)) }));
417
+ if (!sessionId) {
418
+ for (const name of pending ?? []) if (isLocalConnectorName(name) && !result.some((item) => item.name === name)) result.push({ name, display_name: name.split(".").slice(2).join("."), description: "\u8FDE\u63A5\u5668\u5DF2\u79FB\u9664\u6216\u6682\u4E0D\u53EF\u7528\uFF0C\u53EF\u53D6\u6D88\u9009\u62E9\u540E\u7EE7\u7EED\u3002", source: name.startsWith("connector.builtin.") ? "builtin" : "personal", operations: 0, available: false, active: true, connection: { status: "disconnected", revision: 0, account_label: "", verified_at: "" } });
419
+ }
420
+ return result;
421
+ }, [items, pending, sessionId]);
422
+ const selected = useRef(onSelectedChange);
423
+ selected.current = onSelectedChange;
424
+ useEffect(() => {
425
+ selected.current?.(visible.filter((item) => item.active));
426
+ }, [visible]);
427
+ const matching = visible.filter((item) => `${item.display_name} ${item.description}`.toLowerCase().includes(query.trim().toLowerCase()));
428
+ return /* @__PURE__ */ jsxs("div", { className: catalog ? "grid gap-4 sm:grid-cols-2 xl:grid-cols-3" : void 0, children: [
429
+ !catalog ? /* @__PURE__ */ jsx("div", { className: "px-3 pt-1 pb-0.5 text-[10px] text-[hsl(var(--muted-foreground))]", children: "\u8FDE\u63A5\u5668" }) : null,
430
+ loading ? /* @__PURE__ */ jsx("p", { className: "px-3 py-2 text-xs text-[hsl(var(--muted-foreground))]", children: "\u6B63\u5728\u8BFB\u53D6\u8FDE\u63A5\u5668\u2026" }) : null,
431
+ !loading && !failure && matching.length === 0 ? /* @__PURE__ */ jsx("p", { className: "px-3 py-2 text-xs text-[hsl(var(--muted-foreground))]", children: query.trim() ? "\u6CA1\u6709\u5339\u914D\u7684\u8FDE\u63A5\u5668" : "\u6682\u65E0\u8FDE\u63A5\u5668" }) : null,
432
+ matching.map((item) => {
433
+ const connected = item.connection.status === "connected";
434
+ const label = item.display_name || item.name;
435
+ const ConnectIcon = connected ? RefreshCw : Plug;
436
+ const connectionClass = `${actionClass} ${!connected ? "border-transparent bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))] hover:bg-[hsl(var(--primary)/0.9)]" : ""}`;
437
+ const connectAction = /* @__PURE__ */ jsxs("button", { type: "button", disabled: busy || item.available === false, className: connectionClass, onClick: () => {
438
+ setFailure(null);
439
+ setEditing(item);
440
+ }, children: [
441
+ /* @__PURE__ */ jsx(ConnectIcon, { size: 14, "aria-hidden": "true" }),
442
+ ["device", "managed"].includes(item.authorization?.type ?? "") ? "\u7BA1\u7406\u6388\u6743" : connected ? "\u7BA1\u7406\u8FDE\u63A5" : "\u8FDE\u63A5"
443
+ ] });
444
+ const useAction = onUse && (item.active || connected && item.operations > 0) ? /* @__PURE__ */ jsxs("button", { type: "button", disabled: busy || Boolean(disabledReason), title: disabledReason ?? void 0, className: actionClass, onClick: async () => {
445
+ const scope = lifetime.current;
446
+ setBusy(true);
447
+ setFailure(null);
448
+ try {
449
+ await onUse(item.name, label, !item.active, item.icon ?? null);
450
+ if (sessionId) await reload();
451
+ } catch (error) {
452
+ const message = await failureMessage(error);
453
+ if (scope === lifetime.current && !scope?.signal.aborted) setFailure(message);
454
+ } finally {
455
+ if (scope === lifetime.current && !scope?.signal.aborted) setBusy(false);
456
+ }
457
+ }, children: [
458
+ item.active ? /* @__PURE__ */ jsx(Check, { size: 14, "aria-hidden": "true" }) : null,
459
+ item.active ? "\u5DF2\u542F\u7528" : "\u4F7F\u7528"
460
+ ] }) : null;
461
+ return /* @__PURE__ */ jsxs("div", { className: catalog ? "flex flex-col rounded-xl border border-[hsl(var(--border))] bg-[hsl(var(--card))] p-5" : "px-3 py-1.5", children: [
462
+ /* @__PURE__ */ jsxs("div", { className: `flex items-center gap-2 ${catalog ? "text-sm" : "text-[11px]"}`, children: [
463
+ /* @__PURE__ */ jsx(SessionPluginIcon, { client, sessionId: null, plugin: { name: item.name, icon: item.icon ?? null }, size: catalog ? 32 : 20 }),
464
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate font-medium", title: label, children: label }),
465
+ /* @__PURE__ */ jsx("span", { className: "shrink-0 rounded-md bg-[hsl(var(--muted))] px-1.5 py-0.5 text-[10px] text-[hsl(var(--muted-foreground))]", children: item.source === "builtin" ? "\u5185\u7F6E" : "\u6211\u521B\u5EFA\u7684" }),
466
+ !catalog ? /* @__PURE__ */ jsxs(Fragment, { children: [
467
+ connectAction,
468
+ useAction
469
+ ] }) : null
470
+ ] }),
471
+ catalog ? /* @__PURE__ */ jsx("p", { className: "mt-2 flex-1 text-xs leading-5 text-[hsl(var(--muted-foreground))]", children: item.description }) : null,
472
+ /* @__PURE__ */ jsxs("div", { className: "mt-3 flex items-center gap-1.5 text-[11px] text-[hsl(var(--muted-foreground))]", children: [
473
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: `size-1.5 shrink-0 rounded-full ${connected ? "bg-emerald-500" : "bg-[hsl(var(--muted-foreground)/0.4)]"}` }),
474
+ connected ? `\u5DF2\u8FDE\u63A5${item.connection.account_label ? ` \xB7 ${item.connection.account_label}` : ""}${item.name === "connector.builtin.feishu" ? "\uFF0C\u6309\u5DF2\u5F00\u901A\u80FD\u529B\u63D0\u4F9B\u64CD\u4F5C" : item.operations === 0 ? "\uFF0C\u5C1A\u672A\u914D\u7F6E\u4E1A\u52A1\u64CD\u4F5C" : ""}` : item.connection.status === "auth_required" ? "\u9700\u8981\u91CD\u65B0\u8BA4\u8BC1" : "\u672A\u8FDE\u63A5"
475
+ ] }),
476
+ catalog ? /* @__PURE__ */ jsxs("div", { className: "mt-4 flex items-center gap-2 border-t border-[hsl(var(--border))] pt-4", children: [
477
+ connectAction,
478
+ useAction,
479
+ manage ? /* @__PURE__ */ jsx("div", { className: "ml-auto flex items-center gap-1.5", children: item.source === "personal" ? /* @__PURE__ */ jsxs(Fragment, { children: [
480
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: busy, "aria-label": "\u7F16\u8F91", title: "\u7F16\u8F91\u8FDE\u63A5\u5668", className: iconActionClass, onClick: () => onEdit?.(item), children: /* @__PURE__ */ jsx(Pencil, { size: 15, "aria-hidden": "true" }) }),
481
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: busy, "aria-label": "\u5220\u9664", title: "\u5220\u9664\u8FDE\u63A5\u5668", className: `${iconActionClass} text-[hsl(var(--destructive))] hover:border-[hsl(var(--destructive)/0.3)] hover:bg-[hsl(var(--destructive)/0.08)]`, onClick: () => setDeleting(item), children: /* @__PURE__ */ jsx(Trash2, { size: 15, "aria-hidden": "true" }) })
482
+ ] }) : null }) : null
483
+ ] }) : null
484
+ ] }, item.name);
485
+ }),
486
+ deleting ? /* @__PURE__ */ jsxs("dialog", { ref: deleteDialog, onCancel: (event) => {
487
+ event.preventDefault();
488
+ if (!busy) setDeleting(null);
489
+ }, "aria-label": "\u5220\u9664\u8FDE\u63A5\u5668", className: "fixed inset-0 z-50 m-auto w-[min(420px,calc(100%_-_32px))] rounded-xl border border-[hsl(var(--border))] bg-[hsl(var(--popover))] p-5 text-[hsl(var(--popover-foreground))] shadow-xl", children: [
490
+ /* @__PURE__ */ jsxs("p", { className: "text-sm", children: [
491
+ "\u5220\u9664\u300C",
492
+ deleting.display_name || deleting.name,
493
+ "\u300D\u53CA\u5176\u8FDE\u63A5\u4FE1\u606F\uFF1F\u9700\u8981\u4F7F\u7528\u65F6\u53EF\u4EE5\u91CD\u65B0\u521B\u5EFA\u3002"
494
+ ] }),
495
+ /* @__PURE__ */ jsxs("div", { className: "mt-4 flex justify-end gap-3", children: [
496
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: busy, className: actionClass, onClick: () => setDeleting(null), children: "\u53D6\u6D88" }),
497
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: busy, className: `${actionClass} border-transparent bg-[hsl(var(--destructive))] text-white hover:bg-[hsl(var(--destructive)/0.9)]`, onClick: async () => {
498
+ setBusy(true);
499
+ try {
500
+ await client.connectors.delete(deleting.name);
501
+ setDeleting(null);
502
+ await reload();
503
+ } catch (error) {
504
+ setFailure(await failureMessage(error));
505
+ setDeleting(null);
506
+ } finally {
507
+ setBusy(false);
508
+ }
509
+ }, children: busy ? "\u6B63\u5728\u5220\u9664\u2026" : "\u786E\u8BA4\u5220\u9664" })
510
+ ] })
511
+ ] }) : null,
512
+ failure ? /* @__PURE__ */ jsxs("div", { role: "alert", className: "px-3 py-1 text-xs text-[hsl(var(--destructive))]", children: [
513
+ failure,
514
+ /* @__PURE__ */ jsx("button", { type: "button", className: `${actionClass} ml-2`, onClick: () => {
515
+ void reload().catch(() => setFailure("\u8BFB\u53D6\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"));
516
+ }, children: "\u91CD\u8BD5" })
517
+ ] }) : null,
518
+ editing && ["device", "managed"].includes(editing.authorization?.type ?? "") ? /* @__PURE__ */ jsx(DeviceDialog, { client, connector: editing, onChanged: reload, onClose: () => {
519
+ setEditing(null);
520
+ void reload();
521
+ } }, editing.name) : editing?.authorization?.type === "browser" ? /* @__PURE__ */ jsx(BrowserConnectionDialog, { connector: editing, client, name: editing.name, label: editing.display_name || editing.name, onClose: () => {
522
+ setEditing(null);
523
+ void reload().catch(() => setFailure("\u8BFB\u53D6\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"));
524
+ } }, editing.name) : editing ? /* @__PURE__ */ jsx(ConnectionDialog, { client, onChanged: reload, connector: editing, onClose: () => setEditing(null), onConnected: async () => {
525
+ const scope = lifetime.current;
526
+ await reload();
527
+ if (scope !== lifetime.current || scope?.signal.aborted) return;
528
+ if (onUse && editing.operations > 0 && !disabledReason) {
529
+ await onUse(editing.name, editing.display_name || editing.name, true);
530
+ if (sessionId) await reload();
531
+ }
532
+ } }, editing.name) : null
533
+ ] });
534
+ }
535
+
536
+ // src/components/ConnectorPanel.tsx
537
+ import { isLocalConnectorName as isLocalConnectorName2 } from "@blade-hq/agent-client/internal";
538
+ import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
539
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
540
+ function PanelDivider() {
541
+ return /* @__PURE__ */ jsx2("div", { className: "my-1 border-[hsl(var(--border))] border-t" });
542
+ }
543
+ function PanelTitle({ children }) {
544
+ return /* @__PURE__ */ jsx2("div", { className: "px-3 pt-1 pb-0.5 text-[10px] text-[hsl(var(--muted-foreground))]", children });
545
+ }
546
+ function ConnectorPanel({
547
+ client,
548
+ sessionId,
549
+ pendingPlugins,
550
+ onPendingPluginsChange,
551
+ pendingDisabledReason,
552
+ onPluginsChanged,
553
+ onSelectedChange,
554
+ renderComputerSection,
555
+ renderPhoneSection,
556
+ renderExternalAccounts,
557
+ renderFooterActions,
558
+ className
559
+ }) {
560
+ const [query, setQuery] = useState2("");
561
+ const [selectedConnectors, setSelectedConnectors] = useState2([]);
562
+ const [pendingCatalog, setPendingCatalog] = useState2(null);
563
+ const [pendingLoading, setPendingLoading] = useState2(false);
564
+ const [pendingError, setPendingError] = useState2(false);
565
+ const activation = useSessionPluginActivation({
566
+ client,
567
+ sessionId: sessionId ?? "",
568
+ onChange: onPluginsChanged
569
+ });
570
+ const { reload, items: sessionItems } = activation;
571
+ useEffect2(() => {
572
+ if (sessionId) reload();
573
+ }, [reload, sessionId]);
574
+ const loadPendingCatalog = useCallback2(async () => {
575
+ setPendingLoading(true);
576
+ setPendingError(false);
577
+ try {
578
+ const { plugins } = await client.plugins.catalog();
579
+ setPendingCatalog(plugins);
580
+ } catch {
581
+ setPendingError(true);
582
+ } finally {
583
+ setPendingLoading(false);
584
+ }
585
+ }, [client]);
586
+ useEffect2(() => {
587
+ if (sessionId) return;
588
+ void loadPendingCatalog();
589
+ }, [loadPendingCatalog, sessionId]);
590
+ const selected = useMemo2(
591
+ () => new Set((pendingPlugins ?? []).map((item) => item.name)),
592
+ [pendingPlugins]
593
+ );
594
+ const items = useMemo2(() => {
595
+ if (sessionId) return sessionItems;
596
+ return catalogToConnectorItems(pendingCatalog ?? []).map((item) => ({
597
+ ...item,
598
+ active: selected.has(item.name)
599
+ }));
600
+ }, [pendingCatalog, selected, sessionId, sessionItems]);
601
+ const visibleItems = useMemo2(
602
+ () => sessionId ? filterConnectorItems(items, query) : filterConnectorItems(items, query).map((item) => ({ ...item, config: void 0 })),
603
+ [items, query, sessionId]
604
+ );
605
+ const togglePending = useCallback2((item, next) => {
606
+ const kept = (pendingPlugins ?? []).filter((entry) => entry.name !== item.name);
607
+ onPendingPluginsChange?.(next ? [...kept, selectionFromItem(item)] : kept);
608
+ }, [onPendingPluginsChange, pendingPlugins]);
609
+ const toggle = useCallback2((item, next) => {
610
+ if (sessionId) activation.toggle(item, next);
611
+ else togglePending(item, next);
612
+ }, [activation, sessionId, togglePending]);
613
+ const selectedItems = useMemo2(
614
+ () => [
615
+ ...items.filter((item) => item.active && !isLocalConnectorName2(item.name)),
616
+ ...selectedConnectors.map((item) => ({
617
+ name: item.name,
618
+ display_name: item.display_name,
619
+ icon: item.icon ?? null,
620
+ iconSource: "account",
621
+ installed: true,
622
+ active: true,
623
+ status: "valid",
624
+ projected: false,
625
+ connector: true
626
+ }))
627
+ ],
628
+ [items, selectedConnectors]
629
+ );
630
+ const onSelectedChangeRef = useRef2(onSelectedChange);
631
+ onSelectedChangeRef.current = onSelectedChange;
632
+ const latestSelected = useRef2(selectedItems);
633
+ latestSelected.current = selectedItems;
634
+ const reportSelected = useCallback2(() => {
635
+ onSelectedChangeRef.current?.(latestSelected.current);
636
+ }, []);
637
+ const selectedNames = selectedItems.map((item) => item.name).join("\0");
638
+ useEffect2(reportSelected, [reportSelected, selectedNames]);
639
+ const failed = sessionId ? activation.listError : pendingError;
640
+ return /* @__PURE__ */ jsxs2("div", { className, children: [
641
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-2 border-[hsl(var(--border))] border-b px-3 py-2", children: [
642
+ /* @__PURE__ */ jsx2(Search, { size: 12, className: "shrink-0 text-[hsl(var(--muted-foreground))]", "aria-hidden": "true" }),
643
+ /* @__PURE__ */ jsx2(
644
+ "input",
645
+ {
646
+ value: query,
647
+ onChange: (event) => setQuery(event.target.value),
648
+ placeholder: "\u641C\u7D22\u8FDE\u63A5\u5668",
649
+ "aria-label": "\u641C\u7D22\u8FDE\u63A5\u5668",
650
+ className: "min-w-0 flex-1 bg-transparent text-[11px] outline-none placeholder:text-[hsl(var(--muted-foreground))]"
651
+ }
652
+ )
653
+ ] }),
654
+ renderComputerSection ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
655
+ /* @__PURE__ */ jsx2(PanelTitle, { children: "\u7535\u8111" }),
656
+ renderComputerSection(query)
657
+ ] }) : null,
658
+ renderPhoneSection ? renderPhoneSection(query) : null,
659
+ /* @__PURE__ */ jsx2(PanelDivider, {}),
660
+ /* @__PURE__ */ jsx2(
661
+ AccountConnectors,
662
+ {
663
+ client,
664
+ query,
665
+ sessionId,
666
+ pending: selected,
667
+ onSelectedChange: setSelectedConnectors,
668
+ disabledReason: pendingDisabledReason,
669
+ onUse: async (name, label, enabled, icon) => {
670
+ if (sessionId) {
671
+ const result = await client.sessions.setSessionPluginActivation(sessionId, name, enabled);
672
+ onPluginsChanged?.(result.plugin);
673
+ } else {
674
+ const kept = (pendingPlugins ?? []).filter((item) => item.name !== name);
675
+ onPendingPluginsChange?.(enabled ? [...kept, { name, displayName: label, icon: icon ?? null, iconSource: "account" }] : kept);
676
+ }
677
+ }
678
+ }
679
+ ),
680
+ /* @__PURE__ */ jsx2(PanelDivider, {}),
681
+ /* @__PURE__ */ jsx2(PanelTitle, { children: "\u63D2\u4EF6" }),
682
+ !sessionId ? /* @__PURE__ */ jsx2("div", { className: "px-3 pb-0.5 text-[10px] text-[hsl(var(--muted-foreground))]", children: "\u5148\u9009\u4E2D\uFF0C\u53D1\u9001\u8FD9\u6761\u6D88\u606F\u65F6\u4F1A\u4E00\u5E76\u542F\u7528" }) : null,
683
+ (sessionId ? activation.loading : pendingLoading) && visibleItems.length === 0 ? /* @__PURE__ */ jsxs2("div", { className: "px-3 py-1.5 text-[11px] text-[hsl(var(--muted-foreground))]", children: [
684
+ /* @__PURE__ */ jsx2(LoaderCircle, { size: 12, className: "mr-1 inline animate-spin" }),
685
+ "\u6B63\u5728\u83B7\u53D6\u63D2\u4EF6\u2026"
686
+ ] }) : null,
687
+ failed ? /* @__PURE__ */ jsx2(
688
+ "button",
689
+ {
690
+ type: "button",
691
+ onClick: () => sessionId ? reload() : void loadPendingCatalog(),
692
+ className: "px-3 py-1.5 text-left text-[11px] text-[hsl(var(--muted-foreground))] underline",
693
+ children: "\u63D2\u4EF6\u5217\u8868\u6682\u4E0D\u53EF\u7528\uFF0C\u70B9\u51FB\u91CD\u8BD5"
694
+ }
695
+ ) : null,
696
+ /* @__PURE__ */ jsx2(
697
+ PluginConnectorList,
698
+ {
699
+ client,
700
+ sessionId,
701
+ items: visibleItems.filter((item) => !isLocalConnectorName2(item.name)),
702
+ inFlight: activation.inFlight,
703
+ busy: sessionId ? activation.busy : pendingLoading,
704
+ mutationError: sessionId ? activation.mutationError : false,
705
+ onToggle: toggle,
706
+ onRetry: activation.retry,
707
+ onEditConfig: activation.editConfig,
708
+ configuring: sessionId ? activation.configuring : null,
709
+ onConfigSaved: activation.onConfigSaved,
710
+ onConfigClose: activation.onConfigClose,
711
+ disabledReason: sessionId ? null : pendingDisabledReason,
712
+ unavailableText: failed ? null : query.trim() ? "\u6CA1\u6709\u5339\u914D\u7684\u63D2\u4EF6" : null,
713
+ emptyText: sessionId ? "\u5C1A\u672A\u5B89\u88C5\u63D2\u4EF6" : "\u5C1A\u672A\u5B89\u88C5\u63D2\u4EF6\uFF0C\u53BB\u5E94\u7528\u5E02\u573A\u6DFB\u52A0\u4E00\u4E2A",
714
+ draft: !sessionId
715
+ }
716
+ ),
717
+ renderExternalAccounts ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
718
+ /* @__PURE__ */ jsx2(PanelDivider, {}),
719
+ /* @__PURE__ */ jsx2(PanelTitle, { children: "\u5916\u90E8\u8D26\u53F7" }),
720
+ renderExternalAccounts(query)
721
+ ] }) : null,
722
+ renderFooterActions ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
723
+ /* @__PURE__ */ jsx2(PanelDivider, {}),
724
+ renderFooterActions()
725
+ ] }) : null
726
+ ] });
727
+ }
728
+
729
+ // src/components/PluginTriggerStack.tsx
730
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
731
+ var AVATAR_SIZE = 20;
732
+ function hueOf(name) {
733
+ let hash = 0;
734
+ for (const char of name) hash = (hash * 31 + char.codePointAt(0)) % 1000003;
735
+ return hash % 360;
736
+ }
737
+ var AVATAR_PALETTE = [
738
+ "bg-violet-100 text-violet-800 dark:bg-violet-500/25 dark:text-violet-200",
739
+ "bg-sky-100 text-sky-800 dark:bg-sky-500/25 dark:text-sky-200",
740
+ "bg-emerald-100 text-emerald-800 dark:bg-emerald-500/25 dark:text-emerald-200",
741
+ "bg-amber-100 text-amber-800 dark:bg-amber-500/25 dark:text-amber-200",
742
+ "bg-rose-100 text-rose-800 dark:bg-rose-500/25 dark:text-rose-200",
743
+ "bg-indigo-100 text-indigo-800 dark:bg-indigo-500/25 dark:text-indigo-200",
744
+ "bg-teal-100 text-teal-800 dark:bg-teal-500/25 dark:text-teal-200",
745
+ "bg-fuchsia-100 text-fuchsia-800 dark:bg-fuchsia-500/25 dark:text-fuchsia-200"
746
+ ];
747
+ function PluginTriggerStack({ client, sessionId, summary, className }) {
748
+ if (summary.total === 0) return null;
749
+ const ring = "ring-2 ring-[hsl(var(--background))]";
750
+ return /* @__PURE__ */ jsxs3("span", { className: `flex items-center -space-x-1 ${className ?? ""}`, children: [
751
+ summary.visible.map((item) => {
752
+ const label = item.displayName?.trim() || item.name;
753
+ const tone = AVATAR_PALETTE[hueOf(item.name) % AVATAR_PALETTE.length];
754
+ return item.icon ? /* @__PURE__ */ jsx3(
755
+ SessionPluginIcon,
756
+ {
757
+ client,
758
+ sessionId: item.iconSource === "account" ? null : sessionId,
759
+ plugin: item,
760
+ size: AVATAR_SIZE,
761
+ shape: "circle",
762
+ className: ring
763
+ },
764
+ item.name
765
+ ) : /* @__PURE__ */ jsx3(
766
+ "span",
767
+ {
768
+ title: label,
769
+ className: `flex shrink-0 items-center justify-center rounded-full font-semibold text-[11px] ${tone} ${ring}`,
770
+ style: { width: AVATAR_SIZE, height: AVATAR_SIZE },
771
+ children: Array.from(label.trim())[0]?.toUpperCase() ?? "?"
772
+ },
773
+ item.name
774
+ );
775
+ }),
776
+ summary.overflow > 0 ? /* @__PURE__ */ jsxs3(
777
+ "span",
778
+ {
779
+ className: `flex shrink-0 items-center justify-center rounded-full bg-[hsl(var(--muted))] font-medium text-[hsl(var(--muted-foreground))] text-[10px] ${ring}`,
780
+ style: { width: AVATAR_SIZE, height: AVATAR_SIZE },
781
+ children: [
782
+ "+",
783
+ summary.overflow
784
+ ]
785
+ }
786
+ ) : null
787
+ ] });
788
+ }
789
+
790
+ export {
791
+ composerChannels,
792
+ useComposerChannels,
793
+ skillDisplayName,
794
+ backgroundTaskDismissals,
795
+ useDismissedBackgroundTasks,
796
+ visibleSkills,
797
+ visibleSkillIds,
798
+ selectionFromItem,
799
+ TRIGGER_ICON_LIMIT,
800
+ triggerSummary,
801
+ AccountConnectors,
802
+ ConnectorPanel,
803
+ PluginTriggerStack
804
+ };
805
+ //# sourceMappingURL=chunk-JBVJMUJA.js.map