@mastra/client-js 0.14.1 → 0.15.0
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 +30 -0
- package/README.md +4 -4
- package/dist/client.d.ts +1 -13
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +103 -184
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +103 -184
- 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 +10 -7
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/types.d.ts +11 -3
- package/dist/types.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 the week of 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 the week of 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
|
|
@@ -982,7 +965,7 @@ var Agent = class extends BaseResource {
|
|
|
982
965
|
onFinish?.({ message, finishReason, usage });
|
|
983
966
|
}
|
|
984
967
|
async processStreamResponse_vNext(processedParams, writable) {
|
|
985
|
-
const response = await this.request(`/api/agents/${this.agentId}/stream
|
|
968
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
986
969
|
method: "POST",
|
|
987
970
|
body: processedParams,
|
|
988
971
|
stream: true
|
|
@@ -1131,7 +1114,7 @@ var Agent = class extends BaseResource {
|
|
|
1131
1114
|
};
|
|
1132
1115
|
return streamResponse;
|
|
1133
1116
|
}
|
|
1134
|
-
async
|
|
1117
|
+
async stream(messagesOrParams, options) {
|
|
1135
1118
|
let params;
|
|
1136
1119
|
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1137
1120
|
params = messagesOrParams;
|
|
@@ -1356,6 +1339,12 @@ var Agent = class extends BaseResource {
|
|
|
1356
1339
|
body: params
|
|
1357
1340
|
});
|
|
1358
1341
|
}
|
|
1342
|
+
async generateVNext(_messagesOrParams, _options) {
|
|
1343
|
+
throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
|
|
1344
|
+
}
|
|
1345
|
+
async streamVNext(_messagesOrParams, _options) {
|
|
1346
|
+
throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
|
|
1347
|
+
}
|
|
1359
1348
|
};
|
|
1360
1349
|
|
|
1361
1350
|
// src/resources/memory-thread.ts
|
|
@@ -1958,6 +1947,53 @@ var Workflow = class extends BaseResource {
|
|
|
1958
1947
|
});
|
|
1959
1948
|
return response.body.pipeThrough(transformStream);
|
|
1960
1949
|
}
|
|
1950
|
+
/**
|
|
1951
|
+
* Observes workflow vNext stream for a workflow run
|
|
1952
|
+
* @param params - Object containing the runId
|
|
1953
|
+
* @returns Promise containing the workflow execution results
|
|
1954
|
+
*/
|
|
1955
|
+
async observeStreamVNext(params) {
|
|
1956
|
+
const searchParams = new URLSearchParams();
|
|
1957
|
+
searchParams.set("runId", params.runId);
|
|
1958
|
+
const response = await this.request(
|
|
1959
|
+
`/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
|
|
1960
|
+
{
|
|
1961
|
+
method: "POST",
|
|
1962
|
+
stream: true
|
|
1963
|
+
}
|
|
1964
|
+
);
|
|
1965
|
+
if (!response.ok) {
|
|
1966
|
+
throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
|
|
1967
|
+
}
|
|
1968
|
+
if (!response.body) {
|
|
1969
|
+
throw new Error("Response body is null");
|
|
1970
|
+
}
|
|
1971
|
+
let failedChunk = void 0;
|
|
1972
|
+
const transformStream = new TransformStream({
|
|
1973
|
+
start() {
|
|
1974
|
+
},
|
|
1975
|
+
async transform(chunk, controller) {
|
|
1976
|
+
try {
|
|
1977
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1978
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1979
|
+
for (const chunk2 of chunks) {
|
|
1980
|
+
if (chunk2) {
|
|
1981
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1982
|
+
try {
|
|
1983
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1984
|
+
controller.enqueue(parsedChunk);
|
|
1985
|
+
failedChunk = void 0;
|
|
1986
|
+
} catch {
|
|
1987
|
+
failedChunk = newChunk;
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
} catch {
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
});
|
|
1995
|
+
return response.body.pipeThrough(transformStream);
|
|
1996
|
+
}
|
|
1961
1997
|
/**
|
|
1962
1998
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1963
1999
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
@@ -1980,17 +2016,54 @@ var Workflow = class extends BaseResource {
|
|
|
1980
2016
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1981
2017
|
* @returns Promise containing the workflow resume results
|
|
1982
2018
|
*/
|
|
1983
|
-
resumeStreamVNext(params) {
|
|
2019
|
+
async resumeStreamVNext(params) {
|
|
2020
|
+
const searchParams = new URLSearchParams();
|
|
2021
|
+
searchParams.set("runId", params.runId);
|
|
1984
2022
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
2023
|
+
const response = await this.request(
|
|
2024
|
+
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2025
|
+
{
|
|
2026
|
+
method: "POST",
|
|
2027
|
+
body: {
|
|
2028
|
+
step: params.step,
|
|
2029
|
+
resumeData: params.resumeData,
|
|
2030
|
+
runtimeContext,
|
|
2031
|
+
tracingOptions: params.tracingOptions
|
|
2032
|
+
},
|
|
2033
|
+
stream: true
|
|
2034
|
+
}
|
|
2035
|
+
);
|
|
2036
|
+
if (!response.ok) {
|
|
2037
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2038
|
+
}
|
|
2039
|
+
if (!response.body) {
|
|
2040
|
+
throw new Error("Response body is null");
|
|
2041
|
+
}
|
|
2042
|
+
let failedChunk = void 0;
|
|
2043
|
+
const transformStream = new TransformStream({
|
|
2044
|
+
start() {
|
|
2045
|
+
},
|
|
2046
|
+
async transform(chunk, controller) {
|
|
2047
|
+
try {
|
|
2048
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2049
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2050
|
+
for (const chunk2 of chunks) {
|
|
2051
|
+
if (chunk2) {
|
|
2052
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2053
|
+
try {
|
|
2054
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2055
|
+
controller.enqueue(parsedChunk);
|
|
2056
|
+
failedChunk = void 0;
|
|
2057
|
+
} catch {
|
|
2058
|
+
failedChunk = newChunk;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
} catch {
|
|
2063
|
+
}
|
|
1992
2064
|
}
|
|
1993
2065
|
});
|
|
2066
|
+
return response.body.pipeThrough(transformStream);
|
|
1994
2067
|
}
|
|
1995
2068
|
/**
|
|
1996
2069
|
* Watches workflow transitions in real-time
|
|
@@ -2658,145 +2731,6 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2658
2731
|
}
|
|
2659
2732
|
};
|
|
2660
2733
|
|
|
2661
|
-
// src/resources/vNextNetwork.ts
|
|
2662
|
-
var RECORD_SEPARATOR3 = "";
|
|
2663
|
-
var VNextNetwork = class extends BaseResource {
|
|
2664
|
-
constructor(options, networkId) {
|
|
2665
|
-
super(options);
|
|
2666
|
-
this.networkId = networkId;
|
|
2667
|
-
}
|
|
2668
|
-
/**
|
|
2669
|
-
* Retrieves details about the network
|
|
2670
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2671
|
-
* @returns Promise containing vNext network details
|
|
2672
|
-
*/
|
|
2673
|
-
details(runtimeContext) {
|
|
2674
|
-
return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2675
|
-
}
|
|
2676
|
-
/**
|
|
2677
|
-
* Generates a response from the v-next network
|
|
2678
|
-
* @param params - Generation parameters including message
|
|
2679
|
-
* @returns Promise containing the generated response
|
|
2680
|
-
*/
|
|
2681
|
-
generate(params) {
|
|
2682
|
-
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
2683
|
-
method: "POST",
|
|
2684
|
-
body: {
|
|
2685
|
-
...params,
|
|
2686
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2687
|
-
}
|
|
2688
|
-
});
|
|
2689
|
-
}
|
|
2690
|
-
/**
|
|
2691
|
-
* Generates a response from the v-next network using multiple primitives
|
|
2692
|
-
* @param params - Generation parameters including message
|
|
2693
|
-
* @returns Promise containing the generated response
|
|
2694
|
-
*/
|
|
2695
|
-
loop(params) {
|
|
2696
|
-
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
2697
|
-
method: "POST",
|
|
2698
|
-
body: {
|
|
2699
|
-
...params,
|
|
2700
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2701
|
-
}
|
|
2702
|
-
});
|
|
2703
|
-
}
|
|
2704
|
-
async *streamProcessor(stream) {
|
|
2705
|
-
const reader = stream.getReader();
|
|
2706
|
-
let doneReading = false;
|
|
2707
|
-
let buffer = "";
|
|
2708
|
-
try {
|
|
2709
|
-
while (!doneReading) {
|
|
2710
|
-
const { done, value } = await reader.read();
|
|
2711
|
-
doneReading = done;
|
|
2712
|
-
if (done && !value) continue;
|
|
2713
|
-
try {
|
|
2714
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2715
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2716
|
-
buffer = chunks.pop() || "";
|
|
2717
|
-
for (const chunk of chunks) {
|
|
2718
|
-
if (chunk) {
|
|
2719
|
-
if (typeof chunk === "string") {
|
|
2720
|
-
try {
|
|
2721
|
-
const parsedChunk = JSON.parse(chunk);
|
|
2722
|
-
yield parsedChunk;
|
|
2723
|
-
} catch {
|
|
2724
|
-
}
|
|
2725
|
-
}
|
|
2726
|
-
}
|
|
2727
|
-
}
|
|
2728
|
-
} catch {
|
|
2729
|
-
}
|
|
2730
|
-
}
|
|
2731
|
-
if (buffer) {
|
|
2732
|
-
try {
|
|
2733
|
-
yield JSON.parse(buffer);
|
|
2734
|
-
} catch {
|
|
2735
|
-
}
|
|
2736
|
-
}
|
|
2737
|
-
} finally {
|
|
2738
|
-
reader.cancel().catch(() => {
|
|
2739
|
-
});
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
/**
|
|
2743
|
-
* Streams a response from the v-next network
|
|
2744
|
-
* @param params - Stream parameters including message
|
|
2745
|
-
* @returns Promise containing the results
|
|
2746
|
-
*/
|
|
2747
|
-
async stream(params, onRecord) {
|
|
2748
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
2749
|
-
method: "POST",
|
|
2750
|
-
body: {
|
|
2751
|
-
...params,
|
|
2752
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2753
|
-
},
|
|
2754
|
-
stream: true
|
|
2755
|
-
});
|
|
2756
|
-
if (!response.ok) {
|
|
2757
|
-
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
2758
|
-
}
|
|
2759
|
-
if (!response.body) {
|
|
2760
|
-
throw new Error("Response body is null");
|
|
2761
|
-
}
|
|
2762
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2763
|
-
if (typeof record === "string") {
|
|
2764
|
-
onRecord(JSON.parse(record));
|
|
2765
|
-
} else {
|
|
2766
|
-
onRecord(record);
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
}
|
|
2770
|
-
/**
|
|
2771
|
-
* Streams a response from the v-next network loop
|
|
2772
|
-
* @param params - Stream parameters including message
|
|
2773
|
-
* @returns Promise containing the results
|
|
2774
|
-
*/
|
|
2775
|
-
async loopStream(params, onRecord) {
|
|
2776
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
2777
|
-
method: "POST",
|
|
2778
|
-
body: {
|
|
2779
|
-
...params,
|
|
2780
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2781
|
-
},
|
|
2782
|
-
stream: true
|
|
2783
|
-
});
|
|
2784
|
-
if (!response.ok) {
|
|
2785
|
-
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
2786
|
-
}
|
|
2787
|
-
if (!response.body) {
|
|
2788
|
-
throw new Error("Response body is null");
|
|
2789
|
-
}
|
|
2790
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2791
|
-
if (typeof record === "string") {
|
|
2792
|
-
onRecord(JSON.parse(record));
|
|
2793
|
-
} else {
|
|
2794
|
-
onRecord(record);
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
}
|
|
2798
|
-
};
|
|
2799
|
-
|
|
2800
2734
|
// src/client.ts
|
|
2801
2735
|
var MastraClient = class extends BaseResource {
|
|
2802
2736
|
observability;
|
|
@@ -3138,21 +3072,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3138
3072
|
return this.request(`/api/telemetry`);
|
|
3139
3073
|
}
|
|
3140
3074
|
}
|
|
3141
|
-
/**
|
|
3142
|
-
* Retrieves all available vNext networks
|
|
3143
|
-
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
3144
|
-
*/
|
|
3145
|
-
getVNextNetworks() {
|
|
3146
|
-
return this.request("/api/networks/v-next");
|
|
3147
|
-
}
|
|
3148
|
-
/**
|
|
3149
|
-
* Gets a vNext network instance by ID
|
|
3150
|
-
* @param networkId - ID of the vNext network to retrieve
|
|
3151
|
-
* @returns vNext Network instance
|
|
3152
|
-
*/
|
|
3153
|
-
getVNextNetwork(networkId) {
|
|
3154
|
-
return new VNextNetwork(this.options, networkId);
|
|
3155
|
-
}
|
|
3156
3075
|
/**
|
|
3157
3076
|
* Retrieves a list of available MCP servers.
|
|
3158
3077
|
* @param params - Optional parameters for pagination (limit, offset).
|