autokap 1.0.7 → 1.0.8
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/assets/cursors/macos.svg +4 -0
- package/assets/cursors/windows.svg +15 -0
- package/assets/skill/OPCODE-REFERENCE.md +607 -0
- package/assets/skill/README.md +39 -0
- package/assets/skill/SKILL.md +453 -468
- package/assets/skill/STUDIO-SKILL.md +476 -0
- package/assets/skill/references/examples.md +104 -0
- package/assets/skill/references/interactive-demo.md +225 -0
- package/assets/skill/references/mock-data.md +178 -0
- package/dist/action-verifier.d.ts +29 -0
- package/dist/action-verifier.js +133 -0
- package/dist/agent-action-recovery.d.ts +45 -0
- package/dist/agent-action-recovery.js +370 -0
- package/dist/agent-message-utils.d.ts +21 -0
- package/dist/agent-message-utils.js +77 -0
- package/dist/agent-url-utils.d.ts +30 -0
- package/dist/agent-url-utils.js +138 -0
- package/dist/agent.d.ts +92 -8
- package/dist/agent.js +2936 -781
- package/dist/ak-tree.d.ts +39 -0
- package/dist/ak-tree.js +368 -0
- package/dist/alt-text.d.ts +26 -0
- package/dist/alt-text.js +55 -0
- package/dist/auth-capture.d.ts +17 -0
- package/dist/auth-capture.js +164 -0
- package/dist/benchmark.d.ts +59 -0
- package/dist/benchmark.js +135 -0
- package/dist/browser-bar.d.ts +14 -6
- package/dist/browser-bar.js +145 -8
- package/dist/browser-pool.d.ts +7 -0
- package/dist/browser-pool.js +15 -5
- package/dist/browser-utils.d.ts +31 -0
- package/dist/browser-utils.js +97 -0
- package/dist/browser.d.ts +51 -1
- package/dist/browser.js +1481 -31
- package/dist/capture-alt-text.js +2 -1
- package/dist/capture-language-preflight.js +14 -0
- package/dist/capture-llm-page-identity.js +22 -10
- package/dist/capture-page-identity.d.ts +5 -7
- package/dist/capture-page-identity.js +211 -78
- package/dist/capture-preset-credentials.d.ts +50 -0
- package/dist/capture-preset-credentials.js +127 -0
- package/dist/capture-request-plan.d.ts +2 -2
- package/dist/capture-request-plan.js +64 -16
- package/dist/capture-run-optimizer.js +48 -33
- package/dist/capture-selector-memory.d.ts +5 -0
- package/dist/capture-selector-memory.js +18 -0
- package/dist/capture-strategy.d.ts +36 -0
- package/dist/capture-strategy.js +95 -0
- package/dist/capture-studio-sync.d.ts +1 -0
- package/dist/capture-studio-sync.js +9 -3
- package/dist/capture-surface-contract.d.ts +36 -0
- package/dist/capture-surface-contract.js +299 -0
- package/dist/capture-transition-engine.d.ts +28 -0
- package/dist/capture-transition-engine.js +292 -0
- package/dist/capture-variant-state.d.ts +2 -0
- package/dist/capture-variant-state.js +26 -0
- package/dist/capture-verification.d.ts +35 -0
- package/dist/capture-verification.js +95 -0
- package/dist/capture-viewport-lock.d.ts +48 -0
- package/dist/capture-viewport-lock.js +74 -0
- package/dist/circuit-breaker.d.ts +42 -0
- package/dist/circuit-breaker.js +119 -0
- package/dist/cli-config.d.ts +8 -1
- package/dist/cli-config.js +62 -6
- package/dist/cli-contract.d.ts +15 -0
- package/dist/cli-contract.js +167 -0
- package/dist/cli-runner-local.d.ts +12 -0
- package/dist/cli-runner-local.js +102 -0
- package/dist/cli-runner.d.ts +34 -0
- package/dist/cli-runner.js +433 -0
- package/dist/cli-utils.d.ts +0 -1
- package/dist/cli-utils.js +2 -5
- package/dist/cli.js +1005 -267
- package/dist/clip-orchestrator.js +9 -2
- package/dist/clip-postprocess.js +25 -16
- package/dist/cookie-dismiss.d.ts +2 -0
- package/dist/cookie-dismiss.js +48 -13
- package/dist/cost-logging.d.ts +8 -0
- package/dist/cost-logging.js +160 -46
- package/dist/cost-resolution-monitor.d.ts +16 -0
- package/dist/cost-resolution-monitor.js +34 -0
- package/dist/credential-templates.js +2 -2
- package/dist/cursor-overlay-script.d.ts +6 -0
- package/dist/cursor-overlay-script.js +169 -0
- package/dist/dom-css-purger.d.ts +65 -0
- package/dist/dom-css-purger.js +333 -0
- package/dist/dom-font-inliner.d.ts +45 -0
- package/dist/dom-font-inliner.js +148 -0
- package/dist/dom-patch-resolver.d.ts +52 -0
- package/dist/dom-patch-resolver.js +242 -0
- package/dist/dom-serializer.d.ts +82 -0
- package/dist/dom-serializer.js +378 -0
- package/dist/element-capture.d.ts +1 -41
- package/dist/element-capture.js +202 -446
- package/dist/env-validation.d.ts +5 -0
- package/dist/env-validation.js +29 -0
- package/dist/execution-schema.d.ts +4423 -0
- package/dist/execution-schema.js +507 -0
- package/dist/execution-types.d.ts +886 -0
- package/dist/execution-types.js +65 -0
- package/dist/fonts-loader.d.ts +14 -0
- package/dist/fonts-loader.js +55 -0
- package/dist/hybrid-navigator.js +12 -12
- package/dist/index.d.ts +9 -6
- package/dist/index.js +10 -4
- package/dist/legacy/agent-action-recovery.d.ts +45 -0
- package/dist/legacy/agent-action-recovery.js +370 -0
- package/dist/legacy/agent-message-utils.d.ts +21 -0
- package/dist/legacy/agent-message-utils.js +77 -0
- package/dist/legacy/agent-url-utils.d.ts +30 -0
- package/dist/legacy/agent-url-utils.js +138 -0
- package/dist/legacy/agent.d.ts +226 -0
- package/dist/legacy/agent.js +6666 -0
- package/dist/legacy/clip-orchestrator.d.ts +148 -0
- package/dist/legacy/clip-orchestrator.js +957 -0
- package/dist/legacy/credential-templates.d.ts +5 -0
- package/dist/legacy/credential-templates.js +60 -0
- package/dist/legacy/hybrid-navigator.d.ts +138 -0
- package/dist/legacy/hybrid-navigator.js +468 -0
- package/dist/legacy/llm-usage.d.ts +17 -0
- package/dist/legacy/llm-usage.js +45 -0
- package/dist/legacy/prompt-cache.d.ts +10 -0
- package/dist/legacy/prompt-cache.js +24 -0
- package/dist/legacy/prompts.d.ts +175 -0
- package/dist/legacy/prompts.js +1038 -0
- package/dist/legacy/tools.d.ts +4 -0
- package/dist/legacy/tools.js +216 -0
- package/dist/legacy/video-agent.d.ts +143 -0
- package/dist/legacy/video-agent.js +4788 -0
- package/dist/legacy/video-observation.d.ts +36 -0
- package/dist/legacy/video-observation.js +192 -0
- package/dist/legacy/video-planner.d.ts +12 -0
- package/dist/legacy/video-planner.js +501 -0
- package/dist/legacy/video-prompts.d.ts +37 -0
- package/dist/legacy/video-prompts.js +569 -0
- package/dist/legacy/video-tools.d.ts +3 -0
- package/dist/legacy/video-tools.js +59 -0
- package/dist/legacy/video-variant-state.d.ts +29 -0
- package/dist/legacy/video-variant-state.js +80 -0
- package/dist/legacy/vision-model.d.ts +17 -0
- package/dist/legacy/vision-model.js +74 -0
- package/dist/llm-healer.d.ts +63 -0
- package/dist/llm-healer.js +166 -0
- package/dist/llm-provider.d.ts +29 -0
- package/dist/llm-provider.js +80 -0
- package/dist/logger.d.ts +6 -2
- package/dist/logger.js +15 -1
- package/dist/mockup-html.js +35 -25
- package/dist/mockup.d.ts +95 -2
- package/dist/mockup.js +427 -166
- package/dist/mouse-animation.d.ts +2 -2
- package/dist/mouse-animation.js +34 -20
- package/dist/opcode-actions.d.ts +42 -0
- package/dist/opcode-actions.js +511 -0
- package/dist/opcode-runner.d.ts +51 -0
- package/dist/opcode-runner.js +770 -0
- package/dist/openrouter-client.d.ts +40 -0
- package/dist/openrouter-client.js +16 -0
- package/dist/overlay-engine.d.ts +24 -0
- package/dist/overlay-engine.js +176 -0
- package/dist/postcondition.d.ts +16 -0
- package/dist/postcondition.js +269 -0
- package/dist/program-patcher.d.ts +25 -0
- package/dist/program-patcher.js +44 -0
- package/dist/prompts.d.ts +13 -5
- package/dist/prompts.js +224 -351
- package/dist/provider-config.d.ts +12 -0
- package/dist/provider-config.js +15 -0
- package/dist/recovery-chain.d.ts +37 -0
- package/dist/recovery-chain.js +350 -0
- package/dist/remote-browser.d.ts +28 -4
- package/dist/remote-browser.js +60 -5
- package/dist/safari-browser-bar.d.ts +15 -0
- package/dist/safari-browser-bar.js +95 -0
- package/dist/safari-toolbar-asset.d.ts +15 -0
- package/dist/safari-toolbar-asset.js +12 -0
- package/dist/security.d.ts +2 -1
- package/dist/security.js +49 -10
- package/dist/selector-resolver.d.ts +34 -0
- package/dist/selector-resolver.js +181 -0
- package/dist/semantic-resolver.d.ts +35 -0
- package/dist/semantic-resolver.js +161 -0
- package/dist/server-capture-runtime.d.ts +5 -3
- package/dist/server-capture-runtime.js +42 -95
- package/dist/server-credit-usage.d.ts +2 -2
- package/dist/server-project-webhooks.d.ts +15 -1
- package/dist/server-project-webhooks.js +34 -8
- package/dist/server-screenshot-watermark.js +27 -5
- package/dist/session-profile.js +164 -1
- package/dist/sf-pro-symbols.d.ts +1 -0
- package/dist/sf-pro-symbols.js +55 -0
- package/dist/skill-packaging.d.ts +28 -0
- package/dist/skill-packaging.js +169 -0
- package/dist/smart-wait.d.ts +27 -0
- package/dist/smart-wait.js +81 -0
- package/dist/status-bar-render.d.ts +20 -0
- package/dist/status-bar-render.js +410 -0
- package/dist/status-bar.d.ts +9 -0
- package/dist/status-bar.js +298 -14
- package/dist/svg-browser-bar.d.ts +33 -0
- package/dist/svg-browser-bar.js +206 -0
- package/dist/svg-status-bar.d.ts +36 -0
- package/dist/svg-status-bar.js +597 -0
- package/dist/svg-text.d.ts +61 -0
- package/dist/svg-text.js +118 -0
- package/dist/tools.js +89 -451
- package/dist/types.d.ts +240 -5
- package/dist/types.js +23 -1
- package/dist/v2/action-verifier.d.ts +29 -0
- package/dist/v2/action-verifier.js +133 -0
- package/dist/v2/alt-text.d.ts +26 -0
- package/dist/v2/alt-text.js +55 -0
- package/dist/v2/benchmark.d.ts +59 -0
- package/dist/v2/benchmark.js +135 -0
- package/dist/v2/capture-strategy.d.ts +30 -0
- package/dist/v2/capture-strategy.js +67 -0
- package/dist/v2/capture-verification.d.ts +35 -0
- package/dist/v2/capture-verification.js +95 -0
- package/dist/v2/circuit-breaker.d.ts +42 -0
- package/dist/v2/circuit-breaker.js +119 -0
- package/dist/v2/cli-runner-local.d.ts +11 -0
- package/dist/v2/cli-runner-local.js +91 -0
- package/dist/v2/cli-runner.d.ts +34 -0
- package/dist/v2/cli-runner.js +300 -0
- package/dist/v2/compiler-prompts.d.ts +27 -0
- package/dist/v2/compiler-prompts.js +123 -0
- package/dist/v2/compiler.d.ts +37 -0
- package/dist/v2/compiler.js +147 -0
- package/dist/v2/explorer.d.ts +41 -0
- package/dist/v2/explorer.js +56 -0
- package/dist/v2/index.d.ts +37 -0
- package/dist/v2/index.js +31 -0
- package/dist/v2/llm-healer.d.ts +62 -0
- package/dist/v2/llm-healer.js +166 -0
- package/dist/v2/llm-provider.d.ts +29 -0
- package/dist/v2/llm-provider.js +80 -0
- package/dist/v2/opcode-runner.d.ts +47 -0
- package/dist/v2/opcode-runner.js +634 -0
- package/dist/v2/overlay-engine.d.ts +24 -0
- package/dist/v2/overlay-engine.js +150 -0
- package/dist/v2/postcondition.d.ts +16 -0
- package/dist/v2/postcondition.js +249 -0
- package/dist/v2/program-patcher.d.ts +25 -0
- package/dist/v2/program-patcher.js +44 -0
- package/dist/v2/recovery-chain.d.ts +30 -0
- package/dist/v2/recovery-chain.js +368 -0
- package/dist/v2/schema.d.ts +2580 -0
- package/dist/v2/schema.js +295 -0
- package/dist/v2/selector-resolver.d.ts +34 -0
- package/dist/v2/selector-resolver.js +181 -0
- package/dist/v2/semantic-resolver.d.ts +35 -0
- package/dist/v2/semantic-resolver.js +161 -0
- package/dist/v2/smart-wait.d.ts +27 -0
- package/dist/v2/smart-wait.js +81 -0
- package/dist/v2/types.d.ts +444 -0
- package/dist/v2/types.js +19 -0
- package/dist/v2/web-playwright-local.d.ts +69 -0
- package/dist/v2/web-playwright-local.js +392 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +5 -0
- package/dist/video-agent.js +18 -13
- package/dist/video-planner.js +2 -1
- package/dist/video-prompts.js +3 -3
- package/dist/web-playwright-local.d.ts +126 -0
- package/dist/web-playwright-local.js +819 -0
- package/dist/ws-auth.js +4 -1
- package/dist/ws-broadcast.d.ts +34 -0
- package/dist/ws-broadcast.js +85 -0
- package/dist/ws-connection-limits.d.ts +12 -0
- package/dist/ws-connection-limits.js +44 -0
- package/dist/ws-handler-utils.d.ts +32 -0
- package/dist/ws-handler-utils.js +139 -0
- package/dist/ws-handler.js +294 -164
- package/dist/ws-metrics-server.d.ts +9 -0
- package/dist/ws-metrics-server.js +31 -0
- package/dist/ws-server.js +41 -1
- package/package.json +51 -34
package/dist/ws-auth.js
CHANGED
|
@@ -33,12 +33,15 @@ export async function validateApiKey(rawKey) {
|
|
|
33
33
|
const supabase = getSupabase();
|
|
34
34
|
const { data, error } = await supabase
|
|
35
35
|
.from('api_keys')
|
|
36
|
-
.select('id, user_id, scopes, project_id')
|
|
36
|
+
.select('id, user_id, scopes, project_id, expires_at')
|
|
37
37
|
.eq('key_hash', hash)
|
|
38
38
|
.eq('revoked', false)
|
|
39
39
|
.single();
|
|
40
40
|
if (error || !data)
|
|
41
41
|
return null;
|
|
42
|
+
// Reject expired keys
|
|
43
|
+
if (data.expires_at && new Date(data.expires_at) < new Date())
|
|
44
|
+
return null;
|
|
42
45
|
// Update last_used_at (fire-and-forget)
|
|
43
46
|
supabase
|
|
44
47
|
.from('api_keys')
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Broadcast publisher for CLI capture events.
|
|
3
|
+
*
|
|
4
|
+
* Bridges WS-handler capture events to the web UI via Supabase Realtime
|
|
5
|
+
* Broadcast channels. The web client subscribes to the same channel
|
|
6
|
+
* name (`capture-live:{runId}`) and receives SSEEvent-shaped payloads
|
|
7
|
+
* that feed directly into the existing captureReducer.
|
|
8
|
+
*
|
|
9
|
+
* All broadcast calls are fire-and-forget — a broadcast failure must
|
|
10
|
+
* never block or fail the capture.
|
|
11
|
+
*/
|
|
12
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
13
|
+
/** Matches web/lib/types.ts SSEEvent shape. */
|
|
14
|
+
interface BroadcastSSEEvent {
|
|
15
|
+
type: string;
|
|
16
|
+
data: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
export interface CaptureBroadcast {
|
|
19
|
+
/** Fire-and-forget: sends an SSEEvent to the web UI. */
|
|
20
|
+
send(event: BroadcastSSEEvent): void;
|
|
21
|
+
/**
|
|
22
|
+
* Resize a base64 screenshot to a small thumbnail and broadcast it.
|
|
23
|
+
* The resizing is async but errors are swallowed.
|
|
24
|
+
*/
|
|
25
|
+
sendScreenshot(base64: string, meta?: {
|
|
26
|
+
lang?: string;
|
|
27
|
+
theme?: string;
|
|
28
|
+
targetId?: string;
|
|
29
|
+
}): void;
|
|
30
|
+
/** Unsubscribe and clean up the channel. */
|
|
31
|
+
close(): void;
|
|
32
|
+
}
|
|
33
|
+
export declare function createCaptureBroadcast(runId: string, supabase: SupabaseClient): CaptureBroadcast;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Broadcast publisher for CLI capture events.
|
|
3
|
+
*
|
|
4
|
+
* Bridges WS-handler capture events to the web UI via Supabase Realtime
|
|
5
|
+
* Broadcast channels. The web client subscribes to the same channel
|
|
6
|
+
* name (`capture-live:{runId}`) and receives SSEEvent-shaped payloads
|
|
7
|
+
* that feed directly into the existing captureReducer.
|
|
8
|
+
*
|
|
9
|
+
* All broadcast calls are fire-and-forget — a broadcast failure must
|
|
10
|
+
* never block or fail the capture.
|
|
11
|
+
*/
|
|
12
|
+
import sharp from 'sharp';
|
|
13
|
+
import { logger } from './logger.js';
|
|
14
|
+
const THUMBNAIL_WIDTH = 400;
|
|
15
|
+
const THUMBNAIL_QUALITY = 60;
|
|
16
|
+
async function resizeScreenshot(base64) {
|
|
17
|
+
const buf = Buffer.from(base64, 'base64');
|
|
18
|
+
const resized = await sharp(buf)
|
|
19
|
+
.resize({ width: THUMBNAIL_WIDTH, withoutEnlargement: true })
|
|
20
|
+
.jpeg({ quality: THUMBNAIL_QUALITY })
|
|
21
|
+
.toBuffer();
|
|
22
|
+
return resized.toString('base64');
|
|
23
|
+
}
|
|
24
|
+
export function createCaptureBroadcast(runId, supabase) {
|
|
25
|
+
const channelName = `capture-live:${runId}`;
|
|
26
|
+
let channel = null;
|
|
27
|
+
let ready = false;
|
|
28
|
+
// Subscribe asynchronously — events before subscription completes are dropped.
|
|
29
|
+
try {
|
|
30
|
+
channel = supabase.channel(channelName);
|
|
31
|
+
channel.subscribe((status) => {
|
|
32
|
+
if (status === 'SUBSCRIBED') {
|
|
33
|
+
ready = true;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
logger.debug(`[broadcast] Failed to create channel: ${err.message}`);
|
|
39
|
+
}
|
|
40
|
+
function broadcast(event) {
|
|
41
|
+
if (!ready || !channel)
|
|
42
|
+
return;
|
|
43
|
+
try {
|
|
44
|
+
channel.send({
|
|
45
|
+
type: 'broadcast',
|
|
46
|
+
event: 'capture_event',
|
|
47
|
+
payload: event,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Swallow — broadcast must never affect capture.
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
send(event) {
|
|
56
|
+
broadcast(event);
|
|
57
|
+
},
|
|
58
|
+
sendScreenshot(base64, meta) {
|
|
59
|
+
// Resize asynchronously, then broadcast.
|
|
60
|
+
resizeScreenshot(base64)
|
|
61
|
+
.then((thumbnail) => {
|
|
62
|
+
broadcast({
|
|
63
|
+
type: 'screenshot_update',
|
|
64
|
+
data: { base64: thumbnail, ...meta },
|
|
65
|
+
});
|
|
66
|
+
})
|
|
67
|
+
.catch(() => {
|
|
68
|
+
// Swallow resize errors.
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
close() {
|
|
72
|
+
if (channel) {
|
|
73
|
+
try {
|
|
74
|
+
supabase.removeChannel(channel);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Best effort.
|
|
78
|
+
}
|
|
79
|
+
channel = null;
|
|
80
|
+
ready = false;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=ws-broadcast.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory connection tracking for per-IP and per-user WS limits.
|
|
3
|
+
* Separate module to avoid circular imports between ws-server and ws-handler.
|
|
4
|
+
*/
|
|
5
|
+
import type { WebSocket } from 'ws';
|
|
6
|
+
export declare const MAX_CONNECTIONS_PER_IP = 10;
|
|
7
|
+
export declare function incrementIpConnections(ip: string): number;
|
|
8
|
+
export declare function decrementIpConnections(ip: string): void;
|
|
9
|
+
export declare function getIpConnectionCount(ip: string): number;
|
|
10
|
+
export declare function trackUserConnection(userId: string, ws: WebSocket): void;
|
|
11
|
+
export declare function untrackUserConnection(userId: string, ws: WebSocket): void;
|
|
12
|
+
export declare function getUserConnectionCount(userId: string): number;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory connection tracking for per-IP and per-user WS limits.
|
|
3
|
+
* Separate module to avoid circular imports between ws-server and ws-handler.
|
|
4
|
+
*/
|
|
5
|
+
// ── Per-IP connection tracking ─────────────────────────────────────
|
|
6
|
+
export const MAX_CONNECTIONS_PER_IP = 10;
|
|
7
|
+
const ipConnectionCounts = new Map();
|
|
8
|
+
export function incrementIpConnections(ip) {
|
|
9
|
+
const count = (ipConnectionCounts.get(ip) ?? 0) + 1;
|
|
10
|
+
ipConnectionCounts.set(ip, count);
|
|
11
|
+
return count;
|
|
12
|
+
}
|
|
13
|
+
export function decrementIpConnections(ip) {
|
|
14
|
+
const current = ipConnectionCounts.get(ip) ?? 1;
|
|
15
|
+
if (current <= 1)
|
|
16
|
+
ipConnectionCounts.delete(ip);
|
|
17
|
+
else
|
|
18
|
+
ipConnectionCounts.set(ip, current - 1);
|
|
19
|
+
}
|
|
20
|
+
export function getIpConnectionCount(ip) {
|
|
21
|
+
return ipConnectionCounts.get(ip) ?? 0;
|
|
22
|
+
}
|
|
23
|
+
// ── Per-user connection tracking ───────────────────────────────────
|
|
24
|
+
const userConnections = new Map();
|
|
25
|
+
export function trackUserConnection(userId, ws) {
|
|
26
|
+
let conns = userConnections.get(userId);
|
|
27
|
+
if (!conns) {
|
|
28
|
+
conns = new Set();
|
|
29
|
+
userConnections.set(userId, conns);
|
|
30
|
+
}
|
|
31
|
+
conns.add(ws);
|
|
32
|
+
}
|
|
33
|
+
export function untrackUserConnection(userId, ws) {
|
|
34
|
+
const conns = userConnections.get(userId);
|
|
35
|
+
if (conns) {
|
|
36
|
+
conns.delete(ws);
|
|
37
|
+
if (conns.size === 0)
|
|
38
|
+
userConnections.delete(userId);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function getUserConnectionCount(userId) {
|
|
42
|
+
return userConnections.get(userId)?.size ?? 0;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=ws-connection-limits.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone utility functions extracted from ws-handler.ts.
|
|
3
|
+
* These have zero closure dependencies and can be safely imported by any module.
|
|
4
|
+
*/
|
|
5
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
6
|
+
import type { RemoteBrowser } from './remote-browser.js';
|
|
7
|
+
import type { AgentResult, AgentRunHint, BrowserStorageState, BrowserSessionStorageState, CaptureHandoffContext, ExecutedAction, ValidatedSessionProfile } from './types.js';
|
|
8
|
+
export type PageRun = {
|
|
9
|
+
url: string;
|
|
10
|
+
prompt: string;
|
|
11
|
+
pageId: string | null;
|
|
12
|
+
};
|
|
13
|
+
export declare function urlsRoughlyMatch(left: string | null | undefined, right: string | null | undefined): boolean;
|
|
14
|
+
export declare function loadRunHints(supabase: SupabaseClient, presetId: string): Promise<AgentRunHint[] | undefined>;
|
|
15
|
+
export declare function buildPersistableProfile(previousProfile: ValidatedSessionProfile | undefined, storageState: BrowserStorageState | undefined, sessionStorage: BrowserSessionStorageState | undefined, currentUrl: string, lang: string, theme: 'light' | 'dark'): ValidatedSessionProfile;
|
|
16
|
+
export declare function inferAuthState(storageState: BrowserStorageState | undefined, sessionStorage: BrowserSessionStorageState | undefined): ValidatedSessionProfile['authState'];
|
|
17
|
+
export declare function buildPreverifiedAgentResult(assessment: string, verification: NonNullable<AgentResult['verification']>): AgentResult;
|
|
18
|
+
export declare function makeFailedAgentResult(message: string): AgentResult;
|
|
19
|
+
export declare function buildHandoffContext(params: {
|
|
20
|
+
browser: RemoteBrowser;
|
|
21
|
+
pageRun: PageRun;
|
|
22
|
+
profile: ValidatedSessionProfile;
|
|
23
|
+
lang: string;
|
|
24
|
+
theme: 'light' | 'dark';
|
|
25
|
+
selectorMemory: Record<string, string[]>;
|
|
26
|
+
actions?: ExecutedAction[];
|
|
27
|
+
agentResult?: AgentResult;
|
|
28
|
+
}): Promise<CaptureHandoffContext>;
|
|
29
|
+
export declare function restorePreparedPageState(browser: RemoteBrowser, viewport: {
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
}, preparedPageUrl: string): Promise<void>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone utility functions extracted from ws-handler.ts.
|
|
3
|
+
* These have zero closure dependencies and can be safely imported by any module.
|
|
4
|
+
*/
|
|
5
|
+
import { buildAgentRunHints } from './session-profile.js';
|
|
6
|
+
import { urlsPointToSameCaptureState, } from './capture-request-plan.js';
|
|
7
|
+
import { lockCaptureViewport, } from './capture-viewport-lock.js';
|
|
8
|
+
import { buildSequentialHandoffArtifacts, mergeSelectorMemory, } from './capture-run-optimizer.js';
|
|
9
|
+
import { isTerminalAgentResultSuccess, isStrongCheckpointVerified, } from './types.js';
|
|
10
|
+
export function urlsRoughlyMatch(left, right) {
|
|
11
|
+
return urlsPointToSameCaptureState(left, right);
|
|
12
|
+
}
|
|
13
|
+
export async function loadRunHints(supabase, presetId) {
|
|
14
|
+
try {
|
|
15
|
+
const { data } = await supabase
|
|
16
|
+
.from('agent_errors')
|
|
17
|
+
.select('error_type, message, user_response, created_at')
|
|
18
|
+
.eq('preset_id', presetId)
|
|
19
|
+
.order('created_at', { ascending: false })
|
|
20
|
+
.limit(10);
|
|
21
|
+
const hints = buildAgentRunHints((data ?? []));
|
|
22
|
+
return hints.length > 0 ? hints : undefined;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function buildPersistableProfile(previousProfile, storageState, sessionStorage, currentUrl, lang, theme) {
|
|
29
|
+
return {
|
|
30
|
+
storageState,
|
|
31
|
+
sessionStorage,
|
|
32
|
+
authState: previousProfile?.authState ?? inferAuthState(storageState, sessionStorage),
|
|
33
|
+
accountLabel: previousProfile?.accountLabel ?? null,
|
|
34
|
+
detectedLang: lang,
|
|
35
|
+
detectedTheme: theme,
|
|
36
|
+
validatedStartUrl: previousProfile?.validatedStartUrl ?? currentUrl,
|
|
37
|
+
lastKnownUrl: currentUrl,
|
|
38
|
+
summary: previousProfile?.summary ?? 'Validated browser state captured from a successful WS-driven run.',
|
|
39
|
+
validationStatus: previousProfile?.validationStatus ?? 'unknown',
|
|
40
|
+
lastUsedAt: new Date().toISOString(),
|
|
41
|
+
profileVersion: previousProfile?.profileVersion ?? 1,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function inferAuthState(storageState, sessionStorage) {
|
|
45
|
+
const structuredStorageState = storageState && typeof storageState === 'object' && !Array.isArray(storageState)
|
|
46
|
+
? storageState
|
|
47
|
+
: undefined;
|
|
48
|
+
const cookieCount = structuredStorageState?.cookies?.length ?? 0;
|
|
49
|
+
const originCount = structuredStorageState?.origins?.length ?? 0;
|
|
50
|
+
const sessionOriginCount = sessionStorage ? Object.keys(sessionStorage).length : 0;
|
|
51
|
+
return cookieCount > 0 || originCount > 0 || sessionOriginCount > 0
|
|
52
|
+
? 'authenticated'
|
|
53
|
+
: 'unknown';
|
|
54
|
+
}
|
|
55
|
+
export function buildPreverifiedAgentResult(assessment, verification) {
|
|
56
|
+
return {
|
|
57
|
+
success: true,
|
|
58
|
+
screenshotPath: null,
|
|
59
|
+
screenshots: [],
|
|
60
|
+
iterations: 0,
|
|
61
|
+
actions: [],
|
|
62
|
+
assessment,
|
|
63
|
+
usage: verification.usage,
|
|
64
|
+
runtimeStrategy: 'preverified_handoff',
|
|
65
|
+
deterministicRecoveryUsed: false,
|
|
66
|
+
evaluatorUsed: false,
|
|
67
|
+
verification,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function makeFailedAgentResult(message) {
|
|
71
|
+
return {
|
|
72
|
+
success: false,
|
|
73
|
+
screenshotPath: null,
|
|
74
|
+
assessment: message,
|
|
75
|
+
iterations: 0,
|
|
76
|
+
actions: [],
|
|
77
|
+
screenshots: [],
|
|
78
|
+
usage: [],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function resolvePersistedHandoffTrust(params) {
|
|
82
|
+
const agentResult = params.agentResult;
|
|
83
|
+
if (!agentResult
|
|
84
|
+
|| !isTerminalAgentResultSuccess(agentResult)
|
|
85
|
+
|| !isStrongCheckpointVerified(agentResult?.verification?.checkpointEvidence)) {
|
|
86
|
+
return 'degraded';
|
|
87
|
+
}
|
|
88
|
+
if (params.profile.validationStatus === 'repaired'
|
|
89
|
+
|| agentResult.deterministicRecoveryUsed
|
|
90
|
+
|| agentResult.evaluatorUsed
|
|
91
|
+
|| agentResult.runtimeStrategy === 'action_replay'
|
|
92
|
+
|| agentResult.runtimeStrategy === 'action_replay_fallback') {
|
|
93
|
+
return 'degraded';
|
|
94
|
+
}
|
|
95
|
+
return 'verified';
|
|
96
|
+
}
|
|
97
|
+
export async function buildHandoffContext(params) {
|
|
98
|
+
const handoffArtifacts = buildSequentialHandoffArtifacts(params.actions ?? []);
|
|
99
|
+
const trust = resolvePersistedHandoffTrust({
|
|
100
|
+
profile: params.profile,
|
|
101
|
+
agentResult: params.agentResult,
|
|
102
|
+
});
|
|
103
|
+
const derivedFromRepair = params.profile.validationStatus === 'repaired'
|
|
104
|
+
|| params.agentResult?.deterministicRecoveryUsed === true
|
|
105
|
+
|| params.agentResult?.evaluatorUsed === true;
|
|
106
|
+
const evidence = params.agentResult?.verification?.checkpointEvidence ?? null;
|
|
107
|
+
return {
|
|
108
|
+
previousPageId: params.pageRun.pageId,
|
|
109
|
+
previousPrompt: params.pageRun.prompt,
|
|
110
|
+
currentUrl: params.browser.currentPage.url() || params.pageRun.url,
|
|
111
|
+
pageTitle: await params.browser.currentPage.title().catch(() => null),
|
|
112
|
+
authState: params.profile.authState,
|
|
113
|
+
accountLabel: params.profile.accountLabel ?? null,
|
|
114
|
+
currentLang: params.lang,
|
|
115
|
+
currentTheme: params.theme,
|
|
116
|
+
summary: [
|
|
117
|
+
`Continue from ${params.pageRun.pageId ?? 'main'}.`,
|
|
118
|
+
`trust=${trust}`,
|
|
119
|
+
derivedFromRepair ? 'repair-derived=true' : null,
|
|
120
|
+
evidence?.strongSurfaceSignature ? `surface=${evidence.strongSurfaceSignature}` : null,
|
|
121
|
+
`url=${params.browser.currentPage.url() || params.pageRun.url}`,
|
|
122
|
+
].filter(Boolean).join(' '),
|
|
123
|
+
selectorHints: handoffArtifacts.selectorHints,
|
|
124
|
+
navigationHints: [],
|
|
125
|
+
selectorMemory: mergeSelectorMemory(params.selectorMemory, handoffArtifacts.selectorMemory),
|
|
126
|
+
trust,
|
|
127
|
+
strongCheckpointId: null,
|
|
128
|
+
derivedFromRepair,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export async function restorePreparedPageState(browser, viewport, preparedPageUrl) {
|
|
132
|
+
await lockCaptureViewport(browser, viewport, { settleMs: 0 });
|
|
133
|
+
if (!urlsRoughlyMatch(browser.currentPage.url(), preparedPageUrl)) {
|
|
134
|
+
await browser.navigateTo(preparedPageUrl);
|
|
135
|
+
}
|
|
136
|
+
await browser.dismissOverlays().catch(() => undefined);
|
|
137
|
+
await browser.wait(250);
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=ws-handler-utils.js.map
|