@parcha/agentrun-serve 0.1.0-beta.40 → 0.1.0-beta.41
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 +77 -0
- package/README.md +78 -15
- package/dist/api-only.d.ts +3 -1
- package/dist/api-only.js +4 -2
- package/dist/api-token.d.ts +30 -0
- package/dist/api-token.js +89 -0
- package/dist/cli.js +19 -5
- package/dist/composio-made.d.ts +54 -0
- package/dist/composio-made.js +83 -0
- package/dist/composio-preset.d.ts +16 -8
- package/dist/composio-preset.js +106 -43
- package/dist/composio-triggers.d.ts +7 -2
- package/dist/composio-triggers.js +13 -7
- package/dist/computer-attach.d.ts +29 -11
- package/dist/computer-attach.js +141 -47
- package/dist/computer-keys.d.ts +4 -0
- package/dist/computer-keys.js +5 -0
- package/dist/computers.d.ts +11 -1
- package/dist/computers.js +21 -12
- package/dist/console/assets/{index-B8Zn1Iqn.css → index-C3gNPz58.css} +1 -1
- package/dist/console/assets/index-COGhx_2Z.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +9 -2
- package/dist/eval-feed.d.ts +26 -0
- package/dist/eval-feed.js +68 -0
- package/dist/eval-mailbox.d.ts +4 -1
- package/dist/eval-mailbox.js +11 -3
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/feed/feed-faux.d.ts +62 -0
- package/dist/feed/feed-faux.js +123 -0
- package/dist/feed/fetch.d.ts +41 -0
- package/dist/feed/fetch.js +128 -0
- package/dist/feed/parse.d.ts +41 -0
- package/dist/feed/parse.js +300 -0
- package/dist/learn/check.d.ts +3 -1
- package/dist/learn/check.js +57 -2
- package/dist/learn/compile.js +1 -1
- package/dist/learned-nodes.d.ts +21 -4
- package/dist/learned-nodes.js +21 -8
- package/dist/learned-workflow.d.ts +3 -3
- package/dist/learned-workflow.js +14 -5
- package/dist/mcp-oauth.d.ts +15 -1
- package/dist/mcp-oauth.js +39 -5
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +4 -3
- package/dist/mcp-servers-store.d.ts +58 -5
- package/dist/mcp-servers-store.js +136 -17
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +2 -2
- package/dist/observation/http.d.ts +4 -1
- package/dist/observation/http.js +5 -4
- package/dist/openapi.js +46 -12
- package/dist/print.d.ts +6 -3
- package/dist/print.js +4 -2
- package/dist/run-labels.d.ts +23 -0
- package/dist/run-labels.js +79 -0
- package/dist/run-secrets.js +12 -4
- package/dist/runner/adapter-loop.js +91 -10
- package/dist/runner/adapter-run-spec.d.ts +4 -0
- package/dist/runner/adapter-run-spec.js +38 -31
- package/dist/runner/beside.d.ts +6 -3
- package/dist/runner/beside.js +9 -7
- package/dist/runner/cli-run-spec.js +32 -26
- package/dist/runner/conformance/harness.js +69 -14
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/main.d.ts +1 -1
- package/dist/runner/main.js +2 -2
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +4 -0
- package/dist/runner/mcp-run.js +5 -3
- package/dist/runner/model-route.d.ts +4 -2
- package/dist/runner/model-route.js +8 -8
- package/dist/runner/promotion.d.ts +8 -0
- package/dist/runner/promotion.js +43 -1
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +9 -7
- package/dist/runs-over-store.js +5 -2
- package/dist/sdk/runs.d.ts +7 -1
- package/dist/sdk/runs.js +19 -6
- package/dist/secret-cut.js +3 -1
- package/dist/secrets.js +3 -1
- package/dist/server.d.ts +27 -2
- package/dist/server.js +168 -50
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
- package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
- package/dist/store/schema.d.ts +9 -0
- package/dist/store/schema.js +26 -2
- package/dist/store/sqlite/connection.js +11 -3
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +3 -2
- package/dist/store/sqlite/store.js +64 -10
- package/dist/store/store.d.ts +38 -1
- package/dist/store-reads/journal.js +2 -1
- package/dist/store-reads/learning.js +6 -1
- package/dist/store-reads/runs.d.ts +4 -3
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.js +4 -2
- package/dist/template-eval.d.ts +4 -0
- package/dist/template-eval.js +127 -50
- package/dist/templates.d.ts +10 -0
- package/dist/templates.js +75 -17
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/trigger-adapter.d.ts +9 -4
- package/dist/trigger-adapters.js +2 -1
- package/dist/trigger-feed.d.ts +12 -0
- package/dist/trigger-feed.js +371 -0
- package/dist/triggers.d.ts +2 -1
- package/dist/triggers.js +23 -5
- package/dist/webhooks.js +9 -5
- package/dist/workspace/computer-deps.d.ts +5 -1
- package/dist/workspace/computer-deps.js +2 -2
- package/dist/workspace/index.d.ts +1 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/resolve-computer.d.ts +32 -3
- package/dist/workspace/resolve-computer.js +47 -9
- package/launcher/agentrun-serve +6 -1
- package/package.json +10 -9
- package/templates/README.md +27 -2
- package/dist/console/assets/index-Jbxjcmdp.js +0 -705
package/dist/template-eval.js
CHANGED
|
@@ -23,6 +23,7 @@ import { inputMessage } from "./run-manifest.js";
|
|
|
23
23
|
import { shownUrl } from "./mcp-probe.js";
|
|
24
24
|
import { isMonidName, MCP_SERVER_NAME, MCP_TOOL_NAME, mcpNameOf, mcpToolName, monidNameOf, parseToolName } from "./tool-names.js";
|
|
25
25
|
import { evalClock, LAYOUTS, mailboxAfter, mailboxFixtureOf, mailboxText, mailboxVerdict, seed, seededFaux, snapshot } from "./eval-mailbox.js";
|
|
26
|
+
import { caseFeeds, feedFixtureOf } from "./eval-feed.js";
|
|
26
27
|
import { EMAIL_TOOLS } from "./email/names.js";
|
|
27
28
|
import { settingsKeyOf, shellToolOf } from "./tool-gate.js";
|
|
28
29
|
import { webShownOf } from "./timeline/index.js";
|
|
@@ -32,7 +33,7 @@ import { WEB_FETCH_TOOL } from "./web-fetch.js";
|
|
|
32
33
|
import { WEB_SEARCH_TOOL } from "./web-search.js";
|
|
33
34
|
import { dayIn, serverZone } from "./environment.js";
|
|
34
35
|
import { instantOf } from "./trigger-adapter.js";
|
|
35
|
-
import { applyBodyOf, compiled, filledPins, onServerName, onServers, packageView, readPackage } from "./templates.js";
|
|
36
|
+
import { applyBodyOf, compiled, filledPins, filledSource, onServerName, onServers, packageView, readPackage } from "./templates.js";
|
|
36
37
|
import { inputIssues, inputSchemaOf, isObject, MODEL_REF } from "./validate.js";
|
|
37
38
|
/** What a grader run is told, whatever the rubric: blind, strict, and its verdict as one JSON block. */
|
|
38
39
|
export const GRADER_INSTRUCTIONS = `You grade one run of an AI agent against one rubric. You see the rubric, the task the agent was given, its answer, and the tool calls it made; nothing else, and nothing else matters.
|
|
@@ -63,7 +64,7 @@ export const EVAL_HARNESSES = "agentrun-eval-harnesses";
|
|
|
63
64
|
export const ON_DATA_WITH_SERVER = "--on-data is the data folder of the eval's own server, and --server names another server: give one of them";
|
|
64
65
|
const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
|
|
65
66
|
const PROMPT_FIELDS = ["description", "runs", "max_cost_usd", "input"];
|
|
66
|
-
const CASE_FIELDS = ["parameters", "grants", "mcp", "web", "monid", "learning", "now", "email"];
|
|
67
|
+
const CASE_FIELDS = ["parameters", "grants", "mcp", "web", "monid", "learning", "now", "email", "feed"];
|
|
67
68
|
const GRADER_FIELDS = {
|
|
68
69
|
llm: ["type", "target"],
|
|
69
70
|
regex: ["type", "pattern", "flags", "expect", "target"],
|
|
@@ -79,7 +80,7 @@ const LOOPBACK = "127.0.0.1"; // key-gate: loopback-rule each fake MCP server li
|
|
|
79
80
|
/** A host name on this machine: a case with fake MCP servers needs a server here, which reaches them on loopback. */
|
|
80
81
|
const LOOPBACK_HOST = /^(?:127\.\d+\.\d+\.\d+|localhost|\[::1\])$/; // key-gate: loopback-rule a server on this machine reaches the fakes
|
|
81
82
|
/** A case's fields that the eval's own runner alone binds (EvalFakes), each with what it does: a named server refuses them. */
|
|
82
|
-
const OWN_SERVER_FAKES = [["web", "web fakes the web tools"], ["now", "now sets its runs' clock"], ["monid", "monid fakes the package's monid endpoints"], ["email", "email fakes the server's email account"]];
|
|
83
|
+
const OWN_SERVER_FAKES = [["web", "web fakes the web tools"], ["now", "now sets its runs' clock"], ["monid", "monid fakes the package's monid endpoints"], ["email", "email fakes the server's email account"], ["feed", "feed fakes the package's feeds"]];
|
|
83
84
|
/** A case's run input: its prompt's body as content (none when empty), then its typed fields. */
|
|
84
85
|
export const runInput = (content, fields) => ({ ...(content ? { content } : {}), ...fields });
|
|
85
86
|
/** Cases that do not check: every problem, each naming its file. */
|
|
@@ -304,7 +305,7 @@ export function readCases(dir, names) {
|
|
|
304
305
|
for (const field of unknown(c, CASE_FIELDS))
|
|
305
306
|
bad(`${at}/case.yaml: no field ${field}: its fields are ${CASE_FIELDS.join(", ")}`);
|
|
306
307
|
// An email case's run is on its trigger's input, and its prompt gives none (`email` below holds it to that).
|
|
307
|
-
if (c.email === undefined)
|
|
308
|
+
if (c.email === undefined && c.feed === undefined)
|
|
308
309
|
for (const issue of inputIssues(runInput(body, fields), inputSchemaOf(pkg.inputSchema)))
|
|
309
310
|
bad(`${at}/prompt.md: ${issue.message}`);
|
|
310
311
|
if (c.parameters !== undefined && !isObject(c.parameters))
|
|
@@ -419,6 +420,39 @@ export function readCases(dir, names) {
|
|
|
419
420
|
if (body || fields || f.max_cost_usd !== undefined)
|
|
420
421
|
bad(`${at}/prompt.md: an email case's run is started by the package's trigger, on the trigger's input and cap: its prompt.md holds description and runs alone`);
|
|
421
422
|
}
|
|
423
|
+
// The case's fake feed: its fixture, and the package's feed trigger its runs start from (eval-feed.ts).
|
|
424
|
+
let feed;
|
|
425
|
+
if (c.feed !== undefined) {
|
|
426
|
+
const path = inside(root, c.feed, "file");
|
|
427
|
+
let parsed;
|
|
428
|
+
if (c.email !== undefined)
|
|
429
|
+
bad(`${at}/case.yaml: a case's run is started by one trigger: email or feed, not both`);
|
|
430
|
+
if (!path)
|
|
431
|
+
bad(`${at}/case.yaml: feed is a feed fixture file in the case (not ${JSON.stringify(c.feed)})`);
|
|
432
|
+
else {
|
|
433
|
+
try {
|
|
434
|
+
parsed = JSON.parse(readFileSync(join(root, path), "utf8"));
|
|
435
|
+
}
|
|
436
|
+
catch (error) {
|
|
437
|
+
bad(`${at}/${path}: is not JSON (${error.message})`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
const fixture = parsed === undefined ? undefined : feedFixtureOf(parsed, `${at}/${path}`, bad);
|
|
441
|
+
const kindOf = (t) => (isObject(t.source) ? t.source.kind : undefined);
|
|
442
|
+
const named = fixture?.trigger === undefined ? undefined : pkg.triggers.find((t) => t.name === fixture.trigger);
|
|
443
|
+
const starts = named ? [named] : pkg.triggers.filter((t) => kindOf(t) === "feed");
|
|
444
|
+
if (!fixture)
|
|
445
|
+
undefined;
|
|
446
|
+
else if (fixture.trigger !== undefined && !named)
|
|
447
|
+
bad(`${at}/${path}: trigger ${fixture.trigger} is not one of the package's triggers (${pkg.triggers.map((t) => String(t.name)).join(", ") || "none"})`);
|
|
448
|
+
else if (starts.length !== 1 || kindOf(starts[0]) !== "feed")
|
|
449
|
+
bad(`${at}/${path}: a feed case starts its run through the package's feed trigger, and ${named ? `${fixture.trigger} is a ${String(kindOf(named))} trigger` : starts.length ? `the package has ${starts.length}: name one with trigger` : "the package has none"}`);
|
|
450
|
+
else
|
|
451
|
+
feed = { ...fixture, trigger: String(starts[0].name) };
|
|
452
|
+
// Its run is the trigger's, on the trigger's input and cap: the prompt gives neither.
|
|
453
|
+
if (body || fields || f.max_cost_usd !== undefined)
|
|
454
|
+
bad(`${at}/prompt.md: a feed case's run is started by the package's trigger, on the trigger's input and cap: its prompt.md holds description and runs alone`);
|
|
455
|
+
}
|
|
422
456
|
const learning = [];
|
|
423
457
|
if (c.learning !== undefined) {
|
|
424
458
|
const folder = inside(root, c.learning, "dir");
|
|
@@ -464,7 +498,7 @@ export function readCases(dir, names) {
|
|
|
464
498
|
cases.push({
|
|
465
499
|
name, description: typeof f.description === "string" ? f.description : "", runs: typeof f.runs === "number" ? f.runs : 1,
|
|
466
500
|
...(typeof f.max_cost_usd === "number" ? { maxCostUsd: f.max_cost_usd } : {}), input: body, ...(fields ? { fields } : {}),
|
|
467
|
-
parameters, grants, mcp, ...(web ? { web } : {}), ...(monid ? { monid } : {}), learning, graders, ...(typeof c.now === "string" ? { now: c.now } : {}), ...(email ? { email } : {}),
|
|
501
|
+
parameters, grants, mcp, ...(web ? { web } : {}), ...(monid ? { monid } : {}), learning, graders, ...(typeof c.now === "string" ? { now: c.now } : {}), ...(email ? { email } : {}), ...(feed ? { feed } : {}),
|
|
468
502
|
});
|
|
469
503
|
}
|
|
470
504
|
if (problems.length)
|
|
@@ -958,7 +992,11 @@ export async function evalTemplate(options) {
|
|
|
958
992
|
throw new CaseError(options.dir, refused);
|
|
959
993
|
// Each run's fakes, by the agent the eval made for it (runOnce), which the runner beside the server reads at the claim.
|
|
960
994
|
const fakes = new Map();
|
|
961
|
-
const clock = !options.server && cases.some((one) => one.email) ? evalClock() : undefined;
|
|
995
|
+
const clock = !options.server && cases.some((one) => one.email || one.feed) ? evalClock() : undefined;
|
|
996
|
+
// Where the eval's own server reads each feed: the running feed case's fakes (feedRun). A feed no case routes (a feed
|
|
997
|
+
// trigger of the package's that the eval deletes once the apply made it, read at its creation) is served nowhere: its
|
|
998
|
+
// read is unreachable at once, never sent, so no eval reads a real feed.
|
|
999
|
+
const feedRoutes = {};
|
|
962
1000
|
const started = new Date().toISOString();
|
|
963
1001
|
const scratch = options.server ? undefined : mkdtempSync(join(process.env.TMPDIR ?? tmpdir(), "agentrun-eval-"));
|
|
964
1002
|
// The in-process server's data: the owner's folder (options.data), which stays, or one in the scratch, gone with it.
|
|
@@ -991,7 +1029,7 @@ export async function evalTemplate(options) {
|
|
|
991
1029
|
// A token of its own on a scratch folder. On the owner's folder none is given: a given token makes the server remove
|
|
992
1030
|
// the folder's .token (server.ts), the owner's saved API token, so the eval's server reads the one the folder keeps,
|
|
993
1031
|
// and a .token it had to make there (the folder had none) goes when it closes, the folder as it was.
|
|
994
|
-
const serve = await startServe({ mcpLoopback: true, mcpStandIns: true, data: data, port: 0, ...(options.data === undefined ? { token: randomBytes(24).toString("base64url") } : {}), templates: join(scratch, "templates"), drainTimeout: "5s", harnessInstall, ...(options.serve ?? {}), ...(clock ? { triggerClock: clock } : {}) }).catch((error) => {
|
|
1032
|
+
const serve = await startServe({ mcpLoopback: true, mcpStandIns: true, data: data, port: 0, ...(options.data === undefined ? { token: randomBytes(24).toString("base64url") } : {}), templates: join(scratch, "templates"), drainTimeout: "5s", harnessInstall, feedsAt: (url) => feedRoutes.route?.(url) ?? null, ...(options.serve ?? {}), ...(clock ? { triggerClock: clock } : {}) }).catch((error) => {
|
|
995
1033
|
removeTree(scratch);
|
|
996
1034
|
throw error;
|
|
997
1035
|
});
|
|
@@ -1008,7 +1046,7 @@ export async function evalTemplate(options) {
|
|
|
1008
1046
|
const { withoutFaux } = await import("./model.js");
|
|
1009
1047
|
const serveOptions = options.serve ?? {};
|
|
1010
1048
|
// Its run lines go to stderr: stdout is the eval's report.
|
|
1011
|
-
const beside = await runnerBeside(data, { mcpLoopback: serve.localInstall, evalFakes: (agentId) => fakes.get(agentId), harnessInstall, onLine: (line) => console.error(line), ...(serveOptions.faux ? { env: { ...withoutFaux(process.env), ...fauxEnvOf({ data: data, ...serveOptions }) } } : {}) }).catch(async (error) => {
|
|
1049
|
+
const beside = await runnerBeside(data, { mcpLoopback: serve.localInstall, mcpOwn: serve.own, evalFakes: (agentId) => fakes.get(agentId), harnessInstall, onLine: (line) => console.error(line), ...(serveOptions.faux ? { env: { ...withoutFaux(process.env), ...fauxEnvOf({ data: data, ...serveOptions }) } } : {}) }).catch(async (error) => {
|
|
1012
1050
|
await closeServe();
|
|
1013
1051
|
removeTree(scratch);
|
|
1014
1052
|
throw error;
|
|
@@ -1047,7 +1085,7 @@ export async function evalTemplate(options) {
|
|
|
1047
1085
|
let grader;
|
|
1048
1086
|
const made = { agents: [], runs: new Set(), triggers: new Set() };
|
|
1049
1087
|
const ctx = {
|
|
1050
|
-
api, pkg, options, made, log, fakes, ...(clock ? { clock } : {}), ...(owner ? { owner } : {}),
|
|
1088
|
+
api, pkg, options, made, log, fakes, feedRoutes, ...(clock ? { clock } : {}), ...(owner ? { owner } : {}),
|
|
1051
1089
|
graderAgent: async () => {
|
|
1052
1090
|
if (grader)
|
|
1053
1091
|
return grader;
|
|
@@ -1133,7 +1171,7 @@ async function runCase(ctx, one) {
|
|
|
1133
1171
|
options.signal?.throwIfAborted();
|
|
1134
1172
|
for (const fake of fakes)
|
|
1135
1173
|
fake.calls.length = 0;
|
|
1136
|
-
const result = layout ? await mailRun(ctx, one, n, fakes, layout) : await runOnce(ctx, one, n, fakes);
|
|
1174
|
+
const result = layout ? await mailRun(ctx, one, n, fakes, layout) : one.feed ? await feedRun(ctx, one, n, fakes) : await runOnce(ctx, one, n, fakes);
|
|
1137
1175
|
log(`case ${one.name} run ${n}${layout ? ` (${layout})` : ""}: ${result.status}, ${result.pass ? "pass" : "FAIL"}${result.cost_usd === null ? "" : ` (${usd(result.cost_usd)})`}`);
|
|
1138
1176
|
runs.push(result);
|
|
1139
1177
|
}
|
|
@@ -1206,26 +1244,48 @@ async function mailRun(ctx, one, n, fakes, layout) {
|
|
|
1206
1244
|
await faux.close();
|
|
1207
1245
|
}
|
|
1208
1246
|
}
|
|
1209
|
-
/**
|
|
1210
|
-
*
|
|
1211
|
-
*
|
|
1212
|
-
async function
|
|
1247
|
+
/** One run of a feed case: its fake feeds started from the case's fixture, the trigger's URLs (filled from the case's
|
|
1248
|
+
* parameters, as the apply fills them) routed to them before the apply makes the trigger, the run started as the
|
|
1249
|
+
* package's trigger starts it (runOnce), then the fakes closed: runs never share one. */
|
|
1250
|
+
async function feedRun(ctx, one, n, fakes) {
|
|
1251
|
+
const fixture = one.feed;
|
|
1252
|
+
const source = filledSource(ctx.pkg, fixture.trigger, one.parameters);
|
|
1253
|
+
const urls = Array.isArray(source?.urls) ? source.urls.filter((url) => typeof url === "string") : [];
|
|
1254
|
+
if (!urls.length)
|
|
1255
|
+
throw new ApiFailure(`the package's trigger ${fixture.trigger} names no feed URL with the case's parameters`);
|
|
1256
|
+
const feeds = await caseFeeds(fixture, urls, typeof source?.items === "string" ? source.items : undefined);
|
|
1257
|
+
ctx.feedRoutes.route = feeds.route;
|
|
1258
|
+
try {
|
|
1259
|
+
return await runOnce(ctx, one, n, fakes, undefined, feeds);
|
|
1260
|
+
}
|
|
1261
|
+
finally {
|
|
1262
|
+
ctx.feedRoutes.route = undefined;
|
|
1263
|
+
await feeds.close();
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
/** The run of an email or feed case's trigger: its first poll waited on at the apply, on what the fake held then (the
|
|
1267
|
+
* history), then the case's new message or item delivered (`deliver`, given the trigger as it reads), and the trigger's
|
|
1268
|
+
* own next time come on the eval's clock, so its poll (or its schedule) fires through the engine's path; the run is its
|
|
1269
|
+
* firing's. `hint`: what to add when it starts none. */
|
|
1270
|
+
async function triggerRun(ctx, name, agentId, triggerId, deliver, hint) {
|
|
1213
1271
|
const { api, options } = ctx;
|
|
1214
|
-
const
|
|
1215
|
-
const
|
|
1216
|
-
const
|
|
1272
|
+
const read = () => api("GET", `/triggers/${encodeURIComponent(triggerId)}`).then((answered) => expectOk(`reading the package's trigger ${name}`, answered));
|
|
1273
|
+
const firings = async () => expectOk(`reading the firings of ${name}`, await api("GET", `/triggers/${encodeURIComponent(triggerId)}/firings`)).firings ?? [];
|
|
1274
|
+
const deadline = Date.now() + (options.queueTimeoutMs ?? QUEUE_TIMEOUT_MS);
|
|
1275
|
+
// Its first poll takes its start (the apply kicks it, and answers once it has or at FIRST_POLL_WAIT_MS, if slower): the
|
|
1276
|
+
// case's mail or item goes in only once that poll has read, or it would be part of the start and fire nothing, and the
|
|
1277
|
+
// clock moves only once that poll has set the next time, or the poll's next time would be a tick past the clock's.
|
|
1278
|
+
let trigger = await read();
|
|
1279
|
+
while (trigger.last_check === null && trigger.enabled === true && Date.now() < deadline) {
|
|
1280
|
+
options.signal?.throwIfAborted();
|
|
1281
|
+
await sleep(100);
|
|
1282
|
+
trigger = await read();
|
|
1283
|
+
}
|
|
1217
1284
|
const known = new Set((await firings()).map((f) => String(f.key)));
|
|
1218
|
-
|
|
1219
|
-
// The new message arrives where the trigger watches: its source's mailbox (INBOX by default).
|
|
1220
|
-
const watched = isObject(trigger.source) && typeof trigger.source.mailbox === "string" ? trigger.source.mailbox : "INBOX";
|
|
1221
|
-
if (fixture.message)
|
|
1222
|
-
seed(mail.faux, mail.layout, watched, fixture.message);
|
|
1223
|
-
// What the account holds before the run: what it adds or moves is read against this.
|
|
1224
|
-
const before = snapshot(mail.faux);
|
|
1285
|
+
deliver(trigger);
|
|
1225
1286
|
if (typeof trigger.next_at !== "string")
|
|
1226
|
-
throw new ApiFailure(`the package's trigger ${
|
|
1287
|
+
throw new ApiFailure(`the package's trigger ${name} has no next time to fire at${isObject(trigger.disabled) ? ` (it is off: ${String(trigger.disabled.detail ?? trigger.disabled.reason)})` : ""}`);
|
|
1227
1288
|
ctx.clock.to(Date.parse(trigger.next_at));
|
|
1228
|
-
const deadline = Date.now() + (options.queueTimeoutMs ?? QUEUE_TIMEOUT_MS);
|
|
1229
1289
|
for (;;) {
|
|
1230
1290
|
options.signal?.throwIfAborted();
|
|
1231
1291
|
const fresh = (await firings()).filter((f) => !known.has(String(f.key)));
|
|
@@ -1233,25 +1293,25 @@ async function triggerRun(ctx, one, agentId, triggerId, mail) {
|
|
|
1233
1293
|
if (started) {
|
|
1234
1294
|
ctx.made.runs.add(String(started.run_id));
|
|
1235
1295
|
// Off at once, before the run is waited on or graded: a repeating schedule (or a second message) would start
|
|
1236
|
-
// another paid run on the same fake
|
|
1237
|
-
expectOk(`turning off the package's trigger ${
|
|
1238
|
-
return
|
|
1296
|
+
// another paid run on the same fake, which no report counts and which changes what the graders read.
|
|
1297
|
+
expectOk(`turning off the package's trigger ${name} after its run started`, await api("PATCH", `/triggers/${encodeURIComponent(triggerId)}`, { enabled: false }));
|
|
1298
|
+
return String(started.run_id);
|
|
1239
1299
|
}
|
|
1240
1300
|
const failed = fresh.find((f) => f.status === "failed");
|
|
1241
1301
|
if (failed)
|
|
1242
|
-
throw new ApiFailure(`the package's trigger ${
|
|
1302
|
+
throw new ApiFailure(`the package's trigger ${name} fired and its run was refused: ${String(failed.error ?? "no reason given")}`);
|
|
1243
1303
|
if (Date.now() > deadline) {
|
|
1244
1304
|
const last = (await read()).last_check;
|
|
1245
1305
|
const check = isObject(last) ? last : undefined;
|
|
1246
1306
|
const said = fresh.flatMap((f) => (typeof f.reason === "string" ? [f.reason] : []));
|
|
1247
|
-
throw new ApiFailure(`the package's trigger ${
|
|
1307
|
+
throw new ApiFailure(`the package's trigger ${name} started no run of ${agentId} within ${Math.round((options.queueTimeoutMs ?? QUEUE_TIMEOUT_MS) / 1000)} s of its time${check ? `; its last check: ${String(check.message)}` : ""}${said.length ? `; its firings: ${said.join(" ")}` : ""}${hint}`);
|
|
1248
1308
|
}
|
|
1249
1309
|
await sleep(200);
|
|
1250
1310
|
}
|
|
1251
1311
|
}
|
|
1252
1312
|
/** One run of a case: a fresh agent (so one run's learning never reaches the next), its notes, the run, its grades. An
|
|
1253
1313
|
* email case's run (`mail`) is its trigger's (triggerRun). */
|
|
1254
|
-
async function runOnce(ctx, one, n, fakes, mail) {
|
|
1314
|
+
async function runOnce(ctx, one, n, fakes, mail, feeds) {
|
|
1255
1315
|
const { api, pkg, options, made } = ctx;
|
|
1256
1316
|
const stopped = () => options.signal?.throwIfAborted();
|
|
1257
1317
|
await serverPins(ctx, one);
|
|
@@ -1262,7 +1322,9 @@ async function runOnce(ctx, one, n, fakes, mail) {
|
|
|
1262
1322
|
// every run. Left where the run before took it, a schedule's next time is a later day each run, with no mail of the case.
|
|
1263
1323
|
// A millisecond before it: a schedule's next time is strictly after the clock, so a case whose `now` is the schedule's
|
|
1264
1324
|
// own time (an evening digest's 18:00) fires for that time, not the next day's.
|
|
1265
|
-
|
|
1325
|
+
// An email or feed case's run is its one trigger's (readCases chose it): `via`, that trigger's name.
|
|
1326
|
+
const via = mail ? one.email.trigger : feeds ? one.feed.trigger : undefined;
|
|
1327
|
+
if (via !== undefined && one.now !== undefined)
|
|
1266
1328
|
ctx.clock?.set(instantOf(one.now) - 1);
|
|
1267
1329
|
// Approvals never, for the eval's own agent only: a run that stopped at its first ask would measure nothing. The
|
|
1268
1330
|
// package's default (ask, say, for a template whose tools cost money) is the owner's at install, and stays as it is;
|
|
@@ -1272,17 +1334,17 @@ async function runOnce(ctx, one, n, fakes, mail) {
|
|
|
1272
1334
|
made.agents.push(agentId);
|
|
1273
1335
|
// An eval's agent runs only the eval's runs: the package's triggers (a weekly schedule, say) would start paid runs of
|
|
1274
1336
|
// their own, into the fakes' logs, and outlive the eval. Each one the apply made is deleted at once.
|
|
1275
|
-
// An email case's run is its one trigger's
|
|
1337
|
+
// An email or feed case's run is its one trigger's: that one stays, until the run is read.
|
|
1276
1338
|
let kept;
|
|
1277
1339
|
for (const id of Array.isArray(applied.trigger_ids) ? applied.trigger_ids.map(String) : []) {
|
|
1278
|
-
if (
|
|
1340
|
+
if (via !== undefined && !kept && expectOk(`reading the package's trigger ${id}`, await api("GET", `/triggers/${encodeURIComponent(id)}`)).name === via)
|
|
1279
1341
|
kept = id;
|
|
1280
1342
|
else
|
|
1281
1343
|
made.triggers.add(id);
|
|
1282
1344
|
}
|
|
1283
1345
|
await deleteTriggers(api, made, true);
|
|
1284
|
-
if (
|
|
1285
|
-
throw new ApiFailure(`the apply made no trigger named ${
|
|
1346
|
+
if (via !== undefined && !kept)
|
|
1347
|
+
throw new ApiFailure(`the apply made no trigger named ${via}`);
|
|
1286
1348
|
if (kept)
|
|
1287
1349
|
made.triggers.add(kept);
|
|
1288
1350
|
const agent = expectOk(`reading the agent ${agentId}`, await api("GET", `/agents/${encodeURIComponent(agentId)}`));
|
|
@@ -1297,21 +1359,35 @@ async function runOnce(ctx, one, n, fakes, mail) {
|
|
|
1297
1359
|
// The case's fakes, for this run's agent alone, before its run can be claimed.
|
|
1298
1360
|
ctx.fakes.set(agentId, { ...(one.web !== undefined ? { web: one.web } : {}), ...(one.now !== undefined ? { now: new Date(instantOf(one.now)) } : {}), ...(one.monid !== undefined ? { monid: one.monid } : {}), ...(mail ? { email: { imap: mail.faux.imap, smtp: mail.faux.smtp, kind: mail.layout } } : {}) });
|
|
1299
1361
|
let runId;
|
|
1300
|
-
let
|
|
1301
|
-
if (
|
|
1362
|
+
let fired;
|
|
1363
|
+
if (via !== undefined && kept) {
|
|
1302
1364
|
// A trigger the package ships off is turned on for the eval's run: its start is taken then, on the history.
|
|
1303
|
-
if (expectOk(`reading the package's trigger ${
|
|
1304
|
-
expectOk(`turning on the package's trigger ${
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1365
|
+
if (expectOk(`reading the package's trigger ${via}`, await api("GET", `/triggers/${encodeURIComponent(kept)}`)).enabled !== true)
|
|
1366
|
+
expectOk(`turning on the package's trigger ${via}`, await api("PATCH", `/triggers/${encodeURIComponent(kept)}`, { enabled: true }));
|
|
1367
|
+
if (mail) {
|
|
1368
|
+
const fixture = one.email;
|
|
1369
|
+
let before;
|
|
1370
|
+
runId = await triggerRun(ctx, via, agentId, kept, (trigger) => {
|
|
1371
|
+
// The new message arrives where the trigger watches: its source's mailbox (INBOX by default).
|
|
1372
|
+
const watched = isObject(trigger.source) && typeof trigger.source.mailbox === "string" ? trigger.source.mailbox : "INBOX";
|
|
1373
|
+
if (fixture.message)
|
|
1374
|
+
seed(mail.faux, mail.layout, watched, fixture.message);
|
|
1375
|
+
// What the account holds before the run: what it adds or moves is read against this.
|
|
1376
|
+
before = snapshot(mail.faux);
|
|
1377
|
+
}, fixture.message ? " (its accept rules may leave the case's message)" : "");
|
|
1378
|
+
fired = { mailbox: () => mailboxAfter(mail.faux, mail.layout, before) };
|
|
1379
|
+
}
|
|
1380
|
+
else {
|
|
1381
|
+
runId = await triggerRun(ctx, via, agentId, kept, () => feeds.deliver(), " (its accept rules may leave the case's item)");
|
|
1382
|
+
fired = {};
|
|
1383
|
+
}
|
|
1308
1384
|
}
|
|
1309
1385
|
else
|
|
1310
1386
|
runId = await startRun(ctx, agentId, { input: runInput(one.input, one.fields), ...(one.maxCostUsd !== undefined ? { max_cost_usd: one.maxCostUsd } : {}) }, "starting the run");
|
|
1311
1387
|
// A run started is paid for: whatever fails after this (a read, a grade) still gives it a result, with its cost where
|
|
1312
1388
|
// the server says it, so the case's total never drops it.
|
|
1313
1389
|
try {
|
|
1314
|
-
return await ranOnce(ctx, one, n, fakes, agent, agentId, runId, used,
|
|
1390
|
+
return await ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, fired);
|
|
1315
1391
|
}
|
|
1316
1392
|
catch (error) {
|
|
1317
1393
|
if (!(error instanceof ApiFailure))
|
|
@@ -1326,8 +1402,9 @@ async function runOnce(ctx, one, n, fakes, mail) {
|
|
|
1326
1402
|
}
|
|
1327
1403
|
}
|
|
1328
1404
|
/** The started run `runId` of `agentId` waited on, read and graded; its calls on the saved servers `used` gave its needs
|
|
1329
|
-
* ({toolkit: server}) named on the package's toolkits;
|
|
1330
|
-
|
|
1405
|
+
* ({toolkit: server}) named on the package's toolkits; a run its trigger started (`fired`) graded on the input it was
|
|
1406
|
+
* given, an email run's fake mailbox read once it has ended. */
|
|
1407
|
+
async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, fired) {
|
|
1331
1408
|
const { api, options } = ctx;
|
|
1332
1409
|
const stopped = () => options.signal?.throwIfAborted();
|
|
1333
1410
|
const ended = await waitRun(api, runId, Date.now() + (options.runTimeoutMs ?? RUN_TIMEOUT_MS), options.signal, options.queueTimeoutMs);
|
|
@@ -1336,7 +1413,7 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, after) {
|
|
|
1336
1413
|
await settle(ctx, runId, ended.status);
|
|
1337
1414
|
// Its metrics once it has ended (a cancelled run's end writes them too), before the eval's server can go.
|
|
1338
1415
|
const metrics = await metricsOf(api, agentId, options.signal);
|
|
1339
|
-
const mailbox =
|
|
1416
|
+
const mailbox = fired?.mailbox ? await fired.mailbox() : undefined;
|
|
1340
1417
|
stopped();
|
|
1341
1418
|
const result = isObject(view.result) ? view.result : {};
|
|
1342
1419
|
const harness = isObject(agent.definition) && typeof agent.definition.harness === "string" ? agent.definition.harness : "pi";
|
|
@@ -1354,8 +1431,8 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, after) {
|
|
|
1354
1431
|
};
|
|
1355
1432
|
stopped();
|
|
1356
1433
|
const base = { run: n, agent_id: agentId, run_id: runId, status: ended.status, cost_usd: costOf(view), answer: record.answer, calls: record.calls, mcp_calls: record.mcpCalls, created_at: typeof view.created_at === "string" ? view.created_at : null, ended_at: typeof view.ended_at === "string" ? view.ended_at : null, metrics, ...(mailbox ? { mailbox_after: mailbox.after } : {}) };
|
|
1357
|
-
// The grader's task: the input the run was given, an email run's its trigger's (the payload in its tag).
|
|
1358
|
-
const task =
|
|
1434
|
+
// The grader's task: the input the run was given, an email or feed run's its trigger's (the payload in its tag).
|
|
1435
|
+
const task = fired ? inputMessage(view.input ?? {}) : inputMessage(runInput(one.input, one.fields));
|
|
1359
1436
|
// Waiting on its person's answer (an ask_person question, a tool call's approval) is where such a run stops, and is
|
|
1360
1437
|
// graded; paused at its cap, or stopped, it did not get there.
|
|
1361
1438
|
const pending = isObject(view.pending) && typeof view.pending.kind === "string" ? view.pending.kind : undefined;
|
package/dist/templates.d.ts
CHANGED
|
@@ -175,11 +175,21 @@ export declare const TRIGGER_NOT_SET_UP_YET: Readonly<Record<string, readonly st
|
|
|
175
175
|
export declare const notSetUpYet: (kind: unknown, code: string) => boolean;
|
|
176
176
|
/** What an apply says of a composio trigger it skipped (notSetUpYet): which trigger, and the refusal's own words. */
|
|
177
177
|
export declare function composioTriggerSkipped(packageName: string, trigger: Json, why: string): string;
|
|
178
|
+
/** Whether a feed trigger, its parameters filled, reads no feed: its urls one whole array parameter the apply was given
|
|
179
|
+
* empty. An apply skips it, never itself, as it skips a github trigger with GitHub not connected (a warning under
|
|
180
|
+
* triggers.<i>): the agent stands. */
|
|
181
|
+
export declare const feedLeftEmpty: (trigger: Json) => boolean;
|
|
182
|
+
/** What an apply says of a feed trigger it skipped (feedLeftEmpty): which, and the parameter to set. `declared` is the
|
|
183
|
+
* package's own urls ("${parameters.status_feeds}"). */
|
|
184
|
+
export declare function feedTriggerEmpty(packageName: string, trigger: Json, declared: unknown): string;
|
|
178
185
|
/** Where the owner makes a composio trigger an apply skipped, once what refused it is fixed. */
|
|
179
186
|
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.";
|
|
180
187
|
/** What an apply says of a github trigger it skipped because GitHub is not connected here: what to do, and what the
|
|
181
188
|
* trigger would then run on, in the package's own words ("Code review runs on each pull request to acme/widgets."). */
|
|
182
189
|
export declare const githubTriggerUnconnected: (packageName: string, source: Json) => string;
|
|
190
|
+
/** The source of the package's trigger `name`, filled from the apply's `parameters` as an apply fills it (each parameter
|
|
191
|
+
* left out given its default): a template eval reads the feed URLs its case's trigger will read before it applies. */
|
|
192
|
+
export declare function filledSource(p: Package, name: string, parameters: Json): Json | undefined;
|
|
183
193
|
/** One entry of a package's folder, as readdirSync's withFileTypes gives it. */
|
|
184
194
|
export type PackageEntry = {
|
|
185
195
|
name: string;
|
package/dist/templates.js
CHANGED
|
@@ -152,10 +152,10 @@ export class PackageError extends Error {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
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),
|
|
156
|
-
* trigger's. */
|
|
157
|
-
const FILTERED_KINDS = ["github", "webhook", "composio"];
|
|
158
|
-
/** A github, webhook or
|
|
155
|
+
* sends every trigger of a project to one URL is filtered to the owner's own repository by them), a composio
|
|
156
|
+
* trigger's, and a feed trigger's (the pull requests of one author, say). */
|
|
157
|
+
const FILTERED_KINDS = ["github", "webhook", "composio", "feed"];
|
|
158
|
+
/** A github, webhook, composio or feed source split at its where conditions' `in` values, the one place a parameter may fill it: `ins`, each
|
|
159
159
|
* condition's list, and `rest`, the source without them. */
|
|
160
160
|
function whereIns(source) {
|
|
161
161
|
const ins = [];
|
|
@@ -195,6 +195,16 @@ export function composioTriggerSkipped(packageName, trigger, why) {
|
|
|
195
195
|
const source = isObject(trigger.source) ? trigger.source : {};
|
|
196
196
|
return `The ${packageName} template's trigger ${String(trigger.name)} (Composio ${String(source.event)} on ${String(source.server)}) was not made: ${why}`;
|
|
197
197
|
}
|
|
198
|
+
/** Whether a feed trigger, its parameters filled, reads no feed: its urls one whole array parameter the apply was given
|
|
199
|
+
* empty. An apply skips it, never itself, as it skips a github trigger with GitHub not connected (a warning under
|
|
200
|
+
* triggers.<i>): the agent stands. */
|
|
201
|
+
export const feedLeftEmpty = (trigger) => isObject(trigger.source) && trigger.source.kind === "feed" && Array.isArray(trigger.source.urls) && !trigger.source.urls.length;
|
|
202
|
+
/** What an apply says of a feed trigger it skipped (feedLeftEmpty): which, and the parameter to set. `declared` is the
|
|
203
|
+
* package's own urls ("${parameters.status_feeds}"). */
|
|
204
|
+
export function feedTriggerEmpty(packageName, trigger, declared) {
|
|
205
|
+
const named = (typeof declared === "string" ? [...declared.matchAll(PLACEHOLDER)][0]?.[1] : undefined) ?? "its feeds parameter";
|
|
206
|
+
return `The ${packageName} template's feed trigger ${String(trigger.name)} was not made: no feeds given in ${named}. Apply again with ${named} set to the feeds it should read.`;
|
|
207
|
+
}
|
|
198
208
|
/** Where the owner makes a composio trigger an apply skipped, once what refused it is fixed. */
|
|
199
209
|
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.";
|
|
200
210
|
/** What an apply says of a github trigger it skipped because GitHub is not connected here: what to do, and what the
|
|
@@ -243,8 +253,20 @@ const triggerFilled = (trigger, given) => {
|
|
|
243
253
|
// parameter's type (an integer config field gets an integer).
|
|
244
254
|
if (isObject(trigger.source) && trigger.source.kind === "composio" && isObject(trigger.source.config))
|
|
245
255
|
out.source = { ...out.source, config: inputFilled(trigger.source.config, given) };
|
|
256
|
+
// A feed trigger's urls as one placeholder alone take the array its parameter names, whole; a list's URLs are text.
|
|
257
|
+
if (isObject(trigger.source) && trigger.source.kind === "feed" && typeof trigger.source.urls === "string")
|
|
258
|
+
out.source = { ...out.source, urls: typedFilled(trigger.source.urls, given) };
|
|
246
259
|
return out;
|
|
247
260
|
};
|
|
261
|
+
/** The source of the package's trigger `name`, filled from the apply's `parameters` as an apply fills it (each parameter
|
|
262
|
+
* left out given its default): a template eval reads the feed URLs its case's trigger will read before it applies. */
|
|
263
|
+
export function filledSource(p, name, parameters) {
|
|
264
|
+
const trigger = p.triggers.find((one) => one.name === name);
|
|
265
|
+
if (!trigger)
|
|
266
|
+
return undefined;
|
|
267
|
+
const filledOne = triggerFilled(trigger, applyBodyOf(p, { parameters }).parameters);
|
|
268
|
+
return isObject(filledOne.source) ? filledOne.source : undefined;
|
|
269
|
+
}
|
|
248
270
|
/** An mcp entry's `pin` read: by tool, each one of the entry's `tools`, its arguments checked by the one rule every pin
|
|
249
271
|
* is (tool-plane.ts pinIssues, on the tool's gate name), text in it may hold `${parameters.<name>}` (checked with the
|
|
250
272
|
* other placeholders). Each problem is told through `bad`; a tool whose pin reads is kept. */
|
|
@@ -717,11 +739,12 @@ export function readPackage(from) {
|
|
|
717
739
|
bad(MANIFEST, `\${parameters.${used}} names no parameter`);
|
|
718
740
|
}
|
|
719
741
|
// 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
|
|
721
|
-
// config values (what Composio watches for it: the owner's repository, team or label)
|
|
722
|
-
//
|
|
723
|
-
//
|
|
724
|
-
//
|
|
742
|
+
// github, webhook, composio or feed trigger's where `in` values (the repository it takes, say), a composio trigger's
|
|
743
|
+
// config values (what Composio watches for it: the owner's repository, team or label), and a feed trigger's urls (a
|
|
744
|
+
// placeholder inside a URL, or the whole list as one naming an array parameter); a trigger's other settings, a
|
|
745
|
+
// composio trigger's server and event and a feed trigger's every_s, items and id among them, are the package's own,
|
|
746
|
+
// checked here. A parameter that sets a time has a default, so the schedule the package ships is checked here too; one
|
|
747
|
+
// a where, a composio config or a feed's urls take is required or has a default, so the trigger never fills empty.
|
|
725
748
|
triggers.forEach((trigger, i) => {
|
|
726
749
|
if (!isObject(trigger))
|
|
727
750
|
return;
|
|
@@ -730,12 +753,13 @@ export function readPackage(from) {
|
|
|
730
753
|
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])
|
|
731
754
|
: key === "source" && timed && isObject(value) ? Object.entries(value).filter(([k]) => !SCHEDULE_FIELDS.includes(k)).map(([k, v]) => [`source.${k}`, v])
|
|
732
755
|
: 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) ?
|
|
734
|
-
: key === "
|
|
735
|
-
:
|
|
756
|
+
: key === "source" && filtered && isObject(value) && value.kind === "feed" ? Object.entries(whereIns(value).rest).filter(([k]) => k !== "urls").map(([k, v]) => [`source.${k}`, v])
|
|
757
|
+
: key === "source" && filtered && isObject(value) ? [[key, whereIns(value).rest]]
|
|
758
|
+
: key === "enabled" && typeof value === "string" ? []
|
|
759
|
+
: [[key, value]]);
|
|
736
760
|
for (const [at, value] of fixed)
|
|
737
761
|
for (const [used] of strings(value).flatMap((text) => [...text.matchAll(PLACEHOLDER)]))
|
|
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
|
|
762
|
+
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, composio or feed trigger's where in values, a composio trigger's config values, a feed trigger's urls, or an mcp pin's values`);
|
|
739
763
|
// enabled is true, false, or one boolean parameter with a default, filled at apply (triggerFilled): the trigger is on
|
|
740
764
|
// or off by the owner's answer, and by the package's default when the apply leaves it out.
|
|
741
765
|
if (typeof trigger.enabled === "string") {
|
|
@@ -755,6 +779,24 @@ export function readPackage(from) {
|
|
|
755
779
|
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`);
|
|
756
780
|
}
|
|
757
781
|
}
|
|
782
|
+
// A feed's urls: a list whose URLs may hold placeholders, or one placeholder alone naming an array-of-strings
|
|
783
|
+
// parameter, filled whole; each parameter they name required or with a default, so the trigger never reads none.
|
|
784
|
+
if (isObject(trigger.source) && trigger.source.kind === "feed") {
|
|
785
|
+
const urls = trigger.source.urls;
|
|
786
|
+
if (typeof urls === "string") {
|
|
787
|
+
const rule = `triggers[${i}].source.urls is a list of URLs, or one placeholder alone, "\${parameters.<name>}", naming an array parameter of strings`;
|
|
788
|
+
const whole = WHOLE.exec(urls);
|
|
789
|
+
const spec = whole && Object.hasOwn(fields, whole[1]) ? fields[whole[1]] : undefined;
|
|
790
|
+
if (!whole)
|
|
791
|
+
bad(MANIFEST, rule);
|
|
792
|
+
else if (spec && (spec.type !== "array" || !isObject(spec.items) || spec.items.type !== "string"))
|
|
793
|
+
bad(MANIFEST, `${rule}: parameters.${whole[1]} is ${spec.type === "array" ? "an array of other than strings" : `a ${String(spec.type)}`}`);
|
|
794
|
+
}
|
|
795
|
+
for (const used of new Set(strings(urls).flatMap((text) => [...text.matchAll(PLACEHOLDER)].map((m) => m[1])))) {
|
|
796
|
+
if (Object.hasOwn(fields, used) && !parameters.required?.includes(used) && fields[used].default === undefined)
|
|
797
|
+
bad(MANIFEST, `parameters.${used} is used in triggers[${i}].source.urls, so it is required or has a default: a feed trigger filled empty reads no feed`);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
758
800
|
if (isObject(trigger.source) && trigger.source.kind === "composio") {
|
|
759
801
|
for (const used of new Set(strings(trigger.source.config).flatMap((text) => [...text.matchAll(PLACEHOLDER)].map((m) => m[1])))) {
|
|
760
802
|
if (Object.hasOwn(fields, used) && !parameters.required?.includes(used) && fields[used].default === undefined)
|
|
@@ -824,11 +866,12 @@ export function readPackage(from) {
|
|
|
824
866
|
const caseDoc = own.includes("case.yaml") ? parseDocument(text(`${at}/case.yaml`), { uniqueKeys: true }) : undefined;
|
|
825
867
|
if (caseDoc?.errors.length)
|
|
826
868
|
bad(`${at}/case.yaml`, "is not YAML");
|
|
827
|
-
// An email case's run is its trigger's, on the trigger's input (template-eval.ts): its prompt.md has no body.
|
|
828
|
-
const
|
|
869
|
+
// An email or feed case's run is its trigger's, on the trigger's input (template-eval.ts): its prompt.md has no body.
|
|
870
|
+
const caseJs = !!caseDoc && !caseDoc.errors.length && isObject(caseDoc.toJS()) ? caseDoc.toJS() : undefined;
|
|
871
|
+
const triggeredCase = caseJs !== undefined && (caseJs.email !== undefined || caseJs.feed !== undefined);
|
|
829
872
|
if (!own.includes("prompt.md"))
|
|
830
873
|
bad(at, "has no prompt.md");
|
|
831
|
-
else if (!
|
|
874
|
+
else if (!triggeredCase && !front(`${at}/prompt.md`, false)?.body.trim())
|
|
832
875
|
bad(`${at}/prompt.md`, "its body is empty: the body is the run's input");
|
|
833
876
|
const graders = own.filter((p) => p.startsWith("graders/"));
|
|
834
877
|
if (!graders.length)
|
|
@@ -867,6 +910,14 @@ export function readPackage(from) {
|
|
|
867
910
|
// hangs on the value (a pattern, a bound, a choice) is the apply's, on the value given. Its type, and whether the
|
|
868
911
|
// inputs name the field at all, are checked here.
|
|
869
912
|
const sampled = (field) => {
|
|
913
|
+
// A feed's URL filled from a parameter with no default holds a sample, no URL: the apply checks the value given.
|
|
914
|
+
const url = /^triggers\.(\d+)\.source\.urls(?:\[(\d+)\])?$/.exec(field);
|
|
915
|
+
if (url) {
|
|
916
|
+
const urls = p.triggers[Number(url[1])]?.source?.urls;
|
|
917
|
+
const named = (text) => strings(text).flatMap((one) => [...one.matchAll(PLACEHOLDER)].map((m) => m[1]));
|
|
918
|
+
const used = typeof urls === "string" ? named(urls) : Array.isArray(urls) && url[2] !== undefined ? named(urls[Number(url[2])]) : [];
|
|
919
|
+
return used.some((name) => Object.hasOwn(fields, name) && fields[name].default === undefined);
|
|
920
|
+
}
|
|
870
921
|
const at = /^triggers\.(\d+)\.target\.input\.([^.]+)/.exec(field);
|
|
871
922
|
const target = at ? p.triggers[Number(at[1])]?.target : undefined;
|
|
872
923
|
const value = at && isObject(target) && isObject(target.input) ? target.input[at[2]] : undefined;
|
|
@@ -878,8 +929,15 @@ export function readPackage(from) {
|
|
|
878
929
|
const at = /^triggers\.(\d+)\.enabled$/.exec(field);
|
|
879
930
|
return !!at && typeof p.triggers[Number(at[1])]?.enabled === "string";
|
|
880
931
|
};
|
|
932
|
+
// A feed trigger a parameter's default leaves with no feeds is skipped at apply (feedLeftEmpty), never refused: so its
|
|
933
|
+
// urls are not refused here. Every other field of it is checked, as the apply makes it once the owner sets urls.
|
|
934
|
+
const skippedAtApply = (field) => {
|
|
935
|
+
const at = /^triggers\.(\d+)\.source\.urls(?:\[\d+\])?$/.exec(field);
|
|
936
|
+
const trigger = at ? made.triggers[Number(at[1])] : undefined;
|
|
937
|
+
return !!trigger && feedLeftEmpty(trigger);
|
|
938
|
+
};
|
|
881
939
|
for (const issue of madeTriggerIssues(made.triggers, 0, p.inputSchema))
|
|
882
|
-
if (!saidEnabled(issue.field) && (["wrong_type", "not_allowed", "missing"].includes(issue.reason) || !sampled(issue.field)))
|
|
940
|
+
if (!saidEnabled(issue.field) && !skippedAtApply(issue.field) && (["wrong_type", "not_allowed", "missing"].includes(issue.reason) || !sampled(issue.field)))
|
|
883
941
|
bad(MANIFEST, `${issue.field.replace(/^triggers\.(\d+)\./, "triggers[$1].")}: ${issue.message}`);
|
|
884
942
|
if (problems.length)
|
|
885
943
|
throw new PackageError(dir, [...new Set(problems)]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EntryLike } from "./timeline.js";
|
|
2
2
|
/** What fired a trigger: its definition's kind, never what its payload says. */
|
|
3
|
-
export declare const TRIGGER_SOURCES: readonly ["schedule", "webhook", "slack", "github", "composio", "email"];
|
|
3
|
+
export declare const TRIGGER_SOURCES: readonly ["schedule", "webhook", "slack", "github", "composio", "email", "feed"];
|
|
4
4
|
export type TriggerSource = (typeof TRIGGER_SOURCES)[number];
|
|
5
5
|
/** How a trigger's Timeline row names its source: "<label> <trigger>: <its first line>". */
|
|
6
6
|
export declare const TRIGGER_LABELS: Readonly<Record<TriggerSource, string>>;
|
package/dist/timeline/origin.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { obj, str } from "./util.js";
|
|
2
2
|
/** What fired a trigger: its definition's kind, never what its payload says. */
|
|
3
|
-
export const TRIGGER_SOURCES = ["schedule", "webhook", "slack", "github", "composio", "email"];
|
|
3
|
+
export const TRIGGER_SOURCES = ["schedule", "webhook", "slack", "github", "composio", "email", "feed"];
|
|
4
4
|
/** How a trigger's Timeline row names its source: "<label> <trigger>: <its first line>". */
|
|
5
|
-
export const TRIGGER_LABELS = { schedule: "Schedule", webhook: "Webhook", slack: "Slack", github: "GitHub", composio: "Composio", email: "Email" };
|
|
5
|
+
export const TRIGGER_LABELS = { schedule: "Schedule", webhook: "Webhook", slack: "Slack", github: "GitHub", composio: "Composio", email: "Email", feed: "Feed" };
|
|
6
6
|
const REASONS = new Set(["cap_raised", "approval", "handed_back", "output_retry"]);
|
|
7
7
|
const SOURCES = new Set(TRIGGER_SOURCES);
|
|
8
8
|
/** An entry kind that names the origin of the next user entry in its conversation whose text is exactly `text`: written
|
|
@@ -76,7 +76,7 @@ export type TriggerAdapter = {
|
|
|
76
76
|
/** Whether each firing of a trigger of `source` starts its own run, its last run active or not (a webhook that takes
|
|
77
77
|
* only the events it names). Default false: a firing while the last run is active is skipped. */
|
|
78
78
|
concurrent?(source: Source): boolean;
|
|
79
|
-
/** For a clock source that polls (the email
|
|
79
|
+
/** For a clock source that polls (the email and feed triggers): what it finds when its time comes, read from outside the server.
|
|
80
80
|
* The engine fires each event it returns through the path a pushed event takes (`takes`, `concurrent`,
|
|
81
81
|
* max_active_runs, the day-kept keys, a run per event), records no `missed` row for a time it was not there for, and
|
|
82
82
|
* keeps the poll's cursor once its firings are recorded. A poll with no cursor is where its trigger starts watching:
|
|
@@ -95,14 +95,16 @@ export type PollContext = {
|
|
|
95
95
|
credentials(): Promise<unknown>;
|
|
96
96
|
};
|
|
97
97
|
/** One event a poll found: a pushed event's fields; `cursor`, the settings to keep once it and every event before it are
|
|
98
|
-
* recorded; `left`, when it is recorded as skipped and starts nothing, why (in words). */
|
|
98
|
+
* recorded (read by the engine of the last event it records alone, so a source may make it when asked); `left`, when it is recorded as skipped and starts nothing, why (in words). */
|
|
99
99
|
export type PolledEvent = PushEvent & {
|
|
100
100
|
cursor: Record<string, string>;
|
|
101
101
|
left?: string;
|
|
102
102
|
};
|
|
103
103
|
/** What a poll found: `check`, said on the trigger as its last check; `refused`, the source's credentials refused (the
|
|
104
|
-
* engine turns the trigger off at the third in a row, `detail` its words); `
|
|
105
|
-
* (a
|
|
104
|
+
* engine turns the trigger off at the third in a row, `detail` its words); `stop`, the source can't be read again as it
|
|
105
|
+
* is (every feed a feed trigger reads gone): the engine turns the trigger off now, its source unreadable, `detail` its
|
|
106
|
+
* words; `note`, one history line that starts no run (a first poll's, a reset's); `events`, oldest first; `cursor`, the
|
|
107
|
+
* settings to keep once every event is recorded. */
|
|
106
108
|
export type PollResult = {
|
|
107
109
|
check: {
|
|
108
110
|
ok: boolean;
|
|
@@ -111,6 +113,9 @@ export type PollResult = {
|
|
|
111
113
|
refused?: {
|
|
112
114
|
detail: string;
|
|
113
115
|
};
|
|
116
|
+
stop?: {
|
|
117
|
+
detail: string;
|
|
118
|
+
};
|
|
114
119
|
note?: string;
|
|
115
120
|
events?: PolledEvent[];
|
|
116
121
|
cursor?: Record<string, string>;
|
package/dist/trigger-adapters.js
CHANGED
|
@@ -3,4 +3,5 @@ import { schedule } from "./trigger-schedule.js";
|
|
|
3
3
|
import { github } from "./trigger-github.js";
|
|
4
4
|
import { webhook } from "./trigger-webhook.js";
|
|
5
5
|
import { email } from "./trigger-email.js";
|
|
6
|
-
|
|
6
|
+
import { feed } from "./trigger-feed.js";
|
|
7
|
+
export const TRIGGER_ADAPTERS = [schedule, webhook, github, composio, email, feed];
|