@dbx-tools/appkit-mastra 0.1.71 → 0.1.73

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 CHANGED
@@ -88,6 +88,94 @@ Override per plugin or per agent by passing `memory` / `storage` as
88
88
  index / schema). The fields are typed in [`config.ts`](src/config.ts);
89
89
  the wiring is in [`memory.ts`](src/memory.ts).
90
90
 
91
+ ### Conversations (threads)
92
+
93
+ When storage is on, a user owns many conversation threads. The plugin
94
+ resolves the thread a request targets from `RequestContext`, in order:
95
+
96
+ 1. A **client-selected thread id** - the thread-selection header
97
+ (`x-mastra-thread-id`) or `?threadId=` query. This is how the chat UI
98
+ references a specific conversation: it picks an id from the threads
99
+ listing (or mints one for a new chat) and stamps it on every call, so
100
+ streaming, history, and clear all target that thread.
101
+ 2. The **per-session cookie** (`appkit_<plugin-name>_session_id`), minted
102
+ on first contact, as the single-thread fallback for clients that
103
+ don't manage threads explicitly.
104
+
105
+ The thread id pins both `agent.stream()` persistence and the history /
106
+ threads routes, so client and server can never disagree on which
107
+ conversation is active. Two custom routes back the UI's conversation
108
+ management (registered alongside `/route/history`):
109
+
110
+ - `GET /route/threads` (`/route/threads/:agentId`) - one page of the
111
+ caller's threads, newest first, **scoped to the caller's resource** so
112
+ a user only ever sees their own conversations.
113
+ - `DELETE /route/threads` - delete the targeted thread (id from the
114
+ thread-selection header). Ownership is enforced server-side: a thread
115
+ is only removed when it belongs to the caller.
116
+
117
+ Each thread is auto-titled from its opening turn (Mastra's
118
+ `generateTitle`), but titling runs on the **small / fast chat tier**
119
+ (`ModelClass.ChatFast`) via the dedicated summarizer in
120
+ [`summarize.ts`](src/summarize.ts) - not the agent's primary model - so
121
+ naming a conversation never spends the heavyweight model. The route
122
+ handlers live in [`threads.ts`](src/threads.ts); the thread-id
123
+ resolution is in [`server.ts`](src/server.ts). The drop-in `MastraChat`
124
+ from `@dbx-tools/appkit-mastra-ui` renders the whole conversation sidebar
125
+ over these routes with no extra wiring.
126
+
127
+ ### Summarization (`summarize` tool)
128
+
129
+ Every agent gets a system-default ambient `summarize` tool that condenses
130
+ arbitrary text (long content, notes, transcripts, bulky tool results) on
131
+ the small / fast chat tier instead of the agent's primary model. It takes
132
+ `text` plus optional `instructions` (e.g. "one sentence", "list the action
133
+ items") and a `maxWords` soft cap, and returns `{ summary }`. The same
134
+ small-tier summarizer backs conversation titling above. Shadow it by
135
+ defining a same-named tool in `config.tools` (or a per-agent `tools`), and
136
+ reuse it programmatically via the exported `summarizeText(config, text,
137
+ opts)` / `buildSummarizeTool(config)`.
138
+
139
+ ### Managed Memory (Databricks Agent Memory, Beta)
140
+
141
+ `managedMemory` swaps the Postgres `PgVector` semantic-recall layer for
142
+ [Databricks Managed Agent Memory](https://docs.databricks.com/aws/en/generative-ai/agent-framework/managed-memory)
143
+ - a Unity Catalog memory-store. When active, every agent gets two
144
+ ambient tools (`save_memory`, `search_memory`) plus an auto-recall input
145
+ processor that searches the user's entries with the latest message and
146
+ injects the top matches before each turn. Entries are scoped per-user
147
+ via OBO (the model never sets the scope). The thread / message
148
+ transcript still uses `PostgresStore` only when `lakebase()` is
149
+ registered - managed memory does not pull in Lakebase.
150
+
151
+ ```ts
152
+ mastra({
153
+ // Prefer-if-available: enabled automatically when MEMORY_STORE is set
154
+ // and the workspace exposes the memory-stores API; otherwise PgVector.
155
+ managedMemory: true, // or { store, topK, autoCreate, recall, tools }
156
+ });
157
+ ```
158
+
159
+ The store is a three-level Unity Catalog name (`catalog.schema.name`),
160
+ resolved from `managedMemory.store` or the `MEMORY_STORE` env var.
161
+ Enable semantics:
162
+
163
+ - **omitted** (default, prefer-if-available): on only when `MEMORY_STORE`
164
+ is set and the API is reachable; otherwise the `PgVector` path.
165
+ - **`false`**: never use managed memory.
166
+ - **`true`**: enable; store must come from `MEMORY_STORE`.
167
+ - **object**: enable with explicit `store` (or `MEMORY_STORE`) plus
168
+ `topK`, `autoCreate`, `recall`, `tools`, `entryPath` overrides.
169
+
170
+ Required Unity Catalog privileges for the app service principal:
171
+ `CREATE MEMORY STORE` on the schema (only when `autoCreate` is on, the
172
+ default), plus `READ MEMORY STORE` / `WRITE MEMORY STORE` on the store.
173
+ The capability probe and optional store auto-create run once at setup as
174
+ the service principal. Managed Memory is Beta and REST-only; on any
175
+ probe, create, or search failure the plugin logs and falls back to the
176
+ `PgVector` path so chat stays available. The connector lives in
177
+ [`connectors/managed-memory/`](src/connectors/managed-memory).
178
+
91
179
  ## The `tools(plugins)` callback
92
180
 
93
181
  Each agent supplies either a static `tools: { ... }` record or a
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { appkitUtils, logUtils } from "@dbx-tools/shared";
4
4
  import * as _mastra_core_agent0 from "@mastra/core/agent";
5
5
  import { Agent, AgentConfig, ToolsInput } from "@mastra/core/agent";
6
6
  import * as _mastra_core_tools0 from "@mastra/core/tools";
7
- import { Tool, createTool } from "@mastra/core/tools";
7
+ import { Tool, createTool, createTool as createTool$1 } from "@mastra/core/tools";
8
8
  import * as _databricks_appkit0 from "@databricks/appkit";
9
9
  import { BasePluginConfig, IAppRouter, Plugin, ResourceRequirement } from "@databricks/appkit";
10
10
  import { z } from "zod";
@@ -29,6 +29,99 @@ import * as _mastra_core_channels0 from "@mastra/core/channels";
29
29
  export * from "@dbx-tools/appkit-mastra-shared";
30
30
  export * from "@dbx-tools/model";
31
31
 
32
+ //#region packages/appkit-mastra/src/connectors/managed-memory/types.d.ts
33
+ /**
34
+ * Type contract for the Databricks Managed Agent Memory connector.
35
+ *
36
+ * Managed Memory is a Beta Unity Catalog feature (REST-only, no TS
37
+ * SDK yet) that stores long-term agent memories as scoped entries in a
38
+ * UC `memory-store`. In `@dbx-tools/appkit-mastra` it plays the role
39
+ * the Postgres `PgVector` semantic-recall layer otherwise fills: an
40
+ * auto-recall input processor reads the user's top entries before each
41
+ * turn, and `save_memory` / `search_memory` tools let the agent persist
42
+ * and look up durable facts. Every read / write is scoped to the OBO
43
+ * user id resolved in trusted server code - the model never sets scope.
44
+ */
45
+ /**
46
+ * Caller-facing configuration for the managed-memory backend, set via
47
+ * {@link MastraPluginConfig.managedMemory}. Every field is optional;
48
+ * the object form only needs to override what differs from the
49
+ * connector defaults.
50
+ */
51
+ interface ManagedMemoryConfig {
52
+ /**
53
+ * Three-level Unity Catalog name of the memory store
54
+ * (`catalog.schema.name`). Falls back to the `MEMORY_STORE` env var
55
+ * when omitted. Required (here or in env) whenever managed memory is
56
+ * explicitly enabled; in prefer-if-available mode its absence simply
57
+ * leaves managed memory off.
58
+ */
59
+ store?: string;
60
+ /** Description stamped on the store when {@link autoCreate} creates it. */
61
+ description?: string;
62
+ /**
63
+ * Number of entries the recall processor injects and `search_memory`
64
+ * returns by default. Defaults to {@link DEFAULT_TOPK}.
65
+ */
66
+ topK?: number;
67
+ /**
68
+ * Create the store at setup when it doesn't exist (requires
69
+ * `CREATE MEMORY STORE` on the schema). Defaults to `true`; set
70
+ * `false` to require the store be provisioned out of band.
71
+ */
72
+ autoCreate?: boolean;
73
+ /**
74
+ * Attach the auto-recall input processor that injects the user's
75
+ * top entries before each turn. Defaults to `true`.
76
+ */
77
+ recall?: boolean;
78
+ /**
79
+ * Expose the `save_memory` / `search_memory` ambient tools to every
80
+ * agent. Defaults to `true`.
81
+ */
82
+ tools?: boolean;
83
+ /**
84
+ * Entry path new `save_memory` writes land under. Defaults to
85
+ * {@link DEFAULT_ENTRY_PATH}. Managed Memory keys entries by path
86
+ * within a scope, so a stable path accumulates notes for a user.
87
+ */
88
+ entryPath?: string;
89
+ }
90
+ /**
91
+ * A single memory entry as returned by the search endpoint. Fields
92
+ * mirror the UC memory-store wire shape but are all optional except
93
+ * `contents` because the Beta API surface may still drift.
94
+ */
95
+ interface MemoryEntry {
96
+ /** Entry path within the scope (e.g. `/memories/notes.md`). */
97
+ path?: string;
98
+ /** Entry body - the recalled text. */
99
+ contents: string;
100
+ /** Optional one-line summary of the entry. */
101
+ description?: string;
102
+ /** Relevance score from the search ranker, when present. */
103
+ score?: number;
104
+ }
105
+ /**
106
+ * Resolved managed-memory runtime handed to the tools and recall
107
+ * processor when managed memory is the active long-term backend.
108
+ * Built once at setup after the capability probe succeeds; carries the
109
+ * store target and recall sizing, not the workspace client (that is
110
+ * resolved per-request from the OBO execution context).
111
+ */
112
+ interface ManagedMemoryRuntime {
113
+ /** Three-level UC name of the resolved store. */
114
+ storeName: string;
115
+ /** Entries to recall / return per call. */
116
+ topK: number;
117
+ /** Default path for `save_memory` writes. */
118
+ entryPath: string;
119
+ /** Whether to expose the `save_memory` / `search_memory` tools. */
120
+ tools: boolean;
121
+ /** Whether to attach the auto-recall input processor. */
122
+ recall: boolean;
123
+ }
124
+ //#endregion
32
125
  //#region packages/appkit-mastra/src/genie.d.ts
33
126
  /** Default alias used when a single unnamed Genie space is wired up. */
34
127
  declare const DEFAULT_GENIE_ALIAS = "default";
@@ -252,8 +345,40 @@ interface MastraPluginConfig extends BasePluginConfig {
252
345
  /**
253
346
  * PgVector store for Mastra memory recall. `true` reuses the
254
347
  * `lakebase` plugin's pool; an object opens a dedicated store.
348
+ *
349
+ * When {@link managedMemory} is active it takes over the long-term /
350
+ * semantic-recall role and `PgVector` is not built, regardless of
351
+ * this setting; thread / message transcript (`storage`) is
352
+ * unaffected.
255
353
  */
256
354
  memory?: boolean | MastraMemoryConfig;
355
+ /**
356
+ * Databricks Managed Agent Memory (Beta) as the long-term /
357
+ * semantic-recall backend, replacing the Postgres `PgVector` role.
358
+ * When active, every agent gets `save_memory` / `search_memory` tools
359
+ * and an auto-recall input processor that injects the user's top
360
+ * entries before each turn; entries are scoped per-user via OBO. The
361
+ * thread / message transcript still uses `PostgresStore` only when
362
+ * the `lakebase` plugin is registered - managed memory does not pull
363
+ * in Lakebase.
364
+ *
365
+ * - `undefined` (default, prefer-if-available): enabled only when the
366
+ * `MEMORY_STORE` env var names a store and the workspace exposes the
367
+ * memory-stores API; otherwise the `PgVector` path is used.
368
+ * - `false`: never use managed memory.
369
+ * - `true`: enable; the store must be named via the `MEMORY_STORE`
370
+ * env var (a missing store is a setup error).
371
+ * - {@link ManagedMemoryConfig}: enable with explicit `store`
372
+ * (or `MEMORY_STORE`), recall size, auto-create, and tool / recall
373
+ * toggles.
374
+ *
375
+ * The store is a three-level Unity Catalog name (`catalog.schema.name`).
376
+ * The app service principal needs `CREATE MEMORY STORE` on the schema
377
+ * when auto-create is on, plus `READ/WRITE MEMORY STORE`. On any probe
378
+ * or create failure the plugin logs and falls back to the `PgVector`
379
+ * path so chat stays available.
380
+ */
381
+ managedMemory?: boolean | ManagedMemoryConfig;
257
382
  /**
258
383
  * Code-defined agents. Accepts three shapes for convenience:
259
384
  *
@@ -502,6 +627,17 @@ interface MastraPluginConfig extends BasePluginConfig {
502
627
  }
503
628
  //#endregion
504
629
  //#region packages/appkit-mastra/src/memory.d.ts
630
+ /** Options controlling how {@link MemoryBuilder} resolves each agent's memory. */
631
+ interface MemoryBuilderOptions {
632
+ /**
633
+ * Skip building / attaching `PgVector` (and its `semanticRecall`)
634
+ * for every agent. Set when Databricks Managed Memory is the active
635
+ * long-term backend - it fills the semantic-recall role instead, via
636
+ * the recall input processor and memory tools. Thread / message
637
+ * storage (`PostgresStore`) is unaffected.
638
+ */
639
+ suppressVector?: boolean;
640
+ }
505
641
  /**
506
642
  * Builds one `Memory` per agent against a shared service-principal
507
643
  * Lakebase pool. Per-instance state keeps the shared `PgVector` alive
@@ -510,8 +646,9 @@ interface MastraPluginConfig extends BasePluginConfig {
510
646
  declare class MemoryBuilder {
511
647
  private readonly config;
512
648
  private readonly servicePrincipalPool;
649
+ private readonly options;
513
650
  private sharedVector;
514
- constructor(config: MastraPluginConfig, servicePrincipalPool: Pool);
651
+ constructor(config: MastraPluginConfig, servicePrincipalPool: Pool, options?: MemoryBuilderOptions);
515
652
  /**
516
653
  * Build a `Memory` for `agentId` after the plugin/agent cascade.
517
654
  * Returns `undefined` when the agent has neither storage nor a
@@ -843,6 +980,14 @@ declare function buildAgents(opts: {
843
980
  config: MastraPluginConfig;
844
981
  context: appkitUtils.PluginContextLike | undefined;
845
982
  memoryBuilder?: MemoryBuilder;
983
+ /**
984
+ * Active Databricks Managed Memory runtime, present only when managed
985
+ * memory was resolved and probed successfully at setup. When set,
986
+ * every agent gets the `save_memory` / `search_memory` tools and the
987
+ * auto-recall input processor; the `PgVector` path is suppressed
988
+ * upstream in `memory.ts`.
989
+ */
990
+ managedMemory?: ManagedMemoryRuntime;
846
991
  log: logUtils.Logger;
847
992
  }): Promise<BuiltAgents>;
848
993
  //#endregion
@@ -971,6 +1116,144 @@ declare function buildRenderDataTool(config: MastraPluginConfig): _mastra_core_t
971
1116
  chartId: string;
972
1117
  }, unknown, unknown, _mastra_core_tools0.ToolExecutionContext<unknown, unknown, unknown>, "render_data", unknown>;
