@microfox/ai-worker 1.0.1 → 1.0.2
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/CHANGELOG.md +6 -0
- package/README.md +18 -0
- package/dist/chunk-4WU5ZCHS.mjs +1053 -0
- package/dist/chunk-4WU5ZCHS.mjs.map +1 -0
- package/dist/chunk-BJPQY2NJ.mjs +186 -0
- package/dist/chunk-BJPQY2NJ.mjs.map +1 -0
- package/dist/client-D25XR0V8.d.mts +167 -0
- package/dist/client-D25XR0V8.d.ts +167 -0
- package/dist/client.d.mts +2 -64
- package/dist/client.d.ts +2 -64
- package/dist/client.js +107 -2
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +7 -3
- package/dist/handler.d.mts +83 -14
- package/dist/handler.d.ts +83 -14
- package/dist/handler.js +773 -5
- package/dist/handler.js.map +1 -1
- package/dist/handler.mjs +7 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1027 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +159 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
- package/dist/chunk-FQCZSXDI.mjs +0 -83
- package/dist/chunk-FQCZSXDI.mjs.map +0 -1
- package/dist/chunk-WVR4JVWK.mjs +0 -285
- package/dist/chunk-WVR4JVWK.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -110,8 +110,11 @@ npx @microfox/ai-worker-cli@latest push
|
|
|
110
110
|
**Required for Lambda (set via deploy script):**
|
|
111
111
|
- `AWS_REGION` - AWS region for SQS/Lambda
|
|
112
112
|
- `STAGE` - Deployment stage (dev/stage/prod)
|
|
113
|
+
- `MONGODB_URI` or `DATABASE_MONGODB_URI` - For job store (and internalJobs / await polling).
|
|
113
114
|
- Any secrets your workers need (OPENAI_KEY, DATABASE_URL, etc.)
|
|
114
115
|
|
|
116
|
+
**Worker-to-worker (Lambda):** When a worker calls another via `ctx.dispatchWorker`, the CLI injects `WORKER_QUEUE_URL_<SANITIZED_ID>` (e.g. `WORKER_QUEUE_URL_COST_USAGE_AI`) into that function’s environment. Same-service callees get this automatically; cross-service callees require setting the env var manually.
|
|
117
|
+
|
|
115
118
|
### Worker Configuration
|
|
116
119
|
|
|
117
120
|
**Best Practice**: Export `workerConfig` as a separate const from your worker file:
|
|
@@ -180,6 +183,21 @@ Dispatches a job to the background worker.
|
|
|
180
183
|
|
|
181
184
|
**Returns:** `Promise<{ messageId: string, status: 'queued', jobId: string }>`
|
|
182
185
|
|
|
186
|
+
### Worker-to-worker: `ctx.dispatchWorker(workerId, input, options?)`
|
|
187
|
+
|
|
188
|
+
Inside a worker handler, call another worker (fire-and-forget or await):
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
handler: async ({ ctx }) => {
|
|
192
|
+
await ctx.dispatchWorker('other-worker', {}, { await: true });
|
|
193
|
+
};
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
- **Fire-and-forget**: `ctx.dispatchWorker(id, input)` — enqueues and returns `{ jobId, messageId }`. Parent job’s `internalJobs` is appended.
|
|
197
|
+
- **Await**: `ctx.dispatchWorker(id, input, { await: true })` — enqueues, appends to `internalJobs`, then polls the job store until the child completes or fails. Returns `{ jobId, messageId, output }` or throws. Optional `pollIntervalMs`, `pollTimeoutMs`.
|
|
198
|
+
|
|
199
|
+
The CLI detects `ctx.dispatchWorker('id', ...)` and adds `WORKER_QUEUE_URL_<ID>` to that Lambda’s env. Local dev uses the HTTP trigger when queue URL is not set.
|
|
200
|
+
|
|
183
201
|
## License
|
|
184
202
|
|
|
185
203
|
MIT
|