@parcha/agentrun-serve 0.1.0-beta.57 → 0.1.0-beta.58

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 (108) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +64 -33
  3. package/dist/api-only.d.ts +2 -4
  4. package/dist/api-only.js +2 -4
  5. package/dist/box-paths.d.ts +4 -3
  6. package/dist/box-paths.js +7 -4
  7. package/dist/claude-login-token.d.ts +117 -0
  8. package/dist/claude-login-token.js +737 -0
  9. package/dist/claude-login.d.ts +52 -12
  10. package/dist/claude-login.js +164 -39
  11. package/dist/cli.js +7 -41
  12. package/dist/computer-attach.d.ts +35 -17
  13. package/dist/computer-attach.js +301 -49
  14. package/dist/computers.d.ts +10 -10
  15. package/dist/computers.js +5 -5
  16. package/dist/console/assets/{backend-DVhHzJX2.js → backend-CSAWUqtZ.js} +1 -1
  17. package/dist/console/assets/index-DPh29cyz.js +747 -0
  18. package/dist/console/index.html +1 -1
  19. package/dist/dial-relay.d.ts +25 -4
  20. package/dist/dial-relay.js +129 -1
  21. package/dist/env-switch.d.ts +1 -3
  22. package/dist/env-switch.js +1 -3
  23. package/dist/fal-price.d.ts +1 -3
  24. package/dist/fal-price.js +77 -26
  25. package/dist/learn/ledger.d.ts +170 -0
  26. package/dist/learn/ledger.js +218 -0
  27. package/dist/learn/promote.d.ts +3 -3
  28. package/dist/learn/promote.js +1 -1
  29. package/dist/learning-cost.d.ts +22 -20
  30. package/dist/learning-cost.js +15 -21
  31. package/dist/live-reach.d.ts +2 -0
  32. package/dist/live-reach.js +2 -0
  33. package/dist/mcp-api-only-origins.d.ts +8 -3
  34. package/dist/mcp-api-only-origins.js +17 -17
  35. package/dist/micro.d.ts +2 -0
  36. package/dist/micro.js +2 -0
  37. package/dist/model.d.ts +5 -4
  38. package/dist/model.js +7 -6
  39. package/dist/monid.d.ts +14 -1
  40. package/dist/monid.js +103 -26
  41. package/dist/openapi.js +34 -12
  42. package/dist/place-offers.d.ts +4 -0
  43. package/dist/place-offers.js +7 -4
  44. package/dist/provider.d.ts +2 -2
  45. package/dist/provider.js +9 -5
  46. package/dist/run-learning-served.d.ts +2 -2
  47. package/dist/run-view.d.ts +1 -2
  48. package/dist/run-view.js +2 -1
  49. package/dist/runner/adapter-loop.js +3 -16
  50. package/dist/runner/adapter-run-spec.d.ts +20 -13
  51. package/dist/runner/adapter-run-spec.js +57 -48
  52. package/dist/runner/beside.d.ts +9 -2
  53. package/dist/runner/beside.js +24 -7
  54. package/dist/runner/claim-secrets.d.ts +17 -15
  55. package/dist/runner/claim-secrets.js +32 -34
  56. package/dist/runner/cli-run-spec.js +21 -9
  57. package/dist/runner/held.d.ts +16 -4
  58. package/dist/runner/main.d.ts +11 -6
  59. package/dist/runner/main.js +12 -7
  60. package/dist/runner/mcp-claim.js +3 -2
  61. package/dist/runner/mcp-run.d.ts +3 -6
  62. package/dist/runner/mcp-run.js +3 -4
  63. package/dist/runner/presence.d.ts +11 -1
  64. package/dist/runner/presence.js +7 -0
  65. package/dist/runner/reflect-hook.js +1 -1
  66. package/dist/runner/run-child-host.d.ts +19 -8
  67. package/dist/runner/run-child-host.js +80 -34
  68. package/dist/runner/runner.d.ts +3 -0
  69. package/dist/runner/runner.js +1 -1
  70. package/dist/runner/save-slots.js +2 -1
  71. package/dist/runner/subagent.d.ts +11 -0
  72. package/dist/runner/subagent.js +17 -3
  73. package/dist/runner/workflow-first.d.ts +27 -14
  74. package/dist/runner/workflow-first.js +29 -22
  75. package/dist/runner/workflow-spec.js +1 -1
  76. package/dist/server.d.ts +18 -7
  77. package/dist/server.js +150 -64
  78. package/dist/slots.d.ts +9 -0
  79. package/dist/slots.js +45 -0
  80. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  81. package/dist/store/schema.d.ts +17 -0
  82. package/dist/store/schema.js +47 -1
  83. package/dist/store/sqlite/run-patch.d.ts +11 -1
  84. package/dist/store/sqlite/run-patch.js +29 -1
  85. package/dist/store/sqlite/store.js +72 -9
  86. package/dist/store/store.d.ts +14 -0
  87. package/dist/store-reads/learning.d.ts +81 -124
  88. package/dist/store-reads/learning.js +207 -286
  89. package/dist/template-eval.d.ts +19 -0
  90. package/dist/template-eval.js +92 -43
  91. package/dist/template-import.d.ts +0 -10
  92. package/dist/template-import.js +5 -10
  93. package/dist/timeline/web-calls.d.ts +12 -14
  94. package/dist/timeline/web-calls.js +14 -30
  95. package/dist/web-save.d.ts +4 -9
  96. package/dist/web-save.js +4 -43
  97. package/dist/workspace/attached-computers.d.ts +32 -9
  98. package/dist/workspace/attached-computers.js +77 -13
  99. package/dist/workspace/computer-deps.d.ts +6 -1
  100. package/dist/workspace/computer-deps.js +1 -1
  101. package/dist/workspace/computer-for-claim.js +6 -3
  102. package/dist/workspace/paired-route.d.ts +91 -0
  103. package/dist/workspace/paired-route.js +153 -0
  104. package/dist/wrapped.d.ts +8 -2
  105. package/dist/wrapped.js +21 -6
  106. package/package.json +12 -12
  107. package/templates/README.md +3 -3
  108. package/dist/console/assets/index-okP-y8PK.js +0 -747
