mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-22 22:52:03 +00:00
refactor(plugins): move auth profile hooks into providers
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
emptyPluginConfigSchema,
|
||||
type OpenClawPluginApi,
|
||||
type ProviderAuthContext,
|
||||
type ProviderResolveDynamicModelContext,
|
||||
type ProviderRuntimeModel,
|
||||
} from "openclaw/plugin-sdk/core";
|
||||
@@ -8,6 +9,7 @@ import { listProfilesForProvider } from "../../src/agents/auth-profiles/profiles
|
||||
import { ensureAuthProfileStore } from "../../src/agents/auth-profiles/store.js";
|
||||
import { normalizeModelCompat } from "../../src/agents/model-compat.js";
|
||||
import { coerceSecretRef } from "../../src/config/types.secrets.js";
|
||||
import { githubCopilotLoginCommand } from "../../src/providers/github-copilot-auth.js";
|
||||
import { DEFAULT_COPILOT_API_BASE_URL, resolveCopilotApiToken } from "./token.js";
|
||||
import { fetchCopilotUsage } from "./usage.js";
|
||||
|
||||
@@ -72,6 +74,46 @@ function resolveCopilotForwardCompatModel(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function runGitHubCopilotAuth(ctx: ProviderAuthContext) {
|
||||
await ctx.prompter.note(
|
||||
[
|
||||
"This will open a GitHub device login to authorize Copilot.",
|
||||
"Requires an active GitHub Copilot subscription.",
|
||||
].join("\n"),
|
||||
"GitHub Copilot",
|
||||
);
|
||||
|
||||
if (!process.stdin.isTTY) {
|
||||
await ctx.prompter.note("GitHub Copilot login requires an interactive TTY.", "GitHub Copilot");
|
||||
return { profiles: [] };
|
||||
}
|
||||
|
||||
try {
|
||||
await githubCopilotLoginCommand({ yes: true, profileId: "github-copilot:github" }, ctx.runtime);
|
||||
} catch (err) {
|
||||
await ctx.prompter.note(`GitHub Copilot login failed: ${String(err)}`, "GitHub Copilot");
|
||||
return { profiles: [] };
|
||||
}
|
||||
|
||||
const authStore = ensureAuthProfileStore(undefined, {
|
||||
allowKeychainPrompt: false,
|
||||
});
|
||||
const credential = authStore.profiles["github-copilot:github"];
|
||||
if (!credential || credential.type !== "token") {
|
||||
return { profiles: [] };
|
||||
}
|
||||
|
||||
return {
|
||||
profiles: [
|
||||
{
|
||||
profileId: "github-copilot:github",
|
||||
credential,
|
||||
},
|
||||
],
|
||||
defaultModel: "github-copilot/gpt-4o",
|
||||
};
|
||||
}
|
||||
|
||||
const githubCopilotPlugin = {
|
||||
id: "github-copilot",
|
||||
name: "GitHub Copilot Provider",
|
||||
@@ -83,7 +125,23 @@ const githubCopilotPlugin = {
|
||||
label: "GitHub Copilot",
|
||||
docsPath: "/providers/models",
|
||||
envVars: COPILOT_ENV_VARS,
|
||||
auth: [],
|
||||
auth: [
|
||||
{
|
||||
id: "device",
|
||||
label: "GitHub device login",
|
||||
hint: "Browser device-code flow",
|
||||
kind: "device_code",
|
||||
run: async (ctx) => await runGitHubCopilotAuth(ctx),
|
||||
},
|
||||
],
|
||||
wizard: {
|
||||
setup: {
|
||||
choiceId: "github-copilot",
|
||||
choiceLabel: "GitHub Copilot",
|
||||
choiceHint: "Device login with your GitHub account",
|
||||
methodId: "device",
|
||||
},
|
||||
},
|
||||
catalog: {
|
||||
order: "late",
|
||||
run: async (ctx) => {
|
||||
|
||||
Reference in New Issue
Block a user