openvibers/openvibe.actor Commits

Actor: an agent's page offers to wake it when something happens (through OpenVibe.Watch) (#52)

OP OpenVibers committed 30 days ago · 5539b03bf6 · 2 files, +3 −0

Plan T17: "Still to come: Events and Watch triggers". Watch now has a no-code event template, and `/watches/new` prefills an agent from a link (Watch#56). So an agent's page offers to wake it the moment something happens on OpenVibe (a channel goes live, a blog post, a wiki page) or when a page changes. The links open Watch's form with this agent already chosen; the person still submits it.

**Tests:** `agents-pages` (the link is on the agent's page).

Changes

ddiff --git a/server/http/agent-pages.js b/server/http/agent-pages.js
iindex 7878d71..e305860 100644
---- a/server/http/agent-pages.js
++++ b/server/http/agent-pages.js
@@@ -112,6 +112,8 @@ ${a.state === 'pending' ? html`<form method="post" action="/me/approvals/${a.id}
${a.last_skip_reason ? html`<p class="notice" role="status">The last scheduled run was skipped: ${a.last_skip_reason}</p>` : ''}
<div class="pa-grid">
<section class="pa-panel"><h2>Run now</h2><form method="post" action="/me/agents/${a.id}/run"><label>Input (optional) <span class="pa-hint">Anything this run should also consider.</span><textarea name="input" maxlength="8000" rows="3"></textarea></label><button type="submit" class="pa-btn pa-primary">Run now</button></form></section>
++<section class="pa-panel"><h2>Wake it when something happens</h2><p>Besides its schedule, this agent can run the moment something happens: a channel goes live, a new blog post, a page changes, a price drops, a webhook arrives. <a href="https://openvibe.watch">OpenVibe.Watch</a> watches for it and runs this agent with what it saw.</p>
++<p class="pa-actions"><a class="pa-btn" href="https://openvibe.watch/watches/new?template=event&amp;agent_id=${a.id}">When something happens on OpenVibe</a> <a class="pa-btn" href="https://openvibe.watch/watches/new?template=page&amp;agent_id=${a.id}">When a page changes</a></p></section>
<section class="pa-panel"><h2>Recent runs</h2>${runs.length ? html`<ul class="pa-runs">${runs.map((t) => html`<li><a href="/tasks/${t.id}">${time(t.created_at)}</a> <span class="pill ${pill(t.state)}">${t.state}</span></li>`)}</ul>` : html`<p class="muted">No run yet.</p>`}</section>
</div>
<section class="pa-panel"><h2>Memory</h2><p class="pa-hint">What this agent remembers, newest first. Notes you write are never dropped; when memory is full (50 notes) the oldest note the agent wrote goes first. An agent adds at most one note per run, and only when its answer passed the check.</p>
ddiff --git a/test/agents-pages.test.js b/test/agents-pages.test.js
iindex 53d94e0..9f72f3f 100644
---- a/test/agents-pages.test.js
++++ b/test/agents-pages.test.js
@@@ -22,6 +22,7 @@ const SAME = { 'sec-fetch-site': 'same-origin' };
const id = create.headers.get('location').split('/').pop();
const own = await t.get(`/me/agents/${id}`, { as: a });
assert.match(own.text, /Run now/);
++ assert.ok(own.text.includes(`https://openvibe.watch/watches/new?template=event&amp;agent_id=${id}`), 'a link to wake it from Watch');
assert.match(own.text, /Forget everything/);
assert.strictEqual((await t.get(`/me/agents/${id}/memory`, { as: a, form: { text: 'Remember this.' }, headers: SAME })).status, 303);
const withNote = await t.get(`/me/agents/${id}`, { as: a });