@frontera-sdk/workflow 1.53.37 → 1.53.39
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 +7 -161
- package/dist/definition.d.ts +1 -0
- package/dist/definition.js +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.js +1 -0
- package/dist/workflow-client.d.ts +1 -0
- package/dist/workflow-client.js +1 -0
- package/package.json +21 -30
- package/src/definition.ts +0 -459
- package/src/types.ts +0 -484
- package/src/workflow-client.ts +0 -362
package/README.md
CHANGED
|
@@ -1,168 +1,14 @@
|
|
|
1
1
|
# @frontera-sdk/workflow
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
authors and publishes a definition, starts runs, reads the run tree, waits for a
|
|
5
|
-
run to settle, and manages versions and agent access. No React, no UI.
|
|
3
|
+
This package is part of the Frontera SDK, `@frontera-sdk/core`, and re-exports `@frontera-sdk/core/workflow`. It is published on every release so Apps that import `@frontera-sdk/workflow` keep working and keep getting fixes.
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
bun add @frontera-sdk/workflow @frontera-sdk/core
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Credential
|
|
12
|
-
|
|
13
|
-
Use a workspace key (`sk-ws-…`). Workflows are closed to organization keys, and
|
|
14
|
-
no capability on an organization key opens them. A call made with one fails
|
|
15
|
-
with a `FronteraError` whose `code` is `FORBIDDEN` and whose message says so.
|
|
16
|
-
|
|
17
|
-
## Run a workflow
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
import { FronteraClient } from '@frontera-sdk/core/client'
|
|
21
|
-
import { FronteraError } from '@frontera-sdk/core/errors'
|
|
22
|
-
import { WorkflowClient } from '@frontera-sdk/workflow/workflow-client'
|
|
23
|
-
|
|
24
|
-
const client = new FronteraClient({
|
|
25
|
-
apiBaseUrl: 'https://api.acme.example',
|
|
26
|
-
credential: { kind: 'apiKey', key: process.env.FRONTERA_WORKSPACE_KEY! },
|
|
27
|
-
})
|
|
28
|
-
const workflows = new WorkflowClient(client)
|
|
29
|
-
|
|
30
|
-
const { runId } = await workflows.run('supplier-onboarding', {
|
|
31
|
-
input: { supplierId: 'S-1042' },
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
const run = await workflows.waitForRun(runId, { timeoutMs: 5 * 60_000 })
|
|
35
|
-
console.log(run.status, run.output)
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
`waitForRun` polls every 1.5 seconds by default and resolves once the run is
|
|
39
|
-
`succeeded`, `failed` or `canceled`. On timeout it throws a `FronteraError` with
|
|
40
|
-
code `RUN_WAIT_TIMEOUT` and leaves the run alone.
|
|
41
|
-
|
|
42
|
-
### Cancel
|
|
43
|
-
|
|
44
|
-
```ts
|
|
45
|
-
const controller = new AbortController()
|
|
46
|
-
setTimeout(() => controller.abort(), 30_000)
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
await workflows.waitForRun(runId, { signal: controller.signal })
|
|
50
|
-
} catch (err) {
|
|
51
|
-
if (err instanceof FronteraError && err.code === 'ABORTED') {
|
|
52
|
-
const { status } = await workflows.cancel(runId)
|
|
53
|
-
console.log('cancelled, run is now', status)
|
|
54
|
-
} else {
|
|
55
|
-
throw err
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
A run that had already finished comes back from `cancel` with the status it
|
|
61
|
-
reached, not `canceled`.
|
|
62
|
-
|
|
63
|
-
### File inputs
|
|
64
|
-
|
|
65
|
-
Put a `File` in `input` and the request goes as multipart, with each file as its
|
|
66
|
-
own part. Nothing else changes.
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
await workflows.run('supplier-onboarding', {
|
|
70
|
-
input: { supplierId: 'S-1042', contract: new File([bytes], 'contract.pdf') },
|
|
71
|
-
})
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
An input of type `files` takes several files. Put a list of `File` values under
|
|
75
|
-
that input and each file goes as its own part under the input's name, in list
|
|
76
|
-
order.
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
await workflows.run('delivery-intake', {
|
|
80
|
-
input: {
|
|
81
|
-
carrier: 'globex-logistics',
|
|
82
|
-
scans: [new File([page1], 'page-1.pdf'), new File([page2], 'page-2.pdf')],
|
|
83
|
-
},
|
|
84
|
-
})
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
The list must hold only `File` values. A list that mixes `File` values with
|
|
88
|
-
references to files that are already uploaded is not sent as file parts, and
|
|
89
|
-
the service refuses it. An input takes 20 files unless the workflow sets another limit, and
|
|
90
|
-
50 at most.
|
|
91
|
-
|
|
92
|
-
## Author a workflow
|
|
93
|
-
|
|
94
|
-
A definition is a plain object typed as `WorkflowDefinition`, so the step kinds,
|
|
95
|
-
their parameters and the trigger forms are checked as you write them.
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
import type { WorkflowDefinition } from '@frontera-sdk/workflow/definition'
|
|
99
|
-
|
|
100
|
-
const definition: WorkflowDefinition = {
|
|
101
|
-
apiVersion: 'workflow/v1',
|
|
102
|
-
name: 'supplier-onboarding',
|
|
103
|
-
trigger: [{ kind: 'manual' }],
|
|
104
|
-
nodes: [
|
|
105
|
-
{ id: 'score', kind: 'function', params: { slug: 'score-supplier' } },
|
|
106
|
-
],
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const check = await workflows.push('supplier-onboarding', definition, { dryRun: true })
|
|
110
|
-
if (!check.ok) throw new Error(check.errors?.join('\n'))
|
|
111
|
-
|
|
112
|
-
const published = await workflows.push('supplier-onboarding', definition)
|
|
113
|
-
await workflows.promote('supplier-onboarding', published.version!.number)
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
A dry run validates and writes nothing, reporting every problem at once as
|
|
117
|
-
`ok: false` with `errors`. It also returns `grants`, the set of resources the
|
|
118
|
-
server derived from the definition. A slug that does not exist is created by the
|
|
119
|
-
first push.
|
|
120
|
-
|
|
121
|
-
The type describes the document after the server applies its defaults, so a
|
|
122
|
-
field with a default reads as required.
|
|
123
|
-
|
|
124
|
-
### Iterate on a draft
|
|
5
|
+
New code imports from `@frontera-sdk/core`:
|
|
125
6
|
|
|
126
7
|
```ts
|
|
127
|
-
|
|
128
|
-
|
|
8
|
+
// before
|
|
9
|
+
import { … } from '@frontera-sdk/workflow/…'
|
|
10
|
+
// after
|
|
11
|
+
import { … } from '@frontera-sdk/core/workflow/…'
|
|
129
12
|
```
|
|
130
13
|
|
|
131
|
-
|
|
132
|
-
edit. `testNode` runs one step. `copyVersion` opens a published version as a new
|
|
133
|
-
draft, `deleteVersion` discards one.
|
|
134
|
-
|
|
135
|
-
## Read the run tree
|
|
136
|
-
|
|
137
|
-
`runById(runId)` and `waitForRun` return a `RunTree`. `RunTree.nodes[]` has one
|
|
138
|
-
entry per executed step with its `status`, `input`, `output`, `error` and the
|
|
139
|
-
ids of any Function run, Action request, conversation or child run it produced.
|
|
140
|
-
Pass `depth: 'all'` to have those expanded inline, child runs included, so a
|
|
141
|
-
renderer needs no further request.
|
|
142
|
-
|
|
143
|
-
```ts
|
|
144
|
-
const run = await workflows.runById(runId, 'all')
|
|
145
|
-
for (const node of run.nodes) console.log(node.nodeId, node.status)
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
## Page through run history
|
|
149
|
-
|
|
150
|
-
`runs(slug, filters)` returns the newest rows first. Pass
|
|
151
|
-
`before: runCursor(lastRow)` to fetch the page after the one you have.
|
|
152
|
-
`workspaceRuns(filters)` does the same across every workflow in the workspace.
|
|
153
|
-
|
|
154
|
-
## Entry points
|
|
155
|
-
|
|
156
|
-
| Import | What it is |
|
|
157
|
-
|---|---|
|
|
158
|
-
| `@frontera-sdk/workflow/workflow-client` | `WorkflowClient` |
|
|
159
|
-
| `@frontera-sdk/workflow/definition` | `WorkflowDefinition` and the step and trigger types |
|
|
160
|
-
| `@frontera-sdk/workflow/types` | request and response types, `runCursor`, `isTerminalRunStatus` |
|
|
161
|
-
|
|
162
|
-
`@frontera-sdk/workflow/definition` is the same model the engine validates
|
|
163
|
-
against; the service reads these types back from this package, and a drift
|
|
164
|
-
between them fails its typecheck.
|
|
165
|
-
|
|
166
|
-
## License
|
|
167
|
-
|
|
168
|
-
Apache-2.0. See [LICENSE](./LICENSE).
|
|
14
|
+
Every subpath keeps its name: `@frontera-sdk/workflow/<subpath>` is `@frontera-sdk/core/workflow/<subpath>`. See the README of `@frontera-sdk/core`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@frontera-sdk/core/workflow/definition'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@frontera-sdk/core/workflow/definition'
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@frontera-sdk/core/workflow/types'
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@frontera-sdk/core/workflow/types'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@frontera-sdk/core/workflow/workflow-client'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@frontera-sdk/core/workflow/workflow-client'
|
package/package.json
CHANGED
|
@@ -1,48 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontera-sdk/workflow",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"description": "Typed headless client for starting, inspecting, waiting on and cancelling Frontera workflow runs from a script or backend. Published as @frontera-sdk/core/workflow; this package re-exports it.",
|
|
4
|
+
"version": "1.53.39",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
5
7
|
"keywords": [
|
|
6
8
|
"frontera",
|
|
7
9
|
"workflow",
|
|
8
10
|
"sdk"
|
|
9
11
|
],
|
|
10
|
-
"
|
|
11
|
-
"type": "module",
|
|
12
|
-
"files": [
|
|
13
|
-
"src",
|
|
14
|
-
"!src/__tests__",
|
|
15
|
-
"!src/**/*.test.ts",
|
|
16
|
-
"README.md",
|
|
17
|
-
"LICENSE"
|
|
18
|
-
],
|
|
19
|
-
"publishConfig": {
|
|
20
|
-
"access": "public"
|
|
21
|
-
},
|
|
12
|
+
"sideEffects": false,
|
|
22
13
|
"exports": {
|
|
23
14
|
"./definition": {
|
|
24
|
-
"types": "./
|
|
25
|
-
"
|
|
15
|
+
"types": "./dist/definition.d.ts",
|
|
16
|
+
"default": "./dist/definition.js"
|
|
26
17
|
},
|
|
27
18
|
"./types": {
|
|
28
|
-
"types": "./
|
|
29
|
-
"
|
|
19
|
+
"types": "./dist/types.d.ts",
|
|
20
|
+
"default": "./dist/types.js"
|
|
30
21
|
},
|
|
31
22
|
"./workflow-client": {
|
|
32
|
-
"types": "./
|
|
33
|
-
"
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
"scripts": {
|
|
37
|
-
"test": "bun test",
|
|
38
|
-
"typecheck": "../../node_modules/typescript7/bin/tsc --noEmit"
|
|
23
|
+
"types": "./dist/workflow-client.d.ts",
|
|
24
|
+
"default": "./dist/workflow-client.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
39
27
|
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
],
|
|
40
33
|
"dependencies": {
|
|
41
|
-
"@frontera-sdk/core": "1.53.
|
|
42
|
-
"@frontera-sdk/functions": "1.53.37"
|
|
34
|
+
"@frontera-sdk/core": "1.53.39"
|
|
43
35
|
},
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"typescript": "^5.9.3"
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
47
38
|
}
|
|
48
39
|
}
|