@dbx-tools/appkit-mastra 0.1.13 → 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 +34 -39
- 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 +4 -4
- package/dist/src/memory.js +2 -2
- package/dist/src/model.js +2 -2
- package/dist/src/observability.d.ts +56 -25
- package/dist/src/observability.js +70 -56
- package/dist/src/plugin.js +25 -15
- 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 -18
- 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 +5 -5
- package/src/model.ts +3 -3
- package/src/observability.ts +94 -70
- package/src/plugin.ts +25 -15
- 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/dist/src/server.d.ts
CHANGED
|
@@ -19,6 +19,18 @@ export declare class MastraServer extends MastraServerExpress {
|
|
|
19
19
|
constructor(config: MastraPluginConfig, ...args: ConstructorParameters<typeof MastraServerExpress>);
|
|
20
20
|
registerAuthMiddleware(): void;
|
|
21
21
|
configureRequestContextUser(requestContext: RequestContext): void;
|
|
22
|
+
/**
|
|
23
|
+
* Stamp a per-request id and echo it on the response so an upstream
|
|
24
|
+
* proxy / curl client / browser-side log line can pair its view of
|
|
25
|
+
* the request with the matching trace span. Reuses `X-Request-Id`
|
|
26
|
+
* when the upstream already supplies one so multi-hop traces stay
|
|
27
|
+
* joined; otherwise mints a UUIDv4.
|
|
28
|
+
*
|
|
29
|
+
* The id is surfaced as `mastra__requestId` span metadata via
|
|
30
|
+
* {@link TRACE_REQUEST_CONTEXT_KEYS} and as the `X-Request-Id`
|
|
31
|
+
* response header so dev tools can copy it from either side.
|
|
32
|
+
*/
|
|
33
|
+
configureRequestContextRequestId(req: express.Request, res: express.Response, requestContext: RequestContext): void;
|
|
22
34
|
configureRequestContextThreadId(req: express.Request, res: express.Response, requestContext: RequestContext): void;
|
|
23
35
|
configureRequestContextModelOverride(req: express.Request, requestContext: RequestContext): void;
|
|
24
36
|
}
|
package/dist/src/server.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* point.
|
|
6
6
|
*/
|
|
7
7
|
import { getExecutionContext } from "@databricks/appkit";
|
|
8
|
-
import { httpUtils, logUtils, stringUtils } from "@dbx-tools/
|
|
8
|
+
import { httpUtils, logUtils, stringUtils } from "@dbx-tools/shared";
|
|
9
9
|
import { MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY, } from "@mastra/core/request-context";
|
|
10
10
|
import { MastraServer as MastraServerExpress } from "@mastra/express";
|
|
11
11
|
import { randomUUID } from "node:crypto";
|
|
12
|
-
import { MASTRA_USER_KEY } from "./config.js";
|
|
12
|
+
import { MASTRA_REQUEST_ID_KEY, MASTRA_USER_EMAIL_KEY, MASTRA_USER_KEY, MASTRA_USER_NAME_KEY, } from "./config.js";
|
|
13
13
|
import { extractModelOverride, MASTRA_MODEL_OVERRIDE_KEY, resolveServingConfig, } from "./serving.js";
|
|
14
14
|
/**
|
|
15
15
|
* `@mastra/express` subclass that stamps `RequestContext` with the
|
|
@@ -31,11 +31,15 @@ export class MastraServer extends MastraServerExpress {
|
|
|
31
31
|
this.configureRequestContextUser(requestContext);
|
|
32
32
|
this.configureRequestContextThreadId(req, res, requestContext);
|
|
33
33
|
this.configureRequestContextModelOverride(req, requestContext);
|
|
34
|
+
this.configureRequestContextRequestId(req, res, requestContext);
|
|
34
35
|
this.log.debug("auth:middleware", {
|
|
35
36
|
method: req.method,
|
|
36
37
|
path: req.path,
|
|
38
|
+
requestId: requestContext.get(MASTRA_REQUEST_ID_KEY),
|
|
37
39
|
threadId: requestContext.get(MASTRA_THREAD_ID_KEY),
|
|
38
40
|
resourceId: requestContext.get(MASTRA_RESOURCE_ID_KEY),
|
|
41
|
+
userName: requestContext.get(MASTRA_USER_NAME_KEY),
|
|
42
|
+
userEmail: requestContext.get(MASTRA_USER_EMAIL_KEY),
|
|
39
43
|
modelOverride: requestContext.get(
|
|
40
44
|
// imported below; logged so a misrouted request shows
|
|
41
45
|
// up alongside its model selection in `LOG_LEVEL=debug`.
|
|
@@ -56,6 +60,38 @@ export class MastraServer extends MastraServerExpress {
|
|
|
56
60
|
};
|
|
57
61
|
requestContext.set(MASTRA_USER_KEY, user);
|
|
58
62
|
requestContext.set(MASTRA_RESOURCE_ID_KEY, user.id);
|
|
63
|
+
// AppKit's `UserContext` surfaces display name / email only on
|
|
64
|
+
// OBO requests. Service-context calls (background tasks, server
|
|
65
|
+
// start-up) leave these undefined and we skip the stamp so
|
|
66
|
+
// downstream trace metadata stays absent rather than empty.
|
|
67
|
+
if ("isUserContext" in executionContext) {
|
|
68
|
+
if (executionContext.userName) {
|
|
69
|
+
requestContext.set(MASTRA_USER_NAME_KEY, executionContext.userName);
|
|
70
|
+
}
|
|
71
|
+
if (executionContext.userEmail) {
|
|
72
|
+
requestContext.set(MASTRA_USER_EMAIL_KEY, executionContext.userEmail);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Stamp a per-request id and echo it on the response so an upstream
|
|
78
|
+
* proxy / curl client / browser-side log line can pair its view of
|
|
79
|
+
* the request with the matching trace span. Reuses `X-Request-Id`
|
|
80
|
+
* when the upstream already supplies one so multi-hop traces stay
|
|
81
|
+
* joined; otherwise mints a UUIDv4.
|
|
82
|
+
*
|
|
83
|
+
* The id is surfaced as `mastra__requestId` span metadata via
|
|
84
|
+
* {@link TRACE_REQUEST_CONTEXT_KEYS} and as the `X-Request-Id`
|
|
85
|
+
* response header so dev tools can copy it from either side.
|
|
86
|
+
*/
|
|
87
|
+
configureRequestContextRequestId(req, res, requestContext) {
|
|
88
|
+
if (requestContext.get(MASTRA_REQUEST_ID_KEY))
|
|
89
|
+
return;
|
|
90
|
+
const headerValue = req.headers["x-request-id"];
|
|
91
|
+
const upstream = Array.isArray(headerValue) ? headerValue[0] : headerValue;
|
|
92
|
+
const requestId = upstream?.trim() || randomUUID();
|
|
93
|
+
requestContext.set(MASTRA_REQUEST_ID_KEY, requestId);
|
|
94
|
+
res.setHeader("X-Request-Id", requestId);
|
|
59
95
|
}
|
|
60
96
|
configureRequestContextThreadId(req, res, requestContext) {
|
|
61
97
|
if (requestContext.get(MASTRA_THREAD_ID_KEY))
|
package/dist/src/serving.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* `plugin.ts` exposes the cached list at `GET /models`.
|
|
21
21
|
*/
|
|
22
22
|
import { CacheManager } from "@databricks/appkit";
|
|
23
|
-
import { logUtils, stringUtils } from "@dbx-tools/
|
|
23
|
+
import { logUtils, stringUtils } from "@dbx-tools/shared";
|
|
24
24
|
import Fuse from "fuse.js";
|
|
25
25
|
const log = logUtils.logger("mastra/serving");
|
|
26
26
|
/**
|
package/dist/src/tools/email.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* email is domain-specific, not infrastructure. Spread it into the
|
|
26
26
|
* specific agents that should be able to draft emails.
|
|
27
27
|
*/
|
|
28
|
-
import { logUtils, stringUtils } from "@dbx-tools/
|
|
28
|
+
import { logUtils, stringUtils } from "@dbx-tools/shared";
|
|
29
29
|
import { createTool } from "@mastra/core/tools";
|
|
30
30
|
import { z } from "zod";
|
|
31
31
|
const log = logUtils.logger("mastra/tool/send-email");
|