openclaw-plugin-model-fetch 0.2.6 → 0.2.7

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.
@@ -413,6 +413,167 @@ function forEachExplicitModelReference(config, visit) {
413
413
  }
414
414
  }
415
415
  }
416
+ /**
417
+ * Rewrites the explicit model references that name `fromRef` to `toRef`.
418
+ *
419
+ * The reference collector only reads, so the walk is repeated here with a
420
+ * writable setter. `forEachExplicitModelReference` reports the exact path of
421
+ * every reference it finds, so the setter mirrors that path shape.
422
+ */
423
+ export function rewriteModelReferences(draft, fromRef, toRef) {
424
+ if (!isRecord(draft))
425
+ return { changed: false, paths: [] };
426
+ const source = fromRef.trim();
427
+ const target = toRef.trim();
428
+ if (!source || !target || source === target)
429
+ return { changed: false, paths: [] };
430
+ const changed = [];
431
+ const writeScalar = (container, field, basePath) => {
432
+ if (!isRecord(container))
433
+ return;
434
+ const current = container[field];
435
+ if (typeof current !== "string" || current.trim() !== source)
436
+ return;
437
+ container[field] = target;
438
+ changed.push(`${basePath}.${field}`);
439
+ };
440
+ const writeSetting = (container, field, basePath) => {
441
+ if (!isRecord(container))
442
+ return;
443
+ const current = container[field];
444
+ if (typeof current === "string") {
445
+ if (current.trim() !== source)
446
+ return;
447
+ container[field] = target;
448
+ changed.push(`${basePath}.${field}`);
449
+ return;
450
+ }
451
+ if (!isRecord(current))
452
+ return;
453
+ if (typeof current.primary === "string" && current.primary.trim() === source) {
454
+ current.primary = target;
455
+ changed.push(`${basePath}.${field}.primary`);
456
+ }
457
+ const fallbacks = current.fallbacks;
458
+ if (!Array.isArray(fallbacks))
459
+ return;
460
+ fallbacks.forEach((fallback, index) => {
461
+ if (typeof fallback !== "string" || fallback.trim() !== source)
462
+ return;
463
+ fallbacks[index] = target;
464
+ changed.push(`${basePath}.${field}.fallbacks[${index}]`);
465
+ });
466
+ };
467
+ const tools = isRecord(draft.tools) ? draft.tools : undefined;
468
+ if (tools) {
469
+ const exec = asOptionalRecord(tools.exec);
470
+ const reviewer = asOptionalRecord(exec?.reviewer);
471
+ if (isRecord(reviewer))
472
+ writeSetting(reviewer, "model", "tools.exec.reviewer");
473
+ if (isRecord(tools.media)) {
474
+ for (const capability of ["image", "audio", "video"]) {
475
+ const media = asOptionalRecord(tools.media[capability]);
476
+ if (!media)
477
+ continue;
478
+ writeScalar(media, "preferredModel", `tools.media.${capability}`);
479
+ }
480
+ }
481
+ }
482
+ const agents = isRecord(draft.agents) ? draft.agents : undefined;
483
+ const defaults = asOptionalRecord(agents?.defaults);
484
+ if (defaults)
485
+ rewriteAgentModelReferences(defaults, "agents.defaults", false, writeScalar, writeSetting);
486
+ if (agents && isRecord(agents.entries)) {
487
+ for (const agentId of Object.keys(agents.entries).sort((left, right) => left.localeCompare(right))) {
488
+ const entry = agents.entries[agentId];
489
+ if (!isRecord(entry))
490
+ continue;
491
+ rewriteAgentModelReferences(entry, `agents.entries.${agentId}`, true, writeScalar, writeSetting);
492
+ }
493
+ }
494
+ else if (agents && Array.isArray(agents.list)) {
495
+ agents.list.forEach((entry, index) => {
496
+ if (!isRecord(entry))
497
+ return;
498
+ rewriteAgentModelReferences(entry, `agents.list[${index}]`, true, writeScalar, writeSetting);
499
+ });
500
+ }
501
+ const tts = asOptionalRecord(draft.tts);
502
+ if (tts)
503
+ writeSetting(tts, "summaryModel", "tts");
504
+ const hooks = isRecord(draft.hooks) ? draft.hooks : undefined;
505
+ if (hooks) {
506
+ if (isRecord(hooks.gmail))
507
+ writeScalar(hooks.gmail, "model", "hooks.gmail");
508
+ if (Array.isArray(hooks.mappings)) {
509
+ hooks.mappings.forEach((mapping, index) => {
510
+ if (!isRecord(mapping))
511
+ return;
512
+ writeScalar(mapping, "model", `hooks.mappings[${index}]`);
513
+ });
514
+ }
515
+ }
516
+ const channels = isRecord(draft.channels) ? draft.channels : undefined;
517
+ if (channels) {
518
+ const modelByChannel = isRecord(channels.modelByChannel) ? channels.modelByChannel : undefined;
519
+ if (modelByChannel) {
520
+ for (const channelId of Object.keys(modelByChannel).sort((left, right) => left.localeCompare(right))) {
521
+ const channelMap = modelByChannel[channelId];
522
+ if (!isRecord(channelMap))
523
+ continue;
524
+ for (const targetId of Object.keys(channelMap).sort((left, right) => left.localeCompare(right))) {
525
+ writeSetting(channelMap, targetId, `channels.modelByChannel.${channelId}`);
526
+ }
527
+ }
528
+ }
529
+ const discord = asOptionalRecord(channels.discord);
530
+ if (discord) {
531
+ rewriteDiscordVoiceModelReferences(discord.voice, "channels.discord.voice", writeScalar, writeSetting);
532
+ if (isRecord(discord.accounts)) {
533
+ for (const accountId of Object.keys(discord.accounts).sort((left, right) => left.localeCompare(right))) {
534
+ rewriteDiscordVoiceModelReferences(asOptionalRecord(discord.accounts[accountId])?.voice, `channels.discord.accounts.${accountId}.voice`, writeScalar, writeSetting);
535
+ }
536
+ }
537
+ }
538
+ }
539
+ return { changed: changed.length > 0, paths: changed.sort((left, right) => left.localeCompare(right)) };
540
+ }
541
+ function rewriteAgentModelReferences(agent, basePath, includeEntrySelectors, writeScalar, writeSetting) {
542
+ writeSetting(agent, "model", basePath);
543
+ writeScalar(agent, "utilityModel", basePath);
544
+ writeScalar(agent, "decisionModel", basePath);
545
+ writeSetting(agent, "imageModel", basePath);
546
+ writeSetting(agent, "voiceModel", basePath);
547
+ writeSetting(agent, "pdfModel", basePath);
548
+ const mediaModels = asOptionalRecord(agent.mediaModels);
549
+ if (mediaModels) {
550
+ for (const capability of ["image", "video", "music"]) {
551
+ writeSetting(mediaModels, capability, `${basePath}.mediaModels`);
552
+ }
553
+ }
554
+ const cyberFailover = asOptionalRecord(asOptionalRecord(agent.embeddedAgent)?.cyberFailover);
555
+ if (cyberFailover)
556
+ writeSetting(cyberFailover, "model", `${basePath}.embeddedAgent.cyberFailover`);
557
+ writeSetting(asOptionalRecord(agent.heartbeat), "model", `${basePath}.heartbeat`);
558
+ writeSetting(asOptionalRecord(agent.subagents), "model", `${basePath}.subagents`);
559
+ const compaction = asOptionalRecord(agent.compaction);
560
+ if (compaction) {
561
+ writeSetting(compaction, "model", `${basePath}.compaction`);
562
+ writeSetting(asOptionalRecord(compaction.memoryFlush), "model", `${basePath}.compaction.memoryFlush`);
563
+ }
564
+ if (!includeEntrySelectors)
565
+ return;
566
+ const exec = asOptionalRecord(asOptionalRecord(agent.tools)?.exec);
567
+ writeSetting(asOptionalRecord(exec?.reviewer), "model", `${basePath}.tools.exec.reviewer`);
568
+ writeSetting(asOptionalRecord(agent.tts), "summaryModel", `${basePath}.tts`);
569
+ }
570
+ function rewriteDiscordVoiceModelReferences(voice, basePath, writeScalar, writeSetting) {
571
+ const voiceConfig = asOptionalRecord(voice);
572
+ if (!voiceConfig)
573
+ return;
574
+ writeSetting(voiceConfig, "model", basePath);
575
+ writeSetting(asOptionalRecord(voiceConfig.tts), "summaryModel", `${basePath}.tts`);
576
+ }
416
577
  function visitAgentModelReferences(path, agent, includeEntrySelectors, visit) {
417
578
  readModelRefSetting(agent.model, `${path}.model`, visit);
418
579
  readModelRefScalar(agent.utilityModel, `${path}.utilityModel`, visit);
@@ -507,6 +668,85 @@ export function applyModelReferenceProtection({ existing, merged, providerId, co
507
668
  }
508
669
  return { models, protectedModels };
509
670
  }
671
+ /**
672
+ * Finds removal candidates that only differ from a surviving model by letter
673
+ * case.
674
+ *
675
+ * A provider list can hold both `auto/MiniMax-M3` and `auto/minimax-m3`. The
676
+ * filter keeps one of them and drops the other, so the two entries point at
677
+ * the same remote model and the deletion plan can say so instead of leaving
678
+ * the user with two look-alike ids.
679
+ */
680
+ export function collectCaseVariantRelations(removedIds, survivingIds) {
681
+ const byLowerId = new Map();
682
+ for (const id of survivingIds) {
683
+ const key = id.toLowerCase();
684
+ const bucket = byLowerId.get(key);
685
+ if (bucket)
686
+ bucket.push(id);
687
+ else
688
+ byLowerId.set(key, [id]);
689
+ }
690
+ const relations = [];
691
+ for (const removedId of removedIds) {
692
+ const bucket = byLowerId.get(removedId.toLowerCase());
693
+ if (!bucket)
694
+ continue;
695
+ const match = bucket.find((id) => id !== removedId);
696
+ if (!match)
697
+ continue;
698
+ relations.push({ removedId, survivingModelId: match });
699
+ }
700
+ return relations.sort((left, right) => left.removedId.localeCompare(right.removedId));
701
+ }
702
+ /**
703
+ * The model OpenClaw falls back to when an agent has no explicit selection.
704
+ *
705
+ * Agents can override the default, so the first agent that names a primary
706
+ * model wins. The value is the bare `provider/model` reference.
707
+ */
708
+ export function resolveDefaultModelRef(config) {
709
+ if (!isRecord(config))
710
+ return undefined;
711
+ const agents = isRecord(config.agents) ? config.agents : undefined;
712
+ if (!agents)
713
+ return undefined;
714
+ const readPrimary = (agent) => {
715
+ if (!isRecord(agent))
716
+ return undefined;
717
+ const model = agent.model;
718
+ if (typeof model === "string") {
719
+ const trimmed = model.trim();
720
+ return trimmed ? trimmed : undefined;
721
+ }
722
+ if (!isRecord(model))
723
+ return undefined;
724
+ const primary = model.primary;
725
+ if (typeof primary !== "string")
726
+ return undefined;
727
+ const trimmed = primary.trim();
728
+ return trimmed ? trimmed : undefined;
729
+ };
730
+ const defaults = asOptionalRecord(agents.defaults);
731
+ const defaultPrimary = readPrimary(defaults);
732
+ if (defaultPrimary)
733
+ return defaultPrimary;
734
+ if (isRecord(agents.entries)) {
735
+ for (const agentId of Object.keys(agents.entries).sort((left, right) => left.localeCompare(right))) {
736
+ const primary = readPrimary(agents.entries[agentId]);
737
+ if (primary)
738
+ return primary;
739
+ }
740
+ }
741
+ if (Array.isArray(agents.list)) {
742
+ for (const entry of agents.list) {
743
+ const primary = readPrimary(entry);
744
+ if (primary)
745
+ return primary;
746
+ }
747
+ }
748
+ return undefined;
749
+ }
510
750
  function normalizeBaseUrl(baseUrl) {
511
751
  return baseUrl.trim().replace(/\/+$/, "");
512
752
  }
@@ -23,7 +23,7 @@ export declare function createModelFetchOperations({ api, factoryConfig, fetchMo
23
23
  fetchModels: (providerId: string) => Promise<FetchModelsOutput>;
24
24
  saveStrategy: ({ provider, filter, targetAgents, }: SaveStrategyInput) => Promise<SaveStrategyOutput>;
25
25
  previewApply: (provider: string, scope?: SessionSelectionScope) => Promise<PreviewApplyOutput>;
26
- applyStrategy: ({ provider, fingerprint, expectedRemovals, targetAgents, }: ApplyStrategyInput, scope?: SessionSelectionScope) => Promise<ApplyStrategyOutput>;
26
+ applyStrategy: ({ provider, fingerprint, expectedRemovals, referenceRewrites, targetAgents, }: ApplyStrategyInput, scope?: SessionSelectionScope) => Promise<ApplyStrategyOutput>;
27
27
  refreshProvider: (params: ModelFetchParams) => Promise<{
28
28
  provider: string;
29
29
  fetched: number;
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
2
2
  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
- import { applyModelReferenceProtection, collectModelReferenceUsages, fetchProviderModels, getProvider, mergeModels, resolveApiKey, resolveProviderFilter, resolveProviderTargetAgents, runModelFetch, selectFetchedModels, syncAgentModelEntries, syncConfiguredModelPolicyAllow, } from "./model-fetch.js";
5
+ import { applyModelReferenceProtection, collectCaseVariantRelations, collectModelReferenceUsages, fetchProviderModels, getProvider, mergeModels, resolveDefaultModelRef, resolveApiKey, resolveProviderFilter, resolveProviderTargetAgents, rewriteModelReferences, runModelFetch, selectFetchedModels, syncAgentModelEntries, syncConfiguredModelPolicyAllow, } from "./model-fetch.js";
6
6
  /**
7
7
  * The host exposes a single-attempt config mutation to plugins, so a write
8
8
  * that loses the race against another writer (for example an OpenClaw upgrade
@@ -69,6 +69,50 @@ function normalizeTargetAgents(targetAgents) {
69
69
  function configPath(providerId) {
70
70
  return `models.providers.${providerId}.models`;
71
71
  }
72
+ /**
73
+ * Validates the requested reference rewrites against the plan.
74
+ *
75
+ * A rewrite may only retarget a model that the plan protects, and it may only
76
+ * point at a model that survives the replacement. Rewriting to a model that is
77
+ * itself removed would leave the config with a dangling reference, so the
78
+ * whole plan is rejected instead.
79
+ */
80
+ function normalizeReferenceRewrites(requested, computed) {
81
+ if (!requested || requested.length === 0)
82
+ return [];
83
+ const protectedIds = new Set(computed.protectedModels.map((entry) => entry.modelId));
84
+ const survivingIds = new Set(computed.finalModels.map((model) => model.id));
85
+ const removedIds = new Set(computed.removedIds);
86
+ const providerPrefix = `${computed.providerId}/`;
87
+ const result = [];
88
+ const seen = new Set();
89
+ for (const entry of requested) {
90
+ const protectedModelId = entry.protectedModelId.trim();
91
+ if (!protectedIds.has(protectedModelId)) {
92
+ throw new Error(`引用改写目标 ${protectedModelId} 不在本次保留列表中,已取消写入。请重新预览。`);
93
+ }
94
+ if (seen.has(protectedModelId))
95
+ continue;
96
+ const targetRef = entry.targetRef.trim();
97
+ if (!targetRef.startsWith(providerPrefix)) {
98
+ throw new Error(`引用改写目标 ${targetRef} 不属于当前 Provider,已取消写入。请重新预览。`);
99
+ }
100
+ const targetId = targetRef.slice(providerPrefix.length);
101
+ if (!targetId) {
102
+ throw new Error(`引用改写目标 ${targetRef} 无效,已取消写入。请重新预览。`);
103
+ }
104
+ if (removedIds.has(targetId) || !survivingIds.has(targetId)) {
105
+ throw new Error(`引用改写目标 ${targetRef} 也会被删除,已取消写入。请重新预览。`);
106
+ }
107
+ seen.add(protectedModelId);
108
+ result.push({
109
+ protectedModelId,
110
+ fromRef: `${computed.providerId}/${protectedModelId}`,
111
+ toRef: targetRef,
112
+ });
113
+ }
114
+ return result;
115
+ }
72
116
  function planFingerprint(input) {
73
117
  return createHash("sha256")
74
118
  .update(JSON.stringify({
@@ -400,6 +444,8 @@ export function createModelFetchOperations({ api, factoryConfig, fetchModels = f
400
444
  removedIds,
401
445
  protectedModels: protection.protectedModels,
402
446
  });
447
+ const caseVariants = collectCaseVariantRelations(removedIds, protection.models.map((model) => model.id));
448
+ const defaultModelRef = resolveDefaultModelRef(config);
403
449
  return {
404
450
  providerId,
405
451
  provider,
@@ -412,9 +458,13 @@ export function createModelFetchOperations({ api, factoryConfig, fetchModels = f
412
458
  selectedIds: merge.selectedIds,
413
459
  unchangedCount: merge.unchanged,
414
460
  protectedModels: protection.protectedModels,
461
+ caseVariants,
462
+ defaultModelRef,
415
463
  models,
416
464
  fingerprint,
417
465
  finalModels: protection.models,
466
+ existingModels: existing,
467
+ mergedModels: merge.models,
418
468
  };
419
469
  }
420
470
  async function listProviders() {
@@ -495,6 +545,8 @@ export function createModelFetchOperations({ api, factoryConfig, fetchModels = f
495
545
  addedIds: computed.addedIds,
496
546
  removedIds: computed.removedIds,
497
547
  protectedModels: computed.protectedModels,
548
+ caseVariants: computed.caseVariants,
549
+ defaultModelRef: computed.defaultModelRef,
498
550
  selectedIds: computed.selectedIds,
499
551
  unchangedCount: computed.unchangedCount,
500
552
  affectedSessions,
@@ -505,7 +557,7 @@ export function createModelFetchOperations({ api, factoryConfig, fetchModels = f
505
557
  models: computed.models,
506
558
  };
507
559
  }
508
- async function applyStrategy({ provider, fingerprint, expectedRemovals, targetAgents, }, scope = {}) {
560
+ async function applyStrategy({ provider, fingerprint, expectedRemovals, referenceRewrites, targetAgents, }, scope = {}) {
509
561
  const computed = await computePlan(provider);
510
562
  if (computed.fingerprint !== fingerprint) {
511
563
  throw new Error("模型列表或筛选策略已变化,请重新预览后再确认应用。");
@@ -513,8 +565,10 @@ export function createModelFetchOperations({ api, factoryConfig, fetchModels = f
513
565
  if (!sameStringSets(computed.removedIds, expectedRemovals)) {
514
566
  throw new Error("待删除模型与确认列表不一致,已取消写入。请重新预览。");
515
567
  }
568
+ const rewrites = normalizeReferenceRewrites(referenceRewrites, computed);
516
569
  const nextTargetAgents = normalizeTargetAgents(targetAgents ?? savedTargetAgents(provider));
517
570
  let syncedAgents = [];
571
+ const rewrittenReferences = [];
518
572
  const result = await mutateConfigFileWithRetry(runtime, {
519
573
  base: "source",
520
574
  afterWrite: { mode: "auto" },
@@ -532,13 +586,29 @@ export function createModelFetchOperations({ api, factoryConfig, fetchModels = f
532
586
  if (referenceProtectionDrift(config, provider, computed)) {
533
587
  throw new Error("模型引用在确认后发生变化,已取消写入。请重新预览。");
534
588
  }
535
- target.models = computed.finalModels;
589
+ for (const rewrite of rewrites) {
590
+ const result = rewriteModelReferences(config, rewrite.fromRef, rewrite.toRef);
591
+ if (result.changed)
592
+ rewrittenReferences.push(...result.paths);
593
+ }
594
+ // The rewrites may have released the references that kept a model in
595
+ // the list, so the final list is recomputed against the rewritten
596
+ // draft instead of reusing the previewed one.
597
+ const finalModels = rewrites.length > 0
598
+ ? applyModelReferenceProtection({
599
+ existing: computed.existingModels,
600
+ merged: computed.mergedModels,
601
+ providerId: provider,
602
+ config,
603
+ }).models
604
+ : computed.finalModels;
605
+ target.models = finalModels;
536
606
  ensurePluginEntry(config, provider, computed.filter, nextTargetAgents);
537
- const syncResult = syncConfiguredModelPolicyAllow(config, provider, computed.finalModels, {
607
+ const syncResult = syncConfiguredModelPolicyAllow(config, provider, finalModels, {
538
608
  targetAgents: nextTargetAgents,
539
609
  });
540
610
  syncedAgents = syncResult.syncedAgents;
541
- syncAgentModelEntries(config, provider, computed.finalModels, {
611
+ syncAgentModelEntries(config, provider, finalModels, {
542
612
  targetAgents: syncedAgents,
543
613
  });
544
614
  },
@@ -570,6 +640,7 @@ export function createModelFetchOperations({ api, factoryConfig, fetchModels = f
570
640
  removed: computed.removedIds.length,
571
641
  selectedIds: computed.selectedIds,
572
642
  protectedModels: computed.protectedModels,
643
+ rewrittenReferences,
573
644
  targetAgents: nextTargetAgents,
574
645
  syncedAgents,
575
646
  sessionSelectionResets: resetSessionKeys.length,
package/dist/schemas.d.ts CHANGED
@@ -37,6 +37,27 @@ export declare const protectedModelSchema: Type.TObject<{
37
37
  references: Type.TArray<Type.TString>;
38
38
  }>;
39
39
  export type ProtectedModel = Static<typeof protectedModelSchema>;
40
+ /**
41
+ * A removal candidate that only differs from a surviving model by letter case.
42
+ */
43
+ export declare const caseVariantSchema: Type.TObject<{
44
+ removedId: Type.TString;
45
+ survivingModelId: Type.TString;
46
+ }>;
47
+ export type CaseVariant = Static<typeof caseVariantSchema>;
48
+ /**
49
+ * The replacement a protected model's references are rewritten to.
50
+ *
51
+ * `targetRef` is the full `provider/model` reference written into the config.
52
+ * `useDefaultModel` marks the case where the target is the agent default
53
+ * model, which the UI shows without naming a concrete provider model.
54
+ */
55
+ export declare const referenceRewriteSchema: Type.TObject<{
56
+ protectedModelId: Type.TString;
57
+ targetRef: Type.TString;
58
+ useDefaultModel: Type.TBoolean;
59
+ }>;
60
+ export type ReferenceRewrite = Static<typeof referenceRewriteSchema>;
40
61
  export declare const modelFetchResultSchema: Type.TObject<{
41
62
  provider: Type.TString;
42
63
  fetched: Type.TInteger;
@@ -171,6 +192,11 @@ export declare const applyPlanSchema: Type.TObject<{
171
192
  ref: Type.TString;
172
193
  references: Type.TArray<Type.TString>;
173
194
  }>>;
195
+ caseVariants: Type.TArray<Type.TObject<{
196
+ removedId: Type.TString;
197
+ survivingModelId: Type.TString;
198
+ }>>;
199
+ defaultModelRef: Type.TOptional<Type.TString>;
174
200
  selectedIds: Type.TArray<Type.TString>;
175
201
  unchangedCount: Type.TInteger;
176
202
  affectedSessions: Type.TArray<Type.TObject<{
@@ -193,6 +219,11 @@ export declare const previewApplyOutputSchema: Type.TObject<{
193
219
  ref: Type.TString;
194
220
  references: Type.TArray<Type.TString>;
195
221
  }>>;
222
+ caseVariants: Type.TArray<Type.TObject<{
223
+ removedId: Type.TString;
224
+ survivingModelId: Type.TString;
225
+ }>>;
226
+ defaultModelRef: Type.TOptional<Type.TString>;
196
227
  selectedIds: Type.TArray<Type.TString>;
197
228
  unchangedCount: Type.TInteger;
198
229
  affectedSessions: Type.TArray<Type.TObject<{
@@ -212,6 +243,11 @@ export declare const applyStrategyInputSchema: Type.TObject<{
212
243
  provider: Type.TString;
213
244
  fingerprint: Type.TString;
214
245
  expectedRemovals: Type.TArray<Type.TString>;
246
+ referenceRewrites: Type.TOptional<Type.TArray<Type.TObject<{
247
+ protectedModelId: Type.TString;
248
+ targetRef: Type.TString;
249
+ useDefaultModel: Type.TBoolean;
250
+ }>>>;
215
251
  targetAgents: Type.TOptional<Type.TArray<Type.TString>>;
216
252
  }>;
217
253
  export type ApplyStrategyInput = Static<typeof applyStrategyInputSchema>;
@@ -230,6 +266,7 @@ export declare const applyStrategyOutputSchema: Type.TObject<{
230
266
  ref: Type.TString;
231
267
  references: Type.TArray<Type.TString>;
232
268
  }>>;
269
+ rewrittenReferences: Type.TArray<Type.TString>;
233
270
  targetAgents: Type.TArray<Type.TString>;
234
271
  syncedAgents: Type.TArray<Type.TString>;
235
272
  sessionSelectionResets: Type.TInteger;
package/dist/schemas.js CHANGED
@@ -57,6 +57,25 @@ export const protectedModelSchema = Type.Object({
57
57
  ref: Type.String({ minLength: 1, maxLength: 1_024 }),
58
58
  references: Type.Array(Type.String({ maxLength: 1_024 }), { maxItems: 256 }),
59
59
  }, { additionalProperties: false });
60
+ /**
61
+ * A removal candidate that only differs from a surviving model by letter case.
62
+ */
63
+ export const caseVariantSchema = Type.Object({
64
+ removedId: Type.String({ minLength: 1, maxLength: 512 }),
65
+ survivingModelId: Type.String({ minLength: 1, maxLength: 512 }),
66
+ }, { additionalProperties: false });
67
+ /**
68
+ * The replacement a protected model's references are rewritten to.
69
+ *
70
+ * `targetRef` is the full `provider/model` reference written into the config.
71
+ * `useDefaultModel` marks the case where the target is the agent default
72
+ * model, which the UI shows without naming a concrete provider model.
73
+ */
74
+ export const referenceRewriteSchema = Type.Object({
75
+ protectedModelId: Type.String({ minLength: 1, maxLength: 512 }),
76
+ targetRef: Type.String({ minLength: 1, maxLength: 1_024 }),
77
+ useDefaultModel: Type.Boolean(),
78
+ }, { additionalProperties: false });
60
79
  export const modelFetchResultSchema = Type.Object({
61
80
  provider: providerIdSchema,
62
81
  fetched: Type.Integer({ minimum: 0 }),
@@ -137,6 +156,8 @@ export const applyPlanSchema = Type.Object({
137
156
  addedIds: Type.Array(Type.String({ maxLength: 512 }), { maxItems: 2_000 }),
138
157
  removedIds: Type.Array(Type.String({ maxLength: 512 }), { maxItems: 2_000 }),
139
158
  protectedModels: Type.Array(protectedModelSchema, { maxItems: 2_000 }),
159
+ caseVariants: Type.Array(caseVariantSchema, { maxItems: 2_000 }),
160
+ defaultModelRef: Type.Optional(Type.String({ maxLength: 1_024 })),
140
161
  selectedIds: Type.Array(Type.String({ maxLength: 512 }), { maxItems: 2_000 }),
141
162
  unchangedCount: Type.Integer({ minimum: 0 }),
142
163
  affectedSessions: Type.Array(affectedSessionSchema, { maxItems: 2_000 }),
@@ -150,6 +171,7 @@ export const applyStrategyInputSchema = Type.Object({
150
171
  provider: providerIdSchema,
151
172
  fingerprint: Type.String({ minLength: 64, maxLength: 64 }),
152
173
  expectedRemovals: Type.Array(Type.String({ maxLength: 512 }), { maxItems: 2_000 }),
174
+ referenceRewrites: Type.Optional(Type.Array(referenceRewriteSchema, { maxItems: 2_000 })),
153
175
  targetAgents: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 128 }), {
154
176
  maxItems: 256,
155
177
  uniqueItems: true,
@@ -166,6 +188,7 @@ export const applyStrategyOutputSchema = Type.Object({
166
188
  removed: Type.Integer({ minimum: 0 }),
167
189
  selectedIds: Type.Array(Type.String({ maxLength: 512 }), { maxItems: 2_000 }),
168
190
  protectedModels: Type.Array(protectedModelSchema, { maxItems: 2_000 }),
191
+ rewrittenReferences: Type.Array(Type.String({ maxLength: 1_024 }), { maxItems: 2_000 }),
169
192
  targetAgents: Type.Array(Type.String({ minLength: 1, maxLength: 128 }), {
170
193
  maxItems: 256,
171
194
  uniqueItems: true,
@@ -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.6",
5
+ "version": "0.2.7",
6
6
  "configSchema": {
7
7
  "type": "object",
8
8
  "properties": {
@@ -65,9 +65,9 @@
65
65
  "navigation"
66
66
  ],
67
67
  "controlUi": {
68
- "entry": "dist/control-ui/3c4f0a9bd18e23199c1dfcdf9de58e7b0594e1654697f13214b5b9f800cbd5c8/index.js",
68
+ "entry": "dist/control-ui/f8e122768109836f1d9d9a6b4d177c8e9fb5f8b0bc4778c799b566c3dd7c1fd3/index.js",
69
69
  "styles": [
70
- "dist/control-ui/3c4f0a9bd18e23199c1dfcdf9de58e7b0594e1654697f13214b5b9f800cbd5c8/index.css"
70
+ "dist/control-ui/f8e122768109836f1d9d9a6b4d177c8e9fb5f8b0bc4778c799b566c3dd7c1fd3/index.css"
71
71
  ]
72
72
  },
73
73
  "contracts": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-plugin-model-fetch",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
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": {