{"version":3,"file":"backgroundWork.mjs","names":[],"sources":["../../src/schemas/backgroundWork.ts"],"sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\nimport { type Static, Type } from 'typebox';\n\n/** Cordis service that owns pull-based background-work contributions for Pi sessions. */\nexport const DOOM_BACKGROUND_WORK_SERVICE = 'doom/background-work';\n/**\n * Snapshot invalidation only. Consumers must reread the authoritative service snapshot\n * and must not infer current work from the event payload.\n */\nexport const DOOM_BACKGROUND_WORK_CHANGED_EVENT = 'doom/background-work/changed';\n\nexport const BackgroundProviderWorkItemSchema = Type.Object(\n  {\n    id: Type.String({ minLength: 1 }),\n    sessionId: Type.String({ minLength: 1 }),\n    label: Type.Optional(Type.String({ minLength: 1 })),\n    status: Type.Optional(Type.String({ minLength: 1 })),\n  },\n  { additionalProperties: false },\n);\nexport type BackgroundProviderWorkItem = Static<typeof BackgroundProviderWorkItemSchema>;\n\nexport const BackgroundWorkItemSchema = Type.Object(\n  { ...BackgroundProviderWorkItemSchema.properties, provider: Type.String({ minLength: 1 }) },\n  { additionalProperties: false },\n);\nexport type BackgroundWorkItem = Static<typeof BackgroundWorkItemSchema>;\n\nexport interface BackgroundWorkProvider {\n  readonly provider: string;\n  /**\n   * Returns the current authoritative work set. Items must use their owning Pi session ID.\n   * Publish work before releasing asynchronous launch ownership, and retain terminal items\n   * until Pi accepts their completion handoff or a durable fallback owns delivery.\n   */\n  listActiveWork(): readonly BackgroundProviderWorkItem[];\n}\n\nexport interface BackgroundWorkProviderHandle {\n  readonly provider: string;\n  readonly generation: string;\n  /** Announces that the provider's pull-based snapshot changed. This carries no snapshot state. */\n  update(): void;\n  dispose(): void;\n}\n\nexport interface DoomBackgroundWorkSnapshot {\n  readonly items: readonly BackgroundWorkItem[];\n  readonly errors: readonly { readonly provider: string; readonly message: string }[];\n}\n\nexport interface DoomBackgroundWorkChanged {\n  readonly provider: string;\n  readonly generation: string;\n  readonly kind: 'registered' | 'updated' | 'unregistered';\n}\n\nexport interface DoomBackgroundWorkService {\n  /** Changes when the owning coordination service is replaced. */\n  readonly generation: string;\n  register(provider: BackgroundWorkProvider): BackgroundWorkProviderHandle;\n  /** Returns an authoritative snapshot, filtered to an exact session when supplied. */\n  snapshot(sessionId?: string): DoomBackgroundWorkSnapshot;\n}\n\ndeclare module '@deepseek-ai/cordis' {\n  interface Context {\n    'doom/background-work': DoomBackgroundWorkService;\n  }\n\n  interface Events {\n    'doom/background-work/changed'(event: DoomBackgroundWorkChanged): void;\n  }\n}\n\n/** Reads the active host-owned background-work coordination service. */\nexport function readDoomBackgroundWorkService(ctx: Context): DoomBackgroundWorkService | undefined {\n  return ctx.get(DOOM_BACKGROUND_WORK_SERVICE) as DoomBackgroundWorkService | undefined;\n}\n"],"mappings":"+BAIA,MAAa,EAA+B,uBAK/B,EAAqC,+BAErC,EAAmC,EAAK,OACnD,CACE,GAAI,EAAK,OAAO,CAAE,UAAW,CAAE,CAAC,EAChC,UAAW,EAAK,OAAO,CAAE,UAAW,CAAE,CAAC,EACvC,MAAO,EAAK,SAAS,EAAK,OAAO,CAAE,UAAW,CAAE,CAAC,CAAC,EAClD,OAAQ,EAAK,SAAS,EAAK,OAAO,CAAE,UAAW,CAAE,CAAC,CAAC,CACrD,EACA,CAAE,qBAAsB,EAAM,CAChC,EAGa,EAA2B,EAAK,OAC3C,CAAE,GAAG,EAAiC,WAAY,SAAU,EAAK,OAAO,CAAE,UAAW,CAAE,CAAC,CAAE,EAC1F,CAAE,qBAAsB,EAAM,CAChC,EAmDA,SAAgB,EAA8B,EAAqD,CACjG,OAAO,EAAI,IAAI,CAA4B,CAC7C"}