@mastra/client-js 1.0.0-beta.21 → 1.0.0-beta.23
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 +115 -0
- package/dist/docs/README.md +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/SOURCE_MAP.json +1 -1
- package/dist/docs/ai-sdk/01-reference.md +2 -2
- package/dist/docs/client-js/01-reference.md +20 -8
- package/dist/docs/server/01-mastra-client.md +2 -2
- package/dist/index.cjs +62 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +62 -24
- package/dist/index.js.map +1 -1
- package/dist/resources/agent.d.ts +28 -6
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/types.d.ts +7 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,120 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`c8417b4`](https://github.com/mastra-ai/mastra/commit/c8417b41d9f3486854dc7842d977fbe5e2166264), [`dd4f34c`](https://github.com/mastra-ai/mastra/commit/dd4f34c78cbae24063463475b0619575c415f9b8)]:
|
|
8
|
+
- @mastra/core@1.0.0-beta.23
|
|
9
|
+
|
|
10
|
+
## 1.0.0-beta.22
|
|
11
|
+
|
|
12
|
+
### Major Changes
|
|
13
|
+
|
|
14
|
+
- **Breaking Change**: Convert OUTPUT generic from `OutputSchema` constraint to plain generic ([#11741](https://github.com/mastra-ai/mastra/pull/11741))
|
|
15
|
+
|
|
16
|
+
This change removes the direct dependency on Zod typings in the public API by converting all `OUTPUT extends OutputSchema` generic constraints to plain `OUTPUT` generics throughout the codebase. This is preparation for moving to a standard schema approach.
|
|
17
|
+
- All generic type parameters previously constrained to `OutputSchema` (e.g., `<OUTPUT extends OutputSchema = undefined>`) are now plain generics with defaults (e.g., `<OUTPUT = undefined>`)
|
|
18
|
+
- Affects all public APIs including `Agent`, `MastraModelOutput`, `AgentExecutionOptions`, and stream/generate methods
|
|
19
|
+
- `InferSchemaOutput<OUTPUT>` replaced with `OUTPUT` throughout
|
|
20
|
+
- `PartialSchemaOutput<OUTPUT>` replaced with `Partial<OUTPUT>`
|
|
21
|
+
- Schema fields now use `NonNullable<OutputSchema<OUTPUT>>` instead of `OUTPUT` directly
|
|
22
|
+
- Added `FullOutput<OUTPUT>` type representing complete output with all fields
|
|
23
|
+
- Added `AgentExecutionOptionsBase<OUTPUT>` type
|
|
24
|
+
- `getFullOutput()` method now returns `Promise<FullOutput<OUTPUT>>`
|
|
25
|
+
- `Agent` class now generic: `Agent<TAgentId, TTools, TOutput>`
|
|
26
|
+
- `agent.generate()` and `agent.stream()` methods have updated signatures
|
|
27
|
+
- `MastraModelOutput<OUTPUT>` no longer requires `OutputSchema` constraint
|
|
28
|
+
- Network route and streaming APIs updated to use plain OUTPUT generic
|
|
29
|
+
|
|
30
|
+
**Before:**
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
const output = await agent.generate<z.ZodType>({
|
|
34
|
+
messages: [...],
|
|
35
|
+
structuredOutput: { schema: mySchema }
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
**After:**
|
|
39
|
+
const output = await agent.generate<z.infer<typeof mySchema>>({
|
|
40
|
+
messages: [...],
|
|
41
|
+
structuredOutput: { schema: mySchema }
|
|
42
|
+
});
|
|
43
|
+
// Or rely on type inference:
|
|
44
|
+
const output = await agent.generate({
|
|
45
|
+
messages: [...],
|
|
46
|
+
structuredOutput: { schema: mySchema }
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- Removes the deprecated `threadId` and `resourceId` options from `AgentExecutionOptions`. These have been deprecated for months in favour of the `memory` option. ([#11897](https://github.com/mastra-ai/mastra/pull/11897))
|
|
54
|
+
|
|
55
|
+
### Breaking Changes
|
|
56
|
+
|
|
57
|
+
#### `@mastra/core`
|
|
58
|
+
|
|
59
|
+
The `threadId` and `resourceId` options have been removed from `agent.generate()` and `agent.stream()`. Use the `memory` option instead:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
// Before
|
|
63
|
+
await agent.stream('Hello', {
|
|
64
|
+
threadId: 'thread-123',
|
|
65
|
+
resourceId: 'user-456',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// After
|
|
69
|
+
await agent.stream('Hello', {
|
|
70
|
+
memory: {
|
|
71
|
+
thread: 'thread-123',
|
|
72
|
+
resource: 'user-456',
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### `@mastra/server`
|
|
78
|
+
|
|
79
|
+
The `threadId`, `resourceId`, and `resourceid` fields have been removed from the main agent execution body schema. The server now expects the `memory` option format in request bodies. Legacy routes (`/api/agents/:agentId/generate-legacy` and `/api/agents/:agentId/stream-legacy`) continue to support the deprecated fields.
|
|
80
|
+
|
|
81
|
+
#### `@mastra/react`
|
|
82
|
+
|
|
83
|
+
The `useChat` hook now internally converts `threadId` to the `memory` option format when making API calls. No changes needed in component code - the hook handles the conversion automatically.
|
|
84
|
+
|
|
85
|
+
#### `@mastra/client-js`
|
|
86
|
+
|
|
87
|
+
When using the client SDK agent methods, use the `memory` option instead of `threadId`/`resourceId`:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
const agent = client.getAgent('my-agent');
|
|
91
|
+
|
|
92
|
+
// Before
|
|
93
|
+
await agent.generate({
|
|
94
|
+
messages: [...],
|
|
95
|
+
threadId: 'thread-123',
|
|
96
|
+
resourceId: 'user-456',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// After
|
|
100
|
+
await agent.generate({
|
|
101
|
+
messages: [...],
|
|
102
|
+
memory: {
|
|
103
|
+
thread: 'thread-123',
|
|
104
|
+
resource: 'user-456',
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- Add human-in-the-loop (HITL) support to agent networks ([#11678](https://github.com/mastra-ai/mastra/pull/11678))
|
|
110
|
+
- Add suspend/resume capabilities to agent network
|
|
111
|
+
- Enable auto-resume for suspended network execution via `autoResumeSuspendedTools`
|
|
112
|
+
|
|
113
|
+
`agent.resumeNetwork`, `agent.approveNetworkToolCall`, `agent.declineNetworkToolCall`
|
|
114
|
+
|
|
115
|
+
- Updated dependencies [[`ebae12a`](https://github.com/mastra-ai/mastra/commit/ebae12a2dd0212e75478981053b148a2c246962d), [`c61a0a5`](https://github.com/mastra-ai/mastra/commit/c61a0a5de4904c88fd8b3718bc26d1be1c2ec6e7), [`69136e7`](https://github.com/mastra-ai/mastra/commit/69136e748e32f57297728a4e0f9a75988462f1a7), [`449aed2`](https://github.com/mastra-ai/mastra/commit/449aed2ba9d507b75bf93d427646ea94f734dfd1), [`eb648a2`](https://github.com/mastra-ai/mastra/commit/eb648a2cc1728f7678768dd70cd77619b448dab9), [`0131105`](https://github.com/mastra-ai/mastra/commit/0131105532e83bdcbb73352fc7d0879eebf140dc), [`9d5059e`](https://github.com/mastra-ai/mastra/commit/9d5059eae810829935fb08e81a9bb7ecd5b144a7), [`ef756c6`](https://github.com/mastra-ai/mastra/commit/ef756c65f82d16531c43f49a27290a416611e526), [`b00ccd3`](https://github.com/mastra-ai/mastra/commit/b00ccd325ebd5d9e37e34dd0a105caae67eb568f), [`3bdfa75`](https://github.com/mastra-ai/mastra/commit/3bdfa7507a91db66f176ba8221aa28dd546e464a), [`e770de9`](https://github.com/mastra-ai/mastra/commit/e770de941a287a49b1964d44db5a5763d19890a6), [`52e2716`](https://github.com/mastra-ai/mastra/commit/52e2716b42df6eff443de72360ae83e86ec23993), [`27b4040`](https://github.com/mastra-ai/mastra/commit/27b4040bfa1a95d92546f420a02a626b1419a1d6), [`610a70b`](https://github.com/mastra-ai/mastra/commit/610a70bdad282079f0c630e0d7bb284578f20151), [`8dc7f55`](https://github.com/mastra-ai/mastra/commit/8dc7f55900395771da851dc7d78d53ae84fe34ec), [`8379099`](https://github.com/mastra-ai/mastra/commit/8379099fc467af6bef54dd7f80c9bd75bf8bbddf), [`8c0ec25`](https://github.com/mastra-ai/mastra/commit/8c0ec25646c8a7df253ed1e5ff4863a0d3f1316c), [`ff4d9a6`](https://github.com/mastra-ai/mastra/commit/ff4d9a6704fc87b31a380a76ed22736fdedbba5a), [`69821ef`](https://github.com/mastra-ai/mastra/commit/69821ef806482e2c44e2197ac0b050c3fe3a5285), [`1ed5716`](https://github.com/mastra-ai/mastra/commit/1ed5716830867b3774c4a1b43cc0d82935f32b96), [`4186bdd`](https://github.com/mastra-ai/mastra/commit/4186bdd00731305726fa06adba0b076a1d50b49f), [`7aaf973`](https://github.com/mastra-ai/mastra/commit/7aaf973f83fbbe9521f1f9e7a4fd99b8de464617)]:
|
|
116
|
+
- @mastra/core@1.0.0-beta.22
|
|
117
|
+
|
|
3
118
|
## 1.0.0-beta.21
|
|
4
119
|
|
|
5
120
|
### Patch Changes
|
package/dist/docs/README.md
CHANGED
package/dist/docs/SKILL.md
CHANGED
|
@@ -295,7 +295,7 @@ const uiMessages = toAISdkV4Messages(messages);
|
|
|
295
295
|
|
|
296
296
|
> API reference for toAISdkV5Messages(), a function to convert Mastra messages to AI SDK v5 UI messages.
|
|
297
297
|
|
|
298
|
-
Converts messages from various input formats to AI SDK V5 UI message format. This function accepts messages in multiple formats (strings, AI SDK V4/V5 messages, Mastra DB messages, etc.) and normalizes them to the AI SDK V5 `UIMessage` format, which is suitable for use with AI SDK UI components like `useChat()`.
|
|
298
|
+
Converts messages from various input formats to AI SDK V5 (and later) UI message format. This function accepts messages in multiple formats (strings, AI SDK V4/V5 messages, Mastra DB messages, etc.) and normalizes them to the AI SDK V5+ `UIMessage` format, which is suitable for use with AI SDK UI components like `useChat()`.
|
|
299
299
|
|
|
300
300
|
## Usage example
|
|
301
301
|
|
|
@@ -332,7 +332,7 @@ export default function Chat() {
|
|
|
332
332
|
|
|
333
333
|
## Returns
|
|
334
334
|
|
|
335
|
-
Returns an array of AI SDK V5 `UIMessage` objects with the following structure:
|
|
335
|
+
Returns an array of AI SDK V5+ `UIMessage` objects with the following structure:
|
|
336
336
|
|
|
337
337
|
## Examples
|
|
338
338
|
|
|
@@ -67,12 +67,14 @@ const response = await agent.generate(
|
|
|
67
67
|
);
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
You can also use the simplified string format:
|
|
70
|
+
You can also use the simplified string format with memory options:
|
|
71
71
|
|
|
72
72
|
```typescript
|
|
73
73
|
const response = await agent.generate("Hello, how are you?", {
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
memory: {
|
|
75
|
+
thread: "thread-1",
|
|
76
|
+
resource: "resource-1",
|
|
77
|
+
},
|
|
76
78
|
});
|
|
77
79
|
```
|
|
78
80
|
|
|
@@ -91,11 +93,14 @@ response.processDataStream({
|
|
|
91
93
|
});
|
|
92
94
|
```
|
|
93
95
|
|
|
94
|
-
You can also use the simplified string format:
|
|
96
|
+
You can also use the simplified string format with memory options:
|
|
95
97
|
|
|
96
98
|
```typescript
|
|
97
99
|
const response = await agent.stream("Tell me a story", {
|
|
98
|
-
|
|
100
|
+
memory: {
|
|
101
|
+
thread: "thread-1",
|
|
102
|
+
resource: "resource-1",
|
|
103
|
+
},
|
|
99
104
|
clientTools: { colorChangeTool },
|
|
100
105
|
});
|
|
101
106
|
|
|
@@ -1062,7 +1067,7 @@ await run.start({
|
|
|
1062
1067
|
});
|
|
1063
1068
|
|
|
1064
1069
|
// Poll for results later
|
|
1065
|
-
const result = await workflow.
|
|
1070
|
+
const result = await workflow.runById(run.runId);
|
|
1066
1071
|
```
|
|
1067
1072
|
|
|
1068
1073
|
This is useful for long-running workflows where you want to start execution and check results later.
|
|
@@ -1126,12 +1131,19 @@ for await (const chunk of stream) {
|
|
|
1126
1131
|
}
|
|
1127
1132
|
```
|
|
1128
1133
|
|
|
1129
|
-
###
|
|
1134
|
+
### runById()
|
|
1130
1135
|
|
|
1131
1136
|
Get the execution result for a workflow run:
|
|
1132
1137
|
|
|
1133
1138
|
```typescript
|
|
1134
|
-
const result = await workflow.
|
|
1139
|
+
const result = await workflow.runById(runId);
|
|
1140
|
+
|
|
1141
|
+
// Or with options for performance optimization:
|
|
1142
|
+
const result = await workflow.runById(runId, {
|
|
1143
|
+
fields: ['status', 'result'], // Only fetch specific fields
|
|
1144
|
+
withNestedWorkflows: false, // Skip expensive nested workflow data
|
|
1145
|
+
requestContext: { userId: 'user-123' }, // Optional request context
|
|
1146
|
+
});
|
|
1135
1147
|
```
|
|
1136
1148
|
|
|
1137
1149
|
<h3>Run result format</h3>
|
|
@@ -102,7 +102,7 @@ const testAgent = async () => {
|
|
|
102
102
|
|
|
103
103
|
> **Note:**
|
|
104
104
|
|
|
105
|
-
Visit [.generate()](https://mastra.ai/reference/v1/client-js/agents#generate
|
|
105
|
+
Visit [.generate()](https://mastra.ai/reference/v1/client-js/agents#generate) for more information.
|
|
106
106
|
|
|
107
107
|
## Streaming responses
|
|
108
108
|
|
|
@@ -137,7 +137,7 @@ const testAgent = async () => {
|
|
|
137
137
|
|
|
138
138
|
> **Note:**
|
|
139
139
|
|
|
140
|
-
Visit [.stream()](https://mastra.ai/reference/v1/client-js/agents#stream
|
|
140
|
+
Visit [.stream()](https://mastra.ai/reference/v1/client-js/agents#stream) for more information.
|
|
141
141
|
|
|
142
142
|
## Configuration options
|
|
143
143
|
|
package/dist/index.cjs
CHANGED
|
@@ -1331,10 +1331,7 @@ async function executeToolCallAndRespond({
|
|
|
1331
1331
|
]
|
|
1332
1332
|
}
|
|
1333
1333
|
];
|
|
1334
|
-
return respondFn(
|
|
1335
|
-
...params,
|
|
1336
|
-
messages: updatedMessages
|
|
1337
|
-
});
|
|
1334
|
+
return respondFn(updatedMessages, params);
|
|
1338
1335
|
}
|
|
1339
1336
|
}
|
|
1340
1337
|
}
|
|
@@ -1478,16 +1475,11 @@ var Agent = class extends BaseResource {
|
|
|
1478
1475
|
}
|
|
1479
1476
|
return response;
|
|
1480
1477
|
}
|
|
1481
|
-
async generate(
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
}
|
|
1486
|
-
params = {
|
|
1487
|
-
messages: messagesOrParams,
|
|
1488
|
-
...options
|
|
1489
|
-
};
|
|
1490
|
-
}
|
|
1478
|
+
async generate(messages, options) {
|
|
1479
|
+
const params = {
|
|
1480
|
+
...options,
|
|
1481
|
+
messages
|
|
1482
|
+
};
|
|
1491
1483
|
const processedParams = {
|
|
1492
1484
|
...params,
|
|
1493
1485
|
requestContext: parseClientRequestContext(params.requestContext),
|
|
@@ -1497,7 +1489,10 @@ var Agent = class extends BaseResource {
|
|
|
1497
1489
|
schema: zodToJsonSchema2(params.structuredOutput.schema)
|
|
1498
1490
|
} : void 0
|
|
1499
1491
|
};
|
|
1500
|
-
const {
|
|
1492
|
+
const { memory, requestContext } = processedParams;
|
|
1493
|
+
const { resource, thread } = memory ?? {};
|
|
1494
|
+
const resourceId = resource;
|
|
1495
|
+
const threadId = typeof thread === "string" ? thread : thread?.id;
|
|
1501
1496
|
const response = await this.request(
|
|
1502
1497
|
`/api/agents/${this.agentId}/generate`,
|
|
1503
1498
|
{
|
|
@@ -2222,16 +2217,59 @@ var Agent = class extends BaseResource {
|
|
|
2222
2217
|
};
|
|
2223
2218
|
return streamResponse;
|
|
2224
2219
|
}
|
|
2225
|
-
async
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
params
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
};
|
|
2220
|
+
async approveNetworkToolCall(params) {
|
|
2221
|
+
const response = await this.request(`/api/agents/${this.agentId}/approve-network-tool-call`, {
|
|
2222
|
+
method: "POST",
|
|
2223
|
+
body: params,
|
|
2224
|
+
stream: true
|
|
2225
|
+
});
|
|
2226
|
+
if (!response.body) {
|
|
2227
|
+
throw new Error("No response body");
|
|
2234
2228
|
}
|
|
2229
|
+
const streamResponse = new Response(response.body, {
|
|
2230
|
+
status: response.status,
|
|
2231
|
+
statusText: response.statusText,
|
|
2232
|
+
headers: response.headers
|
|
2233
|
+
});
|
|
2234
|
+
streamResponse.processDataStream = async ({
|
|
2235
|
+
onChunk
|
|
2236
|
+
}) => {
|
|
2237
|
+
await processMastraNetworkStream({
|
|
2238
|
+
stream: streamResponse.body,
|
|
2239
|
+
onChunk
|
|
2240
|
+
});
|
|
2241
|
+
};
|
|
2242
|
+
return streamResponse;
|
|
2243
|
+
}
|
|
2244
|
+
async declineNetworkToolCall(params) {
|
|
2245
|
+
const response = await this.request(`/api/agents/${this.agentId}/decline-network-tool-call`, {
|
|
2246
|
+
method: "POST",
|
|
2247
|
+
body: params,
|
|
2248
|
+
stream: true
|
|
2249
|
+
});
|
|
2250
|
+
if (!response.body) {
|
|
2251
|
+
throw new Error("No response body");
|
|
2252
|
+
}
|
|
2253
|
+
const streamResponse = new Response(response.body, {
|
|
2254
|
+
status: response.status,
|
|
2255
|
+
statusText: response.statusText,
|
|
2256
|
+
headers: response.headers
|
|
2257
|
+
});
|
|
2258
|
+
streamResponse.processDataStream = async ({
|
|
2259
|
+
onChunk
|
|
2260
|
+
}) => {
|
|
2261
|
+
await processMastraNetworkStream({
|
|
2262
|
+
stream: streamResponse.body,
|
|
2263
|
+
onChunk
|
|
2264
|
+
});
|
|
2265
|
+
};
|
|
2266
|
+
return streamResponse;
|
|
2267
|
+
}
|
|
2268
|
+
async stream(messagesOrParams, options) {
|
|
2269
|
+
let params = {
|
|
2270
|
+
messages: messagesOrParams,
|
|
2271
|
+
...options
|
|
2272
|
+
};
|
|
2235
2273
|
const processedParams = {
|
|
2236
2274
|
...params,
|
|
2237
2275
|
requestContext: parseClientRequestContext(params.requestContext),
|