Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

3.0 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import { agentToolPhases } from '../../src/lib/ee/agent/tool-phases'

const ALL = [
    'ap_research_pieces',
    'ap_get_piece_props',
    'ap_resolve_property_options',
    'ap_list_connections',
    'ap_explore_data',
    'ap_validate_flow',
    'ap_show_questions',
    'ap_build_flow',
    'ap_run_task',
    'ap_add_step',
    'ap_test_flow',
    'ap_lock_and_publish',
    'ap_execute_action',
]

describe('agentToolPhases.activeToolsForPhase', () => {
    it('hides build/edit/execute tools during discovery', () => {
        const active = agentToolPhases.activeToolsForPhase({ phase: 'discovery', allToolNames: ALL })
        expect(active).toContain('ap_research_pieces')
        expect(active).toContain('ap_explore_data')
        expect(active).toContain('ap_show_questions')
        expect(active).not.toContain('ap_build_flow')
        expect(active).not.toContain('ap_add_step')
        expect(active).not.toContain('ap_test_flow')
        expect(active).not.toContain('ap_lock_and_publish')
        expect(active).not.toContain('ap_execute_action')
    })

    it('exposes the full toolset during build', () => {
        const active = agentToolPhases.activeToolsForPhase({ phase: 'build', allToolNames: ALL })
        expect(active).toEqual(ALL)
    })

    it('keeps read/discovery tools available in both phases', () => {
        const discovery = agentToolPhases.activeToolsForPhase({ phase: 'discovery', allToolNames: ALL })
        const build = agentToolPhases.activeToolsForPhase({ phase: 'build', allToolNames: ALL })
        for (const tool of ['ap_research_pieces', 'ap_get_piece_props', 'ap_list_connections', 'ap_explore_data', 'ap_validate_flow', 'ap_run_task']) {
            expect(discovery).toContain(tool)
            expect(build).toContain(tool)
        }
    })

    it('leaves the agent tools reachable in discovery, since nothing else flips the phase for them', () => {
        const names = ['ap_list_agents', 'ap_create_agent', 'ap_update_agent', 'ap_add_agent_tool', 'ap_remove_agent_tool']
        const active = agentToolPhases.activeToolsForPhase({ phase: 'discovery', allToolNames: names })
        expect(active).toEqual(names)
    })

    it('leaves unknown tools visible during discovery (denylist, not allowlist)', () => {
        const active = agentToolPhases.activeToolsForPhase({ phase: 'discovery', allToolNames: ['ap_some_new_tool'] })
        expect(active).toContain('ap_some_new_tool')
    })
})

describe('agentToolPhases hidden/build classification', () => {
    it('flags chat-hidden tools', () => {
        expect(agentToolPhases.isAgentHiddenTool('ap_run_action')).toBe(true)
        expect(agentToolPhases.isAgentHiddenTool('ap_create_flow')).toBe(true)
        expect(agentToolPhases.isAgentHiddenTool('ap_execute_action')).toBe(false)
    })

    it('flags build-only tools', () => {
        expect(agentToolPhases.isBuildOnlyTool('ap_build_flow')).toBe(true)
        expect(agentToolPhases.isBuildOnlyTool('ap_research_pieces')).toBe(false)
    })
})