@knocklabs/agent-toolkit 0.1.7 → 0.1.9
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.
- package/dist/ai-sdk/index.d.ts +43 -9
- package/dist/ai-sdk/index.js +45 -19
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/{chunk-3CUTEODM.js → chunk-6UHXLKAV.js} +262 -182
- package/dist/chunk-6UHXLKAV.js.map +1 -0
- package/dist/{chunk-CXOB4H3U.js → chunk-OMZBTWDH.js} +2 -2
- package/dist/chunk-OMZBTWDH.js.map +1 -0
- package/dist/{chunk-SADGJJQS.js → chunk-VGU7NXYJ.js} +11 -7
- package/dist/chunk-VGU7NXYJ.js.map +1 -0
- package/dist/modelcontextprotocol/index.d.ts +3 -3
- package/dist/modelcontextprotocol/index.js +2 -2
- package/dist/modelcontextprotocol/local-server.js +5 -5
- package/dist/modelcontextprotocol/local-server.js.map +1 -1
- package/dist/openai/index.d.ts +31 -7
- package/dist/openai/index.js +33 -22
- package/dist/openai/index.js.map +1 -1
- package/dist/{types-DmmGlWVt.d.ts → types-BJFe1DAl.d.ts} +18 -1
- package/package.json +19 -3
- package/dist/chunk-3CUTEODM.js.map +0 -1
- package/dist/chunk-CXOB4H3U.js.map +0 -1
- package/dist/chunk-SADGJJQS.js.map +0 -1
package/dist/ai-sdk/index.d.ts
CHANGED
|
@@ -1,18 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ToolSet, Tool } from 'ai';
|
|
2
|
+
import { T as ToolkitConfig, a as ToolCategory } from '../types-BJFe1DAl.js';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Creates a Knock toolkit for use with the AI SDK.
|
|
6
|
+
*
|
|
7
|
+
* You can filter the set of tools that are available by setting the `config.permissions` property.
|
|
8
|
+
*
|
|
9
|
+
* When the `config.permissions.workflows.run` is set, then workflow triggers for
|
|
10
|
+
* the specified workflows will be included in the returned tools.
|
|
11
|
+
*
|
|
12
|
+
* You can also specify a list of workflow keys to include in the returned tools, should you wish to
|
|
13
|
+
* limit the set of workflows that are available.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const toolkit = await createKnockToolkit({
|
|
18
|
+
* permissions: {
|
|
19
|
+
* workflows: { read: true },
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param config - The configuration to use for the toolkit
|
|
25
|
+
* @returns A toolkit for use with the AI SDK
|
|
26
|
+
*/
|
|
27
|
+
declare const createKnockToolkit: (config: ToolkitConfig) => Promise<{
|
|
5
28
|
/**
|
|
6
|
-
* Get all tools for all categories
|
|
7
|
-
*
|
|
29
|
+
* Get all tools for all categories. When the `config.permissions.workflows.run` is set, then workflow triggers for
|
|
30
|
+
* the specified workflows will be included in the returned tools.
|
|
31
|
+
*
|
|
32
|
+
* @returns A promise that resolves to a set of tools
|
|
8
33
|
*/
|
|
9
|
-
getAllTools: () => ToolSet
|
|
34
|
+
getAllTools: () => Promise<ToolSet>;
|
|
10
35
|
/**
|
|
11
|
-
* Get all tools for a specific category
|
|
36
|
+
* Get all tools for a specific category. When trying to get tools for the `workflows` category and the run permission is set,
|
|
37
|
+
* the workflow triggers for the specified workflows will be included in the returned tools.
|
|
38
|
+
*
|
|
12
39
|
* @param category - The category of tools to get
|
|
13
40
|
* @returns An array of tools for the given category
|
|
14
41
|
*/
|
|
15
|
-
getTools: (category: ToolCategory) => ToolSet
|
|
16
|
-
|
|
42
|
+
getTools: (category: ToolCategory) => Promise<ToolSet>;
|
|
43
|
+
/**
|
|
44
|
+
* Get a map of all tools by method name. When the `config.permissions.workflows.run` is set, then workflow triggers for
|
|
45
|
+
* the specified workflows will be included in the returned tools.
|
|
46
|
+
*
|
|
47
|
+
* @returns A map of all tools by method name
|
|
48
|
+
*/
|
|
49
|
+
getToolMap: () => Promise<Record<string, Tool>>;
|
|
50
|
+
}>;
|
|
17
51
|
|
|
18
52
|
export { createKnockToolkit };
|
package/dist/ai-sdk/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createKnockClient
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-OMZBTWDH.js";
|
|
4
4
|
import {
|
|
5
|
+
getToolMap,
|
|
5
6
|
getToolsByPermissionsInCategories
|
|
6
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-6UHXLKAV.js";
|
|
7
8
|
|
|
8
9
|
// src/ai-sdk/tool-converter.ts
|
|
9
10
|
import { tool } from "ai";
|
|
@@ -15,35 +16,60 @@ var knockToolToAiTool = (knockClient, config, knockTool) => {
|
|
|
15
16
|
execute: knockTool.bindExecute(knockClient, config)
|
|
16
17
|
});
|
|
17
18
|
};
|
|
19
|
+
var knockToolsToToolSet = (knockClient, config, knockTools) => {
|
|
20
|
+
return knockTools.reduce(
|
|
21
|
+
(acc, tool2) => {
|
|
22
|
+
acc[tool2.method] = knockToolToAiTool(knockClient, config, tool2);
|
|
23
|
+
return acc;
|
|
24
|
+
},
|
|
25
|
+
{}
|
|
26
|
+
);
|
|
27
|
+
};
|
|
18
28
|
|
|
19
29
|
// src/ai-sdk/index.ts
|
|
20
|
-
var createKnockToolkit = (config) => {
|
|
30
|
+
var createKnockToolkit = async (config) => {
|
|
21
31
|
const knockClient = createKnockClient(config);
|
|
22
|
-
const allowedToolsByCategory = getToolsByPermissionsInCategories(
|
|
32
|
+
const allowedToolsByCategory = await getToolsByPermissionsInCategories(
|
|
33
|
+
knockClient,
|
|
34
|
+
config
|
|
35
|
+
);
|
|
36
|
+
const allTools = Object.values(allowedToolsByCategory).flat();
|
|
37
|
+
const toolsByMethod = getToolMap(allTools);
|
|
23
38
|
return {
|
|
24
39
|
/**
|
|
25
|
-
* Get all tools for all categories
|
|
26
|
-
*
|
|
40
|
+
* Get all tools for all categories. When the `config.permissions.workflows.run` is set, then workflow triggers for
|
|
41
|
+
* the specified workflows will be included in the returned tools.
|
|
42
|
+
*
|
|
43
|
+
* @returns A promise that resolves to a set of tools
|
|
27
44
|
*/
|
|
28
|
-
getAllTools: () => {
|
|
29
|
-
return
|
|
30
|
-
(acc, tool2) => ({
|
|
31
|
-
...acc,
|
|
32
|
-
[tool2.method]: knockToolToAiTool(knockClient, config, tool2)
|
|
33
|
-
}),
|
|
34
|
-
{}
|
|
35
|
-
);
|
|
45
|
+
getAllTools: async () => {
|
|
46
|
+
return knockToolsToToolSet(knockClient, config, allTools);
|
|
36
47
|
},
|
|
37
48
|
/**
|
|
38
|
-
* Get all tools for a specific category
|
|
49
|
+
* Get all tools for a specific category. When trying to get tools for the `workflows` category and the run permission is set,
|
|
50
|
+
* the workflow triggers for the specified workflows will be included in the returned tools.
|
|
51
|
+
*
|
|
39
52
|
* @param category - The category of tools to get
|
|
40
53
|
* @returns An array of tools for the given category
|
|
41
54
|
*/
|
|
42
|
-
getTools: (category) => {
|
|
43
|
-
return
|
|
44
|
-
|
|
55
|
+
getTools: async (category) => {
|
|
56
|
+
return knockToolsToToolSet(
|
|
57
|
+
knockClient,
|
|
58
|
+
config,
|
|
59
|
+
allowedToolsByCategory[category]
|
|
60
|
+
);
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* Get a map of all tools by method name. When the `config.permissions.workflows.run` is set, then workflow triggers for
|
|
64
|
+
* the specified workflows will be included in the returned tools.
|
|
65
|
+
*
|
|
66
|
+
* @returns A map of all tools by method name
|
|
67
|
+
*/
|
|
68
|
+
getToolMap: async () => {
|
|
69
|
+
return Object.entries(toolsByMethod).reduce(
|
|
70
|
+
(acc, [method, tool2]) => ({
|
|
45
71
|
...acc,
|
|
46
|
-
[
|
|
72
|
+
[method]: knockToolToAiTool(knockClient, config, tool2)
|
|
47
73
|
}),
|
|
48
74
|
{}
|
|
49
75
|
);
|
package/dist/ai-sdk/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ai-sdk/tool-converter.ts","../../src/ai-sdk/index.ts"],"sourcesContent":["import type { Tool } from \"ai\";\nimport { tool } from \"ai\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/ai-sdk/tool-converter.ts","../../src/ai-sdk/index.ts"],"sourcesContent":["import type { Tool } from \"ai\";\nimport { tool } from \"ai\";\nimport { z } from \"zod\";\n\nimport { KnockClient } from \"../lib/knock-client.js\";\nimport { KnockTool } from \"../lib/knock-tool.js\";\nimport { Config } from \"../types.js\";\n\n/**\n * Convert a KnockTool to an AI Tool, ready to pass to the AI SDK.\n */\nconst knockToolToAiTool = (\n knockClient: KnockClient,\n config: Config,\n knockTool: KnockTool\n): Tool => {\n return tool({\n description: knockTool.description,\n parameters: knockTool.parameters ?? z.object({}),\n execute: knockTool.bindExecute(knockClient, config),\n });\n};\n\n/**\n * Convert a list of KnockTools to an AI ToolSet, ready to pass to the AI SDK.\n */\nconst knockToolsToToolSet = (\n knockClient: KnockClient,\n config: Config,\n knockTools: KnockTool[]\n) => {\n return knockTools.reduce(\n (acc, tool) => {\n acc[tool.method] = knockToolToAiTool(knockClient, config, tool);\n return acc;\n },\n {} as Record<string, Tool>\n );\n};\n\nexport { knockToolToAiTool, knockToolsToToolSet };\n","import { Tool, ToolSet } from \"ai\";\n\nimport { createKnockClient } from \"../lib/knock-client.js\";\nimport { getToolMap, getToolsByPermissionsInCategories } from \"../lib/utils.js\";\nimport { ToolCategory, ToolkitConfig } from \"../types.js\";\n\nimport { knockToolsToToolSet, knockToolToAiTool } from \"./tool-converter.js\";\n\n/**\n * Creates a Knock toolkit for use with the AI SDK.\n *\n * You can filter the set of tools that are available by setting the `config.permissions` property.\n *\n * When the `config.permissions.workflows.run` is set, then workflow triggers for\n * the specified workflows will be included in the returned tools.\n *\n * You can also specify a list of workflow keys to include in the returned tools, should you wish to\n * limit the set of workflows that are available.\n *\n * @example\n * ```ts\n * const toolkit = await createKnockToolkit({\n * permissions: {\n * workflows: { read: true },\n * },\n * });\n * ```\n *\n * @param config - The configuration to use for the toolkit\n * @returns A toolkit for use with the AI SDK\n */\nconst createKnockToolkit = async (config: ToolkitConfig) => {\n const knockClient = createKnockClient(config);\n const allowedToolsByCategory = await getToolsByPermissionsInCategories(\n knockClient,\n config\n );\n const allTools = Object.values(allowedToolsByCategory).flat();\n const toolsByMethod = getToolMap(allTools);\n\n return {\n /**\n * Get all tools for all categories. When the `config.permissions.workflows.run` is set, then workflow triggers for\n * the specified workflows will be included in the returned tools.\n *\n * @returns A promise that resolves to a set of tools\n */\n getAllTools: async (): Promise<ToolSet> => {\n return knockToolsToToolSet(knockClient, config, allTools);\n },\n\n /**\n * Get all tools for a specific category. When trying to get tools for the `workflows` category and the run permission is set,\n * the workflow triggers for the specified workflows will be included in the returned tools.\n *\n * @param category - The category of tools to get\n * @returns An array of tools for the given category\n */\n getTools: async (category: ToolCategory): Promise<ToolSet> => {\n return knockToolsToToolSet(\n knockClient,\n config,\n allowedToolsByCategory[category]\n );\n },\n\n /**\n * Get a map of all tools by method name. When the `config.permissions.workflows.run` is set, then workflow triggers for\n * the specified workflows will be included in the returned tools.\n *\n * @returns A map of all tools by method name\n */\n getToolMap: async (): Promise<Record<string, Tool>> => {\n return Object.entries(toolsByMethod).reduce(\n (acc, [method, tool]) => ({\n ...acc,\n [method]: knockToolToAiTool(knockClient, config, tool),\n }),\n {} as Record<string, Tool>\n );\n },\n };\n};\n\nexport { createKnockToolkit };\n"],"mappings":";;;;;;;;;AACA,SAAS,YAAY;AACrB,SAAS,SAAS;AASlB,IAAM,oBAAoB,CACxB,aACA,QACA,cACS;AACT,SAAO,KAAK;AAAA,IACV,aAAa,UAAU;AAAA,IACvB,YAAY,UAAU,cAAc,EAAE,OAAO,CAAC,CAAC;AAAA,IAC/C,SAAS,UAAU,YAAY,aAAa,MAAM;AAAA,EACpD,CAAC;AACH;AAKA,IAAM,sBAAsB,CAC1B,aACA,QACA,eACG;AACH,SAAO,WAAW;AAAA,IAChB,CAAC,K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