feat: add unified IM access policies

This commit is contained in:
xmanrui 2026-09-01 10:45:12 +08:00
parent 075d2713c1
commit 840e5aa857
89 changed files with 5573 additions and 1676 deletions

View file

@ -17,6 +17,10 @@ import {
createDeliveryAdapter,
supportsDeliveryChannel,
} from '../../delivery-adapter.mjs';
import {
accessPolicyProvider,
initialAccessPolicyFor,
} from './access-policy-production.mjs';
export function pluginPaths(config, channel) {
const dshHome = resolve(config.dshHome ?? process.env.DSH_HOME ?? join(homedir(), '.dsh'));
@ -46,6 +50,11 @@ export async function createTokenProductionController(ctx, config, internals, de
throw new TypeError(`dsh-im ${channel} runtimeOptions must return an object`);
}
const createSupervisor = internals.createConnectionSupervisor ?? createTokenConnectionSupervisor;
const seedAccessPolicy = typeof definitions.initialAccessPolicyForBot === 'function'
? definitions.initialAccessPolicyForBot
// Telegram is the only token channel with a legacy access model. Other
// current token channels preserve their fully-open baseline.
: (bot) => initialAccessPolicyFor(channel === 'telegram' ? 'telegram' : 'discord', bot);
const logger = typeof ctx.logger === 'function'
? ctx.logger(`dsh-im:${channel}`) : (ctx.logger ?? console);
const agentPresetCatalog = () => listAgentPresetCatalog(ctx);
@ -59,6 +68,7 @@ export async function createTokenProductionController(ctx, config, internals, de
await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
defaultAgentPreset: config.agentPreset,
initialAccessPolicy: seedAccessPolicy(bot),
})));
const observedConfigStore = typeof configStore.remove === 'function'
? observeBotWorkspaceRemovals(configStore, { workspaces })
@ -96,7 +106,10 @@ export async function createTokenProductionController(ctx, config, internals, de
...(internals.inspectToken ? { inspectToken: internals.inspectToken } : {}),
createRuntime: async ({ botId, config: botConfig, token }) => {
const state = await stateFor(botId);
await workspaces.ensure(botId, { defaultAgentPreset: config.agentPreset });
await workspaces.ensure(botId, {
defaultAgentPreset: config.agentPreset,
initialAccessPolicy: seedAccessPolicy(botConfig),
});
const workspaceScope = createBotWorkspaceScope(harness, {
botId, workspaces, state, agentPresetCatalog,
});
@ -107,6 +120,7 @@ export async function createTokenProductionController(ctx, config, internals, de
harness: workspaceScope.harness,
state: workspaceScope.state,
contextEnhancement: { botId, getSettings: () => workspaces.contextEnhancementFor(botId) },
accessPolicy: accessPolicyProvider(workspaces, botId, { channel, config: botConfig }),
replyTimeoutMs: config.replyTimeoutMs ?? 600_000,
connectTimeoutMs: config.connectTimeoutMs ?? 20_000,
logger: {