@seenn/types 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -0
- package/dist/index.d.mts +416 -0
- package/dist/index.d.ts +416 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +19 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +39 -0
- package/src/index.ts +525 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @seenn/types - Shared TypeScript types for Seenn SDKs
|
|
3
|
+
*
|
|
4
|
+
* This package is the single source of truth for all Seenn type definitions.
|
|
5
|
+
* All SDK packages (react-native, node, flutter) should depend on this package.
|
|
6
|
+
*
|
|
7
|
+
* @version 0.1.0
|
|
8
|
+
* @license MIT
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// ============================================
|
|
12
|
+
// Core Job Types
|
|
13
|
+
// ============================================
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Job status values
|
|
17
|
+
*/
|
|
18
|
+
export type JobStatus =
|
|
19
|
+
| 'pending'
|
|
20
|
+
| 'queued'
|
|
21
|
+
| 'running'
|
|
22
|
+
| 'completed'
|
|
23
|
+
| 'failed'
|
|
24
|
+
| 'cancelled';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* How parent job progress is calculated from children
|
|
28
|
+
*/
|
|
29
|
+
export type ChildProgressMode = 'average' | 'weighted' | 'sequential';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Main job object returned by API and SSE
|
|
33
|
+
*/
|
|
34
|
+
export interface SeennJob {
|
|
35
|
+
/** Unique job identifier (ULID format) */
|
|
36
|
+
jobId: string;
|
|
37
|
+
/** User who owns this job */
|
|
38
|
+
userId: string;
|
|
39
|
+
/** Application ID */
|
|
40
|
+
appId: string;
|
|
41
|
+
/** Current job status */
|
|
42
|
+
status: JobStatus;
|
|
43
|
+
/** Human-readable job title */
|
|
44
|
+
title: string;
|
|
45
|
+
/** Job type for categorization */
|
|
46
|
+
jobType: string;
|
|
47
|
+
/** Workflow ID for ETA tracking (default: jobType) */
|
|
48
|
+
workflowId?: string;
|
|
49
|
+
/** Progress percentage (0-100) */
|
|
50
|
+
progress: number;
|
|
51
|
+
/** Current status message */
|
|
52
|
+
message?: string;
|
|
53
|
+
/** Stage information for multi-step jobs */
|
|
54
|
+
stage?: StageInfo;
|
|
55
|
+
/** Estimated completion timestamp (ISO 8601) */
|
|
56
|
+
estimatedCompletionAt?: string;
|
|
57
|
+
/** ETA confidence score (0.0 - 1.0) */
|
|
58
|
+
etaConfidence?: number;
|
|
59
|
+
/** Number of historical jobs used to calculate ETA */
|
|
60
|
+
etaBasedOn?: number;
|
|
61
|
+
/** Queue position info */
|
|
62
|
+
queue?: QueueInfo;
|
|
63
|
+
/** Job result on completion */
|
|
64
|
+
result?: JobResult;
|
|
65
|
+
/** Error details on failure */
|
|
66
|
+
error?: JobError;
|
|
67
|
+
/** Custom metadata */
|
|
68
|
+
metadata?: Record<string, unknown>;
|
|
69
|
+
/** Parent info (if this is a child job) */
|
|
70
|
+
parent?: ParentInfo;
|
|
71
|
+
/** Children stats (if this is a parent job) */
|
|
72
|
+
children?: ChildrenStats;
|
|
73
|
+
/** Progress calculation mode for parent jobs */
|
|
74
|
+
childProgressMode?: ChildProgressMode;
|
|
75
|
+
/** Job creation timestamp (ISO 8601) */
|
|
76
|
+
createdAt: string;
|
|
77
|
+
/** Last update timestamp (ISO 8601) */
|
|
78
|
+
updatedAt: string;
|
|
79
|
+
/** When the job started running (ISO 8601) */
|
|
80
|
+
startedAt?: string;
|
|
81
|
+
/** Job completion timestamp (ISO 8601) */
|
|
82
|
+
completedAt?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ============================================
|
|
86
|
+
// Stage & Queue Types
|
|
87
|
+
// ============================================
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Stage information for multi-step jobs
|
|
91
|
+
*/
|
|
92
|
+
export interface StageInfo {
|
|
93
|
+
/** Current stage name */
|
|
94
|
+
name: string;
|
|
95
|
+
/** Current stage index (1-based) */
|
|
96
|
+
current: number;
|
|
97
|
+
/** Total number of stages */
|
|
98
|
+
total: number;
|
|
99
|
+
/** Optional stage description */
|
|
100
|
+
description?: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Queue position information
|
|
105
|
+
*/
|
|
106
|
+
export interface QueueInfo {
|
|
107
|
+
/** Position in queue (1-based) */
|
|
108
|
+
position: number;
|
|
109
|
+
/** Total items in queue */
|
|
110
|
+
total?: number;
|
|
111
|
+
/** Queue name/identifier */
|
|
112
|
+
queueName?: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ============================================
|
|
116
|
+
// Result & Error Types
|
|
117
|
+
// ============================================
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Job result on successful completion
|
|
121
|
+
*/
|
|
122
|
+
export interface JobResult {
|
|
123
|
+
/** Result type (e.g., 'video', 'image', 'file') */
|
|
124
|
+
type?: string;
|
|
125
|
+
/** Result URL if applicable */
|
|
126
|
+
url?: string;
|
|
127
|
+
/** Additional result data */
|
|
128
|
+
data?: Record<string, unknown>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Error details on job failure
|
|
133
|
+
*/
|
|
134
|
+
export interface JobError {
|
|
135
|
+
/** Error code for programmatic handling */
|
|
136
|
+
code: string;
|
|
137
|
+
/** Human-readable error message */
|
|
138
|
+
message: string;
|
|
139
|
+
/** Additional error details */
|
|
140
|
+
details?: Record<string, unknown>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ============================================
|
|
144
|
+
// Parent-Child Types
|
|
145
|
+
// ============================================
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Parent info for child jobs
|
|
149
|
+
*/
|
|
150
|
+
export interface ParentInfo {
|
|
151
|
+
/** Parent job ID */
|
|
152
|
+
parentJobId: string;
|
|
153
|
+
/** Child index within parent (0-based) */
|
|
154
|
+
childIndex: number;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Children stats for parent jobs
|
|
159
|
+
*/
|
|
160
|
+
export interface ChildrenStats {
|
|
161
|
+
/** Total number of children */
|
|
162
|
+
total: number;
|
|
163
|
+
/** Number of completed children */
|
|
164
|
+
completed: number;
|
|
165
|
+
/** Number of failed children */
|
|
166
|
+
failed: number;
|
|
167
|
+
/** Number of running children */
|
|
168
|
+
running: number;
|
|
169
|
+
/** Number of pending children */
|
|
170
|
+
pending: number;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Summary of a child job (used in parent.children array)
|
|
175
|
+
*/
|
|
176
|
+
export interface ChildJobSummary {
|
|
177
|
+
/** Child job ID */
|
|
178
|
+
id: string;
|
|
179
|
+
/** Child index within parent (0-based) */
|
|
180
|
+
childIndex: number;
|
|
181
|
+
/** Child job title */
|
|
182
|
+
title: string;
|
|
183
|
+
/** Child job status */
|
|
184
|
+
status: JobStatus;
|
|
185
|
+
/** Child progress (0-100) */
|
|
186
|
+
progress: number;
|
|
187
|
+
/** Child status message */
|
|
188
|
+
message?: string;
|
|
189
|
+
/** Child result */
|
|
190
|
+
result?: JobResult;
|
|
191
|
+
/** Child error */
|
|
192
|
+
error?: JobError;
|
|
193
|
+
/** Child creation timestamp */
|
|
194
|
+
createdAt: string;
|
|
195
|
+
/** Child last update timestamp */
|
|
196
|
+
updatedAt: string;
|
|
197
|
+
/** Child completion timestamp */
|
|
198
|
+
completedAt?: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Parent job with all its children
|
|
203
|
+
*/
|
|
204
|
+
export interface ParentWithChildren {
|
|
205
|
+
/** Parent job */
|
|
206
|
+
parent: SeennJob;
|
|
207
|
+
/** List of child jobs */
|
|
208
|
+
children: ChildJobSummary[];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ============================================
|
|
212
|
+
// SSE Types
|
|
213
|
+
// ============================================
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Connection state for SSE
|
|
217
|
+
*/
|
|
218
|
+
export type ConnectionState =
|
|
219
|
+
| 'disconnected'
|
|
220
|
+
| 'connecting'
|
|
221
|
+
| 'connected'
|
|
222
|
+
| 'reconnecting';
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* SSE event types
|
|
226
|
+
*/
|
|
227
|
+
export type SSEEventType =
|
|
228
|
+
| 'connected'
|
|
229
|
+
| 'job.sync'
|
|
230
|
+
| 'job.started'
|
|
231
|
+
| 'job.progress'
|
|
232
|
+
| 'job.completed'
|
|
233
|
+
| 'job.failed'
|
|
234
|
+
| 'job.cancelled'
|
|
235
|
+
| 'child.progress'
|
|
236
|
+
| 'parent.updated'
|
|
237
|
+
| 'in_app_message'
|
|
238
|
+
| 'connection.idle'
|
|
239
|
+
| 'heartbeat'
|
|
240
|
+
| 'error';
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* SSE event wrapper
|
|
244
|
+
*/
|
|
245
|
+
export interface SSEEvent {
|
|
246
|
+
/** Event type */
|
|
247
|
+
event: SSEEventType;
|
|
248
|
+
/** Event data */
|
|
249
|
+
data: unknown;
|
|
250
|
+
/** Event ID for replay */
|
|
251
|
+
id?: string;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// ============================================
|
|
255
|
+
// In-App Message Types
|
|
256
|
+
// ============================================
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* In-app message types
|
|
260
|
+
*/
|
|
261
|
+
export type InAppMessageType =
|
|
262
|
+
| 'job_complete_banner'
|
|
263
|
+
| 'job_failed_modal'
|
|
264
|
+
| 'job_toast';
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* In-app message for UI notifications
|
|
268
|
+
*/
|
|
269
|
+
export interface InAppMessage {
|
|
270
|
+
/** Message ID */
|
|
271
|
+
messageId: string;
|
|
272
|
+
/** Message type */
|
|
273
|
+
type: InAppMessageType;
|
|
274
|
+
/** Associated job ID */
|
|
275
|
+
jobId: string;
|
|
276
|
+
/** Message title */
|
|
277
|
+
title: string;
|
|
278
|
+
/** Message body */
|
|
279
|
+
body?: string;
|
|
280
|
+
/** Call-to-action text */
|
|
281
|
+
cta?: string;
|
|
282
|
+
/** Call-to-action URL */
|
|
283
|
+
ctaUrl?: string;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ============================================
|
|
287
|
+
// API Types
|
|
288
|
+
// ============================================
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Create job request parameters
|
|
292
|
+
*/
|
|
293
|
+
export interface CreateJobParams {
|
|
294
|
+
/** User ID */
|
|
295
|
+
userId: string;
|
|
296
|
+
/** Job type */
|
|
297
|
+
jobType: string;
|
|
298
|
+
/** Job title */
|
|
299
|
+
title: string;
|
|
300
|
+
/** Workflow ID for ETA tracking (default: jobType) */
|
|
301
|
+
workflowId?: string;
|
|
302
|
+
/** Initial message */
|
|
303
|
+
message?: string;
|
|
304
|
+
/** Custom metadata */
|
|
305
|
+
metadata?: Record<string, unknown>;
|
|
306
|
+
/** Estimated duration in ms (for ETA default) */
|
|
307
|
+
estimatedDuration?: number;
|
|
308
|
+
/** Parent job ID (for child jobs) */
|
|
309
|
+
parentJobId?: string;
|
|
310
|
+
/** Child index (for child jobs) */
|
|
311
|
+
childIndex?: number;
|
|
312
|
+
/** Total children (for parent jobs) */
|
|
313
|
+
totalChildren?: number;
|
|
314
|
+
/** Child progress mode (for parent jobs) */
|
|
315
|
+
childProgressMode?: ChildProgressMode;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Update job request parameters
|
|
320
|
+
*/
|
|
321
|
+
export interface UpdateJobParams {
|
|
322
|
+
/** New progress (0-100) */
|
|
323
|
+
progress?: number;
|
|
324
|
+
/** New message */
|
|
325
|
+
message?: string;
|
|
326
|
+
/** New stage info */
|
|
327
|
+
stage?: StageInfo;
|
|
328
|
+
/** Custom metadata to merge */
|
|
329
|
+
metadata?: Record<string, unknown>;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Complete job request parameters
|
|
334
|
+
*/
|
|
335
|
+
export interface CompleteJobParams {
|
|
336
|
+
/** Job result */
|
|
337
|
+
result?: JobResult;
|
|
338
|
+
/** Final message */
|
|
339
|
+
message?: string;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Fail job request parameters
|
|
344
|
+
*/
|
|
345
|
+
export interface FailJobParams {
|
|
346
|
+
/** Error details */
|
|
347
|
+
error: JobError;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ============================================
|
|
351
|
+
// Webhook Types
|
|
352
|
+
// ============================================
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Webhook event types
|
|
356
|
+
*/
|
|
357
|
+
export type WebhookEventType =
|
|
358
|
+
| 'job.started'
|
|
359
|
+
| 'job.progress'
|
|
360
|
+
| 'job.completed'
|
|
361
|
+
| 'job.failed'
|
|
362
|
+
| 'job.cancelled';
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Webhook payload
|
|
366
|
+
*/
|
|
367
|
+
export interface WebhookPayload {
|
|
368
|
+
/** Event type */
|
|
369
|
+
event: WebhookEventType;
|
|
370
|
+
/** Job data */
|
|
371
|
+
job: SeennJob;
|
|
372
|
+
/** Event timestamp (ISO 8601) */
|
|
373
|
+
timestamp: string;
|
|
374
|
+
/** Webhook delivery ID */
|
|
375
|
+
deliveryId: string;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ============================================
|
|
379
|
+
// ETA Types
|
|
380
|
+
// ============================================
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* ETA statistics for a workflow/jobType
|
|
384
|
+
*/
|
|
385
|
+
export interface EtaStats {
|
|
386
|
+
/** ETA key (workflowId or jobType) */
|
|
387
|
+
etaKey: string;
|
|
388
|
+
/** Number of completed jobs */
|
|
389
|
+
count: number;
|
|
390
|
+
/** Average duration in ms */
|
|
391
|
+
avgDuration: number;
|
|
392
|
+
/** Minimum duration in ms */
|
|
393
|
+
minDuration: number;
|
|
394
|
+
/** Maximum duration in ms */
|
|
395
|
+
maxDuration: number;
|
|
396
|
+
/** Default duration if no history */
|
|
397
|
+
defaultDuration?: number;
|
|
398
|
+
/** Last updated timestamp */
|
|
399
|
+
lastUpdated: string;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// ============================================
|
|
403
|
+
// SDK Configuration Types
|
|
404
|
+
// ============================================
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Base SDK configuration
|
|
408
|
+
*/
|
|
409
|
+
export interface SeennConfig {
|
|
410
|
+
/** API base URL */
|
|
411
|
+
baseUrl: string;
|
|
412
|
+
/** Authentication token (pk_* for client, sk_* for server) */
|
|
413
|
+
authToken?: string;
|
|
414
|
+
/** SSE endpoint URL (default: baseUrl + /v1/sse) */
|
|
415
|
+
sseUrl?: string;
|
|
416
|
+
/** Enable auto-reconnect (default: true) */
|
|
417
|
+
reconnect?: boolean;
|
|
418
|
+
/** Reconnect interval in ms (default: 1000) */
|
|
419
|
+
reconnectInterval?: number;
|
|
420
|
+
/** Max reconnect attempts (default: 10) */
|
|
421
|
+
maxReconnectAttempts?: number;
|
|
422
|
+
/** Enable debug logging (default: false) */
|
|
423
|
+
debug?: boolean;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// ============================================
|
|
427
|
+
// Live Activity Types (iOS/Android)
|
|
428
|
+
// ============================================
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Live Activity start parameters
|
|
432
|
+
*/
|
|
433
|
+
export interface LiveActivityStartParams {
|
|
434
|
+
/** Job ID */
|
|
435
|
+
jobId: string;
|
|
436
|
+
/** Activity title */
|
|
437
|
+
title: string;
|
|
438
|
+
/** Job type for icon selection */
|
|
439
|
+
jobType?: string;
|
|
440
|
+
/** Initial progress (0-100) */
|
|
441
|
+
initialProgress?: number;
|
|
442
|
+
/** Initial message */
|
|
443
|
+
initialMessage?: string;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Live Activity update parameters
|
|
448
|
+
*/
|
|
449
|
+
export interface LiveActivityUpdateParams {
|
|
450
|
+
/** Job ID */
|
|
451
|
+
jobId: string;
|
|
452
|
+
/** New progress (0-100) */
|
|
453
|
+
progress?: number;
|
|
454
|
+
/** New status */
|
|
455
|
+
status?: JobStatus;
|
|
456
|
+
/** New message */
|
|
457
|
+
message?: string;
|
|
458
|
+
/** Stage info */
|
|
459
|
+
stage?: StageInfo;
|
|
460
|
+
/** ETA timestamp (Unix ms) */
|
|
461
|
+
estimatedEndTime?: number;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Live Activity end parameters
|
|
466
|
+
*/
|
|
467
|
+
export interface LiveActivityEndParams {
|
|
468
|
+
/** Job ID */
|
|
469
|
+
jobId: string;
|
|
470
|
+
/** Final status */
|
|
471
|
+
finalStatus?: JobStatus;
|
|
472
|
+
/** Final progress */
|
|
473
|
+
finalProgress?: number;
|
|
474
|
+
/** Final message */
|
|
475
|
+
message?: string;
|
|
476
|
+
/** Result URL */
|
|
477
|
+
resultUrl?: string;
|
|
478
|
+
/** Error message */
|
|
479
|
+
errorMessage?: string;
|
|
480
|
+
/** Dismiss after seconds (default: 300) */
|
|
481
|
+
dismissAfter?: number;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Live Activity result
|
|
486
|
+
*/
|
|
487
|
+
export interface LiveActivityResult {
|
|
488
|
+
/** Success flag */
|
|
489
|
+
success: boolean;
|
|
490
|
+
/** Activity ID (platform-specific) */
|
|
491
|
+
activityId?: string;
|
|
492
|
+
/** Associated job ID */
|
|
493
|
+
jobId?: string;
|
|
494
|
+
/** Error message if failed */
|
|
495
|
+
error?: string;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Push token event for Live Activity updates
|
|
500
|
+
*/
|
|
501
|
+
export interface LiveActivityPushTokenEvent {
|
|
502
|
+
/** Job ID */
|
|
503
|
+
jobId: string;
|
|
504
|
+
/** APNs push token */
|
|
505
|
+
token: string;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// ============================================
|
|
509
|
+
// Version & Compatibility
|
|
510
|
+
// ============================================
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* SDK version info
|
|
514
|
+
*/
|
|
515
|
+
export const SDK_VERSION = '0.1.0';
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Minimum API version required
|
|
519
|
+
*/
|
|
520
|
+
export const MIN_API_VERSION = '1.0.0';
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* SSE protocol version
|
|
524
|
+
*/
|
|
525
|
+
export const SSE_PROTOCOL_VERSION = '1.0';
|