@mastra/client-js 0.0.0-working-memory-per-user-20250620161509 → 0.0.0-zod-v4-compat-part-2-20250820135355

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +601 -2
  2. package/LICENSE.md +11 -42
  3. package/README.md +1 -0
  4. package/dist/adapters/agui.d.ts +23 -0
  5. package/dist/adapters/agui.d.ts.map +1 -0
  6. package/dist/client.d.ts +265 -0
  7. package/dist/client.d.ts.map +1 -0
  8. package/dist/example.d.ts +2 -0
  9. package/dist/example.d.ts.map +1 -0
  10. package/dist/index.cjs +883 -22
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.ts +4 -952
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +884 -23
  15. package/dist/index.js.map +1 -0
  16. package/dist/resources/a2a.d.ts +44 -0
  17. package/dist/resources/a2a.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +112 -0
  19. package/dist/resources/agent.d.ts.map +1 -0
  20. package/dist/resources/base.d.ts +13 -0
  21. package/dist/resources/base.d.ts.map +1 -0
  22. package/dist/resources/index.d.ts +11 -0
  23. package/dist/resources/index.d.ts.map +1 -0
  24. package/dist/resources/legacy-workflow.d.ts +87 -0
  25. package/dist/resources/legacy-workflow.d.ts.map +1 -0
  26. package/dist/resources/mcp-tool.d.ts +27 -0
  27. package/dist/resources/mcp-tool.d.ts.map +1 -0
  28. package/dist/resources/memory-thread.d.ts +53 -0
  29. package/dist/resources/memory-thread.d.ts.map +1 -0
  30. package/dist/resources/network-memory-thread.d.ts +47 -0
  31. package/dist/resources/network-memory-thread.d.ts.map +1 -0
  32. package/dist/resources/network.d.ts +30 -0
  33. package/dist/resources/network.d.ts.map +1 -0
  34. package/dist/resources/tool.d.ts +23 -0
  35. package/dist/resources/tool.d.ts.map +1 -0
  36. package/dist/resources/vNextNetwork.d.ts +42 -0
  37. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  38. package/dist/resources/vector.d.ts +48 -0
  39. package/dist/resources/vector.d.ts.map +1 -0
  40. package/dist/resources/workflow.d.ts +154 -0
  41. package/dist/resources/workflow.d.ts.map +1 -0
  42. package/dist/types.d.ts +422 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/utils/index.d.ts +3 -0
  45. package/dist/utils/index.d.ts.map +1 -0
  46. package/dist/utils/process-client-tools.d.ts +3 -0
  47. package/dist/utils/process-client-tools.d.ts.map +1 -0
  48. package/dist/utils/zod-to-json-schema.d.ts +3 -0
  49. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  50. package/integration-tests/agui-adapter.test.ts +122 -0
  51. package/integration-tests/package.json +18 -0
  52. package/integration-tests/src/mastra/index.ts +35 -0
  53. package/integration-tests/vitest.config.ts +9 -0
  54. package/package.json +16 -12
  55. package/src/adapters/agui.test.ts +145 -3
  56. package/src/client.ts +214 -1
  57. package/src/example.ts +46 -15
  58. package/src/index.test.ts +402 -6
  59. package/src/index.ts +1 -0
  60. package/src/resources/agent.ts +593 -25
  61. package/src/resources/base.ts +6 -0
  62. package/src/resources/memory-thread.test.ts +285 -0
  63. package/src/resources/memory-thread.ts +36 -0
  64. package/src/resources/network-memory-thread.test.ts +269 -0
  65. package/src/resources/network-memory-thread.ts +81 -0
  66. package/src/resources/network.ts +6 -6
  67. package/src/resources/vNextNetwork.ts +194 -0
  68. package/src/resources/workflow.ts +45 -8
  69. package/src/types.ts +171 -8
  70. package/src/utils/process-client-tools.ts +4 -3
  71. package/src/utils/zod-to-json-schema.ts +20 -3
  72. package/src/v2-messages.test.ts +180 -0
  73. package/tsconfig.build.json +9 -0
  74. package/tsconfig.json +1 -1
  75. package/tsup.config.ts +22 -0
  76. package/dist/index.d.cts +0 -952
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.0.0-working-memory-per-user-20250620161509",
3
+ "version": "0.0.0-zod-v4-compat-part-2-20250820135355",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -25,33 +25,37 @@
25
25
  "directory": "client-sdks/client-js"
