@dbx-tools/appkit-mastra 0.6.8 → 0.6.10
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 +49 -2
- package/index.ts +14 -26
- package/lib/index.d.ts +14 -26
- package/lib/index.js +13 -26
- package/lib/src/config.d.ts +21 -0
- package/lib/src/config.js +5 -1
- package/lib/src/databricks-aitools.d.ts +73 -0
- package/lib/src/databricks-aitools.js +152 -0
- package/lib/src/filesystems.d.ts +52 -170
- package/lib/src/filesystems.js +168 -888
- package/lib/src/plugin.js +14 -2
- package/lib/src/remote-skills.d.ts +4 -4
- package/lib/src/remote-skills.js +63 -35
- package/lib/src/workspaces.d.ts +4 -0
- package/lib/src/workspaces.js +37 -13
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -10
- package/src/config.ts +27 -0
- package/src/databricks-aitools.ts +216 -0
- package/src/filesystems.ts +225 -970
- package/src/plugin.ts +14 -1
- package/src/remote-skills.ts +69 -38
- package/src/workspaces.ts +41 -16
package/lib/src/filesystems.d.ts
CHANGED
|
@@ -1,208 +1,90 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Mastra
|
|
2
|
+
* Mastra workspace filesystem adapters.
|
|
3
3
|
*
|
|
4
|
-
* {@link
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* Path helpers ({@link normalizeDatabricksBasePath}, {@link isDbfsPath}, …)
|
|
10
|
-
* are exported for tests and callers that need to reason about Databricks
|
|
11
|
-
* paths without constructing a filesystem.
|
|
4
|
+
* {@link filesystems} wraps any portable `@dbx-tools/shared-fs` {@link FileSystem}
|
|
5
|
+
* (local disk, Databricks, memory, …) as a Mastra {@link MastraFilesystem}.
|
|
6
|
+
* {@link scratchFilesystem} always returns a fresh {@link localFS.tmpFS} mount
|
|
7
|
+
* (random id root) when Mastra needs a filesystem and no other mount resolved.
|
|
12
8
|
*
|
|
13
9
|
* @module
|
|
14
10
|
*/
|
|
15
|
-
import {
|
|
11
|
+
import type { FileSystem } from "@dbx-tools/shared-fs";
|
|
16
12
|
import { MastraFilesystem } from "@mastra/core/workspace";
|
|
17
13
|
import type { CopyOptions, FileContent, FileEntry, FileStat, FilesystemInfo, ListOptions, MastraFilesystemOptions, ProviderStatus, ReadOptions, RemoveOptions, WriteOptions } from "@mastra/core/workspace";
|
|
18
|
-
/**
|
|
19
|
-
export
|
|
20
|
-
/**
|
|
21
|
-
export interface DatabricksWorkspaceFilesystemOptions extends MastraFilesystemOptions {
|
|
22
|
-
/** Unique identifier for this filesystem instance. */
|
|
14
|
+
/** Options for {@link filesystems} / {@link MastraFileSystemAdapter}. */
|
|
15
|
+
export interface MastraFileSystemAdapterOptions extends MastraFilesystemOptions {
|
|
16
|
+
/** Override the Mastra filesystem id. Defaults to the source {@link FileSystem.id}. */
|
|
23
17
|
id?: string;
|
|
24
|
-
/**
|
|
25
|
-
|
|
18
|
+
/** Override the Mastra display name. Defaults to `MastraFileSystemAdapter`. */
|
|
19
|
+
name?: string;
|
|
26
20
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
21
|
+
* Override the Mastra provider id. Defaults to the source
|
|
22
|
+
* {@link FileSystem.backend}.
|
|
29
23
|
*/
|
|
30
|
-
|
|
24
|
+
provider?: string;
|
|
31
25
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* falls back to an empty read-only namespace on failure; `true` fails init;
|
|
35
|
-
* `false` skips creation and uses the empty namespace.
|
|
36
|
-
*
|
|
37
|
-
* A successful mkdir also satisfies the write-access probe when
|
|
38
|
-
* {@link readOnly} is omitted.
|
|
26
|
+
* Force read-only mounts even when the source filesystem allows writes.
|
|
27
|
+
* The source {@link FileSystem.readOnly} flag still applies either way.
|
|
39
28
|
*/
|
|
40
|
-
mkdirs?: DatabricksMkdirsMode;
|
|
41
|
-
/** Block writes while still allowing reads. When omitted, {@link init} probes write access. */
|
|
42
29
|
readOnly?: boolean;
|
|
43
30
|
}
|
|
44
|
-
/** Normalize a Databricks base path (POSIX, no trailing slash). */
|
|
45
|
-
export declare function normalizeDatabricksBasePath(basePath: string): string;
|
|
46
|
-
/** True when `absolutePath` is served by DBFS rather than the UC Files API. */
|
|
47
|
-
export declare function isDbfsPath(absolutePath: string): boolean;
|
|
48
|
-
/** True when `absolutePath` is a Databricks workspace object path. */
|
|
49
|
-
export declare function isWorkspaceFilesPath(absolutePath: string): boolean;
|
|
50
31
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
32
|
+
* Wrap a portable {@link FileSystem} as a Mastra {@link MastraFilesystem}.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { filesystems } from "@dbx-tools/appkit-mastra";
|
|
37
|
+
* import { DatabricksFileSystem } from "@dbx-tools/databricks";
|
|
38
|
+
* import { localFS } from "@dbx-tools/fs";
|
|
39
|
+
*
|
|
40
|
+
* const volume = filesystems.filesystems(
|
|
41
|
+
* new DatabricksFileSystem({ root: "/Volumes/main/default/assets" }),
|
|
42
|
+
* );
|
|
43
|
+
* const scratch = filesystems.filesystems(localFS.tmpFS("agent-job"));
|
|
44
|
+
* ```
|
|
53
45
|
*/
|
|
54
|
-
export declare function
|
|
55
|
-
/** Map an absolute Databricks path back to the workspace namespace. */
|
|
56
|
-
export declare function toDatabricksWorkspacePath(basePath: string, absolutePath: string): string;
|
|
46
|
+
export declare function filesystems(fs: FileSystem, options?: MastraFileSystemAdapterOptions): MastraFileSystemAdapter;
|
|
57
47
|
/**
|
|
58
|
-
* Mastra
|
|
59
|
-
* {@link
|
|
60
|
-
*
|
|
61
|
-
* Workspace paths are absolute within the namespace (`/notes.md` maps to
|
|
62
|
-
* `<basePath>/notes.md`). Unity Catalog volumes use the Files API;
|
|
63
|
-
* `/dbfs/...` paths use DBFS.
|
|
48
|
+
* Thin Mastra {@link MastraFilesystem} adapter over a `@dbx-tools/shared-fs`
|
|
49
|
+
* {@link FileSystem}. Identity fields are getters that read the source on
|
|
50
|
+
* access; construction does not snapshot them.
|
|
64
51
|
*/
|
|
65
|
-
export declare class
|
|
66
|
-
readonly id: string;
|
|
67
|
-
readonly name = "DatabricksWorkspaceFilesystem";
|
|
68
|
-
readonly provider = "databricks";
|
|
69
|
-
readonly basePath: string;
|
|
52
|
+
export declare class MastraFileSystemAdapter extends MastraFilesystem {
|
|
70
53
|
status: ProviderStatus;
|
|
71
|
-
private readonly
|
|
72
|
-
private readonly
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
get
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
* @param options.readOnly - When omitted, {@link init} probes write access.
|
|
80
|
-
*/
|
|
81
|
-
constructor(options: DatabricksWorkspaceFilesystemOptions);
|
|
82
|
-
/** Resolve and sandbox a workspace-relative path under {@link basePath}. */
|
|
83
|
-
private resolvePath;
|
|
84
|
-
/** Map a Databricks absolute path back to the workspace namespace. */
|
|
85
|
-
private workspacePath;
|
|
86
|
-
/** Throw when the filesystem is read-only. */
|
|
87
|
-
private assertWritable;
|
|
88
|
-
/** Map SDK / HTTP errors to Mastra workspace filesystem errors. */
|
|
89
|
-
private rethrow;
|
|
90
|
-
/**
|
|
91
|
-
* Probe whether {@link basePath} exists and cache the result on
|
|
92
|
-
* {@link _basePathMissing}.
|
|
93
|
-
*/
|
|
94
|
-
private resolveBasePathStatus;
|
|
95
|
-
/** Delegate to {@link emptyFilesystem} when the base path is missing. */
|
|
96
|
-
private emptyFallback;
|
|
54
|
+
private readonly fs;
|
|
55
|
+
private readonly options;
|
|
56
|
+
constructor(fs: FileSystem, options?: MastraFileSystemAdapterOptions);
|
|
57
|
+
get id(): string;
|
|
58
|
+
get name(): string;
|
|
59
|
+
get provider(): string;
|
|
60
|
+
get readOnly(): boolean;
|
|
61
|
+
get basePath(): string;
|
|
97
62
|
init(): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Write and delete a ephemeral probe file to detect read-only access when
|
|
100
|
-
* {@link DatabricksWorkspaceFilesystemOptions.readOnly} was not set.
|
|
101
|
-
*
|
|
102
|
-
* @returns `true` when the probe write (and cleanup) succeeded.
|
|
103
|
-
*/
|
|
104
|
-
private probeReadOnly;
|
|
105
63
|
destroy(): Promise<void>;
|
|
106
|
-
/** Probe that `absolutePath` exists (file or directory metadata). */
|
|
107
|
-
private assertAbsoluteReadable;
|
|
108
|
-
/** Read the full contents of `absolutePath` from the matching backend. */
|
|
109
|
-
private readAbsolute;
|
|
110
|
-
/** Write `buffer` to `absolutePath` on the matching backend. */
|
|
111
|
-
private writeAbsolute;
|
|
112
|
-
/** Upload a buffer to a Unity Catalog Files API path. */
|
|
113
|
-
private uploadUcFile;
|
|
114
|
-
/** Delete a single file at `absolutePath` (non-recursive). */
|
|
115
|
-
private deleteAbsoluteFile;
|
|
116
|
-
/**
|
|
117
|
-
* Delete a file or directory at `absolutePath`.
|
|
118
|
-
*
|
|
119
|
-
* DBFS and workspace APIs accept `recursive`; UC volumes recurse manually.
|
|
120
|
-
*/
|
|
121
|
-
private deleteAbsolutePath;
|
|
122
|
-
/** Create `absolutePath` and any missing parents on the matching backend. */
|
|
123
|
-
private mkdirAbsolute;
|
|
124
|
-
private readDbfsFile;
|
|
125
|
-
private readWorkspaceFile;
|
|
126
|
-
private writeDbfsFile;
|
|
127
|
-
private writeWorkspaceFile;
|
|
128
64
|
getInfo(): FilesystemInfo<{
|
|
129
|
-
|
|
65
|
+
root: string;
|
|
66
|
+
backend: string;
|
|
130
67
|
}>;
|
|
131
68
|
getInstructions(): string;
|
|
132
|
-
/** Map a workspace-relative path to the backing Databricks absolute path. */
|
|
133
|
-
resolveAbsolutePath(inputPath: string): string | undefined;
|
|
134
|
-
/** Read file contents from the workspace namespace. */
|
|
135
69
|
readFile(inputPath: string, options?: ReadOptions): Promise<string | Buffer>;
|
|
136
|
-
/** Write file contents into the workspace namespace. */
|
|
137
70
|
writeFile(inputPath: string, content: FileContent, options?: WriteOptions): Promise<void>;
|
|
138
|
-
/** Append to an existing file, creating it when missing. */
|
|
139
71
|
appendFile(inputPath: string, content: FileContent): Promise<void>;
|
|
140
|
-
/** Delete a file in the workspace namespace. */
|
|
141
72
|
deleteFile(inputPath: string, options?: RemoveOptions): Promise<void>;
|
|
142
|
-
/** Copy a file within the workspace namespace. */
|
|
143
73
|
copyFile(src: string, dest: string, options?: CopyOptions): Promise<void>;
|
|
144
|
-
/** Move or rename a file within the workspace namespace. */
|
|
145
74
|
moveFile(src: string, dest: string, options?: CopyOptions): Promise<void>;
|
|
146
|
-
/** Create a directory in the workspace namespace. */
|
|
147
75
|
mkdir(inputPath: string, options?: {
|
|
148
76
|
recursive?: boolean;
|
|
149
77
|
}): Promise<void>;
|
|
150
|
-
/** Remove a directory from the workspace namespace. */
|
|
151
78
|
rmdir(inputPath: string, options?: RemoveOptions): Promise<void>;
|
|
152
|
-
/**
|
|
153
|
-
* Recursively delete a Unity Catalog directory tree.
|
|
154
|
-
*
|
|
155
|
-
* DBFS and workspace trees use native recursive delete via
|
|
156
|
-
* {@link deleteAbsolutePath} instead.
|
|
157
|
-
*/
|
|
158
|
-
private deleteUcDirectoryRecursive;
|
|
159
|
-
/** List entries in a workspace directory. */
|
|
160
79
|
readdir(inputPath: string, options?: ListOptions): Promise<FileEntry[]>;
|
|
161
|
-
private readDirectoryRecursive;
|
|
162
|
-
private listAbsoluteDirectory;
|
|
163
|
-
/** Apply Mastra list filters (`extension`, etc.) to directory entries. */
|
|
164
|
-
private filterEntries;
|
|
165
|
-
/** Return whether `inputPath` exists in the workspace namespace. */
|
|
166
|
-
exists(inputPath: string): Promise<boolean>;
|
|
167
|
-
/** Return file or directory metadata for `inputPath`. */
|
|
168
|
-
stat(inputPath: string): Promise<FileStat>;
|
|
169
|
-
/**
|
|
170
|
-
* Stat a Unity Catalog path by probing file metadata first, then
|
|
171
|
-
* directory metadata.
|
|
172
|
-
*/
|
|
173
|
-
private statUcAbsolute;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Read-only in-memory {@link WorkspaceFilesystem} with a single empty root.
|
|
177
|
-
* Use {@link emptyFilesystem} rather than constructing directly.
|
|
178
|
-
*/
|
|
179
|
-
declare class EmptyFilesystem extends MastraFilesystem {
|
|
180
|
-
readonly id = "empty-fs";
|
|
181
|
-
readonly name = "EmptyFilesystem";
|
|
182
|
-
readonly provider = "empty";
|
|
183
|
-
readonly readOnly = true;
|
|
184
|
-
status: ProviderStatus;
|
|
185
|
-
constructor();
|
|
186
|
-
init(): Promise<void>;
|
|
187
|
-
destroy(): Promise<void>;
|
|
188
|
-
getInfo(): FilesystemInfo;
|
|
189
|
-
getInstructions(): string;
|
|
190
|
-
private rootStat;
|
|
191
|
-
private assertWritable;
|
|
192
|
-
readFile(inputPath: string, _options?: ReadOptions): Promise<string | Buffer>;
|
|
193
|
-
writeFile(_inputPath: string, _content: FileContent, _options?: WriteOptions): Promise<void>;
|
|
194
|
-
appendFile(_inputPath: string, _content: FileContent): Promise<void>;
|
|
195
|
-
deleteFile(inputPath: string, options?: RemoveOptions): Promise<void>;
|
|
196
|
-
copyFile(src: string, _dest: string, _options?: CopyOptions): Promise<void>;
|
|
197
|
-
moveFile(src: string, dest: string, options?: CopyOptions): Promise<void>;
|
|
198
|
-
mkdir(_inputPath: string, _options?: {
|
|
199
|
-
recursive?: boolean;
|
|
200
|
-
}): Promise<void>;
|
|
201
|
-
rmdir(inputPath: string, options?: RemoveOptions): Promise<void>;
|
|
202
|
-
readdir(inputPath: string, _options?: ListOptions): Promise<FileEntry[]>;
|
|
203
80
|
exists(inputPath: string): Promise<boolean>;
|
|
204
81
|
stat(inputPath: string): Promise<FileStat>;
|
|
82
|
+
private delegate;
|
|
83
|
+
/** {@link delegate} for a mutation: refuse a read-only mount before doing any work. */
|
|
84
|
+
private delegateWrite;
|
|
85
|
+
/** When Mastra asks for non-recursive writes, require the parent directory. */
|
|
86
|
+
private assertParentExists;
|
|
87
|
+
private rethrow;
|
|
205
88
|
}
|
|
206
|
-
/**
|
|
207
|
-
export declare
|
|
208
|
-
export {};
|
|
89
|
+
/** Fresh writable local temp mount on a root unique to this call. */
|
|
90
|
+
export declare function scratchFilesystem(): MastraFileSystemAdapter;
|