@stackline/tool-router 1.0.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/CHANGELOG.md +24 -0
- package/CONTRIBUTING.md +34 -0
- package/LICENSE +21 -0
- package/NOTICE +5 -0
- package/README.md +336 -0
- package/SECURITY.md +33 -0
- package/dist/index.cjs +1123 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.cts +247 -0
- package/dist/index.d.mts +247 -0
- package/dist/index.d.ts +247 -0
- package/dist/index.js +1102 -0
- package/dist/index.js.map +7 -0
- package/dist/index.min.js +3 -0
- package/dist/index.min.js.map +7 -0
- package/package.json +100 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
export type ToolFormat =
|
|
2
|
+
| 'canonical'
|
|
3
|
+
| 'mcp'
|
|
4
|
+
| 'openai-chat'
|
|
5
|
+
| 'openai-responses'
|
|
6
|
+
| 'anthropic'
|
|
7
|
+
| 'gemini';
|
|
8
|
+
|
|
9
|
+
export type ToolFormatInput = ToolFormat | 'auto';
|
|
10
|
+
|
|
11
|
+
export type JsonSchema = boolean | {
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export interface CanonicalTool {
|
|
16
|
+
id?: string;
|
|
17
|
+
name: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
namespace?: string;
|
|
20
|
+
tags?: readonly string[];
|
|
21
|
+
aliases?: readonly string[];
|
|
22
|
+
inputSchema?: JsonSchema;
|
|
23
|
+
outputSchema?: JsonSchema;
|
|
24
|
+
schema?: JsonSchema;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface NormalizedTool<T = unknown> {
|
|
29
|
+
readonly aliases: readonly string[];
|
|
30
|
+
readonly description: string;
|
|
31
|
+
readonly format: ToolFormat;
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly inputSchema: unknown;
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly namespace: string;
|
|
36
|
+
readonly original: T;
|
|
37
|
+
readonly outputSchema: unknown;
|
|
38
|
+
readonly tags: readonly string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface FieldWeights {
|
|
42
|
+
aliases?: number;
|
|
43
|
+
description?: number;
|
|
44
|
+
name?: number;
|
|
45
|
+
namespace?: number;
|
|
46
|
+
schema?: number;
|
|
47
|
+
tags?: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ToolRouterOptions {
|
|
51
|
+
b?: number;
|
|
52
|
+
fieldWeights?: FieldWeights;
|
|
53
|
+
format?: ToolFormatInput;
|
|
54
|
+
fuzzy?: boolean;
|
|
55
|
+
k1?: number;
|
|
56
|
+
maxExpansions?: number;
|
|
57
|
+
maxQueryLength?: number;
|
|
58
|
+
maxSchemaDepth?: number;
|
|
59
|
+
maxSchemaNodes?: number;
|
|
60
|
+
maxTextLength?: number;
|
|
61
|
+
maxTools?: number;
|
|
62
|
+
minFuzzyLength?: number;
|
|
63
|
+
onDuplicate?: 'error' | 'replace';
|
|
64
|
+
synonyms?: false | {
|
|
65
|
+
[word: string]: string | readonly string[];
|
|
66
|
+
};
|
|
67
|
+
tokenizer?(input: string): string[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface ResolvedToolRouterOptions {
|
|
71
|
+
readonly b: number;
|
|
72
|
+
readonly fieldWeights: Readonly<Required<FieldWeights>>;
|
|
73
|
+
readonly format?: ToolFormatInput;
|
|
74
|
+
readonly fuzzy: boolean;
|
|
75
|
+
readonly k1: number;
|
|
76
|
+
readonly maxExpansions: number;
|
|
77
|
+
readonly maxQueryLength: number;
|
|
78
|
+
readonly maxSchemaDepth: number;
|
|
79
|
+
readonly maxSchemaNodes: number;
|
|
80
|
+
readonly maxTextLength: number;
|
|
81
|
+
readonly maxTools: number;
|
|
82
|
+
readonly minFuzzyLength: number;
|
|
83
|
+
readonly onDuplicate: 'error' | 'replace';
|
|
84
|
+
readonly synonyms: Readonly<Record<string, readonly string[]>>;
|
|
85
|
+
readonly tokenizer: (input: string) => string[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ToolSearchOptions<T = unknown> {
|
|
89
|
+
filter?(record: NormalizedTool<T>): boolean;
|
|
90
|
+
formats?: string | readonly string[];
|
|
91
|
+
ids?: string | readonly string[];
|
|
92
|
+
limit?: number;
|
|
93
|
+
maxEstimatedTokens?: number;
|
|
94
|
+
minScore?: number;
|
|
95
|
+
namespaces?: string | readonly string[];
|
|
96
|
+
tags?: string | readonly string[];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface ToolRouteOptions<T = unknown> extends ToolSearchOptions<T> {
|
|
100
|
+
fallback?: 'none' | 'first' | 'all';
|
|
101
|
+
maxTools?: number;
|
|
102
|
+
pinned?: string | readonly string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface ToolMatch<T = unknown> {
|
|
106
|
+
readonly estimatedTokens: number;
|
|
107
|
+
readonly id: string;
|
|
108
|
+
readonly matchedFields: readonly string[];
|
|
109
|
+
readonly matchedTerms: readonly string[];
|
|
110
|
+
readonly name: string;
|
|
111
|
+
readonly pinned: boolean;
|
|
112
|
+
readonly queryCoverage: number;
|
|
113
|
+
readonly record: NormalizedTool<T>;
|
|
114
|
+
readonly score: number | null;
|
|
115
|
+
readonly tool: T;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface ToolRouteResult<T = unknown> {
|
|
119
|
+
readonly budgetExceeded: boolean;
|
|
120
|
+
readonly catalogEstimatedTokens: number;
|
|
121
|
+
readonly catalogSize: number;
|
|
122
|
+
readonly estimatedTokens: number;
|
|
123
|
+
readonly matches: readonly ToolMatch<T>[];
|
|
124
|
+
readonly records: readonly NormalizedTool<T>[];
|
|
125
|
+
readonly selectedCount: number;
|
|
126
|
+
readonly tokenReduction: number;
|
|
127
|
+
readonly tools: readonly T[];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface ToolRouterStats {
|
|
131
|
+
readonly estimatedTokens: number;
|
|
132
|
+
readonly fields: Readonly<Record<string, number>>;
|
|
133
|
+
readonly terms: number;
|
|
134
|
+
readonly tools: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export type ToolCatalog<T> =
|
|
138
|
+
| readonly T[]
|
|
139
|
+
| { tools: readonly T[] }
|
|
140
|
+
| { functionDeclarations: readonly T[] };
|
|
141
|
+
|
|
142
|
+
export class ToolRouterError extends Error {
|
|
143
|
+
constructor(code: string, message: string, details?: unknown);
|
|
144
|
+
readonly code: string;
|
|
145
|
+
readonly details?: unknown;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export class ToolRouter<T = unknown> {
|
|
149
|
+
constructor(tools?: ToolCatalog<T>, options?: ToolRouterOptions);
|
|
150
|
+
readonly size: number;
|
|
151
|
+
readonly options: ResolvedToolRouterOptions;
|
|
152
|
+
add(tools: T | ToolCatalog<T>, options?: { format?: ToolFormatInput }): this;
|
|
153
|
+
remove(ids: string | readonly string[]): number;
|
|
154
|
+
replace(tools: ToolCatalog<T>, options?: { format?: ToolFormatInput }): this;
|
|
155
|
+
clear(): this;
|
|
156
|
+
has(idOrName: string): boolean;
|
|
157
|
+
get(idOrName: string): NormalizedTool<T> | undefined;
|
|
158
|
+
list(): NormalizedTool<T>[];
|
|
159
|
+
stats(): ToolRouterStats;
|
|
160
|
+
search(query: string, options?: ToolSearchOptions<T>): ToolMatch<T>[];
|
|
161
|
+
select(query: string, options?: ToolSearchOptions<T>): T[];
|
|
162
|
+
route(query: string, options?: ToolRouteOptions<T>): ToolRouteResult<T>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export type ToolSearchTarget = ToolFormat;
|
|
166
|
+
|
|
167
|
+
export interface ToolSearchInput {
|
|
168
|
+
query: string;
|
|
169
|
+
limit?: number;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface ToolSearchSummary {
|
|
173
|
+
readonly description: string;
|
|
174
|
+
readonly id: string;
|
|
175
|
+
readonly name: string;
|
|
176
|
+
readonly namespace?: string;
|
|
177
|
+
readonly score: number | null;
|
|
178
|
+
readonly tags: readonly string[];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface ToolSearchResult {
|
|
182
|
+
readonly catalogSize: number;
|
|
183
|
+
readonly query: string;
|
|
184
|
+
readonly tools: readonly ToolSearchSummary[];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface ToolSearchHelper {
|
|
188
|
+
readonly definition: unknown;
|
|
189
|
+
execute(input: ToolSearchInput): ToolSearchResult;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export const TOOL_FORMATS: readonly ToolFormat[];
|
|
193
|
+
|
|
194
|
+
export function createToolRouter<T = unknown>(
|
|
195
|
+
tools?: ToolCatalog<T>,
|
|
196
|
+
options?: ToolRouterOptions
|
|
197
|
+
): ToolRouter<T>;
|
|
198
|
+
|
|
199
|
+
export function routeTools<T = unknown>(
|
|
200
|
+
tools: ToolCatalog<T>,
|
|
201
|
+
query: string,
|
|
202
|
+
options?: ToolRouteOptions<T> & { router?: ToolRouterOptions }
|
|
203
|
+
): ToolRouteResult<T>;
|
|
204
|
+
|
|
205
|
+
export function createToolSearch<T = unknown>(
|
|
206
|
+
router: ToolRouter<T>,
|
|
207
|
+
options?: {
|
|
208
|
+
target?: ToolSearchTarget;
|
|
209
|
+
name?: string;
|
|
210
|
+
description?: string;
|
|
211
|
+
limit?: number;
|
|
212
|
+
}
|
|
213
|
+
): ToolSearchHelper;
|
|
214
|
+
|
|
215
|
+
export function defineTool<T>(tool: T): T;
|
|
216
|
+
export function detectToolFormat(tool: unknown): ToolFormat;
|
|
217
|
+
export function normalizeTool<T = unknown>(
|
|
218
|
+
tool: T,
|
|
219
|
+
options?: { format?: ToolFormatInput }
|
|
220
|
+
): NormalizedTool<T>;
|
|
221
|
+
export function normalizeTools<T = unknown>(
|
|
222
|
+
tools: ToolCatalog<T>,
|
|
223
|
+
options?: { format?: ToolFormatInput; maxTools?: number }
|
|
224
|
+
): NormalizedTool<T>[];
|
|
225
|
+
export function estimateToolTokens(tool: unknown): number;
|
|
226
|
+
export function normalizeIdentifier(input: unknown): string;
|
|
227
|
+
export function normalizeText(input: unknown): string;
|
|
228
|
+
export function tokenize(input: unknown, options?: { maxTokenLength?: number }): string[];
|
|
229
|
+
|
|
230
|
+
declare const api: {
|
|
231
|
+
TOOL_FORMATS: typeof TOOL_FORMATS;
|
|
232
|
+
ToolRouter: typeof ToolRouter;
|
|
233
|
+
ToolRouterError: typeof ToolRouterError;
|
|
234
|
+
createToolRouter: typeof createToolRouter;
|
|
235
|
+
createToolSearch: typeof createToolSearch;
|
|
236
|
+
defineTool: typeof defineTool;
|
|
237
|
+
detectToolFormat: typeof detectToolFormat;
|
|
238
|
+
estimateToolTokens: typeof estimateToolTokens;
|
|
239
|
+
normalizeIdentifier: typeof normalizeIdentifier;
|
|
240
|
+
normalizeText: typeof normalizeText;
|
|
241
|
+
normalizeTool: typeof normalizeTool;
|
|
242
|
+
normalizeTools: typeof normalizeTools;
|
|
243
|
+
routeTools: typeof routeTools;
|
|
244
|
+
tokenize: typeof tokenize;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
export default api;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
export type ToolFormat =
|
|
2
|
+
| 'canonical'
|
|
3
|
+
| 'mcp'
|
|
4
|
+
| 'openai-chat'
|
|
5
|
+
| 'openai-responses'
|
|
6
|
+
| 'anthropic'
|
|
7
|
+
| 'gemini';
|
|
8
|
+
|
|
9
|
+
export type ToolFormatInput = ToolFormat | 'auto';
|
|
10
|
+
|
|
11
|
+
export type JsonSchema = boolean | {
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export interface CanonicalTool {
|
|
16
|
+
id?: string;
|
|
17
|
+
name: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
namespace?: string;
|
|
20
|
+
tags?: readonly string[];
|
|
21
|
+
aliases?: readonly string[];
|
|
22
|
+
inputSchema?: JsonSchema;
|
|
23
|
+
outputSchema?: JsonSchema;
|
|
24
|
+
schema?: JsonSchema;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface NormalizedTool<T = unknown> {
|
|
29
|
+
readonly aliases: readonly string[];
|
|
30
|
+
readonly description: string;
|
|
31
|
+
readonly format: ToolFormat;
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly inputSchema: unknown;
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly namespace: string;
|
|
36
|
+
readonly original: T;
|
|
37
|
+
readonly outputSchema: unknown;
|
|
38
|
+
readonly tags: readonly string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface FieldWeights {
|
|
42
|
+
aliases?: number;
|
|
43
|
+
description?: number;
|
|
44
|
+
name?: number;
|
|
45
|
+
namespace?: number;
|
|
46
|
+
schema?: number;
|
|
47
|
+
tags?: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ToolRouterOptions {
|
|
51
|
+
b?: number;
|
|
52
|
+
fieldWeights?: FieldWeights;
|
|
53
|
+
format?: ToolFormatInput;
|
|
54
|
+
fuzzy?: boolean;
|
|
55
|
+
k1?: number;
|
|
56
|
+
maxExpansions?: number;
|
|
57
|
+
maxQueryLength?: number;
|
|
58
|
+
maxSchemaDepth?: number;
|
|
59
|
+
maxSchemaNodes?: number;
|
|
60
|
+
maxTextLength?: number;
|
|
61
|
+
maxTools?: number;
|
|
62
|
+
minFuzzyLength?: number;
|
|
63
|
+
onDuplicate?: 'error' | 'replace';
|
|
64
|
+
synonyms?: false | {
|
|
65
|
+
[word: string]: string | readonly string[];
|
|
66
|
+
};
|
|
67
|
+
tokenizer?(input: string): string[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface ResolvedToolRouterOptions {
|
|
71
|
+
readonly b: number;
|
|
72
|
+
readonly fieldWeights: Readonly<Required<FieldWeights>>;
|
|
73
|
+
readonly format?: ToolFormatInput;
|
|
74
|
+
readonly fuzzy: boolean;
|
|
75
|
+
readonly k1: number;
|
|
76
|
+
readonly maxExpansions: number;
|
|
77
|
+
readonly maxQueryLength: number;
|
|
78
|
+
readonly maxSchemaDepth: number;
|
|
79
|
+
readonly maxSchemaNodes: number;
|
|
80
|
+
readonly maxTextLength: number;
|
|
81
|
+
readonly maxTools: number;
|
|
82
|
+
readonly minFuzzyLength: number;
|
|
83
|
+
readonly onDuplicate: 'error' | 'replace';
|
|
84
|
+
readonly synonyms: Readonly<Record<string, readonly string[]>>;
|
|
85
|
+
readonly tokenizer: (input: string) => string[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ToolSearchOptions<T = unknown> {
|
|
89
|
+
filter?(record: NormalizedTool<T>): boolean;
|
|
90
|
+
formats?: string | readonly string[];
|
|
91
|
+
ids?: string | readonly string[];
|
|
92
|
+
limit?: number;
|
|
93
|
+
maxEstimatedTokens?: number;
|
|
94
|
+
minScore?: number;
|
|
95
|
+
namespaces?: string | readonly string[];
|
|
96
|
+
tags?: string | readonly string[];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface ToolRouteOptions<T = unknown> extends ToolSearchOptions<T> {
|
|
100
|
+
fallback?: 'none' | 'first' | 'all';
|
|
101
|
+
maxTools?: number;
|
|
102
|
+
pinned?: string | readonly string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface ToolMatch<T = unknown> {
|
|
106
|
+
readonly estimatedTokens: number;
|
|
107
|
+
readonly id: string;
|
|
108
|
+
readonly matchedFields: readonly string[];
|
|
109
|
+
readonly matchedTerms: readonly string[];
|
|
110
|
+
readonly name: string;
|
|
111
|
+
readonly pinned: boolean;
|
|
112
|
+
readonly queryCoverage: number;
|
|
113
|
+
readonly record: NormalizedTool<T>;
|
|
114
|
+
readonly score: number | null;
|
|
115
|
+
readonly tool: T;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface ToolRouteResult<T = unknown> {
|
|
119
|
+
readonly budgetExceeded: boolean;
|
|
120
|
+
readonly catalogEstimatedTokens: number;
|
|
121
|
+
readonly catalogSize: number;
|
|
122
|
+
readonly estimatedTokens: number;
|
|
123
|
+
readonly matches: readonly ToolMatch<T>[];
|
|
124
|
+
readonly records: readonly NormalizedTool<T>[];
|
|
125
|
+
readonly selectedCount: number;
|
|
126
|
+
readonly tokenReduction: number;
|
|
127
|
+
readonly tools: readonly T[];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface ToolRouterStats {
|
|
131
|
+
readonly estimatedTokens: number;
|
|
132
|
+
readonly fields: Readonly<Record<string, number>>;
|
|
133
|
+
readonly terms: number;
|
|
134
|
+
readonly tools: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export type ToolCatalog<T> =
|
|
138
|
+
| readonly T[]
|
|
139
|
+
| { tools: readonly T[] }
|
|
140
|
+
| { functionDeclarations: readonly T[] };
|
|
141
|
+
|
|
142
|
+
export class ToolRouterError extends Error {
|
|
143
|
+
constructor(code: string, message: string, details?: unknown);
|
|
144
|
+
readonly code: string;
|
|
145
|
+
readonly details?: unknown;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export class ToolRouter<T = unknown> {
|
|
149
|
+
constructor(tools?: ToolCatalog<T>, options?: ToolRouterOptions);
|
|
150
|
+
readonly size: number;
|
|
151
|
+
readonly options: ResolvedToolRouterOptions;
|
|
152
|
+
add(tools: T | ToolCatalog<T>, options?: { format?: ToolFormatInput }): this;
|
|
153
|
+
remove(ids: string | readonly string[]): number;
|
|
154
|
+
replace(tools: ToolCatalog<T>, options?: { format?: ToolFormatInput }): this;
|
|
155
|
+
clear(): this;
|
|
156
|
+
has(idOrName: string): boolean;
|
|
157
|
+
get(idOrName: string): NormalizedTool<T> | undefined;
|
|
158
|
+
list(): NormalizedTool<T>[];
|
|
159
|
+
stats(): ToolRouterStats;
|
|
160
|
+
search(query: string, options?: ToolSearchOptions<T>): ToolMatch<T>[];
|
|
161
|
+
select(query: string, options?: ToolSearchOptions<T>): T[];
|
|
162
|
+
route(query: string, options?: ToolRouteOptions<T>): ToolRouteResult<T>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export type ToolSearchTarget = ToolFormat;
|
|
166
|
+
|
|
167
|
+
export interface ToolSearchInput {
|
|
168
|
+
query: string;
|
|
169
|
+
limit?: number;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface ToolSearchSummary {
|
|
173
|
+
readonly description: string;
|
|
174
|
+
readonly id: string;
|
|
175
|
+
readonly name: string;
|
|
176
|
+
readonly namespace?: string;
|
|
177
|
+
readonly score: number | null;
|
|
178
|
+
readonly tags: readonly string[];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface ToolSearchResult {
|
|
182
|
+
readonly catalogSize: number;
|
|
183
|
+
readonly query: string;
|
|
184
|
+
readonly tools: readonly ToolSearchSummary[];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface ToolSearchHelper {
|
|
188
|
+
readonly definition: unknown;
|
|
189
|
+
execute(input: ToolSearchInput): ToolSearchResult;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export const TOOL_FORMATS: readonly ToolFormat[];
|
|
193
|
+
|
|
194
|
+
export function createToolRouter<T = unknown>(
|
|
195
|
+
tools?: ToolCatalog<T>,
|
|
196
|
+
options?: ToolRouterOptions
|
|
197
|
+
): ToolRouter<T>;
|
|
198
|
+
|
|
199
|
+
export function routeTools<T = unknown>(
|
|
200
|
+
tools: ToolCatalog<T>,
|
|
201
|
+
query: string,
|
|
202
|
+
options?: ToolRouteOptions<T> & { router?: ToolRouterOptions }
|
|
203
|
+
): ToolRouteResult<T>;
|
|
204
|
+
|
|
205
|
+
export function createToolSearch<T = unknown>(
|
|
206
|
+
router: ToolRouter<T>,
|
|
207
|
+
options?: {
|
|
208
|
+
target?: ToolSearchTarget;
|
|
209
|
+
name?: string;
|
|
210
|
+
description?: string;
|
|
211
|
+
limit?: number;
|
|
212
|
+
}
|
|
213
|
+
): ToolSearchHelper;
|
|
214
|
+
|
|
215
|
+
export function defineTool<T>(tool: T): T;
|
|
216
|
+
export function detectToolFormat(tool: unknown): ToolFormat;
|
|
217
|
+
export function normalizeTool<T = unknown>(
|
|
218
|
+
tool: T,
|
|
219
|
+
options?: { format?: ToolFormatInput }
|
|
220
|
+
): NormalizedTool<T>;
|
|
221
|
+
export function normalizeTools<T = unknown>(
|
|
222
|
+
tools: ToolCatalog<T>,
|
|
223
|
+
options?: { format?: ToolFormatInput; maxTools?: number }
|
|
224
|
+
): NormalizedTool<T>[];
|
|
225
|
+
export function estimateToolTokens(tool: unknown): number;
|
|
226
|
+
export function normalizeIdentifier(input: unknown): string;
|
|
227
|
+
export function normalizeText(input: unknown): string;
|
|
228
|
+
export function tokenize(input: unknown, options?: { maxTokenLength?: number }): string[];
|
|
229
|
+
|
|
230
|
+
declare const api: {
|
|
231
|
+
TOOL_FORMATS: typeof TOOL_FORMATS;
|
|
232
|
+
ToolRouter: typeof ToolRouter;
|
|
233
|
+
ToolRouterError: typeof ToolRouterError;
|
|
234
|
+
createToolRouter: typeof createToolRouter;
|
|
235
|
+
createToolSearch: typeof createToolSearch;
|
|
236
|
+
defineTool: typeof defineTool;
|
|
237
|
+
detectToolFormat: typeof detectToolFormat;
|
|
238
|
+
estimateToolTokens: typeof estimateToolTokens;
|
|
239
|
+
normalizeIdentifier: typeof normalizeIdentifier;
|
|
240
|
+
normalizeText: typeof normalizeText;
|
|
241
|
+
normalizeTool: typeof normalizeTool;
|
|
242
|
+
normalizeTools: typeof normalizeTools;
|
|
243
|
+
routeTools: typeof routeTools;
|
|
244
|
+
tokenize: typeof tokenize;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
export default api;
|