26
26
  },
27
27
  "homepage": "https://github.com/mastra-ai/mastra/tree/main/client-sdks/client-js#readme",
28
- "license": "Elastic-2.0",
28
+ "license": "Apache-2.0",
29
29
  "dependencies": {
30
- "@ag-ui/client": "^0.0.27",
30
+ "@ag-ui/client": "^0.0.35",
31
31
  "@ai-sdk/ui-utils": "^1.2.11",
32
+ "@lukeed/uuid": "^2.0.1",
32
33
  "json-schema": "^0.4.0",
33
34
  "rxjs": "7.8.1",
34
- "zod": "^3.25.57",
35
35
  "zod-to-json-schema": "^3.24.5",
36
- "@mastra/core": "0.0.0-working-memory-per-user-20250620161509"
36
+ "@mastra/core": "0.0.0-zod-v4-compat-part-2-20250820135355"
37
37
  },
38
38
  "peerDependencies": {
39
- "zod": "^3.0.0"
39
+ "zod": "^3.0.0 || ^4.0.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@babel/preset-env": "^7.27.2",
42
+ "@babel/preset-env": "^7.28.0",
43
43
  "@babel/preset-typescript": "^7.27.1",
44
- "@tsconfig/recommended": "^1.0.8",
44
+ "@tsconfig/recommended": "^1.0.9",
45
45
  "@types/json-schema": "^7.0.15",
46
46
  "@types/node": "^20.19.0",
47
+ "zod": "^3.25.67",
48
+ "ai": "^4.3.19",
47
49
  "tsup": "^8.5.0",
48
50
  "typescript": "^5.8.3",
49
- "vitest": "^3.2.3",
50
- "@internal/lint": "0.0.0-working-memory-per-user-20250620161509"
51
+ "vitest": "^3.2.4",
52
+ "@internal/lint": "0.0.0-zod-v4-compat-part-2-20250820135355"
51
53
  },
52
54
  "scripts": {
53
- "build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
55
+ "build": "tsup --silent --config tsup.config.ts",
54
56
  "dev": "pnpm build --watch",
55
- "test": "vitest run"
57
+ "test": "vitest run && pnpm run test:integration",
58
+ "test:unit": "vitest run",
59
+ "test:integration": "cd integration-tests && pnpm test"
56
60
  }
57
61
  }
@@ -1,6 +1,9 @@
1
- import type { Message } from '@ag-ui/client';
2
- import { describe, it, expect } from 'vitest';
3
- import { generateUUID, convertMessagesToMastraMessages } from './agui';
1
+ import type { Message, BaseEvent } from '@ag-ui/client';
2
+ import { describe, it, expect, vi } from 'vitest';
3
+ import { generateUUID, convertMessagesToMastraMessages, AGUIAdapter } from './agui';
4
+ import { Agent } from '@mastra/core/agent';
5
+ import { MockLanguageModelV1 } from 'ai/test';
6
+ import { simulateReadableStream } from 'ai';
4
7
 
