@mastra/client-js 0.0.0-fix-network-silence-20250930164151 → 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 +139 -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 +125 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +125 -194
- 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 +12 -7
- 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.js
CHANGED
|
@@ -317,12 +317,6 @@ var Agent = class extends BaseResource {
|
|
|
317
317
|
details(runtimeContext) {
|
|
318
318
|
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
319
319
|
}
|
|
320
|
-
async generate(params) {
|
|
321
|
-
console.warn(
|
|
322
|
-
"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."
|
|
323
|
-
);
|
|
324
|
-
return this.generateLegacy(params);
|
|
325
|
-
}
|
|
326
320
|
async generateLegacy(params) {
|
|
327
321
|
const processedParams = {
|
|
328
322
|
...params,
|
|
@@ -386,7 +380,7 @@ var Agent = class extends BaseResource {
|
|
|
386
380
|
}
|
|
387
381
|
return response;
|
|
388
382
|
}
|
|
389
|
-
async
|
|
383
|
+
async generate(messagesOrParams, options) {
|
|
390
384
|
let params;
|
|
391
385
|
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
392
386
|
params = messagesOrParams;
|
|
@@ -408,7 +402,7 @@ var Agent = class extends BaseResource {
|
|
|
408
402
|
};
|
|
409
403
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
410
404
|
const response = await this.request(
|
|
411
|
-
`/api/agents/${this.agentId}/generate
|
|
405
|
+
`/api/agents/${this.agentId}/generate`,
|
|
412
406
|
{
|
|
413
407
|
method: "POST",
|
|
414
408
|
body: processedParams
|
|
@@ -422,7 +416,7 @@ var Agent = class extends BaseResource {
|
|
|
422
416
|
resourceId,
|
|
423
417
|
threadId,
|
|
424
418
|
runtimeContext,
|
|
425
|
-
respondFn: this.
|
|
419
|
+
respondFn: this.generate.bind(this)
|
|
426
420
|
});
|
|
427
421
|
}
|
|
428
422
|
return response;
|
|
@@ -689,17 +683,6 @@ var Agent = class extends BaseResource {
|
|
|
689
683
|
});
|
|
690
684
|
onFinish?.({ message, finishReason, usage });
|
|
691
685
|
}
|
|
692
|
-
/**
|
|
693
|
-
* Streams a response from the agent
|
|
694
|
-
* @param params - Stream parameters including prompt
|
|
695
|
-
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
696
|
-
*/
|
|
697
|
-
async stream(params) {
|
|
698
|
-
console.warn(
|
|
699
|
-
"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."
|
|
700
|
-
);
|
|
701
|
-
return this.streamLegacy(params);
|
|
702
|
-
}
|
|
703
686
|
/**
|
|
704
687
|
* Streams a response from the agent
|
|
705
688
|
* @param params - Stream parameters including prompt
|
|
@@ -801,6 +784,14 @@ var Agent = class extends BaseResource {
|
|
|
801
784
|
// but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
|
|
802
785
|
onChunk: async (chunk) => {
|
|
803
786
|
switch (chunk.type) {
|
|
787
|
+
case "tripwire": {
|
|
788
|
+
message.parts.push({
|
|
789
|
+
type: "text",
|
|
790
|
+
text: chunk.payload.tripwireReason
|
|
791
|
+
});
|
|
792
|
+
execUpdate();
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
804
795
|
case "step-start": {
|
|
805
796
|
if (!replaceLastMessage) {
|
|
806
797
|
message.id = chunk.payload.messageId;
|
|
@@ -982,7 +973,7 @@ var Agent = class extends BaseResource {
|
|
|
982
973
|
onFinish?.({ message, finishReason, usage });
|
|
983
974
|
}
|
|
984
975
|
async processStreamResponse_vNext(processedParams, writable) {
|
|
985
|
-
const response = await this.request(`/api/agents/${this.agentId}/stream
|
|
976
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
986
977
|
method: "POST",
|
|
987
978
|
body: processedParams,
|
|
988
979
|
stream: true
|
|
@@ -997,18 +988,17 @@ var Agent = class extends BaseResource {
|
|
|
997
988
|
streamForWritable.pipeTo(
|
|
998
989
|
new WritableStream({
|
|
999
990
|
async write(chunk) {
|
|
991
|
+
let writer;
|
|
1000
992
|
try {
|
|
993
|
+
writer = writable.getWriter();
|
|
1001
994
|
const text = new TextDecoder().decode(chunk);
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
995
|
+
const lines = text.split("\n\n");
|
|
996
|
+
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
997
|
+
await writer.write(new TextEncoder().encode(readableLines));
|
|
1005
998
|
} catch {
|
|
1006
|
-
|
|
1007
|
-
const writer = writable.getWriter();
|
|
1008
|
-
try {
|
|
1009
|
-
await writer.write(chunk);
|
|
999
|
+
await writer?.write(chunk);
|
|
1010
1000
|
} finally {
|
|
1011
|
-
writer
|
|
1001
|
+
writer?.releaseLock();
|
|
1012
1002
|
}
|
|
1013
1003
|
}
|
|
1014
1004
|
}),
|
|
@@ -1131,7 +1121,7 @@ var Agent = class extends BaseResource {
|
|
|
1131
1121
|
};
|
|
1132
1122
|
return streamResponse;
|
|
1133
1123
|
}
|
|
1134
|
-
async
|
|
1124
|
+
async stream(messagesOrParams, options) {
|
|
1135
1125
|
let params;
|
|
1136
1126
|
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1137
1127
|
params = messagesOrParams;
|
|
@@ -1356,6 +1346,12 @@ var Agent = class extends BaseResource {
|
|
|
1356
1346
|
body: params
|
|
1357
1347
|
});
|
|
1358
1348
|
}
|
|
1349
|
+
async generateVNext(_messagesOrParams, _options) {
|
|
1350
|
+
throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
|
|
1351
|
+
}
|
|
1352
|
+
async streamVNext(_messagesOrParams, _options) {
|
|
1353
|
+
throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
|
|
1354
|
+
}
|
|
1359
1355
|
};
|
|
1360
1356
|
|
|
1361
1357
|
// src/resources/memory-thread.ts
|
|
@@ -1819,7 +1815,7 @@ var Workflow = class extends BaseResource {
|
|
|
1819
1815
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1820
1816
|
{
|
|
1821
1817
|
method: "POST",
|
|
1822
|
-
body: { inputData: params.inputData, runtimeContext },
|
|
1818
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
|
|
1823
1819
|
stream: true
|
|
1824
1820
|
}
|
|
1825
1821
|
);
|
|
@@ -1917,7 +1913,12 @@ var Workflow = class extends BaseResource {
|
|
|
1917
1913
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1918
1914
|
{
|
|
1919
1915
|
method: "POST",
|
|
1920
|
-
body: {
|
|
1916
|
+
body: {
|
|
1917
|
+
inputData: params.inputData,
|
|
1918
|
+
runtimeContext,
|
|
1919
|
+
closeOnSuspend: params.closeOnSuspend,
|
|
1920
|
+
tracingOptions: params.tracingOptions
|
|
1921
|
+
},
|
|
1921
1922
|
stream: true
|
|
1922
1923
|
}
|
|
1923
1924
|
);
|
|
@@ -1953,6 +1954,53 @@ var Workflow = class extends BaseResource {
|
|
|
1953
1954
|
});
|
|
1954
1955
|
return response.body.pipeThrough(transformStream);
|
|
1955
1956
|
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Observes workflow vNext stream for a workflow run
|
|
1959
|
+
* @param params - Object containing the runId
|
|
1960
|
+
* @returns Promise containing the workflow execution results
|
|
1961
|
+
*/
|
|
1962
|
+
async observeStreamVNext(params) {
|
|
1963
|
+
const searchParams = new URLSearchParams();
|
|
1964
|
+
searchParams.set("runId", params.runId);
|
|
1965
|
+
const response = await this.request(
|
|
1966
|
+
`/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
|
|
1967
|
+
{
|
|
1968
|
+
method: "POST",
|
|
1969
|
+
stream: true
|
|
1970
|
+
}
|
|
1971
|
+
);
|
|
1972
|
+
if (!response.ok) {
|
|
1973
|
+
throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
|
|
1974
|
+
}
|
|
1975
|
+
if (!response.body) {
|
|
1976
|
+
throw new Error("Response body is null");
|
|
1977
|
+
}
|
|
1978
|
+
let failedChunk = void 0;
|
|
1979
|
+
const transformStream = new TransformStream({
|
|
1980
|
+
start() {
|
|
1981
|
+
},
|
|
1982
|
+
async transform(chunk, controller) {
|
|
1983
|
+
try {
|
|
1984
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1985
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1986
|
+
for (const chunk2 of chunks) {
|
|
1987
|
+
if (chunk2) {
|
|
1988
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1989
|
+
try {
|
|
1990
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1991
|
+
controller.enqueue(parsedChunk);
|
|
1992
|
+
failedChunk = void 0;
|
|
1993
|
+
} catch {
|
|
1994
|
+
failedChunk = newChunk;
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
} catch {
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
});
|
|
2002
|
+
return response.body.pipeThrough(transformStream);
|
|
2003
|
+
}
|
|
1956
2004
|
/**
|
|
1957
2005
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1958
2006
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
@@ -1975,17 +2023,54 @@ var Workflow = class extends BaseResource {
|
|
|
1975
2023
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1976
2024
|
* @returns Promise containing the workflow resume results
|
|
1977
2025
|
*/
|
|
1978
|
-
resumeStreamVNext(params) {
|
|
2026
|
+
async resumeStreamVNext(params) {
|
|
2027
|
+
const searchParams = new URLSearchParams();
|
|
2028
|
+
searchParams.set("runId", params.runId);
|
|
1979
2029
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
2030
|
+
const response = await this.request(
|
|
2031
|
+
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2032
|
+
{
|
|
2033
|
+
method: "POST",
|
|
2034
|
+
body: {
|
|
2035
|
+
step: params.step,
|
|
2036
|
+
resumeData: params.resumeData,
|
|
2037
|
+
runtimeContext,
|
|
2038
|
+
tracingOptions: params.tracingOptions
|
|
2039
|
+
},
|
|
2040
|
+
stream: true
|
|
2041
|
+
}
|
|
2042
|
+
);
|
|
2043
|
+
if (!response.ok) {
|
|
2044
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2045
|
+
}
|
|
2046
|
+
if (!response.body) {
|
|
2047
|
+
throw new Error("Response body is null");
|
|
2048
|
+
}
|
|
2049
|
+
let failedChunk = void 0;
|
|
2050
|
+
const transformStream = new TransformStream({
|
|
2051
|
+
start() {
|
|
2052
|
+
},
|
|
2053
|
+
async transform(chunk, controller) {
|
|
2054
|
+
try {
|
|
2055
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2056
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2057
|
+
for (const chunk2 of chunks) {
|
|
2058
|
+
if (chunk2) {
|
|
2059
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2060
|
+
try {
|
|
2061
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2062
|
+
controller.enqueue(parsedChunk);
|
|
2063
|
+
failedChunk = void 0;
|
|
2064
|
+
} catch {
|
|
2065
|
+
failedChunk = newChunk;
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
} catch {
|
|
2070
|
+
}
|
|
1987
2071
|
}
|
|
1988
2072
|
});
|
|
2073
|
+
return response.body.pipeThrough(transformStream);
|
|
1989
2074
|
}
|
|
1990
2075
|
/**
|
|
1991
2076
|
* Watches workflow transitions in real-time
|
|
@@ -2653,145 +2738,6 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2653
2738
|
}
|
|
2654
2739
|
};
|
|
2655
2740
|
|
|
2656
|
-
// src/resources/vNextNetwork.ts
|
|
2657
|
-
var RECORD_SEPARATOR3 = "";
|
|
2658
|
-
var VNextNetwork = class extends BaseResource {
|
|
2659
|
-
constructor(options, networkId) {
|
|
2660
|
-
super(options);
|
|
2661
|
-
this.networkId = networkId;
|
|
2662
|
-
}
|
|
2663
|
-
/**
|
|
2664
|
-
* Retrieves details about the network
|
|
2665
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2666
|
-
* @returns Promise containing vNext network details
|
|
2667
|
-
*/
|
|
2668
|
-
details(runtimeContext) {
|
|
2669
|
-
return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2670
|
-
}
|
|
2671
|
-
/**
|
|
2672
|
-
* Generates a response from the v-next network
|
|
2673
|
-
* @param params - Generation parameters including message
|
|
2674
|
-
* @returns Promise containing the generated response
|
|
2675
|
-
*/
|
|
2676
|
-
generate(params) {
|
|
2677
|
-
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
2678
|
-
method: "POST",
|
|
2679
|
-
body: {
|
|
2680
|
-
...params,
|
|
2681
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2682
|
-
}
|
|
2683
|
-
});
|
|
2684
|
-
}
|
|
2685
|
-
/**
|
|
2686
|
-
* Generates a response from the v-next network using multiple primitives
|
|
2687
|
-
* @param params - Generation parameters including message
|
|
2688
|
-
* @returns Promise containing the generated response
|
|
2689
|
-
*/
|
|
2690
|
-
loop(params) {
|
|
2691
|
-
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
2692
|
-
method: "POST",
|
|
2693
|
-
body: {
|
|
2694
|
-
...params,
|
|
2695
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2696
|
-
}
|
|
2697
|
-
});
|
|
2698
|
-
}
|
|
2699
|
-
async *streamProcessor(stream) {
|
|
2700
|
-
const reader = stream.getReader();
|
|
2701
|
-
let doneReading = false;
|
|
2702
|
-
let buffer = "";
|
|
2703
|
-
try {
|
|
2704
|
-
while (!doneReading) {
|
|
2705
|
-
const { done, value } = await reader.read();
|
|
2706
|
-
doneReading = done;
|
|
2707
|
-
if (done && !value) continue;
|
|
2708
|
-
try {
|
|
2709
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2710
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2711
|
-
buffer = chunks.pop() || "";
|
|
2712
|
-
for (const chunk of chunks) {
|
|
2713
|
-
if (chunk) {
|
|
2714
|
-
if (typeof chunk === "string") {
|
|
2715
|
-
try {
|
|
2716
|
-
const parsedChunk = JSON.parse(chunk);
|
|
2717
|
-
yield parsedChunk;
|
|
2718
|
-
} catch {
|
|
2719
|
-
}
|
|
2720
|
-
}
|
|
2721
|
-
}
|
|
2722
|
-
}
|
|
2723
|
-
} catch {
|
|
2724
|
-
}
|
|
2725
|
-
}
|
|
2726
|
-
if (buffer) {
|
|
2727
|
-
try {
|
|
2728
|
-
yield JSON.parse(buffer);
|
|
2729
|
-
} catch {
|
|
2730
|
-
}
|
|
2731
|
-
}
|
|
2732
|
-
} finally {
|
|
2733
|
-
reader.cancel().catch(() => {
|
|
2734
|
-
});
|
|
2735
|
-
}
|
|
2736
|
-
}
|
|
2737
|
-
/**
|
|
2738
|
-
* Streams a response from the v-next network
|
|
2739
|
-
* @param params - Stream parameters including message
|
|
2740
|
-
* @returns Promise containing the results
|
|
2741
|
-
*/
|
|
2742
|
-
async stream(params, onRecord) {
|
|
2743
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
2744
|
-
method: "POST",
|
|
2745
|
-
body: {
|
|
2746
|
-
...params,
|
|
2747
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2748
|
-
},
|
|
2749
|
-
stream: true
|
|
2750
|
-
});
|
|
2751
|
-
if (!response.ok) {
|
|
2752
|
-
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
2753
|
-
}
|
|
2754
|
-
if (!response.body) {
|
|
2755
|
-
throw new Error("Response body is null");
|
|
2756
|
-
}
|
|
2757
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2758
|
-
if (typeof record === "string") {
|
|
2759
|
-
onRecord(JSON.parse(record));
|
|
2760
|
-
} else {
|
|
2761
|
-
onRecord(record);
|
|
2762
|
-
}
|
|
2763
|
-
}
|
|
2764
|
-
}
|
|
2765
|
-
/**
|
|
2766
|
-
* Streams a response from the v-next network loop
|
|
2767
|
-
* @param params - Stream parameters including message
|
|
2768
|
-
* @returns Promise containing the results
|
|
2769
|
-
*/
|
|
2770
|
-
async loopStream(params, onRecord) {
|
|
2771
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
2772
|
-
method: "POST",
|
|
2773
|
-
body: {
|
|
2774
|
-
...params,
|
|
2775
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2776
|
-
},
|
|
2777
|
-
stream: true
|
|
2778
|
-
});
|
|
2779
|
-
if (!response.ok) {
|
|
2780
|
-
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
2781
|
-
}
|
|
2782
|
-
if (!response.body) {
|
|
2783
|
-
throw new Error("Response body is null");
|
|
2784
|
-
}
|
|
2785
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2786
|
-
if (typeof record === "string") {
|
|
2787
|
-
onRecord(JSON.parse(record));
|
|
2788
|
-
} else {
|
|
2789
|
-
onRecord(record);
|
|
2790
|
-
}
|
|
2791
|
-
}
|
|
2792
|
-
}
|
|
2793
|
-
};
|
|
2794
|
-
|
|
2795
2741
|
// src/client.ts
|
|
2796
2742
|
var MastraClient = class extends BaseResource {
|
|
2797
2743
|
observability;
|
|
@@ -3133,21 +3079,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3133
3079
|
return this.request(`/api/telemetry`);
|
|
3134
3080
|
}
|
|
3135
3081
|
}
|
|
3136
|
-
/**
|
|
3137
|
-
* Retrieves all available vNext networks
|
|
3138
|
-
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
3139
|
-
*/
|
|
3140
|
-
getVNextNetworks() {
|
|
3141
|
-
return this.request("/api/networks/v-next");
|
|
3142
|
-
}
|
|
3143
|
-
/**
|
|
3144
|
-
* Gets a vNext network instance by ID
|
|
3145
|
-
* @param networkId - ID of the vNext network to retrieve
|
|
3146
|
-
* @returns vNext Network instance
|
|
3147
|
-
*/
|
|
3148
|
-
getVNextNetwork(networkId) {
|
|
3149
|
-
return new VNextNetwork(this.options, networkId);
|
|
3150
|
-
}
|
|
3151
3082
|
/**
|
|
3152
3083
|
* Retrieves a list of available MCP servers.
|
|
3153
3084
|
* @param params - Optional parameters for pagination (limit, offset).
|