@mastra/client-js 1.2.0 → 1.2.1-alpha.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +10 -7
  3. package/dist/client.d.ts +11 -1
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/docs/SKILL.md +32 -22
  6. package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +1 -1
  7. package/dist/docs/{server/07-auth0.md → references/docs-server-auth-auth0.md} +68 -79
  8. package/dist/docs/{server/03-clerk.md → references/docs-server-auth-clerk.md} +41 -52
  9. package/dist/docs/{server/05-firebase.md → references/docs-server-auth-firebase.md} +83 -97
  10. package/dist/docs/{server/02-jwt.md → references/docs-server-auth-jwt.md} +46 -35
  11. package/dist/docs/{server/04-supabase.md → references/docs-server-auth-supabase.md} +33 -44
  12. package/dist/docs/{server/06-workos.md → references/docs-server-auth-workos.md} +45 -56
  13. package/dist/docs/{server/01-mastra-client.md → references/docs-server-mastra-client.md} +32 -20
  14. package/dist/docs/{ai-sdk/01-reference.md → references/reference-ai-sdk-to-ai-sdk-stream.md} +27 -153
  15. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-v4-messages.md +79 -0
  16. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-v5-messages.md +73 -0
  17. package/dist/docs/references/reference-client-js-agents.md +438 -0
  18. package/dist/docs/references/reference-client-js-error-handling.md +16 -0
  19. package/dist/docs/references/reference-client-js-logs.md +24 -0
  20. package/dist/docs/references/reference-client-js-mastra-client.md +63 -0
  21. package/dist/docs/references/reference-client-js-memory.md +225 -0
  22. package/dist/docs/references/reference-client-js-observability.md +72 -0
  23. package/dist/docs/references/reference-client-js-telemetry.md +20 -0
  24. package/dist/docs/references/reference-client-js-tools.md +44 -0
  25. package/dist/docs/references/reference-client-js-vectors.md +79 -0
  26. package/dist/docs/references/reference-client-js-workflows.md +199 -0
  27. package/dist/index.cjs +18 -1
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.js +18 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/types.d.ts +158 -27
  32. package/dist/types.d.ts.map +1 -1
  33. package/package.json +7 -7
  34. package/dist/docs/README.md +0 -33
  35. package/dist/docs/client-js/01-reference.md +0 -1180
