@mastra/server 1.84.0-alpha.4 → 1.84.0-alpha.5

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.
Files changed (36) hide show
  1. package/dist/agent-controller-DHzp0yHo.js +1910 -0
  2. package/dist/agent-controller-DHzp0yHo.js.map +1 -0
  3. package/dist/agent-controller-Dwtk-Oi1.cjs +2131 -0
  4. package/dist/agent-controller-Dwtk-Oi1.cjs.map +1 -0
  5. package/dist/{api-schema-manifest-CAXT81dM.js → api-schema-manifest-C889XFn5.js} +2 -2
  6. package/dist/{api-schema-manifest-CAXT81dM.js.map → api-schema-manifest-C889XFn5.js.map} +1 -1
  7. package/dist/{api-schema-manifest-BdpqONHU.cjs → api-schema-manifest-Cn9tPyZh.cjs} +2 -2
  8. package/dist/{api-schema-manifest-BdpqONHU.cjs.map → api-schema-manifest-Cn9tPyZh.cjs.map} +1 -1
  9. package/dist/{catalogue-CpTFH24l.js → catalogue-C2Frc4-i.js} +3 -3
  10. package/dist/{catalogue-CpTFH24l.js.map → catalogue-C2Frc4-i.js.map} +1 -1
  11. package/dist/{catalogue-Cnb2A1bK.cjs → catalogue-COgS_54R.cjs} +3 -3
  12. package/dist/{catalogue-Cnb2A1bK.cjs.map → catalogue-COgS_54R.cjs.map} +1 -1
  13. package/dist/docs/SKILL.md +1 -1
  14. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  15. package/dist/{routes-8_3X8t-L.js → routes-DGoYe50m.js} +3 -3
  16. package/dist/{routes-8_3X8t-L.js.map → routes-DGoYe50m.js.map} +1 -1
  17. package/dist/{routes-C76k7FKk.cjs → routes-pkh0aVDt.cjs} +39 -39
  18. package/dist/{routes-C76k7FKk.cjs.map → routes-pkh0aVDt.cjs.map} +1 -1
  19. package/dist/server/handlers/agent-controller.cjs +37 -1793
  20. package/dist/server/handlers/agent-controller.d.ts.map +1 -1
  21. package/dist/server/handlers/agent-controller.js +1 -1758
  22. package/dist/server/handlers/system.cjs +1 -1
  23. package/dist/server/handlers/system.js +1 -1
  24. package/dist/server/server-adapter/index.cjs +4 -3
  25. package/dist/server/server-adapter/index.js +3 -2
  26. package/dist/server/server-adapter/serialize.d.ts +6 -0
  27. package/dist/server/server-adapter/serialize.d.ts.map +1 -1
  28. package/dist/{server-adapter-BhDR1wnp.cjs → server-adapter-9QWRzNZI.cjs} +3 -84
  29. package/dist/server-adapter-9QWRzNZI.cjs.map +1 -0
  30. package/dist/{server-adapter-BCeL96pF.js → server-adapter-CB8qI6YQ.js} +4 -79
  31. package/dist/server-adapter-CB8qI6YQ.js.map +1 -0
  32. package/package.json +5 -5
  33. package/dist/server/handlers/agent-controller.cjs.map +0 -1
  34. package/dist/server/handlers/agent-controller.js.map +0 -1
  35. package/dist/server-adapter-BCeL96pF.js.map +0 -1
  36. package/dist/server-adapter-BhDR1wnp.cjs.map +0 -1
