@parcha/agentrun-serve 0.1.0-beta.39 → 0.1.0-beta.40
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 +37 -0
- package/README.md +51 -1
- package/dist/console/assets/index-B8Zn1Iqn.css +1 -0
- package/dist/console/assets/index-Jbxjcmdp.js +705 -0
- package/dist/console/index.html +2 -2
- package/dist/email/account.d.ts +0 -1
- package/dist/email/account.js +3 -3
- package/dist/email/answer.d.ts +5 -0
- package/dist/email/answer.js +35 -0
- package/dist/email/mail.js +19 -26
- package/dist/email/names.d.ts +30 -0
- package/dist/email/names.js +34 -0
- package/dist/email/routes.d.ts +1 -0
- package/dist/email/routes.js +1 -1
- package/dist/email/tools.d.ts +11 -4
- package/dist/email/tools.js +91 -46
- package/dist/eval-mailbox.d.ts +1 -1
- package/dist/eval-mailbox.js +3 -3
- package/dist/learn/compile.d.ts +3 -2
- package/dist/learn/compile.js +6 -5
- package/dist/learn/promote.d.ts +25 -14
- package/dist/learn/promote.js +32 -14
- package/dist/learning-cost.d.ts +17 -8
- package/dist/learning-cost.js +12 -4
- package/dist/local-models.d.ts +7 -1
- package/dist/local-models.js +11 -5
- package/dist/openapi.d.ts +1 -1
- package/dist/openapi.js +17 -15
- package/dist/port-models.d.ts +4 -1
- package/dist/port-models.js +1 -0
- package/dist/refusal-words.d.ts +3 -0
- package/dist/refusal-words.js +3 -0
- package/dist/run-launch.d.ts +2 -0
- package/dist/run-launch.js +2 -0
- package/dist/run-view.d.ts +3 -4
- package/dist/run-view.js +26 -24
- package/dist/runner/adapter-loop.d.ts +6 -2
- package/dist/runner/adapter-loop.js +45 -12
- package/dist/runner/adapter-run-spec.d.ts +1 -0
- package/dist/runner/adapter-run-spec.js +37 -1
- package/dist/runner/cli-run-spec.js +1 -0
- package/dist/runner/journal-kinds.d.ts +22 -0
- package/dist/runner/journal-kinds.js +39 -0
- package/dist/runner/model-route.d.ts +3 -1
- package/dist/runner/model-route.js +18 -3
- package/dist/runner/promotion.d.ts +8 -8
- package/dist/runner/promotion.js +135 -54
- package/dist/server.js +15 -8
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/postgres/connection.d.ts +11 -5
- package/dist/store/postgres/connection.js +44 -17
- package/dist/store/postgres/dialect.js +5 -0
- package/dist/store/postgres/store.d.ts +7 -3
- package/dist/store/postgres/store.js +1 -0
- package/dist/store/sqlite/connection.js +72 -8
- package/dist/store/sqlite/run-launch.d.ts +11 -0
- package/dist/store/sqlite/run-launch.js +8 -0
- package/dist/store/sqlite/store.js +37 -16
- package/dist/store/sqlite/worker.d.ts +2 -0
- package/dist/store/sqlite/worker.js +13 -10
- package/dist/store/store.d.ts +15 -0
- package/dist/store-reads/learning.d.ts +30 -13
- package/dist/store-reads/learning.js +125 -51
- package/dist/template-eval.js +1 -1
- package/dist/templates.d.ts +14 -1
- package/dist/templates.js +67 -17
- package/dist/tool-gate.d.ts +5 -3
- package/dist/tool-gate.js +5 -2
- package/dist/tools.d.ts +13 -0
- package/dist/tools.js +15 -10
- package/dist/trigger-adapter.d.ts +3 -32
- package/dist/trigger-email.js +30 -77
- package/dist/triggers.d.ts +26 -14
- package/dist/triggers.js +99 -76
- package/dist/workflow/decision-recovery.js +5 -2
- package/dist/workflow/decisions.d.ts +7 -0
- package/package.json +9 -9
- package/templates/README.md +2 -2
- package/dist/console/assets/index-BNhZs-jp.css +0 -1
- package/dist/console/assets/index-BQv5aOGB.js +0 -700
|
@@ -27,8 +27,22 @@ type KeptRow = {
|
|
|
27
27
|
};
|
|
28
28
|
/** What a kept row says of a run that looked back (learning-run.ts closeLearning's fields): none for one that did not. */
|
|
29
29
|
declare function answeredOf(row: KeptRow): Pick<Learning, "answered_at" | "job_cost_usd" | "look_back_usd">;
|
|
30
|
-
/**
|
|
31
|
-
|
|
30
|
+
/** The reads of a run's records a learning read makes: its launch, a round of its kept learning, a run's row (its
|
|
31
|
+
* learning run's). The store's own reads, one a run, or an agent's read at once (agentRecordsOf). */
|
|
32
|
+
export type RunRecords = {
|
|
33
|
+
/** `learningStart`: a run's learning start read from the agent's one narrow read (agentRecordsOf), when it was; absent, the run's launch is read. */
|
|
34
|
+
readonly runs: Pick<Store["runs"], "launch" | "get"> & {
|
|
35
|
+
readonly learningStart?: (runId: string) => Promise<RunLaunch["learning"]>;
|
|
36
|
+
};
|
|
37
|
+
readonly learning: Pick<Store["learning"], "proposal">;
|
|
38
|
+
};
|
|
39
|
+
/** Agent `agentId`'s runs' records read at once, whatever their number: its runs' launches (Store.runs.launches) and every
|
|
40
|
+
* round its runs' learning kept with the learning runs they name (Store.learning.kept), two reads beside `listed` (its
|
|
41
|
+
* runs, as runs.list read them). Each answers as the store's per-run read does: a run of `listed` with no launch row is
|
|
42
|
+
* StoreLaunchMissing, one that kept no learning has no round. A run not of `listed` is read from the store. */
|
|
43
|
+
export declare function agentRecordsOf(store: Store, agentId: string, listed: readonly RunRecord[]): Promise<RunRecords>;
|
|
44
|
+
/** Run `runId`'s learning end (its newest round's, or round `round`'s); null when the run kept no learning. Proposed while its learning run has not ended. `records`: where its rows are read (the store's per-run reads by default). */
|
|
45
|
+
export declare function runLearningEnd(store: Store, runId: string, round?: number, records?: RunRecords): Promise<RunLearningEnd | null>;
|
|
32
46
|
/** How the runs that tried to learn fared (GET /stats's `learning`): `runs` with a learning end, `merged`, `dropped` by
|
|
33
47
|
* reason, and `in_progress` (proposed, its learning run not ended). The shape today's counts give (learning-run.ts
|
|
34
48
|
* learningStats). */
|
|
@@ -41,8 +55,9 @@ export type LearningCounts = {
|
|
|
41
55
|
/** GET /stats's learning counts from the one store, over the runs `filter` picks as the analytics pick them (not archived,
|
|
42
56
|
* their own or their agent's; started in [from, to); of `agent`): an agentic run with a learning end counts, its end
|
|
43
57
|
* read as the run's view reads it (runLearningEnd). A workflow's run, and one with no learning, is not counted; nor is
|
|
44
|
-
* one whose reason this server does not give (an older server's). An imported run keeps no learning in the store.
|
|
45
|
-
|
|
58
|
+
* one whose reason this server does not give (an older server's). An imported run keeps no learning in the store. Each
|
|
59
|
+
* agent's runs' records are read at once (agentRecordsOf; `records`, already read for `filter.agent`), never a read a run. */
|
|
60
|
+
export declare function learningCountsOverStore(store: Store, filter: AnalyticsFilter, records?: RunRecords): Promise<LearningCounts>;
|
|
46
61
|
/** What learning spent outside any run (GET /usage's `learning` meter) in [from, to) (ms), one entry per run whose
|
|
47
62
|
* learning ended then, as the learning ledger's lines gave it: its agent, when its learning ended, and what its grade
|
|
48
63
|
* cost: 0 for a run never graded, null when the grade's spend is unknown (a grade that failed), never $0 then. One read
|
|
@@ -58,13 +73,15 @@ export declare function learningSpendOverStore(store: Store, window: {
|
|
|
58
73
|
/** An agent's learning counts as its learning view gives them (GET /agents/{id}/learning, learning-run.ts ofAgent's
|
|
59
74
|
* counts): how its runs that tried to learn fared, less `runs`, from the one store. Its notes' runs and its impact are
|
|
60
75
|
* agentLearningOverStore's. */
|
|
61
|
-
export declare function agentLearningCountsOverStore(store: Store, agentId: string): Promise<Omit<LearningCounts, "runs">>;
|
|
76
|
+
export declare function agentLearningCountsOverStore(store: Store, agentId: string, records?: RunRecords): Promise<Omit<LearningCounts, "runs">>;
|
|
62
77
|
/** Agent `agentId`'s learning view from the one store (GET /agents/{id}/learning, learning-run.ts ofAgent): its counts
|
|
63
78
|
* (agentLearningCountsOverStore), each note's runs given it and that read it (noteRuns over notesOf), and what learning
|
|
64
79
|
* changed (learningImpact), never a run's files. Each run's part is read from its launch (the notes it was given,
|
|
65
80
|
* learningStartOf), its journal once final (the notes its job read, notesReadOf) and its learning end (when its job
|
|
66
81
|
* answered and what it and looking back cost, its grade's cost). `seed_notes`, the notes a run started from, is its
|
|
67
|
-
* launch's seedNotes: every note in its seed, before the budget picked the given ones (main's seed_notes).
|
|
82
|
+
* launch's seedNotes: every note in its seed, before the budget picked the given ones (main's seed_notes). Its runs'
|
|
83
|
+
* launches and learning are read at once (agentRecordsOf), and a settled run's journal once a server (settledCache):
|
|
84
|
+
* a read a run only the first time it is seen. */
|
|
68
85
|
export declare function agentLearningOverStore(store: Store, agentId: string): Promise<{
|
|
69
86
|
counts: Omit<LearningCounts, "runs">;
|
|
70
87
|
impact: Impact;
|
|
@@ -99,28 +116,28 @@ export declare function servingReplayOf(records: readonly PromotionRecord[], run
|
|
|
99
116
|
* (roundsSpendOf's figures): its job is what it had cost when its first round answered, and everything after (each
|
|
100
117
|
* later round's follow-up turn and every round's look-back: feedback the run was given is learning, never the job) is
|
|
101
118
|
* its look-back here, `rowUsd` (the run's row cost) less that job (roundsLooked). */
|
|
102
|
-
export declare function learningSpendOf(store:
|
|
119
|
+
export declare function learningSpendOf(store: RunRecords, runId: string, rowUsd: number | null): Promise<{
|
|
103
120
|
looked: ReturnType<typeof answeredOf> | null;
|
|
104
121
|
grade: number | null;
|
|
105
122
|
}>;
|
|
106
123
|
/** Every round run `runId` kept (one a follow-up opened again is a round past its first), oldest first: none when it kept
|
|
107
124
|
* no learning. The store's proposal(runId) is the newest round alone; a read of what the run's learning did or spent
|
|
108
125
|
* reads them all. */
|
|
109
|
-
export declare function roundsOf(store: Pick<
|
|
126
|
+
export declare function roundsOf(store: Pick<RunRecords, "learning">, runId: string): Promise<LearningProposal[]>;
|
|
110
127
|
type RunRecord = NonNullable<Awaited<ReturnType<Store["runs"]["get"]>>>;
|
|
111
128
|
/** A run's own cost and what learning added for it (runCostOf): its row's cost, every round of its learning (a run a
|
|
112
129
|
* follow-up opened again, a review's or a person's, learned in rounds: every round's look-back and grade, roundsSpendOf,
|
|
113
130
|
* never the newest round's alone), else its one round's (learningSpendOf). `total_usd` is the run's all-in cost, the one
|
|
114
131
|
* the cost page shows and the money rule reads (pastRunsOverStore); null when any part is unknown. */
|
|
115
|
-
export declare function allInOf(store:
|
|
132
|
+
export declare function allInOf(store: RunRecords, run: RunRecord): Promise<ReturnType<typeof runCostOf>>;
|
|
116
133
|
/** One run of the cost series, as number `n` of it: its figures (allInOf) and its path (agentCostOverStore's loop body,
|
|
117
134
|
* and a learning batch's row once the run's learning has settled). */
|
|
118
|
-
export declare function costRunOf(store:
|
|
135
|
+
export declare function costRunOf(store: RunRecords, run: RunRecord, n: number): Promise<CostRun>;
|
|
119
136
|
/** The runs the money rule reads for agent `agentId` (runner/workflow-first.ts costLineOf), one set for the run's launch
|
|
120
137
|
* and the cost page: of its newest PAST_RUNS runs, each that ended (ended, stopped or failed), is neither imported nor
|
|
121
138
|
* archived nor a workflow revision's run, with its all-in cost (allInOf). `known`: all-in costs already read, by run id
|
|
122
|
-
* (the cost page's series), read again for no run. */
|
|
123
|
-
export declare function pastRunsOverStore(store: Store, agentId: string, known?: ReadonlyMap<string, number | null
|
|
139
|
+
* (the cost page's series), read again for no run; `records`, where any other's rows are read (the store's by default). */
|
|
140
|
+
export declare function pastRunsOverStore(store: Store, agentId: string, known?: ReadonlyMap<string, number | null>, records?: RunRecords): Promise<PastRun[]>;
|
|
124
141
|
/** The path run `runId` took and the learned workflow it ran, the one classifier its run record keeps (metrics.path,
|
|
125
142
|
* metrics.workflow, metrics.workflow_digest: workflow-first.ts pathMetrics, written at the run's end) and its cost per run
|
|
126
143
|
* reads (pathOfRow). A run its learned workflow served first (its WORKFLOW_FIRST entry, servedOf): `workflow` when it
|
|
@@ -164,7 +181,7 @@ export declare function roundsLooked(rounds: RoundsSpend, rowUsd: number | null)
|
|
|
164
181
|
job_cost_usd: number | null;
|
|
165
182
|
look_back_usd: number | null;
|
|
166
183
|
};
|
|
167
|
-
export declare function roundsSpendOf(store:
|
|
184
|
+
export declare function roundsSpendOf(store: RunRecords, runId: string): Promise<RoundsSpend | undefined>;
|
|
168
185
|
/** What a run's learning end tells its impact, as ofAgent's learningOf read a held run: how it ended and when, the notes
|
|
169
186
|
* it started from; when its job answered and its costs once it looked back (a look-back of 0 for an ended one that did
|
|
170
187
|
* not); its grade's cost once it ended (0 when nothing was graded). */
|
|
@@ -9,7 +9,7 @@ import { posix } from "node:path";
|
|
|
9
9
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
10
10
|
import { currentLearning, holdsForOk, LEARNING_REASONS } from "../learning.js";
|
|
11
11
|
import { runLearningBody } from "../learning-routes.js";
|
|
12
|
-
import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
|
|
12
|
+
import { learningStartOf, learningStartOfStored, readLaunchBody, seedFailed } from "../run-launch.js";
|
|
13
13
|
import { said, STOPPED } from "../learning-words.js";
|
|
14
14
|
import { learningImpact, noteRuns, notesRead } from "../learning-run.js";
|
|
15
15
|
import { costSummary, RUN_PATHS, runCostOf } from "../learning-cost.js";
|
|
@@ -19,7 +19,7 @@ import { PAST_RUNS, servedAnswerOf, servedAnswerStands, servedOf, workflowCostsO
|
|
|
19
19
|
import { reflects } from "../reflect-range.js";
|
|
20
20
|
import { notesOf } from "../usage.js";
|
|
21
21
|
import { runEntries, runReflect, runTimeline, withoutFeedbackRounds } from "./journal.js";
|
|
22
|
-
import { FINAL_STATES } from "../store/store.js";
|
|
22
|
+
import { FINAL_STATES, StoreLaunchMissing } from "../store/store.js";
|
|
23
23
|
import { journalEntries } from "../runner/journal-reader.js";
|
|
24
24
|
import { KINDS } from "../runner/journal-kinds.js";
|
|
25
25
|
import { keptOf, learnedOf, lostOf } from "../runner/learning-loop.js";
|
|
@@ -34,13 +34,48 @@ function answeredOf(row) {
|
|
|
34
34
|
return {};
|
|
35
35
|
return { answered_at: row.answered_at, job_cost_usd: usdOrNull(row.job_cost_usd), look_back_usd: usdOrNull(row.look_back_usd) };
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
/** Agent `agentId`'s runs' records read at once, whatever their number: its runs' launches (Store.runs.launches) and every
|
|
38
|
+
* round its runs' learning kept with the learning runs they name (Store.learning.kept), two reads beside `listed` (its
|
|
39
|
+
* runs, as runs.list read them). Each answers as the store's per-run read does: a run of `listed` with no launch row is
|
|
40
|
+
* StoreLaunchMissing, one that kept no learning has no round. A run not of `listed` is read from the store. */
|
|
41
|
+
export async function agentRecordsOf(store, agentId, listed) {
|
|
42
|
+
const [starts, kept] = await Promise.all([store.runs.learningStarts(agentId), store.learning.kept(agentId)]);
|
|
43
|
+
const ours = new Set(listed.map((run) => run.id));
|
|
44
|
+
const startOf = new Map(starts.map((row) => [row.runId, row.learning]));
|
|
45
|
+
// Each run's rounds, oldest first (the store reads them so).
|
|
46
|
+
const rounds = new Map();
|
|
47
|
+
for (const one of kept.proposals)
|
|
48
|
+
rounds.set(one.runId, [...(rounds.get(one.runId) ?? []), one]);
|
|
49
|
+
const rows = new Map([...listed, ...kept.learningRuns].map((run) => [run.id, run]));
|
|
50
|
+
return {
|
|
51
|
+
runs: {
|
|
52
|
+
launch: (runId) => store.runs.launch(runId),
|
|
53
|
+
learningStart: async (runId) => {
|
|
54
|
+
if (!ours.has(runId))
|
|
55
|
+
return learningStartOfRun(store, runId);
|
|
56
|
+
if (!startOf.has(runId))
|
|
57
|
+
throw new StoreLaunchMissing(runId);
|
|
58
|
+
return learningStartOfStored(startOf.get(runId));
|
|
59
|
+
},
|
|
60
|
+
get: async (id) => rows.get(id) ?? store.runs.get(id),
|
|
61
|
+
},
|
|
62
|
+
learning: {
|
|
63
|
+
proposal: async (runId, round) => {
|
|
64
|
+
if (!ours.has(runId))
|
|
65
|
+
return store.learning.proposal(runId, round);
|
|
66
|
+
const list = rounds.get(runId);
|
|
67
|
+
return round === undefined ? list?.at(-1) : list?.find((one) => one.round === round);
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Run `runId`'s learning end (its newest round's, or round `round`'s); null when the run kept no learning. Proposed while its learning run has not ended. `records`: where its rows are read (the store's per-run reads by default). */
|
|
73
|
+
export async function runLearningEnd(store, runId, round, records = store) {
|
|
74
|
+
const kept = await records.learning.proposal(runId, round);
|
|
40
75
|
if (!kept)
|
|
41
76
|
return null;
|
|
42
77
|
const row = (kept.proposal ?? {});
|
|
43
|
-
return { ...(await endOfKept(store, kept, row)), ...answeredOf(row), ...compiledOf(row) };
|
|
78
|
+
return { ...(await endOfKept(store, kept, row, records)), ...answeredOf(row), ...compiledOf(row) };
|
|
44
79
|
}
|
|
45
80
|
/** What a kept row says of its compile turn (runner/reflect-hook.ts): the record, and a failed draft's errors; read as
|
|
46
81
|
* untrusted, an entry out of shape left out. */
|
|
@@ -59,7 +94,7 @@ function compiledOf(row) {
|
|
|
59
94
|
return out;
|
|
60
95
|
}
|
|
61
96
|
/** The learning end a kept row and its learning run's journal say. */
|
|
62
|
-
async function endOfKept(store, kept, row) {
|
|
97
|
+
async function endOfKept(store, kept, row, records = store) {
|
|
63
98
|
const at = timeOf(kept.createdAt);
|
|
64
99
|
// Dropped before it was proposed (a cut run, nothing to keep, the checks): its end is the kept row's.
|
|
65
100
|
if (row.state !== "proposed" || !row.proposal) {
|
|
@@ -70,14 +105,10 @@ async function endOfKept(store, kept, row) {
|
|
|
70
105
|
const proposed = { state: "proposed", reason: null, detail: row.detail ?? null, at, ...left };
|
|
71
106
|
if (!kept.learningRunId)
|
|
72
107
|
return proposed;
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const merged = dataOf(KINDS.learningMerged);
|
|
76
|
-
const dropped = dataOf(KINDS.learningDropped);
|
|
108
|
+
const learningRun = await records.runs.get(kept.learningRunId);
|
|
109
|
+
const { merged, dropped, graded } = await learningEndEntries(store, kept.learningRunId, learningRun);
|
|
77
110
|
if (!merged && !dropped)
|
|
78
111
|
return proposed;
|
|
79
|
-
const graded = dataOf(KINDS.learningGraded);
|
|
80
|
-
const learningRun = await store.runs.get(kept.learningRunId);
|
|
81
112
|
const endedAt = learningRun?.endedAt ? timeOf(learningRun.endedAt) : at;
|
|
82
113
|
// What the grade spent: the graded entry's, or what a grade that failed spent before it did.
|
|
83
114
|
const spent = graded ?? (dropped && "usd" in dropped ? { usd: dropped.usd ?? null, tokens: dropped.tokens ?? null } : undefined);
|
|
@@ -110,14 +141,33 @@ async function endOfKept(store, kept, row) {
|
|
|
110
141
|
/** GET /stats's learning counts from the one store, over the runs `filter` picks as the analytics pick them (not archived,
|
|
111
142
|
* their own or their agent's; started in [from, to); of `agent`): an agentic run with a learning end counts, its end
|
|
112
143
|
* read as the run's view reads it (runLearningEnd). A workflow's run, and one with no learning, is not counted; nor is
|
|
113
|
-
* one whose reason this server does not give (an older server's). An imported run keeps no learning in the store.
|
|
114
|
-
|
|
144
|
+
* one whose reason this server does not give (an older server's). An imported run keeps no learning in the store. Each
|
|
145
|
+
* agent's runs' records are read at once (agentRecordsOf; `records`, already read for `filter.agent`), never a read a run. */
|
|
146
|
+
export async function learningCountsOverStore(store, filter, records) {
|
|
115
147
|
const from = filter.from === undefined ? -Infinity : Date.parse(filter.from);
|
|
116
148
|
const to = filter.to === undefined ? Infinity : Date.parse(filter.to);
|
|
117
149
|
const out = { runs: 0, merged: 0, dropped: {}, in_progress: 0 };
|
|
118
150
|
const agentArchived = new Map();
|
|
119
151
|
const workflow = new Map();
|
|
120
|
-
|
|
152
|
+
const listed = await store.runs.list(filter.agent !== undefined ? { agentId: filter.agent } : {});
|
|
153
|
+
const byAgent = new Map();
|
|
154
|
+
for (const run of listed) {
|
|
155
|
+
const runs = byAgent.get(run.agentId);
|
|
156
|
+
if (runs)
|
|
157
|
+
runs.push(run);
|
|
158
|
+
else
|
|
159
|
+
byAgent.set(run.agentId, [run]);
|
|
160
|
+
}
|
|
161
|
+
const read = new Map();
|
|
162
|
+
const recordsOf = (agentId) => {
|
|
163
|
+
if (records && agentId === filter.agent)
|
|
164
|
+
return Promise.resolve(records);
|
|
165
|
+
let one = read.get(agentId);
|
|
166
|
+
if (!one)
|
|
167
|
+
read.set(agentId, (one = agentRecordsOf(store, agentId, byAgent.get(agentId) ?? [])));
|
|
168
|
+
return one;
|
|
169
|
+
};
|
|
170
|
+
for (const run of listed) {
|
|
121
171
|
if (filter.agent !== undefined && run.agentId !== filter.agent)
|
|
122
172
|
continue;
|
|
123
173
|
if (run.importedFrom || run.archivedAt !== null || !(run.startedAt >= from && run.startedAt < to))
|
|
@@ -130,7 +180,7 @@ export async function learningCountsOverStore(store, filter) {
|
|
|
130
180
|
workflow.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind === "workflow");
|
|
131
181
|
if (workflow.get(run.revisionId))
|
|
132
182
|
continue;
|
|
133
|
-
const learning = await runLearningEnd(store, run.id);
|
|
183
|
+
const learning = await runLearningEnd(store, run.id, undefined, await recordsOf(run.agentId));
|
|
134
184
|
// A reason this server does not give (an older server's) is not counted.
|
|
135
185
|
if (!learning || (learning.reason !== null && !LEARNING_REASONS.includes(learning.reason)))
|
|
136
186
|
continue;
|
|
@@ -154,8 +204,8 @@ export async function learningSpendOverStore(store, window) {
|
|
|
154
204
|
/** An agent's learning counts as its learning view gives them (GET /agents/{id}/learning, learning-run.ts ofAgent's
|
|
155
205
|
* counts): how its runs that tried to learn fared, less `runs`, from the one store. Its notes' runs and its impact are
|
|
156
206
|
* agentLearningOverStore's. */
|
|
157
|
-
export async function agentLearningCountsOverStore(store, agentId) {
|
|
158
|
-
const { runs: _, ...counts } = await learningCountsOverStore(store, { agent: agentId });
|
|
207
|
+
export async function agentLearningCountsOverStore(store, agentId, records) {
|
|
208
|
+
const { runs: _, ...counts } = await learningCountsOverStore(store, { agent: agentId }, records);
|
|
159
209
|
return counts;
|
|
160
210
|
}
|
|
161
211
|
/** Agent `agentId`'s learning view from the one store (GET /agents/{id}/learning, learning-run.ts ofAgent): its counts
|
|
@@ -163,22 +213,24 @@ export async function agentLearningCountsOverStore(store, agentId) {
|
|
|
163
213
|
* changed (learningImpact), never a run's files. Each run's part is read from its launch (the notes it was given,
|
|
164
214
|
* learningStartOf), its journal once final (the notes its job read, notesReadOf) and its learning end (when its job
|
|
165
215
|
* answered and what it and looking back cost, its grade's cost). `seed_notes`, the notes a run started from, is its
|
|
166
|
-
* launch's seedNotes: every note in its seed, before the budget picked the given ones (main's seed_notes).
|
|
216
|
+
* launch's seedNotes: every note in its seed, before the budget picked the given ones (main's seed_notes). Its runs'
|
|
217
|
+
* launches and learning are read at once (agentRecordsOf), and a settled run's journal once a server (settledCache):
|
|
218
|
+
* a read a run only the first time it is seen. */
|
|
167
219
|
export async function agentLearningOverStore(store, agentId) {
|
|
168
|
-
const
|
|
220
|
+
const listed = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId);
|
|
221
|
+
const records = await agentRecordsOf(store, agentId, listed);
|
|
222
|
+
const counts = await agentLearningCountsOverStore(store, agentId, records);
|
|
169
223
|
const kinds = new Map();
|
|
170
224
|
const rows = [];
|
|
171
225
|
const learnings = new Map();
|
|
172
226
|
const files = [];
|
|
173
|
-
for (const run of
|
|
174
|
-
if (run.agentId !== agentId)
|
|
175
|
-
continue;
|
|
227
|
+
for (const run of listed) {
|
|
176
228
|
if (!kinds.has(run.revisionId))
|
|
177
229
|
kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind);
|
|
178
230
|
const final = FINAL_STATES.includes(run.state);
|
|
179
|
-
const started = await learningStartOfRun(
|
|
231
|
+
const started = await learningStartOfRun(records, run.id);
|
|
180
232
|
// A run that only uses what its agent learned keeps no proposal: its end is its start's (usedOnly), as its run reads give it.
|
|
181
|
-
const end = (await runLearningEnd(store, run.id)) ?? (started?.use ? usedOnly(started, final, timeOf(run.endedAt ?? run.startedAt)) : null);
|
|
233
|
+
const end = (await runLearningEnd(store, run.id, undefined, records)) ?? (started?.use ? usedOnly(started, final, timeOf(run.endedAt ?? run.startedAt)) : null);
|
|
182
234
|
const { read, laid } = await journalReadsOf(store, run, started);
|
|
183
235
|
if (started || end)
|
|
184
236
|
files.push(notesOf({ given: started?.given ?? [], read }));
|
|
@@ -190,7 +242,7 @@ export async function agentLearningOverStore(store, agentId) {
|
|
|
190
242
|
});
|
|
191
243
|
// What its claims laid of the skills and workflows it was offered (every learningLaid entry, laidOf): the run started
|
|
192
244
|
// from those alone.
|
|
193
|
-
learnings.set(run.id, end ? impactLearningOf(end, started, laid, await roundsSpendOf(
|
|
245
|
+
learnings.set(run.id, end ? impactLearningOf(end, started, laid, await roundsSpendOf(records, run.id), run.costUsd) : null);
|
|
194
246
|
}
|
|
195
247
|
return { counts, impact: learningImpact(rows, (row) => learnings.get(row.id) ?? null), notes: noteRuns(files) };
|
|
196
248
|
}
|
|
@@ -205,7 +257,10 @@ export async function agentLearningOverStore(store, agentId) {
|
|
|
205
257
|
* `limit`: the latest runs shown, each keeping its number; the summary is over every run. */
|
|
206
258
|
export async function agentCostOverStore(store, agentId, limit = Infinity) {
|
|
207
259
|
const kinds = new Map();
|
|
208
|
-
const
|
|
260
|
+
const listed = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId);
|
|
261
|
+
// Every run's launch and learning in a few reads (agentRecordsOf), never a read a run.
|
|
262
|
+
const records = await agentRecordsOf(store, agentId, listed);
|
|
263
|
+
const ended = listed.filter((run) => FINAL_STATES.includes(run.state) && !run.importedFrom && run.archivedAt === null).sort((a, b) => a.startedAt - b.startedAt || (a.id < b.id ? -1 : 1));
|
|
209
264
|
const runs = [];
|
|
210
265
|
let unknownPath = 0;
|
|
211
266
|
for (const run of ended) {
|
|
@@ -214,16 +269,16 @@ export async function agentCostOverStore(store, agentId, limit = Infinity) {
|
|
|
214
269
|
if (kinds.get(run.revisionId) === "workflow")
|
|
215
270
|
continue;
|
|
216
271
|
// A run that learns whose record names no path is left out and counted, never `agent` at $0.
|
|
217
|
-
if (!pathOfRow(run.metrics, await learningStartOfRun(
|
|
272
|
+
if (!pathOfRow(run.metrics, await learningStartOfRun(records, run.id))) {
|
|
218
273
|
unknownPath += 1;
|
|
219
274
|
continue;
|
|
220
275
|
}
|
|
221
|
-
runs.push(await costRunOf(
|
|
276
|
+
runs.push(await costRunOf(records, run, runs.length + 1));
|
|
222
277
|
}
|
|
223
278
|
// Each learned workflow that ran first, where it stands against the money rule (workflow-first.ts workflowCostsOf), over
|
|
224
279
|
// the runs the run's launch reads (pastRunsOverStore) at the all-in cost this series shows: a workflow over the line
|
|
225
280
|
// shows `needs_revision` with its two numbers, so the page and the launch's decision agree.
|
|
226
|
-
const workflows = workflowCostsOf(await pastRunsOverStore(store, agentId, new Map(runs.map((run) => [run.run_id, run.total_usd]))));
|
|
281
|
+
const workflows = workflowCostsOf(await pastRunsOverStore(store, agentId, new Map(runs.map((run) => [run.run_id, run.total_usd])), records));
|
|
227
282
|
const replay = servingReplayOf(await promotionsOf(store.settings, agentId), runs);
|
|
228
283
|
return { runs: runs.slice(Math.max(0, runs.length - limit)), summary: costSummary(runs, replay), total_runs: runs.length, unknown_cost_runs: runs.filter((run) => run.total_usd === null).length, unknown_path_runs: unknownPath, workflows };
|
|
229
284
|
}
|
|
@@ -311,8 +366,8 @@ export async function costRunOf(store, run, n) {
|
|
|
311
366
|
/** The runs the money rule reads for agent `agentId` (runner/workflow-first.ts costLineOf), one set for the run's launch
|
|
312
367
|
* and the cost page: of its newest PAST_RUNS runs, each that ended (ended, stopped or failed), is neither imported nor
|
|
313
368
|
* archived nor a workflow revision's run, with its all-in cost (allInOf). `known`: all-in costs already read, by run id
|
|
314
|
-
* (the cost page's series), read again for no run. */
|
|
315
|
-
export async function pastRunsOverStore(store, agentId, known) {
|
|
369
|
+
* (the cost page's series), read again for no run; `records`, where any other's rows are read (the store's by default). */
|
|
370
|
+
export async function pastRunsOverStore(store, agentId, known, records = store) {
|
|
316
371
|
const kinds = new Map();
|
|
317
372
|
const kept = [];
|
|
318
373
|
for (const run of await store.runs.list({ agentId, limit: PAST_RUNS })) {
|
|
@@ -326,7 +381,7 @@ export async function pastRunsOverStore(store, agentId, known) {
|
|
|
326
381
|
// A few reads a run, a batch at a time: a launch reads up to PAST_RUNS of them.
|
|
327
382
|
const past = [];
|
|
328
383
|
for (let at = 0; at < kept.length; at += 16) {
|
|
329
|
-
past.push(...(await Promise.all(kept.slice(at, at + 16).map(async (run) => ({ metrics: run.metrics, startedAt: run.startedAt, allInUsd: known?.has(run.id) ? known.get(run.id) : (await allInOf(
|
|
384
|
+
past.push(...(await Promise.all(kept.slice(at, at + 16).map(async (run) => ({ metrics: run.metrics, startedAt: run.startedAt, allInUsd: known?.has(run.id) ? known.get(run.id) : (await allInOf(records, run)).total_usd })))));
|
|
330
385
|
}
|
|
331
386
|
return past;
|
|
332
387
|
}
|
|
@@ -389,24 +444,40 @@ async function journalReadsOf(store, run, started) {
|
|
|
389
444
|
}
|
|
390
445
|
/** `name` when it is one of the learned workflows the run's launch offered, else null. */
|
|
391
446
|
const offeredName = (name, offered) => (name !== null && offered?.includes(name) ? name : null);
|
|
392
|
-
/** What a settled run's journal tells the agent's learning view, kept by store and run id with the run's epoch: a claim
|
|
393
|
-
* and a run's end each move the epoch, and only a claim writes to its journal, so a settled run's reads hold until the
|
|
394
|
-
* next claim of it. At most SETTLED_READS_MAX runs a store, the oldest read dropped first. */
|
|
395
|
-
const settledReads = new WeakMap();
|
|
396
447
|
const SETTLED_READS_MAX = 4096;
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
448
|
+
/** A cache of what a settled run's journal says, by store and run id with the run's epoch (see above), at most
|
|
449
|
+
* SETTLED_READS_MAX runs a store, the oldest read dropped first. A read in flight is kept too, so two reads of the
|
|
450
|
+
* agent at once (its page and its tab) walk a run's journal once; one that fails is dropped, for the next to read. */
|
|
451
|
+
function settledCache() {
|
|
452
|
+
const byStore = new WeakMap();
|
|
453
|
+
return (store, runId, epoch, read) => {
|
|
454
|
+
const runs = byStore.get(store) ?? new Map();
|
|
455
|
+
byStore.set(store, runs);
|
|
456
|
+
const kept = runs.get(runId);
|
|
457
|
+
if (kept && kept.epoch === epoch)
|
|
458
|
+
return kept.value;
|
|
459
|
+
const value = read();
|
|
460
|
+
const entry = { epoch, value };
|
|
461
|
+
runs.delete(runId);
|
|
462
|
+
runs.set(runId, entry);
|
|
463
|
+
if (runs.size > SETTLED_READS_MAX)
|
|
464
|
+
runs.delete(runs.keys().next().value);
|
|
465
|
+
value.catch(() => { if (runs.get(runId) === entry)
|
|
466
|
+
runs.delete(runId); });
|
|
467
|
+
return value;
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
const settledJournalReads = settledCache();
|
|
471
|
+
const settledLearningEnds = settledCache();
|
|
472
|
+
/** Learning run `id`'s end entries (`run`: its row): read once it is final and kept (settledCache), so an agent's
|
|
473
|
+
* learning view reads each of its learning runs' journals once, not at every read; read now while it runs. */
|
|
474
|
+
async function learningEndEntries(store, id, run) {
|
|
475
|
+
const read = async () => {
|
|
476
|
+
const entries = await journalEntries(store.readJournal(id), BACKGROUND_CONTEXT);
|
|
477
|
+
const dataOf = (kind) => entries.find((entry) => entry.kind === kind)?.data;
|
|
478
|
+
return { merged: dataOf(KINDS.learningMerged), dropped: dataOf(KINDS.learningDropped), graded: dataOf(KINDS.learningGraded) };
|
|
479
|
+
};
|
|
480
|
+
return run && FINAL_STATES.includes(run.state) ? settledLearningEnds(store, id, run.epoch, read) : read();
|
|
410
481
|
}
|
|
411
482
|
/** What every claim of a run laid, from its learningLaid entries, each name once: a resumed claim finds an earlier
|
|
412
483
|
* claim's skill folders there already and lays none of them again, though the run still has them. None laid when it has
|
|
@@ -593,6 +664,9 @@ export function withNotes(end, started, read) {
|
|
|
593
664
|
/** Run `runId`'s learning start as its launch records it (run-launch.ts learningStartOf, the one reader): its given notes,
|
|
594
665
|
* its seed sha and its # Learned section; undefined when the run does not learn or has no launch. */
|
|
595
666
|
async function learningStartOfRun(store, runId) {
|
|
667
|
+
// The agent's narrow read (agentRecordsOf) answers when the run is in it; a missing launch reads as a run that does not learn.
|
|
668
|
+
if (store.runs.learningStart)
|
|
669
|
+
return store.runs.learningStart(runId).catch(() => undefined);
|
|
596
670
|
const row = await store.runs.launch(runId).catch(() => undefined);
|
|
597
671
|
const launch = row ? readLaunchBody(row.body) : undefined;
|
|
598
672
|
return launch ? learningStartOf(launch) : undefined;
|
package/dist/template-eval.js
CHANGED
|
@@ -1206,7 +1206,7 @@ async function mailRun(ctx, one, n, fakes, layout) {
|
|
|
1206
1206
|
await faux.close();
|
|
1207
1207
|
}
|
|
1208
1208
|
}
|
|
1209
|
-
/** The run of an email case's trigger on `mail`: its
|
|
1209
|
+
/** The run of an email case's trigger on `mail`: its first poll waited on at the apply, on the account as seeded (the history),
|
|
1210
1210
|
* then the case's new message delivered, and the trigger's own next time come on the eval's clock, so its poll (or its
|
|
1211
1211
|
* schedule) fires through the engine's path; the run is its firing's. */
|
|
1212
1212
|
async function triggerRun(ctx, one, agentId, triggerId, mail) {
|
package/dist/templates.d.ts
CHANGED
|
@@ -165,6 +165,18 @@ export declare class PackageError extends Error {
|
|
|
165
165
|
* to acme/widgets." The package's name says what runs; the events are its accept's, the repositories its where
|
|
166
166
|
* conditions on /repository/full_name, when every rule names some. */
|
|
167
167
|
export declare function githubTriggerWords(packageName: string, source: Json): string;
|
|
168
|
+
/** The refusals of a trigger's create that mean this server can't set it up yet, by the trigger's source kind: an apply
|
|
169
|
+
* skips that trigger, never the apply, and says so under triggers.<i> (not_set_up_here). Any other refusal (a bad event
|
|
170
|
+
* or config, a 422, Composio's own error on the create) undoes the apply. GitHub's: no GitHub App here. Composio's: no
|
|
171
|
+
* public URL to send to, no connected account (or several) for the saved server's user, or the project's subscription
|
|
172
|
+
* at another address, which only the owner moves, from the console. */
|
|
173
|
+
export declare const TRIGGER_NOT_SET_UP_YET: Readonly<Record<string, readonly string[]>>;
|
|
174
|
+
/** Whether refusal `code` of a trigger of source kind `kind` is one TRIGGER_NOT_SET_UP_YET skips. */
|
|
175
|
+
export declare const notSetUpYet: (kind: unknown, code: string) => boolean;
|
|
176
|
+
/** What an apply says of a composio trigger it skipped (notSetUpYet): which trigger, and the refusal's own words. */
|
|
177
|
+
export declare function composioTriggerSkipped(packageName: string, trigger: Json, why: string): string;
|
|
178
|
+
/** Where the owner makes a composio trigger an apply skipped, once what refused it is fixed. */
|
|
179
|
+
export declare const COMPOSIO_TRIGGER_FIX = "Once that's fixed, make it from Triggers \u2192 New app trigger for this agent, with the same event and config.";
|
|
168
180
|
/** What an apply says of a github trigger it skipped because GitHub is not connected here: what to do, and what the
|
|
169
181
|
* trigger would then run on, in the package's own words ("Code review runs on each pull request to acme/widgets."). */
|
|
170
182
|
export declare const githubTriggerUnconnected: (packageName: string, source: Json) => string;
|
|
@@ -500,5 +512,6 @@ export declare function onServerName(name: string, servers: Readonly<Record<stri
|
|
|
500
512
|
* another of the package's toolkits is never rewritten twice. */
|
|
501
513
|
export declare function onServerNames(text: string, servers: Readonly<Record<string, string>>): string;
|
|
502
514
|
/** `p` as the agent an apply makes on `servers` sees it: its instructions and each skill file with the package's tool
|
|
503
|
-
* names on the saved servers' (onServerNames)
|
|
515
|
+
* names on the saved servers' (onServerNames), and each composio trigger's server, its need's toolkit, the saved server
|
|
516
|
+
* that need resolved to (onServerTrigger). Nothing else of it names a server: its pins and allow are by tool. */
|
|
504
517
|
export declare function onServers(p: Package, servers: Readonly<Record<string, string>>): Package;
|
package/dist/templates.js
CHANGED
|
@@ -151,10 +151,11 @@ export class PackageError extends Error {
|
|
|
151
151
|
this.problems = problems;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
/** The source kinds whose accept rules a parameter may fill: a github trigger's,
|
|
155
|
-
* sends every trigger of a project to one URL
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
/** The source kinds whose accept rules a parameter may fill: a github trigger's, a webhook trigger's (a provider that
|
|
155
|
+
* sends every trigger of a project to one URL is filtered to the owner's own repository by them), and a composio
|
|
156
|
+
* trigger's. */
|
|
157
|
+
const FILTERED_KINDS = ["github", "webhook", "composio"];
|
|
158
|
+
/** A github, webhook or composio source split at its where conditions' `in` values, the one place a parameter may fill it: `ins`, each
|
|
158
159
|
* condition's list, and `rest`, the source without them. */
|
|
159
160
|
function whereIns(source) {
|
|
160
161
|
const ins = [];
|
|
@@ -178,6 +179,24 @@ export function githubTriggerWords(packageName, source) {
|
|
|
178
179
|
return `${subject} runs on each ${or(events)} ${repos.length ? `to ${or(repos)}` : "to a repository the GitHub App is installed on"}.`;
|
|
179
180
|
}
|
|
180
181
|
const GITHUB_EVENT_WORDS = { pull_request: "pull request", pull_request_review: "pull request review", pull_request_review_comment: "review comment", issue_comment: "comment", issues: "issue", release: "release" };
|
|
182
|
+
/** The refusals of a trigger's create that mean this server can't set it up yet, by the trigger's source kind: an apply
|
|
183
|
+
* skips that trigger, never the apply, and says so under triggers.<i> (not_set_up_here). Any other refusal (a bad event
|
|
184
|
+
* or config, a 422, Composio's own error on the create) undoes the apply. GitHub's: no GitHub App here. Composio's: no
|
|
185
|
+
* public URL to send to, no connected account (or several) for the saved server's user, or the project's subscription
|
|
186
|
+
* at another address, which only the owner moves, from the console. */
|
|
187
|
+
export const TRIGGER_NOT_SET_UP_YET = {
|
|
188
|
+
github: ["github_not_connected"],
|
|
189
|
+
composio: ["composio_no_public_url", "composio_not_connected", "composio_account_ambiguous", "composio_subscription_elsewhere"],
|
|
190
|
+
};
|
|
191
|
+
/** Whether refusal `code` of a trigger of source kind `kind` is one TRIGGER_NOT_SET_UP_YET skips. */
|
|
192
|
+
export const notSetUpYet = (kind, code) => typeof kind === "string" && Object.hasOwn(TRIGGER_NOT_SET_UP_YET, kind) && TRIGGER_NOT_SET_UP_YET[kind].includes(code);
|
|
193
|
+
/** What an apply says of a composio trigger it skipped (notSetUpYet): which trigger, and the refusal's own words. */
|
|
194
|
+
export function composioTriggerSkipped(packageName, trigger, why) {
|
|
195
|
+
const source = isObject(trigger.source) ? trigger.source : {};
|
|
196
|
+
return `The ${packageName} template's trigger ${String(trigger.name)} (Composio ${String(source.event)} on ${String(source.server)}) was not made: ${why}`;
|
|
197
|
+
}
|
|
198
|
+
/** Where the owner makes a composio trigger an apply skipped, once what refused it is fixed. */
|
|
199
|
+
export const COMPOSIO_TRIGGER_FIX = "Once that's fixed, make it from Triggers → New app trigger for this agent, with the same event and config.";
|
|
181
200
|
/** What an apply says of a github trigger it skipped because GitHub is not connected here: what to do, and what the
|
|
182
201
|
* trigger would then run on, in the package's own words ("Code review runs on each pull request to acme/widgets."). */
|
|
183
202
|
export const githubTriggerUnconnected = (packageName, source) => `Connect GitHub in Settings, then apply again so it runs by itself: ${githubTriggerWords(packageName, source)}`;
|
|
@@ -212,14 +231,18 @@ const inputFilled = (value, given) => {
|
|
|
212
231
|
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, inputFilled(item, given)]).filter(([, item]) => item !== undefined));
|
|
213
232
|
return value;
|
|
214
233
|
};
|
|
215
|
-
/** A trigger filled from the apply's parameters: its target.input typed (inputFilled),
|
|
216
|
-
* placeholder names, the rest as text. */
|
|
234
|
+
/** A trigger filled from the apply's parameters: its target.input and a composio source's config typed (inputFilled),
|
|
235
|
+
* its enabled the boolean its one placeholder names, the rest as text. */
|
|
217
236
|
const triggerFilled = (trigger, given) => {
|
|
218
237
|
const out = filled(trigger, given);
|
|
219
238
|
if (isObject(trigger.target) && trigger.target.input !== undefined)
|
|
220
239
|
out.target = { ...out.target, input: inputFilled(trigger.target.input, given) };
|
|
221
240
|
if (typeof trigger.enabled === "string" && WHOLE.test(trigger.enabled))
|
|
222
241
|
out.enabled = typedFilled(trigger.enabled, given);
|
|
242
|
+
// A composio trigger's config is typed as a pin's values are: a value that is one placeholder alone takes the
|
|
243
|
+
// parameter's type (an integer config field gets an integer).
|
|
244
|
+
if (isObject(trigger.source) && trigger.source.kind === "composio" && isObject(trigger.source.config))
|
|
245
|
+
out.source = { ...out.source, config: inputFilled(trigger.source.config, given) };
|
|
223
246
|
return out;
|
|
224
247
|
};
|
|
225
248
|
/** An mcp entry's `pin` read: by tool, each one of the entry's `tools`, its arguments checked by the one rule every pin
|
|
@@ -652,6 +675,16 @@ export function readPackage(from) {
|
|
|
652
675
|
const set = isObject(source) && source.kind === "composio" ? COMPOSIO_SET.filter((field) => source[field] !== undefined) : [];
|
|
653
676
|
if (set.length)
|
|
654
677
|
bad(MANIFEST, `triggers[${i}].source holds ${set.join(" and ")}, which this server sets when it makes a composio trigger on Composio: a template can't carry ${set.length > 1 ? "them" : "it"}. Leave ${set.length > 1 ? "them" : "it"} out, or make the trigger from the console on this server (Triggers → New app trigger) once the agent is made.`);
|
|
678
|
+
// Its server is one of the package's own needs, by its toolkit, as mcp:<toolkit>/<tool> names its tools: no saved
|
|
679
|
+
// server's name, which is only the author's. The apply makes it on the saved server that need resolves to
|
|
680
|
+
// (onServers). A required need: one with no saved server refuses the apply, so the trigger is never made without one.
|
|
681
|
+
if (isObject(source) && source.kind === "composio") {
|
|
682
|
+
const need = mcp.find((one) => one.toolkit === source.server);
|
|
683
|
+
if (!need || need.source !== "composio")
|
|
684
|
+
bad(MANIFEST, `triggers[${i}].source.server ${JSON.stringify(source.server)} names no MCP need of the package with source: composio: a template's composio trigger names that need's toolkit (server: github for the need {source: composio, toolkit: github}), and the apply makes it on the saved Composio server the need resolves to`);
|
|
685
|
+
else if (!need.required)
|
|
686
|
+
bad(MANIFEST, `triggers[${i}].source.server ${need.toolkit}: the trigger's server is the mcp need of the toolkit ${need.toolkit}, so that need is required: true. An optional one may have no saved server here, and the trigger would have none`);
|
|
687
|
+
}
|
|
655
688
|
});
|
|
656
689
|
if (triggers.length && !(isObject(f.budget) && f.budget.per_run_usd !== undefined))
|
|
657
690
|
bad(MANIFEST, "budget is required when the package has triggers: {per_run_usd}, each run's cap");
|
|
@@ -683,11 +716,12 @@ export function readPackage(from) {
|
|
|
683
716
|
if (!Object.hasOwn(fields, used))
|
|
684
717
|
bad(MANIFEST, `\${parameters.${used}} names no parameter`);
|
|
685
718
|
}
|
|
686
|
-
// A placeholder fills text a run reads, a schedule's time (its cron and timezone, read as the schedule at apply),
|
|
687
|
-
// github or
|
|
688
|
-
//
|
|
689
|
-
//
|
|
690
|
-
//
|
|
719
|
+
// A placeholder fills text a run reads, a schedule's time (its cron and timezone, read as the schedule at apply), a
|
|
720
|
+
// github, webhook or composio trigger's where `in` values (the repository it takes, say), and a composio trigger's
|
|
721
|
+
// config values (what Composio watches for it: the owner's repository, team or label); a trigger's other settings,
|
|
722
|
+
// a composio trigger's server and event among them, are the package's own, checked here. A parameter that sets a time
|
|
723
|
+
// has a default, so the schedule the package ships is checked here too; one a where or a composio config takes is
|
|
724
|
+
// required or has a default, so the trigger never fills empty.
|
|
691
725
|
triggers.forEach((trigger, i) => {
|
|
692
726
|
if (!isObject(trigger))
|
|
693
727
|
return;
|
|
@@ -695,12 +729,13 @@ export function readPackage(from) {
|
|
|
695
729
|
const filtered = isObject(trigger.source) && FILTERED_KINDS.includes(trigger.source.kind);
|
|
696
730
|
const fixed = Object.entries(trigger).flatMap(([key, value]) => key === "target" && isObject(value) ? Object.entries(value).filter(([k]) => k !== "input").map(([k, v]) => [`target.${k}`, v])
|
|
697
731
|
: key === "source" && timed && isObject(value) ? Object.entries(value).filter(([k]) => !SCHEDULE_FIELDS.includes(k)).map(([k, v]) => [`source.${k}`, v])
|
|
698
|
-
: key === "source" && filtered && isObject(value) ?
|
|
699
|
-
: key === "
|
|
700
|
-
:
|
|
732
|
+
: key === "source" && filtered && isObject(value) && value.kind === "composio" ? Object.entries(whereIns(value).rest).filter(([k]) => k !== "config").map(([k, v]) => [`source.${k}`, v])
|
|
733
|
+
: key === "source" && filtered && isObject(value) ? [[key, whereIns(value).rest]]
|
|
734
|
+
: key === "enabled" && typeof value === "string" ? []
|
|
735
|
+
: [[key, value]]);
|
|
701
736
|
for (const [at, value] of fixed)
|
|
702
737
|
for (const [used] of strings(value).flatMap((text) => [...text.matchAll(PLACEHOLDER)]))
|
|
703
|
-
bad(MANIFEST, `triggers[${i}].${at} holds ${used}: a placeholder goes in display_name, the instructions, a trigger's target.input, a schedule's cron and timezone, a github or
|
|
738
|
+
bad(MANIFEST, `triggers[${i}].${at} holds ${used}: a placeholder goes in display_name, the instructions, a trigger's target.input, a schedule's cron and timezone, a github, webhook or composio trigger's where in values, a composio trigger's config values, or an mcp pin's values`);
|
|
704
739
|
// enabled is true, false, or one boolean parameter with a default, filled at apply (triggerFilled): the trigger is on
|
|
705
740
|
// or off by the owner's answer, and by the package's default when the apply leaves it out.
|
|
706
741
|
if (typeof trigger.enabled === "string") {
|
|
@@ -720,6 +755,12 @@ export function readPackage(from) {
|
|
|
720
755
|
bad(MANIFEST, `parameters.${used} is used in triggers[${i}].source.accept, so it is required or has a default: a ${trigger.source.kind} trigger filled empty takes no event`);
|
|
721
756
|
}
|
|
722
757
|
}
|
|
758
|
+
if (isObject(trigger.source) && trigger.source.kind === "composio") {
|
|
759
|
+
for (const used of new Set(strings(trigger.source.config).flatMap((text) => [...text.matchAll(PLACEHOLDER)].map((m) => m[1])))) {
|
|
760
|
+
if (Object.hasOwn(fields, used) && !parameters.required?.includes(used) && fields[used].default === undefined)
|
|
761
|
+
bad(MANIFEST, `parameters.${used} is used in triggers[${i}].source.config, so it is required or has a default: a composio trigger filled empty watches nothing of the owner's (Composio refuses a required config value left empty)`);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
723
764
|
if (!timed)
|
|
724
765
|
return;
|
|
725
766
|
for (const field of SCHEDULE_FIELDS) {
|
|
@@ -1221,7 +1262,16 @@ export function onServerNames(text, servers) {
|
|
|
1221
1262
|
return text.replace(MCP_NAME_IN_TEXT, (name) => onServerName(name, servers));
|
|
1222
1263
|
}
|
|
1223
1264
|
/** `p` as the agent an apply makes on `servers` sees it: its instructions and each skill file with the package's tool
|
|
1224
|
-
* names on the saved servers' (onServerNames)
|
|
1265
|
+
* names on the saved servers' (onServerNames), and each composio trigger's server, its need's toolkit, the saved server
|
|
1266
|
+
* that need resolved to (onServerTrigger). Nothing else of it names a server: its pins and allow are by tool. */
|
|
1225
1267
|
export function onServers(p, servers) {
|
|
1226
|
-
return { ...p, instructions: onServerNames(p.instructions, servers), skills: Object.fromEntries(Object.entries(p.skills).map(([path, text]) => [path, onServerNames(text, servers)])) };
|
|
1268
|
+
return { ...p, instructions: onServerNames(p.instructions, servers), skills: Object.fromEntries(Object.entries(p.skills).map(([path, text]) => [path, onServerNames(text, servers)])), triggers: p.triggers.map((trigger) => onServerTrigger(trigger, servers)) };
|
|
1269
|
+
}
|
|
1270
|
+
/** Trigger `trigger` on the saved servers of `servers` ({toolkit: saved name}): a composio one's `source.server`, the
|
|
1271
|
+
* toolkit of the package's need (readPackage), the saved server the apply resolved that need to. Any other as it is. */
|
|
1272
|
+
function onServerTrigger(trigger, servers) {
|
|
1273
|
+
const source = trigger.source;
|
|
1274
|
+
if (!isObject(source) || source.kind !== "composio" || typeof source.server !== "string" || !Object.hasOwn(servers, source.server))
|
|
1275
|
+
return trigger;
|
|
1276
|
+
return { ...trigger, source: { ...source, server: servers[source.server] } };
|
|
1227
1277
|
}
|