@prompteryx/sdk 0.4.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/src/types.ts ADDED
@@ -0,0 +1,680 @@
1
+ /**
2
+ * Shared types for the Prompteryx SDK.
3
+ *
4
+ * Two important framing decisions reflected here:
5
+ *
6
+ * 1. NAMING: We use Prompteryx-native names throughout — `copilot`,
7
+ * `autopilot`, `read`, `scan`, `do`, `run`. We deliberately don't
8
+ * use the Stagehand vocabulary (act/extract/observe/agent).
9
+ * 2. EXTENSIBILITY: Many fields accept `string` rather than enums so
10
+ * new Visual Studio nodes / new Gemini models / new providers
11
+ * work the moment they're available server-side, without the SDK
12
+ * needing a release. Where we DO enum, the type adds `| string`
13
+ * so callers can still pass forward-compatible values.
14
+ */
15
+
16
+ import type { AutopilotModel } from './models'
17
+
18
+ // ─── Common ──────────────────────────────────────────────────────────────
19
+
20
+ export type ExecutionStatus =
21
+ | 'queued'
22
+ | 'running'
23
+ | 'completed'
24
+ | 'failed'
25
+ | 'cancelled'
26
+ | 'timed_out'
27
+
28
+ export type Region =
29
+ | 'us-east-1'
30
+ | 'us-west-2'
31
+ | 'eu-west-1'
32
+ | 'eu-central-1'
33
+ | 'ap-southeast-1'
34
+ | (string & {})
35
+
36
+ export type ProxyLocation =
37
+ | 'auto'
38
+ | 'us' | 'gb' | 'ca' | 'de' | 'fr' | 'au' | 'in' | 'br' | 'jp'
39
+ | (string & {})
40
+
41
+ /** Where a workflow runs. Cloud = our infrastructure (always works).
42
+ * Local = the user's own Chrome via the Prompteryx plugin (more
43
+ * capable for tasks needing the user's real logins). */
44
+ export type ExecutionTarget = 'cloud' | 'local'
45
+
46
+ // ─── Workflows ───────────────────────────────────────────────────────────
47
+
48
+ export interface WorkflowSummary {
49
+ /** `wf_…` */
50
+ id: string
51
+ name: string
52
+ description?: string
53
+ createdAt: string
54
+ updatedAt: string
55
+ nodeCount?: number
56
+ /** True if the workflow has an active schedule attached. */
57
+ scheduled?: boolean
58
+ /** Tags / categories the user has assigned. */
59
+ tags?: string[]
60
+ }
61
+
62
+ /**
63
+ * Every option the Visual Studio UI exposes when you run a workflow.
64
+ * Adding a new option in the UI? Add it here too. Anything passed in
65
+ * an `executionOptions` field unrecognised by the SDK still rides
66
+ * through (passthrough = future-proof).
67
+ */
68
+ export interface WorkflowExecutionOptions {
69
+ /** Run on cloud browser (default) or via the user's local Chrome
70
+ * through the Prompteryx plugin. */
71
+ target?: ExecutionTarget
72
+ /** Chrome profile id (cloud or local). Override the workflow's
73
+ * saved profile for this one run. */
74
+ chromeProfile?: string
75
+ /** 'visible' = headed; 'headless' = no UI. */
76
+ runMode?: 'visible' | 'headless'
77
+ /** Capture a video recording. */
78
+ videoRecording?: boolean
79
+ /** "Turbo" mode skips visual polish + delay tweaks for speed. */
80
+ turboBoost?: boolean
81
+ /** Max execution time in ms. */
82
+ timeout?: number
83
+ /** Return every node's output in the execution record (heavy). */
84
+ includeNodeOutputs?: boolean
85
+ /** Override viewport size. */
86
+ viewport?: { width: number; height: number }
87
+ /** Run in a specific region (cloud only). */
88
+ region?: Region
89
+ /** Use residential proxy. */
90
+ useProxy?: boolean
91
+ /** Proxy exit country. */
92
+ proxyLocation?: ProxyLocation
93
+ /** Auto-solve CAPTCHAs during the run. */
94
+ useCaptcha?: boolean
95
+ /** Free-form passthrough — anything unrecognised by the SDK is
96
+ * forwarded to the server intact. Use for new server-side
97
+ * options before the SDK gets a release for them. */
98
+ passthrough?: Record<string, unknown>
99
+ }
100
+
101
+ export interface RunWorkflowOptions {
102
+ /** Workflow variables / input the workflow expects. */
103
+ input?: Record<string, unknown>
104
+ /** Execution options — overrides the workflow's saved settings. */
105
+ execution?: WorkflowExecutionOptions
106
+ }
107
+
108
+ export interface RunWorkflowResult {
109
+ executionId: string
110
+ status: ExecutionStatus
111
+ workflowId: string
112
+ startedAt?: string
113
+ }
114
+
115
+ // ─── Executions ──────────────────────────────────────────────────────────
116
+
117
+ export interface ExecutionRecord {
118
+ id: string
119
+ workflowId: string
120
+ status: ExecutionStatus
121
+ startedAt: string
122
+ finishedAt?: string
123
+ durationMs?: number
124
+ outputs?: Record<string, unknown>
125
+ /** Detailed final state of every node (only when
126
+ * `execution.includeNodeOutputs` was set to true). */
127
+ nodeOutputs?: Record<string, unknown>
128
+ error?: { message: string; nodeId?: string; nodeLabel?: string }
129
+ nodeErrors?: Array<{ nodeId: string; nodeLabel?: string; message: string }>
130
+ /** AI Credit + cloud-minute + proxy-MB + CAPTCHA consumption. */
131
+ usage?: {
132
+ aiCredits?: number
133
+ cloudBrowserMinutes?: number
134
+ proxyDataMB?: number
135
+ captchaSolves?: number
136
+ connectHubCalls?: number
137
+ }
138
+ }
139
+
140
+ export interface ExecutionLogEvent {
141
+ type: 'log' | 'progress' | 'node-start' | 'node-end' | 'error' | 'done'
142
+ message?: string
143
+ nodeId?: string
144
+ nodeLabel?: string
145
+ timestamp: string
146
+ level?: 'info' | 'warn' | 'error' | 'debug'
147
+ data?: unknown
148
+ }
149
+
150
+ // ─── Cloud Browser ───────────────────────────────────────────────────────
151
+
152
+ export interface CreateSessionOptions {
153
+ /**
154
+ * Where the browser should actually run.
155
+ * • 'cloud' (default) — Prompteryx Cloud / AWS fleet, billed in
156
+ * cloud-browser minutes.
157
+ * • 'local' — your own Chrome via the Prompteryx plugin + Electron
158
+ * runner. ZERO cloud minutes, but requires the plugin to be
159
+ * running on the SAME machine as the SDK consumer (your script
160
+ * talks to localhost). Best for personal dev work where you want
161
+ * a real browser but don't want to spend cloud minutes.
162
+ * See README "Local mode" for the prereqs.
163
+ */
164
+ target?: 'cloud' | 'local'
165
+ recordSession?: boolean
166
+ captureDownloads?: boolean
167
+ /** Storage keys for bring-your-own Chrome extensions
168
+ * (.tar.gz bundles uploaded via the platform). */
169
+ extensions?: string[]
170
+ /** Route the session through a residential proxy (sent as the wire
171
+ * field `proxy`). */
172
+ useProxy?: boolean
173
+ /** Proxy exit country (sent as the wire field `country`, e.g. 'us'). */
174
+ proxyLocation?: ProxyLocation
175
+ /** Auto-close the session after this many minutes. */
176
+ sessionTimeoutMinutes?: number
177
+ /**
178
+ * Reuse a named cloud profile (preserves cookies + storage state
179
+ * across sessions). OPTIONAL — when omitted the session is
180
+ * ephemeral: nothing is loaded at start, nothing is saved at close,
181
+ * which is usually what you want for one-off automations. Naming a
182
+ * profile implicitly opts in to persistence — you don't need to set
183
+ * `persistContext` as well.
184
+ */
185
+ profileId?: string
186
+ /**
187
+ * Explicit persistence opt-in WITHOUT naming a profile. Uses the
188
+ * account's Default profile. Most users should leave this alone and
189
+ * either pass `profileId` (named profile) or nothing (ephemeral).
190
+ */
191
+ persistContext?: boolean
192
+ /** Custom viewport. */
193
+ viewport?: { width: number; height: number }
194
+ /** Anything unrecognised by the SDK is forwarded as-is. */
195
+ passthrough?: Record<string, unknown>
196
+ }
197
+
198
+ /** Response of `sessions.create` — matches POST /api/v1/cloud-browser/sessions. */
199
+ export interface CloudSession {
200
+ id: string
201
+ /** CDP endpoint — pass to `chromium.connectOverCDP(connectUrl)`. */
202
+ connectUrl: string
203
+ /** Watch-it-live URL (when the provider supports it). */
204
+ liveURL?: string | null
205
+ status: 'launching' | 'active' | 'closed' | 'failed' | (string & {})
206
+ startedAt: string
207
+ recordSession?: boolean
208
+ }
209
+
210
+ /** Row returned by `sessions.list` / `sessions.get` — durable session
211
+ * history, NOT a live handle (no connectUrl). */
212
+ export interface CloudSessionSummary {
213
+ id: string
214
+ status: string
215
+ provider?: string
216
+ startedAt?: string
217
+ endedAt?: string | null
218
+ durationMs?: number | null
219
+ region?: string
220
+ hasRecording?: boolean
221
+ }
222
+
223
+ /** Options for the one-shot `cloudBrowser.fetch` — matches
224
+ * POST /api/v1/cloud-browser/fetch. */
225
+ export interface CloudFetchOptions {
226
+ url: string
227
+ /** What to return in `content`. Default 'text' (readable text —
228
+ * token-efficient for LLMs). 'links' fills `links` instead. */
229
+ format?: 'text' | 'markdown' | 'html' | 'links'
230
+ /** Navigation wait state. Default 'domcontentloaded'. */
231
+ waitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit'
232
+ /** Page-load budget in ms (5000–60000, default 30000). */
233
+ timeoutMs?: number
234
+ /** Route through a residential proxy. */
235
+ proxy?: boolean
236
+ /** Proxy exit country (with `proxy: true`), e.g. 'us'. */
237
+ country?: string
238
+ /** After load, wait until this CSS selector exists (JS-rendered content). */
239
+ waitForSelector?: string
240
+ /** Extra settle time after load/selector, ms (capped at 10000). */
241
+ waitMs?: number
242
+ /** Up to 10 CSS selectors extracted deterministically — per selector the
243
+ * match count and the first 50 elements' text + outerHTML (capped). */
244
+ selectors?: string[]
245
+ /** Include a base64 JPEG of the viewport in the response. */
246
+ screenshot?: boolean
247
+ }
248
+
249
+ /** Response of `cloudBrowser.fetch`. */
250
+ export interface CloudFetchResult {
251
+ url: string
252
+ finalUrl: string
253
+ title: string
254
+ status: string
255
+ /** Page content in the requested `format` (absent for format 'links'). */
256
+ content?: string
257
+ /** Present for format 'links'. */
258
+ links?: Array<{ text: string; href: string }>
259
+ /** Present when `waitForSelector` was given — whether it appeared in time. */
260
+ waitedSelector?: boolean
261
+ /** Present when `selectors` were given. */
262
+ extracted?: Array<{
263
+ selector: string
264
+ count?: number
265
+ elements?: Array<{ text: string; html: string }>
266
+ error?: string
267
+ }>
268
+ /** Present when `screenshot: true`. */
269
+ screenshotBase64?: string
270
+ }
271
+
272
+ export interface CloudSearchResult {
273
+ title: string
274
+ url: string
275
+ snippet: string
276
+ }
277
+
278
+ // ─── Autopilot (autonomous agent) ────────────────────────────────────────
279
+
280
+ /**
281
+ * Every option exposed by the in-app AI Browser Agent surface, plus
282
+ * SDK-only hooks. Naming is `autopilot` not `agent` — autopilot
283
+ * implies "runs the whole task end-to-end without you", which is
284
+ * what this actually does.
285
+ */
286
+ export interface AutopilotRunOptions {
287
+ /** What the autopilot should accomplish, in plain English. */
288
+ goal: string
289
+ /** Where to start. The autopilot navigates here before reasoning. */
290
+ startUrl?: string
291
+ /** Max reasoning steps before giving up. Default 30. */
292
+ maxSteps?: number
293
+ /** Hard cap on AI Credits this run may spend — the run stops once reached.
294
+ * A cost guardrail for unattended/automated runs (pairs with maxSteps). */
295
+ maxCredits?: number
296
+ /** Cost-saving action batching — let the model chain several safe actions per
297
+ * screenshot before taking the next one (cheaper on simple same-page tasks).
298
+ * Default false. */
299
+ costSaving?: boolean
300
+ /** When `costSaving` is on: max actions the model may chain per screenshot
301
+ * (2–20, default 5). Higher = cheaper on simple pages; lower = safer. */
302
+ costSavingMaxBatch?: number
303
+ /** When `costSaving` is on: "careful batching" — take a fresh screenshot after
304
+ * each submit/commit action in a batch, so the agent never types the next
305
+ * record blind. Fewer skipped/duplicated rows on form loops. Default false. */
306
+ carefulBatching?: boolean
307
+ /** AI Vision quality preset. Lower presets are cheaper and faster per step;
308
+ * higher presets read small text and dense pages more accurately.
309
+ * One of: 'ultra-saver' | 'low' | 'saver' | 'efficient' | 'balanced' |
310
+ * 'detailed' | 'enhanced' | 'precision' | 'max-precision'. */
311
+ aiVision?: 'ultra-saver' | 'low' | 'saver' | 'efficient' | 'balanced'
312
+ | 'detailed' | 'enhanced' | 'precision' | 'max-precision' | (string & {})
313
+ /** Final-step quality boost: one extra look at the finished page at this
314
+ * preset right before the answer is written — sharper reads of prices,
315
+ * dates and small text for one screenshot's extra cost.
316
+ * 'same' (default) = off. */
317
+ finalStepVision?: 'same' | 'ultra-saver' | 'low' | 'saver' | 'efficient'
318
+ | 'balanced' | 'detailed' | 'enhanced' | 'precision' | 'max-precision' | (string & {})
319
+ /** Structured output: a JSON Schema object for the final answer. When set,
320
+ * `finalAnswer` is JSON conforming to this schema (the server also accepts
321
+ * the snake_case `output_schema` spelling via passthrough). */
322
+ outputSchema?: Record<string, unknown>
323
+ /**
324
+ * Safety checkpoints. 'auto' (default) auto-consents past the model's safety
325
+ * decisions (e.g. submitting a form) — best for unattended runs. 'ask' pauses
326
+ * the job (status becomes terminal `awaiting_input`, with the checkpoint in
327
+ * `finalAnswer`) so you can review and resume it. Mirrors the settings dialog's
328
+ * "Auto-consent to safety checkpoints" toggle.
329
+ */
330
+ safetyConsent?: 'auto' | 'ask'
331
+ /**
332
+ * "Check unclear or risky tasks" (default ON). When on, a too-vague goal makes
333
+ * the agent ask a clarifying question first, and it confirms before an
334
+ * irreversible/costly action instead of guessing — surfacing as a terminal
335
+ * `awaiting_input` with the question in `finalAnswer`. Pass false to always
336
+ * proceed with a best guess.
337
+ */
338
+ confirmUnclear?: boolean
339
+ /**
340
+ * Smart Context Compression (default OFF). Summarises long sessions to cut token
341
+ * cost (~70% on long tasks). `compressionThreshold` = compress after this many
342
+ * steps (default 8).
343
+ */
344
+ enableContextCompression?: boolean
345
+ compressionThreshold?: number
346
+ /**
347
+ * Fresh-session reset (default OFF) — an alternative long-task cost saver. Every
348
+ * N turns it starts a clean session from a verified progress summary so per-step
349
+ * cost stops climbing. `sessionResetThreshold` = reset every N turns (default 12).
350
+ */
351
+ enableSessionReset?: boolean
352
+ sessionResetThreshold?: number
353
+ /**
354
+ * Where the autopilot should drive the browser.
355
+ * • 'cloud' (default) — cloud browser, bills cloud-browser minutes.
356
+ * • 'local' (v0.3+) — YOUR local Chrome via the Prompteryx desktop app.
357
+ * ZERO cloud-browser minutes; AI Credits still apply. Requirements:
358
+ * the desktop app must be RUNNING and SIGNED IN on this machine, and
359
+ * your code must run on the same machine (the SDK talks to the app
360
+ * directly at http://localhost:61337 — override with `runnerUrl`).
361
+ * The browser tab stays open after the run for inspection/follow-ups.
362
+ */
363
+ target?: 'cloud' | 'local'
364
+ /** Local target only: the desktop app's local address.
365
+ * Default 'http://localhost:61337'. */
366
+ runnerUrl?: string
367
+ /** Which browser-agent model to use. Default: 'gemini-3.5-flash'.
368
+ * The known catalog is `AUTOPILOT_MODELS` (see models.ts — mirrored from
369
+ * the platform's canonical V2_BROWSER_MODELS list); any other string is
370
+ * forwarded as-is for forward compatibility, but an id the server doesn't
371
+ * know hard-400s with UNSUPPORTED_MODEL. */
372
+ model?: AutopilotModel
373
+ /**
374
+ * Capture the discovered action sequence as a permanent workflow
375
+ * the user can replay forever at zero AI cost — the action-caching
376
+ * pattern, materialised as a first-class Visual Studio workflow
377
+ * (schedulable, shareable, editable, multi-option-selector
378
+ * resilient). The response includes `savedWorkflowId`.
379
+ */
380
+ saveAsWorkflow?: boolean
381
+ /** Display name for the saved workflow. Defaults to a slug of `goal`. */
382
+ savedWorkflowName?: string
383
+ /** Hard timeout for the whole run in ms. Default 5 minutes. */
384
+ timeoutMs?: number
385
+ /** Run on a pre-existing cloud session. If omitted the autopilot
386
+ * spins up a fresh one + closes it on completion. */
387
+ sessionId?: string
388
+ /** Override the autopilot's system prompt. Advanced — most users
389
+ * shouldn't set this. Used for niche bespoke tasks where the
390
+ * default prompt loses subtlety (e.g. "always confirm before
391
+ * submitting any form"). */
392
+ systemPromptOverride?: string
393
+ /** Restrict the tools the autopilot can use. By default all of
394
+ * click / type / scroll / navigate / press_key / hover / extract
395
+ * are available; pass a subset to constrain behaviour (e.g.
396
+ * `['click', 'extract']` for a read-only task). */
397
+ allowedTools?: string[]
398
+ /** Viewport for the cloud browser session the autopilot uses. */
399
+ viewport?: { width: number; height: number }
400
+ /** Per-session controls forwarded to the underlying cloud-browser
401
+ * session creation. Ignored when `sessionId` is set. */
402
+ session?: Omit<CreateSessionOptions, 'viewport'>
403
+ /**
404
+ * MULTI-AGENT SWARM. Run the goal across N parallel cloud agents instead of
405
+ * one. Default 1 (a normal single-agent run). When > 1 the response gains a
406
+ * `swarm` block with per-agent answers/usage, and `finalAnswer` is the merged
407
+ * result across all agents. Each agent still respects `maxCredits`; use
408
+ * `maxRunCredits` to bound the whole run.
409
+ */
410
+ agents?: number
411
+ /**
412
+ * Swarm coordination style (only meaningful when `agents` > 1):
413
+ * • false (default) — N INDEPENDENT agents, each runs the FULL `goal` in its
414
+ * own browser (fastest for "do the same thing N ways / N places").
415
+ * • true — COLLABORATE via a shared work-queue: the goal (or the attached
416
+ * spreadsheet, one item per row) is split into work items that agents claim
417
+ * atomically — none done twice, none missed, idle agents work-steal.
418
+ */
419
+ collaborate?: boolean
420
+ /** Collaborate mode: a spreadsheet's TEXT (CSV / TSV / pipe table). When it looks
421
+ * like a row table the shared queue is seeded ONE work item per ROW. */
422
+ attachmentContext?: string
423
+ /** Swarm whole-run credit budget (admission control). Once the run's total AI
424
+ * Credits reach this, agents stop claiming new work items and wrap up what's in
425
+ * flight. 0/undefined = no cap. Distinct from per-agent `maxCredits`. */
426
+ maxRunCredits?: number
427
+ /** Passthrough for future server-side options. */
428
+ passthrough?: Record<string, unknown>
429
+ }
430
+
431
+ export interface AutopilotStep {
432
+ step: number
433
+ action: string
434
+ reasoning?: string
435
+ /** Base64 JPEG screenshot taken before the step (debugging aid). */
436
+ screenshot?: string
437
+ result?: unknown
438
+ }
439
+
440
+ export interface AutopilotRunResult {
441
+ success: boolean
442
+ /** The autopilot's final summary / answer. */
443
+ finalAnswer?: string
444
+ steps: AutopilotStep[]
445
+ /** `wf_…` if `saveAsWorkflow` was true. Run it later with
446
+ * `px.workflows.run(savedWorkflowId)` for zero-AI-cost replay. */
447
+ savedWorkflowId?: string
448
+ /** AI Credit + token usage telemetry. Sums ALL agents on a swarm run. */
449
+ usage?: {
450
+ aiCredits: number
451
+ tokensIn?: number
452
+ tokensOut?: number
453
+ /** USD cost the platform charged the user (1 credit = $0.01). */
454
+ costUSD?: number
455
+ /** Model turns (think-and-act cycles) the run took. */
456
+ turns?: number
457
+ }
458
+ /** Present only when `agents` > 1 — the multi-agent swarm detail. `finalAnswer`
459
+ * above is the merged answer across every agent; this exposes each agent's own
460
+ * answer/usage/session and (collaborate mode) the shared work-queue coverage. */
461
+ swarm?: {
462
+ mode: 'collaborate' | 'independent'
463
+ status: 'completed' | 'partial' | 'error'
464
+ agents: Array<{
465
+ idx: number
466
+ title: string
467
+ status: 'completed' | 'error' | 'stopped'
468
+ finalAnswer: string
469
+ costUSD: number
470
+ inTokens: number
471
+ outTokens: number
472
+ turns: number
473
+ sessionId: string
474
+ recordingUrl?: string
475
+ error?: string
476
+ }>
477
+ /** Shared-queue coverage (collaborate mode): items total / done / failed / etc. */
478
+ coverage?: {
479
+ total: number
480
+ done: number
481
+ failed: number
482
+ claimed: number
483
+ unclaimed: number
484
+ }
485
+ }
486
+ }
487
+
488
+ // ─── Copilot (single-action / read / scan) ───────────────────────────────
489
+
490
+ export interface CopilotDoResult {
491
+ success: boolean
492
+ action: string
493
+ selector?: string
494
+ /** True when every ranked selector failed and the AI-vision coordinate
495
+ * fallback was used instead. Lets you spot pages where stable selectors
496
+ * aren't resolving so you can tighten them. */
497
+ usedVisionFallback?: boolean
498
+ durationMs: number
499
+ error?: string
500
+ }
501
+
502
+ export interface DiscoveredAction {
503
+ /** Semantic intent: 'click', 'fill', 'select', 'hover'. */
504
+ type: string
505
+ selector: string
506
+ alternativeSelectors?: string[]
507
+ description: string
508
+ /** Natural-language instruction the user would describe this with
509
+ * ("click the Sign up button"). Useful for `px.copilot.do(page, a.example)`. */
510
+ example?: string
511
+ }
512
+
513
+ // ─── Connect Hub (2,800+ integrations) ───────────────────────────────────
514
+
515
+ export interface ConnectHubAppSummary {
516
+ /** Pipedream slug ('gmail', 'google-sheets', ...). */
517
+ slug: string
518
+ name: string
519
+ iconUrl?: string
520
+ /** Categories the app belongs to. */
521
+ categories?: string[]
522
+ }
523
+
524
+ export interface ConnectHubActionSummary {
525
+ app: string
526
+ /** Action key ('send_message', 'create_row', etc.). */
527
+ action: string
528
+ name: string
529
+ description?: string
530
+ /** Parameter spec — the schema the user must satisfy in `params`. */
531
+ parameters?: Record<string, unknown>
532
+ }
533
+
534
+ export interface RunConnectHubActionOptions {
535
+ app: string
536
+ action: string
537
+ /** Action parameters. Shape depends on the action — call
538
+ * `px.connectHub.getAction(app, action)` to fetch the schema. */
539
+ params: Record<string, unknown>
540
+ /** Optional credential id if the user has multiple accounts of the
541
+ * same app connected. Defaults to the most recently used. */
542
+ credentialId?: string
543
+ }
544
+
545
+ // ─── Custom Nodes (user-built) ───────────────────────────────────────────
546
+
547
+ export interface CustomNodeSummary {
548
+ id: string
549
+ name: string
550
+ description?: string
551
+ /** 'http' (one external call) or 'expression' (data transform) or
552
+ * 'composition' (sub-workflow). */
553
+ kind: 'http' | 'expression' | 'composition'
554
+ /** Input schema the node accepts. */
555
+ inputSchema?: Record<string, unknown>
556
+ /** Output schema the node returns. */
557
+ outputSchema?: Record<string, unknown>
558
+ }
559
+
560
+ // ─── Schedules ───────────────────────────────────────────────────────────
561
+
562
+ export interface ScheduleSummary {
563
+ id: string
564
+ workflowId: string
565
+ workflowName?: string
566
+ /** Cron expression in the schedule's timezone. */
567
+ cronExpression: string
568
+ timezone: string
569
+ active: boolean
570
+ nextRun?: string
571
+ lastRun?: string
572
+ createdAt: string
573
+ }
574
+
575
+ export interface CreateScheduleOptions {
576
+ workflowId: string
577
+ cronExpression: string
578
+ /** IANA timezone ('America/New_York'). */
579
+ timezone?: string
580
+ /** Initial state. Default true. */
581
+ active?: boolean
582
+ /** Override the workflow's saved execution options for scheduled
583
+ * runs. */
584
+ execution?: WorkflowExecutionOptions
585
+ /** Input variables passed every scheduled run. */
586
+ input?: Record<string, unknown>
587
+ }
588
+
589
+ // ─── Templates ───────────────────────────────────────────────────────────
590
+
591
+ export interface TemplateSummary {
592
+ id: string
593
+ name: string
594
+ description?: string
595
+ categories?: string[]
596
+ /** Author of the template (the platform team or another user). */
597
+ author?: string
598
+ /** Indicative complexity. */
599
+ nodeCount?: number
600
+ }
601
+
602
+ // ─── Profiles ────────────────────────────────────────────────────────────
603
+
604
+ export interface ProfileSummary {
605
+ id: string
606
+ name: string
607
+ /** 'cloud' = persistent cloud profile; 'local' = Chrome profile
608
+ * on the user's machine (requires the Prompteryx plugin). */
609
+ kind: 'cloud' | 'local'
610
+ /** Cookies / storage size. */
611
+ sizeBytes?: number
612
+ lastUsedAt?: string
613
+ }
614
+
615
+ // ─── Subscription / billing ─────────────────────────────────────────────
616
+
617
+ export interface SubscriptionStatus {
618
+ tier: 'free' | 'starter' | 'developer' | 'pro' | 'enterprise' | (string & {})
619
+ renewedAt?: string
620
+ /** Plan-included balances. */
621
+ balances: {
622
+ aiCredits: { remaining: number; included: number }
623
+ cloudBrowserMinutes: { remaining: number; included: number }
624
+ proxyDataMB: { remaining: number; included: number }
625
+ captchaSolves: { remaining: number; included: number }
626
+ connectHubCalls: { remaining: number; included: number }
627
+ monthlyExecutions: { remaining: number; included: number }
628
+ }
629
+ /** Top-up balances (don't reset monthly). */
630
+ topUpBalances: {
631
+ aiCredits: number
632
+ cloudBrowserMinutes: number
633
+ proxyDataMB: number
634
+ captchaSolves: number
635
+ connectHubCalls: number
636
+ }
637
+ }
638
+
639
+ // ─── Recordings + API Keys ──────────────────────────────────────────────
640
+
641
+ export interface SessionRecording {
642
+ sessionId: string
643
+ startedAt: string
644
+ endedAt?: string
645
+ url: string
646
+ durationMs?: number
647
+ sizeBytes?: number
648
+ }
649
+
650
+ export interface ApiKeySummary {
651
+ id: string
652
+ name: string
653
+ keyPrefix: string
654
+ createdAt: string
655
+ lastUsedAt?: string
656
+ expiresAt?: string
657
+ status: 'active' | 'expired' | 'revoked'
658
+ usageCount: number
659
+ }
660
+
661
+ // ─── Client config ───────────────────────────────────────────────────────
662
+
663
+ export interface PrompteryxClientOptions {
664
+ /** Platform API key (`px_live_…`) — sent as `Authorization: Bearer`.
665
+ * Rate limits: 60 requests/minute, 10,000/day. */
666
+ apiKey: string
667
+ /**
668
+ * Cloud Browser API key (`pcb_live_…`) — a SEPARATE key family, created
669
+ * under Cloud Platform → API Keys. Required for `px.cloudBrowser.*`
670
+ * (sessions / fetch / search), which authenticates with `x-api-key`
671
+ * rather than the platform Bearer key. Calls to `px.cloudBrowser.*`
672
+ * throw an AuthError explaining this when it's absent.
673
+ */
674
+ cloudBrowserKey?: string
675
+ baseUrl?: string
676
+ timeoutMs?: number
677
+ maxRetries?: number
678
+ defaultHeaders?: Record<string, string>
679
+ fetch?: typeof fetch
680
+ }