@parcha/agentrun-serve 0.1.0-beta.55 → 0.1.0-beta.56

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 (80) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +44 -10
  3. package/dist/adapters.d.ts +3 -2
  4. package/dist/adapters.js +6 -3
  5. package/dist/answer-json.d.ts +6 -2
  6. package/dist/answer-json.js +22 -4
  7. package/dist/api-only.js +2 -0
  8. package/dist/calendar/tools.js +3 -2
  9. package/dist/chatgpt-plan.d.ts +16 -1
  10. package/dist/chatgpt-plan.js +116 -12
  11. package/dist/claude-login.d.ts +34 -5
  12. package/dist/claude-login.js +31 -7
  13. package/dist/claude-sign-in.d.ts +35 -0
  14. package/dist/claude-sign-in.js +90 -0
  15. package/dist/console/assets/{backend-D5EmB4N3.js → backend-Boh7tC4i.js} +1 -1
  16. package/dist/console/assets/{index-DUYLaqiR.js → index-CQ3cJRzI.js} +130 -130
  17. package/dist/console/assets/index-DKkaS3a0.css +1 -0
  18. package/dist/console/index.html +2 -2
  19. package/dist/host-check.d.ts +4 -0
  20. package/dist/host-check.js +4 -0
  21. package/dist/key-refusal.d.ts +21 -5
  22. package/dist/key-refusal.js +231 -37
  23. package/dist/learn/secrets.d.ts +20 -10
  24. package/dist/learn/secrets.js +44 -184
  25. package/dist/llms.txt +1 -1
  26. package/dist/openapi.d.ts +3 -3
  27. package/dist/openapi.js +70 -18
  28. package/dist/place-offers.d.ts +14 -6
  29. package/dist/place-offers.js +26 -13
  30. package/dist/redact/match.d.ts +74 -0
  31. package/dist/redact/match.js +771 -0
  32. package/dist/run-timeline-served.d.ts +1 -1
  33. package/dist/run-timeline-served.js +4 -4
  34. package/dist/runner/adapter-loop.d.ts +3 -0
  35. package/dist/runner/adapter-loop.js +1 -1
  36. package/dist/runner/adapter-run-spec.js +4 -1
  37. package/dist/runner/beside.js +7 -3
  38. package/dist/runner/cli-run-spec.js +3 -1
  39. package/dist/runner/loop-contract.d.ts +4 -0
  40. package/dist/runner/main.js +8 -4
  41. package/dist/runner/presence.d.ts +4 -3
  42. package/dist/runner/presence.js +4 -2
  43. package/dist/runner/run-child-host.d.ts +2 -0
  44. package/dist/runner/run-child-host.js +2 -2
  45. package/dist/runner/runner.d.ts +4 -0
  46. package/dist/runner/runner.js +33 -3
  47. package/dist/server.d.ts +5 -2
  48. package/dist/server.js +41 -10
  49. package/dist/store/dialect.d.ts +3 -0
  50. package/dist/store/dialect.js +1 -0
  51. package/dist/store/index.d.ts +1 -1
  52. package/dist/store/index.js +1 -1
  53. package/dist/store/postgres/dialect.js +3 -0
  54. package/dist/store/sqlite/store.js +43 -13
  55. package/dist/store/store.d.ts +10 -1
  56. package/dist/store/store.js +7 -0
  57. package/dist/store-view.js +1 -1
  58. package/dist/template-eval.d.ts +2 -2
  59. package/dist/template-eval.js +9 -8
  60. package/dist/timeline/index.d.ts +1 -1
  61. package/dist/timeline/index.js +1 -1
  62. package/dist/timeline/timeline.d.ts +12 -7
  63. package/dist/timeline/timeline.js +14 -6
  64. package/dist/tool-gate.js +3 -1
  65. package/dist/validate.js +1 -1
  66. package/dist/workspace/computer-deps.d.ts +2 -1
  67. package/dist/workspace/computer-deps.js +5 -4
  68. package/dist/workspace/computer-for-claim.d.ts +8 -2
  69. package/dist/workspace/computer-for-claim.js +28 -9
  70. package/dist/workspace/computer-janitor.d.ts +15 -7
  71. package/dist/workspace/computer-janitor.js +33 -8
  72. package/dist/workspace/computer-kept.d.ts +52 -4
  73. package/dist/workspace/computer-kept.js +118 -6
  74. package/dist/workspace/run-end-computers.d.ts +5 -1
  75. package/dist/workspace/run-end-computers.js +27 -1
  76. package/dist/wrapped.d.ts +57 -0
  77. package/dist/wrapped.js +51 -0
  78. package/package.json +11 -11
  79. package/templates/README.md +8 -7
  80. package/dist/console/assets/index-DYhU4adm.css +0 -1
@@ -1,4 +1,5 @@
1
1
  import type { ClaudeAgentLogin, ClaudeLoginStatus } from "@parcha/agentrun-harness-claude";
2
+ import type { ClaudeSignIns, SignInView } from "./claude-sign-in.js";
2
3
  import type { Settings } from "./store/index.js";
3
4
  /** The switch: `off` (or 0, false, no) turns the mode off on this server, `on` (or 1, true, yes) leaves it there past
4
5
  * loopback; unset, the listen address decides (claudeLoginSwitchedOff). */