5
8
  describe('generateUUID', () => {
6
9
  it('should generate a valid UUID v4 string', () => {
@@ -178,3 +181,142 @@ describe('convertMessagesToMastraMessages', () => {
178
181
  expect(result[3].role).toBe('assistant');
179
182
  });
180
183
  });
184
+
185
+ describe('AGUIAdapter', () => {
186
+ it('should correctly pass parameters to agent stream method', async () => {
187
+ // Create a real agent with MockLanguageModelV1
188
+ const mockModel = new MockLanguageModelV1({
189
+ doStream: async () => ({
190
+ stream: simulateReadableStream({
191
+ chunks: [
192
+ { type: 'text-delta', textDelta: 'Hello' },
193
+ { type: 'text-delta', textDelta: ' from' },
194
+ { type: 'text-delta', textDelta: ' agent' },
195
+ {
196
+ type: 'finish',
197
+ finishReason: 'stop',
198
+ logprobs: undefined,
199
+ usage: { completionTokens: 3, promptTokens: 10 },
200
+ },
201
+ ],
202
+ }),
203
+ rawCall: { rawPrompt: null, rawSettings: {} },
204
+ }),
205
+ });
206
+
207
+ const agent = new Agent({
208
+ name: 'Test Agent',
209
+ instructions: 'You are a test agent',
210
+ model: mockModel,
211
+ });
212
+
213
+ // Create a mock client agent that simulates the expected behavior
214
+ const clientAgent = {
215
+ stream: vi.fn().mockImplementation(async (params: any) => {
216
+ // Verify the parameters are passed correctly
217
+ expect(params).toHaveProperty('messages');
218
+ expect(params).toHaveProperty('threadId');
219
+ expect(params).toHaveProperty('resourceId');
220
+ expect(params).toHaveProperty('runId');
221
+ expect(params).toHaveProperty('clientTools');
222
+
223
+ // Verify that messages array is passed, not the entire request object
224
+ expect(Array.isArray(params.messages)).toBe(true);
225
+ expect(params.messages[0]).toHaveProperty('role');
226
+ expect(params.messages[0]).toHaveProperty('content');
227
+
228
+ // Return a mock processDataStream that mimics the expected behavior
229
+ return {
230
+ processDataStream: vi.fn().mockImplementation(async ({ onTextPart, onFinishMessagePart }: any) => {
231
+ // Simulate streaming text
232
+ if (onTextPart) {
233
+ onTextPart('Hello from agent');
234
+ }
235
+ if (onFinishMessagePart) {
236
+ onFinishMessagePart();
237
+ }
238
+ return Promise.resolve();
239
+ }),
240
+ };
241
+ }),
242
+ };
243
+
244
+ const adapter = new AGUIAdapter({
245
+ agent: clientAgent as any,
246
+ agentId: 'test',
247
+ resourceId: 'testAgent',
248
+ });
249
+
250
+ const input = {
251
+ threadId: 'test-thread-id',
252
+ runId: 'test-run-id',
253
+ messages: [
254
+ {
255
+ id: '1',
256
+ role: 'user' as const,
257
+ content: 'Hello',
258
+ },
259
+ ],
260
+ tools: [],
261
+ context: [],
262
+ };
263
+
264
+ const observable = adapter['run'](input);
265
+ const events: BaseEvent[] = [];
266
+
267
+ await new Promise<void>((resolve, reject) => {
268
+ observable.subscribe({
269
+ next: (event: BaseEvent) => events.push(event),
270
+ complete: () => resolve(),
271
+ error: (error: any) => reject(error),
272
+ });
273
+ });
274
+
275
+ // Verify we received the expected events
276
+ expect(events).toHaveLength(5); // RUN_STARTED, TEXT_MESSAGE_START, TEXT_MESSAGE_CONTENT, TEXT_MESSAGE_END, RUN_FINISHED
277
+ expect(events[0].type).toBe('RUN_STARTED');
278
+ expect(events[1].type).toBe('TEXT_MESSAGE_START');
279
+ expect(events[2].type).toBe('TEXT_MESSAGE_CONTENT');
280
+ expect(events[3].type).toBe('TEXT_MESSAGE_END');
281
+ expect(events[4].type).toBe('RUN_FINISHED');
282
+
283
+ // Verify the stream method was called with the correct parameters
284
+ expect(clientAgent.stream).toHaveBeenCalledWith({
285
+ threadId: 'test-thread-id',
286
+ resourceId: 'testAgent',
287
+ runId: 'test-run-id',
288
+ messages: [{ role: 'user', content: 'Hello' }],
289
+ clientTools: {},
290
+ });
291
+ });
292
+
293
+ it('should handle messages without role property in request objects', async () => {
294
+ // This test demonstrates that request objects without role property
295
+ // would cause validation errors if passed directly to MessageList
296
+ const requestObject = {
297
+ threadId: 'test-thread-id',
298
+ resourceId: 'testAgent',
299
+ runId: 'test-run-id',
300
+ messages: [
301
+ {
302
+ role: 'user',
303
+ content: 'Hello',
304
+ },
305
+ ],
306
+ clientTools: {},
307
+ };
308
+
309
+ // Request objects don't have role property
310
+ expect('role' in requestObject).toBe(false);
311
+ expect('messages' in requestObject).toBe(true);
312
+ expect('content' in requestObject).toBe(false);
313
+ expect('parts' in requestObject).toBe(false);
314
+
315
+ // This structure would cause validation errors if treated as a message
316
+ // because it lacks required message properties (role, content/parts)
317
+ const hasValidMessageStructure =
318
+ 'role' in requestObject && ('content' in requestObject || 'parts' in requestObject);
319
+
320
+ expect(hasValidMessageStructure).toBe(false);
321
+ });
322
+ });
package/src/client.ts CHANGED
@@ -13,6 +13,8 @@ import {
13
13
  MCPTool,
14
14
  LegacyWorkflow,
15
15
  } from './resources';
16
+ import { NetworkMemoryThread } from './resources/network-memory-thread';
17
+ import { VNextNetwork } from './resources/vNextNetwork';
16
18
  import type {
17
19
  ClientOptions,
18
20
  CreateMemoryThreadParams,
@@ -33,6 +35,17 @@ import type {
33
35
  McpServerListResponse,
34
36
  McpServerToolListResponse,
35
37
  GetLegacyWorkflowResponse,
38
+ GetVNextNetworkResponse,
39
+ GetNetworkMemoryThreadParams,
40
+ CreateNetworkMemoryThreadParams,
41
+ SaveNetworkMessageToMemoryParams,
42
+ GetScorerResponse,
43
+ GetScoresByScorerIdParams,
44
+ GetScoresResponse,
45
+ GetScoresByRunIdParams,
46
+ GetScoresByEntityIdParams,
47
+ SaveScoreParams,
48
+ SaveScoreResponse,
36
49
  } from './types';
37
50
 
38
51
  export class MastraClient extends BaseResource {
@@ -123,6 +136,53 @@ export class MastraClient extends BaseResource {
123
136
  return this.request(`/api/memory/status?agentId=${agentId}`);
124
137
  }
125
138
 
139
+ /**
140
+ * Retrieves memory threads for a resource
141
+ * @param params - Parameters containing the resource ID
142
+ * @returns Promise containing array of memory threads
143
+ */
144
+ public getNetworkMemoryThreads(params: GetNetworkMemoryThreadParams): Promise<GetMemoryThreadResponse> {
145
+ return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
146
+ }
147
+
148
+ /**
149
+ * Creates a new memory thread
150
+ * @param params - Parameters for creating the memory thread
151
+ * @returns Promise containing the created memory thread
152
+ */
153
+ public createNetworkMemoryThread(params: CreateNetworkMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
154
+ return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: 'POST', body: params });
155
+ }
156
+
157
+ /**
158
+ * Gets a memory thread instance by ID
159
+ * @param threadId - ID of the memory thread to retrieve
160
+ * @returns MemoryThread instance
161
+ */
162
+ public getNetworkMemoryThread(threadId: string, networkId: string) {
163
+ return new NetworkMemoryThread(this.options, threadId, networkId);
164
+ }
165
+
166
+ /**
167
+ * Saves messages to memory
168
+ * @param params - Parameters containing messages to save
169
+ * @returns Promise containing the saved messages
170
+ */
171
+ public saveNetworkMessageToMemory(params: SaveNetworkMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
172
+ return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
173
+ method: 'POST',
174
+ body: params,
175
+ });
176
+ }
177
+
178
+ /**
179
+ * Gets the status of the memory system
180
+ * @returns Promise containing memory system status
181
+ */
182
+ public getNetworkMemoryStatus(networkId: string): Promise<{ result: boolean }> {
183
+ return this.request(`/api/memory/network/status?networkId=${networkId}`);
184
+ }
185
+
126
186
  /**
127
187
  * Retrieves all available tools
128
188
  * @returns Promise containing map of tool IDs to tool details
@@ -334,10 +394,18 @@ export class MastraClient extends BaseResource {
334
394
  * Retrieves all available networks
335
395
  * @returns Promise containing map of network IDs to network details
336
396
  */
