@mastra/client-js 0.10.1-alpha.0 → 0.10.1-alpha.2
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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +21 -0
- package/dist/index.cjs +70 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +70 -0
- package/package.json +2 -2
- package/src/resources/workflow.ts +86 -0
- package/src/types.ts +2 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/client-js@0.10.1-alpha.
|
|
2
|
+
> @mastra/client-js@0.10.1-alpha.2 build /home/runner/work/mastra/mastra/client-sdks/client-js
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
[34mCLI[39m Cleaning output folder
|
|
10
10
|
[34mESM[39m Build start
|
|
11
11
|
[34mCJS[39m Build start
|
|
12
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
13
|
-
[32mESM[39m ⚡️ Build success in
|
|
14
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
15
|
-
[32mCJS[39m ⚡️ Build success in
|
|
12
|
+
[32mESM[39m [1mdist/index.js [22m[32m43.30 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 1577ms
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m43.59 KB[39m
|
|
15
|
+
[32mCJS[39m ⚡️ Build success in 1577ms
|
|
16
16
|
[34mDTS[39m Build start
|
|
17
|
-
[32mDTS[39m ⚡️ Build success in
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
19
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[
|
|
17
|
+
[32mDTS[39m ⚡️ Build success in 14357ms
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m31.64 KB[39m
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m31.64 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
+
## 0.10.1-alpha.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6015bdf: Leverage defaultAgentStreamOption, defaultAgentGenerateOption in playground
|
|
8
|
+
- Updated dependencies [6015bdf]
|
|
9
|
+
- @mastra/core@0.10.1-alpha.2
|
|
10
|
+
|
|
11
|
+
## 0.10.1-alpha.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 5343f93: Move emitter to symbol to make private
|
|
16
|
+
- Updated dependencies [200d0da]
|
|
17
|
+
- Updated dependencies [bf5f17b]
|
|
18
|
+
- Updated dependencies [5343f93]
|
|
19
|
+
- Updated dependencies [38aee50]
|
|
20
|
+
- Updated dependencies [5c41100]
|
|
21
|
+
- Updated dependencies [d6a759b]
|
|
22
|
+
- @mastra/core@0.10.1-alpha.1
|
|
23
|
+
|
|
3
24
|
## 0.10.1-alpha.0
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -954,6 +954,53 @@ var Workflow = class extends BaseResource {
|
|
|
954
954
|
body: { inputData: params.inputData, runtimeContext }
|
|
955
955
|
});
|
|
956
956
|
}
|
|
957
|
+
/**
|
|
958
|
+
* Starts a vNext workflow run and returns a stream
|
|
959
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
960
|
+
* @returns Promise containing the vNext workflow execution results
|
|
961
|
+
*/
|
|
962
|
+
async stream(params) {
|
|
963
|
+
const searchParams = new URLSearchParams();
|
|
964
|
+
if (!!params?.runId) {
|
|
965
|
+
searchParams.set("runId", params.runId);
|
|
966
|
+
}
|
|
967
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
968
|
+
const response = await this.request(
|
|
969
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
970
|
+
{
|
|
971
|
+
method: "POST",
|
|
972
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
973
|
+
stream: true
|
|
974
|
+
}
|
|
975
|
+
);
|
|
976
|
+
if (!response.ok) {
|
|
977
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
978
|
+
}
|
|
979
|
+
if (!response.body) {
|
|
980
|
+
throw new Error("Response body is null");
|
|
981
|
+
}
|
|
982
|
+
const transformStream = new TransformStream({
|
|
983
|
+
start() {
|
|
984
|
+
},
|
|
985
|
+
async transform(chunk, controller) {
|
|
986
|
+
try {
|
|
987
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
988
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
989
|
+
for (const chunk2 of chunks) {
|
|
990
|
+
if (chunk2) {
|
|
991
|
+
try {
|
|
992
|
+
const parsedChunk = JSON.parse(chunk2);
|
|
993
|
+
controller.enqueue(parsedChunk);
|
|
994
|
+
} catch {
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
} catch {
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
return response.body.pipeThrough(transformStream);
|
|
1003
|
+
}
|
|
957
1004
|
/**
|
|
958
1005
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
959
1006
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
@@ -989,6 +1036,29 @@ var Workflow = class extends BaseResource {
|
|
|
989
1036
|
onRecord(record);
|
|
990
1037
|
}
|
|
991
1038
|
}
|
|
1039
|
+
/**
|
|
1040
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
1041
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
1042
|
+
*
|
|
1043
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
1044
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
1045
|
+
*/
|
|
1046
|
+
static createRecordStream(records) {
|
|
1047
|
+
const encoder = new TextEncoder();
|
|
1048
|
+
return new ReadableStream({
|
|
1049
|
+
async start(controller) {
|
|
1050
|
+
try {
|
|
1051
|
+
for await (const record of records) {
|
|
1052
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
1053
|
+
controller.enqueue(encoder.encode(json));
|
|
1054
|
+
}
|
|
1055
|
+
controller.close();
|
|
1056
|
+
} catch (err) {
|
|
1057
|
+
controller.error(err);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
992
1062
|
};
|
|
993
1063
|
|
|
994
1064
|
// src/resources/a2a.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -9,6 +9,7 @@ import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
|
|
|
9
9
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
10
10
|
import { Workflow as Workflow$1, WorkflowResult, WatchEvent } from '@mastra/core/workflows';
|
|
11
11
|
import { StepAction, StepGraph, LegacyWorkflowRunResult as LegacyWorkflowRunResult$1 } from '@mastra/core/workflows/legacy';
|
|
12
|
+
import * as stream_web from 'stream/web';
|
|
12
13
|
import { AgentCard, TaskSendParams, Task, TaskQueryParams, TaskIdParams } from '@mastra/core/a2a';
|
|
13
14
|
|
|
14
15
|
interface ClientOptions {
|
|
@@ -42,6 +43,8 @@ interface GetAgentResponse {
|
|
|
42
43
|
workflows: Record<string, GetWorkflowResponse>;
|
|
43
44
|
provider: string;
|
|
44
45
|
modelId: string;
|
|
46
|
+
defaultGenerateOptions: WithoutMethods<AgentGenerateOptions>;
|
|
47
|
+
defaultStreamOptions: WithoutMethods<AgentStreamOptions>;
|
|
45
48
|
}
|
|
46
49
|
type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
47
50
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
@@ -627,6 +630,16 @@ declare class Workflow extends BaseResource {
|
|
|
627
630
|
inputData: Record<string, any>;
|
|
628
631
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
629
632
|
}): Promise<WorkflowRunResult>;
|
|
633
|
+
/**
|
|
634
|
+
* Starts a vNext workflow run and returns a stream
|
|
635
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
636
|
+
* @returns Promise containing the vNext workflow execution results
|
|
637
|
+
*/
|
|
638
|
+
stream(params: {
|
|
639
|
+
runId?: string;
|
|
640
|
+
inputData: Record<string, any>;
|
|
641
|
+
runtimeContext?: RuntimeContext;
|
|
642
|
+
}): Promise<stream_web.ReadableStream<WorkflowWatchResult>>;
|
|
630
643
|
/**
|
|
631
644
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
632
645
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
@@ -646,6 +659,14 @@ declare class Workflow extends BaseResource {
|
|
|
646
659
|
watch({ runId }: {
|
|
647
660
|
runId?: string;
|
|
648
661
|
}, onRecord: (record: WorkflowWatchResult) => void): Promise<void>;
|
|
662
|
+
/**
|
|
663
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
664
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
665
|
+
*
|
|
666
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
667
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
668
|
+
*/
|
|
669
|
+
static createRecordStream(records: Iterable<any> | AsyncIterable<any>): ReadableStream;
|
|
649
670
|
}
|
|
650
671
|
|
|
651
672
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
|
|
|
9
9
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
10
10
|
import { Workflow as Workflow$1, WorkflowResult, WatchEvent } from '@mastra/core/workflows';
|
|
11
11
|
import { StepAction, StepGraph, LegacyWorkflowRunResult as LegacyWorkflowRunResult$1 } from '@mastra/core/workflows/legacy';
|
|
12
|
+
import * as stream_web from 'stream/web';
|
|
12
13
|
import { AgentCard, TaskSendParams, Task, TaskQueryParams, TaskIdParams } from '@mastra/core/a2a';
|
|
13
14
|
|
|
14
15
|
interface ClientOptions {
|
|
@@ -42,6 +43,8 @@ interface GetAgentResponse {
|
|
|
42
43
|
workflows: Record<string, GetWorkflowResponse>;
|
|
43
44
|
provider: string;
|
|
44
45
|
modelId: string;
|
|
46
|
+
defaultGenerateOptions: WithoutMethods<AgentGenerateOptions>;
|
|
47
|
+
defaultStreamOptions: WithoutMethods<AgentStreamOptions>;
|
|
45
48
|
}
|
|
46
49
|
type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
47
50
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
@@ -627,6 +630,16 @@ declare class Workflow extends BaseResource {
|
|
|
627
630
|
inputData: Record<string, any>;
|
|
628
631
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
629
632
|
}): Promise<WorkflowRunResult>;
|
|
633
|
+
/**
|
|
634
|
+
* Starts a vNext workflow run and returns a stream
|
|
635
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
636
|
+
* @returns Promise containing the vNext workflow execution results
|
|
637
|
+
*/
|
|
638
|
+
stream(params: {
|
|
639
|
+
runId?: string;
|
|
640
|
+
inputData: Record<string, any>;
|
|
641
|
+
runtimeContext?: RuntimeContext;
|
|
642
|
+
}): Promise<stream_web.ReadableStream<WorkflowWatchResult>>;
|
|
630
643
|
/**
|
|
631
644
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
632
645
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
@@ -646,6 +659,14 @@ declare class Workflow extends BaseResource {
|
|
|
646
659
|
watch({ runId }: {
|
|
647
660
|
runId?: string;
|
|
648
661
|
}, onRecord: (record: WorkflowWatchResult) => void): Promise<void>;
|
|
662
|
+
/**
|
|
663
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
664
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
665
|
+
*
|
|
666
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
667
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
668
|
+
*/
|
|
669
|
+
static createRecordStream(records: Iterable<any> | AsyncIterable<any>): ReadableStream;
|
|
649
670
|
}
|
|
650
671
|
|
|
651
672
|
/**
|
package/dist/index.js
CHANGED
|
@@ -948,6 +948,53 @@ var Workflow = class extends BaseResource {
|
|
|
948
948
|
body: { inputData: params.inputData, runtimeContext }
|
|
949
949
|
});
|
|
950
950
|
}
|
|
951
|
+
/**
|
|
952
|
+
* Starts a vNext workflow run and returns a stream
|
|
953
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
954
|
+
* @returns Promise containing the vNext workflow execution results
|
|
955
|
+
*/
|
|
956
|
+
async stream(params) {
|
|
957
|
+
const searchParams = new URLSearchParams();
|
|
958
|
+
if (!!params?.runId) {
|
|
959
|
+
searchParams.set("runId", params.runId);
|
|
960
|
+
}
|
|
961
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
962
|
+
const response = await this.request(
|
|
963
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
964
|
+
{
|
|
965
|
+
method: "POST",
|
|
966
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
967
|
+
stream: true
|
|
968
|
+
}
|
|
969
|
+
);
|
|
970
|
+
if (!response.ok) {
|
|
971
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
972
|
+
}
|
|
973
|
+
if (!response.body) {
|
|
974
|
+
throw new Error("Response body is null");
|
|
975
|
+
}
|
|
976
|
+
const transformStream = new TransformStream({
|
|
977
|
+
start() {
|
|
978
|
+
},
|
|
979
|
+
async transform(chunk, controller) {
|
|
980
|
+
try {
|
|
981
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
982
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
983
|
+
for (const chunk2 of chunks) {
|
|
984
|
+
if (chunk2) {
|
|
985
|
+
try {
|
|
986
|
+
const parsedChunk = JSON.parse(chunk2);
|
|
987
|
+
controller.enqueue(parsedChunk);
|
|
988
|
+
} catch {
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
} catch {
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
return response.body.pipeThrough(transformStream);
|
|
997
|
+
}
|
|
951
998
|
/**
|
|
952
999
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
953
1000
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
@@ -983,6 +1030,29 @@ var Workflow = class extends BaseResource {
|
|
|
983
1030
|
onRecord(record);
|
|
984
1031
|
}
|
|
985
1032
|
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
1035
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
1036
|
+
*
|
|
1037
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
1038
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
1039
|
+
*/
|
|
1040
|
+
static createRecordStream(records) {
|
|
1041
|
+
const encoder = new TextEncoder();
|
|
1042
|
+
return new ReadableStream({
|
|
1043
|
+
async start(controller) {
|
|
1044
|
+
try {
|
|
1045
|
+
for await (const record of records) {
|
|
1046
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
1047
|
+
controller.enqueue(encoder.encode(json));
|
|
1048
|
+
}
|
|
1049
|
+
controller.close();
|
|
1050
|
+
} catch (err) {
|
|
1051
|
+
controller.error(err);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
986
1056
|
};
|
|
987
1057
|
|
|
988
1058
|
// src/resources/a2a.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.10.1-alpha.
|
|
3
|
+
"version": "0.10.1-alpha.2",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"type": "module",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"typescript": "^5.8.2",
|
|
44
44
|
"vitest": "^3.1.2",
|
|
45
45
|
"@internal/lint": "0.0.6",
|
|
46
|
-
"@mastra/core": "0.10.1-alpha.
|
|
46
|
+
"@mastra/core": "0.10.1-alpha.3"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
|
|
@@ -216,6 +216,68 @@ export class Workflow extends BaseResource {
|
|
|
216
216
|
});
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Starts a vNext workflow run and returns a stream
|
|
221
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
222
|
+
* @returns Promise containing the vNext workflow execution results
|
|
223
|
+
*/
|
|
224
|
+
async stream(params: { runId?: string; inputData: Record<string, any>; runtimeContext?: RuntimeContext }) {
|
|
225
|
+
const searchParams = new URLSearchParams();
|
|
226
|
+
|
|
227
|
+
if (!!params?.runId) {
|
|
228
|
+
searchParams.set('runId', params.runId);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined;
|
|
232
|
+
const response: Response = await this.request(
|
|
233
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
234
|
+
{
|
|
235
|
+
method: 'POST',
|
|
236
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
237
|
+
stream: true,
|
|
238
|
+
},
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
if (!response.ok) {
|
|
242
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (!response.body) {
|
|
246
|
+
throw new Error('Response body is null');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Create a transform stream that processes the response body
|
|
250
|
+
const transformStream = new TransformStream<ArrayBuffer, WorkflowWatchResult>({
|
|
251
|
+
start() {},
|
|
252
|
+
async transform(chunk, controller) {
|
|
253
|
+
try {
|
|
254
|
+
// Decode binary data to text
|
|
255
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
256
|
+
|
|
257
|
+
// Split by record separator
|
|
258
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
259
|
+
|
|
260
|
+
// Process each chunk
|
|
261
|
+
for (const chunk of chunks) {
|
|
262
|
+
if (chunk) {
|
|
263
|
+
try {
|
|
264
|
+
const parsedChunk = JSON.parse(chunk);
|
|
265
|
+
controller.enqueue(parsedChunk);
|
|
266
|
+
} catch {
|
|
267
|
+
// Silently ignore parsing errors
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
} catch {
|
|
272
|
+
// Silently ignore processing errors
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// Pipe the response body through the transform stream
|
|
278
|
+
return response.body.pipeThrough(transformStream);
|
|
279
|
+
}
|
|
280
|
+
|
|
219
281
|
/**
|
|
220
282
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
221
283
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
@@ -260,4 +322,28 @@ export class Workflow extends BaseResource {
|
|
|
260
322
|
onRecord(record);
|
|
261
323
|
}
|
|
262
324
|
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
328
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
329
|
+
*
|
|
330
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
331
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
332
|
+
*/
|
|
333
|
+
static createRecordStream(records: Iterable<any> | AsyncIterable<any>): ReadableStream {
|
|
334
|
+
const encoder = new TextEncoder();
|
|
335
|
+
return new ReadableStream({
|
|
336
|
+
async start(controller) {
|
|
337
|
+
try {
|
|
338
|
+
for await (const record of records as AsyncIterable<any>) {
|
|
339
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
340
|
+
controller.enqueue(encoder.encode(json));
|
|
341
|
+
}
|
|
342
|
+
controller.close();
|
|
343
|
+
} catch (err) {
|
|
344
|
+
controller.error(err);
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
}
|
|
263
349
|
}
|
package/src/types.ts
CHANGED
|
@@ -60,6 +60,8 @@ export interface GetAgentResponse {
|
|
|
60
60
|
workflows: Record<string, GetWorkflowResponse>;
|
|
61
61
|
provider: string;
|
|
62
62
|
modelId: string;
|
|
63
|
+
defaultGenerateOptions: WithoutMethods<AgentGenerateOptions>;
|
|
64
|
+
defaultStreamOptions: WithoutMethods<AgentStreamOptions>;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|