@microfox/ai-worker 1.0.3 → 1.0.5
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 +14 -0
- package/README.md +22 -0
- package/dist/chainMapDefaults.d.mts +21 -0
- package/dist/chainMapDefaults.d.ts +21 -0
- package/dist/chainMapDefaults.js +59 -0
- package/dist/chainMapDefaults.js.map +1 -0
- package/dist/chainMapDefaults.mjs +10 -0
- package/dist/chainMapDefaults.mjs.map +1 -0
- package/dist/chunk-BCRJIFKB.mjs +9 -0
- package/dist/chunk-BCRJIFKB.mjs.map +1 -0
- package/dist/{chunk-72XGFZCE.mjs → chunk-CILTGUUQ.mjs} +14 -3
- package/dist/chunk-CILTGUUQ.mjs.map +1 -0
- package/dist/{chunk-7LQNS2SG.mjs → chunk-QHX55IML.mjs} +442 -56
- package/dist/chunk-QHX55IML.mjs.map +1 -0
- package/dist/chunk-SQB5FQCZ.mjs +21 -0
- package/dist/chunk-SQB5FQCZ.mjs.map +1 -0
- package/dist/{chunk-AOXGONGI.mjs → chunk-T7DRPKR6.mjs} +7 -5
- package/dist/chunk-T7DRPKR6.mjs.map +1 -0
- package/dist/chunk-XCKWV2WZ.mjs +34 -0
- package/dist/chunk-XCKWV2WZ.mjs.map +1 -0
- package/dist/chunk-ZW4PNCDH.mjs +17 -0
- package/dist/chunk-ZW4PNCDH.mjs.map +1 -0
- package/dist/client.d.mts +148 -2
- package/dist/client.d.ts +148 -2
- package/dist/client.js +13 -2
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +1 -1
- package/dist/handler.d.mts +121 -23
- package/dist/handler.d.ts +121 -23
- package/dist/handler.js +450 -58
- package/dist/handler.js.map +1 -1
- package/dist/handler.mjs +5 -2
- package/dist/hitlConfig.d.mts +46 -0
- package/dist/hitlConfig.d.ts +46 -0
- package/dist/hitlConfig.js +33 -0
- package/dist/hitlConfig.js.map +1 -0
- package/dist/hitlConfig.mjs +8 -0
- package/dist/hitlConfig.mjs.map +1 -0
- package/dist/index.d.mts +28 -4
- package/dist/index.d.ts +28 -4
- package/dist/index.js +575 -74
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -20
- package/dist/index.mjs.map +1 -1
- package/dist/queue-B5n6YVQV.d.ts +306 -0
- package/dist/queue-DaR2UuZi.d.mts +306 -0
- package/dist/queue.d.mts +3 -0
- package/dist/queue.d.ts +3 -0
- package/dist/queue.js +47 -0
- package/dist/queue.js.map +1 -0
- package/dist/queue.mjs +12 -0
- package/dist/queue.mjs.map +1 -0
- package/dist/queueInputEnvelope.d.mts +31 -0
- package/dist/queueInputEnvelope.d.ts +31 -0
- package/dist/queueInputEnvelope.js +42 -0
- package/dist/queueInputEnvelope.js.map +1 -0
- package/dist/queueInputEnvelope.mjs +10 -0
- package/dist/queueInputEnvelope.mjs.map +1 -0
- package/dist/queueJobStore.d.mts +3 -2
- package/dist/queueJobStore.d.ts +3 -2
- package/dist/queueJobStore.js +6 -4
- package/dist/queueJobStore.js.map +1 -1
- package/dist/queueJobStore.mjs +1 -1
- package/package.json +7 -2
- package/dist/chunk-72XGFZCE.mjs.map +0 -1
- package/dist/chunk-7LQNS2SG.mjs.map +0 -1
- package/dist/chunk-AOXGONGI.mjs.map +0 -1
- package/dist/client-BqSJQ9mZ.d.mts +0 -183
- package/dist/client-BqSJQ9mZ.d.ts +0 -183
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* UI rendering hint for a HITL step.
|
|
5
|
+
*
|
|
6
|
+
* - `'custom'` — render using a registered view component (by `viewId`).
|
|
7
|
+
* - `'schema-form'` — auto-render a form for the step (no custom view needed).
|
|
8
|
+
* The panel falls back to a raw-JSON textarea if no schema-form renderer is available.
|
|
9
|
+
*/
|
|
10
|
+
type HitlUiSpec = {
|
|
11
|
+
type: 'custom';
|
|
12
|
+
/** View ID used to look up the renderer in the app's HITL view registry. */
|
|
13
|
+
viewId: string;
|
|
14
|
+
title?: string;
|
|
15
|
+
sections?: Array<Record<string, unknown>>;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'schema-form';
|
|
19
|
+
title?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
};
|
|
22
|
+
/** Metadata for a human-in-the-loop step on `WorkerQueueStep.hitl`. */
|
|
23
|
+
type HitlStepConfig = {
|
|
24
|
+
taskKey: string;
|
|
25
|
+
timeoutSeconds?: number;
|
|
26
|
+
onTimeout?: 'reject' | 'auto-approve';
|
|
27
|
+
assignees?: string[];
|
|
28
|
+
ui: HitlUiSpec;
|
|
29
|
+
/** Reviewer form schema — single source of truth; use `z.infer<typeof schema>` for types. */
|
|
30
|
+
inputSchema?: ZodType;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* DX helper for queue authors: keeps HITL config typed/readable.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const hitl = defineHitlConfig({
|
|
38
|
+
* taskKey: 'review-step',
|
|
39
|
+
* ui: { type: 'schema-form', title: 'Review the output' },
|
|
40
|
+
* inputSchema: z.object({ approved: z.boolean(), comment: z.string().optional() }),
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function defineHitlConfig<T extends HitlStepConfig>(config: T): T;
|
|
45
|
+
|
|
46
|
+
export { type HitlStepConfig, type HitlUiSpec, defineHitlConfig };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/hitlConfig.ts
|
|
21
|
+
var hitlConfig_exports = {};
|
|
22
|
+
__export(hitlConfig_exports, {
|
|
23
|
+
defineHitlConfig: () => defineHitlConfig
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(hitlConfig_exports);
|
|
26
|
+
function defineHitlConfig(config) {
|
|
27
|
+
return config;
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
defineHitlConfig
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=hitlConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hitlConfig.ts"],"sourcesContent":["import type { ZodType } from 'zod';\n\n/**\n * UI rendering hint for a HITL step.\n *\n * - `'custom'` — render using a registered view component (by `viewId`).\n * - `'schema-form'` — auto-render a form for the step (no custom view needed).\n * The panel falls back to a raw-JSON textarea if no schema-form renderer is available.\n */\nexport type HitlUiSpec =\n | {\n type: 'custom';\n /** View ID used to look up the renderer in the app's HITL view registry. */\n viewId: string;\n title?: string;\n sections?: Array<Record<string, unknown>>;\n [key: string]: unknown;\n }\n | {\n type: 'schema-form';\n title?: string;\n description?: string;\n };\n\n/** Metadata for a human-in-the-loop step on `WorkerQueueStep.hitl`. */\nexport type HitlStepConfig = {\n taskKey: string;\n timeoutSeconds?: number;\n onTimeout?: 'reject' | 'auto-approve';\n assignees?: string[];\n ui: HitlUiSpec;\n /** Reviewer form schema — single source of truth; use `z.infer<typeof schema>` for types. */\n inputSchema?: ZodType;\n};\n\n/**\n * DX helper for queue authors: keeps HITL config typed/readable.\n *\n * @example\n * ```ts\n * const hitl = defineHitlConfig({\n * taskKey: 'review-step',\n * ui: { type: 'schema-form', title: 'Review the output' },\n * inputSchema: z.object({ approved: z.boolean(), comment: z.string().optional() }),\n * });\n * ```\n */\nexport function defineHitlConfig<T extends HitlStepConfig>(config: T): T {\n return config;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+CO,SAAS,iBAA2C,QAAc;AACvE,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import * as aws_lambda from 'aws-lambda';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
2
|
+
import { DispatchOptions, DispatchResult } from './client.mjs';
|
|
3
|
+
export { DispatchQueueResult, SerializedContext, WorkerQueueRegistry, dispatch, dispatchLocal, dispatchQueue, dispatchWorker, getQueueStartUrl, getWorkersTriggerUrl } from './client.mjs';
|
|
4
4
|
import { WorkerHandler } from './handler.mjs';
|
|
5
|
-
export { DispatchWorkerOptions, JobRecord, JobStore, JobStoreUpdate, QueueNextStep, QueueRuntime,
|
|
5
|
+
export { DispatchWorkerOptions, JobRecord, JobStore, JobStoreUpdate, MapStepInputContext, QueueNextStep, QueueRuntime, SQSMessageBody, SQS_MAX_DELAY_SECONDS, TokenBudgetExceededError, TokenBudgetState, TokenUsage, WebhookPayload, WorkerHandlerParams, WorkerLogger, createLambdaHandler, createWorkerLogger, wrapHandlerForQueue } from './handler.mjs';
|
|
6
|
+
import { S as SmartRetryConfig } from './queue-DaR2UuZi.mjs';
|
|
7
|
+
export { B as BuiltInRetryPattern, b as ChainContext, C as CustomRetryPattern, H as HitlResumeContext, L as LoopContext, c as QUEUE_ORCHESTRATION_KEYS, Q as QueueStepOutput, R as RetryContext, a as RetryPattern, d as WorkerQueueConfig, e as WorkerQueueContext, W as WorkerQueueStep, f as defineWorkerQueue, g as executeWithRetry, m as matchesRetryPattern, r as repeatStep } from './queue-DaR2UuZi.mjs';
|
|
6
8
|
import { ZodType, z } from 'zod';
|
|
7
9
|
export { WorkersConfig, clearWorkersConfigCache, getWorkersConfig, resolveQueueUrl } from './config.mjs';
|
|
10
|
+
export { QueueOrchestrationFields, queueOrchestrationFieldsSchema, withQueueOrchestrationEnvelope } from './queueInputEnvelope.mjs';
|
|
11
|
+
export { defaultMapChainContinueFromPrevious, defaultMapChainPassthrough } from './chainMapDefaults.mjs';
|
|
12
|
+
export { HitlStepConfig, HitlUiSpec, defineHitlConfig } from './hitlConfig.mjs';
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Schedule event configuration for a worker.
|
|
@@ -144,6 +149,11 @@ interface WorkerConfig {
|
|
|
144
149
|
* ```
|
|
145
150
|
*/
|
|
146
151
|
schedule?: ScheduleConfig;
|
|
152
|
+
/**
|
|
153
|
+
* If set, this worker is deployed to the serverless project for this group.
|
|
154
|
+
* Do not use 'core' (reserved). Max 12 characters (serverless service name limits).
|
|
155
|
+
*/
|
|
156
|
+
group?: string;
|
|
147
157
|
/**
|
|
148
158
|
* SQS queue settings for this worker (used by @microfox/ai-worker-cli when generating serverless.yml).
|
|
149
159
|
*
|
|
@@ -179,6 +189,18 @@ interface WorkerAgentConfig<INPUT_SCHEMA extends ZodType<any>, OUTPUT> {
|
|
|
179
189
|
inputSchema: INPUT_SCHEMA;
|
|
180
190
|
outputSchema: ZodType<OUTPUT>;
|
|
181
191
|
handler: WorkerHandler<z.infer<INPUT_SCHEMA>, OUTPUT>;
|
|
192
|
+
/**
|
|
193
|
+
* Smart retry configuration for this worker.
|
|
194
|
+
* Applies whenever this worker runs (Lambda or local mode).
|
|
195
|
+
* Can be overridden per queue step via WorkerQueueStep.retry.
|
|
196
|
+
* Retries are in-process so ctx.retryContext is populated on each retry attempt.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* retry: { maxAttempts: 3, on: ['rate-limit', 'json-parse'] }
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
retry?: SmartRetryConfig;
|
|
182
204
|
/**
|
|
183
205
|
* @deprecated Prefer exporting `workerConfig` as a separate const from your worker file.
|
|
184
206
|
* The CLI will automatically extract it from the export. This parameter is kept for backward compatibility.
|
|
@@ -192,6 +214,8 @@ interface WorkerAgent<INPUT_SCHEMA extends ZodType<any>, OUTPUT> {
|
|
|
192
214
|
inputSchema: INPUT_SCHEMA;
|
|
193
215
|
outputSchema: ZodType<OUTPUT>;
|
|
194
216
|
workerConfig?: WorkerConfig;
|
|
217
|
+
/** Smart retry config set on this worker via createWorker({ retry }). */
|
|
218
|
+
retry?: SmartRetryConfig;
|
|
195
219
|
}
|
|
196
220
|
/**
|
|
197
221
|
* Creates a worker agent that can be dispatched to SQS/Lambda.
|
|
@@ -233,4 +257,4 @@ declare function createWorker<INPUT_SCHEMA extends ZodType<any>, OUTPUT>(config:
|
|
|
233
257
|
*/
|
|
234
258
|
declare function createLambdaEntrypoint<INPUT_SCHEMA extends ZodType<any>, OUTPUT>(agent: WorkerAgent<INPUT_SCHEMA, OUTPUT>): (event: aws_lambda.SQSEvent, context: aws_lambda.Context) => Promise<void>;
|
|
235
259
|
|
|
236
|
-
export { DispatchOptions, DispatchResult, type ScheduleConfig, type ScheduleEventConfig, type WorkerAgent, type WorkerAgentConfig, type WorkerConfig, WorkerHandler, createLambdaEntrypoint, createWorker };
|
|
260
|
+
export { DispatchOptions, DispatchResult, type ScheduleConfig, type ScheduleEventConfig, SmartRetryConfig, type WorkerAgent, type WorkerAgentConfig, type WorkerConfig, WorkerHandler, createLambdaEntrypoint, createWorker };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import * as aws_lambda from 'aws-lambda';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
2
|
+
import { DispatchOptions, DispatchResult } from './client.js';
|
|
3
|
+
export { DispatchQueueResult, SerializedContext, WorkerQueueRegistry, dispatch, dispatchLocal, dispatchQueue, dispatchWorker, getQueueStartUrl, getWorkersTriggerUrl } from './client.js';
|
|
4
4
|
import { WorkerHandler } from './handler.js';
|
|
5
|
-
export { DispatchWorkerOptions, JobRecord, JobStore, JobStoreUpdate, QueueNextStep, QueueRuntime,
|
|
5
|
+
export { DispatchWorkerOptions, JobRecord, JobStore, JobStoreUpdate, MapStepInputContext, QueueNextStep, QueueRuntime, SQSMessageBody, SQS_MAX_DELAY_SECONDS, TokenBudgetExceededError, TokenBudgetState, TokenUsage, WebhookPayload, WorkerHandlerParams, WorkerLogger, createLambdaHandler, createWorkerLogger, wrapHandlerForQueue } from './handler.js';
|
|
6
|
+
import { S as SmartRetryConfig } from './queue-B5n6YVQV.js';
|
|
7
|
+
export { B as BuiltInRetryPattern, b as ChainContext, C as CustomRetryPattern, H as HitlResumeContext, L as LoopContext, c as QUEUE_ORCHESTRATION_KEYS, Q as QueueStepOutput, R as RetryContext, a as RetryPattern, d as WorkerQueueConfig, e as WorkerQueueContext, W as WorkerQueueStep, f as defineWorkerQueue, g as executeWithRetry, m as matchesRetryPattern, r as repeatStep } from './queue-B5n6YVQV.js';
|
|
6
8
|
import { ZodType, z } from 'zod';
|
|
7
9
|
export { WorkersConfig, clearWorkersConfigCache, getWorkersConfig, resolveQueueUrl } from './config.js';
|
|
10
|
+
export { QueueOrchestrationFields, queueOrchestrationFieldsSchema, withQueueOrchestrationEnvelope } from './queueInputEnvelope.js';
|
|
11
|
+
export { defaultMapChainContinueFromPrevious, defaultMapChainPassthrough } from './chainMapDefaults.js';
|
|
12
|
+
export { HitlStepConfig, HitlUiSpec, defineHitlConfig } from './hitlConfig.js';
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Schedule event configuration for a worker.
|
|
@@ -144,6 +149,11 @@ interface WorkerConfig {
|
|
|
144
149
|
* ```
|
|
145
150
|
*/
|
|
146
151
|
schedule?: ScheduleConfig;
|
|
152
|
+
/**
|
|
153
|
+
* If set, this worker is deployed to the serverless project for this group.
|
|
154
|
+
* Do not use 'core' (reserved). Max 12 characters (serverless service name limits).
|
|
155
|
+
*/
|
|
156
|
+
group?: string;
|
|
147
157
|
/**
|
|
148
158
|
* SQS queue settings for this worker (used by @microfox/ai-worker-cli when generating serverless.yml).
|
|
149
159
|
*
|
|
@@ -179,6 +189,18 @@ interface WorkerAgentConfig<INPUT_SCHEMA extends ZodType<any>, OUTPUT> {
|
|
|
179
189
|
inputSchema: INPUT_SCHEMA;
|
|
180
190
|
outputSchema: ZodType<OUTPUT>;
|
|
181
191
|
handler: WorkerHandler<z.infer<INPUT_SCHEMA>, OUTPUT>;
|
|
192
|
+
/**
|
|
193
|
+
* Smart retry configuration for this worker.
|
|
194
|
+
* Applies whenever this worker runs (Lambda or local mode).
|
|
195
|
+
* Can be overridden per queue step via WorkerQueueStep.retry.
|
|
196
|
+
* Retries are in-process so ctx.retryContext is populated on each retry attempt.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* retry: { maxAttempts: 3, on: ['rate-limit', 'json-parse'] }
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
retry?: SmartRetryConfig;
|
|
182
204
|
/**
|
|
183
205
|
* @deprecated Prefer exporting `workerConfig` as a separate const from your worker file.
|
|
184
206
|
* The CLI will automatically extract it from the export. This parameter is kept for backward compatibility.
|
|
@@ -192,6 +214,8 @@ interface WorkerAgent<INPUT_SCHEMA extends ZodType<any>, OUTPUT> {
|
|
|
192
214
|
inputSchema: INPUT_SCHEMA;
|
|
193
215
|
outputSchema: ZodType<OUTPUT>;
|
|
194
216
|
workerConfig?: WorkerConfig;
|
|
217
|
+
/** Smart retry config set on this worker via createWorker({ retry }). */
|
|
218
|
+
retry?: SmartRetryConfig;
|
|
195
219
|
}
|
|
196
220
|
/**
|
|
197
221
|
* Creates a worker agent that can be dispatched to SQS/Lambda.
|
|
@@ -233,4 +257,4 @@ declare function createWorker<INPUT_SCHEMA extends ZodType<any>, OUTPUT>(config:
|
|
|
233
257
|
*/
|
|
234
258
|
declare function createLambdaEntrypoint<INPUT_SCHEMA extends ZodType<any>, OUTPUT>(agent: WorkerAgent<INPUT_SCHEMA, OUTPUT>): (event: aws_lambda.SQSEvent, context: aws_lambda.Context) => Promise<void>;
|
|
235
259
|
|
|
236
|
-
export { DispatchOptions, DispatchResult, type ScheduleConfig, type ScheduleEventConfig, type WorkerAgent, type WorkerAgentConfig, type WorkerConfig, WorkerHandler, createLambdaEntrypoint, createWorker };
|
|
260
|
+
export { DispatchOptions, DispatchResult, type ScheduleConfig, type ScheduleEventConfig, SmartRetryConfig, type WorkerAgent, type WorkerAgentConfig, type WorkerConfig, WorkerHandler, createLambdaEntrypoint, createWorker };
|