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 { ChatRequest, ChatResponse, ToolMessage, ContentBlock } from './types.js';
|
|
|
|
describe('Model types with tool support', () => {
|
|
it('ChatRequest accepts tools array', () => {
|
|
const req: ChatRequest = {
|
|
messages: [{ role: 'user', content: 'hi' }],
|
|
tools: [{
|
|
name: 'test',
|
|
description: 'test tool',
|
|
input_schema: { type: 'object', properties: {} },
|
|
}],
|
|
};
|
|
expect(req.tools).toHaveLength(1);
|
|
});
|
|
|
|
it('ChatResponse has optional toolCalls', () => {
|
|
const resp: ChatResponse = {
|
|
content: '',
|
|
stopReason: 'tool_use',
|
|
usage: { inputTokens: 0, outputTokens: 0 },
|
|
toolCalls: [{ id: 'call_1', name: 'test', args: {} }],
|
|
};
|
|
expect(resp.toolCalls).toHaveLength(1);
|
|
expect(resp.stopReason).toBe('tool_use');
|
|
});
|
|
|
|
it('ChatResponse works without toolCalls (backward compatible)', () => {
|
|
const resp: ChatResponse = {
|
|
content: 'hello',
|
|
stopReason: 'end_turn',
|
|
usage: { inputTokens: 10, outputTokens: 5 },
|
|
};
|
|
expect(resp.toolCalls).toBeUndefined();
|
|
});
|
|
|
|
it('ToolMessage represents tool results in conversation', () => {
|
|
const msg: ToolMessage = {
|
|
role: 'tool_result',
|
|
toolResults: [{ tool_use_id: 'call_1', content: 'result', is_error: false }],
|
|
};
|
|
expect(msg.role).toBe('tool_result');
|
|
expect(msg.toolResults).toHaveLength(1);
|
|
});
|
|
|
|
it('ContentBlock can be text or tool_use', () => {
|
|
const text: ContentBlock = { type: 'text', text: 'hello' };
|
|
const tool: ContentBlock = { type: 'tool_use', id: 'c1', name: 'test', input: {} };
|
|
expect(text.type).toBe('text');
|
|
expect(tool.type).toBe('tool_use');
|
|
});
|
|
});
|