@@ -0,0 +1,2131 @@
1
+ const require_constants = require("./constants-1yTmKUZD.cjs");
2
+ const require_utils = require("./utils-DFhesFfA.cjs");
3
+ const require_http_exception = require("./http-exception-Co3MbFUf.cjs");
4
+ const require_memory = require("./memory--xJDrSwF.cjs");
5
+ const require_route_builder = require("./route-builder-DjTBxSZN.cjs");
6
+ const require_server_handlers_error = require("./server/handlers/error.cjs");
7
+ let zod_v4 = require("zod/v4");
8
+ let _mastra_core_error = require("@mastra/core/error");
9
+ let _mastra_core_utils = require("@mastra/core/utils");
10
+ let _mastra_core_storage = require("@mastra/core/storage");
11
+ // src/server/server-adapter/serialize.ts
12
+ /** Chunks marked by {@link shareStreamChunk}, with their JSON once the first stream serializes them. */
13
+ const sharedChunks = /* @__PURE__ */ new WeakMap();
14
+ /**
15
+ * Mark a chunk that is enqueued, unchanged, on several streams so it is
16
+ * serialized once instead of once per stream. The chunk must not be mutated
17
+ * afterwards: every stream receives the JSON of its first serialization.
18
+ */
19
+ function shareStreamChunk(chunk) {
20
+ if (!sharedChunks.has(chunk)) sharedChunks.set(chunk, void 0);
21
+ return chunk;
22
+ }
23
+ /**
24
+ * Serializes a stream chunk to JSON for wire transport.
25
+ *
26
+ * Stream chunks can contain values that plain `JSON.stringify` throws on
27
+ * (e.g. BigInt produced by zod coercions/transforms in structuredOutput
28
+ * schemas, or circular references) — `safeStringify` handles those. A single
29
+ * bad chunk must never kill the whole stream — Studio relies on later chunks
30
+ * (`workflow-step-result`, `workflow-finish`) to render run state.
31
+ *
32
+ * Returns `{ ok: false, error }` if the chunk cannot be serialized at all
33
+ * (e.g. a throwing getter/toJSON) — callers should log the error, skip the
34
+ * chunk, and keep streaming.
35
+ */
36
+ function serializeStreamChunk(chunk) {
37
+ const shared = typeof chunk === "object" && chunk !== null && sharedChunks.has(chunk);
38
+ if (shared) {
39
+ const serialized = sharedChunks.get(chunk);
40
+ if (serialized) return serialized;
41
+ }
42
+ let serialized;
43
+ try {
44
+ serialized = {
45
+ ok: true,
46
+ json: (0, _mastra_core_utils.safeStringify)(withPlainPayloadError(chunk))
47
+ };
48
+ } catch (error) {
49
+ serialized = {
50
+ ok: false,
51
+ error: error instanceof Error ? error : new Error(String(error))
52
+ };
53
+ }
54
+ if (shared) sharedChunks.set(chunk, serialized);
55
+ return serialized;
56
+ }
57
+ /**
58
+ * `JSON.stringify(new Error('x'))` keeps only own enumerable fields, so an Error subclass that sets `name`
59
+ * arrives as `{ name }` and clients show `[object Object]`. Send the message too; never the stack. An
60
+ * error whose class curates its JSON (`toJSON`, e.g. MastraError) keeps that shape, so fields it leaves
61
+ * out stay out.
62
+ */
63
+ function withPlainPayloadError(chunk) {
64
+ if (!chunk || typeof chunk !== "object" || !("payload" in chunk)) return chunk;
65
+ const { payload } = chunk;
66
+ if (!payload || typeof payload !== "object" || !("error" in payload)) return chunk;
67
+ const { error } = payload;
68
+ if (!(error instanceof Error)) return withoutStack(chunk, payload, error);
69
+ const plain = {
70
+ ...curatedJson(error) ?? error,
71
+ message: error.message
72
+ };
73
+ delete plain.stack;
74
+ if (!plain.name && error.name !== "Error") plain.name = error.name;
75
+ return {
76
+ ...chunk,
77
+ payload: {
78
+ ...payload,
79
+ error: plain
80
+ }
81
+ };
82
+ }
83
+ /** An error that is already a plain object (a replayed one) is kept as is, minus its stack. */
84
+ function withoutStack(chunk, payload, error) {
85
+ if (!error || typeof error !== "object" || Array.isArray(error) || !("stack" in error)) return chunk;
86
+ const { stack: _stack, ...rest } = error;
87
+ return {
88
+ ...chunk,
89
+ payload: {
90
+ ...payload,
91
+ error: rest
92
+ }
93
+ };
94
+ }
95
+ function curatedJson(error) {
96
+ const toJSON = error.toJSON;
97
+ if (typeof toJSON !== "function") return void 0;
98
+ try {
99
+ const json = toJSON.call(error);
100
+ return json && typeof json === "object" ? json : void 0;
101
+ } catch {
102
+ return;
103
+ }
104
+ }
105
+ // src/server/handlers/agent-controller.ts
106
+ /**
107
+ * AgentController session routes.
108
+ *
109
+ * An AgentController registered on a Mastra instance (via
110
+ * `new Mastra({ agentControllers })`) exposes its sessions over HTTP so
111
+ * non-terminal clients — e.g. a browser-based MastraCode — can create sessions,
112
+ * send messages, stream events, and drive run-control. Each route resolves its
113
+ * target AgentController by id, then operates on the session addressed by
114
+ * `sessionId` (which works on the threads and memory of its `resourceId`).
115
+ * Mutating routes use get-or-create resolution so reconnects
116
+ * resume rather than fork the conversation; read routes only inspect existing
117
+ * live sessions.
118
+ */
119
+ /**
120
+ * Internal thread-metadata keys that `Session.loadMetadata()` reads back as
121
+ * runtime bookkeeping (selected model/mode, observer/reflector config, token
122
+ * usage). They share the flat thread `metadata` bag with user-provided session
123
+ * scoping tags, so they must never be treated as tags here.
124
+ *
125
+ * Importing core's list as a value would exceed this package's peer-dependency
126
+ * floor, so it is mirrored under `satisfies`: tsc rejects a missing or extra key.
127
+ */
128
+ const RESERVED_THREAD_METADATA_KEYS = {
129
+ currentModelId: true,
130
+ modelPersistenceVersion: true,
131
+ currentModeId: true,
132
+ observerModelId: true,
133
+ reflectorModelId: true,
134
+ observerModelSelection: true,
135
+ reflectorModelSelection: true,
136
+ observationThreshold: true,
137
+ reflectionThreshold: true,
138
+ tokenUsage: true,
139
+ ownerId: true,
140
+ createdBy: true,
141
+ thinkingLevel: true,
142
+ notifications: true,
143
+ permissionRules: true
144
+ };
145
+ function isReservedThreadMetadataKey(key) {
146
+ return Object.hasOwn(RESERVED_THREAD_METADATA_KEYS, key) || key.startsWith("modeModelId_");
147
+ }
148
+ function storageTagFilter(tags) {
149
+ try {
150
+ return (0, _mastra_core_storage.validateStorageMetadataFilter)(tags);
151
+ } catch {
152
+ return;
153
+ }
154
+ }
155
+ function getRequestMessageAuthor(requestContext) {
156
+ const user = requestContext?.get(require_constants.MASTRA_USER_KEY);
157
+ if (!user || typeof user !== "object" || Array.isArray(user)) return void 0;
158
+ const id = user.id;
159
+ return typeof id === "string" && id ? { id } : void 0;
160
+ }
161
+ /**
162
+ * Resolves a controller by id via the canonical `mastra.getAgentController`
163
+ * accessor, throwing a 404 if no controller is registered under that id.
164
+ */
165
+ function getAgentControllerOrThrow(mastra, controllerId) {
166
+ const controller = mastra.getAgentController?.(controllerId);
167
+ if (!controller) throw new require_http_exception.HTTPException(404, { message: `agent controller "${controllerId}" not found` });
168
+ return controller;
169
+ }
170
+ /**
171
+ * The resource of the session addressed by `sessionId`, without materializing
172
+ * it: the live session's resource, else the resource of the thread sharing the
173
+ * session's id, else `sessionId` itself (the default when a session is created
174
+ * without a `sessionId`).
175
+ */
176
+ async function resolveSessionResourceId(controller, sessionId) {
177
+ const live = await controller.getSession(sessionId);
178
+ if (live) return live.identity.getResourceId();
179
+ return (await controller.queryThreadById({ threadId: sessionId }))?.resourceId ?? sessionId;
180
+ }
181
+ /**
182
+ * Resolve the session addressed by `sessionId` that every route other than create acts on: the live one, or a
183
+ * lost one (e.g. after a restart) rebuilt from storage. When a thread with the session's id exists, the session
184
+ * resumes on that thread under the thread's resource (hosts that use `sessionId === threadId` recover their own
185
+ * thread even when many sessions share one resource); otherwise it resumes on `resourceId = sessionId`, the
186
+ * default `POST /sessions` applies when no `sessionId` is sent. Never starts a conversation, so a write that
187
+ * arrives before the session was started fails instead of landing on a thread nobody reads.
188
+ */
189
+ async function getSession(controller, sessionId, requestContext) {
190
+ await controller.init();
191
+ const live = await controller.getSession(sessionId);
192
+ const thread = live ? null : await controller.queryThreadById({ threadId: sessionId });
193
+ try {
194
+ return await controller.createSession({
195
+ id: sessionId,
196
+ resourceId: live?.identity.getResourceId() ?? thread?.resourceId ?? sessionId,
197
+ ownerId: controller.id,
198
+ threadId: thread ? sessionId : void 0,
199
+ resumeOnly: true,
200
+ requestContext
201
+ });
202
+ } catch (error) {
203
+ if (error instanceof Error && error.code === "SESSION_NOT_STARTED") throw new require_http_exception.HTTPException(404, {
204
+ message: `No session "${sessionId}" has been started. Create it with POST /agent-controller/:controllerId/sessions first.`,
205
+ cause: error
206
+ });
207
+ throw error;
208
+ }
209
+ }
210
+ async function getExistingSession(controller, sessionId, requestContext) {
211
+ await controller.init();
212
+ const session = await controller.getSession(sessionId, requestContext);
213
+ if (session) return session;
214
+ return getSession(controller, sessionId, requestContext);
215
+ }
216
+ /**
217
+ * Acknowledges a session operation that keeps running after the response is
218
+ * sent.
219
+ *
220
+ * The messages/steer/follow-up routes answer `{ ok: true }` as soon as the
221
+ * message is handed to the session: the reply itself arrives on the session's
222
+ * SSE stream, so the request must not block for the whole turn. Those session
223
+ * methods can still reject — `sendMessage` deliberately rejects when signal
224
+ * submission fails before a stream starts — and a bare `void promise` turns
225
+ * that into an unhandled rejection, which terminates the process on Node's
226
+ * default `--unhandled-rejections=throw`.
227
+ *
228
+ * Observing the promise keeps the immediate acknowledgement while logging the
229
+ * failure and emitting an `error` event on the session, so a client streaming
230
+ * the session is told the turn died instead of waiting for an `agent_end` that
231
+ * will never come.
232
+ */
233
+ function ackBackgroundSessionWork({ work, session, mastra, operation }) {
234
+ work.catch((error) => {
235
+ const failure = error instanceof Error ? error : new Error(String(error));
236
+ mastra.getLogger?.()?.error?.(`AgentController ${operation} failed after the request was acknowledged`, {
237
+ operation,
238
+ error: failure
239
+ });
240
+ try {
241
+ session.emit({
242
+ type: "error",
243
+ error: failure
244
+ });
245
+ } catch {}
246
+ });
247
+ }
248
+ const controllerIdPathParams = zod_v4.z.object({ controllerId: zod_v4.z.string() });
249
+ const sessionPathParams = zod_v4.z.object({
250
+ controllerId: zod_v4.z.string(),
251
+ sessionId: zod_v4.z.string()
252
+ });
253
+ /**
254
+ * Sessions used to be addressed by `resourceId` plus `sessionScope`. The param is gone: reject it
255
+ * rather than drop it, so an older client's scoped session can't quietly merge into another one.
256
+ */
257
+ const removedSessionScope = zod_v4.z.never({ error: "sessionScope was removed; address the session by sessionId" }).optional();
258
+ const sessionQuerySchema = zod_v4.z.object({ sessionScope: removedSessionScope });
259
+ const sessionStateQuerySchema = sessionQuerySchema.extend({ threadId: zod_v4.z.string().optional() });
260
+ const createSessionBodySchema = zod_v4.z.object({
261
+ /**
262
+ * Whose threads and memory the session works on. Optional when `sessionId` is
263
+ * sent: the session then resumes on the resource it already has (the live
264
+ * session's, or the resource of the thread with the session's id), falling
265
+ * back to the session id.
266
+ */
267
+ resourceId: zod_v4.z.string().optional(),
268
+ /** Address of the session. Defaults to `resourceId`. */
269
+ sessionId: zod_v4.z.string().optional(),
270
+ sessionScope: removedSessionScope,
271
+ tags: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.string()).optional(),
272
+ threadId: zod_v4.z.string().optional()
273
+ }).refine((body) => body.resourceId !== void 0 || body.sessionId !== void 0, { message: "resourceId or sessionId is required" });
274
+ const MAX_FILE_DATA_LENGTH = 14680064;
275
+ const MAX_TOTAL_FILE_DATA_LENGTH = 29360128;
276
+ /**
277
+ * Optional client-supplied request context, merged into the server-derived
278
+ * request context by the adapter context middleware (reserved keys are
279
+ * server-controlled). Declared on run-triggering body schemas so the OpenAPI
280
+ * spec documents it.
281
+ */
282
+ const bodyRequestContextSchema = zod_v4.z.record(zod_v4.z.string(), zod_v4.z.unknown()).optional();
283
+ const messageFilesSchema = zod_v4.z.array(zod_v4.z.object({
284
+ data: zod_v4.z.string().max(MAX_FILE_DATA_LENGTH),
285
+ mediaType: zod_v4.z.string(),
286
+ filename: zod_v4.z.string().optional()
287
+ })).max(20).refine((files) => files.reduce((total, file) => total + file.data.length, 0) <= MAX_TOTAL_FILE_DATA_LENGTH, { message: "Total attachment size exceeds limit" }).optional();
288
+ const sendMessageBodySchema = zod_v4.z.object({
289
+ message: zod_v4.z.string(),
290
+ requestContext: bodyRequestContextSchema,
291
+ files: messageFilesSchema
292
+ });
293
+ const steerBodySchema = zod_v4.z.object({
294
+ message: zod_v4.z.string(),
295
+ requestContext: bodyRequestContextSchema,
296
+ files: messageFilesSchema
297
+ });
298
+ const toolApprovalBodySchema = zod_v4.z.object({
299
+ toolCallId: zod_v4.z.string(),
300
+ approved: zod_v4.z.boolean(),
301
+ /**
302
+ * Grants the gated tool's category to the thread that owns the call, then
303
+ * approves — the same "always allow" the in-process TUI offers. Requires
304
+ * `approved: true`.
305
+ */
306
+ alwaysAllowCategory: zod_v4.z.boolean().optional(),
307
+ requestContext: bodyRequestContextSchema
308
+ }).refine((body) => !body.alwaysAllowCategory || body.approved, {
309
+ message: "alwaysAllowCategory requires approved: true",
310
+ path: ["alwaysAllowCategory"]
311
+ });
312
+ const toolSuspensionBodySchema = zod_v4.z.object({
313
+ toolCallId: zod_v4.z.string().min(1),
314
+ runId: zod_v4.z.string().min(1).optional(),
315
+ resumeData: zod_v4.z.unknown(),
316
+ requestContext: bodyRequestContextSchema
317
+ });
318
+ const switchModeBodySchema = zod_v4.z.object({ modeId: zod_v4.z.string() });
319
+ const switchModelBodySchema = zod_v4.z.object({
320
+ modelId: zod_v4.z.string(),
321
+ thinkingLevel: zod_v4.z.enum([
322
+ "off",
323
+ "low",
324
+ "medium",
325
+ "high",
326
+ "xhigh",
327
+ "max"
328
+ ]).optional()
329
+ });
330
+ const switchThreadBodySchema = zod_v4.z.object({ threadId: zod_v4.z.string() });
331
+ const createThreadBodySchema = zod_v4.z.object({ title: zod_v4.z.string().optional() });
332
+ const renameThreadBodySchema = zod_v4.z.object({ title: zod_v4.z.string() });
333
+ const threadPathParams = zod_v4.z.object({
334
+ controllerId: zod_v4.z.string(),
335
+ sessionId: zod_v4.z.string(),
336
+ threadId: zod_v4.z.string()
337
+ });
338
+ const cloneThreadBodySchema = zod_v4.z.object({
339
+ sourceThreadId: zod_v4.z.string().optional(),
340
+ title: zod_v4.z.string().optional()
341
+ });
342
+ const controllerPaginationNumber = zod_v4.z.coerce.number().int().min(0);
343
+ const listMessagesQuerySchema = zod_v4.z.object({
344
+ sessionScope: removedSessionScope,
345
+ /** @deprecated Use page and perPage instead. */
346
+ limit: controllerPaginationNumber.optional(),
347
+ page: controllerPaginationNumber.optional(),
348
+ perPage: zod_v4.z.preprocess((value) => value === "false" ? false : value, zod_v4.z.union([zod_v4.z.literal(false), controllerPaginationNumber])).optional(),
349
+ orderBy: require_memory.messageOrderBySchema,
350
+ include: require_memory.includeSchema,
351
+ filter: require_memory.filterSchema
352
+ }).superRefine((value, ctx) => {
353
+ if (value.limit === void 0) return;
354
+ for (const field of [
355
+ "perPage",
356
+ "orderBy",
357
+ "include",
358
+ "filter"
359
+ ]) if (value[field] !== void 0) ctx.addIssue({
360
+ code: "custom",
361
+ message: `limit cannot be combined with ${field}; use perPage instead`,
362
+ path: ["limit"]
363
+ });
364
+ });
365
+ /**
366
+ * `tags` arrives as a JSON-encoded object in the query string (query params are
367
+ * flat strings). It scopes the listing to threads whose metadata matches every
368
+ * tag — e.g. `{ projectPath }` so git worktrees sharing a resourceId each see
369
+ * only their own threads. Malformed JSON is treated as "no filter".
370
+ */
371
+ const listThreadsQuerySchema = zod_v4.z.object({
372
+ sessionScope: removedSessionScope,
373
+ limit: zod_v4.z.coerce.number().optional(),
374
+ tags: zod_v4.z.preprocess((value) => {
375
+ if (typeof value !== "string" || value.length === 0) return void 0;
376
+ try {
377
+ return JSON.parse(value);
378
+ } catch {
379
+ return;
380
+ }
381
+ }, zod_v4.z.record(zod_v4.z.string(), zod_v4.z.string()).optional()).optional()
382
+ });
383
+ const followUpBodySchema = zod_v4.z.object({
384
+ message: zod_v4.z.string(),
385
+ requestContext: bodyRequestContextSchema,
386
+ files: messageFilesSchema
387
+ });
388
+ const sendNotificationBodySchema = zod_v4.z.object({
389
+ source: zod_v4.z.string(),
390
+ kind: zod_v4.z.string(),
391
+ summary: zod_v4.z.string(),
392
+ priority: zod_v4.z.enum([
393
+ "low",
394
+ "medium",
395
+ "high",
396
+ "urgent"
397
+ ]).optional(),
398
+ payload: zod_v4.z.unknown().optional(),
399
+ sourceId: zod_v4.z.string().optional(),
400
+ dedupeKey: zod_v4.z.string().optional(),
401
+ coalesceKey: zod_v4.z.string().optional(),
402
+ attributes: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.unknown()).optional(),
403
+ metadata: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.unknown()).optional()
404
+ });
405
+ const listAgentControllersResponseSchema = zod_v4.z.object({ agentControllers: zod_v4.z.array(zod_v4.z.object({ id: zod_v4.z.string() })) });
406
+ const createSessionResponseSchema = zod_v4.z.object({
407
+ controllerId: zod_v4.z.string(),
408
+ sessionId: zod_v4.z.string(),
409
+ resourceId: zod_v4.z.string(),
410
+ threadId: zod_v4.z.string().optional()
411
+ });
412
+ const ackResponseSchema = zod_v4.z.object({ ok: zod_v4.z.boolean() });
413
+ const transferOwnershipResponseSchema = ackResponseSchema.extend({ ownerId: zod_v4.z.string() });
414
+ const toolCommandAckResponseSchema = zod_v4.z.object({
415
+ ok: zod_v4.z.boolean(),
416
+ reason: zod_v4.z.enum([
417
+ "not_pending",
418
+ "stale_tool_call",
419
+ "aborting",
420
+ "no_pending_suspension"
421
+ ]).optional()
422
+ });
423
+ /**
424
+ * Status-line relevant slice of the session's observational-memory progress.
425
+ * Mirrors the TUI status line: `msg pending/threshold ↓removal` (the active
426
+ * message window before an observation fires) and `mem observed/reflection
427
+ * ↓savings` (accumulated observations before a reflection fires).
428
+ */
429
+ const omProgressSummarySchema = zod_v4.z.object({
430
+ status: zod_v4.z.string(),
431
+ pendingTokens: zod_v4.z.number(),
432
+ threshold: zod_v4.z.number(),
433
+ thresholdPercent: zod_v4.z.number(),
434
+ observationTokens: zod_v4.z.number(),
435
+ reflectionThreshold: zod_v4.z.number(),
436
+ reflectionThresholdPercent: zod_v4.z.number(),
437
+ /** Tokens the next observation will remove from the message window. */
438
+ projectedMessageRemoval: zod_v4.z.number(),
439
+ /** Tokens the next reflection is projected to save. */
440
+ projectedReflectionSavings: zod_v4.z.number()
441
+ });
442
+ const tokenUsageSchema = zod_v4.z.object({
443
+ promptTokens: zod_v4.z.number(),
444
+ completionTokens: zod_v4.z.number(),
445
+ totalTokens: zod_v4.z.number(),
446
+ reasoningTokens: zod_v4.z.number().optional(),
447
+ cachedInputTokens: zod_v4.z.number().optional(),
448
+ cacheCreationInputTokens: zod_v4.z.number().optional(),
449
+ cacheCreationInputTokens5m: zod_v4.z.number().optional(),
450
+ cacheCreationInputTokens1h: zod_v4.z.number().optional(),
451
+ raw: zod_v4.z.unknown().optional()
452
+ });
453
+ const sessionSettingsSchema = zod_v4.z.object({
454
+ yolo: zod_v4.z.boolean(),
455
+ /** Session override only — absent when the session inherits a configured default. */
456
+ thinkingLevel: zod_v4.z.enum([
457
+ "off",
458
+ "low",
459
+ "medium",
460
+ "high",
461
+ "xhigh",
462
+ "max"
463
+ ]).optional(),
464
+ notifications: zod_v4.z.enum([
465
+ "off",
466
+ "bell",
467
+ "system",
468
+ "both"
469
+ ]),
470
+ smartEditing: zod_v4.z.boolean()
471
+ });
472
+ const taskSnapshotSchema = zod_v4.z.object({
473
+ id: zod_v4.z.string(),
474
+ content: zod_v4.z.string(),
475
+ status: zod_v4.z.enum([
476
+ "pending",
477
+ "in_progress",
478
+ "completed"
479
+ ]),
480
+ activeForm: zod_v4.z.string()
481
+ });
482
+ const sessionStateResponseSchema = zod_v4.z.object({
483
+ controllerId: zod_v4.z.string(),
484
+ sessionId: zod_v4.z.string(),
485
+ resourceId: zod_v4.z.string(),
486
+ threadId: zod_v4.z.string().optional(),
487
+ modeId: zod_v4.z.string(),
488
+ modelId: zod_v4.z.string(),
489
+ /** Whether the agent is currently executing a run (for initial UI hydration). */
490
+ running: zod_v4.z.boolean().optional(),
491
+ tasks: zod_v4.z.array(taskSnapshotSchema).optional(),
492
+ omProgress: omProgressSummarySchema.optional(),
493
+ tokenUsage: tokenUsageSchema.optional(),
494
+ settings: sessionSettingsSchema.optional()
495
+ });
496
+ const listModesResponseSchema = zod_v4.z.object({ modes: zod_v4.z.array(zod_v4.z.object({
497
+ id: zod_v4.z.string(),
498
+ name: zod_v4.z.string().optional()
499
+ })) });
500
+ const listThreadsResponseSchema = zod_v4.z.object({ threads: zod_v4.z.array(zod_v4.z.object({
501
+ id: zod_v4.z.string(),
502
+ title: zod_v4.z.string().optional(),
503
+ updatedAt: zod_v4.z.string().optional(),
504
+ /** The session scoping tags stamped on this thread (e.g. `{ projectPath }`). */
505
+ tags: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.string()).optional(),
506
+ /** Whether a run is currently executing on this thread ('active') or not ('idle'). */
507
+ state: zod_v4.z.enum(["active", "idle"]).optional()
508
+ })) });
509
+ const threadResponseSchema = zod_v4.z.object({
510
+ id: zod_v4.z.string(),
511
+ title: zod_v4.z.string().optional(),
512
+ resourceId: zod_v4.z.string().optional(),
513
+ createdAt: zod_v4.z.string().optional(),
514
+ updatedAt: zod_v4.z.string().optional()
515
+ });
516
+ const messagePartSchema = zod_v4.z.object({ type: zod_v4.z.string() }).passthrough();
517
+ const messageContentV2Schema = zod_v4.z.object({
518
+ format: zod_v4.z.literal(2),
519
+ parts: zod_v4.z.array(messagePartSchema)
520
+ }).passthrough();
521
+ const listMessagesResponseSchema = zod_v4.z.object({
522
+ messages: zod_v4.z.array(zod_v4.z.object({
523
+ id: zod_v4.z.string(),
524
+ role: zod_v4.z.enum([
525
+ "user",
526
+ "assistant",
527
+ "system",
528
+ "tool",
529
+ "signal"
530
+ ]),
531
+ content: messageContentV2Schema,
532
+ createdAt: zod_v4.z.string().optional(),
533
+ threadId: zod_v4.z.string().optional(),
534
+ resourceId: zod_v4.z.string().optional(),
535
+ type: zod_v4.z.string().optional()
536
+ })),
537
+ total: zod_v4.z.number(),
538
+ page: zod_v4.z.number(),
539
+ perPage: zod_v4.z.union([zod_v4.z.number(), zod_v4.z.literal(false)]),
540
+ hasMore: zod_v4.z.boolean()
541
+ });
542
+ const listModelsResponseSchema = zod_v4.z.object({ models: zod_v4.z.array(zod_v4.z.object({
543
+ id: zod_v4.z.string(),
544
+ provider: zod_v4.z.string(),
545
+ modelName: zod_v4.z.string(),
546
+ releaseDate: zod_v4.z.string().optional(),
547
+ hasApiKey: zod_v4.z.boolean(),
548
+ useCount: zod_v4.z.number()
549
+ })) });
550
+ const workspaceStatusResponseSchema = zod_v4.z.object({
551
+ hasWorkspace: zod_v4.z.boolean(),
552
+ isReady: zod_v4.z.boolean()
553
+ });
554
+ const omRecordResponseSchema = zod_v4.z.object({ record: zod_v4.z.unknown().optional() });
555
+ const permissionPolicyEnum = zod_v4.z.enum([
556
+ "allow",
557
+ "ask",
558
+ "deny"
559
+ ]);
560
+ const toolCategoryEnum = zod_v4.z.enum([
561
+ "read",
562
+ "edit",
563
+ "execute",
564
+ "mcp",
565
+ "other"
566
+ ]);
567
+ const permissionRulesResponseSchema = zod_v4.z.object({
568
+ categories: zod_v4.z.record(zod_v4.z.string(), permissionPolicyEnum).optional(),
569
+ tools: zod_v4.z.record(zod_v4.z.string(), permissionPolicyEnum).optional()
570
+ });
571
+ const setCategoryPermissionBodySchema = zod_v4.z.object({
572
+ category: toolCategoryEnum,
573
+ policy: permissionPolicyEnum
574
+ });
575
+ const setToolPermissionBodySchema = zod_v4.z.object({
576
+ toolName: zod_v4.z.string(),
577
+ policy: permissionPolicyEnum
578
+ });
579
+ const LIST_AGENT_CONTROLLERS_ROUTE = require_route_builder.createRoute({
580
+ method: "GET",
581
+ path: "/agent-controller",
582
+ responseType: "json",
583
+ responseSchema: listAgentControllersResponseSchema,
584
+ summary: "List agent controllers",
585
+ description: "Lists the agent controllers hosted on this Mastra instance.",
586
+ tags: ["AgentController"],
587
+ requiresAuth: true,
588
+ requiresPermission: "agent-controller:read",
589
+ handler: async ({ mastra }) => {
590
+ try {
591
+ const ids = /* @__PURE__ */ new Set();
592
+ if (mastra.listAgentControllers) for (const id of Object.keys(mastra.listAgentControllers())) ids.add(id);
593
+ return { agentControllers: Array.from(ids).map((id) => ({ id })) };
594
+ } catch (error) {
595
+ return require_server_handlers_error.handleError(error, "error listing agent controllers");
596
+ }
597
+ }
598
+ });
599
+ const CREATE_AGENT_CONTROLLER_SESSION_ROUTE = require_route_builder.createRoute({
600
+ method: "POST",
601
+ path: "/agent-controller/:controllerId/sessions",
602
+ queryParamSchema: sessionQuerySchema,
603
+ responseType: "json",
604
+ pathParamSchema: controllerIdPathParams,
605
+ bodySchema: createSessionBodySchema,
606
+ responseSchema: createSessionResponseSchema,
607
+ summary: "Create or resume a controller session",
608
+ description: "Creates the session addressed by `sessionId` on the given resourceId, or returns the existing one (get-or-create), so reconnects resume the conversation. Without a `sessionId` the session is addressed by `resourceId`; without a `resourceId` it resumes on the resource it already has. Every other session route requires a started session and returns 404 until one exists or can be recovered from a stored thread.",
609
+ tags: ["AgentController"],
610
+ requiresAuth: true,
611
+ requiresPermission: "agent-controller:execute",
612
+ handler: async ({ mastra, controllerId, resourceId, sessionId, tags, threadId, requestContext }) => {
613
+ try {
614
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
615
+ await controller.init();
616
+ const id = sessionId ?? resourceId;
617
+ const session = await controller.createSession({
618
+ id,
619
+ resourceId: resourceId ?? await resolveSessionResourceId(controller, id),
620
+ ownerId: controller.id,
621
+ tags,
622
+ threadId,
623
+ requestContext
624
+ });
625
+ return {
626
+ controllerId,
627
+ sessionId: session.identity.getId(),
628
+ resourceId: session.identity.getResourceId(),
629
+ threadId: session.thread.getId() ?? void 0
630
+ };
631
+ } catch (error) {
632
+ return require_server_handlers_error.handleError(error, "error creating controller session");
633
+ }
634
+ }
635
+ });
636
+ /**
637
+ * Copy a display-state value as `JSON.stringify` would read it now: `toJSON` is
638
+ * resolved and every object and array is copied, so the reducer's in-place
639
+ * updates (tool status and results, input buffers, file operations, subagent
640
+ * progress) cannot reach a queued frame. Primitives are immutable and shared, so
641
+ * message text and large tool results are not duplicated per snapshot the way
642
+ * `structuredClone` duplicates them. `copies` preserves shared and circular
643
+ * references.
644
+ */
645
+ function snapshotForWire(value, key, copies) {
646
+ if (value === null || typeof value !== "object") return value;
647
+ if (copies.has(value)) return copies.get(value);
648
+ if (ArrayBuffer.isView(value)) {
649
+ const copy = structuredClone(value);
650
+ copies.set(value, copy);
651
+ return copy;
652
+ }
653
+ const toJSON = value.toJSON;
654
+ let source = typeof toJSON === "function" ? toJSON.call(value, key) : value;
655
+ if (source instanceof Number || source instanceof String || source instanceof Boolean) source = source.valueOf();
656
+ if (source === null || typeof source !== "object") {
657
+ copies.set(value, source);
658
+ return source;
659
+ }
660
+ if (Array.isArray(source)) {
661
+ const copy = new Array(source.length);
662
+ copies.set(value, copy);
663
+ for (let index = 0; index < source.length; index++) copy[index] = snapshotForWire(source[index], String(index), copies);
664
+ return copy;
665
+ }
666
+ const copy = {};
667
+ copies.set(value, copy);
668
+ for (const field of Object.keys(source)) {
669
+ const fieldCopy = snapshotForWire(source[field], field, copies);
670
+ if (field === "__proto__") Object.defineProperty(copy, field, {
671
+ value: fieldCopy,
672
+ enumerable: true,
673
+ writable: true,
674
+ configurable: true
675
+ });
676
+ else copy[field] = fieldCopy;
677
+ }
678
+ return copy;
679
+ }
680
+ /**
681
+ * `display_state_changed` Maps JSON-serialize to `{}`, so convert them to
682
+ * records, and snapshot the live display state so queued wire events retain
683
+ * point-in-time state.
684
+ */
685
+ function toWireDisplayState(displayState) {
686
+ const copies = /* @__PURE__ */ new Map();
687
+ const wire = {};
688
+ for (const [field, value] of Object.entries(displayState)) wire[field] = value instanceof Map ? Object.fromEntries(Array.from(value, ([id, entry]) => [id, snapshotForWire(entry, String(id), copies)])) : snapshotForWire(value, field, copies);
689
+ return wire;
690
+ }
691
+ /**
692
+ * The frame of the display-state event being dispatched. Every stream of a
693
+ * session receives the same event object in one synchronous dispatch, so they
694
+ * share one snapshot, and its JSON, rather than each building its own.
695
+ */
696
+ let dispatchedDisplayFrame;
697
+ function toWireDisplayEvent(event) {
698
+ if (dispatchedDisplayFrame?.event === event) return shareStreamChunk(dispatchedDisplayFrame.frame);
699
+ const frame = {
700
+ ...event,
701
+ displayState: toWireDisplayState(event.displayState)
702
+ };
703
+ dispatchedDisplayFrame = {
704
+ event,
705
+ frame
706
+ };
707
+ queueMicrotask(() => {
708
+ if (dispatchedDisplayFrame?.event === event) dispatchedDisplayFrame = void 0;
709
+ });
710
+ return frame;
711
+ }
712
+ function carriesError(event) {
713
+ return "error" in event && event.error instanceof Error;
714
+ }
715
+ /**
716
+ * An `Error`'s `message`/`name` are non-enumerable, so flatten it before JSON
717
+ * serialization, into the same identity a saved error part keeps. Compact
718
+ * message updates and ends are already JSON-safe and pass through unchanged;
719
+ * only `message_start` carries a message snapshot.
720
+ */
721
+ function toWireEvent(event) {
722
+ if ("displayState" in event) return toWireDisplayEvent(event);
723
+ if (carriesError(event)) return {
724
+ ...event,
725
+ error: (0, _mastra_core_error.toPersistedErrorIdentity)(event.error)
726
+ };
727
+ return event;
728
+ }
729
+ const STREAM_AGENT_CONTROLLER_SESSION_ROUTE = require_route_builder.createRoute({
730
+ method: "GET",
731
+ path: "/agent-controller/:controllerId/sessions/:sessionId/stream",
732
+ queryParamSchema: sessionQuerySchema.extend({ displayState: zod_v4.z.preprocess((value) => {
733
+ if (value === "true") return true;
734
+ if (value === "false") return false;
735
+ return value;
736
+ }, zod_v4.z.boolean().optional()) }),
737
+ responseType: "stream",
738
+ streamFormat: "sse",
739
+ sseFlushOnConnect: true,
740
+ pathParamSchema: sessionPathParams,
741
+ summary: "Stream controller session events",
742
+ description: "Subscribes to a session’s event bus and streams events to the client over SSE.",
743
+ tags: ["AgentController", "Streaming"],
744
+ requiresAuth: true,
745
+ requiresPermission: "agent-controller:read",
746
+ handler: async ({ mastra, controllerId, sessionId, displayState, abortSignal, requestContext }) => {
747
+ try {
748
+ const session = await getExistingSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext);
749
+ let cleanedUp = false;
750
+ let heartbeat;
751
+ let unsubscribe;
752
+ const clearHeartbeat = () => {
753
+ if (heartbeat) {
754
+ clearTimeout(heartbeat);
755
+ heartbeat = void 0;
756
+ }
757
+ };
758
+ const cleanup = (controller) => {
759
+ if (cleanedUp) return;
760
+ cleanedUp = true;
761
+ clearHeartbeat();
762
+ unsubscribe?.();
763
+ if (controller) try {
764
+ controller.close();
765
+ } catch {}
766
+ };
767
+ return new ReadableStream({
768
+ start(controller) {
769
+ const scheduleHeartbeat = () => {
770
+ if (cleanedUp) return;
771
+ clearHeartbeat();
772
+ heartbeat = setTimeout(() => {
773
+ heartbeat = void 0;
774
+ if (cleanedUp) return;
775
+ try {
776
+ controller.enqueue(": heartbeat\n\n");
777
+ } catch {
778
+ cleanup();
779
+ return;
780
+ }
781
+ scheduleHeartbeat();
782
+ }, 25e3);
783
+ };
784
+ if (displayState !== false) try {
785
+ controller.enqueue(toWireEvent({
786
+ type: "display_state_changed",
787
+ displayState: session.displayState.get()
788
+ }));
789
+ } catch {
790
+ cleanup(controller);
791
+ return;
792
+ }
793
+ unsubscribe = session.subscribe((event) => {
794
+ if (cleanedUp || displayState === false && event.type === "display_state_changed") return;
795
+ try {
796
+ controller.enqueue(toWireEvent(event));
797
+ scheduleHeartbeat();
798
+ } catch {
799
+ cleanup();
800
+ }
801
+ });
802
+ const abortCleanup = () => cleanup(controller);
803
+ if (abortSignal?.aborted) {
804
+ abortCleanup();
805
+ return;
806
+ }
807
+ abortSignal?.addEventListener("abort", abortCleanup, { once: true });
808
+ scheduleHeartbeat();
809
+ },
810
+ cancel() {
811
+ cleanup();
812
+ }
813
+ });
814
+ } catch (error) {
815
+ return require_server_handlers_error.handleError(error, "error streaming controller session");
816
+ }
817
+ }
818
+ });
819
+ const SEND_AGENT_CONTROLLER_MESSAGE_ROUTE = require_route_builder.createRoute({
820
+ method: "POST",
821
+ path: "/agent-controller/:controllerId/sessions/:sessionId/messages",
822
+ queryParamSchema: sessionQuerySchema,
823
+ responseType: "json",
824
+ pathParamSchema: sessionPathParams,
825
+ bodySchema: sendMessageBodySchema,
826
+ responseSchema: ackResponseSchema,
827
+ summary: "Send a message to a controller session",
828
+ description: "Sends a user message to the session. The reply streams as events on the session’s SSE stream.",
829
+ tags: ["AgentController", "Streaming"],
830
+ requiresAuth: true,
831
+ requiresPermission: "agent-controller:execute",
832
+ handler: async ({ mastra, controllerId, sessionId, message, files, requestContext }) => {
833
+ try {
834
+ const session = await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext);
835
+ const author = getRequestMessageAuthor(requestContext);
836
+ ackBackgroundSessionWork({
837
+ work: session.sendMessage({
838
+ content: message,
839
+ files,
840
+ requestContext,
841
+ ...author ? { author } : {}
842
+ }),
843
+ session,
844
+ mastra,
845
+ operation: "sendMessage"
846
+ });
847
+ return { ok: true };
848
+ } catch (error) {
849
+ return require_server_handlers_error.handleError(error, "error sending controller message");
850
+ }
851
+ }
852
+ });
853
+ const ABORT_AGENT_CONTROLLER_SESSION_ROUTE = require_route_builder.createRoute({
854
+ method: "POST",
855
+ path: "/agent-controller/:controllerId/sessions/:sessionId/abort",
856
+ queryParamSchema: sessionQuerySchema,
857
+ responseType: "json",
858
+ pathParamSchema: sessionPathParams,
859
+ responseSchema: ackResponseSchema,
860
+ summary: "Abort a controller session run",
861
+ description: "Aborts the in-flight run for the session, if any.",
862
+ tags: ["AgentController"],
863
+ requiresAuth: true,
864
+ requiresPermission: "agent-controller:execute",
865
+ handler: async ({ mastra, controllerId, sessionId, requestContext }) => {
866
+ try {
867
+ (await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext)).abort();
868
+ return { ok: true };
869
+ } catch (error) {
870
+ return require_server_handlers_error.handleError(error, "error aborting controller session");
871
+ }
872
+ }
873
+ });
874
+ const AGENT_CONTROLLER_TOOL_APPROVAL_ROUTE = require_route_builder.createRoute({
875
+ method: "POST",
876
+ path: "/agent-controller/:controllerId/sessions/:sessionId/tool-approval",
877
+ queryParamSchema: sessionQuerySchema,
878
+ responseType: "json",
879
+ pathParamSchema: sessionPathParams,
880
+ bodySchema: toolApprovalBodySchema,
881
+ responseSchema: toolCommandAckResponseSchema,
882
+ summary: "Respond to a controller tool approval",
883
+ description: "Approves or declines a pending tool call surfaced by the session.",
884
+ tags: ["AgentController"],
885
+ requiresAuth: true,
886
+ requiresPermission: "agent-controller:execute",
887
+ handler: async ({ mastra, controllerId, sessionId, toolCallId, approved, alwaysAllowCategory, requestContext }) => {
888
+ try {
889
+ const session = await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext);
890
+ if ((toolCallId ? session.approval.isArmed({ toolCallId }) : session.approval.isArmed()) || !toolCallId) {
891
+ const result = session.respondToToolApproval({
892
+ toolCallId,
893
+ decision: !approved ? "decline" : alwaysAllowCategory ? "always_allow_category" : "approve",
894
+ requestContext
895
+ });
896
+ if (!result.accepted) return {
897
+ ok: false,
898
+ reason: result.reason
899
+ };
900
+ } else {
901
+ if (!await session.hasPersistedToolApproval(toolCallId)) return {
902
+ ok: false,
903
+ reason: session.approval.isArmed() ? "stale_tool_call" : "not_pending"
904
+ };
905
+ if (!session.claimToolResponse(toolCallId)) return {
906
+ ok: false,
907
+ reason: "not_pending"
908
+ };
909
+ ackBackgroundSessionWork({
910
+ work: session.respondToPersistedToolApproval({
911
+ toolCallId,
912
+ approved,
913
+ alwaysAllowCategory,
914
+ requestContext
915
+ }).finally(() => session.releaseToolResponse(toolCallId)),
916
+ session,
917
+ mastra,
918
+ operation: "respondToPersistedToolApproval"
919
+ });
920
+ }
921
+ return { ok: true };
922
+ } catch (error) {
923
+ return require_server_handlers_error.handleError(error, "error responding to controller tool approval");
924
+ }
925
+ }
926
+ });
927
+ const AGENT_CONTROLLER_TOOL_SUSPENSION_ROUTE = require_route_builder.createRoute({
928
+ method: "POST",
929
+ path: "/agent-controller/:controllerId/sessions/:sessionId/tool-suspension",
930
+ queryParamSchema: sessionQuerySchema,
931
+ responseType: "json",
932
+ pathParamSchema: sessionPathParams,
933
+ bodySchema: toolSuspensionBodySchema,
934
+ responseSchema: toolCommandAckResponseSchema,
935
+ summary: "Respond to a suspended controller tool",
936
+ description: "Resumes a suspended interactive tool (ask_user, request_access, submit_plan) with the provided resume data.",
937
+ tags: ["AgentController"],
938
+ requiresAuth: true,
939
+ requiresPermission: "agent-controller:execute",
940
+ handler: async ({ mastra, controllerId, sessionId, toolCallId, runId, resumeData, requestContext }) => {
941
+ try {
942
+ const session = await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext);
943
+ if (typeof session.restoreStoredToolSuspension === "function") await session.restoreStoredToolSuspension(toolCallId, runId);
944
+ const claim = session.claimToolSuspension(toolCallId, runId);
945
+ if (!claim.accepted) return {
946
+ ok: false,
947
+ reason: claim.reason
948
+ };
949
+ ackBackgroundSessionWork({
950
+ work: session.respondToToolSuspension({
951
+ address: claim.address,
952
+ resumeData,
953
+ requestContext
954
+ }).finally(() => session.releaseToolResponse(claim.claimKey)),
955
+ session,
956
+ mastra,
957
+ operation: "respondToToolSuspension"
958
+ });
959
+ return { ok: true };
960
+ } catch (error) {
961
+ return require_server_handlers_error.handleError(error, "error responding to controller tool suspension");
962
+ }
963
+ }
964
+ });
965
+ const STEER_AGENT_CONTROLLER_SESSION_ROUTE = require_route_builder.createRoute({
966
+ method: "POST",
967
+ path: "/agent-controller/:controllerId/sessions/:sessionId/steer",
968
+ queryParamSchema: sessionQuerySchema,
969
+ responseType: "json",
970
+ pathParamSchema: sessionPathParams,
971
+ bodySchema: steerBodySchema,
972
+ responseSchema: ackResponseSchema,
973
+ summary: "Steer the in-flight run",
974
+ description: "Injects a message into the running turn (interjection) without starting a new run.",
975
+ tags: ["AgentController"],
976
+ requiresAuth: true,
977
+ requiresPermission: "agent-controller:execute",
978
+ handler: async ({ mastra, controllerId, sessionId, message, files, requestContext }) => {
979
+ try {
980
+ const session = await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext);
981
+ const author = getRequestMessageAuthor(requestContext);
982
+ ackBackgroundSessionWork({
983
+ work: session.steer({
984
+ content: message,
985
+ files,
986
+ requestContext,
987
+ ...author ? { author } : {}
988
+ }),
989
+ session,
990
+ mastra,
991
+ operation: "steer"
992
+ });
993
+ return { ok: true };
994
+ } catch (error) {
995
+ return require_server_handlers_error.handleError(error, "error steering controller session");
996
+ }
997
+ }
998
+ });
999
+ const SWITCH_AGENT_CONTROLLER_MODE_ROUTE = require_route_builder.createRoute({
1000
+ method: "POST",
1001
+ path: "/agent-controller/:controllerId/sessions/:sessionId/mode",
1002
+ queryParamSchema: sessionQuerySchema,
1003
+ responseType: "json",
1004
+ pathParamSchema: sessionPathParams,
1005
+ bodySchema: switchModeBodySchema,
1006
+ responseSchema: ackResponseSchema,
1007
+ summary: "Switch the session mode",
1008
+ description: "Switches the active mode (e.g. build, plan) for the session.",
1009
+ tags: ["AgentController"],
1010
+ requiresAuth: true,
1011
+ requiresPermission: "agent-controller:execute",
1012
+ handler: async ({ mastra, controllerId, sessionId, modeId, requestContext }) => {
1013
+ try {
1014
+ await (await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext)).mode.switch({ modeId });
1015
+ return { ok: true };
1016
+ } catch (error) {
1017
+ return require_server_handlers_error.handleError(error, "error switching controller mode");
1018
+ }
1019
+ }
1020
+ });
1021
+ const SWITCH_AGENT_CONTROLLER_MODEL_ROUTE = require_route_builder.createRoute({
1022
+ method: "POST",
1023
+ path: "/agent-controller/:controllerId/sessions/:sessionId/model",
1024
+ queryParamSchema: sessionQuerySchema,
1025
+ responseType: "json",
1026
+ pathParamSchema: sessionPathParams,
1027
+ bodySchema: switchModelBodySchema,
1028
+ responseSchema: ackResponseSchema,
1029
+ summary: "Switch the session model",
1030
+ description: "Switches the model for the session and persists it to the active thread. Optionally applies and persists a thinking level with the model.",
1031
+ tags: ["AgentController"],
1032
+ requiresAuth: true,
1033
+ requiresPermission: "agent-controller:execute",
1034
+ handler: async ({ mastra, controllerId, sessionId, modelId, thinkingLevel, requestContext }) => {
1035
+ try {
1036
+ await (await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext)).model.switch(modelId, { thinkingLevel });
1037
+ return { ok: true };
1038
+ } catch (error) {
1039
+ return require_server_handlers_error.handleError(error, "error switching controller model");
1040
+ }
1041
+ }
1042
+ });
1043
+ const SWITCH_AGENT_CONTROLLER_THREAD_ROUTE = require_route_builder.createRoute({
1044
+ method: "POST",
1045
+ path: "/agent-controller/:controllerId/sessions/:sessionId/thread",
1046
+ queryParamSchema: sessionQuerySchema,
1047
+ responseType: "json",
1048
+ pathParamSchema: sessionPathParams,
1049
+ bodySchema: switchThreadBodySchema,
1050
+ responseSchema: ackResponseSchema,
1051
+ summary: "Switch the session thread",
1052
+ description: "Switches the session to an existing thread (rebinding its stream and state).",
1053
+ tags: ["AgentController"],
1054
+ requiresAuth: true,
1055
+ requiresPermission: "agent-controller:execute",
1056
+ handler: async ({ mastra, controllerId, sessionId, threadId, requestContext }) => {
1057
+ try {
1058
+ const session = await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext);
1059
+ if (session.thread.getId() !== threadId) await session.thread.switch({
1060
+ threadId,
1061
+ requestContext
1062
+ });
1063
+ return { ok: true };
1064
+ } catch (error) {
1065
+ return require_server_handlers_error.handleError(error, "error switching controller thread");
1066
+ }
1067
+ }
1068
+ });
1069
+ const TRANSFER_AGENT_CONTROLLER_THREAD_OWNERSHIP_ROUTE = require_route_builder.createRoute({
1070
+ method: "POST",
1071
+ path: "/agent-controller/:controllerId/sessions/:sessionId/threads/:threadId/owner",
1072
+ queryParamSchema: sessionQuerySchema,
1073
+ responseType: "json",
1074
+ pathParamSchema: threadPathParams,
1075
+ responseSchema: transferOwnershipResponseSchema,
1076
+ summary: "Take ownership of a thread",
1077
+ description: "Transfers ownership of the specified thread to the authenticated user from the request context. The thread must belong to the session's resource, and the caller needs memory write access to it. The session's active thread does not change.",
1078
+ tags: ["AgentController", "Threads"],
1079
+ requiresAuth: true,
1080
+ requiresPermission: "agent-controller:execute",
1081
+ handler: async ({ mastra, controllerId, sessionId, threadId, requestContext }) => {
1082
+ try {
1083
+ const ownerId = getRequestMessageAuthor(requestContext)?.id;
1084
+ if (!ownerId) throw new require_http_exception.HTTPException(401, { message: "An authenticated user is required to transfer thread ownership" });
1085
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
1086
+ await controller.init();
1087
+ const resourceId = await resolveSessionResourceId(controller, sessionId);
1088
+ const thread = await controller.queryThreadById({ threadId });
1089
+ if (!thread || thread.resourceId !== resourceId) throw new require_http_exception.HTTPException(404, { message: "Thread not found" });
1090
+ await require_utils.enforceThreadAccess({
1091
+ mastra,
1092
+ requestContext,
1093
+ threadId,
1094
+ thread,
1095
+ effectiveResourceId: resourceId,
1096
+ permission: require_utils.MastraFGAPermissions.MEMORY_WRITE
1097
+ });
1098
+ await (await getSession(controller, sessionId, requestContext)).thread.transferOwnership({
1099
+ toOwnerId: ownerId,
1100
+ threadId
1101
+ });
1102
+ return {
1103
+ ok: true,
1104
+ ownerId
1105
+ };
1106
+ } catch (error) {
1107
+ return require_server_handlers_error.handleError(error, "error transferring controller thread ownership");
1108
+ }
1109
+ }
1110
+ });
1111
+ const GET_AGENT_CONTROLLER_SESSION_STATE_ROUTE = require_route_builder.createRoute({
1112
+ method: "GET",
1113
+ path: "/agent-controller/:controllerId/sessions/:sessionId",
1114
+ responseType: "json",
1115
+ pathParamSchema: sessionPathParams,
1116
+ queryParamSchema: sessionStateQuerySchema,
1117
+ responseSchema: sessionStateResponseSchema,
1118
+ summary: "Get session state",
1119
+ description: "Returns the current mode, model, thread, and durable tasks for initial UI hydration.",
1120
+ tags: ["AgentController"],
1121
+ requiresAuth: true,
1122
+ requiresPermission: "agent-controller:read",
1123
+ handler: async ({ mastra, controllerId, sessionId, threadId: requestedThreadId, requestContext }) => {
1124
+ try {
1125
+ const session = await getExistingSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext);
1126
+ const resourceId = session.identity.getResourceId();
1127
+ const ds = session.displayState.get();
1128
+ const threadId = requestedThreadId ?? session.thread.getId() ?? void 0;
1129
+ const storage = mastra.getStorage();
1130
+ if (requestedThreadId) {
1131
+ if (!await (await storage?.getStore("memory"))?.getThreadById({
1132
+ threadId: requestedThreadId,
1133
+ resourceId
1134
+ })) throw new require_http_exception.HTTPException(404, { message: `thread "${requestedThreadId}" not found` });
1135
+ }
1136
+ const threadState = threadId ? await storage?.getStore("threadState") : void 0;
1137
+ const storedTasks = threadId ? await threadState?.getState({
1138
+ threadId,
1139
+ type: "task"
1140
+ }) : void 0;
1141
+ const parsedTasks = taskSnapshotSchema.array().safeParse(storedTasks);
1142
+ const tasks = parsedTasks.success ? parsedTasks.data : [];
1143
+ const om = ds.omProgress;
1144
+ const reflectionSavings = om.buffered.reflection.inputObservationTokens - om.buffered.reflection.observationTokens;
1145
+ const st = session.state.get();
1146
+ const oneOf = (value, allowed, fallback) => allowed.includes(value) ? value : fallback;
1147
+ const oneOfOptional = (value, allowed) => allowed.includes(value) ? value : void 0;
1148
+ return {
1149
+ controllerId,
1150
+ sessionId: session.identity.getId(),
1151
+ resourceId,
1152
+ threadId,
1153
+ modeId: session.mode.get(),
1154
+ modelId: session.model.get(),
1155
+ running: ds.isRunning === true,
1156
+ tasks,
1157
+ omProgress: {
1158
+ status: om.status,
1159
+ pendingTokens: om.pendingTokens,
1160
+ threshold: om.threshold,
1161
+ thresholdPercent: om.thresholdPercent,
1162
+ observationTokens: om.observationTokens,
1163
+ reflectionThreshold: om.reflectionThreshold,
1164
+ reflectionThresholdPercent: om.reflectionThresholdPercent,
1165
+ projectedMessageRemoval: om.buffered.observations.projectedMessageRemoval,
1166
+ projectedReflectionSavings: reflectionSavings > 0 ? reflectionSavings : 0
1167
+ },
1168
+ tokenUsage: ds.tokenUsage,
1169
+ settings: {
1170
+ yolo: st.yolo === true,
1171
+ thinkingLevel: oneOfOptional(st.thinkingLevel, [
1172
+ "off",
1173
+ "low",
1174
+ "medium",
1175
+ "high",
1176
+ "xhigh",
1177
+ "max"
1178
+ ]),
1179
+ notifications: oneOf(st.notifications, [
1180
+ "off",
1181
+ "bell",
1182
+ "system",
1183
+ "both"
1184
+ ], "off"),
1185
+ smartEditing: st.smartEditing !== false
1186
+ }
1187
+ };
1188
+ } catch (error) {
1189
+ return require_server_handlers_error.handleError(error, "error reading controller session state");
1190
+ }
1191
+ }
1192
+ });
1193
+ const LIST_AGENT_CONTROLLER_MODES_ROUTE = require_route_builder.createRoute({
1194
+ method: "GET",
1195
+ path: "/agent-controller/:controllerId/modes",
1196
+ responseType: "json",
1197
+ pathParamSchema: controllerIdPathParams,
1198
+ responseSchema: listModesResponseSchema,
1199
+ summary: "List controller modes",
1200
+ description: "Lists the modes configured on the controller (e.g. build, plan).",
1201
+ tags: ["AgentController"],
1202
+ requiresAuth: true,
1203
+ requiresPermission: "agent-controller:read",
1204
+ handler: async ({ mastra, controllerId }) => {
1205
+ try {
1206
+ return { modes: getAgentControllerOrThrow(mastra, controllerId).listModes().map((mode) => ({
1207
+ id: mode.id,
1208
+ name: mode.name
1209
+ })) };
1210
+ } catch (error) {
1211
+ return require_server_handlers_error.handleError(error, "error listing controller modes");
1212
+ }
1213
+ }
1214
+ });
1215
+ const listActiveRunsResponseSchema = zod_v4.z.object({ runs: zod_v4.z.array(zod_v4.z.object({
1216
+ runId: zod_v4.z.string(),
1217
+ resourceId: zod_v4.z.string().optional(),
1218
+ threadId: zod_v4.z.string()
1219
+ })) });
1220
+ const LIST_AGENT_CONTROLLER_ACTIVE_RUNS_ROUTE = require_route_builder.createRoute({
1221
+ method: "GET",
1222
+ path: "/agent-controller/:controllerId/active-runs",
1223
+ responseType: "json",
1224
+ pathParamSchema: controllerIdPathParams,
1225
+ responseSchema: listActiveRunsResponseSchema,
1226
+ summary: "List active controller runs",
1227
+ description: "Lists the runs in flight on the controller across all resources, without creating or touching a session.",
1228
+ tags: ["AgentController"],
1229
+ requiresAuth: true,
1230
+ requiresPermission: "agent-controller:read",
1231
+ handler: async ({ mastra, controllerId }) => {
1232
+ try {
1233
+ return { runs: getAgentControllerOrThrow(mastra, controllerId).listActiveThreadRuns() };
1234
+ } catch (error) {
1235
+ return require_server_handlers_error.handleError(error, "error listing active controller runs");
1236
+ }
1237
+ }
1238
+ });
1239
+ const LIST_AGENT_CONTROLLER_THREADS_ROUTE = require_route_builder.createRoute({
1240
+ method: "GET",
1241
+ path: "/agent-controller/:controllerId/sessions/:sessionId/threads",
1242
+ responseType: "json",
1243
+ pathParamSchema: sessionPathParams,
1244
+ queryParamSchema: listThreadsQuerySchema,
1245
+ responseSchema: listThreadsResponseSchema,
1246
+ summary: "List session threads",
1247
+ description: "Lists every thread of the session’s resource (not only the session’s own threads), most-recently-updated first. Pass `limit` to return only the newest N (e.g. for a sidebar). Pass `tags` (a JSON-encoded object) to scope the list to threads matching every tag — e.g. `{ projectPath }` so git worktrees sharing a resourceId each see only their own threads.",
1248
+ tags: ["AgentController"],
1249
+ requiresAuth: true,
1250
+ requiresPermission: "agent-controller:read",
1251
+ handler: async ({ mastra, controllerId, sessionId, limit, tags }) => {
1252
+ try {
1253
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
1254
+ const resourceId = await resolveSessionResourceId(controller, sessionId);
1255
+ const tagEntries = tags ? Object.entries(tags).filter(([key]) => !isReservedThreadMetadataKey(key)) : [];
1256
+ const storageTags = storageTagFilter(Object.fromEntries(tagEntries));
1257
+ const max = Number(limit);
1258
+ const normalizedLimit = Number.isFinite(max) && max > 0 ? Math.floor(max) : void 0;
1259
+ const threads = await controller.queryThreads({
1260
+ resourceId,
1261
+ metadata: storageTags,
1262
+ limit: normalizedLimit !== void 0 && (tagEntries.length === 0 || storageTags) ? normalizedLimit : void 0,
1263
+ matchesScope: tagEntries.length === 0 ? void 0 : (thread) => {
1264
+ const values = thread.metadata ?? {};
1265
+ return tagEntries.every(([key, value]) => values[key] === value);
1266
+ }
1267
+ });
1268
+ const getTags = (t) => {
1269
+ const metadata = t.metadata ?? {};
1270
+ const result = {};
1271
+ for (const [key, value] of Object.entries(metadata)) if (typeof value === "string" && !isReservedThreadMetadataKey(key)) result[key] = value;
1272
+ return result;
1273
+ };
1274
+ const scoped = tagEntries.length > 0 ? threads.filter((t) => {
1275
+ const metadata = t.metadata ?? {};
1276
+ return tagEntries.every(([key, value]) => metadata[key] === value);
1277
+ }) : threads;
1278
+ const toTime = (t) => (t.updatedAt ?? t.createdAt)?.getTime() ?? 0;
1279
+ const sorted = [...scoped].sort((a, b) => toTime(b) - toTime(a));
1280
+ const limited = normalizedLimit !== void 0 ? sorted.slice(0, normalizedLimit) : sorted;
1281
+ const activeThreadIds = new Set(controller.listActiveThreadRuns().filter((r) => r.resourceId === resourceId).map((r) => r.threadId));
1282
+ return { threads: limited.map((t) => {
1283
+ const threadTags = getTags(t);
1284
+ return {
1285
+ id: t.id,
1286
+ title: t.title,
1287
+ tags: Object.keys(threadTags).length > 0 ? threadTags : void 0,
1288
+ updatedAt: t.updatedAt instanceof Date ? t.updatedAt.toISOString() : void 0,
1289
+ state: activeThreadIds.has(t.id) ? "active" : "idle"
1290
+ };
1291
+ }) };
1292
+ } catch (error) {
1293
+ return require_server_handlers_error.handleError(error, "error listing controller threads");
1294
+ }
1295
+ }
1296
+ });
1297
+ const SEND_AGENT_CONTROLLER_NOTIFICATION_ROUTE = require_route_builder.createRoute({
1298
+ method: "POST",
1299
+ path: "/agent-controller/:controllerId/sessions/:sessionId/notifications",
1300
+ queryParamSchema: sessionQuerySchema,
1301
+ responseType: "json",
1302
+ pathParamSchema: sessionPathParams,
1303
+ bodySchema: sendNotificationBodySchema,
1304
+ responseSchema: zod_v4.z.object({
1305
+ accepted: zod_v4.z.boolean(),
1306
+ notificationId: zod_v4.z.string().optional(),
1307
+ decision: zod_v4.z.string().optional(),
1308
+ runId: zod_v4.z.string().optional()
1309
+ }),
1310
+ summary: "Send a notification signal to a session",
1311
+ description: "Delivers a notification to the session’s current agent/thread. The agent’s delivery policy determines whether the notification wakes an idle thread, is summarised, or is persisted for later.",
1312
+ tags: ["AgentController"],
1313
+ requiresAuth: true,
1314
+ requiresPermission: "agent-controller:execute",
1315
+ handler: async ({ mastra, controllerId, sessionId, source, kind, summary, priority, payload, sourceId, dedupeKey, coalesceKey, attributes, metadata, requestContext }) => {
1316
+ try {
1317
+ const result = await (await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext)).sendNotificationSignal({
1318
+ source,
1319
+ kind,
1320
+ summary,
1321
+ priority,
1322
+ payload,
1323
+ sourceId,
1324
+ dedupeKey,
1325
+ coalesceKey,
1326
+ attributes,
1327
+ metadata
1328
+ }, { requestContext });
1329
+ return {
1330
+ accepted: result.accepted !== void 0,
1331
+ notificationId: result.record?.id,
1332
+ decision: result.decision?.action,
1333
+ runId: result.runId
1334
+ };
1335
+ } catch (error) {
1336
+ return require_server_handlers_error.handleError(error, "error sending controller notification");
1337
+ }
1338
+ }
1339
+ });
1340
+ const CREATE_AGENT_CONTROLLER_THREAD_ROUTE = require_route_builder.createRoute({
1341
+ method: "POST",
1342
+ path: "/agent-controller/:controllerId/sessions/:sessionId/threads",
1343
+ queryParamSchema: sessionQuerySchema,
1344
+ responseType: "json",
1345
+ pathParamSchema: sessionPathParams,
1346
+ bodySchema: createThreadBodySchema,
1347
+ responseSchema: threadResponseSchema,
1348
+ summary: "Create a new thread",
1349
+ description: "Creates a new thread in the session (unbinds the previous thread, binds the new one).",
1350
+ tags: ["AgentController", "Threads"],
1351
+ requiresAuth: true,
1352
+ requiresPermission: "agent-controller:execute",
1353
+ handler: async ({ mastra, controllerId, sessionId, title, requestContext }) => {
1354
+ try {
1355
+ const thread = await (await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext)).thread.create({
1356
+ title,
1357
+ requestContext
1358
+ });
1359
+ return {
1360
+ id: thread.id,
1361
+ title: thread.title,
1362
+ resourceId: thread.resourceId,
1363
+ createdAt: thread.createdAt instanceof Date ? thread.createdAt.toISOString() : void 0,
1364
+ updatedAt: thread.updatedAt instanceof Date ? thread.updatedAt.toISOString() : void 0
1365
+ };
1366
+ } catch (error) {
1367
+ return require_server_handlers_error.handleError(error, "error creating controller thread");
1368
+ }
1369
+ }
1370
+ });
1371
+ const DELETE_AGENT_CONTROLLER_THREAD_ROUTE = require_route_builder.createRoute({
1372
+ method: "DELETE",
1373
+ path: "/agent-controller/:controllerId/sessions/:sessionId/threads/:threadId",
1374
+ queryParamSchema: sessionQuerySchema,
1375
+ responseType: "json",
1376
+ pathParamSchema: threadPathParams,
1377
+ responseSchema: ackResponseSchema,
1378
+ summary: "Delete a thread",
1379
+ description: "Deletes a thread. If the deleted thread is the active one, the session is unbound.",
1380
+ tags: ["AgentController", "Threads"],
1381
+ requiresAuth: true,
1382
+ requiresPermission: "agent-controller:execute",
1383
+ handler: async ({ mastra, controllerId, sessionId, threadId, requestContext }) => {
1384
+ try {
1385
+ await (await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext)).thread.delete({
1386
+ threadId,
1387
+ requestContext
1388
+ });
1389
+ return { ok: true };
1390
+ } catch (error) {
1391
+ return require_server_handlers_error.handleError(error, "error deleting controller thread");
1392
+ }
1393
+ }
1394
+ });
1395
+ const RENAME_AGENT_CONTROLLER_THREAD_ROUTE = require_route_builder.createRoute({
1396
+ method: "PUT",
1397
+ path: "/agent-controller/:controllerId/sessions/:sessionId/threads/:threadId",
1398
+ queryParamSchema: sessionQuerySchema,
1399
+ responseType: "json",
1400
+ pathParamSchema: threadPathParams,
1401
+ bodySchema: renameThreadBodySchema,
1402
+ responseSchema: ackResponseSchema,
1403
+ summary: "Rename a thread",
1404
+ description: "Renames the specified thread.",
1405
+ tags: ["AgentController", "Threads"],
1406
+ requiresAuth: true,
1407
+ requiresPermission: "agent-controller:execute",
1408
+ handler: async ({ mastra, controllerId, sessionId, threadId, title, requestContext }) => {
1409
+ try {
1410
+ const session = await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext);
1411
+ if (session.thread.getId() !== threadId) await session.thread.switch({
1412
+ threadId,
1413
+ requestContext
1414
+ });
1415
+ await session.thread.rename({ title });
1416
+ return { ok: true };
1417
+ } catch (error) {
1418
+ return require_server_handlers_error.handleError(error, "error renaming controller thread");
1419
+ }
1420
+ }
1421
+ });
1422
+ const CLONE_AGENT_CONTROLLER_THREAD_ROUTE = require_route_builder.createRoute({
1423
+ method: "POST",
1424
+ path: "/agent-controller/:controllerId/sessions/:sessionId/threads/clone",
1425
+ queryParamSchema: sessionQuerySchema,
1426
+ responseType: "json",
1427
+ pathParamSchema: sessionPathParams,
1428
+ bodySchema: cloneThreadBodySchema,
1429
+ responseSchema: threadResponseSchema,
1430
+ summary: "Clone a thread",
1431
+ description: "Clones a thread (and its messages). The session binds to the new clone.",
1432
+ tags: ["AgentController", "Threads"],
1433
+ requiresAuth: true,
1434
+ requiresPermission: "agent-controller:execute",
1435
+ handler: async ({ mastra, controllerId, sessionId, sourceThreadId, title, requestContext }) => {
1436
+ try {
1437
+ const thread = await (await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext)).thread.clone({
1438
+ sourceThreadId,
1439
+ title,
1440
+ requestContext
1441
+ });
1442
+ return {
1443
+ id: thread.id,
1444
+ title: thread.title,
1445
+ resourceId: thread.resourceId,
1446
+ createdAt: thread.createdAt instanceof Date ? thread.createdAt.toISOString() : void 0,
1447
+ updatedAt: thread.updatedAt instanceof Date ? thread.updatedAt.toISOString() : void 0
1448
+ };
1449
+ } catch (error) {
1450
+ return require_server_handlers_error.handleError(error, "error cloning controller thread");
1451
+ }
1452
+ }
1453
+ });
1454
+ const LIST_AGENT_CONTROLLER_THREAD_MESSAGES_ROUTE = require_route_builder.createRoute({
1455
+ method: "GET",
1456
+ path: "/agent-controller/:controllerId/sessions/:sessionId/threads/:threadId/messages",
1457
+ responseType: "json",
1458
+ pathParamSchema: threadPathParams,
1459
+ queryParamSchema: listMessagesQuerySchema,
1460
+ responseSchema: listMessagesResponseSchema,
1461
+ summary: "List thread messages",
1462
+ description: "Returns a paginated list of messages in a specific thread. The deprecated limit parameter may only be combined with page.",
1463
+ tags: ["AgentController", "Threads"],
1464
+ requiresAuth: true,
1465
+ requiresPermission: "agent-controller:read",
1466
+ handler: async ({ mastra, controllerId, sessionId, threadId, limit, page, perPage, orderBy, include, filter, requestContext }) => {
1467
+ try {
1468
+ if (limit !== void 0 && (perPage !== void 0 || orderBy !== void 0 || include !== void 0 || filter !== void 0)) throw new require_http_exception.HTTPException(400, { message: "limit can only be combined with page; use perPage instead" });
1469
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
1470
+ const resourceId = await resolveSessionResourceId(controller, sessionId);
1471
+ const thread = await controller.queryThreadById({ threadId });
1472
+ if (!thread || thread.resourceId && thread.resourceId !== resourceId) throw new require_http_exception.HTTPException(404, { message: "Thread not found" });
1473
+ await require_utils.enforceThreadAccess({
1474
+ mastra,
1475
+ requestContext,
1476
+ threadId,
1477
+ thread,
1478
+ effectiveResourceId: resourceId
1479
+ });
1480
+ const isLegacyLimitQuery = limit !== void 0;
1481
+ const result = await controller.queryThreadMessages(limit !== void 0 ? {
1482
+ threadId,
1483
+ resourceId,
1484
+ perPage: limit,
1485
+ page: page ?? 0,
1486
+ orderBy: {
1487
+ field: "createdAt",
1488
+ direction: "DESC"
1489
+ }
1490
+ } : {
1491
+ threadId,
1492
+ resourceId,
1493
+ ...perPage !== void 0 ? { perPage } : {},
1494
+ ...page !== void 0 ? { page } : {},
1495
+ ...orderBy !== void 0 ? { orderBy } : {},
1496
+ ...include !== void 0 ? { include } : {},
1497
+ ...filter !== void 0 ? { filter } : {}
1498
+ });
1499
+ const messages = isLegacyLimitQuery ? result.messages.reverse() : result.messages;
1500
+ return {
1501
+ ...result,
1502
+ messages: messages.map((m) => ({
1503
+ id: m.id,
1504
+ role: m.role,
1505
+ content: m.content,
1506
+ createdAt: m.createdAt instanceof Date ? m.createdAt.toISOString() : void 0,
1507
+ threadId: m.threadId,
1508
+ resourceId: m.resourceId,
1509
+ type: m.type
1510
+ }))
1511
+ };
1512
+ } catch (error) {
1513
+ return require_server_handlers_error.handleError(error, "error listing controller thread messages");
1514
+ }
1515
+ }
1516
+ });
1517
+ const FOLLOW_UP_AGENT_CONTROLLER_SESSION_ROUTE = require_route_builder.createRoute({
1518
+ method: "POST",
1519
+ path: "/agent-controller/:controllerId/sessions/:sessionId/follow-up",
1520
+ queryParamSchema: sessionQuerySchema,
1521
+ responseType: "json",
1522
+ pathParamSchema: sessionPathParams,
1523
+ bodySchema: followUpBodySchema,
1524
+ responseSchema: ackResponseSchema,
1525
+ summary: "Queue a follow-up message",
1526
+ description: "Queues a follow-up message. If the session is idle it sends immediately; if a run is active it queues for after completion.",
1527
+ tags: ["AgentController"],
1528
+ requiresAuth: true,
1529
+ requiresPermission: "agent-controller:execute",
1530
+ handler: async ({ mastra, controllerId, sessionId, message, files, requestContext }) => {
1531
+ try {
1532
+ const session = await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext);
1533
+ ackBackgroundSessionWork({
1534
+ work: session.followUp({
1535
+ content: message,
1536
+ files,
1537
+ requestContext
1538
+ }),
1539
+ session,
1540
+ mastra,
1541
+ operation: "followUp"
1542
+ });
1543
+ return { ok: true };
1544
+ } catch (error) {
1545
+ return require_server_handlers_error.handleError(error, "error queuing controller follow-up");
1546
+ }
1547
+ }
1548
+ });
1549
+ const LIST_AGENT_CONTROLLER_MODELS_ROUTE = require_route_builder.createRoute({
1550
+ method: "GET",
1551
+ path: "/agent-controller/:controllerId/models",
1552
+ responseType: "json",
1553
+ pathParamSchema: controllerIdPathParams,
1554
+ responseSchema: listModelsResponseSchema,
1555
+ summary: "List available models",
1556
+ description: "Lists all models available on this controller (with auth status and use counts).",
1557
+ tags: ["AgentController"],
1558
+ requiresAuth: true,
1559
+ requiresPermission: "agent-controller:read",
1560
+ handler: async ({ mastra, controllerId }) => {
1561
+ try {
1562
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
1563
+ await controller.init();
1564
+ return { models: (await controller.listAvailableModels()).map((m) => ({
1565
+ id: m.id,
1566
+ provider: m.provider,
1567
+ modelName: m.modelName,
1568
+ releaseDate: m.releaseDate,
1569
+ hasApiKey: m.hasApiKey,
1570
+ useCount: m.useCount
1571
+ })) };
1572
+ } catch (error) {
1573
+ return require_server_handlers_error.handleError(error, "error listing controller models");
1574
+ }
1575
+ }
1576
+ });
1577
+ const GET_AGENT_CONTROLLER_WORKSPACE_STATUS_ROUTE = require_route_builder.createRoute({
1578
+ method: "GET",
1579
+ path: "/agent-controller/:controllerId/workspace",
1580
+ responseType: "json",
1581
+ pathParamSchema: controllerIdPathParams,
1582
+ responseSchema: workspaceStatusResponseSchema,
1583
+ summary: "Get workspace status",
1584
+ description: "Returns whether the controller has a workspace configured and whether it is ready.",
1585
+ tags: ["AgentController"],
1586
+ requiresAuth: true,
1587
+ requiresPermission: "agent-controller:read",
1588
+ handler: async ({ mastra, controllerId }) => {
1589
+ try {
1590
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
1591
+ await controller.init();
1592
+ return {
1593
+ hasWorkspace: controller.hasWorkspace(),
1594
+ isReady: controller.isWorkspaceReady()
1595
+ };
1596
+ } catch (error) {
1597
+ return require_server_handlers_error.handleError(error, "error reading controller workspace status");
1598
+ }
1599
+ }
1600
+ });
1601
+ const GET_AGENT_CONTROLLER_OM_RECORD_ROUTE = require_route_builder.createRoute({
1602
+ method: "GET",
1603
+ path: "/agent-controller/:controllerId/sessions/:sessionId/om",
1604
+ queryParamSchema: sessionQuerySchema,
1605
+ responseType: "json",
1606
+ pathParamSchema: sessionPathParams,
1607
+ responseSchema: omRecordResponseSchema,
1608
+ summary: "Get observational memory record",
1609
+ description: "Returns the current observational memory record for the session’s thread/resource.",
1610
+ tags: ["AgentController"],
1611
+ requiresAuth: true,
1612
+ requiresPermission: "agent-controller:read",
1613
+ handler: async ({ mastra, controllerId, sessionId, requestContext }) => {
1614
+ try {
1615
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
1616
+ const session = await getExistingSession(controller, sessionId, requestContext);
1617
+ return { record: await controller.getObservationalMemoryRecord(session) ?? void 0 };
1618
+ } catch (error) {
1619
+ return require_server_handlers_error.handleError(error, "error reading controller OM record");
1620
+ }
1621
+ }
1622
+ });
1623
+ const SET_AGENT_CONTROLLER_RESOURCE_ID_ROUTE = require_route_builder.createRoute({
1624
+ method: "POST",
1625
+ path: "/agent-controller/:controllerId/sessions/:sessionId/resource",
1626
+ queryParamSchema: sessionQuerySchema,
1627
+ responseType: "json",
1628
+ pathParamSchema: sessionPathParams,
1629
+ bodySchema: zod_v4.z.object({ newResourceId: zod_v4.z.string() }),
1630
+ responseSchema: ackResponseSchema,
1631
+ summary: "Change the session resource ID",
1632
+ description: "Updates the session’s resource identity (e.g. when a user logs in).",
1633
+ tags: ["AgentController"],
1634
+ requiresAuth: true,
1635
+ requiresPermission: "agent-controller:execute",
1636
+ handler: async ({ mastra, controllerId, sessionId, newResourceId, requestContext }) => {
1637
+ try {
1638
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
1639
+ const session = await getSession(controller, sessionId, requestContext);
1640
+ await controller.setResourceId(session, { resourceId: newResourceId });
1641
+ return { ok: true };
1642
+ } catch (error) {
1643
+ return require_server_handlers_error.handleError(error, "error setting controller resource ID");
1644
+ }
1645
+ }
1646
+ });
1647
+ const GET_AGENT_CONTROLLER_RESOURCE_IDS_ROUTE = require_route_builder.createRoute({
1648
+ method: "GET",
1649
+ path: "/agent-controller/:controllerId/sessions/:sessionId/resources",
1650
+ queryParamSchema: sessionQuerySchema,
1651
+ responseType: "json",
1652
+ pathParamSchema: sessionPathParams,
1653
+ responseSchema: zod_v4.z.object({ resourceIds: zod_v4.z.array(zod_v4.z.string()) }),
1654
+ summary: "Get known resource IDs",
1655
+ description: "Lists the resource IDs known to this session (from threads).",
1656
+ tags: ["AgentController"],
1657
+ requiresAuth: true,
1658
+ requiresPermission: "agent-controller:read",
1659
+ handler: async ({ mastra, controllerId, sessionId, requestContext }) => {
1660
+ try {
1661
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
1662
+ const session = await getExistingSession(controller, sessionId, requestContext);
1663
+ return { resourceIds: await controller.getKnownResourceIds(session) };
1664
+ } catch (error) {
1665
+ return require_server_handlers_error.handleError(error, "error listing controller resource IDs");
1666
+ }
1667
+ }
1668
+ });
1669
+ const setGoalBodySchema = zod_v4.z.object({
1670
+ objective: zod_v4.z.string(),
1671
+ judgeModelId: zod_v4.z.string().optional(),
1672
+ maxRuns: zod_v4.z.number().optional()
1673
+ });
1674
+ const updateGoalBodySchema = zod_v4.z.object({
1675
+ judgeModelId: zod_v4.z.string().optional(),
1676
+ maxRuns: zod_v4.z.number().optional(),
1677
+ status: zod_v4.z.enum([
1678
+ "active",
1679
+ "paused",
1680
+ "done"
1681
+ ]).optional()
1682
+ });
1683
+ const goalRecordSchema = zod_v4.z.object({
1684
+ id: zod_v4.z.string().optional(),
1685
+ objective: zod_v4.z.string(),
1686
+ status: zod_v4.z.enum([
1687
+ "active",
1688
+ "paused",
1689
+ "done"
1690
+ ]),
1691
+ runsUsed: zod_v4.z.number(),
1692
+ maxRuns: zod_v4.z.number().optional(),
1693
+ judgeModelId: zod_v4.z.string().optional(),
1694
+ startedAt: zod_v4.z.number(),
1695
+ updatedAt: zod_v4.z.number(),
1696
+ pausedReason: zod_v4.z.string().optional()
1697
+ });
1698
+ const goalResponseSchema = zod_v4.z.object({ goal: goalRecordSchema.optional() });
1699
+ function getAgentForSession(controller, session) {
1700
+ return controller.getCurrentAgent(session);
1701
+ }
1702
+ const GET_AGENT_CONTROLLER_GOAL_ROUTE = require_route_builder.createRoute({
1703
+ method: "GET",
1704
+ path: "/agent-controller/:controllerId/sessions/:sessionId/goal",
1705
+ queryParamSchema: sessionQuerySchema,
1706
+ responseType: "json",
1707
+ pathParamSchema: sessionPathParams,
1708
+ responseSchema: goalResponseSchema,
1709
+ summary: "Get the current goal",
1710
+ description: "Returns the active/paused/done goal objective for the session’s thread, if any.",
1711
+ tags: ["AgentController", "Goals"],
1712
+ requiresAuth: true,
1713
+ requiresPermission: "agent-controller:read",
1714
+ handler: async ({ mastra, controllerId, sessionId, requestContext }) => {
1715
+ try {
1716
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
1717
+ const session = await getExistingSession(controller, sessionId, requestContext);
1718
+ const threadId = session.thread.getId();
1719
+ if (!threadId) return { goal: void 0 };
1720
+ return { goal: await getAgentForSession(controller, session).getObjective({ threadId }) ?? void 0 };
1721
+ } catch (error) {
1722
+ return require_server_handlers_error.handleError(error, "error reading controller goal");
1723
+ }
1724
+ }
1725
+ });
1726
+ const SET_AGENT_CONTROLLER_GOAL_ROUTE = require_route_builder.createRoute({
1727
+ method: "POST",
1728
+ path: "/agent-controller/:controllerId/sessions/:sessionId/goal",
1729
+ queryParamSchema: sessionQuerySchema,
1730
+ responseType: "json",
1731
+ pathParamSchema: sessionPathParams,
1732
+ bodySchema: setGoalBodySchema,
1733
+ responseSchema: goalResponseSchema,
1734
+ summary: "Set a goal",
1735
+ description: "Sets a new objective for the session’s thread. The agent’s in-loop goal judge evaluates progress after each turn.",
1736
+ tags: ["AgentController", "Goals"],
1737
+ requiresAuth: true,
1738
+ requiresPermission: "agent-controller:execute",
1739
+ handler: async ({ mastra, controllerId, sessionId, objective, judgeModelId, maxRuns, requestContext }) => {
1740
+ try {
1741
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
1742
+ const session = await getSession(controller, sessionId, requestContext);
1743
+ const threadId = session.thread.getId();
1744
+ if (!threadId) throw new require_http_exception.HTTPException(400, { message: "session has no active thread" });
1745
+ return { goal: await getAgentForSession(controller, session).setObjective(objective, {
1746
+ threadId,
1747
+ resourceId: session.identity.getResourceId(),
1748
+ ...judgeModelId ? { judgeModelId } : {},
1749
+ ...maxRuns != null ? { maxRuns } : {}
1750
+ }) ?? void 0 };
1751
+ } catch (error) {
1752
+ return require_server_handlers_error.handleError(error, "error setting controller goal");
1753
+ }
1754
+ }
1755
+ });
1756
+ const UPDATE_AGENT_CONTROLLER_GOAL_ROUTE = require_route_builder.createRoute({
1757
+ method: "PUT",
1758
+ path: "/agent-controller/:controllerId/sessions/:sessionId/goal",
1759
+ queryParamSchema: sessionQuerySchema,
1760
+ responseType: "json",
1761
+ pathParamSchema: sessionPathParams,
1762
+ bodySchema: updateGoalBodySchema,
1763
+ responseSchema: goalResponseSchema,
1764
+ summary: "Update goal options",
1765
+ description: "Updates the judge model, max runs, or status of the active goal. No-op when no goal is set.",
1766
+ tags: ["AgentController", "Goals"],
1767
+ requiresAuth: true,
1768
+ requiresPermission: "agent-controller:execute",
1769
+ handler: async ({ mastra, controllerId, sessionId, judgeModelId, maxRuns, status, requestContext }) => {
1770
+ try {
1771
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
1772
+ const session = await getSession(controller, sessionId, requestContext);
1773
+ const threadId = session.thread.getId();
1774
+ if (!threadId) throw new require_http_exception.HTTPException(400, { message: "session has no active thread" });
1775
+ return { goal: await getAgentForSession(controller, session).updateObjectiveOptions({
1776
+ threadId,
1777
+ ...judgeModelId !== void 0 ? { judgeModelId } : {},
1778
+ ...maxRuns !== void 0 ? { maxRuns } : {},
1779
+ ...status !== void 0 ? { status } : {}
1780
+ }) ?? void 0 };
1781
+ } catch (error) {
1782
+ return require_server_handlers_error.handleError(error, "error updating controller goal");
1783
+ }
1784
+ }
1785
+ });
1786
+ const CLEAR_AGENT_CONTROLLER_GOAL_ROUTE = require_route_builder.createRoute({
1787
+ method: "DELETE",
1788
+ path: "/agent-controller/:controllerId/sessions/:sessionId/goal",
1789
+ queryParamSchema: sessionQuerySchema,
1790
+ responseType: "json",
1791
+ pathParamSchema: sessionPathParams,
1792
+ responseSchema: ackResponseSchema,
1793
+ summary: "Clear the goal",
1794
+ description: "Removes the active goal from the session’s thread.",
1795
+ tags: ["AgentController", "Goals"],
1796
+ requiresAuth: true,
1797
+ requiresPermission: "agent-controller:execute",
1798
+ handler: async ({ mastra, controllerId, sessionId, requestContext }) => {
1799
+ try {
1800
+ const controller = getAgentControllerOrThrow(mastra, controllerId);
1801
+ const session = await getSession(controller, sessionId, requestContext);
1802
+ const threadId = session.thread.getId();
1803
+ if (!threadId) throw new require_http_exception.HTTPException(400, { message: "session has no active thread" });
1804
+ await getAgentForSession(controller, session).clearObjective({ threadId });
1805
+ return { ok: true };
1806
+ } catch (error) {
1807
+ return require_server_handlers_error.handleError(error, "error clearing controller goal");
1808
+ }
1809
+ }
1810
+ });
1811
+ const GET_AGENT_CONTROLLER_PERMISSIONS_ROUTE = require_route_builder.createRoute({
1812
+ method: "GET",
1813
+ path: "/agent-controller/:controllerId/sessions/:sessionId/permissions",
1814
+ queryParamSchema: sessionQuerySchema,
1815
+ responseType: "json",
1816
+ pathParamSchema: sessionPathParams,
1817
+ responseSchema: permissionRulesResponseSchema,
1818
+ summary: "Get permission rules",
1819
+ description: "Returns the current permission rules (per-category and per-tool policies) for the session.",
1820
+ tags: ["AgentController", "Permissions"],
1821
+ requiresAuth: true,
1822
+ requiresPermission: "agent-controller:read",
1823
+ handler: async ({ mastra, controllerId, sessionId, requestContext }) => {
1824
+ try {
1825
+ const rules = (await getExistingSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext)).permissions.getRules();
1826
+ return {
1827
+ categories: rules.categories,
1828
+ tools: rules.tools
1829
+ };
1830
+ } catch (error) {
1831
+ return require_server_handlers_error.handleError(error, "error getting controller permissions");
1832
+ }
1833
+ }
1834
+ });
1835
+ const SET_AGENT_CONTROLLER_CATEGORY_PERMISSION_ROUTE = require_route_builder.createRoute({
1836
+ method: "PUT",
1837
+ path: "/agent-controller/:controllerId/sessions/:sessionId/permissions/category",
1838
+ queryParamSchema: sessionQuerySchema,
1839
+ responseType: "json",
1840
+ pathParamSchema: sessionPathParams,
1841
+ bodySchema: setCategoryPermissionBodySchema,
1842
+ responseSchema: ackResponseSchema,
1843
+ summary: "Set permission for a tool category",
1844
+ description: "Sets the approval policy (allow/ask/deny) for all tools in a category.",
1845
+ tags: ["AgentController", "Permissions"],
1846
+ requiresAuth: true,
1847
+ requiresPermission: "agent-controller:execute",
1848
+ handler: async ({ mastra, controllerId, sessionId, category, policy, requestContext }) => {
1849
+ try {
1850
+ await (await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext)).permissions.setForCategory({
1851
+ category,
1852
+ policy
1853
+ });
1854
+ return { ok: true };
1855
+ } catch (error) {
1856
+ return require_server_handlers_error.handleError(error, "error setting controller category permission");
1857
+ }
1858
+ }
1859
+ });
1860
+ const SET_AGENT_CONTROLLER_TOOL_PERMISSION_ROUTE = require_route_builder.createRoute({
1861
+ method: "PUT",
1862
+ path: "/agent-controller/:controllerId/sessions/:sessionId/permissions/tool",
1863
+ queryParamSchema: sessionQuerySchema,
1864
+ responseType: "json",
1865
+ pathParamSchema: sessionPathParams,
1866
+ bodySchema: setToolPermissionBodySchema,
1867
+ responseSchema: ackResponseSchema,
1868
+ summary: "Set permission for a specific tool",
1869
+ description: "Sets the approval policy (allow/ask/deny) for a specific tool by name. Per-tool overrides take precedence over category policies.",
1870
+ tags: ["AgentController", "Permissions"],
1871
+ requiresAuth: true,
1872
+ requiresPermission: "agent-controller:execute",
1873
+ handler: async ({ mastra, controllerId, sessionId, toolName, policy, requestContext }) => {
1874
+ try {
1875
+ await (await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext)).permissions.setForTool({
1876
+ toolName,
1877
+ policy
1878
+ });
1879
+ return { ok: true };
1880
+ } catch (error) {
1881
+ return require_server_handlers_error.handleError(error, "error setting controller tool permission");
1882
+ }
1883
+ }
1884
+ });
1885
+ const setSessionStateBodySchema = zod_v4.z.object({ state: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.unknown()) });
1886
+ const SET_AGENT_CONTROLLER_SESSION_STATE_ROUTE = require_route_builder.createRoute({
1887
+ method: "PUT",
1888
+ path: "/agent-controller/:controllerId/sessions/:sessionId/state",
1889
+ queryParamSchema: sessionQuerySchema,
1890
+ responseType: "json",
1891
+ pathParamSchema: sessionPathParams,
1892
+ bodySchema: setSessionStateBodySchema,
1893
+ responseSchema: ackResponseSchema,
1894
+ summary: "Set session state",
1895
+ description: "Merges the provided key-value pairs into the session state. Existing keys not in the payload are preserved.",
1896
+ tags: ["AgentController"],
1897
+ requiresAuth: true,
1898
+ requiresPermission: "agent-controller:execute",
1899
+ handler: async ({ mastra, controllerId, sessionId, state, requestContext }) => {
1900
+ try {
1901
+ await (await getSession(getAgentControllerOrThrow(mastra, controllerId), sessionId, requestContext)).state.set(state);
1902
+ return { ok: true };
1903
+ } catch (error) {
1904
+ return require_server_handlers_error.handleError(error, "error setting controller session state");
1905
+ }
1906
+ }
1907
+ });
1908
+ Object.defineProperty(exports, "ABORT_AGENT_CONTROLLER_SESSION_ROUTE", {
1909
+ enumerable: true,
1910
+ get: function() {
1911
+ return ABORT_AGENT_CONTROLLER_SESSION_ROUTE;
1912
+ }
1913
+ });
1914
+ Object.defineProperty(exports, "AGENT_CONTROLLER_TOOL_APPROVAL_ROUTE", {
1915
+ enumerable: true,
1916
+ get: function() {
1917
+ return AGENT_CONTROLLER_TOOL_APPROVAL_ROUTE;
1918
+ }
1919
+ });
1920
+ Object.defineProperty(exports, "AGENT_CONTROLLER_TOOL_SUSPENSION_ROUTE", {
1921
+ enumerable: true,
1922
+ get: function() {
1923
+ return AGENT_CONTROLLER_TOOL_SUSPENSION_ROUTE;
1924
+ }
1925
+ });
1926
+ Object.defineProperty(exports, "CLEAR_AGENT_CONTROLLER_GOAL_ROUTE", {
1927
+ enumerable: true,
1928
+ get: function() {
1929
+ return CLEAR_AGENT_CONTROLLER_GOAL_ROUTE;
1930
+ }
1931
+ });
1932
+ Object.defineProperty(exports, "CLONE_AGENT_CONTROLLER_THREAD_ROUTE", {
1933
+ enumerable: true,
1934
+ get: function() {
1935
+ return CLONE_AGENT_CONTROLLER_THREAD_ROUTE;
1936
+ }
1937
+ });
1938
+ Object.defineProperty(exports, "CREATE_AGENT_CONTROLLER_SESSION_ROUTE", {
1939
+ enumerable: true,
1940
+ get: function() {
1941
+ return CREATE_AGENT_CONTROLLER_SESSION_ROUTE;
1942
+ }
1943
+ });
1944
+ Object.defineProperty(exports, "CREATE_AGENT_CONTROLLER_THREAD_ROUTE", {
1945
+ enumerable: true,
1946
+ get: function() {
1947
+ return CREATE_AGENT_CONTROLLER_THREAD_ROUTE;
1948
+ }
1949
+ });
1950
+ Object.defineProperty(exports, "DELETE_AGENT_CONTROLLER_THREAD_ROUTE", {
1951
+ enumerable: true,
1952
+ get: function() {
1953
+ return DELETE_AGENT_CONTROLLER_THREAD_ROUTE;
1954
+ }
1955
+ });
1956
+ Object.defineProperty(exports, "FOLLOW_UP_AGENT_CONTROLLER_SESSION_ROUTE", {
1957
+ enumerable: true,
1958
+ get: function() {
1959
+ return FOLLOW_UP_AGENT_CONTROLLER_SESSION_ROUTE;
1960
+ }
1961
+ });
1962
+ Object.defineProperty(exports, "GET_AGENT_CONTROLLER_GOAL_ROUTE", {
1963
+ enumerable: true,
1964
+ get: function() {
1965
+ return GET_AGENT_CONTROLLER_GOAL_ROUTE;
1966
+ }
1967
+ });
1968
+ Object.defineProperty(exports, "GET_AGENT_CONTROLLER_OM_RECORD_ROUTE", {
1969
+ enumerable: true,
1970
+ get: function() {
1971
+ return GET_AGENT_CONTROLLER_OM_RECORD_ROUTE;
1972
+ }
1973
+ });
1974
+ Object.defineProperty(exports, "GET_AGENT_CONTROLLER_PERMISSIONS_ROUTE", {
1975
+ enumerable: true,
1976
+ get: function() {
1977
+ return GET_AGENT_CONTROLLER_PERMISSIONS_ROUTE;
1978
+ }
1979
+ });
1980
+ Object.defineProperty(exports, "GET_AGENT_CONTROLLER_RESOURCE_IDS_ROUTE", {
1981
+ enumerable: true,
1982
+ get: function() {
1983
+ return GET_AGENT_CONTROLLER_RESOURCE_IDS_ROUTE;
1984
+ }
1985
+ });
1986
+ Object.defineProperty(exports, "GET_AGENT_CONTROLLER_SESSION_STATE_ROUTE", {
1987
+ enumerable: true,
1988
+ get: function() {
1989
+ return GET_AGENT_CONTROLLER_SESSION_STATE_ROUTE;
1990
+ }
1991
+ });
1992
+ Object.defineProperty(exports, "GET_AGENT_CONTROLLER_WORKSPACE_STATUS_ROUTE", {
1993
+ enumerable: true,
1994
+ get: function() {
1995
+ return GET_AGENT_CONTROLLER_WORKSPACE_STATUS_ROUTE;
1996
+ }
1997
+ });
1998
+ Object.defineProperty(exports, "LIST_AGENT_CONTROLLERS_ROUTE", {
1999
+ enumerable: true,
2000
+ get: function() {
2001
+ return LIST_AGENT_CONTROLLERS_ROUTE;
2002
+ }
2003
+ });
2004
+ Object.defineProperty(exports, "LIST_AGENT_CONTROLLER_ACTIVE_RUNS_ROUTE", {
2005
+ enumerable: true,
2006
+ get: function() {
2007
+ return LIST_AGENT_CONTROLLER_ACTIVE_RUNS_ROUTE;
2008
+ }
2009
+ });
2010
+ Object.defineProperty(exports, "LIST_AGENT_CONTROLLER_MODELS_ROUTE", {
2011
+ enumerable: true,
2012
+ get: function() {
2013
+ return LIST_AGENT_CONTROLLER_MODELS_ROUTE;
2014
+ }
2015
+ });
2016
+ Object.defineProperty(exports, "LIST_AGENT_CONTROLLER_MODES_ROUTE", {
2017
+ enumerable: true,
2018
+ get: function() {
2019
+ return LIST_AGENT_CONTROLLER_MODES_ROUTE;
2020
+ }
2021
+ });
2022
+ Object.defineProperty(exports, "LIST_AGENT_CONTROLLER_THREADS_ROUTE", {
2023
+ enumerable: true,
2024
+ get: function() {
2025
+ return LIST_AGENT_CONTROLLER_THREADS_ROUTE;
2026
+ }
2027
+ });
2028
+ Object.defineProperty(exports, "LIST_AGENT_CONTROLLER_THREAD_MESSAGES_ROUTE", {
2029
+ enumerable: true,
2030
+ get: function() {
2031
+ return LIST_AGENT_CONTROLLER_THREAD_MESSAGES_ROUTE;
2032
+ }
2033
+ });
2034
+ Object.defineProperty(exports, "RENAME_AGENT_CONTROLLER_THREAD_ROUTE", {
2035
+ enumerable: true,
2036
+ get: function() {
2037
+ return RENAME_AGENT_CONTROLLER_THREAD_ROUTE;
2038
+ }
2039
+ });
2040
+ Object.defineProperty(exports, "SEND_AGENT_CONTROLLER_MESSAGE_ROUTE", {
2041
+ enumerable: true,
2042
+ get: function() {
2043
+ return SEND_AGENT_CONTROLLER_MESSAGE_ROUTE;
2044
+ }
2045
+ });
2046
+ Object.defineProperty(exports, "SEND_AGENT_CONTROLLER_NOTIFICATION_ROUTE", {
2047
+ enumerable: true,
2048
+ get: function() {
2049
+ return SEND_AGENT_CONTROLLER_NOTIFICATION_ROUTE;
2050
+ }
2051
+ });
2052
+ Object.defineProperty(exports, "SET_AGENT_CONTROLLER_CATEGORY_PERMISSION_ROUTE", {
2053
+ enumerable: true,
2054
+ get: function() {
2055
+ return SET_AGENT_CONTROLLER_CATEGORY_PERMISSION_ROUTE;
2056
+ }
2057
+ });
2058
+ Object.defineProperty(exports, "SET_AGENT_CONTROLLER_GOAL_ROUTE", {
2059
+ enumerable: true,
2060
+ get: function() {
2061
+ return SET_AGENT_CONTROLLER_GOAL_ROUTE;
2062
+ }
2063
+ });
2064
+ Object.defineProperty(exports, "SET_AGENT_CONTROLLER_RESOURCE_ID_ROUTE", {
2065
+ enumerable: true,
2066
+ get: function() {
2067
+ return SET_AGENT_CONTROLLER_RESOURCE_ID_ROUTE;
2068
+ }
2069
+ });
2070
+ Object.defineProperty(exports, "SET_AGENT_CONTROLLER_SESSION_STATE_ROUTE", {
2071
+ enumerable: true,
2072
+ get: function() {
2073
+ return SET_AGENT_CONTROLLER_SESSION_STATE_ROUTE;
2074
+ }
2075
+ });
2076
+ Object.defineProperty(exports, "SET_AGENT_CONTROLLER_TOOL_PERMISSION_ROUTE", {
2077
+ enumerable: true,
2078
+ get: function() {
2079
+ return SET_AGENT_CONTROLLER_TOOL_PERMISSION_ROUTE;
2080
+ }
2081
+ });
2082
+ Object.defineProperty(exports, "STEER_AGENT_CONTROLLER_SESSION_ROUTE", {
2083
+ enumerable: true,
2084
+ get: function() {
2085
+ return STEER_AGENT_CONTROLLER_SESSION_ROUTE;
2086
+ }
2087
+ });
2088
+ Object.defineProperty(exports, "STREAM_AGENT_CONTROLLER_SESSION_ROUTE", {
2089
+ enumerable: true,
2090
+ get: function() {
2091
+ return STREAM_AGENT_CONTROLLER_SESSION_ROUTE;
2092
+ }
2093
+ });
2094
+ Object.defineProperty(exports, "SWITCH_AGENT_CONTROLLER_MODEL_ROUTE", {
2095
+ enumerable: true,
2096
+ get: function() {
2097
+ return SWITCH_AGENT_CONTROLLER_MODEL_ROUTE;
2098
+ }
2099
+ });
2100
+ Object.defineProperty(exports, "SWITCH_AGENT_CONTROLLER_MODE_ROUTE", {
2101
+ enumerable: true,
2102
+ get: function() {
2103
+ return SWITCH_AGENT_CONTROLLER_MODE_ROUTE;
2104
+ }
2105
+ });
2106
+ Object.defineProperty(exports, "SWITCH_AGENT_CONTROLLER_THREAD_ROUTE", {
2107
+ enumerable: true,
2108
+ get: function() {
2109
+ return SWITCH_AGENT_CONTROLLER_THREAD_ROUTE;
2110
+ }
2111
+ });
2112
+ Object.defineProperty(exports, "TRANSFER_AGENT_CONTROLLER_THREAD_OWNERSHIP_ROUTE", {
2113
+ enumerable: true,
2114
+ get: function() {
2115
+ return TRANSFER_AGENT_CONTROLLER_THREAD_OWNERSHIP_ROUTE;
2116
+ }
2117
+ });
2118
+ Object.defineProperty(exports, "UPDATE_AGENT_CONTROLLER_GOAL_ROUTE", {
2119
+ enumerable: true,
2120
+ get: function() {
2121
+ return UPDATE_AGENT_CONTROLLER_GOAL_ROUTE;
2122
+ }
2123
+ });
2124
+ Object.defineProperty(exports, "serializeStreamChunk", {
2125
+ enumerable: true,
2126
+ get: function() {
2127
+ return serializeStreamChunk;
2128
+ }
2129
+ });
2130
+
2131
+ //# sourceMappingURL=agent-controller-Dwtk-Oi1.cjs.map