@ai-ecoverse/slicc-agent 7.26.0 → 7.28.0
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.
- package/README.md +9 -6
- package/dist/approvals/index.js +74 -17
- package/dist/approvals/index.js.map +2 -2
- package/dist/approvals/people.js +5 -0
- package/dist/approvals/people.js.map +7 -0
- package/dist/approvals/reasons.js +19 -0
- package/dist/approvals/reasons.js.map +7 -0
- package/dist/approvals/record.js +19 -18
- package/dist/approvals/record.js.map +2 -2
- package/dist/approvals/stoppable.js +5 -0
- package/dist/approvals/stoppable.js.map +7 -0
- package/dist/approvals/sudo-client.js +16 -4
- package/dist/approvals/sudo-client.js.map +2 -2
- package/dist/approvals/sudo.js +13 -5
- package/dist/approvals/sudo.js.map +2 -2
- package/dist/host.js +1 -0
- package/dist/host.js.map +2 -2
- package/dist/index.js.map +2 -2
- package/dist/page.js +6 -1
- package/dist/page.js.map +2 -2
- package/dist/services.js.map +1 -1
- package/dist/spectrum/approvals-port.js +2 -0
- package/dist/spectrum/approvals-port.js.map +2 -2
- package/dist/types/approvals/index.d.ts +2 -0
- package/dist/types/approvals/people.d.ts +2 -0
- package/dist/types/approvals/reasons.d.ts +15 -0
- package/dist/types/approvals/record.d.ts +10 -18
- package/dist/types/approvals/stoppable.d.ts +2 -0
- package/dist/types/approvals/sudo-client.d.ts +2 -1
- package/dist/types/approvals/sudo.d.ts +9 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/page.d.ts +2 -2
- package/dist/types/services.d.ts +2 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -741,18 +741,21 @@ It prints the tab's stdout and stderr on their own streams and exits with its co
|
|
|
741
741
|
|
|
742
742
|
Every approval, of a guest's prompt, of a tool call in a run a guest started, of a sudo request, or of a media capture from a run a guest started, is an item in one session document, `slicc.approvals` ([`src/approvals/`](src/approvals/)). That document is the authority: not a lick, which the agent can confirm itself, and not a UI projection, so a settled item stays settled after a reload.
|
|
743
743
|
|
|
744
|
-
- **An item** is `{ id, kind, seat?, agentId, requester, detail, tier, state, decidedBy, device?, answer?, reason?, verdict?, judging?, verdictError?, always, createdAt, expiresAt, decidedAt? }`. `kind` is `guest-message` (`detail: { text, attachments }`), `guest-tool` (`{ tool, summary, arguments?, task? }`) `sudo` (`{ command, target?, cwd?, alwaysScope?, stdin?, rootOnly?, writable? }`) or `capture` (`{ what, mode, seconds?, system?, microphone?, device?, program }`, see Media capture). `judging` is `true` while the judge runs; `verdictError` says why there is no verdict. `requester` is `{ kind: 'guest' | 'agent' | 'user', name, seat?, agentId?, where?, device? }`.
|
|
745
|
-
- **`state`** is `pending`, `approved` (with `answer` `once` or `always`), `rejected` (someone said no), `unanswered` (nobody decided: it timed out or couldn't be routed) or `withdrawn` (the requester went away). `reason` is a field, never a state: a person's own words, or `timeout`, `unknown-tier`, `unroutable`, `unknown-answer`, `restart`, `revoked`, `aborted` or `
|
|
744
|
+
- **An item** is `{ id, kind, seat?, agentId, requester, detail, tier, state, decidedBy, device?, answer?, reason?, verdict?, judging?, verdictError?, always, createdAt, expiresAt, decidedAt? }`. `kind` is `guest-message` (`detail: { text, attachments }`), `guest-tool` (`{ tool, summary, arguments?, task? }`) `sudo` (`{ command, target?, cwd?, alwaysScope?, stdin?, rootOnly?, writable?, validate? }`) or `capture` (`{ what, mode, seconds?, system?, microphone?, device?, program }`, see Media capture). `judging` is `true` while the judge runs; `verdictError` says why there is no verdict. `requester` is `{ kind: 'guest' | 'agent' | 'user', name, seat?, agentId?, where?, device? }`.
|
|
745
|
+
- **`state`** is `pending`, `approved` (with `answer` `once` or `always`), `rejected` (someone said no), `unanswered` (nobody decided: it timed out or couldn't be routed) or `withdrawn` (the requester went away). `reason` is a field, never a state: a person's own words, or `timeout`, `unknown-tier`, `unroutable`, `unknown-answer`, `restart`, `revoked`, `aborted`, `disconnected` or `stopped` (see Deny and stop). `decidedBy` is `owner`, `follower`, `judge` or `host`.
|
|
746
746
|
- **`tier`** says who answers: `user` (a person, through `decide`), `agent` (the automatic judge), `cone` or `scoop:<name>`. A tier the agent doesn't know settles at once as `unanswered` with `unknown-tier`, and so does `cone` for a guest's tool call or capture (`unroutable`), because a run can't approve its own gate. A person answers only `user` items, the judge only `agent` ones.
|
|
747
|
-
- **The rules:** the first decision wins, and a later one, or one past `expiresAt`, is refused ("Someone else already answered this.", "This request timed out.", "This request was withdrawn."). An answer other than `once`, `always` or `
|
|
747
|
+
- **The rules:** the first decision wins, and a later one, or one past `expiresAt`, is refused ("Someone else already answered this.", "This request timed out.", "This request was withdrawn."). An answer other than `once`, `always`, `deny` or `stop` is a deny (`unknown-answer`). `always` is `false` for anything a guest triggered unless the approval policy's `guests.always` offers it for that kind (by default it doesn't). A `sudo` or `capture` item starts with `always: false` and gets `true` only from a verdict (see The automatic judge), and `decide(id, 'always')` on an item without it is refused and leaves it pending. For a guest's tool call, Always records an exact rule on the seat (see Guest seats), and for a capture a narrow one (see Media capture).
|
|
748
|
+
- **Deny and stop:** `decide(id, 'stop')` denies a `sudo` item and stops the turn of the agent that asked for it, in one step inside the worker. Only a person (`owner` or `follower`) may send it, and only for a pending `sudo` item whose `requester` is an agent with an `agentId` (a cone or a scoop); anything else is refused with an error ("Only a person can stop a turn.", "This request has no turn to stop.") and the item stays pending, and so is one to approvals attached without a way to stop a turn. One write settles the item `rejected` with `reason: 'stopped'` and `decidedBy` the person, withdraws that agent's other pending `sudo` and `capture` items (`withdrawn`, `stopped`), and holds that agent's next `sudo` or `capture` asks; then the worker aborts that agent's conversation (`Conversation.abort()`, as `stopAgent` does), which kills the running command's process tree. A held ask waits until the turn has stopped and is then filed `withdrawn` (`stopped`), so a shell loop that keeps calling `sudo` can't reach a person in between, and `decide` resolves after the turn is idle. A scoop's request stops the scoop's turn, never its cone's: a cone waiting on it in `agent --prompt` gets "the scoop's request ended without an answer: aborted" and carries on, and `agent wait` returns once the scoop is idle. A person's own reason that is the word `stopped` isn't kept, so a plain deny never reads as a stop. A worker from before this answers `stop` as `unknown-answer`, a plain deny.
|
|
748
749
|
- **Lifetime:** an item waits 5 minutes unless its requester sets `expiresAt`, then settles `unanswered`. Pending guest items survive a reload of the worker; pending `sudo` and `capture` items are withdrawn (`restart`), because a reload ends the kernel's processes and the page's request. The document keeps every pending item and the last 100 settled ones.
|
|
749
750
|
- **In the worker,** `AgentHost.approvals` has `request(draft, ctx)`, `decide(id, answer, reason, by, ctx)` (`by` is a `DecidedBy`, or `{ by, device }` to record the deciding device), `settled(id, ctx)` (resolves when the item leaves `pending`), `withdraw(id, reason, ctx)` and `withdrawSeat(seat, ctx)`, which withdraws a revoked seat's pending items.
|
|
750
751
|
- **Over the link,** `AgentTranscript.approvals` replicates the items, and `AgentControl.decide(id, decision, reason, ctx)` answers one, for every owner device: the owner's pages and followers with or without Control, all with the same powers. `decidedBy` comes from the link's seat (`owner` for the owner's pages, `follower` for the others), and is only a record of who answered. A guest never gets `decide`.
|
|
751
|
-
- **In spectrum** (1.112 on, which shows approvals in `<slicc-approvals>` with Always allow when `always` is true, as notices without `decide`, and the verdict's level), `createAgentModel` returns `approvals`, an `ApprovalsAdapter` for `SliccModel.approvals`. `list()` has the pending `user` items, oldest first, as spectrum's `Approval`s, with the cone's name as `agentName` and the item's own `always`, so a guest approval offers Always allow only when the policy did when it was asked. Every approval carries the judge's `verdict` once it lands, as `{ level?, aligned?, reason }` (spectrum 1.112 on shows the level; `aligned` is `true` at P over 0.8, or the chat model's answer), `judging: true` while the check runs and `verdictError` when there is none. Its `always` is the item's, so Always allow shows up only when a level 1 verdict offers it. `decide(id, decision, reason?)` rejects with the agent's message, and `ended` reports `answered`, `expired` or `withdrawn` for an item that left without this tab's decision. Every owner device's adapter has `decide`; a guest connection's doesn't. So a notice instead of a dialog shows only where nothing can answer. A `capture` item is a `CaptureApproval`, with the guest items' `agentId`, `agentName`, `always` and verdict fields and the item's `detail` as it is (`what`, `mode`, `seconds?`, `system?`, `microphone?`, `device?`, `program`), which spectrum 2.4.1 on shows as its capture line. A `guest-tool` approval also carries `args`, the call's arguments pretty-printed as JSON (two-space indent), so spectrum can show them uncut when `summary` is empty. The worker runs every string in the arguments through the secrets scrub before it files the item, so `summary`, `detail.arguments` and `args` show a secret as its placeholder; the seat's Always rules still match the call's own arguments. `args` is capped at 64 KiB (65,536 UTF-16 code units, `ARGS_LENGTH`, never splitting a surrogate pair): longer arguments are sent as that prefix with `argsTruncated: true`, and spectrum must then offer only Deny and Always deny, never Allow, because the end wasn't seen.
|
|
752
|
+
- **In spectrum** (1.112 on, which shows approvals in `<slicc-approvals>` with Always allow when `always` is true, as notices without `decide`, and the verdict's level), `createAgentModel` returns `approvals`, an `ApprovalsAdapter` for `SliccModel.approvals`. `list()` has the pending `user` items, oldest first, as spectrum's `Approval`s, with the cone's name as `agentName` and the item's own `always`, so a guest approval offers Always allow only when the policy did when it was asked. Every approval carries the judge's `verdict` once it lands, as `{ level?, aligned?, reason }` (spectrum 1.112 on shows the level; `aligned` is `true` at P over 0.8, or the chat model's answer), `judging: true` while the check runs and `verdictError` when there is none. Its `always` is the item's, so Always allow shows up only when a level 1 verdict offers it. A `sudo` approval from a cone or a scoop (`requester.kind` `agent` with an `agentId`) carries `stoppable: true`, and spectrum then offers Deny and stop, sent as `decide(id, 'stop')`; a terminal's, a sprinkle's or a linked device's never does. `decide(id, decision, reason?)` rejects with the agent's message, and `ended` reports `answered`, `expired` or `withdrawn` for an item that left without this tab's decision. Every owner device's adapter has `decide`; a guest connection's doesn't. So a notice instead of a dialog shows only where nothing can answer. A `capture` item is a `CaptureApproval`, with the guest items' `agentId`, `agentName`, `always` and verdict fields and the item's `detail` as it is (`what`, `mode`, `seconds?`, `system?`, `microphone?`, `device?`, `program`), which spectrum 2.4.1 on shows as its capture line. A `guest-tool` approval also carries `args`, the call's arguments pretty-printed as JSON (two-space indent), so spectrum can show them uncut when `summary` is empty. The worker runs every string in the arguments through the secrets scrub before it files the item, so `summary`, `detail.arguments` and `args` show a secret as its placeholder; the seat's Always rules still match the call's own arguments. `args` is capped at 64 KiB (65,536 UTF-16 code units, `ARGS_LENGTH`, never splitting a surrogate pair): longer arguments are sent as that prefix with `argsTruncated: true`, and spectrum must then offer only Deny and Always deny, never Allow, because the end wasn't seen.
|
|
752
753
|
- **Kernel sudo:** `AgentOwner.approve(req, { signal, where? })` from `startAgent` takes slicc-kernel's sudo request as it comes to the kernel's `approve` hook and resolves `once`, `always` or `deny`. bios hands its hook to it while the agent runs, and to its own dialog otherwise. It rejects with `code: 'EAGAIN'` before anything is recorded when the agent can't take the request (released, restarting, or an older worker) or when the request's `kind` isn't `sudo`, such as a program's secret `ask`, so that's when to fall back; any other rejection is a deny. The request goes through `slicc.agent.sudo`, a service only the owner's pages get, and becomes a `sudo` item on the `user` tier with the kernel's `expiresAt`:
|
|
753
754
|
- **Requester** comes from the kernel's process tag: `{ kind: 'agent', agentId }` is the cone or scoop by its name, `{ kind: 'user', where }` is the kernel user with `where` (`terminal:…` reads "a terminal", `follower:<device>` the `where` the page passes, such as "on Pat's phone", or "a linked device", with the device id kept as `requester.device`), and anything else is the kernel user alone.
|
|
754
755
|
- **Detail:** the command as the kernel resolved it (`path` and the arguments, shell-quoted), `target`, `cwd`, `alwaysScope: 'cwd'` when `req.always === true`, since the kernel's Always writes a rule for that directory, and the kernel's facts for the judge: `stdin` (`tty`, `none`, `pipe` or `file`), `rootOnly` (for each path on the line, whether only root can change it) and `writable` (`req.always`, whether the kernel can record the line). Requests without them still work; `req.always: false` or `writable: false` means no Always.
|
|
755
|
-
- **Answers:** `approved` resolves its answer, a judge's rejection resolves a `SudoDenial`, `{ answer: 'deny', message: 'sudo: denied by the approval judge: <reason>' }` (the prefix is `JUDGE_DENIED`), so the shell can say who refused, and anything else `deny`. A kernel that doesn't know the object denies it as it denies any answer but `once` and `always`. Every device of the owner answers with the same powers: a follower, with or without Control, sees the same item, Always included when the verdict offers it, and its `always` counts as the owner tab's would. `device` on the item names the device that answered, from `owner.port({ device })`.
|
|
756
|
+
- **Answers:** `approved` resolves its answer, a judge's rejection resolves a `SudoDenial`, `{ answer: 'deny', message: 'sudo: denied by the approval judge: <reason>' }` (the prefix is `JUDGE_DENIED`), so the shell can say who refused, a deny and stop resolves `{ answer: 'deny', message: 'sudo: denied, and the owner stopped this turn' }` (`STOPPED`), and anything else `deny`. A kernel that doesn't know the object denies it as it denies any answer but `once` and `always`. Every device of the owner answers with the same powers: a follower, with or without Control, sees the same item, Always included when the verdict offers it, and its `always` counts as the owner tab's would. `device` on the item names the device that answered, from `owner.port({ device })`.
|
|
757
|
+
- **Timestamps:** a kernel that keeps sudo timestamps (`Defaults timestamp_timeout`, slicc-kernel 1.177.0 or later) says so with `req.timestamp: true`. To such a request, an approval decided by a person (`decidedBy` `owner` or `follower`) resolves `SudoTimestamp`, `{ answer: 'once' | 'always', timestamp: true }`, which lets the kernel open or refresh the timestamp, so that shell isn't asked again until it runs out. The judge's and the host's approvals stay plain `once`, and a scoop can't approve sudo at all, so none of them open the window. Denials don't change. A request without `timestamp: true` always gets the plain string, because an older kernel denies any object that isn't a denial.
|
|
758
|
+
- **`sudo -v`:** a request with `validate: true` has no command (argv may be empty). It is always on the `user` tier, whatever `sudo.approver` says, the judge never sees it, and it never offers Always (`writable: false`). Its `detail` is only `{ command: 'start a sudo timestamp for <user> (no command)', validate: true, writable: false }`, and a scoop's lick says it asked to start a sudo timestamp. Any other request with an empty argv is refused.
|
|
756
759
|
- **Ends:** when the kernel aborts `signal` (`withdrawn`) the item is withdrawn, and on `expired` the page keeps its link until the record's own timeout settles it (`unanswered`), so it never reads as withdrawn. When the page's link closes the worker withdraws its open sudo items (`disconnected`). A restart or release of the owner first ends the old worker, then denies the requests still waiting, so the old worker never sees their links close, and the next worker withdraws their items (`restart`). The kernel already allows one pending request per user.
|
|
757
760
|
- **Scoops:** a scoop's request sends its cone a `sudo-request` lick without actions once a person has to answer it (at once on the `user` tier, after the judge hands it on with the `agent` policy, never when the judge decides), so the cone knows the scoop waits and can't approve it itself. A cone that asks gets none: it waits in its own command.
|
|
758
761
|
- **Media capture:** `AgentOwner.approveCapture(request, { signal, where? })` takes a `/dev/embedder` request as bios's hook receives it, `{ kind, options, stamp }`, and resolves `once`, `always`, `deny` or `{ answer: 'deny', message }`. It rejects with `code: 'EAGAIN'` when the agent can't answer (released, restarting, or a worker without it) and when `stamp.users` is neither `report` nor `enforce`, since the agent can't tell who started the program then, so bios falls back to its own prompt.
|
|
@@ -771,7 +774,7 @@ Every approval, of a guest's prompt, of a tool call in a run a guest started, of
|
|
|
771
774
|
|
|
772
775
|
#### The automatic judge
|
|
773
776
|
|
|
774
|
-
The judge ([`src/approvals/judge.ts`](src/approvals/judge.ts)) gives a request a verdict by the owner's intent, never the requester's. It judges only items in `slicc.approvals`, never a `secret` approval, which always goes to a person. `request()` starts it at once for every `sudo` item
|
|
777
|
+
The judge ([`src/approvals/judge.ts`](src/approvals/judge.ts)) gives a request a verdict by the owner's intent, never the requester's. It judges only items in `slicc.approvals`, never a `secret` approval, which always goes to a person. `request()` starts it at once for every `sudo` item but `sudo -v`, whatever its tier, and for every `agent` or `user` item, so a person is asked with the verdict shown. Who answers is the gate: a `sudo` item's tier is the owner's approval policy (`sudo.approver`), not the request's, `user` (a person) by default and for anything but `agent`; a guest item's tier is the seat's gate. On a `user` item the verdict is advice for the person and decides nothing; on an `agent` item the routing table below decides. The dialog never waits: Allow once and Deny work while `judging` is `true`.
|
|
775
778
|
|
|
776
779
|
- **Levels:** the verdict is `level` 1 Routine (normal work that doesn't change who may do what), 2 Permissions (it changes who may do what: sudoers, users and groups, ownership or modes, secret rules, the approvals policy, guest seats, credentials and tokens) or 3 Harm (it would damage the system or the work in a way that is hard to undo); `aligned`, whether it serves what the owner asked for; and for sudo `always`, whether a later run of exactly this line can do no more than this one. No command lists anywhere: every answer is the model's, and code only combines them. `request.sudo: { stdin, writable, rootOnly }` holds only what the requester can't choose (`rootOnly` is whether every path on the line and the directory can be changed only by root), while the command, the target user, the directory and each path's root-only fact (`path "/etc/x": root-only` or `changeable`, one JSON-quoted path per line) are inside the fenced `request.untrusted`, because the requester chose them.
|
|
777
780
|
- **Sudo: narrow questions, matched in code.** A classifier on `approvals.judgeModel` (in the agent's `settings.json`, `/etc/slicc/agent/settings.json` with kernel users, `adobe/clef` by default), on the harness's own `Models`, with one retry and a 15 s timeout (`JUDGE_TIMEOUT`), gets two calls in parallel. The action call (`SUDO_QUESTIONS`, state `{ request }` only) asks eleven bools about the command: `changes` (creates, changes, moves, copies or deletes anything), `others` (in another user's home), `system` (system files), `delete`, `permissions`, `code` (code or output the line doesn't spell out: scripts, package installs, `xargs`, `find -exec` or `-delete`, redirections, command substitution, `sort -o`, `tee`, `curl` or `wget`, `git` with its hooks, pager and aliases, interpreters, editors, pagers), `services`, `send` (off the machine), `secrets` (its output shows a secret, including dumps of the environment, process environments, shell history and config or credentials files), `plain` (a standard tool whose whole effect its options and paths show) and `always` ("Could a later run of exactly this line do something different from this one, because it reads piped or file input, runs a script or a file someone other than root can change, takes code on the line, or is interactive?"). The intent call (`INTENT_QUESTIONS`, state `{ owner }` only: `owner.policy`, the last 10 `owner.messages` and `owner.memory`) asks what the owner wants done now, the latest messages with earlier ones only as context ("A request the owner made earlier for a task that is finished or replaced doesn't count."), in the same words: `wants_read`, `wants_write`, `wants_delete`, `wants_permissions`, `wants_code`, `wants_send`, `wants_secrets`, `wants_services`. It depends only on the owner's words, so the judge keeps its answer per judge model and owner state (the last 16, `INTENTS_KEPT`) and asks again only when the owner said something new or the policy or memory changed; a failed intent call isn't kept. `matchOf` then decides in code, a probability counting at ≥ 0.5 (`JUDGE_CUT`): level 3 when it deletes anything, changes something in another user's home or among system files, or touches processes or services; else 2 when it changes permissions; else 1. Deleting counts as harm wherever it is, because on live `clef` the `system` answer stayed under 0.5 for 24 of 28 `rm` commands outside `/home` in a real cleanup session, most of them on directories at the top of `/`. `routine` is 1 minus the highest danger answer, over all of them (`delete`, `services`, `permissions`, `send`, `secrets`, `code`, `others` and `system`), and never more than P(plain). For a line that changes anything (P(changes) ≥ 0.2), `others` and `system` count from 0.05 (`JUDGE_PLACE`): they enter `routine` scaled by 0.2 / 0.05. So any danger answer of 0.2 or more, or a system or another user answer of 0.05 or more on a write, keeps `routine` at or under 0.8 and the line goes to a person, even when the owner asked for it; on live `clef` every dangerous line in the evals had a danger answer over its bar, none relied on `plain` alone. Every action the command may take (P ≥ 0.2, `JUDGE_LOW`) needs an intent: `changes` needs `write`, `delete` `delete`, `permissions` `permissions`, `code` `code`, `services` `services`, `send` `send`, `secrets` `secrets`, and a line that changes nothing needs `read`. `aligned` is the lowest of the needed intents, so it counts (over 0.8, `JUDGE_ALLOW`) only when the owner asked for everything the line does: showing a secret or sending data out never rides on a read. `always` is safe at P < 0.2 (`JUDGE_ALWAYS`). Exact boundaries never approve: a danger cut counts from its bar minus 1e-9 (`JUDGE_EPSILON`), and `routine`, `aligned` and 1 − P(always) must reach their bar plus 1e-9 (`clears`), so a danger of exactly 0.2, a `plain` or an intent of exactly 0.8 all ask. The verdict keeps every answer as `actions` and `intent`.
|
package/dist/approvals/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
heldKind,
|
|
14
14
|
knownTier,
|
|
15
15
|
MAX_DELAY,
|
|
16
|
+
personOnly,
|
|
16
17
|
prune,
|
|
17
18
|
REASONS,
|
|
18
19
|
routable,
|
|
@@ -36,13 +37,13 @@ function mark(item, how, at) {
|
|
|
36
37
|
if (how.reason) item.reason = how.reason;
|
|
37
38
|
}
|
|
38
39
|
const offered = (options, draft) => guestKind(draft.kind) && draft.kind !== "capture" ? options.guestAlways?.(draft.kind) === true : false;
|
|
39
|
-
const judgedKind = (
|
|
40
|
+
const judgedKind = (item, tier) => !personOnly(item) && (item.kind === "sudo" || tier === "agent" || tier === "user");
|
|
40
41
|
function detailOf(draft) {
|
|
41
42
|
if (draft.kind !== "sudo" || draft.always !== false) return draft.detail;
|
|
42
43
|
return { ...draft.detail, writable: false };
|
|
43
44
|
}
|
|
44
45
|
function fresh(draft, at, ttl, options) {
|
|
45
|
-
const tier = tierOf(draft
|
|
46
|
+
const tier = tierOf(draft, sudoApprover(options.sudoApprover?.()));
|
|
46
47
|
const item = {
|
|
47
48
|
...draft,
|
|
48
49
|
detail: detailOf(draft),
|
|
@@ -51,7 +52,7 @@ function fresh(draft, at, ttl, options) {
|
|
|
51
52
|
state: "pending",
|
|
52
53
|
decidedBy: null,
|
|
53
54
|
always: offered(options, draft),
|
|
54
|
-
...options.judge && judgedKind(draft
|
|
55
|
+
...options.judge && judgedKind(draft, tier) ? { judging: true } : {},
|
|
55
56
|
createdAt: at,
|
|
56
57
|
expiresAt: draft.expiresAt ?? at + ttl
|
|
57
58
|
};
|
|
@@ -67,6 +68,59 @@ const withdrawIn = (match, reason, now) => (doc) => {
|
|
|
67
68
|
mark(item, { state: "withdrawn", by: "host", ...reason ? { reason } : {} }, now());
|
|
68
69
|
return hit.map((item) => copy([item])[0]);
|
|
69
70
|
};
|
|
71
|
+
const NO_STOP = "This agent can't stop a turn.";
|
|
72
|
+
function haltsOf(stop) {
|
|
73
|
+
const stopping = /* @__PURE__ */ new Map();
|
|
74
|
+
const of = (agentId) => [...stopping.values()].filter((entry) => entry.agentId === agentId);
|
|
75
|
+
const drop = (token) => {
|
|
76
|
+
stopping.get(token)?.release();
|
|
77
|
+
stopping.delete(token);
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
halted: (agentId) => of(agentId).length > 0,
|
|
81
|
+
async idle(agentId) {
|
|
82
|
+
while (of(agentId).length) await Promise.all(of(agentId).map((entry) => entry.done));
|
|
83
|
+
},
|
|
84
|
+
able: (ruling) => ruling.stop && !stop ? { error: NO_STOP } : ruling,
|
|
85
|
+
begin(token, agentId) {
|
|
86
|
+
let release = () => {
|
|
87
|
+
};
|
|
88
|
+
const done = new Promise((resolve) => {
|
|
89
|
+
release = resolve;
|
|
90
|
+
});
|
|
91
|
+
drop(token);
|
|
92
|
+
stopping.set(token, { agentId, done, release });
|
|
93
|
+
},
|
|
94
|
+
drop,
|
|
95
|
+
async end(token) {
|
|
96
|
+
const entry = stopping.get(token);
|
|
97
|
+
if (!entry) return;
|
|
98
|
+
await Promise.resolve().then(() => stop?.(entry.agentId, BACKGROUND_CONTEXT)).catch(() => void 0);
|
|
99
|
+
drop(token);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const decidedIn = (id, { token, by, device, ruling: rule, halts, now }) => (doc) => {
|
|
104
|
+
halts.drop(token);
|
|
105
|
+
const item = doc.items.find((entry) => entry.id === id);
|
|
106
|
+
const ruling = item ? rule(item) : { error: `There is no approval ${id}.` };
|
|
107
|
+
if (item && ruling.settle) {
|
|
108
|
+
if (ruling.answer) item.answer = ruling.answer;
|
|
109
|
+
if (device && ruling.settle.by === by) item.device = device;
|
|
110
|
+
mark(item, ruling.settle, now());
|
|
111
|
+
}
|
|
112
|
+
if (ruling.error) return { done: false, state: null, error: ruling.error };
|
|
113
|
+
if (ruling.stop) {
|
|
114
|
+
halts.begin(token, ruling.stop);
|
|
115
|
+
stoppedIn(ruling.stop, id, now)(doc);
|
|
116
|
+
}
|
|
117
|
+
return { done: true, state: item.state, error: null };
|
|
118
|
+
};
|
|
119
|
+
const stoppedIn = (agentId, id, now) => withdrawIn(
|
|
120
|
+
(item) => item.id !== id && item.agentId === agentId && heldKind(item.kind),
|
|
121
|
+
REASONS.stopped,
|
|
122
|
+
now
|
|
123
|
+
);
|
|
70
124
|
const routeOf = (item, { judgement, present }) => route(judgement.verdict, item.requester, gateOf(item.tier), present);
|
|
71
125
|
const judgedIn = (id, judged, now) => (doc) => {
|
|
72
126
|
const { judgement } = judged;
|
|
@@ -167,6 +221,7 @@ async function attachApprovals(options, context = BACKGROUND_CONTEXT) {
|
|
|
167
221
|
const ttl = options.ttlMs ?? APPROVAL_MS;
|
|
168
222
|
const setTimer = options.setTimer ?? systemTimer;
|
|
169
223
|
const timers = /* @__PURE__ */ new Map();
|
|
224
|
+
const halts = haltsOf(options.stop);
|
|
170
225
|
let line = Promise.resolve();
|
|
171
226
|
let closed = false;
|
|
172
227
|
const settle = (item, how) => mark(item, how, now());
|
|
@@ -255,6 +310,8 @@ async function attachApprovals(options, context = BACKGROUND_CONTEXT) {
|
|
|
255
310
|
state,
|
|
256
311
|
async request(draft, using) {
|
|
257
312
|
let created = true;
|
|
313
|
+
const held = heldKind(draft.kind) && halts.halted(draft.agentId);
|
|
314
|
+
if (held) await halts.idle(draft.agentId);
|
|
258
315
|
const made = await serial((doc) => {
|
|
259
316
|
const kept = draft.id && doc.items.find((entry) => entry.id === draft.id);
|
|
260
317
|
if (kept) {
|
|
@@ -262,28 +319,27 @@ async function attachApprovals(options, context = BACKGROUND_CONTEXT) {
|
|
|
262
319
|
return copy([kept])[0];
|
|
263
320
|
}
|
|
264
321
|
const item = fresh(draft, now(), ttl, options);
|
|
322
|
+
if (item.state === "pending" && heldKind(item.kind) && (held || halts.halted(item.agentId)))
|
|
323
|
+
settle(item, { state: "withdrawn", by: "host", reason: REASONS.stopped });
|
|
265
324
|
doc.items.push(item);
|
|
266
325
|
return copy([item])[0];
|
|
267
326
|
}, using);
|
|
268
|
-
if (created && options.judge && made.state === "pending" && judgedKind(made
|
|
327
|
+
if (created && options.judge && made.state === "pending" && judgedKind(made, made.tier))
|
|
269
328
|
void judging(options.judge, made, made.tier === "agent" ? using : BACKGROUND_CONTEXT);
|
|
270
329
|
if (created) toScoop(made);
|
|
271
330
|
return made;
|
|
272
331
|
},
|
|
273
|
-
decide(id, answer, reason, decider, using) {
|
|
332
|
+
async decide(id, answer, reason, decider, using) {
|
|
274
333
|
const { by, device } = deciderOf(decider);
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
return { done: false, state: null, error: ruling.error };
|
|
285
|
-
return { done: true, state: item.state, error: null };
|
|
286
|
-
}, using);
|
|
334
|
+
const token = {};
|
|
335
|
+
const ruling = (item) => halts.able(ruled(item, answer, reason, by, now()));
|
|
336
|
+
const deciding = { token, by, device, ruling, halts, now };
|
|
337
|
+
const decided = await serial(decidedIn(id, deciding), using).catch((error) => {
|
|
338
|
+
halts.drop(token);
|
|
339
|
+
throw error;
|
|
340
|
+
});
|
|
341
|
+
await halts.end(token);
|
|
342
|
+
return decided;
|
|
287
343
|
},
|
|
288
344
|
settled: (id, using) => settledIn(state, id, using),
|
|
289
345
|
assign(id, reviewer, using) {
|
|
@@ -323,6 +379,7 @@ async function attachApprovals(options, context = BACKGROUND_CONTEXT) {
|
|
|
323
379
|
};
|
|
324
380
|
}
|
|
325
381
|
export {
|
|
382
|
+
NO_STOP,
|
|
326
383
|
attachApprovals
|
|
327
384
|
};
|
|
328
385
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/approvals/index.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type Context,\n type ReplicatedState,\n replicatedState,\n type WatchHandle,\n} from '@earendil-works/chord';\nimport { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';\nimport type { Harness } from '@earendil-works/pi-durable';\nimport type { Clock } from '../clock.ts';\nimport { type ApprovalJudge, ASK_MIN_MS, JUDGE_RESTARTED, type Judgement } from './judge.ts';\nimport {\n APPROVAL_MS,\n type Approval,\n type ApprovalDraft,\n type ApprovalKind,\n type ApprovalState,\n ApprovalsDoc,\n type ApprovalsState,\n alwaysOffered,\n cleanReason,\n type DecidedBy,\n gateOf,\n guestKind,\n heldKind,\n knownTier,\n MAX_DELAY,\n prune,\n REASONS,\n type Routed,\n routable,\n route,\n ruled,\n type Settle,\n scoopTier,\n sudoApprover,\n tierOf,\n} from './record.ts';\n\nexport * from './intent.ts';\nexport * from './judge.ts';\nexport * from './present.ts';\nexport * from './record.ts';\n\nexport type ApprovalDecided =\n | { done: true; state: ApprovalState; error: null }\n | { done: false; state: null; error: string };\n\nexport type Decider = DecidedBy | { by: DecidedBy; device?: string };\n\nconst deciderOf = (decider: Decider) => (typeof decider === 'string' ? { by: decider } : decider);\n\nexport interface Approvals {\n readonly state: ReplicatedState<Approval[]>;\n request(draft: ApprovalDraft & { id?: string }, context: Context): Promise<Approval>;\n decide(\n id: string,\n answer: unknown,\n reason: string | null,\n by: Decider,\n context: Context\n ): Promise<ApprovalDecided>;\n settled(id: string, context: Context): Promise<Approval>;\n assign(id: string, reviewer: string, context: Context): Promise<Approval | undefined>;\n withdraw(id: string, reason: string | null, context: Context): Promise<Approval | undefined>;\n withdrawSeat(seat: string, context: Context): Promise<number>;\n expire(id: string, context: Context): Promise<Approval | undefined>;\n close(): void;\n}\n\nexport interface ScoopRouter {\n route(item: Approval): Promise<void>;\n}\n\nexport interface ApprovalsAttach {\n harness: Pick<Harness, 'commit' | 'watchDoc'>;\n now?: () => number;\n setTimer?: Clock['setTimer'];\n ttlMs?: number;\n judge?: ApprovalJudge;\n scoops?: ScoopRouter;\n guestAlways?: (kind: ApprovalKind) => boolean;\n sudoApprover?: () => unknown;\n present?: (item: Approval, context: Context) => Promise<boolean>;\n}\n\nconst copy = (items: readonly Approval[]): Approval[] => JSON.parse(JSON.stringify(items));\n\nfunction mark(item: Approval, how: Settle, at: number) {\n item.state = how.state;\n item.decidedBy = how.by;\n item.decidedAt = at;\n delete item.judging;\n if (how.reason) item.reason = how.reason;\n}\n\nconst offered = (options: ApprovalsAttach, draft: ApprovalDraft): boolean =>\n guestKind(draft.kind) && draft.kind !== 'capture'\n ? options.guestAlways?.(draft.kind) === true\n : false;\n\nconst judgedKind = (kind: ApprovalKind, tier: string) =>\n kind === 'sudo' || tier === 'agent' || tier === 'user';\n\nfunction detailOf(draft: ApprovalDraft): ApprovalDraft['detail'] {\n if (draft.kind !== 'sudo' || draft.always !== false) return draft.detail;\n return { ...draft.detail, writable: false };\n}\n\nfunction fresh(\n draft: ApprovalDraft & { id?: string },\n at: number,\n ttl: number,\n options: ApprovalsAttach\n): Approval {\n const tier = tierOf(draft.kind, draft.tier, sudoApprover(options.sudoApprover?.()));\n const item = {\n ...draft,\n detail: detailOf(draft),\n tier,\n id: draft.id ?? `apr-${crypto.randomUUID()}`,\n state: 'pending',\n decidedBy: null,\n always: offered(options, draft),\n ...(options.judge && judgedKind(draft.kind, tier) ? { judging: true } : {}),\n createdAt: at,\n expiresAt: draft.expiresAt ?? at + ttl,\n } as Approval;\n if (!knownTier(item.tier))\n mark(item, { state: 'unanswered', by: 'host', reason: REASONS.unknownTier }, at);\n else if (!routable(draft.kind, item.tier))\n mark(item, { state: 'unanswered', by: 'host', reason: REASONS.unroutable }, at);\n return item;\n}\n\nconst withdrawIn =\n (match: (item: Approval) => boolean, reason: string | undefined, now: () => number) =>\n (doc: ApprovalsState) => {\n const hit = doc.items.filter((item) => item.state === 'pending' && match(item));\n for (const item of hit)\n mark(item, { state: 'withdrawn', by: 'host', ...(reason ? { reason } : {}) }, now());\n return hit.map((item) => copy([item])[0] as Approval);\n };\n\ntype Judged = { judgement: Judgement; present: boolean; offer?: boolean };\n\nconst routeOf = (item: Approval, { judgement, present }: Judged): Routed =>\n route(judgement.verdict, item.requester, gateOf(item.tier), present);\n\nconst judgedIn = (id: string, judged: Judged, now: () => number) => (doc: ApprovalsState) => {\n const { judgement } = judged;\n const item = doc.items.find((entry) => entry.id === id);\n if (!item) return undefined;\n const late = item.state === 'unanswered' && item.reason === REASONS.timeout && !item.verdict;\n if (item.state !== 'pending' && !(late && judgement.verdict)) return undefined;\n delete item.judging;\n if (judgement.verdict) item.verdict = judgement.verdict;\n else item.verdictError = judgement.error ?? 'the judge gave no verdict';\n if (late) return copy([item])[0] as Approval;\n const routed = routeOf(item, judged);\n if (routed === 'ask') {\n item.tier = 'user';\n if (item.kind === 'sudo') item.always = alwaysOffered(item);\n if (item.kind === 'capture') item.always = alwaysOffered(item) && judged.offer === true;\n return copy([item])[0] as Approval;\n }\n const at = now();\n const ruling = ruled(item, routed === 'approve' ? 'once' : 'deny', null, 'judge', at);\n if (ruling.answer) item.answer = ruling.answer;\n if (ruling.settle) mark(item, ruling.settle, at);\n return copy([item])[0] as Approval;\n};\n\nasync function judgedBy(\n judge: ApprovalJudge,\n present: ApprovalsAttach['present'],\n item: Approval,\n using: Context,\n now: () => number\n): Promise<Judged> {\n const judgement = await judge\n .judge(item, using)\n .catch((error: unknown): Judgement => ({ error: String(error) }));\n if (judgement.verdict?.level !== 3 || !present || item.tier !== 'agent')\n return { judgement, present: false };\n const there = await present(item, using).catch(() => false);\n return { judgement, present: there && item.expiresAt - now() >= ASK_MIN_MS };\n}\n\ntype Serial = <R>(change: (doc: ApprovalsState) => R, using: Context) => Promise<R>;\n\nfunction judgeRunner(run: {\n serial: Serial;\n present: ApprovalsAttach['present'];\n guestAlways: ApprovalsAttach['guestAlways'];\n now: () => number;\n closed: () => boolean;\n}) {\n const { serial, now } = run;\n return async (judge: ApprovalJudge, item: Approval, using: Context) => {\n const signal = using.abortSignal;\n let gone = false;\n const abort = () => {\n gone = true;\n void serial(\n withdrawIn((entry) => entry.id === item.id && entry.tier === 'agent', REASONS.aborted, now),\n BACKGROUND_CONTEXT\n ).catch(() => undefined);\n };\n if (signal?.aborted) return abort();\n signal?.addEventListener('abort', abort, { once: true });\n const found = await judgedBy(judge, run.present, item, using, now);\n signal?.removeEventListener('abort', abort);\n if (gone || run.closed()) return;\n const judged = { ...found, offer: run.guestAlways?.(item.kind) === true };\n const after = await serial(judgedIn(item.id, judged, now), BACKGROUND_CONTEXT).catch(\n () => undefined\n );\n if (!after) return;\n await judge.record?.(after, judged.judgement, BACKGROUND_CONTEXT).catch(() => undefined);\n };\n}\n\nfunction following(\n watch: WatchHandle<Readonly<ApprovalsState>>,\n changed: (using: Context, items: Approval[]) => void\n) {\n const items = () => watch.value.items;\n let shown = items();\n return (using: Context) => {\n const now = items();\n if (now === shown) return;\n shown = now;\n changed(using, copy(now));\n };\n}\n\nfunction settledIn(\n state: ReplicatedState<Approval[]>,\n id: string,\n using: Context\n): Promise<Approval> {\n return new Promise((resolve, reject) => {\n const signal = using.abortSignal;\n let done = false;\n let off: (() => void) | undefined;\n const finish = (end: () => void) => {\n done = true;\n off?.();\n signal?.removeEventListener('abort', abort);\n end();\n };\n const abort = () => finish(() => reject(signal?.reason));\n const check = (items: readonly Approval[] | undefined) => {\n const item = items?.find((entry) => entry.id === id);\n if (!item) finish(() => reject(new Error(`There is no approval ${id}.`)));\n else if (item.state !== 'pending') finish(() => resolve(item));\n };\n if (signal?.aborted) return abort();\n check(state.value);\n if (done) return;\n signal?.addEventListener('abort', abort, { once: true });\n off = state.subscribe((items) => check(items));\n });\n}\n\nconst systemTimer: Clock['setTimer'] = (callback, delayMs) => {\n const timer = setTimeout(callback, delayMs);\n return () => clearTimeout(timer);\n};\n\nexport async function attachApprovals(\n options: ApprovalsAttach,\n context: Context = BACKGROUND_CONTEXT\n): Promise<Approvals> {\n const { harness } = options;\n const now = options.now ?? Date.now;\n const ttl = options.ttlMs ?? APPROVAL_MS;\n const setTimer = options.setTimer ?? systemTimer;\n const timers = new Map<string, () => void>();\n let line: Promise<unknown> = Promise.resolve();\n let closed = false;\n const settle = (item: Approval, how: Settle) => mark(item, how, now());\n const write = <R>(\n change: (doc: ApprovalsState) => R,\n using: Context\n ): Promise<{ result: R; items: Approval[] }> =>\n harness.commit(async (tx) => {\n const doc = await tx.doc(ApprovalsDoc);\n const result = change(doc);\n doc.items = prune(doc.items);\n return { result, items: copy(doc.items) };\n }, using);\n const startup = await write((doc) => {\n for (const item of doc.items) {\n if (item.state !== 'pending') continue;\n if (heldKind(item.kind))\n settle(item, { state: 'withdrawn', by: 'host', reason: REASONS.restart });\n else if (item.expiresAt <= now())\n settle(item, { state: 'unanswered', by: 'host', reason: REASONS.timeout });\n else if (options.judge && item.tier === 'agent') item.tier = 'user';\n if (item.state === 'pending' && item.judging) {\n delete item.judging;\n item.verdictError = JUDGE_RESTARTED;\n }\n }\n }, context);\n const state = replicatedState<Approval[]>(startup.items);\n const watch = await harness.watchDoc(ApprovalsDoc, context);\n if (!watch) throw new Error('approvals document is missing');\n const follow = following(watch, (using, items) => {\n state.replace(using, items);\n arm(items);\n });\n follow(context);\n watch.start(async (call, using) => {\n if (call.kind === 'value') follow(using);\n });\n const serial = <R>(change: (doc: ApprovalsState) => R, using: Context): Promise<R> => {\n const run = line.then(async () => {\n const { result } = await write(change, using);\n follow(using);\n return result;\n });\n line = run.catch(() => undefined);\n return run;\n };\n const expire = (id: string) => {\n timers.delete(id);\n const due = (state.value as Approval[]).find((entry) => entry.id === id);\n if (due?.state === 'pending' && due.expiresAt > now()) return arm(state.value as Approval[]);\n void serial((doc) => {\n const item = doc.items.find((entry) => entry.id === id);\n if (item?.state === 'pending' && item.expiresAt <= now())\n settle(item, { state: 'unanswered', by: 'host', reason: REASONS.timeout });\n }, BACKGROUND_CONTEXT).catch(() => undefined);\n };\n function arm(items: readonly Approval[]) {\n const pending = new Set<string>();\n for (const item of items) {\n if (item.state !== 'pending') continue;\n pending.add(item.id);\n if (timers.has(item.id) || closed) continue;\n timers.set(\n item.id,\n setTimer(() => expire(item.id), Math.min(MAX_DELAY, Math.max(0, item.expiresAt - now())))\n );\n }\n for (const [id, timer] of timers)\n if (!pending.has(id)) {\n timer();\n timers.delete(id);\n }\n }\n arm(startup.items);\n const toScoop = (item: Approval) => {\n if (options.scoops && item.state === 'pending' && scoopTier(item.tier))\n void options.scoops.route(item).catch(() => undefined);\n };\n for (const item of startup.items) toScoop(item);\n const withdrawWhere = (match: (item: Approval) => boolean, reason: string | undefined) =>\n withdrawIn(match, reason, now);\n const judging = judgeRunner({\n serial,\n present: options.present,\n guestAlways: options.guestAlways,\n now,\n closed: () => closed,\n });\n return {\n state,\n async request(draft, using) {\n let created = true;\n const made = await serial((doc) => {\n const kept = draft.id && doc.items.find((entry) => entry.id === draft.id);\n if (kept) {\n created = false;\n return copy([kept])[0] as Approval;\n }\n const item = fresh(draft, now(), ttl, options);\n doc.items.push(item);\n return copy([item])[0] as Approval;\n }, using);\n if (created && options.judge && made.state === 'pending' && judgedKind(made.kind, made.tier))\n void judging(options.judge, made, made.tier === 'agent' ? using : BACKGROUND_CONTEXT);\n if (created) toScoop(made);\n return made;\n },\n decide(id, answer, reason, decider, using) {\n const { by, device } = deciderOf(decider);\n return serial((doc): ApprovalDecided => {\n const item = doc.items.find((entry) => entry.id === id);\n const ruling = item\n ? ruled(item, answer, reason, by, now())\n : { error: `There is no approval ${id}.` };\n if (item && ruling.settle) {\n if (ruling.answer) item.answer = ruling.answer;\n if (device && ruling.settle.by === by) item.device = device;\n settle(item, ruling.settle);\n }\n if ('error' in ruling && ruling.error)\n return { done: false, state: null, error: ruling.error };\n return { done: true, state: (item as Approval).state, error: null };\n }, using);\n },\n settled: (id, using) => settledIn(state, id, using),\n assign(id, reviewer, using) {\n return serial((doc) => {\n const item = doc.items.find((entry) => entry.id === id);\n if (item?.state === 'pending' && scoopTier(item.tier)) item.reviewer ??= reviewer;\n return item ? (copy([item])[0] as Approval) : undefined;\n }, using);\n },\n async withdraw(id, reason, using) {\n const [hit] = await serial(\n withdrawWhere((item) => item.id === id, cleanReason(reason)),\n using\n );\n return hit;\n },\n async withdrawSeat(seat, using) {\n return (\n await serial(\n withdrawWhere((item) => item.seat === seat, REASONS.revoked),\n using\n )\n ).length;\n },\n async expire(id, using) {\n return serial((doc) => {\n const item = doc.items.find((entry) => entry.id === id);\n if (item?.state === 'pending' && item.expiresAt <= now())\n settle(item, { state: 'unanswered', by: 'host', reason: REASONS.timeout });\n return item ? (copy([item])[0] as Approval) : undefined;\n }, using);\n },\n close() {\n closed = true;\n for (const timer of timers.values()) timer();\n timers.clear();\n void watch.stop();\n },\n };\n}\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EAGE;AAAA,OAEK;AACP,SAAS,0BAA0B;AAGnC,SAA6B,YAAY,uBAAuC;AAChF;AAAA,EACE;AAAA,EAKA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,E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edState,\n replicatedState,\n type WatchHandle,\n} from '@earendil-works/chord';\nimport { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';\nimport type { Harness } from '@earendil-works/pi-durable';\nimport type { Clock } from '../clock.ts';\nimport { type ApprovalJudge, ASK_MIN_MS, JUDGE_RESTARTED, type Judgement } from './judge.ts';\nimport {\n APPROVAL_MS,\n type Approval,\n type ApprovalDraft,\n type ApprovalKind,\n type ApprovalState,\n ApprovalsDoc,\n type ApprovalsState,\n alwaysOffered,\n cleanReason,\n type DecidedBy,\n gateOf,\n guestKind,\n heldKind,\n knownTier,\n MAX_DELAY,\n personOnly,\n prune,\n REASONS,\n type Routed,\n type Ruling,\n routable,\n route,\n ruled,\n type Settle,\n scoopTier,\n sudoApprover,\n tierOf,\n} from './record.ts';\n\nexport * from './intent.ts';\nexport * from './judge.ts';\nexport * from './present.ts';\nexport * from './record.ts';\n\nexport type ApprovalDecided =\n | { done: true; state: ApprovalState; error: null }\n | { done: false; state: null; error: string };\n\nexport type Decider = DecidedBy | { by: DecidedBy; device?: string };\n\nconst deciderOf = (decider: Decider) => (typeof decider === 'string' ? { by: decider } : decider);\n\nexport interface Approvals {\n readonly state: ReplicatedState<Approval[]>;\n request(draft: ApprovalDraft & { id?: string }, context: Context): Promise<Approval>;\n decide(\n id: string,\n answer: unknown,\n reason: string | null,\n by: Decider,\n context: Context\n ): Promise<ApprovalDecided>;\n settled(id: string, context: Context): Promise<Approval>;\n assign(id: string, reviewer: string, context: Context): Promise<Approval | undefined>;\n withdraw(id: string, reason: string | null, context: Context): Promise<Approval | undefined>;\n withdrawSeat(seat: string, context: Context): Promise<number>;\n expire(id: string, context: Context): Promise<Approval | undefined>;\n close(): void;\n}\n\nexport interface ScoopRouter {\n route(item: Approval): Promise<void>;\n}\n\nexport interface ApprovalsAttach {\n harness: Pick<Harness, 'commit' | 'watchDoc'>;\n now?: () => number;\n setTimer?: Clock['setTimer'];\n ttlMs?: number;\n judge?: ApprovalJudge;\n scoops?: ScoopRouter;\n guestAlways?: (kind: ApprovalKind) => boolean;\n sudoApprover?: () => unknown;\n present?: (item: Approval, context: Context) => Promise<boolean>;\n stop?: (agentId: string, context: Context) => Promise<void>;\n}\n\nconst copy = (items: readonly Approval[]): Approval[] => JSON.parse(JSON.stringify(items));\n\nfunction mark(item: Approval, how: Settle, at: number) {\n item.state = how.state;\n item.decidedBy = how.by;\n item.decidedAt = at;\n delete item.judging;\n if (how.reason) item.reason = how.reason;\n}\n\nconst offered = (options: ApprovalsAttach, draft: ApprovalDraft): boolean =>\n guestKind(draft.kind) && draft.kind !== 'capture'\n ? options.guestAlways?.(draft.kind) === true\n : false;\n\nconst judgedKind = (item: Pick<ApprovalDraft, 'kind' | 'detail'>, tier: string) =>\n !personOnly(item) && (item.kind === 'sudo' || tier === 'agent' || tier === 'user');\n\nfunction detailOf(draft: ApprovalDraft): ApprovalDraft['detail'] {\n if (draft.kind !== 'sudo' || draft.always !== false) return draft.detail;\n return { ...draft.detail, writable: false };\n}\n\nfunction fresh(\n draft: ApprovalDraft & { id?: string },\n at: number,\n ttl: number,\n options: ApprovalsAttach\n): Approval {\n const tier = tierOf(draft, sudoApprover(options.sudoApprover?.()));\n const item = {\n ...draft,\n detail: detailOf(draft),\n tier,\n id: draft.id ?? `apr-${crypto.randomUUID()}`,\n state: 'pending',\n decidedBy: null,\n always: offered(options, draft),\n ...(options.judge && judgedKind(draft, tier) ? { judging: true } : {}),\n createdAt: at,\n expiresAt: draft.expiresAt ?? at + ttl,\n } as Approval;\n if (!knownTier(item.tier))\n mark(item, { state: 'unanswered', by: 'host', reason: REASONS.unknownTier }, at);\n else if (!routable(draft.kind, item.tier))\n mark(item, { state: 'unanswered', by: 'host', reason: REASONS.unroutable }, at);\n return item;\n}\n\nconst withdrawIn =\n (match: (item: Approval) => boolean, reason: string | undefined, now: () => number) =>\n (doc: ApprovalsState) => {\n const hit = doc.items.filter((item) => item.state === 'pending' && match(item));\n for (const item of hit)\n mark(item, { state: 'withdrawn', by: 'host', ...(reason ? { reason } : {}) }, now());\n return hit.map((item) => copy([item])[0] as Approval);\n };\n\nexport const NO_STOP = \"This agent can't stop a turn.\";\n\ntype Halts = ReturnType<typeof haltsOf>;\n\ntype Halt = { agentId: string; done: Promise<void>; release: () => void };\n\nfunction haltsOf(stop: ApprovalsAttach['stop']) {\n const stopping = new Map<object, Halt>();\n const of = (agentId: string) =>\n [...stopping.values()].filter((entry) => entry.agentId === agentId);\n const drop = (token: object) => {\n stopping.get(token)?.release();\n stopping.delete(token);\n };\n return {\n halted: (agentId: string) => of(agentId).length > 0,\n async idle(agentId: string) {\n while (of(agentId).length) await Promise.all(of(agentId).map((entry) => entry.done));\n },\n able: (ruling: Ruling): Ruling => (ruling.stop && !stop ? { error: NO_STOP } : ruling),\n begin(token: object, agentId: string) {\n let release = () => {};\n const done = new Promise<void>((resolve) => {\n release = resolve;\n });\n drop(token);\n stopping.set(token, { agentId, done, release });\n },\n drop,\n async end(token: object) {\n const entry = stopping.get(token);\n if (!entry) return;\n await Promise.resolve()\n .then(() => stop?.(entry.agentId, BACKGROUND_CONTEXT))\n .catch(() => undefined);\n drop(token);\n },\n };\n}\n\ntype Deciding = {\n token: object;\n by: DecidedBy;\n device: string | undefined;\n ruling: (item: Approval) => Ruling;\n halts: Halts;\n now: () => number;\n};\n\nconst decidedIn =\n (id: string, { token, by, device, ruling: rule, halts, now }: Deciding) =>\n (doc: ApprovalsState): ApprovalDecided => {\n halts.drop(token);\n const item = doc.items.find((entry) => entry.id === id);\n const ruling: Ruling = item ? rule(item) : { error: `There is no approval ${id}.` };\n if (item && ruling.settle) {\n if (ruling.answer) item.answer = ruling.answer;\n if (device && ruling.settle.by === by) item.device = device;\n mark(item, ruling.settle, now());\n }\n if (ruling.error) return { done: false, state: null, error: ruling.error };\n if (ruling.stop) {\n halts.begin(token, ruling.stop);\n stoppedIn(ruling.stop, id, now)(doc);\n }\n return { done: true, state: (item as Approval).state, error: null };\n };\n\nconst stoppedIn = (agentId: string, id: string, now: () => number) =>\n withdrawIn(\n (item) => item.id !== id && item.agentId === agentId && heldKind(item.kind),\n REASONS.stopped,\n now\n );\n\ntype Judged = { judgement: Judgement; present: boolean; offer?: boolean };\n\nconst routeOf = (item: Approval, { judgement, present }: Judged): Routed =>\n route(judgement.verdict, item.requester, gateOf(item.tier), present);\n\nconst judgedIn = (id: string, judged: Judged, now: () => number) => (doc: ApprovalsState) => {\n const { judgement } = judged;\n const item = doc.items.find((entry) => entry.id === id);\n if (!item) return undefined;\n const late = item.state === 'unanswered' && item.reason === REASONS.timeout && !item.verdict;\n if (item.state !== 'pending' && !(late && judgement.verdict)) return undefined;\n delete item.judging;\n if (judgement.verdict) item.verdict = judgement.verdict;\n else item.verdictError = judgement.error ?? 'the judge gave no verdict';\n if (late) return copy([item])[0] as Approval;\n const routed = routeOf(item, judged);\n if (routed === 'ask') {\n item.tier = 'user';\n if (item.kind === 'sudo') item.always = alwaysOffered(item);\n if (item.kind === 'capture') item.always = alwaysOffered(item) && judged.offer === true;\n return copy([item])[0] as Approval;\n }\n const at = now();\n const ruling = ruled(item, routed === 'approve' ? 'once' : 'deny', null, 'judge', at);\n if (ruling.answer) item.answer = ruling.answer;\n if (ruling.settle) mark(item, ruling.settle, at);\n return copy([item])[0] as Approval;\n};\n\nasync function judgedBy(\n judge: ApprovalJudge,\n present: ApprovalsAttach['present'],\n item: Approval,\n using: Context,\n now: () => number\n): Promise<Judged> {\n const judgement = await judge\n .judge(item, using)\n .catch((error: unknown): Judgement => ({ error: String(error) }));\n if (judgement.verdict?.level !== 3 || !present || item.tier !== 'agent')\n return { judgement, present: false };\n const there = await present(item, using).catch(() => false);\n return { judgement, present: there && item.expiresAt - now() >= ASK_MIN_MS };\n}\n\ntype Serial = <R>(change: (doc: ApprovalsState) => R, using: Context) => Promise<R>;\n\nfunction judgeRunner(run: {\n serial: Serial;\n present: ApprovalsAttach['present'];\n guestAlways: ApprovalsAttach['guestAlways'];\n now: () => number;\n closed: () => boolean;\n}) {\n const { serial, now } = run;\n return async (judge: ApprovalJudge, item: Approval, using: Context) => {\n const signal = using.abortSignal;\n let gone = false;\n const abort = () => {\n gone = true;\n void serial(\n withdrawIn((entry) => entry.id === item.id && entry.tier === 'agent', REASONS.aborted, now),\n BACKGROUND_CONTEXT\n ).catch(() => undefined);\n };\n if (signal?.aborted) return abort();\n signal?.addEventListener('abort', abort, { once: true });\n const found = await judgedBy(judge, run.present, item, using, now);\n signal?.removeEventListener('abort', abort);\n if (gone || run.closed()) return;\n const judged = { ...found, offer: run.guestAlways?.(item.kind) === true };\n const after = await serial(judgedIn(item.id, judged, now), BACKGROUND_CONTEXT).catch(\n () => undefined\n );\n if (!after) return;\n await judge.record?.(after, judged.judgement, BACKGROUND_CONTEXT).catch(() => undefined);\n };\n}\n\nfunction following(\n watch: WatchHandle<Readonly<ApprovalsState>>,\n changed: (using: Context, items: Approval[]) => void\n) {\n const items = () => watch.value.items;\n let shown = items();\n return (using: Context) => {\n const now = items();\n if (now === shown) return;\n shown = now;\n changed(using, copy(now));\n };\n}\n\nfunction settledIn(\n state: ReplicatedState<Approval[]>,\n id: string,\n using: Context\n): Promise<Approval> {\n return new Promise((resolve, reject) => {\n const signal = using.abortSignal;\n let done = false;\n let off: (() => void) | undefined;\n const finish = (end: () => void) => {\n done = true;\n off?.();\n signal?.removeEventListener('abort', abort);\n end();\n };\n const abort = () => finish(() => reject(signal?.reason));\n const check = (items: readonly Approval[] | undefined) => {\n const item = items?.find((entry) => entry.id === id);\n if (!item) finish(() => reject(new Error(`There is no approval ${id}.`)));\n else if (item.state !== 'pending') finish(() => resolve(item));\n };\n if (signal?.aborted) return abort();\n check(state.value);\n if (done) return;\n signal?.addEventListener('abort', abort, { once: true });\n off = state.subscribe((items) => check(items));\n });\n}\n\nconst systemTimer: Clock['setTimer'] = (callback, delayMs) => {\n const timer = setTimeout(callback, delayMs);\n return () => clearTimeout(timer);\n};\n\nexport async function attachApprovals(\n options: ApprovalsAttach,\n context: Context = BACKGROUND_CONTEXT\n): Promise<Approvals> {\n const { harness } = options;\n const now = options.now ?? Date.now;\n const ttl = options.ttlMs ?? APPROVAL_MS;\n const setTimer = options.setTimer ?? systemTimer;\n const timers = new Map<string, () => void>();\n const halts = haltsOf(options.stop);\n let line: Promise<unknown> = Promise.resolve();\n let closed = false;\n const settle = (item: Approval, how: Settle) => mark(item, how, now());\n const write = <R>(\n change: (doc: ApprovalsState) => R,\n using: Context\n ): Promise<{ result: R; items: Approval[] }> =>\n harness.commit(async (tx) => {\n const doc = await tx.doc(ApprovalsDoc);\n const result = change(doc);\n doc.items = prune(doc.items);\n return { result, items: copy(doc.items) };\n }, using);\n const startup = await write((doc) => {\n for (const item of doc.items) {\n if (item.state !== 'pending') continue;\n if (heldKind(item.kind))\n settle(item, { state: 'withdrawn', by: 'host', reason: REASONS.restart });\n else if (item.expiresAt <= now())\n settle(item, { state: 'unanswered', by: 'host', reason: REASONS.timeout });\n else if (options.judge && item.tier === 'agent') item.tier = 'user';\n if (item.state === 'pending' && item.judging) {\n delete item.judging;\n item.verdictError = JUDGE_RESTARTED;\n }\n }\n }, context);\n const state = replicatedState<Approval[]>(startup.items);\n const watch = await harness.watchDoc(ApprovalsDoc, context);\n if (!watch) throw new Error('approvals document is missing');\n const follow = following(watch, (using, items) => {\n state.replace(using, items);\n arm(items);\n });\n follow(context);\n watch.start(async (call, using) => {\n if (call.kind === 'value') follow(using);\n });\n const serial = <R>(change: (doc: ApprovalsState) => R, using: Context): Promise<R> => {\n const run = line.then(async () => {\n const { result } = await write(change, using);\n follow(using);\n return result;\n });\n line = run.catch(() => undefined);\n return run;\n };\n const expire = (id: string) => {\n timers.delete(id);\n const due = (state.value as Approval[]).find((entry) => entry.id === id);\n if (due?.state === 'pending' && due.expiresAt > now()) return arm(state.value as Approval[]);\n void serial((doc) => {\n const item = doc.items.find((entry) => entry.id === id);\n if (item?.state === 'pending' && item.expiresAt <= now())\n settle(item, { state: 'unanswered', by: 'host', reason: REASONS.timeout });\n }, BACKGROUND_CONTEXT).catch(() => undefined);\n };\n function arm(items: readonly Approval[]) {\n const pending = new Set<string>();\n for (const item of items) {\n if (item.state !== 'pending') continue;\n pending.add(item.id);\n if (timers.has(item.id) || closed) continue;\n timers.set(\n item.id,\n setTimer(() => expire(item.id), Math.min(MAX_DELAY, Math.max(0, item.expiresAt - now())))\n );\n }\n for (const [id, timer] of timers)\n if (!pending.has(id)) {\n timer();\n timers.delete(id);\n }\n }\n arm(startup.items);\n const toScoop = (item: Approval) => {\n if (options.scoops && item.state === 'pending' && scoopTier(item.tier))\n void options.scoops.route(item).catch(() => undefined);\n };\n for (const item of startup.items) toScoop(item);\n const withdrawWhere = (match: (item: Approval) => boolean, reason: string | undefined) =>\n withdrawIn(match, reason, now);\n const judging = judgeRunner({\n serial,\n present: options.present,\n guestAlways: options.guestAlways,\n now,\n closed: () => closed,\n });\n return {\n state,\n async request(draft, using) {\n let created = true;\n const held = heldKind(draft.kind) && halts.halted(draft.agentId);\n if (held) await halts.idle(draft.agentId);\n const made = await serial((doc) => {\n const kept = draft.id && doc.items.find((entry) => entry.id === draft.id);\n if (kept) {\n created = false;\n return copy([kept])[0] as Approval;\n }\n const item = fresh(draft, now(), ttl, options);\n if (item.state === 'pending' && heldKind(item.kind) && (held || halts.halted(item.agentId)))\n settle(item, { state: 'withdrawn', by: 'host', reason: REASONS.stopped });\n doc.items.push(item);\n return copy([item])[0] as Approval;\n }, using);\n if (created && options.judge && made.state === 'pending' && judgedKind(made, made.tier))\n void judging(options.judge, made, made.tier === 'agent' ? using : BACKGROUND_CONTEXT);\n if (created) toScoop(made);\n return made;\n },\n async decide(id, answer, reason, decider, using) {\n const { by, device } = deciderOf(decider);\n const token = {};\n const ruling = (item: Approval) => halts.able(ruled(item, answer, reason, by, now()));\n const deciding = { token, by, device, ruling, halts, now };\n const decided = await serial(decidedIn(id, deciding), using).catch((error: unknown) => {\n halts.drop(token);\n throw error;\n });\n await halts.end(token);\n return decided;\n },\n settled: (id, using) => settledIn(state, id, using),\n assign(id, reviewer, using) {\n return serial((doc) => {\n const item = doc.items.find((entry) => entry.id === id);\n if (item?.state === 'pending' && scoopTier(item.tier)) item.reviewer ??= reviewer;\n return item ? (copy([item])[0] as Approval) : undefined;\n }, using);\n },\n async withdraw(id, reason, using) {\n const [hit] = await serial(\n withdrawWhere((item) => item.id === id, cleanReason(reason)),\n using\n );\n return hit;\n },\n async withdrawSeat(seat, using) {\n return (\n await serial(\n withdrawWhere((item) => item.seat === seat, REASONS.revoked),\n using\n )\n ).length;\n },\n async expire(id, using) {\n return serial((doc) => {\n const item = doc.items.find((entry) => entry.id === id);\n if (item?.state === 'pending' && item.expiresAt <= now())\n settle(item, { state: 'unanswered', by: 'host', reason: REASONS.timeout });\n return item ? (copy([item])[0] as Approval) : undefined;\n }, using);\n },\n close() {\n closed = true;\n for (const timer of timers.values()) timer();\n timers.clear();\n void watch.stop();\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EAGE;AAAA,OAEK;AACP,SAAS,0BAA0B;AAGnC,SAA6B,YAAY,uBAAuC;AAChF;AAAA,EACE;AAAA,EAKA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAQd,MAAM,YAAY,CAAC,YAAsB,OAAO,YAAY,WAAW,EAAE,IAAI,QAAQ,IAAI;AAqCzF,MAAM,OAAO,CAAC,UAA2C,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AAEzF,SAAS,KAAK,MAAgB,KAAa,IAAY;AACrD,OAAK,QAAQ,IAAI;AACjB,OAAK,YAAY,IAAI;AACrB,OAAK,YAAY;AACjB,SAAO,KAAK;AACZ,MAAI,IAAI,OAAQ,MAAK,SAAS,IAAI;AACp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;AACrD,iBAAO,MAAM,EAAE,OAAO,cAAc,IAAI,QAAQ,QAAQ,QAAQ,QAAQ,CAAC;AAC3E,eAAO,OAAQ,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,IAAiB;AAAA,MAChD,GAAG,KAAK;AAAA,IACV;AAAA,IACA,QAAQ;AACN,eAAS;AACT,iBAAW,SAAS,OAAO,OAAO,EAAG,OAAM;AAC3C,aAAO,MAAM;AACb,WAAK,MAAM,KAAK;AAAA,IAClB;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/approvals/people.ts"],
|
|
4
|
+
"sourcesContent": ["import type { DecidedBy } from './record.ts';\n\nexport const personal = (by: DecidedBy): boolean => by === 'owner' || by === 'follower';\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,WAAW,CAAC,OAA2B,OAAO,WAAW,OAAO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const REASONS = {
|
|
2
|
+
timeout: "timeout",
|
|
3
|
+
unknownTier: "unknown-tier",
|
|
4
|
+
unroutable: "unroutable",
|
|
5
|
+
unknownAnswer: "unknown-answer",
|
|
6
|
+
restart: "restart",
|
|
7
|
+
revoked: "revoked",
|
|
8
|
+
aborted: "aborted",
|
|
9
|
+
disconnected: "disconnected",
|
|
10
|
+
noScoop: "no-scoop",
|
|
11
|
+
scoopStopped: "scoop-stopped",
|
|
12
|
+
scoopAsked: "scoop-asked",
|
|
13
|
+
scoopUndecided: "scoop-undecided",
|
|
14
|
+
stopped: "stopped"
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
REASONS
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=reasons.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/approvals/reasons.ts"],
|
|
4
|
+
"sourcesContent": ["export const REASONS = {\n timeout: 'timeout',\n unknownTier: 'unknown-tier',\n unroutable: 'unroutable',\n unknownAnswer: 'unknown-answer',\n restart: 'restart',\n revoked: 'revoked',\n aborted: 'aborted',\n disconnected: 'disconnected',\n noScoop: 'no-scoop',\n scoopStopped: 'scoop-stopped',\n scoopAsked: 'scoop-asked',\n scoopUndecided: 'scoop-undecided',\n stopped: 'stopped',\n} as const;\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,UAAU;AAAA,EACrB,SAAS;AAAA,EACT,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,cAAc;AAAA,EACd,SAAS;AAAA,EACT,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,gBAAgB;AAAA,EAChB,SAAS;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/approvals/record.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { defineDoc } from "@earendil-works/pi-durable";
|
|
2
2
|
import { boundedDeltas } from "../checkpoints.js";
|
|
3
3
|
import { clears, fits, JUDGE_ALLOW, JUDGE_LOW, reaches } from "./aligned.js";
|
|
4
|
+
import { personal } from "./people.js";
|
|
5
|
+
import { REASONS } from "./reasons.js";
|
|
6
|
+
import { stoppable } from "./stoppable.js";
|
|
4
7
|
const ApprovalsDoc = defineDoc({
|
|
5
8
|
kind: "slicc.approvals",
|
|
6
9
|
checkpointWhen: boundedDeltas,
|
|
@@ -12,20 +15,6 @@ const APPROVAL_MS = 3e5;
|
|
|
12
15
|
const APPROVALS_KEPT = 100;
|
|
13
16
|
const MAX_DELAY = 2147483647;
|
|
14
17
|
const REASON_LENGTH = 500;
|
|
15
|
-
const REASONS = {
|
|
16
|
-
timeout: "timeout",
|
|
17
|
-
unknownTier: "unknown-tier",
|
|
18
|
-
unroutable: "unroutable",
|
|
19
|
-
unknownAnswer: "unknown-answer",
|
|
20
|
-
restart: "restart",
|
|
21
|
-
revoked: "revoked",
|
|
22
|
-
aborted: "aborted",
|
|
23
|
-
disconnected: "disconnected",
|
|
24
|
-
noScoop: "no-scoop",
|
|
25
|
-
scoopStopped: "scoop-stopped",
|
|
26
|
-
scoopAsked: "scoop-asked",
|
|
27
|
-
scoopUndecided: "scoop-undecided"
|
|
28
|
-
};
|
|
29
18
|
const guestKind = (kind) => kind !== "sudo";
|
|
30
19
|
const scoopTier = (tier) => typeof tier === "string" && /^scoop:\S+$/.test(tier);
|
|
31
20
|
function knownTier(tier) {
|
|
@@ -37,9 +26,8 @@ function routable(kind, tier) {
|
|
|
37
26
|
return !((kind === "guest-tool" || kind === "capture") && tier === "cone");
|
|
38
27
|
}
|
|
39
28
|
function answerOf(value) {
|
|
40
|
-
return value === "once" || value === "always" || value === "deny" ? value : null;
|
|
29
|
+
return value === "once" || value === "always" || value === "deny" || value === "stop" ? value : null;
|
|
41
30
|
}
|
|
42
|
-
const personal = (by) => by === "owner" || by === "follower";
|
|
43
31
|
function answerer(by, item) {
|
|
44
32
|
if (personal(by)) return item.tier === "user";
|
|
45
33
|
if (by === "judge") return item.tier === "agent";
|
|
@@ -47,7 +35,8 @@ function answerer(by, item) {
|
|
|
47
35
|
return true;
|
|
48
36
|
}
|
|
49
37
|
const sudoApprover = (value) => value === "agent" ? "agent" : "user";
|
|
50
|
-
const
|
|
38
|
+
const personOnly = (item) => item.kind === "sudo" && item.detail.validate === true;
|
|
39
|
+
const tierOf = (draft, sudo) => draft.kind !== "sudo" ? draft.tier : personOnly(draft) ? "user" : sudo;
|
|
51
40
|
const gateOf = (tier) => tier === "agent" ? "judge" : "person";
|
|
52
41
|
const vetoed = ({ forbidden }) => forbidden === true || typeof forbidden === "number" && reaches(forbidden, JUDGE_LOW);
|
|
53
42
|
function approvable(verdict) {
|
|
@@ -62,6 +51,7 @@ function route(verdict, requester, gate, present) {
|
|
|
62
51
|
}
|
|
63
52
|
function alwaysOffered(item) {
|
|
64
53
|
if (item.kind !== "sudo" && item.kind !== "capture" || item.tier !== "user") return false;
|
|
54
|
+
if (personOnly(item)) return false;
|
|
65
55
|
const { verdict } = item;
|
|
66
56
|
const writable = item.kind !== "sudo" || item.detail.writable !== false;
|
|
67
57
|
return verdict?.level === 1 && verdict.always === true && writable;
|
|
@@ -83,7 +73,15 @@ function prune(items, kept = APPROVALS_KEPT) {
|
|
|
83
73
|
const drop = new Set(settled.slice(0, Math.max(0, settled.length - kept)));
|
|
84
74
|
return items.filter((item) => !drop.has(item));
|
|
85
75
|
}
|
|
86
|
-
|
|
76
|
+
function stopped(item, by) {
|
|
77
|
+
if (!personal(by)) return { error: "Only a person can stop a turn." };
|
|
78
|
+
if (!stoppable(item)) return { error: "This request has no turn to stop." };
|
|
79
|
+
return {
|
|
80
|
+
settle: { state: "rejected", by, reason: REASONS.stopped },
|
|
81
|
+
stop: item.requester.agentId
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const why = (reason) => reason && reason !== REASONS.stopped ? { reason } : {};
|
|
87
85
|
function ruled(item, answer, reason, by, at) {
|
|
88
86
|
if (item.state !== "pending") return { error: gone(item.state) };
|
|
89
87
|
if (item.expiresAt <= at)
|
|
@@ -99,6 +97,7 @@ function ruled(item, answer, reason, by, at) {
|
|
|
99
97
|
if (known === "always" && !item.always)
|
|
100
98
|
return { error: "Always isn't offered for this request." };
|
|
101
99
|
if (!known) return { settle: { state: "rejected", by, reason: REASONS.unknownAnswer } };
|
|
100
|
+
if (known === "stop") return stopped(item, by);
|
|
102
101
|
const given = why(cleanReason(reason));
|
|
103
102
|
if (known === "deny") return { settle: { state: "rejected", by, ...given } };
|
|
104
103
|
return { settle: { state: "approved", by, ...given }, answer: known };
|
|
@@ -122,12 +121,14 @@ export {
|
|
|
122
121
|
guestKind,
|
|
123
122
|
heldKind,
|
|
124
123
|
knownTier,
|
|
124
|
+
personOnly,
|
|
125
125
|
personal,
|
|
126
126
|
prune,
|
|
127
127
|
routable,
|
|
128
128
|
route,
|
|
129
129
|
ruled,
|
|
130
130
|
scoopTier,
|
|
131
|
+
stoppable,
|
|
131
132
|
sudoApprover,
|
|
132
133
|
tierOf,
|
|
133
134
|
vetoed
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/approvals/record.ts"],
|
|
4
|
-
"sourcesContent": ["import { defineDoc } from '@earendil-works/pi-durable';\nimport { boundedDeltas } from '../checkpoints.ts';\nimport { clears, fits, JUDGE_ALLOW, JUDGE_LOW, reaches } from './aligned.ts';\n\nexport { fits, JUDGE_ALLOW };\n\nexport type ApprovalKind = 'guest-message' | 'guest-tool' | 'sudo' | 'capture';\n\nexport type ApprovalState = 'pending' | 'approved' | 'rejected' | 'unanswered' | 'withdrawn';\n\nexport type ApprovalTier = 'user' | 'agent' | 'cone' | `scoop:${string}`;\n\nexport type ApprovalAnswer = 'once' | 'always' | 'deny';\n\nexport type DecidedBy = 'owner' | 'follower' | 'judge' | 'host' | `scoop:${string}`;\n\nexport type ApprovalRequester = {\n kind: 'guest' | 'agent' | 'user';\n name: string;\n seat?: string;\n agentId?: string;\n where?: string;\n device?: string;\n};\n\nexport type ApprovalLevel = 1 | 2 | 3;\n\nexport type ApprovalVerdict = {\n level?: ApprovalLevel;\n routine?: number;\n aligned?: number | boolean;\n always?: boolean;\n reason: string;\n via?: 'classifier' | 'chat';\n risk?: number;\n model?: string;\n actions?: Record<string, number>;\n intent?: Record<string, number>;\n forbidden?: number | boolean;\n};\n\nexport type ApprovalAttachment = { name: string; mimeType: string; size: number };\n\nexport type GuestMessageDetail = { text: string; attachments: ApprovalAttachment[] };\n\nexport type GuestToolDetail = { tool: string; summary: string; arguments?: string; task?: number };\n\nexport type SudoStdin = 'tty' | 'none' | 'pipe' | 'file';\n\nexport type SudoDetail = {\n command: string;\n target?: string;\n cwd?: string;\n alwaysScope?: 'cwd';\n stdin?: SudoStdin;\n rootOnly?: Record<string, boolean>;\n writable?: boolean;\n};\n\nexport type CaptureWhat = 'screen' | 'camera' | 'microphone';\n\nexport type CaptureMode = 'still' | 'video' | 'audio';\n\nexport type CaptureDetail = {\n what: CaptureWhat;\n mode: CaptureMode;\n seconds?: number;\n system?: boolean;\n microphone?: boolean;\n device?: string;\n program: string;\n};\n\ntype Base = {\n id: string;\n seat?: string;\n agentId: string;\n requester: ApprovalRequester;\n tier: string;\n state: ApprovalState;\n decidedBy: DecidedBy | null;\n device?: string;\n answer?: 'once' | 'always';\n reviewer?: string;\n reason?: string;\n verdict?: ApprovalVerdict;\n judging?: boolean;\n verdictError?: string;\n always: boolean;\n createdAt: number;\n expiresAt: number;\n decidedAt?: number;\n};\n\nexport type GuestMessageApproval = Base & { kind: 'guest-message'; detail: GuestMessageDetail };\nexport type GuestToolApproval = Base & { kind: 'guest-tool'; detail: GuestToolDetail };\nexport type SudoApproval = Base & { kind: 'sudo'; detail: SudoDetail };\nexport type CaptureApproval = Base & { kind: 'capture'; detail: CaptureDetail };\n\nexport type Approval = GuestMessageApproval | GuestToolApproval | SudoApproval | CaptureApproval;\n\ntype DraftOf<T extends Approval> = Pick<T, 'kind' | 'detail' | 'agentId' | 'requester'> & {\n seat?: string;\n tier: string;\n always?: boolean;\n expiresAt?: number;\n};\n\nexport type ApprovalDraft =\n | DraftOf<GuestMessageApproval>\n | DraftOf<GuestToolApproval>\n | DraftOf<SudoApproval>\n | DraftOf<CaptureApproval>;\n\nexport type ApprovalsState = { items: Approval[] };\n\nexport const ApprovalsDoc = defineDoc<ApprovalsState>({\n kind: 'slicc.approvals',\n checkpointWhen: boundedDeltas,\n version: 1,\n scope: 'session',\n initial: () => ({ items: [] }),\n});\n\nexport const APPROVAL_MS = 300_000;\nexport const APPROVALS_KEPT = 100;\nexport const MAX_DELAY = 2_147_483_647;\nexport const REASON_LENGTH = 500;\n\nexport const
|
|
5
|
-
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,QAAQ,MAAM,aAAa,WAAW,eAAe;
|
|
4
|
+
"sourcesContent": ["import { defineDoc } from '@earendil-works/pi-durable';\nimport { boundedDeltas } from '../checkpoints.ts';\nimport { clears, fits, JUDGE_ALLOW, JUDGE_LOW, reaches } from './aligned.ts';\nimport { personal } from './people.ts';\nimport { REASONS } from './reasons.ts';\nimport { stoppable } from './stoppable.ts';\n\nexport { fits, JUDGE_ALLOW, personal, REASONS, stoppable };\n\nexport type ApprovalKind = 'guest-message' | 'guest-tool' | 'sudo' | 'capture';\n\nexport type ApprovalState = 'pending' | 'approved' | 'rejected' | 'unanswered' | 'withdrawn';\n\nexport type ApprovalTier = 'user' | 'agent' | 'cone' | `scoop:${string}`;\n\nexport type ApprovalAnswer = 'once' | 'always' | 'deny';\n\nexport type ApprovalDecision = ApprovalAnswer | 'stop';\n\nexport type DecidedBy = 'owner' | 'follower' | 'judge' | 'host' | `scoop:${string}`;\n\nexport type ApprovalRequester = {\n kind: 'guest' | 'agent' | 'user';\n name: string;\n seat?: string;\n agentId?: string;\n where?: string;\n device?: string;\n};\n\nexport type ApprovalLevel = 1 | 2 | 3;\n\nexport type ApprovalVerdict = {\n level?: ApprovalLevel;\n routine?: number;\n aligned?: number | boolean;\n always?: boolean;\n reason: string;\n via?: 'classifier' | 'chat';\n risk?: number;\n model?: string;\n actions?: Record<string, number>;\n intent?: Record<string, number>;\n forbidden?: number | boolean;\n};\n\nexport type ApprovalAttachment = { name: string; mimeType: string; size: number };\n\nexport type GuestMessageDetail = { text: string; attachments: ApprovalAttachment[] };\n\nexport type GuestToolDetail = { tool: string; summary: string; arguments?: string; task?: number };\n\nexport type SudoStdin = 'tty' | 'none' | 'pipe' | 'file';\n\nexport type SudoDetail = {\n command: string;\n target?: string;\n cwd?: string;\n alwaysScope?: 'cwd';\n stdin?: SudoStdin;\n rootOnly?: Record<string, boolean>;\n writable?: boolean;\n validate?: true;\n};\n\nexport type CaptureWhat = 'screen' | 'camera' | 'microphone';\n\nexport type CaptureMode = 'still' | 'video' | 'audio';\n\nexport type CaptureDetail = {\n what: CaptureWhat;\n mode: CaptureMode;\n seconds?: number;\n system?: boolean;\n microphone?: boolean;\n device?: string;\n program: string;\n};\n\ntype Base = {\n id: string;\n seat?: string;\n agentId: string;\n requester: ApprovalRequester;\n tier: string;\n state: ApprovalState;\n decidedBy: DecidedBy | null;\n device?: string;\n answer?: 'once' | 'always';\n reviewer?: string;\n reason?: string;\n verdict?: ApprovalVerdict;\n judging?: boolean;\n verdictError?: string;\n always: boolean;\n createdAt: number;\n expiresAt: number;\n decidedAt?: number;\n};\n\nexport type GuestMessageApproval = Base & { kind: 'guest-message'; detail: GuestMessageDetail };\nexport type GuestToolApproval = Base & { kind: 'guest-tool'; detail: GuestToolDetail };\nexport type SudoApproval = Base & { kind: 'sudo'; detail: SudoDetail };\nexport type CaptureApproval = Base & { kind: 'capture'; detail: CaptureDetail };\n\nexport type Approval = GuestMessageApproval | GuestToolApproval | SudoApproval | CaptureApproval;\n\ntype DraftOf<T extends Approval> = Pick<T, 'kind' | 'detail' | 'agentId' | 'requester'> & {\n seat?: string;\n tier: string;\n always?: boolean;\n expiresAt?: number;\n};\n\nexport type ApprovalDraft =\n | DraftOf<GuestMessageApproval>\n | DraftOf<GuestToolApproval>\n | DraftOf<SudoApproval>\n | DraftOf<CaptureApproval>;\n\nexport type ApprovalsState = { items: Approval[] };\n\nexport const ApprovalsDoc = defineDoc<ApprovalsState>({\n kind: 'slicc.approvals',\n checkpointWhen: boundedDeltas,\n version: 1,\n scope: 'session',\n initial: () => ({ items: [] }),\n});\n\nexport const APPROVAL_MS = 300_000;\nexport const APPROVALS_KEPT = 100;\nexport const MAX_DELAY = 2_147_483_647;\nexport const REASON_LENGTH = 500;\n\nexport const guestKind = (kind: ApprovalKind): boolean => kind !== 'sudo';\n\nexport const scoopTier = (tier: unknown): tier is `scoop:${string}` =>\n typeof tier === 'string' && /^scoop:\\S+$/.test(tier);\n\nexport function knownTier(tier: unknown): tier is ApprovalTier {\n if (tier === 'user' || tier === 'agent' || tier === 'cone') return true;\n return scoopTier(tier);\n}\n\nexport const heldKind = (kind: ApprovalKind): boolean => kind === 'sudo' || kind === 'capture';\n\nexport function routable(kind: ApprovalKind, tier: ApprovalTier): boolean {\n return !((kind === 'guest-tool' || kind === 'capture') && tier === 'cone');\n}\n\nexport function answerOf(value: unknown): ApprovalDecision | null {\n return value === 'once' || value === 'always' || value === 'deny' || value === 'stop'\n ? value\n : null;\n}\n\nexport function answerer(by: DecidedBy, item: Pick<Approval, 'tier' | 'reviewer'>): boolean {\n if (personal(by)) return item.tier === 'user';\n if (by === 'judge') return item.tier === 'agent';\n if (scoopTier(by)) return scoopTier(item.tier) && item.reviewer === by;\n return true;\n}\n\nexport type SudoApprover = 'user' | 'agent';\n\nexport const sudoApprover = (value: unknown): SudoApprover =>\n value === 'agent' ? 'agent' : 'user';\n\nexport const personOnly = (item: Pick<ApprovalDraft, 'kind' | 'detail'>): boolean =>\n item.kind === 'sudo' && (item.detail as SudoDetail).validate === true;\n\nexport const tierOf = (\n draft: Pick<ApprovalDraft, 'kind' | 'detail' | 'tier'>,\n sudo: SudoApprover\n) => (draft.kind !== 'sudo' ? draft.tier : personOnly(draft) ? 'user' : sudo);\n\nexport type Gate = 'person' | 'judge';\n\nexport type Routed = 'approve' | 'deny' | 'ask';\n\nexport const gateOf = (tier: string): Gate => (tier === 'agent' ? 'judge' : 'person');\n\nexport const vetoed = ({ forbidden }: ApprovalVerdict): boolean =>\n forbidden === true || (typeof forbidden === 'number' && reaches(forbidden, JUDGE_LOW));\n\nexport function approvable(verdict: ApprovalVerdict): boolean {\n const sure =\n verdict.routine === undefined ? verdict.via === 'chat' : clears(verdict.routine, JUDGE_ALLOW);\n return verdict.level === 1 && sure && fits(verdict.aligned);\n}\n\nexport function route(\n verdict: ApprovalVerdict | undefined,\n requester: Pick<ApprovalRequester, 'kind'>,\n gate: Gate,\n present: boolean\n): Routed {\n if (gate !== 'judge' || !verdict?.level) return 'ask';\n if (approvable(verdict) && !vetoed(verdict)) return 'approve';\n if (verdict.level === 3 && requester.kind !== 'user' && !present) return 'deny';\n return 'ask';\n}\n\nexport function alwaysOffered(item: Approval): boolean {\n if ((item.kind !== 'sudo' && item.kind !== 'capture') || item.tier !== 'user') return false;\n if (personOnly(item)) return false;\n const { verdict } = item;\n const writable = item.kind !== 'sudo' || item.detail.writable !== false;\n return verdict?.level === 1 && verdict.always === true && writable;\n}\n\nexport function gone(state: ApprovalState): string {\n if (state === 'unanswered') return 'This request timed out.';\n if (state === 'withdrawn') return 'This request was withdrawn.';\n return 'Someone else already answered this.';\n}\n\nexport function cleanReason(reason: unknown): string | undefined {\n if (typeof reason !== 'string') return undefined;\n const text = reason.trim().slice(0, REASON_LENGTH);\n return text || undefined;\n}\n\nconst decided = (item: Approval) => item.decidedAt ?? item.createdAt;\n\nexport function prune(items: Approval[], kept = APPROVALS_KEPT): Approval[] {\n const settled = items.filter((item) => item.state !== 'pending');\n settled.sort((a, b) => decided(a) - decided(b));\n const drop = new Set(settled.slice(0, Math.max(0, settled.length - kept)));\n return items.filter((item) => !drop.has(item));\n}\n\nexport type Settle = { state: Exclude<ApprovalState, 'pending'>; by: DecidedBy; reason?: string };\n\nexport type Ruling = {\n error?: string;\n settle?: Settle;\n answer?: 'once' | 'always';\n stop?: string;\n};\n\nfunction stopped(item: Approval, by: DecidedBy): Ruling {\n if (!personal(by)) return { error: 'Only a person can stop a turn.' };\n if (!stoppable(item)) return { error: 'This request has no turn to stop.' };\n return {\n settle: { state: 'rejected', by, reason: REASONS.stopped },\n stop: item.requester.agentId as string,\n };\n}\n\nconst why = (reason: string | undefined) =>\n reason && reason !== REASONS.stopped ? { reason } : {};\n\nexport function ruled(\n item: Approval,\n answer: unknown,\n reason: unknown,\n by: DecidedBy,\n at: number\n): Ruling {\n if (item.state !== 'pending') return { error: gone(item.state) };\n if (item.expiresAt <= at)\n return {\n error: gone('unanswered'),\n settle: { state: 'unanswered', by: 'host', reason: REASONS.timeout },\n };\n if (!answerer(by, item)) return { error: \"This request isn't yours to answer.\" };\n const known = answerOf(answer);\n if (known === 'always' && scoopTier(by)) return { error: 'A scoop answers once or deny.' };\n if (known === 'always' && !personal(by))\n return { error: 'Always can only be answered by a person.' };\n if (known === 'always' && !item.always)\n return { error: \"Always isn't offered for this request.\" };\n if (!known) return { settle: { state: 'rejected', by, reason: REASONS.unknownAnswer } };\n if (known === 'stop') return stopped(item, by);\n const given = why(cleanReason(reason));\n if (known === 'deny') return { settle: { state: 'rejected', by, ...given } };\n return { settle: { state: 'approved', by, ...given }, answer: known };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,QAAQ,MAAM,aAAa,WAAW,eAAe;AAC9D,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAqHnB,MAAM,eAAe,UAA0B;AAAA,EACpD,MAAM;AAAA,EACN,gBAAgB;AAAA,EAChB,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS,OAAO,EAAE,OAAO,CAAC,EAAE;AAC9B,CAAC;AAEM,MAAM,cAAc;AACpB,MAAM,iBAAiB;AACvB,MAAM,YAAY;AAClB,MAAM,gBAAgB;AAEtB,MAAM,YAAY,CAAC,SAAgC,SAAS;AAE5D,MAAM,YAAY,CAAC,SACxB,OAAO,SAAS,YAAY,cAAc,KAAK,IAAI;AAE9C,SAAS,UAAU,MAAqC;AAC7D,MAAI,SAAS,UAAU,SAAS,WAAW,SAAS,OAAQ,QAAO;AACnE,SAAO,UAAU,IAAI;AACvB;AAEO,MAAM,WAAW,CAAC,SAAgC,SAAS,UAAU,SAAS;AAE9E,SAAS,SAAS,MAAoB,MAA6B;AACxE,SAAO,GAAG,SAAS,gBAAgB,SAAS,cAAc,SAAS;AACrE;AAEO,SAAS,SAAS,OAAyC;AAChE,SAAO,UAAU,UAAU,UAAU,YAAY,UAAU,UAAU,UAA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QAAQ,EAAE,OAAO,cAAc,IAAI,QAAQ,QAAQ,QAAQ,QAAQ;AAAA,IACrE;AACF,MAAI,CAAC,SAAS,IAAI,IAAI,EAAG,QAAO,EAAE,OAAO,sCAAsC;AAC/E,QAAM,QAAQ,SAAS,MAAM;AAC7B,MAAI,UAAU,YAAY,UAAU,EAAE,EAAG,QAAO,EAAE,OAAO,gCAAgC;AACzF,MAAI,UAAU,YAAY,CAAC,SAAS,EAAE;AACpC,WAAO,EAAE,OAAO,2CAA2C;AAC7D,MAAI,UAAU,YAAY,CAAC,KAAK;AAC9B,WAAO,EAAE,OAAO,yCAAyC;AAC3D,MAAI,CAAC,MAAO,QAAO,EAAE,QAAQ,EAAE,OAAO,YAAY,IAAI,QAAQ,QAAQ,cAAc,EAAE;AACtF,MAAI,UAAU,OAAQ,QAAO,QAAQ,MAAM,EAAE;AAC7C,QAAM,QAAQ,IAAI,YAAY,MAAM,CAAC;AACrC,MAAI,UAAU,OAAQ,QAAO,EAAE,QAAQ,EAAE,OAAO,YAAY,IAAI,GAAG,MAAM,EAAE;AAC3E,SAAO,EAAE,QAAQ,EAAE,OAAO,YAAY,IAAI,GAAG,MAAM,GAAG,QAAQ,MAAM;AACtE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/approvals/stoppable.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Approval } from './record.ts';\n\nexport const stoppable = (item: Approval): boolean =>\n item.kind === 'sudo' && item.requester.kind === 'agent' && Boolean(item.requester.agentId);\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,YAAY,CAAC,SACxB,KAAK,SAAS,UAAU,KAAK,UAAU,SAAS,WAAW,QAAQ,KAAK,UAAU,OAAO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|