@2en/clawly-plugins 1.19.0 → 1.19.1
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 +41 -3
- package/package.json +1 -1
package/model-gateway-setup.ts
CHANGED
|
@@ -97,9 +97,47 @@ export function setupModelGateway(api: PluginApi): void {
|
|
|
97
97
|
const configPath = path.join(stateDir, 'openclaw.json')
|
|
98
98
|
const config = readOpenclawConfig(configPath)
|
|
99
99
|
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
// If provider already exists, check if extra models or aliases need updating
|
|
101
|
+
const existingProvider = (config.models as any)?.providers?.[PROVIDER_NAME]
|
|
102
|
+
if (existingProvider) {
|
|
103
|
+
let dirty = false
|
|
104
|
+
const existingModels: Array<{id: string}> = existingProvider.models ?? []
|
|
105
|
+
const existingIds = new Set(existingModels.map((m: {id: string}) => m.id))
|
|
106
|
+
|
|
107
|
+
// Append any missing extra models
|
|
108
|
+
for (const m of EXTRA_GATEWAY_MODELS) {
|
|
109
|
+
if (!existingIds.has(m.id)) {
|
|
110
|
+
existingModels.push({id: m.id, name: m.name, input: m.input} as any)
|
|
111
|
+
dirty = true
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Ensure aliases exist for all models
|
|
116
|
+
const agents = (config.agents ?? {}) as any
|
|
117
|
+
const defaults = agents.defaults ?? {}
|
|
118
|
+
const existingAliases: Record<string, {alias: string}> = defaults.models ?? {}
|
|
119
|
+
for (const m of EXTRA_GATEWAY_MODELS) {
|
|
120
|
+
const key = `${PROVIDER_NAME}/${m.id}`
|
|
121
|
+
if (!existingAliases[key]) {
|
|
122
|
+
existingAliases[key] = {alias: m.alias}
|
|
123
|
+
dirty = true
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (dirty) {
|
|
128
|
+
existingProvider.models = existingModels
|
|
129
|
+
defaults.models = existingAliases
|
|
130
|
+
agents.defaults = defaults
|
|
131
|
+
config.agents = agents
|
|
132
|
+
try {
|
|
133
|
+
writeOpenclawConfig(configPath, config)
|
|
134
|
+
api.logger.info(`Model gateway updated: appended missing extra models/aliases.`)
|
|
135
|
+
} catch (err) {
|
|
136
|
+
api.logger.error(`Failed to update model gateway: ${(err as Error).message}`)
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
api.logger.info('Model gateway provider already configured.')
|
|
140
|
+
}
|
|
103
141
|
return
|
|
104
142
|
}
|
|
105
143
|
|