@@ -0,0 +1,225 @@
1
+ # Memory API
2
+
3
+ The Memory API provides methods to manage conversation threads and message history in Mastra.
4
+
5
+ ### Get All Threads
6
+
7
+ Retrieve all memory threads for a specific resource:
8
+
9
+ ```typescript
10
+ const threads = await mastraClient.getMemoryThreads({
11
+ resourceId: "resource-1",
12
+ agentId: "agent-1", // Optional - can be omitted if storage is configured
13
+ });
14
+ ```
15
+
16
+ When `agentId` is omitted and storage is configured on the server, threads will be retrieved using storage directly. This is useful when multiple agents share the same threads (e.g., in workflows with multiple agent steps).
17
+
18
+ ### Create a New Thread
19
+
20
+ Create a new memory thread:
21
+
22
+ ```typescript
23
+ const thread = await mastraClient.createMemoryThread({
24
+ title: "New Conversation",
25
+ metadata: { category: "support" },
26
+ resourceId: "resource-1",
27
+ agentId: "agent-1",
28
+ });
29
+ ```
30
+
31
+ ### Working with a Specific Thread
32
+
33
+ Get an instance of a specific memory thread:
34
+
35
+ ```typescript
36
+ const thread = mastraClient.getMemoryThread({ threadId: "thread-id", agentId: "agent-id" });
37
+ ```
38
+
39
+ ## Thread Methods
40
+
41
+ ### Get Thread Details
42
+
43
+ Retrieve details about a specific thread:
44
+
45
+ ```typescript
46
+ const details = await thread.get();
47
+ ```
48
+
49
+ ### Update Thread
50
+
51
+ Update thread properties:
52
+
53
+ ```typescript
54
+ const updated = await thread.update({
55
+ title: "Updated Title",
56
+ metadata: { status: "resolved" },
57
+ resourceId: "resource-1",
58
+ });
59
+ ```
60
+
61
+ ### Delete Thread
62
+
63
+ Delete a thread and its messages:
64
+
65
+ ```typescript
66
+ await thread.delete();
67
+ ```
68
+
69
+ ### Clone Thread
70
+
71
+ Create a copy of a thread with all its messages:
72
+
73
+ ```typescript
74
+ const { thread: clonedThread, clonedMessages } = await thread.clone();
75
+ ```
76
+
77
+ Clone with options:
78
+
79
+ ```typescript
80
+ const { thread: clonedThread, clonedMessages } = await thread.clone({
81
+ newThreadId: "custom-clone-id",
82
+ title: "Cloned Conversation",
83
+ metadata: { branch: "experiment-1" },
84
+ options: {
85
+ messageLimit: 10, // Only clone last 10 messages
86
+ },
87
+ });
88
+ ```
89
+
90
+ Clone with message filtering:
91
+
92
+ ```typescript
93
+ const { thread: clonedThread } = await thread.clone({
94
+ options: {
95
+ messageFilter: {
96
+ startDate: new Date("2024-01-01"),
97
+ endDate: new Date("2024-01-31"),
98
+ },
99
+ },
100
+ });
101
+ ```
102
+
103
+ The clone response includes:
104
+
105
+ - `thread`: The newly created cloned thread with clone metadata
106
+ - `clonedMessages`: Array of the cloned messages with new IDs
107
+
108
+ ## Message Operations
109
+
110
+ ### Save Messages
111
+
112
+ Save messages to memory:
113
+
114
+ ```typescript
115
+ const result = await mastraClient.saveMessageToMemory({
116
+ messages: [
117
+ {
118
+ role: "user",
119
+ content: "Hello!",
120
+ id: "1",
121
+ threadId: "thread-1",
122
+ resourceId: "resource-1",
123
+ createdAt: new Date(),
124
+ format: 2,
125
+ },
126
+ ],
127
+ agentId: "agent-1",
128
+ });
129
+
130
+ // result.messages contains the saved messages
131
+ console.log(result.messages);
132
+ ```
133
+
134
+ ### Retrieve Thread Messages
135
+
136
+ Get messages associated with a memory thread:
137
+
138
+ ```typescript
139
+ // Get all messages in the thread (paginated)
140
+ const result = await thread.listMessages();
141
+ console.log(result.messages); // Array of messages
142
+ console.log(result.total); // Total count
143
+ console.log(result.hasMore); // Whether more pages exist
144
+
145
+ // Get messages with pagination
146
+ const result = await thread.listMessages({
147
+ page: 0,
148
+ perPage: 20
149
+ });
150
+
151
+ // Get messages with ordering
152
+ const result = await thread.listMessages({
153
+ orderBy: { field: 'createdAt', direction: 'ASC' }
154
+ });
155
+ ```
156
+
157
+ ### Delete Messages
158
+
159
+ Delete one or more messages from a thread:
160
+
161
+ ```typescript
162
+ // Delete a single message
163
+ const result = await thread.deleteMessages("message-id");
164
+
165
+ // Delete multiple messages
166
+ const result = await thread.deleteMessages([
167
+ "message-1",
168
+ "message-2",
169
+ "message-3",
170
+ ]);
171
+
172
+ // Returns: { success: true, message: "Message deleted successfully" }
173
+ ```
174
+
175
+ ## Working Memory
176
+
177
+ Working memory allows agents to maintain persistent information about users across interactions. It can be scoped to either a specific thread or across all threads for a resource (user).
178
+
179
+ ### Get Working Memory
180
+
181
+ Retrieve the current working memory for a thread:
182
+
183
+ ```typescript
184
+ const workingMemory = await mastraClient.getWorkingMemory({
185
+ agentId: "agent-1",
186
+ threadId: "thread-1",
187
+ resourceId: "user-123", // Optional, required for resource-scoped memory
188
+ });
189
+ ```
190
+
191
+ The response includes:
192
+
193
+ - `workingMemory`: The current working memory content (string or null)
194
+ - `source`: Whether the memory is from `"thread"` or `"resource"` scope
195
+ - `workingMemoryTemplate`: The template used for working memory (if configured)
196
+ - `threadExists`: Whether the thread exists
197
+
198
+ ### Update Working Memory
199
+
200
+ Update the working memory content for a thread:
201
+
202
+ ```typescript
203
+ await mastraClient.updateWorkingMemory({
204
+ agentId: "agent-1",
205
+ threadId: "thread-1",
206
+ workingMemory: `# User Profile
207
+ - Name: John Doe
208
+ - Location: New York
209
+ - Preferences: Prefers formal communication
210
+ `,
211
+ resourceId: "user-123", // Optional, required for resource-scoped memory
212
+ });
213
+
214
+ // Returns: { success: true }
215
+ ```
216
+
217
+ **Note:** For resource-scoped working memory, you must provide the `resourceId` parameter. This allows the memory to persist across all conversation threads for that user.
218
+
219
+ ### Get Memory Status
220
+
221
+ Check the status of the memory system:
222
+
223
+ ```typescript
224
+ const status = await mastraClient.getMemoryStatus("agent-id");
225
+ ```
@@ -0,0 +1,72 @@
1
+ # Observability API
2
+
3
+ The Observability API provides methods to retrieve traces, monitor your application's performance, and score traces for evaluation. This helps you understand how your AI agents and workflows are performing.
4
+
5
+ ## Getting a Specific Trace
6
+
7
+ Retrieve a specific trace by its ID, including all its spans and details:
8
+
9
+ ```typescript
10
+ const trace = await mastraClient.getTrace("trace-id-123");
11
+ ```
12
+
13
+ ## Getting Traces with Filtering
14
+
15
+ Retrieve a paginated list of trace root spans with optional filtering:
16
+
17
+ ```typescript
18
+ const traces = await mastraClient.getTraces({
19
+ pagination: {
20
+ page: 1,
21
+ perPage: 20,
22
+ dateRange: {
23
+ start: new Date("2024-01-01"),
24
+ end: new Date("2024-01-31"),
25
+ },
26
+ },
27
+ filters: {
28
+ name: "weather-agent", // Filter by trace name
29
+ spanType: "agent", // Filter by span type
30
+ entityId: "weather-agent-id", // Filter by entity ID
31
+ entityType: "agent", // Filter by entity type
32
+ },
33
+ });
34
+
35
+ console.log(`Found ${traces.spans.length} root spans`);
36
+ console.log(`Total pages: ${traces.pagination.totalPages}`);
37
+
38
+ // To get the complete trace with all spans, use getTrace
39
+ const completeTrace = await mastraClient.getTrace(traces.spans[0].traceId);
40
+ ```
41
+
42
+ ## Scoring Traces
43
+
44
+ Score specific traces using registered scorers for evaluation:
45
+
46
+ ```typescript
47
+ const result = await mastraClient.score({
48
+ scorerName: "answer-relevancy",
49
+ targets: [
50
+ { traceId: "trace-1", spanId: "span-1" }, // Score specific span
51
+ { traceId: "trace-2" }, // Score specific span which defaults to the parent span
52
+ ],
53
+ });
54
+ ```
55
+
56
+ ## Getting Scores by Span
57
+
58
+ Retrieve scores for a specific span within a trace:
59
+
60
+ ```typescript
61
+ const scores = await mastraClient.listScoresBySpan({
62
+ traceId: "trace-123",
63
+ spanId: "span-456",
64
+ page: 1,
65
+ perPage: 20,
66
+ });
67
+ ```
68
+
69
+ ## Related
70
+
71
+ - [Agents API](https://mastra.ai/reference/client-js/agents) - Learn about agent interactions that generate traces
72
+ - [Workflows API](https://mastra.ai/reference/client-js/workflows) - Understand workflow execution monitoring
@@ -0,0 +1,20 @@
1
+ # Telemetry API
2
+
3
+ The Telemetry API provides methods to retrieve and analyze traces from your Mastra application. This helps you monitor and debug your application's behavior and performance.
4
+
5
+ ## Getting Traces
6
+
7
+ Retrieve traces with optional filtering and pagination:
8
+
9
+ ```typescript
10
+ const telemetry = await mastraClient.getTelemetry({
11
+ name: "trace-name", // Optional: Filter by trace name
12
+ scope: "scope-name", // Optional: Filter by scope
13
+ page: 1, // Optional: Page number for pagination
14
+ perPage: 10, // Optional: Number of items per page
15
+ attribute: {
16
+ // Optional: Filter by custom attributes
17
+ key: "value",
18
+ },
19
+ });
20
+ ```
@@ -0,0 +1,44 @@
1
+ # Tools API
2
+
3
+ The Tools API provides methods to interact with and execute tools available in the Mastra platform.
4
+
5
+ ## Getting All Tools
6
+
7
+ Retrieve a list of all available tools:
8
+
9
+ ```typescript
10
+ const tools = await mastraClient.listTools();
11
+ ```
12
+
13
+ ## Working with a Specific Tool
14
+
15
+ Get an instance of a specific tool:
16
+
17
+ ```typescript
18
+ const tool = mastraClient.getTool("tool-id");
19
+ ```
20
+
21
+ ## Tool Methods
22
+
23
+ ### Get Tool Details
24
+
25
+ Retrieve detailed information about a tool:
26
+
27
+ ```typescript
28
+ const details = await tool.details();
29
+ ```
30
+
31
+ ### Execute Tool
32
+
33
+ Execute a tool with specific arguments:
34
+
35
+ ```typescript
36
+ const result = await tool.execute({
37
+ args: {
38
+ param1: "value1",
39
+ param2: "value2",
40
+ },
41
+ threadId: "thread-1", // Optional: Thread context
42
+ resourceId: "resource-1", // Optional: Resource identifier
43
+ });
44
+ ```
@@ -0,0 +1,79 @@
1
+ # Vectors API
2
+
3
+ The Vectors API provides methods to work with vector embeddings for semantic search and similarity matching in Mastra.
4
+
5
+ ## Working with Vectors
6
+
7
+ Get an instance of a vector store:
8
+
9
+ ```typescript
10
+ const vector = mastraClient.getVector("vector-name");
11
+ ```
12
+
13
+ ## Vector Methods
14
+
15
+ ### Get Vector Index Details
16
+
17
+ Retrieve information about a specific vector index:
18
+
19
+ ```typescript
20
+ const details = await vector.details("index-name");
21
+ ```
22
+
23
+ ### Create Vector Index
24
+
25
+ Create a new vector index:
26
+
27
+ ```typescript
28
+ const result = await vector.createIndex({
29
+ indexName: "new-index",
30
+ dimension: 128,
31
+ metric: "cosine", // 'cosine', 'euclidean', or 'dotproduct'
32
+ });
33
+ ```
34
+
35
+ ### Upsert Vectors
36
+
37
+ Add or update vectors in an index:
38
+
39
+ ```typescript
40
+ const ids = await vector.upsert({
41
+ indexName: "my-index",
42
+ vectors: [
43
+ [0.1, 0.2, 0.3], // First vector
44
+ [0.4, 0.5, 0.6], // Second vector
45
+ ],
46
+ metadata: [{ label: "first" }, { label: "second" }],
47
+ ids: ["id1", "id2"], // Optional: Custom IDs
48
+ });
49
+ ```
50
+
51
+ ### Query Vectors
52
+
53
+ Search for similar vectors:
54
+
55
+ ```typescript
56
+ const results = await vector.query({
57
+ indexName: "my-index",
58
+ queryVector: [0.1, 0.2, 0.3],
59
+ topK: 10,
60
+ filter: { label: "first" }, // Optional: Metadata filter
61
+ includeVector: true, // Optional: Include vectors in results
62
+ });
63
+ ```
64
+
65
+ ### Get All Indexes
66
+
67
+ List all available indexes:
68
+
69
+ ```typescript
70
+ const indexes = await vector.getIndexes();
71
+ ```
72
+
73
+ ### Delete Index
74
+
75
+ Delete a vector index:
76
+
77
+ ```typescript
78
+ const result = await vector.delete("index-name");
79
+ ```
@@ -0,0 +1,199 @@
1
+ # Workflows API
2
+
3
+ The Workflows API provides methods to interact with and execute automated workflows in Mastra.
4
+
5
+ ## Getting All Workflows
6
+
7
+ Retrieve a list of all available workflows:
8
+
9
+ ```typescript
10
+ const workflows = await mastraClient.listWorkflows();
11
+ ```
12
+
13
+ ## Working with a Specific Workflow
14
+
15
+ Get an instance of a specific workflow by its ID:
16
+
17
+ ```typescript
18
+ export const testWorkflow = createWorkflow({
19
+ id: "city-workflow",
20
+ });
21
+ ```
22
+
23
+ ```typescript
24
+ const workflow = mastraClient.getWorkflow("city-workflow");
25
+ ```
26
+
27
+ ## Workflow Methods
28
+
29
+ ### details()
30
+
31
+ Retrieve detailed information about a workflow:
32
+
33
+ ```typescript
34
+ const details = await workflow.details();
35
+ ```
36
+
37
+ ### createRun()
38
+
39
+ Create a new workflow run instance:
40
+
41
+ ```typescript
42
+ const run = await workflow.createRun();
43
+
44
+ // Or with an existing runId
45
+ const run = await workflow.createRun({ runId: "existing-run-id" });
46
+
47
+ // Or with a resourceId to associate the run with a specific resource
48
+ const run = await workflow.createRun({
49
+ runId: "my-run-id",
50
+ resourceId: "user-123"
51
+ });
52
+ ```
53
+
54
+ The `resourceId` parameter associates the workflow run with a specific resource (e.g., user ID, tenant ID). This value is persisted with the run and can be used for filtering and querying runs later.
55
+
56
+ ### startAsync()
57
+
58
+ Start a workflow run and await the full result:
59
+
60
+ ```typescript
61
+ const run = await workflow.createRun();
62
+
63
+ const result = await run.startAsync({
64
+ inputData: {
65
+ city: "New York",
66
+ },
67
+ });
68
+ ```
69
+
70
+ You can also pass `initialState` to set the starting values for the workflow's state:
71
+
72
+ ```typescript
73
+ const result = await run.startAsync({
74
+ inputData: {
75
+ city: "New York",
76
+ },
77
+ initialState: {
78
+ count: 0,
79
+ items: [],
80
+ },
81
+ });
82
+ ```
83
+
84
+ The `initialState` object should match the structure defined in the workflow's `stateSchema`. See [Workflow State](https://mastra.ai/docs/workflows/workflow-state) for more details.
85
+
86
+ To associate a run with a specific resource, pass `resourceId` to `createRun()`:
87
+
88
+ ```typescript
89
+ const run = await workflow.createRun({ resourceId: "user-123" });
90
+
91
+ const result = await run.startAsync({
92
+ inputData: {
93
+ city: "New York",
94
+ },
95
+ });
96
+ ```
97
+
98
+ ### start()
99
+
100
+ Start a workflow run without waiting for completion:
101
+
102
+ ```typescript
103
+ const run = await workflow.createRun();
104
+
105
+ await run.start({
106
+ inputData: {
107
+ city: "New York",
108
+ },
109
+ });
110
+
111
+ // Poll for results later
112
+ const result = await workflow.runById(run.runId);
113
+ ```
114
+
115
+ This is useful for long-running workflows where you want to start execution and check results later.
116
+
117
+ ### resumeAsync()
118
+
119
+ Resume a suspended workflow step and await the full result:
120
+
121
+ ```typescript
122
+ const run = await workflow.createRun({ runId: prevRunId });
123
+
124
+ const result = await run.resumeAsync({
125
+ step: "step-id",
126
+ resumeData: { key: "value" },
127
+ });
128
+ ```
129
+
130
+ ### resume()
131
+
132
+ Resume a suspended workflow step without waiting for completion:
133
+
134
+ ```typescript
135
+ const run = await workflow.createRun({ runId: prevRunId });
136
+
137
+ await run.resume({
138
+ step: "step-id",
139
+ resumeData: { key: "value" },
140
+ });
141
+ ```
142
+
143
+ ### cancel()
144
+
145
+ Cancel a running workflow:
146
+
147
+ ```typescript
148
+ const run = await workflow.createRun({ runId: existingRunId });
149
+
150
+ const result = await run.cancel();
151
+ // Returns: { message: 'Workflow run canceled' }
152
+ ```
153
+
154
+ This method stops any running steps and prevents subsequent steps from executing. Steps that check the `abortSignal` parameter can respond to cancellation by cleaning up resources (timeouts, network requests, etc.).
155
+
156
+ See the [Run.cancel()](https://mastra.ai/reference/workflows/run-methods/cancel) reference for detailed information about how cancellation works and how to write steps that respond to cancellation.
157
+
158
+ ### stream()
159
+
160
+ Stream workflow execution for real-time updates:
161
+
162
+ ```typescript
163
+ const run = await workflow.createRun();
164
+
165
+ const stream = await run.stream({
166
+ inputData: {
167
+ city: "New York",
168
+ },
169
+ });
170
+
171
+ for await (const chunk of stream) {
172
+ console.log(JSON.stringify(chunk, null, 2));
173
+ }
174
+ ```
175
+
176
+ ### runById()
177
+
178
+ Get the execution result for a workflow run:
179
+
180
+ ```typescript
181
+ const result = await workflow.runById(runId);
182
+
183
+ // Or with options for performance optimization:
184
+ const result = await workflow.runById(runId, {
185
+ fields: ['status', 'result'], // Only fetch specific fields
186
+ withNestedWorkflows: false, // Skip expensive nested workflow data
187
+ requestContext: { userId: 'user-123' }, // Optional request context
188
+ });
189
+ ```
190
+
191
+ ### Run result format
192
+
193
+ A workflow run result yields the following:
194
+
195
+ **runId:** (`string`): Unique identifier for this workflow run instance
196
+
197
+ **eventTimestamp:** (`Date`): The timestamp of the event
198
+
199
+ **payload:** (`object`): Contains currentStep (id, status, output, payload) and workflowState (status, steps record)
package/dist/index.cjs CHANGED
@@ -354,7 +354,7 @@ function safeParseJSON({
354
354
  }
355
355
  }
356
356
 
357
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
357
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
358
358
  new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
359
359
  function fixJson(input) {
360
360
  const stack = ["ROOT"];
@@ -4953,6 +4953,23 @@ var MastraClient = class extends BaseResource {
4953
4953
  getWorkspace(workspaceId) {
4954
4954
  return new Workspace(this.options, workspaceId);
4955
4955
  }
4956
+ // ============================================================================
4957
+ // Vectors & Embedders
4958
+ // ============================================================================
4959
+ /**
4960
+ * Lists all available vector stores
4961
+ * @returns Promise containing list of available vector stores
4962
+ */
4963
+ listVectors() {
4964
+ return this.request("/vectors");
4965
+ }
4966
+ /**
4967
+ * Lists all available embedding models
4968
+ * @returns Promise containing list of available embedders
4969
+ */
4970
+ listEmbedders() {
4971
+ return this.request("/embedders");
4972
+ }
4956
4973
  };
4957
4974
 
4958
4975
  // src/tools.ts