@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
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/queueJobStore.ts"],"sourcesContent":["/**\n * Queue job store for worker queues (MongoDB or Upstash Redis).\n *\n * Mirrors the worker_jobs pattern but optimized for queues:\n * - MongoDB: collection `queue_jobs` (configurable via MONGODB_QUEUE_JOBS_COLLECTION)\n * - Upstash Redis: JSON blob per queue job with compact step entries\n *\n * This module is runtime-only (used by Lambda workers). Next.js APIs can read\n * the same collections/keys to show queue progress.\n */\n\nimport type { Redis } from '@upstash/redis';\nimport { Redis as UpstashRedis } from '@upstash/redis';\nimport { MongoClient, type Collection } from 'mongodb';\n\ntype QueueJobStep = {\n workerId: string;\n workerJobId: string;\n status: 'queued' | 'running' | 'completed' | 'failed';\n input?: unknown;\n output?: unknown;\n error?: { message: string };\n startedAt?: string;\n completedAt?: string;\n};\n\ntype QueueJobDoc = {\n _id: string; // queueJobId\n id: string;\n queueId: string;\n status: 'running' | 'completed' | 'failed' | 'partial';\n steps: QueueJobStep[];\n metadata?: Record<string, unknown>;\n createdAt: string;\n updatedAt: string;\n completedAt?: string;\n};\n\n\n// === Mongo backend (shares connection pattern with mongoJobStore) ===\n\nconst mongoUri = process.env.DATABASE_MONGODB_URI || process.env.MONGODB_URI;\nconst mongoDbName =\n process.env.DATABASE_MONGODB_DB ||\n process.env.MONGODB_DB ||\n 'mediamake';\nconst mongoQueueCollectionName =\n process.env.MONGODB_QUEUE_JOBS_COLLECTION || 'queue_jobs';\n\nlet mongoClientPromise: Promise<MongoClient> | null = null;\n\nasync function getMongoClient(): Promise<MongoClient> {\n if (!mongoUri) {\n throw new Error(\n 'MongoDB URI required for queue job store. Set DATABASE_MONGODB_URI or MONGODB_URI.'\n );\n }\n if (!mongoClientPromise) {\n mongoClientPromise = new MongoClient(mongoUri, {\n maxPoolSize: 10,\n minPoolSize: 0,\n serverSelectionTimeoutMS: 10_000,\n }).connect();\n }\n return mongoClientPromise;\n}\n\nasync function getMongoQueueCollection(): Promise<Collection<QueueJobDoc>> {\n const client = await getMongoClient();\n return client.db(mongoDbName).collection<QueueJobDoc>(mongoQueueCollectionName);\n}\n\n// === Redis backend (Upstash) ===\n\nconst redisUrl =\n process.env.WORKER_UPSTASH_REDIS_REST_URL ||\n process.env.UPSTASH_REDIS_REST_URL ||\n process.env.UPSTASH_REDIS_URL;\nconst redisToken =\n process.env.WORKER_UPSTASH_REDIS_REST_TOKEN ||\n process.env.UPSTASH_REDIS_REST_TOKEN ||\n process.env.UPSTASH_REDIS_TOKEN;\nconst queueKeyPrefix =\n process.env.WORKER_UPSTASH_REDIS_QUEUE_PREFIX ||\n process.env.UPSTASH_REDIS_QUEUE_PREFIX ||\n 'worker:queue-jobs:';\n\nconst defaultTtlSeconds = 60 * 60 * 24 * 7; // 7 days\nconst queueJobTtlSeconds =\n typeof process.env.WORKER_QUEUE_JOBS_TTL_SECONDS === 'string'\n ? parseInt(process.env.WORKER_QUEUE_JOBS_TTL_SECONDS, 10) || defaultTtlSeconds\n : typeof process.env.WORKER_JOBS_TTL_SECONDS === 'string'\n ? parseInt(process.env.WORKER_JOBS_TTL_SECONDS, 10) || defaultTtlSeconds\n : defaultTtlSeconds;\n\nlet redisClient: Redis | null = null;\n\nfunction getRedis(): Redis {\n if (!redisUrl || !redisToken) {\n throw new Error(\n 'Upstash Redis configuration missing for queue job store. Set WORKER_UPSTASH_REDIS_REST_URL and WORKER_UPSTASH_REDIS_REST_TOKEN (or UPSTASH_REDIS_REST_URL/UPSTASH_REDIS_REST_TOKEN).'\n );\n }\n if (!redisClient) {\n redisClient = new UpstashRedis({\n url: redisUrl,\n token: redisToken,\n });\n }\n return redisClient;\n}\n\nfunction queueKey(id: string): string {\n return `${queueKeyPrefix}${id}`;\n}\n\ntype QueueJobRecord = Omit<QueueJobDoc, '_id'>;\n\n/** Hash values from Upstash hgetall may be auto-parsed (array/object) or raw strings. */\nfunction stepsFromHash(val: unknown): QueueJobStep[] {\n if (Array.isArray(val)) return val as QueueJobStep[];\n if (typeof val === 'string') {\n try {\n const parsed = JSON.parse(val) as QueueJobStep[];\n return Array.isArray(parsed) ? parsed : [];\n } catch {\n return [];\n }\n }\n return [];\n}\n\nfunction metadataFromHash(val: unknown): Record<string, unknown> {\n if (val && typeof val === 'object' && !Array.isArray(val)) return val as Record<string, unknown>;\n if (typeof val === 'string') {\n try {\n const parsed = JSON.parse(val) as Record<string, unknown>;\n return parsed && typeof parsed === 'object' ? parsed : {};\n } catch {\n return {};\n }\n }\n return {};\n}\n\nasync function loadQueueJobRedis(queueJobId: string): Promise<QueueJobRecord | null> {\n const redis = getRedis();\n const key = queueKey(queueJobId);\n const data = await redis.hgetall(key);\n if (!data || typeof data !== 'object' || Object.keys(data).length === 0) return null;\n const d = data as Record<string, unknown>;\n const record: QueueJobRecord = {\n id: (d.id === undefined ? queueJobId : String(d.id)) as string,\n queueId: String(d.queueId ?? ''),\n status: (String(d.status ?? 'running') as QueueJobRecord['status']),\n steps: stepsFromHash(d.steps),\n metadata: metadataFromHash(d.metadata),\n createdAt: String(d.createdAt ?? new Date().toISOString()),\n updatedAt: String(d.updatedAt ?? new Date().toISOString()),\n completedAt: d.completedAt != null ? String(d.completedAt) : undefined,\n };\n return record;\n}\n\nasync function saveQueueJobRedis(record: QueueJobRecord): Promise<void> {\n const redis = getRedis();\n const key = queueKey(record.id);\n const now = new Date().toISOString();\n const toSet: Record<string, string> = {\n id: record.id,\n queueId: record.queueId,\n status: record.status,\n steps: JSON.stringify(record.steps || []),\n metadata: JSON.stringify(record.metadata || {}),\n createdAt: record.createdAt || now,\n updatedAt: record.updatedAt || now,\n };\n if (record.completedAt) {\n toSet.completedAt = record.completedAt;\n }\n await redis.hset(key, toSet);\n if (queueJobTtlSeconds > 0) {\n await redis.expire(key, queueJobTtlSeconds);\n }\n}\n\n// === Backend selection ===\n\nfunction getStoreType(): 'mongodb' | 'upstash-redis' {\n const t = (process.env.WORKER_DATABASE_TYPE || 'upstash-redis').toLowerCase();\n return t === 'mongodb' ? 'mongodb' : 'upstash-redis';\n}\n\nfunction preferMongo(): boolean {\n return getStoreType() === 'mongodb' && Boolean(mongoUri?.trim());\n}\n\nfunction preferRedis(): boolean {\n return getStoreType() !== 'mongodb' && Boolean((redisUrl || '').trim() && (redisToken || '').trim());\n}\n\n// === Public API used from handler.ts ===\n\nexport async function upsertInitialQueueJob(options: {\n queueJobId: string;\n queueId: string;\n firstWorkerId: string;\n firstWorkerJobId: string;\n metadata?: Record<string, any>;\n}): Promise<void> {\n const { queueJobId, queueId, firstWorkerId, firstWorkerJobId, metadata } = options;\n const now = new Date().toISOString();\n\n if (preferMongo()) {\n const coll = await getMongoQueueCollection();\n const existing = await coll.findOne({ _id: queueJobId });\n if (existing) {\n const steps = existing.steps ?? [];\n if (steps.length === 0) {\n steps.push({\n workerId: firstWorkerId,\n workerJobId: firstWorkerJobId,\n status: 'queued',\n });\n }\n await coll.updateOne(\n { _id: queueJobId },\n {\n $set: {\n steps,\n updatedAt: now,\n },\n }\n );\n } else {\n const doc: QueueJobDoc = {\n _id: queueJobId,\n id: queueJobId,\n queueId,\n status: 'running',\n steps: [\n {\n workerId: firstWorkerId,\n workerJobId: firstWorkerJobId,\n status: 'queued',\n },\n ],\n metadata: metadata ?? {},\n createdAt: now,\n updatedAt: now,\n };\n await coll.updateOne(\n { _id: queueJobId },\n { $set: doc },\n { upsert: true }\n );\n }\n return;\n }\n\n if (preferRedis()) {\n const existing = await loadQueueJobRedis(queueJobId);\n if (existing) {\n // Ensure we have at least one step\n if (!existing.steps || existing.steps.length === 0) {\n existing.steps = [\n {\n workerId: firstWorkerId,\n workerJobId: firstWorkerJobId,\n status: 'queued',\n },\n ];\n }\n existing.updatedAt = now;\n await saveQueueJobRedis(existing);\n } else {\n const record: QueueJobRecord = {\n id: queueJobId,\n queueId,\n status: 'running',\n steps: [\n {\n workerId: firstWorkerId,\n workerJobId: firstWorkerJobId,\n status: 'queued',\n },\n ],\n metadata: metadata ?? {},\n createdAt: now,\n updatedAt: now,\n };\n await saveQueueJobRedis(record);\n }\n }\n}\n\nexport async function updateQueueJobStepInStore(options: {\n queueJobId: string;\n queueId?: string;\n stepIndex: number;\n workerId: string;\n workerJobId: string;\n status: 'running' | 'completed' | 'failed';\n input?: unknown;\n output?: unknown;\n error?: { message: string };\n}): Promise<void> {\n const { queueJobId, stepIndex, status, input, output, error } = options;\n const now = new Date().toISOString();\n\n if (preferMongo()) {\n const coll = await getMongoQueueCollection();\n const existing = await coll.findOne({ _id: queueJobId });\n if (!existing) return;\n const step = existing.steps[stepIndex];\n if (!step) return;\n\n const mergedStep: QueueJobStep = {\n ...step,\n status,\n ...(input !== undefined && { input }),\n ...(output !== undefined && { output }),\n ...(error !== undefined && { error }),\n startedAt: step.startedAt ?? (status === 'running' ? now : step.startedAt),\n completedAt:\n step.completedAt ??\n (status === 'completed' || status === 'failed' ? now : step.completedAt),\n };\n\n const setDoc: Partial<QueueJobDoc> & { steps: QueueJobStep[] } = {\n steps: existing.steps,\n updatedAt: now,\n };\n setDoc.steps[stepIndex] = mergedStep;\n if (status === 'failed') {\n setDoc.status = 'failed';\n if (!existing.completedAt) setDoc.completedAt = now;\n } else if (status === 'completed' && stepIndex === existing.steps.length - 1) {\n setDoc.status = 'completed';\n if (!existing.completedAt) setDoc.completedAt = now;\n }\n\n await coll.updateOne(\n { _id: queueJobId },\n {\n $set: setDoc,\n }\n );\n return;\n }\n\n if (preferRedis()) {\n const existing = await loadQueueJobRedis(queueJobId);\n if (!existing) {\n // No queue job; nothing to update\n return;\n }\n const steps = existing.steps || [];\n const step = steps[stepIndex];\n if (!step) {\n return;\n }\n step.status = status;\n if (input !== undefined) step.input = input;\n if (output !== undefined) step.output = output;\n if (error !== undefined) step.error = error;\n if (status === 'running') {\n step.startedAt = step.startedAt ?? now;\n }\n if (status === 'completed' || status === 'failed') {\n step.completedAt = step.completedAt ?? now;\n }\n\n existing.steps = steps;\n existing.updatedAt = now;\n if (status === 'failed') {\n existing.status = 'failed';\n existing.completedAt = existing.completedAt ?? now;\n } else if (status === 'completed' && stepIndex === steps.length - 1) {\n existing.status = 'completed';\n existing.completedAt = existing.completedAt ?? now;\n }\n await saveQueueJobRedis(existing);\n }\n}\n\nexport async function appendQueueJobStepInStore(options: {\n queueJobId: string;\n queueId?: string;\n workerId: string;\n workerJobId: string;\n}): Promise<void> {\n const { queueJobId, workerId, workerJobId } = options;\n const now = new Date().toISOString();\n\n if (preferMongo()) {\n const coll = await getMongoQueueCollection();\n await coll.updateOne(\n { _id: queueJobId },\n {\n $push: {\n steps: {\n workerId,\n workerJobId,\n status: 'queued',\n } as QueueJobStep,\n },\n $set: { updatedAt: now },\n }\n );\n return;\n }\n\n if (preferRedis()) {\n const existing = await loadQueueJobRedis(queueJobId);\n if (!existing) return;\n const steps = existing.steps || [];\n steps.push({\n workerId,\n workerJobId,\n status: 'queued',\n });\n existing.steps = steps;\n existing.updatedAt = now;\n await saveQueueJobRedis(existing);\n }\n}\n\n/**\n * Load a queue job by ID (for mapping context: previous step outputs).\n * Used by wrapHandlerForQueue when invoking mapInputFromPrev with previousOutputs.\n */\nexport async function getQueueJob(queueJobId: string): Promise<{\n id: string;\n queueId: string;\n status: string;\n steps: Array<{ workerId: string; workerJobId: string; status: string; output?: unknown }>;\n} | null> {\n if (preferMongo()) {\n const coll = await getMongoQueueCollection();\n const doc = await coll.findOne({ _id: queueJobId });\n if (!doc) return null;\n return {\n id: doc.id ?? queueJobId,\n queueId: doc.queueId,\n status: doc.status,\n steps: (doc.steps ?? []).map((s: QueueJobStep) => ({\n workerId: s.workerId,\n workerJobId: s.workerJobId,\n status: s.status,\n output: s.output,\n })),\n };\n }\n if (preferRedis()) {\n const record = await loadQueueJobRedis(queueJobId);\n if (!record) return null;\n return {\n id: record.id,\n queueId: record.queueId,\n status: record.status,\n steps: (record.steps ?? []).map((s) => ({\n workerId: s.workerId,\n workerJobId: s.workerJobId,\n status: s.status,\n output: s.output,\n })),\n };\n }\n return null;\n}\n\n"],"mappings":";AAYA,SAAS,SAAS,oBAAoB;AACtC,SAAS,mBAAoC;AA4B7C,IAAM,WAAW,QAAQ,IAAI,wBAAwB,QAAQ,IAAI;AACjE,IAAM,cACJ,QAAQ,IAAI,uBACZ,QAAQ,IAAI,cACZ;AACF,IAAM,2BACJ,QAAQ,IAAI,iCAAiC;AAE/C,IAAI,qBAAkD;AAEtD,eAAe,iBAAuC;AAC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AsB,YAAY,YAKxB;AACR,MAAI,YAAY,GAAG;AACjB,UAAM,OAAO,MAAM,wBAAwB;AAC3C,UAAM,MAAM,MAAM,KAAK,QAAQ,EAAE,KAAK,WAAW,CAAC;AAClD,QAAI,CAAC,IAAK,QAAO;AACjB,WAAO;AAAA,MACL,IAAI,IAAI,MAAM;AAAA,MACd,SAAS,IAAI;AAAA,MACb,QAAQ,IAAI;AAAA,MACZ,QAAQ,IAAI,SAAS,CAAC,GAAG,IAAI,CAAC,OAAqB;AAAA,QACjD,UAAU,EAAE;AAAA,QACZ,aAAa,EAAE;AAAA,QACf,QAAQ,EAAE;AAAA,QACV,QAAQ,EAAE;AAAA,MACZ,EAAE;AAAA,IACJ;AAAA,EACF;AACA,MAAI,YAAY,GAAG;AACjB,UAAM,SAAS,MAAM,kBAAkB,UAAU;AACjD,QAAI,CAAC,OAAQ,QAAO;AACpB,WAAO;AAAA,MACL,IAAI,OAAO;AAAA,MACX,SAAS,OAAO;AAAA,MAChB,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO;AAAA,QACtC,UAAU,EAAE;AAAA,QACZ,aAAa,EAAE;AAAA,QACf,QAAQ,EAAE;AAAA,QACV,QAAQ,EAAE;AAAA,MACZ,EAAE;AAAA,IACJ;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
@@ -1,183 +0,0 @@
1
- import { ZodType, z } from 'zod';
2
-
3
- /**
4
- * Queue definition and context types for worker queues.
5
- *
6
- * These types are used at code-time by .queue.ts files and at runtime
7
- * by the client and generated registry/queue wrappers.
8
- */
9
- interface WorkerQueueStep {
10
- /** Worker ID for this step. Must match an existing worker id. */
11
- workerId: string;
12
- /**
13
- * Optional delay (in seconds) before this step is executed.
14
- * Implemented via SQS DelaySeconds (0–900).
15
- */
16
- delaySeconds?: number;
17
- /**
18
- * Optional name of a mapping function exported from the .queue.ts file.
19
- * The function is called with (initialInput, previousOutputs):
20
- * - initialInput: original input passed to dispatchQueue (always first, for best DX).
21
- * - previousOutputs: array of { stepIndex, workerId, output } for steps 0..current-1.
22
- * Use any prior step's output; the immediate previous step is previousOutputs[previousOutputs.length - 1]?.output.
23
- */
24
- mapInputFromPrev?: string;
25
- }
26
- interface WorkerQueueConfig<InitialInput = any, StepOutput = any> {
27
- /** Stable queue identifier, e.g. "cost-usage". */
28
- id: string;
29
- /** Ordered list of workers forming the queue. */
30
- steps: WorkerQueueStep[];
31
- /**
32
- * Optional schedule for the queue (cron or rate).
33
- * When set, the CLI generates a queue-starter Lambda triggered by this schedule.
34
- * Example: 'cron(0 3 * * ? *)' for daily at 03:00 UTC.
35
- */
36
- schedule?: string | {
37
- rate: string;
38
- enabled?: boolean;
39
- input?: Record<string, any>;
40
- };
41
- _initialInputType?: InitialInput;
42
- _stepOutputType?: StepOutput;
43
- }
44
- /**
45
- * Queue execution context that is embedded into job input/metadata so
46
- * queue-aware wrappers can determine where they are in the queue.
47
- */
48
- interface WorkerQueueContext<InitialInput = any> {
49
- id: string;
50
- stepIndex: number;
51
- initialInput: InitialInput;
52
- /** Queue job ID (same as first worker's jobId) for tracking progress. */
53
- queueJobId?: string;
54
- }
55
- /**
56
- * Identity helper for defining worker queues in .queue.ts files.
57
- * This is primarily for type safety and CLI discovery.
58
- */
59
- declare function defineWorkerQueue<T extends WorkerQueueConfig>(config: T): T;
60
-
61
- /**
62
- * Client for dispatching background worker jobs.
63
- *
64
- * In production, dispatching happens via the workers HTTP API:
65
- * POST /workers/trigger -> enqueues message to SQS on the workers service side
66
- *
67
- * This avoids requiring AWS credentials in your Next.js app.
68
- */
69
-
70
- interface WorkerQueueRegistry {
71
- getQueueById(queueId: string): WorkerQueueConfig | undefined;
72
- /** (initialInput, previousOutputs) for best DX: derive next input from original request and all prior step outputs. */
73
- invokeMapInput?: (queueId: string, stepIndex: number, initialInput: unknown, previousOutputs: Array<{
74
- stepIndex: number;
75
- workerId: string;
76
- output: unknown;
77
- }>) => Promise<unknown> | unknown;
78
- }
79
- interface DispatchOptions {
80
- /**
81
- * Optional webhook callback URL to notify when the job finishes.
82
- * Only called when provided. Default: no webhook (use job store / MongoDB only).
83
- */
84
- webhookUrl?: string;
85
- /**
86
- * Controls how dispatch executes.
87
- * - "auto" (default): local inline execution in development unless WORKERS_LOCAL_MODE=false.
88
- * - "local": force inline execution (no SQS).
89
- * - "remote": force SQS/Lambda dispatch even in development.
90
- */
91
- mode?: 'auto' | 'local' | 'remote';
92
- jobId?: string;
93
- metadata?: Record<string, any>;
94
- /**
95
- * In-memory queue registry for dispatchQueue. Required when using dispatchQueue.
96
- * Pass a registry that imports from your .queue.ts definitions (works on Vercel/serverless).
97
- */
98
- registry?: WorkerQueueRegistry;
99
- /**
100
- * Optional callback to create a queue job record before dispatching.
101
- * Called with queueJobId (= first worker's jobId), queueId, and firstStep.
102
- */
103
- onCreateQueueJob?: (params: {
104
- queueJobId: string;
105
- queueId: string;
106
- firstStep: {
107
- workerId: string;
108
- workerJobId: string;
109
- };
110
- metadata?: Record<string, unknown>;
111
- }) => Promise<void>;
112
- }
113
- interface DispatchResult {
114
- messageId: string;
115
- status: 'queued';
116
- jobId: string;
117
- }
118
- interface DispatchQueueResult extends DispatchResult {
119
- queueId: string;
120
- }
121
- interface SerializedContext {
122
- requestId?: string;
123
- userId?: string;
124
- traceId?: string;
125
- [key: string]: any;
126
- }
127
- /**
128
- * Derives the full /workers/trigger URL from env.
129
- * Exported for use by local dispatchWorker (worker-to-worker in dev).
130
- * Server-side only; clients should use useWorkflowJob with your app's /api/workflows routes.
131
- *
132
- * Env vars:
133
- * - WORKER_BASE_URL: base URL of the workers service (e.g. https://.../prod)
134
- * - WORKERS_TRIGGER_API_URL / WORKERS_CONFIG_API_URL: legacy, still supported
135
- */
136
- declare function getWorkersTriggerUrl(): string;
137
- /**
138
- * URL for the queue start endpoint (dispatch proxy). Use this so queue starts
139
- * go through the queue handler Lambda for easier debugging (one log stream per queue).
140
- */
141
- declare function getQueueStartUrl(queueId: string): string;
142
- /**
143
- * Dispatches a background worker job to SQS.
144
- *
145
- * @param workerId - The ID of the worker to dispatch
146
- * @param input - The input data for the worker (will be validated against inputSchema)
147
- * @param inputSchema - Zod schema for input validation
148
- * @param options - Dispatch options including webhook URL
149
- * @param ctx - Optional context object (only serializable parts will be sent)
150
- * @returns Promise resolving to dispatch result with messageId and jobId
151
- */
152
- declare function dispatch<INPUT_SCHEMA extends ZodType<any>>(workerId: string, input: z.input<INPUT_SCHEMA>, inputSchema: INPUT_SCHEMA, options: DispatchOptions, ctx?: any): Promise<DispatchResult>;
153
- /**
154
- * Dispatch a worker by ID without importing the worker module.
155
- * Sends to the workers trigger API (WORKER_BASE_URL). No input schema validation at call site.
156
- *
157
- * @param workerId - The worker ID (e.g. 'echo', 'data-processor')
158
- * @param input - Input payload (object or undefined)
159
- * @param options - Optional jobId, webhookUrl, metadata
160
- * @param ctx - Optional context (serializable parts sent in the request)
161
- * @returns Promise resolving to { messageId, status: 'queued', jobId }
162
- */
163
- declare function dispatchWorker(workerId: string, input?: Record<string, unknown>, options?: DispatchOptions, ctx?: any): Promise<DispatchResult>;
164
- /**
165
- * Local development mode: runs the handler immediately in the same process.
166
- * This bypasses SQS and Lambda for faster iteration during development.
167
- *
168
- * @param handler - The worker handler function
169
- * @param input - The input data
170
- * @param ctx - The context object
171
- * @returns The handler result
172
- */
173
- declare function dispatchLocal<INPUT, OUTPUT>(handler: (params: {
174
- input: INPUT;
175
- ctx: any;
176
- }) => Promise<OUTPUT>, input: INPUT, ctx?: any): Promise<OUTPUT>;
177
- /**
178
- * Dispatches a queue by ID. POSTs to the queue-start API; the queue-start handler creates the queue job.
179
- * Pass the first worker's input directly (no registry required).
180
- */
181
- declare function dispatchQueue<InitialInput = any>(queueId: string, initialInput?: InitialInput, options?: DispatchOptions, _ctx?: any): Promise<DispatchQueueResult>;
182
-
183
- export { type DispatchOptions as D, type SerializedContext as S, type WorkerQueueRegistry as W, type DispatchResult as a, type DispatchQueueResult as b, getQueueStartUrl as c, dispatch as d, dispatchWorker as e, dispatchLocal as f, getWorkersTriggerUrl as g, dispatchQueue as h, type WorkerQueueStep as i, type WorkerQueueConfig as j, type WorkerQueueContext as k, defineWorkerQueue as l };
@@ -1,183 +0,0 @@
1
- import { ZodType, z } from 'zod';
2
-
3
- /**
4
- * Queue definition and context types for worker queues.
5
- *
6
- * These types are used at code-time by .queue.ts files and at runtime
7
- * by the client and generated registry/queue wrappers.
8
- */
9
- interface WorkerQueueStep {
10
- /** Worker ID for this step. Must match an existing worker id. */
11
- workerId: string;
12
- /**
13
- * Optional delay (in seconds) before this step is executed.
14
- * Implemented via SQS DelaySeconds (0–900).
15
- */
16
- delaySeconds?: number;
17
- /**
18
- * Optional name of a mapping function exported from the .queue.ts file.
19
- * The function is called with (initialInput, previousOutputs):
20
- * - initialInput: original input passed to dispatchQueue (always first, for best DX).
21
- * - previousOutputs: array of { stepIndex, workerId, output } for steps 0..current-1.
22
- * Use any prior step's output; the immediate previous step is previousOutputs[previousOutputs.length - 1]?.output.
23
- */
24
- mapInputFromPrev?: string;
25
- }
26
- interface WorkerQueueConfig<InitialInput = any, StepOutput = any> {
27
- /** Stable queue identifier, e.g. "cost-usage". */
28
- id: string;
29
- /** Ordered list of workers forming the queue. */
30
- steps: WorkerQueueStep[];
31
- /**
32
- * Optional schedule for the queue (cron or rate).
33
- * When set, the CLI generates a queue-starter Lambda triggered by this schedule.
34
- * Example: 'cron(0 3 * * ? *)' for daily at 03:00 UTC.
35
- */
36
- schedule?: string | {
37
- rate: string;
38
- enabled?: boolean;
39
- input?: Record<string, any>;
40
- };
41
- _initialInputType?: InitialInput;
42
- _stepOutputType?: StepOutput;
43
- }
44
- /**
45
- * Queue execution context that is embedded into job input/metadata so
46
- * queue-aware wrappers can determine where they are in the queue.
47
- */
48
- interface WorkerQueueContext<InitialInput = any> {
49
- id: string;
50
- stepIndex: number;
51
- initialInput: InitialInput;
52
- /** Queue job ID (same as first worker's jobId) for tracking progress. */
53
- queueJobId?: string;
54
- }
55
- /**
56
- * Identity helper for defining worker queues in .queue.ts files.
57
- * This is primarily for type safety and CLI discovery.
58
- */
59
- declare function defineWorkerQueue<T extends WorkerQueueConfig>(config: T): T;
60
-
61
- /**
62
- * Client for dispatching background worker jobs.
63
- *
64
- * In production, dispatching happens via the workers HTTP API:
65
- * POST /workers/trigger -> enqueues message to SQS on the workers service side
66
- *
67
- * This avoids requiring AWS credentials in your Next.js app.
68
- */
69
-
70
- interface WorkerQueueRegistry {
71
- getQueueById(queueId: string): WorkerQueueConfig | undefined;
72
- /** (initialInput, previousOutputs) for best DX: derive next input from original request and all prior step outputs. */
73
- invokeMapInput?: (queueId: string, stepIndex: number, initialInput: unknown, previousOutputs: Array<{
74
- stepIndex: number;
75
- workerId: string;
76
- output: unknown;
77
- }>) => Promise<unknown> | unknown;
78
- }
79
- interface DispatchOptions {
80
- /**
81
- * Optional webhook callback URL to notify when the job finishes.
82
- * Only called when provided. Default: no webhook (use job store / MongoDB only).
83
- */
84
- webhookUrl?: string;
85
- /**
86
- * Controls how dispatch executes.
87
- * - "auto" (default): local inline execution in development unless WORKERS_LOCAL_MODE=false.
88
- * - "local": force inline execution (no SQS).
89
- * - "remote": force SQS/Lambda dispatch even in development.
90
- */
91
- mode?: 'auto' | 'local' | 'remote';
92
- jobId?: string;
93
- metadata?: Record<string, any>;
94
- /**
95
- * In-memory queue registry for dispatchQueue. Required when using dispatchQueue.
96
- * Pass a registry that imports from your .queue.ts definitions (works on Vercel/serverless).
97
- */
98
- registry?: WorkerQueueRegistry;
99
- /**
100
- * Optional callback to create a queue job record before dispatching.
101
- * Called with queueJobId (= first worker's jobId), queueId, and firstStep.
102
- */
103
- onCreateQueueJob?: (params: {
104
- queueJobId: string;
105
- queueId: string;
106
- firstStep: {
107
- workerId: string;
108
- workerJobId: string;
109
- };
110
- metadata?: Record<string, unknown>;
111
- }) => Promise<void>;
112
- }
113
- interface DispatchResult {
114
- messageId: string;
115
- status: 'queued';
116
- jobId: string;
117
- }
118
- interface DispatchQueueResult extends DispatchResult {
119
- queueId: string;
120
- }
121
- interface SerializedContext {
122
- requestId?: string;
123
- userId?: string;
124
- traceId?: string;
125
- [key: string]: any;
126
- }
127
- /**
128
- * Derives the full /workers/trigger URL from env.
129
- * Exported for use by local dispatchWorker (worker-to-worker in dev).
130
- * Server-side only; clients should use useWorkflowJob with your app's /api/workflows routes.
131
- *
132
- * Env vars:
133
- * - WORKER_BASE_URL: base URL of the workers service (e.g. https://.../prod)
134
- * - WORKERS_TRIGGER_API_URL / WORKERS_CONFIG_API_URL: legacy, still supported
135
- */
136
- declare function getWorkersTriggerUrl(): string;
137
- /**
138
- * URL for the queue start endpoint (dispatch proxy). Use this so queue starts
139
- * go through the queue handler Lambda for easier debugging (one log stream per queue).
140
- */
141
- declare function getQueueStartUrl(queueId: string): string;
142
- /**
143
- * Dispatches a background worker job to SQS.
144
- *
145
- * @param workerId - The ID of the worker to dispatch
146
- * @param input - The input data for the worker (will be validated against inputSchema)
147
- * @param inputSchema - Zod schema for input validation
148
- * @param options - Dispatch options including webhook URL
149
- * @param ctx - Optional context object (only serializable parts will be sent)
150
- * @returns Promise resolving to dispatch result with messageId and jobId
151
- */
152
- declare function dispatch<INPUT_SCHEMA extends ZodType<any>>(workerId: string, input: z.input<INPUT_SCHEMA>, inputSchema: INPUT_SCHEMA, options: DispatchOptions, ctx?: any): Promise<DispatchResult>;
153
- /**
154
- * Dispatch a worker by ID without importing the worker module.
155
- * Sends to the workers trigger API (WORKER_BASE_URL). No input schema validation at call site.
156
- *
157
- * @param workerId - The worker ID (e.g. 'echo', 'data-processor')
158
- * @param input - Input payload (object or undefined)
159
- * @param options - Optional jobId, webhookUrl, metadata
160
- * @param ctx - Optional context (serializable parts sent in the request)
161
- * @returns Promise resolving to { messageId, status: 'queued', jobId }
162
- */
163
- declare function dispatchWorker(workerId: string, input?: Record<string, unknown>, options?: DispatchOptions, ctx?: any): Promise<DispatchResult>;
164
- /**
165
- * Local development mode: runs the handler immediately in the same process.
166
- * This bypasses SQS and Lambda for faster iteration during development.
167
- *
168
- * @param handler - The worker handler function
169
- * @param input - The input data
170
- * @param ctx - The context object
171
- * @returns The handler result
172
- */
173
- declare function dispatchLocal<INPUT, OUTPUT>(handler: (params: {
174
- input: INPUT;
175
- ctx: any;
176
- }) => Promise<OUTPUT>, input: INPUT, ctx?: any): Promise<OUTPUT>;
177
- /**
178
- * Dispatches a queue by ID. POSTs to the queue-start API; the queue-start handler creates the queue job.
179
- * Pass the first worker's input directly (no registry required).
180
- */
181
- declare function dispatchQueue<InitialInput = any>(queueId: string, initialInput?: InitialInput, options?: DispatchOptions, _ctx?: any): Promise<DispatchQueueResult>;
182
-
183
- export { type DispatchOptions as D, type SerializedContext as S, type WorkerQueueRegistry as W, type DispatchResult as a, type DispatchQueueResult as b, getQueueStartUrl as c, dispatch as d, dispatchWorker as e, dispatchLocal as f, getWorkersTriggerUrl as g, dispatchQueue as h, type WorkerQueueStep as i, type WorkerQueueConfig as j, type WorkerQueueContext as k, defineWorkerQueue as l };