@solidxai/core-ui 0.1.22-beta.4 → 0.1.22

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 (108) hide show
  1. package/dist/adapters/auth/adminEmbedSession.d.ts +16 -0
  2. package/dist/adapters/auth/adminEmbedSession.d.ts.map +1 -0
  3. package/dist/adapters/auth/adminEmbedSession.js +72 -0
  4. package/dist/adapters/auth/adminEmbedSession.js.map +1 -0
  5. package/dist/adapters/auth/adminEmbedSession.ts +67 -0
  6. package/dist/adapters/auth/getSession.d.ts.map +1 -1
  7. package/dist/adapters/auth/getSession.js +4 -1
  8. package/dist/adapters/auth/getSession.js.map +1 -1
  9. package/dist/adapters/auth/getSession.ts +4 -1
  10. package/dist/adapters/auth/storage.d.ts +1 -0
  11. package/dist/adapters/auth/storage.d.ts.map +1 -1
  12. package/dist/adapters/auth/storage.js +9 -3
  13. package/dist/adapters/auth/storage.js.map +1 -1
  14. package/dist/adapters/auth/storage.ts +10 -2
  15. package/dist/components/common/Link.d.ts.map +1 -1
  16. package/dist/components/common/Link.js +3 -2
  17. package/dist/components/common/Link.js.map +1 -1
  18. package/dist/components/common/Link.tsx +3 -2
  19. package/dist/components/core/form/SolidFormFooter.js +2 -2
  20. package/dist/components/core/form/SolidFormFooter.js.map +1 -1
  21. package/dist/components/core/form/SolidFormFooter.tsx +2 -2
  22. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.d.ts.map +1 -1
  23. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.js +17 -15
  24. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.js.map +1 -1
  25. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.tsx +7 -5
  26. package/dist/components/core/form/fields/relations/SolidRelationOneToManyField.d.ts.map +1 -1
  27. package/dist/components/core/form/fields/relations/SolidRelationOneToManyField.js +13 -11
  28. package/dist/components/core/form/fields/relations/SolidRelationOneToManyField.js.map +1 -1
  29. package/dist/components/core/form/fields/relations/SolidRelationOneToManyField.tsx +8 -6
  30. package/dist/components/core/solid-agent/browser/AgentBrowser.module.css +170 -0
  31. package/dist/components/core/solid-agent/browser/AgentBrowserScreen.d.ts +13 -0
  32. package/dist/components/core/solid-agent/browser/AgentBrowserScreen.d.ts.map +1 -0
  33. package/dist/components/core/solid-agent/browser/AgentBrowserScreen.js +138 -0
  34. package/dist/components/core/solid-agent/browser/AgentBrowserScreen.js.map +1 -0
  35. package/dist/components/core/solid-agent/browser/AgentBrowserScreen.tsx +162 -0
  36. package/dist/components/core/solid-agent/browser/DefaultAgentBrowserPanelWidget.d.ts +9 -0
  37. package/dist/components/core/solid-agent/browser/DefaultAgentBrowserPanelWidget.d.ts.map +1 -0
  38. package/dist/components/core/solid-agent/browser/DefaultAgentBrowserPanelWidget.js +59 -0
  39. package/dist/components/core/solid-agent/browser/DefaultAgentBrowserPanelWidget.js.map +1 -0
  40. package/dist/components/core/solid-agent/browser/DefaultAgentBrowserPanelWidget.tsx +159 -0
  41. package/dist/components/core/solid-agent/browser/useAgentBrowser.d.ts +6 -0
  42. package/dist/components/core/solid-agent/browser/useAgentBrowser.d.ts.map +1 -0
  43. package/dist/components/core/solid-agent/browser/useAgentBrowser.js +37 -0
  44. package/dist/components/core/solid-agent/browser/useAgentBrowser.js.map +1 -0
  45. package/dist/components/core/solid-agent/browser/useAgentBrowser.ts +38 -0
  46. package/dist/components/core/solid-agent/client/agentBrowser.d.ts +128 -0
  47. package/dist/components/core/solid-agent/client/agentBrowser.d.ts.map +1 -0
  48. package/dist/components/core/solid-agent/client/agentBrowser.js +474 -0
  49. package/dist/components/core/solid-agent/client/agentBrowser.js.map +1 -0
  50. package/dist/components/core/solid-agent/client/agentBrowser.ts +342 -0
  51. package/dist/components/core/solid-agent/toolFiles.d.ts +13 -0
  52. package/dist/components/core/solid-agent/toolFiles.d.ts.map +1 -0
  53. package/dist/components/core/solid-agent/toolFiles.js +54 -0
  54. package/dist/components/core/solid-agent/toolFiles.js.map +1 -0
  55. package/dist/components/core/solid-agent/toolFiles.ts +42 -0
  56. package/dist/components/core/solid-agent/widgets/AgentToolFiles.d.ts +9 -0
  57. package/dist/components/core/solid-agent/widgets/AgentToolFiles.d.ts.map +1 -0
  58. package/dist/components/core/solid-agent/widgets/AgentToolFiles.js +37 -0
  59. package/dist/components/core/solid-agent/widgets/AgentToolFiles.js.map +1 -0
  60. package/dist/components/core/solid-agent/widgets/AgentToolFiles.tsx +46 -0
  61. package/dist/components/core/solid-agent/widgets/SolidQuestionChatWidget.d.ts.map +1 -1
  62. package/dist/components/core/solid-agent/widgets/SolidQuestionChatWidget.js +3 -2
  63. package/dist/components/core/solid-agent/widgets/SolidQuestionChatWidget.js.map +1 -1
  64. package/dist/components/core/solid-agent/widgets/SolidQuestionChatWidget.tsx +3 -2
  65. package/dist/dummy.d.ts +2 -0
  66. package/dist/dummy.d.ts.map +1 -0
  67. package/dist/dummy.js +3 -0
  68. package/dist/dummy.js.map +1 -0
  69. package/dist/dummy.ts +2 -0
  70. package/dist/helpers/modelViewPersistence.d.ts +1 -1
  71. package/dist/helpers/modelViewPersistence.d.ts.map +1 -1
  72. package/dist/helpers/modelViewPersistence.js +5 -4
  73. package/dist/helpers/modelViewPersistence.js.map +1 -1
  74. package/dist/helpers/modelViewPersistence.ts +6 -4
  75. package/dist/hooks/useRouter.d.ts.map +1 -1
  76. package/dist/hooks/useRouter.js +5 -3
  77. package/dist/hooks/useRouter.js.map +1 -1
  78. package/dist/hooks/useRouter.ts +5 -3
  79. package/dist/resources/solid-custom.css +14 -1
  80. package/dist/routes/AppEventListener.js +1 -1
  81. package/dist/routes/AppEventListener.js.map +1 -1
  82. package/dist/routes/AppEventListener.tsx +1 -1
  83. package/dist/routes/pages/admin/core/AgentDeploymentPanel.d.ts +3 -4
  84. package/dist/routes/pages/admin/core/AgentDeploymentPanel.d.ts.map +1 -1
  85. package/dist/routes/pages/admin/core/AgentDeploymentPanel.js +13 -83
  86. package/dist/routes/pages/admin/core/AgentDeploymentPanel.js.map +1 -1
  87. package/dist/routes/pages/admin/core/AgentDeploymentPanel.tsx +22 -43
  88. package/dist/routes/pages/admin/core/AgentJobsInboxPage.d.ts.map +1 -1
  89. package/dist/routes/pages/admin/core/AgentJobsInboxPage.js +157 -34
  90. package/dist/routes/pages/admin/core/AgentJobsInboxPage.js.map +1 -1
  91. package/dist/routes/pages/admin/core/AgentJobsInboxPage.module.css +88 -12
  92. package/dist/routes/pages/admin/core/AgentJobsInboxPage.tsx +238 -26
  93. package/dist/routes/pages/admin/core/AgentRegistryEditorPage.css +6 -0
  94. package/dist/routes/pages/admin/core/AgentRegistryEditorPage.d.ts.map +1 -1
  95. package/dist/routes/pages/admin/core/AgentRegistryEditorPage.js +56 -49
  96. package/dist/routes/pages/admin/core/AgentRegistryEditorPage.js.map +1 -1
  97. package/dist/routes/pages/admin/core/AgentRegistryEditorPage.tsx +13 -6
  98. package/dist/routes/pages/embed/AdminEmbedPage.d.ts +7 -0
  99. package/dist/routes/pages/embed/AdminEmbedPage.d.ts.map +1 -0
  100. package/dist/routes/pages/embed/AdminEmbedPage.js +104 -0
  101. package/dist/routes/pages/embed/AdminEmbedPage.js.map +1 -0
  102. package/dist/routes/pages/embed/AdminEmbedPage.module.css +9 -0
  103. package/dist/routes/pages/embed/AdminEmbedPage.tsx +128 -0
  104. package/dist/routes/solidRoutes.d.ts.map +1 -1
  105. package/dist/routes/solidRoutes.js +2 -0
  106. package/dist/routes/solidRoutes.js.map +1 -1
  107. package/dist/routes/solidRoutes.tsx +2 -0
  108. package/package.json +1 -1
