MCPcopy Create free account
hub / github.com/Noumena-Network/code / queryModel

Function queryModel

src/services/api/claude.ts:1044–2919  ·  view source on GitHub ↗
(
  messages: Message[],
  systemPrompt: SystemPrompt,
  thinkingConfig: ThinkingConfig,
  tools: Tools,
  signal: AbortSignal,
  options: Options,
)

Source from the content-addressed store, hash-verified

1042}
1043
1044async function* queryModel(
1045 messages: Message[],
1046 systemPrompt: SystemPrompt,
1047 thinkingConfig: ThinkingConfig,
1048 tools: Tools,
1049 signal: AbortSignal,
1050 options: Options,
1051): AsyncGenerator<
1052 StreamEvent | AssistantMessage | SystemAPIErrorMessage,
1053 void
1054> {
1055 // Check cheap conditions first — the off-switch await blocks on GrowthBook
1056 // init (~10ms). For non-Opus models (haiku, sonnet) this skips the await
1057 // entirely. Subscribers don't hit this path at all.
1058 if (
1059 getCurrentOauthBackedFirstPartyInferenceSession() === null &&
1060 isNonCustomOpusModel(options.model) &&
1061 (
1062 await getDynamicConfig_BLOCKS_ON_INIT<{ activated: boolean }>(
1063 'ncode-off-switch',
1064 {
1065 activated: false,
1066 },
1067 )
1068 ).activated
1069 ) {
1070 logEvent('ncode_off_switch_query', {})
1071 yield getAssistantMessageFromError(
1072 new Error(CUSTOM_OFF_SWITCH_MESSAGE),
1073 options.model,
1074 )
1075 return
1076 }
1077
1078 // Derive previous request ID from the last assistant message in this query chain.
1079 // This is scoped per message array (main thread, subagent, teammate each have their own),
1080 // so concurrent agents don't clobber each other's request chain tracking.
1081 // Also naturally handles rollback/undo since removed messages won't be in the array.
1082 const previousRequestId = getPreviousRequestIdFromMessages(messages)
1083
1084 const resolvedModel =
1085 getAPIProvider() === 'bedrock' &&
1086 options.model.includes('application-inference-profile')
1087 ? ((await getInferenceProfileBackingModel(options.model)) ??
1088 options.model)
1089 : options.model
1090
1091 queryCheckpoint('query_tool_schema_build_start')
1092 const isAgenticQuery =
1093 options.querySource.startsWith('repl_main_thread') ||
1094 options.querySource.startsWith('agent:') ||
1095 options.querySource === 'sdk' ||
1096 options.querySource === 'hook_agent' ||
1097 options.querySource === 'verification_agent'
1098 const betas = getMergedBetas(options.model, { isAgenticQuery })
1099
1100 // Always send the advisor beta header when advisor is enabled, so
1101 // non-agentic queries (compact, side_question, extract_memories, etc.)

Callers 2

queryModelWithStreamingFunction · 0.85

Calls 15

randomUUIDFunction · 0.90
isEnvTruthyFunction · 0.90
isNonCustomOpusModelFunction · 0.85
getAPIProviderFunction · 0.85
queryCheckpointFunction · 0.85
getMergedBetasFunction · 0.85
isAdvisorEnabledFunction · 0.85

Tested by

no test coverage detected