StorageWorkspaceRef
StorageWorkspaceRef is the discriminated union used to attach a workspace to a stored agent. It points at a workspace registered on the Mastra runtime by ID, embeds a workspace snapshot inline, or names a workspace provider registered on MastraEditor.workspaces that builds the workspace.
It's the type used by BuilderAgentDefaults.workspace and by stored agent records.
Usage exampleUsage example的直接链接
import { MastraEditor } from '@mastra/editor'
// Variant 1 — reference a runtime workspace by id
new MastraEditor({
builder: {
enabled: true,
configuration: {
agent: {
workspace: { type: 'id', workspaceId: 'builder-workspace' },
},
},
},
})
// Variant 2 — inline a workspace snapshot
new MastraEditor({
builder: {
enabled: true,
configuration: {
agent: {
workspace: {
type: 'inline',
config: {
name: 'inline-builder-workspace',
filesystem: {
provider: 'local',
config: { basePath: './agent-files' },
},
},
},
},
},
},
})
// Variant 3 — build the workspace with a registered workspace provider
new MastraEditor({
workspaces: { 'my-provider': myWorkspaceProvider },
builder: {
enabled: true,
configuration: {
agent: {
workspace: {
type: 'provider',
provider: 'my-provider',
config: { region: 'us-east-1' },
},
},
},
},
})
VariantsVariants的直接链接
{ type: 'id'; workspaceId: string }:
new Mastra({ workspace }) or mastra.addWorkspace(). The id is the join key between admin config, stored agent record, and hydration.type:
"id".workspaceId:
{ type: 'inline'; config: StorageWorkspaceSnapshotType }:
inline-<sha256(config)[:12]> and persists the snapshot, so identical inline configs are deduplicated across agents.type:
"inline".config:
StorageWorkspaceSnapshotType section below for the field list.{ type: 'provider'; provider: string; config: Record<string, unknown> }:
MastraEditor.workspaces. The ref is stored as-is in the agent snapshot; no separate workspace record is persisted.type:
"provider".provider:
new MastraEditor({ workspaces }).config:
createWorkspace(config).StorageWorkspaceSnapshotTypestorageworkspacesnapshottype的直接链接
The shape embedded under { type: 'inline', config }. Defined in @mastra/core/storage.
name:
description?:
filesystem?:
provider must match an id registered on MastraEditor.filesystems (built-in: local).sandbox?:
provider must match an id registered on MastraEditor.sandboxes (built-in: local).mounts?:
search?:
skills?:
tools?:
autoSync?:
operationTimeout?:
HydrationHydration的直接链接
StorageWorkspaceRef is resolved lazily on mastra.editor.agent.getById(), not on list(). The editor looks up filesystem and sandbox providers on MastraEditor.filesystems / MastraEditor.sandboxes and materializes a runtime Workspace. Missing providers surface as a warning and the workspace is omitted. For { type: 'provider' } refs, the editor calls createWorkspace(config) on the provider registered on MastraEditor.workspaces. An unregistered provider throws an error.
RelatedRelated的直接链接
- Workspace: Concept and worked examples.
- BuilderAgentDefaults: Where this type is pinned as the Builder default.
- MastraEditor class: Registers filesystem and sandbox providers.
- StorageBrowserRef: Sibling reference type for browser configuration.