@parcha/agentrun-serve 0.1.0-beta.39 → 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.
Files changed (173) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/README.md +129 -16
  3. package/dist/api-only.d.ts +3 -1
  4. package/dist/api-only.js +4 -2
  5. package/dist/api-token.d.ts +30 -0
  6. package/dist/api-token.js +89 -0
  7. package/dist/cli.js +19 -5
  8. package/dist/composio-made.d.ts +54 -0
  9. package/dist/composio-made.js +83 -0
  10. package/dist/composio-preset.d.ts +16 -8
  11. package/dist/composio-preset.js +106 -43
  12. package/dist/composio-triggers.d.ts +7 -2
  13. package/dist/composio-triggers.js +13 -7
  14. package/dist/computer-attach.d.ts +29 -11
  15. package/dist/computer-attach.js +141 -47
  16. package/dist/computer-keys.d.ts +4 -0
  17. package/dist/computer-keys.js +5 -0
  18. package/dist/computers.d.ts +11 -1
  19. package/dist/computers.js +21 -12
  20. package/dist/console/assets/index-C3gNPz58.css +1 -0
  21. package/dist/console/assets/index-COGhx_2Z.js +711 -0
  22. package/dist/console/index.html +2 -2
  23. package/dist/decisions.js +9 -2
  24. package/dist/email/account.d.ts +0 -1
  25. package/dist/email/account.js +3 -3
  26. package/dist/email/answer.d.ts +5 -0
  27. package/dist/email/answer.js +35 -0
  28. package/dist/email/mail.js +19 -26
  29. package/dist/email/names.d.ts +30 -0
  30. package/dist/email/names.js +34 -0
  31. package/dist/email/routes.d.ts +1 -0
  32. package/dist/email/routes.js +1 -1
  33. package/dist/email/tools.d.ts +11 -4
  34. package/dist/email/tools.js +91 -46
  35. package/dist/eval-feed.d.ts +26 -0
  36. package/dist/eval-feed.js +68 -0
  37. package/dist/eval-mailbox.d.ts +5 -2
  38. package/dist/eval-mailbox.js +14 -6
  39. package/dist/exa-keyless.d.ts +1 -1
  40. package/dist/exa-keyless.js +1 -1
  41. package/dist/feed/feed-faux.d.ts +62 -0
  42. package/dist/feed/feed-faux.js +123 -0
  43. package/dist/feed/fetch.d.ts +41 -0
  44. package/dist/feed/fetch.js +128 -0
  45. package/dist/feed/parse.d.ts +41 -0
  46. package/dist/feed/parse.js +300 -0
  47. package/dist/learn/check.d.ts +3 -1
  48. package/dist/learn/check.js +57 -2
  49. package/dist/learn/compile.d.ts +3 -2
  50. package/dist/learn/compile.js +7 -6
  51. package/dist/learn/promote.d.ts +25 -14
  52. package/dist/learn/promote.js +32 -14
  53. package/dist/learned-nodes.d.ts +21 -4
  54. package/dist/learned-nodes.js +21 -8
  55. package/dist/learned-workflow.d.ts +3 -3
  56. package/dist/learned-workflow.js +14 -5
  57. package/dist/learning-cost.d.ts +17 -8
  58. package/dist/learning-cost.js +12 -4
  59. package/dist/local-models.d.ts +7 -1
  60. package/dist/local-models.js +11 -5
  61. package/dist/mcp-oauth.d.ts +15 -1
  62. package/dist/mcp-oauth.js +39 -5
  63. package/dist/mcp-pin-first.d.ts +4 -2
  64. package/dist/mcp-pin-first.js +4 -3
  65. package/dist/mcp-servers-store.d.ts +58 -5
  66. package/dist/mcp-servers-store.js +136 -17
  67. package/dist/mcp.d.ts +2 -2
  68. package/dist/mcp.js +2 -2
  69. package/dist/observation/http.d.ts +4 -1
  70. package/dist/observation/http.js +5 -4
  71. package/dist/openapi.d.ts +1 -1
  72. package/dist/openapi.js +63 -27
  73. package/dist/port-models.d.ts +4 -1
  74. package/dist/port-models.js +1 -0
  75. package/dist/print.d.ts +6 -3
  76. package/dist/print.js +4 -2
  77. package/dist/refusal-words.d.ts +3 -0
  78. package/dist/refusal-words.js +3 -0
  79. package/dist/run-labels.d.ts +23 -0
  80. package/dist/run-labels.js +79 -0
  81. package/dist/run-launch.d.ts +2 -0
  82. package/dist/run-launch.js +2 -0
  83. package/dist/run-secrets.js +12 -4
  84. package/dist/run-view.d.ts +3 -4
  85. package/dist/run-view.js +26 -24
  86. package/dist/runner/adapter-loop.d.ts +6 -2
  87. package/dist/runner/adapter-loop.js +136 -22
  88. package/dist/runner/adapter-run-spec.d.ts +5 -0
  89. package/dist/runner/adapter-run-spec.js +75 -32
  90. package/dist/runner/beside.d.ts +6 -3
  91. package/dist/runner/beside.js +9 -7
  92. package/dist/runner/cli-run-spec.js +33 -26
  93. package/dist/runner/conformance/harness.js +69 -14
  94. package/dist/runner/conformance/subject.d.ts +4 -1
  95. package/dist/runner/journal-kinds.d.ts +22 -0
  96. package/dist/runner/journal-kinds.js +39 -0
  97. package/dist/runner/main.d.ts +1 -1
  98. package/dist/runner/main.js +2 -2
  99. package/dist/runner/mcp-claim.d.ts +3 -0
  100. package/dist/runner/mcp-claim.js +1 -1
  101. package/dist/runner/mcp-run.d.ts +4 -0
  102. package/dist/runner/mcp-run.js +5 -3
  103. package/dist/runner/model-route.d.ts +7 -3
  104. package/dist/runner/model-route.js +24 -9
  105. package/dist/runner/promotion.d.ts +16 -8
  106. package/dist/runner/promotion.js +178 -55
  107. package/dist/runner/workflow-first.d.ts +6 -5
  108. package/dist/runner/workflow-first.js +9 -7
  109. package/dist/runs-over-store.js +5 -2
  110. package/dist/sdk/runs.d.ts +7 -1
  111. package/dist/sdk/runs.js +19 -6
  112. package/dist/secret-cut.js +3 -1
  113. package/dist/secrets.js +3 -1
  114. package/dist/server.d.ts +27 -2
  115. package/dist/server.js +181 -56
  116. package/dist/store/dialect.d.ts +6 -0
  117. package/dist/store/dialect.js +2 -0
  118. package/dist/store/index.d.ts +1 -1
  119. package/dist/store/postgres/connection.d.ts +11 -5
  120. package/dist/store/postgres/connection.js +44 -17
  121. package/dist/store/postgres/dialect.js +6 -0
  122. package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
  123. package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
  124. package/dist/store/postgres/store.d.ts +7 -3
  125. package/dist/store/postgres/store.js +1 -0
  126. package/dist/store/schema.d.ts +9 -0
  127. package/dist/store/schema.js +26 -2
  128. package/dist/store/sqlite/connection.js +80 -8
  129. package/dist/store/sqlite/run-launch.d.ts +11 -0
  130. package/dist/store/sqlite/run-launch.js +8 -0
  131. package/dist/store/sqlite/run-patch.d.ts +2 -1
  132. package/dist/store/sqlite/run-patch.js +3 -2
  133. package/dist/store/sqlite/store.js +101 -26
  134. package/dist/store/sqlite/worker.d.ts +2 -0
  135. package/dist/store/sqlite/worker.js +13 -10
  136. package/dist/store/store.d.ts +53 -1
  137. package/dist/store-reads/journal.js +2 -1
  138. package/dist/store-reads/learning.d.ts +30 -13
  139. package/dist/store-reads/learning.js +130 -51
  140. package/dist/store-reads/runs.d.ts +4 -3
  141. package/dist/store-reads/runs.js +3 -2
  142. package/dist/store-view.js +4 -2
  143. package/dist/template-eval.d.ts +4 -0
  144. package/dist/template-eval.js +127 -50
  145. package/dist/templates.d.ts +24 -1
  146. package/dist/templates.js +129 -21
  147. package/dist/timeline/origin.d.ts +1 -1
  148. package/dist/timeline/origin.js +2 -2
  149. package/dist/tool-gate.d.ts +5 -3
  150. package/dist/tool-gate.js +5 -2
  151. package/dist/tools.d.ts +13 -0
  152. package/dist/tools.js +15 -10
  153. package/dist/trigger-adapter.d.ts +12 -36
  154. package/dist/trigger-adapters.js +2 -1
  155. package/dist/trigger-email.js +30 -77
  156. package/dist/trigger-feed.d.ts +12 -0
  157. package/dist/trigger-feed.js +371 -0
  158. package/dist/triggers.d.ts +27 -14
  159. package/dist/triggers.js +121 -80
  160. package/dist/webhooks.js +9 -5
  161. package/dist/workflow/decision-recovery.js +5 -2
  162. package/dist/workflow/decisions.d.ts +7 -0
  163. package/dist/workspace/computer-deps.d.ts +5 -1
  164. package/dist/workspace/computer-deps.js +2 -2
  165. package/dist/workspace/index.d.ts +1 -0
  166. package/dist/workspace/index.js +2 -0
  167. package/dist/workspace/resolve-computer.d.ts +32 -3
  168. package/dist/workspace/resolve-computer.js +47 -9
  169. package/launcher/agentrun-serve +6 -1
  170. package/package.json +10 -9
  171. package/templates/README.md +27 -2
  172. package/dist/console/assets/index-BNhZs-jp.css +0 -1
  173. package/dist/console/assets/index-BQv5aOGB.js +0 -700
