@ricsam/r5d-browser 0.0.136 → 0.0.137

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.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-browser",
3
- "version": "0.0.136",
3
+ "version": "0.0.137",
4
4
  "type": "commonjs"
5
5
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-browser",
3
- "version": "0.0.136",
3
+ "version": "0.0.137",
4
4
  "type": "module"
5
5
  }
@@ -0,0 +1,8 @@
1
+ import type { BrowserRuntime } from "../browser-runtime";
2
+ import type { BrowserExecutor } from "./keeper";
3
+ /**
4
+ * The supplied runtime must be constructed/retained by the independently supervised keeper.
5
+ * It is not recreated on adapter replacement. This uses the existing action implementation,
6
+ * including its retained tab IDs, cursor, CDP sessions and upload store, without profile copies.
7
+ */
8
+ export declare function browserRuntimeExecutor(runtime: Pick<BrowserRuntime, "execute">): BrowserExecutor;
@@ -0,0 +1,3 @@
1
+ import type { BrowserKeeperRuntimeFactory } from "../main";
2
+ /** Offline subprocess proof. No Chrome, network, profiles or user resources. */
3
+ export declare const createBrowserKeeperRuntime: BrowserKeeperRuntimeFactory;
@@ -0,0 +1,23 @@
1
+ import { BrowserKeeper, type BrowserAdapterPrincipal } from "./keeper";
2
+ import { type BrowserKeeperMessage } from "./protocol";
3
+ export type BrowserKeeperIpcOptions = {
4
+ keeper: BrowserKeeper;
5
+ socketPath: string;
6
+ /** Authentication must bind installation + user + owner; an unverified hello is NOT authority. */
7
+ authenticate: (token: string) => BrowserAdapterPrincipal | null;
8
+ maxFrameBytes?: number;
9
+ maxConnections?: number;
10
+ };
11
+ export type BrowserKeeperIpc = {
12
+ close(): Promise<void>;
13
+ };
14
+ /** One bounded JSON request/reply per private Unix connection. No raw requests/errors are logged. */
15
+ export declare function serveBrowserKeeper(options: BrowserKeeperIpcOptions): Promise<BrowserKeeperIpc>;
16
+ /** No automatic retries: caller resubmits the SAME operation ID to reconcile a lost response. */
17
+ export declare function callBrowserKeeper(options: {
18
+ socketPath: string;
19
+ token: string;
20
+ message: BrowserKeeperMessage;
21
+ timeoutMs?: number;
22
+ maxReplyBytes?: number;
23
+ }): Promise<unknown>;
@@ -0,0 +1,44 @@
1
+ import { RuntimeHello } from "@ricsam/r5d-api/runtime-protocol";
2
+ import { type LedgerOptions } from "./ledger";
3
+ import { BrowserOperation, type BrowserReceipt } from "./protocol";
4
+ /** Granted by the authenticated transport, NEVER inferred from hello or request fields. */
5
+ export type BrowserAdapterPrincipal = {
6
+ installationId: string;
7
+ userId: string;
8
+ ownerId: string;
9
+ };
10
+ /** This object and its browser handles live in the keeper, not in a replaceable socket adapter. */
11
+ export interface BrowserExecutor {
12
+ execute(operation: BrowserOperation): Promise<unknown>;
13
+ /** Keeper maintenance only; called after drain while still holding the exclusive ledger lock. */
14
+ dispose?(): Promise<void>;
15
+ }
16
+ export type BrowserKeeperOptions = LedgerOptions & {
17
+ executor: BrowserExecutor;
18
+ instanceId: string;
19
+ releaseId: string;
20
+ maxInFlight?: number;
21
+ maxPayloadBytes?: number;
22
+ };
23
+ export declare class BrowserKeeper {
24
+ readonly hello: RuntimeHello;
25
+ private readonly ledger;
26
+ private readonly executor;
27
+ private readonly inFlight;
28
+ private readonly queues;
29
+ private readonly maxInFlight;
30
+ private readonly maxPayloadBytes;
31
+ private readonly pruneTimer;
32
+ private closing;
33
+ private closePromise;
34
+ private storageFailed;
35
+ constructor(options: BrowserKeeperOptions);
36
+ /** Callable versioned boundary. Transport disconnect is deliberately not an AbortSignal. */
37
+ handle(input: unknown, principal: BrowserAdapterPrincipal): Promise<BrowserReceipt | {
38
+ ok: true;
39
+ } | null>;
40
+ private handleRequest;
41
+ private perform;
42
+ /** Maintenance only: adapter disconnection must NOT invoke close or executor disposal. */
43
+ close(): Promise<void>;
44
+ }
@@ -0,0 +1,41 @@
1
+ import { type OwnershipFence } from "@ricsam/r5d-api/runtime-protocol";
2
+ import { type BrowserOperation, type BrowserReceipt } from "./protocol";
3
+ export type LedgerOptions = {
4
+ directory: string;
5
+ installationId: string;
6
+ userId: string;
7
+ now?: () => number;
8
+ retentionMs?: number;
9
+ maxReceiptBytes?: number;
10
+ maxTotalReceiptBytes?: number;
11
+ maxOperations?: number;
12
+ maxClaims?: number;
13
+ maxLeaseMs?: number;
14
+ };
15
+ /** Local single-process authority. The exclusive SQLite lock is retained until close/crash. */
16
+ export declare class BrowserLedger {
17
+ private readonly db;
18
+ private readonly now;
19
+ readonly installationId: string;
20
+ readonly userId: string;
21
+ private readonly retentionMs;
22
+ private readonly maxReceiptBytes;
23
+ private readonly maxTotalReceiptBytes;
24
+ private readonly maxOperations;
25
+ private readonly maxClaims;
26
+ private readonly maxLeaseMs;
27
+ constructor(options: LedgerOptions);
28
+ assertIdentity(installationId: string, userId: string): void;
29
+ private claimRow;
30
+ assertFence(fence: OwnershipFence): void;
31
+ claim(fence: OwnershipFence, expiresAt: number, renew?: boolean): void;
32
+ release(fence: OwnershipFence): void;
33
+ private count;
34
+ find(operation: BrowserOperation, hash: string): BrowserReceipt | null;
35
+ admit(operation: BrowserOperation, hash: string): void;
36
+ running(operationId: string): void;
37
+ finish(operationId: string, state: "completed" | "cancelled" | "unknown", resultJson: string | null, reason?: BrowserReceipt["reason"]): void;
38
+ prune(): void;
39
+ private receipt;
40
+ close(): void;
41
+ }
@@ -0,0 +1,16 @@
1
+ import { type BrowserExecutor } from "./keeper";
2
+ export type BrowserKeeperRuntimeFactory = (input: {
3
+ installationId: string;
4
+ userId: string;
5
+ directory: string;
6
+ }) => Promise<{
7
+ executor: BrowserExecutor;
8
+ dispose?: () => Promise<void>;
9
+ }>;
10
+ /**
11
+ * Explicit, private, standalone launch surface. runtimeModule is trusted operator code, not a wire field.
12
+ * It must export createBrowserKeeperRuntime, constructing browserRuntimeExecutor(runtime) INSIDE this process.
13
+ */
14
+ export declare function startConfiguredBrowserKeeper(configPath: string): Promise<{
15
+ close(): Promise<void>;
16
+ }>;
@@ -0,0 +1,228 @@
1
+ import { z } from "zod";
2
+ import { RUNTIME_PROTOCOL } from "@ricsam/r5d-api/runtime-protocol";
3
+ export declare const BROWSER_KEEPER_CAPABILITY = "browser-operations.v1";
4
+ export declare const BrowserAction: z.ZodEnum<{
5
+ list_tabs: "list_tabs";
6
+ list_downloads: "list_downloads";
7
+ get_download: "get_download";
8
+ open_tab: "open_tab";
9
+ close_tab: "close_tab";
10
+ navigate: "navigate";
11
+ set_viewport: "set_viewport";
12
+ read_page: "read_page";
13
+ screenshot: "screenshot";
14
+ move_mouse: "move_mouse";
15
+ mouse_click: "mouse_click";
16
+ scroll: "scroll";
17
+ wait_for: "wait_for";
18
+ form_input: "form_input";
19
+ keyboard: "keyboard";
20
+ keyboard_type: "keyboard_type";
21
+ run_js: "run_js";
22
+ upload_begin: "upload_begin";
23
+ upload_chunk: "upload_chunk";
24
+ upload_attach: "upload_attach";
25
+ upload_abort: "upload_abort";
26
+ }>;
27
+ export declare const BrowserFence: z.ZodObject<{
28
+ installationId: z.ZodString;
29
+ resourceType: z.ZodString;
30
+ resourceId: z.ZodString;
31
+ ownerId: z.ZodString;
32
+ epoch: z.ZodNumber;
33
+ }, z.core.$strict>;
34
+ export declare const BrowserOperation: z.ZodObject<{
35
+ protocol: z.ZodLiteral<1>;
36
+ installationId: z.ZodString;
37
+ operationId: z.ZodString;
38
+ userId: z.ZodString;
39
+ sessionId: z.ZodOptional<z.ZodString>;
40
+ kind: z.ZodString;
41
+ fence: z.ZodObject<{
42
+ installationId: z.ZodString;
43
+ resourceType: z.ZodString;
44
+ resourceId: z.ZodString;
45
+ ownerId: z.ZodString;
46
+ epoch: z.ZodNumber;
47
+ }, z.core.$strict>;
48
+ payload: z.ZodUnknown;
49
+ }, z.core.$strict>;
50
+ export type BrowserOperation = z.infer<typeof BrowserOperation>;
51
+ export declare const BrowserKeeperRequest: z.ZodDiscriminatedUnion<[z.ZodObject<{
52
+ method: z.ZodLiteral<"claim">;
53
+ userId: z.ZodString;
54
+ fence: z.ZodObject<{
55
+ installationId: z.ZodString;
56
+ resourceType: z.ZodString;
57
+ resourceId: z.ZodString;
58
+ ownerId: z.ZodString;
59
+ epoch: z.ZodNumber;
60
+ }, z.core.$strict>;
61
+ expiresAt: z.ZodNumber;
62
+ }, z.core.$strict>, z.ZodObject<{
63
+ method: z.ZodLiteral<"renew">;
64
+ userId: z.ZodString;
65
+ fence: z.ZodObject<{
66
+ installationId: z.ZodString;
67
+ resourceType: z.ZodString;
68
+ resourceId: z.ZodString;
69
+ ownerId: z.ZodString;
70
+ epoch: z.ZodNumber;
71
+ }, z.core.$strict>;
72
+ expiresAt: z.ZodNumber;
73
+ }, z.core.$strict>, z.ZodObject<{
74
+ method: z.ZodLiteral<"release">;
75
+ userId: z.ZodString;
76
+ fence: z.ZodObject<{
77
+ installationId: z.ZodString;
78
+ resourceType: z.ZodString;
79
+ resourceId: z.ZodString;
80
+ ownerId: z.ZodString;
81
+ epoch: z.ZodNumber;
82
+ }, z.core.$strict>;
83
+ }, z.core.$strict>, z.ZodObject<{
84
+ method: z.ZodLiteral<"execute">;
85
+ operation: z.ZodObject<{
86
+ protocol: z.ZodLiteral<1>;
87
+ installationId: z.ZodString;
88
+ operationId: z.ZodString;
89
+ userId: z.ZodString;
90
+ sessionId: z.ZodOptional<z.ZodString>;
91
+ kind: z.ZodString;
92
+ fence: z.ZodObject<{
93
+ installationId: z.ZodString;
94
+ resourceType: z.ZodString;
95
+ resourceId: z.ZodString;
96
+ ownerId: z.ZodString;
97
+ epoch: z.ZodNumber;
98
+ }, z.core.$strict>;
99
+ payload: z.ZodUnknown;
100
+ }, z.core.$strict>;
101
+ }, z.core.$strict>, z.ZodObject<{
102
+ method: z.ZodLiteral<"inspect">;
103
+ operation: z.ZodObject<{
104
+ protocol: z.ZodLiteral<1>;
105
+ installationId: z.ZodString;
106
+ operationId: z.ZodString;
107
+ userId: z.ZodString;
108
+ sessionId: z.ZodOptional<z.ZodString>;
109
+ kind: z.ZodString;
110
+ fence: z.ZodObject<{
111
+ installationId: z.ZodString;
112
+ resourceType: z.ZodString;
113
+ resourceId: z.ZodString;
114
+ ownerId: z.ZodString;
115
+ epoch: z.ZodNumber;
116
+ }, z.core.$strict>;
117
+ payload: z.ZodUnknown;
118
+ }, z.core.$strict>;
119
+ }, z.core.$strict>], "method">;
120
+ export type BrowserKeeperRequest = z.infer<typeof BrowserKeeperRequest>;
121
+ export declare const BrowserKeeperMessage: z.ZodObject<{
122
+ hello: z.ZodObject<{
123
+ installationId: z.ZodString;
124
+ instanceId: z.ZodString;
125
+ releaseId: z.ZodString;
126
+ role: z.ZodEnum<{
127
+ web: "web";
128
+ scheduler: "scheduler";
129
+ runner: "runner";
130
+ gateway: "gateway";
131
+ "worker-adapter": "worker-adapter";
132
+ "browser-adapter": "browser-adapter";
133
+ executor: "executor";
134
+ keeper: "keeper";
135
+ storage: "storage";
136
+ }>;
137
+ protocol: z.ZodObject<{
138
+ min: z.ZodNumber;
139
+ max: z.ZodNumber;
140
+ }, z.core.$strict>;
141
+ capabilities: z.ZodArray<z.ZodString>;
142
+ }, z.core.$strict>;
143
+ request: z.ZodDiscriminatedUnion<[z.ZodObject<{
144
+ method: z.ZodLiteral<"claim">;
145
+ userId: z.ZodString;
146
+ fence: z.ZodObject<{
147
+ installationId: z.ZodString;
148
+ resourceType: z.ZodString;
149
+ resourceId: z.ZodString;
150
+ ownerId: z.ZodString;
151
+ epoch: z.ZodNumber;
152
+ }, z.core.$strict>;
153
+ expiresAt: z.ZodNumber;
154
+ }, z.core.$strict>, z.ZodObject<{
155
+ method: z.ZodLiteral<"renew">;
156
+ userId: z.ZodString;
157
+ fence: z.ZodObject<{
158
+ installationId: z.ZodString;
159
+ resourceType: z.ZodString;
160
+ resourceId: z.ZodString;
161
+ ownerId: z.ZodString;
162
+ epoch: z.ZodNumber;
163
+ }, z.core.$strict>;
164
+ expiresAt: z.ZodNumber;
165
+ }, z.core.$strict>, z.ZodObject<{
166
+ method: z.ZodLiteral<"release">;
167
+ userId: z.ZodString;
168
+ fence: z.ZodObject<{
169
+ installationId: z.ZodString;
170
+ resourceType: z.ZodString;
171
+ resourceId: z.ZodString;
172
+ ownerId: z.ZodString;
173
+ epoch: z.ZodNumber;
174
+ }, z.core.$strict>;
175
+ }, z.core.$strict>, z.ZodObject<{
176
+ method: z.ZodLiteral<"execute">;
177
+ operation: z.ZodObject<{
178
+ protocol: z.ZodLiteral<1>;
179
+ installationId: z.ZodString;
180
+ operationId: z.ZodString;
181
+ userId: z.ZodString;
182
+ sessionId: z.ZodOptional<z.ZodString>;
183
+ kind: z.ZodString;
184
+ fence: z.ZodObject<{
185
+ installationId: z.ZodString;
186
+ resourceType: z.ZodString;
187
+ resourceId: z.ZodString;
188
+ ownerId: z.ZodString;
189
+ epoch: z.ZodNumber;
190
+ }, z.core.$strict>;
191
+ payload: z.ZodUnknown;
192
+ }, z.core.$strict>;
193
+ }, z.core.$strict>, z.ZodObject<{
194
+ method: z.ZodLiteral<"inspect">;
195
+ operation: z.ZodObject<{
196
+ protocol: z.ZodLiteral<1>;
197
+ installationId: z.ZodString;
198
+ operationId: z.ZodString;
199
+ userId: z.ZodString;
200
+ sessionId: z.ZodOptional<z.ZodString>;
201
+ kind: z.ZodString;
202
+ fence: z.ZodObject<{
203
+ installationId: z.ZodString;
204
+ resourceType: z.ZodString;
205
+ resourceId: z.ZodString;
206
+ ownerId: z.ZodString;
207
+ epoch: z.ZodNumber;
208
+ }, z.core.$strict>;
209
+ payload: z.ZodUnknown;
210
+ }, z.core.$strict>;
211
+ }, z.core.$strict>], "method">;
212
+ }, z.core.$strict>;
213
+ export type BrowserKeeperMessage = z.infer<typeof BrowserKeeperMessage>;
214
+ export type BrowserReceipt = {
215
+ protocol: typeof RUNTIME_PROTOCOL;
216
+ installationId: string;
217
+ userId: string;
218
+ operationId: string;
219
+ payloadHash: string;
220
+ state: "accepted" | "running" | "completed" | "cancelled" | "unknown";
221
+ resultAvailable: boolean;
222
+ result?: unknown;
223
+ reason?: "keeper_restarted" | "executor_uncertain" | "stale_before_start" | "receipt_too_large";
224
+ };
225
+ export declare class BrowserKeeperError extends Error {
226
+ readonly code: string;
227
+ constructor(code: string);
228
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-browser",
3
- "version": "0.0.136",
3
+ "version": "0.0.137",
4
4
  "type": "module",
5
5
  "main": "./dist/cjs/main.cjs",
6
6
  "module": "./dist/mjs/main.mjs",
@@ -21,7 +21,7 @@
21
21
  "r5d-browser": "dist/cjs/main.cjs"
22
22
  },
23
23
  "dependencies": {
24
- "@ricsam/r5d-api": "^0.0.136",
24
+ "@ricsam/r5d-api": "^0.0.137",
25
25
  "playwright-core": "1.62.1",
26
26
  "ws": "^8.18.3"
27
27
  },