@dbx-tools/appkit-mastra 0.1.12 → 0.1.18
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 +47 -45
- package/dist/src/agents.d.ts +2 -2
- package/dist/src/agents.js +66 -14
- package/dist/src/chart.d.ts +39 -105
- package/dist/src/chart.js +199 -194
- package/dist/src/config.d.ts +104 -0
- package/dist/src/config.js +43 -0
- package/dist/src/genie.d.ts +170 -107
- package/dist/src/genie.js +1003 -577
- package/dist/src/history.d.ts +31 -3
- package/dist/src/history.js +137 -31
- package/dist/src/memory.d.ts +25 -4
- package/dist/src/memory.js +34 -2
- package/dist/src/model.js +2 -2
- package/dist/src/observability.d.ts +64 -0
- package/dist/src/observability.js +85 -0
- package/dist/src/plugin.js +39 -7
- package/dist/src/processors/strip-stale-charts.js +1 -1
- package/dist/src/server.d.ts +12 -0
- package/dist/src/server.js +38 -2
- package/dist/src/serving.js +1 -1
- package/dist/src/tools/email.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +21 -16
- package/src/agents.ts +73 -17
- package/src/chart.ts +221 -251
- package/src/config.ts +120 -0
- package/src/genie.ts +1199 -654
- package/src/history.ts +147 -33
- package/src/memory.ts +41 -5
- package/src/model.ts +3 -3
- package/src/observability.ts +116 -0
- package/src/plugin.ts +39 -7
- package/src/processors/strip-stale-charts.ts +1 -1
- package/src/server.ts +49 -2
- package/src/serving.ts +1 -1
- package/src/tools/email.ts +1 -1
package/package.json
CHANGED
|
@@ -9,30 +9,35 @@
|
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
11
|
"name": "@dbx-tools/appkit-mastra",
|
|
12
|
-
"version": "0.1.
|
|
13
|
-
"type": "module",
|
|
14
|
-
"module": "index.ts",
|
|
12
|
+
"version": "0.1.18",
|
|
15
13
|
"dependencies": {
|
|
16
|
-
"@
|
|
17
|
-
"@dbx-tools/appkit-shared": "0.1.
|
|
18
|
-
"@
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"@mastra/
|
|
22
|
-
"@mastra/
|
|
23
|
-
"@mastra/
|
|
14
|
+
"@databricks/sdk-experimental": "^0.17",
|
|
15
|
+
"@dbx-tools/appkit-mastra-shared": "0.1.18",
|
|
16
|
+
"@dbx-tools/genie": "0.1.18",
|
|
17
|
+
"@dbx-tools/genie-shared": "0.1.18",
|
|
18
|
+
"@dbx-tools/shared": "0.1.18",
|
|
19
|
+
"@mastra/ai-sdk": "^1",
|
|
20
|
+
"@mastra/core": "^1",
|
|
21
|
+
"@mastra/express": "^1",
|
|
22
|
+
"@mastra/fastembed": "^1",
|
|
23
|
+
"@mastra/memory": "^1",
|
|
24
|
+
"@mastra/observability": "^1",
|
|
25
|
+
"@mastra/otel-bridge": "^1",
|
|
26
|
+
"@mastra/pg": "^1",
|
|
24
27
|
"fuse.js": "^7.0.0",
|
|
25
28
|
"zod": "^4.3.6"
|
|
26
29
|
},
|
|
27
|
-
"peerDependencies": {
|
|
28
|
-
"@databricks/appkit": "^0.35",
|
|
29
|
-
"express": "^5"
|
|
30
|
-
},
|
|
31
30
|
"devDependencies": {
|
|
32
31
|
"@types/express": "^5",
|
|
33
32
|
"@types/pg": "^8",
|
|
34
33
|
"express": "^5"
|
|
35
34
|
},
|
|
35
|
+
"module": "index.ts",
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@databricks/appkit": "^0.35",
|
|
38
|
+
"express": "^5"
|
|
39
|
+
},
|
|
40
|
+
"type": "module",
|
|
36
41
|
"files": [
|
|
37
42
|
"dist",
|
|
38
43
|
"index*.ts",
|
|
@@ -46,6 +51,6 @@
|
|
|
46
51
|
"repository": {
|
|
47
52
|
"type": "git",
|
|
48
53
|
"url": "git+https://github.com/reggie-db/dbx-tools-appkit.git",
|
|
49
|
-
"directory": "packages/mastra"
|
|
54
|
+
"directory": "packages/appkit-mastra"
|
|
50
55
|
}
|
|
51
56
|
}
|
package/src/agents.ts
CHANGED
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
* `chatRoute` agent for demos.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import {
|
|
17
|
-
import { logUtils, pluginUtils, stringUtils } from "@dbx-tools/appkit-shared";
|
|
16
|
+
import { appkitUtils, logUtils, stringUtils } from "@dbx-tools/shared";
|
|
18
17
|
import { Agent } from "@mastra/core/agent";
|
|
19
18
|
import type { AgentConfig, ToolsInput } from "@mastra/core/agent";
|
|
20
19
|
import { createTool } from "@mastra/core/tools";
|
|
@@ -23,9 +22,9 @@ import type { PgVectorConfig, PostgresStoreConfig } from "@mastra/pg";
|
|
|
23
22
|
|
|
24
23
|
import { buildRenderDataTool } from "./chart.js";
|
|
25
24
|
import type { MastraPluginConfig } from "./config.js";
|
|
26
|
-
import {
|
|
25
|
+
import { buildGenieToolkitProvider, resolveGenieSpaces } from "./genie.js";
|
|
27
26
|
import type { MemoryBuilder } from "./memory.js";
|
|
28
|
-
import { buildModel } from "./model.js";
|
|
27
|
+
import { buildModel, FALLBACK_MODEL_IDS } from "./model.js";
|
|
29
28
|
import { stripStaleChartsProcessor } from "./processors/strip-stale-charts.js";
|
|
30
29
|
|
|
31
30
|
/**
|
|
@@ -399,7 +398,7 @@ function composeInstructions(agentInstructions: string, style: string | null): s
|
|
|
399
398
|
*/
|
|
400
399
|
export async function buildAgents(opts: {
|
|
401
400
|
config: MastraPluginConfig;
|
|
402
|
-
context:
|
|
401
|
+
context: appkitUtils.PluginContextLike | undefined;
|
|
403
402
|
memoryBuilder?: MemoryBuilder;
|
|
404
403
|
log: logUtils.Logger;
|
|
405
404
|
}): Promise<BuiltAgents> {
|
|
@@ -440,6 +439,18 @@ export async function buildAgents(opts: {
|
|
|
440
439
|
...(memory ? { memory } : {}),
|
|
441
440
|
...(inputProcessors.length > 0 ? { inputProcessors } : {}),
|
|
442
441
|
});
|
|
442
|
+
// Surface the effective default model per agent so operators can
|
|
443
|
+
// see at a glance which endpoint each agent points at without
|
|
444
|
+
// having to fire a request and inspect a trace. The value is the
|
|
445
|
+
// *static* default; per-request overrides (header / query /
|
|
446
|
+
// body) and the workspace-catalogue fuzzy match still apply at
|
|
447
|
+
// call time.
|
|
448
|
+
log.info("agent registered", {
|
|
449
|
+
id,
|
|
450
|
+
name: def.name ?? id,
|
|
451
|
+
defaultModel: describeAgentDefaultModel(config, def),
|
|
452
|
+
tools: Object.keys(tools),
|
|
453
|
+
});
|
|
443
454
|
}
|
|
444
455
|
|
|
445
456
|
if (!agents[defaultAgentId]) {
|
|
@@ -448,10 +459,41 @@ export async function buildAgents(opts: {
|
|
|
448
459
|
);
|
|
449
460
|
}
|
|
450
461
|
|
|
451
|
-
log.info("agents
|
|
462
|
+
log.info("agents ready", { ids, defaultAgentId });
|
|
452
463
|
return { agents, defaultAgentId };
|
|
453
464
|
}
|
|
454
465
|
|
|
466
|
+
/**
|
|
467
|
+
* Best-effort description of the *static* default model an agent will
|
|
468
|
+
* resolve to at call time. Walks the same precedence ladder as
|
|
469
|
+
* {@link resolveModel} / {@link buildModel}:
|
|
470
|
+
*
|
|
471
|
+
* 1. Per-agent `def.model` (string sugar -> the literal id;
|
|
472
|
+
* function / `DynamicArgument` -> `"<dynamic>"` because the
|
|
473
|
+
* resolver decides at call time).
|
|
474
|
+
* 2. Plugin-level `config.defaultModel` (same rules).
|
|
475
|
+
* 3. `DATABRICKS_SERVING_ENDPOINT_NAME` env var.
|
|
476
|
+
* 4. First entry of `config.defaultModelFallbacks ?? FALLBACK_MODEL_IDS`.
|
|
477
|
+
*
|
|
478
|
+
* Used for the startup `agent registered` log so operators can see
|
|
479
|
+
* which endpoint each agent points at by default. Per-request
|
|
480
|
+
* overrides (`X-Mastra-Model` etc.) and the workspace-catalogue
|
|
481
|
+
* fuzzy match are still applied at runtime.
|
|
482
|
+
*/
|
|
483
|
+
function describeAgentDefaultModel(
|
|
484
|
+
config: MastraPluginConfig,
|
|
485
|
+
def: MastraAgentDefinition,
|
|
486
|
+
): string {
|
|
487
|
+
const effective = def.model ?? config.defaultModel;
|
|
488
|
+
if (typeof effective === "string") return effective;
|
|
489
|
+
if (effective !== undefined) return "<dynamic>";
|
|
490
|
+
return (
|
|
491
|
+
process.env.DATABRICKS_SERVING_ENDPOINT_NAME ??
|
|
492
|
+
config.defaultModelFallbacks?.[0] ??
|
|
493
|
+
FALLBACK_MODEL_IDS[0]!
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
|
|
455
497
|
/**
|
|
456
498
|
* Normalize `config.agents` into a `Record<id, definition>`. Accepts
|
|
457
499
|
* any of the three shapes documented on
|
|
@@ -590,7 +632,7 @@ async function resolveTools(
|
|
|
590
632
|
*/
|
|
591
633
|
function buildPluginsMap(
|
|
592
634
|
config: MastraPluginConfig,
|
|
593
|
-
context:
|
|
635
|
+
context: appkitUtils.PluginContextLike | undefined,
|
|
594
636
|
): MastraPlugins {
|
|
595
637
|
const cache = new Map<string, MastraPluginToolkitProvider | null>();
|
|
596
638
|
return new Proxy({} as MastraPlugins, {
|
|
@@ -606,22 +648,36 @@ function buildPluginsMap(
|
|
|
606
648
|
|
|
607
649
|
/**
|
|
608
650
|
* Pick the right {@link MastraPluginToolkitProvider} for a sibling
|
|
609
|
-
* plugin lookup. Returns the
|
|
610
|
-
* caller asks for `genie
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
*
|
|
614
|
-
*
|
|
651
|
+
* plugin lookup. Returns the Genie agent-backed adapter when
|
|
652
|
+
* the caller asks for `genie` AND at least one space is reachable
|
|
653
|
+
* via {@link resolveGenieSpaces} (the explicit
|
|
654
|
+
* `config.genieSpaces`, the registered AppKit `genie()` plugin's
|
|
655
|
+
* `spaces` config, or the `DATABRICKS_GENIE_SPACE_ID` env var).
|
|
656
|
+
* Falls back to the generic AppKit `ToolProvider` adapter for
|
|
657
|
+
* every other plugin name. `config` is threaded through so the
|
|
658
|
+
* Genie agent inherits the same model resolver / fallback
|
|
659
|
+
* ladder the calling agents use.
|
|
660
|
+
*
|
|
661
|
+
* The legacy AppKit `genie` plugin's tools are no longer consulted
|
|
662
|
+
* at runtime - the Genie agent talks to Genie directly via
|
|
663
|
+
* `@dbx-tools/genie` (`genieEventChat`) and the workspace
|
|
664
|
+
* `statementExecution.getStatement` API. But the plugin's
|
|
665
|
+
* resource manifest and `spaces` config are still honored so
|
|
666
|
+
* existing `app.yaml` configs and `genie({ spaces })` wiring
|
|
667
|
+
* keep working without change.
|
|
615
668
|
*/
|
|
616
669
|
function resolveProvider(
|
|
617
670
|
config: MastraPluginConfig,
|
|
618
|
-
context:
|
|
671
|
+
context: appkitUtils.PluginContextLike | undefined,
|
|
619
672
|
propName: string,
|
|
620
673
|
): MastraPluginToolkitProvider | null {
|
|
621
674
|
if (propName === "genie") {
|
|
622
|
-
const
|
|
623
|
-
if (
|
|
624
|
-
return
|
|
675
|
+
const spaces = resolveGenieSpaces(config, context);
|
|
676
|
+
if (Object.keys(spaces).length === 0) return null;
|
|
677
|
+
return buildGenieToolkitProvider({
|
|
678
|
+
spaces,
|
|
679
|
+
config,
|
|
680
|
+
}) as MastraPluginToolkitProvider;
|
|
625
681
|
}
|
|
626
682
|
const plugin = context?.getPlugins().get(propName);
|
|
627
683
|
return adaptPluginToolkit(plugin);
|