const { requestUserInput } = window.aparte;
const chat = document.querySelector('aparte-chat');
chat.viewport.appendMessage({ id: 'u1', role: 'user', content: 'Clean up the old client.', timestamp: Date.now() });
chat.viewport.appendMessage({
id: 'a1', role: 'assistant', timestamp: Date.now(),
segments: [{
id: 's1', type: 'tool_call', status: 'awaiting-approval',
toolCall: { id: 't1', name: 'delete_file', input: { path: 'src/legacy/old-client.ts' } },
}],
});
// The decision is asked at the composer, with the arguments it is about. AparteClient
// runs or refuses the call on the answer; here the answer is played onto the row by hand.
const row = (updates) => chat.viewport.updateSegment('a1', 's1', updates);
const reply = (content) => chat.viewport.addSegment('a1', { id: 's2', type: 'text', content });
requestUserInput({
kind: 'approval',
message: 'Allow delete_file?',
details: JSON.stringify({ path: 'src/legacy/old-client.ts' }, null, 2),
options: [
{ value: 'approve', label: 'Approve' },
{ value: 'reject', label: 'Reject', tone: 'deny' },
],
}).then((answer) => {
const typed = answer.action === 'accept' ? (answer.content.instruction || '').trim() : '';
if (answer.action === 'accept' && !typed && answer.content.option === 'approve') {
row({ status: 'pending' });
setTimeout(() => {
row({ status: 'resolved', result: 'Deleted src/legacy/old-client.ts.' });
reply('Done: the old client is gone.');
}, 900);
} else {
// Typing instead of choosing is a refusal that carries the person's words.
row({
status: 'rejected',
result: 'Tool execution was rejected by the user.',
refusal: typed ? { by: 'person', instruction: typed } : { by: 'person' },
});
reply(typed ? 'Understood, I will do that instead.' : 'Understood, I left it in place.');
}
}).catch(() => {});