MCPcopy Create free account
hub / github.com/Roy3838/Observer / sendToolMessages

Method sendToolMessages

app/src/utils/ModelManager.ts:774–803  ·  view source on GitHub ↗

* 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
  )

Source from the content-addressed store, hash-verified

772 * models aren't returned by listModels but are valid on the Observer API).
773 */
774 public async sendToolMessages(
775 modelName: string,
776 messages: Array<{ role: string; content: any }>,
777 tools: WireToolSpec[],
778 token?: string,
779 enableStreaming: boolean = false,
780 onStreamChunk?: (chunk: string) => void,
781 onReasoningChunk?: (chunk: string) => void
782 ): Promise<AssistantResponse> {
783 let modelsResponse = this.listModels();
784 let model = modelsResponse.models.find(m => m.name === modelName);
785 if (!model) {
786 modelsResponse = await this.fetchModels();
787 model = modelsResponse.models.find(m => m.name === modelName);
788 }
789 if (!model && !token) throw new Error(`Model '${modelName}' not found in available models`);
790
791 const serverAddress = model ? model.server : 'https://api.observer-ai.com:443';
792
793 if (this.isLocalModel(serverAddress)) {
794 throw new Error('Tool calling is only available with cloud models. Please use Ob-Server or a remote inference server.');
795 }
796
797 if (serverAddress.includes('api.observer-ai.com') && token) {
798 this.optimisticUpdateQuota();
799 }
800 const { fetchResponse } = await import('./sendApi');
801 const params = { ...DEFAULT_INFERENCE_PARAMS, ...this.getModelParams(modelName) };
802 return fetchResponse(serverAddress, messages, modelName, token, enableStreaming, onStreamChunk, params, onReasoningChunk, tools);
803 }
804
805 private optimisticUpdateQuota(): void {
806 try {

Callers 1

sendToModelFunction · 0.80

Calls 6

listModelsMethod · 0.95
fetchModelsMethod · 0.95
isLocalModelMethod · 0.95
optimisticUpdateQuotaMethod · 0.95
getModelParamsMethod · 0.95
fetchResponseFunction · 0.85

Tested by

no test coverage detected