@dbx-tools/appkit-mastra 0.1.58 → 0.1.68

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.
Files changed (51) hide show
  1. package/README.md +41 -1
  2. package/dist/index.d.ts +1229 -17
  3. package/dist/index.js +3348 -19
  4. package/package.json +17 -30
  5. package/dist/src/agents.d.ts +0 -316
  6. package/dist/src/agents.js +0 -470
  7. package/dist/src/chart.d.ts +0 -153
  8. package/dist/src/chart.js +0 -570
  9. package/dist/src/config.d.ts +0 -295
  10. package/dist/src/config.js +0 -55
  11. package/dist/src/genie.d.ts +0 -161
  12. package/dist/src/genie.js +0 -973
  13. package/dist/src/history.d.ts +0 -95
  14. package/dist/src/history.js +0 -278
  15. package/dist/src/memory.d.ts +0 -109
  16. package/dist/src/memory.js +0 -253
  17. package/dist/src/model.d.ts +0 -52
  18. package/dist/src/model.js +0 -198
  19. package/dist/src/observability.d.ts +0 -64
  20. package/dist/src/observability.js +0 -83
  21. package/dist/src/plugin.d.ts +0 -177
  22. package/dist/src/plugin.js +0 -554
  23. package/dist/src/processor.d.ts +0 -8
  24. package/dist/src/processor.js +0 -40
  25. package/dist/src/processors/strip-stale-charts.d.ts +0 -32
  26. package/dist/src/processors/strip-stale-charts.js +0 -98
  27. package/dist/src/server.d.ts +0 -51
  28. package/dist/src/server.js +0 -152
  29. package/dist/src/serving.d.ts +0 -65
  30. package/dist/src/serving.js +0 -79
  31. package/dist/src/statement.d.ts +0 -66
  32. package/dist/src/statement.js +0 -111
  33. package/dist/src/writer.d.ts +0 -23
  34. package/dist/src/writer.js +0 -37
  35. package/dist/tsconfig.build.tsbuildinfo +0 -1
  36. package/index.ts +0 -27
  37. package/src/agents.ts +0 -772
  38. package/src/chart.ts +0 -716
  39. package/src/config.ts +0 -320
  40. package/src/genie.ts +0 -1123
  41. package/src/history.ts +0 -322
  42. package/src/memory.ts +0 -293
  43. package/src/model.ts +0 -257
  44. package/src/observability.ts +0 -114
  45. package/src/plugin.ts +0 -623
  46. package/src/processor.ts +0 -46
  47. package/src/processors/strip-stale-charts.ts +0 -102
  48. package/src/server.ts +0 -195
  49. package/src/serving.ts +0 -104
  50. package/src/statement.ts +0 -120
  51. package/src/writer.ts +0 -44
