@knocklabs/agent-toolkit 0.1.8 → 0.1.10
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/README.md +93 -22
- package/dist/ai-sdk/index.d.ts +25 -26
- package/dist/ai-sdk/index.js +106 -8
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/{chunk-JBEVT2QK.js → chunk-25NTCHCG.js} +226 -115
- package/dist/chunk-25NTCHCG.js.map +1 -0
- package/dist/chunk-6O7VMHBN.js +57 -0
- package/dist/chunk-6O7VMHBN.js.map +1 -0
- package/dist/{chunk-WXHVAABP.js → chunk-C7RK7AZJ.js} +10 -6
- package/dist/chunk-C7RK7AZJ.js.map +1 -0
- package/dist/chunk-G3PMV62Z.js +36 -0
- package/dist/chunk-G3PMV62Z.js.map +1 -0
- package/dist/human-in-the-loop.d.ts +33 -0
- package/dist/human-in-the-loop.js +12 -0
- package/dist/human-in-the-loop.js.map +1 -0
- package/dist/knock-client-BH7Juvis.d.ts +10 -0
- package/dist/langchain/index.d.ts +17 -0
- package/dist/langchain/index.js +16055 -0
- package/dist/langchain/index.js.map +1 -0
- package/dist/modelcontextprotocol/index.d.ts +8 -8
- package/dist/modelcontextprotocol/index.js +3 -2
- package/dist/modelcontextprotocol/local-server.js +11 -6
- package/dist/modelcontextprotocol/local-server.js.map +1 -1
- package/dist/openai/index.d.ts +9 -33
- package/dist/openai/index.js +4 -3
- package/dist/openai/index.js.map +1 -1
- package/dist/types-CrTRlRnE.d.ts +105 -0
- package/dist/{types-BJFe1DAl.d.ts → types.d.ts} +2 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +13 -1
- package/dist/chunk-JBEVT2QK.js.map +0 -1
- package/dist/chunk-WXHVAABP.js.map +0 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/lib/human-in-the-loop/index.ts
|
|
2
|
+
function wrapToolDescription(description) {
|
|
3
|
+
return `${description}
|
|
4
|
+
|
|
5
|
+
This tool call is deferred. You will NOT receive a result from this tool but this is NOT an error. Do NOT retry the tool call as the result will be the same. The tool call result will be provided to you in the future.`;
|
|
6
|
+
}
|
|
7
|
+
async function triggerHumanInTheLoopWorkflow({
|
|
8
|
+
knockClient,
|
|
9
|
+
config,
|
|
10
|
+
toolCall,
|
|
11
|
+
inputConfig
|
|
12
|
+
}) {
|
|
13
|
+
const knock = await knockClient.publicApi(config.environment);
|
|
14
|
+
const result = await knock.workflows.trigger(inputConfig.workflow, {
|
|
15
|
+
data: {
|
|
16
|
+
type: "deferred_tool_call",
|
|
17
|
+
tool_call: toolCall,
|
|
18
|
+
metadata: inputConfig.metadata
|
|
19
|
+
},
|
|
20
|
+
recipients: inputConfig.recipients,
|
|
21
|
+
tenant: inputConfig.tenant,
|
|
22
|
+
actor: inputConfig.actor
|
|
23
|
+
});
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
function handleMessageInteraction(event) {
|
|
27
|
+
const { data: message } = event;
|
|
28
|
+
if (event.type !== "message.interacted") {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (message.data.type !== "deferred_tool_call" || !message.data.tool_call) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const messageData = message.data;
|
|
35
|
+
return {
|
|
36
|
+
workflow: message.source.key,
|
|
37
|
+
interaction: event.event_data,
|
|
38
|
+
toolCall: {
|
|
39
|
+
method: messageData.tool_call.method,
|
|
40
|
+
args: messageData.tool_call.args,
|
|
41
|
+
extra: messageData.tool_call.extra
|
|
42
|
+
},
|
|
43
|
+
metadata: messageData.metadata,
|
|
44
|
+
context: {
|
|
45
|
+
messageId: message.id,
|
|
46
|
+
channelId: message.channel_id,
|
|
47
|
+
timestamp: event.created_at
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
wrapToolDescription,
|
|
54
|
+
triggerHumanInTheLoopWorkflow,
|
|
55
|
+
handleMessageInteraction
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=chunk-6O7VMHBN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/human-in-the-loop/index.ts"],"sourcesContent":["import { Config } from \"@/types\";\n\nimport { KnockClient } from \"../knock-client\";\n\nimport {\n DeferredToolCallWorkflowData,\n DeferredToolCallConfig,\n KnockOutboundWebhookEvent,\n DeferredToolCall,\n DeferredToolCallInteractionResult,\n} from \"./types\";\n\nfunction wrapToolDescription(description: string) {\n return `${description}\\n\\nThis tool call is deferred. You will NOT receive a result from this tool but this is NOT an error. Do NOT retry the tool call as the result will be the same. The tool call result will be provided to you in the future.`;\n}\n\n/**\n * Triggers a human in the loop workflow.\n *\n * @param knockClient - The Knock client to use.\n * @param toolCall - The tool call to trigger.\n * @param config - The configuration to use.\n */\nasync function triggerHumanInTheLoopWorkflow({\n knockClient,\n config,\n toolCall,\n inputConfig,\n}: {\n knockClient: KnockClient;\n config: Config;\n toolCall: DeferredToolCall;\n inputConfig: DeferredToolCallConfig;\n}) {\n const knock = await knockClient.publicApi(config.environment);\n\n const result = await knock.workflows.trigger(inputConfig.workflow, {\n data: {\n type: \"deferred_tool_call\",\n tool_call: toolCall,\n metadata: inputConfig.metadata,\n } as DeferredToolCallWorkflowData,\n recipients: inputConfig.recipients,\n tenant: inputConfig.tenant,\n actor: inputConfig.actor,\n });\n\n return result;\n}\n\n/**\n * Given an outboundwebhook event, this function will parse the event into a normalized format.\n *\n * If the event is not associated with a deferred tool call, this function will return null.\n *\n * @param event - The outbound webhook event\n * @returns A deferred tool call interaction result, or null if the event is not a deferred tool call\n */\nfunction handleMessageInteraction(\n event: KnockOutboundWebhookEvent\n): DeferredToolCallInteractionResult | null {\n const { data: message } = event;\n\n // We only care about message.interacted events\n if (event.type !== \"message.interacted\") {\n return null;\n }\n\n // We only care about messages that contain a tool call\n if (message.data.type !== \"deferred_tool_call\" || !message.data.tool_call) {\n return null;\n }\n\n const messageData = message.data as DeferredToolCallWorkflowData;\n\n return {\n workflow: message.source.key,\n interaction: event.event_data,\n toolCall: {\n method: messageData.tool_call.method,\n args: messageData.tool_call.args,\n extra: messageData.tool_call.extra,\n },\n metadata: messageData.metadata,\n context: {\n messageId: message.id,\n channelId: message.channel_id,\n timestamp: event.created_at,\n },\n };\n}\n\nexport {\n handleMessageInteraction,\n triggerHumanInTheLoopWorkflow,\n wrapToolDescription,\n};\n"],"mappings":";AAYA,SAAS,oBAAoB,aAAqB;AAChD,SAAO,GAAG,WAAW;AAAA;AAAA;AACvB;AASA,eAAe,8BAA8B;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKG;AACD,QAAM,QAAQ,MAAM,YAAY,UAAU,OAAO,WAAW;AAE5D,QAAM,SAAS,MAAM,MAAM,UAAU,QAAQ,YAAY,UAAU;AAAA,IACjE,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,WAAW;AAAA,MACX,UAAU,YAAY;AAAA,IACxB;AAAA,IACA,YAAY,YAAY;AAAA,IACxB,QAAQ,YAAY;AAAA,IACpB,OAAO,YAAY;AAAA,EACrB,CAAC;AAED,SAAO;AACT;AAUA,SAAS,yBACP,OAC0C;AAC1C,QAAM,EAAE,MAAM,QAAQ,IAAI;AAG1B,MAAI,MAAM,SAAS,sBAAsB;AACvC,WAAO;AAAA,EACT;AAGA,MAAI,QAAQ,KAAK,SAAS,wBAAwB,CAAC,QAAQ,KAAK,WAAW;AACzE,WAAO;AAAA,EACT;AAEA,QAAM,cAAc,QAAQ;AAE5B,SAAO;AAAA,IACL,UAAU,QAAQ,OAAO;AAAA,IACzB,aAAa,MAAM;AAAA,IACnB,UAAU;AAAA,MACR,QAAQ,YAAY,UAAU;AAAA,MAC9B,MAAM,YAAY,UAAU;AAAA,MAC5B,OAAO,YAAY,UAAU;AAAA,IAC/B;AAAA,IACA,UAAU,YAAY;AAAA,IACtB,SAAS;AAAA,MACP,WAAW,QAAQ;AAAA,MACnB,WAAW,QAAQ;AAAA,MACnB,WAAW,MAAM;AAAA,IACnB;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
allTools,
|
|
3
3
|
createWorkflowTools
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-25NTCHCG.js";
|
|
5
5
|
|
|
6
6
|
// src/modelcontextprotocol/adapter.ts
|
|
7
7
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
var KnockMcpServer = class extends McpServer {
|
|
10
10
|
constructor(knockClient, config, tools) {
|
|
11
|
-
super({ name: "Knock", version: "0.1.
|
|
11
|
+
super({ name: "Knock", version: "0.1.10" });
|
|
12
12
|
tools.forEach((tool) => {
|
|
13
13
|
const toolParams = tool.parameters ?? z.object({});
|
|
14
14
|
this.tool(
|
|
@@ -28,10 +28,14 @@ var KnockMcpServer = class extends McpServer {
|
|
|
28
28
|
|
|
29
29
|
// src/modelcontextprotocol/index.ts
|
|
30
30
|
var createKnockMcpServer = async (params) => {
|
|
31
|
-
const { tools, knockClient, config } = params;
|
|
31
|
+
const { tools, knockClient, config, workflows } = params;
|
|
32
32
|
let baseTools = tools || Object.values(allTools);
|
|
33
|
-
if (
|
|
34
|
-
const workflowTools = await createWorkflowTools(
|
|
33
|
+
if (workflows && Array.isArray(workflows) && workflows.length > 0) {
|
|
34
|
+
const workflowTools = await createWorkflowTools(
|
|
35
|
+
knockClient,
|
|
36
|
+
config,
|
|
37
|
+
workflows
|
|
38
|
+
);
|
|
35
39
|
baseTools = [...baseTools, ...workflowTools];
|
|
36
40
|
}
|
|
37
41
|
return Promise.resolve(new KnockMcpServer(knockClient, config, baseTools));
|
|
@@ -40,4 +44,4 @@ var createKnockMcpServer = async (params) => {
|
|
|
40
44
|
export {
|
|
41
45
|
createKnockMcpServer
|
|
42
46
|
};
|
|
43
|
-
//# sourceMappingURL=chunk-
|
|
47
|
+
//# sourceMappingURL=chunk-C7RK7AZJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/modelcontextprotocol/adapter.ts","../src/modelcontextprotocol/index.ts"],"sourcesContent":["import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\n\nimport { KnockClient } from \"../lib/knock-client.js\";\nimport type { KnockTool } from \"../lib/knock-tool.js\";\nimport { Config } from \"../types.js\";\n\nexport class KnockMcpServer extends McpServer {\n constructor(knockClient: KnockClient, config: Config, tools: KnockTool[]) {\n super({ name: \"Knock\", version: PACKAGE_VERSION });\n\n tools.forEach((tool) => {\n const toolParams = tool.parameters ?? z.object({});\n\n this.tool(\n tool.method,\n tool.description,\n toolParams.shape,\n async (arg: unknown) => {\n const res = await tool.bindExecute(knockClient, config)(arg);\n\n return {\n content: [{ type: \"text\" as const, text: JSON.stringify(res) }],\n };\n }\n );\n });\n }\n}\n","import { KnockClient } from \"../lib/knock-client.js\";\nimport type { KnockTool } from \"../lib/knock-tool.js\";\nimport { allTools } from \"../lib/tools/index.js\";\nimport { createWorkflowTools } from \"../lib/tools/workflows-as-tools.js\";\nimport { Config } from \"../types.js\";\n\nimport { KnockMcpServer } from \"./adapter.js\";\n\ntype CreateKnockMcpServerParams = {\n /**\n * Array of Knock tools to enable in the server.\n */\n tools?: KnockTool[];\n\n /**\n * A Knock client to use for the server.\n */\n knockClient: KnockClient;\n\n /**\n * The config to use for the server.\n */\n config: Config;\n\n /**\n * The workflows to enable as tools in the MCP server.\n */\n workflows?: string[];\n};\n\n/**\n * Creates a Knock MCP Server with the given parameters.\n */\nexport const createKnockMcpServer = async (\n params: CreateKnockMcpServerParams\n): Promise<KnockMcpServer> => {\n const { tools, knockClient, config, workflows } = params;\n\n let baseTools = tools || Object.values(allTools);\n\n if (workflows && Array.isArray(workflows) && workflows.length > 0) {\n const workflowTools = await createWorkflowTools(\n knockClient,\n config,\n workflows\n );\n\n baseTools = [...baseTools, ...workflowTools];\n }\n\n return Promise.resolve(new KnockMcpServer(knockClient, config, baseTools));\n};\n"],"mappings":";;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS;AAMX,IAAM,iBAAN,cAA6B,UAAU;AAAA,EAC5C,YAAY,aAA0B,QAAgB,OAAoB;AACxE,UAAM,EAAE,MAAM,SAAS,SAAS,SAAgB,CAAC;AAEjD,UAAM,QAAQ,CAAC,SAAS;AACtB,YAAM,aAAa,KAAK,cAAc,EAAE,OAAO,CAAC,CAAC;AAEjD,WAAK;AAAA,QACH,KAAK;AAAA,QACL,KAAK;AAAA,QACL,WAAW;AAAA,QACX,OAAO,QAAiB;AACtB,gBAAM,MAAM,MAAM,KAAK,YAAY,aAAa,MAAM,EAAE,GAAG;AAE3D,iBAAO;AAAA,YACL,SAAS,CAAC,EAAE,MAAM,QAAiB,MAAM,KAAK,UAAU,GAAG,EAAE,CAAC;AAAA,UAChE;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;ACKO,IAAM,uBAAuB,OAClC,WAC4B;AAC5B,QAAM,EAAE,OAAO,aAAa,QAAQ,UAAU,IAAI;AAElD,MAAI,YAAY,SAAS,OAAO,OAAO,QAAQ;AAE/C,MAAI,aAAa,MAAM,QAAQ,SAAS,KAAK,UAAU,SAAS,GAAG;AACjE,UAAM,gBAAgB,MAAM;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,gBAAY,CAAC,GAAG,WAAW,GAAG,aAAa;AAAA,EAC7C;AAEA,SAAO,QAAQ,QAAQ,IAAI,eAAe,aAAa,QAAQ,SAAS,CAAC;AAC3E;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
__commonJS,
|
|
33
|
+
__export,
|
|
34
|
+
__toESM
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=chunk-G3PMV62Z.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as _knocklabs_node from '@knocklabs/node';
|
|
2
|
+
import { Config } from './types.js';
|
|
3
|
+
import { K as KnockClient } from './knock-client-BH7Juvis.js';
|
|
4
|
+
import { K as KnockOutboundWebhookEvent, D as DeferredToolCallInteractionResult, a as DeferredToolCall, b as DeferredToolCallConfig } from './types-CrTRlRnE.js';
|
|
5
|
+
export { c as DeferredToolCallWorkflowData } from './types-CrTRlRnE.js';
|
|
6
|
+
import '@knocklabs/mgmt';
|
|
7
|
+
import '@knocklabs/node/dist/src/resources/messages/interfaces';
|
|
8
|
+
|
|
9
|
+
declare function wrapToolDescription(description: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Triggers a human in the loop workflow.
|
|
12
|
+
*
|
|
13
|
+
* @param knockClient - The Knock client to use.
|
|
14
|
+
* @param toolCall - The tool call to trigger.
|
|
15
|
+
* @param config - The configuration to use.
|
|
16
|
+
*/
|
|
17
|
+
declare function triggerHumanInTheLoopWorkflow({ knockClient, config, toolCall, inputConfig, }: {
|
|
18
|
+
knockClient: KnockClient;
|
|
19
|
+
config: Config;
|
|
20
|
+
toolCall: DeferredToolCall;
|
|
21
|
+
inputConfig: DeferredToolCallConfig;
|
|
22
|
+
}): Promise<_knocklabs_node.WorkflowRun>;
|
|
23
|
+
/**
|
|
24
|
+
* Given an outboundwebhook event, this function will parse the event into a normalized format.
|
|
25
|
+
*
|
|
26
|
+
* If the event is not associated with a deferred tool call, this function will return null.
|
|
27
|
+
*
|
|
28
|
+
* @param event - The outbound webhook event
|
|
29
|
+
* @returns A deferred tool call interaction result, or null if the event is not a deferred tool call
|
|
30
|
+
*/
|
|
31
|
+
declare function handleMessageInteraction(event: KnockOutboundWebhookEvent): DeferredToolCallInteractionResult | null;
|
|
32
|
+
|
|
33
|
+
export { DeferredToolCall, DeferredToolCallConfig, DeferredToolCallInteractionResult, KnockOutboundWebhookEvent, handleMessageInteraction, triggerHumanInTheLoopWorkflow, wrapToolDescription };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleMessageInteraction,
|
|
3
|
+
triggerHumanInTheLoopWorkflow,
|
|
4
|
+
wrapToolDescription
|
|
5
|
+
} from "./chunk-6O7VMHBN.js";
|
|
6
|
+
import "./chunk-G3PMV62Z.js";
|
|
7
|
+
export {
|
|
8
|
+
handleMessageInteraction,
|
|
9
|
+
triggerHumanInTheLoopWorkflow,
|
|
10
|
+
wrapToolDescription
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=human-in-the-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import KnockMgmt from '@knocklabs/mgmt';
|
|
2
|
+
import { Knock } from '@knocklabs/node';
|
|
3
|
+
import { Config } from './types.js';
|
|
4
|
+
|
|
5
|
+
type KnockClient = ReturnType<typeof createKnockClient>;
|
|
6
|
+
declare const createKnockClient: (config: Config) => KnockMgmt & {
|
|
7
|
+
publicApi: (environmentSlug?: string) => Promise<Knock>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type { KnockClient as K };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
2
|
+
import { ToolkitConfig, ToolCategory } from '../types.js';
|
|
3
|
+
|
|
4
|
+
type KnockToolkit = {
|
|
5
|
+
getAllTools: () => DynamicStructuredTool[];
|
|
6
|
+
getTools: (category: ToolCategory) => DynamicStructuredTool[];
|
|
7
|
+
getToolMap: () => Record<string, DynamicStructuredTool>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Create a toolkit for use with the LangChain framework.
|
|
11
|
+
*
|
|
12
|
+
* @param config - The configuration to use for the toolkit
|
|
13
|
+
* @returns A toolkit for use with the LangChain framework
|
|
14
|
+
*/
|
|
15
|
+
declare const createKnockToolkit: (config: ToolkitConfig) => Promise<KnockToolkit>;
|
|
16
|
+
|
|
17
|
+
export { createKnockToolkit };
|