@blockrun/franklin 3.21.0 → 3.21.1
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/dist/tools/phone.js +15 -9
- package/dist/tools/voice.js +22 -7
- package/package.json +1 -1
package/dist/tools/phone.js
CHANGED
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, createSolanaPaymentPayload, parsePaymentRequired, extractPaymentDetails, solanaKeyToBytes, SOLANA_NETWORK, } from '@blockrun/llm';
|
|
15
15
|
import { loadChain, API_URLS, VERSION } from '../config.js';
|
|
16
16
|
import { logger } from '../logger.js';
|
|
17
|
+
import { recordUsage } from '../stats/tracker.js';
|
|
17
18
|
const PHONE_TIMEOUT_MS = 30_000;
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
async function postWithPayment(path, body, ctx, meta) {
|
|
20
|
+
const startMs = Date.now();
|
|
20
21
|
const chain = loadChain();
|
|
21
22
|
const apiUrl = API_URLS[chain];
|
|
22
23
|
const endpoint = `${apiUrl}${path}`;
|
|
@@ -51,7 +52,12 @@ async function postWithPayment(path, body, ctx) {
|
|
|
51
52
|
const errText = await response.text().catch(() => '');
|
|
52
53
|
throw new Error(`Phone ${path} failed (${response.status}): ${errText.slice(0, 300)}`);
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
+
const data = (await response.json());
|
|
56
|
+
try {
|
|
57
|
+
recordUsage(meta.tool, 0, 0, meta.priceUsd, Date.now() - startMs);
|
|
58
|
+
}
|
|
59
|
+
catch { /* telemetry best-effort */ }
|
|
60
|
+
return data;
|
|
55
61
|
}
|
|
56
62
|
finally {
|
|
57
63
|
clearTimeout(timeout);
|
|
@@ -117,7 +123,7 @@ export const listPhoneNumbersCapability = {
|
|
|
117
123
|
},
|
|
118
124
|
execute: async (_input, ctx) => {
|
|
119
125
|
try {
|
|
120
|
-
const res = await postWithPayment('/v1/phone/numbers/list', {}, ctx);
|
|
126
|
+
const res = await postWithPayment('/v1/phone/numbers/list', {}, ctx, { tool: 'ListPhoneNumbers', priceUsd: 0.001 });
|
|
121
127
|
return {
|
|
122
128
|
output: `## Phone numbers (wallet-owned)\n\n` +
|
|
123
129
|
'```json\n' + JSON.stringify(res, null, 2) + '\n```',
|
|
@@ -150,7 +156,7 @@ export const buyPhoneNumberCapability = {
|
|
|
150
156
|
if (typeof input.area_code === 'string')
|
|
151
157
|
body.areaCode = input.area_code;
|
|
152
158
|
try {
|
|
153
|
-
const res = await postWithPayment('/v1/phone/numbers/buy', body, ctx);
|
|
159
|
+
const res = await postWithPayment('/v1/phone/numbers/buy', body, ctx, { tool: 'BuyPhoneNumber', priceUsd: 5.0 });
|
|
154
160
|
return {
|
|
155
161
|
output: `## Number provisioned ($5 USDC charged)\n\n` +
|
|
156
162
|
'```json\n' + JSON.stringify(res, null, 2) + '\n```',
|
|
@@ -180,7 +186,7 @@ export const renewPhoneNumberCapability = {
|
|
|
180
186
|
return { output: 'phone_number (E.164) required', isError: true };
|
|
181
187
|
}
|
|
182
188
|
try {
|
|
183
|
-
const res = await postWithPayment('/v1/phone/numbers/renew', { phoneNumber: input.phone_number }, ctx);
|
|
189
|
+
const res = await postWithPayment('/v1/phone/numbers/renew', { phoneNumber: input.phone_number }, ctx, { tool: 'RenewPhoneNumber', priceUsd: 5.0 });
|
|
184
190
|
return {
|
|
185
191
|
output: `## Lease renewed (+30 days, $5 USDC charged)\n\n` +
|
|
186
192
|
'```json\n' + JSON.stringify(res, null, 2) + '\n```',
|
|
@@ -210,7 +216,7 @@ export const releasePhoneNumberCapability = {
|
|
|
210
216
|
return { output: 'phone_number (E.164) required', isError: true };
|
|
211
217
|
}
|
|
212
218
|
try {
|
|
213
|
-
const res = await postWithPayment('/v1/phone/numbers/release', { phoneNumber: input.phone_number }, ctx);
|
|
219
|
+
const res = await postWithPayment('/v1/phone/numbers/release', { phoneNumber: input.phone_number }, ctx, { tool: 'ReleasePhoneNumber', priceUsd: 0 });
|
|
214
220
|
return {
|
|
215
221
|
output: `## Number released (free)\n\n` +
|
|
216
222
|
'```json\n' + JSON.stringify(res, null, 2) + '\n```',
|
|
@@ -241,7 +247,7 @@ export const phoneLookupCapability = {
|
|
|
241
247
|
return { output: 'phone_number (E.164) required', isError: true };
|
|
242
248
|
}
|
|
243
249
|
try {
|
|
244
|
-
const res = await postWithPayment('/v1/phone/lookup', { phoneNumber: input.phone_number }, ctx);
|
|
250
|
+
const res = await postWithPayment('/v1/phone/lookup', { phoneNumber: input.phone_number }, ctx, { tool: 'PhoneLookup', priceUsd: 0.01 });
|
|
245
251
|
return {
|
|
246
252
|
output: `## Phone lookup ($0.01 USDC charged)\n\n` +
|
|
247
253
|
'```json\n' + JSON.stringify(res, null, 2) + '\n```',
|
|
@@ -271,7 +277,7 @@ export const phoneFraudCheckCapability = {
|
|
|
271
277
|
return { output: 'phone_number (E.164) required', isError: true };
|
|
272
278
|
}
|
|
273
279
|
try {
|
|
274
|
-
const res = await postWithPayment('/v1/phone/lookup/fraud', { phoneNumber: input.phone_number }, ctx);
|
|
280
|
+
const res = await postWithPayment('/v1/phone/lookup/fraud', { phoneNumber: input.phone_number }, ctx, { tool: 'PhoneFraudCheck', priceUsd: 0.05 });
|
|
275
281
|
return {
|
|
276
282
|
output: `## Fraud check ($0.05 USDC charged)\n\n` +
|
|
277
283
|
'```json\n' + JSON.stringify(res, null, 2) + '\n```',
|
package/dist/tools/voice.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, createSolanaPaymentPayload, parsePaymentRequired, extractPaymentDetails, solanaKeyToBytes, SOLANA_NETWORK, } from '@blockrun/llm';
|
|
18
18
|
import { loadChain, API_URLS, VERSION } from '../config.js';
|
|
19
19
|
import { logger } from '../logger.js';
|
|
20
|
+
import { recordUsage } from '../stats/tracker.js';
|
|
20
21
|
import { CallLog } from '../phone/call-log.js';
|
|
21
22
|
/** Singleton, lazy — paths are computed at first use so tests can stub homedir. */
|
|
22
23
|
let _callLog = null;
|
|
@@ -52,8 +53,8 @@ function normalizeStatus(raw) {
|
|
|
52
53
|
return 'queued';
|
|
53
54
|
}
|
|
54
55
|
const VOICE_TIMEOUT_MS = 30_000;
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
async function postWithPayment(path, body, ctx, meta) {
|
|
57
|
+
const startMs = Date.now();
|
|
57
58
|
const chain = loadChain();
|
|
58
59
|
const apiUrl = API_URLS[chain];
|
|
59
60
|
const endpoint = `${apiUrl}${path}`;
|
|
@@ -88,14 +89,22 @@ async function postWithPayment(path, body, ctx) {
|
|
|
88
89
|
const errText = await response.text().catch(() => '');
|
|
89
90
|
throw new Error(`Voice ${path} failed (${response.status}): ${errText.slice(0, 400)}`);
|
|
90
91
|
}
|
|
91
|
-
|
|
92
|
+
const data = (await response.json());
|
|
93
|
+
// Telemetry — record the cost so the status bar's per-turn delta reflects
|
|
94
|
+
// real x402 spend (not just LLM cost). Best-effort; never block on failure.
|
|
95
|
+
try {
|
|
96
|
+
recordUsage(meta.tool, 0, 0, meta.priceUsd, Date.now() - startMs);
|
|
97
|
+
}
|
|
98
|
+
catch { /* telemetry best-effort */ }
|
|
99
|
+
return data;
|
|
92
100
|
}
|
|
93
101
|
finally {
|
|
94
102
|
clearTimeout(timeout);
|
|
95
103
|
ctx.abortSignal.removeEventListener('abort', onAbort);
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
|
-
async function getNoPayment(path, ctx) {
|
|
106
|
+
async function getNoPayment(path, ctx, meta) {
|
|
107
|
+
const startMs = Date.now();
|
|
99
108
|
const chain = loadChain();
|
|
100
109
|
const apiUrl = API_URLS[chain];
|
|
101
110
|
const endpoint = `${apiUrl}${path}`;
|
|
@@ -113,7 +122,13 @@ async function getNoPayment(path, ctx) {
|
|
|
113
122
|
const errText = await resp.text().catch(() => '');
|
|
114
123
|
throw new Error(`Voice ${path} failed (${resp.status}): ${errText.slice(0, 300)}`);
|
|
115
124
|
}
|
|
116
|
-
|
|
125
|
+
const data = (await resp.json());
|
|
126
|
+
// Record even free calls so the audit tab shows the activity (cost 0).
|
|
127
|
+
try {
|
|
128
|
+
recordUsage(meta.tool, 0, 0, meta.priceUsd, Date.now() - startMs);
|
|
129
|
+
}
|
|
130
|
+
catch { /* telemetry best-effort */ }
|
|
131
|
+
return data;
|
|
117
132
|
}
|
|
118
133
|
finally {
|
|
119
134
|
clearTimeout(timeout);
|
|
@@ -255,7 +270,7 @@ export const voiceCallCapability = {
|
|
|
255
270
|
if (typeof input.wait_for_greeting === 'boolean')
|
|
256
271
|
body.wait_for_greeting = input.wait_for_greeting;
|
|
257
272
|
try {
|
|
258
|
-
const res = await postWithPayment('/v1/voice/call', body, ctx);
|
|
273
|
+
const res = await postWithPayment('/v1/voice/call', body, ctx, { tool: 'VoiceCall', priceUsd: 0.54 });
|
|
259
274
|
const callId = (res.call_id || res.id);
|
|
260
275
|
// Persist a "queued" row so the panel sees the call before VoiceStatus polls.
|
|
261
276
|
// Best-effort — if disk write fails we still surface the call_id to the agent.
|
|
@@ -314,7 +329,7 @@ export const voiceStatusCapability = {
|
|
|
314
329
|
return { output: 'call_id required', isError: true };
|
|
315
330
|
}
|
|
316
331
|
try {
|
|
317
|
-
const res = await getNoPayment(`/v1/voice/call/${encodeURIComponent(input.call_id)}`, ctx);
|
|
332
|
+
const res = await getNoPayment(`/v1/voice/call/${encodeURIComponent(input.call_id)}`, ctx, { tool: 'VoiceStatus', priceUsd: 0 });
|
|
318
333
|
// Patch the local journal with whatever fields the gateway returned —
|
|
319
334
|
// transcript / recording / duration / disposition. Append-only schema
|
|
320
335
|
// means we just write a new row; CallLog.summary() picks the latest.
|
package/package.json
CHANGED