refactor tools #731
Conversation
|
commit: |
Claude Code ReviewSummary: Clean refactoring that simplifies the human-in-the-loop API. The new Issues FoundCritical:
Moderate:
Minor:
Positive Changes
RecommendationFix issues #1-2 before merging (type safety + validation). Consider addressing #3 if backward compatibility matters. |
Syncs documentation changes from cloudflare/agents PR #731: - Add comprehensive useChat API reference documentation - Update human-in-the-loop guide to use new useChat hook - Replace two-hook pattern (useAgent + useAgentChat) with single useChat hook - Update tool configuration to use declarative confirm property - Simplify approval flow with approve() and deny() methods This is a breaking change that improves developer experience with: - Simpler single-hook API - Declarative tool configuration with execute and confirm properties - Cleaner approval flow without magic strings - Better TypeScript types with PendingConfirmation Related PR: cloudflare/agents#731 Generated with Claude Code https://claude.com/claude-code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add useChat hook that wraps useAgent + useAgentChat with simpler API - Support declarative tool configuration with confirm: true/false - Add approve()/deny() functions instead of addToolResult() with magic strings - Export pendingToolCalls array for easy UI rendering - Export TOOL_CONFIRMATION constants for protocol values - Update human-in-the-loop example to use new hook
1bc3ddf to
73dbfdc
Compare
- Single source of truth for tool definitions (tools.ts) - Shared TOOL_CONFIRMATION constants between client/server - Derive toolsRequiringConfirmation from tool config (not hardcoded) - Add isLoading state to UseChatHelpers - Improved documentation with execution model table - Server.ts refactored with extracted metadata helper
- Move TOOL_CONFIRMATION constants to ai-types.ts (shared client/server) - Export from main index.ts for server-side use - Re-export from use-chat.tsx for client convenience - use-chat.tsx now imports from ai-types.ts (single source of truth) - Update example to document protocol requirement
Updates documentation to reflect the breaking changes in PR #731: - Replace useAgent + useAgentChat two-hook pattern with unified useChat hook - Update human-in-the-loop guide with new declarative tool configuration - Document new approve(id)/deny(id) API replacing addToolResult() - Add TOOL_CONFIRMATION protocol constants documentation - Update tool configuration to use confirm property instead of manual lists - Simplify examples to show new streamlined API This is a breaking change that affects how users implement human-in-the-loop workflows with the Agents SDK. Related PR: cloudflare/agents#731
disclaimer: this is breaking change, but man i think we need to clean this
Replaces the two-hook pattern (useAgent + useAgentChat) with a single useChat hook that provides: