openvibers/openvibe.sdk Commits
openvibe-sdk/machines: the network's machines hub (plan L34, step M2) (#109)
Changes
@@@ -1,5 +1,22 @@# Changelog++## 0.79.0 (2026-10-31)++++- **`openvibe-sdk/machines`: the network's machines hub** (plan L34, step M2; Contracts 0.258.0). A person's machines++ are the network's: Bot stays the registry underneath, and OpenVibe.Network fronts it on openvibe.network/machines for++ the person and for the apps the person consented to.++ - `createMachines({ networkUrl, token, fetch, timeoutMs })`: `token` returns the caller's own bearer token — the++ person's session token, or an app's token holding `network.machines.read` or `network.machines.manage` with the++ person's consent.++ - `list()` → `{ machines }`, `get(id)` → `{ machine }`, `catalogue()` → `{ roles }` (what a machine may do for the++ network), `pair()` → `{ pairing }` (a one-time code and the command to run), `rename(id, name)` → `{ machine }`,++ `roles(id, roles)` → `{ machine }` (the whole set, not a change), `revoke(id)` → `{ machine }`.++ - A refusal throws a `MachinesError` with the hub's own `status` and `code` (`capability.denied`,++ `capability.owner_denied`, `registry.unknown_role`, a 404 for a machine that is not the caller's). A hub that does++ not answer is a `machines.timeout`, never a hang.++ - The machines' own capabilities stay where they are: `openvibe-sdk/bot`'s `machines.desk()` and `machines.chat()`++ talk to Bot itself and are unchanged.++## 0.78.0 (2026-10-31)- **`openvibe-sdk/consent`:** the client for the L24 consent registry. Nothing a person makes is off-limits to AI or@@@ -2,16 +2,16 @@> Supported browser and server clients for the OpenVibe platform.--**Status:** alpha, v0.78.0 (roadmap Wave 2; developer apps from Wave 20; Media objects v2 from Wave 4; the Tools platform API; Search, Chat, AI, Vision and consent clients; sign-in with recovery and a client health check). Every release is tagged (see [CHANGELOG.md](CHANGELOG.md)). Tested against local stub servers and the built-in mock platform only, never against the live platform. Services pin release tags; each repository's `STATUS.json` names the one it uses.++**Status:** alpha, v0.79.0 (roadmap Wave 2; developer apps from Wave 20; Media objects v2 from Wave 4; the Tools platform API; Search, Chat, AI, Vision and consent clients; sign-in with recovery and a client health check). Every release is tagged (see [CHANGELOG.md](CHANGELOG.md)). Tested against local stub servers and the built-in mock platform only, never against the live platform. Services pin release tags; each repository's `STATUS.json` names the one it uses.**Plan:** OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), §3.2; roadmap §30.**License:** MIT ([LICENSE](LICENSE)). This package is a library that apps outside the network embed, so it uses MIT. The OpenVibe services themselves stay AGPL-3.0.**If a capability is not in the SDK, it is not public.** Apps call services through `openvibe-sdk` and never build internal routes themselves. A route with no SDK wrapper is internal, even when you can reach it, and it can change without notice. To make a capability public, first define it in OpenVibe.Contracts, then wrap it here.--After v0.78.0 is tagged:++After v0.79.0 is tagged:```bash--npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.78.0++npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.79.0```It has no runtime dependencies. It needs Node ≥ 20, or any browser with `fetch`, Web Crypto and `TextDecoder`. There is no build step. The package is CommonJS with ESM entry points (`import` works). Each subpath has its own `.d.ts`. For a page with no bundler, `browser/openvibe-sdk.mjs` is one self-contained ES module of the browser-safe subpaths (see [Browser without a bundler](#browser-without-a-bundler)). It does not depend on `openvibe-contracts` at runtime: it copies the contract types it uses (from Contracts v0.86.0, a devDependency the tests check them against).@@@ -563,5 +563,5 @@ Nothing at runtime. `openvibe-contracts` and `@electric-sql/pglite` are devDepenPart of the [OpenVibe network](https://openvibe.network). Built in the open by [OpenVibers](https://github.com/OpenVibers).<!-- versions:start -->--- openvibe-contracts: v0.222.0++- openvibe-contracts: v0.261.0<!-- versions:end -->@@@ -3,11 +3,11 @@"stage": "alpha","code": true,"wave": "W2",-- "version": "0.78.0",-- "plan": "OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), \u00a73.2; roadmap \u00a730",++ "version": "0.79.0",++ "plan": "OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), §3.2; roadmap §30","deployed": false,"deployment": "none: a package released as git tags; services and apps pin a tag",-- "contracts": "openvibe-contracts v0.222.0 (devDependency; runtime contracts range >=0.5.0 <1.0.0)",++ "contracts": "openvibe-contracts v0.261.0 (devDependency; runtime contracts range >=0.5.0 <1.0.0)","features": ["redact (openvibe-sdk/redact): the shared secret scrubber for memory, the same shapes and corpus as OpenVibe.Node's internal/memory/redact.go (redact, onlySecret)","core client: retries, timeouts, problem+json errors, trace propagation",@@@ -28,13 +28,14 @@"valkey, cache, queue, pubsub and a shared limits store on Valkey 9, each with an in-process twin for tests","commerce (openvibe-sdk/commerce): the shared Billing client for Tips and VIP, with intentKey and receipt","events: the PostgreSQL outbox (lease-claimed, several relays per table) and inbox (handler in its transaction)",-- "usage: createUsageReporter (openvibe-sdk/usage), the shared platform.usage-sample@1 reporter \u2014 validated readings queued idempotency-keyed in an outbox and relayed to Billing with retry, never dropped, refused readings kept",++ "usage: createUsageReporter (openvibe-sdk/usage), the shared platform.usage-sample@1 reporter — validated readings queued idempotency-keyed in an outbox and relayed to Billing with retry, never dropped, refused readings kept","the HTTP telemetry kit (openvibe-sdk/service): the platform.telemetry-sample@1 middleware aggregated per route|method|status_class per flush, with active-requests, p95 and event-loop-lag gauges, lifted from Network's server/telemetry.js and server/observability.js","the telemetry sink (openvibe-sdk/telemetry): telemetrySchema() DDL, createPgTelemetrySink() and pruneTelemetry(), a per-service PostgreSQL table every service stores platform.telemetry-sample@1 into","account-data (openvibe-sdk/account-data, ADR-033): telemetry_samples covered once by the SDK (exported as telemetry.json, anonymized on deletion), and uncovered() listing every table with a person column that no table map, task-keyed list or reasoned exemption covers","resources (openvibe-sdk/resources): the ADR-048 resource index fan-out and the idempotent control client","placement v1 (openvibe-sdk/placement): place() with the person's rules and ownership, the quality bar, cost per success, learn/successOf, escalate and the one-line reason; plan() takes the optional success map and never defaults to user-owned",-- "consent (openvibe-sdk/consent): the L24 check before any use of a person's content or likeness for AI or data; allowed() and filter() (batches of 500), onChange() drops a subject's answers on network.consent.changed, mock() for tests; fails closed, caches 60 s, server-side"++ "consent (openvibe-sdk/consent): the L24 check before any use of a person's content or likeness for AI or data; allowed() and filter() (batches of 500), onChange() drops a subject's answers on network.consent.changed, mock() for tests; fails closed, caches 60 s, server-side",++ "openvibe-sdk/machines: the network's machines hub (list, get, catalogue, pair, rename, roles, revoke) against OpenVibe.Network, for a person and for the apps they consented to"],"updated": "2026-10-31"}@@@ -1,4 +1,4 @@--// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.78.0, MIT). Do not edit.++// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.79.0, MIT). Do not edit.// One self-contained ES module: core at the top level plus the browser-safe subpaths as namespaces// (auth, registry, modules, realtime, media, community, bot, search, bench, vision, themes, redact, chat, ai, jobs, tools, projects, geo). No server-only code: no service tokens, JWT verification, events, identity./* eslint-disable */@@@ -46,7 +46,7 @@ const { paginate, offsetPager } = __load(7);const semver = __load(6);/** The package version (test/version.test.js keeps it equal to package.json). */--const SDK_VERSION = '0.78.0';++const SDK_VERSION = '0.79.0';module.exports = {createClient,@@@ -571,6 +571,11 @@"openvibe-sdk/live": {"createLiveClient": "function"},++ "openvibe-sdk/machines": {++ "DEFAULT_TIMEOUT_MS": "number",++ "MachinesError": "class",++ "createMachines": "function"++ },"openvibe-sdk/media": {"DEFAULT_PUBLIC_ORIGIN": "string","createMediaClient": "function",nnew file mode 100644@@@ -0,0 +1,7 @@++// Generated by scripts/esm.js from src/machines.js. Do not edit.++import cjs from '../src/machines.js';++++export const {++ createMachines, MachinesError, DEFAULT_TIMEOUT_MS,++} = cjs;++export default cjs;@@@ -1,12 +1,12 @@{"name": "openvibe-sdk",-- "version": "0.78.0",++ "version": "0.79.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "openvibe-sdk",-- "version": "0.78.0",++ "version": "0.79.0","license": "MIT","bin": {"openvibe-download": "bin/openvibe-download.js"@@@ -14,7 +14,7 @@"devDependencies": {"@electric-sql/pglite": "^0.5.8","iovalkey": "^0.4.0",-- "openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.225.0",++ "openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.261.0","pg": "^8.23.0"},"engines": {@@@ -198,9 +198,9 @@"license": "MIT"},"node_modules/openvibe-contracts": {-- "version": "0.225.0",-- "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.225.0",-- "integrity": "sha512-msLaRYa2Byyabnf/+L3aRPwkx8MI3zWbofFhwupq+RyBCdgbA4gLlkPsJu9nK/1UTCWdNdSTfWXW5pZY1/1zbQ==",++ "version": "0.261.0",++ "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.261.0",++ "integrity": "sha512-SiXOcXRL9+WivMkKM1W6sGNJMD4uCBR9o7KYZvs99hT2xgYxDvP4rM7tLBudGu1boPH+coMdUXVQAAWbS/3JDw==","dev": true,"license": "AGPL-3.0-only","dependencies": {@@@ -1,6 +1,6 @@{"name": "openvibe-sdk",-- "version": "0.78.0",++ "version": "0.79.0","description": "Supported browser and server clients for the OpenVibe platform: auth (incl. developer apps), registry discovery, identity, user modules, events, realtime, media, community, Bot robots, search, chat, AI runs, Tools (registry, run API and jobs), VIP memberships and developer projects, the async PostgreSQL data layer (db) and the Valkey cache, limits store, queue and pub/sub, with deadlines, safe retries, problem errors and trace propagation.","main": "index.js","types": "types/index.d.ts",@@@ -82,6 +82,11 @@"import": "./esm/bot.mjs","default": "./src/bot.js"},++ "./machines": {++ "types": "./types/machines.d.ts",++ "import": "./esm/machines.mjs",++ "default": "./src/machines.js"++ },"./search": {"types": "./types/search.d.ts","import": "./esm/search.mjs",@@@ -470,7 +475,7 @@"devDependencies": {"@electric-sql/pglite": "^0.5.8","iovalkey": "^0.4.0",-- "openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.225.0",++ "openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.261.0","pg": "^8.23.0"},"peerDependencies": {@@@ -26,6 +26,7 @@ const ENTRIES = {'media.mjs': '../src/media.js','community.mjs': '../src/community.js','bot.mjs': '../src/bot.js',++ 'machines.mjs': '../src/machines.js','search.mjs': '../src/search.js','bench.mjs': '../src/bench.js','themes.mjs': '../src/themes.js',@@@ -8,7 +8,7 @@ const { paginate, offsetPager } = require('./paginate');const semver = require('./semver');/** The package version (test/version.test.js keeps it equal to package.json). */--const SDK_VERSION = '0.78.0';++const SDK_VERSION = '0.79.0';module.exports = {createClient,nnew file mode 100644@@@ -0,0 +1,104 @@++'use strict';++/**++ * openvibe-sdk/machines — the network's machines hub (plan L34, step M2; Contracts 0.258.0).++ *++ * A person's machines are the network's: Bot stays the registry underneath, and OpenVibe.Network fronts it on++ * openvibe.network/machines for the person and for the apps the person consented to. This module is the hub's API:++ *++ * // createMachines from the openvibe-sdk/machines entry (CommonJS or ESM)++ * const machines = createMachines({ networkUrl: 'https://openvibe.network', token: () => sessionToken });++ *++ * await machines.list(); → { machines: [machine] } the person's own machines++ * await machines.get(id); → { machine }++ * await machines.catalogue(); → { roles: [role] } what a machine may do++ * await machines.pair(); → { pairing } a one-time code and the command++ * await machines.rename(id, 'Studio'); → { machine }++ * await machines.roles(id, ['codes.worker']); → { machine } the whole set, not a change++ * await machines.revoke(id); → { machine }++ *++ * The token is the caller's own: the person's session token, or an app's token holding network.machines.read or++ * network.machines.manage with the person's consent. `token` may return the token or a promise of it.++ *++ * A refusal is an error with the hub's own status and code (`err.status`, `err.code`): 403 capability.denied when++ * the caller holds no capability, 403 capability.owner_denied when the app's consent is gone, 404 when the machine++ * is not the caller's, 422 when a role is not in the catalogue.++ *++ * The machines' own capabilities (a computer, a desk, a model on it) stay where they are: openvibe-sdk/bot's++ * machines.desk() and machines.chat() talk to Bot itself and are unchanged.++ */++const DEFAULT_TIMEOUT_MS = 10_000;++++/** The error a refusal carries: the hub's status and code, so a caller can tell them apart. */++class MachinesError extends Error {++ constructor(status, code, message) {++ super(message || code || `the hub answered ${status}`);++ this.name = 'MachinesError';++ this.status = status;++ this.code = code || 'machines.failed';++ }++}++++/**++ * The machines client.++ * networkUrl OpenVibe.Network's base URL++ * token () => the caller's bearer token (a person session, or an app's consented token)++ * fetch the fetch implementation (default globalThis.fetch)++ * timeoutMs the deadline of one call (default 10 s)++ */++function createMachines({ networkUrl, token, fetch: fetchImpl = globalThis.fetch, timeoutMs = DEFAULT_TIMEOUT_MS } = {}) {++ if (!networkUrl || typeof networkUrl !== 'string') throw new TypeError('createMachines: networkUrl is required');++ if (typeof token !== 'function') throw new TypeError('createMachines: token must be a function returning a bearer token');++ if (typeof fetchImpl !== 'function') throw new TypeError('createMachines: a fetch implementation is required');++ const base = String(networkUrl).replace(/\/+$/, '');++++ async function call(method, path, body) {++ const bearer = await token();++ if (!bearer) throw new MachinesError(401, 'token.invalid', 'no token');++ const controller = new AbortController();++ const timer = setTimeout(() => controller.abort(), timeoutMs);++ let res;++ try {++ res = await fetchImpl(`${base}${path}`, {++ method,++ headers: {++ authorization: `Bearer ${bearer}`, accept: 'application/json',++ ...(body === undefined ? {} : { 'content-type': 'application/json' }),++ },++ ...(body === undefined ? {} : { body: JSON.stringify(body) }),++ signal: controller.signal,++ });++ } catch (e) {++ clearTimeout(timer);++ const aborted = e && (e.name === 'AbortError' || e.code === 'ABORT_ERR');++ throw new MachinesError(0, aborted ? 'machines.timeout' : 'machines.unreachable', aborted ? `the hub did not answer within ${timeoutMs} ms` : `the hub is not reachable: ${e.message}`);++ }++ clearTimeout(timer);++ const out = await res.json().catch(() => null);++ if (!res.ok) {++ const code = (out && out.code) || `machines.failed`;++ throw new MachinesError(res.status, code, (out && (out.detail || out.error || out.title)) || `the hub answered ${res.status}`);++ }++ return out || {};++ }++++ const enc = (id) => encodeURIComponent(String(id == null ? '' : id));++++ return {++ /** The caller's machines: { machines }. */++ list: () => call('GET', '/api/v1/machines'),++ /** One machine: { machine }. A machine that is not the caller's is a 404. */++ get: (id) => call('GET', `/api/v1/machines/${enc(id)}`),++ /** The catalogue of roles: { roles } — what a machine may do for the network. */++ catalogue: () => call('GET', '/api/v1/machines/roles'),++ /** A one-time pairing code and the command to run on the machine: { pairing }. */++ pair: () => call('POST', '/api/v1/machines/pairings', {}),++ /** A new name for the machine: { machine }. */++ rename: (id, name) => call('PATCH', `/api/v1/machines/${enc(id)}`, { name: String(name == null ? '' : name) }),++ /** The machine's roles — the whole set, not a change: { machine }. */++ roles: (id, roles) => call('PUT', `/api/v1/machines/${enc(id)}/roles`, { roles: Array.isArray(roles) ? roles : [] }),++ /** The machine is no longer the caller's: { machine }. */++ revoke: (id) => call('POST', `/api/v1/machines/${enc(id)}/revoke`, {}),++ };++}++++module.exports = { createMachines, MachinesError, DEFAULT_TIMEOUT_MS };nnew file mode 100644@@@ -0,0 +1,93 @@++'use strict';++/**++ * openvibe-sdk/machines (plan L34, step M2): the network's machines hub. What this proves:++ * - every call goes to the hub's own route with the caller's bearer token;++ * - the answers are the hub's own shapes (machines, machine, roles, pairing);++ * - a refusal is an error with the hub's status and code, so a caller can tell them apart;++ * - a hub that does not answer is a timeout, not a hang.++ */++const assert = require('node:assert/strict');++const { stubServer, send, run, sleep } = require('./helpers');++const { createMachines, DEFAULT_TIMEOUT_MS } = require('../src/machines');++++const MACHINE = { id: 'dev_01ARZ3NDEKTSV4RRFFQ69G5FAV', kind: 'server', online: true, roles: ['codes.worker'], running: [] };++++async function hub(answer) {++ const state = { requests: [], token: 'person-token' };++ const stub = await stubServer(async (req, res, body) => {++ state.requests.push({ method: req.method, url: req.url, headers: req.headers, body: body ? body.toString() : '' });++ const a = answer(req, body, state.requests.length);++ if (!a || a.hang) return await new Promise(() => {});++ if (a.delayMs) await sleep(a.delayMs);++ send(res, a.status || 200, a.body === undefined ? '' : a.body);++ });++ return { stub, state };++}++++run([++ ['the default timeout is ten seconds', async () => {++ assert.equal(DEFAULT_TIMEOUT_MS, 10_000);++ }],++++ ['the calls are the hub\'s own routes, with the caller\'s token', async () => {++ const { stub, state } = await hub((req) => {++ if (req.url === '/api/v1/machines' && req.method === 'GET') return { body: { machines: [MACHINE] } };++ if (req.url === '/api/v1/machines/roles') return { body: { roles: [{ id: 'codes.worker', name: 'Codes worker', installs: 'the runner', shows: 'Runs your coding jobs.' }] } };++ if (req.url.endsWith('/roles') && req.method === 'PUT') return { body: { machine: { ...MACHINE, roles: ['codes.worker', 'desks.host'] } } };++ if (req.url.endsWith('/revoke')) return { body: { machine: { ...MACHINE, online: false } } };++ if (req.url === '/api/v1/machines/pairings') return { body: { pairing: { code: 'ABCD-EFGH', expires_at: '2026-10-31T12:00:00.000Z', installer: 'curl -fsSL https://openvibe.bot/install | sh' } } };++ if (req.method === 'PATCH') return { body: { machine: { ...MACHINE, name: 'Studio' } } };++ return { body: { machine: MACHINE } };++ });++ const machines = createMachines({ networkUrl: stub.url, token: () => state.token });++ try {++ const list = await machines.list();++ assert.equal(list.machines.length, 1);++ assert.equal(list.machines[0].id, MACHINE.id);++ assert.equal((await machines.get(MACHINE.id)).machine.kind, 'server');++ assert.equal((await machines.catalogue()).roles[0].id, 'codes.worker');++ assert.equal((await machines.pair()).pairing.code, 'ABCD-EFGH');++ assert.equal((await machines.rename(MACHINE.id, 'Studio')).machine.name, 'Studio');++ assert.deepEqual((await machines.roles(MACHINE.id, ['codes.worker', 'desks.host'])).machine.roles, ['codes.worker', 'desks.host']);++ assert.equal((await machines.revoke(MACHINE.id)).machine.online, false);++ for (const r of state.requests) {++ assert.equal(r.headers.authorization, 'Bearer person-token', 'every call carries the caller\'s token');++ }++ assert.equal(state.requests[4].body, JSON.stringify({ name: 'Studio' }));++ assert.equal(state.requests[5].body, JSON.stringify({ roles: ['codes.worker', 'desks.host'] }));++ } finally { await stub.close(); }++ }],++++ ['a refusal is an error with the hub\'s status and code', async () => {++ const { stub } = await hub(() => ({ status: 403, body: { code: 'capability.denied', detail: 'network.machines.read not granted' } }));++ const machines = createMachines({ networkUrl: stub.url, token: () => 'person-token' });++ try {++ await assert.rejects(() => machines.list(), (e) => {++ assert.equal(e.name, 'MachinesError');++ assert.equal(e.status, 403);++ assert.equal(e.code, 'capability.denied');++ return true;++ });++ } finally { await stub.close(); }++ }],++++ ['a hub that does not answer is a timeout, not a hang', async () => {++ const { stub } = await hub(() => ({ hang: true }));++ const machines = createMachines({ networkUrl: stub.url, token: () => 'person-token', timeoutMs: 200 });++ try {++ await assert.rejects(() => machines.list(), (e) => {++ assert.equal(e.code, 'machines.timeout');++ return true;++ });++ } finally { await stub.close(); }++ }],++++ ['no token is refused before anything is asked', async () => {++ const { stub, state } = await hub(() => ({ body: { machines: [] } }));++ const machines = createMachines({ networkUrl: stub.url, token: () => '' });++ try {++ await assert.rejects(() => machines.list(), (e) => e.code === 'token.invalid');++ assert.equal(state.requests.length, 0, 'the hub was never asked');++ } finally { await stub.close(); }++ }],++]);@@@ -68,7 +68,7 @@ run([})().catch((err) => { console.error(err); process.exit(1); });`;const res = execFileSync(process.execPath, ['-e', script], { cwd: app, encoding: 'utf8' });assert.match(res, new RegExp(`consumer ok: ${subpaths.length} subpaths \\+ the browser bundle`));-- assert.equal(subpaths.length, 73); // 0.78.0 adds openvibe-sdk/consent++ assert.equal(subpaths.length, 74); // 0.79.0 adds openvibe-sdk/machinesassert.ok(!fs.existsSync(path.join(app, 'node_modules/openvibe-contracts')), 'the optional peer is not installed');} finally {fs.rmSync(tmp, { recursive: true, force: true });@@@ -125,7 +125,7 @@ export interface Problem {[k: string]: unknown | undefined;}--/** [email protected] (owner: network) */++/** [email protected] (owner: network) *//*** What a service is, where it lives and what it offers. The ecosystem registry is built from these, not from hard-coded route maps.*/@@@ -1924,11 +1924,21 @@ export interface ServiceManifest {*/statusApi?: string;};++ /**++ * The room's launcher group in OpenVibe.Shared rooms.js and OpenVibe.Network frame/sites.js; optional so older manifests retain their meaning.++ */++ neighbourhood?: "streams" | "games" | "answers" | "make" | "shop" | "people" | "build";};capabilities: string[];eventsProduced: string[];eventsConsumed: string[];namespacesOwned: string[];++ machineRoles?: {++ id: string;++ name: string;++ installs: string;++ shows: string;++ }[];contractRanges?: {[k: string]: string | undefined;};nnew file mode 100644@@@ -0,0 +1,78 @@++/** openvibe-sdk/machines: the network's machines hub (plan L34; Contracts 0.258.0). */++++/** One machine as the hub shows it (network.machine@1). */++export interface Machine {++ /** Bot's device id (dev_…). */++ id: string;++ /** onboard (a robot's machine), bridge or server (a machine that runs its owner's jobs). */++ kind: 'onboard' | 'bridge' | 'server';++ /** Whether the machine is connected to Bot right now. */++ online: boolean;++ /** What the machine does for the network: the ids from the catalogue. */++ roles: string[];++ /** What it does right now: its Codes jobs, its desks, its local models, its robots. */++ running: Array<{ kind: 'codes.jobs' | 'desks' | 'models' | 'robots'; count: number; label?: string }>;++ /** The node principal on Network (nod_…), when it has one. */++ principal_id?: string;++ /** The name the owner gave it. */++ name?: string;++ /** The operating system the machine reports. */++ os?: string;++ /** When the machine was last seen. */++ last_seen_at?: string;++ /** The OpenVibe Node version the machine reports. */++ node_version?: string;++}++++/** One role of the catalogue (network.machine-role@1). */++export interface MachineRole {++ id: string;++ name: string;++ /** What the role installs on the machine. */++ installs: string;++ /** What the hub shows for a machine with this role. */++ shows: string;++}++++/** A one-time pairing code and the command to run on the machine (network.machine-pairing@1). */++export interface MachinePairing {++ code: string;++ expires_at: string;++ installer: string;++ pairing_id?: string;++}++++export interface MachinesClientOptions {++ /** OpenVibe.Network's base URL. */++ networkUrl: string;++ /** The caller's bearer token: the person's session token, or an app's consented token. */++ token: () => string | Promise<string>;++ fetch?: typeof fetch;++ timeoutMs?: number;++}++++export interface MachinesClient {++ /** The caller's own machines. */++ list(): Promise<{ machines: Machine[] }>;++ /** One machine; a machine that is not the caller's is a 404. */++ get(id: string): Promise<{ machine: Machine }>;++ /** The catalogue of roles: what a machine may do for the network. */++ catalogue(): Promise<{ roles: MachineRole[] }>;++ /** A one-time pairing code and the command to run on the machine. */++ pair(): Promise<{ pairing: MachinePairing }>;++ /** A new name for the machine. */++ rename(id: string, name: string): Promise<{ machine: Machine }>;++ /** The machine's roles — the whole set, not a change. */++ roles(id: string, roles: string[]): Promise<{ machine: Machine }>;++ /** The machine is no longer the caller's. */++ revoke(id: string): Promise<{ machine: Machine }>;++}++++/** A refusal: the hub's own status and code (err.status, err.code). */++export declare class MachinesError extends Error {++ status: number;++ code: string;++}++++export declare function createMachines(options: MachinesClientOptions): MachinesClient;++export declare const DEFAULT_TIMEOUT_MS: number;
@@ -1,5 +1,22 @@
@@ -1,5 +1,22 @@
# Changelog
# Changelog
+## 0.79.0 (2026-10-31)
+
+- **`openvibe-sdk/machines`: the network's machines hub** (plan L34, step M2; Contracts 0.258.0). A person's machines
+ are the network's: Bot stays the registry underneath, and OpenVibe.Network fronts it on openvibe.network/machines for
+ the person and for the apps the person consented to.
+ - `createMachines({ networkUrl, token, fetch, timeoutMs })`: `token` returns the caller's own bearer token — the
+ person's session token, or an app's token holding `network.machines.read` or `network.machines.manage` with the
+ person's consent.
+ - `list()` → `{ machines }`, `get(id)` → `{ machine }`, `catalogue()` → `{ roles }` (what a machine may do for the
+ network), `pair()` → `{ pairing }` (a one-time code and the command to run), `rename(id, name)` → `{ machine }`,
+ `roles(id, roles)` → `{ machine }` (the whole set, not a change), `revoke(id)` → `{ machine }`.
+ - A refusal throws a `MachinesError` with the hub's own `status` and `code` (`capability.denied`,
+ `capability.owner_denied`, `registry.unknown_role`, a 404 for a machine that is not the caller's). A hub that does
+ not answer is a `machines.timeout`, never a hang.
+ - The machines' own capabilities stay where they are: `openvibe-sdk/bot`'s `machines.desk()` and `machines.chat()`
+ talk to Bot itself and are unchanged.
+
## 0.78.0 (2026-10-31)
## 0.78.0 (2026-10-31)
- **`openvibe-sdk/consent`:** the client for the L24 consent registry. Nothing a person makes is off-limits to AI or
- **`openvibe-sdk/consent`:** the client for the L24 consent registry. Nothing a person makes is off-limits to AI or
@@ -2,16 +2,16 @@
@@ -2,16 +2,16 @@
> Supported browser and server clients for the OpenVibe platform.
> Supported browser and server clients for the OpenVibe platform.
-**Status:** alpha, v0.78.0 (roadmap Wave 2; developer apps from Wave 20; Media objects v2 from Wave 4; the Tools platform API; Search, Chat, AI, Vision and consent clients; sign-in with recovery and a client health check). Every release is tagged (see [CHANGELOG.md](CHANGELOG.md)). Tested against local stub servers and the built-in mock platform only, never against the live platform. Services pin release tags; each repository's `STATUS.json` names the one it uses.
+**Status:** alpha, v0.79.0 (roadmap Wave 2; developer apps from Wave 20; Media objects v2 from Wave 4; the Tools platform API; Search, Chat, AI, Vision and consent clients; sign-in with recovery and a client health check). Every release is tagged (see [CHANGELOG.md](CHANGELOG.md)). Tested against local stub servers and the built-in mock platform only, never against the live platform. Services pin release tags; each repository's `STATUS.json` names the one it uses.
**Plan:** OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), §3.2; roadmap §30.
**Plan:** OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), §3.2; roadmap §30.
**License:** MIT ([LICENSE](LICENSE)). This package is a library that apps outside the network embed, so it uses MIT. The OpenVibe services themselves stay AGPL-3.0.
**License:** MIT ([LICENSE](LICENSE)). This package is a library that apps outside the network embed, so it uses MIT. The OpenVibe services themselves stay AGPL-3.0.
**If a capability is not in the SDK, it is not public.** Apps call services through `openvibe-sdk` and never build internal routes themselves. A route with no SDK wrapper is internal, even when you can reach it, and it can change without notice. To make a capability public, first define it in OpenVibe.Contracts, then wrap it here.
**If a capability is not in the SDK, it is not public.** Apps call services through `openvibe-sdk` and never build internal routes themselves. A route with no SDK wrapper is internal, even when you can reach it, and it can change without notice. To make a capability public, first define it in OpenVibe.Contracts, then wrap it here.
-After v0.78.0 is tagged:
+After v0.79.0 is tagged:
```bash
```bash
-npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.78.0
+npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.79.0
```
```
It has no runtime dependencies. It needs Node ≥ 20, or any browser with `fetch`, Web Crypto and `TextDecoder`. There is no build step. The package is CommonJS with ESM entry points (`import` works). Each subpath has its own `.d.ts`. For a page with no bundler, `browser/openvibe-sdk.mjs` is one self-contained ES module of the browser-safe subpaths (see [Browser without a bundler](#browser-without-a-bundler)). It does not depend on `openvibe-contracts` at runtime: it copies the contract types it uses (from Contracts v0.86.0, a devDependency the tests check them against).
It has no runtime dependencies. It needs Node ≥ 20, or any browser with `fetch`, Web Crypto and `TextDecoder`. There is no build step. The package is CommonJS with ESM entry points (`import` works). Each subpath has its own `.d.ts`. For a page with no bundler, `browser/openvibe-sdk.mjs` is one self-contained ES module of the browser-safe subpaths (see [Browser without a bundler](#browser-without-a-bundler)). It does not depend on `openvibe-contracts` at runtime: it copies the contract types it uses (from Contracts v0.86.0, a devDependency the tests check them against).
@@ -563,5 +563,5 @@ Nothing at runtime. `openvibe-contracts` and `@electric-sql/pglite` are devDepen
@@ -563,5 +563,5 @@ Nothing at runtime. `openvibe-contracts` and `@electric-sql/pglite` are devDepen
Part of the [OpenVibe network](https://openvibe.network). Built in the open by [OpenVibers](https://github.com/OpenVibers).
Part of the [OpenVibe network](https://openvibe.network). Built in the open by [OpenVibers](https://github.com/OpenVibers).
<!-- versions:start -->
<!-- versions:start -->
-- openvibe-contracts: v0.222.0
+- openvibe-contracts: v0.261.0
<!-- versions:end -->
<!-- versions:end -->
@@ -3,11 +3,11 @@
@@ -3,11 +3,11 @@
"stage": "alpha",
"stage": "alpha",
"code": true,
"code": true,
"wave": "W2",
"wave": "W2",
- "version": "0.78.0",
- "plan": "OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), \u00a73.2; roadmap \u00a730",
+ "version": "0.79.0",
+ "plan": "OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), §3.2; roadmap §30",
"deployed": false,
"deployed": false,
"deployment": "none: a package released as git tags; services and apps pin a tag",
"deployment": "none: a package released as git tags; services and apps pin a tag",
- "contracts": "openvibe-contracts v0.222.0 (devDependency; runtime contracts range >=0.5.0 <1.0.0)",
+ "contracts": "openvibe-contracts v0.261.0 (devDependency; runtime contracts range >=0.5.0 <1.0.0)",
"features": [
"features": [
"redact (openvibe-sdk/redact): the shared secret scrubber for memory, the same shapes and corpus as OpenVibe.Node's internal/memory/redact.go (redact, onlySecret)",
"redact (openvibe-sdk/redact): the shared secret scrubber for memory, the same shapes and corpus as OpenVibe.Node's internal/memory/redact.go (redact, onlySecret)",
"core client: retries, timeouts, problem+json errors, trace propagation",
"core client: retries, timeouts, problem+json errors, trace propagation",
@@ -28,13 +28,14 @@
@@ -28,13 +28,14 @@
"valkey, cache, queue, pubsub and a shared limits store on Valkey 9, each with an in-process twin for tests",
"valkey, cache, queue, pubsub and a shared limits store on Valkey 9, each with an in-process twin for tests",
"commerce (openvibe-sdk/commerce): the shared Billing client for Tips and VIP, with intentKey and receipt",
"commerce (openvibe-sdk/commerce): the shared Billing client for Tips and VIP, with intentKey and receipt",
"events: the PostgreSQL outbox (lease-claimed, several relays per table) and inbox (handler in its transaction)",
"events: the PostgreSQL outbox (lease-claimed, several relays per table) and inbox (handler in its transaction)",
- "usage: createUsageReporter (openvibe-sdk/usage), the shared platform.usage-sample@1 reporter \u2014 validated readings queued idempotency-keyed in an outbox and relayed to Billing with retry, never dropped, refused readings kept",
+ "usage: createUsageReporter (openvibe-sdk/usage), the shared platform.usage-sample@1 reporter — validated readings queued idempotency-keyed in an outbox and relayed to Billing with retry, never dropped, refused readings kept",
"the HTTP telemetry kit (openvibe-sdk/service): the platform.telemetry-sample@1 middleware aggregated per route|method|status_class per flush, with active-requests, p95 and event-loop-lag gauges, lifted from Network's server/telemetry.js and server/observability.js",
"the HTTP telemetry kit (openvibe-sdk/service): the platform.telemetry-sample@1 middleware aggregated per route|method|status_class per flush, with active-requests, p95 and event-loop-lag gauges, lifted from Network's server/telemetry.js and server/observability.js",
"the telemetry sink (openvibe-sdk/telemetry): telemetrySchema() DDL, createPgTelemetrySink() and pruneTelemetry(), a per-service PostgreSQL table every service stores platform.telemetry-sample@1 into",
"the telemetry sink (openvibe-sdk/telemetry): telemetrySchema() DDL, createPgTelemetrySink() and pruneTelemetry(), a per-service PostgreSQL table every service stores platform.telemetry-sample@1 into",
"account-data (openvibe-sdk/account-data, ADR-033): telemetry_samples covered once by the SDK (exported as telemetry.json, anonymized on deletion), and uncovered() listing every table with a person column that no table map, task-keyed list or reasoned exemption covers",
"account-data (openvibe-sdk/account-data, ADR-033): telemetry_samples covered once by the SDK (exported as telemetry.json, anonymized on deletion), and uncovered() listing every table with a person column that no table map, task-keyed list or reasoned exemption covers",
"resources (openvibe-sdk/resources): the ADR-048 resource index fan-out and the idempotent control client",
"resources (openvibe-sdk/resources): the ADR-048 resource index fan-out and the idempotent control client",
"placement v1 (openvibe-sdk/placement): place() with the person's rules and ownership, the quality bar, cost per success, learn/successOf, escalate and the one-line reason; plan() takes the optional success map and never defaults to user-owned",
"placement v1 (openvibe-sdk/placement): place() with the person's rules and ownership, the quality bar, cost per success, learn/successOf, escalate and the one-line reason; plan() takes the optional success map and never defaults to user-owned",
- "consent (openvibe-sdk/consent): the L24 check before any use of a person's content or likeness for AI or data; allowed() and filter() (batches of 500), onChange() drops a subject's answers on network.consent.changed, mock() for tests; fails closed, caches 60 s, server-side"
+ "consent (openvibe-sdk/consent): the L24 check before any use of a person's content or likeness for AI or data; allowed() and filter() (batches of 500), onChange() drops a subject's answers on network.consent.changed, mock() for tests; fails closed, caches 60 s, server-side",
+ "openvibe-sdk/machines: the network's machines hub (list, get, catalogue, pair, rename, roles, revoke) against OpenVibe.Network, for a person and for the apps they consented to"
],
],
"updated": "2026-10-31"
"updated": "2026-10-31"
}
}
@@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
-// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.78.0, MIT). Do not edit.
+// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.79.0, MIT). Do not edit.
// One self-contained ES module: core at the top level plus the browser-safe subpaths as namespaces
// One self-contained ES module: core at the top level plus the browser-safe subpaths as namespaces
// (auth, registry, modules, realtime, media, community, bot, search, bench, vision, themes, redact, chat, ai, jobs, tools, projects, geo). No server-only code: no service tokens, JWT verification, events, identity.
// (auth, registry, modules, realtime, media, community, bot, search, bench, vision, themes, redact, chat, ai, jobs, tools, projects, geo). No server-only code: no service tokens, JWT verification, events, identity.
/* eslint-disable */
/* eslint-disable */
@@ -46,7 +46,7 @@ const { paginate, offsetPager } = __load(7);
@@ -46,7 +46,7 @@ const { paginate, offsetPager } = __load(7);
const semver = __load(6);
const semver = __load(6);
/** The package version (test/version.test.js keeps it equal to package.json). */
/** The package version (test/version.test.js keeps it equal to package.json). */
-const SDK_VERSION = '0.78.0';
+const SDK_VERSION = '0.79.0';
module.exports = {
module.exports = {
createClient,
createClient,
@@ -571,6 +571,11 @@
@@ -571,6 +571,11 @@
"openvibe-sdk/live": {
"openvibe-sdk/live": {
"createLiveClient": "function"
"createLiveClient": "function"
},
},
+ "openvibe-sdk/machines": {
+ "DEFAULT_TIMEOUT_MS": "number",
+ "MachinesError": "class",
+ "createMachines": "function"
+ },
"openvibe-sdk/media": {
"openvibe-sdk/media": {
"DEFAULT_PUBLIC_ORIGIN": "string",
"DEFAULT_PUBLIC_ORIGIN": "string",
"createMediaClient": "function",
"createMediaClient": "function",
new file mode 100644
new file mode 100644
@@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
+// Generated by scripts/esm.js from src/machines.js. Do not edit.
+import cjs from '../src/machines.js';
+
+export const {
+ createMachines, MachinesError, DEFAULT_TIMEOUT_MS,
+} = cjs;
+export default cjs;
@@ -1,12 +1,12 @@
@@ -1,12 +1,12 @@
{
{
"name": "openvibe-sdk",
"name": "openvibe-sdk",
- "version": "0.78.0",
+ "version": "0.79.0",
"lockfileVersion": 3,
"lockfileVersion": 3,
"requires": true,
"requires": true,
"packages": {
"packages": {
"": {
"": {
"name": "openvibe-sdk",
"name": "openvibe-sdk",
- "version": "0.78.0",
+ "version": "0.79.0",
"license": "MIT",
"license": "MIT",
"bin": {
"bin": {
"openvibe-download": "bin/openvibe-download.js"
"openvibe-download": "bin/openvibe-download.js"
@@ -14,7 +14,7 @@
@@ -14,7 +14,7 @@
"devDependencies": {
"devDependencies": {
"@electric-sql/pglite": "^0.5.8",
"@electric-sql/pglite": "^0.5.8",
"iovalkey": "^0.4.0",
"iovalkey": "^0.4.0",
- "openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.225.0",
+ "openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.261.0",
"pg": "^8.23.0"
"pg": "^8.23.0"
},
},
"engines": {
"engines": {
@@ -198,9 +198,9 @@
@@ -198,9 +198,9 @@
"license": "MIT"
"license": "MIT"
},
},
"node_modules/openvibe-contracts": {
"node_modules/openvibe-contracts": {
- "version": "0.225.0",
- "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.225.0",
- "integrity": "sha512-msLaRYa2Byyabnf/+L3aRPwkx8MI3zWbofFhwupq+RyBCdgbA4gLlkPsJu9nK/1UTCWdNdSTfWXW5pZY1/1zbQ==",
+ "version": "0.261.0",
+ "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.261.0",
+ "integrity": "sha512-SiXOcXRL9+WivMkKM1W6sGNJMD4uCBR9o7KYZvs99hT2xgYxDvP4rM7tLBudGu1boPH+coMdUXVQAAWbS/3JDw==",
"dev": true,
"dev": true,
"license": "AGPL-3.0-only",
"license": "AGPL-3.0-only",
"dependencies": {
"dependencies": {
@@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
{
{
"name": "openvibe-sdk",
"name": "openvibe-sdk",
- "version": "0.78.0",
+ "version": "0.79.0",
"description": "Supported browser and server clients for the OpenVibe platform: auth (incl. developer apps), registry discovery, identity, user modules, events, realtime, media, community, Bot robots, search, chat, AI runs, Tools (registry, run API and jobs), VIP memberships and developer projects, the async PostgreSQL data layer (db) and the Valkey cache, limits store, queue and pub/sub, with deadlines, safe retries, problem errors and trace propagation.",
"description": "Supported browser and server clients for the OpenVibe platform: auth (incl. developer apps), registry discovery, identity, user modules, events, realtime, media, community, Bot robots, search, chat, AI runs, Tools (registry, run API and jobs), VIP memberships and developer projects, the async PostgreSQL data layer (db) and the Valkey cache, limits store, queue and pub/sub, with deadlines, safe retries, problem errors and trace propagation.",
"main": "index.js",
"main": "index.js",
"types": "types/index.d.ts",
"types": "types/index.d.ts",
@@ -82,6 +82,11 @@
@@ -82,6 +82,11 @@
"import": "./esm/bot.mjs",
"import": "./esm/bot.mjs",
"default": "./src/bot.js"
"default": "./src/bot.js"
},
},
+ "./machines": {
+ "types": "./types/machines.d.ts",
+ "import": "./esm/machines.mjs",
+ "default": "./src/machines.js"
+ },
"./search": {
"./search": {
"types": "./types/search.d.ts",
"types": "./types/search.d.ts",
"import": "./esm/search.mjs",
"import": "./esm/search.mjs",
@@ -470,7 +475,7 @@
@@ -470,7 +475,7 @@
"devDependencies": {
"devDependencies": {
"@electric-sql/pglite": "^0.5.8",
"@electric-sql/pglite": "^0.5.8",
"iovalkey": "^0.4.0",
"iovalkey": "^0.4.0",
- "openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.225.0",
+ "openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.261.0",
"pg": "^8.23.0"
"pg": "^8.23.0"
},
},
"peerDependencies": {
"peerDependencies": {
@@ -26,6 +26,7 @@ const ENTRIES = {
@@ -26,6 +26,7 @@ const ENTRIES = {
'media.mjs': '../src/media.js',
'media.mjs': '../src/media.js',
'community.mjs': '../src/community.js',
'community.mjs': '../src/community.js',
'bot.mjs': '../src/bot.js',
'bot.mjs': '../src/bot.js',
+ 'machines.mjs': '../src/machines.js',
'search.mjs': '../src/search.js',
'search.mjs': '../src/search.js',
'bench.mjs': '../src/bench.js',
'bench.mjs': '../src/bench.js',
'themes.mjs': '../src/themes.js',
'themes.mjs': '../src/themes.js',
@@ -8,7 +8,7 @@ const { paginate, offsetPager } = require('./paginate');
@@ -8,7 +8,7 @@ const { paginate, offsetPager } = require('./paginate');
const semver = require('./semver');
const semver = require('./semver');
/** The package version (test/version.test.js keeps it equal to package.json). */
/** The package version (test/version.test.js keeps it equal to package.json). */
-const SDK_VERSION = '0.78.0';
+const SDK_VERSION = '0.79.0';
module.exports = {
module.exports = {
createClient,
createClient,
new file mode 100644
new file mode 100644
@@ -0,0 +1,104 @@
@@ -0,0 +1,104 @@
+'use strict';
+/**
+ * openvibe-sdk/machines — the network's machines hub (plan L34, step M2; Contracts 0.258.0).
+ *
+ * A person's machines are the network's: Bot stays the registry underneath, and OpenVibe.Network fronts it on
+ * openvibe.network/machines for the person and for the apps the person consented to. This module is the hub's API:
+ *
+ * // createMachines from the openvibe-sdk/machines entry (CommonJS or ESM)
+ * const machines = createMachines({ networkUrl: 'https://openvibe.network', token: () => sessionToken });
+ *
+ * await machines.list(); → { machines: [machine] } the person's own machines
+ * await machines.get(id); → { machine }
+ * await machines.catalogue(); → { roles: [role] } what a machine may do
+ * await machines.pair(); → { pairing } a one-time code and the command
+ * await machines.rename(id, 'Studio'); → { machine }
+ * await machines.roles(id, ['codes.worker']); → { machine } the whole set, not a change
+ * await machines.revoke(id); → { machine }
+ *
+ * The token is the caller's own: the person's session token, or an app's token holding network.machines.read or
+ * network.machines.manage with the person's consent. `token` may return the token or a promise of it.
+ *
+ * A refusal is an error with the hub's own status and code (`err.status`, `err.code`): 403 capability.denied when
+ * the caller holds no capability, 403 capability.owner_denied when the app's consent is gone, 404 when the machine
+ * is not the caller's, 422 when a role is not in the catalogue.
+ *
+ * The machines' own capabilities (a computer, a desk, a model on it) stay where they are: openvibe-sdk/bot's
+ * machines.desk() and machines.chat() talk to Bot itself and are unchanged.
+ */
+const DEFAULT_TIMEOUT_MS = 10_000;
+
+/** The error a refusal carries: the hub's status and code, so a caller can tell them apart. */
+class MachinesError extends Error {
+ constructor(status, code, message) {
+ super(message || code || `the hub answered ${status}`);
+ this.name = 'MachinesError';
+ this.status = status;
+ this.code = code || 'machines.failed';
+ }
+}
+
+/**
+ * The machines client.
+ * networkUrl OpenVibe.Network's base URL
+ * token () => the caller's bearer token (a person session, or an app's consented token)
+ * fetch the fetch implementation (default globalThis.fetch)
+ * timeoutMs the deadline of one call (default 10 s)
+ */
+function createMachines({ networkUrl, token, fetch: fetchImpl = globalThis.fetch, timeoutMs = DEFAULT_TIMEOUT_MS } = {}) {
+ if (!networkUrl || typeof networkUrl !== 'string') throw new TypeError('createMachines: networkUrl is required');
+ if (typeof token !== 'function') throw new TypeError('createMachines: token must be a function returning a bearer token');
+ if (typeof fetchImpl !== 'function') throw new TypeError('createMachines: a fetch implementation is required');
+ const base = String(networkUrl).replace(/\/+$/, '');
+
+ async function call(method, path, body) {
+ const bearer = await token();
+ if (!bearer) throw new MachinesError(401, 'token.invalid', 'no token');
+ const controller = new AbortController();
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
+ let res;
+ try {
+ res = await fetchImpl(`${base}${path}`, {
+ method,
+ headers: {
+ authorization: `Bearer ${bearer}`, accept: 'application/json',
+ ...(body === undefined ? {} : { 'content-type': 'application/json' }),
+ },
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
+ signal: controller.signal,
+ });
+ } catch (e) {
+ clearTimeout(timer);
+ const aborted = e && (e.name === 'AbortError' || e.code === 'ABORT_ERR');
+ throw new MachinesError(0, aborted ? 'machines.timeout' : 'machines.unreachable', aborted ? `the hub did not answer within ${timeoutMs} ms` : `the hub is not reachable: ${e.message}`);
+ }
+ clearTimeout(timer);
+ const out = await res.json().catch(() => null);
+ if (!res.ok) {
+ const code = (out && out.code) || `machines.failed`;
+ throw new MachinesError(res.status, code, (out && (out.detail || out.error || out.title)) || `the hub answered ${res.status}`);
+ }
+ return out || {};
+ }
+
+ const enc = (id) => encodeURIComponent(String(id == null ? '' : id));
+
+ return {
+ /** The caller's machines: { machines }. */
+ list: () => call('GET', '/api/v1/machines'),
+ /** One machine: { machine }. A machine that is not the caller's is a 404. */
+ get: (id) => call('GET', `/api/v1/machines/${enc(id)}`),
+ /** The catalogue of roles: { roles } — what a machine may do for the network. */
+ catalogue: () => call('GET', '/api/v1/machines/roles'),
+ /** A one-time pairing code and the command to run on the machine: { pairing }. */
+ pair: () => call('POST', '/api/v1/machines/pairings', {}),
+ /** A new name for the machine: { machine }. */
+ rename: (id, name) => call('PATCH', `/api/v1/machines/${enc(id)}`, { name: String(name == null ? '' : name) }),
+ /** The machine's roles — the whole set, not a change: { machine }. */
+ roles: (id, roles) => call('PUT', `/api/v1/machines/${enc(id)}/roles`, { roles: Array.isArray(roles) ? roles : [] }),
+ /** The machine is no longer the caller's: { machine }. */
+ revoke: (id) => call('POST', `/api/v1/machines/${enc(id)}/revoke`, {}),
+ };
+}
+
+module.exports = { createMachines, MachinesError, DEFAULT_TIMEOUT_MS };
new file mode 100644
new file mode 100644
@@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
+'use strict';
+/**
+ * openvibe-sdk/machines (plan L34, step M2): the network's machines hub. What this proves:
+ * - every call goes to the hub's own route with the caller's bearer token;
+ * - the answers are the hub's own shapes (machines, machine, roles, pairing);
+ * - a refusal is an error with the hub's status and code, so a caller can tell them apart;
+ * - a hub that does not answer is a timeout, not a hang.
+ */
+const assert = require('node:assert/strict');
+const { stubServer, send, run, sleep } = require('./helpers');
+const { createMachines, DEFAULT_TIMEOUT_MS } = require('../src/machines');
+
+const MACHINE = { id: 'dev_01ARZ3NDEKTSV4RRFFQ69G5FAV', kind: 'server', online: true, roles: ['codes.worker'], running: [] };
+
+async function hub(answer) {
+ const state = { requests: [], token: 'person-token' };
+ const stub = await stubServer(async (req, res, body) => {
+ state.requests.push({ method: req.method, url: req.url, headers: req.headers, body: body ? body.toString() : '' });
+ const a = answer(req, body, state.requests.length);
+ if (!a || a.hang) return await new Promise(() => {});
+ if (a.delayMs) await sleep(a.delayMs);
+ send(res, a.status || 200, a.body === undefined ? '' : a.body);
+ });
+ return { stub, state };
+}
+
+run([
+ ['the default timeout is ten seconds', async () => {
+ assert.equal(DEFAULT_TIMEOUT_MS, 10_000);
+ }],
+
+ ['the calls are the hub\'s own routes, with the caller\'s token', async () => {
+ const { stub, state } = await hub((req) => {
+ if (req.url === '/api/v1/machines' && req.method === 'GET') return { body: { machines: [MACHINE] } };
+ if (req.url === '/api/v1/machines/roles') return { body: { roles: [{ id: 'codes.worker', name: 'Codes worker', installs: 'the runner', shows: 'Runs your coding jobs.' }] } };
+ if (req.url.endsWith('/roles') && req.method === 'PUT') return { body: { machine: { ...MACHINE, roles: ['codes.worker', 'desks.host'] } } };
+ if (req.url.endsWith('/revoke')) return { body: { machine: { ...MACHINE, online: false } } };
+ if (req.url === '/api/v1/machines/pairings') return { body: { pairing: { code: 'ABCD-EFGH', expires_at: '2026-10-31T12:00:00.000Z', installer: 'curl -fsSL https://openvibe.bot/install | sh' } } };
+ if (req.method === 'PATCH') return { body: { machine: { ...MACHINE, name: 'Studio' } } };
+ return { body: { machine: MACHINE } };
+ });
+ const machines = createMachines({ networkUrl: stub.url, token: () => state.token });
+ try {
+ const list = await machines.list();
+ assert.equal(list.machines.length, 1);
+ assert.equal(list.machines[0].id, MACHINE.id);
+ assert.equal((await machines.get(MACHINE.id)).machine.kind, 'server');
+ assert.equal((await machines.catalogue()).roles[0].id, 'codes.worker');
+ assert.equal((await machines.pair()).pairing.code, 'ABCD-EFGH');
+ assert.equal((await machines.rename(MACHINE.id, 'Studio')).machine.name, 'Studio');
+ assert.deepEqual((await machines.roles(MACHINE.id, ['codes.worker', 'desks.host'])).machine.roles, ['codes.worker', 'desks.host']);
+ assert.equal((await machines.revoke(MACHINE.id)).machine.online, false);
+ for (const r of state.requests) {
+ assert.equal(r.headers.authorization, 'Bearer person-token', 'every call carries the caller\'s token');
+ }
+ assert.equal(state.requests[4].body, JSON.stringify({ name: 'Studio' }));
+ assert.equal(state.requests[5].body, JSON.stringify({ roles: ['codes.worker', 'desks.host'] }));
+ } finally { await stub.close(); }
+ }],
+
+ ['a refusal is an error with the hub\'s status and code', async () => {
+ const { stub } = await hub(() => ({ status: 403, body: { code: 'capability.denied', detail: 'network.machines.read not granted' } }));
+ const machines = createMachines({ networkUrl: stub.url, token: () => 'person-token' });
+ try {
+ await assert.rejects(() => machines.list(), (e) => {
+ assert.equal(e.name, 'MachinesError');
+ assert.equal(e.status, 403);
+ assert.equal(e.code, 'capability.denied');
+ return true;
+ });
+ } finally { await stub.close(); }
+ }],
+
+ ['a hub that does not answer is a timeout, not a hang', async () => {
+ const { stub } = await hub(() => ({ hang: true }));
+ const machines = createMachines({ networkUrl: stub.url, token: () => 'person-token', timeoutMs: 200 });
+ try {
+ await assert.rejects(() => machines.list(), (e) => {
+ assert.equal(e.code, 'machines.timeout');
+ return true;
+ });
+ } finally { await stub.close(); }
+ }],
+
+ ['no token is refused before anything is asked', async () => {
+ const { stub, state } = await hub(() => ({ body: { machines: [] } }));
+ const machines = createMachines({ networkUrl: stub.url, token: () => '' });
+ try {
+ await assert.rejects(() => machines.list(), (e) => e.code === 'token.invalid');
+ assert.equal(state.requests.length, 0, 'the hub was never asked');
+ } finally { await stub.close(); }
+ }],
+]);
@@ -68,7 +68,7 @@ run([
@@ -68,7 +68,7 @@ run([
})().catch((err) => { console.error(err); process.exit(1); });`;
})().catch((err) => { console.error(err); process.exit(1); });`;
const res = execFileSync(process.execPath, ['-e', script], { cwd: app, encoding: 'utf8' });
const res = execFileSync(process.execPath, ['-e', script], { cwd: app, encoding: 'utf8' });
assert.match(res, new RegExp(`consumer ok: ${subpaths.length} subpaths \\+ the browser bundle`));
assert.match(res, new RegExp(`consumer ok: ${subpaths.length} subpaths \\+ the browser bundle`));
- assert.equal(subpaths.length, 73); // 0.78.0 adds openvibe-sdk/consent
+ assert.equal(subpaths.length, 74); // 0.79.0 adds openvibe-sdk/machines
assert.ok(!fs.existsSync(path.join(app, 'node_modules/openvibe-contracts')), 'the optional peer is not installed');
assert.ok(!fs.existsSync(path.join(app, 'node_modules/openvibe-contracts')), 'the optional peer is not installed');
} finally {
} finally {
fs.rmSync(tmp, { recursive: true, force: true });
fs.rmSync(tmp, { recursive: true, force: true });
@@ -125,7 +125,7 @@ export interface Problem {
@@ -125,7 +125,7 @@ export interface Problem {
[k: string]: unknown | undefined;
[k: string]: unknown | undefined;
}
}
-/** [email protected] (owner: network) */
+/** [email protected] (owner: network) */
/**
/**
* What a service is, where it lives and what it offers. The ecosystem registry is built from these, not from hard-coded route maps.
* What a service is, where it lives and what it offers. The ecosystem registry is built from these, not from hard-coded route maps.
*/
*/
@@ -1924,11 +1924,21 @@ export interface ServiceManifest {
@@ -1924,11 +1924,21 @@ export interface ServiceManifest {
*/
*/
statusApi?: string;
statusApi?: string;
};
};
+ /**
+ * The room's launcher group in OpenVibe.Shared rooms.js and OpenVibe.Network frame/sites.js; optional so older manifests retain their meaning.
+ */
+ neighbourhood?: "streams" | "games" | "answers" | "make" | "shop" | "people" | "build";
};
};
capabilities: string[];
capabilities: string[];
eventsProduced: string[];
eventsProduced: string[];
eventsConsumed: string[];
eventsConsumed: string[];
namespacesOwned: string[];
namespacesOwned: string[];
+ machineRoles?: {
+ id: string;
+ name: string;
+ installs: string;
+ shows: string;
+ }[];
contractRanges?: {
contractRanges?: {
[k: string]: string | undefined;
[k: string]: string | undefined;
};
};
new file mode 100644
new file mode 100644
@@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
+/** openvibe-sdk/machines: the network's machines hub (plan L34; Contracts 0.258.0). */
+
+/** One machine as the hub shows it (network.machine@1). */
+export interface Machine {
+ /** Bot's device id (dev_…). */
+ id: string;
+ /** onboard (a robot's machine), bridge or server (a machine that runs its owner's jobs). */
+ kind: 'onboard' | 'bridge' | 'server';
+ /** Whether the machine is connected to Bot right now. */
+ online: boolean;
+ /** What the machine does for the network: the ids from the catalogue. */
+ roles: string[];
+ /** What it does right now: its Codes jobs, its desks, its local models, its robots. */
+ running: Array<{ kind: 'codes.jobs' | 'desks' | 'models' | 'robots'; count: number; label?: string }>;
+ /** The node principal on Network (nod_…), when it has one. */
+ principal_id?: string;
+ /** The name the owner gave it. */
+ name?: string;
+ /** The operating system the machine reports. */
+ os?: string;
+ /** When the machine was last seen. */
+ last_seen_at?: string;
+ /** The OpenVibe Node version the machine reports. */
+ node_version?: string;
+}
+
+/** One role of the catalogue (network.machine-role@1). */
+export interface MachineRole {
+ id: string;
+ name: string;
+ /** What the role installs on the machine. */
+ installs: string;
+ /** What the hub shows for a machine with this role. */
+ shows: string;
+}
+
+/** A one-time pairing code and the command to run on the machine (network.machine-pairing@1). */
+export interface MachinePairing {
+ code: string;
+ expires_at: string;
+ installer: string;
+ pairing_id?: string;
+}
+
+export interface MachinesClientOptions {
+ /** OpenVibe.Network's base URL. */
+ networkUrl: string;
+ /** The caller's bearer token: the person's session token, or an app's consented token. */
+ token: () => string | Promise<string>;
+ fetch?: typeof fetch;
+ timeoutMs?: number;
+}
+
+export interface MachinesClient {
+ /** The caller's own machines. */
+ list(): Promise<{ machines: Machine[] }>;
+ /** One machine; a machine that is not the caller's is a 404. */
+ get(id: string): Promise<{ machine: Machine }>;
+ /** The catalogue of roles: what a machine may do for the network. */
+ catalogue(): Promise<{ roles: MachineRole[] }>;
+ /** A one-time pairing code and the command to run on the machine. */
+ pair(): Promise<{ pairing: MachinePairing }>;
+ /** A new name for the machine. */
+ rename(id: string, name: string): Promise<{ machine: Machine }>;
+ /** The machine's roles — the whole set, not a change. */
+ roles(id: string, roles: string[]): Promise<{ machine: Machine }>;
+ /** The machine is no longer the caller's. */
+ revoke(id: string): Promise<{ machine: Machine }>;
+}
+
+/** A refusal: the hub's own status and code (err.status, err.code). */
+export declare class MachinesError extends Error {
+ status: number;
+ code: string;
+}
+
+export declare function createMachines(options: MachinesClientOptions): MachinesClient;
+export declare const DEFAULT_TIMEOUT_MS: number;