-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
72 lines (71 loc) · 2.38 KB
/
Copy pathindex.ts
File metadata and controls
72 lines (71 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { resolveOAuthApiKeyMarker } from "openclaw/plugin-sdk/provider-auth";
import { defineSingleProviderPluginEntry } from "openclaw/plugin-sdk/provider-entry";
import { buildProviderReplayFamilyHooks } from "openclaw/plugin-sdk/provider-model-shared";
import { resolveRuntimeConfig } from "./src/config.js";
import { PROVIDER_ID } from "./src/constants.js";
import {
buildFallbackModel,
buildProviderConfig,
normalizeZenMuxModelId,
refreshModels,
} from "./src/model-catalog.js";
import { loginZenMux, refreshZenMuxOAuthCredential } from "./src/oauth.js";
const replayHooks = buildProviderReplayFamilyHooks({
family: "hybrid-anthropic-openai",
anthropicModelDropThinkingBlocks: true,
});
export default defineSingleProviderPluginEntry({
id: PROVIDER_ID,
name: "ZenMux Provider",
description: "ZenMux OAuth provider with dynamic multi-protocol model discovery",
provider: {
label: "ZenMux",
docsPath: "https://zenmux.ai/docs",
envVars: [
"ZENMUX_OAUTH_CLIENT_ID",
"ZENMUX_OAUTH_ORIGIN",
"ZENMUX_API_BASE_URL",
"ZENMUX_ANTHROPIC_BASE_URL",
"ZENMUX_MODEL_CATALOG_URL",
],
extraAuth: [
{
id: "oauth",
label: "ZenMux OAuth",
hint: "Browser sign-in with PKCE",
kind: "oauth",
wizard: {
choiceId: "zenmux-oauth",
choiceLabel: "ZenMux OAuth",
choiceHint: "Browser sign-in with PKCE",
groupId: PROVIDER_ID,
groupLabel: "ZenMux",
groupHint: "OAuth access to ZenMux models",
methodId: "oauth",
},
run: loginZenMux,
},
],
catalog: {
order: "profile",
run: async (ctx) => {
const config = resolveRuntimeConfig(ctx.env);
const { apiKey } = ctx.resolveProviderAuth(PROVIDER_ID, {
oauthMarker: resolveOAuthApiKeyMarker(PROVIDER_ID),
});
if (!apiKey) return null;
const models = await refreshModels({ config });
return { provider: buildProviderConfig({ config, models, apiKey }) };
},
staticRun: async (ctx) => {
const config = resolveRuntimeConfig(ctx.env);
return {
provider: buildProviderConfig({ config, models: [buildFallbackModel(config)] }),
};
},
},
normalizeModelId: ({ modelId }) => normalizeZenMuxModelId(modelId),
refreshOAuth: refreshZenMuxOAuthCredential,
...replayHooks,
},
});