@@ -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
- /** The run of an email case's trigger on `mail`: its start taken at the apply on the account as seeded (the history),
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
- * schedule) fires through the engine's path; the run is its firing's. */
1212
- async function triggerRun(ctx, one, agentId, triggerId, mail) {
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 fixture = one.email;
1215
- const read = () => api("GET", `/triggers/${encodeURIComponent(triggerId)}`).then((answered) => expectOk(`reading the package's trigger ${fixture.trigger}`, answered));
1216
- const firings = async () => expectOk(`reading the firings of ${fixture.trigger}`, await api("GET", `/triggers/${encodeURIComponent(triggerId)}/firings`)).firings ?? [];
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
- const trigger = await read();
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 ${fixture.trigger} has no next time to fire at${isObject(trigger.disabled) ? ` (it is off: ${String(trigger.disabled.detail ?? trigger.disabled.reason)})` : ""}`);
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 account, which no report counts and which changes what the graders read.
1237
- expectOk(`turning off the package's trigger ${fixture.trigger} after its run started`, await api("PATCH", `/triggers/${encodeURIComponent(triggerId)}`, { enabled: false }));
1238
- return { runId: String(started.run_id), before };
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 ${fixture.trigger} fired and its run was refused: ${String(failed.error ?? "no reason given")}`);
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 ${fixture.trigger} 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(" ")}` : ""}${fixture.message ? " (its accept rules may leave the case's message)" : ""}`);
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
- if (mail && one.now !== undefined)
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 (readCases chose it): that one stays, until the run is read.
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 (mail && !kept && expectOk(`reading the package's trigger ${id}`, await api("GET", `/triggers/${encodeURIComponent(id)}`)).name === one.email.trigger)
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 (mail && !kept)
1285
- throw new ApiFailure(`the apply made no trigger named ${one.email.trigger}`);
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 after;
1301
- if (mail && kept) {
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 ${one.email.trigger}`, await api("GET", `/triggers/${encodeURIComponent(kept)}`)).enabled !== true)
1304
- expectOk(`turning on the package's trigger ${one.email.trigger}`, await api("PATCH", `/triggers/${encodeURIComponent(kept)}`, { enabled: true }));
1305
- const started = await triggerRun(ctx, one, agentId, kept, mail);
1306
- runId = started.runId;
1307
- after = () => mailboxAfter(mail.faux, mail.layout, started.before);
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, after);
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; an email run's fake mailbox read once it has ended (`after`). */
1330
- async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, after) {
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 = after ? await after() : undefined;
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 = after ? inputMessage(view.input ?? {}) : inputMessage(runInput(one.input, one.fields));
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;
@@ -165,9 +165,31 @@ 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
+ /** 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;
185
+ /** Where the owner makes a composio trigger an apply skipped, once what refused it is fixed. */
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.";
168
187
  /** What an apply says of a github trigger it skipped because GitHub is not connected here: what to do, and what the
169
188
  * trigger would then run on, in the package's own words ("Code review runs on each pull request to acme/widgets."). */
170
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;
171
193
  /** One entry of a package's folder, as readdirSync's withFileTypes gives it. */
172
194
  export type PackageEntry = {
173
195
  name: string;
@@ -500,5 +522,6 @@ export declare function onServerName(name: string, servers: Readonly<Record<stri
500
522
  * another of the package's toolkits is never rewritten twice. */
501
523
  export declare function onServerNames(text: string, servers: Readonly<Record<string, string>>): string;
502
524
  /** `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). Nothing else of it names a server: its pins and allow are by tool. */
525
+ * names on the saved servers' (onServerNames), and each composio trigger's server, its need's toolkit, the saved server
526
+ * that need resolved to (onServerTrigger). Nothing else of it names a server: its pins and allow are by tool. */
504
527
  export declare function onServers(p: Package, servers: Readonly<Record<string, string>>): Package;