openclaw-aicodewith-auth 0.3.6 → 0.3.8

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.
Files changed (2) hide show
  1. package/index.ts +42 -0
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
2
+ import { readFileSync, writeFileSync, existsSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { homedir } from "node:os";
2
5
  import {
3
6
  PLUGIN_ID,
4
7
  PLUGIN_NAME,
@@ -169,12 +172,51 @@ function migrateConfig(config: Record<string, unknown>): { config: Record<string
169
172
  return { config, changed };
170
173
  }
171
174
 
175
+ function cleanupStaleModelEntries(): void {
176
+ try {
177
+ const configPath = join(homedir(), ".openclaw", "openclaw.json");
178
+ if (!existsSync(configPath)) return;
179
+
180
+ const raw = readFileSync(configPath, "utf8");
181
+ const config = JSON.parse(raw) as Record<string, unknown>;
182
+
183
+ const agents = config.agents as Record<string, unknown> | undefined;
184
+ const defaults = agents?.defaults as Record<string, unknown> | undefined;
185
+ const modelsConfig = defaults?.models as Record<string, unknown> | undefined;
186
+ if (!modelsConfig) return;
187
+
188
+ const providerConfigs = buildProviderConfigs();
189
+ const activeKeys = new Set<string>();
190
+ for (const providerId of [PROVIDER_ID_GPT, PROVIDER_ID_CLAUDE, PROVIDER_ID_GEMINI] as const) {
191
+ for (const model of providerConfigs[providerId].models) {
192
+ activeKeys.add(`${providerId}/${model.id}`);
193
+ }
194
+ }
195
+
196
+ let changed = false;
197
+ for (const key of Object.keys(modelsConfig)) {
198
+ if (key.startsWith("aicodewith-") && !activeKeys.has(key)) {
199
+ delete modelsConfig[key];
200
+ changed = true;
201
+ }
202
+ }
203
+
204
+ if (changed) {
205
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
206
+ }
207
+ } catch {
208
+ // Config cleanup is best-effort; don't break plugin loading
209
+ }
210
+ }
211
+
172
212
  const aicodewithPlugin = {
173
213
  id: PLUGIN_ID,
174
214
  name: PLUGIN_NAME,
175
215
  description: PLUGIN_DESCRIPTION,
176
216
  configSchema: emptyPluginConfigSchema(),
177
217
  register(api: PluginApi) {
218
+ cleanupStaleModelEntries();
219
+
178
220
  api.on("gateway_start", async () => {
179
221
  try {
180
222
  const config = api.runtime.config.loadConfig();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-aicodewith-auth",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "type": "module",
5
5
  "description": "AICodewith provider plugin for OpenClaw - Access GPT, Claude, and Gemini models via AICodewith API",
6
6
  "author": "daneel",