@2en/clawly-plugins 1.19.1 → 1.20.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/model-gateway-setup.ts +30 -15
- package/package.json +1 -1
package/model-gateway-setup.ts
CHANGED
|
@@ -23,6 +23,12 @@ export const EXTRA_GATEWAY_MODELS: Array<{
|
|
|
23
23
|
alias: string
|
|
24
24
|
input: string[]
|
|
25
25
|
}> = [
|
|
26
|
+
{
|
|
27
|
+
id: 'moonshotai/kimi-k2.5',
|
|
28
|
+
name: 'moonshotai/kimi-k2.5',
|
|
29
|
+
alias: 'Kimi K2.5',
|
|
30
|
+
input: ['text', 'image'],
|
|
31
|
+
},
|
|
26
32
|
{
|
|
27
33
|
id: 'anthropic/claude-sonnet-4.6',
|
|
28
34
|
name: 'anthropic/claude-sonnet-4.6',
|
|
@@ -78,16 +84,6 @@ export function writeOpenclawConfig(configPath: string, config: Record<string, u
|
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
export function setupModelGateway(api: PluginApi): void {
|
|
81
|
-
const cfg = api.pluginConfig as Record<string, unknown> | undefined
|
|
82
|
-
const baseUrl =
|
|
83
|
-
typeof cfg?.modelGatewayBaseUrl === 'string' ? cfg.modelGatewayBaseUrl.replace(/\/$/, '') : ''
|
|
84
|
-
const token = typeof cfg?.modelGatewayToken === 'string' ? cfg.modelGatewayToken : ''
|
|
85
|
-
|
|
86
|
-
if (!baseUrl || !token) {
|
|
87
|
-
api.logger.info('Model gateway not configured (missing baseUrl or token), skipping.')
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
|
|
91
87
|
const stateDir = resolveStateDir(api)
|
|
92
88
|
if (!stateDir) {
|
|
93
89
|
api.logger.warn('Cannot resolve state dir — model gateway setup skipped.')
|
|
@@ -97,7 +93,9 @@ export function setupModelGateway(api: PluginApi): void {
|
|
|
97
93
|
const configPath = path.join(stateDir, 'openclaw.json')
|
|
98
94
|
const config = readOpenclawConfig(configPath)
|
|
99
95
|
|
|
100
|
-
// If provider already exists, check if extra models or aliases need updating
|
|
96
|
+
// If provider already exists, check if extra models or aliases need updating.
|
|
97
|
+
// This runs before the credentials check because provisioned sprites have
|
|
98
|
+
// credentials in openclaw.json directly, not in pluginConfig.
|
|
101
99
|
const existingProvider = (config.models as any)?.providers?.[PROVIDER_NAME]
|
|
102
100
|
if (existingProvider) {
|
|
103
101
|
let dirty = false
|
|
@@ -112,14 +110,15 @@ export function setupModelGateway(api: PluginApi): void {
|
|
|
112
110
|
}
|
|
113
111
|
}
|
|
114
112
|
|
|
115
|
-
// Ensure aliases exist for
|
|
113
|
+
// Ensure aliases exist for ALL models (existing + extras)
|
|
116
114
|
const agents = (config.agents ?? {}) as any
|
|
117
115
|
const defaults = agents.defaults ?? {}
|
|
118
116
|
const existingAliases: Record<string, {alias: string}> = defaults.models ?? {}
|
|
119
|
-
for (const m of
|
|
117
|
+
for (const m of existingModels) {
|
|
120
118
|
const key = `${PROVIDER_NAME}/${m.id}`
|
|
121
119
|
if (!existingAliases[key]) {
|
|
122
|
-
|
|
120
|
+
const extra = EXTRA_GATEWAY_MODELS.find((e) => e.id === m.id)
|
|
121
|
+
existingAliases[key] = {alias: extra?.alias ?? m.id}
|
|
123
122
|
dirty = true
|
|
124
123
|
}
|
|
125
124
|
}
|
|
@@ -141,6 +140,17 @@ export function setupModelGateway(api: PluginApi): void {
|
|
|
141
140
|
return
|
|
142
141
|
}
|
|
143
142
|
|
|
143
|
+
// No existing provider — need pluginConfig credentials to create one
|
|
144
|
+
const cfg = api.pluginConfig as Record<string, unknown> | undefined
|
|
145
|
+
const baseUrl =
|
|
146
|
+
typeof cfg?.modelGatewayBaseUrl === 'string' ? cfg.modelGatewayBaseUrl.replace(/\/$/, '') : ''
|
|
147
|
+
const token = typeof cfg?.modelGatewayToken === 'string' ? cfg.modelGatewayToken : ''
|
|
148
|
+
|
|
149
|
+
if (!baseUrl || !token) {
|
|
150
|
+
api.logger.info('Model gateway not configured (missing baseUrl or token), skipping.')
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
|
|
144
154
|
// Derive model IDs from agents.defaults
|
|
145
155
|
const defaultModelFull: string = (config.agents as any)?.defaults?.model?.primary ?? ''
|
|
146
156
|
const imageModelFull: string = (config.agents as any)?.defaults?.imageModel?.primary ?? ''
|
|
@@ -166,9 +176,14 @@ export function setupModelGateway(api: PluginApi): void {
|
|
|
166
176
|
{id: imageModel, name: imageModel, input: ['text', 'image']},
|
|
167
177
|
]
|
|
168
178
|
|
|
179
|
+
const defaultIds = new Set(defaultModels.map((m) => m.id))
|
|
169
180
|
const models = [
|
|
170
181
|
...defaultModels,
|
|
171
|
-
...EXTRA_GATEWAY_MODELS.map(({id, name, input}) => ({
|
|
182
|
+
...EXTRA_GATEWAY_MODELS.filter((m) => !defaultIds.has(m.id)).map(({id, name, input}) => ({
|
|
183
|
+
id,
|
|
184
|
+
name,
|
|
185
|
+
input,
|
|
186
|
+
})),
|
|
172
187
|
]
|
|
173
188
|
|
|
174
189
|
if (!config.models) config.models = {}
|