@parcha/agentrun-serve 0.1.0-beta.29 → 0.1.0-beta.31

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 (172) hide show
  1. package/CHANGELOG.md +238 -0
  2. package/README.md +739 -116
  3. package/dist/adapters.d.ts +35 -6
  4. package/dist/adapters.js +152 -26
  5. package/dist/agents.d.ts +18 -7
  6. package/dist/agents.js +19 -10
  7. package/dist/app.js +101 -26
  8. package/dist/background.d.ts +29 -0
  9. package/dist/background.js +397 -0
  10. package/dist/box-egress-vm.d.ts +125 -0
  11. package/dist/box-egress-vm.js +350 -0
  12. package/dist/box-egress.d.ts +99 -0
  13. package/dist/box-egress.js +259 -0
  14. package/dist/box-image.d.ts +1 -1
  15. package/dist/box-image.js +9 -7
  16. package/dist/box-relay-vm.d.ts +84 -0
  17. package/dist/box-relay-vm.js +410 -0
  18. package/dist/box-relay.d.ts +8 -5
  19. package/dist/box-relay.js +14 -9
  20. package/dist/boxes.d.ts +28 -5
  21. package/dist/boxes.js +44 -18
  22. package/dist/browser-cost.d.ts +41 -0
  23. package/dist/browser-cost.js +158 -0
  24. package/dist/cap.d.ts +130 -21
  25. package/dist/cap.js +339 -67
  26. package/dist/cli.js +30 -4
  27. package/dist/coding-tools.d.ts +7 -3
  28. package/dist/coding-tools.js +16 -10
  29. package/dist/console/THIRD-PARTY-NOTICES.txt +580 -0
  30. package/dist/console/assets/index-CnJBf7Lc.js +486 -0
  31. package/dist/console/assets/index-DUHbWcIP.css +1 -0
  32. package/dist/console/index.html +2 -2
  33. package/dist/content-filter.d.ts +7 -0
  34. package/dist/content-filter.js +23 -0
  35. package/dist/decision-rows.d.ts +11 -3
  36. package/dist/decision-rows.js +18 -11
  37. package/dist/decisions.d.ts +3 -3
  38. package/dist/decisions.js +4 -3
  39. package/dist/errors.d.ts +2 -0
  40. package/dist/errors.js +5 -2
  41. package/dist/files.d.ts +9 -1
  42. package/dist/files.js +10 -2
  43. package/dist/grade.d.ts +11 -11
  44. package/dist/grade.js +43 -55
  45. package/dist/graph-served.d.ts +23 -0
  46. package/dist/graph-served.js +75 -0
  47. package/dist/graph-view.d.ts +7 -5
  48. package/dist/graph-view.js +10 -3
  49. package/dist/harness-app.d.ts +4 -2
  50. package/dist/harness-app.js +110 -19
  51. package/dist/harness-opencode/adapter.d.ts +45 -0
  52. package/dist/harness-opencode/adapter.js +272 -0
  53. package/dist/harness-opencode/binary.d.ts +18 -0
  54. package/dist/harness-opencode/binary.js +87 -0
  55. package/dist/harness-opencode/config.d.ts +24 -0
  56. package/dist/harness-opencode/config.js +61 -0
  57. package/dist/harness-opencode/harness.d.ts +77 -0
  58. package/dist/harness-opencode/harness.js +620 -0
  59. package/dist/harness-opencode/host/mcp.d.ts +40 -0
  60. package/dist/harness-opencode/host/mcp.js +208 -0
  61. package/dist/harness-opencode/host/policy.d.ts +71 -0
  62. package/dist/harness-opencode/host/policy.js +419 -0
  63. package/dist/harness-opencode/host/server.d.ts +55 -0
  64. package/dist/harness-opencode/host/server.js +165 -0
  65. package/dist/harness-opencode/index.d.ts +9 -0
  66. package/dist/harness-opencode/index.js +6 -0
  67. package/dist/harness-opencode/verify.d.ts +32 -0
  68. package/dist/harness-opencode/verify.js +75 -0
  69. package/dist/harness-opencode/versions.d.ts +33 -0
  70. package/dist/harness-opencode/versions.js +64 -0
  71. package/dist/harness.d.ts +4 -1
  72. package/dist/harness.js +5 -2
  73. package/dist/host-check.d.ts +12 -0
  74. package/dist/host-check.js +34 -0
  75. package/dist/host-tools.d.ts +12 -2
  76. package/dist/host-tools.js +26 -12
  77. package/dist/host.js +6 -2
  78. package/dist/hosted-search.js +5 -1
  79. package/dist/import.d.ts +2 -2
  80. package/dist/import.js +4 -3
  81. package/dist/key-check.d.ts +3 -2
  82. package/dist/key-check.js +7 -3
  83. package/dist/key-refusal.js +8 -4
  84. package/dist/key-words.d.ts +37 -0
  85. package/dist/key-words.js +40 -0
  86. package/dist/learn/check.d.ts +10 -1
  87. package/dist/learn/check.js +19 -1
  88. package/dist/learn/grade.d.ts +6 -2
  89. package/dist/learn/grade.js +28 -14
  90. package/dist/learn/index.d.ts +3 -3
  91. package/dist/learn/index.js +3 -3
  92. package/dist/learn/notes.js +2 -1
  93. package/dist/learn/reflect.d.ts +2 -2
  94. package/dist/learn/reflect.js +53 -5
  95. package/dist/learn/secrets.js +28 -8
  96. package/dist/learn/skills.d.ts +19 -4
  97. package/dist/learn/skills.js +95 -6
  98. package/dist/learned-workflow.d.ts +59 -0
  99. package/dist/learned-workflow.js +191 -0
  100. package/dist/learning-routes.d.ts +30 -1
  101. package/dist/learning-routes.js +173 -19
  102. package/dist/learning-run.d.ts +8 -6
  103. package/dist/learning-run.js +70 -27
  104. package/dist/learning-words.d.ts +12 -5
  105. package/dist/learning-words.js +34 -13
  106. package/dist/learning.d.ts +52 -3
  107. package/dist/learning.js +204 -4
  108. package/dist/mcp-gateway.d.ts +96 -0
  109. package/dist/mcp-gateway.js +408 -0
  110. package/dist/mcp-meta.d.ts +17 -0
  111. package/dist/mcp-meta.js +38 -0
  112. package/dist/mcp-servers.d.ts +33 -9
  113. package/dist/mcp-servers.js +58 -10
  114. package/dist/mcp.js +5 -5
  115. package/dist/model.d.ts +13 -11
  116. package/dist/model.js +11 -10
  117. package/dist/openapi/agentrun-v2.openapi.json +1 -0
  118. package/dist/openapi.js +407 -54
  119. package/dist/page.d.ts +2 -0
  120. package/dist/page.js +3 -0
  121. package/dist/paid-calls.d.ts +5 -1
  122. package/dist/paid-calls.js +1 -1
  123. package/dist/pause.d.ts +2 -0
  124. package/dist/place.d.ts +29 -5
  125. package/dist/place.js +51 -11
  126. package/dist/print.d.ts +7 -0
  127. package/dist/print.js +13 -0
  128. package/dist/propose.d.ts +2 -0
  129. package/dist/propose.js +38 -8
  130. package/dist/request-start.d.ts +12 -4
  131. package/dist/request-start.js +139 -15
  132. package/dist/run-box.d.ts +56 -4
  133. package/dist/run-box.js +183 -23
  134. package/dist/runnable.d.ts +13 -3
  135. package/dist/runnable.js +63 -6
  136. package/dist/runs.d.ts +266 -37
  137. package/dist/runs.js +884 -90
  138. package/dist/secrets.d.ts +27 -0
  139. package/dist/secrets.js +38 -2
  140. package/dist/server.d.ts +141 -36
  141. package/dist/server.js +562 -118
  142. package/dist/sign-ins.d.ts +99 -0
  143. package/dist/sign-ins.js +288 -0
  144. package/dist/skills.d.ts +16 -4
  145. package/dist/skills.js +35 -7
  146. package/dist/stats.d.ts +7 -2
  147. package/dist/stats.js +28 -7
  148. package/dist/tool-gate.d.ts +281 -0
  149. package/dist/tool-gate.js +585 -0
  150. package/dist/tool-keys.d.ts +48 -11
  151. package/dist/tool-keys.js +46 -8
  152. package/dist/tool-plane.d.ts +116 -27
  153. package/dist/tool-plane.js +232 -50
  154. package/dist/tools.d.ts +69 -14
  155. package/dist/tools.js +148 -26
  156. package/dist/trigger-secrets.d.ts +32 -0
  157. package/dist/trigger-secrets.js +143 -0
  158. package/dist/triggers.d.ts +439 -0
  159. package/dist/triggers.js +863 -0
  160. package/dist/turn-end.d.ts +3 -2
  161. package/dist/turn-end.js +3 -2
  162. package/dist/usage-lines.d.ts +26 -0
  163. package/dist/usage-lines.js +28 -0
  164. package/dist/validate.d.ts +2 -0
  165. package/dist/validate.js +11 -2
  166. package/dist/web-fetch.js +3 -3
  167. package/dist/webhooks.d.ts +11 -4
  168. package/dist/webhooks.js +17 -1
  169. package/launcher/agentrun-serve +1 -1
  170. package/package.json +16 -14
  171. package/dist/console/assets/index-BN7oVcO4.js +0 -445
  172. package/dist/console/assets/index-By-jkqki.css +0 -1
