@agi-cli/server 0.1.132 → 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
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"
|
|
@@ -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
|
}
|
package/src/routes/solforge.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
getPublicKeyFromPrivate,
|
|
5
5
|
getAuth,
|
|
6
6
|
loadConfig,
|
|
7
|
+
fetchSolanaUsdcBalance,
|
|
7
8
|
} from '@agi-cli/sdk';
|
|
8
9
|
import { logger } from '@agi-cli/sdk';
|
|
9
10
|
import { serializeError } from '../runtime/errors/api-error.ts';
|
|
@@ -70,4 +71,30 @@ export function registerSolforgeRoutes(app: Hono) {
|
|
|
70
71
|
return c.json(errorResponse, errorResponse.error.status || 500);
|
|
71
72
|
}
|
|
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
|
+
});
|
|
73
100
|
}
|