@tempoxyz/patron 0.0.31 → 0.0.33

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.
@@ -3,7 +3,7 @@ const require = __patronCreateRequire(import.meta.url)
3
3
  import {
4
4
  isExcludedByDefault,
5
5
  normalizePayee
6
- } from "./chunk-JTPFWITF.js";
6
+ } from "./chunk-4FPS3A57.js";
7
7
 
8
8
  // src/hook-input.ts
9
9
  var HOOK_TIMEOUT_MS = 2e3;
@@ -6,7 +6,7 @@ import {
6
6
  statePaths,
7
7
  withLock,
8
8
  writePrivateFile
9
- } from "./chunk-JTPFWITF.js";
9
+ } from "./chunk-4FPS3A57.js";
10
10
 
11
11
  // src/refill-process.ts
12
12
  import { spawn } from "node:child_process";
@@ -21,7 +21,9 @@ function startRefill(options = {}, script = process.argv[1]) {
21
21
  const child = spawn(command, args, {
22
22
  detached: true,
23
23
  env: process.env,
24
- stdio: "ignore"
24
+ stdio: "ignore",
25
+ // On Windows a detached cmd has no console, so its npx child would open a visible one.
26
+ windowsHide: true
25
27
  });
26
28
  child.on("error", () => void 0);
27
29
  child.unref();
@@ -151,6 +153,7 @@ function claimGateway(home, now, random = Math.random, want = true) {
151
153
  }
152
154
  var defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
153
155
  var RECHECK_MS = 6e4;
156
+ var CANCEL_CHECK_MS = 2e3;
154
157
  async function gatewayTurn(home, fn, options = {}) {
155
158
  const sleep = options.sleep ?? defaultSleep;
156
159
  let waited = 0;
@@ -166,9 +169,14 @@ async function gatewayTurn(home, fn, options = {}) {
166
169
  }
167
170
  if (waited + claim > (options.maxWaitMs ?? Number.POSITIVE_INFINITY)) return void 0;
168
171
  if (waited === 0) options.onWait?.(claim);
169
- const ms = claim + 1e3;
170
- await sleep(ms);
171
- waited += ms;
172
+ let remaining = claim + 1e3;
173
+ while (remaining > 0) {
174
+ if (options.cancelled?.()) return void 0;
175
+ const step = Math.min(remaining, CANCEL_CHECK_MS);
176
+ await sleep(step);
177
+ waited += step;
178
+ remaining -= step;
179
+ }
172
180
  }
173
181
  }