@@ -26,7 +27,21 @@ type Setting = {
26
27
  host: string;
27
28
  only_me: true;
28
29
  };
29
- /** The directories of a login at `place`: AgentRun's in `data`, or this machine's (the CLI's own defaults for its user). */
30
+ /** This machine's own Claude Code login folder as the CLI finds it for the server's user, by the CLI's own rule: its
31
+ * config dir is `CLAUDE_CONFIG_DIR` when set, else `~/.claude`, and its credentials are kept there too unless
32
+ * `CLAUDE_SECURESTORAGE_CONFIG_DIR` says otherwise. Read from the server's env, so a Claude Code started with another
33
+ * `CLAUDE_CONFIG_DIR` is found only when AgentRun was started with it as well. A relative one is not taken: the CLI would
34
+ * read it against a working directory this server does not share. `source` says which rule gave the folder. */
35
+ export declare function machineFolder(env?: Readonly<Record<string, string | undefined>>): {
36
+ folder: string;
37
+ source: "CLAUDE_CONFIG_DIR" | "default";
38
+ };
39
+ /** The directories of a login at `place`: AgentRun's in `data`, or this machine's (machineFolder, and the Anthropic
40
+ * profiles where the CLI looks for them: `ANTHROPIC_CONFIG_DIR`, else `$XDG_CONFIG_HOME/anthropic`, else
41
+ * `~/.config/anthropic`). This machine's on the CLI's default folder carries the person's home too, so the harness
42
+ * points the CLI at it as their own CLI runs, with no folder variable (the harness's signInEnv and loginEnv). This
43
+ * machine's is `shared` with the person's own CLI, so a status check runs on a copy of its account file
44
+ * (the harness's claudeLoginStatus). */
30
45
  export declare function loginAt(place: LoginPlace, data: string, env?: Readonly<Record<string, string | undefined>>): ClaudeAgentLogin;
31
46
  /** The setting as saved, or undefined when the mode is not on (or the row is not one this reads). */
32
47
  export declare function claudeLoginSetting(settings: Pick<Settings, "get">): Promise<Setting | undefined>;
@@ -74,6 +89,15 @@ export type ClaudeLoginView = {
74
89
  organization?: string;
75
90
  plan?: string;
76
91
  };
92
+ /** The folder whose login the CLI is asked about: the login's directory at `place`. */
93
+ folder: string;
94
+ /** This machine's own Claude Code login as this server finds it (machineFolder). */
95
+ machine: {
96
+ folder: string;
97
+ source: "CLAUDE_CONFIG_DIR" | "default";
98
+ };
99
+ /** The CLI's sign-in this server started, while this server runs (claude-sign-in.ts). */
100
+ sign_in?: SignInView;
77
101
  };
78
102
  /** The account's words, as the view shows them. */
79
103
  export declare const accountOf: (status: ClaudeLoginStatus) => NonNullable<ClaudeLoginView["account"]>;
