@mastra/client-js 0.0.0-studio-deploy-20260404182525 → 0.0.0-studio-cli-20260504022012
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +917 -3
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +466 -1764
- package/dist/client.d.ts +46 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/docs/SKILL.md +3 -1
- package/dist/docs/assets/SOURCE_MAP.json +7 -2
- package/dist/docs/references/docs-editor-overview.md +290 -0
- package/dist/docs/references/docs-server-mastra-client.md +2 -2
- package/dist/docs/references/reference-ai-sdk-to-ai-sdk-messages.md +95 -0
- package/dist/docs/references/reference-ai-sdk-to-ai-sdk-stream.md +15 -0
- package/dist/docs/references/reference-client-js-agents.md +166 -0
- package/dist/docs/references/reference-client-js-conversations.md +1 -1
- package/dist/docs/references/reference-client-js-mastra-client.md +23 -0
- package/dist/docs/references/reference-client-js-observability.md +2 -2
- package/dist/docs/references/reference-client-js-responses.md +1 -1
- package/dist/docs/references/reference-client-js-workflows.md +62 -1
- package/dist/index.cjs +660 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +657 -35
- package/dist/index.js.map +1 -1
- package/dist/resources/a2a.d.ts +56 -10
- package/dist/resources/a2a.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +69 -0
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/channels.d.ts +63 -0
- package/dist/resources/channels.d.ts.map +1 -0
- package/dist/resources/index.d.ts +1 -0
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/memory-thread.d.ts.map +1 -1
- package/dist/resources/observability.d.ts +18 -1
- package/dist/resources/observability.d.ts.map +1 -1
- package/dist/resources/run.d.ts +26 -2
- package/dist/resources/run.d.ts.map +1 -1
- package/dist/resources/vector.d.ts +5 -5
- package/dist/resources/vector.d.ts.map +1 -1
- package/dist/types.d.ts +115 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/process-a2a-stream.d.ts +4 -0
- package/dist/utils/process-a2a-stream.d.ts.map +1 -0
- package/package.json +12 -12
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ var error = require('@mastra/core/error');
|
|
|
6
6
|
var schema = require('@mastra/schema-compat/schema');
|
|
7
7
|
var requestContext = require('@mastra/core/request-context');
|
|
8
8
|
var zodToJson = require('@mastra/schema-compat/zod-to-json');
|
|
9
|
+
var a2a = require('@mastra/core/a2a');
|
|
9
10
|
|
|
10
11
|
// src/resources/agent.ts
|
|
11
12
|
function normalizeRoutePath(path) {
|
|
@@ -341,6 +342,8 @@ var AgentVoice = class extends BaseResource {
|
|
|
341
342
|
this.version = version;
|
|
342
343
|
this.agentId = agentId;
|
|
343
344
|
}
|
|
345
|
+
agentId;
|
|
346
|
+
version;
|
|
344
347
|
getQueryString(requestContext, delimiter = "?") {
|
|
345
348
|
const searchParams = new URLSearchParams(requestContextQueryString(requestContext).slice(1));
|
|
346
349
|
if (this.version) {
|
|
@@ -410,6 +413,8 @@ var Agent = class extends BaseResource {
|
|
|
410
413
|
this.version = version;
|
|
411
414
|
this.voice = new AgentVoice(options, this.agentId, this.version);
|
|
412
415
|
}
|
|
416
|
+
agentId;
|
|
417
|
+
version;
|
|
413
418
|
voice;
|
|
414
419
|
getQueryString(requestContext, delimiter = "?") {
|
|
415
420
|
const searchParams = new URLSearchParams(requestContextQueryString(requestContext).slice(1));
|
|
@@ -1206,9 +1211,14 @@ var Agent = class extends BaseResource {
|
|
|
1206
1211
|
const { resource, thread } = memory ?? {};
|
|
1207
1212
|
const threadId = processedParams.threadId ?? (typeof thread === "string" ? thread : thread?.id);
|
|
1208
1213
|
const resourceId = processedParams.resourceId ?? resource;
|
|
1214
|
+
let requestBody = processedParams;
|
|
1215
|
+
if (route === "resume-stream") {
|
|
1216
|
+
const { messages: _messages, ...resumeStreamBody } = processedParams;
|
|
1217
|
+
requestBody = resumeStreamBody;
|
|
1218
|
+
}
|
|
1209
1219
|
const response = await this.request(`/agents/${this.agentId}/${route}`, {
|
|
1210
1220
|
method: "POST",
|
|
1211
|
-
body:
|
|
1221
|
+
body: requestBody,
|
|
1212
1222
|
stream: true
|
|
1213
1223
|
});
|
|
1214
1224
|
if (!response.body) {
|
|
@@ -1304,7 +1314,8 @@ var Agent = class extends BaseResource {
|
|
|
1304
1314
|
...processedParams,
|
|
1305
1315
|
messages: updatedMessages
|
|
1306
1316
|
},
|
|
1307
|
-
controller
|
|
1317
|
+
controller,
|
|
1318
|
+
route
|
|
1308
1319
|
);
|
|
1309
1320
|
} catch (error) {
|
|
1310
1321
|
console.error("Error processing recursive stream response:", error);
|
|
@@ -1457,6 +1468,46 @@ var Agent = class extends BaseResource {
|
|
|
1457
1468
|
};
|
|
1458
1469
|
return streamResponse;
|
|
1459
1470
|
}
|
|
1471
|
+
async streamUntilIdle(messagesOrParams, options) {
|
|
1472
|
+
let params = {
|
|
1473
|
+
messages: messagesOrParams,
|
|
1474
|
+
...options
|
|
1475
|
+
};
|
|
1476
|
+
let structuredOutput = void 0;
|
|
1477
|
+
if (params.structuredOutput?.schema) {
|
|
1478
|
+
structuredOutput = {
|
|
1479
|
+
...params.structuredOutput,
|
|
1480
|
+
schema: schema.standardSchemaToJSONSchema(schema.toStandardSchema(params.structuredOutput.schema))
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
const processedParams = {
|
|
1484
|
+
...params,
|
|
1485
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
1486
|
+
clientTools: processClientTools(params.clientTools),
|
|
1487
|
+
structuredOutput
|
|
1488
|
+
};
|
|
1489
|
+
let readableController;
|
|
1490
|
+
const readable = new ReadableStream({
|
|
1491
|
+
start(controller) {
|
|
1492
|
+
readableController = controller;
|
|
1493
|
+
}
|
|
1494
|
+
});
|
|
1495
|
+
const response = await this.processStreamResponse(processedParams, readableController, "stream-until-idle");
|
|
1496
|
+
const streamResponse = new Response(readable, {
|
|
1497
|
+
status: response.status,
|
|
1498
|
+
statusText: response.statusText,
|
|
1499
|
+
headers: response.headers
|
|
1500
|
+
});
|
|
1501
|
+
streamResponse.processDataStream = async ({
|
|
1502
|
+
onChunk
|
|
1503
|
+
}) => {
|
|
1504
|
+
await processMastraStream({
|
|
1505
|
+
stream: streamResponse.body,
|
|
1506
|
+
onChunk
|
|
1507
|
+
});
|
|
1508
|
+
};
|
|
1509
|
+
return streamResponse;
|
|
1510
|
+
}
|
|
1460
1511
|
async approveToolCall(params) {
|
|
1461
1512
|
const { requestContext, ...rest } = params;
|
|
1462
1513
|
const processedParams = { ...rest, requestContext: parseClientRequestContext(requestContext) };
|
|
@@ -1507,6 +1558,88 @@ var Agent = class extends BaseResource {
|
|
|
1507
1558
|
};
|
|
1508
1559
|
return streamResponse;
|
|
1509
1560
|
}
|
|
1561
|
+
/**
|
|
1562
|
+
* Observe (reconnect to) an existing agent stream.
|
|
1563
|
+
* Use this to resume receiving events after a disconnection.
|
|
1564
|
+
*
|
|
1565
|
+
* @param params.runId - The run ID to observe
|
|
1566
|
+
* @param params.offset - Optional position to resume from (0-based). If omitted, replays all events.
|
|
1567
|
+
* @returns Promise containing a streaming Response
|
|
1568
|
+
*
|
|
1569
|
+
* @example
|
|
1570
|
+
* ```typescript
|
|
1571
|
+
* // Reconnect to a stream from a specific position
|
|
1572
|
+
* const response = await client.agents('my-agent').observe({
|
|
1573
|
+
* runId: 'run-123',
|
|
1574
|
+
* offset: 42, // Resume from event 42
|
|
1575
|
+
* });
|
|
1576
|
+
*
|
|
1577
|
+
* await response.processDataStream({
|
|
1578
|
+
* onChunk: (chunk) => console.log('Received:', chunk),
|
|
1579
|
+
* });
|
|
1580
|
+
* ```
|
|
1581
|
+
*/
|
|
1582
|
+
async observe(params) {
|
|
1583
|
+
const response = await this.request(`/agents/${this.agentId}/observe`, {
|
|
1584
|
+
method: "POST",
|
|
1585
|
+
body: params,
|
|
1586
|
+
stream: true
|
|
1587
|
+
});
|
|
1588
|
+
if (!response.body) {
|
|
1589
|
+
throw new Error("No response body");
|
|
1590
|
+
}
|
|
1591
|
+
const streamResponse = new Response(response.body, {
|
|
1592
|
+
status: response.status,
|
|
1593
|
+
statusText: response.statusText,
|
|
1594
|
+
headers: response.headers
|
|
1595
|
+
});
|
|
1596
|
+
streamResponse.processDataStream = async ({
|
|
1597
|
+
onChunk
|
|
1598
|
+
}) => {
|
|
1599
|
+
await processMastraStream({
|
|
1600
|
+
stream: streamResponse.body,
|
|
1601
|
+
onChunk
|
|
1602
|
+
});
|
|
1603
|
+
};
|
|
1604
|
+
return streamResponse;
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Resumes a suspended agent stream with custom resume data.
|
|
1608
|
+
* Used to continue execution after a suspension point (e.g., workflow suspend within an agent).
|
|
1609
|
+
*/
|
|
1610
|
+
async resumeStream(resumeData, options) {
|
|
1611
|
+
const processedParams = {
|
|
1612
|
+
...options,
|
|
1613
|
+
resumeData,
|
|
1614
|
+
requestContext: parseClientRequestContext(options.requestContext),
|
|
1615
|
+
clientTools: processClientTools(options.clientTools),
|
|
1616
|
+
structuredOutput: options.structuredOutput ? {
|
|
1617
|
+
...options.structuredOutput,
|
|
1618
|
+
schema: schema.standardSchemaToJSONSchema(schema.toStandardSchema(options.structuredOutput.schema))
|
|
1619
|
+
} : void 0
|
|
1620
|
+
};
|
|
1621
|
+
let readableController;
|
|
1622
|
+
const readable = new ReadableStream({
|
|
1623
|
+
start(controller) {
|
|
1624
|
+
readableController = controller;
|
|
1625
|
+
}
|
|
1626
|
+
});
|
|
1627
|
+
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream");
|
|
1628
|
+
const streamResponse = new Response(readable, {
|
|
1629
|
+
status: response.status,
|
|
1630
|
+
statusText: response.statusText,
|
|
1631
|
+
headers: response.headers
|
|
1632
|
+
});
|
|
1633
|
+
streamResponse.processDataStream = async ({
|
|
1634
|
+
onChunk
|
|
1635
|
+
}) => {
|
|
1636
|
+
await processMastraStream({
|
|
1637
|
+
stream: streamResponse.body,
|
|
1638
|
+
onChunk
|
|
1639
|
+
});
|
|
1640
|
+
};
|
|
1641
|
+
return streamResponse;
|
|
1642
|
+
}
|
|
1510
1643
|
/**
|
|
1511
1644
|
* Approves a pending tool call and returns the complete response (non-streaming).
|
|
1512
1645
|
* Used when `requireToolApproval` is enabled with generate() to allow the agent to proceed.
|
|
@@ -1723,6 +1856,8 @@ var MemoryThread = class extends BaseResource {
|
|
|
1723
1856
|
this.threadId = threadId;
|
|
1724
1857
|
this.agentId = agentId;
|
|
1725
1858
|
}
|
|
1859
|
+
threadId;
|
|
1860
|
+
agentId;
|
|
1726
1861
|
/**
|
|
1727
1862
|
* Builds the query string for agentId (if provided)
|
|
1728
1863
|
*/
|
|
@@ -1770,7 +1905,7 @@ var MemoryThread = class extends BaseResource {
|
|
|
1770
1905
|
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
1771
1906
|
*/
|
|
1772
1907
|
listMessages(params = {}) {
|
|
1773
|
-
const { page, perPage, orderBy, filter, include, resourceId, requestContext } = params;
|
|
1908
|
+
const { page, perPage, orderBy, filter, include, resourceId, requestContext, includeSystemReminders } = params;
|
|
1774
1909
|
const queryParams = {};
|
|
1775
1910
|
if (this.agentId) queryParams.agentId = this.agentId;
|
|
1776
1911
|
if (resourceId) queryParams.resourceId = resourceId;
|
|
@@ -1779,6 +1914,7 @@ var MemoryThread = class extends BaseResource {
|
|
|
1779
1914
|
if (orderBy) queryParams.orderBy = JSON.stringify(orderBy);
|
|
1780
1915
|
if (filter) queryParams.filter = JSON.stringify(filter);
|
|
1781
1916
|
if (include) queryParams.include = JSON.stringify(include);
|
|
1917
|
+
if (includeSystemReminders !== void 0) queryParams.includeSystemReminders = String(includeSystemReminders);
|
|
1782
1918
|
const query = new URLSearchParams(queryParams);
|
|
1783
1919
|
const queryString = query.toString();
|
|
1784
1920
|
const url = `/memory/threads/${this.threadId}/messages${queryString ? `?${queryString}` : ""}${requestContextQueryString(requestContext, queryString ? "&" : "?")}`;
|
|
@@ -1826,6 +1962,7 @@ var Vector = class extends BaseResource {
|
|
|
1826
1962
|
super(options);
|
|
1827
1963
|
this.vectorName = vectorName;
|
|
1828
1964
|
}
|
|
1965
|
+
vectorName;
|
|
1829
1966
|
/**
|
|
1830
1967
|
* Retrieves details about a specific vector index
|
|
1831
1968
|
* @param indexName - Name of the index to get details for
|
|
@@ -1871,7 +2008,7 @@ var Vector = class extends BaseResource {
|
|
|
1871
2008
|
/**
|
|
1872
2009
|
* Upserts vectors into an index
|
|
1873
2010
|
* @param params - Parameters containing vectors, metadata, and optional IDs
|
|
1874
|
-
* @returns Promise containing
|
|
2011
|
+
* @returns Promise containing the inserted vector IDs
|
|
1875
2012
|
*/
|
|
1876
2013
|
upsert(params) {
|
|
1877
2014
|
return this.request(`/vector/${encodeURIComponent(this.vectorName)}/upsert`, {
|
|
@@ -1898,6 +2035,7 @@ var Tool = class extends BaseResource {
|
|
|
1898
2035
|
super(options);
|
|
1899
2036
|
this.toolId = toolId;
|
|
1900
2037
|
}
|
|
2038
|
+
toolId;
|
|
1901
2039
|
/**
|
|
1902
2040
|
* Retrieves details about the tool
|
|
1903
2041
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -1933,6 +2071,7 @@ var Processor = class extends BaseResource {
|
|
|
1933
2071
|
super(options);
|
|
1934
2072
|
this.processorId = processorId;
|
|
1935
2073
|
}
|
|
2074
|
+
processorId;
|
|
1936
2075
|
/**
|
|
1937
2076
|
* Retrieves details about the processor
|
|
1938
2077
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -2014,6 +2153,8 @@ var Run = class extends BaseResource {
|
|
|
2014
2153
|
this.workflowId = workflowId;
|
|
2015
2154
|
this.runId = runId;
|
|
2016
2155
|
}
|
|
2156
|
+
workflowId;
|
|
2157
|
+
runId;
|
|
2017
2158
|
/**
|
|
2018
2159
|
* Creates a transform stream that parses RECORD_SEPARATOR-delimited JSON chunks
|
|
2019
2160
|
*/
|
|
@@ -2147,6 +2288,7 @@ var Run = class extends BaseResource {
|
|
|
2147
2288
|
resumeData,
|
|
2148
2289
|
tracingOptions,
|
|
2149
2290
|
perStep,
|
|
2291
|
+
forEachIndex,
|
|
2150
2292
|
...rest
|
|
2151
2293
|
}) {
|
|
2152
2294
|
const requestContext = parseClientRequestContext(rest.requestContext);
|
|
@@ -2157,7 +2299,8 @@ var Run = class extends BaseResource {
|
|
|
2157
2299
|
resumeData,
|
|
2158
2300
|
requestContext,
|
|
2159
2301
|
tracingOptions,
|
|
2160
|
-
perStep
|
|
2302
|
+
perStep,
|
|
2303
|
+
forEachIndex
|
|
2161
2304
|
}
|
|
2162
2305
|
});
|
|
2163
2306
|
}
|
|
@@ -2213,19 +2356,32 @@ var Run = class extends BaseResource {
|
|
|
2213
2356
|
return response.body.pipeThrough(this.createChunkTransformStream());
|
|
2214
2357
|
}
|
|
2215
2358
|
/**
|
|
2216
|
-
*
|
|
2217
|
-
*
|
|
2359
|
+
* Observe (reconnect to) an existing workflow stream.
|
|
2360
|
+
* Use this to resume receiving events after a disconnection.
|
|
2361
|
+
*
|
|
2362
|
+
* @param params.offset - Optional position to resume from (0-based). If omitted, replays all events.
|
|
2363
|
+
* @returns Promise containing a ReadableStream of workflow events
|
|
2364
|
+
*
|
|
2365
|
+
* @example
|
|
2366
|
+
* ```typescript
|
|
2367
|
+
* // Reconnect to a workflow stream from a specific position
|
|
2368
|
+
* const stream = await run.observe({ offset: 42 });
|
|
2369
|
+
*
|
|
2370
|
+
* for await (const event of stream) {
|
|
2371
|
+
* console.log('Received:', event);
|
|
2372
|
+
* }
|
|
2373
|
+
* ```
|
|
2218
2374
|
*/
|
|
2219
|
-
async
|
|
2375
|
+
async observe(params) {
|
|
2220
2376
|
const searchParams = new URLSearchParams();
|
|
2221
2377
|
searchParams.set("runId", this.runId);
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
);
|
|
2378
|
+
if (params?.offset !== void 0) {
|
|
2379
|
+
searchParams.set("offset", String(params.offset));
|
|
2380
|
+
}
|
|
2381
|
+
const response = await this.request(`/workflows/${this.workflowId}/observe?${searchParams.toString()}`, {
|
|
2382
|
+
method: "POST",
|
|
2383
|
+
stream: true
|
|
2384
|
+
});
|
|
2229
2385
|
if (!response.ok) {
|
|
2230
2386
|
throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
|
|
2231
2387
|
}
|
|
@@ -2234,6 +2390,14 @@ var Run = class extends BaseResource {
|
|
|
2234
2390
|
}
|
|
2235
2391
|
return response.body.pipeThrough(this.createChunkTransformStream());
|
|
2236
2392
|
}
|
|
2393
|
+
/**
|
|
2394
|
+
* Observes workflow stream for a workflow run
|
|
2395
|
+
* @deprecated Use `observe()` instead for better control over replay position
|
|
2396
|
+
* @returns Promise containing the workflow execution results
|
|
2397
|
+
*/
|
|
2398
|
+
async observeStream() {
|
|
2399
|
+
return this.observe();
|
|
2400
|
+
}
|
|
2237
2401
|
/**
|
|
2238
2402
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
2239
2403
|
* @param params - Object containing the step, resumeData and requestContext
|
|
@@ -2248,7 +2412,8 @@ var Run = class extends BaseResource {
|
|
|
2248
2412
|
resumeData: params.resumeData,
|
|
2249
2413
|
requestContext,
|
|
2250
2414
|
tracingOptions: params.tracingOptions,
|
|
2251
|
-
perStep: params.perStep
|
|
2415
|
+
perStep: params.perStep,
|
|
2416
|
+
forEachIndex: params.forEachIndex
|
|
2252
2417
|
}
|
|
2253
2418
|
}).then(deserializeWorkflowError);
|
|
2254
2419
|
}
|
|
@@ -2270,7 +2435,8 @@ var Run = class extends BaseResource {
|
|
|
2270
2435
|
resumeData: params.resumeData,
|
|
2271
2436
|
requestContext,
|
|
2272
2437
|
tracingOptions: params.tracingOptions,
|
|
2273
|
-
perStep: params.perStep
|
|
2438
|
+
perStep: params.perStep,
|
|
2439
|
+
forEachIndex: params.forEachIndex
|
|
2274
2440
|
},
|
|
2275
2441
|
stream: true
|
|
2276
2442
|
}
|
|
@@ -2381,6 +2547,7 @@ var Workflow = class extends BaseResource {
|
|
|
2381
2547
|
super(options);
|
|
2382
2548
|
this.workflowId = workflowId;
|
|
2383
2549
|
}
|
|
2550
|
+
workflowId;
|
|
2384
2551
|
/**
|
|
2385
2552
|
* Retrieves details about the workflow
|
|
2386
2553
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -2528,26 +2695,162 @@ var Workflow = class extends BaseResource {
|
|
|
2528
2695
|
}
|
|
2529
2696
|
};
|
|
2530
2697
|
|
|
2698
|
+
// src/utils/process-a2a-stream.ts
|
|
2699
|
+
function splitNextEvent(buffer) {
|
|
2700
|
+
const normalizedBuffer = buffer.replace(/\x1E/g, "\n\n");
|
|
2701
|
+
const match = normalizedBuffer.match(/\r?\n\r?\n/);
|
|
2702
|
+
if (!match || match.index === void 0) {
|
|
2703
|
+
return { rest: normalizedBuffer };
|
|
2704
|
+
}
|
|
2705
|
+
const separatorLength = match[0].length;
|
|
2706
|
+
return {
|
|
2707
|
+
eventBlock: normalizedBuffer.slice(0, match.index),
|
|
2708
|
+
rest: normalizedBuffer.slice(match.index + separatorLength)
|
|
2709
|
+
};
|
|
2710
|
+
}
|
|
2711
|
+
function parseEventBlock(eventBlock) {
|
|
2712
|
+
const trimmedBlock = eventBlock.trim();
|
|
2713
|
+
if (!trimmedBlock) {
|
|
2714
|
+
return {};
|
|
2715
|
+
}
|
|
2716
|
+
const lines = trimmedBlock.split(/\r?\n/);
|
|
2717
|
+
const dataLines = lines.filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trimStart());
|
|
2718
|
+
const payload = dataLines.length > 0 ? dataLines.join("\n") : trimmedBlock;
|
|
2719
|
+
if (!payload || payload === "[DONE]") {
|
|
2720
|
+
return { done: true };
|
|
2721
|
+
}
|
|
2722
|
+
let parsed;
|
|
2723
|
+
try {
|
|
2724
|
+
parsed = JSON.parse(payload);
|
|
2725
|
+
} catch (error) {
|
|
2726
|
+
throw new Error(
|
|
2727
|
+
`Failed to parse A2A stream event: ${error instanceof Error ? error.message : "unknown parse error"}`
|
|
2728
|
+
);
|
|
2729
|
+
}
|
|
2730
|
+
if (parsed && typeof parsed === "object" && "error" in parsed && parsed.error) {
|
|
2731
|
+
throw new MastraClientError(200, "OK", `A2A stream error - ${JSON.stringify(parsed.error)}`, parsed.error);
|
|
2732
|
+
}
|
|
2733
|
+
if (parsed && typeof parsed === "object" && "result" in parsed) {
|
|
2734
|
+
return { event: parsed.result };
|
|
2735
|
+
}
|
|
2736
|
+
return { event: parsed };
|
|
2737
|
+
}
|
|
2738
|
+
async function* processA2AStream(stream) {
|
|
2739
|
+
const reader = stream.getReader();
|
|
2740
|
+
const decoder = new TextDecoder();
|
|
2741
|
+
let buffer = "";
|
|
2742
|
+
try {
|
|
2743
|
+
while (true) {
|
|
2744
|
+
const { done, value } = await reader.read();
|
|
2745
|
+
if (done) {
|
|
2746
|
+
buffer += decoder.decode();
|
|
2747
|
+
} else {
|
|
2748
|
+
buffer += decoder.decode(value, { stream: true });
|
|
2749
|
+
}
|
|
2750
|
+
while (true) {
|
|
2751
|
+
const { eventBlock, rest } = splitNextEvent(buffer);
|
|
2752
|
+
buffer = rest;
|
|
2753
|
+
if (!eventBlock) {
|
|
2754
|
+
break;
|
|
2755
|
+
}
|
|
2756
|
+
const parsedEvent = parseEventBlock(eventBlock);
|
|
2757
|
+
if (parsedEvent.done) {
|
|
2758
|
+
return;
|
|
2759
|
+
}
|
|
2760
|
+
if (parsedEvent.event) {
|
|
2761
|
+
yield parsedEvent.event;
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
if (done) {
|
|
2765
|
+
break;
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
if (buffer.trim()) {
|
|
2769
|
+
const parsedEvent = parseEventBlock(buffer);
|
|
2770
|
+
if (!parsedEvent.done && parsedEvent.event) {
|
|
2771
|
+
yield parsedEvent.event;
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
} finally {
|
|
2775
|
+
reader.releaseLock();
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2531
2779
|
// src/resources/a2a.ts
|
|
2780
|
+
function createA2AJsonRpcError(response) {
|
|
2781
|
+
const error = response.error;
|
|
2782
|
+
const message = error?.message ?? "Unknown A2A JSON-RPC error";
|
|
2783
|
+
return typeof error?.code === "number" ? new a2a.MastraA2AError(error.code, message, error.data) : new MastraClientError(200, "OK", `A2A JSON-RPC error - ${message}`, error);
|
|
2784
|
+
}
|
|
2785
|
+
function unwrapA2AResult(response) {
|
|
2786
|
+
if ("error" in response && response.error) {
|
|
2787
|
+
throw createA2AJsonRpcError(response);
|
|
2788
|
+
}
|
|
2789
|
+
if ("result" in response) {
|
|
2790
|
+
return response.result;
|
|
2791
|
+
}
|
|
2792
|
+
throw new MastraClientError(200, "OK", "A2A JSON-RPC response did not include a result", response);
|
|
2793
|
+
}
|
|
2794
|
+
async function requireResponseBody(response, method) {
|
|
2795
|
+
if (response.body) {
|
|
2796
|
+
return response.body;
|
|
2797
|
+
}
|
|
2798
|
+
const headerSummary = Array.from(response.headers.entries()).map(([key, value]) => `${key}: ${value}`).join(", ");
|
|
2799
|
+
let responseText = "";
|
|
2800
|
+
try {
|
|
2801
|
+
responseText = await response.text();
|
|
2802
|
+
} catch {
|
|
2803
|
+
}
|
|
2804
|
+
const details = [
|
|
2805
|
+
`A2A ${method} stream response did not include a body`,
|
|
2806
|
+
`(status: ${response.status} ${response.statusText})`,
|
|
2807
|
+
headerSummary ? `headers: ${headerSummary}` : "",
|
|
2808
|
+
responseText ? `body: ${responseText}` : ""
|
|
2809
|
+
].filter(Boolean).join(" ");
|
|
2810
|
+
throw new MastraClientError(response.status, response.statusText, details);
|
|
2811
|
+
}
|
|
2532
2812
|
var A2A = class extends BaseResource {
|
|
2533
2813
|
constructor(options, agentId) {
|
|
2534
2814
|
super(options);
|
|
2535
2815
|
this.agentId = agentId;
|
|
2536
2816
|
}
|
|
2817
|
+
agentId;
|
|
2537
2818
|
/**
|
|
2538
|
-
* Get the agent card with metadata about the agent
|
|
2819
|
+
* Get the agent card with metadata about the agent.
|
|
2539
2820
|
* @returns Promise containing the agent card information
|
|
2540
2821
|
*/
|
|
2541
|
-
async
|
|
2822
|
+
async getAgentCard() {
|
|
2542
2823
|
return this.request(`/.well-known/${this.agentId}/agent-card.json`);
|
|
2543
2824
|
}
|
|
2544
2825
|
/**
|
|
2545
|
-
*
|
|
2826
|
+
* @deprecated Use getAgentCard() instead.
|
|
2827
|
+
*/
|
|
2828
|
+
async getCard() {
|
|
2829
|
+
return this.getAgentCard();
|
|
2830
|
+
}
|
|
2831
|
+
/**
|
|
2832
|
+
* Get the authenticated extended agent card.
|
|
2833
|
+
* @returns Promise containing the authenticated extended agent card
|
|
2834
|
+
*/
|
|
2835
|
+
async getExtendedAgentCard() {
|
|
2836
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2837
|
+
method: "POST",
|
|
2838
|
+
body: {
|
|
2839
|
+
jsonrpc: "2.0",
|
|
2840
|
+
id: crypto.randomUUID(),
|
|
2841
|
+
method: "agent/getAuthenticatedExtendedCard"
|
|
2842
|
+
}
|
|
2843
|
+
});
|
|
2844
|
+
return unwrapA2AResult(response);
|
|
2845
|
+
}
|
|
2846
|
+
/**
|
|
2847
|
+
* @deprecated Use sendMessageStream() for the streaming experience.
|
|
2848
|
+
* Send a message to the agent and gets a message or task response.
|
|
2546
2849
|
* @param params - Parameters for the task
|
|
2547
|
-
* @returns Promise containing the response
|
|
2850
|
+
* @returns Promise containing the JSON-RPC response envelope
|
|
2548
2851
|
*/
|
|
2549
2852
|
async sendMessage(params) {
|
|
2550
|
-
|
|
2853
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
2551
2854
|
method: "POST",
|
|
2552
2855
|
body: {
|
|
2553
2856
|
jsonrpc: "2.0",
|
|
@@ -2556,15 +2859,14 @@ var A2A = class extends BaseResource {
|
|
|
2556
2859
|
params
|
|
2557
2860
|
}
|
|
2558
2861
|
});
|
|
2559
|
-
return response;
|
|
2560
2862
|
}
|
|
2561
2863
|
/**
|
|
2562
|
-
* Sends a message to an agent to initiate
|
|
2864
|
+
* Sends a message to an agent to initiate or continue a task and subscribes
|
|
2563
2865
|
* the client to real-time updates for that task via Server-Sent Events (SSE).
|
|
2564
2866
|
* @param params - Parameters for the task
|
|
2565
|
-
* @returns
|
|
2867
|
+
* @returns An async generator of typed A2A stream events
|
|
2566
2868
|
*/
|
|
2567
|
-
async
|
|
2869
|
+
async *sendMessageStream(params) {
|
|
2568
2870
|
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2569
2871
|
method: "POST",
|
|
2570
2872
|
body: {
|
|
@@ -2575,15 +2877,30 @@ var A2A = class extends BaseResource {
|
|
|
2575
2877
|
},
|
|
2576
2878
|
stream: true
|
|
2577
2879
|
});
|
|
2578
|
-
|
|
2880
|
+
yield* processA2AStream(await requireResponseBody(response, "message/stream"));
|
|
2881
|
+
}
|
|
2882
|
+
/**
|
|
2883
|
+
* @deprecated Use sendMessageStream() instead.
|
|
2884
|
+
*/
|
|
2885
|
+
async sendStreamingMessage(params) {
|
|
2886
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
2887
|
+
method: "POST",
|
|
2888
|
+
body: {
|
|
2889
|
+
jsonrpc: "2.0",
|
|
2890
|
+
id: crypto.randomUUID(),
|
|
2891
|
+
method: "message/stream",
|
|
2892
|
+
params
|
|
2893
|
+
},
|
|
2894
|
+
stream: true
|
|
2895
|
+
});
|
|
2579
2896
|
}
|
|
2580
2897
|
/**
|
|
2581
|
-
* Get the status and result of a task
|
|
2898
|
+
* Get the status and result of a task.
|
|
2582
2899
|
* @param params - Parameters for querying the task
|
|
2583
|
-
* @returns Promise containing the
|
|
2900
|
+
* @returns Promise containing the JSON-RPC response envelope
|
|
2584
2901
|
*/
|
|
2585
2902
|
async getTask(params) {
|
|
2586
|
-
|
|
2903
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
2587
2904
|
method: "POST",
|
|
2588
2905
|
body: {
|
|
2589
2906
|
jsonrpc: "2.0",
|
|
@@ -2592,10 +2909,9 @@ var A2A = class extends BaseResource {
|
|
|
2592
2909
|
params
|
|
2593
2910
|
}
|
|
2594
2911
|
});
|
|
2595
|
-
return response;
|
|
2596
2912
|
}
|
|
2597
2913
|
/**
|
|
2598
|
-
* Cancel a running task
|
|
2914
|
+
* Cancel a running task.
|
|
2599
2915
|
* @param params - Parameters identifying the task to cancel
|
|
2600
2916
|
* @returns Promise containing the task response
|
|
2601
2917
|
*/
|
|
@@ -2610,6 +2926,92 @@ var A2A = class extends BaseResource {
|
|
|
2610
2926
|
}
|
|
2611
2927
|
});
|
|
2612
2928
|
}
|
|
2929
|
+
/**
|
|
2930
|
+
* Resume a task stream for an existing task.
|
|
2931
|
+
* @param params - Parameters identifying the task to resubscribe to
|
|
2932
|
+
* @returns An async generator of typed A2A stream events
|
|
2933
|
+
*/
|
|
2934
|
+
async *resubscribeTask(params) {
|
|
2935
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2936
|
+
method: "POST",
|
|
2937
|
+
body: {
|
|
2938
|
+
jsonrpc: "2.0",
|
|
2939
|
+
id: crypto.randomUUID(),
|
|
2940
|
+
method: "tasks/resubscribe",
|
|
2941
|
+
params
|
|
2942
|
+
},
|
|
2943
|
+
stream: true
|
|
2944
|
+
});
|
|
2945
|
+
yield* processA2AStream(await requireResponseBody(response, "tasks/resubscribe"));
|
|
2946
|
+
}
|
|
2947
|
+
/**
|
|
2948
|
+
* Set push notification config for a task.
|
|
2949
|
+
* @param params - Push notification configuration for the task
|
|
2950
|
+
* @returns Promise containing the push notification configuration
|
|
2951
|
+
*/
|
|
2952
|
+
async setTaskPushNotificationConfig(params) {
|
|
2953
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2954
|
+
method: "POST",
|
|
2955
|
+
body: {
|
|
2956
|
+
jsonrpc: "2.0",
|
|
2957
|
+
id: crypto.randomUUID(),
|
|
2958
|
+
method: "tasks/pushNotificationConfig/set",
|
|
2959
|
+
params
|
|
2960
|
+
}
|
|
2961
|
+
});
|
|
2962
|
+
return unwrapA2AResult(response);
|
|
2963
|
+
}
|
|
2964
|
+
/**
|
|
2965
|
+
* Get push notification config for a task.
|
|
2966
|
+
* @param params - Parameters identifying the task
|
|
2967
|
+
* @returns Promise containing the push notification configuration
|
|
2968
|
+
*/
|
|
2969
|
+
async getTaskPushNotificationConfig(params) {
|
|
2970
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2971
|
+
method: "POST",
|
|
2972
|
+
body: {
|
|
2973
|
+
jsonrpc: "2.0",
|
|
2974
|
+
id: crypto.randomUUID(),
|
|
2975
|
+
method: "tasks/pushNotificationConfig/get",
|
|
2976
|
+
params
|
|
2977
|
+
}
|
|
2978
|
+
});
|
|
2979
|
+
return unwrapA2AResult(response);
|
|
2980
|
+
}
|
|
2981
|
+
/**
|
|
2982
|
+
* List push notification configs for a task.
|
|
2983
|
+
* @param params - Parameters identifying the task
|
|
2984
|
+
* @returns Promise containing the push notification configurations
|
|
2985
|
+
*/
|
|
2986
|
+
async listTaskPushNotificationConfig(params) {
|
|
2987
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2988
|
+
method: "POST",
|
|
2989
|
+
body: {
|
|
2990
|
+
jsonrpc: "2.0",
|
|
2991
|
+
id: crypto.randomUUID(),
|
|
2992
|
+
method: "tasks/pushNotificationConfig/list",
|
|
2993
|
+
params
|
|
2994
|
+
}
|
|
2995
|
+
});
|
|
2996
|
+
return unwrapA2AResult(response);
|
|
2997
|
+
}
|
|
2998
|
+
/**
|
|
2999
|
+
* Delete a push notification config for a task.
|
|
3000
|
+
* @param params - Parameters identifying the config to delete
|
|
3001
|
+
* @returns Promise that resolves when the config is deleted
|
|
3002
|
+
*/
|
|
3003
|
+
async deleteTaskPushNotificationConfig(params) {
|
|
3004
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
3005
|
+
method: "POST",
|
|
3006
|
+
body: {
|
|
3007
|
+
jsonrpc: "2.0",
|
|
3008
|
+
id: crypto.randomUUID(),
|
|
3009
|
+
method: "tasks/pushNotificationConfig/delete",
|
|
3010
|
+
params
|
|
3011
|
+
}
|
|
3012
|
+
});
|
|
3013
|
+
unwrapA2AResult(response);
|
|
3014
|
+
}
|
|
2613
3015
|
};
|
|
2614
3016
|
|
|
2615
3017
|
// src/resources/mcp-tool.ts
|
|
@@ -2656,6 +3058,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2656
3058
|
super(options);
|
|
2657
3059
|
this.actionId = actionId;
|
|
2658
3060
|
}
|
|
3061
|
+
actionId;
|
|
2659
3062
|
// Helper function to transform workflow result to action result
|
|
2660
3063
|
transformWorkflowResult(result) {
|
|
2661
3064
|
if (result.status === "success") {
|
|
@@ -3023,6 +3426,27 @@ var Observability = class extends BaseResource {
|
|
|
3023
3426
|
getTrace(traceId) {
|
|
3024
3427
|
return this.request(`/observability/traces/${traceId}`);
|
|
3025
3428
|
}
|
|
3429
|
+
/**
|
|
3430
|
+
* Retrieves a lightweight trace by ID (timeline fields only).
|
|
3431
|
+
* Excludes heavy fields (input, output, attributes, metadata, tags, links)
|
|
3432
|
+
* for ~97% payload reduction compared to getTrace.
|
|
3433
|
+
*
|
|
3434
|
+
* @param traceId - ID of the trace to retrieve
|
|
3435
|
+
* @returns Promise containing the trace with lightweight spans
|
|
3436
|
+
*/
|
|
3437
|
+
getTraceLight(traceId) {
|
|
3438
|
+
return this.request(`/observability/traces/${traceId}/light`);
|
|
3439
|
+
}
|
|
3440
|
+
/**
|
|
3441
|
+
* Retrieves a single span with full details by trace ID and span ID.
|
|
3442
|
+
*
|
|
3443
|
+
* @param traceId - ID of the trace containing the span
|
|
3444
|
+
* @param spanId - ID of the span to retrieve
|
|
3445
|
+
* @returns Promise containing the full span record
|
|
3446
|
+
*/
|
|
3447
|
+
getSpan(traceId, spanId) {
|
|
3448
|
+
return this.request(`/observability/traces/${traceId}/spans/${spanId}`);
|
|
3449
|
+
}
|
|
3026
3450
|
/**
|
|
3027
3451
|
* Extracts a structured trajectory from a trace's spans.
|
|
3028
3452
|
*
|
|
@@ -3330,6 +3754,7 @@ var StoredAgent = class extends BaseResource {
|
|
|
3330
3754
|
super(options);
|
|
3331
3755
|
this.storedAgentId = storedAgentId;
|
|
3332
3756
|
}
|
|
3757
|
+
storedAgentId;
|
|
3333
3758
|
/**
|
|
3334
3759
|
* Retrieves details about the stored agent
|
|
3335
3760
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -3483,6 +3908,7 @@ var StoredPromptBlock = class extends BaseResource {
|
|
|
3483
3908
|
super(options);
|
|
3484
3909
|
this.storedPromptBlockId = storedPromptBlockId;
|
|
3485
3910
|
}
|
|
3911
|
+
storedPromptBlockId;
|
|
3486
3912
|
/**
|
|
3487
3913
|
* Retrieves details about the stored prompt block
|
|
3488
3914
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -3636,6 +4062,7 @@ var StoredMCPClient = class extends BaseResource {
|
|
|
3636
4062
|
super(options);
|
|
3637
4063
|
this.storedMCPClientId = storedMCPClientId;
|
|
3638
4064
|
}
|
|
4065
|
+
storedMCPClientId;
|
|
3639
4066
|
/**
|
|
3640
4067
|
* Retrieves details about the stored MCP client
|
|
3641
4068
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -3682,6 +4109,7 @@ var StoredScorer = class extends BaseResource {
|
|
|
3682
4109
|
super(options);
|
|
3683
4110
|
this.storedScorerId = storedScorerId;
|
|
3684
4111
|
}
|
|
4112
|
+
storedScorerId;
|
|
3685
4113
|
/**
|
|
3686
4114
|
* Retrieves details about the stored scorer definition
|
|
3687
4115
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -3836,6 +4264,7 @@ var ToolProvider = class extends BaseResource {
|
|
|
3836
4264
|
super(options);
|
|
3837
4265
|
this.providerId = providerId;
|
|
3838
4266
|
}
|
|
4267
|
+
providerId;
|
|
3839
4268
|
/**
|
|
3840
4269
|
* Lists available toolkits from this provider
|
|
3841
4270
|
* @returns Promise containing list of toolkits
|
|
@@ -3885,6 +4314,7 @@ var ProcessorProvider = class extends BaseResource {
|
|
|
3885
4314
|
super(options);
|
|
3886
4315
|
this.providerId = providerId;
|
|
3887
4316
|
}
|
|
4317
|
+
providerId;
|
|
3888
4318
|
/**
|
|
3889
4319
|
* Gets details about this processor provider and its available processors
|
|
3890
4320
|
* @returns Promise containing provider info and processor list
|
|
@@ -3904,6 +4334,9 @@ var WorkspaceSkillResource = class extends BaseResource {
|
|
|
3904
4334
|
this.basePath = `/workspaces/${encodeURIComponent(this.workspaceId)}/skills/${encodeURIComponent(this.skillName)}`;
|
|
3905
4335
|
this.pathQuery = this.skillPath ? `?path=${encodeURIComponent(this.skillPath)}` : "";
|
|
3906
4336
|
}
|
|
4337
|
+
workspaceId;
|
|
4338
|
+
skillName;
|
|
4339
|
+
skillPath;
|
|
3907
4340
|
basePath;
|
|
3908
4341
|
pathQuery;
|
|
3909
4342
|
/**
|
|
@@ -4123,6 +4556,7 @@ var StoredSkill = class extends BaseResource {
|
|
|
4123
4556
|
super(options);
|
|
4124
4557
|
this.storedSkillId = storedSkillId;
|
|
4125
4558
|
}
|
|
4559
|
+
storedSkillId;
|
|
4126
4560
|
/**
|
|
4127
4561
|
* Retrieves details about the stored skill
|
|
4128
4562
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -4219,6 +4653,7 @@ var ResponsesStream = class {
|
|
|
4219
4653
|
constructor(response) {
|
|
4220
4654
|
this.response = response;
|
|
4221
4655
|
}
|
|
4656
|
+
response;
|
|
4222
4657
|
asResponse() {
|
|
4223
4658
|
return this.response;
|
|
4224
4659
|
}
|
|
@@ -4298,16 +4733,68 @@ var Responses = class extends BaseResource {
|
|
|
4298
4733
|
}
|
|
4299
4734
|
};
|
|
4300
4735
|
|
|
4736
|
+
// src/resources/channels.ts
|
|
4737
|
+
var Channels = class extends BaseResource {
|
|
4738
|
+
constructor(options) {
|
|
4739
|
+
super(options);
|
|
4740
|
+
}
|
|
4741
|
+
/**
|
|
4742
|
+
* Lists all registered channel platforms and their configuration status.
|
|
4743
|
+
* @returns Array of available platforms
|
|
4744
|
+
*/
|
|
4745
|
+
listPlatforms() {
|
|
4746
|
+
return this.request("/channels/platforms");
|
|
4747
|
+
}
|
|
4748
|
+
/**
|
|
4749
|
+
* Lists installations for a given platform, optionally filtered by agent.
|
|
4750
|
+
* @param platform - Platform identifier (e.g., "slack")
|
|
4751
|
+
* @param agentId - Optional agent ID to filter by (client-side)
|
|
4752
|
+
* @returns Array of installations
|
|
4753
|
+
*/
|
|
4754
|
+
async listInstallations(platform, agentId) {
|
|
4755
|
+
const all = await this.request(`/channels/${platform}/installations`);
|
|
4756
|
+
if (agentId) {
|
|
4757
|
+
return all.filter((i) => i.agentId === agentId);
|
|
4758
|
+
}
|
|
4759
|
+
return all;
|
|
4760
|
+
}
|
|
4761
|
+
/**
|
|
4762
|
+
* Connects an agent to a channel platform.
|
|
4763
|
+
* @param platform - Platform identifier (e.g., "slack")
|
|
4764
|
+
* @param agentId - Agent to connect
|
|
4765
|
+
* @param options - Platform-specific connection options
|
|
4766
|
+
* @returns Discriminated connect result — check `type` for the authorization flow
|
|
4767
|
+
*/
|
|
4768
|
+
connect(platform, agentId, options) {
|
|
4769
|
+
return this.request(`/channels/${platform}/connect`, {
|
|
4770
|
+
method: "POST",
|
|
4771
|
+
body: { agentId, options }
|
|
4772
|
+
});
|
|
4773
|
+
}
|
|
4774
|
+
/**
|
|
4775
|
+
* Disconnects an agent from a channel platform.
|
|
4776
|
+
* @param platform - Platform identifier (e.g., "slack")
|
|
4777
|
+
* @param agentId - Agent to disconnect
|
|
4778
|
+
*/
|
|
4779
|
+
disconnect(platform, agentId) {
|
|
4780
|
+
return this.request(`/channels/${platform}/${agentId}/disconnect`, {
|
|
4781
|
+
method: "POST"
|
|
4782
|
+
});
|
|
4783
|
+
}
|
|
4784
|
+
};
|
|
4785
|
+
|
|
4301
4786
|
// src/client.ts
|
|
4302
4787
|
var MastraClient = class extends BaseResource {
|
|
4303
4788
|
observability;
|
|
4304
4789
|
conversations;
|
|
4305
4790
|
responses;
|
|
4791
|
+
channels;
|
|
4306
4792
|
constructor(options) {
|
|
4307
4793
|
super(options);
|
|
4308
4794
|
this.observability = new Observability(options);
|
|
4309
4795
|
this.conversations = new Conversations(options);
|
|
4310
4796
|
this.responses = new Responses(options);
|
|
4797
|
+
this.channels = new Channels(options);
|
|
4311
4798
|
}
|
|
4312
4799
|
/**
|
|
4313
4800
|
* Retrieves all available agents
|
|
@@ -4410,12 +4897,13 @@ var MastraClient = class extends BaseResource {
|
|
|
4410
4897
|
*/
|
|
4411
4898
|
listThreadMessages(threadId, opts = {}) {
|
|
4412
4899
|
let url = "";
|
|
4900
|
+
const includeSystemRemindersQuery = opts.includeSystemReminders === void 0 ? "" : `includeSystemReminders=${opts.includeSystemReminders}`;
|
|
4413
4901
|
if (opts.networkId) {
|
|
4414
|
-
url = `/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
4902
|
+
url = `/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${includeSystemRemindersQuery ? `&${includeSystemRemindersQuery}` : ""}${requestContextQueryString(opts.requestContext, includeSystemRemindersQuery ? "&" : "&")}`;
|
|
4415
4903
|
} else if (opts.agentId) {
|
|
4416
|
-
url = `/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
4904
|
+
url = `/memory/threads/${threadId}/messages?agentId=${opts.agentId}${includeSystemRemindersQuery ? `&${includeSystemRemindersQuery}` : ""}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
4417
4905
|
} else {
|
|
4418
|
-
url = `/memory/threads/${threadId}/messages${requestContextQueryString(opts.requestContext, "?")}`;
|
|
4906
|
+
url = `/memory/threads/${threadId}/messages${includeSystemRemindersQuery ? `?${includeSystemRemindersQuery}` : ""}${requestContextQueryString(opts.requestContext, includeSystemRemindersQuery ? "&" : "?")}`;
|
|
4419
4907
|
}
|
|
4420
4908
|
return this.request(url);
|
|
4421
4909
|
}
|
|
@@ -4464,6 +4952,14 @@ var MastraClient = class extends BaseResource {
|
|
|
4464
4952
|
const queryParams = new URLSearchParams({ agentId: params.agentId });
|
|
4465
4953
|
if (params.resourceId) queryParams.set("resourceId", params.resourceId);
|
|
4466
4954
|
if (params.threadId) queryParams.set("threadId", params.threadId);
|
|
4955
|
+
if (params.from) {
|
|
4956
|
+
queryParams.set("from", params.from instanceof Date ? params.from.toISOString() : params.from);
|
|
4957
|
+
}
|
|
4958
|
+
if (params.to) {
|
|
4959
|
+
queryParams.set("to", params.to instanceof Date ? params.to.toISOString() : params.to);
|
|
4960
|
+
}
|
|
4961
|
+
if (params.offset != null) queryParams.set("offset", String(params.offset));
|
|
4962
|
+
if (params.limit != null) queryParams.set("limit", String(params.limit));
|
|
4467
4963
|
const queryString = queryParams.toString();
|
|
4468
4964
|
return this.request(
|
|
4469
4965
|
`/memory/observational-memory?${queryString}${requestContextQueryString(params.requestContext, "&")}`
|
|
@@ -4882,6 +5378,14 @@ var MastraClient = class extends BaseResource {
|
|
|
4882
5378
|
getTrace(traceId) {
|
|
4883
5379
|
return this.observability.getTrace(traceId);
|
|
4884
5380
|
}
|
|
5381
|
+
/** Retrieves a lightweight trace by ID (timeline fields only, excludes heavy fields). */
|
|
5382
|
+
getTraceLight(traceId) {
|
|
5383
|
+
return this.observability.getTraceLight(traceId);
|
|
5384
|
+
}
|
|
5385
|
+
/** Retrieves a single span with full details by trace ID and span ID. */
|
|
5386
|
+
getSpan(traceId, spanId) {
|
|
5387
|
+
return this.observability.getSpan(traceId, spanId);
|
|
5388
|
+
}
|
|
4885
5389
|
/** Extracts a structured trajectory from a trace's spans. */
|
|
4886
5390
|
getTraceTrajectory(traceId) {
|
|
4887
5391
|
return this.observability.getTraceTrajectory(traceId);
|
|
@@ -5629,6 +6133,123 @@ var MastraClient = class extends BaseResource {
|
|
|
5629
6133
|
body
|
|
5630
6134
|
});
|
|
5631
6135
|
}
|
|
6136
|
+
// ============================================================================
|
|
6137
|
+
// Background Tasks
|
|
6138
|
+
// ============================================================================
|
|
6139
|
+
/**
|
|
6140
|
+
* Lists background tasks with optional filtering and pagination.
|
|
6141
|
+
*/
|
|
6142
|
+
listBackgroundTasks(params = {}) {
|
|
6143
|
+
const searchParams = new URLSearchParams();
|
|
6144
|
+
if (params.agentId) searchParams.set("agentId", params.agentId);
|
|
6145
|
+
if (params.status) searchParams.set("status", params.status);
|
|
6146
|
+
if (params.runId) searchParams.set("runId", params.runId);
|
|
6147
|
+
if (params.threadId) searchParams.set("threadId", params.threadId);
|
|
6148
|
+
if (params.resourceId) searchParams.set("resourceId", params.resourceId);
|
|
6149
|
+
if (params.fromDate) searchParams.set("fromDate", params.fromDate.toISOString());
|
|
6150
|
+
if (params.toDate) searchParams.set("toDate", params.toDate.toISOString());
|
|
6151
|
+
if (params.dateFilterBy) searchParams.set("dateFilterBy", params.dateFilterBy);
|
|
6152
|
+
if (params.orderBy) searchParams.set("orderBy", params.orderBy);
|
|
6153
|
+
if (params.orderDirection) searchParams.set("orderDirection", params.orderDirection);
|
|
6154
|
+
if (params.page !== void 0) searchParams.set("page", String(params.page));
|
|
6155
|
+
if (params.perPage !== void 0) searchParams.set("perPage", String(params.perPage));
|
|
6156
|
+
const qs = searchParams.toString();
|
|
6157
|
+
return this.request(`/background-tasks${qs ? `?${qs}` : ""}`);
|
|
6158
|
+
}
|
|
6159
|
+
/**
|
|
6160
|
+
* Gets a single background task by ID.
|
|
6161
|
+
*/
|
|
6162
|
+
getBackgroundTask(backgroundTaskId) {
|
|
6163
|
+
return this.request(`/background-tasks/${encodeURIComponent(backgroundTaskId)}`);
|
|
6164
|
+
}
|
|
6165
|
+
/**
|
|
6166
|
+
* Opens an SSE stream of background task events (completed/failed).
|
|
6167
|
+
* Returns a Response that can be consumed as a ReadableStream.
|
|
6168
|
+
*/
|
|
6169
|
+
async streamBackgroundTasks(params = {}) {
|
|
6170
|
+
const searchParams = new URLSearchParams();
|
|
6171
|
+
if (params.agentId) searchParams.set("agentId", params.agentId);
|
|
6172
|
+
if (params.runId) searchParams.set("runId", params.runId);
|
|
6173
|
+
if (params.threadId) searchParams.set("threadId", params.threadId);
|
|
6174
|
+
if (params.resourceId) searchParams.set("resourceId", params.resourceId);
|
|
6175
|
+
if (params.taskId) searchParams.set("taskId", params.taskId);
|
|
6176
|
+
const qs = searchParams.toString();
|
|
6177
|
+
const response = await this.request(`/background-tasks/stream${qs ? `?${qs}` : ""}`, { stream: true });
|
|
6178
|
+
if (!response.ok) {
|
|
6179
|
+
throw new Error(`Failed to stream background tasks: ${response.statusText}`);
|
|
6180
|
+
}
|
|
6181
|
+
if (!response.body) {
|
|
6182
|
+
throw new Error("Response body is null");
|
|
6183
|
+
}
|
|
6184
|
+
let failedChunk = void 0;
|
|
6185
|
+
return response.body.pipeThrough(
|
|
6186
|
+
new TransformStream({
|
|
6187
|
+
async transform(chunk, controller) {
|
|
6188
|
+
try {
|
|
6189
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
6190
|
+
const chunks = decoded.split("\n\n");
|
|
6191
|
+
for (const chunk2 of chunks) {
|
|
6192
|
+
if (chunk2) {
|
|
6193
|
+
const cleanChunk = chunk2.substring("data: ".length);
|
|
6194
|
+
const newChunk = failedChunk ? failedChunk + cleanChunk : cleanChunk;
|
|
6195
|
+
try {
|
|
6196
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
6197
|
+
controller.enqueue(parsedChunk);
|
|
6198
|
+
failedChunk = void 0;
|
|
6199
|
+
} catch {
|
|
6200
|
+
failedChunk = newChunk;
|
|
6201
|
+
}
|
|
6202
|
+
}
|
|
6203
|
+
}
|
|
6204
|
+
} catch {
|
|
6205
|
+
}
|
|
6206
|
+
}
|
|
6207
|
+
})
|
|
6208
|
+
);
|
|
6209
|
+
}
|
|
6210
|
+
/**
|
|
6211
|
+
* Lists workflow schedules with optional filtering by workflowId or status.
|
|
6212
|
+
*/
|
|
6213
|
+
listSchedules(params = {}) {
|
|
6214
|
+
const searchParams = new URLSearchParams();
|
|
6215
|
+
if (params.workflowId) searchParams.set("workflowId", params.workflowId);
|
|
6216
|
+
if (params.status) searchParams.set("status", params.status);
|
|
6217
|
+
const qs = searchParams.toString();
|
|
6218
|
+
return this.request(`/schedules${qs ? `?${qs}` : ""}`);
|
|
6219
|
+
}
|
|
6220
|
+
/**
|
|
6221
|
+
* Gets a single schedule by ID.
|
|
6222
|
+
*/
|
|
6223
|
+
getSchedule(scheduleId) {
|
|
6224
|
+
return this.request(`/schedules/${encodeURIComponent(scheduleId)}`);
|
|
6225
|
+
}
|
|
6226
|
+
/**
|
|
6227
|
+
* Lists trigger history for a schedule, ordered by actualFireAt descending.
|
|
6228
|
+
*/
|
|
6229
|
+
listScheduleTriggers(scheduleId, params = {}) {
|
|
6230
|
+
const searchParams = new URLSearchParams();
|
|
6231
|
+
if (params.limit !== void 0) searchParams.set("limit", String(params.limit));
|
|
6232
|
+
if (params.fromActualFireAt !== void 0) searchParams.set("fromActualFireAt", String(params.fromActualFireAt));
|
|
6233
|
+
if (params.toActualFireAt !== void 0) searchParams.set("toActualFireAt", String(params.toActualFireAt));
|
|
6234
|
+
const qs = searchParams.toString();
|
|
6235
|
+
return this.request(`/schedules/${encodeURIComponent(scheduleId)}/triggers${qs ? `?${qs}` : ""}`);
|
|
6236
|
+
}
|
|
6237
|
+
/**
|
|
6238
|
+
* Pauses a schedule. The scheduler tick loop will skip paused schedules.
|
|
6239
|
+
* Idempotent — pausing an already-paused schedule returns the current state unchanged.
|
|
6240
|
+
* Pause status survives redeploys.
|
|
6241
|
+
*/
|
|
6242
|
+
pauseSchedule(scheduleId) {
|
|
6243
|
+
return this.request(`/schedules/${encodeURIComponent(scheduleId)}/pause`, { method: "POST" });
|
|
6244
|
+
}
|
|
6245
|
+
/**
|
|
6246
|
+
* Resumes a paused schedule. Recomputes nextFireAt from "now" so a long-paused schedule
|
|
6247
|
+
* does not fire a backlog. Idempotent — resuming an already-active schedule returns
|
|
6248
|
+
* the current state unchanged.
|
|
6249
|
+
*/
|
|
6250
|
+
resumeSchedule(scheduleId) {
|
|
6251
|
+
return this.request(`/schedules/${encodeURIComponent(scheduleId)}/resume`, { method: "POST" });
|
|
6252
|
+
}
|
|
5632
6253
|
};
|
|
5633
6254
|
|
|
5634
6255
|
// src/tools.ts
|
|
@@ -5650,6 +6271,10 @@ function createTool(opts) {
|
|
|
5650
6271
|
return new ClientTool(opts);
|
|
5651
6272
|
}
|
|
5652
6273
|
|
|
6274
|
+
Object.defineProperty(exports, "RequestContext", {
|
|
6275
|
+
enumerable: true,
|
|
6276
|
+
get: function () { return requestContext.RequestContext; }
|
|
6277
|
+
});
|
|
5653
6278
|
exports.ClientTool = ClientTool;
|
|
5654
6279
|
exports.MastraClient = MastraClient;
|
|
5655
6280
|
exports.MastraClientError = MastraClientError;
|