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

next
ts 65 lines 1.43 KB
Raw
1 import type { SessionProxyExecuteResponse } from '@composio/client/resources/tool-router/session';
2
3 export const formatProxyOutput = (
4 result: Pick<
5 Extract<SessionProxyExecuteResponse, { result_type: 'completed' }>,
6 'status' | 'data' | 'headers' | 'binary_data'
7 >
8 ) => {
9 if (result.binary_data) {
10 return JSON.stringify(
11 {
12 status: result.status ?? null,
13 headers: result.headers ?? {},
14 binary_data: result.binary_data,
15 },
16 null,
17 2
18 );
19 }
20
21 if (typeof result.data === 'string') {
22 return result.data;
23 }
24
25 if (result.data === undefined || result.data === null) {
26 return '';
27 }
28
29 return JSON.stringify(result.data, null, 2);
30 };
31
32 export const formatProxyErrorOutput = (params: {
33 readonly error: string;
34 readonly toolkit: string;
35 readonly endpoint: string;
36 readonly slug?: string;
37 }) =>
38 JSON.stringify(
39 {
40 successful: false,
41 error: params.error,
42 toolkit: params.toolkit,
43 endpoint: params.endpoint,
44 slug: params.slug ?? null,
45 },
46 null,
47 2
48 );
49
50 /** The stdout result of a call refused because the toolkit is not connected. */
51 export const formatProxyNotConnectedOutput = (params: {
52 readonly error: string;
53 readonly toolkit: string;
54 readonly endpoint: string;
55 }) =>
56 JSON.stringify(
57 {
58 successful: false,
59 error: params.error,
60 toolkit: params.toolkit,
61 endpoint: params.endpoint,
62 },
63 null,
64 2
65 );