mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-05 21:32:46 +02:00
Refactor Composio connection handling and improve tool display logic
- Removed the connection bridge for Composio toolkit OAuth, simplifying the connection process. - Updated ComposioConnectCard to display a more user-friendly connection message. - Introduced a new utility function, getToolDisplayName, to provide human-friendly names for builtin tools. - Refactored App and ChatSidebar components to utilize the new getToolDisplayName function for improved clarity in tool titles. - Cleaned up imports and removed unused code for better maintainability.
This commit is contained in:
parent
587778cb07
commit
fd1632ea5c
7 changed files with 65 additions and 79 deletions
|
|
@ -15,7 +15,6 @@ import { WorkDir } from "../../config/config.js";
|
|||
import { composioAccountsRepo } from "../../composio/repo.js";
|
||||
import { executeAction as executeComposioAction, isConfigured as isComposioConfigured, searchTools as searchComposioTools } from "../../composio/client.js";
|
||||
import { CURATED_TOOLKITS, CURATED_TOOLKIT_SLUGS } from "@x/shared/dist/composio.js";
|
||||
import { getConnectionInitiator } from "../../composio/connection-bridge.js";
|
||||
import type { ToolContext } from "./exec-tool.js";
|
||||
import { generateText } from "ai";
|
||||
import { createProvider } from "../../models/models.js";
|
||||
|
|
@ -1292,7 +1291,7 @@ export const BuiltinTools: z.infer<typeof BuiltinToolsSchema> = {
|
|||
},
|
||||
|
||||
'composio-connect-toolkit': {
|
||||
description: 'Connect a Composio service (Gmail, Slack, GitHub, etc.) via OAuth. Opens the user\'s browser for authentication. After authenticating, the user can use tools from that service.',
|
||||
description: 'Connect a Composio service (Gmail, Slack, GitHub, etc.) via OAuth. Shows a connect card for the user to authenticate.',
|
||||
inputSchema: z.object({
|
||||
toolkitSlug: z.string().describe('The toolkit slug to connect (e.g., "gmail", "github", "slack", "notion")'),
|
||||
}),
|
||||
|
|
@ -1315,35 +1314,13 @@ export const BuiltinTools: z.infer<typeof BuiltinToolsSchema> = {
|
|||
};
|
||||
}
|
||||
|
||||
// Use the connection bridge to trigger OAuth
|
||||
const initiator = getConnectionInitiator();
|
||||
if (!initiator) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Connection system not available. Please try connecting via Settings > Tools Library instead.',
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await initiator(toolkitSlug);
|
||||
if (result.success) {
|
||||
const toolkit = CURATED_TOOLKITS.find(t => t.slug === toolkitSlug);
|
||||
return {
|
||||
success: true,
|
||||
message: `Opening browser to authenticate with ${toolkit?.displayName ?? toolkitSlug}. Please complete the authentication in your browser, then let me know when you're done.`,
|
||||
};
|
||||
}
|
||||
return {
|
||||
success: false,
|
||||
error: result.error || 'Failed to initiate connection',
|
||||
};
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
return {
|
||||
success: false,
|
||||
error: `Connection failed: ${message}`,
|
||||
};
|
||||
}
|
||||
// Return signal — the UI renders a ComposioConnectCard with a Connect button.
|
||||
// OAuth only starts when the user clicks that button.
|
||||
const toolkit = CURATED_TOOLKITS.find(t => t.slug === toolkitSlug);
|
||||
return {
|
||||
success: true,
|
||||
message: `Please connect ${toolkit?.displayName ?? toolkitSlug} to continue.`,
|
||||
};
|
||||
},
|
||||
isAvailable: async () => isComposioConfigured(),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
/**
|
||||
* Connection bridge for Composio toolkit OAuth.
|
||||
*
|
||||
* Builtin tools run in the core package which cannot import Electron-specific
|
||||
* code from the main process. This module provides a callback registry so the
|
||||
* main process can register its `initiateConnection` function at startup, and
|
||||
* builtin tools can call it at runtime.
|
||||
*/
|
||||
|
||||
type ConnectionInitiator = (toolkitSlug: string) => Promise<{
|
||||
success: boolean;
|
||||
redirectUrl?: string;
|
||||
connectedAccountId?: string;
|
||||
error?: string;
|
||||
}>;
|
||||
|
||||
let connectionInitiator: ConnectionInitiator | null = null;
|
||||
|
||||
/**
|
||||
* Register the connection initiator callback.
|
||||
* Called once by the main process at startup.
|
||||
*/
|
||||
export function setConnectionInitiator(fn: ConnectionInitiator): void {
|
||||
connectionInitiator = fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the registered connection initiator.
|
||||
* Returns null if not yet registered (app not fully initialized).
|
||||
*/
|
||||
export function getConnectionInitiator(): ConnectionInitiator | null {
|
||||
return connectionInitiator;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue