@myrialabs/clopen 0.4.40 → 0.4.42
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/.env.example +1 -1
- package/backend/artifacts/detect.ts +15 -3
- package/backend/artifacts/generate.ts +2 -2
- package/backend/artifacts/index.ts +12 -4
- package/backend/artifacts/markers.ts +24 -1
- package/backend/artifacts/matrix.ts +47 -3
- package/backend/artifacts/sync.test.ts +3 -3
- package/backend/artifacts/sync.ts +8 -20
- package/backend/artifacts/types.ts +9 -3
- package/backend/auth/permissions.ts +6 -11
- package/backend/auth/session-cleanup.ts +10 -1
- package/backend/auth/tokens.ts +9 -1
- package/backend/chat/stream-manager.ts +50 -0
- package/backend/database/crypto/secret-columns.ts +5 -1
- package/backend/database/index.ts +18 -0
- package/backend/database/migrations/079_merge_commands_into_skills.ts +222 -0
- package/backend/database/migrations/080_create_file_shares.ts +111 -0
- package/backend/database/migrations/081_create_push_subscriptions.ts +32 -0
- package/backend/database/migrations/082_create_git_identities.test.ts +186 -0
- package/backend/database/migrations/082_create_git_identities.ts +122 -0
- package/backend/database/migrations/index.ts +28 -0
- package/backend/database/queries/file-share-queries.ts +163 -0
- package/backend/database/queries/git-identity-queries.ts +290 -0
- package/backend/database/queries/index.ts +8 -4
- package/backend/database/queries/profile-queries.ts +5 -3
- package/backend/database/queries/push-subscription-queries.test.ts +90 -0
- package/backend/database/queries/push-subscription-queries.ts +99 -0
- package/backend/database/queries/skill-queries.ts +96 -18
- package/backend/engine/adapters/claude/environment.ts +11 -1
- package/backend/engine/adapters/claude/stream.ts +3 -2
- package/backend/engine/adapters/cline/stream.ts +3 -3
- package/backend/engine/adapters/codex/stream.ts +38 -6
- package/backend/engine/adapters/copilot/stream.ts +3 -3
- package/backend/engine/adapters/cursor/stream.ts +25 -3
- package/backend/engine/adapters/opencode/server.ts +26 -2
- package/backend/engine/adapters/opencode/stream.ts +8 -7
- package/backend/engine/adapters/pi/stream.ts +2 -2
- package/backend/engine/adapters/qwen/stream.ts +5 -3
- package/backend/engine/artifact-sync.ts +26 -20
- package/backend/engine/docs/artifacts.md +81 -22
- package/backend/engine/docs/quick-reference.md +2 -1
- package/backend/engine/resolve-model.test.ts +108 -0
- package/backend/engine/resolve-model.ts +53 -10
- package/backend/engine/structured-helpers.ts +22 -0
- package/backend/engine/types.ts +10 -0
- package/backend/files/file-shares.ts +369 -0
- package/backend/files/path-browsing.ts +27 -21
- package/backend/git/git-executor.ts +28 -2
- package/backend/git/git-service.ts +59 -40
- package/backend/git/identity/cli.test.ts +58 -0
- package/backend/git/identity/cli.ts +201 -0
- package/backend/git/identity/credential-helper.test.ts +242 -0
- package/backend/git/identity/env.test.ts +214 -0
- package/backend/git/identity/env.ts +193 -0
- package/backend/git/identity/import-local.test.ts +199 -0
- package/backend/git/identity/import-local.ts +141 -0
- package/backend/git/identity/index.ts +78 -0
- package/backend/git/identity/keys.ts +183 -0
- package/backend/git/identity/resolve.ts +140 -0
- package/backend/git/identity/scope-config.test.ts +145 -0
- package/backend/git/identity/scope-config.ts +175 -0
- package/backend/git/identity/service.ts +297 -0
- package/backend/http/files-shared.test.ts +505 -0
- package/backend/http/files-shared.ts +351 -0
- package/backend/http/push.ts +150 -0
- package/backend/index.ts +24 -0
- package/backend/instructions/index.ts +1 -1
- package/backend/instructions/sync.ts +30 -6
- package/backend/memory/compose.ts +2 -2
- package/backend/memory/consolidate.ts +2 -2
- package/backend/memory/extract/episodic.ts +2 -2
- package/backend/memory/judge.ts +2 -2
- package/backend/preview/browser/browser-console-manager.ts +214 -34
- package/backend/preview/browser/browser-pool.ts +526 -123
- package/backend/preview/browser/browser-preview-service.ts +192 -8
- package/backend/preview/browser/browser-tab-lifecycle.test.ts +240 -0
- package/backend/preview/browser/browser-tab-lifecycle.ts +495 -0
- package/backend/preview/browser/browser-tab-manager.ts +291 -65
- package/backend/preview/browser/capture-profile.ts +15 -1
- package/backend/preview/browser/types.ts +26 -1
- package/backend/profiles/service.ts +7 -6
- package/backend/push/sender.ts +172 -0
- package/backend/push/tags.ts +25 -0
- package/backend/push/vapid-keys.ts +77 -0
- package/backend/push/webpush-crypto.test.ts +200 -0
- package/backend/push/webpush-crypto.ts +231 -0
- package/backend/skills/detect.ts +28 -0
- package/backend/skills/index.ts +22 -4
- package/backend/skills/invoke.test.ts +114 -0
- package/backend/skills/invoke.ts +222 -0
- package/backend/skills/service.ts +194 -44
- package/backend/skills/spec.ts +35 -0
- package/backend/skills/sync.ts +85 -55
- package/backend/subagents/detect.ts +2 -3
- package/backend/subagents/sync.ts +15 -8
- package/backend/terminal/ptykit.ts +24 -0
- package/backend/work/pull-requests.ts +2 -2
- package/backend/ws/chat/stream.ts +100 -8
- package/backend/ws/files/index.ts +4 -0
- package/backend/ws/files/share.ts +95 -0
- package/backend/ws/git/branch-name.ts +2 -2
- package/backend/ws/git/branch.ts +17 -6
- package/backend/ws/git/commit-message.ts +2 -2
- package/backend/ws/git/commit.ts +6 -5
- package/backend/ws/git/conflict.ts +3 -2
- package/backend/ws/git/identity-context.ts +91 -0
- package/backend/ws/git/identity.ts +200 -0
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/remote.ts +57 -11
- package/backend/ws/index.ts +3 -4
- package/backend/ws/preview/browser/data.ts +60 -0
- package/backend/ws/preview/browser/interact.ts +6 -0
- package/backend/ws/preview/browser/tab-info.ts +9 -1
- package/backend/ws/preview/browser/tab.ts +64 -8
- package/backend/ws/preview/index.ts +21 -0
- package/backend/ws/profiles/crud.ts +2 -3
- package/backend/ws/skills/catalog.ts +5 -1
- package/backend/ws/skills/crud.ts +128 -22
- package/backend/ws/skills/index.ts +4 -1
- package/backend/ws/user/crud.ts +12 -3
- package/bin/clopen.ts +9 -0
- package/dist/assets/{index-D4igjF6e.js → index-BynqyvF4.js} +1 -1
- package/dist/assets/{index-DONNwiXm.js → index-DLoJsmNQ.js} +1 -1
- package/dist/assets/{main-BrfXH1bL.js → main-CUyZAmqt.js} +601 -592
- package/dist/assets/main-DVCW3cfr.css +1 -0
- package/dist/index.html +7 -2
- package/dist/sw.js +112 -0
- package/package.json +2 -2
- package/shared/constants/engine-tools.ts +31 -6
- package/shared/constants/notification-messages.ts +142 -0
- package/shared/types/git-identity.ts +112 -0
- package/shared/types/unified/stream.ts +7 -0
- package/backend/commands/detect.ts +0 -25
- package/backend/commands/index.ts +0 -9
- package/backend/commands/service.ts +0 -178
- package/backend/commands/store.ts +0 -45
- package/backend/commands/sync.ts +0 -94
- package/backend/database/queries/command-queries.ts +0 -82
- package/backend/ws/commands/crud.ts +0 -157
- package/backend/ws/commands/index.ts +0 -8
- package/dist/assets/main-CT1PygsW.css +0 -1
package/backend/memory/judge.ts
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { initializeEngine } from '$backend/engine';
|
|
28
|
-
import { resolveGenerationTarget } from '$backend/engine/resolve-model';
|
|
28
|
+
import { resolveGenerationTarget, GENERATION_SETTINGS } from '$backend/engine/resolve-model';
|
|
29
29
|
import { getDatabase } from '$backend/database';
|
|
30
30
|
import { graphQueries } from '$backend/database/queries/graph-queries';
|
|
31
31
|
import { debug } from '$shared/utils/logger';
|
|
@@ -62,7 +62,7 @@ async function generate<T>(model: MemoryModelConfig, prompt: string, schema: Rec
|
|
|
62
62
|
try {
|
|
63
63
|
const engine = await initializeEngine(model.engine);
|
|
64
64
|
if (!engine.generateStructured) return null;
|
|
65
|
-
const target = await resolveGenerationTarget(engine, model.modelId, model.providerSlug);
|
|
65
|
+
const target = await resolveGenerationTarget(engine, model.modelId, model.providerSlug, GENERATION_SETTINGS.memory);
|
|
66
66
|
const accountId = model.accountId ?? target.accountId;
|
|
67
67
|
return await engine.generateStructured<T>({
|
|
68
68
|
prompt,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import type { Page, ConsoleMessage as PuppeteerConsoleMessage, HTTPResponse } from 'puppeteer';
|
|
2
|
+
import type { JSHandle, Page, ConsoleMessage as PuppeteerConsoleMessage, HTTPResponse } from 'puppeteer';
|
|
3
3
|
import type { BrowserConsoleMessage, BrowserConsoleValue, BrowserTab } from './types';
|
|
4
4
|
|
|
5
5
|
import { debug } from '$shared/utils/logger';
|
|
@@ -8,6 +8,87 @@ import { debug } from '$shared/utils/logger';
|
|
|
8
8
|
const MAX_LOGS = 1000;
|
|
9
9
|
const TRIM_TO = 500;
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Per-tab ceiling on page-originated console traffic.
|
|
13
|
+
*
|
|
14
|
+
* Every message costs a structured payload to each viewer in the project, and
|
|
15
|
+
* a dev build in a re-render loop can produce thousands a second. Past the
|
|
16
|
+
* ceiling the messages are counted rather than carried, and the count is
|
|
17
|
+
* reported — a panel that says "4,812 dropped" is honest, whereas one that
|
|
18
|
+
* silently keeps up is the one that makes the whole workspace stutter.
|
|
19
|
+
*/
|
|
20
|
+
const RATE_WINDOW_MS = 1000;
|
|
21
|
+
const MAX_MESSAGES_PER_WINDOW = 60;
|
|
22
|
+
|
|
23
|
+
interface ConsoleBudget {
|
|
24
|
+
windowStart: number;
|
|
25
|
+
used: number;
|
|
26
|
+
dropped: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** What the manager needs to know about the world outside it. */
|
|
30
|
+
export interface ConsoleManagerDeps {
|
|
31
|
+
/**
|
|
32
|
+
* Whether anyone is actually looking at this tab.
|
|
33
|
+
*
|
|
34
|
+
* Console capture used to be unconditional: every tab, watched or not,
|
|
35
|
+
* paid a CDP round-trip per logged argument and a broadcast per message,
|
|
36
|
+
* for a panel that in most cases was not even open. Unwatched tabs now
|
|
37
|
+
* keep a text-only history — enough to read back when the panel opens,
|
|
38
|
+
* with none of the per-message cost.
|
|
39
|
+
*/
|
|
40
|
+
isWatched(sessionId: string): boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function shorten(text: string, limit = 200): string {
|
|
44
|
+
return text.length > limit ? `${text.slice(0, limit)}…` : text;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Read an argument's value straight off the CDP payload Chrome already sent.
|
|
49
|
+
*
|
|
50
|
+
* Primitives — which is what the overwhelming majority of logs are made of —
|
|
51
|
+
* arrive complete with the console event, so evaluating in the page to learn
|
|
52
|
+
* what `"hello"` is costs a round-trip for something already in hand. Returns
|
|
53
|
+
* null for anything that genuinely needs the page to describe it.
|
|
54
|
+
*/
|
|
55
|
+
function valueFromRemoteObject(handle: JSHandle): BrowserConsoleValue | null {
|
|
56
|
+
const remote = handle.remoteObject();
|
|
57
|
+
|
|
58
|
+
switch (remote.type) {
|
|
59
|
+
case 'string':
|
|
60
|
+
return { type: 'string', preview: shorten(String(remote.value), 1000) };
|
|
61
|
+
case 'number':
|
|
62
|
+
return { type: 'number', preview: remote.unserializableValue ?? String(remote.value) };
|
|
63
|
+
case 'boolean':
|
|
64
|
+
return { type: 'boolean', preview: String(remote.value) };
|
|
65
|
+
case 'undefined':
|
|
66
|
+
return { type: 'undefined', preview: 'undefined' };
|
|
67
|
+
case 'bigint':
|
|
68
|
+
return { type: 'bigint', preview: remote.unserializableValue ?? `${String(remote.value)}n` };
|
|
69
|
+
case 'symbol':
|
|
70
|
+
return { type: 'symbol', preview: remote.description ?? 'Symbol()' };
|
|
71
|
+
case 'function': {
|
|
72
|
+
// `description` is the function's source; its signature is the part
|
|
73
|
+
// before the body, which is what DevTools shows too.
|
|
74
|
+
const signature = (remote.description ?? '').split('{')[0].trim().replace(/^function\s*/, '');
|
|
75
|
+
return { type: 'function', preview: `ƒ ${shorten(signature || '()', 80)}` };
|
|
76
|
+
}
|
|
77
|
+
case 'object':
|
|
78
|
+
if (remote.subtype === 'null') return { type: 'null', preview: 'null' };
|
|
79
|
+
return null;
|
|
80
|
+
default:
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The shape of an object, without asking the page to walk it. */
|
|
86
|
+
function outlineFromRemoteObject(handle: JSHandle): BrowserConsoleValue {
|
|
87
|
+
const remote = handle.remoteObject();
|
|
88
|
+
const label = remote.className || remote.subtype || 'Object';
|
|
89
|
+
return { type: 'object', preview: remote.description ? shorten(remote.description) : label };
|
|
90
|
+
}
|
|
91
|
+
|
|
11
92
|
/**
|
|
12
93
|
* Flatten a page value into something renderable.
|
|
13
94
|
*
|
|
@@ -160,8 +241,87 @@ function normalizeConsoleType(type: string): BrowserConsoleMessage['type'] {
|
|
|
160
241
|
}
|
|
161
242
|
|
|
162
243
|
export class BrowserConsoleManager extends EventEmitter {
|
|
163
|
-
|
|
244
|
+
private deps: ConsoleManagerDeps;
|
|
245
|
+
private budgets = new Map<string, ConsoleBudget>();
|
|
246
|
+
|
|
247
|
+
constructor(deps: ConsoleManagerDeps) {
|
|
164
248
|
super();
|
|
249
|
+
this.deps = deps;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private isWatched(sessionId: string): boolean {
|
|
253
|
+
try {
|
|
254
|
+
return this.deps.isWatched(sessionId);
|
|
255
|
+
} catch {
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Whether this tab may spend another message this second.
|
|
262
|
+
*
|
|
263
|
+
* Rolling the window is also where a burst gets reported, so the drop is
|
|
264
|
+
* visible in the panel at the point it happened rather than inferred from
|
|
265
|
+
* a gap in the log.
|
|
266
|
+
*/
|
|
267
|
+
private admit(session: BrowserTab): boolean {
|
|
268
|
+
const now = Date.now();
|
|
269
|
+
let budget = this.budgets.get(session.id);
|
|
270
|
+
|
|
271
|
+
if (!budget || now - budget.windowStart >= RATE_WINDOW_MS) {
|
|
272
|
+
const dropped = budget?.dropped ?? 0;
|
|
273
|
+
budget = { windowStart: now, used: 0, dropped: 0 };
|
|
274
|
+
this.budgets.set(session.id, budget);
|
|
275
|
+
|
|
276
|
+
if (dropped > 0) {
|
|
277
|
+
budget.used += 1;
|
|
278
|
+
this.record(session, {
|
|
279
|
+
id: BrowserConsoleManager.makeId('console'),
|
|
280
|
+
type: 'warn',
|
|
281
|
+
text: `${dropped} more console message${dropped === 1 ? '' : 's'} dropped (rate limit)`,
|
|
282
|
+
timestamp: now
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (budget.used >= MAX_MESSAGES_PER_WINDOW) {
|
|
288
|
+
budget.dropped += 1;
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
budget.used += 1;
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Turn a console call's arguments into renderable values.
|
|
298
|
+
*
|
|
299
|
+
* Primitives are read off the event itself. Objects need the page to walk
|
|
300
|
+
* them, which is a round-trip per argument — worth paying while someone is
|
|
301
|
+
* watching, and not worth paying at all for a tab in the background, which
|
|
302
|
+
* gets the outline Chrome already sent instead.
|
|
303
|
+
*/
|
|
304
|
+
private async collectValues(
|
|
305
|
+
consoleMessage: PuppeteerConsoleMessage,
|
|
306
|
+
watched: boolean
|
|
307
|
+
): Promise<BrowserConsoleValue[]> {
|
|
308
|
+
const args = consoleMessage.args();
|
|
309
|
+
if (args.length === 0) return [];
|
|
310
|
+
|
|
311
|
+
// Still one Promise.all: the arguments that do need the page are walked
|
|
312
|
+
// concurrently, as they always were. What changed is how few of them
|
|
313
|
+
// reach that path at all.
|
|
314
|
+
return Promise.all(
|
|
315
|
+
args.map((arg) => {
|
|
316
|
+
const cheap = valueFromRemoteObject(arg);
|
|
317
|
+
if (cheap) return cheap;
|
|
318
|
+
if (!watched) return outlineFromRemoteObject(arg);
|
|
319
|
+
|
|
320
|
+
return arg
|
|
321
|
+
.evaluate(serializeConsoleValue as never)
|
|
322
|
+
.catch(() => ({ type: 'object', preview: '[unserializable]' }) as BrowserConsoleValue);
|
|
323
|
+
})
|
|
324
|
+
);
|
|
165
325
|
}
|
|
166
326
|
|
|
167
327
|
/**
|
|
@@ -169,7 +329,12 @@ export class BrowserConsoleManager extends EventEmitter {
|
|
|
169
329
|
* a counter the way DevTools does — a page logging inside a rAF loop would
|
|
170
330
|
* otherwise flood the panel and evict everything useful.
|
|
171
331
|
*/
|
|
172
|
-
private record(session: BrowserTab, message: BrowserConsoleMessage): void {
|
|
332
|
+
private record(session: BrowserTab, message: BrowserConsoleMessage, force = false): void {
|
|
333
|
+
// The buffer is always kept — it is what the panel reads back when it
|
|
334
|
+
// opens. Only the live broadcast is conditional: pushing a message to
|
|
335
|
+
// every viewer in the project for a tab none of them is looking at is
|
|
336
|
+
// work that ends in nothing being displayed.
|
|
337
|
+
const publish = force || this.isWatched(session.id);
|
|
173
338
|
const previous = session.consoleLogs[session.consoleLogs.length - 1];
|
|
174
339
|
|
|
175
340
|
if (
|
|
@@ -181,7 +346,7 @@ export class BrowserConsoleManager extends EventEmitter {
|
|
|
181
346
|
) {
|
|
182
347
|
previous.count = (previous.count ?? 1) + 1;
|
|
183
348
|
previous.timestamp = message.timestamp;
|
|
184
|
-
this.emit('console-message', { sessionId: session.id, message: previous });
|
|
349
|
+
if (publish) this.emit('console-message', { sessionId: session.id, message: previous });
|
|
185
350
|
return;
|
|
186
351
|
}
|
|
187
352
|
|
|
@@ -190,7 +355,7 @@ export class BrowserConsoleManager extends EventEmitter {
|
|
|
190
355
|
session.consoleLogs = session.consoleLogs.slice(-TRIM_TO);
|
|
191
356
|
}
|
|
192
357
|
|
|
193
|
-
this.emit('console-message', { sessionId: session.id, message });
|
|
358
|
+
if (publish) this.emit('console-message', { sessionId: session.id, message });
|
|
194
359
|
}
|
|
195
360
|
|
|
196
361
|
private static makeId(prefix: string): string {
|
|
@@ -207,6 +372,8 @@ export class BrowserConsoleManager extends EventEmitter {
|
|
|
207
372
|
return;
|
|
208
373
|
}
|
|
209
374
|
|
|
375
|
+
if (!this.admit(session)) return;
|
|
376
|
+
|
|
210
377
|
try {
|
|
211
378
|
const text = consoleMessage.text();
|
|
212
379
|
const type = normalizeConsoleType(consoleMessage.type());
|
|
@@ -226,16 +393,7 @@ export class BrowserConsoleManager extends EventEmitter {
|
|
|
226
393
|
// which make `jsonValue()` throw and used to be dropped entirely.
|
|
227
394
|
let values: BrowserConsoleValue[] = [];
|
|
228
395
|
try {
|
|
229
|
-
|
|
230
|
-
if (args.length > 0) {
|
|
231
|
-
values = await Promise.all(
|
|
232
|
-
args.map((arg) =>
|
|
233
|
-
arg
|
|
234
|
-
.evaluate(serializeConsoleValue as never)
|
|
235
|
-
.catch(() => ({ type: 'object', preview: '[unserializable]' }) as BrowserConsoleValue)
|
|
236
|
-
)
|
|
237
|
-
);
|
|
238
|
-
}
|
|
396
|
+
values = await this.collectValues(consoleMessage, this.isWatched(session.id));
|
|
239
397
|
} catch (error) {
|
|
240
398
|
debug.warn('preview', 'Could not extract console message args:', error);
|
|
241
399
|
}
|
|
@@ -265,6 +423,8 @@ export class BrowserConsoleManager extends EventEmitter {
|
|
|
265
423
|
return;
|
|
266
424
|
}
|
|
267
425
|
|
|
426
|
+
if (!this.admit(session)) return;
|
|
427
|
+
|
|
268
428
|
try {
|
|
269
429
|
const error = err as Error;
|
|
270
430
|
this.record(session, {
|
|
@@ -283,6 +443,7 @@ export class BrowserConsoleManager extends EventEmitter {
|
|
|
283
443
|
page.on('response', (response: HTTPResponse) => {
|
|
284
444
|
if (!session.consoleEnabled) return;
|
|
285
445
|
if (response.ok() || response.status() < 400) return;
|
|
446
|
+
if (!this.admit(session)) return;
|
|
286
447
|
|
|
287
448
|
try {
|
|
288
449
|
this.record(session, {
|
|
@@ -307,6 +468,7 @@ export class BrowserConsoleManager extends EventEmitter {
|
|
|
307
468
|
// would otherwise be invisible in the panel.
|
|
308
469
|
page.on('requestfailed', (request) => {
|
|
309
470
|
if (!session.consoleEnabled) return;
|
|
471
|
+
if (!this.admit(session)) return;
|
|
310
472
|
|
|
311
473
|
try {
|
|
312
474
|
const failure = request.failure();
|
|
@@ -331,6 +493,7 @@ export class BrowserConsoleManager extends EventEmitter {
|
|
|
331
493
|
if (!session) return false;
|
|
332
494
|
|
|
333
495
|
session.consoleLogs = [];
|
|
496
|
+
this.budgets.delete(session.id);
|
|
334
497
|
|
|
335
498
|
// Emit clear event
|
|
336
499
|
this.emit('console-clear', {
|
|
@@ -341,6 +504,11 @@ export class BrowserConsoleManager extends EventEmitter {
|
|
|
341
504
|
return true;
|
|
342
505
|
}
|
|
343
506
|
|
|
507
|
+
/** Drop a closed tab's rate-limit bookkeeping. */
|
|
508
|
+
forgetSession(sessionId: string): void {
|
|
509
|
+
this.budgets.delete(sessionId);
|
|
510
|
+
}
|
|
511
|
+
|
|
344
512
|
toggleConsoleLogging(session: BrowserTab, enabled: boolean): boolean {
|
|
345
513
|
if (!session) return false;
|
|
346
514
|
|
|
@@ -359,12 +527,16 @@ export class BrowserConsoleManager extends EventEmitter {
|
|
|
359
527
|
async executeConsoleCommand(session: BrowserTab, command: string): Promise<BrowserConsoleValue> {
|
|
360
528
|
if (!session) throw new Error('Session not found');
|
|
361
529
|
|
|
362
|
-
this.record(
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
530
|
+
this.record(
|
|
531
|
+
session,
|
|
532
|
+
{
|
|
533
|
+
id: BrowserConsoleManager.makeId('input'),
|
|
534
|
+
type: 'input',
|
|
535
|
+
text: command,
|
|
536
|
+
timestamp: Date.now()
|
|
537
|
+
},
|
|
538
|
+
true
|
|
539
|
+
);
|
|
368
540
|
|
|
369
541
|
try {
|
|
370
542
|
const outcome = await session.page.evaluate(
|
|
@@ -392,24 +564,32 @@ export class BrowserConsoleManager extends EventEmitter {
|
|
|
392
564
|
serializeConsoleValue.toString()
|
|
393
565
|
);
|
|
394
566
|
|
|
395
|
-
this.record(
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
567
|
+
this.record(
|
|
568
|
+
session,
|
|
569
|
+
{
|
|
570
|
+
id: BrowserConsoleManager.makeId('result'),
|
|
571
|
+
type: outcome.failed ? 'error' : 'result',
|
|
572
|
+
text: outcome.value.preview,
|
|
573
|
+
values: [outcome.value],
|
|
574
|
+
timestamp: Date.now()
|
|
575
|
+
},
|
|
576
|
+
true
|
|
577
|
+
);
|
|
402
578
|
|
|
403
579
|
return outcome.value;
|
|
404
580
|
} catch (error) {
|
|
405
581
|
const message = error instanceof Error ? error.message : String(error);
|
|
406
582
|
|
|
407
|
-
this.record(
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
583
|
+
this.record(
|
|
584
|
+
session,
|
|
585
|
+
{
|
|
586
|
+
id: BrowserConsoleManager.makeId('result'),
|
|
587
|
+
type: 'error',
|
|
588
|
+
text: message,
|
|
589
|
+
timestamp: Date.now()
|
|
590
|
+
},
|
|
591
|
+
true
|
|
592
|
+
);
|
|
413
593
|
|
|
414
594
|
throw error;
|
|
415
595
|
}
|