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

Method sendMessages

app/src/utils/ModelManager.ts:731–764  ·  view source on GitHub ↗

* Send messages to a model by name. Routes local models directly, remote models via fetchResponse.

(
    modelName: string,
    messages: Array<{ role: string; content: any }>,
    token?: string,
    enableStreaming: boolean = false,
    onStreamChunk?: (chunk: string) => void,
    onReasoningChunk?: (chunk: string) => void
  )

Source from the content-addressed store, hash-verified

729 * Send messages to a model by name. Routes local models directly, remote models via fetchResponse.
730 */
731 public async sendMessages(
732 modelName: string,
733 messages: Array<{ role: string; content: any }>,
734 token?: string,
735 enableStreaming: boolean = false,
736 onStreamChunk?: (chunk: string) => void,
737 onReasoningChunk?: (chunk: string) => void
738 ): Promise<string> {
739 let modelsResponse = this.listModels();
740 let model = modelsResponse.models.find(m => m.name === modelName);
741 if (!model) {
742 modelsResponse = await this.fetchModels();
743 model = modelsResponse.models.find(m => m.name === modelName);
744 }
745 // Ghost models (agent-creator-only) aren't returned by listModels but are valid on the
746 // Observer API — route them there when a token is present.
747 if (!model && !token) throw new Error(`Model '${modelName}' not found in available models`);
748
749 const serverAddress = model ? model.server : 'https://api.observer-ai.com:443';
750
751 if (this.isLocalModel(serverAddress)) {
752 if (!this.isLocalModelReady(serverAddress)) {
753 throw new Error('Local model not loaded. Please load it from the Add Model panel.');
754 }
755 return this.generateWithLocalModel(serverAddress, messages, onStreamChunk, onReasoningChunk);
756 }
757
758 if (serverAddress.includes('api.observer-ai.com') && token) {
759 this.optimisticUpdateQuota();
760 }
761 const { fetchResponse } = await import('./sendApi');
762 const params = { ...DEFAULT_INFERENCE_PARAMS, ...this.getModelParams(modelName) };
763 return fetchResponse(serverAddress, messages, modelName, token, enableStreaming, onStreamChunk, params, onReasoningChunk);
764 }
765
766 /**
767 * Tools-aware send path. Returns the full AssistantResponse (content + tool_calls +

Callers 4

handleSubmitFunction · 0.80
sendConversationFunction · 0.80
testImageFunction · 0.80
improvePromptFunction · 0.80

Calls 8

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

Tested by

no test coverage detected