@agi-cli/server 0.1.131 → 0.1.133
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 +4 -0
- package/src/openapi/paths/config.ts +54 -0
- package/src/openapi/paths/solforge.ts +154 -0
- package/src/openapi/spec.ts +3 -0
- package/src/routes/config/defaults.ts +42 -0
- package/src/routes/config/index.ts +2 -0
- package/src/routes/solforge.ts +100 -0
- package/src/runtime/provider/openai.ts +7 -1
- package/src/runtime/provider/solforge.ts +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agi-cli/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.133",
|
|
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.133",
|
|
33
|
+
"@agi-cli/database": "0.1.133",
|
|
34
34
|
"drizzle-orm": "^0.44.5",
|
|
35
35
|
"hono": "^4.9.9",
|
|
36
36
|
"zod": "^4.1.8"
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { registerTerminalsRoutes } from './routes/terminals.ts';
|
|
|
16
16
|
import { registerSessionFilesRoutes } from './routes/session-files.ts';
|
|
17
17
|
import { registerBranchRoutes } from './routes/branch.ts';
|
|
18
18
|
import { registerResearchRoutes } from './routes/research.ts';
|
|
19
|
+
import { registerSolforgeRoutes } from './routes/solforge.ts';
|
|
19
20
|
import type { AgentConfigEntry } from './runtime/agent/registry.ts';
|
|
20
21
|
|
|
21
22
|
const globalTerminalManager = new TerminalManager();
|
|
@@ -68,6 +69,7 @@ function initApp() {
|
|
|
68
69
|
registerSessionFilesRoutes(app);
|
|
69
70
|
registerBranchRoutes(app);
|
|
70
71
|
registerResearchRoutes(app);
|
|
72
|
+
registerSolforgeRoutes(app);
|
|
71
73
|
|
|
72
74
|
return app;
|
|
73
75
|
}
|
|
@@ -136,6 +138,7 @@ export function createStandaloneApp(_config?: StandaloneAppConfig) {
|
|
|
136
138
|
registerSessionFilesRoutes(honoApp);
|
|
137
139
|
registerBranchRoutes(honoApp);
|
|
138
140
|
registerResearchRoutes(honoApp);
|
|
141
|
+
registerSolforgeRoutes(honoApp);
|
|
139
142
|
|
|
140
143
|
return honoApp;
|
|
141
144
|
}
|
|
@@ -232,6 +235,7 @@ export function createEmbeddedApp(config: EmbeddedAppConfig = {}) {
|
|
|
232
235
|
registerSessionFilesRoutes(honoApp);
|
|
233
236
|
registerBranchRoutes(honoApp);
|
|
234
237
|
registerResearchRoutes(honoApp);
|
|
238
|
+
registerSolforgeRoutes(honoApp);
|
|
235
239
|
|
|
236
240
|
return honoApp;
|
|
237
241
|
}
|
|
@@ -161,4 +161,58 @@ export const configPaths = {
|
|
|
161
161
|
},
|
|
162
162
|
},
|
|
163
163
|
},
|
|
164
|
+
'/v1/config/defaults': {
|
|
165
|
+
patch: {
|
|
166
|
+
tags: ['config'],
|
|
167
|
+
operationId: 'updateDefaults',
|
|
168
|
+
summary: 'Update default configuration',
|
|
169
|
+
description: 'Update the default agent, provider, and/or model',
|
|
170
|
+
parameters: [projectQueryParam()],
|
|
171
|
+
requestBody: {
|
|
172
|
+
required: true,
|
|
173
|
+
content: {
|
|
174
|
+
'application/json': {
|
|
175
|
+
schema: {
|
|
176
|
+
type: 'object',
|
|
177
|
+
properties: {
|
|
178
|
+
agent: { type: 'string' },
|
|
179
|
+
provider: { type: 'string' },
|
|
180
|
+
model: { type: 'string' },
|
|
181
|
+
scope: {
|
|
182
|
+
type: 'string',
|
|
183
|
+
enum: ['global', 'local'],
|
|
184
|
+
default: 'local',
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
responses: {
|
|
192
|
+
200: {
|
|
193
|
+
description: 'OK',
|
|
194
|
+
content: {
|
|
195
|
+
'application/json': {
|
|
196
|
+
schema: {
|
|
197
|
+
type: 'object',
|
|
198
|
+
properties: {
|
|
199
|
+
success: { type: 'boolean' },
|
|
200
|
+
defaults: {
|
|
201
|
+
type: 'object',
|
|
202
|
+
properties: {
|
|
203
|
+
agent: { type: 'string' },
|
|
204
|
+
provider: { type: 'string' },
|
|
205
|
+
model: { type: 'string' },
|
|
206
|
+
},
|
|
207
|
+
required: ['agent', 'provider', 'model'],
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
required: ['success', 'defaults'],
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
164
218
|
} as const;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
export const solforgePaths = {
|
|
2
|
+
'/v1/solforge/balance': {
|
|
3
|
+
get: {
|
|
4
|
+
tags: ['solforge'],
|
|
5
|
+
operationId: 'getSolforgeBalance',
|
|
6
|
+
summary: 'Get Solforge account balance',
|
|
7
|
+
description:
|
|
8
|
+
'Returns wallet balance, total spent, total topups, and request count',
|
|
9
|
+
responses: {
|
|
10
|
+
200: {
|
|
11
|
+
description: 'OK',
|
|
12
|
+
content: {
|
|
13
|
+
'application/json': {
|
|
14
|
+
schema: {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
walletAddress: { type: 'string' },
|
|
18
|
+
balance: { type: 'number' },
|
|
19
|
+
totalSpent: { type: 'number' },
|
|
20
|
+
totalTopups: { type: 'number' },
|
|
21
|
+
requestCount: { type: 'number' },
|
|
22
|
+
},
|
|
23
|
+
required: [
|
|
24
|
+
'walletAddress',
|
|
25
|
+
'balance',
|
|
26
|
+
'totalSpent',
|
|
27
|
+
'totalTopups',
|
|
28
|
+
'requestCount',
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
401: {
|
|
35
|
+
description: 'Wallet not configured',
|
|
36
|
+
content: {
|
|
37
|
+
'application/json': {
|
|
38
|
+
schema: {
|
|
39
|
+
type: 'object',
|
|
40
|
+
properties: { error: { type: 'string' } },
|
|
41
|
+
required: ['error'],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
502: {
|
|
47
|
+
description: 'Failed to fetch balance from Solforge',
|
|
48
|
+
content: {
|
|
49
|
+
'application/json': {
|
|
50
|
+
schema: {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: { error: { type: 'string' } },
|
|
53
|
+
required: ['error'],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
'/v1/solforge/wallet': {
|
|
62
|
+
get: {
|
|
63
|
+
tags: ['solforge'],
|
|
64
|
+
operationId: 'getSolforgeWallet',
|
|
65
|
+
summary: 'Get Solforge wallet info',
|
|
66
|
+
description:
|
|
67
|
+
'Returns whether the wallet is configured and its public key',
|
|
68
|
+
responses: {
|
|
69
|
+
200: {
|
|
70
|
+
description: 'OK',
|
|
71
|
+
content: {
|
|
72
|
+
'application/json': {
|
|
73
|
+
schema: {
|
|
74
|
+
type: 'object',
|
|
75
|
+
properties: {
|
|
76
|
+
configured: { type: 'boolean' },
|
|
77
|
+
publicKey: { type: 'string' },
|
|
78
|
+
error: { type: 'string' },
|
|
79
|
+
},
|
|
80
|
+
required: ['configured'],
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
'/v1/solforge/usdc-balance': {
|
|
89
|
+
get: {
|
|
90
|
+
tags: ['solforge'],
|
|
91
|
+
operationId: 'getSolforgeUsdcBalance',
|
|
92
|
+
summary: 'Get USDC token balance',
|
|
93
|
+
description:
|
|
94
|
+
'Fetches USDC balance from Solana blockchain for the configured wallet',
|
|
95
|
+
parameters: [
|
|
96
|
+
{
|
|
97
|
+
in: 'query',
|
|
98
|
+
name: 'network',
|
|
99
|
+
schema: {
|
|
100
|
+
type: 'string',
|
|
101
|
+
enum: ['mainnet', 'devnet'],
|
|
102
|
+
default: 'mainnet',
|
|
103
|
+
},
|
|
104
|
+
description: 'Solana network to query',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
responses: {
|
|
108
|
+
200: {
|
|
109
|
+
description: 'OK',
|
|
110
|
+
content: {
|
|
111
|
+
'application/json': {
|
|
112
|
+
schema: {
|
|
113
|
+
type: 'object',
|
|
114
|
+
properties: {
|
|
115
|
+
walletAddress: { type: 'string' },
|
|
116
|
+
usdcBalance: { type: 'number' },
|
|
117
|
+
network: {
|
|
118
|
+
type: 'string',
|
|
119
|
+
enum: ['mainnet', 'devnet'],
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
required: ['walletAddress', 'usdcBalance', 'network'],
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
401: {
|
|
128
|
+
description: 'Wallet not configured',
|
|
129
|
+
content: {
|
|
130
|
+
'application/json': {
|
|
131
|
+
schema: {
|
|
132
|
+
type: 'object',
|
|
133
|
+
properties: { error: { type: 'string' } },
|
|
134
|
+
required: ['error'],
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
502: {
|
|
140
|
+
description: 'Failed to fetch USDC balance from Solana',
|
|
141
|
+
content: {
|
|
142
|
+
'application/json': {
|
|
143
|
+
schema: {
|
|
144
|
+
type: 'object',
|
|
145
|
+
properties: { error: { type: 'string' } },
|
|
146
|
+
required: ['error'],
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
} as const;
|
package/src/openapi/spec.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { streamPaths } from './paths/stream';
|
|
|
8
8
|
import { schemas } from './schemas';
|
|
9
9
|
|
|
10
10
|
import { terminalsPath } from './paths/terminals';
|
|
11
|
+
import { solforgePaths } from './paths/solforge';
|
|
11
12
|
|
|
12
13
|
export function getOpenAPISpec() {
|
|
13
14
|
const spec = {
|
|
@@ -27,6 +28,7 @@ export function getOpenAPISpec() {
|
|
|
27
28
|
{ name: 'files' },
|
|
28
29
|
{ name: 'git' },
|
|
29
30
|
{ name: 'terminals' },
|
|
31
|
+
{ name: 'solforge' },
|
|
30
32
|
],
|
|
31
33
|
paths: {
|
|
32
34
|
...askPaths,
|
|
@@ -37,6 +39,7 @@ export function getOpenAPISpec() {
|
|
|
37
39
|
...filesPaths,
|
|
38
40
|
...gitPaths,
|
|
39
41
|
...terminalsPath,
|
|
42
|
+
...solforgePaths,
|
|
40
43
|
},
|
|
41
44
|
components: {
|
|
42
45
|
schemas,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Hono } from 'hono';
|
|
2
|
+
import { setConfig, loadConfig } from '@agi-cli/sdk';
|
|
3
|
+
import { logger } from '@agi-cli/sdk';
|
|
4
|
+
import { serializeError } from '../../runtime/errors/api-error.ts';
|
|
5
|
+
|
|
6
|
+
export function registerDefaultsRoute(app: Hono) {
|
|
7
|
+
app.patch('/v1/config/defaults', async (c) => {
|
|
8
|
+
try {
|
|
9
|
+
const projectRoot = c.req.query('project') || process.cwd();
|
|
10
|
+
const body = await c.req.json<{
|
|
11
|
+
agent?: string;
|
|
12
|
+
provider?: string;
|
|
13
|
+
model?: string;
|
|
14
|
+
scope?: 'global' | 'local';
|
|
15
|
+
}>();
|
|
16
|
+
|
|
17
|
+
const scope = body.scope || 'local';
|
|
18
|
+
const updates: Partial<{
|
|
19
|
+
agent: string;
|
|
20
|
+
provider: string;
|
|
21
|
+
model: string;
|
|
22
|
+
}> = {};
|
|
23
|
+
|
|
24
|
+
if (body.agent) updates.agent = body.agent;
|
|
25
|
+
if (body.provider) updates.provider = body.provider;
|
|
26
|
+
if (body.model) updates.model = body.model;
|
|
27
|
+
|
|
28
|
+
await setConfig(scope, updates, projectRoot);
|
|
29
|
+
|
|
30
|
+
const cfg = await loadConfig(projectRoot);
|
|
31
|
+
|
|
32
|
+
return c.json({
|
|
33
|
+
success: true,
|
|
34
|
+
defaults: cfg.defaults,
|
|
35
|
+
});
|
|
36
|
+
} catch (error) {
|
|
37
|
+
logger.error('Failed to update defaults', error);
|
|
38
|
+
const errorResponse = serializeError(error);
|
|
39
|
+
return c.json(errorResponse, errorResponse.error.status || 500);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -4,6 +4,7 @@ import { registerMainConfigRoute } from './main.ts';
|
|
|
4
4
|
import { registerAgentsRoute } from './agents.ts';
|
|
5
5
|
import { registerProvidersRoute } from './providers.ts';
|
|
6
6
|
import { registerModelsRoutes } from './models.ts';
|
|
7
|
+
import { registerDefaultsRoute } from './defaults.ts';
|
|
7
8
|
|
|
8
9
|
export function registerConfigRoutes(app: Hono) {
|
|
9
10
|
registerCwdRoute(app);
|
|
@@ -11,4 +12,5 @@ export function registerConfigRoutes(app: Hono) {
|
|
|
11
12
|
registerAgentsRoute(app);
|
|
12
13
|
registerProvidersRoute(app);
|
|
13
14
|
registerModelsRoutes(app);
|
|
15
|
+
registerDefaultsRoute(app);
|
|
14
16
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { Hono } from 'hono';
|
|
2
|
+
import {
|
|
3
|
+
fetchSolforgeBalance,
|
|
4
|
+
getPublicKeyFromPrivate,
|
|
5
|
+
getAuth,
|
|
6
|
+
loadConfig,
|
|
7
|
+
fetchSolanaUsdcBalance,
|
|
8
|
+
} from '@agi-cli/sdk';
|
|
9
|
+
import { logger } from '@agi-cli/sdk';
|
|
10
|
+
import { serializeError } from '../runtime/errors/api-error.ts';
|
|
11
|
+
|
|
12
|
+
async function getSolforgePrivateKey(): Promise<string | null> {
|
|
13
|
+
if (process.env.SOLFORGE_PRIVATE_KEY) {
|
|
14
|
+
return process.env.SOLFORGE_PRIVATE_KEY;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const cfg = await loadConfig(process.cwd());
|
|
19
|
+
const auth = await getAuth('solforge', cfg.projectRoot);
|
|
20
|
+
if (auth?.type === 'wallet' && auth.secret) {
|
|
21
|
+
return auth.secret;
|
|
22
|
+
}
|
|
23
|
+
} catch {}
|
|
24
|
+
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function registerSolforgeRoutes(app: Hono) {
|
|
29
|
+
app.get('/v1/solforge/balance', async (c) => {
|
|
30
|
+
try {
|
|
31
|
+
const privateKey = await getSolforgePrivateKey();
|
|
32
|
+
if (!privateKey) {
|
|
33
|
+
return c.json({ error: 'Solforge wallet not configured' }, 401);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const balance = await fetchSolforgeBalance({ privateKey });
|
|
37
|
+
if (!balance) {
|
|
38
|
+
return c.json({ error: 'Failed to fetch balance from Solforge' }, 502);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return c.json(balance);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
logger.error('Failed to fetch Solforge balance', error);
|
|
44
|
+
const errorResponse = serializeError(error);
|
|
45
|
+
return c.json(errorResponse, errorResponse.error.status || 500);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
app.get('/v1/solforge/wallet', async (c) => {
|
|
50
|
+
try {
|
|
51
|
+
const privateKey = await getSolforgePrivateKey();
|
|
52
|
+
if (!privateKey) {
|
|
53
|
+
return c.json(
|
|
54
|
+
{ error: 'Solforge wallet not configured', configured: false },
|
|
55
|
+
200,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const publicKey = getPublicKeyFromPrivate(privateKey);
|
|
60
|
+
if (!publicKey) {
|
|
61
|
+
return c.json({ error: 'Invalid private key', configured: false }, 200);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return c.json({
|
|
65
|
+
configured: true,
|
|
66
|
+
publicKey,
|
|
67
|
+
});
|
|
68
|
+
} catch (error) {
|
|
69
|
+
logger.error('Failed to get Solforge wallet info', error);
|
|
70
|
+
const errorResponse = serializeError(error);
|
|
71
|
+
return c.json(errorResponse, errorResponse.error.status || 500);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
app.get('/v1/solforge/usdc-balance', async (c) => {
|
|
76
|
+
try {
|
|
77
|
+
const privateKey = await getSolforgePrivateKey();
|
|
78
|
+
if (!privateKey) {
|
|
79
|
+
return c.json({ error: 'Solforge wallet not configured' }, 401);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const network =
|
|
83
|
+
(c.req.query('network') as 'mainnet' | 'devnet') || 'mainnet';
|
|
84
|
+
|
|
85
|
+
const balance = await fetchSolanaUsdcBalance({ privateKey }, network);
|
|
86
|
+
if (!balance) {
|
|
87
|
+
return c.json(
|
|
88
|
+
{ error: 'Failed to fetch USDC balance from Solana' },
|
|
89
|
+
502,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return c.json(balance);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
logger.error('Failed to fetch USDC balance', error);
|
|
96
|
+
const errorResponse = serializeError(error);
|
|
97
|
+
return c.json(errorResponse, errorResponse.error.status || 500);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
@@ -5,7 +5,11 @@ import { openai, createOpenAI } from '@ai-sdk/openai';
|
|
|
5
5
|
export async function resolveOpenAIModel(
|
|
6
6
|
model: string,
|
|
7
7
|
cfg: AGIConfig,
|
|
8
|
-
options?: {
|
|
8
|
+
options?: {
|
|
9
|
+
systemPrompt?: string;
|
|
10
|
+
promptCacheKey?: string;
|
|
11
|
+
promptCacheRetention?: 'in_memory' | '24h';
|
|
12
|
+
},
|
|
9
13
|
) {
|
|
10
14
|
const auth = await getAuth('openai', cfg.projectRoot);
|
|
11
15
|
if (auth?.type === 'oauth') {
|
|
@@ -16,6 +20,8 @@ export async function resolveOpenAIModel(
|
|
|
16
20
|
reasoningEffort: isCodexModel ? 'high' : 'medium',
|
|
17
21
|
reasoningSummary: 'auto',
|
|
18
22
|
instructions: options?.systemPrompt,
|
|
23
|
+
promptCacheKey: options?.promptCacheKey,
|
|
24
|
+
promptCacheRetention: options?.promptCacheRetention,
|
|
19
25
|
});
|
|
20
26
|
}
|
|
21
27
|
if (auth?.type === 'api' && auth.key) {
|
|
@@ -19,7 +19,6 @@ export function resolveSolforgeModel(model: string, sessionId?: string) {
|
|
|
19
19
|
}
|
|
20
20
|
const baseURL = process.env.SOLFORGE_BASE_URL;
|
|
21
21
|
const rpcURL = process.env.SOLFORGE_SOLANA_RPC_URL;
|
|
22
|
-
const topupAmount = process.env.SOLFORGE_TOPUP_MICRO_USDC;
|
|
23
22
|
|
|
24
23
|
const callbacks: SolforgePaymentCallbacks = sessionId
|
|
25
24
|
? {
|
|
@@ -62,7 +61,6 @@ export function resolveSolforgeModel(model: string, sessionId?: string) {
|
|
|
62
61
|
{
|
|
63
62
|
baseURL,
|
|
64
63
|
rpcURL,
|
|
65
|
-
topupAmountMicroUsdc: topupAmount,
|
|
66
64
|
callbacks,
|
|
67
65
|
providerNpm,
|
|
68
66
|
},
|