@codebolt/codeboltjs 5.1.10 → 6.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.
Files changed (50) hide show
  1. package/dist/core/Codebolt.d.ts +1 -20
  2. package/dist/core/Codebolt.js +16 -18
  3. package/dist/core/websocket.js +1 -1
  4. package/dist/index.d.ts +0 -1
  5. package/dist/index.js +3 -6
  6. package/dist/modules/agentDeliberation.js +1 -3
  7. package/dist/modules/swarm.d.ts +8 -2
  8. package/dist/modules/swarm.js +14 -0
  9. package/dist/tools/index.d.ts +2 -16
  10. package/dist/tools/index.js +5 -45
  11. package/dist/tools/registry.d.ts +0 -21
  12. package/dist/tools/registry.js +1 -38
  13. package/dist/types/agentDeliberation.d.ts +1 -15
  14. package/dist/types/agentDeliberation.js +0 -2
  15. package/dist/types/job.d.ts +1 -1
  16. package/package.json +19 -20
  17. package/dist/modules/environment.d.ts +0 -24
  18. package/dist/modules/environment.js +0 -51
  19. package/dist/tools/environment/environment-create.d.ts +0 -23
  20. package/dist/tools/environment/environment-create.js +0 -90
  21. package/dist/tools/environment/environment-delete.d.ts +0 -17
  22. package/dist/tools/environment/environment-delete.js +0 -70
  23. package/dist/tools/environment/environment-get.d.ts +0 -17
  24. package/dist/tools/environment/environment-get.js +0 -73
  25. package/dist/tools/environment/environment-list.d.ts +0 -15
  26. package/dist/tools/environment/environment-list.js +0 -72
  27. package/dist/tools/environment/environment-providers.d.ts +0 -24
  28. package/dist/tools/environment/environment-providers.js +0 -130
  29. package/dist/tools/environment/environment-restart.d.ts +0 -17
  30. package/dist/tools/environment/environment-restart.js +0 -70
  31. package/dist/tools/environment/environment-send-message.d.ts +0 -19
  32. package/dist/tools/environment/environment-send-message.js +0 -74
  33. package/dist/tools/environment/environment-start.d.ts +0 -17
  34. package/dist/tools/environment/environment-start.js +0 -70
  35. package/dist/tools/environment/environment-statistics.d.ts +0 -15
  36. package/dist/tools/environment/environment-statistics.js +0 -69
  37. package/dist/tools/environment/environment-status.d.ts +0 -17
  38. package/dist/tools/environment/environment-status.js +0 -72
  39. package/dist/tools/environment/environment-stop.d.ts +0 -17
  40. package/dist/tools/environment/environment-stop.js +0 -70
  41. package/dist/tools/environment/environment-update.d.ts +0 -19
  42. package/dist/tools/environment/environment-update.js +0 -74
  43. package/dist/tools/environment/index.d.ts +0 -31
  44. package/dist/tools/environment/index.js +0 -61
  45. package/dist/tools/tool-search.d.ts +0 -49
  46. package/dist/tools/tool-search.js +0 -140
  47. package/dist/tools/toolSearch/index.d.ts +0 -9
  48. package/dist/tools/toolSearch/index.js +0 -15
  49. package/dist/tools/toolSearch/tool-search-tool.d.ts +0 -32
  50. package/dist/tools/toolSearch/tool-search-tool.js +0 -110
