@clerk/agent-toolkit 0.0.6-canary.v20250306110334

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,648 @@
1
+ // src/lib/clerk-client.ts
2
+ import { createClerkClient } from "@clerk/backend";
3
+ import { apiUrlFromPublishableKey } from "@clerk/shared/apiUrlFromPublishableKey";
4
+ import { getEnvVariable } from "@clerk/shared/getEnvVariable";
5
+ var API_VERSION = getEnvVariable("CLERK_API_VERSION") || "v1";
6
+ var SECRET_KEY = getEnvVariable("CLERK_SECRET_KEY") || "";
7
+ var PUBLISHABLE_KEY = getEnvVariable("CLERK_PUBLISHABLE_KEY") || "";
8
+ var API_URL = getEnvVariable("CLERK_API_URL") || apiUrlFromPublishableKey(PUBLISHABLE_KEY);
9
+ var JWT_KEY = getEnvVariable("CLERK_JWT_KEY") || "";
10
+ var SDK_METADATA = {
11
+ name: "@clerk/agent-toolkit",
12
+ version: "0.0.6-canary.v20250306110334",
13
+ environment: getEnvVariable("NODE_ENV")
14
+ };
15
+ var clerkClient = createClerkClient({
16
+ secretKey: SECRET_KEY,
17
+ apiUrl: API_URL,
18
+ apiVersion: API_VERSION,
19
+ jwtKey: JWT_KEY,
20
+ userAgent: `${"@clerk/agent-toolkit"}@${"0.0.6-canary.v20250306110334"}`,
21
+ sdkMetadata: SDK_METADATA
22
+ });
23
+
24
+ // src/lib/constants.ts
25
+ var defaultToolkitContext = {
26
+ allowPrivateMetadata: false
27
+ };
28
+
29
+ // src/lib/inject-session-claims.ts
30
+ var injectSessionClaims = (context) => (prompt) => {
31
+ if (!context.sessionClaims && !context.userId) {
32
+ return prompt;
33
+ }
34
+ const lines = [];
35
+ lines.push(`# Signed-in user info:`);
36
+ lines.push(
37
+ context.sessionClaims?.sub || context.userId ? `Your userId is ${context.sessionClaims?.sub || context.userId}` : ""
38
+ );
39
+ lines.push(context.sessionClaims?.sid ? `Your sessionId is ${context.sessionClaims?.sid}` : "");
40
+ lines.push(prompt);
41
+ return lines.filter(Boolean).join("\n");
42
+ };
43
+
44
+ // src/lib/utils.ts
45
+ function shallowTransform(input, transformFn) {
46
+ const result = {};
47
+ for (const key in input) {
48
+ if (Object.prototype.hasOwnProperty.call(input, key)) {
49
+ const typedKey = key;
50
+ result[typedKey] = transformFn(input[typedKey]);
51
+ }
52
+ }
53
+ return result;
54
+ }
55
+ var prunePrivateData = (context, o) => {
56
+ if (context.allowPrivateMetadata) {
57
+ return o;
58
+ }
59
+ if (o && o.private_metadata) {
60
+ delete o.private_metadata;
61
+ }
62
+ return o;
63
+ };
64
+
65
+ // src/lib/tools/invitations.ts
66
+ import { z } from "zod";
67
+
68
+ // src/lib/clerk-tool.ts
69
+ var trimLines = (text) => text.split("\n").map((l) => l.trim()).filter(Boolean).join("\n");
70
+ var ClerkTool = (params) => {
71
+ const schemaEntries = Object.entries(params.parameters.shape);
72
+ const args = schemaEntries.length === 0 ? "Takes no arguments" : Object.entries(params.parameters.shape).map(([key, value]) => {
73
+ return `- ${key}: ${value.description || ""}`;
74
+ }).join("\n");
75
+ const description = trimLines(`
76
+ Tool name:
77
+ ${params.name}
78
+ Description:
79
+ ${params.description}.
80
+ Arguments:
81
+ ${args}
82
+ `);
83
+ return { ...params, description };
84
+ };
85
+
86
+ // src/lib/tools/invitations.ts
87
+ var createInvitation = ClerkTool({
88
+ name: "createInvitation",
89
+ description: `
90
+ Creates a new invitation for a specified email address to join your application.
91
+ Use this tool when you need to send invitation emails to new users.
92
+
93
+ The invited email will receive an email with a sign-up link.
94
+ You can customize the redirect URL and attach public metadata to the invitation.
95
+
96
+ Example use cases:
97
+ 1. Implementing a user invitation system for a private beta
98
+ 2. Creating a closed registration system where only invited users can join
99
+ 3. Pre-configuring user attributes via publicMetadata before they sign up
100
+ `,
101
+ parameters: z.object({
102
+ emailAddress: z.string().describe("(string): Email address to send the invitation to. Required."),
103
+ redirectUrl: z.string().optional().describe("(string, optional): URL to redirect users to after they accept the invitation."),
104
+ publicMetadata: z.record(z.string(), z.any()).optional().describe("(Record<string,any>, optional): Public metadata for the invitation."),
105
+ notify: z.boolean().optional().describe("(boolean, optional): Whether to send an email notification. Defaults to true."),
106
+ ignoreExisting: z.boolean().optional().describe("(boolean, optional): Whether to ignore if an invitation already exists. Defaults to false.")
107
+ }),
108
+ bindRunnable: (clerkClient2, context) => async (params) => {
109
+ const res = await clerkClient2.invitations.createInvitation(params);
110
+ return prunePrivateData(context, res.raw);
111
+ }
112
+ });
113
+ var revokeInvitation = ClerkTool({
114
+ name: "revokeInvitation",
115
+ description: `
116
+ Revokes a pending invitation, preventing the recipient from using it to sign up.
117
+ Use this tool when you need to cancel an invitation before it's accepted.
118
+
119
+ This immediately invalidates the invitation link sent to the user.
120
+ Once revoked, an invitation cannot be un-revoked; you would need to create a new invitation.
121
+
122
+ Example use cases:
123
+ 1. Canceling invitations sent by mistake
124
+ 2. Revoking access when a prospective user should no longer be invited
125
+ 3. Implementing invitation management controls for administrators
126
+ `,
127
+ parameters: z.object({
128
+ invitationId: z.string().describe("(string): The ID of the invitation to revoke. Required.")
129
+ }),
130
+ bindRunnable: (clerkClient2, context) => async (params) => {
131
+ const res = await clerkClient2.invitations.revokeInvitation(params.invitationId);
132
+ return prunePrivateData(context, res.raw);
133
+ }
134
+ });
135
+ var invitations = {
136
+ createInvitation,
137
+ revokeInvitation
138
+ };
139
+
140
+ // src/lib/tools/organizations.ts
141
+ import { z as z2 } from "zod";
142
+ var getOrganization = ClerkTool({
143
+ name: "getOrganization",
144
+ description: `
145
+ Retrieves a single organization by ID or slug.
146
+ Use this tool when you need detailed information about a specific organization.
147
+
148
+ You must provide either an organizationId OR a slug to identify the organization.
149
+
150
+ Example use cases:
151
+ 1. Displaying organization details on a profile page
152
+ 2. Checking if an organization exists before performing operations on it
153
+ 3. Retrieving organization metadata for application-specific functionality
154
+ `,
155
+ parameters: z2.object({
156
+ organizationId: z2.string().optional().describe("(string, optional): The ID of the organization to retrieve. Required if slug is not provided."),
157
+ slug: z2.string().optional().describe(
158
+ "(string, optional): The slug of the organization to retrieve. Required if organizationId is not provided."
159
+ ),
160
+ includeMembersCount: z2.boolean().optional().describe("(boolean, optional): Whether to include the members count for the organization.")
161
+ }),
162
+ bindRunnable: (clerkClient2, context) => async (params) => {
163
+ if (!params.organizationId && !params.slug) {
164
+ throw new Error("Either organizationId or slug must be provided");
165
+ }
166
+ const res = await clerkClient2.organizations.getOrganization({
167
+ ...params,
168
+ organizationId: context.organizationId || params.organizationId
169
+ });
170
+ return prunePrivateData(context, res.raw);
171
+ }
172
+ });
173
+ var createOrganization = ClerkTool({
174
+ name: "createOrganization",
175
+ description: `
176
+ Creates a new organization in your Clerk instance.
177
+ Use this tool when you need to programmatically create organizations.
178
+
179
+ A name is required to create an organization. Other fields like slug,
180
+ maxAllowedMemberships, and metadata are optional.
181
+
182
+ Example use cases:
183
+ 1. Creating organizations during user onboarding
184
+ 2. Building a self-service organization creation flow
185
+ 3. Migrating organizations from another system
186
+ `,
187
+ parameters: z2.object({
188
+ name: z2.string().describe("(string): The name of the new organization. Required."),
189
+ slug: z2.string().optional().describe(
190
+ "(string, optional): A URL-friendly identifier for the organization. If not provided, created from the name."
191
+ ),
192
+ createdBy: z2.string().optional().describe(
193
+ "(string, optional): The user ID of the user creating the organization. Defaults to the current authenticated user."
194
+ ),
195
+ maxAllowedMemberships: z2.number().optional().describe("(number, optional): Maximum number of members allowed in the organization."),
196
+ publicMetadata: z2.record(z2.string(), z2.any()).optional().describe("(Record<string,any>, optional): Public metadata for the organization."),
197
+ privateMetadata: z2.record(z2.string(), z2.any()).optional().describe("(Record<string,any>, optional): Private metadata for the organization (backend-only).")
198
+ }),
199
+ bindRunnable: (clerkClient2, context) => async (params) => {
200
+ const { createdBy, ...createParams } = params;
201
+ const createParamsWithUser = createdBy || context.userId ? { ...createParams, createdBy: createdBy || context.userId } : createParams;
202
+ const res = await clerkClient2.organizations.createOrganization(createParamsWithUser);
203
+ return prunePrivateData(context, res.raw);
204
+ }
205
+ });
206
+ var updateOrganization = ClerkTool({
207
+ name: "updateOrganization",
208
+ description: `
209
+ Updates an existing organization's attributes.
210
+ Use this tool when you need to modify core organization information (NOT metadata).
211
+
212
+ Only the fields you provide will be updated; others remain unchanged.
213
+ For updating just metadata, consider using updateOrganizationMetadata instead.
214
+
215
+ Example use cases:
216
+ 1. Updating an organization's name or slug
217
+ 2. Changing the maximum allowed memberships
218
+ 3. Updating multiple organization attributes at once
219
+ `,
220
+ parameters: z2.object({
221
+ organizationId: z2.string().describe("(string): The ID of the organization to update. Required."),
222
+ name: z2.string().optional().describe("(string, optional): New name for the organization."),
223
+ slug: z2.string().optional().describe("(string, optional): New slug for the organization."),
224
+ maxAllowedMemberships: z2.number().optional().describe("(number, optional): New maximum number of members allowed."),
225
+ publicMetadata: z2.record(z2.string(), z2.any()).optional().describe("(Record<string,any>, optional): New public metadata for the organization."),
226
+ privateMetadata: z2.record(z2.string(), z2.any()).optional().describe("(Record<string,any>, optional): New private metadata for the organization (backend-only).")
227
+ }),
228
+ bindRunnable: (clerkClient2, context) => async (params) => {
229
+ const { organizationId, ...updateParams } = params;
230
+ const res = await clerkClient2.organizations.updateOrganization(
231
+ context.organizationId || organizationId,
232
+ updateParams
233
+ );
234
+ return prunePrivateData(context, res.raw);
235
+ }
236
+ });
237
+ var updateOrganizationMetadata = ClerkTool({
238
+ name: "updateOrganizationMetadata",
239
+ description: `
240
+ Updates the metadata associated with an organization by merging existing values with the provided parameters.
241
+ Use this tool when you need to store or update organization-specific data without changing other attributes.
242
+
243
+ Important characteristics:
244
+ 1. A "deep" merge is performed - any nested JSON objects will be merged recursively
245
+ 2. You can remove metadata keys at any level by setting their value to null
246
+ 3. Public metadata is visible to the frontend
247
+ 4. Private metadata is only accessible on the backend
248
+
249
+ Example use cases:
250
+ 1. Storing organization preferences or settings
251
+ 2. Keeping track of organization-specific application state
252
+ 3. Adding custom attributes to organizations
253
+ `,
254
+ parameters: z2.object({
255
+ organizationId: z2.string().describe("(string): The ID of the organization to update. Required."),
256
+ publicMetadata: z2.record(z2.string(), z2.any()).optional().describe(
257
+ "(Record<string,any>, optional): The public metadata to set or update. Use null values to remove specific keys."
258
+ ),
259
+ privateMetadata: z2.record(z2.string(), z2.any()).optional().describe(
260
+ "(Record<string,any>, optional): The private metadata to set or update. Backend-only data. Use null values to remove specific keys."
261
+ )
262
+ }),
263
+ bindRunnable: (clerkClient2, context) => async (params) => {
264
+ const { organizationId, ...metadataParams } = params;
265
+ const res = await clerkClient2.organizations.updateOrganizationMetadata(
266
+ context.organizationId || organizationId,
267
+ metadataParams
268
+ );
269
+ return prunePrivateData(context, res.raw);
270
+ }
271
+ });
272
+ var deleteOrganization = ClerkTool({
273
+ name: "deleteOrganization",
274
+ description: `
275
+ Permanently deletes an organization from your Clerk instance.
276
+ Use this tool when you need to remove an organization completely.
277
+
278
+ WARNING: This action is irreversible. All organization data, memberships,
279
+ and invitations will be permanently deleted.
280
+
281
+ Example use cases:
282
+ 1. Implementing organization cleanup flows
283
+ 2. Allowing users to delete their own organizations
284
+ 3. Administrative operations to remove unwanted organizations
285
+ `,
286
+ parameters: z2.object({
287
+ organizationId: z2.string().describe("(string): The ID of the organization to delete. Required.")
288
+ }),
289
+ bindRunnable: (clerkClient2, context) => async (params) => {
290
+ const res = await clerkClient2.organizations.deleteOrganization(context.organizationId || params.organizationId);
291
+ return prunePrivateData(context, res.raw);
292
+ }
293
+ });
294
+ var createOrganizationMembership = ClerkTool({
295
+ name: "createOrganizationMembership",
296
+ description: `
297
+ Adds a user to an organization with a specified role.
298
+ Use this tool when you need to programmatically add members to an organization.
299
+
300
+ This creates an immediate membership without requiring an invitation process.
301
+ The specified role determines what permissions the user will have in the organization.
302
+
303
+ Example use cases:
304
+ 1. Adding users to organizations during onboarding
305
+ 2. Building administrative interfaces for member management
306
+ 3. Migrating memberships from another system
307
+ `,
308
+ parameters: z2.object({
309
+ organizationId: z2.string().describe("(string): The ID of the organization to add the member to. Required."),
310
+ userId: z2.string().describe("(string): The ID of the user to add as a member. Required."),
311
+ role: z2.string().describe("(string): The role to assign to the user in the organization. Required.")
312
+ }),
313
+ bindRunnable: (clerkClient2, context) => async (params) => {
314
+ const res = await clerkClient2.organizations.createOrganizationMembership({
315
+ ...params,
316
+ organizationId: context.organizationId || params.organizationId,
317
+ userId: context.userId || params.userId
318
+ });
319
+ return prunePrivateData(context, res.raw);
320
+ }
321
+ });
322
+ var updateOrganizationMembership = ClerkTool({
323
+ name: "updateOrganizationMembership",
324
+ description: `
325
+ Updates a user's role within an organization.
326
+ Use this tool when you need to change a member's role or permissions.
327
+
328
+ This updates an existing membership relationship between a user and an organization.
329
+ The new role will replace the current role and change the user's permissions accordingly.
330
+
331
+ Example use cases:
332
+ 1. Promoting or demoting users within an organization
333
+ 2. Building role management interfaces
334
+ 3. Implementing admin-level controls for organization management
335
+ `,
336
+ parameters: z2.object({
337
+ organizationId: z2.string().describe("(string): The ID of the organization containing the membership. Required."),
338
+ userId: z2.string().describe("(string): The ID of the user whose membership is being updated. Required."),
339
+ role: z2.string().describe("(string): The new role to assign to the user. Required.")
340
+ }),
341
+ bindRunnable: (clerkClient2, context) => async (params) => {
342
+ const res = await clerkClient2.organizations.updateOrganizationMembership({
343
+ ...params,
344
+ organizationId: context.organizationId || params.organizationId
345
+ });
346
+ return prunePrivateData(context, res.raw);
347
+ }
348
+ });
349
+ var updateOrganizationMembershipMetadata = ClerkTool({
350
+ name: "updateOrganizationMembershipMetadata",
351
+ description: `
352
+ Updates the metadata associated with a user's membership in an organization.
353
+ Use this tool when you need to store or update membership-specific data.
354
+
355
+ Important characteristics:
356
+ 1. A "deep" merge is performed - any nested JSON objects will be merged recursively
357
+ 2. You can remove metadata keys at any level by setting their value to null
358
+ 3. Public metadata is visible to the frontend
359
+ 4. Private metadata is only accessible on the backend
360
+
361
+ Example use cases:
362
+ 1. Storing member-specific preferences or settings within an organization
363
+ 2. Adding custom attributes to track member activity or status
364
+ 3. Customizing a user's experience within a specific organization
365
+ `,
366
+ parameters: z2.object({
367
+ organizationId: z2.string().describe("(string): The ID of the organization containing the membership. Required."),
368
+ userId: z2.string().describe("(string): The ID of the user whose membership metadata is being updated. Required."),
369
+ publicMetadata: z2.record(z2.string(), z2.any()).optional().describe(
370
+ "(Record<string,any>, optional): The public metadata to set or update. Use null values to remove specific keys."
371
+ ),
372
+ privateMetadata: z2.record(z2.string(), z2.any()).optional().describe(
373
+ "(Record<string,any>, optional): The private metadata to set or update. Backend-only data. Use null values to remove specific keys."
374
+ )
375
+ }),
376
+ bindRunnable: (clerkClient2, context) => async (params) => {
377
+ const res = await clerkClient2.organizations.updateOrganizationMembershipMetadata({
378
+ ...params,
379
+ organizationId: context.organizationId || params.organizationId
380
+ });
381
+ return prunePrivateData(context, res.raw);
382
+ }
383
+ });
384
+ var deleteOrganizationMembership = ClerkTool({
385
+ name: "deleteOrganizationMembership",
386
+ description: `
387
+ Removes a user from an organization.
388
+ Use this tool when you need to revoke a user's membership in an organization.
389
+
390
+ This permanently breaks the membership relationship between the user and organization.
391
+ The user will immediately lose access to organization resources.
392
+
393
+ Example use cases:
394
+ 1. Removing users who have left the organization
395
+ 2. Building membership management interfaces with removal capability
396
+ 3. Implementing self-service leave organization functionality
397
+ `,
398
+ parameters: z2.object({
399
+ organizationId: z2.string().describe("(string): The ID of the organization to remove the member from. Required."),
400
+ userId: z2.string().describe("(string): The ID of the user to remove from the organization. Required.")
401
+ }),
402
+ bindRunnable: (clerkClient2, context) => async (params) => {
403
+ const res = await clerkClient2.organizations.deleteOrganizationMembership({
404
+ ...params,
405
+ userId: context.userId || params.userId
406
+ });
407
+ return prunePrivateData(context, res.raw);
408
+ }
409
+ });
410
+ var createOrganizationInvitation = ClerkTool({
411
+ name: "createOrganizationInvitation",
412
+ description: `
413
+ Creates an invitation to join an organization for a specified email address.
414
+ Use this tool when you need to invite new members to an organization.
415
+
416
+ The invited email will receive an email invitation to join the organization.
417
+ You can specify the role the user will have upon accepting the invitation.
418
+
419
+ Example use cases:
420
+ 1. Building invite flows for organization member management
421
+ 2. Implementing team expansion functionality
422
+ 3. Creating administrative tools for organization growth
423
+ `,
424
+ parameters: z2.object({
425
+ organizationId: z2.string().describe("(string): The ID of the organization to create an invitation for. Required."),
426
+ emailAddress: z2.string().describe("(string): Email address to send the invitation to. Required."),
427
+ role: z2.string().describe("(string): Role to assign to the user upon accepting the invitation. Required."),
428
+ inviterUserId: z2.string().optional().describe(
429
+ "(string, optional): User ID of the person sending the invitation. Defaults to the current authenticated user."
430
+ ),
431
+ redirectUrl: z2.string().optional().describe("(string, optional): URL to redirect users to after they accept the invitation."),
432
+ publicMetadata: z2.record(z2.string(), z2.any()).optional().describe("(Record<string,any>, optional): Public metadata for the invitation.")
433
+ }),
434
+ bindRunnable: (clerkClient2, context) => async (params) => {
435
+ const { inviterUserId, ...inviteParams } = params;
436
+ const inviteParamsWithUser = inviterUserId || context.userId ? { ...inviteParams, inviterUserId: inviterUserId || context.userId } : inviteParams;
437
+ const res = await clerkClient2.organizations.createOrganizationInvitation(inviteParamsWithUser);
438
+ return prunePrivateData(context, res.raw);
439
+ }
440
+ });
441
+ var revokeOrganizationInvitation = ClerkTool({
442
+ name: "revokeOrganizationInvitation",
443
+ description: `
444
+ Revokes a pending invitation to an organization.
445
+ Use this tool when you need to cancel an invitation before it's accepted.
446
+
447
+ This immediately invalidates the invitation, preventing the recipient
448
+ from using it to join the organization.
449
+
450
+ Example use cases:
451
+ 1. Canceling invitations sent by mistake
452
+ 2. Building invitation management interfaces with revocation capability
453
+ 3. Implementing security measures to quickly revoke access
454
+ `,
455
+ parameters: z2.object({
456
+ organizationId: z2.string().describe("(string): The ID of the organization containing the invitation. Required."),
457
+ invitationId: z2.string().describe("(string): The ID of the invitation to revoke. Required."),
458
+ requestingUserId: z2.string().optional().describe(
459
+ "(string, optional): User ID of the person revoking the invitation. Defaults to the current authenticated user."
460
+ )
461
+ }),
462
+ bindRunnable: (clerkClient2, context) => async (params) => {
463
+ const { requestingUserId, ...revokeParams } = params;
464
+ const revokeParamsWithUser = requestingUserId || context.userId ? { ...revokeParams, requestingUserId: requestingUserId || context.userId } : revokeParams;
465
+ const res = await clerkClient2.organizations.revokeOrganizationInvitation(revokeParamsWithUser);
466
+ return prunePrivateData(context, res.raw);
467
+ }
468
+ });
469
+ var organizations = {
470
+ getOrganization,
471
+ createOrganization,
472
+ updateOrganization,
473
+ updateOrganizationMetadata,
474
+ deleteOrganization,
475
+ createOrganizationMembership,
476
+ updateOrganizationMembership,
477
+ updateOrganizationMembershipMetadata,
478
+ deleteOrganizationMembership,
479
+ createOrganizationInvitation,
480
+ revokeOrganizationInvitation
481
+ };
482
+
483
+ // src/lib/tools/user.ts
484
+ import { z as z3 } from "zod";
485
+ var getUserId = ClerkTool({
486
+ name: "getUserId",
487
+ description: `
488
+ Get the userId of the current authenticated user if signed in, otherwise return null.
489
+ Use this tool when you need to identify the current user but don't need their profile details.
490
+ This tool takes no parameters and is the quickest way to check if a user is authenticated.
491
+ Example use case: When you need to verify if a user is logged in before performing user-specific operations.
492
+ `,
493
+ parameters: z3.object({}),
494
+ bindRunnable: (clerkClient2, context) => () => {
495
+ return Promise.resolve(context.userId || null);
496
+ }
497
+ });
498
+ var getUser = ClerkTool({
499
+ name: "getUser",
500
+ description: `
501
+ Retrieves detailed information about a user by their userId, including email addresses,
502
+ username, profile image, created/updated timestamps, and public metadata.
503
+ Use this tool when you need comprehensive user information beyond just their ID.
504
+ If the userId parameter is not provided, it will use the current authenticated user's ID.
505
+ Example use case: When you need to display user profile information or check user attributes.
506
+ `,
507
+ parameters: z3.object({
508
+ userId: z3.string().describe("(string): The userId of the User to retrieve.")
509
+ }),
510
+ bindRunnable: (clerkClient2, context) => async (params) => {
511
+ const res = await clerkClient2.users.getUser(context.userId || params.userId);
512
+ return prunePrivateData(context, res.raw);
513
+ }
514
+ });
515
+ var getUserCount = ClerkTool({
516
+ name: "getUserCount",
517
+ description: `
518
+ Retrieves the total count of users in your Clerk instance.
519
+ Use this tool when you need to know the total number of users in the system.
520
+ This tool takes no parameters and is an efficient way to get just the count without retrieving user details.
521
+ `,
522
+ parameters: z3.object({}),
523
+ bindRunnable: (clerkClient2, _) => async () => {
524
+ return await clerkClient2.users.getCount();
525
+ }
526
+ });
527
+ var updateUserPublicMetadata = ClerkTool({
528
+ name: "updateUserPublicMetadata",
529
+ description: `
530
+ Updates the public metadata associated with a user by merging existing values with the provided parameters.
531
+ Use this tool when you need to store or update user preferences, settings, or other non-sensitive information.
532
+
533
+ Important characteristics:
534
+ 1. A "deep" merge is performed - any nested JSON objects will be merged recursively.
535
+ 2. You can remove metadata keys at any level by setting their value to null.
536
+ 3. Public metadata is visible to the frontend and should NOT contain sensitive information.
537
+
538
+ Example use case: Storing user preferences, feature flags, or application-specific data that persists across sessions.
539
+ `,
540
+ parameters: z3.object({
541
+ userId: z3.string().describe("(string): The userId of the User to update."),
542
+ metadata: z3.record(z3.string(), z3.any()).describe("(Record<string,any>): The public metadata to set or update. Use null values to remove specific keys.")
543
+ }),
544
+ bindRunnable: (clerkClient2, context) => async (params) => {
545
+ const { userId, metadata } = params;
546
+ const res = await clerkClient2.users.updateUserMetadata(context.userId || userId, { publicMetadata: metadata });
547
+ return prunePrivateData(context, res.raw);
548
+ }
549
+ });
550
+ var updateUserUnsafeMetadata = ClerkTool({
551
+ name: "updateUserUnsafeMetadata",
552
+ description: `
553
+ Updates the unsafe metadata associated with a user by merging existing values with the provided parameters.
554
+ Use this tool when you need to store data that should be accessible both on the frontend and backend.
555
+
556
+ Important characteristics:
557
+ 1. A "deep" merge is performed - any nested JSON objects will be merged recursively.
558
+ 2. You can remove metadata keys at any level by setting their value to null.
559
+ 3. Unsafe metadata is accessible from both frontend and backend code.
560
+ 4. Unlike public metadata, unsafe metadata is NOT included in JWT tokens.
561
+
562
+ Example use case: Storing user data that should be modifiable from the frontend but not included in authentication tokens.
563
+ `,
564
+ parameters: z3.object({
565
+ userId: z3.string().describe("(string): The userId of the User to update."),
566
+ metadata: z3.record(z3.string(), z3.any()).describe("(Record<string,any>): The unsafe metadata to set or update. Use null values to remove specific keys.")
567
+ }),
568
+ bindRunnable: (clerkClient2, context) => async (params) => {
569
+ const { userId, metadata } = params;
570
+ const res = await clerkClient2.users.updateUserMetadata(context.userId || userId, { unsafeMetadata: metadata });
571
+ return prunePrivateData(context, res.raw);
572
+ }
573
+ });
574
+ var updateUser = ClerkTool({
575
+ name: "updateUser",
576
+ description: `
577
+ Updates an existing user's attributes in your Clerk instance.
578
+ Use this tool when you need to modify core user information (NOT metadata).
579
+
580
+ Important notes:
581
+ 1. If the userId parameter is not provided, it will use the current authenticated user's ID
582
+ 2. Only the provided fields will be updated, other fields remain unchanged
583
+ 3. For updating metadata, use the specialized metadata update tools instead
584
+ 4. Email and phone verification status cannot be changed with this tool
585
+
586
+ Example use cases:
587
+ 1. Updating a user's name, username, or other profile information
588
+ 2. Enabling or disabling a user account
589
+ 3. Setting a user's primary contact information
590
+ `,
591
+ parameters: z3.object({
592
+ userId: z3.string().describe("(string): The userId of the User to update."),
593
+ firstName: z3.string().optional().describe("(string): New first name for the user"),
594
+ lastName: z3.string().optional().describe("(string): New last name for the user"),
595
+ username: z3.string().optional().describe("(string): New username for the user"),
596
+ profileImageUrl: z3.string().optional().describe("(string): URL for the user profile image")
597
+ }),
598
+ bindRunnable: (clerkClient2, context) => async (params) => {
599
+ const { userId, ...updateParams } = params;
600
+ const res = await clerkClient2.users.updateUser(context.userId || userId, updateParams);
601
+ return prunePrivateData(context, res.raw);
602
+ }
603
+ });
604
+ var users = {
605
+ getUserId,
606
+ getUser,
607
+ getUserCount,
608
+ updateUser,
609
+ updateUserPublicMetadata,
610
+ updateUserUnsafeMetadata
611
+ };
612
+
613
+ // src/lib/tools/index.ts
614
+ var tools = {
615
+ /**
616
+ * Tools for interacting with users.
617
+ * This is a wrapper around the `clerkClient.users` API.
618
+ * For more information, see the [Clerk API documentation](https://clerk.com/docs/reference/backend-api/tag/Users).
619
+ */
620
+ users,
621
+ /**
622
+ * Tools for interacting with organizations.
623
+ * This is a wrapper around the `clerkClient.organizations` API.
624
+ * For more information, see the [Clerk API documentation](https://clerk.com/docs/reference/backend-api/tag/Organizations).
625
+ */
626
+ organizations,
627
+ /**
628
+ * Tools for interacting with invitations.
629
+ * This is a wrapper around the `clerkClient.invitations` API.
630
+ * For more information, see the [Clerk API documentation](https://clerk.com/docs/reference/backend-api/tag/Invitations).
631
+ */
632
+ invitations
633
+ };
634
+ var flatTools = {
635
+ ...users,
636
+ ...organizations,
637
+ ...invitations
638
+ };
639
+
640
+ export {
641
+ clerkClient,
642
+ defaultToolkitContext,
643
+ injectSessionClaims,
644
+ shallowTransform,
645
+ tools,
646
+ flatTools
647
+ };
648
+ //# sourceMappingURL=chunk-K5TBM24J.js.map