@praveen-palanisamy/agent-browser-runtime 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE +23 -0
  3. package/README.md +261 -0
  4. package/action.yml +185 -0
  5. package/dist/attribution.d.ts +22 -0
  6. package/dist/attribution.d.ts.map +1 -0
  7. package/dist/attribution.js +57 -0
  8. package/dist/attribution.js.map +1 -0
  9. package/dist/cli.d.ts +21 -0
  10. package/dist/cli.d.ts.map +1 -0
  11. package/dist/cli.js +242 -0
  12. package/dist/cli.js.map +1 -0
  13. package/dist/client/index.d.ts +9 -0
  14. package/dist/client/index.d.ts.map +1 -0
  15. package/dist/client/index.js +26 -0
  16. package/dist/client/index.js.map +1 -0
  17. package/dist/client/runner-client.d.ts +41 -0
  18. package/dist/client/runner-client.d.ts.map +1 -0
  19. package/dist/client/runner-client.js +98 -0
  20. package/dist/client/runner-client.js.map +1 -0
  21. package/dist/core/capture.d.ts +50 -0
  22. package/dist/core/capture.d.ts.map +1 -0
  23. package/dist/core/capture.js +129 -0
  24. package/dist/core/capture.js.map +1 -0
  25. package/dist/core/poster.d.ts +45 -0
  26. package/dist/core/poster.d.ts.map +1 -0
  27. package/dist/core/poster.js +132 -0
  28. package/dist/core/poster.js.map +1 -0
  29. package/dist/core/stores.d.ts +35 -0
  30. package/dist/core/stores.d.ts.map +1 -0
  31. package/dist/core/stores.js +32 -0
  32. package/dist/core/stores.js.map +1 -0
  33. package/dist/core/types.d.ts +138 -0
  34. package/dist/core/types.d.ts.map +1 -0
  35. package/dist/core/types.js +13 -0
  36. package/dist/core/types.js.map +1 -0
  37. package/dist/index.d.ts +20 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +48 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/platform.d.ts +6 -0
  42. package/dist/platform.d.ts.map +1 -0
  43. package/dist/platform.js +3 -0
  44. package/dist/platform.js.map +1 -0
  45. package/dist/protocol.d.ts +84 -0
  46. package/dist/protocol.d.ts.map +1 -0
  47. package/dist/protocol.js +24 -0
  48. package/dist/protocol.js.map +1 -0
  49. package/dist/providers/kernel.d.ts +53 -0
  50. package/dist/providers/kernel.d.ts.map +1 -0
  51. package/dist/providers/kernel.js +82 -0
  52. package/dist/providers/kernel.js.map +1 -0
  53. package/dist/providers/playwright.d.ts +88 -0
  54. package/dist/providers/playwright.d.ts.map +1 -0
  55. package/dist/providers/playwright.js +114 -0
  56. package/dist/providers/playwright.js.map +1 -0
  57. package/dist/providers/steel.d.ts +48 -0
  58. package/dist/providers/steel.d.ts.map +1 -0
  59. package/dist/providers/steel.js +79 -0
  60. package/dist/providers/steel.js.map +1 -0
  61. package/dist/service/config.d.ts +33 -0
  62. package/dist/service/config.d.ts.map +1 -0
  63. package/dist/service/config.js +59 -0
  64. package/dist/service/config.js.map +1 -0
  65. package/dist/service/index.d.ts +30 -0
  66. package/dist/service/index.d.ts.map +1 -0
  67. package/dist/service/index.js +53 -0
  68. package/dist/service/index.js.map +1 -0
  69. package/dist/service/live-proxy.d.ts +27 -0
  70. package/dist/service/live-proxy.d.ts.map +1 -0
  71. package/dist/service/live-proxy.js +146 -0
  72. package/dist/service/live-proxy.js.map +1 -0
  73. package/dist/service/runner.d.ts +35 -0
  74. package/dist/service/runner.d.ts.map +1 -0
  75. package/dist/service/runner.js +139 -0
  76. package/dist/service/runner.js.map +1 -0
  77. package/dist/service/serialized-provider.d.ts +20 -0
  78. package/dist/service/serialized-provider.d.ts.map +1 -0
  79. package/dist/service/serialized-provider.js +68 -0
  80. package/dist/service/serialized-provider.js.map +1 -0
  81. package/dist/service/server.d.ts +17 -0
  82. package/dist/service/server.d.ts.map +1 -0
  83. package/dist/service/server.js +159 -0
  84. package/dist/service/server.js.map +1 -0
  85. package/docs/AGENTS.md +46 -0
  86. package/docs/ARCHITECTURE.md +73 -0
  87. package/docs/DEPLOY.md +61 -0
  88. package/docs/GITHUB_ACTION.md +92 -0
  89. package/examples/demo-strategy/index.js +53 -0
  90. package/examples/demo-strategy/session.json +5 -0
  91. package/package.json +96 -0