973
1118
  //#endregion
1119
+ //#region packages/appkit-mastra/src/connectors/managed-memory/client.d.ts
1120
+ /** Workspace client carried on an AppKit execution context. */
1121
+ type WorkspaceClient$1 = appkitUtils.WorkspaceClientLike;
1122
+ /** Parsed three-level Unity Catalog name. */
1123
+ interface StoreName {
1124
+ catalog: string;
1125
+ schema: string;
1126
+ name: string;
1127
+ }
1128
+ /**
1129
+ * Error thrown for a non-2xx memory-store response. Carries the HTTP
1130
+ * status so callers can distinguish "feature unavailable / store
1131
+ * missing" (probe falls back) from genuine failures.
1132
+ */
1133
+ declare class ManagedMemoryError extends Error {
1134
+ readonly status: number;
1135
+ readonly statusText: string;
1136
+ constructor(status: number, statusText: string, body: string);
1137
+ }
1138
+ /**
1139
+ * Split a three-level `catalog.schema.name` into its parts. Throws when
1140
+ * the input isn't exactly three dot-separated, non-empty segments so a
1141
+ * misconfigured `MEMORY_STORE` fails loudly at setup rather than
1142
+ * silently hitting a malformed URL.
1143
+ */
1144
+ declare function parseStoreName(fullName: string): StoreName;
1145
+ /**
1146
+ * Fetch a store by full name. Returns the raw store payload when it
1147
+ * exists, or `null` on 404 so callers can treat "missing" as a normal
1148
+ * condition (the capability probe and `ensureStore` both rely on this).
1149
+ * Any other non-2xx status throws.
1150
+ */
1151
+ declare function getStore(client: WorkspaceClient$1, fullName: string, signal?: AbortSignal): Promise<unknown | null>;
1152
+ /**
1153
+ * Probe for the store and create it when missing. Returns `true` when
1154
+ * the store exists (found or created). The create body splits the
1155
+ * three-level name into the catalog / schema / name fields the API
1156
+ * expects. A `getStore` 404 followed by a successful create is the
1157
+ * common first-run path.
1158
+ */
1159
+ declare function ensureStore(client: WorkspaceClient$1, fullName: string, description: string, signal?: AbortSignal): Promise<boolean>;
1160
+ /**
1161
+ * Write (upsert) an entry into the store under `scope`. Scope is the
1162
+ * OBO user id resolved in trusted code; it travels as a query parameter
1163
+ * so the API isolates one user's memories from another's.
1164
+ */
1165
+ declare function writeEntry(client: WorkspaceClient$1, fullName: string, scope: string, entry: {
1166
+ path: string;
1167
+ contents: string;
1168
+ description?: string;
1169
+ }, signal?: AbortSignal): Promise<void>;
1170
+ /**
1171
+ * Semantic search over a user's entries within `scope`. Returns up to
1172
+ * `topK` entries, parsed defensively so a renamed / missing Beta field
1173
+ * degrades to an empty list rather than crashing the turn.
1174
+ */
1175
+ declare function search(client: WorkspaceClient$1, fullName: string, scope: string, query: string, topK: number, signal?: AbortSignal): Promise<MemoryEntry[]>;
1176
+ //#endregion
1177
+ //#region packages/appkit-mastra/src/connectors/managed-memory/context.d.ts
1178
+ /** Resolved per-request memory context: the client to call and the scope. */
1179
+ interface MemoryRequestContext {
1180
+ client: appkitUtils.WorkspaceClientLike;
1181
+ scope: string;
1182
+ }
1183
+ /**
1184
+ * Resolve the OBO-scoped workspace client and the memory scope for the
1185
+ * current turn. Mirrors `model.ts`: prefer the AppKit user stamped on
1186
+ * the request context, fall back to the ambient execution context (the
1187
+ * active OBO scope or the service principal). Scope is the Mastra
1188
+ * resource id (the per-user thread owner) when present, else the user
1189
+ * id. Returns `null` when neither yields a usable scope.
1190
+ */
1191
+ declare function resolveMemoryContext(requestContext: RequestContext | undefined): MemoryRequestContext | null;
1192
+ //#endregion
1193
+ //#region packages/appkit-mastra/src/connectors/managed-memory/defaults.d.ts
1194
+ /**
1195
+ * Default values and environment variable names for the managed-memory
1196
+ * connector. Kept in a leaf module so the client, tools, recall
1197
+ * processor, and plugin setup can share them without a cycle.
1198
+ */
1199
+ /**
1200
+ * Environment variable holding the three-level Unity Catalog store name
1201
+ * (`catalog.schema.name`). Read when {@link ManagedMemoryConfig.store}
1202
+ * is omitted; also the sole enable signal in prefer-if-available mode
1203
+ * (managed memory stays off when it is unset).
1204
+ */
1205
+ declare const MEMORY_STORE_ENV = "MEMORY_STORE";
1206
+ /**
1207
+ * Default number of entries the recall processor injects and
1208
+ * `search_memory` returns. Matches the prior `PgVector`
1209
+ * `semanticRecall.topK` so behavior is unchanged after the swap.
1210
+ */
1211
+ declare const DEFAULT_TOPK = 3;
1212
+ /**
1213
+ * Default path `save_memory` writes land under. Managed Memory keys
1214
+ * entries by path within a scope, so a single stable path accumulates a
1215
+ * user's notes rather than scattering them.
1216
+ */
1217
+ declare const DEFAULT_ENTRY_PATH = "/memories/notes.md";
1218
+ /** Description stamped on the store when the connector auto-creates it. */
1219
+ declare const DEFAULT_STORE_DESCRIPTION = "Long-term agent memory managed by @dbx-tools/appkit-mastra.";
1220
+ //#endregion
1221
+ //#region packages/appkit-mastra/src/connectors/managed-memory/resolve.d.ts
1222
+ /**
1223
+ * Fully-resolved managed-memory target: everything `plugin.ts` needs to
1224
+ * probe the API, optionally create the store, and (on success) build
1225
+ * the runtime / tools / recall processor.
1226
+ */
1227
+ interface ManagedMemoryTarget {
1228
+ storeName: string;
1229
+ description: string;
1230
+ topK: number;
1231
+ entryPath: string;
1232
+ autoCreate: boolean;
1233
+ recall: boolean;
1234
+ tools: boolean;
1235
+ }
1236
+ /**
1237
+ * Resolve the managed-memory target from config + env, or `null` when
1238
+ * managed memory is disabled. Throws when explicitly enabled but no
1239
+ * store name can be resolved (config or `MEMORY_STORE`), so a
1240
+ * misconfiguration surfaces at setup rather than silently falling back.
1241
+ */
1242
+ declare function resolveManagedMemoryTarget(config: MastraPluginConfig): ManagedMemoryTarget | null;
1243
+ //#endregion
1244
+ //#region packages/appkit-mastra/src/connectors/managed-memory/tools.d.ts
1245
+ /** Mastra tool record shape (kept local to avoid an `agents.ts` cycle). */
1246
+ type MastraTools$1 = Record<string, ReturnType<typeof createTool$1>>;
1247
+ /**
1248
+ * Build the `save_memory` / `search_memory` tool pair bound to a
1249
+ * resolved managed-memory runtime. The runtime supplies the store name,
1250
+ * recall size, and default entry path; the per-request client and scope
1251
+ * are resolved inside each `execute`.
1252
+ */
1253
+ declare function buildManagedMemoryTools(runtime: ManagedMemoryRuntime): MastraTools$1;
1254
+ /** Render an entry to a single recall line (summary prefix when present). */
1255
+ declare function renderEntry(entry: MemoryEntry): string;
1256
+ //#endregion
974
1257
  //#region packages/appkit-mastra/src/mcp.d.ts