337
- public getNetworks(): Promise<Record<string, GetNetworkResponse>> {
397
+ public getNetworks(): Promise<Array<GetNetworkResponse>> {
338
398
  return this.request('/api/networks');
339
399
  }
340
400
 
401
+ /**
402
+ * Retrieves all available vNext networks
403
+ * @returns Promise containing map of vNext network IDs to vNext network details
404
+ */
405
+ public getVNextNetworks(): Promise<Array<GetVNextNetworkResponse>> {
406
+ return this.request('/api/networks/v-next');
407
+ }
408
+
341
409
  /**
342
410
  * Gets a network instance by ID
343
411
  * @param networkId - ID of the network to retrieve
@@ -347,6 +415,15 @@ export class MastraClient extends BaseResource {
347
415
  return new Network(this.options, networkId);
348
416
  }
349
417
 
418
+ /**
419
+ * Gets a vNext network instance by ID
420
+ * @param networkId - ID of the vNext network to retrieve
421
+ * @returns vNext Network instance
422
+ */
423
+ public getVNextNetwork(networkId: string) {
424
+ return new VNextNetwork(this.options, networkId);
425
+ }
426
+
350
427
  /**
351
428
  * Retrieves a list of available MCP servers.
352
429
  * @param params - Optional parameters for pagination (limit, offset).
@@ -407,4 +484,140 @@ export class MastraClient extends BaseResource {
407
484
  public getA2A(agentId: string) {
408
485
  return new A2A(this.options, agentId);
409
486
  }
487
+
488
+ /**
489
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
490
+ * @param agentId - ID of the agent.
491
+ * @param threadId - ID of the thread.
492
+ * @param resourceId - Optional ID of the resource.
493
+ * @returns Working memory for the specified thread or resource.
494
+ */
495
+ public getWorkingMemory({
496
+ agentId,
497
+ threadId,
498
+ resourceId,
499
+ }: {
500
+ agentId: string;
501
+ threadId: string;
502
+ resourceId?: string;
503
+ }) {
504
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
505
+ }
506
+
507
+ /**
508
+ * Updates the working memory for a specific thread (optionally resource-scoped).
509
+ * @param agentId - ID of the agent.
510
+ * @param threadId - ID of the thread.
511
+ * @param workingMemory - The new working memory content.
512
+ * @param resourceId - Optional ID of the resource.
513
+ */
514
+ public updateWorkingMemory({
515
+ agentId,
516
+ threadId,
517
+ workingMemory,
518
+ resourceId,
519
+ }: {
520
+ agentId: string;
521
+ threadId: string;
522
+ workingMemory: string;
523
+ resourceId?: string;
524
+ }) {
525
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
526
+ method: 'POST',
527
+ body: {
528
+ workingMemory,
529
+ resourceId,
530
+ },
531
+ });
532
+ }
533
+
534
+ /**
535
+ * Retrieves all available scorers
536
+ * @returns Promise containing list of available scorers
537
+ */
538
+ public getScorers(): Promise<Record<string, GetScorerResponse>> {
539
+ return this.request('/api/scores/scorers');
540
+ }
541
+
542
+ /**
543
+ * Retrieves a scorer by ID
544
+ * @param scorerId - ID of the scorer to retrieve
545
+ * @returns Promise containing the scorer
546
+ */
547
+ public getScorer(scorerId: string): Promise<GetScorerResponse> {
548
+ return this.request(`/api/scores/scorers/${scorerId}`);
549
+ }
550
+
551
+ public getScoresByScorerId(params: GetScoresByScorerIdParams): Promise<GetScoresResponse> {
552
+ const { page, perPage, scorerId, entityId, entityType } = params;
553
+ const searchParams = new URLSearchParams();
554
+
555
+ if (entityId) {
556
+ searchParams.set('entityId', entityId);
557
+ }
558
+ if (entityType) {
559
+ searchParams.set('entityType', entityType);
560
+ }
561
+
562
+ if (page !== undefined) {
563
+ searchParams.set('page', String(page));
564
+ }
565
+ if (perPage !== undefined) {
566
+ searchParams.set('perPage', String(perPage));
567
+ }
568
+ const queryString = searchParams.toString();
569
+ return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ''}`);
570
+ }
571
+
572
+ /**
573
+ * Retrieves scores by run ID
574
+ * @param params - Parameters containing run ID and pagination options
575
+ * @returns Promise containing scores and pagination info
576
+ */
577
+ public getScoresByRunId(params: GetScoresByRunIdParams): Promise<GetScoresResponse> {
578
+ const { runId, page, perPage } = params;
579
+ const searchParams = new URLSearchParams();
580
+
581
+ if (page !== undefined) {
582
+ searchParams.set('page', String(page));
583
+ }
584
+ if (perPage !== undefined) {
585
+ searchParams.set('perPage', String(perPage));
586
+ }
587
+
588
+ const queryString = searchParams.toString();
589
+ return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ''}`);
590
+ }
591
+
592
+ /**
593
+ * Retrieves scores by entity ID and type
594
+ * @param params - Parameters containing entity ID, type, and pagination options
595
+ * @returns Promise containing scores and pagination info
596
+ */
597
+ public getScoresByEntityId(params: GetScoresByEntityIdParams): Promise<GetScoresResponse> {
598
+ const { entityId, entityType, page, perPage } = params;
599
+ const searchParams = new URLSearchParams();
600
+
601
+ if (page !== undefined) {
602
+ searchParams.set('page', String(page));
603
+ }
604
+ if (perPage !== undefined) {
605
+ searchParams.set('perPage', String(perPage));
606
+ }
607
+
608
+ const queryString = searchParams.toString();
609
+ return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ''}`);
610
+ }
611
+
612
+ /**
613
+ * Saves a score
614
+ * @param params - Parameters containing the score data to save
615
+ * @returns Promise containing the saved score
616
+ */
617
+ public saveScore(params: SaveScoreParams): Promise<SaveScoreResponse> {
618
+ return this.request('/api/scores', {
619
+ method: 'POST',
620
+ body: params,
621
+ });
622
+ }
410
623
  }
package/src/example.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { MastraClient } from './client';
2
+ import z from 'zod';
2
3
  // import type { WorkflowRunResult } from './types';
3
4
 
4
5
  // Agent
5
-
6
6
  (async () => {
7
7
  const client = new MastraClient({
8
8
  baseUrl: 'http://localhost:4111',
@@ -14,22 +14,53 @@ import { MastraClient } from './client';
14
14
  const agent = client.getAgent('weatherAgent');
15
15
  const response = await agent.stream({
16
16
  messages: 'what is the weather in new york?',
17
+ output: z.object({
18
+ weather: z.string(),
19
+ temperature: z.number(),
20
+ humidity: z.number(),
21
+ windSpeed: z.number(),
22
+ windDirection: z.string(),
23
+ windGust: z.number(),
24
+ windChill: z.number(),
25
+ }),
17
26
  });
18
27
 
19
- response.processDataStream({
20
- onTextPart: text => {
21
- process.stdout.write(text);
22
- },
23
- onFilePart: file => {
24
- console.log(file);
25
- },
26
- onDataPart: data => {
27
- console.log(data);
28
- },
29
- onErrorPart: error => {
30
- console.error(error);
31
- },
32
- });
28
+ // Process data stream - unstructured output
29
+
30
+ // response.processDataStream({
31
+ // onTextPart: text => {
32
+ // process.stdout.write(text);
33
+ // },
34
+ // onFilePart: file => {
35
+ // console.log(file);
36
+ // },
37
+ // onDataPart: data => {
38
+ // console.log(data);
39
+ // },
40
+ // onErrorPart: error => {
41
+ // console.error(error);
42
+ // },
43
+ // onToolCallPart(streamPart) {
44
+ // console.log(streamPart);
45
+ // },
46
+ // });
47
+
48
+ // Process text stream - structured output
49
+
50
+ // response.processTextStream({
51
+ // onTextPart: text => {
52
+ // process.stdout.write(text);
53
+ // },
54
+ // });
55
+
56
+ // read the response body directly
57
+
58
+ // const reader = response.body!.getReader();
59
+ // while (true) {
60
+ // const { done, value } = await reader.read();
61
+ // if (done) break;
62
+ // console.log(new TextDecoder().decode(value));
63
+ // }
33
64
  } catch (error) {
34
65
  console.error(error);
35
66
  }