LibreChat/examples/sdk-runtime/server.cjs
Danny Avila 4c6da07a7a
🚠 feat: Bridge Registered SDK Agents to Remote Runtimes (#18150)
* feat: bridge registered SDK agents to remote runtimes

* docs: make remote runtime parity gates explicit

* fix: bound runtime authorization admission and shutdown

* fix: reject unresolved runtime secrets and preserve checkpoint queries

* fix: order remote policy hooks after preceding events
2026-11-14 10:56:05 -05:00

34 lines
1.5 KiB
JavaScript

const { createRemoteSdkServer } = require('@librechat/api/sdk');
const { createExampleRun } = require('./agent.cjs');
const { createMinimalRun } = require('./minimal.cjs');
const secret = process.env.SDK_RUNTIME_SECRET;
if (!secret || secret.length < 32)
throw new Error('Set SDK_RUNTIME_SECRET to at least 32 random characters.');
const runtimeId = process.env.SDK_RUNTIME_ID || 'remote-example';
const allowedAgents = new Set((process.env.SDK_RUNTIME_AGENT_IDS || '').split(',').filter(Boolean));
const runtime = createRemoteSdkServer({
runtimeId,
secret,
// The host signs identities only after resolving an authorized saved-agent binding.
// Set SDK_RUNTIME_AGENT_IDS to additionally pin this deployment to specific saved agent IDs.
authorize: (identity) =>
identity.runtimeId === runtimeId &&
(!allowedAgents.size || allowedAgents.has(identity.agentId)),
createRun: (input) =>
process.env.SDK_EXAMPLE_GRAPH === 'simple'
? createMinimalRun(input)
: createExampleRun(input, {
stepDelayMs: Number(process.env.SDK_EXAMPLE_STEP_DELAY_MS || 0),
}),
onError: () => console.error('Remote SDK run failed'),
});
runtime.server.listen(Number(process.env.SDK_RUNTIME_PORT || 8804), '127.0.0.1', () => {
console.log(
`SDK runtime ${runtimeId} listening on loopback port ${runtime.server.address().port}`,
);
});
for (const signal of ['SIGTERM', 'SIGINT'])
process.once(signal, () => {
void runtime.close().then(() => process.exit(0));
});