feat: add session-scoped workflow approval gate commands
This commit is contained in:
@@ -20,6 +20,7 @@ import { AgentConfigRegistry, AgentRouter } from '../agents/index.js';
|
||||
import type { CommandRegistry } from '../commands/index.js';
|
||||
import type { ComponentRegistry } from '../intents/index.js';
|
||||
import type { RoutingPolicy } from '../routing/index.js';
|
||||
import type { HookEngine } from '../hooks/index.js';
|
||||
import { createClientFromConfig } from './models.js';
|
||||
import { matchReactionPrompt } from '../automation/reactions.js';
|
||||
import type { SkillRegistry } from '../skills/index.js';
|
||||
@@ -116,6 +117,7 @@ export function createMessageRouter(deps: {
|
||||
agentRouter?: AgentRouter;
|
||||
sandboxManager?: SandboxManager;
|
||||
commandRegistry?: CommandRegistry;
|
||||
hookEngine?: HookEngine;
|
||||
intentRegistry?: ComponentRegistry;
|
||||
routingPolicy?: RoutingPolicy;
|
||||
skillRegistry?: SkillRegistry;
|
||||
@@ -936,6 +938,86 @@ export function createMessageRouter(deps: {
|
||||
deps.sessionManager.transferSession(msg.channel, msg.senderId, toFrontend, toUserId);
|
||||
return `Session transferred to ${destinationLabel}`;
|
||||
},
|
||||
|
||||
getApprovals: () => {
|
||||
if (!deps.hookEngine) {
|
||||
return 'Approval gates are not enabled in this runtime.';
|
||||
}
|
||||
const pending = deps.hookEngine.getPendingConfirmations({ sessionId: session.id });
|
||||
if (pending.length === 0) {
|
||||
return 'No pending approvals for this session.';
|
||||
}
|
||||
const lines = ['Pending approvals:'];
|
||||
for (const item of pending) {
|
||||
const ageSec = Math.max(0, Math.round((Date.now() - item.createdAt.getTime()) / 1000));
|
||||
lines.push(`- ${item.id} | ${item.tool} | ${ageSec}s old`);
|
||||
}
|
||||
lines.push('');
|
||||
lines.push('Use `/approve <id>` or `/deny <id> <reason>` (id optional: latest is used).');
|
||||
return lines.join('\n');
|
||||
},
|
||||
|
||||
approvePending: (inputRaw: string) => {
|
||||
if (!deps.hookEngine) {
|
||||
return 'Approval gates are not enabled in this runtime.';
|
||||
}
|
||||
const pending = deps.hookEngine.getPendingConfirmations({ sessionId: session.id });
|
||||
if (pending.length === 0) {
|
||||
return 'No pending approvals for this session.';
|
||||
}
|
||||
|
||||
const input = inputRaw.trim();
|
||||
const selected = input
|
||||
? pending.find((item) => item.id === input)
|
||||
: pending[pending.length - 1];
|
||||
|
||||
if (!selected) {
|
||||
return `Approval id not found in this session: ${input}`;
|
||||
}
|
||||
|
||||
const resolved = deps.hookEngine.resolveConfirmation(selected.id, { approved: true });
|
||||
return resolved
|
||||
? `Approved: ${selected.tool} (${selected.id})`
|
||||
: `Approval request is no longer pending: ${selected.id}`;
|
||||
},
|
||||
|
||||
denyPending: (inputRaw: string) => {
|
||||
if (!deps.hookEngine) {
|
||||
return 'Approval gates are not enabled in this runtime.';
|
||||
}
|
||||
const pending = deps.hookEngine.getPendingConfirmations({ sessionId: session.id });
|
||||
if (pending.length === 0) {
|
||||
return 'No pending approvals for this session.';
|
||||
}
|
||||
|
||||
const input = inputRaw.trim();
|
||||
let targetId: string | undefined;
|
||||
let reason = 'Denied by user';
|
||||
|
||||
if (input) {
|
||||
const [first, ...rest] = input.split(/\s+/);
|
||||
const matched = pending.find((item) => item.id === first);
|
||||
if (matched) {
|
||||
targetId = matched.id;
|
||||
reason = rest.join(' ').trim() || reason;
|
||||
} else {
|
||||
targetId = pending[pending.length - 1].id;
|
||||
reason = input;
|
||||
}
|
||||
} else {
|
||||
targetId = pending[pending.length - 1].id;
|
||||
}
|
||||
|
||||
const selected = pending.find((item) => item.id === targetId);
|
||||
if (!selected) {
|
||||
return `Approval request is no longer pending: ${targetId}`;
|
||||
}
|
||||
|
||||
const resolved = deps.hookEngine.resolveConfirmation(selected.id, { approved: false, reason });
|
||||
return resolved
|
||||
? `Denied: ${selected.tool} (${selected.id}) — ${reason}`
|
||||
: `Approval request is no longer pending: ${selected.id}`;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user