@mastra/client-js 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807182016

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 (127) hide show
  1. package/CHANGELOG.md +9405 -3
  2. package/LICENSE.md +15 -0
  3. package/README.md +11 -13
  4. package/dist/_types/@ai-sdk_provider/dist/index.d.ts +1587 -0
  5. package/dist/_types/@ai-sdk_provider-utils/dist/index.d.ts +379 -0
  6. package/dist/_types/@ai-sdk_ui-utils/dist/index.d.ts +820 -0
  7. package/dist/agent-learning.d.ts +182 -0
  8. package/dist/agent-learning.d.ts.map +1 -0
  9. package/dist/client.d.ts +767 -80
  10. package/dist/client.d.ts.map +1 -1
  11. package/dist/docs/SKILL.md +52 -0
  12. package/dist/docs/assets/SOURCE_MAP.json +6 -0
  13. package/dist/docs/references/docs-agents-a2a.md +340 -0
  14. package/dist/docs/references/docs-editor-overview.md +349 -0
  15. package/dist/docs/references/docs-long-running-agents-schedules.md +201 -0
  16. package/dist/docs/references/docs-long-running-agents-signals.md +426 -0
  17. package/dist/docs/references/docs-server-auth-auth0.md +262 -0
  18. package/dist/docs/references/docs-server-auth-clerk.md +154 -0
  19. package/dist/docs/references/docs-server-auth-firebase.md +294 -0
  20. package/dist/docs/references/docs-server-auth-jwt.md +116 -0
  21. package/dist/docs/references/docs-server-auth-supabase.md +139 -0
  22. package/dist/docs/references/docs-server-auth-workos.md +271 -0
  23. package/dist/docs/references/docs-server-mastra-client.md +323 -0
  24. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-messages.md +97 -0
  25. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-stream.md +282 -0
  26. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-v4-messages.md +81 -0
  27. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-v5-messages.md +78 -0
  28. package/dist/docs/references/reference-client-js-agents.md +959 -0
  29. package/dist/docs/references/reference-client-js-conversations.md +137 -0
  30. package/dist/docs/references/reference-client-js-error-handling.md +18 -0
  31. package/dist/docs/references/reference-client-js-logs.md +26 -0
  32. package/dist/docs/references/reference-client-js-mastra-client.md +96 -0
  33. package/dist/docs/references/reference-client-js-memory.md +237 -0
  34. package/dist/docs/references/reference-client-js-observability.md +183 -0
  35. package/dist/docs/references/reference-client-js-responses.md +219 -0
  36. package/dist/docs/references/reference-client-js-telemetry.md +22 -0
  37. package/dist/docs/references/reference-client-js-tools.md +46 -0
  38. package/dist/docs/references/reference-client-js-vectors.md +81 -0
  39. package/dist/docs/references/reference-client-js-workflows.md +393 -0
  40. package/dist/docs/references/reference-editor-versioning.md +130 -0
  41. package/dist/index.cjs +7638 -3257
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.ts +9 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +7606 -3252
  46. package/dist/index.js.map +1 -1
  47. package/dist/observability/collector.d.ts +45 -0
  48. package/dist/observability/collector.d.ts.map +1 -0
  49. package/dist/observability/index.d.ts +14 -0
  50. package/dist/observability/index.d.ts.map +1 -0
  51. package/dist/observability/types.d.ts +27 -0
  52. package/dist/observability/types.d.ts.map +1 -0
  53. package/dist/resources/a2a.d.ts +80 -11
  54. package/dist/resources/a2a.d.ts.map +1 -1
  55. package/dist/resources/agent-builder.d.ts +57 -72
  56. package/dist/resources/agent-builder.d.ts.map +1 -1
  57. package/dist/resources/agent-controller.d.ts +589 -0
  58. package/dist/resources/agent-controller.d.ts.map +1 -0
  59. package/dist/resources/agent.d.ts +368 -59
  60. package/dist/resources/agent.d.ts.map +1 -1
  61. package/dist/resources/base.d.ts +2 -1
  62. package/dist/resources/base.d.ts.map +1 -1
  63. package/dist/resources/channels.d.ts +63 -0
  64. package/dist/resources/channels.d.ts.map +1 -0
  65. package/dist/resources/conversations.d.ts +15 -0
  66. package/dist/resources/conversations.d.ts.map +1 -0
  67. package/dist/resources/index.d.ts +14 -0
  68. package/dist/resources/index.d.ts.map +1 -1
  69. package/dist/resources/mcp-tool.d.ts +5 -5
  70. package/dist/resources/mcp-tool.d.ts.map +1 -1
  71. package/dist/resources/memory-thread.d.ts +51 -16
  72. package/dist/resources/memory-thread.d.ts.map +1 -1
  73. package/dist/resources/observability.d.ts +222 -19
  74. package/dist/resources/observability.d.ts.map +1 -1
  75. package/dist/resources/processor-provider.d.ts +15 -0
  76. package/dist/resources/processor-provider.d.ts.map +1 -0
  77. package/dist/resources/processor.d.ts +20 -0
  78. package/dist/resources/processor.d.ts.map +1 -0
  79. package/dist/resources/responses.d.ts +22 -0
  80. package/dist/resources/responses.d.ts.map +1 -0
  81. package/dist/resources/run.d.ts +256 -0
  82. package/dist/resources/run.d.ts.map +1 -0
  83. package/dist/resources/stored-agent.d.ts +112 -0
  84. package/dist/resources/stored-agent.d.ts.map +1 -0
  85. package/dist/resources/stored-mcp-client.d.ts +30 -0
  86. package/dist/resources/stored-mcp-client.d.ts.map +1 -0
  87. package/dist/resources/stored-prompt-block.d.ts +83 -0
  88. package/dist/resources/stored-prompt-block.d.ts.map +1 -0
  89. package/dist/resources/stored-scorer.d.ts +83 -0
  90. package/dist/resources/stored-scorer.d.ts.map +1 -0
  91. package/dist/resources/stored-skill.d.ts +40 -0
  92. package/dist/resources/stored-skill.d.ts.map +1 -0
  93. package/dist/resources/stored-workflow.d.ts +18 -0
  94. package/dist/resources/stored-workflow.d.ts.map +1 -0
  95. package/dist/resources/tool-provider.d.ts +80 -0
  96. package/dist/resources/tool-provider.d.ts.map +1 -0
  97. package/dist/resources/tool.d.ts +4 -4
  98. package/dist/resources/vector.d.ts +9 -9
  99. package/dist/resources/vector.d.ts.map +1 -1
  100. package/dist/resources/workflow.d.ts +32 -231
  101. package/dist/resources/workflow.d.ts.map +1 -1
  102. package/dist/resources/workspace.d.ts +129 -0
  103. package/dist/resources/workspace.d.ts.map +1 -0
  104. package/dist/route-types.generated.d.ts +18087 -0
  105. package/dist/route-types.generated.d.ts.map +1 -0
  106. package/dist/tools.d.ts +3 -6
  107. package/dist/tools.d.ts.map +1 -1
  108. package/dist/types.d.ts +2740 -197
  109. package/dist/types.d.ts.map +1 -1
  110. package/dist/utils/client-tool-model-output.d.ts +16 -0
  111. package/dist/utils/client-tool-model-output.d.ts.map +1 -0
  112. package/dist/utils/index.d.ts +65 -4
  113. package/dist/utils/index.d.ts.map +1 -1
  114. package/dist/utils/process-a2a-stream.d.ts +4 -0
  115. package/dist/utils/process-a2a-stream.d.ts.map +1 -0
  116. package/dist/utils/process-client-tools.d.ts.map +1 -1
  117. package/dist/utils/process-mastra-stream.d.ts +8 -7
  118. package/dist/utils/process-mastra-stream.d.ts.map +1 -1
  119. package/dist/utils/stream-transforms.d.ts +9 -0
  120. package/dist/utils/stream-transforms.d.ts.map +1 -0
  121. package/dist/utils/verify-agent-card-signature.d.ts +21 -0
  122. package/dist/utils/verify-agent-card-signature.d.ts.map +1 -0
  123. package/dist/utils/zod-to-json-schema.d.ts +11 -2
  124. package/dist/utils/zod-to-json-schema.d.ts.map +1 -1
  125. package/package.json +26 -19
  126. package/dist/resources/network-memory-thread.d.ts +0 -47
  127. package/dist/resources/network-memory-thread.d.ts.map +0 -1
