mcard-js
Version:
MCard - Content-addressable storage with cryptographic hashing, handle resolution, and vector search for Node.js and browsers
94 lines • 2.88 kB
JavaScript
/**
* Builtin detection and routing for CLM execution.
*/
// Network builtins that should be routed to NetworkRuntime
const NETWORK_BUILTINS = new Set([
'http_get', 'http_post', 'http_put', 'http_delete', 'http_patch',
'websocket_connect', 'websocket_send', 'websocket_listen',
'queue_send', 'queue_receive',
'load_url',
'mcard_send', 'mcard_read', 'mcard_sync',
'listen_http', 'listen_sync',
'session_record',
'run_command',
'clm_orchestrator',
'signaling_server',
'webrtc_connect', 'webrtc_send', 'webrtc_listen',
]);
// Server builtins that manage long-running processes
const SERVER_BUILTINS = new Set([
'static_server',
'websocket_server',
]);
/**
* Check if a builtin should be handled by network runtime.
*/
export function isNetworkBuiltin(builtin, operation) {
if (builtin === false)
return false;
// If builtin is true, check operation name
const op = (typeof builtin === 'string' ? builtin : operation) || '';
if (!op)
return false;
// Check exact match
if (NETWORK_BUILTINS.has(op))
return true;
// Check prefix patterns
return (op.startsWith('http_') ||
op.startsWith('websocket_') ||
op.startsWith('queue_') ||
op.startsWith('webrtc_'));
}
/**
* Check if a builtin is a loader operation.
*/
export function isLoaderBuiltin(builtin, operation) {
if (builtin === false)
return false;
const op = (typeof builtin === 'string' ? builtin : operation) || '';
return op === 'loader' ||
op === 'load_files' ||
operation === 'loader';
}
/**
* Check if a builtin is a handle operation.
*/
export function isHandleBuiltin(builtin, operation) {
if (builtin === false)
return false;
const op = (typeof builtin === 'string' ? builtin : operation) || '';
return op === 'handle_version' ||
op === 'handle_prune';
}
/**
* Get the type of handle builtin.
*/
export function getHandleBuiltinType(builtin, operation) {
if (builtin === false)
return null;
const op = (typeof builtin === 'string' ? builtin : operation) || '';
if (op === 'handle_version')
return 'version';
if (op === 'handle_prune')
return 'prune';
return null;
}
/**
* Check if a builtin is a static server operation.
*/
export function isStaticServerBuiltin(builtin, operation) {
if (builtin === false)
return false;
const op = (typeof builtin === 'string' ? builtin : operation) || '';
return op === 'static_server';
}
/**
* Check if a builtin is a WebSocket server operation.
*/
export function isWebSocketServerBuiltin(builtin, operation) {
if (builtin === false)
return false;
const op = (typeof builtin === 'string' ? builtin : operation) || '';
return op === 'websocket_server';
}
//# sourceMappingURL=index.js.map