|
|
@@ -0,0 +1,28 @@
|
|
|
+import { PluginContext } from "@opencode/plugin";
|
|
|
+import { validateConfig } from "./config";
|
|
|
+import { discoverModels } from "./discovery";
|
|
|
+import { registerProvider } from "./provider";
|
|
|
+
|
|
|
+export default async function (ctx: PluginContext) {
|
|
|
+ const config = validateConfig(ctx.config);
|
|
|
+
|
|
|
+ for (const endpoint of config.endpoints) {
|
|
|
+ try {
|
|
|
+ const models = await discoverModels(endpoint.baseURL, endpoint.apiKey);
|
|
|
+ await registerProvider(ctx, endpoint.name, endpoint.baseURL, models);
|
|
|
+ ctx.log.info(`Discovered ${models.length} models from ${endpoint.name}`);
|
|
|
+ } catch (error) {
|
|
|
+ ctx.log.error(`Failed to discover models from ${endpoint.name}: ${error}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Command: /models refresh
|
|
|
+ ctx.commands.register({
|
|
|
+ id: "refresh-models",
|
|
|
+ description: "Refresh all discovered models",
|
|
|
+ async run() {
|
|
|
+ ctx.log.info("Refreshing models...");
|
|
|
+ await ctx.provider.reload();
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|