mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
Changed id back to type on config
This commit is contained in:
@@ -39,7 +39,7 @@ interface ToolParam {
|
||||
// Assumes the first tool in the access array is the tool to be used
|
||||
// TODO: Switch to getting tools instead of tool blocks once we switch to providers
|
||||
const getToolIdFromBlock = (blockType: string): string | undefined => {
|
||||
const block = getAllBlocks().find((block) => block.id === blockType)
|
||||
const block = getAllBlocks().find((block) => block.type === blockType)
|
||||
return block?.tools.access[0]
|
||||
}
|
||||
|
||||
@@ -71,14 +71,14 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) {
|
||||
|
||||
const handleSelectTool = (toolBlock: (typeof toolBlocks)[0]) => {
|
||||
// Check if tool already exists
|
||||
if (selectedTools.some((tool) => tool.type === toolBlock.id)) {
|
||||
if (selectedTools.some((tool) => tool.type === toolBlock.type)) {
|
||||
setOpen(false)
|
||||
return
|
||||
}
|
||||
|
||||
const toolId = getToolIdFromBlock(toolBlock.id)
|
||||
const toolId = getToolIdFromBlock(toolBlock.type)
|
||||
const newTool: StoredTool = {
|
||||
type: toolBlock.id,
|
||||
type: toolBlock.type,
|
||||
title: toolBlock.name,
|
||||
params: {},
|
||||
isExpanded: true,
|
||||
@@ -155,7 +155,7 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) {
|
||||
<CommandGroup>
|
||||
{toolBlocks.map((block) => (
|
||||
<CommandItem
|
||||
key={block.id}
|
||||
key={block.type}
|
||||
onSelect={() => handleSelectTool(block)}
|
||||
className="flex items-center gap-2 cursor-pointer"
|
||||
>
|
||||
@@ -176,7 +176,7 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) {
|
||||
) : (
|
||||
<div className="flex flex-wrap gap-2 min-h-[2.5rem] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background">
|
||||
{selectedTools.map((tool) => {
|
||||
const toolBlock = toolBlocks.find((block) => block.id === tool.type)
|
||||
const toolBlock = toolBlocks.find((block) => block.type === tool.type)
|
||||
const toolId = getToolIdFromBlock(tool.type)
|
||||
const requiredParams = toolId ? getRequiredToolParams(toolId) : []
|
||||
|
||||
@@ -269,7 +269,7 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) {
|
||||
<CommandGroup>
|
||||
{toolBlocks.map((block) => (
|
||||
<CommandItem
|
||||
key={block.id}
|
||||
key={block.type}
|
||||
onSelect={() => handleSelectTool(block)}
|
||||
className="flex items-center gap-2 cursor-pointer"
|
||||
>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useMemo, useState } from 'react'
|
||||
import { format, formatDistanceToNow } from 'date-fns'
|
||||
import { format } from 'date-fns'
|
||||
import { AlertCircle, AlertTriangle, Calendar, CheckCircle2, Clock, Terminal } from 'lucide-react'
|
||||
import { ConsoleEntry as ConsoleEntryType } from '@/stores/console/types'
|
||||
import { getBlock } from '@/blocks'
|
||||
@@ -13,14 +13,6 @@ interface ConsoleEntryProps {
|
||||
export function ConsoleEntry({ entry, consoleWidth }: ConsoleEntryProps) {
|
||||
const [isExpanded, setIsExpanded] = useState(false)
|
||||
|
||||
const timeAgo = useMemo(
|
||||
() =>
|
||||
formatDistanceToNow(new Date(entry.startedAt), {
|
||||
addSuffix: true,
|
||||
}),
|
||||
[entry.startedAt]
|
||||
)
|
||||
|
||||
const blockConfig = useMemo(() => {
|
||||
if (!entry.blockType) return null
|
||||
return getBlock(entry.blockType)
|
||||
|
||||
@@ -6,7 +6,7 @@ export type ToolbarBlockProps = {
|
||||
|
||||
export function ToolbarBlock({ config }: ToolbarBlockProps) {
|
||||
const handleDragStart = (e: React.DragEvent) => {
|
||||
e.dataTransfer.setData('application/json', JSON.stringify({ type: config.id }))
|
||||
e.dataTransfer.setData('application/json', JSON.stringify({ type: config.type }))
|
||||
e.dataTransfer.effectAllowed = 'move'
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export function ToolbarBlock({ config }: ToolbarBlockProps) {
|
||||
>
|
||||
<config.icon
|
||||
className={`text-white transition-transform duration-200 group-hover:scale-110 ${
|
||||
config.id === 'agent' ? 'w-[24px] h-[24px]' : 'w-[22px] h-[22px]'
|
||||
config.type === 'agent' ? 'w-[24px] h-[24px]' : 'w-[22px] h-[22px]'
|
||||
}`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -69,7 +69,7 @@ export function Toolbar() {
|
||||
<div className="p-4 pb-20">
|
||||
<div className="flex flex-col gap-3">
|
||||
{blocks.map((block) => (
|
||||
<ToolbarBlock key={block.id} config={block} />
|
||||
<ToolbarBlock key={block.type} config={block} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -23,7 +23,7 @@ interface AgentResponse extends ToolResponse {
|
||||
}
|
||||
|
||||
export const AgentBlock: BlockConfig<AgentResponse> = {
|
||||
id: 'agent',
|
||||
type: 'agent',
|
||||
name: 'Agent',
|
||||
description: 'Build an agent',
|
||||
category: 'blocks',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { RequestResponse } from '@/tools/http/request'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const ApiBlock: BlockConfig<RequestResponse> = {
|
||||
id: 'api',
|
||||
type: 'api',
|
||||
name: 'API',
|
||||
description: 'Use any API',
|
||||
category: 'blocks',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { CodeExecutionOutput } from '@/tools/function/execute'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const ConditionBlock: BlockConfig<CodeExecutionOutput> = {
|
||||
id: 'condition',
|
||||
type: 'condition',
|
||||
name: 'Condition',
|
||||
description: 'Add a condition',
|
||||
longDescription: 'Add a condition to the workflow',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { VisionResponse } from '@/tools/crewai/vision'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const CrewAIVisionBlock: BlockConfig<VisionResponse> = {
|
||||
id: 'crewai_vision',
|
||||
type: 'crewai_vision',
|
||||
name: 'CrewAI Vision',
|
||||
description: 'Analyze images with vision models',
|
||||
category: 'tools',
|
||||
|
||||
@@ -56,7 +56,7 @@ const generateResponseFormat = (metrics: Metric[]) => ({
|
||||
})
|
||||
|
||||
export const EvaluatorBlock: BlockConfig<EvaluatorResponse> = {
|
||||
id: 'evaluator',
|
||||
type: 'evaluator',
|
||||
name: 'Evaluator',
|
||||
description: 'Evaluate content',
|
||||
category: 'blocks',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ScrapeResponse } from '@/tools/firecrawl/scrape'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const FirecrawlBlock: BlockConfig<ScrapeResponse> = {
|
||||
id: 'firecrawl',
|
||||
type: 'firecrawl',
|
||||
name: 'Firecrawl',
|
||||
description: 'Scrape website content',
|
||||
category: 'tools',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { CodeExecutionOutput } from '@/tools/function/execute'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const FunctionBlock: BlockConfig<CodeExecutionOutput> = {
|
||||
id: 'function',
|
||||
type: 'function',
|
||||
name: 'Function',
|
||||
description: 'Run custom logic',
|
||||
category: 'blocks',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { GithubIcon } from '../../components/icons'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const GitHubBlock: BlockConfig<RepoInfoResponse> = {
|
||||
id: 'github',
|
||||
type: 'github',
|
||||
name: 'GitHub',
|
||||
description: 'Fetch GitHub repository',
|
||||
category: 'tools',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { GmailToolResponse } from '@/tools/gmail/types'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const GmailBlock: BlockConfig<GmailToolResponse> = {
|
||||
id: 'gmail',
|
||||
type: 'gmail',
|
||||
name: 'Gmail',
|
||||
description: 'Send, read, and search Gmail messages',
|
||||
category: 'tools',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ReadUrlResponse } from '@/tools/jina/reader'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const JinaBlock: BlockConfig<ReadUrlResponse> = {
|
||||
id: 'jina',
|
||||
type: 'jina',
|
||||
name: 'Jina',
|
||||
description: 'Convert website content into text',
|
||||
category: 'tools',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { NotionResponse } from '@/tools/notion/read'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const NotionBlock: BlockConfig<NotionResponse> = {
|
||||
id: 'notion',
|
||||
type: 'notion',
|
||||
name: 'Notion',
|
||||
description: 'Read and write to Notion pages and databases',
|
||||
category: 'tools',
|
||||
|
||||
@@ -86,7 +86,7 @@ Remember: Your response must be ONLY the block ID - no additional text, formatti
|
||||
}
|
||||
|
||||
export const RouterBlock: BlockConfig<RouterResponse> = {
|
||||
id: 'router',
|
||||
type: 'router',
|
||||
name: 'Router',
|
||||
description: 'Route workflow',
|
||||
category: 'blocks',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { SearchResponse } from '@/tools/serper/search'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const SerperBlock: BlockConfig<SearchResponse> = {
|
||||
id: 'serper',
|
||||
type: 'serper',
|
||||
name: 'Serper',
|
||||
description: 'Search the web using Serper',
|
||||
category: 'tools',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { SlackMessageResponse } from '@/tools/slack/message'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const SlackBlock: BlockConfig<SlackMessageResponse> = {
|
||||
id: 'slack',
|
||||
type: 'slack',
|
||||
name: 'Slack',
|
||||
description: 'Send a message to Slack',
|
||||
category: 'tools',
|
||||
|
||||
@@ -2,7 +2,7 @@ import { StartIcon } from '@/components/icons'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const StarterBlock: BlockConfig = {
|
||||
id: 'starter',
|
||||
type: 'starter',
|
||||
name: 'Starter',
|
||||
description: 'Start workflow',
|
||||
category: 'blocks',
|
||||
|
||||
@@ -5,7 +5,7 @@ import { BlockConfig } from '../types'
|
||||
type TavilyResponse = TavilySearchResponse | TavilyExtractResponse
|
||||
|
||||
export const TavilyBlock: BlockConfig<TavilyResponse> = {
|
||||
id: 'tavily',
|
||||
type: 'tavily',
|
||||
name: 'Tavily',
|
||||
description: 'Search and extract information using Tavily AI',
|
||||
category: 'tools',
|
||||
|
||||
@@ -15,7 +15,7 @@ const getTranslationPrompt = (
|
||||
Only return the translated text without any explanations or notes. The translation should be natural and fluent in ${targetLanguage || 'English'}.`
|
||||
|
||||
export const TranslateBlock: BlockConfig<ChatResponse> = {
|
||||
id: 'translate',
|
||||
type: 'translate',
|
||||
name: 'Translate',
|
||||
description: 'Translate text to any language',
|
||||
category: 'tools',
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import { BlockConfig } from '../types'
|
||||
type XResponse = XWriteResponse | XReadResponse | XSearchResponse | XUserResponse
|
||||
|
||||
export const XBlock: BlockConfig<XResponse> = {
|
||||
id: 'x',
|
||||
type: 'x',
|
||||
name: 'X',
|
||||
description: 'Interact with X',
|
||||
category: 'tools',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { YouTubeSearchResponse } from '@/tools/youtube/search'
|
||||
import { BlockConfig } from '../types'
|
||||
|
||||
export const YouTubeBlock: BlockConfig<YouTubeSearchResponse> = {
|
||||
id: 'youtube',
|
||||
type: 'youtube',
|
||||
name: 'YouTube',
|
||||
description: 'Search for videos on YouTube',
|
||||
category: 'tools',
|
||||
|
||||
+3
-3
@@ -67,13 +67,13 @@ const blocks: Record<string, BlockConfig> = {
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
export const getBlock = (id: string): BlockConfig | undefined => blocks[id]
|
||||
export const getBlock = (type: string): BlockConfig | undefined => blocks[type]
|
||||
|
||||
export const getBlocksByCategory = (category: 'blocks' | 'tools'): BlockConfig[] =>
|
||||
Object.values(blocks).filter((block) => block.category === category)
|
||||
|
||||
export const getAllBlockIds = (): string[] => Object.keys(blocks)
|
||||
export const getAllBlockTypes = (): string[] => Object.keys(blocks)
|
||||
|
||||
export const isValidBlockId = (id: string): id is string => id in blocks
|
||||
export const isValidBlockType = (type: string): type is string => type in blocks
|
||||
|
||||
export const getAllBlocks = (): BlockConfig[] => Object.values(blocks)
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ export interface SubBlockConfig {
|
||||
|
||||
// Main block definition
|
||||
export interface BlockConfig<T extends ToolResponse = ToolResponse> {
|
||||
id: string
|
||||
type: string
|
||||
name: string
|
||||
description: string
|
||||
category: BlockCategory
|
||||
|
||||
+1
-1
@@ -486,7 +486,7 @@ export class Executor {
|
||||
const formattedTools = Array.isArray(inputs.tools)
|
||||
? inputs.tools
|
||||
.map((tool: any) => {
|
||||
const blockFound = getAllBlocks().find((b: BlockConfig) => b.id === tool.type)
|
||||
const blockFound = getAllBlocks().find((b: BlockConfig) => b.type === tool.type)
|
||||
const toolId = blockFound?.tools.access[0]
|
||||
if (!toolId) return null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user