mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-16 22:01:35 +00:00
* feat(openai): add provider-owned route facts * fix(openai): harden provider route facts * test(codex): update rebased auth fixtures * chore: leave release notes to release workflow * fix(openai): align route auth with current contracts * test(openai): align route and shard expectations * test(openai): satisfy route fixture contracts * fix(openai): preserve direct profile forwarding * test(models): complete route auth mocks * test(codex): type compaction factory mock * fix(openai): preserve provider-native model ids * test(agents): align route auth fixtures * style(agents): format route integrations * test(plugin-sdk): pin current surface counts
55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
/** Client-scoped Codex auth and account observers. */
|
|
import { refreshCodexAppServerAuthTokens } from "./auth-bridge.js";
|
|
import type { CodexAppServerClient } from "./client.js";
|
|
import type { JsonValue } from "./protocol.js";
|
|
import { mergeCodexRateLimitsUpdate } from "./rate-limit-cache.js";
|
|
import type { CodexAppServerAuthProfileLookup } from "./session-binding.js";
|
|
|
|
type ClientRuntimeContext = Omit<CodexAppServerAuthProfileLookup, "agentDir"> & {
|
|
agentDir: string;
|
|
authMode?: "prepared-api-key" | "profile";
|
|
};
|
|
|
|
type ClientRuntime = {
|
|
context: ClientRuntimeContext;
|
|
};
|
|
|
|
const configuredClients = new WeakMap<CodexAppServerClient, ClientRuntime>();
|
|
|
|
/** Installs one auth-refresh handler and one rate-limit observer per physical client. */
|
|
export function ensureCodexAppServerClientRuntime(
|
|
client: CodexAppServerClient,
|
|
context: ClientRuntimeContext,
|
|
): void {
|
|
const existing = configuredClients.get(client);
|
|
if (existing) {
|
|
// Shared-client keys already isolate agent/auth identity. Keep config fresh
|
|
// without installing another physical-client handler set.
|
|
existing.context = context;
|
|
return;
|
|
}
|
|
const runtime: ClientRuntime = { context };
|
|
configuredClients.set(client, runtime);
|
|
client.addRequestHandler(async (request) => {
|
|
if (request.method !== "account/chatgptAuthTokens/refresh") {
|
|
return undefined;
|
|
}
|
|
if (runtime.context.authMode === "prepared-api-key") {
|
|
throw new Error("ChatGPT token refresh is unavailable for prepared Codex API-key auth.");
|
|
}
|
|
return (await refreshCodexAppServerAuthTokens({
|
|
agentDir: runtime.context.agentDir,
|
|
authProfileId: runtime.context.authProfileId,
|
|
...(runtime.context.authProfileStore
|
|
? { authProfileStore: runtime.context.authProfileStore }
|
|
: {}),
|
|
config: runtime.context.config,
|
|
})) as unknown as JsonValue;
|
|
});
|
|
client.addNotificationHandler((notification) => {
|
|
if (notification.method === "account/rateLimits/updated") {
|
|
mergeCodexRateLimitsUpdate(client, notification.params);
|
|
}
|
|
});
|
|
}
|