{"version":3,"file":"contract-E1QJBH6_.mjs","names":[],"sources":["../src/types.ts","../src/contract.ts"],"sourcesContent":["export type JobKind =\n  | \"workflow\"\n  | \"agent\"\n  | \"trigger\"\n  | \"trigger-overview\"\n  | \"workflow-canvas-annotations\"\n  | \"workflow-overview\"\n  | \"runtime\"\n  | \"maintenance\";\n\nexport type JobTrigger = \"api\" | \"cron\" | \"webhook\" | \"poll\" | \"retry\" | \"prompt\";\n\n/**\n * Identifies a run that dispatched this job as a child. The parent metadata\n * survives the queue boundary so the child can resume its parent at a terminal\n * outcome without treating the child as a separately-billable dispatch.\n */\nexport type JobParent = {\n  kind: \"workflow\" | \"agent\";\n  runId: string;\n  targetId: string;\n  correlationId?: string;\n};\n\nexport type JobPayload = {\n  kind: JobKind;\n  targetId: string;\n  runId: string;\n  trigger: JobTrigger;\n  payload: unknown;\n  attempt: number;\n  maxAttempts: number;\n  /** True when this delivery is the final retry attempt. */\n  exhaustedRetries?: boolean;\n  scheduledAt: Date;\n  jobId: string;\n  /** Project scope for org-wide worker queues. */\n  projectId?: string;\n  /** Parent run that dispatched this child job, when applicable. */\n  parent?: JobParent;\n  /** Optional W3C trace context carrier (sibling of user payload). */\n  traceContext?: Record<string, string>;\n};\n\nexport type EnqueueInput = {\n  kind: JobKind;\n  targetId: string;\n  runId: string;\n  trigger: JobTrigger;\n  payload?: unknown;\n  scheduledAt?: Date;\n  attempt?: number;\n  maxAttempts?: number;\n  /** Dedupe key — pg-boss singletonKey / BullMQ jobId. */\n  dedupeKey?: string;\n  /** Project scope for org-wide worker queues. */\n  projectId?: string;\n  /** Parent run that dispatched this child job, when applicable. */\n  parent?: JobParent;\n  /** Optional W3C trace context carrier (sibling of user payload). */\n  traceContext?: Record<string, string>;\n};\n\nexport type JobHandler = (job: JobPayload) => Promise<void>;\n\nexport type CancelHandler = (runId: string) => void | Promise<void>;\n\nexport type StopFn = () => Promise<void> | void;\n\nexport type WorkerOptions = {\n  workerId?: string;\n  pollIntervalMs?: number;\n  leaseSweepIntervalMs?: number;\n};\n\nexport type JobQueue = {\n  enqueue(input: EnqueueInput): Promise<string>;\n  startWorker(handler: JobHandler, options?: WorkerOptions): Promise<StopFn>;\n  /**\n   * Temporarily lends a worker slot to a child while an agent job waits on it.\n   * Backends without a hard concurrency cap may omit it.\n   */\n  withLentSlot?<T>(fn: () => Promise<T>): Promise<T>;\n  publishCancel(runId: string): Promise<void>;\n  subscribeCancel(handler: CancelHandler): Promise<StopFn>;\n};\n\nimport type { SchedulerPlugin, SchedulerScope, TriggerScheduleSpec } from \"./contract\";\n\nexport type { TriggerScheduleSpec };\n\nexport type CreateJobQueueOptions = {\n  url?: string;\n  dialect?: \"postgres\" | \"sqlite\";\n  adapter?: JobQueue;\n  plugin?: SchedulerPlugin;\n  scope?: SchedulerScope;\n  projectId?: string;\n  organizationId?: string;\n};\n\nexport type ScheduleSyncOptions = {\n  schedules: TriggerScheduleSpec[];\n  scheduleOverrides?: {\n    global?: string;\n    byTrigger?: Record<string, string>;\n  };\n};\n\nexport type ScheduleTickerOptions = {\n  pollIntervalMs?: number;\n  batchSize?: number;\n  /** When `organization`, claims due schedules across all projects in the org schema. */\n  scope?: \"project\" | \"organization\";\n};\n\nexport type Scheduler = JobQueue & {\n  syncTriggerSchedules(options: ScheduleSyncOptions): Promise<void>;\n  startScheduleTicker(options?: ScheduleTickerOptions): Promise<StopFn>;\n  fireDueSchedules(asOf?: Date): Promise<number>;\n  upsertTriggerSchedule?(\n    spec: TriggerScheduleSpec,\n    overrides?: ScheduleSyncOptions[\"scheduleOverrides\"],\n  ): Promise<void>;\n  removeTriggerSchedule?(triggerSlug: string, projectId?: string): Promise<void>;\n};\n\nexport type CreateSchedulerOptions = CreateJobQueueOptions;\n\nexport const DEFAULT_RETRY_DELAY_MS = 5_000;\n\nexport function retryDelayMs(attempt: number): number {\n  return DEFAULT_RETRY_DELAY_MS * 2 ** Math.max(0, attempt - 1);\n}\n","export type {\n  JobKind,\n  JobTrigger,\n  JobPayload,\n  JobParent,\n  EnqueueInput,\n  JobHandler,\n  CancelHandler,\n  StopFn,\n  WorkerOptions,\n  JobQueue,\n} from \"./types\";\nexport { retryDelayMs, DEFAULT_RETRY_DELAY_MS } from \"./types\";\n\nimport type { JobQueue, StopFn } from \"./types\";\n\n/**\n * Inlined to keep the contract database-free — structurally identical to\n * `@keystrokehq/database`'s `DatabaseDialect`. Importing it from the database\n * package would re-introduce the dependency `./contract` exists to avoid.\n */\nexport type DatabaseDialect = \"postgres\" | \"sqlite\";\n\nexport type SchedulerScope = \"platform\" | \"project\" | \"organization\";\n\nexport type SchedulerPluginContext = {\n  scope: SchedulerScope;\n  url?: string;\n  dialect?: DatabaseDialect;\n  projectId?: string;\n  organizationId?: string;\n};\n\nexport type TriggerScheduleSpec = {\n  triggerSlug: string;\n  kind: \"cron\" | \"poll\";\n  schedule: string;\n  /** IANA timezone for schedule wall-clock fields. When omitted, UTC. */\n  timezone?: string;\n  /** Project scope for org-wide worker queues. */\n  projectId?: string;\n};\n\nexport type TriggerScheduleSyncOptions = {\n  schedules: TriggerScheduleSpec[];\n  scheduleOverrides?: {\n    global?: string;\n    byTrigger?: Record<string, string>;\n  };\n};\n\nexport type TriggerSchedulerStartOptions = {\n  pollIntervalMs?: number;\n  batchSize?: number;\n  /** When `organization`, claims due schedules across all projects in the org schema. */\n  scope?: \"project\" | \"organization\";\n};\n\nexport type TriggerScheduler = {\n  sync(options: TriggerScheduleSyncOptions): Promise<void>;\n  start(options?: TriggerSchedulerStartOptions): Promise<StopFn>;\n  /** Register or refresh one trigger schedule in the firing backend. */\n  upsert?(\n    spec: TriggerScheduleSpec,\n    overrides?: TriggerScheduleSyncOptions[\"scheduleOverrides\"],\n  ): Promise<void>;\n  remove?(triggerSlug: string, projectId?: string): Promise<void>;\n  fireDue?(asOf?: Date): Promise<number>;\n};\n\nexport type SchedulerPlugin = {\n  name: string;\n  createJobQueue(ctx: SchedulerPluginContext): Promise<JobQueue>;\n  createTriggerScheduler?(ctx: SchedulerPluginContext, queue: JobQueue): Promise<TriggerScheduler>;\n};\n\nexport function defineSchedulerPlugin(plugin: SchedulerPlugin): SchedulerPlugin {\n  return plugin;\n}\n"],"mappings":";AAiIA,MAAa,yBAAyB;AAEtC,SAAgB,aAAa,SAAyB;CACpD,OAAO,yBAAyB,KAAK,KAAK,IAAI,GAAG,UAAU,CAAC;AAC9D;;;ACzDA,SAAgB,sBAAsB,QAA0C;CAC9E,OAAO;AACT"}