@anthropic-ai/sdk 0.119.0 → 0.120.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/CHANGELOG.md +13 -0
- package/helpers/beta/environments.d.mts +5 -4
- package/helpers/beta/environments.d.mts.map +1 -1
- package/helpers/beta/environments.d.ts +5 -4
- package/helpers/beta/environments.d.ts.map +1 -1
- package/helpers/beta/environments.js +5 -4
- package/helpers/beta/environments.js.map +1 -1
- package/helpers/beta/environments.mjs +5 -4
- package/helpers/beta/environments.mjs.map +1 -1
- package/internal/file-store.d.mts +136 -0
- package/internal/file-store.d.mts.map +1 -0
- package/internal/file-store.d.ts +136 -0
- package/internal/file-store.d.ts.map +1 -0
- package/internal/file-store.js +531 -0
- package/internal/file-store.js.map +1 -0
- package/internal/file-store.mjs +523 -0
- package/internal/file-store.mjs.map +1 -0
- package/lib/environments/poller.d.mts +6 -0
- package/lib/environments/poller.d.mts.map +1 -1
- package/lib/environments/poller.d.ts +6 -0
- package/lib/environments/poller.d.ts.map +1 -1
- package/lib/environments/poller.js +46 -1
- package/lib/environments/poller.js.map +1 -1
- package/lib/environments/poller.mjs +46 -1
- package/lib/environments/poller.mjs.map +1 -1
- package/lib/environments/worker.d.mts +89 -12
- package/lib/environments/worker.d.mts.map +1 -1
- package/lib/environments/worker.d.ts +89 -12
- package/lib/environments/worker.d.ts.map +1 -1
- package/lib/environments/worker.js +336 -67
- package/lib/environments/worker.js.map +1 -1
- package/lib/environments/worker.mjs +336 -68
- package/lib/environments/worker.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/beta/agents/agents.d.mts +322 -27
- package/resources/beta/agents/agents.d.mts.map +1 -1
- package/resources/beta/agents/agents.d.ts +322 -27
- package/resources/beta/agents/agents.d.ts.map +1 -1
- package/resources/beta/agents/agents.js.map +1 -1
- package/resources/beta/agents/agents.mjs.map +1 -1
- package/resources/beta/agents/index.d.mts +1 -1
- package/resources/beta/agents/index.d.mts.map +1 -1
- package/resources/beta/agents/index.d.ts +1 -1
- package/resources/beta/agents/index.d.ts.map +1 -1
- package/resources/beta/agents/index.js.map +1 -1
- package/resources/beta/agents/index.mjs.map +1 -1
- package/resources/beta/beta.d.mts +2 -2
- package/resources/beta/beta.d.mts.map +1 -1
- package/resources/beta/beta.d.ts +2 -2
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/environments/work.d.mts +5 -1
- package/resources/beta/environments/work.d.mts.map +1 -1
- package/resources/beta/environments/work.d.ts +5 -1
- package/resources/beta/environments/work.d.ts.map +1 -1
- package/resources/beta/environments/work.js +0 -17
- package/resources/beta/environments/work.js.map +1 -1
- package/resources/beta/environments/work.mjs +0 -17
- package/resources/beta/environments/work.mjs.map +1 -1
- package/resources/beta/index.d.mts +1 -1
- package/resources/beta/index.d.mts.map +1 -1
- package/resources/beta/index.d.ts +1 -1
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/messages/messages.d.mts +1 -1
- package/resources/beta/messages/messages.d.ts +1 -1
- package/resources/messages/messages.d.mts +1 -1
- package/resources/messages/messages.d.ts +1 -1
- package/src/helpers/beta/environments.ts +5 -4
- package/src/internal/file-store.ts +550 -0
- package/src/lib/environments/poller.ts +47 -1
- package/src/lib/environments/worker.ts +419 -79
- package/src/resources/beta/agents/agents.ts +435 -30
- package/src/resources/beta/agents/index.ts +17 -0
- package/src/resources/beta/beta.ts +34 -0
- package/src/resources/beta/environments/work.ts +7 -0
- package/src/resources/beta/index.ts +17 -0
- package/src/resources/beta/messages/messages.ts +1 -1
- package/src/resources/messages/messages.ts +1 -1
- package/src/tools/agent-toolset/fs-util.ts +40 -24
- package/src/tools/agent-toolset/memories.ts +1017 -0
- package/src/tools/agent-toolset/node.browser.ts +68 -0
- package/src/tools/agent-toolset/node.ts +139 -53
- package/src/tools/agent-toolset/skills.ts +29 -9
- package/src/tools/agent-toolset/sync-interval.ts +30 -0
- package/src/version.ts +1 -1
- package/tools/agent-toolset/fs-util.d.mts +23 -10
- package/tools/agent-toolset/fs-util.d.mts.map +1 -1
- package/tools/agent-toolset/fs-util.d.ts +23 -10
- package/tools/agent-toolset/fs-util.d.ts.map +1 -1
- package/tools/agent-toolset/fs-util.js +40 -25
- package/tools/agent-toolset/fs-util.js.map +1 -1
- package/tools/agent-toolset/fs-util.mjs +38 -25
- package/tools/agent-toolset/fs-util.mjs.map +1 -1
- package/tools/agent-toolset/memories.d.mts +173 -0
- package/tools/agent-toolset/memories.d.mts.map +1 -0
- package/tools/agent-toolset/memories.d.ts +173 -0
- package/tools/agent-toolset/memories.d.ts.map +1 -0
- package/tools/agent-toolset/memories.js +902 -0
- package/tools/agent-toolset/memories.js.map +1 -0
- package/tools/agent-toolset/memories.mjs +895 -0
- package/tools/agent-toolset/memories.mjs.map +1 -0
- package/tools/agent-toolset/node.browser.d.mts +31 -0
- package/tools/agent-toolset/node.browser.d.mts.map +1 -1
- package/tools/agent-toolset/node.browser.d.ts +31 -0
- package/tools/agent-toolset/node.browser.d.ts.map +1 -1
- package/tools/agent-toolset/node.browser.js +59 -1
- package/tools/agent-toolset/node.browser.js.map +1 -1
- package/tools/agent-toolset/node.browser.mjs +54 -0
- package/tools/agent-toolset/node.browser.mjs.map +1 -1
- package/tools/agent-toolset/node.d.mts +54 -22
- package/tools/agent-toolset/node.d.mts.map +1 -1
- package/tools/agent-toolset/node.d.ts +54 -22
- package/tools/agent-toolset/node.d.ts.map +1 -1
- package/tools/agent-toolset/node.js +83 -44
- package/tools/agent-toolset/node.js.map +1 -1
- package/tools/agent-toolset/node.mjs +77 -44
- package/tools/agent-toolset/node.mjs.map +1 -1
- package/tools/agent-toolset/skills.d.mts +16 -7
- package/tools/agent-toolset/skills.d.mts.map +1 -1
- package/tools/agent-toolset/skills.d.ts +16 -7
- package/tools/agent-toolset/skills.d.ts.map +1 -1
- package/tools/agent-toolset/skills.js +27 -9
- package/tools/agent-toolset/skills.js.map +1 -1
- package/tools/agent-toolset/skills.mjs +27 -9
- package/tools/agent-toolset/skills.mjs.map +1 -1
- package/tools/agent-toolset/sync-interval.d.mts +19 -0
- package/tools/agent-toolset/sync-interval.d.mts.map +1 -0
- package/tools/agent-toolset/sync-interval.d.ts +19 -0
- package/tools/agent-toolset/sync-interval.d.ts.map +1 -0
- package/tools/agent-toolset/sync-interval.js +29 -0
- package/tools/agent-toolset/sync-interval.js.map +1 -0
- package/tools/agent-toolset/sync-interval.mjs +25 -0
- package/tools/agent-toolset/sync-interval.mjs.map +1 -0
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.120.0 (2026-08-19)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [sdk-v0.119.0...sdk-v0.120.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/sdk-v0.119.0...sdk-v0.120.0)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
* **api:** managed agents web search config and self hosted sandbox memory ([ba8ec50](https://github.com/anthropics/anthropic-sdk-typescript/commit/ba8ec50ffe31e10781971a942d54289439307424))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Chores
|
|
13
|
+
|
|
14
|
+
* **internal:** use a single pnpm workspace lockfile ([#359](https://github.com/anthropics/anthropic-sdk-typescript/issues/359)) ([3c32145](https://github.com/anthropics/anthropic-sdk-typescript/commit/3c32145d2bc4d53888c6c6857c9af216eec95fb9))
|
|
15
|
+
|
|
3
16
|
## 0.119.0 (2026-08-19)
|
|
4
17
|
|
|
5
18
|
Full Changelog: [sdk-v0.118.0...sdk-v0.119.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/sdk-v0.118.0...sdk-v0.119.0)
|
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
* - {@link EnvironmentWorker} (`client.beta.environments.work.worker`) — the full
|
|
10
10
|
* composition: poll → set up the workdir + skills → run a
|
|
11
11
|
* {@link SessionToolRunner} while heartbeating the work-item lease →
|
|
12
|
-
* force-stop on exit
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* force-stop on exit (unless the lease was lost to another holder) → loop.
|
|
13
|
+
* Use `handleItem()` for the per-item flow when you already hold a claimed
|
|
14
|
+
* work item — with no arguments it reads the `ANTHROPIC_*` env vars that
|
|
15
|
+
* `ant worker poll --on-work` sets. The class is also exported here if you
|
|
16
|
+
* prefer `new EnvironmentWorker({ client, ... })`.
|
|
16
17
|
*
|
|
17
18
|
* The tool implementations themselves (`betaAgentToolset20260401` and the
|
|
18
19
|
* per-tool factories) live in their own Node-only module — import them directly
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environments.d.mts","sourceRoot":"","sources":["../../src/helpers/beta/environments.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"environments.d.mts","sourceRoot":"","sources":["../../src/helpers/beta/environments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,GAC9B,yCAAqC"}
|
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
* - {@link EnvironmentWorker} (`client.beta.environments.work.worker`) — the full
|
|
10
10
|
* composition: poll → set up the workdir + skills → run a
|
|
11
11
|
* {@link SessionToolRunner} while heartbeating the work-item lease →
|
|
12
|
-
* force-stop on exit
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* force-stop on exit (unless the lease was lost to another holder) → loop.
|
|
13
|
+
* Use `handleItem()` for the per-item flow when you already hold a claimed
|
|
14
|
+
* work item — with no arguments it reads the `ANTHROPIC_*` env vars that
|
|
15
|
+
* `ant worker poll --on-work` sets. The class is also exported here if you
|
|
16
|
+
* prefer `new EnvironmentWorker({ client, ... })`.
|
|
16
17
|
*
|
|
17
18
|
* The tool implementations themselves (`betaAgentToolset20260401` and the
|
|
18
19
|
* per-tool factories) live in their own Node-only module — import them directly
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environments.d.ts","sourceRoot":"","sources":["../../src/helpers/beta/environments.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"environments.d.ts","sourceRoot":"","sources":["../../src/helpers/beta/environments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,GAC9B,wCAAqC"}
|
|
@@ -12,10 +12,11 @@ exports.DEFAULT_MAX_IDLE_MS = exports.MANAGED_AGENTS_BETA = exports.SessionToolR
|
|
|
12
12
|
* - {@link EnvironmentWorker} (`client.beta.environments.work.worker`) — the full
|
|
13
13
|
* composition: poll → set up the workdir + skills → run a
|
|
14
14
|
* {@link SessionToolRunner} while heartbeating the work-item lease →
|
|
15
|
-
* force-stop on exit
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* force-stop on exit (unless the lease was lost to another holder) → loop.
|
|
16
|
+
* Use `handleItem()` for the per-item flow when you already hold a claimed
|
|
17
|
+
* work item — with no arguments it reads the `ANTHROPIC_*` env vars that
|
|
18
|
+
* `ant worker poll --on-work` sets. The class is also exported here if you
|
|
19
|
+
* prefer `new EnvironmentWorker({ client, ... })`.
|
|
19
20
|
*
|
|
20
21
|
* The tool implementations themselves (`betaAgentToolset20260401` and the
|
|
21
22
|
* per-tool factories) live in their own Node-only module — import them directly
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environments.js","sourceRoot":"","sources":["../../src/helpers/beta/environments.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"environments.js","sourceRoot":"","sources":["../../src/helpers/beta/environments.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,yDAYsC;AAXpC,mGAAA,UAAU,OAAA;AACV,0GAAA,iBAAiB,OAAA;AACjB,0GAAA,iBAAiB,OAAA;AACjB,4GAAA,mBAAmB,OAAA;AACnB,4GAAA,mBAAmB,OAAA"}
|
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
* - {@link EnvironmentWorker} (`client.beta.environments.work.worker`) — the full
|
|
10
10
|
* composition: poll → set up the workdir + skills → run a
|
|
11
11
|
* {@link SessionToolRunner} while heartbeating the work-item lease →
|
|
12
|
-
* force-stop on exit
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* force-stop on exit (unless the lease was lost to another holder) → loop.
|
|
13
|
+
* Use `handleItem()` for the per-item flow when you already hold a claimed
|
|
14
|
+
* work item — with no arguments it reads the `ANTHROPIC_*` env vars that
|
|
15
|
+
* `ant worker poll --on-work` sets. The class is also exported here if you
|
|
16
|
+
* prefer `new EnvironmentWorker({ client, ... })`.
|
|
16
17
|
*
|
|
17
18
|
* The tool implementations themselves (`betaAgentToolset20260401` and the
|
|
18
19
|
* per-tool factories) live in their own Node-only module — import them directly
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environments.mjs","sourceRoot":"","sources":["../../src/helpers/beta/environments.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"environments.mjs","sourceRoot":"","sources":["../../src/helpers/beta/environments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,GAOpB,yCAAqC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `FileStore` — one confined folder; a relative path cannot escape it.
|
|
3
|
+
*
|
|
4
|
+
* Beta scope: symlinks are refused or skipped wherever the store meets them,
|
|
5
|
+
* but there is no hardening against a process racing the store's own
|
|
6
|
+
* syscalls; fsync durability, non-POSIX hosts, and read-size caps are out of
|
|
7
|
+
* scope.
|
|
8
|
+
*/
|
|
9
|
+
/** A refused operation — input the store will not act on. OS errors propagate with their `.code`. */
|
|
10
|
+
export declare class FileStoreError extends Error {
|
|
11
|
+
static readonly ESCAPES_ROOT = "escapes the store root";
|
|
12
|
+
static readonly IS_A_SYMLINK = "is a symlink";
|
|
13
|
+
static readonly NOT_A_FILE = "is not a regular file";
|
|
14
|
+
static readonly NOT_A_DIRECTORY = "is not a directory";
|
|
15
|
+
static readonly NOT_UTF8 = "is not valid utf-8";
|
|
16
|
+
static readonly MOVE_DESTINATION_EXISTS = "already exists";
|
|
17
|
+
readonly reason: string;
|
|
18
|
+
readonly relPath: string;
|
|
19
|
+
constructor(reason: string, relPath: string);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The store's resolved root, and what {@link FileStore.dispose} will do to it.
|
|
23
|
+
*
|
|
24
|
+
* `removedOnDispose` is true when `open` found no root, so `dispose` removes
|
|
25
|
+
* it. A root that was already there is someone else's — a pre-seeded mount, a
|
|
26
|
+
* caller's workdir — and is kept.
|
|
27
|
+
*/
|
|
28
|
+
export type Root = {
|
|
29
|
+
path: string;
|
|
30
|
+
removedOnDispose: boolean;
|
|
31
|
+
};
|
|
32
|
+
/** Options for {@link FileStore.open} / {@link openFileStore}. */
|
|
33
|
+
export interface OpenFileStoreOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Restrict the store to valid UTF-8 (default `false`): a `put` of binary
|
|
36
|
+
* bytes and a `get` of a binary file are refused with
|
|
37
|
+
* {@link FileStoreError}, so a caller that decodes what `get` returns can
|
|
38
|
+
* never hit a decode error.
|
|
39
|
+
*/
|
|
40
|
+
utf8?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Resolve `root`; creates nothing — only {@link FileStore.createRoot} makes the folder. */
|
|
43
|
+
export declare function openFileStore(root: string, opts?: OpenFileStoreOptions): Promise<FileStore>;
|
|
44
|
+
/**
|
|
45
|
+
* True for a path usable verbatim as a store location: absolute, with no `..`
|
|
46
|
+
* components. Paths are judged in POSIX terms — they are wire values naming
|
|
47
|
+
* locations inside a POSIX container, not host-native paths.
|
|
48
|
+
*/
|
|
49
|
+
export declare function isPathLegal(p: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* One confined folder of regular files.
|
|
52
|
+
*
|
|
53
|
+
* Every `relPath` is relative to the root (a leading `/` also means the root)
|
|
54
|
+
* and refused with {@link FileStoreError} when it escapes. The store holds
|
|
55
|
+
* regular files only: symlinks are refused on read and skipped by listings —
|
|
56
|
+
* {@link findSymlinks} reports them. A `relPath` resolving to the root itself
|
|
57
|
+
* is banned by this interface: `put` and `get` refuse it, `move` and `remove`
|
|
58
|
+
* do nothing. A store opened with `utf8: true` refuses binary content the
|
|
59
|
+
* same way — on `put` of such bytes and on `get` of such a file. Only
|
|
60
|
+
* {@link createRoot} makes the root: writes create directories below it,
|
|
61
|
+
* never the root itself, so a root removed while the store is open stays
|
|
62
|
+
* removed and the write fails with `ENOENT`.
|
|
63
|
+
*/
|
|
64
|
+
export declare class FileStore {
|
|
65
|
+
private readonly rootPath;
|
|
66
|
+
/** True ⇒ this open created the root, so {@link dispose} removes it. */
|
|
67
|
+
private readonly removedOnDispose;
|
|
68
|
+
/** Set iff the store refuses non-UTF-8 content; {@link requireUtf8} decodes against it, on both put and get. */
|
|
69
|
+
private readonly decoder;
|
|
70
|
+
/** `hashtree`'s advisory cache; every hit re-validates against a fresh stat. */
|
|
71
|
+
private readonly hashes;
|
|
72
|
+
static isPathLegal: typeof isPathLegal;
|
|
73
|
+
/** @internal — use {@link FileStore.open} / {@link openFileStore}. */
|
|
74
|
+
constructor(root: string, removedOnDispose: boolean, utf8Only?: boolean);
|
|
75
|
+
/** Resolve `root`; creates nothing — only {@link createRoot} makes the folder. */
|
|
76
|
+
static open(root: string, opts?: OpenFileStoreOptions): Promise<FileStore>;
|
|
77
|
+
/** Create the root directory and any missing ancestors; already existing is fine. */
|
|
78
|
+
createRoot(): Promise<void>;
|
|
79
|
+
/** The resolved root, and what {@link dispose} will do to it. */
|
|
80
|
+
root(): Root;
|
|
81
|
+
/**
|
|
82
|
+
* Remove the root iff `open` created it; pre-existing roots are kept.
|
|
83
|
+
*
|
|
84
|
+
* Wired to `Symbol.asyncDispose` at runtime when the host provides it, so
|
|
85
|
+
* `await using` works on engines with explicit resource management.
|
|
86
|
+
*/
|
|
87
|
+
dispose(): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Write `data` (`string` UTF-8 or bytes) atomically to the file at `relPath`.
|
|
90
|
+
*
|
|
91
|
+
* Missing directories below the root are created; a missing root is not —
|
|
92
|
+
* the write fails with `ENOENT`.
|
|
93
|
+
*/
|
|
94
|
+
put(relPath: string, data: string | Uint8Array, opts?: {
|
|
95
|
+
executable?: boolean;
|
|
96
|
+
}): Promise<void>;
|
|
97
|
+
/** The file's bytes; `null` when absent. */
|
|
98
|
+
get(relPath: string): Promise<Uint8Array | null>;
|
|
99
|
+
/** The relative path of every file under the directory `under`. */
|
|
100
|
+
ls(under?: string): Promise<Set<string>>;
|
|
101
|
+
/**
|
|
102
|
+
* Every symlink under `under` — listings skip them and reads refuse them,
|
|
103
|
+
* so a caller that must know they exist asks here.
|
|
104
|
+
*/
|
|
105
|
+
findSymlinks(under?: string): Promise<Set<string>>;
|
|
106
|
+
/**
|
|
107
|
+
* `{relPath: sha256Hex}` of every file under the directory `under`.
|
|
108
|
+
*
|
|
109
|
+
* Unchanged files — same size, mtime, and ctime since the last call —
|
|
110
|
+
* reuse their recorded hash instead of being re-read.
|
|
111
|
+
*/
|
|
112
|
+
hashtree(under?: string): Promise<Record<string, string>>;
|
|
113
|
+
/** One file's sha256; `null` when absent. Shares {@link hashtree}'s cache. */
|
|
114
|
+
hashFile(relPath: string): Promise<string | null>;
|
|
115
|
+
/**
|
|
116
|
+
* Rename `src` to `dst`; an existing `dst` is refused. The banned store
|
|
117
|
+
* root as either end does nothing.
|
|
118
|
+
*/
|
|
119
|
+
move(src: string, dst: string): Promise<void>;
|
|
120
|
+
/** Delete a file or subtree; absent — and the banned store root — do nothing. */
|
|
121
|
+
remove(relPath: string): Promise<void>;
|
|
122
|
+
private resolveUnderRoot;
|
|
123
|
+
private requireUtf8;
|
|
124
|
+
private hashViaCache;
|
|
125
|
+
}
|
|
126
|
+
/** sha256 of a file's contents, streamed — constant memory on any file size. */
|
|
127
|
+
declare function hashFile(full: string): Promise<string>;
|
|
128
|
+
/** Test seam — the hasher, the trust margin, and the walk clock. @internal */
|
|
129
|
+
export declare const _internals: {
|
|
130
|
+
hashFile: typeof hashFile;
|
|
131
|
+
timestampTrustMarginNs: bigint;
|
|
132
|
+
nowNs: () => bigint;
|
|
133
|
+
};
|
|
134
|
+
export declare const LocalFileStore: typeof FileStore;
|
|
135
|
+
export {};
|
|
136
|
+
//# sourceMappingURL=file-store.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-store.d.mts","sourceRoot":"","sources":["../src/internal/file-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAmBH,qGAAqG;AACrG,qBAAa,cAAe,SAAQ,KAAK;IACvC,MAAM,CAAC,QAAQ,CAAC,YAAY,4BAA4B;IACxD,MAAM,CAAC,QAAQ,CAAC,YAAY,kBAAkB;IAC9C,MAAM,CAAC,QAAQ,CAAC,UAAU,2BAA2B;IACrD,MAAM,CAAC,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,CAAC;AAEF,eAAO,MAAM,cAAc,kBAAY,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `FileStore` — one confined folder; a relative path cannot escape it.
|
|
3
|
+
*
|
|
4
|
+
* Beta scope: symlinks are refused or skipped wherever the store meets them,
|
|
5
|
+
* but there is no hardening against a process racing the store's own
|
|
6
|
+
* syscalls; fsync durability, non-POSIX hosts, and read-size caps are out of
|
|
7
|
+
* scope.
|
|
8
|
+
*/
|
|
9
|
+
/** A refused operation — input the store will not act on. OS errors propagate with their `.code`. */
|
|
10
|
+
export declare class FileStoreError extends Error {
|
|
11
|
+
static readonly ESCAPES_ROOT = "escapes the store root";
|
|
12
|
+
static readonly IS_A_SYMLINK = "is a symlink";
|
|
13
|
+
static readonly NOT_A_FILE = "is not a regular file";
|
|
14
|
+
static readonly NOT_A_DIRECTORY = "is not a directory";
|
|
15
|
+
static readonly NOT_UTF8 = "is not valid utf-8";
|
|
16
|
+
static readonly MOVE_DESTINATION_EXISTS = "already exists";
|
|
17
|
+
readonly reason: string;
|
|
18
|
+
readonly relPath: string;
|
|
19
|
+
constructor(reason: string, relPath: string);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The store's resolved root, and what {@link FileStore.dispose} will do to it.
|
|
23
|
+
*
|
|
24
|
+
* `removedOnDispose` is true when `open` found no root, so `dispose` removes
|
|
25
|
+
* it. A root that was already there is someone else's — a pre-seeded mount, a
|
|
26
|
+
* caller's workdir — and is kept.
|
|
27
|
+
*/
|
|
28
|
+
export type Root = {
|
|
29
|
+
path: string;
|
|
30
|
+
removedOnDispose: boolean;
|
|
31
|
+
};
|
|
32
|
+
/** Options for {@link FileStore.open} / {@link openFileStore}. */
|
|
33
|
+
export interface OpenFileStoreOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Restrict the store to valid UTF-8 (default `false`): a `put` of binary
|
|
36
|
+
* bytes and a `get` of a binary file are refused with
|
|
37
|
+
* {@link FileStoreError}, so a caller that decodes what `get` returns can
|
|
38
|
+
* never hit a decode error.
|
|
39
|
+
*/
|
|
40
|
+
utf8?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Resolve `root`; creates nothing — only {@link FileStore.createRoot} makes the folder. */
|
|
43
|
+
export declare function openFileStore(root: string, opts?: OpenFileStoreOptions): Promise<FileStore>;
|
|
44
|
+
/**
|
|
45
|
+
* True for a path usable verbatim as a store location: absolute, with no `..`
|
|
46
|
+
* components. Paths are judged in POSIX terms — they are wire values naming
|
|
47
|
+
* locations inside a POSIX container, not host-native paths.
|
|
48
|
+
*/
|
|
49
|
+
export declare function isPathLegal(p: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* One confined folder of regular files.
|
|
52
|
+
*
|
|
53
|
+
* Every `relPath` is relative to the root (a leading `/` also means the root)
|
|
54
|
+
* and refused with {@link FileStoreError} when it escapes. The store holds
|
|
55
|
+
* regular files only: symlinks are refused on read and skipped by listings —
|
|
56
|
+
* {@link findSymlinks} reports them. A `relPath` resolving to the root itself
|
|
57
|
+
* is banned by this interface: `put` and `get` refuse it, `move` and `remove`
|
|
58
|
+
* do nothing. A store opened with `utf8: true` refuses binary content the
|
|
59
|
+
* same way — on `put` of such bytes and on `get` of such a file. Only
|
|
60
|
+
* {@link createRoot} makes the root: writes create directories below it,
|
|
61
|
+
* never the root itself, so a root removed while the store is open stays
|
|
62
|
+
* removed and the write fails with `ENOENT`.
|
|
63
|
+
*/
|
|
64
|
+
export declare class FileStore {
|
|
65
|
+
private readonly rootPath;
|
|
66
|
+
/** True ⇒ this open created the root, so {@link dispose} removes it. */
|
|
67
|
+
private readonly removedOnDispose;
|
|
68
|
+
/** Set iff the store refuses non-UTF-8 content; {@link requireUtf8} decodes against it, on both put and get. */
|
|
69
|
+
private readonly decoder;
|
|
70
|
+
/** `hashtree`'s advisory cache; every hit re-validates against a fresh stat. */
|
|
71
|
+
private readonly hashes;
|
|
72
|
+
static isPathLegal: typeof isPathLegal;
|
|
73
|
+
/** @internal — use {@link FileStore.open} / {@link openFileStore}. */
|
|
74
|
+
constructor(root: string, removedOnDispose: boolean, utf8Only?: boolean);
|
|
75
|
+
/** Resolve `root`; creates nothing — only {@link createRoot} makes the folder. */
|
|
76
|
+
static open(root: string, opts?: OpenFileStoreOptions): Promise<FileStore>;
|
|
77
|
+
/** Create the root directory and any missing ancestors; already existing is fine. */
|
|
78
|
+
createRoot(): Promise<void>;
|
|
79
|
+
/** The resolved root, and what {@link dispose} will do to it. */
|
|
80
|
+
root(): Root;
|
|
81
|
+
/**
|
|
82
|
+
* Remove the root iff `open` created it; pre-existing roots are kept.
|
|
83
|
+
*
|
|
84
|
+
* Wired to `Symbol.asyncDispose` at runtime when the host provides it, so
|
|
85
|
+
* `await using` works on engines with explicit resource management.
|
|
86
|
+
*/
|
|
87
|
+
dispose(): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Write `data` (`string` UTF-8 or bytes) atomically to the file at `relPath`.
|
|
90
|
+
*
|
|
91
|
+
* Missing directories below the root are created; a missing root is not —
|
|
92
|
+
* the write fails with `ENOENT`.
|
|
93
|
+
*/
|
|
94
|
+
put(relPath: string, data: string | Uint8Array, opts?: {
|
|
95
|
+
executable?: boolean;
|
|
96
|
+
}): Promise<void>;
|
|
97
|
+
/** The file's bytes; `null` when absent. */
|
|
98
|
+
get(relPath: string): Promise<Uint8Array | null>;
|
|
99
|
+
/** The relative path of every file under the directory `under`. */
|
|
100
|
+
ls(under?: string): Promise<Set<string>>;
|
|
101
|
+
/**
|
|
102
|
+
* Every symlink under `under` — listings skip them and reads refuse them,
|
|
103
|
+
* so a caller that must know they exist asks here.
|
|
104
|
+
*/
|
|
105
|
+
findSymlinks(under?: string): Promise<Set<string>>;
|
|
106
|
+
/**
|
|
107
|
+
* `{relPath: sha256Hex}` of every file under the directory `under`.
|
|
108
|
+
*
|
|
109
|
+
* Unchanged files — same size, mtime, and ctime since the last call —
|
|
110
|
+
* reuse their recorded hash instead of being re-read.
|
|
111
|
+
*/
|
|
112
|
+
hashtree(under?: string): Promise<Record<string, string>>;
|
|
113
|
+
/** One file's sha256; `null` when absent. Shares {@link hashtree}'s cache. */
|
|
114
|
+
hashFile(relPath: string): Promise<string | null>;
|
|
115
|
+
/**
|
|
116
|
+
* Rename `src` to `dst`; an existing `dst` is refused. The banned store
|
|
117
|
+
* root as either end does nothing.
|
|
118
|
+
*/
|
|
119
|
+
move(src: string, dst: string): Promise<void>;
|
|
120
|
+
/** Delete a file or subtree; absent — and the banned store root — do nothing. */
|
|
121
|
+
remove(relPath: string): Promise<void>;
|
|
122
|
+
private resolveUnderRoot;
|
|
123
|
+
private requireUtf8;
|
|
124
|
+
private hashViaCache;
|
|
125
|
+
}
|
|
126
|
+
/** sha256 of a file's contents, streamed — constant memory on any file size. */
|
|
127
|
+
declare function hashFile(full: string): Promise<string>;
|
|
128
|
+
/** Test seam — the hasher, the trust margin, and the walk clock. @internal */
|
|
129
|
+
export declare const _internals: {
|
|
130
|
+
hashFile: typeof hashFile;
|
|
131
|
+
timestampTrustMarginNs: bigint;
|
|
132
|
+
nowNs: () => bigint;
|
|
133
|
+
};
|
|
134
|
+
export declare const LocalFileStore: typeof FileStore;
|
|
135
|
+
export {};
|
|
136
|
+
//# sourceMappingURL=file-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-store.d.ts","sourceRoot":"","sources":["../src/internal/file-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAmBH,qGAAqG;AACrG,qBAAa,cAAe,SAAQ,KAAK;IACvC,MAAM,CAAC,QAAQ,CAAC,YAAY,4BAA4B;IACxD,MAAM,CAAC,QAAQ,CAAC,YAAY,kBAAkB;IAC9C,MAAM,CAAC,QAAQ,CAAC,UAAU,2BAA2B;IACrD,MAAM,CAAC,QAAQ,CAAC,eAAe,wBAAwB;IACvD,MAAM,CAAC,QAAQ,CAAC,QAAQ,wBAAwB;IAChD,MAAM,CAAC,QAAQ,CAAC,uBAAuB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