From 1c49528fb5549a691830ae9da200d1f63f103e14 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Fri, 23 May 2025 01:33:15 +0700 Subject: [PATCH] =?UTF-8?q?=E2=99=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/bin/generate-project-schema.ts | 87 +++++++++++++++++++++++++ apps/api/package.json | 3 +- apps/api/src/db/schema/deployment.ts | 5 +- apps/api/src/db/schema/schemas.ts | 2 +- apps/api/tsconfig.json | 2 +- pnpm-lock.yaml | 3 + 6 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 apps/api/bin/generate-project-schema.ts diff --git a/apps/api/bin/generate-project-schema.ts b/apps/api/bin/generate-project-schema.ts new file mode 100644 index 00000000..74d84dcd --- /dev/null +++ b/apps/api/bin/generate-project-schema.ts @@ -0,0 +1,87 @@ +import 'dotenv/config' + +import { z } from '@hono/zod-openapi' +import restoreCursor from 'restore-cursor' +import { zodToJsonSchema } from 'zod-to-json-schema' + +import { deploymentOriginAdapterSchema, pricingPlanListSchema } from '@/db' + +// TODO: +// - **service / tool definitions** +// - optional per-service config (PricingPlanServiceConfigMap) +// - optional external auth provider config (google, github, twitter, etc) +// - origin adapter openapi schema path, url, or in-place definition +// - optional stripe webhooks +// - optional response header config (custom headers, immutability for caching, etc) + +const publicSchema = z.object({ + name: z.string().describe('The name of the project.'), + + // Metadata + description: z + .string() + .describe('A one-sentence description of the project.') + .optional(), + readme: z + .string() + .describe( + 'A readme documenting the project (supports GitHub-flavored markdown).' + ) + .optional(), + sourceUrl: z + .string() + .url() + .optional() + .describe('Optional URL to the source code for this project.'), + iconUrl: z + .string() + .url() + .optional() + .describe( + 'Optional logo image URL to use for this project. Logos should have a square aspect ratio.' + ), + + // Required origin API config + originUrl: z.string().url() + .describe(`Required base URL of the externally hosted origin API server. Must be a valid \`https\` URL. + +NOTE: Agentic currently only supports \`external\` API servers. If you'd like to host your API or MCP server on Agentic's infrastructure, please reach out to support@agentic.so.`), + + // Optional origin API config + originAdapter: deploymentOriginAdapterSchema + .default({ + location: 'external', + type: 'raw' + }) + .optional(), + + // Optional subscription pricing config + pricingPlans: pricingPlanListSchema + .describe( + 'List of PricingPlans to enable subscriptions for this project. Defaults to a single free tier.' + ) + .default([ + { + name: 'Free', + slug: 'free', + lineItems: [ + { + slug: 'base', + usageType: 'licensed', + amount: 0 + } + ] + } + ]) +}) + +async function main() { + restoreCursor() + + const publicJsonSchema = zodToJsonSchema(publicSchema) + + // eslint-disable-next-line no-console + console.log(JSON.stringify(publicJsonSchema, null, 2)) +} + +await main() diff --git a/apps/api/package.json b/apps/api/package.json index e80e8d14..d334640b 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -55,6 +55,7 @@ "@types/semver": "^7.7.0", "drizzle-kit": "^0.31.1", "drizzle-orm": "^0.43.1", - "openapi-typescript": "^7.8.0" + "openapi-typescript": "^7.8.0", + "zod-to-json-schema": "^3.24.5" } } diff --git a/apps/api/src/db/schema/deployment.ts b/apps/api/src/db/schema/deployment.ts index d24871e7..3d099958 100644 --- a/apps/api/src/db/schema/deployment.ts +++ b/apps/api/src/db/schema/deployment.ts @@ -53,6 +53,7 @@ export const deployments = pgTable( description: text().default('').notNull(), readme: text().default('').notNull(), iconUrl: text(), + sourceUrl: text(), userId: userId() .notNull() @@ -164,9 +165,11 @@ export const deploymentInsertSchema = createInsertSchema(deployments, { schema .url() .describe( - 'Logo image URL to use for this delpoyment. Logos should have a square aspect ratio.' + 'Logo image URL to use for this deployment. Logos should have a square aspect ratio.' ), + sourceUrl: (schema) => schema.url(), + originUrl: (schema) => schema.url().describe(`Base URL of the externally hosted origin API server. diff --git a/apps/api/src/db/schema/schemas.ts b/apps/api/src/db/schema/schemas.ts index 21e99d3e..facde8d3 100644 --- a/apps/api/src/db/schema/schemas.ts +++ b/apps/api/src/db/schema/schemas.ts @@ -296,7 +296,7 @@ export const pricingPlanSchema = z interval: pricingIntervalSchema.optional(), desc: z.string().optional(), - features: z.array(z.string()), + features: z.array(z.string()).optional(), // TODO? trialPeriodDays: z.number().nonnegative().optional(), diff --git a/apps/api/tsconfig.json b/apps/api/tsconfig.json index 7af731f3..235bf7d7 100644 --- a/apps/api/tsconfig.json +++ b/apps/api/tsconfig.json @@ -6,6 +6,6 @@ "@/*": ["src/*"] } }, - "include": ["src", "*.config.ts", "../../packages/core/src/errors.ts"], + "include": ["src", "*.config.ts", "bin/*"], "exclude": ["node_modules", "dist"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8ef6f8a4..cd80159e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -213,6 +213,9 @@ importers: openapi-typescript: specifier: ^7.8.0 version: 7.8.0(typescript@5.8.3) + zod-to-json-schema: + specifier: ^3.24.5 + version: 3.24.5(zod@3.24.4) packages/api-client: dependencies: