@tempoxyz/patron 0.0.24 → 0.0.26

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/bin.js CHANGED
@@ -4,14 +4,14 @@ const require = __patronCreateRequire(import.meta.url)
4
4
 
5
5
  // src/bin.ts
6
6
  if (process.argv[2] === "hook") {
7
- const { runHookProcess } = await import("./chunks/hook-process-QIK6YAOS.js");
7
+ const { runHookProcess } = await import("./chunks/hook-process-ZPEWRFL2.js");
8
8
  await runHookProcess().catch(() => void 0);
9
9
  process.exit(0);
10
10
  } else if (process.argv[2] === "pay") {
11
- const { runPayProcess } = await import("./chunks/hook-process-QIK6YAOS.js");
11
+ const { runPayProcess } = await import("./chunks/hook-process-ZPEWRFL2.js");
12
12
  await runPayProcess().catch(() => void 0);
13
13
  process.exit(0);
14
14
  } else {
15
- const { run } = await import("./chunks/-CTLNBCDF.js");
15
+ const { run } = await import("./chunks/-WOZ4DM2Y.js");
16
16
  process.exitCode = await run(process.argv.slice(2));
17
17
  }
@@ -92,6 +92,13 @@ export const description = 'Patron: pays $0.001 to each site Amp reads with read
92
92
  const COMMAND = ${JSON.stringify(command)}
93
93
  const TOOLS = new Set(${JSON.stringify(AMP_WEB_TOOLS)})
94
94
 
