@sylphx/sdk 0.4.0 → 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.
- package/dist/index.d.cts +583 -144
- package/dist/index.d.ts +583 -144
- package/dist/index.js +697 -267
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +691 -269
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.js +43 -24
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/index.mjs +43 -24
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.d.cts +61 -33
- package/dist/react/index.d.ts +61 -33
- package/dist/react/index.js +907 -749
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +907 -749
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.d.cts +355 -18
- package/dist/server/index.d.ts +355 -18
- package/dist/server/index.js +529 -11
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +525 -11
- package/dist/server/index.mjs.map +1 -1
- package/dist/web-analytics.js.map +1 -1
- package/dist/web-analytics.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/web-analytics.d.cts +0 -90
- package/dist/web-analytics.d.ts +0 -90
package/dist/index.d.cts
CHANGED
|
@@ -1,140 +1,170 @@
|
|
|
1
1
|
import * as openapi_fetch from 'openapi-fetch';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* SDK
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* This is
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
4
|
+
* Sylphx Connection URL Parser — SDK Self-Contained Copy
|
|
5
|
+
*
|
|
6
|
+
* Implements the canonical connection string format defined in ADR-055 §5.
|
|
7
|
+
* This is a self-contained copy for SDK package independence (no app imports).
|
|
8
|
+
*
|
|
9
|
+
* Format:
|
|
10
|
+
* sylphx://{credential}@{slug}.{domain}[:port][/v{version}]
|
|
11
|
+
*
|
|
12
|
+
* Examples:
|
|
13
|
+
* sylphx://pk_prod_f19e5cdc3cc54f7ff81bdc26ec5bfbad@bold-river-a1b2c3.sylphx.com
|
|
14
|
+
* sylphx://sk_prod_5120bfeb5120bfeb5120bfeb5120bfeb@bold-river-a1b2c3.sylphx.com/v1
|
|
15
|
+
* sylphx://pk_dev_abc12345abc12345abc12345abc12345@calm-peak-z9x4d5.sylphx.dev
|
|
16
|
+
*
|
|
17
|
+
* Invariants:
|
|
18
|
+
* - Protocol is always `sylphx:` (no exceptions)
|
|
19
|
+
* - Credential matches `(pk|sk)_(dev|stg|prod|prev)_[a-f0-9]{32,64}`
|
|
20
|
+
* - Host's first DNS label is the resource slug (validated by slug regex)
|
|
21
|
+
* - `apiBaseUrl` is always HTTPS, with `/v{version}` appended (default `v1`)
|
|
22
|
+
*
|
|
23
|
+
* Parsing uses the WHATWG `URL` constructor — custom regex parsing is banned
|
|
24
|
+
* because it is notoriously brittle (ADR-055 §5.3).
|
|
25
|
+
*/
|
|
26
|
+
type ConnectionCredentialType = 'pk' | 'sk';
|
|
27
|
+
type ConnectionEnv = 'dev' | 'stg' | 'prod' | 'prev';
|
|
28
|
+
interface ParsedConnectionUrl {
|
|
29
|
+
/** Full credential string, e.g. `pk_prod_f19e...` */
|
|
30
|
+
readonly credential: string;
|
|
31
|
+
/** Credential kind — `pk` (publishable) or `sk` (secret) */
|
|
32
|
+
readonly credentialType: ConnectionCredentialType;
|
|
33
|
+
/** Target environment encoded in the credential */
|
|
34
|
+
readonly env: ConnectionEnv;
|
|
35
|
+
/** First DNS label of the host — the resource slug (e.g. `bold-river-a1b2c3`) */
|
|
36
|
+
readonly slug: string;
|
|
37
|
+
/** Full host including port when present (e.g. `bold-river-a1b2c3.sylphx.com`) */
|
|
38
|
+
readonly host: string;
|
|
39
|
+
/** Ready-to-use SDK base URL, always HTTPS (e.g. `https://bold-river-a1b2c3.sylphx.com/v1`) */
|
|
40
|
+
readonly apiBaseUrl: string;
|
|
27
41
|
}
|
|
42
|
+
declare class InvalidConnectionUrlError extends Error {
|
|
43
|
+
readonly code: "INVALID_CONNECTION_URL";
|
|
44
|
+
constructor(message: string);
|
|
45
|
+
}
|
|
46
|
+
|
|
28
47
|
/**
|
|
29
|
-
*
|
|
48
|
+
* SDK Configuration — ADR-055 Connection URL API
|
|
30
49
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
50
|
+
* v0.5.0: The primary entry point is `createClient(url)` which accepts
|
|
51
|
+
* a `sylphx://` connection URL. The old `createConfig({ ref, publicKey })`
|
|
52
|
+
* API is removed.
|
|
34
53
|
*
|
|
35
|
-
* @
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { createClient } from '@sylphx/sdk'
|
|
57
|
+
*
|
|
58
|
+
* const sylphx = createClient(process.env.SYLPHX_URL!)
|
|
59
|
+
* // Parses: sylphx://pk_prod_{hex}@bold-river-a1b2c3.sylphx.com
|
|
60
|
+
* ```
|
|
36
61
|
*/
|
|
37
|
-
|
|
62
|
+
|
|
38
63
|
/**
|
|
39
|
-
* SDK Configuration
|
|
40
|
-
*
|
|
41
|
-
* This is the configuration object passed to pure SDK functions like
|
|
42
|
-
* `track()`, `signIn()`, `getPlans()`, etc.
|
|
43
|
-
*
|
|
44
|
-
* ## Config Type Hierarchy
|
|
45
|
-
*
|
|
46
|
-
* - `SylphxConfig` (this) — Pure functions, server or client
|
|
47
|
-
* - `SylphxClientConfig` — React hooks return value (appId, platformUrl only)
|
|
48
|
-
* - `SylphxProviderProps` — React provider component props
|
|
49
|
-
* - `SylphxMiddlewareConfig` — Next.js middleware options
|
|
64
|
+
* SDK Configuration object — immutable, frozen.
|
|
50
65
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* import { createConfig, track } from '@sylphx/sdk'
|
|
54
|
-
*
|
|
55
|
-
* const config = createConfig({ secretKey: process.env.SYLPHX_SECRET_KEY! })
|
|
56
|
-
* await track(config, { event: 'purchase', properties: { amount: 99 } })
|
|
57
|
-
* ```
|
|
66
|
+
* Created by `createClient()` or `createServerClient()`.
|
|
67
|
+
* Passed to all pure SDK functions (`track()`, `signIn()`, etc.).
|
|
58
68
|
*/
|
|
59
69
|
interface SylphxConfig {
|
|
70
|
+
/** The credential string (pk_* or sk_*) */
|
|
71
|
+
readonly credential: string;
|
|
72
|
+
/** Credential type: 'pk' (publishable) or 'sk' (secret) */
|
|
73
|
+
readonly credentialType: 'pk' | 'sk';
|
|
74
|
+
/** Target environment: dev, stg, prod, or prev */
|
|
75
|
+
readonly env: 'dev' | 'stg' | 'prod' | 'prev';
|
|
76
|
+
/** Resource slug (first DNS label), e.g. 'bold-river-a1b2c3' */
|
|
77
|
+
readonly slug: string;
|
|
78
|
+
/** Pre-computed API base URL, e.g. 'https://bold-river-a1b2c3.sylphx.com/v1' */
|
|
79
|
+
readonly baseUrl: string;
|
|
80
|
+
/** Optional access token for authenticated requests */
|
|
81
|
+
readonly accessToken?: string;
|
|
60
82
|
/**
|
|
61
|
-
* Secret key
|
|
62
|
-
*
|
|
63
|
-
* Get from Platform Console → Apps → Your App → Environments.
|
|
83
|
+
* Secret key — populated when credentialType is 'sk'.
|
|
84
|
+
* Backward-compatible alias for `credential` when credential is sk_*.
|
|
64
85
|
*/
|
|
65
86
|
readonly secretKey?: string;
|
|
66
87
|
/**
|
|
67
|
-
* Publishable key
|
|
68
|
-
*
|
|
69
|
-
* Get from Platform Console → Apps → Your App → Environments.
|
|
88
|
+
* Publishable key — populated when credentialType is 'pk'.
|
|
89
|
+
* Backward-compatible alias for `credential` when credential is pk_*.
|
|
70
90
|
*/
|
|
71
91
|
readonly publicKey?: string;
|
|
72
92
|
/**
|
|
73
|
-
*
|
|
74
|
-
* Extracted from the key automatically (ADR-021).
|
|
75
|
-
* The SDK targets: https://{ref}.api.sylphx.com/v1
|
|
93
|
+
* @deprecated Use `slug`. Backward-compatible alias.
|
|
76
94
|
*/
|
|
77
95
|
readonly ref: string;
|
|
78
|
-
/**
|
|
79
|
-
* Pre-computed base URL: https://{ref}.api.sylphx.com/v1
|
|
80
|
-
* Derived from the embedded ref in the key.
|
|
81
|
-
*/
|
|
82
|
-
readonly baseUrl: string;
|
|
83
|
-
/** Optional: Current access token for authenticated requests */
|
|
84
|
-
readonly accessToken?: string;
|
|
85
96
|
}
|
|
86
97
|
/**
|
|
87
|
-
*
|
|
98
|
+
* Explicit components input — alternative to connection URL string.
|
|
88
99
|
*
|
|
89
|
-
*
|
|
90
|
-
* The project ref is extracted automatically from the key.
|
|
100
|
+
* For multi-tenant apps or cases where components are stored separately.
|
|
91
101
|
*/
|
|
92
|
-
interface
|
|
93
|
-
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
* env var: NEXT_PUBLIC_SYLPHX_KEY
|
|
97
|
-
*/
|
|
102
|
+
interface SylphxClientInput {
|
|
103
|
+
/** Resource slug, e.g. 'bold-river-a1b2c3' */
|
|
104
|
+
slug?: string;
|
|
105
|
+
/** Publishable key (pk_*) — client-safe */
|
|
98
106
|
publicKey?: string;
|
|
99
|
-
/**
|
|
100
|
-
* Secret key (sk_*) — server-side only.
|
|
101
|
-
* Format: sk_{env}_{ref}_{64hex}
|
|
102
|
-
* env var: SYLPHX_SECRET_KEY
|
|
103
|
-
*/
|
|
107
|
+
/** Secret key (sk_*) — server-side only */
|
|
104
108
|
secretKey?: string;
|
|
109
|
+
/** Optional access token */
|
|
110
|
+
accessToken?: string;
|
|
111
|
+
/** API domain override (default: sylphx.com) */
|
|
112
|
+
domain?: string;
|
|
105
113
|
/**
|
|
106
|
-
* @deprecated Use
|
|
107
|
-
* Still accepted for backward compatibility; overridden by key-embedded ref.
|
|
114
|
+
* @deprecated Use `slug`. Accepted for backward compatibility during migration.
|
|
108
115
|
*/
|
|
109
116
|
ref?: string;
|
|
110
|
-
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated Use `domain`. Accepted for backward compatibility during migration.
|
|
119
|
+
*/
|
|
120
|
+
platformUrl?: string;
|
|
111
121
|
}
|
|
112
122
|
/**
|
|
113
|
-
* Create a Sylphx
|
|
123
|
+
* Create a Sylphx client from a connection URL or explicit components.
|
|
114
124
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
125
|
+
* This is the primary SDK entry point for client-side (browser) usage.
|
|
126
|
+
* Accepts a `sylphx://` connection URL or an explicit components object.
|
|
117
127
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
128
|
+
* @example Connection URL (recommended)
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const sylphx = createClient(process.env.NEXT_PUBLIC_SYLPHX_URL!)
|
|
131
|
+
* // Parses: sylphx://pk_prod_{hex}@bold-river-a1b2c3.sylphx.com
|
|
132
|
+
* ```
|
|
120
133
|
*
|
|
121
|
-
* @example
|
|
134
|
+
* @example Explicit components
|
|
122
135
|
* ```typescript
|
|
123
|
-
* const
|
|
124
|
-
*
|
|
136
|
+
* const sylphx = createClient({
|
|
137
|
+
* slug: 'bold-river-a1b2c3',
|
|
138
|
+
* publicKey: 'pk_prod_f19e...',
|
|
125
139
|
* })
|
|
126
140
|
* ```
|
|
141
|
+
*/
|
|
142
|
+
declare function createClient(input: string | SylphxClientInput): SylphxConfig;
|
|
143
|
+
/**
|
|
144
|
+
* Create a Sylphx server client from a connection URL or explicit components.
|
|
127
145
|
*
|
|
128
|
-
*
|
|
146
|
+
* Equivalent to `createClient()` but validates that a secret key (sk_*) is provided.
|
|
147
|
+
* Use this for server-side operations that require elevated permissions.
|
|
148
|
+
*
|
|
149
|
+
* @example Connection URL (recommended)
|
|
129
150
|
* ```typescript
|
|
130
|
-
* const
|
|
131
|
-
*
|
|
151
|
+
* const sylphx = createServerClient(process.env.SYLPHX_SECRET_URL!)
|
|
152
|
+
* // Parses: sylphx://sk_prod_{hex}@bold-river-a1b2c3.sylphx.com
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @example Explicit components
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const sylphx = createServerClient({
|
|
158
|
+
* slug: 'bold-river-a1b2c3',
|
|
159
|
+
* secretKey: 'sk_prod_5120...',
|
|
132
160
|
* })
|
|
133
161
|
* ```
|
|
134
162
|
*/
|
|
135
|
-
declare function
|
|
163
|
+
declare function createServerClient(input: string | SylphxClientInput): SylphxConfig;
|
|
136
164
|
/**
|
|
137
|
-
* Create a new config with an updated access token
|
|
165
|
+
* Create a new config with an updated access token.
|
|
166
|
+
*
|
|
167
|
+
* Returns a new frozen config — does not mutate the original.
|
|
138
168
|
*
|
|
139
169
|
* @example
|
|
140
170
|
* ```typescript
|
|
@@ -142,6 +172,15 @@ declare function createConfig(input: SylphxConfigInput): SylphxConfig;
|
|
|
142
172
|
* ```
|
|
143
173
|
*/
|
|
144
174
|
declare function withToken(config: SylphxConfig, accessToken: string): SylphxConfig;
|
|
175
|
+
/**
|
|
176
|
+
* @deprecated Use `createClient()` or `createServerClient()` instead.
|
|
177
|
+
* This function is kept temporarily for migration but will be removed.
|
|
178
|
+
*/
|
|
179
|
+
type SylphxConfigInput = string | SylphxClientInput;
|
|
180
|
+
/**
|
|
181
|
+
* @deprecated Use `createClient()` instead. See ADR-055.
|
|
182
|
+
*/
|
|
183
|
+
declare const createConfig: typeof createClient;
|
|
145
184
|
|
|
146
185
|
/**
|
|
147
186
|
* SDK Debug Mode
|
|
@@ -21362,17 +21401,17 @@ interface RegisterInput {
|
|
|
21362
21401
|
invitationToken?: string;
|
|
21363
21402
|
}
|
|
21364
21403
|
/**
|
|
21365
|
-
* Org context claims present in org-scoped tokens.
|
|
21404
|
+
* Org context claims present in org-scoped tokens (after switch-org).
|
|
21366
21405
|
*
|
|
21367
|
-
*
|
|
21368
|
-
*
|
|
21406
|
+
* The JWT carries the role key only. Permissions are resolved server-side
|
|
21407
|
+
* via Redis-cached role→permissions lookup (WorkOS pattern). This keeps
|
|
21408
|
+
* tokens small and ensures permission changes take effect without token refresh.
|
|
21369
21409
|
*/
|
|
21370
21410
|
interface OrgTokenPayload {
|
|
21371
21411
|
org_id: string;
|
|
21372
21412
|
org_slug: string;
|
|
21413
|
+
/** RBAC role key (e.g. "hr_manager", "admin"). Permissions resolved server-side. */
|
|
21373
21414
|
org_role: string;
|
|
21374
|
-
/** RBAC: resolved permission keys (e.g. ["org:members:read", "payroll:approve"]) */
|
|
21375
|
-
org_permissions?: string[];
|
|
21376
21415
|
}
|
|
21377
21416
|
/**
|
|
21378
21417
|
* Invite a user request payload.
|
|
@@ -22324,6 +22363,32 @@ type NativeStepContext = {
|
|
|
22324
22363
|
* @param duration Human-readable duration: '5s', '30m', '2h', '1d'.
|
|
22325
22364
|
*/
|
|
22326
22365
|
sleep(name: string, duration: string): Promise<void>;
|
|
22366
|
+
/**
|
|
22367
|
+
* Pause execution until a named event is published via TriggersClient.publishEvent().
|
|
22368
|
+
*
|
|
22369
|
+
* On first encounter: signals the platform to wait for the event; stops execution.
|
|
22370
|
+
* After the event arrives: returns the event payload.
|
|
22371
|
+
* If timeout expires before event arrives: returns null.
|
|
22372
|
+
*
|
|
22373
|
+
* @param name Step identifier (must be unique within the handler).
|
|
22374
|
+
* @param eventName The event name to listen for (e.g. 'user.approved').
|
|
22375
|
+
* @param options Optional timeout ('24h', '7d') and payload filter.
|
|
22376
|
+
*
|
|
22377
|
+
* @example Human-in-the-loop approval
|
|
22378
|
+
* ```typescript
|
|
22379
|
+
* const approval = await step.waitForEvent<{ approvedBy: string }>(
|
|
22380
|
+
* 'wait-approval',
|
|
22381
|
+
* 'order.approved',
|
|
22382
|
+
* { timeout: '48h', filter: { orderId: payload.orderId } },
|
|
22383
|
+
* )
|
|
22384
|
+
* if (!approval) throw new Error('Approval timed out')
|
|
22385
|
+
* await notifyCustomer(approval.approvedBy)
|
|
22386
|
+
* ```
|
|
22387
|
+
*/
|
|
22388
|
+
waitForEvent<T = unknown>(name: string, eventName: string, options?: {
|
|
22389
|
+
timeout?: string;
|
|
22390
|
+
filter?: Record<string, unknown>;
|
|
22391
|
+
}): Promise<T | null>;
|
|
22327
22392
|
};
|
|
22328
22393
|
/**
|
|
22329
22394
|
* A named task definition registered with sylphx.tasks.define().
|
|
@@ -22416,9 +22481,9 @@ declare class StepSleepSignal {
|
|
|
22416
22481
|
* Build the step proxy for a single handler invocation.
|
|
22417
22482
|
*
|
|
22418
22483
|
* @param completedSteps Map of stepName → cached result
|
|
22419
|
-
* @param resolvedWaits
|
|
22484
|
+
* @param resolvedWaits Map of stepName → wait result (sleep = undefined, event = event payload)
|
|
22420
22485
|
*/
|
|
22421
|
-
declare function createStepContext(completedSteps: Map<string, unknown>, resolvedWaits:
|
|
22486
|
+
declare function createStepContext(completedSteps: Map<string, unknown>, resolvedWaits: Map<string, unknown>): NativeStepContext;
|
|
22422
22487
|
/**
|
|
22423
22488
|
* Constant-time HMAC-SHA256 signature verification.
|
|
22424
22489
|
* Accepts both raw hex and 'sha256={hex}' formats.
|
|
@@ -25689,6 +25754,21 @@ interface SandboxOptions {
|
|
|
25689
25754
|
};
|
|
25690
25755
|
/** Environment variables injected into the sandbox container */
|
|
25691
25756
|
env?: Record<string, string>;
|
|
25757
|
+
/**
|
|
25758
|
+
* Shared volume mounts from org-level managed volumes.
|
|
25759
|
+
* Requires ReadWriteMany volumes (CephFS). Multiple sandboxes can mount
|
|
25760
|
+
* the same volume for shared filesystem access.
|
|
25761
|
+
*/
|
|
25762
|
+
volumeMounts?: Array<{
|
|
25763
|
+
/** Volume resource ID (from `sylphx volumes list`) */
|
|
25764
|
+
volumeId: string;
|
|
25765
|
+
/** Absolute path inside the container (e.g. "/shared") */
|
|
25766
|
+
mountPath: string;
|
|
25767
|
+
/** Optional sub-path within the volume */
|
|
25768
|
+
subPath?: string;
|
|
25769
|
+
/** Read-only mount (default: false) */
|
|
25770
|
+
readOnly?: boolean;
|
|
25771
|
+
}>;
|
|
25692
25772
|
}
|
|
25693
25773
|
/** SSE event emitted by sandbox.exec() */
|
|
25694
25774
|
type ExecEvent = {
|
|
@@ -25727,6 +25807,75 @@ interface ExecOptions {
|
|
|
25727
25807
|
timeout?: number;
|
|
25728
25808
|
stdin?: string;
|
|
25729
25809
|
}
|
|
25810
|
+
interface ProcessStartOptions {
|
|
25811
|
+
/** Command + args (e.g. ['npm', 'install']) */
|
|
25812
|
+
command: string[];
|
|
25813
|
+
/** Working directory */
|
|
25814
|
+
cwd?: string;
|
|
25815
|
+
/** Environment variables */
|
|
25816
|
+
env?: Record<string, string>;
|
|
25817
|
+
/** Hard timeout in seconds (0 = no timeout) */
|
|
25818
|
+
timeoutSeconds?: number;
|
|
25819
|
+
/** Open stdin pipe for writing */
|
|
25820
|
+
stdin?: boolean;
|
|
25821
|
+
}
|
|
25822
|
+
interface ProcessInfo {
|
|
25823
|
+
id: string;
|
|
25824
|
+
pid: number;
|
|
25825
|
+
command: string[];
|
|
25826
|
+
cwd: string;
|
|
25827
|
+
status: 'running' | 'exited' | 'killed' | 'timeout';
|
|
25828
|
+
exitCode: number | null;
|
|
25829
|
+
signal: string | null;
|
|
25830
|
+
startedAt: string;
|
|
25831
|
+
exitedAt: string | null;
|
|
25832
|
+
durationMs: number | null;
|
|
25833
|
+
stdout: string;
|
|
25834
|
+
stderr: string;
|
|
25835
|
+
}
|
|
25836
|
+
interface ProcessSummary {
|
|
25837
|
+
id: string;
|
|
25838
|
+
pid: number;
|
|
25839
|
+
command: string[];
|
|
25840
|
+
status: 'running' | 'exited' | 'killed' | 'timeout';
|
|
25841
|
+
exitCode: number | null;
|
|
25842
|
+
startedAt: string;
|
|
25843
|
+
exitedAt: string | null;
|
|
25844
|
+
durationMs: number | null;
|
|
25845
|
+
}
|
|
25846
|
+
/** SSE event from a process stream */
|
|
25847
|
+
type ProcessEvent = {
|
|
25848
|
+
type: 'stdout';
|
|
25849
|
+
pid: number;
|
|
25850
|
+
data: string;
|
|
25851
|
+
} | {
|
|
25852
|
+
type: 'stderr';
|
|
25853
|
+
pid: number;
|
|
25854
|
+
data: string;
|
|
25855
|
+
} | {
|
|
25856
|
+
type: 'exit';
|
|
25857
|
+
pid: number;
|
|
25858
|
+
exitCode: number;
|
|
25859
|
+
};
|
|
25860
|
+
interface WatchOptions {
|
|
25861
|
+
/** Path to watch (relative to /workspace or absolute) */
|
|
25862
|
+
path: string;
|
|
25863
|
+
/** Watch subdirectories recursively (default: true) */
|
|
25864
|
+
recursive?: boolean;
|
|
25865
|
+
/** Additional patterns to ignore */
|
|
25866
|
+
ignore?: string[];
|
|
25867
|
+
}
|
|
25868
|
+
interface WatchEntry {
|
|
25869
|
+
path: string;
|
|
25870
|
+
recursive: boolean;
|
|
25871
|
+
createdAt: string;
|
|
25872
|
+
}
|
|
25873
|
+
/** File change event delivered via SSE /events stream */
|
|
25874
|
+
interface FileEvent {
|
|
25875
|
+
type: 'file';
|
|
25876
|
+
path: string;
|
|
25877
|
+
event: 'created' | 'modified' | 'deleted';
|
|
25878
|
+
}
|
|
25730
25879
|
interface SandboxRecord {
|
|
25731
25880
|
id: string;
|
|
25732
25881
|
status: 'starting' | 'running' | 'idle' | 'terminated' | 'error';
|
|
@@ -25756,6 +25905,46 @@ declare class SandboxFiles {
|
|
|
25756
25905
|
/** List files in a directory. */
|
|
25757
25906
|
list(path?: string): Promise<string[]>;
|
|
25758
25907
|
}
|
|
25908
|
+
declare class SandboxProcesses {
|
|
25909
|
+
private readonly endpoint;
|
|
25910
|
+
private readonly token;
|
|
25911
|
+
constructor(endpoint: string, token: string);
|
|
25912
|
+
private authHeader;
|
|
25913
|
+
/** Spawn a new tracked process. Returns processId + pid immediately. */
|
|
25914
|
+
start(opts: ProcessStartOptions): Promise<{
|
|
25915
|
+
id: string;
|
|
25916
|
+
pid: number;
|
|
25917
|
+
}>;
|
|
25918
|
+
/** List all tracked processes. */
|
|
25919
|
+
list(): Promise<ProcessSummary[]>;
|
|
25920
|
+
/** Get full process info including buffered output. */
|
|
25921
|
+
get(processId: string): Promise<ProcessInfo>;
|
|
25922
|
+
/** Send a signal to a process. */
|
|
25923
|
+
kill(processId: string, signal?: string): Promise<void>;
|
|
25924
|
+
/** Write to process stdin. */
|
|
25925
|
+
writeStdin(processId: string, data: string): Promise<void>;
|
|
25926
|
+
/**
|
|
25927
|
+
* Wait for a process to complete and return its final info.
|
|
25928
|
+
* Polls every 500ms until status is no longer 'running'.
|
|
25929
|
+
*
|
|
25930
|
+
* For real-time output, use stream() instead.
|
|
25931
|
+
*/
|
|
25932
|
+
wait(processId: string, timeoutMs?: number): Promise<ProcessInfo>;
|
|
25933
|
+
/** Stream process output as async iterable SSE events. */
|
|
25934
|
+
stream(processId: string): AsyncGenerator<ProcessEvent>;
|
|
25935
|
+
}
|
|
25936
|
+
declare class SandboxWatch {
|
|
25937
|
+
private readonly endpoint;
|
|
25938
|
+
private readonly token;
|
|
25939
|
+
constructor(endpoint: string, token: string);
|
|
25940
|
+
private authHeader;
|
|
25941
|
+
/** Start watching a path. Events delivered via sandbox.events() SSE stream. */
|
|
25942
|
+
add(opts: WatchOptions): Promise<WatchEntry>;
|
|
25943
|
+
/** List active watches. */
|
|
25944
|
+
list(): Promise<WatchEntry[]>;
|
|
25945
|
+
/** Stop watching a path. */
|
|
25946
|
+
remove(path: string): Promise<void>;
|
|
25947
|
+
}
|
|
25759
25948
|
declare class SandboxClient {
|
|
25760
25949
|
readonly id: string;
|
|
25761
25950
|
private readonly config;
|
|
@@ -25765,6 +25954,10 @@ declare class SandboxClient {
|
|
|
25765
25954
|
readonly token: string | null;
|
|
25766
25955
|
/** File operations (direct to exec-server) */
|
|
25767
25956
|
readonly files: SandboxFiles | null;
|
|
25957
|
+
/** Concurrent process management (direct to exec-server) */
|
|
25958
|
+
readonly processes: SandboxProcesses | null;
|
|
25959
|
+
/** Filesystem watch management (direct to exec-server) */
|
|
25960
|
+
readonly watch: SandboxWatch | null;
|
|
25768
25961
|
private constructor();
|
|
25769
25962
|
/**
|
|
25770
25963
|
* Create a new sandbox.
|
|
@@ -25782,10 +25975,21 @@ declare class SandboxClient {
|
|
|
25782
25975
|
getStatus(): Promise<SandboxRecord>;
|
|
25783
25976
|
terminate(): Promise<void>;
|
|
25784
25977
|
/**
|
|
25785
|
-
* Execute a command and stream output as async iterable events.
|
|
25978
|
+
* Execute a command and stream output as async iterable SSE events.
|
|
25786
25979
|
*
|
|
25787
|
-
*
|
|
25788
|
-
*
|
|
25980
|
+
* **Stateless mode**: each exec() call runs in an isolated bash invocation.
|
|
25981
|
+
* Shell state (CWD changes, exported env vars, functions) is NOT preserved
|
|
25982
|
+
* between calls.
|
|
25983
|
+
*
|
|
25984
|
+
* For state-preserving execution (CWD, env), use `run()` which runs in the
|
|
25985
|
+
* persistent active shell and returns the result once complete.
|
|
25986
|
+
*
|
|
25987
|
+
* For streaming + state-preserving (advanced), combine `sandbox.events()` with `run()`:
|
|
25988
|
+
* ```typescript
|
|
25989
|
+
* const eventStream = sandbox.events({ type: 'stdout' })
|
|
25990
|
+
* sandbox.run(['npm', 'install']) // don't await yet
|
|
25991
|
+
* for await (const ev of eventStream) { ... }
|
|
25992
|
+
* ```
|
|
25789
25993
|
*
|
|
25790
25994
|
* @example
|
|
25791
25995
|
* ```typescript
|
|
@@ -25803,6 +26007,24 @@ declare class SandboxClient {
|
|
|
25803
26007
|
* For long-running commands, prefer exec() to stream output incrementally.
|
|
25804
26008
|
*/
|
|
25805
26009
|
run(command: string[], options?: ExecOptions): Promise<ExecResult>;
|
|
26010
|
+
/**
|
|
26011
|
+
* Subscribe to the unified event stream (SSE).
|
|
26012
|
+
*
|
|
26013
|
+
* Receives all sandbox events: stdout, stderr, exit, port, file, shell, resource.
|
|
26014
|
+
* Filter by type/pid/shellId using query params.
|
|
26015
|
+
*
|
|
26016
|
+
* @example
|
|
26017
|
+
* ```typescript
|
|
26018
|
+
* for await (const event of sandbox.events({ type: 'file' })) {
|
|
26019
|
+
* console.log('File changed:', event.path, event.event)
|
|
26020
|
+
* }
|
|
26021
|
+
* ```
|
|
26022
|
+
*/
|
|
26023
|
+
events(filter?: {
|
|
26024
|
+
type?: 'stdout' | 'stderr' | 'exit' | 'port' | 'file' | 'shell' | 'resource';
|
|
26025
|
+
pid?: number;
|
|
26026
|
+
shellId?: string;
|
|
26027
|
+
}): AsyncGenerator<Record<string, unknown>>;
|
|
25806
26028
|
/**
|
|
25807
26029
|
* Open an interactive PTY session (WebSocket).
|
|
25808
26030
|
*
|
|
@@ -25822,11 +26044,11 @@ declare class SandboxClient {
|
|
|
25822
26044
|
}
|
|
25823
26045
|
|
|
25824
26046
|
/**
|
|
25825
|
-
*
|
|
26047
|
+
* Runs Client (ADR-040, formerly Workers)
|
|
25826
26048
|
*
|
|
25827
26049
|
* Fire-and-forget batch compute API (Modal-style run-to-completion jobs).
|
|
25828
26050
|
*
|
|
25829
|
-
*
|
|
26051
|
+
* Runs are ephemeral K8s Jobs that run to completion. Use them for:
|
|
25830
26052
|
* - ML training folds (walk-forward cross-validation)
|
|
25831
26053
|
* - Data processing pipelines
|
|
25832
26054
|
* - Batch inference
|
|
@@ -25836,11 +26058,11 @@ declare class SandboxClient {
|
|
|
25836
26058
|
*
|
|
25837
26059
|
* ### Single worker
|
|
25838
26060
|
* ```typescript
|
|
25839
|
-
* import { createConfig,
|
|
26061
|
+
* import { createConfig, RunsClient } from '@sylphx/sdk'
|
|
25840
26062
|
*
|
|
25841
26063
|
* const config = createConfig({ secretKey: process.env.SYLPHX_SECRET_KEY!, ref: 'my-project' })
|
|
25842
26064
|
*
|
|
25843
|
-
* const
|
|
26065
|
+
* const run = await RunsClient.create(config, {
|
|
25844
26066
|
* image: 'registry.sylphx.com/sylphx/my-trainer:abc123',
|
|
25845
26067
|
* command: ['python', 'train.py', '--fold', '0'],
|
|
25846
26068
|
* resources: { requests: { cpu: '4', memory: '8Gi' } },
|
|
@@ -25856,7 +26078,7 @@ declare class SandboxClient {
|
|
|
25856
26078
|
* ```typescript
|
|
25857
26079
|
* const workers = await Promise.all(
|
|
25858
26080
|
* folds.map((fold) =>
|
|
25859
|
-
*
|
|
26081
|
+
* RunsClient.create(config, {
|
|
25860
26082
|
* image: 'registry.sylphx.com/sylphx/trainer:abc123',
|
|
25861
26083
|
* command: ['python', 'train.py', '--fold', String(fold.id)],
|
|
25862
26084
|
* env: { FOLD_ID: String(fold.id), DATABASE_URL: process.env.DATABASE_URL! },
|
|
@@ -25884,8 +26106,8 @@ declare class SandboxClient {
|
|
|
25884
26106
|
* @module
|
|
25885
26107
|
*/
|
|
25886
26108
|
|
|
25887
|
-
type
|
|
25888
|
-
interface
|
|
26109
|
+
type RunStatus = 'pending' | 'running' | 'succeeded' | 'failed' | 'cancelled' | 'timeout';
|
|
26110
|
+
interface RunVolumeMount {
|
|
25889
26111
|
/** UUID of the volumeResource to mount (must belong to this org) */
|
|
25890
26112
|
volumeId: string;
|
|
25891
26113
|
/** Absolute mount path inside the container (e.g. '/cache') */
|
|
@@ -25895,7 +26117,7 @@ interface WorkerVolumeMount {
|
|
|
25895
26117
|
/** Mount as read-only (default: false) */
|
|
25896
26118
|
readOnly?: boolean;
|
|
25897
26119
|
}
|
|
25898
|
-
interface
|
|
26120
|
+
interface RunResourceSpec {
|
|
25899
26121
|
requests?: {
|
|
25900
26122
|
/** CPU request (e.g. '500m', '2', '4') */
|
|
25901
26123
|
cpu?: string;
|
|
@@ -25909,7 +26131,7 @@ interface WorkerResourceSpec {
|
|
|
25909
26131
|
memory?: string;
|
|
25910
26132
|
};
|
|
25911
26133
|
}
|
|
25912
|
-
interface
|
|
26134
|
+
interface CreateRunOptions {
|
|
25913
26135
|
/**
|
|
25914
26136
|
* Docker image to run (must be from registry.sylphx.com).
|
|
25915
26137
|
*
|
|
@@ -25932,7 +26154,7 @@ interface RunWorkerOptions {
|
|
|
25932
26154
|
* CPU/memory resource spec.
|
|
25933
26155
|
* Defaults: { requests: { cpu: '500m', memory: '512Mi' }, limits: { cpu: '2', memory: '2Gi' } }
|
|
25934
26156
|
*/
|
|
25935
|
-
resources?:
|
|
26157
|
+
resources?: RunResourceSpec;
|
|
25936
26158
|
/**
|
|
25937
26159
|
* Hard timeout in seconds (default: 3600 = 1 hour, max: 86400 = 24 hours).
|
|
25938
26160
|
* K8s terminates the Job when the deadline is reached (status: 'timeout').
|
|
@@ -25942,13 +26164,13 @@ interface RunWorkerOptions {
|
|
|
25942
26164
|
* Volume mounts from org-level volumeResources.
|
|
25943
26165
|
* ReadWriteMany volumes (rook-cephfs) allow concurrent access by multiple parallel workers.
|
|
25944
26166
|
*/
|
|
25945
|
-
volumeMounts?:
|
|
26167
|
+
volumeMounts?: RunVolumeMount[];
|
|
25946
26168
|
}
|
|
25947
|
-
interface
|
|
26169
|
+
interface Run {
|
|
25948
26170
|
/** Worker run ID (e.g. 'worker_Vh3kJ9mNpQ2wXsL1') */
|
|
25949
26171
|
id: string;
|
|
25950
26172
|
/** Current lifecycle status */
|
|
25951
|
-
status:
|
|
26173
|
+
status: RunStatus;
|
|
25952
26174
|
/** Docker image */
|
|
25953
26175
|
image: string;
|
|
25954
26176
|
/** Command being executed */
|
|
@@ -25956,11 +26178,11 @@ interface WorkerRun {
|
|
|
25956
26178
|
/** Environment variables */
|
|
25957
26179
|
env: Record<string, string> | null;
|
|
25958
26180
|
/** Resource spec */
|
|
25959
|
-
resources:
|
|
26181
|
+
resources: RunResourceSpec | null;
|
|
25960
26182
|
/** Hard timeout in seconds */
|
|
25961
26183
|
timeoutSeconds: number;
|
|
25962
26184
|
/** Volume mounts */
|
|
25963
|
-
volumeMounts:
|
|
26185
|
+
volumeMounts: RunVolumeMount[] | null;
|
|
25964
26186
|
/** Exit code (only when succeeded or failed) */
|
|
25965
26187
|
exitCode: number | null;
|
|
25966
26188
|
/** Captured stdout (up to 1 MiB) */
|
|
@@ -25980,11 +26202,11 @@ interface WorkerRun {
|
|
|
25980
26202
|
/** Last update timestamp */
|
|
25981
26203
|
updatedAt: string;
|
|
25982
26204
|
}
|
|
25983
|
-
interface
|
|
26205
|
+
interface RunResult {
|
|
25984
26206
|
/** Exit code (0 = success) */
|
|
25985
26207
|
exitCode: number | null;
|
|
25986
26208
|
/** Status at completion */
|
|
25987
|
-
status:
|
|
26209
|
+
status: RunStatus;
|
|
25988
26210
|
/** Captured stdout */
|
|
25989
26211
|
stdout: string | null;
|
|
25990
26212
|
/** Captured stderr */
|
|
@@ -25994,7 +26216,7 @@ interface WorkerResult {
|
|
|
25994
26216
|
/** Wall-clock duration in milliseconds */
|
|
25995
26217
|
durationMs: number | null;
|
|
25996
26218
|
}
|
|
25997
|
-
interface
|
|
26219
|
+
interface RunLogsResult {
|
|
25998
26220
|
/** Captured stdout (up to 1 MiB) */
|
|
25999
26221
|
stdout: string;
|
|
26000
26222
|
/** Captured stderr (up to 1 MiB) */
|
|
@@ -26002,14 +26224,14 @@ interface WorkerLogsResult {
|
|
|
26002
26224
|
/** Whether logs are still being captured (worker is running) */
|
|
26003
26225
|
live: boolean;
|
|
26004
26226
|
}
|
|
26005
|
-
interface
|
|
26227
|
+
interface ListRunsOptions {
|
|
26006
26228
|
/** Filter by status */
|
|
26007
|
-
status?:
|
|
26229
|
+
status?: RunStatus;
|
|
26008
26230
|
}
|
|
26009
26231
|
/** OpenAI/Stripe-style list response */
|
|
26010
|
-
interface
|
|
26232
|
+
interface ListRunsResult {
|
|
26011
26233
|
object: 'list';
|
|
26012
|
-
data:
|
|
26234
|
+
data: Run[];
|
|
26013
26235
|
/** True if there are more results (limit was hit) */
|
|
26014
26236
|
has_more: boolean;
|
|
26015
26237
|
}
|
|
@@ -26017,20 +26239,20 @@ interface ListWorkersResult {
|
|
|
26017
26239
|
* Handle to a running (or completed) worker.
|
|
26018
26240
|
* Use `.wait()` to poll until completion, `.logs()` to stream logs, `.cancel()` to abort.
|
|
26019
26241
|
*/
|
|
26020
|
-
declare class
|
|
26242
|
+
declare class RunHandle {
|
|
26021
26243
|
readonly id: string;
|
|
26022
26244
|
private readonly config;
|
|
26023
26245
|
constructor(id: string, config: SylphxConfig);
|
|
26024
26246
|
/**
|
|
26025
26247
|
* Get the current status of this worker.
|
|
26026
26248
|
*/
|
|
26027
|
-
status(): Promise<
|
|
26249
|
+
status(): Promise<Run>;
|
|
26028
26250
|
/**
|
|
26029
26251
|
* Poll the worker until it reaches a terminal state (succeeded, failed, cancelled, timeout).
|
|
26030
26252
|
*
|
|
26031
26253
|
* @param options.pollIntervalMs - How often to poll in ms (default: 3000)
|
|
26032
26254
|
* @param options.timeoutMs - Max time to wait before throwing (default: 7_200_000 = 2h)
|
|
26033
|
-
* @returns
|
|
26255
|
+
* @returns RunResult with exit code, status, stdout/stderr
|
|
26034
26256
|
* @throws Error if waitTimeout is exceeded
|
|
26035
26257
|
*
|
|
26036
26258
|
* @example
|
|
@@ -26044,7 +26266,7 @@ declare class WorkerHandle {
|
|
|
26044
26266
|
wait(options?: {
|
|
26045
26267
|
pollIntervalMs?: number;
|
|
26046
26268
|
timeoutMs?: number;
|
|
26047
|
-
}): Promise<
|
|
26269
|
+
}): Promise<RunResult>;
|
|
26048
26270
|
/**
|
|
26049
26271
|
* Fetch captured logs for this worker.
|
|
26050
26272
|
*
|
|
@@ -26058,7 +26280,7 @@ declare class WorkerHandle {
|
|
|
26058
26280
|
* if (live) console.log('(worker still running, logs may be incomplete)')
|
|
26059
26281
|
* ```
|
|
26060
26282
|
*/
|
|
26061
|
-
logs(): Promise<
|
|
26283
|
+
logs(): Promise<RunLogsResult>;
|
|
26062
26284
|
/**
|
|
26063
26285
|
* Cancel this worker.
|
|
26064
26286
|
*
|
|
@@ -26076,13 +26298,75 @@ declare class WorkerHandle {
|
|
|
26076
26298
|
* const config = createConfig({ secretKey: process.env.SYLPHX_SECRET_KEY!, ref: 'my-project' })
|
|
26077
26299
|
*
|
|
26078
26300
|
* // Run a worker and wait for completion
|
|
26079
|
-
* const result = await
|
|
26301
|
+
* const result = await RunsClient.create(config, { ... }).then(w => w.wait())
|
|
26080
26302
|
*
|
|
26081
26303
|
* // Run N workers in parallel, wait for all
|
|
26082
|
-
* const handles = await Promise.all(folds.map(fold =>
|
|
26304
|
+
* const handles = await Promise.all(folds.map(fold => RunsClient.create(config, { ... })))
|
|
26083
26305
|
* const results = await Promise.all(handles.map(h => h.wait()))
|
|
26084
26306
|
* ```
|
|
26085
26307
|
*/
|
|
26308
|
+
declare const RunsClient: {
|
|
26309
|
+
/**
|
|
26310
|
+
* Spawn a new worker (K8s Job) and return a handle.
|
|
26311
|
+
*
|
|
26312
|
+
* The Job is created immediately and starts pulling the image.
|
|
26313
|
+
* Use the returned handle to `.wait()` for completion or `.cancel()`.
|
|
26314
|
+
*
|
|
26315
|
+
* @example
|
|
26316
|
+
* ```typescript
|
|
26317
|
+
* const run = await RunsClient.create(config, {
|
|
26318
|
+
* image: 'registry.sylphx.com/sylphx/trainer:abc123',
|
|
26319
|
+
* command: ['python', 'train.py', '--fold', '3'],
|
|
26320
|
+
* resources: { requests: { cpu: '4', memory: '16Gi' } },
|
|
26321
|
+
* volumeMounts: [{ volumeId: cacheVolumeId, mountPath: '/cache' }],
|
|
26322
|
+
* })
|
|
26323
|
+
* const result = await worker.wait()
|
|
26324
|
+
* ```
|
|
26325
|
+
*/
|
|
26326
|
+
run(config: SylphxConfig, options: CreateRunOptions): Promise<RunHandle>;
|
|
26327
|
+
/**
|
|
26328
|
+
* Get a RunHandle for an existing run by ID.
|
|
26329
|
+
*
|
|
26330
|
+
* Useful for resuming monitoring across requests.
|
|
26331
|
+
*
|
|
26332
|
+
* @example
|
|
26333
|
+
* ```typescript
|
|
26334
|
+
* // Store the worker ID, retrieve later
|
|
26335
|
+
* const handle = RunsClient.fromId(config, storedWorkerId)
|
|
26336
|
+
* const result = await handle.wait()
|
|
26337
|
+
* ```
|
|
26338
|
+
*/
|
|
26339
|
+
fromId(config: SylphxConfig, workerId: string): RunHandle;
|
|
26340
|
+
/**
|
|
26341
|
+
* List worker runs for this environment.
|
|
26342
|
+
*
|
|
26343
|
+
* @example
|
|
26344
|
+
* ```typescript
|
|
26345
|
+
* const { workers } = await RunsClient.list(config, { status: 'running' })
|
|
26346
|
+
* console.log(`${workers.length} workers currently running`)
|
|
26347
|
+
* ```
|
|
26348
|
+
*/
|
|
26349
|
+
list(config: SylphxConfig, options?: ListRunsOptions): Promise<ListRunsResult>;
|
|
26350
|
+
/**
|
|
26351
|
+
* Spawn a worker and wait for it to complete in one call.
|
|
26352
|
+
*
|
|
26353
|
+
* Equivalent to `(await RunsClient.create(config, options)).wait(waitOptions)`.
|
|
26354
|
+
*
|
|
26355
|
+
* @example
|
|
26356
|
+
* ```typescript
|
|
26357
|
+
* const result = await RunsClient.runAndWait(config, {
|
|
26358
|
+
* image: 'registry.sylphx.com/sylphx/process:abc',
|
|
26359
|
+
* command: ['node', 'dist/process.js'],
|
|
26360
|
+
* })
|
|
26361
|
+
* if (result.exitCode !== 0) throw new Error(result.errorMessage ?? 'worker failed')
|
|
26362
|
+
* ```
|
|
26363
|
+
*/
|
|
26364
|
+
runAndWait(config: SylphxConfig, options: CreateRunOptions, waitOptions?: {
|
|
26365
|
+
pollIntervalMs?: number;
|
|
26366
|
+
timeoutMs?: number;
|
|
26367
|
+
}): Promise<RunResult>;
|
|
26368
|
+
};
|
|
26369
|
+
/** @deprecated Use RunsClient */
|
|
26086
26370
|
declare const WorkersClient: {
|
|
26087
26371
|
/**
|
|
26088
26372
|
* Spawn a new worker (K8s Job) and return a handle.
|
|
@@ -26092,7 +26376,7 @@ declare const WorkersClient: {
|
|
|
26092
26376
|
*
|
|
26093
26377
|
* @example
|
|
26094
26378
|
* ```typescript
|
|
26095
|
-
* const
|
|
26379
|
+
* const run = await RunsClient.create(config, {
|
|
26096
26380
|
* image: 'registry.sylphx.com/sylphx/trainer:abc123',
|
|
26097
26381
|
* command: ['python', 'train.py', '--fold', '3'],
|
|
26098
26382
|
* resources: { requests: { cpu: '4', memory: '16Gi' } },
|
|
@@ -26101,48 +26385,203 @@ declare const WorkersClient: {
|
|
|
26101
26385
|
* const result = await worker.wait()
|
|
26102
26386
|
* ```
|
|
26103
26387
|
*/
|
|
26104
|
-
run(config: SylphxConfig, options:
|
|
26388
|
+
run(config: SylphxConfig, options: CreateRunOptions): Promise<RunHandle>;
|
|
26105
26389
|
/**
|
|
26106
|
-
* Get a
|
|
26390
|
+
* Get a RunHandle for an existing run by ID.
|
|
26107
26391
|
*
|
|
26108
26392
|
* Useful for resuming monitoring across requests.
|
|
26109
26393
|
*
|
|
26110
26394
|
* @example
|
|
26111
26395
|
* ```typescript
|
|
26112
26396
|
* // Store the worker ID, retrieve later
|
|
26113
|
-
* const handle =
|
|
26397
|
+
* const handle = RunsClient.fromId(config, storedWorkerId)
|
|
26114
26398
|
* const result = await handle.wait()
|
|
26115
26399
|
* ```
|
|
26116
26400
|
*/
|
|
26117
|
-
fromId(config: SylphxConfig, workerId: string):
|
|
26401
|
+
fromId(config: SylphxConfig, workerId: string): RunHandle;
|
|
26118
26402
|
/**
|
|
26119
26403
|
* List worker runs for this environment.
|
|
26120
26404
|
*
|
|
26121
26405
|
* @example
|
|
26122
26406
|
* ```typescript
|
|
26123
|
-
* const { workers } = await
|
|
26407
|
+
* const { workers } = await RunsClient.list(config, { status: 'running' })
|
|
26124
26408
|
* console.log(`${workers.length} workers currently running`)
|
|
26125
26409
|
* ```
|
|
26126
26410
|
*/
|
|
26127
|
-
list(config: SylphxConfig, options?:
|
|
26411
|
+
list(config: SylphxConfig, options?: ListRunsOptions): Promise<ListRunsResult>;
|
|
26128
26412
|
/**
|
|
26129
26413
|
* Spawn a worker and wait for it to complete in one call.
|
|
26130
26414
|
*
|
|
26131
|
-
* Equivalent to `(await
|
|
26415
|
+
* Equivalent to `(await RunsClient.create(config, options)).wait(waitOptions)`.
|
|
26132
26416
|
*
|
|
26133
26417
|
* @example
|
|
26134
26418
|
* ```typescript
|
|
26135
|
-
* const result = await
|
|
26419
|
+
* const result = await RunsClient.runAndWait(config, {
|
|
26136
26420
|
* image: 'registry.sylphx.com/sylphx/process:abc',
|
|
26137
26421
|
* command: ['node', 'dist/process.js'],
|
|
26138
26422
|
* })
|
|
26139
26423
|
* if (result.exitCode !== 0) throw new Error(result.errorMessage ?? 'worker failed')
|
|
26140
26424
|
* ```
|
|
26141
26425
|
*/
|
|
26142
|
-
runAndWait(config: SylphxConfig, options:
|
|
26426
|
+
runAndWait(config: SylphxConfig, options: CreateRunOptions, waitOptions?: {
|
|
26143
26427
|
pollIntervalMs?: number;
|
|
26144
26428
|
timeoutMs?: number;
|
|
26145
|
-
}): Promise<
|
|
26429
|
+
}): Promise<RunResult>;
|
|
26146
26430
|
};
|
|
26147
26431
|
|
|
26148
|
-
|
|
26432
|
+
/**
|
|
26433
|
+
* Triggers Client (ADR-040)
|
|
26434
|
+
*
|
|
26435
|
+
* Unified scheduling + event dispatch API.
|
|
26436
|
+
* Create cron schedules and event triggers that dispatch to Tasks, Runs, or HTTP URLs.
|
|
26437
|
+
*
|
|
26438
|
+
* ## Usage
|
|
26439
|
+
*
|
|
26440
|
+
* ### Cron → Task
|
|
26441
|
+
* ```typescript
|
|
26442
|
+
* import { createConfig, TriggersClient } from '@sylphx/sdk'
|
|
26443
|
+
* const config = createConfig({ secretKey: process.env.SYLPHX_SECRET_KEY!, ref: 'my-project' })
|
|
26444
|
+
*
|
|
26445
|
+
* const trigger = await TriggersClient.create(config, {
|
|
26446
|
+
* name: 'daily-cleanup',
|
|
26447
|
+
* source: { type: 'cron', expression: '0 2 * * *' },
|
|
26448
|
+
* target: { type: 'task', taskName: 'daily-cleanup' },
|
|
26449
|
+
* })
|
|
26450
|
+
* ```
|
|
26451
|
+
*
|
|
26452
|
+
* ### Event → Task (fires when event is published via publishEvent)
|
|
26453
|
+
* ```typescript
|
|
26454
|
+
* const trigger = await TriggersClient.create(config, {
|
|
26455
|
+
* name: 'welcome-email-on-signup',
|
|
26456
|
+
* source: { type: 'event', eventName: 'user.signup' },
|
|
26457
|
+
* target: { type: 'task', taskName: 'send-welcome-email' },
|
|
26458
|
+
* })
|
|
26459
|
+
* // Publish from your app:
|
|
26460
|
+
* await TriggersClient.publishEvent(config, 'user.signup', { userId: '123' })
|
|
26461
|
+
* ```
|
|
26462
|
+
*
|
|
26463
|
+
* ### Cron → HTTP URL (any language, no code required)
|
|
26464
|
+
* ```typescript
|
|
26465
|
+
* const trigger = await TriggersClient.create(config, {
|
|
26466
|
+
* name: 'nightly-backup',
|
|
26467
|
+
* source: { type: 'cron', expression: '0 3 * * *' },
|
|
26468
|
+
* target: { type: 'http', url: 'https://myapp.com/api/backup', payload: { type: 'full' } },
|
|
26469
|
+
* })
|
|
26470
|
+
* ```
|
|
26471
|
+
*/
|
|
26472
|
+
|
|
26473
|
+
type TriggerTargetType = 'task' | 'run' | 'http';
|
|
26474
|
+
type TriggerSourceType = 'cron' | 'event';
|
|
26475
|
+
type TriggerStatus = 'active' | 'paused' | 'deleted';
|
|
26476
|
+
interface TaskTarget {
|
|
26477
|
+
type: 'task';
|
|
26478
|
+
taskName: string;
|
|
26479
|
+
handlerPath?: string;
|
|
26480
|
+
payload?: Record<string, unknown>;
|
|
26481
|
+
}
|
|
26482
|
+
interface HttpTarget {
|
|
26483
|
+
type: 'http';
|
|
26484
|
+
url: string;
|
|
26485
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
26486
|
+
headers?: Record<string, string>;
|
|
26487
|
+
payload?: Record<string, unknown>;
|
|
26488
|
+
}
|
|
26489
|
+
interface RunTarget {
|
|
26490
|
+
type: 'run';
|
|
26491
|
+
image: string;
|
|
26492
|
+
command: string[];
|
|
26493
|
+
resources?: {
|
|
26494
|
+
cpu?: string;
|
|
26495
|
+
memory?: string;
|
|
26496
|
+
};
|
|
26497
|
+
}
|
|
26498
|
+
type TriggerTarget = TaskTarget | HttpTarget | RunTarget;
|
|
26499
|
+
interface CronSource {
|
|
26500
|
+
type: 'cron';
|
|
26501
|
+
expression: string;
|
|
26502
|
+
}
|
|
26503
|
+
interface EventSource {
|
|
26504
|
+
type: 'event';
|
|
26505
|
+
/** The event name to listen for. e.g. 'user.signup', 'order.paid' */
|
|
26506
|
+
eventName: string;
|
|
26507
|
+
}
|
|
26508
|
+
type TriggerSource = CronSource | EventSource;
|
|
26509
|
+
interface CreateTriggerOptions {
|
|
26510
|
+
name?: string;
|
|
26511
|
+
source: TriggerSource;
|
|
26512
|
+
target: TriggerTarget;
|
|
26513
|
+
paused?: boolean;
|
|
26514
|
+
/** Idempotency key — prevents duplicate trigger creation per project+environment */
|
|
26515
|
+
idempotencyKey?: string;
|
|
26516
|
+
}
|
|
26517
|
+
interface UpdateTriggerOptions {
|
|
26518
|
+
name?: string;
|
|
26519
|
+
source?: TriggerSource;
|
|
26520
|
+
paused?: boolean;
|
|
26521
|
+
}
|
|
26522
|
+
interface Trigger {
|
|
26523
|
+
id: string;
|
|
26524
|
+
name: string;
|
|
26525
|
+
targetType: TriggerTargetType;
|
|
26526
|
+
sourceType: TriggerSourceType;
|
|
26527
|
+
cronExpression: string | null;
|
|
26528
|
+
eventName: string | null;
|
|
26529
|
+
handlerPath: string | null;
|
|
26530
|
+
callbackUrl: string | null;
|
|
26531
|
+
payload: unknown;
|
|
26532
|
+
status: TriggerStatus;
|
|
26533
|
+
nextRunAt: string | null;
|
|
26534
|
+
lastRunAt: string | null;
|
|
26535
|
+
createdAt: string;
|
|
26536
|
+
updatedAt: string;
|
|
26537
|
+
}
|
|
26538
|
+
interface ListTriggersResult {
|
|
26539
|
+
triggers: Trigger[];
|
|
26540
|
+
}
|
|
26541
|
+
interface PublishEventResult {
|
|
26542
|
+
dispatched: number;
|
|
26543
|
+
eventName: string;
|
|
26544
|
+
}
|
|
26545
|
+
declare class TriggersClient {
|
|
26546
|
+
/** Create a new trigger (cron or event source, task/run/http target) */
|
|
26547
|
+
static create(config: SylphxConfig, options: CreateTriggerOptions): Promise<Trigger>;
|
|
26548
|
+
/** List all triggers for the project */
|
|
26549
|
+
static list(config: SylphxConfig): Promise<ListTriggersResult>;
|
|
26550
|
+
/** Get a trigger by ID */
|
|
26551
|
+
static get(config: SylphxConfig, triggerId: string): Promise<Trigger>;
|
|
26552
|
+
/** Update a trigger */
|
|
26553
|
+
static update(config: SylphxConfig, triggerId: string, options: UpdateTriggerOptions): Promise<Trigger>;
|
|
26554
|
+
/** Delete a trigger */
|
|
26555
|
+
static delete(config: SylphxConfig, triggerId: string): Promise<{
|
|
26556
|
+
success: boolean;
|
|
26557
|
+
}>;
|
|
26558
|
+
/** Pause a trigger */
|
|
26559
|
+
static pause(config: SylphxConfig, triggerId: string): Promise<Trigger>;
|
|
26560
|
+
/** Resume a paused trigger */
|
|
26561
|
+
static resume(config: SylphxConfig, triggerId: string): Promise<Trigger>;
|
|
26562
|
+
/** Fire a trigger immediately (one-shot, regardless of schedule) */
|
|
26563
|
+
static fire(config: SylphxConfig, triggerId: string): Promise<{
|
|
26564
|
+
success: boolean;
|
|
26565
|
+
message: string;
|
|
26566
|
+
}>;
|
|
26567
|
+
/**
|
|
26568
|
+
* Publish an event — dispatches all active event triggers matching the event name.
|
|
26569
|
+
*
|
|
26570
|
+
* @example
|
|
26571
|
+
* ```typescript
|
|
26572
|
+
* await TriggersClient.publishEvent(config, 'user.signup', { userId: '123', plan: 'pro' })
|
|
26573
|
+
* ```
|
|
26574
|
+
*/
|
|
26575
|
+
/**
|
|
26576
|
+
* Publish an event — dispatches all active event triggers matching the event name.
|
|
26577
|
+
* Endpoint: POST /triggers/events
|
|
26578
|
+
*
|
|
26579
|
+
* @example
|
|
26580
|
+
* ```typescript
|
|
26581
|
+
* await TriggersClient.publishEvent(config, 'user.signup', { userId: '123', plan: 'pro' })
|
|
26582
|
+
* ```
|
|
26583
|
+
*/
|
|
26584
|
+
static publishEvent(config: SylphxConfig, eventName: string, payload?: Record<string, unknown>): Promise<PublishEventResult>;
|
|
26585
|
+
}
|
|
26586
|
+
|
|
26587
|
+
export { ACHIEVEMENT_TIER_CONFIG, type AIListModelsOptions, type AIListModelsResponse, type AIMessage, type AIMessageRole, type AIModel, type AIModelInfo, type AIModelsResponse, type AIProvider, type AIRateLimitInfo, type AIRateLimitResponse, type AIRequestType, type AIStreamChunk, type AITool, type AIToolCall, type AIUsageResponse, type AIUsageStats, type AccessTokenPayload, type AchievementCategory, type AchievementCriteria, type AchievementCriterion, type AchievementDefinition, type AchievementTier, type AchievementType, type AchievementUnlockEvent, type AdminUser, AuthenticationError, AuthorizationError, type BalanceResponse, type BatchEvent, type BatchIndexInput, type BatchIndexResult, type Breadcrumb, type BuildLog, type BuildLogHistoryResponse, type CaptureExceptionRequest, type CaptureMessageRequest, type ChatCompletionInput, type ChatCompletionResponse, type ChatInput, type ChatMessage, type ChatResult, type ChatStreamChunk, type CheckoutRequest, type CheckoutResponse, type CircuitBreakerConfig, CircuitBreakerOpenError, type CircuitState, type CommandResult, type ConsentCategory, type ConsentHistoryEntry, type ConsentHistoryResult, type ConsentPurposeDefaults, type ConsentType, type ContentPart, type CreateOrgInput, type CreatePermissionInput, type CreateRoleInput, type CreateRunOptions, type CreateTriggerOptions, type CriteriaOperator, type CronInput, type CronSchedule, type CronSource, type DatabaseConnectionInfo, type DatabaseStatus, type DatabaseStatusInfo, type DebugCategory, type DeduplicationConfig, type DeleteDocumentInput, type DeployHistoryResponse, type DeployInfo, type DeployStatus, type DynamicRestClient, ERROR_CODE_STATUS, type EmbedInput, type EmbedResult, type EmbeddingInput, type EmbeddingResponse, type LeaderboardEntry as EngagementLeaderboardEntry, type LeaderboardResult as EngagementLeaderboardResult, type EnvVar, type ErrorCode, type ErrorResponse, type EventSource, type ExceptionFrame, type ExceptionValue, type ExecEvent, type ExecOptions, type ExecResult, type FacetsResponse, type FileEvent, type FileInfo, type FileUploadOptions, type FlagContext, type FlagResult, type GetConsentHistoryInput, type GetConsentsInput, type GetFacetsInput, type GetSecretInput, type GetSecretResult, type GetSecretsInput, type GetSecretsResult, type HttpTarget, type IdentifyInput, type IndexDocumentInput, type IndexDocumentResult, InvalidConnectionUrlError, type InviteMemberInput, type InviteUserRequest, type InviteUserResponse, type KvExpireRequest, type KvHgetRequest, type KvHgetallRequest, type KvHsetRequest, type KvIncrRequest, type KvLpushRequest, type KvLrangeRequest, type KvMgetRequest, type KvMsetRequest, type KvRateLimitRequest, type KvRateLimitResult, type KvScanOptions, type KvScanResult, type KvSetOptions, type KvSetRequest, type KvZMember, type KvZaddRequest, type KvZrangeRequest, type LeaderboardAggregation, type LeaderboardDefinition, type LeaderboardEntry$1 as LeaderboardEntry, type LeaderboardOptions, type LeaderboardQueryOptions, type LeaderboardResetPeriod, type LeaderboardResult$1 as LeaderboardResult, type LeaderboardSortDirection, type LinkAnonymousConsentsInput, type ListRunsOptions, type ListRunsResult, type ListScheduledEmailsOptions, type ListSecretKeysInput, type ListTriggersResult, type ListUsersOptions, type ListUsersResult, type LoginHistoryEntry, type LoginRequest, type LoginResponse, type MeResponse, type MemberPermissionsResult, type MonitoringResponse, type MonitoringSeverity, type NativeStepContext, type NativeTaskDefinition, type TaskRunStatus as NativeTaskRunStatus, NetworkError, NotFoundError, type OrgRole, type OrgTokenPayload, type Organization, type OrganizationInvitation, type OrganizationMember, type OrganizationMembership, type PageInput, type PaginatedResponse, type PaginationInput, type ParsedConnectionUrl, type Permission, type Plan, type PortalRequest, type PortalResponse, type ProcessEvent, type ProcessInfo, type ProcessStartOptions, type ProcessSummary, type PublishEventResult, type PushNotification, type PushNotificationPayload, type PushServiceWorkerConfig, type PushSubscription, RETRYABLE_CODES, RateLimitError, type RealtimeEmitRequest, type RealtimeEmitResponse, type RealtimeHistoryRequest, type RealtimeHistoryResponse, type RecordActivityInput, type RecordActivityResult, type RedeemReferralInput, type RedeemResult, type ReferralCode, type ReferralStats, type RegisterInput, type RegisterRequest, type RegisterResponse, type RestClient, type RestClientConfig, type RestDynamicConfig, type paths as RestPaths, type RetryConfig, type RevokeTokenOptions, type Role, type RollbackDeployRequest, type Run, RunHandle, type RunLogsResult, type RunResourceSpec, type RunResult, type RunStatus, type RunTarget, type RunVolumeMount, type CreateRunOptions as RunWorkerOptions, RunsClient, SandboxClient, type SandboxFile, SandboxFiles, type SandboxOptions, SandboxProcesses, type SandboxRecord, SandboxWatch, type ScheduleEmailOptions, type ScheduledEmail, type ScheduledEmailStats, type ScheduledEmailsResult, type SearchInput, type SearchResponse, type SearchResultItem, type SearchStatsResult, type SearchType, type SecretKeyInfo, type SecuritySettings, type SendEmailOptions, type SendResult, type SendTemplatedEmailOptions, type SendToUserOptions, type SessionResult, type SetConsentsInput, type SetEnvVarRequest, type SignedUrlOptions, type SignedUrlResult, StepCompleteSignal, StepSleepSignal, type StreakDefinition, type StreakFrequency, type StreakState, type StreamMessage, type SubmitScoreInput, type SubmitScoreResult, type Subscription, type SuccessResponse, type SylphxClientInput, type SylphxConfig, type SylphxConfigInput, SylphxError, type SylphxErrorCode, type SylphxErrorOptions, type TaskInput, type TaskResult, type TaskStatus, type TaskTarget, type TextCompletionInput, type TextCompletionResponse, TimeoutError, type TokenIntrospectionResult, type TokenResponse, type Tool, type ToolCall, type TrackClickInput, type TrackInput, type Trigger, type TriggerDeployRequest, type TriggerSource, type TriggerSourceType, type TriggerStatus, type TriggerTarget, type TriggerTargetType, TriggersClient, type TwoFactorVerifyRequest, type UpdateOrgInput, type UpdateRoleInput, type UpdateTriggerOptions, type UploadProgressEvent, type UploadResult, type UpsertDocumentInput, type UpsertDocumentResult, type UsageResponse, type User, type UserAchievement, type UserConsent, type UserProfile, ValidationError, type VisionInput, type WatchEntry, type WatchOptions, type WebhookConfig, type WebhookConfigUpdate, type WebhookDeliveriesResult, type WebhookDelivery, type WebhookStats, RunHandle as WorkerHandle, type RunLogsResult as WorkerLogsResult, type RunResourceSpec as WorkerResourceSpec, type RunResult as WorkerResult, type Run as WorkerRun, type RunStatus as WorkerStatus, type RunVolumeMount as WorkerVolumeMount, WorkersClient, acceptAllConsents, acceptOrganizationInvitation, assignMemberRole, batchIndex, canDeleteOrganization, canManageMembers, canManageSettings, cancelScheduledEmail, cancelTask, captureException, captureExceptionRaw, captureMessage, chat, chatStream, checkFlag, complete, createCheckout, createClient, createConfig, createCron, createDynamicRestClient, createOrganization, createPermission, createPortalSession, createRestClient, createRole, createServerClient, createServiceWorkerScript, createStepContext, createTasksHandler, createTracker, debugError, debugLog, debugTimer, debugWarn, declineOptionalConsents, deleteCron, deleteDocument, deleteEnvVar, deleteFile, deleteOrganization, deletePermission, deleteRole, deleteUser, disableDebug, embed, enableDebug, exponentialBackoff, extendedSignUp, forgotPassword, generateAnonymousId, getAchievement, getAchievementPoints, getAchievements, getAllFlags, getAllSecrets, getAllStreaks, getBillingBalance, getBillingUsage, getBuildLogHistory, getCircuitBreakerState, getConsentHistory, getConsentTypes, getDatabaseConnectionString, getDatabaseStatus, getDebugMode, getDeployHistory, getDeployStatus, getErrorCode, getErrorMessage, getFacets, getFileInfo, getFileUrl, getFlagPayload, getFlags, getLeaderboard, getMemberPermissions, getMyReferralCode, getOrganization, getOrganizationInvitations, getOrganizationMembers, getOrganizations, getPlans, getPushPreferences, getRealtimeHistory, getReferralLeaderboard, getReferralStats, getRestErrorMessage, getRole, getScheduledEmail, getScheduledEmailStats, getSearchStats, getSecret, getSecrets, getSession, getSignedUrl, getStreak, getSubscription, getTask, getUser, getUserByEmail, getUserConsents, getUserLeaderboardRank, getVariant, getWebhookConfig, getWebhookDeliveries, getWebhookDelivery, getWebhookStats, hasAllPermissions, hasAnyPermission, hasConsent, hasError, hasPermission, hasRole, hasSecret, identify, incrementAchievementProgress, indexDocument, initPushServiceWorker, installGlobalDebugHelpers, introspectToken, inviteOrganizationMember, inviteUser, isEmailConfigured, isEnabled, isRetryableError, isSylphxError, kvDelete, kvExists, kvExpire, kvGet, kvGetJSON, kvHget, kvHgetall, kvHset, kvIncr, kvLpush, kvLrange, kvMget, kvMset, kvRateLimit, kvScan, kvSet, kvSetJSON, kvZadd, kvZrange, leaveOrganization, linkAnonymousConsents, listEnvVars, listPermissions, listRoles, listScheduledEmails, listSecretKeys, listTasks, listUsers, page, pauseCron, realtimeEmit, recordStreakActivity, recoverStreak, redeemReferralCode, refreshToken, regenerateReferralCode, registerPush, registerPushServiceWorker, removeOrganizationMember, replayWebhookDelivery, rescheduleEmail, resetCircuitBreaker, resetDebugModeCache, resetPassword, resumeCron, revokeAllTokens, revokeOrganizationInvitation, revokeToken, rollbackDeploy, scheduleEmail, scheduleTask, search, sendEmail, sendEmailToUser, sendPush, sendTemplatedEmail, setConsents, setEnvVar, signIn, signOut, signUp, streamToString, submitScore, suspendUser, switchOrg, toSylphxError, track, trackBatch, trackClick, triggerDeploy, unlockAchievement, unregisterPush, updateOrganization, updateOrganizationMemberRole, updatePushPreferences, updateRole, updateUser, updateUserMetadata, updateWebhookConfig, uploadAvatar, uploadFile, upsertDocument, verifyEmail, verifySignature as verifyTaskSignature, verifyTwoFactor, withToken };
|