@yaklabs-ai/plugin-sdk 0.12.4 → 0.13.0

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/README.md CHANGED
@@ -13,7 +13,7 @@ it under the name your plugin code actually imports:
13
13
  ```json
14
14
  {
15
15
  "dependencies": {
16
- "@kay/plugin-sdk": "npm:@yaklabs-ai/plugin-sdk@^0.12.4"
16
+ "@kay/plugin-sdk": "npm:@yaklabs-ai/plugin-sdk@^0.13.0"
17
17
  }
18
18
  }
19
19
  ```
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "package": "@yaklabs-ai/plugin-sdk",
4
- "version": "0.12.4",
4
+ "version": "0.13.0",
5
5
  "target": "npm",
6
6
  "firstPartyLicense": "MIT",
7
7
  "bundled": [
@@ -1024,52 +1024,14 @@ declare interface KayAgentEvents {
1024
1024
  publish(localId: string, payload: unknown): void;
1025
1025
  }
1026
1026
 
1027
- /**
1028
- * Claim-checked filesystem operations. Paths are root-relative; canonical host paths never cross
1029
- * the seam. Writes are atomic: readers see the old file or the new one, never a partial write. A
1030
- * replace keeps the file's mode but makes a new file, so owner and extended attributes are not
1031
- * carried over. On a volume without hard links an exclusive create can briefly show an empty file.
1032
- */
1033
- declare interface KayAgentFilesystem {
1034
- readText(location: KayAgentFilesystemLocation): Promise<string>;
1035
- writeText(location: KayAgentFilesystemLocation, content: string, options?: KayAgentFilesystemWriteOptions): Promise<void>;
1036
- /** The whole file, or the requested window of it. */
1037
- readBytes(location: KayAgentFilesystemLocation, range?: KayAgentFilesystemByteRange): Promise<Uint8Array>;
1038
- writeBytes(location: KayAgentFilesystemLocation, bytes: Uint8Array, options?: KayAgentFilesystemWriteOptions): Promise<void>;
1039
- mkdir(location: KayAgentFilesystemLocation): Promise<void>;
1040
- readDir(location: KayAgentFilesystemLocation): Promise<readonly KayAgentFilesystemEntry[]>;
1041
- stat(location: KayAgentFilesystemLocation): Promise<KayAgentFilesystemStat>;
1042
- rename(from: KayAgentFilesystemLocation, to: KayAgentFilesystemLocation): Promise<void>;
1043
- /** Returns the canonical path relative to the selected grant root. */
1044
- realpath(location: KayAgentFilesystemLocation): Promise<string>;
1045
- }
1046
-
1047
- /** A byte window of a file; `maxBytes` is capped by the host. */
1048
- declare interface KayAgentFilesystemByteRange {
1049
- readonly offset: number;
1050
- readonly maxBytes: number;
1051
- }
1052
-
1053
- declare interface KayAgentFilesystemEntry {
1054
- readonly name: string;
1055
- readonly kind: "file" | "directory" | "symlink" | "other";
1056
- }
1057
-
1058
- declare interface KayAgentFilesystemLocation {
1059
- /** Exact `root` selector the host bound for this target, plus a path relative to it. */
1060
- readonly root: string;
1061
- readonly path: string;
1062
- }
1063
-
1064
- declare interface KayAgentFilesystemStat {
1065
- readonly kind: "file" | "directory" | "other";
1066
- readonly size: number;
1067
- readonly modifiedAtMs: number;
1068
- }
1069
-
1070
- declare interface KayAgentFilesystemWriteOptions {
1071
- /** Fail with `already_exists` instead of replacing a file already at the location. */
1072
- readonly exclusive?: boolean;
1027
+ /** This plugin's folder in the session family's shared Whiteboard. */
1028
+ declare interface KayAgentFamilyFolder {
1029
+ /**
1030
+ * The folder's absolute path, created on first use. The plugin that owns the Whiteboard gets
1031
+ * the whole family folder; every other plugin gets its own `plugins/<plugin-id>/` inside it.
1032
+ * Undefined outside a session.
1033
+ */
1034
+ path(): Promise<string | undefined>;
1073
1035
  }
1074
1036
 
1075
1037
  declare interface KayAgentInteractionSurfaces {
@@ -1211,11 +1173,8 @@ declare interface KayAgentPluginApi {
1211
1173
  /** Register a whole URI module (a scheme handler that owns its address space, e.g. `drive://`). */
1212
1174
  registerModule(module: UriExtensionModule): void;
1213
1175
  };
1214
- /**
1215
- * Always present; each call is checked against `filesystem.read {root}` / `filesystem.write
1216
- * {root}` for the root it touches, and against the host's binding for that root.
1217
- */
1218
- readonly filesystem: KayAgentFilesystem;
1176
+ /** This plugin's folder in the session family's shared Whiteboard, created on first use. Undefined outside a session. */
1177
+ readonly familyFolder: KayAgentFamilyFolder;
1219
1178
  /** Absent unless the `knowledgeSearch` grant is requested and effectively granted. */
1220
1179
  readonly knowledgeSearch?: KayAgentKnowledgeSearch;
1221
1180
  /** Absent unless the `knownResources` grant is requested and effectively granted. */
@@ -1266,6 +1225,13 @@ declare interface KayAgentPluginApi {
1266
1225
  * the same zone-of-record port the session stamp uses; see {@link KayAppTime.snapshot}.
1267
1226
  */
1268
1227
  readonly time: KayAppTime;
1228
+ /**
1229
+ * File I/O in user folders, run by the host on its own worker threads under a deadline and
1230
+ * answered as a typed result. Always present and ungated: it takes absolute paths and checks no
1231
+ * grant, because it adds no authority a plugin's `node:fs` does not already have. What it adds is that a slow or unresponsive folder never blocks the daemon. See
1232
+ * {@link KayAppUserFiles}.
1233
+ */
1234
+ readonly userFiles: KayAppUserFiles;
1269
1235
  /**
1270
1236
  * Publish the plugin's declared events, for example so a default notification rule can tell the
1271
1237
  * user what the agent just did. Always present, like {@link withJev}: there is nothing to
@@ -1570,6 +1536,135 @@ declare interface KayAppTimeSnapshot {
1570
1536
  readonly zoneSource: "host" | "utc-fallback";
1571
1537
  }
1572
1538
 
1539
+ declare interface KayAppUserFileEntry {
1540
+ readonly name: string;
1541
+ /** From the directory entry itself: a symlink is reported as `symlink`, never followed. */
1542
+ readonly kind: KayAppUserFileKind;
1543
+ }
1544
+
1545
+ /**
1546
+ * The plugin-facing user-files contract: file I/O in folders the user owns, done by the host on
1547
+ * its own worker threads.
1548
+ *
1549
+ * Ungated and always present, like `app.paths`. It confers no authority: a plugin runs in the
1550
+ * daemon's process and can call `node:fs` itself. What the door adds is where the work runs. A
1551
+ * `node:fs` sync call blocks the daemon's event loop for as long as the path takes to answer,
1552
+ * which under a macOS-protected folder or on a drive that stopped answering can be a very long
1553
+ * time (kay#11575); an async one holds a thread of the pool the whole daemon shares. The host runs
1554
+ * each request on a dedicated worker, gives it a deadline, and answers a typed result instead of
1555
+ * throwing.
1556
+ *
1557
+ * This is a leaf module. It lives beside both target SDKs, like `time.ts`, so the `kay.agent` SDK
1558
+ * exposes the same door without importing the `kay.app` surface.
1559
+ */
1560
+ declare type KayAppUserFileKind = "file" | "directory" | "symlink" | "other";
1561
+
1562
+ declare interface KayAppUserFileListing {
1563
+ readonly entries: readonly KayAppUserFileEntry[];
1564
+ /** True when the directory had more entries than `maxEntries`; the rest were not read. */
1565
+ readonly entryLimitReached: boolean;
1566
+ }
1567
+
1568
+ /**
1569
+ * File I/O in user folders, run by the host off the daemon's main thread. Every path is absolute.
1570
+ * No method rejects; each answers a {@link KayAppUserFilesResult}. This is not a sandbox: it does
1571
+ * not limit which paths a plugin may touch. Added in SDK 0.12.5: a plugin that calls it declares
1572
+ * `compatibility.sdk` `^0.12.5`, so an older Bonsai refuses a directory or repository plugin at
1573
+ * load instead of the call failing.
1574
+ */
1575
+ declare interface KayAppUserFiles {
1576
+ /** Follows symlinks. */
1577
+ stat(path: string, options?: KayAppUserFilesCallOptions): Promise<KayAppUserFilesResult<KayAppUserFileStat>>;
1578
+ /** UTF-8. */
1579
+ readText(path: string, options?: KayAppUserFilesReadTextOptions): Promise<KayAppUserFilesResult<string>>;
1580
+ list(path: string, options?: KayAppUserFilesListOptions): Promise<KayAppUserFilesResult<KayAppUserFileListing>>;
1581
+ /** Depth-first below `path`; symlinks are reported, never followed. */
1582
+ walk(path: string, options?: KayAppUserFilesWalkOptions): Promise<KayAppUserFilesResult<KayAppUserFileWalk>>;
1583
+ /** The path with every symlink resolved. */
1584
+ realpath(path: string, options?: KayAppUserFilesCallOptions): Promise<KayAppUserFilesResult<string>>;
1585
+ /**
1586
+ * Creates or replaces a UTF-8 file, not atomically. After `timeout` or `aborted` the write may
1587
+ * still happen.
1588
+ */
1589
+ writeText(path: string, content: string, options?: KayAppUserFilesCallOptions): Promise<KayAppUserFilesResult<null>>;
1590
+ /** Creates the directory and any missing parents; succeeds when it already exists. */
1591
+ mkdir(path: string, options?: KayAppUserFilesCallOptions): Promise<KayAppUserFilesResult<null>>;
1592
+ rename(from: string, to: string, options?: KayAppUserFilesCallOptions): Promise<KayAppUserFilesResult<null>>;
1593
+ }
1594
+
1595
+ declare interface KayAppUserFilesCallOptions {
1596
+ /** Deadline in milliseconds from the call, waiting included. Default 5000, at most 60000. */
1597
+ readonly timeoutMs?: number;
1598
+ readonly signal?: AbortSignal;
1599
+ }
1600
+
1601
+ declare interface KayAppUserFilesListOptions extends KayAppUserFilesCallOptions {
1602
+ /** Default 5000, at most 50000. */
1603
+ readonly maxEntries?: number;
1604
+ }
1605
+
1606
+ declare interface KayAppUserFilesReadTextOptions extends KayAppUserFilesCallOptions {
1607
+ /** A larger file answers `error` with code `EFBIG`. Default 8 MiB, at most 64 MiB. */
1608
+ readonly maxBytes?: number;
1609
+ }
1610
+
1611
+ /**
1612
+ * Every answer. `missing`: nothing exists at the path (ENOENT). `timeout`: no answer from the path
1613
+ * in time. Its `reason` is `deadline` (this request ran out of time), `cooling-down` (a request at
1614
+ * or above this path timed out recently, so the host did not try) or `saturated` (the host's
1615
+ * workers are stuck on other paths, so it did not try). `aborted`: the caller's signal fired.
1616
+ * `error`: anything else, with the Node error `code` when there is one (`EACCES`, `EISDIR`,
1617
+ * `EFBIG` for a file over `maxBytes`, `EINVAL` for a relative path).
1618
+ */
1619
+ declare type KayAppUserFilesResult<T> = {
1620
+ readonly kind: "ok";
1621
+ readonly value: T;
1622
+ } | {
1623
+ readonly kind: "missing";
1624
+ } | {
1625
+ readonly kind: "timeout";
1626
+ readonly reason: "deadline" | "cooling-down" | "saturated";
1627
+ readonly detail: string;
1628
+ } | {
1629
+ readonly kind: "aborted";
1630
+ } | {
1631
+ readonly kind: "error";
1632
+ readonly code?: string;
1633
+ readonly detail: string;
1634
+ };
1635
+
1636
+ declare interface KayAppUserFileStat {
1637
+ /** What the path is after following symlinks; never `symlink`. */
1638
+ readonly kind: "file" | "directory" | "other";
1639
+ /** Bytes. */
1640
+ readonly size: number;
1641
+ /** Milliseconds since the Unix epoch. */
1642
+ readonly modifiedAtMs: number;
1643
+ }
1644
+
1645
+ declare interface KayAppUserFilesWalkOptions extends KayAppUserFilesCallOptions {
1646
+ /** Default 10000, at most 100000. */
1647
+ readonly maxEntries?: number;
1648
+ /** Deepest level reported; the root's children are depth 1. Default 16, at most 64. */
1649
+ readonly maxDepth?: number;
1650
+ /** Report and descend into dot-prefixed entries. Default true. */
1651
+ readonly includeHidden?: boolean;
1652
+ }
1653
+
1654
+ declare interface KayAppUserFileWalk {
1655
+ readonly entries: readonly KayAppUserFileWalkEntry[];
1656
+ /** True when the walk stopped at `maxEntries`. */
1657
+ readonly entryLimitReached: boolean;
1658
+ /** True when a directory at `maxDepth` was reported but not descended into. */
1659
+ readonly depthLimitReached: boolean;
1660
+ }
1661
+
1662
+ declare interface KayAppUserFileWalkEntry {
1663
+ /** Path segments below the walk's root. */
1664
+ readonly segments: readonly string[];
1665
+ readonly kind: KayAppUserFileKind;
1666
+ }
1667
+
1573
1668
  declare type KnownApi = "openai-completions" | "mistral-conversations" | "openai-responses" | "azure-openai-responses" | "openai-codex-responses" | "anthropic-messages" | "bedrock-converse-stream" | "google-generative-ai" | "google-vertex" | "pi-messages";
1574
1669
 
1575
1670
  declare type KnownProvider = "amazon-bedrock" | "ant-ling" | "anthropic" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "radius" | "typesafe" | "nvidia" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "zai-coding-cn" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "together" | "baseten" | "opencode" | "opencode-go" | "kimi-coding" | "meta" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "qwen-token-plan" | "qwen-token-plan-cn" | "qwen-token-plan-individual" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
@@ -765,17 +765,6 @@ function unavailableInteractionSurfaces(message) {
765
765
  // packages/plugin-sdk/dist/disclosure/probe-kay-agent-capabilities.js
766
766
  var inertResult = () => new Promise(() => {
767
767
  });
768
- var INERT_FILESYSTEM = {
769
- readText: inertResult,
770
- writeText: inertResult,
771
- readBytes: inertResult,
772
- writeBytes: inertResult,
773
- mkdir: inertResult,
774
- readDir: inertResult,
775
- stat: inertResult,
776
- rename: inertResult,
777
- realpath: inertResult
778
- };
779
768
  var INERT_NETWORK = {
780
769
  fetch: inertResult
781
770
  };
@@ -807,7 +796,6 @@ var INERT_WHITEBOARD = {
807
796
  var INERT_WITH_JEV = async (_use, fallback) => fallback();
808
797
  function createKayAgentProbeCapabilityHandles() {
809
798
  return {
810
- filesystem: INERT_FILESYSTEM,
811
799
  network: INERT_NETWORK,
812
800
  webSession: INERT_WEB_SESSION,
813
801
  process: INERT_PROCESS,
@@ -824,7 +812,20 @@ function createKayAgentProbeCapabilityHandles() {
824
812
  // real capability keeps for a zone the host cannot read.
825
813
  time: {
826
814
  snapshot: () => ({ nowMs: 0, zone: "UTC", zoneSource: "utc-fallback" })
827
- }
815
+ },
816
+ // Inert like the process broker: a probe must never touch the user's disk.
817
+ userFiles: {
818
+ stat: inertResult,
819
+ readText: inertResult,
820
+ list: inertResult,
821
+ walk: inertResult,
822
+ realpath: inertResult,
823
+ writeText: inertResult,
824
+ mkdir: inertResult,
825
+ rename: inertResult
826
+ },
827
+ // A probe runs outside any session, and must not create a folder on the user's disk.
828
+ familyFolder: { path: async () => void 0 }
828
829
  };
829
830
  }
830
831
 
package/dist/fs.d.ts ADDED
@@ -0,0 +1,156 @@
1
+ import { constants } from 'node:fs';
2
+ import { FileHandle } from 'node:fs/promises';
3
+ import * as nodeFsp from 'node:fs/promises';
4
+
5
+ export declare const access: typeof nodeFsp.access;
6
+
7
+ export declare const appendFile: typeof nodeFsp.appendFile;
8
+
9
+ export declare const chmod: typeof nodeFsp.chmod;
10
+
11
+ export declare const chown: typeof nodeFsp.chown;
12
+
13
+ export { constants }
14
+
15
+ export declare const copyFile: typeof nodeFsp.copyFile;
16
+
17
+ export declare const cp: typeof nodeFsp.cp;
18
+
19
+ declare const _default: {
20
+ access: typeof nodeFsp.access;
21
+ appendFile: typeof nodeFsp.appendFile;
22
+ chmod: typeof nodeFsp.chmod;
23
+ chown: typeof nodeFsp.chown;
24
+ constants: typeof constants;
25
+ copyFile: typeof nodeFsp.copyFile;
26
+ cp: typeof nodeFsp.cp;
27
+ glob: typeof nodeFsp.glob;
28
+ lchmod: typeof nodeFsp.lchmod;
29
+ lchown: typeof nodeFsp.lchown;
30
+ link: typeof nodeFsp.link;
31
+ lstat: typeof nodeFsp.lstat;
32
+ lutimes: typeof nodeFsp.lutimes;
33
+ mkdir: typeof nodeFsp.mkdir;
34
+ mkdtemp: typeof nodeFsp.mkdtemp;
35
+ mkdtempDisposable: (prefix: string, options?: unknown) => Promise<{
36
+ path: string;
37
+ remove(): Promise<void>;
38
+ [Symbol.asyncDispose](): Promise<void>;
39
+ }>;
40
+ open: typeof nodeFsp.open;
41
+ opendir: typeof nodeFsp.opendir;
42
+ readdir: typeof nodeFsp.readdir;
43
+ readFile: typeof nodeFsp.readFile;
44
+ readlink: typeof nodeFsp.readlink;
45
+ realpath: typeof nodeFsp.realpath;
46
+ rename: typeof nodeFsp.rename;
47
+ rm: typeof nodeFsp.rm;
48
+ rmdir: typeof nodeFsp.rmdir;
49
+ stat: typeof nodeFsp.stat;
50
+ statfs: typeof nodeFsp.statfs;
51
+ symlink: typeof nodeFsp.symlink;
52
+ truncate: typeof nodeFsp.truncate;
53
+ unlink: typeof nodeFsp.unlink;
54
+ utimes: typeof nodeFsp.utimes;
55
+ watch: typeof nodeFsp.watch;
56
+ writeFile: typeof nodeFsp.writeFile;
57
+ writeFileAtomic: typeof writeFileAtomic;
58
+ withTimeout: typeof withTimeout;
59
+ };
60
+ export default _default;
61
+
62
+ export { FileHandle }
63
+
64
+ export declare const glob: typeof nodeFsp.glob;
65
+
66
+ /** Not tried: a call at or above this path missed its deadline recently. */
67
+ export declare const KAY_FS_COOLING_DOWN = "ERR_KAY_FS_COOLING_DOWN";
68
+
69
+ /** The call did not finish by its deadline; the host abandoned the worker running it. */
70
+ export declare const KAY_FS_DEADLINE = "ERR_KAY_FS_DEADLINE";
71
+
72
+ /** A call's deadline when its options name none. */
73
+ export declare const KAY_FS_DEFAULT_TIMEOUT_MS = 30000;
74
+
75
+ /** Not tried: the host's file workers are all stuck on other paths. */
76
+ export declare const KAY_FS_SATURATED = "ERR_KAY_FS_SATURATED";
77
+
78
+ /** The host's file service is closed, or its worker could not start or died mid-call. */
79
+ export declare const KAY_FS_UNAVAILABLE = "ERR_KAY_FS_UNAVAILABLE";
80
+
81
+ /** An option or function this module does not implement (see the module docs). */
82
+ export declare const KAY_FS_UNSUPPORTED = "ERR_KAY_FS_UNSUPPORTED";
83
+
84
+ export declare const lchmod: typeof nodeFsp.lchmod;
85
+
86
+ export declare const lchown: typeof nodeFsp.lchown;
87
+
88
+ export declare const link: typeof nodeFsp.link;
89
+
90
+ export declare const lstat: typeof nodeFsp.lstat;
91
+
92
+ export declare const lutimes: typeof nodeFsp.lutimes;
93
+
94
+ export declare const mkdir: typeof nodeFsp.mkdir;
95
+
96
+ export declare const mkdtemp: typeof nodeFsp.mkdtemp;
97
+
98
+ /** Node 24's disposable temporary directory, built on {@link mkdtemp} and {@link rm}. */
99
+ export declare const mkdtempDisposable: (prefix: string, options?: unknown) => Promise<{
100
+ path: string;
101
+ remove(): Promise<void>;
102
+ [Symbol.asyncDispose](): Promise<void>;
103
+ }>;
104
+
105
+ export declare const open: typeof nodeFsp.open;
106
+
107
+ export declare const opendir: typeof nodeFsp.opendir;
108
+
109
+ export declare const readdir: typeof nodeFsp.readdir;
110
+
111
+ export declare const readFile: typeof nodeFsp.readFile;
112
+
113
+ export declare const readlink: typeof nodeFsp.readlink;
114
+
115
+ export declare const realpath: typeof nodeFsp.realpath;
116
+
117
+ export declare const rename: typeof nodeFsp.rename;
118
+
119
+ export declare const rm: typeof nodeFsp.rm;
120
+
121
+ export declare const rmdir: typeof nodeFsp.rmdir;
122
+
123
+ export declare const stat: typeof nodeFsp.stat;
124
+
125
+ export declare const statfs: typeof nodeFsp.statfs;
126
+
127
+ export declare const symlink: typeof nodeFsp.symlink;
128
+
129
+ export declare const truncate: typeof nodeFsp.truncate;
130
+
131
+ export declare const unlink: typeof nodeFsp.unlink;
132
+
133
+ export declare const utimes: typeof nodeFsp.utimes;
134
+
135
+ export declare const watch: typeof nodeFsp.watch;
136
+
137
+ /**
138
+ * Run `run` with `timeoutMs` as the deadline of every call it makes that names none itself,
139
+ * including calls without an options object (`open`, `stat`, a file handle's methods). Not in
140
+ * Node; with no host installed it only runs `run`.
141
+ */
142
+ export declare function withTimeout<T>(timeoutMs: number, run: () => T): T;
143
+
144
+ export declare const writeFile: typeof nodeFsp.writeFile;
145
+
146
+ /**
147
+ * Replace `path` so a reader never sees a partial file: write a temporary file beside it, flush
148
+ * it to disk, then rename it over `path`. Not in Node; works with or without a host.
149
+ */
150
+ export declare function writeFileAtomic(path: string | URL, data: string | NodeJS.ArrayBufferView, options?: {
151
+ readonly encoding?: BufferEncoding;
152
+ readonly mode?: number;
153
+ readonly timeoutMs?: number;
154
+ }): Promise<void>;
155
+
156
+ export { }