2026-06-02 16:04:49 +01:00
"use strict" ;
const fs = require ( "fs" ) ;
2026-06-16 22:39:03 +01:00
const { createRequire } = require ( "module" ) ;
2026-06-16 21:59:36 +01:00
const path = require ( "path" ) ;
2026-07-04 22:38:43 +01:00
const { fileURLToPath } = require ( "url" ) ;
const { stableId } = require ( "./utils.cjs" ) ;
2026-06-02 16:04:49 +01:00
2026-06-16 22:39:03 +01:00
const requireCultCacheInspection = createRequire (
path . resolve ( _ _dirname , ".." , ".." , ".." , "CultLib" , "packages" , "cultcache-ts" , "package.json" ) ,
) ;
const { inspectCultCacheBytes } = requireCultCacheInspection ( "./dist/cult-cache-inspector.js" ) ;
2026-06-02 16:04:49 +01:00
function createInterfaceDiscovery ( {
CultMesh ,
documents ,
interfaceBindingStores ,
2026-06-23 22:07:04 +01:00
liveProviderRegistry ,
2026-06-02 16:04:49 +01:00
} ) {
async function discoverInterfaces ( ) {
2026-06-23 18:36:59 +01:00
const { interfaces } = await discoverAll ( ) ;
return interfaces ;
}
async function discoverProviderAdvertisements ( ) {
const { providerAdvertisements } = await discoverAll ( ) ;
return providerAdvertisements ;
}
async function discoverAll ( ) {
const { interfaces : cultMeshInterfaces , providerAdvertisements } = await discoverCultMeshEntries ( ) ;
2026-06-23 22:07:04 +01:00
const liveAnnouncements = liveProviderRegistry ? . snapshot ? . ( ) || {
interfaces : [ ] ,
providerAdvertisements : [ ] ,
} ;
2026-06-02 16:04:49 +01:00
2026-07-04 22:38:43 +01:00
const interfaces = [ ] ;
2026-06-23 22:07:04 +01:00
for ( const entry of [ ... cultMeshInterfaces , ... liveAnnouncements . interfaces ] ) {
2026-06-02 16:04:49 +01:00
const existingIndex = interfaces . findIndex ( ( candidate ) => candidate . providerId === entry . providerId ) ;
if ( existingIndex >= 0 ) {
interfaces [ existingIndex ] = entry ;
} else {
interfaces . push ( entry ) ;
}
}
interfaces . sort ( ( left , right ) => left . providerId . localeCompare ( right . providerId ) ) ;
2026-06-23 22:07:04 +01:00
const allProviderAdvertisements = [ ... providerAdvertisements , ... liveAnnouncements . providerAdvertisements ] ;
const providersById = new Map ( ) ;
for ( const provider of allProviderAdvertisements ) {
if ( provider ? . id ) {
2026-07-04 22:38:43 +01:00
const existing = providersById . get ( String ( provider . id ) ) ;
providersById . set ( String ( provider . id ) , mergeProviderAdvertisement ( existing , provider ) ) ;
2026-06-23 22:07:04 +01:00
}
}
return {
interfaces ,
providerAdvertisements : [ ... providersById . values ( ) ] . sort ( ( left , right ) => String ( left . id ) . localeCompare ( String ( right . id ) ) ) ,
} ;
2026-06-02 16:04:49 +01:00
}
2026-06-23 18:36:59 +01:00
function cultMeshDocumentsAvailable ( ) {
2026-06-04 14:42:35 +01:00
const {
interfaceBindingDefinition ,
2026-07-04 22:38:43 +01:00
idunnCommandBoundaryDefinition ,
2026-06-16 12:47:59 +01:00
idunnDaemonHealthDefinition ,
2026-07-04 22:38:43 +01:00
idunnTransportProfileDefinition ,
2026-06-16 21:45:52 +01:00
muninnCaptureStreamDefinition ,
muninnCommandBoundaryDefinition ,
2026-06-16 21:59:36 +01:00
muninnMoveControllerStateDefinition ,
2026-06-23 17:04:07 +01:00
muninnMoveIdentityDefinition ,
2026-06-16 21:59:36 +01:00
muninnMoveLightCommandDefinition ,
muninnMoveMarkerCandidateDefinition ,
2026-06-16 21:45:52 +01:00
muninnObsStreamCatalogDefinition ,
muninnQuestAccessDefinition ,
muninnTelemetrySurfaceDefinition ,
muninnTransportProfileDefinition ,
2026-06-16 11:01:27 +01:00
operatorStateDefinition ,
2026-06-04 14:42:35 +01:00
providerAdvertisementDefinition ,
2026-07-04 22:38:43 +01:00
voidbotProviderCatalogDefinition ,
2026-06-16 12:04:26 +01:00
stonksCommandBoundaryDefinition ,
stonksMarketSnapshotDefinition ,
stonksRequestEventDefinition ,
stonksTransportProfileDefinition ,
2026-06-16 12:47:59 +01:00
streamPixelsCommandBoundaryDefinition ,
streamPixelsTransportProfileDefinition ,
2026-06-04 14:42:35 +01:00
surfaceDefinition ,
2026-06-16 11:01:27 +01:00
viliCommandBoundaryDefinition ,
viliTransportProfileDefinition ,
2026-06-16 11:31:02 +01:00
weksaCommandBoundaryDefinition ,
weksaOperatorStateDefinition ,
weksaTransportProfileDefinition ,
2026-06-04 14:42:35 +01:00
voidbotSwarmSnapshotDefinition ,
} = documents ;
2026-06-23 18:36:59 +01:00
return Boolean (
CultMesh &&
interfaceBindingDefinition &&
2026-07-04 22:38:43 +01:00
idunnCommandBoundaryDefinition &&
2026-06-23 18:36:59 +01:00
idunnDaemonHealthDefinition &&
2026-07-04 22:38:43 +01:00
idunnTransportProfileDefinition &&
2026-06-23 18:36:59 +01:00
muninnCaptureStreamDefinition &&
muninnCommandBoundaryDefinition &&
muninnMoveControllerStateDefinition &&
muninnMoveIdentityDefinition &&
muninnMoveLightCommandDefinition &&
muninnMoveMarkerCandidateDefinition &&
muninnObsStreamCatalogDefinition &&
muninnQuestAccessDefinition &&
muninnTelemetrySurfaceDefinition &&
muninnTransportProfileDefinition &&
operatorStateDefinition &&
providerAdvertisementDefinition &&
2026-07-04 22:38:43 +01:00
voidbotProviderCatalogDefinition &&
2026-06-23 18:36:59 +01:00
stonksCommandBoundaryDefinition &&
stonksMarketSnapshotDefinition &&
stonksRequestEventDefinition &&
stonksTransportProfileDefinition &&
streamPixelsCommandBoundaryDefinition &&
streamPixelsTransportProfileDefinition &&
surfaceDefinition &&
viliCommandBoundaryDefinition &&
viliTransportProfileDefinition &&
weksaCommandBoundaryDefinition &&
weksaOperatorStateDefinition &&
weksaTransportProfileDefinition &&
voidbotSwarmSnapshotDefinition
) ;
}
2026-06-04 14:42:35 +01:00
2026-06-23 18:36:59 +01:00
async function discoverCultMeshEntries ( ) {
2026-06-02 16:04:49 +01:00
const {
interfaceBindingDefinition ,
2026-07-04 22:38:43 +01:00
idunnCommandBoundaryDefinition ,
2026-06-16 12:47:59 +01:00
idunnDaemonHealthDefinition ,
2026-07-04 22:38:43 +01:00
idunnTransportProfileDefinition ,
2026-06-16 21:45:52 +01:00
muninnCaptureStreamDefinition ,
muninnCommandBoundaryDefinition ,
2026-06-16 21:59:36 +01:00
muninnMoveControllerStateDefinition ,
2026-06-23 17:04:07 +01:00
muninnMoveIdentityDefinition ,
2026-06-16 21:59:36 +01:00
muninnMoveLightCommandDefinition ,
muninnMoveMarkerCandidateDefinition ,
2026-06-16 21:45:52 +01:00
muninnObsStreamCatalogDefinition ,
muninnQuestAccessDefinition ,
muninnTelemetrySurfaceDefinition ,
muninnTransportProfileDefinition ,
2026-06-16 11:01:27 +01:00
operatorStateDefinition ,
2026-06-02 16:04:49 +01:00
providerAdvertisementDefinition ,
2026-07-04 22:38:43 +01:00
voidbotProviderCatalogDefinition ,
2026-06-16 12:04:26 +01:00
stonksCommandBoundaryDefinition ,
stonksMarketSnapshotDefinition ,
stonksRequestEventDefinition ,
stonksTransportProfileDefinition ,
2026-06-16 12:47:59 +01:00
streamPixelsCommandBoundaryDefinition ,
streamPixelsTransportProfileDefinition ,
2026-06-02 16:04:49 +01:00
surfaceDefinition ,
2026-06-16 11:01:27 +01:00
viliCommandBoundaryDefinition ,
viliTransportProfileDefinition ,
2026-06-16 11:31:02 +01:00
weksaCommandBoundaryDefinition ,
weksaOperatorStateDefinition ,
weksaTransportProfileDefinition ,
2026-06-02 16:04:49 +01:00
voidbotSwarmSnapshotDefinition ,
} = documents ;
2026-06-23 18:36:59 +01:00
if ( ! cultMeshDocumentsAvailable ( ) ) {
return { interfaces : [ ] , providerAdvertisements : [ ] } ;
2026-06-02 16:04:49 +01:00
}
2026-06-23 18:36:59 +01:00
const nodeDocuments = [
voidbotSwarmSnapshotDefinition ,
stonksRequestEventDefinition ,
stonksMarketSnapshotDefinition ,
providerAdvertisementDefinition ,
2026-07-04 22:38:43 +01:00
voidbotProviderCatalogDefinition ,
2026-06-23 18:36:59 +01:00
interfaceBindingDefinition ,
surfaceDefinition ,
2026-07-04 22:38:43 +01:00
idunnCommandBoundaryDefinition ,
idunnTransportProfileDefinition ,
2026-06-23 18:36:59 +01:00
stonksCommandBoundaryDefinition ,
stonksTransportProfileDefinition ,
streamPixelsCommandBoundaryDefinition ,
streamPixelsTransportProfileDefinition ,
idunnDaemonHealthDefinition ,
muninnCaptureStreamDefinition ,
muninnCommandBoundaryDefinition ,
muninnMoveControllerStateDefinition ,
muninnMoveIdentityDefinition ,
muninnMoveLightCommandDefinition ,
muninnMoveMarkerCandidateDefinition ,
muninnObsStreamCatalogDefinition ,
muninnQuestAccessDefinition ,
muninnTelemetrySurfaceDefinition ,
muninnTransportProfileDefinition ,
operatorStateDefinition ,
viliCommandBoundaryDefinition ,
viliTransportProfileDefinition ,
weksaOperatorStateDefinition ,
weksaCommandBoundaryDefinition ,
weksaTransportProfileDefinition ,
] ;
const storeEntries = await Promise . all ( interfaceBindingStores . map ( async ( storeSpec ) => {
2026-06-16 22:39:03 +01:00
let resolvedStore = null ;
2026-06-02 16:04:49 +01:00
try {
2026-06-16 22:39:03 +01:00
resolvedStore = resolveInterfaceBindingStore ( storeSpec ) ;
2026-06-16 21:59:36 +01:00
if ( ! resolvedStore ) {
2026-06-23 18:36:59 +01:00
return { interfaces : [ ] , providerAdvertisements : [ ] } ;
2026-06-16 21:59:36 +01:00
}
const { localPath : storePath , sourceId } = resolvedStore ;
2026-06-02 16:04:49 +01:00
if ( ! fs . existsSync ( storePath ) ) {
2026-06-23 18:36:59 +01:00
return { interfaces : [ ] , providerAdvertisements : [ ] } ;
2026-06-02 16:04:49 +01:00
}
2026-06-23 18:36:59 +01:00
const node = await CultMesh . createNode ( storePath , { documents : nodeDocuments } ) ;
2026-07-04 22:38:43 +01:00
const typed = inspectCultMeshStore ( {
2026-06-23 18:36:59 +01:00
documents ,
interfaceBindingDefinition ,
muninnTelemetrySurfaceDefinition ,
node ,
providerAdvertisementDefinition ,
sourceId ,
storePath ,
2026-06-02 16:04:49 +01:00
} ) ;
2026-07-04 22:38:43 +01:00
const inspected = inspectCultMeshStoreBytes ( storePath , sourceId ) ;
return {
interfaces : mergeInterfaces ( [ ... typed . interfaces , ... inspected . interfaces ] ) ,
providerAdvertisements : mergeProviderAdvertisements ( [
... typed . providerAdvertisements ,
... inspected . providerAdvertisements ,
] ) ,
} ;
2026-06-02 16:04:49 +01:00
} catch ( error ) {
2026-06-23 18:36:59 +01:00
const interfaces = [ ] ;
const providerAdvertisements = [ ] ;
2026-06-16 22:39:03 +01:00
if ( resolvedStore ? . localPath && fs . existsSync ( resolvedStore . localPath ) ) {
2026-07-04 22:38:43 +01:00
try {
const inspected = inspectCultMeshStoreBytes ( resolvedStore . localPath , resolvedStore . sourceId ) ;
interfaces . push ( ... inspected . interfaces ) ;
providerAdvertisements . push ( ... inspected . providerAdvertisements ) ;
} catch ( fallbackError ) {
if ( fallbackError ? . code !== "ENOENT" ) {
throw fallbackError ;
}
}
2026-06-16 22:39:03 +01:00
}
2026-06-23 18:36:59 +01:00
if ( interfaces . length === 0 ) {
interfaces . push ( dashboardUnavailable ( ` cultmesh: ${ storeSpec } ` , ` cultmesh: ${ storeSpec } ` , error . message ) ) ;
}
return { interfaces , providerAdvertisements } ;
2026-06-23 17:04:07 +01:00
} finally {
resolvedStore ? . cleanup ? . ( ) ;
2026-06-02 16:04:49 +01:00
}
2026-06-23 18:36:59 +01:00
} ) ) ;
return {
interfaces : storeEntries . flatMap ( ( entry ) => entry . interfaces ) ,
providerAdvertisements : storeEntries . flatMap ( ( entry ) => entry . providerAdvertisements ) ,
} ;
2026-06-02 16:04:49 +01:00
}
return {
2026-06-23 18:36:59 +01:00
discoverAll ,
2026-06-04 14:42:35 +01:00
discoverProviderAdvertisements ,
2026-06-02 16:04:49 +01:00
discoverInterfaces ,
} ;
}
2026-06-16 11:01:27 +01:00
function cultMeshProviderInterface ( {
advertisement ,
state ,
storePath ,
operatorState = null ,
commandBoundary = null ,
transportProfile = null ,
} ) {
const surface = state . surface || null ;
2026-06-16 12:47:59 +01:00
const providerId = advertisement . providerId || advertisement . provider ? . id || advertisement . id || "unknown-provider" ;
const title = state . title || advertisement . title || advertisement . provider ? . title || providerId ;
2026-07-04 22:38:43 +01:00
const endpoints = sanitizeProviderEndpoints ( advertisement . endpoints ) ;
const routes = sanitizeProviderEndpoints ( advertisement . routes ) ;
2026-06-16 11:01:27 +01:00
return {
2026-06-16 12:47:59 +01:00
providerId ,
title ,
2026-06-16 11:01:27 +01:00
state : "active" ,
detail : ` ${ surface ? . root ? . kind || surface ? . root ? . type || "surface" } ${ countSurfaceNodes ( surface , state ) } nodes via provider advertisement ` ,
version : state . version || 0 ,
updatedAt : state . updatedAt || advertisement . updatedAt || new Date ( ) . toISOString ( ) ,
source : ` cultmesh: ${ storePath } ` ,
2026-07-04 22:38:43 +01:00
manifest : {
... advertisement ,
endpoints ,
routes ,
} ,
2026-06-16 11:01:27 +01:00
canonicalService : advertisement . canonicalService || null ,
locatedService : advertisement . locatedService || null ,
cultMeshAddress : advertisement . cultMeshAddress || null ,
2026-07-04 22:38:43 +01:00
endpoints ,
routes ,
2026-06-16 11:01:27 +01:00
operatorState ,
commandBoundary ,
transportProfile ,
surface ,
} ;
}
2026-06-23 18:36:59 +01:00
function inspectCultMeshStore ( {
documents ,
interfaceBindingDefinition ,
muninnTelemetrySurfaceDefinition ,
node ,
providerAdvertisementDefinition ,
sourceId ,
} ) {
const {
2026-07-04 22:38:43 +01:00
idunnCommandBoundaryDefinition ,
idunnTransportProfileDefinition ,
2026-06-23 18:36:59 +01:00
operatorStateDefinition ,
stonksCommandBoundaryDefinition ,
stonksTransportProfileDefinition ,
streamPixelsCommandBoundaryDefinition ,
streamPixelsTransportProfileDefinition ,
surfaceDefinition ,
viliCommandBoundaryDefinition ,
viliTransportProfileDefinition ,
weksaCommandBoundaryDefinition ,
weksaOperatorStateDefinition ,
weksaTransportProfileDefinition ,
muninnCommandBoundaryDefinition ,
muninnTransportProfileDefinition ,
} = documents ;
const providerAdvertisements = [ ] ;
const interfaces = [ ] ;
const advertisements = typeof node . cache ? . getAll === "function"
? node . cache . getAll ( providerAdvertisementDefinition ) . map ( unwrapDocumentRecord )
: [ ] ;
for ( const advertisement of advertisements ) {
const providerId = advertisement ? . providerId || advertisement ? . provider ? . id || advertisement ? . id ;
if ( ! providerId ) {
continue ;
}
2026-07-04 22:38:43 +01:00
const endpoints = sanitizeProviderEndpoints ( advertisement . endpoints ) ;
const routes = sanitizeProviderEndpoints ( advertisement . routes ) ;
const providerEndpoint = advertisement . cultMeshAddress
|| providerTypedEndpoint ( routes )
|| providerTypedEndpoint ( endpoints )
|| typedProviderEndpoint ( advertisement . provider ? . endpoint )
|| ` cultmesh: ${ sourceId } ` ;
2026-06-23 18:36:59 +01:00
providerAdvertisements . push ( {
id : providerId ,
title : advertisement . title || advertisement . provider ? . title || providerId ,
description : advertisement . description || "Provider-owned CultMesh advertisement." ,
version : String ( advertisement . version || 0 ) ,
2026-07-04 22:38:43 +01:00
endpoint : providerEndpoint ,
2026-06-23 18:36:59 +01:00
canonicalService : advertisement . canonicalService || null ,
locatedService : advertisement . locatedService || null ,
cultMeshAddress : advertisement . cultMeshAddress || null ,
2026-07-04 22:38:43 +01:00
endpoints ,
routes ,
inputStreams : Array . isArray ( advertisement . inputStreams ) ? advertisement . inputStreams : [ ] ,
activeStreams : Array . isArray ( advertisement . activeStreams ) ? advertisement . activeStreams : [ ] ,
availableSources : Array . isArray ( advertisement . availableSources ) ? advertisement . availableSources : [ ] ,
transportEndpoint : providerTypedEndpoint ( routes )
|| typedProviderEndpoint ( advertisement . provider ? . endpoint )
|| providerEndpoint ,
2026-06-23 18:36:59 +01:00
capabilities : advertisement . provider ? . capabilities || advertisement . capabilities || [ ] ,
operatorState : providerRecord ( node , [
operatorStateDefinition ,
weksaOperatorStateDefinition ,
] , advertisement ) || null ,
commandBoundary : providerRecord ( node , [
2026-07-04 22:38:43 +01:00
idunnCommandBoundaryDefinition ,
2026-06-23 18:36:59 +01:00
muninnCommandBoundaryDefinition ,
viliCommandBoundaryDefinition ,
weksaCommandBoundaryDefinition ,
stonksCommandBoundaryDefinition ,
streamPixelsCommandBoundaryDefinition ,
] , advertisement ) || null ,
transportProfile : providerRecord ( node , [
2026-07-04 22:38:43 +01:00
idunnTransportProfileDefinition ,
2026-06-23 18:36:59 +01:00
muninnTransportProfileDefinition ,
viliTransportProfileDefinition ,
weksaTransportProfileDefinition ,
stonksTransportProfileDefinition ,
streamPixelsTransportProfileDefinition ,
] , advertisement ) || null ,
usesCultMesh : true ,
transport : advertisement . provider ? . transport || "CultMesh provider advertisement" ,
status : advertisement . status || "unknown" ,
updatedAt : advertisement . updatedAt || new Date ( ) . toISOString ( ) ,
source : ` cultmesh: ${ sourceId } ` ,
commandSurface : advertisement . commandSurface || null ,
} ) ;
const state = providerSurfaceState (
node ,
advertisement ,
surfaceDefinition ,
muninnTelemetrySurfaceDefinition ,
) ;
if ( state ? . surface ? . root ) {
interfaces . push ( cultMeshProviderInterface ( {
advertisement ,
state ,
storePath : sourceId ,
operatorState : providerRecord ( node , [
operatorStateDefinition ,
weksaOperatorStateDefinition ,
] , advertisement ) || null ,
commandBoundary : providerRecord ( node , [
2026-07-04 22:38:43 +01:00
idunnCommandBoundaryDefinition ,
2026-06-23 18:36:59 +01:00
muninnCommandBoundaryDefinition ,
viliCommandBoundaryDefinition ,
weksaCommandBoundaryDefinition ,
stonksCommandBoundaryDefinition ,
streamPixelsCommandBoundaryDefinition ,
] , advertisement ) || null ,
transportProfile : providerRecord ( node , [
2026-07-04 22:38:43 +01:00
idunnTransportProfileDefinition ,
2026-06-23 18:36:59 +01:00
muninnTransportProfileDefinition ,
viliTransportProfileDefinition ,
weksaTransportProfileDefinition ,
stonksTransportProfileDefinition ,
streamPixelsTransportProfileDefinition ,
] , advertisement ) || null ,
} ) ) ;
}
}
const bindings = typeof node . cache ? . getAll === "function"
? node . cache . getAll ( interfaceBindingDefinition ) . map ( unwrapDocumentRecord )
: [ unwrapDocumentRecord ( node . get ( interfaceBindingDefinition , "voidbot.swarm" ) ) ] . filter ( Boolean ) ;
for ( const binding of bindings ) {
if ( ! binding ? . providerId ) {
continue ;
}
const state = unwrapDocumentRecord ( node . get ( surfaceDefinition , binding . providerId ) ) ;
const surface = state ? . surface || binding . surface || null ;
interfaces . push ( {
providerId : binding . providerId ,
title : binding . title || state ? . title || binding . providerId ,
state : "active" ,
detail : ` ${ surface ? . root ? . kind || binding . kind || "surface" } ${ countSurfaceNodes ( surface , state ) } nodes via CultMesh ` ,
version : state ? . version || 0 ,
updatedAt : state ? . updatedAt || binding . updatedAt || new Date ( ) . toISOString ( ) ,
source : ` cultmesh: ${ sourceId } ` ,
manifest : binding . provider || null ,
canonicalService : binding . provider ? . canonicalService || null ,
locatedService : binding . provider ? . locatedService || null ,
cultMeshAddress : binding . provider ? . cultMeshAddress || binding . provider ? . endpoint || null ,
2026-07-04 22:38:43 +01:00
endpoints : sanitizeProviderEndpoints ( binding . provider ? . endpoints ) ,
routes : sanitizeProviderEndpoints ( binding . provider ? . routes ) ,
2026-06-23 18:36:59 +01:00
surface ,
} ) ;
}
return { interfaces , providerAdvertisements } ;
}
2026-06-23 17:04:07 +01:00
function providerSurfaceState ( node , advertisement , surfaceDefinition , muninnTelemetrySurfaceDefinition ) {
2026-07-04 22:38:43 +01:00
const surfaceKeys = [
advertisement . surfaceId ,
advertisement . surface _id ,
advertisement . providerId ,
advertisement . provider ? . id ,
] . filter ( Boolean ) ;
for ( const surfaceKey of [ ... new Set ( surfaceKeys . map ( String ) ) ] ) {
const surfaceState = unwrapDocumentRecord ( node . get ? . ( surfaceDefinition , surfaceKey ) ) ;
const providerId = surfaceState ? . providerId || surfaceState ? . provider _id ;
const updatedAt = surfaceState ? . updatedAt || surfaceState ? . updated _at ;
if ( surfaceState ? . surface ? . root ) {
return {
providerId : providerId || advertisement . providerId || advertisement . provider ? . id || "unknown-provider" ,
title : surfaceState . title || advertisement . title || advertisement . provider ? . title || advertisement . providerId || "unknown-provider" ,
version : Number ( surfaceState . version || 0 ) ,
updatedAt : updatedAt || advertisement . updatedAt || new Date ( ) . toISOString ( ) ,
surface : surfaceState . surface ,
} ;
}
2026-06-23 17:04:07 +01:00
}
const telemetryState = providerTelemetrySurfaceState ( node , advertisement , muninnTelemetrySurfaceDefinition ) ;
if ( telemetryState ) {
return telemetryState ;
}
return null ;
}
function providerTelemetrySurfaceState ( node , advertisement , muninnTelemetrySurfaceDefinition ) {
if ( ! muninnTelemetrySurfaceDefinition ) {
return null ;
}
const keys = [
advertisement . surfaceId ,
advertisement . surface _id ,
"latest" ,
] . filter ( Boolean ) ;
for ( const key of keys ) {
const record = unwrapDocumentRecord ( node . get ? . ( muninnTelemetrySurfaceDefinition , key ) ) ;
const telemetryState = muninnTelemetryStateFromRecord ( record , advertisement ) ;
if ( telemetryState ) {
return telemetryState ;
}
}
return null ;
}
2026-06-16 11:31:02 +01:00
function providerRecord ( node , definitions , advertisement ) {
const keys = providerRecordKeys ( advertisement ) ;
for ( const definition of definitions ) {
if ( ! definition ) continue ;
for ( const key of keys ) {
2026-06-16 21:45:52 +01:00
const record = unwrapDocumentRecord ( node . get ? . ( definition , key ) ) ;
2026-06-16 11:31:02 +01:00
if ( record ) return record ;
}
}
return null ;
}
2026-06-16 21:45:52 +01:00
function unwrapDocumentRecord ( record ) {
if ( Array . isArray ( record ) && record . length === 1 && record [ 0 ] && typeof record [ 0 ] === "object" ) {
return record [ 0 ] ;
}
return record ;
}
2026-06-16 11:31:02 +01:00
function providerRecordKeys ( advertisement ) {
const keys = [
2026-06-16 21:45:52 +01:00
advertisement ? . commandSurface ? . commandBoundaryId ,
advertisement ? . commandSurface ? . transportProfileId ,
2026-06-16 11:31:02 +01:00
advertisement ? . providerId ,
advertisement ? . daemonId ,
advertisement ? . daemon _id ,
advertisement ? . serviceId ,
advertisement ? . service _id ,
2026-06-16 12:47:59 +01:00
advertisement ? . provider ? . id ,
2026-06-16 11:31:02 +01:00
advertisement ? . canonicalService ,
advertisement ? . locatedService ,
] ;
if ( advertisement ? . providerId === "vili.animation" ) keys . push ( "vili" ) ;
if ( advertisement ? . providerId === "weksa.intent.service" ) keys . push ( "weksa" ) ;
2026-06-16 12:04:26 +01:00
if ( advertisement ? . providerId === "stonks.market" ) keys . push ( "stonks" ) ;
2026-06-16 12:47:59 +01:00
if ( advertisement ? . provider ? . id === "streampixels.service" ) keys . push ( "streampixels" , "yggdrasil-streampixels" ) ;
2026-06-16 11:31:02 +01:00
return [ ... new Set ( keys . filter ( Boolean ) . map ( String ) ) ] ;
}
2026-06-16 22:39:03 +01:00
function inspectProviderAdvertisementsFromStore ( storePath , sourceId ) {
const inspection = inspectCultCacheBytes ( storePath , fs . readFileSync ( storePath ) ) ;
const records = inspection . records || [ ] ;
return records
. filter ( ( record ) => record . schemaName === "gamecult.eve.provider_advertisement" )
. map ( ( record ) => buildInspectedProviderAdvertisement ( record , records , sourceId ) )
. filter ( Boolean ) ;
}
function buildInspectedProviderAdvertisement ( record , records , sourceId ) {
const advertisement = normalizeInspectedProviderAdvertisement ( record ? . payloadPreview ) ;
const providerId = advertisement ? . providerId ;
if ( ! providerId ) {
return null ;
}
const commandBoundary = inspectProviderCommandBoundary ( providerId , records ) ;
const transportProfile = inspectProviderTransportProfile ( providerId , records ) ;
2026-07-04 22:38:43 +01:00
const endpoints = sanitizeProviderEndpoints ( advertisement . endpoints ) ;
const routes = sanitizeProviderEndpoints ( normalizeInspectedRoutes ( advertisement ) ) ;
2026-06-16 22:39:03 +01:00
return {
id : providerId ,
title : advertisement . title || providerId ,
description : advertisement . description || "Provider-owned CultMesh advertisement." ,
version : String ( advertisement . version || 0 ) ,
2026-07-04 22:38:43 +01:00
endpoint : advertisement . cultMeshAddress || providerTypedEndpoint ( endpoints ) || ` cultmesh: ${ sourceId } ` ,
2026-06-16 22:39:03 +01:00
canonicalService : advertisement . canonicalService || null ,
locatedService : advertisement . locatedService || null ,
cultMeshAddress : advertisement . cultMeshAddress || null ,
endpoints ,
2026-07-04 22:38:43 +01:00
routes ,
inputStreams : Array . isArray ( advertisement . inputStreams ) ? advertisement . inputStreams : [ ] ,
activeStreams : Array . isArray ( advertisement . activeStreams ) ? advertisement . activeStreams : [ ] ,
availableSources : Array . isArray ( advertisement . availableSources ) ? advertisement . availableSources : [ ] ,
transportEndpoint : advertisement . cultMeshAddress || providerTypedEndpoint ( routes ) || providerTypedEndpoint ( endpoints ) || ` cultmesh: ${ sourceId } ` ,
2026-06-16 22:39:03 +01:00
capabilities : advertisement . capabilities || [ ] ,
operatorState : null ,
commandBoundary ,
transportProfile ,
usesCultMesh : true ,
transport : "CultMesh provider advertisement" ,
status : advertisement . status || "unknown" ,
updatedAt : advertisement . updatedAt || new Date ( ) . toISOString ( ) ,
source : ` cultmesh: ${ sourceId } ` ,
commandSurface : advertisement . commandSurface || null ,
} ;
}
function inspectCultMeshInterfacesFromStore ( storePath , sourceId ) {
const inspection = inspectCultCacheBytes ( storePath , fs . readFileSync ( storePath ) ) ;
const records = inspection . records || [ ] ;
const providersById = new Map (
records
. filter ( ( record ) => record . schemaName === "gamecult.eve.provider_advertisement" )
. map ( ( record ) => buildInspectedProviderAdvertisement ( record , records , sourceId ) )
. filter ( Boolean )
. map ( ( provider ) => [ provider . id , provider ] ) ,
) ;
2026-06-23 17:04:07 +01:00
const surfaceInterfaces = records
2026-06-16 22:39:03 +01:00
. filter ( ( record ) => record . schemaName === "gamecult.eve.surface_state" )
. map ( ( record ) => buildInspectedInterfaceFromSurfaceRecord (
record ,
providersById ,
sourceId ,
records ,
) )
. filter ( Boolean ) ;
2026-06-23 17:04:07 +01:00
const telemetryInterfaces = records
. filter ( ( record ) => record . schemaName === "muninn.telemetry_surface" )
. map ( ( record ) => buildInspectedInterfaceFromTelemetryRecord (
record ,
providersById ,
sourceId ,
records ,
) )
. filter ( Boolean ) ;
return [ ... surfaceInterfaces , ... telemetryInterfaces ] ;
2026-06-16 22:39:03 +01:00
}
2026-07-04 22:38:43 +01:00
function inspectCultMeshStoreBytes ( storePath , sourceId ) {
return {
interfaces : inspectCultMeshInterfacesFromStore ( storePath , sourceId ) ,
providerAdvertisements : inspectProviderAdvertisementsFromStore ( storePath , sourceId ) ,
} ;
}
function mergeInterfaces ( entries ) {
const byProvider = new Map ( ) ;
for ( const entry of entries ) {
if ( ! entry ? . providerId ) continue ;
const existing = byProvider . get ( String ( entry . providerId ) ) ;
if ( ! existing || ( ! existing . surface ? . root && entry . surface ? . root ) ) {
byProvider . set ( String ( entry . providerId ) , entry ) ;
}
}
return [ ... byProvider . values ( ) ] ;
}
function mergeProviderAdvertisements ( entries ) {
const byProvider = new Map ( ) ;
for ( const entry of entries ) {
if ( ! entry ? . id ) continue ;
const existing = byProvider . get ( String ( entry . id ) ) ;
byProvider . set ( String ( entry . id ) , mergeProviderAdvertisement ( existing , entry ) ) ;
}
return [ ... byProvider . values ( ) ] ;
}
function mergeProviderAdvertisement ( existing , entry ) {
if ( ! existing ) return entry ;
return {
... existing ,
... entry ,
endpoints : preferNonEmptyArray ( entry . endpoints , existing . endpoints ) ,
routes : preferNonEmptyArray ( entry . routes , existing . routes ) ,
inputStreams : preferNonEmptyArray ( entry . inputStreams , existing . inputStreams ) ,
activeStreams : preferNonEmptyArray ( entry . activeStreams , existing . activeStreams ) ,
availableSources : preferNonEmptyArray ( entry . availableSources , existing . availableSources ) ,
capabilities : preferNonEmptyArray ( entry . capabilities , existing . capabilities ) ,
} ;
}
function preferNonEmptyArray ( candidate , fallback ) {
return Array . isArray ( candidate ) && candidate . length > 0
? candidate
: ( Array . isArray ( fallback ) ? fallback : [ ] ) ;
}
2026-06-16 22:39:03 +01:00
function buildInspectedInterfaceFromSurfaceRecord ( record , providersById , sourceId , records ) {
const state = normalizeInspectedSurfaceState ( record ? . payloadPreview ) ;
if ( ! state ? . providerId || ! state . surface ? . root ) {
return null ;
}
const provider = providersById . get ( state . providerId ) || null ;
return {
providerId : state . providerId ,
title : state . title || provider ? . title || state . providerId ,
state : "active" ,
detail : ` ${ state . surface . root . kind || "surface" } ${ countSurfaceNodes ( state . surface ) } nodes via CultMesh witness inspection ` ,
version : state . version || 0 ,
updatedAt : state . updatedAt || provider ? . updatedAt || new Date ( ) . toISOString ( ) ,
source : ` cultmesh: ${ sourceId } ` ,
manifest : provider ? {
providerId : provider . id ,
title : provider . title ,
description : provider . description ,
canonicalService : provider . canonicalService ,
locatedService : provider . locatedService ,
cultMeshAddress : provider . cultMeshAddress ,
2026-07-04 22:38:43 +01:00
endpoints : sanitizeProviderEndpoints ( provider . endpoints ) ,
routes : sanitizeProviderEndpoints ( provider . routes ) ,
2026-06-16 22:39:03 +01:00
} : null ,
canonicalService : provider ? . canonicalService || null ,
locatedService : provider ? . locatedService || null ,
cultMeshAddress : provider ? . cultMeshAddress || null ,
2026-07-04 22:38:43 +01:00
endpoints : sanitizeProviderEndpoints ( provider ? . endpoints ) ,
routes : sanitizeProviderEndpoints ( provider ? . routes ) ,
2026-06-16 22:39:03 +01:00
operatorState : null ,
commandBoundary : provider ? . commandBoundary || inspectProviderCommandBoundary ( state . providerId , records ) ,
transportProfile : provider ? . transportProfile || inspectProviderTransportProfile ( state . providerId , records ) ,
surface : state . surface ,
} ;
}
2026-06-23 17:04:07 +01:00
function buildInspectedInterfaceFromTelemetryRecord ( record , providersById , sourceId , records ) {
const telemetry = normalizeInspectedMuninnTelemetrySurfaceRecord ( record ? . payloadPreview ) ;
if ( ! telemetry ? . hostId ) {
return null ;
}
const providerId = ` muninn.telemetry. ${ telemetry . hostId } ` ;
const provider = providersById . get ( providerId ) || null ;
const state = muninnTelemetryStateFromRecord ( telemetry , provider ) ;
if ( ! state ? . surface ? . root ) {
return null ;
}
return {
providerId : state . providerId ,
title : state . title ,
state : "active" ,
detail : ` ${ state . surface . root . kind || "surface" } ${ countSurfaceNodes ( state . surface ) } nodes via Muninn telemetry surface ` ,
version : state . version || 0 ,
updatedAt : state . updatedAt || provider ? . updatedAt || new Date ( ) . toISOString ( ) ,
source : ` cultmesh: ${ sourceId } ` ,
manifest : provider ? {
providerId : provider . id ,
title : provider . title ,
description : provider . description ,
canonicalService : provider . canonicalService ,
locatedService : provider . locatedService ,
cultMeshAddress : provider . cultMeshAddress ,
2026-07-04 22:38:43 +01:00
endpoints : sanitizeProviderEndpoints ( provider . endpoints ) ,
routes : sanitizeProviderEndpoints ( provider . routes ) ,
2026-06-23 17:04:07 +01:00
} : null ,
canonicalService : provider ? . canonicalService || null ,
locatedService : provider ? . locatedService || null ,
cultMeshAddress : provider ? . cultMeshAddress || null ,
2026-07-04 22:38:43 +01:00
endpoints : sanitizeProviderEndpoints ( provider ? . endpoints ) ,
routes : sanitizeProviderEndpoints ( provider ? . routes ) ,
2026-06-23 17:04:07 +01:00
operatorState : null ,
commandBoundary : provider ? . commandBoundary || null ,
transportProfile : provider ? . transportProfile || null ,
surface : state . surface ,
} ;
}
function muninnTelemetryStateFromRecord ( record , advertisement = null ) {
const telemetry = normalizeMuninnTelemetrySurfaceRecord ( record ) ;
if ( ! telemetry ? . hostId ) {
return null ;
}
const providerId = advertisement ? . providerId || advertisement ? . id || ` muninn.telemetry. ${ telemetry . hostId } ` ;
const title = advertisement ? . title || advertisement ? . provider ? . title || ` Muninn ${ titleCase ( telemetry . hostId ) } Telemetry ` ;
const updatedAt = telemetry . updatedAt || advertisement ? . updatedAt || new Date ( ) . toISOString ( ) ;
const parsedVersion = Date . parse ( updatedAt ) ;
return {
providerId ,
title ,
version : Number . isFinite ( parsedVersion ) ? parsedVersion : 0 ,
updatedAt ,
surface : buildMuninnTelemetrySurfaceDocument ( providerId , title , telemetry ) ,
} ;
}
function normalizeMuninnTelemetrySurfaceRecord ( record ) {
if ( ! record ) {
return null ;
}
if ( ! Array . isArray ( record ) && typeof record === "object" ) {
return {
surfaceId : record . surface _id || record . surfaceId || null ,
hostId : record . host _id || record . hostId || null ,
state : record . state || "unknown" ,
availableSources : Array . isArray ( record . available _sources || record . availableSources )
? ( record . available _sources || record . availableSources )
: [ ] ,
streamAffordances : Array . isArray ( record . stream _affordances || record . streamAffordances )
? ( record . stream _affordances || record . streamAffordances )
: [ ] ,
activeStreams : Array . isArray ( record . active _streams || record . activeStreams )
? ( record . active _streams || record . activeStreams )
: [ ] ,
activationAuthority : record . activation _authority || record . activationAuthority || "" ,
detail : record . detail || "" ,
updatedAt : record . updated _at || record . updatedAt || null ,
} ;
}
return normalizeInspectedMuninnTelemetrySurfaceRecord ( record ) ;
}
function normalizeInspectedMuninnTelemetrySurfaceRecord ( preview ) {
if ( Array . isArray ( preview ) && preview . length === 1 && preview [ 0 ] && typeof preview [ 0 ] === "object" && ! Array . isArray ( preview [ 0 ] ) ) {
return normalizeMuninnTelemetrySurfaceRecord ( preview [ 0 ] ) ;
}
if ( ! Array . isArray ( preview ) || preview . length < 9 ) {
return null ;
}
return {
surfaceId : preview [ 0 ] || null ,
hostId : preview [ 1 ] || null ,
state : preview [ 2 ] || "unknown" ,
availableSources : Array . isArray ( preview [ 3 ] ) ? preview [ 3 ] : [ ] ,
streamAffordances : Array . isArray ( preview [ 4 ] ) ? preview [ 4 ] : [ ] ,
activeStreams : Array . isArray ( preview [ 5 ] ) ? preview [ 5 ] : [ ] ,
activationAuthority : preview [ 6 ] || "" ,
detail : preview [ 7 ] || "" ,
updatedAt : preview [ 8 ] || null ,
} ;
}
function buildMuninnTelemetrySurfaceDocument ( providerId , title , telemetry ) {
const sourceSummary = telemetry . availableSources . length ? telemetry . availableSources . join ( ", " ) : "none" ;
const activeSummary = telemetry . activeStreams . length ? telemetry . activeStreams . join ( ", " ) : "none" ;
const affordanceSummary = telemetry . streamAffordances . length ? telemetry . streamAffordances . join ( ", " ) : "none" ;
return {
schema : "gamecult.eve.surface.v1" ,
id : telemetry . surfaceId || ` ${ providerId } .surface ` ,
title ,
root : {
id : ` ${ providerId } .root ` ,
kind : "dashboard" ,
props : {
title ,
summary : telemetry . detail || ` ${ telemetry . state } on ${ telemetry . hostId } ` ,
status : telemetry . state || "unknown" ,
} ,
children : [
{
id : ` ${ providerId } .runtime ` ,
kind : "card" ,
props : { title : "Runtime" } ,
children : [
textElement ( ` ${ providerId } .state ` , ` state: ${ telemetry . state || "unknown" } ` ) ,
textElement ( ` ${ providerId } .host ` , ` host: ${ telemetry . hostId } ` ) ,
textElement ( ` ${ providerId } .authority ` , ` activation: ${ telemetry . activationAuthority || "unknown" } ` ) ,
textElement ( ` ${ providerId } .updated ` , ` updated: ${ telemetry . updatedAt || "unknown" } ` ) ,
] ,
} ,
{
id : ` ${ providerId } .sources ` ,
kind : "card" ,
props : { title : "Sources" } ,
children : [
textElement ( ` ${ providerId } .available-sources ` , ` available: ${ sourceSummary } ` ) ,
textElement ( ` ${ providerId } .affordances ` , ` affordances: ${ affordanceSummary } ` ) ,
] ,
} ,
{
id : ` ${ providerId } .streams ` ,
kind : "card" ,
props : { title : "Streams" } ,
children : [
textElement ( ` ${ providerId } .active-streams ` , ` active: ${ activeSummary } ` ) ,
textElement ( ` ${ providerId } .detail ` , telemetry . detail || "detail: none" ) ,
] ,
} ,
] ,
} ,
assets : [ ] ,
} ;
}
2026-06-16 22:39:03 +01:00
function normalizeInspectedProviderAdvertisement ( preview ) {
if ( Array . isArray ( preview ) && preview . length === 1 && preview [ 0 ] && typeof preview [ 0 ] === "object" && ! Array . isArray ( preview [ 0 ] ) ) {
const value = preview [ 0 ] ;
return {
providerId : value . providerId || value . ProviderId || null ,
title : value . title || value . Title || null ,
description : value . description || value . Description || null ,
canonicalService : value . canonicalService || value . CanonicalService || null ,
locatedService : value . locatedService || value . LocatedService || null ,
cultMeshAddress : value . cultMeshAddress || value . CultMeshAddress || null ,
status : value . status || value . Status || null ,
updatedAt : value . updatedAt || value . UpdatedAt || null ,
capabilities : value . capabilities || value . CapabilityIds || [ ] ,
endpoints : value . endpoints || value . Endpoints || [ ] ,
commandSurface : value . commandSurface || value . CommandSurface || null ,
} ;
}
if ( ! Array . isArray ( preview ) || preview . length < 11 ) {
return null ;
}
return {
providerId : preview [ 1 ] || null ,
serviceId : preview [ 2 ] || null ,
verseId : preview [ 3 ] || null ,
title : preview [ 4 ] || null ,
description : preview [ 5 ] || null ,
canonicalService : preview [ 6 ] || null ,
locatedService : preview [ 7 ] || null ,
cultMeshAddress : preview [ 8 ] || null ,
status : preview [ 9 ] || null ,
updatedAt : preview [ 10 ] || null ,
capabilities : Array . isArray ( preview [ 11 ] ) ? preview [ 11 ] : [ ] ,
endpoints : Array . isArray ( preview [ 12 ] ) ? preview [ 12 ] : [ ] ,
schemas : Array . isArray ( preview [ 13 ] ) ? preview [ 13 ] : [ ] ,
witnesses : Array . isArray ( preview [ 14 ] ) ? preview [ 14 ] : [ ] ,
surfaces : Array . isArray ( preview [ 15 ] ) ? preview [ 15 ] : [ ] ,
} ;
}
function normalizeInspectedSurfaceState ( preview ) {
if ( Array . isArray ( preview ) && preview . length === 1 && preview [ 0 ] && typeof preview [ 0 ] === "object" && ! Array . isArray ( preview [ 0 ] ) ) {
const value = preview [ 0 ] ;
return {
providerId : value . providerId || value . ProviderId || null ,
title : value . title || value . Title || null ,
version : Number ( value . version || value . Version || 0 ) ,
updatedAt : value . updatedAt || value . UpdatedAt || null ,
surface : normalizeInspectedSurface ( value . surface || value . Surface || null ) ,
} ;
}
if ( ! Array . isArray ( preview ) || preview . length < 5 ) {
return null ;
}
if ( preview . length >= 6 ) {
return {
providerId : preview [ 1 ] || null ,
title : preview [ 2 ] || null ,
version : Number ( preview [ 3 ] || 0 ) ,
updatedAt : preview [ 4 ] || null ,
surface : normalizeInspectedSurface ( preview [ 5 ] ) ,
} ;
}
return {
providerId : preview [ 0 ] || null ,
title : preview [ 1 ] || null ,
version : Number ( preview [ 2 ] || 0 ) ,
updatedAt : preview [ 3 ] || null ,
surface : normalizeInspectedSurface ( preview [ 4 ] ) ,
} ;
}
function normalizeInspectedSurface ( preview ) {
if ( ! preview ) {
return null ;
}
if ( ! Array . isArray ( preview ) && typeof preview === "object" ) {
return {
... preview ,
root : normalizeInspectedSurfaceNode ( preview . root ) ,
assets : Array . isArray ( preview . assets ) ? preview . assets : [ ] ,
} ;
}
if ( ! Array . isArray ( preview ) || preview . length < 4 ) {
return null ;
}
return {
schema : preview [ 0 ] || "gamecult.eve.surface.v1" ,
id : preview [ 1 ] || "surface" ,
title : preview [ 2 ] || "" ,
root : normalizeInspectedSurfaceNode ( preview [ 3 ] ) ,
assets : Array . isArray ( preview [ 4 ] ) ? preview [ 4 ] : [ ] ,
} ;
}
function normalizeInspectedSurfaceNode ( preview ) {
if ( ! preview ) {
return null ;
}
if ( ! Array . isArray ( preview ) && typeof preview === "object" ) {
return {
... preview ,
props : normalizeInspectedSurfaceProps ( preview . props ) ,
children : Array . isArray ( preview . children )
? preview . children . map ( ( child ) => normalizeInspectedSurfaceNode ( child ) ) . filter ( Boolean )
: [ ] ,
} ;
}
if ( ! Array . isArray ( preview ) || preview . length < 3 ) {
return null ;
}
return {
id : preview [ 0 ] || "node" ,
kind : preview [ 1 ] || "group" ,
props : normalizeInspectedSurfaceProps ( preview [ 2 ] ) ,
children : Array . isArray ( preview [ 3 ] )
? preview [ 3 ] . map ( ( child ) => normalizeInspectedSurfaceNode ( child ) ) . filter ( Boolean )
: [ ] ,
} ;
}
function normalizeInspectedSurfaceProps ( preview ) {
if ( ! preview ) {
return { } ;
}
if ( ! Array . isArray ( preview ) && typeof preview === "object" ) {
return preview ;
}
if ( ! Array . isArray ( preview ) ) {
return { } ;
}
return {
title : preview [ 0 ] || "" ,
text : preview [ 1 ] || "" ,
label : preview [ 2 ] || "" ,
value : preview [ 3 ] || "" ,
status : preview [ 4 ] || "" ,
summary : preview [ 5 ] || "" ,
detail : preview [ 6 ] || "" ,
} ;
}
function inspectProviderCommandBoundary ( providerId , records ) {
if ( providerId !== "nightwing-gjallar" ) {
return null ;
}
const record = records . find ( ( entry ) => entry . schemaName === "gjallar.command_boundary" ) ;
if ( ! record || ! Array . isArray ( record . payloadPreview ) ) {
return null ;
}
return {
boundary _id : record . payloadPreview [ 0 ] || null ,
daemon _id : record . payloadPreview [ 1 ] || null ,
owner : record . payloadPreview [ 2 ] || null ,
lifecycle _authority : record . payloadPreview [ 5 ] || null ,
updated _at : record . payloadPreview [ 8 ] || null ,
} ;
}
function inspectProviderTransportProfile ( providerId , records ) {
if ( providerId !== "nightwing-gjallar" ) {
return null ;
}
const record = records . find ( ( entry ) => entry . schemaName === "gjallar.transport_profile" ) ;
if ( ! record || ! Array . isArray ( record . payloadPreview ) ) {
return null ;
}
return {
profile _id : record . payloadPreview [ 0 ] || null ,
daemon _id : record . payloadPreview [ 1 ] || null ,
state : record . payloadPreview [ 2 ] || null ,
2026-07-04 22:38:43 +01:00
debug _transport : record . payloadPreview [ 3 ] || null ,
2026-06-16 22:39:03 +01:00
current _transport : record . payloadPreview [ 4 ] || null ,
health _contract : record . payloadPreview [ 5 ] || null ,
cut _line : record . payloadPreview [ 9 ] || null ,
updated _at : record . payloadPreview [ 10 ] || null ,
} ;
}
function normalizeInspectedEndpoints ( endpoints ) {
if ( ! Array . isArray ( endpoints ) ) {
return [ ] ;
}
return endpoints . map ( ( entry ) => {
if ( entry && typeof entry === "object" && ! Array . isArray ( entry ) ) {
return entry ;
}
return {
2026-07-04 22:38:43 +01:00
transport : "witness" ,
2026-06-16 22:39:03 +01:00
address : String ( entry || "" ) ,
} ;
} ) ;
}
2026-07-04 22:38:43 +01:00
function sanitizeProviderEndpoints ( endpoints ) {
return normalizeInspectedEndpoints ( endpoints ) . filter ( ( entry ) => {
const transport = String ( entry ? . transport || "" ) . toLowerCase ( ) ;
const address = String ( entry ? . address || "" ) . trim ( ) ;
if ( address . startsWith ( "cultmesh:" ) ) {
return true ;
}
if ( transport . includes ( "cultmesh" ) || transport . includes ( "cultcache" ) ) {
return true ;
}
return false ;
} ) ;
}
function providerTypedEndpoint ( endpoints ) {
const normalized = sanitizeProviderEndpoints ( endpoints ) ;
return normalized . find ( ( entry ) => {
const address = String ( entry ? . address || "" ) ;
return address . startsWith ( "cultmesh:" ) ;
} ) ? . address || null ;
}
function typedProviderEndpoint ( endpoint ) {
const value = typeof endpoint === "string" ? endpoint . trim ( ) : "" ;
if ( ! value ) {
return null ;
}
return value . startsWith ( "cultmesh:" ) ? value : null ;
}
2026-06-16 22:39:03 +01:00
function normalizeInspectedRoutes ( advertisement ) {
if ( Array . isArray ( advertisement ? . routes ) ) {
return advertisement . routes ;
}
if ( Array . isArray ( advertisement ? . endpoints ) ) {
return normalizeInspectedEndpoints ( advertisement . endpoints ) ;
}
return [ ] ;
}
2026-06-16 21:59:36 +01:00
function resolveInterfaceBindingStore ( storeSpec ) {
if ( typeof storeSpec !== "string" || ! storeSpec . trim ( ) ) {
return null ;
}
2026-07-04 22:38:43 +01:00
const text = storeSpec . trim ( ) ;
if ( text . startsWith ( "cultmesh-store:file://" ) ) {
const localPath = fileURLToPath ( text . slice ( "cultmesh-store:" . length ) ) ;
return {
localPath ,
sourceId : text ,
cleanup : ( ) => { } ,
} ;
2026-06-02 16:04:49 +01:00
}
2026-07-04 22:38:43 +01:00
if ( text . startsWith ( "cultmesh://" ) ) {
throw new Error ( ` CultMesh rendezvous URI ${ text } must announce through Odin; static interface store imports are not the rendezvous owner. ` ) ;
2026-06-06 20:20:04 +01:00
}
2026-07-04 22:38:43 +01:00
if ( text . startsWith ( "sftp://" ) || text . startsWith ( "http://" ) || text . startsWith ( "https://" ) || text . startsWith ( "rudp://" ) ) {
throw new Error ( ` network interface binding stores are no longer supported by Odin discovery: ${ text } ` ) ;
2026-06-06 20:20:04 +01:00
}
2026-07-04 22:38:43 +01:00
throw new Error ( ` raw interface binding store paths are no longer supported by Odin discovery: ${ text } . Use CultMesh announcement through Odin, or an explicit cultmesh-store:file:// URI for a local debug import. ` ) ;
2026-06-06 20:20:04 +01:00
}
2026-06-02 16:04:49 +01:00
function dashboardUnavailable ( providerId , source , detail ) {
return {
providerId ,
title : providerId ,
state : "unavailable" ,
detail ,
version : 0 ,
updatedAt : new Date ( ) . toISOString ( ) ,
source ,
manifest : null ,
surface : null ,
} ;
}
2026-06-04 20:59:16 +01:00
function countSurfaceNodes ( surface , state = null ) {
if ( Array . isArray ( state ? . nodes ) ) {
return state . nodes . length ;
}
if ( ! surface ? . root ) {
return 0 ;
}
let count = 0 ;
const stack = [ surface . root ] ;
while ( stack . length > 0 ) {
const node = stack . pop ( ) ;
if ( ! node || typeof node !== "object" ) {
continue ;
}
count += 1 ;
if ( Array . isArray ( node . children ) ) {
for ( const child of node . children ) {
stack . push ( child ) ;
}
}
}
return count ;
}
2026-06-03 11:26:52 +01:00
function textElement ( id , text ) {
return {
id : String ( id ) ,
kind : "text" ,
props : { text : String ( text ) } ,
children : [ ] ,
} ;
}
2026-06-23 17:04:07 +01:00
function titleCase ( value ) {
return String ( value || "" )
. split ( /[^a-zA-Z0-9]+/ )
. filter ( Boolean )
. map ( ( part ) => part . charAt ( 0 ) . toUpperCase ( ) + part . slice ( 1 ) )
. join ( " " ) ;
}
2026-06-02 16:04:49 +01:00
module . exports = {
createInterfaceDiscovery ,
dashboardUnavailable ,
} ;