{"version":3,"file":"delegation.cjs","names":["Type","InlineAgentSchema"],"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":"+DAKA,MAAa,EAA0B,kBAQ1B,EAA0BA,EAAAA,KAAK,OAC1C,CACE,UAAWA,EAAAA,KAAK,OAAO,CAAE,UAAW,CAAE,CAAC,EACvC,OAAQA,EAAAA,KAAK,MAAM,CAACA,EAAAA,KAAK,OAAO,EAAGA,EAAAA,KAAK,OAAO,CAAC,CAAC,EACjD,MAAOA,EAAAA,KAAK,OAAO,CAAE,UAAW,CAAE,CAAC,EACnC,YAAaA,EAAAA,KAAK,SAASC,EAAAA,iBAAiB,EAC5C,OAAQD,EAAAA,KAAK,OAAO,CAAE,UAAW,CAAE,CAAC,EACpC,IAAKA,EAAAA,KAAK,OAAO,CAAE,UAAW,CAAE,CAAC,EACjC,MAAOA,EAAAA,KAAK,SAASA,EAAAA,KAAK,OAAO,CAAE,UAAW,CAAE,CAAC,CAAC,EAClD,QAASA,EAAAA,KAAK,SAASA,EAAAA,KAAK,MAAM,CAACA,EAAAA,KAAK,QAAQ,OAAO,EAAGA,EAAAA,KAAK,QAAQ,MAAM,CAAC,CAAC,CAAC,EAChF,UAAWA,EAAAA,KAAK,SAASA,EAAAA,KAAK,QAAQ,CAAE,QAAS,CAAE,CAAC,CAAC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