@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/src/processors.ts
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Mastra stream processors wired onto the plugin's agents.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* scrubs turn-scoped `chartId` fields out of prior tool results
|
|
8
|
-
* replayed from Memory, so the model can't copy a stale id into the
|
|
9
|
-
* new turn's `[chart:<id>]` markers.
|
|
10
|
-
* - An **output** processor ({@link ResultProcessor}) that trims the
|
|
11
|
-
* bulky, redundant payload fields off targeted outbound stream frames
|
|
12
|
-
* before they're serialized to the SSE client.
|
|
4
|
+
* The input processor ({@link stripStaleChartsProcessor}) scrubs turn-scoped
|
|
5
|
+
* `chartId` fields out of prior tool results replayed from Memory, so the model
|
|
6
|
+
* cannot copy a stale id into the new turn's `[chart:<id>]` markers.
|
|
13
7
|
*
|
|
14
8
|
* @module
|
|
15
9
|
*/
|
|
16
10
|
|
|
17
11
|
import { log } from "@dbx-tools/shared-core";
|
|
18
|
-
import type { InputProcessor, ProcessInputArgs
|
|
12
|
+
import type { InputProcessor, ProcessInputArgs } from "@mastra/core/processors";
|
|
19
13
|
|
|
20
14
|
const logger = log.logger("mastra/processors");
|
|
21
15
|
|
|
@@ -112,59 +106,3 @@ export const stripStaleChartsProcessor: InputProcessor = {
|
|
|
112
106
|
return args.messages;
|
|
113
107
|
},
|
|
114
108
|
};
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Mastra output processor that trims the bulky, redundant payload
|
|
118
|
-
* fields off targeted outbound stream frames.
|
|
119
|
-
*
|
|
120
|
-
* Mastra emits step / finish / tool-result frames whose payloads
|
|
121
|
-
* echo the full tool `output` / `result` / assistant `messages` /
|
|
122
|
-
* `response` - data the chat client already received inline and
|
|
123
|
-
* doesn't need re-sent. This processor empties those keys on the
|
|
124
|
-
* targeted frame types so the outbound SSE stream stays lean;
|
|
125
|
-
* every other frame passes through untouched.
|
|
126
|
-
*/
|
|
127
|
-
export class ResultProcessor implements Processor {
|
|
128
|
-
id = "result-processor";
|
|
129
|
-
|
|
130
|
-
// Tell Mastra to also route tool/data parts to this processor method
|
|
131
|
-
processDataParts = true;
|
|
132
|
-
|
|
133
|
-
async processOutputStream({ part }: { part: any }): Promise<any | null> {
|
|
134
|
-
// 1. Guard clause: Ensure the chunk is a valid object
|
|
135
|
-
if (!part || typeof part !== "object") {
|
|
136
|
-
return part;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// 2. Filter for the targeted frame types
|
|
140
|
-
const targetedTypes = ["step-finish", "finish", "tool-result", "data-tool-agent"];
|
|
141
|
-
if (!targetedTypes.includes(part.type)) {
|
|
142
|
-
return part; // Return unchanged to pass-through
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// 3. Check for the presence of a payload object
|
|
146
|
-
const payload = part.payload;
|
|
147
|
-
if (!payload || typeof payload !== "object") {
|
|
148
|
-
return part;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// 4. Safely delete the unwanted keys from the payload reference
|
|
152
|
-
const keysToDelete = ["output", "messages", "response", "result"];
|
|
153
|
-
for (const key of keysToDelete) {
|
|
154
|
-
if (key in payload) {
|
|
155
|
-
const value = payload[key];
|
|
156
|
-
if (typeof value === "object") {
|
|
157
|
-
payload[key] = {};
|
|
158
|
-
} else if (Array.isArray(value)) {
|
|
159
|
-
payload[key] = [];
|
|
160
|
-
} else {
|
|
161
|
-
delete payload[key];
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// 5. Return the modified part object. Mastra handles re-serialization
|
|
167
|
-
// for the outbound SSE client stream automatically.
|
|
168
|
-
return part;
|
|
169
|
-
}
|
|
170
|
-
}
|
package/src/server.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Express-layer plumbing for the Mastra plugin: a `MastraServer` that
|
|
3
|
-
* stamps the per-request `RequestContext
|
|
4
|
-
* that lets the plugin's custom API routes (e.g. `historyRoute`) work
|
|
5
|
-
* behind an Express mount point.
|
|
3
|
+
* stamps the per-request `RequestContext` and a scoped native API gate.
|
|
6
4
|
*
|
|
7
5
|
* @module
|
|
8
6
|
*/
|
|
@@ -44,6 +42,23 @@ import {
|
|
|
44
42
|
* attach feedback to.
|
|
45
43
|
*/
|
|
46
44
|
const INVALID_TRACE_ID = "0".repeat(32);
|
|
45
|
+
const TRUSTED_REQUEST_CONTEXT_KEYS = [
|
|
46
|
+
MASTRA_RESOURCE_ID_KEY,
|
|
47
|
+
MASTRA_THREAD_ID_KEY,
|
|
48
|
+
MASTRA_USER_KEY,
|
|
49
|
+
MASTRA_USER_NAME_KEY,
|
|
50
|
+
MASTRA_USER_EMAIL_KEY,
|
|
51
|
+
MASTRA_REQUEST_ID_KEY,
|
|
52
|
+
MASTRA_SCOPES_KEY,
|
|
53
|
+
MASTRA_MODEL_OVERRIDE_KEY,
|
|
54
|
+
] as const;
|
|
55
|
+
|
|
56
|
+
/** Remove browser-supplied values for fields owned by trusted server middleware. */
|
|
57
|
+
export function clearTrustedRequestContext(requestContext: RequestContext): void {
|
|
58
|
+
for (const key of TRUSTED_REQUEST_CONTEXT_KEYS) {
|
|
59
|
+
requestContext.deleteRaw(key);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
47
62
|
|
|
48
63
|
/**
|
|
49
64
|
* Who a turn is ATTRIBUTED to, independent of which Databricks credential runs
|
|
@@ -173,6 +188,7 @@ export class MastraServer extends ExpressMastraServer {
|
|
|
173
188
|
super.registerAuthMiddleware();
|
|
174
189
|
this.app.use(async (req, res, next) => {
|
|
175
190
|
const requestContext = res.locals.requestContext! as RequestContext;
|
|
191
|
+
clearTrustedRequestContext(requestContext);
|
|
176
192
|
await this.configureRequestContextUser(req, requestContext);
|
|
177
193
|
this.configureRequestContextThreadId(req, res, requestContext);
|
|
178
194
|
this.configureRequestContextModelOverride(req, requestContext);
|
|
@@ -268,7 +284,7 @@ export class MastraServer extends ExpressMastraServer {
|
|
|
268
284
|
/**
|
|
269
285
|
* Resolve the thread id this request targets and pin it on
|
|
270
286
|
* `RequestContext` (consumed by the agent stream for persistence and
|
|
271
|
-
* by
|
|
287
|
+
* by native memory routes). Resolution order:
|
|
272
288
|
*
|
|
273
289
|
* 1. A client-supplied thread id (the thread-selection header /
|
|
274
290
|
* `?threadId=` query). This is how the chat UI references a
|
|
@@ -365,26 +381,34 @@ export interface MastraApiGateOptions {
|
|
|
365
381
|
* prefix their `-generate` non-streaming variants), the `-network-` variants,
|
|
366
382
|
* and `resume-stream` (covers `resume-stream-until-idle`). Without these an
|
|
367
383
|
* approval-gated tool (e.g. `send_email`) can be requested but never approved
|
|
368
|
-
* from the browser - the resume `POST` 403s under scoped mode.
|
|
369
|
-
*
|
|
384
|
+
* from the browser - the resume `POST` 403s under scoped mode. Together with
|
|
385
|
+
* the resource-scoped memory mutations below, these are the only stock Mastra
|
|
386
|
+
* writes the browser client can make.
|
|
370
387
|
*/
|
|
371
388
|
const AGENT_INFERENCE =
|
|
372
389
|
/^\/agents\/[^/]+\/(stream|generate|network|resume-stream|approve-tool-call|decline-tool-call|approve-network-tool-call|decline-network-tool-call)/i;
|
|
373
390
|
|
|
374
391
|
/** Mount-relative read-only agent metadata (`/agents`, `/agents/:id`). */
|
|
375
392
|
const AGENT_METADATA = /^\/agents(\/[^/]+)?$/;
|
|
393
|
+
/** Persisted approval discovery for one agent. */
|
|
394
|
+
const AGENT_SUSPENDED_RUNS = /^\/agents\/[^/]+\/suspended-runs$/i;
|
|
395
|
+
/** Official AI SDK UI stream route, including `resumeData` continuations. */
|
|
396
|
+
const AGENT_CHAT = /^\/chat\/[^/]+$/i;
|
|
397
|
+
/** Native resource-scoped memory reads used by history and the thread list. */
|
|
398
|
+
const MEMORY_READ = /^\/memory\/threads(?:\/[^/]+(?:\/messages)?)?$/i;
|
|
399
|
+
/** Native thread rename/delete routes. */
|
|
400
|
+
const MEMORY_THREAD_MUTATION = /^\/memory\/threads\/[^/]+$/i;
|
|
376
401
|
|
|
377
402
|
/**
|
|
378
403
|
* Whether a request to the stock `@mastra/express` sub-app should be
|
|
379
404
|
* dispatched, given the configured {@link MastraApiGateOptions.access}.
|
|
380
405
|
*
|
|
381
406
|
* `path` is mount-relative (what the plugin's catch-all sees, e.g.
|
|
382
|
-
* `/
|
|
407
|
+
* `/chat/x`, `/memory/threads`, `/mcp/...`). In `"scoped"`
|
|
383
408
|
* mode the allowlist is deliberately tight - the chat client only ever
|
|
384
|
-
* needs agent inference, read-only agent metadata,
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
* denied by default rather than enumerated.
|
|
409
|
+
* needs agent inference, read-only agent metadata, resource-scoped memory,
|
|
410
|
+
* this plugin's own `/route/*` routes, and (when enabled) MCP. The remaining
|
|
411
|
+
* admin, mutating, and bulk-export surface stays denied by default.
|
|
388
412
|
*/
|
|
389
413
|
export function isMastraRequestAllowed(
|
|
390
414
|
method: string,
|
|
@@ -393,33 +417,31 @@ export function isMastraRequestAllowed(
|
|
|
393
417
|
): boolean {
|
|
394
418
|
if (opts.access === "full") return true;
|
|
395
419
|
const p = path.startsWith("/") ? path : `/${path}`;
|
|
396
|
-
//
|
|
397
|
-
//
|
|
420
|
+
// The plugin's `/route/*` additions validate their own inputs and trusted
|
|
421
|
+
// AppKit request context before reaching product behavior.
|
|
398
422
|
if (p === "/route" || p.startsWith("/route/")) return true;
|
|
399
423
|
if (opts.mcpEnabled && (p === "/mcp" || p.startsWith("/mcp/"))) return true;
|
|
400
424
|
const m = method.toUpperCase();
|
|
425
|
+
if (m === "POST" && AGENT_CHAT.test(p)) return true;
|
|
401
426
|
if (m === "POST" && AGENT_INFERENCE.test(p)) return true;
|
|
402
|
-
if (m === "GET" && AGENT_METADATA.test(p)) return true;
|
|
427
|
+
if (m === "GET" && (AGENT_METADATA.test(p) || AGENT_SUSPENDED_RUNS.test(p))) return true;
|
|
428
|
+
if (m === "GET" && MEMORY_READ.test(p)) return true;
|
|
429
|
+
if ((m === "PATCH" || m === "DELETE") && MEMORY_THREAD_MUTATION.test(p)) return true;
|
|
430
|
+
if (m === "POST" && p === "/memory/messages/delete") return true;
|
|
403
431
|
return false;
|
|
404
432
|
}
|
|
405
433
|
|
|
406
434
|
/**
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
* `MastraServer` is hosted on an Express subapp mounted under a parent
|
|
410
|
-
* path (e.g. `/api/mastra`).
|
|
411
|
-
*
|
|
412
|
-
* The adapter's `registerCustomApiRoutes` matches against `req.path`
|
|
413
|
-
* (mount-relative, correct) but dispatches to its internal Hono
|
|
414
|
-
* mini-app using `req.originalUrl`, which still contains the parent
|
|
415
|
-
* mount prefix. The Hono app registers the literal route paths
|
|
416
|
-
* (for example `/route/history`), so the absolute URL never matches
|
|
417
|
-
* until we overwrite `originalUrl` for `/route` and `/route/*` to the
|
|
418
|
-
* mount-relative path.
|
|
435
|
+
* Keep Mastra custom API routes mount-relative when the Express subapp is
|
|
436
|
+
* hosted under AppKit's `/api/<plugin>` path.
|
|
419
437
|
*/
|
|
420
438
|
export function attachRoutePatchMiddleware(app: express.Express): void {
|
|
421
439
|
app.use((req, _res, next) => {
|
|
422
|
-
const isCustomRoute =
|
|
440
|
+
const isCustomRoute =
|
|
441
|
+
req.path === "/chat" ||
|
|
442
|
+
req.path.startsWith("/chat/") ||
|
|
443
|
+
req.path === "/route" ||
|
|
444
|
+
req.path.startsWith("/route/");
|
|
423
445
|
if (!isCustomRoute) return next();
|
|
424
446
|
req.originalUrl = req.path;
|
|
425
447
|
next();
|
package/src/trace-io.ts
CHANGED
|
@@ -33,7 +33,7 @@ export const TRACE_IO_LIMIT = 8_000;
|
|
|
33
33
|
* are intentionally excluded: their bodies are tool decisions, not the
|
|
34
34
|
* user prompt, and they rarely produce a fresh answer worth surfacing.
|
|
35
35
|
*/
|
|
36
|
-
const AGENT_TURN_ROUTE =
|
|
36
|
+
const AGENT_TURN_ROUTE = /^(?:\/agents\/[^/]+\/(?:stream|generate)(?:\/|$)|\/chat\/[^/]+$)/i;
|
|
37
37
|
|
|
38
38
|
/** Attribute keys the MLflow UC `*_trace_unified` view reads from the root span. */
|
|
39
39
|
export const MLFLOW_SPAN_INPUTS_ATTR = "mlflow.spanInputs";
|
|
@@ -55,7 +55,12 @@ export function assistantTextFromSse(body: string): string {
|
|
|
55
55
|
// assistant text, so skipping them is the intended path rather than an error.
|
|
56
56
|
const frame = json.parse(line.slice(5));
|
|
57
57
|
if (!object.isRecord(frame) || frame.type !== "text-delta") continue;
|
|
58
|
-
const text =
|
|
58
|
+
const text =
|
|
59
|
+
typeof frame.delta === "string"
|
|
60
|
+
? frame.delta
|
|
61
|
+
: object.isRecord(frame.payload)
|
|
62
|
+
? frame.payload.text
|
|
63
|
+
: undefined;
|
|
59
64
|
if (typeof text === "string") parts.push(text);
|
|
60
65
|
}
|
|
61
66
|
return parts.join("");
|
package/src/writer.ts
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
|
|
@@ -13,10 +11,12 @@
|
|
|
13
11
|
*/
|
|
14
12
|
|
|
15
13
|
import { error, log } from "@dbx-tools/shared-core";
|
|
16
|
-
import type
|
|
14
|
+
import { GENIE_PROGRESS_PART_TYPE, type GenieWriterEvent } from "@dbx-tools/shared-mastra";
|
|
15
|
+
import type { ToolExecutionContext } from "@mastra/core/tools";
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
|
-
* Best-effort
|
|
18
|
+
* Best-effort native custom progress write. No-op when the writer or owning
|
|
19
|
+
* tool call id is unavailable;
|
|
20
20
|
* caught errors are logged via `log.warn("writer:error", ...)`
|
|
21
21
|
* along with any caller-supplied `context` fields (e.g. a
|
|
22
22
|
* `chartId` or `messageId`) so the warning is greppable per
|
|
@@ -24,18 +24,22 @@ import type { MastraWriter } from "@dbx-tools/shared-mastra";
|
|
|
24
24
|
*
|
|
25
25
|
* Returns when the write resolves or rejects; never throws.
|
|
26
26
|
*/
|
|
27
|
-
export async function
|
|
27
|
+
export async function safeWriteProgress(
|
|
28
28
|
log: log.Logger,
|
|
29
|
-
writer:
|
|
30
|
-
|
|
29
|
+
writer: ToolExecutionContext["writer"],
|
|
30
|
+
toolCallId: string | undefined,
|
|
31
|
+
event: GenieWriterEvent,
|
|
31
32
|
context: Record<string, unknown> = {},
|
|
32
33
|
): Promise<void> {
|
|
33
|
-
if (!writer) {
|
|
34
|
+
if (!writer || !toolCallId) {
|
|
34
35
|
log.debug("writer:no-writer", context);
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
38
|
try {
|
|
38
|
-
await writer.
|
|
39
|
+
await writer.custom({
|
|
40
|
+
type: GENIE_PROGRESS_PART_TYPE,
|
|
41
|
+
data: { toolCallId, event },
|
|
42
|
+
});
|
|
39
43
|
log.debug("writer:ok", context);
|
|
40
44
|
} catch (err) {
|
|
41
45
|
log.warn("writer:error", {
|
package/lib/src/history.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thread history loader exposed as a Mastra custom API route.
|
|
3
|
-
*
|
|
4
|
-
* Backed entirely by native Mastra: looks up the active agent by id,
|
|
5
|
-
* asks its `Memory` instance to `recall` a page of `MastraDBMessage`s,
|
|
6
|
-
* and converts the result to AI SDK V5 `UIMessage`s with the official
|
|
7
|
-
* {@link toAISdkV5Messages} helper from `@mastra/ai-sdk/ui`. No direct
|
|
8
|
-
* database reads.
|
|
9
|
-
*
|
|
10
|
-
* The route is registered through {@link historyRoute} as a Mastra
|
|
11
|
-
* `registerApiRoute` so it sits in the same dispatcher pipeline as
|
|
12
|
-
* the standard agent routes. That means the `MastraServer` auth
|
|
13
|
-
* middleware (in `./server.ts`) has already populated `RequestContext` with
|
|
14
|
-
* `MASTRA_THREAD_ID_KEY` and `MASTRA_RESOURCE_ID_KEY` by the time
|
|
15
|
-
* the handler runs - no cookie or user lookups happen here, and the
|
|
16
|
-
* session-cookie logic stays the single source of truth in `server.ts`.
|
|
17
|
-
*
|
|
18
|
-
* @module
|
|
19
|
-
*/
|
|
20
|
-
import type { MastraHistoryResponse } from "@dbx-tools/shared-mastra";
|
|
21
|
-
import type { Agent } from "@mastra/core/agent";
|
|
22
|
-
import { type AgentRouteOptions } from "./_agent-route-context.ts";
|
|
23
|
-
/** Inputs accepted by {@link loadHistory}. */
|
|
24
|
-
export interface LoadHistoryOptions {
|
|
25
|
-
agent: Agent;
|
|
26
|
-
threadId: string;
|
|
27
|
-
resourceId: string;
|
|
28
|
-
page?: number;
|
|
29
|
-
perPage?: number;
|
|
30
|
-
/** When true, returns the *oldest* page first (chronological). */
|
|
31
|
-
ascending?: boolean;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Fetch a page of UI-formatted messages for a thread.
|
|
35
|
-
*
|
|
36
|
-
* Uses the agent's resolved `Memory` (`getMemory()`) so per-agent
|
|
37
|
-
* storage namespaces (`mastra_<agentId>` schemas) and any future
|
|
38
|
-
* memory-side filters apply automatically. When the agent has no
|
|
39
|
-
* memory configured the response is a successful empty page so
|
|
40
|
-
* callers don't have to special-case stateless agents.
|
|
41
|
-
*
|
|
42
|
-
* Pagination is descending-by-default: page 0 is the most recent
|
|
43
|
-
* page, page 1 the page before that, etc. The returned `uiMessages`
|
|
44
|
-
* are always re-sorted into chronological order (oldest -> newest)
|
|
45
|
-
* so the client can prepend them above the existing transcript
|
|
46
|
-
* without sorting locally.
|
|
47
|
-
*/
|
|
48
|
-
export declare function loadHistory(opts: LoadHistoryOptions): Promise<MastraHistoryResponse>;
|
|
49
|
-
/** Inputs accepted by {@link clearHistory}. */
|
|
50
|
-
export interface ClearHistoryOptions {
|
|
51
|
-
agent: Agent;
|
|
52
|
-
threadId: string;
|
|
53
|
-
resourceId: string;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Wipe every persisted message tied to a thread. Returns the count
|
|
57
|
-
* of messages that were on the thread at delete time so the caller
|
|
58
|
-
* can render a "cleared N messages" affordance without an
|
|
59
|
-
* additional round-trip.
|
|
60
|
-
*
|
|
61
|
-
* Agents without a configured `Memory` resolve to a no-op (count
|
|
62
|
-
* 0), matching {@link loadHistory}'s "stateless agents return an
|
|
63
|
-
* empty page" stance so callers don't have to special-case them.
|
|
64
|
-
* Threads that don't exist yet are also a successful no-op - the
|
|
65
|
-
* operation is idempotent so the UI can fire-and-forget without
|
|
66
|
-
* tracking thread existence.
|
|
67
|
-
*/
|
|
68
|
-
export declare function clearHistory(opts: ClearHistoryOptions): Promise<{
|
|
69
|
-
cleared: number;
|
|
70
|
-
}>;
|
|
71
|
-
/** Options accepted by {@link historyRoute}. */
|
|
72
|
-
export type HistoryRouteOptions = AgentRouteOptions;
|
|
73
|
-
/**
|
|
74
|
-
* Register the `<path>` Mastra custom API route. Handles two
|
|
75
|
-
* methods on the same mount:
|
|
76
|
-
*
|
|
77
|
-
* - `GET`: return a page of AI SDK V5 `UIMessage`s for the
|
|
78
|
-
* caller's current thread ({@link loadHistory}).
|
|
79
|
-
* - `DELETE`: wipe every persisted message on the caller's
|
|
80
|
-
* thread ({@link clearHistory}). The session cookie that
|
|
81
|
-
* anchors the thread id is left alone so the user keeps the
|
|
82
|
-
* same thread - only the contents go away.
|
|
83
|
-
*
|
|
84
|
-
* Follows the `@mastra/ai-sdk` `chatRoute` convention for agent
|
|
85
|
-
* binding: pass `agent` for a fixed-agent mount, or include
|
|
86
|
-
* `:agentId` in the path for dynamic routing. The plugin registers
|
|
87
|
-
* both `/route/history` (default agent) and `/route/history/:agentId`.
|
|
88
|
-
*
|
|
89
|
-
* The handler reads `threadId` and `resourceId` from `RequestContext`
|
|
90
|
-
* (populated upstream by `MastraServer.registerAuthMiddleware`), so
|
|
91
|
-
* no cookie or user lookups happen here.
|
|
92
|
-
*/
|
|
93
|
-
export declare function historyRoute(options: HistoryRouteOptions): import("@mastra/core/server").ApiRoute[];
|