@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.
- package/CHANGELOG.md +23 -0
- package/LICENSE +23 -0
- package/README.md +261 -0
- package/action.yml +185 -0
- package/dist/attribution.d.ts +22 -0
- package/dist/attribution.d.ts.map +1 -0
- package/dist/attribution.js +57 -0
- package/dist/attribution.js.map +1 -0
- package/dist/cli.d.ts +21 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +242 -0
- package/dist/cli.js.map +1 -0
- package/dist/client/index.d.ts +9 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +26 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/runner-client.d.ts +41 -0
- package/dist/client/runner-client.d.ts.map +1 -0
- package/dist/client/runner-client.js +98 -0
- package/dist/client/runner-client.js.map +1 -0
- package/dist/core/capture.d.ts +50 -0
- package/dist/core/capture.d.ts.map +1 -0
- package/dist/core/capture.js +129 -0
- package/dist/core/capture.js.map +1 -0
- package/dist/core/poster.d.ts +45 -0
- package/dist/core/poster.d.ts.map +1 -0
- package/dist/core/poster.js +132 -0
- package/dist/core/poster.js.map +1 -0
- package/dist/core/stores.d.ts +35 -0
- package/dist/core/stores.d.ts.map +1 -0
- package/dist/core/stores.js +32 -0
- package/dist/core/stores.js.map +1 -0
- package/dist/core/types.d.ts +138 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +13 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/platform.d.ts +6 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +3 -0
- package/dist/platform.js.map +1 -0
- package/dist/protocol.d.ts +84 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +24 -0
- package/dist/protocol.js.map +1 -0
- package/dist/providers/kernel.d.ts +53 -0
- package/dist/providers/kernel.d.ts.map +1 -0
- package/dist/providers/kernel.js +82 -0
- package/dist/providers/kernel.js.map +1 -0
- package/dist/providers/playwright.d.ts +88 -0
- package/dist/providers/playwright.d.ts.map +1 -0
- package/dist/providers/playwright.js +114 -0
- package/dist/providers/playwright.js.map +1 -0
- package/dist/providers/steel.d.ts +48 -0
- package/dist/providers/steel.d.ts.map +1 -0
- package/dist/providers/steel.js +79 -0
- package/dist/providers/steel.js.map +1 -0
- package/dist/service/config.d.ts +33 -0
- package/dist/service/config.d.ts.map +1 -0
- package/dist/service/config.js +59 -0
- package/dist/service/config.js.map +1 -0
- package/dist/service/index.d.ts +30 -0
- package/dist/service/index.d.ts.map +1 -0
- package/dist/service/index.js +53 -0
- package/dist/service/index.js.map +1 -0
- package/dist/service/live-proxy.d.ts +27 -0
- package/dist/service/live-proxy.d.ts.map +1 -0
- package/dist/service/live-proxy.js +146 -0
- package/dist/service/live-proxy.js.map +1 -0
- package/dist/service/runner.d.ts +35 -0
- package/dist/service/runner.d.ts.map +1 -0
- package/dist/service/runner.js +139 -0
- package/dist/service/runner.js.map +1 -0
- package/dist/service/serialized-provider.d.ts +20 -0
- package/dist/service/serialized-provider.d.ts.map +1 -0
- package/dist/service/serialized-provider.js +68 -0
- package/dist/service/serialized-provider.js.map +1 -0
- package/dist/service/server.d.ts +17 -0
- package/dist/service/server.d.ts.map +1 -0
- package/dist/service/server.js +159 -0
- package/dist/service/server.js.map +1 -0
- package/docs/AGENTS.md +46 -0
- package/docs/ARCHITECTURE.md +73 -0
- package/docs/DEPLOY.md +61 -0
- package/docs/GITHUB_ACTION.md +92 -0
- package/examples/demo-strategy/index.js +53 -0
- package/examples/demo-strategy/session.json +5 -0
- package/package.json +96 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel session provider (https://www.kernel.sh — Apache-2.0 browser
|
|
3
|
+
* images, managed microVM orchestration). Useful as a burst / secondary
|
|
4
|
+
* provider behind the same `SessionProvider` contract: sub-second cold
|
|
5
|
+
* starts, standby billing, optional stealth and persistent profiles.
|
|
6
|
+
*
|
|
7
|
+
* API surface used:
|
|
8
|
+
* POST https://api.onkernel.com/browsers -> { session_id, cdp_ws_url, browser_live_view_url }
|
|
9
|
+
* DELETE https://api.onkernel.com/browsers/{session_id}
|
|
10
|
+
*
|
|
11
|
+
* Session cookies are injected per job from the caller's encrypted store;
|
|
12
|
+
* Kernel profiles are optional warm caches, never the source of truth.
|
|
13
|
+
*/
|
|
14
|
+
import type { AgentSessionHandle, AgentSessionState, SessionProvider } from '../core/types';
|
|
15
|
+
import type { PlatformId } from '../platform';
|
|
16
|
+
export type KernelProviderOptions = {
|
|
17
|
+
apiKey: string;
|
|
18
|
+
/** Defaults to https://api.onkernel.com */
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
/** Reduce bot detection (Kernel stealth image). Default true. */
|
|
21
|
+
stealth?: boolean;
|
|
22
|
+
/** Inactivity timeout for headless jobs (seconds). Default 300. */
|
|
23
|
+
jobTimeoutSeconds?: number;
|
|
24
|
+
/** Inactivity timeout for interactive captures (seconds). Default 1200. */
|
|
25
|
+
interactiveTimeoutSeconds?: number;
|
|
26
|
+
/** Optional persistent profile name to warm-start from. */
|
|
27
|
+
profileName?: string;
|
|
28
|
+
fetchImpl?: typeof fetch;
|
|
29
|
+
};
|
|
30
|
+
type KernelBrowser = {
|
|
31
|
+
session_id: string;
|
|
32
|
+
cdp_ws_url: string;
|
|
33
|
+
browser_live_view_url?: string;
|
|
34
|
+
};
|
|
35
|
+
export declare class KernelSessionProvider implements SessionProvider {
|
|
36
|
+
private opts;
|
|
37
|
+
readonly id = "kernel";
|
|
38
|
+
private readonly fetchImpl;
|
|
39
|
+
private readonly baseUrl;
|
|
40
|
+
constructor(opts: KernelProviderOptions);
|
|
41
|
+
private headers;
|
|
42
|
+
createBrowser(input: {
|
|
43
|
+
interactive?: boolean;
|
|
44
|
+
}): Promise<KernelBrowser>;
|
|
45
|
+
deleteBrowser(sessionId: string): Promise<void>;
|
|
46
|
+
acquire(input: {
|
|
47
|
+
platform: PlatformId;
|
|
48
|
+
state?: AgentSessionState;
|
|
49
|
+
interactive?: boolean;
|
|
50
|
+
}): Promise<AgentSessionHandle>;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=kernel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../src/providers/kernel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iEAAiE;IACjE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mEAAmE;IACnE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2EAA2E;IAC3E,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,qBAAa,qBAAsB,YAAW,eAAe;IAK/C,OAAO,CAAC,IAAI;IAJxB,QAAQ,CAAC,EAAE,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,YAAoB,IAAI,EAAE,qBAAqB,EAM9C;IAED,OAAO,CAAC,OAAO;IAOT,aAAa,CAAC,KAAK,EAAE;QACzB,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,GAAG,OAAO,CAAC,aAAa,CAAC,CAsBzB;IAEK,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQpD;IAEK,OAAO,CAAC,KAAK,EAAE;QACnB,QAAQ,EAAE,UAAU,CAAC;QACrB,KAAK,CAAC,EAAE,iBAAiB,CAAC;QAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAiB9B;CACF"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Kernel session provider (https://www.kernel.sh — Apache-2.0 browser
|
|
4
|
+
* images, managed microVM orchestration). Useful as a burst / secondary
|
|
5
|
+
* provider behind the same `SessionProvider` contract: sub-second cold
|
|
6
|
+
* starts, standby billing, optional stealth and persistent profiles.
|
|
7
|
+
*
|
|
8
|
+
* API surface used:
|
|
9
|
+
* POST https://api.onkernel.com/browsers -> { session_id, cdp_ws_url, browser_live_view_url }
|
|
10
|
+
* DELETE https://api.onkernel.com/browsers/{session_id}
|
|
11
|
+
*
|
|
12
|
+
* Session cookies are injected per job from the caller's encrypted store;
|
|
13
|
+
* Kernel profiles are optional warm caches, never the source of truth.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.KernelSessionProvider = void 0;
|
|
17
|
+
const playwright_1 = require("./playwright");
|
|
18
|
+
class KernelSessionProvider {
|
|
19
|
+
opts;
|
|
20
|
+
id = 'kernel';
|
|
21
|
+
fetchImpl;
|
|
22
|
+
baseUrl;
|
|
23
|
+
constructor(opts) {
|
|
24
|
+
this.opts = opts;
|
|
25
|
+
this.fetchImpl = opts.fetchImpl ?? fetch;
|
|
26
|
+
this.baseUrl = (opts.baseUrl ?? 'https://api.onkernel.com').replace(/\/+$/, '');
|
|
27
|
+
}
|
|
28
|
+
headers() {
|
|
29
|
+
return {
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
Authorization: `Bearer ${this.opts.apiKey}`,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async createBrowser(input) {
|
|
35
|
+
const res = await this.fetchImpl(`${this.baseUrl}/browsers`, {
|
|
36
|
+
method: 'POST',
|
|
37
|
+
headers: this.headers(),
|
|
38
|
+
body: JSON.stringify({
|
|
39
|
+
// Live view is only available for non-headless browsers.
|
|
40
|
+
headless: !input.interactive,
|
|
41
|
+
stealth: this.opts.stealth ?? true,
|
|
42
|
+
timeout_seconds: input.interactive
|
|
43
|
+
? (this.opts.interactiveTimeoutSeconds ?? 1200)
|
|
44
|
+
: (this.opts.jobTimeoutSeconds ?? 300),
|
|
45
|
+
...(this.opts.profileName
|
|
46
|
+
? { profile: { name: this.opts.profileName, save_changes: false } }
|
|
47
|
+
: {}),
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
if (!res.ok) {
|
|
51
|
+
throw new Error(`Kernel browser create failed (${res.status}): ${await res.text()}`);
|
|
52
|
+
}
|
|
53
|
+
return (await res.json());
|
|
54
|
+
}
|
|
55
|
+
async deleteBrowser(sessionId) {
|
|
56
|
+
await this.fetchImpl(`${this.baseUrl}/browsers/${encodeURIComponent(sessionId)}`, {
|
|
57
|
+
method: 'DELETE',
|
|
58
|
+
headers: this.headers(),
|
|
59
|
+
}).catch(() => undefined);
|
|
60
|
+
}
|
|
61
|
+
async acquire(input) {
|
|
62
|
+
const browser = await this.createBrowser({
|
|
63
|
+
interactive: input.interactive,
|
|
64
|
+
});
|
|
65
|
+
try {
|
|
66
|
+
return await (0, playwright_1.attachOverCdp)({
|
|
67
|
+
wsUrl: browser.cdp_ws_url,
|
|
68
|
+
platform: input.platform,
|
|
69
|
+
state: input.state,
|
|
70
|
+
providerSessionId: browser.session_id,
|
|
71
|
+
liveViewUrl: browser.browser_live_view_url,
|
|
72
|
+
onDispose: () => this.deleteBrowser(browser.session_id),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
await this.deleteBrowser(browser.session_id);
|
|
77
|
+
throw err;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.KernelSessionProvider = KernelSessionProvider;
|
|
82
|
+
//# sourceMappingURL=kernel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kernel.js","sourceRoot":"","sources":["../../src/providers/kernel.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAQH,6CAA6C;AAuB7C;IAKsB,IAAI;IAJf,EAAE,GAAG,QAAQ,CAAC;IACN,SAAS,CAAe;IACxB,OAAO,CAAS;IAEjC,YAAoB,IAA2B;oBAA3B,IAAI;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,0BAA0B,CAAC,CAAC,OAAO,CACjE,MAAM,EACN,EAAE,CACH,CAAC;IACJ,CAAC;IAEO,OAAO;QACb,OAAO;YACL,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;SAC5C,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,KAEnB;QACC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,WAAW,EAAE;YAC3D,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;YACvB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,yDAAyD;gBACzD,QAAQ,EAAE,CAAC,KAAK,CAAC,WAAW;gBAC5B,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAA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Q;gBACxB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,iBAAiB,EAAE,OAAO,CAAC,UAAU;gBACrC,WAAW,EAAE,OAAO,CAAC,qBAAqB;gBAC1C,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC;aACxD,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC7C,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session providers: turn stored session state into live browser contexts.
|
|
3
|
+
*
|
|
4
|
+
* All providers speak Playwright's BrowserContext, so strategies and the
|
|
5
|
+
* AgentPoster are identical whether the browser runs on this machine or in
|
|
6
|
+
* a remote sandbox. Swapping providers is a config change, not a code
|
|
7
|
+
* change. See `steel-provider.ts` for the self-hosted Steel implementation.
|
|
8
|
+
*/
|
|
9
|
+
import { type Browser, type BrowserContext } from 'playwright-core';
|
|
10
|
+
import type { AgentSessionHandle, AgentSessionState, SessionProvider, StorageState } from '../core/types';
|
|
11
|
+
import type { PlatformId } from '../platform';
|
|
12
|
+
export declare const DEFAULT_VIEWPORT: {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function buildHandle(browser: Browser, context: BrowserContext, extra?: {
|
|
17
|
+
providerSessionId?: string;
|
|
18
|
+
liveViewUrl?: string;
|
|
19
|
+
onDispose?: () => Promise<void>;
|
|
20
|
+
}): Promise<AgentSessionHandle>;
|
|
21
|
+
export declare function contextOptions(input: {
|
|
22
|
+
platform: PlatformId;
|
|
23
|
+
state?: AgentSessionState;
|
|
24
|
+
}): {
|
|
25
|
+
storageState: StorageState | undefined;
|
|
26
|
+
userAgent: string | undefined;
|
|
27
|
+
viewport: {
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Runs a Chromium instance on the current machine. Used by the runner
|
|
34
|
+
* service for headless jobs (each job gets a fresh, isolated context with
|
|
35
|
+
* the stored cookies injected) and for headed local capture in development.
|
|
36
|
+
*/
|
|
37
|
+
export declare class LocalBrowserSessionProvider implements SessionProvider {
|
|
38
|
+
private opts;
|
|
39
|
+
readonly id = "local";
|
|
40
|
+
constructor(opts?: {
|
|
41
|
+
headless?: boolean;
|
|
42
|
+
});
|
|
43
|
+
acquire(input: {
|
|
44
|
+
platform: PlatformId;
|
|
45
|
+
state?: AgentSessionState;
|
|
46
|
+
interactive?: boolean;
|
|
47
|
+
}): Promise<AgentSessionHandle>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Attach a stored session to a remote browser reached over CDP. Remote
|
|
51
|
+
* browsers ship with a default context; we inject state into a fresh
|
|
52
|
+
* context when the provider allows it, otherwise reuse the default one.
|
|
53
|
+
*/
|
|
54
|
+
export declare function attachOverCdp(input: {
|
|
55
|
+
wsUrl: string;
|
|
56
|
+
platform: PlatformId;
|
|
57
|
+
state?: AgentSessionState;
|
|
58
|
+
providerSessionId?: string;
|
|
59
|
+
liveViewUrl?: string;
|
|
60
|
+
onDispose?: () => Promise<void>;
|
|
61
|
+
}): Promise<AgentSessionHandle>;
|
|
62
|
+
/**
|
|
63
|
+
* Connects to any remote browser that exposes a CDP websocket endpoint.
|
|
64
|
+
* The `createEndpoint` callback encapsulates the provider's session API
|
|
65
|
+
* (Steel, Kernel, Browserbase, a self-hosted Chrome fleet, ...).
|
|
66
|
+
*/
|
|
67
|
+
export declare class CdpSessionProvider implements SessionProvider {
|
|
68
|
+
private opts;
|
|
69
|
+
readonly id: string;
|
|
70
|
+
constructor(opts: {
|
|
71
|
+
id?: string;
|
|
72
|
+
createEndpoint: (input: {
|
|
73
|
+
platform: PlatformId;
|
|
74
|
+
interactive?: boolean;
|
|
75
|
+
}) => Promise<{
|
|
76
|
+
wsUrl: string;
|
|
77
|
+
sessionId?: string;
|
|
78
|
+
liveViewUrl?: string;
|
|
79
|
+
release?: () => Promise<void>;
|
|
80
|
+
}>;
|
|
81
|
+
});
|
|
82
|
+
acquire(input: {
|
|
83
|
+
platform: PlatformId;
|
|
84
|
+
state?: AgentSessionState;
|
|
85
|
+
interactive?: boolean;
|
|
86
|
+
}): Promise<AgentSessionHandle>;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=playwright.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playwright.d.ts","sourceRoot":"","sources":["../../src/providers/playwright.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,cAAc,EAAY,MAAM,iBAAiB,CAAC;AAC9E,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,eAAO,MAAM,gBAAgB;IAAK,KAAK;IAAQ,MAAM;CAAO,CAAC;AAE7D,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,cAAc,EACvB,KAAK,GAAE;IACL,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,GACL,OAAO,CAAC,kBAAkB,CAAC,CAe7B;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE;IACpC,QAAQ,EAAE,UAAU,CAAC;IACrB,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B;IAEG,YAAY;IACZ,SAAS;IACT,QAAQ;;;;EAEX;AAED;;;;GAIG;AACH,qBAAa,2BAA4B,YAAW,eAAe;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AAE,iBAAiB,CAAC;QAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAa9B;CACF"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Session providers: turn stored session state into live browser contexts.
|
|
4
|
+
*
|
|
5
|
+
* All providers speak Playwright's BrowserContext, so strategies and the
|
|
6
|
+
* AgentPoster are identical whether the browser runs on this machine or in
|
|
7
|
+
* a remote sandbox. Swapping providers is a config change, not a code
|
|
8
|
+
* change. See `steel-provider.ts` for the self-hosted Steel implementation.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.CdpSessionProvider = exports.LocalBrowserSessionProvider = exports.DEFAULT_VIEWPORT = void 0;
|
|
12
|
+
exports.buildHandle = buildHandle;
|
|
13
|
+
exports.contextOptions = contextOptions;
|
|
14
|
+
exports.attachOverCdp = attachOverCdp;
|
|
15
|
+
const playwright_core_1 = require("playwright-core");
|
|
16
|
+
exports.DEFAULT_VIEWPORT = { width: 1280, height: 900 };
|
|
17
|
+
async function buildHandle(browser, context, extra = {}) {
|
|
18
|
+
return {
|
|
19
|
+
context,
|
|
20
|
+
providerSessionId: extra.providerSessionId,
|
|
21
|
+
liveViewUrl: extra.liveViewUrl,
|
|
22
|
+
async exportState() {
|
|
23
|
+
const state = await context.storageState();
|
|
24
|
+
return state;
|
|
25
|
+
},
|
|
26
|
+
async dispose() {
|
|
27
|
+
await context.close().catch(() => undefined);
|
|
28
|
+
await browser.close().catch(() => undefined);
|
|
29
|
+
await extra.onDispose?.().catch(() => undefined);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function contextOptions(input) {
|
|
34
|
+
return {
|
|
35
|
+
storageState: input.state?.storageState,
|
|
36
|
+
userAgent: input.state?.userAgent,
|
|
37
|
+
viewport: exports.DEFAULT_VIEWPORT,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Runs a Chromium instance on the current machine. Used by the runner
|
|
42
|
+
* service for headless jobs (each job gets a fresh, isolated context with
|
|
43
|
+
* the stored cookies injected) and for headed local capture in development.
|
|
44
|
+
*/
|
|
45
|
+
class LocalBrowserSessionProvider {
|
|
46
|
+
opts;
|
|
47
|
+
id = 'local';
|
|
48
|
+
constructor(opts = {}) {
|
|
49
|
+
this.opts = opts;
|
|
50
|
+
}
|
|
51
|
+
async acquire(input) {
|
|
52
|
+
const browser = await playwright_core_1.chromium.launch({
|
|
53
|
+
headless: input.interactive ? false : (this.opts.headless ?? true),
|
|
54
|
+
});
|
|
55
|
+
const context = await browser.newContext(contextOptions(input));
|
|
56
|
+
return buildHandle(browser, context);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.LocalBrowserSessionProvider = LocalBrowserSessionProvider;
|
|
60
|
+
/**
|
|
61
|
+
* Attach a stored session to a remote browser reached over CDP. Remote
|
|
62
|
+
* browsers ship with a default context; we inject state into a fresh
|
|
63
|
+
* context when the provider allows it, otherwise reuse the default one.
|
|
64
|
+
*/
|
|
65
|
+
async function attachOverCdp(input) {
|
|
66
|
+
const browser = await playwright_core_1.chromium.connectOverCDP(input.wsUrl);
|
|
67
|
+
let context;
|
|
68
|
+
try {
|
|
69
|
+
context = await browser.newContext(contextOptions(input));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
context = browser.contexts()[0];
|
|
73
|
+
if (!context) {
|
|
74
|
+
throw new Error('Remote browser exposed no context');
|
|
75
|
+
}
|
|
76
|
+
if (input.state?.storageState?.cookies?.length) {
|
|
77
|
+
await context.addCookies(input.state.storageState.cookies);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return buildHandle(browser, context, {
|
|
81
|
+
providerSessionId: input.providerSessionId,
|
|
82
|
+
liveViewUrl: input.liveViewUrl,
|
|
83
|
+
onDispose: input.onDispose,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Connects to any remote browser that exposes a CDP websocket endpoint.
|
|
88
|
+
* The `createEndpoint` callback encapsulates the provider's session API
|
|
89
|
+
* (Steel, Kernel, Browserbase, a self-hosted Chrome fleet, ...).
|
|
90
|
+
*/
|
|
91
|
+
class CdpSessionProvider {
|
|
92
|
+
opts;
|
|
93
|
+
id;
|
|
94
|
+
constructor(opts) {
|
|
95
|
+
this.opts = opts;
|
|
96
|
+
this.id = opts.id || 'cdp';
|
|
97
|
+
}
|
|
98
|
+
async acquire(input) {
|
|
99
|
+
const ep = await this.opts.createEndpoint({
|
|
100
|
+
platform: input.platform,
|
|
101
|
+
interactive: input.interactive,
|
|
102
|
+
});
|
|
103
|
+
return attachOverCdp({
|
|
104
|
+
wsUrl: ep.wsUrl,
|
|
105
|
+
platform: input.platform,
|
|
106
|
+
state: input.state,
|
|
107
|
+
providerSessionId: ep.sessionId,
|
|
108
|
+
liveViewUrl: ep.liveViewUrl,
|
|
109
|
+
onDispose: ep.release,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.CdpSessionProvider = CdpSessionProvider;
|
|
114
|
+
//# sourceMappingURL=playwright.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playwright.js","sourceRoot":"","sources":["../../src/providers/playwright.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;AAEH,qDAA8E;AASjE,QAAA,gBAAgB,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AAEtD,KAAK,sBACV,OAAgB,EAChB,OAAuB,EACvB,KAAK,GAID,EAAE;IAEN,OAAO;QACL,OAAO;QACP,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,KAAK,CAAC,WAAW;YACf,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,YAAY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;YAC/B,WAAW,EAAE,EAAE,CAAC,WAAW;YAC3B,SAAS,EAAE,EAAE,CAAC,OAAO;SACtB,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Steel session provider (self-hosted `steel-browser`, Apache-2.0, or Steel
|
|
3
|
+
* Cloud). Steel exposes a REST session API plus a CDP websocket and a
|
|
4
|
+
* human-viewable live view, which is exactly what interactive session
|
|
5
|
+
* capture needs: the user signs in inside the live view, we export the
|
|
6
|
+
* resulting cookies and never see a password.
|
|
7
|
+
*
|
|
8
|
+
* The embedding application keeps the encrypted session as the source of
|
|
9
|
+
* truth; Steel profiles are treated as a disposable warm cache.
|
|
10
|
+
*
|
|
11
|
+
* API surface used (stable across OSS + Cloud):
|
|
12
|
+
* POST {baseUrl}/v1/sessions -> { id, websocketUrl, debugUrl, sessionViewerUrl }
|
|
13
|
+
* POST {baseUrl}/v1/sessions/{id}/release
|
|
14
|
+
*/
|
|
15
|
+
import type { AgentSessionHandle, AgentSessionState, SessionProvider } from '../core/types';
|
|
16
|
+
import type { PlatformId } from '../platform';
|
|
17
|
+
export type SteelProviderOptions = {
|
|
18
|
+
/** e.g. http://localhost:3000 (self-hosted) or https://api.steel.dev */
|
|
19
|
+
baseUrl: string;
|
|
20
|
+
/** Steel Cloud API key; unused for self-hosted. */
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
/** Session timeout in ms (Steel default 5 minutes; capture needs longer). */
|
|
23
|
+
sessionTimeoutMs?: number;
|
|
24
|
+
interactiveTimeoutMs?: number;
|
|
25
|
+
fetchImpl?: typeof fetch;
|
|
26
|
+
};
|
|
27
|
+
export declare class SteelSessionProvider implements SessionProvider {
|
|
28
|
+
private opts;
|
|
29
|
+
readonly id = "steel";
|
|
30
|
+
private readonly fetchImpl;
|
|
31
|
+
constructor(opts: SteelProviderOptions);
|
|
32
|
+
private headers;
|
|
33
|
+
createSession(input: {
|
|
34
|
+
userAgent?: string;
|
|
35
|
+
interactive?: boolean;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
id: string;
|
|
38
|
+
wsUrl: string;
|
|
39
|
+
liveViewUrl?: string;
|
|
40
|
+
}>;
|
|
41
|
+
releaseSession(id: string): Promise<void>;
|
|
42
|
+
acquire(input: {
|
|
43
|
+
platform: PlatformId;
|
|
44
|
+
state?: AgentSessionState;
|
|
45
|
+
interactive?: boolean;
|
|
46
|
+
}): Promise<AgentSessionHandle>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=steel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steel.d.ts","sourceRoot":"","sources":["../../src/providers/steel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,MAAM,oBAAoB,GAAG;IACjC,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,CAAC;AASF,qBAAa,oBAAqB,YAAW,eAAe;IAI9C,OAAO,CAAC,IAAI;IAHxB,QAAQ,CAAC,EAAE,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;IAEzC,YAAoB,IAAI,EAAE,oBAAoB,EAE7C;IAED,OAAO,CAAC,OAAO;IAOT,aAAa,CAAC,KAAK,EAAE;QACzB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CA0B/D;IAEK,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK9C;IAEK,OAAO,CAAC,KAAK,EAAE;QACnB,QAAQ,EAAE,UAAU,CAAC;QACrB,KAAK,CAAC,EAAE,iBAAiB,CAAC;QAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAa9B;CACF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Steel session provider (self-hosted `steel-browser`, Apache-2.0, or Steel
|
|
4
|
+
* Cloud). Steel exposes a REST session API plus a CDP websocket and a
|
|
5
|
+
* human-viewable live view, which is exactly what interactive session
|
|
6
|
+
* capture needs: the user signs in inside the live view, we export the
|
|
7
|
+
* resulting cookies and never see a password.
|
|
8
|
+
*
|
|
9
|
+
* The embedding application keeps the encrypted session as the source of
|
|
10
|
+
* truth; Steel profiles are treated as a disposable warm cache.
|
|
11
|
+
*
|
|
12
|
+
* API surface used (stable across OSS + Cloud):
|
|
13
|
+
* POST {baseUrl}/v1/sessions -> { id, websocketUrl, debugUrl, sessionViewerUrl }
|
|
14
|
+
* POST {baseUrl}/v1/sessions/{id}/release
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SteelSessionProvider = void 0;
|
|
18
|
+
const playwright_1 = require("./playwright");
|
|
19
|
+
class SteelSessionProvider {
|
|
20
|
+
opts;
|
|
21
|
+
id = 'steel';
|
|
22
|
+
fetchImpl;
|
|
23
|
+
constructor(opts) {
|
|
24
|
+
this.opts = opts;
|
|
25
|
+
this.fetchImpl = opts.fetchImpl ?? fetch;
|
|
26
|
+
}
|
|
27
|
+
headers() {
|
|
28
|
+
return {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
...(this.opts.apiKey ? { 'steel-api-key': this.opts.apiKey } : {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async createSession(input) {
|
|
34
|
+
const timeout = input.interactive
|
|
35
|
+
? (this.opts.interactiveTimeoutMs ?? 20 * 60_000)
|
|
36
|
+
: (this.opts.sessionTimeoutMs ?? 5 * 60_000);
|
|
37
|
+
const res = await this.fetchImpl(`${this.opts.baseUrl}/v1/sessions`, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: this.headers(),
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
timeout,
|
|
42
|
+
...(input.userAgent ? { userAgent: input.userAgent } : {}),
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
if (!res.ok) {
|
|
46
|
+
throw new Error(`Steel session create failed (${res.status}): ${await res.text()}`);
|
|
47
|
+
}
|
|
48
|
+
const data = (await res.json());
|
|
49
|
+
const wsUrl = data.websocketUrl ||
|
|
50
|
+
`${this.opts.baseUrl.replace(/^http/, 'ws')}/v1/sessions/${data.id}/cdp`;
|
|
51
|
+
return {
|
|
52
|
+
id: data.id,
|
|
53
|
+
wsUrl,
|
|
54
|
+
liveViewUrl: data.debugUrl || data.sessionViewerUrl,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async releaseSession(id) {
|
|
58
|
+
await this.fetchImpl(`${this.opts.baseUrl}/v1/sessions/${id}/release`, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: this.headers(),
|
|
61
|
+
}).catch(() => undefined);
|
|
62
|
+
}
|
|
63
|
+
async acquire(input) {
|
|
64
|
+
const session = await this.createSession({
|
|
65
|
+
userAgent: input.state?.userAgent,
|
|
66
|
+
interactive: input.interactive,
|
|
67
|
+
});
|
|
68
|
+
return (0, playwright_1.attachOverCdp)({
|
|
69
|
+
wsUrl: session.wsUrl,
|
|
70
|
+
platform: input.platform,
|
|
71
|
+
state: input.state,
|
|
72
|
+
providerSessionId: session.id,
|
|
73
|
+
liveViewUrl: session.liveViewUrl,
|
|
74
|
+
onDispose: () => this.releaseSession(session.id),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.SteelSessionProvider = SteelSessionProvider;
|
|
79
|
+
//# sourceMappingURL=steel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steel.js","sourceRoot":"","sources":["../../src/providers/steel.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAQH,6CAA6C;AAoB7C;IAIsB,IAAI;IAHf,EAAE,GAAG,OAAO,CAAC;IACL,SAAS,CAAe;IAEzC,YAAoB,IAA0B;oBAA1B,IAAI;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC;IAC3C,CAAC;IAEO,OAAO;QACb,OAAO;YACL,cAAc,EAAE,kBAAkB;YAClC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACnE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,KAGnB;QACC,MAAM,OAAO,GAAG,KAAK,CAAC,WAAW;YAC/B,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,IAAI,EAAE,GAAG,MAAM,CAAC;YACjD,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;QAC/C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,cAAc,EAAE;YACnE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;YACvB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,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AAO,CAAC,KAAK;YACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,iBAAiB,EAAE,OAAO,CAAC,EAAE;YAC7B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;SACjD,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runner service configuration (environment driven, validated at boot).
|
|
3
|
+
*
|
|
4
|
+
* - AGENT_RUNNER_TOKEN shared bearer token orchestrators use to call us (required)
|
|
5
|
+
* - AGENT_RUNNER_PUBLIC_URL absolute URL users reach the runner at (live view)
|
|
6
|
+
* - AGENT_RUNNER_JOB_PROVIDER local | steel | kernel (headless post/probe jobs)
|
|
7
|
+
* - AGENT_RUNNER_CAPTURE_PROVIDER local | steel | kernel (interactive sign-in)
|
|
8
|
+
* - STEEL_API_URL e.g. http://127.0.0.1:3000 (sidecar) — required for steel
|
|
9
|
+
* - STEEL_API_KEY Steel Cloud only
|
|
10
|
+
* - KERNEL_API_KEY required for kernel (managed microVM browsers)
|
|
11
|
+
* - KERNEL_API_URL default https://api.onkernel.com
|
|
12
|
+
* - PORT default 8080 (Cloud Run convention)
|
|
13
|
+
*/
|
|
14
|
+
export type ProviderKind = 'local' | 'steel' | 'kernel';
|
|
15
|
+
export type RunnerConfig = {
|
|
16
|
+
port: number;
|
|
17
|
+
token: string;
|
|
18
|
+
publicUrl: string;
|
|
19
|
+
jobProvider: ProviderKind;
|
|
20
|
+
captureProvider: ProviderKind;
|
|
21
|
+
steel?: {
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
};
|
|
25
|
+
kernel?: {
|
|
26
|
+
apiKey: string;
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
};
|
|
29
|
+
captureTtlMs: number;
|
|
30
|
+
pacing: boolean;
|
|
31
|
+
};
|
|
32
|
+
export declare function loadConfig(env?: NodeJS.ProcessEnv): RunnerConfig;
|
|
33
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/service/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAExD,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,YAAY,CAAC;IAC1B,eAAe,EAAE,YAAY,CAAC;IAC9B,KAAK,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,MAAM,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9C,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAYF,wBAAgB,UAAU,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,YAAY,CA4C7E"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Runner service configuration (environment driven, validated at boot).
|
|
4
|
+
*
|
|
5
|
+
* - AGENT_RUNNER_TOKEN shared bearer token orchestrators use to call us (required)
|
|
6
|
+
* - AGENT_RUNNER_PUBLIC_URL absolute URL users reach the runner at (live view)
|
|
7
|
+
* - AGENT_RUNNER_JOB_PROVIDER local | steel | kernel (headless post/probe jobs)
|
|
8
|
+
* - AGENT_RUNNER_CAPTURE_PROVIDER local | steel | kernel (interactive sign-in)
|
|
9
|
+
* - STEEL_API_URL e.g. http://127.0.0.1:3000 (sidecar) — required for steel
|
|
10
|
+
* - STEEL_API_KEY Steel Cloud only
|
|
11
|
+
* - KERNEL_API_KEY required for kernel (managed microVM browsers)
|
|
12
|
+
* - KERNEL_API_URL default https://api.onkernel.com
|
|
13
|
+
* - PORT default 8080 (Cloud Run convention)
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.loadConfig = loadConfig;
|
|
17
|
+
function providerKind(value, fallback) {
|
|
18
|
+
if (value === 'local' || value === 'steel' || value === 'kernel') {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
return fallback;
|
|
22
|
+
}
|
|
23
|
+
function loadConfig(env = process.env) {
|
|
24
|
+
const token = env.AGENT_RUNNER_TOKEN;
|
|
25
|
+
if (!token || token.length < 16) {
|
|
26
|
+
throw new Error('AGENT_RUNNER_TOKEN must be set (>= 16 chars)');
|
|
27
|
+
}
|
|
28
|
+
const port = Number(env.PORT || 8080);
|
|
29
|
+
const publicUrl = (env.AGENT_RUNNER_PUBLIC_URL || `http://localhost:${port}`).replace(/\/+$/, '');
|
|
30
|
+
const jobProvider = providerKind(env.AGENT_RUNNER_JOB_PROVIDER, 'local');
|
|
31
|
+
const captureProvider = providerKind(env.AGENT_RUNNER_CAPTURE_PROVIDER, env.STEEL_API_URL ? 'steel' : 'local');
|
|
32
|
+
const steel = env.STEEL_API_URL
|
|
33
|
+
? {
|
|
34
|
+
baseUrl: env.STEEL_API_URL.replace(/\/+$/, ''),
|
|
35
|
+
apiKey: env.STEEL_API_KEY || undefined,
|
|
36
|
+
}
|
|
37
|
+
: undefined;
|
|
38
|
+
if ((jobProvider === 'steel' || captureProvider === 'steel') && !steel) {
|
|
39
|
+
throw new Error('STEEL_API_URL is required when a provider is set to steel');
|
|
40
|
+
}
|
|
41
|
+
const kernel = env.KERNEL_API_KEY
|
|
42
|
+
? { apiKey: env.KERNEL_API_KEY, baseUrl: env.KERNEL_API_URL || undefined }
|
|
43
|
+
: undefined;
|
|
44
|
+
if ((jobProvider === 'kernel' || captureProvider === 'kernel') && !kernel) {
|
|
45
|
+
throw new Error('KERNEL_API_KEY is required when a provider is set to kernel');
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
port,
|
|
49
|
+
token,
|
|
50
|
+
publicUrl,
|
|
51
|
+
jobProvider,
|
|
52
|
+
captureProvider,
|
|
53
|
+
steel,
|
|
54
|
+
kernel,
|
|
55
|
+
captureTtlMs: Number(env.AGENT_RUNNER_CAPTURE_TTL_MS || 20 * 60_000),
|
|
56
|
+
pacing: env.AGENT_RUNNER_PACING !== 'false',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/service/config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAgBH,SAAS,YAAY,CACnB,KAAyB,EACzB,QAAsB;IAEtB,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;QACjE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,oBAA2B,GAAG,GAAsB,OAAO,CAAC,GAAG;IAC7D,MAAM,KAAK,GAAG,GAAG,CAAC,kBAAkB,CAAC;IACrC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,CAChB,GAAG,CAAC,uBAAuB,IAAI,oBAAoB,IAAI,EAAE,CAC1D,CAAC,OAAO,CAAC,MAAM,EAA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
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent runner service entry point.
|
|
3
|
+
*
|
|
4
|
+
* import { startRunner } from 'agent-browser-runtime/service';
|
|
5
|
+
* startRunner({ strategies: [new MyPlatformStrategy()] });
|
|
6
|
+
*
|
|
7
|
+
* The runner is platform-agnostic; the embedding application supplies the
|
|
8
|
+
* `WebPostStrategy` implementations it wants to expose.
|
|
9
|
+
*/
|
|
10
|
+
import type { WebPostStrategy } from '../core/types';
|
|
11
|
+
import { AgentRunner, type ProviderFactory } from './runner';
|
|
12
|
+
export { loadConfig, type ProviderKind, type RunnerConfig } from './config';
|
|
13
|
+
export { handleLiveHttp, handleLiveUpgrade, parseLivePath, rewriteLiveHtml, } from './live-proxy';
|
|
14
|
+
export { AgentRunner, defaultProviderFactory, type ProviderFactory, } from './runner';
|
|
15
|
+
export { Mutex, SerializedProvider } from './serialized-provider';
|
|
16
|
+
export { createRunnerServer, HttpError, isAuthorized } from './server';
|
|
17
|
+
export type StartRunnerOptions = {
|
|
18
|
+
strategies: WebPostStrategy[];
|
|
19
|
+
env?: NodeJS.ProcessEnv;
|
|
20
|
+
providerFactory?: ProviderFactory;
|
|
21
|
+
onListening?: (info: {
|
|
22
|
+
port: number;
|
|
23
|
+
}) => void;
|
|
24
|
+
};
|
|
25
|
+
export declare function startRunner(opts: StartRunnerOptions): {
|
|
26
|
+
server: import("node:http").Server<typeof import("node:http").IncomingMessage, typeof import("node:http").ServerResponse>;
|
|
27
|
+
runner: AgentRunner;
|
|
28
|
+
config: import("./config").RunnerConfig;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,KAAK,eAAe,GACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEvE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAChD,CAAC;AAEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,kBAAkB;;;;EAoBnD"}
|