From 1faf1b707a32ee9f98e830664a037d1fd7fc05bf Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Mon, 19 May 2025 16:16:02 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/api-v1/deployments/get-deployment.ts | 2 +- .../api-v1/deployments/publish-deployment.ts | 2 +- .../api-v1/deployments/update-deployment.ts | 2 +- apps/api/src/db/schema/deployment.ts | 6 ++++- apps/api/src/db/schema/schemas.ts | 22 ++++++++++++++----- .../{ => deployments}/try-get-deployment.ts | 7 +++--- 6 files changed, 28 insertions(+), 13 deletions(-) rename apps/api/src/lib/{ => deployments}/try-get-deployment.ts (94%) diff --git a/apps/api/src/api-v1/deployments/get-deployment.ts b/apps/api/src/api-v1/deployments/get-deployment.ts index 44df070e..b3b71142 100644 --- a/apps/api/src/api-v1/deployments/get-deployment.ts +++ b/apps/api/src/api-v1/deployments/get-deployment.ts @@ -3,12 +3,12 @@ import { createRoute, type OpenAPIHono } from '@hono/zod-openapi' import type { AuthenticatedEnv } from '@/lib/types' import { schema } from '@/db' import { acl } from '@/lib/acl' +import { tryGetDeployment } from '@/lib/deployments/try-get-deployment' import { openapiAuthenticatedSecuritySchemas, openapiErrorResponse404, openapiErrorResponses } from '@/lib/openapi-utils' -import { tryGetDeployment } from '@/lib/try-get-deployment' import { assert, parseZodSchema } from '@/lib/utils' import { deploymentIdParamsSchema, populateDeploymentSchema } from './schemas' diff --git a/apps/api/src/api-v1/deployments/publish-deployment.ts b/apps/api/src/api-v1/deployments/publish-deployment.ts index 9e1b3639..9229919e 100644 --- a/apps/api/src/api-v1/deployments/publish-deployment.ts +++ b/apps/api/src/api-v1/deployments/publish-deployment.ts @@ -4,12 +4,12 @@ import type { AuthenticatedEnv } from '@/lib/types' import { schema } from '@/db' import { acl } from '@/lib/acl' import { publishDeployment } from '@/lib/deployments/publish-deployment' +import { tryGetDeployment } from '@/lib/deployments/try-get-deployment' import { openapiAuthenticatedSecuritySchemas, openapiErrorResponse404, openapiErrorResponses } from '@/lib/openapi-utils' -import { tryGetDeployment } from '@/lib/try-get-deployment' import { assert, parseZodSchema } from '@/lib/utils' import { deploymentIdParamsSchema } from './schemas' diff --git a/apps/api/src/api-v1/deployments/update-deployment.ts b/apps/api/src/api-v1/deployments/update-deployment.ts index 377016a5..e9ab1311 100644 --- a/apps/api/src/api-v1/deployments/update-deployment.ts +++ b/apps/api/src/api-v1/deployments/update-deployment.ts @@ -3,12 +3,12 @@ import { createRoute, type OpenAPIHono } from '@hono/zod-openapi' import type { AuthenticatedEnv } from '@/lib/types' import { db, eq, schema } from '@/db' import { acl } from '@/lib/acl' +import { tryGetDeployment } from '@/lib/deployments/try-get-deployment' import { openapiAuthenticatedSecuritySchemas, openapiErrorResponse404, openapiErrorResponses } from '@/lib/openapi-utils' -import { tryGetDeployment } from '@/lib/try-get-deployment' import { assert, parseZodSchema } from '@/lib/utils' import { deploymentIdParamsSchema } from './schemas' diff --git a/apps/api/src/db/schema/deployment.ts b/apps/api/src/db/schema/deployment.ts index 47a4217f..d208ba7b 100644 --- a/apps/api/src/db/schema/deployment.ts +++ b/apps/api/src/db/schema/deployment.ts @@ -176,7 +176,11 @@ NOTE: Agentic currently only supports \`external\` API servers. If you'd like to pricingPlans: pricingPlanListSchema.describe( 'List of PricingPlans should be available as subscriptions for this deployment.' ), - originAdapter: deploymentOriginAdapterSchema.optional() + originAdapter: deploymentOriginAdapterSchema.default({ + location: 'external', + type: 'raw' + }) + // .optional() // TODO // coupons: z.array(couponSchema).optional() diff --git a/apps/api/src/db/schema/schemas.ts b/apps/api/src/db/schema/schemas.ts index a1065054..8fae7f50 100644 --- a/apps/api/src/db/schema/schemas.ts +++ b/apps/api/src/db/schema/schemas.ts @@ -452,11 +452,25 @@ export const commonDeploymentOriginAdapterSchema = z.object({ // internalType: deploymentOriginAdapterInternalTypeSchema.optional() }) +const jsonLiteralSchema = z.union([ + z.string(), + z.number(), + z.boolean(), + z.null() +]) +type JsonLiteral = z.infer +type Json = JsonLiteral | { [key: string]: Json } | Json[] +const jsonSchema: z.ZodType = z.lazy(() => + z.union([jsonLiteralSchema, z.array(jsonSchema), z.record(jsonSchema)]) +) +const jsonObjectSchema = z.record(jsonSchema) + // TODO: add future support for: // - external mcp // - internal docker // - internal mcp // - internal http +// - etc export const deploymentOriginAdapterSchema = z .discriminatedUnion('type', [ z @@ -464,7 +478,9 @@ export const deploymentOriginAdapterSchema = z type: z.literal('openapi'), version: z.enum(['3.0', '3.1']), // TODO: Make sure origin API servers are hidden in this embedded OpenAPI spec - spec: z.any().describe('JSON OpenAPI spec for the origin API server.') + spec: jsonObjectSchema.describe( + 'JSON OpenAPI spec for the origin API server.' + ) }) .merge(commonDeploymentOriginAdapterSchema), @@ -474,10 +490,6 @@ export const deploymentOriginAdapterSchema = z }) .merge(commonDeploymentOriginAdapterSchema) ]) - .default({ - location: 'external', - type: 'raw' - }) .describe( `Deployment origin API adapter is used to configure the origin API server downstream from Agentic's API gateway. It specifies whether the origin API server denoted by \`originUrl\` is hosted externally or deployed internally to Agentic's infrastructure. It also specifies the format for how origin tools / services are defined: either as an OpenAPI spec, an MCP server, or as a raw HTTP REST API. diff --git a/apps/api/src/lib/try-get-deployment.ts b/apps/api/src/lib/deployments/try-get-deployment.ts similarity index 94% rename from apps/api/src/lib/try-get-deployment.ts rename to apps/api/src/lib/deployments/try-get-deployment.ts index d2952eaa..f6230844 100644 --- a/apps/api/src/lib/try-get-deployment.ts +++ b/apps/api/src/lib/deployments/try-get-deployment.ts @@ -1,10 +1,9 @@ import { parseFaasIdentifier } from '@agentic/validators' +import type { AuthenticatedContext } from '@/lib/types' import { db, eq, type RawDeployment, schema } from '@/db' - -import type { AuthenticatedContext } from './types' -import { ensureAuthUser } from './ensure-auth-user' -import { assert } from './utils' +import { ensureAuthUser } from '@/lib/ensure-auth-user' +import { assert } from '@/lib/utils' /** * Attempts to find the Deployment matching the given identifier.