@mastra/client-js 1.39.0-alpha.8 → 1.39.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.
@@ -0,0 +1,339 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Client SDK
4
+
5
+ Client SDK changes align with server-side API updates, including utility renames, updated pagination, and type naming conventions.
6
+
7
+ ## Changed
8
+
9
+ ### `messages` is now identical to `@mastra/core/agent` syntax
10
+
11
+ The `messages` argument is now the first argument of the `generate`, `stream` and `network` method calls, similar to the NodeJS version in `@mastra/core/agent`.
12
+
13
+ To migrate, move `messages` to the first argument of the method call:
14
+
15
+ **Using `@mastra/client-js`:**
16
+
17
+ ```diff
18
+ const agent = client.getAgent('my-agent');
19
+
20
+ - await agent.generate({
21
+ - messages: [...]
22
+ + await agent.generate([...], {
23
+ });
24
+
25
+ - await agent.stream({
26
+ - messages: [...]
27
+ + await agent.stream([...], {
28
+ });
29
+
30
+ - await agent.network({
31
+ - messages: [...]
32
+ + await agent.network([...], {
33
+ });
34
+ ```
35
+
36
+ > **Codemod:** You can use Mastra's codemod CLI to update your code automatically:
37
+ >
38
+ > ```bash
39
+ > npx @mastra/codemod@latest v1/client-msg-function-args .
40
+ > ```
41
+
42
+ ### `threadId` and `resourceId` to `memory` option
43
+
44
+ The `threadId` and `resourceId` options have been removed from agent method calls. Use the `memory` option instead, which provides a cleaner API for memory configuration. This applies to both `@mastra/client-js` and `@mastra/react` packages.
45
+
46
+ To migrate, move `threadId` and `resourceId` into the `memory` option:
47
+
48
+ **Using `@mastra/client-js`:**
49
+
50
+ ```diff
51
+ const agent = client.getAgent('my-agent');
52
+
53
+ await agent.generate([...], {
54
+ - threadId: 'thread-123',
55
+ - resourceId: 'user-456',
56
+ + memory: {
57
+ + thread: 'thread-123',
58
+ + resource: 'user-456',
59
+ + },
60
+ });
61
+
62
+ + await agent.stream([...], {
63
+ - threadId: 'thread-123',
64
+ - resourceId: 'user-456',
65
+ + memory: {
66
+ + thread: 'thread-123',
67
+ + resource: 'user-456',
68
+ + },
69
+ });
70
+ ```
71
+
72
+ #### Using `@mastra/react` `useChat` hook
73
+
74
+ The `useChat` hook internally passes the memory option when you provide a `threadId`. No changes are needed in your component code if you're using the hook's built-in memory handling. However, if you were manually passing options to `sendMessage`, update them accordingly:
75
+
76
+ ```diff
77
+ const { sendMessage } = useChat({ agentId: 'my-agent' });
78
+
79
+ await sendMessage({
80
+ message: 'Hello',
81
+ mode: 'stream',
82
+ - threadId: 'thread-123',
83
+ + threadId: 'thread-123', // Still works - internally converted to memory option
84
+ });
85
+ ```
86
+
87
+ The `memory` option also supports passing thread metadata when creating new threads:
88
+
89
+ ```typescript
90
+ await agent.generate([...], {
91
+ memory: {
92
+ thread: {
93
+ id: 'thread-123',
94
+ title: 'Support conversation',
95
+ metadata: { category: 'billing' },
96
+ },
97
+ resource: 'user-456',
98
+ },
99
+ });
100
+ ```
101
+
102
+ ### Client SDK types from `Get*` to `List*`
103
+
104
+ Client SDK types have been renamed from `Get*` to `List*` pattern. This change aligns type names with the method naming convention.
105
+
106
+ To migrate, update type imports to use the new naming pattern.
107
+
108
+ ```diff
109
+ - import type {
110
+ - GetWorkflowRunsParams,
111
+ - GetWorkflowRunsResponse,
112
+ - GetMemoryThreadParams,
113
+ - } from '@mastra/client-js';
114
+ + import type {
115
+ + ListWorkflowRunsParams,
116
+ + ListWorkflowRunsResponse,
117
+ + ListMemoryThreadsParams,
118
+ + } from '@mastra/client-js';
119
+ ```
120
+
121
+ > **Codemod:** You can use Mastra's codemod CLI to update your code automatically:
122
+ >
123
+ > ```bash
124
+ > npx @mastra/codemod@latest v1/client-sdk-types .
125
+ > ```
126
+
127
+ ### Pagination parameters from `offset/limit` to `page/perPage`
128
+
129
+ All client SDK methods that used `offset/limit` now use `page/perPage`, matching page-based web pagination.
130
+
131
+ To migrate, update pagination parameters in all client SDK method calls. Example:
132
+
133
+ ```diff
134
+ client.memory.listMessages({
135
+ threadId: 'thread-123',
136
+ - offset: 0,
137
+ - limit: 20,
138
+ + page: 0,
139
+ + perPage: 20,
140
+ });
141
+ ```
142
+
143
+ > **Codemod:** You can use Mastra's codemod CLI to update your code automatically:
144
+ >
145
+ > ```bash
146
+ > npx @mastra/codemod@latest v1/client-offset-limit .
147
+ > ```
148
+
149
+ ### `getMemoryThread` parameter structure
150
+
151
+ The `getMemoryThread` method parameter structure has been updated. This change provides a more consistent API across memory methods.
152
+
153
+ To migrate, update the method call with the new parameter structure. Check the updated API documentation for the specific changes.
154
+
155
+ ```diff
156
+ - const thread = await client.getMemoryThread(threadId, agentId);
157
+ + const thread = await client.getMemoryThread({ threadId, agentId });
158
+ ```
159
+
160
+ > **Codemod:** You can use Mastra's codemod CLI to update your code automatically:
161
+ >
162
+ > ```bash
163
+ > npx @mastra/codemod@latest v1/client-get-memory-thread .
164
+ > ```
165
+
166
+ ### Unified `runById` API for workflow runs
167
+
168
+ The `runById()` method now returns a unified `WorkflowState` object containing both metadata (runId, workflowName, resourceId, createdAt, updatedAt) and processed execution state (status, result, error, payload, steps). This unifies the previously separate `runById()` and `runExecutionResult()` methods.
169
+
170
+ The method also accepts an options object with optional `fields` and `withNestedWorkflows` parameters for performance optimization.
171
+
172
+ ```diff
173
+ const workflow = client.getWorkflow('my-workflow');
174
+
175
+ - // Previously: runById returned raw WorkflowRun with snapshot
176
+ - const run = await workflow.runById(runId, requestContext);
177
+ - // Separately: runExecutionResult returned processed execution state
178
+ - const result = await workflow.runExecutionResult(runId);
179
+
180
+ + // Now: Single method returns unified WorkflowState
181
+ + const run = await workflow.runById(runId, {
182
+ + requestContext, // Optional request context
183
+ + fields: ['status', 'result'], // Optional: request only specific fields
184
+ + withNestedWorkflows: false, // Optional: skip nested workflow data for performance
185
+ + });
186
+ + // Returns: { runId, workflowName, resourceId, createdAt, updatedAt, status, result, error, payload, steps }
187
+ ```
188
+
189
+ ## Removed
190
+
191
+ ### `runExecutionResult` method and `GetWorkflowRunExecutionResultResponse` type
192
+
193
+ The `runExecutionResult()` method and `GetWorkflowRunExecutionResultResponse` type have been removed from `@mastra/client-js`. The `/execution-result` API endpoints have also been removed.
194
+
195
+ To migrate, use `runById()` instead, which now returns the same unified `WorkflowState` with both metadata and processed execution state.
196
+
197
+ ```diff
198
+ - import type { GetWorkflowRunExecutionResultResponse } from '@mastra/client-js';
199
+ -
200
+ - const workflow = client.getWorkflow('my-workflow');
201
+ - const result = await workflow.runExecutionResult(runId);
202
+
203
+ + const workflow = client.getWorkflow('my-workflow');
204
+ + const result = await workflow.runById(runId);
205
+ + // Or with options for performance optimization:
206
+ + const result = await workflow.runById(runId, {
207
+ + fields: ['status', 'result'], // Only fetch specific fields
208
+ + withNestedWorkflows: false, // Skip expensive nested workflow data
209
+ + });
210
+ ```
211
+
212
+ ### `toAISdkFormat` function
213
+
214
+ The `toAISdkFormat()` function has been removed from `@mastra/ai-sdk`. Use the stream conversion utilities shown below instead.
215
+
216
+ To migrate, use `toAISdkStream()` instead.
217
+
218
+ ```diff
219
+ - import { toAISdkFormat } from '@mastra/ai-sdk';
220
+ - const stream = toAISdkFormat(agentStream, { from: 'agent' });
221
+ + import { toAISdkStream } from '@mastra/ai-sdk';
222
+ + const stream = toAISdkStream(agentStream, { from: 'agent' });
223
+ ```
224
+
225
+ > **Codemod:** You can use Mastra's codemod CLI to update your code automatically:
226
+ >
227
+ > ```bash
228
+ > npx @mastra/codemod@latest v1/client-to-ai-sdk-format .
229
+ > ```
230
+
231
+ ### Network memory methods
232
+
233
+ Network memory methods have been removed from `@mastra/client-js`. The `NetworkMemoryThread` class and all network memory-related methods are no longer available. This change simplifies the memory API by removing specialized network memory functionality.
234
+
235
+ To migrate, use regular memory APIs instead of network memory.
236
+
237
+ ```diff
238
+ - import { MastraClient } from '@mastra/client-js';
239
+ -
240
+ - const client = new MastraClient({ baseUrl: '...' });
241
+ - const networkThread = client.networkMemory.getThread('thread-id');
242
+ - const networkThread = client.memory.networkThread('thread-id', 'network-id');
243
+ - await networkThread.get();
244
+ - await networkThread.getMessages();
245
+
246
+ + // Use regular memory thread APIs instead
247
+ + const client = new MastraClient({ baseUrl: '...' });
248
+ + const thread = client.memory.getThread('thread-id');
249
+ + await thread.get();
250
+ + const messages = await thread.listMessages();
251
+ ```
252
+
253
+ ### Watch-related types
254
+
255
+ Watch-related types have been removed from `@mastra/client-js`. This includes `WorkflowWatchResult`, `WatchEvent`, and related types. This change reflects the removal of the watch API in favor of streaming.
256
+
257
+ To migrate, use workflow streaming APIs instead of watch.
258
+
259
+ ```diff
260
+ - import type { WorkflowWatchResult, WatchEvent } from '@mastra/client-js';
261
+ -
262
+ - const workflow = client.getWorkflow('my-workflow');
263
+ - const run = await workflow.createRun();
264
+ - await run.watch((event: WatchEvent) => {
265
+ - console.log('Event:', event);
266
+ - });
267
+
268
+ + const workflow = client.getWorkflow('my-workflow');
269
+ + const run = await workflow.createRun();
270
+ + const stream = await run.stream({ inputData: { ... } });
271
+ + for await (const chunk of stream) {
272
+ + console.log('Event:', chunk);
273
+ + }
274
+ ```
275
+
276
+ ### Run-related methods can't be called directly on workflow instance
277
+
278
+ Run-related methods can't be called directly on workflow instance. You need to create a run instance first using `createRun()` method.
279
+
280
+ ```diff
281
+ - const result = await workflow.start({ runId: '123', inputData: { ... } });
282
+ + const run = await workflow.createRun({ runId: '123' });
283
+ + const result = await run.start({ inputData: { ... } });
284
+ ```
285
+
286
+ ```diff
287
+ - const result = await workflow.stream({ runId: '123', inputData: { ... } });
288
+ + const run = await workflow.createRun({ runId: '123' });
289
+ + const stream = await run.stream({ inputData: { ... } });
290
+ ```
291
+
292
+ ### `streamVNext`, `resumeStreamVNext`, and `observeStreamVNext` methods
293
+
294
+ The experimental `streamVNext()`, `resumeStreamVNext()`, and `observeStreamVNext()` methods have been removed. These methods are now the standard implementation with updated event structures and return types.
295
+
296
+ To migrate, use the standard `stream()`, `resumeStream()`, and `observeStream()` methods instead.
297
+
298
+ ```diff
299
+ + const run = await workflow.createRun({ runId: '123' });
300
+ - const stream = await run.streamVNext({ inputData: { ... } });
301
+ + const stream = await run.stream({ inputData: { ... } });
302
+ ```
303
+
304
+ ### Deprecated stream endpoints
305
+
306
+ Some stream endpoints are deprecated and will be removed. The `/api/agents/:agentId/stream/vnext` endpoint returns 410 Gone, and `/api/agents/:agentId/stream/ui` is deprecated. This change consolidates on standard streaming endpoints.
307
+
308
+ To migrate, use the standard stream endpoint or `@mastra/ai-sdk` for UI message transformations.
309
+
310
+ ```diff
311
+ - const response = await fetch('/api/agents/my-agent/stream/vnext', {
312
+ - method: 'POST',
313
+ - body: JSON.stringify({ messages: [...] }),
314
+ - });
315
+
316
+ + const response = await fetch('/api/agents/my-agent/stream', {
317
+ + method: 'POST',
318
+ + body: JSON.stringify({ messages: [...] }),
319
+ + });
320
+ +
321
+ + // Or use @mastra/ai-sdk for UI message transformations
322
+ ```
323
+
324
+ ### Network memory API endpoints
325
+
326
+ Network memory API endpoints have been removed including `/api/memory/network/*`. This change simplifies the memory API surface.
327
+
328
+ To migrate, use regular memory API endpoints.
329
+
330
+ ```diff
331
+ - const networkThread = await fetch('/api/memory/network/threads/thread-123');
332
+ + const thread = await fetch('/api/memory/threads/thread-123');
333
+ ```
334
+
335
+ ### Eval-related client SDK types
336
+
337
+ Several eval-related types have been removed from the client SDK including `GetEvalsByAgentIdResponse`, `GetTelemetryResponse`, and `GetTelemetryParams`. This change reflects the removal of legacy evals functionality.
338
+
339
+ To migrate, use the new scorers API instead of legacy evals.