@@ -3,7 +3,10 @@ import type { Duplex } from "node:stream";
3
3
  import { type AttachHub, type AttachSocket, type HelloResult, type MachineTokens } from "@parcha/agentrun-computer";
4
4
  import { WebSocket } from "ws";
5
5
  import { type LiveReach } from "./live-reach.js";
6
- import type { MintedTokens, PairedComputerRow, PairedComputers, RunnerRow, Runners } from "./store/index.js";
6
+ import type { MintedTokens, PairedComputerRow, PairedComputers, Runners } from "./store/index.js";
7
+ import { type Route, type RouteSettings } from "./workspace/paired-route.js";
8
+ export { liveRelays, type RelayRow } from "./runner/presence.js";
9
+ export { RELAY_CONNECT_MS } from "./live-reach.js";
7
10
  /** The characters of a pairing code: no 0, O, 1 or I, so a person reads it off a screen without a doubt. */
8
11
  export declare const PAIRING_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
9
12
  /** A computer's token starts with this, so a secret scanner knows one. */
@@ -64,8 +67,8 @@ export type PairedView = {
64
67
  serves: string[];
65
68
  /** When it serves no kind, why, naming what its driver lacks (servesNoKind); null when it serves one. */
66
69
  unserved: string | null;
67
- /** On a server whose runner runs in a process of its own, why no run here can use it and how to start the server
68
- * instead (RUNNER_APART_WORDS); null where its runs can. */
70
+ /** On a server whose runner runs in a process of its own and relays no computer's socket, why no run here can use it
71
+ * and what to do instead (RUNNER_APART_WORDS); null where its runs can. */
69
72
  runs_refused: string | null;
70
73
  os: string;
71
74
  os_version: string | null;
@@ -84,16 +87,25 @@ export type PairedView = {
84
87
  off: string;
85
88
  }>;
86
89
  driver: string;
90
+ /** Its socket is up: in this server's hub, or relayed to the runner that holds its run. */
87
91
  online: boolean;
88
92
  held_by_run: string | null;
89
93
  held_until: string | null;
94
+ /** The runner whose hub holds it for the run (its route, workspace/paired-route.ts); null while this server's hub does. */
95
+ held_on: string | null;
96
+ /** Why a run's route of it was refused or dropped, in words (its runner gone or restarted, it did not reach the runner
97
+ * in time), until it next attaches here; null when there is nothing to say. */
98
+ hold_note: string | null;
90
99
  /** The pairing (createPairing's id) whose code paired it. */
91
100
  pairing: string;
92
101
  created_at: string;
93
102
  /** Its last hello: the live socket's while it is attached (never null while online), else the last one kept. */
94
103
  seen_at: string | null;
95
104
  };
96
- export declare function pairedView(row: PairedComputerRow, hub: Pick<AttachHub, "online" | "since" | "hello" | "claimed" | "deadline">, serves: readonly string[], runnerApart?: boolean): PairedView;
105
+ /** `row` as GET /v2/computers lists it. `runsRefused`: why no run here can use it (RUNNER_APART_WORDS), or null. `route`:
106
+ * its route (workspace/paired-route.ts), which names the run that holds it and the runner whose hub does while a run's
107
+ * claim routed it there; `relayed`: its socket is relayed to that runner now (createAttachRoutes relayedPaired). */
108
+ export declare function pairedView(row: PairedComputerRow, hub: Pick<AttachHub, "online" | "since" | "hello" | "claimed" | "deadline">, serves: readonly string[], runsRefused?: string | null, route?: Route, relayed?: boolean): PairedView;
97
109
  /** How the socket's liveness is timed: ATTACH_HEARTBEAT_MS and ATTACH_IDLE_MS, unless a test gives its own. */
