@goodandready/dsh-model-sync 0.2.3 → 0.2.5

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 +23 -12
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -21,7 +21,8 @@ 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
27
  let saveConfigImpl
27
28
  // ctx.inject starts a child fiber; keep a stable function reference for the
@@ -33,27 +34,37 @@ export function apply(ctx, config) {
33
34
  return saveConfigImpl(patch)
34
35
  }
35
36
 
36
- // The settings capability is injected as sctx.settings; ctx.get('settings')
37
- // returns the provider service and does not expose the register API.
38
- ctx.inject(['settings'], (sctx) => {
39
- const scope = sctx.settings.register(NS, Config, { base: config })
40
- liveConfig = Config(scope.get() || config)
37
+ let settingsScope
38
+ const bindSettings = (settings, ownerCtx) => {
39
+ if (settingsScope || !settings?.register) return false
40
+ const scope = settings.register(NS, Config, { base: baseConfig })
41
+ settingsScope = scope
42
+ liveConfig = Config(scope.get() || baseConfig)
41
43
  const stop = scope.watch((next) => {
42
- liveConfig = Config(next || config)
44
+ liveConfig = Config(next || baseConfig)
43
45
  reconfigure()
44
46
  })
45
47
  saveConfigImpl = async (patch) => {
46
48
  const result = await scope.update(patch)
47
- // Settings watchers are serialized asynchronously; refresh the snapshot
48
- // synchronously as well so a following request sees the new allowlist.
49
- liveConfig = Config(scope.get() || config)
49
+ liveConfig = Config(scope.get() || baseConfig)
50
50
  return result
51
51
  }
52
- sctx.effect(() => () => {
52
+ ownerCtx.effect(() => () => {
53
+ settingsScope = undefined
53
54
  saveConfigImpl = undefined
54
55
  stop()
55
56
  }, 'dsh-model-sync: settings')
56
- })
57
+ return true
58
+ }
59
+
60
+ let settings
61
+ try { settings = ctx.get('settings') } catch {}
62
+ if (!bindSettings(settings, ctx)) {
63
+ ctx.inject(['settings'], (sctx) => {
64
+ bindSettings(sctx.settings, sctx)
65
+ })
66
+ }
67
+
57
68
 
58
69
  const service = createProviderService(ctx)
59
70
  const synchronizer = createModelSynchronizer(ctx, { getConfig: () => liveConfig, saveConfig })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-model-sync",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Automatic model catalog synchronization for API-key DeepSeek Harness providers.",
5
5
  "keywords": [
6
6
  "deepseek-harness",