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