@conto_finance/sdk 0.3.1 → 0.5.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.
@@ -0,0 +1,141 @@
1
+ import { Browser } from 'playwright-core';
2
+ import { GuardedPlaywrightCheckoutHttpHandler, PlaywrightSessionObservation, GuardedPlaywrightCheckoutClient, PlaywrightCdpSessionRegistryConfig, EncryptedPlaywrightCheckoutTargetStoreConfig, GuardedPlaywrightCheckoutRuntimeConfig } from './playwright.js';
3
+ import './index.js';
4
+
5
+ /** Exact provider endpoints verified against Browserbase's session API; never use a wildcard. */
6
+ declare const BROWSERBASE_CONNECT_ORIGINS: readonly string[];
7
+ type BrowserbaseSessionStatus = 'PENDING' | 'RUNNING' | 'ERROR' | 'TIMED_OUT' | 'COMPLETED';
8
+ type BrowserbaseSessionBindingState = 'ACTIVE' | 'REVOKED';
9
+ type BrowserbaseSessionLifecycleOwner = 'CONTO_RUNTIME' | 'AGENT_HOST';
10
+ /** Credential-free durable record. Never persist Browserbase connect URLs or API keys here. */
11
+ interface BrowserbaseSessionBinding {
12
+ browserSessionId: string;
13
+ organizationId: string;
14
+ agentId: string;
15
+ projectId: string;
16
+ /** Missing legacy values are treated as CONTO_RUNTIME. */
17
+ lifecycleOwner?: BrowserbaseSessionLifecycleOwner;
18
+ state: BrowserbaseSessionBindingState;
19
+ createdAt: string;
20
+ expiresAt: string;
21
+ }
22
+ /**
23
+ * Durable ownership port for remote sessions. `create` must reject duplicate IDs and `revoke`
24
+ * must atomically transition only an ACTIVE record matching every supplied ownership field.
25
+ */
26
+ interface BrowserbaseSessionBindingStore {
27
+ create(binding: BrowserbaseSessionBinding): Promise<boolean>;
28
+ get(browserSessionId: string): Promise<BrowserbaseSessionBinding | null>;
29
+ revoke(input: {
30
+ browserSessionId: string;
31
+ organizationId: string;
32
+ agentId: string;
33
+ projectId: string;
34
+ revokedAt: string;
35
+ }): Promise<boolean>;
36
+ /** Required with contextId. Release only after Browserbase confirms the provider session closed. */
37
+ releaseContextLease?(input: {
38
+ browserSessionId: string;
39
+ organizationId: string;
40
+ agentId: string;
41
+ projectId: string;
42
+ }): Promise<boolean>;
43
+ }
44
+ interface BrowserbaseSessionConfig {
45
+ /** Browserbase credential retained by the privileged runtime. Conto credentials are rejected. */
46
+ apiKey: string;
47
+ projectId: string;
48
+ organizationId: string;
49
+ agentId: string;
50
+ bindingStore: BrowserbaseSessionBindingStore;
51
+ /** Optional 32-byte server-only key required to attach sessions created by an agent host. */
52
+ handoffKey?: Uint8Array;
53
+ /** Optional server-only Browserbase Context used to persist Link or merchant authentication. */
54
+ contextId?: string;
55
+ /** Browserbase session timeout. Defaults to 900 seconds. */
56
+ timeoutSeconds?: number;
57
+ /** Browserbase API request timeout. Defaults to 10 seconds and may not exceed 60 seconds. */
58
+ requestTimeoutMs?: number;
59
+ /** Injected for tests or runtimes with an instrumented fetch implementation. */
60
+ fetch?: typeof fetch;
61
+ now?: () => Date;
62
+ }
63
+ interface BrowserbaseGuardedPlaywrightCheckoutRuntimeHostConfig {
64
+ conto: GuardedPlaywrightCheckoutClient;
65
+ browserbase: BrowserbaseSessionConfig;
66
+ /** Usually `(url) => chromium.connectOverCDP(url)`. */
67
+ connectOverCDP(connectUrl: string): Promise<Browser>;
68
+ selectPage?: PlaywrightCdpSessionRegistryConfig['selectPage'];
69
+ maxSessions?: number;
70
+ targetStore: EncryptedPlaywrightCheckoutTargetStoreConfig;
71
+ dispatchAttemptFor: GuardedPlaywrightCheckoutRuntimeConfig['dispatchAttemptFor'];
72
+ /** Dedicated service credential. Conto and Browserbase API keys are rejected. */
73
+ token: string;
74
+ maxBodyBytes?: number;
75
+ clickTimeoutMs?: number;
76
+ popupTimeoutMs?: number;
77
+ targetTtlMs?: number;
78
+ now?: () => Date;
79
+ }
80
+ /** Safe session projection for the agent-facing browser launcher. */
81
+ interface BrowserbaseOwnedSession {
82
+ browserSessionId: string;
83
+ status: Extract<BrowserbaseSessionStatus, 'PENDING' | 'RUNNING'>;
84
+ expiresAt: string;
85
+ }
86
+ /** Proof-carrying request from a trusted agent host for an existing Browserbase session. */
87
+ interface BrowserbaseSessionHandoff {
88
+ browserSessionId: string;
89
+ handoffAssertion: string;
90
+ }
91
+ /** Safe projection for a session whose provider lifecycle remains owned by the agent host. */
92
+ interface BrowserbaseAttachedSession extends BrowserbaseOwnedSession {
93
+ lifecycleOwner: 'AGENT_HOST';
94
+ }
95
+ interface BrowserbaseSessionHandoffAssertionInput {
96
+ browserSessionId: string;
97
+ projectId: string;
98
+ organizationId: string;
99
+ agentId: string;
100
+ expiresAt: string;
101
+ }
102
+ /** Operator-only capability for a human authentication or challenge handoff. */
103
+ interface BrowserbaseOwnedLiveView {
104
+ browserSessionId: string;
105
+ liveViewUrl: string;
106
+ expiresAt: string;
107
+ }
108
+ /**
109
+ * Closed Browserbase lifecycle plus guarded checkout façade. It never exposes the provider API
110
+ * key, CDP connection URL, Playwright page, target store, discovery primitive, or raw dispatch.
111
+ */
112
+ interface BrowserbaseGuardedPlaywrightCheckoutRuntimeHost {
113
+ handler: GuardedPlaywrightCheckoutHttpHandler;
114
+ createSession(): Promise<BrowserbaseOwnedSession>;
115
+ /** Attaches an existing agent-host session after verifying a short-lived server assertion. */
116
+ attachSession(input: BrowserbaseSessionHandoff): Promise<BrowserbaseAttachedSession>;
117
+ /** Read-only, bounded projection of the exact runtime-owned page. */
118
+ observeSession(browserSessionId: string): Promise<PlaywrightSessionObservation>;
119
+ /** Returns a short-lived provider capability only to a separately authenticated operator path. */
120
+ liveViewForSession(browserSessionId: string): Promise<BrowserbaseOwnedLiveView>;
121
+ /** Revokes Conto ownership first, closes the local connection, then releases Browserbase. */
122
+ releaseSession(browserSessionId: string): Promise<void>;
123
+ /** Revokes the Conto binding without ending the externally owned Browserbase session. */
124
+ detachSession(browserSessionId: string): Promise<void>;
125
+ /** Closes local Playwright connections. Call releaseSession for each keep-alive provider session. */
126
+ close(): Promise<void>;
127
+ }
128
+ type BrowserbaseSessionErrorCode = 'BROWSERBASE_CONFIG_INVALID' | 'BROWSERBASE_PROVIDER_UNAVAILABLE' | 'BROWSERBASE_PROVIDER_RESPONSE_INVALID' | 'BROWSERBASE_SESSION_BINDING_FAILED' | 'BROWSERBASE_SESSION_HANDOFF_DISABLED' | 'BROWSERBASE_SESSION_HANDOFF_INVALID' | 'BROWSERBASE_LIVE_VIEW_UNAVAILABLE' | 'BROWSERBASE_SESSION_NOT_OWNED' | 'BROWSERBASE_SESSION_RELEASE_FAILED';
129
+ declare class BrowserbaseSessionError extends Error {
130
+ readonly code: BrowserbaseSessionErrorCode;
131
+ constructor(code: BrowserbaseSessionErrorCode, message: string);
132
+ }
133
+ /** Creates a short-lived assertion after the trusted agent host creates its Browserbase session. */
134
+ declare function createBrowserbaseSessionHandoffAssertion(input: BrowserbaseSessionHandoffAssertionInput, keyValue: Uint8Array): string;
135
+ /**
136
+ * Creates the recommended Browserbase deployment boundary. Provider lifecycle, ownership checks,
137
+ * remote connection resolution, guarded execution, and cleanup remain in one privileged object.
138
+ */
139
+ declare function createBrowserbaseGuardedPlaywrightCheckoutRuntimeHost(config: BrowserbaseGuardedPlaywrightCheckoutRuntimeHostConfig): BrowserbaseGuardedPlaywrightCheckoutRuntimeHost;
140
+
141
+ export { BROWSERBASE_CONNECT_ORIGINS, type BrowserbaseAttachedSession, type BrowserbaseGuardedPlaywrightCheckoutRuntimeHost, type BrowserbaseGuardedPlaywrightCheckoutRuntimeHostConfig, type BrowserbaseOwnedLiveView, type BrowserbaseOwnedSession, type BrowserbaseSessionBinding, type BrowserbaseSessionBindingState, type BrowserbaseSessionBindingStore, type BrowserbaseSessionConfig, BrowserbaseSessionError, type BrowserbaseSessionErrorCode, type BrowserbaseSessionHandoff, type BrowserbaseSessionHandoffAssertionInput, type BrowserbaseSessionLifecycleOwner, type BrowserbaseSessionStatus, createBrowserbaseGuardedPlaywrightCheckoutRuntimeHost, createBrowserbaseSessionHandoffAssertion };