@mastra/client-js 0.0.0-fix-cloud-peer-deps-loggers-20250929204101 → 0.0.0-fix-maxSteps-modelsetting-playground-20251008194458
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 +143 -3
- package/README.md +4 -4
- package/dist/client.d.ts +1 -13
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +165 -201
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +165 -201
- package/dist/index.js.map +1 -1
- package/dist/resources/agent.d.ts +24 -31
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/workflow.d.ts +23 -8
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/types.d.ts +13 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/process-mastra-stream.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/resources/vNextNetwork.d.ts +0 -43
- package/dist/resources/vNextNetwork.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -323,12 +323,6 @@ var Agent = class extends BaseResource {
|
|
|
323
323
|
details(runtimeContext) {
|
|
324
324
|
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
325
325
|
}
|
|
326
|
-
async generate(params) {
|
|
327
|
-
console.warn(
|
|
328
|
-
"Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 30th, 2025. Please use generateLegacy if you don't want to upgrade just yet."
|
|
329
|
-
);
|
|
330
|
-
return this.generateLegacy(params);
|
|
331
|
-
}
|
|
332
326
|
async generateLegacy(params) {
|
|
333
327
|
const processedParams = {
|
|
334
328
|
...params,
|
|
@@ -392,7 +386,7 @@ var Agent = class extends BaseResource {
|
|
|
392
386
|
}
|
|
393
387
|
return response;
|
|
394
388
|
}
|
|
395
|
-
async
|
|
389
|
+
async generate(messagesOrParams, options) {
|
|
396
390
|
let params;
|
|
397
391
|
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
398
392
|
params = messagesOrParams;
|
|
@@ -414,7 +408,7 @@ var Agent = class extends BaseResource {
|
|
|
414
408
|
};
|
|
415
409
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
416
410
|
const response = await this.request(
|
|
417
|
-
`/api/agents/${this.agentId}/generate
|
|
411
|
+
`/api/agents/${this.agentId}/generate`,
|
|
418
412
|
{
|
|
419
413
|
method: "POST",
|
|
420
414
|
body: processedParams
|
|
@@ -428,7 +422,7 @@ var Agent = class extends BaseResource {
|
|
|
428
422
|
resourceId,
|
|
429
423
|
threadId,
|
|
430
424
|
runtimeContext,
|
|
431
|
-
respondFn: this.
|
|
425
|
+
respondFn: this.generate.bind(this)
|
|
432
426
|
});
|
|
433
427
|
}
|
|
434
428
|
return response;
|
|
@@ -695,17 +689,6 @@ var Agent = class extends BaseResource {
|
|
|
695
689
|
});
|
|
696
690
|
onFinish?.({ message, finishReason, usage });
|
|
697
691
|
}
|
|
698
|
-
/**
|
|
699
|
-
* Streams a response from the agent
|
|
700
|
-
* @param params - Stream parameters including prompt
|
|
701
|
-
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
702
|
-
*/
|
|
703
|
-
async stream(params) {
|
|
704
|
-
console.warn(
|
|
705
|
-
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 30th, 2025. Please use streamLegacy if you don't want to upgrade just yet."
|
|
706
|
-
);
|
|
707
|
-
return this.streamLegacy(params);
|
|
708
|
-
}
|
|
709
692
|
/**
|
|
710
693
|
* Streams a response from the agent
|
|
711
694
|
* @param params - Stream parameters including prompt
|
|
@@ -807,6 +790,14 @@ var Agent = class extends BaseResource {
|
|
|
807
790
|
// but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
|
|
808
791
|
onChunk: async (chunk) => {
|
|
809
792
|
switch (chunk.type) {
|
|
793
|
+
case "tripwire": {
|
|
794
|
+
message.parts.push({
|
|
795
|
+
type: "text",
|
|
796
|
+
text: chunk.payload.tripwireReason
|
|
797
|
+
});
|
|
798
|
+
execUpdate();
|
|
799
|
+
break;
|
|
800
|
+
}
|
|
810
801
|
case "step-start": {
|
|
811
802
|
if (!replaceLastMessage) {
|
|
812
803
|
message.id = chunk.payload.messageId;
|
|
@@ -988,7 +979,7 @@ var Agent = class extends BaseResource {
|
|
|
988
979
|
onFinish?.({ message, finishReason, usage });
|
|
989
980
|
}
|
|
990
981
|
async processStreamResponse_vNext(processedParams, writable) {
|
|
991
|
-
const response = await this.request(`/api/agents/${this.agentId}/stream
|
|
982
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
992
983
|
method: "POST",
|
|
993
984
|
body: processedParams,
|
|
994
985
|
stream: true
|
|
@@ -1003,18 +994,17 @@ var Agent = class extends BaseResource {
|
|
|
1003
994
|
streamForWritable.pipeTo(
|
|
1004
995
|
new WritableStream({
|
|
1005
996
|
async write(chunk) {
|
|
997
|
+
let writer;
|
|
1006
998
|
try {
|
|
999
|
+
writer = writable.getWriter();
|
|
1007
1000
|
const text = new TextDecoder().decode(chunk);
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1001
|
+
const lines = text.split("\n\n");
|
|
1002
|
+
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
1003
|
+
await writer.write(new TextEncoder().encode(readableLines));
|
|
1011
1004
|
} catch {
|
|
1012
|
-
|
|
1013
|
-
const writer = writable.getWriter();
|
|
1014
|
-
try {
|
|
1015
|
-
await writer.write(chunk);
|
|
1005
|
+
await writer?.write(chunk);
|
|
1016
1006
|
} finally {
|
|
1017
|
-
writer
|
|
1007
|
+
writer?.releaseLock();
|
|
1018
1008
|
}
|
|
1019
1009
|
}
|
|
1020
1010
|
}),
|
|
@@ -1040,9 +1030,11 @@ var Agent = class extends BaseResource {
|
|
|
1040
1030
|
if (toolCall) {
|
|
1041
1031
|
toolCalls.push(toolCall);
|
|
1042
1032
|
}
|
|
1033
|
+
let shouldExecuteClientTool = false;
|
|
1043
1034
|
for (const toolCall2 of toolCalls) {
|
|
1044
1035
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1045
1036
|
if (clientTool && clientTool.execute) {
|
|
1037
|
+
shouldExecuteClientTool = true;
|
|
1046
1038
|
const result = await clientTool.execute(
|
|
1047
1039
|
{
|
|
1048
1040
|
context: toolCall2?.args,
|
|
@@ -1091,6 +1083,11 @@ var Agent = class extends BaseResource {
|
|
|
1091
1083
|
});
|
|
1092
1084
|
}
|
|
1093
1085
|
}
|
|
1086
|
+
if (!shouldExecuteClientTool) {
|
|
1087
|
+
setTimeout(() => {
|
|
1088
|
+
writable.close();
|
|
1089
|
+
}, 0);
|
|
1090
|
+
}
|
|
1094
1091
|
} else {
|
|
1095
1092
|
setTimeout(() => {
|
|
1096
1093
|
writable.close();
|
|
@@ -1130,7 +1127,7 @@ var Agent = class extends BaseResource {
|
|
|
1130
1127
|
};
|
|
1131
1128
|
return streamResponse;
|
|
1132
1129
|
}
|
|
1133
|
-
async
|
|
1130
|
+
async stream(messagesOrParams, options) {
|
|
1134
1131
|
let params;
|
|
1135
1132
|
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1136
1133
|
params = messagesOrParams;
|
|
@@ -1355,6 +1352,12 @@ var Agent = class extends BaseResource {
|
|
|
1355
1352
|
body: params
|
|
1356
1353
|
});
|
|
1357
1354
|
}
|
|
1355
|
+
async generateVNext(_messagesOrParams, _options) {
|
|
1356
|
+
throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
|
|
1357
|
+
}
|
|
1358
|
+
async streamVNext(_messagesOrParams, _options) {
|
|
1359
|
+
throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
|
|
1360
|
+
}
|
|
1358
1361
|
};
|
|
1359
1362
|
|
|
1360
1363
|
// src/resources/memory-thread.ts
|
|
@@ -1703,10 +1706,20 @@ var Workflow = class extends BaseResource {
|
|
|
1703
1706
|
return {
|
|
1704
1707
|
runId,
|
|
1705
1708
|
start: async (p) => {
|
|
1706
|
-
return this.start({
|
|
1709
|
+
return this.start({
|
|
1710
|
+
runId,
|
|
1711
|
+
inputData: p.inputData,
|
|
1712
|
+
runtimeContext: p.runtimeContext,
|
|
1713
|
+
tracingOptions: p.tracingOptions
|
|
1714
|
+
});
|
|
1707
1715
|
},
|
|
1708
1716
|
startAsync: async (p) => {
|
|
1709
|
-
return this.startAsync({
|
|
1717
|
+
return this.startAsync({
|
|
1718
|
+
runId,
|
|
1719
|
+
inputData: p.inputData,
|
|
1720
|
+
runtimeContext: p.runtimeContext,
|
|
1721
|
+
tracingOptions: p.tracingOptions
|
|
1722
|
+
});
|
|
1710
1723
|
},
|
|
1711
1724
|
watch: async (onRecord) => {
|
|
1712
1725
|
return this.watch({ runId }, onRecord);
|
|
@@ -1715,10 +1728,22 @@ var Workflow = class extends BaseResource {
|
|
|
1715
1728
|
return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1716
1729
|
},
|
|
1717
1730
|
resume: async (p) => {
|
|
1718
|
-
return this.resume({
|
|
1731
|
+
return this.resume({
|
|
1732
|
+
runId,
|
|
1733
|
+
step: p.step,
|
|
1734
|
+
resumeData: p.resumeData,
|
|
1735
|
+
runtimeContext: p.runtimeContext,
|
|
1736
|
+
tracingOptions: p.tracingOptions
|
|
1737
|
+
});
|
|
1719
1738
|
},
|
|
1720
1739
|
resumeAsync: async (p) => {
|
|
1721
|
-
return this.resumeAsync({
|
|
1740
|
+
return this.resumeAsync({
|
|
1741
|
+
runId,
|
|
1742
|
+
step: p.step,
|
|
1743
|
+
resumeData: p.resumeData,
|
|
1744
|
+
runtimeContext: p.runtimeContext,
|
|
1745
|
+
tracingOptions: p.tracingOptions
|
|
1746
|
+
});
|
|
1722
1747
|
},
|
|
1723
1748
|
resumeStreamVNext: async (p) => {
|
|
1724
1749
|
return this.resumeStreamVNext({
|
|
@@ -1739,7 +1764,7 @@ var Workflow = class extends BaseResource {
|
|
|
1739
1764
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1740
1765
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1741
1766
|
method: "POST",
|
|
1742
|
-
body: { inputData: params?.inputData, runtimeContext }
|
|
1767
|
+
body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1743
1768
|
});
|
|
1744
1769
|
}
|
|
1745
1770
|
/**
|
|
@@ -1751,6 +1776,7 @@ var Workflow = class extends BaseResource {
|
|
|
1751
1776
|
step,
|
|
1752
1777
|
runId,
|
|
1753
1778
|
resumeData,
|
|
1779
|
+
tracingOptions,
|
|
1754
1780
|
...rest
|
|
1755
1781
|
}) {
|
|
1756
1782
|
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
@@ -1759,7 +1785,8 @@ var Workflow = class extends BaseResource {
|
|
|
1759
1785
|
body: {
|
|
1760
1786
|
step,
|
|
1761
1787
|
resumeData,
|
|
1762
|
-
runtimeContext
|
|
1788
|
+
runtimeContext,
|
|
1789
|
+
tracingOptions
|
|
1763
1790
|
}
|
|
1764
1791
|
});
|
|
1765
1792
|
}
|
|
@@ -1776,7 +1803,7 @@ var Workflow = class extends BaseResource {
|
|
|
1776
1803
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1777
1804
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1778
1805
|
method: "POST",
|
|
1779
|
-
body: { inputData: params.inputData, runtimeContext }
|
|
1806
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1780
1807
|
});
|
|
1781
1808
|
}
|
|
1782
1809
|
/**
|
|
@@ -1794,7 +1821,7 @@ var Workflow = class extends BaseResource {
|
|
|
1794
1821
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1795
1822
|
{
|
|
1796
1823
|
method: "POST",
|
|
1797
|
-
body: { inputData: params.inputData, runtimeContext },
|
|
1824
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
|
|
1798
1825
|
stream: true
|
|
1799
1826
|
}
|
|
1800
1827
|
);
|
|
@@ -1892,7 +1919,12 @@ var Workflow = class extends BaseResource {
|
|
|
1892
1919
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1893
1920
|
{
|
|
1894
1921
|
method: "POST",
|
|
1895
|
-
body: {
|
|
1922
|
+
body: {
|
|
1923
|
+
inputData: params.inputData,
|
|
1924
|
+
runtimeContext,
|
|
1925
|
+
closeOnSuspend: params.closeOnSuspend,
|
|
1926
|
+
tracingOptions: params.tracingOptions
|
|
1927
|
+
},
|
|
1896
1928
|
stream: true
|
|
1897
1929
|
}
|
|
1898
1930
|
);
|
|
@@ -1928,6 +1960,53 @@ var Workflow = class extends BaseResource {
|
|
|
1928
1960
|
});
|
|
1929
1961
|
return response.body.pipeThrough(transformStream);
|
|
1930
1962
|
}
|
|
1963
|
+
/**
|
|
1964
|
+
* Observes workflow vNext stream for a workflow run
|
|
1965
|
+
* @param params - Object containing the runId
|
|
1966
|
+
* @returns Promise containing the workflow execution results
|
|
1967
|
+
*/
|
|
1968
|
+
async observeStreamVNext(params) {
|
|
1969
|
+
const searchParams = new URLSearchParams();
|
|
1970
|
+
searchParams.set("runId", params.runId);
|
|
1971
|
+
const response = await this.request(
|
|
1972
|
+
`/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
|
|
1973
|
+
{
|
|
1974
|
+
method: "POST",
|
|
1975
|
+
stream: true
|
|
1976
|
+
}
|
|
1977
|
+
);
|
|
1978
|
+
if (!response.ok) {
|
|
1979
|
+
throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
|
|
1980
|
+
}
|
|
1981
|
+
if (!response.body) {
|
|
1982
|
+
throw new Error("Response body is null");
|
|
1983
|
+
}
|
|
1984
|
+
let failedChunk = void 0;
|
|
1985
|
+
const transformStream = new TransformStream({
|
|
1986
|
+
start() {
|
|
1987
|
+
},
|
|
1988
|
+
async transform(chunk, controller) {
|
|
1989
|
+
try {
|
|
1990
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1991
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1992
|
+
for (const chunk2 of chunks) {
|
|
1993
|
+
if (chunk2) {
|
|
1994
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1995
|
+
try {
|
|
1996
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1997
|
+
controller.enqueue(parsedChunk);
|
|
1998
|
+
failedChunk = void 0;
|
|
1999
|
+
} catch {
|
|
2000
|
+
failedChunk = newChunk;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
} catch {
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
});
|
|
2008
|
+
return response.body.pipeThrough(transformStream);
|
|
2009
|
+
}
|
|
1931
2010
|
/**
|
|
1932
2011
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1933
2012
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
@@ -1940,7 +2019,8 @@ var Workflow = class extends BaseResource {
|
|
|
1940
2019
|
body: {
|
|
1941
2020
|
step: params.step,
|
|
1942
2021
|
resumeData: params.resumeData,
|
|
1943
|
-
runtimeContext
|
|
2022
|
+
runtimeContext,
|
|
2023
|
+
tracingOptions: params.tracingOptions
|
|
1944
2024
|
}
|
|
1945
2025
|
});
|
|
1946
2026
|
}
|
|
@@ -1949,16 +2029,54 @@ var Workflow = class extends BaseResource {
|
|
|
1949
2029
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1950
2030
|
* @returns Promise containing the workflow resume results
|
|
1951
2031
|
*/
|
|
1952
|
-
resumeStreamVNext(params) {
|
|
2032
|
+
async resumeStreamVNext(params) {
|
|
2033
|
+
const searchParams = new URLSearchParams();
|
|
2034
|
+
searchParams.set("runId", params.runId);
|
|
1953
2035
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
2036
|
+
const response = await this.request(
|
|
2037
|
+
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2038
|
+
{
|
|
2039
|
+
method: "POST",
|
|
2040
|
+
body: {
|
|
2041
|
+
step: params.step,
|
|
2042
|
+
resumeData: params.resumeData,
|
|
2043
|
+
runtimeContext,
|
|
2044
|
+
tracingOptions: params.tracingOptions
|
|
2045
|
+
},
|
|
2046
|
+
stream: true
|
|
2047
|
+
}
|
|
2048
|
+
);
|
|
2049
|
+
if (!response.ok) {
|
|
2050
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2051
|
+
}
|
|
2052
|
+
if (!response.body) {
|
|
2053
|
+
throw new Error("Response body is null");
|
|
2054
|
+
}
|
|
2055
|
+
let failedChunk = void 0;
|
|
2056
|
+
const transformStream = new TransformStream({
|
|
2057
|
+
start() {
|
|
2058
|
+
},
|
|
2059
|
+
async transform(chunk, controller) {
|
|
2060
|
+
try {
|
|
2061
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2062
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2063
|
+
for (const chunk2 of chunks) {
|
|
2064
|
+
if (chunk2) {
|
|
2065
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2066
|
+
try {
|
|
2067
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2068
|
+
controller.enqueue(parsedChunk);
|
|
2069
|
+
failedChunk = void 0;
|
|
2070
|
+
} catch {
|
|
2071
|
+
failedChunk = newChunk;
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
} catch {
|
|
2076
|
+
}
|
|
1960
2077
|
}
|
|
1961
2078
|
});
|
|
2079
|
+
return response.body.pipeThrough(transformStream);
|
|
1962
2080
|
}
|
|
1963
2081
|
/**
|
|
1964
2082
|
* Watches workflow transitions in real-time
|
|
@@ -2626,145 +2744,6 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2626
2744
|
}
|
|
2627
2745
|
};
|
|
2628
2746
|
|
|
2629
|
-
// src/resources/vNextNetwork.ts
|
|
2630
|
-
var RECORD_SEPARATOR3 = "";
|
|
2631
|
-
var VNextNetwork = class extends BaseResource {
|
|
2632
|
-
constructor(options, networkId) {
|
|
2633
|
-
super(options);
|
|
2634
|
-
this.networkId = networkId;
|
|
2635
|
-
}
|
|
2636
|
-
/**
|
|
2637
|
-
* Retrieves details about the network
|
|
2638
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2639
|
-
* @returns Promise containing vNext network details
|
|
2640
|
-
*/
|
|
2641
|
-
details(runtimeContext) {
|
|
2642
|
-
return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2643
|
-
}
|
|
2644
|
-
/**
|
|
2645
|
-
* Generates a response from the v-next network
|
|
2646
|
-
* @param params - Generation parameters including message
|
|
2647
|
-
* @returns Promise containing the generated response
|
|
2648
|
-
*/
|
|
2649
|
-
generate(params) {
|
|
2650
|
-
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
2651
|
-
method: "POST",
|
|
2652
|
-
body: {
|
|
2653
|
-
...params,
|
|
2654
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2655
|
-
}
|
|
2656
|
-
});
|
|
2657
|
-
}
|
|
2658
|
-
/**
|
|
2659
|
-
* Generates a response from the v-next network using multiple primitives
|
|
2660
|
-
* @param params - Generation parameters including message
|
|
2661
|
-
* @returns Promise containing the generated response
|
|
2662
|
-
*/
|
|
2663
|
-
loop(params) {
|
|
2664
|
-
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
2665
|
-
method: "POST",
|
|
2666
|
-
body: {
|
|
2667
|
-
...params,
|
|
2668
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2669
|
-
}
|
|
2670
|
-
});
|
|
2671
|
-
}
|
|
2672
|
-
async *streamProcessor(stream) {
|
|
2673
|
-
const reader = stream.getReader();
|
|
2674
|
-
let doneReading = false;
|
|
2675
|
-
let buffer = "";
|
|
2676
|
-
try {
|
|
2677
|
-
while (!doneReading) {
|
|
2678
|
-
const { done, value } = await reader.read();
|
|
2679
|
-
doneReading = done;
|
|
2680
|
-
if (done && !value) continue;
|
|
2681
|
-
try {
|
|
2682
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2683
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2684
|
-
buffer = chunks.pop() || "";
|
|
2685
|
-
for (const chunk of chunks) {
|
|
2686
|
-
if (chunk) {
|
|
2687
|
-
if (typeof chunk === "string") {
|
|
2688
|
-
try {
|
|
2689
|
-
const parsedChunk = JSON.parse(chunk);
|
|
2690
|
-
yield parsedChunk;
|
|
2691
|
-
} catch {
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
}
|
|
2695
|
-
}
|
|
2696
|
-
} catch {
|
|
2697
|
-
}
|
|
2698
|
-
}
|
|
2699
|
-
if (buffer) {
|
|
2700
|
-
try {
|
|
2701
|
-
yield JSON.parse(buffer);
|
|
2702
|
-
} catch {
|
|
2703
|
-
}
|
|
2704
|
-
}
|
|
2705
|
-
} finally {
|
|
2706
|
-
reader.cancel().catch(() => {
|
|
2707
|
-
});
|
|
2708
|
-
}
|
|
2709
|
-
}
|
|
2710
|
-
/**
|
|
2711
|
-
* Streams a response from the v-next network
|
|
2712
|
-
* @param params - Stream parameters including message
|
|
2713
|
-
* @returns Promise containing the results
|
|
2714
|
-
*/
|
|
2715
|
-
async stream(params, onRecord) {
|
|
2716
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
2717
|
-
method: "POST",
|
|
2718
|
-
body: {
|
|
2719
|
-
...params,
|
|
2720
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2721
|
-
},
|
|
2722
|
-
stream: true
|
|
2723
|
-
});
|
|
2724
|
-
if (!response.ok) {
|
|
2725
|
-
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
2726
|
-
}
|
|
2727
|
-
if (!response.body) {
|
|
2728
|
-
throw new Error("Response body is null");
|
|
2729
|
-
}
|
|
2730
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2731
|
-
if (typeof record === "string") {
|
|
2732
|
-
onRecord(JSON.parse(record));
|
|
2733
|
-
} else {
|
|
2734
|
-
onRecord(record);
|
|
2735
|
-
}
|
|
2736
|
-
}
|
|
2737
|
-
}
|
|
2738
|
-
/**
|
|
2739
|
-
* Streams a response from the v-next network loop
|
|
2740
|
-
* @param params - Stream parameters including message
|
|
2741
|
-
* @returns Promise containing the results
|
|
2742
|
-
*/
|
|
2743
|
-
async loopStream(params, onRecord) {
|
|
2744
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
2745
|
-
method: "POST",
|
|
2746
|
-
body: {
|
|
2747
|
-
...params,
|
|
2748
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2749
|
-
},
|
|
2750
|
-
stream: true
|
|
2751
|
-
});
|
|
2752
|
-
if (!response.ok) {
|
|
2753
|
-
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
2754
|
-
}
|
|
2755
|
-
if (!response.body) {
|
|
2756
|
-
throw new Error("Response body is null");
|
|
2757
|
-
}
|
|
2758
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2759
|
-
if (typeof record === "string") {
|
|
2760
|
-
onRecord(JSON.parse(record));
|
|
2761
|
-
} else {
|
|
2762
|
-
onRecord(record);
|
|
2763
|
-
}
|
|
2764
|
-
}
|
|
2765
|
-
}
|
|
2766
|
-
};
|
|
2767
|
-
|
|
2768
2747
|
// src/client.ts
|
|
2769
2748
|
var MastraClient = class extends BaseResource {
|
|
2770
2749
|
observability;
|
|
@@ -3106,21 +3085,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3106
3085
|
return this.request(`/api/telemetry`);
|
|
3107
3086
|
}
|
|
3108
3087
|
}
|
|
3109
|
-
/**
|
|
3110
|
-
* Retrieves all available vNext networks
|
|
3111
|
-
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
3112
|
-
*/
|
|
3113
|
-
getVNextNetworks() {
|
|
3114
|
-
return this.request("/api/networks/v-next");
|
|
3115
|
-
}
|
|
3116
|
-
/**
|
|
3117
|
-
* Gets a vNext network instance by ID
|
|
3118
|
-
* @param networkId - ID of the vNext network to retrieve
|
|
3119
|
-
* @returns vNext Network instance
|
|
3120
|
-
*/
|
|
3121
|
-
getVNextNetwork(networkId) {
|
|
3122
|
-
return new VNextNetwork(this.options, networkId);
|
|
3123
|
-
}
|
|
3124
3088
|
/**
|
|
3125
3089
|
* Retrieves a list of available MCP servers.
|
|
3126
3090
|
* @param params - Optional parameters for pagination (limit, offset).
|