975
1258
  /**
976
1259
  * A built MCP server plus the request paths it answers on, relative to
@@ -1032,7 +1315,32 @@ declare class MastraServer$1 extends MastraServer {
1032
1315
  * response header so dev tools can copy it from either side.
1033
1316
  */
1034
1317
  configureRequestContextRequestId(req: express.Request, res: express.Response, requestContext: RequestContext): void;
1318
+ /**
1319
+ * Resolve the thread id this request targets and pin it on
1320
+ * `RequestContext` (consumed by the agent stream for persistence and
1321
+ * by the history / threads routes). Resolution order:
1322
+ *
1323
+ * 1. A client-supplied thread id (the thread-selection header /
1324
+ * `?threadId=` query). This is how the chat UI references a
1325
+ * specific conversation among the many a user owns - it picks a
1326
+ * thread id from the `/threads` listing (or mints one for a new
1327
+ * conversation) and stamps it here. The id is scoped to the
1328
+ * caller's resource by the recall / list routes, so a client
1329
+ * can only ever read or write its own threads.
1330
+ * 2. The per-session cookie (`appkit_<plugin-name>_session_id`),
1331
+ * minted on first contact. This is the default single-thread
1332
+ * fallback for clients that don't manage threads explicitly, so
1333
+ * existing embeds keep one stable conversation per session with
1334
+ * no client changes.
1335
+ */
1035
1336
  configureRequestContextThreadId(req: express.Request, res: express.Response, requestContext: RequestContext): void;
