@tempoxyz/patron 0.0.16 → 0.0.18

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.
@@ -0,0 +1,43 @@
1
+ import { createRequire as __patronCreateRequire } from 'node:module'
2
+ const require = __patronCreateRequire(import.meta.url)
3
+
4
+ // src/refill-process.ts
5
+ import { spawn } from "node:child_process";
6
+ function startRefill(script = process.argv[1]) {
7
+ try {
8
+ if (!script) return;
9
+ const child = spawn(process.execPath, [...process.execArgv, script, "refill"], {
10
+ detached: true,
11
+ env: process.env,
12
+ stdio: "ignore"
13
+ });
14
+ child.on("error", () => void 0);
15
+ child.unref();
16
+ } catch {
17
+ }
18
+ }
19
+ function startPayment(payload, script = process.argv[1]) {
20
+ return new Promise((resolve) => {
21
+ try {
22
+ if (!script) return resolve(false);
23
+ const child = spawn(process.execPath, [...process.execArgv, script, "pay"], {
24
+ detached: true,
25
+ env: process.env,
26
+ stdio: ["pipe", "ignore", "ignore"]
27
+ });
28
+ child.on("error", () => resolve(false));
29
+ child.stdin.on("error", () => resolve(false));
30
+ child.stdin.end(payload, () => {
31
+ child.unref();
32
+ resolve(true);
33
+ });
34
+ } catch {
35
+ resolve(false);
36
+ }
37
+ });
38
+ }
39
+
40
+ export {
41
+ startRefill,
42
+ startPayment
43
+ };
@@ -0,0 +1,48 @@
1
+ import { createRequire as __patronCreateRequire } from 'node:module'
2
+ const require = __patronCreateRequire(import.meta.url)
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
+ }) : x)(function(x) {
12
+ if (typeof require !== "undefined") return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
15
+ var __commonJS = (cb, mod) => function __require2() {
16
+ try {
17
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
+ } catch (e) {
19
+ throw mod = 0, e;
20
+ }
21
+ };
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
+ // If the importer is in node compatibility mode or this is not an ESM
36
+ // file that has been converted to a CommonJS file using a Babel-
37
+ // compatible transform (i.e. "__esModule" has not been set), then set
38
+ // "default" to the CommonJS "module.exports" for node compatibility.
39
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
+ mod
41
+ ));
42
+
43
+ export {
44
+ __require,
45
+ __commonJS,
46
+ __export,
47
+ __toESM
48
+ };
@@ -1,44 +1,5 @@
1
1
  import { createRequire as __patronCreateRequire } from 'node:module'
2
2
  const require = __patronCreateRequire(import.meta.url)
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
- }) : x)(function(x) {
12
- if (typeof require !== "undefined") return require.apply(this, arguments);
13
- throw Error('Dynamic require of "' + x + '" is not supported');
14
- });
15
- var __commonJS = (cb, mod) => function __require2() {
16
- try {
17
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
- } catch (e) {
19
- throw mod = 0, e;
20
- }
21
- };
22
- var __export = (target, all) => {
23
- for (var name in all)
24
- __defProp(target, name, { get: all[name], enumerable: true });
25
- };
26
- var __copyProps = (to, from, except, desc) => {
27
- if (from && typeof from === "object" || typeof from === "function") {
28
- for (let key of __getOwnPropNames(from))
29
- if (!__hasOwnProp.call(to, key) && key !== except)
30
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
- }
32
- return to;
33
- };
34
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
- // If the importer is in node compatibility mode or this is not an ESM
36
- // file that has been converted to a CommonJS file using a Babel-
37
- // compatible transform (i.e. "__esModule" has not been set), then set
38
- // "default" to the CommonJS "module.exports" for node compatibility.
39
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
- mod
41
- ));
42
3
 
43
4
  // src/state.ts
