Skip to content

refactoring: refactor the server side tool definitions #6827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 23, 2025

Conversation

dancer
Copy link
Collaborator

@dancer dancer commented Jun 22, 2025

background

refactor server-side tool definition - some used function-based exports while others used the createProviderDefinedToolFactory pattern established by computer_20250124.ts.

summary

  • refactor openai and anthropic server-side tools to use createProviderDefinedToolFactory pattern

verification

  • all tests pass (185/185 openai, 82/82 anthropic)
  • builds complete successfully for both packages
  • anthropic web search working in production examples

tasks

  • refactor packages/openai/src/tool/web-search-preview.ts to factory pattern
  • refactor packages/openai/src/tool/file-search.ts to factory pattern
  • refactor packages/anthropic/src/tool/web-search_20250305.ts to factory pattern
  • update prepare tools functions to remove redundant type assertions
  • move example files to generate-text directory

future work

  • consider extracting common patterns for provider-defined tool implementations

@dancer dancer changed the title chore: refactor the server side tool definitions refactoring: refactor the server side tool definitions Jun 22, 2025
@@ -21,7 +21,7 @@ export async function POST(req: Request) {
const result = streamText({
model: anthropic('claude-3-5-sonnet-latest'),
tools: {
web_search: anthropic.tools.webSearch_20250305(),
web_search: anthropic.tools.webSearch_20250305({}),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if we can provide a default? might be tricky

@@ -7,7 +7,7 @@ async function main() {
model: openai.responses('gpt-4o-mini'),
prompt: 'What happened in San Francisco last week?',
tools: {
web_search_preview: openai.tools.webSearchPreview(),
web_search_preview: openai.tools.webSearchPreview({}),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm

@lgrammel
Copy link
Collaborator

needs a changeset since it updates the api for tool use slightly

@dancer dancer merged commit 5d959e7 into v5 Jun 23, 2025
8 checks passed
@dancer dancer deleted the js/server-side-refactor branch June 23, 2025 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants