@microfox/ai-worker 1.0.4 → 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.
Files changed (69) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +22 -0
  3. package/dist/chainMapDefaults.d.mts +21 -0
  4. package/dist/chainMapDefaults.d.ts +21 -0
  5. package/dist/chainMapDefaults.js +59 -0
  6. package/dist/chainMapDefaults.js.map +1 -0
  7. package/dist/chainMapDefaults.mjs +10 -0
  8. package/dist/chainMapDefaults.mjs.map +1 -0
  9. package/dist/chunk-BCRJIFKB.mjs +9 -0
  10. package/dist/chunk-BCRJIFKB.mjs.map +1 -0
  11. package/dist/{chunk-72XGFZCE.mjs → chunk-CILTGUUQ.mjs} +14 -3
  12. package/dist/chunk-CILTGUUQ.mjs.map +1 -0
  13. package/dist/{chunk-7LQNS2SG.mjs → chunk-QHX55IML.mjs} +442 -56
  14. package/dist/chunk-QHX55IML.mjs.map +1 -0
  15. package/dist/chunk-SQB5FQCZ.mjs +21 -0
  16. package/dist/chunk-SQB5FQCZ.mjs.map +1 -0
  17. package/dist/{chunk-AOXGONGI.mjs → chunk-T7DRPKR6.mjs} +7 -5
  18. package/dist/chunk-T7DRPKR6.mjs.map +1 -0
  19. package/dist/chunk-XCKWV2WZ.mjs +34 -0
  20. package/dist/chunk-XCKWV2WZ.mjs.map +1 -0
  21. package/dist/chunk-ZW4PNCDH.mjs +17 -0
  22. package/dist/chunk-ZW4PNCDH.mjs.map +1 -0
  23. package/dist/client.d.mts +148 -2
  24. package/dist/client.d.ts +148 -2
  25. package/dist/client.js +13 -2
  26. package/dist/client.js.map +1 -1
  27. package/dist/client.mjs +1 -1
  28. package/dist/handler.d.mts +121 -23
  29. package/dist/handler.d.ts +121 -23
  30. package/dist/handler.js +450 -58
  31. package/dist/handler.js.map +1 -1
  32. package/dist/handler.mjs +5 -2
  33. package/dist/hitlConfig.d.mts +46 -0
  34. package/dist/hitlConfig.d.ts +46 -0
  35. package/dist/hitlConfig.js +33 -0
  36. package/dist/hitlConfig.js.map +1 -0
  37. package/dist/hitlConfig.mjs +8 -0
  38. package/dist/hitlConfig.mjs.map +1 -0
  39. package/dist/index.d.mts +23 -4
  40. package/dist/index.d.ts +23 -4
  41. package/dist/index.js +575 -74
  42. package/dist/index.js.map +1 -1
  43. package/dist/index.mjs +78 -20
  44. package/dist/index.mjs.map +1 -1
  45. package/dist/queue-B5n6YVQV.d.ts +306 -0
  46. package/dist/queue-DaR2UuZi.d.mts +306 -0
  47. package/dist/queue.d.mts +3 -0
  48. package/dist/queue.d.ts +3 -0
  49. package/dist/queue.js +47 -0
  50. package/dist/queue.js.map +1 -0
  51. package/dist/queue.mjs +12 -0
  52. package/dist/queue.mjs.map +1 -0
  53. package/dist/queueInputEnvelope.d.mts +31 -0
  54. package/dist/queueInputEnvelope.d.ts +31 -0
  55. package/dist/queueInputEnvelope.js +42 -0
  56. package/dist/queueInputEnvelope.js.map +1 -0
  57. package/dist/queueInputEnvelope.mjs +10 -0
  58. package/dist/queueInputEnvelope.mjs.map +1 -0
  59. package/dist/queueJobStore.d.mts +3 -2
  60. package/dist/queueJobStore.d.ts +3 -2
  61. package/dist/queueJobStore.js +6 -4
  62. package/dist/queueJobStore.js.map +1 -1
  63. package/dist/queueJobStore.mjs +1 -1
  64. package/package.json +7 -2
  65. package/dist/chunk-72XGFZCE.mjs.map +0 -1
  66. package/dist/chunk-7LQNS2SG.mjs.map +0 -1
  67. package/dist/chunk-AOXGONGI.mjs.map +0 -1
  68. package/dist/client-BqSJQ9mZ.d.mts +0 -183
  69. 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,8 @@
