@vertesia/create-plugin 0.79.3 → 0.79.4
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/README.md +68 -63
- package/lib/Package.d.ts +2 -2
- package/lib/Package.d.ts.map +1 -1
- package/lib/TemplateInit.d.ts +2 -1
- package/lib/TemplateInit.d.ts.map +1 -1
- package/lib/TemplateInit.js.map +1 -1
- package/lib/ToolTemplateInit.d.ts.map +1 -1
- package/lib/ToolTemplateInit.js +17 -4
- package/lib/ToolTemplateInit.js.map +1 -1
- package/lib/WebTemplateInit.d.ts.map +1 -1
- package/lib/WebTemplateInit.js +0 -9
- package/lib/WebTemplateInit.js.map +1 -1
- package/lib/copy.d.ts +1 -1
- package/lib/copy.d.ts.map +1 -1
- package/lib/copy.js +6 -2
- package/lib/copy.js.map +1 -1
- package/lib/init.d.ts.map +1 -1
- package/lib/init.js +73 -56
- package/lib/init.js.map +1 -1
- package/lib/types.d.ts +12 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +20 -0
- package/lib/types.js.map +1 -0
- package/package.json +15 -3
- package/templates/tool/.env.example +6 -0
- package/templates/tool/.vscode/launch.json +1 -1
- package/templates/tool/README.md +179 -20
- package/templates/tool/gitignore +26 -0
- package/templates/tool/rollup.config.js +30 -0
- package/templates/tool/src/collections/example/icon.svg.ts +6 -0
- package/templates/tool/src/collections/example/index.ts +14 -0
- package/templates/tool/src/collections/example/weather/WeatherTool.ts +32 -0
- package/templates/tool/src/collections/example/weather/manifest.ts +16 -0
- package/templates/tool/src/collections/index.ts +7 -0
- package/templates/tool/src/index.ts +4 -5
- package/templates/tool/src/server.ts +70 -16
- package/templates/tool/tsconfig.json +14 -4
- package/templates/tool/vercel.json +6 -5
- package/templates/tool/vite.config.js +46 -8
- package/templates/web/README.md +153 -51
- package/templates/web/eslint.config.js +2 -1
- package/templates/web/gitignore +25 -0
- package/templates/web/index.html.tmpl +4 -4
- package/templates/web/src/env.ts.tmpl +5 -11
- package/templates/web/vite.config.ts.tmpl +6 -4
- package/templates/tool/src/tools/WeatherTool.ts +0 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vertesia/create-plugin",
|
|
3
|
-
"version": "0.79.
|
|
3
|
+
"version": "0.79.4",
|
|
4
4
|
"description": "Initialize a Vertesia plugin package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -27,11 +27,23 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/hasbin": "^1.2.2",
|
|
29
29
|
"@types/node": "^22.5.0",
|
|
30
|
-
"typescript": "^5.7.2"
|
|
30
|
+
"typescript": "^5.7.2",
|
|
31
|
+
"hono": "^4.10.3",
|
|
32
|
+
"@hono/node-server": "^1.19.5",
|
|
33
|
+
"@llumiverse/common": "0.22.3",
|
|
34
|
+
"@vertesia/common": "0.79.4",
|
|
35
|
+
"@vertesia/tools-sdk": "0.79.4",
|
|
36
|
+
"@vertesia/client": "0.79.4"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/vertesia/composableai.git",
|
|
41
|
+
"directory": "packages/create-plugin"
|
|
31
42
|
},
|
|
32
43
|
"scripts": {
|
|
33
44
|
"eslint": "eslint './src/**/*.{jsx,js,tsx,ts}'",
|
|
34
|
-
"build": "rm -rf ./lib ./tsconfig.tsbuildinfo && tsc --build",
|
|
45
|
+
"build": "rm -rf ./lib ./tsconfig.tsbuildinfo && pnpm run typecheck:templates && tsc --build",
|
|
46
|
+
"typecheck:templates": "tsc --noEmit --project templates/tool/tsconfig.json",
|
|
35
47
|
"clean": "rimraf ./node_modules ./lib ./tsconfig.tsbuildinfo"
|
|
36
48
|
}
|
|
37
49
|
}
|
package/templates/tool/README.md
CHANGED
|
@@ -1,31 +1,190 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Tool Collections
|
|
2
2
|
|
|
3
|
-
This
|
|
4
|
-
1. `GET /` - show tool descriptions
|
|
5
|
-
2. `POST /` - execute a tool given an execution payload.
|
|
3
|
+
This project contains custom tool collections for Vertesia.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
## Project Structure
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
```txt
|
|
8
|
+
src/
|
|
9
|
+
├── collections/ # Tool collections
|
|
10
|
+
│ ├── example/ # Example collection
|
|
11
|
+
│ │ ├── icon.svg.ts # Collection icon
|
|
12
|
+
│ │ ├── index.ts # Collection definition
|
|
13
|
+
│ │ └── weather/ # Weather tool
|
|
14
|
+
│ │ ├── manifest.ts # Tool schema/metadata
|
|
15
|
+
│ │ └── WeatherTool.ts # Tool implementation
|
|
16
|
+
│ └── index.ts # Export all collections
|
|
17
|
+
├── server.ts # Hono server with collection endpoints
|
|
18
|
+
└── index.ts # Main exports
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Development
|
|
22
|
+
|
|
23
|
+
Start the development server:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm install
|
|
27
|
+
pnpm dev
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The server will be available at `http://localhost:5174/api`
|
|
31
|
+
|
|
32
|
+
### API Endpoints
|
|
11
33
|
|
|
12
|
-
|
|
34
|
+
- `GET /api` - List all collections
|
|
35
|
+
- `GET /api/{collection}` - Get collection metadata and tool definitions
|
|
36
|
+
- `POST /api/{collection}` - Execute a tool in the collection
|
|
13
37
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
38
|
+
### Testing the API
|
|
39
|
+
|
|
40
|
+
Get the example collection tools:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
curl http://localhost:5174/api/example
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Execute the weather tool:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
curl -X POST http://localhost:5174/api/example \
|
|
50
|
+
-H "Content-Type: application/json" \
|
|
51
|
+
-H "Authorization: Bearer YOUR_TOKEN" \
|
|
52
|
+
-d '{
|
|
53
|
+
"tool_use": {
|
|
54
|
+
"id": "test-123",
|
|
55
|
+
"tool_name": "weather",
|
|
56
|
+
"tool_input": {
|
|
57
|
+
"location": "New York, NY"
|
|
20
58
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
59
|
+
}
|
|
60
|
+
}'
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Creating New Tools
|
|
64
|
+
|
|
65
|
+
### 1. Create a new tool in an existing collection
|
|
66
|
+
|
|
67
|
+
1. Create a new directory under `src/collections/example/` (e.g., `my-tool/`)
|
|
68
|
+
2. Create `manifest.ts` with your tool's schema
|
|
69
|
+
3. Create `MyTool.ts` with the implementation
|
|
70
|
+
4. Add the tool to `src/collections/example/index.ts`
|
|
71
|
+
|
|
72
|
+
### 2. Create a new collection
|
|
73
|
+
|
|
74
|
+
1. Create a new directory under `src/collections/` (e.g., `my-collection/`)
|
|
75
|
+
2. Create `icon.svg.ts` with an SVG icon
|
|
76
|
+
3. Create `index.ts` to define the collection
|
|
77
|
+
4. Add your tools in subdirectories
|
|
78
|
+
5. Export the collection in `src/collections/index.ts`
|
|
79
|
+
|
|
80
|
+
## Authentication
|
|
81
|
+
|
|
82
|
+
Tools receive authentication context through the `ToolExecutionContext` parameter:
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
export async function myTool(
|
|
86
|
+
payload: ToolExecutionPayload<MyToolParams>,
|
|
87
|
+
context: ToolExecutionContext
|
|
88
|
+
) {
|
|
89
|
+
// Access the decoded JWT token
|
|
90
|
+
const userId = context.payload.sub;
|
|
91
|
+
|
|
92
|
+
// Get a Vertesia client instance
|
|
93
|
+
const client = await context.getClient();
|
|
94
|
+
|
|
95
|
+
// Your tool logic here
|
|
96
|
+
return {
|
|
97
|
+
is_error: false,
|
|
98
|
+
content: "Tool result"
|
|
99
|
+
};
|
|
24
100
|
}
|
|
25
101
|
```
|
|
26
102
|
|
|
27
|
-
|
|
103
|
+
## Building for Production
|
|
104
|
+
|
|
105
|
+
Build the project:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pnpm build
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
This creates an optimized build in the `dist/` directory.
|
|
112
|
+
|
|
113
|
+
## Deployment
|
|
114
|
+
|
|
115
|
+
Your Agent Tool Server can be deployed to various platforms. The server is built with Hono, which supports multiple runtimes including Node.js, Vercel Edge Functions, Cloudflare Workers, AWS Lambda, and more.
|
|
116
|
+
|
|
117
|
+
For detailed guides on deploying to different platforms, visit the [Hono documentation](https://hono.dev/docs/). The documentation provides comprehensive examples for various deployment targets and runtimes.
|
|
118
|
+
|
|
119
|
+
### Deploying to Vercel (Example)
|
|
120
|
+
|
|
121
|
+
This section demonstrates deploying to Vercel as an example, since Vercel offers a generous free tier and simple deployment process. The project includes `api/index.ts` which serves as the entry point for Vercel deployment using the Hono Vercel adapter. Vercel automatically detects and configures the Edge Function.
|
|
122
|
+
|
|
123
|
+
#### Setup
|
|
124
|
+
|
|
125
|
+
Install the Vercel CLI globally:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npm i -g vercel
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### Deployment Steps
|
|
132
|
+
|
|
133
|
+
1. **Login to Vercel**:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
vercel login
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
2. **Deploy to preview**:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
vercel
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
This will create a preview deployment and provide you with a URL to test your tool server.
|
|
146
|
+
|
|
147
|
+
3. **Deploy to production**:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
vercel --prod
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Your tool server will be available at `https://your-project.vercel.app/api`
|
|
154
|
+
|
|
155
|
+
For more information, visit the [Vercel CLI documentation](https://vercel.com/docs/cli).
|
|
156
|
+
|
|
157
|
+
#### Verify Your Deployment
|
|
158
|
+
|
|
159
|
+
Test that your server is responding correctly:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
curl https://your-project.vercel.app/api
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
You should see a JSON response with the API information and available endpoints.
|
|
166
|
+
|
|
167
|
+
#### Configure Your Tool Server in Vertesia
|
|
168
|
+
|
|
169
|
+
After deploying to Vercel, update your app manifest to point to the deployed URL using the vertesia CLI:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
vertesia apps update <appId> --manifest '{
|
|
173
|
+
"name": "my-app",
|
|
174
|
+
"title": "My App",
|
|
175
|
+
"description": "A sample app",
|
|
176
|
+
"publisher": "your-org",
|
|
177
|
+
"private": true,
|
|
178
|
+
"status": "beta",
|
|
179
|
+
"tool_collections": [
|
|
180
|
+
"https://your-app.vercel.app/api/example"
|
|
181
|
+
],
|
|
182
|
+
}'
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Replace `appId` by the actual ID and `https://your-app.vercel.app` with your actual Vercel deployment URL.
|
|
28
186
|
|
|
29
|
-
|
|
187
|
+
## Learn More
|
|
30
188
|
|
|
31
|
-
|
|
189
|
+
- [Vertesia Documentation](https://docs.vertesiahq.com)
|
|
190
|
+
- [Tool SDK Reference](https://github.com/vertesia/composableai/tree/main/packages/tools-sdk)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
2
|
+
import json from '@rollup/plugin-json';
|
|
3
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
input: './dist/server.js',
|
|
7
|
+
output: {
|
|
8
|
+
file: './dist/bundle.js',
|
|
9
|
+
format: 'es',
|
|
10
|
+
sourcemap: false
|
|
11
|
+
},
|
|
12
|
+
plugins: [
|
|
13
|
+
resolve({
|
|
14
|
+
preferBuiltins: true,
|
|
15
|
+
exportConditions: ['node']
|
|
16
|
+
}),
|
|
17
|
+
commonjs(),
|
|
18
|
+
json()
|
|
19
|
+
],
|
|
20
|
+
external: [
|
|
21
|
+
// Keep these as external dependencies
|
|
22
|
+
'hono',
|
|
23
|
+
'jose',
|
|
24
|
+
'dotenv',
|
|
25
|
+
'@vertesia/client',
|
|
26
|
+
'@vertesia/common',
|
|
27
|
+
'@vertesia/tools-sdk',
|
|
28
|
+
'@hono/node-server'
|
|
29
|
+
]
|
|
30
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Simple SVG icon for the collection
|
|
2
|
+
// You can replace this with your own icon
|
|
3
|
+
export const icon = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
4
|
+
<circle cx="12" cy="12" r="10"/>
|
|
5
|
+
<path d="M12 6v6l4 2"/>
|
|
6
|
+
</svg>`;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ToolCollection } from "@vertesia/tools-sdk";
|
|
2
|
+
import { icon } from "./icon.svg.js";
|
|
3
|
+
import { WeatherTool } from "./weather/WeatherTool.js";
|
|
4
|
+
|
|
5
|
+
export const ExampleCollection = new ToolCollection({
|
|
6
|
+
name: "example",
|
|
7
|
+
title: "Example Tools",
|
|
8
|
+
description: "A collection of example tools to get you started",
|
|
9
|
+
icon,
|
|
10
|
+
tools: [
|
|
11
|
+
WeatherTool
|
|
12
|
+
// Add more tools here
|
|
13
|
+
]
|
|
14
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Tool, ToolExecutionPayload, ToolExecutionContext } from "@vertesia/tools-sdk";
|
|
2
|
+
import manifest from "./manifest.js";
|
|
3
|
+
import { ToolResultContent } from "@vertesia/common";
|
|
4
|
+
|
|
5
|
+
interface WeatherToolParams {
|
|
6
|
+
location: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Tool implementation function
|
|
10
|
+
export async function weather(
|
|
11
|
+
payload: ToolExecutionPayload<WeatherToolParams>,
|
|
12
|
+
context: ToolExecutionContext
|
|
13
|
+
) {
|
|
14
|
+
const { location } = payload.tool_use.tool_input!;
|
|
15
|
+
|
|
16
|
+
console.log(`Caller: ${context.payload.user_id}`);
|
|
17
|
+
|
|
18
|
+
// Simulate fetching weather data
|
|
19
|
+
// In a real implementation, you would call a weather API here
|
|
20
|
+
// You can use context.getClient() to access Vertesia services if needed
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
is_error: false,
|
|
24
|
+
content: `The current weather in ${location} is sunny with a temperature of 75°F.`
|
|
25
|
+
} satisfies ToolResultContent;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Export the complete tool with manifest and implementation
|
|
29
|
+
export const WeatherTool = {
|
|
30
|
+
...manifest,
|
|
31
|
+
run: weather
|
|
32
|
+
} satisfies Tool<WeatherToolParams>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ToolDefinition } from "@vertesia/tools-sdk";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
name: "weather",
|
|
5
|
+
description: "Get the current weather for a given location.",
|
|
6
|
+
input_schema: {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {
|
|
9
|
+
location: {
|
|
10
|
+
type: "string",
|
|
11
|
+
description: "The location to get the weather for, e.g., 'New York, NY'."
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
required: ["location"]
|
|
15
|
+
},
|
|
16
|
+
} satisfies ToolDefinition;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// Export collections for use in other modules or for programmatic access
|
|
2
|
+
export { collections } from "./collections/index.js";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
]);
|
|
4
|
+
// Export server as default for deployment
|
|
5
|
+
export { default } from "./server.js";
|
|
@@ -1,19 +1,73 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { cors } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { ToolCollection, ToolCollectionDefinition } from "@vertesia/tools-sdk";
|
|
2
|
+
import { Context, Hono } from "hono";
|
|
3
|
+
import { cors } from "hono/cors";
|
|
4
|
+
import { collections } from "./collections/index.js";
|
|
5
|
+
import { HTTPException } from "hono/http-exception";
|
|
6
|
+
|
|
7
|
+
function createServer(collections: ToolCollection[], prefix = '/api') {
|
|
8
|
+
prefix = prefix.trim();
|
|
9
|
+
const app = new Hono();
|
|
10
|
+
|
|
11
|
+
// Add CORS middleware globally
|
|
12
|
+
app.use('*', cors({ origin: '*', allowMethods: ['GET', 'POST', 'OPTIONS'] }));
|
|
13
|
+
|
|
14
|
+
// Add base API route
|
|
15
|
+
app.get(prefix, (c) => {
|
|
16
|
+
return c.json({
|
|
17
|
+
message: 'Tool Collections API',
|
|
18
|
+
version: '1.0.0',
|
|
19
|
+
endpoints: {
|
|
20
|
+
collections: collections.map(col => `${prefix}/${col.name}`)
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Create endpoints for tool collections
|
|
26
|
+
for (const col of collections) {
|
|
27
|
+
app.route(`${prefix}/${col.name}`, createCollectionEndpoints(col));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Global error handler
|
|
31
|
+
app.onError((err, c) => {
|
|
32
|
+
if (err instanceof HTTPException) {
|
|
33
|
+
return c.json({
|
|
34
|
+
error: err.message,
|
|
35
|
+
}, err.status);
|
|
36
|
+
}
|
|
37
|
+
console.error('Uncaught Error:', err);
|
|
38
|
+
return c.json({
|
|
39
|
+
error: 'Internal Server Error',
|
|
40
|
+
}, 500)
|
|
12
41
|
})
|
|
13
|
-
})
|
|
14
42
|
|
|
15
|
-
app
|
|
16
|
-
|
|
17
|
-
|
|
43
|
+
return app;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const server = createServer(collections);
|
|
47
|
+
|
|
48
|
+
export default server;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Create endpoints for a tool collection
|
|
52
|
+
*/
|
|
53
|
+
function createCollectionEndpoints(coll: ToolCollection) {
|
|
54
|
+
const endpoint = new Hono();
|
|
55
|
+
|
|
56
|
+
// POST endpoint to execute tools
|
|
57
|
+
endpoint.post('/', (c: Context) => {
|
|
58
|
+
return coll.execute(c);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// GET endpoint to retrieve collection metadata and tool definitions
|
|
62
|
+
endpoint.get('/', (c) => {
|
|
63
|
+
const url = new URL(c.req.url);
|
|
64
|
+
return c.json({
|
|
65
|
+
src: `${url.origin}${url.pathname}`,
|
|
66
|
+
title: coll.title || coll.name,
|
|
67
|
+
description: coll.description,
|
|
68
|
+
tools: coll.getToolDefinitions()
|
|
69
|
+
} satisfies ToolCollectionDefinition);
|
|
70
|
+
});
|
|
18
71
|
|
|
19
|
-
|
|
72
|
+
return endpoint;
|
|
73
|
+
}
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
3
|
+
"target": "ES2022",
|
|
4
4
|
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
6
|
"esModuleInterop": true,
|
|
7
7
|
"strict": true,
|
|
8
8
|
"skipLibCheck": true,
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"noUnusedLocals": true,
|
|
13
|
+
"noUnusedParameters": true,
|
|
14
|
+
"noImplicitReturns": true,
|
|
9
15
|
"outDir": "dist"
|
|
10
16
|
},
|
|
11
17
|
"include": [
|
|
12
|
-
"src"
|
|
18
|
+
"src/**/*"
|
|
19
|
+
],
|
|
20
|
+
"exclude": [
|
|
21
|
+
"node_modules",
|
|
22
|
+
"dist"
|
|
13
23
|
]
|
|
14
|
-
}
|
|
24
|
+
}
|
|
@@ -1,10 +1,48 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
1
|
import devServer from '@hono/vite-dev-server';
|
|
2
|
+
import { defineConfig, loadEnv } from 'vite';
|
|
3
3
|
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
export default defineConfig(({ mode }) => {
|
|
5
|
+
// Load env files
|
|
6
|
+
const env = loadEnv(mode, process.cwd(), '');
|
|
7
|
+
|
|
8
|
+
// Dev config
|
|
9
|
+
if (mode === 'development') {
|
|
10
|
+
return {
|
|
11
|
+
base: '/api',
|
|
12
|
+
plugins: [
|
|
13
|
+
devServer({
|
|
14
|
+
entry: './src/server.ts',
|
|
15
|
+
}),
|
|
16
|
+
],
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Build config
|
|
21
|
+
return {
|
|
22
|
+
build: {
|
|
23
|
+
minify: false,
|
|
24
|
+
lib: {
|
|
25
|
+
entry: {
|
|
26
|
+
server: './src/server.ts',
|
|
27
|
+
},
|
|
28
|
+
formats: ['es']
|
|
29
|
+
},
|
|
30
|
+
rollupOptions: {
|
|
31
|
+
external: (id) => {
|
|
32
|
+
// Keep relative imports as part of the bundle
|
|
33
|
+
if (id.startsWith('.') || id.startsWith('/')) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
// Externalize all node modules and absolute imports
|
|
37
|
+
return true;
|
|
38
|
+
},
|
|
39
|
+
output: {
|
|
40
|
+
preserveModules: true,
|
|
41
|
+
preserveModulesRoot: 'src',
|
|
42
|
+
entryFileNames: '[name].js'
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
outDir: 'dist'
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
});
|