mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-10 07:27:57 -05:00
112 lines
3.5 KiB
TypeScript
112 lines
3.5 KiB
TypeScript
import { chatTool as anthropicChat } from './anthropic/chat'
|
|
import { visionTool as crewAIVision } from './crewai/vision'
|
|
import { chatTool as deepseekChat } from './deepseek/chat'
|
|
import { reasonerTool as deepseekReasoner } from './deepseek/reasoner'
|
|
import { scrapeTool } from './firecrawl/scrape'
|
|
import { functionExecuteTool as functionExecute } from './function/execute'
|
|
import { repoInfoTool } from './github/repo'
|
|
import { chatTool as googleChat } from './google/chat'
|
|
import { requestTool as httpRequest } from './http/request'
|
|
import { contactsTool as hubspotContacts } from './hubspot/contacts'
|
|
import { readUrlTool } from './jina/reader'
|
|
import { chatTool as openAIChat } from './openai/chat'
|
|
import { opportunitiesTool as salesforceOpportunities } from './salesforce/opportunities'
|
|
import { searchTool as serperSearch } from './serper/search'
|
|
import { slackMessageTool } from './slack/message'
|
|
import { extractTool as tavilyExtract } from './tavily/extract'
|
|
import { searchTool as tavilySearch } from './tavily/search'
|
|
import { ToolConfig, ToolResponse } from './types'
|
|
import { chatTool as xaiChat } from './xai/chat'
|
|
import { youtubeSearchTool } from './youtube/search'
|
|
|
|
// Registry of all available tools
|
|
export const tools: Record<string, ToolConfig> = {
|
|
// AI Models
|
|
openai_chat: openAIChat,
|
|
anthropic_chat: anthropicChat,
|
|
google_chat: googleChat,
|
|
xai_chat: xaiChat,
|
|
deepseek_chat: deepseekChat,
|
|
deepseek_reasoner: deepseekReasoner,
|
|
// HTTP
|
|
http_request: httpRequest,
|
|
// CRM Tools
|
|
hubspot_contacts: hubspotContacts,
|
|
salesforce_opportunities: salesforceOpportunities,
|
|
// Function Tools
|
|
function_execute: functionExecute,
|
|
// CrewAI Tools
|
|
crewai_vision: crewAIVision,
|
|
// Firecrawl Tools
|
|
firecrawl_scrape: scrapeTool,
|
|
// Jina Tools
|
|
jina_readurl: readUrlTool,
|
|
// Slack Tools
|
|
slack_message: slackMessageTool,
|
|
// GitHub Tools
|
|
github_repoinfo: repoInfoTool,
|
|
// Search Tools
|
|
serper_search: serperSearch,
|
|
tavily_search: tavilySearch,
|
|
tavily_extract: tavilyExtract,
|
|
youtube_search: youtubeSearchTool,
|
|
}
|
|
|
|
// Get a tool by its ID
|
|
export function getTool(toolId: string): ToolConfig | undefined {
|
|
return tools[toolId]
|
|
}
|
|
|
|
// Execute a tool by calling either the proxy for external APIs or directly for internal routes
|
|
export async function executeTool(
|
|
toolId: string,
|
|
params: Record<string, any>
|
|
): Promise<ToolResponse> {
|
|
try {
|
|
const tool = getTool(toolId)
|
|
if (!tool) {
|
|
throw new Error(`Tool not found: ${toolId}`)
|
|
}
|
|
|
|
// For internal routes, call the API directly
|
|
if (tool.request.isInternalRoute) {
|
|
const url =
|
|
typeof tool.request.url === 'function' ? tool.request.url(params) : tool.request.url
|
|
|
|
const response = await fetch(url, {
|
|
method: tool.request.method,
|
|
headers: tool.request.headers(params),
|
|
body: JSON.stringify(tool.request.body ? tool.request.body(params) : params),
|
|
})
|
|
|
|
const result = await tool.transformResponse(response)
|
|
return result
|
|
}
|
|
|
|
// For external APIs, use the proxy
|
|
const response = await fetch('/api/proxy', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ toolId, params }),
|
|
})
|
|
|
|
const result = await response.json()
|
|
|
|
if (!result.success) {
|
|
return {
|
|
success: false,
|
|
output: {},
|
|
error: result.error,
|
|
}
|
|
}
|
|
|
|
return result
|
|
} catch (error: any) {
|
|
return {
|
|
success: false,
|
|
output: {},
|
|
error: error.message || 'Unknown error',
|
|
}
|
|
}
|
|
}
|