@solidxai/core-ui 0.1.22-beta.5 → 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.
- package/dist/components/core/solid-agent/browser/AgentBrowser.module.css +170 -0
- package/dist/components/core/solid-agent/browser/AgentBrowserScreen.d.ts +13 -0
- package/dist/components/core/solid-agent/browser/AgentBrowserScreen.d.ts.map +1 -0
- package/dist/components/core/solid-agent/browser/AgentBrowserScreen.js +138 -0
- package/dist/components/core/solid-agent/browser/AgentBrowserScreen.js.map +1 -0
- package/dist/components/core/solid-agent/browser/AgentBrowserScreen.tsx +162 -0
- package/dist/components/core/solid-agent/browser/DefaultAgentBrowserPanelWidget.d.ts +9 -0
- package/dist/components/core/solid-agent/browser/DefaultAgentBrowserPanelWidget.d.ts.map +1 -0
- package/dist/components/core/solid-agent/browser/DefaultAgentBrowserPanelWidget.js +59 -0
- package/dist/components/core/solid-agent/browser/DefaultAgentBrowserPanelWidget.js.map +1 -0
- package/dist/components/core/solid-agent/browser/DefaultAgentBrowserPanelWidget.tsx +159 -0
- package/dist/components/core/solid-agent/browser/useAgentBrowser.d.ts +6 -0
- package/dist/components/core/solid-agent/browser/useAgentBrowser.d.ts.map +1 -0
- package/dist/components/core/solid-agent/browser/useAgentBrowser.js +37 -0
- package/dist/components/core/solid-agent/browser/useAgentBrowser.js.map +1 -0
- package/dist/components/core/solid-agent/browser/useAgentBrowser.ts +38 -0
- package/dist/components/core/solid-agent/client/agentBrowser.d.ts +128 -0
- package/dist/components/core/solid-agent/client/agentBrowser.d.ts.map +1 -0
- package/dist/components/core/solid-agent/client/agentBrowser.js +474 -0
- package/dist/components/core/solid-agent/client/agentBrowser.js.map +1 -0
- package/dist/components/core/solid-agent/client/agentBrowser.ts +342 -0
- package/dist/components/core/solid-agent/toolFiles.d.ts +13 -0
- package/dist/components/core/solid-agent/toolFiles.d.ts.map +1 -0
- package/dist/components/core/solid-agent/toolFiles.js +54 -0
- package/dist/components/core/solid-agent/toolFiles.js.map +1 -0
- package/dist/components/core/solid-agent/toolFiles.ts +42 -0
- package/dist/components/core/solid-agent/widgets/AgentToolFiles.d.ts +9 -0
- package/dist/components/core/solid-agent/widgets/AgentToolFiles.d.ts.map +1 -0
- package/dist/components/core/solid-agent/widgets/AgentToolFiles.js +37 -0
- package/dist/components/core/solid-agent/widgets/AgentToolFiles.js.map +1 -0
- package/dist/components/core/solid-agent/widgets/AgentToolFiles.tsx +46 -0
- package/package.json +1 -1
|
@@ -0,0 +1,474 @@
|
|
|
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 STATES = ["none", "starting", "live", "state_saved", "released"];
|
|
13
|
+
var DEFAULT_VIEWPORT = { width: 1280, height: 800 };
|
|
14
|
+
/** Moving the screen between the side pane and the large view must not drop the preview. */
|
|
15
|
+
var STOP_DELAY_MS = 800;
|
|
16
|
+
var OFFLINE = { code: "offline", message: "The chat is not connected to the agent. Try again once it reconnects." };
|
|
17
|
+
function initialView(sessionId, available) {
|
|
18
|
+
if (available === void 0) { available = true; }
|
|
19
|
+
return {
|
|
20
|
+
sessionId: sessionId,
|
|
21
|
+
available: available,
|
|
22
|
+
state: "none",
|
|
23
|
+
viewport: DEFAULT_VIEWPORT,
|
|
24
|
+
url: null,
|
|
25
|
+
title: null,
|
|
26
|
+
tabs: [],
|
|
27
|
+
activeTab: null,
|
|
28
|
+
control: { mode: "agent", pending: false, reason: null, expiresAt: null },
|
|
29
|
+
restoredAt: null,
|
|
30
|
+
watching: false,
|
|
31
|
+
hasFrame: false,
|
|
32
|
+
error: null,
|
|
33
|
+
controllable: true,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var text = function (value) { return (typeof value === "string" && value ? value : null); };
|
|
37
|
+
/** Whether the panel should show: the browser runs, or the user has (or is offered) it. */
|
|
38
|
+
export function isBrowserActive(view) {
|
|
39
|
+
return view.available && (view.state === "live" || view.state === "starting" || view.control.mode === "human");
|
|
40
|
+
}
|
|
41
|
+
var AgentBrowserChannel = /** @class */ (function () {
|
|
42
|
+
function AgentBrowserChannel(socket, timers) {
|
|
43
|
+
var _this = this;
|
|
44
|
+
var _a, _b, _c;
|
|
45
|
+
Object.defineProperty(this, "view", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: initialView(null)
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(this, "listeners", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: new Set()
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(this, "frameListeners", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
writable: true,
|
|
61
|
+
value: new Set()
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(this, "frame", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: null
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(this, "frameCount", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: 0
|
|
74
|
+
});
|
|
75
|
+
/** The relay's number of the last frame of the current subscription; a new subscription counts from 1 again. */
|
|
76
|
+
Object.defineProperty(this, "streamSeq", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
configurable: true,
|
|
79
|
+
writable: true,
|
|
80
|
+
value: 0
|
|
81
|
+
});
|
|
82
|
+
/** This socket's number for its current subscription, which the runtime echoes on the frames. */
|
|
83
|
+
Object.defineProperty(this, "stream", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
value: 0
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(this, "watchers", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
configurable: true,
|
|
92
|
+
writable: true,
|
|
93
|
+
value: 0
|
|
94
|
+
});
|
|
95
|
+
/** The session whose preview this socket subscribed to, if any. */
|
|
96
|
+
Object.defineProperty(this, "previewSession", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
configurable: true,
|
|
99
|
+
writable: true,
|
|
100
|
+
value: null
|
|
101
|
+
});
|
|
102
|
+
Object.defineProperty(this, "stopTimer", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
configurable: true,
|
|
105
|
+
writable: true,
|
|
106
|
+
value: null
|
|
107
|
+
});
|
|
108
|
+
Object.defineProperty(this, "socket", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
configurable: true,
|
|
111
|
+
writable: true,
|
|
112
|
+
value: void 0
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(this, "timers", {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
configurable: true,
|
|
117
|
+
writable: true,
|
|
118
|
+
value: void 0
|
|
119
|
+
});
|
|
120
|
+
Object.defineProperty(this, "getView", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
configurable: true,
|
|
123
|
+
writable: true,
|
|
124
|
+
value: function () { return _this.view; }
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperty(this, "subscribe", {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
configurable: true,
|
|
129
|
+
writable: true,
|
|
130
|
+
value: function (listener) {
|
|
131
|
+
_this.listeners.add(listener);
|
|
132
|
+
return function () { _this.listeners.delete(listener); };
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
this.socket = socket;
|
|
136
|
+
this.timers = {
|
|
137
|
+
setTimeout: (_a = timers === null || timers === void 0 ? void 0 : timers.setTimeout) !== null && _a !== void 0 ? _a : (function (callback, ms) { return setTimeout(callback, ms); }),
|
|
138
|
+
clearTimeout: (_b = timers === null || timers === void 0 ? void 0 : timers.clearTimeout) !== null && _b !== void 0 ? _b : (function (handle) { return clearTimeout(handle); }),
|
|
139
|
+
now: (_c = timers === null || timers === void 0 ? void 0 : timers.now) !== null && _c !== void 0 ? _c : (function () { return Date.now(); }),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "onFrame", {
|
|
143
|
+
enumerable: false,
|
|
144
|
+
configurable: true,
|
|
145
|
+
writable: true,
|
|
146
|
+
value: function (listener) {
|
|
147
|
+
var _this = this;
|
|
148
|
+
this.frameListeners.add(listener);
|
|
149
|
+
return function () { _this.frameListeners.delete(listener); };
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "latestFrame", {
|
|
153
|
+
get: function () {
|
|
154
|
+
return this.frame;
|
|
155
|
+
},
|
|
156
|
+
enumerable: false,
|
|
157
|
+
configurable: true
|
|
158
|
+
});
|
|
159
|
+
/** Applies one inbound frame. Returns false for frames that are not about the browser. */
|
|
160
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "handle", {
|
|
161
|
+
enumerable: false,
|
|
162
|
+
configurable: true,
|
|
163
|
+
writable: true,
|
|
164
|
+
value: function (eventType, data) {
|
|
165
|
+
switch (eventType) {
|
|
166
|
+
case "browser_status":
|
|
167
|
+
this.applyStatus(data);
|
|
168
|
+
return true;
|
|
169
|
+
case "browser_frame":
|
|
170
|
+
this.applyFrame(data);
|
|
171
|
+
return true;
|
|
172
|
+
case "browser_tabs":
|
|
173
|
+
this.applyTabs(data);
|
|
174
|
+
return true;
|
|
175
|
+
case "browser_control_state":
|
|
176
|
+
this.applyControl(data);
|
|
177
|
+
return true;
|
|
178
|
+
case "browser_error":
|
|
179
|
+
this.applyError(data);
|
|
180
|
+
return true;
|
|
181
|
+
default: return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
/** The socket (re)confirmed a session. A new socket has no preview yet; another session starts empty. */
|
|
186
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "sessionStarted", {
|
|
187
|
+
enumerable: false,
|
|
188
|
+
configurable: true,
|
|
189
|
+
writable: true,
|
|
190
|
+
value: function (sessionId) {
|
|
191
|
+
this.previewSession = null;
|
|
192
|
+
this.streamSeq = 0;
|
|
193
|
+
if (sessionId !== this.view.sessionId) {
|
|
194
|
+
this.frame = null;
|
|
195
|
+
this.setView(initialView(sessionId, this.view.available));
|
|
196
|
+
}
|
|
197
|
+
else if (this.view.watching) {
|
|
198
|
+
this.setView(__assign(__assign({}, this.view), { watching: false }));
|
|
199
|
+
}
|
|
200
|
+
this.syncPreview();
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
/** Forget the current session's browser (new chat, switched conversation, expired session). */
|
|
204
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "reset", {
|
|
205
|
+
enumerable: false,
|
|
206
|
+
configurable: true,
|
|
207
|
+
writable: true,
|
|
208
|
+
value: function () {
|
|
209
|
+
this.cancelStop();
|
|
210
|
+
if (this.previewSession)
|
|
211
|
+
this.socket.sendNow({ action: "browser_preview_stop", session_id: this.previewSession });
|
|
212
|
+
this.previewSession = null;
|
|
213
|
+
this.streamSeq = 0;
|
|
214
|
+
this.frame = null;
|
|
215
|
+
this.setView(initialView(null, this.view.available));
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
/** Keep the preview running while the returned release function has not been called. */
|
|
219
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "watch", {
|
|
220
|
+
enumerable: false,
|
|
221
|
+
configurable: true,
|
|
222
|
+
writable: true,
|
|
223
|
+
value: function () {
|
|
224
|
+
var _this = this;
|
|
225
|
+
this.watchers += 1;
|
|
226
|
+
this.cancelStop();
|
|
227
|
+
this.syncPreview();
|
|
228
|
+
var released = false;
|
|
229
|
+
return function () {
|
|
230
|
+
if (released)
|
|
231
|
+
return;
|
|
232
|
+
released = true;
|
|
233
|
+
_this.watchers -= 1;
|
|
234
|
+
if (_this.watchers > 0)
|
|
235
|
+
return;
|
|
236
|
+
_this.cancelStop();
|
|
237
|
+
_this.stopTimer = _this.timers.setTimeout(function () {
|
|
238
|
+
_this.stopTimer = null;
|
|
239
|
+
_this.syncPreview();
|
|
240
|
+
}, STOP_DELAY_MS);
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "requestControl", {
|
|
245
|
+
enumerable: false,
|
|
246
|
+
configurable: true,
|
|
247
|
+
writable: true,
|
|
248
|
+
value: function () {
|
|
249
|
+
return this.sendForSession(function (session_id) { return ({ action: "browser_control_request", session_id: session_id }); });
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
/** Give the browser back, or continue a handoff without taking it. The note goes to the agent. */
|
|
253
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "release", {
|
|
254
|
+
enumerable: false,
|
|
255
|
+
configurable: true,
|
|
256
|
+
writable: true,
|
|
257
|
+
value: function (note) {
|
|
258
|
+
var trimmed = typeof note === "string" ? note.trim() : "";
|
|
259
|
+
return this.sendForSession(function (session_id) { return ({ action: "browser_control_release", session_id: session_id, note: trimmed || null }); });
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
/** Forwards one input event while the user has the browser. Dropped (false) otherwise. */
|
|
263
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "sendInput", {
|
|
264
|
+
enumerable: false,
|
|
265
|
+
configurable: true,
|
|
266
|
+
writable: true,
|
|
267
|
+
value: function (event) {
|
|
268
|
+
if (this.view.control.mode !== "human")
|
|
269
|
+
return false;
|
|
270
|
+
var sessionId = this.socket.currentSessionId;
|
|
271
|
+
return !!sessionId && this.socket.sendNow({ action: "browser_input", session_id: sessionId, event: event });
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "navigate", {
|
|
275
|
+
enumerable: false,
|
|
276
|
+
configurable: true,
|
|
277
|
+
writable: true,
|
|
278
|
+
value: function (url) {
|
|
279
|
+
var target = url.trim();
|
|
280
|
+
if (!target)
|
|
281
|
+
return false;
|
|
282
|
+
return this.sendInput({ kind: "navigation", url: /^[a-z][a-z\d+.-]*:/i.test(target) ? target : "https://".concat(target) });
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "navigation", {
|
|
286
|
+
enumerable: false,
|
|
287
|
+
configurable: true,
|
|
288
|
+
writable: true,
|
|
289
|
+
value: function (action) {
|
|
290
|
+
return this.sendInput({ kind: "navigation", action: action });
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "clearError", {
|
|
294
|
+
enumerable: false,
|
|
295
|
+
configurable: true,
|
|
296
|
+
writable: true,
|
|
297
|
+
value: function () {
|
|
298
|
+
if (this.view.error)
|
|
299
|
+
this.setView(__assign(__assign({}, this.view), { error: null }));
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "dispose", {
|
|
303
|
+
enumerable: false,
|
|
304
|
+
configurable: true,
|
|
305
|
+
writable: true,
|
|
306
|
+
value: function () {
|
|
307
|
+
this.cancelStop();
|
|
308
|
+
this.listeners.clear();
|
|
309
|
+
this.frameListeners.clear();
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "sendForSession", {
|
|
313
|
+
enumerable: false,
|
|
314
|
+
configurable: true,
|
|
315
|
+
writable: true,
|
|
316
|
+
value: function (build) {
|
|
317
|
+
var sessionId = this.socket.currentSessionId;
|
|
318
|
+
if (sessionId && this.socket.sendNow(build(sessionId)))
|
|
319
|
+
return true;
|
|
320
|
+
this.setView(__assign(__assign({}, this.view), { error: __assign(__assign({}, OFFLINE), { at: this.timers.now() }) }));
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "wantsPreview", {
|
|
325
|
+
enumerable: false,
|
|
326
|
+
configurable: true,
|
|
327
|
+
writable: true,
|
|
328
|
+
value: function () {
|
|
329
|
+
return this.watchers > 0 && isBrowserActive(this.view);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "syncPreview", {
|
|
333
|
+
enumerable: false,
|
|
334
|
+
configurable: true,
|
|
335
|
+
writable: true,
|
|
336
|
+
value: function () {
|
|
337
|
+
var sessionId = this.socket.currentSessionId;
|
|
338
|
+
if (this.wantsPreview()) {
|
|
339
|
+
if (!sessionId || this.previewSession === sessionId)
|
|
340
|
+
return;
|
|
341
|
+
this.stream += 1;
|
|
342
|
+
if (this.socket.sendNow({ action: "browser_preview_start", session_id: sessionId, stream: this.stream })) {
|
|
343
|
+
this.previewSession = sessionId;
|
|
344
|
+
this.streamSeq = 0;
|
|
345
|
+
this.setView(__assign(__assign({}, this.view), { watching: true }));
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else if (this.watchers === 0 && this.previewSession) {
|
|
349
|
+
this.socket.sendNow({ action: "browser_preview_stop", session_id: this.previewSession });
|
|
350
|
+
this.previewSession = null;
|
|
351
|
+
this.streamSeq = 0;
|
|
352
|
+
this.setView(__assign(__assign({}, this.view), { watching: false }));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "applyStatus", {
|
|
357
|
+
enumerable: false,
|
|
358
|
+
configurable: true,
|
|
359
|
+
writable: true,
|
|
360
|
+
value: function (data) {
|
|
361
|
+
var _a, _b, _c, _d;
|
|
362
|
+
var state = STATES.includes(data.state) ? data.state : this.view.state;
|
|
363
|
+
var width = Number((_a = data.viewport) === null || _a === void 0 ? void 0 : _a.width);
|
|
364
|
+
var height = Number((_b = data.viewport) === null || _b === void 0 ? void 0 : _b.height);
|
|
365
|
+
var ended = state === "none" || state === "released" || state === "state_saved";
|
|
366
|
+
if (ended)
|
|
367
|
+
this.frame = null;
|
|
368
|
+
this.setView(__assign(__assign({}, this.view), { state: state, viewport: width > 0 && height > 0 ? { width: width, height: height } : this.view.viewport, url: (_c = text(data.url)) !== null && _c !== void 0 ? _c : (ended ? null : this.view.url), title: ended ? null : this.view.title, activeTab: (_d = text(data.active_tab)) !== null && _d !== void 0 ? _d : this.view.activeTab, tabs: ended ? [] : this.view.tabs, hasFrame: ended ? false : this.view.hasFrame,
|
|
369
|
+
// Only an explicit "control: false" makes the browser view-only; a server that never sends it keeps control.
|
|
370
|
+
controllable: data.control === false ? false : data.control === true ? true : this.view.controllable, control: data.control_mode === "human" || data.control_mode === "agent"
|
|
371
|
+
? __assign(__assign({}, this.view.control), { mode: data.control_mode }) : this.view.control, restoredAt: data.restored === true ? this.timers.now() : this.view.restoredAt }));
|
|
372
|
+
this.syncPreview();
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "applyFrame", {
|
|
376
|
+
enumerable: false,
|
|
377
|
+
configurable: true,
|
|
378
|
+
writable: true,
|
|
379
|
+
value: function (data) {
|
|
380
|
+
var _a, _b, _c;
|
|
381
|
+
if (typeof data.data !== "string" || !data.data || !this.previewSession)
|
|
382
|
+
return;
|
|
383
|
+
// A frame still on the way from an earlier subscription carries that subscription's number. Taking its
|
|
384
|
+
// seq would hide the new subscription's frames, which the relay may number from 1 again.
|
|
385
|
+
if (data.stream !== undefined && data.stream !== this.stream)
|
|
386
|
+
return;
|
|
387
|
+
var seq = Number(data.seq) || 0;
|
|
388
|
+
// The relay numbers the frames of one subscription; an older one can still arrive after a newer one.
|
|
389
|
+
if (seq > 0 && seq < this.streamSeq)
|
|
390
|
+
return;
|
|
391
|
+
if (seq > 0)
|
|
392
|
+
this.streamSeq = seq;
|
|
393
|
+
this.frameCount += 1;
|
|
394
|
+
var frame = {
|
|
395
|
+
tab: text(data.tab), url: text(data.url), title: text(data.title),
|
|
396
|
+
format: (_a = text(data.format)) !== null && _a !== void 0 ? _a : "jpeg", data: data.data, seq: this.frameCount,
|
|
397
|
+
};
|
|
398
|
+
this.frame = frame;
|
|
399
|
+
var url = (_b = frame.url) !== null && _b !== void 0 ? _b : this.view.url;
|
|
400
|
+
var title = (_c = frame.title) !== null && _c !== void 0 ? _c : this.view.title;
|
|
401
|
+
if (!this.view.hasFrame || url !== this.view.url || title !== this.view.title) {
|
|
402
|
+
this.setView(__assign(__assign({}, this.view), { hasFrame: true, url: url, title: title }));
|
|
403
|
+
}
|
|
404
|
+
this.frameListeners.forEach(function (listener) { return listener(frame); });
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "applyTabs", {
|
|
408
|
+
enumerable: false,
|
|
409
|
+
configurable: true,
|
|
410
|
+
writable: true,
|
|
411
|
+
value: function (data) {
|
|
412
|
+
var _a;
|
|
413
|
+
var tabs = Array.isArray(data.tabs)
|
|
414
|
+
? data.tabs.flatMap(function (tab) { return tab && typeof tab.tab === "string"
|
|
415
|
+
? [{ tab: tab.tab, url: text(tab.url), title: text(tab.title) }] : []; })
|
|
416
|
+
: [];
|
|
417
|
+
this.setView(__assign(__assign({}, this.view), { tabs: tabs, activeTab: (_a = text(data.active_tab)) !== null && _a !== void 0 ? _a : null }));
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "applyControl", {
|
|
421
|
+
enumerable: false,
|
|
422
|
+
configurable: true,
|
|
423
|
+
writable: true,
|
|
424
|
+
value: function (data) {
|
|
425
|
+
var control = {
|
|
426
|
+
mode: data.control_mode === "human" ? "human" : "agent",
|
|
427
|
+
pending: data.pending === true,
|
|
428
|
+
reason: text(data.reason),
|
|
429
|
+
expiresAt: text(data.expires_at),
|
|
430
|
+
};
|
|
431
|
+
this.setView(__assign(__assign({}, this.view), { control: control, error: control.mode === "human" ? null : this.view.error }));
|
|
432
|
+
this.syncPreview();
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "applyError", {
|
|
436
|
+
enumerable: false,
|
|
437
|
+
configurable: true,
|
|
438
|
+
writable: true,
|
|
439
|
+
value: function (data) {
|
|
440
|
+
var _a, _b;
|
|
441
|
+
var code = (_a = text(data.code)) !== null && _a !== void 0 ? _a : "browser_error";
|
|
442
|
+
var error = { code: code, message: (_b = text(data.message)) !== null && _b !== void 0 ? _b : "The browser could not do that.", at: this.timers.now() };
|
|
443
|
+
if (code === "no_browser") {
|
|
444
|
+
this.previewSession = null;
|
|
445
|
+
this.streamSeq = 0;
|
|
446
|
+
this.setView(__assign(__assign({}, this.view), { available: false, watching: false, error: error }));
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
this.setView(__assign(__assign({}, this.view), { error: error }));
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "cancelStop", {
|
|
453
|
+
enumerable: false,
|
|
454
|
+
configurable: true,
|
|
455
|
+
writable: true,
|
|
456
|
+
value: function () {
|
|
457
|
+
if (this.stopTimer != null)
|
|
458
|
+
this.timers.clearTimeout(this.stopTimer);
|
|
459
|
+
this.stopTimer = null;
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
Object.defineProperty(AgentBrowserChannel.prototype, "setView", {
|
|
463
|
+
enumerable: false,
|
|
464
|
+
configurable: true,
|
|
465
|
+
writable: true,
|
|
466
|
+
value: function (view) {
|
|
467
|
+
this.view = view;
|
|
468
|
+
this.listeners.forEach(function (listener) { return listener(); });
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
return AgentBrowserChannel;
|
|
472
|
+
}());
|
|
473
|
+
export { AgentBrowserChannel };
|
|
474
|
+
//# sourceMappingURL=agentBrowser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentBrowser.js","sourceRoot":"","sources":["../../../../../src/components/core/solid-agent/client/agentBrowser.ts"],"names":[],"mappings":";;;;;;;;;;;AA0DA,IAAM,MAAM,GAAiC,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;AACrG,IAAM,gBAAgB,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AACtD,4FAA4F;AAC5F,IAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,IAAM,OAAO,GAAkC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,uEAAuE,EAAE,CAAC;AAErJ,SAAS,WAAW,CAAC,SAAwB,EAAE,SAAgB;IAAhB,0BAAA,EAAA,gBAAgB;IAC3D,OAAO;QACH,SAAS,WAAA;QACT,SAAS,WAAA;QACT,KAAK,EAAE,MAAM;QACb,QAAQ,EAAE,gBAAgB;QAC1B,GAAG,EAAE,IAAI;QACT,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,EAAE;QACR,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;QACzE,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,IAAI;QACX,YAAY,EAAE,IAAI;KACrB,CAAC;AACN,CAAC;AAED,IAAM,IAAI,GAAG,UAAC,KAAc,IAAoB,OAAA,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAAnD,CAAmD,CAAC;AAEpG,2FAA2F;AAC3F,MAAM,UAAU,eAA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OAAO,uBAAM,IAAI,CAAC,IAAI,KAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,OAAA,IAAG,CAAC;gBACzE,OAAO;aACV;YACD,IAAI,CAAC,OAAO,uBAAM,IAAI,CAAC,IAAI,KAAE,KAAK,OAAA,IAAG,CAAC;QAC1C,CAAC;;;;;;eAED;YACI,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI;gBAAE,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACrE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAC1B,CAAC;;;;;;eAED,UAAgB,IAAsB;YAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACjB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAC,QAAQ,IAAK,OAAA,QAAQ,EAAE,EAAV,CAAU,CAAC,CAAC;QACrD,CAAC;;IACL,0BAAC;AAAD,CAAC,AAzPD,IAyPC","sourcesContent":["import type { AgentAction, AgentBrowserInputEvent } from \"../types\";\n\n/**\n * The live view of a session's browser (AgentHub browser tools).\n *\n * Kept outside Redux: frames are large base64 JPEGs at several per second. Status, tabs and control\n * state form a small immutable view for React (`subscribe`/`getView`, made for useSyncExternalStore);\n * frames go to `onFrame` listeners that draw them straight onto a canvas.\n *\n * The preview is a per-socket subscription. Viewers call `watch()` while they show the screen; the\n * channel asks for the preview once the browser is live and stops it shortly after the last viewer\n * leaves. A reconnect or a session switch (`sessionStarted`) subscribes again.\n */\n\nexport type AgentBrowserState = \"none\" | \"starting\" | \"live\" | \"state_saved\" | \"released\";\nexport type AgentBrowserControlMode = \"agent\" | \"human\";\nexport type AgentBrowserTab = { tab: string; url: string | null; title: string | null };\nexport type AgentBrowserControl = {\n mode: AgentBrowserControlMode;\n /** The user asked for the browser and waits for the agent's current step to finish. */\n pending: boolean;\n /** Why the agent handed the browser over (browser_handoff). */\n reason: string | null;\n /** ISO time when control returns to the agent automatically. */\n expiresAt: string | null;\n};\nexport type AgentBrowserError = { code: string; message: string; at: number };\n\nexport type AgentBrowserView = {\n sessionId: string | null;\n /** False once the agent said it has no browser tools. */\n available: boolean;\n state: AgentBrowserState;\n viewport: { width: number; height: number };\n url: string | null;\n title: string | null;\n tabs: AgentBrowserTab[];\n activeTab: string | null;\n control: AgentBrowserControl;\n /** When the agent last reopened a saved browser session (sign-ins and cookies restored). */\n restoredAt: number | null;\n /** The preview subscription is active on this socket. */\n watching: boolean;\n hasFrame: boolean;\n error: AgentBrowserError | null;\n /** False when the browser is only shown: the server sent browser_status with control false, so there is no \"Take control\". */\n controllable: boolean;\n};\n\n/** `seq` grows with every frame the channel accepts, also across preview restarts and reconnects. */\nexport type AgentBrowserFrame = { tab: string | null; url: string | null; title: string | null; format: string; data: string; seq: number };\n\n/** What the channel needs from AgentSocket. */\nexport type AgentBrowserSocket = {\n readonly currentSessionId: string | null;\n sendNow(action: AgentAction): boolean;\n};\n\nconst STATES: readonly AgentBrowserState[] = [\"none\", \"starting\", \"live\", \"state_saved\", \"released\"];\nconst DEFAULT_VIEWPORT = { width: 1280, height: 800 };\n/** Moving the screen between the side pane and the large view must not drop the preview. */\nconst STOP_DELAY_MS = 800;\nconst OFFLINE: Omit<AgentBrowserError, \"at\"> = { code: \"offline\", message: \"The chat is not connected to the agent. Try again once it reconnects.\" };\n\nfunction initialView(sessionId: string | null, available = true): AgentBrowserView {\n return {\n sessionId,\n available,\n state: \"none\",\n viewport: DEFAULT_VIEWPORT,\n url: null,\n title: null,\n tabs: [],\n activeTab: null,\n control: { mode: \"agent\", pending: false, reason: null, expiresAt: null },\n restoredAt: null,\n watching: false,\n hasFrame: false,\n error: null,\n controllable: true,\n };\n}\n\nconst text = (value: unknown): string | null => (typeof value === \"string\" && value ? value : null);\n\n/** Whether the panel should show: the browser runs, or the user has (or is offered) it. */\nexport function isBrowserActive(view: AgentBrowserView): boolean {\n return view.available && (view.state === \"live\" || view.state === \"starting\" || view.control.mode === \"human\");\n}\n\ntype Timers = { setTimeout: (callback: () => void, ms: number) => unknown; clearTimeout: (handle: any) => void; now: () => number };\n\nexport class AgentBrowserChannel {\n private view: AgentBrowserView = initialView(null);\n private listeners = new Set<() => void>();\n private frameListeners = new Set<(frame: AgentBrowserFrame) => void>();\n private frame: AgentBrowserFrame | null = null;\n private frameCount = 0;\n /** The relay's number of the last frame of the current subscription; a new subscription counts from 1 again. */\n private streamSeq = 0;\n /** This socket's number for its current subscription, which the runtime echoes on the frames. */\n private stream = 0;\n private watchers = 0;\n /** The session whose preview this socket subscribed to, if any. */\n private previewSession: string | null = null;\n private stopTimer: unknown = null;\n private readonly socket: AgentBrowserSocket;\n private readonly timers: Timers;\n\n constructor(socket: AgentBrowserSocket, timers?: Partial<Timers>) {\n this.socket = socket;\n this.timers = {\n setTimeout: timers?.setTimeout ?? ((callback, ms) => setTimeout(callback, ms)),\n clearTimeout: timers?.clearTimeout ?? ((handle) => clearTimeout(handle)),\n now: timers?.now ?? (() => Date.now()),\n };\n }\n\n readonly getView = (): AgentBrowserView => this.view;\n\n readonly subscribe = (listener: () => void) => {\n this.listeners.add(listener);\n return () => { this.listeners.delete(listener); };\n };\n\n onFrame(listener: (frame: AgentBrowserFrame) => void) {\n this.frameListeners.add(listener);\n return () => { this.frameListeners.delete(listener); };\n }\n\n get latestFrame(): AgentBrowserFrame | null {\n return this.frame;\n }\n\n /** Applies one inbound frame. Returns false for frames that are not about the browser. */\n handle(eventType: string, data: Record<string, any>): boolean {\n switch (eventType) {\n case \"browser_status\": this.applyStatus(data); return true;\n case \"browser_frame\": this.applyFrame(data); return true;\n case \"browser_tabs\": this.applyTabs(data); return true;\n case \"browser_control_state\": this.applyControl(data); return true;\n case \"browser_error\": this.applyError(data); return true;\n default: return false;\n }\n }\n\n /** The socket (re)confirmed a session. A new socket has no preview yet; another session starts empty. */\n sessionStarted(sessionId: string | null) {\n this.previewSession = null;\n this.streamSeq = 0;\n if (sessionId !== this.view.sessionId) {\n this.frame = null;\n this.setView(initialView(sessionId, this.view.available));\n } else if (this.view.watching) {\n this.setView({ ...this.view, watching: false });\n }\n this.syncPreview();\n }\n\n /** Forget the current session's browser (new chat, switched conversation, expired session). */\n reset() {\n this.cancelStop();\n if (this.previewSession) this.socket.sendNow({ action: \"browser_preview_stop\", session_id: this.previewSession });\n this.previewSession = null;\n this.streamSeq = 0;\n this.frame = null;\n this.setView(initialView(null, this.view.available));\n }\n\n /** Keep the preview running while the returned release function has not been called. */\n watch(): () => void {\n this.watchers += 1;\n this.cancelStop();\n this.syncPreview();\n let released = false;\n return () => {\n if (released) return;\n released = true;\n this.watchers -= 1;\n if (this.watchers > 0) return;\n this.cancelStop();\n this.stopTimer = this.timers.setTimeout(() => {\n this.stopTimer = null;\n this.syncPreview();\n }, STOP_DELAY_MS);\n };\n }\n\n requestControl(): boolean {\n return this.sendForSession((session_id) => ({ action: \"browser_control_request\", session_id }));\n }\n\n /** Give the browser back, or continue a handoff without taking it. The note goes to the agent. */\n release(note?: string | null): boolean {\n const trimmed = typeof note === \"string\" ? note.trim() : \"\";\n return this.sendForSession((session_id) => ({ action: \"browser_control_release\", session_id, note: trimmed || null }));\n }\n\n /** Forwards one input event while the user has the browser. Dropped (false) otherwise. */\n sendInput(event: AgentBrowserInputEvent): boolean {\n if (this.view.control.mode !== \"human\") return false;\n const sessionId = this.socket.currentSessionId;\n return !!sessionId && this.socket.sendNow({ action: \"browser_input\", session_id: sessionId, event });\n }\n\n navigate(url: string): boolean {\n const target = url.trim();\n if (!target) return false;\n return this.sendInput({ kind: \"navigation\", url: /^[a-z][a-z\\d+.-]*:/i.test(target) ? target : `https://${target}` });\n }\n\n navigation(action: \"back\" | \"forward\" | \"refresh\"): boolean {\n return this.sendInput({ kind: \"navigation\", action });\n }\n\n clearError() {\n if (this.view.error) this.setView({ ...this.view, error: null });\n }\n\n dispose() {\n this.cancelStop();\n this.listeners.clear();\n this.frameListeners.clear();\n }\n\n private sendForSession(build: (sessionId: string) => AgentAction): boolean {\n const sessionId = this.socket.currentSessionId;\n if (sessionId && this.socket.sendNow(build(sessionId))) return true;\n this.setView({ ...this.view, error: { ...OFFLINE, at: this.timers.now() } });\n return false;\n }\n\n private wantsPreview() {\n return this.watchers > 0 && isBrowserActive(this.view);\n }\n\n private syncPreview() {\n const sessionId = this.socket.currentSessionId;\n if (this.wantsPreview()) {\n if (!sessionId || this.previewSession === sessionId) return;\n this.stream += 1;\n if (this.socket.sendNow({ action: \"browser_preview_start\", session_id: sessionId, stream: this.stream })) {\n this.previewSession = sessionId;\n this.streamSeq = 0;\n this.setView({ ...this.view, watching: true });\n }\n } else if (this.watchers === 0 && this.previewSession) {\n this.socket.sendNow({ action: \"browser_preview_stop\", session_id: this.previewSession });\n this.previewSession = null;\n this.streamSeq = 0;\n this.setView({ ...this.view, watching: false });\n }\n }\n\n private applyStatus(data: Record<string, any>) {\n const state: AgentBrowserState = STATES.includes(data.state) ? data.state : this.view.state;\n const width = Number(data.viewport?.width);\n const height = Number(data.viewport?.height);\n const ended = state === \"none\" || state === \"released\" || state === \"state_saved\";\n if (ended) this.frame = null;\n this.setView({\n ...this.view,\n state,\n viewport: width > 0 && height > 0 ? { width, height } : this.view.viewport,\n url: text(data.url) ?? (ended ? null : this.view.url),\n title: ended ? null : this.view.title,\n activeTab: text(data.active_tab) ?? this.view.activeTab,\n tabs: ended ? [] : this.view.tabs,\n hasFrame: ended ? false : this.view.hasFrame,\n // Only an explicit \"control: false\" makes the browser view-only; a server that never sends it keeps control.\n controllable: data.control === false ? false : data.control === true ? true : this.view.controllable,\n control: data.control_mode === \"human\" || data.control_mode === \"agent\"\n ? { ...this.view.control, mode: data.control_mode } : this.view.control,\n restoredAt: data.restored === true ? this.timers.now() : this.view.restoredAt,\n });\n this.syncPreview();\n }\n\n private applyFrame(data: Record<string, any>) {\n if (typeof data.data !== \"string\" || !data.data || !this.previewSession) return;\n // A frame still on the way from an earlier subscription carries that subscription's number. Taking its\n // seq would hide the new subscription's frames, which the relay may number from 1 again.\n if (data.stream !== undefined && data.stream !== this.stream) return;\n const seq = Number(data.seq) || 0;\n // The relay numbers the frames of one subscription; an older one can still arrive after a newer one.\n if (seq > 0 && seq < this.streamSeq) return;\n if (seq > 0) this.streamSeq = seq;\n this.frameCount += 1;\n const frame: AgentBrowserFrame = {\n tab: text(data.tab), url: text(data.url), title: text(data.title),\n format: text(data.format) ?? \"jpeg\", data: data.data, seq: this.frameCount,\n };\n this.frame = frame;\n const url = frame.url ?? this.view.url;\n const title = frame.title ?? this.view.title;\n if (!this.view.hasFrame || url !== this.view.url || title !== this.view.title) {\n this.setView({ ...this.view, hasFrame: true, url, title });\n }\n this.frameListeners.forEach((listener) => listener(frame));\n }\n\n private applyTabs(data: Record<string, any>) {\n const tabs: AgentBrowserTab[] = Array.isArray(data.tabs)\n ? data.tabs.flatMap((tab: any) => tab && typeof tab.tab === \"string\"\n ? [{ tab: tab.tab, url: text(tab.url), title: text(tab.title) }] : [])\n : [];\n this.setView({ ...this.view, tabs, activeTab: text(data.active_tab) ?? null });\n }\n\n private applyControl(data: Record<string, any>) {\n const control: AgentBrowserControl = {\n mode: data.control_mode === \"human\" ? \"human\" : \"agent\",\n pending: data.pending === true,\n reason: text(data.reason),\n expiresAt: text(data.expires_at),\n };\n this.setView({ ...this.view, control, error: control.mode === \"human\" ? null : this.view.error });\n this.syncPreview();\n }\n\n private applyError(data: Record<string, any>) {\n const code = text(data.code) ?? \"browser_error\";\n const error = { code, message: text(data.message) ?? \"The browser could not do that.\", at: this.timers.now() };\n if (code === \"no_browser\") {\n this.previewSession = null;\n this.streamSeq = 0;\n this.setView({ ...this.view, available: false, watching: false, error });\n return;\n }\n this.setView({ ...this.view, error });\n }\n\n private cancelStop() {\n if (this.stopTimer != null) this.timers.clearTimeout(this.stopTimer);\n this.stopTimer = null;\n }\n\n private setView(view: AgentBrowserView) {\n this.view = view;\n this.listeners.forEach((listener) => listener());\n }\n}\n"]}
|