MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / createMessage

Function createMessage

src/api/providers/base-openai-compatible-provider.ts:113–193  ·  view source on GitHub ↗
(
		systemPrompt: string,
		messages: Anthropic.Messages.MessageParam[],
		metadata?: ApiHandlerCreateMessageMetadata,
	)

Source from the content-addressed store, hash-verified

111 }
112
113 override async *createMessage(
114 systemPrompt: string,
115 messages: Anthropic.Messages.MessageParam[],
116 metadata?: ApiHandlerCreateMessageMetadata,
117 ): ApiStream {
118 const stream = await this.createStream(systemPrompt, messages, metadata)
119
120 const matcher = new TagMatcher(
121 ["think", "thought"],
122 (chunk) =>
123 ({
124 type: chunk.matched ? "reasoning" : "text",
125 text: chunk.data,
126 }) as const,
127 )
128
129 let lastUsage: OpenAI.CompletionUsage | undefined
130 const activeToolCallIds = new Set<string>()
131
132 for await (const chunk of stream) {
133 // Check for provider-specific error responses (e.g., MiniMax base_resp)
134 const chunkAny = chunk as any
135 if (chunkAny.base_resp?.status_code && chunkAny.base_resp.status_code !== 0) {
136 throw new Error(
137 `${this.providerName} API Error (${chunkAny.base_resp.status_code}): ${chunkAny.base_resp.status_msg || "Unknown error"}`,
138 )
139 }
140
141 const delta = chunk.choices?.[0]?.delta
142 const finishReason = chunk.choices?.[0]?.finish_reason
143
144 if (delta?.content) {
145 for (const processedChunk of matcher.update(delta.content)) {
146 yield processedChunk
147 }
148 }
149
150 const reasoningText = extractReasoningFromDelta(delta)
151 if (reasoningText) {
152 yield { type: "reasoning", text: reasoningText }
153 }
154
155 // Emit raw tool call chunks - NativeToolCallParser handles state management
156 if (delta?.tool_calls) {
157 for (const toolCall of delta.tool_calls) {
158 if (toolCall.id) {
159 activeToolCallIds.add(toolCall.id)
160 }
161 yield {
162 type: "tool_call_partial",
163 index: toolCall.index,
164 id: toolCall.id,
165 name: toolCall.function?.name,
166 arguments: toolCall.function?.arguments,
167 }
168 }
169 }
170

Callers

nothing calls this directly

Calls 7

updateMethod · 0.95
finalMethod · 0.95
createStreamMethod · 0.80
clearMethod · 0.65
getModelMethod · 0.65
processUsageMetricsMethod · 0.45

Tested by

no test coverage detected