MCPcopy
hub / github.com/CodebuffAI/codebuff / promptAiSdk

Function promptAiSdk

sdk/src/impl/llm.ts:720–786  ·  view source on GitHub ↗
(
  params: ParamsOf<PromptAiSdkFn>,
)

Source from the content-addressed store, hash-verified

718}
719
720export async function promptAiSdk(
721 params: ParamsOf<PromptAiSdkFn>,
722): ReturnType<PromptAiSdkFn> {
723 const { logger } = params
724
725 if (params.signal.aborted) {
726 logger.info(
727 {
728 userId: params.userId,
729 userInputId: params.userInputId,
730 },
731 'Skipping prompt due to canceled user input',
732 )
733 return promptAborted('User cancelled input')
734 }
735
736 const modelParams: ModelRequestParams = {
737 apiKey: params.apiKey,
738 model: params.model,
739 skipChatGptOAuth: true, // Always use Codebuff backend for non-streaming
740 }
741 const { model: aiSDKModel } = await getModelForRequest(modelParams)
742
743 const response = await generateText({
744 ...params,
745 prompt: undefined,
746 model: aiSDKModel,
747 messages: convertCbToModelMessages(params),
748 providerOptions: getProviderOptions({
749 ...params,
750 agentProviderOptions: params.agentProviderOptions,
751 cacheDebugCorrelation: params.cacheDebugCorrelation,
752 }),
753 })
754 emitCacheDebugProviderRequest({
755 callback: params.onCacheDebugProviderRequestBuilt,
756 provider: getModelProvider(aiSDKModel),
757 rawBody: response.request?.body,
758 })
759 emitCacheDebugUsage({
760 callback: params.onCacheDebugUsageReceived,
761 usage: response.usage,
762 })
763 const content = response.text
764
765 const providerMetadata = response.providerMetadata ?? {}
766 let costOverrideDollars: number | undefined
767 if (providerMetadata.codebuff) {
768 if (providerMetadata.codebuff.usage) {
769 const openrouterUsage = providerMetadata.codebuff
770 .usage as OpenRouterUsageAccounting
771
772 costOverrideDollars =
773 (openrouterUsage.cost ?? 0) +
774 (openrouterUsage.costDetails?.upstreamInferenceCost ?? 0)
775 }
776 }
777

Callers 7

generateChangelogFunction · 0.90
relabelTraceWithModelFunction · 0.90
relabelWithRelaceFunction · 0.90
runAgentStepFunction · 0.85
promptFlashWithFallbacksFunction · 0.85

Calls 9

promptAbortedFunction · 0.90
getModelForRequestFunction · 0.90
convertCbToModelMessagesFunction · 0.90
promptSuccessFunction · 0.90
getProviderOptionsFunction · 0.85
getModelProviderFunction · 0.85
emitCacheDebugUsageFunction · 0.85
calculateUsedCreditsFunction · 0.85

Tested by

no test coverage detected