{"version":3,"file":"apiContracts.mjs","names":[],"sources":["../../../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses, type DoomHttpContract } from '@agimon-ai/doompi-core/api-contracts';\nimport { Type } from 'typebox';\n\nconst S = Type.String();\nconst N = Type.Number();\nconst B = Type.Boolean();\nconst O = Type.Optional;\nconst values = <T extends string>(items: T[]) => Type.Union(items.map((item) => Type.Literal(item)));\nconst Progress = values(['running', 'completed', 'skipped', 'failed', 'pause_requested', 'paused', 'resumed']);\nconst Step = { name: S, status: Progress, reason: O(S), startedAt: O(S), endedAt: O(S) };\nconst Run = Type.Object({\n  runKey: S,\n  workspace: S,\n  displayName: S,\n  workflowName: O(S),\n  workflowPath: S,\n  stage: values(['running', 'completed', 'error']),\n  outcome: O(values(['success', 'skipped', 'failed', 'interrupted'])),\n  executionState: O(values(['running', 'pause_requested', 'paused', 'resume_requested'])),\n  prompt: O(S),\n  startedAt: S,\n  finishedAt: O(S),\n  errorMessage: O(S),\n  failedJob: O(S),\n  stale: O(B),\n  staleReason: O(S),\n  worktreeBranch: O(S),\n  position: O(Type.Object({ job: S, step: O(S), index: O(N), total: O(N) })),\n  jobs: Type.Array(\n    Type.Object({\n      ...Step,\n      phase: values(['pre', 'job', 'post']),\n      index: O(N),\n      total: O(N),\n      steps: Type.Array(Type.Object(Step)),\n    }),\n  ),\n});\nexport const WorkflowRunsSchema = Type.Object({ runs: Type.Array(Run) });\nconst Artifact = { path: S, kind: values(['file', 'directory']), description: S, producedBy: Type.Array(S) };\nexport const WorkflowCatalogSchema = Type.Object({\n  cwd: S,\n  warning: O(S),\n  workflows: Type.Array(\n    Type.Object({\n      path: S,\n      relativePath: S,\n      name: S,\n      description: S,\n      tags: Type.Array(S),\n      triggers: Type.Array(S),\n      inputs: Type.Array(\n        Type.Object({\n          name: S,\n          description: O(S),\n          required: O(B),\n          default: O(S),\n          type: O(S),\n          options: O(Type.Array(S)),\n        }),\n      ),\n      jobs: Type.Array(Type.Object({ name: S, steps: Type.Array(S) })),\n      artifacts: Type.Array(Type.Object(Artifact)),\n      runners: O(Type.Array(S)),\n      error: O(S),\n    }),\n  ),\n});\nconst Screen = Type.Object({\n  lines: Type.Array(S),\n  capabilities: Type.Object({ readable: B, writable: B, resizable: B, reason: O(S) }),\n  ended: O(B),\n});\nconst Control = Type.Object({ held: B, token: O(S), reason: O(S) });\nconst root = '/runs/{workspace}/{runKey}';\nexport const apiContracts = defineApiContract({\n  version: 1,\n  dynamic: [],\n  http: (['global', 'workspace', 'session'] as const).flatMap((scope): DoomHttpContract[] => [\n    {\n      id: 'workflow.screen',\n      scope,\n      basePath: 'workflow',\n      path: `${root}/screen/stream`,\n      method: 'GET',\n      authentication: 'owner',\n      description: 'Follow the workflow terminal.',\n      responses: {\n        '200': {\n          description: 'SSE stream with JSON screen events.',\n          contentType: 'text/event-stream',\n          schema: S,\n          events: { screen: Screen },\n        },\n        '404': { description: 'Run unavailable.', schema: Type.Object({ error: S }) },\n      },\n    },\n    {\n      id: 'workflow.control',\n      scope,\n      basePath: 'workflow',\n      path: `${root}/control`,\n      method: 'POST',\n      authentication: 'owner',\n      description: 'Take or release the keyboard.',\n      body: { required: true, contentType: 'application/json', schema: Type.Object({ release: O(B), token: O(S) }) },\n      responses: { ...jsonApiResponses(Control), '409': { description: 'Keyboard unavailable.', schema: Control } },\n    },\n    {\n      id: 'workflow.keys',\n      scope,\n      basePath: 'workflow',\n      path: `${root}/keys`,\n      method: 'POST',\n      authentication: 'owner',\n      description: 'Write terminal data with the control token.',\n      body: { required: true, contentType: 'application/json', schema: Type.Object({ token: S, data: S }) },\n      responses: {\n        '204': { description: 'Data written.' },\n        '400': { description: 'Invalid request.', schema: Type.Object({ error: S }) },\n        '409': { description: 'Write refused.', schema: Type.Object({ error: S }) },\n      },\n    },\n    {\n      id: 'workflow.resize',\n      scope,\n      basePath: 'workflow',\n      path: `${root}/resize`,\n      method: 'POST',\n      authentication: 'owner',\n      description: 'Resize the terminal.',\n      body: { required: true, contentType: 'application/json', schema: Type.Object({ token: S, columns: N, rows: N }) },\n      responses: jsonApiResponses(Type.Object({ resized: B })),\n    },\n    {\n      id: 'workflow.delete',\n      scope,\n      basePath: 'workflow',\n      path: root,\n      method: 'DELETE',\n      authentication: 'owner',\n      description: 'Delete a settled run and its directory.',\n      responses: jsonApiResponses(Type.Object({ deleted: Type.Literal(true) })),\n    },\n    {\n      id: 'workflow.artifacts',\n      scope,\n      basePath: 'workflow',\n      path: `${root}/artifacts`,\n      method: 'GET',\n      authentication: 'owner',\n      description: 'List declared and discovered artifacts.',\n      responses: jsonApiResponses(\n        Type.Object({\n          runDir: S,\n          description: S,\n          artifacts: Type.Array(\n            Type.Object({\n              ...Artifact,\n              declared: B,\n              state: values(['written', 'empty', 'pending', 'unreadable']),\n              size: O(N),\n              modifiedAt: O(S),\n            }),\n          ),\n        }),\n      ),\n    },\n    {\n      id: 'workflow.artifact',\n      scope,\n      basePath: 'workflow',\n      path: `${root}/artifacts/{name}`,\n      method: 'GET',\n      authentication: 'owner',\n      description:\n        'Read artifact metadata and text. name may contain nested path segments. raw=1 streams binary with its media type and supports byte ranges.',\n      parameters: [\n        { name: 'raw', in: 'query', required: false, schema: values(['0', '1']) },\n        { name: 'download', in: 'query', required: false, schema: values(['0', '1']) },\n        { name: 'range', in: 'header', required: false, schema: S },\n      ],\n      responses: {\n        ...jsonApiResponses(\n          Type.Union([Type.Object({ path: S, size: N, modifiedAt: S, mimeType: O(S), text: O(S), truncated: B }), S]),\n        ),\n        '206': { description: 'Partial raw bytes.', contentType: 'application/octet-stream', schema: S },\n        '416': { description: 'Unsatisfiable byte range.' },\n      },\n    },\n  ]),\n  sockets: (['global', 'workspace'] as const).flatMap((scope) => [\n    {\n      id: 'workflow.runs',\n      scope,\n      service: 'doompi.hub.v1',\n      member: 'workflow_runs',\n      kind: 'channel',\n      direction: 'server-to-client',\n      description: 'Workflow runs channel payload.',\n      input: WorkflowRunsSchema,\n    },\n    {\n      id: 'workflow.catalog',\n      scope,\n      service: 'doompi.hub.v1',\n      member: 'workflow_catalog',\n      kind: 'channel',\n      direction: 'server-to-client',\n      description: 'Workflow catalog channel payload.',\n      input: WorkflowCatalogSchema,\n    },\n  ]),\n});\nexport default apiContracts;\n"],"mappings":";;;AAGA,MAAM,IAAI,KAAK,OAAO;AACtB,MAAM,IAAI,KAAK,OAAO;AACtB,MAAM,IAAI,KAAK,QAAQ;AACvB,MAAM,IAAI,KAAK;AACf,MAAM,UAA4B,UAAe,KAAK,MAAM,MAAM,KAAK,SAAS,KAAK,QAAQ,IAAI,CAAC,CAAC;AAEnG,MAAM,OAAO;CAAE,MAAM;CAAG,QADP,OAAO;EAAC;EAAW;EAAa;EAAW;EAAU;EAAmB;EAAU;CAAS,CACrE;CAAG,QAAQ,EAAE,CAAC;CAAG,WAAW,EAAE,CAAC;CAAG,SAAS,EAAE,CAAC;AAAE;AACvF,MAAM,MAAM,KAAK,OAAO;CACtB,QAAQ;CACR,WAAW;CACX,aAAa;CACb,cAAc,EAAE,CAAC;CACjB,cAAc;CACd,OAAO,OAAO;EAAC;EAAW;EAAa;CAAO,CAAC;CAC/C,SAAS,EAAE,OAAO;EAAC;EAAW;EAAW;EAAU;CAAa,CAAC,CAAC;CAClE,gBAAgB,EAAE,OAAO;EAAC;EAAW;EAAmB;EAAU;CAAkB,CAAC,CAAC;CACtF,QAAQ,EAAE,CAAC;CACX,WAAW;CACX,YAAY,EAAE,CAAC;CACf,cAAc,EAAE,CAAC;CACjB,WAAW,EAAE,CAAC;CACd,OAAO,EAAE,CAAC;CACV,aAAa,EAAE,CAAC;CAChB,gBAAgB,EAAE,CAAC;CACnB,UAAU,EAAE,KAAK,OAAO;EAAE,KAAK;EAAG,MAAM,EAAE,CAAC;EAAG,OAAO,EAAE,CAAC;EAAG,OAAO,EAAE,CAAC;CAAE,CAAC,CAAC;CACzE,MAAM,KAAK,MACT,KAAK,OAAO;EACV,GAAG;EACH,OAAO,OAAO;GAAC;GAAO;GAAO;EAAM,CAAC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