{"version":3,"file":"apiContracts.mjs","names":[],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses } from '@agimon-ai/doompi-core/apiContracts';\nimport { Type } from 'typebox';\n\nconst S = Type.String();\nconst N = Type.Number();\nconst B = Type.Boolean();\nconst O = Type.Optional;\nconst literals = <T extends string>(values: T[]) => Type.Union(values.map((value) => Type.Literal(value)));\nconst RepositoryId = Type.String({ pattern: '^(?:[a-f0-9]{32}|repo-[A-Za-z0-9_-]{24})$' });\nconst RepositoryQuery = [{ name: 'repositoryId', in: 'query' as const, required: true, schema: RepositoryId }];\nexport const McpCatalogSchema = Type.Object({\n  repositoryId: S,\n  sync: Type.Object({ fresh: B, reasons: Type.Array(S) }),\n  servers: Type.Array(\n    Type.Object({\n      name: S,\n      state: literals(['not-connected', 'connecting', 'connected', 'degraded', 'needs-auth', 'failed', 'closed']),\n      source: literals(['cached', 'live', 'configured']),\n      credentialPresent: B,\n      tools: Type.Array(Type.Object({ name: S, piName: S, description: O(S) })),\n      error: O(S),\n    }),\n  ),\n  droppedServers: Type.Array(S),\n  diagnostics: Type.Array(S),\n});\nexport const McpAuthorizationSchema = Type.Object({\n  id: S,\n  repositoryId: S,\n  serverName: S,\n  status: literals(['starting', 'waiting', 'completed', 'failed', 'cancelled', 'expired']),\n  authorizationUrl: O(S),\n  error: O(S),\n  expiresAt: N,\n});\nexport const apiContracts = defineApiContract({\n  version: 1,\n  sockets: [],\n  dynamic: [],\n  http: (['global', 'workspace'] as const).flatMap((scope) => [\n    {\n      id: 'mcp.catalog',\n      scope,\n      basePath: 'mcp',\n      path: '/repository',\n      method: 'GET',\n      authentication: 'owner',\n      description: 'Read the synced MCP repository catalog.',\n      parameters: RepositoryQuery,\n      responses: jsonApiResponses(McpCatalogSchema),\n    },\n    {\n      id: 'mcp.discover',\n      scope,\n      basePath: 'mcp',\n      path: '/repository/discover',\n      method: 'POST',\n      authentication: 'owner',\n      description: 'Discover repository MCP servers.',\n      body: { required: true, contentType: 'application/json', schema: Type.Object({ repositoryId: RepositoryId }) },\n      responses: jsonApiResponses(McpCatalogSchema),\n    },\n    {\n      id: 'mcp.authorize',\n      scope,\n      basePath: 'mcp',\n      path: '/repository/authorize',\n      method: 'POST',\n      authentication: 'owner',\n      description: 'Start MCP authorization.',\n      body: {\n        required: true,\n        contentType: 'application/json',\n        schema: Type.Object({ repositoryId: RepositoryId, serverName: Type.String({ minLength: 1, maxLength: 160 }) }),\n      },\n      responses: jsonApiResponses(McpAuthorizationSchema, 202),\n    },\n    ...(['GET', 'DELETE'] as const).map((method) => ({\n      id: `mcp.authorization.${method}`,\n      scope,\n      basePath: 'mcp',\n      path: '/repository/authorize/{flowId}',\n      method,\n      authentication: 'owner' as const,\n      description: method === 'GET' ? 'Read an authorization flow.' : 'Cancel an authorization flow.',\n      parameters: RepositoryQuery,\n      responses: jsonApiResponses(McpAuthorizationSchema),\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,YAA8B,WAAgB,KAAK,MAAM,OAAO,KAAK,UAAU,KAAK,QAAQ,KAAK,CAAC,CAAC;AACzG,MAAM,eAAe,KAAK,OAAO,EAAE,SAAS,4CAA4C,CAAC;AACzF,MAAM,kBAAkB,CAAC;CAAE,MAAM;CAAgB,IAAI;CAAkB,UAAU;CAAM,QAAQ;AAAa,CAAC;AAC7G,MAAa,mBAAmB,KAAK,OAAO;CAC1C,cAAc;CACd,MAAM,KAAK,OAAO;EAAE,OAAO;EAAG,SAAS,KAAK,MAAM,CAAC;CAAE,CAAC;CACtD,SAAS,KAAK,MACZ,KAAK,OAAO;EACV,MAAM;EACN,OAAO,SAAS;GAAC;GAAiB;GAAc;GAAa;GAAY;GAAc;GAAU;EAAQ,CAAC;EAC1G,QAAQ,SAAS;GAAC;GAAU;G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