@@ -0,0 +1,154 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Clerk
4
+
5
+ The `@mastra/auth-clerk` package provides authentication for Mastra using Clerk. It verifies incoming requests using Clerk's authentication system and integrates with the Mastra server using the `auth` option.
6
+
7
+ ## Prerequisites
8
+
9
+ This example uses Clerk authentication. Make sure to add your Clerk credentials to your `.env` file and ensure your Clerk project is properly configured.
10
+
11
+ ```env
12
+ CLERK_PUBLISHABLE_KEY=pk_test_...
13
+ CLERK_SECRET_KEY=sk_test_...
14
+ CLERK_JWKS_URI=https://your-clerk-domain.clerk.accounts.dev/.well-known/jwks.json
15
+ ```
16
+
17
+ > **Note:** You can find these keys in your Clerk Dashboard under "API Keys".
18
+
19
+ ## Installation
20
+
21
+ Before you can use the `MastraAuthClerk` class you have to install the `@mastra/auth-clerk` package.
22
+
23
+ **npm**:
24
+
25
+ ```bash
26
+ npm install @mastra/auth-clerk@latest
27
+ ```
28
+
29
+ **pnpm**:
30
+
31
+ ```bash
32
+ pnpm add @mastra/auth-clerk@latest
33
+ ```
34
+
35
+ **Yarn**:
36
+
37
+ ```bash
38
+ yarn add @mastra/auth-clerk@latest
39
+ ```
40
+
41
+ **Bun**:
42
+
43
+ ```bash
44
+ bun add @mastra/auth-clerk@latest
45
+ ```
46
+
47
+ ## Usage example
48
+
49
+ ```typescript
50
+ import { Mastra } from '@mastra/core'
51
+ import { MastraAuthClerk } from '@mastra/auth-clerk'
52
+
53
+ export const mastra = new Mastra({
54
+ server: {
55
+ auth: new MastraAuthClerk({
56
+ publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
57
+ secretKey: process.env.CLERK_SECRET_KEY,
58
+ jwksUri: process.env.CLERK_JWKS_URI,
59
+ }),
60
+ },
61
+ })
62
+ ```
63
+
64
+ > **Info:** The default `authorizeUser` method allows all authenticated users. To customize user authorization, provide a custom `authorizeUser` function when constructing the provider.
65
+ >
66
+ > Visit [MastraAuthClerk](https://mastra.ai/reference/auth/clerk) for all available configuration options.
67
+
68
+ ## Client-side setup
69
+
70
+ When using Clerk auth, you'll need to retrieve the access token from Clerk on the client side and pass it to your Mastra requests.
71
+
72
+ ### Retrieving the access token
73
+
74
+ Use the Clerk React hooks to authenticate users and retrieve their access token:
75
+
76
+ ```typescript
77
+ import { useAuth } from '@clerk/nextjs'
78
+
79
+ export const useClerkAuth = () => {
80
+ const { getToken } = useAuth()
81
+
82
+ const getAccessToken = async () => {
83
+ const token = await getToken()
84
+ return token
85
+ }
86
+
87
+ return { getAccessToken }
88
+ }
89
+ ```
90
+
91
+ Refer to the [Clerk documentation](https://clerk.com/docs) for more information.
92
+
93
+ ## Configuring `MastraClient`
94
+
95
+ When `auth` is enabled, all requests made with `MastraClient` must include a valid Clerk access token in the `Authorization` header:
96
+
97
+ ```typescript
98
+ import { MastraClient } from '@mastra/client-js'
99
+
100
+ export const mastraClient = new MastraClient({
101
+ baseUrl: 'https://<mastra-api-url>',
102
+ headers: {
103
+ Authorization: `Bearer ${accessToken}`,
104
+ },
105
+ })
106
+ ```
107
+
108
+ > **Info:** The access token must be prefixed with `Bearer` in the Authorization header.
109
+ >
110
+ > Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
111
+
112
+ ### Making authenticated requests
113
+
114
+ Once `MastraClient` is configured with the Clerk access token, you can send authenticated requests:
115
+
116
+ **React**:
117
+
118
+ ```tsx
119
+ 'use client'
120
+
121
+ import { useAuth } from '@clerk/nextjs'
122
+ import { MastraClient } from '@mastra/client-js'
123
+
124
+ export const TestAgent = () => {
125
+ const { getToken } = useAuth()
126
+
127
+ async function handleClick() {
128
+ const token = await getToken()
129
+
130
+ const client = new MastraClient({
131
+ baseUrl: 'http://localhost:4111',
132
+ headers: token ? { Authorization: `Bearer ${token}` } : undefined,
133
+ })
134
+
135
+ const weatherAgent = client.getAgent('weatherAgent')
136
+ const response = await weatherAgent.generate("What's the weather like in New York")
137
+
138
+ console.log({ response })
139
+ }
140
+
141
+ return <button onClick={handleClick}>Test Agent</button>
142
+ }
143
+ ```
144
+
145
+ **cURL**:
146
+
147
+ ```bash
148
+ curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
149
+ -H "Content-Type: application/json" \
150
+ -H "Authorization: Bearer <your-clerk-access-token>" \
151
+ -d '{
152
+ "messages": "Weather in London"
153
+ }'
154
+ ```
@@ -0,0 +1,294 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Firebase
4
+
5
+ The `@mastra/auth-firebase` package provides authentication for Mastra using Firebase Authentication. It verifies incoming requests using Firebase ID tokens and integrates with the Mastra server using the `auth` option.
6
+
7
+ ## Prerequisites
8
+
9
+ This example uses Firebase Authentication. Make sure to:
10
+
11
+ 1. Create a Firebase project in the [Firebase Console](https://console.firebase.google.com/)
12
+ 2. Enable Authentication and configure your preferred sign-in methods (Google, Email/Password, etc.)
13
+ 3. Generate a service account key from Project Settings > Service Accounts
14
+ 4. Download the service account JSON file
15
+
16
+ ```env
17
+ FIREBASE_SERVICE_ACCOUNT=/path/to/your/service-account-key.json
18
+ FIRESTORE_DATABASE_ID=(default)
19
+ # Alternative environment variable names:
20
+ # FIREBASE_DATABASE_ID=(default)
21
+ ```
22
+
23
+ > **Note:** Store your service account JSON file securely and never commit it to version control.
24
+
25
+ ## Installation
26
+
27
+ Before you can use the `MastraAuthFirebase` class you have to install the `@mastra/auth-firebase` package.
28
+
29
+ **npm**:
30
+
31
+ ```bash
32
+ npm install @mastra/auth-firebase@latest
33
+ ```
34
+
35
+ **pnpm**:
36
+
37
+ ```bash
38
+ pnpm add @mastra/auth-firebase@latest
39
+ ```
40
+
41
+ **Yarn**:
42
+
43
+ ```bash
44
+ yarn add @mastra/auth-firebase@latest
45
+ ```
46
+
47
+ **Bun**:
48
+
49
+ ```bash
50
+ bun add @mastra/auth-firebase@latest
51
+ ```
52
+
53
+ ## Usage examples
54
+
55
+ ### Basic usage with environment variables
56
+
57
+ If you set the required environment variables (`FIREBASE_SERVICE_ACCOUNT` and `FIRESTORE_DATABASE_ID`), you can initialize `MastraAuthFirebase` without any constructor arguments. The class will automatically read these environment variables as configuration:
58
+
59
+ ```typescript
60
+ import { Mastra } from '@mastra/core'
61
+ import { MastraAuthFirebase } from '@mastra/auth-firebase'
62
+
63
+ // Automatically uses FIREBASE_SERVICE_ACCOUNT and FIRESTORE_DATABASE_ID env vars
64
+ export const mastra = new Mastra({
65
+ server: {
66
+ auth: new MastraAuthFirebase(),
67
+ },
68
+ })
69
+ ```
70
+
71
+ ### Custom configuration
72
+
73
+ ```typescript
74
+ import { Mastra } from '@mastra/core'
75
+ import { MastraAuthFirebase } from '@mastra/auth-firebase'
76
+
77
+ export const mastra = new Mastra({
78
+ server: {
79
+ auth: new MastraAuthFirebase({
80
+ serviceAccount: '/path/to/service-account.json',
81
+ databaseId: 'your-database-id',
82
+ }),
83
+ },
84
+ })
85
+ ```
86
+
87
+ ## Configuration
88
+
89
+ The `MastraAuthFirebase` class can be configured through constructor options or environment variables.
90
+
91
+ ### Environment variables
92
+
93
+ - `FIREBASE_SERVICE_ACCOUNT`: Path to Firebase service account JSON file
94
+ - `FIRESTORE_DATABASE_ID` or `FIREBASE_DATABASE_ID`: Firestore database ID
95
+
96
+ > **Note:** When constructor options aren't provided, the class automatically reads these environment variables. As a result, you can call `new MastraAuthFirebase()` without any arguments if your environment variables are properly configured.
97
+
98
+ ### User Authorization
99
+
100
+ By default, `MastraAuthFirebase` uses Firestore to manage user access. It expects a `user_access` collection with documents keyed by user UIDs. The presence of a document in this collection determines whether a user is authorized.
101
+
102
+ ```text
103
+ user_access/
104
+ {user_uid_1}/ // Document exists = user authorized
105
+ {user_uid_2}/ // Document exists = user authorized
106
+ ```
107
+
108
+ To customize user authorization, provide a custom `authorizeUser` function:
109
+
110
+ ```typescript
111
+ import { MastraAuthFirebase } from '@mastra/auth-firebase'
112
+
113
+ const firebaseAuth = new MastraAuthFirebase({
114
+ authorizeUser: async user => {
115
+ // Custom authorization logic
116
+ return user.email?.endsWith('@yourcompany.com') || false
117
+ },
118
+ })
119
+ ```
120
+
121
+ Visit [MastraAuthFirebase](https://mastra.ai/reference/auth/firebase) for all available configuration options.
122
+
123
+ ## Client-side setup
124
+
125
+ When using Firebase auth, you'll need to initialize Firebase on the client side, authenticate users, and retrieve their ID tokens to pass to your Mastra requests.
126
+
127
+ ### Setting up Firebase on the client
128
+
129
+ First, initialize Firebase in your client application:
130
+
131
+ ```typescript
132
+ import { initializeApp } from 'firebase/app'
133
+ import { getAuth, GoogleAuthProvider } from 'firebase/auth'
134
+
135
+ const firebaseConfig = {
136
+ apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
137
+ authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
138
+ projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
139
+ }
140
+
141
+ const app = initializeApp(firebaseConfig)
142
+ export const auth = getAuth(app)
143
+ export const googleProvider = new GoogleAuthProvider()
144
+ ```
145
+
146
+ ### Authenticating users and retrieving tokens
147
+
148
+ Use Firebase authentication to sign in users and retrieve their ID tokens:
149
+
150
+ ```typescript
151
+ import { signInWithPopup, signOut, User } from 'firebase/auth'
152
+ import { auth, googleProvider } from './firebase'
153
+
154
+ export const signInWithGoogle = async () => {
155
+ try {
156
+ const result = await signInWithPopup(auth, googleProvider)
157
+ return result.user
158
+ } catch (error) {
159
+ console.error('Error signing in:', error)
160
+ throw error
161
+ }
162
+ }
163
+
164
+ export const getIdToken = async (user: User) => {
165
+ try {
166
+ const idToken = await user.getIdToken()
167
+ return idToken
168
+ } catch (error) {
169
+ console.error('Error getting ID token:', error)
170
+ throw error
171
+ }
172
+ }
173
+
174
+ export const signOutUser = async () => {
175
+ try {
176
+ await signOut(auth)
177
+ } catch (error) {
178
+ console.error('Error signing out:', error)
179
+ throw error
180
+ }
181
+ }
182
+ ```
183
+
184
+ > **Note:** Refer to the [Firebase documentation](https://firebase.google.com/docs/auth) for other authentication methods like email/password, phone authentication, and more.
185
+
186
+ ## Configuring `MastraClient`
187
+
188
+ When `auth` is enabled, all requests made with `MastraClient` must include a valid Firebase ID token in the `Authorization` header:
189
+
190
+ ```typescript
191
+ import { MastraClient } from '@mastra/client-js'
192
+
193
+ export const createMastraClient = (idToken: string) => {
194
+ return new MastraClient({
195
+ baseUrl: 'https://<mastra-api-url>',
196
+ headers: {
197
+ Authorization: `Bearer ${idToken}`,
198
+ },
199
+ })
200
+ }
201
+ ```
202
+
203
+ > **Info:** The ID token must be prefixed with `Bearer` in the Authorization header.
204
+ >
205
+ > Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
206
+
207
+ ### Making authenticated requests
208
+
209
+ Once `MastraClient` is configured with the Firebase ID token, you can send authenticated requests:
210
+
211
+ **React**:
212
+
213
+ ```tsx
214
+ 'use client'
215
+
216
+ import { useAuthState } from 'react-firebase-hooks/auth'
217
+ import { MastraClient } from '@mastra/client-js'
218
+ import { auth } from '../lib/firebase'
219
+ import { getIdToken } from '../lib/auth'
220
+
221
+ export const TestAgent = () => {
222
+ const [user] = useAuthState(auth)
223
+
224
+ async function handleClick() {
225
+ if (!user) return
226
+
227
+ const token = await getIdToken(user)
228
+ const client = createMastraClient(token)
229
+
230
+ const weatherAgent = client.getAgent('weatherAgent')
231
+ const response = await weatherAgent.generate("What's the weather like in New York")
232
+
233
+ console.log({ response })
234
+ }
235
+
236
+ return (
237
+ <button onClick={handleClick} disabled={!user}>
238
+ Test Agent
239
+ </button>
240
+ )
241
+ }
242
+ ```
243
+
244
+ **Node.js**:
245
+
246
+ ```typescript
247
+ const express = require('express')
248
+ const admin = require('firebase-admin')
249
+ const { MastraClient } = require('@mastra/client-js')
250
+
251
+ // Initialize Firebase Admin
252
+ admin.initializeApp({
253
+ credential: admin.credential.cert({
254
+ // Your service account credentials
255
+ }),
256
+ })
257
+
258
+ const app = express()
259
+ app.use(express.json())
260
+
261
+ app.post('/generate', async (req, res) => {
262
+ try {
263
+ const { idToken } = req.body
264
+
265
+ // Verify the token
266
+ await admin.auth().verifyIdToken(idToken)
267
+
268
+ const mastra = new MastraClient({
269
+ baseUrl: 'http://localhost:4111',
270
+ headers: {
271
+ Authorization: `Bearer ${idToken}`,
272
+ },
273
+ })
274
+
275
+ const weatherAgent = mastra.getAgent('weatherAgent')
276
+ const response = await weatherAgent.generate("What's the weather like in Nairobi")
277
+
278
+ res.json({ response: response.text })
279
+ } catch (error) {
280
+ res.status(401).json({ error: 'Unauthorized' })
281
+ }
282
+ })
283
+ ```
284
+
285
+ **cURL**:
286
+
287
+ ```bash
288
+ curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
289
+ -H "Content-Type: application/json" \
290
+ -H "Authorization: Bearer <your-firebase-id-token>" \
291
+ -d '{
292
+ "messages": "Weather in London"
293
+ }'
294
+ ```
@@ -0,0 +1,116 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # JSON Web Token
4
+
5
+ The `MastraJwtAuth` class provides a lightweight authentication mechanism for Mastra using JSON Web Tokens (JWTs). It verifies incoming requests based on a shared secret and integrates with the Mastra server using the `auth` option.
6
+
7
+ ## Installation
8
+
9
+ Before you can use the `MastraJwtAuth` class you have to install the `@mastra/auth` package.
10
+
11
+ **npm**:
12
+
13
+ ```bash
14
+ npm install @mastra/auth@latest
15
+ ```
16
+
17
+ **pnpm**:
18
+
19
+ ```bash
20
+ pnpm add @mastra/auth@latest
21
+ ```
22
+
23
+ **Yarn**:
24
+
25
+ ```bash
26
+ yarn add @mastra/auth@latest
27
+ ```
28
+
29
+ **Bun**:
30
+
31
+ ```bash
32
+ bun add @mastra/auth@latest
33
+ ```
34
+
35
+ ## Creating a JWT
36
+
37
+ To authenticate requests to your Mastra server, you'll need a valid JSON Web Token (JWT) signed with your `MASTRA_JWT_SECRET`.
38
+
39
+ The easiest way to generate one is using [jwt.io](https://www.jwt.io/):
40
+
41
+ 1. Select **JWT Encoder**.
42
+ 2. Scroll down to the **Sign JWT: Secret** section.
43
+ 3. Enter your secret (for example: `supersecretdevkeythatishs256safe!`).
44
+ 4. Click **Generate example** to create a valid JWT.
45
+ 5. Copy the generated token and set it as `MASTRA_JWT_TOKEN` in your `.env` file.
46
+
47
+ ## Usage example
48
+
49
+ Take your generated JWT and use it to configure `MastraJwtAuth` in your Mastra server:
50
+
51
+ ```typescript
52
+ import { Mastra } from '@mastra/core'
53
+ import { MastraJwtAuth } from '@mastra/auth'
54
+
55
+ export const mastra = new Mastra({
56
+ server: {
57
+ auth: new MastraJwtAuth({
58
+ secret: process.env.MASTRA_JWT_SECRET,
59
+ }),
60
+ },
61
+ })
62
+ ```
63
+
64
+ Visit [MastraJwtAuth](https://mastra.ai/reference/auth/jwt) for all available configuration options.
65
+
66
+ Inside [Studio](https://mastra.ai/docs/studio/overview), go to **Settings** and under **Headers** select the **"Add Header"** button. Enter `Authorization` as the header name and `Bearer <your-jwt>` as the value.
67
+
68
+ ## Configuring `MastraClient`
69
+
70
+ When `auth` is enabled, all requests made with `MastraClient` must include a valid JWT in the `Authorization` header:
71
+
72
+ ```typescript
73
+ import { MastraClient } from '@mastra/client-js'
74
+
75
+ export const mastraClient = new MastraClient({
76
+ baseUrl: 'https://<mastra-api-url>',
77
+ headers: {
78
+ Authorization: `Bearer ${process.env.MASTRA_JWT_TOKEN}`,
79
+ },
80
+ })
81
+ ```
82
+
83
+ Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
84
+
85
+ ### Making authenticated requests
86
+
87
+ Once `MastraClient` is configured, you can send authenticated requests from your frontend application, or use `curl` for quick local testing:
88
+
89
+ **React**:
90
+
91
+ ```tsx
92
+ import { mastraClient } from '../../lib/mastra-client'
93
+
94
+ export const TestAgent = () => {
95
+ async function handleClick() {
96
+ const agent = mastraClient.getAgent('weatherAgent')
97
+
98
+ const response = await agent.generate('Weather in London')
99
+
100
+ console.log(response)
101
+ }
102
+
103
+ return <button onClick={handleClick}>Test Agent</button>
104
+ }
105
+ ```
106
+
107
+ **cURL**:
108
+
109
+ ```bash
110
+ curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
111
+ -H "Content-Type: application/json" \
112
+ -H "Authorization: Bearer <your-jwt>" \
113
+ -d '{
114
+ "messages": "Weather in London"
115
+ }'
116
+ ```
@@ -0,0 +1,139 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Supabase
4
+
5
+ The `@mastra/auth-supabase` package provides authentication for Mastra using Supabase Auth. It verifies incoming requests using Supabase's authentication system and integrates with the Mastra server using the `auth` option.
6
+
7
+ ## Prerequisites
8
+
9
+ This example uses Supabase Auth. Make sure to add your Supabase credentials to your `.env` file and ensure your Supabase project is properly configured.
10
+
11
+ ```env
12
+ SUPABASE_URL=https://your-project.supabase.co
13
+ SUPABASE_ANON_KEY=your-anon-key
14
+ ```
15
+
16
+ > **Note:** Review your Supabase Row Level Security (RLS) settings to ensure proper data access controls.
17
+
18
+ ## Installation
19
+
20
+ Before you can use the `MastraAuthSupabase` class you have to install the `@mastra/auth-supabase` package.
21
+
22
+ **npm**:
23
+
24
+ ```bash
25
+ npm install @mastra/auth-supabase@latest
26
+ ```
27
+
28
+ **pnpm**:
29
+
30
+ ```bash
31
+ pnpm add @mastra/auth-supabase@latest
32
+ ```
33
+
34
+ **Yarn**:
35
+
36
+ ```bash
37
+ yarn add @mastra/auth-supabase@latest
38
+ ```
39
+
40
+ **Bun**:
41
+
42
+ ```bash
43
+ bun add @mastra/auth-supabase@latest
44
+ ```
45
+
46
+ ## Usage example
47
+
48
+ ```typescript
49
+ import { Mastra } from '@mastra/core'
50
+ import { MastraAuthSupabase } from '@mastra/auth-supabase'
51
+
52
+ export const mastra = new Mastra({
53
+ server: {
54
+ auth: new MastraAuthSupabase({
55
+ url: process.env.SUPABASE_URL,
56
+ anonKey: process.env.SUPABASE_ANON_KEY,
57
+ }),
58
+ },
59
+ })
60
+ ```
61
+
62
+ > **Info:** The default `authorizeUser` method checks the `isAdmin` column in the `users` table in the `public` schema. To customize user authorization, provide a custom `authorizeUser` function when constructing the provider.
63
+ >
64
+ > Visit [MastraAuthSupabase](https://mastra.ai/reference/auth/supabase) for all available configuration options.
65
+
66
+ ## Client-side setup
67
+
68
+ When using Supabase auth, you'll need to retrieve the access token from Supabase on the client side and pass it to your Mastra requests.
69
+
70
+ ### Retrieving the access token
71
+
72
+ Use the Supabase client to authenticate users and retrieve their access token:
73
+
74
+ ```typescript
75
+ import { createClient } from '@supabase/supabase-js'
76
+
77
+ const supabase = createClient('<supabase-url>', '<supabase-key>')
78
+
79
+ const authTokenResponse = await supabase.auth.signInWithPassword({
80
+ email: "<user's email>",
81
+ password: "<user's password>",
82
+ })
83
+
84
+ const accessToken = authTokenResponse.data?.session?.access_token
85
+ ```
86
+
87
+ > **Note:** Refer to the [Supabase documentation](https://supabase.com/docs/guides/auth) for other authentication methods like OAuth, magic links, and more.
88
+
89
+ ## Configuring `MastraClient`
90
+
91
+ When `auth` is enabled, all requests made with `MastraClient` must include a valid Supabase access token in the `Authorization` header:
92
+
93
+ ```typescript
94
+ import { MastraClient } from '@mastra/client-js'
95
+
96
+ export const mastraClient = new MastraClient({
97
+ baseUrl: 'https://<mastra-api-url>',
98
+ headers: {
99
+ Authorization: `Bearer ${accessToken}`,
100
+ },
101
+ })
102
+ ```
103
+
104
+ > **Info:** The access token must be prefixed with `Bearer` in the Authorization header.
105
+ >
106
+ > Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
107
+
108
+ ### Making authenticated requests
109
+
110
+ Once `MastraClient` is configured with the Supabase access token, you can send authenticated requests:
111
+
112
+ **React**:
113
+
114
+ ```tsx
115
+ import { mastraClient } from '../../lib/mastra-client'
116
+
117
+ export const TestAgent = () => {
118
+ async function handleClick() {
119
+ const agent = mastraClient.getAgent('weatherAgent')
120
+
121
+ const response = await agent.generate("What's the weather like in New York")
122
+
123
+ console.log(response)
124
+ }
125
+
126
+ return <button onClick={handleClick}>Test Agent</button>
127
+ }
128
+ ```
129
+
130
+ **cURL**:
131
+
132
+ ```bash
133
+ curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
134
+ -H "Content-Type: application/json" \
135
+ -H "Authorization: Bearer <your-supabase-access-token>" \
136
+ -d '{
137
+ "messages": "Weather in London"
138
+ }'
139
+ ```