{"version":3,"file":"delegation.mjs","names":[],"sources":["../../src/schemas/delegation.ts"],"sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\nimport { type Static, Type } from 'typebox';\nimport { InlineAgentSchema } from './subagentTool.ts';\n\n/** Team-owned Cordis service for one session's delegated runs. */\nexport const DOOM_DELEGATION_SERVICE = 'doom/delegation';\nexport const DOOM_DELEGATION_REQUESTED_EVENT = 'doom/delegation/requested';\nexport const DOOM_DELEGATION_ACCEPTED_EVENT = 'doom/delegation/accepted';\nexport const DOOM_DELEGATION_STARTED_EVENT = 'doom/delegation/started';\nexport const DOOM_DELEGATION_UPDATED_EVENT = 'doom/delegation/updated';\nexport const DOOM_DELEGATION_FINISHED_EVENT = 'doom/delegation/finished';\nexport const DOOM_DELEGATION_CANCELLED_EVENT = 'doom/delegation/cancelled';\n\nexport const DelegationRequestSchema = Type.Object(\n  {\n    requestId: Type.String({ minLength: 1 }),\n    taskId: Type.Union([Type.String(), Type.Number()]),\n    agent: Type.String({ minLength: 1 }),\n    inlineAgent: Type.Optional(InlineAgentSchema),\n    prompt: Type.String({ minLength: 1 }),\n    cwd: Type.String({ minLength: 1 }),\n    model: Type.Optional(Type.String({ minLength: 1 })),\n    context: Type.Optional(Type.Union([Type.Literal('fresh'), Type.Literal('fork')])),\n    timeoutMs: Type.Optional(Type.Integer({ minimum: 1 })),\n    artifacts: Type.Optional(Type.Boolean()),\n    runMode: Type.Optional(Type.Union([Type.Literal('foreground'), Type.Literal('detached')])),\n    teamTask: Type.Optional(\n      Type.Object(\n        { id: Type.String({ minLength: 1 }), subject: Type.String({ minLength: 1 }) },\n        { additionalProperties: false },\n      ),\n    ),\n  },\n  { additionalProperties: false },\n);\nexport type DelegationRequest = Static<typeof DelegationRequestSchema>;\n\nexport const DelegationAcceptedSchema = Type.Object(\n  { requestId: Type.String({ minLength: 1 }) },\n  { additionalProperties: false },\n);\nexport type DelegationAccepted = Static<typeof DelegationAcceptedSchema>;\n\nexport const DelegationStartedSchema = Type.Object(\n  { requestId: Type.String({ minLength: 1 }), runId: Type.String({ minLength: 1 }) },\n  { additionalProperties: false },\n);\nexport type DelegationStarted = Static<typeof DelegationStartedSchema>;\n\nexport const DelegationUpdateSchema = Type.Object(\n  {\n    requestId: Type.String({ minLength: 1 }),\n    runId: Type.String({ minLength: 1 }),\n    status: Type.Optional(Type.String({ minLength: 1 })),\n    currentTool: Type.Optional(Type.String({ minLength: 1 })),\n    toolCount: Type.Optional(Type.Integer({ minimum: 0 })),\n    durationMs: Type.Optional(Type.Integer({ minimum: 0 })),\n    tokens: Type.Optional(Type.Integer({ minimum: 0 })),\n  },\n  { additionalProperties: false },\n);\nexport type DelegationUpdate = Static<typeof DelegationUpdateSchema>;\n\nexport const DelegationStatusSchema = Type.Union([\n  Type.Literal('completed'),\n  Type.Literal('failed'),\n  Type.Literal('timed_out'),\n  Type.Literal('cancelled'),\n  Type.Literal('interrupted'),\n  Type.Literal('turn_budget_exhausted'),\n  Type.Literal('tool_budget_exhausted'),\n  Type.Literal('acceptance_failed'),\n  Type.Literal('invalid_request'),\n  Type.Literal('unavailable_context'),\n]);\nexport type DelegationStatus = Static<typeof DelegationStatusSchema>;\n\nexport const DelegationResultSchema = Type.Object(\n  {\n    requestId: Type.String({ minLength: 1 }),\n    runId: Type.String({ minLength: 1 }),\n    status: DelegationStatusSchema,\n    output: Type.Optional(Type.String()),\n    error: Type.Optional(Type.String()),\n    outputPath: Type.Optional(Type.String({ minLength: 1 })),\n    sessionFile: Type.Optional(Type.String({ minLength: 1 })),\n    durationMs: Type.Optional(Type.Integer({ minimum: 0 })),\n    toolCount: Type.Optional(Type.Integer({ minimum: 0 })),\n  },\n  { additionalProperties: false },\n);\nexport type DelegationResult = Static<typeof DelegationResultSchema>;\n\nexport const DelegationCancelSchema = Type.Object(\n  { requestId: Type.String({ minLength: 1 }), reason: Type.Optional(Type.String({ minLength: 1 })) },\n  { additionalProperties: false },\n);\nexport type DelegationCancel = Static<typeof DelegationCancelSchema>;\n\nexport interface DoomDelegationService {\n  readonly sessionId: string;\n  readonly generation: string;\n  request(request: DelegationRequest): Promise<void>;\n  cancel(request: DelegationCancel): void;\n}\n\ndeclare module '@deepseek-ai/cordis' {\n  interface Context {\n    'doom/delegation': DoomDelegationService;\n  }\n\n  interface Events {\n    'doom/delegation/requested'(event: DelegationRequest): void;\n    'doom/delegation/accepted'(event: DelegationAccepted): void;\n    'doom/delegation/started'(event: DelegationStarted): void;\n    'doom/delegation/updated'(event: DelegationUpdate): void;\n    'doom/delegation/finished'(event: DelegationResult): void;\n    'doom/delegation/cancelled'(event: DelegationCancel): void;\n  }\n}\n\nexport function readDoomDelegationService(ctx: Context): DoomDelegationService | undefined {\n  return ctx.get(DOOM_DELEGATION_SERVICE) as DoomDelegationService | undefined;\n}\n"],"mappings":"sFAKA,MAAa,EAA0B,kBAC1B,EAAkC,4BAClC,EAAiC,2BACjC,EAAgC,0BAChC,EAAgC,0BAChC,EAAiC,2BACjC,EAAkC,4BAElC,EAA0B,EAAK,OAC1C,CACE,UAAW,EAAK,OAAO,CAAE,UAAW,CAAE,CAAC,EACvC,OAAQ,EAAK,MAAM,CAAC,EAAK,OAAO,EAAG,EAAK,OAAO,CAAC,CAAC,EACjD,MAAO,EAAK,OAAO,CAAE,UAAW,CAAE,CAAC,EACnC,YAAa,EAAK,SAAS,CAAiB,EAC5C,OAAQ,EAAK,OAAO,CAAE,UAAW,CAAE,CAAC,EACpC,IAAK,EAAK,OAAO,CAAE,UAAW,CAAE,CAAC,EACjC,MAAO,EAAK,SAAS,EAAK,OAAO,CAAE,UAAW,CAAE,CAAC,CAAC,EAClD,QAAS,EAAK,SAAS,EAAK,MAAM,CAAC,EAAK,QAAQ,OAAO,EAAG,EAAK,QAAQ,MAAM,CAAC,CAAC,CAAC,EAChF,UAAW,EAAK,SAAS,EAAK,QAAQ,CAAE,QAAS,CAAE,CAAC,CAAC,EACrD,UAAW,EAAK,SAAS,EAAK,QAAQ,CAAC,EACvC,QAAS,EAAK,SAAS,EAA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