@knocklabs/agent-toolkit 0.1.6 → 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.
@@ -25,6 +25,14 @@ 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",
@@ -33,10 +41,10 @@ var listChannels = KnockTool({
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
- execute: (knockClient) => async (params) => {
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
  }
@@ -99,7 +107,7 @@ var promoteAllCommits = KnockTool({
99
107
  parameters: z2.object({
100
108
  toEnvironment: z2.string().describe("(string): The environment to promote all commits to.")
101
109
  }),
102
- execute: (knockClient, config) => async (params) => {
110
+ execute: (knockClient, _config) => async (params) => {
103
111
  return await knockClient.put("/v1/commits/promote", {
104
112
  body: { to_environment: params.toEnvironment }
105
113
  });
@@ -115,16 +123,50 @@ var permissions2 = {
115
123
  manage: ["commitAllChanges", "promoteAllCommits"]
116
124
  };
117
125
 
118
- // src/lib/tools/email-layouts.ts
126
+ // src/lib/tools/documentation.ts
119
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";
156
+ function serializeEmailLayoutResponse(emailLayout) {
157
+ return {
158
+ key: emailLayout.key,
159
+ name: emailLayout.name
160
+ };
161
+ }
120
162
  var listEmailLayouts = KnockTool({
121
163
  method: "list_email_layouts",
122
164
  name: "List email layouts",
123
165
  description: `List all email layouts within the environment given. Returns information about the email layout, including the name and the key.
124
166
 
125
167
  Use this tool when building a workflow that is building an email notification when you need to know the available email layouts.`,
126
- parameters: z3.object({
127
- environment: z3.string().optional().describe(
168
+ parameters: z4.object({
169
+ environment: z4.string().optional().describe(
128
170
  "(string): The environment to list email layouts for. Defaults to `development`."
129
171
  )
130
172
  }),
@@ -133,7 +175,7 @@ var listEmailLayouts = KnockTool({
133
175
  for await (const emailLayout of knockClient.emailLayouts.list({
134
176
  environment: params.environment ?? config.environment ?? "development"
135
177
  })) {
136
- allEmailLayouts.push(emailLayout);
178
+ allEmailLayouts.push(serializeEmailLayoutResponse(emailLayout));
137
179
  }
138
180
  return allEmailLayouts;
139
181
  }
@@ -141,21 +183,27 @@ var listEmailLayouts = KnockTool({
141
183
  var emailLayouts = {
142
184
  listEmailLayouts
143
185
  };
144
- var permissions3 = {
186
+ var permissions4 = {
145
187
  read: ["listEmailLayouts"]
146
188
  };
147
189
 
148
190
  // src/lib/tools/environments.ts
191
+ function serializeEnvironmentResponse(environment) {
192
+ return {
193
+ slug: environment.slug,
194
+ name: environment.name
195
+ };
196
+ }
149
197
  var listEnvironments = KnockTool({
150
198
  method: "list_environments",
151
199
  name: "List environments",
152
200
  description: `
153
- 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.
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.
154
202
  `,
155
- execute: (knockClient) => async (params) => {
203
+ execute: (knockClient) => async (_params) => {
156
204
  const allEnvironments = [];
157
205
  for await (const environment of knockClient.environments.list()) {
158
- allEnvironments.push(environment);
206
+ allEnvironments.push(serializeEnvironmentResponse(environment));
159
207
  }
160
208
  return allEnvironments;
161
209
  }
@@ -163,38 +211,20 @@ var listEnvironments = KnockTool({
163
211
  var environments = {
164
212
  listEnvironments
165
213
  };
166
- var permissions4 = {
167
- read: ["listEnvironments"]
168
- };
169
-
170
- // src/lib/tools/messages.ts
171
- import { z as z4 } from "zod";
172
- var getMessageContent = KnockTool({
173
- method: "get_message_content",
174
- name: "Get message content",
175
- description: `
176
- 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.
177
- `,
178
- parameters: z4.object({
179
- environment: z4.string().optional().describe(
180
- "(string): The environment to retrieve the message from. Defaults to `development`."
181
- ),
182
- messageId: z4.string().describe("(string): The messageId of the message to retrieve.")
183
- }),
184
- execute: (knockClient) => async (params) => {
185
- const publicClient = await knockClient.publicApi(params.environment);
186
- return await publicClient.messages.getContent(params.messageId);
187
- }
188
- });
189
- var messages = {
190
- getMessageContent
191
- };
192
214
  var permissions5 = {
193
- read: ["getMessageContent"]
215
+ read: ["listEnvironments"]
194
216
  };
195
217
 
196
218
  // src/lib/tools/message-types.ts
197
219
  import { z as z5 } from "zod";
220
+ function serializeMessageTypeResponse(messageType) {
221
+ return {
222
+ key: messageType.key,
223
+ name: messageType.name,
224
+ description: messageType.description,
225
+ variants: messageType.variants.map((variant) => variant.key)
226
+ };
227
+ }
198
228
  var listMessageTypes = KnockTool({
199
229
  method: "list_message_types",
200
230
  name: "List message types",
@@ -209,7 +239,7 @@ var listMessageTypes = KnockTool({
209
239
  for await (const messageType of knockClient.messageTypes.list({
210
240
  environment: params.environment ?? config.environment ?? "development"
211
241
  })) {
212
- allMessageTypes.push(messageType);
242
+ allMessageTypes.push(serializeMessageTypeResponse(messageType));
213
243
  }
214
244
  return allMessageTypes;
215
245
  }
@@ -361,19 +391,45 @@ var permissions6 = {
361
391
  manage: ["createOrUpdateMessageType"]
362
392
  };
363
393
 
364
- // src/lib/tools/objects.ts
394
+ // src/lib/tools/messages.ts
365
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";
366
422
  var listObjects = KnockTool({
367
423
  method: "list_objects",
368
424
  name: "List objects",
369
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.",
370
- parameters: z6.object({
371
- environment: z6.string().optional().describe(
426
+ parameters: z7.object({
427
+ environment: z7.string().optional().describe(
372
428
  "(string): The environment to list objects from. Defaults to `development`."
373
429
  ),
374
- collection: z6.string().describe("(string): The collection to list objects from.")
430
+ collection: z7.string().describe("(string): The collection to list objects from.")
375
431
  }),
376
- execute: (knockClient, config) => async (params) => {
432
+ execute: (knockClient, _config) => async (params) => {
377
433
  const publicClient = await knockClient.publicApi(params.environment);
378
434
  return await publicClient.objects.list(params.collection);
379
435
  }
@@ -382,14 +438,14 @@ var getObject = KnockTool({
382
438
  method: "get_object",
383
439
  name: "Get object",
384
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.",
385
- parameters: z6.object({
386
- environment: z6.string().optional().describe(
441
+ parameters: z7.object({
442
+ environment: z7.string().optional().describe(
387
443
  "(string): The environment to get the object from. Defaults to `development`."
388
444
  ),
389
- collection: z6.string().describe("(string): The collection to get the object from."),
390
- 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.")
391
447
  }),
392
- execute: (knockClient, config) => async (params) => {
448
+ execute: (knockClient, _config) => async (params) => {
393
449
  const publicClient = await knockClient.publicApi(params.environment);
394
450
  return await publicClient.objects.get(params.collection, params.objectId);
395
451
  }
@@ -400,15 +456,15 @@ var createOrUpdateObject = KnockTool({
400
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.
401
457
 
402
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.`,
403
- parameters: z6.object({
404
- environment: z6.string().optional().describe(
459
+ parameters: z7.object({
460
+ environment: z7.string().optional().describe(
405
461
  "(string): The environment to create or update the object in. Defaults to `development`."
406
462
  ),
407
- collection: z6.string().describe("(string): The collection to create or update the object in."),
408
- objectId: z6.string().describe("(string): The ID of the object to create or update."),
409
- 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.")
410
466
  }),
411
- execute: (knockClient, config) => async (params) => {
467
+ execute: (knockClient, _config) => async (params) => {
412
468
  const publicClient = await knockClient.publicApi(params.environment);
413
469
  return await publicClient.objects.set(
414
470
  params.collection,
@@ -427,13 +483,13 @@ var subscribeUsersToObject = KnockTool({
427
483
 
428
484
  Before using this tool, you should create the object in the collection using the createOrUpdateObject tool.
429
485
  `,
430
- parameters: z6.object({
431
- environment: z6.string().optional().describe(
486
+ parameters: z7.object({
487
+ environment: z7.string().optional().describe(
432
488
  "(string): The environment to subscribe the user to. Defaults to `development`."
433
489
  ),
434
- collection: z6.string().describe("(string): The collection to subscribe the user to."),
435
- objectId: z6.string().describe("(string): The ID of the object to subscribe the user to."),
436
- 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(
437
493
  "(array): The IDs of the users to subscribe to the object. If not provided, the current user will be subscribed."
438
494
  )
439
495
  }),
@@ -454,13 +510,13 @@ var unsubscribeUsersFromObject = KnockTool({
454
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.
455
511
 
456
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.`,
457
- parameters: z6.object({
458
- environment: z6.string().optional().describe(
513
+ parameters: z7.object({
514
+ environment: z7.string().optional().describe(
459
515
  "(string): The environment to unsubscribe the user from. Defaults to `development`."
460
516
  ),
461
- collection: z6.string().describe("(string): The collection to unsubscribe the user from."),
462
- objectId: z6.string().describe("(string): The ID of the object to unsubscribe the user from."),
463
- 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(
464
520
  "(array): The IDs of the users to unsubscribe from the object."
465
521
  )
466
522
  }),
@@ -482,7 +538,7 @@ var objects = {
482
538
  subscribeUsersToObject,
483
539
  unsubscribeUsersFromObject
484
540
  };
485
- var permissions7 = {
541
+ var permissions8 = {
486
542
  read: ["listObjects", "getObject"],
487
543
  manage: [
488
544
  "createOrUpdateObject",
@@ -492,15 +548,23 @@ var permissions7 = {
492
548
  };
493
549
 
494
550
  // src/lib/tools/partials.ts
495
- import { z as z7 } from "zod";
551
+ import { z as z8 } from "zod";
552
+ function serializePartial(partial) {
553
+ return {
554
+ key: partial.key,
555
+ type: partial.type,
556
+ name: partial.name,
557
+ description: partial.description
558
+ };
559
+ }
496
560
  var listPartials = KnockTool({
497
561
  method: "list_partials",
498
562
  name: "List partials",
499
563
  description: `
500
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.
501
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.`,
502
- parameters: z7.object({
503
- environment: z7.string().optional().describe(
566
+ parameters: z8.object({
567
+ environment: z8.string().optional().describe(
504
568
  "(string): The environment to list partials for. Defaults to `development`."
505
569
  )
506
570
  }),
@@ -509,7 +573,7 @@ var listPartials = KnockTool({
509
573
  for await (const partial of knockClient.partials.list({
510
574
  environment: params.environment ?? config.environment ?? "development"
511
575
  })) {
512
- allPartials.push(partial);
576
+ allPartials.push(serializePartial(partial));
513
577
  }
514
578
  return allPartials;
515
579
  }
@@ -517,12 +581,12 @@ var listPartials = KnockTool({
517
581
  var partials = {
518
582
  listPartials
519
583
  };
520
- var permissions8 = {
584
+ var permissions9 = {
521
585
  read: ["listPartials"]
522
586
  };
523
587
 
524
588
  // src/lib/tools/tenants.ts
525
- import { z as z8 } from "zod";
589
+ import { z as z9 } from "zod";
526
590
  var getTenant = KnockTool({
527
591
  method: "get_tenant",
528
592
  name: "Get tenant",
@@ -531,11 +595,11 @@ var getTenant = KnockTool({
531
595
 
532
596
  Use this tool when you need to lookup the information about a tenant, including name, and if there are any custom properties set.
533
597
  `,
534
- parameters: z8.object({
535
- environment: z8.string().optional().describe(
598
+ parameters: z9.object({
599
+ environment: z9.string().optional().describe(
536
600
  "(string): The environment to retrieve the tenant from. Defaults to `development`."
537
601
  ),
538
- 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.")
539
603
  }),
540
604
  execute: (knockClient) => async (params) => {
541
605
  const publicClient = await knockClient.publicApi(params.environment);
@@ -550,8 +614,8 @@ var listTenants = KnockTool({
550
614
 
551
615
  Use this tool when you need to list all tenants in an environment.
552
616
  `,
553
- parameters: z8.object({
554
- environment: z8.string().optional().describe(
617
+ parameters: z9.object({
618
+ environment: z9.string().optional().describe(
555
619
  "(string): The environment to retrieve the tenants from. Defaults to `development`."
556
620
  )
557
621
  }),
@@ -568,13 +632,13 @@ var setTenant = KnockTool({
568
632
 
569
633
  Use this tool when you need to create a new tenant, or update an existing tenant's properties.
570
634
  `,
571
- parameters: z8.object({
572
- environment: z8.string().optional().describe(
635
+ parameters: z9.object({
636
+ environment: z9.string().optional().describe(
573
637
  "(string): The environment to set the tenant in. Defaults to `development`."
574
638
  ),
575
- tenantId: z8.string().describe("(string): The ID of the tenant to update."),
576
- name: z8.string().optional().describe("(string): The name of the tenant."),
577
- 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.")
578
642
  }),
579
643
  execute: (knockClient) => async (params) => {
580
644
  const publicClient = await knockClient.publicApi(params.environment);
@@ -589,13 +653,163 @@ var tenants = {
589
653
  listTenants,
590
654
  setTenant
591
655
  };
592
- var permissions9 = {
656
+ var permissions10 = {
593
657
  read: ["getTenant", "listTenants"],
594
658
  manage: ["setTenant"]
595
659
  };
596
660
 
597
661
  // src/lib/tools/users.ts
598
- 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
+ }
724
+
725
+ // src/lib/utils.ts
726
+ function filterTools(tools2, pattern) {
727
+ if (!pattern) {
728
+ throw new Error("No pattern provided");
729
+ }
730
+ if (pattern === "*") {
731
+ return Object.values(tools2).flatMap((category2) => Object.values(category2));
732
+ }
733
+ const [category, tool] = pattern.split(".");
734
+ if (category === "*" && tool === "*") {
735
+ return Object.values(tools2).flatMap((category2) => Object.values(category2));
736
+ }
737
+ if (category && !tools2[category]) {
738
+ throw new Error(`Tool category ${category} not found`);
739
+ }
740
+ if (category && tool === "*") {
741
+ return Object.values(tools2[category]);
742
+ }
743
+ if (category && tool && !tools2[category][tool]) {
744
+ throw new Error(`Tool ${pattern} not found`);
745
+ }
746
+ return [tools2[category][tool]];
747
+ }
748
+ function getToolsWithPermissions(category, categoryPermissions) {
749
+ const toolsInCategory = tools[category];
750
+ const toolPermissionsInCategory = toolPermissions[category];
751
+ return Object.entries(categoryPermissions).reduce(
752
+ (acc, [permissionType, hasPermission]) => {
753
+ if (Array.isArray(hasPermission) && hasPermission.length > 0 || hasPermission === true) {
754
+ return acc.concat(
755
+ toolPermissionsInCategory[permissionType].map(
756
+ (toolName) => toolsInCategory[toolName]
757
+ )
758
+ );
759
+ }
760
+ return acc;
761
+ },
762
+ []
763
+ );
764
+ }
765
+ async function getToolsByPermissionsInCategories(knockClient, config) {
766
+ const toolsByCategory = Object.keys(config.permissions).reduce(
767
+ (acc, category) => {
768
+ const categoryKey = category;
769
+ const categoryPermissions = config.permissions[categoryKey];
770
+ if (tools[categoryKey] && categoryPermissions) {
771
+ const tools2 = getToolsWithPermissions(categoryKey, categoryPermissions);
772
+ return { ...acc, [categoryKey]: tools2 };
773
+ }
774
+ return acc;
775
+ },
776
+ {}
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
+ );
795
+ }
796
+ function serializeMessageResponse(message) {
797
+ return {
798
+ id: message.id,
799
+ status: message.status,
800
+ engagement_statuses: message.engagement_statuses,
801
+ data: message.data,
802
+ metadata: message.metadata
803
+ };
804
+ }
805
+
806
+ // src/lib/tools/users.ts
807
+ function maybeHideUserData(user, hideUserData = false) {
808
+ if (hideUserData) {
809
+ return { id: user.id };
810
+ }
811
+ return user;
812
+ }
599
813
  var getUser = KnockTool({
600
814
  method: "get_user",
601
815
  name: "Get user",
@@ -604,15 +818,16 @@ var getUser = KnockTool({
604
818
 
605
819
  If the userId is not provided, it will use the userId from the config.
606
820
  `,
607
- parameters: z9.object({
608
- environment: z9.string().optional().describe(
821
+ parameters: z12.object({
822
+ environment: z12.string().optional().describe(
609
823
  "(string): The environment to retrieve the user from. Defaults to `development`."
610
824
  ),
611
- 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.")
612
826
  }),
613
827
  execute: (knockClient, config) => async (params) => {
614
828
  const publicClient = await knockClient.publicApi(params.environment);
615
- return await publicClient.users.get(params.userId ?? config.userId);
829
+ const user = await publicClient.users.get(params.userId ?? config.userId);
830
+ return maybeHideUserData(user, config.hideUserData);
616
831
  }
617
832
  });
618
833
  var createOrUpdateUser = KnockTool({
@@ -625,26 +840,30 @@ var createOrUpdateUser = KnockTool({
625
840
 
626
841
  If the userId is not provided, it will use the userId from the config.
627
842
  `,
628
- parameters: z9.object({
629
- environment: z9.string().optional().describe(
843
+ parameters: z12.object({
844
+ environment: z12.string().optional().describe(
630
845
  "(string): The environment to create or update the user in. Defaults to `development`."
631
846
  ),
632
- userId: z9.string().optional().describe("(string): The userId of the User to update."),
633
- email: z9.string().optional().describe("(string): The email of the User to update."),
634
- name: z9.string().optional().describe("(string): The name of the User to update."),
635
- phoneNumber: z9.string().optional().describe("(string): The phone number of the User to update."),
636
- 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(
637
852
  "(object): A dictionary of custom properties to update for the User."
638
853
  )
639
854
  }),
640
855
  execute: (knockClient, config) => async (params) => {
641
856
  const publicClient = await knockClient.publicApi(params.environment);
642
- return await publicClient.users.identify(params.userId ?? config.userId, {
643
- email: params.email,
644
- name: params.name,
645
- phone_number: params.phoneNumber,
646
- ...params.customProperties ?? {}
647
- });
857
+ const user = await publicClient.users.identify(
858
+ params.userId ?? config.userId,
859
+ {
860
+ email: params.email,
861
+ name: params.name,
862
+ phone_number: params.phoneNumber,
863
+ ...params.customProperties ?? {}
864
+ }
865
+ );
866
+ return maybeHideUserData(user, config.hideUserData);
648
867
  }
649
868
  });
650
869
  var getUserPreferences = KnockTool({
@@ -655,14 +874,14 @@ var getUserPreferences = KnockTool({
655
874
 
656
875
  If the userId is not provided, it will use the userId from the config.
657
876
  `,
658
- parameters: z9.object({
659
- environment: z9.string().optional().describe(
877
+ parameters: z12.object({
878
+ environment: z12.string().optional().describe(
660
879
  "(string): The environment to retrieve the user preferences from. Defaults to `development`."
661
880
  ),
662
- userId: z9.string().optional().describe(
881
+ userId: z12.string().optional().describe(
663
882
  "(string): The userId of the User to retrieve Preferences for."
664
883
  ),
665
- preferenceSetId: z9.string().optional().describe(
884
+ preferenceSetId: z12.string().optional().describe(
666
885
  "(string): The preferenceSetId of the User to retrieve preferences for. Defaults to `default`."
667
886
  )
668
887
  }),
@@ -711,18 +930,18 @@ var setUserPreferences = KnockTool({
711
930
  </example>
712
931
  </examples>
713
932
  `,
714
- parameters: z9.object({
715
- environment: z9.string().optional().describe(
933
+ parameters: z12.object({
934
+ environment: z12.string().optional().describe(
716
935
  "(string): The environment to set the user preferences in. Defaults to `development`."
717
936
  ),
718
- userId: z9.string().optional().describe("(string): The userId of the User to update preferences for."),
719
- 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(
720
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."
721
940
  ),
722
- categories: z9.record(z9.string(), z9.any()).optional().describe(
941
+ categories: z12.record(z12.string(), z12.any()).optional().describe(
723
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."
724
943
  ),
725
- channel_types: z9.record(z9.string(), z9.boolean()).optional().describe(
944
+ channel_types: z12.record(z12.string(), z12.boolean()).optional().describe(
726
945
  "(object): The channel types to update where the key is the channel type, and the value of the object is a boolean value."
727
946
  )
728
947
  }),
@@ -763,23 +982,24 @@ var getUserMessages = KnockTool({
763
982
 
764
983
  If the userId is not provided, it will use the userId from the config.
765
984
  `,
766
- parameters: z9.object({
767
- environment: z9.string().optional().describe(
985
+ parameters: z12.object({
986
+ environment: z12.string().optional().describe(
768
987
  "(string): The environment to retrieve the user messages from. Defaults to `development`."
769
988
  ),
770
- userId: z9.string().optional().describe("(string): The userId of the User to retrieve messages for."),
771
- 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(
772
991
  "(string): The workflowRunId of the User to retrieve. Use this when you want to retrieve messages sent from a workflow trigger."
773
992
  )
774
993
  }),
775
994
  execute: (knockClient, config) => async (params) => {
776
995
  const publicClient = await knockClient.publicApi(params.environment);
777
- return await publicClient.users.getMessages(
996
+ const messages2 = await publicClient.users.getMessages(
778
997
  params.userId ?? config.userId,
779
998
  {
780
999
  workflow_run_id: params.workflowRunId
781
1000
  }
782
1001
  );
1002
+ return messages2.items.map(serializeMessageResponse);
783
1003
  }
784
1004
  });
785
1005
  var users = {
@@ -789,23 +1009,32 @@ var users = {
789
1009
  setUserPreferences,
790
1010
  getUserMessages
791
1011
  };
792
- var permissions10 = {
1012
+ var permissions11 = {
793
1013
  read: ["getUser", "getUserMessages", "getUserPreferences"],
794
1014
  manage: ["createOrUpdateUser", "setUserPreferences"]
795
1015
  };
796
1016
 
797
1017
  // src/lib/tools/workflows.ts
798
- import { z as z10 } from "zod";
1018
+ import { z as z13 } from "zod";
1019
+ function serializeWorkflowResponse(workflow2) {
1020
+ return {
1021
+ key: workflow2.key,
1022
+ name: workflow2.name,
1023
+ description: workflow2.description,
1024
+ categories: workflow2.categories,
1025
+ schema: workflow2.trigger_data_json_schema
1026
+ };
1027
+ }
799
1028
  var listWorkflows = KnockTool({
800
1029
  method: "list_workflows",
801
1030
  name: "List workflows",
802
1031
  description: `
803
- 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.
1032
+ List all workflows available for the given environment. Returns structural information about the workflows, including the key, name, description, and categories.
804
1033
 
805
- Use this tool when you need to understand which workflows are available to be called.
1034
+ Use this tool when you need to understand which workflows are available to be called.
806
1035
  `,
807
- parameters: z10.object({
808
- environment: z10.string().optional().describe(
1036
+ parameters: z13.object({
1037
+ environment: z13.string().optional().describe(
809
1038
  "(string): The environment to list workflows for. Defaults to `development`."
810
1039
  )
811
1040
  }),
@@ -814,32 +1043,53 @@ var listWorkflows = KnockTool({
814
1043
  const listParams = {
815
1044
  environment: params.environment ?? config.environment ?? "development"
816
1045
  };
817
- for await (const workflow of knockClient.workflows.list(listParams)) {
818
- allWorkflows.push(workflow);
1046
+ for await (const workflow2 of knockClient.workflows.list(listParams)) {
1047
+ allWorkflows.push(serializeWorkflowResponse(workflow2));
819
1048
  }
820
1049
  return allWorkflows;
821
1050
  }
822
1051
  });
1052
+ var getWorkflow = KnockTool({
1053
+ method: "get_workflow",
1054
+ name: "Get workflow",
1055
+ description: `
1056
+ Get a workflow by key. Returns structural information about the workflow, including the key, name, description, and categories.
1057
+ `,
1058
+ parameters: z13.object({
1059
+ environment: z13.string().optional().describe(
1060
+ "(string): The environment to get the workflow for. Defaults to `development`."
1061
+ ),
1062
+ workflowKey: z13.string().describe("(string): The key of the workflow to get.")
1063
+ }),
1064
+ execute: (knockClient, config) => async (params) => {
1065
+ const workflow2 = await knockClient.workflows.retrieve(params.workflowKey, {
1066
+ environment: params.environment ?? config.environment ?? "development"
1067
+ });
1068
+ return serializeWorkflowResponse(workflow2);
1069
+ }
1070
+ });
823
1071
  var triggerWorkflow = KnockTool({
824
1072
  method: "trigger_workflow",
825
1073
  name: "Trigger workflow",
826
1074
  description: `
827
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.
828
1076
 
829
- 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.
830
1078
 
831
1079
  When recipients aren't provided, the workflow will be triggered for the current user specified in the config.
1080
+
1081
+ Returns the workflow run ID, which can be used to lookup messages produced by the workflow.
832
1082
  `,
833
- parameters: z10.object({
834
- environment: z10.string().optional().describe(
1083
+ parameters: z13.object({
1084
+ environment: z13.string().optional().describe(
835
1085
  "(string): The environment to trigger the workflow in. Defaults to `development`."
836
1086
  ),
837
- workflowKey: z10.string().describe("(string): The key of the workflow to trigger."),
838
- 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(
839
1089
  "(array): The recipients to trigger the workflow for. This is an array of user IDs."
840
1090
  ),
841
- data: z10.record(z10.string(), z10.any()).optional().describe("(object): Data to pass to the workflow."),
842
- 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(
843
1093
  "(object): The tenant to trigger the workflow for. Must contain an id if being sent."
844
1094
  )
845
1095
  }),
@@ -877,15 +1127,15 @@ var createEmailWorkflow = KnockTool({
877
1127
 
878
1128
  Once you've created the workflow, you should ask if you should commit the changes to the environment.
879
1129
  `,
880
- parameters: z10.object({
881
- environment: z10.string().optional().describe(
1130
+ parameters: z13.object({
1131
+ environment: z13.string().optional().describe(
882
1132
  "(string): The environment to create the workflow in. Defaults to `development`."
883
1133
  ),
884
- workflowKey: z10.string().describe("(string): The key of the workflow."),
885
- name: z10.string().describe("(string): The name of the workflow."),
886
- categories: z10.array(z10.string()).optional().describe("(array): The categories to add to the workflow."),
887
- subject: z10.string().describe("(string): The subject of the email."),
888
- 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.")
889
1139
  }),
890
1140
  execute: (knockClient, config) => async (params) => {
891
1141
  const emailChannelsPage = await knockClient.channels.list();
@@ -923,10 +1173,11 @@ var createEmailWorkflow = KnockTool({
923
1173
  ]
924
1174
  }
925
1175
  };
926
- return await knockClient.workflows.upsert(
1176
+ const result = await knockClient.workflows.upsert(
927
1177
  params.workflowKey,
928
1178
  workflowParams
929
1179
  );
1180
+ return serializeWorkflowResponse(result.workflow);
930
1181
  }
931
1182
  });
932
1183
  var createOneOffWorkflowSchedule = KnockTool({
@@ -943,18 +1194,18 @@ var createOneOffWorkflowSchedule = KnockTool({
943
1194
  - In one hour, send a password reset email to a user
944
1195
  - In two weeks, send a survey to a user
945
1196
  `,
946
- parameters: z10.object({
947
- environment: z10.string().optional().describe(
1197
+ parameters: z13.object({
1198
+ environment: z13.string().optional().describe(
948
1199
  "(string): The environment to create the workflow in. Defaults to `development`."
949
1200
  ),
950
- workflowKey: z10.string().describe("(string): The key of the workflow to schedule."),
951
- userId: z10.string().describe(
1201
+ workflowKey: z13.string().describe("(string): The key of the workflow to schedule."),
1202
+ userId: z13.string().describe(
952
1203
  "(string): The userId of the user to schedule the workflow for."
953
1204
  ),
954
- scheduledAt: z10.string().describe(
1205
+ scheduledAt: z13.string().describe(
955
1206
  "(string): The date and time to schedule the workflow for. Must be in ISO 8601 format."
956
1207
  ),
957
- 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.")
958
1209
  }),
959
1210
  execute: (knockClient, config) => async (params) => {
960
1211
  const publicClient = await knockClient.publicApi(params.environment);
@@ -967,12 +1218,13 @@ var createOneOffWorkflowSchedule = KnockTool({
967
1218
  });
968
1219
  var workflows = {
969
1220
  listWorkflows,
1221
+ getWorkflow,
970
1222
  triggerWorkflow,
971
1223
  createEmailWorkflow,
972
1224
  createOneOffWorkflowSchedule
973
1225
  };
974
- var permissions11 = {
975
- read: ["listWorkflows"],
1226
+ var permissions12 = {
1227
+ read: ["listWorkflows", "getWorkflow"],
976
1228
  manage: ["createEmailWorkflow", "createOneOffWorkflowSchedule"],
977
1229
  run: ["triggerWorkflow"]
978
1230
  };
@@ -981,6 +1233,7 @@ var permissions11 = {
981
1233
  var tools = {
982
1234
  channels,
983
1235
  commits,
1236
+ documentation,
984
1237
  emailLayouts,
985
1238
  environments,
986
1239
  messages,
@@ -994,6 +1247,7 @@ var tools = {
994
1247
  var allTools = {
995
1248
  ...channels,
996
1249
  ...commits,
1250
+ ...documentation,
997
1251
  ...emailLayouts,
998
1252
  ...environments,
999
1253
  ...messageTypes,
@@ -1007,20 +1261,24 @@ var allTools = {
1007
1261
  var toolPermissions = {
1008
1262
  channels: permissions,
1009
1263
  commits: permissions2,
1010
- emailLayouts: permissions3,
1011
- environments: permissions4,
1012
- messages: permissions5,
1264
+ documentation: permissions3,
1265
+ emailLayouts: permissions4,
1266
+ environments: permissions5,
1267
+ messages: permissions7,
1013
1268
  messageTypes: permissions6,
1014
- objects: permissions7,
1015
- partials: permissions8,
1016
- tenants: permissions9,
1017
- users: permissions10,
1018
- workflows: permissions11
1269
+ objects: permissions8,
1270
+ partials: permissions9,
1271
+ tenants: permissions10,
1272
+ users: permissions11,
1273
+ workflows: permissions12
1019
1274
  };
1020
1275
 
1021
1276
  export {
1022
1277
  tools,
1023
1278
  allTools,
1024
- toolPermissions
1279
+ createWorkflowTools,
1280
+ filterTools,
1281
+ getToolsByPermissionsInCategories,
1282
+ getToolMap
1025
1283
  };
1026
- //# sourceMappingURL=chunk-3NU2K26A.js.map
1284
+ //# sourceMappingURL=chunk-JBEVT2QK.js.map