MCPcopy Create free account
hub / github.com/AI45Lab/Code / main

Function main

sdk/node/examples/streaming/hitl_confirmation_loop.ts:70–128  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

68}
69
70async function main(): Promise<void> {
71 const configPath = process.env.A3S_CONFIG_FILE ?? process.argv[2];
72 if (!configPath) {
73 throw new Error('Set A3S_CONFIG_FILE or pass an agent.acl path as the first argument.');
74 }
75
76 const workspace = process.env.A3S_CODE_WORKSPACE ?? process.cwd();
77 const prompt = process.env.A3S_CODE_HITL_PROMPT
78 ?? 'Use the bash tool to run: echo A3S_CODE_HITL_OK. Then summarize the result.';
79
80 const options: SessionOptions = {
81 planningMode: 'disabled',
82 permissionPolicy: {
83 ask: ['bash*'],
84 defaultDecision: 'allow',
85 },
86 confirmationPolicy: {
87 enabled: true,
88 defaultTimeoutMs: 120000,
89 timeoutAction: 'reject',
90 yoloLanes: ['query'],
91 },
92 };
93
94 const agent = await Agent.create(configPath);
95 const session = agent.session(workspace, options);
96 const rl = createInterface({ input, output });
97
98 try {
99 const stream = await session.stream(prompt);
100
101 while (true) {
102 const next = await stream.next();
103 if (next.done || !next.value) break;
104
105 const event = next.value;
106 if (event.type === 'text_delta' && event.text) {
107 process.stdout.write(event.text);
108 } else if (event.type === 'tool_start') {
109 console.log(`\n[tool:start] ${event.toolName ?? 'unknown'}`);
110 } else if (event.type === 'tool_end') {
111 console.log(`\n[tool:end] ${event.toolName ?? 'unknown'} exit=${event.exitCode ?? 0}`);
112 } else if (event.type === 'confirmation_required') {
113 await confirmFromCli(session, event, question => rl.question(question));
114 } else if (event.type === 'confirmation_received') {
115 console.log(`\n[hitl] confirmation_received ${event.toolId ?? ''}`);
116 } else if (event.type === 'confirmation_timeout') {
117 console.log(`\n[hitl] confirmation_timeout ${event.toolId ?? ''}`);
118 } else if (event.type === 'error') {
119 throw new Error(event.error ?? 'stream error');
120 }
121 }
122
123 console.log('\n[hitl] stream complete');
124 } finally {
125 rl.close();
126 await session.cancelConfirmations();
127 }

Callers 1

Calls 8

confirmFromCliFunction · 0.85
writeMethod · 0.80
createMethod · 0.45
sessionMethod · 0.45
streamMethod · 0.45
nextMethod · 0.45
logMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected