@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/dist/handler.d.ts
CHANGED
|
@@ -19,6 +19,25 @@ interface JobStoreUpdate {
|
|
|
19
19
|
name?: string;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
interface JobRecord {
|
|
23
|
+
jobId: string;
|
|
24
|
+
workerId: string;
|
|
25
|
+
status: 'queued' | 'running' | 'completed' | 'failed';
|
|
26
|
+
input: any;
|
|
27
|
+
output?: any;
|
|
28
|
+
error?: {
|
|
29
|
+
message: string;
|
|
30
|
+
stack?: string;
|
|
31
|
+
};
|
|
32
|
+
metadata?: Record<string, any>;
|
|
33
|
+
internalJobs?: Array<{
|
|
34
|
+
jobId: string;
|
|
35
|
+
workerId: string;
|
|
36
|
+
}>;
|
|
37
|
+
createdAt: string;
|
|
38
|
+
updatedAt: string;
|
|
39
|
+
completedAt?: string;
|
|
40
|
+
}
|
|
22
41
|
interface JobStore {
|
|
23
42
|
/**
|
|
24
43
|
* Update job in job store.
|
|
@@ -29,21 +48,38 @@ interface JobStore {
|
|
|
29
48
|
* Get current job record from job store.
|
|
30
49
|
* @returns Job record or null if not found
|
|
31
50
|
*/
|
|
32
|
-
get(): Promise<
|
|
51
|
+
get(): Promise<JobRecord | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Append an internal (child) job to the current job's internalJobs list.
|
|
54
|
+
* Used when this worker dispatches another worker (fire-and-forget or await).
|
|
55
|
+
*/
|
|
56
|
+
appendInternalJob?(entry: {
|
|
33
57
|
jobId: string;
|
|
34
58
|
workerId: string;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
}): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Get any job by jobId (e.g. to poll child job status when await: true).
|
|
62
|
+
* @returns Job record or null if not found
|
|
63
|
+
*/
|
|
64
|
+
getJob?(jobId: string): Promise<JobRecord | null>;
|
|
65
|
+
}
|
|
66
|
+
/** Max SQS delay in seconds (AWS limit). */
|
|
67
|
+
declare const SQS_MAX_DELAY_SECONDS = 900;
|
|
68
|
+
/** Options for ctx.dispatchWorker (worker-to-worker). */
|
|
69
|
+
interface DispatchWorkerOptions {
|
|
70
|
+
webhookUrl?: string;
|
|
71
|
+
metadata?: Record<string, any>;
|
|
72
|
+
/** Optional job ID for the child job (default: generated). */
|
|
73
|
+
jobId?: string;
|
|
74
|
+
/** If true, poll job store until child completes or fails; otherwise fire-and-forget. */
|
|
75
|
+
await?: boolean;
|
|
76
|
+
pollIntervalMs?: number;
|
|
77
|
+
pollTimeoutMs?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Delay before the child is invoked (fire-and-forget only; ignored when await is true).
|
|
80
|
+
* Uses SQS DelaySeconds (0–900). In local mode, waits this many seconds before sending the trigger request.
|
|
81
|
+
*/
|
|
82
|
+
delaySeconds?: number;
|
|
47
83
|
}
|
|
48
84
|
interface WorkerHandlerParams<INPUT, OUTPUT> {
|
|
49
85
|
input: INPUT;
|
|
@@ -56,10 +92,43 @@ interface WorkerHandlerParams<INPUT, OUTPUT> {
|
|
|
56
92
|
* Uses MongoDB directly when configured; never HTTP/origin URL.
|
|
57
93
|
*/
|
|
58
94
|
jobStore?: JobStore;
|
|
95
|
+
/**
|
|
96
|
+
* Dispatch another worker (fire-and-forget or await). Uses WORKER_QUEUE_URL_<SANITIZED_ID> env.
|
|
97
|
+
* Always provided by the runtime (Lambda and local).
|
|
98
|
+
*/
|
|
99
|
+
dispatchWorker: (workerId: string, input: unknown, options?: DispatchWorkerOptions) => Promise<{
|
|
100
|
+
jobId: string;
|
|
101
|
+
messageId?: string;
|
|
102
|
+
output?: unknown;
|
|
103
|
+
}>;
|
|
59
104
|
[key: string]: any;
|
|
60
105
|
};
|
|
61
106
|
}
|
|
62
107
|
type WorkerHandler<INPUT, OUTPUT> = (params: WorkerHandlerParams<INPUT, OUTPUT>) => Promise<OUTPUT>;
|
|
108
|
+
/** Result of getNextStep for queue chaining. */
|
|
109
|
+
interface QueueNextStep {
|
|
110
|
+
workerId: string;
|
|
111
|
+
delaySeconds?: number;
|
|
112
|
+
mapInputFromPrev?: string;
|
|
113
|
+
}
|
|
114
|
+
/** Runtime helpers for queue-aware wrappers (provided by generated registry). */
|
|
115
|
+
interface QueueRuntime {
|
|
116
|
+
getNextStep(queueId: string, stepIndex: number): QueueNextStep | undefined;
|
|
117
|
+
invokeMapInput?(queueId: string, stepIndex: number, prevOutput: unknown, initialInput: unknown): Promise<unknown> | unknown;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Wraps a user handler so that when the job has __workerQueue context (from
|
|
121
|
+
* dispatchQueue or queue cron), it dispatches the next worker in the sequence
|
|
122
|
+
* after the handler completes. Uses literal worker IDs so the CLI env injection
|
|
123
|
+
* picks up WORKER_QUEUE_URL_* for next-step workers.
|
|
124
|
+
*/
|
|
125
|
+
declare function wrapHandlerForQueue<INPUT, OUTPUT>(handler: WorkerHandler<INPUT, OUTPUT>, queueRuntime: QueueRuntime): WorkerHandler<INPUT & {
|
|
126
|
+
__workerQueue?: {
|
|
127
|
+
id: string;
|
|
128
|
+
stepIndex: number;
|
|
129
|
+
initialInput: unknown;
|
|
130
|
+
};
|
|
131
|
+
}, OUTPUT>;
|
|
63
132
|
interface SQSMessageBody {
|
|
64
133
|
workerId: string;
|
|
65
134
|
jobId: string;
|
|
@@ -93,4 +162,4 @@ interface WebhookPayload {
|
|
|
93
162
|
*/
|
|
94
163
|
declare function createLambdaHandler<INPUT, OUTPUT>(handler: WorkerHandler<INPUT, OUTPUT>, outputSchema?: ZodType<OUTPUT>): (event: SQSEvent, context: Context) => Promise<void>;
|
|
95
164
|
|
|
96
|
-
export { type JobStore, type JobStoreUpdate, type SQSMessageBody, type WebhookPayload, type WorkerHandler, type WorkerHandlerParams, createLambdaHandler };
|
|
165
|
+
export { type DispatchWorkerOptions, type JobRecord, type JobStore, type JobStoreUpdate, type QueueNextStep, type QueueRuntime, type SQSMessageBody, SQS_MAX_DELAY_SECONDS, type WebhookPayload, type WorkerHandler, type WorkerHandlerParams, createLambdaHandler, wrapHandlerForQueue };
|