From 9562d92b245472291dcfd17c7492782c6f69732b Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Tue, 10 Jun 2025 12:01:46 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eslint.config.js | 6 +- .../everything-openapi/agentic.config.ts | 71 +++++++++++++++++++ .../valid/everything-openapi/package.json | 25 +++++++ .../everything-openapi/src/exit-hooks.ts | 22 ++++++ .../valid/everything-openapi/src/lib/db.ts | 1 + .../everything-openapi/src/routes/get-user.ts | 48 +++++++++++++ .../src/routes/health-check.ts | 26 +++++++ .../valid/everything-openapi/src/server.ts | 29 ++++++++ .../valid/everything-openapi/tsconfig.json | 5 ++ packages/types/src/tools.ts | 2 +- pnpm-lock.yaml | 18 +++++ readme.md | 10 +-- 12 files changed, 257 insertions(+), 6 deletions(-) create mode 100644 packages/fixtures/valid/everything-openapi/agentic.config.ts create mode 100644 packages/fixtures/valid/everything-openapi/package.json create mode 100644 packages/fixtures/valid/everything-openapi/src/exit-hooks.ts create mode 100644 packages/fixtures/valid/everything-openapi/src/lib/db.ts create mode 100644 packages/fixtures/valid/everything-openapi/src/routes/get-user.ts create mode 100644 packages/fixtures/valid/everything-openapi/src/routes/health-check.ts create mode 100644 packages/fixtures/valid/everything-openapi/src/server.ts create mode 100644 packages/fixtures/valid/everything-openapi/tsconfig.json diff --git a/eslint.config.js b/eslint.config.js index b2bf0ebf..302852fd 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -20,7 +20,11 @@ export default [ } }, { - files: ['packages/cli/src/**/*.ts', '**/*.test.ts'], + files: [ + 'packages/cli/src/**/*.ts', + '**/*.test.ts', + 'packages/fixtures/valid/**/*.ts' + ], rules: { 'no-console': 'off', 'no-process-env': 'off', diff --git a/packages/fixtures/valid/everything-openapi/agentic.config.ts b/packages/fixtures/valid/everything-openapi/agentic.config.ts new file mode 100644 index 00000000..bbb7b9d2 --- /dev/null +++ b/packages/fixtures/valid/everything-openapi/agentic.config.ts @@ -0,0 +1,71 @@ +import { defineConfig } from '@agentic/platform' + +export default defineConfig({ + name: 'test-everything-openapi', + // TODO: deployed url + originUrl: 'TODO', + originAdapter: { + type: 'openapi', + spec: 'TODO/docs' + }, + toolConfigs: [ + { + name: 'getUser', + enabled: true, + pure: true, + // cacheControl: 'no-cache', + reportUsage: true, + rateLimit: null, + pricingPlanConfigMap: { + free: { + enabled: true, + reportUsage: true + } + } + }, + { + name: 'disabledTool', + enabled: false + }, + { + name: 'disabledForFreePlanTool', + pricingPlanConfigMap: { + free: { + enabled: false + } + } + }, + { + name: 'pureTool', + pure: true + }, + { + name: 'unpureToolMarkedPure', + pure: true + }, + { + name: 'customCacheControlTool', + cacheControl: + 'public, max-age=7200, s-maxage=7200, stale-while-revalidate=3600' + }, + { + name: 'noCacheCacheControlTool', + cacheControl: 'no-cache' + }, + { + name: 'noStoreCacheControlTool', + cacheControl: 'no-store' + }, + { + name: 'customRateLimitTool', + rateLimit: { + interval: '30s', + maxPerInterval: 10 + } + }, + { + name: 'disabledRateLimitTool', + rateLimit: null + } + ] +}) diff --git a/packages/fixtures/valid/everything-openapi/package.json b/packages/fixtures/valid/everything-openapi/package.json new file mode 100644 index 00000000..6a6767e9 --- /dev/null +++ b/packages/fixtures/valid/everything-openapi/package.json @@ -0,0 +1,25 @@ +{ + "name": "@agentic/platform-fixtures-everything-openapi", + "private": true, + "author": "Travis Fischer ", + "license": "UNLICENSED", + "repository": { + "type": "git", + "url": "git+https://github.com/transitive-bullshit/agentic-platform.git", + "directory": "packages/fixtures/valid/everything-openapi" + }, + "type": "module", + "scripts": { + "start": "tsx src/server.ts", + "test": "run-s test:*", + "test:lint": "eslint .", + "test:typecheck": "tsc --noEmit" + }, + "dependencies": { + "@hono/node-server": "catalog:", + "@hono/zod-openapi": "catalog:", + "hono": "catalog:", + "restore-cursor": "catalog:", + "zod": "catalog:" + } +} diff --git a/packages/fixtures/valid/everything-openapi/src/exit-hooks.ts b/packages/fixtures/valid/everything-openapi/src/exit-hooks.ts new file mode 100644 index 00000000..2f5ef063 --- /dev/null +++ b/packages/fixtures/valid/everything-openapi/src/exit-hooks.ts @@ -0,0 +1,22 @@ +import type { ServerType } from '@hono/node-server' +import restoreCursor from 'restore-cursor' + +export function initExitHooks({ server }: { server: ServerType }) { + // Gracefully restore the cursor if run from a TTY + restoreCursor() + + process.on('SIGINT', () => { + server.close() + process.exit(0) + }) + + process.on('SIGTERM', () => { + server.close((err) => { + if (err) { + console.error(err) + process.exit(1) + } + process.exit(0) + }) + }) +} diff --git a/packages/fixtures/valid/everything-openapi/src/lib/db.ts b/packages/fixtures/valid/everything-openapi/src/lib/db.ts new file mode 100644 index 00000000..25474f4e --- /dev/null +++ b/packages/fixtures/valid/everything-openapi/src/lib/db.ts @@ -0,0 +1 @@ +export const db = new Map() diff --git a/packages/fixtures/valid/everything-openapi/src/routes/get-user.ts b/packages/fixtures/valid/everything-openapi/src/routes/get-user.ts new file mode 100644 index 00000000..c2a684b2 --- /dev/null +++ b/packages/fixtures/valid/everything-openapi/src/routes/get-user.ts @@ -0,0 +1,48 @@ +import { createRoute, type OpenAPIHono, z } from '@hono/zod-openapi' + +const route = createRoute({ + description: 'Gets a user', + tags: ['users'], + operationId: 'getUser', + method: 'get', + path: '/users/{userId}', + request: { + params: z.object({ + userId: z.string().openapi({ + param: { + description: 'User ID', + name: 'userId', + in: 'path' + } + }) + }) + }, + responses: { + 200: { + description: 'A user object', + content: { + 'application/json': { + schema: z + .object({ + id: z.string(), + name: z.string(), + email: z.string() + }) + .openapi('User') + } + } + } + } +}) + +export function registerGetUser(app: OpenAPIHono) { + return app.openapi(route, async (c) => { + const { userId } = c.req.valid('param') + + return c.json({ + id: userId, + name: 'John Doe', + email: 'john.doe@example.com' + }) + }) +} diff --git a/packages/fixtures/valid/everything-openapi/src/routes/health-check.ts b/packages/fixtures/valid/everything-openapi/src/routes/health-check.ts new file mode 100644 index 00000000..65e9775d --- /dev/null +++ b/packages/fixtures/valid/everything-openapi/src/routes/health-check.ts @@ -0,0 +1,26 @@ +import { createRoute, type OpenAPIHono, z } from '@hono/zod-openapi' + +const route = createRoute({ + description: 'Check if the server is healthy', + operationId: 'healthCheck', + method: 'get', + path: '/health', + responses: { + 200: { + description: 'OK', + content: { + 'application/json': { + schema: z.object({ + status: z.string() + }) + } + } + } + } +}) + +export function registerHealthCheck(app: OpenAPIHono) { + return app.openapi(route, async (c) => { + return c.json({ status: 'ok' }) + }) +} diff --git a/packages/fixtures/valid/everything-openapi/src/server.ts b/packages/fixtures/valid/everything-openapi/src/server.ts new file mode 100644 index 00000000..3eb9c4b5 --- /dev/null +++ b/packages/fixtures/valid/everything-openapi/src/server.ts @@ -0,0 +1,29 @@ +import { serve } from '@hono/node-server' +import { OpenAPIHono } from '@hono/zod-openapi' +import { logger as honoLogger } from 'hono/logger' + +import { initExitHooks } from './exit-hooks' +import { registerGetUser } from './routes/get-user' +import { registerHealthCheck } from './routes/health-check' + +export const app = new OpenAPIHono() + +app.use(honoLogger()) + +registerHealthCheck(app) +registerGetUser(app) + +app.doc31('/docs', { + openapi: '3.1.0', + info: { title: 'OpenAPI server to test everything', version: '0.1.0' } +}) + +const port = 3081 +export const server = serve({ + fetch: app.fetch, + port +}) + +initExitHooks({ server }) + +console.log(`Server running on port ${port}`) diff --git a/packages/fixtures/valid/everything-openapi/tsconfig.json b/packages/fixtures/valid/everything-openapi/tsconfig.json new file mode 100644 index 00000000..46b660fe --- /dev/null +++ b/packages/fixtures/valid/everything-openapi/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "@fisch0920/config/tsconfig-node", + "include": ["*.config.ts", "src"], + "exclude": ["node_modules"] +} diff --git a/packages/types/src/tools.ts b/packages/types/src/tools.ts index 7054767d..bb2db3f8 100644 --- a/packages/types/src/tools.ts +++ b/packages/types/src/tools.ts @@ -165,7 +165,7 @@ export const toolConfigSchema = z * } * } */ - pricingPlanConfig: z + pricingPlanConfigMap: z .record(pricingPlanSlugSchema, pricingPlanToolConfigSchema) .optional() .describe( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 32f02446..2e75bf49 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -606,6 +606,24 @@ importers: specifier: 'catalog:' version: 3.25.51 + packages/fixtures/valid/everything-openapi: + dependencies: + '@hono/node-server': + specifier: 'catalog:' + version: 1.14.3(hono@4.7.11) + '@hono/zod-openapi': + specifier: 'catalog:' + version: 0.19.8(hono@4.7.11)(zod@3.25.51) + hono: + specifier: 'catalog:' + version: 4.7.11 + restore-cursor: + specifier: 'catalog:' + version: 5.1.0 + zod: + specifier: 'catalog:' + version: 3.25.51 + packages/hono: dependencies: '@agentic/platform-core': diff --git a/readme.md b/readme.md index 7fde9e49..7a63289e 100644 --- a/readme.md +++ b/readme.md @@ -30,8 +30,10 @@ - auth - custom auth pages for `openauth` - API gateway - - **do I just ditch the public REST interface and focus on MCP?** - - enforce rate limits + - **enforce rate limits** + - oauth flow + - openapi-kitchen-sink + - mcp-kitchen-sink - how to handle binary bodies and responses? - add support for `immutable` in `toolConfigs` - **Public MCP server interface** @@ -41,8 +43,6 @@ - `_meta` for tool calls - _still need a way of doing this for initial connection requests_ - mcp auth provider support - - SSE support? (no; post-mvp if at all; only support [streamable http](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http) like smithery does, or maybe support both?) - - caching for MCP tool call responses - binary bodies / responses? - resources - prompts @@ -68,6 +68,8 @@ - same for pricing plan line-items - replace `ms` package - API gateway + - **do I just ditch the public REST interface and focus on MCP?** + - SSE support? (no; post-mvp if at all; only support [streamable http](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http) like smithery does, or maybe support both?) - signed requests - add support for custom headers on responses - `@agentic/platform-hono`