44
5
  import {
@@ -232,10 +193,6 @@ async function updateUsage(home, update, now = /* @__PURE__ */ new Date()) {
232
193
  }
233
194
 
234
195
  export {
235
- __require,
236
- __commonJS,
237
- __export,
238
- __toESM,
239
196
  withLock,
240
197
  tryLock,
241
198
  AGENT_IDS,
@@ -0,0 +1,114 @@
1
+ import { createRequire as __patronCreateRequire } from 'node:module'
2
+ const require = __patronCreateRequire(import.meta.url)
3
+ import {
4
+ isExcludedByDefault,
5
+ normalizePayee
6
+ } from "./chunk-CF4LJZLC.js";
7
+
8
+ // src/hook-input.ts
9
+ var HOOK_TIMEOUT_MS = 2e3;
10
+ var MAX_DOMAINS_PER_HOOK = 10;
11
+ var MAX_DEPTH = 6;
12
+ var MAX_URLS = 50;
13
+ var FETCH_TOOLS = /* @__PURE__ */ new Set(["WebFetch", "read_web_page"]);
14
+ var SEARCH_TOOLS = /* @__PURE__ */ new Set(["WebSearch", "web_search"]);
15
+ function hookUrls(payload) {
16
+ if (!isRecord(payload) || typeof payload.tool_name !== "string") return [];
17
+ const tool = payload.tool_name;
18
+ const response = "tool_response" in payload ? payload.tool_response : jsonValue(payload.tool_output);
19
+ if (FETCH_TOOLS.has(tool)) {
20
+ if (!succeeded(response)) return [];
21
+ const input = payload.tool_input;
22
+ if (isRecord(input) && typeof input.url === "string") return [input.url];
23
+ const urls2 = [];
24
+ collectUrls(response, urls2, 0);
25
+ return urls2.slice(0, 1);
26
+ }
27
+ if (!SEARCH_TOOLS.has(tool)) return [];
28
+ const urls = [];
29
+ collectUrls(response, urls, 0);
30
+ if (urls.length === 0 && tool === "web_search") collectTextUrls(response, urls, 0);
31
+ return urls;
32
+ }
33
+ function hookDomains(payload) {
34
+ const domains = [];
35
+ for (const url of hookUrls(payload)) {
36
+ const domain = payableDomain(url);
37
+ if (domain && !domains.includes(domain)) domains.push(domain);
38
+ if (domains.length >= MAX_DOMAINS_PER_HOOK) break;
39
+ }
40
+ return domains;
41
+ }
42
+ function payableDomain(url) {
43
+ return isExcludedByDefault(url) ? null : normalizePayee(url);
44
+ }
45
+ function succeeded(response) {
46
+ if (!isRecord(response)) return true;
47
+ const status = response.code ?? response.status ?? response.statusCode;
48
+ return typeof status !== "number" || status >= 200 && status < 300;
49
+ }
50
+ function turnEnd(payload) {
51
+ if (!isRecord(payload)) return void 0;
52
+ if (payload.hook_event_name === "Stop" && typeof payload.turn_id === "string" && typeof payload.transcript_path === "string")
53
+ return { transcriptPath: payload.transcript_path };
54
+ if (payload.type === "agent-turn-complete" && typeof payload["thread-id"] === "string")
55
+ return { codexThreadId: payload["thread-id"] };
56
+ return void 0;
57
+ }
58
+ function isCursorPayload(payload) {
59
+ return isRecord(payload) && typeof payload.cursor_version === "string";
60
+ }
61
+ function parseHookInput(raw) {
62
+ try {
63
+ return JSON.parse(raw);
64
+ } catch {
65
+ return void 0;
66
+ }
67
+ }
68
+ function jsonValue(value) {
69
+ if (typeof value !== "string") return value;
70
+ try {
71
+ return JSON.parse(value);
72
+ } catch {
73
+ return value;
74
+ }
75
+ }
76
+ function collectUrls(value, urls, depth) {
77
+ if (depth > MAX_DEPTH || urls.length >= MAX_URLS) return;
78
+ if (Array.isArray(value)) {
79
+ for (const item of value) collectUrls(item, urls, depth + 1);
80
+ return;
81
+ }
82
+ if (!isRecord(value)) return;
83
+ for (const [key, item] of Object.entries(value)) {
84
+ if (key === "url" && typeof item === "string") urls.push(item);
85
+ else collectUrls(item, urls, depth + 1);
86
+ }
87
+ }
88
+ function collectTextUrls(value, urls, depth) {
89
+ if (depth > MAX_DEPTH || urls.length >= MAX_URLS) return;
90
+ if (typeof value === "string") {
91
+ for (const match of value.matchAll(/https?:\/\/[^\s"'<>()[\]`]+/g)) {
92
+ if (urls.length >= MAX_URLS) return;
93
+ urls.push(match[0].replace(/[.,;:!?]+$/, ""));
94
+ }
95
+ return;
96
+ }
97
+ if (Array.isArray(value))
98
+ for (const item of value) collectTextUrls(item, urls, depth + 1);
99
+ else if (isRecord(value))
100
+ for (const item of Object.values(value)) collectTextUrls(item, urls, depth + 1);
101
+ }
102
+ function isRecord(value) {
103
+ return typeof value === "object" && value !== null && !Array.isArray(value);
104
+ }
105
+
106
+ export {
107
+ HOOK_TIMEOUT_MS,
108
+ MAX_DOMAINS_PER_HOOK,
109
+ hookDomains,
110
+ payableDomain,
111
+ turnEnd,
112
+ isCursorPayload,
113
+ parseHookInput
114
+ };