@@ -98,8 +122,10 @@ export declare const claudeLoginRouteOff: (name: string, why: string) => string;
98
122
  /** What the routes need of the server. `pinned`: the pinned CLI's path when installed. `refused`: whyNotOneOwner of this
99
123
  * server. `sameMachine`: the request comes from a browser on this machine to a server bound to loopback with no public
100
124
  * address, so a sign-in the CLI opens in a browser here reaches the person. `status`/`start`: the harness's
101
- * claudeLoginStatus and startClaudeLogin. `changed`: env read again after a turn on or off. */
125
+ * claudeLoginStatus and startClaudeLogin. `changed`: env read again after a turn on or off. `signIns`: the sign-in this
126
+ * server started, one per server process (claude-sign-in.ts). */
102
127
  export type ClaudeLoginDeps = {
128
+ signIns: ClaudeSignIns;
103
129
  settings: Pick<Settings, "get" | "put" | "remove">;
104
130
  data: string;
105
131
  env: Readonly<Record<string, string | undefined>>;
@@ -118,10 +144,13 @@ export declare class ClaudeLoginRefused extends Error {
118
144
  export declare function claudeLoginView(deps: ClaudeLoginDeps): Promise<ClaudeLoginView>;
119
145
  /** PUT /settings/claude-login: turned on, refused in one line where more than one person can start runs. */
120
146
  export declare function turnOnClaudeLogin(deps: ClaudeLoginDeps, body: unknown): Promise<ClaudeLoginView>;
121
- /** DELETE /settings/claude-login: turned off. The login itself stays as the CLI keeps it; nothing here signs it out. */
147
+ /** DELETE /settings/claude-login: turned off, and a sign-in this server started that still waits is ended. The login
148
+ * itself stays as the CLI keeps it; nothing here signs it out. */
122
149
  export declare function turnOffClaudeLogin(deps: ClaudeLoginDeps): Promise<ClaudeLoginView>;
123
- /** POST /settings/claude-login/login: the CLI's own sign-in, started on this machine, where it opens a browser. The
124
- * browser code goes to the CLI, never here; the answer is the view as it is when the sign-in starts. */
150
+ /** POST /settings/claude-login/login: the CLI's own sign-in, started on this machine, where it opens a browser, with the
151
+ * shown line's own variables (the harness's signInEnv), so it signs in where the status reads. A sign-in that
152
+ * still waits is ended first (deps.signIns). The browser code goes to the CLI, never here; the answer is the view as it
153
+ * is when the sign-in starts, its `sign_in` waiting. */
125
154
  export declare function startLoginHere(deps: ClaudeLoginDeps): Promise<ClaudeLoginView>;
126
155
  /** At the server's start: a setting saved where the mode is now off or refused (`why`: the switch, a listen address past
127
156
  * loopback, a second token, the API-only profile) goes, so no runner, in this process or another, runs on it; the reason
@@ -46,13 +46,30 @@ export const LOGIN_DEFAULT_MODEL = "anthropic/claude-sonnet-5-5";
46
46
  /** Where the login is: AgentRun's own directory in its data (`agentrun`, the default), or this machine's own Claude Code
47
47
  * login (`machine`, which the owner opts into by name). */
48
48
  export const LOGIN_PLACES = ["agentrun", "machine"];
49
- /** The directories of a login at `place`: AgentRun's in `data`, or this machine's (the CLI's own defaults for its user). */
49
+ /** This machine's own Claude Code login folder as the CLI finds it for the server's user, by the CLI's own rule: its
50
+ * config dir is `CLAUDE_CONFIG_DIR` when set, else `~/.claude`, and its credentials are kept there too unless
51
+ * `CLAUDE_SECURESTORAGE_CONFIG_DIR` says otherwise. Read from the server's env, so a Claude Code started with another
52
+ * `CLAUDE_CONFIG_DIR` is found only when AgentRun was started with it as well. A relative one is not taken: the CLI would
53
+ * read it against a working directory this server does not share. `source` says which rule gave the folder. */
54
+ export function machineFolder(env = process.env) {
55
+ if (env.CLAUDE_CONFIG_DIR && isAbsolute(env.CLAUDE_CONFIG_DIR))
56
+ return { folder: env.CLAUDE_CONFIG_DIR, source: "CLAUDE_CONFIG_DIR" };
57
+ const home = env.HOME && isAbsolute(env.HOME) ? env.HOME : homedir();
58
+ return { folder: join(home, ".claude"), source: "default" };
59
+ }
60
+ /** The directories of a login at `place`: AgentRun's in `data`, or this machine's (machineFolder, and the Anthropic
61
+ * profiles where the CLI looks for them: `ANTHROPIC_CONFIG_DIR`, else `$XDG_CONFIG_HOME/anthropic`, else
62
+ * `~/.config/anthropic`). This machine's on the CLI's default folder carries the person's home too, so the harness
63
+ * points the CLI at it as their own CLI runs, with no folder variable (the harness's signInEnv and loginEnv). This
64
+ * machine's is `shared` with the person's own CLI, so a status check runs on a copy of its account file
65
+ * (the harness's claudeLoginStatus). */
50
66
  export function loginAt(place, data, env = process.env) {
51
67
  if (place === "agentrun")
52
68
  return { dir: join(data, "claude-login"), profiles: join(data, "claude-login", "anthropic") };
53
69
  const home = env.HOME && isAbsolute(env.HOME) ? env.HOME : homedir();
54
70
  const config = env.XDG_CONFIG_HOME && isAbsolute(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : join(home, ".config");
55
- return { dir: join(home, ".claude"), profiles: env.ANTHROPIC_CONFIG_DIR && isAbsolute(env.ANTHROPIC_CONFIG_DIR) ? env.ANTHROPIC_CONFIG_DIR : join(config, "anthropic") };
71
+ const { folder, source } = machineFolder(env);
72
+ return { dir: folder, profiles: env.ANTHROPIC_CONFIG_DIR && isAbsolute(env.ANTHROPIC_CONFIG_DIR) ? env.ANTHROPIC_CONFIG_DIR : join(config, "anthropic"), ...(source === "default" ? { home } : {}), shared: true };
56
73
  }
57
74
  /** The setting as saved, or undefined when the mode is not on (or the row is not one this reads). */
58
75
  export async function claudeLoginSetting(settings) {
@@ -165,7 +182,8 @@ export async function claudeLoginView(deps) {
165
182
  const place = setting?.place ?? "agentrun";
166
183
  const login = loginAt(place, deps.data, deps.env);
167
184
  const cli = loginCli(await deps.pinned(), deps.env);
168
- const base = { place, command: (await deps.claude()).claudeLoginCommand(login, cli ?? "claude"), can_start: deps.sameMachine && cli !== undefined && deps.refused === undefined, ...(deps.refused ? { refused: deps.refused } : {}) };
185
+ const signIn = deps.signIns.view();
186
+ const base = { place, command: (await deps.claude()).claudeLoginCommand(login, cli ?? "claude"), can_start: deps.sameMachine && cli !== undefined && deps.refused === undefined, ...(deps.refused ? { refused: deps.refused } : {}), folder: login.dir, machine: machineFolder(deps.env), ...(signIn ? { sign_in: signIn } : {}) };
169
187
  if (!setting)
170
188
  return { state: "off", ...base };
171
189
  if (setting.host !== hostname())
@@ -191,14 +209,18 @@ export async function turnOnClaudeLogin(deps, body) {
191
209
  await deps.changed();
192
210
  return claudeLoginView(deps);
193
211
  }
194
- /** DELETE /settings/claude-login: turned off. The login itself stays as the CLI keeps it; nothing here signs it out. */
212
+ /** DELETE /settings/claude-login: turned off, and a sign-in this server started that still waits is ended. The login
213
+ * itself stays as the CLI keeps it; nothing here signs it out. */
195
214
  export async function turnOffClaudeLogin(deps) {
215
+ await deps.signIns.stop();
196
216
  await deps.settings.remove(CLAUDE_LOGIN_SETTING);
197
217
  await deps.changed();
198
218
  return claudeLoginView(deps);
199
219
  }
200
- /** POST /settings/claude-login/login: the CLI's own sign-in, started on this machine, where it opens a browser. The
201
- * browser code goes to the CLI, never here; the answer is the view as it is when the sign-in starts. */
220
+ /** POST /settings/claude-login/login: the CLI's own sign-in, started on this machine, where it opens a browser, with the
221
+ * shown line's own variables (the harness's signInEnv), so it signs in where the status reads. A sign-in that
222
+ * still waits is ended first (deps.signIns). The browser code goes to the CLI, never here; the answer is the view as it
223
+ * is when the sign-in starts, its `sign_in` waiting. */
202
224
  export async function startLoginHere(deps) {
203
225
  if (deps.refused)
204
226
  throw new ClaudeLoginRefused("forbidden", deps.refused);
@@ -213,7 +235,9 @@ export async function startLoginHere(deps) {
213
235
  if (!cli)
214
236
  throw new ClaudeLoginRefused("agent_not_runnable", "No Claude Code CLI here yet: claude-agent's first run installs it, or run the command shown.");
215
237
  // The person's home and desktop, so the CLI can open their browser.
216
- (await deps.claude()).startClaudeLogin(cli, loginAt(setting.place, deps.data, deps.env), { ...pathOf(deps.env), ...(deps.env.HOME ? { home: deps.env.HOME } : {}), display: deps.env });
238
+ const claude = await deps.claude();
239
+ const login = loginAt(setting.place, deps.data, deps.env);
240
+ await deps.signIns.start((timeoutMs) => claude.startClaudeLogin(cli, login, { ...pathOf(deps.env), ...(deps.env.HOME ? { home: deps.env.HOME } : {}), display: deps.env, timeoutMs }));
217
241
  return claudeLoginView(deps);
218
242
  }
219
243
  /** At the server's start: a setting saved where the mode is now off or refused (`why`: the switch, a listen address past
@@ -0,0 +1,35 @@
1
+ import type { ClaudeSignIn } from "@parcha/agentrun-harness-claude";
2
+ /** How long a sign-in waits for its browser by default: the harness's own limit. */
3
+ export declare const SIGN_IN_LIMIT_MS: number;
4
+ /** A sign-in as GET /settings/claude-login says it. `state`: `waiting` (for the browser, since `started_at`),
5
+ * `signed_in` (the CLI exited 0), `timed_out` (ended after `limit_ms` with no answer from the browser), `failed` (the
6
+ * CLI ended without signing in: `exit_code`, or the `signal` that ended it), `not_started` (the CLI could not be
7
+ * started: `error`). */
8
+ export type SignInView = {
9
+ state: "waiting" | "signed_in" | "timed_out" | "failed" | "not_started";
10
+ started_at: string;
11
+ ended_at?: string;
12
+ limit_ms: number;
13
+ exit_code?: number;
14
+ signal?: string;
15
+ error?: string;
16
+ };
17
+ /** The one sign-in this server started, and its start and stop. `limitMs`: how long a sign-in waits for its browser
18
+ * (SIGN_IN_LIMIT_MS by default; a test's is short). `now`: the clock its times are read from. */
19
+ export declare class ClaudeSignIns {
20
+ #private;
21
+ readonly limitMs: number;
22
+ constructor(options?: {
23
+ limitMs?: number;
24
+ now?: () => number;
25
+ });
26
+ /** The sign-in as it stands, or undefined when none was started here (or it was stopped). */
27
+ view(): SignInView | undefined;
28
+ /** Start a sign-in with `begin` (the harness's startClaudeLogin, given the limit), after ending one that waits. */
29
+ start(begin: (limitMs: number) => ClaudeSignIn): Promise<SignInView>;
30
+ /** End a sign-in that waits, and forget the one there is (a turn-off). */
31
+ stop(): Promise<void>;
32
+ /** The server's stop: as stop(), resolving once a CLI that waited is gone, and a start asked after it (a request still
33
+ * in flight) spawns nothing. A CLI left waiting would keep the browser's callback port from the next server's sign-in. */
34
+ close(): Promise<void>;
35
+ }
@@ -0,0 +1,90 @@
1
+ /** How long a sign-in waits for its browser by default: the harness's own limit. */
2
+ export const SIGN_IN_LIMIT_MS = 10 * 60_000;
3
+ const words = (error) => String(error?.message ?? error).slice(0, 200);
4
+ /** The view of a sign-in that ended as `end`. */
5
+ function endedView(started, end, at) {
6
+ const ended = { ...started, ended_at: at };
7
+ switch (end.end) {
8
+ case "exited":
9
+ if (end.code === 0)
10
+ return { ...ended, state: "signed_in" };
11
+ return { ...ended, state: "failed", ...(end.code !== null ? { exit_code: end.code } : {}), ...(end.signal ? { signal: end.signal } : {}) };
12
+ case "timed_out":
13
+ return { ...ended, state: "timed_out" };
14
+ case "failed":
15
+ return { ...ended, state: "not_started", error: end.message };
16
+ case "stopped":
17
+ // Only this server stops one, and it forgets it as it does (stop), so this view is never kept.
18
+ return { ...ended, state: "failed" };
19
+ }
20
+ }
21
+ /** The one sign-in this server started, and its start and stop. `limitMs`: how long a sign-in waits for its browser
22
+ * (SIGN_IN_LIMIT_MS by default; a test's is short). `now`: the clock its times are read from. */
23
+ export class ClaudeSignIns {
24
+ limitMs;
25
+ #now;
26
+ #current;
27
+ // Each start or stop is a turn of its own: an end that arrives after a later turn began is not kept.
28
+ #turn = 0;
29
+ // Starts and stops, one after another, so two presses at once never leave two CLIs waiting on one port.
30
+ #queue = Promise.resolve();
31
+ // Set at the server's stop (close): no start after it spawns a CLI.
32
+ #closed = false;
33
+ constructor(options = {}) {
34
+ this.limitMs = options.limitMs ?? SIGN_IN_LIMIT_MS;
35
+ this.#now = options.now ?? Date.now;
36
+ }
37
+ /** The sign-in as it stands, or undefined when none was started here (or it was stopped). */
38
+ view() {
39
+ return this.#current ? { ...this.#current.view } : undefined;
40
+ }
41
+ /** Start a sign-in with `begin` (the harness's startClaudeLogin, given the limit), after ending one that waits. */
42
+ start(begin) {
43
+ const next = this.#queue.then(async () => {
44
+ await this.#end();
45
+ const turn = ++this.#turn;
46
+ const started = { started_at: new Date(this.#now()).toISOString(), limit_ms: this.limitMs };
47
+ if (this.#closed) {
48
+ this.#current = { view: { ...started, state: "not_started", ended_at: started.started_at, error: "this server is stopping" } };
49
+ return this.view();
50
+ }
51
+ let handle;
52
+ try {
53
+ handle = begin(this.limitMs);
54
+ }
55
+ catch (error) {
56
+ this.#current = { view: { ...started, state: "not_started", ended_at: started.started_at, error: words(error) } };
57
+ return this.view();
58
+ }
59
+ this.#current = { view: { ...started, state: "waiting" }, handle };
60
+ void handle.ended.then((end) => {
61
+ if (turn === this.#turn)
62
+ this.#current = { view: endedView(started, end, new Date(this.#now()).toISOString()) };
63
+ });
64
+ return this.view();
65
+ });
66
+ this.#queue = next.catch(() => { });
67
+ return next;
68
+ }
69
+ /** End a sign-in that waits, and forget the one there is (a turn-off). */
70
+ stop() {
71
+ const next = this.#queue.then(() => this.#end());
72
+ this.#queue = next.catch(() => { });
73
+ return next;
74
+ }
75
+ /** The server's stop: as stop(), resolving once a CLI that waited is gone, and a start asked after it (a request still
76
+ * in flight) spawns nothing. A CLI left waiting would keep the browser's callback port from the next server's sign-in. */
77
+ close() {
78
+ this.#closed = true;
79
+ return this.stop();
80
+ }
81
+ async #end() {
82
+ const current = this.#current;
83
+ this.#turn++;
84
+ this.#current = undefined;
85
+ if (current?.view.state !== "waiting" || !current.handle)
86
+ return;
87
+ current.handle.stop();
88
+ await current.handle.ended;
89
+ }
90
+ }
@@ -1,4 +1,4 @@
1
- import{w as bt,d as qt,D as Yn}from"./index-DUYLaqiR.js";const ye=t=>({type:"boolean",description:t}),Yt={type:"object",required:["name","pageCount","pages","text"],properties:{name:{type:"string"},pageCount:{type:"integer"},pages:{type:"array"},text:{type:"string"}}},zn={type:"object",required:["status","text"],properties:{status:{type:"integer"},url:{type:"string"},title:{type:"string"},text:{type:"string"}}},vt={type:"object"},Ke={type:"object",additionalProperties:!1,required:["altered","seal","signature","legible"],properties:{altered:ye("Does the page show signs of digital alteration: mismatched fonts, misaligned lines, pasted regions or an edited date?"),seal:ye("Is a state seal or a filing stamp visible on the page?"),signature:ye("Is the certificate signed by a state official?"),legible:ye("Is the entity's full legal name legible on the page?")}},mt={v:2,name:"coi-batch-review",schemas:{Input:{type:"object",required:["documents"],properties:{documents:{type:"array",items:{type:"string"},minItems:1,maxItems:50}}},DocChecks:Ke,Pages:Yt,Report:vt},input:{schemaId:"Input"},output:{schemaId:"Report",path:"report"},root:{node:"chain",steps:[{node:"map",label:"each-document",itemsPath:"documents",as:"rows",maxConcurrency:4,onItemFailure:"collect",failedAs:"failed",body:{node:"chain",steps:[{node:"call",label:"render-pages",via:"tool",tool:"pdf_pages",args:{path:"{item}",maxPages:2},out:"Pages",as:"pages",deadline_s:60},{node:"judge",label:"inspect-certificate",provider:"jev",state:{document:"{item}",page:"<page1>",text:"{pages.text}"},images:{"<page1>":"{pages.pages.0.image}"},out:"DocChecks",as:"checks"},{node:"code",label:"grade",code:"(s) => ({ document: s.item, verdict: s.checks.altered || !s.checks.seal || !s.checks.legible ? 'doubtful' : 'valid', checks: s.checks })",as:"row"}]}},{node:"code",label:"batch-report",code:"(s) => ({ valid: s.rows.filter((r) => r && r.verdict === 'valid').length, doubtful: s.rows.filter((r) => r && r.verdict === 'doubtful').map((r) => r.document), failed: s.failed })",as:"report"}]}},Ae={v:2,name:"kyb-onboarding",schemas:{Pages:Yt,Result:vt,Input:{type:"object",required:["company","state","registration_number","documents"],properties:{company:{type:"string"},state:{type:"string"},registration_number:{type:"string"},documents:{type:"array",items:{type:"string"}}}},Registry:{type:"object",additionalProperties:!1,required:["registered","active","name_matches"],properties:{registered:ye("Is a company with this exact registration number on file with the named state's business registry?"),active:ye("Is that registration currently active (in good standing, not dissolved, forfeited or revoked)?"),name_matches:ye("Does the registry's legal name match the applicant's name, ignoring punctuation and suffix style?")}},CertLook:{type:"object",additionalProperties:!1,required:["altered","seal","legible"],properties:{altered:Ke.properties.altered,seal:Ke.properties.seal,legible:Ke.properties.legible}},CrossCheck:{type:"object",additionalProperties:!1,required:["same_entity","same_state","dates_consistent"],properties:{same_entity:ye("Do the registry record and the certificate name the same legal entity?"),same_state:ye("Do they name the same state of incorporation?"),dates_consistent:ye("Is the certificate's filing date consistent with the registry's formation date (within 3 days)?")}}},input:{schemaId:"Input"},root:{node:"chain",steps:[{node:"call",label:"render-certificate",via:"tool",tool:"pdf_pages",args:{path:"{documents.0}",maxPages:1},out:"Pages",as:"cert",deadline_s:60},{node:"parallel",label:"checks",branches:[{node:"judge",label:"registry-lookup",provider:"parallel",model:"standard",state:{company:"{company}",state:"{state}",registration_number:"{registration_number}"},out:"Registry",as:"registry"},{node:"judge",label:"certificate-look",provider:"jev",state:{page:"<cert>",text:"{cert.text}"},images:{"<cert>":"{cert.pages.0.image}"},out:"CertLook",as:"look"}]},{node:"judge",label:"cross-check",provider:"jev",state:{applicant:{company:"{company}",state:"{state}"},registry:"{registry$answers}",certificate_text:"{cert.text}"},out:"CrossCheck",as:"cross"},{node:"route",label:"decide",provider:"jev",state:{registry:"{registry}",look:"{look}",cross:"{cross}"},instructions:"Decide the onboarding outcome for this business from the registry check, the certificate's look and the cross-check.",branches:{approve:{criteria:"Registered, active, the certificate looks genuine, and every cross-check agrees.",body:{node:"code",label:"record-approval",code:"(s) => ({ outcome: 'approved' })",as:"outcome"}},review:{criteria:"Mostly consistent, but one check is doubtful or the evidence disagrees on a detail.",body:{node:"code",label:"open-review-case",code:"(s) => ({ outcome: 'review', reasons: s.cross })",as:"outcome"}},reject:{criteria:"Not registered, dissolved, or the certificate is altered.",body:{node:"code",label:"record-rejection",code:"(s) => ({ outcome: 'rejected' })",as:"outcome"}}},unsure:{branch:"review",gte:.75}}]},output:{schemaId:"Result",path:"outcome"}},Jn={type:"object",additionalProperties:!1,required:["prohibited"],properties:{prohibited:ye("Does this merchant sell goods the card networks prohibit: weapons, controlled substances, counterfeit goods, or unlicensed nicotine products?")}},Ve=(t,n,a)=>({node:"judge",label:t,provider:n,...a?{model:a}:{},state:{merchant:"{merchant}",url:"{url}",page_text:"{page.text}"},out:"Prohibited",as:t.replace(/-/g,"_")}),Ze={v:2,name:"prohibited-goods-jury",schemas:{Page:zn,Result:vt,Input:{type:"object",required:["merchant","url"],properties:{merchant:{type:"string"},url:{type:"string"}}},Prohibited:Jn},input:{schemaId:"Input"},root:{node:"chain",steps:[{node:"call",label:"fetch-storefront",via:"tool",tool:"web_fetch",args:{url:"{url}"},out:"Page",as:"page",deadline_s:30},{node:"parallel",label:"jury",branches:[Ve("jev","jev"),Ve("pplx-decider","openrouter","perplexity/pplx-decider-v1.2"),Ve("liquid-d1","openrouter","liquid/d1"),Ve("clef","openrouter","cloudflare/clef")]},{node:"code",label:"aggregate",code:"(s) => { const p = [s.jev$answers, s.pplx_decider$answers, s.liquid_d1$answers, s.clef$answers].map((a) => a.answers.prohibited.noul); const mean = p.reduce((x, y) => x + y, 0) / p.length; const spread = Math.max(...p) - Math.min(...p); return { mean, spread, outcome: spread > 0.3 ? 'disagree' : 'agree' }; }",as:"agreement"},{node:"route",label:"agreement",valuePath:"agreement.outcome",branches:{agree:{body:{node:"code",label:"auto-decide",code:"(s) => ({ decision: s.agreement.mean >= 0.5 ? 'decline' : 'approve' })",as:"decision"}},disagree:{body:{node:"code",label:"human-review",code:"(s) => ({ decision: 'review', spread: s.agreement.spread })",as:"decision"}}}}]},output:{schemaId:"Result",path:"decision"}},re=6e4,ie=60*re,W=24*ie,oe={default:"anthropic/claude-sonnet-5-5",fast:"openai/gpt-6-luna",strong:"anthropic/claude-opus-5-5",codex:"openai/gpt-6.1-sol"},Vn={v:2,name:"ticket-triage",schemas:{Ticket:{type:"object",required:["subject","body"],properties:{subject:{type:"string"},body:{type:"string"}}},Triage:{type:"object",required:["queue","urgency"],properties:{queue:{type:"string"},urgency:{type:"integer"}}}},input:{schemaId:"Ticket"},output:{schemaId:"Triage",path:"triage"},root:{node:"chain",steps:[{node:"call",label:"read the playbook",tool:"read",args:{path:"playbooks/triage.md"},as:"playbook"},{node:"pick",label:"which queue",from:"playbook.queues",instructions:"Which queue does this ticket belong to, by what the buyer or seller asks for?",as:"queue",none:"hand back"},{node:"code",label:"score the urgency",as:"triage"}]}},Qn=`# ticket-triage
1
+ import{w as bt,d as qt,D as Yn}from"./index-CQ3cJRzI.js";const ye=t=>({type:"boolean",description:t}),Yt={type:"object",required:["name","pageCount","pages","text"],properties:{name:{type:"string"},pageCount:{type:"integer"},pages:{type:"array"},text:{type:"string"}}},zn={type:"object",required:["status","text"],properties:{status:{type:"integer"},url:{type:"string"},title:{type:"string"},text:{type:"string"}}},vt={type:"object"},Ke={type:"object",additionalProperties:!1,required:["altered","seal","signature","legible"],properties:{altered:ye("Does the page show signs of digital alteration: mismatched fonts, misaligned lines, pasted regions or an edited date?"),seal:ye("Is a state seal or a filing stamp visible on the page?"),signature:ye("Is the certificate signed by a state official?"),legible:ye("Is the entity's full legal name legible on the page?")}},mt={v:2,name:"coi-batch-review",schemas:{Input:{type:"object",required:["documents"],properties:{documents:{type:"array",items:{type:"string"},minItems:1,maxItems:50}}},DocChecks:Ke,Pages:Yt,Report:vt},input:{schemaId:"Input"},output:{schemaId:"Report",path:"report"},root:{node:"chain",steps:[{node:"map",label:"each-document",itemsPath:"documents",as:"rows",maxConcurrency:4,onItemFailure:"collect",failedAs:"failed",body:{node:"chain",steps:[{node:"call",label:"render-pages",via:"tool",tool:"pdf_pages",args:{path:"{item}",maxPages:2},out:"Pages",as:"pages",deadline_s:60},{node:"judge",label:"inspect-certificate",provider:"jev",state:{document:"{item}",page:"<page1>",text:"{pages.text}"},images:{"<page1>":"{pages.pages.0.image}"},out:"DocChecks",as:"checks"},{node:"code",label:"grade",code:"(s) => ({ document: s.item, verdict: s.checks.altered || !s.checks.seal || !s.checks.legible ? 'doubtful' : 'valid', checks: s.checks })",as:"row"}]}},{node:"code",label:"batch-report",code:"(s) => ({ valid: s.rows.filter((r) => r && r.verdict === 'valid').length, doubtful: s.rows.filter((r) => r && r.verdict === 'doubtful').map((r) => r.document), failed: s.failed })",as:"report"}]}},Ae={v:2,name:"kyb-onboarding",schemas:{Pages:Yt,Result:vt,Input:{type:"object",required:["company","state","registration_number","documents"],properties:{company:{type:"string"},state:{type:"string"},registration_number:{type:"string"},documents:{type:"array",items:{type:"string"}}}},Registry:{type:"object",additionalProperties:!1,required:["registered","active","name_matches"],properties:{registered:ye("Is a company with this exact registration number on file with the named state's business registry?"),active:ye("Is that registration currently active (in good standing, not dissolved, forfeited or revoked)?"),name_matches:ye("Does the registry's legal name match the applicant's name, ignoring punctuation and suffix style?")}},CertLook:{type:"object",additionalProperties:!1,required:["altered","seal","legible"],properties:{altered:Ke.properties.altered,seal:Ke.properties.seal,legible:Ke.properties.legible}},CrossCheck:{type:"object",additionalProperties:!1,required:["same_entity","same_state","dates_consistent"],properties:{same_entity:ye("Do the registry record and the certificate name the same legal entity?"),same_state:ye("Do they name the same state of incorporation?"),dates_consistent:ye("Is the certificate's filing date consistent with the registry's formation date (within 3 days)?")}}},input:{schemaId:"Input"},root:{node:"chain",steps:[{node:"call",label:"render-certificate",via:"tool",tool:"pdf_pages",args:{path:"{documents.0}",maxPages:1},out:"Pages",as:"cert",deadline_s:60},{node:"parallel",label:"checks",branches:[{node:"judge",label:"registry-lookup",provider:"parallel",model:"standard",state:{company:"{company}",state:"{state}",registration_number:"{registration_number}"},out:"Registry",as:"registry"},{node:"judge",label:"certificate-look",provider:"jev",state:{page:"<cert>",text:"{cert.text}"},images:{"<cert>":"{cert.pages.0.image}"},out:"CertLook",as:"look"}]},{node:"judge",label:"cross-check",provider:"jev",state:{applicant:{company:"{company}",state:"{state}"},registry:"{registry$answers}",certificate_text:"{cert.text}"},out:"CrossCheck",as:"cross"},{node:"route",label:"decide",provider:"jev",state:{registry:"{registry}",look:"{look}",cross:"{cross}"},instructions:"Decide the onboarding outcome for this business from the registry check, the certificate's look and the cross-check.",branches:{approve:{criteria:"Registered, active, the certificate looks genuine, and every cross-check agrees.",body:{node:"code",label:"record-approval",code:"(s) => ({ outcome: 'approved' })",as:"outcome"}},review:{criteria:"Mostly consistent, but one check is doubtful or the evidence disagrees on a detail.",body:{node:"code",label:"open-review-case",code:"(s) => ({ outcome: 'review', reasons: s.cross })",as:"outcome"}},reject:{criteria:"Not registered, dissolved, or the certificate is altered.",body:{node:"code",label:"record-rejection",code:"(s) => ({ outcome: 'rejected' })",as:"outcome"}}},unsure:{branch:"review",gte:.75}}]},output:{schemaId:"Result",path:"outcome"}},Jn={type:"object",additionalProperties:!1,required:["prohibited"],properties:{prohibited:ye("Does this merchant sell goods the card networks prohibit: weapons, controlled substances, counterfeit goods, or unlicensed nicotine products?")}},Ve=(t,n,a)=>({node:"judge",label:t,provider:n,...a?{model:a}:{},state:{merchant:"{merchant}",url:"{url}",page_text:"{page.text}"},out:"Prohibited",as:t.replace(/-/g,"_")}),Ze={v:2,name:"prohibited-goods-jury",schemas:{Page:zn,Result:vt,Input:{type:"object",required:["merchant","url"],properties:{merchant:{type:"string"},url:{type:"string"}}},Prohibited:Jn},input:{schemaId:"Input"},root:{node:"chain",steps:[{node:"call",label:"fetch-storefront",via:"tool",tool:"web_fetch",args:{url:"{url}"},out:"Page",as:"page",deadline_s:30},{node:"parallel",label:"jury",branches:[Ve("jev","jev"),Ve("pplx-decider","openrouter","perplexity/pplx-decider-v1.2"),Ve("liquid-d1","openrouter","liquid/d1"),Ve("clef","openrouter","cloudflare/clef")]},{node:"code",label:"aggregate",code:"(s) => { const p = [s.jev$answers, s.pplx_decider$answers, s.liquid_d1$answers, s.clef$answers].map((a) => a.answers.prohibited.noul); const mean = p.reduce((x, y) => x + y, 0) / p.length; const spread = Math.max(...p) - Math.min(...p); return { mean, spread, outcome: spread > 0.3 ? 'disagree' : 'agree' }; }",as:"agreement"},{node:"route",label:"agreement",valuePath:"agreement.outcome",branches:{agree:{body:{node:"code",label:"auto-decide",code:"(s) => ({ decision: s.agreement.mean >= 0.5 ? 'decline' : 'approve' })",as:"decision"}},disagree:{body:{node:"code",label:"human-review",code:"(s) => ({ decision: 'review', spread: s.agreement.spread })",as:"decision"}}}}]},output:{schemaId:"Result",path:"decision"}},re=6e4,ie=60*re,W=24*ie,oe={default:"anthropic/claude-sonnet-5-5",fast:"openai/gpt-6-luna",strong:"anthropic/claude-opus-5-5",codex:"openai/gpt-6.1-sol"},Vn={v:2,name:"ticket-triage",schemas:{Ticket:{type:"object",required:["subject","body"],properties:{subject:{type:"string"},body:{type:"string"}}},Triage:{type:"object",required:["queue","urgency"],properties:{queue:{type:"string"},urgency:{type:"integer"}}}},input:{schemaId:"Ticket"},output:{schemaId:"Triage",path:"triage"},root:{node:"chain",steps:[{node:"call",label:"read the playbook",tool:"read",args:{path:"playbooks/triage.md"},as:"playbook"},{node:"pick",label:"which queue",from:"playbook.queues",instructions:"Which queue does this ticket belong to, by what the buyer or seller asks for?",as:"queue",none:"hand back"},{node:"code",label:"score the urgency",as:"triage"}]}},Qn=`# ticket-triage
2
2
 
3
3
  Files a ticket under its queue (billing, shipping, account, merchant, abuse) and scores its urgency from the playbook: a chargeback, a locked account or a safety problem is 4 or more.
4
4