@proxygate/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -0
- package/README.md +311 -0
- package/dist/commands/apis.d.ts +3 -0
- package/dist/commands/apis.d.ts.map +1 -0
- package/dist/commands/apis.js +68 -0
- package/dist/commands/apis.js.map +1 -0
- package/dist/commands/apis.test.d.ts +2 -0
- package/dist/commands/apis.test.d.ts.map +1 -0
- package/dist/commands/apis.test.js +103 -0
- package/dist/commands/apis.test.js.map +1 -0
- package/dist/commands/balance.d.ts +9 -0
- package/dist/commands/balance.d.ts.map +1 -0
- package/dist/commands/balance.js +50 -0
- package/dist/commands/balance.js.map +1 -0
- package/dist/commands/balance.test.d.ts +2 -0
- package/dist/commands/balance.test.d.ts.map +1 -0
- package/dist/commands/balance.test.js +106 -0
- package/dist/commands/balance.test.js.map +1 -0
- package/dist/commands/categories.d.ts +3 -0
- package/dist/commands/categories.d.ts.map +1 -0
- package/dist/commands/categories.js +45 -0
- package/dist/commands/categories.js.map +1 -0
- package/dist/commands/categories.test.d.ts +2 -0
- package/dist/commands/categories.test.d.ts.map +1 -0
- package/dist/commands/categories.test.js +84 -0
- package/dist/commands/categories.test.js.map +1 -0
- package/dist/commands/create.d.ts +3 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +136 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/create.test.d.ts +2 -0
- package/dist/commands/create.test.d.ts.map +1 -0
- package/dist/commands/create.test.js +95 -0
- package/dist/commands/create.test.js.map +1 -0
- package/dist/commands/deposit.d.ts +9 -0
- package/dist/commands/deposit.d.ts.map +1 -0
- package/dist/commands/deposit.js +78 -0
- package/dist/commands/deposit.js.map +1 -0
- package/dist/commands/deposit.test.d.ts +2 -0
- package/dist/commands/deposit.test.d.ts.map +1 -0
- package/dist/commands/deposit.test.js +93 -0
- package/dist/commands/deposit.test.js.map +1 -0
- package/dist/commands/dev.d.ts +3 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +188 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/dev.test.d.ts +2 -0
- package/dist/commands/dev.test.d.ts.map +1 -0
- package/dist/commands/dev.test.js +89 -0
- package/dist/commands/dev.test.js.map +1 -0
- package/dist/commands/getting-started-steps.d.ts +12 -0
- package/dist/commands/getting-started-steps.d.ts.map +1 -0
- package/dist/commands/getting-started-steps.js +163 -0
- package/dist/commands/getting-started-steps.js.map +1 -0
- package/dist/commands/getting-started.d.ts +9 -0
- package/dist/commands/getting-started.d.ts.map +1 -0
- package/dist/commands/getting-started.js +44 -0
- package/dist/commands/getting-started.js.map +1 -0
- package/dist/commands/init.d.ts +9 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +74 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/init.test.d.ts +2 -0
- package/dist/commands/init.test.d.ts.map +1 -0
- package/dist/commands/init.test.js +115 -0
- package/dist/commands/init.test.js.map +1 -0
- package/dist/commands/jobs.d.ts +11 -0
- package/dist/commands/jobs.d.ts.map +1 -0
- package/dist/commands/jobs.js +370 -0
- package/dist/commands/jobs.js.map +1 -0
- package/dist/commands/listings/create.d.ts +4 -0
- package/dist/commands/listings/create.d.ts.map +1 -0
- package/dist/commands/listings/create.js +133 -0
- package/dist/commands/listings/create.js.map +1 -0
- package/dist/commands/listings/delete.d.ts +4 -0
- package/dist/commands/listings/delete.d.ts.map +1 -0
- package/dist/commands/listings/delete.js +32 -0
- package/dist/commands/listings/delete.js.map +1 -0
- package/dist/commands/listings/docs.d.ts +4 -0
- package/dist/commands/listings/docs.d.ts.map +1 -0
- package/dist/commands/listings/docs.js +48 -0
- package/dist/commands/listings/docs.js.map +1 -0
- package/dist/commands/listings/headers.d.ts +4 -0
- package/dist/commands/listings/headers.d.ts.map +1 -0
- package/dist/commands/listings/headers.js +78 -0
- package/dist/commands/listings/headers.js.map +1 -0
- package/dist/commands/listings/helpers.d.ts +10 -0
- package/dist/commands/listings/helpers.d.ts.map +1 -0
- package/dist/commands/listings/helpers.js +64 -0
- package/dist/commands/listings/helpers.js.map +1 -0
- package/dist/commands/listings/index.d.ts +11 -0
- package/dist/commands/listings/index.d.ts.map +1 -0
- package/dist/commands/listings/index.js +46 -0
- package/dist/commands/listings/index.js.map +1 -0
- package/dist/commands/listings/list.d.ts +4 -0
- package/dist/commands/listings/list.d.ts.map +1 -0
- package/dist/commands/listings/list.js +42 -0
- package/dist/commands/listings/list.js.map +1 -0
- package/dist/commands/listings/pause-unpause.d.ts +6 -0
- package/dist/commands/listings/pause-unpause.d.ts.map +1 -0
- package/dist/commands/listings/pause-unpause.js +37 -0
- package/dist/commands/listings/pause-unpause.js.map +1 -0
- package/dist/commands/listings/rotate-key.d.ts +4 -0
- package/dist/commands/listings/rotate-key.d.ts.map +1 -0
- package/dist/commands/listings/rotate-key.js +62 -0
- package/dist/commands/listings/rotate-key.js.map +1 -0
- package/dist/commands/listings/update.d.ts +4 -0
- package/dist/commands/listings/update.d.ts.map +1 -0
- package/dist/commands/listings/update.js +57 -0
- package/dist/commands/listings/update.js.map +1 -0
- package/dist/commands/listings.d.ts +2 -0
- package/dist/commands/listings.d.ts.map +1 -0
- package/dist/commands/listings.js +3 -0
- package/dist/commands/listings.js.map +1 -0
- package/dist/commands/listings.test.d.ts +2 -0
- package/dist/commands/listings.test.d.ts.map +1 -0
- package/dist/commands/listings.test.js +166 -0
- package/dist/commands/listings.test.js.map +1 -0
- package/dist/commands/pricing.d.ts +9 -0
- package/dist/commands/pricing.d.ts.map +1 -0
- package/dist/commands/pricing.js +67 -0
- package/dist/commands/pricing.js.map +1 -0
- package/dist/commands/pricing.test.d.ts +2 -0
- package/dist/commands/pricing.test.d.ts.map +1 -0
- package/dist/commands/pricing.test.js +87 -0
- package/dist/commands/pricing.test.js.map +1 -0
- package/dist/commands/proxy.d.ts +14 -0
- package/dist/commands/proxy.d.ts.map +1 -0
- package/dist/commands/proxy.js +138 -0
- package/dist/commands/proxy.js.map +1 -0
- package/dist/commands/proxy.test.d.ts +2 -0
- package/dist/commands/proxy.test.d.ts.map +1 -0
- package/dist/commands/proxy.test.js +235 -0
- package/dist/commands/proxy.test.js.map +1 -0
- package/dist/commands/rate.d.ts +3 -0
- package/dist/commands/rate.d.ts.map +1 -0
- package/dist/commands/rate.js +46 -0
- package/dist/commands/rate.js.map +1 -0
- package/dist/commands/rate.test.d.ts +2 -0
- package/dist/commands/rate.test.d.ts.map +1 -0
- package/dist/commands/rate.test.js +74 -0
- package/dist/commands/rate.test.js.map +1 -0
- package/dist/commands/services.d.ts +3 -0
- package/dist/commands/services.d.ts.map +1 -0
- package/dist/commands/services.js +48 -0
- package/dist/commands/services.js.map +1 -0
- package/dist/commands/services.test.d.ts +2 -0
- package/dist/commands/services.test.d.ts.map +1 -0
- package/dist/commands/services.test.js +87 -0
- package/dist/commands/services.test.js.map +1 -0
- package/dist/commands/settlements.d.ts +3 -0
- package/dist/commands/settlements.d.ts.map +1 -0
- package/dist/commands/settlements.js +79 -0
- package/dist/commands/settlements.js.map +1 -0
- package/dist/commands/settlements.test.d.ts +2 -0
- package/dist/commands/settlements.test.d.ts.map +1 -0
- package/dist/commands/settlements.test.js +98 -0
- package/dist/commands/settlements.test.js.map +1 -0
- package/dist/commands/skills.d.ts +3 -0
- package/dist/commands/skills.d.ts.map +1 -0
- package/dist/commands/skills.js +96 -0
- package/dist/commands/skills.js.map +1 -0
- package/dist/commands/skills.test.d.ts +2 -0
- package/dist/commands/skills.test.d.ts.map +1 -0
- package/dist/commands/skills.test.js +89 -0
- package/dist/commands/skills.test.js.map +1 -0
- package/dist/commands/test-service.d.ts +3 -0
- package/dist/commands/test-service.d.ts.map +1 -0
- package/dist/commands/test-service.js +200 -0
- package/dist/commands/test-service.js.map +1 -0
- package/dist/commands/test-service.test.d.ts +2 -0
- package/dist/commands/test-service.test.d.ts.map +1 -0
- package/dist/commands/test-service.test.js +119 -0
- package/dist/commands/test-service.test.js.map +1 -0
- package/dist/commands/tunnel-handlers.d.ts +19 -0
- package/dist/commands/tunnel-handlers.d.ts.map +1 -0
- package/dist/commands/tunnel-handlers.js +103 -0
- package/dist/commands/tunnel-handlers.js.map +1 -0
- package/dist/commands/tunnel.d.ts +7 -0
- package/dist/commands/tunnel.d.ts.map +1 -0
- package/dist/commands/tunnel.js +184 -0
- package/dist/commands/tunnel.js.map +1 -0
- package/dist/commands/usage.d.ts +9 -0
- package/dist/commands/usage.d.ts.map +1 -0
- package/dist/commands/usage.js +78 -0
- package/dist/commands/usage.js.map +1 -0
- package/dist/commands/usage.test.d.ts +2 -0
- package/dist/commands/usage.test.d.ts.map +1 -0
- package/dist/commands/usage.test.js +102 -0
- package/dist/commands/usage.test.js.map +1 -0
- package/dist/commands/withdraw-confirm.d.ts +10 -0
- package/dist/commands/withdraw-confirm.d.ts.map +1 -0
- package/dist/commands/withdraw-confirm.js +51 -0
- package/dist/commands/withdraw-confirm.js.map +1 -0
- package/dist/commands/withdraw-confirm.test.d.ts +2 -0
- package/dist/commands/withdraw-confirm.test.d.ts.map +1 -0
- package/dist/commands/withdraw-confirm.test.js +75 -0
- package/dist/commands/withdraw-confirm.test.js.map +1 -0
- package/dist/commands/withdraw.d.ts +9 -0
- package/dist/commands/withdraw.d.ts.map +1 -0
- package/dist/commands/withdraw.js +78 -0
- package/dist/commands/withdraw.js.map +1 -0
- package/dist/commands/withdraw.test.d.ts +2 -0
- package/dist/commands/withdraw.test.d.ts.map +1 -0
- package/dist/commands/withdraw.test.js +96 -0
- package/dist/commands/withdraw.test.js.map +1 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +38 -0
- package/dist/config.js.map +1 -0
- package/dist/config.test.d.ts +2 -0
- package/dist/config.test.d.ts.map +1 -0
- package/dist/config.test.js +54 -0
- package/dist/config.test.js.map +1 -0
- package/dist/format.d.ts +46 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +101 -0
- package/dist/format.js.map +1 -0
- package/dist/format.test.d.ts +2 -0
- package/dist/format.test.d.ts.map +1 -0
- package/dist/format.test.js +85 -0
- package/dist/format.test.js.map +1 -0
- package/dist/generated/skills.d.ts +2 -0
- package/dist/generated/skills.d.ts.map +1 -0
- package/dist/generated/skills.js +23 -0
- package/dist/generated/skills.js.map +1 -0
- package/dist/helpers.d.ts +12 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +21 -0
- package/dist/helpers.js.map +1 -0
- package/dist/helpers.test.d.ts +2 -0
- package/dist/helpers.test.d.ts.map +1 -0
- package/dist/helpers.test.js +59 -0
- package/dist/helpers.test.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
- package/templates/http-api/README.md +20 -0
- package/templates/http-api/package.json +21 -0
- package/templates/http-api/proxygate.tunnel.yaml +9 -0
- package/templates/http-api/src/index.ts +77 -0
- package/templates/http-api/tsconfig.json +14 -0
- package/templates/llm-agent/README.md +23 -0
- package/templates/llm-agent/package.json +22 -0
- package/templates/llm-agent/proxygate.tunnel.yaml +13 -0
- package/templates/llm-agent/src/index.ts +142 -0
- package/templates/llm-agent/tsconfig.json +14 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# {{name}}
|
|
2
|
+
|
|
3
|
+
A ProxyGate agent service built with [Hono](https://hono.dev).
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install
|
|
9
|
+
npm run dev # Start dev server with hot reload
|
|
10
|
+
proxygate test # Validate endpoints locally
|
|
11
|
+
proxygate tunnel # Go live on ProxyGate
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Endpoints
|
|
15
|
+
|
|
16
|
+
- `POST /v1/analyze` — Analyze input data
|
|
17
|
+
|
|
18
|
+
## Configuration
|
|
19
|
+
|
|
20
|
+
Edit `proxygate.tunnel.yaml` to change pricing, paths, and service settings.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{name}}",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "tsx --watch src/index.ts",
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"start": "node dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@hono/node-server": "^1.14.0",
|
|
13
|
+
"@hono/zod-openapi": "^0.19.0",
|
|
14
|
+
"hono": "^4.7.0",
|
|
15
|
+
"zod": "^3.24.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"tsx": "^4.0.0",
|
|
19
|
+
"typescript": "^5.7.0"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { OpenAPIHono, createRoute, z } from '@hono/zod-openapi';
|
|
2
|
+
import { serve } from '@hono/node-server';
|
|
3
|
+
|
|
4
|
+
const app = new OpenAPIHono();
|
|
5
|
+
|
|
6
|
+
// --- Schemas ---
|
|
7
|
+
|
|
8
|
+
const AnalyzeBody = z
|
|
9
|
+
.object({
|
|
10
|
+
input: z.unknown().openapi({ description: 'Data to analyze' }),
|
|
11
|
+
})
|
|
12
|
+
.openapi('AnalyzeRequest');
|
|
13
|
+
|
|
14
|
+
const AnalyzeResponse = z
|
|
15
|
+
.object({
|
|
16
|
+
input: z.unknown(),
|
|
17
|
+
analysis: z.string(),
|
|
18
|
+
timestamp: z.string().datetime(),
|
|
19
|
+
})
|
|
20
|
+
.openapi('AnalyzeResponse');
|
|
21
|
+
|
|
22
|
+
// --- Routes ---
|
|
23
|
+
|
|
24
|
+
const healthRoute = createRoute({
|
|
25
|
+
method: 'get',
|
|
26
|
+
path: '/',
|
|
27
|
+
responses: {
|
|
28
|
+
200: {
|
|
29
|
+
content: { 'application/json': { schema: z.object({ status: z.string(), service: z.string() }) } },
|
|
30
|
+
description: 'Health check',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
app.openapi(healthRoute, (c) =>
|
|
36
|
+
c.json({ status: 'ok', service: '{{name}}' }),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const analyzeRoute = createRoute({
|
|
40
|
+
method: 'post',
|
|
41
|
+
path: '/v1/analyze',
|
|
42
|
+
request: {
|
|
43
|
+
body: { content: { 'application/json': { schema: AnalyzeBody } }, required: true },
|
|
44
|
+
},
|
|
45
|
+
responses: {
|
|
46
|
+
200: {
|
|
47
|
+
content: { 'application/json': { schema: AnalyzeResponse } },
|
|
48
|
+
description: 'Analysis result',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
app.openapi(analyzeRoute, async (c) => {
|
|
54
|
+
const body = c.req.valid('json');
|
|
55
|
+
|
|
56
|
+
const result = {
|
|
57
|
+
input: body.input,
|
|
58
|
+
analysis: 'This is a placeholder response from {{name}}.',
|
|
59
|
+
timestamp: new Date().toISOString(),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return c.json(result);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// --- OpenAPI spec ---
|
|
66
|
+
|
|
67
|
+
app.doc('/openapi.json', {
|
|
68
|
+
openapi: '3.1.0',
|
|
69
|
+
info: { title: '{{name}}', version: '0.1.0', description: '{{name}} API service' },
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// --- Server ---
|
|
73
|
+
|
|
74
|
+
const port = {{port}};
|
|
75
|
+
console.log(`{{name}} listening on http://localhost:${port}`);
|
|
76
|
+
console.log(`OpenAPI spec: http://localhost:${port}/openapi.json`);
|
|
77
|
+
serve({ fetch: app.fetch, port });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"rootDir": "src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"declaration": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# {{name}}
|
|
2
|
+
|
|
3
|
+
An LLM-powered ProxyGate agent built with [Hono](https://hono.dev) and [OpenAI](https://platform.openai.com).
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install
|
|
9
|
+
export OPENAI_API_KEY=sk-... # Your OpenAI key
|
|
10
|
+
npm run dev # Start dev server
|
|
11
|
+
proxygate test # Validate endpoints
|
|
12
|
+
proxygate tunnel # Go live on ProxyGate
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Endpoints
|
|
16
|
+
|
|
17
|
+
- `POST /v1/review` — Stream a code review (SSE)
|
|
18
|
+
- `POST /v1/summarize` — Summarize text
|
|
19
|
+
|
|
20
|
+
## Configuration
|
|
21
|
+
|
|
22
|
+
Edit `proxygate.tunnel.yaml` to change pricing and service settings.
|
|
23
|
+
Edit `openapi.yaml` to update endpoint documentation shown to buyers.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{name}}",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "tsx --watch src/index.ts",
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"start": "node dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@hono/node-server": "^1.14.0",
|
|
13
|
+
"@hono/zod-openapi": "^0.19.0",
|
|
14
|
+
"hono": "^4.7.0",
|
|
15
|
+
"zod": "^3.24.0",
|
|
16
|
+
"openai": "^4.80.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"tsx": "^4.0.0",
|
|
20
|
+
"typescript": "^5.7.0"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
services:
|
|
2
|
+
- name: {{name}}
|
|
3
|
+
port: {{port}}
|
|
4
|
+
price_per_request: {{price}}
|
|
5
|
+
description: "{{name}} — LLM-powered agent"
|
|
6
|
+
docs: ./openapi.yaml
|
|
7
|
+
endpoints:
|
|
8
|
+
- method: POST
|
|
9
|
+
path: /v1/review
|
|
10
|
+
description: Stream a code review for the given snippet
|
|
11
|
+
- method: POST
|
|
12
|
+
path: /v1/summarize
|
|
13
|
+
description: Summarize text to a given length
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { OpenAPIHono, createRoute, z } from '@hono/zod-openapi';
|
|
2
|
+
import { streamSSE } from 'hono/streaming';
|
|
3
|
+
import { serve } from '@hono/node-server';
|
|
4
|
+
import OpenAI from 'openai';
|
|
5
|
+
|
|
6
|
+
const app = new OpenAPIHono();
|
|
7
|
+
|
|
8
|
+
// Lazy-init so the server starts even without OPENAI_API_KEY set
|
|
9
|
+
let _openai: OpenAI | null = null;
|
|
10
|
+
function openai(): OpenAI {
|
|
11
|
+
if (!_openai) _openai = new OpenAI();
|
|
12
|
+
return _openai;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// --- Schemas ---
|
|
16
|
+
|
|
17
|
+
const ReviewBody = z
|
|
18
|
+
.object({
|
|
19
|
+
code: z.string().openapi({ description: 'Source code to review' }),
|
|
20
|
+
language: z.string().optional().openapi({ description: 'Programming language' }),
|
|
21
|
+
})
|
|
22
|
+
.openapi('ReviewRequest');
|
|
23
|
+
|
|
24
|
+
const SummarizeBody = z
|
|
25
|
+
.object({
|
|
26
|
+
text: z.string().openapi({ description: 'Text to summarize' }),
|
|
27
|
+
max_length: z.number().int().optional().openapi({ description: 'Max words (default 100)' }),
|
|
28
|
+
})
|
|
29
|
+
.openapi('SummarizeRequest');
|
|
30
|
+
|
|
31
|
+
const SummarizeResponse = z
|
|
32
|
+
.object({
|
|
33
|
+
summary: z.string(),
|
|
34
|
+
model: z.string(),
|
|
35
|
+
usage: z.unknown().optional(),
|
|
36
|
+
})
|
|
37
|
+
.openapi('SummarizeResponse');
|
|
38
|
+
|
|
39
|
+
// --- Routes ---
|
|
40
|
+
|
|
41
|
+
const healthRoute = createRoute({
|
|
42
|
+
method: 'get',
|
|
43
|
+
path: '/',
|
|
44
|
+
responses: {
|
|
45
|
+
200: {
|
|
46
|
+
content: { 'application/json': { schema: z.object({ status: z.string(), service: z.string() }) } },
|
|
47
|
+
description: 'Health check',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
app.openapi(healthRoute, (c) =>
|
|
53
|
+
c.json({ status: 'ok', service: '{{name}}' }),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const reviewRoute = createRoute({
|
|
57
|
+
method: 'post',
|
|
58
|
+
path: '/v1/review',
|
|
59
|
+
request: {
|
|
60
|
+
body: { content: { 'application/json': { schema: ReviewBody } }, required: true },
|
|
61
|
+
},
|
|
62
|
+
responses: {
|
|
63
|
+
200: { description: 'SSE stream of review chunks', content: { 'text/event-stream': { schema: z.any() } } },
|
|
64
|
+
400: { description: 'Missing code field' },
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
app.openapi(reviewRoute, async (c) => {
|
|
69
|
+
const { code, language } = c.req.valid('json');
|
|
70
|
+
|
|
71
|
+
const stream = await openai().chat.completions.create({
|
|
72
|
+
model: 'gpt-4o-mini',
|
|
73
|
+
stream: true,
|
|
74
|
+
messages: [
|
|
75
|
+
{
|
|
76
|
+
role: 'system',
|
|
77
|
+
content: `You are a code reviewer. Review the following ${language ?? ''} code for bugs, style issues, and improvements. Be concise.`,
|
|
78
|
+
},
|
|
79
|
+
{ role: 'user', content: code },
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return streamSSE(c, async (sseStream) => {
|
|
84
|
+
for await (const chunk of stream) {
|
|
85
|
+
const content = chunk.choices[0]?.delta?.content;
|
|
86
|
+
if (content) {
|
|
87
|
+
await sseStream.writeSSE({ data: JSON.stringify({ content }) });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
await sseStream.writeSSE({ data: '[DONE]' });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const summarizeRoute = createRoute({
|
|
95
|
+
method: 'post',
|
|
96
|
+
path: '/v1/summarize',
|
|
97
|
+
request: {
|
|
98
|
+
body: { content: { 'application/json': { schema: SummarizeBody } }, required: true },
|
|
99
|
+
},
|
|
100
|
+
responses: {
|
|
101
|
+
200: {
|
|
102
|
+
content: { 'application/json': { schema: SummarizeResponse } },
|
|
103
|
+
description: 'Summary response',
|
|
104
|
+
},
|
|
105
|
+
400: { description: 'Missing text field' },
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
app.openapi(summarizeRoute, async (c) => {
|
|
110
|
+
const { text, max_length } = c.req.valid('json');
|
|
111
|
+
|
|
112
|
+
const response = await openai().chat.completions.create({
|
|
113
|
+
model: 'gpt-4o-mini',
|
|
114
|
+
messages: [
|
|
115
|
+
{
|
|
116
|
+
role: 'system',
|
|
117
|
+
content: `Summarize the following text in ${max_length ?? 100} words or fewer.`,
|
|
118
|
+
},
|
|
119
|
+
{ role: 'user', content: text },
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return c.json({
|
|
124
|
+
summary: response.choices[0]?.message?.content ?? '',
|
|
125
|
+
model: response.model,
|
|
126
|
+
usage: response.usage,
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// --- OpenAPI spec ---
|
|
131
|
+
|
|
132
|
+
app.doc('/openapi.json', {
|
|
133
|
+
openapi: '3.1.0',
|
|
134
|
+
info: { title: '{{name}}', version: '0.1.0', description: '{{name}} — LLM-powered agent' },
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// --- Server ---
|
|
138
|
+
|
|
139
|
+
const port = {{port}};
|
|
140
|
+
console.log(`{{name}} listening on http://localhost:${port}`);
|
|
141
|
+
console.log(`OpenAPI spec: http://localhost:${port}/openapi.json`);
|
|
142
|
+
serve({ fetch: app.fetch, port });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"rootDir": "src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"declaration": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|