package/dist/cli.js ADDED
@@ -0,0 +1,242 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * agent-browser-runtime (ABR) CLI
5
+ *
6
+ * agent-browser-runtime serve --strategies ./dist/strategies.js
7
+ * agent-browser-runtime health [--url http://localhost:8080]
8
+ * agent-browser-runtime probe --platform <id> --session ./session.json [--url … --token … | --local --strategies …]
9
+ * agent-browser-runtime post --platform <id> --session ./session.json --text "…" [--media url,…] [--link url]
10
+ * [--url … --token … | --local --strategies …] [--session-out file] [--out file]
11
+ *
12
+ * `serve` loads a CommonJS/ESM module whose default export (or `strategies`
13
+ * export) is an array of WebPostStrategy instances, then starts the runner
14
+ * using environment configuration (see service/config.ts).
15
+ *
16
+ * `probe` / `post` talk to a running runner by default. With `--local` they
17
+ * run in-process against local Chromium instead (used by the GitHub Action
18
+ * and for one-off jobs), which requires `--strategies`.
19
+ */
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.loadStrategies = loadStrategies;
25
+ const node_fs_1 = require("node:fs");
26
+ const node_path_1 = __importDefault(require("node:path"));
27
+ const node_url_1 = require("node:url");
28
+ const attribution_1 = require("./attribution");
29
+ const runner_client_1 = require("./client/runner-client");
30
+ const poster_1 = require("./core/poster");
31
+ const stores_1 = require("./core/stores");
32
+ const playwright_1 = require("./providers/playwright");
33
+ const service_1 = require("./service");
34
+ function parse(argv) {
35
+ const [cmd = 'help', ...rest] = argv;
36
+ const flags = {};
37
+ for (let i = 0; i < rest.length; i++) {
38
+ const a = rest[i];
39
+ if (!a.startsWith('--'))
40
+ continue;
41
+ const key = a.slice(2);
42
+ const next = rest[i + 1];
43
+ if (next && !next.startsWith('--')) {
44
+ flags[key] = next;
45
+ i++;
46
+ }
47
+ else {
48
+ flags[key] = true;
49
+ }
50
+ }
51
+ return { cmd, flags };
52
+ }
53
+ // tsc (CommonJS output) would rewrite a literal `import()` into `require()`,
54
+ // which cannot load ESM modules. Keep a real dynamic import for those.
55
+ const dynamicImport = new Function('u', 'return import(u)');
56
+ async function loadStrategies(spec) {
57
+ const abs = node_path_1.default.resolve(process.cwd(), spec);
58
+ let mod;
59
+ try {
60
+ mod = require(abs);
61
+ }
62
+ catch (err) {
63
+ if (err.code !== 'ERR_REQUIRE_ESM')
64
+ throw err;
65
+ mod = await dynamicImport((0, node_url_1.pathToFileURL)(abs).href);
66
+ }
67
+ const value = Array.isArray(mod) ? mod : (mod.default ?? mod.strategies);
68
+ const list = typeof value === 'function' ? await value() : value;
69
+ if (!Array.isArray(list) || list.length === 0) {
70
+ throw new Error(`${spec} must export a non-empty WebPostStrategy[] (default or "strategies")`);
71
+ }
72
+ return list;
73
+ }
74
+ function usage() {
75
+ console.log(`${attribution_1.PROJECT.name} v${(0, attribution_1.packageVersion)()} — ${attribution_1.PROJECT.repository}
76
+
77
+ Commands
78
+ serve --strategies <module> start the runner HTTP service (env-configured)
79
+ health [--url <runner>] [--token <t>] check a running runner
80
+ probe --platform <id> --session <file> is the stored session still authenticated?
81
+ post --platform <id> --session <file> --text <t> [--media a,b] [--link url]
82
+ run one job with the stored session
83
+
84
+ Target (probe/post)
85
+ --url <runner> --token <t> call a running runner (default; env AGENT_RUNNER_URL/_TOKEN)
86
+ --local --strategies <module> run in-process with local Chromium instead
87
+ --session-out <file> write the refreshed session state here
88
+ --out <file> write the JSON result here (also printed)
89
+ --workspace <id> --account <id> job identity (default: cli)
90
+
91
+ Environment (serve): AGENT_RUNNER_TOKEN, AGENT_RUNNER_PUBLIC_URL, PORT,
92
+ AGENT_RUNNER_JOB_PROVIDER, AGENT_RUNNER_CAPTURE_PROVIDER (local|steel|kernel),
93
+ STEEL_API_URL, STEEL_API_KEY, KERNEL_API_KEY, AGENT_RUNNER_CAPTURE_TTL_MS, AGENT_RUNNER_PACING`);
94
+ }
95
+ function readJob(str) {
96
+ const file = str('session');
97
+ const platform = str('platform');
98
+ if (!file || !platform) {
99
+ throw new Error('--platform and --session are required');
100
+ }
101
+ return {
102
+ platform,
103
+ session: JSON.parse((0, node_fs_1.readFileSync)(file, 'utf8')),
104
+ workspaceId: str('workspace', 'cli'),
105
+ accountId: str('account', 'cli'),
106
+ sessionOut: str('session-out'),
107
+ out: str('out'),
108
+ };
109
+ }
110
+ function readContent(str) {
111
+ const file = str('content');
112
+ if (file) {
113
+ return JSON.parse((0, node_fs_1.readFileSync)(file, 'utf8'));
114
+ }
115
+ const text = str('text');
116
+ if (!text)
117
+ throw new Error('--text (or --content <file.json>) is required');
118
+ const media = str('media');
119
+ return {
120
+ text,
121
+ mediaUrls: media ? media.split(',').filter(Boolean) : undefined,
122
+ link: str('link'),
123
+ };
124
+ }
125
+ function emit(job, result) {
126
+ const { refreshedSession, ...rest } = result;
127
+ if (refreshedSession && job.sessionOut) {
128
+ (0, node_fs_1.writeFileSync)(job.sessionOut, JSON.stringify(refreshedSession), 'utf8');
129
+ }
130
+ const printable = {
131
+ ...rest,
132
+ refreshedSession: refreshedSession
133
+ ? job.sessionOut
134
+ ? `<written to ${job.sessionOut}>`
135
+ : '<omitted>'
136
+ : undefined,
137
+ };
138
+ const text = JSON.stringify(printable, null, 2);
139
+ if (job.out)
140
+ (0, node_fs_1.writeFileSync)(job.out, text, 'utf8');
141
+ console.log(text);
142
+ }
143
+ async function localPoster(job, strategiesSpec, pacing) {
144
+ if (!strategiesSpec) {
145
+ throw new Error('--local requires --strategies <module>');
146
+ }
147
+ const key = { workspaceId: job.workspaceId, accountId: job.accountId };
148
+ const store = new stores_1.InMemorySessionStore([[key, job.session]]);
149
+ const poster = new poster_1.AgentPoster(new playwright_1.LocalBrowserSessionProvider(), store, {
150
+ pacing,
151
+ });
152
+ for (const s of await loadStrategies(strategiesSpec))
153
+ poster.register(s);
154
+ return { poster, store };
155
+ }
156
+ function refreshedFrom(store, job) {
157
+ const key = { workspaceId: job.workspaceId, accountId: job.accountId };
158
+ const state = store.peek(key);
159
+ return state && state !== job.session ? state : undefined;
160
+ }
161
+ async function main() {
162
+ const { cmd, flags } = parse(process.argv.slice(2));
163
+ const str = (k, fallback) => typeof flags[k] === 'string' ? flags[k] : fallback;
164
+ if (cmd === 'version' || flags.version === true) {
165
+ console.log((0, attribution_1.packageVersion)());
166
+ return;
167
+ }
168
+ if (cmd === 'serve') {
169
+ const spec = str('strategies');
170
+ if (!spec)
171
+ throw new Error('--strategies <module> is required');
172
+ (0, service_1.startRunner)({ strategies: await loadStrategies(spec) });
173
+ return;
174
+ }
175
+ if (cmd !== 'health' && cmd !== 'probe' && cmd !== 'post') {
176
+ usage();
177
+ if (cmd !== 'help')
178
+ process.exitCode = 1;
179
+ return;
180
+ }
181
+ const local = flags.local === true;
182
+ const pacing = process.env.AGENT_RUNNER_PACING !== 'false';
183
+ if (cmd === 'health') {
184
+ const client = new runner_client_1.AgentRunnerClient({
185
+ baseUrl: str('url', process.env.AGENT_RUNNER_URL || 'http://localhost:8080'),
186
+ token: str('token', process.env.AGENT_RUNNER_TOKEN || ''),
187
+ });
188
+ console.log(JSON.stringify(await client.health(), null, 2));
189
+ return;
190
+ }
191
+ const job = readJob(str);
192
+ const ident = {
193
+ workspaceId: job.workspaceId,
194
+ accountId: job.accountId,
195
+ platform: job.platform,
196
+ };
197
+ if (local) {
198
+ const { poster, store } = await localPoster(job, str('strategies'), pacing);
199
+ if (cmd === 'probe') {
200
+ const res = await poster.probe(ident);
201
+ emit(job, { ...res, refreshedSession: refreshedFrom(store, job) });
202
+ if (!res.authenticated)
203
+ process.exitCode = 2;
204
+ return;
205
+ }
206
+ const res = await poster.post({
207
+ ...ident,
208
+ content: readContent(str),
209
+ });
210
+ emit(job, { ...res, refreshedSession: refreshedFrom(store, job) });
211
+ if (!res.ok)
212
+ process.exitCode = res.uncertain ? 3 : 2;
213
+ return;
214
+ }
215
+ const client = new runner_client_1.AgentRunnerClient({
216
+ baseUrl: str('url', process.env.AGENT_RUNNER_URL || 'http://localhost:8080'),
217
+ token: str('token', process.env.AGENT_RUNNER_TOKEN || ''),
218
+ });
219
+ if (cmd === 'probe') {
220
+ const res = await client.probe({ ...ident, session: job.session });
221
+ emit(job, res);
222
+ if (!res.authenticated)
223
+ process.exitCode = 2;
224
+ return;
225
+ }
226
+ const res = await client.post({
227
+ ...ident,
228
+ jobId: str('job-id', `cli-${Date.now()}`),
229
+ session: job.session,
230
+ content: readContent(str),
231
+ });
232
+ emit(job, res);
233
+ if (!res.ok)
234
+ process.exitCode = res.uncertain ? 3 : 2;
235
+ }
236
+ if (require.main === module) {
237
+ main().catch((err) => {
238
+ console.error(err instanceof Error ? err.message : err);
239
+ process.exit(1);
240
+ });
241
+ }
242
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AACA;;;;;;;;;;;;;;;;GAgBG;;;;;;AAEH,qCAAsD;AACtD,0DAA6B;AAC7B,uCAAyC;AACzC,+CAAwD;AACxD,0DAA2D;AAC3D,0CAA4C;AAC5C,0CAAqD;AAOrD,uDAAqE;AACrE,uCAAwC;AAIxC,SAAS,KAAK,CAAC,IAAc;IAC3B,MAAM,CAAC,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACrC,MAAM,KAAK,GAAU,EAAE,CAAC;IACxB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,SAAS;QAClC,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC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functions,
3
+ * queue workers) that call a running agent runner over HTTP.
4
+ */
5
+ export type { AgentPostContent, AgentPostFailureStage, AgentPostResult, AgentPostVerification, AgentSessionState, StorageState, } from '../core/types';
6
+ export type { PlatformId } from '../platform';
7
+ export * from '../protocol';
8
+ export { AgentRunnerClient, type AgentRunnerClientOptions, AgentRunnerError, } from './runner-client';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACV,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,cAAc,aAAa,CAAC;AAC5B,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,gBAAgB,GACjB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /**
3
+ * Playwright-free entry point for orchestrators (serverless functions,
4
+ * queue workers) that call a running agent runner over HTTP.
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.AgentRunnerError = exports.AgentRunnerClient = void 0;
22
+ __exportStar(require("../protocol"), exports);
23
+ var runner_client_1 = require("./runner-client");
24
+ Object.defineProperty(exports, "AgentRunnerClient", { enumerable: true, get: function () { return runner_client_1.AgentRunnerClient; } });
25
+ Object.defineProperty(exports, "AgentRunnerError", { enumerable: true, get: function () { return runner_client_1.AgentRunnerError; } });
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;AAWH,8CAA4B;AAC5B,iDAIyB;AAHvB,kHAAA,iBAAiB,OAAA;AAEjB,iHAAA,gBAAgB,OAAA"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * HTTP client for the agent runner service, for orchestrators such as
3
+ * serverless functions or queue workers.
4
+ *
5
+ * Deliberately free of Playwright imports so it can be bundled anywhere.
6
+ * Auth is a shared bearer token (`AGENT_RUNNER_TOKEN`) kept in a secret
7
+ * manager on both sides.
8
+ */
9
+ import { type RunnerCaptureFinishRequest, type RunnerCaptureFinishResponse, type RunnerCaptureStartRequest, type RunnerCaptureStartResponse, type RunnerPostRequest, type RunnerPostResponse, type RunnerProbeRequest, type RunnerProbeResponse } from '../protocol';
10
+ export type AgentRunnerClientOptions = {
11
+ baseUrl: string;
12
+ token: string;
13
+ /** Per-request timeout; posting with media can take a while. */
14
+ timeoutMs?: number;
15
+ fetchImpl?: typeof fetch;
16
+ };
17
+ export declare class AgentRunnerError extends Error {
18
+ readonly status: number;
19
+ readonly transient: boolean;
20
+ constructor(message: string, status: number, transient: boolean);
21
+ }
22
+ export declare class AgentRunnerClient {
23
+ private opts;
24
+ private readonly fetchImpl;
25
+ private readonly baseUrl;
26
+ constructor(opts: AgentRunnerClientOptions);
27
+ static isConfigured(env: {
28
+ AGENT_RUNNER_URL?: string;
29
+ AGENT_RUNNER_TOKEN?: string;
30
+ }): boolean;
31
+ post(req: RunnerPostRequest): Promise<RunnerPostResponse>;
32
+ probe(req: RunnerProbeRequest): Promise<RunnerProbeResponse>;
33
+ captureStart(req: RunnerCaptureStartRequest): Promise<RunnerCaptureStartResponse>;
34
+ captureFinish(req: RunnerCaptureFinishRequest): Promise<RunnerCaptureFinishResponse>;
35
+ captureCancel(req: RunnerCaptureFinishRequest): Promise<{
36
+ ok: true;
37
+ }>;
38
+ health(): Promise<boolean>;
39
+ private call;
40
+ }
41
+ //# sourceMappingURL=runner-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner-client.d.ts","sourceRoot":"","sources":["../../src/client/runner-client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,CAAC;AAEF,qBAAa,gBAAiB,SAAQ,KAAK;IAGvC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,SAAS,EAAE,OAAO;IAH7B,YACE,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,OAAO,EAI5B;CACF;AAED,qBAAa,iBAAiB;IAIhB,OAAO,CAAC,IAAI;IAHxB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,YAAoB,IAAI,EAAE,wBAAwB,EAGjD;IAED,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE;QACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC7B,GAAG,OAAO,CAEV;IAED,IAAI,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAExD;IAED,KAAK,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAE3D;IAED,YAAY,CACV,GAAG,EAAE,yBAAyB,GAC7B,OAAO,CAAC,0BAA0B,CAAC,CAKrC;IAED,aAAa,CACX,GAAG,EAAE,0BAA0B,GAC9B,OAAO,CAAC,2BAA2B,CAAC,CAKtC;IAED,aAAa,CAAC,GAAG,EAAE,0BAA0B,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,IAAI,CAAA;KAAE,CAAC,CAEpE;IAEK,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAS/B;YAEa,IAAI;CAwCnB"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ /**
3
+ * HTTP client for the agent runner service, for orchestrators such as
4
+ * serverless functions or queue workers.
5
+ *
6
+ * Deliberately free of Playwright imports so it can be bundled anywhere.
7
+ * Auth is a shared bearer token (`AGENT_RUNNER_TOKEN`) kept in a secret
8
+ * manager on both sides.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.AgentRunnerClient = exports.AgentRunnerError = void 0;
12
+ const protocol_1 = require("../protocol");
13
+ class AgentRunnerError extends Error {
14
+ status;
15
+ transient;
16
+ constructor(message, status, transient) {
17
+ super(message);
18
+ this.status = status;
19
+ this.transient = transient;
20
+ this.name = 'AgentRunnerError';
21
+ }
22
+ }
23
+ exports.AgentRunnerError = AgentRunnerError;
24
+ class AgentRunnerClient {
25
+ opts;
26
+ fetchImpl;
27
+ baseUrl;
28
+ constructor(opts) {
29
+ this.opts = opts;
30
+ this.fetchImpl = opts.fetchImpl ?? fetch;
31
+ this.baseUrl = opts.baseUrl.replace(/\/+$/, '');
32
+ }
33
+ static isConfigured(env) {
34
+ return Boolean(env.AGENT_RUNNER_URL && env.AGENT_RUNNER_TOKEN);
35
+ }
36
+ post(req) {
37
+ return this.call(protocol_1.RUNNER_ROUTES.post, req);
38
+ }
39
+ probe(req) {
40
+ return this.call(protocol_1.RUNNER_ROUTES.probe, req);
41
+ }
42
+ captureStart(req) {
43
+ return this.call(protocol_1.RUNNER_ROUTES.captureStart, req);
44
+ }
45
+ captureFinish(req) {
46
+ return this.call(protocol_1.RUNNER_ROUTES.captureFinish, req);
47
+ }
48
+ captureCancel(req) {
49
+ return this.call(protocol_1.RUNNER_ROUTES.captureCancel, req);
50
+ }
51
+ async health() {
52
+ try {
53
+ const res = await this.fetchImpl(`${this.baseUrl}${protocol_1.RUNNER_ROUTES.health}`);
54
+ return res.ok;
55
+ }
56
+ catch {
57
+ return false;
58
+ }
59
+ }
60
+ async call(path, body) {
61
+ const controller = new AbortController();
62
+ const timer = setTimeout(() => controller.abort(), this.opts.timeoutMs ?? 180_000);
63
+ let res;
64
+ try {
65
+ res = await this.fetchImpl(`${this.baseUrl}${path}`, {
66
+ method: 'POST',
67
+ headers: {
68
+ 'Content-Type': 'application/json',
69
+ Authorization: `Bearer ${this.opts.token}`,
70
+ },
71
+ body: JSON.stringify(body),
72
+ signal: controller.signal,
73
+ });
74
+ }
75
+ catch (e) {
76
+ throw new AgentRunnerError(e instanceof Error
77
+ ? `Agent runner unreachable: ${e.message}`
78
+ : 'Agent runner unreachable', 0, true);
79
+ }
80
+ finally {
81
+ clearTimeout(timer);
82
+ }
83
+ const text = await res.text();
84
+ if (!res.ok) {
85
+ let message = text || `Agent runner error ${res.status}`;
86
+ try {
87
+ message = JSON.parse(text).error || message;
88
+ }
89
+ catch {
90
+ // plain text body
91
+ }
92
+ throw new AgentRunnerError(message, res.status, res.status >= 500);
93
+ }
94
+ return JSON.parse(text);
95
+ }
96
+ }
97
+ exports.AgentRunnerClient = AgentRunnerClient;
98
+ //# sourceMappingURL=runner-client.js.map
@@ -0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,CAAC,CAAC;QACtB,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC9B,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,IAAI,OAAO,GAAG,IAAI,IAAI,sBAAsB,GAAG,CAAC,MAAM,EAAE,CAAC;YACzD,IAAI,CAAC;gBACH,OAAO,GAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAwB,CAAC,KAAK,IAAI,OAAO,CAAC;YACtE,CAAC;YAAC,MAAM,CAAC;gBACP,kBAAkB;YACpB,CAAC;YACD,MAAM,IAAI,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Interactive session capture.
3
+ *
4
+ * The user signs in to the platform inside a live-view browser we control
5
+ * (Steel live view in production, a headed local Chromium in development).
6
+ * When they are done, we probe authentication and export `storageState`.
7
+ * Passwords never pass through the runtime; only the resulting cookies do.
8
+ *
9
+ * Captures are stateful (a browser stays open while the user types), so the
10
+ * manager keeps them in memory keyed by an unguessable capture id and
11
+ * expires them after `ttlMs`.
12
+ */
13
+ import type { PlatformId } from '../platform';
14
+ import type { AgentSessionState, SessionProvider, WebPostStrategy } from './types';
15
+ export type CaptureStart = {
16
+ captureId: string;
17
+ /** Provider live view URL (absolute). Undefined for headless providers. */
18
+ liveViewUrl?: string;
19
+ expiresAt: string;
20
+ };
21
+ export type CaptureFinish = {
22
+ ok: true;
23
+ state: AgentSessionState;
24
+ } | {
25
+ ok: false;
26
+ error: string;
27
+ notAuthenticated?: boolean;
28
+ };
29
+ export declare class SessionCaptureManager {
30
+ private provider;
31
+ private opts;
32
+ private active;
33
+ private strategies;
34
+ constructor(provider: SessionProvider, opts?: {
35
+ ttlMs?: number;
36
+ });
37
+ register(strategy: WebPostStrategy): this;
38
+ get size(): number;
39
+ start(input: {
40
+ platform: PlatformId;
41
+ userAgent?: string;
42
+ }): Promise<CaptureStart>;
43
+ /** Probe auth and export cookies; always releases the browser. */
44
+ finish(captureId: string): Promise<CaptureFinish>;
45
+ cancel(captureId: string): Promise<void>;
46
+ /** Live view URL for an active capture (used by the runner's proxy). */
47
+ liveViewUrlFor(captureId: string): string | undefined;
48
+ disposeAll(): Promise<void>;
49
+ }
50
+ //# sourceMappingURL=capture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../src/core/capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAEV,iBAAiB,EACjB,eAAe,EACf,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,aAAa,GACrB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,iBAAiB,CAAA;CAAE,GACtC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAS7D,qBAAa,qBAAqB;IAK9B,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,IAAI;IALd,OAAO,CAAC,MAAM,CAAoC;IAClD,OAAO,CAAC,UAAU,CAA0C;IAE5D,YACU,QAAQ,EAAE,eAAe,EACzB,IAAI,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,EACnC;IAEJ,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAGxC;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAEK,KAAK,CAAC,KAAK,EAAE;QACjB,QAAQ,EAAE,UAAU,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,CAuCxB;IAED,kEAAkE;IAC5D,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAsCtD;IAEK,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ7C;IAED,wEAAwE;IACxE,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEpD;IAEK,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAEhC;CACF"}
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ /**
3
+ * Interactive session capture.
4
+ *
5
+ * The user signs in to the platform inside a live-view browser we control
6
+ * (Steel live view in production, a headed local Chromium in development).
7
+ * When they are done, we probe authentication and export `storageState`.
8
+ * Passwords never pass through the runtime; only the resulting cookies do.
9
+ *
10
+ * Captures are stateful (a browser stays open while the user types), so the
11
+ * manager keeps them in memory keyed by an unguessable capture id and
12
+ * expires them after `ttlMs`.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SessionCaptureManager = void 0;
16
+ const node_crypto_1 = require("node:crypto");
17
+ class SessionCaptureManager {
18
+ provider;
19
+ opts;
20
+ active = new Map();
21
+ strategies = new Map();
22
+ constructor(provider, opts = {}) {
23
+ this.provider = provider;
24
+ this.opts = opts;
25
+ }
26
+ register(strategy) {
27
+ this.strategies.set(strategy.platform, strategy);
28
+ return this;
29
+ }
30
+ get size() {
31
+ return this.active.size;
32
+ }
33
+ async start(input) {
34
+ const strategy = this.strategies.get(input.platform);
35
+ if (!strategy) {
36
+ throw new Error(`No agentic strategy registered for ${input.platform}`);
37
+ }
38
+ const handle = await this.provider.acquire({
39
+ platform: input.platform,
40
+ interactive: true,
41
+ state: input.userAgent
42
+ ? {
43
+ platform: input.platform,
44
+ storageState: { cookies: [], origins: [] },
45
+ userAgent: input.userAgent,
46
+ capturedAt: new Date().toISOString(),
47
+ }
48
+ : undefined,
49
+ });
50
+ const page = await handle.context.newPage();
51
+ await page
52
+ .goto(strategy.loginUrl, { waitUntil: 'domcontentloaded' })
53
+ .catch(() => undefined);
54
+ const captureId = (0, node_crypto_1.randomBytes)(24).toString('base64url');
55
+ const ttl = this.opts.ttlMs ?? 20 * 60_000;
56
+ const expiresAt = Date.now() + ttl;
57
+ const timer = setTimeout(() => {
58
+ this.cancel(captureId).catch(() => undefined);
59
+ }, ttl);
60
+ this.active.set(captureId, {
61
+ platform: input.platform,
62
+ handle,
63
+ expiresAt,
64
+ timer,
65
+ });
66
+ return {
67
+ captureId,
68
+ liveViewUrl: handle.liveViewUrl,
69
+ expiresAt: new Date(expiresAt).toISOString(),
70
+ };
71
+ }
72
+ /** Probe auth and export cookies; always releases the browser. */
73
+ async finish(captureId) {
74
+ const entry = this.active.get(captureId);
75
+ if (!entry) {
76
+ return { ok: false, error: 'Capture not found or expired' };
77
+ }
78
+ this.active.delete(captureId);
79
+ clearTimeout(entry.timer);
80
+ const strategy = this.strategies.get(entry.platform);
81
+ try {
82
+ if (!strategy ||
83
+ !(await strategy.isAuthenticated(entry.handle.context))) {
84
+ return {
85
+ ok: false,
86
+ notAuthenticated: true,
87
+ error: 'Sign-in not detected yet — finish signing in and try again',
88
+ };
89
+ }
90
+ const storageState = await entry.handle.exportState();
91
+ const authCookieExpiry = storageState.cookies
92
+ .map((c) => c.expires)
93
+ .filter((e) => e > 0)
94
+ .sort((a, b) => a - b)[0];
95
+ return {
96
+ ok: true,
97
+ state: {
98
+ platform: entry.platform,
99
+ storageState,
100
+ capturedAt: new Date().toISOString(),
101
+ expiresHint: authCookieExpiry
102
+ ? new Date(authCookieExpiry * 1000).toISOString()
103
+ : undefined,
104
+ },
105
+ };
106
+ }
107
+ finally {
108
+ await entry.handle.dispose();
109
+ }
110
+ }
111
+ async cancel(captureId) {
112
+ const entry = this.active.get(captureId);
113
+ if (!entry) {
114
+ return;
115
+ }
116
+ this.active.delete(captureId);
117
+ clearTimeout(entry.timer);
118
+ await entry.handle.dispose();
119
+ }
120
+ /** Live view URL for an active capture (used by the runner's proxy). */
121
+ liveViewUrlFor(captureId) {
122
+ return this.active.get(captureId)?.handle.liveViewUrl;
123
+ }
124
+ async disposeAll() {
125
+ await Promise.all([...this.active.keys()].map((id) => this.cancel(id)));
126
+ }
127
+ }
128
+ exports.SessionCaptureManager = SessionCaptureManager;
129
+ //# sourceMappingURL=capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.js","sourceRoot":"","sources":["../../src/core/capture.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,6CAA0C;AA2B1C;IAKY,QAAQ;IACR,IAAI;IALN,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC1C,UAAU,GAAG,IAAI,GAAG,EAA+B,CAAC;IAE5D,YACU,QAAyB,EACzB,IAAI,GAAuB,EAAE;wBAD7B,QAAQ;oBACR,IAAI;IACX,CAAC;IAEJ,QAAQ,CAAC,QAAyB;QAChC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,KAGX;QACC,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACrD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,sCAAsC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC1E,CAAC;QACD,MAAM,MAA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