@2en/clawly-plugins 1.19.0 → 1.19.2

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.
@@ -78,16 +78,6 @@ export function writeOpenclawConfig(configPath: string, config: Record<string, u
78
78
  }
79
79
 
80
80
  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
81
  const stateDir = resolveStateDir(api)
92
82
  if (!stateDir) {
93
83
  api.logger.warn('Cannot resolve state dir — model gateway setup skipped.')
@@ -97,9 +87,60 @@ export function setupModelGateway(api: PluginApi): void {
97
87
  const configPath = path.join(stateDir, 'openclaw.json')
98
88
  const config = readOpenclawConfig(configPath)
99
89
 
100
- // Already configured skip
101
- if (config.models?.providers?.[PROVIDER_NAME]) {
102
- api.logger.info('Model gateway provider already configured.')
90
+ // If provider already exists, check if extra models or aliases need updating.
91
+ // This runs before the credentials check because provisioned sprites have
92
+ // credentials in openclaw.json directly, not in pluginConfig.
93
+ const existingProvider = (config.models as any)?.providers?.[PROVIDER_NAME]
94
+ if (existingProvider) {
95
+ let dirty = false
96
+ const existingModels: Array<{id: string}> = existingProvider.models ?? []
97
+ const existingIds = new Set(existingModels.map((m: {id: string}) => m.id))
98
+
99
+ // Append any missing extra models
100
+ for (const m of EXTRA_GATEWAY_MODELS) {
101
+ if (!existingIds.has(m.id)) {
102
+ existingModels.push({id: m.id, name: m.name, input: m.input} as any)
103
+ dirty = true
104
+ }
105
+ }
106
+
107
+ // Ensure aliases exist for all models
108
+ const agents = (config.agents ?? {}) as any
109
+ const defaults = agents.defaults ?? {}
110
+ const existingAliases: Record<string, {alias: string}> = defaults.models ?? {}
111
+ for (const m of EXTRA_GATEWAY_MODELS) {
112
+ const key = `${PROVIDER_NAME}/${m.id}`
113
+ if (!existingAliases[key]) {
114
+ existingAliases[key] = {alias: m.alias}
115
+ dirty = true
116
+ }
117
+ }
118
+
119
+ if (dirty) {
120
+ existingProvider.models = existingModels
121
+ defaults.models = existingAliases
122
+ agents.defaults = defaults
123
+ config.agents = agents
124
+ try {
125
+ writeOpenclawConfig(configPath, config)
126
+ api.logger.info(`Model gateway updated: appended missing extra models/aliases.`)
127
+ } catch (err) {
128
+ api.logger.error(`Failed to update model gateway: ${(err as Error).message}`)
129
+ }
130
+ } else {
131
+ api.logger.info('Model gateway provider already configured.')
132
+ }
133
+ return
134
+ }
135
+
136
+ // No existing provider — need pluginConfig credentials to create one
137
+ const cfg = api.pluginConfig as Record<string, unknown> | undefined
138
+ const baseUrl =
139
+ typeof cfg?.modelGatewayBaseUrl === 'string' ? cfg.modelGatewayBaseUrl.replace(/\/$/, '') : ''
140
+ const token = typeof cfg?.modelGatewayToken === 'string' ? cfg.modelGatewayToken : ''
141
+
142
+ if (!baseUrl || !token) {
143
+ api.logger.info('Model gateway not configured (missing baseUrl or token), skipping.')
103
144
  return
104
145
  }
105
146
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2en/clawly-plugins",
3
- "version": "1.19.0",
3
+ "version": "1.19.2",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "repository": {