@dbx-tools/appkit-mastra 0.1.40 → 0.1.42
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 +59 -58
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/src/agents.d.ts +3 -3
- package/dist/src/agents.js +1 -1
- package/dist/src/chart.d.ts +7 -1
- package/dist/src/chart.js +3 -5
- package/dist/src/config.d.ts +14 -11
- package/dist/src/genie.d.ts +0 -12
- package/dist/src/genie.js +2 -16
- package/dist/src/history.d.ts +6 -6
- package/dist/src/history.js +6 -6
- package/dist/src/memory.d.ts +34 -25
- package/dist/src/memory.js +48 -35
- package/dist/src/model.d.ts +24 -131
- package/dist/src/model.js +39 -268
- package/dist/src/plugin.d.ts +28 -12
- package/dist/src/plugin.js +86 -42
- package/dist/src/server.d.ts +13 -20
- package/dist/src/server.js +15 -22
- package/dist/src/serving.d.ts +14 -98
- package/dist/src/serving.js +18 -163
- package/dist/src/tools/email.d.ts +10 -1
- package/dist/src/writer.d.ts +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/index.ts +2 -13
- package/package.json +7 -6
- package/src/agents.ts +3 -3
- package/src/chart.ts +3 -5
- package/src/config.ts +14 -11
- package/src/genie.ts +4 -22
- package/src/history.ts +6 -6
- package/src/memory.ts +48 -45
- package/src/model.ts +57 -291
- package/src/plugin.ts +99 -50
- package/src/server.ts +15 -22
- package/src/serving.ts +18 -220
- package/src/writer.ts +2 -2
- package/dist/src/intercept.d.ts +0 -48
- package/dist/src/intercept.js +0 -167
- package/src/intercept.ts +0 -206
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
An AppKit plugin that hosts [Mastra](https://mastra.ai) agents inside a
|
|
4
4
|
Databricks App with user-scoped workspace auth (OBO), optional
|
|
5
|
-
Lakebase-backed memory, and
|
|
6
|
-
|
|
5
|
+
Lakebase-backed memory, and the standard Mastra agent stream the React
|
|
6
|
+
client drives via `@mastra/client-js` (`getAgent(id).stream()`).
|
|
7
7
|
|
|
8
8
|
The plugin is designed so that wiring it up looks the same as the
|
|
9
9
|
AppKit
|
|
@@ -70,29 +70,25 @@ for routing / one-shot agents that don't need history.
|
|
|
70
70
|
See [Memory + storage](#memory--storage) for the full cascade and worked
|
|
71
71
|
examples.
|
|
72
72
|
|
|
73
|
-
On the React side,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
so
|
|
73
|
+
On the React side, drop in the prebuilt chat UI from
|
|
74
|
+
[`@dbx-tools/appkit-mastra-ui`](../appkit-mastra-ui) - it wires itself
|
|
75
|
+
from the plugin's published client config and streams over
|
|
76
|
+
`@mastra/client-js`, so there's no transport code to write:
|
|
77
77
|
|
|
78
78
|
```tsx
|
|
79
|
-
import {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
import { useMemo } from "react";
|
|
84
|
-
|
|
85
|
-
function Chat() {
|
|
86
|
-
const config = usePluginClientConfig<MastraClientConfig>("mastra");
|
|
87
|
-
const transport = useMemo(
|
|
88
|
-
() => new DefaultChatTransport({ api: chatUrl(config) }),
|
|
89
|
-
[config],
|
|
90
|
-
);
|
|
91
|
-
const { messages, sendMessage } = useChat({ transport });
|
|
92
|
-
// ...
|
|
79
|
+
import { MastraChat } from "@dbx-tools/appkit-mastra-ui/react";
|
|
80
|
+
|
|
81
|
+
export default function ChatPage() {
|
|
82
|
+
return <MastraChat showModelPicker />;
|
|
93
83
|
}
|
|
94
84
|
```
|
|
95
85
|
|
|
86
|
+
Under the hood that's `useMastraClient()` -> a `MastraPluginClient`
|
|
87
|
+
(a `@mastra/client-js` `MastraClient` subclass) that streams turns and
|
|
88
|
+
adds the plugin's custom routes (history, models, suggestions, embeds).
|
|
89
|
+
Never hardcode `/api/mastra/...`; the client derives every URL from the
|
|
90
|
+
`basePath` published in `clientConfig()`.
|
|
91
|
+
|
|
96
92
|
See [Client wiring](#client-wiring) for the full `MastraClientConfig`
|
|
97
93
|
shape and per-agent selection.
|
|
98
94
|
|
|
@@ -136,9 +132,9 @@ Plugin-level fields:
|
|
|
136
132
|
| Field | Description |
|
|
137
133
|
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
138
134
|
| `agents` | The registry. Omit for a built-in `default` analyst. |
|
|
139
|
-
| `defaultAgent` | Id
|
|
135
|
+
| `defaultAgent` | Id the client talks to when no `:agentId` is supplied. Defaults to first registered. |
|
|
140
136
|
| `defaultModel` | Fallback for any agent that omits `model`. Same shape (string sugar or `DynamicArgument`). |
|
|
141
|
-
| `defaultModelFallbacks` | Priority-ordered list
|
|
137
|
+
| `defaultModelFallbacks` | Priority-ordered list tried first when no `model` / env / override is set, ahead of the dynamic score-classified catalogue. First entry whose endpoint exists in the workspace wins. When unset, resolution is driven by the live Foundation Model API scores (see [Model resolution](#model-resolution)); set this to pin a regulated workspace to an approved subset. Compose one with `modelsForTier(ModelTier.Fast)`. |
|
|
142
138
|
| `tools` | Ambient tools merged into every agent (per-agent tools win on collisions). |
|
|
143
139
|
| `storage` | `undefined` (default) auto-enables when `lakebase()` is registered; `true` does the same explicitly; `false` opts out; an object opens a dedicated `PostgresStore`. Per-agent default is `schemaName: "mastra_<agentId>"`. |
|
|
144
140
|
| `memory` | `undefined` (default) auto-enables when `lakebase()` is registered; `true` does the same explicitly; `false` opts out; an object opens a dedicated `PgVector`. Default behavior: one shared `PgVector` singleton across every agent. |
|
|
@@ -254,7 +250,7 @@ Genie writer event flow:
|
|
|
254
250
|
- Charts ride out-of-band: `prepare_chart` mints a `chartId`
|
|
255
251
|
synchronously, the planner runs in the background and writes
|
|
256
252
|
the spec to the chart cache (1h TTL). The host UI long-polls
|
|
257
|
-
`${
|
|
253
|
+
`${basePath}/embed/chart/:id` (via `MastraPluginClient.chart(id)`)
|
|
258
254
|
by id and renders inline at the matching `[chart:<chartId>]`
|
|
259
255
|
marker.
|
|
260
256
|
- After a hard reload, the live `started` / `status` / `sql`
|
|
@@ -426,43 +422,48 @@ loose tokens like `"claude sonnet"` snap to
|
|
|
426
422
|
`modelFuzzyThreshold` (default `0.4`) the input is returned verbatim
|
|
427
423
|
and Databricks surfaces the canonical 404.
|
|
428
424
|
|
|
429
|
-
### No explicit ask (
|
|
430
|
-
|
|
431
|
-
When nothing is set, the resolver
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
`
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
425
|
+
### No explicit ask (dynamic, score-based tiers)
|
|
426
|
+
|
|
427
|
+
When nothing is set, the resolver classifies the **live** workspace
|
|
428
|
+
catalogue and returns **the first id that is actually present in the
|
|
429
|
+
endpoint listing**. This is how a workspace without Claude Opus still
|
|
430
|
+
gets a sensible default automatically - the resolver skips ahead to
|
|
431
|
+
whichever model is the best fit and actually wired up.
|
|
432
|
+
|
|
433
|
+
Tiers are derived, not hard-coded. Databricks publishes a
|
|
434
|
+
`quality` / `speed` / `cost` profile per Foundation Model API endpoint
|
|
435
|
+
(the bars in the AI Playground), surfaced on `ServingEndpointSummary.profile`.
|
|
436
|
+
`classifyEndpoints(endpoints)` buckets the scored chat models by the
|
|
437
|
+
**relative distribution** of `quality`: the observed scores are split
|
|
438
|
+
at their 1/3 and 2/3 quantiles, so the top third is
|
|
439
|
+
`ModelTier.Thinking`, the bottom third `ModelTier.Fast`, and the
|
|
440
|
+
middle `ModelTier.Balanced`. Because the thresholds come from the data,
|
|
441
|
+
the split adapts as Databricks adds or rescores models - nothing is
|
|
442
|
+
pinned to a fixed score band, and a brand-new model that lands outside
|
|
443
|
+
today's range still slots in next to its peers.
|
|
444
|
+
|
|
445
|
+
Two escape hatches cover missing scores:
|
|
446
|
+
|
|
447
|
+
- **Unscored but recognizable** endpoints (a model Databricks hasn't
|
|
448
|
+
scored yet, e.g. a fresh release) are placed by a small **family
|
|
449
|
+
heuristic** keyed on provider + variant words (`opus`/`sonnet`/`haiku`,
|
|
450
|
+
`pro`/`mini`/`nano`, `flash`/`flash-lite`, Llama parameter sizes).
|
|
451
|
+
Unrecognized, unscored endpoints are never auto-selected.
|
|
452
|
+
- **Catalogue unreachable**: the resolver falls back to the small,
|
|
453
|
+
family-classified `FALLBACK_MODEL_IDS` floor (Thinking → Balanced →
|
|
454
|
+
Fast).
|
|
455
|
+
|
|
456
|
+
The default chain is therefore: any `defaultModelFallbacks` you set,
|
|
457
|
+
then the live score-classified catalogue in descending tier order,
|
|
458
|
+
then the `FALLBACK_MODEL_IDS` floor.
|
|
460
459
|
|
|
461
460
|
#### Pick a tier-appropriate model for one agent
|
|
462
461
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
call
|
|
462
|
+
`modelForTier(tier)` / `modelsForTier(tier)` return the **static
|
|
463
|
+
fallback opinion** for a tier (the small built-in list, no workspace
|
|
464
|
+
call). They're handy for seeding a default; the agent-step resolver
|
|
465
|
+
still fuzzy-matches the result against the live catalogue at call time
|
|
466
|
+
so it works even when the literal pick isn't deployed.
|
|
466
467
|
|
|
467
468
|
```ts
|
|
468
469
|
import { createAgent, ModelTier, modelForTier } from "@dbx-tools/appkit-mastra";
|
|
@@ -480,7 +481,7 @@ const planner = createAgent({
|
|
|
480
481
|
|
|
481
482
|
#### Bias the plugin-level fallback toward a tier
|
|
482
483
|
|
|
483
|
-
`modelsForTier(tier)` returns the
|
|
484
|
+
`modelsForTier(tier)` returns the static fallback list for one tier;
|
|
484
485
|
pass it to `defaultModelFallbacks` to scope the auto-resolver:
|
|
485
486
|
|
|
486
487
|
```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
* consumers.
|
|
12
12
|
*/
|
|
13
13
|
export * from "@dbx-tools/appkit-mastra-shared";
|
|
14
|
+
export * from "@dbx-tools/model";
|
|
14
15
|
export * from "./src/agents.js";
|
|
15
16
|
export * from "./src/chart.js";
|
|
16
17
|
export * from "./src/config.js";
|
|
17
18
|
export * from "./src/genie.js";
|
|
18
|
-
export { FALLBACK_MODEL_IDS, MODEL_CATALOG, ModelTier, modelForTier, modelsForTier, } from "./src/model.js";
|
|
19
19
|
export * from "./src/plugin.js";
|
|
20
|
-
export { MASTRA_MODEL_OVERRIDE_KEY, MODEL_OVERRIDE_BODY_FIELDS, MODEL_OVERRIDE_HEADER, MODEL_OVERRIDE_QUERY,
|
|
20
|
+
export { MASTRA_MODEL_OVERRIDE_KEY, MODEL_OVERRIDE_BODY_FIELDS, MODEL_OVERRIDE_HEADER, MODEL_OVERRIDE_QUERY, extractModelOverride, type ModelOverrideRequest, } from "./src/serving.js";
|
|
21
21
|
export * from "./src/tools/email.js";
|
package/dist/index.js
CHANGED
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
* consumers.
|
|
12
12
|
*/
|
|
13
13
|
export * from "@dbx-tools/appkit-mastra-shared";
|
|
14
|
+
export * from "@dbx-tools/model";
|
|
14
15
|
export * from "./src/agents.js";
|
|
15
16
|
export * from "./src/chart.js";
|
|
16
17
|
export * from "./src/config.js";
|
|
17
18
|
export * from "./src/genie.js";
|
|
18
|
-
export { FALLBACK_MODEL_IDS, MODEL_CATALOG, ModelTier, modelForTier, modelsForTier, } from "./src/model.js";
|
|
19
19
|
export * from "./src/plugin.js";
|
|
20
|
-
export { MASTRA_MODEL_OVERRIDE_KEY, MODEL_OVERRIDE_BODY_FIELDS, MODEL_OVERRIDE_HEADER, MODEL_OVERRIDE_QUERY,
|
|
20
|
+
export { MASTRA_MODEL_OVERRIDE_KEY, MODEL_OVERRIDE_BODY_FIELDS, MODEL_OVERRIDE_HEADER, MODEL_OVERRIDE_QUERY, extractModelOverride, } from "./src/serving.js";
|
|
21
21
|
export * from "./src/tools/email.js";
|
package/dist/src/agents.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* When no agents are registered the plugin falls back to a single
|
|
12
12
|
* built-in analyst so the bare `mastra()` call still mounts a working
|
|
13
|
-
*
|
|
13
|
+
* streamable agent for demos.
|
|
14
14
|
*/
|
|
15
15
|
import { appkitUtils, logUtils } from "@dbx-tools/shared";
|
|
16
16
|
import type { AgentConfig, ToolsInput } from "@mastra/core/agent";
|
|
@@ -185,8 +185,8 @@ export type MastraToolsFn = (plugins: MastraPlugins) => MastraTools | Promise<Ma
|
|
|
185
185
|
/**
|
|
186
186
|
* A code-defined Mastra agent. Mirrors the shape AppKit's `agents`
|
|
187
187
|
* plugin uses for `AgentDefinition`. The registry key under
|
|
188
|
-
* `config.agents` is
|
|
189
|
-
* informational (defaults to the key).
|
|
188
|
+
* `config.agents` is the `agentId` the client streams against; `name`
|
|
189
|
+
* is purely informational (defaults to the key).
|
|
190
190
|
*/
|
|
191
191
|
export interface MastraAgentDefinition {
|
|
192
192
|
/** Display name used as `Agent.name`. Defaults to the registry key. */
|
package/dist/src/agents.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* When no agents are registered the plugin falls back to a single
|
|
12
12
|
* built-in analyst so the bare `mastra()` call still mounts a working
|
|
13
|
-
*
|
|
13
|
+
* streamable agent for demos.
|
|
14
14
|
*/
|
|
15
15
|
import { appkitUtils, logUtils, stringUtils } from "@dbx-tools/shared";
|
|
16
16
|
import { Agent } from "@mastra/core/agent";
|
package/dist/src/chart.d.ts
CHANGED
|
@@ -144,4 +144,10 @@ export declare function fetchChart(chartId: string, options?: FetchChartOptions)
|
|
|
144
144
|
* `prepare_chart` tool, which accepts a `statement_id` and
|
|
145
145
|
* resolves the rows lazily.
|
|
146
146
|
*/
|
|
147
|
-
export declare function buildRenderDataTool(config: MastraPluginConfig): import("@mastra/core/tools").Tool<
|
|
147
|
+
export declare function buildRenderDataTool(config: MastraPluginConfig): import("@mastra/core/tools").Tool<{
|
|
148
|
+
title: string;
|
|
149
|
+
data: readonly Record<string, unknown>[];
|
|
150
|
+
description?: string | undefined;
|
|
151
|
+
}, {
|
|
152
|
+
chartId: string;
|
|
153
|
+
}, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "render_data", unknown>;
|
package/dist/src/chart.js
CHANGED
|
@@ -30,7 +30,7 @@ import { commonUtils, logUtils, stringUtils } from "@dbx-tools/shared";
|
|
|
30
30
|
import { Agent } from "@mastra/core/agent";
|
|
31
31
|
import { createTool } from "@mastra/core/tools";
|
|
32
32
|
import { z } from "zod";
|
|
33
|
-
import { buildModel,
|
|
33
|
+
import { buildModel, ModelTier } from "./model.js";
|
|
34
34
|
const log = logUtils.logger("mastra/chart");
|
|
35
35
|
/* ------------------------------ constants ------------------------------ */
|
|
36
36
|
/**
|
|
@@ -276,9 +276,7 @@ function getPlannerAgent(config) {
|
|
|
276
276
|
name: "Chart Planner",
|
|
277
277
|
description: "Picks chart type and axis encodings for a dataset.",
|
|
278
278
|
instructions: CHART_PLANNER_INSTRUCTIONS,
|
|
279
|
-
model: ({ requestContext }) => buildModel(config, requestContext, {
|
|
280
|
-
modelId: modelForTier(ModelTier.Fast),
|
|
281
|
-
}),
|
|
279
|
+
model: ({ requestContext }) => buildModel(config, requestContext, { tier: ModelTier.Fast }),
|
|
282
280
|
});
|
|
283
281
|
plannerAgents.set(config, agent);
|
|
284
282
|
}
|
|
@@ -302,7 +300,7 @@ async function runChartPlanner(config, request, options = {}) {
|
|
|
302
300
|
...(requestContext ? { requestContext } : {}),
|
|
303
301
|
...(abortSignal ? { abortSignal } : {}),
|
|
304
302
|
});
|
|
305
|
-
const plan = result.object;
|
|
303
|
+
const plan = chartPlanSchema.parse(result.object);
|
|
306
304
|
const option = planToEchartsOption(plan, title);
|
|
307
305
|
return { chartType: plan.chartType, option };
|
|
308
306
|
}
|
package/dist/src/config.d.ts
CHANGED
|
@@ -125,7 +125,8 @@ export interface MastraPluginConfig extends BasePluginConfig {
|
|
|
125
125
|
*/
|
|
126
126
|
tools?: MastraTools;
|
|
127
127
|
/**
|
|
128
|
-
* Agent id used
|
|
128
|
+
* Agent id used when the client doesn't specify one (the bare,
|
|
129
|
+
* un-suffixed history / suggestions routes resolve to it).
|
|
129
130
|
* Defaults to the first key in `agents` (or `"default"` when
|
|
130
131
|
* `agents` is omitted). Must match an id in `agents` when both are
|
|
131
132
|
* set; a mismatch throws at setup with the available candidates.
|
|
@@ -173,17 +174,19 @@ export interface MastraPluginConfig extends BasePluginConfig {
|
|
|
173
174
|
*/
|
|
174
175
|
modelOverride?: boolean;
|
|
175
176
|
/**
|
|
176
|
-
* Priority-ordered list of endpoint names tried when no
|
|
177
|
-
* plugin / env / request-override model id is set
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
177
|
+
* Priority-ordered list of endpoint names tried *first* when no
|
|
178
|
+
* agent / plugin / env / request-override model id is set, ahead of
|
|
179
|
+
* the dynamic score-classified catalogue. The resolver picks the
|
|
180
|
+
* first id that is actually present in the workspace's
|
|
181
|
+
* `/serving-endpoints` listing.
|
|
181
182
|
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
183
|
+
* When unset, resolution is driven by the live Foundation Model API
|
|
184
|
+
* `quality` / `speed` / `cost` scores: endpoints are classified into
|
|
185
|
+
* tiers (`classifyEndpoints`) and walked best-first (Thinking ->
|
|
186
|
+
* Balanced -> Fast), with the small built-in `FALLBACK_MODEL_IDS`
|
|
187
|
+
* list as the floor when the catalogue can't be read. Set this to
|
|
188
|
+
* pin a regulated workspace to an approved subset, or to put custom
|
|
189
|
+
* endpoints in front of the auto-classified catalogue.
|
|
187
190
|
*/
|
|
188
191
|
defaultModelFallbacks?: readonly string[];
|
|
189
192
|
/**
|
package/dist/src/genie.d.ts
CHANGED
|
@@ -142,18 +142,6 @@ export declare function buildGenieToolkitProvider(opts: {
|
|
|
142
142
|
}): {
|
|
143
143
|
toolkit(opts?: unknown): MastraTools;
|
|
144
144
|
};
|
|
145
|
-
/**
|
|
146
|
-
* Returns `true` when at least one Genie space is reachable
|
|
147
|
-
* through {@link resolveGenieSpaces} - either via
|
|
148
|
-
* {@link MastraPluginConfig.genieSpaces}, the AppKit `genie()`
|
|
149
|
-
* plugin instance, or the `DATABRICKS_GENIE_SPACE_ID` env var.
|
|
150
|
-
*
|
|
151
|
-
* Cheap to call from `resolveProvider` to short-circuit `genie`
|
|
152
|
-
* lookups when nothing is wired, so the `plugins.genie` lookup
|
|
153
|
-
* still resolves to `undefined` (matching AppKit's
|
|
154
|
-
* absent-plugin semantics) when neither source is configured.
|
|
155
|
-
*/
|
|
156
|
-
export declare function hasAnyGenieSpaces(config: MastraPluginConfig, context: appkitUtils.PluginContextLike | undefined): boolean;
|
|
157
145
|
/**
|
|
158
146
|
* Collect the curated starter questions across every resolved Genie
|
|
159
147
|
* space, deduped and capped. Each space's `sample_questions` are
|
package/dist/src/genie.js
CHANGED
|
@@ -37,7 +37,7 @@ import { CacheManager, genie } from "@databricks/appkit";
|
|
|
37
37
|
import { ApiError, HttpError, WorkspaceClient } from "@databricks/sdk-experimental";
|
|
38
38
|
import { ChartSchema, } from "@dbx-tools/appkit-mastra-shared";
|
|
39
39
|
import { genieEventChat, genieSampleQuestions, getGenieSpace } from "@dbx-tools/genie";
|
|
40
|
-
import {} from "@dbx-tools/genie-shared";
|
|
40
|
+
import { GenieMessageSchema } from "@dbx-tools/genie-shared";
|
|
41
41
|
import { appkitUtils, commonUtils, logUtils, stringUtils } from "@dbx-tools/shared";
|
|
42
42
|
import { MASTRA_THREAD_ID_KEY } from "@mastra/core/request-context";
|
|
43
43
|
import { createTool } from "@mastra/core/tools";
|
|
@@ -334,7 +334,7 @@ function buildAskGenieTool(opts) {
|
|
|
334
334
|
question: z.string().min(1, "question is required"),
|
|
335
335
|
}),
|
|
336
336
|
outputSchema: z.object({
|
|
337
|
-
message:
|
|
337
|
+
message: GenieMessageSchema,
|
|
338
338
|
}),
|
|
339
339
|
execute: async ({ question }, ctxRaw) => {
|
|
340
340
|
const ctx = ctxRaw;
|
|
@@ -891,20 +891,6 @@ export function buildGenieToolkitProvider(opts) {
|
|
|
891
891
|
},
|
|
892
892
|
};
|
|
893
893
|
}
|
|
894
|
-
/**
|
|
895
|
-
* Returns `true` when at least one Genie space is reachable
|
|
896
|
-
* through {@link resolveGenieSpaces} - either via
|
|
897
|
-
* {@link MastraPluginConfig.genieSpaces}, the AppKit `genie()`
|
|
898
|
-
* plugin instance, or the `DATABRICKS_GENIE_SPACE_ID` env var.
|
|
899
|
-
*
|
|
900
|
-
* Cheap to call from `resolveProvider` to short-circuit `genie`
|
|
901
|
-
* lookups when nothing is wired, so the `plugins.genie` lookup
|
|
902
|
-
* still resolves to `undefined` (matching AppKit's
|
|
903
|
-
* absent-plugin semantics) when neither source is configured.
|
|
904
|
-
*/
|
|
905
|
-
export function hasAnyGenieSpaces(config, context) {
|
|
906
|
-
return Object.keys(resolveGenieSpaces(config, context)).length > 0;
|
|
907
|
-
}
|
|
908
894
|
/* --------------------------- starter suggestions --------------------------- */
|
|
909
895
|
/**
|
|
910
896
|
* Default cap on starter suggestions surfaced to the chat empty
|
package/dist/src/history.d.ts
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* The route is registered through {@link historyRoute} as a Mastra
|
|
11
11
|
* `registerApiRoute` so it sits in the same dispatcher pipeline as
|
|
12
|
-
*
|
|
13
|
-
* `./server.ts`) has already populated `RequestContext` with
|
|
12
|
+
* the standard agent routes. That means the `MastraServer` auth
|
|
13
|
+
* middleware (in `./server.ts`) has already populated `RequestContext` with
|
|
14
14
|
* `MASTRA_THREAD_ID_KEY` and `MASTRA_RESOURCE_ID_KEY` by the time
|
|
15
15
|
* the handler runs - no cookie or user lookups happen here, and the
|
|
16
16
|
* session-cookie logic stays the single source of truth in `server.ts`.
|
|
@@ -83,10 +83,10 @@ export type HistoryRouteOptions = {
|
|
|
83
83
|
* anchors the thread id is left alone so the user keeps the
|
|
84
84
|
* same thread - only the contents go away.
|
|
85
85
|
*
|
|
86
|
-
*
|
|
87
|
-
* fixed-agent mount, or include
|
|
88
|
-
*
|
|
89
|
-
*
|
|
86
|
+
* Follows the `@mastra/ai-sdk` `chatRoute` convention for agent
|
|
87
|
+
* binding: pass `agent` for a fixed-agent mount, or include
|
|
88
|
+
* `:agentId` in the path for dynamic routing. The plugin registers
|
|
89
|
+
* both `/route/history` (default agent) and `/route/history/:agentId`.
|
|
90
90
|
*
|
|
91
91
|
* The handler reads `threadId` and `resourceId` from `RequestContext`
|
|
92
92
|
* (populated upstream by `MastraServer.registerAuthMiddleware`), so
|
package/dist/src/history.js
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* The route is registered through {@link historyRoute} as a Mastra
|
|
11
11
|
* `registerApiRoute` so it sits in the same dispatcher pipeline as
|
|
12
|
-
*
|
|
13
|
-
* `./server.ts`) has already populated `RequestContext` with
|
|
12
|
+
* the standard agent routes. That means the `MastraServer` auth
|
|
13
|
+
* middleware (in `./server.ts`) has already populated `RequestContext` with
|
|
14
14
|
* `MASTRA_THREAD_ID_KEY` and `MASTRA_RESOURCE_ID_KEY` by the time
|
|
15
15
|
* the handler runs - no cookie or user lookups happen here, and the
|
|
16
16
|
* session-cookie logic stays the single source of truth in `server.ts`.
|
|
@@ -153,10 +153,10 @@ export async function clearHistory(opts) {
|
|
|
153
153
|
* anchors the thread id is left alone so the user keeps the
|
|
154
154
|
* same thread - only the contents go away.
|
|
155
155
|
*
|
|
156
|
-
*
|
|
157
|
-
* fixed-agent mount, or include
|
|
158
|
-
*
|
|
159
|
-
*
|
|
156
|
+
* Follows the `@mastra/ai-sdk` `chatRoute` convention for agent
|
|
157
|
+
* binding: pass `agent` for a fixed-agent mount, or include
|
|
158
|
+
* `:agentId` in the path for dynamic routing. The plugin registers
|
|
159
|
+
* both `/route/history` (default agent) and `/route/history/:agentId`.
|
|
160
160
|
*
|
|
161
161
|
* The handler reads `threadId` and `resourceId` from `RequestContext`
|
|
162
162
|
* (populated upstream by `MastraServer.registerAuthMiddleware`), so
|
package/dist/src/memory.d.ts
CHANGED
|
@@ -26,45 +26,55 @@
|
|
|
26
26
|
* (auto-defaulted to `true` in `plugin.ts` when the `lakebase` plugin
|
|
27
27
|
* is registered); per-agent settings cascade on top of that.
|
|
28
28
|
*/
|
|
29
|
-
import { lakebase } from "@databricks/appkit";
|
|
30
|
-
import { appkitUtils } from "@dbx-tools/shared";
|
|
31
29
|
import { Memory } from "@mastra/memory";
|
|
32
30
|
import { PostgresStore } from "@mastra/pg";
|
|
31
|
+
import { Pool, type PoolConfig } from "pg";
|
|
33
32
|
import type { MastraAgentDefinition } from "./agents.js";
|
|
34
33
|
import type { MastraPluginConfig } from "./config.js";
|
|
35
|
-
/** Pool handle returned by the AppKit `lakebase` plugin `exports().pool`. */
|
|
36
|
-
export type LakebasePool = ReturnType<InstanceType<ReturnType<typeof lakebase>["plugin"]>["exports"]>["pool"];
|
|
37
34
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
35
|
+
* Build a dedicated **service-principal** Lakebase pool for Mastra
|
|
36
|
+
* memory from the lakebase plugin's resolved SP pg config.
|
|
37
|
+
*
|
|
38
|
+
* The plugin's `exports().pool` is a `RoutingPool` that switches to
|
|
39
|
+
* the per-user (OBO) pool whenever a query runs inside an `asUser`
|
|
40
|
+
* scope - exactly the context the mastra plugin establishes around
|
|
41
|
+
* every chat turn. Memory (threads / messages + semantic recall) must
|
|
42
|
+
* instead always act as the app service principal: it owns the
|
|
43
|
+
* auto-created `mastra_*` schemas (a per-user role usually can't
|
|
44
|
+
* `CREATE SCHEMA`) and is shared across users, so it cannot inherit a
|
|
45
|
+
* request's OBO identity.
|
|
46
|
+
*
|
|
47
|
+
* `pgConfig` must be the plugin's `exports().getPgConfig()` evaluated
|
|
48
|
+
* **outside** any `asUser` scope (i.e. during setup), so it carries
|
|
49
|
+
* the SP connection target, OAuth token-refresh `password` callback,
|
|
50
|
+
* and any `lakebase({ pool })` tuning overrides - all of which this
|
|
51
|
+
* pool inherits. See the call site in `plugin.ts`.
|
|
42
52
|
*/
|
|
43
|
-
export declare function
|
|
53
|
+
export declare function createServicePrincipalPool(pgConfig: PoolConfig): Promise<Pool>;
|
|
44
54
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
55
|
+
* True when any plugin-level or per-agent setting could need the
|
|
56
|
+
* Lakebase pool. Used by `plugin.ts` to gate creation of the
|
|
57
|
+
* service-principal pool and the {@link MemoryBuilder} that consumes
|
|
58
|
+
* it; when false neither is built.
|
|
49
59
|
*/
|
|
50
|
-
export declare function
|
|
60
|
+
export declare function needsLakebase(config: MastraPluginConfig): boolean;
|
|
51
61
|
/**
|
|
52
|
-
* Construct a per-agent {@link Memory} factory
|
|
53
|
-
*
|
|
54
|
-
*
|
|
62
|
+
* Construct a per-agent {@link Memory} factory bound to the supplied
|
|
63
|
+
* service-principal pool (see {@link createServicePrincipalPool}).
|
|
64
|
+
* Caches the shared `PgVector` singleton (built on first need) so each
|
|
65
|
+
* agent build is O(1) after the first.
|
|
55
66
|
*/
|
|
56
|
-
export declare function createMemoryBuilder(config: MastraPluginConfig,
|
|
67
|
+
export declare function createMemoryBuilder(config: MastraPluginConfig, servicePrincipalPool: Pool): MemoryBuilder;
|
|
57
68
|
/**
|
|
58
|
-
* Builds one `Memory` per agent
|
|
59
|
-
*
|
|
60
|
-
* registering N agents stays cheap.
|
|
69
|
+
* Builds one `Memory` per agent against a shared service-principal
|
|
70
|
+
* Lakebase pool. Per-instance state keeps the shared `PgVector` alive
|
|
71
|
+
* across calls so registering N agents stays cheap.
|
|
61
72
|
*/
|
|
62
73
|
export declare class MemoryBuilder {
|
|
63
74
|
private readonly config;
|
|
64
|
-
private readonly
|
|
75
|
+
private readonly servicePrincipalPool;
|
|
65
76
|
private sharedVector;
|
|
66
|
-
|
|
67
|
-
constructor(config: MastraPluginConfig, context: appkitUtils.PluginContextLike | undefined);
|
|
77
|
+
constructor(config: MastraPluginConfig, servicePrincipalPool: Pool);
|
|
68
78
|
/**
|
|
69
79
|
* Build a `Memory` for `agentId` after the plugin/agent cascade.
|
|
70
80
|
* Returns `undefined` when the agent has neither storage nor a
|
|
@@ -96,5 +106,4 @@ export declare class MemoryBuilder {
|
|
|
96
106
|
*/
|
|
97
107
|
private buildVector;
|
|
98
108
|
private getSharedVector;
|
|
99
|
-
private requirePool;
|
|
100
109
|
}
|