package/src/config.ts DELETED
@@ -1,320 +0,0 @@
1
- /**
2
- * Plugin configuration types and shared `RequestContext` keys.
3
- *
4
- * Kept in a leaf module so `plugin.ts`, `server.ts`, `model.ts`, and
5
- * `memory.ts` can import them without creating a cycle.
6
- */
7
-
8
- import type { BasePluginConfig } from "@databricks/appkit";
9
- import type { appkitUtils } from "@dbx-tools/shared";
10
- import type { AgentConfig } from "@mastra/core/agent";
11
- import {
12
- MASTRA_RESOURCE_ID_KEY,
13
- MASTRA_THREAD_ID_KEY,
14
- } from "@mastra/core/request-context";
15
- import type { PgVectorConfig, PostgresStoreConfig } from "@mastra/pg";
16
-
17
- import type { MastraAgentDefinition, MastraTools } from "./agents.js";
18
- import type { GenieSpacesConfig } from "./genie.js";
19
-
20
- /**
21
- * `RequestContext` key under which {@link MastraServer} stores the
22
- * resolved AppKit user. `model.ts` reads it to mint user-scoped
23
- * Databricks tokens.
24
- */
25
- export const MASTRA_USER_KEY = "mastra__user";
26
-
27
- /**
28
- * `RequestContext` keys for AppKit user metadata stamped by
29
- * {@link MastraServer}. Surfaced as trace metadata via
30
- * {@link TRACE_REQUEST_CONTEXT_KEYS} so traces are filterable by who
31
- * issued the request without leaking the full user object.
32
- */
33
- export const MASTRA_USER_NAME_KEY = "mastra__userName";
34
- export const MASTRA_USER_EMAIL_KEY = "mastra__userEmail";
35
-
36
- /**
37
- * `RequestContext` key for the per-HTTP-request id stamped by
38
- * {@link MastraServer}. Reads `X-Request-Id` from the incoming
39
- * headers when present (so an upstream load balancer / API gateway
40
- * can keep its trace correlation), falls back to a freshly minted
41
- * UUID. Echoed back on the response and surfaced on every span via
42
- * {@link TRACE_REQUEST_CONTEXT_KEYS} so logs and traces share a
43
- * join key.
44
- */
45
- export const MASTRA_REQUEST_ID_KEY = "mastra__requestId";
46
-
47
- /**
48
- * Canonical list of `RequestContext` keys we want Mastra to extract
49
- * as metadata on every observability span (agent runs, model calls,
50
- * tool invocations, workflow steps).
51
- *
52
- * Mirrors {@link https://mastra.ai/docs/observability/tracing/overview#automatic-metadata-from-requestcontext}:
53
- * passed verbatim into `Observability.configs[*].requestContextKeys`,
54
- * so any key listed here is read from `RequestContext` at trace
55
- * start and attached as scalar span metadata. Keep the set to plain
56
- * scalars - never include {@link MASTRA_USER_KEY} (it carries the
57
- * full AppKit execution context with a `WorkspaceClient` reference).
58
- *
59
- * Order is purely cosmetic; Mastra de-dupes internally.
60
- */
61
- export const TRACE_REQUEST_CONTEXT_KEYS: readonly string[] = [
62
- MASTRA_RESOURCE_ID_KEY,
63
- MASTRA_THREAD_ID_KEY,
64
- MASTRA_REQUEST_ID_KEY,
65
- MASTRA_USER_NAME_KEY,
66
- MASTRA_USER_EMAIL_KEY,
67
- // Model override key is owned by `serving.ts`; spelled inline here
68
- // so this module stays leaf-level (no cycles with `serving.ts`).
69
- "mastra__model_override",
70
- ];
71
-
72
- /** AppKit execution context plus the canonical user id. */
73
- export interface User {
74
- id: string;
75
- executionContext: appkitUtils.ExecutionContextLike;
76
- }
77
-
78
- /** PgVector config with an optional Mastra store id. */
79
- export type MastraMemoryConfig = PgVectorConfig & {
80
- id?: string;
81
- };
82
-
83
- /** Configuration accepted by the Mastra AppKit plugin. */
84
- export interface MastraPluginConfig extends BasePluginConfig {
85
- /** Mastra OpenAI-compatible provider id. Defaults to `"databricks"`. */
86
- providerId?: string;
87
- /**
88
- * PostgresStore for Mastra threads/messages. `true` reuses the
89
- * `lakebase` plugin's pool; an object opens a dedicated store.
90
- */
91
- storage?: boolean | PostgresStoreConfig;
92
- /**
93
- * PgVector store for Mastra memory recall. `true` reuses the
94
- * `lakebase` plugin's pool; an object opens a dedicated store.
95
- */
96
- memory?: boolean | MastraMemoryConfig;
97
- /**
98
- * Code-defined agents. Accepts three shapes for convenience:
99
- *
100
- * - **Record**: `{ analyst: def, helper: def }` - keys become the
101
- * registered ids and the first key is the default.
102
- * - **Single definition**: `def` - registered under
103
- * `slugify(def.name)` (or `"default"` when `name` is omitted) and
104
- * automatically marked as the default agent.
105
- * - **Array**: `[def1, def2]` - each registered under
106
- * `slugify(def.name)` (or `agent_${i}` when `name` is omitted);
107
- * the first entry is the default.
108
- *
109
- * Each entry becomes a Mastra `Agent` reachable at
110
- * `/api/<plugin>/route/chat/<id>` (the chat route also matches
111
- * `:agentId`). When `agents` is omitted entirely, the plugin
112
- * registers a single built-in `default` analyst so the bare
113
- * `mastra()` call still mounts a working chat endpoint.
114
- *
115
- * @example Single-agent shorthand
116
- * ```ts
117
- * mastra({
118
- * agents: createAgent({ instructions: "..." }),
119
- * });
120
- * ```
121
- *
122
- * @example Array
123
- * ```ts
124
- * mastra({
125
- * agents: [
126
- * createAgent({ name: "analyst", instructions: "..." }),
127
- * createAgent({ name: "helper", instructions: "..." }),
128
- * ],
129
- * });
130
- * ```
131
- *
132
- * @example Record (explicit ids)
133
- * ```ts
134
- * mastra({
135
- * agents: {
136
- * analyst: createAgent({ instructions: "..." }),
137
- * helper: createAgent({ instructions: "..." }),
138
- * },
139
- * defaultAgent: "analyst",
140
- * });
141
- * ```
142
- */
143
- agents?:
144
- | Record<string, MastraAgentDefinition>
145
- | MastraAgentDefinition
146
- | MastraAgentDefinition[];
147
- /**
148
- * Ambient tools spread into every registered agent's tools record;
149
- * per-agent tools win on key collision. Use for a small shared
150
- * library; for per-agent tools set `agents[id].tools` instead.
151
- */
152
- tools?: MastraTools;
153
- /**
154
- * Agent id used when the client doesn't specify one (the bare,
155
- * un-suffixed history / suggestions routes resolve to it).
156
- * Defaults to the first key in `agents` (or `"default"` when
157
- * `agents` is omitted). Must match an id in `agents` when both are
158
- * set; a mismatch throws at setup with the available candidates.
159
- */
160
- defaultAgent?: string;
161
- /**
162
- * Plugin-level default model applied to every agent that omits its
163
- * own `model`. Mirrors AppKit's `agents({ defaultModel })`.
164
- *
165
- * - `string`: shorthand for "use the OBO auto-resolver but swap the
166
- * `modelId`" (e.g. `"databricks-claude-sonnet-4-6"`).
167
- * - Any other Mastra `DynamicArgument<MastraModelConfig>`: passed
168
- * through verbatim. Use this when you need full control over auth
169
- * or `providerId`.
170
- *
171
- * Resolution order per agent: `def.model` → `defaultModel` →
172
- * built-in `/serving-endpoints` resolver.
173
- */
174
- defaultModel?: AgentConfig["model"] | string;
175
- /**
176
- * Allow loose model names (`"claude sonnet"`) to be fuzzy-matched
177
- * against the workspace's Model Serving endpoints. Defaults to
178
- * `true`; set `false` to require exact endpoint names everywhere.
179
- */
180
- modelFuzzyMatch?: boolean;
181
- /**
182
- * Fuse.js score threshold for the fuzzy matcher (0 = exact match,
183
- * 1 = anything matches). Defaults to `0.4`. Lower values reject
184
- * loose matches; raise it if you have a sprawling endpoint
185
- * catalogue with similar-looking names.
186
- */
187
- modelFuzzyThreshold?: number;
188
- /**
189
- * TTL for the in-memory serving-endpoints list cache, in
190
- * milliseconds. Defaults to 5 minutes. The cache is per workspace
191
- * host and shared across users; concurrent callers coalesce on a
192
- * single in-flight fetch.
193
- */
194
- modelCacheTtlMs?: number;
195
- /**
196
- * Allow clients to override the active model per request via the
197
- * `X-Mastra-Model` header, `?model=` query string, or `model` body
198
- * field. Defaults to `true`. Disable when running multi-tenant
199
- * where untrusted clients shouldn't pick the backing endpoint.
200
- */
201
- modelOverride?: boolean;
202
- /**
203
- * Priority-ordered list of endpoint names tried *first* when no
204
- * agent / plugin / env / request-override model id is set, ahead of
205
- * the dynamic score-classified catalogue. The resolver picks the
206
- * first id that is actually present in the workspace's
207
- * `/serving-endpoints` listing.
208
- *
209
- * When unset, resolution is driven by the live Foundation Model API
210
- * `quality` / `speed` / `cost` scores: endpoints are classified into
211
- * chat classes (`classifyEndpoints`) and walked best-first
212
- * (ChatThinking -> ChatBalanced -> ChatFast), with the small built-in
213
- * `FALLBACK_MODEL_IDS` list as the floor when the catalogue can't be
214
- * read. Set this to
215
- * pin a regulated workspace to an approved subset, or to put custom
216
- * endpoints in front of the auto-classified catalogue.
217
- */
218
- defaultModelFallbacks?: readonly string[];
219
- /**
220
- * When `true` (default), every agent gets a built-in input
221
- * processor that strips `chartId` fields from prior assistant
222
- * tool-invocation results before they reach the model. This
223
- * prevents the model from reusing turn-scoped chartIds it sees
224
- * in memory recall (which would leave `[chart:<id>]` markers
225
- * pointing at writer events that no longer exist).
226
- *
227
- * Set to `false` to opt out - useful if a non-default agent
228
- * needs full visibility into prior chartIds (e.g. an audit
229
- * agent reasoning about chart lineage).
230
- */
231
- stripStaleCharts?: boolean;
232
- /**
233
- * Style guardrails appended to every agent's `instructions` to curb
234
- * common LLM-isms (em dashes, emojis, sycophantic openers, throwaway
235
- * closers, excessive hedging).
236
- *
237
- * - `undefined` (default): use the built-in
238
- * `DEFAULT_STYLE_INSTRUCTIONS` from `agents.ts`.
239
- * - `string`: replace the default with the supplied block.
240
- * - `false`: disable entirely (agents see only their bespoke
241
- * `instructions`).
242
- *
243
- * Appended (not prepended) so the agent's role and rules come first
244
- * and the style block leans on the model's recency bias.
245
- */
246
- styleInstructions?: string | false;
247
- /**
248
- * Genie spaces this plugin's agents can delegate to. One Mastra
249
- * tool is registered per alias (`genie` for the well-known
250
- * `default` alias, `genie_<alias>` otherwise). Each tool spins
251
- * up a per-question Genie sub-agent that runs Databricks
252
- * "agent mode" against the space, broadcasts wire events to the
253
- * UI, fetches statement rows for non-empty results, and returns
254
- * a `(string | data | chart)[]` summary the host UI renders
255
- * inline.
256
- *
257
- * Entries accept either a full {@link GenieSpaceConfig} object
258
- * or a bare `space_id` string when no extras are needed:
259
- *
260
- * ```ts
261
- * mastra({
262
- * genieSpaces: {
263
- * default: "01ef0d3c0e1b1f4a8d2c3e4f5a6b7c8d",
264
- * forecasts: { spaceId: "01ef...", hint: "weekly demand forecasts" },
265
- * },
266
- * });
267
- * ```
268
- *
269
- * Reach the spaces from an agent's `tools(plugins)` callback via
270
- * `plugins.genie?.toolkit()`; the resulting tools accept
271
- * `{ content, conversationId? }` and return a hydrated summary.
272
- *
273
- * **Fallback discovery** (highest precedence first): if this
274
- * field is omitted, the Genie agent also picks up spaces from
275
- * (1) the AppKit `genie({ spaces: { ... } })` plugin instance
276
- * when registered, and (2) the `DATABRICKS_GENIE_SPACE_ID`
277
- * env var (registered under the `default` alias). This keeps
278
- * existing AppKit deployments working without restating the
279
- * spaces config in two places.
280
- */
281
- genieSpaces?: GenieSpacesConfig;
282
- /**
283
- * TTL for the in-memory Genie space metadata cache, in
284
- * milliseconds. Defaults to 5 minutes. The Genie agent calls
285
- * `client.genie.getSpace(...)` on every cold-start to get the
286
- * title / description / warehouse id; cached responses skip the
287
- * round-trip and concurrent callers coalesce on a single
288
- * in-flight fetch. Drop to a smaller value when analysts are
289
- * actively editing space metadata and you want changes visible
290
- * within seconds; raise it to amortise the round-trip when
291
- * space metadata is effectively frozen.
292
- *
293
- * Backed by AppKit's `CacheManager`, so the cache participates
294
- * in telemetry spans (`cache.getOrExecute`) and benefits from
295
- * Lakebase persistence when the `lakebase` plugin is wired up.
296
- */
297
- genieSpaceCacheTtlMs?: number;
298
- /**
299
- * Maximum LLM steps each agent gets per turn. One step = one
300
- * round-trip to the underlying model (a tool call consumes a
301
- * step, the final-text reply consumes one too). Applies to
302
- * every agent registered through {@link MastraPluginConfig.agents}
303
- * - per-agent overrides aren't surfaced yet because the same
304
- * ceiling has been sufficient across every workload we've run.
305
- *
306
- * Defaults to {@link DEFAULT_AGENT_MAX_STEPS} (25), sized to fit
307
- * a decomposed Genie turn (grounding + several `ask_genie` calls
308
- * + `prepare_chart` per dataset + the final-text reply) with
309
- * headroom for the model to chain a couple of follow-ups before
310
- * answering. Mastra's own `agent.generate` default of 5 would
311
- * cut multi-step orchestration off after 2-3 tool calls, so
312
- * explicitly raising the ceiling here is what lets the
313
- * agent-mode loop play out.
314
- *
315
- * Lower when an unusually slow or expensive model makes long
316
- * turns unaffordable; raise for exploratory workloads that need
317
- * to drill deep into a dataset within a single turn.
318
- */
319
- agentMaxSteps?: number;
320
- }