@knocklabs/agent-toolkit 0.1.5 → 0.1.7

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.
@@ -25,18 +25,26 @@ var KnockTool = (args) => {
25
25
  };
26
26
 
27
27
  // src/lib/tools/channels.ts
28
+ function serializeChannelResponse(channel) {
29
+ return {
30
+ key: channel.key,
31
+ name: channel.name,
32
+ type: channel.type,
33
+ provider: channel.provider
34
+ };
35
+ }
28
36
  var listChannels = KnockTool({
29
37
  method: "list_channels",
30
38
  name: "List channels",
31
39
  description: `
32
- Returns a list of all of the channels configured in the account. Each channel returns information about the type of channel it is (email, sms, push, etc), and the provider that's used to power the channel.
40
+ Returns a list of all of the channels configured in the account. Each channel returns information about the type of channel it is (email, sms, push, etc), and the provider that's used to power the channel. Channels can be used across all environments.
33
41
 
34
42
  Use this tool when you need to know about the channels configured in the Knock account, like when configuring a workflow.
35
43
  `,
36
44
  execute: (knockClient) => async (params) => {
37
45
  const allChannels = [];
38
46
  for await (const channel of knockClient.channels.list()) {
39
- allChannels.push(channel);
47
+ allChannels.push(serializeChannelResponse(channel));
40
48
  }
41
49
  return allChannels;
42
50
  }
@@ -57,7 +65,7 @@ var listCommits = KnockTool({
57
65
  Returns all commits available in the environment. Use this tool when you are asked to see what changes are available to be deployed.
58
66
  `,
59
67
  parameters: z2.object({
60
- environment: z2.string().describe(
68
+ environment: z2.string().optional().describe(
61
69
  "(string): The environment to list commits for. Defaults to `development`."
62
70
  ),
63
71
  promoted: z2.boolean().describe(
@@ -75,14 +83,17 @@ var commitAllChanges = KnockTool({
75
83
  method: "commit_all_changes",
76
84
  name: "Commit all changes",
77
85
  description: `
78
- Commit all pending changes to the current environment. Use this tool when you are asked to save all changes to the current environment. This can only be used in the development environment.
86
+ Commit all pending changes. This can only be used in the development environment.
79
87
  `,
80
88
  parameters: z2.object({
81
- message: z2.string().describe("(string): The message to include in the commit.")
89
+ environment: z2.string().optional().describe(
90
+ "(string): The environment to commit all changes to. Defaults to `development`."
91
+ ),
92
+ message: z2.string().optional().describe("(string): The message to include in the commit.")
82
93
  }),
83
94
  execute: (knockClient, config) => async (params) => {
84
95
  return await knockClient.commits.commitAll({
85
- environment: config.environment ?? "development",
96
+ environment: params.environment ?? config.environment ?? "development",
86
97
  commit_message: params.message
87
98
  });
88
99
  }
@@ -91,9 +102,7 @@ var promoteAllCommits = KnockTool({
91
102
  method: "promote_all_commits",
92
103
  name: "Promote all commits",
93
104
  description: `
94
- Promote all commits to the next environment. Use this tool when you are asked to deploy all changes.
95
-
96
- When not specified, the \`toEnvironment\` will default to the environment that comes after the environment specified in the config.
105
+ Promote all commits to the next environment. Use this tool when you are asked to deploy all changes.
97
106
  `,
98
107
  parameters: z2.object({
99
108
  toEnvironment: z2.string().describe("(string): The environment to promote all commits to.")
@@ -116,6 +125,12 @@ var permissions2 = {
116
125
 
117
126
  // src/lib/tools/email-layouts.ts
118
127
  import { z as z3 } from "zod";
128
+ function serializeEmailLayoutResponse(emailLayout) {
129
+ return {
130
+ key: emailLayout.key,
131
+ name: emailLayout.name
132
+ };
133
+ }
119
134
  var listEmailLayouts = KnockTool({
120
135
  method: "list_email_layouts",
121
136
  name: "List email layouts",
@@ -123,7 +138,7 @@ var listEmailLayouts = KnockTool({
123
138
 
124
139
  Use this tool when building a workflow that is building an email notification when you need to know the available email layouts.`,
125
140
  parameters: z3.object({
126
- environment: z3.string().describe(
141
+ environment: z3.string().optional().describe(
127
142
  "(string): The environment to list email layouts for. Defaults to `development`."
128
143
  )
129
144
  }),
@@ -132,7 +147,7 @@ var listEmailLayouts = KnockTool({
132
147
  for await (const emailLayout of knockClient.emailLayouts.list({
133
148
  environment: params.environment ?? config.environment ?? "development"
134
149
  })) {
135
- allEmailLayouts.push(emailLayout);
150
+ allEmailLayouts.push(serializeEmailLayoutResponse(emailLayout));
136
151
  }
137
152
  return allEmailLayouts;
138
153
  }
@@ -145,16 +160,22 @@ var permissions3 = {
145
160
  };
146
161
 
147
162
  // src/lib/tools/environments.ts
163
+ function serializeEnvironmentResponse(environment) {
164
+ return {
165
+ slug: environment.slug,
166
+ name: environment.name
167
+ };
168
+ }
148
169
  var listEnvironments = KnockTool({
149
170
  method: "list_environments",
150
171
  name: "List environments",
151
172
  description: `
152
- Lists all environments available, returning the slug, name, and the order of each environment. Use this tool when you need to see what environments are available to deploy to.
173
+ Lists all environments available, returning the slug and name of each environment. Use this tool when you need to see what environments are available.
153
174
  `,
154
175
  execute: (knockClient) => async (params) => {
155
176
  const allEnvironments = [];
156
177
  for await (const environment of knockClient.environments.list()) {
157
- allEnvironments.push(environment);
178
+ allEnvironments.push(serializeEnvironmentResponse(environment));
158
179
  }
159
180
  return allEnvironments;
160
181
  }
@@ -175,10 +196,13 @@ var getMessageContent = KnockTool({
175
196
  Retrieves the complete contents of a single message, specified by the messageId. The message contents includes the rendered template that was sent to the recipient. Use this tool when you want to surface information about the emails, SMS, and push notifications that were sent to a user.
176
197
  `,
177
198
  parameters: z4.object({
199
+ environment: z4.string().optional().describe(
200
+ "(string): The environment to retrieve the message from. Defaults to `development`."
201
+ ),
178
202
  messageId: z4.string().describe("(string): The messageId of the message to retrieve.")
179
203
  }),
180
204
  execute: (knockClient) => async (params) => {
181
- const publicClient = await knockClient.publicApi();
205
+ const publicClient = await knockClient.publicApi(params.environment);
182
206
  return await publicClient.messages.getContent(params.messageId);
183
207
  }
184
208
  });
@@ -191,12 +215,20 @@ var permissions5 = {
191
215
 
192
216
  // src/lib/tools/message-types.ts
193
217
  import { z as z5 } from "zod";
218
+ function serializeMessageTypeResponse(messageType) {
219
+ return {
220
+ key: messageType.key,
221
+ name: messageType.name,
222
+ description: messageType.description,
223
+ variants: messageType.variants.map((variant) => variant.key)
224
+ };
225
+ }
194
226
  var listMessageTypes = KnockTool({
195
227
  method: "list_message_types",
196
228
  name: "List message types",
197
229
  description: "List all message types available for the environment. Each message type returns the schema, which includes information about the variants and the fields available per-variant. Use this tool when you need to understand the different message types that are available for the environment for use in Guides.",
198
230
  parameters: z5.object({
199
- environment: z5.string().describe(
231
+ environment: z5.string().optional().describe(
200
232
  "(string): The environment to list message types for. Defaults to `development`."
201
233
  )
202
234
  }),
@@ -205,7 +237,7 @@ var listMessageTypes = KnockTool({
205
237
  for await (const messageType of knockClient.messageTypes.list({
206
238
  environment: params.environment ?? config.environment ?? "development"
207
239
  })) {
208
- allMessageTypes.push(messageType);
240
+ allMessageTypes.push(serializeMessageTypeResponse(messageType));
209
241
  }
210
242
  return allMessageTypes;
211
243
  }
@@ -288,26 +320,9 @@ var createOrUpdateMessageType = KnockTool({
288
320
  "value": "warning",
289
321
  "label": "Warning",
290
322
  },
291
- {
292
- "value": "success",
293
- "label": "Success",
294
- },
295
- {
296
- "value": "info",
297
- "label": "Info",
298
- },
299
- {
300
- "value": "error",
301
- "label": "Error",
302
- },
303
323
  ]
304
324
  },
305
325
  },
306
- {
307
- "key": "title",
308
- "type": "text",
309
- "label": "Title",
310
- },
311
326
  {
312
327
  "key": "description",
313
328
  "type": "markdown",
@@ -326,6 +341,9 @@ var createOrUpdateMessageType = KnockTool({
326
341
  </example>
327
342
  `,
328
343
  parameters: z5.object({
344
+ environment: z5.string().optional().describe(
345
+ "(string): The environment to create or update the message type in. Defaults to `development`."
346
+ ),
329
347
  messageTypeKey: z5.string().describe("(string): The key of the message type to create or update."),
330
348
  name: z5.string().describe("(string): The name of the message type."),
331
349
  description: z5.string().optional().describe("(string): The description of the message type."),
@@ -341,10 +359,10 @@ var createOrUpdateMessageType = KnockTool({
341
359
  z5.object({
342
360
  key: z5.string().describe("(string): The key of the field."),
343
361
  type: z5.string().describe(
344
- "(string): The type of the field. One of `text`, `textarea`, `button`, `markdown`, `select`, `multi_select`."
362
+ "(string): The type of the field. One of `text`, `textarea`, `button`, `markdown`, `select`, `multi_select`, `image`."
345
363
  ),
346
364
  label: z5.string().describe("(string): The label of the field."),
347
- settings: z5.object({}).describe("(object): The settings of the field.")
365
+ settings: z5.object({}).optional().describe("(object): The settings of the field.")
348
366
  })
349
367
  ).describe("(array): The fields of the variant.")
350
368
  })
@@ -378,10 +396,13 @@ var listObjects = KnockTool({
378
396
  name: "List objects",
379
397
  description: "List all objects in a single collection. Objects are used to model custom collections in Knock that are NOT users or tenants. Use this tool when you need to return a paginated list of objects in a single collection.",
380
398
  parameters: z6.object({
399
+ environment: z6.string().optional().describe(
400
+ "(string): The environment to list objects from. Defaults to `development`."
401
+ ),
381
402
  collection: z6.string().describe("(string): The collection to list objects from.")
382
403
  }),
383
404
  execute: (knockClient, config) => async (params) => {
384
- const publicClient = await knockClient.publicApi();
405
+ const publicClient = await knockClient.publicApi(params.environment);
385
406
  return await publicClient.objects.list(params.collection);
386
407
  }
387
408
  });
@@ -390,11 +411,14 @@ var getObject = KnockTool({
390
411
  name: "Get object",
391
412
  description: "Get an object wihin a collection. Returns information about the object including any custom properties. Use this tool when you need to retrieve an object to understand it's properties.",
392
413
  parameters: z6.object({
414
+ environment: z6.string().optional().describe(
415
+ "(string): The environment to get the object from. Defaults to `development`."
416
+ ),
393
417
  collection: z6.string().describe("(string): The collection to get the object from."),
394
418
  objectId: z6.string().describe("(string): The ID of the object to get.")
395
419
  }),
396
420
  execute: (knockClient, config) => async (params) => {
397
- const publicClient = await knockClient.publicApi();
421
+ const publicClient = await knockClient.publicApi(params.environment);
398
422
  return await publicClient.objects.get(params.collection, params.objectId);
399
423
  }
400
424
  });
@@ -405,12 +429,15 @@ var createOrUpdateObject = KnockTool({
405
429
 
406
430
  Use this tool when you need to create a new object, or update an existing custom-object. Custom objects can be used to subscribe users' to as lists, and also send non-user facing notifications to.`,
407
431
  parameters: z6.object({
432
+ environment: z6.string().optional().describe(
433
+ "(string): The environment to create or update the object in. Defaults to `development`."
434
+ ),
408
435
  collection: z6.string().describe("(string): The collection to create or update the object in."),
409
436
  objectId: z6.string().describe("(string): The ID of the object to create or update."),
410
- properties: z6.record(z6.string(), z6.any()).describe("(object): The properties to set on the object.")
437
+ properties: z6.record(z6.string(), z6.any()).optional().describe("(object): The properties to set on the object.")
411
438
  }),
412
439
  execute: (knockClient, config) => async (params) => {
413
- const publicClient = await knockClient.publicApi();
440
+ const publicClient = await knockClient.publicApi(params.environment);
414
441
  return await publicClient.objects.set(
415
442
  params.collection,
416
443
  params.objectId,
@@ -418,20 +445,6 @@ var createOrUpdateObject = KnockTool({
418
445
  );
419
446
  }
420
447
  });
421
- var deleteObject = KnockTool({
422
- method: "delete_object",
423
- name: "Delete object",
424
- description: `Delete an object from a specific collection. Use this tool when you need to remove an object from the system.`,
425
- parameters: z6.object({
426
- collection: z6.string().describe("(string): The collection to delete the object from."),
427
- objectId: z6.string().describe("(string): The ID of the object to delete.")
428
- }),
429
- execute: (knockClient, config) => async (params) => {
430
- const publicClient = await knockClient.publicApi();
431
- await publicClient.objects.delete(params.collection, params.objectId);
432
- return { success: true };
433
- }
434
- });
435
448
  var subscribeUsersToObject = KnockTool({
436
449
  method: "subscribe_users_to_object",
437
450
  name: "Subscribe users to object",
@@ -443,6 +456,9 @@ var subscribeUsersToObject = KnockTool({
443
456
  Before using this tool, you should create the object in the collection using the createOrUpdateObject tool.
444
457
  `,
445
458
  parameters: z6.object({
459
+ environment: z6.string().optional().describe(
460
+ "(string): The environment to subscribe the user to. Defaults to `development`."
461
+ ),
446
462
  collection: z6.string().describe("(string): The collection to subscribe the user to."),
447
463
  objectId: z6.string().describe("(string): The ID of the object to subscribe the user to."),
448
464
  userIds: z6.array(z6.string()).describe(
@@ -450,7 +466,7 @@ var subscribeUsersToObject = KnockTool({
450
466
  )
451
467
  }),
452
468
  execute: (knockClient, config) => async (params) => {
453
- const publicClient = await knockClient.publicApi();
469
+ const publicClient = await knockClient.publicApi(params.environment);
454
470
  return await publicClient.objects.addSubscriptions(
455
471
  params.collection,
456
472
  params.objectId,
@@ -467,6 +483,9 @@ var unsubscribeUsersFromObject = KnockTool({
467
483
 
468
484
  Use this tool when you need to unsubscribe one or more users from an object where you will then trigger workflows for those lists of users to send notifications to.`,
469
485
  parameters: z6.object({
486
+ environment: z6.string().optional().describe(
487
+ "(string): The environment to unsubscribe the user from. Defaults to `development`."
488
+ ),
470
489
  collection: z6.string().describe("(string): The collection to unsubscribe the user from."),
471
490
  objectId: z6.string().describe("(string): The ID of the object to unsubscribe the user from."),
472
491
  userIds: z6.array(z6.string()).describe(
@@ -474,7 +493,7 @@ var unsubscribeUsersFromObject = KnockTool({
474
493
  )
475
494
  }),
476
495
  execute: (knockClient, config) => async (params) => {
477
- const publicClient = await knockClient.publicApi();
496
+ const publicClient = await knockClient.publicApi(params.environment);
478
497
  return await publicClient.objects.deleteSubscriptions(
479
498
  params.collection,
480
499
  params.objectId,
@@ -488,7 +507,6 @@ var objects = {
488
507
  listObjects,
489
508
  getObject,
490
509
  createOrUpdateObject,
491
- deleteObject,
492
510
  subscribeUsersToObject,
493
511
  unsubscribeUsersFromObject
494
512
  };
@@ -496,7 +514,6 @@ var permissions7 = {
496
514
  read: ["listObjects", "getObject"],
497
515
  manage: [
498
516
  "createOrUpdateObject",
499
- "deleteObject",
500
517
  "subscribeUsersToObject",
501
518
  "unsubscribeUsersFromObject"
502
519
  ]
@@ -504,14 +521,22 @@ var permissions7 = {
504
521
 
505
522
  // src/lib/tools/partials.ts
506
523
  import { z as z7 } from "zod";
524
+ function serializePartial(partial) {
525
+ return {
526
+ key: partial.key,
527
+ type: partial.type,
528
+ name: partial.name,
529
+ description: partial.description
530
+ };
531
+ }
507
532
  var listPartials = KnockTool({
508
533
  method: "list_partials",
509
534
  name: "List partials",
510
- description: `List all partials within the environment given. Partials provide common building blocks for notification templates. Returns information about the partial, including the name and the key.
511
-
512
- Use this tool when you need to know the available partials for the environment, like when building a notification template and wanting to use a partial to build the template.`,
535
+ description: `
536
+ List all partials within the environment given. Partials provide common building blocks for notification templates. Returns information about the partial, including the name and the key.
537
+ Use this tool when you need to know the available partials for the environment, like when building a notification template and wanting to use a partial to build the template.`,
513
538
  parameters: z7.object({
514
- environment: z7.string().describe(
539
+ environment: z7.string().optional().describe(
515
540
  "(string): The environment to list partials for. Defaults to `development`."
516
541
  )
517
542
  }),
@@ -520,7 +545,7 @@ var listPartials = KnockTool({
520
545
  for await (const partial of knockClient.partials.list({
521
546
  environment: params.environment ?? config.environment ?? "development"
522
547
  })) {
523
- allPartials.push(partial);
548
+ allPartials.push(serializePartial(partial));
524
549
  }
525
550
  return allPartials;
526
551
  }
@@ -543,13 +568,34 @@ var getTenant = KnockTool({
543
568
  Use this tool when you need to lookup the information about a tenant, including name, and if there are any custom properties set.
544
569
  `,
545
570
  parameters: z8.object({
571
+ environment: z8.string().optional().describe(
572
+ "(string): The environment to retrieve the tenant from. Defaults to `development`."
573
+ ),
546
574
  tenantId: z8.string().describe("(string): The ID of the tenant to retrieve.")
547
575
  }),
548
576
  execute: (knockClient) => async (params) => {
549
- const publicClient = await knockClient.publicApi();
577
+ const publicClient = await knockClient.publicApi(params.environment);
550
578
  return await publicClient.tenants.get(params.tenantId);
551
579
  }
552
580
  });
581
+ var listTenants = KnockTool({
582
+ method: "list_tenants",
583
+ name: "List tenants",
584
+ description: `
585
+ Retrieves a list of tenants. Tenants in Knock are used to model organizations, teams, and other groups of users. They are a special type of object.
586
+
587
+ Use this tool when you need to list all tenants in an environment.
588
+ `,
589
+ parameters: z8.object({
590
+ environment: z8.string().optional().describe(
591
+ "(string): The environment to retrieve the tenants from. Defaults to `development`."
592
+ )
593
+ }),
594
+ execute: (knockClient) => async (params) => {
595
+ const publicClient = await knockClient.publicApi(params.environment);
596
+ return await publicClient.tenants.list();
597
+ }
598
+ });
553
599
  var setTenant = KnockTool({
554
600
  method: "set_tenant",
555
601
  name: "Set tenant",
@@ -559,47 +605,105 @@ var setTenant = KnockTool({
559
605
  Use this tool when you need to create a new tenant, or update an existing tenant's properties.
560
606
  `,
561
607
  parameters: z8.object({
608
+ environment: z8.string().optional().describe(
609
+ "(string): The environment to set the tenant in. Defaults to `development`."
610
+ ),
562
611
  tenantId: z8.string().describe("(string): The ID of the tenant to update."),
563
- name: z8.string().describe("(string): The name of the tenant."),
564
- properties: z8.record(z8.string(), z8.any()).describe("(object): The properties to set on the tenant.")
612
+ name: z8.string().optional().describe("(string): The name of the tenant."),
613
+ properties: z8.record(z8.string(), z8.any()).optional().describe("(object): The properties to set on the tenant.")
565
614
  }),
566
615
  execute: (knockClient) => async (params) => {
567
- const publicClient = await knockClient.publicApi();
616
+ const publicClient = await knockClient.publicApi(params.environment);
568
617
  return await publicClient.tenants.set(params.tenantId, {
569
618
  name: params.name,
570
619
  ...params.properties
571
620
  });
572
621
  }
573
622
  });
574
- var deleteTenant = KnockTool({
575
- method: "delete_tenant",
576
- name: "Delete tenant",
577
- description: `
578
- Deletes a tenant. Tenants in Knock are used to model organizations, teams, and other groups of users. They are a special type of object.
579
-
580
- Use this tool when you've been asked to remove a tenant from the system.
581
- `,
582
- parameters: z8.object({
583
- tenantId: z8.string().describe("(string): The ID of the tenant to delete.")
584
- }),
585
- execute: (knockClient) => async (params) => {
586
- const publicClient = await knockClient.publicApi();
587
- await publicClient.tenants.delete(params.tenantId);
588
- return { success: true };
589
- }
590
- });
591
623
  var tenants = {
592
624
  getTenant,
593
- setTenant,
594
- deleteTenant
625
+ listTenants,
626
+ setTenant
595
627
  };
596
628
  var permissions9 = {
597
- read: ["getTenant"],
598
- manage: ["setTenant", "deleteTenant"]
629
+ read: ["getTenant", "listTenants"],
630
+ manage: ["setTenant"]
599
631
  };
600
632
 
601
633
  // src/lib/tools/users.ts
602
634
  import { z as z9 } from "zod";
635
+
636
+ // src/lib/utils.ts
637
+ function filterTools(tools2, pattern) {
638
+ if (!pattern) {
639
+ throw new Error("No pattern provided");
640
+ }
641
+ if (pattern === "*") {
642
+ return Object.values(tools2).flatMap((category2) => Object.values(category2));
643
+ }
644
+ const [category, tool] = pattern.split(".");
645
+ if (category === "*" && tool === "*") {
646
+ return Object.values(tools2).flatMap((category2) => Object.values(category2));
647
+ }
648
+ if (category && !tools2[category]) {
649
+ throw new Error(`Tool category ${category} not found`);
650
+ }
651
+ if (category && tool === "*") {
652
+ return Object.values(tools2[category]);
653
+ }
654
+ if (category && tool && !tools2[category][tool]) {
655
+ throw new Error(`Tool ${pattern} not found`);
656
+ }
657
+ return [tools2[category][tool]];
658
+ }
659
+ function getToolsWithPermissions(category, categoryPermissions) {
660
+ const toolsInCategory = tools[category];
661
+ const toolPermissionsInCategory = toolPermissions[category];
662
+ return Object.entries(categoryPermissions).reduce(
663
+ (acc, [permissionType, hasPermission]) => {
664
+ if (hasPermission) {
665
+ return acc.concat(
666
+ toolPermissionsInCategory[permissionType].map(
667
+ (toolName) => toolsInCategory[toolName]
668
+ )
669
+ );
670
+ }
671
+ return acc;
672
+ },
673
+ []
674
+ );
675
+ }
676
+ function getToolsByPermissionsInCategories(config) {
677
+ return Object.keys(config.permissions).reduce(
678
+ (acc, category) => {
679
+ const categoryKey = category;
680
+ const categoryPermissions = config.permissions[categoryKey];
681
+ if (tools[categoryKey] && categoryPermissions) {
682
+ const tools2 = getToolsWithPermissions(categoryKey, categoryPermissions);
683
+ return { ...acc, [categoryKey]: tools2 };
684
+ }
685
+ return acc;
686
+ },
687
+ {}
688
+ );
689
+ }
690
+ function serializeMessageResponse(message) {
691
+ return {
692
+ id: message.id,
693
+ status: message.status,
694
+ engagement_statuses: message.engagement_statuses,
695
+ data: message.data,
696
+ metadata: message.metadata
697
+ };
698
+ }
699
+
700
+ // src/lib/tools/users.ts
701
+ function maybeHideUserData(user, hideUserData = false) {
702
+ if (hideUserData) {
703
+ return { id: user.id };
704
+ }
705
+ return user;
706
+ }
603
707
  var getUser = KnockTool({
604
708
  method: "get_user",
605
709
  name: "Get user",
@@ -609,11 +713,15 @@ var getUser = KnockTool({
609
713
  If the userId is not provided, it will use the userId from the config.
610
714
  `,
611
715
  parameters: z9.object({
612
- userId: z9.string().describe("(string): The userId of the User to retrieve.")
716
+ environment: z9.string().optional().describe(
717
+ "(string): The environment to retrieve the user from. Defaults to `development`."
718
+ ),
719
+ userId: z9.string().optional().describe("(string): The userId of the User to retrieve.")
613
720
  }),
614
721
  execute: (knockClient, config) => async (params) => {
615
- const publicClient = await knockClient.publicApi();
616
- return await publicClient.users.get(params.userId ?? config.userId);
722
+ const publicClient = await knockClient.publicApi(params.environment);
723
+ const user = await publicClient.users.get(params.userId ?? config.userId);
724
+ return maybeHideUserData(user, config.hideUserData);
617
725
  }
618
726
  });
619
727
  var createOrUpdateUser = KnockTool({
@@ -627,37 +735,29 @@ var createOrUpdateUser = KnockTool({
627
735
  If the userId is not provided, it will use the userId from the config.
628
736
  `,
629
737
  parameters: z9.object({
630
- userId: z9.string().describe("(string): The userId of the User to update."),
631
- email: z9.string().describe("(string): The email of the User to update."),
632
- name: z9.string().describe("(string): The name of the User to update."),
633
- phoneNumber: z9.string().describe("(string): The phone number of the User to update."),
634
- customProperties: z9.record(z9.string(), z9.any()).describe(
738
+ environment: z9.string().optional().describe(
739
+ "(string): The environment to create or update the user in. Defaults to `development`."
740
+ ),
741
+ userId: z9.string().optional().describe("(string): The userId of the User to update."),
742
+ email: z9.string().optional().describe("(string): The email of the User to update."),
743
+ name: z9.string().optional().describe("(string): The name of the User to update."),
744
+ phoneNumber: z9.string().optional().describe("(string): The phone number of the User to update."),
745
+ customProperties: z9.record(z9.string(), z9.any()).optional().describe(
635
746
  "(object): A dictionary of custom properties to update for the User."
636
747
  )
637
748
  }),
638
749
  execute: (knockClient, config) => async (params) => {
639
- const publicClient = await knockClient.publicApi();
640
- return await publicClient.users.identify(params.userId, {
641
- email: params.email,
642
- name: params.name,
643
- phone_number: params.phoneNumber,
644
- ...params.customProperties ?? {}
645
- });
646
- }
647
- });
648
- var deleteUser = KnockTool({
649
- method: "delete_user",
650
- name: "Delete user",
651
- description: `
652
- Deletes a user. Use this tool when you've been asked to remove a user from the system.
653
- `,
654
- parameters: z9.object({
655
- userId: z9.string().describe("(string): The userId of the User to delete.")
656
- }),
657
- execute: (knockClient, config) => async (params) => {
658
- const publicClient = await knockClient.publicApi();
659
- await publicClient.users.delete(params.userId);
660
- return { success: true };
750
+ const publicClient = await knockClient.publicApi(params.environment);
751
+ const user = await publicClient.users.identify(
752
+ params.userId ?? config.userId,
753
+ {
754
+ email: params.email,
755
+ name: params.name,
756
+ phone_number: params.phoneNumber,
757
+ ...params.customProperties ?? {}
758
+ }
759
+ );
760
+ return maybeHideUserData(user, config.hideUserData);
661
761
  }
662
762
  });
663
763
  var getUserPreferences = KnockTool({
@@ -669,15 +769,18 @@ var getUserPreferences = KnockTool({
669
769
  If the userId is not provided, it will use the userId from the config.
670
770
  `,
671
771
  parameters: z9.object({
672
- userId: z9.string().describe(
772
+ environment: z9.string().optional().describe(
773
+ "(string): The environment to retrieve the user preferences from. Defaults to `development`."
774
+ ),
775
+ userId: z9.string().optional().describe(
673
776
  "(string): The userId of the User to retrieve Preferences for."
674
777
  ),
675
- preferenceSetId: z9.string().describe(
778
+ preferenceSetId: z9.string().optional().describe(
676
779
  "(string): The preferenceSetId of the User to retrieve preferences for. Defaults to `default`."
677
780
  )
678
781
  }),
679
782
  execute: (knockClient, config) => async (params) => {
680
- const publicClient = await knockClient.publicApi();
783
+ const publicClient = await knockClient.publicApi(params.environment);
681
784
  return await publicClient.users.getPreferences(
682
785
  params.userId ?? config.userId,
683
786
  {
@@ -722,19 +825,22 @@ var setUserPreferences = KnockTool({
722
825
  </examples>
723
826
  `,
724
827
  parameters: z9.object({
725
- userId: z9.string().describe("(string): The userId of the User to update preferences for."),
726
- workflows: z9.record(z9.string(), z9.any()).describe(
828
+ environment: z9.string().optional().describe(
829
+ "(string): The environment to set the user preferences in. Defaults to `development`."
830
+ ),
831
+ userId: z9.string().optional().describe("(string): The userId of the User to update preferences for."),
832
+ workflows: z9.record(z9.string(), z9.any()).optional().describe(
727
833
  "(object): The workflows to update where the key is the workflow key, and the value of the object is an object that contains a `channel_types` key with a boolean value for each channel type."
728
834
  ),
729
- categories: z9.record(z9.string(), z9.any()).describe(
835
+ categories: z9.record(z9.string(), z9.any()).optional().describe(
730
836
  "(object): The categories to update where the key is the category key, and the value of the object is an object that contains a `channel_types` key with a boolean value for each channel type."
731
837
  ),
732
- channel_types: z9.record(z9.string(), z9.boolean()).describe(
838
+ channel_types: z9.record(z9.string(), z9.boolean()).optional().describe(
733
839
  "(object): The channel types to update where the key is the channel type, and the value of the object is a boolean value."
734
840
  )
735
841
  }),
736
842
  execute: (knockClient, config) => async (params) => {
737
- const publicClient = await knockClient.publicApi();
843
+ const publicClient = await knockClient.publicApi(params.environment);
738
844
  const existingPreferences = await publicClient.users.getPreferences(
739
845
  params.userId ?? config.userId,
740
846
  {
@@ -771,46 +877,58 @@ var getUserMessages = KnockTool({
771
877
  If the userId is not provided, it will use the userId from the config.
772
878
  `,
773
879
  parameters: z9.object({
774
- userId: z9.string().describe("(string): The userId of the User to retrieve messages for."),
775
- workflowRunId: z9.string().describe(
880
+ environment: z9.string().optional().describe(
881
+ "(string): The environment to retrieve the user messages from. Defaults to `development`."
882
+ ),
883
+ userId: z9.string().optional().describe("(string): The userId of the User to retrieve messages for."),
884
+ workflowRunId: z9.string().optional().describe(
776
885
  "(string): The workflowRunId of the User to retrieve. Use this when you want to retrieve messages sent from a workflow trigger."
777
886
  )
778
887
  }),
779
888
  execute: (knockClient, config) => async (params) => {
780
- const publicClient = await knockClient.publicApi();
781
- return await publicClient.users.getMessages(
889
+ const publicClient = await knockClient.publicApi(params.environment);
890
+ const messages2 = await publicClient.users.getMessages(
782
891
  params.userId ?? config.userId,
783
892
  {
784
893
  workflow_run_id: params.workflowRunId
785
894
  }
786
895
  );
896
+ return messages2.items.map(serializeMessageResponse);
787
897
  }
788
898
  });
789
899
  var users = {
790
900
  getUser,
791
- deleteUser,
792
901
  createOrUpdateUser,
793
902
  getUserPreferences,
794
903
  setUserPreferences,
795
904
  getUserMessages
796
905
  };
797
906
  var permissions10 = {
798
- read: ["getUser", "getUserPreferences", "getUserMessages"],
799
- manage: ["createOrUpdateUser", "deleteUser", "setUserPreferences"]
907
+ read: ["getUser", "getUserMessages", "getUserPreferences"],
908
+ manage: ["createOrUpdateUser", "setUserPreferences"]
800
909
  };
801
910
 
802
911
  // src/lib/tools/workflows.ts
803
912
  import { z as z10 } from "zod";
913
+ function serializeWorkflowResponse(workflow) {
914
+ return {
915
+ key: workflow.key,
916
+ name: workflow.name,
917
+ description: workflow.description,
918
+ categories: workflow.categories,
919
+ schema: workflow.trigger_data_json_schema
920
+ };
921
+ }
804
922
  var listWorkflows = KnockTool({
805
923
  method: "list_workflows",
806
924
  name: "List workflows",
807
925
  description: `
808
- List all workflows available for the given environment. Returns structural information about the workflows, including the key, name, description, and categories. Will also return the steps that make up the workflow.
926
+ List all workflows available for the given environment. Returns structural information about the workflows, including the key, name, description, and categories.
809
927
 
810
- Use this tool when you need to understand which workflows are available to be called.
928
+ Use this tool when you need to understand which workflows are available to be called.
811
929
  `,
812
930
  parameters: z10.object({
813
- environment: z10.string().describe(
931
+ environment: z10.string().optional().describe(
814
932
  "(string): The environment to list workflows for. Defaults to `development`."
815
933
  )
816
934
  }),
@@ -820,35 +938,61 @@ var listWorkflows = KnockTool({
820
938
  environment: params.environment ?? config.environment ?? "development"
821
939
  };
822
940
  for await (const workflow of knockClient.workflows.list(listParams)) {
823
- allWorkflows.push(workflow);
941
+ allWorkflows.push(serializeWorkflowResponse(workflow));
824
942
  }
825
943
  return allWorkflows;
826
944
  }
827
945
  });
946
+ var getWorkflow = KnockTool({
947
+ method: "get_workflow",
948
+ name: "Get workflow",
949
+ description: `
950
+ Get a workflow by key. Returns structural information about the workflow, including the key, name, description, and categories.
951
+ `,
952
+ parameters: z10.object({
953
+ environment: z10.string().optional().describe(
954
+ "(string): The environment to get the workflow for. Defaults to `development`."
955
+ ),
956
+ workflowKey: z10.string().describe("(string): The key of the workflow to get.")
957
+ }),
958
+ execute: (knockClient, config) => async (params) => {
959
+ const workflow = await knockClient.workflows.retrieve(params.workflowKey, {
960
+ environment: params.environment ?? config.environment ?? "development"
961
+ });
962
+ return serializeWorkflowResponse(workflow);
963
+ }
964
+ });
828
965
  var triggerWorkflow = KnockTool({
829
966
  method: "trigger_workflow",
830
967
  name: "Trigger workflow",
831
968
  description: `
832
- Trigger a workflow for one or more recipients.
969
+ Trigger a workflow for one or more recipients, which may produce one or more messages for each recipient depending on the workflow's steps.
833
970
 
834
971
  Use this tool when you need to trigger a workflow to send a notification across the channels configured for the workflow. The workflow must be committed in the environment for you to trigger it.
835
972
 
836
973
  When recipients aren't provided, the workflow will be triggered for the current user specified in the config.
974
+
975
+ Returns the workflow run ID, which can be used to lookup messages produced by the workflow.
837
976
  `,
838
977
  parameters: z10.object({
978
+ environment: z10.string().optional().describe(
979
+ "(string): The environment to trigger the workflow in. Defaults to `development`."
980
+ ),
839
981
  workflowKey: z10.string().describe("(string): The key of the workflow to trigger."),
840
- recipients: z10.array(z10.string()).describe("(array): The recipients to trigger the workflow for."),
841
- data: z10.record(z10.string(), z10.any()).describe("(object): Data to pass to the workflow."),
842
- tenant: z10.record(z10.string(), z10.any()).describe(
982
+ recipients: z10.array(z10.string()).optional().describe(
983
+ "(array): The recipients to trigger the workflow for. This is an array of user IDs."
984
+ ),
985
+ data: z10.record(z10.string(), z10.any()).optional().describe("(object): Data to pass to the workflow."),
986
+ tenant: z10.record(z10.string(), z10.any()).optional().describe(
843
987
  "(object): The tenant to trigger the workflow for. Must contain an id if being sent."
844
988
  )
845
989
  }),
846
990
  execute: (knockClient, config) => async (params) => {
847
- const publicClient = await knockClient.publicApi();
991
+ const publicClient = await knockClient.publicApi(params.environment);
848
992
  const result = await publicClient.workflows.trigger(params.workflowKey, {
849
- recipients: params.recipients,
993
+ recipients: params.recipients ?? [config.userId] ?? [],
850
994
  data: params.data,
851
- tenant: params.tenant
995
+ tenant: params.tenant ?? config.tenantId
852
996
  });
853
997
  return result.workflow_run_id;
854
998
  }
@@ -878,12 +1022,12 @@ var createEmailWorkflow = KnockTool({
878
1022
  Once you've created the workflow, you should ask if you should commit the changes to the environment.
879
1023
  `,
880
1024
  parameters: z10.object({
881
- environment: z10.string().describe(
1025
+ environment: z10.string().optional().describe(
882
1026
  "(string): The environment to create the workflow in. Defaults to `development`."
883
1027
  ),
884
1028
  workflowKey: z10.string().describe("(string): The key of the workflow."),
885
1029
  name: z10.string().describe("(string): The name of the workflow."),
886
- categories: z10.array(z10.string()).describe("(array): The categories to add to the workflow."),
1030
+ categories: z10.array(z10.string()).optional().describe("(array): The categories to add to the workflow."),
887
1031
  subject: z10.string().describe("(string): The subject of the email."),
888
1032
  body: z10.string().describe("(string): The body of the email.")
889
1033
  }),
@@ -923,10 +1067,11 @@ var createEmailWorkflow = KnockTool({
923
1067
  ]
924
1068
  }
925
1069
  };
926
- return await knockClient.workflows.upsert(
1070
+ const result = await knockClient.workflows.upsert(
927
1071
  params.workflowKey,
928
1072
  workflowParams
929
1073
  );
1074
+ return serializeWorkflowResponse(result.workflow);
930
1075
  }
931
1076
  });
932
1077
  var createOneOffWorkflowSchedule = KnockTool({
@@ -944,6 +1089,9 @@ var createOneOffWorkflowSchedule = KnockTool({
944
1089
  - In two weeks, send a survey to a user
945
1090
  `,
946
1091
  parameters: z10.object({
1092
+ environment: z10.string().optional().describe(
1093
+ "(string): The environment to create the workflow in. Defaults to `development`."
1094
+ ),
947
1095
  workflowKey: z10.string().describe("(string): The key of the workflow to schedule."),
948
1096
  userId: z10.string().describe(
949
1097
  "(string): The userId of the user to schedule the workflow for."
@@ -951,10 +1099,10 @@ var createOneOffWorkflowSchedule = KnockTool({
951
1099
  scheduledAt: z10.string().describe(
952
1100
  "(string): The date and time to schedule the workflow for. Must be in ISO 8601 format."
953
1101
  ),
954
- data: z10.record(z10.string(), z10.any()).describe("(object): Data to pass to the workflow.")
1102
+ data: z10.record(z10.string(), z10.any()).optional().describe("(object): Data to pass to the workflow.")
955
1103
  }),
956
1104
  execute: (knockClient, config) => async (params) => {
957
- const publicClient = await knockClient.publicApi();
1105
+ const publicClient = await knockClient.publicApi(params.environment);
958
1106
  return await publicClient.workflows.createSchedules(params.workflowKey, {
959
1107
  recipients: [params.userId ?? config.userId],
960
1108
  scheduled_at: params.scheduledAt,
@@ -964,20 +1112,50 @@ var createOneOffWorkflowSchedule = KnockTool({
964
1112
  });
965
1113
  var workflows = {
966
1114
  listWorkflows,
1115
+ getWorkflow,
967
1116
  triggerWorkflow,
968
1117
  createEmailWorkflow,
969
1118
  createOneOffWorkflowSchedule
970
1119
  };
971
1120
  var permissions11 = {
972
- read: ["listWorkflows"],
1121
+ read: ["listWorkflows", "getWorkflow"],
973
1122
  manage: ["createEmailWorkflow", "createOneOffWorkflowSchedule"],
974
- trigger: ["triggerWorkflow"]
1123
+ run: ["triggerWorkflow"]
1124
+ };
1125
+
1126
+ // src/lib/tools/documentation.ts
1127
+ import { z as z11 } from "zod";
1128
+ var searchDocumentation = KnockTool({
1129
+ method: "search_documentation",
1130
+ name: "Search documentation",
1131
+ description: "Search the Knock documentation for a given query",
1132
+ parameters: z11.object({
1133
+ query: z11.string().describe("The query to search the documentation for")
1134
+ }),
1135
+ execute: () => async (params) => {
1136
+ const response = await fetch(`https://docs.knock.app/api/search`, {
1137
+ method: "POST",
1138
+ headers: {
1139
+ "Content-Type": "application/json"
1140
+ },
1141
+ body: JSON.stringify({ query: params.query })
1142
+ });
1143
+ const data = await response.json();
1144
+ return data;
1145
+ }
1146
+ });
1147
+ var documentation = {
1148
+ searchDocumentation
1149
+ };
1150
+ var permissions12 = {
1151
+ read: ["searchDocumentation"]
975
1152
  };
976
1153
 
977
1154
  // src/lib/tools/index.ts
978
1155
  var tools = {
979
1156
  channels,
980
1157
  commits,
1158
+ documentation,
981
1159
  emailLayouts,
982
1160
  environments,
983
1161
  messages,
@@ -991,6 +1169,7 @@ var tools = {
991
1169
  var allTools = {
992
1170
  ...channels,
993
1171
  ...commits,
1172
+ ...documentation,
994
1173
  ...emailLayouts,
995
1174
  ...environments,
996
1175
  ...messageTypes,
@@ -1004,6 +1183,7 @@ var allTools = {
1004
1183
  var toolPermissions = {
1005
1184
  channels: permissions,
1006
1185
  commits: permissions2,
1186
+ documentation: permissions12,
1007
1187
  emailLayouts: permissions3,
1008
1188
  environments: permissions4,
1009
1189
  messages: permissions5,
@@ -1018,6 +1198,7 @@ var toolPermissions = {
1018
1198
  export {
1019
1199
  tools,
1020
1200
  allTools,
1021
- toolPermissions
1201
+ filterTools,
1202
+ getToolsByPermissionsInCategories
1022
1203
  };
1023
- //# sourceMappingURL=chunk-RPKDXX4O.js.map
1204
+ //# sourceMappingURL=chunk-3CUTEODM.js.map