@dbx-tools/appkit-mastra 0.1.111 → 0.3.1
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 +309 -344
- package/index.ts +46 -0
- package/package.json +50 -28
- package/src/agents.ts +858 -0
- package/src/chart.ts +695 -0
- package/src/config.ts +443 -0
- package/src/filesystems.ts +1090 -0
- package/src/genie.ts +1091 -0
- package/src/history.ts +297 -0
- package/src/mcp.ts +105 -0
- package/src/memory.ts +300 -0
- package/src/mlflow.ts +149 -0
- package/src/model.ts +163 -0
- package/src/observability.ts +144 -0
- package/src/pagination.ts +34 -0
- package/src/plugin.ts +804 -0
- package/src/processors.ts +168 -0
- package/src/rest.ts +67 -0
- package/src/server.ts +343 -0
- package/src/serving-sanitize.ts +167 -0
- package/src/serving.ts +97 -0
- package/src/statement.ts +89 -0
- package/src/storage-schema.ts +41 -0
- package/src/summarize.ts +176 -0
- package/src/threads.ts +338 -0
- package/src/workspaces.ts +346 -0
- package/src/writer.ts +44 -0
- package/tsconfig.json +41 -0
- package/dist/index.d.ts +0 -1676
- package/dist/index.js +0 -5337
package/dist/index.d.ts
DELETED
|
@@ -1,1676 +0,0 @@
|
|
|
1
|
-
import { Chart } from "@dbx-tools/appkit-mastra-shared";
|
|
2
|
-
import { ServingEndpointSummary } from "@dbx-tools/model";
|
|
3
|
-
import { CopyOptions, FileContent, FileEntry, FileStat, FilesystemInfo, ListOptions, MastraFilesystem, MastraFilesystemOptions, ProviderStatus, ReadOptions, RemoveOptions, SkillsResolver, Workspace, WorkspaceFilesystem, WriteOptions } from "@mastra/core/workspace";
|
|
4
|
-
import { appkitUtils, logUtils } from "@dbx-tools/shared";
|
|
5
|
-
import { RequestContext } from "@mastra/core/request-context";
|
|
6
|
-
import { WorkspaceClient } from "@databricks/sdk-experimental";
|
|
7
|
-
import * as _databricks_appkit0 from "@databricks/appkit";
|
|
8
|
-
import { BasePluginConfig, IAppRouter, Plugin, ResourceRequirement } from "@databricks/appkit";
|
|
9
|
-
import * as _mastra_core_agent0 from "@mastra/core/agent";
|
|
10
|
-
import { Agent, AgentConfig, ToolsInput } from "@mastra/core/agent";
|
|
11
|
-
import * as _mastra_core_tools0 from "@mastra/core/tools";
|
|
12
|
-
import { Tool, createTool } from "@mastra/core/tools";
|
|
13
|
-
import { z } from "zod";
|
|
14
|
-
import { MCPServer } from "@mastra/mcp";
|
|
15
|
-
import { Mastra } from "@mastra/core/mastra";
|
|
16
|
-
import express from "express";
|
|
17
|
-
import { Memory } from "@mastra/memory";
|
|
18
|
-
import { PgVectorConfig, PostgresStore, PostgresStoreConfig } from "@mastra/pg";
|
|
19
|
-
import { Pool } from "pg";
|
|
20
|
-
import { MastraServer } from "@mastra/express";
|
|
21
|
-
import * as _mastra_core_workflows0 from "@mastra/core/workflows";
|
|
22
|
-
import * as _mastra_core_vector0 from "@mastra/core/vector";
|
|
23
|
-
import * as _mastra_core_tts0 from "@mastra/core/tts";
|
|
24
|
-
import * as _mastra_core_logger0 from "@mastra/core/logger";
|
|
25
|
-
import * as _mastra_core_mcp0 from "@mastra/core/mcp";
|
|
26
|
-
import * as _mastra_core_evals0 from "@mastra/core/evals";
|
|
27
|
-
import * as _mastra_core_processors0 from "@mastra/core/processors";
|
|
28
|
-
import * as _mastra_core_memory0 from "@mastra/core/memory";
|
|
29
|
-
import * as _mastra_core_channels0 from "@mastra/core/channels";
|
|
30
|
-
export * from "@dbx-tools/appkit-mastra-shared";
|
|
31
|
-
export * from "@dbx-tools/model";
|
|
32
|
-
|
|
33
|
-
//#region packages/appkit-mastra/src/workspaces.d.ts
|
|
34
|
-
/** Per-request context for mount resolvers. */
|
|
35
|
-
interface WorkspaceMountContext {
|
|
36
|
-
requestContext?: RequestContext;
|
|
37
|
-
}
|
|
38
|
-
/** Mount map plus optional Mastra skill scan roots for one resolver. */
|
|
39
|
-
interface WorkspaceMountContribution {
|
|
40
|
-
mounts: Record<string, WorkspaceFilesystem>;
|
|
41
|
-
/** Paths within the composite namespace where `SKILL.md` files are scanned. */
|
|
42
|
-
skillPaths?: string[];
|
|
43
|
-
}
|
|
44
|
-
/** Contributes filesystem mounts (and optional skill paths) for one request. */
|
|
45
|
-
type WorkspaceMountResolver = (context: WorkspaceMountContext) => WorkspaceMountContribution | Promise<WorkspaceMountContribution>;
|
|
46
|
-
/** Options for {@link createWorkspace}. */
|
|
47
|
-
interface CreateWorkspaceOptions {
|
|
48
|
-
/** Workspace id; derived from `name` or `"workspace"` when omitted. */
|
|
49
|
-
id?: string;
|
|
50
|
-
/** Display name; derived from `id` when omitted. */
|
|
51
|
-
name?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Mount read-only Assistant skill trees from `/Workspace/.assistant/skills`
|
|
54
|
-
* and `/Users/<email>/.assistant/skills`. Defaults to `true`.
|
|
55
|
-
*/
|
|
56
|
-
assistantSkills?: boolean;
|
|
57
|
-
/** Extra per-request mount resolvers (run after built-in options). */
|
|
58
|
-
mounts?: WorkspaceMountResolver[];
|
|
59
|
-
/** Replace the auto-built dynamic skills resolver. */
|
|
60
|
-
skills?: SkillsResolver;
|
|
61
|
-
/** Forwarded to Mastra when skill discovery is enabled. */
|
|
62
|
-
checkSkillFileMtime?: boolean;
|
|
63
|
-
/** Enable BM25 keyword search over indexed workspace content. */
|
|
64
|
-
bm25?: boolean;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Create a Mastra {@link Workspace} with per-request Databricks mounts.
|
|
68
|
-
*
|
|
69
|
-
* @example Assistant skills only (default for agents in this plugin)
|
|
70
|
-
* ```ts
|
|
71
|
-
* createWorkspace()
|
|
72
|
-
* ```
|
|
73
|
-
*
|
|
74
|
-
* @example Assistant skills plus a custom mount resolver
|
|
75
|
-
* ```ts
|
|
76
|
-
* createWorkspace({
|
|
77
|
-
* assistantSkills: true,
|
|
78
|
-
* mounts: [
|
|
79
|
-
* async ({ requestContext }) => ({
|
|
80
|
-
* mounts: { "/data": myFilesystem },
|
|
81
|
-
* skillPaths: [],
|
|
82
|
-
* }),
|
|
83
|
-
* ],
|
|
84
|
-
* })
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
declare function createWorkspace(options?: CreateWorkspaceOptions): Workspace;
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region packages/appkit-mastra/src/genie.d.ts
|
|
90
|
-
/** Default alias used when a single unnamed Genie space is wired up. */
|
|
91
|
-
declare const DEFAULT_GENIE_ALIAS = "default";
|
|
92
|
-
/** Per-space Genie agent configuration. */
|
|
93
|
-
interface GenieSpaceConfig {
|
|
94
|
-
/** Genie `space_id`. Required; resolves via `client.genie.getSpace`. */
|
|
95
|
-
spaceId: string;
|
|
96
|
-
/**
|
|
97
|
-
* Optional human-readable description appended to the per-space
|
|
98
|
-
* tool descriptions so the calling LLM has hints about *what
|
|
99
|
-
* data* this space covers (e.g. "orders, returns,
|
|
100
|
-
* fulfillment"). When omitted, only the space's own
|
|
101
|
-
* `description` (fetched on first use of `get_space_description`)
|
|
102
|
-
* is shown.
|
|
103
|
-
*/
|
|
104
|
-
hint?: string;
|
|
105
|
-
}
|
|
106
|
-
/** Map of alias -> space config. Accepts either explicit objects or bare space ids. */
|
|
107
|
-
type GenieSpacesConfig = Record<string, GenieSpaceConfig | string>;
|
|
108
|
-
/**
|
|
109
|
-
* Suggested orchestration prompt for the central agent that owns
|
|
110
|
-
* the Genie tools. Compose into your agent's `instructions` to
|
|
111
|
-
* get the canonical "decompose questions, ask Genie focused
|
|
112
|
-
* sub-questions, place data / chart markers in prose" behavior:
|
|
113
|
-
*
|
|
114
|
-
* ```ts
|
|
115
|
-
* createAgent({
|
|
116
|
-
* instructions: `${myAgentInstructions}\n\n${GENIE_INSTRUCTIONS}`,
|
|
117
|
-
* tools(plugins) {
|
|
118
|
-
* return { ...plugins.genie?.toolkit() };
|
|
119
|
-
* },
|
|
120
|
-
* });
|
|
121
|
-
* ```
|
|
122
|
-
*
|
|
123
|
-
* The prompt references the bare tool names (`ask_genie`,
|
|
124
|
-
* `get_space_description`, `get_space_serialized`,
|
|
125
|
-
* `get_statement`, `prepare_chart`) used for the single-space
|
|
126
|
-
* default alias. Multi-space deployments should write their own
|
|
127
|
-
* variant that names the suffixed per-space tools
|
|
128
|
-
* (e.g. `ask_genie_sales`).
|
|
129
|
-
*/
|
|
130
|
-
declare const GENIE_INSTRUCTIONS: string;
|
|
131
|
-
/**
|
|
132
|
-
* Normalize the {@link GenieSpacesConfig} record. Bare-string
|
|
133
|
-
* entries (`{ default: "01ef..." }`) get wrapped as
|
|
134
|
-
* `{ spaceId: "01ef..." }`; object entries pass through unchanged.
|
|
135
|
-
* `undefined` and empty-string values are dropped so callers can
|
|
136
|
-
* pass `process.env.X` directly (matches AppKit `genie()`'s
|
|
137
|
-
* defensive treatment of unset env vars).
|
|
138
|
-
*/
|
|
139
|
-
declare function normalizeGenieSpaces(spaces: GenieSpacesConfig | Record<string, string | GenieSpaceConfig | undefined> | undefined): Record<string, GenieSpaceConfig>;
|
|
140
|
-
/**
|
|
141
|
-
* Discover Genie space aliases from every supported source and
|
|
142
|
-
* merge them into a single record. Precedence (highest first):
|
|
143
|
-
*
|
|
144
|
-
* 1. {@link MastraPluginConfig.genieSpaces} on the `mastra(...)`
|
|
145
|
-
* call. Explicit Mastra wiring always wins so users can
|
|
146
|
-
* override AppKit's defaults per-agent.
|
|
147
|
-
* 2. AppKit `genie({ spaces: { ... } })` plugin instance. Lets
|
|
148
|
-
* users keep using the existing AppKit config format
|
|
149
|
-
* (`genie({ spaces: { sales: "...", ops: "..." } })`)
|
|
150
|
-
* without restating the same record on the Mastra plugin.
|
|
151
|
-
* Read off the live plugin instance via a structural cast
|
|
152
|
-
* since `Plugin.config` is TS-protected (not runtime-private).
|
|
153
|
-
* 3. `DATABRICKS_GENIE_SPACE_ID` env var (registered under the
|
|
154
|
-
* well-known `default` alias). Matches the AppKit `genie()`
|
|
155
|
-
* plugin's fallback behavior so a bare `mastra()` + `genie()`
|
|
156
|
-
* pair just works.
|
|
157
|
-
*
|
|
158
|
-
* Aliases collide cleanly: a higher-precedence source's value
|
|
159
|
-
* replaces a lower one's wholesale. Sources that contribute zero
|
|
160
|
-
* aliases (or contribute only `undefined` / empty entries) are
|
|
161
|
-
* silently ignored.
|
|
162
|
-
*/
|
|
163
|
-
declare function resolveGenieSpaces(config: MastraPluginConfig, context: appkitUtils.PluginContextLike | undefined): Record<string, GenieSpaceConfig>;
|
|
164
|
-
/**
|
|
165
|
-
* Build the flat Mastra tools record for every configured Genie
|
|
166
|
-
* space. Two shared, space-agnostic tools (`get_statement`,
|
|
167
|
-
* `prepare_chart`) are registered once regardless of how many
|
|
168
|
-
* spaces are wired; the per-space tools (`ask_genie`,
|
|
169
|
-
* `get_space_description`, `get_space_serialized`) are suffixed
|
|
170
|
-
* with `_<alias>` for non-default aliases so multi-space
|
|
171
|
-
* deployments stay disambiguated.
|
|
172
|
-
*
|
|
173
|
-
* Returns a record keyed by tool id, ready to spread into the
|
|
174
|
-
* central `Agent`'s `tools` map (or surfaced via the
|
|
175
|
-
* `plugins.genie?.toolkit()` callback). Returns an empty record
|
|
176
|
-
* when `spaces` resolves to zero entries so the caller can spread
|
|
177
|
-
* safely.
|
|
178
|
-
*/
|
|
179
|
-
declare function buildGenieTools(opts: {
|
|
180
|
-
spaces: GenieSpacesConfig | Record<string, GenieSpaceConfig>;
|
|
181
|
-
config: MastraPluginConfig;
|
|
182
|
-
}): MastraTools;
|
|
183
|
-
/**
|
|
184
|
-
* Plugin-toolkit adapter so the `plugins.genie?.toolkit()` lookup
|
|
185
|
-
* inside an agent's `tools(plugins)` callback returns the
|
|
186
|
-
* flat Genie tools record instead of throwing on missing plugin.
|
|
187
|
-
* Mirrors AppKit's `PluginToolkitProvider` shape.
|
|
188
|
-
*/
|
|
189
|
-
declare function buildGenieToolkitProvider(opts: {
|
|
190
|
-
spaces: GenieSpacesConfig | Record<string, GenieSpaceConfig>;
|
|
191
|
-
config: MastraPluginConfig;
|
|
192
|
-
}): {
|
|
193
|
-
toolkit(opts?: unknown): MastraTools;
|
|
194
|
-
};
|
|
195
|
-
/**
|
|
196
|
-
* Collect the curated starter questions across every resolved Genie
|
|
197
|
-
* space, deduped and capped. Each space's `sample_questions` are
|
|
198
|
-
* fetched once (cached for {@link SUGGESTION_CACHE_TTL_MS}) via
|
|
199
|
-
* {@link getGenieSpace} + {@link genieSampleQuestions}, then merged in
|
|
200
|
-
* alias-iteration order so a single-space app surfaces that space's
|
|
201
|
-
* questions and a multi-space app round-trips breadth-first up to the
|
|
202
|
-
* cap. A per-space fetch failure degrades to "no questions for that
|
|
203
|
-
* space" (logged, not thrown) so one unreachable space never blanks
|
|
204
|
-
* the whole list. Returns `[]` when no spaces are configured.
|
|
205
|
-
*/
|
|
206
|
-
declare function collectSpaceSuggestions(opts: {
|
|
207
|
-
spaces: Record<string, GenieSpaceConfig>;
|
|
208
|
-
client: WorkspaceClient;
|
|
209
|
-
signal?: AbortSignal;
|
|
210
|
-
limit?: number;
|
|
211
|
-
}): Promise<string[]>;
|
|
212
|
-
//#endregion
|
|
213
|
-
//#region packages/appkit-mastra/src/config.d.ts
|
|
214
|
-
/**
|
|
215
|
-
* `RequestContext` key under which {@link MastraServer} stores the
|
|
216
|
-
* resolved AppKit user. `model.ts` reads it to mint user-scoped
|
|
217
|
-
* Databricks tokens.
|
|
218
|
-
*/
|
|
219
|
-
declare const MASTRA_USER_KEY = "mastra__user";
|
|
220
|
-
/**
|
|
221
|
-
* `RequestContext` keys for AppKit user metadata stamped by
|
|
222
|
-
* {@link MastraServer}. Surfaced as trace metadata via
|
|
223
|
-
* {@link TRACE_REQUEST_CONTEXT_KEYS} so traces are filterable by who
|
|
224
|
-
* issued the request without leaking the full user object.
|
|
225
|
-
*/
|
|
226
|
-
declare const MASTRA_USER_NAME_KEY = "mastra__userName";
|
|
227
|
-
declare const MASTRA_USER_EMAIL_KEY = "mastra__userEmail";
|
|
228
|
-
/**
|
|
229
|
-
* `RequestContext` key for the per-HTTP-request id stamped by
|
|
230
|
-
* {@link MastraServer}. Reads `X-Request-Id` from the incoming
|
|
231
|
-
* headers when present (so an upstream load balancer / API gateway
|
|
232
|
-
* can keep its trace correlation), falls back to a freshly minted
|
|
233
|
-
* UUID. Echoed back on the response and surfaced on every span via
|
|
234
|
-
* {@link TRACE_REQUEST_CONTEXT_KEYS} so logs and traces share a
|
|
235
|
-
* join key.
|
|
236
|
-
*/
|
|
237
|
-
declare const MASTRA_REQUEST_ID_KEY = "mastra__requestId";
|
|
238
|
-
/**
|
|
239
|
-
* `RequestContext` key for OAuth scopes parsed from the forwarded
|
|
240
|
-
* access token by {@link MastraServer.configureRequestContextScopes}.
|
|
241
|
-
* Workspace mounts that touch Databricks workspace files require
|
|
242
|
-
* `workspace` or `all-apis` in this list.
|
|
243
|
-
*/
|
|
244
|
-
declare const MASTRA_SCOPES_KEY = "mastra__scopes";
|
|
245
|
-
/**
|
|
246
|
-
* Canonical list of `RequestContext` keys we want Mastra to extract
|
|
247
|
-
* as metadata on every observability span (agent runs, model calls,
|
|
248
|
-
* tool invocations, workflow steps).
|
|
249
|
-
*
|
|
250
|
-
* Mirrors {@link https://mastra.ai/docs/observability/tracing/overview#automatic-metadata-from-requestcontext}:
|
|
251
|
-
* passed verbatim into `Observability.configs[*].requestContextKeys`,
|
|
252
|
-
* so any key listed here is read from `RequestContext` at trace
|
|
253
|
-
* start and attached as scalar span metadata. Keep the set to plain
|
|
254
|
-
* scalars - never include {@link MASTRA_USER_KEY} (it carries the
|
|
255
|
-
* full AppKit execution context with a `WorkspaceClient` reference).
|
|
256
|
-
*
|
|
257
|
-
* Order is purely cosmetic; Mastra de-dupes internally.
|
|
258
|
-
*/
|
|
259
|
-
declare const TRACE_REQUEST_CONTEXT_KEYS: readonly string[];
|
|
260
|
-
/** AppKit execution context plus the canonical user id. */
|
|
261
|
-
interface User {
|
|
262
|
-
id: string;
|
|
263
|
-
executionContext: appkitUtils.ExecutionContextLike;
|
|
264
|
-
}
|
|
265
|
-
/** PgVector config with an optional Mastra store id. */
|
|
266
|
-
type MastraMemoryConfig = PgVectorConfig & {
|
|
267
|
-
id?: string;
|
|
268
|
-
};
|
|
269
|
-
/**
|
|
270
|
-
* Fine-grained control for the optional MCP server exposure
|
|
271
|
-
* ({@link MastraPluginConfig.mcp}). Every field is optional; the object
|
|
272
|
-
* form only needs to set what differs from the defaults.
|
|
273
|
-
*/
|
|
274
|
-
interface MastraMcpConfig {
|
|
275
|
-
/**
|
|
276
|
-
* Server id used in the route path (`/mcp/<serverId>/...`) and as the
|
|
277
|
-
* MCP registry id. Defaults to the plugin's registered name.
|
|
278
|
-
*/
|
|
279
|
-
serverId?: string;
|
|
280
|
-
/** Display name advertised over MCP. Defaults to `"<displayName> MCP"`. */
|
|
281
|
-
name?: string;
|
|
282
|
-
/** Semantic version advertised over MCP. Defaults to `"1.0.0"`. */
|
|
283
|
-
version?: string;
|
|
284
|
-
/** Optional human-readable description advertised over MCP. */
|
|
285
|
-
description?: string;
|
|
286
|
-
/**
|
|
287
|
-
* Expose every registered agent as an `ask_<agentId>` MCP tool.
|
|
288
|
-
* Defaults to `true` - this is the "leverage the Mastra agents over
|
|
289
|
-
* MCP" behavior most callers want.
|
|
290
|
-
*/
|
|
291
|
-
agents?: boolean;
|
|
292
|
-
/**
|
|
293
|
-
* Also expose the plugin's ambient tools (the built-in `render_data`
|
|
294
|
-
* plus anything in `config.tools`) as MCP tools. Defaults to `false`:
|
|
295
|
-
* the ambient tools assume an in-process chat turn (they publish
|
|
296
|
-
* writer events the chat UI consumes), so they aren't useful to a
|
|
297
|
-
* standalone MCP client. Turn this on only when those tools are safe
|
|
298
|
-
* to call out-of-band.
|
|
299
|
-
*/
|
|
300
|
-
tools?: boolean;
|
|
301
|
-
/**
|
|
302
|
-
* Extra tools to expose over MCP beyond the agent / ambient sets.
|
|
303
|
-
* Use this for tools written specifically for MCP consumers.
|
|
304
|
-
*/
|
|
305
|
-
extraTools?: MastraTools;
|
|
306
|
-
}
|
|
307
|
-
/** Configuration accepted by the Mastra AppKit plugin. */
|
|
308
|
-
interface MastraPluginConfig extends BasePluginConfig {
|
|
309
|
-
/** Mastra OpenAI-compatible provider id. Defaults to `"databricks"`. */
|
|
310
|
-
providerId?: string;
|
|
311
|
-
/**
|
|
312
|
-
* PostgresStore for Mastra threads/messages. `true` reuses the
|
|
313
|
-
* `lakebase` plugin's pool; an object opens a dedicated store.
|
|
314
|
-
*/
|
|
315
|
-
storage?: boolean | PostgresStoreConfig;
|
|
316
|
-
/**
|
|
317
|
-
* PgVector store for Mastra memory recall. `true` reuses the
|
|
318
|
-
* `lakebase` plugin's pool; an object opens a dedicated store.
|
|
319
|
-
*/
|
|
320
|
-
memory?: boolean | MastraMemoryConfig;
|
|
321
|
-
/**
|
|
322
|
-
* Code-defined agents. Accepts three shapes for convenience:
|
|
323
|
-
*
|
|
324
|
-
* - **Record**: `{ analyst: def, helper: def }` - keys become the
|
|
325
|
-
* registered ids and the first key is the default.
|
|
326
|
-
* - **Single definition**: `def` - registered under
|
|
327
|
-
* `slugify(def.name)` (or `"default"` when `name` is omitted) and
|
|
328
|
-
* automatically marked as the default agent.
|
|
329
|
-
* - **Array**: `[def1, def2]` - each registered under
|
|
330
|
-
* `slugify(def.name)` (or `agent_${i}` when `name` is omitted);
|
|
331
|
-
* the first entry is the default.
|
|
332
|
-
*
|
|
333
|
-
* Each entry becomes a Mastra `Agent` reachable at
|
|
334
|
-
* `/api/<plugin>/route/chat/<id>` (the chat route also matches
|
|
335
|
-
* `:agentId`). When `agents` is omitted entirely, the plugin
|
|
336
|
-
* registers a single built-in `default` analyst so the bare
|
|
337
|
-
* `mastra()` call still mounts a working chat endpoint.
|
|
338
|
-
*
|
|
339
|
-
* @example Single-agent shorthand
|
|
340
|
-
* ```ts
|
|
341
|
-
* mastra({
|
|
342
|
-
* agents: createAgent({ instructions: "..." }),
|
|
343
|
-
* });
|
|
344
|
-
* ```
|
|
345
|
-
*
|
|
346
|
-
* @example Array
|
|
347
|
-
* ```ts
|
|
348
|
-
* mastra({
|
|
349
|
-
* agents: [
|
|
350
|
-
* createAgent({ name: "analyst", instructions: "..." }),
|
|
351
|
-
* createAgent({ name: "helper", instructions: "..." }),
|
|
352
|
-
* ],
|
|
353
|
-
* });
|
|
354
|
-
* ```
|
|
355
|
-
*
|
|
356
|
-
* @example Record (explicit ids)
|
|
357
|
-
* ```ts
|
|
358
|
-
* mastra({
|
|
359
|
-
* agents: {
|
|
360
|
-
* analyst: createAgent({ instructions: "..." }),
|
|
361
|
-
* helper: createAgent({ instructions: "..." }),
|
|
362
|
-
* },
|
|
363
|
-
* defaultAgent: "analyst",
|
|
364
|
-
* });
|
|
365
|
-
* ```
|
|
366
|
-
*/
|
|
367
|
-
agents?: Record<string, MastraAgentDefinition> | MastraAgentDefinition | MastraAgentDefinition[];
|
|
368
|
-
/**
|
|
369
|
-
* Ambient tools spread into every registered agent's tools record;
|
|
370
|
-
* per-agent tools win on key collision. Use for a small shared
|
|
371
|
-
* library; for per-agent tools set `agents[id].tools` instead.
|
|
372
|
-
*/
|
|
373
|
-
tools?: MastraTools;
|
|
374
|
-
/**
|
|
375
|
-
* Agent id used when the client doesn't specify one (the bare,
|
|
376
|
-
* un-suffixed history / suggestions routes resolve to it).
|
|
377
|
-
* Defaults to the first key in `agents` (or `"default"` when
|
|
378
|
-
* `agents` is omitted). Must match an id in `agents` when both are
|
|
379
|
-
* set; a mismatch throws at setup with the available candidates.
|
|
380
|
-
*/
|
|
381
|
-
defaultAgent?: string;
|
|
382
|
-
/**
|
|
383
|
-
* Plugin-level default model applied to every agent that omits its
|
|
384
|
-
* own `model`. Mirrors AppKit's `agents({ defaultModel })`.
|
|
385
|
-
*
|
|
386
|
-
* - `string`: shorthand for "use the OBO auto-resolver but swap the
|
|
387
|
-
* `modelId`" (e.g. `"databricks-claude-sonnet-4-6"`).
|
|
388
|
-
* - Any other Mastra `DynamicArgument<MastraModelConfig>`: passed
|
|
389
|
-
* through verbatim. Use this when you need full control over auth
|
|
390
|
-
* or `providerId`.
|
|
391
|
-
*
|
|
392
|
-
* Resolution order per agent: `def.model` → `defaultModel` →
|
|
393
|
-
* built-in `/serving-endpoints` resolver.
|
|
394
|
-
*/
|
|
395
|
-
defaultModel?: AgentConfig["model"] | string;
|
|
396
|
-
/**
|
|
397
|
-
* Allow loose model names (`"claude sonnet"`) to be fuzzy-matched
|
|
398
|
-
* against the workspace's Model Serving endpoints. Defaults to
|
|
399
|
-
* `true`; set `false` to require exact endpoint names everywhere.
|
|
400
|
-
*/
|
|
401
|
-
modelFuzzyMatch?: boolean;
|
|
402
|
-
/**
|
|
403
|
-
* Fuse.js score threshold for the fuzzy matcher (0 = exact match,
|
|
404
|
-
* 1 = anything matches). Defaults to `0.4`. Lower values reject
|
|
405
|
-
* loose matches; raise it if you have a sprawling endpoint
|
|
406
|
-
* catalogue with similar-looking names.
|
|
407
|
-
*/
|
|
408
|
-
modelFuzzyThreshold?: number;
|
|
409
|
-
/**
|
|
410
|
-
* TTL for the in-memory serving-endpoints list cache, in
|
|
411
|
-
* milliseconds. Defaults to 5 minutes. The cache is per workspace
|
|
412
|
-
* host and shared across users; concurrent callers coalesce on a
|
|
413
|
-
* single in-flight fetch.
|
|
414
|
-
*/
|
|
415
|
-
modelCacheTtlMs?: number;
|
|
416
|
-
/**
|
|
417
|
-
* Allow clients to override the active model per request via the
|
|
418
|
-
* `X-Mastra-Model` header, `?model=` query string, or `model` body
|
|
419
|
-
* field. Defaults to `true`. Disable when running multi-tenant
|
|
420
|
-
* where untrusted clients shouldn't pick the backing endpoint.
|
|
421
|
-
*/
|
|
422
|
-
modelOverride?: boolean;
|
|
423
|
-
/**
|
|
424
|
-
* Priority-ordered list of endpoint names tried *first* when no
|
|
425
|
-
* agent / plugin / env / request-override model id is set, ahead of
|
|
426
|
-
* the dynamic score-classified catalogue. The resolver picks the
|
|
427
|
-
* first id that is actually present in the workspace's
|
|
428
|
-
* `/serving-endpoints` listing.
|
|
429
|
-
*
|
|
430
|
-
* When unset, resolution is driven by the live Foundation Model API
|
|
431
|
-
* `quality` / `speed` / `cost` scores: endpoints are classified into
|
|
432
|
-
* chat classes (`classifyEndpoints`) and walked best-first
|
|
433
|
-
* (ChatThinking -> ChatBalanced -> ChatFast), with the small built-in
|
|
434
|
-
* `FALLBACK_MODEL_IDS` list as the floor when the catalogue can't be
|
|
435
|
-
* read. Set this to
|
|
436
|
-
* pin a regulated workspace to an approved subset, or to put custom
|
|
437
|
-
* endpoints in front of the auto-classified catalogue.
|
|
438
|
-
*/
|
|
439
|
-
defaultModelFallbacks?: readonly string[];
|
|
440
|
-
/**
|
|
441
|
-
* When `true` (default), every agent gets a built-in input
|
|
442
|
-
* processor that strips `chartId` fields from prior assistant
|
|
443
|
-
* tool-invocation results before they reach the model. This
|
|
444
|
-
* prevents the model from reusing turn-scoped chartIds it sees
|
|
445
|
-
* in memory recall (which would leave `[chart:<id>]` markers
|
|
446
|
-
* pointing at writer events that no longer exist).
|
|
447
|
-
*
|
|
448
|
-
* Set to `false` to opt out - useful if a non-default agent
|
|
449
|
-
* needs full visibility into prior chartIds (e.g. an audit
|
|
450
|
-
* agent reasoning about chart lineage).
|
|
451
|
-
*/
|
|
452
|
-
stripStaleCharts?: boolean;
|
|
453
|
-
/**
|
|
454
|
-
* Style guardrails appended to every agent's `instructions` to curb
|
|
455
|
-
* common LLM-isms (em dashes, emojis, sycophantic openers, throwaway
|
|
456
|
-
* closers, excessive hedging).
|
|
457
|
-
*
|
|
458
|
-
* - `undefined` (default): use the built-in
|
|
459
|
-
* `DEFAULT_STYLE_INSTRUCTIONS` from `agents.ts`.
|
|
460
|
-
* - `string`: replace the default with the supplied block.
|
|
461
|
-
* - `false`: disable entirely (agents see only their bespoke
|
|
462
|
-
* `instructions`).
|
|
463
|
-
*
|
|
464
|
-
* Appended (not prepended) so the agent's role and rules come first
|
|
465
|
-
* and the style block leans on the model's recency bias.
|
|
466
|
-
*/
|
|
467
|
-
styleInstructions?: string | false;
|
|
468
|
-
/**
|
|
469
|
-
* Genie spaces this plugin's agents can delegate to. One Mastra
|
|
470
|
-
* tool is registered per alias (`genie` for the well-known
|
|
471
|
-
* `default` alias, `genie_<alias>` otherwise). Each tool spins
|
|
472
|
-
* up a per-question Genie sub-agent that runs Databricks
|
|
473
|
-
* "agent mode" against the space, broadcasts wire events to the
|
|
474
|
-
* UI, fetches statement rows for non-empty results, and returns
|
|
475
|
-
* a `(string | data | chart)[]` summary the host UI renders
|
|
476
|
-
* inline.
|
|
477
|
-
*
|
|
478
|
-
* Entries accept either a full {@link GenieSpaceConfig} object
|
|
479
|
-
* or a bare `space_id` string when no extras are needed:
|
|
480
|
-
*
|
|
481
|
-
* ```ts
|
|
482
|
-
* mastra({
|
|
483
|
-
* genieSpaces: {
|
|
484
|
-
* default: "01ef0d3c0e1b1f4a8d2c3e4f5a6b7c8d",
|
|
485
|
-
* forecasts: { spaceId: "01ef...", hint: "weekly demand forecasts" },
|
|
486
|
-
* },
|
|
487
|
-
* });
|
|
488
|
-
* ```
|
|
489
|
-
*
|
|
490
|
-
* Reach the spaces from an agent's `tools(plugins)` callback via
|
|
491
|
-
* `plugins.genie?.toolkit()`; the resulting tools accept
|
|
492
|
-
* `{ content, conversationId? }` and return a hydrated summary.
|
|
493
|
-
*
|
|
494
|
-
* **Fallback discovery** (highest precedence first): if this
|
|
495
|
-
* field is omitted, the Genie agent also picks up spaces from
|
|
496
|
-
* (1) the AppKit `genie({ spaces: { ... } })` plugin instance
|
|
497
|
-
* when registered, and (2) the `DATABRICKS_GENIE_SPACE_ID`
|
|
498
|
-
* env var (registered under the `default` alias). This keeps
|
|
499
|
-
* existing AppKit deployments working without restating the
|
|
500
|
-
* spaces config in two places.
|
|
501
|
-
*/
|
|
502
|
-
genieSpaces?: GenieSpacesConfig;
|
|
503
|
-
/**
|
|
504
|
-
* TTL for the in-memory Genie space metadata cache, in
|
|
505
|
-
* milliseconds. Defaults to 5 minutes. The Genie agent calls
|
|
506
|
-
* `client.genie.getSpace(...)` on every cold-start to get the
|
|
507
|
-
* title / description / warehouse id; cached responses skip the
|
|
508
|
-
* round-trip and concurrent callers coalesce on a single
|
|
509
|
-
* in-flight fetch. Drop to a smaller value when analysts are
|
|
510
|
-
* actively editing space metadata and you want changes visible
|
|
511
|
-
* within seconds; raise it to amortise the round-trip when
|
|
512
|
-
* space metadata is effectively frozen.
|
|
513
|
-
*
|
|
514
|
-
* Backed by AppKit's `CacheManager`, so the cache participates
|
|
515
|
-
* in telemetry spans (`cache.getOrExecute`) and benefits from
|
|
516
|
-
* Lakebase persistence when the `lakebase` plugin is wired up.
|
|
517
|
-
*/
|
|
518
|
-
genieSpaceCacheTtlMs?: number;
|
|
519
|
-
/**
|
|
520
|
-
* Maximum LLM steps each agent gets per turn. One step = one
|
|
521
|
-
* round-trip to the underlying model (a tool call consumes a
|
|
522
|
-
* step, the final-text reply consumes one too). Applies to
|
|
523
|
-
* every agent registered through {@link MastraPluginConfig.agents}
|
|
524
|
-
* - per-agent overrides aren't surfaced yet because the same
|
|
525
|
-
* ceiling has been sufficient across every workload we've run.
|
|
526
|
-
*
|
|
527
|
-
* Defaults to {@link DEFAULT_AGENT_MAX_STEPS} (25), sized to fit
|
|
528
|
-
* a decomposed Genie turn (grounding + several `ask_genie` calls
|
|
529
|
-
* + `prepare_chart` per dataset + the final-text reply) with
|
|
530
|
-
* headroom for the model to chain a couple of follow-ups before
|
|
531
|
-
* answering. Mastra's own `agent.generate` default of 5 would
|
|
532
|
-
* cut multi-step orchestration off after 2-3 tool calls, so
|
|
533
|
-
* explicitly raising the ceiling here is what lets the
|
|
534
|
-
* agent-mode loop play out.
|
|
535
|
-
*
|
|
536
|
-
* Lower when an unusually slow or expensive model makes long
|
|
537
|
-
* turns unaffordable; raise for exploratory workloads that need
|
|
538
|
-
* to drill deep into a dataset within a single turn.
|
|
539
|
-
*/
|
|
540
|
-
agentMaxSteps?: number;
|
|
541
|
-
/**
|
|
542
|
-
* Wire Mastra spans into AppKit's global OTel pipeline via
|
|
543
|
-
* `@mastra/otel-bridge`.
|
|
544
|
-
*
|
|
545
|
-
* - `undefined` (default, auto): on only when
|
|
546
|
-
* `OTEL_EXPORTER_OTLP_ENDPOINT` or
|
|
547
|
-
* `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` is set. When unset, the
|
|
548
|
-
* bridge is skipped so Mastra does not log
|
|
549
|
-
* `[OtelBridge] No OTEL span found` on the noop tracer.
|
|
550
|
-
* - `true`: force on even without an OTLP endpoint.
|
|
551
|
-
* - `false`: force off.
|
|
552
|
-
*/
|
|
553
|
-
observability?: boolean;
|
|
554
|
-
/**
|
|
555
|
-
* Log user feedback (thumbs up/down + freeform comments) to MLflow as
|
|
556
|
-
* trace assessments, and surface the feedback controls in the chat UI.
|
|
557
|
-
*
|
|
558
|
-
* - `undefined` (default, auto): enabled only when MLflow tracing is
|
|
559
|
-
* wired - an OTLP exporter endpoint is set and an MLflow experiment
|
|
560
|
-
* is named (the same signals the observability pipeline needs to
|
|
561
|
-
* ship traces to MLflow). Otherwise off, since there'd be no trace
|
|
562
|
-
* to attach feedback to.
|
|
563
|
-
* - `true`: force on. Feedback controls show and writes are attempted
|
|
564
|
-
* regardless of env detection (use when the env is configured in a
|
|
565
|
-
* way the auto-probe doesn't recognize).
|
|
566
|
-
* - `false`: force off. No trace-id header, no feedback route, no UI.
|
|
567
|
-
*
|
|
568
|
-
* Feedback attaches to a turn's MLflow trace via the OpenTelemetry
|
|
569
|
-
* trace id the server stamps on each response; see `mlflow.ts`.
|
|
570
|
-
*/
|
|
571
|
-
feedback?: boolean;
|
|
572
|
-
/**
|
|
573
|
-
* Expose the plugin's agents (and optionally tools) as a Mastra MCP
|
|
574
|
-
* server so external MCP clients - Claude Desktop, Cursor, the Mastra
|
|
575
|
-
* playground, or another agent - can call them over the standard MCP
|
|
576
|
-
* transports. Enabled by default (agents only): wrapping the
|
|
577
|
-
* already-registered agents costs nothing extra, so the endpoint is on
|
|
578
|
-
* out of the box; only the ambient tools (which assume an in-process
|
|
579
|
-
* chat turn) stay off unless explicitly opted in.
|
|
580
|
-
*
|
|
581
|
-
* - `undefined` (default) / `true`: expose every registered agent as
|
|
582
|
-
* an `ask_<agentId>` MCP tool under a server whose id is the plugin
|
|
583
|
-
* name.
|
|
584
|
-
* - `false`: no MCP endpoints.
|
|
585
|
-
* - {@link MastraMcpConfig}: fine-grained control over the server id,
|
|
586
|
-
* advertised metadata, and which agents / tools are exposed.
|
|
587
|
-
*
|
|
588
|
-
* When enabled, the stock Mastra MCP routes mount under the plugin's
|
|
589
|
-
* base path (no bespoke route is added - the server is handed to the
|
|
590
|
-
* `Mastra` instance via `mcpServers`, which `@mastra/express` serves):
|
|
591
|
-
*
|
|
592
|
-
* - Streamable HTTP: `POST /api/<plugin>/mcp/<serverId>/mcp`
|
|
593
|
-
* - SSE (legacy): `GET /api/<plugin>/mcp/<serverId>/sse`
|
|
594
|
-
* `POST /api/<plugin>/mcp/<serverId>/messages`
|
|
595
|
-
*
|
|
596
|
-
* Requests run under the same AppKit OBO scope as the chat routes, so
|
|
597
|
-
* an agent invoked over MCP resolves its model and tools as the
|
|
598
|
-
* calling user.
|
|
599
|
-
*/
|
|
600
|
-
mcp?: boolean | MastraMcpConfig;
|
|
601
|
-
/**
|
|
602
|
-
* How much of the stock `@mastra/express` management API is reachable
|
|
603
|
-
* through the plugin mount. `@mastra/express` registers its full route
|
|
604
|
-
* table (agent inference plus admin / mutating routes: direct tool
|
|
605
|
-
* execution, workflow control, raw memory read/write, telemetry, logs,
|
|
606
|
-
* scores). AppKit already authenticates every request as the OBO user,
|
|
607
|
-
* but nothing there restricts *which* of those operations the browser
|
|
608
|
-
* client may invoke.
|
|
609
|
-
*
|
|
610
|
-
* - `"scoped"` (default): only the routes the chat client legitimately
|
|
611
|
-
* needs are dispatched to Mastra - agent inference
|
|
612
|
-
* (`stream` / `generate` / `network`), read-only agent metadata, this
|
|
613
|
-
* plugin's own OBO- and resource-scoped `/route/*` routes (history /
|
|
614
|
-
* threads), and, when {@link mcp} is enabled, the MCP transport.
|
|
615
|
-
* Everything else (tool execution, workflow control, raw memory,
|
|
616
|
-
* telemetry, logs, scores, and other mutations) is rejected with
|
|
617
|
-
* `403` before it reaches Mastra.
|
|
618
|
-
* - `"full"`: dispatch the entire stock Mastra API. Use only for a
|
|
619
|
-
* trusted first-party console that genuinely needs the management
|
|
620
|
-
* surface.
|
|
621
|
-
*/
|
|
622
|
-
apiAccess?: "scoped" | "full";
|
|
623
|
-
}
|
|
624
|
-
//#endregion
|
|
625
|
-
//#region packages/appkit-mastra/src/memory.d.ts
|
|
626
|
-
/**
|
|
627
|
-
* Builds one `Memory` per agent against a shared service-principal
|
|
628
|
-
* Lakebase pool. Per-instance state keeps the shared `PgVector` alive
|
|
629
|
-
* across calls so registering N agents stays cheap.
|
|
630
|
-
*/
|
|
631
|
-
declare class MemoryBuilder {
|
|
632
|
-
private readonly config;
|
|
633
|
-
private readonly servicePrincipalPool;
|
|
634
|
-
private sharedVector;
|
|
635
|
-
constructor(config: MastraPluginConfig, servicePrincipalPool: Pool);
|
|
636
|
-
/**
|
|
637
|
-
* Build the Mastra-instance-level storage used for workflow
|
|
638
|
-
* snapshots. Returns `undefined` when plugin-level `storage` is
|
|
639
|
-
* disabled, in which case `agent.resumeStream()` (and therefore
|
|
640
|
-
* the `requireApproval` flow) will not be available.
|
|
641
|
-
*
|
|
642
|
-
* The store lives in a dedicated `mastra_instance` schema so it
|
|
643
|
-
* never collides with per-agent {@link agentStorageSchemaName} namespaces.
|
|
644
|
-
* Workflow snapshots are not per-agent state; they belong to the
|
|
645
|
-
* `Mastra` instance that owns the workflow execution.
|
|
646
|
-
*/
|
|
647
|
-
instanceStorage(): PostgresStore | undefined;
|
|
648
|
-
/**
|
|
649
|
-
* Build a `Memory` for `agentId` after the plugin/agent cascade.
|
|
650
|
-
* Returns `undefined` when the agent has neither storage nor a
|
|
651
|
-
* vector store enabled - Mastra accepts a missing `memory` field
|
|
652
|
-
* and treats the agent as stateless.
|
|
653
|
-
*/
|
|
654
|
-
forAgent(agentId: string, def: MastraAgentDefinition): Memory | undefined;
|
|
655
|
-
private buildStorage;
|
|
656
|
-
/**
|
|
657
|
-
* Resolve the agent's vector store. Cascade:
|
|
658
|
-
*
|
|
659
|
-
* - falsy: no vector.
|
|
660
|
-
* - `boolean` / `undefined-inheriting-true`: return the shared
|
|
661
|
-
* singleton (built lazily on first call). All agents that
|
|
662
|
-
* default-enable memory write into and recall from one index.
|
|
663
|
-
* - object: build a dedicated `PgVector` for this agent.
|
|
664
|
-
*/
|
|
665
|
-
private buildVector;
|
|
666
|
-
private getSharedVector;
|
|
667
|
-
}
|
|
668
|
-
//#endregion
|
|
669
|
-
//#region packages/appkit-mastra/src/agents.d.ts
|
|
670
|
-
/**
|
|
671
|
-
* Tool record accepted by every Mastra `Agent.tools` field and by the
|
|
672
|
-
* `tools(plugins)` callback on {@link MastraAgentDefinition}.
|
|
673
|
-
*
|
|
674
|
-
* Alias of Mastra's `ToolsInput`, so it already accepts:
|
|
675
|
-
*
|
|
676
|
-
* - Mastra tools built with {@link createTool} (or `new Tool(...)`)
|
|
677
|
-
* - Mastra tools built with the AppKit-shaped {@link tool} wrapper
|
|
678
|
-
* below
|
|
679
|
-
* - Vercel AI SDK tools (`tool({ ... })` from `ai`)
|
|
680
|
-
* - Provider-defined tools (e.g. `openai.tools.webSearch(...)`)
|
|
681
|
-
*
|
|
682
|
-
* Existing tool libraries drop in as-is - nothing in this package
|
|
683
|
-
* forces a rebuild.
|
|
684
|
-
*/
|
|
685
|
-
type MastraTools = ToolsInput;
|
|
686
|
-
/**
|
|
687
|
-
* AppKit-shaped tool factory. Lets users mix-and-match tools across
|
|
688
|
-
* AppKit's `agents` plugin and `mastra` with a single import:
|
|
689
|
-
*
|
|
690
|
-
* ```ts
|
|
691
|
-
* import { tool } from "@dbx-tools/appkit-mastra";
|
|
692
|
-
* import { z } from "zod";
|
|
693
|
-
*
|
|
694
|
-
* get_weather: tool({
|
|
695
|
-
* description: "Weather",
|
|
696
|
-
* schema: z.object({ city: z.string() }),
|
|
697
|
-
* execute: async ({ city }) => `Sunny in ${city}`,
|
|
698
|
-
* }),
|
|
699
|
-
* ```
|
|
700
|
-
*
|
|
701
|
-
* Maps onto Mastra's `createTool`:
|
|
702
|
-
*
|
|
703
|
-
* - `description` -> `description` (required)
|
|
704
|
-
* - `schema` -> `inputSchema` (optional)
|
|
705
|
-
* - `execute(input)` -> `execute(input, ctx)` - Mastra already calls
|
|
706
|
-
* the first arg with the parsed inputs, so the body shape is
|
|
707
|
-
* identical. The Mastra `context` arg is forwarded as the second
|
|
708
|
-
* parameter when the caller declares it.
|
|
709
|
-
* - `id`: optional. Defaults to a stable identifier derived from
|
|
710
|
-
* `description` (slugified, with a short hash suffix for
|
|
711
|
-
* uniqueness). Pass an explicit `id` when you need a stable string
|
|
712
|
-
* for tracing or MCP exposure.
|
|
713
|
-
*
|
|
714
|
-
* Reach for {@link createTool} when you need Mastra-only fields
|
|
715
|
-
* (`outputSchema`, `suspendSchema`, `requireApproval`, `mcp`, etc.).
|
|
716
|
-
*/
|
|
717
|
-
declare function tool(opts: AppKitToolOptions): Tool;
|
|
718
|
-
/**
|
|
719
|
-
* Input shape for the AppKit-style {@link tool} factory. A trimmed
|
|
720
|
-
* subset of Mastra's `createTool` options that mirrors the
|
|
721
|
-
* `@databricks/appkit/beta` `tool({ description, schema, execute })`
|
|
722
|
-
* signature.
|
|
723
|
-
*
|
|
724
|
-
* Generics are intentionally absent - inference flows through the
|
|
725
|
-
* caller's `schema` (typically a Zod object), and the `execute` body
|
|
726
|
-
* destructures naturally from that. Reach for {@link createTool} when
|
|
727
|
-
* you need the fully-typed input/output schemas wired explicitly.
|
|
728
|
-
*/
|
|
729
|
-
interface AppKitToolOptions {
|
|
730
|
-
/** Optional stable identifier; auto-derived from `description` when omitted. */
|
|
731
|
-
id?: string;
|
|
732
|
-
/** Human-readable description shown to the model. Required. */
|
|
733
|
-
description: string;
|
|
734
|
-
/**
|
|
735
|
-
* Optional input schema (any Standard Schema instance, e.g. Zod).
|
|
736
|
-
* Maps to Mastra's `inputSchema`; passed through to the model
|
|
737
|
-
* verbatim.
|
|
738
|
-
*/
|
|
739
|
-
schema?: unknown;
|
|
740
|
-
/**
|
|
741
|
-
* Execute body. First arg is the parsed input (typed off `schema`
|
|
742
|
-
* when supplied), second arg is the full Mastra execution context
|
|
743
|
-
* (request context, abort signal, mastra instance) if you need it.
|
|
744
|
-
*/
|
|
745
|
-
execute: (input: any, context?: unknown) => unknown;
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Identity helper that brands a definition as a Mastra agent. Mirrors
|
|
749
|
-
* AppKit's `createAgent(def)` so the registration shape matches:
|
|
750
|
-
*
|
|
751
|
-
* ```ts
|
|
752
|
-
* const support = createAgent({
|
|
753
|
-
* instructions: "...",
|
|
754
|
-
* model: "databricks-claude-sonnet-4-6",
|
|
755
|
-
* tools(plugins) { return { ... }; },
|
|
756
|
-
* });
|
|
757
|
-
* ```
|
|
758
|
-
*
|
|
759
|
-
* Returns the definition unchanged - the wrapper exists only to anchor
|
|
760
|
-
* type inference and to match the AppKit API surface.
|
|
761
|
-
*/
|
|
762
|
-
declare function createAgent<T extends MastraAgentDefinition>(def: T): T;
|
|
763
|
-
/**
|
|
764
|
-
* Filter / rename options accepted by every plugin's `.toolkit()`
|
|
765
|
-
* method. Mirrors AppKit's `ToolkitOptions` verbatim so options pass
|
|
766
|
-
* through unchanged - the underlying AppKit plugin does the filtering
|
|
767
|
-
* and we just adapt the resulting entries into Mastra tools.
|
|
768
|
-
*/
|
|
769
|
-
interface ToolkitOptions {
|
|
770
|
-
/**
|
|
771
|
-
* Key prefix prepended to every tool name. AppKit's default is
|
|
772
|
-
* `${pluginName}.` when omitted; pass an explicit `""` to drop it.
|
|
773
|
-
*/
|
|
774
|
-
prefix?: string;
|
|
775
|
-
/** Allowlist of local tool names. */
|
|
776
|
-
only?: string[];
|
|
777
|
-
/** Denylist of local tool names. */
|
|
778
|
-
except?: string[];
|
|
779
|
-
/** Remap specific local names to different keys. */
|
|
780
|
-
rename?: Record<string, string>;
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* Toolkit provider shape every entry in the {@link MastraPlugins} map
|
|
784
|
-
* exposes. Identical to AppKit's `PluginToolkitProvider` - any AppKit
|
|
785
|
-
* plugin that implements the standard `ToolProvider` interface
|
|
786
|
-
* (`getAgentTools` + `executeAgentTool` + `toolkit`) is reachable
|
|
787
|
-
* through this surface automatically.
|
|
788
|
-
*/
|
|
789
|
-
interface MastraPluginToolkitProvider {
|
|
790
|
-
/**
|
|
791
|
-
* Returns a Mastra-shaped tools record adapted from the plugin's
|
|
792
|
-
* agent tools. Each tool dispatches back through the plugin's
|
|
793
|
-
* `executeAgentTool` so OBO auth and telemetry spans stay intact.
|
|
794
|
-
*/
|
|
795
|
-
toolkit(opts?: ToolkitOptions): MastraTools;
|
|
796
|
-
}
|
|
797
|
-
/**
|
|
798
|
-
* Plugin map handed to the function form of
|
|
799
|
-
* {@link MastraAgentDefinition.tools}. Mirrors AppKit's `Plugins`
|
|
800
|
-
* type exactly: a string-keyed record where every value exposes
|
|
801
|
-
* `.toolkit(opts)`.
|
|
802
|
-
*
|
|
803
|
-
* Implemented as a runtime Proxy that auto-discovers any registered
|
|
804
|
-
* AppKit plugin implementing the standard `ToolProvider` interface
|
|
805
|
-
* (`analytics`, `files`, `lakebase`, `genie`, plus any third-party
|
|
806
|
-
* plugin that does the same). Unknown names resolve to `undefined`
|
|
807
|
-
* at runtime, so guard with `?.` and `?? {}` when spreading from a
|
|
808
|
-
* plugin that may not be registered in every environment.
|
|
809
|
-
*
|
|
810
|
-
* @example
|
|
811
|
-
* ```ts
|
|
812
|
-
* createAgent({
|
|
813
|
-
* instructions: "...",
|
|
814
|
-
* tools(plugins) {
|
|
815
|
-
* return {
|
|
816
|
-
* ...plugins.analytics.toolkit(),
|
|
817
|
-
* ...plugins.files.toolkit({ only: ["uploads.read"] }),
|
|
818
|
-
* get_weather: tool({
|
|
819
|
-
* description: "Weather",
|
|
820
|
-
* schema: z.object({ city: z.string() }),
|
|
821
|
-
* execute: async ({ city }) => `Sunny in ${city}`,
|
|
822
|
-
* }),
|
|
823
|
-
* };
|
|
824
|
-
* },
|
|
825
|
-
* });
|
|
826
|
-
* ```
|
|
827
|
-
*/
|
|
828
|
-
type MastraPlugins = Record<string, MastraPluginToolkitProvider>;
|
|
829
|
-
/** Function form of {@link MastraAgentDefinition.tools}. */
|
|
830
|
-
type MastraToolsFn = (plugins: MastraPlugins) => MastraTools | Promise<MastraTools>;
|
|
831
|
-
/** Function form of {@link MastraAgentDefinition.workspace}. */
|
|
832
|
-
type MastraAgentWorkspaceResolver = () => Workspace | undefined;
|
|
833
|
-
/**
|
|
834
|
-
* A code-defined Mastra agent. Mirrors the shape AppKit's `agents`
|
|
835
|
-
* plugin uses for `AgentDefinition`. The registry key under
|
|
836
|
-
* `config.agents` is the `agentId` the client streams against; `name`
|
|
837
|
-
* is purely informational (defaults to the key).
|
|
838
|
-
*/
|
|
839
|
-
interface MastraAgentDefinition {
|
|
840
|
-
/** Display name used as `Agent.name`. Defaults to the registry key. */
|
|
841
|
-
name?: string;
|
|
842
|
-
/** Optional long-form description; surfaced as `Agent.description`. */
|
|
843
|
-
description?: string;
|
|
844
|
-
/** System prompt body. */
|
|
845
|
-
instructions: string;
|
|
846
|
-
/**
|
|
847
|
-
* Per-agent model override.
|
|
848
|
-
*
|
|
849
|
-
* - `undefined` (default): falls back to the workspace
|
|
850
|
-
* `/serving-endpoints` resolver that {@link buildModel} configures
|
|
851
|
-
* from the per-request `WorkspaceClient`.
|
|
852
|
-
* - `string`: shorthand for "use the default resolver but swap the
|
|
853
|
-
* `modelId`" (e.g. `"databricks-meta-llama-3-3-70b-instruct"`).
|
|
854
|
-
* - Any other Mastra `DynamicArgument<MastraModelConfig>`: passed
|
|
855
|
-
* straight through to `Agent.model`. Use this when you need full
|
|
856
|
-
* control over auth or providerId.
|
|
857
|
-
*/
|
|
858
|
-
model?: AgentConfig["model"] | string;
|
|
859
|
-
/**
|
|
860
|
-
* Per-agent tool record. Either a plain map or a callback that
|
|
861
|
-
* receives the typed {@link MastraPlugins} sibling-plugin index and
|
|
862
|
-
* returns a map. The callback runs exactly once at agent setup; the
|
|
863
|
-
* result is cached for the agent's lifetime.
|
|
864
|
-
*/
|
|
865
|
-
tools?: MastraTools | MastraToolsFn;
|
|
866
|
-
/**
|
|
867
|
-
* Per-agent semantic recall (PgVector) override. Cascades from
|
|
868
|
-
* `config.memory`; the agent value wins when set.
|
|
869
|
-
*
|
|
870
|
-
* - `undefined` (default): inherit `config.memory`. When that's
|
|
871
|
-
* enabled, the agent **shares the plugin-level singleton `PgVector`
|
|
872
|
-
* instance** (cross-agent semantic recall across the same index).
|
|
873
|
-
* - `false`: disable semantic recall for this agent only.
|
|
874
|
-
* - `true`: enable using the shared singleton (same as default when
|
|
875
|
-
* plugin memory is enabled; useful to opt in when plugin disabled).
|
|
876
|
-
* - {@link MastraMemoryConfig} object: dedicated `PgVector` for this
|
|
877
|
-
* agent (private recall index). Bypasses the shared singleton.
|
|
878
|
-
*/
|
|
879
|
-
memory?: boolean | MastraMemoryConfigOverride;
|
|
880
|
-
/**
|
|
881
|
-
* Per-agent thread/message storage (`PostgresStore`) override.
|
|
882
|
-
* Cascades from `config.storage`; the agent value wins when set.
|
|
883
|
-
*
|
|
884
|
-
* - `undefined` (default): inherit `config.storage`. When that's
|
|
885
|
-
* enabled, the agent gets its **own per-agent `PostgresStore`**
|
|
886
|
-
* keyed by {@link agentStorageSchemaName} so threads and
|
|
887
|
-
* messages stay isolated between agents in the same database.
|
|
888
|
-
* - `false`: disable storage for this agent only (purely in-memory).
|
|
889
|
-
* - `true`: enable with the per-agent default schema.
|
|
890
|
-
* - {@link MastraStorageConfigOverride} object: dedicated
|
|
891
|
-
* `PostgresStore` config (custom schema, connection, etc.).
|
|
892
|
-
*/
|
|
893
|
-
storage?: boolean | MastraStorageConfigOverride;
|
|
894
|
-
/**
|
|
895
|
-
* Mastra {@link Workspace} for this agent (filesystem, sandbox, or other
|
|
896
|
-
* providers). Assistant skills from Databricks workspace paths are wired
|
|
897
|
-
* via {@link createWorkspace}.
|
|
898
|
-
*/
|
|
899
|
-
workspace?: Workspace | MastraAgentWorkspaceResolver;
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* Distributive `Omit` so unions in `PostgresStoreConfig` /
|
|
903
|
-
* `PgVectorConfig` keep their discriminants after the override types
|
|
904
|
-
* strip `id`. The built-in `Omit` collapses unions to one shape with
|
|
905
|
-
* common fields only, which loses the connection-style discriminants.
|
|
906
|
-
*/
|
|
907
|
-
type DistributiveOmit<T, K extends keyof never> = T extends unknown ? Omit<T, K> : never;
|
|
908
|
-
/**
|
|
909
|
-
* `PostgresStoreConfig` minus `id` - per-agent overrides accept any
|
|
910
|
-
* Mastra-supported storage shape. `id` is filled in automatically
|
|
911
|
-
* from the agent registry key so traces stay stable.
|
|
912
|
-
*/
|
|
913
|
-
type MastraStorageConfigOverride = DistributiveOmit<PostgresStoreConfig, "id"> & {
|
|
914
|
-
id?: string;
|
|
915
|
-
};
|
|
916
|
-
/**
|
|
917
|
-
* `PgVectorConfig` minus `id` - per-agent overrides accept any
|
|
918
|
-
* Mastra-supported vector shape. `id` is filled in automatically
|
|
919
|
-
* from the agent registry key.
|
|
920
|
-
*/
|
|
921
|
-
type MastraMemoryConfigOverride = DistributiveOmit<PgVectorConfig, "id"> & {
|
|
922
|
-
id?: string;
|
|
923
|
-
};
|
|
924
|
-
/** Output of {@link buildAgents}: resolved agents plus the default id. */
|
|
925
|
-
interface BuiltAgents {
|
|
926
|
-
agents: Record<string, Agent>;
|
|
927
|
-
defaultAgentId: string;
|
|
928
|
-
/**
|
|
929
|
-
* Ambient tools shared across every agent (the built-in system tools
|
|
930
|
-
* spread with `config.tools`). Surfaced so the optional MCP server
|
|
931
|
-
* can re-expose them when {@link MastraMcpConfig.tools} is enabled.
|
|
932
|
-
*/
|
|
933
|
-
ambientTools: MastraTools;
|
|
934
|
-
}
|
|
935
|
-
/** Fallback agent id used when `config.agents` is omitted entirely. */
|
|
936
|
-
declare const FALLBACK_AGENT_ID = "default";
|
|
937
|
-
/**
|
|
938
|
-
* Default per-turn step ceiling applied to every registered agent
|
|
939
|
-
* when {@link MastraPluginConfig.agentMaxSteps} is unset. Sized to
|
|
940
|
-
* fit a decomposed Genie turn (grounding + several `ask_genie`
|
|
941
|
-
* calls + `prepare_chart` per dataset + the final-text reply) with
|
|
942
|
-
* headroom for the model to chain a couple of follow-ups before
|
|
943
|
-
* answering - well above Mastra's own `agent.generate` default of
|
|
944
|
-
* 5, which would cut multi-step orchestration off mid-loop.
|
|
945
|
-
*/
|
|
946
|
-
declare const DEFAULT_AGENT_MAX_STEPS = 25;
|
|
947
|
-
/**
|
|
948
|
-
* Style guardrails appended to every agent's `instructions` to curb
|
|
949
|
-
* common LLM-isms (em dashes, emojis, sycophantic openers, excessive
|
|
950
|
-
* hedging, throwaway closers). Appended rather than prepended so the
|
|
951
|
-
* agent's role/context comes first; the model's recency bias then
|
|
952
|
-
* helps the style rules dominate the response surface.
|
|
953
|
-
*
|
|
954
|
-
* Override globally via {@link MastraPluginConfig.styleInstructions}
|
|
955
|
-
* (pass `false` to disable entirely, or a string to replace).
|
|
956
|
-
*/
|
|
957
|
-
declare const DEFAULT_STYLE_INSTRUCTIONS: string;
|
|
958
|
-
/**
|
|
959
|
-
* Resolve every entry in `config.agents` into a Mastra `Agent`
|
|
960
|
-
* instance. When `config.agents` is omitted the plugin registers a
|
|
961
|
-
* single built-in `default` analyst so the bare `mastra()` call still
|
|
962
|
-
* yields a working agent.
|
|
963
|
-
*
|
|
964
|
-
* Per-agent tool callbacks are invoked once with a typed
|
|
965
|
-
* {@link MastraPlugins} index built from registered sibling plugins
|
|
966
|
-
* (currently `genie`; extend `MastraPlugins` to surface more).
|
|
967
|
-
*
|
|
968
|
-
* @throws when `config.defaultAgent` is set to an id that isn't in the
|
|
969
|
-
* resolved registry; this is a wiring bug, not a runtime condition.
|
|
970
|
-
*/
|
|
971
|
-
declare function buildAgents(opts: {
|
|
972
|
-
config: MastraPluginConfig;
|
|
973
|
-
context: appkitUtils.PluginContextLike | undefined;
|
|
974
|
-
memoryBuilder?: MemoryBuilder;
|
|
975
|
-
log: logUtils.Logger;
|
|
976
|
-
}): Promise<BuiltAgents>;
|
|
977
|
-
/**
|
|
978
|
-
* Tool ids on `tools` that are approval-gated (`requireApproval: true`).
|
|
979
|
-
* Keys are used as a fallback when a tool omits an explicit `id`.
|
|
980
|
-
*/
|
|
981
|
-
declare function approvalGatedToolIds(tools: MastraTools): string[];
|
|
982
|
-
//#endregion
|
|
983
|
-
//#region packages/appkit-mastra/src/chart.d.ts
|
|
984
|
-
/**
|
|
985
|
-
* Canonical planner input shape. Tools that source rows from an
|
|
986
|
-
* inline dataset (`render_data`) use it as their `inputSchema`
|
|
987
|
-
* verbatim; tools that resolve rows from a remote (`prepare_chart`
|
|
988
|
-
* over a Genie statement) `omit({ data })` and `extend` with their
|
|
989
|
-
* own identifier field, so the field-level `.describe()` text
|
|
990
|
-
* stays a single source of truth. Server-only - the UI never
|
|
991
|
-
* sees a planner request, only the resolved {@link Chart}.
|
|
992
|
-
*/
|
|
993
|
-
declare const chartPlannerRequestSchema: z.ZodObject<{
|
|
994
|
-
title: z.ZodString;
|
|
995
|
-
description: z.ZodOptional<z.ZodString>;
|
|
996
|
-
data: z.ZodReadonly<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
997
|
-
}, z.core.$strip>;
|
|
998
|
-
type ChartPlannerRequest = z.infer<typeof chartPlannerRequestSchema>;
|
|
999
|
-
/** Inputs to {@link prepareChart}. */
|
|
1000
|
-
interface PrepareChartOptions {
|
|
1001
|
-
/** Plugin config; resolves the planner agent's model. */
|
|
1002
|
-
config: MastraPluginConfig;
|
|
1003
|
-
/** Display title forwarded to the planner agent. */
|
|
1004
|
-
title?: string;
|
|
1005
|
-
/** Optional intent hint forwarded to the planner agent. */
|
|
1006
|
-
description?: string;
|
|
1007
|
-
/**
|
|
1008
|
-
* Resolves the rows to chart. Called once, in the background.
|
|
1009
|
-
* Any thrown error lands in the cache as the entry's `error`
|
|
1010
|
-
* field (never propagated to the caller of {@link prepareChart}).
|
|
1011
|
-
* An empty `rows` array is rejected as `"dataset has no rows;
|
|
1012
|
-
* nothing to chart"`.
|
|
1013
|
-
*/
|
|
1014
|
-
resolveData: (signal?: AbortSignal) => Promise<{
|
|
1015
|
-
rows: ReadonlyArray<Record<string, unknown>>;
|
|
1016
|
-
}>;
|
|
1017
|
-
/**
|
|
1018
|
-
* Per-request `RequestContext`. Forwarded to the planner agent so
|
|
1019
|
-
* user-scoped model resolution (OBO) stays in effect.
|
|
1020
|
-
*/
|
|
1021
|
-
requestContext?: RequestContext;
|
|
1022
|
-
/**
|
|
1023
|
-
* Cooperative cancellation. Forwarded to `resolveData` and the
|
|
1024
|
-
* planner agent. Note: the chart task continues running in the
|
|
1025
|
-
* background after the parent request ends, so external abort
|
|
1026
|
-
* signals are best-effort; typical use is to leave this unset
|
|
1027
|
-
* and let the 1h TTL cap stale entries.
|
|
1028
|
-
*/
|
|
1029
|
-
signal?: AbortSignal;
|
|
1030
|
-
}
|
|
1031
|
-
/**
|
|
1032
|
-
* Mint a `chartId`, cache an empty `{ chartId }` placeholder
|
|
1033
|
-
* synchronously, and kick off a background task that resolves the
|
|
1034
|
-
* dataset and runs the planner. Returns the `chartId` once the
|
|
1035
|
-
* placeholder lands so the first {@link fetchChart} call always
|
|
1036
|
-
* sees an entry (no spurious 404 race).
|
|
1037
|
-
*
|
|
1038
|
-
* The background task swallows its own failures and writes them
|
|
1039
|
-
* as `error` entries, so callers never see a rejected promise.
|
|
1040
|
-
* Cache state machine:
|
|
1041
|
-
*
|
|
1042
|
-
* - just after this call returns: `{ chartId }` (processing)
|
|
1043
|
-
* - on planner success: `{ chartId, result }`
|
|
1044
|
-
* - on data / planner failure: `{ chartId, error }`
|
|
1045
|
-
*/
|
|
1046
|
-
declare function prepareChart(opts: PrepareChartOptions): Promise<{
|
|
1047
|
-
chartId: string;
|
|
1048
|
-
}>;
|
|
1049
|
-
/** Inputs to {@link fetchChart}. */
|
|
1050
|
-
interface FetchChartOptions {
|
|
1051
|
-
/**
|
|
1052
|
-
* Server-side polling budget in ms. When the entry stays in
|
|
1053
|
-
* the processing state past this window, the helper returns the
|
|
1054
|
-
* last seen value (still processing) so the client can re-poll.
|
|
1055
|
-
* Defaults to {@link DEFAULT_FETCH_TIMEOUT_MS} (60s).
|
|
1056
|
-
*/
|
|
1057
|
-
timeoutMs?: number;
|
|
1058
|
-
/**
|
|
1059
|
-
* Poll interval in ms. Defaults to
|
|
1060
|
-
* {@link DEFAULT_FETCH_INTERVAL_MS} (250ms).
|
|
1061
|
-
*/
|
|
1062
|
-
intervalMs?: number;
|
|
1063
|
-
/** External cancellation handle (e.g. request `req.signal`). */
|
|
1064
|
-
signal?: AbortSignal;
|
|
1065
|
-
}
|
|
1066
|
-
/**
|
|
1067
|
-
* Long-poll the chart cache until the entry settles (`result` or
|
|
1068
|
-
* `error` set), the entry is missing, or the server-side timeout
|
|
1069
|
-
* elapses.
|
|
1070
|
-
*
|
|
1071
|
-
* Returns:
|
|
1072
|
-
* - the resolved {@link Chart} when it settled, errored, or
|
|
1073
|
-
* stayed in processing past `timeoutMs` (so the client can
|
|
1074
|
-
* re-poll);
|
|
1075
|
-
* - `undefined` when the entry is missing or expired (the
|
|
1076
|
-
* consumer should treat as 404).
|
|
1077
|
-
*
|
|
1078
|
-
* `signal` lets the caller cancel ahead of timeout (e.g. the HTTP
|
|
1079
|
-
* request closed). Cancellation propagates to the inter-poll sleep
|
|
1080
|
-
* so the helper returns immediately.
|
|
1081
|
-
*/
|
|
1082
|
-
declare function fetchChart(chartId: string, options?: FetchChartOptions): Promise<Chart | undefined>;
|
|
1083
|
-
/**
|
|
1084
|
-
* Build the `render_data` Mastra tool bound to the given plugin
|
|
1085
|
-
* config. Auto-wired as a system tool on every agent (see
|
|
1086
|
-
* `agents.ts`); per-agent tools can shadow it by registering a
|
|
1087
|
-
* same-named entry.
|
|
1088
|
-
*
|
|
1089
|
-
* Thin wrapper over {@link prepareChart} for callers that already
|
|
1090
|
-
* have a dataset in hand. Mints a `chartId` synchronously, caches
|
|
1091
|
-
* an empty placeholder, and kicks off the chart-planner in the
|
|
1092
|
-
* background. Returns just the `chartId`; the host UI resolves
|
|
1093
|
-
* `[chart:<chartId>]` markers by hitting the plugin's
|
|
1094
|
-
* `/embed/chart/:id` route.
|
|
1095
|
-
*
|
|
1096
|
-
* For Genie statement results, prefer the Genie agent's
|
|
1097
|
-
* `prepare_chart` tool, which accepts a `statement_id` and
|
|
1098
|
-
* resolves the rows lazily.
|
|
1099
|
-
*/
|
|
1100
|
-
declare function buildRenderDataTool(config: MastraPluginConfig): _mastra_core_tools0.Tool<{
|
|
1101
|
-
title: string;
|
|
1102
|
-
data: readonly Record<string, unknown>[];
|
|
1103
|
-
description?: string | undefined;
|
|
1104
|
-
}, {
|
|
1105
|
-
chartId: string;
|
|
1106
|
-
}, unknown, unknown, _mastra_core_tools0.ToolExecutionContext<unknown, unknown, unknown>, "render_data", unknown>;
|
|
1107
|
-
//#endregion
|
|
1108
|
-
//#region packages/appkit-mastra/src/filesystems.d.ts
|
|
1109
|
-
/** How {@link DatabricksWorkspaceFilesystem.init} handles a missing {@link basePath}. */
|
|
1110
|
-
type DatabricksMkdirsMode = boolean | "try";
|
|
1111
|
-
/** Options for {@link DatabricksWorkspaceFilesystem}. */
|
|
1112
|
-
interface DatabricksWorkspaceFilesystemOptions extends MastraFilesystemOptions {
|
|
1113
|
-
/** Unique identifier for this filesystem instance. */
|
|
1114
|
-
id?: string;
|
|
1115
|
-
/** Auth-scoped Databricks workspace client. */
|
|
1116
|
-
client?: WorkspaceClient;
|
|
1117
|
-
/**
|
|
1118
|
-
* Absolute Databricks path that roots the workspace namespace, e.g.
|
|
1119
|
-
* `/Volumes/catalog/schema/volume` or `/dbfs/FileStore/shared`.
|
|
1120
|
-
*/
|
|
1121
|
-
basePath: string;
|
|
1122
|
-
/**
|
|
1123
|
-
* When the {@link basePath} is missing at {@link init}, create it with the
|
|
1124
|
-
* matching Databricks `mkdirs` API. `"try"` (default) logs at debug and
|
|
1125
|
-
* falls back to an empty read-only namespace on failure; `true` fails init;
|
|
1126
|
-
* `false` skips creation and uses the empty namespace.
|
|
1127
|
-
*
|
|
1128
|
-
* A successful mkdir also satisfies the write-access probe when
|
|
1129
|
-
* {@link readOnly} is omitted.
|
|
1130
|
-
*/
|
|
1131
|
-
mkdirs?: DatabricksMkdirsMode;
|
|
1132
|
-
/** Block writes while still allowing reads. When omitted, {@link init} probes write access. */
|
|
1133
|
-
readOnly?: boolean;
|
|
1134
|
-
}
|
|
1135
|
-
/** Normalize a Databricks base path (POSIX, no trailing slash). */
|
|
1136
|
-
declare function normalizeDatabricksBasePath(basePath: string): string;
|
|
1137
|
-
/** True when `absolutePath` is served by DBFS rather than the UC Files API. */
|
|
1138
|
-
declare function isDbfsPath(absolutePath: string): boolean;
|
|
1139
|
-
/** True when `absolutePath` is a Databricks workspace object path. */
|
|
1140
|
-
declare function isWorkspaceFilesPath(absolutePath: string): boolean;
|
|
1141
|
-
/**
|
|
1142
|
-
* Resolve a workspace-relative path to an absolute Databricks path under
|
|
1143
|
-
* `basePath`.
|
|
1144
|
-
*/
|
|
1145
|
-
declare function resolveDatabricksAbsolutePath(basePath: string, inputPath: string): string;
|
|
1146
|
-
/** Map an absolute Databricks path back to the workspace namespace. */
|
|
1147
|
-
declare function toDatabricksWorkspacePath(basePath: string, absolutePath: string): string;
|
|
1148
|
-
/**
|
|
1149
|
-
* Mastra filesystem provider that reads and writes through a Databricks
|
|
1150
|
-
* {@link WorkspaceClient}.
|
|
1151
|
-
*
|
|
1152
|
-
* Workspace paths are absolute within the namespace (`/notes.md` maps to
|
|
1153
|
-
* `<basePath>/notes.md`). Unity Catalog volumes use the Files API;
|
|
1154
|
-
* `/dbfs/...` paths use DBFS.
|
|
1155
|
-
*/
|
|
1156
|
-
declare class DatabricksWorkspaceFilesystem extends MastraFilesystem {
|
|
1157
|
-
readonly id: string;
|
|
1158
|
-
readonly name = "DatabricksWorkspaceFilesystem";
|
|
1159
|
-
readonly provider = "databricks";
|
|
1160
|
-
readonly basePath: string;
|
|
1161
|
-
status: ProviderStatus;
|
|
1162
|
-
private readonly client;
|
|
1163
|
-
private readonly mkdirs;
|
|
1164
|
-
private _readOnly;
|
|
1165
|
-
private _basePathMissing;
|
|
1166
|
-
get readOnly(): boolean | undefined;
|
|
1167
|
-
/**
|
|
1168
|
-
* @param options.client - Defaults to the AppKit execution-context client.
|
|
1169
|
-
* @param options.mkdirs - Default `"try"`; see {@link DatabricksMkdirsMode}.
|
|
1170
|
-
* @param options.readOnly - When omitted, {@link init} probes write access.
|
|
1171
|
-
*/
|
|
1172
|
-
constructor(options: DatabricksWorkspaceFilesystemOptions);
|
|
1173
|
-
/** Resolve and sandbox a workspace-relative path under {@link basePath}. */
|
|
1174
|
-
private resolvePath;
|
|
1175
|
-
/** Map a Databricks absolute path back to the workspace namespace. */
|
|
1176
|
-
private workspacePath;
|
|
1177
|
-
/** Throw when the filesystem is read-only. */
|
|
1178
|
-
private assertWritable;
|
|
1179
|
-
/** Map SDK / HTTP errors to Mastra workspace filesystem errors. */
|
|
1180
|
-
private rethrow;
|
|
1181
|
-
/**
|
|
1182
|
-
* Probe whether {@link basePath} exists and cache the result on
|
|
1183
|
-
* {@link _basePathMissing}.
|
|
1184
|
-
*/
|
|
1185
|
-
private resolveBasePathStatus;
|
|
1186
|
-
/** Delegate to {@link emptyFilesystem} when the base path is missing. */
|
|
1187
|
-
private emptyFallback;
|
|
1188
|
-
init(): Promise<void>;
|
|
1189
|
-
/**
|
|
1190
|
-
* Write and delete a ephemeral probe file to detect read-only access when
|
|
1191
|
-
* {@link DatabricksWorkspaceFilesystemOptions.readOnly} was not set.
|
|
1192
|
-
*
|
|
1193
|
-
* @returns `true` when the probe write (and cleanup) succeeded.
|
|
1194
|
-
*/
|
|
1195
|
-
private probeReadOnly;
|
|
1196
|
-
destroy(): Promise<void>;
|
|
1197
|
-
/** Probe that `absolutePath` exists (file or directory metadata). */
|
|
1198
|
-
private assertAbsoluteReadable;
|
|
1199
|
-
/** Read the full contents of `absolutePath` from the matching backend. */
|
|
1200
|
-
private readAbsolute;
|
|
1201
|
-
/** Write `buffer` to `absolutePath` on the matching backend. */
|
|
1202
|
-
private writeAbsolute;
|
|
1203
|
-
/** Upload a buffer to a Unity Catalog Files API path. */
|
|
1204
|
-
private uploadUcFile;
|
|
1205
|
-
/** Delete a single file at `absolutePath` (non-recursive). */
|
|
1206
|
-
private deleteAbsoluteFile;
|
|
1207
|
-
/**
|
|
1208
|
-
* Delete a file or directory at `absolutePath`.
|
|
1209
|
-
*
|
|
1210
|
-
* DBFS and workspace APIs accept `recursive`; UC volumes recurse manually.
|
|
1211
|
-
*/
|
|
1212
|
-
private deleteAbsolutePath;
|
|
1213
|
-
/** Create `absolutePath` and any missing parents on the matching backend. */
|
|
1214
|
-
private mkdirAbsolute;
|
|
1215
|
-
private readDbfsFile;
|
|
1216
|
-
private readWorkspaceFile;
|
|
1217
|
-
private writeDbfsFile;
|
|
1218
|
-
private writeWorkspaceFile;
|
|
1219
|
-
getInfo(): FilesystemInfo<{
|
|
1220
|
-
basePath: string;
|
|
1221
|
-
}>;
|
|
1222
|
-
getInstructions(): string;
|
|
1223
|
-
/** Map a workspace-relative path to the backing Databricks absolute path. */
|
|
1224
|
-
resolveAbsolutePath(inputPath: string): string | undefined;
|
|
1225
|
-
/** Read file contents from the workspace namespace. */
|
|
1226
|
-
readFile(inputPath: string, options?: ReadOptions): Promise<string | Buffer>;
|
|
1227
|
-
/** Write file contents into the workspace namespace. */
|
|
1228
|
-
writeFile(inputPath: string, content: FileContent, options?: WriteOptions): Promise<void>;
|
|
1229
|
-
/** Append to an existing file, creating it when missing. */
|
|
1230
|
-
appendFile(inputPath: string, content: FileContent): Promise<void>;
|
|
1231
|
-
/** Delete a file in the workspace namespace. */
|
|
1232
|
-
deleteFile(inputPath: string, options?: RemoveOptions): Promise<void>;
|
|
1233
|
-
/** Copy a file within the workspace namespace. */
|
|
1234
|
-
copyFile(src: string, dest: string, options?: CopyOptions): Promise<void>;
|
|
1235
|
-
/** Move or rename a file within the workspace namespace. */
|
|
1236
|
-
moveFile(src: string, dest: string, options?: CopyOptions): Promise<void>;
|
|
1237
|
-
/** Create a directory in the workspace namespace. */
|
|
1238
|
-
mkdir(inputPath: string, options?: {
|
|
1239
|
-
recursive?: boolean;
|
|
1240
|
-
}): Promise<void>;
|
|
1241
|
-
/** Remove a directory from the workspace namespace. */
|
|
1242
|
-
rmdir(inputPath: string, options?: RemoveOptions): Promise<void>;
|
|
1243
|
-
/**
|
|
1244
|
-
* Recursively delete a Unity Catalog directory tree.
|
|
1245
|
-
*
|
|
1246
|
-
* DBFS and workspace trees use native recursive delete via
|
|
1247
|
-
* {@link deleteAbsolutePath} instead.
|
|
1248
|
-
*/
|
|
1249
|
-
private deleteUcDirectoryRecursive;
|
|
1250
|
-
/** List entries in a workspace directory. */
|
|
1251
|
-
readdir(inputPath: string, options?: ListOptions): Promise<FileEntry[]>;
|
|
1252
|
-
private readDirectoryRecursive;
|
|
1253
|
-
private listAbsoluteDirectory;
|
|
1254
|
-
/** Apply Mastra list filters (`extension`, etc.) to directory entries. */
|
|
1255
|
-
private filterEntries;
|
|
1256
|
-
/** Return whether `inputPath` exists in the workspace namespace. */
|
|
1257
|
-
exists(inputPath: string): Promise<boolean>;
|
|
1258
|
-
/** Return file or directory metadata for `inputPath`. */
|
|
1259
|
-
stat(inputPath: string): Promise<FileStat>;
|
|
1260
|
-
/**
|
|
1261
|
-
* Stat a Unity Catalog path by probing file metadata first, then
|
|
1262
|
-
* directory metadata.
|
|
1263
|
-
*/
|
|
1264
|
-
private statUcAbsolute;
|
|
1265
|
-
}
|
|
1266
|
-
/**
|
|
1267
|
-
* Read-only in-memory {@link WorkspaceFilesystem} with a single empty root.
|
|
1268
|
-
* Use {@link emptyFilesystem} rather than constructing directly.
|
|
1269
|
-
*/
|
|
1270
|
-
declare class EmptyFilesystem extends MastraFilesystem {
|
|
1271
|
-
readonly id = "empty-fs";
|
|
1272
|
-
readonly name = "EmptyFilesystem";
|
|
1273
|
-
readonly provider = "empty";
|
|
1274
|
-
readonly readOnly = true;
|
|
1275
|
-
status: ProviderStatus;
|
|
1276
|
-
constructor();
|
|
1277
|
-
init(): Promise<void>;
|
|
1278
|
-
destroy(): Promise<void>;
|
|
1279
|
-
getInfo(): FilesystemInfo;
|
|
1280
|
-
getInstructions(): string;
|
|
1281
|
-
private rootStat;
|
|
1282
|
-
private assertWritable;
|
|
1283
|
-
readFile(inputPath: string, _options?: ReadOptions): Promise<string | Buffer>;
|
|
1284
|
-
writeFile(_inputPath: string, _content: FileContent, _options?: WriteOptions): Promise<void>;
|
|
1285
|
-
appendFile(_inputPath: string, _content: FileContent): Promise<void>;
|
|
1286
|
-
deleteFile(inputPath: string, options?: RemoveOptions): Promise<void>;
|
|
1287
|
-
copyFile(src: string, _dest: string, _options?: CopyOptions): Promise<void>;
|
|
1288
|
-
moveFile(src: string, dest: string, options?: CopyOptions): Promise<void>;
|
|
1289
|
-
mkdir(_inputPath: string, _options?: {
|
|
1290
|
-
recursive?: boolean;
|
|
1291
|
-
}): Promise<void>;
|
|
1292
|
-
rmdir(inputPath: string, options?: RemoveOptions): Promise<void>;
|
|
1293
|
-
readdir(inputPath: string, _options?: ListOptions): Promise<FileEntry[]>;
|
|
1294
|
-
exists(inputPath: string): Promise<boolean>;
|
|
1295
|
-
stat(inputPath: string): Promise<FileStat>;
|
|
1296
|
-
}
|
|
1297
|
-
/** Memoized singleton empty read-only filesystem for no-op mounts. */
|
|
1298
|
-
declare const emptyFilesystem: () => EmptyFilesystem;
|
|
1299
|
-
//#endregion
|
|
1300
|
-
//#region packages/appkit-mastra/src/mcp.d.ts
|
|
1301
|
-
/**
|
|
1302
|
-
* A built MCP server plus the request paths it answers on, relative to
|
|
1303
|
-
* the plugin's base path (`/api/<plugin>`).
|
|
1304
|
-
*
|
|
1305
|
-
* The paths are the **clean public aliases** (`/mcp`, `/sse`,
|
|
1306
|
-
* `/messages`) the plugin exposes. `@mastra/express` actually mounts the
|
|
1307
|
-
* transports under `/mcp/<serverId>/<transport>` off the `Mastra`
|
|
1308
|
-
* instance's `mcpServers`; the plugin rewrites the alias to that route
|
|
1309
|
-
* before dispatch (see {@link ResolvedMcp.serverId}), so a client never
|
|
1310
|
-
* sees the doubled `/mcp/<serverId>/mcp` segment.
|
|
1311
|
-
*/
|
|
1312
|
-
interface ResolvedMcp {
|
|
1313
|
-
/**
|
|
1314
|
-
* Registry id, used in the underlying `@mastra/express` route
|
|
1315
|
-
* (`/mcp/<serverId>/...`) the plugin rewrites the clean alias to.
|
|
1316
|
-
*/
|
|
1317
|
-
serverId: string;
|
|
1318
|
-
/** The Mastra MCP server to hand to `new Mastra({ mcpServers })`. */
|
|
1319
|
-
server: MCPServer;
|
|
1320
|
-
/** Streamable-HTTP transport path, relative to the plugin base path. */
|
|
1321
|
-
httpPath: string;
|
|
1322
|
-
/** SSE transport path, relative to the plugin base path. */
|
|
1323
|
-
ssePath: string;
|
|
1324
|
-
/** SSE message path, relative to the plugin base path. */
|
|
1325
|
-
messagePath: string;
|
|
1326
|
-
}
|
|
1327
|
-
/**
|
|
1328
|
-
* Build the plugin's MCP server, or `null` only when `config.mcp` is
|
|
1329
|
-
* explicitly `false`.
|
|
1330
|
-
*
|
|
1331
|
-
* Agent exposure is on by default because it's cheap: the already-
|
|
1332
|
-
* registered agents are wrapped as `ask_<agentId>` tools and handed to
|
|
1333
|
-
* `@mastra/express` (already mounted for the chat routes) - no extra
|
|
1334
|
-
* process, dependency, or network cost, and requests run under the same
|
|
1335
|
-
* OBO scope. So `undefined` (the default) and `true` both expose every
|
|
1336
|
-
* registered agent under a server id equal to the plugin name; only
|
|
1337
|
-
* `false` turns MCP off. The object form ({@link MastraMcpConfig}) tunes
|
|
1338
|
-
* the id / advertised metadata and can additionally expose the plugin's
|
|
1339
|
-
* ambient tools or a set of extra MCP-only tools. Ambient tools stay off
|
|
1340
|
-
* unless explicitly enabled - they assume an in-process chat turn, so
|
|
1341
|
-
* they aren't cheap / safe to expose to a standalone MCP client.
|
|
1342
|
-
*/
|
|
1343
|
-
declare function buildMcpServer(opts: {
|
|
1344
|
-
config: MastraPluginConfig;
|
|
1345
|
-
pluginName: string;
|
|
1346
|
-
displayName: string;
|
|
1347
|
-
agents: Record<string, Agent>;
|
|
1348
|
-
ambientTools: MastraTools;
|
|
1349
|
-
}): ResolvedMcp | null;
|
|
1350
|
-
//#endregion
|
|
1351
|
-
//#region packages/appkit-mastra/src/server.d.ts
|
|
1352
|
-
/**
|
|
1353
|
-
* `@mastra/express` subclass that stamps `RequestContext` with the
|
|
1354
|
-
* AppKit user, resource id, and a thread id backed by an HTTP-only
|
|
1355
|
-
* session cookie (`appkit_<plugin-name>_session_id`).
|
|
1356
|
-
*/
|
|
1357
|
-
declare class MastraServer$1 extends MastraServer {
|
|
1358
|
-
private config;
|
|
1359
|
-
private log;
|
|
1360
|
-
/**
|
|
1361
|
-
* Whether to stamp the MLflow trace-id header on responses. Shares the
|
|
1362
|
-
* plugin's feedback gate via {@link resolveFeedbackEnabled}.
|
|
1363
|
-
*/
|
|
1364
|
-
private feedbackEnabled;
|
|
1365
|
-
constructor(config: MastraPluginConfig, ...args: ConstructorParameters<typeof MastraServer>);
|
|
1366
|
-
registerAuthMiddleware(): void;
|
|
1367
|
-
configureRequestContextUser(requestContext: RequestContext): Promise<void>;
|
|
1368
|
-
/**
|
|
1369
|
-
* Stamp a per-request id and echo it on the response so an upstream
|
|
1370
|
-
* proxy / curl client / browser-side log line can pair its view of
|
|
1371
|
-
* the request with the matching trace span. Reuses `X-Request-Id`
|
|
1372
|
-
* when the upstream already supplies one so multi-hop traces stay
|
|
1373
|
-
* joined; otherwise mints a UUIDv4.
|
|
1374
|
-
*
|
|
1375
|
-
* The id is surfaced as `mastra__requestId` span metadata via
|
|
1376
|
-
* {@link TRACE_REQUEST_CONTEXT_KEYS} and as the `X-Request-Id`
|
|
1377
|
-
* response header so dev tools can copy it from either side.
|
|
1378
|
-
*/
|
|
1379
|
-
configureRequestContextRequestId(req: express.Request, res: express.Response, requestContext: RequestContext): void;
|
|
1380
|
-
/**
|
|
1381
|
-
* Stamp OAuth scopes from the forwarded access token on
|
|
1382
|
-
* {@link MASTRA_SCOPES_KEY} for workspace mount gating.
|
|
1383
|
-
*/
|
|
1384
|
-
configureRequestContextScopes(req: express.Request, requestContext: RequestContext): void;
|
|
1385
|
-
/**
|
|
1386
|
-
* Stamp the turn's MLflow trace id on the response so the chat client
|
|
1387
|
-
* can attach thumbs / comment feedback to it later. MLflow derives
|
|
1388
|
-
* its trace id from the OpenTelemetry trace id (`tr-<hex>`), and every
|
|
1389
|
-
* Mastra span for this request inherits the ambient OTel context (see
|
|
1390
|
-
* `observability.ts`), so the active span's trace id here is the id
|
|
1391
|
-
* MLflow will record for the turn.
|
|
1392
|
-
*
|
|
1393
|
-
* No-op unless feedback is enabled, and when no live OTel span is
|
|
1394
|
-
* active (e.g. the OTLP SDK isn't registered): in that case the header
|
|
1395
|
-
* is simply absent and the client hides feedback for that message,
|
|
1396
|
-
* degrading gracefully rather than emitting a bogus trace id.
|
|
1397
|
-
*/
|
|
1398
|
-
configureMlflowTraceId(res: express.Response): void;
|
|
1399
|
-
/**
|
|
1400
|
-
* Resolve the thread id this request targets and pin it on
|
|
1401
|
-
* `RequestContext` (consumed by the agent stream for persistence and
|
|
1402
|
-
* by the history / threads routes). Resolution order:
|
|
1403
|
-
*
|
|
1404
|
-
* 1. A client-supplied thread id (the thread-selection header /
|
|
1405
|
-
* `?threadId=` query). This is how the chat UI references a
|
|
1406
|
-
* specific conversation among the many a user owns - it picks a
|
|
1407
|
-
* thread id from the `/threads` listing (or mints one for a new
|
|
1408
|
-
* conversation) and stamps it here. The id is scoped to the
|
|
1409
|
-
* caller's resource by the recall / list routes, so a client
|
|
1410
|
-
* can only ever read or write its own threads.
|
|
1411
|
-
* 2. The per-session cookie (`appkit_<plugin-name>_session_id`),
|
|
1412
|
-
* minted on first contact. This is the default single-thread
|
|
1413
|
-
* fallback for clients that don't manage threads explicitly, so
|
|
1414
|
-
* existing embeds keep one stable conversation per session with
|
|
1415
|
-
* no client changes.
|
|
1416
|
-
*/
|
|
1417
|
-
configureRequestContextThreadId(req: express.Request, res: express.Response, requestContext: RequestContext): void;
|
|
1418
|
-
/**
|
|
1419
|
-
* Read the client-selected thread id from the request, preferring
|
|
1420
|
-
* the thread-selection header over the `?threadId=` query. Returns
|
|
1421
|
-
* `null` when neither carries a non-empty value so the caller falls
|
|
1422
|
-
* back to the session cookie.
|
|
1423
|
-
*/
|
|
1424
|
-
private readRequestedThreadId;
|
|
1425
|
-
configureRequestContextModelOverride(req: express.Request, requestContext: RequestContext): void;
|
|
1426
|
-
}
|
|
1427
|
-
//#endregion
|
|
1428
|
-
//#region packages/appkit-mastra/src/plugin.d.ts
|
|
1429
|
-
/**
|
|
1430
|
-
* AppKit plugin (registered name: `mastra`) that hosts Mastra agents
|
|
1431
|
-
* with optional Lakebase-backed memory and AI SDK chat routes under
|
|
1432
|
-
* the plugin mount (typically `/api/mastra`).
|
|
1433
|
-
*/
|
|
1434
|
-
declare class MastraPlugin extends Plugin<MastraPluginConfig> {
|
|
1435
|
-
static manifest: {
|
|
1436
|
-
name: "mastra";
|
|
1437
|
-
displayName: string;
|
|
1438
|
-
description: string;
|
|
1439
|
-
stability: "beta";
|
|
1440
|
-
resources: {
|
|
1441
|
-
required: never[];
|
|
1442
|
-
optional: Omit<ResourceRequirement, "required">[];
|
|
1443
|
-
};
|
|
1444
|
-
};
|
|
1445
|
-
/**
|
|
1446
|
-
* Tighten resource requirements based on which features are enabled.
|
|
1447
|
-
* AppKit calls this at registration time (config-aware) so disabled
|
|
1448
|
-
* features don't surface their resource asks to the host app.
|
|
1449
|
-
*/
|
|
1450
|
-
static getResourceRequirements(config: MastraPluginConfig): ResourceRequirement[];
|
|
1451
|
-
private log;
|
|
1452
|
-
private built;
|
|
1453
|
-
private mastra;
|
|
1454
|
-
private mastraApp;
|
|
1455
|
-
private mastraServer;
|
|
1456
|
-
/**
|
|
1457
|
-
* The optional MCP server exposing this plugin's agents / tools, or
|
|
1458
|
-
* `null` when `config.mcp` is disabled (the default). Built in
|
|
1459
|
-
* {@link buildAgentAndServer} and registered on the Mastra instance.
|
|
1460
|
-
*/
|
|
1461
|
-
private mcp;
|
|
1462
|
-
/**
|
|
1463
|
-
* Dedicated service-principal Lakebase pool backing Mastra memory /
|
|
1464
|
-
* storage. Built once in {@link buildAgentAndServer} (outside any
|
|
1465
|
-
* `asUser` scope, so it never inherits a request's OBO identity) and
|
|
1466
|
-
* drained in {@link abortActiveOperations}. `null` until setup runs
|
|
1467
|
-
* or when Lakebase isn't needed.
|
|
1468
|
-
*/
|
|
1469
|
-
private servicePrincipalPool;
|
|
1470
|
-
setup(): Promise<void>;
|
|
1471
|
-
/**
|
|
1472
|
-
* When the `lakebase` plugin is registered, auto-enable `storage`
|
|
1473
|
-
* and `memory` unless the caller opted out explicitly (`false` or a
|
|
1474
|
-
* custom config object). Run after `setup:complete` so the lookup
|
|
1475
|
-
* is reliable: any plugin that registers itself synchronously is
|
|
1476
|
-
* already in the registry by the time this fires.
|
|
1477
|
-
*/
|
|
1478
|
-
private applyLakebaseAutoDefaults;
|
|
1479
|
-
/**
|
|
1480
|
-
* Drain the memory service-principal pool on shutdown. AppKit calls
|
|
1481
|
-
* this during teardown; the lakebase plugin closes its own SP / OBO
|
|
1482
|
-
* pools the same way. Fire-and-forget so shutdown isn't blocked on a
|
|
1483
|
-
* slow drain, and clear the handle so a re-`setup()` rebuilds it.
|
|
1484
|
-
*/
|
|
1485
|
-
abortActiveOperations(): void;
|
|
1486
|
-
exports(): {
|
|
1487
|
-
/**
|
|
1488
|
-
* Ids of every registered agent in registration order. Matches
|
|
1489
|
-
* AppKit `agents.list()` so callers can iterate the registry the
|
|
1490
|
-
* same way under both plugins.
|
|
1491
|
-
*/
|
|
1492
|
-
list: () => string[];
|
|
1493
|
-
/**
|
|
1494
|
-
* Look up a registered agent by id. Returns `null` (not
|
|
1495
|
-
* undefined) when unknown so call sites can early-return without
|
|
1496
|
-
* a separate `in` check.
|
|
1497
|
-
*/
|
|
1498
|
-
get: (id: string) => Agent | null;
|
|
1499
|
-
/**
|
|
1500
|
-
* The agent the client converses with when it doesn't name one.
|
|
1501
|
-
* Resolves to `config.defaultAgent`, the first registered id, or
|
|
1502
|
-
* the built-in `default` fallback.
|
|
1503
|
-
*/
|
|
1504
|
-
getDefault: () => Agent | null; /** Underlying Mastra instance for advanced use (custom routes etc.). */
|
|
1505
|
-
getMastra: () => Mastra<Record<string, Agent<any, _mastra_core_agent0.ToolsInput, undefined, unknown, _mastra_core_agent0.AgentEditorConfig | undefined>>, Record<string, _mastra_core_workflows0.AnyWorkflow>, Record<string, _mastra_core_vector0.MastraVector<any>>, Record<string, _mastra_core_tts0.MastraTTS>, _mastra_core_logger0.IMastraLogger, Record<string, _mastra_core_mcp0.MCPServerBase<any>>, Record<string, _mastra_core_evals0.MastraScorer<any, any, any, any>>, Record<string, _mastra_core_tools0.ToolAction<any, any, any, any, any, any, unknown>>, Record<string, _mastra_core_processors0.Processor<any, unknown>>, Record<string, _mastra_core_memory0.MastraMemory>, Record<string, _mastra_core_channels0.ChannelProvider>> | null;
|
|
1506
|
-
/**
|
|
1507
|
-
* MCP endpoint info when `config.mcp` is enabled, else `null`.
|
|
1508
|
-
* Paths are absolute (under the plugin mount), ready to hand to an
|
|
1509
|
-
* MCP client. Streamable HTTP is `http`; the SSE pair is the
|
|
1510
|
-
* legacy transport.
|
|
1511
|
-
*/
|
|
1512
|
-
getMcp: () => {
|
|
1513
|
-
serverId: string;
|
|
1514
|
-
http: string;
|
|
1515
|
-
sse: string;
|
|
1516
|
-
messages: string;
|
|
1517
|
-
} | null; /** Express subapp Mastra is mounted on; mostly for tests. */
|
|
1518
|
-
getMastraServer: () => MastraServer$1 | null;
|
|
1519
|
-
/**
|
|
1520
|
-
* Fetch the workspace's Model Serving endpoints (cached). Same
|
|
1521
|
-
* payload the `GET /models` route returns; surfaced here so
|
|
1522
|
-
* other plugins / scripts can introspect the catalogue without
|
|
1523
|
-
* an HTTP round-trip. AppKit wraps this with `asUser(req)` for
|
|
1524
|
-
* OBO scoping automatically.
|
|
1525
|
-
*/
|
|
1526
|
-
listModels: () => Promise<ServingEndpointSummary[]>;
|
|
1527
|
-
/**
|
|
1528
|
-
* Force-evict cached endpoint listings via AppKit's
|
|
1529
|
-
* `CacheManager`. Useful in tests or right after an admin
|
|
1530
|
-
* deploys a new endpoint and doesn't want to wait for the TTL.
|
|
1531
|
-
* Returns the underlying `CacheManager.delete`/`clear` promise.
|
|
1532
|
-
*/
|
|
1533
|
-
clearModelsCache: (host?: string) => Promise<void>;
|
|
1534
|
-
};
|
|
1535
|
-
clientConfig(): Record<string, unknown>;
|
|
1536
|
-
/**
|
|
1537
|
-
* Whether user feedback can be logged to MLflow. Delegates to
|
|
1538
|
-
* {@link resolveFeedbackEnabled} so the client-config flag and the
|
|
1539
|
-
* feedback route share the same gate as the server's trace-id header.
|
|
1540
|
-
*/
|
|
1541
|
-
private feedbackEnabled;
|
|
1542
|
-
injectRoutes(router: IAppRouter): void;
|
|
1543
|
-
/**
|
|
1544
|
-
* Invoke the Mastra express sub-app. Exists as a method (instead of reading
|
|
1545
|
-
* `this.mastraApp` through the `asUser(req)` proxy at the call site) so the
|
|
1546
|
-
* proxy binds this plain method - whose `.bind` is `Function.prototype.bind`
|
|
1547
|
-
* - rather than the express app, whose `.bind` is the HTTP BIND route
|
|
1548
|
-
* registrar (see the note in `injectRoutes`). Runs inside the user scope so
|
|
1549
|
-
* `getExecutionContext()` returns the OBO client for the agent/model
|
|
1550
|
-
* resolvers.
|
|
1551
|
-
*/
|
|
1552
|
-
private dispatchMastra;
|
|
1553
|
-
/**
|
|
1554
|
-
* Map a clean, mount-relative MCP alias path to the underlying
|
|
1555
|
-
* `@mastra/express` route. Returns `null` when MCP is off or the path
|
|
1556
|
-
* isn't an alias. Collapses the stock `/mcp/<serverId>/<transport>`
|
|
1557
|
-
* layout (serverId defaults to the plugin name) down to `/mcp`,
|
|
1558
|
-
* `/sse`, and `/messages`.
|
|
1559
|
-
*/
|
|
1560
|
-
private mcpRouteAlias;
|
|
1561
|
-
/**
|
|
1562
|
-
* Implementation backing the `/suggestions` route. Runs inside the
|
|
1563
|
-
* AppKit user-context proxy so `getExecutionContext()` returns the
|
|
1564
|
-
* OBO-scoped client. Resolves the plugin's Genie spaces and merges
|
|
1565
|
-
* their curated `sample_questions` (see {@link collectSpaceSuggestions}).
|
|
1566
|
-
* Returns `[]` when no Genie space is configured so the client
|
|
1567
|
-
* shows a bare empty state instead of built-in example prompts.
|
|
1568
|
-
*/
|
|
1569
|
-
private fetchSuggestions;
|
|
1570
|
-
/**
|
|
1571
|
-
* Implementation backing the `/route/feedback` route. Runs inside the
|
|
1572
|
-
* AppKit user-context proxy so `getExecutionContext()` returns the
|
|
1573
|
-
* OBO-scoped client and the assessment is attributed to the signed-in
|
|
1574
|
-
* user (their email / id as the assessment source). Returns the
|
|
1575
|
-
* created assessment id on success, or `undefined` on a soft failure
|
|
1576
|
-
* (see {@link logFeedback} in `./mlflow.js`).
|
|
1577
|
-
*/
|
|
1578
|
-
private logFeedback;
|
|
1579
|
-
/**
|
|
1580
|
-
* Implementation backing the `data` embed resolver
|
|
1581
|
-
* (`GET /embed/data/:id`). Runs inside the AppKit user-context proxy so
|
|
1582
|
-
* `getExecutionContext()` returns the OBO-scoped workspace
|
|
1583
|
-
* client, then reuses the same `fetchStatementData` pipeline
|
|
1584
|
-
* the `get_statement` tool runs so the LLM and the UI see the
|
|
1585
|
-
* exact same shape for the same statement.
|
|
1586
|
-
*
|
|
1587
|
-
* Returns `undefined` for upstream 404s so the route can map
|
|
1588
|
-
* them to a clean HTTP 404; any other failure bubbles up.
|
|
1589
|
-
*/
|
|
1590
|
-
private fetchStatement;
|
|
1591
|
-
/**
|
|
1592
|
-
* Return `this.asUser(req)` when the request carries an OBO token,
|
|
1593
|
-
* otherwise return `this` directly. Prevents the noisy AppKit warn
|
|
1594
|
-
* (`asUser() called without user token in development mode. Skipping
|
|
1595
|
-
* user impersonation.`) on every request in local dev where the
|
|
1596
|
-
* browser never sends `x-forwarded-access-token`. Behavior is
|
|
1597
|
-
* unchanged in production: a missing token always means a real OBO
|
|
1598
|
-
* proxy call (and AppKit will throw upstream if that's wrong).
|
|
1599
|
-
*/
|
|
1600
|
-
private userScopedSelf;
|
|
1601
|
-
/**
|
|
1602
|
-
* Implementation backing both the `/models` route and the
|
|
1603
|
-
* `listModels` export. Runs inside the AppKit user-context proxy so
|
|
1604
|
-
* `getExecutionContext()` returns the OBO-scoped client.
|
|
1605
|
-
*/
|
|
1606
|
-
private listModels;
|
|
1607
|
-
private buildAgentAndServer;
|
|
1608
|
-
}
|
|
1609
|
-
declare const mastra: _databricks_appkit0.ToPlugin<typeof MastraPlugin, MastraPluginConfig, "mastra">;
|
|
1610
|
-
//#endregion
|
|
1611
|
-
//#region packages/appkit-mastra/src/serving.d.ts
|
|
1612
|
-
/**
|
|
1613
|
-
* `RequestContext` key under which {@link MastraServer} stores the
|
|
1614
|
-
* per-request model override (header / query / body). `model.ts`
|
|
1615
|
-
* reads it before falling back to the agent / plugin default.
|
|
1616
|
-
*/
|
|
1617
|
-
declare const MASTRA_MODEL_OVERRIDE_KEY = "mastra__model_override";
|
|
1618
|
-
/**
|
|
1619
|
-
* Minimal Express-ish request shape used by {@link extractModelOverride}.
|
|
1620
|
-
* Keeps this module independent of `express` so the helper can be
|
|
1621
|
-
* reused from non-Express adapters.
|
|
1622
|
-
*/
|
|
1623
|
-
interface ModelOverrideRequest {
|
|
1624
|
-
headers?: Record<string, string | string[] | undefined>;
|
|
1625
|
-
query?: Record<string, unknown> | undefined;
|
|
1626
|
-
body?: unknown;
|
|
1627
|
-
}
|
|
1628
|
-
/**
|
|
1629
|
-
* Pull a model override out of a single HTTP request, checking
|
|
1630
|
-
* sources in priority order:
|
|
1631
|
-
*
|
|
1632
|
-
* 1. `X-Mastra-Model` header
|
|
1633
|
-
* 2. `?model=` query string parameter
|
|
1634
|
-
* 3. Body field (`model` or `modelId`, in that order)
|
|
1635
|
-
*
|
|
1636
|
-
* Returns `null` when nothing is set, so callers can wrap with
|
|
1637
|
-
* `if (override) ...` without juggling empty strings. Body inspection
|
|
1638
|
-
* is lenient - any plain object with one of the configured keys
|
|
1639
|
-
* counts, mirroring how AI SDK chat clients pass arbitrary metadata
|
|
1640
|
-
* alongside `messages`.
|
|
1641
|
-
*/
|
|
1642
|
-
declare function extractModelOverride(req: ModelOverrideRequest): string | null;
|
|
1643
|
-
//#endregion
|
|
1644
|
-
//#region packages/appkit-mastra/src/summarize.d.ts
|
|
1645
|
-
/** Options accepted by {@link summarizeText}. */
|
|
1646
|
-
interface SummarizeOptions {
|
|
1647
|
-
/** Extra guidance for the summary (length, focus, format). */
|
|
1648
|
-
instructions?: string;
|
|
1649
|
-
/** Soft cap on summary length, in words. */
|
|
1650
|
-
maxWords?: number;
|
|
1651
|
-
/** Active request context, so the model resolver mints user-scoped tokens. */
|
|
1652
|
-
requestContext?: RequestContext;
|
|
1653
|
-
/** Abort signal bridged from the calling tool / request. */
|
|
1654
|
-
abortSignal?: AbortSignal;
|
|
1655
|
-
}
|
|
1656
|
-
/**
|
|
1657
|
-
* Summarize `text` with the small-tier summarizer agent, returning the
|
|
1658
|
-
* trimmed summary string. Throws on model failure (the caller decides
|
|
1659
|
-
* how to degrade).
|
|
1660
|
-
*/
|
|
1661
|
-
declare function summarizeText(config: MastraPluginConfig, text: string, options?: SummarizeOptions): Promise<string>;
|
|
1662
|
-
/**
|
|
1663
|
-
* Build the `summarize` tool. Exposed as an ambient system tool (like
|
|
1664
|
-
* `render_data`) so every agent can offload condensing long content,
|
|
1665
|
-
* notes, transcripts, or bulky tool results to the fast tier instead of
|
|
1666
|
-
* spending its primary chat model. The tool reads the live
|
|
1667
|
-
* `requestContext` / `abortSignal` off the Mastra execution context so
|
|
1668
|
-
* its model call stays user-scoped and cancels with the turn.
|
|
1669
|
-
*/
|
|
1670
|
-
declare function buildSummarizeTool(config: MastraPluginConfig): _mastra_core_tools0.Tool<{
|
|
1671
|
-
text: string;
|
|
1672
|
-
instructions?: string | undefined;
|
|
1673
|
-
maxWords?: number | undefined;
|
|
1674
|
-
}, unknown, unknown, unknown, _mastra_core_tools0.ToolExecutionContext<unknown, unknown, unknown>, "summarize", unknown>;
|
|
1675
|
-
//#endregion
|
|
1676
|
-
export { AppKitToolOptions, BuiltAgents, ChartPlannerRequest, DEFAULT_AGENT_MAX_STEPS, DEFAULT_GENIE_ALIAS, DEFAULT_STYLE_INSTRUCTIONS, type DatabricksMkdirsMode, DatabricksWorkspaceFilesystem, type DatabricksWorkspaceFilesystemOptions, FALLBACK_AGENT_ID, FetchChartOptions, GENIE_INSTRUCTIONS, GenieSpaceConfig, GenieSpacesConfig, MASTRA_MODEL_OVERRIDE_KEY, MASTRA_REQUEST_ID_KEY, MASTRA_SCOPES_KEY, MASTRA_USER_EMAIL_KEY, MASTRA_USER_KEY, MASTRA_USER_NAME_KEY, MastraAgentDefinition, MastraAgentWorkspaceResolver, MastraMcpConfig, MastraMemoryConfig, MastraMemoryConfigOverride, MastraPlugin, MastraPluginConfig, MastraPluginToolkitProvider, MastraPlugins, MastraStorageConfigOverride, MastraTools, MastraToolsFn, type ModelOverrideRequest, PrepareChartOptions, ResolvedMcp, type SummarizeOptions, TRACE_REQUEST_CONTEXT_KEYS, ToolkitOptions, User, approvalGatedToolIds, buildAgents, buildGenieToolkitProvider, buildGenieTools, buildMcpServer, buildRenderDataTool, buildSummarizeTool, chartPlannerRequestSchema, collectSpaceSuggestions, createAgent, createTool, createWorkspace, emptyFilesystem, extractModelOverride, fetchChart, isDbfsPath, isWorkspaceFilesPath, mastra, normalizeDatabricksBasePath, normalizeGenieSpaces, prepareChart, resolveDatabricksAbsolutePath, resolveGenieSpaces, summarizeText, toDatabricksWorkspacePath, tool };
|