mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-16 18:25:17 +02:00
Upgrade composio package and update no_auth logic
This commit is contained in:
parent
ec40873212
commit
463630cc0a
3 changed files with 114 additions and 221 deletions
|
|
@ -74,13 +74,111 @@ export async function listTools(toolkitSlug: string, searchQuery: string | null
|
|||
url.searchParams.set("cursor", cursor);
|
||||
}
|
||||
|
||||
// fetch
|
||||
return composioApiCall(ZListResponse(ZTool), url.toString());
|
||||
// First get the tools list response
|
||||
const toolsResponse = await fetch(url.toString(), {
|
||||
headers: {
|
||||
"x-api-key": COMPOSIO_API_KEY,
|
||||
},
|
||||
});
|
||||
|
||||
if (!toolsResponse.ok) {
|
||||
throw new Error(`Failed to fetch tools list: ${toolsResponse.status} ${toolsResponse.statusText}`);
|
||||
}
|
||||
|
||||
const toolsData = await toolsResponse.json();
|
||||
|
||||
// Check for error response
|
||||
if ('error' in toolsData) {
|
||||
const response = ZErrorResponse.parse(toolsData);
|
||||
throw new Error(`(code: ${response.error.error_code}): ${response.error.message}: ${response.error.suggested_fix}: ${response.error.errors?.join(', ')}`);
|
||||
}
|
||||
|
||||
// Get toolkit data to compute no_auth for all tools
|
||||
const toolkitUrl = new URL(`${BASE_URL}/toolkits/${toolkitSlug}`);
|
||||
const toolkitResponse = await fetch(toolkitUrl.toString(), {
|
||||
headers: {
|
||||
"x-api-key": COMPOSIO_API_KEY,
|
||||
},
|
||||
});
|
||||
|
||||
if (!toolkitResponse.ok) {
|
||||
throw new Error(`Failed to fetch toolkit: ${toolkitResponse.status} ${toolkitResponse.statusText}`);
|
||||
}
|
||||
|
||||
const toolkitData = await toolkitResponse.json();
|
||||
|
||||
// Compute no_auth from toolkit data
|
||||
const no_auth = toolkitData.composio_managed_auth_schemes?.includes('NO_AUTH') ||
|
||||
toolkitData.auth_config_details?.some((config: any) => config.mode === 'NO_AUTH') ||
|
||||
false;
|
||||
|
||||
// Enrich all tools in the list with computed no_auth
|
||||
const enrichedToolsData = {
|
||||
...toolsData,
|
||||
items: toolsData.items.map((tool: any) => ({
|
||||
...tool,
|
||||
no_auth
|
||||
}))
|
||||
};
|
||||
|
||||
// Now parse with our schema
|
||||
return ZListResponse(ZTool).parse(enrichedToolsData);
|
||||
}
|
||||
|
||||
export async function getTool(toolSlug: string): Promise<z.infer<typeof ZTool>> {
|
||||
const url = new URL(`${BASE_URL}/tools/${toolSlug}`);
|
||||
return composioApiCall(ZTool, url.toString());
|
||||
|
||||
// First get the tool response
|
||||
const toolResponse = await fetch(url.toString(), {
|
||||
headers: {
|
||||
"x-api-key": COMPOSIO_API_KEY,
|
||||
},
|
||||
});
|
||||
|
||||
if (!toolResponse.ok) {
|
||||
throw new Error(`Failed to fetch tool: ${toolResponse.status} ${toolResponse.statusText}`);
|
||||
}
|
||||
|
||||
const toolData = await toolResponse.json();
|
||||
|
||||
// Check for error response
|
||||
if ('error' in toolData) {
|
||||
const response = ZErrorResponse.parse(toolData);
|
||||
throw new Error(`(code: ${response.error.error_code}): ${response.error.message}: ${response.error.suggested_fix}: ${response.error.errors?.join(', ')}`);
|
||||
}
|
||||
|
||||
// Get toolkit data to compute no_auth
|
||||
const toolkitSlug = toolData.toolkit?.slug;
|
||||
if (!toolkitSlug) {
|
||||
throw new Error(`Tool response missing toolkit slug: ${JSON.stringify(toolData)}`);
|
||||
}
|
||||
|
||||
const toolkitUrl = new URL(`${BASE_URL}/toolkits/${toolkitSlug}`);
|
||||
const toolkitResponse = await fetch(toolkitUrl.toString(), {
|
||||
headers: {
|
||||
"x-api-key": COMPOSIO_API_KEY,
|
||||
},
|
||||
});
|
||||
|
||||
if (!toolkitResponse.ok) {
|
||||
throw new Error(`Failed to fetch toolkit: ${toolkitResponse.status} ${toolkitResponse.statusText}`);
|
||||
}
|
||||
|
||||
const toolkitData = await toolkitResponse.json();
|
||||
|
||||
// Compute no_auth from toolkit data
|
||||
const no_auth = toolkitData.composio_managed_auth_schemes?.includes('NO_AUTH') ||
|
||||
toolkitData.auth_config_details?.some((config: any) => config.mode === 'NO_AUTH') ||
|
||||
false;
|
||||
|
||||
// Inject computed no_auth into tool data
|
||||
const enrichedToolData = {
|
||||
...toolData,
|
||||
no_auth
|
||||
};
|
||||
|
||||
// Now parse with our schema
|
||||
return ZTool.parse(enrichedToolData);
|
||||
}
|
||||
|
||||
export async function listAuthConfigs(toolkitSlug: string, cursor: string | null = null, managedOnly: boolean = false): Promise<z.infer<ReturnType<typeof ZListResponse<typeof ZAuthConfig>>>> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue