@dbx-tools/appkit-mastra 0.1.58 → 0.1.67

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 (44) 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 -28
  5. package/src/agents.ts +7 -1
  6. package/src/config.ts +64 -0
  7. package/src/genie.ts +9 -21
  8. package/{index.ts → src/index.ts} +7 -9
  9. package/src/mcp.ts +89 -0
  10. package/src/model.ts +9 -3
  11. package/src/plugin.ts +51 -8
  12. package/src/serving.ts +5 -9
  13. package/src/statement.ts +8 -36
  14. package/dist/src/agents.d.ts +0 -316
  15. package/dist/src/agents.js +0 -470
  16. package/dist/src/chart.d.ts +0 -153
  17. package/dist/src/chart.js +0 -570
  18. package/dist/src/config.d.ts +0 -295
  19. package/dist/src/config.js +0 -55
  20. package/dist/src/genie.d.ts +0 -161
  21. package/dist/src/genie.js +0 -973
  22. package/dist/src/history.d.ts +0 -95
  23. package/dist/src/history.js +0 -278
  24. package/dist/src/memory.d.ts +0 -109
  25. package/dist/src/memory.js +0 -253
  26. package/dist/src/model.d.ts +0 -52
  27. package/dist/src/model.js +0 -198
  28. package/dist/src/observability.d.ts +0 -64
  29. package/dist/src/observability.js +0 -83
  30. package/dist/src/plugin.d.ts +0 -177
  31. package/dist/src/plugin.js +0 -554
  32. package/dist/src/processor.d.ts +0 -8
  33. package/dist/src/processor.js +0 -40
  34. package/dist/src/processors/strip-stale-charts.d.ts +0 -32
  35. package/dist/src/processors/strip-stale-charts.js +0 -98
  36. package/dist/src/server.d.ts +0 -51
  37. package/dist/src/server.js +0 -152
  38. package/dist/src/serving.d.ts +0 -65
  39. package/dist/src/serving.js +0 -79
  40. package/dist/src/statement.d.ts +0 -66
  41. package/dist/src/statement.js +0 -111
  42. package/dist/src/writer.d.ts +0 -23
  43. package/dist/src/writer.js +0 -37
  44. package/dist/tsconfig.build.tsbuildinfo +0 -1
