opencode-aifs-provider 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +70 -2
- package/package.json +24 -4
- package/src/index.ts +127 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sven Weber
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,71 @@
|
|
|
1
|
-
#
|
|
1
|
+
# opencode-aifs-provider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
OpenCode V2 plugin that auto-discovers **AIFS LLM Serving** models at runtime from the provider's `/models` endpoint, so users no longer hand-maintain a `models` block in `opencode.json(c)`.
|
|
4
|
+
|
|
5
|
+
> **Compatibility**: Tested against AIFS LLM Serving (OpenAI-compatible `/models` endpoint). Other AIFS pillars (SmartChat, RAG, Fine Tuning) are not covered by this plugin.
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
AIFS (AI Foundation Services, T-Systems) exposes an OpenAI-compatible LLM endpoint but is not indexed on models.dev. OpenCode V2 cannot auto-discover models from a generic `openai-compatible` provider's `/models` endpoint — it relies on explicit `models` entries in config. This plugin closes that gap by calling the AIFS API at startup and registering the discovered models through OpenCode's provider transform API.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install -g opencode-aifs-provider
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Configure
|
|
18
|
+
|
|
19
|
+
Add to `~/.config/opencode/opencode.json(c)`:
|
|
20
|
+
|
|
21
|
+
```jsonc
|
|
22
|
+
{
|
|
23
|
+
"$schema": "https://opencode.ai/config.json",
|
|
24
|
+
"plugins": ["opencode-aifs-provider"],
|
|
25
|
+
"providers": {
|
|
26
|
+
"aifs": {
|
|
27
|
+
"name": "AIFS",
|
|
28
|
+
"package": "aisdk:@ai-sdk/openai-compatible",
|
|
29
|
+
"settings": {
|
|
30
|
+
"baseURL": "{env:AIFS_BASE_URL}",
|
|
31
|
+
"apiKey": "{env:AIFS_API_KEY}"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
No `models` block under `providers.aifs` — the plugin fills it at runtime.
|
|
39
|
+
|
|
40
|
+
## Environment
|
|
41
|
+
|
|
42
|
+
| Variable | Required | Notes |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
| `AIFS_BASE_URL` | yes | Must include the API version, e.g. `https://llm-server.llmhub.t-systems.net/v2` |
|
|
45
|
+
| `AIFS_API_KEY` | yes | AIFS API key with model-list scope |
|
|
46
|
+
|
|
47
|
+
## Plugin options
|
|
48
|
+
|
|
49
|
+
Pass options via the object form in the `plugins` array when you need to override defaults:
|
|
50
|
+
|
|
51
|
+
```jsonc
|
|
52
|
+
{ "plugins": [{ "package": "opencode-aifs-provider", "options": { "providerID": "aifs" } }] }
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
| Option | Default | Purpose |
|
|
56
|
+
|---|---|---|
|
|
57
|
+
| `providerID` | `"aifs"` | Register models under this provider ID. Must match the key under `providers` in your config. |
|
|
58
|
+
| `baseURL` | `process.env.AIFS_BASE_URL` | Override the AIFS base URL |
|
|
59
|
+
| `apiKey` | `process.env.AIFS_API_KEY` | Override the AIFS API key |
|
|
60
|
+
|
|
61
|
+
## Behavior
|
|
62
|
+
|
|
63
|
+
- Fetches `${baseURL}/models` with Bearer auth at plugin load.
|
|
64
|
+
- OpenCode supports chat models that emit text output (`model_type === "LLM"` and `output_modalities` includes `"text"`). Models not matching this are ignored.
|
|
65
|
+
- Maps AIFS metadata to OpenCode `Model.Info`: `id`, `name` (`display_name`), `limit.context`/`output` (`max_sequence_length`/`max_output_length`), `capabilities.input`/`output` (modalities, lowercased), `status` (`Stable`→`active`, `Experimental`→`beta`).
|
|
66
|
+
- Calls `ctx.provider.transform(editor => editor.models.set(providerID, models))`.
|
|
67
|
+
- On fetch failure: logs and skips — does not crash OpenCode.
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-aifs-provider",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OpenCode V2 plugin that auto-discovers AIFS LLM Serving models at runtime from the /models endpoint.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Sven Weber",
|
|
7
|
+
"keywords": ["opencode", "aifs", "t-systems", "openai-compatible", "llm"],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"files": ["src"],
|
|
13
|
+
"engines": {
|
|
14
|
+
"opencode": "^2.0.0"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@opencode/plugin": "^2.2.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^5.6.0",
|
|
21
|
+
"@types/node": "^22.0.0"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"typecheck": "tsc --noEmit"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Plugin, Model, Provider } from "@opencode/plugin"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AIFS /v2/models response shape (OpenAI-compatible with meta_data nesting).
|
|
5
|
+
* The helper fetches ${AIFS_BASE_URL}/models with Bearer auth.
|
|
6
|
+
*/
|
|
7
|
+
interface AifsModelMeta {
|
|
8
|
+
display_name: string
|
|
9
|
+
model_type: string
|
|
10
|
+
source_type: string
|
|
11
|
+
max_sequence_length: number
|
|
12
|
+
max_output_length: number
|
|
13
|
+
deployment_region: string
|
|
14
|
+
deployment_country: string
|
|
15
|
+
location: string
|
|
16
|
+
input_modalities: string[]
|
|
17
|
+
output_modalities: string[]
|
|
18
|
+
model_lifecycle_stage: string
|
|
19
|
+
license: string
|
|
20
|
+
is_externally_hosted: boolean
|
|
21
|
+
end_of_life_date: string | null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface AifsModel {
|
|
25
|
+
id: string
|
|
26
|
+
meta_data: AifsModelMeta
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface AifsResponse {
|
|
30
|
+
data: AifsModel[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Plugin options. Set `providerID` to register models under a different provider
|
|
34
|
+
* (used for the `aifs2` test sandbox without touching the live `aifs` block). */
|
|
35
|
+
interface AifsPluginOptions {
|
|
36
|
+
providerID?: string
|
|
37
|
+
baseURL?: string
|
|
38
|
+
apiKey?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** OpenAI-compatible adapter package used by the provider block in opencode.json(c). */
|
|
42
|
+
const ADAPTER = "aisdk:@ai-sdk/openai-compatible"
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Keep only chat-relevant models: LLMs that emit text output.
|
|
46
|
+
* Embeddings, OCR, decision, and image-generation models are skipped —
|
|
47
|
+
* they are not useful for OpenCode agents.
|
|
48
|
+
*/
|
|
49
|
+
function isChatModel(m: AifsModel): boolean {
|
|
50
|
+
return (
|
|
51
|
+
m.meta_data?.model_type === "LLM" &&
|
|
52
|
+
(m.meta_data.output_modalities ?? []).some((o) => o.toLowerCase() === "text")
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function toModelInfo(providerID: Provider.ID, m: AifsModel): Model.Info {
|
|
57
|
+
const id = Model.ID.make(m.id)
|
|
58
|
+
const base = Model.Info.default(providerID, id)
|
|
59
|
+
const stage = (m.meta_data.model_lifecycle_stage ?? "").toLowerCase()
|
|
60
|
+
const status: Model.Info["status"] = stage === "experimental" ? "beta" : "active"
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
...base,
|
|
64
|
+
name: m.meta_data.display_name || m.id,
|
|
65
|
+
type: "chat",
|
|
66
|
+
status,
|
|
67
|
+
// capabilities.tools defaults to true (Capabilities.default); AIFS /v2/models
|
|
68
|
+
// does not report tool-calling support. v2 of this plugin will fetch the
|
|
69
|
+
// `toolCalling` field from the public pricing page and override here.
|
|
70
|
+
capabilities: {
|
|
71
|
+
...base.capabilities,
|
|
72
|
+
input: (m.meta_data.input_modalities ?? []).map((s) => s.toLowerCase()),
|
|
73
|
+
output: (m.meta_data.output_modalities ?? []).map((s) => s.toLowerCase()),
|
|
74
|
+
},
|
|
75
|
+
limit: {
|
|
76
|
+
context: m.meta_data.max_sequence_length ?? base.limit.context,
|
|
77
|
+
output: m.meta_data.max_output_length ?? base.limit.output,
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export default Plugin.define({
|
|
83
|
+
id: "aifs",
|
|
84
|
+
async setup(ctx) {
|
|
85
|
+
const opts = (ctx.options ?? {}) as AifsPluginOptions
|
|
86
|
+
const providerID = Provider.ID.make(opts.providerID ?? "aifs")
|
|
87
|
+
const baseURL = opts.baseURL ?? process.env.AIFS_BASE_URL
|
|
88
|
+
const apiKey = opts.apiKey ?? process.env.AIFS_API_KEY
|
|
89
|
+
|
|
90
|
+
if (!baseURL || !apiKey) {
|
|
91
|
+
console.error(
|
|
92
|
+
"[opencode-aifs-provider] AIFS_BASE_URL and AIFS_API_KEY must be set (env or plugin options).",
|
|
93
|
+
)
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const url = `${baseURL.replace(/\/+$/, "")}/models`
|
|
98
|
+
|
|
99
|
+
let res: Response
|
|
100
|
+
try {
|
|
101
|
+
res = await fetch(url, { headers: { Authorization: `Bearer ${apiKey}` } })
|
|
102
|
+
} catch (err) {
|
|
103
|
+
console.error(`[opencode-aifs-provider] Failed to reach ${url}:`, err)
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
if (!res.ok) {
|
|
107
|
+
console.error(`[opencode-aifs-provider] ${url} returned ${res.status} ${res.statusText}`)
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const json = (await res.json()) as AifsResponse
|
|
112
|
+
if (!Array.isArray(json.data)) {
|
|
113
|
+
console.error("[opencode-aifs-provider] Response missing 'data' array")
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const models: Model.Info[] = json.data.filter(isChatModel).map((m) => toModelInfo(providerID, m))
|
|
118
|
+
|
|
119
|
+
console.log(
|
|
120
|
+
`[opencode-aifs-provider] Discovered ${models.length} chat models for provider "${opts.providerID ?? "aifs"}"`,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
await ctx.provider.transform((editor) => {
|
|
124
|
+
editor.models.set(providerID, models)
|
|
125
|
+
})
|
|
126
|
+
},
|
|
127
|
+
})
|