174
182
  async function awaitRedemptions(home, leaseMs, options = {}) {
@@ -0,0 +1,2 @@
1
+ import { createRequire as __patronCreateRequire } from 'node:module'
2
+ const require = __patronCreateRequire(import.meta.url)
@@ -1,24 +1,24 @@
1
1
  import { createRequire as __patronCreateRequire } from 'node:module'
2
2
  const require = __patronCreateRequire(import.meta.url)
3
3
  import {
4
+ ISSUER_NAME,
4
5
  IssueResponse,
5
6
  IssuerInfo,
6
- RedeemResponse
7
- } from "./chunk-GBZCXMDZ.js";
8
- import {
9
- ISSUER_NAME,
10
7
  MAX_TOKENS_PER_PURCHASE,
11
8
  PACK_SIZE,
9
+ RedeemResponse,
12
10
  TOKEN_PRICE_UNITS,
13
11
  TOKEN_TYPE,
14
12
  ensureHome,
15
13
  fromBase64Url,
14
+ parseErrorCode,
16
15
  readJson,
16
+ routeUrl,
17
17
  statePaths,
18
18
  toBase64Url,
19
19
  withLock,
20
20
  writePrivateFile
21
- } from "./chunk-JTPFWITF.js";
21
+ } from "./chunk-4FPS3A57.js";
22
22
  import {
23
23
  __commonJS,
24
24
  __export,
@@ -14942,9 +14942,30 @@ async function sha256(data) {
14942
14942
  return new Uint8Array(await crypto.subtle.digest("SHA-256", data.slice()));
14943
14943
  }
14944
14944
 
14945
+ // ../client/src/issuer.ts
14946
+ var ISSUER_TTL_MS = 60 * 60 * 1e3;
14947
+
14948
+ // ../client/src/spacing.ts
14949
+ var REDEEM_HOLD_MIN_MS = 2 * 6e4;
14950
+ var REDEEM_HOLD_SPREAD_MS = 8 * 6e4;
14951
+ var GATEWAY_QUIET_MS = 2 * 6e4;
14952
+ var GATEWAY_WANT_MS = 15 * 6e4;
14953
+ var GATEWAY_LEASE_MS = 15 * 6e4;
14954
+ var REDEEM_LEASE_MS = 2 * 6e4;
14955
+
14945
14956
  // ../client/src/index.ts
14957
+ var RelayError = class extends Error {
14958
+ status;
14959
+ code;
14960
+ constructor(status, code) {
14961
+ super(`relay request failed: ${status}`);
14962
+ this.name = "RelayError";
14963
+ this.status = status;
14964
+ this.code = code;
14965
+ }
14966
+ };
14946
14967
  async function getIssuer(gatewayUrl, fetchFn = fetch) {
14947
- const response = await fetchFn(new URL("/v1/issuer", gatewayUrl));
14968
+ const response = await fetchFn(routeUrl("issuer", gatewayUrl));
14948
14969
  if (!response.ok) throw new Error(`issuer request failed: ${response.status}`);
14949
14970
  return IssuerInfo.parse(await response.json());
14950
14971
  }
@@ -14954,7 +14975,7 @@ async function buyTokens(options) {
14954
14975
  throw new Error("count must be a positive integer");
14955
14976
  const issuer = options.issuer ?? await getIssuer(gatewayUrl);
14956
14977
  const pending = await createTokenRequests(issuer.publicKey, count);
14957
- const response = await options.fetch(new URL("/v1/tokens", gatewayUrl), {
14978
+ const response = await options.fetch(routeUrl("tokens", gatewayUrl), {
14958
14979
  method: "POST",
14959
14980
  headers: { "content-type": "application/json" },
14960
14981
  body: JSON.stringify({ blindedRequests: pending.map((token) => token.request) })
@@ -14983,13 +15004,23 @@ async function redeem(options) {
14983
15004
  ...init,
14984
15005
  credentials: "omit"
14985
15006
  });
14986
- if (!outer.ok) throw new Error(`relay request failed: ${outer.status}`);
15007
+ if (!outer.ok) throw new RelayError(outer.status, await refusalCode(outer));
14987
15008
  const inner = await context.decapsulateResponse(outer);
14988
15009
  return RedeemResponse.parse(await inner.json());
14989
15010
  }
15011
+ async function refusalCode(response) {
15012
+ const text = await response.text().catch(() => "");
15013
+ let value = text.trim();
15014
+ try {
15015
+ const json = JSON.parse(text);
15016
+ if (typeof json === "object" && json !== null && "error" in json) value = json.error;
15017
+ } catch {
15018
+ }
15019
+ return parseErrorCode(value, response.status);
15020
+ }
14990
15021
 
14991
15022
  // src/budget.ts
14992
- var LINK_TOKEN_STEP = 10;
15023
+ var LINK_TOKEN_STEP2 = 10;
14993
15024
  var REFILL_THRESHOLD = 400;
14994
15025
  var STARTER_TOKENS = 100;
14995
15026
  function budgetTokens(monthlyBudgetUsd) {
@@ -14999,7 +15030,7 @@ function budgetTokens(monthlyBudgetUsd) {
14999
15030
  }
15000
15031
  function purchasableTokens(config, usage, wanted) {
15001
15032
  const left = budgetTokens(config.monthlyBudgetUsd) - usage.boughtTokens;
15002
- const step = config.wallet === "link" ? LINK_TOKEN_STEP : 1;
15033
+ const step = config.wallet === "link" ? LINK_TOKEN_STEP2 : 1;
15003
15034
  const asked = Math.ceil(Math.floor(wanted) / step) * step;
15004
15035
  const count = Math.max(0, Math.min(asked, left, MAX_TOKENS_PER_PURCHASE));
15005
15036
  return count - count % step;
@@ -15269,13 +15300,13 @@ async function writeText(path, text) {
15269
15300
  }
15270
15301
 
15271
15302
  // src/issuer.ts
15272
- var ISSUER_TTL_MS = 60 * 60 * 1e3;
15303
+ var ISSUER_TTL_MS2 = 60 * 60 * 1e3;
15273
15304
  async function storedIssuer(home, gatewayUrl, now = Date.now()) {
15274
15305
  const cached = await readJson(statePaths(home).issuer).catch(() => void 0);
15275
15306
  const parsed = IssuerInfo.safeParse(cached?.issuer);
15276
15307
  if (!parsed.success || cached?.gatewayUrl !== gatewayUrl) return void 0;
15277
15308
  const at = typeof cached.at === "number" ? cached.at : Number.NEGATIVE_INFINITY;
15278
- return { issuer: parsed.data, stale: !(now - at < ISSUER_TTL_MS) };
15309
+ return { issuer: parsed.data, stale: !(now - at < ISSUER_TTL_MS2) };
15279
15310
  }
15280
15311
  async function loadIssuer(home, gatewayUrl, options = {}) {
15281
15312
  const now = options.now ?? Date.now();
@@ -15397,7 +15428,7 @@ var FileTokenStore = class {
15397
15428
  export {
15398
15429
  buyTokens,
15399
15430
  redeem,
15400
- LINK_TOKEN_STEP,
15431
+ LINK_TOKEN_STEP2 as LINK_TOKEN_STEP,
15401
15432
  STARTER_TOKENS,
15402
15433
  budgetTokens,
15403
15434
  purchasableTokens,
@@ -8,7 +8,7 @@ import {
8
8
  parseHookInput,
9
9
  payableDomain,
10
10
  turnEnd
11
- } from "./chunk-6G6SAUGB.js";
11
+ } from "./chunk-G7QDLLRS.js";
12
12
  import {
13
13
  FileTokenStore,
14
14
  codexHome,
@@ -16,11 +16,11 @@ import {
16
16
  redeem,
17
17
  refillSize,
18
18
  storedIssuer
19
- } from "./chunk-AN64RW3X.js";
19
+ } from "./chunk-U536WCJ4.js";
20
20
  import {
21
21
  settingsFor
22
22
  } from "./chunk-NDBTADXZ.js";
23
- import "./chunk-GBZCXMDZ.js";
23
+ import "./chunk-SSV6C6E5.js";
24
24
  import {
25
25
  clampTokensPerPage,
26
26
  readConfig,
@@ -28,7 +28,7 @@ import {
28
28
  updateUsage,
29
29
  withLock,
30
30
  writePrivateFile
31
- } from "./chunk-JTPFWITF.js";
31
+ } from "./chunk-4FPS3A57.js";
32
32
  import "./chunk-GTMLTZRN.js";
33
33
 
34
34
  // src/hook.ts
@@ -7,19 +7,19 @@ import {
7
7
  isCursorPayload,
8
8
  parseHookInput,
9
9
  turnEnd
10
- } from "./chunk-6G6SAUGB.js";
10
+ } from "./chunk-G7QDLLRS.js";
11
11
  import {
12
12
  claimRedemptions,
13
13
  redemptionWait,
14
14
  startDrain,
15
15
  startRefill
16
- } from "./chunk-IIB6TI3U.js";
16
+ } from "./chunk-H2MOKUUK.js";
17
17
  import {
18
18
  resolveSettings
19
19
  } from "./chunk-NDBTADXZ.js";
20
20
  import {
21
21
  tryLock
22
- } from "./chunk-JTPFWITF.js";
22
+ } from "./chunk-4FPS3A57.js";
23
23
  import "./chunk-GTMLTZRN.js";
24
24
 
25
25
  // src/hook-process.ts
@@ -248,7 +248,7 @@ async function waitForHold(home) {
248
248
  }
249
249
  async function payEvent(event, settings, refill, timeoutMs) {
250
250
  if (timeoutMs <= 0) return;
251
- const { runHook } = await import("./hook-6DQ3RLVH.js");
251
+ const { runHook } = await import("./hook-XH5QRR5O.js");
252
252
  await runHook(
253
253
  {
254
254
  readInput: async () => event.raw,
@@ -1,10 +1,10 @@
1
1
  import { createRequire as __patronCreateRequire } from 'node:module'
2
2
  const require = __patronCreateRequire(import.meta.url)
3
- import "./chunk-GBZCXMDZ.js";
3
+ import "./chunk-SSV6C6E5.js";
4
4
  import {
5
5
  accessKeyLimitUnits,
6
6
  statePaths
7
- } from "./chunk-JTPFWITF.js";
7
+ } from "./chunk-4FPS3A57.js";
8
8
  import "./chunk-GTMLTZRN.js";
9
9
 
10
10
  // src/wallet.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempoxyz/patron",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "description": "Pay the websites your AI agents read, privately",
5
5
  "type": "module",
6
6
  "bin": {