@@ -1,316 +0,0 @@
1
- /**
2
- * Agent registration for the Mastra AppKit plugin.
3
- *
4
- * Mirrors the shape of the AppKit `agents` plugin (`config.agents` map
5
- * of {@link MastraAgentDefinition}, dual-form `tools` accepting a plain
6
- * record or a `(plugins) => tools` callback). Resolves each definition
7
- * into a Mastra `Agent` instance during plugin setup; user-supplied
8
- * tool callbacks are invoked exactly once with a typed
9
- * {@link MastraPlugins} map built from registered sibling plugins.
10
- *
11
- * When no agents are registered the plugin falls back to a single
12
- * built-in analyst so the bare `mastra()` call still mounts a working
13
- * streamable agent for demos.
14
- */
15
- import { appkitUtils, logUtils } from "@dbx-tools/shared";
16
- import type { AgentConfig, ToolsInput } from "@mastra/core/agent";
17
- import { Agent } from "@mastra/core/agent";
18
- import type { Tool } from "@mastra/core/tools";
19
- import type { PgVectorConfig, PostgresStoreConfig } from "@mastra/pg";
20
- import type { MastraPluginConfig } from "./config.js";
21
- import type { MemoryBuilder } from "./memory.js";
22
- /**
23
- * Tool record accepted by every Mastra `Agent.tools` field and by the
24
- * `tools(plugins)` callback on {@link MastraAgentDefinition}.
25
- *
26
- * Alias of Mastra's `ToolsInput`, so it already accepts:
27
- *
28
- * - Mastra tools built with {@link createTool} (or `new Tool(...)`)
29
- * - Mastra tools built with the AppKit-shaped {@link tool} wrapper
30
- * below
31
- * - Vercel AI SDK tools (`tool({ ... })` from `ai`)
32
- * - Provider-defined tools (e.g. `openai.tools.webSearch(...)`)
33
- *
34
- * Existing tool libraries drop in as-is - nothing in this package
35
- * forces a rebuild.
36
- */
37
- export type MastraTools = ToolsInput;
38
- /** Re-export of Mastra's native `createTool` for full-feature access. */
39
- export { createTool } from "@mastra/core/tools";
40
- /**
41
- * AppKit-shaped tool factory. Lets users mix-and-match tools across
42
- * AppKit's `agents` plugin and `mastra` with a single import:
43
- *
44
- * ```ts
45
- * import { tool } from "@dbx-tools/appkit-mastra";
46
- * import { z } from "zod";
47
- *
48
- * get_weather: tool({
49
- * description: "Weather",
50
- * schema: z.object({ city: z.string() }),
51
- * execute: async ({ city }) => `Sunny in ${city}`,
52
- * }),
53
- * ```
54
- *
55
- * Maps onto Mastra's `createTool`:
56
- *
57
- * - `description` -> `description` (required)
58
- * - `schema` -> `inputSchema` (optional)
59
- * - `execute(input)` -> `execute(input, ctx)` - Mastra already calls
60
- * the first arg with the parsed inputs, so the body shape is
61
- * identical. The Mastra `context` arg is forwarded as the second
62
- * parameter when the caller declares it.
63
- * - `id`: optional. Defaults to a stable identifier derived from
64
- * `description` (slugified, with a short hash suffix for
65
- * uniqueness). Pass an explicit `id` when you need a stable string
66
- * for tracing or MCP exposure.
67
- *
68
- * Reach for {@link createTool} when you need Mastra-only fields
69
- * (`outputSchema`, `suspendSchema`, `requireApproval`, `mcp`, etc.).
70
- */
71
- export declare function tool(opts: AppKitToolOptions): Tool;
72
- /**
73
- * Input shape for the AppKit-style {@link tool} factory. A trimmed
74
- * subset of Mastra's `createTool` options that mirrors the
75
- * `@databricks/appkit/beta` `tool({ description, schema, execute })`
76
- * signature.
77
- *
78
- * Generics are intentionally absent - inference flows through the
79
- * caller's `schema` (typically a Zod object), and the `execute` body
80
- * destructures naturally from that. Reach for {@link createTool} when
81
- * you need the fully-typed input/output schemas wired explicitly.
82
- */
83
- export interface AppKitToolOptions {
84
- /** Optional stable identifier; auto-derived from `description` when omitted. */
85
- id?: string;
86
- /** Human-readable description shown to the model. Required. */
87
- description: string;
88
- /**
89
- * Optional input schema (any Standard Schema instance, e.g. Zod).
90
- * Maps to Mastra's `inputSchema`; passed through to the model
91
- * verbatim.
92
- */
93
- schema?: unknown;
94
- /**
95
- * Execute body. First arg is the parsed input (typed off `schema`
96
- * when supplied), second arg is the full Mastra execution context
97
- * (request context, abort signal, mastra instance) if you need it.
98
- */
99
- execute: (input: any, context?: unknown) => unknown;
100
- }
101
- /**
102
- * Identity helper that brands a definition as a Mastra agent. Mirrors
103
- * AppKit's `createAgent(def)` so the registration shape matches:
104
- *
105
- * ```ts
106
- * const support = createAgent({
107
- * instructions: "...",
108
- * model: "databricks-claude-sonnet-4-6",
109
- * tools(plugins) { return { ... }; },
110
- * });
111
- * ```
112
- *
113
- * Returns the definition unchanged - the wrapper exists only to anchor
114
- * type inference and to match the AppKit API surface.
115
- */
116
- export declare function createAgent<T extends MastraAgentDefinition>(def: T): T;
117
- /**
118
- * Filter / rename options accepted by every plugin's `.toolkit()`
119
- * method. Mirrors AppKit's `ToolkitOptions` verbatim so options pass
120
- * through unchanged - the underlying AppKit plugin does the filtering
121
- * and we just adapt the resulting entries into Mastra tools.
122
- */
123
- export interface ToolkitOptions {
124
- /**
125
- * Key prefix prepended to every tool name. AppKit's default is
126
- * `${pluginName}.` when omitted; pass an explicit `""` to drop it.
127
- */
128
- prefix?: string;
129
- /** Allowlist of local tool names. */
130
- only?: string[];
131
- /** Denylist of local tool names. */
132
- except?: string[];
133
- /** Remap specific local names to different keys. */
134
- rename?: Record<string, string>;
135
- }
136
- /**
137
- * Toolkit provider shape every entry in the {@link MastraPlugins} map
138
- * exposes. Identical to AppKit's `PluginToolkitProvider` - any AppKit
139
- * plugin that implements the standard `ToolProvider` interface
140
- * (`getAgentTools` + `executeAgentTool` + `toolkit`) is reachable
141
- * through this surface automatically.
142
- */
143
- export interface MastraPluginToolkitProvider {
144
- /**
145
- * Returns a Mastra-shaped tools record adapted from the plugin's
146
- * agent tools. Each tool dispatches back through the plugin's
147
- * `executeAgentTool` so OBO auth and telemetry spans stay intact.
148
- */
149
- toolkit(opts?: ToolkitOptions): MastraTools;
150
- }
151
- /**
152
- * Plugin map handed to the function form of
153
- * {@link MastraAgentDefinition.tools}. Mirrors AppKit's `Plugins`
154
- * type exactly: a string-keyed record where every value exposes
155
- * `.toolkit(opts)`.
156
- *
157
- * Implemented as a runtime Proxy that auto-discovers any registered
158
- * AppKit plugin implementing the standard `ToolProvider` interface
159
- * (`analytics`, `files`, `lakebase`, `genie`, plus any third-party
160
- * plugin that does the same). Unknown names resolve to `undefined`
161
- * at runtime, so guard with `?.` and `?? {}` when spreading from a
162
- * plugin that may not be registered in every environment.
163
- *
164
- * @example
165
- * ```ts
166
- * createAgent({
167
- * instructions: "...",
168
- * tools(plugins) {
169
- * return {
170
- * ...plugins.analytics.toolkit(),
171
- * ...plugins.files.toolkit({ only: ["uploads.read"] }),
172
- * get_weather: tool({
173
- * description: "Weather",
174
- * schema: z.object({ city: z.string() }),
175
- * execute: async ({ city }) => `Sunny in ${city}`,
176
- * }),
177
- * };
178
- * },
179
- * });
180
- * ```
181
- */
182
- export type MastraPlugins = Record<string, MastraPluginToolkitProvider>;
183
- /** Function form of {@link MastraAgentDefinition.tools}. */
184
- export type MastraToolsFn = (plugins: MastraPlugins) => MastraTools | Promise<MastraTools>;
185
- /**
186
- * A code-defined Mastra agent. Mirrors the shape AppKit's `agents`
187
- * plugin uses for `AgentDefinition`. The registry key under
188
- * `config.agents` is the `agentId` the client streams against; `name`
189
- * is purely informational (defaults to the key).
190
- */
191
- export interface MastraAgentDefinition {
192
- /** Display name used as `Agent.name`. Defaults to the registry key. */
193
- name?: string;
194
- /** Optional long-form description; surfaced as `Agent.description`. */
195
- description?: string;
196
- /** System prompt body. */
197
- instructions: string;
198
- /**
199
- * Per-agent model override.
200
- *
201
- * - `undefined` (default): falls back to the workspace
202
- * `/serving-endpoints` resolver that {@link buildModel} configures
203
- * from the per-request `WorkspaceClient`.
204
- * - `string`: shorthand for "use the default resolver but swap the
205
- * `modelId`" (e.g. `"databricks-meta-llama-3-3-70b-instruct"`).
206
- * - Any other Mastra `DynamicArgument<MastraModelConfig>`: passed
207
- * straight through to `Agent.model`. Use this when you need full
208
- * control over auth or providerId.
209
- */
210
- model?: AgentConfig["model"] | string;
211
- /**
212
- * Per-agent tool record. Either a plain map or a callback that
213
- * receives the typed {@link MastraPlugins} sibling-plugin index and
214
- * returns a map. The callback runs exactly once at agent setup; the
215
- * result is cached for the agent's lifetime.
216
- */
217
- tools?: MastraTools | MastraToolsFn;
218
- /**
219
- * Per-agent semantic recall (PgVector) override. Cascades from
220
- * `config.memory`; the agent value wins when set.
221
- *
222
- * - `undefined` (default): inherit `config.memory`. When that's
223
- * enabled, the agent **shares the plugin-level singleton `PgVector`
224
- * instance** (cross-agent semantic recall across the same index).
225
- * - `false`: disable semantic recall for this agent only.
226
- * - `true`: enable using the shared singleton (same as default when
227
- * plugin memory is enabled; useful to opt in when plugin disabled).
228
- * - {@link MastraMemoryConfig} object: dedicated `PgVector` for this
229
- * agent (private recall index). Bypasses the shared singleton.
230
- */
231
- memory?: boolean | MastraMemoryConfigOverride;
232
- /**
233
- * Per-agent thread/message storage (`PostgresStore`) override.
234
- * Cascades from `config.storage`; the agent value wins when set.
235
- *
236
- * - `undefined` (default): inherit `config.storage`. When that's
237
- * enabled, the agent gets its **own per-agent `PostgresStore`**
238
- * keyed by `schemaName: "mastra_<agentId>"` so threads and
239
- * messages stay isolated between agents in the same database.
240
- * - `false`: disable storage for this agent only (purely in-memory).
241
- * - `true`: enable with the per-agent default schema.
242
- * - {@link MastraStorageConfigOverride} object: dedicated
243
- * `PostgresStore` config (custom schema, connection, etc.).
244
- */
245
- storage?: boolean | MastraStorageConfigOverride;
246
- }
247
- /**
248
- * Distributive `Omit` so unions in `PostgresStoreConfig` /
249
- * `PgVectorConfig` keep their discriminants after the override types
250
- * strip `id`. The built-in `Omit` collapses unions to one shape with
251
- * common fields only, which loses the connection-style discriminants.
252
- */
253
- type DistributiveOmit<T, K extends keyof never> = T extends unknown ? Omit<T, K> : never;
254
- /**
255
- * `PostgresStoreConfig` minus `id` - per-agent overrides accept any
256
- * Mastra-supported storage shape. `id` is filled in automatically
257
- * from the agent registry key so traces stay stable.
258
- */
259
- export type MastraStorageConfigOverride = DistributiveOmit<PostgresStoreConfig, "id"> & {
260
- id?: string;
261
- };
262
- /**
263
- * `PgVectorConfig` minus `id` - per-agent overrides accept any
264
- * Mastra-supported vector shape. `id` is filled in automatically
265
- * from the agent registry key.
266
- */
267
- export type MastraMemoryConfigOverride = DistributiveOmit<PgVectorConfig, "id"> & {
268
- id?: string;
269
- };
270
- /** Output of {@link buildAgents}: resolved agents plus the default id. */
271
- export interface BuiltAgents {
272
- agents: Record<string, Agent>;
273
- defaultAgentId: string;
274
- }
275
- /** Fallback agent id used when `config.agents` is omitted entirely. */
276
- export declare const FALLBACK_AGENT_ID = "default";
277
- /**
278
- * Default per-turn step ceiling applied to every registered agent
279
- * when {@link MastraPluginConfig.agentMaxSteps} is unset. Sized to
280
- * fit a decomposed Genie turn (grounding + several `ask_genie`
281
- * calls + `prepare_chart` per dataset + the final-text reply) with
282
- * headroom for the model to chain a couple of follow-ups before
283
- * answering - well above Mastra's own `agent.generate` default of
284
- * 5, which would cut multi-step orchestration off mid-loop.
285
- */
286
- export declare const DEFAULT_AGENT_MAX_STEPS = 25;
287
- /**
288
- * Style guardrails appended to every agent's `instructions` to curb
289
- * common LLM-isms (em dashes, emojis, sycophantic openers, excessive
290
- * hedging, throwaway closers). Appended rather than prepended so the
291
- * agent's role/context comes first; the model's recency bias then
292
- * helps the style rules dominate the response surface.
293
- *
294
- * Override globally via {@link MastraPluginConfig.styleInstructions}
295
- * (pass `false` to disable entirely, or a string to replace).
296
- */
297
- export declare const DEFAULT_STYLE_INSTRUCTIONS: string;
298
- /**
299
- * Resolve every entry in `config.agents` into a Mastra `Agent`
300
- * instance. When `config.agents` is omitted the plugin registers a
301
- * single built-in `default` analyst so the bare `mastra()` call still
302
- * yields a working agent.
303
- *
304
- * Per-agent tool callbacks are invoked once with a typed
305
- * {@link MastraPlugins} index built from registered sibling plugins
306
- * (currently `genie`; extend `MastraPlugins` to surface more).
307
- *
308
- * @throws when `config.defaultAgent` is set to an id that isn't in the
309
- * resolved registry; this is a wiring bug, not a runtime condition.
310
- */
311
- export declare function buildAgents(opts: {
312
- config: MastraPluginConfig;
313
- context: appkitUtils.PluginContextLike | undefined;
314
- memoryBuilder?: MemoryBuilder;
315
- log: logUtils.Logger;
316
- }): Promise<BuiltAgents>;