@frontera-sdk/workflow 1.53.38 → 1.53.40

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 DELETED
@@ -1,484 +0,0 @@
1
- import type { InputsSchema } from '@frontera-sdk/functions'
2
-
3
- export type WorkflowRunStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'canceled'
4
- export type WorkflowNodeStatus = 'pending' | 'running' | 'succeeded' | 'failed' | 'skipped' | 'canceled'
5
-
6
- export const TERMINAL_RUN_STATUSES: ReadonlySet<WorkflowRunStatus> = new Set<WorkflowRunStatus>([
7
- 'succeeded',
8
- 'failed',
9
- 'canceled',
10
- ])
11
-
12
- export function isTerminalRunStatus(status: string): boolean {
13
- return TERMINAL_RUN_STATUSES.has(status as WorkflowRunStatus)
14
- }
15
-
16
- /** A row of `GET /v1/workflows`. */
17
- export interface WorkflowSummary {
18
- id: string
19
- slug: string
20
- enabled: boolean
21
- description: string | null
22
- liveVersion: number | null
23
- latestDraftNumber: number | null
24
- versionCount: number
25
- runCount: number
26
- lastRunAt: string | null
27
- lastRunStatus: WorkflowRunStatus | null
28
- triggerKinds: string[]
29
- cron: string | null
30
- subjectApiName: string | null
31
- subjectLabel: string | null
32
- /** One per webhook trigger. Absent from a service that predates webhooks. */
33
- webhooks?: WorkflowWebhook[]
34
- }
35
-
36
- export interface WorkflowWebhook {
37
- methods: string[]
38
- path: string
39
- auth: string
40
- respond: string
41
- url: string
42
- testUrl: string
43
- }
44
-
45
- /** The whole workflow row, which the two create routes answer with. */
46
- export interface Workflow {
47
- id: string
48
- orgId: string
49
- workspaceId: string
50
- slug: string
51
- displayName: string | null
52
- subjectObjectTypeId: string | null
53
- enabled: boolean
54
- liveVersionId: string | null
55
- testHookVersionId: string | null
56
- testHookUntil: string | null
57
- createdBy: string
58
- createdAt: string
59
- }
60
-
61
- export interface CreateWorkflowInput {
62
- /** Lowercase, digits and hyphens; unique in the workspace. */
63
- slug: string
64
- /** A Blueprint object type id. Every run is then about one of its objects. */
65
- subjectObjectTypeId?: string
66
- }
67
-
68
- /** `createDraft`: the workflow and the empty draft made with it, in one write. */
69
- export interface WorkflowDraft {
70
- workflow: Workflow
71
- version: { id: string; number: number; status: WorkflowVersionStatus }
72
- }
73
-
74
- /** What `rename` answers with. The slug does not move with the name. */
75
- export interface RenameResult {
76
- id: string
77
- slug: string
78
- displayName: string
79
- }
80
-
81
- export interface EnabledResult {
82
- id: string
83
- enabled: boolean
84
- }
85
-
86
- export interface WorkflowDeleteResult {
87
- deleted: boolean
88
- runsDeleted: number
89
- }
90
-
91
- /** Answered by the two routes that remove a version or a binding. */
92
- export interface DeletedResult {
93
- deleted: boolean
94
- }
95
-
96
- /** draft | live | draining | retired */
97
- export type WorkflowVersionStatus = 'draft' | 'live' | 'draining' | 'retired'
98
-
99
- /** A row of `GET /v1/workflows/:slug/versions`, narrowed to what a listing shows. */
100
- export interface VersionSummary {
101
- id: string
102
- number: number
103
- status: WorkflowVersionStatus
104
- createdAt: string
105
- createdVia: string | null
106
- }
107
-
108
- /** The whole row `GET /v1/workflows/:slug/versions/:n` answers with. */
109
- export interface WorkflowVersion {
110
- id: string
111
- workflowId: string
112
- number: number
113
- status: WorkflowVersionStatus
114
- definition: Record<string, unknown>
115
- grants: string[]
116
- lineage: LineageEdge[]
117
- inputSchema: InputsSchema | null
118
- /** Presentation only; null means none saved. */
119
- layout?: WorkflowLayout | null
120
- createdVia: string | null
121
- createdBy: string
122
- createdAt: string
123
- }
124
-
125
- /** Canvas card positions keyed by node id. Never read by the engine. */
126
- export type WorkflowLayout = Record<string, { x: number; y: number }>
127
-
128
- /** What `saveLayout` answers with. */
129
- export interface LayoutResult {
130
- versionId: string
131
- number: number
132
- layout: WorkflowLayout | null
133
- }
134
-
135
- /**
136
- * One step run on its own against the draft's newest test data.
137
- *
138
- * `ok: false` is the step failing, not the request failing — a 200 carries it.
139
- * `preview` marks a kind that only reports what it would do, so its output is
140
- * never what a real run would put in `$steps`.
141
- */
142
- export type NodeTestResult =
143
- | { ok: true; nodeId: string; kind: string; mocked: boolean; preview?: boolean; input: unknown; output: unknown }
144
- | {
145
- ok: false
146
- nodeId: string
147
- kind: string
148
- mocked: boolean
149
- preview?: boolean
150
- input: unknown
151
- error: Record<string, unknown>
152
- }
153
-
154
- /** One step's newest stored step test, as `stepTests` lists them. */
155
- export interface StepTest {
156
- nodeId: string
157
- kind: string
158
- status: 'succeeded' | 'failed'
159
- mocked: boolean
160
- preview: boolean
161
- input: unknown
162
- output: unknown
163
- error: Record<string, unknown> | null
164
- testedAt: string
165
- }
166
-
167
- /** How long the draft's test webhook URL stays armed, ISO. */
168
- export interface WebhookTestWindow {
169
- until: string
170
- }
171
-
172
- /**
173
- * What a push answers with.
174
- *
175
- * `ok: false` is a result, not a transport failure, and only on a dry run. A
176
- * real push that fails validation comes back as a 400 whose
177
- * `FronteraError.details.errors` lists the reasons.
178
- */
179
- export interface PushResult {
180
- ok: boolean
181
- errors?: string[]
182
- workflowId?: string
183
- version?: { id: string; number: number; status: WorkflowVersionStatus }
184
- grants?: string[]
185
- lineage?: LineageEdge[]
186
- }
187
-
188
- export interface PromoteResult {
189
- workflowId: string
190
- versionId: string
191
- /** True when the version was already live and nothing changed. */
192
- alreadyLive: boolean
193
- }
194
-
195
- export interface LineageEdge {
196
- kind: string
197
- resourceKind: string
198
- resourceId: string
199
- label?: string | null
200
- property?: string | null
201
- nodeId?: string | null
202
- }
203
-
204
- export interface VersionLineage {
205
- version: number
206
- status: WorkflowVersionStatus
207
- grants: string[]
208
- lineage: LineageEdge[]
209
- }
210
-
211
- export interface RunRequest {
212
- /**
213
- * A `File` value here is sent as its own multipart part, named after the
214
- * `file` input it fills. A list of `File`s fills a `files` input: one part
215
- * per file, all under that input's name. Everything else travels as JSON.
216
- */
217
- input?: Record<string, unknown>
218
- subject?: { pk: string }
219
- /** A version number; without it the live version runs. */
220
- version?: number
221
- /** `test` is allowed only against a draft. */
222
- source?: 'manual' | 'test'
223
- }
224
-
225
- export interface RunResult {
226
- runId: string
227
- versionNumber: number
228
- /** True when an idempotency key matched a run that already existed. */
229
- reused?: boolean
230
- }
231
-
232
- /** A row of `GET /v1/workflows/:slug/runs`. */
233
- export interface RunSummary {
234
- id: string
235
- orgId: string
236
- workflowId: string
237
- versionId: string
238
- status: WorkflowRunStatus
239
- triggerSource: string
240
- triggerIndex: number | null
241
- triggeredBy: string | null
242
- subjectObjectTypeId: string | null
243
- subjectPk: string | null
244
- rootRunId: string | null
245
- parentRunId: string | null
246
- depth: number
247
- input: Record<string, unknown>
248
- output: unknown
249
- error: Record<string, unknown> | null
250
- nodeCalls: number
251
- conversationId: string | null
252
- idempotencyKey: string | null
253
- invocationDepth: number
254
- iteration: { nodePath: string; nodeId: string; index: number; item: unknown; outerSteps: Record<string, unknown> } | null
255
- startedAt: string
256
- endedAt: string | null
257
- versionNumber: number
258
- workflowSlug: string
259
- workflowDisplayName: string | null
260
- triggeredByName: string | null
261
- triggeredByEmail: string | null
262
- subjectLabel: string | null
263
- }
264
-
265
- export type RunListFilters = {
266
- /** `live` hides test runs; `test` shows only them. */
267
- source?: 'live' | 'test'
268
- status?: WorkflowRunStatus
269
- /** Default 50, maximum 200. */
270
- limit?: number
271
- /** Keyset cursor `<startedAt ISO>|<run id>`; see `runCursor`. */
272
- before?: string
273
- from?: string
274
- to?: string
275
- }
276
-
277
- /**
278
- * `workspaceRuns` filters: the per-workflow set plus the slug that narrows to
279
- * one workflow. A `type`, not an `interface`, because it is passed as a query
280
- * bag and only a type alias carries an implicit index signature.
281
- */
282
- export type WorkspaceRunListFilters = RunListFilters & {
283
- /** A workflow slug. Without it, every workflow in the workspace is included. */
284
- workflow?: string
285
- }
286
-
287
- export type RunMetricsPeriod = '24h' | '7d' | '30d' | '90d'
288
-
289
- export type RunMetricsQuery = {
290
- /** Default `7d`. */
291
- period?: RunMetricsPeriod
292
- /** A workflow slug; without it the whole workspace is counted. */
293
- workflow?: string
294
- }
295
-
296
- /** Run counts over one window. Test runs and forEach children are excluded. */
297
- export interface RunMetricsTotals {
298
- runs: number
299
- succeeded: number
300
- failed: number
301
- canceled: number
302
- running: number
303
- /** Succeeded over finished. Null when nothing finished in the window. */
304
- successRate: number | null
305
- p50DurationMs: number | null
306
- p95DurationMs: number | null
307
- nodeCalls: number
308
- lastRunAt: string | null
309
- }
310
-
311
- export interface RunMetricsByWorkflow extends RunMetricsTotals {
312
- workflowId: string
313
- workflowSlug: string
314
- }
315
-
316
- export interface RunVolumeBucket {
317
- /** Bucket start, ISO. */
318
- at: string
319
- succeeded: number
320
- failed: number
321
- }
322
-
323
- export interface RunMetrics {
324
- period: RunMetricsPeriod
325
- /** The current window, ISO; `to` is exclusive. `previous` is the span before it. */
326
- range: { from: string; to: string }
327
- granularity: 'hour' | 'day' | 'week' | 'month'
328
- current: RunMetricsTotals
329
- previous: RunMetricsTotals
330
- buckets: RunVolumeBucket[]
331
- byWorkflow: RunMetricsByWorkflow[]
332
- }
333
-
334
- /** A step output stored by reference, read back whole. */
335
- export interface NodeOutput {
336
- id: string
337
- runId: string
338
- nodeId: string
339
- output: unknown
340
- }
341
-
342
- /** `run` implies `read`; `read` grants the observation tools and no run tool. */
343
- export type BindingAccess = 'read' | 'run'
344
-
345
- /** One agent's standing permission on one workflow, from the workflow's side. */
346
- export interface WorkflowBinding {
347
- agentId: string
348
- agentSlug: string
349
- agentName: string
350
- enabled: boolean
351
- access: BindingAccess
352
- requiresApproval: boolean
353
- waitSeconds: number
354
- createdBy: string
355
- createdAt: string
356
- }
357
-
358
- /**
359
- * The same permission from the agent's side, plus whether it currently grants
360
- * anything: a row can exist while nothing is promoted, or while the live
361
- * version declares a redacted input an agent may not supply.
362
- */
363
- export interface AgentBinding {
364
- workflowId: string
365
- workflowSlug: string
366
- enabled: boolean
367
- access: BindingAccess
368
- requiresApproval: boolean
369
- waitSeconds: number
370
- runnable: boolean
371
- /** Why not, when `runnable` is false. */
372
- inertReason: 'no_live_version' | 'input_redacted' | 'disabled' | 'read_only' | null
373
- }
374
-
375
- /** Every field is optional: an omitted one keeps what the row already holds. */
376
- export interface BindAgentInput {
377
- enabled?: boolean
378
- /** Defaults to `run` on a binding that does not exist yet. */
379
- access?: BindingAccess
380
- requiresApproval?: boolean
381
- /** 5 to 300; defaults to 90. */
382
- waitSeconds?: number
383
- }
384
-
385
- /** The `before` cursor for the page after `run`, the last row of the current page. */
386
- export function runCursor(run: Pick<RunSummary, 'startedAt' | 'id'>): string {
387
- return `${run.startedAt}|${run.id}`
388
- }
389
-
390
- export interface RunTreeNode {
391
- id: string
392
- nodePath: string
393
- nodeId: string
394
- kind: string
395
- status: WorkflowNodeStatus
396
- attempt: number
397
- input: unknown
398
- output: unknown
399
- error: unknown
400
- startedAt: string
401
- endedAt: string | null
402
- functionRunId: string | null
403
- actionRequestId: string | null
404
- conversationId: string | null
405
- childRunId: string | null
406
- /** Present with `depth: 'all'`. */
407
- functionRun?: {
408
- id: string
409
- slug: string | null
410
- status: string
411
- startedAt: string
412
- endedAt: string | null
413
- result: unknown
414
- errorMessage: string | null
415
- steps: Array<{
416
- id: string
417
- seq: number
418
- kind: string
419
- label: string
420
- status: string
421
- durationMs: number | null
422
- stepName: string | null
423
- }>
424
- } | null
425
- /** Present with `depth: 'all'`. */
426
- actionRequest?: {
427
- id: string
428
- lifecycle: string
429
- createdAt: string
430
- attempts: Array<{ id: string; createdAt: string }>
431
- approvals: Array<{ id: string; decision: string; createdAt: string }>
432
- outcomes: Array<{ id: string; certainty: string; businessOutcomeCode: string | null; createdAt: string }>
433
- } | null
434
- /** Present with `depth: 'all'`. */
435
- conversation?: {
436
- id: string
437
- status: string | null
438
- createdAt: string | null
439
- messages: Array<{ id: string; role: string; createdAt: string | null }>
440
- } | null
441
- /** Present with `depth: 'all'`. */
442
- childRun?: RunTree | null
443
- }
444
-
445
- export interface RunTree {
446
- id: string
447
- workflowId: string
448
- slug: string
449
- versionId: string
450
- versionNumber: number | null
451
- status: WorkflowRunStatus
452
- triggerSource: string
453
- triggeredBy: string | null
454
- triggeredByName: string | null
455
- subject: { objectTypeId: string; pk: string; apiName: string | null; label: string | null } | null
456
- rootRunId: string | null
457
- parentRunId: string | null
458
- depth: number
459
- input: Record<string, unknown>
460
- output: unknown
461
- error: unknown
462
- nodeCalls: number
463
- startedAt: string
464
- endedAt: string | null
465
- nodes: RunTreeNode[]
466
- /** Only on the root of the tree, and only for a webhook delivery. */
467
- triggerCapture?: unknown
468
- }
469
-
470
- export interface CancelResult {
471
- runId: string
472
- status: WorkflowRunStatus
473
- }
474
-
475
- export interface WaitForRunOptions {
476
- /** Default 1500. */
477
- intervalMs?: number
478
- /** Default 10 minutes. The run is left running on timeout. */
479
- timeoutMs?: number
480
- signal?: AbortSignal
481
- /** Default `'run'`. */
482
- depth?: 'run' | 'all'
483
- onPoll?: (run: RunTree) => void
484
- }