@vheins/opencode-9router 0.4.1 → 0.4.3

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.
Files changed (2) hide show
  1. package/dist/plugin.js +19 -16
  2. package/package.json +1 -1
package/dist/plugin.js CHANGED
@@ -1,4 +1,4 @@
1
- import { PLUGIN_NAME, PROVIDER_DISPLAY_NAME, DEFAULT_BASE_URL, DEFAULT_API_PATH, FALLBACK_MODELS, KNOWN_PROVIDER_PREFIXES, } from "./constants.js";
1
+ import { PLUGIN_NAME, PROVIDER_DISPLAY_NAME, DEFAULT_BASE_URL, DEFAULT_API_PATH, KNOWN_PROVIDER_PREFIXES, } from "./constants.js";
2
2
  function formatModelName(modelId) {
3
3
  for (const [prefix, provider] of Object.entries(KNOWN_PROVIDER_PREFIXES)) {
4
4
  if (modelId.startsWith(prefix)) {
@@ -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,15 +46,23 @@ async function discoverModels(baseURL) {
46
46
  }
47
47
  }
48
48
  export const NineRouterPlugin = async ({ client }, options) => {
49
- const configuredBaseURL = resolveBaseURL(options);
50
- const discovered = await discoverModels(configuredBaseURL);
51
- const models = discovered ?? FALLBACK_MODELS;
52
- if (!discovered && client?.app?.log) {
49
+ const { url: configuredBaseURL, isDefault } = resolveBaseURL(options);
50
+ const discovered = isDefault ? null : await discoverModels(configuredBaseURL);
51
+ if (!discovered && !isDefault && client?.app?.log) {
53
52
  await client.app.log({
54
53
  body: {
55
54
  service: "9router-provider",
56
- level: "warn",
57
- message: `9Router not reachable at ${configuredBaseURL}. Using well-known model list. Start 9Router and restart opencode to auto-discover models.`,
55
+ level: "error",
56
+ message: `9Router not reachable at ${configuredBaseURL}. Please check if 9Router is running and accessible.`,
57
+ },
58
+ });
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.`,
58
66
  },
59
67
  });
60
68
  }
@@ -67,7 +75,7 @@ export const NineRouterPlugin = async ({ client }, options) => {
67
75
  options: {
68
76
  baseURL: ensureAPIPath(configuredBaseURL),
69
77
  },
70
- models,
78
+ models: discovered ?? {},
71
79
  };
72
80
  },
73
81
  auth: {
@@ -90,11 +98,6 @@ export const NineRouterPlugin = async ({ client }, options) => {
90
98
  message: `${PROVIDER_DISPLAY_NAME} Base URL (default: ${DEFAULT_BASE_URL})`,
91
99
  key: "baseURL",
92
100
  },
93
- {
94
- type: "text",
95
- message: `${PROVIDER_DISPLAY_NAME} API Key (from Dashboard → Endpoints)`,
96
- key: "apiKey",
97
- },
98
101
  ],
99
102
  },
100
103
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vheins/opencode-9router",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "OpenCode plugin provider for 9Router — FREE AI Router & Token Saver. 40+ providers, 100+ models.",
5
5
  "author": "vheins",
6
6
  "keywords": [