@knocklabs/agent-toolkit 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dist/ai-sdk/index.d.ts +1 -4
  2. package/dist/ai-sdk/index.js +14 -20
  3. package/dist/ai-sdk/index.js.map +1 -1
  4. package/dist/{chunk-XUYE3AGB.js → chunk-B6DIDKFY.js} +14 -2
  5. package/dist/chunk-B6DIDKFY.js.map +1 -0
  6. package/dist/chunk-RPKDXX4O.js +1023 -0
  7. package/dist/chunk-RPKDXX4O.js.map +1 -0
  8. package/dist/{chunk-4VR65G5W.js → chunk-ZV2SOIO7.js} +29 -4
  9. package/dist/chunk-ZV2SOIO7.js.map +1 -0
  10. package/dist/modelcontextprotocol/index.d.ts +47 -6
  11. package/dist/modelcontextprotocol/index.js +2 -15
  12. package/dist/modelcontextprotocol/local-server.js +5 -20
  13. package/dist/modelcontextprotocol/local-server.js.map +1 -1
  14. package/dist/openai/index.d.ts +1 -4
  15. package/dist/openai/index.js +18 -20
  16. package/dist/openai/index.js.map +1 -1
  17. package/dist/types-DyB12-Gk.d.ts +73 -0
  18. package/package.json +2 -2
  19. package/dist/ai-sdk/tool-converter.d.ts +0 -12
  20. package/dist/ai-sdk/tool-converter.js +0 -7
  21. package/dist/ai-sdk/tool-converter.js.map +0 -1
  22. package/dist/chunk-2CNJ4XX6.js +0 -33
  23. package/dist/chunk-2CNJ4XX6.js.map +0 -1
  24. package/dist/chunk-3LZK6RH6.js +0 -29
  25. package/dist/chunk-3LZK6RH6.js.map +0 -1
  26. package/dist/chunk-4VR65G5W.js.map +0 -1
  27. package/dist/chunk-6H3BXH2Y.js +0 -15
  28. package/dist/chunk-6H3BXH2Y.js.map +0 -1
  29. package/dist/chunk-BY4KQPUO.js +0 -39
  30. package/dist/chunk-BY4KQPUO.js.map +0 -1
  31. package/dist/chunk-DSRTYV37.js +0 -39
  32. package/dist/chunk-DSRTYV37.js.map +0 -1
  33. package/dist/chunk-JTYQTWCX.js +0 -75
  34. package/dist/chunk-JTYQTWCX.js.map +0 -1
  35. package/dist/chunk-NZB2TMJW.js +0 -92
  36. package/dist/chunk-NZB2TMJW.js.map +0 -1
  37. package/dist/chunk-O6DWF42E.js +0 -31
  38. package/dist/chunk-O6DWF42E.js.map +0 -1
  39. package/dist/chunk-OD5VHBGN.js +0 -32
  40. package/dist/chunk-OD5VHBGN.js.map +0 -1
  41. package/dist/chunk-PDMA6RIB.js +0 -19
  42. package/dist/chunk-PDMA6RIB.js.map +0 -1
  43. package/dist/chunk-RYMJEH6P.js +0 -140
  44. package/dist/chunk-RYMJEH6P.js.map +0 -1
  45. package/dist/chunk-THLK376Y.js +0 -191
  46. package/dist/chunk-THLK376Y.js.map +0 -1
  47. package/dist/chunk-TLHETJRF.js +0 -75
  48. package/dist/chunk-TLHETJRF.js.map +0 -1
  49. package/dist/chunk-TOBLV65T.js +0 -30
  50. package/dist/chunk-TOBLV65T.js.map +0 -1
  51. package/dist/chunk-VJFA3ZVW.js +0 -210
  52. package/dist/chunk-VJFA3ZVW.js.map +0 -1
  53. package/dist/chunk-WB4XCCUS.js +0 -19
  54. package/dist/chunk-WB4XCCUS.js.map +0 -1
  55. package/dist/chunk-XRQWR3LY.js +0 -184
  56. package/dist/chunk-XRQWR3LY.js.map +0 -1
  57. package/dist/chunk-XUYE3AGB.js.map +0 -1
  58. package/dist/lib/knock-client.d.ts +0 -4
  59. package/dist/lib/knock-client.js +0 -7
  60. package/dist/lib/knock-client.js.map +0 -1
  61. package/dist/lib/knock-tool.d.ts +0 -4
  62. package/dist/lib/knock-tool.js +0 -7
  63. package/dist/lib/knock-tool.js.map +0 -1
  64. package/dist/lib/tools/channels.d.ts +0 -13
  65. package/dist/lib/tools/channels.js +0 -10
  66. package/dist/lib/tools/channels.js.map +0 -1
  67. package/dist/lib/tools/commits.d.ts +0 -16
  68. package/dist/lib/tools/commits.js +0 -10
  69. package/dist/lib/tools/commits.js.map +0 -1
  70. package/dist/lib/tools/email-layouts.d.ts +0 -13
  71. package/dist/lib/tools/email-layouts.js +0 -10
  72. package/dist/lib/tools/email-layouts.js.map +0 -1
  73. package/dist/lib/tools/environments.d.ts +0 -13
  74. package/dist/lib/tools/environments.js +0 -10
  75. package/dist/lib/tools/environments.js.map +0 -1
  76. package/dist/lib/tools/index.d.ts +0 -4
  77. package/dist/lib/tools/index.js +0 -23
  78. package/dist/lib/tools/index.js.map +0 -1
  79. package/dist/lib/tools/message-types.d.ts +0 -15
  80. package/dist/lib/tools/message-types.js +0 -10
  81. package/dist/lib/tools/message-types.js.map +0 -1
  82. package/dist/lib/tools/messages.d.ts +0 -13
  83. package/dist/lib/tools/messages.js +0 -10
  84. package/dist/lib/tools/messages.js.map +0 -1
  85. package/dist/lib/tools/objects.d.ts +0 -19
  86. package/dist/lib/tools/objects.js +0 -10
  87. package/dist/lib/tools/objects.js.map +0 -1
  88. package/dist/lib/tools/partials.d.ts +0 -13
  89. package/dist/lib/tools/partials.js +0 -10
  90. package/dist/lib/tools/partials.js.map +0 -1
  91. package/dist/lib/tools/tenants.d.ts +0 -16
  92. package/dist/lib/tools/tenants.js +0 -10
  93. package/dist/lib/tools/tenants.js.map +0 -1
  94. package/dist/lib/tools/users.d.ts +0 -19
  95. package/dist/lib/tools/users.js +0 -10
  96. package/dist/lib/tools/users.js.map +0 -1
  97. package/dist/lib/tools/workflows.d.ts +0 -18
  98. package/dist/lib/tools/workflows.js +0 -10
  99. package/dist/lib/tools/workflows.js.map +0 -1
  100. package/dist/lib/utils.d.ts +0 -33
  101. package/dist/lib/utils.js +0 -24
  102. package/dist/lib/utils.js.map +0 -1
  103. package/dist/modelcontextprotocol/adapter.d.ts +0 -11
  104. package/dist/modelcontextprotocol/adapter.js +0 -7
  105. package/dist/modelcontextprotocol/adapter.js.map +0 -1
  106. package/dist/openai/tool-converter.d.ts +0 -15
  107. package/dist/openai/tool-converter.js +0 -7
  108. package/dist/openai/tool-converter.js.map +0 -1
  109. package/dist/types-B-9pppCQ.d.ts +0 -199
  110. package/dist/types.d.ts +0 -4
  111. package/dist/types.js +0 -1
  112. package/dist/types.js.map +0 -1
