@wopr-network/platform-core 1.36.0 → 1.36.2

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.
@@ -24,7 +24,10 @@ export declare class BtcWatcher {
24
24
  constructor(opts: BtcWatcherOpts);
25
25
  /** Update the set of watched addresses. */
26
26
  setWatchedAddresses(addresses: string[]): void;
27
- /** Import an address into bitcoind's wallet (watch-only, no rescan). */
27
+ /**
28
+ * Import an address into bitcoind's wallet (watch-only).
29
+ * Uses `importdescriptors` (modern bitcoind v24+) with fallback to legacy `importaddress`.
30
+ */
28
31
  importAddress(address: string): Promise<void>;
29
32
  /** Poll for confirmed payments to watched addresses. */
30
33
  poll(): Promise<void>;
@@ -21,9 +21,23 @@ export class BtcWatcher {
21
21
  for (const a of addresses)
22
22
  this.addresses.add(a);
23
23
  }
24
- /** Import an address into bitcoind's wallet (watch-only, no rescan). */
24
+ /**
25
+ * Import an address into bitcoind's wallet (watch-only).
26
+ * Uses `importdescriptors` (modern bitcoind v24+) with fallback to legacy `importaddress`.
27
+ */
25
28
  async importAddress(address) {
26
- await this.rpc("importaddress", [address, "", false]);
29
+ try {
30
+ // Modern bitcoind: get descriptor checksum, then import
31
+ const info = (await this.rpc("getdescriptorinfo", [`addr(${address})`]));
32
+ const result = (await this.rpc("importdescriptors", [[{ desc: info.descriptor, timestamp: 0 }]]));
33
+ if (result[0] && !result[0].success) {
34
+ throw new Error(result[0].error?.message ?? "importdescriptors failed");
35
+ }
36
+ }
37
+ catch {
38
+ // Fallback: legacy importaddress (bitcoind <v24)
39
+ await this.rpc("importaddress", [address, "", false]);
40
+ }
27
41
  this.addresses.add(address);
28
42
  }
29
43
  /** Poll for confirmed payments to watched addresses. */
@@ -261,7 +261,26 @@ export function chatCompletions(deps) {
261
261
  });
262
262
  debitCredits(deps, tenant.id, cost, deps.defaultMargin, "chat-completions", "openrouter");
263
263
  }
264
- return new Response(responseBody, {
264
+ // Sanitize response: strip non-standard OpenRouter fields from usage
265
+ // (cost, cost_details, is_byok, prompt_tokens_details, completion_tokens_details)
266
+ // that break downstream AI SDKs expecting standard OpenAI format.
267
+ let sanitizedBody = responseBody;
268
+ try {
269
+ const parsed = JSON.parse(responseBody);
270
+ if (parsed.usage && typeof parsed.usage === "object") {
271
+ const u = parsed.usage;
272
+ parsed.usage = {
273
+ prompt_tokens: u.prompt_tokens,
274
+ completion_tokens: u.completion_tokens,
275
+ total_tokens: u.total_tokens,
276
+ };
277
+ sanitizedBody = JSON.stringify(parsed);
278
+ }
279
+ }
280
+ catch {
281
+ // Forward raw body if parse fails
282
+ }
283
+ return new Response(sanitizedBody, {
265
284
  status: res.status,
266
285
  headers: { "Content-Type": "application/json" },
267
286
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wopr-network/platform-core",
3
- "version": "1.36.0",
3
+ "version": "1.36.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -48,9 +48,27 @@ export class BtcWatcher {
48
48
  for (const a of addresses) this.addresses.add(a);
49
49
  }
50
50
 
51
- /** Import an address into bitcoind's wallet (watch-only, no rescan). */
51
+ /**
52
+ * Import an address into bitcoind's wallet (watch-only).
53
+ * Uses `importdescriptors` (modern bitcoind v24+) with fallback to legacy `importaddress`.
54
+ */
52
55
  async importAddress(address: string): Promise<void> {
53
- await this.rpc("importaddress", [address, "", false]);
56
+ try {
57
+ // Modern bitcoind: get descriptor checksum, then import
58
+ const info = (await this.rpc("getdescriptorinfo", [`addr(${address})`])) as {
59
+ descriptor: string;
60
+ };
61
+ const result = (await this.rpc("importdescriptors", [[{ desc: info.descriptor, timestamp: 0 }]])) as Array<{
62
+ success: boolean;
63
+ error?: { message: string };
64
+ }>;
65
+ if (result[0] && !result[0].success) {
66
+ throw new Error(result[0].error?.message ?? "importdescriptors failed");
67
+ }
68
+ } catch {
69
+ // Fallback: legacy importaddress (bitcoind <v24)
70
+ await this.rpc("importaddress", [address, "", false]);
71
+ }
54
72
  this.addresses.add(address);
55
73
  }
56
74
 
@@ -350,7 +350,26 @@ export function chatCompletions(deps: ProxyDeps) {
350
350
  debitCredits(deps, tenant.id, cost, deps.defaultMargin, "chat-completions", "openrouter");
351
351
  }
352
352
 
353
- return new Response(responseBody, {
353
+ // Sanitize response: strip non-standard OpenRouter fields from usage
354
+ // (cost, cost_details, is_byok, prompt_tokens_details, completion_tokens_details)
355
+ // that break downstream AI SDKs expecting standard OpenAI format.
356
+ let sanitizedBody = responseBody;
357
+ try {
358
+ const parsed = JSON.parse(responseBody) as Record<string, unknown>;
359
+ if (parsed.usage && typeof parsed.usage === "object") {
360
+ const u = parsed.usage as Record<string, unknown>;
361
+ parsed.usage = {
362
+ prompt_tokens: u.prompt_tokens,
363
+ completion_tokens: u.completion_tokens,
364
+ total_tokens: u.total_tokens,
365
+ };
366
+ sanitizedBody = JSON.stringify(parsed);
367
+ }
368
+ } catch {
369
+ // Forward raw body if parse fails
370
+ }
371
+
372
+ return new Response(sanitizedBody, {
354
373
  status: res.status,
355
374
  headers: { "Content-Type": "application/json" },
356
375
  });