Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

server-tools.test.ts

94 lines2.5 KB

1import { describe, expect, it } from 'vitest'
2​
3import { grokServerTools } from './grok.ts'
4import { openrouterServerTools } from './openrouter.ts'
5import {
6 parseByteplusServerTools,
7 parseGroqBuiltinTools,
8 parseMistralPageTools,
9} from './server-tools.ts'
10​
11const GROQ_TOOLS = `# Groq Built-In Tools
12​
13### GPT-OSS Models
14​
15**Models:**
16​
17* \`openai/gpt-oss-120b\`
18* \`openai/gpt-oss-20b\`
19​
20**Available Tools:**
21​
22| Tool | Identifier |
23| --- | --- |
24| Browser Search | browser\\_search |
25| Code Execution | code\\_interpreter |
26​
27### Something else
28​
29Llama stays on the models page and is not listed here.
31​
32const MISTRAL_TOOLS = `<html><body>
33<h2>Supported tools</h2>
34<p>This model accepts <code>web_search</code> and <code>code_interpreter</code>.</p>
35<p>Client <code>function</code> tools are not hosted.</p>
36</body></html>`
37​
38const BYTEPLUS_TOOLS = `# Image generation API
39​
40## Seedream 4.5
41​
42Model ID: \`seedream-4-5-251128\`
43​
44tools: [{"type": "web_search"}]
45​
46## Seedream 5.0 pro
47​
48Model ID: \`seedream-5-0-pro-260115\`
49​
50Sequential image generation, web search, and streaming output are not currently supported.
52​
53describe('server tools from docs (issue #123)', () => {
54 it('reads Groq tool type ids only for models the built-in tools page names', () => {
55 const tools = parseGroqBuiltinTools(GROQ_TOOLS)
56 expect(tools.get('openai/gpt-oss-120b')).toEqual([
57 'browser_search',
58 'code_interpreter',
59 ])
60 expect(tools.get('openai/gpt-oss-20b')).toEqual([
61 'browser_search',
62 'code_interpreter',
63 ])
64 expect(tools.has('llama-3.3-70b-versatile')).toBe(false)
65 })
66​
67 it('reads Mistral tool type ids from a model page and ignores a page that names none', () => {
68 expect(parseMistralPageTools(MISTRAL_TOOLS)).toEqual([
69 'web_search',
70 'code_interpreter',
71 ])
72 expect(
73 parseMistralPageTools(
74 '<html><p>No tool section.</p><script>"web_search"</script></html>',
75 ),
76 ).toEqual([])
77 })
78​
79 it('reads a BytePlus tool type only next to the model the section names', () => {
80 const tools = parseByteplusServerTools(BYTEPLUS_TOOLS)
81 expect(tools.get('seedream-4-5-251128')).toEqual(['web_search'])
82 expect(tools.has('seedream-5-0-pro-260115')).toBe(false)
83 })
84​
85 it('leaves Grok and OpenRouter null', () => {
86 const page = `# Grok\n\n## Capabilities\n\n- **Web search:** Yes\n- **tools:** web_search\n`
87 expect(grokServerTools(page)).toBeNull()
88 expect(
89 openrouterServerTools({
90 supported_parameters: ['tools', 'tool_choice', 'web_search'],
91 }),
92 ).toBeNull()
93 })
94})