mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 23:27:26 +00:00
refactor(media): share provider auth resolution for entry runs
This commit is contained in:
@@ -298,6 +298,28 @@ function resolveEntryRunOptions(params: {
|
||||
return { maxBytes, maxChars, timeoutMs, prompt };
|
||||
}
|
||||
|
||||
async function resolveProviderExecutionAuth(params: {
|
||||
providerId: string;
|
||||
cfg: OpenClawConfig;
|
||||
entry: MediaUnderstandingModelConfig;
|
||||
agentDir?: string;
|
||||
}) {
|
||||
const auth = await resolveApiKeyForProvider({
|
||||
provider: params.providerId,
|
||||
cfg: params.cfg,
|
||||
profileId: params.entry.profile,
|
||||
preferredProfile: params.entry.preferredProfile,
|
||||
agentDir: params.agentDir,
|
||||
});
|
||||
return {
|
||||
apiKeys: collectProviderApiKeysForExecution({
|
||||
provider: params.providerId,
|
||||
primaryApiKey: requireApiKey(auth, params.providerId),
|
||||
}),
|
||||
providerConfig: params.cfg.models?.providers?.[params.providerId],
|
||||
};
|
||||
}
|
||||
|
||||
export function formatDecisionSummary(decision: MediaUnderstandingDecision): string {
|
||||
const total = decision.attachments.length;
|
||||
const success = decision.attachments.filter(
|
||||
@@ -406,18 +428,12 @@ export async function runProviderEntry(params: {
|
||||
maxBytes,
|
||||
timeoutMs,
|
||||
});
|
||||
const auth = await resolveApiKeyForProvider({
|
||||
provider: providerId,
|
||||
const { apiKeys, providerConfig } = await resolveProviderExecutionAuth({
|
||||
providerId,
|
||||
cfg,
|
||||
profileId: entry.profile,
|
||||
preferredProfile: entry.preferredProfile,
|
||||
entry,
|
||||
agentDir: params.agentDir,
|
||||
});
|
||||
const apiKeys = collectProviderApiKeysForExecution({
|
||||
provider: providerId,
|
||||
primaryApiKey: requireApiKey(auth, providerId),
|
||||
});
|
||||
const providerConfig = cfg.models?.providers?.[providerId];
|
||||
const baseUrl = entry.baseUrl ?? params.config?.baseUrl ?? providerConfig?.baseUrl;
|
||||
const mergedHeaders = {
|
||||
...providerConfig?.headers,
|
||||
@@ -475,18 +491,12 @@ export async function runProviderEntry(params: {
|
||||
`Video attachment ${params.attachmentIndex + 1} base64 payload ${estimatedBase64Bytes} exceeds ${maxBase64Bytes}`,
|
||||
);
|
||||
}
|
||||
const auth = await resolveApiKeyForProvider({
|
||||
provider: providerId,
|
||||
const { apiKeys, providerConfig } = await resolveProviderExecutionAuth({
|
||||
providerId,
|
||||
cfg,
|
||||
profileId: entry.profile,
|
||||
preferredProfile: entry.preferredProfile,
|
||||
entry,
|
||||
agentDir: params.agentDir,
|
||||
});
|
||||
const apiKeys = collectProviderApiKeysForExecution({
|
||||
provider: providerId,
|
||||
primaryApiKey: requireApiKey(auth, providerId),
|
||||
});
|
||||
const providerConfig = cfg.models?.providers?.[providerId];
|
||||
const result = await executeWithApiKeyRotation({
|
||||
provider: providerId,
|
||||
apiKeys,
|
||||
|
||||
Reference in New Issue
Block a user