@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 04:45 UTC

next
ts 73 lines 2.66 KB
Raw
1 /** Unattended CI verification, restricted to the read-only tools in session.ts. */
2 import assert from 'node:assert/strict';
3 import { type ToolRouterInputResponse } from '@composio/core';
4 import { runWithApprovals } from './approval';
5 import {
6 createApprovalSession,
7 createComposio,
8 multiArguments,
9 tool,
10 toolArguments,
11 } from './session';
12 import { assertBatch, assertDenied } from './verification';
13
14 const composio = createComposio();
15 const cases: [string, ToolRouterInputResponse, boolean][] = [
16 ['approve', { action: 'accept', content: { decision: 'approve' } }, true],
17 ['deny', { action: 'accept', content: { decision: 'deny' } }, false],
18 ['decline', { action: 'decline' }, false],
19 ['cancel', { action: 'cancel' }, false],
20 ['always_approve', { action: 'accept', content: { decision: 'always_approve' } }, true],
21 ];
22
23 for (const [label, answer, allowed] of cases) {
24 // Fresh sessions prevent Always approve from affecting other cases.
25 const session = await createApprovalSession(composio);
26 try {
27 let prompts = 0;
28 const result = await runWithApprovals(
29 options => session.execute(tool, toolArguments, options),
30 async () => {
31 assert.ok(++prompts <= 2, 'Approval did not resolve');
32 return answer;
33 }
34 );
35 assert.ok(prompts > 0, 'Execution bypassed approval');
36 assert.equal(result.resultType, allowed ? 'completed' : 'failed');
37 if (allowed) {
38 assert.equal(result.error, null);
39 assert.ok(Object.keys(result.data).length > 0);
40 } else assertDenied(result.error);
41 if (label === 'always_approve') {
42 const next = await runWithApprovals(
43 options => session.execute(tool, { username: 'dang' }, options),
44 async () => {
45 throw new Error('Always approve asked again in the same session');
46 }
47 );
48 assert.equal(next.resultType, 'completed');
49 assert.equal(next.error, null);
50 assert.ok(Object.keys(next.data).length > 0);
51 }
52 console.log(`PASS ${label}`);
53 } finally {
54 await composio.sessions.delete(session.sessionId);
55 }
56 }
57
58 const session = await createApprovalSession(composio);
59 try {
60 let prompts = 0;
61 const result = await runWithApprovals(
62 options => session.executeMeta('COMPOSIO_MULTI_EXECUTE_TOOL', multiArguments, options),
63 async () => {
64 assert.ok(++prompts <= 2, 'Batch approval did not resolve');
65 return { action: 'accept', content: { decision: prompts === 1 ? 'approve' : 'deny' } };
66 }
67 );
68 assert.equal(prompts, 2, 'Expected a question for each tool call');
69 assertBatch(result.data, 1, 1);
70 console.log('PASS batch with one approval and one denial');
71 } finally {
72 await composio.sessions.delete(session.sessionId);
73 }