@parcha/agentrun-serve 0.1.0-beta.42 → 0.1.0-beta.44
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 +126 -0
- package/README.md +221 -31
- package/dist/cli.js +42 -8
- package/dist/composio-preset.d.ts +4 -3
- package/dist/composio-preset.js +12 -4
- package/dist/composio-triggers.d.ts +20 -2
- package/dist/composio-triggers.js +183 -17
- package/dist/computer-lost.d.ts +11 -0
- package/dist/computer-lost.js +19 -0
- package/dist/computer-record.d.ts +10 -2
- package/dist/computer-record.js +50 -18
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +2 -2
- package/dist/console/assets/index-BUktRvS-.css +1 -0
- package/dist/console/assets/index-nB9kTfIN.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +0 -4
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/harness-table.d.ts +51 -3
- package/dist/harness-table.js +101 -13
- package/dist/harness.d.ts +18 -1
- package/dist/harness.js +21 -9
- package/dist/host.d.ts +12 -10
- package/dist/host.js +18 -16
- package/dist/import-sources.js +25 -5
- package/dist/import-worker.d.ts +3 -0
- package/dist/import-worker.js +7 -5
- package/dist/import.d.ts +22 -1
- package/dist/import.js +141 -28
- package/dist/learn/audit.d.ts +123 -0
- package/dist/learn/audit.js +159 -0
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +1 -1
- package/dist/learn/compile.d.ts +50 -74
- package/dist/learn/compile.js +90 -124
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +44 -0
- package/dist/learn/folder.d.ts +9 -0
- package/dist/learn/folder.js +13 -2
- package/dist/learn/promote.d.ts +92 -200
- package/dist/learn/promote.js +65 -187
- package/dist/learn/replay-calls.d.ts +5 -0
- package/dist/learn/replay-calls.js +12 -1
- package/dist/learn/secrets.d.ts +8 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +19 -5
- package/dist/learn/workflow-nodes.d.ts +23 -3
- package/dist/learn/workflow-nodes.js +30 -12
- package/dist/learned-nodes.d.ts +9 -34
- package/dist/learned-nodes.js +11 -23
- package/dist/learned-workflow.d.ts +6 -8
- package/dist/learned-workflow.js +18 -57
- package/dist/learning-batch.d.ts +13 -5
- package/dist/learning-batch.js +34 -8
- package/dist/learning-cost.d.ts +111 -4
- package/dist/learning-cost.js +120 -3
- package/dist/learning-evals.d.ts +2 -0
- package/dist/learning-evals.js +4 -3
- package/dist/learning-routes.d.ts +8 -0
- package/dist/learning-routes.js +18 -1
- package/dist/learning-setting.d.ts +16 -1
- package/dist/learning-setting.js +34 -2
- package/dist/learning.d.ts +1 -1
- package/dist/listen-first.d.ts +30 -0
- package/dist/listen-first.js +115 -0
- package/dist/llms.txt +2 -1
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/model.d.ts +8 -4
- package/dist/model.js +16 -8
- package/dist/openapi.js +203 -87
- package/dist/owner.d.ts +8 -0
- package/dist/owner.js +11 -0
- package/dist/paid-calls.d.ts +6 -0
- package/dist/paid-calls.js +11 -1
- package/dist/place.d.ts +8 -3
- package/dist/place.js +13 -9
- package/dist/provider.js +15 -1
- package/dist/run-launch.d.ts +6 -3
- package/dist/run-launch.js +2 -0
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-model-key.d.ts +64 -0
- package/dist/run-model-key.js +147 -0
- package/dist/runner/adapter-loop.d.ts +10 -0
- package/dist/runner/adapter-loop.js +26 -4
- package/dist/runner/adapter-run-spec.d.ts +6 -3
- package/dist/runner/adapter-run-spec.js +83 -25
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +13 -4
- package/dist/runner/audit.d.ts +68 -0
- package/dist/runner/audit.js +349 -0
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +6 -3
- package/dist/runner/claim-secrets.d.ts +49 -0
- package/dist/runner/claim-secrets.js +110 -1
- package/dist/runner/cli-run-spec.d.ts +2 -1
- package/dist/runner/cli-run-spec.js +44 -15
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/feedback-round.d.ts +3 -2
- package/dist/runner/feedback-round.js +8 -7
- package/dist/runner/harness-loops.js +31 -23
- package/dist/runner/journal-kinds.d.ts +5 -7
- package/dist/runner/journal-kinds.js +0 -7
- package/dist/runner/learning-dispatch.d.ts +0 -16
- package/dist/runner/learning-dispatch.js +4 -47
- package/dist/runner/learning-end.d.ts +55 -13
- package/dist/runner/learning-end.js +128 -44
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +1 -4
- package/dist/runner/learning-loop.d.ts +2 -38
- package/dist/runner/learning-loop.js +8 -116
- package/dist/runner/loop-contract.d.ts +6 -0
- package/dist/runner/loop-contract.js +4 -0
- package/dist/runner/loop.js +6 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +25 -8
- package/dist/runner/memory-claim.d.ts +9 -6
- package/dist/runner/memory-claim.js +12 -9
- package/dist/runner/promotion.d.ts +55 -54
- package/dist/runner/promotion.js +232 -585
- package/dist/runner/reflect-hook.d.ts +14 -0
- package/dist/runner/reflect-hook.js +28 -3
- package/dist/runner/runner.js +57 -4
- package/dist/runner/store-secrets.js +9 -5
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +17 -12
- package/dist/runner/workflow-spec.js +10 -2
- package/dist/runs-over-store.d.ts +5 -4
- package/dist/runs-over-store.js +13 -3
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +64 -50
- package/dist/server.js +516 -134
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/seal.d.ts +20 -2
- package/dist/store/seal.js +24 -8
- package/dist/store/sqlite/run-launch.d.ts +4 -1
- package/dist/store/sqlite/run-launch.js +12 -0
- package/dist/store/sqlite/store.d.ts +3 -2
- package/dist/store/sqlite/store.js +119 -16
- package/dist/store/store.d.ts +41 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +57 -7
- package/dist/store-reads/learning.js +194 -28
- package/dist/store-reads/loop.d.ts +4 -39
- package/dist/store-reads/loop.js +10 -79
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +12 -1
- package/dist/telemetry.d.ts +59 -0
- package/dist/telemetry.js +153 -0
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +11 -11
- package/dist/tools.js +18 -5
- package/dist/trigger-adapter.d.ts +3 -0
- package/dist/trigger-adapters.d.ts +4 -0
- package/dist/trigger-adapters.js +13 -0
- package/dist/trigger-composio.d.ts +58 -1
- package/dist/trigger-composio.js +160 -6
- package/dist/triggers.d.ts +4 -0
- package/dist/triggers.js +22 -3
- package/dist/validate.d.ts +11 -7
- package/dist/validate.js +8 -7
- package/dist/workspace/computer-for-claim.d.ts +15 -5
- package/dist/workspace/computer-for-claim.js +228 -32
- package/dist/workspace/resolve-computer.d.ts +8 -2
- package/dist/workspace/resolve-computer.js +1 -1
- package/dist/workspace/run-tools.d.ts +1 -1
- package/dist/workspace/run-tools.js +14 -3
- package/package.json +10 -9
- package/dist/console/assets/index-C3gNPz58.css +0 -1
- package/dist/console/assets/index-DYJ_wj27.js +0 -711
- package/dist/learn/general.d.ts +0 -69
- package/dist/learn/general.js +0 -75
- package/dist/learn/refit.d.ts +0 -48
- package/dist/learn/refit.js +0 -264
- package/dist/runner/step-guard.d.ts +0 -62
- package/dist/runner/step-guard.js +0 -93
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { runReadState } from "./runs.js";
|
|
2
|
+
import { isShadowRun, shadowRunId } from "../learn/audit.js";
|
|
2
3
|
const RUN_STATES = ["running", "completed", "failed", "stopped", "escalated"];
|
|
3
4
|
const emptyCounts = () => ({ total: 0, running: 0, completed: 0, failed: 0, stopped: 0, escalated: 0 });
|
|
4
5
|
/** Every agent, by name then id (the old order), with its archive and name. */
|
|
@@ -18,7 +19,12 @@ export async function stats(store) {
|
|
|
18
19
|
const running = [];
|
|
19
20
|
// Each revision's kind, read once: an agentic run a person stopped reads running (runReadState).
|
|
20
21
|
const kinds = new Map();
|
|
22
|
+
// An audit's shadow run is learning spend on the run it audits, never a run of its own (A8): its cost, once known, is
|
|
23
|
+
// in the dollars with that run, shown or hidden with it; it is in no count, and never running work.
|
|
24
|
+
const shadows = new Map(runs.filter((run) => isShadowRun(run.id)).map((run) => [run.id, run]));
|
|
21
25
|
for (const run of runs) {
|
|
26
|
+
if (isShadowRun(run.id))
|
|
27
|
+
continue;
|
|
22
28
|
if (!kinds.has(run.revisionId))
|
|
23
29
|
kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind === "workflow" ? "workflow" : "agentic");
|
|
24
30
|
const state = runReadState(run, kinds.get(run.revisionId));
|
|
@@ -31,7 +37,10 @@ export async function stats(store) {
|
|
|
31
37
|
}
|
|
32
38
|
let g = shown.get(run.agentId);
|
|
33
39
|
if (g === undefined)
|
|
34
|
-
shown.set(run.agentId, (g = { counts: emptyCounts(), costUsd: 0, known: 0 }));
|
|
40
|
+
shown.set(run.agentId, (g = { counts: emptyCounts(), costUsd: 0, known: 0, shadowUsd: 0 }));
|
|
41
|
+
const shadow = shadows.get(shadowRunId(run.id));
|
|
42
|
+
if (shadow && runReadState(shadow, "agentic") !== "running" && shadow.costUsd !== null)
|
|
43
|
+
g.shadowUsd += shadow.costUsd;
|
|
35
44
|
g.counts.total += 1;
|
|
36
45
|
g.counts[state] += 1;
|
|
37
46
|
if (state !== "running" && run.costUsd !== null) {
|
|
@@ -54,8 +63,9 @@ export async function stats(store) {
|
|
|
54
63
|
for (const key of ["total", ...RUN_STATES])
|
|
55
64
|
stats.runs[key] += counts[key];
|
|
56
65
|
const known = g?.known ?? 0;
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
// A shadow's known $ is spent whether or not the run it audits has a known cost: never a null for its dollars.
|
|
67
|
+
if (known > 0 || (g?.shadowUsd ?? 0) > 0)
|
|
68
|
+
stats.cost.usd = (stats.cost.usd ?? 0) + (g?.costUsd ?? 0) + (g?.shadowUsd ?? 0);
|
|
59
69
|
stats.cost.known += known;
|
|
60
70
|
stats.cost.unknown += counts.total - known;
|
|
61
71
|
}
|
package/dist/store-view.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type TimelineEvent } from "./timeline/index.js";
|
|
2
2
|
import { type ItemStatus } from "./learning.js";
|
|
3
|
-
import { type RunMoment, type SignInReader } from "./run-view.js";
|
|
3
|
+
import { type RunMoment, type SignInReader, type Status } from "./run-view.js";
|
|
4
|
+
import { type RunReadState } from "./store-reads/runs.js";
|
|
4
5
|
import { type Store } from "./store/store.js";
|
|
5
6
|
import type { RecordingView } from "./run-recordings.js";
|
|
6
7
|
/** What the store-backed view needs beside the store: where its console lives, every secret it never shows (read now, so
|
|
@@ -25,6 +26,9 @@ export interface ViewDeps {
|
|
|
25
26
|
* so a list, a poll or a status read opens no file. */
|
|
26
27
|
readonly recordings?: (agentId: string, runId: string, endedAt: number | null) => Promise<RecordingView[]>;
|
|
27
28
|
}
|
|
29
|
+
/** A settled run's v2 status from its row alone (STATUS_OF), the status its view reads (statusOf returns the outcome
|
|
30
|
+
* first); undefined for a run still going, whose status only its journal says. */
|
|
31
|
+
export declare const settledStatusOf: (state: RunReadState) => Status | undefined;
|
|
28
32
|
/** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's, and
|
|
29
33
|
* never an earlier turn's: a final answer row before the person's last message belongs to the turn that message
|
|
30
34
|
* followed, so a follow-up whose own stop said nothing (no text block: a thinking-only stop) has no answer, null, not
|
package/dist/store-view.js
CHANGED
|
@@ -13,6 +13,7 @@ import { isObject } from "./validate.js";
|
|
|
13
13
|
import { currentLearning, holdsForOk, learningView, LEARNING_LABEL, secretsShown, shortOf } from "./learning.js";
|
|
14
14
|
import { said } from "./learning-words.js";
|
|
15
15
|
import { CONTENT_FILTER_WORDS, contentFiltered, MODERATED } from "./content-filter.js";
|
|
16
|
+
import { COMPUTER_UNAVAILABLE_CODE, lostEndMessage } from "./computer-lost.js";
|
|
16
17
|
import { launchOf } from "./handed-values.js";
|
|
17
18
|
import { learningStartOf, seedFailed } from "./run-launch.js";
|
|
18
19
|
import { momentOf, pendingOf, stoppedTurn, approvalOf, asksOf, answersOf, activePauseOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costWordsOfView, freeOf, usersOf, withAsks, withApprovalRows, } from "./run-view.js";
|
|
@@ -35,6 +36,9 @@ import { FINAL_STATES, stoppedByPerson } from "./store/store.js";
|
|
|
35
36
|
* review; a stopped run is a cancellation), as runs.ts's STATUS_OF mapped them. A running run reads its status from the
|
|
36
37
|
* journal, and so does an agentic run a person stopped, which reads running (runReadState). */
|
|
37
38
|
const STATUS_OF = { completed: "completed", failed: "failed", escalated: "completed", stopped: "cancelled" };
|
|
39
|
+
/** A settled run's v2 status from its row alone (STATUS_OF), the status its view reads (statusOf returns the outcome
|
|
40
|
+
* first); undefined for a run still going, whose status only its journal says. */
|
|
41
|
+
export const settledStatusOf = (state) => (state === "running" ? undefined : STATUS_OF[state]);
|
|
38
42
|
/** A run that has reached a last state (its view is its ended shape). */
|
|
39
43
|
const TERMINAL = new Set(["completed", "failed", "cancelled"]);
|
|
40
44
|
const iso = (ms) => new Date(ms).toISOString();
|
|
@@ -81,13 +85,17 @@ export const answerOf = (timeline) => {
|
|
|
81
85
|
/** A failed run's error from its row (its own words are the summary; the store keeps no code or detail apart). A run
|
|
82
86
|
* its cap ended once its cost passed it (the kernel's overCapEnd) is code spend_cap_reached, its message the words after
|
|
83
87
|
* the code, as main served it; a provider's content-filter stop is `moderated`, in words a person can act on
|
|
84
|
-
* (content-filter.ts);
|
|
88
|
+
* (content-filter.ts); a run whose sandbox was lost more times than its claim starts new ones (computer-lost.ts lostEnd)
|
|
89
|
+
* is computer_unavailable, its message the words after the code; every other failure is run_failed. */
|
|
85
90
|
const errorOfRow = (summary) => {
|
|
86
91
|
// A run that reached its limit of requests on free models (the kernel cap's freeCeilingEnd) ends as its cap ends one: code
|
|
87
92
|
// spend_cap_reached, its message the words after the code.
|
|
88
93
|
const over = overCapMessage(summary) ?? freeCeilingMessage(summary);
|
|
89
94
|
if (over !== undefined)
|
|
90
95
|
return { code: SPEND_CAP_REACHED, message: over, retryable: false };
|
|
96
|
+
const lost = lostEndMessage(summary);
|
|
97
|
+
if (lost !== undefined)
|
|
98
|
+
return { code: COMPUTER_UNAVAILABLE_CODE, message: lost, retryable: false };
|
|
91
99
|
if (summary !== null && contentFiltered(summary))
|
|
92
100
|
return { code: MODERATED, message: CONTENT_FILTER_WORDS, retryable: false };
|
|
93
101
|
return { code: "run_failed", message: summary ?? "The run failed.", retryable: false };
|
|
@@ -452,7 +460,10 @@ export async function viewOverStore(store, runId, deps) {
|
|
|
452
460
|
error,
|
|
453
461
|
review,
|
|
454
462
|
pending,
|
|
463
|
+
// Its own spend: an audit's shadow run of it is learning (GET /runs/{id}'s cost.learning_usd), never its cost.usd.
|
|
455
464
|
cost: costOfView(run),
|
|
465
|
+
// The run an audit's shadow run audits (launch.audit, runner/audit.ts); null for any other run.
|
|
466
|
+
audit_of: launch?.audit?.of ?? null,
|
|
456
467
|
// Whether it ran unattended (its revision's approvals, as it started): never, an ask allowed at its gate; ask, the default.
|
|
457
468
|
approvals: run.approvalsMode,
|
|
458
469
|
archived_at: row.archivedAt ?? null,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Where events go: PostHog's capture route, behind this project's own name. */
|
|
2
|
+
export declare const TELEMETRY_URL = "https://telemetry.agentrun.ai/i/v0/e/";
|
|
3
|
+
/** The project's write-only key, public by design. Empty: this build sends nothing and prints no notice. */
|
|
4
|
+
export declare const TELEMETRY_KEY = "";
|
|
5
|
+
/** The file in the data directory that keeps the id, when the notice was printed and how many runs ended. */
|
|
6
|
+
export declare const TELEMETRY_FILE = ".telemetry.json";
|
|
7
|
+
/** How often a running server says it still runs. */
|
|
8
|
+
export declare const HEARTBEAT_MS: number;
|
|
9
|
+
export declare const TELEMETRY_NOTICE = "AgentRun sends anonymous usage counts (a random id, the version, the platform, how many runs as a range): never prompts, files, keys or names. Nothing was sent at this start. Turn it off with AGENTRUN_TELEMETRY=0 or DO_NOT_TRACK=1. Every field: https://github.com/Parcha-ai/agentrun/blob/main/docs/telemetry.md";
|
|
10
|
+
export type TelemetryEventName = "server_started" | "heartbeat" | "first_run_completed";
|
|
11
|
+
/** One event, as sent. `runs` is a range, never a count. */
|
|
12
|
+
export interface TelemetryEvent {
|
|
13
|
+
event: TelemetryEventName;
|
|
14
|
+
distinct_id: string;
|
|
15
|
+
timestamp: string;
|
|
16
|
+
properties: {
|
|
17
|
+
version: string;
|
|
18
|
+
os: string;
|
|
19
|
+
arch: string;
|
|
20
|
+
node: number;
|
|
21
|
+
runs: RunsRange;
|
|
22
|
+
$process_person_profile: false;
|
|
23
|
+
$geoip_disable: true;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export type RunsRange = "0" | "1-10" | "11-100" | "101+";
|
|
27
|
+
/** Why nothing is sent, or "on" / "debug" (events printed to stderr, none sent). */
|
|
28
|
+
export type TelemetryMode = "on" | "debug" | "off_setting" | "off_do_not_track" | "off_ci" | "off_faux" | "off_no_key";
|
|
29
|
+
/** What this start does, from its environment: the operator's own setting first, then DO_NOT_TRACK, CI and --faux. */
|
|
30
|
+
export declare function telemetryMode(env: NodeJS.ProcessEnv, o?: {
|
|
31
|
+
faux?: boolean;
|
|
32
|
+
key?: string;
|
|
33
|
+
}): TelemetryMode;
|
|
34
|
+
export declare const runsRange: (runs: number) => RunsRange;
|
|
35
|
+
export interface Telemetry {
|
|
36
|
+
mode: TelemetryMode;
|
|
37
|
+
/** The line to print once, at the start that first could send; undefined at every other. */
|
|
38
|
+
notice?: string;
|
|
39
|
+
/** A run reached its end here. `status` is the runner's (`ended` is a completed run). */
|
|
40
|
+
runEnded(status: string): void;
|
|
41
|
+
/** Stops the heartbeat and waits for the count's last write. Sends nothing. */
|
|
42
|
+
close(): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
export interface TelemetryOptions {
|
|
45
|
+
data: string;
|
|
46
|
+
/** The server's version (default: this package's). */
|
|
47
|
+
version?: string;
|
|
48
|
+
env?: NodeJS.ProcessEnv;
|
|
49
|
+
faux?: boolean;
|
|
50
|
+
/** For tests: the key, the route, the sender, the clock, the heartbeat's period and where debug lines go. */
|
|
51
|
+
key?: string;
|
|
52
|
+
url?: string;
|
|
53
|
+
fetch?: typeof fetch;
|
|
54
|
+
now?: () => Date;
|
|
55
|
+
heartbeatMs?: number;
|
|
56
|
+
say?: (line: string) => void;
|
|
57
|
+
}
|
|
58
|
+
/** Starts the counts for a server on `data`. Never throws: a data directory it cannot write turns it off. */
|
|
59
|
+
export declare function startTelemetry(o: TelemetryOptions): Telemetry;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Anonymous usage counts (docs/telemetry.md): that a server started, that it is still running a day later, and that its
|
|
2
|
+
// first run completed. Each event holds a random id made for this data directory, the server's version, the platform,
|
|
3
|
+
// and how many runs ended here as a range. It never holds a prompt, a workflow, a key, a name, a path or an address.
|
|
4
|
+
//
|
|
5
|
+
// Off with AGENTRUN_TELEMETRY=0 or DO_NOT_TRACK=1, in CI, and under --faux. The start that first could send prints one
|
|
6
|
+
// notice and sends nothing at its start, so a person reads how to turn it off before anything leaves the machine.
|
|
7
|
+
// AGENTRUN_TELEMETRY=debug prints every event and sends none; it never stands in for that notice.
|
|
8
|
+
// Sending never delays a start, a run or a stop, and a send that fails is dropped without a word. A run's end is counted
|
|
9
|
+
// in memory and written behind it, one write at a time, so no request or run waits on the disk.
|
|
10
|
+
import { randomUUID } from "node:crypto";
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
import { rename, unlink, writeFile } from "node:fs/promises";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { tempOf, writeDurableSync } from "./server-fs.js";
|
|
15
|
+
/** Where events go: PostHog's capture route, behind this project's own name. */
|
|
16
|
+
export const TELEMETRY_URL = "https://telemetry.agentrun.ai/i/v0/e/";
|
|
17
|
+
/** The project's write-only key, public by design. Empty: this build sends nothing and prints no notice. */
|
|
18
|
+
export const TELEMETRY_KEY = "";
|
|
19
|
+
/** The file in the data directory that keeps the id, when the notice was printed and how many runs ended. */
|
|
20
|
+
export const TELEMETRY_FILE = ".telemetry.json";
|
|
21
|
+
/** How often a running server says it still runs. */
|
|
22
|
+
export const HEARTBEAT_MS = 24 * 60 * 60 * 1000;
|
|
23
|
+
/** How long one send may take before it is dropped. */
|
|
24
|
+
const SEND_TIMEOUT_MS = 3_000;
|
|
25
|
+
const ownVersion = () => JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
26
|
+
export const TELEMETRY_NOTICE = "AgentRun sends anonymous usage counts (a random id, the version, the platform, how many runs as a range): never prompts, files, keys or names. Nothing was sent at this start. Turn it off with AGENTRUN_TELEMETRY=0 or DO_NOT_TRACK=1. Every field: https://github.com/Parcha-ai/agentrun/blob/main/docs/telemetry.md";
|
|
27
|
+
const OFF = new Set(["0", "false", "off", "no"]);
|
|
28
|
+
/** What this start does, from its environment: the operator's own setting first, then DO_NOT_TRACK, CI and --faux. */
|
|
29
|
+
export function telemetryMode(env, o = {}) {
|
|
30
|
+
const setting = (env.AGENTRUN_TELEMETRY ?? "").trim().toLowerCase();
|
|
31
|
+
if (OFF.has(setting))
|
|
32
|
+
return "off_setting";
|
|
33
|
+
const dnt = (env.DO_NOT_TRACK ?? "").trim().toLowerCase();
|
|
34
|
+
if (dnt !== "" && !OFF.has(dnt))
|
|
35
|
+
return "off_do_not_track";
|
|
36
|
+
if (env.CI)
|
|
37
|
+
return "off_ci";
|
|
38
|
+
if (o.faux)
|
|
39
|
+
return "off_faux";
|
|
40
|
+
if (setting === "debug")
|
|
41
|
+
return "debug";
|
|
42
|
+
return (o.key ?? TELEMETRY_KEY) === "" ? "off_no_key" : "on";
|
|
43
|
+
}
|
|
44
|
+
export const runsRange = (runs) => (runs <= 0 ? "0" : runs <= 10 ? "1-10" : runs <= 100 ? "11-100" : "101+");
|
|
45
|
+
/** The kept state, or a new one when the file is missing or not what this wrote. */
|
|
46
|
+
function readState(file) {
|
|
47
|
+
try {
|
|
48
|
+
const kept = JSON.parse(readFileSync(file, "utf8"));
|
|
49
|
+
if (kept && typeof kept.id === "string" && /^[0-9a-f-]{36}$/.test(kept.id)) {
|
|
50
|
+
return {
|
|
51
|
+
id: kept.id,
|
|
52
|
+
runs: typeof kept.runs === "number" && Number.isInteger(kept.runs) && kept.runs >= 0 ? kept.runs : 0,
|
|
53
|
+
...(typeof kept.noticed_at === "string" ? { noticed_at: kept.noticed_at } : {}),
|
|
54
|
+
...(kept.first_run_sent === true ? { first_run_sent: true } : {}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Missing or unreadable: a new id, and the notice again.
|
|
60
|
+
}
|
|
61
|
+
return { id: randomUUID(), runs: 0 };
|
|
62
|
+
}
|
|
63
|
+
/** Starts the counts for a server on `data`. Never throws: a data directory it cannot write turns it off. */
|
|
64
|
+
export function startTelemetry(o) {
|
|
65
|
+
const env = o.env ?? process.env;
|
|
66
|
+
const key = o.key ?? TELEMETRY_KEY;
|
|
67
|
+
const mode = telemetryMode(env, { ...(o.faux ? { faux: true } : {}), key });
|
|
68
|
+
const idle = { mode, runEnded: () => { }, close: () => Promise.resolve() };
|
|
69
|
+
if (mode !== "on" && mode !== "debug")
|
|
70
|
+
return idle;
|
|
71
|
+
const file = join(o.data, TELEMETRY_FILE);
|
|
72
|
+
const now = o.now ?? (() => new Date());
|
|
73
|
+
const say = o.say ?? ((line) => void process.stderr.write(`${line}\n`));
|
|
74
|
+
const send = o.fetch ?? fetch;
|
|
75
|
+
const state = readState(file);
|
|
76
|
+
const version = o.version ?? ownVersion();
|
|
77
|
+
const text = () => `${JSON.stringify(state)}\n`;
|
|
78
|
+
// The start's one write, durable before anything is sent: the id, and the notice's time when this start prints it.
|
|
79
|
+
const keepNow = () => {
|
|
80
|
+
try {
|
|
81
|
+
writeDurableSync(file, text());
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
// Every later write (a run's end) goes behind the caller: one at a time, the latest state each time, so ends that come
|
|
89
|
+
// together make one write and none waits on the disk. A write that fails is dropped; the next end writes again.
|
|
90
|
+
// Each goes through a temporary file of its own: a server that takes this data directory while this one still stops
|
|
91
|
+
// never shares one with it. The two can still each write the file whole, last one kept, so a restart that overlaps a
|
|
92
|
+
// run's end may count a few runs short: the count is sent as a range, and nothing else is kept here.
|
|
93
|
+
const whole = async () => {
|
|
94
|
+
const temp = tempOf(file);
|
|
95
|
+
try {
|
|
96
|
+
await writeFile(temp, text(), { mode: 0o600 });
|
|
97
|
+
await rename(temp, file);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
await unlink(temp).catch(() => { });
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
let stale = false;
|
|
104
|
+
let writing;
|
|
105
|
+
const keepLater = () => {
|
|
106
|
+
stale = true;
|
|
107
|
+
writing ??= (async () => {
|
|
108
|
+
while (stale) {
|
|
109
|
+
stale = false;
|
|
110
|
+
await whole();
|
|
111
|
+
}
|
|
112
|
+
writing = undefined;
|
|
113
|
+
})();
|
|
114
|
+
};
|
|
115
|
+
// The start that first could send: the notice, kept before anything is sent. If it cannot be kept, the next start would
|
|
116
|
+
// print it again and still send nothing, so this one stays quiet too. Debug sends nothing and prints no notice, so it
|
|
117
|
+
// never marks the notice as read: a start that can send after it still prints the notice and holds its first event.
|
|
118
|
+
const first = mode === "on" && state.noticed_at === undefined;
|
|
119
|
+
if (first)
|
|
120
|
+
state.noticed_at = now().toISOString();
|
|
121
|
+
if (!keepNow())
|
|
122
|
+
return { ...idle, mode: "off_setting" };
|
|
123
|
+
const emit = (event) => {
|
|
124
|
+
const body = {
|
|
125
|
+
event,
|
|
126
|
+
distinct_id: state.id,
|
|
127
|
+
timestamp: now().toISOString(),
|
|
128
|
+
properties: { version, os: process.platform, arch: process.arch, node: Number(process.versions.node.split(".")[0]), runs: runsRange(state.runs), $process_person_profile: false, $geoip_disable: true },
|
|
129
|
+
};
|
|
130
|
+
if (mode === "debug")
|
|
131
|
+
return say(`agentrun-serve telemetry (debug, not sent): ${JSON.stringify(body)}`);
|
|
132
|
+
void send(o.url ?? TELEMETRY_URL, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ api_key: key, ...body }), signal: AbortSignal.timeout(SEND_TIMEOUT_MS) }).then(() => { }, () => { });
|
|
133
|
+
};
|
|
134
|
+
if (!first)
|
|
135
|
+
emit("server_started");
|
|
136
|
+
// A server that stays up is counted by its heartbeat, the first start's too: a day after the notice.
|
|
137
|
+
const beat = setInterval(() => emit("heartbeat"), o.heartbeatMs ?? HEARTBEAT_MS);
|
|
138
|
+
beat.unref();
|
|
139
|
+
return {
|
|
140
|
+
mode,
|
|
141
|
+
...(first ? { notice: TELEMETRY_NOTICE } : {}),
|
|
142
|
+
runEnded(status) {
|
|
143
|
+
state.runs += 1;
|
|
144
|
+
const completed = status === "ended" && !state.first_run_sent;
|
|
145
|
+
if (completed)
|
|
146
|
+
state.first_run_sent = true;
|
|
147
|
+
keepLater();
|
|
148
|
+
if (completed)
|
|
149
|
+
emit("first_run_completed");
|
|
150
|
+
},
|
|
151
|
+
close: () => (clearInterval(beat), writing ?? Promise.resolve()),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -69,7 +69,7 @@ declare class ToolKeysOverStore {
|
|
|
69
69
|
at: string;
|
|
70
70
|
} | null;
|
|
71
71
|
unlocks: string[];
|
|
72
|
-
harnesses: ("opencode" | "codex" | "
|
|
72
|
+
harnesses: ("opencode" | "codex" | "claude-agent" | "pi")[];
|
|
73
73
|
id: string;
|
|
74
74
|
kind: "model" | "tool";
|
|
75
75
|
label: string;
|
package/dist/tool-keys.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export declare function unlockedBy(candidates: readonly string[], tools: readonl
|
|
|
58
58
|
id: string;
|
|
59
59
|
}[]): {
|
|
60
60
|
unlocks: string[];
|
|
61
|
-
harnesses: ("opencode" | "codex" | "
|
|
61
|
+
harnesses: ("opencode" | "codex" | "claude-agent" | "pi")[];
|
|
62
62
|
};
|
|
63
63
|
/** What a row unlocks here: a `tool` row's, its tools and providers as capabilities bind them (unlockedBy); any other
|
|
64
64
|
* kind's (a model's), no tool, on those that run on it (its `harnesses`, when it names them) that this server runs
|
|
@@ -77,7 +77,7 @@ export declare function rowUnlocks(row: {
|
|
|
77
77
|
keys?: readonly string[];
|
|
78
78
|
}[]): {
|
|
79
79
|
unlocks: string[];
|
|
80
|
-
harnesses: ("opencode" | "codex" | "
|
|
80
|
+
harnesses: ("opencode" | "codex" | "claude-agent" | "pi")[];
|
|
81
81
|
};
|
|
82
82
|
/** Whether a key row's `unlock` unlocks the tool `name`: by its name, or `<source>:*` for every tool of a catalog source
|
|
83
83
|
* (`monid:*`: `monid:apollo/people/match`, `monid:apollo/*`). */
|
package/dist/tool-plane.d.ts
CHANGED
|
@@ -39,11 +39,11 @@ export declare const permissionsOf: (name: string) => readonly Permission[];
|
|
|
39
39
|
* give it: the one in force under the server's settings (`permission`), the owner's default (`default_permission`) and
|
|
40
40
|
* those it may be set to. An agent's read gives the same, the agent's own layer over it (agentTools). */
|
|
41
41
|
export declare const serverGate: (name: string, settings: ToolSettingsMap, effect?: ToolEffect) => {
|
|
42
|
-
default_permission: "
|
|
43
|
-
permissions: ("
|
|
42
|
+
default_permission: "ask" | "allow" | "deny";
|
|
43
|
+
permissions: ("ask" | "allow" | "deny")[];
|
|
44
44
|
fallback_allow_reads?: true | undefined;
|
|
45
45
|
allow_reads?: true | undefined;
|
|
46
|
-
permission: "
|
|
46
|
+
permission: "ask" | "allow" | "deny";
|
|
47
47
|
};
|
|
48
48
|
/** The run's own tools beyond the table, each its own settings key, allowed by default like a table tool: the learned
|
|
49
49
|
* workflow a run's pin names runs as `learned_workflow` (learned-workflow.ts LEARNED_WORKFLOW_TOOL), and the host's
|
|
@@ -285,17 +285,17 @@ export declare function shellUnavailable(name: string, shell: ShellPlace): Resol
|
|
|
285
285
|
* computer setting); a tool of bash's family that leaves out resolves unavailable, saying why (shellUnavailable). */
|
|
286
286
|
export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSettingsMap, agent: Tooling, order: readonly string[], shell?: ShellPlace, effectOf?: (name: string) => ToolEffect | undefined): ({
|
|
287
287
|
resolved: Resolution;
|
|
288
|
-
permission: "
|
|
288
|
+
permission: "ask" | "allow" | "deny";
|
|
289
289
|
permission_from: import("./refusal-words.js").SettingFrom;
|
|
290
|
-
default_permission: "
|
|
291
|
-
permissions: ("
|
|
290
|
+
default_permission: "ask" | "allow" | "deny";
|
|
291
|
+
permissions: ("ask" | "allow" | "deny")[];
|
|
292
292
|
blurb?: string | undefined;
|
|
293
293
|
name: string;
|
|
294
294
|
} | {
|
|
295
|
-
permission: "
|
|
295
|
+
permission: "ask" | "allow" | "deny";
|
|
296
296
|
permission_from: import("./refusal-words.js").SettingFrom;
|
|
297
|
-
default_permission: "
|
|
298
|
-
permissions: ("
|
|
297
|
+
default_permission: "ask" | "allow" | "deny";
|
|
298
|
+
permissions: ("ask" | "allow" | "deny")[];
|
|
299
299
|
blurb?: string | undefined;
|
|
300
300
|
name: string;
|
|
301
301
|
} | {
|
|
@@ -303,10 +303,10 @@ export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSetting
|
|
|
303
303
|
provider_from: string;
|
|
304
304
|
default_provider: string;
|
|
305
305
|
resolved: Resolution;
|
|
306
|
-
permission: "
|
|
306
|
+
permission: "ask" | "allow" | "deny";
|
|
307
307
|
permission_from: import("./refusal-words.js").SettingFrom;
|
|
308
|
-
default_permission: "
|
|
309
|
-
permissions: ("
|
|
308
|
+
default_permission: "ask" | "allow" | "deny";
|
|
309
|
+
permissions: ("ask" | "allow" | "deny")[];
|
|
310
310
|
blurb?: string | undefined;
|
|
311
311
|
name: string;
|
|
312
312
|
})[];
|
package/dist/tools.d.ts
CHANGED
|
@@ -323,7 +323,7 @@ export declare function toolingOf(revision: Revision): Promise<Tooling>;
|
|
|
323
323
|
/** The variables `entry` needs that `env` does not set, by name. */
|
|
324
324
|
export declare const missingEnv: (entry: ToolEntry, env: NodeJS.ProcessEnv) => string[];
|
|
325
325
|
/** Every tool as capabilities show it, the server's one tool catalog: available here, or the variables it is missing
|
|
326
|
-
* (names only), and the harnesses that run it (
|
|
326
|
+
* (names only), and the harnesses that run it (one on an adapter runs only the host tools, host-tools.ts). A tool
|
|
327
327
|
* a user picks a provider for (tool-plane.ts) gives the providers offered, the server's (`provider`, the default where it
|
|
328
328
|
* sets none), the default, and what it resolves to on each harness under the server's `settings`: available where any
|
|
329
329
|
* is not unavailable, and missing PARALLEL_API_KEY where Parallel is picked without it. An unavailable tool says why
|
|
@@ -337,14 +337,14 @@ export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettings
|
|
|
337
337
|
providers?: string[] | undefined;
|
|
338
338
|
provider?: string | undefined;
|
|
339
339
|
default_provider?: string | undefined;
|
|
340
|
-
resolves?: Record<"opencode" | "codex" | "
|
|
341
|
-
why?: Record<"opencode" | "codex" | "
|
|
342
|
-
default_permission: "
|
|
343
|
-
permissions: ("
|
|
340
|
+
resolves?: Record<"opencode" | "codex" | "claude-agent" | "pi", Resolution> | undefined;
|
|
341
|
+
why?: Record<"opencode" | "codex" | "claude-agent" | "pi", string> | undefined;
|
|
342
|
+
default_permission: "ask" | "allow" | "deny";
|
|
343
|
+
permissions: ("ask" | "allow" | "deny")[];
|
|
344
344
|
fallback_allow_reads?: true | undefined;
|
|
345
345
|
allow_reads?: true | undefined;
|
|
346
|
-
permission: "
|
|
347
|
-
harnesses:
|
|
346
|
+
permission: "ask" | "allow" | "deny";
|
|
347
|
+
harnesses: string[];
|
|
348
348
|
missing?: string[] | undefined;
|
|
349
349
|
reason?: string | undefined;
|
|
350
350
|
available: boolean;
|
|
@@ -356,11 +356,11 @@ export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettings
|
|
|
356
356
|
name: string;
|
|
357
357
|
summary: string;
|
|
358
358
|
} | {
|
|
359
|
-
default_permission: "
|
|
360
|
-
permissions: ("
|
|
359
|
+
default_permission: "ask" | "allow" | "deny";
|
|
360
|
+
permissions: ("ask" | "allow" | "deny")[];
|
|
361
361
|
fallback_allow_reads?: true | undefined;
|
|
362
362
|
allow_reads?: true | undefined;
|
|
363
|
-
permission: "
|
|
363
|
+
permission: "ask" | "allow" | "deny";
|
|
364
364
|
name: string;
|
|
365
365
|
summary: string;
|
|
366
366
|
blurb: string;
|
|
@@ -368,5 +368,5 @@ export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettings
|
|
|
368
368
|
calls: boolean;
|
|
369
369
|
meta: true;
|
|
370
370
|
available: boolean;
|
|
371
|
-
harnesses:
|
|
371
|
+
harnesses: string[];
|
|
372
372
|
})[];
|
package/dist/tools.js
CHANGED
|
@@ -19,7 +19,7 @@ import { registerTurnEnding } from "./timeline/index.js";
|
|
|
19
19
|
import { BACKGROUND_LOG_BYTES, BACKGROUND_MAX, BACKGROUND_PAGE_BYTES } from "./background.js";
|
|
20
20
|
import { isWorkspaceError, localWorkspace } from "./workspace/index.js";
|
|
21
21
|
import { fetchOptions, HTML_READ_CHARS, TEXT_CAP } from "./web-fetch-direct.js";
|
|
22
|
-
import {
|
|
22
|
+
import { harnessIds, onAdapter } from "./harness-table.js";
|
|
23
23
|
import { META_TOOLS } from "./meta-tool-names.js";
|
|
24
24
|
import { localFolderOf } from "./workspace/local.js";
|
|
25
25
|
import { LLM_TOOL } from "./llm.js";
|
|
@@ -28,6 +28,7 @@ import { FAUX_ENV, workflowNodes } from "./model.js";
|
|
|
28
28
|
import { bookedIn, booking } from "./paid-calls.js";
|
|
29
29
|
import { hostToolDefs } from "@parcha/agentrun-kernel/kernel";
|
|
30
30
|
import { browserPrice, browserSpend } from "./browser-cost.js";
|
|
31
|
+
import { sessionRecordings } from "./computer-record.js";
|
|
31
32
|
import { forModel } from "./result.js";
|
|
32
33
|
import { fetchFor, pagesOf, WEB_FETCH_TOOL, webFetchTool } from "./web-fetch.js";
|
|
33
34
|
import { searchFor, WEB_SEARCH_TOOL, webSearchTool } from "./web-search.js";
|
|
@@ -267,7 +268,8 @@ export const runSignInSaved = (store, sealKey, claim, kept) => async (row, chang
|
|
|
267
268
|
* (browser-computer.ts), each driven over its CDP URL by pi-browser's raw-CDP driver: the agent's computer, where it is
|
|
268
269
|
* a browser (the claim's, computer-for-claim.ts), else the one the run's plane names (tool-plane.ts: picked, else
|
|
269
270
|
* Browserbase where the server holds its keys, else Kernel), kept for the run's life; a plane that names none (a run kept
|
|
270
|
-
* from before the pick) is Browserbase. Its sessions' custody lives in the run's own store. No recording
|
|
271
|
+
* from before the pick) is Browserbase. Its sessions' custody lives in the run's own store. No vendor's recording:
|
|
272
|
+
* where the agent's computer says computer.record, each session's video is the live view's screencast. The owner
|
|
271
273
|
* watches it live, takes it over and hands it back, and the agent may ask them to (browser-live.ts, browser-person.ts).
|
|
272
274
|
* A session the run still holds is released when the run is let go. Where the plane says unavailable (its vendor's key
|
|
273
275
|
* gone since), each call is refused, saying why. Its session time is the run's spend, held under its cap before it runs
|
|
@@ -423,6 +425,9 @@ const browserTool = {
|
|
|
423
425
|
// (host.liveViewers); never a file in the run's folder, which is the agent's workspace.
|
|
424
426
|
const viewers = live.sessionHandovers(host.liveViewers, at?.host);
|
|
425
427
|
const onSession = (row, change) => viewers.changed(row, change);
|
|
428
|
+
// Where the agent's computer records (its claim's `record`, computer.record): each session's video, by its computer,
|
|
429
|
+
// from its launch (or its reopening after a restart) to its release, through the live view's one screencast of it.
|
|
430
|
+
const recordSession = sessionRecordings(view, computer?.record);
|
|
426
431
|
// Its session time is the run's spend, at its provider's price, and held under the run's cap (browser-cost.ts).
|
|
427
432
|
const providerName = parts.provider?.name ?? vendor;
|
|
428
433
|
const price = browserPrice(providerName, host.env);
|
|
@@ -451,6 +456,7 @@ const browserTool = {
|
|
|
451
456
|
// A session let go ends a wait on the person's answer that kept it open (personWait, below): the run parks.
|
|
452
457
|
if (change === "released")
|
|
453
458
|
hands.sessionEnded(row.session.tag);
|
|
459
|
+
await recordSession(row.session.tag, change === "released" ? null : row.session.resourceId);
|
|
454
460
|
// A session that opens, whatever let the last one go: the Screen tab's ended state goes (browser-wait-ended.ts).
|
|
455
461
|
if (change === "launched" && host.store && host.claim)
|
|
456
462
|
await clearWaitEnded(host.store.settings, host.claim.runId, host.claim.epoch).catch(() => undefined);
|
|
@@ -513,6 +519,8 @@ const browserTool = {
|
|
|
513
519
|
try {
|
|
514
520
|
const opened = await watched?.liveView?.({ id: row.resourceId, tag: row.tag });
|
|
515
521
|
await viewers.reopened(row.tag, opened?.fullscreen);
|
|
522
|
+
if (opened)
|
|
523
|
+
await recordSession(row.tag, row.resourceId);
|
|
516
524
|
}
|
|
517
525
|
catch {
|
|
518
526
|
// A browser that cannot be reached has no view to give: the owner reads none, as for any session without one.
|
|
@@ -706,7 +714,7 @@ export async function toolingOf(revision) {
|
|
|
706
714
|
/** The variables `entry` needs that `env` does not set, by name. */
|
|
707
715
|
export const missingEnv = (entry, env) => entry.needs.filter((name) => !env[name]);
|
|
708
716
|
/** Every tool as capabilities show it, the server's one tool catalog: available here, or the variables it is missing
|
|
709
|
-
* (names only), and the harnesses that run it (
|
|
717
|
+
* (names only), and the harnesses that run it (one on an adapter runs only the host tools, host-tools.ts). A tool
|
|
710
718
|
* a user picks a provider for (tool-plane.ts) gives the providers offered, the server's (`provider`, the default where it
|
|
711
719
|
* sets none), the default, and what it resolves to on each harness under the server's `settings`: available where any
|
|
712
720
|
* is not unavailable, and missing PARALLEL_API_KEY where Parallel is picked without it. An unavailable tool says why
|
|
@@ -719,6 +727,11 @@ export const missingEnv = (entry, env) => entry.needs.filter((name) => !env[name
|
|
|
719
727
|
export const toolsView = (env, settings = {}, noBox, refused = {}, runnerShell = new Set()) => {
|
|
720
728
|
const views = explainsView(env, settings);
|
|
721
729
|
const picked = withDefaults(settings);
|
|
730
|
+
// The harnesses by the table `env` runs on (a module's among them): a host tool runs on each; any other tool on those
|
|
731
|
+
// that run on the general spec with pi's tools (no adapter facts: pi, and a module's harness without them), as the save
|
|
732
|
+
// check takes them (runnable.ts onAdapter).
|
|
733
|
+
const everyHarness = harnessIds(env);
|
|
734
|
+
const generalSpec = everyHarness.filter((id) => !onAdapter(env, id));
|
|
722
735
|
const table = Object.entries(TOOLS).map(([name, entry]) => {
|
|
723
736
|
const view = PICKABLE.includes(name) ? views[name] : undefined;
|
|
724
737
|
const plane = view?.resolves;
|
|
@@ -732,11 +745,11 @@ export const toolsView = (env, settings = {}, noBox, refused = {}, runnerShell =
|
|
|
732
745
|
// Unavailable says why: a sandbox-only tool no box here can run, why none can (`noBox`); on a tool a user picks a
|
|
733
746
|
// provider for, the resolutions' own words (`web_search is turned off in settings`); else the variables it needs.
|
|
734
747
|
const reason = available ? undefined : refusal ?? boxless ?? (plane ? [...new Set(Object.values(plane).filter(isUnavailable).map(whyUnavailable))].join("; ") : `Needs ${keyNeeded(missing)}`);
|
|
735
|
-
return { name, summary: entry.summary, ...(blurbOf(name) ? { blurb: blurbOf(name) } : {}), nodes: entry.nodes, calls: entry.effect !== undefined, ...(entry.callOnly ? { call_only: true } : {}), ...(entry.sandboxOnly ? { sandbox_only: true } : {}), available, ...(reason ? { reason } : {}), ...(missing.length ? { missing } : {}), harnesses: isHostTool(name) ? [...
|
|
748
|
+
return { name, summary: entry.summary, ...(blurbOf(name) ? { blurb: blurbOf(name) } : {}), nodes: entry.nodes, calls: entry.effect !== undefined, ...(entry.callOnly ? { call_only: true } : {}), ...(entry.sandboxOnly ? { sandbox_only: true } : {}), available, ...(reason ? { reason } : {}), ...(missing.length ? { missing } : {}), harnesses: isHostTool(name) ? [...everyHarness] : [...generalSpec], ...serverGate(name, settings), ...(plane ? { providers: [...PROVIDERS[name]], provider: picked[name].provider, default_provider: PROVIDERS[name][0], resolves: plane, why: view.why } : {}) };
|
|
736
749
|
});
|
|
737
750
|
// The host tools over a run's own tools (META_TOOLS): not in the table, never granted or named by a node (`meta`), listed
|
|
738
751
|
// so the owner sees them and their setting (allow or deny; a deny is not offered at all).
|
|
739
|
-
const meta = [...META_TOOLS].map((name) => ({ name, summary: META_SUMMARY[name], blurb: blurbOf(name), nodes: false, calls: false, meta: true, available: true, harnesses: [...
|
|
752
|
+
const meta = [...META_TOOLS].map((name) => ({ name, summary: META_SUMMARY[name], blurb: blurbOf(name), nodes: false, calls: false, meta: true, available: true, harnesses: [...everyHarness], ...serverGate(name, settings) }));
|
|
740
753
|
return [...table, ...meta];
|
|
741
754
|
};
|
|
742
755
|
const META_SUMMARY = Object.freeze({
|
|
@@ -54,6 +54,9 @@ export type TriggerAdapter = {
|
|
|
54
54
|
parse(value: Json, now: number, bad: (field: string, reason: string, message: string) => void, issues: InputIssue[]): Source | undefined;
|
|
55
55
|
/** Whether a source the store keeps is whole, of its type. */
|
|
56
56
|
wellFormed(source: Json): boolean;
|
|
57
|
+
/** A kept source as every answer sends it, when that is not as kept: a field that holds a credential masked (a composio
|
|
58
|
+
* config's key), by the one rule, whether the source sealed it yet or not. Default: as kept. */
|
|
59
|
+
shown?(source: Source): Source;
|
|
57
60
|
/** The zone its times are read in, for its runs' provenance line. Default UTC. */
|
|
58
61
|
zone?(source: Source): string;
|
|
59
62
|
/** A clock source's times. */
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { TriggerAdapter } from "./trigger-adapter.js";
|
|
2
2
|
export declare const TRIGGER_ADAPTERS: readonly TriggerAdapter[];
|
|
3
|
+
/** A trigger's answer (an object whose top-level `source` is a trigger source) with that source as a read sends it now
|
|
4
|
+
* (its adapter's `shown`): for an answer kept before that rule, an Idempotency-Key's record of a trigger create. Only
|
|
5
|
+
* that one field of that one shape: any other value is as it is. */
|
|
6
|
+
export declare function shownTrigger(body: unknown, adapters?: readonly TriggerAdapter[]): unknown;
|
package/dist/trigger-adapters.js
CHANGED
|
@@ -5,3 +5,16 @@ import { webhook } from "./trigger-webhook.js";
|
|
|
5
5
|
import { email } from "./trigger-email.js";
|
|
6
6
|
import { feed } from "./trigger-feed.js";
|
|
7
7
|
export const TRIGGER_ADAPTERS = [schedule, webhook, github, composio, email, feed];
|
|
8
|
+
/** A trigger's answer (an object whose top-level `source` is a trigger source) with that source as a read sends it now
|
|
9
|
+
* (its adapter's `shown`): for an answer kept before that rule, an Idempotency-Key's record of a trigger create. Only
|
|
10
|
+
* that one field of that one shape: any other value is as it is. */
|
|
11
|
+
export function shownTrigger(body, adapters = TRIGGER_ADAPTERS) {
|
|
12
|
+
if (body === null || typeof body !== "object" || Array.isArray(body))
|
|
13
|
+
return body;
|
|
14
|
+
const source = body.source;
|
|
15
|
+
if (source === null || typeof source !== "object" || Array.isArray(source))
|
|
16
|
+
return body;
|
|
17
|
+
const kind = source.kind;
|
|
18
|
+
const adapter = typeof kind === "string" ? adapters.find((a) => a.id === kind) : undefined;
|
|
19
|
+
return adapter?.shown ? { ...body, source: adapter.shown(source) } : body;
|
|
20
|
+
}
|