openclaw-plugin-model-fetch 0.2.4 → 0.2.6

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.
@@ -308,6 +308,9 @@ export function mergeModels({ existing, selected, filter, }) {
308
308
  selectedIds,
309
309
  };
310
310
  }
311
+ function asOptionalRecord(value) {
312
+ return isRecord(value) ? value : undefined;
313
+ }
311
314
  function readModelRefScalar(value, path, visit) {
312
315
  if (typeof value !== "string")
313
316
  return;
@@ -332,43 +335,47 @@ function readModelRefSetting(value, path, visit) {
332
335
  }
333
336
  /**
334
337
  * Walks the explicit model references that live outside the agent allowlist and
335
- * agent `models` sync: utility/decision models, media, voice, pdf, embedded agent
336
- * cyber failover, and hook models. Deleting a model named here would leave a
337
- * dangling `provider/model` reference behind.
338
+ * agent `models` sync. Those two collections are reconciled separately by the
339
+ * apply operation; deleting a model named here would leave a dangling
340
+ * `provider/model` reference behind.
338
341
  */
339
342
  function forEachExplicitModelReference(config, visit) {
340
343
  if (!isRecord(config))
341
344
  return;
342
- const agents = isRecord(config.agents) ? config.agents : undefined;
343
- const defaults = agents && isRecord(agents.defaults) ? agents.defaults : undefined;
344
- if (defaults) {
345
- readModelRefScalar(defaults.utilityModel, "agents.defaults.utilityModel", visit);
346
- readModelRefScalar(defaults.decisionModel, "agents.defaults.decisionModel", visit);
347
- readModelRefSetting(defaults.imageModel, "agents.defaults.imageModel", visit);
348
- readModelRefSetting(defaults.voiceModel, "agents.defaults.voiceModel", visit);
349
- readModelRefSetting(defaults.pdfModel, "agents.defaults.pdfModel", visit);
350
- if (isRecord(defaults.mediaModels)) {
351
- readModelRefSetting(defaults.mediaModels.image, "agents.defaults.mediaModels.image", visit);
352
- readModelRefSetting(defaults.mediaModels.video, "agents.defaults.mediaModels.video", visit);
353
- readModelRefSetting(defaults.mediaModels.music, "agents.defaults.mediaModels.music", visit);
354
- }
355
- const embeddedAgent = isRecord(defaults.embeddedAgent) ? defaults.embeddedAgent : undefined;
356
- if (embeddedAgent && isRecord(embeddedAgent.cyberFailover)) {
357
- readModelRefScalar(embeddedAgent.cyberFailover.model, "agents.defaults.embeddedAgent.cyberFailover.model", visit);
345
+ const tools = isRecord(config.tools) ? config.tools : undefined;
346
+ if (tools) {
347
+ const exec = asOptionalRecord(tools.exec);
348
+ const reviewer = asOptionalRecord(exec?.reviewer);
349
+ readModelRefSetting(reviewer?.model, "tools.exec.reviewer.model", visit);
350
+ if (isRecord(tools.media)) {
351
+ for (const capability of ["image", "audio", "video"]) {
352
+ readModelRefScalar(asOptionalRecord(tools.media[capability])?.preferredModel, `tools.media.${capability}.preferredModel`, visit);
353
+ }
358
354
  }
359
355
  }
360
- const entries = agents && isRecord(agents.entries) ? agents.entries : undefined;
361
- if (entries) {
362
- for (const agentId of Object.keys(entries).sort((left, right) => left.localeCompare(right))) {
363
- if (agentId.includes("."))
364
- continue;
365
- const entry = entries[agentId];
366
- if (!isRecord(entry))
367
- continue;
368
- readModelRefScalar(entry.utilityModel, `agents.entries.${agentId}.utilityModel`, visit);
369
- readModelRefScalar(entry.decisionModel, `agents.entries.${agentId}.decisionModel`, visit);
356
+ const agents = isRecord(config.agents) ? config.agents : undefined;
357
+ const defaults = asOptionalRecord(agents?.defaults);
358
+ if (defaults)
359
+ visitAgentModelReferences("agents.defaults", defaults, false, visit);
360
+ if (agents && isRecord(agents.entries)) {
361
+ for (const agentId of Object.keys(agents.entries).sort((left, right) => left.localeCompare(right))) {
362
+ const entry = agents.entries[agentId];
363
+ if (isRecord(entry)) {
364
+ visitAgentModelReferences(`agents.entries.${agentId}`, entry, true, visit);
365
+ }
370
366
  }
371
367
  }
368
+ else if (agents && Array.isArray(agents.list)) {
369
+ agents.list.forEach((entry, index) => {
370
+ if (isRecord(entry)) {
371
+ visitAgentModelReferences(`agents.list[${index}]`, entry, true, visit);
372
+ }
373
+ });
374
+ }
375
+ const tts = asOptionalRecord(config.tts);
376
+ if (tts) {
377
+ readModelRefSetting(tts.summaryModel, "tts.summaryModel", visit);
378
+ }
372
379
  const hooks = isRecord(config.hooks) ? config.hooks : undefined;
373
380
  if (hooks) {
374
381
  if (isRecord(hooks.gmail)) {
@@ -382,6 +389,66 @@ function forEachExplicitModelReference(config, visit) {
382
389
  });
383
390
  }
384
391
  }
392
+ const channels = isRecord(config.channels) ? config.channels : undefined;
393
+ if (channels) {
394
+ const modelByChannel = isRecord(channels.modelByChannel) ? channels.modelByChannel : undefined;
395
+ if (modelByChannel) {
396
+ for (const channelId of Object.keys(modelByChannel).sort((left, right) => left.localeCompare(right))) {
397
+ const channelMap = modelByChannel[channelId];
398
+ if (!isRecord(channelMap))
399
+ continue;
400
+ for (const targetId of Object.keys(channelMap).sort((left, right) => left.localeCompare(right))) {
401
+ readModelRefSetting(channelMap[targetId], `channels.modelByChannel.${channelId}.${targetId}`, visit);
402
+ }
403
+ }
404
+ }
405
+ const discord = isRecord(channels.discord) ? channels.discord : undefined;
406
+ if (discord) {
407
+ visitDiscordVoiceModelReferences("channels.discord.voice", discord.voice, visit);
408
+ if (isRecord(discord.accounts)) {
409
+ for (const accountId of Object.keys(discord.accounts).sort((left, right) => left.localeCompare(right))) {
410
+ visitDiscordVoiceModelReferences(`channels.discord.accounts.${accountId}.voice`, asOptionalRecord(discord.accounts[accountId])?.voice, visit);
411
+ }
412
+ }
413
+ }
414
+ }
415
+ }
416
+ function visitAgentModelReferences(path, agent, includeEntrySelectors, visit) {
417
+ readModelRefSetting(agent.model, `${path}.model`, visit);
418
+ readModelRefScalar(agent.utilityModel, `${path}.utilityModel`, visit);
419
+ readModelRefScalar(agent.decisionModel, `${path}.decisionModel`, visit);
420
+ readModelRefSetting(agent.imageModel, `${path}.imageModel`, visit);
421
+ readModelRefSetting(agent.voiceModel, `${path}.voiceModel`, visit);
422
+ readModelRefSetting(agent.pdfModel, `${path}.pdfModel`, visit);
423
+ const mediaModels = asOptionalRecord(agent.mediaModels);
424
+ if (mediaModels) {
425
+ for (const capability of ["image", "video", "music"]) {
426
+ readModelRefSetting(mediaModels[capability], `${path}.mediaModels.${capability}`, visit);
427
+ }
428
+ }
429
+ const cyberFailover = asOptionalRecord(asOptionalRecord(agent.embeddedAgent)?.cyberFailover);
430
+ if (cyberFailover) {
431
+ readModelRefSetting(cyberFailover.model, `${path}.embeddedAgent.cyberFailover.model`, visit);
432
+ }
433
+ readModelRefSetting(asOptionalRecord(agent.heartbeat)?.model, `${path}.heartbeat.model`, visit);
434
+ readModelRefSetting(asOptionalRecord(agent.subagents)?.model, `${path}.subagents.model`, visit);
435
+ const compaction = asOptionalRecord(agent.compaction);
436
+ if (compaction) {
437
+ readModelRefSetting(compaction.model, `${path}.compaction.model`, visit);
438
+ readModelRefSetting(asOptionalRecord(compaction.memoryFlush)?.model, `${path}.compaction.memoryFlush.model`, visit);
439
+ }
440
+ if (!includeEntrySelectors)
441
+ return;
442
+ const exec = asOptionalRecord(asOptionalRecord(agent.tools)?.exec);
443
+ readModelRefSetting(asOptionalRecord(exec?.reviewer)?.model, `${path}.tools.exec.reviewer.model`, visit);
444
+ readModelRefSetting(asOptionalRecord(agent.tts)?.summaryModel, `${path}.tts.summaryModel`, visit);
445
+ }
446
+ function visitDiscordVoiceModelReferences(path, voice, visit) {
447
+ const voiceConfig = asOptionalRecord(voice);
448
+ if (!voiceConfig)
449
+ return;
450
+ readModelRefSetting(voiceConfig.model, `${path}.model`, visit);
451
+ readModelRefSetting(asOptionalRecord(voiceConfig.tts)?.summaryModel, `${path}.tts.summaryModel`, visit);
385
452
  }
386
453
  /**
387
454
  * Reports which of `modelIds` are still named by a non-agent model consumer,
@@ -3,6 +3,34 @@ import { Value } from "typebox/value";
3
3
  import { getSessionEntryAsync, listSessionEntries, patchSessionEntry, } from "openclaw/plugin-sdk/session-store-runtime";
4
4
  import { modelFetchContract } from "./contract.js";
5
5
  import { applyModelReferenceProtection, collectModelReferenceUsages, fetchProviderModels, getProvider, mergeModels, resolveApiKey, resolveProviderFilter, resolveProviderTargetAgents, runModelFetch, selectFetchedModels, syncAgentModelEntries, syncConfiguredModelPolicyAllow, } from "./model-fetch.js";
6
+ /**
7
+ * The host exposes a single-attempt config mutation to plugins, so a write
8
+ * that loses the race against another writer (for example an OpenClaw upgrade
9
+ * rewriting the config file) fails outright. The host's own config writer
10
+ * retries these conflicts, so mirror that behaviour here.
11
+ */
12
+ const CONFIG_MUTATION_MAX_ATTEMPTS = 5;
13
+ function isRetryableConfigConflict(error) {
14
+ if (!(error instanceof Error))
15
+ return false;
16
+ if (error.name !== "ConfigMutationConflictError")
17
+ return false;
18
+ return error.retryable !== false;
19
+ }
20
+ async function mutateConfigFileWithRetry(runtime, params) {
21
+ let lastError;
22
+ for (let attempt = 0; attempt < CONFIG_MUTATION_MAX_ATTEMPTS; attempt += 1) {
23
+ try {
24
+ return await runtime.config.mutateConfigFile(params);
25
+ }
26
+ catch (error) {
27
+ lastError = error;
28
+ if (!isRetryableConfigConflict(error))
29
+ throw error;
30
+ }
31
+ }
32
+ throw lastError;
33
+ }
6
34
  const AFFECTED_SESSION_LIMIT = 2_000;
7
35
  const DEFAULT_AGENT_ID = "main";
8
36
  function isRecord(value) {
@@ -438,7 +466,7 @@ export function createModelFetchOperations({ api, factoryConfig, fetchModels = f
438
466
  const nextTargetAgents = targetAgents === undefined
439
467
  ? savedTargetAgents(provider, config)
440
468
  : normalizeTargetAgents(targetAgents);
441
- const result = await runtime.config.mutateConfigFile({
469
+ const result = await mutateConfigFileWithRetry(runtime, {
442
470
  base: "source",
443
471
  afterWrite: { mode: "auto" },
444
472
  mutate: (draft) => {
@@ -487,7 +515,7 @@ export function createModelFetchOperations({ api, factoryConfig, fetchModels = f
487
515
  }
488
516
  const nextTargetAgents = normalizeTargetAgents(targetAgents ?? savedTargetAgents(provider));
489
517
  let syncedAgents = [];
490
- const result = await runtime.config.mutateConfigFile({
518
+ const result = await mutateConfigFileWithRetry(runtime, {
491
519
  base: "source",
492
520
  afterWrite: { mode: "auto" },
493
521
  mutate: (draft) => {
@@ -2,7 +2,7 @@
2
2
  "id": "model-fetch",
3
3
  "name": "Model Fetch",
4
4
  "description": "Fetch and refresh configured provider model lists into OpenClaw config with independent per-provider filters.",
5
- "version": "0.2.4",
5
+ "version": "0.2.6",
6
6
  "configSchema": {
7
7
  "type": "object",
8
8
  "properties": {
@@ -60,10 +60,14 @@
60
60
  "activation": {
61
61
  "onStartup": true
62
62
  },
63
+ "uiCapabilities": [
64
+ "page",
65
+ "navigation"
66
+ ],
63
67
  "controlUi": {
64
- "entry": "dist/control-ui/19f1eb3db914391c2d26d2ce107c2db20a661d83717d99fa2e32c280a7de9204/index.js",
68
+ "entry": "dist/control-ui/3c4f0a9bd18e23199c1dfcdf9de58e7b0594e1654697f13214b5b9f800cbd5c8/index.js",
65
69
  "styles": [
66
- "dist/control-ui/19f1eb3db914391c2d26d2ce107c2db20a661d83717d99fa2e32c280a7de9204/index.css"
70
+ "dist/control-ui/3c4f0a9bd18e23199c1dfcdf9de58e7b0594e1654697f13214b5b9f800cbd5c8/index.css"
67
71
  ]
68
72
  },
69
73
  "contracts": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-plugin-model-fetch",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "OpenClaw plugin tool that refreshes configured provider model lists into OpenClaw config with independent per-provider filters.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -52,7 +52,7 @@
52
52
  "devDependencies": {
53
53
  "esbuild": "^0.28.2",
54
54
  "linkedom": "^0.18.13",
55
- "openclaw": "latest",
55
+ "openclaw": "2026.10.10",
56
56
  "typescript": "7.0.2",
57
57
  "vitest": "^3.2.0"
58
58
  },