@@ -0,0 +1,1023 @@
1
+ // src/lib/knock-tool.ts
2
+ import { z } from "zod";
3
+ var trimLines = (text) => text.split("\n").map((l) => l.trim()).filter(Boolean).join("\n");
4
+ var KnockTool = (args) => {
5
+ const { execute, ...restOfArgs } = args;
6
+ const parameters = restOfArgs.parameters ? restOfArgs.parameters : z.object({});
7
+ const schemaEntries = Object.entries(parameters.shape);
8
+ const argsStr = schemaEntries.length === 0 ? "Takes no arguments" : schemaEntries.map(([key, value]) => {
9
+ return `- ${key}: ${value.description || ""}`;
10
+ }).join("\n");
11
+ const fullDescription = trimLines(`
12
+ Tool name:
13
+ ${args.name}
14
+ Description:
15
+ ${args.description}.
16
+ Arguments:
17
+ ${argsStr}
18
+ `);
19
+ return {
20
+ ...restOfArgs,
21
+ parameters,
22
+ fullDescription,
23
+ bindExecute: (knockClient, config) => execute(knockClient, config)
24
+ };
25
+ };
26
+
27
+ // src/lib/tools/channels.ts
28
+ var listChannels = KnockTool({
29
+ method: "list_channels",
30
+ name: "List channels",
31
+ 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.
33
+
34
+ Use this tool when you need to know about the channels configured in the Knock account, like when configuring a workflow.
35
+ `,
36
+ execute: (knockClient) => async (params) => {
37
+ const allChannels = [];
38
+ for await (const channel of knockClient.channels.list()) {
39
+ allChannels.push(channel);
40
+ }
41
+ return allChannels;
42
+ }
43
+ });
44
+ var channels = {
45
+ listChannels
46
+ };
47
+ var permissions = {
48
+ read: ["listChannels"]
49
+ };
50
+
51
+ // src/lib/tools/commits.ts
52
+ import { z as z2 } from "zod";
53
+ var listCommits = KnockTool({
54
+ method: "list_commits",
55
+ name: "List commits",
56
+ description: `
57
+ Returns all commits available in the environment. Use this tool when you are asked to see what changes are available to be deployed.
58
+ `,
59
+ parameters: z2.object({
60
+ environment: z2.string().describe(
61
+ "(string): The environment to list commits for. Defaults to `development`."
62
+ ),
63
+ promoted: z2.boolean().describe(
64
+ "(boolean): Whether to only return promoted commits. Defaults to `false`."
65
+ )
66
+ }),
67
+ execute: (knockClient, config) => async (params) => {
68
+ return await knockClient.commits.list({
69
+ environment: params.environment ?? config.environment ?? "development",
70
+ promoted: params.promoted ?? false
71
+ });
72
+ }
73
+ });
74
+ var commitAllChanges = KnockTool({
75
+ method: "commit_all_changes",
76
+ name: "Commit all changes",
77
+ 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.
79
+ `,
80
+ parameters: z2.object({
81
+ message: z2.string().describe("(string): The message to include in the commit.")
82
+ }),
83
+ execute: (knockClient, config) => async (params) => {
84
+ return await knockClient.commits.commitAll({
85
+ environment: config.environment ?? "development",
86
+ commit_message: params.message
87
+ });
88
+ }
89
+ });
90
+ var promoteAllCommits = KnockTool({
91
+ method: "promote_all_commits",
92
+ name: "Promote all commits",
93
+ 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.
97
+ `,
98
+ parameters: z2.object({
99
+ toEnvironment: z2.string().describe("(string): The environment to promote all commits to.")
100
+ }),
101
+ execute: (knockClient, config) => async (params) => {
102
+ return await knockClient.put("/v1/commits/promote", {
103
+ body: { to_environment: params.toEnvironment }
104
+ });
105
+ }
106
+ });
107
+ var commits = {
108
+ listCommits,
109
+ commitAllChanges,
110
+ promoteAllCommits
111
+ };
112
+ var permissions2 = {
113
+ read: ["listCommits"],
114
+ manage: ["commitAllChanges", "promoteAllCommits"]
115
+ };
116
+
117
+ // src/lib/tools/email-layouts.ts
118
+ import { z as z3 } from "zod";
119
+ var listEmailLayouts = KnockTool({
120
+ method: "list_email_layouts",
121
+ name: "List email layouts",
122
+ description: `List all email layouts within the environment given. Returns information about the email layout, including the name and the key.
123
+
124
+ Use this tool when building a workflow that is building an email notification when you need to know the available email layouts.`,
125
+ parameters: z3.object({
126
+ environment: z3.string().describe(
127
+ "(string): The environment to list email layouts for. Defaults to `development`."
128
+ )
129
+ }),
130
+ execute: (knockClient, config) => async (params) => {
131
+ const allEmailLayouts = [];
132
+ for await (const emailLayout of knockClient.emailLayouts.list({
133
+ environment: params.environment ?? config.environment ?? "development"
134
+ })) {
135
+ allEmailLayouts.push(emailLayout);
136
+ }
137
+ return allEmailLayouts;
138
+ }
139
+ });
140
+ var emailLayouts = {
141
+ listEmailLayouts
142
+ };
143
+ var permissions3 = {
144
+ read: ["listEmailLayouts"]
145
+ };
146
+
147
+ // src/lib/tools/environments.ts
148
+ var listEnvironments = KnockTool({
149
+ method: "list_environments",
150
+ name: "List environments",
151
+ 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.
153
+ `,
154
+ execute: (knockClient) => async (params) => {
155
+ const allEnvironments = [];
156
+ for await (const environment of knockClient.environments.list()) {
157
+ allEnvironments.push(environment);
158
+ }
159
+ return allEnvironments;
160
+ }
161
+ });
162
+ var environments = {
163
+ listEnvironments
164
+ };
165
+ var permissions4 = {
166
+ read: ["listEnvironments"]
167
+ };
168
+
169
+ // src/lib/tools/messages.ts
170
+ import { z as z4 } from "zod";
171
+ var getMessageContent = KnockTool({
172
+ method: "get_message_content",
173
+ name: "Get message content",
174
+ description: `
175
+ 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
+ `,
177
+ parameters: z4.object({
178
+ messageId: z4.string().describe("(string): The messageId of the message to retrieve.")
179
+ }),
180
+ execute: (knockClient) => async (params) => {
181
+ const publicClient = await knockClient.publicApi();
182
+ return await publicClient.messages.getContent(params.messageId);
183
+ }
184
+ });
185
+ var messages = {
186
+ getMessageContent
187
+ };
188
+ var permissions5 = {
189
+ read: ["getMessageContent"]
190
+ };
191
+
192
+ // src/lib/tools/message-types.ts
193
+ import { z as z5 } from "zod";
194
+ var listMessageTypes = KnockTool({
195
+ method: "list_message_types",
196
+ name: "List message types",
197
+ 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
+ parameters: z5.object({
199
+ environment: z5.string().describe(
200
+ "(string): The environment to list message types for. Defaults to `development`."
201
+ )
202
+ }),
203
+ execute: (knockClient, config) => async (params) => {
204
+ const allMessageTypes = [];
205
+ for await (const messageType of knockClient.messageTypes.list({
206
+ environment: params.environment ?? config.environment ?? "development"
207
+ })) {
208
+ allMessageTypes.push(messageType);
209
+ }
210
+ return allMessageTypes;
211
+ }
212
+ });
213
+ var createOrUpdateMessageType = KnockTool({
214
+ method: "create_or_update_message_type",
215
+ name: "Create or update message type",
216
+ description: `
217
+ Create or update a message type. A message type is a schema that defines fields available to an editor within Knock. Message types always have at least one variant, that MUST be named "default".
218
+
219
+ Use this tool when you need to create a new message type, or update an existing message type. You must pass the FULL message type to this tool if you're going to update an existing message type.
220
+
221
+ The preview is a string of HTML that will be rendered in the Knock UI as a representation of the message type. It is shared across all variants. It supports liquid, where the field name is available as a variable, so a field named "text" will be rendered as {{ text }}.
222
+
223
+ <example>
224
+ <description>
225
+ Create a new message type for a banner component that has a text and an action URL.
226
+ </description>
227
+ <input>
228
+ {
229
+ "messageTypeKey": "banner",
230
+ "name": "Banner",
231
+ "description": "A banner component that has a text and an action URL.",
232
+ "preview": "<div>{{ text }}</div>",
233
+ "variants": [
234
+ {
235
+ "key": "default",
236
+ "name": "Default",
237
+ "fields": [
238
+ {
239
+ "key": "text",
240
+ "type": "text",
241
+ "label": "Text",
242
+ "settings": {
243
+ "max_length": 100,
244
+ },
245
+ },
246
+ {
247
+ "key": "action_url",
248
+ "type": "text",
249
+ "label": "Action URL",
250
+ "settings": {
251
+ "placeholder": "https://example.com",
252
+ },
253
+ }
254
+ ]
255
+ }
256
+ ]
257
+ }
258
+ </input>
259
+ </example>
260
+ <example>
261
+ <description>
262
+ Create a message type for a card component that has an icon type, title, body, and a single action button.
263
+ </description>
264
+ <input>
265
+ {
266
+ "messageTypeKey": "card",
267
+ "name": "Card",
268
+ "description": "A single-action card component.",
269
+ "preview": "
270
+ <div>
271
+ <h2>{{ title }}</h2>
272
+ <p>{{ body }}</p>
273
+ <button>Action</button>
274
+ </div>
275
+ ",
276
+ "variants": [
277
+ {
278
+ "key": "default",
279
+ "name": "Default",
280
+ "fields": [
281
+ {
282
+ "key": "icon_type",
283
+ "type": "select",
284
+ "label": "Icon type",
285
+ "settings": {
286
+ "options": [
287
+ {
288
+ "value": "warning",
289
+ "label": "Warning",
290
+ },
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
+ ]
304
+ },
305
+ },
306
+ {
307
+ "key": "title",
308
+ "type": "text",
309
+ "label": "Title",
310
+ },
311
+ {
312
+ "key": "description",
313
+ "type": "markdown",
314
+ "label": "Description",
315
+ },
316
+ {
317
+ "key": "action_button",
318
+ "type": "button",
319
+ "label": "Action button",
320
+ },
321
+ ]
322
+ }
323
+ ]
324
+ }
325
+ </input>
326
+ </example>
327
+ `,
328
+ parameters: z5.object({
329
+ messageTypeKey: z5.string().describe("(string): The key of the message type to create or update."),
330
+ name: z5.string().describe("(string): The name of the message type."),
331
+ description: z5.string().optional().describe("(string): The description of the message type."),
332
+ preview: z5.string().optional().describe(
333
+ "(string): The preview of the variant. This is a string of HTML that will be rendered in the preview of the message type. There is a single preview shared by all variants."
334
+ ),
335
+ variants: z5.array(
336
+ z5.object({
337
+ key: z5.string().describe("(string): The key of the variant."),
338
+ name: z5.string().describe("(string): The name of the variant."),
339
+ description: z5.string().optional().describe("(string): The description of the variant."),
340
+ fields: z5.array(
341
+ z5.object({
342
+ key: z5.string().describe("(string): The key of the field."),
343
+ type: z5.string().describe(
344
+ "(string): The type of the field. One of `text`, `textarea`, `button`, `markdown`, `select`, `multi_select`."
345
+ ),
346
+ label: z5.string().describe("(string): The label of the field."),
347
+ settings: z5.object({}).describe("(object): The settings of the field.")
348
+ })
349
+ ).describe("(array): The fields of the variant.")
350
+ })
351
+ ).describe("(array): The variants of the message type.")
352
+ }),
353
+ execute: (knockClient, config) => async (params) => {
354
+ return await knockClient.messageTypes.upsert(params.messageTypeKey, {
355
+ message_type: {
356
+ name: params.name,
357
+ variants: params.variants,
358
+ description: params.description ?? "",
359
+ preview: params.preview ?? "<div></div>"
360
+ },
361
+ environment: params.environment ?? config.environment ?? "development"
362
+ });
363
+ }
364
+ });
365
+ var messageTypes = {
366
+ listMessageTypes,
367
+ createOrUpdateMessageType
368
+ };
369
+ var permissions6 = {
370
+ read: ["listMessageTypes"],
371
+ manage: ["createOrUpdateMessageType"]
372
+ };
373
+
374
+ // src/lib/tools/objects.ts
375
+ import { z as z6 } from "zod";
376
+ var listObjects = KnockTool({
377
+ method: "list_objects",
378
+ name: "List objects",
379
+ 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
+ parameters: z6.object({
381
+ collection: z6.string().describe("(string): The collection to list objects from.")
382
+ }),
383
+ execute: (knockClient, config) => async (params) => {
384
+ const publicClient = await knockClient.publicApi();
385
+ return await publicClient.objects.list(params.collection);
386
+ }
387
+ });
388
+ var getObject = KnockTool({
389
+ method: "get_object",
390
+ name: "Get object",
391
+ 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
+ parameters: z6.object({
393
+ collection: z6.string().describe("(string): The collection to get the object from."),
394
+ objectId: z6.string().describe("(string): The ID of the object to get.")
395
+ }),
396
+ execute: (knockClient, config) => async (params) => {
397
+ const publicClient = await knockClient.publicApi();
398
+ return await publicClient.objects.get(params.collection, params.objectId);
399
+ }
400
+ });
401
+ var createOrUpdateObject = KnockTool({
402
+ method: "create_or_update_object",
403
+ name: "Create or update object",
404
+ 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.
405
+
406
+ 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
+ parameters: z6.object({
408
+ collection: z6.string().describe("(string): The collection to create or update the object in."),
409
+ 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.")
411
+ }),
412
+ execute: (knockClient, config) => async (params) => {
413
+ const publicClient = await knockClient.publicApi();
414
+ return await publicClient.objects.set(
415
+ params.collection,
416
+ params.objectId,
417
+ params.properties
418
+ );
419
+ }
420
+ });
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
+ var subscribeUsersToObject = KnockTool({
436
+ method: "subscribe_users_to_object",
437
+ name: "Subscribe users to object",
438
+ description: `
439
+ Subscribe a list of users to an object in a specific collection. We use this to model lists of users, for pub-sub use cases.
440
+
441
+ Use this tool when you need to subscribe one or more users to an object where you will then trigger workflows for those lists of users to send notifications to.
442
+
443
+ Before using this tool, you should create the object in the collection using the createOrUpdateObject tool.
444
+ `,
445
+ parameters: z6.object({
446
+ collection: z6.string().describe("(string): The collection to subscribe the user to."),
447
+ objectId: z6.string().describe("(string): The ID of the object to subscribe the user to."),
448
+ userIds: z6.array(z6.string()).describe(
449
+ "(array): The IDs of the users to subscribe to the object. If not provided, the current user will be subscribed."
450
+ )
451
+ }),
452
+ execute: (knockClient, config) => async (params) => {
453
+ const publicClient = await knockClient.publicApi();
454
+ return await publicClient.objects.addSubscriptions(
455
+ params.collection,
456
+ params.objectId,
457
+ {
458
+ recipients: params.userIds ?? [config.userId]
459
+ }
460
+ );
461
+ }
462
+ });
463
+ var unsubscribeUsersFromObject = KnockTool({
464
+ method: "unsubscribe_users_from_object",
465
+ name: "Unsubscribe users from object",
466
+ 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.
467
+
468
+ 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
+ parameters: z6.object({
470
+ collection: z6.string().describe("(string): The collection to unsubscribe the user from."),
471
+ objectId: z6.string().describe("(string): The ID of the object to unsubscribe the user from."),
472
+ userIds: z6.array(z6.string()).describe(
473
+ "(array): The IDs of the users to unsubscribe from the object."
474
+ )
475
+ }),
476
+ execute: (knockClient, config) => async (params) => {
477
+ const publicClient = await knockClient.publicApi();
478
+ return await publicClient.objects.deleteSubscriptions(
479
+ params.collection,
480
+ params.objectId,
481
+ {
482
+ recipients: params.userIds ?? [config.userId]
483
+ }
484
+ );
485
+ }
486
+ });
487
+ var objects = {
488
+ listObjects,
489
+ getObject,
490
+ createOrUpdateObject,
491
+ deleteObject,
492
+ subscribeUsersToObject,
493
+ unsubscribeUsersFromObject
494
+ };
495
+ var permissions7 = {
496
+ read: ["listObjects", "getObject"],
497
+ manage: [
498
+ "createOrUpdateObject",
499
+ "deleteObject",
500
+ "subscribeUsersToObject",
501
+ "unsubscribeUsersFromObject"
502
+ ]
503
+ };
504
+
505
+ // src/lib/tools/partials.ts
506
+ import { z as z7 } from "zod";
507
+ var listPartials = KnockTool({
508
+ method: "list_partials",
509
+ 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.`,
513
+ parameters: z7.object({
514
+ environment: z7.string().describe(
515
+ "(string): The environment to list partials for. Defaults to `development`."
516
+ )
517
+ }),
518
+ execute: (knockClient, config) => async (params) => {
519
+ const allPartials = [];
520
+ for await (const partial of knockClient.partials.list({
521
+ environment: params.environment ?? config.environment ?? "development"
522
+ })) {
523
+ allPartials.push(partial);
524
+ }
525
+ return allPartials;
526
+ }
527
+ });
528
+ var partials = {
529
+ listPartials
530
+ };
531
+ var permissions8 = {
532
+ read: ["listPartials"]
533
+ };
534
+
535
+ // src/lib/tools/tenants.ts
536
+ import { z as z8 } from "zod";
537
+ var getTenant = KnockTool({
538
+ method: "get_tenant",
539
+ name: "Get tenant",
540
+ description: `
541
+ Retrieves a tenant by their ID. Tenants in Knock are used to model organizations, teams, and other groups of users. They are a special type of object.
542
+
543
+ Use this tool when you need to lookup the information about a tenant, including name, and if there are any custom properties set.
544
+ `,
545
+ parameters: z8.object({
546
+ tenantId: z8.string().describe("(string): The ID of the tenant to retrieve.")
547
+ }),
548
+ execute: (knockClient) => async (params) => {
549
+ const publicClient = await knockClient.publicApi();
550
+ return await publicClient.tenants.get(params.tenantId);
551
+ }
552
+ });
553
+ var setTenant = KnockTool({
554
+ method: "set_tenant",
555
+ name: "Set tenant",
556
+ description: `
557
+ Creates or updates a tenant using the properties provided. Tenants in Knock are used to model organizations, teams, and other groups of users. They are a special type of object.
558
+
559
+ Use this tool when you need to create a new tenant, or update an existing tenant's properties.
560
+ `,
561
+ parameters: z8.object({
562
+ 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.")
565
+ }),
566
+ execute: (knockClient) => async (params) => {
567
+ const publicClient = await knockClient.publicApi();
568
+ return await publicClient.tenants.set(params.tenantId, {
569
+ name: params.name,
570
+ ...params.properties
571
+ });
572
+ }
573
+ });
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
+ var tenants = {
592
+ getTenant,
593
+ setTenant,
594
+ deleteTenant
595
+ };
596
+ var permissions9 = {
597
+ read: ["getTenant"],
598
+ manage: ["setTenant", "deleteTenant"]
599
+ };
600
+
601
+ // src/lib/tools/users.ts
602
+ import { z as z9 } from "zod";
603
+ var getUser = KnockTool({
604
+ method: "get_user",
605
+ name: "Get user",
606
+ description: `
607
+ Retrieves the complete user object for the given userId, including email, name, phone number, and any custom properties. Use this tool when you need to retrieve a user's complete profile.
608
+
609
+ If the userId is not provided, it will use the userId from the config.
610
+ `,
611
+ parameters: z9.object({
612
+ userId: z9.string().describe("(string): The userId of the User to retrieve.")
613
+ }),
614
+ execute: (knockClient, config) => async (params) => {
615
+ const publicClient = await knockClient.publicApi();
616
+ return await publicClient.users.get(params.userId ?? config.userId);
617
+ }
618
+ });
619
+ var createOrUpdateUser = KnockTool({
620
+ method: "create_or_update_user",
621
+ name: "Create or update user",
622
+ description: `
623
+ Creates a new user if they don't exist, or updates the user object for the given userId, including email, name, phone number, and any custom properties.
624
+
625
+ Use this tool when you need to update a user's profile.
626
+
627
+ If the userId is not provided, it will use the userId from the config.
628
+ `,
629
+ 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(
635
+ "(object): A dictionary of custom properties to update for the User."
636
+ )
637
+ }),
638
+ 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 };
661
+ }
662
+ });
663
+ var getUserPreferences = KnockTool({
664
+ method: "get_user_preferences",
665
+ name: "Get user preferences",
666
+ description: `
667
+ Retrieves the user's notification preferences for the given userId.
668
+
669
+ If the userId is not provided, it will use the userId from the config.
670
+ `,
671
+ parameters: z9.object({
672
+ userId: z9.string().describe(
673
+ "(string): The userId of the User to retrieve Preferences for."
674
+ ),
675
+ preferenceSetId: z9.string().describe(
676
+ "(string): The preferenceSetId of the User to retrieve preferences for. Defaults to `default`."
677
+ )
678
+ }),
679
+ execute: (knockClient, config) => async (params) => {
680
+ const publicClient = await knockClient.publicApi();
681
+ return await publicClient.users.getPreferences(
682
+ params.userId ?? config.userId,
683
+ {
684
+ preferenceSet: params.preferenceSetId ?? "default"
685
+ }
686
+ );
687
+ }
688
+ });
689
+ var setUserPreferences = KnockTool({
690
+ method: "set_user_preferences",
691
+ name: "Set user preferences",
692
+ description: `
693
+ Overwrites the user's notification preferences for the given userId. Allows setting per-workflow, per-category, or per-channel notification preferences. Use this tool when you are asked to update a user's notification preferences.
694
+
695
+ If the userId is not provided, it will use the userId from the config.
696
+
697
+ Instructions:
698
+
699
+ - You must ALWAYS provide a full preference set to this tool.
700
+ - When setting per-workflow preferences, the key in the object should be the workflow key.
701
+ - Workflow and category preferences should always have channel types underneath.
702
+ - The channel types available to you are: email, sms, push, chat, and in_app_feed.
703
+ - To turn OFF a preference, you must set it to false.
704
+ - To turn ON a preference, you must set it to true.
705
+
706
+ <examples>
707
+ <example>
708
+ <description>
709
+ Update the user's preferences to turn off email notifications for the "welcome" workflow.
710
+ </description>
711
+ <input>
712
+ {
713
+ "workflows": {
714
+ "welcome": {
715
+ "channel_types": {
716
+ "email": false
717
+ }
718
+ }
719
+ }
720
+ }
721
+ </example>
722
+ </examples>
723
+ `,
724
+ 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(
727
+ "(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
+ ),
729
+ categories: z9.record(z9.string(), z9.any()).describe(
730
+ "(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
+ ),
732
+ channel_types: z9.record(z9.string(), z9.boolean()).describe(
733
+ "(object): The channel types to update where the key is the channel type, and the value of the object is a boolean value."
734
+ )
735
+ }),
736
+ execute: (knockClient, config) => async (params) => {
737
+ const publicClient = await knockClient.publicApi();
738
+ const existingPreferences = await publicClient.users.getPreferences(
739
+ params.userId ?? config.userId,
740
+ {
741
+ preferenceSet: "default"
742
+ }
743
+ );
744
+ const updatedPreferences = {
745
+ ...existingPreferences,
746
+ workflows: {
747
+ ...existingPreferences.workflows,
748
+ ...params.workflows
749
+ },
750
+ categories: {
751
+ ...existingPreferences.categories,
752
+ ...params.categories
753
+ },
754
+ channel_types: {
755
+ ...existingPreferences.channel_types,
756
+ ...params.channel_types
757
+ }
758
+ };
759
+ return await publicClient.users.setPreferences(
760
+ params.userId ?? config.userId,
761
+ updatedPreferences
762
+ );
763
+ }
764
+ });
765
+ var getUserMessages = KnockTool({
766
+ method: "get_user_messages",
767
+ name: "Get user messages",
768
+ description: `
769
+ Retrieves the messages that this user has received from the service. Use this tool when you need information about the notifications that the user has received, including if the message has been read, seen, or interacted with. This will return a list of messages across all of the channels.
770
+
771
+ If the userId is not provided, it will use the userId from the config.
772
+ `,
773
+ parameters: z9.object({
774
+ userId: z9.string().describe("(string): The userId of the User to retrieve messages for."),
775
+ workflowRunId: z9.string().describe(
776
+ "(string): The workflowRunId of the User to retrieve. Use this when you want to retrieve messages sent from a workflow trigger."
777
+ )
778
+ }),
779
+ execute: (knockClient, config) => async (params) => {
780
+ const publicClient = await knockClient.publicApi();
781
+ return await publicClient.users.getMessages(
782
+ params.userId ?? config.userId,
783
+ {
784
+ workflow_run_id: params.workflowRunId
785
+ }
786
+ );
787
+ }
788
+ });
789
+ var users = {
790
+ getUser,
791
+ deleteUser,
792
+ createOrUpdateUser,
793
+ getUserPreferences,
794
+ setUserPreferences,
795
+ getUserMessages
796
+ };
797
+ var permissions10 = {
798
+ read: ["getUser", "getUserPreferences", "getUserMessages"],
799
+ manage: ["createOrUpdateUser", "deleteUser", "setUserPreferences"]
800
+ };
801
+
802
+ // src/lib/tools/workflows.ts
803
+ import { z as z10 } from "zod";
804
+ var listWorkflows = KnockTool({
805
+ method: "list_workflows",
806
+ name: "List workflows",
807
+ 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.
809
+
810
+ Use this tool when you need to understand which workflows are available to be called.
811
+ `,
812
+ parameters: z10.object({
813
+ environment: z10.string().describe(
814
+ "(string): The environment to list workflows for. Defaults to `development`."
815
+ )
816
+ }),
817
+ execute: (knockClient, config) => async (params) => {
818
+ const allWorkflows = [];
819
+ const listParams = {
820
+ environment: params.environment ?? config.environment ?? "development"
821
+ };
822
+ for await (const workflow of knockClient.workflows.list(listParams)) {
823
+ allWorkflows.push(workflow);
824
+ }
825
+ return allWorkflows;
826
+ }
827
+ });
828
+ var triggerWorkflow = KnockTool({
829
+ method: "trigger_workflow",
830
+ name: "Trigger workflow",
831
+ description: `
832
+ Trigger a workflow for one or more recipients.
833
+
834
+ 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
+
836
+ When recipients aren't provided, the workflow will be triggered for the current user specified in the config.
837
+ `,
838
+ parameters: z10.object({
839
+ 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(
843
+ "(object): The tenant to trigger the workflow for. Must contain an id if being sent."
844
+ )
845
+ }),
846
+ execute: (knockClient, config) => async (params) => {
847
+ const publicClient = await knockClient.publicApi();
848
+ const result = await publicClient.workflows.trigger(params.workflowKey, {
849
+ recipients: params.recipients,
850
+ data: params.data,
851
+ tenant: params.tenant
852
+ });
853
+ return result.workflow_run_id;
854
+ }
855
+ });
856
+ var createEmailWorkflow = KnockTool({
857
+ method: "create_email_workflow",
858
+ name: "Create email workflow",
859
+ description: `
860
+ Creates a simple email workflow with a single step that sends an email to the recipient. Use this tool when you need to need to create an email notification, and you don't need to specify any additional steps. You can only create workflows in the development environment.
861
+
862
+ The content of the email you supply should ONLY ever be in markdown format for simplicity. You can supply dynamic variables to the subject and body of the email using the liquid template language.
863
+
864
+ When writing markdown, be sure to use headings (##) to separate sections of the email. Use an informal writing style, and avoid using complex language.
865
+
866
+ The following variables are available to use in the email subject and body:
867
+
868
+ - \`recipient.name\`: The name of the recipient.
869
+ - \`recipient.email\`: The email of the recipient.
870
+ - \`recipient.phone_number\`: The phone number of the recipient.
871
+ - \`tenant.id\`: The id of the tenant.
872
+ - \`tenant.name\`: The name of the tenant.
873
+
874
+ You can supply any other dynamic variables by referencing them under the \`data\` key in the \`data\` parameter when triggering the workflow. You add those like \`{{ data.variable_name }}\`.
875
+
876
+ You can also supply a list of categories to the workflow. These are used to categorize workflows for notification preferences. Categories should be supplied as lowercase strings in kebab case.
877
+
878
+ Once you've created the workflow, you should ask if you should commit the changes to the environment.
879
+ `,
880
+ parameters: z10.object({
881
+ environment: z10.string().describe(
882
+ "(string): The environment to create the workflow in. Defaults to `development`."
883
+ ),
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()).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.")
889
+ }),
890
+ execute: (knockClient, config) => async (params) => {
891
+ const emailChannelsPage = await knockClient.channels.list();
892
+ const emailChannels = emailChannelsPage.entries.filter(
893
+ (channel) => channel.type === "email"
894
+ );
895
+ if (emailChannels.length === 0) {
896
+ throw new Error("No email channels found");
897
+ }
898
+ const workflowParams = {
899
+ environment: params.environment ?? config.environment ?? "development",
900
+ workflow: {
901
+ name: params.name,
902
+ categories: params.categories ?? [],
903
+ steps: [
904
+ {
905
+ type: "channel",
906
+ channel_key: emailChannels[0].key,
907
+ template: {
908
+ settings: {
909
+ layout_key: "default"
910
+ },
911
+ subject: params.subject,
912
+ visual_blocks: [
913
+ // @ts-ignore
914
+ {
915
+ type: "markdown",
916
+ content: params.body
917
+ }
918
+ ]
919
+ },
920
+ name: "Email",
921
+ ref: "email_1"
922
+ }
923
+ ]
924
+ }
925
+ };
926
+ return await knockClient.workflows.upsert(
927
+ params.workflowKey,
928
+ workflowParams
929
+ );
930
+ }
931
+ });
932
+ var createOneOffWorkflowSchedule = KnockTool({
933
+ method: "create_one_off_workflow_schedule",
934
+ name: "Create one-off workflow schedule",
935
+ description: `
936
+ Create a one-off workflow schedule for a user. Use this tool when you need to schedule the execution of a workflow for a specific user in the future, like to power a delayed notification.
937
+
938
+ Schedules can accept a set of data that will be passed to the workflow trigger when it is executed. When the userId is not provided, the schedule will be created for the current user specified in the config.
939
+
940
+ Examples:
941
+
942
+ - In three days, send a welcome email to a user
943
+ - In one hour, send a password reset email to a user
944
+ - In two weeks, send a survey to a user
945
+ `,
946
+ parameters: z10.object({
947
+ workflowKey: z10.string().describe("(string): The key of the workflow to schedule."),
948
+ userId: z10.string().describe(
949
+ "(string): The userId of the user to schedule the workflow for."
950
+ ),
951
+ scheduledAt: z10.string().describe(
952
+ "(string): The date and time to schedule the workflow for. Must be in ISO 8601 format."
953
+ ),
954
+ data: z10.record(z10.string(), z10.any()).describe("(object): Data to pass to the workflow.")
955
+ }),
956
+ execute: (knockClient, config) => async (params) => {
957
+ const publicClient = await knockClient.publicApi();
958
+ return await publicClient.workflows.createSchedules(params.workflowKey, {
959
+ recipients: [params.userId ?? config.userId],
960
+ scheduled_at: params.scheduledAt,
961
+ data: params.data
962
+ });
963
+ }
964
+ });
965
+ var workflows = {
966
+ listWorkflows,
967
+ triggerWorkflow,
968
+ createEmailWorkflow,
969
+ createOneOffWorkflowSchedule
970
+ };
971
+ var permissions11 = {
972
+ read: ["listWorkflows"],
973
+ manage: ["createEmailWorkflow", "createOneOffWorkflowSchedule"],
974
+ trigger: ["triggerWorkflow"]
975
+ };
976
+
977
+ // src/lib/tools/index.ts
978
+ var tools = {
979
+ channels,
980
+ commits,
981
+ emailLayouts,
982
+ environments,
983
+ messages,
984
+ messageTypes,
985
+ objects,
986
+ partials,
987
+ tenants,
988
+ users,
989
+ workflows
990
+ };
991
+ var allTools = {
992
+ ...channels,
993
+ ...commits,
994
+ ...emailLayouts,
995
+ ...environments,
996
+ ...messageTypes,
997
+ ...messages,
998
+ ...objects,
999
+ ...partials,
1000
+ ...tenants,
1001
+ ...users,
1002
+ ...workflows
1003
+ };
1004
+ var toolPermissions = {
1005
+ channels: permissions,
1006
+ commits: permissions2,
1007
+ emailLayouts: permissions3,
1008
+ environments: permissions4,
1009
+ messages: permissions5,
1010
+ messageTypes: permissions6,
1011
+ objects: permissions7,
1012
+ partials: permissions8,
1013
+ tenants: permissions9,
1014
+ users: permissions10,
1015
+ workflows: permissions11
1016
+ };
1017
+
1018
+ export {
1019
+ tools,
1020
+ allTools,
1021
+ toolPermissions
1022
+ };
1023
+ //# sourceMappingURL=chunk-RPKDXX4O.js.map