@liyang8246/dsh-accounts 0.1.10 → 0.1.12

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 +37 -65
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -626,73 +626,48 @@
626
626
  }
627
627
  /**
628
628
  * Keep only models whose name contains one of the keywords.
629
- * @param state - the session's model directory snapshot.
629
+ * @param state - the shared catalog snapshot.
630
630
  * @param keywords - lowercase keywords; empty keeps everything.
631
- * @returns the snapshot with filtered provider groups; the selected model stays visible so the composer trigger keeps naming the model in use.
631
+ * @returns the snapshot with filtered provider groups.
632
632
  */
633
- function filterModels(state, keywords) {
634
- if (!keywords.length) return state;
635
- const groups = state.groups.map((group) => ({
633
+ function filterCatalog(state, keywords) {
634
+ if (!keywords.length || state.value === null) return state;
635
+ const groups = state.value.groups.map((group) => ({
636
636
  ...group,
637
637
  models: group.models.filter((model) => matches(model.name, keywords))
638
- }));
639
- const { current } = state;
640
- if (current !== null) {
641
- const source = state.groups.find((group) => group.id === current.provider);
642
- const model = source?.models.find((item) => item.id === current.model);
643
- if (source !== void 0 && model !== void 0) {
644
- const target = groups.find((group) => group.id === source.id);
645
- if (target === void 0) groups.push({
646
- ...source,
647
- models: [model]
648
- });
649
- else if (!target.models.some((item) => item.id === model.id)) target.models = [...target.models, model];
650
- }
651
- }
638
+ })).filter((group) => group.models.length > 0);
652
639
  return {
653
640
  ...state,
654
- groups: groups.filter((group) => group.models.length > 0)
641
+ value: {
642
+ ...state.value,
643
+ groups
644
+ }
655
645
  };
656
646
  }
657
647
  /**
658
- * Filter every session model directory the composer seat and /model popup share.
659
- * Both entries read the directory's store, so the filter sits on the store
660
- * instead of on either surface.
648
+ * Filter the one Host-generation model catalog that every session directory copies,
649
+ * so the composer seat and the /model popup share the filtered list.
650
+ *
651
+ * The resolver's own `directoryFor` is NOT wrapped: any method reached through
652
+ * `ctx.get` becomes callable only under this plugin's inject set, where the
653
+ * resolver's `this.ctx.remote.session` read is illegal and takes the composer
654
+ * seat down with it.
661
655
  * @param ctx - client root context.
662
656
  * @param filter - the page-owned keyword filter.
663
657
  */
664
658
  function installModelFilter(ctx, filter) {
665
- const models = ctx.get("modelDirectories");
666
- if (models === void 0) return;
667
- const original = models.directoryFor;
668
- const patched = /* @__PURE__ */ new WeakSet();
669
- models.directoryFor = (sessionId) => {
670
- const directory = original.call(models, sessionId);
671
- if (!patched.has(directory)) {
672
- patched.add(directory);
673
- try {
674
- filterDirectory(directory, filter);
675
- } catch {}
676
- }
677
- return directory;
678
- };
679
- ctx.effect(() => () => {
680
- models.directoryFor = original;
681
- });
682
- }
683
- function filterDirectory(directory, filter) {
684
- const source = directory.store;
659
+ const catalog = ctx.get("modelDirectories")?.catalog;
660
+ const source = catalog?.store;
661
+ if (catalog === void 0 || source === void 0) return;
685
662
  let cache;
686
663
  const read = () => {
687
664
  const snapshot = source.getSnapshot();
688
665
  const key = filter.getSnapshot();
689
666
  if (cache === void 0 || cache.snapshot !== snapshot || cache.key !== key) {
690
- let value;
667
+ let value = snapshot;
691
668
  try {
692
- value = filterModels(snapshot, filter.keywords());
693
- } catch {
694
- value = snapshot;
695
- }
669
+ value = filterCatalog(snapshot, filter.keywords());
670
+ } catch {}
696
671
  cache = {
697
672
  snapshot,
698
673
  key,
@@ -701,24 +676,21 @@
701
676
  }
702
677
  return cache.value;
703
678
  };
704
- const wrapped = {
705
- getSnapshot: read,
706
- subscribe(listener) {
707
- const stopSource = source.subscribe(listener);
708
- const stopFilter = filter.subscribe(listener);
709
- return () => {
710
- stopSource();
711
- stopFilter();
712
- };
713
- },
714
- set: (next) => {
715
- source.set(next);
716
- },
717
- update: (mutator) => {
718
- source.update(mutator);
719
- }
679
+ const subscribe = (listener) => {
680
+ const stopSource = source.subscribe(listener);
681
+ const stopFilter = filter.subscribe(listener);
682
+ return () => {
683
+ stopSource();
684
+ stopFilter();
685
+ };
720
686
  };
721
- Object.defineProperty(directory, "store", {
687
+ const wrapped = new Proxy(source, { get(target, property) {
688
+ if (property === "getSnapshot") return read;
689
+ if (property === "subscribe") return subscribe;
690
+ const value = Reflect.get(target, property, target);
691
+ return typeof value === "function" ? value.bind(target) : value;
692
+ } });
693
+ Object.defineProperty(catalog, "store", {
722
694
  configurable: true,
723
695
  get: () => wrapped
724
696
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@liyang8246/dsh-accounts",
3
3
  "type": "module",
4
- "version": "0.1.10",
4
+ "version": "0.1.12",
5
5
  "description": "Independent multi-account Codex, OpenCode Go and CommandCode Go plugin for DeepSeek Harness.",
6
6
  "repository": { "type": "git", "url": "https://github.com/liyang8246/dsh-zolin.git", "directory": "packages/dsh-accounts" },
7
7
  "exports": {