@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.30

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 (273) hide show
  1. package/CHANGELOG.md +748 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +5 -0
  4. package/README.md +2190 -2
  5. package/dist/adapters.d.ts +234 -0
  6. package/dist/adapters.js +585 -0
  7. package/dist/agents.d.ts +130 -0
  8. package/dist/agents.js +308 -0
  9. package/dist/app.d.ts +7 -0
  10. package/dist/app.js +384 -0
  11. package/dist/background.d.ts +28 -0
  12. package/dist/background.js +376 -0
  13. package/dist/bound-files.d.ts +4 -0
  14. package/dist/bound-files.js +164 -0
  15. package/dist/box/record.d.ts +6 -0
  16. package/dist/box/record.js +41 -0
  17. package/dist/box/sweep.d.ts +53 -0
  18. package/dist/box/sweep.js +193 -0
  19. package/dist/box-egress.d.ts +98 -0
  20. package/dist/box-egress.js +259 -0
  21. package/dist/box-image.d.ts +98 -0
  22. package/dist/box-image.js +285 -0
  23. package/dist/box-relay-vm.d.ts +80 -0
  24. package/dist/box-relay-vm.js +389 -0
  25. package/dist/box-relay.d.ts +45 -0
  26. package/dist/box-relay.js +227 -0
  27. package/dist/boxes.d.ts +72 -0
  28. package/dist/boxes.js +189 -0
  29. package/dist/browser-cost.d.ts +41 -0
  30. package/dist/browser-cost.js +158 -0
  31. package/dist/cap.d.ts +332 -0
  32. package/dist/cap.js +992 -0
  33. package/dist/catalog.d.ts +20 -0
  34. package/dist/catalog.js +53 -0
  35. package/dist/cli.d.ts +2 -0
  36. package/dist/cli.js +167 -0
  37. package/dist/coding-tools.d.ts +35 -0
  38. package/dist/coding-tools.js +87 -0
  39. package/dist/console/THIRD-PARTY-NOTICES.txt +1721 -0
  40. package/dist/console/assets/index-34jfpIbQ.js +481 -0
  41. package/dist/console/assets/index-DUHbWcIP.css +1 -0
  42. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
  43. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
  44. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
  45. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
  46. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
  47. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
  48. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
  49. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
  50. package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
  51. package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
  52. package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
  53. package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
  54. package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
  55. package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  56. package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
  57. package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
  58. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  59. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
  60. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
  61. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
  62. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
  63. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
  64. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
  65. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
  66. package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
  67. package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
  68. package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
  69. package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
  70. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
  71. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
  72. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
  73. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
  74. package/dist/console/index.html +15 -0
  75. package/dist/content-filter.d.ts +7 -0
  76. package/dist/content-filter.js +23 -0
  77. package/dist/daytona-api.d.ts +21 -0
  78. package/dist/daytona-api.js +101 -0
  79. package/dist/decision-rows.d.ts +19 -0
  80. package/dist/decision-rows.js +123 -0
  81. package/dist/decisions.d.ts +94 -0
  82. package/dist/decisions.js +184 -0
  83. package/dist/effort-guidance.d.ts +5 -0
  84. package/dist/effort-guidance.js +14 -0
  85. package/dist/environment.d.ts +5 -0
  86. package/dist/environment.js +11 -0
  87. package/dist/errors.d.ts +74 -0
  88. package/dist/errors.js +69 -0
  89. package/dist/exa-keyless.d.ts +35 -0
  90. package/dist/exa-keyless.js +202 -0
  91. package/dist/fetch-page.d.ts +114 -0
  92. package/dist/fetch-page.js +182 -0
  93. package/dist/files.d.ts +65 -0
  94. package/dist/files.js +158 -0
  95. package/dist/grade.d.ts +93 -0
  96. package/dist/grade.js +328 -0
  97. package/dist/graph-served.d.ts +23 -0
  98. package/dist/graph-served.js +75 -0
  99. package/dist/graph-view.d.ts +102 -0
  100. package/dist/graph-view.js +219 -0
  101. package/dist/harness-app.d.ts +40 -0
  102. package/dist/harness-app.js +708 -0
  103. package/dist/harness-opencode/adapter.d.ts +45 -0
  104. package/dist/harness-opencode/adapter.js +272 -0
  105. package/dist/harness-opencode/binary.d.ts +18 -0
  106. package/dist/harness-opencode/binary.js +87 -0
  107. package/dist/harness-opencode/config.d.ts +24 -0
  108. package/dist/harness-opencode/config.js +61 -0
  109. package/dist/harness-opencode/harness.d.ts +77 -0
  110. package/dist/harness-opencode/harness.js +620 -0
  111. package/dist/harness-opencode/host/mcp.d.ts +40 -0
  112. package/dist/harness-opencode/host/mcp.js +208 -0
  113. package/dist/harness-opencode/host/policy.d.ts +71 -0
  114. package/dist/harness-opencode/host/policy.js +419 -0
  115. package/dist/harness-opencode/host/server.d.ts +55 -0
  116. package/dist/harness-opencode/host/server.js +165 -0
  117. package/dist/harness-opencode/index.d.ts +9 -0
  118. package/dist/harness-opencode/index.js +6 -0
  119. package/dist/harness-opencode/verify.d.ts +32 -0
  120. package/dist/harness-opencode/verify.js +75 -0
  121. package/dist/harness-opencode/versions.d.ts +33 -0
  122. package/dist/harness-opencode/versions.js +64 -0
  123. package/dist/harness.d.ts +56 -0
  124. package/dist/harness.js +77 -0
  125. package/dist/home-path.d.ts +27 -0
  126. package/dist/home-path.js +78 -0
  127. package/dist/host-tools.d.ts +30 -0
  128. package/dist/host-tools.js +154 -0
  129. package/dist/host.d.ts +39 -0
  130. package/dist/host.js +85 -0
  131. package/dist/hosted-search.d.ts +27 -0
  132. package/dist/hosted-search.js +133 -0
  133. package/dist/import-sources.d.ts +104 -0
  134. package/dist/import-sources.js +629 -0
  135. package/dist/import-summary.d.ts +25 -0
  136. package/dist/import-summary.js +75 -0
  137. package/dist/import-worker.d.ts +26 -0
  138. package/dist/import-worker.js +41 -0
  139. package/dist/import.d.ts +145 -0
  140. package/dist/import.js +1222 -0
  141. package/dist/index.d.ts +7 -0
  142. package/dist/index.js +6 -0
  143. package/dist/key-check.d.ts +37 -0
  144. package/dist/key-check.js +112 -0
  145. package/dist/key-refusal.d.ts +51 -0
  146. package/dist/key-refusal.js +191 -0
  147. package/dist/learn/check.d.ts +108 -0
  148. package/dist/learn/check.js +277 -0
  149. package/dist/learn/grade.d.ts +80 -0
  150. package/dist/learn/grade.js +445 -0
  151. package/dist/learn/index.d.ts +7 -0
  152. package/dist/learn/index.js +11 -0
  153. package/dist/learn/invisible.d.ts +5 -0
  154. package/dist/learn/invisible.js +42 -0
  155. package/dist/learn/notes.d.ts +59 -0
  156. package/dist/learn/notes.js +147 -0
  157. package/dist/learn/reflect.d.ts +49 -0
  158. package/dist/learn/reflect.js +213 -0
  159. package/dist/learn/secrets.d.ts +18 -0
  160. package/dist/learn/secrets.js +131 -0
  161. package/dist/learn/skills.d.ts +97 -0
  162. package/dist/learn/skills.js +271 -0
  163. package/dist/learned-workflow.d.ts +59 -0
  164. package/dist/learned-workflow.js +191 -0
  165. package/dist/learning-routes.d.ts +196 -0
  166. package/dist/learning-routes.js +609 -0
  167. package/dist/learning-run.d.ts +306 -0
  168. package/dist/learning-run.js +819 -0
  169. package/dist/learning-words.d.ts +76 -0
  170. package/dist/learning-words.js +174 -0
  171. package/dist/learning.d.ts +418 -0
  172. package/dist/learning.js +946 -0
  173. package/dist/llm.d.ts +40 -0
  174. package/dist/llm.js +37 -0
  175. package/dist/llms.txt +37 -0
  176. package/dist/mcp-servers.d.ts +118 -0
  177. package/dist/mcp-servers.js +450 -0
  178. package/dist/mcp.d.ts +51 -0
  179. package/dist/mcp.js +392 -0
  180. package/dist/model.d.ts +186 -0
  181. package/dist/model.js +485 -0
  182. package/dist/monid.d.ts +74 -0
  183. package/dist/monid.js +277 -0
  184. package/dist/openapi/agentrun-v2.openapi.json +4806 -0
  185. package/dist/openapi.d.ts +10 -0
  186. package/dist/openapi.js +1727 -0
  187. package/dist/owner.d.ts +55 -0
  188. package/dist/owner.js +222 -0
  189. package/dist/packs.d.ts +71 -0
  190. package/dist/packs.js +180 -0
  191. package/dist/page.d.ts +32 -0
  192. package/dist/page.js +133 -0
  193. package/dist/paid-calls.d.ts +50 -0
  194. package/dist/paid-calls.js +110 -0
  195. package/dist/pause.d.ts +70 -0
  196. package/dist/pause.js +97 -0
  197. package/dist/pdf-pages.d.ts +44 -0
  198. package/dist/pdf-pages.js +147 -0
  199. package/dist/place.d.ts +69 -0
  200. package/dist/place.js +137 -0
  201. package/dist/print.d.ts +20 -0
  202. package/dist/print.js +29 -0
  203. package/dist/propose.d.ts +40 -0
  204. package/dist/propose.js +112 -0
  205. package/dist/quiet-sqlite-warning.d.ts +1 -0
  206. package/dist/quiet-sqlite-warning.js +14 -0
  207. package/dist/request-start.d.ts +22 -0
  208. package/dist/request-start.js +350 -0
  209. package/dist/result.d.ts +3 -0
  210. package/dist/result.js +5 -0
  211. package/dist/rows.d.ts +46 -0
  212. package/dist/rows.js +121 -0
  213. package/dist/run-box.d.ts +186 -0
  214. package/dist/run-box.js +590 -0
  215. package/dist/run-manifest.d.ts +27 -0
  216. package/dist/run-manifest.js +60 -0
  217. package/dist/runnable.d.ts +83 -0
  218. package/dist/runnable.js +170 -0
  219. package/dist/runs.d.ts +1062 -0
  220. package/dist/runs.js +3020 -0
  221. package/dist/secret-cut.d.ts +27 -0
  222. package/dist/secret-cut.js +109 -0
  223. package/dist/secrets.d.ts +62 -0
  224. package/dist/secrets.js +158 -0
  225. package/dist/server-lock.d.ts +44 -0
  226. package/dist/server-lock.js +140 -0
  227. package/dist/server.d.ts +722 -0
  228. package/dist/server.js +2118 -0
  229. package/dist/sessions.d.ts +4 -0
  230. package/dist/sessions.js +105 -0
  231. package/dist/sign-ins.d.ts +99 -0
  232. package/dist/sign-ins.js +288 -0
  233. package/dist/skills.d.ts +43 -0
  234. package/dist/skills.js +96 -0
  235. package/dist/stats.d.ts +106 -0
  236. package/dist/stats.js +103 -0
  237. package/dist/tool-gate.d.ts +266 -0
  238. package/dist/tool-gate.js +554 -0
  239. package/dist/tool-keys.d.ts +187 -0
  240. package/dist/tool-keys.js +315 -0
  241. package/dist/tool-plane.d.ts +228 -0
  242. package/dist/tool-plane.js +400 -0
  243. package/dist/tools.d.ts +202 -0
  244. package/dist/tools.js +372 -0
  245. package/dist/trigger-secrets.d.ts +32 -0
  246. package/dist/trigger-secrets.js +143 -0
  247. package/dist/triggers.d.ts +439 -0
  248. package/dist/triggers.js +863 -0
  249. package/dist/turn-end.d.ts +24 -0
  250. package/dist/turn-end.js +15 -0
  251. package/dist/turns.d.ts +34 -0
  252. package/dist/turns.js +202 -0
  253. package/dist/uploads.d.ts +104 -0
  254. package/dist/uploads.js +474 -0
  255. package/dist/usage-lines.d.ts +26 -0
  256. package/dist/usage-lines.js +28 -0
  257. package/dist/usage.d.ts +29 -0
  258. package/dist/usage.js +58 -0
  259. package/dist/validate.d.ts +57 -0
  260. package/dist/validate.js +184 -0
  261. package/dist/web-fetch.d.ts +64 -0
  262. package/dist/web-fetch.js +262 -0
  263. package/dist/web-search.d.ts +54 -0
  264. package/dist/web-search.js +136 -0
  265. package/dist/webhooks.d.ts +189 -0
  266. package/dist/webhooks.js +503 -0
  267. package/dist/workspace-paths.d.ts +33 -0
  268. package/dist/workspace-paths.js +104 -0
  269. package/dist/workspace.d.ts +88 -0
  270. package/dist/workspace.js +369 -0
  271. package/launcher/agentrun-serve +109 -0
  272. package/package.json +100 -4
  273. package/skills/agentrun-serve/SKILL.md +128 -0