@@ -0,0 +1,342 @@
1
+ import type { AgentAction, AgentBrowserInputEvent } from "../types";
2
+
3
+ /**
4
+ * The live view of a session's browser (AgentHub browser tools).
5
+ *
6
+ * Kept outside Redux: frames are large base64 JPEGs at several per second. Status, tabs and control
7
+ * state form a small immutable view for React (`subscribe`/`getView`, made for useSyncExternalStore);
8
+ * frames go to `onFrame` listeners that draw them straight onto a canvas.
9
+ *
10
+ * The preview is a per-socket subscription. Viewers call `watch()` while they show the screen; the
11
+ * channel asks for the preview once the browser is live and stops it shortly after the last viewer
12
+ * leaves. A reconnect or a session switch (`sessionStarted`) subscribes again.
13
+ */
14
+
15
+ export type AgentBrowserState = "none" | "starting" | "live" | "state_saved" | "released";
16
+ export type AgentBrowserControlMode = "agent" | "human";
17
+ export type AgentBrowserTab = { tab: string; url: string | null; title: string | null };
18
+ export type AgentBrowserControl = {
19
+ mode: AgentBrowserControlMode;
20
+ /** The user asked for the browser and waits for the agent's current step to finish. */
21
+ pending: boolean;
22
+ /** Why the agent handed the browser over (browser_handoff). */
23
+ reason: string | null;
24
+ /** ISO time when control returns to the agent automatically. */
25
+ expiresAt: string | null;
26
+ };
27
+ export type AgentBrowserError = { code: string; message: string; at: number };
28
+
29
+ export type AgentBrowserView = {
30
+ sessionId: string | null;
31
+ /** False once the agent said it has no browser tools. */
32
+ available: boolean;
33
+ state: AgentBrowserState;
34
+ viewport: { width: number; height: number };
35
+ url: string | null;
36
+ title: string | null;
37
+ tabs: AgentBrowserTab[];
38
+ activeTab: string | null;
39
+ control: AgentBrowserControl;
40
+ /** When the agent last reopened a saved browser session (sign-ins and cookies restored). */
41
+ restoredAt: number | null;
42
+ /** The preview subscription is active on this socket. */
43
+ watching: boolean;
44
+ hasFrame: boolean;
45
+ error: AgentBrowserError | null;
46
+ /** False when the browser is only shown: the server sent browser_status with control false, so there is no "Take control". */
47
+ controllable: boolean;
48
+ };
49
+
50
+ /** `seq` grows with every frame the channel accepts, also across preview restarts and reconnects. */
51
+ export type AgentBrowserFrame = { tab: string | null; url: string | null; title: string | null; format: string; data: string; seq: number };
52
+
53
+ /** What the channel needs from AgentSocket. */
54
+ export type AgentBrowserSocket = {
55
+ readonly currentSessionId: string | null;
56
+ sendNow(action: AgentAction): boolean;
57
+ };
58
+
59
+ const STATES: readonly AgentBrowserState[] = ["none", "starting", "live", "state_saved", "released"];
60
+ const DEFAULT_VIEWPORT = { width: 1280, height: 800 };
61
+ /** Moving the screen between the side pane and the large view must not drop the preview. */
62
+ const STOP_DELAY_MS = 800;
63
+ const OFFLINE: Omit<AgentBrowserError, "at"> = { code: "offline", message: "The chat is not connected to the agent. Try again once it reconnects." };
64
+
65
+ function initialView(sessionId: string | null, available = true): AgentBrowserView {
66
+ return {
67
+ sessionId,
68
+ available,
69
+ state: "none",
70
+ viewport: DEFAULT_VIEWPORT,
71
+ url: null,
72
+ title: null,
73
+ tabs: [],
74
+ activeTab: null,
75
+ control: { mode: "agent", pending: false, reason: null, expiresAt: null },
76
+ restoredAt: null,
77
+ watching: false,
78
+ hasFrame: false,
79
+ error: null,
80
+ controllable: true,
81
+ };
82
+ }
83
+
84
+ const text = (value: unknown): string | null => (typeof value === "string" && value ? value : null);
85
+
86
+ /** Whether the panel should show: the browser runs, or the user has (or is offered) it. */
87
+ export function isBrowserActive(view: AgentBrowserView): boolean {
88
+ return view.available && (view.state === "live" || view.state === "starting" || view.control.mode === "human");
89
+ }
90
+
91
+ type Timers = { setTimeout: (callback: () => void, ms: number) => unknown; clearTimeout: (handle: any) => void; now: () => number };
92
+
93
+ export class AgentBrowserChannel {
94
+ private view: AgentBrowserView = initialView(null);
95
+ private listeners = new Set<() => void>();
96
+ private frameListeners = new Set<(frame: AgentBrowserFrame) => void>();
97
+ private frame: AgentBrowserFrame | null = null;
98
+ private frameCount = 0;
99
+ /** The relay's number of the last frame of the current subscription; a new subscription counts from 1 again. */
100
+ private streamSeq = 0;
101
+ /** This socket's number for its current subscription, which the runtime echoes on the frames. */
102
+ private stream = 0;
103
+ private watchers = 0;
104
+ /** The session whose preview this socket subscribed to, if any. */
105
+ private previewSession: string | null = null;
106
+ private stopTimer: unknown = null;
107
+ private readonly socket: AgentBrowserSocket;
108
+ private readonly timers: Timers;
109
+
110
+ constructor(socket: AgentBrowserSocket, timers?: Partial<Timers>) {
111
+ this.socket = socket;
112
+ this.timers = {
113
+ setTimeout: timers?.setTimeout ?? ((callback, ms) => setTimeout(callback, ms)),
114
+ clearTimeout: timers?.clearTimeout ?? ((handle) => clearTimeout(handle)),
115
+ now: timers?.now ?? (() => Date.now()),
116
+ };
117
+ }
118
+
119
+ readonly getView = (): AgentBrowserView => this.view;
120
+
121
+ readonly subscribe = (listener: () => void) => {
122
+ this.listeners.add(listener);
123
+ return () => { this.listeners.delete(listener); };
124
+ };
125
+
126
+ onFrame(listener: (frame: AgentBrowserFrame) => void) {
127
+ this.frameListeners.add(listener);
128
+ return () => { this.frameListeners.delete(listener); };
129
+ }
130
+
131
+ get latestFrame(): AgentBrowserFrame | null {
132
+ return this.frame;
133
+ }
134
+
135
+ /** Applies one inbound frame. Returns false for frames that are not about the browser. */
136
+ handle(eventType: string, data: Record<string, any>): boolean {
137
+ switch (eventType) {
138
+ case "browser_status": this.applyStatus(data); return true;
139
+ case "browser_frame": this.applyFrame(data); return true;
140
+ case "browser_tabs": this.applyTabs(data); return true;
141
+ case "browser_control_state": this.applyControl(data); return true;
142
+ case "browser_error": this.applyError(data); return true;
143
+ default: return false;
144
+ }
145
+ }
146
+
147
+ /** The socket (re)confirmed a session. A new socket has no preview yet; another session starts empty. */
148
+ sessionStarted(sessionId: string | null) {
149
+ this.previewSession = null;
150
+ this.streamSeq = 0;
151
+ if (sessionId !== this.view.sessionId) {
152
+ this.frame = null;
153
+ this.setView(initialView(sessionId, this.view.available));
154
+ } else if (this.view.watching) {
155
+ this.setView({ ...this.view, watching: false });
156
+ }
157
+ this.syncPreview();
158
+ }
159
+
160
+ /** Forget the current session's browser (new chat, switched conversation, expired session). */
161
+ reset() {
162
+ this.cancelStop();
163
+ if (this.previewSession) this.socket.sendNow({ action: "browser_preview_stop", session_id: this.previewSession });
164
+ this.previewSession = null;
165
+ this.streamSeq = 0;
166
+ this.frame = null;
167
+ this.setView(initialView(null, this.view.available));
168
+ }
169
+
170
+ /** Keep the preview running while the returned release function has not been called. */
171
+ watch(): () => void {
172
+ this.watchers += 1;
173
+ this.cancelStop();
174
+ this.syncPreview();
175
+ let released = false;
176
+ return () => {
177
+ if (released) return;
178
+ released = true;
179
+ this.watchers -= 1;
180
+ if (this.watchers > 0) return;
181
+ this.cancelStop();
182
+ this.stopTimer = this.timers.setTimeout(() => {
183
+ this.stopTimer = null;
184
+ this.syncPreview();
185
+ }, STOP_DELAY_MS);
186
+ };
187
+ }
188
+
189
+ requestControl(): boolean {
190
+ return this.sendForSession((session_id) => ({ action: "browser_control_request", session_id }));
191
+ }
192
+
193
+ /** Give the browser back, or continue a handoff without taking it. The note goes to the agent. */
194
+ release(note?: string | null): boolean {
195
+ const trimmed = typeof note === "string" ? note.trim() : "";
196
+ return this.sendForSession((session_id) => ({ action: "browser_control_release", session_id, note: trimmed || null }));
197
+ }
198
+
199
+ /** Forwards one input event while the user has the browser. Dropped (false) otherwise. */
200
+ sendInput(event: AgentBrowserInputEvent): boolean {
201
+ if (this.view.control.mode !== "human") return false;
202
+ const sessionId = this.socket.currentSessionId;
203
+ return !!sessionId && this.socket.sendNow({ action: "browser_input", session_id: sessionId, event });
204
+ }
205
+
206
+ navigate(url: string): boolean {
207
+ const target = url.trim();
208
+ if (!target) return false;
209
+ return this.sendInput({ kind: "navigation", url: /^[a-z][a-z\d+.-]*:/i.test(target) ? target : `https://${target}` });
210
+ }
211
+
212
+ navigation(action: "back" | "forward" | "refresh"): boolean {
213
+ return this.sendInput({ kind: "navigation", action });
214
+ }
215
+
216
+ clearError() {
217
+ if (this.view.error) this.setView({ ...this.view, error: null });
218
+ }
219
+
220
+ dispose() {
221
+ this.cancelStop();
222
+ this.listeners.clear();
223
+ this.frameListeners.clear();
224
+ }
225
+
226
+ private sendForSession(build: (sessionId: string) => AgentAction): boolean {
227
+ const sessionId = this.socket.currentSessionId;
228
+ if (sessionId && this.socket.sendNow(build(sessionId))) return true;
229
+ this.setView({ ...this.view, error: { ...OFFLINE, at: this.timers.now() } });
230
+ return false;
231
+ }
232
+
233
+ private wantsPreview() {
234
+ return this.watchers > 0 && isBrowserActive(this.view);
235
+ }
236
+
237
+ private syncPreview() {
238
+ const sessionId = this.socket.currentSessionId;
239
+ if (this.wantsPreview()) {
240
+ if (!sessionId || this.previewSession === sessionId) return;
241
+ this.stream += 1;
242
+ if (this.socket.sendNow({ action: "browser_preview_start", session_id: sessionId, stream: this.stream })) {
243
+ this.previewSession = sessionId;
244
+ this.streamSeq = 0;
245
+ this.setView({ ...this.view, watching: true });
246
+ }
247
+ } else if (this.watchers === 0 && this.previewSession) {
248
+ this.socket.sendNow({ action: "browser_preview_stop", session_id: this.previewSession });
249
+ this.previewSession = null;
250
+ this.streamSeq = 0;
251
+ this.setView({ ...this.view, watching: false });
252
+ }
253
+ }
254
+
255
+ private applyStatus(data: Record<string, any>) {
256
+ const state: AgentBrowserState = STATES.includes(data.state) ? data.state : this.view.state;
257
+ const width = Number(data.viewport?.width);
258
+ const height = Number(data.viewport?.height);
259
+ const ended = state === "none" || state === "released" || state === "state_saved";
260
+ if (ended) this.frame = null;
261
+ this.setView({
262
+ ...this.view,
263
+ state,
264
+ viewport: width > 0 && height > 0 ? { width, height } : this.view.viewport,
265
+ url: text(data.url) ?? (ended ? null : this.view.url),
266
+ title: ended ? null : this.view.title,
267
+ activeTab: text(data.active_tab) ?? this.view.activeTab,
268
+ tabs: ended ? [] : this.view.tabs,
269
+ hasFrame: ended ? false : this.view.hasFrame,
270
+ // Only an explicit "control: false" makes the browser view-only; a server that never sends it keeps control.
271
+ controllable: data.control === false ? false : data.control === true ? true : this.view.controllable,
272
+ control: data.control_mode === "human" || data.control_mode === "agent"
273
+ ? { ...this.view.control, mode: data.control_mode } : this.view.control,
274
+ restoredAt: data.restored === true ? this.timers.now() : this.view.restoredAt,
275
+ });
276
+ this.syncPreview();
277
+ }
278
+
279
+ private applyFrame(data: Record<string, any>) {
280
+ if (typeof data.data !== "string" || !data.data || !this.previewSession) return;
281
+ // A frame still on the way from an earlier subscription carries that subscription's number. Taking its
282
+ // seq would hide the new subscription's frames, which the relay may number from 1 again.
283
+ if (data.stream !== undefined && data.stream !== this.stream) return;
284
+ const seq = Number(data.seq) || 0;
285
+ // The relay numbers the frames of one subscription; an older one can still arrive after a newer one.
286
+ if (seq > 0 && seq < this.streamSeq) return;
287
+ if (seq > 0) this.streamSeq = seq;
288
+ this.frameCount += 1;
289
+ const frame: AgentBrowserFrame = {
290
+ tab: text(data.tab), url: text(data.url), title: text(data.title),
291
+ format: text(data.format) ?? "jpeg", data: data.data, seq: this.frameCount,
292
+ };
293
+ this.frame = frame;
294
+ const url = frame.url ?? this.view.url;
295
+ const title = frame.title ?? this.view.title;
296
+ if (!this.view.hasFrame || url !== this.view.url || title !== this.view.title) {
297
+ this.setView({ ...this.view, hasFrame: true, url, title });
298
+ }
299
+ this.frameListeners.forEach((listener) => listener(frame));
300
+ }
301
+
302
+ private applyTabs(data: Record<string, any>) {
303
+ const tabs: AgentBrowserTab[] = Array.isArray(data.tabs)
304
+ ? data.tabs.flatMap((tab: any) => tab && typeof tab.tab === "string"
305
+ ? [{ tab: tab.tab, url: text(tab.url), title: text(tab.title) }] : [])
306
+ : [];
307
+ this.setView({ ...this.view, tabs, activeTab: text(data.active_tab) ?? null });
308
+ }
309
+
310
+ private applyControl(data: Record<string, any>) {
311
+ const control: AgentBrowserControl = {
312
+ mode: data.control_mode === "human" ? "human" : "agent",
313
+ pending: data.pending === true,
314
+ reason: text(data.reason),
315
+ expiresAt: text(data.expires_at),
316
+ };
317
+ this.setView({ ...this.view, control, error: control.mode === "human" ? null : this.view.error });
318
+ this.syncPreview();
319
+ }
320
+
321
+ private applyError(data: Record<string, any>) {
322
+ const code = text(data.code) ?? "browser_error";
323
+ const error = { code, message: text(data.message) ?? "The browser could not do that.", at: this.timers.now() };
324
+ if (code === "no_browser") {
325
+ this.previewSession = null;
326
+ this.streamSeq = 0;
327
+ this.setView({ ...this.view, available: false, watching: false, error });
328
+ return;
329
+ }
330
+ this.setView({ ...this.view, error });
331
+ }
332
+
333
+ private cancelStop() {
334
+ if (this.stopTimer != null) this.timers.clearTimeout(this.stopTimer);
335
+ this.stopTimer = null;
336
+ }
337
+
338
+ private setView(view: AgentBrowserView) {
339
+ this.view = view;
340
+ this.listeners.forEach((listener) => listener());
341
+ }
342
+ }
@@ -0,0 +1,13 @@
1
+ import type { AgentToolFile } from "./types";
2
+ /** A stored copy of a tool file, as SolidX returns it for the owning agentEvent. */
3
+ export type AgentToolFileMedia = {
4
+ id?: number;
5
+ name?: string;
6
+ url: string;
7
+ };
8
+ /** The files of a ToolResult event in the shape the thread keeps. Runtime-internal URLs (solidx-media:) are dropped. */
9
+ export declare function normalizeToolFiles(raw: unknown): AgentToolFile[];
10
+ /** Puts the resolved media URLs on the files: by media id, then by file name, then by position. */
11
+ export declare function mergeToolFileMedia(files: AgentToolFile[], media: AgentToolFileMedia[]): AgentToolFile[];
12
+ export declare const isImageFile: (file: AgentToolFile) => boolean;
13
+ //# sourceMappingURL=toolFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolFiles.d.ts","sourceRoot":"","sources":["../../../../src/components/core/solid-agent/toolFiles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,oFAAoF;AACpF,MAAM,MAAM,kBAAkB,GAAG;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAK7E,wHAAwH;AACxH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,EAAE,CAiBhE;AAED,mGAAmG;AACnG,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE,GAAG,aAAa,EAAE,CAUvG;AAED,eAAO,MAAM,WAAW,SAAU,aAAa,YAAuC,CAAC"}
@@ -0,0 +1,54 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
21
+ var fetchable = function (url) {
22
+ return typeof url === "string" && (/^https?:\/\//i.test(url) || url.startsWith("/") || url.startsWith("blob:"));
23
+ };
24
+ /** The files of a ToolResult event in the shape the thread keeps. Runtime-internal URLs (solidx-media:) are dropped. */
25
+ export function normalizeToolFiles(raw) {
26
+ if (!Array.isArray(raw))
27
+ return [];
28
+ return raw.flatMap(function (entry) {
29
+ var _a;
30
+ if (!entry || typeof entry !== "object")
31
+ return [];
32
+ var file = entry;
33
+ var mediaId = Number((_a = file.mediaId) !== null && _a !== void 0 ? _a : file.media_id);
34
+ var name = typeof file.name === "string" && file.name ? file.name : "file";
35
+ var mimeType = typeof file.mimeType === "string" ? file.mimeType : typeof file.mime_type === "string" ? file.mime_type : "";
36
+ var size = Number(file.size);
37
+ return [__assign(__assign(__assign(__assign({}, (Number.isInteger(mediaId) && mediaId > 0 ? { mediaId: mediaId } : {})), { name: name, mimeType: mimeType }), (Number.isFinite(size) && size >= 0 ? { size: size } : {})), (fetchable(file.url) ? { url: file.url } : {}))];
38
+ });
39
+ }
40
+ /** Puts the resolved media URLs on the files: by media id, then by file name, then by position. */
41
+ export function mergeToolFileMedia(files, media) {
42
+ var unused = __spreadArray([], media, true);
43
+ var take = function (match) {
44
+ var index = unused.findIndex(match);
45
+ return index >= 0 ? unused.splice(index, 1)[0] : undefined;
46
+ };
47
+ var found = files.map(function (file) { return file.mediaId !== undefined ? take(function (item) { return item.id === file.mediaId; }) : undefined; });
48
+ files.forEach(function (file, index) { var _a; (_a = found[index]) !== null && _a !== void 0 ? _a : (found[index] = take(function (item) { return item.name === file.name; })); });
49
+ if (files.length === media.length)
50
+ files.forEach(function (_, index) { var _a; (_a = found[index]) !== null && _a !== void 0 ? _a : (found[index] = unused.shift()); });
51
+ return files.map(function (file, index) { var _a; return ((_a = found[index]) === null || _a === void 0 ? void 0 : _a.url) ? __assign(__assign({}, file), { url: found[index].url }) : file; });
52
+ }
53
+ export var isImageFile = function (file) { return file.mimeType.startsWith("image/"); };
54
+ //# sourceMappingURL=toolFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolFiles.js","sourceRoot":"","sources":["../../../../src/components/core/solid-agent/toolFiles.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAKA,IAAM,SAAS,GAAG,UAAC,GAAY;IAC3B,OAAA,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAAxG,CAAwG,CAAC;AAE7G,wHAAwH;AACxH,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC;IACnC,OAAO,GAAG,CAAC,OAAO,CAAC,UAAC,KAAK;;QACrB,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,EAAE,CAAC;QACnD,IAAM,IAAI,GAAG,KAAgC,CAAC;QAC9C,IAAM,OAAO,GAAG,MAAM,CAAC,MAAA,IAAI,CAAC,OAAO,mCAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;QACtD,IAAM,IAAI,GAAG,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI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\nexport type AgentToolFileMedia = { id?: number; name?: string; url: string };\n\nconst fetchable = (url: unknown): url is string =>\n typeof url === \"string\" && (/^https?:\\/\\//i.test(url) || url.startsWith(\"/\") || url.startsWith(\"blob:\"));\n\n/** The files of a ToolResult event in the shape the thread keeps. Runtime-internal URLs (solidx-media:) are dropped. */\nexport function normalizeToolFiles(raw: unknown): AgentToolFile[] {\n if (!Array.isArray(raw)) return [];\n return raw.flatMap((entry): AgentToolFile[] => {\n if (!entry || typeof entry !== \"object\") return [];\n const file = entry as Record<string, unknown>;\n const mediaId = Number(file.mediaId ?? file.media_id);\n const name = typeof file.name === \"string\" && file.name ? file.name : \"file\";\n const mimeType = typeof file.mimeType === \"string\" ? file.mimeType : typeof file.mime_type === \"string\" ? file.mime_type : \"\";\n const size = Number(file.size);\n return [{\n ...(Number.isInteger(mediaId) && mediaId > 0 ? { mediaId } : {}),\n name,\n mimeType,\n ...(Number.isFinite(size) && size >= 0 ? { size } : {}),\n ...(fetchable(file.url) ? { url: file.url } : {}),\n }];\n });\n}\n\n/** Puts the resolved media URLs on the files: by media id, then by file name, then by position. */\nexport function mergeToolFileMedia(files: AgentToolFile[], media: AgentToolFileMedia[]): AgentToolFile[] {\n const unused = [...media];\n const take = (match: (item: AgentToolFileMedia) => boolean) => {\n const index = unused.findIndex(match);\n return index >= 0 ? unused.splice(index, 1)[0] : undefined;\n };\n const found = files.map((file) => file.mediaId !== undefined ? take((item) => item.id === file.mediaId) : undefined);\n files.forEach((file, index) => { found[index] ??= take((item) => item.name === file.name); });\n if (files.length === media.length) files.forEach((_, index) => { found[index] ??= unused.shift(); });\n return files.map((file, index) => found[index]?.url ? { ...file, url: found[index]!.url } : file);\n}\n\nexport const isImageFile = (file: AgentToolFile) => file.mimeType.startsWith(\"image/\");\n"]}
@@ -0,0 +1,42 @@
1
+ import type { AgentToolFile } from "./types";
2
+
3
+ /** A stored copy of a tool file, as SolidX returns it for the owning agentEvent. */
4
+ export type AgentToolFileMedia = { id?: number; name?: string; url: string };
5
+
6
+ const fetchable = (url: unknown): url is string =>
7
+ typeof url === "string" && (/^https?:\/\//i.test(url) || url.startsWith("/") || url.startsWith("blob:"));
8
+
9
+ /** The files of a ToolResult event in the shape the thread keeps. Runtime-internal URLs (solidx-media:) are dropped. */
10
+ export function normalizeToolFiles(raw: unknown): AgentToolFile[] {
11
+ if (!Array.isArray(raw)) return [];
12
+ return raw.flatMap((entry): AgentToolFile[] => {
13
+ if (!entry || typeof entry !== "object") return [];
14
+ const file = entry as Record<string, unknown>;
15
+ const mediaId = Number(file.mediaId ?? file.media_id);
16
+ const name = typeof file.name === "string" && file.name ? file.name : "file";
17
+ const mimeType = typeof file.mimeType === "string" ? file.mimeType : typeof file.mime_type === "string" ? file.mime_type : "";
18
+ const size = Number(file.size);
19
+ return [{
20
+ ...(Number.isInteger(mediaId) && mediaId > 0 ? { mediaId } : {}),
21
+ name,
22
+ mimeType,
23
+ ...(Number.isFinite(size) && size >= 0 ? { size } : {}),
24
+ ...(fetchable(file.url) ? { url: file.url } : {}),
25
+ }];
26
+ });
27
+ }
28
+
29
+ /** Puts the resolved media URLs on the files: by media id, then by file name, then by position. */
30
+ export function mergeToolFileMedia(files: AgentToolFile[], media: AgentToolFileMedia[]): AgentToolFile[] {
31
+ const unused = [...media];
32
+ const take = (match: (item: AgentToolFileMedia) => boolean) => {
33
+ const index = unused.findIndex(match);
34
+ return index >= 0 ? unused.splice(index, 1)[0] : undefined;
35
+ };
36
+ const found = files.map((file) => file.mediaId !== undefined ? take((item) => item.id === file.mediaId) : undefined);
37
+ files.forEach((file, index) => { found[index] ??= take((item) => item.name === file.name); });
38
+ if (files.length === media.length) files.forEach((_, index) => { found[index] ??= unused.shift(); });
39
+ return files.map((file, index) => found[index]?.url ? { ...file, url: found[index]!.url } : file);
40
+ }
41
+
42
+ export const isImageFile = (file: AgentToolFile) => file.mimeType.startsWith("image/");
@@ -0,0 +1,9 @@
1
+ import type { AgentToolFile } from "../types";
2
+ /**
3
+ * Files a tool returned: screenshots as thumbnails, downloads as links. A file shows its name only
4
+ * until SolidX hands out its stored URL.
5
+ */
6
+ export declare function AgentToolFiles({ files }: {
7
+ files: AgentToolFile[];
8
+ }): import("react/jsx-runtime").JSX.Element;
9
+ //# sourceMappingURL=AgentToolFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentToolFiles.d.ts","sourceRoot":"","sources":["../../../../../src/components/core/solid-agent/widgets/AgentToolFiles.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAS9C;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,aAAa,EAAE,CAAA;CAAE,2CA2BnE"}
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { FileDown, Image as ImageIcon } from "lucide-react";
4
+ import agentStyles from "../SolidAgent.module.css";
5
+ import styles from "./solidChatWidgets.module.css";
6
+ import { isImageFile } from "../toolFiles";
7
+ function formatSize(size) {
8
+ if (size === undefined)
9
+ return "";
10
+ if (size < 1024)
11
+ return "".concat(size, " B");
12
+ if (size < 1024 * 1024)
13
+ return "".concat(Math.round(size / 1024), " KB");
14
+ return "".concat((size / (1024 * 1024)).toFixed(1), " MB");
15
+ }
16
+ /**
17
+ * Files a tool returned: screenshots as thumbnails, downloads as links. A file shows its name only
18
+ * until SolidX hands out its stored URL.
19
+ */
20
+ export function AgentToolFiles(_a) {
21
+ var files = _a.files;
22
+ var _b = useState(null), preview = _b[0], setPreview = _b[1];
23
+ return (_jsxs("div", { className: styles.ToolFiles, children: [files.map(function (file, index) {
24
+ var _a;
25
+ var key = "".concat((_a = file.mediaId) !== null && _a !== void 0 ? _a : file.name, "-").concat(index);
26
+ var size = formatSize(file.size);
27
+ if (isImageFile(file) && file.url) {
28
+ return (_jsx("button", { type: "button", className: styles.ToolFileThumb, title: "View ".concat(file.name), onClick: function () { return setPreview(file); }, children: _jsx("img", { src: file.url, alt: file.name, loading: "lazy" }) }, key));
29
+ }
30
+ var Icon = isImageFile(file) ? ImageIcon : FileDown;
31
+ var label = _jsxs(_Fragment, { children: [_jsx(Icon, { size: 12, "aria-hidden": "true" }), _jsx("span", { className: styles.ToolFileName, children: file.name }), size && _jsx("span", { className: styles.ToolFileSize, children: size })] });
32
+ return file.url
33
+ ? _jsx("a", { className: styles.ToolFileChip, href: file.url, download: file.name, target: "_blank", rel: "noreferrer", title: "Download ".concat(file.name), children: label }, key)
34
+ : _jsx("span", { className: styles.ToolFileChip, title: file.name, children: label }, key);
35
+ }), (preview === null || preview === void 0 ? void 0 : preview.url) && (_jsx("div", { className: agentStyles.lightbox, role: "dialog", "aria-label": preview.name, onClick: function () { return setPreview(null); }, children: _jsx("img", { src: preview.url, alt: preview.name }) }))] }));
36
+ }
37
+ //# sourceMappingURL=AgentToolFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentToolFiles.js","sourceRoot":"","sources":["../../../../../src/components/core/solid-agent/widgets/AgentToolFiles.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,MAAM,MAAM,+BAA+B,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,SAAS,UAAU,CAAC,IAAa;IAC7B,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IAClC,IAAI,IAAI,GAAG,IAAI;QAAE,OAAO,UAAG,IAAI,OAAI,CAAC;IACpC,IAAI,IAAI,GAAG,IAAI,GAAG,IAAI;QAAE,OAAO,UAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,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Y,YAAG,IAAI,CAAC,IAAI,GAAQ,EAAC,IAAI,IAAI,eAAM,SAAS,EAAE,MAAM,CAAC,YAAY,YAAG,IAAI,GAAQ,IAAI,CAAC;gBAC9K,OAAO,IAAI,CAAC,GAAG;oBACX,CAAC,CAAC,YAAa,SAAS,EAAE,MAAM,CAAC,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAC,QAAQ,EAAC,GAAG,EAAC,YAAY,EAAC,KAAK,EAAE,mBAAY,IAAI,CAAC,IAAI,CAAE,YAAG,KAAK,IAAjJ,GAAG,CAAmJ;oBAChK,CAAC,CAAC,eAAgB,SAAS,EAAE,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,YAAG,KAAK,IAA7D,GAAG,CAAkE,CAAC;YAC3F,CAAC,CAAC,EACD,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,KAAI,CACb,cAAK,SAAS,EAAE,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAC,QAAQ,gBAAa,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,cAAM,OAAA,UAAU,CAAC,IAAI,CAAC,EAAhB,CAAgB,YACzG,cAAK,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,IAAI,GAAI,GAC1C,CACT,IACC,CACT,CAAC;AACN,CAAC","sourcesContent":["import { useState } from \"react\";\nimport { FileDown, Image as ImageIcon } from \"lucide-react\";\nimport agentStyles from \"../SolidAgent.module.css\";\nimport styles from \"./solidChatWidgets.module.css\";\nimport { isImageFile } from \"../toolFiles\";\nimport type { AgentToolFile } from \"../types\";\n\nfunction formatSize(size?: number) {\n if (size === undefined) return \"\";\n if (size < 1024) return `${size} B`;\n if (size < 1024 * 1024) return `${Math.round(size / 1024)} KB`;\n return `${(size / (1024 * 1024)).toFixed(1)} MB`;\n}\n\n/**\n * Files a tool returned: screenshots as thumbnails, downloads as links. A file shows its name only\n * until SolidX hands out its stored URL.\n */\nexport function AgentToolFiles({ files }: { files: AgentToolFile[] }) {\n const [preview, setPreview] = useState<AgentToolFile | null>(null);\n return (\n <div className={styles.ToolFiles}>\n {files.map((file, index) => {\n const key = `${file.mediaId ?? file.name}-${index}`;\n const size = formatSize(file.size);\n if (isImageFile(file) && file.url) {\n return (\n <button key={key} type=\"button\" className={styles.ToolFileThumb} title={`View ${file.name}`} onClick={() => setPreview(file)}>\n <img src={file.url} alt={file.name} loading=\"lazy\" />\n </button>\n );\n }\n const Icon = isImageFile(file) ? ImageIcon : FileDown;\n const label = <><Icon size={12} aria-hidden=\"true\" /><span className={styles.ToolFileName}>{file.name}</span>{size && <span className={styles.ToolFileSize}>{size}</span>}</>;\n return file.url\n ? <a key={key} className={styles.ToolFileChip} href={file.url} download={file.name} target=\"_blank\" rel=\"noreferrer\" title={`Download ${file.name}`}>{label}</a>\n : <span key={key} className={styles.ToolFileChip} title={file.name}>{label}</span>;\n })}\n {preview?.url && (\n <div className={agentStyles.lightbox} role=\"dialog\" aria-label={preview.name} onClick={() => setPreview(null)}>\n <img src={preview.url} alt={preview.name} />\n </div>\n )}\n </div>\n );\n}\n"]}
@@ -0,0 +1,46 @@
1
+ import { useState } from "react";
2
+ import { FileDown, Image as ImageIcon } from "lucide-react";
3
+ import agentStyles from "../SolidAgent.module.css";
4
+ import styles from "./solidChatWidgets.module.css";
5
+ import { isImageFile } from "../toolFiles";
6
+ import type { AgentToolFile } from "../types";
7
+
8
+ function formatSize(size?: number) {
9
+ if (size === undefined) return "";
10
+ if (size < 1024) return `${size} B`;
11
+ if (size < 1024 * 1024) return `${Math.round(size / 1024)} KB`;
12
+ return `${(size / (1024 * 1024)).toFixed(1)} MB`;
13
+ }
14
+
15
+ /**
16
+ * Files a tool returned: screenshots as thumbnails, downloads as links. A file shows its name only
17
+ * until SolidX hands out its stored URL.
18
+ */
19
+ export function AgentToolFiles({ files }: { files: AgentToolFile[] }) {
20
+ const [preview, setPreview] = useState<AgentToolFile | null>(null);
21
+ return (
22
+ <div className={styles.ToolFiles}>
23
+ {files.map((file, index) => {
24
+ const key = `${file.mediaId ?? file.name}-${index}`;
25
+ const size = formatSize(file.size);
26
+ if (isImageFile(file) && file.url) {
27
+ return (
28
+ <button key={key} type="button" className={styles.ToolFileThumb} title={`View ${file.name}`} onClick={() => setPreview(file)}>
29
+ <img src={file.url} alt={file.name} loading="lazy" />
30
+ </button>
31
+ );
32
+ }
33
+ const Icon = isImageFile(file) ? ImageIcon : FileDown;
34
+ const label = <><Icon size={12} aria-hidden="true" /><span className={styles.ToolFileName}>{file.name}</span>{size && <span className={styles.ToolFileSize}>{size}</span>}</>;
35
+ return file.url
36
+ ? <a key={key} className={styles.ToolFileChip} href={file.url} download={file.name} target="_blank" rel="noreferrer" title={`Download ${file.name}`}>{label}</a>
37
+ : <span key={key} className={styles.ToolFileChip} title={file.name}>{label}</span>;
38
+ })}
39
+ {preview?.url && (
40
+ <div className={agentStyles.lightbox} role="dialog" aria-label={preview.name} onClick={() => setPreview(null)}>
41
+ <img src={preview.url} alt={preview.name} />
42
+ </div>
43
+ )}
44
+ </div>
45
+ );
46
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"SolidQuestionChatWidget.d.ts","sourceRoot":"","sources":["../../../../../src/components/core/solid-agent/widgets/SolidQuestionChatWidget.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAUpE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,gCAAiC,oBAAoB,4CA2ExF,CAAC"}
1
+ {"version":3,"file":"SolidQuestionChatWidget.d.ts","sourceRoot":"","sources":["../../../../../src/components/core/solid-agent/widgets/SolidQuestionChatWidget.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAWpE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,gCAAiC,oBAAoB,4CA2ExF,CAAC"}
@@ -11,6 +11,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  import { useState } from "react";
12
12
  import styles from "../SolidAgent.module.css";
13
13
  import { asArray, getChatWidgetData } from "./chatWidgetUtils";
14
+ import { SolidAgentMarkdown } from "../SolidAgentMarkdown";
14
15
  /**
15
16
  * `event_data: { widget: "question", question, hint?, options: [...], multiple? }`.
16
17
  * A single-choice answer is sent on click; multiple choice waits for Submit.
@@ -38,13 +39,13 @@ export var SolidQuestionChatWidget = function (_a) {
38
39
  return (_jsxs("div", { className: styles.card, children: [_jsxs("div", { className: styles.cardBody, children: [data.reviewKind === "approval" && (data.toolName || data.toolArguments) && (_jsxs("section", { "aria-label": "Tool call details", className: styles.reviewDetails, children: [_jsxs("div", { className: styles.reviewDetailsHeading, children: [_jsx("span", { children: "Tool call" }), data.toolName && _jsx("code", { children: data.toolName })] }), data.toolArguments && Object.keys(data.toolArguments).length > 0 && (_jsx("dl", { className: styles.reviewArgumentList, children: Object.entries(data.toolArguments).map(function (_a) {
39
40
  var key = _a[0], value = _a[1];
40
41
  return (_jsxs("div", { className: styles.reviewArgument, children: [_jsx("dt", { children: key }), _jsx("dd", { children: typeof value === "string" ? value : JSON.stringify(value, null, 2) })] }, key));
41
- }) }))] })), data.question && _jsx("strong", { children: data.question }), data.hint && _jsx("span", { style: { color: "var(--agent-muted)", fontSize: 12.5 }, children: data.hint }), options.map(function (option, index) { return (_jsx("button", { type: "button", className: "".concat(styles.btn, " ").concat(picked.includes(index) ? styles.optionOn : ""), style: { textAlign: "left" }, disabled: locked && (serverManagedReply || !picked.includes(index)), "aria-pressed": picked.includes(index), onClick: function () { return choose(index); }, children: option.label }, index)); })] }), data.multiple && !locked && (_jsx("div", { className: styles.cardFoot, children: _jsx("button", { type: "button", className: "".concat(styles.btn, " ").concat(styles.btnPrimary), disabled: !picked.length, onClick: function () {
42
+ }) }))] })), data.question && _jsx(SolidAgentMarkdown, { text: data.question }), data.hint && _jsx("span", { style: { color: "var(--agent-muted)", fontSize: 12.5 }, children: data.hint }), options.map(function (option, index) { return (_jsx("button", { type: "button", className: "".concat(styles.btn, " ").concat(picked.includes(index) ? styles.optionOn : ""), style: { textAlign: "left" }, disabled: locked && (serverManagedReply || !picked.includes(index)), "aria-pressed": picked.includes(index), onClick: function () { return choose(index); }, children: option.label }, index)); })] }), data.multiple && !locked && (_jsx("div", { className: styles.cardFoot, children: _jsx("button", { type: "button", className: "".concat(styles.btn, " ").concat(styles.btnPrimary), disabled: !picked.length, onClick: function () {
42
43
  if (!serverManagedReply)
43
44
  setAnswered(true);
44
45
  reply(picked.map(function (i) { return options[i].value; }));
45
46
  }, children: "Submit" }) }))] }));
46
47
  };
47
48
  Object.assign(SolidQuestionChatWidget, { getExtensionMetadata: function () { return ({
48
- agentWidget: { name: "question", description: "Ask the user a single or multiple choice question.", propsSchema: { type: "object", properties: { question: { type: "string" }, hint: { type: "string" }, options: { type: "array", items: { anyOf: [{ type: "string" }, { type: "object", properties: { label: { type: "string" }, value: {} }, required: ["label"] }] } }, multiple: { type: "boolean" } } } },
49
+ agentWidget: { name: "question", description: "Ask the user a single or multiple choice question.", propsSchema: { type: "object", properties: { question: { type: "string", description: "The question as Markdown. Supports **bold**, *italic*, lists and [links](https://…)." }, hint: { type: "string" }, options: { type: "array", items: { anyOf: [{ type: "string" }, { type: "object", properties: { label: { type: "string" }, value: {} }, required: ["label"] }] } }, multiple: { type: "boolean" } } } },
49
50
  }); } });
50
51
  //# sourceMappingURL=SolidQuestionChatWidget.js.map