@dbx-tools/appkit-mastra 0.1.25 → 0.1.27
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 +115 -303
- package/dist/src/agents.d.ts +10 -0
- package/dist/src/agents.js +15 -2
- package/dist/src/chart.d.ts +131 -79
- package/dist/src/chart.js +386 -279
- package/dist/src/config.d.ts +19 -16
- package/dist/src/genie.d.ts +90 -106
- package/dist/src/genie.js +523 -642
- package/dist/src/intercept.d.ts +48 -0
- package/dist/src/intercept.js +167 -0
- package/dist/src/plugin.d.ts +12 -0
- package/dist/src/plugin.js +185 -1
- package/dist/src/processors/strip-stale-charts.d.ts +16 -13
- package/dist/src/processors/strip-stale-charts.js +16 -13
- package/dist/src/statement.d.ts +73 -0
- package/dist/src/statement.js +118 -0
- package/dist/src/tools/email.js +27 -28
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/agents.ts +16 -2
- package/src/chart.ts +499 -319
- package/src/config.ts +19 -16
- package/src/genie.ts +560 -768
- package/src/intercept.ts +206 -0
- package/src/plugin.ts +210 -2
- package/src/processors/strip-stale-charts.ts +16 -13
- package/src/statement.ts +127 -0
- package/src/tools/email.ts +27 -28
package/dist/src/config.d.ts
CHANGED
|
@@ -191,7 +191,7 @@ export interface MastraPluginConfig extends BasePluginConfig {
|
|
|
191
191
|
* processor that strips `chartId` fields from prior assistant
|
|
192
192
|
* tool-invocation results before they reach the model. This
|
|
193
193
|
* prevents the model from reusing turn-scoped chartIds it sees
|
|
194
|
-
* in memory recall (which would leave `[
|
|
194
|
+
* in memory recall (which would leave `[chart:<id>]` markers
|
|
195
195
|
* pointing at writer events that no longer exist).
|
|
196
196
|
*
|
|
197
197
|
* Set to `false` to opt out - useful if a non-default agent
|
|
@@ -266,22 +266,25 @@ export interface MastraPluginConfig extends BasePluginConfig {
|
|
|
266
266
|
*/
|
|
267
267
|
genieSpaceCacheTtlMs?: number;
|
|
268
268
|
/**
|
|
269
|
-
* Maximum LLM steps
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
269
|
+
* Maximum LLM steps each agent gets per turn. One step = one
|
|
270
|
+
* round-trip to the underlying model (a tool call consumes a
|
|
271
|
+
* step, the final-text reply consumes one too). Applies to
|
|
272
|
+
* every agent registered through {@link MastraPluginConfig.agents}
|
|
273
|
+
* - per-agent overrides aren't surfaced yet because the same
|
|
274
|
+
* ceiling has been sufficient across every workload we've run.
|
|
273
275
|
*
|
|
274
|
-
* Defaults to
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* Mastra's own `agent.generate` default of 5 would
|
|
279
|
-
*
|
|
280
|
-
* the ceiling here is what lets the
|
|
276
|
+
* Defaults to {@link DEFAULT_AGENT_MAX_STEPS} (25), sized to fit
|
|
277
|
+
* a decomposed Genie turn (grounding + several `ask_genie` calls
|
|
278
|
+
* + `prepare_chart` per dataset + the final-text reply) with
|
|
279
|
+
* headroom for the model to chain a couple of follow-ups before
|
|
280
|
+
* answering. Mastra's own `agent.generate` default of 5 would
|
|
281
|
+
* cut multi-step orchestration off after 2-3 tool calls, so
|
|
282
|
+
* explicitly raising the ceiling here is what lets the
|
|
283
|
+
* agent-mode loop play out.
|
|
281
284
|
*
|
|
282
|
-
* Lower
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
+
* Lower when an unusually slow or expensive model makes long
|
|
286
|
+
* turns unaffordable; raise for exploratory workloads that need
|
|
287
|
+
* to drill deep into a dataset within a single turn.
|
|
285
288
|
*/
|
|
286
|
-
|
|
289
|
+
agentMaxSteps?: number;
|
|
287
290
|
}
|
package/dist/src/genie.d.ts
CHANGED
|
@@ -1,46 +1,61 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Genie
|
|
2
|
+
* Genie tools for Mastra.
|
|
3
3
|
*
|
|
4
|
-
* Each configured Genie space
|
|
5
|
-
* calling agent
|
|
6
|
-
*
|
|
4
|
+
* Each configured Genie space is surfaced as a small set of flat
|
|
5
|
+
* Mastra tools the calling agent can drive directly - no inner
|
|
6
|
+
* orchestrator agent. The central agent decomposes user questions,
|
|
7
|
+
* picks which Genie space to ask, and composes the final reply.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `started` writer event so the host UI can show progress
|
|
11
|
-
* immediately, before any LLM round-trip.
|
|
12
|
-
* 2. Spins up a per-call inner Mastra `Agent` with three tools:
|
|
13
|
-
* - `ask_genie`: drives one `genieEventChat` turn, fetches
|
|
14
|
-
* the matching statement's rows when the turn ran SQL,
|
|
15
|
-
* and forwards every wire event (status, thinking, sql,
|
|
16
|
-
* rows) through `ctx.writer` for streaming UI updates.
|
|
17
|
-
* - `get_space_description`: cheap title / description /
|
|
18
|
-
* warehouse id lookup for grounding.
|
|
19
|
-
* - `get_space_serialized`: full `GenieSpace` JSON for
|
|
20
|
-
* column-level grounding when the description isn't
|
|
21
|
-
* enough.
|
|
22
|
-
* 3. Runs the inner agent with `structuredOutput` (Mastra's
|
|
23
|
-
* two-pass mode + `jsonPromptInjection`) to coerce the
|
|
24
|
-
* agent's final answer into a tagged
|
|
25
|
-
* `[{type:"text"|"data", ...}]` array. The two-pass design
|
|
26
|
-
* avoids Databricks Model Serving's `response_format` +
|
|
27
|
-
* `tools` collision; prompt injection sidesteps the
|
|
28
|
-
* separate `response_format` + streaming collision in the
|
|
29
|
-
* structuring agent.
|
|
30
|
-
* 4. Charts every `data` item in parallel via
|
|
31
|
-
* {@link runChartPlanner}, maps `text` items to the shared
|
|
32
|
-
* {@link GenieSummaryItem} `string` variant, and returns the
|
|
33
|
-
* hydrated {@link GenieAgentResult}.
|
|
9
|
+
* Per-space tools (suffixed with `_<alias>` for non-default
|
|
10
|
+
* aliases):
|
|
34
11
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* `
|
|
38
|
-
*
|
|
39
|
-
*
|
|
12
|
+
* - `ask_genie`: drives one `genieEventChat` turn and
|
|
13
|
+
* forwards every wire event (status, thinking, sql, rows)
|
|
14
|
+
* through `ctx.writer` for streaming UI updates. Returns
|
|
15
|
+
* the terminal `GenieMessage` only - rows are NOT fetched
|
|
16
|
+
* eagerly.
|
|
17
|
+
* - `get_space_description`: cheap title / description /
|
|
18
|
+
* warehouse id lookup for grounding.
|
|
19
|
+
* - `get_space_serialized`: full `GenieSpace` JSON for
|
|
20
|
+
* column-level grounding when the description isn't enough.
|
|
21
|
+
*
|
|
22
|
+
* Space-agnostic shared tools (registered once, regardless of
|
|
23
|
+
* how many spaces are wired):
|
|
24
|
+
*
|
|
25
|
+
* - `get_statement`: opt-in lookup of a Genie statement's rows
|
|
26
|
+
* by `statement_id` (with a row `limit`). The agent calls
|
|
27
|
+
* this only when it needs to read values to reason about
|
|
28
|
+
* them; if the data is just being displayed, it embeds a
|
|
29
|
+
* `[data:<statement_id>]` marker in prose instead and lets
|
|
30
|
+
* the host UI resolve it.
|
|
31
|
+
* - `prepare_chart`: mints a short `chartId`, kicks off a
|
|
32
|
+
* background task that fetches the statement's rows and
|
|
33
|
+
* runs the chart-planner, and caches the resolved Echarts
|
|
34
|
+
* spec under the id (1h TTL). Returns the `chartId`
|
|
35
|
+
* synchronously so the agent embeds `[chart:<chartId>]`
|
|
36
|
+
* markers in prose without blocking on chart generation;
|
|
37
|
+
* the host UI fetches the cached chart by id once it's
|
|
38
|
+
* ready (see {@link fetchChart}).
|
|
39
|
+
*
|
|
40
|
+
* Each tool's `execute` pulls the per-request
|
|
41
|
+
* {@link WorkspaceClient} off `ctx.requestContext` (stamped by
|
|
42
|
+
* `MastraServer` under {@link MASTRA_USER_KEY}) and the per-call
|
|
43
|
+
* `writer` / `abortSignal` off `ctx`, so the tools are stateless
|
|
44
|
+
* across requests and the central agent owns the loop.
|
|
45
|
+
*
|
|
46
|
+
* The tools talk to Genie directly via `@dbx-tools/genie`
|
|
47
|
+
* (`genieEventChat`); statement-row fetching is delegated to
|
|
48
|
+
* {@link fetchStatementData} from `./statement.js`, which wraps
|
|
49
|
+
* the workspace `statementExecution.getStatement` API. AppKit's
|
|
50
|
+
* stock `genie` plugin is honored only for its `spaces` config
|
|
51
|
+
* so existing AppKit-style wiring keeps working without change.
|
|
52
|
+
*
|
|
53
|
+
* Suggested orchestration prompt for the central agent lives in
|
|
54
|
+
* {@link GENIE_INSTRUCTIONS}; compose it into the agent's own
|
|
55
|
+
* `instructions` when you want the canonical "how to drive the
|
|
56
|
+
* Genie tools" guidance.
|
|
40
57
|
*/
|
|
41
|
-
import { type ChartEvent } from "@dbx-tools/appkit-mastra-shared";
|
|
42
58
|
import { appkitUtils } from "@dbx-tools/shared";
|
|
43
|
-
import type { RequestContext } from "@mastra/core/request-context";
|
|
44
59
|
import type { MastraTools } from "./agents.js";
|
|
45
60
|
import type { MastraPluginConfig } from "./config.js";
|
|
46
61
|
/** Default alias used when a single unnamed Genie space is wired up. */
|
|
@@ -50,76 +65,40 @@ export interface GenieSpaceConfig {
|
|
|
50
65
|
/** Genie `space_id`. Required; resolves via `client.genie.getSpace`. */
|
|
51
66
|
spaceId: string;
|
|
52
67
|
/**
|
|
53
|
-
* Optional human-readable description appended to the
|
|
54
|
-
* tool
|
|
55
|
-
*
|
|
68
|
+
* Optional human-readable description appended to the per-space
|
|
69
|
+
* tool descriptions so the calling LLM has hints about *what
|
|
70
|
+
* data* this space covers (e.g. "orders, returns,
|
|
56
71
|
* fulfillment"). When omitted, only the space's own
|
|
57
|
-
* `description` (fetched on first use
|
|
72
|
+
* `description` (fetched on first use of `get_space_description`)
|
|
73
|
+
* is shown.
|
|
58
74
|
*/
|
|
59
75
|
hint?: string;
|
|
60
76
|
}
|
|
61
77
|
/** Map of alias -> space config. Accepts either explicit objects or bare space ids. */
|
|
62
78
|
export type GenieSpacesConfig = Record<string, GenieSpaceConfig | string>;
|
|
63
79
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* leak.
|
|
69
|
-
*/
|
|
70
|
-
export declare function chartInventoryFromContext(requestContext: RequestContext): Map<string, ChartEvent>;
|
|
71
|
-
/**
|
|
72
|
-
* Options for {@link createGenieTool}. Only carries config that
|
|
73
|
-
* doesn't vary per request - the per-request {@link WorkspaceClient},
|
|
74
|
-
* `RequestContext`, writer, and abort signal flow through the
|
|
75
|
-
* tool's `execute(_, ctx)` and are not captured here.
|
|
76
|
-
*/
|
|
77
|
-
export interface CreateGenieToolOptions {
|
|
78
|
-
/** Genie space id this tool targets. */
|
|
79
|
-
spaceId: string;
|
|
80
|
-
/** Plugin config; resolves the LLM and chart planner agent. */
|
|
81
|
-
config: MastraPluginConfig;
|
|
82
|
-
/** Override the registered tool id. Defaults to `"genie"`. */
|
|
83
|
-
toolId?: string;
|
|
84
|
-
/** Override the tool description shown to the calling LLM. */
|
|
85
|
-
toolDescription?: string;
|
|
86
|
-
/**
|
|
87
|
-
* Override the inner agent's max tool-loop steps. Defaults to
|
|
88
|
-
* {@link DEFAULT_MAX_STEPS}.
|
|
89
|
-
*/
|
|
90
|
-
maxSteps?: number;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Build the calling agent's Genie tool. The returned Mastra tool
|
|
94
|
-
* runs end-to-end on each invocation:
|
|
80
|
+
* Suggested orchestration prompt for the central agent that owns
|
|
81
|
+
* the Genie tools. Compose into your agent's `instructions` to
|
|
82
|
+
* get the canonical "decompose questions, ask Genie focused
|
|
83
|
+
* sub-questions, place data / chart markers in prose" behavior:
|
|
95
84
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* `statementId` are dropped with a warn log; chart-planner
|
|
112
|
-
* failures leave `dataset.chart` unset so the host UI falls
|
|
113
|
-
* back to a table.
|
|
114
|
-
*/
|
|
115
|
-
export declare function createGenieTool(opts: CreateGenieToolOptions): import("@mastra/core/tools").Tool<any, any, any, any, import("@mastra/core/tools").ToolExecutionContext<any, any, unknown>, string, unknown>;
|
|
116
|
-
/**
|
|
117
|
-
* Default tool id for a wired Genie alias. The well-known
|
|
118
|
-
* `default` alias collapses to `genie`; every other alias gets a
|
|
119
|
-
* `genie_` prefix so multi-space registrations stay
|
|
120
|
-
* disambiguated.
|
|
85
|
+
* ```ts
|
|
86
|
+
* createAgent({
|
|
87
|
+
* instructions: `${myAgentInstructions}\n\n${GENIE_INSTRUCTIONS}`,
|
|
88
|
+
* tools(plugins) {
|
|
89
|
+
* return { ...plugins.genie?.toolkit() };
|
|
90
|
+
* },
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* The prompt references the bare tool names (`ask_genie`,
|
|
95
|
+
* `get_space_description`, `get_space_serialized`,
|
|
96
|
+
* `get_statement`, `prepare_chart`) used for the single-space
|
|
97
|
+
* default alias. Multi-space deployments should write their own
|
|
98
|
+
* variant that names the suffixed per-space tools
|
|
99
|
+
* (e.g. `ask_genie_sales`).
|
|
121
100
|
*/
|
|
122
|
-
export declare
|
|
101
|
+
export declare const GENIE_INSTRUCTIONS: string;
|
|
123
102
|
/**
|
|
124
103
|
* Normalize the {@link GenieSpacesConfig} record. Bare-string
|
|
125
104
|
* entries (`{ default: "01ef..." }`) get wrapped as
|
|
@@ -154,14 +133,19 @@ export declare function normalizeGenieSpaces(spaces: GenieSpacesConfig | Record<
|
|
|
154
133
|
*/
|
|
155
134
|
export declare function resolveGenieSpaces(config: MastraPluginConfig, context: appkitUtils.PluginContextLike | undefined): Record<string, GenieSpaceConfig>;
|
|
156
135
|
/**
|
|
157
|
-
* Build
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
136
|
+
* Build the flat Mastra tools record for every configured Genie
|
|
137
|
+
* space. Two shared, space-agnostic tools (`get_statement`,
|
|
138
|
+
* `prepare_chart`) are registered once regardless of how many
|
|
139
|
+
* spaces are wired; the per-space tools (`ask_genie`,
|
|
140
|
+
* `get_space_description`, `get_space_serialized`) are suffixed
|
|
141
|
+
* with `_<alias>` for non-default aliases so multi-space
|
|
142
|
+
* deployments stay disambiguated.
|
|
161
143
|
*
|
|
162
|
-
* Returns a record keyed by tool id, ready to spread into
|
|
163
|
-
* `Agent`'s `tools` map (or surfaced via
|
|
164
|
-
* `plugins.genie?.toolkit()`).
|
|
144
|
+
* Returns a record keyed by tool id, ready to spread into the
|
|
145
|
+
* central `Agent`'s `tools` map (or surfaced via the
|
|
146
|
+
* `plugins.genie?.toolkit()` callback). Returns an empty record
|
|
147
|
+
* when `spaces` resolves to zero entries so the caller can spread
|
|
148
|
+
* safely.
|
|
165
149
|
*/
|
|
166
150
|
export declare function buildGenieTools(opts: {
|
|
167
151
|
spaces: GenieSpacesConfig | Record<string, GenieSpaceConfig>;
|
|
@@ -170,7 +154,7 @@ export declare function buildGenieTools(opts: {
|
|
|
170
154
|
/**
|
|
171
155
|
* Plugin-toolkit adapter so the `plugins.genie?.toolkit()` lookup
|
|
172
156
|
* inside an agent's `tools(plugins)` callback returns the
|
|
173
|
-
* Genie
|
|
157
|
+
* flat Genie tools record instead of throwing on missing plugin.
|
|
174
158
|
* Mirrors AppKit's `PluginToolkitProvider` shape.
|
|
175
159
|
*/
|
|
176
160
|
export declare function buildGenieToolkitProvider(opts: {
|