@yaklabs-ai/plugin-sdk 0.53.0 → 0.54.1

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.
package/dist/fs.d.ts CHANGED
@@ -10,6 +10,9 @@ export declare const chmod: typeof nodeFsp.chmod;
10
10
 
11
11
  export declare const chown: typeof nodeFsp.chown;
12
12
 
13
+ /** Receives the committed paths under the folder it subscribed to. */
14
+ export declare type CommittedChangeListener = (paths: readonly string[]) => void;
15
+
13
16
  export { constants }
14
17
 
15
18
  export declare const copyFile: typeof nodeFsp.copyFile;
@@ -59,6 +62,21 @@ declare const _default: {
59
62
  };
60
63
  export default _default;
61
64
 
65
+ /**
66
+ * Report paths whose writes have landed: created, replaced, moved or removed. A path is a source
67
+ * that changed, never a claim that anything is gone. Never throws: a subscriber's failure goes
68
+ * to its own `warn`, and a failing `warn` is ignored, because a report cannot undo the write.
69
+ */
70
+ export declare function emitCommittedChanges(paths: readonly string[]): void;
71
+
72
+ /**
73
+ * Run `work` after every task queued earlier under `key` in this process, and
74
+ * before every task queued later. Nothing touches the filesystem: `key` is an
75
+ * opaque string, and there is no cross-process lock. Use it when this process
76
+ * is the only writer and only same-process ordering matters.
77
+ */
78
+ export declare function enqueueInProcess<T>(key: string, work: () => Promise<T>): Promise<T>;
79
+
62
80
  export { FileHandle }
63
81
 
64
82
  export declare const glob: typeof nodeFsp.glob;
@@ -124,6 +142,14 @@ export declare const stat: typeof nodeFsp.stat;
124
142
 
125
143
  export declare const statfs: typeof nodeFsp.statfs;
126
144
 
145
+ /**
146
+ * Hear about writes any plugin in this process reports with {@link emitCommittedChanges} under
147
+ * `folder`. `listener` receives the absolute, deduplicated paths inside `folder` (the folder
148
+ * itself included), synchronously from the emit. A throw from `listener` goes to `warn`. Returns
149
+ * the function that stops delivery.
150
+ */
151
+ export declare function subscribeCommittedChanges(folder: string, listener: CommittedChangeListener, warn: (error: unknown) => void): () => void;
152
+
127
153
  export declare const symlink: typeof nodeFsp.symlink;
128
154
 
129
155
  export declare const truncate: typeof nodeFsp.truncate;
package/dist/fs.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { Buffer as Buffer3 } from "node:buffer";
3
3
  import { constants } from "node:fs";
4
4
  import * as nodeFsp from "node:fs/promises";
5
- import { basename, dirname, join, resolve as resolve2 } from "node:path";
5
+ import { basename, dirname, join, resolve as resolve3 } from "node:path";
6
6
 
7
7
  // packages/plugin-sdk/dist/fs/handle.js
8
8
  import { Buffer as Buffer2 } from "node:buffer";
@@ -611,6 +611,50 @@ function currentKayFsBackend() {
611
611
  return globalThis[KAY_FS_BACKEND];
612
612
  }
613
613
 
614
+ // packages/plugin-sdk/dist/fs/mutation-queue.js
615
+ var mutationQueues = /* @__PURE__ */ new Map();
616
+ async function enqueueInProcess(key, work) {
617
+ const previous = mutationQueues.get(key) ?? Promise.resolve();
618
+ const next = previous.catch(() => void 0).then(work);
619
+ mutationQueues.set(key, next);
620
+ try {
621
+ return await next;
622
+ } finally {
623
+ if (mutationQueues.get(key) === next)
624
+ mutationQueues.delete(key);
625
+ }
626
+ }
627
+
628
+ // packages/plugin-sdk/dist/fs/committed-changes.js
629
+ import { isAbsolute, relative, resolve as resolve2 } from "node:path";
630
+ var subscriptions = /* @__PURE__ */ new Set();
631
+ function subscribeCommittedChanges(folder, listener, warn) {
632
+ const subscription = { folder: resolve2(folder), listener, warn };
633
+ subscriptions.add(subscription);
634
+ return () => {
635
+ subscriptions.delete(subscription);
636
+ };
637
+ }
638
+ function emitCommittedChanges(paths) {
639
+ const resolved = [...new Set(paths.map((path) => resolve2(path)))];
640
+ for (const subscription of subscriptions) {
641
+ const owned = resolved.filter((path) => {
642
+ const fromFolder = relative(subscription.folder, path);
643
+ return fromFolder === "" || !fromFolder.startsWith("..") && !isAbsolute(fromFolder);
644
+ });
645
+ if (owned.length === 0)
646
+ continue;
647
+ try {
648
+ subscription.listener(owned);
649
+ } catch (error) {
650
+ try {
651
+ subscription.warn(error);
652
+ } catch {
653
+ }
654
+ }
655
+ }
656
+ }
657
+
614
658
  // packages/plugin-sdk/dist/fs/index.js
615
659
  function route(node, host) {
616
660
  return ((...args) => {
@@ -766,7 +810,7 @@ var glob2 = route(() => nodeFsp.glob, (backend, pattern, options) => {
766
810
  pattern,
767
811
  wire === void 0 ? {} : { ...wire, ...cwd === void 0 ? {} : { cwd: wirePath(cwd) } }
768
812
  ], {
769
- paths: [cwd === void 0 ? resolve2(".") : keyPath(cwd)],
813
+ paths: [cwd === void 0 ? resolve3(".") : keyPath(cwd)],
770
814
  timeoutMs: timeoutOf(options),
771
815
  walksTree: true
772
816
  });
@@ -864,6 +908,8 @@ export {
864
908
  copyFile2 as copyFile,
865
909
  cp2 as cp,
866
910
  index_default as default,
911
+ emitCommittedChanges,
912
+ enqueueInProcess,
867
913
  glob2 as glob,
868
914
  lchmod2 as lchmod,
869
915
  lchown2 as lchown,
@@ -884,6 +930,7 @@ export {
884
930
  rmdir2 as rmdir,
885
931
  stat2 as stat,
886
932
  statfs2 as statfs,
933
+ subscribeCommittedChanges,
887
934
  symlink2 as symlink,
888
935
  truncate2 as truncate,
889
936
  unlink2 as unlink,