@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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @microfox/ai-worker
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - ab4a506: Changes from PR #52: add_workers-dispatch-queue
8
+
3
9
  ## 1.0.1
4
10
 
5
11
  ### Patch Changes
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