mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-16 18:25:17 +02:00
Fix/composio saml auth scheme (#325)
* fix: add SAML to Composio auth scheme enum - Add 'SAML' to ZAuthScheme enum in types.ts to support SAML authentication - Add SAML case to getAuthMethodName in ToolkitAuthModal for proper display - Fixes ZodError when Composio API returns toolkits with SAML auth schemes - Resolves 500 error when fetching Composio toolkits * refactor: update composio tool search response handling in copilot
This commit is contained in:
parent
3185772080
commit
d56df553c6
3 changed files with 27 additions and 15 deletions
|
|
@ -312,6 +312,8 @@ export function ToolkitAuthModal({
|
||||||
return 'Bearer Token';
|
return 'Bearer Token';
|
||||||
case 'BASIC':
|
case 'BASIC':
|
||||||
return 'Basic Auth';
|
return 'Basic Auth';
|
||||||
|
case 'SAML':
|
||||||
|
return 'SAML';
|
||||||
default:
|
default:
|
||||||
return authScheme.toLowerCase().replace('_', ' ');
|
return authScheme.toLowerCase().replace('_', ' ');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ export const ZAuthScheme = z.enum([
|
||||||
'NO_AUTH',
|
'NO_AUTH',
|
||||||
'OAUTH1',
|
'OAUTH1',
|
||||||
'OAUTH2',
|
'OAUTH2',
|
||||||
|
'SAML',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const ZConnectedAccountStatus = z.enum([
|
export const ZConnectedAccountStatus = z.enum([
|
||||||
|
|
|
||||||
|
|
@ -36,16 +36,10 @@ const openai = createOpenAI({
|
||||||
compatibility: "strict",
|
compatibility: "strict",
|
||||||
});
|
});
|
||||||
|
|
||||||
const composioToolSearchToolSuggestion = z.object({
|
|
||||||
toolkit: z.string(),
|
|
||||||
tool_slug: z.string(),
|
|
||||||
description: z.string(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const composioToolSearchResponseSchema = z.object({
|
const composioToolSearchResponseSchema = z.object({
|
||||||
main_tools: z.array(composioToolSearchToolSuggestion).optional(),
|
results: z.array(z.object({
|
||||||
related_tools: z.array(composioToolSearchToolSuggestion).optional(),
|
primary_tool_slugs: z.array(z.string()).optional(),
|
||||||
results: z.array(composioToolSearchToolSuggestion).optional(), // Keep for backward compatibility
|
}).passthrough()).optional(),
|
||||||
}).passthrough();
|
}).passthrough();
|
||||||
|
|
||||||
function getContextPrompt(context: z.infer<typeof CopilotChatContext> | null): string {
|
function getContextPrompt(context: z.infer<typeof CopilotChatContext> | null): string {
|
||||||
|
|
@ -182,17 +176,19 @@ async function searchRelevantTools(usageTracker: UsageTracker, query: string): P
|
||||||
const result = composioToolSearchResponseSchema.safeParse(searchResult.data);
|
const result = composioToolSearchResponseSchema.safeParse(searchResult.data);
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
logger.log(`tool search response is invalid: ${JSON.stringify(result.error)}`);
|
logger.log(`tool search response is invalid: ${JSON.stringify(result.error)}`);
|
||||||
logger.log(`expected schema: results (array), got: ${JSON.stringify(Object.keys(searchResult.data || {}))}`);
|
|
||||||
return 'No tools found!';
|
return 'No tools found!';
|
||||||
}
|
}
|
||||||
const tools = result.data.main_tools || result.data.results || [];
|
|
||||||
|
|
||||||
if (!tools.length) {
|
// Extract tool slugs from results[].primary_tool_slugs[]
|
||||||
|
const toolSlugs = (result.data.results || [])
|
||||||
|
.flatMap((item: any) => item.primary_tool_slugs || [])
|
||||||
|
.filter((slug: string) => slug);
|
||||||
|
|
||||||
|
if (!toolSlugs.length) {
|
||||||
logger.log(`tool search yielded no results`);
|
logger.log(`tool search yielded no results`);
|
||||||
return 'No tools found!';
|
return 'No tools found!';
|
||||||
}
|
}
|
||||||
|
|
||||||
const toolSlugs = tools.map((item) => item.tool_slug);
|
|
||||||
logger.log(`found tool slugs: ${toolSlugs.join(', ')}`);
|
logger.log(`found tool slugs: ${toolSlugs.join(', ')}`);
|
||||||
console.log("✅ TOOL CALL SUCCESS: COMPOSIO_SEARCH_TOOLS", {
|
console.log("✅ TOOL CALL SUCCESS: COMPOSIO_SEARCH_TOOLS", {
|
||||||
toolSlugs,
|
toolSlugs,
|
||||||
|
|
@ -201,7 +197,20 @@ async function searchRelevantTools(usageTracker: UsageTracker, query: string): P
|
||||||
|
|
||||||
// Enrich tools with full details
|
// Enrich tools with full details
|
||||||
console.log("🔧 TOOL CALL: getTool (multiple calls)", { toolSlugs });
|
console.log("🔧 TOOL CALL: getTool (multiple calls)", { toolSlugs });
|
||||||
const composioTools = await Promise.all(toolSlugs.map(slug => getTool(slug)));
|
const composioToolsResults = await Promise.allSettled(
|
||||||
|
toolSlugs.map(slug => getTool(slug))
|
||||||
|
);
|
||||||
|
|
||||||
|
// Filter out failed tool fetches
|
||||||
|
const composioTools = composioToolsResults
|
||||||
|
.filter((result): result is PromiseFulfilledResult<any> => result.status === 'fulfilled')
|
||||||
|
.map(result => result.value);
|
||||||
|
|
||||||
|
if (composioTools.length === 0) {
|
||||||
|
logger.log('all tool fetches failed');
|
||||||
|
return 'No tools found!';
|
||||||
|
}
|
||||||
|
|
||||||
const workflowTools: z.infer<typeof WorkflowTool>[] = composioTools.map(tool => ({
|
const workflowTools: z.infer<typeof WorkflowTool>[] = composioTools.map(tool => ({
|
||||||
name: tool.name,
|
name: tool.name,
|
||||||
description: tool.description,
|
description: tool.description,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue