@parcha/agentrun-kernel 0.1.0-beta.37 → 0.1.0-beta.39

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 (70) hide show
  1. package/CHANGELOG.md +136 -0
  2. package/NOTICE +2 -0
  3. package/dist/booking.d.ts +25 -6
  4. package/dist/booking.js +15 -4
  5. package/dist/host/index.d.ts +4 -5
  6. package/dist/host/index.js +3 -3
  7. package/dist/host/o200k.d.ts +11 -0
  8. package/dist/host/o200k.js +185 -0
  9. package/dist/host/overhead.d.ts +105 -3
  10. package/dist/host/overhead.js +276 -20
  11. package/dist/host/proxy.d.ts +97 -16
  12. package/dist/host/proxy.js +420 -108
  13. package/dist/index.d.ts +6 -5
  14. package/dist/index.js +4 -3
  15. package/dist/kernel/cap/admit.d.ts +5 -8
  16. package/dist/kernel/cap/admit.js +13 -19
  17. package/dist/kernel/cap/free.d.ts +43 -0
  18. package/dist/kernel/cap/free.js +71 -0
  19. package/dist/kernel/cap/index.d.ts +7 -6
  20. package/dist/kernel/cap/index.js +6 -5
  21. package/dist/kernel/cap/marks.d.ts +2 -3
  22. package/dist/kernel/cap/park.d.ts +3 -4
  23. package/dist/kernel/cap/park.js +4 -5
  24. package/dist/kernel/cap/port.d.ts +11 -5
  25. package/dist/kernel/cap/port.js +26 -24
  26. package/dist/kernel/cap/price.d.ts +10 -30
  27. package/dist/kernel/cap/price.js +15 -48
  28. package/dist/kernel/cap/recover.d.ts +1 -2
  29. package/dist/kernel/cap/recover.js +2 -4
  30. package/dist/kernel/cap/rule.d.ts +11 -17
  31. package/dist/kernel/cap/rule.js +37 -19
  32. package/dist/kernel/cap/run-cap.d.ts +25 -10
  33. package/dist/kernel/cap/run-cap.js +78 -35
  34. package/dist/kernel/cap/types.d.ts +11 -27
  35. package/dist/kernel/cap/words.d.ts +13 -8
  36. package/dist/kernel/cap/words.js +23 -14
  37. package/dist/kernel/cap/wrap-up.d.ts +4 -0
  38. package/dist/kernel/cap/wrap-up.js +5 -1
  39. package/dist/kernel/registry/computer-surface.generated.d.ts +1 -1
  40. package/dist/kernel/registry/computer-surface.generated.js +18 -27
  41. package/dist/kernel/registry/computer.d.ts +14 -7
  42. package/dist/kernel/registry/computer.js +64 -16
  43. package/dist/kernel/registry/gate.d.ts +2 -2
  44. package/dist/kernel/registry/gate.js +4 -7
  45. package/dist/kernel/registry/hands.d.ts +4 -5
  46. package/dist/kernel/registry/index.d.ts +1 -1
  47. package/dist/kernel/registry/index.js +1 -1
  48. package/dist/kernel/registry/registry.js +6 -9
  49. package/dist/kernel/types.d.ts +8 -1
  50. package/dist/process/recovery.d.ts +4 -1
  51. package/dist/process/recovery.js +15 -3
  52. package/dist/process/resume.d.ts +5 -2
  53. package/dist/process/resume.js +15 -3
  54. package/dist/process/tools.d.ts +28 -1
  55. package/dist/process/tools.js +102 -5
  56. package/dist/run-booking.d.ts +21 -2
  57. package/dist/run-booking.js +215 -18
  58. package/dist/runner.d.ts +82 -21
  59. package/dist/runner.js +271 -56
  60. package/dist/testing.d.ts +10 -4
  61. package/dist/testing.js +7 -5
  62. package/dist/tool-deferral.d.ts +12 -0
  63. package/dist/tool-deferral.js +17 -0
  64. package/dist/types.d.ts +133 -48
  65. package/dist/types.js +8 -0
  66. package/package.json +5 -3
  67. package/vendor/o200k/LICENSE +61 -0
  68. package/vendor/o200k/o200k_base.tiktoken +199998 -0
  69. package/dist/host/mcp-route.d.ts +0 -14
  70. package/dist/host/mcp-route.js +0 -125
