@ottocode/server 0.1.204 → 0.1.205
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": "@ottocode/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.205",
|
|
4
4
|
"description": "HTTP API server for ottocode",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"typecheck": "tsc --noEmit"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@ottocode/sdk": "0.1.
|
|
53
|
-
"@ottocode/database": "0.1.
|
|
52
|
+
"@ottocode/sdk": "0.1.205",
|
|
53
|
+
"@ottocode/database": "0.1.205",
|
|
54
54
|
"drizzle-orm": "^0.44.5",
|
|
55
55
|
"hono": "^4.9.9",
|
|
56
56
|
"zod": "^4.1.8"
|
package/src/routes/setu.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
getPublicKeyFromPrivate,
|
|
5
5
|
getAuth,
|
|
6
6
|
loadConfig,
|
|
7
|
-
fetchSolanaUsdcBalance,
|
|
8
7
|
} from '@ottocode/sdk';
|
|
9
8
|
import { logger } from '@ottocode/sdk';
|
|
10
9
|
import { serializeError } from '../runtime/errors/api-error.ts';
|
|
@@ -117,18 +116,44 @@ export function registerSetuRoutes(app: Hono) {
|
|
|
117
116
|
return c.json({ error: 'Setu wallet not configured' }, 401);
|
|
118
117
|
}
|
|
119
118
|
|
|
120
|
-
const
|
|
121
|
-
|
|
119
|
+
const publicKey = getPublicKeyFromPrivate(privateKey);
|
|
120
|
+
if (!publicKey) {
|
|
121
|
+
return c.json({ error: 'Invalid private key' }, 400);
|
|
122
|
+
}
|
|
122
123
|
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
const baseUrl = getSetuBaseUrl();
|
|
125
|
+
const response = await fetch(
|
|
126
|
+
`${baseUrl}/v1/wallet/${publicKey}/balances?limit=100&showNative=false&showNfts=false&showZeroBalance=false`,
|
|
127
|
+
{
|
|
128
|
+
method: 'GET',
|
|
129
|
+
headers: { 'Content-Type': 'application/json' },
|
|
130
|
+
},
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
if (!response.ok) {
|
|
134
|
+
return c.json({ error: 'Failed to fetch wallet balances' }, 502);
|
|
129
135
|
}
|
|
130
136
|
|
|
131
|
-
|
|
137
|
+
const data = (await response.json()) as {
|
|
138
|
+
balances: Array<{
|
|
139
|
+
mint: string;
|
|
140
|
+
symbol: string;
|
|
141
|
+
name: string;
|
|
142
|
+
balance: number;
|
|
143
|
+
decimals: number;
|
|
144
|
+
pricePerToken: number | null;
|
|
145
|
+
usdValue: number | null;
|
|
146
|
+
}>;
|
|
147
|
+
totalUsdValue: number;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const usdcEntry = data.balances.find((b) => b.symbol === 'USDC');
|
|
151
|
+
|
|
152
|
+
return c.json({
|
|
153
|
+
walletAddress: publicKey,
|
|
154
|
+
usdcBalance: usdcEntry?.balance ?? 0,
|
|
155
|
+
network: 'mainnet' as const,
|
|
156
|
+
});
|
|
132
157
|
} catch (error) {
|
|
133
158
|
logger.error('Failed to fetch USDC balance', error);
|
|
134
159
|
const errorResponse = serializeError(error);
|
|
@@ -21,6 +21,7 @@ export async function resolveModel(
|
|
|
21
21
|
sessionId?: string;
|
|
22
22
|
messageId?: string;
|
|
23
23
|
topupApprovalMode?: ResolveSetuModelOptions['topupApprovalMode'];
|
|
24
|
+
autoPayThresholdUsd?: ResolveSetuModelOptions['autoPayThresholdUsd'];
|
|
24
25
|
},
|
|
25
26
|
) {
|
|
26
27
|
if (provider === 'openai') {
|
|
@@ -46,6 +47,7 @@ export async function resolveModel(
|
|
|
46
47
|
return await resolveSetuModel(model, options?.sessionId, {
|
|
47
48
|
messageId: options?.messageId,
|
|
48
49
|
topupApprovalMode: options?.topupApprovalMode,
|
|
50
|
+
autoPayThresholdUsd: options?.autoPayThresholdUsd,
|
|
49
51
|
});
|
|
50
52
|
}
|
|
51
53
|
if (provider === 'zai') {
|
|
@@ -21,6 +21,7 @@ function getProviderNpm(model: string): string | undefined {
|
|
|
21
21
|
export interface ResolveSetuModelOptions {
|
|
22
22
|
messageId?: string;
|
|
23
23
|
topupApprovalMode?: 'auto' | 'approval';
|
|
24
|
+
autoPayThresholdUsd?: number;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
async function getSetuPrivateKey(): Promise<string> {
|
|
@@ -50,7 +51,11 @@ export async function resolveSetuModel(
|
|
|
50
51
|
}
|
|
51
52
|
const baseURL = process.env.SETU_BASE_URL;
|
|
52
53
|
const rpcURL = process.env.SETU_SOLANA_RPC_URL;
|
|
53
|
-
const {
|
|
54
|
+
const {
|
|
55
|
+
messageId,
|
|
56
|
+
topupApprovalMode = 'approval',
|
|
57
|
+
autoPayThresholdUsd = MIN_TOPUP_USD,
|
|
58
|
+
} = options;
|
|
54
59
|
|
|
55
60
|
const callbacks: SetuPaymentCallbacks = sessionId
|
|
56
61
|
? {
|
|
@@ -128,6 +133,7 @@ export async function resolveSetuModel(
|
|
|
128
133
|
callbacks,
|
|
129
134
|
providerNpm,
|
|
130
135
|
topupApprovalMode,
|
|
136
|
+
autoPayThresholdUsd,
|
|
131
137
|
},
|
|
132
138
|
);
|
|
133
139
|
}
|