






















@@ -21,6 +21,7 @@ import {
2121} from "../agent-scope.js";
2222import {
2323type AuthProfileFailureReason,
24+type AuthProfileStore,
2425markAuthProfileFailure,
2526resolveAuthProfileEligibility,
2627markAuthProfileGood,
@@ -38,6 +39,7 @@ import {
3839FailoverError,
3940resolveFailoverStatus,
4041} from "../failover-error.js";
42+import { selectAgentHarness } from "../harness/selection.js";
4143import { LiveSessionModelSwitchError } from "../live-model-switch-error.js";
4244import { shouldSwitchToLiveModel, clearLiveModelSwitchPending } from "../live-model-switch.js";
4345import {
@@ -140,6 +142,13 @@ type ApiKeyInfo = ResolvedProviderAuth;
140142141143const MAX_SAME_MODEL_IDLE_TIMEOUT_RETRIES = 1;
142144145+function createEmptyAuthProfileStore(): AuthProfileStore {
146+return {
147+version: 1,
148+profiles: {},
149+};
150+}
151+143152function buildTraceToolSummary(params: {
144153toolMetas: Array<{ toolName: string; meta?: string }>;
145154hadFailure: boolean;
@@ -291,7 +300,6 @@ export async function runEmbeddedPiAgent(
291300agentId: params.agentId,
292301sessionKey: normalizedSessionKey,
293302});
294-await ensureOpenClawModelsJson(params.config, agentDir);
295303const resolvedSessionKey = normalizedSessionKey;
296304const hookRunner = getGlobalHookRunner();
297305const hookCtx = {
@@ -318,12 +326,28 @@ export async function runEmbeddedPiAgent(
318326provider = hookSelection.provider;
319327modelId = hookSelection.modelId;
320328const legacyBeforeAgentStartResult = hookSelection.legacyBeforeAgentStartResult;
329+const agentHarness = selectAgentHarness({
330+ provider,
331+ modelId,
332+config: params.config,
333+agentId: params.agentId,
334+sessionKey: params.sessionKey,
335+agentHarnessId: params.agentHarnessId,
336+});
337+const pluginHarnessOwnsTransport = agentHarness.id !== "pi";
338+if (!pluginHarnessOwnsTransport) {
339+await ensureOpenClawModelsJson(params.config, agentDir);
340+}
321341322342const { model, error, authStorage, modelRegistry } = await resolveModelAsync(
323343provider,
324344modelId,
325345agentDir,
326346params.config,
347+// Plugin harnesses may expose synthetic providers that PI cannot
348+// discover safely; resolve their model metadata without touching PI
349+// auth/model stores.
350+{ skipPiDiscovery: pluginHarnessOwnsTransport },
327351);
328352if (!model) {
329353throw new FailoverError(error ?? `Unknown model: ${provider}/${modelId}`, {
@@ -343,9 +367,11 @@ export async function runEmbeddedPiAgent(
343367const ctxInfo = resolvedRuntimeModel.ctxInfo;
344368let effectiveModel = resolvedRuntimeModel.effectiveModel;
345369346-const authStore = ensureAuthProfileStore(agentDir, {
347-allowKeychainPrompt: false,
348-});
370+const authStore = pluginHarnessOwnsTransport
371+ ? createEmptyAuthProfileStore()
372+ : ensureAuthProfileStore(agentDir, {
373+allowKeychainPrompt: false,
374+});
349375const preferredProfileId = params.authProfileId?.trim();
350376let lockedProfileId = params.authProfileIdSource === "user" ? preferredProfileId : undefined;
351377if (lockedProfileId) {
@@ -444,7 +470,12 @@ export async function runEmbeddedPiAgent(
444470 log,
445471});
446472447-await initializeAuthProfile();
473+// Plugin harnesses own their model transport/auth. Running PI's generic
474+// auth bootstrap here can turn synthetic provider markers into real
475+// vendor-token refresh attempts before the plugin gets control.
476+if (!pluginHarnessOwnsTransport) {
477+await initializeAuthProfile();
478+}
448479const { sessionAgentId } = resolveSessionAgentIds({
449480sessionKey: params.sessionKey,
450481config: params.config,
@@ -731,7 +762,10 @@ export async function runEmbeddedPiAgent(
731762disableTools: params.disableTools,
732763 provider,
733764 modelId,
734-agentHarnessId: params.agentHarnessId,
765+// Use the harness selected before model/auth setup for the actual
766+// attempt too. Otherwise plugin-owned transports can skip PI auth
767+// bootstrap but drift back to PI when the attempt is created.
768+agentHarnessId: agentHarness.id,
735769model: applyAuthHeaderOverride(
736770applyLocalNoAuthHeaderOverride(effectiveModel, apiKeyInfo),
737771// When runtime auth exchange produced a different credential
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。