@@ -28,6 +28,9 @@ export declare function installHint(message: string, npmLine: string, spec: stri
28
28
  /** For tests: a JSON `{command, args?, env?}` that speaks Codex's app-server protocol in place of Codex. agentrun-harness-codex
29
29
  * takes it only under its own guard (AGENTRUN_CODEX_STANDIN=1, under a test runner). */
30
30
  export declare const CODEX_STANDIN_ENV = "AGENTRUN_SERVE_CODEX_STANDIN";
31
+ /** For tests: a JSON `{command, args?, env?}` that speaks `opencode serve`'s HTTP API in place of OpenCode. The OpenCode
32
+ * adapter (src/harness-opencode) takes it only under its own guard (AGENTRUN_OPENCODE_STANDIN=1, under a test runner). */
33
+ export declare const OPENCODE_STANDIN_ENV = "AGENTRUN_SERVE_OPENCODE_STANDIN";
31
34
  /** The event of a harness's own lines in the run's log (its model proxy's refusals and failures): a failed run's message
32
35
  * is never taken from one (runs.ts lastLogLine). */
33
36
  export declare const HARNESS_LOG_EVENT = "harness";
@@ -89,7 +92,7 @@ export declare function confineOf(prefix: readonly string[]): ConfineChild | und
89
92
  * segment (raw or percent-encoded), a backslash, whitespace, or plain http to anything but this machine.
90
93
  */
91
94
  export declare function gatewayBase(setting: string, value: string): string;
92
- /** The model key a run on `harness` (claude-agent or codex) of `model` (the revision's; none, the host's default for the
95
+ /** The model key a run on `harness` (claude-agent, codex, or opencode, which takes codex's route) of `model` (the revision's; none, the host's default for the
93
96
  * harness) takes: the one its requests carry on the route its provider below takes, as key-refusal.ts' runKeyOf names
94
97
  * it. codex: the gateway's when AGENT_MODEL_BASE_URL is set, else OpenAI's, or OpenRouter's on OpenRouter's route;
95
98
  * claude-agent: Anthropic's, for api.anthropic.com or ANTHROPIC_BASE_URL alike, or OpenRouter's on OpenRouter's route.
@@ -98,6 +101,10 @@ export declare function harnessModelKeys(harness: string, env: NodeJS.ProcessEnv
98
101
  /** OpenRouter's API: its Anthropic Messages endpoint (`<base>/v1/messages`) and its Responses API (`<base>/v1/responses`)
99
102
  * under one base, its key taken as a bearer token. The OpenRouter key goes nowhere else. */
100
103
  export declare const OPENROUTER_BASE = "https://openrouter.ai/api";
104
+ /** Anthropic's own origin, where pi-ai's Anthropic provider sends (a gateway is not it). */
105
+ export declare const ANTHROPIC_ORIGIN = "https://api.anthropic.com";
106
+ /** OpenAI's own origin, where pi-ai's OpenAI provider sends. */
107
+ export declare const OPENAI_ORIGIN = "https://api.openai.com";
101
108
  export { openRouterOnly };
102
109
  /** Where codex's model requests go, and the model id sent there: a gateway at AGENT_MODEL_BASE_URL's base (gatewayBase:
103
110
  * the proxy sends the Responses API to <base>/v1/responses) with its key, the model as model.ts chose it; OpenAI with
@@ -109,12 +116,12 @@ export type CodexProvider = {
109
116
  credential: () => string;
110
117
  modelId: string;
111
118
  };
112
- export declare function codexProvider(env: NodeJS.ProcessEnv, model: ModelRef): CodexProvider;
113
- /** codex's model for `ref` (a revision's; none, the host's default for codex): as model.ts chooses it, except where
114
- * codex reaches OpenAI only through OpenRouter (openRouterOnly), where an OpenAI model needs no OpenAI key, only a
119
+ export declare function codexProvider(env: NodeJS.ProcessEnv, model: ModelRef, harness?: "codex" | "opencode"): CodexProvider;
120
+ /** codex's model for `ref` (a revision's; none, the host's default for codex), or opencode's (`harness`), which takes
121
+ * codex's route: as model.ts chooses it, except where it reaches OpenAI only through OpenRouter (openRouterOnly), where an OpenAI model needs no OpenAI key, only a
115
122
  * model pi-ai's catalog lists (it prices the run): OpenRouter's key is the one codexProvider sends. A save, a run and
116
123
  * capabilities all ask this. */
117
- export declare function codexModel(env: NodeJS.ProcessEnv, ref: string | undefined): ReturnType<typeof chooseModel>;
124
+ export declare function codexModel(env: NodeJS.ProcessEnv, ref: string | undefined, harness?: "codex" | "opencode"): ReturnType<typeof chooseModel>;
118
125
  /** A response's price in USD, from the same catalog that prices pi's runs; null when the model has no price. The
119
126
  * usage's input is net of the cached tokens, which are priced at their own rate. */
120
127
  export declare function priceOf(needs: AdapterNeeds): (_model: string, usage: {
@@ -156,6 +163,24 @@ export declare const openRouterName: (id: string) => string;
156
163
  /** The catalog entry a claude-agent run on `model` is priced and capped by: claudeProvider's, or the model's own where
157
164
  * claude-agent does not run here (its run is refused before any request). */
158
165
  export declare function claudePriceModel(env: NodeJS.ProcessEnv, model: ModelRef): ModelRef;
166
+ /** The model a learned workflow's requests on `harness` name in the run's models (pi-ai's catalog, app.ts): the route
167
+ * the harness's own requests take (claudeProvider, codexProvider). Through OpenRouter, OpenRouter's name for the run's
168
+ * model, whose key the run holds and whose entry prices it; the vendor's provider would need the vendor's key, which a
169
+ * run on OpenRouter alone does not have. Otherwise the run's model as it is (Anthropic's own id for claude-agent); under
170
+ * a faux harness, through codex's gateway (AGENT_MODEL_BASE_URL), or where the harness refuses the run (before any
171
+ * request), `model` itself. */
172
+ export declare function learnedRoute(harness: string, env: NodeJS.ProcessEnv, model: ModelRef): ModelRef;
173
+ /** Why a run on `harness` is offered no learned workflow, or undefined when it is. A learned workflow's model requests go
174
+ * through the run's models (pi-ai's catalog, learnedRoute), whose Anthropic provider reaches api.anthropic.com alone:
175
+ * claude-agent through the operator's own gateway (ANTHROPIC_BASE_URL) would have them go around it, with its key. So
176
+ * that run gets none (fail closed), and its pin says why. codex and opencode (codex's route) the same, at any origin
177
+ * learnedOriginOk does not name; their gateway is the run's models' own (runModels), and pi runs on them. A run its
178
+ * harness refuses sends nothing, so it is not this one's to say. */
179
+ export declare function learnedWorkflowsOff(harness: string | undefined, env: NodeJS.ProcessEnv, ref: string | undefined): Promise<string | undefined>;
180
+ /** Whether a learned workflow's requests reach `origin`, where `harness` sends the run's own (learnedWorkflowsOff): the
181
+ * run's models hold Anthropic's, OpenAI's and OpenRouter's providers, and, for codex and opencode (runModels), the
182
+ * gateway at AGENT_MODEL_BASE_URL. Any other origin is not one they can follow. */
183
+ export declare function learnedOriginOk(harness: string, origin: string, env: NodeJS.ProcessEnv): boolean;
159
184
  /** claude-agent's model: the revision's (or the server's default for claude-agent, hostModel) as `provider/model-id`.
160
185
  * Never the gateway's model, which serves the other harnesses. An Anthropic model (`anthropic/<id>`) is Anthropic's
161
186
  * own id, dots as dashes, except where claude-agent reaches Anthropic only through OpenRouter (openRouterOnly), where it
@@ -182,11 +207,15 @@ export declare function nativeOptions(harness: string, env: NodeJS.ProcessEnv):
182
207
  };
183
208
  /** claude-agent's adapter, from `load` (the installed package; a test gives its own). */
184
209
  export declare function claudeOf(env: NodeJS.ProcessEnv, needs: AdapterNeeds, load?: () => Promise<unknown>, npx?: boolean): Promise<AgentAdapter>;
185
- /** The run's thinking level as the harness takes it: serve's levels run to max; Codex's reasoning efforts stop at xhigh. */
210
+ /** The run's thinking level as the harness takes it: serve's levels run to max; Codex's and OpenCode's reasoning efforts
211
+ * (OpenAI's) stop at xhigh. */
186
212
  export declare const thinkingFor: (harness: string, level: string) => SessionSpec["thinking"];
187
213
  /** The bare id Codex takes: serve's "openai/<id>" without its provider. */
188
214
  /** codex's adapter, from `load` (the installed package; a test gives its own). */
189
215
  export declare function codexOf(env: NodeJS.ProcessEnv, needs: AdapterNeeds, load?: () => Promise<typeof import("@parcha/agentrun-harness-codex")>, npx?: boolean): Promise<AgentAdapter>;
216
+ /** opencode's adapter, from `load` (the installed package; a test gives its own). Its model goes where codex's does: serve's
217
+ * gateway (AGENT_MODEL_BASE_URL) or OpenAI, on the Responses API, through the adapter's proxy. */
218
+ export declare function opencodeOf(env: NodeJS.ProcessEnv, needs: AdapterNeeds, load?: () => Promise<typeof import("./harness-opencode/index.js")>, npx?: boolean): Promise<AgentAdapter>;
190
219
  export declare function adapterFor(harness: string, env: NodeJS.ProcessEnv, needs: AdapterNeeds): Promise<AgentAdapter>;
191
220
  /** Why `harness` cannot run here, or undefined when it can: its package and pins, its provider, and the adapter's own
192
221
  * check of the model `given` names (with none, a model of the harness's own provider: whether it runs here at all).
package/dist/adapters.js CHANGED
@@ -1,10 +1,11 @@
1
1
  // The adapter a harness id runs on, and whether this server can run it. With a faux harness module (FAUX_HARNESS_ENV)
2
2
  // every id runs on run-adapters' faux harness, scripted by the module's `script(spec)`, as `--faux` runs pi on the
3
- // faux model. Otherwise codex runs on @parcha/agentrun-harness-codex and claude-agent on @parcha/agentrun-harness-claude, each
4
- // with serve's own model, price and endpoint, under the run's confinement, and claude-agent with its own web search
5
- // where the run's web_search resolves native, and codex with its own; a package or a pinned CLI that is missing says
6
- // so with the one line that installs it: an npm install beside serve, or, when serve runs from npx, the npx line that
7
- // runs it with the missing package (claude-agent's SDK, Codex).
3
+ // faux model. Otherwise codex runs on @parcha/agentrun-harness-codex, opencode on this server's own OpenCode adapter
4
+ // (src/harness-opencode) and claude-agent on @parcha/agentrun-harness-claude, each with serve's own model, price and
5
+ // endpoint, under the run's confinement, and claude-agent with its own web search where the run's web_search resolves
6
+ // native, and codex with its own; a package or a pinned CLI that is missing says so with the one line that installs it:
7
+ // an npm install beside serve, or, when serve runs from npx, the npx line that runs it with the missing package
8
+ // (claude-agent's SDK, Codex, OpenCode).
8
9
  import { existsSync, readFileSync } from "node:fs";
9
10
  import { dirname, join, resolve, sep } from "node:path";
10
11
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -19,6 +20,9 @@ import { NATIVE_SEARCH_ALLOWANCE_TOKENS } from "./cap.js";
19
20
  export const INSTALL = {
20
21
  "claude-agent": "npm install @parcha/agentrun-harness-claude @anthropic-ai/claude-agent-sdk@0.3.286 zod",
21
22
  codex: "npm install @parcha/agentrun-harness-codex @openai/codex@0.164.0",
23
+ // The server is named first, as the other lines name a package beside it: OpenCode's CLI is an optional peer of the
24
+ // server's own.
25
+ opencode: "npm install @parcha/agentrun-serve opencode-ai@1.19.5",
22
26
  };
23
27
  /** This server's version: an npx line names it, so the server it runs is the one that said what was missing. */
24
28
  const SERVE_VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
@@ -31,7 +35,7 @@ export const startedByNpx = (file = fileURLToPath(import.meta.url)) => file.spli
31
35
  * (`@parcha/agentrun@0.3.0`), so a hint names the command the person ran, not the server's own. */
32
36
  export const NPX_PACKAGE_ENV = "AGENTRUN_NPX_PACKAGE";
33
37
  /** The package each harness needs beside the server, as an npx line adds it. */
34
- const HARNESS_PACKAGES = ["@anthropic-ai/claude-agent-sdk", "@openai/codex"];
38
+ const HARNESS_PACKAGES = ["@anthropic-ai/claude-agent-sdk", "@openai/codex", "opencode-ai"];
35
39
  /** The version of `name` installed where Node would look for it from `from`, or undefined. */
36
40
  export function installedHere(name, from = fileURLToPath(import.meta.url)) {
37
41
  for (let dir = dirname(from);; dir = dirname(dir)) {
@@ -82,6 +86,9 @@ export function installHint(message, npmLine, spec, npx = startedByNpx(), env =
82
86
  /** For tests: a JSON `{command, args?, env?}` that speaks Codex's app-server protocol in place of Codex. agentrun-harness-codex
83
87
  * takes it only under its own guard (AGENTRUN_CODEX_STANDIN=1, under a test runner). */
84
88
  export const CODEX_STANDIN_ENV = "AGENTRUN_SERVE_CODEX_STANDIN";
89
+ /** For tests: a JSON `{command, args?, env?}` that speaks `opencode serve`'s HTTP API in place of OpenCode. The OpenCode
90
+ * adapter (src/harness-opencode) takes it only under its own guard (AGENTRUN_OPENCODE_STANDIN=1, under a test runner). */
91
+ export const OPENCODE_STANDIN_ENV = "AGENTRUN_SERVE_OPENCODE_STANDIN";
85
92
  /** The event of a harness's own lines in the run's log (its model proxy's refusals and failures): a failed run's message
86
93
  * is never taken from one (runs.ts lastLogLine). */
87
94
  export const HARNESS_LOG_EVENT = "harness";
@@ -134,9 +141,9 @@ export class HarnessUnavailable extends Error {
134
141
  /** What an adapter's own setup error says installing fixes, by its typed code: none for any other error. */
135
142
  function fixOf(error) {
136
143
  const code = error?.code;
137
- if (code === "CLAUDE_AGENT_NOT_INSTALLED" || code === "CODEX_NOT_INSTALLED")
144
+ if (code === "CLAUDE_AGENT_NOT_INSTALLED" || code === "CODEX_NOT_INSTALLED" || code === "OPENCODE_NOT_INSTALLED")
138
145
  return "install";
139
- if (code === "CLAUDE_AGENT_PIN_MISMATCH" || code === "CODEX_PIN_MISMATCH")
146
+ if (code === "CLAUDE_AGENT_PIN_MISMATCH" || code === "CODEX_PIN_MISMATCH" || code === "OPENCODE_PIN_MISMATCH")
140
147
  return "pins";
141
148
  return undefined;
142
149
  }
@@ -201,13 +208,13 @@ export function gatewayBase(setting, value) {
201
208
  throw wrong(`is ${url.protocol.replace(/:$/, "")}, not https`);
202
209
  return `${url.origin}${url.pathname.replace(/\/+$/, "").replace(/\/v1$/, "")}`;
203
210
  }
204
- /** The model key a run on `harness` (claude-agent or codex) of `model` (the revision's; none, the host's default for the
211
+ /** The model key a run on `harness` (claude-agent, codex, or opencode, which takes codex's route) of `model` (the revision's; none, the host's default for the
205
212
  * harness) takes: the one its requests carry on the route its provider below takes, as key-refusal.ts' runKeyOf names
206
213
  * it. codex: the gateway's when AGENT_MODEL_BASE_URL is set, else OpenAI's, or OpenRouter's on OpenRouter's route;
207
214
  * claude-agent: Anthropic's, for api.anthropic.com or ANTHROPIC_BASE_URL alike, or OpenRouter's on OpenRouter's route.
208
215
  * None for pi, whose keys are its models' (model.ts' modelKeys). */
209
216
  export function harnessModelKeys(harness, env, model) {
210
- if (harness !== "codex" && harness !== "claude-agent")
217
+ if (harness !== "codex" && harness !== "claude-agent" && harness !== "opencode")
211
218
  return [];
212
219
  const key = runKeyOf(env, harness, model);
213
220
  return key ? [key.field] : [];
@@ -215,6 +222,10 @@ export function harnessModelKeys(harness, env, model) {
215
222
  /** OpenRouter's API: its Anthropic Messages endpoint (`<base>/v1/messages`) and its Responses API (`<base>/v1/responses`)
216
223
  * under one base, its key taken as a bearer token. The OpenRouter key goes nowhere else. */
217
224
  export const OPENROUTER_BASE = "https://openrouter.ai/api";
225
+ /** Anthropic's own origin, where pi-ai's Anthropic provider sends (a gateway is not it). */
226
+ export const ANTHROPIC_ORIGIN = "https://api.anthropic.com";
227
+ /** OpenAI's own origin, where pi-ai's OpenAI provider sends. */
228
+ export const OPENAI_ORIGIN = "https://api.openai.com";
218
229
  export { openRouterOnly };
219
230
  /** OpenRouter's key, read per request, refused by name where it is not set (a model named on OpenRouter, a host
220
231
  * without its key). */
@@ -223,28 +234,28 @@ function openRouterKey(env, harness, named) {
223
234
  throw new HarnessUnavailable(`${harness} runs ${named} through OpenRouter, which needs OPENROUTER_API_KEY.`, undefined, ["OPENROUTER_API_KEY"]);
224
235
  return () => env.OPENROUTER_API_KEY ?? "";
225
236
  }
226
- export function codexProvider(env, model) {
237
+ export function codexProvider(env, model, harness = "codex") {
227
238
  if (env.AGENT_MODEL_BASE_URL)
228
239
  return { origin: gatewayBase("AGENT_MODEL_BASE_URL", env.AGENT_MODEL_BASE_URL), credential: () => env.AGENT_MODEL_API_KEY || "none", modelId: model.modelId };
229
240
  const named = `${model.provider}/${model.modelId}`;
230
241
  if (model.provider === "openrouter" && model.modelId.startsWith("openai/"))
231
- return { origin: OPENROUTER_BASE, credential: openRouterKey(env, "codex", named), modelId: model.modelId };
242
+ return { origin: OPENROUTER_BASE, credential: openRouterKey(env, harness, named), modelId: model.modelId };
232
243
  if (model.provider !== "openai")
233
- throw new HarnessUnavailable(`codex runs OpenAI models; the run's model is ${named}.`);
234
- if (openRouterOnly("codex", env))
235
- return { origin: OPENROUTER_BASE, credential: openRouterKey(env, "codex", named), modelId: named };
244
+ throw new HarnessUnavailable(`${harness} runs OpenAI models; the run's model is ${named}.`);
245
+ if (openRouterOnly(harness, env))
246
+ return { origin: OPENROUTER_BASE, credential: openRouterKey(env, harness, named), modelId: named };
236
247
  if (!env.OPENAI_API_KEY)
237
- throw new HarnessUnavailable("codex needs OPENAI_API_KEY, OPENROUTER_API_KEY (OpenAI's models through OpenRouter), or a gateway in AGENT_MODEL_BASE_URL.", undefined, ["OPENAI_API_KEY", "OPENROUTER_API_KEY"]);
238
- return { origin: "https://api.openai.com", credential: () => env.OPENAI_API_KEY ?? "", modelId: model.modelId };
248
+ throw new HarnessUnavailable(`${harness} needs OPENAI_API_KEY, OPENROUTER_API_KEY (OpenAI's models through OpenRouter), or a gateway in AGENT_MODEL_BASE_URL.`, undefined, ["OPENAI_API_KEY", "OPENROUTER_API_KEY"]);
249
+ return { origin: OPENAI_ORIGIN, credential: () => env.OPENAI_API_KEY ?? "", modelId: model.modelId };
239
250
  }
240
- /** codex's model for `ref` (a revision's; none, the host's default for codex): as model.ts chooses it, except where
241
- * codex reaches OpenAI only through OpenRouter (openRouterOnly), where an OpenAI model needs no OpenAI key, only a
251
+ /** codex's model for `ref` (a revision's; none, the host's default for codex), or opencode's (`harness`), which takes
252
+ * codex's route: as model.ts chooses it, except where it reaches OpenAI only through OpenRouter (openRouterOnly), where an OpenAI model needs no OpenAI key, only a
242
253
  * model pi-ai's catalog lists (it prices the run): OpenRouter's key is the one codexProvider sends. A save, a run and
243
254
  * capabilities all ask this. */
244
- export async function codexModel(env, ref) {
245
- const named = ref ?? hostModel(env, "default", "codex");
246
- if (env[FAUX_ENV] || env[FAUX_HARNESS_ENV] || !openRouterOnly("codex", env) || !named?.startsWith("openai/"))
247
- return chooseModel(env, ref, "default", "codex");
255
+ export async function codexModel(env, ref, harness = "codex") {
256
+ const named = ref ?? hostModel(env, "default", harness);
257
+ if (env[FAUX_ENV] || env[FAUX_HARNESS_ENV] || !openRouterOnly(harness, env) || !named?.startsWith("openai/"))
258
+ return chooseModel(env, ref, "default", harness);
248
259
  const modelId = named.slice("openai/".length);
249
260
  const { builtinModels } = await import("@earendil-works/pi-ai/providers/all");
250
261
  if (!builtinModels().getModel("openai", modelId))
@@ -281,7 +292,7 @@ export function claudeProvider(env, model) {
281
292
  return { origin: OPENROUTER_BASE, credential: openRouterKey(env, "claude-agent", named), auth: "bearer", modelId: own, priceModel: { provider: "openrouter", id: `anthropic/${openRouterName(own)}` } };
282
293
  // The endpoint first: one it refuses is the reason, and no key would fix it (no `keys`). An endpoint the host names
283
294
  // takes Anthropic's key alone: OpenRouter's never goes there.
284
- const origin = env.ANTHROPIC_BASE_URL ? gatewayBase("ANTHROPIC_BASE_URL", env.ANTHROPIC_BASE_URL) : "https://api.anthropic.com";
295
+ const origin = env.ANTHROPIC_BASE_URL ? gatewayBase("ANTHROPIC_BASE_URL", env.ANTHROPIC_BASE_URL) : ANTHROPIC_ORIGIN;
285
296
  if (!env.ANTHROPIC_API_KEY)
286
297
  throw env.ANTHROPIC_BASE_URL ? new HarnessUnavailable("claude-agent needs ANTHROPIC_API_KEY.", undefined, ["ANTHROPIC_API_KEY"]) : new HarnessUnavailable("claude-agent needs ANTHROPIC_API_KEY or OPENROUTER_API_KEY.", undefined, ["ANTHROPIC_API_KEY", "OPENROUTER_API_KEY"]);
287
298
  return { origin, credential: () => env.ANTHROPIC_API_KEY ?? "", auth: "x-api-key", modelId: own, priceModel: { provider: "anthropic", id: own } };
@@ -306,6 +317,95 @@ export function claudePriceModel(env, model) {
306
317
  return { ...model, modelId: claudeModelId(model) };
307
318
  }
308
319
  }
320
+ /** The model a learned workflow's requests on `harness` name in the run's models (pi-ai's catalog, app.ts): the route
321
+ * the harness's own requests take (claudeProvider, codexProvider). Through OpenRouter, OpenRouter's name for the run's
322
+ * model, whose key the run holds and whose entry prices it; the vendor's provider would need the vendor's key, which a
323
+ * run on OpenRouter alone does not have. Otherwise the run's model as it is (Anthropic's own id for claude-agent); under
324
+ * a faux harness, through codex's gateway (AGENT_MODEL_BASE_URL), or where the harness refuses the run (before any
325
+ * request), `model` itself. */
326
+ export function learnedRoute(harness, env, model) {
327
+ if (env[FAUX_ENV] || env[FAUX_HARNESS_ENV])
328
+ return model;
329
+ try {
330
+ if (harness === "claude-agent") {
331
+ const { origin, auth, priceModel } = claudeProvider(env, model);
332
+ // OpenRouter's own route only (its key, as a bearer token): a gateway named by ANTHROPIC_BASE_URL, even at
333
+ // OpenRouter's URL, takes Anthropic's key (x-api-key), and learnedWorkflowsOff withholds learned workflows there.
334
+ return origin === OPENROUTER_BASE && auth === "bearer" ? { provider: "openrouter", modelId: priceModel.id } : { ...model, modelId: claudeModelId(model) };
335
+ }
336
+ if (harness === "codex" || harness === "opencode") {
337
+ // Through a gateway (AGENT_MODEL_BASE_URL), even one at OpenRouter's URL, the run's models hold the gateway's
338
+ // provider (runModels), not OpenRouter's: its model is the one prepared. opencode takes codex's route.
339
+ if (env.AGENT_MODEL_BASE_URL)
340
+ return model;
341
+ const { origin, modelId } = codexProvider(env, model, harness);
342
+ return origin === OPENROUTER_BASE ? { provider: "openrouter", modelId } : model;
343
+ }
344
+ }
345
+ catch {
346
+ // The harness refuses this run before any request: nothing is sent on this model.
347
+ }
348
+ return model;
349
+ }
350
+ /** Why a run on `harness` is offered no learned workflow, or undefined when it is. A learned workflow's model requests go
351
+ * through the run's models (pi-ai's catalog, learnedRoute), whose Anthropic provider reaches api.anthropic.com alone:
352
+ * claude-agent through the operator's own gateway (ANTHROPIC_BASE_URL) would have them go around it, with its key. So
353
+ * that run gets none (fail closed), and its pin says why. codex and opencode (codex's route) the same, at any origin
354
+ * learnedOriginOk does not name; their gateway is the run's models' own (runModels), and pi runs on them. A run its
355
+ * harness refuses sends nothing, so it is not this one's to say. */
356
+ export async function learnedWorkflowsOff(harness, env, ref) {
357
+ if (env[FAUX_ENV] || env[FAUX_HARNESS_ENV])
358
+ return undefined;
359
+ let origin;
360
+ if (harness === "claude-agent") {
361
+ const choice = claudeModel(env, ref);
362
+ if ("why" in choice)
363
+ return undefined;
364
+ let chosen;
365
+ try {
366
+ chosen = claudeProvider(env, choice.model);
367
+ }
368
+ catch {
369
+ return undefined;
370
+ }
371
+ // On the route the run chose: the operator's gateway (ANTHROPIC_BASE_URL with Anthropic's key, x-api-key), at any
372
+ // URL, OpenRouter's too, is one a learned node's provider could not follow. OpenRouter's own route (its key, bearer)
373
+ // never goes there, whatever ANTHROPIC_BASE_URL says.
374
+ if (chosen.auth === "x-api-key" && env.ANTHROPIC_BASE_URL)
375
+ return "claude-agent sends this run's model requests to the gateway at ANTHROPIC_BASE_URL, and a learned workflow's requests could not go through it";
376
+ origin = chosen.origin;
377
+ }
378
+ else if (harness === "codex" || harness === "opencode") {
379
+ const choice = await codexModel(env, ref, harness);
380
+ if ("why" in choice)
381
+ return undefined;
382
+ try {
383
+ origin = codexProvider(env, choice.model, harness).origin;
384
+ }
385
+ catch {
386
+ return undefined;
387
+ }
388
+ }
389
+ else
390
+ return undefined;
391
+ if (learnedOriginOk(harness, origin, env))
392
+ return undefined;
393
+ return harness === "claude-agent"
394
+ ? "claude-agent sends this run's model requests to the gateway at ANTHROPIC_BASE_URL, and a learned workflow's requests could not go through it"
395
+ : `${harness} sends this run's model requests to ${origin}, where a learned workflow's requests could not follow`;
396
+ }
397
+ /** Whether a learned workflow's requests reach `origin`, where `harness` sends the run's own (learnedWorkflowsOff): the
398
+ * run's models hold Anthropic's, OpenAI's and OpenRouter's providers, and, for codex and opencode (runModels), the
399
+ * gateway at AGENT_MODEL_BASE_URL. Any other origin is not one they can follow. */
400
+ export function learnedOriginOk(harness, origin, env) {
401
+ if (origin === OPENROUTER_BASE)
402
+ return true;
403
+ if (harness === "claude-agent")
404
+ return origin === ANTHROPIC_ORIGIN;
405
+ if (harness === "codex" || harness === "opencode")
406
+ return origin === OPENAI_ORIGIN || Boolean(env.AGENT_MODEL_BASE_URL);
407
+ return true;
408
+ }
309
409
  /** claude-agent's model: the revision's (or the server's default for claude-agent, hostModel) as `provider/model-id`.
310
410
  * Never the gateway's model, which serves the other harnesses. An Anthropic model (`anthropic/<id>`) is Anthropic's
311
411
  * own id, dots as dashes, except where claude-agent reaches Anthropic only through OpenRouter (openRouterOnly), where it
@@ -395,8 +495,9 @@ export async function claudeOf(env, needs, load = loadClaude, npx = startedByNpx
395
495
  throw refused;
396
496
  return adapter;
397
497
  }
398
- /** The run's thinking level as the harness takes it: serve's levels run to max; Codex's reasoning efforts stop at xhigh. */
399
- export const thinkingFor = (harness, level) => (harness === "codex" && level === "max" ? "xhigh" : level);
498
+ /** The run's thinking level as the harness takes it: serve's levels run to max; Codex's and OpenCode's reasoning efforts
499
+ * (OpenAI's) stop at xhigh. */
500
+ export const thinkingFor = (harness, level) => ((harness === "codex" || harness === "opencode") && level === "max" ? "xhigh" : level);
400
501
  /** The bare id Codex takes: serve's "openai/<id>" without its provider. */
401
502
  /** codex's adapter, from `load` (the installed package; a test gives its own). */
402
503
  export async function codexOf(env, needs, load = () => import("@parcha/agentrun-harness-codex"), npx = startedByNpx()) {
@@ -418,6 +519,29 @@ export async function codexOf(env, needs, load = () => import("@parcha/agentrun-
418
519
  const provider = codexProvider(env, needs.model);
419
520
  return codex.codexAdapter({ model: provider.modelId, provider: { origin: provider.origin, credential: provider.credential }, price: priceOf(needs), log: harnessLog("codex", env), ...(nativeOptions("codex", env).webSearch === "live" ? { webSearch: "live" } : {}), ...(needs.confine ? { confine: needs.confine } : {}), ...(standIn ? { standIn } : {}) });
420
521
  }
522
+ /** opencode's adapter, from `load` (the installed package; a test gives its own). Its model goes where codex's does: serve's
523
+ * gateway (AGENT_MODEL_BASE_URL) or OpenAI, on the Responses API, through the adapter's proxy. */
524
+ export async function opencodeOf(env, needs, load = () => import("./harness-opencode/index.js"), npx = startedByNpx()) {
525
+ const opencode = await load().catch(() => {
526
+ throw new HarnessUnavailable(`opencode is not installed here: ${INSTALL.opencode}`, "install");
527
+ });
528
+ const standIn = env[OPENCODE_STANDIN_ENV] ? JSON.parse(env[OPENCODE_STANDIN_ENV]) : undefined;
529
+ if (!standIn) {
530
+ try {
531
+ opencode.verifyOpenCode();
532
+ }
533
+ catch (error) {
534
+ // serve's own line, which installs the adapter with its pinned CLI, in place of the adapter's (the CLI alone).
535
+ const message = error.message.replace(opencode.OPENCODE_INSTALL, INSTALL.opencode);
536
+ throw unavailable("opencode", Object.assign(new Error(message), { code: error?.code }), { npmLine: INSTALL.opencode, spec: `opencode-ai@${opencode.OPENCODE_VERSION}` }, npx, env);
537
+ }
538
+ }
539
+ // The shared date line (environment.ts) reaches OpenCode in the session's system prompt (app.ts), as it reaches every
540
+ // harness.
541
+ // The id as the provider's endpoint names it (codexProvider, as codexOf takes it): OpenRouter's is the whole slug.
542
+ const provider = codexProvider(env, needs.model, "opencode");
543
+ return opencode.openCodeAdapter({ model: provider.modelId, provider: { origin: provider.origin, credential: provider.credential }, price: priceOf(needs), log: harnessLog("opencode", env), ...(needs.confine ? { confine: needs.confine } : {}), ...(standIn ? { standIn } : {}) });
544
+ }
421
545
  export async function adapterFor(harness, env, needs) {
422
546
  const faux = env[FAUX_HARNESS_ENV];
423
547
  if (faux) {
@@ -430,6 +554,8 @@ export async function adapterFor(harness, env, needs) {
430
554
  }
431
555
  if (harness === "codex")
432
556
  return codexOf(env, needs);
557
+ if (harness === "opencode")
558
+ return opencodeOf(env, needs);
433
559
  if (harness === "claude-agent")
434
560
  return claudeOf(env, needs);
435
561
  throw new HarnessUnavailable(`This server does not run ${harness} yet.`);
package/dist/agents.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { type Agent, type AgentStore, type NewRevision, type Revision, type RevisionRow } from "@parcha/pi-durable-agent";
1
+ import { type Agent, type AgentStore, type NewRevision, type Revision, type RevisionPlace, type RevisionRow } from "@parcha/pi-durable-agent";
2
2
  import { ApiError } from "./errors.js";
3
3
  import { type DefinitionBody, type Json } from "./validate.js";
4
+ import type { SignInView } from "./sign-ins.js";
4
5
  /** One agent as the routes show it: its row, its current revision and that revision's number (the oldest is 1). */
5
6
  export type AgentEntry = {
6
7
  agent: Agent;
@@ -49,7 +50,12 @@ export declare class Agents {
49
50
  private checked;
50
51
  /** A new agent and its first revision, current. A definition id already here is `409 agent_exists`. `check` sees the
51
52
  * revision before anything is written, and may refuse it. */
52
- create({ definition, skills, note }: DefinitionBody, check?: (revision: NewRevision) => Promise<void>): Promise<AgentEntry>;
53
+ /** `fresh`: the place a new agent that names none is saved with, and the tools it gets when it names none (place.ts
54
+ * newAgentPlace); an agentic definition alone takes them, and only where it leaves them out. */
55
+ create({ definition, skills, note }: DefinitionBody, check?: (revision: NewRevision) => Promise<void>, fresh?: {
56
+ place: RevisionPlace;
57
+ tools: readonly string[];
58
+ }): Promise<AgentEntry>;
53
59
  /** An edit: a new revision of the agent, its parent the current one, made current. Without `skills` the current
54
60
  * revision's skill files carry over. An edit that is the current revision writes nothing, so a PUT sent twice makes
55
61
  * one revision. The store keeps an agent's id, name and description from its creation. `ifCurrent` (from If-Match)
@@ -85,8 +91,15 @@ export declare class Agents {
85
91
  export declare const etagOf: (entry: AgentEntry) => string;
86
92
  /** A revision as a definition, as `POST /agents` takes one, numbered. */
87
93
  export declare function definitionOf(agent: Agent, revision: Revision, version: number): Json;
88
- /** `Agent` as the contract shows it, with its current revision. */
89
- export declare function agentView(entry: AgentEntry): {
94
+ /** `Agent` as the contract shows it, with its current revision and its saved sign-ins (sign-ins.ts view: never a ref). */
95
+ export declare function agentView(entry: AgentEntry, signIns?: readonly SignInView[], learning?: {
96
+ pending: number;
97
+ }): {
98
+ created_at: string;
99
+ updated_at: string;
100
+ learning?: {
101
+ pending: number;
102
+ } | undefined;
90
103
  agent_id: string;
91
104
  definition: Json | null;
92
105
  kind: "workflow" | "agentic" | null;
@@ -98,7 +111,7 @@ export declare function agentView(entry: AgentEntry): {
98
111
  sha256: string;
99
112
  size_bytes: number | null;
100
113
  }[];
101
- sign_ins: never[];
114
+ sign_ins: readonly SignInView[];
102
115
  runs: {
103
116
  count: number;
104
117
  live: number;
@@ -106,8 +119,6 @@ export declare function agentView(entry: AgentEntry): {
106
119
  region: string;
107
120
  home_etag: string;
108
121
  archived_at: string | null;
109
- created_at: string;
110
- updated_at: string;
111
122
  };
112
123
  /** One revision as `GET .../revisions` lists it. */
113
124
  export declare function revisionView(agent: Agent, row: RevisionRow & {
package/dist/agents.js CHANGED
@@ -106,7 +106,7 @@ export class Agents {
106
106
  // The learning switch is kept whenever a definition sets it, false included; a definition that leaves it out keeps
107
107
  // none, and its revision id is the one it had before the switch.
108
108
  const learning = typeof definition.learning === "boolean" ? { learning: definition.learning } : {};
109
- return { kind: "agentic", instructions: definition.instructions, ...(typeof definition.model === "string" ? { model: definition.model } : {}), ...(typeof definition.thinking === "string" ? { thinking: definition.thinking } : {}), ...common, ...learning };
109
+ return { kind: "agentic", instructions: definition.instructions, ...(typeof definition.model === "string" ? { model: definition.model } : {}), ...(typeof definition.thinking === "string" ? { thinking: definition.thinking } : {}), ...common, ...learning, ...(typeof definition.max_cost_usd === "number" && definition.max_cost_usd > 0 ? { maxCostUsd: definition.max_cost_usd } : {}) };
110
110
  }
111
111
  /** `definition.version`, when given, is the number of the revision the request leaves current. */
112
112
  checkVersion(definition, version) {
@@ -122,11 +122,15 @@ export class Agents {
122
122
  }
123
123
  /** A new agent and its first revision, current. A definition id already here is `409 agent_exists`. `check` sees the
124
124
  * revision before anything is written, and may refuse it. */
125
- async create({ definition, skills = {}, note }, check) {
125
+ /** `fresh`: the place a new agent that names none is saved with, and the tools it gets when it names none (place.ts
126
+ * newAgentPlace); an agentic definition alone takes them, and only where it leaves them out. */
127
+ async create({ definition, skills = {}, note }, check, fresh) {
126
128
  const given = typeof definition.id === "string" ? definition.id : undefined;
127
129
  if (given !== undefined && (await this.request(() => this.store.readAgent(given))))
128
130
  throw new ApiError("agent_exists", `an agent ${given} exists here`);
129
- const revision = this.revisionOf(definition, skills, note);
131
+ // Stamped on the revision now, never resolved at run time: an agent saved with no place keeps running on the runner.
132
+ const stamped = fresh && definition.place === undefined && !isObject(definition.workflow) ? { place: fresh.place, ...(definition.tools === undefined ? { tools: [...fresh.tools] } : {}) } : {};
133
+ const revision = this.revisionOf({ ...definition, ...stamped }, skills, note);
130
134
  this.checkVersion(definition, 1);
131
135
  await this.checked(revision);
132
136
  await check?.(revision);
@@ -178,12 +182,14 @@ export class Agents {
178
182
  const texts = await this.request(() => this.texts(held.map(([, sha]) => sha)));
179
183
  files = Object.fromEntries(held.map(([path, sha]) => [path, texts.get(sha) ?? ""]));
180
184
  }
181
- // An edit that names no harness, place or learning switch keeps the agent's, as it keeps its skill files: absent
182
- // here is unchanged, not the default.
185
+ // An edit that names no harness, place, learning switch or default cap keeps the agent's, as it keeps its skill
186
+ // files: absent here is unchanged, not the default.
183
187
  const harness = entry.revision?.body.harness;
184
188
  const place = entry.revision?.body.place;
185
189
  const learning = entry.revision?.kind === "agentic" && !isObject(definition.workflow) ? entry.revision.body.learning : undefined;
186
- const revision = this.revisionOf({ ...definition, ...(definition.harness === undefined && harness ? { harness } : {}), ...(definition.place === undefined && place ? { place } : {}), ...(definition.learning === undefined && learning !== undefined ? { learning } : {}) }, files, note);
190
+ // And its default cap: leaving it out never removes a spend limit; only 0 clears it.
191
+ const cap = entry.revision?.kind === "agentic" && !isObject(definition.workflow) ? entry.revision.body.maxCostUsd : undefined;
192
+ const revision = this.revisionOf({ ...definition, ...(definition.harness === undefined && harness ? { harness } : {}), ...(definition.place === undefined && place ? { place } : {}), ...(definition.learning === undefined && learning !== undefined ? { learning } : {}), ...(definition.max_cost_usd === undefined && cap !== undefined ? { max_cost_usd: cap } : {}) }, files, note);
187
193
  await this.checked(revision);
188
194
  await check?.(revision);
189
195
  const base = entry.revision?.id ?? null;
@@ -272,12 +278,12 @@ export const etagOf = (entry) => `"${entry.revision?.id ?? "none"}"`;
272
278
  /** A revision as a definition, as `POST /agents` takes one, numbered. */
273
279
  export function definitionOf(agent, revision, version) {
274
280
  const body = revision.kind === "agentic"
275
- ? { instructions: revision.body.instructions, ...(revision.body.model ? { model: revision.body.model } : {}), ...(revision.body.thinking ? { thinking: revision.body.thinking } : {}), ...(revision.body.learning !== undefined ? { learning: revision.body.learning } : {}) }
281
+ ? { instructions: revision.body.instructions, ...(revision.body.model ? { model: revision.body.model } : {}), ...(revision.body.thinking ? { thinking: revision.body.thinking } : {}), ...(revision.body.learning !== undefined ? { learning: revision.body.learning } : {}), ...(revision.body.maxCostUsd !== undefined ? { max_cost_usd: revision.body.maxCostUsd } : {}) }
276
282
  : { workflow: revision.body.workflow };
277
283
  return { id: agent.id, version, name: agent.name, ...(agent.description !== undefined ? { description: agent.description } : {}), ...body, harness: harnessOfBody(revision.body), ...(revision.body.place ? { place: revision.body.place } : {}), skills: skillNames(Object.keys(revision.body.skills)), tools: revision.body.tools, ...(revision.body.toolSettings ? { tool_settings: revision.body.toolSettings } : {}) };
278
284
  }
279
- /** `Agent` as the contract shows it, with its current revision. */
280
- export function agentView(entry) {
285
+ /** `Agent` as the contract shows it, with its current revision and its saved sign-ins (sign-ins.ts view: never a ref). */
286
+ export function agentView(entry, signIns = [], learning) {
281
287
  const { agent, revision } = entry;
282
288
  return {
283
289
  agent_id: agent.id,
@@ -287,11 +293,14 @@ export function agentView(entry) {
287
293
  revisions: entry.revisions,
288
294
  source: null,
289
295
  skills: Object.entries(revision?.body.skills ?? {}).map(([path, sha]) => ({ path, sha256: sha, size_bytes: entry.sizes.get(sha) ?? null })),
290
- sign_ins: [],
296
+ sign_ins: signIns,
291
297
  runs: entry.runs,
292
298
  region: "local",
293
299
  home_etag: etagOf(entry),
294
300
  archived_at: agent.archivedAt ?? null,
301
+ // How many of its learned items wait for its owner's OK (learning-routes.ts pendingCount): only for an agent that
302
+ // learns on a server whose learning is on.
303
+ ...(learning ? { learning } : {}),
295
304
  created_at: agent.createdAt,
296
305
  updated_at: revision && revision.createdAt > agent.createdAt ? revision.createdAt : agent.createdAt,
297
306
  };