@knocklabs/agent-toolkit 0.1.2 → 0.1.3

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 (83) hide show
  1. package/dist/ai-sdk/index.js +22 -1085
  2. package/dist/ai-sdk/index.js.map +1 -1
  3. package/dist/ai-sdk/tool-converter.js +3 -10
  4. package/dist/ai-sdk/tool-converter.js.map +1 -1
  5. package/dist/chunk-2CNJ4XX6.js +33 -0
  6. package/dist/chunk-2CNJ4XX6.js.map +1 -0
  7. package/dist/chunk-3LZK6RH6.js +29 -0
  8. package/dist/chunk-3LZK6RH6.js.map +1 -0
  9. package/dist/chunk-4VR65G5W.js +66 -0
  10. package/dist/chunk-4VR65G5W.js.map +1 -0
  11. package/dist/chunk-6H3BXH2Y.js +15 -0
  12. package/dist/chunk-6H3BXH2Y.js.map +1 -0
  13. package/dist/chunk-BY4KQPUO.js +39 -0
  14. package/dist/chunk-BY4KQPUO.js.map +1 -0
  15. package/dist/chunk-DSRTYV37.js +39 -0
  16. package/dist/chunk-DSRTYV37.js.map +1 -0
  17. package/dist/chunk-JTYQTWCX.js +75 -0
  18. package/dist/chunk-JTYQTWCX.js.map +1 -0
  19. package/dist/chunk-NZB2TMJW.js +92 -0
  20. package/dist/chunk-NZB2TMJW.js.map +1 -0
  21. package/dist/chunk-O6DWF42E.js +31 -0
  22. package/dist/chunk-O6DWF42E.js.map +1 -0
  23. package/dist/chunk-OD5VHBGN.js +32 -0
  24. package/dist/chunk-OD5VHBGN.js.map +1 -0
  25. package/dist/chunk-PDMA6RIB.js +19 -0
  26. package/dist/chunk-PDMA6RIB.js.map +1 -0
  27. package/dist/chunk-RYMJEH6P.js +140 -0
  28. package/dist/chunk-RYMJEH6P.js.map +1 -0
  29. package/dist/chunk-THLK376Y.js +191 -0
  30. package/dist/chunk-THLK376Y.js.map +1 -0
  31. package/dist/chunk-TLHETJRF.js +75 -0
  32. package/dist/chunk-TLHETJRF.js.map +1 -0
  33. package/dist/chunk-TOBLV65T.js +30 -0
  34. package/dist/chunk-TOBLV65T.js.map +1 -0
  35. package/dist/chunk-VJFA3ZVW.js +210 -0
  36. package/dist/chunk-VJFA3ZVW.js.map +1 -0
  37. package/dist/chunk-WB4XCCUS.js +19 -0
  38. package/dist/chunk-WB4XCCUS.js.map +1 -0
  39. package/dist/chunk-XRQWR3LY.js +184 -0
  40. package/dist/chunk-XRQWR3LY.js.map +1 -0
  41. package/dist/chunk-XUYE3AGB.js +27 -0
  42. package/dist/chunk-XUYE3AGB.js.map +1 -0
  43. package/dist/lib/knock-client.js +3 -24
  44. package/dist/lib/knock-client.js.map +1 -1
  45. package/dist/lib/knock-tool.js +3 -25
  46. package/dist/lib/knock-tool.js.map +1 -1
  47. package/dist/lib/tools/channels.js +5 -49
  48. package/dist/lib/tools/channels.js.map +1 -1
  49. package/dist/lib/tools/commits.js +5 -93
  50. package/dist/lib/tools/commits.js.map +1 -1
  51. package/dist/lib/tools/email-layouts.js +5 -55
  52. package/dist/lib/tools/email-layouts.js.map +1 -1
  53. package/dist/lib/tools/environments.js +5 -47
  54. package/dist/lib/tools/environments.js.map +1 -1
  55. package/dist/lib/tools/index.js +17 -1016
  56. package/dist/lib/tools/index.js.map +1 -1
  57. package/dist/lib/tools/message-types.js +5 -209
  58. package/dist/lib/tools/message-types.js.map +1 -1
  59. package/dist/lib/tools/messages.js +5 -50
  60. package/dist/lib/tools/messages.js.map +1 -1
  61. package/dist/lib/tools/objects.js +5 -158
  62. package/dist/lib/tools/objects.js.map +1 -1
  63. package/dist/lib/tools/partials.js +5 -55
  64. package/dist/lib/tools/partials.js.map +1 -1
  65. package/dist/lib/tools/tenants.js +5 -93
  66. package/dist/lib/tools/tenants.js.map +1 -1
  67. package/dist/lib/tools/users.js +5 -228
  68. package/dist/lib/tools/users.js.map +1 -1
  69. package/dist/lib/tools/workflows.js +5 -202
  70. package/dist/lib/tools/workflows.js.map +1 -1
  71. package/dist/lib/utils.js +18 -1071
  72. package/dist/lib/utils.js.map +1 -1
  73. package/dist/modelcontextprotocol/adapter.js +3 -22
  74. package/dist/modelcontextprotocol/adapter.js.map +1 -1
  75. package/dist/modelcontextprotocol/index.js +17 -976
  76. package/dist/modelcontextprotocol/index.js.map +1 -1
  77. package/dist/modelcontextprotocol/local-server.js +25 -1041
  78. package/dist/modelcontextprotocol/local-server.js.map +1 -1
  79. package/dist/openai/index.js +22 -1089
  80. package/dist/openai/index.js.map +1 -1
  81. package/dist/openai/tool-converter.js +3 -14
  82. package/dist/openai/tool-converter.js.map +1 -1
  83. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/tools/objects.ts","../../../src/lib/knock-tool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { KnockTool } from \"../knock-tool.js\";\n\nconst listObjects = KnockTool({\n method: \"list_objects\",\n name: \"List objects\",\n description:\n \"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.\",\n parameters: z.object({\n collection: z\n .string()\n .describe(\"(string): The collection to list objects from.\"),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n return await publicClient.objects.list(params.collection);\n },\n});\n\nconst getObject = KnockTool({\n method: \"get_object\",\n name: \"Get object\",\n description:\n \"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.\",\n parameters: z.object({\n collection: z\n .string()\n .describe(\"(string): The collection to get the object from.\"),\n objectId: z.string().describe(\"(string): The ID of the object to get.\"),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n return await publicClient.objects.get(params.collection, params.objectId);\n },\n});\n\nconst createOrUpdateObject = KnockTool({\n method: \"create_or_update_object\",\n name: \"Create or update object\",\n 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.\n \n 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.`,\n parameters: z.object({\n collection: z\n .string()\n .describe(\"(string): The collection to create or update the object in.\"),\n objectId: z\n .string()\n .describe(\"(string): The ID of the object to create or update.\"),\n properties: z\n .record(z.string(), z.any())\n .describe(\"(object): The properties to set on the object.\"),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n return await publicClient.objects.set(\n params.collection,\n params.objectId,\n params.properties\n );\n },\n});\n\nconst deleteObject = KnockTool({\n method: \"delete_object\",\n name: \"Delete object\",\n description: `Delete an object from a specific collection. Use this tool when you need to remove an object from the system.`,\n parameters: z.object({\n collection: z\n .string()\n .describe(\"(string): The collection to delete the object from.\"),\n objectId: z.string().describe(\"(string): The ID of the object to delete.\"),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n await publicClient.objects.delete(params.collection, params.objectId);\n return { success: true };\n },\n});\n\nconst subscribeUsersToObject = KnockTool({\n method: \"subscribe_users_to_object\",\n name: \"Subscribe users to object\",\n description: `\n 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.\n \n 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.\n\n Before using this tool, you should create the object in the collection using the createOrUpdateObject tool.\n `,\n parameters: z.object({\n collection: z\n .string()\n .describe(\"(string): The collection to subscribe the user to.\"),\n objectId: z\n .string()\n .describe(\"(string): The ID of the object to subscribe the user to.\"),\n userIds: z\n .array(z.string())\n .describe(\n \"(array): The IDs of the users to subscribe to the object. If not provided, the current user will be subscribed.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n return await publicClient.objects.addSubscriptions(\n params.collection,\n params.objectId,\n {\n recipients: params.userIds ?? [config.userId],\n }\n );\n },\n});\n\nconst unsubscribeUsersFromObject = KnockTool({\n method: \"unsubscribe_users_from_object\",\n name: \"Unsubscribe users from object\",\n 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.\n \n 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.`,\n parameters: z.object({\n collection: z\n .string()\n .describe(\"(string): The collection to unsubscribe the user from.\"),\n objectId: z\n .string()\n .describe(\"(string): The ID of the object to unsubscribe the user from.\"),\n userIds: z\n .array(z.string())\n .describe(\n \"(array): The IDs of the users to unsubscribe from the object.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n return await publicClient.objects.deleteSubscriptions(\n params.collection,\n params.objectId,\n {\n recipients: params.userIds ?? [config.userId],\n }\n );\n },\n});\n\nexport const objects = {\n listObjects,\n getObject,\n createOrUpdateObject,\n deleteObject,\n subscribeUsersToObject,\n unsubscribeUsersFromObject,\n};\n\nexport const permissions = {\n read: [\"listObjects\", \"getObject\"],\n manage: [\n \"createOrUpdateObject\",\n \"deleteObject\",\n \"subscribeUsersToObject\",\n \"unsubscribeUsersFromObject\",\n ],\n};\n","import type { ZodObject } from \"zod\";\nimport { z } from \"zod\";\nimport { Config } from \"../types.js\";\nimport { KnockClient } from \"./knock-client.js\";\n\nexport interface KnockToolDefinition {\n /**\n * The method name of the tool. This is a machine-readable string.\n */\n method: string;\n /**\n * The name of the tool. This can be used to reference the tool in the code.\n * A descriptive LLM-readable string.\n */\n name: string;\n\n /**\n * A descriptive prompt explaining the tool's purpose, including examples where useful.\n */\n description: string;\n\n /**\n * A descriptive prompt explaining the tool's purpose, usage and input parameters.\n * Ths is intended to be used by the underlying LLM.\n */\n fullDescription: string;\n\n /**\n * The Zod schema for the input parameters of the tool\n */\n parameters?: ZodObject<any>;\n /**\n * The actual implementation of the tool.\n */\n execute: (\n knockClient: KnockClient,\n config: Config\n ) => (input: any) => Promise<unknown>;\n}\n\nexport interface KnockTool extends Omit<KnockToolDefinition, \"execute\"> {\n bindExecute: (\n knockClient: KnockClient,\n config: Config\n ) => (input: any) => Promise<unknown>;\n}\n\nconst trimLines = (text: string) =>\n text\n .split(\"\\n\")\n .map((l) => l.trim())\n .filter(Boolean)\n .join(\"\\n\");\n\nexport const KnockTool = (\n args: Omit<KnockToolDefinition, \"fullDescription\">\n): KnockTool => {\n const { execute, ...restOfArgs } = args;\n const parameters = restOfArgs.parameters\n ? restOfArgs.parameters\n : z.object({});\n\n const schemaEntries = Object.entries(parameters.shape);\n\n const argsStr =\n schemaEntries.length === 0\n ? \"Takes no arguments\"\n : schemaEntries\n .map(([key, value]) => {\n return `- ${key}: ${(value as any).description || \"\"}`;\n })\n .join(\"\\n\");\n\n const fullDescription = trimLines(`\n Tool name:\n ${args.name}\n Description:\n ${args.description}.\n Arguments:\n ${argsStr}\n `);\n\n return {\n ...restOfArgs,\n parameters,\n fullDescription,\n bindExecute: (knockClient: KnockClient, config: Config) =>\n execute(knockClient, config),\n };\n};\n"],"mappings":";AAAA,SAAS,KAAAA,UAAS;;;ACClB,SAAS,SAAS;AA8ClB,IAAM,YAAY,CAAC,SACjB,KACG,MAAM,IAAI,EACV,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EACnB,OAAO,OAAO,EACd,KAAK,IAAI;AAEP,IAAM,YAAY,CACvB,SACc;AACd,QAAM,EAAE,SAAS,GAAG,WAAW,IAAI;AACnC,QAAM,aAAa,WAAW,aAC1B,WAAW,aACX,EAAE,OAAO,CAAC,CAAC;AAEf,QAAM,gBAAgB,OAAO,QAAQ,WAAW,KAAK;AAErD,QAAM,UACJ,cAAc,WAAW,IACrB,uBACA,cACG,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACrB,WAAO,KAAK,GAAG,KAAM,MAAc,eAAe,EAAE;AAAA,EACtD,CAAC,EACA,KAAK,IAAI;AAElB,QAAM,kBAAkB,UAAU;AAAA;AAAA,IAEhC,KAAK,IAAI;AAAA;AAAA,IAET,KAAK,WAAW;AAAA;AAAA,IAEhB,OAAO;AAAA,GACR;AAED,SAAO;AAAA,IACL,G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AA,EAGb,YAAYA,GAAE,OAAO;AAAA,IACnB,YAAYA,GACT,OAAO,EACP,SAAS,wDAAwD;AAAA,IACpE,UAAUA,GACP,OAAO,EACP,SAAS,8DAA8D;AAAA,IAC1E,SAASA,GACN,MAAMA,GAAE,OAAO,CAAC,EAChB;AAAA,MACC;AAAA,IACF;AAAA,EACJ,CAAC;AAAA,EACD,SAAS,CAAC,aAAa,WAAW,OAAO,WAAW;AAClD,UAAM,eAAe,MAAM,YAAY,UAAU;AACjD,WAAO,MAAM,aAAa,QAAQ;AAAA,MAChC,OAAO;AAAA,MACP,OAAO;AAAA,MACP;AAAA,QACE,YAAY,OAAO,WAAW,CAAC,OAAO,MAAM;AAAA,MAC9C;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAEM,IAAM,UAAU;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,cAAc;AAAA,EACzB,MAAM,CAAC,eAAe,WAAW;AAAA,EACjC,QAAQ;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["z","z"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,58 +1,8 @@
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/partials.ts
28
- import { z as z2 } from "zod";
29
- var listPartials = KnockTool({
30
- method: "list_partials",
31
- name: "List partials",
32
- 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.
33
-
34
- 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.`,
35
- parameters: z2.object({
36
- environment: z2.string().describe(
37
- "(string): The environment to list partials for. Defaults to `development`."
38
- )
39
- }),
40
- execute: (knockClient, config) => async (params) => {
41
- const allPartials = [];
42
- for await (const partial of knockClient.partials.list({
43
- environment: params.environment ?? config.environment ?? "development"
44
- })) {
45
- allPartials.push(partial);
46
- }
47
- return allPartials;
48
- }
49
- });
50
- var partials = {
51
- listPartials
52
- };
53
- var permissions = {
54
- read: ["listPartials"]
55
- };
1
+ import {
2
+ partials,
3
+ permissions
4
+ } from "../../chunk-BY4KQPUO.js";
5
+ import "../../chunk-TOBLV65T.js";
56
6
  export {
57
7
  partials,
58
8
  permissions
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/knock-tool.ts","../../../src/lib/tools/partials.ts"],"sourcesContent":["import type { ZodObject } from \"zod\";\nimport { z } from \"zod\";\nimport { Config } from \"../types.js\";\nimport { KnockClient } from \"./knock-client.js\";\n\nexport interface KnockToolDefinition {\n /**\n * The method name of the tool. This is a machine-readable string.\n */\n method: string;\n /**\n * The name of the tool. This can be used to reference the tool in the code.\n * A descriptive LLM-readable string.\n */\n name: string;\n\n /**\n * A descriptive prompt explaining the tool's purpose, including examples where useful.\n */\n description: string;\n\n /**\n * A descriptive prompt explaining the tool's purpose, usage and input parameters.\n * Ths is intended to be used by the underlying LLM.\n */\n fullDescription: string;\n\n /**\n * The Zod schema for the input parameters of the tool\n */\n parameters?: ZodObject<any>;\n /**\n * The actual implementation of the tool.\n */\n execute: (\n knockClient: KnockClient,\n config: Config\n ) => (input: any) => Promise<unknown>;\n}\n\nexport interface KnockTool extends Omit<KnockToolDefinition, \"execute\"> {\n bindExecute: (\n knockClient: KnockClient,\n config: Config\n ) => (input: any) => Promise<unknown>;\n}\n\nconst trimLines = (text: string) =>\n text\n .split(\"\\n\")\n .map((l) => l.trim())\n .filter(Boolean)\n .join(\"\\n\");\n\nexport const KnockTool = (\n args: Omit<KnockToolDefinition, \"fullDescription\">\n): KnockTool => {\n const { execute, ...restOfArgs } = args;\n const parameters = restOfArgs.parameters\n ? restOfArgs.parameters\n : z.object({});\n\n const schemaEntries = Object.entries(parameters.shape);\n\n const argsStr =\n schemaEntries.length === 0\n ? \"Takes no arguments\"\n : schemaEntries\n .map(([key, value]) => {\n return `- ${key}: ${(value as any).description || \"\"}`;\n })\n .join(\"\\n\");\n\n const fullDescription = trimLines(`\n Tool name:\n ${args.name}\n Description:\n ${args.description}.\n Arguments:\n ${argsStr}\n `);\n\n return {\n ...restOfArgs,\n parameters,\n fullDescription,\n bindExecute: (knockClient: KnockClient, config: Config) =>\n execute(knockClient, config),\n };\n};\n","import { KnockTool } from \"../knock-tool.js\";\nimport { z } from \"zod\";\nimport { Partial } from \"@knocklabs/mgmt/resources/partials.js\";\n\nconst listPartials = KnockTool({\n method: \"list_partials\",\n name: \"List partials\",\n 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.\n \n 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.`,\n parameters: z.object({\n environment: z\n .string()\n .describe(\n \"(string): The environment to list partials for. Defaults to `development`.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const allPartials: Partial[] = [];\n for await (const partial of knockClient.partials.list({\n environment: params.environment ?? config.environment ?? \"development\",\n })) {\n allPartials.push(partial);\n }\n return allPartials;\n },\n});\n\nexport const partials = {\n listPartials,\n};\n\nexport const permissions = {\n read: [\"listPartials\"],\n};\n"],"mappings":";AACA,SAAS,SAAS;AA8ClB,IAAM,YAAY,CAAC,SACjB,KACG,MAAM,I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ACvB;","names":["z"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,96 +1,8 @@
1
- // src/lib/tools/tenants.ts
2
- import { z as z2 } from "zod";
3
-
4
- // src/lib/knock-tool.ts
5
- import { z } from "zod";
6
- var trimLines = (text) => text.split("\n").map((l) => l.trim()).filter(Boolean).join("\n");
7
- var KnockTool = (args) => {
8
- const { execute, ...restOfArgs } = args;
9
- const parameters = restOfArgs.parameters ? restOfArgs.parameters : z.object({});
10
- const schemaEntries = Object.entries(parameters.shape);
11
- const argsStr = schemaEntries.length === 0 ? "Takes no arguments" : schemaEntries.map(([key, value]) => {
12
- return `- ${key}: ${value.description || ""}`;
13
- }).join("\n");
14
- const fullDescription = trimLines(`
15
- Tool name:
16
- ${args.name}
17
- Description:
18
- ${args.description}.
19
- Arguments:
20
- ${argsStr}
21
- `);
22
- return {
23
- ...restOfArgs,
24
- parameters,
25
- fullDescription,
26
- bindExecute: (knockClient, config) => execute(knockClient, config)
27
- };
28
- };
29
-
30
- // src/lib/tools/tenants.ts
31
- var getTenant = KnockTool({
32
- method: "get_tenant",
33
- name: "Get tenant",
34
- description: `
35
- 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.
36
-
37
- Use this tool when you need to lookup the information about a tenant, including name, and if there are any custom properties set.
38
- `,
39
- parameters: z2.object({
40
- tenantId: z2.string().describe("(string): The ID of the tenant to retrieve.")
41
- }),
42
- execute: (knockClient) => async (params) => {
43
- const publicClient = await knockClient.publicApi();
44
- return await publicClient.tenants.get(params.tenantId);
45
- }
46
- });
47
- var setTenant = KnockTool({
48
- method: "set_tenant",
49
- name: "Set tenant",
50
- description: `
51
- 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.
52
-
53
- Use this tool when you need to create a new tenant, or update an existing tenant's properties.
54
- `,
55
- parameters: z2.object({
56
- tenantId: z2.string().describe("(string): The ID of the tenant to update."),
57
- name: z2.string().describe("(string): The name of the tenant."),
58
- properties: z2.record(z2.string(), z2.any()).describe("(object): The properties to set on the tenant.")
59
- }),
60
- execute: (knockClient) => async (params) => {
61
- const publicClient = await knockClient.publicApi();
62
- return await publicClient.tenants.set(params.tenantId, {
63
- name: params.name,
64
- ...params.properties
65
- });
66
- }
67
- });
68
- var deleteTenant = KnockTool({
69
- method: "delete_tenant",
70
- name: "Delete tenant",
71
- description: `
72
- Deletes a tenant. Tenants in Knock are used to model organizations, teams, and other groups of users. They are a special type of object.
73
-
74
- Use this tool when you've been asked to remove a tenant from the system.
75
- `,
76
- parameters: z2.object({
77
- tenantId: z2.string().describe("(string): The ID of the tenant to delete.")
78
- }),
79
- execute: (knockClient) => async (params) => {
80
- const publicClient = await knockClient.publicApi();
81
- await publicClient.tenants.delete(params.tenantId);
82
- return { success: true };
83
- }
84
- });
85
- var tenants = {
86
- getTenant,
87
- setTenant,
88
- deleteTenant
89
- };
90
- var permissions = {
91
- read: ["getTenant"],
92
- manage: ["setTenant", "deleteTenant"]
93
- };
1
+ import {
2
+ permissions,
3
+ tenants
4
+ } from "../../chunk-JTYQTWCX.js";
5
+ import "../../chunk-TOBLV65T.js";
94
6
  export {
95
7
  permissions,
96
8
  tenants
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/tools/tenants.ts","../../../src/lib/knock-tool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { KnockTool } from \"../knock-tool.js\";\n\nconst getTenant = KnockTool({\n method: \"get_tenant\",\n name: \"Get tenant\",\n description: `\n 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.\n \n Use this tool when you need to lookup the information about a tenant, including name, and if there are any custom properties set.\n `,\n parameters: z.object({\n tenantId: z\n .string()\n .describe(\"(string): The ID of the tenant to retrieve.\"),\n }),\n execute: (knockClient) => async (params) => {\n const publicClient = await knockClient.publicApi();\n return await publicClient.tenants.get(params.tenantId);\n },\n});\n\nconst setTenant = KnockTool({\n method: \"set_tenant\",\n name: \"Set tenant\",\n description: `\n 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.\n \n Use this tool when you need to create a new tenant, or update an existing tenant's properties.\n `,\n parameters: z.object({\n tenantId: z.string().describe(\"(string): The ID of the tenant to update.\"),\n name: z.string().describe(\"(string): The name of the tenant.\"),\n properties: z\n .record(z.string(), z.any())\n .describe(\"(object): The properties to set on the tenant.\"),\n }),\n execute: (knockClient) => async (params) => {\n const publicClient = await knockClient.publicApi();\n return await publicClient.tenants.set(params.tenantId, {\n name: params.name,\n ...params.properties,\n });\n },\n});\n\nconst deleteTenant = KnockTool({\n method: \"delete_tenant\",\n name: \"Delete tenant\",\n description: `\n Deletes a tenant. Tenants in Knock are used to model organizations, teams, and other groups of users. They are a special type of object.\n \n Use this tool when you've been asked to remove a tenant from the system.\n `,\n parameters: z.object({\n tenantId: z.string().describe(\"(string): The ID of the tenant to delete.\"),\n }),\n execute: (knockClient) => async (params) => {\n const publicClient = await knockClient.publicApi();\n await publicClient.tenants.delete(params.tenantId);\n return { success: true };\n },\n});\n\nexport const tenants = {\n getTenant,\n setTenant,\n deleteTenant,\n};\n\nexport const permissions = {\n read: [\"getTenant\"],\n manage: [\"setTenant\", \"deleteTenant\"],\n};\n","import type { ZodObject } from \"zod\";\nimport { z } from \"zod\";\nimport { Config } from \"../types.js\";\nimport { KnockClient } from \"./knock-client.js\";\n\nexport interface KnockToolDefinition {\n /**\n * The method name of the tool. This is a machine-readable string.\n */\n method: string;\n /**\n * The name of the tool. This can be used to reference the tool in the code.\n * A descriptive LLM-readable string.\n */\n name: string;\n\n /**\n * A descriptive prompt explaining the tool's purpose, including examples where useful.\n */\n description: string;\n\n /**\n * A descriptive prompt explaining the tool's purpose, usage and input parameters.\n * Ths is intended to be used by the underlying LLM.\n */\n fullDescription: string;\n\n /**\n * The Zod schema for the input parameters of the tool\n */\n parameters?: ZodObject<any>;\n /**\n * The actual implementation of the tool.\n */\n execute: (\n knockClient: KnockClient,\n config: Config\n ) => (input: any) => Promise<unknown>;\n}\n\nexport interface KnockTool extends Omit<KnockToolDefinition, \"execute\"> {\n bindExecute: (\n knockClient: KnockClient,\n config: Config\n ) => (input: any) => Promise<unknown>;\n}\n\nconst trimLines = (text: string) =>\n text\n .split(\"\\n\")\n .map((l) => l.trim())\n .filter(Boolean)\n .join(\"\\n\");\n\nexport const KnockTool = (\n args: Omit<KnockToolDefinition, \"fullDescription\">\n): KnockTool => {\n const { execute, ...restOfArgs } = args;\n const parameters = restOfArgs.parameters\n ? restOfArgs.parameters\n : z.object({});\n\n const schemaEntries = Object.entries(parameters.shape);\n\n const argsStr =\n schemaEntries.length === 0\n ? \"Takes no arguments\"\n : schemaEntries\n .map(([key, value]) => {\n return `- ${key}: ${(value as any).description || \"\"}`;\n })\n .join(\"\\n\");\n\n const fullDescription = trimLines(`\n Tool name:\n ${args.name}\n Description:\n ${args.description}.\n Arguments:\n ${argsStr}\n `);\n\n return {\n ...restOfArgs,\n parameters,\n fullDescription,\n bindExecute: (knockClient: KnockClient, config: Config) =>\n execute(knockClient, config),\n };\n};\n"],"mappings":";AAAA,SAAS,KAAAA,UAAS;;;ACClB,SAAS,SAAS;AA8ClB,IAAM,YAAY,CAAC,SACjB,KACG,MAAM,IAAI,EACV,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EACnB,OAAO,OAAO,EACd,KAAK,IAAI;AAEP,IAAM,YAAY,CACvB,SACc;AACd,QAAM,EAAE,SAAS,GAAG,WAAW,IAAI;AACnC,QAAM,aAAa,WAAW,aAC1B,WAAW,aACX,EAAE,OAAO,CAAC,CAAC;AAEf,QAAM,gBAAgB,OAAO,QAAQ,WAAW,KAAK;AAErD,QAAM,UACJ,cAAc,WAAW,IACrB,uBACA,cACG,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACrB,WAAO,KAAK,GAAG,KAAM,MAAc,eAAe,EAAE;AAAA,EACtD,CAAC,EACA,KAAK,IAAI;AAElB,QAAM,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;AAAA;AAAA;AAAA;AAAA;AAAA,EAKb,YAAYA,GAAE,OAAO;AAAA,IACnB,UAAUA,GAAE,OAAO,EAAE,SAAS,2CAA2C;AAAA,EAC3E,CAAC;AAAA,EACD,SAAS,CAAC,gBAAgB,OAAO,WAAW;AAC1C,UAAM,eAAe,MAAM,YAAY,UAAU;AACjD,UAAM,aAAa,QAAQ,OAAO,OAAO,QAAQ;AACjD,WAAO,EAAE,SAAS,KAAK;AAAA,EACzB;AACF,CAAC;AAEM,IAAM,UAAU;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,cAAc;AAAA,EACzB,MAAM,CAAC,WAAW;AAAA,EAClB,QAAQ,CAAC,aAAa,cAAc;AACtC;","names":["z","z"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,231 +1,8 @@
1
- // src/lib/tools/users.ts
2
- import { z as z2 } from "zod";
3
-
4
- // src/lib/knock-tool.ts
5
- import { z } from "zod";
6
- var trimLines = (text) => text.split("\n").map((l) => l.trim()).filter(Boolean).join("\n");
7
- var KnockTool = (args) => {
8
- const { execute, ...restOfArgs } = args;
9
- const parameters = restOfArgs.parameters ? restOfArgs.parameters : z.object({});
10
- const schemaEntries = Object.entries(parameters.shape);
11
- const argsStr = schemaEntries.length === 0 ? "Takes no arguments" : schemaEntries.map(([key, value]) => {
12
- return `- ${key}: ${value.description || ""}`;
13
- }).join("\n");
14
- const fullDescription = trimLines(`
15
- Tool name:
16
- ${args.name}
17
- Description:
18
- ${args.description}.
19
- Arguments:
20
- ${argsStr}
21
- `);
22
- return {
23
- ...restOfArgs,
24
- parameters,
25
- fullDescription,
26
- bindExecute: (knockClient, config) => execute(knockClient, config)
27
- };
28
- };
29
-
30
- // src/lib/tools/users.ts
31
- var getUser = KnockTool({
32
- method: "get_user",
33
- name: "Get user",
34
- description: `
35
- 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.
36
-
37
- If the userId is not provided, it will use the userId from the config.
38
- `,
39
- parameters: z2.object({
40
- userId: z2.string().describe("(string): The userId of the User to retrieve.")
41
- }),
42
- execute: (knockClient, config) => async (params) => {
43
- const publicClient = await knockClient.publicApi();
44
- return await publicClient.users.get(params.userId ?? config.userId);
45
- }
46
- });
47
- var createOrUpdateUser = KnockTool({
48
- method: "create_or_update_user",
49
- name: "Create or update user",
50
- description: `
51
- 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.
52
-
53
- Use this tool when you need to update a user's profile.
54
-
55
- If the userId is not provided, it will use the userId from the config.
56
- `,
57
- parameters: z2.object({
58
- userId: z2.string().describe("(string): The userId of the User to update."),
59
- email: z2.string().describe("(string): The email of the User to update."),
60
- name: z2.string().describe("(string): The name of the User to update."),
61
- phoneNumber: z2.string().describe("(string): The phone number of the User to update."),
62
- customProperties: z2.record(z2.string(), z2.any()).describe(
63
- "(object): A dictionary of custom properties to update for the User."
64
- )
65
- }),
66
- execute: (knockClient, config) => async (params) => {
67
- const publicClient = await knockClient.publicApi();
68
- return await publicClient.users.identify(params.userId, {
69
- email: params.email,
70
- name: params.name,
71
- phone_number: params.phoneNumber,
72
- ...params.customProperties ?? {}
73
- });
74
- }
75
- });
76
- var deleteUser = KnockTool({
77
- method: "delete_user",
78
- name: "Delete user",
79
- description: `
80
- Deletes a user. Use this tool when you've been asked to remove a user from the system.
81
- `,
82
- parameters: z2.object({
83
- userId: z2.string().describe("(string): The userId of the User to delete.")
84
- }),
85
- execute: (knockClient, config) => async (params) => {
86
- const publicClient = await knockClient.publicApi();
87
- await publicClient.users.delete(params.userId);
88
- return { success: true };
89
- }
90
- });
91
- var getUserPreferences = KnockTool({
92
- method: "get_user_preferences",
93
- name: "Get user preferences",
94
- description: `
95
- Retrieves the user's notification preferences for the given userId.
96
-
97
- If the userId is not provided, it will use the userId from the config.
98
- `,
99
- parameters: z2.object({
100
- userId: z2.string().describe(
101
- "(string): The userId of the User to retrieve Preferences for."
102
- ),
103
- preferenceSetId: z2.string().describe(
104
- "(string): The preferenceSetId of the User to retrieve preferences for. Defaults to `default`."
105
- )
106
- }),
107
- execute: (knockClient, config) => async (params) => {
108
- const publicClient = await knockClient.publicApi();
109
- return await publicClient.users.getPreferences(
110
- params.userId ?? config.userId,
111
- {
112
- preferenceSet: params.preferenceSetId ?? "default"
113
- }
114
- );
115
- }
116
- });
117
- var setUserPreferences = KnockTool({
118
- method: "set_user_preferences",
119
- name: "Set user preferences",
120
- description: `
121
- 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.
122
-
123
- If the userId is not provided, it will use the userId from the config.
124
-
125
- Instructions:
126
-
127
- - You must ALWAYS provide a full preference set to this tool.
128
- - When setting per-workflow preferences, the key in the object should be the workflow key.
129
- - Workflow and category preferences should always have channel types underneath.
130
- - The channel types available to you are: email, sms, push, chat, and in_app_feed.
131
- - To turn OFF a preference, you must set it to false.
132
- - To turn ON a preference, you must set it to true.
133
-
134
- <examples>
135
- <example>
136
- <description>
137
- Update the user's preferences to turn off email notifications for the "welcome" workflow.
138
- </description>
139
- <input>
140
- {
141
- "workflows": {
142
- "welcome": {
143
- "channel_types": {
144
- "email": false
145
- }
146
- }
147
- }
148
- }
149
- </example>
150
- </examples>
151
- `,
152
- parameters: z2.object({
153
- userId: z2.string().describe("(string): The userId of the User to update preferences for."),
154
- workflows: z2.record(z2.string(), z2.any()).describe(
155
- "(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."
156
- ),
157
- categories: z2.record(z2.string(), z2.any()).describe(
158
- "(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."
159
- ),
160
- channel_types: z2.record(z2.string(), z2.boolean()).describe(
161
- "(object): The channel types to update where the key is the channel type, and the value of the object is a boolean value."
162
- )
163
- }),
164
- execute: (knockClient, config) => async (params) => {
165
- const publicClient = await knockClient.publicApi();
166
- const existingPreferences = await publicClient.users.getPreferences(
167
- params.userId ?? config.userId,
168
- {
169
- preferenceSet: "default"
170
- }
171
- );
172
- const updatedPreferences = {
173
- ...existingPreferences,
174
- workflows: {
175
- ...existingPreferences.workflows,
176
- ...params.workflows
177
- },
178
- categories: {
179
- ...existingPreferences.categories,
180
- ...params.categories
181
- },
182
- channel_types: {
183
- ...existingPreferences.channel_types,
184
- ...params.channel_types
185
- }
186
- };
187
- return await publicClient.users.setPreferences(
188
- params.userId ?? config.userId,
189
- updatedPreferences
190
- );
191
- }
192
- });
193
- var getUserMessages = KnockTool({
194
- method: "get_user_messages",
195
- name: "Get user messages",
196
- description: `
197
- 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.
198
-
199
- If the userId is not provided, it will use the userId from the config.
200
- `,
201
- parameters: z2.object({
202
- userId: z2.string().describe("(string): The userId of the User to retrieve messages for."),
203
- workflowRunId: z2.string().describe(
204
- "(string): The workflowRunId of the User to retrieve. Use this when you want to retrieve messages sent from a workflow trigger."
205
- )
206
- }),
207
- execute: (knockClient, config) => async (params) => {
208
- const publicClient = await knockClient.publicApi();
209
- return await publicClient.users.getMessages(
210
- params.userId ?? config.userId,
211
- {
212
- workflow_run_id: params.workflowRunId
213
- }
214
- );
215
- }
216
- });
217
- var users = {
218
- getUser,
219
- deleteUser,
220
- createOrUpdateUser,
221
- getUserPreferences,
222
- setUserPreferences,
223
- getUserMessages
224
- };
225
- var permissions = {
226
- read: ["getUser", "getUserPreferences", "getUserMessages"],
227
- manage: ["createOrUpdateUser", "deleteUser", "setUserPreferences"]
228
- };
1
+ import {
2
+ permissions,
3
+ users
4
+ } from "../../chunk-VJFA3ZVW.js";
5
+ import "../../chunk-TOBLV65T.js";
229
6
  export {
230
7
  permissions,
231
8
  users
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/tools/users.ts","../../../src/lib/knock-tool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { KnockTool } from \"../knock-tool.js\";\n\nconst getUser = KnockTool({\n method: \"get_user\",\n name: \"Get user\",\n description: `\n 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.\n\n If the userId is not provided, it will use the userId from the config.\n `,\n parameters: z.object({\n userId: z\n .string()\n .describe(\"(string): The userId of the User to retrieve.\"),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n\n return await publicClient.users.get(params.userId ?? config.userId);\n },\n});\n\nconst createOrUpdateUser = KnockTool({\n method: \"create_or_update_user\",\n name: \"Create or update user\",\n description: `\n 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.\n \n Use this tool when you need to update a user's profile.\n\n If the userId is not provided, it will use the userId from the config.\n `,\n parameters: z.object({\n userId: z.string().describe(\"(string): The userId of the User to update.\"),\n email: z.string().describe(\"(string): The email of the User to update.\"),\n name: z.string().describe(\"(string): The name of the User to update.\"),\n phoneNumber: z\n .string()\n .describe(\"(string): The phone number of the User to update.\"),\n customProperties: z\n .record(z.string(), z.any())\n .describe(\n \"(object): A dictionary of custom properties to update for the User.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n\n return await publicClient.users.identify(params.userId, {\n email: params.email,\n name: params.name,\n phone_number: params.phoneNumber,\n ...(params.customProperties ?? {}),\n });\n },\n});\n\nconst deleteUser = KnockTool({\n method: \"delete_user\",\n name: \"Delete user\",\n description: `\n Deletes a user. Use this tool when you've been asked to remove a user from the system.\n `,\n parameters: z.object({\n userId: z.string().describe(\"(string): The userId of the User to delete.\"),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n await publicClient.users.delete(params.userId);\n return { success: true };\n },\n});\n\nconst getUserPreferences = KnockTool({\n method: \"get_user_preferences\",\n name: \"Get user preferences\",\n description: `\n Retrieves the user's notification preferences for the given userId.\n\n If the userId is not provided, it will use the userId from the config. \n `,\n parameters: z.object({\n userId: z\n .string()\n .describe(\n \"(string): The userId of the User to retrieve Preferences for.\"\n ),\n preferenceSetId: z\n .string()\n .describe(\n \"(string): The preferenceSetId of the User to retrieve preferences for. Defaults to `default`.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n\n return await publicClient.users.getPreferences(\n params.userId ?? config.userId,\n {\n preferenceSet: params.preferenceSetId ?? \"default\",\n }\n );\n },\n});\n\nconst setUserPreferences = KnockTool({\n method: \"set_user_preferences\",\n name: \"Set user preferences\",\n description: `\n 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.\n\n If the userId is not provided, it will use the userId from the config.\n\n Instructions:\n\n - You must ALWAYS provide a full preference set to this tool.\n - When setting per-workflow preferences, the key in the object should be the workflow key.\n - Workflow and category preferences should always have channel types underneath.\n - The channel types available to you are: email, sms, push, chat, and in_app_feed.\n - To turn OFF a preference, you must set it to false.\n - To turn ON a preference, you must set it to true.\n\n <examples>\n <example>\n <description>\n Update the user's preferences to turn off email notifications for the \"welcome\" workflow.\n </description>\n <input>\n {\n \"workflows\": {\n \"welcome\": {\n \"channel_types\": {\n \"email\": false\n }\n }\n }\n }\n </example>\n </examples>\n `,\n parameters: z.object({\n userId: z\n .string()\n .describe(\"(string): The userId of the User to update preferences for.\"),\n workflows: z\n .record(z.string(), z.any())\n .describe(\n \"(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.\"\n ),\n categories: z\n .record(z.string(), z.any())\n .describe(\n \"(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.\"\n ),\n channel_types: z\n .record(z.string(), z.boolean())\n .describe(\n \"(object): The channel types to update where the key is the channel type, and the value of the object is a boolean value.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n\n const existingPreferences = await publicClient.users.getPreferences(\n params.userId ?? config.userId,\n {\n preferenceSet: \"default\",\n }\n );\n\n const updatedPreferences = {\n ...existingPreferences,\n workflows: {\n ...existingPreferences.workflows,\n ...params.workflows,\n },\n categories: {\n ...existingPreferences.categories,\n ...params.categories,\n },\n channel_types: {\n ...existingPreferences.channel_types,\n ...params.channel_types,\n },\n };\n\n return await publicClient.users.setPreferences(\n params.userId ?? config.userId,\n updatedPreferences\n );\n },\n});\n\nconst getUserMessages = KnockTool({\n method: \"get_user_messages\",\n name: \"Get user messages\",\n description: `\n 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.\n\n If the userId is not provided, it will use the userId from the config.\n `,\n parameters: z.object({\n userId: z\n .string()\n .describe(\"(string): The userId of the User to retrieve messages for.\"),\n workflowRunId: z\n .string()\n .describe(\n \"(string): The workflowRunId of the User to retrieve. Use this when you want to retrieve messages sent from a workflow trigger.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n\n return await publicClient.users.getMessages(\n params.userId ?? config.userId,\n {\n workflow_run_id: params.workflowRunId,\n }\n );\n },\n});\n\nexport const users = {\n getUser,\n deleteUser,\n createOrUpdateUser,\n getUserPreferences,\n setUserPreferences,\n getUserMessages,\n};\n\nexport const permissions = {\n read: [\"getUser\", \"getUserPreferences\", \"getUserMessages\"],\n manage: [\"createOrUpdateUser\", \"deleteUser\", \"setUserPreferences\"],\n};\n","import type { ZodObject } from \"zod\";\nimport { z } from \"zod\";\nimport { Config } from \"../types.js\";\nimport { KnockClient } from \"./knock-client.js\";\n\nexport interface KnockToolDefinition {\n /**\n * The method name of the tool. This is a machine-readable string.\n */\n method: string;\n /**\n * The name of the tool. This can be used to reference the tool in the code.\n * A descriptive LLM-readable string.\n */\n name: string;\n\n /**\n * A descriptive prompt explaining the tool's purpose, including examples where useful.\n */\n description: string;\n\n /**\n * A descriptive prompt explaining the tool's purpose, usage and input parameters.\n * Ths is intended to be used by the underlying LLM.\n */\n fullDescription: string;\n\n /**\n * The Zod schema for the input parameters of the tool\n */\n parameters?: ZodObject<any>;\n /**\n * The actual implementation of the tool.\n */\n execute: (\n knockClient: KnockClient,\n config: Config\n ) => (input: any) => Promise<unknown>;\n}\n\nexport interface KnockTool extends Omit<KnockToolDefinition, \"execute\"> {\n bindExecute: (\n knockClient: KnockClient,\n config: Config\n ) => (input: any) => Promise<unknown>;\n}\n\nconst trimLines = (text: string) =>\n text\n .split(\"\\n\")\n .map((l) => l.trim())\n .filter(Boolean)\n .join(\"\\n\");\n\nexport const KnockTool = (\n args: Omit<KnockToolDefinition, \"fullDescription\">\n): KnockTool => {\n const { execute, ...restOfArgs } = args;\n const parameters = restOfArgs.parameters\n ? restOfArgs.parameters\n : z.object({});\n\n const schemaEntries = Object.entries(parameters.shape);\n\n const argsStr =\n schemaEntries.length === 0\n ? \"Takes no arguments\"\n : schemaEntries\n .map(([key, value]) => {\n return `- ${key}: ${(value as any).description || \"\"}`;\n })\n .join(\"\\n\");\n\n const fullDescription = trimLines(`\n Tool name:\n ${args.name}\n Description:\n ${args.description}.\n Arguments:\n ${argsStr}\n `);\n\n return {\n ...restOfArgs,\n parameters,\n fullDescription,\n bindExecute: (knockClient: KnockClient, config: Config) =>\n execute(knockClient, config),\n };\n};\n"],"mappings":";AAAA,SAAS,KAAAA,UAAS;;;ACClB,SAAS,SAAS;AA8ClB,IAAM,YAAY,CAAC,SACjB,KACG,MAAM,IAAI,EACV,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EACnB,OAAO,OAAO,EACd,KAAK,IAAI;AAEP,IAAM,YAAY,CACvB,SACc;AACd,QAAM,EAAE,SAAS,GAAG,WAAW,IAAI;AACnC,QAAM,aAAa,WAAW,aAC1B,WAAW,aACX,EAAE,OAAO,CAAC,CAAC;AAEf,QAAM,gBAAgB,OAAO,QAAQ,WAAW,KAAK;AAErD,QAAM,UACJ,cAAc,WAAW,IACrB,uBACA,cACG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