@dbx-tools/appkit-mastra 0.9.175 → 0.9.177

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/src/server.ts CHANGED
@@ -55,6 +55,7 @@ import {
55
55
  extractModelOverride,
56
56
  MASTRA_MODEL_OVERRIDE_KEY,
57
57
  MASTRA_RESOLVED_MODEL_KEY,
58
+ MASTRA_SMART_ROUTER_INPUT_KEY,
58
59
  resolveServingConfig,
59
60
  } from "./serving.ts";
60
61
  import { recordActiveTraceAuth, recordActiveTraceUser } from "./telemetry.ts";
@@ -78,6 +79,7 @@ const TRUSTED_REQUEST_CONTEXT_KEYS = [
78
79
  MASTRA_SCOPES_KEY,
79
80
  MASTRA_MODEL_OVERRIDE_KEY,
80
81
  MASTRA_RESOLVED_MODEL_KEY,
82
+ MASTRA_SMART_ROUTER_INPUT_KEY,
81
83
  FOLLOW_UP_USER_TEXT_KEY,
82
84
  FOLLOW_UP_NATIVE_QUESTIONS_KEY,
83
85
  FOLLOW_UP_RUN_ID_KEY,
@@ -245,6 +247,7 @@ export class MastraServer extends ExpressMastraServer {
245
247
  await this.configureRequestContextUser(req, requestContext);
246
248
  this.configureRequestContextThreadId(req, res, requestContext);
247
249
  this.configureRequestContextModelOverride(req, requestContext);
250
+ this.configureRequestContextSmartRouterInput(req, requestContext);
248
251
  this.configureRequestContextRequestId(req, res, requestContext);
249
252
  this.configureRequestContextOrigin(req, requestContext);
250
253
  this.configureRequestContextScopes(req, requestContext);
@@ -429,6 +432,14 @@ export class MastraServer extends ExpressMastraServer {
429
432
  if (override) requestContext.set(MASTRA_MODEL_OVERRIDE_KEY, override);
430
433
  }
431
434
  }
435
+
436
+ /** Preserve the parsed request body for task-aware Smart Router selection. */
437
+ configureRequestContextSmartRouterInput(
438
+ req: express.Request,
439
+ requestContext: RequestContext,
440
+ ): void {
441
+ if (req.body !== undefined) requestContext.set(MASTRA_SMART_ROUTER_INPUT_KEY, req.body);
442
+ }
432
443
  }
433
444
 
434
445
  /** Inputs for {@link isMastraRequestAllowed}. */
package/src/serving.ts CHANGED
@@ -31,6 +31,9 @@ export const MASTRA_MODEL_OVERRIDE_KEY = "mastra__model_override";
31
31
  /** RequestContext key carrying the endpoint selected for the active agent step. */
32
32
  export const MASTRA_RESOLVED_MODEL_KEY = "mastra__resolved_model";
33
33
 
34
+ /** RequestContext key carrying the raw request body used to build Smart Router context. */
35
+ export const MASTRA_SMART_ROUTER_INPUT_KEY = "mastra__smart_router_input";
36
+
34
37
  /**
35
38
  * Minimal Express-ish request shape used by {@link extractModelOverride}.
36
39
  * Keeps this module independent of `express` so the helper can be
package/src/summarize.ts CHANGED
@@ -1,16 +1,9 @@
1
1
  /**
2
2
  * Small-tier summarization for the Mastra plugin.
3
3
  *
4
- * Two surfaces, both backed by the fast / small chat tier
4
+ * A dedicated `summarize` tool backed by the fast / small chat tier
5
5
  * ({@link model.ModelClass.ChatFast}) resolved through the same
6
- * `/serving-endpoints` pipeline as the main agents:
7
- *
8
- * - A dedicated `summarize` tool (see {@link buildSummarizeTool})
9
- * agents can call to condense arbitrary text without burning the
10
- * heavyweight chat model.
11
- * - The model + instructions Mastra's memory uses to auto-name
12
- * conversation threads (`generateTitle`), so titling reuses the
13
- * same small tier rather than the agent's primary model.
6
+ * `/serving-endpoints` pipeline as the main agents.
14
7
  *
15
8
  * Mirrors the chart-planner wiring in `chart.ts`: a per-config cached
16
9
  * `Agent` on the fast tier, invoked via `agent.generate(...)` inside
@@ -46,9 +39,9 @@ const SUMMARIZER_INSTRUCTIONS = [
46
39
  ].join("\n");
47
40
 
48
41
  /**
49
- * Instructions Mastra's `generateTitle` hands the small-tier model to
50
- * name a conversation thread from its opening turn. Kept terse so the
51
- * model returns a bare title with no decoration.
42
+ * Instructions Mastra's `generateTitle` hands the agent model to name a
43
+ * conversation thread from its opening turn. Kept terse so the model returns
44
+ * a bare title with no decoration.
52
45
  */
53
46
  export const TITLE_INSTRUCTIONS = [
54
47
  "Generate a short, specific title for this conversation, 3 to 6 words.",
@@ -59,8 +52,7 @@ export const TITLE_INSTRUCTIONS = [
59
52
  ].join(" ");
60
53
 
61
54
  /**
62
- * Resolve the small-tier model for summarization / titling. Reused by
63
- * both the summarizer agent and Mastra memory's `generateTitle`.
55
+ * Resolve the small-tier model for summarization.
64
56
  *
65
57
  * Returned as a `requestContext`-taking function (a Mastra
66
58
  * `DynamicArgument<MastraModelConfig>`) so each call mints user-scoped