1337
+ /**
1338
+ * Read the client-selected thread id from the request, preferring
1339
+ * the thread-selection header over the `?threadId=` query. Returns
1340
+ * `null` when neither carries a non-empty value so the caller falls
1341
+ * back to the session cookie.
1342
+ */
1343
+ private readRequestedThreadId;
1036
1344
  configureRequestContextModelOverride(req: express.Request, requestContext: RequestContext): void;
1037
1345
  }
1038
1346
  //#endregion
@@ -1192,6 +1500,25 @@ declare class MastraPlugin extends Plugin<MastraPluginConfig> {
1192
1500
  * `getExecutionContext()` returns the OBO-scoped client.
1193
1501
  */
1194
1502
  private listModels;
1503
+ /**
1504
+ * Resolve and probe the Databricks Managed Memory backend at setup.
1505
+ *
1506
+ * Returns the runtime (store + recall sizing + tool / recall toggles)
1507
+ * when managed memory is enabled and the workspace memory-stores API
1508
+ * is reachable, else `undefined` so the caller uses the PgVector path.
1509
+ *
1510
+ * The probe runs as the service principal (setup is outside any
1511
+ * `asUser` scope, so `getExecutionContext()` yields the SP client):
1512
+ * the SP owns the store and is the identity that can `CREATE MEMORY
1513
+ * STORE`. When `autoCreate` is on the store is created if missing.
1514
+ *
1515
+ * A misconfiguration where managed memory is explicitly enabled but no
1516
+ * store name is resolvable throws ({@link resolveManagedMemoryTarget})
1517
+ * - that is a wiring bug, not a runtime condition. Every other failure
1518
+ * (feature unavailable, permission denied, network) is caught, logged,
1519
+ * and degraded to a PgVector fallback so chat stays available.
1520
+ */
1521
+ private resolveManagedMemory;
1195
1522
  private buildAgentAndServer;
1196
1523
  }