98
110
  export type AttachTiming = {
99
111
  readonly heartbeatMs: number;
@@ -106,9 +118,12 @@ export type AttachTiming = {
106
118
  * once ws gives up on it. */
107
119
  export declare function attachSocketOf(ws: WebSocket, timing?: AttachTiming, closing?: (code: number, reason: string) => void): AttachSocket;
108
120
  export interface AttachRoutesOptions {
121
+ /** `settings`: where the paired computers' routes are (workspace/paired-route.ts); absent, no paired computer is
122
+ * routed (every one is this hub's on the server, and none is taken on a runner's listener). */
109
123
  readonly store: {
110
124
  readonly pairedComputers: PairedComputers;
111
125
  readonly mintedTokens: MintedTokens;
126
+ readonly settings?: RouteSettings;
112
127
  };
113
128
  readonly hub: AttachHub;
114
129
  /** Told each event worth a line: a computer paired, attached, refused at its hello, removed; a machine's token minted
@@ -117,9 +132,13 @@ export interface AttachRoutesOptions {
117
132
  /** An API-only server's (api-only.ts): the socket takes a hosted machine's minted token alone, and a paired computer's
118
133
  * (the console's) is 401 as one it does not know. */
119
134
  readonly machinesOnly?: boolean;
120
- /** No runner in this server's process (ServeOptions.runnerApart): a pairing code and the pair answer say no run here
121
- * can use a paired computer, and how to start the server so one can (RUNNER_APART_WORDS). */
135
+ /** No runner in this server's process (ServeOptions.runnerApart): while no runner relays (`relayed`), a pairing code
136
+ * and the pair answer say no run here can use a paired computer, and what to do so one can (RUNNER_APART_WORDS).
137
+ * Not runnerApart, the route tick stops at its read while no route row is there and no box is relayed. */
122
138
  readonly runnerApart?: boolean;
139
+ /** Whether a runner in a process of its own relays now (server.ts relayed), read at each pairing code and pair answer;
140
+ * absent: none does. */
141
+ readonly relayed?: () => Promise<boolean>;
123
142
  /** The socket's liveness timing: the protocol's unless a test gives its own. */
124
143
  readonly timing?: AttachTiming;
125
144
  readonly now?: () => number;
@@ -138,20 +157,16 @@ export interface AttachRoutesOptions {
138
157
  readonly runners: Pick<Runners, "live">;
139
158
  readonly reach: LiveReach;
140
159
  };
160
+ /** On the server: the runner beside it in its process (Serve.beside, runner/beside.ts), whose run's route keeps a
161
+ * paired box in this hub. A route that names it and its incarnation is this hub's: the upgrade takes the box here,
162
+ * and the tick moves it here (from a runner apart that still has it) and never away. */
163
+ readonly beside?: {
164
+ readonly runner: string;
165
+ readonly incarnation: string;
166
+ };
141
167
  }
142
168
  /** A request's Bearer token, or undefined. */
143
169
  export declare const bearerOf: (authorization: string | undefined) => string | undefined;
144
- /** A runner's row that says where its relay answers. */
145
- export type RelayRow = RunnerRow & {
146
- readonly host: string;
147
- readonly port: number;
148
- };
149
- /** The runners whose relay takes dials now: their rows seen within PRESENCE_STALE_MS on the store's clock (Runners.live,
150
- * the database's on Postgres), never one process's, that say where their relay answers. The server relays a dial only
151
- * to one of these, and says a dial provider is served while one answers at a host it dials (server.ts relayed). */
152
- export declare function liveRelays(runners: Pick<Runners, "live">): Promise<RelayRow[]>;
153
- /** How long the server waits for a runner's attach listener to take a relayed dial. */
154
- export declare const RELAY_CONNECT_MS = 10000;
155
170
  /** Two WebSockets joined frame by frame, each an attach socket with `timing` (attachSocketOf: its idle close, its binary
156
171
  * refusal, the server's maxPayload), each closing the other with its code and reason: once it ended, or as soon as it
157
172
  * starts a close of its own, so an idle peer's close reaches the other side at once. */
@@ -175,5 +190,8 @@ export declare function createAttachRoutes(options: AttachRoutesOptions): {
175
190
  close: () => Promise<void>;
176
191
  machineTokens: MachineTokens;
177
192
  daemon: (authorization: string | undefined, arch: string | null) => Promise<string>;
193
+ tick: () => Promise<void>;
194
+ relayedTo: (id: string) => string | undefined;
195
+ runsRefused: () => Promise<string | null>;
178
196
  };
179
197
  export type AttachRoutes = ReturnType<typeof createAttachRoutes>;