* Tools-aware send path. Returns the full AssistantResponse (content + tool_calls + * finish_reason) so callers can drive native OpenAI function calling. * * Native function calling requires a capable remote model — local 2B watcher models * are not supported here. Mirrors sendMessages'
(
modelName: string,
messages: Array<{ role: string; content: any }>,
tools: WireToolSpec[],
token?: string,
enableStreaming: boolean = false,
onStreamChunk?: (chunk: string) => void,
onReasoningChunk?: (chunk: string) => void
)
| 832 | * models aren't returned by listModels but are valid on the Observer API). |
| 833 | */ |
| 834 | public async sendToolMessages( |
| 835 | modelName: string, |
| 836 | messages: Array<{ role: string; content: any }>, |
| 837 | tools: WireToolSpec[], |
| 838 | token?: string, |
| 839 | enableStreaming: boolean = false, |
| 840 | onStreamChunk?: (chunk: string) => void, |
| 841 | onReasoningChunk?: (chunk: string) => void |
| 842 | ): Promise<AssistantResponse> { |
| 843 | let modelsResponse = this.listModels(); |
| 844 | let model = modelsResponse.models.find(m => m.name === modelName); |
| 845 | if (!model) { |
| 846 | modelsResponse = await this.fetchModels(); |
| 847 | model = modelsResponse.models.find(m => m.name === modelName); |
| 848 | } |
| 849 | if (!model && !token) throw new Error(`Model '${modelName}' not found in available models`); |
| 850 | |
| 851 | const serverAddress = model ? model.server : 'https://api.observer-ai.com:443'; |
| 852 | |
| 853 | if (this.isLocalModel(serverAddress)) { |
| 854 | throw new Error('Tool calling is only available with cloud models. Please use Ob-Server or a remote inference server.'); |
| 855 | } |
| 856 | |
| 857 | if (serverAddress.includes('api.observer-ai.com') && token) { |
| 858 | this.optimisticUpdateQuota(); |
| 859 | } |
| 860 | const { fetchResponse } = await import('./sendApi'); |
| 861 | const params = { ...DEFAULT_INFERENCE_PARAMS, ...this.getModelParams(modelName) }; |
| 862 | return fetchResponse(serverAddress, messages, modelName, token, enableStreaming, onStreamChunk, params, onReasoningChunk, tools); |
| 863 | } |
| 864 | |
| 865 | private optimisticUpdateQuota(credits: number = 4): void { |
| 866 | try { |
no test coverage detected