@dbx-tools/appkit-mastra 0.9.99 → 0.9.105
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 +139 -217
- package/index.ts +2 -3
- package/lib/index.d.ts +2 -3
- package/lib/index.js +3 -4
- package/lib/src/agents.d.ts +2 -0
- package/lib/src/agents.js +62 -14
- package/lib/src/chat.d.ts +3 -1
- package/lib/src/chat.js +98 -12
- package/lib/src/config.d.ts +7 -1
- package/lib/src/config.js +6 -2
- package/lib/src/model.d.ts +3 -6
- package/lib/src/model.js +11 -94
- package/lib/src/monty-sandbox.d.ts +1 -2
- package/lib/src/monty-sandbox.js +3 -3
- package/lib/src/plugin.js +3 -1
- package/lib/src/workspaces.js +17 -49
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -22
- package/src/agents.ts +61 -12
- package/src/chat.ts +103 -11
- package/src/config.ts +13 -2
- package/src/model.ts +10 -108
- package/src/monty-sandbox.ts +7 -6
- package/src/plugin.ts +2 -0
- package/src/workspaces.ts +32 -74
- package/lib/src/serving-sanitize.d.ts +0 -6
- package/lib/src/serving-sanitize.js +0 -7
- package/src/serving-sanitize.ts +0 -19
package/src/workspaces.ts
CHANGED
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
import { createHash } from "node:crypto";
|
|
16
16
|
import { tmpdir } from "node:os";
|
|
17
17
|
import { join } from "node:path";
|
|
18
|
-
import { ConfigurationError, createWorkspaceClient
|
|
18
|
+
import { ConfigurationError, createWorkspaceClient } from "@databricks/appkit";
|
|
19
19
|
import type { WorkspaceClient } from "@databricks/appkit";
|
|
20
|
-
import { pluginRegistry } from "@dbx-tools/appkit";
|
|
20
|
+
import { appkit, pluginRegistry } from "@dbx-tools/appkit";
|
|
21
21
|
import {
|
|
22
22
|
filesCache as filesCachePlugin,
|
|
23
23
|
type FilesCacheExports,
|
|
@@ -38,15 +38,12 @@ import {
|
|
|
38
38
|
} from "@dbx-tools/shared-fs";
|
|
39
39
|
import type { RequestContext } from "@mastra/core/request-context";
|
|
40
40
|
import {
|
|
41
|
-
WORKSPACE_TOOLS,
|
|
42
41
|
Workspace,
|
|
43
42
|
type SkillsResolver,
|
|
44
|
-
type ToolConfigWithArgsContext,
|
|
45
43
|
type WorkspaceConfig,
|
|
46
44
|
type WorkspaceFilesystem,
|
|
47
45
|
type WorkspaceSandbox,
|
|
48
46
|
type WorkspaceSandboxResolver,
|
|
49
|
-
type WorkspaceToolConfig,
|
|
50
47
|
type WorkspaceToolsConfig,
|
|
51
48
|
} from "@mastra/core/workspace";
|
|
52
49
|
|
|
@@ -192,8 +189,10 @@ export type WorkspaceSandboxSelection =
|
|
|
192
189
|
| WorkspaceSandboxResolver;
|
|
193
190
|
|
|
194
191
|
/** Native Mastra workspace options plus Databricks path shortcuts. */
|
|
195
|
-
export interface DatabricksWorkspaceOptions
|
|
196
|
-
|
|
192
|
+
export interface DatabricksWorkspaceOptions extends Omit<
|
|
193
|
+
WorkspaceConfig,
|
|
194
|
+
"filesystem" | "mounts" | "sandbox" | "skills"
|
|
195
|
+
> {
|
|
197
196
|
/**
|
|
198
197
|
* Start from {@link DEFAULT_DATABRICKS_WORKSPACE_PATHS}. Defaults to `true`.
|
|
199
198
|
*/
|
|
@@ -396,48 +395,14 @@ export function resolveDatabricksWorkspacePaths(
|
|
|
396
395
|
|
|
397
396
|
/* ---------------------------- private helpers ---------------------------- */
|
|
398
397
|
|
|
399
|
-
/** Require approval unless a filesystem mutation stays inside a user-owned writable root. */
|
|
400
|
-
function requireApprovalOutsideWritableRoots({
|
|
401
|
-
args,
|
|
402
|
-
requestContext,
|
|
403
|
-
}: ToolConfigWithArgsContext): boolean {
|
|
404
|
-
const inputPath = args.path;
|
|
405
|
-
if (typeof inputPath !== "string" || !posixPath.isAbsolute(inputPath)) return true;
|
|
406
|
-
const normalized = posixPath.normalize(inputPath);
|
|
407
|
-
if (!normalized.ok) return true;
|
|
408
|
-
if (posixPath.isWithinRoot(SCRATCH_MOUNT, normalized.path)) return false;
|
|
409
|
-
const emailValue = requestContext[MASTRA_USER_EMAIL_KEY];
|
|
410
|
-
const email = typeof emailValue === "string" ? stringUtils.trimToNull(emailValue) : undefined;
|
|
411
|
-
if (!email) return true;
|
|
412
|
-
return !posixPath.isWithinRoot(personalWorkspacePath(email), normalized.path);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
398
|
function workspaceTools(configured: WorkspaceToolsConfig | undefined): WorkspaceToolsConfig {
|
|
416
|
-
const requireApproval: WorkspaceToolConfig =
|
|
417
|
-
configured?.requireApproval === undefined
|
|
418
|
-
? { requireApproval: requireApprovalOutsideWritableRoots }
|
|
419
|
-
: {};
|
|
420
|
-
const defaults = {
|
|
421
|
-
[WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE]: requireApproval,
|
|
422
|
-
[WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE]: requireApproval,
|
|
423
|
-
[WORKSPACE_TOOLS.FILESYSTEM.AST_EDIT]: requireApproval,
|
|
424
|
-
[WORKSPACE_TOOLS.FILESYSTEM.DELETE]: requireApproval,
|
|
425
|
-
[WORKSPACE_TOOLS.FILESYSTEM.MKDIR]: requireApproval,
|
|
426
|
-
} satisfies WorkspaceToolsConfig;
|
|
427
|
-
const configuredTools = configured as
|
|
428
|
-
Readonly<Record<string, WorkspaceToolConfig | undefined>> | undefined;
|
|
429
|
-
const mergedTools = Object.fromEntries(
|
|
430
|
-
Object.entries(defaults).map(([name, defaultConfig]) => [
|
|
431
|
-
name,
|
|
432
|
-
{ ...defaultConfig, ...configuredTools?.[name] },
|
|
433
|
-
]),
|
|
434
|
-
);
|
|
435
399
|
return {
|
|
436
|
-
|
|
400
|
+
enabled: true,
|
|
401
|
+
requireApproval: false,
|
|
437
402
|
...configured,
|
|
438
|
-
...mergedTools,
|
|
439
403
|
};
|
|
440
404
|
}
|
|
405
|
+
|
|
441
406
|
function resolveWorkspaceSandbox(
|
|
442
407
|
selection: WorkspaceSandboxSelection | undefined,
|
|
443
408
|
workspaceId: string,
|
|
@@ -586,9 +551,7 @@ async function resolveSkillFolderMounts(
|
|
|
586
551
|
const mount = configured.mount ?? configured.path;
|
|
587
552
|
mounts[mount] = userTempFilesystem(context, configured.path);
|
|
588
553
|
if (configured.readable !== false) {
|
|
589
|
-
skillPaths.push(
|
|
590
|
-
...(configured.skills ?? []).map((path) => mountedSkillPath(mount, path)),
|
|
591
|
-
);
|
|
554
|
+
skillPaths.push(...(configured.skills ?? []).map((path) => mountedSkillPath(mount, path)));
|
|
592
555
|
}
|
|
593
556
|
continue;
|
|
594
557
|
}
|
|
@@ -712,14 +675,9 @@ async function resolveCacheConfig(
|
|
|
712
675
|
value: DatabricksWorkspaceCache | undefined,
|
|
713
676
|
context: DatabricksWorkspaceContext,
|
|
714
677
|
): Promise<
|
|
715
|
-
|
|
|
716
|
-
| DatabricksWorkspaceCacheFilter
|
|
717
|
-
| readonly DatabricksWorkspaceCacheFilter[]
|
|
718
|
-
| undefined
|
|
678
|
+
boolean | DatabricksWorkspaceCacheFilter | readonly DatabricksWorkspaceCacheFilter[] | undefined
|
|
719
679
|
> {
|
|
720
|
-
return typeof value === "function"
|
|
721
|
-
? value(context)
|
|
722
|
-
: value;
|
|
680
|
+
return typeof value === "function" ? value(context) : value;
|
|
723
681
|
}
|
|
724
682
|
|
|
725
683
|
function requestContextValues(requestContext: RequestContext | undefined): Record<string, unknown> {
|
|
@@ -801,15 +759,7 @@ async function resolveFileCacheOptions(
|
|
|
801
759
|
return {
|
|
802
760
|
operations,
|
|
803
761
|
filter: (operation, path) =>
|
|
804
|
-
policies.some((policy) =>
|
|
805
|
-
cacheFilterMatches(
|
|
806
|
-
policy,
|
|
807
|
-
operation,
|
|
808
|
-
path,
|
|
809
|
-
requestContext,
|
|
810
|
-
root,
|
|
811
|
-
),
|
|
812
|
-
),
|
|
762
|
+
policies.some((policy) => cacheFilterMatches(policy, operation, path, requestContext, root)),
|
|
813
763
|
};
|
|
814
764
|
}
|
|
815
765
|
|
|
@@ -843,9 +793,7 @@ function buildMountResolvers(
|
|
|
843
793
|
const resolvers: WorkspaceMountResolver[] = [];
|
|
844
794
|
const pathCount = paths.length;
|
|
845
795
|
if (pathCount > 0) {
|
|
846
|
-
resolvers.push((context) =>
|
|
847
|
-
resolveSkillFolderMounts(paths, context, filesCache, cacheConfig),
|
|
848
|
-
);
|
|
796
|
+
resolvers.push((context) => resolveSkillFolderMounts(paths, context, filesCache, cacheConfig));
|
|
849
797
|
}
|
|
850
798
|
if (mounts && Object.keys(mounts).length > 0) resolvers.push(() => ({ mounts }));
|
|
851
799
|
resolvers.push(...localMounts);
|
|
@@ -929,15 +877,8 @@ async function databricksFilesystem(
|
|
|
929
877
|
}
|
|
930
878
|
| undefined
|
|
931
879
|
> {
|
|
932
|
-
const initialClient = workspaceClient.toLegacyWorkspaceClient(client);
|
|
933
880
|
const fs = new DatabricksFileSystem({
|
|
934
|
-
client: () =>
|
|
935
|
-
try {
|
|
936
|
-
return workspaceClient.toLegacyWorkspaceClient(getExecutionContext().client);
|
|
937
|
-
} catch {
|
|
938
|
-
return initialClient;
|
|
939
|
-
}
|
|
940
|
-
},
|
|
881
|
+
client: () => workspaceClient.toLegacyWorkspaceClient(requestWorkspaceClient(client)),
|
|
941
882
|
root,
|
|
942
883
|
readOnly,
|
|
943
884
|
createRoot,
|
|
@@ -961,6 +902,23 @@ async function databricksFilesystem(
|
|
|
961
902
|
return undefined;
|
|
962
903
|
}
|
|
963
904
|
|
|
905
|
+
/** @internal Keep service context from replacing the request-scoped workspace client. */
|
|
906
|
+
export function requestWorkspaceClient(
|
|
907
|
+
initialClient: WorkspaceClient,
|
|
908
|
+
executionContext: ReturnType<
|
|
909
|
+
typeof appkit.tryGetExecutionContext
|
|
910
|
+
> = appkit.tryGetExecutionContext(),
|
|
911
|
+
): WorkspaceClient {
|
|
912
|
+
if (
|
|
913
|
+
executionContext &&
|
|
914
|
+
"isUserContext" in executionContext &&
|
|
915
|
+
executionContext.isUserContext === true
|
|
916
|
+
) {
|
|
917
|
+
return executionContext.client;
|
|
918
|
+
}
|
|
919
|
+
return initialClient;
|
|
920
|
+
}
|
|
921
|
+
|
|
964
922
|
function verifyFirstFileSystemAccess<TFileSystem extends FileSystem>(
|
|
965
923
|
filesystem: TFileSystem,
|
|
966
924
|
readProbe: () => Promise<unknown>,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Databricks Model Serving wire repairs shared with the model gateway.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
export { applyToolReasoningCompatibility, flattenChoiceDeltaContent, flattenChoiceMessageContent, repairAssistantPrefill, rewriteServingBody, rewriteServingRequest, rewriteServingResponseBody, rewriteServingResponseStream, stripReasoningFromServingMessages, type RewrittenServingRequest, type ServingChatMessage, } from "@dbx-tools/model/serving-wire";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Databricks Model Serving wire repairs shared with the model gateway.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
export { applyToolReasoningCompatibility, flattenChoiceDeltaContent, flattenChoiceMessageContent, repairAssistantPrefill, rewriteServingBody, rewriteServingRequest, rewriteServingResponseBody, rewriteServingResponseStream, stripReasoningFromServingMessages, } from "@dbx-tools/model/serving-wire";
|
|
7
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VydmluZy1zYW5pdGl6ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zZXJ2aW5nLXNhbml0aXplLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7O0dBSUc7QUFFSCxPQUFPLEVBQ0wsK0JBQStCLEVBQy9CLHlCQUF5QixFQUN6QiwyQkFBMkIsRUFDM0Isc0JBQXNCLEVBQ3RCLGtCQUFrQixFQUNsQixxQkFBcUIsRUFDckIsMEJBQTBCLEVBQzFCLDRCQUE0QixFQUM1QixpQ0FBaUMsR0FHbEMsTUFBTSwrQkFBK0IsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogRGF0YWJyaWNrcyBNb2RlbCBTZXJ2aW5nIHdpcmUgcmVwYWlycyBzaGFyZWQgd2l0aCB0aGUgbW9kZWwgZ2F0ZXdheS5cbiAqXG4gKiBAbW9kdWxlXG4gKi9cblxuZXhwb3J0IHtcbiAgYXBwbHlUb29sUmVhc29uaW5nQ29tcGF0aWJpbGl0eSxcbiAgZmxhdHRlbkNob2ljZURlbHRhQ29udGVudCxcbiAgZmxhdHRlbkNob2ljZU1lc3NhZ2VDb250ZW50LFxuICByZXBhaXJBc3Npc3RhbnRQcmVmaWxsLFxuICByZXdyaXRlU2VydmluZ0JvZHksXG4gIHJld3JpdGVTZXJ2aW5nUmVxdWVzdCxcbiAgcmV3cml0ZVNlcnZpbmdSZXNwb25zZUJvZHksXG4gIHJld3JpdGVTZXJ2aW5nUmVzcG9uc2VTdHJlYW0sXG4gIHN0cmlwUmVhc29uaW5nRnJvbVNlcnZpbmdNZXNzYWdlcyxcbiAgdHlwZSBSZXdyaXR0ZW5TZXJ2aW5nUmVxdWVzdCxcbiAgdHlwZSBTZXJ2aW5nQ2hhdE1lc3NhZ2UsXG59IGZyb20gXCJAZGJ4LXRvb2xzL21vZGVsL3NlcnZpbmctd2lyZVwiO1xuIl19
|
package/src/serving-sanitize.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Databricks Model Serving wire repairs shared with the model gateway.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
applyToolReasoningCompatibility,
|
|
9
|
-
flattenChoiceDeltaContent,
|
|
10
|
-
flattenChoiceMessageContent,
|
|
11
|
-
repairAssistantPrefill,
|
|
12
|
-
rewriteServingBody,
|
|
13
|
-
rewriteServingRequest,
|
|
14
|
-
rewriteServingResponseBody,
|
|
15
|
-
rewriteServingResponseStream,
|
|
16
|
-
stripReasoningFromServingMessages,
|
|
17
|
-
type RewrittenServingRequest,
|
|
18
|
-
type ServingChatMessage,
|
|
19
|
-
} from "@dbx-tools/model/serving-wire";
|