package/dist/cap.d.ts ADDED
@@ -0,0 +1,332 @@
1
+ import { type Ended } from "@parcha/agentrun-kernel";
2
+ import { type EntryLike } from "@parcha/pi-durable-agent/timeline";
3
+ import type { Api, AssistantMessage, Context, Model, Models } from "@earendil-works/pi-ai";
4
+ /** A run's cap in USD, passed to its process. */
5
+ export declare const CAP_ENV = "AGENTRUN_SERVE_MAX_COST_USD";
6
+ /** How a request the cap refused begins its error, which the server ends the run with. */
7
+ export declare const SPEND_CAP_REACHED = "spend_cap_reached";
8
+ /** How near two dollar figures are the same figure: a sum a float puts a hair past the cap (0.0028 + 0.3072 is
9
+ * 0.31000000000000005) is the cap, and fits it. A raise must be above a run's cap by more (runs.ts). */
10
+ export declare const CAP_TOLERANCE = 1e-9;
11
+ /** How far past what is left a sum may read and still fit it: a float's own tail (0.0028 + 0.3072 is 0.31000000000000005
12
+ * against a 0.31 cap), never a spend that is past the cap, by however little (a 1e-11 hair is past it). CAP_TOLERANCE
13
+ * is the other question: how near two caps are the same cap. */
14
+ export declare const FIT_TOLERANCE = 1e-12;
15
+ /** The option a request's worst case rides on from the cap to its marks (request-start.ts): what the cap held for it. A
16
+ * symbol, so no provider ever sends it. */
17
+ export declare const HELD_USD: unique symbol;
18
+ /** Records that `message` ended on an error after its response began. */
19
+ export declare const markResponseBegan: (message: AssistantMessage) => void;
20
+ /** The field of a request's end mark (REQUEST_ENDED) that says what the cap held for it, when its stream ended aborted
21
+ * or its summary failed: the request counts at that figure. Optional: an end with none (an older store, a run with no
22
+ * cap) leaves the request cut, at an unknown cost. */
23
+ export declare const HELD_FIELD = "heldUsd";
24
+ /** The field of the start mark (REQUEST_STARTED) written for a request this cap refused: it never left, and pi's error
25
+ * entry for it answers this mark, never an earlier request's. */
26
+ export declare const CAP_REFUSED_FIELD = "capRefused";
27
+ /** The option a request the cap limited rides on to its start mark (request-start.ts, as `clamp`): the output tokens it was
28
+ * limited to, what was left of the cap for it, and the cap, so a reply cut short there says so. */
29
+ export declare const CLAMP: unique symbol;
30
+ /** The tokens a limited request keeps for its answer (pi-ai's MIN_ANSWER_TOKENS): a request is refused, never sent, when
31
+ * what is left of its cap cannot buy them (or what it asked for, when it asked for fewer). */
32
+ export declare const ANSWER_TOKENS_LEAST = 1024;
33
+ /** The least thinking budget Anthropic takes: a request that thinks on an API whose thinking takes a budget keeps it
34
+ * beside its answer, the budget squeezed to it at the least. */
35
+ export declare const THINKING_BUDGET_LEAST = 1024;
36
+ /** The output tokens a request the person stopped counts beyond what it streamed: what the provider may have produced after
37
+ * the last word read, before it saw the stop. A stopped request counts its input, each byte it streamed as a token, and
38
+ * these, never more than it was held at (stoppedFigure). A stated bound, as NATIVE_SEARCH_ALLOWANCE_TOKENS is. */
39
+ export declare const STOP_ALLOWANCE_TOKENS = 1024;
40
+ /** The option a request's stopped figure rides on to its end mark (request-start.ts): what it counts at, given the answer
41
+ * it streamed, when it is stopped before its end. A symbol, so no provider ever sends it. */
42
+ export declare const STOPPED_USD: unique symbol;
43
+ /** What a model answer streamed, in bytes: its text, its thinking, and each tool call's name and arguments as JSON. Each
44
+ * byte counts as a token (a byte-level tokenizer never makes a token of less than one byte), as inputBound counts input. */
45
+ export declare function streamedBytes(message: {
46
+ content?: unknown;
47
+ } | undefined): number;
48
+ /** What of a model answer's reasoning streamed, in bytes (streamedBytes' unit): its thinking blocks. */
49
+ export declare function reasoningBytes(message: {
50
+ content?: unknown;
51
+ } | undefined): number;
52
+ /** A request's figure if it is stopped before its end, given the answer it had streamed. */
53
+ export type Stopped = (message: {
54
+ content?: unknown;
55
+ }) => number;
56
+ /** What a request stopped before its end counts at: its input and `streamed` tokens plus STOP_ALLOWANCE_TOKENS of output,
57
+ * at most the output it was sent with (`limit`), at `cost`'s price; never more than `worst`, what it was held at. */
58
+ export declare const stoppedFigure: (cost: (output: number) => number, limit: number, worst: number, streamed: number) => number;
59
+ /** What a stopped request counts at, having streamed `streamed` tokens: those and STOP_ALLOWANCE_TOKENS of output, at
60
+ * most the output it was sent with (`limit`), at `cost`'s price; bookRequest keeps it within the hold. */
61
+ export declare const stoppedPriceOf: (cost: (output: number) => number, limit: number) => (streamed: number) => number;
62
+ /** The option a request's attempts ride on to its marks (request-start.ts): each HTTP attempt pi-ai made for it, as the
63
+ * fetch the cap gave it saw them. A symbol, so no provider ever sends it. */
64
+ export declare const ATTEMPTS: unique symbol;
65
+ /** One attempt of a request: the status it was answered with, or the code its fetch was refused with, `aborted` when the
66
+ * request's own signal had fired by then (the run stopped it: no attempt lost to the provider). */
67
+ export type Attempt = {
68
+ status: number;
69
+ } | {
70
+ code: string | undefined;
71
+ aborted?: true;
72
+ };
73
+ /** The APIs whose requests the cap cannot watch through a fetch, each with why: it gives them no recording fetch, and
74
+ * a request on one that fails before any event books its hold (piEnded). The one table both read. */
75
+ export declare const UNWATCHED_APIS: Readonly<Record<string, string>>;
76
+ /** A fetch that does what `inner` does (globalThis.fetch by default) and records each attempt in `attempts`. An attempt
77
+ * is `aborted` only when the request's own signal (`stop`, the run's) had fired: the SDKs hand fetch a signal of their
78
+ * own, which they also abort on their own timeout, and an attempt that timed out left, so it is lost, never a stop. */
79
+ export declare function recordingFetch(attempts: Attempt[], inner?: typeof fetch, stop?: AbortSignal): typeof fetch;
80
+ /** Whether one attempt was lost: refused after it could have left (any code but a connect one), a gateway's timeout, or
81
+ * an answer that was not the request's last attempt (pi-ai tried again after it). That last reading assumes every fetch
82
+ * through the recorder is a model attempt. pi-ai's Anthropic workload identity federation (anthropic-messages.js,
83
+ * getAnthropicFederation) exchanges its token through the same fetch, so under it "a 2xx that was not the last" would
84
+ * read every answer as lost. It arms only when no API key or auth header resolves, and serve always gives pi-ai an API
85
+ * key, so it never arms here. */
86
+ export declare const attemptLost: (a: Attempt, last: boolean) => boolean;
87
+ /** Whether any attempt of a request was lost (attemptLost), its last counted as the last; one the run's own stop cut is
88
+ * none. A request lost so counts at its hold however it then ended: answered, failed or stopped. */
89
+ export declare const anyAttemptLost: (attempts: readonly Attempt[] | undefined) => boolean;
90
+ export declare function piEnded(message: Pick<AssistantMessage, "stopReason" | "usage" | "api">, began: boolean, attempts: readonly Attempt[] | undefined): Ended;
91
+ /** How pi's error for a request whose start mark could not be written begins (request-start.ts builds it from this): the
92
+ * request never left, so the entry answers none, and spentIn leaves it out by this. */
93
+ export declare const MARK_NOT_WRITTEN = "the model request was not sent: its mark could not be written";
94
+ /** pi's error for a request that left and whose end mark the store refused (request-start.ts): its cost is not recorded
95
+ * as booked, so it stays open, read at its start mark's hold, never closed by this entry at its own usage. */
96
+ export declare const END_NOT_WRITTEN = "the model request's end could not be recorded";
97
+ /** The input a request carrying claude-agent's native web search may read in beyond its body, added to its input bound
98
+ * by its adapter (adapters.ts hands it over): Claude's CLI asks for at most 8 searches a request (max_uses 8), and each
99
+ * search's results are billed as input, about 25,000 tokens a search as a working estimate. */
100
+ export declare const NATIVE_SEARCH_ALLOWANCE_TOKENS: number;
101
+ /** A tool's own request through the run's models (`completeSimple`), by its context: the label its marks carry, the
102
+ * input its hosted tool may add beyond its context (results billed as input) and the most fee it can run up, which the
103
+ * cap holds (cap.ts), and the fee its tokens do not show (its searches), read once it ended. */
104
+ export type SideRequest = {
105
+ label: string;
106
+ extraInputTokens: number;
107
+ maxFeeUsd: number;
108
+ feeUsd(): number;
109
+ };
110
+ export declare const sideRequests: WeakMap<object, SideRequest>;
111
+ /** The run's cap from its process's environment; absent for a run without one. */
112
+ export declare function capOf(env: NodeJS.ProcessEnv): number | undefined;
113
+ /** The code a cap's refusal begins with: `spend_cap_reached: `, or with a note after it, as a request it limited refuses
114
+ * in (CAP_REFUSAL_CODE, "spend_cap_reached (out of budget): "). Every reader of a refusal's text (a run's end, its
115
+ * learning, the spend read back) reads the code through this, never a bare prefix. */
116
+ export declare const CAP_REFUSAL_PREFIX: RegExp;
117
+ /** What the run's store says its model requests cost, across every conversation in it: known or not as the run's own
118
+ * timeline says (pi-durable-agent's timelineOf), read as a settled run, since the process that wrote it is gone, and
119
+ * then the full amount, never the timeline's total rounded for display. Every response, and each cost written apart
120
+ * from one (a compaction summary's; a harness request's that came in after its answer). A cost that is not a number, or
121
+ * one still pending, leaves it unknown, as the timeline says. These readings are the cap's own, on its copy of the
122
+ * entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end counts at the figure its
123
+ * end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the figure its start mark
124
+ * holds (openFigures), each the worst case the cap held for it; without that figure either stays cut, at an unknown
125
+ * cost. A paid call settled at a charge it did not say, like one a crash cut, counts at the figure its mark holds. And
126
+ * this cap's refusals are left out, as none left. Unknown is null, which a cap never reads as $0. `sides`: only the
127
+ * run's side requests (each marked with a label: a learned workflow's, a hosted search's), what a run on another
128
+ * harness spent beside its harness's own requests and its paid tools, which that harness's booking does not hold. */
129
+ export declare function spentIn(storeFile: string, { sides }?: {
130
+ sides?: boolean;
131
+ }): number | null;
132
+ /** /usage's meters for a run that ended, from its store: `tools`, each TOOL_COST's `usd`, unknown (null) when one is,
133
+ * or when a call was cut (marked, never settled: what it charged no one knows); and `tokens`, the rest of its root
134
+ * conversation as its settled timeline prices it; `browser`, the part of `tools` that is browser session time
135
+ * (browser-cost.ts), with its seconds; and `others`, the rest of `tools`, each unknown (null) apart. A mark is never a charge here (the cap's alone). Never for a live run: its process
136
+ * holds the store exclusively. */
137
+ export type Meters = {
138
+ tools: number | null;
139
+ tokens: number | null;
140
+ browser: {
141
+ usd: number | null;
142
+ seconds: number;
143
+ };
144
+ others: number | null;
145
+ };
146
+ export declare function metersIn(storeFile: string): Meters;
147
+ /** metersIn's meters, and beside them each meter's known dollars: its settled charges' figures, whether or not another of
148
+ * its charges is unknown (a hold, a call cut or never settled, is no charge here: it adds nothing). What a run of
149
+ * unknown cost is known to have spent on each (server.ts /usage). */
150
+ export declare function meterFiguresIn(storeFile: string): Meters & {
151
+ known: {
152
+ tokens: number;
153
+ browser: number;
154
+ others: number;
155
+ };
156
+ };
157
+ /** What the paid tools of `entries` (TOOL_STARTED and TOOL_COST) spent, as the cap counts it: each charge, and a call
158
+ * settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as spentIn counts it;
159
+ * null when one has no figure. The run's reported cost reads such a call unknown instead (the timeline). */
160
+ export declare function capToolSpend(entries: readonly EntryLike[]): number | null;
161
+ /** The worst case of each model request a cap admitted and whose cost is not booked yet, by its turn, for a paid tool's
162
+ * check on a harness whose booking counts a request only once its cost is in (harness-app.ts): `admitted` takes what
163
+ * the guard held, `started` gives it the turn that request leaves as (admissions run one at a time), `ended` drops it. */
164
+ export declare function holdsInFlight(): {
165
+ admitted: (usd: number | undefined) => undefined;
166
+ started: (turn: number) => undefined;
167
+ ended: (turn: number) => undefined;
168
+ total: () => number;
169
+ };
170
+ /** The run's spend as its process counts it, for a paid tool: what it has spent (`spent`; null when unknown), what its
171
+ * model requests in flight are held at, at their worst case (`held`, read once `spent` is in; absent: none apart from
172
+ * `spent`), and the charge a call adds (`add`). Set by the run's cap, on pi (capModels) and on another harness
173
+ * (harness-app.ts); none without a cap. A run is one process, so one is set per process. `now`: the whole figure read at
174
+ * once, held requests included, with no wait for a cost still coming in; another harness sets it, for the run's own
175
+ * model requests beside the harness's (capModels' `joined`). */
176
+ export type RunSpend = {
177
+ cap: number;
178
+ spent(): number | null | Promise<number | null>;
179
+ held?(): number;
180
+ add(usd: number | null): void;
181
+ now?(): number | null;
182
+ };
183
+ export declare const useSpend: (spend: RunSpend | undefined) => void;
184
+ /** What the paid calls under way are held at, together (0 when none is): the one figure every check of the run's cap
185
+ * adds to what the run has spent, a model request's (capModels, capBefore) and a paid call's (paidCall). On another
186
+ * harness the run's own model requests in flight (a learned workflow's, a hosted search's) are held here too, so the
187
+ * harness's check sees them. */
188
+ export declare const paidHolds: () => number;
189
+ /** A paid hold that outlives the paidCall that took it (a browser session's, browser-cost.ts), counted in paidHolds as a
190
+ * call's is until `drop`: its figure is `usd`, which its owner moves as charges use it. */
191
+ export declare const keepHold: (usd: number) => {
192
+ usd: number;
193
+ drop(): void;
194
+ };
195
+ /** A charge booked outside any paidCall (a browser session's, booked in the commit that bills it) joins what the run's
196
+ * process counts as spent, as a paid call's does; with no cap, nothing counts it. */
197
+ export declare const addSpend: (usd: number | null) => void;
198
+ /** The run's cap, when it has one. */
199
+ export declare const runCap: () => number | undefined;
200
+ /** What sidesSpent says: the harness's check adds it to what its booking says the run spent (harness-app.ts). */
201
+ export declare const sideSpend: () => number | null;
202
+ /** The paid call's refusal the next model request of the run whose spend is `owner` is refused with, once: undefined
203
+ * when there is none, or it is another spend's. Only a run's own guard asks (capModels for pi, harness-app.ts for the
204
+ * others), never a guard a caller builds apart. */
205
+ export declare function takePaidRefusal(owner: RunSpend | undefined): {
206
+ words: string;
207
+ figures: RefusalFigures;
208
+ } | undefined;
209
+ export declare function paidCall<T>(name: string, call: () => Promise<T>, charge: (result: T) => number | null | undefined, hold: {
210
+ usd: number;
211
+ basis: string;
212
+ }): Promise<{
213
+ refused: string;
214
+ } | {
215
+ result: T;
216
+ }>;
217
+ /** The most output tokens one request may take: the model's ceiling, else its context window. A thinking budget can
218
+ * raise a request's ceiling up to the model's, whatever maxTokens it asked for. */
219
+ export declare const ceilingTokens: (model: Pick<Model<Api>, "maxTokens" | "contextWindow">) => number;
220
+ /** A request's input tokens, bounded above: one per UTF-8 byte of what is sent (a byte-level tokenizer never takes
221
+ * fewer than one byte a token, and an image's base64 is far more bytes than its tokens), plus `overhead`, what the
222
+ * provider adds server-side that the body does not hold. The same bound on every harness. */
223
+ export declare const inputBound: (sent: string, overhead?: number) => number;
224
+ /** What pi's provider adds server-side to a request of `context`, the same table the model proxy uses, by the model's API
225
+ * kind: undefined for a kind whose additions are not known. The context does not say how the request chooses a tool,
226
+ * so the dearer choice is taken. */
227
+ export declare function piOverhead(model: Pick<Model<Api>, "api">, context: Context): number | undefined;
228
+ /** An amount in words: two decimals, or as many as it takes (up to eight) to show it whole ($0.50, $0.105, $0.0005). */
229
+ export declare function money(usd: number): string;
230
+ /** The code a cap's refusal begins with: `spend_cap_reached`, which the server ends the run with, and "out of budget",
231
+ * which pi-ai's retry (isRetryableAssistantError, which reads only an error's text) takes as final whatever digits the
232
+ * words after it hold. The words after it are the ones a person reads. */
233
+ export declare const CAP_REFUSAL_CODE = "spend_cap_reached (out of budget): ";
234
+ /** A refusal for room's figures, beside its words: what the cap counted as taken (spent, and held for requests still
235
+ * answering) and the least the refused request needs. Kept on the refusal's own start mark (`spentUsd`, `needsUsd`), so a
236
+ * run paused at its cap says them (runs.ts pending), and its cap's raise is checked against them. */
237
+ export type RefusalFigures = {
238
+ spentUsd: number;
239
+ needsUsd: number;
240
+ };
241
+ /** The words of a refusal for room (CAP_REFUSAL_CODE: what is left of the cap cannot buy the request's least), which a
242
+ * higher cap would send; undefined for any other text, a refusal no cap could fix included (an unknown spend, no price,
243
+ * no output ceiling, an input not measured: the bare `spend_cap_reached: ` code). The one reader of that difference. */
244
+ export declare const roomRefusal: (text: string | undefined) => string | undefined;
245
+ /** A model's name as the words say it: the catalog's, without a vendor's prefix ("Anthropic: Claude Sonnet 5.5" reads
246
+ * "Claude Sonnet 5.5"), else its id. */
247
+ export declare const nameOf: (model: Pick<Model<Api>, "name" | "id">) => string;
248
+ /** A least in words: rounded up to the cent, so that it is enough ($0.1024 is $0.11). */
249
+ export declare const leastMoney: (usd: number) => string;
250
+ /** The cap to raise to for a request past `cap` that needs `total` in all: a cent at least, and above the cap, never
251
+ * the cap itself, so a raise to it is one PATCH /runs/{id} takes. */
252
+ export declare const raiseTo: (cap: number, total: number) => string;
253
+ /** The least output a pi request may be limited to and still answer: the answer's 1,024 tokens, and when it thinks,
254
+ * the least budget on an API whose thinking takes one (squeezed to it), else its thinking level's budget, since its
255
+ * reasoning then shares the limit. */
256
+ export declare function leastOutput(model: Pick<Model<Api>, "api" | "reasoning">, thinking: string | undefined, budgetOf: (level: string) => number): number;
257
+ /** The cap of a run on another harness, before each of its requests: the runner's booking says what the run has spent
258
+ * (its session, across processes) and which of its requests are still in flight, each with the output limit it was
259
+ * admitted with, and the model proxy each request's input bound (`inputTokensMax`, inputBound of its body; undefined
260
+ * when the body could not be measured), the output it asks for, and the least it may be limited to. */
261
+ export interface CapGuard {
262
+ beforeRequest(request: GuardRequest): undefined | ({
263
+ refuse: string;
264
+ } & Partial<RefusalFigures>) | {
265
+ outputTokensMax: number;
266
+ };
267
+ /** The worst case a request this guard admitted is held at (its input bound, and the output limit it was admitted with
268
+ * or else its output ceiling, at the model's price): what the runner records for it, and counts it at when its own cost
269
+ * never comes in (cut short, or by a crash). */
270
+ worstOf?(request: {
271
+ inputTokensMax?: number;
272
+ outputTokensMax?: number;
273
+ }): number | undefined;
274
+ /** What a request this guard admitted counts at if its client stops it part way, having streamed `streamed` tokens (one
275
+ * a byte): its input bound and those tokens plus STOP_ALLOWANCE_TOKENS of output, at most its output limit, at the
276
+ * model's price. The runner counts it at no more than its hold. Undefined when its input was not measured. */
277
+ stoppedOf?(request: {
278
+ inputTokensMax?: number;
279
+ outputTokensMax?: number;
280
+ }, streamed: number): number | undefined;
281
+ }
282
+ export type GuardRequest = {
283
+ spentUsd: number | null;
284
+ inFlight: readonly {
285
+ inputTokensMax?: number;
286
+ outputTokensMax?: number;
287
+ }[];
288
+ inputTokensMax?: number;
289
+ outputTokensAsked?: number;
290
+ outputTokensLeast?: number;
291
+ };
292
+ /** A run on another harness: before each request, what the run has spent, plus the worst case of each request still in
293
+ * flight (at the output limit it was admitted with), must leave room for this request at its least output (1,024 tokens,
294
+ * or what its body says it needs to think and answer; what it asks for when that is fewer), else the request is refused
295
+ * with spend_cap_reached. Admitted, it is limited to the most output what is left buys (`outputTokensMax`, at most what
296
+ * it asks for and its model's ceiling), which the model proxy writes into its body: what it is held at is then what the
297
+ * provider can bill for it. A request's worst case is at the run model's
298
+ * price, as on pi (a request on a cheaper model is held at that price too, which only refuses sooner). What cannot be
299
+ * kept within a cap is refused under one: a spend that is unknown (a request a crash cut), an input that could not be
300
+ * measured, a model serve has no price for (`listed: false`, or none at all), and a model whose output is priced and
301
+ * that has no output ceiling. With no cap, nothing is refused. */
302
+ export declare function capBefore(cap: number | undefined, model: Model<Api> | undefined, { listed }?: {
303
+ listed?: boolean;
304
+ }): Promise<CapGuard | undefined>;
305
+ /** A request's input bound (inputBound of its context, plus `overhead(model, context)`, what its provider adds
306
+ * server-side) and the most fee it can run up: a tool's own request adds what its hosted tool may read
307
+ * (hosted-search.ts), and its most fee. Undefined when its input cannot be measured. */
308
+ export declare function requestParts(overhead?: (model: Model<Api>, context: Context) => number | undefined): (model: Model<Api>, context: Context) => {
309
+ input: number;
310
+ feeUsd: number;
311
+ } | undefined;
312
+ /** `models`, each request limited to the output tokens what is left of `cap` after `spent` USD (and what requests in flight
313
+ * hold) can buy, at most what it asks for, thinking included (CLAMP on its marks when that is less), and refused when that
314
+ * cannot buy its least (`leastOutput`: 1,024 tokens for the answer, and its thinking's least), saying so in plain words;
315
+ * and, under the cap,
316
+ * each request to a model in `unpriced` (one serve has no price for) or whose output is priced and that has no output
317
+ * ceiling, each whose input cannot be bounded, and every request once what the run has spent is unknown: `spent` null
318
+ * (spentIn), or an answer since whose cost is unknown. A request's input is inputBound of its context, plus
319
+ * `overhead(model, context)` (piOverhead), what its provider adds server-side; undefined is unmeasured, never 0. Each
320
+ * request sent carries its worst case (HELD_USD) to the marks below, and one stopped before its end counts at it.
321
+ * `refused` (markRequests') writes the start mark of a refused model request before pi writes its error entry.
322
+ * `joined`: the run is on another harness, whose spend is the run's one total, and these are the run's own requests
323
+ * beside the harness's (a learned workflow's, a hosted search's). Each is judged against that total as the harness
324
+ * sets it when its run opens (RunSpend.now: its booked requests, its paid tools' charges and its requests in flight,
325
+ * with sideSpend), unknown until then; held where the harness's check sees it (paidHolds); and its cost added to
326
+ * sideSpend, which starts at `spent` (what these cost in earlier processes: spentIn's `sides`). */
327
+ export declare function capModels<M extends Models>(models: M, cap: number, spent: number | null, { unpriced, overhead, refused: markRefused, joined }?: {
328
+ unpriced?: ReadonlySet<string>;
329
+ overhead?: (model: Model<Api>, context: Context) => number | undefined;
330
+ refused?: (figures?: RefusalFigures) => Promise<void>;
331
+ joined?: boolean;
332
+ }): Promise<M>;