@dbx-tools/appkit-mastra 0.6.218 → 0.6.219
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 +63 -18
- package/index.ts +4 -7
- package/lib/index.d.ts +4 -7
- package/lib/index.js +4 -5
- package/lib/src/agents.d.ts +15 -6
- package/lib/src/agents.js +30 -12
- package/lib/src/chat.d.ts +7 -0
- package/lib/src/chat.js +19 -0
- package/lib/src/config.d.ts +2 -2
- package/lib/src/config.js +1 -1
- package/lib/src/genie.js +5 -4
- package/lib/src/memory.d.ts +2 -2
- package/lib/src/memory.js +2 -2
- package/lib/src/plugin.d.ts +1 -1
- package/lib/src/plugin.js +3 -31
- package/lib/src/processors.d.ts +4 -28
- package/lib/src/processors.js +4 -61
- package/lib/src/server.d.ts +10 -21
- package/lib/src/server.js +52 -28
- package/lib/src/trace-io.js +7 -3
- package/lib/src/writer.d.ts +7 -7
- package/lib/src/writer.js +12 -9
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -22
- package/src/agents.ts +92 -27
- package/src/chat.ts +20 -0
- package/src/config.ts +5 -2
- package/src/genie.ts +7 -11
- package/src/memory.ts +8 -8
- package/src/plugin.ts +2 -30
- package/src/processors.ts +4 -66
- package/src/server.ts +49 -27
- package/src/trace-io.ts +7 -2
- package/src/writer.ts +15 -11
- package/lib/src/history.d.ts +0 -93
- package/lib/src/history.js +0 -231
- package/lib/src/threads.d.ts +0 -104
- package/lib/src/threads.js +0 -264
- package/src/history.ts +0 -270
- package/src/threads.ts +0 -309
package/lib/src/writer.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared helper for publishing
|
|
3
|
-
* `ctx.writer
|
|
4
|
-
* be closed, don't take the whole tool down" pattern that the
|
|
5
|
-
* Genie agent and chart tool both need.
|
|
2
|
+
* Shared helper for publishing Genie progress through Mastra's native
|
|
3
|
+
* `ctx.writer.custom()` data-part surface.
|
|
6
4
|
*
|
|
7
5
|
* Failures are logged at `warn` (a persistently-closed writer is
|
|
8
6
|
* the most likely culprit when events go missing client-side) but
|
|
@@ -12,8 +10,10 @@
|
|
|
12
10
|
* @module
|
|
13
11
|
*/
|
|
14
12
|
import { error } from "@dbx-tools/shared-core";
|
|
13
|
+
import { GENIE_PROGRESS_PART_TYPE } from "@dbx-tools/shared-mastra";
|
|
15
14
|
/**
|
|
16
|
-
* Best-effort
|
|
15
|
+
* Best-effort native custom progress write. No-op when the writer or owning
|
|
16
|
+
* tool call id is unavailable;
|
|
17
17
|
* caught errors are logged via `log.warn("writer:error", ...)`
|
|
18
18
|
* along with any caller-supplied `context` fields (e.g. a
|
|
19
19
|
* `chartId` or `messageId`) so the warning is greppable per
|
|
@@ -21,13 +21,16 @@ import { error } from "@dbx-tools/shared-core";
|
|
|
21
21
|
*
|
|
22
22
|
* Returns when the write resolves or rejects; never throws.
|
|
23
23
|
*/
|
|
24
|
-
export async function
|
|
25
|
-
if (!writer) {
|
|
24
|
+
export async function safeWriteProgress(log, writer, toolCallId, event, context = {}) {
|
|
25
|
+
if (!writer || !toolCallId) {
|
|
26
26
|
log.debug("writer:no-writer", context);
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
try {
|
|
30
|
-
await writer.
|
|
30
|
+
await writer.custom({
|
|
31
|
+
type: GENIE_PROGRESS_PART_TYPE,
|
|
32
|
+
data: { toolCallId, event },
|
|
33
|
+
});
|
|
31
34
|
log.debug("writer:ok", context);
|
|
32
35
|
}
|
|
33
36
|
catch (err) {
|
|
@@ -37,4 +40,4 @@ export async function safeWrite(log, writer, chunk, context = {}) {
|
|
|
37
40
|
});
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
43
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid3JpdGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4v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|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/_agent-route-context.ts","../src/agents.ts","../src/chart.ts","../src/
|
|
1
|
+
{"root":["../src/_agent-route-context.ts","../src/agents.ts","../src/chart.ts","../src/chat.ts","../src/config.ts","../src/defaults.ts","../src/filesystems.ts","../src/genie.ts","../src/identity.ts","../src/mcp.ts","../src/memory.ts","../src/mlflow.ts","../src/model.ts","../src/monty-sandbox.ts","../src/observability.ts","../src/pagination.ts","../src/plugin.ts","../src/processors.ts","../src/remote-skills.ts","../src/rest.ts","../src/sandbox.ts","../src/server.ts","../src/serving-sanitize.ts","../src/serving.ts","../src/skill-paths.ts","../src/statement.ts","../src/storage-schema.ts","../src/style.ts","../src/summarize.ts","../src/trace-io.ts","../src/validation.ts","../src/workspaces.ts","../src/writer.ts","../index.ts"],"version":"5.9.3"}
|
package/package.json
CHANGED
|
@@ -31,27 +31,27 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@databricks/appkit": "^0.60.0",
|
|
34
|
-
"@dbx-tools/appkit": "0.6.
|
|
35
|
-
"@dbx-tools/core": "0.6.
|
|
36
|
-
"@dbx-tools/databricks": "0.6.
|
|
37
|
-
"@dbx-tools/fs": "0.6.
|
|
38
|
-
"@dbx-tools/genie": "0.6.
|
|
39
|
-
"@dbx-tools/model": "0.6.
|
|
40
|
-
"@dbx-tools/path": "0.6.
|
|
41
|
-
"@dbx-tools/shared-core": "0.6.
|
|
42
|
-
"@dbx-tools/shared-fs": "0.6.
|
|
43
|
-
"@dbx-tools/shared-genie": "0.6.
|
|
44
|
-
"@dbx-tools/shared-mastra": "0.6.
|
|
45
|
-
"@dbx-tools/shared-model": "0.6.
|
|
46
|
-
"@mastra/ai-sdk": "1.10.
|
|
47
|
-
"@mastra/core": "1.
|
|
48
|
-
"@mastra/express": "1.5.
|
|
49
|
-
"@mastra/fastembed": "1.3.
|
|
50
|
-
"@mastra/mcp": "1.
|
|
51
|
-
"@mastra/memory": "1.
|
|
52
|
-
"@mastra/observability": "1.
|
|
53
|
-
"@mastra/otel-bridge": "1.5.
|
|
54
|
-
"@mastra/pg": "1.
|
|
34
|
+
"@dbx-tools/appkit": "0.6.219",
|
|
35
|
+
"@dbx-tools/core": "0.6.219",
|
|
36
|
+
"@dbx-tools/databricks": "0.6.219",
|
|
37
|
+
"@dbx-tools/fs": "0.6.219",
|
|
38
|
+
"@dbx-tools/genie": "0.6.219",
|
|
39
|
+
"@dbx-tools/model": "0.6.219",
|
|
40
|
+
"@dbx-tools/path": "0.6.219",
|
|
41
|
+
"@dbx-tools/shared-core": "0.6.219",
|
|
42
|
+
"@dbx-tools/shared-fs": "0.6.219",
|
|
43
|
+
"@dbx-tools/shared-genie": "0.6.219",
|
|
44
|
+
"@dbx-tools/shared-mastra": "0.6.219",
|
|
45
|
+
"@dbx-tools/shared-model": "0.6.219",
|
|
46
|
+
"@mastra/ai-sdk": "1.10.5",
|
|
47
|
+
"@mastra/core": "1.71.0",
|
|
48
|
+
"@mastra/express": "1.5.14",
|
|
49
|
+
"@mastra/fastembed": "1.3.2",
|
|
50
|
+
"@mastra/mcp": "2.1.0",
|
|
51
|
+
"@mastra/memory": "1.32.1",
|
|
52
|
+
"@mastra/observability": "1.18.0",
|
|
53
|
+
"@mastra/otel-bridge": "1.5.10",
|
|
54
|
+
"@mastra/pg": "1.27.1",
|
|
55
55
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
56
56
|
"@opentelemetry/api": "^1.9.1",
|
|
57
57
|
"@pydantic/monty": "0.0.23",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"./package.json": "./package.json"
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
|
-
"version": "0.6.
|
|
76
|
+
"version": "0.6.219",
|
|
77
77
|
"types": "./lib/index.d.ts",
|
|
78
78
|
"type": "module",
|
|
79
79
|
"exports": {
|
package/src/agents.ts
CHANGED
|
@@ -19,7 +19,12 @@ import { ConfigurationError } from "@databricks/appkit";
|
|
|
19
19
|
import { plugin } from "@dbx-tools/appkit";
|
|
20
20
|
import { fallback } from "@dbx-tools/model";
|
|
21
21
|
import { log, object, string } from "@dbx-tools/shared-core";
|
|
22
|
-
import type {
|
|
22
|
+
import type {
|
|
23
|
+
AgentConfig,
|
|
24
|
+
AgentExecutionOptions,
|
|
25
|
+
AgentInstructions,
|
|
26
|
+
ToolsInput,
|
|
27
|
+
} from "@mastra/core/agent";
|
|
23
28
|
import { Agent } from "@mastra/core/agent";
|
|
24
29
|
import { MASTRA_RESOURCE_ID_KEY } from "@mastra/core/request-context";
|
|
25
30
|
import type { Tool } from "@mastra/core/tools";
|
|
@@ -32,7 +37,7 @@ import type { MastraPluginConfig } from "./config.ts";
|
|
|
32
37
|
import { buildGenieToolkitProvider, resolveGenieSpaces } from "./genie.ts";
|
|
33
38
|
import type { MemoryBuilder } from "./memory.ts";
|
|
34
39
|
import { buildModel } from "./model.ts";
|
|
35
|
-
import {
|
|
40
|
+
import { stripStaleChartsProcessor } from "./processors.ts";
|
|
36
41
|
import { TYPOGRAPHY_RULE } from "./style.ts";
|
|
37
42
|
import { buildSummarizeTool } from "./summarize.ts";
|
|
38
43
|
import { createWorkspace } from "./workspaces.ts";
|
|
@@ -155,7 +160,11 @@ function deriveToolId(description: string): string {
|
|
|
155
160
|
* workspace carries Databricks skill mounts and Databricks Sandbox command
|
|
156
161
|
* execution. An explicit workspace remains the caller's complete override.
|
|
157
162
|
*/
|
|
158
|
-
export function createAgent<
|
|
163
|
+
export function createAgent<
|
|
164
|
+
TRequestContext extends Record<string, unknown> | unknown = unknown,
|
|
165
|
+
TDefinition extends MastraAgentDefinition<TRequestContext> =
|
|
166
|
+
MastraAgentDefinition<TRequestContext>,
|
|
167
|
+
>(def: TDefinition): TDefinition {
|
|
159
168
|
if (def.workspace) return { ...def };
|
|
160
169
|
const workspace = createWorkspace();
|
|
161
170
|
markDefaultWorkspace(workspace);
|
|
@@ -260,13 +269,27 @@ export type MastraAgentWorkspaceResolver = () => Workspace | undefined;
|
|
|
260
269
|
* `config.agents` is the `agentId` the client streams against; `name`
|
|
261
270
|
* is purely informational (defaults to the key).
|
|
262
271
|
*/
|
|
263
|
-
export interface MastraAgentDefinition
|
|
272
|
+
export interface MastraAgentDefinition<
|
|
273
|
+
TRequestContext extends Record<string, unknown> | unknown = unknown,
|
|
274
|
+
> {
|
|
264
275
|
/** Display name used as `Agent.name`. Defaults to the registry key. */
|
|
265
276
|
name?: string;
|
|
266
277
|
/** Optional long-form description; surfaced as `Agent.description`. */
|
|
267
278
|
description?: string;
|
|
268
|
-
/**
|
|
269
|
-
instructions: string;
|
|
279
|
+
/** Static or request-context-aware system instructions. */
|
|
280
|
+
instructions: AgentConfig<string, ToolsInput, undefined, TRequestContext>["instructions"];
|
|
281
|
+
/** Native Mastra schema that validates and types application request context. */
|
|
282
|
+
requestContextSchema?: AgentConfig<
|
|
283
|
+
string,
|
|
284
|
+
ToolsInput,
|
|
285
|
+
undefined,
|
|
286
|
+
TRequestContext
|
|
287
|
+
>["requestContextSchema"];
|
|
288
|
+
/**
|
|
289
|
+
* Mastra-native per-call approval gate for this agent's tools. Supports an
|
|
290
|
+
* async Classifier-backed function; tool-level approval remains authoritative.
|
|
291
|
+
*/
|
|
292
|
+
requireToolApproval?: AgentExecutionOptions["requireToolApproval"];
|
|
270
293
|
/**
|
|
271
294
|
* Per-agent model override.
|
|
272
295
|
*
|
|
@@ -279,7 +302,7 @@ export interface MastraAgentDefinition {
|
|
|
279
302
|
* straight through to `Agent.model`. Use this when you need full
|
|
280
303
|
* control over auth or providerId.
|
|
281
304
|
*/
|
|
282
|
-
model?: AgentConfig["model"] | string;
|
|
305
|
+
model?: AgentConfig<string, ToolsInput, undefined, TRequestContext>["model"] | string;
|
|
283
306
|
/**
|
|
284
307
|
* Per-agent tool record. Either a plain map or a callback that
|
|
285
308
|
* receives the typed {@link MastraPlugins} sibling-plugin index and
|
|
@@ -323,6 +346,9 @@ export interface MastraAgentDefinition {
|
|
|
323
346
|
workspace?: Workspace | MastraAgentWorkspaceResolver;
|
|
324
347
|
}
|
|
325
348
|
|
|
349
|
+
/** Type-erased registry member; each definition retains typing at `createAgent`. */
|
|
350
|
+
export type AnyMastraAgentDefinition = MastraAgentDefinition<any>;
|
|
351
|
+
|
|
326
352
|
/**
|
|
327
353
|
* Distributive `Omit` so unions in `PostgresStoreConfig` /
|
|
328
354
|
* `PgVectorConfig` keep their discriminants after the override types
|
|
@@ -433,13 +459,47 @@ function resolveStyleInstructions(config: MastraPluginConfig): string | null {
|
|
|
433
459
|
return DEFAULT_STYLE_INSTRUCTIONS;
|
|
434
460
|
}
|
|
435
461
|
|
|
462
|
+
/** Append the style block without narrowing Mastra's native instruction shapes. */
|
|
463
|
+
function appendStyleInstructions(
|
|
464
|
+
instructions: AgentInstructions,
|
|
465
|
+
style: string | null,
|
|
466
|
+
): AgentInstructions {
|
|
467
|
+
if (!style) return instructions;
|
|
468
|
+
if (typeof instructions === "string") {
|
|
469
|
+
return `${instructions.trimEnd()}\n\n${style}`;
|
|
470
|
+
}
|
|
471
|
+
if (Array.isArray(instructions)) {
|
|
472
|
+
if (instructions.every((instruction) => typeof instruction === "string")) {
|
|
473
|
+
return [...instructions, style] as AgentInstructions;
|
|
474
|
+
}
|
|
475
|
+
return [...instructions, { role: "system", content: style }] as AgentInstructions;
|
|
476
|
+
}
|
|
477
|
+
return [instructions, { role: "system", content: style }] as AgentInstructions;
|
|
478
|
+
}
|
|
479
|
+
|
|
436
480
|
/**
|
|
437
|
-
*
|
|
438
|
-
*
|
|
481
|
+
* Compose static or request-context-aware instructions with the shared style
|
|
482
|
+
* policy while preserving Mastra's native generic inference.
|
|
439
483
|
*/
|
|
440
|
-
function composeInstructions
|
|
441
|
-
|
|
442
|
-
|
|
484
|
+
function composeInstructions<TRequestContext extends Record<string, unknown> | unknown>(
|
|
485
|
+
agentInstructions: AgentConfig<string, ToolsInput, undefined, TRequestContext>["instructions"],
|
|
486
|
+
style: string | null,
|
|
487
|
+
): AgentConfig<string, ToolsInput, undefined, TRequestContext>["instructions"] {
|
|
488
|
+
if (typeof agentInstructions !== "function") {
|
|
489
|
+
return appendStyleInstructions(agentInstructions, style) as AgentConfig<
|
|
490
|
+
string,
|
|
491
|
+
ToolsInput,
|
|
492
|
+
undefined,
|
|
493
|
+
TRequestContext
|
|
494
|
+
>["instructions"];
|
|
495
|
+
}
|
|
496
|
+
return (async (args) =>
|
|
497
|
+
appendStyleInstructions(await agentInstructions(args), style)) as AgentConfig<
|
|
498
|
+
string,
|
|
499
|
+
ToolsInput,
|
|
500
|
+
undefined,
|
|
501
|
+
TRequestContext
|
|
502
|
+
>["instructions"];
|
|
443
503
|
}
|
|
444
504
|
|
|
445
505
|
/**
|
|
@@ -502,7 +562,6 @@ export async function buildAgents(opts: {
|
|
|
502
562
|
// chartIds from prior assistant tool results into the new
|
|
503
563
|
// turn's `[chart:<id>]` markers. Opt out per-plugin via
|
|
504
564
|
// `config.stripStaleCharts: false`.
|
|
505
|
-
const outputProcessors = [new ResultProcessor()];
|
|
506
565
|
const inputProcessors = [
|
|
507
566
|
...(config.stripStaleCharts === false ? [] : [stripStaleChartsProcessor]),
|
|
508
567
|
];
|
|
@@ -536,15 +595,18 @@ export async function buildAgents(opts: {
|
|
|
536
595
|
// omits it.
|
|
537
596
|
description: def.description?.trim() || defaultAgentDescription(def.name ?? id),
|
|
538
597
|
instructions: composeInstructions(def.instructions, style),
|
|
598
|
+
...(def.requestContextSchema ? { requestContextSchema: def.requestContextSchema } : {}),
|
|
539
599
|
model: resolveModel(config, def.model),
|
|
540
600
|
defaultOptions: {
|
|
541
601
|
maxSteps: config.agentMaxSteps ?? DEFAULT_AGENT_MAX_STEPS,
|
|
602
|
+
...(def.requireToolApproval !== undefined
|
|
603
|
+
? { requireToolApproval: def.requireToolApproval }
|
|
604
|
+
: {}),
|
|
542
605
|
},
|
|
543
606
|
tools,
|
|
544
607
|
...(memory ? { memory } : {}),
|
|
545
608
|
...(workspace ? { workspace } : {}),
|
|
546
609
|
inputProcessors,
|
|
547
|
-
outputProcessors,
|
|
548
610
|
});
|
|
549
611
|
// Surface the effective default model per agent so operators can
|
|
550
612
|
// see at a glance which endpoint each agent points at without
|
|
@@ -642,7 +704,10 @@ function assertApprovalGatedToolsHaveStorage(
|
|
|
642
704
|
* overrides (`X-Mastra-Model` etc.) and the workspace-catalogue
|
|
643
705
|
* fuzzy match are still applied at runtime.
|
|
644
706
|
*/
|
|
645
|
-
function describeAgentDefaultModel(
|
|
707
|
+
function describeAgentDefaultModel(
|
|
708
|
+
config: MastraPluginConfig,
|
|
709
|
+
def: AnyMastraAgentDefinition,
|
|
710
|
+
): string {
|
|
646
711
|
const effective = def.model ?? config.defaultModel;
|
|
647
712
|
if (typeof effective === "string") return effective;
|
|
648
713
|
if (effective !== undefined) return "<dynamic>";
|
|
@@ -667,13 +732,13 @@ function describeAgentDefaultModel(config: MastraPluginConfig, def: MastraAgentD
|
|
|
667
732
|
* Omitted or empty inputs fall back to a single built-in analyst so
|
|
668
733
|
* the bare `mastra()` call still mounts a working chat route.
|
|
669
734
|
*/
|
|
670
|
-
function resolveDefinitions(config: MastraPluginConfig): Record<string,
|
|
735
|
+
function resolveDefinitions(config: MastraPluginConfig): Record<string, AnyMastraAgentDefinition> {
|
|
671
736
|
const input = config.agents;
|
|
672
737
|
if (!input) return fallbackDefinitions();
|
|
673
738
|
|
|
674
739
|
if (Array.isArray(input)) {
|
|
675
740
|
if (input.length === 0) return fallbackDefinitions();
|
|
676
|
-
const out: Record<string,
|
|
741
|
+
const out: Record<string, AnyMastraAgentDefinition> = {};
|
|
677
742
|
input.forEach((def, i) => {
|
|
678
743
|
const key = deriveAgentKey(def, i);
|
|
679
744
|
if (out[key]) {
|
|
@@ -687,21 +752,21 @@ function resolveDefinitions(config: MastraPluginConfig): Record<string, MastraAg
|
|
|
687
752
|
return out;
|
|
688
753
|
}
|
|
689
754
|
|
|
690
|
-
// Single-definition shorthand: an agent
|
|
691
|
-
// a record-of-agents never
|
|
692
|
-
if (
|
|
693
|
-
const def = input as
|
|
755
|
+
// Single-definition shorthand: an agent owns the required `instructions`
|
|
756
|
+
// field (static or dynamic); a record-of-agents never owns it directly.
|
|
757
|
+
if ("instructions" in input) {
|
|
758
|
+
const def = input as AnyMastraAgentDefinition;
|
|
694
759
|
const key = deriveAgentKey(def);
|
|
695
760
|
return { [key]: def };
|
|
696
761
|
}
|
|
697
762
|
|
|
698
|
-
const record = input as Record<string,
|
|
763
|
+
const record = input as Record<string, AnyMastraAgentDefinition>;
|
|
699
764
|
if (Object.keys(record).length === 0) return fallbackDefinitions();
|
|
700
765
|
return record;
|
|
701
766
|
}
|
|
702
767
|
|
|
703
768
|
/** Derive a registry id from a definition's `name`, with a fallback. */
|
|
704
|
-
function deriveAgentKey(def:
|
|
769
|
+
function deriveAgentKey(def: AnyMastraAgentDefinition, index?: number): string {
|
|
705
770
|
if (def.name) {
|
|
706
771
|
const slug = string.toIdentifier(def.name);
|
|
707
772
|
if (slug) return slug;
|
|
@@ -710,7 +775,7 @@ function deriveAgentKey(def: MastraAgentDefinition, index?: number): string {
|
|
|
710
775
|
}
|
|
711
776
|
|
|
712
777
|
/** Built-in fallback registry used when `agents` is omitted / empty. */
|
|
713
|
-
function fallbackDefinitions(): Record<string,
|
|
778
|
+
function fallbackDefinitions(): Record<string, AnyMastraAgentDefinition> {
|
|
714
779
|
return {
|
|
715
780
|
[FALLBACK_AGENT_ID]: {
|
|
716
781
|
name: "Default Agent",
|
|
@@ -738,7 +803,7 @@ function fallbackDefinitions(): Record<string, MastraAgentDefinition> {
|
|
|
738
803
|
*/
|
|
739
804
|
function resolveModel(
|
|
740
805
|
config: MastraPluginConfig,
|
|
741
|
-
override:
|
|
806
|
+
override: AnyMastraAgentDefinition["model"],
|
|
742
807
|
): AgentConfig["model"] {
|
|
743
808
|
const effective = override ?? config.defaultModel;
|
|
744
809
|
if (effective === undefined) {
|
|
@@ -758,7 +823,7 @@ function resolveModel(
|
|
|
758
823
|
* survives - the caller already knows which agent was registering.
|
|
759
824
|
*/
|
|
760
825
|
async function resolveTools(
|
|
761
|
-
defTools:
|
|
826
|
+
defTools: AnyMastraAgentDefinition["tools"],
|
|
762
827
|
plugins: MastraPlugins,
|
|
763
828
|
ambientTools: MastraTools,
|
|
764
829
|
): Promise<MastraTools> {
|
|
@@ -768,7 +833,7 @@ async function resolveTools(
|
|
|
768
833
|
}
|
|
769
834
|
|
|
770
835
|
function resolveAgentWorkspace(
|
|
771
|
-
workspace:
|
|
836
|
+
workspace: AnyMastraAgentDefinition["workspace"],
|
|
772
837
|
): Workspace | undefined {
|
|
773
838
|
if (!workspace) return undefined;
|
|
774
839
|
return typeof workspace === "function" ? workspace() : workspace;
|
package/src/chat.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official Mastra AI SDK chat routes for browser-compatible UI streams.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { routes } from "@dbx-tools/shared-mastra";
|
|
8
|
+
import { chatRoute } from "@mastra/ai-sdk";
|
|
9
|
+
|
|
10
|
+
/** Register the official AI SDK chat stream plus its approval continuation. */
|
|
11
|
+
export function agentChatRoutes() {
|
|
12
|
+
const path = `${routes.MASTRA_ROUTES.chat}/:agentId` as `${string}:agentId`;
|
|
13
|
+
return [
|
|
14
|
+
chatRoute({
|
|
15
|
+
path,
|
|
16
|
+
sendReasoning: true,
|
|
17
|
+
sendSources: true,
|
|
18
|
+
}),
|
|
19
|
+
];
|
|
20
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -22,7 +22,7 @@ import type { RequestContext } from "@mastra/core/request-context";
|
|
|
22
22
|
import { MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY } from "@mastra/core/request-context";
|
|
23
23
|
import type { PgVectorConfig, PostgresStoreConfig } from "@mastra/pg";
|
|
24
24
|
|
|
25
|
-
import type {
|
|
25
|
+
import type { AnyMastraAgentDefinition, MastraTools } from "./agents.ts";
|
|
26
26
|
import type { GenieSpacesConfig } from "./genie.ts";
|
|
27
27
|
import { IDENTITY_MODES, type MastraIdentityMode } from "./identity.ts";
|
|
28
28
|
import type { RemoteSkillsOption } from "./remote-skills.ts";
|
|
@@ -252,7 +252,10 @@ export interface MastraPluginConfig extends BasePluginConfig {
|
|
|
252
252
|
* });
|
|
253
253
|
* ```
|
|
254
254
|
*/
|
|
255
|
-
agents?:
|
|
255
|
+
agents?:
|
|
256
|
+
| Record<string, AnyMastraAgentDefinition>
|
|
257
|
+
| AnyMastraAgentDefinition
|
|
258
|
+
| AnyMastraAgentDefinition[];
|
|
256
259
|
/**
|
|
257
260
|
* Ambient tools spread into every registered agent's tools record;
|
|
258
261
|
* per-agent tools win on key collision. Use for a small shared
|
package/src/genie.ts
CHANGED
|
@@ -48,10 +48,10 @@ import { plugin } from "@dbx-tools/appkit";
|
|
|
48
48
|
import { chat, space as genieSpace } from "@dbx-tools/genie";
|
|
49
49
|
import { error, log, string } from "@dbx-tools/shared-core";
|
|
50
50
|
import { genieModel, type GenieMessage } from "@dbx-tools/shared-genie";
|
|
51
|
-
import type {
|
|
51
|
+
import type { StartedEvent } from "@dbx-tools/shared-mastra";
|
|
52
52
|
import type { RequestContext } from "@mastra/core/request-context";
|
|
53
53
|
import { MASTRA_THREAD_ID_KEY } from "@mastra/core/request-context";
|
|
54
|
-
import { createTool } from "@mastra/core/tools";
|
|
54
|
+
import { createTool, type ToolExecutionContext } from "@mastra/core/tools";
|
|
55
55
|
import { z } from "zod";
|
|
56
56
|
|
|
57
57
|
import type { MastraTools } from "./agents.ts";
|
|
@@ -59,7 +59,7 @@ import { chartPlannerRequestSchema, chartToolOutputSchema, prepareChart } from "
|
|
|
59
59
|
import { MASTRA_USER_KEY, resolveUserKey } from "./config.ts";
|
|
60
60
|
import type { MastraPluginConfig, User } from "./config.ts";
|
|
61
61
|
import { fetchStatementData } from "./statement.ts";
|
|
62
|
-
import {
|
|
62
|
+
import { safeWriteProgress } from "./writer.ts";
|
|
63
63
|
|
|
64
64
|
const logger = log.logger("mastra/genie");
|
|
65
65
|
|
|
@@ -96,12 +96,7 @@ export type GenieSpacesConfig = Record<string, GenieSpaceConfig | string>;
|
|
|
96
96
|
* `abortSignal` (for per-call cancellation).
|
|
97
97
|
*/
|
|
98
98
|
type ToolExecuteCtx =
|
|
99
|
-
|
|
|
100
|
-
requestContext?: RequestContext;
|
|
101
|
-
writer?: MastraWriter;
|
|
102
|
-
abortSignal?: AbortSignal;
|
|
103
|
-
}
|
|
104
|
-
| undefined;
|
|
99
|
+
Pick<ToolExecutionContext, "requestContext" | "writer" | "abortSignal" | "agent"> | undefined;
|
|
105
100
|
|
|
106
101
|
/**
|
|
107
102
|
* Pull the per-request {@link WorkspaceClient} off the active
|
|
@@ -435,6 +430,7 @@ function buildAskGenieTool(opts: {
|
|
|
435
430
|
const ctx = ctxRaw as ToolExecuteCtx;
|
|
436
431
|
const { client, requestContext } = requireClient(ctx, toolId);
|
|
437
432
|
const writer = ctx?.writer;
|
|
433
|
+
const toolCallId = ctx?.agent?.toolCallId;
|
|
438
434
|
const signal = ctx?.abortSignal;
|
|
439
435
|
const threadId = requestContext.get(MASTRA_THREAD_ID_KEY) as string | undefined;
|
|
440
436
|
|
|
@@ -475,7 +471,7 @@ function buildAskGenieTool(opts: {
|
|
|
475
471
|
spaceId,
|
|
476
472
|
content: question,
|
|
477
473
|
};
|
|
478
|
-
await
|
|
474
|
+
await safeWriteProgress(logger, writer, toolCallId, startedEvent);
|
|
479
475
|
|
|
480
476
|
const runTurn = async (): Promise<GenieMessage> => {
|
|
481
477
|
const seedConversationId = conversationId;
|
|
@@ -487,7 +483,7 @@ function buildAskGenieTool(opts: {
|
|
|
487
483
|
...(signal ? { context: signal } : {}),
|
|
488
484
|
})) {
|
|
489
485
|
if (event.type !== "message") {
|
|
490
|
-
await
|
|
486
|
+
await safeWriteProgress(logger, writer, toolCallId, event);
|
|
491
487
|
}
|
|
492
488
|
const eventConversationId = event.conversation_id;
|
|
493
489
|
if (eventConversationId) {
|
package/src/memory.ts
CHANGED
|
@@ -39,7 +39,7 @@ import { Memory } from "@mastra/memory";
|
|
|
39
39
|
import { PgVector, PostgresStore } from "@mastra/pg";
|
|
40
40
|
import { Pool, type PoolConfig } from "pg";
|
|
41
41
|
|
|
42
|
-
import type {
|
|
42
|
+
import type { AnyMastraAgentDefinition, MastraMemoryConfigOverride } from "./agents.ts";
|
|
43
43
|
import type { MastraPluginConfig } from "./config.ts";
|
|
44
44
|
import { agentStorageSchemaName } from "./storage-schema.ts";
|
|
45
45
|
import { summaryModel, TITLE_INSTRUCTIONS } from "./summarize.ts";
|
|
@@ -143,8 +143,8 @@ export async function createServicePrincipalPool(pgConfig: PoolConfig): Promise<
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
/** Effective per-knob setting after the plugin/agent cascade. */
|
|
146
|
-
type StorageSetting =
|
|
147
|
-
type MemorySetting =
|
|
146
|
+
type StorageSetting = AnyMastraAgentDefinition["storage"];
|
|
147
|
+
type MemorySetting = AnyMastraAgentDefinition["memory"];
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
150
|
* True when any plugin-level or per-agent setting could need the
|
|
@@ -223,7 +223,7 @@ export class MemoryBuilder {
|
|
|
223
223
|
* vector store enabled - Mastra accepts a missing `memory` field
|
|
224
224
|
* and treats the agent as stateless.
|
|
225
225
|
*/
|
|
226
|
-
forAgent(agentId: string, def:
|
|
226
|
+
forAgent(agentId: string, def: AnyMastraAgentDefinition): Memory | undefined {
|
|
227
227
|
const storageSetting = def.storage ?? this.config.storage;
|
|
228
228
|
const memorySetting = def.memory ?? this.config.memory;
|
|
229
229
|
|
|
@@ -368,14 +368,14 @@ function settingNeedsSharedPool(setting: StorageSetting | MemorySetting | undefi
|
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
/** Walk the three shapes of `config.agents` into a flat list. */
|
|
371
|
-
function collectAgentDefinitions(config: MastraPluginConfig):
|
|
371
|
+
function collectAgentDefinitions(config: MastraPluginConfig): AnyMastraAgentDefinition[] {
|
|
372
372
|
const agents = config.agents;
|
|
373
373
|
if (!agents) return [];
|
|
374
374
|
if (Array.isArray(agents)) return agents;
|
|
375
|
-
if (
|
|
376
|
-
return [agents as
|
|
375
|
+
if ("instructions" in agents) {
|
|
376
|
+
return [agents as AnyMastraAgentDefinition];
|
|
377
377
|
}
|
|
378
|
-
return Object.values(agents
|
|
378
|
+
return Object.values(agents);
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
/** Fill in a default `id` when the caller didn't supply one. */
|
package/src/plugin.ts
CHANGED
|
@@ -76,6 +76,7 @@ import type { Pool } from "pg";
|
|
|
76
76
|
|
|
77
77
|
import { buildAgents, FALLBACK_AGENT_ID, type BuiltAgents } from "./agents.ts";
|
|
78
78
|
import { fetchChart } from "./chart.ts";
|
|
79
|
+
import { agentChatRoutes } from "./chat.ts";
|
|
79
80
|
import { attributedUserId, MASTRA_CONFIG_SCHEMA, type MastraPluginConfig } from "./config.ts";
|
|
80
81
|
import {
|
|
81
82
|
chartFetchDefaults,
|
|
@@ -85,7 +86,6 @@ import {
|
|
|
85
86
|
statementDataDefaults,
|
|
86
87
|
} from "./defaults.ts";
|
|
87
88
|
import { collectSpaceSuggestions, resolveGenieSpaces } from "./genie.ts";
|
|
88
|
-
import { historyRoute } from "./history.ts";
|
|
89
89
|
import {
|
|
90
90
|
requestUserId,
|
|
91
91
|
resolveIdentityMode,
|
|
@@ -105,7 +105,6 @@ import {
|
|
|
105
105
|
} from "./server.ts";
|
|
106
106
|
import { resolveServingConfig } from "./serving.ts";
|
|
107
107
|
import { fetchStatementData, STATEMENT_ROW_CAP } from "./statement.ts";
|
|
108
|
-
import { threadsRoute } from "./threads.ts";
|
|
109
108
|
import { attachChatTurnTraceIo } from "./trace-io.ts";
|
|
110
109
|
import { invalidFields } from "./validation.ts";
|
|
111
110
|
|
|
@@ -1122,34 +1121,7 @@ export class MastraPlugin extends Plugin<MastraPluginConfig> {
|
|
|
1122
1121
|
app: this.mastraApp,
|
|
1123
1122
|
mastra: this.mastra,
|
|
1124
1123
|
prefix: "",
|
|
1125
|
-
customApiRoutes:
|
|
1126
|
-
// `historyRoute` registers both GET (load) and DELETE
|
|
1127
|
-
// (clear) on the same path, so it returns an array we
|
|
1128
|
-
// splice in.
|
|
1129
|
-
...historyRoute({
|
|
1130
|
-
path: routes.MASTRA_ROUTES.history,
|
|
1131
|
-
agent: this.built.defaultAgentId,
|
|
1132
|
-
}),
|
|
1133
|
-
// Assert the `:agentId` template type: the per-package build's
|
|
1134
|
-
// NodeNext resolution widens the imported `routes.MASTRA_ROUTES.history`
|
|
1135
|
-
// to `string` (the source/bundler typecheck keeps it a literal),
|
|
1136
|
-
// which would otherwise drop this out of the dynamic-agent
|
|
1137
|
-
// overload and demand a fixed `agent`.
|
|
1138
|
-
...historyRoute({
|
|
1139
|
-
path: `${routes.MASTRA_ROUTES.history}/:agentId` as `${string}:agentId`,
|
|
1140
|
-
}),
|
|
1141
|
-
// `threadsRoute` registers GET (list the caller's conversation
|
|
1142
|
-
// threads) and DELETE (remove the targeted thread) on the same
|
|
1143
|
-
// path; both the default-agent and dynamic-agent mounts are
|
|
1144
|
-
// spliced in, mirroring the history routes above.
|
|
1145
|
-
...threadsRoute({
|
|
1146
|
-
path: routes.MASTRA_ROUTES.threads,
|
|
1147
|
-
agent: this.built.defaultAgentId,
|
|
1148
|
-
}),
|
|
1149
|
-
...threadsRoute({
|
|
1150
|
-
path: `${routes.MASTRA_ROUTES.threads}/:agentId` as `${string}:agentId`,
|
|
1151
|
-
}),
|
|
1152
|
-
],
|
|
1124
|
+
customApiRoutes: agentChatRoutes(),
|
|
1153
1125
|
});
|
|
1154
1126
|
await this.mastraServer.init();
|
|
1155
1127
|
this.logger.info("ready", {
|