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, 06:00 UTC
| 1 | /** |
| 2 | * E2E fixture: the proxyExecute session option against the live API. |
| 3 | * |
| 4 | * Covers sessions.create() and session.update() with the boolean shorthand, |
| 5 | * the { enable } block, and null, and checks what the session lists. |
| 6 | * |
| 7 | * Requires COMPOSIO_API_KEY in environment. |
| 8 | */ |
| 9 | import { Composio } from '@composio/core'; |
| 10 | |
| 11 | const apiKey = process.env.COMPOSIO_API_KEY; |
| 12 | if (!apiKey) { |
| 13 | console.error('COMPOSIO_API_KEY is required'); |
| 14 | process.exit(1); |
| 15 | } |
| 16 | |
| 17 | const composio = new Composio({ apiKey }); |
| 18 | const META_TOOL = 'COMPOSIO_PROXY_EXECUTE'; |
| 19 | |
| 20 | const toolNames = async session => (await session.tools()).map(tool => tool.function.name); |
| 21 | const enableOf = config => config.proxy_execute?.enable; |
| 22 | |
| 23 | const expectEnable = (label, config, expected) => { |
| 24 | const actual = enableOf(config); |
| 25 | if (actual !== expected) { |
| 26 | throw new Error(`${label}: proxy_execute.enable is ${actual}, expected ${expected}`); |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | const expectListed = async (label, session, expected) => { |
| 31 | const names = await toolNames(session); |
| 32 | if (names.includes(META_TOOL) !== expected) { |
| 33 | throw new Error( |
| 34 | `${label}: ${META_TOOL} ${expected ? 'missing from' : 'present in'} ${names.join(',')}` |
| 35 | ); |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | async function main() { |
| 40 | const userId = `e2e-tool-router-proxy-execute-${Date.now()}`; |
| 41 | const sessions = []; |
| 42 | |
| 43 | try { |
| 44 | const on = await composio.sessions.create(userId, { toolkits: ['github'], proxyExecute: true }); |
| 45 | sessions.push(on); |
| 46 | expectEnable('create(true)', on.config, true); |
| 47 | await expectListed('create(true)', on, true); |
| 48 | console.log('CREATE_ON_OK'); |
| 49 | |
| 50 | expectEnable('update(false)', await on.update({ proxyExecute: false }), false); |
| 51 | await expectListed('update(false)', on, false); |
| 52 | console.log('UPDATE_OFF_OK'); |
| 53 | |
| 54 | expectEnable( |
| 55 | 'update({ enable: true })', |
| 56 | await on.update({ proxyExecute: { enable: true } }), |
| 57 | true |
| 58 | ); |
| 59 | expectEnable('update(null)', await on.update({ proxyExecute: null }), undefined); |
| 60 | const reread = await composio.sessions.use(on.sessionId); |
| 61 | expectEnable('use() after update(null)', reread.config, undefined); |
| 62 | console.log('UPDATE_NULL_OK'); |
| 63 | |
| 64 | const off = await composio.sessions.create(userId, { toolkits: ['github'] }); |
| 65 | sessions.push(off); |
| 66 | expectEnable('create()', off.config, undefined); |
| 67 | await expectListed('create()', off, false); |
| 68 | console.log('DEFAULT_OK'); |
| 69 | |
| 70 | let rejected = false; |
| 71 | try { |
| 72 | const conflict = await composio.sessions.create(userId, { |
| 73 | toolkits: ['github'], |
| 74 | proxyExecute: false, |
| 75 | sandbox: { enableProxyExecution: true }, |
| 76 | }); |
| 77 | sessions.push(conflict); |
| 78 | } catch { |
| 79 | rejected = true; |
| 80 | } |
| 81 | if (!rejected) { |
| 82 | throw new Error( |
| 83 | 'create(false + sandbox.enableProxyExecution) was accepted, expected a rejection' |
| 84 | ); |
| 85 | } |
| 86 | console.log('CONFLICT_REJECTED_OK'); |
| 87 | } finally { |
| 88 | for (const session of sessions) { |
| 89 | await composio.sessions.delete(session.sessionId); |
| 90 | } |
| 91 | console.log('DELETE_OK'); |
| 92 | } |
| 93 | |
| 94 | console.log('ALL_OK'); |
| 95 | } |
| 96 | |
| 97 | main().catch(err => { |
| 98 | console.log('ERROR:', err?.message || err); |
| 99 | process.exit(1); |
| 100 | }); |