Repository navigation
Expand file tree
/
Copy pathapproval-flow.js
More file actions
50 lines (41 loc) · 1.46 KB
/
Copy pathapproval-flow.js
File metadata and controls
50 lines (41 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { DashClaw, ApprovalDeniedError } from '../sdk/dashclaw.js';
import dotenv from 'dotenv';
dotenv.config();
const claw = new DashClaw({
baseUrl: process.env.DASHCLAW_BASE_URL || 'http://localhost:3000',
apiKey: process.env.DASHCLAW_API_KEY,
agentId: 'node-approval-agent',
});
async function main() {
console.log('Initiating high-risk action...');
try {
// 1. Create action that requires approval
const { action } = await claw.createAction({
action_type: 'infrastructure',
declared_goal: 'Resize production database cluster',
risk_score: 95,
systems_touched: ['aws_rds', 'terraform'],
reversible: true
});
const actionId = action.action_id;
console.log(`Action created: ${actionId}. Waiting for human operator...`);
// 2. Wait for HITL decision (polls until approved/denied)
await claw.waitForApproval(actionId);
console.log('Approval received! Proceeding with execution...');
// 3. Perform the work
await new Promise(resolve => setTimeout(resolve, 2000)); // Simulate work
// 4. Record success
await claw.updateOutcome(actionId, {
status: 'completed',
output_summary: 'Cluster resized to 4x large successfully.'
});
console.log('Task complete.');
} catch (error) {
if (error instanceof ApprovalDeniedError) {
console.error(`Action DENIED by operator: ${error.message}`);
} else {
console.error(`Unexpected error: ${error.message}`);
}
}
}
main();