1
+ import {
2
+ defineHitlConfig
3
+ } from "./chunk-BCRJIFKB.mjs";
4
+ import "./chunk-BJTO5JO5.mjs";
5
+ export {
6
+ defineHitlConfig
7
+ };
8
+ //# sourceMappingURL=hitlConfig.mjs.map
@@ -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 { D as DispatchOptions, a as DispatchResult } from './client-BqSJQ9mZ.mjs';
3
- export { b as DispatchQueueResult, S as SerializedContext, j as WorkerQueueConfig, k as WorkerQueueContext, W as WorkerQueueRegistry, i as WorkerQueueStep, l as defineWorkerQueue, d as dispatch, f as dispatchLocal, h as dispatchQueue, e as dispatchWorker, c as getQueueStartUrl, g as getWorkersTriggerUrl } from './client-BqSJQ9mZ.mjs';
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, QueueStepOutput, SQSMessageBody, SQS_MAX_DELAY_SECONDS, WebhookPayload, WorkerHandlerParams, WorkerLogger, createLambdaHandler, createWorkerLogger, wrapHandlerForQueue } from './handler.mjs';
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.
@@ -184,6 +189,18 @@ interface WorkerAgentConfig<INPUT_SCHEMA extends ZodType<any>, OUTPUT> {
184
189
  inputSchema: INPUT_SCHEMA;
185
190
  outputSchema: ZodType<OUTPUT>;
186
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;
187
204
  /**
188
205
  * @deprecated Prefer exporting `workerConfig` as a separate const from your worker file.
189
206
  * The CLI will automatically extract it from the export. This parameter is kept for backward compatibility.
@@ -197,6 +214,8 @@ interface WorkerAgent<INPUT_SCHEMA extends ZodType<any>, OUTPUT> {
197
214
  inputSchema: INPUT_SCHEMA;
198
215
  outputSchema: ZodType<OUTPUT>;
199
216
  workerConfig?: WorkerConfig;
217
+ /** Smart retry config set on this worker via createWorker({ retry }). */
218
+ retry?: SmartRetryConfig;
200
219
  }
201
220
  /**
202
221
  * Creates a worker agent that can be dispatched to SQS/Lambda.
@@ -238,4 +257,4 @@ declare function createWorker<INPUT_SCHEMA extends ZodType<any>, OUTPUT>(config:
238
257
  */
239
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>;
240
259
 
241
- 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 { D as DispatchOptions, a as DispatchResult } from './client-BqSJQ9mZ.js';
3
- export { b as DispatchQueueResult, S as SerializedContext, j as WorkerQueueConfig, k as WorkerQueueContext, W as WorkerQueueRegistry, i as WorkerQueueStep, l as defineWorkerQueue, d as dispatch, f as dispatchLocal, h as dispatchQueue, e as dispatchWorker, c as getQueueStartUrl, g as getWorkersTriggerUrl } from './client-BqSJQ9mZ.js';
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, QueueStepOutput, SQSMessageBody, SQS_MAX_DELAY_SECONDS, WebhookPayload, WorkerHandlerParams, WorkerLogger, createLambdaHandler, createWorkerLogger, wrapHandlerForQueue } from './handler.js';
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.
@@ -184,6 +189,18 @@ interface WorkerAgentConfig<INPUT_SCHEMA extends ZodType<any>, OUTPUT> {
184
189
  inputSchema: INPUT_SCHEMA;
185
190
  outputSchema: ZodType<OUTPUT>;
186
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;
187
204
  /**
188
205
  * @deprecated Prefer exporting `workerConfig` as a separate const from your worker file.
189
206
  * The CLI will automatically extract it from the export. This parameter is kept for backward compatibility.
@@ -197,6 +214,8 @@ interface WorkerAgent<INPUT_SCHEMA extends ZodType<any>, OUTPUT> {
197
214
  inputSchema: INPUT_SCHEMA;
198
215
  outputSchema: ZodType<OUTPUT>;
199
216
  workerConfig?: WorkerConfig;
217
+ /** Smart retry config set on this worker via createWorker({ retry }). */
218
+ retry?: SmartRetryConfig;
200
219
  }
201
220
  /**
202
221
  * Creates a worker agent that can be dispatched to SQS/Lambda.
@@ -238,4 +257,4 @@ declare function createWorker<INPUT_SCHEMA extends ZodType<any>, OUTPUT>(config:
238
257
  */
239
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>;
240
259
 
241
- 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 };