@vheins/opencode-9router 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugin.js +40 -7
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -12,13 +12,13 @@ function normalizeBaseURL(url) {
|
|
|
12
12
|
}
|
|
13
13
|
function resolveBaseURL(options) {
|
|
14
14
|
if (options?.baseURL && typeof options.baseURL === "string") {
|
|
15
|
-
return normalizeBaseURL(options.baseURL);
|
|
15
|
+
return { url: normalizeBaseURL(options.baseURL), isDefault: false };
|
|
16
16
|
}
|
|
17
17
|
const envURL = globalThis.process;
|
|
18
18
|
if (envURL?.env?.ROUTER_BASE_URL) {
|
|
19
|
-
return normalizeBaseURL(envURL.env.ROUTER_BASE_URL);
|
|
19
|
+
return { url: normalizeBaseURL(envURL.env.ROUTER_BASE_URL), isDefault: false };
|
|
20
20
|
}
|
|
21
|
-
return DEFAULT_BASE_URL;
|
|
21
|
+
return { url: DEFAULT_BASE_URL, isDefault: true };
|
|
22
22
|
}
|
|
23
23
|
function ensureAPIPath(baseURL) {
|
|
24
24
|
return baseURL.endsWith(DEFAULT_API_PATH) ? baseURL : `${baseURL}${DEFAULT_API_PATH}`;
|
|
@@ -46,9 +46,9 @@ async function discoverModels(baseURL) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
export const NineRouterPlugin = async ({ client }, options) => {
|
|
49
|
-
const configuredBaseURL = resolveBaseURL(options);
|
|
50
|
-
|
|
51
|
-
if (!discovered && client?.app?.log) {
|
|
49
|
+
const { url: configuredBaseURL, isDefault } = resolveBaseURL(options);
|
|
50
|
+
let discovered = isDefault ? null : await discoverModels(configuredBaseURL);
|
|
51
|
+
if (!discovered && !isDefault && client?.app?.log) {
|
|
52
52
|
await client.app.log({
|
|
53
53
|
body: {
|
|
54
54
|
service: "9router-provider",
|
|
@@ -57,6 +57,15 @@ export const NineRouterPlugin = async ({ client }, options) => {
|
|
|
57
57
|
},
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
+
if (isDefault && client?.app?.log) {
|
|
61
|
+
await client.app.log({
|
|
62
|
+
body: {
|
|
63
|
+
service: "9router-provider",
|
|
64
|
+
level: "info",
|
|
65
|
+
message: `9Router baseURL not configured. Set it via plugin options or ROUTER_BASE_URL env var to auto-discover models.`,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
60
69
|
return {
|
|
61
70
|
config: async (config) => {
|
|
62
71
|
config.provider ??= {};
|
|
@@ -75,7 +84,31 @@ export const NineRouterPlugin = async ({ client }, options) => {
|
|
|
75
84
|
const auth = await getAuth();
|
|
76
85
|
if (auth && typeof auth === "object" && "baseURL" in auth) {
|
|
77
86
|
const userURL = normalizeBaseURL(String(auth.baseURL));
|
|
78
|
-
|
|
87
|
+
const apiURL = ensureAPIPath(userURL);
|
|
88
|
+
// Re-discover models with user-provided baseURL
|
|
89
|
+
const authDiscovered = await discoverModels(userURL);
|
|
90
|
+
if (authDiscovered) {
|
|
91
|
+
discovered = authDiscovered;
|
|
92
|
+
if (client?.app?.log) {
|
|
93
|
+
await client.app.log({
|
|
94
|
+
body: {
|
|
95
|
+
service: "9router-provider",
|
|
96
|
+
level: "info",
|
|
97
|
+
message: `Discovered ${Object.keys(authDiscovered).length} models from ${apiURL}`,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (client?.app?.log) {
|
|
103
|
+
await client.app.log({
|
|
104
|
+
body: {
|
|
105
|
+
service: "9router-provider",
|
|
106
|
+
level: "error",
|
|
107
|
+
message: `Failed to discover models from ${apiURL}. Check if 9Router is running and accessible.`,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return { baseURL: apiURL };
|
|
79
112
|
}
|
|
80
113
|
return {};
|
|
81
114
|
},
|