@mastra/client-js 1.7.2 → 1.7.3
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 +18 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-ai-sdk-to-ai-sdk-stream.md +9 -9
- package/dist/docs/references/reference-ai-sdk-to-ai-sdk-v4-messages.md +9 -9
- package/dist/docs/references/reference-ai-sdk-to-ai-sdk-v5-messages.md +5 -5
- package/dist/docs/references/reference-client-js-mastra-client.md +23 -23
- package/dist/docs/references/reference-client-js-workflows.md +3 -3
- package/dist/index.cjs +19 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- package/dist/resources/agent.d.ts.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
+
## 1.7.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix agent losing conversation context ("amnesia") when using client-side tools with stateless server deployments. Recursive calls after tool execution now include the full conversation history when no `threadId` is provided. ([#11476](https://github.com/mastra-ai/mastra/pull/11476))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`41e48c1`](https://github.com/mastra-ai/mastra/commit/41e48c198eee846478e60c02ec432c19d322a517), [`82469d3`](https://github.com/mastra-ai/mastra/commit/82469d3135d5a49dd8dc8feec0ff398b4e0225a0), [`33e2fd5`](https://github.com/mastra-ai/mastra/commit/33e2fd5088f83666df17401e2da68c943dbc0448), [`7ef6e2c`](https://github.com/mastra-ai/mastra/commit/7ef6e2c61be5a42e26f55d15b5902866fc76634f), [`b12d2a5`](https://github.com/mastra-ai/mastra/commit/b12d2a59a48be0477cabae66eb6cf0fc94a7d40d), [`fa37d39`](https://github.com/mastra-ai/mastra/commit/fa37d39910421feaf8847716292e3d65dd4f30c2), [`b12d2a5`](https://github.com/mastra-ai/mastra/commit/b12d2a59a48be0477cabae66eb6cf0fc94a7d40d), [`71c38bf`](https://github.com/mastra-ai/mastra/commit/71c38bf905905148ecd0e75c07c1f9825d299b76), [`f993c38`](https://github.com/mastra-ai/mastra/commit/f993c3848c97479b813231be872443bedeced6ab), [`f51849a`](https://github.com/mastra-ai/mastra/commit/f51849a568935122b5100b7ee69704e6d680cf7b), [`9bf3a0d`](https://github.com/mastra-ai/mastra/commit/9bf3a0dac602787925f1762f1f0387d7b4a59620), [`cafa045`](https://github.com/mastra-ai/mastra/commit/cafa0453c9de141ad50c09a13894622dffdd9978), [`1fd9ddb`](https://github.com/mastra-ai/mastra/commit/1fd9ddbb3fe83b281b12bd2e27e426ae86288266), [`6135ef4`](https://github.com/mastra-ai/mastra/commit/6135ef4f5288652bf45f616ec590607e4c95f443), [`d9d228c`](https://github.com/mastra-ai/mastra/commit/d9d228c0c6ae82ae6ce3b540a3a56b2b1c2b8d98), [`5576507`](https://github.com/mastra-ai/mastra/commit/55765071e360fb97e443aa0a91ccf7e1cd8d92aa), [`79d69c9`](https://github.com/mastra-ai/mastra/commit/79d69c9d5f842ff1c31352fb6026f04c1f6190f3), [`94f44b8`](https://github.com/mastra-ai/mastra/commit/94f44b827ce57b179e50f4916a84c0fa6e7f3b8c), [`13187db`](https://github.com/mastra-ai/mastra/commit/13187dbac880174232dedc5a501ff6c5d0fe59bc), [`2ae5311`](https://github.com/mastra-ai/mastra/commit/2ae531185fff66a80fa165c0999e3d801900e89d), [`6135ef4`](https://github.com/mastra-ai/mastra/commit/6135ef4f5288652bf45f616ec590607e4c95f443)]:
|
|
10
|
+
- @mastra/core@1.10.0
|
|
11
|
+
|
|
12
|
+
## 1.7.3-alpha.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Fix agent losing conversation context ("amnesia") when using client-side tools with stateless server deployments. Recursive calls after tool execution now include the full conversation history when no `threadId` is provided. ([#11476](https://github.com/mastra-ai/mastra/pull/11476))
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`41e48c1`](https://github.com/mastra-ai/mastra/commit/41e48c198eee846478e60c02ec432c19d322a517), [`82469d3`](https://github.com/mastra-ai/mastra/commit/82469d3135d5a49dd8dc8feec0ff398b4e0225a0), [`33e2fd5`](https://github.com/mastra-ai/mastra/commit/33e2fd5088f83666df17401e2da68c943dbc0448), [`7ef6e2c`](https://github.com/mastra-ai/mastra/commit/7ef6e2c61be5a42e26f55d15b5902866fc76634f), [`b12d2a5`](https://github.com/mastra-ai/mastra/commit/b12d2a59a48be0477cabae66eb6cf0fc94a7d40d), [`fa37d39`](https://github.com/mastra-ai/mastra/commit/fa37d39910421feaf8847716292e3d65dd4f30c2), [`b12d2a5`](https://github.com/mastra-ai/mastra/commit/b12d2a59a48be0477cabae66eb6cf0fc94a7d40d), [`71c38bf`](https://github.com/mastra-ai/mastra/commit/71c38bf905905148ecd0e75c07c1f9825d299b76), [`f993c38`](https://github.com/mastra-ai/mastra/commit/f993c3848c97479b813231be872443bedeced6ab), [`f51849a`](https://github.com/mastra-ai/mastra/commit/f51849a568935122b5100b7ee69704e6d680cf7b), [`9bf3a0d`](https://github.com/mastra-ai/mastra/commit/9bf3a0dac602787925f1762f1f0387d7b4a59620), [`cafa045`](https://github.com/mastra-ai/mastra/commit/cafa0453c9de141ad50c09a13894622dffdd9978), [`1fd9ddb`](https://github.com/mastra-ai/mastra/commit/1fd9ddbb3fe83b281b12bd2e27e426ae86288266), [`6135ef4`](https://github.com/mastra-ai/mastra/commit/6135ef4f5288652bf45f616ec590607e4c95f443), [`d9d228c`](https://github.com/mastra-ai/mastra/commit/d9d228c0c6ae82ae6ce3b540a3a56b2b1c2b8d98), [`5576507`](https://github.com/mastra-ai/mastra/commit/55765071e360fb97e443aa0a91ccf7e1cd8d92aa), [`79d69c9`](https://github.com/mastra-ai/mastra/commit/79d69c9d5f842ff1c31352fb6026f04c1f6190f3), [`94f44b8`](https://github.com/mastra-ai/mastra/commit/94f44b827ce57b179e50f4916a84c0fa6e7f3b8c), [`13187db`](https://github.com/mastra-ai/mastra/commit/13187dbac880174232dedc5a501ff6c5d0fe59bc), [`2ae5311`](https://github.com/mastra-ai/mastra/commit/2ae531185fff66a80fa165c0999e3d801900e89d), [`6135ef4`](https://github.com/mastra-ai/mastra/commit/6135ef4f5288652bf45f616ec590607e4c95f443)]:
|
|
19
|
+
- @mastra/core@1.10.0-alpha.0
|
|
20
|
+
|
|
3
21
|
## 1.7.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -45,23 +45,23 @@ The first parameter is the Mastra stream to convert. It can be one of:
|
|
|
45
45
|
|
|
46
46
|
The second parameter is an options object:
|
|
47
47
|
|
|
48
|
-
**from
|
|
48
|
+
**from** (`'agent' | 'network' | 'workflow'`): The type of Mastra stream being converted. (Default: `'agent'`)
|
|
49
49
|
|
|
50
|
-
**lastMessageId
|
|
50
|
+
**lastMessageId** (`string`): (Agent only) The ID of the last message in the conversation.
|
|
51
51
|
|
|
52
|
-
**sendStart
|
|
52
|
+
**sendStart** (`boolean`): (Agent only) Whether to send start events in the stream. (Default: `true`)
|
|
53
53
|
|
|
54
|
-
**sendFinish
|
|
54
|
+
**sendFinish** (`boolean`): (Agent only) Whether to send finish events in the stream. (Default: `true`)
|
|
55
55
|
|
|
56
|
-
**sendReasoning
|
|
56
|
+
**sendReasoning** (`boolean`): (Agent only) Whether to include reasoning-delta chunks in the stream. Set to true to stream reasoning content from models that support extended thinking. (Default: `false`)
|
|
57
57
|
|
|
58
|
-
**sendSources
|
|
58
|
+
**sendSources** (`boolean`): (Agent only) Whether to include source citations in the output. (Default: `false`)
|
|
59
59
|
|
|
60
|
-
**includeTextStreamParts
|
|
60
|
+
**includeTextStreamParts** (`boolean`): (Workflow only) Whether to include text stream parts in the output. (Default: `true`)
|
|
61
61
|
|
|
62
|
-
**messageMetadata
|
|
62
|
+
**messageMetadata** (`(options: { part: UIMessageStreamPart }) => Record<string, unknown> | undefined`): (Agent only) A function that receives the current stream part and returns metadata to attach to start and finish chunks.
|
|
63
63
|
|
|
64
|
-
**onError
|
|
64
|
+
**onError** (`(error: unknown) => string`): (Agent only) A function to handle errors during stream conversion. Receives the error and should return a string representation.
|
|
65
65
|
|
|
66
66
|
## Examples
|
|
67
67
|
|
|
@@ -33,27 +33,27 @@ export default function Chat() {
|
|
|
33
33
|
|
|
34
34
|
## Parameters
|
|
35
35
|
|
|
36
|
-
**messages
|
|
36
|
+
**messages** (`MessageListInput`): Messages to convert. Can be a string, array of strings, a single message object, or an array of message objects in any supported format.
|
|
37
37
|
|
|
38
38
|
## Returns
|
|
39
39
|
|
|
40
40
|
Returns an array of AI SDK V4 `UIMessage` objects with the following structure:
|
|
41
41
|
|
|
42
|
-
**id
|
|
42
|
+
**id** (`string`): Unique message identifier.
|
|
43
43
|
|
|
44
|
-
**role
|
|
44
|
+
**role** (`'user' | 'assistant' | 'system'`): The role of the message sender.
|
|
45
45
|
|
|
46
|
-
**content
|
|
46
|
+
**content** (`string`): Text content of the message.
|
|
47
47
|
|
|
48
|
-
**parts
|
|
48
|
+
**parts** (`UIMessagePart[]`): Array of UI parts including text, tool-invocation, file, reasoning, source, and step markers.
|
|
49
49
|
|
|
50
|
-
**createdAt
|
|
50
|
+
**createdAt** (`Date`): Message creation timestamp.
|
|
51
51
|
|
|
52
|
-
**toolInvocations
|
|
52
|
+
**toolInvocations** (`ToolInvocation[]`): Array of tool invocations for assistant messages.
|
|
53
53
|
|
|
54
|
-
**experimental\_attachments
|
|
54
|
+
**experimental\_attachments** (`Attachment[]`): File attachments on the message.
|
|
55
55
|
|
|
56
|
-
**metadata
|
|
56
|
+
**metadata** (`Record<string, unknown>`): Custom metadata attached to the message.
|
|
57
57
|
|
|
58
58
|
## Examples
|
|
59
59
|
|
|
@@ -38,19 +38,19 @@ export default function Chat() {
|
|
|
38
38
|
|
|
39
39
|
## Parameters
|
|
40
40
|
|
|
41
|
-
**messages
|
|
41
|
+
**messages** (`MessageListInput`): Messages to convert. Can be a string, array of strings, a single message object, or an array of message objects in any supported format.
|
|
42
42
|
|
|
43
43
|
## Returns
|
|
44
44
|
|
|
45
45
|
Returns an array of AI SDK V5+ `UIMessage` objects with the following structure:
|
|
46
46
|
|
|
47
|
-
**id
|
|
47
|
+
**id** (`string`): Unique message identifier.
|
|
48
48
|
|
|
49
|
-
**role
|
|
49
|
+
**role** (`'user' | 'assistant' | 'system'`): The role of the message sender.
|
|
50
50
|
|
|
51
|
-
**parts
|
|
51
|
+
**parts** (`UIMessagePart[]`): Array of UI parts including text, tool results, files, reasoning, sources, and step markers.
|
|
52
52
|
|
|
53
|
-
**metadata
|
|
53
|
+
**metadata** (`Record<string, unknown>`): Optional metadata including createdAt, threadId, resourceId, and custom fields.
|
|
54
54
|
|
|
55
55
|
## Examples
|
|
56
56
|
|
|
@@ -14,50 +14,50 @@ export const mastraClient = new MastraClient({
|
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
16
16
|
|
|
17
|
-
**baseUrl
|
|
17
|
+
**baseUrl** (`string`): The base URL for the Mastra API. All requests will be sent relative to this URL.
|
|
18
18
|
|
|
19
|
-
**retries
|
|
19
|
+
**retries** (`number`): The number of times a request will be retried on failure before throwing an error. (Default: `3`)
|
|
20
20
|
|
|
21
|
-
**backoffMs
|
|
21
|
+
**backoffMs** (`number`): The initial delay in milliseconds before retrying a failed request. This value is doubled with each retry (exponential backoff). (Default: `300`)
|
|
22
22
|
|
|
23
|
-
**maxBackoffMs
|
|
23
|
+
**maxBackoffMs** (`number`): The maximum backoff time in milliseconds. Prevents retries from waiting too long between attempts. (Default: `5000`)
|
|
24
24
|
|
|
25
|
-
**headers
|
|
25
|
+
**headers** (`Record<string, string>`): An object containing custom HTTP headers to include with every request.
|
|
26
26
|
|
|
27
|
-
**credentials
|
|
27
|
+
**credentials** (`"omit" | "same-origin" | "include"`): Credentials mode for requests. See https\://developer.mozilla.org/en-US/docs/Web/API/Request/credentials for more info.
|
|
28
28
|
|
|
29
29
|
## Methods
|
|
30
30
|
|
|
31
|
-
**listAgents()
|
|
31
|
+
**listAgents()** (`Promise<Record<string, GetAgentResponse>>`): Returns all available agent instances.
|
|
32
32
|
|
|
33
|
-
**getAgent(agentId)
|
|
33
|
+
**getAgent(agentId)** (`Agent`): Retrieves a specific agent instance by ID.
|
|
34
34
|
|
|
35
|
-
**getMemoryThreads(params)
|
|
35
|
+
**getMemoryThreads(params)** (`Promise<StorageThreadType[]>`): Retrieves memory threads for the specified resource and agent. Requires a \`resourceId\` and an \`agentId\`.
|
|
36
36
|
|
|
37
|
-
**createMemoryThread(params)
|
|
37
|
+
**createMemoryThread(params)** (`Promise<MemoryThread>`): Creates a new memory thread with the given parameters.
|
|
38
38
|
|
|
39
|
-
**getMemoryThread({ threadId, agentId })
|
|
39
|
+
**getMemoryThread({ threadId, agentId })** (`MemoryThread`): Fetches a specific memory thread by ID.
|
|
40
40
|
|
|
41
|
-
**saveMessageToMemory(params)
|
|
41
|
+
**saveMessageToMemory(params)** (`Promise<{ messages: (MastraMessageV1 | MastraDBMessage)[] }>`): Saves one or more messages to the memory system. Returns the saved messages.
|
|
42
42
|
|
|
43
|
-
**getMemoryStatus()
|
|
43
|
+
**getMemoryStatus()** (`Promise<MemoryStatus>`): Returns the current status of the memory system.
|
|
44
44
|
|
|
45
|
-
**listTools()
|
|
45
|
+
**listTools()** (`Record<string, Tool>`): Returns all available tools.
|
|
46
46
|
|
|
47
|
-
**getTool(toolId)
|
|
47
|
+
**getTool(toolId)** (`Tool`): Retrieves a specific tool instance by ID.
|
|
48
48
|
|
|
49
|
-
**listWorkflows()
|
|
49
|
+
**listWorkflows()** (`Record<string, Workflow>`): Returns all available workflow instances.
|
|
50
50
|
|
|
51
|
-
**getWorkflow(workflowId)
|
|
51
|
+
**getWorkflow(workflowId)** (`Workflow`): Retrieves a specific workflow instance by ID.
|
|
52
52
|
|
|
53
|
-
**getVector(vectorName)
|
|
53
|
+
**getVector(vectorName)** (`MastraVector`): Returns a vector store instance by name.
|
|
54
54
|
|
|
55
|
-
**listLogs(params)
|
|
55
|
+
**listLogs(params)** (`Promise<LogEntry[]>`): Fetches system logs matching the provided filters.
|
|
56
56
|
|
|
57
|
-
**getLog(params)
|
|
57
|
+
**getLog(params)** (`Promise<LogEntry>`): Retrieves a specific log entry by ID or filter.
|
|
58
58
|
|
|
59
|
-
**listLogTransports()
|
|
59
|
+
**listLogTransports()** (`string[]`): Returns the list of configured log transport types.
|
|
60
60
|
|
|
61
|
-
**getTrace(traceId)
|
|
61
|
+
**getTrace(traceId)** (`Promise<TraceRecord>`): Retrieves a specific trace by ID, including all its spans and details.
|
|
62
62
|
|
|
63
|
-
**getTraces(params)
|
|
63
|
+
**getTraces(params)** (`Promise<GetTracesResponse>`): Retrieves paginated list of trace root spans with optional filtering. Use getTrace() to get complete traces with all spans.
|
|
@@ -192,8 +192,8 @@ const result = await workflow.runById(runId, {
|
|
|
192
192
|
|
|
193
193
|
A workflow run result yields the following:
|
|
194
194
|
|
|
195
|
-
**runId
|
|
195
|
+
**runId** (`string`): Unique identifier for this workflow run instance
|
|
196
196
|
|
|
197
|
-
**eventTimestamp
|
|
197
|
+
**eventTimestamp** (`Date`): The timestamp of the event
|
|
198
198
|
|
|
199
|
-
**payload
|
|
199
|
+
**payload** (`object`): Contains currentStep (id, status, output, payload) and workflowState (status, steps record)
|
package/dist/index.cjs
CHANGED
|
@@ -1367,7 +1367,7 @@ async function executeToolCallAndRespond({
|
|
|
1367
1367
|
resourceId
|
|
1368
1368
|
}
|
|
1369
1369
|
});
|
|
1370
|
-
const
|
|
1370
|
+
const newMessages = [
|
|
1371
1371
|
...response.response.messages || [],
|
|
1372
1372
|
{
|
|
1373
1373
|
role: "tool",
|
|
@@ -1381,6 +1381,7 @@ async function executeToolCallAndRespond({
|
|
|
1381
1381
|
]
|
|
1382
1382
|
}
|
|
1383
1383
|
];
|
|
1384
|
+
const updatedMessages = threadId ? newMessages : [...Array.isArray(params.messages) ? params.messages : [], ...newMessages];
|
|
1384
1385
|
return respondFn(updatedMessages, params);
|
|
1385
1386
|
}
|
|
1386
1387
|
}
|
|
@@ -2132,6 +2133,10 @@ var Agent = class extends BaseResource {
|
|
|
2132
2133
|
onFinish?.({ message, finishReason, usage });
|
|
2133
2134
|
}
|
|
2134
2135
|
async processStreamResponse(processedParams, controller, route = "stream") {
|
|
2136
|
+
const { memory } = processedParams ?? {};
|
|
2137
|
+
const { resource, thread } = memory ?? {};
|
|
2138
|
+
const threadId = processedParams.threadId ?? (typeof thread === "string" ? thread : thread?.id);
|
|
2139
|
+
const resourceId = processedParams.resourceId ?? resource;
|
|
2135
2140
|
const response = await this.request(`/agents/${this.agentId}/${route}`, {
|
|
2136
2141
|
method: "POST",
|
|
2137
2142
|
body: processedParams,
|
|
@@ -2198,8 +2203,8 @@ var Agent = class extends BaseResource {
|
|
|
2198
2203
|
toolCallId: toolCall2?.toolCallId,
|
|
2199
2204
|
suspend: async () => {
|
|
2200
2205
|
},
|
|
2201
|
-
threadId
|
|
2202
|
-
resourceId
|
|
2206
|
+
threadId,
|
|
2207
|
+
resourceId
|
|
2203
2208
|
}
|
|
2204
2209
|
});
|
|
2205
2210
|
const lastMessageRaw = messages[messages.length - 1];
|
|
@@ -2221,7 +2226,8 @@ var Agent = class extends BaseResource {
|
|
|
2221
2226
|
toolInvocation.state = "result";
|
|
2222
2227
|
toolInvocation.result = result;
|
|
2223
2228
|
}
|
|
2224
|
-
const
|
|
2229
|
+
const newMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
2230
|
+
const updatedMessages = threadId ? newMessages : [...Array.isArray(processedParams.messages) ? processedParams.messages : [], ...newMessages];
|
|
2225
2231
|
try {
|
|
2226
2232
|
await this.processStreamResponse(
|
|
2227
2233
|
{
|
|
@@ -2445,6 +2451,10 @@ var Agent = class extends BaseResource {
|
|
|
2445
2451
|
* Processes the stream response and handles tool calls
|
|
2446
2452
|
*/
|
|
2447
2453
|
async processStreamResponseLegacy(processedParams, writable) {
|
|
2454
|
+
const { memory } = processedParams ?? {};
|
|
2455
|
+
const { resource, thread } = memory ?? {};
|
|
2456
|
+
const threadId = processedParams.threadId ?? (typeof thread === "string" ? thread : thread?.id);
|
|
2457
|
+
const resourceId = processedParams.resourceId ?? resource;
|
|
2448
2458
|
const response = await this.request(`/agents/${this.agentId}/stream-legacy`, {
|
|
2449
2459
|
method: "POST",
|
|
2450
2460
|
body: processedParams,
|
|
@@ -2490,8 +2500,8 @@ var Agent = class extends BaseResource {
|
|
|
2490
2500
|
toolCallId: toolCall2?.toolCallId,
|
|
2491
2501
|
suspend: async () => {
|
|
2492
2502
|
},
|
|
2493
|
-
threadId
|
|
2494
|
-
resourceId
|
|
2503
|
+
threadId,
|
|
2504
|
+
resourceId
|
|
2495
2505
|
}
|
|
2496
2506
|
});
|
|
2497
2507
|
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
@@ -2525,10 +2535,12 @@ var Agent = class extends BaseResource {
|
|
|
2525
2535
|
} finally {
|
|
2526
2536
|
writer.releaseLock();
|
|
2527
2537
|
}
|
|
2538
|
+
const newMessages = [...messages.filter((m) => m.id !== lastMessage.id), lastMessage];
|
|
2539
|
+
const updatedMessages = threadId ? newMessages : [...Array.isArray(processedParams.messages) ? processedParams.messages : [], ...newMessages];
|
|
2528
2540
|
this.processStreamResponseLegacy(
|
|
2529
2541
|
{
|
|
2530
2542
|
...processedParams,
|
|
2531
|
-
messages:
|
|
2543
|
+
messages: updatedMessages
|
|
2532
2544
|
},
|
|
2533
2545
|
writable
|
|
2534
2546
|
).catch((error) => {
|