{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @microfox/ai-worker\n * Worker runtime for ai-router - SQS-based async agent execution\n */\n\nimport { dispatch, dispatchLocal, getWorkersTriggerUrl, type DispatchOptions, type DispatchResult } from './client.js';\nimport { createLambdaHandler, createWorkerLogger, type WorkerHandler, type JobStore, type DispatchWorkerOptions, SQS_MAX_DELAY_SECONDS } from './handler.js';\nimport { QUEUE_ORCHESTRATION_KEYS } from './queue.js';\nimport { type SmartRetryConfig, type RetryContext, executeWithRetry } from './retryConfig.js';\nimport { type TokenUsage, createTokenTracker } from './tokenBudget.js';\nimport type { ZodType, z } from 'zod';\n\nexport * from './client.js';\nexport * from './handler.js';\nexport * from './config.js';\nexport * from './queue.js';\nexport * from './queueInputEnvelope.js';\nexport * from './chainMapDefaults.js';\nexport * from './hitlConfig.js';\nexport * from './retryConfig.js';\nexport { TokenBudgetExceededError } from './tokenBudget.js';\nexport type { TokenUsage, TokenBudgetState } from './tokenBudget.js';\nexport * from './localBridge.js';\nexport * from './localJobStore.js';\n\n/**\n * Schedule event configuration for a worker.\n * Supports both simple rate/cron strings and full configuration objects.\n * \n * @example Simple rate/cron\n * ```typescript\n * schedule: 'rate(2 hours)'\n * // or\n * schedule: 'cron(0 12 * * ? *)'\n * ```\n * \n * @example Full configuration\n * ```typescript\n * schedule: {\n *   rate: 'rate(10 minutes)',\n *   enabled: true,\n *   input: { key1: 'value1' }\n * }\n * ```\n * \n * @example Multiple schedules\n * ```typescript\n * schedule: [\n *   'rate(2 hours)',\n *   { rate: 'cron(0 12 * * ? *)', enabled: false }\n * ]\n * ```\n */\nexport interface ScheduleEventConfig {\n  /**\n   * Schedule rate using either rate() or cron() syntax.\n   * Can be a string or array of strings for multiple schedules.\n   * \n   * @example 'rate(2 hours)' or 'cron(0 12 * * ? *)'\n   * @example ['cron(0 0/4 ? * MON-FRI *)', 'cron(0 2 ? * SAT-SUN *)']\n   */\n  rate: string | string[];\n  /**\n   * Whether the schedule is enabled (default: true).\n   */\n  enabled?: boolean;\n  /**\n   * Input payload to pass to the function.\n   */\n  input?: Record<string, any>;\n  /**\n   * JSONPath expression to select part of the event data as input.\n   */\n  inputPath?: string;\n  /**\n   * Input transformer configuration for custom input mapping.\n   */\n  inputTransformer?: {\n    inputPathsMap?: Record<string, string>;\n    inputTemplate?: string;\n  };\n  /**\n   * Name of the schedule event.\n   */\n  name?: string;\n  /**\n   * Description of the schedule event.\n   */\n  description?: string;\n  /**\n   * Method to use: 'eventBus' (default) or 'scheduler'.\n   * Use 'scheduler' for higher limits (1M events vs 300).\n   */\n  method?: 'eventBus' | 'scheduler';\n  /**\n   * Timezone for the schedule (only used with method: 'scheduler').\n   * @example 'America/New_York'\n   */\n  timezone?: string;\n}\n\nexport type ScheduleConfig = \n  | string \n  | ScheduleEventConfig \n  | (string | ScheduleEventConfig)[];\n\n/**\n * Configuration for a worker's Lambda function deployment.\n * \n * **Best Practice**: Export this as a separate const from your worker file:\n * ```typescript\n * export const workerConfig: WorkerConfig = {\n *   timeout: 900,\n *   memorySize: 2048,\n *   layers: ['arn:aws:lambda:${aws:region}:${aws:accountId}:layer:ffmpeg:1'],\n *   schedule: 'rate(2 hours)',\n * };\n * ```\n * \n * The CLI will automatically extract it from the export. You do not need to pass it to `createWorker()`.\n */\nexport interface WorkerConfig {\n  /**\n   * Lambda function timeout in seconds (max 900).\n   */\n  timeout?: number;\n  /**\n   * Lambda function memory size in MB (128-10240).\n   */\n  memorySize?: number;\n  /**\n   * Optional Lambda layers ARNs to attach to this worker function.\n   *\n   * This is primarily used by @microfox/ai-worker-cli when generating serverless.yml.\n   * Supports CloudFormation pseudo-parameters like ${aws:region} and ${aws:accountId}.\n   *\n   * Example:\n   *   layers: ['arn:aws:lambda:${aws:region}:${aws:accountId}:layer:ffmpeg:1']\n   */\n  layers?: string[];\n  /**\n   * Schedule events configuration for this worker.\n   * Allows multiple schedule events to be attached to the same function.\n   * \n   * @example Simple rate\n   * ```typescript\n   * schedule: 'rate(2 hours)'\n   * ```\n   * \n   * @example Multiple schedules\n   * ```typescript\n   * schedule: [\n   *   'rate(2 hours)',\n   *   { rate: 'cron(0 12 * * ? *)', enabled: true, input: { key: 'value' } }\n   * ]\n   * ```\n   * \n   * @example Using scheduler method with timezone\n   * ```typescript\n   * schedule: {\n   *   method: 'scheduler',\n   *   rate: 'cron(0 0/4 ? * MON-FRI *)',\n   *   timezone: 'America/New_York',\n   *   input: { key1: 'value1' }\n   * }\n   * ```\n   */\n  schedule?: ScheduleConfig;\n\n  /**\n   * If set, this worker is deployed to the serverless project for this group.\n   * Do not use 'core' (reserved). Max 12 characters (serverless service name limits).\n   */\n  group?: string;\n\n  /**\n   * SQS queue settings for this worker (used by @microfox/ai-worker-cli when generating serverless.yml).\n   *\n   * Notes:\n   * - To effectively disable retries, set `maxReceiveCount: 1` (requires DLQ; the CLI will create one).\n   * - SQS does not support `maxReceiveCount: 0`.\n   * - `messageRetentionPeriod` is in seconds (max 1209600 = 14 days).\n   */\n  sqs?: {\n    /**\n     * How many receives before sending to DLQ.\n     * Use 1 to avoid retries.\n     */\n    maxReceiveCount?: number;\n    /**\n     * How long messages are retained in the main queue (seconds).\n     */\n    messageRetentionPeriod?: number;\n    /**\n     * Visibility timeout for the main queue (seconds).\n     * If not set, CLI defaults to (worker timeout + 60s).\n     */\n    visibilityTimeout?: number;\n    /**\n     * DLQ message retention period (seconds).\n     * Defaults to `messageRetentionPeriod` (or 14 days).\n     */\n    deadLetterMessageRetentionPeriod?: number;\n  };\n}\n\nexport interface WorkerAgentConfig<INPUT_SCHEMA extends ZodType<any>, OUTPUT> {\n  id: string;\n  inputSchema: INPUT_SCHEMA;\n  outputSchema: ZodType<OUTPUT>;\n  handler: WorkerHandler<z.infer<INPUT_SCHEMA>, OUTPUT>;\n  /**\n   * Smart retry configuration for this worker.\n   * Applies whenever this worker runs (Lambda or local mode).\n   * Can be overridden per queue step via WorkerQueueStep.retry.\n   * Retries are in-process so ctx.retryContext is populated on each retry attempt.\n   *\n   * @example\n   * ```ts\n   * retry: { maxAttempts: 3, on: ['rate-limit', 'json-parse'] }\n   * ```\n   */\n  retry?: SmartRetryConfig;\n  /**\n   * @deprecated Prefer exporting `workerConfig` as a separate const from your worker file.\n   * The CLI will automatically extract it from the export. This parameter is kept for backward compatibility.\n   */\n  workerConfig?: WorkerConfig;\n}\n\nexport interface WorkerAgent<INPUT_SCHEMA extends ZodType<any>, OUTPUT> {\n  id: string;\n  dispatch: (\n    input: z.input<INPUT_SCHEMA>,\n    options: DispatchOptions\n  ) => Promise<DispatchResult>;\n  handler: WorkerHandler<z.infer<INPUT_SCHEMA>, OUTPUT>;\n  inputSchema: INPUT_SCHEMA;\n  outputSchema: ZodType<OUTPUT>;\n  workerConfig?: WorkerConfig;\n  /** Smart retry config set on this worker via createWorker({ retry }). */\n  retry?: SmartRetryConfig;\n}\n\n/**\n * Creates a worker agent that can be dispatched to SQS/Lambda.\n *\n * In development mode (NODE_ENV === 'development' and WORKERS_LOCAL_MODE !== 'false'),\n * dispatch() will run the handler immediately in the same process.\n *\n * In production, dispatch() sends a message to SQS which triggers a Lambda function.\n *\n * @template INPUT_SCHEMA - The Zod schema type (e.g., `typeof InputSchema`).\n *                          Used to derive both:\n *                          - Pre-parse input type via `z.input<INPUT_SCHEMA>` for `dispatch()` (preserves optional fields)\n *                          - Parsed input type via `z.infer<INPUT_SCHEMA>` for handler (defaults applied)\n * @template OUTPUT - The output type returned by the handler. Use `z.infer<typeof OutputSchema>`.\n *\n * @param config - Worker agent configuration\n * @returns A worker agent object with a dispatch method\n *\n * @example\n * ```typescript\n * const InputSchema = z.object({\n *   url: z.string().url(),\n *   timeout: z.number().optional().default(5000), // optional with default\n * });\n *\n * export const worker = createWorker<typeof InputSchema, Output>({\n *   // dispatch() accepts { url: string, timeout?: number } (pre-parse, optional preserved)\n *   // handler receives { url: string, timeout: number } (parsed, default applied)\n * });\n * ```\n */\nexport function createWorker<INPUT_SCHEMA extends ZodType<any>, OUTPUT>(\n  config: WorkerAgentConfig<INPUT_SCHEMA, OUTPUT>\n): WorkerAgent<INPUT_SCHEMA, OUTPUT> {\n  const { id, inputSchema, outputSchema, handler, retry: retryConfig } = config;\n\n  const agent: WorkerAgent<INPUT_SCHEMA, OUTPUT> = {\n    id,\n    handler,\n    inputSchema,\n    outputSchema,\n    retry: retryConfig,\n\n    async dispatch(input: z.input<INPUT_SCHEMA>, options: DispatchOptions): Promise<DispatchResult> {\n      const mode = options.mode ?? 'auto';\n      const envWantsLocal =\n        process.env.NODE_ENV === 'development' &&\n        process.env.WORKERS_LOCAL_MODE !== 'false';\n      // Check if we're in local development mode\n      const isLocal = mode === 'local' || (mode === 'auto' && envWantsLocal);\n\n      if (isLocal) {\n        // Local mode: run handler immediately.\n        // Strip queue/HITL orchestration keys before parsing so workers don't need\n        // queueOrchestrationFieldsSchema in their Zod schemas.\n        const rawInputObj =\n          input !== null && typeof input === 'object' ? (input as Record<string, unknown>) : null;\n        const domainInput = rawInputObj\n          ? Object.fromEntries(\n              Object.entries(rawInputObj).filter(\n                ([k]) => k !== '__workerQueue' && !(QUEUE_ORCHESTRATION_KEYS as readonly string[]).includes(k)\n              )\n            )\n          : input;\n        const parsedInput = inputSchema.parse(domainInput);\n        const localJobId = options.jobId || `local-${Date.now()}`;\n        \n        // Try to get direct job store access in local mode (same process as Next.js app)\n        // This allows direct DB updates without needing HTTP/webhook URLs\n        let directJobStore: {\n          updateJob: (jobId: string, data: any) => Promise<void>;\n          setJob?: (jobId: string, data: any) => Promise<void>;\n        } | null = null;\n\n        // Path constants for job store imports\n        const nextJsPathAlias = '@/app/api/workflows/stores/jobStore';\n        const explicitPath = process.env.WORKER_JOB_STORE_MODULE_PATH;\n\n        // Reliable approach: try Next.js path alias first, then explicit env var\n        // The @/ alias works at runtime in Next.js context\n        const resolveJobStore = async () => {\n          // Option 1: Try Next.js path alias (works in Next.js runtime context)\n          try {\n            const module = await import(nextJsPathAlias);\n            if (module?.updateJob) {\n              return { updateJob: module.updateJob, setJob: module.setJob };\n            }\n          } catch {\n            // Path alias not available (not in Next.js context or alias not configured)\n          }\n\n          // Option 2: Use explicit env var if provided (for custom setups)\n          if (explicitPath) {\n            try {\n              const module = await import(explicitPath).catch(() => {\n                // eslint-disable-next-line @typescript-eslint/no-require-imports\n                return require(explicitPath);\n              });\n              if (module?.updateJob) {\n                return { updateJob: module.updateJob, setJob: module.setJob };\n              }\n            } catch {\n              // Explicit path failed\n            }\n          }\n\n          return null;\n        };\n\n        directJobStore = await resolveJobStore();\n        if (directJobStore) {\n          console.log('[Worker] Using direct job store in local mode (no HTTP needed)');\n        }\n\n        // Derive job store URL from webhook URL or environment (fallback for HTTP mode)\n        let jobStoreUrl: string | undefined;\n        if (options.webhookUrl) {\n          try {\n            const webhookUrlObj = new URL(options.webhookUrl);\n            jobStoreUrl = webhookUrlObj.pathname.replace(/\\/webhook$/, '');\n            jobStoreUrl = `${webhookUrlObj.origin}${jobStoreUrl}`;\n          } catch {\n            // Invalid URL, skip job store URL\n          }\n        }\n        jobStoreUrl = jobStoreUrl || process.env.WORKER_JOB_STORE_URL;\n\n        // Create job store interface for local mode\n        // Prefer direct DB access, fallback to HTTP calls if needed\n        const createLocalJobStore = (\n          directStore: typeof directJobStore,\n          httpUrl?: string\n        ): JobStore | undefined => {\n          // If we have direct job store access, use it (no HTTP needed)\n          if (directStore) {\n            return {\n              update: async (update) => {\n                try {\n                  // Build update payload\n                  const updatePayload: any = {};\n                  \n                  if (update.status !== undefined) {\n                    updatePayload.status = update.status;\n                  }\n                  if (update.metadata !== undefined) {\n                    updatePayload.metadata = update.metadata;\n                  }\n                  if (update.progress !== undefined) {\n                    // Merge progress into metadata\n                    updatePayload.metadata = {\n                      ...updatePayload.metadata,\n                      progress: update.progress,\n                      progressMessage: update.progressMessage,\n                    };\n                  }\n                  if (update.output !== undefined) {\n                    updatePayload.output = update.output;\n                  }\n                  if (update.error !== undefined) {\n                    updatePayload.error = update.error;\n                  }\n\n                  await directStore.updateJob(localJobId, updatePayload);\n                  console.log('[Worker] Local job updated (direct DB):', {\n                    jobId: localJobId,\n                    workerId: id,\n                    updates: Object.keys(updatePayload),\n                  });\n                } catch (error: any) {\n                  console.warn('[Worker] Failed to update local job (direct DB):', {\n                    jobId: localJobId,\n                    workerId: id,\n                    error: error?.message || String(error),\n                  });\n                }\n              },\n              get: async () => {\n                try {\n                  // Use the same direct store that has updateJob - it should also have getJob\n                  if (directStore) {\n                    // Try to import getJob from the same module\n                    const nextJsPath = '@/app/api/workflows/stores/jobStore';\n                    const explicitPath = process.env.WORKER_JOB_STORE_MODULE_PATH;\n                    \n                    for (const importPath of [nextJsPath, explicitPath].filter(Boolean)) {\n                      try {\n                        const module = await import(importPath!);\n                        if (module?.getJob) {\n                          return await module.getJob(localJobId);\n                        }\n                      } catch {\n                        // Continue\n                      }\n                    }\n                  }\n                  return null;\n                } catch (error: any) {\n                  console.warn('[Worker] Failed to get local job (direct DB):', {\n                    jobId: localJobId,\n                    workerId: id,\n                    error: error?.message || String(error),\n                  });\n                  return null;\n                }\n              },\n              appendInternalJob: async (entry: { jobId: string; workerId: string }) => {\n                try {\n                  const nextJsPath = '@/app/api/workflows/stores/jobStore';\n                  const explicitPath = process.env.WORKER_JOB_STORE_MODULE_PATH;\n                  for (const importPath of [nextJsPath, explicitPath].filter(Boolean)) {\n                    try {\n                      const module = await import(importPath!);\n                      if (typeof module?.appendInternalJob === 'function') {\n                        await module.appendInternalJob(localJobId, entry);\n                        return;\n                      }\n                    } catch {\n                      // Continue\n                    }\n                  }\n                } catch (error: any) {\n                  console.warn('[Worker] Failed to appendInternalJob (direct DB):', { localJobId, error: error?.message || String(error) });\n                }\n              },\n              getJob: async (otherJobId: string) => {\n                try {\n                  const nextJsPath = '@/app/api/workflows/stores/jobStore';\n                  const explicitPath = process.env.WORKER_JOB_STORE_MODULE_PATH;\n                  for (const importPath of [nextJsPath, explicitPath].filter(Boolean)) {\n                    try {\n                      const module = await import(importPath!);\n                      if (typeof module?.getJob === 'function') {\n                        return await module.getJob(otherJobId);\n                      }\n                    } catch {\n                      // Continue\n                    }\n                  }\n                } catch (error: any) {\n                  console.warn('[Worker] Failed to getJob (direct DB):', { otherJobId, error: error?.message || String(error) });\n                }\n                return null;\n              },\n            };\n          }\n\n          // Fallback to HTTP calls if no direct access\n          if (!httpUrl) {\n            return undefined;\n          }\n\n          // Use HTTP calls to update job store\n          return {\n            update: async (update) => {\n              try {\n                // Build update payload\n                const updatePayload: any = { jobId: localJobId, workerId: id };\n                \n                if (update.status !== undefined) {\n                  updatePayload.status = update.status;\n                }\n                if (update.metadata !== undefined) {\n                  updatePayload.metadata = update.metadata;\n                }\n                if (update.progress !== undefined) {\n                  // Merge progress into metadata\n                  updatePayload.metadata = {\n                    ...updatePayload.metadata,\n                    progress: update.progress,\n                    progressMessage: update.progressMessage,\n                  };\n                }\n                if (update.output !== undefined) {\n                  updatePayload.output = update.output;\n                }\n                if (update.error !== undefined) {\n                  updatePayload.error = update.error;\n                }\n\n                const response = await fetch(`${httpUrl}/update`, {\n                  method: 'POST',\n                  headers: { 'Content-Type': 'application/json' },\n                  body: JSON.stringify(updatePayload),\n                });\n                if (!response.ok) {\n                  throw new Error(`Job store update failed: ${response.status} ${response.statusText}`);\n                }\n                console.log('[Worker] Local job updated (HTTP):', {\n                  jobId: localJobId,\n                  workerId: id,\n                  updates: Object.keys(updatePayload),\n                });\n              } catch (error: any) {\n                console.warn('[Worker] Failed to update local job (HTTP):', {\n                  jobId: localJobId,\n                  workerId: id,\n                  error: error?.message || String(error),\n                });\n              }\n            },\n            get: async () => {\n              try {\n                // GET /api/workflows/workers/:workerId/:jobId\n                const response = await fetch(`${httpUrl}/${id}/${localJobId}`, {\n                  method: 'GET',\n                  headers: { 'Content-Type': 'application/json' },\n                });\n\n                if (!response.ok) {\n                  if (response.status === 404) {\n                    return null;\n                  }\n                  throw new Error(`Job store get failed: ${response.status} ${response.statusText}`);\n                }\n\n                return await response.json();\n              } catch (error: any) {\n                console.warn('[Worker] Failed to get local job (HTTP):', {\n                  jobId: localJobId,\n                  workerId: id,\n                  error: error?.message || String(error),\n                });\n                return null;\n              }\n            },\n          };\n        };\n\n        const jobStore = createLocalJobStore(directJobStore, jobStoreUrl);\n\n        const DEFAULT_POLL_INTERVAL_MS = 2000;\n        const DEFAULT_POLL_TIMEOUT_MS = 15 * 60 * 1000;\n\n        const createLocalDispatchWorker = (\n          parentJobId: string,\n          parentWorkerId: string,\n          parentContext: Record<string, any>,\n          store: JobStore | undefined\n        ): ((\n          workerId: string,\n          input: unknown,\n          options?: DispatchWorkerOptions\n        ) => Promise<{ jobId: string; messageId?: string; output?: unknown }>) => {\n          return async (\n            calleeWorkerId: string,\n            input: unknown,\n            options?: DispatchWorkerOptions\n          ): Promise<{ jobId: string; messageId?: string; output?: unknown }> => {\n            const childJobId =\n              options?.jobId ||\n              `job-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;\n            const metadata = options?.metadata ?? {};\n            const serializedContext: Record<string, any> = {};\n            if (parentContext.requestId) serializedContext.requestId = parentContext.requestId;\n            if (parentContext.userId) serializedContext.userId = parentContext.userId;\n            const messageBody = {\n              workerId: calleeWorkerId,\n              jobId: childJobId,\n              input: input ?? {},\n              context: serializedContext,\n              webhookUrl: options?.webhookUrl,\n              metadata,\n              timestamp: new Date().toISOString(),\n            };\n            let triggerUrl: string;\n            try {\n              triggerUrl = getWorkersTriggerUrl();\n            } catch (e: any) {\n              throw new Error(\n                `Local dispatchWorker requires WORKER_BASE_URL (or similar) for worker \"${calleeWorkerId}\": ${e?.message ?? e}`\n              );\n            }\n            const headers: Record<string, string> = { 'Content-Type': 'application/json' };\n            const triggerKey = process.env.WORKERS_TRIGGER_API_KEY;\n            if (triggerKey) headers['x-workers-trigger-key'] = triggerKey;\n\n            // Fire-and-forget with delay: schedule trigger after delay, return immediately (no computation/wait in caller).\n            if (options?.await !== true && options?.delaySeconds != null && options.delaySeconds > 0) {\n              const sec = Math.min(SQS_MAX_DELAY_SECONDS, Math.max(0, Math.floor(options.delaySeconds)));\n              const storeRef = store;\n              setTimeout(() => {\n                fetch(triggerUrl, {\n                  method: 'POST',\n                  headers,\n                  body: JSON.stringify({ workerId: calleeWorkerId, body: messageBody }),\n                })\n                  .then(async (response) => {\n                    if (!response.ok) {\n                      const text = await response.text().catch(() => '');\n                      console.error(\n                        `[Worker] Delayed trigger failed for \"${calleeWorkerId}\": ${response.status} ${response.statusText}${text ? ` - ${text}` : ''}`\n                      );\n                      return;\n                    }\n                    if (storeRef?.appendInternalJob) {\n                      await storeRef.appendInternalJob({ jobId: childJobId, workerId: calleeWorkerId });\n                    }\n                  })\n                  .catch((err) => {\n                    console.error('[Worker] Delayed trigger error:', { calleeWorkerId, jobId: childJobId, error: err?.message ?? err });\n                  });\n              }, sec * 1000);\n              return { jobId: childJobId, messageId: undefined };\n            }\n\n            const response = await fetch(triggerUrl, {\n              method: 'POST',\n              headers,\n              body: JSON.stringify({ workerId: calleeWorkerId, body: messageBody }),\n            });\n            if (!response.ok) {\n              const text = await response.text().catch(() => '');\n              throw new Error(\n                `Failed to trigger worker \"${calleeWorkerId}\": ${response.status} ${response.statusText}${text ? ` - ${text}` : ''}`\n              );\n            }\n            const data = (await response.json().catch(() => ({}))) as any;\n            const messageId = data?.messageId ? String(data.messageId) : `trigger-${childJobId}`;\n\n            if (store?.appendInternalJob) {\n              await store.appendInternalJob({ jobId: childJobId, workerId: calleeWorkerId });\n            }\n\n            if (options?.await && store?.getJob) {\n              const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n              const pollTimeoutMs = options.pollTimeoutMs ?? DEFAULT_POLL_TIMEOUT_MS;\n              const deadline = Date.now() + pollTimeoutMs;\n              while (Date.now() < deadline) {\n                const child = await store.getJob(childJobId);\n                if (!child) {\n                  await new Promise((r) => setTimeout(r, pollIntervalMs));\n                  continue;\n                }\n                if (child.status === 'completed') {\n                  return { jobId: childJobId, messageId, output: child.output };\n                }\n                if (child.status === 'failed') {\n                  const err = child.error;\n                  throw new Error(err?.message ?? `Child worker ${calleeWorkerId} failed`);\n                }\n                await new Promise((r) => setTimeout(r, pollIntervalMs));\n              }\n              throw new Error(\n                `Child worker ${calleeWorkerId} (${childJobId}) did not complete within ${pollTimeoutMs}ms`\n              );\n            }\n\n            return { jobId: childJobId, messageId };\n          };\n        };\n\n        // Create initial job record if we have job store access\n        if (directJobStore?.setJob) {\n          try {\n            await directJobStore.setJob(localJobId, {\n              jobId: localJobId,\n              workerId: id,\n              status: 'queued',\n              input: parsedInput,\n              metadata: options.metadata || {},\n            });\n          } catch (error: any) {\n            console.warn('[Worker] Failed to create initial job record:', {\n              jobId: localJobId,\n              workerId: id,\n              error: error?.message || String(error),\n            });\n            // Continue - job will still be created when status is updated\n          }\n        }\n\n        const localUserId = options.userId;\n        const baseContext = {\n          jobId: localJobId,\n          workerId: id,\n          ...(localUserId ? { userId: localUserId } : {}),\n        };\n        if (localUserId) {\n          // Parseable audit log matching Lambda pattern for consistent log parsing.\n          console.log(`[WORKER_USER:${localUserId}]`, { jobId: localJobId, workerId: id, mode: 'local', timestamp: new Date().toISOString() });\n        }\n\n        const localLogger = createWorkerLogger(localJobId, id);\n        const tokenTracker = createTokenTracker(options.maxTokens ?? null);\n\n        const handlerContext: any = {\n          ...baseContext,\n          ...(jobStore ? { jobStore } : {}),\n          logger: localLogger,\n          dispatchWorker: createLocalDispatchWorker(localJobId, id, baseContext, jobStore),\n          reportTokenUsage: async (usage: TokenUsage) => {\n            tokenTracker.report(usage);\n            const state = tokenTracker.getState();\n            if (jobStore) {\n              await jobStore.update({ metadata: { tokenUsage: state } }).catch((e: any) => {\n                localLogger.warn('Failed to persist tokenUsage', { error: e?.message });\n              });\n            }\n          },\n          getTokenBudget: () => tokenTracker.getBudgetInfo(),\n          retryContext: undefined as RetryContext | undefined,\n        };\n\n        try {\n          // Update status to running before execution\n          if (jobStore) {\n            await jobStore.update({ status: 'running' });\n          }\n\n          const executeLocal = async (retryCtx: RetryContext | undefined) => {\n            handlerContext.retryContext = retryCtx;\n            return dispatchLocal(handler, parsedInput, handlerContext);\n          };\n\n          const output = retryConfig && retryConfig.on.length > 0\n            ? await executeWithRetry(executeLocal, retryConfig, (retryCtx, delayMs) => {\n                localLogger.warn(\n                  `[worker-retry] Local retry (attempt ${retryCtx.attempt}/${retryCtx.maxAttempts}): ${retryCtx.lastError.message}`,\n                  { delayMs }\n                );\n              })\n            : await executeLocal(undefined);\n\n          // Update status to completed before webhook\n          if (jobStore) {\n            await jobStore.update({ status: 'completed', output });\n          }\n\n          // Only send webhook if webhookUrl is provided\n          if (options.webhookUrl) {\n            try {\n              await fetch(options.webhookUrl, {\n                method: 'POST',\n                headers: { 'Content-Type': 'application/json' },\n                body: JSON.stringify({\n                  jobId: localJobId,\n                  workerId: id,\n                  status: 'success',\n                  output,\n                  metadata: options.metadata,\n                }),\n              });\n            } catch (error) {\n              console.warn('[Worker] Local webhook call failed:', error);\n            }\n          }\n\n          return {\n            messageId: `local-${Date.now()}`,\n            status: 'queued',\n            jobId: localJobId,\n          };\n        } catch (error: any) {\n          // Update status to failed before webhook\n          if (jobStore) {\n            await jobStore.update({\n              status: 'failed',\n              error: {\n                message: error.message || 'Unknown error',\n                stack: error.stack,\n                name: error.name || 'Error',\n              },\n            });\n          }\n\n          // Only send error webhook if webhookUrl is provided\n          if (options.webhookUrl) {\n            try {\n              await fetch(options.webhookUrl, {\n                method: 'POST',\n                headers: { 'Content-Type': 'application/json' },\n                body: JSON.stringify({\n                  jobId: localJobId,\n                  workerId: id,\n                  status: 'error',\n                  error: {\n                    message: error.message || 'Unknown error',\n                    stack: error.stack,\n                    name: error.name || 'Error',\n                  },\n                  metadata: options.metadata,\n                }),\n              });\n            } catch (webhookError) {\n              console.warn('[Worker] Local error webhook call failed:', webhookError);\n            }\n          }\n          throw error;\n        }\n      }\n\n      // Production mode: dispatch to SQS\n      return dispatch(id, input, inputSchema, options);\n    },\n  };\n\n  return agent;\n}\n\n/**\n * Creates a Lambda handler entrypoint for a worker agent.\n * This is used by the deployment script to generate Lambda entrypoints.\n *\n * @param agent - The worker agent\n * @returns A Lambda handler function\n */\nexport function createLambdaEntrypoint<INPUT_SCHEMA extends ZodType<any>, OUTPUT>(\n  agent: WorkerAgent<INPUT_SCHEMA, OUTPUT>\n) {\n  return createLambdaHandler(agent.handler, agent.outputSchema, { retry: agent.retry });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkRO,SAAS,aACd,QACmC;AACnC,QAAM,EAAE,IAAI,aAAa,cAAc,SAAS,OAAO,YAAY,IAAI;AAEvE,QAAM,QAA2C;AAAA,IAC/C;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IAEP,MAAM,SAAS,OAA8B,SAAmD;AAC9F,YAAM,OAAO,QAAQ,QAAQ;AAC7B,YAAM,gBACJ,QAAQ,IAAI,aAAa,iBACzB,QAAQ,IAAI,uBAAuB;AAErC,YAAM,UAAU,SAAS,WAAY,SAAS,UAAU;AAExD,UAAI,SAAS;AAIX,cAAM,cACJ,UAAU,QAAQ,OAAO,UAAU,WAAY,QAAoC;AACrF,cAAM,cAAc,cAChB,OAAO;AAAA,UACL,OAAO,QAAQ,WAAW,EAAE;AAAA,YAC1B,CAAC,CAAC,CAAC,MAAM,MAAM,mBAAmB,CAAE,yBAA+C,SAAS,CAAC;AAAA,UAC/F;AAAA,QACF,IACA;AACJ,cAAM,cAAc,YAAY,MAAM,WAAW;AACjD,cAAM,aAAa,QAAQ,SAAS,SAAS,KAAK,IAAI,CAAC;AAIvD,YAAI,iBAGO;AAGX,cAAM,kBAAkB;AACxB,cAAM,eAAe,QAAQ,IAAI;AAIjC,cAAM,kBAAkB,YAAY;AAElC,cAAI;AACF,kBAAM,SAAS,MAAM,OAAO;AAC5B,gBAAI,QAAQ,WAAW;AACrB,qBAAO,EAAE,WAAW,OAAO,WAAW,QAAQ,OAAO,OAAO;AAAA,YAC9D;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