@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 28 lines 999 Bytes
Raw
1 import { extractComposioConnectLinks } from '../auth-links';
2 import { runHook } from './hooks';
3 import { hookControls } from './results';
4 import type { PiAuthLinkContext, PiHookControls, PiSessionToolCapabilities } from './types';
5
6 export { extractComposioConnectLinks } from '../auth-links';
7
8 export const applyAuthLinkHandlers = async (
9 capabilities: PiSessionToolCapabilities,
10 value: unknown,
11 context: Omit<PiAuthLinkContext, 'url' | keyof PiHookControls>
12 ): Promise<{ value: unknown; authLinks: string[] }> => {
13 const links = extractComposioConnectLinks(value);
14 const run = async (index: number, currentValue: unknown): Promise<unknown> => {
15 const url = links[index];
16 if (!url) return currentValue;
17 return run(
18 index + 1,
19 await runHook(
20 capabilities.hooks?.onAuthLink,
21 { ...context, ...hookControls, url, result: currentValue },
22 async () => currentValue
23 )
24 );
25 };
26
27 return { value: await run(0, value), authLinks: links };
28 };