openvibers/openvibe.network Commits
Design's ai.chat reaches the production grant row (#534)
Changes
@@@ -784,6 +784,10 @@ const CHANGED_DEFAULT_NAMESPACES = [['media-hub', 'ai.run.create', 'openvibe.ai', ['media.analyze'], ['media.analyze', 'pics.describe_image']],// Search's embedder runs AI workflow ai.embed (contracts 0.234.0; POST /api/v1/embed for hybrid ranking).['search', 'ai.run.create', 'openvibe.ai', ['research.*'], ['research.*', 'ai.embed']],++ // Design's frames with a preference run ai.chat (Design #57, 10-31). Network #533 added it to the default; the++ // production row, seeded before, kept ['ai.generate'] (the seed never changes an existing row), so frames still++ // failed until this moved it.++ ['design', 'ai.run.create', 'openvibe.ai', ['ai.generate'], ['ai.generate', 'ai.chat']],];async function ensureSchema(db) {nnew file mode 100644@@@ -0,0 +1,29 @@++/**++ * Design's AI grant reaches the row production already has (11-02): Design's frames with a preference run AI's ai.chat++ * workflow, and the default grant names ai.generate and ai.chat. The seed never changes an existing row, so a row++ * seeded before with ['ai.generate'] must be moved at boot; a row someone edited by hand is left alone.++ *++ * node test/design-ai-chat-grant.test.js++ */++'use strict';++const assert = require('assert');++const { getDb } = require('../server/db/database');++const principals = require('../server/identity/principals');++++(async () => {++ const db = getDb();++ await principals.ensureSchema(db);++ const row = async () => JSON.parse((await db.prepare("SELECT namespaces FROM principal_grants WHERE client_id = 'design' AND capability = 'ai.run.create' AND audience = 'openvibe.ai'").get()).namespaces);++ assert.deepStrictEqual((await row()).sort(), ['ai.chat', 'ai.generate'], 'a fresh database gets both');++++ // Production's row, as the old default seeded it.++ await db.prepare("UPDATE principal_grants SET namespaces = ? WHERE client_id = 'design' AND capability = 'ai.run.create' AND audience = 'openvibe.ai'").run(JSON.stringify(['ai.generate']));++ await principals.ensureSchema(db);++ assert.deepStrictEqual(await row(), ['ai.generate', 'ai.chat'], 'the old default row is moved at boot');++++ // A row edited by hand stays as it was.++ await db.prepare("UPDATE principal_grants SET namespaces = ? WHERE client_id = 'design' AND capability = 'ai.run.create' AND audience = 'openvibe.ai'").run(JSON.stringify(['ai.generate', 'custom.x']));++ await principals.ensureSchema(db);++ assert.deepStrictEqual(await row(), ['ai.generate', 'custom.x'], 'an edited row is left alone');++ console.log('design ai.chat grant: all checks passed');++})().catch((e) => { console.error(e); process.exit(1); });
@@ -784,6 +784,10 @@ const CHANGED_DEFAULT_NAMESPACES = [
@@ -784,6 +784,10 @@ const CHANGED_DEFAULT_NAMESPACES = [
['media-hub', 'ai.run.create', 'openvibe.ai', ['media.analyze'], ['media.analyze', 'pics.describe_image']],
['media-hub', 'ai.run.create', 'openvibe.ai', ['media.analyze'], ['media.analyze', 'pics.describe_image']],
// Search's embedder runs AI workflow ai.embed (contracts 0.234.0; POST /api/v1/embed for hybrid ranking).
// Search's embedder runs AI workflow ai.embed (contracts 0.234.0; POST /api/v1/embed for hybrid ranking).
['search', 'ai.run.create', 'openvibe.ai', ['research.*'], ['research.*', 'ai.embed']],
['search', 'ai.run.create', 'openvibe.ai', ['research.*'], ['research.*', 'ai.embed']],
+ // Design's frames with a preference run ai.chat (Design #57, 10-31). Network #533 added it to the default; the
+ // production row, seeded before, kept ['ai.generate'] (the seed never changes an existing row), so frames still
+ // failed until this moved it.
+ ['design', 'ai.run.create', 'openvibe.ai', ['ai.generate'], ['ai.generate', 'ai.chat']],
];
];
async function ensureSchema(db) {
async function ensureSchema(db) {
new file mode 100644
new file mode 100644
@@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
+/**
+ * Design's AI grant reaches the row production already has (11-02): Design's frames with a preference run AI's ai.chat
+ * workflow, and the default grant names ai.generate and ai.chat. The seed never changes an existing row, so a row
+ * seeded before with ['ai.generate'] must be moved at boot; a row someone edited by hand is left alone.
+ *
+ * node test/design-ai-chat-grant.test.js
+ */
+'use strict';
+const assert = require('assert');
+const { getDb } = require('../server/db/database');
+const principals = require('../server/identity/principals');
+
+(async () => {
+ const db = getDb();
+ await principals.ensureSchema(db);
+ const row = async () => JSON.parse((await db.prepare("SELECT namespaces FROM principal_grants WHERE client_id = 'design' AND capability = 'ai.run.create' AND audience = 'openvibe.ai'").get()).namespaces);
+ assert.deepStrictEqual((await row()).sort(), ['ai.chat', 'ai.generate'], 'a fresh database gets both');
+
+ // Production's row, as the old default seeded it.
+ await db.prepare("UPDATE principal_grants SET namespaces = ? WHERE client_id = 'design' AND capability = 'ai.run.create' AND audience = 'openvibe.ai'").run(JSON.stringify(['ai.generate']));
+ await principals.ensureSchema(db);
+ assert.deepStrictEqual(await row(), ['ai.generate', 'ai.chat'], 'the old default row is moved at boot');
+
+ // A row edited by hand stays as it was.
+ await db.prepare("UPDATE principal_grants SET namespaces = ? WHERE client_id = 'design' AND capability = 'ai.run.create' AND audience = 'openvibe.ai'").run(JSON.stringify(['ai.generate', 'custom.x']));
+ await principals.ensureSchema(db);
+ assert.deepStrictEqual(await row(), ['ai.generate', 'custom.x'], 'an edited row is left alone');
+ console.log('design ai.chat grant: all checks passed');
+})().catch((e) => { console.error(e); process.exit(1); });