@goodandready/dsh-model-sync 0.2.1 → 0.2.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.
package/lib/index.js CHANGED
@@ -26,22 +26,25 @@ export function apply(ctx, config) {
26
26
  let saveConfig = async () => {
27
27
  throw Object.assign(new Error('dsh-model-sync settings are not writable'), { code: 'CONFIG_UNAVAILABLE' })
28
28
  }
29
- const settings = ctx.get('settings')
30
- if (settings?.settings?.register) {
31
- const scope = settings.settings.register(NS, Config, { base: config })
29
+
30
+ // The settings capability is injected as sctx.settings; ctx.get('settings')
31
+ // returns the provider service and does not expose the register API.
32
+ ctx.inject(['settings'], (sctx) => {
33
+ const scope = sctx.settings.register(NS, Config, { base: config })
32
34
  liveConfig = Config(scope.get() || config)
33
- const watch = scope.watch ?? scope.onChange
34
- ctx.effect(() => watch?.call(scope, (next) => {
35
+ const stop = scope.watch((next) => {
35
36
  liveConfig = Config(next || config)
36
37
  reconfigure()
37
- }), 'dsh-model-sync: settings')
38
+ })
38
39
  saveConfig = async (patch) => {
39
- if (typeof scope.update === 'function') return scope.update(patch)
40
- const next = { ...scope.get(), ...patch }
41
- if (typeof scope.replace === 'function') return scope.replace(next)
42
- throw Object.assign(new Error('dsh-model-sync settings are not writable'), { code: 'CONFIG_UNAVAILABLE' })
40
+ const result = await scope.update(patch)
41
+ // Settings watchers are serialized asynchronously; refresh the snapshot
42
+ // synchronously as well so a following request sees the new allowlist.
43
+ liveConfig = Config(scope.get() || config)
44
+ return result
43
45
  }
44
- }
46
+ sctx.effect(() => () => stop(), 'dsh-model-sync: settings')
47
+ })
45
48
 
46
49
  const service = createProviderService(ctx)
47
50
  const synchronizer = createModelSynchronizer(ctx, { getConfig: () => liveConfig, saveConfig })
@@ -149,9 +149,22 @@ export function createModelSynchronizer(ctx, { getConfig = () => ({}), saveConfi
149
149
  ? selectedModels.map((id) => availableById.get(id))
150
150
  : (available.length > 0 ? available : current)
151
151
  const next = catalogPatch(section, provider, nextModels)
152
- await settings.replace(PIAI_NS, next, descriptor.revision)
153
- const modelSelections = { ...(config.modelSelections ?? {}), [provider]: selectedModels }
152
+ const previousModelSelections = structuredClone(config.modelSelections ?? {})
153
+ const modelSelections = { ...previousModelSelections, [provider]: selectedModels }
154
+
155
+ // Persist the allowlist first. If the LLM catalog write fails, roll the
156
+ // allowlist back so the two namespaces cannot be left disagreeing.
154
157
  await saveConfig({ modelSelections })
158
+ try {
159
+ await settings.replace(PIAI_NS, next, descriptor.revision)
160
+ } catch (error) {
161
+ try {
162
+ await saveConfig({ modelSelections: previousModelSelections })
163
+ } catch {
164
+ // Preserve the original, more actionable catalog-write error.
165
+ }
166
+ throw error
167
+ }
155
168
  return { provider, selectedModels, models: nextModels, availableModels: available, applied: true }
156
169
  }
157
170
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-model-sync",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Automatic model catalog synchronization for API-key DeepSeek Harness providers.",
5
5
  "keywords": [
6
6
  "deepseek-harness",