b00706325b
- Task 0: SOUL.md + loadSystemPrompt() in daemon - Task 1: Tool type definitions (Tool, ToolCall, ToolResult, etc.) - Task 2: ToolRegistry with Anthropic/OpenAI serialization - Task 3: ToolExecutor with hooks, timeout, truncation - Task 4: shell.exec builtin tool - Task 8: Model types updated for tool use (ToolDefinition, ModelToolCall, etc.) - Task 15: Model index exports for tool types
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import type { Tool, ToolCall, ToolResult, ToolUseMessage, ToolResultMessage } from './types.js';
|
|
|
|
describe('Tool types', () => {
|
|
it('Tool interface is structurally correct', () => {
|
|
const tool: Tool = {
|
|
name: 'test.echo',
|
|
description: 'Echoes input',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: { text: { type: 'string' } },
|
|
required: ['text'],
|
|
},
|
|
execute: async (args) => ({ success: true, output: String((args as { text: string }).text) }),
|
|
};
|
|
|
|
expect(tool.name).toBe('test.echo');
|
|
expect(tool.inputSchema.type).toBe('object');
|
|
});
|
|
|
|
it('ToolCall has required fields', () => {
|
|
const call: ToolCall = { id: 'call_1', name: 'test.echo', args: { text: 'hi' } };
|
|
expect(call.id).toBe('call_1');
|
|
expect(call.name).toBe('test.echo');
|
|
});
|
|
|
|
it('ToolResult has success and output', () => {
|
|
const result: ToolResult = { success: true, output: 'hello' };
|
|
expect(result.success).toBe(true);
|
|
|
|
const errResult: ToolResult = { success: false, output: '', error: 'boom' };
|
|
expect(errResult.error).toBe('boom');
|
|
});
|
|
|
|
it('ToolUseMessage has correct shape', () => {
|
|
const msg: ToolUseMessage = {
|
|
role: 'assistant',
|
|
content: [{ type: 'tool_use', id: 'call_1', name: 'test.echo', input: { text: 'hi' } }],
|
|
};
|
|
expect(msg.role).toBe('assistant');
|
|
expect(msg.content[0].type).toBe('tool_use');
|
|
});
|
|
|
|
it('ToolResultMessage has correct shape', () => {
|
|
const msg: ToolResultMessage = {
|
|
role: 'user',
|
|
content: [{ type: 'tool_result', tool_use_id: 'call_1', content: 'output here' }],
|
|
};
|
|
expect(msg.role).toBe('user');
|
|
expect(msg.content[0].type).toBe('tool_result');
|
|
});
|
|
});
|