chore(cleanup): remove tool-calling plumbing, no skills remain
Remove the general-purpose tool/function-calling machinery from openrouter.ts (loadSkills usage, buildTools, executeTool, tool_calls request/response handling) and the recovery helpers it existed to patch (extractFakeToolCall/extractBareJsonRetry in toolCallRecovery.ts), since every skill that plumbing could call has now been deleted. Delete src/main/skills/ entirely (types.ts, argUtils.ts, index.ts), now empty. Strip the system prompt paragraphs describing tool usage. getAssistantReply() keeps the core chat loop: send the user's message to OpenRouter with DeepSeek/Qwen fallback, the malformed-response guard, degenerate-text detection and requireLoggedIn(), and return the assistant's plain-text reply. Drop the now-stale coverage exclude for the already-removed memory/store.ts. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
acdd8a08d3
commit
d0c730fa6f
@@ -3,26 +3,6 @@ import { setCurrentUserEmail, clearSession } from '../../src/main/auth/session'
|
||||
|
||||
vi.mock('@electron-toolkit/utils', () => ({ is: { dev: false } }))
|
||||
|
||||
interface FakeSkill {
|
||||
name: string
|
||||
description: string
|
||||
parameters: object
|
||||
execute: (args: Record<string, unknown>) => Promise<string>
|
||||
}
|
||||
|
||||
let currentSkills: FakeSkill[] = []
|
||||
const loadSkills = vi.fn(() => currentSkills)
|
||||
vi.mock('../../src/main/skills', () => ({ loadSkills }))
|
||||
|
||||
const getMood = vi.fn(() => 0)
|
||||
vi.mock('../../src/main/memory/store', () => ({ getMood }))
|
||||
|
||||
const synthesizeSpeech = vi.fn(async () => Buffer.from([1, 2, 3]))
|
||||
vi.mock('../../src/main/ai/elevenlabs', () => ({ synthesizeSpeech }))
|
||||
|
||||
const sendToRenderer = vi.fn()
|
||||
vi.mock('../../src/main/windowBridge', () => ({ sendToRenderer }))
|
||||
|
||||
const { getAssistantReply } = await import('../../src/main/ai/openrouter')
|
||||
|
||||
function okResponse(body: unknown): Response {
|
||||
@@ -33,27 +13,10 @@ function textMessage(content: string): unknown {
|
||||
return { choices: [{ message: { role: 'assistant', content } }] }
|
||||
}
|
||||
|
||||
function toolCallMessage(name: string, args: Record<string, unknown>, content = ''): unknown {
|
||||
return {
|
||||
choices: [
|
||||
{
|
||||
message: {
|
||||
role: 'assistant',
|
||||
content,
|
||||
tool_calls: [
|
||||
{ id: 'call-1', type: 'function', function: { name, arguments: JSON.stringify(args) } }
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
describe('getAssistantReply()', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
vi.stubGlobal('fetch', vi.fn())
|
||||
currentSkills = []
|
||||
process.env.OPENROUTER_API_KEY = 'test-key'
|
||||
setCurrentUserEmail('test@example.com')
|
||||
})
|
||||
@@ -67,51 +30,12 @@ describe('getAssistantReply()', () => {
|
||||
await expect(getAssistantReply('Bonjour')).rejects.toThrow(/OPENROUTER_API_KEY/)
|
||||
})
|
||||
|
||||
it('should return a direct text reply when the model calls no tool', async () => {
|
||||
it('should return the assistant text reply when the API responds successfully', async () => {
|
||||
vi.mocked(fetch).mockResolvedValue(okResponse(textMessage('Bonjour, comment puis-je aider ?')))
|
||||
const reply = await getAssistantReply('Salut Max')
|
||||
expect(reply).toBe('Bonjour, comment puis-je aider ?')
|
||||
})
|
||||
|
||||
it('should execute a requested tool and use its result for the follow-up reply', async () => {
|
||||
const execute = vi.fn(async () => 'Notepad ouvert.')
|
||||
currentSkills = [
|
||||
{ name: 'open_notepad', description: 'ouvre notepad', parameters: {}, execute }
|
||||
]
|
||||
vi.mocked(fetch)
|
||||
.mockResolvedValueOnce(okResponse(toolCallMessage('open_notepad', {})))
|
||||
.mockResolvedValueOnce(okResponse(textMessage("C'est fait, le bloc-notes est ouvert.")))
|
||||
|
||||
const reply = await getAssistantReply('ouvre le bloc-notes')
|
||||
expect(execute).toHaveBeenCalled()
|
||||
expect(reply).toBe("C'est fait, le bloc-notes est ouvert.")
|
||||
})
|
||||
|
||||
it('should report an unknown/unauthorized tool without crashing', async () => {
|
||||
currentSkills = []
|
||||
vi.mocked(fetch)
|
||||
.mockResolvedValueOnce(okResponse(toolCallMessage('outil_interdit', {})))
|
||||
.mockResolvedValueOnce(okResponse(textMessage('Compris.')))
|
||||
|
||||
const reply = await getAssistantReply('fais un truc interdit')
|
||||
expect(reply).toBe('Compris.')
|
||||
})
|
||||
|
||||
it('should report a tool execution failure without crashing the turn', async () => {
|
||||
const execute = vi.fn(async () => {
|
||||
throw new Error('disque plein')
|
||||
})
|
||||
currentSkills = [
|
||||
{ name: 'create_file', description: 'cree un fichier', parameters: {}, execute }
|
||||
]
|
||||
vi.mocked(fetch)
|
||||
.mockResolvedValueOnce(okResponse(toolCallMessage('create_file', { name: 'test' })))
|
||||
.mockResolvedValueOnce(okResponse(textMessage('Echec note.')))
|
||||
|
||||
const reply = await getAssistantReply('cree un fichier')
|
||||
expect(reply).toBe('Echec note.')
|
||||
})
|
||||
|
||||
it('should transparently fall back to the secondary model when the primary one errors out', async () => {
|
||||
vi.mocked(fetch)
|
||||
.mockResolvedValueOnce({
|
||||
@@ -144,20 +68,6 @@ describe('getAssistantReply()', () => {
|
||||
await expect(getAssistantReply('question')).rejects.toThrow(/Aucun modele disponible/)
|
||||
})
|
||||
|
||||
it('should recover a fake tool call written as plain text instead of real tool_calls', async () => {
|
||||
const execute = vi.fn(async () => 'Notepad ouvert.')
|
||||
currentSkills = [
|
||||
{ name: 'open_notepad', description: 'ouvre notepad', parameters: {}, execute }
|
||||
]
|
||||
vi.mocked(fetch)
|
||||
.mockResolvedValueOnce(okResponse(textMessage('open_notepad\n{"text": "bonjour"}')))
|
||||
.mockResolvedValueOnce(okResponse(textMessage('Fait.')))
|
||||
|
||||
const reply = await getAssistantReply('ouvre le bloc-notes')
|
||||
expect(execute).toHaveBeenCalled()
|
||||
expect(reply).toBe('Fait.')
|
||||
})
|
||||
|
||||
it('should replace a leaked English boilerplate reply with the safe fallback message', async () => {
|
||||
vi.mocked(fetch).mockResolvedValue(
|
||||
okResponse(
|
||||
@@ -177,12 +87,4 @@ describe('getAssistantReply()', () => {
|
||||
const reply = await getAssistantReply('question')
|
||||
expect(reply).toMatch(/bien avance avec toi/)
|
||||
})
|
||||
|
||||
it('should throw once the tool-call round limit is exceeded', async () => {
|
||||
const execute = vi.fn(async () => 'ok')
|
||||
currentSkills = [{ name: 'loop_tool', description: 'boucle', parameters: {}, execute }]
|
||||
vi.mocked(fetch).mockImplementation(async () => okResponse(toolCallMessage('loop_tool', {})))
|
||||
|
||||
await expect(getAssistantReply('boucle indefiniment')).rejects.toThrow(/Trop d'appels d'outils/)
|
||||
}, 20000)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user