@parcha/agentrun-serve 0.1.0-beta.40 → 0.1.0-beta.42
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 +130 -0
- package/NOTICE +2 -0
- package/README.md +149 -21
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +3 -1
- 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/calendar/address.d.ts +49 -0
- package/dist/calendar/address.js +153 -0
- package/dist/calendar/fetch.d.ts +24 -0
- package/dist/calendar/fetch.js +146 -0
- package/dist/calendar/ics-faux.d.ts +39 -0
- package/dist/calendar/ics-faux.js +236 -0
- package/dist/calendar/labels.d.ts +3 -0
- package/dist/calendar/labels.js +61 -0
- package/dist/calendar/names.d.ts +52 -0
- package/dist/calendar/names.js +54 -0
- package/dist/calendar/parse.d.ts +108 -0
- package/dist/calendar/parse.js +625 -0
- package/dist/calendar/routes.d.ts +17 -0
- package/dist/calendar/routes.js +81 -0
- package/dist/calendar/tools.d.ts +23 -0
- package/dist/calendar/tools.js +124 -0
- package/dist/cli.js +22 -6
- 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/computer-record.d.ts +55 -0
- package/dist/computer-record.js +315 -0
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +15 -2
- package/dist/computers.d.ts +11 -1
- package/dist/computers.js +23 -26
- package/dist/console/assets/{index-B8Zn1Iqn.css → index-C3gNPz58.css} +1 -1
- package/dist/console/assets/index-DYJ_wj27.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 +72 -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 +42 -0
- package/dist/feed/parse.js +291 -0
- package/dist/feed/pointer.d.ts +2 -0
- package/dist/feed/pointer.js +17 -0
- package/dist/file-types.js +1 -0
- package/dist/host-command.d.ts +3 -0
- package/dist/host-command.js +18 -0
- package/dist/host.d.ts +3 -0
- package/dist/host.js +3 -0
- package/dist/learn/check.d.ts +17 -1
- package/dist/learn/check.js +240 -5
- package/dist/learn/compile.d.ts +48 -27
- package/dist/learn/compile.js +134 -101
- package/dist/learn/promote.d.ts +61 -5
- package/dist/learn/promote.js +12 -2
- 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/learning-setting.d.ts +23 -0
- package/dist/learning-setting.js +51 -0
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +3 -0
- package/dist/learning.d.ts +3 -2
- package/dist/learning.js +5 -3
- package/dist/mcp-oauth.d.ts +23 -1
- package/dist/mcp-oauth.js +46 -5
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +4 -3
- package/dist/mcp-private-hosts.d.ts +13 -0
- package/dist/mcp-private-hosts.js +16 -0
- 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.d.ts +1 -0
- package/dist/openapi.js +151 -21
- package/dist/print.d.ts +6 -3
- package/dist/print.js +4 -2
- package/dist/run-files.d.ts +6 -2
- package/dist/run-files.js +29 -7
- package/dist/run-labels.d.ts +23 -0
- package/dist/run-labels.js +79 -0
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-reads-over-store.d.ts +5 -1
- package/dist/run-reads-over-store.js +8 -4
- package/dist/run-recordings.d.ts +20 -0
- package/dist/run-recordings.js +133 -0
- package/dist/run-secrets.js +12 -4
- package/dist/runner/adapter-loop.d.ts +1 -1
- package/dist/runner/adapter-loop.js +94 -16
- package/dist/runner/adapter-run-spec.d.ts +19 -0
- package/dist/runner/adapter-run-spec.js +57 -36
- package/dist/runner/beside.d.ts +6 -3
- package/dist/runner/beside.js +9 -7
- package/dist/runner/cli-run-spec.js +41 -32
- package/dist/runner/conformance/harness.js +69 -14
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/feedback-round.d.ts +9 -25
- package/dist/runner/feedback-round.js +22 -40
- package/dist/runner/learning-end.d.ts +17 -7
- package/dist/runner/learning-end.js +79 -53
- package/dist/runner/main.d.ts +12 -1
- package/dist/runner/main.js +31 -4
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +6 -2
- 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 +44 -4
- package/dist/runner/promotion.js +323 -21
- package/dist/runner/reflect-hook.d.ts +5 -0
- package/dist/runner/reflect-hook.js +22 -14
- package/dist/runner/store-secrets.js +3 -1
- package/dist/runner/workflow-first.d.ts +6 -11
- package/dist/runner/workflow-first.js +16 -20
- package/dist/runs-over-store.d.ts +1 -1
- package/dist/runs-over-store.js +5 -2
- package/dist/sdk/runs.d.ts +7 -1
- package/dist/sdk/runs.js +21 -7
- package/dist/secret-cut.js +3 -1
- package/dist/secrets.js +5 -3
- package/dist/server.d.ts +31 -5
- package/dist/server.js +240 -61
- package/dist/store/agent-body.d.ts +5 -3
- package/dist/store/agent-body.js +14 -10
- 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.d.ts +1 -1
- package/dist/store-reads/learning.js +6 -1
- package/dist/store-reads/loop.d.ts +1 -0
- package/dist/store-reads/loop.js +14 -4
- package/dist/store-reads/runs.d.ts +4 -3
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +8 -2
- package/dist/template-eval.d.ts +11 -0
- package/dist/template-eval.js +177 -52
- package/dist/templates.d.ts +13 -1
- package/dist/templates.js +89 -18
- package/dist/timeline/computer.js +2 -1
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +11 -0
- 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 +420 -0
- package/dist/triggers.d.ts +2 -1
- package/dist/triggers.js +23 -5
- package/dist/validate.js +7 -2
- 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/computer-for-claim.d.ts +7 -0
- package/dist/workspace/computer-for-claim.js +12 -2
- package/dist/workspace/index.d.ts +1 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/paths.d.ts +4 -0
- package/dist/workspace/paths.js +9 -0
- package/dist/workspace/resolve-computer.d.ts +35 -4
- package/dist/workspace/resolve-computer.js +47 -9
- package/launcher/agentrun-serve +34 -22
- package/package.json +11 -9
- package/templates/README.md +38 -4
- package/dist/console/assets/index-Jbxjcmdp.js +0 -705
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { pointed } from "./feed/pointer.js";
|
|
2
|
+
import { ACCEPT_SCHEMA, acceptOf, acceptRefusal } from "./trigger-accept.js";
|
|
3
|
+
import { closedSchema, PAYLOAD_KEPT_BYTES, unknownSourceFields } from "./trigger-adapter.js";
|
|
4
|
+
import { MAX_EVERY_S, MIN_EVERY_S } from "./trigger-schedule.js";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
/** The most items one poll takes, across its feeds: the rest wait for the next. */
|
|
7
|
+
export const POLL_TAKES = 20;
|
|
8
|
+
/** The most feeds one trigger reads. */
|
|
9
|
+
export const MAX_FEEDS = 20;
|
|
10
|
+
/** How often a feed is read by default, in seconds. */
|
|
11
|
+
export const DEFAULT_EVERY_S = 900;
|
|
12
|
+
/** The keys a feed's seen set keeps at least (twice its feed's length when that is more). */
|
|
13
|
+
export const SEEN_KEPT = 1000;
|
|
14
|
+
/** The 404s in a row that stop a feed. */
|
|
15
|
+
const MISSING_TO_STOP = 3;
|
|
16
|
+
/** The feeds read at once. */
|
|
17
|
+
const READ_AT_ONCE = 4;
|
|
18
|
+
/** The one event a feed trigger's accept names. */
|
|
19
|
+
const EVENT = "item";
|
|
20
|
+
/** The trigger's own settings: its cursor and its last check (the engine's), no secret (public). */
|
|
21
|
+
const CURSOR = "cursor";
|
|
22
|
+
const LAST_CHECK = "last_check";
|
|
23
|
+
const URL_CHARS = 2000;
|
|
24
|
+
const POINTER = /^(\/([^~]|~[01])*)?$/;
|
|
25
|
+
const POINTER_CHARS = 300;
|
|
26
|
+
/** The most fields a JSON list's `fields` keeps of each item. */
|
|
27
|
+
const MAX_FIELDS = 50;
|
|
28
|
+
/** The source's own fields, checked: each issue through `bad`. Undefined when one does not read. */
|
|
29
|
+
function fieldsOf(value, bad) {
|
|
30
|
+
let failed = false;
|
|
31
|
+
const fail = (field, reason, message) => ((failed = true), bad(field, reason, message));
|
|
32
|
+
const urls = value.urls;
|
|
33
|
+
const rule = `urls is a list of 1 to ${MAX_FEEDS} feed URLs, each http or https, none twice`;
|
|
34
|
+
if (!Array.isArray(urls))
|
|
35
|
+
fail("urls", urls === undefined ? "missing" : "wrong_type", rule);
|
|
36
|
+
else if (urls.length < 1 || urls.length > MAX_FEEDS)
|
|
37
|
+
fail("urls", "invalid", rule);
|
|
38
|
+
else {
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
urls.forEach((url, i) => {
|
|
41
|
+
const why = urlProblem(url);
|
|
42
|
+
if (why)
|
|
43
|
+
fail(`urls[${i}]`, "invalid", why);
|
|
44
|
+
else if (seen.has(url))
|
|
45
|
+
fail(`urls[${i}]`, "duplicate", `urls[${i}] is ${url} again: each feed is read once`);
|
|
46
|
+
else
|
|
47
|
+
seen.add(url);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const every = value.every_s ?? DEFAULT_EVERY_S;
|
|
51
|
+
if (!Number.isSafeInteger(every) || every < MIN_EVERY_S || every > MAX_EVERY_S)
|
|
52
|
+
fail("every_s", "invalid", `every_s is a whole number of seconds, ${MIN_EVERY_S} to ${MAX_EVERY_S}`);
|
|
53
|
+
for (const name of ["items", "id", "updated"]) {
|
|
54
|
+
const pointer = value[name];
|
|
55
|
+
if (pointer === undefined)
|
|
56
|
+
continue;
|
|
57
|
+
const whole = name === "items";
|
|
58
|
+
if (typeof pointer !== "string" || pointer.length > POINTER_CHARS || !POINTER.test(pointer) || (!whole && !pointer)) {
|
|
59
|
+
if (name === "updated")
|
|
60
|
+
fail(name, "invalid", "updated is a JSON Pointer into a JSON list's item to the date it last changed (/updated_at): for a feed that is a JSON list");
|
|
61
|
+
else
|
|
62
|
+
fail(name, "invalid", whole ? `items is a JSON Pointer to a JSON list's array of items ("" for the whole document, /data/items): for a feed that is a JSON list` : `id is a JSON Pointer into a JSON list's item to its id (/id, /number): for a feed that is a JSON list`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const fields = value.fields;
|
|
66
|
+
if (fields !== undefined && (!Array.isArray(fields) || fields.length < 1 || fields.length > MAX_FIELDS || fields.some((one) => typeof one !== "string" || !one || one.length > POINTER_CHARS || !POINTER.test(one)))) {
|
|
67
|
+
fail("fields", "invalid", `fields is a list of 1 to ${MAX_FIELDS} JSON Pointers into a JSON list's item (/number, /user/login): the payload's item keeps only these, for a feed that is a JSON list`);
|
|
68
|
+
}
|
|
69
|
+
const accept = value.accept === undefined ? undefined : acceptOf(value.accept, fail);
|
|
70
|
+
accept?.forEach((rule, i) => {
|
|
71
|
+
if (rule.event !== EVENT)
|
|
72
|
+
fail(`accept[${i}].event`, "not_an_option", `A feed trigger's one event is "${EVENT}"`);
|
|
73
|
+
if (rule.actions !== undefined)
|
|
74
|
+
fail(`accept[${i}].actions`, "not_allowed", "A feed item has no action: take it by its fields with where");
|
|
75
|
+
});
|
|
76
|
+
if (failed)
|
|
77
|
+
return undefined;
|
|
78
|
+
return { kind: "feed", urls: urls, every_s: every, ...(value.items !== undefined ? { items: value.items } : {}), ...(value.id !== undefined ? { id: value.id } : {}), ...(value.updated !== undefined ? { updated: value.updated } : {}), ...(value.fields !== undefined ? { fields: value.fields } : {}), ...(accept ? { accept } : {}) };
|
|
79
|
+
}
|
|
80
|
+
/** Why `url` is no feed URL a trigger reads, or undefined: an http(s) URL, with no user or password in it. */
|
|
81
|
+
export function urlProblem(url) {
|
|
82
|
+
const words = "a feed URL is http or https, with no user or password in it";
|
|
83
|
+
if (typeof url !== "string" || !url || url.length > URL_CHARS)
|
|
84
|
+
return `${words}, at most ${URL_CHARS} characters`;
|
|
85
|
+
const at = URL.parse(url);
|
|
86
|
+
if (!at || (at.protocol !== "http:" && at.protocol !== "https:") || !at.hostname)
|
|
87
|
+
return `${words}: ${url.slice(0, 200)} is not`;
|
|
88
|
+
if (at.username || at.password)
|
|
89
|
+
return `${words}: ${at.host}'s holds one`;
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
/** The cursor kept, when it reads; else none (every feed starts). */
|
|
93
|
+
function cursorOf(text) {
|
|
94
|
+
if (!text)
|
|
95
|
+
return { feeds: {} };
|
|
96
|
+
try {
|
|
97
|
+
const value = JSON.parse(text);
|
|
98
|
+
return value && typeof value.feeds === "object" && value.feeds !== null && !Array.isArray(value.feeds) ? value : { feeds: {} };
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return { feeds: {} };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const hashed = (key) => createHash("sha256").update(key).digest("hex").slice(0, 16);
|
|
105
|
+
const iso = (ms) => (ms === null ? null : new Date(ms).toISOString());
|
|
106
|
+
const itemsWord = (n) => `${n} item${n === 1 ? "" : "s"}`;
|
|
107
|
+
/** `url` read on `reach` from its state's validators: its items, a 304, or what went wrong, in words. */
|
|
108
|
+
async function readOne(url, state, source, reach) {
|
|
109
|
+
const [{ readFeed, FeedRefused, FeedUnreachable }, { parseFeed, FeedUnreadable }] = await Promise.all([import("./feed/fetch.js"), import("./feed/parse.js")]);
|
|
110
|
+
// A feed with no seen set yet is read whole: its start is every item there now.
|
|
111
|
+
const last = state?.seen ? { ...(state.etag ? { etag: state.etag } : {}), ...(state.modified ? { modified: state.modified } : {}) } : {};
|
|
112
|
+
try {
|
|
113
|
+
const read = await readFeed(url, last, reach);
|
|
114
|
+
if (read.status === 304)
|
|
115
|
+
return { url, ok: true, changed: false };
|
|
116
|
+
if (!("body" in read))
|
|
117
|
+
return { url, ok: false, status: read.status, problem: `Couldn't read ${url}: HTTP ${read.status}.` };
|
|
118
|
+
try {
|
|
119
|
+
const feed = parseFeed(read.body, { ...(source.items !== undefined ? { items: source.items } : {}), ...(source.id !== undefined ? { id: source.id } : {}), ...(source.updated !== undefined ? { updated: source.updated } : {}) });
|
|
120
|
+
return { url, ok: true, changed: true, feed, validators: { ...(read.etag ? { etag: read.etag } : {}), ...(read.modified ? { modified: read.modified } : {}) } };
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (!(error instanceof FeedUnreadable))
|
|
124
|
+
throw error;
|
|
125
|
+
return { url, ok: false, status: 200, problem: `Couldn't read ${url}: ${error.message}.` };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (error instanceof FeedUnreachable)
|
|
130
|
+
return { url, ok: false, problem: `Couldn't reach ${url}: ${error.message}.` };
|
|
131
|
+
if (error instanceof FeedRefused)
|
|
132
|
+
return { url, ok: false, problem: `Couldn't read ${url}: ${error.message}.` };
|
|
133
|
+
return { url, ok: false, problem: `Couldn't read ${url}: ${String(error?.message ?? error).slice(0, 300)}.` };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/** `work` over `items`, at most `n` at once, in their order. */
|
|
137
|
+
async function pooled(items, n, work) {
|
|
138
|
+
const out = new Array(items.length);
|
|
139
|
+
let next = 0;
|
|
140
|
+
await Promise.all(Array.from({ length: Math.min(n, items.length) }, async () => {
|
|
141
|
+
for (let i = next++; i < items.length; i = next++)
|
|
142
|
+
out[i] = await work(items[i]);
|
|
143
|
+
}));
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
/** `state`'s seen set as a map, a missing date null. A set saved before dates were told apart (no \`dates\`) holds 0 for one:
|
|
147
|
+
* read as missing for a JSON list, whose items had no dates then; an RSS, Atom or JSON Feed item's 0 stays a number. */
|
|
148
|
+
const seenOf = (state, list) => new Map((state.seen ?? []).map(([key, at]) => [key, at === 0 && list && state.dates !== 2 ? null : at]));
|
|
149
|
+
/** One feed's items, oldest first: as it serves them reversed (a feed lists newest first), then by date when every one
|
|
150
|
+
* has one. Each key once (its first, the newest). */
|
|
151
|
+
function oldestFirst(items) {
|
|
152
|
+
const once = new Map();
|
|
153
|
+
for (const item of items)
|
|
154
|
+
if (!once.has(item.key))
|
|
155
|
+
once.set(item.key, item);
|
|
156
|
+
const reversed = [...once.values()].reverse();
|
|
157
|
+
const dated = (item) => item.updated ?? item.published;
|
|
158
|
+
return reversed.every((item) => dated(item) !== null) ? reversed.sort((a, b) => dated(a) - dated(b)) : reversed;
|
|
159
|
+
}
|
|
160
|
+
/** The payload an item fires with, within PAYLOAD_KEPT_BYTES: a JSON list's {id, link, title, item, update}, its raw item
|
|
161
|
+
* cut shallower until it fits; any other's {id, link, title, published, updated, author, summary, categories, feed,
|
|
162
|
+
* update}, its summary cut until it fits. */
|
|
163
|
+
function payloadOf(c, list, title, fields) {
|
|
164
|
+
const { item, update } = c;
|
|
165
|
+
if (list) {
|
|
166
|
+
// `fields`, when the source names some, keep only those of the item, before the cap.
|
|
167
|
+
const raw = fields ? keeping(item.raw, fields) : item.raw;
|
|
168
|
+
const whole = { id: item.id, link: item.link, title: item.title, item: raw, update };
|
|
169
|
+
if (fits(whole))
|
|
170
|
+
return whole;
|
|
171
|
+
for (const [depth, chars] of [[3, 2000], [3, 300], [2, 2000], [2, 300], [1, 300], [1, 100]]) {
|
|
172
|
+
const cut = { ...whole, item: shallow(raw, depth, chars), item_truncated: true };
|
|
173
|
+
if (fits(cut))
|
|
174
|
+
return cut;
|
|
175
|
+
}
|
|
176
|
+
return { id: item.id, link: item.link, title: item.title?.slice(0, 300) ?? null, item: null, item_truncated: true, update };
|
|
177
|
+
}
|
|
178
|
+
const whole = { id: item.id, link: item.link, title: item.title, published: iso(item.published), updated: iso(item.updated), author: item.author, summary: item.summary, categories: item.categories, feed: { title, url: c.url }, update };
|
|
179
|
+
if (fits(whole))
|
|
180
|
+
return whole;
|
|
181
|
+
for (const chars of [1000, 300]) {
|
|
182
|
+
const cut = { ...whole, id: clipped(item.id, chars), link: clipped(item.link, chars), title: clipped(item.title, chars), author: clipped(item.author, chars), summary: clipped(item.summary, chars), categories: item.categories.slice(0, 10).map((one) => clipped(one, 100)), feed: { title: clipped(title, 200), url: c.url } };
|
|
183
|
+
if (fits(cut))
|
|
184
|
+
return cut;
|
|
185
|
+
}
|
|
186
|
+
return { id: clipped(item.id, 200), link: clipped(item.link, 200), title: clipped(item.title, 200), published: iso(item.published), updated: iso(item.updated), author: null, summary: null, categories: [], feed: { title: null, url: c.url }, update };
|
|
187
|
+
}
|
|
188
|
+
/** `raw` with only the values at `pointers` kept, each at its own place (a list's kept entries compacted). Every
|
|
189
|
+
* container is built bare and every key set as an own property, so no name (\`__proto__\` too) reaches a prototype; only
|
|
190
|
+
* own keys of the item are read. */
|
|
191
|
+
function keeping(raw, pointers) {
|
|
192
|
+
const bare = (like) => (Array.isArray(like) ? [] : Object.create(null));
|
|
193
|
+
const own = (from, key) => (from !== null && typeof from === "object" && Object.hasOwn(from, key) ? from[key] : undefined);
|
|
194
|
+
const out = bare(raw);
|
|
195
|
+
for (const pointer of pointers) {
|
|
196
|
+
const value = pointed(raw, pointer);
|
|
197
|
+
if (value === undefined)
|
|
198
|
+
continue;
|
|
199
|
+
const keys = pointer.split("/").slice(1).map((part) => part.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
200
|
+
let from = raw;
|
|
201
|
+
let into = out;
|
|
202
|
+
keys.forEach((key, i) => {
|
|
203
|
+
const source = own(from, key);
|
|
204
|
+
if (i === keys.length - 1)
|
|
205
|
+
Object.defineProperty(into, key, { value, enumerable: true, writable: true, configurable: true });
|
|
206
|
+
else {
|
|
207
|
+
if (!Object.hasOwn(into, key))
|
|
208
|
+
Object.defineProperty(into, key, { value: bare(source), enumerable: true, writable: true, configurable: true });
|
|
209
|
+
into = into[key];
|
|
210
|
+
}
|
|
211
|
+
from = source;
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
const dense = (value) => (Array.isArray(value) ? value.filter(() => true).map(dense) : value !== null && typeof value === "object" ? Object.fromEntries(Object.entries(value).map(([k, v]) => [k, dense(v)])) : value);
|
|
215
|
+
return dense(out);
|
|
216
|
+
}
|
|
217
|
+
const fits = (value) => Buffer.byteLength(JSON.stringify(value), "utf8") <= PAYLOAD_KEPT_BYTES;
|
|
218
|
+
const clipped = (text, n) => (text !== null && text.length > n ? `${text.slice(0, n - 1)}…` : text);
|
|
219
|
+
/** `value` with its objects and lists `depth` deep (deeper ones dropped), a list's first 20, its strings `chars` long. */
|
|
220
|
+
function shallow(value, depth, chars) {
|
|
221
|
+
if (typeof value === "string")
|
|
222
|
+
return clipped(value, chars);
|
|
223
|
+
if (value === null || typeof value !== "object")
|
|
224
|
+
return value;
|
|
225
|
+
if (depth <= 0)
|
|
226
|
+
return undefined;
|
|
227
|
+
if (Array.isArray(value))
|
|
228
|
+
return value.slice(0, 20).map((one) => shallow(one, depth - 1, chars)).filter((one) => one !== undefined);
|
|
229
|
+
return Object.fromEntries(Object.entries(value).map(([key, one]) => [key, shallow(one, depth - 1, chars)]).filter(([, one]) => one !== undefined));
|
|
230
|
+
}
|
|
231
|
+
/** One poll of `source`'s feeds from `cursor`. */
|
|
232
|
+
async function poll(source, reach, cursor) {
|
|
233
|
+
// Each feed the source reads now, with the state it had (none for one an edit added); a removed one's goes.
|
|
234
|
+
const states = Object.fromEntries(source.urls.flatMap((url) => (cursor.feeds[url] ? [[url, { ...cursor.feeds[url] }]] : [])));
|
|
235
|
+
const live = source.urls.filter((url) => !states[url]?.stopped);
|
|
236
|
+
const reads = await pooled(live, READ_AT_ONCE, (url) => readOne(url, states[url], source, reach));
|
|
237
|
+
const problems = [];
|
|
238
|
+
const started = [];
|
|
239
|
+
const candidates = [];
|
|
240
|
+
/** Each feed read and parsed: its items oldest first, for its seen set. */
|
|
241
|
+
const present = new Map();
|
|
242
|
+
const lists = new Map();
|
|
243
|
+
for (const read of reads) {
|
|
244
|
+
const state = (states[read.url] ??= {});
|
|
245
|
+
if (!read.ok) {
|
|
246
|
+
state.missing = read.status === 404 ? (state.missing ?? 0) + 1 : 0;
|
|
247
|
+
if (read.status === 410)
|
|
248
|
+
state.stopped = "is gone (HTTP 410)";
|
|
249
|
+
else if (read.status === 404 && state.missing >= MISSING_TO_STOP)
|
|
250
|
+
state.stopped = `answered HTTP 404 ${MISSING_TO_STOP} checks running`;
|
|
251
|
+
if (!state.stopped)
|
|
252
|
+
problems.push(read.problem);
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
state.missing = 0;
|
|
256
|
+
if (!read.changed)
|
|
257
|
+
continue;
|
|
258
|
+
const { feed, validators } = read;
|
|
259
|
+
if (feed.title)
|
|
260
|
+
state.title = feed.title;
|
|
261
|
+
delete state.etag;
|
|
262
|
+
delete state.modified;
|
|
263
|
+
Object.assign(state, validators);
|
|
264
|
+
const items = oldestFirst(feed.items);
|
|
265
|
+
lists.set(read.url, feed.list);
|
|
266
|
+
if (!state.seen) {
|
|
267
|
+
// Its start: every item there now is seen, and starts nothing.
|
|
268
|
+
state.seen = items.map((item) => [hashed(item.key), item.updated]);
|
|
269
|
+
state.dates = 2;
|
|
270
|
+
started.push({ url: read.url, count: items.length });
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
present.set(read.url, items);
|
|
274
|
+
const seen = seenOf(state, feed.list);
|
|
275
|
+
const fresh = [];
|
|
276
|
+
for (const item of items) {
|
|
277
|
+
const was = seen.get(hashed(item.key));
|
|
278
|
+
if (was === undefined)
|
|
279
|
+
fresh.push({ url: read.url, item, update: false, at: item.updated ?? item.published, n: 0 });
|
|
280
|
+
else if (item.updated !== null && (was === null ? !feed.list : item.updated > was))
|
|
281
|
+
fresh.push({ url: read.url, item, update: true, at: item.updated, n: 0 });
|
|
282
|
+
}
|
|
283
|
+
candidates.push(fresh);
|
|
284
|
+
}
|
|
285
|
+
// The oldest POLL_TAKES across the feeds: each feed's in its order, the oldest head first (one with no date at once).
|
|
286
|
+
const taken = [];
|
|
287
|
+
const heads = candidates.map(() => 0);
|
|
288
|
+
while (taken.length < POLL_TAKES) {
|
|
289
|
+
let pick = -1;
|
|
290
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
291
|
+
const head = candidates[i][heads[i]];
|
|
292
|
+
if (!head)
|
|
293
|
+
continue;
|
|
294
|
+
const best = pick < 0 ? undefined : candidates[pick][heads[pick]];
|
|
295
|
+
if (!best || (head.at ?? -Infinity) < (best.at ?? -Infinity))
|
|
296
|
+
pick = i;
|
|
297
|
+
}
|
|
298
|
+
if (pick < 0)
|
|
299
|
+
break;
|
|
300
|
+
taken.push({ ...candidates[pick][heads[pick]], n: taken.length });
|
|
301
|
+
heads[pick]++;
|
|
302
|
+
}
|
|
303
|
+
const waiting = candidates.flat().length - taken.length;
|
|
304
|
+
// The feeds with an item not taken this poll: read whole at the next.
|
|
305
|
+
const left = new Set(candidates.flatMap((list, i) => list.slice(heads[i]).map((c) => c.url)));
|
|
306
|
+
const marks = new Map(taken.map((c) => [`${c.url}\n${c.item.key}`, c]));
|
|
307
|
+
/** The cursor once the first `upTo` items taken are recorded: each feed's seen set with them marked, the items it
|
|
308
|
+
* serves now moved to its end, trimmed; a feed with an item not marked yet keeps no validators, so its next read is
|
|
309
|
+
* whole. An item new to its feed and not marked is not in its set; one updated and not marked keeps its last time. */
|
|
310
|
+
const cursorAfter = (upTo) => {
|
|
311
|
+
const feeds = {};
|
|
312
|
+
for (const url of source.urls) {
|
|
313
|
+
const state = states[url];
|
|
314
|
+
if (!state)
|
|
315
|
+
continue;
|
|
316
|
+
const items = present.get(url);
|
|
317
|
+
if (!items || !state.seen) {
|
|
318
|
+
feeds[url] = state;
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
const list = lists.get(url) ?? false;
|
|
322
|
+
const seen = seenOf(state, list);
|
|
323
|
+
for (const item of items) {
|
|
324
|
+
const key = hashed(item.key);
|
|
325
|
+
const was = seen.get(key);
|
|
326
|
+
const mark = marks.get(`${url}\n${item.key}`);
|
|
327
|
+
seen.delete(key);
|
|
328
|
+
if (mark && mark.n < upTo)
|
|
329
|
+
seen.set(key, item.updated);
|
|
330
|
+
// A JSON list's item first seen with no date takes the one it gains, fired on never.
|
|
331
|
+
else if (was !== undefined)
|
|
332
|
+
seen.set(key, was === null && list ? item.updated : was);
|
|
333
|
+
}
|
|
334
|
+
const whole = !left.has(url) && !taken.slice(upTo).some((c) => c.url === url);
|
|
335
|
+
const { etag, modified, ...rest } = state;
|
|
336
|
+
feeds[url] = { ...rest, dates: 2, ...(whole && etag ? { etag } : {}), ...(whole && modified ? { modified } : {}), seen: [...seen.entries()].slice(-Math.max(SEEN_KEPT, 2 * items.length)) };
|
|
337
|
+
}
|
|
338
|
+
return { [CURSOR]: JSON.stringify({ feeds }) };
|
|
339
|
+
};
|
|
340
|
+
const name = (url) => states[url]?.title ?? url;
|
|
341
|
+
const named = (urls) => (urls.length === 1 ? name(urls[0]) : `${urls.length} feeds`);
|
|
342
|
+
const events = taken.map((c) => {
|
|
343
|
+
const body = payloadOf(c, lists.get(c.url) ?? false, states[c.url]?.title ?? null, source.fields);
|
|
344
|
+
const key = `${c.url}\n${c.item.key}${c.item.updated !== null ? `\n${iso(c.item.updated)}` : ""}`;
|
|
345
|
+
// Its cursor made only when the engine asks for it (the last event it records, when the poll is cut short): never one
|
|
346
|
+
// whole cursor per item taken.
|
|
347
|
+
return { key, text: JSON.stringify(body), attrs: { title: (c.item.title ?? c.item.link ?? c.item.key).slice(0, 200), feed: c.url }, event: EVENT, body, get cursor() { return cursorAfter(c.n + 1); } };
|
|
348
|
+
});
|
|
349
|
+
const stopped = source.urls.filter((url) => states[url]?.stopped);
|
|
350
|
+
const said = stopped.map((url) => `${url} ${states[url].stopped}: it is no longer read; edit the trigger's urls to drop or fix it.`);
|
|
351
|
+
const parts = [];
|
|
352
|
+
if (started.length)
|
|
353
|
+
parts.push(`Watching ${named(started.map((s) => s.url))}.`);
|
|
354
|
+
const okUrls = reads.filter((r) => r.ok && !started.some((s) => s.url === r.url)).map((r) => r.url);
|
|
355
|
+
if (okUrls.length)
|
|
356
|
+
parts.push(`Read ${named(okUrls)}: ${taken.length} new${waiting > 0 ? `, ${waiting} more at the next check` : ""}.`);
|
|
357
|
+
const note = started.length ? (() => {
|
|
358
|
+
const count = started.reduce((sum, s) => sum + s.count, 0);
|
|
359
|
+
const which = named(started.map((s) => s.url));
|
|
360
|
+
return count ? `Watching ${which} from now: the ${itemsWord(count)} already there won't start runs.` : `Watching ${which} from now: ${started.length === 1 ? "it holds" : "they hold"} no items yet.`;
|
|
361
|
+
})() : undefined;
|
|
362
|
+
const result = {
|
|
363
|
+
check: { ok: !problems.length && !stopped.length, message: [...parts, ...problems, ...said].join(" ") || "Read nothing." },
|
|
364
|
+
...(note ? { note } : {}),
|
|
365
|
+
...(events.length ? { events } : {}),
|
|
366
|
+
cursor: cursorAfter(taken.length),
|
|
367
|
+
};
|
|
368
|
+
if (stopped.length === source.urls.length) {
|
|
369
|
+
result.stop = { detail: `Every feed it reads has stopped: ${stopped.map((url) => `${url} ${states[url].stopped}`).join("; ")}. Edit its urls, then turn it on again.` };
|
|
370
|
+
}
|
|
371
|
+
return result;
|
|
372
|
+
}
|
|
373
|
+
export const feed = {
|
|
374
|
+
id: "feed",
|
|
375
|
+
label: "feed trigger",
|
|
376
|
+
delivery: "clock",
|
|
377
|
+
owner: false,
|
|
378
|
+
// Each item is its own: one run's answer is never handed to the next.
|
|
379
|
+
previousResult: false,
|
|
380
|
+
settings: { scope: "trigger", fields: { [CURSOR]: { public: true }, [LAST_CHECK]: { public: true } } },
|
|
381
|
+
describe: `{kind: "feed", urls: ["https://..."], every_s?: ${DEFAULT_EVERY_S}, items?: "/data/items", id?: "/id", updated?: "/updated_at", fields?: ["/number", "/title"], accept?: [{event: "${EVENT}", where?}]}`,
|
|
382
|
+
fires: "each new or updated item in its feeds (`feed`: RSS, Atom, JSON Feed or a JSON list), read every every_s seconds, that its `accept` takes",
|
|
383
|
+
firedBy: "`feed`: an item new to one of its feeds, or one seen before with a later updated time, its key from the trigger, the feed's URL, the item's key and its updated time.",
|
|
384
|
+
schemas: [
|
|
385
|
+
closedSchema({ kind: { const: "feed" }, urls: { type: "array", minItems: 1, maxItems: MAX_FEEDS, uniqueItems: true, items: { type: "string", minLength: 1, maxLength: URL_CHARS, pattern: "^[Hh][Tt][Tt][Pp][Ss]?://" }, description: `The feeds it reads, 1 to ${MAX_FEEDS}, each an http or https URL: RSS, Atom, JSON Feed, or a JSON list (an API's array of objects). Plain http is read on a public address alone.` } }, {
|
|
386
|
+
every_s: { type: "integer", minimum: MIN_EVERY_S, maximum: MAX_EVERY_S, default: DEFAULT_EVERY_S, description: "How often it reads its feeds, in seconds, on a grid from the epoch." },
|
|
387
|
+
items: { type: "string", maxLength: POINTER_CHARS, pattern: "^(/([^~]|~[01])*)?$", description: "For a JSON list: a JSON Pointer to its array of items. Absent: the whole document." },
|
|
388
|
+
id: { type: "string", minLength: 1, maxLength: POINTER_CHARS, pattern: "^/([^~]|~[01])*$", description: "For a JSON list: a JSON Pointer into each item to its id. Absent: /id." },
|
|
389
|
+
updated: { type: "string", minLength: 1, maxLength: POINTER_CHARS, pattern: "^/([^~]|~[01])*$", description: "For a JSON list: a JSON Pointer into each item to the date it last changed (/updated_at). An item whose date moves on fires again with update: true. Absent: a JSON list's item fires once." },
|
|
390
|
+
fields: { type: "array", minItems: 1, maxItems: MAX_FIELDS, items: { type: "string", minLength: 1, maxLength: POINTER_CHARS, pattern: "^/([^~]|~[01])*$" }, description: "For a JSON list: JSON Pointers into each item; the payload's item keeps only these, each at its own place, before the payload's size cap (a pull request that is large whole fits). Absent: the whole item, cut shallower when it is over the cap." },
|
|
391
|
+
accept: { ...ACCEPT_SCHEMA, description: `The items that start a run: each rule's event is "${EVENT}", its where reads the payload (/title, /link, /feed/url; a JSON list's /item/...). None: every item.` },
|
|
392
|
+
}),
|
|
393
|
+
],
|
|
394
|
+
sent: [
|
|
395
|
+
closedSchema({ kind: { const: "feed" }, urls: { type: "array", minItems: 1, maxItems: MAX_FEEDS, items: { type: "string" } }, every_s: { type: "integer", minimum: MIN_EVERY_S, maximum: MAX_EVERY_S } }, { items: { type: "string" }, id: { type: "string" }, updated: { type: "string" }, fields: { type: "array", items: { type: "string" } }, accept: ACCEPT_SCHEMA }),
|
|
396
|
+
],
|
|
397
|
+
parse(value, _now, bad, issues) {
|
|
398
|
+
issues.push(...unknownSourceFields(value, ["kind", "urls", "every_s", "items", "id", "updated", "fields", "accept"]));
|
|
399
|
+
return fieldsOf(value, bad);
|
|
400
|
+
},
|
|
401
|
+
wellFormed: (source) => fieldsOf(source, () => { }) !== undefined,
|
|
402
|
+
clock(source) {
|
|
403
|
+
const step = source.every_s * 1000;
|
|
404
|
+
return { next: (after) => (Math.floor(after / step) + 1) * step, latest: (first, now) => first + Math.floor((now - first) / step) * step, step };
|
|
405
|
+
},
|
|
406
|
+
problem: (source) => (typeof source.every_s === "number" && (source.every_s < MIN_EVERY_S || source.every_s > MAX_EVERY_S) ? `every_s ${source.every_s} is not ${MIN_EVERY_S} to ${MAX_EVERY_S} seconds` : undefined),
|
|
407
|
+
// Each item is its own work: a run per item, max_active_runs bounding how many at once.
|
|
408
|
+
concurrent: () => true,
|
|
409
|
+
takes: (source, event) => {
|
|
410
|
+
const rules = source.accept;
|
|
411
|
+
return rules ? acceptRefusal(rules, event.event, event.body) : undefined;
|
|
412
|
+
},
|
|
413
|
+
async poll(source, ctx) {
|
|
414
|
+
const reach = (await ctx.credentials());
|
|
415
|
+
if (!reach)
|
|
416
|
+
return { check: { ok: false, message: "This server reads no feeds." } };
|
|
417
|
+
return poll(source, reach, cursorOf(ctx.setting(CURSOR)));
|
|
418
|
+
},
|
|
419
|
+
title: (attrs) => attrs.title,
|
|
420
|
+
};
|
package/dist/triggers.d.ts
CHANGED
|
@@ -476,7 +476,8 @@ export declare class Triggers {
|
|
|
476
476
|
* history line; one it leaves, skipped and said; one its accept does not take, an ignored row kept for its day; any
|
|
477
477
|
* other due, and driven), its cursor kept once they are, then its last check, and at the REFUSALS_TO_STOPth refused
|
|
478
478
|
* sign-in in a row the trigger turned off. A poll that throws is a failed check. */
|
|
479
|
-
/** False when an edit of its source while it polled dropped what it found
|
|
479
|
+
/** False when an edit of its source while it polled dropped what it found, or landed while its cursor was written and
|
|
480
|
+
* left its stop and its check unwritten (the edit's poll comes after it); else true. */
|
|
480
481
|
private polled;
|
|
481
482
|
/** A firing taken from due to its end: skipped when its trigger's last run is active, else its run started (or its
|
|
482
483
|
* message sent). A failed try keeps it due under the backoff table, or ends it failed. Each step reads the trigger and
|
package/dist/triggers.js
CHANGED
|
@@ -716,7 +716,8 @@ export class Triggers {
|
|
|
716
716
|
* history line; one it leaves, skipped and said; one its accept does not take, an ignored row kept for its day; any
|
|
717
717
|
* other due, and driven), its cursor kept once they are, then its last check, and at the REFUSALS_TO_STOPth refused
|
|
718
718
|
* sign-in in a row the trigger turned off. A poll that throws is a failed check. */
|
|
719
|
-
/** False when an edit of its source while it polled dropped what it found
|
|
719
|
+
/** False when an edit of its source while it polled dropped what it found, or landed while its cursor was written and
|
|
720
|
+
* left its stop and its check unwritten (the edit's poll comes after it); else true. */
|
|
720
721
|
async polled(trigger, adapter, nominalAt, now) {
|
|
721
722
|
const settings = this.deps.settings(adapter.id);
|
|
722
723
|
// Turned on again while it polled (off and on): its cursor was forgotten, and nothing this poll found is its own.
|
|
@@ -743,7 +744,9 @@ export class Triggers {
|
|
|
743
744
|
if (result.note)
|
|
744
745
|
await this.record(current, { key: firingKey(by, trigger.id, `note\n${second(nominalAt)}`), by, nominalAt: at, status: "skipped", reason: result.note });
|
|
745
746
|
const events = result.events ?? [];
|
|
746
|
-
|
|
747
|
+
// The last event recorded: the cursor is its once they are (each event's is read only here, once: a source may make
|
|
748
|
+
// it when asked, as the feed's does).
|
|
749
|
+
let last;
|
|
747
750
|
let full = false;
|
|
748
751
|
for (const event of events) {
|
|
749
752
|
const key = firingKey(by, trigger.id, event.key);
|
|
@@ -767,20 +770,35 @@ export class Triggers {
|
|
|
767
770
|
full = true;
|
|
768
771
|
break;
|
|
769
772
|
}
|
|
770
|
-
|
|
773
|
+
last = event;
|
|
771
774
|
}
|
|
772
|
-
|
|
773
|
-
cursor = result.cursor ?? cursor;
|
|
775
|
+
const cursor = !events.length ? result.cursor : full ? last?.cursor : (result.cursor ?? last?.cursor);
|
|
774
776
|
if (restarted())
|
|
775
777
|
return true;
|
|
776
778
|
for (const [field, value] of Object.entries(cursor ?? {}))
|
|
777
779
|
await settings?.set(trigger.id, field, value);
|
|
780
|
+
// Edited, turned off or on again while its cursor was written: its stop, a refusal's turn-off and its check were read
|
|
781
|
+
// on the source as it was. None is applied; an edit's poll, after this one, says what holds now.
|
|
782
|
+
const still = await this.find(trigger.id);
|
|
783
|
+
if (!still || !still.enabled || restarted())
|
|
784
|
+
return true;
|
|
785
|
+
if (JSON.stringify(still.source) !== JSON.stringify(trigger.source))
|
|
786
|
+
return false;
|
|
778
787
|
const refusals = result.refused ? (checkOf(settings?.get(trigger.id, LAST_CHECK))?.refused ?? 0) + 1 : 0;
|
|
779
788
|
if (result.refused && refusals >= REFUSALS_TO_STOP) {
|
|
780
789
|
await this.store.triggers.update(trigger.id, { enabled: false, nextAt: null, disabled: { at: iso(this.clock.now()), reason: "sign_in_refused", detail: result.refused.detail } });
|
|
781
790
|
this.deps.say({ condition: "trigger_sign_in_refused", trigger: trigger.id, refused: refusals });
|
|
782
791
|
await this.arm();
|
|
783
792
|
}
|
|
793
|
+
// Its source can't be read again as it is (every feed gone): off now, in its words, until an owner edits it and
|
|
794
|
+
// turns it on again. Before its last check is written, as a refused sign-in's is: a check that says so is never read
|
|
795
|
+
// beside a trigger still on.
|
|
796
|
+
if (result.stop && !result.refused) {
|
|
797
|
+
await this.store.triggers.update(trigger.id, { enabled: false, nextAt: null, disabled: { at: iso(this.clock.now()), reason: "source_unreadable", detail: result.stop.detail } });
|
|
798
|
+
this.deps.say({ condition: "trigger_source_unreadable", trigger: trigger.id, error: result.stop.detail });
|
|
799
|
+
await this.offThere([current]);
|
|
800
|
+
await this.arm();
|
|
801
|
+
}
|
|
784
802
|
const message = full ? `${result.check.message} ${DUE_KEPT} firings are still waiting for their runs: the rest wait for the next check.` : result.check.message;
|
|
785
803
|
await settings?.set(trigger.id, LAST_CHECK, JSON.stringify({ at: iso(now), ok: result.check.ok, message, refused: refusals }));
|
|
786
804
|
if (!result.check.ok)
|
package/dist/validate.js
CHANGED
|
@@ -8,6 +8,7 @@ import { computerIssues, settingConflict } from "./computer-setting.js";
|
|
|
8
8
|
import { settingsIssues } from "./tool-plane.js";
|
|
9
9
|
import { APPROVALS } from "./approvals.js";
|
|
10
10
|
import { schemaCheck } from "./answer-json.js";
|
|
11
|
+
import { learningSettingIssue } from "./learning-setting.js";
|
|
11
12
|
export const ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
12
13
|
/** An inline agent's source or kind in its external reference (POST /runs): no colon, which the reference's key splits on. */
|
|
13
14
|
export const EXTERNAL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
@@ -119,8 +120,12 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
119
120
|
if (d.learning !== undefined) {
|
|
120
121
|
if (d.workflow !== undefined)
|
|
121
122
|
out.push(issue(`${at}.learning`, "not_allowed", "A workflow revision does not learn: only an agentic run reflects on its work.", `Remove ${at}.learning.`));
|
|
122
|
-
else
|
|
123
|
-
|
|
123
|
+
else {
|
|
124
|
+
// true learns notes, skills and workflows, "notes" notes and skills alone; an object is on, with the loop's numbers.
|
|
125
|
+
const wrong = learningSettingIssue(d.learning, `${at}.learning`);
|
|
126
|
+
if (wrong)
|
|
127
|
+
out.push(issue(`${at}.learning`, "wrong_type", wrong));
|
|
128
|
+
}
|
|
124
129
|
}
|
|
125
130
|
// An agentic revision's structured answer: the JSON Schema its final answer's last fenced json block meets, read into a
|
|
126
131
|
// completed run's result.output (answer-json.ts structuredAnswer). A workflow's output is its workflow's own.
|
package/dist/webhooks.js
CHANGED
|
@@ -73,12 +73,15 @@ const WAIT = "wait:";
|
|
|
73
73
|
* read of the run) needs its mark, and that is one of its last few. */
|
|
74
74
|
const WAITS_KEPT = 20;
|
|
75
75
|
const iso = (ms) => new Date(ms).toISOString();
|
|
76
|
-
/** `work`'s result, or `signal`'s reason the moment it aborts: a lookup that never answers is given up on, not waited out.
|
|
76
|
+
/** `work`'s result, or `signal`'s reason the moment it aborts: a lookup that never answers is given up on, not waited out.
|
|
77
|
+
* `work` is always followed to its end, so one that fails after the abort (a name that answers NXDOMAIN once the server
|
|
78
|
+
* is stopping) is no unhandled rejection. */
|
|
77
79
|
const abortable = (work, signal) => new Promise((resolve, reject) => {
|
|
78
|
-
if (signal.aborted)
|
|
79
|
-
return reject(signal.reason);
|
|
80
80
|
const onAbort = () => reject(signal.reason);
|
|
81
|
-
signal.
|
|
81
|
+
if (signal.aborted)
|
|
82
|
+
onAbort();
|
|
83
|
+
else
|
|
84
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
82
85
|
work.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
83
86
|
});
|
|
84
87
|
export { signatureOf } from "./standard-webhooks.js";
|
|
@@ -627,6 +630,8 @@ export class Webhooks {
|
|
|
627
630
|
}
|
|
628
631
|
attempt.latency_ms = Math.round(performance.now() - started);
|
|
629
632
|
}
|
|
633
|
+
// In its words, written or not: a try the server's stop cut short still says why it ended.
|
|
634
|
+
attempt.error = failure ?? null;
|
|
630
635
|
if (this.closed)
|
|
631
636
|
return attempt;
|
|
632
637
|
// What the try found is settled against the webhook as it stands once every change asked for before it (a PUT, a
|
|
@@ -644,7 +649,6 @@ export class Webhooks {
|
|
|
644
649
|
async settleTry(id, how, now, tryId, claimed, config, failure, attempt) {
|
|
645
650
|
if (this.closed)
|
|
646
651
|
return attempt;
|
|
647
|
-
attempt.error = failure ?? null;
|
|
648
652
|
// The schedule counts the message's own tries, from the count its claim took it at; a redelivery counts none.
|
|
649
653
|
const attempts = claimed ? claimed.attempts + 1 : undefined;
|
|
650
654
|
// A 410 turns off the webhook as this try found it: one set again or removed while the try waited is not its to turn
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AttachHub, type ComputerSpec, type DockerVolume } from "@parcha/agentrun-computer";
|
|
1
|
+
import { type AttachHub, type ComputerSpec, type DockerVolume, type HostedDial } from "@parcha/agentrun-computer";
|
|
2
2
|
import type { DockerPaths } from "../box-paths.js";
|
|
3
3
|
import { type HostRead } from "../docker-host-addresses.js";
|
|
4
4
|
import { type ProviderFactories } from "../computer-keys.js";
|
|
@@ -56,6 +56,10 @@ export interface ComputerDepsOptions {
|
|
|
56
56
|
/** The server's AttachHub, where this runner shares the server's process (runner/beside.ts): a paired computer's
|
|
57
57
|
* socket is there. Absent: a runner of its own process, which refuses a paired computer in words. */
|
|
58
58
|
readonly hub?: AttachHub;
|
|
59
|
+
/** The server's dial (Serve.dial), where this runner shares the server's process: every remote provider's create
|
|
60
|
+
* takes it, and one whose host dials the server (facts.connect "dial") mints its machine's token there. Absent: a
|
|
61
|
+
* runner of its own process, where such a provider's create refuses in words. */
|
|
62
|
+
readonly dial?: HostedDial;
|
|
59
63
|
/** The server's seal key: absent, no saved key is opened (a key from the environment still is). */
|
|
60
64
|
readonly sealKey: Buffer | undefined;
|
|
61
65
|
/** The kind registry: the computer package's unless given (a test's fixture). */
|
|
@@ -293,11 +293,11 @@ export function computerDepsFrom(options) {
|
|
|
293
293
|
* Chrome's, where it finds Chrome), and no other variable of the server's. */
|
|
294
294
|
const hostEnvOf = (names) => Object.fromEntries(names.flatMap((name) => (env[name] === undefined ? [] : [[name, String(env[name])]])));
|
|
295
295
|
/** The options a provider takes beside its keys, by what its descriptor declares, never by its id: for a local one,
|
|
296
|
-
* its image source and its host options; the host environment it reads. */
|
|
296
|
+
* its image source and its host options; for a remote one, the server's dial; the host environment it reads. */
|
|
297
297
|
const declaredOptions = async (id, boxAllow) => {
|
|
298
298
|
const entry = kinds.PROVIDERS.find((one) => one.id === id);
|
|
299
299
|
return {
|
|
300
|
-
...(entry?.local ? { image: preparedImage, ...(await localHostOptions(boxAllow)) } : {}),
|
|
300
|
+
...(entry?.local ? { image: preparedImage, ...(await localHostOptions(boxAllow)) } : options.dial ? { dial: options.dial } : {}),
|
|
301
301
|
...(entry?.hostEnv ? { env: hostEnvOf(entry.hostEnv) } : {}),
|
|
302
302
|
};
|
|
303
303
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ComputerProvider, ComputerSpec, HelloResult, Result, ScreenWatch, ScreenWatchHandlers, WatchOptions } from "@parcha/agentrun-computer";
|
|
2
|
+
import { type RecordInput } from "../computer-record.js";
|
|
2
3
|
import { type PlaceView } from "../computer-setting.js";
|
|
3
4
|
import { type KeyTable, type ProviderSettings } from "../computer-keys.js";
|
|
4
5
|
import type { Store } from "../store/index.js";
|
|
@@ -114,6 +115,12 @@ export interface ComputerForClaimDeps {
|
|
|
114
115
|
readonly revokeMount?: () => Promise<void>;
|
|
115
116
|
/** The live view's registration for a desktop or a phone (proxy-only). Absent: no view is opened. */
|
|
116
117
|
readonly openComputerView?: OpenComputerView;
|
|
118
|
+
/** Where the agent's setting asks for a video of its desktop's or phone's screen (computer.record): the run's
|
|
119
|
+
* recordings folder on this machine (paths.ts recordingsFolder) and where its lines on the run's timeline go
|
|
120
|
+
* (computer-record.ts startRecording; for tests, the program in ffmpeg's place and the bounds). The computer this claim
|
|
121
|
+
* attaches is recorded through a watch of its own, with or without a viewer, until its release, the run's end or its
|
|
122
|
+
* park. Absent: nothing is recorded. */
|
|
123
|
+
readonly recordings?: Pick<RecordInput, "folder" | "say" | "ffmpeg" | "limits">;
|
|
117
124
|
/** Told once, before the claim waits on its computer's image (a provider that makes its own: Docker's recipe built on
|
|
118
125
|
* a host that lacks it, or a named image pulled); never when the host has it. The run's caller says it on the run's
|
|
119
126
|
* timeline. Absent: nothing is said. */
|