@knocklabs/agent-toolkit 0.1.7 → 0.1.8

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.
@@ -41,7 +41,7 @@ var listChannels = KnockTool({
41
41
 
42
42
  Use this tool when you need to know about the channels configured in the Knock account, like when configuring a workflow.
43
43
  `,
44
- execute: (knockClient) => async (params) => {
44
+ execute: (knockClient) => async (_params) => {
45
45
  const allChannels = [];
46
46
  for await (const channel of knockClient.channels.list()) {
47
47
  allChannels.push(serializeChannelResponse(channel));
@@ -107,7 +107,7 @@ var promoteAllCommits = KnockTool({
107
107
  parameters: z2.object({
108
108
  toEnvironment: z2.string().describe("(string): The environment to promote all commits to.")
109
109
  }),
110
- execute: (knockClient, config) => async (params) => {
110
+ execute: (knockClient, _config) => async (params) => {
111
111
  return await knockClient.put("/v1/commits/promote", {
112
112
  body: { to_environment: params.toEnvironment }
113
113
  });
@@ -123,8 +123,36 @@ var permissions2 = {
123
123
  manage: ["commitAllChanges", "promoteAllCommits"]
124
124
  };
125
125
 
126
- // src/lib/tools/email-layouts.ts
126
+ // src/lib/tools/documentation.ts
127
127
  import { z as z3 } from "zod";
128
+ var searchDocumentation = KnockTool({
129
+ method: "search_documentation",
130
+ name: "Search documentation",
131
+ description: "Search the Knock documentation for a given query",
132
+ parameters: z3.object({
133
+ query: z3.string().describe("The query to search the documentation for")
134
+ }),
135
+ execute: () => async (params) => {
136
+ const response = await fetch(`https://docs.knock.app/api/search`, {
137
+ method: "POST",
138
+ headers: {
139
+ "Content-Type": "application/json"
140
+ },
141
+ body: JSON.stringify({ query: params.query })
142
+ });
143
+ const data = await response.json();
144
+ return data;
145
+ }
146
+ });
147
+ var documentation = {
148
+ searchDocumentation
149
+ };
150
+ var permissions3 = {
151
+ read: ["searchDocumentation"]
152
+ };
153
+
154
+ // src/lib/tools/email-layouts.ts
155
+ import { z as z4 } from "zod";
128
156
  function serializeEmailLayoutResponse(emailLayout) {
129
157
  return {
130
158
  key: emailLayout.key,
@@ -137,8 +165,8 @@ var listEmailLayouts = KnockTool({
137
165
  description: `List all email layouts within the environment given. Returns information about the email layout, including the name and the key.
138
166
 
139
167
  Use this tool when building a workflow that is building an email notification when you need to know the available email layouts.`,
140
- parameters: z3.object({
141
- environment: z3.string().optional().describe(
168
+ parameters: z4.object({
169
+ environment: z4.string().optional().describe(
142
170
  "(string): The environment to list email layouts for. Defaults to `development`."
143
171
  )
144
172
  }),
@@ -155,7 +183,7 @@ var listEmailLayouts = KnockTool({
155
183
  var emailLayouts = {
156
184
  listEmailLayouts
157
185
  };
158
- var permissions3 = {
186
+ var permissions4 = {
159
187
  read: ["listEmailLayouts"]
160
188
  };
161
189
 
@@ -172,7 +200,7 @@ var listEnvironments = KnockTool({
172
200
  description: `
173
201
  Lists all environments available, returning the slug and name of each environment. Use this tool when you need to see what environments are available.
174
202
  `,
175
- execute: (knockClient) => async (params) => {
203
+ execute: (knockClient) => async (_params) => {
176
204
  const allEnvironments = [];
177
205
  for await (const environment of knockClient.environments.list()) {
178
206
  allEnvironments.push(serializeEnvironmentResponse(environment));
@@ -183,34 +211,8 @@ var listEnvironments = KnockTool({
183
211
  var environments = {
184
212
  listEnvironments
185
213
  };
186
- var permissions4 = {
187
- read: ["listEnvironments"]
188
- };
189
-
190
- // src/lib/tools/messages.ts
191
- import { z as z4 } from "zod";
192
- var getMessageContent = KnockTool({
193
- method: "get_message_content",
194
- name: "Get message content",
195
- description: `
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.
197
- `,
198
- parameters: z4.object({
199
- environment: z4.string().optional().describe(
200
- "(string): The environment to retrieve the message from. Defaults to `development`."
201
- ),
202
- messageId: z4.string().describe("(string): The messageId of the message to retrieve.")
203
- }),
204
- execute: (knockClient) => async (params) => {
205
- const publicClient = await knockClient.publicApi(params.environment);
206
- return await publicClient.messages.getContent(params.messageId);
207
- }
208
- });
209
- var messages = {
210
- getMessageContent
211
- };
212
214
  var permissions5 = {
213
- read: ["getMessageContent"]
215
+ read: ["listEnvironments"]
214
216
  };
215
217
 
216
218
  // src/lib/tools/message-types.ts
@@ -389,19 +391,45 @@ var permissions6 = {
389
391
  manage: ["createOrUpdateMessageType"]
390
392
  };
391
393
 
392
- // src/lib/tools/objects.ts
394
+ // src/lib/tools/messages.ts
393
395
  import { z as z6 } from "zod";
396
+ var getMessageContent = KnockTool({
397
+ method: "get_message_content",
398
+ name: "Get message content",
399
+ description: `
400
+ 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.
401
+ `,
402
+ parameters: z6.object({
403
+ environment: z6.string().optional().describe(
404
+ "(string): The environment to retrieve the message from. Defaults to `development`."
405
+ ),
406
+ messageId: z6.string().describe("(string): The messageId of the message to retrieve.")
407
+ }),
408
+ execute: (knockClient) => async (params) => {
409
+ const publicClient = await knockClient.publicApi(params.environment);
410
+ return await publicClient.messages.getContent(params.messageId);
411
+ }
412
+ });
413
+ var messages = {
414
+ getMessageContent
415
+ };
416
+ var permissions7 = {
417
+ read: ["getMessageContent"]
418
+ };
419
+
420
+ // src/lib/tools/objects.ts
421
+ import { z as z7 } from "zod";
394
422
  var listObjects = KnockTool({
395
423
  method: "list_objects",
396
424
  name: "List objects",
397
425
  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.",
398
- parameters: z6.object({
399
- environment: z6.string().optional().describe(
426
+ parameters: z7.object({
427
+ environment: z7.string().optional().describe(
400
428
  "(string): The environment to list objects from. Defaults to `development`."
401
429
  ),
402
- collection: z6.string().describe("(string): The collection to list objects from.")
430
+ collection: z7.string().describe("(string): The collection to list objects from.")
403
431
  }),
404
- execute: (knockClient, config) => async (params) => {
432
+ execute: (knockClient, _config) => async (params) => {
405
433
  const publicClient = await knockClient.publicApi(params.environment);
406
434
  return await publicClient.objects.list(params.collection);
407
435
  }
@@ -410,14 +438,14 @@ var getObject = KnockTool({
410
438
  method: "get_object",
411
439
  name: "Get object",
412
440
  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.",
413
- parameters: z6.object({
414
- environment: z6.string().optional().describe(
441
+ parameters: z7.object({
442
+ environment: z7.string().optional().describe(
415
443
  "(string): The environment to get the object from. Defaults to `development`."
416
444
  ),
417
- collection: z6.string().describe("(string): The collection to get the object from."),
418
- objectId: z6.string().describe("(string): The ID of the object to get.")
445
+ collection: z7.string().describe("(string): The collection to get the object from."),
446
+ objectId: z7.string().describe("(string): The ID of the object to get.")
419
447
  }),
420
- execute: (knockClient, config) => async (params) => {
448
+ execute: (knockClient, _config) => async (params) => {
421
449
  const publicClient = await knockClient.publicApi(params.environment);
422
450
  return await publicClient.objects.get(params.collection, params.objectId);
423
451
  }
@@ -428,15 +456,15 @@ var createOrUpdateObject = KnockTool({
428
456
  description: `Create or update an object in a specific collection. Objects are used to model custom collections in Knock that are NOT users or tenants. If the object does not exist, it will be created. If the object exists, it will be updated with the provided properties. The update will always perform an upsert operation, so you do not need to provide the full properties each time.
429
457
 
430
458
  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.`,
431
- parameters: z6.object({
432
- environment: z6.string().optional().describe(
459
+ parameters: z7.object({
460
+ environment: z7.string().optional().describe(
433
461
  "(string): The environment to create or update the object in. Defaults to `development`."
434
462
  ),
435
- collection: z6.string().describe("(string): The collection to create or update the object in."),
436
- objectId: z6.string().describe("(string): The ID of the object to create or update."),
437
- properties: z6.record(z6.string(), z6.any()).optional().describe("(object): The properties to set on the object.")
463
+ collection: z7.string().describe("(string): The collection to create or update the object in."),
464
+ objectId: z7.string().describe("(string): The ID of the object to create or update."),
465
+ properties: z7.record(z7.string(), z7.any()).optional().describe("(object): The properties to set on the object.")
438
466
  }),
439
- execute: (knockClient, config) => async (params) => {
467
+ execute: (knockClient, _config) => async (params) => {
440
468
  const publicClient = await knockClient.publicApi(params.environment);
441
469
  return await publicClient.objects.set(
442
470
  params.collection,
@@ -455,13 +483,13 @@ var subscribeUsersToObject = KnockTool({
455
483
 
456
484
  Before using this tool, you should create the object in the collection using the createOrUpdateObject tool.
457
485
  `,
458
- parameters: z6.object({
459
- environment: z6.string().optional().describe(
486
+ parameters: z7.object({
487
+ environment: z7.string().optional().describe(
460
488
  "(string): The environment to subscribe the user to. Defaults to `development`."
461
489
  ),
462
- collection: z6.string().describe("(string): The collection to subscribe the user to."),
463
- objectId: z6.string().describe("(string): The ID of the object to subscribe the user to."),
464
- userIds: z6.array(z6.string()).describe(
490
+ collection: z7.string().describe("(string): The collection to subscribe the user to."),
491
+ objectId: z7.string().describe("(string): The ID of the object to subscribe the user to."),
492
+ userIds: z7.array(z7.string()).describe(
465
493
  "(array): The IDs of the users to subscribe to the object. If not provided, the current user will be subscribed."
466
494
  )
467
495
  }),
@@ -482,13 +510,13 @@ var unsubscribeUsersFromObject = KnockTool({
482
510
  description: `Unsubscribe a list of users from an object in a specific collection. We use this to model lists of users, for pub-sub use cases.
483
511
 
484
512
  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.`,
485
- parameters: z6.object({
486
- environment: z6.string().optional().describe(
513
+ parameters: z7.object({
514
+ environment: z7.string().optional().describe(
487
515
  "(string): The environment to unsubscribe the user from. Defaults to `development`."
488
516
  ),
489
- collection: z6.string().describe("(string): The collection to unsubscribe the user from."),
490
- objectId: z6.string().describe("(string): The ID of the object to unsubscribe the user from."),
491
- userIds: z6.array(z6.string()).describe(
517
+ collection: z7.string().describe("(string): The collection to unsubscribe the user from."),
518
+ objectId: z7.string().describe("(string): The ID of the object to unsubscribe the user from."),
519
+ userIds: z7.array(z7.string()).describe(
492
520
  "(array): The IDs of the users to unsubscribe from the object."
493
521
  )
494
522
  }),
@@ -510,7 +538,7 @@ var objects = {
510
538
  subscribeUsersToObject,
511
539
  unsubscribeUsersFromObject
512
540
  };
513
- var permissions7 = {
541
+ var permissions8 = {
514
542
  read: ["listObjects", "getObject"],
515
543
  manage: [
516
544
  "createOrUpdateObject",
@@ -520,7 +548,7 @@ var permissions7 = {
520
548
  };
521
549
 
522
550
  // src/lib/tools/partials.ts
523
- import { z as z7 } from "zod";
551
+ import { z as z8 } from "zod";
524
552
  function serializePartial(partial) {
525
553
  return {
526
554
  key: partial.key,
@@ -535,8 +563,8 @@ var listPartials = KnockTool({
535
563
  description: `
536
564
  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
565
  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.`,
538
- parameters: z7.object({
539
- environment: z7.string().optional().describe(
566
+ parameters: z8.object({
567
+ environment: z8.string().optional().describe(
540
568
  "(string): The environment to list partials for. Defaults to `development`."
541
569
  )
542
570
  }),
@@ -553,12 +581,12 @@ var listPartials = KnockTool({
553
581
  var partials = {
554
582
  listPartials
555
583
  };
556
- var permissions8 = {
584
+ var permissions9 = {
557
585
  read: ["listPartials"]
558
586
  };
559
587
 
560
588
  // src/lib/tools/tenants.ts
561
- import { z as z8 } from "zod";
589
+ import { z as z9 } from "zod";
562
590
  var getTenant = KnockTool({
563
591
  method: "get_tenant",
564
592
  name: "Get tenant",
@@ -567,11 +595,11 @@ var getTenant = KnockTool({
567
595
 
568
596
  Use this tool when you need to lookup the information about a tenant, including name, and if there are any custom properties set.
569
597
  `,
570
- parameters: z8.object({
571
- environment: z8.string().optional().describe(
598
+ parameters: z9.object({
599
+ environment: z9.string().optional().describe(
572
600
  "(string): The environment to retrieve the tenant from. Defaults to `development`."
573
601
  ),
574
- tenantId: z8.string().describe("(string): The ID of the tenant to retrieve.")
602
+ tenantId: z9.string().describe("(string): The ID of the tenant to retrieve.")
575
603
  }),
576
604
  execute: (knockClient) => async (params) => {
577
605
  const publicClient = await knockClient.publicApi(params.environment);
@@ -586,8 +614,8 @@ var listTenants = KnockTool({
586
614
 
587
615
  Use this tool when you need to list all tenants in an environment.
588
616
  `,
589
- parameters: z8.object({
590
- environment: z8.string().optional().describe(
617
+ parameters: z9.object({
618
+ environment: z9.string().optional().describe(
591
619
  "(string): The environment to retrieve the tenants from. Defaults to `development`."
592
620
  )
593
621
  }),
@@ -604,13 +632,13 @@ var setTenant = KnockTool({
604
632
 
605
633
  Use this tool when you need to create a new tenant, or update an existing tenant's properties.
606
634
  `,
607
- parameters: z8.object({
608
- environment: z8.string().optional().describe(
635
+ parameters: z9.object({
636
+ environment: z9.string().optional().describe(
609
637
  "(string): The environment to set the tenant in. Defaults to `development`."
610
638
  ),
611
- tenantId: z8.string().describe("(string): The ID of the tenant to update."),
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.")
639
+ tenantId: z9.string().describe("(string): The ID of the tenant to update."),
640
+ name: z9.string().optional().describe("(string): The name of the tenant."),
641
+ properties: z9.record(z9.string(), z9.any()).optional().describe("(object): The properties to set on the tenant.")
614
642
  }),
615
643
  execute: (knockClient) => async (params) => {
616
644
  const publicClient = await knockClient.publicApi(params.environment);
@@ -625,13 +653,74 @@ var tenants = {
625
653
  listTenants,
626
654
  setTenant
627
655
  };
628
- var permissions9 = {
656
+ var permissions10 = {
629
657
  read: ["getTenant", "listTenants"],
630
658
  manage: ["setTenant"]
631
659
  };
632
660
 
633
661
  // src/lib/tools/users.ts
634
- import { z as z9 } from "zod";
662
+ import { z as z12 } from "zod";
663
+
664
+ // src/lib/tools/workflows-as-tools.ts
665
+ import jsonSchemaToZod from "json-schema-to-zod";
666
+ import { z as z11 } from "zod";
667
+
668
+ // src/lib/tools/shared.ts
669
+ import { z as z10 } from "zod";
670
+ var recipientSchema = z10.union([
671
+ z10.string().describe("A user ID (string)."),
672
+ z10.object({ id: z10.string(), collection: z10.string() }).describe("A reference to an object in a collection.")
673
+ ]).describe(
674
+ "A recipient can be a user ID or a reference to an object in a collection."
675
+ );
676
+
677
+ // src/lib/tools/workflows-as-tools.ts
678
+ function workflowAsTool(workflow) {
679
+ return KnockTool({
680
+ method: `trigger_${workflow.key.replace("-", "_")}_workflow`,
681
+ name: `Trigger ${workflow.name} workflow`,
682
+ description: `Triggers the ${workflow.name} workflow. Use this tool when you're asked to notify, send, or trigger for ${workflow.name} or ${workflow.key}.
683
+
684
+ ${workflow.description ? `Additional information to consider on when to use this tool: ${workflow.description}` : ""}
685
+
686
+ Returns the workflow run ID, which can be used to lookup messages produced by the workflow.`,
687
+ parameters: z11.object({
688
+ environment: z11.string().optional(),
689
+ actor: recipientSchema.optional().describe("An optional actor to trigger the workflow with."),
690
+ recipients: z11.array(recipientSchema).describe(
691
+ "An optional array of recipients to trigger the workflow with."
692
+ ).optional(),
693
+ // Here we dynamically generate a zod schema from the workflow's `trigger_data_json_schema`
694
+ // This allows us to validate the data passed to the workflow
695
+ data: workflow.trigger_data_json_schema ? eval(jsonSchemaToZod(workflow.trigger_data_json_schema)).describe(
696
+ "The data to pass to the workflow."
697
+ ) : z11.record(z11.string(), z11.any()).optional().describe("The data to pass to the workflow."),
698
+ tenant: z11.string().optional().describe("The tenant ID to trigger the workflow for.")
699
+ }),
700
+ execute: (knockClient, config) => async (params) => {
701
+ const publicClient = await knockClient.publicApi(params.environment);
702
+ const result = await publicClient.workflows.trigger(workflow.key, {
703
+ recipients: [params.userId ?? config.userId],
704
+ actor: params.actor,
705
+ data: params.data,
706
+ tenant: params.tenant ?? config.tenantId
707
+ });
708
+ return result.workflow_run_id;
709
+ }
710
+ });
711
+ }
712
+ async function createWorkflowTools(knockClient, config, workflowKeysToInclude) {
713
+ const workflows2 = [];
714
+ for await (const workflow2 of knockClient.workflows.list({
715
+ environment: config.environment ?? "development"
716
+ })) {
717
+ if (workflowKeysToInclude && !workflowKeysToInclude.includes(workflow2.key)) {
718
+ continue;
719
+ }
720
+ workflows2.push(workflow2);
721
+ }
722
+ return workflows2.map((workflow2) => workflowAsTool(workflow2));
723
+ }
635
724
 
636
725
  // src/lib/utils.ts
637
726
  function filterTools(tools2, pattern) {
@@ -661,7 +750,7 @@ function getToolsWithPermissions(category, categoryPermissions) {
661
750
  const toolPermissionsInCategory = toolPermissions[category];
662
751
  return Object.entries(categoryPermissions).reduce(
663
752
  (acc, [permissionType, hasPermission]) => {
664
- if (hasPermission) {
753
+ if (Array.isArray(hasPermission) && hasPermission.length > 0 || hasPermission === true) {
665
754
  return acc.concat(
666
755
  toolPermissionsInCategory[permissionType].map(
667
756
  (toolName) => toolsInCategory[toolName]
@@ -673,8 +762,8 @@ function getToolsWithPermissions(category, categoryPermissions) {
673
762
  []
674
763
  );
675
764
  }
676
- function getToolsByPermissionsInCategories(config) {
677
- return Object.keys(config.permissions).reduce(
765
+ async function getToolsByPermissionsInCategories(knockClient, config) {
766
+ const toolsByCategory = Object.keys(config.permissions).reduce(
678
767
  (acc, category) => {
679
768
  const categoryKey = category;
680
769
  const categoryPermissions = config.permissions[categoryKey];
@@ -686,6 +775,23 @@ function getToolsByPermissionsInCategories(config) {
686
775
  },
687
776
  {}
688
777
  );
778
+ if (config.permissions.workflows?.run) {
779
+ const workflowTools = await createWorkflowTools(knockClient, config);
780
+ toolsByCategory.workflows = [
781
+ ...toolsByCategory.workflows,
782
+ ...workflowTools
783
+ ];
784
+ }
785
+ return toolsByCategory;
786
+ }
787
+ function getToolMap(tools2) {
788
+ return tools2.reduce(
789
+ (acc, tool) => {
790
+ acc[tool.method] = tool;
791
+ return acc;
792
+ },
793
+ {}
794
+ );
689
795
  }
690
796
  function serializeMessageResponse(message) {
691
797
  return {
@@ -712,11 +818,11 @@ var getUser = KnockTool({
712
818
 
713
819
  If the userId is not provided, it will use the userId from the config.
714
820
  `,
715
- parameters: z9.object({
716
- environment: z9.string().optional().describe(
821
+ parameters: z12.object({
822
+ environment: z12.string().optional().describe(
717
823
  "(string): The environment to retrieve the user from. Defaults to `development`."
718
824
  ),
719
- userId: z9.string().optional().describe("(string): The userId of the User to retrieve.")
825
+ userId: z12.string().optional().describe("(string): The userId of the User to retrieve.")
720
826
  }),
721
827
  execute: (knockClient, config) => async (params) => {
722
828
  const publicClient = await knockClient.publicApi(params.environment);
@@ -734,15 +840,15 @@ var createOrUpdateUser = KnockTool({
734
840
 
735
841
  If the userId is not provided, it will use the userId from the config.
736
842
  `,
737
- parameters: z9.object({
738
- environment: z9.string().optional().describe(
843
+ parameters: z12.object({
844
+ environment: z12.string().optional().describe(
739
845
  "(string): The environment to create or update the user in. Defaults to `development`."
740
846
  ),
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(
847
+ userId: z12.string().optional().describe("(string): The userId of the User to update."),
848
+ email: z12.string().optional().describe("(string): The email of the User to update."),
849
+ name: z12.string().optional().describe("(string): The name of the User to update."),
850
+ phoneNumber: z12.string().optional().describe("(string): The phone number of the User to update."),
851
+ customProperties: z12.record(z12.string(), z12.any()).optional().describe(
746
852
  "(object): A dictionary of custom properties to update for the User."
747
853
  )
748
854
  }),
@@ -768,14 +874,14 @@ var getUserPreferences = KnockTool({
768
874
 
769
875
  If the userId is not provided, it will use the userId from the config.
770
876
  `,
771
- parameters: z9.object({
772
- environment: z9.string().optional().describe(
877
+ parameters: z12.object({
878
+ environment: z12.string().optional().describe(
773
879
  "(string): The environment to retrieve the user preferences from. Defaults to `development`."
774
880
  ),
775
- userId: z9.string().optional().describe(
881
+ userId: z12.string().optional().describe(
776
882
  "(string): The userId of the User to retrieve Preferences for."
777
883
  ),
778
- preferenceSetId: z9.string().optional().describe(
884
+ preferenceSetId: z12.string().optional().describe(
779
885
  "(string): The preferenceSetId of the User to retrieve preferences for. Defaults to `default`."
780
886
  )
781
887
  }),
@@ -824,18 +930,18 @@ var setUserPreferences = KnockTool({
824
930
  </example>
825
931
  </examples>
826
932
  `,
827
- parameters: z9.object({
828
- environment: z9.string().optional().describe(
933
+ parameters: z12.object({
934
+ environment: z12.string().optional().describe(
829
935
  "(string): The environment to set the user preferences in. Defaults to `development`."
830
936
  ),
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(
937
+ userId: z12.string().optional().describe("(string): The userId of the User to update preferences for."),
938
+ workflows: z12.record(z12.string(), z12.any()).optional().describe(
833
939
  "(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."
834
940
  ),
835
- categories: z9.record(z9.string(), z9.any()).optional().describe(
941
+ categories: z12.record(z12.string(), z12.any()).optional().describe(
836
942
  "(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."
837
943
  ),
838
- channel_types: z9.record(z9.string(), z9.boolean()).optional().describe(
944
+ channel_types: z12.record(z12.string(), z12.boolean()).optional().describe(
839
945
  "(object): The channel types to update where the key is the channel type, and the value of the object is a boolean value."
840
946
  )
841
947
  }),
@@ -876,12 +982,12 @@ var getUserMessages = KnockTool({
876
982
 
877
983
  If the userId is not provided, it will use the userId from the config.
878
984
  `,
879
- parameters: z9.object({
880
- environment: z9.string().optional().describe(
985
+ parameters: z12.object({
986
+ environment: z12.string().optional().describe(
881
987
  "(string): The environment to retrieve the user messages from. Defaults to `development`."
882
988
  ),
883
- userId: z9.string().optional().describe("(string): The userId of the User to retrieve messages for."),
884
- workflowRunId: z9.string().optional().describe(
989
+ userId: z12.string().optional().describe("(string): The userId of the User to retrieve messages for."),
990
+ workflowRunId: z12.string().optional().describe(
885
991
  "(string): The workflowRunId of the User to retrieve. Use this when you want to retrieve messages sent from a workflow trigger."
886
992
  )
887
993
  }),
@@ -903,20 +1009,20 @@ var users = {
903
1009
  setUserPreferences,
904
1010
  getUserMessages
905
1011
  };
906
- var permissions10 = {
1012
+ var permissions11 = {
907
1013
  read: ["getUser", "getUserMessages", "getUserPreferences"],
908
1014
  manage: ["createOrUpdateUser", "setUserPreferences"]
909
1015
  };
910
1016
 
911
1017
  // src/lib/tools/workflows.ts
912
- import { z as z10 } from "zod";
913
- function serializeWorkflowResponse(workflow) {
1018
+ import { z as z13 } from "zod";
1019
+ function serializeWorkflowResponse(workflow2) {
914
1020
  return {
915
- key: workflow.key,
916
- name: workflow.name,
917
- description: workflow.description,
918
- categories: workflow.categories,
919
- schema: workflow.trigger_data_json_schema
1021
+ key: workflow2.key,
1022
+ name: workflow2.name,
1023
+ description: workflow2.description,
1024
+ categories: workflow2.categories,
1025
+ schema: workflow2.trigger_data_json_schema
920
1026
  };
921
1027
  }
922
1028
  var listWorkflows = KnockTool({
@@ -927,8 +1033,8 @@ var listWorkflows = KnockTool({
927
1033
 
928
1034
  Use this tool when you need to understand which workflows are available to be called.
929
1035
  `,
930
- parameters: z10.object({
931
- environment: z10.string().optional().describe(
1036
+ parameters: z13.object({
1037
+ environment: z13.string().optional().describe(
932
1038
  "(string): The environment to list workflows for. Defaults to `development`."
933
1039
  )
934
1040
  }),
@@ -937,8 +1043,8 @@ var listWorkflows = KnockTool({
937
1043
  const listParams = {
938
1044
  environment: params.environment ?? config.environment ?? "development"
939
1045
  };
940
- for await (const workflow of knockClient.workflows.list(listParams)) {
941
- allWorkflows.push(serializeWorkflowResponse(workflow));
1046
+ for await (const workflow2 of knockClient.workflows.list(listParams)) {
1047
+ allWorkflows.push(serializeWorkflowResponse(workflow2));
942
1048
  }
943
1049
  return allWorkflows;
944
1050
  }
@@ -949,17 +1055,17 @@ var getWorkflow = KnockTool({
949
1055
  description: `
950
1056
  Get a workflow by key. Returns structural information about the workflow, including the key, name, description, and categories.
951
1057
  `,
952
- parameters: z10.object({
953
- environment: z10.string().optional().describe(
1058
+ parameters: z13.object({
1059
+ environment: z13.string().optional().describe(
954
1060
  "(string): The environment to get the workflow for. Defaults to `development`."
955
1061
  ),
956
- workflowKey: z10.string().describe("(string): The key of the workflow to get.")
1062
+ workflowKey: z13.string().describe("(string): The key of the workflow to get.")
957
1063
  }),
958
1064
  execute: (knockClient, config) => async (params) => {
959
- const workflow = await knockClient.workflows.retrieve(params.workflowKey, {
1065
+ const workflow2 = await knockClient.workflows.retrieve(params.workflowKey, {
960
1066
  environment: params.environment ?? config.environment ?? "development"
961
1067
  });
962
- return serializeWorkflowResponse(workflow);
1068
+ return serializeWorkflowResponse(workflow2);
963
1069
  }
964
1070
  });
965
1071
  var triggerWorkflow = KnockTool({
@@ -968,22 +1074,22 @@ var triggerWorkflow = KnockTool({
968
1074
  description: `
969
1075
  Trigger a workflow for one or more recipients, which may produce one or more messages for each recipient depending on the workflow's steps.
970
1076
 
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.
1077
+ Use this tool when you need to trigger a workflow to send a notification across the channels configured for the workflow.
972
1078
 
973
1079
  When recipients aren't provided, the workflow will be triggered for the current user specified in the config.
974
1080
 
975
1081
  Returns the workflow run ID, which can be used to lookup messages produced by the workflow.
976
1082
  `,
977
- parameters: z10.object({
978
- environment: z10.string().optional().describe(
1083
+ parameters: z13.object({
1084
+ environment: z13.string().optional().describe(
979
1085
  "(string): The environment to trigger the workflow in. Defaults to `development`."
980
1086
  ),
981
- workflowKey: z10.string().describe("(string): The key of the workflow to trigger."),
982
- recipients: z10.array(z10.string()).optional().describe(
1087
+ workflowKey: z13.string().describe("(string): The key of the workflow to trigger."),
1088
+ recipients: z13.array(z13.string()).optional().describe(
983
1089
  "(array): The recipients to trigger the workflow for. This is an array of user IDs."
984
1090
  ),
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(
1091
+ data: z13.record(z13.string(), z13.any()).optional().describe("(object): Data to pass to the workflow."),
1092
+ tenant: z13.record(z13.string(), z13.any()).optional().describe(
987
1093
  "(object): The tenant to trigger the workflow for. Must contain an id if being sent."
988
1094
  )
989
1095
  }),
@@ -1021,15 +1127,15 @@ var createEmailWorkflow = KnockTool({
1021
1127
 
1022
1128
  Once you've created the workflow, you should ask if you should commit the changes to the environment.
1023
1129
  `,
1024
- parameters: z10.object({
1025
- environment: z10.string().optional().describe(
1130
+ parameters: z13.object({
1131
+ environment: z13.string().optional().describe(
1026
1132
  "(string): The environment to create the workflow in. Defaults to `development`."
1027
1133
  ),
1028
- workflowKey: z10.string().describe("(string): The key of the workflow."),
1029
- name: z10.string().describe("(string): The name of the workflow."),
1030
- categories: z10.array(z10.string()).optional().describe("(array): The categories to add to the workflow."),
1031
- subject: z10.string().describe("(string): The subject of the email."),
1032
- body: z10.string().describe("(string): The body of the email.")
1134
+ workflowKey: z13.string().describe("(string): The key of the workflow."),
1135
+ name: z13.string().describe("(string): The name of the workflow."),
1136
+ categories: z13.array(z13.string()).optional().describe("(array): The categories to add to the workflow."),
1137
+ subject: z13.string().describe("(string): The subject of the email."),
1138
+ body: z13.string().describe("(string): The body of the email.")
1033
1139
  }),
1034
1140
  execute: (knockClient, config) => async (params) => {
1035
1141
  const emailChannelsPage = await knockClient.channels.list();
@@ -1088,18 +1194,18 @@ var createOneOffWorkflowSchedule = KnockTool({
1088
1194
  - In one hour, send a password reset email to a user
1089
1195
  - In two weeks, send a survey to a user
1090
1196
  `,
1091
- parameters: z10.object({
1092
- environment: z10.string().optional().describe(
1197
+ parameters: z13.object({
1198
+ environment: z13.string().optional().describe(
1093
1199
  "(string): The environment to create the workflow in. Defaults to `development`."
1094
1200
  ),
1095
- workflowKey: z10.string().describe("(string): The key of the workflow to schedule."),
1096
- userId: z10.string().describe(
1201
+ workflowKey: z13.string().describe("(string): The key of the workflow to schedule."),
1202
+ userId: z13.string().describe(
1097
1203
  "(string): The userId of the user to schedule the workflow for."
1098
1204
  ),
1099
- scheduledAt: z10.string().describe(
1205
+ scheduledAt: z13.string().describe(
1100
1206
  "(string): The date and time to schedule the workflow for. Must be in ISO 8601 format."
1101
1207
  ),
1102
- data: z10.record(z10.string(), z10.any()).optional().describe("(object): Data to pass to the workflow.")
1208
+ data: z13.record(z13.string(), z13.any()).optional().describe("(object): Data to pass to the workflow.")
1103
1209
  }),
1104
1210
  execute: (knockClient, config) => async (params) => {
1105
1211
  const publicClient = await knockClient.publicApi(params.environment);
@@ -1117,40 +1223,12 @@ var workflows = {
1117
1223
  createEmailWorkflow,
1118
1224
  createOneOffWorkflowSchedule
1119
1225
  };
1120
- var permissions11 = {
1226
+ var permissions12 = {
1121
1227
  read: ["listWorkflows", "getWorkflow"],
1122
1228
  manage: ["createEmailWorkflow", "createOneOffWorkflowSchedule"],
1123
1229
  run: ["triggerWorkflow"]
1124
1230
  };
1125
1231
 
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"]
1152
- };
1153
-
1154
1232
  // src/lib/tools/index.ts
1155
1233
  var tools = {
1156
1234
  channels,
@@ -1183,22 +1261,24 @@ var allTools = {
1183
1261
  var toolPermissions = {
1184
1262
  channels: permissions,
1185
1263
  commits: permissions2,
1186
- documentation: permissions12,
1187
- emailLayouts: permissions3,
1188
- environments: permissions4,
1189
- messages: permissions5,
1264
+ documentation: permissions3,
1265
+ emailLayouts: permissions4,
1266
+ environments: permissions5,
1267
+ messages: permissions7,
1190
1268
  messageTypes: permissions6,
1191
- objects: permissions7,
1192
- partials: permissions8,
1193
- tenants: permissions9,
1194
- users: permissions10,
1195
- workflows: permissions11
1269
+ objects: permissions8,
1270
+ partials: permissions9,
1271
+ tenants: permissions10,
1272
+ users: permissions11,
1273
+ workflows: permissions12
1196
1274
  };
1197
1275
 
1198
1276
  export {
1199
1277
  tools,
1200
1278
  allTools,
1279
+ createWorkflowTools,
1201
1280
  filterTools,
1202
- getToolsByPermissionsInCategories
1281
+ getToolsByPermissionsInCategories,
1282
+ getToolMap
1203
1283
  };
1204
- //# sourceMappingURL=chunk-3CUTEODM.js.map
1284
+ //# sourceMappingURL=chunk-JBEVT2QK.js.map