package/dist/runner.d.ts CHANGED
@@ -41,9 +41,6 @@ export type BeforeRequest = (request: {
41
41
  /** The most input tokens this request can be billed for (the body's UTF-8 bytes plus what the provider adds, as the
42
42
  * model proxy measured it), undefined when it was not measured: a budget treats that input as unknown, never 0. */
43
43
  inputTokensMax?: number;
44
- /** Its `inputTokensMax` is its provider's count, not its bytes (ModelRequest.inputTokensCounted): two bounds are compared
45
- * (the cap's expected pricing) only when both were measured the same way. */
46
- inputTokensCounted?: true;
47
44
  /** The most output tokens it asks for, and the least it may be limited to and still answer, as the model proxy read
48
45
  * them from its body (ModelRequest). */
49
46
  outputTokensAsked?: number;
@@ -53,7 +50,8 @@ export type BeforeRequest = (request: {
53
50
  /** A paid tool call, no model request (ModelRequest.paid): held at its fee alone, named so in a refusal. `call`: the
54
51
  * tool call it was booked under, `charged_by`, who charges for it, and `tool`/`tag`, the tool it is and its session,
55
52
  * all written on its runner.request. `owed`: money already owed at its provider, held and booked, never refused.
56
- * `hold`: a hold-only step, given back on a lost claim; `ref`: the one booking it names (ModelRequest.paid). */
53
+ * `hold`: a hold-only step, given back on a lost claim; `ref`: the one booking it names; `under`: the model session
54
+ * whose tool call it runs in, whose requests in flight it never waits on (ModelRequest.paid). */
57
55
  paid?: {
58
56
  name: string;
59
57
  basis: string;
@@ -64,11 +62,12 @@ export type BeforeRequest = (request: {
64
62
  owed?: true;
65
63
  hold?: true;
66
64
  ref?: string;
65
+ under?: string;
67
66
  };
68
67
  /** A side call (ModelRequest.side): on another model than the session's (a client's), or the host's own (`host`). */
69
68
  side?: true;
70
69
  /** A request on the session's model that is no answer of the turn (ModelRequest.unanswered: a title, a summary, a
71
- * child's): still the run's own to book, but never the session's previous request, read or replaced. */
70
+ * child's): still the run's own to book, but no answer the host keeps its wrap-up's reserve back for. */
72
71
  unanswered?: true;
73
72
  /** It carries the host's note (ModelRequest.noted), and its input measured without it (`inputTokensMaxWithoutNote`):
74
73
  * a host that admits it only without the note says so (Admission.withoutNote). */
@@ -84,18 +83,29 @@ export type BeforeRequest = (request: {
84
83
  * (`holdUsd`): a budget holds each one until it answers, since `spentUsd` counts answered requests only. Requests are
85
84
  * admitted one at a time, so each check sees every request admitted before it. */
86
85
  inFlight: readonly InFlight[];
87
- }) => void | Refusal | Admission | Promise<void | Refusal | Admission>;
86
+ /** The run's requests on free models so far (runBooking, over every session of the run): each whose runner.request says
87
+ * so (`freeRequest`), answered, in flight or cut, and each admitted that no record shows yet. Absent: not counted here. */
88
+ freeRequestsMade?: number;
89
+ /** The request's client's signal (ModelRequest.signal): a host that makes it wait for room lets it go when it aborts. */
90
+ signal?: AbortSignal;
91
+ /** The booking's own stop or pause, now (its `stopped`, `draining`, or a cost it could not record): a request waiting
92
+ * for room leaves with this error once there is one, nothing written for it. */
93
+ halted?: () => Error | undefined;
94
+ }) => void | Refusal | Admitted | Promise<void | Refusal | Admitted>;
88
95
  /** A host's refusal of a request: its words, and, from a spend cap, whether no raise could send it (`forGood`) and, for
89
- * one a raise could, its figures (what the cap counted as taken, what the request needs at the least, the least cap that
90
- * sends it): what the run's end is decided from (the kernel cap's parkOf). */
96
+ * one a raise could, its figures (what the run had spent, never a hold; what its steps in flight held; what the request
97
+ * needs at the least; the least cap that sends it): what the run's end is decided from (the kernel cap's parkOf).
98
+ * `waits`: refused only because steps still in flight hold the room it needs, steps that settle on their own (it fits
99
+ * beside the run's spend with none of them out): a booking that can wait (runBooking) asks again once they settle, and
100
+ * any other reads it as the refusal it is. */
91
101
  export type Refusal = {
92
102
  refuse: string;
93
103
  forGood?: boolean;
94
104
  figures?: {
95
105
  spentUsd: number;
106
+ heldUsd?: number;
96
107
  needsUsd: number;
97
108
  leastCapUsd: number;
98
- boundUsd?: number;
99
109
  step?: {
100
110
  name: string;
101
111
  holdUsd: number;
@@ -105,18 +115,21 @@ export type Refusal = {
105
115
  /** The refusal's code, from a host that gives one (a spend cap's: `spend_cap_reached`): carried on the error that ends
106
116
  * the node (HarnessRunError.refusal), so a reader knows the refusal by it, never by its words. */
107
117
  code?: string;
118
+ waits?: true;
108
119
  };
109
120
  /** A request admitted and not yet answered, as a budget holds it: at what its host held for it (`holdUsd`), when it held
110
- * one. */
121
+ * one. `stays`: a hold-only step (ModelRequest.paid.hold, a browser session's reserve), let go only when its holder says,
122
+ * never by settling on its own: no request waits for it. */
111
123
  export type InFlight = {
112
124
  turn: number;
113
125
  model: string;
114
126
  inputTokensMax?: number;
115
127
  outputTokensMax?: number;
116
128
  holdUsd?: number;
117
- boundUsd?: number;
118
129
  host?: string;
119
130
  route?: string;
131
+ freeRequest?: true;
132
+ stays?: true;
120
133
  };
121
134
  /** A host's admission: what it holds for the request (`holdUsd`), and the most output tokens, thinking included, it may
122
135
  * be sent with (`outputTokensMax`, what is left of a cap can buy), which its ticket carries to the model proxy. A
@@ -124,17 +137,27 @@ export type InFlight = {
124
137
  * streamed, in tokens (one a byte), never more than `holdUsd`; without it, at `holdUsd`. `withoutNote`: a request that
125
138
  * carries its host's note is admitted only as it was without it (the note's bytes did not fit): it goes without it.
126
139
  * `note`: the host's record of the note this request carries, written on the request's `runner.turn` record once it
127
- * ends, beside how it was booked, so a later process reads whether the note reached an answer. `boundUsd`: the most a
128
- * cache miss adds to `holdUsd`, written beside it, so a request that never answers counts for the cap at both. */
140
+ * ends, beside how it was booked, so a later process reads whether the note reached an answer. `freeRequest`: one of
141
+ * the run's requests on a free model, which its ceiling on such requests counts: written on its runner.request (as
142
+ * `freeRequest`), so the count holds it in every process, and a cut one books at $0 (bookCut). */
129
143
  export type Admission = {
130
144
  holdUsd?: number;
131
- boundUsd?: number;
132
145
  outputTokensMax?: number;
133
146
  stoppedUsd?: (streamedTokens: number) => number;
134
147
  withoutNote?: true;
135
148
  note?: {
136
149
  [key: string]: JsonValue;
137
150
  };
151
+ freeRequest?: true;
152
+ };
153
+ /** An admission as a host gives it: with `free` when the request is on a free model (its known price is $0 for every
154
+ * token, with no fee beside), so it costs nothing however it ends: booked a known $0 (booking.ts), its own cost 0, its
155
+ * runner.turn marked `free` for a reader to say why. `plan`: the request is billed to a person's subscription plan (a
156
+ * ChatGPT plan's model, CapModel.plan), never in dollars: it costs the run $0 however it ends, its runner.request and
157
+ * runner.turn marked so (`plan`, `billing: "plan"`), so a later process books it so too when a crash cut it. */
158
+ export type Admitted = Admission & {
159
+ free?: true;
160
+ plan?: true;
138
161
  };
139
162
  export interface HarnessRunnerOptions {
140
163
  /** The run's store, through whoever owns it. */
@@ -226,12 +249,9 @@ export interface ModelBooking {
226
249
  * only, so a reader of the run's spend that a request overlapping another must see adds this. Null while one in flight
227
250
  * has no hold (never under a cap, which refuses a request it cannot price): unknown, never read as 0. */
228
251
  heldUsd(): number | null;
229
- /** What a cache miss adds to those holds (Admission.boundUsd), the requests still in flight together: the run's tools stop
230
- * on the holds plus this (the cap counts a request that never answers at both), so a reader that must warn no later
231
- * adds it too. 0 with none in flight or none with a bound. */
232
- boundUsd(): number;
233
252
  /** Books, once, each paid request a crash cut off (a `runner.request` with no `runner.turn`): a `runner.turn` marked
234
- * `cut` at an unknown price, and a `request_end` saying so. A booked request is answered, so this is idempotent.
253
+ * `cut`, at its hold as the most it can have cost (CUT_AT_HOLD) or, with none, at an unknown price (one billed to a
254
+ * plan, its runner.request's `plan`: at $0, `billing: "plan"`), and a `request_end` saying so. A booked request is answered, so this is idempotent.
235
255
  * Call it before the session sends anything. */
236
256
  bookCut(): Promise<void>;
237
257
  }
@@ -247,7 +267,6 @@ export declare function modelPortFor(writer: SessionWriter, options: ModelPortOp
247
267
  export declare function sessionSpendOf(records: readonly SessionRecord[]): {
248
268
  turns: number[];
249
269
  held: Map<number, number>;
250
- bounds: Map<number, number>;
251
270
  hosts: Map<number, string>;
252
271
  answered: Set<number>;
253
272
  openHolds: Set<number>;
@@ -258,6 +277,45 @@ export declare function sessionSpendOf(records: readonly SessionRecord[]): {
258
277
  }[];
259
278
  cost: SessionCost;
260
279
  };
280
+ /** A cost's parts, each charge counted by turnCostOf: `known`, the sum of the figures that are a charge's own; `bounded`,
281
+ * the sum of those that are a cut request's hold (CUT_AT_HOLD), the most each can have cost, and `atMost`, how many those
282
+ * are; `unpriced`, how many charges have no figure at all. */
283
+ export type CostParts = {
284
+ readonly known: number;
285
+ readonly bounded: number;
286
+ readonly atMost: number;
287
+ readonly unpriced: number;
288
+ };
289
+ /** The one rule for a cost made of parts, as every reader of a run's cost says it (the session's, the run's stored cost,
290
+ * its view and its usage row). Every charge counted: `usd` is their sum, holds included, and `atMost` how many of them are
291
+ * a hold, so the cost is at most `usd`. Any charge with no figure: `usd` is null, `soFarUsd` the charges' own figures
292
+ * alone, and `unpriced` counts the held ones with those of no figure. A hold is a ceiling, never spend: beside a cost no
293
+ * one knows it bounds nothing, so it joins no known sum, where it would read as money spent. */
294
+ export declare function costOfParts(parts: readonly CostParts[]): SessionCost;
295
+ /** Whether a runner.turn books a request already booked: its turn (`key`, as the reader names it) is in `seen`, which it
296
+ * joins otherwise. Every reader of a booking (sessionSpendOf, serve's bookedSpend) skips such a record, so a request is
297
+ * counted once: two bookings of one session that each read it open, or a cut written twice, wrote it twice. A record
298
+ * with no turn (written before turns were named) is never a repeat. */
299
+ export declare function rebooked<K>(seen: Set<K>, key: K | undefined): boolean;
300
+ /** The rule (runner.turn `rule`) of a request cut with no answer that bookCut booked at what its host held for it: the
301
+ * most it can have cost (its whole input uncached and the output it was sent with), marked `atMost`. */
302
+ export declare const CUT_AT_HOLD = "cut";
303
+ /** A booked request's own cost, from its runner.turn, as every reader of a run's cost reads it (the session's cost, the
304
+ * run's stored cost and its views): what it was booked at, else its `usd`; null when no one knows it (an answer with no
305
+ * price of its own booked at its hold for the cap, answeredUnpriced; a request cut with no hold). `atMost`: a request cut
306
+ * with no answer, booked at its hold (CUT_AT_HOLD), so the figure is the most it can have cost, never less. One billed to
307
+ * a person's plan (`billing: "plan"`) is $0 to the run however it ended: the plan pays for it, never the run. */
308
+ export declare function turnCostOf(data: {
309
+ usd?: unknown;
310
+ bookedUsd?: unknown;
311
+ cut?: unknown;
312
+ rule?: unknown;
313
+ atMost?: unknown;
314
+ billing?: unknown;
315
+ }): {
316
+ usd: number | null;
317
+ atMost: boolean;
318
+ };
261
319
  /** Whether a request ended with no price of its own (usd null) under a rule that books it at a figure of the host's: an
262
320
  * answer with no cost (bookRequest's rule `answered`, or `answered:<label>`: its hold), or one our side stopped
263
321
  * (`stopped`: what streamed, an estimate) or lost (`lost`, `lost:<label>`: its hold). Each counts for the cap at that
@@ -267,10 +325,13 @@ export declare const answeredUnpriced: (data: {
267
325
  rule?: unknown;
268
326
  }) => boolean;
269
327
  /** A session's cost as a person is shown it: `usd` when every paid request has its own figure, else null with the known
270
- * part so far (`soFarUsd`) and how many have none (`unpriced`). */
328
+ * part so far (`soFarUsd`, the charges' own figures alone) and how many have none (`unpriced`, a cut request's hold
329
+ * among them). `atMost`, set only while `usd` is known: how many of its figures are a cut request's hold (turnCostOf),
330
+ * so the cost is at most what it says (costOfParts). */
271
331
  export type SessionCost = {
272
332
  usd: number | null;
273
333
  soFarUsd: number;
274
334
  unpriced: number;
335
+ atMost?: number;
275
336
  };
276
337
  export declare function createHarnessRunner(adapter: AgentAdapter, options: HarnessRunnerOptions): HarnessRunner;