@connortessaro/pai 0.4.1 → 0.4.3

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.
Files changed (2) hide show
  1. package/dist/pai.mjs +11 -3
  2. package/package.json +1 -1
package/dist/pai.mjs CHANGED
@@ -23,7 +23,7 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
23
23
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
24
24
  import * as z from 'zod';
25
25
  export const DEFAULT_BASE_URL = 'https://phantom.codes/v1';
26
- export const VERSION = '0.4.1';
26
+ export const VERSION = '0.4.3';
27
27
  // ── errors ───────────────────────────────────────────────────────────────────
28
28
  export class PhantomApiError extends Error {
29
29
  status;
@@ -1446,12 +1446,20 @@ function pendingPath(apiKey, env) {
1446
1446
  * money may have left the wallet and paying again is the costly mistake.
1447
1447
  */
1448
1448
  function readPending(apiKey, env) {
1449
+ const file = pendingPath(apiKey, env);
1450
+ if (!existsSync(file))
1451
+ return null;
1452
+ // A file that exists but can't be read may record a payment already sent.
1453
+ // Treating it as "nothing pending" would pay again, so stop instead.
1449
1454
  try {
1450
- return JSON.parse(readFileSync(pendingPath(apiKey, env), 'utf-8'));
1455
+ const p = JSON.parse(readFileSync(file, 'utf-8'));
1456
+ if (p && typeof p === 'object' && typeof p.payment_id === 'string')
1457
+ return p;
1451
1458
  }
1452
1459
  catch {
1453
- return null;
1460
+ /* falls through */
1454
1461
  }
1462
+ die(`The pending payment record at ${file} is unreadable, so pai won't pay again in case it was already sent. Check the wallet's history, then delete the file.`, 'pending_corrupt');
1455
1463
  }
1456
1464
  /** Codes that mean Phantom AI reported the payment dead, so nothing more will be credited. */
1457
1465
  const PAYMENT_DEAD = new Set(['payment_expired', 'payment_failed', 'payment_refunded']);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connortessaro/pai",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Keys, money and subagents for AI agents: Phantom AI keys and child keys, budgets and plans, model routing, an agent wallet, and signed receipts. CLI, MCP server, and a skill for pi, Claude Code, Codex and Cursor.",
5
5
  "keywords": [
6
6
  "phantom",