@meyverick/opencode-omniroute-auth 1.0.0

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.
@@ -0,0 +1,3 @@
1
+ export type { Plugin, Hooks, AuthHook, ProviderHook } from "./src/index.js";
2
+ export declare const OmniRouteAuthPlugin: Plugin;
3
+ export default OmniRouteAuthPlugin;
package/dist/index.js ADDED
@@ -0,0 +1,57 @@
1
+ export const OmniRouteAuthPlugin = async (_input) => {
2
+ return {
3
+ config: (config) => {
4
+ const providers = config.provider ?? {};
5
+ const existing = providers.omniroute;
6
+ const baseUrl = existing?.options?.baseURL ?? "http://localhost:20128/v1";
7
+ providers.omniroute = {
8
+ ...existing, name: "OmniRoute",
9
+ npm: "@ai-sdk/openai-compatible", env: ["OMNIROUTE_API_KEY"],
10
+ options: { ...existing?.options, baseURL: baseUrl },
11
+ };
12
+ config.provider = providers;
13
+ },
14
+ auth: {
15
+ provider: "omniroute", methods: [{ type: "api", label: "API Key" }],
16
+ loader: async (getAuth, provider) => {
17
+ const auth = await getAuth();
18
+ if (!auth || auth.type !== "api" || !auth.key)
19
+ throw new Error("No API key. Run /connect omniroute.");
20
+ const baseUrl = provider.options?.baseURL ?? "http://localhost:20128/v1";
21
+ return { apiKey: auth.key, baseURL: baseUrl.replace(/\/+$/, "") };
22
+ },
23
+ },
24
+ provider: {
25
+ id: "omniroute",
26
+ models: async (provider, ctx) => {
27
+ if (ctx.auth?.type !== "api" || !ctx.auth.key) return {};
28
+ try {
29
+ const baseUrl = provider.options?.baseURL ?? "http://localhost:20128/v1";
30
+ const url = `${baseUrl.replace(/\/+$/, "")}/models`;
31
+ const res = await fetch(url, {
32
+ headers: { Authorization: `Bearer ${ctx.auth.key}` }, signal: AbortSignal.timeout(10000),
33
+ });
34
+ if (!res.ok) return {};
35
+ const body = await res.json(); const raw = body.data ?? []; const models = {};
36
+ for (const m of raw) {
37
+ models[m.id] = {
38
+ id: m.id, name: m.name ?? m.id, providerID: "omniroute",
39
+ family: m.family ?? m.id.split("/")[0] ?? "unknown",
40
+ capabilities: {
41
+ vision: !!m.capabilities?.vision, tools: !!(m.capabilities?.tool_calling ?? m.capabilities?.tools),
42
+ reasoning: !!m.capabilities?.reasoning, streaming: m.capabilities?.streaming ?? true,
43
+ temperature: m.capabilities?.temperature ?? true,
44
+ },
45
+ cost: { input: m.pricing?.input ?? m.cost?.input ?? 0, output: m.pricing?.output ?? m.cost?.output ?? 0 },
46
+ limit: { context: m.contextWindow ?? m.context_length ?? m.limit?.context ?? 128000, output: m.maxTokens ?? m.max_output_tokens ?? m.limit?.output ?? 8192 },
47
+ api: { type: "openai", url: `${baseUrl.replace(/\/+$/, "")}` }, status: m.status ?? "active",
48
+ };
49
+ }
50
+ return models;
51
+ } catch { return {}; }
52
+ },
53
+ },
54
+ };
55
+ };
56
+ export { OmniRouteAuthPlugin }
57
+ export default OmniRouteAuthPlugin
@@ -0,0 +1,88 @@
1
+ export const OmniRouteAuthPlugin = async (_input) => {
2
+ return {
3
+ config: (config) => {
4
+ const providers = config.provider ?? {};
5
+ const existing = providers.omniroute;
6
+ const baseUrl =
7
+ existing?.options?.baseURL ?? "http://localhost:20128/v1";
8
+ providers.omniroute = {
9
+ ...existing,
10
+ name: "OmniRoute",
11
+ npm: "@ai-sdk/openai-compatible",
12
+ env: ["OMNIROUTE_API_KEY"],
13
+ options: { ...existing?.options, baseURL: baseUrl },
14
+ };
15
+ config.provider = providers;
16
+ },
17
+ auth: {
18
+ provider: "omniroute",
19
+ methods: [{ type: "api", label: "API Key" }],
20
+ loader: async (getAuth, provider) => {
21
+ const auth = await getAuth();
22
+ if (!auth || auth.type !== "api" || !auth.key) {
23
+ throw new Error(
24
+ "No API key available. Run /connect omniroute to add your OmniRoute API key."
25
+ );
26
+ }
27
+ const baseUrl =
28
+ provider.options?.baseURL ?? "http://localhost:20128/v1";
29
+ const normalized = baseUrl.replace(/\/+$/, "");
30
+ return {
31
+ apiKey: auth.key,
32
+ baseURL: normalized,
33
+ };
34
+ },
35
+ },
36
+ provider: {
37
+ id: "omniroute",
38
+ models: async (provider, ctx) => {
39
+ if (ctx.auth?.type !== "api" || !ctx.auth.key) return {};
40
+ try {
41
+ const baseUrl =
42
+ provider.options?.baseURL ?? "http://localhost:20128/v1";
43
+ const url = `${baseUrl.replace(/\/+$/, "")}/models`;
44
+ const res = await fetch(url, {
45
+ headers: { Authorization: `Bearer ${ctx.auth.key}` },
46
+ signal: AbortSignal.timeout(10000),
47
+ });
48
+ if (!res.ok) return {};
49
+ const body = await res.json();
50
+ const raw = body.data ?? [];
51
+ const models = {};
52
+ for (const m of raw) {
53
+ models[m.id] = {
54
+ id: m.id,
55
+ name: m.name ?? m.id,
56
+ providerID: "omniroute",
57
+ family: m.family ?? m.id.split("/")[0] ?? "unknown",
58
+ capabilities: {
59
+ vision: !!m.capabilities?.vision,
60
+ tools: !!(m.capabilities?.tool_calling ?? m.capabilities?.tools),
61
+ reasoning: !!m.capabilities?.reasoning,
62
+ streaming: m.capabilities?.streaming ?? true,
63
+ temperature: m.capabilities?.temperature ?? true,
64
+ },
65
+ cost: {
66
+ input: m.pricing?.input ?? m.cost?.input ?? 0,
67
+ output: m.pricing?.output ?? m.cost?.output ?? 0,
68
+ },
69
+ limit: {
70
+ context:
71
+ m.contextWindow ?? m.context_length ?? m.limit?.context ?? 128000,
72
+ output: m.maxTokens ?? m.max_output_tokens ?? m.limit?.output ?? 8192,
73
+ },
74
+ api: { type: "openai", url: `${baseUrl.replace(/\/+$/, "")}` },
75
+ status: m.status ?? "active",
76
+ };
77
+ }
78
+ return models;
79
+ } catch {
80
+ return {};
81
+ }
82
+ },
83
+ },
84
+ };
85
+ };
86
+
87
+ export { OmniRouteAuthPlugin }
88
+ export default OmniRouteAuthPlugin
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@meyverick/opencode-omniroute-auth",
3
+ "version": "1.0.0",
4
+ "description": "OpenCode authentication plugin for OmniRoute API with /connect command and dynamic model fetching",
5
+ "keywords": [
6
+ "opencode",
7
+ "plugin",
8
+ "auth",
9
+ "omniroute",
10
+ "authentication",
11
+ "api-key",
12
+ "connect",
13
+ "models"
14
+ ],
15
+ "homepage": "https://github.com/meyverick/omnicode/tree/main/plugin-npm#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/meyverick/omnicode/issues"
18
+ },
19
+ "license": "MIT",
20
+ "type": "module",
21
+ "main": "./dist/index.js",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./dist/index.js",
25
+ "types": "./dist/index.d.ts"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "scripts": {
32
+ "build": "node -e \"const fs=require('fs');fs.mkdirSync('dist',{recursive:true});fs.copyFileSync('src/index.js','dist/index.js');console.log('Built');\"",
33
+ "prepublishOnly": "npm run build"
34
+ },
35
+ "engines": {
36
+ "node": ">=20.0.0"
37
+ },
38
+ "peerDependencies": {
39
+ "@opencode-ai/plugin": "*"
40
+ }
41
+ }