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

Method createMessage

src/api/providers/bedrock.ts:387–799  ·  view source on GitHub ↗
(
		systemPrompt: string,
		messages: Anthropic.Messages.MessageParam[],
		metadata?: ApiHandlerCreateMessageMetadata & {
			thinking?: {
				enabled: boolean
				maxTokens?: number
				maxThinkingTokens?: number
			}
		},
	)

Source from the content-addressed store, hash-verified

385 }
386
387 override async *createMessage(
388 systemPrompt: string,
389 messages: Anthropic.Messages.MessageParam[],
390 metadata?: ApiHandlerCreateMessageMetadata & {
391 thinking?: {
392 enabled: boolean
393 maxTokens?: number
394 maxThinkingTokens?: number
395 }
396 },
397 ): ApiStream {
398 const modelConfig = this.getModel()
399 const usePromptCache = Boolean(
400 (this.options.awsUsePromptCache ?? true) && this.supportsAwsPromptCache(modelConfig),
401 )
402
403 const conversationId =
404 messages.length > 0
405 ? `conv_${messages[0].role}_${
406 typeof messages[0].content === "string"
407 ? messages[0].content.substring(0, 20)
408 : "complex_content"
409 }`
410 : "default_conversation"
411
412 const formatted = this.convertToBedrockConverseMessages(
413 messages,
414 systemPrompt,
415 usePromptCache,
416 modelConfig.info,
417 conversationId,
418 )
419
420 let additionalModelRequestFields: BedrockAdditionalModelFields | undefined
421 let thinkingEnabled = false
422
423 // Detect models that require the adaptive-thinking API contract (Opus/Sonnet
424 // 4.7 and 4.8). See isAdaptiveThinkingModel for details. The same guard is
425 // reused in completePrompt so both request paths stay consistent.
426 const baseModelId = this.parseBaseModelId(modelConfig.id)
427 const isAdaptiveThinkingModel = this.isAdaptiveThinkingModel(modelConfig.id)
428
429 // Determine if thinking should be enabled
430 // metadata?.thinking?.enabled: Explicitly enabled through API metadata (direct request)
431 // shouldUseReasoningBudget(): Enabled through user settings (enableReasoningEffort = true)
432 const isThinkingExplicitlyEnabled = metadata?.thinking?.enabled
433 const isThinkingEnabledBySettings =
434 shouldUseReasoningBudget({ model: modelConfig.info, settings: this.options }) &&
435 modelConfig.reasoning &&
436 modelConfig.reasoningBudget
437
438 if ((isThinkingExplicitlyEnabled || isThinkingEnabledBySettings) && modelConfig.info.supportsReasoningBudget) {
439 thinkingEnabled = true
440 if (isAdaptiveThinkingModel) {
441 // Claude 4.7+ (incl. 4.8 and Fable 5) uses adaptive thinking with effort levels —
442 // budget_tokens causes a 400 error.
443 // display: "summarized" surfaces thinking content in Zoo Code UI.
444 // effort "xhigh" remains the recommended level for agentic coding tasks

Callers

nothing calls this directly

Calls 15

getModelMethod · 0.95
parseBaseModelIdMethod · 0.95
parseArnMethod · 0.95
getModelByIdMethod · 0.95
getErrorTypeMethod · 0.95
handleBedrockErrorMethod · 0.95
formatErrorMessageMethod · 0.95

Tested by

no test coverage detected