UseChatBackend defines the interface for AI chat backend providers (OpenAI, Anthropic, etc.) This interface abstracts the provider-specific API calls needed by the usechat system.
| 18 | // UseChatBackend defines the interface for AI chat backend providers (OpenAI, Anthropic, etc.) |
| 19 | // This interface abstracts the provider-specific API calls needed by the usechat system. |
| 20 | type UseChatBackend interface { |
| 21 | // RunChatStep executes a single step in the chat conversation with the AI backend. |
| 22 | // Returns the stop reason, native messages from the response, rate limit info, and any error. |
| 23 | // The cont parameter allows continuing from a previous response (e.g., after rate limiting). |
| 24 | RunChatStep( |
| 25 | ctx context.Context, |
| 26 | sseHandler *sse.SSEHandlerCh, |
| 27 | chatOpts uctypes.WaveChatOpts, |
| 28 | cont *uctypes.WaveContinueResponse, |
| 29 | ) (*uctypes.WaveStopReason, []uctypes.GenAIMessage, *uctypes.RateLimitInfo, error) |
| 30 | |
| 31 | // UpdateToolUseData updates the tool use data for a specific tool call in the chat. |
| 32 | // This is used to update the UI state for tool execution (approval status, results, etc.) |
| 33 | UpdateToolUseData(chatId string, toolCallId string, toolUseData uctypes.UIMessageDataToolUse) error |
| 34 | |
| 35 | // RemoveToolUseCall removes a tool use call from the chat's native messages. |
| 36 | // This is used to clean up incomplete or canceled tool calls when stopping execution. |
| 37 | RemoveToolUseCall(chatId string, toolCallId string) error |
| 38 | |
| 39 | // ConvertToolResultsToNativeChatMessage converts tool execution results into native chat messages |
| 40 | // that can be sent back to the AI backend. Returns a slice of messages (some backends may |
| 41 | // require multiple messages per tool result). |
| 42 | ConvertToolResultsToNativeChatMessage(toolResults []uctypes.AIToolResult) ([]uctypes.GenAIMessage, error) |
| 43 | |
| 44 | // ConvertAIMessageToNativeChatMessage converts a generic AIMessage (from the user) |
| 45 | // into the backend's native message format for sending to the API. |
| 46 | ConvertAIMessageToNativeChatMessage(message uctypes.AIMessage) (uctypes.GenAIMessage, error) |
| 47 | |
| 48 | // GetFunctionCallInputByToolCallId retrieves the function call input data for a specific |
| 49 | // tool call ID from the chat history. Returns the function call structure |
| 50 | // or nil if not found. |
| 51 | GetFunctionCallInputByToolCallId(aiChat uctypes.AIChat, toolCallId string) *uctypes.AIFunctionCallInput |
| 52 | |
| 53 | // ConvertAIChatToUIChat converts a stored AIChat (with native backend messages) into |
| 54 | // a UI-friendly UIChat format that can be displayed in the frontend. |
| 55 | ConvertAIChatToUIChat(aiChat uctypes.AIChat) (*uctypes.UIChat, error) |
| 56 | } |
| 57 | |
| 58 | // Compile-time interface checks |
| 59 | var _ UseChatBackend = (*openaiResponsesBackend)(nil) |
no outgoing calls
no test coverage detected