feat(ai-proxy): add HTTP client for frontend and agent-client usage#1436
Open
feat(ai-proxy): add HTTP client for frontend and agent-client usage#1436
Conversation
2 new issues
|
657874e to
87fbd66
Compare
|
Coverage Impact This PR will not change total coverage. 🚦 See full report on Qlty Cloud »🛟 Help
|
c3a1199 to
544d9ee
Compare
Add AiProxyClient class with a clean, UX-friendly API: - chat(input): accepts a simple string or ChatInput object - getTools(): list available remote tools - callTool(name, inputs): execute a specific tool API improvements: - Simplified chat() that accepts just a string for common use cases - Consistent camelCase naming (toolChoice, aiName) - Renamed apiKey (more generic than openAiApiKey) - Clear method names: chat(), getTools(), callTool() Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
544d9ee to
ba3bcac
Compare
Create a single source of truth for API types by introducing routes.ts. This file defines types for all routes (ai-query, invoke-remote-tool, remote-tools) and is imported by both server and client code. - Add src/routes.ts with shared OpenAI and route types - Update router.ts to use AiQueryRequest and InvokeToolRequest - Update provider-dispatcher.ts to import from routes.ts - Update remote-tools.ts to use RemoteToolDefinition - Update client/types.ts to re-export from routes.ts - Maintain backwards compatibility with legacy type aliases Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The dependency is only used for type imports (Logger type), so it doesn't need to be installed by consumers at runtime. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove legacy type exports (DispatchBody, ChatCompletionResponse, etc.) since there are no external consumers yet. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add Object.setPrototypeOf for proper Error subclass behavior - Add cause property to preserve original error stack traces - Add error categorization helpers (isNetworkError, isClientError, isServerError) - Fail fast when auth required but no apiKey configured - Handle JSON parse errors on successful responses properly - Add request context (method, path) to all error messages - Add tests for edge cases: both json/text fail, non-Error exceptions, invalid JSON on success, error cause preservation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Not needed since Node 18+ is the minimum supported version. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Better reflects that this file contains type definitions, not routing logic. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Authentication is handled at a different layer. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
AiProxyClientConfig now uses a union type where fetch and baseUrl are
mutually exclusive:
- Custom fetch mode: { fetch, timeout? }
- Simple mode: { baseUrl, headers?, timeout? }
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Document mutually exclusive config modes (baseUrl vs fetch) - Remove outdated apiKey references - Add complex tool example with nested objects, arrays, and enums - Document error categorization helpers Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add Quick Start section at the top - Remove redundant API Reference and TypeScript sections - Simplify error handling documentation - Focus on time-to-first-success Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use toBeInstanceOf(AiProxyClientError) instead of toMatchObject - Add return value assertions to all tests - Add tests for default timeout (30s) - Add tests for empty aiName - Add tests for URL encoding special characters in aiName/toolName - Add tests for custom headers overriding Content-Type - Add tests for concurrent requests with independent abort signals - Replace expect.anything() with specific assertions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tonours
approved these changes
Jan 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
AiProxyClientclass with a clean, UX-friendly API to interact with ai-proxy from frontend or agent-client@forestadmin/ai-proxy/client- zero dependenciesLangchain packages are now optional peer dependencies. Users of the server-side features (Router, ProviderDispatcher) must install them manually:
Users who only use the client don't need to install anything extra.
API
Package Structure
@forestadmin/ai-proxy@forestadmin/ai-proxy/clientTest plan
🤖 Generated with Claude Code