sonamu 0.8.24 → 0.8.26
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/api/__tests__/config.test.js +189 -0
- package/dist/api/config.d.ts.map +1 -1
- package/dist/api/config.js +7 -2
- package/dist/api/sonamu.d.ts.map +1 -1
- package/dist/api/sonamu.js +14 -10
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +2 -1
- package/dist/auth/knex-adapter.d.ts +23 -0
- package/dist/auth/knex-adapter.d.ts.map +1 -0
- package/dist/auth/knex-adapter.js +163 -0
- package/dist/auth/plugins/wrappers/admin.d.ts +2 -2
- package/dist/bin/__tests__/ts-loader-register.test.js +45 -0
- package/dist/bin/cli.js +47 -9
- package/dist/bin/ts-loader-register.js +3 -29
- package/dist/bin/ts-loader-registration.d.ts +2 -0
- package/dist/bin/ts-loader-registration.d.ts.map +1 -0
- package/dist/bin/ts-loader-registration.js +42 -0
- package/dist/cone/cone-generator.js +3 -3
- package/dist/database/puri-subset.test-d.js +9 -1
- package/dist/database/puri-subset.types.d.ts +1 -1
- package/dist/database/puri-subset.types.d.ts.map +1 -1
- package/dist/database/puri-subset.types.js +1 -1
- package/dist/testing/fixture-generator.js +5 -5
- package/dist/ui/ai-client.js +2 -2
- package/dist/ui/api.d.ts.map +1 -1
- package/dist/ui/api.js +14 -14
- package/dist/ui/cdd-service.d.ts +15 -18
- package/dist/ui/cdd-service.d.ts.map +1 -1
- package/dist/ui/cdd-service.js +246 -222
- package/dist/ui/cdd-types.d.ts +41 -68
- package/dist/ui/cdd-types.d.ts.map +1 -1
- package/dist/ui/cdd-types.js +2 -2
- package/dist/ui-web/assets/index-CKo0Z2Iu.css +1 -0
- package/dist/ui-web/assets/{index-CxiydzeC.js → index-DK-2aacv.js} +83 -83
- package/dist/ui-web/index.html +2 -2
- package/package.json +6 -2
- package/src/api/__tests__/config.test.ts +225 -0
- package/src/api/config.ts +10 -4
- package/src/api/sonamu.ts +16 -13
- package/src/auth/index.ts +1 -0
- package/src/auth/knex-adapter.ts +208 -0
- package/src/bin/__tests__/ts-loader-register.test.ts +62 -0
- package/src/bin/cli.ts +52 -9
- package/src/bin/ts-loader-register.ts +2 -32
- package/src/bin/ts-loader-registration.ts +55 -0
- package/src/cone/cone-generator.ts +2 -2
- package/src/database/puri-subset.test-d.ts +102 -0
- package/src/database/puri-subset.types.ts +1 -1
- package/src/skills/commands/sonamu-skills.md +20 -0
- package/src/skills/sonamu/SKILL.md +179 -137
- package/src/skills/sonamu/ai-agents.md +69 -69
- package/src/skills/sonamu/api.md +147 -147
- package/src/skills/sonamu/auth-migration.md +220 -220
- package/src/skills/sonamu/auth-plugins.md +83 -83
- package/src/skills/sonamu/auth.md +106 -106
- package/src/skills/sonamu/cdd.md +65 -200
- package/src/skills/sonamu/cone.md +138 -138
- package/src/skills/sonamu/config.md +191 -191
- package/src/skills/sonamu/create-sonamu.md +66 -66
- package/src/skills/sonamu/database.md +158 -158
- package/src/skills/sonamu/entity-basic.md +292 -293
- package/src/skills/sonamu/entity-relations.md +246 -246
- package/src/skills/sonamu/entity-validation-checklist.md +124 -124
- package/src/skills/sonamu/fixture-cli.md +231 -231
- package/src/skills/sonamu/framework-change.md +37 -37
- package/src/skills/sonamu/frontend.md +223 -223
- package/src/skills/sonamu/i18n.md +82 -82
- package/src/skills/sonamu/migration.md +77 -77
- package/src/skills/sonamu/model.md +222 -222
- package/src/skills/sonamu/naite.md +86 -86
- package/src/skills/sonamu/project-init.md +228 -228
- package/src/skills/sonamu/puri.md +122 -122
- package/src/skills/sonamu/scaffolding.md +154 -154
- package/src/skills/sonamu/skill-contribution.md +124 -124
- package/src/skills/sonamu/subset.md +46 -46
- package/src/skills/sonamu/tasks.md +82 -82
- package/src/skills/sonamu/testing-devrunner.md +147 -147
- package/src/skills/sonamu/testing.md +673 -673
- package/src/skills/sonamu/upsert.md +79 -79
- package/src/skills/sonamu/vector.md +67 -67
- package/src/testing/fixture-generator.ts +4 -4
- package/src/ui/ai-client.ts +1 -1
- package/src/ui/api.ts +18 -17
- package/src/ui/cdd-service.ts +264 -254
- package/src/ui/cdd-types.ts +40 -75
- package/dist/ui-web/assets/index-BrQKU3j9.css +0 -1
- package/src/skills/sonamu/workflow.md +0 -317
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: sonamu-tasks
|
|
3
|
-
description: Sonamu Tasks
|
|
3
|
+
description: Sonamu Tasks workflow system. Background jobs, scheduling, durable step execution. Use when implementing background workflows, scheduled tasks, or multi-step async processes.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Tasks (
|
|
6
|
+
# Tasks (Workflow System)
|
|
7
7
|
|
|
8
|
-
PostgreSQL
|
|
8
|
+
PostgreSQL-based durable workflow engine. Uses the `@sonamu-kit/tasks` package.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
-
|
|
10
|
+
**Source code:**
|
|
11
|
+
- Decorator: `modules/sonamu/src/tasks/decorator.ts`
|
|
12
12
|
- StepWrapper: `modules/sonamu/src/tasks/step-wrapper.ts`
|
|
13
13
|
- WorkflowManager: `modules/sonamu/src/tasks/workflow-manager.ts`
|
|
14
14
|
- @sonamu-kit/tasks: `modules/tasks/`
|
|
15
15
|
|
|
16
|
-
##
|
|
16
|
+
## Workflow Definition
|
|
17
17
|
|
|
18
|
-
`workflow()`
|
|
18
|
+
Define with the `workflow()` function. When exported, the syncer automatically collects and registers it with WorkflowManager.
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
21
|
import { workflow } from "sonamu";
|
|
22
22
|
|
|
23
|
-
//
|
|
23
|
+
// Method 1: decorator + function separated
|
|
24
24
|
export const myTask = workflow({
|
|
25
25
|
version: "1",
|
|
26
26
|
})(async ({ input, step, logger, version }) => {
|
|
27
27
|
// ...
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
//
|
|
30
|
+
// Method 2: decorator + function inlined
|
|
31
31
|
export const myTask = workflow({
|
|
32
32
|
version: "1",
|
|
33
33
|
}, async ({ input, step, logger, version }) => {
|
|
@@ -37,28 +37,28 @@ export const myTask = workflow({
|
|
|
37
37
|
|
|
38
38
|
### DefineWorkflowOptions
|
|
39
39
|
|
|
40
|
-
|
|
|
40
|
+
| Option | Type | Required | Description |
|
|
41
41
|
|------|------|------|------|
|
|
42
|
-
| `version` | `string` | Y |
|
|
43
|
-
| `name` | `string` | N |
|
|
44
|
-
| `schema` | `StandardSchemaV1` | N |
|
|
45
|
-
| `schedules` | `Schedule[]` | N | cron
|
|
46
|
-
| `retryPolicy` | `RetryPolicy` | N |
|
|
42
|
+
| `version` | `string` | Y | Workflow version (distinguishes from existing runs when changed) |
|
|
43
|
+
| `name` | `string` | N | Workflow name (default: function name converted to underscore case) |
|
|
44
|
+
| `schema` | `StandardSchemaV1` | N | Input validation schema (Zod, etc.) |
|
|
45
|
+
| `schedules` | `Schedule[]` | N | Array of cron schedules |
|
|
46
|
+
| `retryPolicy` | `RetryPolicy` | N | Retry policy |
|
|
47
47
|
|
|
48
|
-
###
|
|
48
|
+
### Workflow Function Parameters
|
|
49
49
|
|
|
50
|
-
|
|
|
50
|
+
| Parameter | Type | Description |
|
|
51
51
|
|---------|------|------|
|
|
52
|
-
| `input` | `Input` |
|
|
53
|
-
| `step` | `StepWrapper` |
|
|
54
|
-
| `logger` | `Logger` | @logtape/logtape
|
|
55
|
-
| `version` | `string \| null` |
|
|
52
|
+
| `input` | `Input` | Input value passed when the workflow runs |
|
|
53
|
+
| `step` | `StepWrapper` | Tool for defining/executing steps |
|
|
54
|
+
| `logger` | `Logger` | @logtape/logtape logger |
|
|
55
|
+
| `version` | `string \| null` | Current workflow version |
|
|
56
56
|
|
|
57
57
|
## Step
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
An atomic unit of execution within a workflow. On failure, retry begins from that step.
|
|
60
60
|
|
|
61
|
-
### step.define —
|
|
61
|
+
### step.define — Inline Function
|
|
62
62
|
|
|
63
63
|
```typescript
|
|
64
64
|
const result = await step.define({ name: "fetch-data" }, async () => {
|
|
@@ -67,73 +67,73 @@ const result = await step.define({ name: "fetch-data" }, async () => {
|
|
|
67
67
|
}).run();
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
### step.get —
|
|
70
|
+
### step.get — Wrapping an Existing Method
|
|
71
71
|
|
|
72
72
|
```typescript
|
|
73
|
-
// Model
|
|
73
|
+
// Wrap a Model method as a Step
|
|
74
74
|
const result = await step.get(MyModel, "processData").run(inputData);
|
|
75
75
|
|
|
76
|
-
//
|
|
76
|
+
// Specify a custom name
|
|
77
77
|
const result = await step.get({ name: "custom_step" }, MyService, "execute").run(params);
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
`step.get
|
|
81
|
-
- `step.get(object, methodName)` — Step
|
|
82
|
-
- `step.get({ name }, object, methodName)` — Step
|
|
80
|
+
Overloads for `step.get`:
|
|
81
|
+
- `step.get(object, methodName)` — Step name is the methodName converted to underscore case
|
|
82
|
+
- `step.get({ name }, object, methodName)` — Step name specified directly
|
|
83
83
|
|
|
84
|
-
### step.sleep — Durable
|
|
84
|
+
### step.sleep — Durable Wait
|
|
85
85
|
|
|
86
86
|
```typescript
|
|
87
87
|
await step.sleep("wait-before-retry", "30m");
|
|
88
88
|
await step.sleep("daily-delay", "1d");
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
The wait time is preserved even if the server restarts.
|
|
92
92
|
|
|
93
|
-
**DurationString
|
|
93
|
+
**DurationString format:** `{number}{unit}` — e.g. `"5s"`, `"30m"`, `"2h"`, `"7d"`, `"1w"`, `"1y"`
|
|
94
94
|
|
|
95
|
-
##
|
|
95
|
+
## Scheduling (cron)
|
|
96
96
|
|
|
97
97
|
```typescript
|
|
98
98
|
export const dailyReport = workflow({
|
|
99
99
|
version: "1",
|
|
100
100
|
schedules: [{
|
|
101
|
-
expression: "0 9 * * *", //
|
|
102
|
-
name: "daily-report", //
|
|
103
|
-
input: () => ({ date: new Date().toISOString() }), //
|
|
101
|
+
expression: "0 9 * * *", // every day at 9am
|
|
102
|
+
name: "daily-report", // optional (default: workflowName[expression])
|
|
103
|
+
input: () => ({ date: new Date().toISOString() }), // optional
|
|
104
104
|
}],
|
|
105
105
|
}, async ({ input, step }) => {
|
|
106
106
|
// ...
|
|
107
107
|
});
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
|
|
|
110
|
+
| Field | Type | Required | Description |
|
|
111
111
|
|------|------|------|------|
|
|
112
|
-
| `expression` | `string` | Y | cron
|
|
113
|
-
| `name` | `string` | N |
|
|
114
|
-
| `input` | `Executable<Input>` | N |
|
|
112
|
+
| `expression` | `string` | Y | cron expression |
|
|
113
|
+
| `name` | `string` | N | Schedule name (default: `workflowName[expression]`) |
|
|
114
|
+
| `input` | `Executable<Input>` | N | Input value to pass on execution (function or value) |
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
The timezone follows the `api.timezone` setting in `sonamu.config.ts`.
|
|
117
117
|
|
|
118
|
-
##
|
|
118
|
+
## Retry Policy
|
|
119
119
|
|
|
120
|
-
###
|
|
120
|
+
### Static Policy (Default)
|
|
121
121
|
|
|
122
122
|
```typescript
|
|
123
123
|
export const reliableTask = workflow({
|
|
124
124
|
version: "1",
|
|
125
125
|
retryPolicy: {
|
|
126
|
-
maxAttempts: 5, //
|
|
127
|
-
initialIntervalMs: 1000, //
|
|
128
|
-
backoffCoefficient: 2, //
|
|
129
|
-
maximumIntervalMs: 60000, //
|
|
126
|
+
maxAttempts: 5, // maximum retry attempts (default: 5)
|
|
127
|
+
initialIntervalMs: 1000, // first retry wait time (default: 1000ms)
|
|
128
|
+
backoffCoefficient: 2, // wait time multiplier (default: 2)
|
|
129
|
+
maximumIntervalMs: 60000, // maximum wait time
|
|
130
130
|
},
|
|
131
131
|
}, async ({ step }) => {
|
|
132
132
|
// ...
|
|
133
133
|
});
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
###
|
|
136
|
+
### Dynamic Policy
|
|
137
137
|
|
|
138
138
|
```typescript
|
|
139
139
|
retryPolicy: {
|
|
@@ -145,77 +145,77 @@ retryPolicy: {
|
|
|
145
145
|
}
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
-
## sonamu.config.ts
|
|
148
|
+
## sonamu.config.ts Configuration
|
|
149
149
|
|
|
150
150
|
```typescript
|
|
151
151
|
export default defineConfig({
|
|
152
152
|
tasks: {
|
|
153
153
|
enableWorker: true,
|
|
154
154
|
workerOptions: {
|
|
155
|
-
concurrency: 4, //
|
|
156
|
-
usePubSub: true, // DB pub/sub
|
|
157
|
-
listenDelay: 500, // pub/sub
|
|
155
|
+
concurrency: 4, // concurrent execution count (default: CPU cores - 1)
|
|
156
|
+
usePubSub: true, // use DB pub/sub (default: true)
|
|
157
|
+
listenDelay: 500, // execution delay after pub/sub receive in ms (default: 500)
|
|
158
158
|
},
|
|
159
159
|
contextProvider: (defaultContext) => {
|
|
160
|
-
//
|
|
160
|
+
// build Context to use within workflows
|
|
161
161
|
return { ...defaultContext };
|
|
162
162
|
},
|
|
163
163
|
},
|
|
164
164
|
});
|
|
165
165
|
```
|
|
166
166
|
|
|
167
|
-
|
|
|
167
|
+
| Option | Type | Description |
|
|
168
168
|
|------|------|------|
|
|
169
|
-
| `enableWorker` | `boolean` | Worker
|
|
170
|
-
| `workerOptions.concurrency` | `number` |
|
|
171
|
-
| `workerOptions.usePubSub` | `boolean` | PostgreSQL pub/sub
|
|
172
|
-
| `workerOptions.listenDelay` | `number` | pub/sub
|
|
173
|
-
| `contextProvider` | `(ctx) => Context` |
|
|
169
|
+
| `enableWorker` | `boolean` | Whether to enable Worker (use only in daemon mode) |
|
|
170
|
+
| `workerOptions.concurrency` | `number` | Number of concurrently executing tasks |
|
|
171
|
+
| `workerOptions.usePubSub` | `boolean` | Use PostgreSQL pub/sub |
|
|
172
|
+
| `workerOptions.listenDelay` | `number` | Execution delay after pub/sub receive (ms) |
|
|
173
|
+
| `contextProvider` | `(ctx) => Context` | Context creation function when workflow runs |
|
|
174
174
|
|
|
175
|
-
##
|
|
175
|
+
## Manual Execution
|
|
176
176
|
|
|
177
177
|
```typescript
|
|
178
178
|
import { Sonamu } from "sonamu";
|
|
179
179
|
|
|
180
|
-
//
|
|
180
|
+
// Run via WorkflowManager
|
|
181
181
|
const handle = await Sonamu.workflowManager.run(
|
|
182
182
|
{ name: "my-task", version: "1" },
|
|
183
183
|
{ target: "manual" }
|
|
184
184
|
);
|
|
185
185
|
|
|
186
|
-
//
|
|
186
|
+
// Wait for result
|
|
187
187
|
const result = await handle.result();
|
|
188
188
|
```
|
|
189
189
|
|
|
190
|
-
##
|
|
190
|
+
## File Placement
|
|
191
191
|
|
|
192
192
|
```
|
|
193
193
|
packages/api/src/application/
|
|
194
194
|
├── {domain}/
|
|
195
195
|
│ ├── {domain}.model.ts
|
|
196
196
|
│ ├── {domain}.types.ts
|
|
197
|
-
│ └── {domain}.workflow.ts ←
|
|
197
|
+
│ └── {domain}.workflow.ts ← workflow file
|
|
198
198
|
```
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
Define with `workflow()` and export in the workflow file; the syncer will collect it automatically.
|
|
201
201
|
|
|
202
|
-
##
|
|
202
|
+
## Architecture
|
|
203
203
|
|
|
204
204
|
```
|
|
205
|
-
Dev Server
|
|
206
|
-
→ WorkflowManager
|
|
207
|
-
→ Worker
|
|
208
|
-
→ syncer
|
|
209
|
-
→ WorkflowManager.synchronize()
|
|
210
|
-
→ cron
|
|
211
|
-
|
|
212
|
-
HMR
|
|
213
|
-
→
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
→ run()
|
|
217
|
-
→ Worker
|
|
218
|
-
→
|
|
219
|
-
→
|
|
220
|
-
→
|
|
205
|
+
Dev Server startup
|
|
206
|
+
→ WorkflowManager initialization (BackendPostgres)
|
|
207
|
+
→ Worker startup (when enableWorker: true)
|
|
208
|
+
→ syncer collects .workflow.ts files
|
|
209
|
+
→ registers via WorkflowManager.synchronize()
|
|
210
|
+
→ cron schedules start automatically
|
|
211
|
+
|
|
212
|
+
On HMR
|
|
213
|
+
→ re-register workflows from changed files (synchronize)
|
|
214
|
+
|
|
215
|
+
Execution flow
|
|
216
|
+
→ run() called → workflow execution record created in DB
|
|
217
|
+
→ Worker receives via pub/sub → steps executed sequentially
|
|
218
|
+
→ checkpoint saved to DB on each step completion
|
|
219
|
+
→ on failure: retry from that step according to retryPolicy
|
|
220
|
+
→ on server restart: incomplete workflows recovered from DB and continue
|
|
221
221
|
```
|