@goodandready/dsh-model-sync 0.2.2 → 0.2.4

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/lib/index.js +19 -9
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -21,29 +21,39 @@ export const Config = Schema.object({
21
21
  })
22
22
 
23
23
  export function apply(ctx, config) {
24
- let liveConfig = Config(structuredClone(config || {}))
24
+ const baseConfig = structuredClone(config || {})
25
+ let liveConfig = Config(baseConfig)
25
26
  let reconfigure = () => {}
26
- let saveConfig = async () => {
27
- throw Object.assign(new Error('dsh-model-sync settings are not writable'), { code: 'CONFIG_UNAVAILABLE' })
27
+ let saveConfigImpl
28
+ // ctx.inject starts a child fiber; keep a stable function reference for the
29
+ // synchronizer while that fiber connects to the Settings service.
30
+ const saveConfig = async (patch) => {
31
+ if (!saveConfigImpl) {
32
+ throw Object.assign(new Error('dsh-model-sync settings are not writable'), { code: 'CONFIG_UNAVAILABLE' })
33
+ }
34
+ return saveConfigImpl(patch)
28
35
  }
29
36
 
30
37
  // The settings capability is injected as sctx.settings; ctx.get('settings')
31
38
  // returns the provider service and does not expose the register API.
32
39
  ctx.inject(['settings'], (sctx) => {
33
- const scope = sctx.settings.register(NS, Config, { base: config })
34
- liveConfig = Config(scope.get() || config)
40
+ const scope = sctx.settings.register(NS, Config, { base: baseConfig })
41
+ liveConfig = Config(scope.get() || baseConfig)
35
42
  const stop = scope.watch((next) => {
36
- liveConfig = Config(next || config)
43
+ liveConfig = Config(next || baseConfig)
37
44
  reconfigure()
38
45
  })
39
- saveConfig = async (patch) => {
46
+ saveConfigImpl = async (patch) => {
40
47
  const result = await scope.update(patch)
41
48
  // Settings watchers are serialized asynchronously; refresh the snapshot
42
49
  // synchronously as well so a following request sees the new allowlist.
43
- liveConfig = Config(scope.get() || config)
50
+ liveConfig = Config(scope.get() || baseConfig)
44
51
  return result
45
52
  }
46
- sctx.effect(() => () => stop(), 'dsh-model-sync: settings')
53
+ sctx.effect(() => () => {
54
+ saveConfigImpl = undefined
55
+ stop()
56
+ }, 'dsh-model-sync: settings')
47
57
  })
48
58
 
49
59
  const service = createProviderService(ctx)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-model-sync",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Automatic model catalog synchronization for API-key DeepSeek Harness providers.",
5
5
  "keywords": [
6
6
  "deepseek-harness",