@goodandready/dsh-moa 0.2.5 → 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/client.js +57 -5
  2. package/package.json +2 -2
package/lib/client.js CHANGED
@@ -888,14 +888,45 @@ window.__ModuleLoader__.load({
888
888
 
889
889
  function useMoASettings(props) {
890
890
  const t = makeT(rootCtx, props)
891
+ const effectiveCtx = (props && props.ctx) || rootCtx
892
+
893
+ // Reactive binding to settingsScope if available
894
+ const scope = React.useMemo(() => {
895
+ if (!effectiveCtx) return undefined
896
+ const s = effectiveCtx.get ? effectiveCtx.get('settingsScope') : effectiveCtx.settingsScope
897
+ return s && typeof s.bind === 'function' ? s.bind({ namespace: NS }) : undefined
898
+ }, [effectiveCtx])
899
+
900
+ const snapshot = React.useSyncExternalStore
901
+ ? React.useSyncExternalStore(
902
+ React.useMemo(() => (cb) => (scope ? scope.subscribe(cb) : () => {}), [scope]),
903
+ React.useCallback(() => (scope ? scope.getSnapshot() : { status: 'ready' }), [scope]),
904
+ React.useCallback(() => ({ status: 'loading' }), [])
905
+ )
906
+ : null
907
+
891
908
  const [status, setStatus] = React.useState('loading')
892
909
  const [presets, setPresets] = React.useState([])
893
910
  const [defaultPreset, setDefaultPreset] = React.useState('default')
894
911
  const [availableModels, setAvailableModels] = React.useState([])
895
912
  const [saveStatus, setSaveStatus] = React.useState('')
896
913
 
914
+ // Sync from settingsScope snapshot when available
915
+ React.useEffect(() => {
916
+ if (!scope || !snapshot) return
917
+ const snapStatus = snapshot.status || 'ready'
918
+ if (snapStatus === 'ready') {
919
+ const val = snapshot.value || {}
920
+ if (Array.isArray(val.presets)) setPresets(val.presets)
921
+ if (val.default_preset) setDefaultPreset(val.default_preset)
922
+ setStatus('ready')
923
+ } else if (snapStatus === 'unavailable') {
924
+ setStatus('unavailable')
925
+ }
926
+ }, [scope, snapshot])
927
+
897
928
  const reload = React.useCallback(() => {
898
- setStatus('loading')
929
+ if (!scope) setStatus('loading')
899
930
 
900
931
  fetch('/dsh-moa/presets', { cache: 'no-store' })
901
932
  .then((r) => {
@@ -907,13 +938,13 @@ window.__ModuleLoader__.load({
907
938
  setPresets(data.presets || [])
908
939
  setDefaultPreset(data.defaultPreset || 'default')
909
940
  setStatus('ready')
910
- } else {
941
+ } else if (!scope) {
911
942
  setStatus('unavailable')
912
943
  }
913
944
  })
914
945
  .catch((err) => {
915
946
  console.warn('[dsh-moa] Presets fetch failed:', err)
916
- setStatus('unavailable')
947
+ if (!scope) setStatus('unavailable')
917
948
  })
918
949
 
919
950
  fetch('/dsh-moa/models', { cache: 'no-store' })
@@ -926,7 +957,7 @@ window.__ModuleLoader__.load({
926
957
  .catch((err) => {
927
958
  console.warn('[dsh-moa] Models fetch failed:', err)
928
959
  })
929
- }, [])
960
+ }, [scope])
930
961
 
931
962
  React.useEffect(() => {
932
963
  reload()
@@ -934,6 +965,27 @@ window.__ModuleLoader__.load({
934
965
 
935
966
  const handleSave = () => {
936
967
  setSaveStatus(t('loading'))
968
+
969
+ if (scope && typeof scope.set === 'function') {
970
+ Promise.all([
971
+ scope.set('presets', presets),
972
+ scope.set('default_preset', defaultPreset),
973
+ ])
974
+ .then(() => {
975
+ setSaveStatus(t('saved'))
976
+ setTimeout(() => setSaveStatus(''), 2500)
977
+ })
978
+ .catch((err) => {
979
+ console.warn('[dsh-moa] scope.set failed, trying REST fallback:', err)
980
+ doRestSave()
981
+ })
982
+ return
983
+ }
984
+
985
+ doRestSave()
986
+ }
987
+
988
+ const doRestSave = () => {
937
989
  fetch('/dsh-moa/presets', {
938
990
  method: 'POST',
939
991
  headers: { 'Content-Type': 'application/json' },
@@ -1111,7 +1163,7 @@ window.__ModuleLoader__.load({
1111
1163
  )
1112
1164
  }
1113
1165
 
1114
- exports.inject = ['slots', 'locale', 'inputTriggers']
1166
+ exports.inject = ['slots', 'locale', 'inputTriggers', 'settingsScope']
1115
1167
  exports.apply = function apply(ctx) {
1116
1168
  rootCtx = ctx
1117
1169
  const t = makeT(ctx)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-moa",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Mixture of Agents (MoA) plugin for DeepSeek Harness with /moa slash command",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -58,4 +58,4 @@
58
58
  "@deepseek-ai/dsh-tools": "^0.1.0-rc.6",
59
59
  "@deepseek-ai/schemastery": "^3.18.1"
60
60
  }
61
- }
61
+ }