@requence/task 1.0.0-alpha.5 → 1.0.0-alpha.51

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.
Files changed (108) hide show
  1. package/CHANGELOG.md +276 -0
  2. package/README.md +383 -0
  3. package/build/chunk-b4h2we9a.js +35 -0
  4. package/build/chunk-b4h2we9a.js.map +10 -0
  5. package/build/cli.js +21 -4874
  6. package/build/cli.js.map +4 -37
  7. package/build/index.js +1011 -233
  8. package/build/index.js.map +22 -8
  9. package/build/types/helpers/src/files/RequenceFile.d.ts +40 -0
  10. package/build/types/helpers/src/files/RequenceFile.d.ts.map +1 -0
  11. package/build/types/helpers/src/files/RequenceStream.d.ts +32 -0
  12. package/build/types/helpers/src/files/RequenceStream.d.ts.map +1 -0
  13. package/build/types/helpers/src/files/fileObject.d.ts +16 -0
  14. package/build/types/helpers/src/files/fileObject.d.ts.map +1 -0
  15. package/build/types/helpers/src/files/index.d.ts +7 -0
  16. package/build/types/helpers/src/files/index.d.ts.map +1 -0
  17. package/build/types/helpers/src/files/isValidMimeType.d.ts +5 -0
  18. package/build/types/helpers/src/files/isValidMimeType.d.ts.map +1 -0
  19. package/build/types/helpers/src/files/mapOutput.d.ts +10 -0
  20. package/build/types/helpers/src/files/mapOutput.d.ts.map +1 -0
  21. package/build/types/helpers/src/files/streamObject.d.ts +14 -0
  22. package/build/types/helpers/src/files/streamObject.d.ts.map +1 -0
  23. package/build/types/helpers/src/files/types.d.ts +4 -0
  24. package/build/types/helpers/src/files/types.d.ts.map +1 -0
  25. package/build/types/helpers/src/index.d.ts +12 -6
  26. package/build/types/helpers/src/index.d.ts.map +1 -1
  27. package/build/types/helpers/src/jsonschema/mapSchema.d.ts +20 -0
  28. package/build/types/helpers/src/jsonschema/mapSchema.d.ts.map +1 -0
  29. package/build/types/helpers/src/jsonschema/types.d.ts +13 -0
  30. package/build/types/helpers/src/jsonschema/types.d.ts.map +1 -0
  31. package/build/types/helpers/src/jsonschema/validate.d.ts +32 -0
  32. package/build/types/helpers/src/jsonschema/validate.d.ts.map +1 -0
  33. package/build/types/helpers/src/jsonschema/zod.d.ts +17 -0
  34. package/build/types/helpers/src/jsonschema/zod.d.ts.map +1 -0
  35. package/build/types/helpers/src/protocol/NodeTree.d.ts +510 -0
  36. package/build/types/helpers/src/protocol/NodeTree.d.ts.map +1 -0
  37. package/build/types/helpers/src/protocol/command.d.ts +507 -0
  38. package/build/types/helpers/src/protocol/command.d.ts.map +1 -0
  39. package/build/types/helpers/src/protocol/helpers.d.ts +7 -0
  40. package/build/types/helpers/src/protocol/helpers.d.ts.map +1 -0
  41. package/build/types/helpers/src/protocol/index.d.ts +8 -0
  42. package/build/types/helpers/src/protocol/index.d.ts.map +1 -0
  43. package/build/types/helpers/src/protocol/nodeType.d.ts +181 -0
  44. package/build/types/helpers/src/protocol/nodeType.d.ts.map +1 -0
  45. package/build/types/helpers/src/protocol/taskOptions.d.ts +23 -0
  46. package/build/types/helpers/src/protocol/taskOptions.d.ts.map +1 -0
  47. package/build/types/helpers/src/protocol/templateNodeTypes.d.ts +267 -0
  48. package/build/types/helpers/src/protocol/templateNodeTypes.d.ts.map +1 -0
  49. package/build/types/helpers/src/protocol/treeNodes.d.ts +874 -0
  50. package/build/types/helpers/src/protocol/treeNodes.d.ts.map +1 -0
  51. package/build/types/helpers/src/protocol/update.d.ts +406 -0
  52. package/build/types/helpers/src/protocol/update.d.ts.map +1 -0
  53. package/build/types/helpers/src/utils/callbackToAsyncIterator.d.ts +3 -0
  54. package/build/types/helpers/src/utils/callbackToAsyncIterator.d.ts.map +1 -0
  55. package/build/types/helpers/src/utils/clone.d.ts +3 -0
  56. package/build/types/helpers/src/utils/clone.d.ts.map +1 -0
  57. package/build/types/helpers/src/utils/createObjectProxy.d.ts +2 -0
  58. package/build/types/helpers/src/utils/createObjectProxy.d.ts.map +1 -0
  59. package/build/types/helpers/src/utils/debounce.d.ts +4 -0
  60. package/build/types/helpers/src/utils/debounce.d.ts.map +1 -0
  61. package/build/types/helpers/src/utils/guards.d.ts +3 -0
  62. package/build/types/helpers/src/utils/guards.d.ts.map +1 -0
  63. package/build/types/helpers/src/utils/mapData.d.ts +18 -0
  64. package/build/types/helpers/src/utils/mapData.d.ts.map +1 -0
  65. package/build/types/helpers/src/{utils.d.ts → utils/matchSchema.d.ts} +2 -2
  66. package/build/types/helpers/src/utils/matchSchema.d.ts.map +1 -0
  67. package/build/types/helpers/src/utils/obfuscate.d.ts.map +1 -0
  68. package/build/types/helpers/src/utils/obj.d.ts +4 -0
  69. package/build/types/helpers/src/utils/obj.d.ts.map +1 -0
  70. package/build/types/helpers/src/utils/requenceCallback.d.ts +17 -0
  71. package/build/types/helpers/src/utils/requenceCallback.d.ts.map +1 -0
  72. package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts +8 -0
  73. package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts.map +1 -0
  74. package/build/types/helpers/src/utils/types.d.ts +7 -0
  75. package/build/types/helpers/src/utils/types.d.ts.map +1 -0
  76. package/build/types/task/src/abortTask.d.ts +8 -0
  77. package/build/types/task/src/abortTask.d.ts.map +1 -0
  78. package/build/types/task/src/ackTask.d.ts +7 -0
  79. package/build/types/task/src/ackTask.d.ts.map +1 -0
  80. package/build/types/task/src/createTask.d.ts +14 -103
  81. package/build/types/task/src/createTask.d.ts.map +1 -1
  82. package/build/types/task/src/getTask.d.ts +26 -0
  83. package/build/types/task/src/getTask.d.ts.map +1 -0
  84. package/build/types/task/src/index.d.ts +7 -1
  85. package/build/types/task/src/index.d.ts.map +1 -1
  86. package/build/types/task/src/protectTask.d.ts +7 -0
  87. package/build/types/task/src/protectTask.d.ts.map +1 -0
  88. package/build/types/task/src/recreateTask.d.ts +10 -0
  89. package/build/types/task/src/recreateTask.d.ts.map +1 -0
  90. package/build/types/task/src/types.d.ts +196 -941
  91. package/build/types/task/src/types.d.ts.map +1 -1
  92. package/build/types/task/src/utils/getAccessToken.d.ts.map +1 -1
  93. package/build/types/task/src/watchTasks.d.ts +13 -97
  94. package/build/types/task/src/watchTasks.d.ts.map +1 -1
  95. package/package.json +12 -7
  96. package/build/chunk-6pjtq0hg.js +0 -66
  97. package/build/chunk-6pjtq0hg.js.map +0 -12
  98. package/build/types/helpers/src/clone.d.ts +0 -3
  99. package/build/types/helpers/src/clone.d.ts.map +0 -1
  100. package/build/types/helpers/src/createObjectProxy.d.ts +0 -2
  101. package/build/types/helpers/src/createObjectProxy.d.ts.map +0 -1
  102. package/build/types/helpers/src/createRemotePromise.d.ts +0 -7
  103. package/build/types/helpers/src/createRemotePromise.d.ts.map +0 -1
  104. package/build/types/helpers/src/obfuscate.d.ts.map +0 -1
  105. package/build/types/helpers/src/utils.d.ts.map +0 -1
  106. package/build/types/task/src/utils/callbackToAsyncIterator.d.ts +0 -5
  107. package/build/types/task/src/utils/callbackToAsyncIterator.d.ts.map +0 -1
  108. /package/build/types/helpers/src/{obfuscate.d.ts → utils/obfuscate.d.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,281 @@
1
1
  # @requence/task
2
2
 
3
+ ## 1.0.0-alpha.51
4
+
5
+ ### Patch Changes
6
+
7
+ - 7fdea3b: lint
8
+
9
+ ## 1.0.0-alpha.50
10
+
11
+ ### Patch Changes
12
+
13
+ - 6922266: trace ids
14
+
15
+ ## 1.0.0-alpha.49
16
+
17
+ ### Patch Changes
18
+
19
+ - c7d1c6b: qos
20
+
21
+ ## 1.0.0-alpha.48
22
+
23
+ ### Minor Changes
24
+
25
+ - ad9368b: Fix mapped task priority float validation error on backend and add `finalized()` method for cheap task finalization / validation without full progress monitoring.
26
+
27
+ ## 1.0.0-alpha.47
28
+
29
+ ### Patch Changes
30
+
31
+ - b8d9c18: fix rounding bug for priority
32
+
33
+ ## 1.0.0-alpha.46
34
+
35
+ ### Patch Changes
36
+
37
+ - eedd227: added task protect endpoint
38
+
39
+ ## 1.0.0-alpha.45
40
+
41
+ ### Patch Changes
42
+
43
+ - 3a4654c: road to 1.0
44
+
45
+ ## 1.0.0-alpha.44
46
+
47
+ ### Patch Changes
48
+
49
+ - a57eb9d: correctly define properties
50
+
51
+ ## 1.0.0-alpha.43
52
+
53
+ ### Patch Changes
54
+
55
+ - d68fa16: don't reject url and response promise when not needed
56
+
57
+ ## 1.0.0-alpha.42
58
+
59
+ ### Patch Changes
60
+
61
+ - 5dd34ff: there is no type
62
+
63
+ ## 1.0.0-alpha.41
64
+
65
+ ### Patch Changes
66
+
67
+ - 409cb37: make statusText accessible
68
+
69
+ ## 1.0.0-alpha.40
70
+
71
+ ### Patch Changes
72
+
73
+ - e0f2d73: recreateTask api
74
+
75
+ ## 1.0.0-alpha.39
76
+
77
+ ### Patch Changes
78
+
79
+ - 230f9b9: don't reject promises that are not queried
80
+
81
+ ## 1.0.0-alpha.38
82
+
83
+ ### Patch Changes
84
+
85
+ - bfcb99d: update deployment
86
+
87
+ ## 1.0.0-alpha.37
88
+
89
+ ### Patch Changes
90
+
91
+ - 574829e: improved task service connection, fixed access token
92
+
93
+ ## 1.0.0-alpha.36
94
+
95
+ ### Patch Changes
96
+
97
+ - a068600: status should be UPPERCASE
98
+
99
+ ## 1.0.0-alpha.35
100
+
101
+ ### Patch Changes
102
+
103
+ - 2b0e652: allow task filtering for watch all
104
+
105
+ ## 1.0.0-alpha.34
106
+
107
+ ### Patch Changes
108
+
109
+ - 8ed981e: linting
110
+
111
+ ## 1.0.0-alpha.33
112
+
113
+ ### Patch Changes
114
+
115
+ - e4e137b: better auto reconnect
116
+
117
+ ## 1.0.0-alpha.32
118
+
119
+ ### Patch Changes
120
+
121
+ - c2e0e72: added root task id
122
+
123
+ ## 1.0.0-alpha.31
124
+
125
+ ### Patch Changes
126
+
127
+ - 4952eff: python types & bug fixes
128
+
129
+ ## 1.0.0-alpha.30
130
+
131
+ ### Patch Changes
132
+
133
+ - bda4a97: don't use wrong response for error handling
134
+
135
+ ## 1.0.0-alpha.29
136
+
137
+ ### Patch Changes
138
+
139
+ - e75841f: add missing callbacks
140
+
141
+ ## 1.0.0-alpha.28
142
+
143
+ ### Patch Changes
144
+
145
+ - f2a63fa: added missing type
146
+
147
+ ## 1.0.0-alpha.27
148
+
149
+ ### Patch Changes
150
+
151
+ - 63e3195: rerelease task package
152
+
153
+ ## 1.0.0-alpha.26
154
+
155
+ ### Patch Changes
156
+
157
+ - 14caa43: correctly transport task abort event
158
+
159
+ ## 1.0.0-alpha.25
160
+
161
+ ### Patch Changes
162
+
163
+ - 0c320ec: added task name and exit name infos
164
+
165
+ ## 1.0.0-alpha.24
166
+
167
+ ### Patch Changes
168
+
169
+ - 6c441e3: ensure task id gets resolved as early as possible
170
+
171
+ ## 1.0.0-alpha.23
172
+
173
+ ### Patch Changes
174
+
175
+ - 8743124: fixed type generation & schema resolution
176
+
177
+ ## 1.0.0-alpha.22
178
+
179
+ ### Patch Changes
180
+
181
+ - 817e7ee: granular data / sub tasks / operator logic
182
+
183
+ ## 1.0.0-alpha.21
184
+
185
+ ### Patch Changes
186
+
187
+ - bd65a2c: improved logging
188
+
189
+ ## 1.0.0-alpha.20
190
+
191
+ ### Patch Changes
192
+
193
+ - e83bf22: improve task updates
194
+
195
+ ## 1.0.0-alpha.19
196
+
197
+ ### Patch Changes
198
+
199
+ - 831c549: added abort reason
200
+
201
+ ## 1.0.0-alpha.18
202
+
203
+ ### Patch Changes
204
+
205
+ - 3e78516: allow task abort in task package
206
+
207
+ ## 1.0.0-alpha.17
208
+
209
+ ### Patch Changes
210
+
211
+ - 0a7c05f: include output name in update info
212
+
213
+ ## 1.0.0-alpha.16
214
+
215
+ ### Patch Changes
216
+
217
+ - 92ef7aa: include node info in all node related task updates
218
+
219
+ ## 1.0.0-alpha.15
220
+
221
+ ### Patch Changes
222
+
223
+ - 45d26fc: fixed task access token retrieval
224
+
225
+ ## 1.0.0-alpha.14
226
+
227
+ ### Patch Changes
228
+
229
+ - 3a5e3e2: allow more access token options
230
+
231
+ ## 1.0.0-alpha.13
232
+
233
+ ### Patch Changes
234
+
235
+ - dc413ab: deps update
236
+
237
+ ## 1.0.0-alpha.12
238
+
239
+ ### Patch Changes
240
+
241
+ - 77bc2ed: improved task creation and event order
242
+
243
+ ## 1.0.0-alpha.11
244
+
245
+ ### Patch Changes
246
+
247
+ - 300f7de: temporary upload as formdata
248
+
249
+ ## 1.0.0-alpha.10
250
+
251
+ ### Patch Changes
252
+
253
+ - 9dcaeae: fixed dependencies
254
+
255
+ ## 1.0.0-alpha.9
256
+
257
+ ### Patch Changes
258
+
259
+ - 1df3d43: improved typing
260
+
261
+ ## 1.0.0-alpha.8
262
+
263
+ ### Patch Changes
264
+
265
+ - 679cbaf: streams
266
+
267
+ ## 1.0.0-alpha.7
268
+
269
+ ### Patch Changes
270
+
271
+ - a464543: improved file matching algorithm
272
+
273
+ ## 1.0.0-alpha.6
274
+
275
+ ### Patch Changes
276
+
277
+ - 1d847ee: improved files handling
278
+
3
279
  ## 1.0.0-alpha.5
4
280
 
5
281
  ### Patch Changes
package/README.md ADDED
@@ -0,0 +1,383 @@
1
+ # @requence/task
2
+
3
+ This package lets you start and monitor Requence tasks programmatically from a TypeScript / Bun application.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @requence/task
9
+ ```
10
+
11
+ ## Authentication
12
+
13
+ Every call to `createTask` requires an **access token** — either a personal access token or a scoped token created at the organization, group, or project level.
14
+
15
+ The token is resolved in this order:
16
+
17
+ 1. `accessToken` option passed to `createTask()`
18
+ 2. `REQUENCE_TASK_ACCESS_TOKEN` or `REQUENCE_ACCESS_TOKEN` environment variable
19
+ 3. `requence.task.accessToken` or `requence.accessToken` in `package.json`
20
+
21
+ ```bash
22
+ REQUENCE_ACCESS_TOKEN=your-token bun run index.ts
23
+ ```
24
+
25
+ ## Basic Usage
26
+
27
+ ```typescript
28
+ import { createTask } from '@requence/task'
29
+
30
+ const result = await createTask({
31
+ taskTemplate: 'my-template',
32
+ input: { name: 'World' },
33
+ })
34
+
35
+ console.log(result.result) // The final output of the task
36
+ ```
37
+
38
+ > **Note:** `await createTask(...)` waits for the **entire task** to finish. If you don't need to block, omit the `await` and use the returned task handle instead.
39
+
40
+ ## Task Handle
41
+
42
+ `createTask` returns a **task handle** immediately. You can use it to access task metadata without waiting for the task to complete:
43
+
44
+ ```typescript
45
+ const task = createTask({ taskTemplate: 'my-template', input: {} })
46
+
47
+ const taskId = await task.getTaskId() // Resolves as soon as the task is created
48
+ const taskUrl = await task.getTaskUrl() // URL to view the task in the Requence UI
49
+
50
+ await task.abort('No longer needed') // Abort the running task
51
+ await task.protect() // Protect the task from automatic cleanup
52
+
53
+ // Await the final result when you need it
54
+ const result = await task
55
+ ```
56
+
57
+ The task handle is also an **AsyncIterable** — iterate over it to stream updates as the task executes.
58
+
59
+ ### Awaiting Finalization (Cheap Monitoring)
60
+
61
+ By default, awaiting the result or iterating the handle starts full SSE monitoring. If you only need to confirm that the task passed input validation and started on the backend — without tracking every node — await `task.finalized()`:
62
+
63
+ ```typescript
64
+ const task = createTask({ taskTemplate: 'my-template', input: { /* ... */ } })
65
+
66
+ try {
67
+ const taskId = await task.finalized()
68
+ console.log(`Task ${taskId} is running in the background`)
69
+ } catch (error) {
70
+ console.error('Validation failed:', error.message)
71
+ }
72
+ ```
73
+
74
+ `finalized()` resolves with the task ID on success, or rejects with a `TaskError` if the task cannot be created (e.g. schema validation failure).
75
+
76
+ ## Options
77
+
78
+ | Option | Type | Default | Description |
79
+ |---|---|---|---|
80
+ | `taskTemplate` | `string` | — | **Required.** Name of the task template |
81
+ | `input` | `unknown` | — | Required when the template defines an input schema |
82
+ | `name` | `string` | — | Human-readable task name shown in the UI |
83
+ | `priority` | `number` | `2` | Priority `0` (lowest) to `4` (highest) |
84
+ | `accessToken` | `string` | — | Access token (falls back to env / config file) |
85
+ | `requireAck` | `boolean` | `false` | Enable delivery guarantee (see below) |
86
+ | `suppressBranchWarning` | `boolean` | `false` | Suppress the branch warning when running on a non-live branch |
87
+
88
+ ## Result
89
+
90
+ When awaited, the task handle resolves to a result object:
91
+
92
+ ```typescript
93
+ const result = await createTask({ taskTemplate: 'my-template', input: {} })
94
+
95
+ result.input // The input you provided
96
+ result.result // The final task output
97
+ result.taskId // Unique task identifier
98
+ result.taskUrl // URL to view the task in the Requence UI
99
+ result.getNodeData(alias) // Get output from a specific node by alias
100
+ result.getNodeError(alias) // Get error from a specific node by alias
101
+ ```
102
+
103
+ ## Streaming Updates
104
+
105
+ The task handle is an `AsyncIterable` that emits updates as the task executes. Iterate over it with `for await`:
106
+
107
+ ```typescript
108
+ const task = createTask({
109
+ taskTemplate: 'my-template',
110
+ input: { data: [1, 2, 3] },
111
+ })
112
+
113
+ for await (const update of task) {
114
+ switch (update.type) {
115
+ case 'taskStart':
116
+ console.log(`Task ${update.taskId} started`)
117
+ break
118
+ case 'nodeStart':
119
+ console.log(`Node ${update.node.alias ?? update.node.id} started`)
120
+ break
121
+ case 'nodeUpdate':
122
+ console.log(`Node output:`, update.data)
123
+ break
124
+ case 'nodeError':
125
+ console.log(`Node error:`, update.error)
126
+ break
127
+ case 'nodeDefer':
128
+ console.log(`Node deferred:`, update.reason)
129
+ break
130
+ case 'nodeEnd':
131
+ console.log(`Node ${update.node.alias ?? update.node.id} finished`)
132
+ break
133
+ case 'taskEnd':
134
+ console.log(`Task completed:`, update.context.result)
135
+ break
136
+ case 'taskError':
137
+ console.log(`Task failed:`, update.reason)
138
+ break
139
+ case 'taskAborted':
140
+ console.log(`Task aborted:`, update.reason)
141
+ break
142
+ }
143
+ }
144
+ ```
145
+
146
+ ### `onUpdate` callback
147
+
148
+ Alternatively, pass a callback as the second argument to stream updates while still awaiting the final result:
149
+
150
+ ```typescript
151
+ const result = await createTask(
152
+ { taskTemplate: 'my-template', input: {} },
153
+ (update) => {
154
+ console.log(`[${update.type}]`, update.timestamp)
155
+ },
156
+ )
157
+ ```
158
+
159
+ ### Update types
160
+
161
+ | Type | Description |
162
+ |---|---|
163
+ | `taskStart` | Task execution has begun. Contains `input` and `taskId`. |
164
+ | `nodeStart` | A node started processing. Contains `node` info (id, type, alias). |
165
+ | `nodeUpdate` | A node produced output. Contains `data` and `output` (named output, if any). |
166
+ | `nodeError` | A node encountered an error. Contains `error` message. |
167
+ | `nodeDefer` | A node has been deferred (waiting for an external callback). |
168
+ | `nodeEnd` | A node finished processing. |
169
+ | `taskEnd` | The task completed successfully. Contains final `result`. |
170
+ | `taskError` | The task failed. Contains `reason`. |
171
+ | `taskAborted` | The task was aborted. Contains `reason`. |
172
+
173
+ ### Context on every update
174
+
175
+ Every update includes a `context` object with the current accumulated state:
176
+
177
+ ```typescript
178
+ update.context.input // The task input
179
+ update.context.taskId // The task ID
180
+ update.context.result // Accumulated result (partial until taskEnd)
181
+ update.context.getNodeData(alias) // Output from a specific node by alias
182
+ update.context.getNodeError(alias) // Error from a specific node by alias
183
+ ```
184
+
185
+ ## Aborting a Task
186
+
187
+ Via the task handle:
188
+
189
+ ```typescript
190
+ const task = createTask({ taskTemplate: 'my-template', input: {} })
191
+ await task.abort('No longer needed')
192
+ ```
193
+
194
+ Or standalone, using a known task ID:
195
+
196
+ ```typescript
197
+ import { abortTask } from '@requence/task'
198
+
199
+ await abortTask({
200
+ taskId: 'some-task-id',
201
+ reason: 'Cancelled by user',
202
+ })
203
+ ```
204
+
205
+ ## Protecting a Task
206
+
207
+ Protected tasks are excluded from automatic cleanup — useful for important results you want to keep indefinitely.
208
+
209
+ Via the task handle:
210
+
211
+ ```typescript
212
+ const task = createTask({ taskTemplate: 'my-template', input: {} })
213
+ await task.protect()
214
+ ```
215
+
216
+ Or standalone:
217
+
218
+ ```typescript
219
+ import { protectTask } from '@requence/task'
220
+
221
+ await protectTask({ taskId: 'some-task-id' })
222
+ ```
223
+
224
+ ## Fetching a Task by ID
225
+
226
+ Retrieve the current state of any task:
227
+
228
+ ```typescript
229
+ import { getTask } from '@requence/task'
230
+
231
+ const task = await getTask('some-task-id')
232
+ // or: getTask({ taskId: 'some-task-id', accessToken: '...' })
233
+
234
+ task.status // 'SUCCESSFUL' | 'FAILED' | 'IDLE' | 'PENDING' | 'RUNNING' | 'STOPPED' | 'AWAITING_DELIVERY'
235
+ task.statusText // Human-readable status description, if any
236
+ task.taskTemplate // The task template name
237
+ task.name // Human-readable task name
238
+ task.branch // 'live' or a branch name
239
+
240
+ task.context.input // The task's input
241
+ task.context.result // The task's result (if finished)
242
+ task.context.getNodeData(alias) // Output from a specific node
243
+ task.context.getNodeError(alias) // Error from a specific node
244
+ ```
245
+
246
+ ## Recreating a Task
247
+
248
+ Re-run an existing task with the same template and input:
249
+
250
+ ```typescript
251
+ import { recreateTask } from '@requence/task'
252
+
253
+ const task = await recreateTask({
254
+ taskId: 'some-task-id',
255
+ name: 'My Retry', // Optional — overrides the original name
256
+ priority: 3, // Optional — overrides the original priority
257
+ })
258
+
259
+ const result = await task
260
+ ```
261
+
262
+ ## Watching All Tasks (`watchTasks`)
263
+
264
+ Subscribe to real-time updates across **all tasks** — useful for dashboards, monitoring systems, or audit logs.
265
+
266
+ ```typescript
267
+ import { watchTasks } from '@requence/task'
268
+
269
+ const stop = watchTasks({
270
+ since: new Date(),
271
+ onUpdate(update) {
272
+ console.log(`[${update.type}] Task ${update.context.taskId}`)
273
+ },
274
+ })
275
+
276
+ // Later — disconnect the watcher
277
+ stop()
278
+ ```
279
+
280
+ `watchTasks` returns a stop function that is also an **AsyncIterable**:
281
+
282
+ ```typescript
283
+ const watcher = watchTasks({ since: new Date() })
284
+
285
+ for await (const update of watcher) {
286
+ console.log(update.type, update.context.taskId)
287
+
288
+ if (shouldStop) {
289
+ watcher() // stop watching
290
+ break
291
+ }
292
+ }
293
+ ```
294
+
295
+ ### `watchTasks` options
296
+
297
+ | Option | Type | Description |
298
+ |---|---|---|
299
+ | `since` | `Date` | **Required.** Only receive updates after this timestamp. |
300
+ | `accessToken` | `string` | Access token (falls back to env / config file) |
301
+ | `filter.only` | `string[]` | Filter to specific update types (e.g. `['taskEnd', 'taskError']`) |
302
+ | `onUpdate` | `function` | Callback for each update |
303
+ | `onConnect` | `function` | Called when the connection is established |
304
+ | `onReconnecting` | `function` | Called when the connection is being re-established |
305
+ | `onError` | `function` | Called on connection errors — receives `(status, reason)` |
306
+
307
+ ### Incomplete updates
308
+
309
+ Each update from `watchTasks` includes an `incomplete` flag. When `true`, it means the watcher connected after the task had already started and the `taskStart` event was missed. Use this to decide whether to skip or partially process the update.
310
+
311
+ It also includes a `rootTaskId` field — the ID of the root task when the update belongs to a sub-task, or `null` for top-level tasks.
312
+
313
+ ## Delivery Guarantee
314
+
315
+ By default, a task transitions immediately from `RUNNING` to `SUCCESSFUL` / `FAILED` / `STOPPED` when it finishes. If the process that started the task crashes at the exact moment the terminal event is emitted, the event can be lost.
316
+
317
+ Setting `requireAck: true` enables an explicit acknowledgement step:
318
+
319
+ 1. When the task reaches its terminal state the backend holds it in **`AWAITING_DELIVERY`** instead of immediately finalising.
320
+ 2. The SDK receives the terminal event over SSE and automatically sends an ACK back.
321
+ 3. Only after the ACK is received does the task move to its real final status, and the exact delivery timestamp is recorded.
322
+
323
+ ```typescript
324
+ const result = await createTask({
325
+ taskTemplate: 'my-template',
326
+ input: { /* ... */ },
327
+ requireAck: true,
328
+ })
329
+ // Resolves only after the ACK has been confirmed
330
+ ```
331
+
332
+ `requireAck` also works with `watchTasks` — when a task with `requireAck` reaches its terminal state, the watcher ACKs it automatically using the same access token.
333
+
334
+ ## CLI — Generate Types
335
+
336
+ The package ships with a CLI that generates TypeScript types for your task templates, derived from the schemas defined in the Requence UI:
337
+
338
+ ```bash
339
+ npx requence-task generate-types
340
+ ```
341
+
342
+ This creates a `requence-env.d.ts` file in your project root. TypeScript picks it up automatically — `input`, `result`, and node data will be fully typed.
343
+
344
+ ### Options
345
+
346
+ | Option | Default | Description |
347
+ |---|---|---|
348
+ | `--access-token` | — | Access token (falls back to env / config file) |
349
+ | `--outfile` | `requence-env.d.ts` | Name of the generated type file |
350
+ | `--outdir` | `.` | Directory to write the type file to |
351
+
352
+ The token resolution order for the CLI is the same as for `createTask`: option → `REQUENCE_TASK_ACCESS_TOKEN` / `REQUENCE_ACCESS_TOKEN` env var → `requence.task.accessToken` / `requence.accessToken` in `package.json`.
353
+
354
+ ## Full Example
355
+
356
+ ```typescript
357
+ import { createTask, watchTasks } from '@requence/task'
358
+
359
+ // Start a task and stream its progress
360
+ const task = createTask(
361
+ {
362
+ taskTemplate: 'invoice-processing',
363
+ input: { invoiceUrl: 'https://...' },
364
+ name: 'Invoice #1234',
365
+ priority: 3,
366
+ },
367
+ (update) => {
368
+ if (update.type === 'nodeUpdate') {
369
+ console.log('Node result:', update.data)
370
+ }
371
+ },
372
+ )
373
+
374
+ const taskId = await task.getTaskId()
375
+ console.log('Started task:', taskId)
376
+
377
+ try {
378
+ const result = await task
379
+ console.log('Final result:', result.result)
380
+ } catch (error) {
381
+ console.error('Task failed:', error.message)
382
+ }
383
+ ```
@@ -0,0 +1,35 @@
1
+ // ../helpers/src/utils/obfuscate.ts
2
+ var separator = "";
3
+ var base65Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
4
+ var base65CharToIndex = {};
5
+ for (let i = 0;i < base65Chars.length; i++) {
6
+ base65CharToIndex[base65Chars[i]] = i;
7
+ }
8
+ function deobfuscate(str) {
9
+ const paddingCount = parseInt(str.slice(-1), 10);
10
+ str = str.slice(0, -1);
11
+ let binaryString = "";
12
+ for (let i = 0;i < str.length; i++) {
13
+ const decimalValue = base65CharToIndex[str[i]];
14
+ const binaryChunk = decimalValue.toString(2).padStart(6, "0");
15
+ binaryString += binaryChunk;
16
+ }
17
+ if (paddingCount > 0) {
18
+ binaryString = binaryString.slice(0, -paddingCount);
19
+ }
20
+ let decodedString = "";
21
+ const charSize = 16;
22
+ for (let i = 0;i < binaryString.length; i += charSize) {
23
+ const byte = binaryString.substring(i, i + charSize);
24
+ if (byte.length === 16) {
25
+ const charCode = parseInt(byte, 2);
26
+ decodedString += String.fromCharCode(charCode);
27
+ }
28
+ }
29
+ return decodedString.split(separator);
30
+ }
31
+
32
+ export { deobfuscate };
33
+
34
+ //# debugId=58DA2BE245CFC84464756E2164756E21
35
+ //# sourceMappingURL=chunk-b4h2we9a.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../helpers/src/utils/obfuscate.ts"],
4
+ "sourcesContent": [
5
+ "const separator = '\\u{f6ee}'\n\nconst base65Chars =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$'\n\nconst base65CharToIndex: Record<string, number> = {}\nfor (let i = 0; i < base65Chars.length; i++) {\n base65CharToIndex[base65Chars[i]] = i\n}\n\nexport function obfuscate(...parts: Array<string>) {\n const str = parts.join(separator)\n let binaryString = ''\n\n for (let i = 0; i < str.length; i++) {\n const charCode = str.charCodeAt(i)\n binaryString += charCode.toString(2).padStart(16, '0')\n }\n\n let encodedString = ''\n const chunkSize = 6\n let paddingCount = 0\n\n for (let i = 0; i < binaryString.length; i += chunkSize) {\n let chunk = binaryString.substring(i, i + chunkSize)\n\n if (chunk.length < chunkSize) {\n paddingCount = chunkSize - chunk.length\n chunk = chunk.padEnd(chunkSize, '0')\n }\n\n const decimalValue = parseInt(chunk, 2)\n encodedString += base65Chars[decimalValue]\n }\n\n return encodedString + paddingCount.toString()\n}\n\nexport function randomString(length: number) {\n const randomValues = new Uint8Array(length)\n crypto.getRandomValues(randomValues)\n\n let randomString = ''\n for (let i = 0; i < length; i++) {\n randomString += base65Chars[randomValues[i] % base65Chars.length]\n }\n\n return randomString\n}\n\nexport function deobfuscate(str: string) {\n const paddingCount = parseInt(str.slice(-1), 10)\n str = str.slice(0, -1)\n\n let binaryString = ''\n\n for (let i = 0; i < str.length; i++) {\n const decimalValue = base65CharToIndex[str[i]]\n const binaryChunk = decimalValue.toString(2).padStart(6, '0')\n binaryString += binaryChunk\n }\n\n if (paddingCount > 0) {\n binaryString = binaryString.slice(0, -paddingCount)\n }\n\n let decodedString = ''\n const charSize = 16\n\n for (let i = 0; i < binaryString.length; i += charSize) {\n const byte = binaryString.substring(i, i + charSize)\n if (byte.length === 16) {\n const charCode = parseInt(byte, 2)\n decodedString += String.fromCharCode(charCode)\n }\n }\n\n return decodedString.split(separator)\n}\n"
6
+ ],
7
+ "mappings": ";AAAA,IAAM,YAAY;AAElB,IAAM,cACJ;AAEF,IAAM,oBAA4C,CAAC;AACnD,SAAS,IAAI,EAAG,IAAI,YAAY,QAAQ,KAAK;AAAA,EAC3C,kBAAkB,YAAY,MAAM;AACtC;AA0CO,SAAS,WAAW,CAAC,KAAa;AAAA,EACvC,MAAM,eAAe,SAAS,IAAI,MAAM,EAAE,GAAG,EAAE;AAAA,EAC/C,MAAM,IAAI,MAAM,GAAG,EAAE;AAAA,EAErB,IAAI,eAAe;AAAA,EAEnB,SAAS,IAAI,EAAG,IAAI,IAAI,QAAQ,KAAK;AAAA,IACnC,MAAM,eAAe,kBAAkB,IAAI;AAAA,IAC3C,MAAM,cAAc,aAAa,SAAS,CAAC,EAAE,SAAS,GAAG,GAAG;AAAA,IAC5D,gBAAgB;AAAA,EAClB;AAAA,EAEA,IAAI,eAAe,GAAG;AAAA,IACpB,eAAe,aAAa,MAAM,IAAI,YAAY;AAAA,EACpD;AAAA,EAEA,IAAI,gBAAgB;AAAA,EACpB,MAAM,WAAW;AAAA,EAEjB,SAAS,IAAI,EAAG,IAAI,aAAa,QAAQ,KAAK,UAAU;AAAA,IACtD,MAAM,OAAO,aAAa,UAAU,GAAG,IAAI,QAAQ;AAAA,IACnD,IAAI,KAAK,WAAW,IAAI;AAAA,MACtB,MAAM,WAAW,SAAS,MAAM,CAAC;AAAA,MACjC,iBAAiB,OAAO,aAAa,QAAQ;AAAA,IAC/C;AAAA,EACF;AAAA,EAEA,OAAO,cAAc,MAAM,SAAS;AAAA;",
8
+ "debugId": "58DA2BE245CFC84464756E2164756E21",
9
+ "names": []
10
+ }