95
+ /** Length of a tool's output; 0 for none or blank text. */
96
+ function size(output: unknown): number {
97
+ if (output === undefined || output === null) return 0
98
+ const text = typeof output === 'string' ? output : JSON.stringify(output)
99
+ return text.trim().length
100
+ }
101
+
95
102
  export default function (amp: PluginAPI) {
96
103
  amp.on('tool.result', (event) => {
97
104
  if (event.status !== 'done' || !TOOLS.has(event.tool)) return
@@ -104,7 +111,8 @@ export default function (amp: PluginAPI) {
104
111
  hook_event_name: 'tool.result',
105
112
  tool_input: event.input,
106
113
  tool_name: event.tool,
107
- tool_response: event.tool === 'web_search' ? event.output : undefined,
114
+ // read_web_page sends only the page's length, so an empty page pays nothing.
115
+ tool_response: event.tool === 'web_search' ? event.output : { bytes: size(event.output) },
108
116
  }),
109
117
  )
110
118
  child.unref()
@@ -692,10 +700,10 @@ async function linkRefillFailedAt(home) {
692
700
  var REFILL_LOCK_STALE_MS = 5 * 60 * 1e3;
693
701
  var defaultOpenWallet = async (settings, config, issuer, maxUnits) => {
694
702
  if (config.wallet === "link") {
695
- const { openLinkWallet } = await import("./wallet-7M2LEO4J.js");
703
+ const { openLinkWallet } = await import("./wallet-IDSQUCB5.js");
696
704
  return openLinkWallet(config, maxUnits);
697
705
  }
698
- const { openWallet } = await import("./wallet-7M2LEO4J.js");
706
+ const { openWallet } = await import("./wallet-IDSQUCB5.js");
699
707
  return openWallet(settings, config.wallet, issuer, maxUnits);
700
708
  };
701
709
  async function buyWithinBudget(settings, config, wanted, openWallet = defaultOpenWallet) {
@@ -1064,7 +1072,7 @@ async function tempoSignIn(deps, budgetUnits, issuer) {
1064
1072
  deps,
1065
1073
  deps.settings.privateKey ? "Using PATRON_PRIVATE_KEY" : "Signing in with Tempo Wallet"
1066
1074
  );
1067
- const { signIn } = await import("./wallet-7M2LEO4J.js");
1075
+ const { signIn } = await import("./wallet-IDSQUCB5.js");
1068
1076
  const account = await signIn(deps.settings, {
1069
1077
  budgetUnits,
1070
1078
  issuer,
@@ -1178,7 +1186,7 @@ async function changeBudget(deps, input) {
1178
1186
  } else budget = await askBudget(deps, config.monthlyBudgetUsd);
1179
1187
  if (config.wallet === "tempo" && budget > config.monthlyBudgetUsd) {
1180
1188
  step(deps, "Approve the new spending limit in Tempo Wallet");
1181
- const { authorizeBudget } = await import("./wallet-7M2LEO4J.js");
1189
+ const { authorizeBudget } = await import("./wallet-IDSQUCB5.js");
1182
1190
  const issuer = await loadIssuer(settings.home, settings.gatewayUrl, {
1183
1191
  fetch: deps.fetch
1184
1192
  });
@@ -1294,7 +1302,7 @@ async function setName(deps, name) {
1294
1302
  const issuer = await loadIssuer(settings.home, settings.gatewayUrl, {
1295
1303
  fetch: deps.fetch
1296
1304
  });
1297
- const open = deps.openWallet ?? (async (s, c, i, max) => (await import("./wallet-7M2LEO4J.js")).openWallet(s, c.wallet, i, max));
1305
+ const open = deps.openWallet ?? (async (s, c, i, max) => (await import("./wallet-IDSQUCB5.js")).openWallet(s, c.wallet, i, max));
1298
1306
  const wallet = await open(settings, config, issuer, 0n);
1299
1307
  await setProfile(settings.gatewayUrl, wallet, name, deps.fetch);
1300
1308
  await writeConfig(settings.home, { ...config, name });
@@ -46,7 +46,14 @@ function payableDomain(url) {
46
46
  function succeeded(response) {
47
47
  if (!isRecord(response)) return true;
48
48
  const status = response.code ?? response.status ?? response.statusCode;
49
- return typeof status !== "number" || status >= 200 && status < 300;
49
+ if (typeof status === "number" && (status < 200 || status >= 300 || status === 204))
50
+ return false;
51
+ if (response.bytes === 0) return false;
52
+ for (const field of ["markdown", "content"]) {
53
+ const body = response[field];
54
+ if (typeof body === "string" && body.trim() === "") return false;
55
+ }
56
+ return true;
50
57
  }
51
58
  function turnEnd(payload) {
52
59
  if (!isRecord(payload)) return void 0;
@@ -8,7 +8,7 @@ import {
8
8
  parseHookInput,
9
9
  payableDomain,
10
10
  turnEnd
11
- } from "./chunk-SIIFXQ6S.js";
11
+ } from "./chunk-HVTTV2A5.js";
12
12
  import {
13
13
  FileTokenStore,
14
14
  codexHome,
@@ -7,7 +7,7 @@ import {
7
7
  isCursorPayload,
8
8
  parseHookInput,
9
9
  turnEnd
10
- } from "./chunk-SIIFXQ6S.js";
10
+ } from "./chunk-HVTTV2A5.js";
11
11
  import {
12
12
  startDrain,
13
13
  startRefill
@@ -202,7 +202,7 @@ async function runPayProcess() {
202
202
  }
203
203
  async function payEvent(event, settings, refill, timeoutMs) {
204
204
  if (timeoutMs <= 0) return;
205
- const { runHook } = await import("./hook-RJN6WCIT.js");
205
+ const { runHook } = await import("./hook-OZRD6I6F.js");
206
206
  await runHook(
207
207
  {
208
208
  readInput: async () => event.raw,
@@ -36,7 +36,7 @@ var BUDGET_PERIOD_SECONDS = 30 * 24 * 60 * 60;
36
36
  async function signIn(settings, options) {
37
37
  if (settings.privateKey)
38
38
  return { address: privateKeyToAccount(settings.privateKey).address, wallet: "key" };
39
- const provider = tempoProvider(settings, options.issuer.chainId, options.output);
39
+ const provider = tempoProvider(settings, options.issuer, options.output);
40
40
  await Store.waitForHydration(provider.store);
41
41
  const result = await provider.request({
42
42
  method: "wallet_connect",
@@ -57,7 +57,7 @@ async function signIn(settings, options) {
57
57
  }
58
58
  async function authorizeBudget(settings, options) {
59
59
  if (settings.privateKey) return;
60
- const provider = tempoProvider(settings, options.issuer.chainId, options.output);
60
+ const provider = tempoProvider(settings, options.issuer, options.output);
61
61
  await Store.waitForHydration(provider.store);
62
62
  await provider.request({
63
63
  method: "wallet_authorizeAccessKey",
@@ -89,7 +89,7 @@ async function openWallet(settings, wallet, issuer, maxUnits, output = process.s
89
89
  signMessage: (message) => account.signMessage({ message })
90
90
  };
91
91
  }
92
- const provider = tempoProvider(settings, issuer.chainId, output);
92
+ const provider = tempoProvider(settings, issuer, output);
93
93
  await Store.waitForHydration(provider.store);
94
94
  const [address] = await provider.request({ method: "eth_accounts" });
95
95
  if (!address)
@@ -142,8 +142,9 @@ function budgetLimit(budgetUnits, currency) {
142
142
  token: currency
143
143
  };
144
144
  }
145
- function tempoProvider(settings, chainId, output) {
146
- const chain = chainId === tempoModerato.id ? tempoModerato : tempo;
145
+ function tempoProvider(settings, issuer, output) {
146
+ const base = issuer.chainId === tempoModerato.id ? tempoModerato : tempo;
147
+ const chain = base.extend({ feeToken: issuer.currency });
147
148
  return CliProvider.create({
148
149
  chains: [chain],
149
150
  mpp: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempoxyz/patron",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "description": "Pay the websites your AI agents read, privately",
5
5
  "type": "module",
6
6
  "bin": {