@prompteryx/sdk 0.4.0 → 0.4.1

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,197 +1,197 @@
1
- /**
2
- * `px.cloudBrowser.*` — sessions, one-shot fetch, search.
3
- *
4
- * The most-used path: `sessions.create()` returns a `connectUrl` you
5
- * pass to Playwright's `chromium.connectOverCDP(connectUrl)`. Your own
6
- * Playwright code drives the browser from there; we handle the
7
- * infrastructure (residential proxies, recording, persistence).
8
- *
9
- * ⚠️ KEY FAMILY (verified live 2026-09-03): every /api/v1/cloud-browser/*
10
- * route authenticates with a CLOUD BROWSER key (`pcb_live_…`) sent as
11
- * `x-api-key` — NOT the platform `px_live_…` Bearer key the rest of the
12
- * SDK uses. Pass it as `new Prompteryx({ apiKey, cloudBrowserKey })`;
13
- * calls throw a descriptive AuthError when it's missing.
14
- */
15
-
16
- import type { HttpClient, RequestOptions } from '../client'
17
- import { AuthError } from '../errors'
18
- import type {
19
- CloudFetchOptions,
20
- CloudFetchResult,
21
- CloudSearchResult,
22
- CloudSession,
23
- CloudSessionSummary,
24
- CreateSessionOptions,
25
- } from '../types'
26
-
27
- const MISSING_CB_KEY_MESSAGE =
28
- 'px.cloudBrowser.* uses a Cloud Browser API key (pcb_live_…), which is a ' +
29
- 'separate key family from the platform px_live_… key. Create one under ' +
30
- 'Cloud Platform → API Keys and pass it as ' +
31
- 'new Prompteryx({ apiKey, cloudBrowserKey }).'
32
-
33
- /** Sub-resource: cloud browser sessions. */
34
- export class SessionsResource {
35
- constructor(private readonly http: HttpClient) {}
36
-
37
- /** Headers for the pcb_live_ key family (throws a clear error if absent). */
38
- private cbAuth(): Record<string, string> {
39
- const key = this.http.cloudBrowserKey
40
- if (!key) throw new AuthError(MISSING_CB_KEY_MESSAGE)
41
- return { 'x-api-key': key }
42
- }
43
-
44
- private cbRequest<T>(path: string, opts: RequestOptions = {}): Promise<T> {
45
- return this.http.request<T>(path, {
46
- ...opts,
47
- headers: { ...this.cbAuth(), ...(opts.headers ?? {}) },
48
- })
49
- }
50
-
51
- /** Create a new browser session.
52
- *
53
- * Cloud (default):
54
- * ```ts
55
- * const s = await px.cloudBrowser.sessions.create()
56
- * // s.connectUrl → Prompteryx Cloud CDP. Bills cloud-browser minutes.
57
- * ```
58
- *
59
- * Local — uses YOUR machine's Chrome via the Prompteryx plugin +
60
- * Electron runner. ZERO cloud-browser minutes. Requires the plugin
61
- * to be running on the same machine as the SDK consumer; the call
62
- * short-circuits to localhost and never reaches the API.
63
- * ```ts
64
- * const s = await px.cloudBrowser.sessions.create({ target: 'local' })
65
- * // s.connectUrl → http://localhost:9222 (your Chrome's debug port)
66
- * ```
67
- *
68
- * When `target: 'local'` is set, cloud-only fields (recordSession,
69
- * proxy, profileId) are ignored — you're driving your own Chrome
70
- * with whatever cookies/extensions you've already installed.
71
- */
72
- async create(opts: CreateSessionOptions = {}): Promise<CloudSession> {
73
- if (opts.target === 'local') {
74
- // Local mode short-circuit. We don't hit the API at all — the
75
- // session is just a thin wrapper over the user's local Chrome's
76
- // CDP endpoint (managed by the Prompteryx plugin). Saves cloud
77
- // minutes AND avoids a round-trip. Failure to connect is the
78
- // consumer's problem at .connectOverCDP() time.
79
- const localCdp = 'http://127.0.0.1:9222'
80
- const localId = `local_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`
81
- return {
82
- id: localId,
83
- connectUrl: localCdp,
84
- status: 'active',
85
- startedAt: new Date().toISOString(),
86
- recordSession: false,
87
- }
88
- }
89
- // Wire names match the route (proxy/country), while the SDK options keep
90
- // the friendlier useProxy/proxyLocation spelling.
91
- return this.cbRequest<CloudSession>('/api/v1/cloud-browser/sessions', {
92
- method: 'POST',
93
- body: {
94
- recordSession: opts.recordSession,
95
- captureDownloads: opts.captureDownloads,
96
- extensions: opts.extensions,
97
- proxy: opts.useProxy,
98
- country: opts.proxyLocation,
99
- sessionTimeoutMinutes: opts.sessionTimeoutMinutes,
100
- profileId: opts.profileId,
101
- persistContext: opts.persistContext,
102
- viewport: opts.viewport,
103
- ...(opts.passthrough || {}),
104
- },
105
- })
106
- }
107
-
108
- /** Retrieve a session's history record (status/duration/recording flag).
109
- * Note: this is durable history, not a live handle — it has no
110
- * `connectUrl`. Keep the `create()` response for connecting. */
111
- async get(sessionId: string): Promise<CloudSessionSummary> {
112
- return this.cbRequest(
113
- `/api/v1/cloud-browser/sessions/${encodeURIComponent(sessionId)}`,
114
- )
115
- }
116
-
117
- /** List recent sessions for your account, newest first. */
118
- async list(opts: { limit?: number } = {}): Promise<CloudSessionSummary[]> {
119
- const res = await this.cbRequest<{ sessions: CloudSessionSummary[] }>(
120
- '/api/v1/cloud-browser/sessions',
121
- { query: { limit: opts.limit } },
122
- )
123
- return res.sessions ?? []
124
- }
125
-
126
- /** Close a session, finalising the recording (if any) + releasing the
127
- * cloud-browser slot. Idempotent. No-op for local sessions
128
- * (target: 'local') — those don't have a slot to release. */
129
- async close(sessionId: string): Promise<{ ok: boolean; proxyMB?: number }> {
130
- // Local sessions are pure client-side handles — nothing to release.
131
- if (sessionId.startsWith('local_')) return { ok: true }
132
- return this.cbRequest(
133
- `/api/v1/cloud-browser/sessions/${encodeURIComponent(sessionId)}`,
134
- { method: 'DELETE' },
135
- )
136
- }
137
- }
138
-
139
- export class CloudBrowserResource {
140
- readonly sessions: SessionsResource
141
-
142
- constructor(private readonly http: HttpClient) {
143
- this.sessions = new SessionsResource(http)
144
- }
145
-
146
- private cbAuth(): Record<string, string> {
147
- const key = this.http.cloudBrowserKey
148
- if (!key) throw new AuthError(MISSING_CB_KEY_MESSAGE)
149
- return { 'x-api-key': key }
150
- }
151
-
152
- /**
153
- * One-shot fetch through the cloud browser. Spins up a short-lived
154
- * session, loads the page in real Chromium (so JS-rendered sites work),
155
- * extracts the content, and tears down. Use this when you only need ONE
156
- * page and don't want to manage Playwright yourself.
157
- *
158
- * ```ts
159
- * const page = await px.cloudBrowser.fetch({
160
- * url: 'https://example.com/pricing',
161
- * format: 'markdown', // 'text' (default) | 'markdown' | 'html' | 'links'
162
- * waitForSelector: '.pricing-table', // for JS-rendered content
163
- * selectors: ['.pricing-table .plan'], // deterministic CSS extraction
164
- * })
165
- * // page.content, page.extracted, page.title, page.finalUrl …
166
- * ```
167
- */
168
- async fetch(opts: CloudFetchOptions): Promise<CloudFetchResult> {
169
- return this.http.request('/api/v1/cloud-browser/fetch', {
170
- method: 'POST',
171
- body: opts,
172
- headers: this.cbAuth(),
173
- timeoutMs: Math.max(90_000, (opts.timeoutMs ?? 30_000) + 30_000),
174
- })
175
- }
176
-
177
- /**
178
- * Search the web through the cloud browser and get structured results
179
- * (title/url/snippet). Runs the query against DuckDuckGo's server-rendered
180
- * HTML endpoint in a real browser — there is no engine choice today.
181
- */
182
- async search(opts: {
183
- query: string
184
- /** Max results, 1–25. Default 10. */
185
- limit?: number
186
- /** Route through a residential proxy. */
187
- proxy?: boolean
188
- /** Proxy exit country (with `proxy: true`), e.g. 'us'. */
189
- country?: string
190
- }): Promise<CloudSearchResult[]> {
191
- const res = await this.http.request<{ query: string; results: CloudSearchResult[] }>(
192
- '/api/v1/cloud-browser/search',
193
- { method: 'POST', body: opts, headers: this.cbAuth(), timeoutMs: 90_000 },
194
- )
195
- return res.results ?? []
196
- }
197
- }
1
+ /**
2
+ * `px.cloudBrowser.*` — sessions, one-shot fetch, search.
3
+ *
4
+ * The most-used path: `sessions.create()` returns a `connectUrl` you
5
+ * pass to Playwright's `chromium.connectOverCDP(connectUrl)`. Your own
6
+ * Playwright code drives the browser from there; we handle the
7
+ * infrastructure (residential proxies, recording, persistence).
8
+ *
9
+ * ⚠️ KEY FAMILY (verified live 2026-09-03): every /api/v1/cloud-browser/*
10
+ * route authenticates with a CLOUD BROWSER key (`pcb_live_…`) sent as
11
+ * `x-api-key` — NOT the platform `px_live_…` Bearer key the rest of the
12
+ * SDK uses. Pass it as `new Prompteryx({ apiKey, cloudBrowserKey })`;
13
+ * calls throw a descriptive AuthError when it's missing.
14
+ */
15
+
16
+ import type { HttpClient, RequestOptions } from '../client'
17
+ import { AuthError } from '../errors'
18
+ import type {
19
+ CloudFetchOptions,
20
+ CloudFetchResult,
21
+ CloudSearchResult,
22
+ CloudSession,
23
+ CloudSessionSummary,
24
+ CreateSessionOptions,
25
+ } from '../types'
26
+
27
+ const MISSING_CB_KEY_MESSAGE =
28
+ 'px.cloudBrowser.* uses a Cloud Browser API key (pcb_live_…), which is a ' +
29
+ 'separate key family from the platform px_live_… key. Create one under ' +
30
+ 'Cloud Platform → API Keys and pass it as ' +
31
+ 'new Prompteryx({ apiKey, cloudBrowserKey }).'
32
+
33
+ /** Sub-resource: cloud browser sessions. */
34
+ export class SessionsResource {
35
+ constructor(private readonly http: HttpClient) {}
36
+
37
+ /** Headers for the pcb_live_ key family (throws a clear error if absent). */
38
+ private cbAuth(): Record<string, string> {
39
+ const key = this.http.cloudBrowserKey
40
+ if (!key) throw new AuthError(MISSING_CB_KEY_MESSAGE)
41
+ return { 'x-api-key': key }
42
+ }
43
+
44
+ private cbRequest<T>(path: string, opts: RequestOptions = {}): Promise<T> {
45
+ return this.http.request<T>(path, {
46
+ ...opts,
47
+ headers: { ...this.cbAuth(), ...(opts.headers ?? {}) },
48
+ })
49
+ }
50
+
51
+ /** Create a new browser session.
52
+ *
53
+ * Cloud (default):
54
+ * ```ts
55
+ * const s = await px.cloudBrowser.sessions.create()
56
+ * // s.connectUrl → Prompteryx Cloud CDP. Bills cloud-browser minutes.
57
+ * ```
58
+ *
59
+ * Local — uses YOUR machine's Chrome via the Prompteryx plugin +
60
+ * Electron runner. ZERO cloud-browser minutes. Requires the plugin
61
+ * to be running on the same machine as the SDK consumer; the call
62
+ * short-circuits to localhost and never reaches the API.
63
+ * ```ts
64
+ * const s = await px.cloudBrowser.sessions.create({ target: 'local' })
65
+ * // s.connectUrl → http://localhost:9222 (your Chrome's debug port)
66
+ * ```
67
+ *
68
+ * When `target: 'local'` is set, cloud-only fields (recordSession,
69
+ * proxy, profileId) are ignored — you're driving your own Chrome
70
+ * with whatever cookies/extensions you've already installed.
71
+ */
72
+ async create(opts: CreateSessionOptions = {}): Promise<CloudSession> {
73
+ if (opts.target === 'local') {
74
+ // Local mode short-circuit. We don't hit the API at all — the
75
+ // session is just a thin wrapper over the user's local Chrome's
76
+ // CDP endpoint (managed by the Prompteryx plugin). Saves cloud
77
+ // minutes AND avoids a round-trip. Failure to connect is the
78
+ // consumer's problem at .connectOverCDP() time.
79
+ const localCdp = 'http://127.0.0.1:9222'
80
+ const localId = `local_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`
81
+ return {
82
+ id: localId,
83
+ connectUrl: localCdp,
84
+ status: 'active',
85
+ startedAt: new Date().toISOString(),
86
+ recordSession: false,
87
+ }
88
+ }
89
+ // Wire names match the route (proxy/country), while the SDK options keep
90
+ // the friendlier useProxy/proxyLocation spelling.
91
+ return this.cbRequest<CloudSession>('/api/v1/cloud-browser/sessions', {
92
+ method: 'POST',
93
+ body: {
94
+ recordSession: opts.recordSession,
95
+ captureDownloads: opts.captureDownloads,
96
+ extensions: opts.extensions,
97
+ proxy: opts.useProxy,
98
+ country: opts.proxyLocation,
99
+ sessionTimeoutMinutes: opts.sessionTimeoutMinutes,
100
+ profileId: opts.profileId,
101
+ persistContext: opts.persistContext,
102
+ viewport: opts.viewport,
103
+ ...(opts.passthrough || {}),
104
+ },
105
+ })
106
+ }
107
+
108
+ /** Retrieve a session's history record (status/duration/recording flag).
109
+ * Note: this is durable history, not a live handle — it has no
110
+ * `connectUrl`. Keep the `create()` response for connecting. */
111
+ async get(sessionId: string): Promise<CloudSessionSummary> {
112
+ return this.cbRequest(
113
+ `/api/v1/cloud-browser/sessions/${encodeURIComponent(sessionId)}`,
114
+ )
115
+ }
116
+
117
+ /** List recent sessions for your account, newest first. */
118
+ async list(opts: { limit?: number } = {}): Promise<CloudSessionSummary[]> {
119
+ const res = await this.cbRequest<{ sessions: CloudSessionSummary[] }>(
120
+ '/api/v1/cloud-browser/sessions',
121
+ { query: { limit: opts.limit } },
122
+ )
123
+ return res.sessions ?? []
124
+ }
125
+
126
+ /** Close a session, finalising the recording (if any) + releasing the
127
+ * cloud-browser slot. Idempotent. No-op for local sessions
128
+ * (target: 'local') — those don't have a slot to release. */
129
+ async close(sessionId: string): Promise<{ ok: boolean; proxyMB?: number }> {
130
+ // Local sessions are pure client-side handles — nothing to release.
131
+ if (sessionId.startsWith('local_')) return { ok: true }
132
+ return this.cbRequest(
133
+ `/api/v1/cloud-browser/sessions/${encodeURIComponent(sessionId)}`,
134
+ { method: 'DELETE' },
135
+ )
136
+ }
137
+ }
138
+
139
+ export class CloudBrowserResource {
140
+ readonly sessions: SessionsResource
141
+
142
+ constructor(private readonly http: HttpClient) {
143
+ this.sessions = new SessionsResource(http)
144
+ }
145
+
146
+ private cbAuth(): Record<string, string> {
147
+ const key = this.http.cloudBrowserKey
148
+ if (!key) throw new AuthError(MISSING_CB_KEY_MESSAGE)
149
+ return { 'x-api-key': key }
150
+ }
151
+
152
+ /**
153
+ * One-shot fetch through the cloud browser. Spins up a short-lived
154
+ * session, loads the page in real Chromium (so JS-rendered sites work),
155
+ * extracts the content, and tears down. Use this when you only need ONE
156
+ * page and don't want to manage Playwright yourself.
157
+ *
158
+ * ```ts
159
+ * const page = await px.cloudBrowser.fetch({
160
+ * url: 'https://example.com/pricing',
161
+ * format: 'markdown', // 'text' (default) | 'markdown' | 'html' | 'links'
162
+ * waitForSelector: '.pricing-table', // for JS-rendered content
163
+ * selectors: ['.pricing-table .plan'], // deterministic CSS extraction
164
+ * })
165
+ * // page.content, page.extracted, page.title, page.finalUrl …
166
+ * ```
167
+ */
168
+ async fetch(opts: CloudFetchOptions): Promise<CloudFetchResult> {
169
+ return this.http.request('/api/v1/cloud-browser/fetch', {
170
+ method: 'POST',
171
+ body: opts,
172
+ headers: this.cbAuth(),
173
+ timeoutMs: Math.max(90_000, (opts.timeoutMs ?? 30_000) + 30_000),
174
+ })
175
+ }
176
+
177
+ /**
178
+ * Search the web through the cloud browser and get structured results
179
+ * (title/url/snippet). Runs the query against DuckDuckGo's server-rendered
180
+ * HTML endpoint in a real browser — there is no engine choice today.
181
+ */
182
+ async search(opts: {
183
+ query: string
184
+ /** Max results, 1–25. Default 10. */
185
+ limit?: number
186
+ /** Route through a residential proxy. */
187
+ proxy?: boolean
188
+ /** Proxy exit country (with `proxy: true`), e.g. 'us'. */
189
+ country?: string
190
+ }): Promise<CloudSearchResult[]> {
191
+ const res = await this.http.request<{ query: string; results: CloudSearchResult[] }>(
192
+ '/api/v1/cloud-browser/search',
193
+ { method: 'POST', body: opts, headers: this.cbAuth(), timeoutMs: 90_000 },
194
+ )
195
+ return res.results ?? []
196
+ }
197
+ }
@@ -5,7 +5,7 @@
5
5
  * live v1 routes in docs/API_SDK_DEVELOPER_PLAN_GOLIVE_AUDIT.md. Kept as
6
6
  * source for a future release; do not re-export without re-verifying.
7
7
  *
8
- * `px.connectHub.*` — 2,800+ integrations.
8
+ * `px.connectHub.*` — 3,000+ integrations.
9
9
  *
10
10
  * Browse + run actions from any of the Pipedream-backed apps
11
11
  * Prompteryx exposes via Connect Hub (Gmail, Sheets, Slack,
package/src/types.ts CHANGED
@@ -510,7 +510,7 @@ export interface DiscoveredAction {
510
510
  example?: string
511
511
  }
512
512
 
513
- // ─── Connect Hub (2,800+ integrations) ───────────────────────────────────
513
+ // ─── Connect Hub (3,000+ integrations) ───────────────────────────────────
514
514
 
515
515
  export interface ConnectHubAppSummary {
516
516
  /** Pipedream slug ('gmail', 'google-sheets', ...). */