@@ -1,72 +0,0 @@
1
- "use strict";
2
- /**
3
- * Environment Status Tool - Gets the status of an environment
4
- * Wraps the SDK's cbenvironment.getEnvironmentStatus() method
5
- */
6
- var __importDefault = (this && this.__importDefault) || function (mod) {
7
- return (mod && mod.__esModule) ? mod : { "default": mod };
8
- };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.EnvironmentStatusTool = void 0;
11
- const types_1 = require("../types");
12
- const base_tool_1 = require("../base-tool");
13
- const environment_1 = __importDefault(require("../../modules/environment"));
14
- const chat_1 = __importDefault(require("../../modules/chat"));
15
- class EnvironmentStatusInvocation extends base_tool_1.BaseToolInvocation {
16
- constructor(params) {
17
- super(params);
18
- }
19
- async execute() {
20
- try {
21
- if (this.params.explanation) {
22
- chat_1.default.sendMessage(this.params.explanation);
23
- }
24
- const response = await environment_1.default.getEnvironmentStatus(this.params.environmentId);
25
- if (response && response.success === false) {
26
- const errorMsg = response.error || 'Failed to get environment status';
27
- return {
28
- llmContent: `Failed to get environment status: ${errorMsg}`,
29
- returnDisplay: `Error: ${errorMsg}`,
30
- error: { message: errorMsg, type: types_1.ToolErrorType.EXECUTION_FAILED },
31
- };
32
- }
33
- const data = response.data || {};
34
- const output = `Environment Status (${this.params.environmentId}):\n- State: ${data.state || 'unknown'}\n- Running: ${data.isRunning}\n- Healthy: ${data.isHealthy}\n- Restart Count: ${data.restartCount || 0}\n- Error Count: ${data.errorCount || 0}${data.lastError ? `\n- Last Error: ${data.lastError}` : ''}`;
35
- return {
36
- llmContent: output,
37
- returnDisplay: `Environment status: ${data.state || 'unknown'}`,
38
- };
39
- }
40
- catch (error) {
41
- const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
42
- return {
43
- llmContent: `Error getting environment status: ${errorMessage}`,
44
- returnDisplay: `Error: ${errorMessage}`,
45
- error: { message: errorMessage, type: types_1.ToolErrorType.EXECUTION_FAILED },
46
- };
47
- }
48
- }
49
- }
50
- class EnvironmentStatusTool extends base_tool_1.BaseDeclarativeTool {
51
- constructor() {
52
- super(EnvironmentStatusTool.Name, 'EnvironmentStatus', 'Gets the status of an environment including state, health, and error information.', types_1.Kind.Read, {
53
- properties: {
54
- explanation: {
55
- description: "One sentence explanation as to why this tool is being used, and how it contributes to the goal.",
56
- type: 'string',
57
- },
58
- environmentId: {
59
- description: 'The ID of the environment to check status for.',
60
- type: 'string',
61
- },
62
- },
63
- required: ['environmentId'],
64
- type: 'object',
65
- });
66
- }
67
- createInvocation(params) {
68
- return new EnvironmentStatusInvocation(params);
69
- }
70
- }
71
- exports.EnvironmentStatusTool = EnvironmentStatusTool;
72
- EnvironmentStatusTool.Name = 'environment_status';
@@ -1,17 +0,0 @@
1
- /**
2
- * Environment Stop Tool - Stops an environment provider
3
- * Wraps the SDK's cbenvironment.stopEnvironment() method
4
- */
5
- import type { ToolInvocation, ToolResult } from '../types';
6
- import { BaseDeclarativeTool } from '../base-tool';
7
- export interface EnvironmentStopParams {
8
- /** One sentence explanation of why this tool is being used */
9
- explanation?: string;
10
- /** The ID of the environment to stop */
11
- environmentId: string;
12
- }
13
- export declare class EnvironmentStopTool extends BaseDeclarativeTool<EnvironmentStopParams, ToolResult> {
14
- static readonly Name: string;
15
- constructor();
16
- protected createInvocation(params: EnvironmentStopParams): ToolInvocation<EnvironmentStopParams, ToolResult>;
17
- }
@@ -1,70 +0,0 @@
1
- "use strict";
2
- /**
3
- * Environment Stop Tool - Stops an environment provider
4
- * Wraps the SDK's cbenvironment.stopEnvironment() method
5
- */
6
- var __importDefault = (this && this.__importDefault) || function (mod) {
7
- return (mod && mod.__esModule) ? mod : { "default": mod };
8
- };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.EnvironmentStopTool = void 0;
11
- const types_1 = require("../types");
12
- const base_tool_1 = require("../base-tool");
13
- const environment_1 = __importDefault(require("../../modules/environment"));
14
- const chat_1 = __importDefault(require("../../modules/chat"));
15
- class EnvironmentStopInvocation extends base_tool_1.BaseToolInvocation {
16
- constructor(params) {
17
- super(params);
18
- }
19
- async execute() {
20
- try {
21
- if (this.params.explanation) {
22
- chat_1.default.sendMessage(this.params.explanation);
23
- }
24
- const response = await environment_1.default.stopEnvironment(this.params.environmentId);
25
- if (response && response.success === false) {
26
- const errorMsg = response.error || 'Failed to stop environment';
27
- return {
28
- llmContent: `Failed to stop environment: ${errorMsg}`,
29
- returnDisplay: `Error: ${errorMsg}`,
30
- error: { message: errorMsg, type: types_1.ToolErrorType.EXECUTION_FAILED },
31
- };
32
- }
33
- return {
34
- llmContent: `Environment ${this.params.environmentId} stopped successfully.`,
35
- returnDisplay: `Stopped environment: ${this.params.environmentId}`,
36
- };
37
- }
38
- catch (error) {
39
- const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
40
- return {
41
- llmContent: `Error stopping environment: ${errorMessage}`,
42
- returnDisplay: `Error: ${errorMessage}`,
43
- error: { message: errorMessage, type: types_1.ToolErrorType.EXECUTION_FAILED },
44
- };
45
- }
46
- }
47
- }
48
- class EnvironmentStopTool extends base_tool_1.BaseDeclarativeTool {
49
- constructor() {
50
- super(EnvironmentStopTool.Name, 'EnvironmentStop', 'Stops an environment by ID.', types_1.Kind.Execute, {
51
- properties: {
52
- explanation: {
53
- description: "One sentence explanation as to why this tool is being used, and how it contributes to the goal.",
54
- type: 'string',
55
- },
56
- environmentId: {
57
- description: 'The ID of the environment to stop.',
58
- type: 'string',
59
- },
60
- },
61
- required: ['environmentId'],
62
- type: 'object',
63
- });
64
- }
65
- createInvocation(params) {
66
- return new EnvironmentStopInvocation(params);
67
- }
68
- }
69
- exports.EnvironmentStopTool = EnvironmentStopTool;
70
- EnvironmentStopTool.Name = 'environment_stop';
@@ -1,19 +0,0 @@
1
- /**
2
- * Environment Update Tool - Updates an existing environment
3
- * Wraps the SDK's cbenvironment.updateEnvironment() method
4
- */
5
- import type { ToolInvocation, ToolResult } from '../types';
6
- import { BaseDeclarativeTool } from '../base-tool';
7
- export interface EnvironmentUpdateParams {
8
- /** One sentence explanation of why this tool is being used */
9
- explanation?: string;
10
- /** The ID of the environment to update */
11
- environmentId: string;
12
- /** The data to update */
13
- updateData: any;
14
- }
15
- export declare class EnvironmentUpdateTool extends BaseDeclarativeTool<EnvironmentUpdateParams, ToolResult> {
16
- static readonly Name: string;
17
- constructor();
18
- protected createInvocation(params: EnvironmentUpdateParams): ToolInvocation<EnvironmentUpdateParams, ToolResult>;
19
- }
@@ -1,74 +0,0 @@
1
- "use strict";
2
- /**
3
- * Environment Update Tool - Updates an existing environment
4
- * Wraps the SDK's cbenvironment.updateEnvironment() method
5
- */
6
- var __importDefault = (this && this.__importDefault) || function (mod) {
7
- return (mod && mod.__esModule) ? mod : { "default": mod };
8
- };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.EnvironmentUpdateTool = void 0;
11
- const types_1 = require("../types");
12
- const base_tool_1 = require("../base-tool");
13
- const environment_1 = __importDefault(require("../../modules/environment"));
14
- const chat_1 = __importDefault(require("../../modules/chat"));
15
- class EnvironmentUpdateInvocation extends base_tool_1.BaseToolInvocation {
16
- constructor(params) {
17
- super(params);
18
- }
19
- async execute() {
20
- try {
21
- if (this.params.explanation) {
22
- chat_1.default.sendMessage(this.params.explanation);
23
- }
24
- const response = await environment_1.default.updateEnvironment(this.params.environmentId, this.params.updateData);
25
- if (response && response.success === false) {
26
- const errorMsg = response.error || 'Failed to update environment';
27
- return {
28
- llmContent: `Failed to update environment: ${errorMsg}`,
29
- returnDisplay: `Error: ${errorMsg}`,
30
- error: { message: errorMsg, type: types_1.ToolErrorType.EXECUTION_FAILED },
31
- };
32
- }
33
- return {
34
- llmContent: `Environment ${this.params.environmentId} updated successfully.`,
35
- returnDisplay: `Updated environment: ${this.params.environmentId}`,
36
- };
37
- }
38
- catch (error) {
39
- const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
40
- return {
41
- llmContent: `Error updating environment: ${errorMessage}`,
42
- returnDisplay: `Error: ${errorMessage}`,
43
- error: { message: errorMessage, type: types_1.ToolErrorType.EXECUTION_FAILED },
44
- };
45
- }
46
- }
47
- }
48
- class EnvironmentUpdateTool extends base_tool_1.BaseDeclarativeTool {
49
- constructor() {
50
- super(EnvironmentUpdateTool.Name, 'EnvironmentUpdate', 'Updates an existing environment by ID.', types_1.Kind.Edit, {
51
- properties: {
52
- explanation: {
53
- description: "One sentence explanation as to why this tool is being used, and how it contributes to the goal.",
54
- type: 'string',
55
- },
56
- environmentId: {
57
- description: 'The ID of the environment to update.',
58
- type: 'string',
59
- },
60
- updateData: {
61
- description: 'The data to update on the environment.',
62
- type: 'object',
63
- },
64
- },
65
- required: ['environmentId', 'updateData'],
66
- type: 'object',
67
- });
68
- }
69
- createInvocation(params) {
70
- return new EnvironmentUpdateInvocation(params);
71
- }
72
- }
73
- exports.EnvironmentUpdateTool = EnvironmentUpdateTool;
74
- EnvironmentUpdateTool.Name = 'environment_update';
@@ -1,31 +0,0 @@
1
- /**
2
- * Environment tools - Tools for environment management
3
- */
4
- export { EnvironmentListTool, type EnvironmentListParams } from './environment-list';
5
- export { EnvironmentGetTool, type EnvironmentGetParams } from './environment-get';
6
- export { EnvironmentCreateTool, type EnvironmentCreateParams } from './environment-create';
7
- export { EnvironmentUpdateTool, type EnvironmentUpdateParams } from './environment-update';
8
- export { EnvironmentDeleteTool, type EnvironmentDeleteParams } from './environment-delete';
9
- export { EnvironmentStartTool, type EnvironmentStartParams } from './environment-start';
10
- export { EnvironmentStopTool, type EnvironmentStopParams } from './environment-stop';
11
- export { EnvironmentRestartTool, type EnvironmentRestartParams } from './environment-restart';
12
- export { EnvironmentStatusTool, type EnvironmentStatusParams } from './environment-status';
13
- export { EnvironmentGetLocalProvidersTool, EnvironmentGetRunningProvidersTool, type EnvironmentGetLocalProvidersParams, type EnvironmentGetRunningProvidersParams } from './environment-providers';
14
- export { EnvironmentStatisticsTool, type EnvironmentStatisticsParams } from './environment-statistics';
15
- export { EnvironmentSendMessageTool, type EnvironmentSendMessageParams } from './environment-send-message';
16
- import { EnvironmentListTool } from './environment-list';
17
- import { EnvironmentGetTool } from './environment-get';
18
- import { EnvironmentCreateTool } from './environment-create';
19
- import { EnvironmentUpdateTool } from './environment-update';
20
- import { EnvironmentDeleteTool } from './environment-delete';
21
- import { EnvironmentStartTool } from './environment-start';
22
- import { EnvironmentStopTool } from './environment-stop';
23
- import { EnvironmentRestartTool } from './environment-restart';
24
- import { EnvironmentStatusTool } from './environment-status';
25
- import { EnvironmentGetLocalProvidersTool, EnvironmentGetRunningProvidersTool } from './environment-providers';
26
- import { EnvironmentStatisticsTool } from './environment-statistics';
27
- import { EnvironmentSendMessageTool } from './environment-send-message';
28
- /**
29
- * All environment tools
30
- */
31
- export declare const environmentTools: (EnvironmentListTool | EnvironmentGetTool | EnvironmentCreateTool | EnvironmentUpdateTool | EnvironmentDeleteTool | EnvironmentStartTool | EnvironmentStopTool | EnvironmentRestartTool | EnvironmentStatusTool | EnvironmentGetLocalProvidersTool | EnvironmentGetRunningProvidersTool | EnvironmentStatisticsTool | EnvironmentSendMessageTool)[];
@@ -1,61 +0,0 @@
1
- "use strict";
2
- /**
3
- * Environment tools - Tools for environment management
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.environmentTools = exports.EnvironmentSendMessageTool = exports.EnvironmentStatisticsTool = exports.EnvironmentGetRunningProvidersTool = exports.EnvironmentGetLocalProvidersTool = exports.EnvironmentStatusTool = exports.EnvironmentRestartTool = exports.EnvironmentStopTool = exports.EnvironmentStartTool = exports.EnvironmentDeleteTool = exports.EnvironmentUpdateTool = exports.EnvironmentCreateTool = exports.EnvironmentGetTool = exports.EnvironmentListTool = void 0;
7
- var environment_list_1 = require("./environment-list");
8
- Object.defineProperty(exports, "EnvironmentListTool", { enumerable: true, get: function () { return environment_list_1.EnvironmentListTool; } });
9
- var environment_get_1 = require("./environment-get");
10
- Object.defineProperty(exports, "EnvironmentGetTool", { enumerable: true, get: function () { return environment_get_1.EnvironmentGetTool; } });
11
- var environment_create_1 = require("./environment-create");
12
- Object.defineProperty(exports, "EnvironmentCreateTool", { enumerable: true, get: function () { return environment_create_1.EnvironmentCreateTool; } });
13
- var environment_update_1 = require("./environment-update");
14
- Object.defineProperty(exports, "EnvironmentUpdateTool", { enumerable: true, get: function () { return environment_update_1.EnvironmentUpdateTool; } });
15
- var environment_delete_1 = require("./environment-delete");
16
- Object.defineProperty(exports, "EnvironmentDeleteTool", { enumerable: true, get: function () { return environment_delete_1.EnvironmentDeleteTool; } });
17
- var environment_start_1 = require("./environment-start");
18
- Object.defineProperty(exports, "EnvironmentStartTool", { enumerable: true, get: function () { return environment_start_1.EnvironmentStartTool; } });
19
- var environment_stop_1 = require("./environment-stop");
20
- Object.defineProperty(exports, "EnvironmentStopTool", { enumerable: true, get: function () { return environment_stop_1.EnvironmentStopTool; } });
21
- var environment_restart_1 = require("./environment-restart");
22
- Object.defineProperty(exports, "EnvironmentRestartTool", { enumerable: true, get: function () { return environment_restart_1.EnvironmentRestartTool; } });
23
- var environment_status_1 = require("./environment-status");
24
- Object.defineProperty(exports, "EnvironmentStatusTool", { enumerable: true, get: function () { return environment_status_1.EnvironmentStatusTool; } });
25
- var environment_providers_1 = require("./environment-providers");
26
- Object.defineProperty(exports, "EnvironmentGetLocalProvidersTool", { enumerable: true, get: function () { return environment_providers_1.EnvironmentGetLocalProvidersTool; } });
27
- Object.defineProperty(exports, "EnvironmentGetRunningProvidersTool", { enumerable: true, get: function () { return environment_providers_1.EnvironmentGetRunningProvidersTool; } });
28
- var environment_statistics_1 = require("./environment-statistics");
29
- Object.defineProperty(exports, "EnvironmentStatisticsTool", { enumerable: true, get: function () { return environment_statistics_1.EnvironmentStatisticsTool; } });
30
- var environment_send_message_1 = require("./environment-send-message");
31
- Object.defineProperty(exports, "EnvironmentSendMessageTool", { enumerable: true, get: function () { return environment_send_message_1.EnvironmentSendMessageTool; } });
32
- const environment_list_2 = require("./environment-list");
33
- const environment_get_2 = require("./environment-get");
34
- const environment_create_2 = require("./environment-create");
35
- const environment_update_2 = require("./environment-update");
36
- const environment_delete_2 = require("./environment-delete");
37
- const environment_start_2 = require("./environment-start");
38
- const environment_stop_2 = require("./environment-stop");
39
- const environment_restart_2 = require("./environment-restart");
40
- const environment_status_2 = require("./environment-status");
41
- const environment_providers_2 = require("./environment-providers");
42
- const environment_statistics_2 = require("./environment-statistics");
43
- const environment_send_message_2 = require("./environment-send-message");
44
- /**
45
- * All environment tools
46
- */
47
- exports.environmentTools = [
48
- new environment_list_2.EnvironmentListTool(),
49
- new environment_get_2.EnvironmentGetTool(),
50
- new environment_create_2.EnvironmentCreateTool(),
51
- new environment_update_2.EnvironmentUpdateTool(),
52
- new environment_delete_2.EnvironmentDeleteTool(),
53
- new environment_start_2.EnvironmentStartTool(),
54
- new environment_stop_2.EnvironmentStopTool(),
55
- new environment_restart_2.EnvironmentRestartTool(),
56
- new environment_status_2.EnvironmentStatusTool(),
57
- new environment_providers_2.EnvironmentGetLocalProvidersTool(),
58
- new environment_providers_2.EnvironmentGetRunningProvidersTool(),
59
- new environment_statistics_2.EnvironmentStatisticsTool(),
60
- new environment_send_message_2.EnvironmentSendMessageTool(),
61
- ];
@@ -1,49 +0,0 @@
1
- /**
2
- * Tool Search Engine - Full-text search over registered tools using MiniSearch
3
- */
4
- import type { AnyDeclarativeTool } from './types';
5
- export interface ToolSearchResult {
6
- /** Tool name (internal identifier) */
7
- name: string;
8
- /** User-friendly display name */
9
- displayName: string;
10
- /** Tool description */
11
- description: string;
12
- /** Tool kind/category */
13
- kind: string;
14
- /** Search relevance score */
15
- score: number;
16
- }
17
- export interface ToolSearchOptions {
18
- /** Maximum number of results to return (default: 10) */
19
- limit?: number;
20
- /** Enable fuzzy matching (default: 0.2) */
21
- fuzzy?: number | boolean;
22
- /** Enable prefix matching (default: true) */
23
- prefix?: boolean;
24
- /** Filter by tool kind */
25
- kind?: string;
26
- /** Field-specific boost weights */
27
- boost?: Record<string, number>;
28
- }
29
- export declare class ToolSearchEngine {
30
- private miniSearch;
31
- private indexed;
32
- constructor();
33
- /**
34
- * Build the search index from a map of tools
35
- */
36
- buildIndex(tools: Map<string, AnyDeclarativeTool>): void;
37
- /**
38
- * Search for tools matching a query
39
- */
40
- search(query: string, options?: ToolSearchOptions): ToolSearchResult[];
41
- /**
42
- * Get auto-complete suggestions for a partial query
43
- */
44
- suggest(query: string, options?: ToolSearchOptions): ToolSearchResult[];
45
- /**
46
- * Get the number of indexed tools
47
- */
48
- get size(): number;
49
- }
@@ -1,140 +0,0 @@
1
- "use strict";
2
- /**
3
- * Tool Search Engine - Full-text search over registered tools using MiniSearch
4
- */
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.ToolSearchEngine = void 0;
10
- const minisearch_1 = __importDefault(require("minisearch"));
11
- class ToolSearchEngine {
12
- constructor() {
13
- this.indexed = false;
14
- this.miniSearch = new minisearch_1.default({
15
- fields: ['name', 'displayName', 'description', 'kind', 'parameterNames'],
16
- storeFields: ['name', 'displayName', 'description', 'kind'],
17
- searchOptions: {
18
- boost: { displayName: 3, description: 2, name: 1.5, kind: 1, parameterNames: 0.5 },
19
- fuzzy: 0.2,
20
- prefix: true,
21
- },
22
- tokenize: (text) => {
23
- // Split on spaces, underscores, hyphens, and camelCase boundaries
24
- return text
25
- .replace(/([a-z])([A-Z])/g, '$1 $2')
26
- .replace(/[_\-]/g, ' ')
27
- .toLowerCase()
28
- .split(/\s+/)
29
- .filter(t => t.length > 0);
30
- },
31
- });
32
- }
33
- /**
34
- * Build the search index from a map of tools
35
- */
36
- buildIndex(tools) {
37
- var _a, _b;
38
- // Clear existing index
39
- if (this.indexed) {
40
- this.miniSearch.removeAll();
41
- }
42
- const documents = [];
43
- for (const [name, tool] of tools) {
44
- const params = (_b = (_a = tool.schema) === null || _a === void 0 ? void 0 : _a.function) === null || _b === void 0 ? void 0 : _b.parameters;
45
- const paramNames = (params === null || params === void 0 ? void 0 : params.properties)
46
- ? Object.keys(params.properties).filter(p => p !== 'explanation').join(' ')
47
- : '';
48
- documents.push({
49
- id: name,
50
- name: tool.name,
51
- displayName: tool.displayName,
52
- description: tool.description,
53
- kind: tool.kind,
54
- parameterNames: paramNames,
55
- });
56
- }
57
- this.miniSearch.addAll(documents);
58
- this.indexed = true;
59
- }
60
- /**
61
- * Search for tools matching a query
62
- */
63
- search(query, options) {
64
- var _a;
65
- if (!this.indexed) {
66
- return [];
67
- }
68
- const limit = (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : 10;
69
- const searchOpts = {};
70
- if ((options === null || options === void 0 ? void 0 : options.fuzzy) !== undefined) {
71
- searchOpts.fuzzy = options.fuzzy;
72
- }
73
- if ((options === null || options === void 0 ? void 0 : options.prefix) !== undefined) {
74
- searchOpts.prefix = options.prefix;
75
- }
76
- if (options === null || options === void 0 ? void 0 : options.boost) {
77
- searchOpts.boost = options.boost;
78
- }
79
- if (options === null || options === void 0 ? void 0 : options.kind) {
80
- const kindFilter = options.kind;
81
- searchOpts.filter = (result) => result.kind === kindFilter;
82
- }
83
- const results = this.miniSearch.search(query, searchOpts);
84
- return results.slice(0, limit).map(r => ({
85
- name: r.name,
86
- displayName: r.displayName,
87
- description: r.description,
88
- kind: r.kind,
89
- score: r.score,
90
- }));
91
- }
92
- /**
93
- * Get auto-complete suggestions for a partial query
94
- */
95
- suggest(query, options) {
96
- var _a;
97
- if (!this.indexed) {
98
- return [];
99
- }
100
- const limit = (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : 5;
101
- const suggestOpts = {};
102
- if ((options === null || options === void 0 ? void 0 : options.fuzzy) !== undefined) {
103
- suggestOpts.fuzzy = options.fuzzy;
104
- }
105
- if (options === null || options === void 0 ? void 0 : options.kind) {
106
- const kindFilter = options.kind;
107
- suggestOpts.filter = (result) => result.kind === kindFilter;
108
- }
109
- const suggestions = this.miniSearch.autoSuggest(query, suggestOpts);
110
- // autoSuggest returns grouped suggestions; map them to tool results
111
- const toolNames = new Set();
112
- const results = [];
113
- for (const suggestion of suggestions) {
114
- // Search for this suggestion to get actual tool matches
115
- const searchResults = this.miniSearch.search(suggestion.suggestion, { prefix: true });
116
- for (const r of searchResults) {
117
- if (!toolNames.has(r.name) && results.length < limit) {
118
- toolNames.add(r.name);
119
- results.push({
120
- name: r.name,
121
- displayName: r.displayName,
122
- description: r.description,
123
- kind: r.kind,
124
- score: r.score * suggestion.score,
125
- });
126
- }
127
- }
128
- if (results.length >= limit)
129
- break;
130
- }
131
- return results;
132
- }
133
- /**
134
- * Get the number of indexed tools
135
- */
136
- get size() {
137
- return this.miniSearch.documentCount;
138
- }
139
- }
140
- exports.ToolSearchEngine = ToolSearchEngine;
@@ -1,9 +0,0 @@
1
- /**
2
- * Tool Search Tool - Searches for available tools using full-text search (MiniSearch)
3
- */
4
- export { ToolSearchTool, type ToolSearchToolParams } from './tool-search-tool';
5
- import { ToolSearchTool } from './tool-search-tool';
6
- /**
7
- * All tool search tools
8
- */
9
- export declare const toolSearchTools: ToolSearchTool[];
@@ -1,15 +0,0 @@
1
- "use strict";
2
- /**
3
- * Tool Search Tool - Searches for available tools using full-text search (MiniSearch)
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.toolSearchTools = exports.ToolSearchTool = void 0;
7
- var tool_search_tool_1 = require("./tool-search-tool");
8
- Object.defineProperty(exports, "ToolSearchTool", { enumerable: true, get: function () { return tool_search_tool_1.ToolSearchTool; } });
9
- const tool_search_tool_2 = require("./tool-search-tool");
10
- /**
11
- * All tool search tools
12
- */
13
- exports.toolSearchTools = [
14
- new tool_search_tool_2.ToolSearchTool(),
15
- ];
@@ -1,32 +0,0 @@
1
- /**
2
- * Tool Search Tool - An LLM-callable tool that searches for available tools
3
- * Uses MiniSearch for full-text fuzzy search over all registered tools
4
- */
5
- import type { ToolInvocation, ToolResult } from '../types';
6
- import { BaseDeclarativeTool } from '../base-tool';
7
- import type { AnyDeclarativeTool } from '../types';
8
- export interface ToolSearchToolParams {
9
- /** One sentence explanation of why this tool is being used */
10
- explanation?: string;
11
- /** The search query to find relevant tools (e.g. "create environment", "read file", "git commit") */
12
- query: string;
13
- /** Maximum number of results to return (default: 10) */
14
- limit?: number;
15
- /** Filter results by tool kind (e.g. "read", "edit", "execute", "delete") */
16
- kind?: string;
17
- }
18
- export declare class ToolSearchTool extends BaseDeclarativeTool<ToolSearchToolParams, ToolResult> {
19
- static readonly Name: string;
20
- constructor();
21
- /**
22
- * Initialize the search index with a set of tools.
23
- * Call this before using the tool so the search engine knows what tools are available.
24
- * @param tools - Array of tools to index
25
- */
26
- static setTools(tools: AnyDeclarativeTool[]): void;
27
- /**
28
- * Get the currently indexed tools
29
- */
30
- static getIndexedTools(): AnyDeclarativeTool[];
31
- protected createInvocation(params: ToolSearchToolParams): ToolInvocation<ToolSearchToolParams, ToolResult>;
32
- }