1197
1524
  declare const mastra: _databricks_appkit0.ToPlugin<typeof MastraPlugin, MastraPluginConfig, "mastra">;
@@ -1229,4 +1556,36 @@ interface ModelOverrideRequest {
1229
1556
  */
1230
1557
  declare function extractModelOverride(req: ModelOverrideRequest): string | null;
1231
1558
  //#endregion
1232
- export { AppKitToolOptions, BuiltAgents, ChartPlannerRequest, DEFAULT_AGENT_MAX_STEPS, DEFAULT_GENIE_ALIAS, DEFAULT_STYLE_INSTRUCTIONS, FALLBACK_AGENT_ID, FetchChartOptions, GENIE_INSTRUCTIONS, GenieSpaceConfig, GenieSpacesConfig, MASTRA_MODEL_OVERRIDE_KEY, MASTRA_REQUEST_ID_KEY, MASTRA_USER_EMAIL_KEY, MASTRA_USER_KEY, MASTRA_USER_NAME_KEY, MastraAgentDefinition, MastraMcpConfig, MastraMemoryConfig, MastraMemoryConfigOverride, MastraPlugin, MastraPluginConfig, MastraPluginToolkitProvider, MastraPlugins, MastraStorageConfigOverride, MastraTools, MastraToolsFn, type ModelOverrideRequest, PrepareChartOptions, ResolvedMcp, TRACE_REQUEST_CONTEXT_KEYS, ToolkitOptions, User, buildAgents, buildGenieToolkitProvider, buildGenieTools, buildMcpServer, buildRenderDataTool, chartPlannerRequestSchema, collectSpaceSuggestions, createAgent, createTool, extractModelOverride, fetchChart, mastra, normalizeGenieSpaces, prepareChart, resolveGenieSpaces, tool };
1559
+ //#region packages/appkit-mastra/src/summarize.d.ts
1560
+ /** Options accepted by {@link summarizeText}. */
1561
+ interface SummarizeOptions {
1562
+ /** Extra guidance for the summary (length, focus, format). */
1563
+ instructions?: string;
1564
+ /** Soft cap on summary length, in words. */
1565
+ maxWords?: number;
1566
+ /** Active request context, so the model resolver mints user-scoped tokens. */
1567
+ requestContext?: RequestContext;
1568
+ /** Abort signal bridged from the calling tool / request. */
1569
+ abortSignal?: AbortSignal;
1570
+ }
1571
+ /**
1572
+ * Summarize `text` with the small-tier summarizer agent, returning the
1573
+ * trimmed summary string. Throws on model failure (the caller decides
1574
+ * how to degrade).
1575
+ */
1576
+ declare function summarizeText(config: MastraPluginConfig, text: string, options?: SummarizeOptions): Promise<string>;
1577
+ /**
1578
+ * Build the `summarize` tool. Exposed as an ambient system tool (like
1579
+ * `render_data`) so every agent can offload condensing long content,
1580
+ * notes, transcripts, or bulky tool results to the fast tier instead of
1581
+ * spending its primary chat model. The tool reads the live
1582
+ * `requestContext` / `abortSignal` off the Mastra execution context so
1583
+ * its model call stays user-scoped and cancels with the turn.
1584
+ */
1585
+ declare function buildSummarizeTool(config: MastraPluginConfig): _mastra_core_tools0.Tool<{
1586
+ text: string;
1587
+ instructions?: string | undefined;
1588
+ maxWords?: number | undefined;
1589
+ }, unknown, unknown, unknown, _mastra_core_tools0.ToolExecutionContext<unknown, unknown, unknown>, "summarize", unknown>;
1590
+ //#endregion
1591
+ export { AppKitToolOptions, BuiltAgents, ChartPlannerRequest, DEFAULT_AGENT_MAX_STEPS, DEFAULT_ENTRY_PATH, DEFAULT_GENIE_ALIAS, DEFAULT_STORE_DESCRIPTION, DEFAULT_STYLE_INSTRUCTIONS, DEFAULT_TOPK, FALLBACK_AGENT_ID, FetchChartOptions, GENIE_INSTRUCTIONS, GenieSpaceConfig, GenieSpacesConfig, MASTRA_MODEL_OVERRIDE_KEY, MASTRA_REQUEST_ID_KEY, MASTRA_USER_EMAIL_KEY, MASTRA_USER_KEY, MASTRA_USER_NAME_KEY, MEMORY_STORE_ENV, ManagedMemoryConfig, ManagedMemoryError, ManagedMemoryRuntime, ManagedMemoryTarget, MastraAgentDefinition, MastraMcpConfig, MastraMemoryConfig, MastraMemoryConfigOverride, MastraPlugin, MastraPluginConfig, MastraPluginToolkitProvider, MastraPlugins, MastraStorageConfigOverride, MastraTools, MastraToolsFn, MemoryEntry, MemoryRequestContext, type ModelOverrideRequest, PrepareChartOptions, ResolvedMcp, type SummarizeOptions, TRACE_REQUEST_CONTEXT_KEYS, ToolkitOptions, User, buildAgents, buildGenieToolkitProvider, buildGenieTools, buildManagedMemoryTools, buildMcpServer, buildRenderDataTool, buildSummarizeTool, chartPlannerRequestSchema, collectSpaceSuggestions, createAgent, createTool, ensureStore, extractModelOverride, fetchChart, getStore, mastra, normalizeGenieSpaces, parseStoreName, prepareChart, renderEntry, resolveGenieSpaces, resolveManagedMemoryTarget, resolveMemoryContext, search, summarizeText, tool, writeEntry };