kernl 0.2.1 → 0.6.0
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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-check-types.log +4 -0
- package/CHANGELOG.md +138 -0
- package/LICENSE +1 -1
- package/dist/agent/__tests__/concurrency.test.d.ts +2 -0
- package/dist/agent/__tests__/concurrency.test.d.ts.map +1 -0
- package/dist/agent/__tests__/concurrency.test.js +152 -0
- package/dist/agent/__tests__/run.test.d.ts +2 -0
- package/dist/agent/__tests__/run.test.d.ts.map +1 -0
- package/dist/agent/__tests__/run.test.js +357 -0
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent.d.ts +32 -9
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +101 -14
- package/dist/api/__tests__/cursor-page.test.d.ts +2 -0
- package/dist/api/__tests__/cursor-page.test.d.ts.map +1 -0
- package/dist/api/__tests__/cursor-page.test.js +414 -0
- package/dist/api/__tests__/offset-page.test.d.ts +2 -0
- package/dist/api/__tests__/offset-page.test.d.ts.map +1 -0
- package/dist/api/__tests__/offset-page.test.js +510 -0
- package/dist/api/__tests__/threads.test.d.ts +2 -0
- package/dist/api/__tests__/threads.test.d.ts.map +1 -0
- package/dist/api/__tests__/threads.test.js +338 -0
- package/dist/api/models/index.d.ts +2 -0
- package/dist/api/models/index.d.ts.map +1 -0
- package/dist/api/models/thread.d.ts +120 -0
- package/dist/api/models/thread.d.ts.map +1 -0
- package/dist/api/pagination/base.d.ts +48 -0
- package/dist/api/pagination/base.d.ts.map +1 -0
- package/dist/api/pagination/base.js +45 -0
- package/dist/api/pagination/cursor.d.ts +44 -0
- package/dist/api/pagination/cursor.d.ts.map +1 -0
- package/dist/api/pagination/cursor.js +52 -0
- package/dist/api/pagination/offset.d.ts +42 -0
- package/dist/api/pagination/offset.d.ts.map +1 -0
- package/dist/api/pagination/offset.js +55 -0
- package/dist/api/resources/threads/events.d.ts +21 -0
- package/dist/api/resources/threads/events.d.ts.map +1 -0
- package/dist/api/resources/threads/events.js +24 -0
- package/dist/api/resources/threads/index.d.ts +4 -0
- package/dist/api/resources/threads/index.d.ts.map +1 -0
- package/dist/api/resources/threads/index.js +2 -0
- package/dist/api/resources/threads/threads.d.ts +57 -0
- package/dist/api/resources/threads/threads.d.ts.map +1 -0
- package/dist/api/resources/threads/threads.js +199 -0
- package/dist/api/resources/threads/types.d.ts +123 -0
- package/dist/api/resources/threads/types.d.ts.map +1 -0
- package/dist/api/resources/threads/utils.d.ts +18 -0
- package/dist/api/resources/threads/utils.d.ts.map +1 -0
- package/dist/api/resources/threads/utils.js +78 -0
- package/dist/context.d.ts +5 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +6 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/internal.d.ts +4 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +2 -0
- package/dist/kernl/index.d.ts +3 -0
- package/dist/kernl/index.d.ts.map +1 -0
- package/dist/kernl/index.js +2 -0
- package/dist/kernl/kernl.d.ts +64 -0
- package/dist/kernl/kernl.d.ts.map +1 -0
- package/dist/kernl/kernl.js +116 -0
- package/dist/kernl/threads.d.ts +110 -0
- package/dist/kernl/threads.d.ts.map +1 -0
- package/dist/kernl/threads.js +126 -0
- package/dist/kernl.d.ts +22 -6
- package/dist/kernl.d.ts.map +1 -1
- package/dist/kernl.js +73 -10
- package/dist/lib/env.d.ts +3 -3
- package/dist/lib/env.js +1 -1
- package/dist/mcp/__tests__/integration.test.js +8 -8
- package/dist/mcp/__tests__/utils.test.js +6 -6
- package/dist/mcp/http.d.ts +1 -1
- package/dist/mcp/http.d.ts.map +1 -1
- package/dist/mcp/http.js +9 -9
- package/dist/mcp/sse.d.ts +1 -1
- package/dist/mcp/sse.d.ts.map +1 -1
- package/dist/mcp/sse.js +7 -7
- package/dist/mcp/utils.d.ts +1 -1
- package/dist/mcp/utils.d.ts.map +1 -1
- package/dist/mcp/utils.js +4 -5
- package/dist/storage/__tests__/in-memory.test.d.ts +2 -0
- package/dist/storage/__tests__/in-memory.test.d.ts.map +1 -0
- package/dist/storage/__tests__/in-memory.test.js +455 -0
- package/dist/storage/base.d.ts +64 -0
- package/dist/storage/base.d.ts.map +1 -0
- package/dist/storage/base.js +4 -0
- package/dist/storage/in-memory.d.ts +62 -0
- package/dist/storage/in-memory.d.ts.map +1 -0
- package/dist/storage/in-memory.js +283 -0
- package/dist/storage/index.d.ts +10 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +7 -0
- package/dist/storage/thread.d.ts +123 -0
- package/dist/storage/thread.d.ts.map +1 -0
- package/dist/storage/thread.js +4 -0
- package/dist/task.d.ts +5 -3
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js +10 -8
- package/dist/thread/__tests__/fixtures/mock-model.d.ts +1 -2
- package/dist/thread/__tests__/fixtures/mock-model.d.ts.map +1 -1
- package/dist/thread/__tests__/integration.test.js +6 -6
- package/dist/thread/__tests__/namespace.test.d.ts +2 -0
- package/dist/thread/__tests__/namespace.test.d.ts.map +1 -0
- package/dist/thread/__tests__/namespace.test.js +131 -0
- package/dist/thread/__tests__/thread-persistence.test.d.ts +2 -0
- package/dist/thread/__tests__/thread-persistence.test.d.ts.map +1 -0
- package/dist/thread/__tests__/thread-persistence.test.js +351 -0
- package/dist/thread/__tests__/thread.test.js +49 -51
- package/dist/thread/thread.d.ts +70 -18
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +211 -73
- package/dist/thread/utils.d.ts +36 -8
- package/dist/thread/utils.d.ts.map +1 -1
- package/dist/thread/utils.js +52 -8
- package/dist/tool/__tests__/fixtures.js +1 -1
- package/dist/tool/__tests__/toolkit.test.js +15 -12
- package/dist/tool/tool.js +3 -3
- package/dist/types/kernl.d.ts +42 -0
- package/dist/types/kernl.d.ts.map +1 -0
- package/dist/types/thread.d.ts +108 -22
- package/dist/types/thread.d.ts.map +1 -1
- package/dist/types/thread.js +12 -0
- package/package.json +11 -7
- package/src/agent/__tests__/concurrency.test.ts +194 -0
- package/src/agent/__tests__/run.test.ts +441 -0
- package/src/agent/index.ts +0 -0
- package/src/agent.ts +139 -24
- package/src/api/__tests__/cursor-page.test.ts +512 -0
- package/src/api/__tests__/offset-page.test.ts +624 -0
- package/src/api/__tests__/threads.test.ts +415 -0
- package/src/api/models/index.ts +6 -0
- package/src/api/models/thread.ts +138 -0
- package/src/api/pagination/base.ts +79 -0
- package/src/api/pagination/cursor.ts +86 -0
- package/src/api/pagination/offset.ts +89 -0
- package/src/api/resources/threads/events.ts +26 -0
- package/src/api/resources/threads/index.ts +9 -0
- package/src/api/resources/threads/threads.ts +256 -0
- package/src/api/resources/threads/types.ts +143 -0
- package/src/api/resources/threads/utils.ts +104 -0
- package/src/context.ts +10 -1
- package/src/index.ts +49 -1
- package/src/internal.ts +15 -0
- package/src/kernl.ts +86 -17
- package/src/mcp/__tests__/integration.test.ts +8 -9
- package/src/mcp/__tests__/utils.test.ts +6 -6
- package/src/mcp/http.ts +9 -9
- package/src/mcp/sse.ts +7 -7
- package/src/mcp/utils.ts +6 -5
- package/src/storage/__tests__/in-memory.test.ts +534 -0
- package/src/storage/base.ts +77 -0
- package/src/storage/in-memory.ts +372 -0
- package/src/storage/index.ts +21 -0
- package/src/storage/thread.ts +141 -0
- package/src/task.ts +12 -10
- package/src/thread/__tests__/fixtures/mock-model.ts +2 -4
- package/src/thread/__tests__/integration.test.ts +13 -12
- package/src/thread/__tests__/namespace.test.ts +158 -0
- package/src/thread/__tests__/thread-persistence.test.ts +367 -0
- package/src/thread/__tests__/thread.test.ts +52 -54
- package/src/thread/thread.ts +247 -96
- package/src/thread/utils.ts +76 -13
- package/src/tool/__tests__/fixtures.ts +1 -1
- package/src/tool/__tests__/toolkit.test.ts +15 -12
- package/src/tool/tool.ts +3 -3
- package/src/types/kernl.ts +51 -0
- package/src/types/thread.ts +139 -25
- package/vitest.config.ts +1 -0
- package/dist/env.d.ts +0 -45
- package/dist/env.d.ts.map +0 -1
- package/dist/env.js +0 -31
- package/dist/error.d.ts +0 -1
- package/dist/error.d.ts.map +0 -1
- package/dist/kernel.d.ts +0 -7
- package/dist/kernel.d.ts.map +0 -1
- package/dist/kernel.js +0 -7
- package/dist/lib/serde/__tests__/codec.test.d.ts +0 -2
- package/dist/lib/serde/__tests__/codec.test.d.ts.map +0 -1
- package/dist/lib/serde/__tests__/codec.test.js +0 -75
- package/dist/lib/serde/codec.d.ts +0 -12
- package/dist/lib/serde/codec.d.ts.map +0 -1
- package/dist/lib/serde/codec.js +0 -54
- package/dist/lib/serde/thread.d.ts +0 -1
- package/dist/lib/serde/thread.d.ts.map +0 -1
- package/dist/lib/serde/thread.js +0 -172
- package/dist/lib/serde/tool.d.ts +0 -36
- package/dist/lib/serde/tool.d.ts.map +0 -1
- package/dist/lib/utils.d.ts +0 -19
- package/dist/lib/utils.d.ts.map +0 -1
- package/dist/lib/utils.js +0 -41
- package/dist/logger.d.ts +0 -36
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -43
- package/dist/mcp/__tests__/fixtures/echo-server.d.ts +0 -3
- package/dist/mcp/__tests__/fixtures/echo-server.d.ts.map +0 -1
- package/dist/mcp/__tests__/fixtures/echo-server.js +0 -92
- package/dist/mcp/__tests__/fixtures/math-server.d.ts +0 -3
- package/dist/mcp/__tests__/fixtures/math-server.d.ts.map +0 -1
- package/dist/mcp/__tests__/fixtures/math-server.js +0 -98
- package/dist/mcp/__tests__/fixtures/test-server.d.ts +0 -3
- package/dist/mcp/__tests__/fixtures/test-server.d.ts.map +0 -1
- package/dist/mcp/__tests__/fixtures/test-server.js +0 -163
- package/dist/mcp/__tests__/test-utils.d.ts +0 -17
- package/dist/mcp/__tests__/test-utils.d.ts.map +0 -1
- package/dist/mcp/__tests__/test-utils.js +0 -42
- package/dist/mcp/node.d.ts +0 -60
- package/dist/mcp/node.d.ts.map +0 -1
- package/dist/mcp/node.js +0 -297
- package/dist/model.d.ts +0 -175
- package/dist/model.d.ts.map +0 -1
- package/dist/providers/ai.d.ts +0 -1
- package/dist/providers/ai.d.ts.map +0 -1
- package/dist/providers/ai.js +0 -1
- package/dist/providers/default.d.ts +0 -16
- package/dist/providers/default.d.ts.map +0 -1
- package/dist/providers/default.js +0 -17
- package/dist/providers/registry.d.ts +0 -1
- package/dist/providers/registry.d.ts.map +0 -1
- package/dist/providers/registry.js +0 -1
- package/dist/sched/scheduler.d.ts +0 -20
- package/dist/sched/scheduler.d.ts.map +0 -1
- package/dist/sched/task.d.ts +0 -92
- package/dist/sched/task.d.ts.map +0 -1
- package/dist/sched/task.js +0 -102
- package/dist/serde/__tests__/codec.test.d.ts +0 -2
- package/dist/serde/__tests__/codec.test.d.ts.map +0 -1
- package/dist/serde/__tests__/codec.test.js +0 -75
- package/dist/serde/codec.d.ts +0 -12
- package/dist/serde/codec.d.ts.map +0 -1
- package/dist/serde/codec.js +0 -54
- package/dist/serde/json.d.ts +0 -8
- package/dist/serde/json.d.ts.map +0 -1
- package/dist/serde/json.js +0 -13
- package/dist/serde/thread.d.ts +0 -687
- package/dist/serde/thread.d.ts.map +0 -1
- package/dist/serde/thread.js +0 -158
- package/dist/serde/tool.d.ts +0 -36
- package/dist/serde/tool.d.ts.map +0 -1
- package/dist/session.d.ts +0 -1
- package/dist/session.d.ts.map +0 -1
- package/dist/session.js +0 -1
- package/dist/thread/__tests__/stream.test.d.ts +0 -2
- package/dist/thread/__tests__/stream.test.d.ts.map +0 -1
- package/dist/thread/__tests__/stream.test.js +0 -244
- package/dist/tool/mcp.d.ts +0 -75
- package/dist/tool/mcp.d.ts.map +0 -1
- package/dist/tool/mcp.js +0 -111
- package/dist/tools.d.ts +0 -362
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -220
- package/dist/types/proto.d.ts +0 -1551
- package/dist/types/proto.d.ts.map +0 -1
- package/dist/types/proto.js +0 -531
- package/dist/usage.d.ts +0 -43
- package/dist/usage.d.ts.map +0 -1
- package/dist/usage.js +0 -61
- package/src/lib/serde/thread.ts +0 -188
- /package/dist/{error.js → agent/index.js} +0 -0
- /package/dist/{lib/serde/tool.js → api/models/index.js} +0 -0
- /package/dist/{model.js → api/models/thread.js} +0 -0
- /package/dist/{sched/scheduler.js → api/resources/threads/types.js} +0 -0
- /package/dist/{serde/tool.js → types/kernl.js} +0 -0
package/dist/tools.d.ts
DELETED
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type { Agent } from "./agent";
|
|
3
|
-
import type { RunResult } from "./result";
|
|
4
|
-
import { RunToolApprovalItem, RunToolCallOutputItem } from "./items";
|
|
5
|
-
import * as protocol from "./types/proto";
|
|
6
|
-
import { Context, UnknownContext } from "./context";
|
|
7
|
-
export type { ToolOutputText, ToolOutputImage, ToolOutputFileContent, ToolCallStructuredOutput, ToolCallOutputContent, } from "./types/proto";
|
|
8
|
-
/**
|
|
9
|
-
* A function that determines if a tool call should be approved.
|
|
10
|
-
*
|
|
11
|
-
* @param runContext The current run context
|
|
12
|
-
* @param input The input to the tool
|
|
13
|
-
* @param callId The ID of the tool call
|
|
14
|
-
* @returns True if the tool call should be approved, false otherwise
|
|
15
|
-
*/
|
|
16
|
-
export type ToolApprovalFunction<TParameters extends ToolInputParameters> = (context: Context, input: ToolExecuteArgument<TParameters>, callId?: string) => Promise<boolean>;
|
|
17
|
-
export type ToolEnabledFunction<TContext = UnknownContext> = (context: Context<TContext>, agent: Agent<any, any>) => Promise<boolean>;
|
|
18
|
-
type ToolEnabledPredicate<TContext = UnknownContext> = (args: {
|
|
19
|
-
context: Context<TContext>;
|
|
20
|
-
agent: Agent<any, any>;
|
|
21
|
-
}) => boolean | Promise<boolean>;
|
|
22
|
-
type ToolEnabledOption<Context = UnknownContext> = boolean | ToolEnabledPredicate<Context>;
|
|
23
|
-
/**
|
|
24
|
-
* Exposes a function to the agent as a tool to be called
|
|
25
|
-
*
|
|
26
|
-
* @param Context The context of the tool
|
|
27
|
-
* @param Result The result of the tool
|
|
28
|
-
*/
|
|
29
|
-
export type FunctionTool<TContext = UnknownContext, TParameters extends ToolInputParameters = undefined, Result = unknown> = {
|
|
30
|
-
type: "function";
|
|
31
|
-
/**
|
|
32
|
-
* The name of the tool.
|
|
33
|
-
*/
|
|
34
|
-
name: string;
|
|
35
|
-
/**
|
|
36
|
-
* The description of the tool that helps the model to understand when to use the tool
|
|
37
|
-
*/
|
|
38
|
-
description: string;
|
|
39
|
-
/**
|
|
40
|
-
* A JSON schema describing the parameters of the tool.
|
|
41
|
-
*/
|
|
42
|
-
parameters: JsonObjectSchema<any>;
|
|
43
|
-
/**
|
|
44
|
-
* Whether the tool is strict. If true, the model must try to strictly follow the schema (might result in slower response times).
|
|
45
|
-
*/
|
|
46
|
-
strict: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* The function to invoke when the tool is called.
|
|
49
|
-
*/
|
|
50
|
-
invoke: (context: Context<TContext>, input: string, details?: {
|
|
51
|
-
toolCall: protocol.FunctionCallItem;
|
|
52
|
-
}) => Promise<string | Result>;
|
|
53
|
-
/**
|
|
54
|
-
* Whether the tool needs human approval before it can be called. If this is true, the run will result in an `interruption` that the
|
|
55
|
-
* program has to resolve by approving or rejecting the tool call.
|
|
56
|
-
*/
|
|
57
|
-
needsApproval: ToolApprovalFunction<TParameters>;
|
|
58
|
-
/**
|
|
59
|
-
* Determines whether the tool should be made available to the model for the current run.
|
|
60
|
-
*/
|
|
61
|
-
isEnabled: ToolEnabledFunction<Context>;
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Exposes a computer to the model as a tool to be called
|
|
65
|
-
*
|
|
66
|
-
* @param Context The context of the tool
|
|
67
|
-
* @param Result The result of the tool
|
|
68
|
-
*/
|
|
69
|
-
export type ComputerTool = {
|
|
70
|
-
type: "computer";
|
|
71
|
-
/**
|
|
72
|
-
* The name of the tool.
|
|
73
|
-
*/
|
|
74
|
-
name: "computer_use_preview" | string;
|
|
75
|
-
};
|
|
76
|
-
export type HostedMCPApprovalFunction<TContext = UnknownContext> = (context: Context<TContext>, data: RunToolApprovalItem) => Promise<{
|
|
77
|
-
approve: boolean;
|
|
78
|
-
reason?: string;
|
|
79
|
-
}>;
|
|
80
|
-
/**
|
|
81
|
-
* A hosted MCP tool that lets the model call a remote MCP server directly
|
|
82
|
-
* without a round trip back to your code.
|
|
83
|
-
*/
|
|
84
|
-
export type HostedMCPTool<TContext = UnknownContext> = HostedTool & {
|
|
85
|
-
name: "hosted_mcp";
|
|
86
|
-
providerData: ProviderData.HostedMCPTool<TContext>;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Creates a hosted MCP tool definition.
|
|
90
|
-
*
|
|
91
|
-
* @param options - Configuration for the hosted MCP tool, including server connection details
|
|
92
|
-
* and approval requirements.
|
|
93
|
-
*/
|
|
94
|
-
export declare function hostedMcpTool<TContext = UnknownContext>(options: {
|
|
95
|
-
allowedTools?: string[] | {
|
|
96
|
-
toolNames?: string[];
|
|
97
|
-
};
|
|
98
|
-
} & ({
|
|
99
|
-
serverLabel: string;
|
|
100
|
-
serverUrl?: string;
|
|
101
|
-
authorization?: string;
|
|
102
|
-
headers?: Record<string, string>;
|
|
103
|
-
} | {
|
|
104
|
-
serverLabel: string;
|
|
105
|
-
connectorId: string;
|
|
106
|
-
authorization?: string;
|
|
107
|
-
headers?: Record<string, string>;
|
|
108
|
-
}) & ({
|
|
109
|
-
requireApproval?: never;
|
|
110
|
-
} | {
|
|
111
|
-
requireApproval: "never";
|
|
112
|
-
} | {
|
|
113
|
-
requireApproval: "always" | {
|
|
114
|
-
never?: {
|
|
115
|
-
toolNames: string[];
|
|
116
|
-
};
|
|
117
|
-
always?: {
|
|
118
|
-
toolNames: string[];
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
onApproval?: HostedMCPApprovalFunction<Context>;
|
|
122
|
-
})): HostedMCPTool<Context>;
|
|
123
|
-
/**
|
|
124
|
-
* A built-in hosted tool that will be executed directly by the model during the request and won't result in local code executions.
|
|
125
|
-
* Examples of these are `web_search_call` or `file_search_call`.
|
|
126
|
-
*
|
|
127
|
-
* @param Context The context of the tool
|
|
128
|
-
* @param Result The result of the tool
|
|
129
|
-
*/
|
|
130
|
-
export type HostedTool = {
|
|
131
|
-
type: "hosted_tool";
|
|
132
|
-
/**
|
|
133
|
-
* A unique name for the tool.
|
|
134
|
-
*/
|
|
135
|
-
name: string;
|
|
136
|
-
/**
|
|
137
|
-
* Additional configuration data that gets passed to the tool
|
|
138
|
-
*/
|
|
139
|
-
providerData?: Record<string, any>;
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* A tool that can be called by the model.
|
|
143
|
-
* @template Context The context passed to the tool
|
|
144
|
-
*/
|
|
145
|
-
export type Tool<Context = unknown> = FunctionTool<Context, any, any> | ComputerTool | HostedTool;
|
|
146
|
-
/**
|
|
147
|
-
* The result of invoking a function tool. Either the actual output of the execution or a tool
|
|
148
|
-
* approval request.
|
|
149
|
-
*
|
|
150
|
-
* These get passed for example to the `toolUseBehavior` option of the `Agent` constructor.
|
|
151
|
-
*/
|
|
152
|
-
export type FunctionToolResult<TContext = UnknownContext, TParameters extends ToolInputParameters = any, Result = any> = {
|
|
153
|
-
type: "function_output";
|
|
154
|
-
/**
|
|
155
|
-
* The tool that was called.
|
|
156
|
-
*/
|
|
157
|
-
tool: FunctionTool<TContext, TParameters, Result>;
|
|
158
|
-
/**
|
|
159
|
-
* The output of the tool call. This can be a string or a stringifable item.
|
|
160
|
-
*/
|
|
161
|
-
output: string | unknown;
|
|
162
|
-
/**
|
|
163
|
-
* The run item representing the tool call output.
|
|
164
|
-
*/
|
|
165
|
-
runItem: RunToolCallOutputItem;
|
|
166
|
-
/**
|
|
167
|
-
* The result returned when the tool execution runs another agent. Populated when the
|
|
168
|
-
* invocation originated from {@link Agent.asTool} and the nested agent completed a run.
|
|
169
|
-
*/
|
|
170
|
-
agentRunResult?: RunResult<TContext, Agent<TContext, any>>;
|
|
171
|
-
/**
|
|
172
|
-
* Any interruptions collected while the nested agent executed. These are surfaced to allow
|
|
173
|
-
* callers to pause and resume workflows that require approvals.
|
|
174
|
-
*/
|
|
175
|
-
interruptions?: RunToolApprovalItem[];
|
|
176
|
-
} | {
|
|
177
|
-
/**
|
|
178
|
-
* Indicates that the tool requires approval before it can be called.
|
|
179
|
-
*/
|
|
180
|
-
type: "function_approval";
|
|
181
|
-
/**
|
|
182
|
-
* The tool that is requiring to be approved.
|
|
183
|
-
*/
|
|
184
|
-
tool: FunctionTool<TContext, TParameters, Result>;
|
|
185
|
-
/**
|
|
186
|
-
* The item representing the tool call that is requiring approval.
|
|
187
|
-
*/
|
|
188
|
-
runItem: RunToolApprovalItem;
|
|
189
|
-
} | {
|
|
190
|
-
/**
|
|
191
|
-
* Indicates that the tool requires approval before it can be called.
|
|
192
|
-
*/
|
|
193
|
-
type: "hosted_mcp_tool_approval";
|
|
194
|
-
/**
|
|
195
|
-
* The tool that is requiring to be approved.
|
|
196
|
-
*/
|
|
197
|
-
tool: HostedMCPTool<TContext>;
|
|
198
|
-
/**
|
|
199
|
-
* The item representing the tool call that is requiring approval.
|
|
200
|
-
*/
|
|
201
|
-
runItem: RunToolApprovalItem;
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
204
|
-
* The parameters of a tool.
|
|
205
|
-
*
|
|
206
|
-
* This can be a Zod schema, a JSON schema or undefined.
|
|
207
|
-
*
|
|
208
|
-
* If a Zod schema is provided, the arguments to the tool will automatically be parsed and validated
|
|
209
|
-
* against the schema.
|
|
210
|
-
*
|
|
211
|
-
* If a JSON schema is provided, the arguments to the tool will be passed as is.
|
|
212
|
-
*
|
|
213
|
-
* If undefined is provided, the arguments to the tool will be passed as a string.
|
|
214
|
-
*/
|
|
215
|
-
export type ToolInputParameters = undefined | ZodObjectLike | JsonObjectSchema<any>;
|
|
216
|
-
/**
|
|
217
|
-
* The parameters of a tool that has strict mode enabled.
|
|
218
|
-
*
|
|
219
|
-
* This can be a Zod schema, a JSON schema or undefined.
|
|
220
|
-
*
|
|
221
|
-
* If a Zod schema is provided, the arguments to the tool will automatically be parsed and validated
|
|
222
|
-
* against the schema.
|
|
223
|
-
*
|
|
224
|
-
* If a JSON schema is provided, the arguments to the tool will be parsed as JSON but not validated.
|
|
225
|
-
*
|
|
226
|
-
* If undefined is provided, the arguments to the tool will be passed as a string.
|
|
227
|
-
*/
|
|
228
|
-
export type ToolInputParametersStrict = undefined | ZodObjectLike | JsonObjectSchemaStrict<any>;
|
|
229
|
-
/**
|
|
230
|
-
* The parameters of a tool that has strict mode disabled.
|
|
231
|
-
*
|
|
232
|
-
* If a JSON schema is provided, the arguments to the tool will be parsed as JSON but not validated.
|
|
233
|
-
*
|
|
234
|
-
* Zod schemas are not supported without strict: true.
|
|
235
|
-
*/
|
|
236
|
-
export type ToolInputParametersNonStrict = undefined | JsonObjectSchemaNonStrict<any>;
|
|
237
|
-
/**
|
|
238
|
-
* The arguments to a tool.
|
|
239
|
-
*
|
|
240
|
-
* The type of the arguments are derived from the parameters passed to the tool definition.
|
|
241
|
-
*
|
|
242
|
-
* If the parameters are passed as a JSON schema the type is `unknown`. For Zod schemas it will
|
|
243
|
-
* match the inferred Zod type. Otherwise the type is `string`
|
|
244
|
-
*/
|
|
245
|
-
export type ToolExecuteArgument<TParameters extends ToolInputParameters> = TParameters extends ZodObjectLike ? z.infer<TParameters> : TParameters extends JsonObjectSchema<any> ? unknown : string;
|
|
246
|
-
/**
|
|
247
|
-
* The function to invoke when the tool is called.
|
|
248
|
-
*
|
|
249
|
-
* @param input The arguments to the tool (see ToolExecuteArgument)
|
|
250
|
-
* @param context An instance of the current RunContext
|
|
251
|
-
*/
|
|
252
|
-
type ToolExecuteFunction<TContext = UnknownContext, TParameters extends ToolInputParameters> = (context: Context<TContext>, input: ToolExecuteArgument<TParameters>, details?: {
|
|
253
|
-
toolCall: protocol.FunctionCallItem;
|
|
254
|
-
}) => Promise<unknown> | unknown;
|
|
255
|
-
/**
|
|
256
|
-
* The function to invoke when an error occurs while running the tool. This can be used to define
|
|
257
|
-
* what the model should receive as tool output in case of an error. It can be used to provide
|
|
258
|
-
* for example additional context or a fallback value.
|
|
259
|
-
*
|
|
260
|
-
* @param context An instance of the current RunContext
|
|
261
|
-
* @param error The error that occurred
|
|
262
|
-
*/
|
|
263
|
-
type ToolErrorFunction = (context: Context, error: Error | unknown) => Promise<string> | string;
|
|
264
|
-
/**
|
|
265
|
-
* The options for a tool that has strict mode enabled.
|
|
266
|
-
*
|
|
267
|
-
* @param TParameters The parameters of the tool
|
|
268
|
-
* @param Context The context of the tool
|
|
269
|
-
*/
|
|
270
|
-
type StrictToolOptions<TParameters extends ToolInputParametersStrict, Context = UnknownContext> = {
|
|
271
|
-
/**
|
|
272
|
-
* The name of the tool. Must be unique within the agent.
|
|
273
|
-
*/
|
|
274
|
-
name?: string;
|
|
275
|
-
/**
|
|
276
|
-
* The description of the tool. This is used to help the model understand when to use the tool.
|
|
277
|
-
*/
|
|
278
|
-
description: string;
|
|
279
|
-
/**
|
|
280
|
-
* A Zod schema or JSON schema describing the parameters of the tool.
|
|
281
|
-
* If a Zod schema is provided, the arguments to the tool will automatically be parsed and validated
|
|
282
|
-
* against the schema.
|
|
283
|
-
*/
|
|
284
|
-
parameters: TParameters;
|
|
285
|
-
/**
|
|
286
|
-
* Whether the tool is strict. If true, the model must try to strictly follow the schema (might result in slower response times).
|
|
287
|
-
*/
|
|
288
|
-
strict?: true;
|
|
289
|
-
/**
|
|
290
|
-
* The function to invoke when the tool is called.
|
|
291
|
-
*/
|
|
292
|
-
execute: ToolExecuteFunction<TParameters, Context>;
|
|
293
|
-
/**
|
|
294
|
-
* The function to invoke when an error occurs while running the tool.
|
|
295
|
-
*/
|
|
296
|
-
errorFunction?: ToolErrorFunction | null;
|
|
297
|
-
/**
|
|
298
|
-
* Whether the tool needs human approval before it can be called. If this is true, the run will result in an `interruption` that the
|
|
299
|
-
* program has to resolve by approving or rejecting the tool call.
|
|
300
|
-
*/
|
|
301
|
-
needsApproval?: boolean | ToolApprovalFunction<TParameters>;
|
|
302
|
-
/**
|
|
303
|
-
* Determines whether the tool should be exposed to the model for the current run.
|
|
304
|
-
*/
|
|
305
|
-
isEnabled?: ToolEnabledOption<Context>;
|
|
306
|
-
};
|
|
307
|
-
/**
|
|
308
|
-
* The options for a tool that has strict mode disabled.
|
|
309
|
-
*
|
|
310
|
-
* @param TParameters The parameters of the tool
|
|
311
|
-
* @param Context The context of the tool
|
|
312
|
-
*/
|
|
313
|
-
type NonStrictToolOptions<TParameters extends ToolInputParametersNonStrict, TContext = UnknownContext> = {
|
|
314
|
-
/**
|
|
315
|
-
* The name of the tool. Must be unique within the agent.
|
|
316
|
-
*/
|
|
317
|
-
name?: string;
|
|
318
|
-
/**
|
|
319
|
-
* The description of the tool. This is used to help the model understand when to use the tool.
|
|
320
|
-
*/
|
|
321
|
-
description: string;
|
|
322
|
-
/**
|
|
323
|
-
* A JSON schema of the tool. To use a Zod schema, you need to use a `strict` schema.
|
|
324
|
-
*/
|
|
325
|
-
parameters: TParameters;
|
|
326
|
-
/**
|
|
327
|
-
* Whether the tool is strict If true, the model must try to strictly follow the schema (might result in slower response times).
|
|
328
|
-
*/
|
|
329
|
-
strict: false;
|
|
330
|
-
/**
|
|
331
|
-
* The function to invoke when the tool is called.
|
|
332
|
-
*/
|
|
333
|
-
execute: ToolExecuteFunction<TContext, TParameters>;
|
|
334
|
-
/**
|
|
335
|
-
* The function to invoke when an error occurs while running the tool.
|
|
336
|
-
*/
|
|
337
|
-
errorFunction?: ToolErrorFunction | null;
|
|
338
|
-
/**
|
|
339
|
-
* Whether the tool needs human approval before it can be called. If this is true, the run will result in an `interruption` that the
|
|
340
|
-
* program has to resolve by approving or rejecting the tool call.
|
|
341
|
-
*/
|
|
342
|
-
needsApproval?: boolean | ToolApprovalFunction<TParameters>;
|
|
343
|
-
/**
|
|
344
|
-
* Determines whether the tool should be exposed to the model for the current run.
|
|
345
|
-
*/
|
|
346
|
-
isEnabled?: ToolEnabledOption<TContext>;
|
|
347
|
-
};
|
|
348
|
-
/**
|
|
349
|
-
* The options for a tool.
|
|
350
|
-
*
|
|
351
|
-
* @param TContext The context of the tool
|
|
352
|
-
* @param TParameters The parameters of the tool
|
|
353
|
-
*/
|
|
354
|
-
export type ToolOptions<TContext = UnknownContext, TParameters extends ToolInputParameters> = StrictToolOptions<Extract<TParameters, ToolInputParametersStrict>, TContext> | NonStrictToolOptions<Extract<TParameters, ToolInputParametersNonStrict>, TContext>;
|
|
355
|
-
/**
|
|
356
|
-
* Exposes a function to the agent as a tool to be called
|
|
357
|
-
*
|
|
358
|
-
* @param options The options for the tool
|
|
359
|
-
* @returns A new tool
|
|
360
|
-
*/
|
|
361
|
-
export declare function tool<TContext = UnknownContext, TParameters extends ToolInputParameters = undefined, Result = string>(options: ToolOptions<TContext, TParameters>): FunctionTool<TContext, TParameters, Result>;
|
|
362
|
-
//# sourceMappingURL=tools.d.ts.map
|
package/dist/tools.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAYrE,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEpD,YAAY,EACV,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB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,EAAE,OAAO,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAE5D;;OAEG;IACH,SAAS,CAAC,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC;CACzC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,WAAW,CACrB,QAAQ,GAAG,cAAc,EACzB,WAAW,SAAS,mBAAmB,IAErC,iBAAiB,CAAC,OAAO,CAAC,WAAW,EAAE,yBAAyB,CAAC,EAAE,QAAQ,CAAC,GAC5E,oBAAoB,CAClB,OAAO,CAAC,WAAW,EAAE,4BAA4B,CAAC,EAClD,QAAQ,CACT,CAAC;AAEN;;;;;GAKG;AACH,wBAAgB,IAAI,CAClB,QAAQ,GAAG,cAAc,EACzB,WAAW,SAAS,mBAAmB,GAAG,SAAS,EACnD,MAAM,GAAG,MAAM,EAEf,OAAO,EAAE,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,GAC1C,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CA4G7C"}
|
package/dist/tools.js
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import logger from "./logger";
|
|
2
|
-
import { getCurrentSpan } from "./tracing";
|
|
3
|
-
// --- utils ---
|
|
4
|
-
import { safeExecute } from "./utils/safeExecute";
|
|
5
|
-
import { toFunctionToolName } from "./utils/tools";
|
|
6
|
-
import { getSchemaAndParserFromInputType } from "./utils/tools";
|
|
7
|
-
import { isZodObject } from "./utils/typeGuards";
|
|
8
|
-
/**
|
|
9
|
-
* Creates a hosted MCP tool definition.
|
|
10
|
-
*
|
|
11
|
-
* @param options - Configuration for the hosted MCP tool, including server connection details
|
|
12
|
-
* and approval requirements.
|
|
13
|
-
*/
|
|
14
|
-
export function hostedMcpTool(options) {
|
|
15
|
-
if ("serverUrl" in options) {
|
|
16
|
-
// the MCP servers comaptible with the specification
|
|
17
|
-
const providerData = typeof options.requireApproval === "undefined" ||
|
|
18
|
-
options.requireApproval === "never"
|
|
19
|
-
? {
|
|
20
|
-
type: "mcp",
|
|
21
|
-
server_label: options.serverLabel,
|
|
22
|
-
server_url: options.serverUrl,
|
|
23
|
-
authorization: options.authorization,
|
|
24
|
-
require_approval: "never",
|
|
25
|
-
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
|
|
26
|
-
headers: options.headers,
|
|
27
|
-
}
|
|
28
|
-
: {
|
|
29
|
-
type: "mcp",
|
|
30
|
-
server_label: options.serverLabel,
|
|
31
|
-
server_url: options.serverUrl,
|
|
32
|
-
authorization: options.authorization,
|
|
33
|
-
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
|
|
34
|
-
headers: options.headers,
|
|
35
|
-
require_approval: typeof options.requireApproval === "string"
|
|
36
|
-
? "always"
|
|
37
|
-
: buildRequireApproval(options.requireApproval),
|
|
38
|
-
on_approval: options.onApproval,
|
|
39
|
-
};
|
|
40
|
-
return {
|
|
41
|
-
type: "hosted_tool",
|
|
42
|
-
name: "hosted_mcp",
|
|
43
|
-
providerData,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
else if ("connectorId" in options) {
|
|
47
|
-
// OpenAI's connectors
|
|
48
|
-
const providerData = typeof options.requireApproval === "undefined" ||
|
|
49
|
-
options.requireApproval === "never"
|
|
50
|
-
? {
|
|
51
|
-
type: "mcp",
|
|
52
|
-
server_label: options.serverLabel,
|
|
53
|
-
connector_id: options.connectorId,
|
|
54
|
-
authorization: options.authorization,
|
|
55
|
-
require_approval: "never",
|
|
56
|
-
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
|
|
57
|
-
headers: options.headers,
|
|
58
|
-
}
|
|
59
|
-
: {
|
|
60
|
-
type: "mcp",
|
|
61
|
-
server_label: options.serverLabel,
|
|
62
|
-
connector_id: options.connectorId,
|
|
63
|
-
authorization: options.authorization,
|
|
64
|
-
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
|
|
65
|
-
headers: options.headers,
|
|
66
|
-
require_approval: typeof options.requireApproval === "string"
|
|
67
|
-
? "always"
|
|
68
|
-
: buildRequireApproval(options.requireApproval),
|
|
69
|
-
on_approval: options.onApproval,
|
|
70
|
-
};
|
|
71
|
-
return {
|
|
72
|
-
type: "hosted_tool",
|
|
73
|
-
name: "hosted_mcp",
|
|
74
|
-
providerData,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
// the MCP servers comaptible with the specification
|
|
79
|
-
const providerData = typeof options.requireApproval === "undefined" ||
|
|
80
|
-
options.requireApproval === "never"
|
|
81
|
-
? {
|
|
82
|
-
type: "mcp",
|
|
83
|
-
server_label: options.serverLabel,
|
|
84
|
-
require_approval: "never",
|
|
85
|
-
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
|
|
86
|
-
}
|
|
87
|
-
: {
|
|
88
|
-
type: "mcp",
|
|
89
|
-
server_label: options.serverLabel,
|
|
90
|
-
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
|
|
91
|
-
require_approval: typeof options.requireApproval === "string"
|
|
92
|
-
? "always"
|
|
93
|
-
: buildRequireApproval(options.requireApproval),
|
|
94
|
-
on_approval: options.onApproval,
|
|
95
|
-
};
|
|
96
|
-
return {
|
|
97
|
-
type: "hosted_tool",
|
|
98
|
-
name: "hosted_mcp",
|
|
99
|
-
providerData,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* The default function to invoke when an error occurs while running the tool.
|
|
105
|
-
*
|
|
106
|
-
* Always returns `An error occurred while running the tool. Please try again. Error: <error details>`
|
|
107
|
-
*
|
|
108
|
-
* @param context An instance of the current RunContext
|
|
109
|
-
* @param error The error that occurred
|
|
110
|
-
*/
|
|
111
|
-
function defaultToolErrorFunction(context, error) {
|
|
112
|
-
const details = error instanceof Error ? error.toString() : String(error);
|
|
113
|
-
return `An error occurred while running the tool. Please try again. Error: ${details}`;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Exposes a function to the agent as a tool to be called
|
|
117
|
-
*
|
|
118
|
-
* @param options The options for the tool
|
|
119
|
-
* @returns A new tool
|
|
120
|
-
*/
|
|
121
|
-
export function tool(options) {
|
|
122
|
-
const name = options.name
|
|
123
|
-
? toFunctionToolName(options.name)
|
|
124
|
-
: toFunctionToolName(options.execute.name);
|
|
125
|
-
const toolErrorFunction = typeof options.errorFunction === "undefined"
|
|
126
|
-
? defaultToolErrorFunction
|
|
127
|
-
: options.errorFunction;
|
|
128
|
-
if (!name) {
|
|
129
|
-
throw new Error("Tool name cannot be empty. Either name your function or provide a name in the options.");
|
|
130
|
-
}
|
|
131
|
-
const strictMode = options.strict ?? true;
|
|
132
|
-
if (!strictMode && isZodObject(options.parameters)) {
|
|
133
|
-
throw new UserError("Strict mode is required for Zod parameters");
|
|
134
|
-
}
|
|
135
|
-
const { parser, schema: parameters } = getSchemaAndParserFromInputType(options.parameters, name);
|
|
136
|
-
async function _invoke(context, input, details) {
|
|
137
|
-
const [error, parsed] = await safeExecute(() => parser(input));
|
|
138
|
-
if (error !== null) {
|
|
139
|
-
if (logger.dontLogToolData) {
|
|
140
|
-
logger.debug(`Invalid JSON input for tool ${name}`);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
logger.debug(`Invalid JSON input for tool ${name}: ${input}`);
|
|
144
|
-
}
|
|
145
|
-
throw new ModelBehaviorError("Invalid JSON input for tool");
|
|
146
|
-
}
|
|
147
|
-
if (logger.dontLogToolData) {
|
|
148
|
-
logger.debug(`Invoking tool ${name}`);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
logger.debug(`Invoking tool ${name} with input ${input}`);
|
|
152
|
-
}
|
|
153
|
-
const result = await options.execute(parsed, context, details);
|
|
154
|
-
const stringResult = toSmartString(result);
|
|
155
|
-
if (logger.dontLogToolData) {
|
|
156
|
-
logger.debug(`Tool ${name} completed`);
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
logger.debug(`Tool ${name} returned: ${stringResult}`);
|
|
160
|
-
}
|
|
161
|
-
return result;
|
|
162
|
-
}
|
|
163
|
-
async function invoke(context, input, details) {
|
|
164
|
-
return _invoke(context, input, details).catch((error) => {
|
|
165
|
-
if (toolErrorFunction) {
|
|
166
|
-
const currentSpan = getCurrentSpan();
|
|
167
|
-
currentSpan?.setError({
|
|
168
|
-
message: "Error running tool (non-fatal)",
|
|
169
|
-
data: {
|
|
170
|
-
tool_name: name,
|
|
171
|
-
error: error.toString(),
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
return toolErrorFunction(context, error);
|
|
175
|
-
}
|
|
176
|
-
throw error;
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
const needsApproval = typeof options.needsApproval === "function"
|
|
180
|
-
? options.needsApproval
|
|
181
|
-
: async () => typeof options.needsApproval === "boolean"
|
|
182
|
-
? options.needsApproval
|
|
183
|
-
: false;
|
|
184
|
-
const isEnabled = typeof options.isEnabled === "function"
|
|
185
|
-
? async (context, agent) => {
|
|
186
|
-
const predicate = options.isEnabled;
|
|
187
|
-
const result = await predicate({ context, agent });
|
|
188
|
-
return Boolean(result);
|
|
189
|
-
}
|
|
190
|
-
: async () => typeof options.isEnabled === "boolean" ? options.isEnabled : true;
|
|
191
|
-
return {
|
|
192
|
-
type: "function",
|
|
193
|
-
name,
|
|
194
|
-
description: options.description,
|
|
195
|
-
parameters,
|
|
196
|
-
strict: strictMode,
|
|
197
|
-
invoke,
|
|
198
|
-
needsApproval,
|
|
199
|
-
isEnabled,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
function buildRequireApproval(requireApproval) {
|
|
203
|
-
const result = {};
|
|
204
|
-
if (requireApproval.always) {
|
|
205
|
-
result.always = { tool_names: requireApproval.always.toolNames };
|
|
206
|
-
}
|
|
207
|
-
if (requireApproval.never) {
|
|
208
|
-
result.never = { tool_names: requireApproval.never.toolNames };
|
|
209
|
-
}
|
|
210
|
-
return result;
|
|
211
|
-
}
|
|
212
|
-
function toMcpAllowedToolsFilter(allowedTools) {
|
|
213
|
-
if (typeof allowedTools === "undefined") {
|
|
214
|
-
return undefined;
|
|
215
|
-
}
|
|
216
|
-
if (Array.isArray(allowedTools)) {
|
|
217
|
-
return { tool_names: allowedTools };
|
|
218
|
-
}
|
|
219
|
-
return { tool_names: allowedTools?.toolNames ?? [] };
|
|
220
|
-
}
|