openvibers/openvibe.actor Commits

A-1: Vibe first on a person's first write (#318)

OP OpenVibers committed 6 days ago · 8ea3013413 · 2 files, +11 −0

Changes

ddiff --git a/server/agents/contacts.js b/server/agents/contacts.js
iindex bad3ca1..ffbb2ed 100644
---- a/server/agents/contacts.js
++++ b/server/agents/contacts.js
@@@ -139,6 +139,8 @@ async function create(s, config, owner, input) {
if (invalid) return { error: invalid };
const instructions = body.instructions != null ? body.instructions : (base.instructions || `You are ${next.name}, one of this person's agents.`);
if (typeof instructions !== 'string' || !instructions.trim() || instructions.length > 4000) return { error: 'instructions must be 1–4000 characters.' };
++ // Vibe comes first even when the first thing a person does is create another contact.
++ await ensureVibe(s, config, owner);
const count = Number(await s.db.value('SELECT count(*) FROM actor_agents WHERE owner = $1', [owner]));
if (count >= config.agents.maxPerOwner) return { limit: true, error: 'Agent limit reached.' };
const now = s.iso();
ddiff --git a/test/agents-contacts.test.js b/test/agents-contacts.test.js
iindex efa6b17..6e403db 100644
---- a/test/agents-contacts.test.js
++++ b/test/agents-contacts.test.js
@@@ -118,6 +118,15 @@ const PRESET_NAMES = ['Researcher', 'Inbox', 'Studio editor', 'Party host'];
assert.strictEqual((await t.get('/api/v1/agents', { json: { name: 'Nope' } })).status, 401);
});
++ await check('a person\'s first write still creates Vibe first', async () => {
++ const carol = t.network.addUser('contacts-carol');
++ const made = await t.get('/api/v1/agents', { as: carol, json: { name: 'First' }, headers: SAME });
++ assert.strictEqual(made.status, 201, made.text);
++ const roster = (await t.get('/api/v1/agents', { as: carol })).json().agents;
++ assert.deepStrictEqual(roster.map((a) => a.name), ['Vibe', 'First']);
++ assert.strictEqual(Number(await t.ctx.s.db.value('SELECT count(*) FROM actor_agents WHERE owner = $1 AND is_vibe', [`user:${carol.subject}`])), 1);
++ });
++
await check('the OpenAPI document lists every new contact route', async () => {
const doc = (await t.get('/openapi.json')).json();
for (const [path, method] of [