Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

store the managed-visitor bridge token in the private credential store, resolved live

[._.]/ Adam Eivy52c3c3877dd5
diff --git a/server/lib/credentialRegistry.js b/server/lib/credentialRegistry.js
index 62092ab84f..4f1a8ea4f5 100644
--- a/server/lib/credentialRegistry.js
+++ b/server/lib/credentialRegistry.js
@@ -219,6 +219,18 @@ export const CREDENTIALS = Object.freeze([
settingsPath: null,
configurePath: '/ai',
}),
+ Object.freeze({
+ id: 'eidoverse-visitor-token',
+ privateStore: true,
+ label: 'Eidoverse Visitor Bridge',
+ unlocks: 'The managed-visitor broker\'s shared host credential, letting an app the owner explicitly provisions (e.g. Fly Garden) admit a paused body into an allowlisted Eidoverse world.',
+ tier: 'none',
+ getUrl: null,
+ envVars: Object.freeze(['PORTOS_EIDOVERSE_VISITOR_TOKEN']),
+ settingsPath: 'secrets.eidoverse.visitorToken',
+ configurePath: '/settings/credentials',
+ feature: 'eidoverse',
+ }),
]);
export const CREDENTIAL_IDS = Object.freeze(CREDENTIALS.map((credential) => credential.id));
diff --git a/server/services/managedVisitorHost.js b/server/services/managedVisitorHost.js
index 47fab5030a..7e326a3ac8 100644
--- a/server/services/managedVisitorHost.js
+++ b/server/services/managedVisitorHost.js
@@ -1,10 +1,30 @@
import { ServerError } from '../lib/errorHandler.js';
+// Settings win over the env var so the owner can set/rotate the credential from
+// Settings > Credentials without restarting PortOS — same precedence and
+// rationale as `resolveCivitaiKey` in services/loras.js. Resolved fresh on every
+// call (getSettings reads its JSON file each time; cheap, and avoids a stale
+// in-memory token surviving a rotation).
+async function resolveVisitorToken() {
+ const env = (process.env.PORTOS_EIDOVERSE_VISITOR_TOKEN || '').trim();
+ const { getSettings } = await import('./settings.js');
+ const settings = await getSettings();
+ const fromSettings = (settings?.secrets?.eidoverse?.visitorToken || '').trim();
+ return fromSettings || env || '';
+}
+
/** Explicitly configured local host only; construction and disabled capability reads make no requests. */
-export function createManagedVisitorHost({ token = process.env.PORTOS_EIDOVERSE_VISITOR_TOKEN, fetchImpl = fetch, port = 8940 } = {}) {
+export function createManagedVisitorHost({ token, fetchImpl = fetch, port = 8940 } = {}) {
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new ServerError('Invalid managed visitor host port.', { status: 400 });
- const enabled = typeof token === 'string' && /^[a-f0-9]{64}$/.test(token);
+ // An explicitly passed `token` (including '' in tests) is honored verbatim and
+ // resolved statically, exactly as before. Omitting it entirely resolves fresh
+ // from settings/env on every call, so a credential rotation takes effect
+ // immediately rather than only at the next process restart.
+ const explicitToken = typeof token === 'string' ? token : undefined;
+ const resolveToken = explicitToken !== undefined ? async () => explicitToken : resolveVisitorToken;
async function request(path, body, deadlineMs) {
+ const token = await resolveToken();
+ const enabled = /^[a-f0-9]{64}$/.test(token);
if (!enabled) throw new ServerError('Managed visitor host credential is not configured.', { status: 409 });
if (path === '/admissions' && (!Number.isSafeInteger(deadlineMs) || deadlineMs <= Date.now())) throw new ServerError('Invalid managed visitor admission deadline.', { status: 409 });
const response = await fetchImpl(`http://127.0.0.1:${port}/api/managed-visitors/v1${path}`, {
@@ -25,7 +45,11 @@ export function createManagedVisitorHost({ token = process.env.PORTOS_EIDOVERSE_
.catch(() => { throw new ServerError('Managed visitor host returned invalid JSON.', { status: 409 }); });
}
return {
- capabilities: () => enabled ? request('/version').then(value => value.capabilities, () => null) : Promise.resolve(null),
+ capabilities: async () => {
+ const token = await resolveToken();
+ if (!/^[a-f0-9]{64}$/.test(token)) return null;
+ return request('/version').then(value => value.capabilities, () => null);
+ },
admit: (body, { deadlineMs } = {}) => request('/admissions', body, deadlineMs),
observe: (id, body) => request(`/sessions/${encodeURIComponent(id)}/observations`, body),
leave: (id, body) => request(`/sessions/${encodeURIComponent(id)}/leave`, body),
diff --git a/server/services/managedVisitorHost.test.js b/server/services/managedVisitorHost.test.js
index ee884f55d8..f584b8835e 100644
--- a/server/services/managedVisitorHost.test.js
+++ b/server/services/managedVisitorHost.test.js
@@ -18,3 +18,30 @@ it('host response buffering is bounded and malformed/non-success replies do not
fetchImpl.mockResolvedValueOnce(new Response('not json')); expect(await host.capabilities()).toBe(null);
fetchImpl.mockResolvedValueOnce(new Response('{}', { status: 401 })); await expect(host.admit({}, { deadlineMs: Date.now() + 1000 })).rejects.toThrow(/refused/);
});
+it('an omitted token resolves live from settings (winning over the env var) or falls back to it, with no caching across calls', async () => {
+ const originalEnv = process.env.PORTOS_EIDOVERSE_VISITOR_TOKEN;
+ const envToken = 'e'.repeat(64), settingsToken = 'a'.repeat(64);
+ process.env.PORTOS_EIDOVERSE_VISITOR_TOKEN = envToken;
+ try {
+ vi.resetModules();
+ let stubbedSettings = { secrets: { eidoverse: { visitorToken: settingsToken } } };
+ vi.doMock('./settings.js', () => ({ getSettings: async () => stubbedSettings }));
+ const { createManagedVisitorHost: createHost } = await import('./managedVisitorHost.js');
+ const fetchImpl = vi.fn(async () => new Response(JSON.stringify({ capabilities: { managedVisitors: null } })));
+ const host = createHost({ fetchImpl }); // no explicit token: must resolve live
+ await host.capabilities();
+ expect(fetchImpl.mock.calls[0][1].headers.Authorization).toBe(`Bearer ${settingsToken}`); // settings wins over env
+
+ stubbedSettings = { secrets: {} }; // settings cleared — must fall back to env, not a cached settings value
+ await host.capabilities();
+ expect(fetchImpl.mock.calls[1][1].headers.Authorization).toBe(`Bearer ${envToken}`);
+
+ stubbedSettings = {}; process.env.PORTOS_EIDOVERSE_VISITOR_TOKEN = '';
+ expect(await host.capabilities()).toBe(null); // neither source configured: disabled, no request made
+ expect(fetchImpl).toHaveBeenCalledTimes(2);
+ } finally {
+ vi.doUnmock('./settings.js'); vi.resetModules();
+ if (originalEnv === undefined) delete process.env.PORTOS_EIDOVERSE_VISITOR_TOKEN;
+ else process.env.PORTOS_EIDOVERSE_VISITOR_TOKEN = originalEnv;
+ }
+});