@agi-cli/server 0.1.57 → 0.1.58
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/package.json +3 -3
- package/src/index.ts +30 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agi-cli/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.58",
|
|
4
4
|
"description": "HTTP API server for AGI CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"typecheck": "tsc --noEmit"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@agi-cli/sdk": "0.1.
|
|
33
|
-
"@agi-cli/database": "0.1.
|
|
32
|
+
"@agi-cli/sdk": "0.1.58",
|
|
33
|
+
"@agi-cli/database": "0.1.58",
|
|
34
34
|
"drizzle-orm": "^0.44.5",
|
|
35
35
|
"hono": "^4.9.9"
|
|
36
36
|
},
|
package/src/index.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type { AgentConfigEntry } from './runtime/agent-registry.ts';
|
|
|
14
14
|
function initApp() {
|
|
15
15
|
const app = new Hono();
|
|
16
16
|
|
|
17
|
-
// Enable CORS for
|
|
17
|
+
// Enable CORS for localhost and local network access
|
|
18
18
|
app.use(
|
|
19
19
|
'*',
|
|
20
20
|
cors({
|
|
@@ -22,15 +22,16 @@ function initApp() {
|
|
|
22
22
|
// Allow all localhost and 127.0.0.1 on any port
|
|
23
23
|
if (
|
|
24
24
|
origin.startsWith('http://localhost:') ||
|
|
25
|
-
origin.startsWith('http://127.0.0.1:')
|
|
25
|
+
origin.startsWith('http://127.0.0.1:') ||
|
|
26
|
+
origin.startsWith('https://localhost:') ||
|
|
27
|
+
origin.startsWith('https://127.0.0.1:')
|
|
26
28
|
) {
|
|
27
29
|
return origin;
|
|
28
30
|
}
|
|
29
|
-
// Allow
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
) {
|
|
31
|
+
// Allow local network IPs (192.168.x.x, 10.x.x.x, 172.16-31.x.x)
|
|
32
|
+
const localNetworkPattern =
|
|
33
|
+
/^https?:\/\/(192\.168\.\d{1,3}\.\d{1,3}|10\.\d{1,3}\.\d{1,3}\.\d{1,3}|172\.(1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}):\d+$/;
|
|
34
|
+
if (localNetworkPattern.test(origin)) {
|
|
34
35
|
return origin;
|
|
35
36
|
}
|
|
36
37
|
// Default to allowing the origin (can be restricted in production)
|
|
@@ -76,7 +77,7 @@ export type StandaloneAppConfig = {
|
|
|
76
77
|
export function createStandaloneApp(_config?: StandaloneAppConfig) {
|
|
77
78
|
const honoApp = new Hono();
|
|
78
79
|
|
|
79
|
-
// Enable CORS for
|
|
80
|
+
// Enable CORS for localhost and local network access
|
|
80
81
|
honoApp.use(
|
|
81
82
|
'*',
|
|
82
83
|
cors({
|
|
@@ -84,15 +85,16 @@ export function createStandaloneApp(_config?: StandaloneAppConfig) {
|
|
|
84
85
|
// Allow all localhost and 127.0.0.1 on any port
|
|
85
86
|
if (
|
|
86
87
|
origin.startsWith('http://localhost:') ||
|
|
87
|
-
origin.startsWith('http://127.0.0.1:')
|
|
88
|
+
origin.startsWith('http://127.0.0.1:') ||
|
|
89
|
+
origin.startsWith('https://localhost:') ||
|
|
90
|
+
origin.startsWith('https://127.0.0.1:')
|
|
88
91
|
) {
|
|
89
92
|
return origin;
|
|
90
93
|
}
|
|
91
|
-
// Allow
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
) {
|
|
94
|
+
// Allow local network IPs (192.168.x.x, 10.x.x.x, 172.16-31.x.x)
|
|
95
|
+
const localNetworkPattern =
|
|
96
|
+
/^https?:\/\/(192\.168\.\d{1,3}\.\d{1,3}|10\.\d{1,3}\.\d{1,3}\.\d{1,3}|172\.(1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}):\d+$/;
|
|
97
|
+
if (localNetworkPattern.test(origin)) {
|
|
96
98
|
return origin;
|
|
97
99
|
}
|
|
98
100
|
// Default to allowing the origin
|
|
@@ -148,6 +150,8 @@ export type EmbeddedAppConfig = {
|
|
|
148
150
|
model?: string;
|
|
149
151
|
agent?: string;
|
|
150
152
|
};
|
|
153
|
+
/** Additional CORS origins for proxies/Tailscale (e.g., ['https://myapp.ts.net', 'https://example.com']) */
|
|
154
|
+
corsOrigins?: string[];
|
|
151
155
|
};
|
|
152
156
|
|
|
153
157
|
export function createEmbeddedApp(config: EmbeddedAppConfig = {}) {
|
|
@@ -160,7 +164,7 @@ export function createEmbeddedApp(config: EmbeddedAppConfig = {}) {
|
|
|
160
164
|
await next();
|
|
161
165
|
});
|
|
162
166
|
|
|
163
|
-
// Enable CORS for
|
|
167
|
+
// Enable CORS for localhost and local network access
|
|
164
168
|
honoApp.use(
|
|
165
169
|
'*',
|
|
166
170
|
cors({
|
|
@@ -168,15 +172,20 @@ export function createEmbeddedApp(config: EmbeddedAppConfig = {}) {
|
|
|
168
172
|
// Allow all localhost and 127.0.0.1 on any port
|
|
169
173
|
if (
|
|
170
174
|
origin.startsWith('http://localhost:') ||
|
|
171
|
-
origin.startsWith('http://127.0.0.1:')
|
|
175
|
+
origin.startsWith('http://127.0.0.1:') ||
|
|
176
|
+
origin.startsWith('https://localhost:') ||
|
|
177
|
+
origin.startsWith('https://127.0.0.1:')
|
|
172
178
|
) {
|
|
173
179
|
return origin;
|
|
174
180
|
}
|
|
175
|
-
// Allow
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
181
|
+
// Allow local network IPs (192.168.x.x, 10.x.x.x, 172.16-31.x.x)
|
|
182
|
+
const localNetworkPattern =
|
|
183
|
+
/^https?:\/\/(192\.168\.\d{1,3}\.\d{1,3}|10\.\d{1,3}\.\d{1,3}\.\d{1,3}|172\.(1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}):\d+$/;
|
|
184
|
+
if (localNetworkPattern.test(origin)) {
|
|
185
|
+
return origin;
|
|
186
|
+
}
|
|
187
|
+
// Allow custom CORS origins (for Tailscale, proxies, etc.)
|
|
188
|
+
if (config.corsOrigins && config.corsOrigins.includes(origin)) {
|
|
180
189
|
return origin;
|
|
181
190
|
}
|
|
182
191
|
// Default to allowing the origin
|