@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.45
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/CHANGELOG.md +131 -5
- package/README.md +371 -300
- package/dist/acp-package.d.ts +28 -0
- package/dist/acp-package.js +23 -0
- package/dist/adapter-facts.d.ts +8 -1
- package/dist/adapter-facts.js +9 -1
- package/dist/adapters.d.ts +5 -0
- package/dist/adapters.js +36 -3
- package/dist/agent-delete.d.ts +50 -0
- package/dist/agent-delete.js +125 -0
- package/dist/agents-store.d.ts +9 -3
- package/dist/agents-store.js +22 -8
- package/dist/agents.d.ts +5 -1
- package/dist/agents.js +8 -4
- package/dist/api-only.d.ts +8 -3
- package/dist/api-only.js +10 -4
- package/dist/archil-routes.d.ts +5 -1
- package/dist/archil-routes.js +57 -2
- package/dist/browser-wait-ended.d.ts +2 -0
- package/dist/browser-wait-ended.js +2 -0
- package/dist/calendar/ics-faux.d.ts +3 -1
- package/dist/calendar/ics-faux.js +12 -2
- package/dist/calendar/tools.js +5 -2
- package/dist/chatgpt-plan.js +3 -1
- package/dist/claude-login.d.ts +135 -0
- package/dist/claude-login.js +244 -0
- package/dist/cli.js +52 -16
- package/dist/composio-preset.js +69 -7
- package/dist/composio-triggers.d.ts +14 -0
- package/dist/composio-triggers.js +79 -15
- package/dist/computer-attach.d.ts +40 -5
- package/dist/computer-attach.js +130 -15
- package/dist/computer-keys.d.ts +3 -0
- package/dist/computer-keys.js +7 -1
- package/dist/computer-live.js +3 -2
- package/dist/computers.d.ts +21 -10
- package/dist/computers.js +39 -28
- package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
- package/dist/console/assets/index-DaFsZuzQ.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/dial-relay.d.ts +29 -0
- package/dist/dial-relay.js +94 -0
- package/dist/email/tools.js +10 -5
- package/dist/env-proxy.d.ts +2 -0
- package/dist/env-proxy.js +35 -0
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +7 -4
- package/dist/faux-computers.d.ts +8 -2
- package/dist/faux-computers.js +83 -6
- package/dist/harness-archive.d.ts +67 -0
- package/dist/harness-archive.js +177 -0
- package/dist/harness-goose.d.ts +34 -0
- package/dist/harness-goose.js +87 -0
- package/dist/harness-install.d.ts +21 -0
- package/dist/harness-install.js +24 -11
- package/dist/harness-opencode/adapter.js +1 -1
- package/dist/harness-table.d.ts +9 -1
- package/dist/harness-table.js +20 -3
- package/dist/harness.d.ts +1 -2
- package/dist/harness.js +3 -4
- package/dist/host.js +2 -1
- package/dist/key-check.js +3 -0
- package/dist/learn/audit.d.ts +6 -6
- package/dist/learn/audit.js +3 -7
- package/dist/learn/check.d.ts +23 -89
- package/dist/learn/check.js +57 -335
- package/dist/learn/commit.d.ts +63 -90
- package/dist/learn/commit.js +124 -316
- package/dist/learn/compile.d.ts +53 -50
- package/dist/learn/compile.js +87 -102
- package/dist/learn/corrections.d.ts +13 -0
- package/dist/learn/corrections.js +23 -0
- package/dist/learn/delete.d.ts +5 -5
- package/dist/learn/delete.js +8 -10
- package/dist/learn/folder.d.ts +35 -47
- package/dist/learn/folder.js +118 -134
- package/dist/learn/index.d.ts +3 -5
- package/dist/learn/index.js +6 -9
- package/dist/learn/learning.sh +45 -15
- package/dist/learn/promote.d.ts +13 -1
- package/dist/learn/promote.js +9 -0
- package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
- package/dist/learn/{skills.js → workflow-draft.js} +48 -58
- package/dist/learn/workflow-nodes.js +1 -1
- package/dist/learned-workflow.js +2 -2
- package/dist/learning-cost.d.ts +38 -24
- package/dist/learning-cost.js +41 -24
- package/dist/learning-routes.d.ts +91 -170
- package/dist/learning-routes.js +183 -421
- package/dist/learning-run.d.ts +19 -40
- package/dist/learning-run.js +23 -93
- package/dist/learning-setting.d.ts +4 -4
- package/dist/learning-setting.js +6 -6
- package/dist/learning-words.d.ts +28 -74
- package/dist/learning-words.js +64 -162
- package/dist/learning.d.ts +61 -392
- package/dist/learning.js +101 -651
- package/dist/live-reach.d.ts +25 -2
- package/dist/live-reach.js +46 -4
- package/dist/llms.txt +1 -1
- package/dist/local-models.d.ts +3 -11
- package/dist/local-models.js +5 -6
- package/dist/mcp-servers-store.d.ts +4 -4
- package/dist/model-form.js +6 -5
- package/dist/model.d.ts +4 -0
- package/dist/model.js +26 -9
- package/dist/native/binding.js +1 -1
- package/dist/native/connection.js +1 -1
- package/dist/native/discovery.js +1 -1
- package/dist/native/instructions.d.ts +3 -0
- package/dist/native/instructions.js +5 -3
- package/dist/native/remote-worker-bridge.js +9 -43
- package/dist/native/remote.d.ts +8 -15
- package/dist/native/remote.js +3 -3
- package/dist/native/schema.js +1 -1
- package/dist/native/types.d.ts +2 -2
- package/dist/openapi.js +268 -316
- package/dist/paid-calls.d.ts +8 -0
- package/dist/paid-calls.js +20 -0
- package/dist/particle-provider.d.ts +11 -0
- package/dist/particle-provider.js +135 -0
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +28 -11
- package/dist/print.d.ts +27 -0
- package/dist/print.js +21 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +15 -1
- package/dist/reflect-range.js +2 -3
- package/dist/run-launch.d.ts +14 -28
- package/dist/run-launch.js +9 -12
- package/dist/run-learning-served.d.ts +15 -89
- package/dist/run-listing.d.ts +34 -0
- package/dist/run-listing.js +128 -0
- package/dist/run-model-key.js +1 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-trace.d.ts +97 -0
- package/dist/run-trace.js +253 -0
- package/dist/run-view.d.ts +15 -0
- package/dist/run-view.js +9 -0
- package/dist/runnable.js +2 -1
- package/dist/runner/adapter-loop.d.ts +8 -6
- package/dist/runner/adapter-loop.js +16 -12
- package/dist/runner/adapter-run-spec.d.ts +16 -4
- package/dist/runner/adapter-run-spec.js +64 -58
- package/dist/runner/adapters/index.js +22 -0
- package/dist/runner/adapters/pi.d.ts +4 -12
- package/dist/runner/adapters/pi.js +2 -2
- package/dist/runner/audit.d.ts +1 -1
- package/dist/runner/audit.js +16 -8
- package/dist/runner/beside.d.ts +6 -2
- package/dist/runner/beside.js +38 -9
- package/dist/runner/claim-secrets.d.ts +18 -2
- package/dist/runner/claim-secrets.js +42 -18
- package/dist/runner/cli-run-spec.js +55 -51
- package/dist/runner/conformance/harness.d.ts +6 -0
- package/dist/runner/conformance/harness.js +16 -5
- package/dist/runner/dispatch.d.ts +2 -2
- package/dist/runner/end-of-run.d.ts +6 -14
- package/dist/runner/end-of-run.js +8 -33
- package/dist/runner/feedback-round.d.ts +2 -2
- package/dist/runner/feedback-round.js +7 -7
- package/dist/runner/github-app.js +3 -1
- package/dist/runner/harness-loops.d.ts +0 -8
- package/dist/runner/harness-loops.js +11 -59
- package/dist/runner/held.d.ts +170 -0
- package/dist/runner/held.js +57 -0
- package/dist/runner/journal-kinds.d.ts +2 -3
- package/dist/runner/journal-kinds.js +2 -3
- package/dist/runner/learned-first.d.ts +40 -0
- package/dist/runner/learned-first.js +32 -0
- package/dist/runner/learning-end.d.ts +77 -69
- package/dist/runner/learning-end.js +250 -303
- package/dist/runner/learning-seed.d.ts +15 -33
- package/dist/runner/learning-seed.js +24 -45
- package/dist/runner/loop-contract.d.ts +2 -3
- package/dist/runner/main.d.ts +17 -9
- package/dist/runner/main.js +63 -20
- package/dist/runner/mcp-run.d.ts +11 -0
- package/dist/runner/mcp-run.js +67 -0
- package/dist/runner/memory-claim.d.ts +10 -5
- package/dist/runner/memory-claim.js +12 -6
- package/dist/runner/model-route.d.ts +7 -4
- package/dist/runner/model-route.js +22 -10
- package/dist/runner/native-loop.d.ts +0 -7
- package/dist/runner/native-loop.js +9 -101
- package/dist/runner/promotion.d.ts +8 -6
- package/dist/runner/promotion.js +19 -12
- package/dist/runner/reflect-hook.d.ts +64 -95
- package/dist/runner/reflect-hook.js +112 -225
- package/dist/runner/run-channel.d.ts +43 -0
- package/dist/runner/run-channel.js +467 -0
- package/dist/runner/run-child-host.d.ts +169 -0
- package/dist/runner/run-child-host.js +1222 -0
- package/dist/runner/run-child.d.ts +1 -0
- package/dist/runner/run-child.js +254 -0
- package/dist/runner/run-errors.d.ts +2 -0
- package/dist/runner/run-errors.js +20 -0
- package/dist/runner/runner.js +1 -5
- package/dist/runner/sdk-ask.d.ts +78 -0
- package/dist/runner/sdk-ask.js +158 -0
- package/dist/runner/sdk-loop.d.ts +2 -4
- package/dist/runner/sdk-loop.js +29 -49
- package/dist/runner/store-secrets.d.ts +5 -3
- package/dist/runner/store-secrets.js +5 -1
- package/dist/runner/workflow-first.d.ts +5 -0
- package/dist/runner/workflow-first.js +4 -0
- package/dist/runner/workflow-spec.js +7 -2
- package/dist/runs-over-store.d.ts +16 -28
- package/dist/runs-over-store.js +31 -38
- package/dist/sdk/runs.d.ts +6 -11
- package/dist/sdk/runs.js +20 -41
- package/dist/sdk/schema.js +3 -4
- package/dist/seal-key.d.ts +5 -0
- package/dist/seal-key.js +7 -0
- package/dist/secrets.d.ts +3 -0
- package/dist/secrets.js +16 -3
- package/dist/server.d.ts +55 -33
- package/dist/server.js +685 -320
- package/dist/sign-ins-store.d.ts +8 -0
- package/dist/sign-ins-store.js +36 -1
- package/dist/skills.js +1 -1
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +3 -0
- package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
- package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
- package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
- package/dist/store/schema.d.ts +53 -4
- package/dist/store/schema.js +137 -6
- package/dist/store/sqlite/connection.d.ts +2 -0
- package/dist/store/sqlite/connection.js +3 -1
- package/dist/store/sqlite/run-patch.d.ts +0 -17
- package/dist/store/sqlite/run-patch.js +4 -33
- package/dist/store/sqlite/store.js +246 -63
- package/dist/store/sqlite/worker.js +25 -0
- package/dist/store/store.d.ts +193 -36
- package/dist/store/store.js +25 -3
- package/dist/store-reads/learning.d.ts +102 -204
- package/dist/store-reads/learning.js +159 -321
- package/dist/store-reads/loop.d.ts +0 -1
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +29 -1
- package/dist/store-view.js +97 -31
- package/dist/template-eval.d.ts +3 -6
- package/dist/template-eval.js +22 -36
- package/dist/templates.d.ts +2 -1
- package/dist/templates.js +6 -3
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -1
- package/dist/timeline/timeline.js +16 -0
- package/dist/tool-gate.d.ts +0 -7
- package/dist/tool-gate.js +1 -15
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +6 -4
- package/dist/tool-keys.js +12 -6
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +11 -4
- package/dist/triggers.d.ts +60 -5
- package/dist/triggers.js +123 -18
- package/dist/validate.js +1 -1
- package/dist/webhooks.d.ts +4 -1
- package/dist/webhooks.js +11 -4
- package/dist/workspace/agent-computer.d.ts +2 -0
- package/dist/workspace/agent-computer.js +2 -0
- package/dist/workspace/archil-claim.d.ts +7 -0
- package/dist/workspace/archil-claim.js +29 -0
- package/dist/workspace/archil.d.ts +9 -1
- package/dist/workspace/archil.js +165 -3
- package/dist/workspace/attach.d.ts +3 -1
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/attached-computers.d.ts +16 -5
- package/dist/workspace/attached-computers.js +25 -9
- package/dist/workspace/computer-deps.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +7 -3
- package/dist/workspace/computer-for-claim.js +119 -22
- package/dist/workspace/computer-hold.js +2 -1
- package/dist/workspace/computer-kept.d.ts +11 -1
- package/dist/workspace/computer-kept.js +24 -3
- package/dist/workspace/resolve-computer.d.ts +33 -19
- package/dist/workspace/resolve-computer.js +172 -64
- package/dist/workspace/revision-skills.d.ts +1 -2
- package/dist/workspace/revision-skills.js +3 -4
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +5 -0
- package/dist/workspace/synced-folder.d.ts +85 -0
- package/dist/workspace/synced-folder.js +230 -0
- package/dist/workspace/workspace.d.ts +4 -0
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/templates/README.md +7 -7
- package/templates/inbound-lead/agent.md +3 -3
- package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
- package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
- package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
- package/templates/inbound-lead/lead.schema.json +6 -5
- package/templates/inbound-lead/rules/RUBRIC.md +4 -4
- package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
- package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
- package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
- package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
- package/templates/release-notes/evals/learned-style/case.yaml +4 -4
- package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
- package/templates/release-notes/evals/learned-style/prompt.md +1 -1
- package/dist/console/assets/index-BUktRvS-.css +0 -1
- package/dist/console/assets/index-nB9kTfIN.js +0 -711
- package/dist/learn/grade.d.ts +0 -138
- package/dist/learn/grade.js +0 -682
- package/dist/learn/notes.d.ts +0 -81
- package/dist/learn/notes.js +0 -178
- package/dist/learn/reflect.d.ts +0 -77
- package/dist/learn/reflect.js +0 -228
- package/dist/learn/relevance.d.ts +0 -24
- package/dist/learn/relevance.js +0 -91
- package/dist/learn/seed-check.d.ts +0 -74
- package/dist/learn/seed-check.js +0 -103
- package/dist/learning-batch.d.ts +0 -291
- package/dist/learning-batch.js +0 -600
- package/dist/learning-evals.d.ts +0 -35
- package/dist/learning-evals.js +0 -99
- package/dist/native/context.d.ts +0 -6
- package/dist/native/context.js +0 -22
- package/dist/propose.d.ts +0 -52
- package/dist/propose.js +0 -224
- package/dist/runner/learning-ask.d.ts +0 -47
- package/dist/runner/learning-ask.js +0 -128
- package/dist/runner/learning-dispatch.d.ts +0 -45
- package/dist/runner/learning-dispatch.js +0 -99
- package/dist/runner/learning-factory.d.ts +0 -16
- package/dist/runner/learning-factory.js +0 -50
- package/dist/runner/learning-loop.d.ts +0 -273
- package/dist/runner/learning-loop.js +0 -521
- package/dist/usage.d.ts +0 -11
- package/dist/usage.js +0 -11
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
package/dist/tool-gate.js
CHANGED
|
@@ -26,8 +26,7 @@
|
|
|
26
26
|
// in words, never parked.
|
|
27
27
|
import { COMPUTER_OP_TOOL, computerToolDefs, defaultPermissionOf, SHELL_FAMILY, SHELL_WATCHERS, shellPermission, shellToolOf } from "@parcha/agentrun-kernel/kernel";
|
|
28
28
|
import { READ_SKILL_FILE } from "@parcha/agentrun-kernel";
|
|
29
|
-
import {
|
|
30
|
-
import { COMPUTER_ROOT, portPath } from "./workspace/paths.js";
|
|
29
|
+
import { COMPUTER_ROOT } from "./workspace/paths.js";
|
|
31
30
|
import { builtinHarness } from "./harness-table.js";
|
|
32
31
|
import { META_TOOLS } from "./meta-tool-names.js";
|
|
33
32
|
import { DEFAULT_HARNESS } from "./harness.js";
|
|
@@ -338,19 +337,6 @@ export const noApproverText = (tool, ran = "no", because) => because === undefin
|
|
|
338
337
|
export const APPROVAL_ROW = "tool_approval_requested";
|
|
339
338
|
/** A call's arguments shown on its approval, at most this many bytes. */
|
|
340
339
|
export const ARGS_PREVIEW_BYTES = 2048;
|
|
341
|
-
/** The refusal of the end-of-run turn's write or edit under work/.learning/: its notes are kept only from its answer's
|
|
342
|
-
* note blocks (learn/reflect.ts parseReflection), which the host merges in its own store; a file there is never kept. */
|
|
343
|
-
export const NOTE_ONLY_TEXT = "A note is kept only from your answer: write it in a ```note block, not to a file.";
|
|
344
|
-
/** Whether `args.path`, as a file tool resolves it (a leading `@` dropped, Unicode spaces made plain, then the port's
|
|
345
|
-
* path of it, portPath), names .learning/ in the run's folder or a path under it: by the folder's path here (`work`)
|
|
346
|
-
* or a computer's name for it (COMPUTER_ROOT). */
|
|
347
|
-
export function underLearning(work, args) {
|
|
348
|
-
const path = args?.path;
|
|
349
|
-
if (typeof path !== "string")
|
|
350
|
-
return false;
|
|
351
|
-
const plain = path.replace(/[\u00A0\u2002-\u200A\u202F\u205F\u3000]/g, " ").replace(/^@/, "");
|
|
352
|
-
return portPath(plain, [work, COMPUTER_ROOT])?.split("/")[0] === LEARNED_DIR;
|
|
353
|
-
}
|
|
354
340
|
/** `text` cut to at most ARGS_PREVIEW_BYTES. What is shown of a call's arguments is the whole of them redacted first, then
|
|
355
341
|
* cut (runs.ts), so a cut never leaves the head of a key no redaction recognizes. */
|
|
356
342
|
export function previewOf(text) {
|
package/dist/tool-keys.d.ts
CHANGED
|
@@ -50,7 +50,8 @@ export declare const TOOL_KEYS: readonly [{
|
|
|
50
50
|
export declare const TOOL_FIELDS: readonly string[];
|
|
51
51
|
/** What `candidates` unlock here, as capabilities show it: the tools of `tools` (capabilities' `tools`, available or
|
|
52
52
|
* not) and the providers of `providers` (its `workflows.decisions.providers`) named among them, and the harnesses
|
|
53
|
-
* that run those tools
|
|
53
|
+
* that run those tools: the built-in ones first, then any other the tools run on (Goose once its owner installs it). A
|
|
54
|
+
* name neither holds is left out; a key that unlocks none of its names lists nothing. */
|
|
54
55
|
export declare function unlockedBy(candidates: readonly string[], tools: readonly {
|
|
55
56
|
name: string;
|
|
56
57
|
harnesses: readonly string[];
|
|
@@ -58,14 +59,15 @@ export declare function unlockedBy(candidates: readonly string[], tools: readonl
|
|
|
58
59
|
id: string;
|
|
59
60
|
}[]): {
|
|
60
61
|
unlocks: string[];
|
|
61
|
-
harnesses:
|
|
62
|
+
harnesses: string[];
|
|
62
63
|
};
|
|
63
64
|
/** What a row unlocks here: a `tool` row's, its tools and providers as capabilities bind them (unlockedBy); any other
|
|
64
65
|
* kind's (a model's), no tool, on those that run on it (its `harnesses`, when it names them) that this server runs
|
|
65
66
|
* (`offers`, harness.ts' harnessOffers) on the row's key: one whose `keys` (the model keys that run it here, available
|
|
66
67
|
* now or once one is saved) include the row's (its first field). So OpenRouter's row names all three before any key
|
|
67
68
|
* is saved, and no row changes when another provider's key is saved; a harness not installed, off its pins or too big
|
|
68
|
-
* for this host is left out.
|
|
69
|
+
* for this host is left out. A harness the server lists beyond the built-in ones (Goose once its owner installs it: it
|
|
70
|
+
* has no offer before) is named, after them, where its own offer's `keys` name the row's. */
|
|
69
71
|
export declare function rowUnlocks(row: {
|
|
70
72
|
kind: string;
|
|
71
73
|
unlocks: readonly string[];
|
|
@@ -77,7 +79,7 @@ export declare function rowUnlocks(row: {
|
|
|
77
79
|
keys?: readonly string[];
|
|
78
80
|
}[]): {
|
|
79
81
|
unlocks: string[];
|
|
80
|
-
harnesses:
|
|
82
|
+
harnesses: string[];
|
|
81
83
|
};
|
|
82
84
|
/** Whether a key row's `unlock` unlocks the tool `name`: by its name, or `<source>:*` for every tool of a catalog source
|
|
83
85
|
* (`monid:*`: `monid:apollo/people/match`, `monid:apollo/*`). */
|
package/dist/tool-keys.js
CHANGED
|
@@ -29,21 +29,25 @@ export const TOOL_KEYS = [
|
|
|
29
29
|
export const TOOL_FIELDS = TOOL_KEYS.filter((row) => row.kind === "tool").flatMap((row) => row.fields);
|
|
30
30
|
/** What `candidates` unlock here, as capabilities show it: the tools of `tools` (capabilities' `tools`, available or
|
|
31
31
|
* not) and the providers of `providers` (its `workflows.decisions.providers`) named among them, and the harnesses
|
|
32
|
-
* that run those tools
|
|
32
|
+
* that run those tools: the built-in ones first, then any other the tools run on (Goose once its owner installs it). A
|
|
33
|
+
* name neither holds is left out; a key that unlocks none of its names lists nothing. */
|
|
33
34
|
export function unlockedBy(candidates, tools, providers) {
|
|
34
35
|
const bound = new Set([...tools.map((tool) => tool.name), ...providers.map((provider) => `decisions.${provider.id}`)]);
|
|
35
36
|
// A catalog source's tools (`monid:*`) are granted by name, never listed: the source is shown as it is, and its tools are
|
|
36
|
-
// host tools, run on every harness.
|
|
37
|
+
// host tools, run on every harness: the built-in ones and any other a tool here runs on.
|
|
37
38
|
const unlocks = candidates.filter((name) => bound.has(name) || name.endsWith(":*"));
|
|
38
|
-
const
|
|
39
|
-
|
|
39
|
+
const every = unlocks.some((name) => name.endsWith(":*"));
|
|
40
|
+
const run = new Set(tools.filter((tool) => every || unlocks.includes(tool.name)).flatMap((tool) => tool.harnesses));
|
|
41
|
+
const listed = [...run].filter((harness) => !HARNESSES.includes(harness));
|
|
42
|
+
return { unlocks, harnesses: [...HARNESSES.filter((harness) => every || run.has(harness)), ...listed] };
|
|
40
43
|
}
|
|
41
44
|
/** What a row unlocks here: a `tool` row's, its tools and providers as capabilities bind them (unlockedBy); any other
|
|
42
45
|
* kind's (a model's), no tool, on those that run on it (its `harnesses`, when it names them) that this server runs
|
|
43
46
|
* (`offers`, harness.ts' harnessOffers) on the row's key: one whose `keys` (the model keys that run it here, available
|
|
44
47
|
* now or once one is saved) include the row's (its first field). So OpenRouter's row names all three before any key
|
|
45
48
|
* is saved, and no row changes when another provider's key is saved; a harness not installed, off its pins or too big
|
|
46
|
-
* for this host is left out.
|
|
49
|
+
* for this host is left out. A harness the server lists beyond the built-in ones (Goose once its owner installs it: it
|
|
50
|
+
* has no offer before) is named, after them, where its own offer's `keys` name the row's. */
|
|
47
51
|
export function rowUnlocks(row, tools, providers, offers) {
|
|
48
52
|
if (row.kind === "tool")
|
|
49
53
|
return unlockedBy(row.unlocks, tools, providers);
|
|
@@ -51,7 +55,9 @@ export function rowUnlocks(row, tools, providers, offers) {
|
|
|
51
55
|
// Where an offer knows which model keys run it (its `keys`), the row's key must be one of them, available now or not;
|
|
52
56
|
// else (no key runs it: pi on any, or one unavailable for another reason) whether it runs here now.
|
|
53
57
|
const runs = (harness) => offers.some((offer) => offer.id === harness && (offer.keys ? key !== undefined && offer.keys.includes(key) : offer.available));
|
|
54
|
-
|
|
58
|
+
const builtin = HARNESSES.filter((harness) => (row.harnesses ?? HARNESSES).includes(harness) && runs(harness));
|
|
59
|
+
const listed = offers.filter((offer) => !HARNESSES.includes(offer.id) && key !== undefined && offer.keys?.includes(key)).map((offer) => offer.id);
|
|
60
|
+
return { unlocks: [], harnesses: [...builtin, ...listed] };
|
|
55
61
|
}
|
|
56
62
|
/** Whether a key row's `unlock` unlocks the tool `name`: by its name, or `<source>:*` for every tool of a catalog source
|
|
57
63
|
* (`monid:*`: `monid:apollo/people/match`, `monid:apollo/*`). */
|
package/dist/tools.d.ts
CHANGED
|
@@ -261,7 +261,7 @@ export declare const savedOnRelease: (row: {
|
|
|
261
261
|
/** On the runner, the per-session hook that verifies the run's saved sign-in: a session that saved to it (savedOnRelease,
|
|
262
262
|
* in a run handed it to save) verifies it under the run's claim, at the session's own end (its time, else now), as the
|
|
263
263
|
* saved mark main reads at the lease's end. Answers whether it verified (sign-ins-store.ts verifyRunSignIn). */
|
|
264
|
-
export declare const runSignInSaved: (store: Pick<Store, "runs" | "signIns">, sealKey: Buffer, claim: Claim, kept: RunSignIn) => (row: {
|
|
264
|
+
export declare const runSignInSaved: (store: Pick<Store, "runs" | "signIns">, sealKey: Buffer | undefined, claim: Claim, kept: RunSignIn) => (row: {
|
|
265
265
|
session: {
|
|
266
266
|
resourceId: string | null;
|
|
267
267
|
releaseReason: string | null;
|
|
@@ -279,7 +279,7 @@ export declare const allows: (allowed: readonly string[], name: string) => boole
|
|
|
279
279
|
* agent's `granted` tools a workflow's call node runs here (CALL_TOOLS, and each MCP tool granted by its own name,
|
|
280
280
|
* tool-names.ts mcpNameOf), and with the run's `plane`, none it resolves unavailable (its agent's own tool of the name
|
|
281
281
|
* does not run either). A
|
|
282
|
-
* learned model node runs without tools (learn/
|
|
282
|
+
* learned model node runs without tools (learn/workflow-draft.ts MODEL_NODE_TOOLS), and a harness's own tool (Bash,
|
|
283
283
|
* exec_command, apply_patch) is never one, so the DSL refuses a draft that names it. */
|
|
284
284
|
export declare const learnedWorkflowTools: (granted: readonly string[], plane?: Plane, options?: LearnedMcp) => string[];
|
|
285
285
|
/** `mcp: true` at learn time (the end-of-run step's draft tools, a person's write): an MCP tool the revision grants by its
|
package/dist/tools.js
CHANGED
|
@@ -47,6 +47,7 @@ import { HANDOVER_WAITING } from "./runner/journal-kinds.js";
|
|
|
47
47
|
import { provenFor } from "./live-reach.js";
|
|
48
48
|
import { clearWaitEnded, markWaitEnded } from "./browser-wait-ended.js";
|
|
49
49
|
import { runSignIn, verifyRunSignIn } from "./sign-ins-store.js";
|
|
50
|
+
import { held } from "./runner/held.js";
|
|
50
51
|
export const ASK_TOOL = "ask_person";
|
|
51
52
|
/** Under `--faux` only: a module whose default export gives the browser's `{ computer, driver }` for the run's
|
|
52
53
|
* environment, the vendor its plane names and the saved sign-in it was handed for that vendor (`{ provider, ref, save }`,
|
|
@@ -262,7 +263,11 @@ export const runSignInSaved = (store, sealKey, claim, kept) => async (row, chang
|
|
|
262
263
|
if (!kept.save || !savedOnRelease(row, change))
|
|
263
264
|
return false;
|
|
264
265
|
const ended = row.session.endedAt ? Date.parse(row.session.endedAt) : Number.NaN;
|
|
265
|
-
|
|
266
|
+
const at = Number.isFinite(ended) ? ended : Date.now();
|
|
267
|
+
// A run's own process holds no seal key: its runner marks it under the claim (held.ts verifySignIn).
|
|
268
|
+
if (!sealKey)
|
|
269
|
+
return (await held()?.verifySignIn(kept, at)) ?? false;
|
|
270
|
+
return verifyRunSignIn(store, sealKey, claim, kept, at);
|
|
266
271
|
};
|
|
267
272
|
/** A browser on pi-browser's durable adapter, its sessions a browser computer provider's of the computer registry
|
|
268
273
|
* (browser-computer.ts), each driven over its CDP URL by pi-browser's raw-CDP driver: the agent's computer, where it is
|
|
@@ -309,7 +314,9 @@ const browserTool = {
|
|
|
309
314
|
// launch makes it: never the process's environment, so one run's keys never make another's.
|
|
310
315
|
const runLog = (line) => void process.stderr.write(`agentrun-serve: run ${host.where.ref.id}: ${line}\n`);
|
|
311
316
|
const vendorFetch = async () => (host.env[FAUX_ENV] ? fauxFetch(host.env, FAUX_VENDOR_API_ENV) : fetch);
|
|
312
|
-
|
|
317
|
+
// A run's own process holds no seal key: its runner opens the run's sign-in under the claim (held.ts runSignIn).
|
|
318
|
+
const atRunner = held();
|
|
319
|
+
const handed = computer ? undefined : host.claim ? (planeRefused || !host.store ? undefined : host.sealKey ? await runSignIn(host.store, host.sealKey, host.claim, vendor, { vendors: vendorsOver(() => host.env, vendorFetch), log: runLog }) : await atRunner?.runSignIn(vendor)) : handedSignIn();
|
|
313
320
|
const kept = !planeRefused && handed?.provider === vendor ? handed : undefined;
|
|
314
321
|
// Tests only (--faux): the faux browser's computer provider and driver stand in for the plane vendor's and the raw-CDP
|
|
315
322
|
// driver. The agent's browser computer is still the claim's, so a test hands the claim a faux provider of its own.
|
|
@@ -445,7 +452,7 @@ const browserTool = {
|
|
|
445
452
|
const files = { files: uploadsFrom(work, MAX_UPLOAD_BYTES, uploadMime), ...(folder !== undefined && keepsDownloads ? { workspace: () => folder } : {}) };
|
|
446
453
|
// A session that saved to the sign-in, let go: its time, for the sign-in's verified_at when the run's lease ends.
|
|
447
454
|
// On the runner, the store's verified_at under the run's claim (runSignInSaved), never a mark in the run's directory.
|
|
448
|
-
const verify = kept?.save && host.claim && host.store && host.sealKey ? runSignInSaved(host.store, host.sealKey, host.claim, kept) : undefined;
|
|
455
|
+
const verify = kept?.save && host.claim && host.store && (host.sealKey || held()) ? runSignInSaved(host.store, host.sealKey, host.claim, kept) : undefined;
|
|
449
456
|
// Awaited by the session's change, so the release that lets a run's sessions go (beforeRelease) returns only once its
|
|
450
457
|
// last save is verified: the run's end commit, which ends the claim, never fences it.
|
|
451
458
|
const saved = verify
|
|
@@ -649,7 +656,7 @@ export const allows = (allowed, name) => allowed.includes(name);
|
|
|
649
656
|
* agent's `granted` tools a workflow's call node runs here (CALL_TOOLS, and each MCP tool granted by its own name,
|
|
650
657
|
* tool-names.ts mcpNameOf), and with the run's `plane`, none it resolves unavailable (its agent's own tool of the name
|
|
651
658
|
* does not run either). A
|
|
652
|
-
* learned model node runs without tools (learn/
|
|
659
|
+
* learned model node runs without tools (learn/workflow-draft.ts MODEL_NODE_TOOLS), and a harness's own tool (Bash,
|
|
653
660
|
* exec_command, apply_patch) is never one, so the DSL refuses a draft that names it. */
|
|
654
661
|
export const learnedWorkflowTools = (granted, plane, options = {}) => [...new Set(granted.filter((name) => (options.mcp === true && mcpNameOf(name) !== undefined) || (allows(CALL_TOOLS, name) && !isUnavailable(plane?.[name]))))];
|
|
655
662
|
/** The tools a learned draft may name (learnedWorkflowTools) that the gate allows: `permission` is what the gate holds a
|
package/dist/triggers.d.ts
CHANGED
|
@@ -50,8 +50,15 @@ export type TriggerUpstream = {
|
|
|
50
50
|
patched(was: Source, given: Source): Source;
|
|
51
51
|
/** The trigger `id` of `source`, turned on or off here: the same there. */
|
|
52
52
|
turned(source: Source, id: string, on: boolean): Promise<Json | undefined>;
|
|
53
|
-
/** The trigger `id` of `source`, deleted here: removed there. */
|
|
53
|
+
/** The trigger `id` of `source`, deleted here: removed there, with what it keeps here for it (a sealed config). */
|
|
54
54
|
removed(source: Source, id: string): Promise<Json | undefined>;
|
|
55
|
+
/** The trigger `id` of `source`, still here: removed there, then `here` (its delete here) in the same step, so no other
|
|
56
|
+
* trigger's removal there reads it as still holding what they share; what it keeps here for it is left (`forgotten`
|
|
57
|
+
* drops that once the trigger is gone). Undefined when it is gone there and `here` is done; what could not be done
|
|
58
|
+
* there, said, with `here` not run. A refusal of `here`'s is thrown. */
|
|
59
|
+
removedThere(source: Source, id: string, here: () => Promise<void>): Promise<Json | undefined>;
|
|
60
|
+
/** What it keeps here for the trigger `id` of `source` (a sealed config), dropped once the trigger is gone here. */
|
|
61
|
+
forgotten(source: Source, id: string): Promise<void>;
|
|
55
62
|
};
|
|
56
63
|
/** `max_cost_usd`: each run's cap; absent, the agent's default as it stands when the firing starts (one of the two is
|
|
57
64
|
* required: server.ts targetIssues and start). */
|
|
@@ -176,6 +183,11 @@ export declare class Triggers {
|
|
|
176
183
|
/** Each trigger's firings, driven one after another in the order asked: a firing's overlap check reads what the one
|
|
177
184
|
* before it settled to. */
|
|
178
185
|
private readonly turns;
|
|
186
|
+
/** Each trigger's removals and the edits that name a target (the one way it moves to another agent), one after another
|
|
187
|
+
* on this server: a move never lands between a template update's delete of its Composio instance and its conditional
|
|
188
|
+
* delete of the row (remove), so a moved trigger never stands on an instance that delete took. Across servers the
|
|
189
|
+
* store's conditional write holds the row. Removed from the map once idle. */
|
|
190
|
+
private readonly edits;
|
|
179
191
|
/** Whether a firing waits for its trigger's room (max_active_runs): the timer then reads the store every WAIT_POLL_MS. */
|
|
180
192
|
private waiting;
|
|
181
193
|
/** The triggers whose day-kept keys are at their cap, said once until they are under it again. */
|
|
@@ -295,7 +307,7 @@ export declare class Triggers {
|
|
|
295
307
|
} | null;
|
|
296
308
|
}[];
|
|
297
309
|
}>;
|
|
298
|
-
create(body: Json): Promise<{
|
|
310
|
+
create(body: Json, own?: TriggerOwn): Promise<{
|
|
299
311
|
secret?: string;
|
|
300
312
|
id: string;
|
|
301
313
|
name: string;
|
|
@@ -378,6 +390,9 @@ export declare class Triggers {
|
|
|
378
390
|
}[]>;
|
|
379
391
|
/** Refused (409 agent_archived) when agent `agentId` is archived: a trigger made on, turned on or aimed at it. */
|
|
380
392
|
private needAgentOn;
|
|
393
|
+
/** Refused (409 agent_not_runnable, agents.ts agentDeleting) when agent `agentId` is being deleted: another system's
|
|
394
|
+
* agent with an archive time, which only its delete writes (agent-delete.ts). */
|
|
395
|
+
private needNotDeleting;
|
|
381
396
|
/** The store's refusal of a trigger left on for an archived agent (an archive that committed past needAgentOn) as the
|
|
382
397
|
* same 409; undefined for any other error. */
|
|
383
398
|
private archivedRefusal;
|
|
@@ -402,7 +417,7 @@ export declare class Triggers {
|
|
|
402
417
|
/** PATCH: any of name, enabled, source, target, catchup_window_s and max_active_runs. Enabled again, or its source changed, a trigger goes on from now: a
|
|
403
418
|
* paused range is skipped, never caught up. Only the fields named change, applied to the trigger as it stands once
|
|
404
419
|
* the target's check is done: an edit made meanwhile keeps its own. */
|
|
405
|
-
update(id: string, body: Json): Promise<{
|
|
420
|
+
update(id: string, body: Json, own?: TriggerOwn): Promise<{
|
|
406
421
|
id: string;
|
|
407
422
|
name: string;
|
|
408
423
|
enabled: boolean;
|
|
@@ -440,11 +455,37 @@ export declare class Triggers {
|
|
|
440
455
|
} | null | undefined;
|
|
441
456
|
hook_url?: string | undefined;
|
|
442
457
|
}>;
|
|
458
|
+
private updating;
|
|
443
459
|
/** One try of `update`: undefined when its source write was refused because the trigger changed since it was read and
|
|
444
460
|
* `retry` (try again); refused on the last try, precondition_failed. */
|
|
445
461
|
private updateOnce;
|
|
446
|
-
/** The trigger deleted, and what its sender keeps of it removed after (said, when it could not be: the delete holds).
|
|
447
|
-
|
|
462
|
+
/** The trigger deleted, and what its sender keeps of it removed after (said, when it could not be: the delete holds).
|
|
463
|
+
* On its agent's condition (`onAgent`: a template update's removal), what its sender keeps goes first: one its sender
|
|
464
|
+
* did not remove is said, and the trigger is kept here as it was (its row, its package mark, its sealed config and
|
|
465
|
+
* whether it is on), for the next update to remove; once it is gone there, the trigger goes here while it is still that
|
|
466
|
+
* agent's, then what its sender kept here for it. */
|
|
467
|
+
remove(id: string, own?: Pick<TriggerOwn, "onAgent">): Promise<Json | undefined>;
|
|
468
|
+
private removing;
|
|
469
|
+
/** `value` as a create keeps a source (its adapter's defaults filled in: a feed's every_s), or undefined when a create
|
|
470
|
+
* would refuse it. */
|
|
471
|
+
sourceAsKept(value: unknown): Source | undefined;
|
|
472
|
+
/** A deleted agent's trigger (agent-delete.ts), its first half: what its sender keeps of it removed there, the trigger
|
|
473
|
+
* kept here, so a failure, or a stop before the second half (removeHere), leaves the row that names what is left to
|
|
474
|
+
* remove for the next delete to find. Throws `unavailable` with what could not be done there. */
|
|
475
|
+
removeThere(id: string): Promise<void>;
|
|
476
|
+
/** The second half's first part, once removeThere is done: the trigger's adapter settings removed, its row kept. */
|
|
477
|
+
removeSettings(id: string): Promise<void>;
|
|
478
|
+
/** The second half, once removeThere is done: the trigger deleted here, its adapter settings and then its row. */
|
|
479
|
+
removeHere(id: string): Promise<void>;
|
|
480
|
+
/** A trigger's adapter settings (a webhook's secret, a poll's cursor) removed; nothing else of it. */
|
|
481
|
+
private dropSettings;
|
|
482
|
+
/** The trigger's settings and row removed. Without `onAgent`, its settings first, then its row: the settings have no
|
|
483
|
+
* link to the row, so a failure or a stop between the two leaves the row, which the next remove finds, never settings
|
|
484
|
+
* with no trigger left to name them. With `onAgent` (a template update's removal), the row first, on its agent's
|
|
485
|
+
* condition compared in the delete, then its settings: a trigger moved to another agent meanwhile keeps both. A stop
|
|
486
|
+
* between the two there leaves settings no row names (keyed by an id never used again), never a moved trigger
|
|
487
|
+
* without its own. */
|
|
488
|
+
private dropHere;
|
|
448
489
|
/** Run now: one firing per Idempotency-Key, driven before the answer. `created` false: the key's firing, as it stands. */
|
|
449
490
|
fire(id: string, idempotencyKey: string): Promise<{
|
|
450
491
|
created: boolean;
|
|
@@ -454,6 +495,12 @@ export declare class Triggers {
|
|
|
454
495
|
* then each failure's trigger.failed queued that is not yet, each due firing whose time has come driven, each waiting
|
|
455
496
|
* firing whose trigger has room again driven (one read for all of them), and the timer armed again. */
|
|
456
497
|
private tick;
|
|
498
|
+
/** `work` on trigger `id` once every edit or removal of it asked before has settled (edits). Neither update nor remove
|
|
499
|
+
* calls the other, so a turn never waits on itself. Only a target edit takes a turn: any other edit runs beside one, as
|
|
500
|
+
* concurrent edits each keep their change (trigger-engine.test.mjs, two edits at once, one a target whose check is
|
|
501
|
+
* slow: the source edit lands while the target's check waits). One racing a removal writes its row while the row is
|
|
502
|
+
* there, or finds it gone (not_found): the store's update changes no row a delete took. */
|
|
503
|
+
private one;
|
|
457
504
|
/** `key`'s firing driven after every firing of its trigger asked before it. */
|
|
458
505
|
private inTurn;
|
|
459
506
|
/** Each of `triggers` turned off, with why its source no longer reads, and said. */
|
|
@@ -571,6 +618,14 @@ export declare class Triggers {
|
|
|
571
618
|
* source says of it), then a line saying what fired it and when, in the trigger's zone. */
|
|
572
619
|
private inputOf;
|
|
573
620
|
}
|
|
621
|
+
/** What a template apply alone gives a trigger write, never an API body: `templateId`, the package mark it makes the
|
|
622
|
+
* trigger with or sets on one it keeps in place (TriggerRow.templateId); `onAgent`, the agent it read the trigger on, so
|
|
623
|
+
* the write (an update, a removal) is made only while the trigger is still that agent's, compared in the store's
|
|
624
|
+
* statement: one moved to another agent meanwhile is not_found, and nothing is written. */
|
|
625
|
+
export interface TriggerOwn {
|
|
626
|
+
readonly templateId?: string;
|
|
627
|
+
readonly onAgent?: string;
|
|
628
|
+
}
|
|
574
629
|
declare function firingView(firing: FiringRow): {
|
|
575
630
|
attempts?: number | undefined;
|
|
576
631
|
retry_at?: string | undefined;
|
package/dist/triggers.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
// now. A failed firing queues a trigger.failed webhook message.
|
|
24
24
|
import { createHash, randomBytes } from "node:crypto";
|
|
25
25
|
import { TRIGGER_LABELS } from "./timeline/index.js";
|
|
26
|
+
import { agentDeleting } from "./agents.js";
|
|
26
27
|
import { ApiError, invalid } from "./errors.js";
|
|
27
28
|
import { EFFORTS } from "./model.js";
|
|
28
29
|
import { AgentArchived, StoreConstraint, TriggerFull } from "./store/index.js";
|
|
@@ -217,6 +218,11 @@ export class Triggers {
|
|
|
217
218
|
/** Each trigger's firings, driven one after another in the order asked: a firing's overlap check reads what the one
|
|
218
219
|
* before it settled to. */
|
|
219
220
|
turns = new Map();
|
|
221
|
+
/** Each trigger's removals and the edits that name a target (the one way it moves to another agent), one after another
|
|
222
|
+
* on this server: a move never lands between a template update's delete of its Composio instance and its conditional
|
|
223
|
+
* delete of the row (remove), so a moved trigger never stands on an instance that delete took. Across servers the
|
|
224
|
+
* store's conditional write holds the row. Removed from the map once idle. */
|
|
225
|
+
edits = new Map();
|
|
220
226
|
/** Whether a firing waits for its trigger's room (max_active_runs): the timer then reads the store every WAIT_POLL_MS. */
|
|
221
227
|
waiting = false;
|
|
222
228
|
/** The triggers whose day-kept keys are at their cap, said once until they are under it again. */
|
|
@@ -270,7 +276,7 @@ export class Triggers {
|
|
|
270
276
|
await this.need(id);
|
|
271
277
|
return { firings: (await this.store.triggers.firings(id)).map(firingView) };
|
|
272
278
|
}
|
|
273
|
-
async create(body) {
|
|
279
|
+
async create(body, own = {}) {
|
|
274
280
|
const now = this.clock.now();
|
|
275
281
|
const { issues, source, target, settings } = readBody(this.adapters, body, now);
|
|
276
282
|
// Checked as its runs are given it: the input, then the line saying what fired it (a name the trigger may yet take).
|
|
@@ -281,6 +287,9 @@ export class Triggers {
|
|
|
281
287
|
const agentId = await this.agentOf(target);
|
|
282
288
|
const id = `trg_${randomBytes(12).toString("hex")}`;
|
|
283
289
|
const enabled = body.enabled !== false;
|
|
290
|
+
// None for an agent being deleted, off too, told before anything is minted or registered upstream (the store's own
|
|
291
|
+
// refusal is the backstop): the delete has listed its triggers already.
|
|
292
|
+
await this.needNotDeleting(agentId);
|
|
284
293
|
if (enabled)
|
|
285
294
|
await this.needAvailable(source.kind);
|
|
286
295
|
// Never made on for an archived agent: told before anything is minted (the store's own refusal is the backstop).
|
|
@@ -294,7 +303,7 @@ export class Triggers {
|
|
|
294
303
|
try {
|
|
295
304
|
// Its secrets are kept before the trigger is: one whose secret cannot be kept makes none.
|
|
296
305
|
const minted = await this.mint(kept, id);
|
|
297
|
-
const row = await this.store.triggers.create({ id, agentId, name, enabled, source: kept, target, nextAt: enabled ? nextAfter(this.adapter(kept), kept, now) : null, catchupWindowS: settings.catchup_window_s ?? CATCHUP_WINDOW_S, ...(typeof settings.max_active_runs === "number" ? { maxActiveRuns: settings.max_active_runs } : {}) }, this.scopesOf(kept));
|
|
306
|
+
const row = await this.store.triggers.create({ id, agentId, name, enabled, source: kept, target, nextAt: enabled ? nextAfter(this.adapter(kept), kept, now) : null, catchupWindowS: settings.catchup_window_s ?? CATCHUP_WINDOW_S, ...(typeof settings.max_active_runs === "number" ? { maxActiveRuns: settings.max_active_runs } : {}), ...(own.templateId !== undefined ? { templateId: own.templateId } : {}) }, this.scopesOf(kept));
|
|
298
307
|
return { row, minted };
|
|
299
308
|
}
|
|
300
309
|
catch (error) {
|
|
@@ -391,6 +400,13 @@ export class Triggers {
|
|
|
391
400
|
if (agent?.archivedAt != null)
|
|
392
401
|
throw new ApiError("agent_archived", archivedDetail(agent.name));
|
|
393
402
|
}
|
|
403
|
+
/** Refused (409 agent_not_runnable, agents.ts agentDeleting) when agent `agentId` is being deleted: another system's
|
|
404
|
+
* agent with an archive time, which only its delete writes (agent-delete.ts). */
|
|
405
|
+
async needNotDeleting(agentId) {
|
|
406
|
+
const agent = await this.store.agents.get(agentId);
|
|
407
|
+
if (agent?.archivedAt != null && agent.externalRef != null)
|
|
408
|
+
throw agentDeleting(agentId);
|
|
409
|
+
}
|
|
394
410
|
/** The store's refusal of a trigger left on for an archived agent (an archive that committed past needAgentOn) as the
|
|
395
411
|
* same 409; undefined for any other error. */
|
|
396
412
|
async archivedRefusal(error) {
|
|
@@ -441,20 +457,23 @@ export class Triggers {
|
|
|
441
457
|
/** PATCH: any of name, enabled, source, target, catchup_window_s and max_active_runs. Enabled again, or its source changed, a trigger goes on from now: a
|
|
442
458
|
* paused range is skipped, never caught up. Only the fields named change, applied to the trigger as it stands once
|
|
443
459
|
* the target's check is done: an edit made meanwhile keeps its own. */
|
|
444
|
-
async update(id, body) {
|
|
460
|
+
async update(id, body, own = {}) {
|
|
461
|
+
return isObject(body) && body.target !== undefined ? this.one(id, () => this.updating(id, body, own)) : this.updating(id, body, own);
|
|
462
|
+
}
|
|
463
|
+
async updating(id, body, own) {
|
|
445
464
|
// A source is written only on the row it was checked against (its updatedAt): another write meanwhile (the
|
|
446
465
|
// after-start seal's, a poll's next time) checks it again on the row as it is then, so a source read before a seal
|
|
447
466
|
// never writes the clear value back over it.
|
|
448
467
|
for (let tries = 1;; tries++) {
|
|
449
|
-
const done = await this.updateOnce(id, body, tries < SOURCE_EDIT_TRIES);
|
|
468
|
+
const done = await this.updateOnce(id, body, tries < SOURCE_EDIT_TRIES, own);
|
|
450
469
|
if (done)
|
|
451
470
|
return done;
|
|
452
471
|
}
|
|
453
472
|
}
|
|
454
473
|
/** One try of `update`: undefined when its source write was refused because the trigger changed since it was read and
|
|
455
474
|
* `retry` (try again); refused on the last try, precondition_failed. */
|
|
456
|
-
async updateOnce(id, body, retry) {
|
|
457
|
-
const was = await this.need(id);
|
|
475
|
+
async updateOnce(id, body, retry, own) {
|
|
476
|
+
const was = await this.need(id, own.onAgent);
|
|
458
477
|
const issues = unknownFields(body, WRITABLE);
|
|
459
478
|
let source = body.source === undefined ? undefined : sourceOf(this.adapters, body.source, this.clock.now(), issues);
|
|
460
479
|
const target = body.target === undefined ? undefined : targetOf(body.target, issues);
|
|
@@ -472,7 +491,7 @@ export class Triggers {
|
|
|
472
491
|
issues.push(...(await this.deps.targetIssues(this.given(typeof body.name === "string" ? body.name.trim() : was.name, source ?? was.source, target, this.clock.now()))));
|
|
473
492
|
if (issues.length || (body.source !== undefined && !source) || (body.target !== undefined && !target))
|
|
474
493
|
throw invalid(issues);
|
|
475
|
-
const trigger = await this.need(id);
|
|
494
|
+
const trigger = await this.need(id, own.onAgent);
|
|
476
495
|
if (source && source.kind !== trigger.source.kind)
|
|
477
496
|
throw invalid([{ field: "source.kind", reason: "not_allowed", message: "A trigger's source kind is fixed: make a new trigger for another." }]);
|
|
478
497
|
// What its sender keeps of it stays as it was made (Composio's instance): only what reads it here changes.
|
|
@@ -498,6 +517,9 @@ export class Triggers {
|
|
|
498
517
|
// A trigger belongs to its target's agent: aimed at another agent (or another agent's run), it moves to that agent,
|
|
499
518
|
// whose one name per trigger and list of triggers it joins.
|
|
500
519
|
const agentId = target ? await this.agentOf(target) : trigger.agentId;
|
|
520
|
+
// Moved to an agent being deleted, off too, or turned on for one: never (the store's own refusal is the backstop).
|
|
521
|
+
if (agentId !== trigger.agentId || (enabled && !trigger.enabled))
|
|
522
|
+
await this.needNotDeleting(agentId);
|
|
501
523
|
// Turned on, or aimed elsewhere while on: never for an archived agent (the store's own refusal is the backstop).
|
|
502
524
|
if (enabled && (!trigger.enabled || target))
|
|
503
525
|
await this.needAgentOn(agentId);
|
|
@@ -505,16 +527,20 @@ export class Triggers {
|
|
|
505
527
|
const polls = enabled && adapter.poll !== undefined && (!trigger.enabled || source !== undefined);
|
|
506
528
|
if (polls && !trigger.enabled)
|
|
507
529
|
this.restarts.set(id, (this.restarts.get(id) ?? 0) + 1);
|
|
530
|
+
// Moved to another agent, it is no package's (its mark cleared in the same write): a template update of the agent it
|
|
531
|
+
// left, or of the one it was moved back to, never takes it for one of its own. Kept in place by an apply, it is marked.
|
|
508
532
|
const patch = {
|
|
509
|
-
...(agentId !== trigger.agentId ? { agentId } : {}),
|
|
533
|
+
...(agentId !== trigger.agentId ? { agentId, templateId: null } : own.templateId !== undefined ? { templateId: own.templateId } : {}),
|
|
510
534
|
...(typeof body.name === "string" ? { name: body.name.trim() } : {}), ...(source ? { source } : {}), ...(target ? { target } : {}),
|
|
511
535
|
...(settings.catchup_window_s !== undefined ? { catchupWindowS: settings.catchup_window_s } : {}),
|
|
512
536
|
...(settings.max_active_runs !== undefined ? { maxActiveRuns: settings.max_active_runs } : {}), ...again, enabled, nextAt: next,
|
|
513
537
|
};
|
|
514
|
-
const
|
|
538
|
+
const conditions = { ...(source ? { ifUpdatedAt: trigger.updatedAt, ifSource: trigger.source } : {}), ...(own.onAgent !== undefined ? { ifAgent: own.onAgent } : {}) };
|
|
539
|
+
const row = await this.store.triggers.update(id, patch, enabled ? this.scopesOf(scopeSource) : [], Object.keys(conditions).length ? conditions : undefined).catch(async (error) => {
|
|
515
540
|
throw (await this.scopeTaken(error, scopeSource, trigger.id)) ?? (await this.archivedRefusal(error)) ?? nameTaken(error, patch.name ?? trigger.name);
|
|
516
541
|
});
|
|
517
|
-
|
|
542
|
+
const still = !row && source ? await this.store.triggers.get(id) : undefined;
|
|
543
|
+
if (still && (own.onAgent === undefined || still.agentId === own.onAgent)) {
|
|
518
544
|
if (retry)
|
|
519
545
|
return undefined;
|
|
520
546
|
throw new ApiError("precondition_failed", "the trigger kept changing while this edit was checked: read it again, then send the edit again");
|
|
@@ -535,14 +561,78 @@ export class Triggers {
|
|
|
535
561
|
const said = upstream && enabled !== trigger.enabled ? await upstream.turned(row.source, id, enabled) : undefined;
|
|
536
562
|
return { ...(await this.view(asTrigger(row))), ...said };
|
|
537
563
|
}
|
|
538
|
-
/** The trigger deleted, and what its sender keeps of it removed after (said, when it could not be: the delete holds).
|
|
539
|
-
|
|
564
|
+
/** The trigger deleted, and what its sender keeps of it removed after (said, when it could not be: the delete holds).
|
|
565
|
+
* On its agent's condition (`onAgent`: a template update's removal), what its sender keeps goes first: one its sender
|
|
566
|
+
* did not remove is said, and the trigger is kept here as it was (its row, its package mark, its sealed config and
|
|
567
|
+
* whether it is on), for the next update to remove; once it is gone there, the trigger goes here while it is still that
|
|
568
|
+
* agent's, then what its sender kept here for it. */
|
|
569
|
+
async remove(id, own = {}) {
|
|
570
|
+
return this.one(id, () => this.removing(id, own));
|
|
571
|
+
}
|
|
572
|
+
async removing(id, own) {
|
|
573
|
+
const trigger = await this.need(id, own.onAgent);
|
|
574
|
+
const upstream = this.deps.upstream?.(trigger.source.kind);
|
|
575
|
+
if (own.onAgent === undefined) {
|
|
576
|
+
await this.dropHere(trigger);
|
|
577
|
+
return upstream?.removed(trigger.source, id);
|
|
578
|
+
}
|
|
579
|
+
const here = () => this.dropHere(trigger, own.onAgent);
|
|
580
|
+
if (!upstream)
|
|
581
|
+
return void (await here());
|
|
582
|
+
const said = await upstream.removedThere(trigger.source, id, here);
|
|
583
|
+
if (said !== undefined)
|
|
584
|
+
return said;
|
|
585
|
+
await upstream.forgotten(trigger.source, id);
|
|
586
|
+
return undefined;
|
|
587
|
+
}
|
|
588
|
+
/** `value` as a create keeps a source (its adapter's defaults filled in: a feed's every_s), or undefined when a create
|
|
589
|
+
* would refuse it. */
|
|
590
|
+
sourceAsKept(value) {
|
|
591
|
+
const issues = [];
|
|
592
|
+
const source = sourceOf(this.adapters, value, this.clock.now(), issues);
|
|
593
|
+
return issues.length ? undefined : source;
|
|
594
|
+
}
|
|
595
|
+
/** A deleted agent's trigger (agent-delete.ts), its first half: what its sender keeps of it removed there, the trigger
|
|
596
|
+
* kept here, so a failure, or a stop before the second half (removeHere), leaves the row that names what is left to
|
|
597
|
+
* remove for the next delete to find. Throws `unavailable` with what could not be done there. */
|
|
598
|
+
async removeThere(id) {
|
|
540
599
|
const trigger = await this.need(id);
|
|
541
|
-
await this.
|
|
600
|
+
const said = await this.deps.upstream?.(trigger.source.kind)?.removed(trigger.source, id);
|
|
601
|
+
if (said === undefined)
|
|
602
|
+
return;
|
|
603
|
+
const notes = isObject(said) ? Object.values(said).flatMap((one) => (isObject(one) && typeof one.note === "string" ? [one.note] : [])) : [];
|
|
604
|
+
throw new ApiError("unavailable", `What ${trigger.source.kind} keeps of the trigger ${id} is not removed there yet${notes.length ? ` (${notes.join(" ")})` : ""}.`, { retry_after_ms: 5_000 });
|
|
605
|
+
}
|
|
606
|
+
/** The second half's first part, once removeThere is done: the trigger's adapter settings removed, its row kept. */
|
|
607
|
+
async removeSettings(id) {
|
|
608
|
+
await this.dropSettings(await this.need(id));
|
|
609
|
+
}
|
|
610
|
+
/** The second half, once removeThere is done: the trigger deleted here, its adapter settings and then its row. */
|
|
611
|
+
async removeHere(id) {
|
|
612
|
+
await this.dropHere(await this.need(id));
|
|
613
|
+
}
|
|
614
|
+
/** A trigger's adapter settings (a webhook's secret, a poll's cursor) removed; nothing else of it. */
|
|
615
|
+
async dropSettings(trigger) {
|
|
542
616
|
if (this.adapter(trigger.source)?.settings?.scope === "trigger")
|
|
543
|
-
await this.deps.settings(trigger.source.kind)?.remove(id);
|
|
617
|
+
await this.deps.settings(trigger.source.kind)?.remove(trigger.id);
|
|
618
|
+
}
|
|
619
|
+
/** The trigger's settings and row removed. Without `onAgent`, its settings first, then its row: the settings have no
|
|
620
|
+
* link to the row, so a failure or a stop between the two leaves the row, which the next remove finds, never settings
|
|
621
|
+
* with no trigger left to name them. With `onAgent` (a template update's removal), the row first, on its agent's
|
|
622
|
+
* condition compared in the delete, then its settings: a trigger moved to another agent meanwhile keeps both. A stop
|
|
623
|
+
* between the two there leaves settings no row names (keyed by an id never used again), never a moved trigger
|
|
624
|
+
* without its own. */
|
|
625
|
+
async dropHere(trigger, onAgent) {
|
|
626
|
+
if (onAgent === undefined) {
|
|
627
|
+
await this.dropSettings(trigger);
|
|
628
|
+
await this.store.triggers.remove(trigger.id);
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
if (!(await this.store.triggers.remove(trigger.id, { ifAgent: onAgent })))
|
|
632
|
+
throw new ApiError("not_found", `no trigger ${trigger.id} on the agent ${onAgent}`);
|
|
633
|
+
await this.dropSettings(trigger);
|
|
634
|
+
}
|
|
544
635
|
await this.arm();
|
|
545
|
-
return this.deps.upstream?.(trigger.source.kind)?.removed(trigger.source, id);
|
|
546
636
|
}
|
|
547
637
|
/** Run now: one firing per Idempotency-Key, driven before the answer. `created` false: the key's firing, as it stands. */
|
|
548
638
|
async fire(id, idempotencyKey) {
|
|
@@ -593,6 +683,21 @@ export class Triggers {
|
|
|
593
683
|
}
|
|
594
684
|
await this.arm();
|
|
595
685
|
}
|
|
686
|
+
/** `work` on trigger `id` once every edit or removal of it asked before has settled (edits). Neither update nor remove
|
|
687
|
+
* calls the other, so a turn never waits on itself. Only a target edit takes a turn: any other edit runs beside one, as
|
|
688
|
+
* concurrent edits each keep their change (trigger-engine.test.mjs, two edits at once, one a target whose check is
|
|
689
|
+
* slow: the source edit lands while the target's check waits). One racing a removal writes its row while the row is
|
|
690
|
+
* there, or finds it gone (not_found): the store's update changes no row a delete took. */
|
|
691
|
+
one(id, work) {
|
|
692
|
+
const done = (this.edits.get(id) ?? Promise.resolve()).then(work);
|
|
693
|
+
const turn = done.then(() => undefined, () => undefined);
|
|
694
|
+
this.edits.set(id, turn);
|
|
695
|
+
void turn.then(() => {
|
|
696
|
+
if (this.edits.get(id) === turn)
|
|
697
|
+
this.edits.delete(id);
|
|
698
|
+
});
|
|
699
|
+
return done;
|
|
700
|
+
}
|
|
596
701
|
/** `key`'s firing driven after every firing of its trigger asked before it. */
|
|
597
702
|
inTurn(triggerId, key) {
|
|
598
703
|
const known = this.driving.get(key);
|
|
@@ -1112,10 +1217,10 @@ export class Triggers {
|
|
|
1112
1217
|
async all() {
|
|
1113
1218
|
return (await this.store.triggers.all()).map(asTrigger);
|
|
1114
1219
|
}
|
|
1115
|
-
async need(id) {
|
|
1220
|
+
async need(id, onAgent) {
|
|
1116
1221
|
const row = await this.store.triggers.get(id);
|
|
1117
|
-
if (!row)
|
|
1118
|
-
throw new ApiError("not_found", `no trigger ${id}`);
|
|
1222
|
+
if (!row || (onAgent !== undefined && row.agentId !== onAgent))
|
|
1223
|
+
throw new ApiError("not_found", onAgent !== undefined && row ? `no trigger ${id} on the agent ${onAgent}` : `no trigger ${id}`);
|
|
1119
1224
|
return asTrigger(row);
|
|
1120
1225
|
}
|
|
1121
1226
|
/** The agent a trigger belongs to: its start_run target's, or the run its message_run target names. */
|
package/dist/validate.js
CHANGED
|
@@ -122,7 +122,7 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
122
122
|
if (d.workflow !== undefined)
|
|
123
123
|
out.push(issue(`${at}.learning`, "not_allowed", "A workflow revision does not learn: only an agentic run reflects on its work.", `Remove ${at}.learning.`));
|
|
124
124
|
else {
|
|
125
|
-
// true learns
|
|
125
|
+
// true learns (corrections and workflows); an object is on, with the loop's numbers.
|
|
126
126
|
const wrong = learningSettingIssue(d.learning, `${at}.learning`);
|
|
127
127
|
if (wrong)
|
|
128
128
|
out.push(issue(`${at}.learning`, "wrong_type", wrong));
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -33,12 +33,14 @@ export declare function shownUrl(url: string): string;
|
|
|
33
33
|
/** What the webhook takes beside its store: `retryMs`, the waits between tries; `privateTargets`, whether it may send to a
|
|
34
34
|
* private network or this machine (the operator's AGENTRUN_WEBHOOK_PRIVATE_TARGETS, never the API's); `lookup`, every
|
|
35
35
|
* address a name resolves to (the system resolver by default); `storeRetryMs`, the wait before a try the store failed is
|
|
36
|
-
* tried again (STORE_RETRY_MS by default)
|
|
36
|
+
* tried again (STORE_RETRY_MS by default); `timeoutMs`, the bound on one try (TIMEOUT_MS by default), under the claim a
|
|
37
|
+
* try holds its message by (CLAIM_MS), so no try outlives its claim. */
|
|
37
38
|
export type WebhooksOptions = {
|
|
38
39
|
retryMs?: readonly number[];
|
|
39
40
|
privateTargets?: boolean;
|
|
40
41
|
lookup?: (host: string) => Promise<string[]>;
|
|
41
42
|
storeRetryMs?: number;
|
|
43
|
+
timeoutMs?: number;
|
|
42
44
|
};
|
|
43
45
|
/** What `emit` did with a notice: `queued`, in the store (or already there, or counted as sent); `unsaved`, the store
|
|
44
46
|
* refused the write, so the caller tells it again; `off`, no webhook set, or one a 410 turned off, so nothing is to be
|
|
@@ -123,6 +125,7 @@ export declare class Webhooks {
|
|
|
123
125
|
private readonly privateTargets;
|
|
124
126
|
private readonly lookup;
|
|
125
127
|
private readonly storeRetryMs;
|
|
128
|
+
private readonly timeoutMs;
|
|
126
129
|
/** `key` is the server's seal key; `say` takes a log line's fields. */
|
|
127
130
|
constructor(store: WebhooksStore, key: Buffer, say: (fields: Record<string, string | number>) => void, options?: WebhooksOptions);
|
|
128
131
|
/** Reads the webhook, its secret and its ledger once, and goes on with the messages an earlier server left queued, each
|