@mxf-dev/core 1.0.1 → 2.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/README.md +18 -0
- package/dist/adapters/FrameworkAdapter.js +1 -1
- package/dist/adapters/FrameworkAdapter.js.map +1 -1
- package/dist/config/ConfigManager.d.ts +9 -8
- package/dist/config/ConfigManager.d.ts.map +1 -1
- package/dist/config/ConfigManager.js +47 -17
- package/dist/config/ConfigManager.js.map +1 -1
- package/dist/config/memory-strata.config.d.ts +25 -0
- package/dist/config/memory-strata.config.d.ts.map +1 -0
- package/dist/config/memory-strata.config.js +107 -0
- package/dist/config/memory-strata.config.js.map +1 -0
- package/dist/constants/ToolNames.d.ts +1 -29
- package/dist/constants/ToolNames.d.ts.map +1 -1
- package/dist/constants/ToolNames.js +4 -17
- package/dist/constants/ToolNames.js.map +1 -1
- package/dist/database/DatabaseAdapterFactory.d.ts +14 -2
- package/dist/database/DatabaseAdapterFactory.d.ts.map +1 -1
- package/dist/database/DatabaseAdapterFactory.js +21 -6
- package/dist/database/DatabaseAdapterFactory.js.map +1 -1
- package/dist/database/adapters/mongodb/MongoBaseRepository.d.ts +7 -1
- package/dist/database/adapters/mongodb/MongoBaseRepository.d.ts.map +1 -1
- package/dist/database/adapters/mongodb/MongoBaseRepository.js +12 -2
- package/dist/database/adapters/mongodb/MongoBaseRepository.js.map +1 -1
- package/dist/events/ClientEventBus.d.ts +16 -77
- package/dist/events/ClientEventBus.d.ts.map +1 -1
- package/dist/events/ClientEventBus.js +38 -311
- package/dist/events/ClientEventBus.js.map +1 -1
- package/dist/events/EventBus.d.ts +1 -1
- package/dist/events/EventBus.d.ts.map +1 -1
- package/dist/events/EventBus.js +5 -4
- package/dist/events/EventBus.js.map +1 -1
- package/dist/events/EventBusBase.d.ts +139 -34
- package/dist/events/EventBusBase.d.ts.map +1 -1
- package/dist/events/EventBusBase.js +366 -88
- package/dist/events/EventBusBase.js.map +1 -1
- package/dist/events/EventNames.d.ts +10 -1
- package/dist/events/EventNames.d.ts.map +1 -1
- package/dist/events/EventNames.js +3 -0
- package/dist/events/EventNames.js.map +1 -1
- package/dist/events/PublicEvents.d.ts +6 -2
- package/dist/events/PublicEvents.d.ts.map +1 -1
- package/dist/events/PublicEvents.js +7 -4
- package/dist/events/PublicEvents.js.map +1 -1
- package/dist/events/ServerEventBus.d.ts +23 -112
- package/dist/events/ServerEventBus.d.ts.map +1 -1
- package/dist/events/ServerEventBus.js +58 -323
- package/dist/events/ServerEventBus.js.map +1 -1
- package/dist/events/event-definitions/LlmBudgetEvents.d.ts +68 -0
- package/dist/events/event-definitions/LlmBudgetEvents.d.ts.map +1 -0
- package/dist/events/event-definitions/LlmBudgetEvents.js +35 -0
- package/dist/events/event-definitions/LlmBudgetEvents.js.map +1 -0
- package/dist/interfaces/IMemoryPersistence.d.ts +41 -0
- package/dist/interfaces/IMemoryPersistence.d.ts.map +1 -0
- package/dist/interfaces/IMemoryPersistence.js +15 -0
- package/dist/interfaces/IMemoryPersistence.js.map +1 -0
- package/dist/middleware/MxpMiddleware.d.ts +8 -1
- package/dist/middleware/MxpMiddleware.d.ts.map +1 -1
- package/dist/middleware/MxpMiddleware.js +42 -20
- package/dist/middleware/MxpMiddleware.js.map +1 -1
- package/dist/models/channelKey.d.ts +1 -0
- package/dist/models/channelKey.d.ts.map +1 -1
- package/dist/models/channelKey.js +5 -0
- package/dist/models/channelKey.js.map +1 -1
- package/dist/models/memoryUtility.d.ts +39 -0
- package/dist/models/memoryUtility.d.ts.map +1 -0
- package/dist/models/memoryUtility.js +39 -0
- package/dist/models/memoryUtility.js.map +1 -0
- package/dist/models/user.d.ts.map +1 -1
- package/dist/models/user.js +23 -1
- package/dist/models/user.js.map +1 -1
- package/dist/mxp/BinaryProtocolLayer.d.ts +24 -8
- package/dist/mxp/BinaryProtocolLayer.d.ts.map +1 -1
- package/dist/mxp/BinaryProtocolLayer.js +90 -103
- package/dist/mxp/BinaryProtocolLayer.js.map +1 -1
- package/dist/mxp/ContextCompressionEngine.d.ts +57 -10
- package/dist/mxp/ContextCompressionEngine.d.ts.map +1 -1
- package/dist/mxp/ContextCompressionEngine.js +170 -128
- package/dist/mxp/ContextCompressionEngine.js.map +1 -1
- package/dist/mxp/MxpTokenOptimizer.d.ts +7 -3
- package/dist/mxp/MxpTokenOptimizer.d.ts.map +1 -1
- package/dist/mxp/MxpTokenOptimizer.js +8 -5
- package/dist/mxp/MxpTokenOptimizer.js.map +1 -1
- package/dist/prompts/MxfAgentSystemPrompt.d.ts +1 -1
- package/dist/prompts/MxfAgentSystemPrompt.d.ts.map +1 -1
- package/dist/prompts/MxfAgentSystemPrompt.js +47 -57
- package/dist/prompts/MxfAgentSystemPrompt.js.map +1 -1
- package/dist/protocols/mcp/ToolError.d.ts +123 -0
- package/dist/protocols/mcp/ToolError.d.ts.map +1 -0
- package/dist/protocols/mcp/ToolError.js +108 -0
- package/dist/protocols/mcp/ToolError.js.map +1 -0
- package/dist/protocols/mcp/defineTool.d.ts +133 -0
- package/dist/protocols/mcp/defineTool.d.ts.map +1 -0
- package/dist/protocols/mcp/defineTool.js +236 -0
- package/dist/protocols/mcp/defineTool.js.map +1 -0
- package/dist/protocols/mcp/security/HttpTargetGuard.d.ts +38 -0
- package/dist/protocols/mcp/security/HttpTargetGuard.d.ts.map +1 -0
- package/dist/protocols/mcp/security/HttpTargetGuard.js +227 -0
- package/dist/protocols/mcp/security/HttpTargetGuard.js.map +1 -0
- package/dist/protocols/mcp/security/McpSecurityGuard.d.ts +9 -1
- package/dist/protocols/mcp/security/McpSecurityGuard.d.ts.map +1 -1
- package/dist/protocols/mcp/security/McpSecurityGuard.js +10 -2
- package/dist/protocols/mcp/security/McpSecurityGuard.js.map +1 -1
- package/dist/protocols/mcp/security/McpToolPolicy.d.ts +81 -0
- package/dist/protocols/mcp/security/McpToolPolicy.d.ts.map +1 -0
- package/dist/protocols/mcp/security/McpToolPolicy.js +202 -0
- package/dist/protocols/mcp/security/McpToolPolicy.js.map +1 -0
- package/dist/protocols/mcp/services/ExternalMcpServerManager.d.ts +51 -18
- package/dist/protocols/mcp/services/ExternalMcpServerManager.d.ts.map +1 -1
- package/dist/protocols/mcp/services/ExternalMcpServerManager.js +256 -283
- package/dist/protocols/mcp/services/ExternalMcpServerManager.js.map +1 -1
- package/dist/protocols/mcp/services/ExternalServerConfigs.d.ts +39 -6
- package/dist/protocols/mcp/services/ExternalServerConfigs.d.ts.map +1 -1
- package/dist/protocols/mcp/services/ExternalServerConfigs.js +76 -18
- package/dist/protocols/mcp/services/ExternalServerConfigs.js.map +1 -1
- package/dist/protocols/mcp/tools/AnalyticsTools.js +1 -1
- package/dist/protocols/mcp/tools/AnalyticsTools.js.map +1 -1
- package/dist/protocols/mcp/tools/CodeAnalysisTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/CodeAnalysisTools.js +15 -0
- package/dist/protocols/mcp/tools/CodeAnalysisTools.js.map +1 -1
- package/dist/protocols/mcp/tools/EffectivenessTools.js +3 -3
- package/dist/protocols/mcp/tools/EffectivenessTools.js.map +1 -1
- package/dist/protocols/mcp/tools/GitTools.d.ts +9 -369
- package/dist/protocols/mcp/tools/GitTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/GitTools.js +222 -517
- package/dist/protocols/mcp/tools/GitTools.js.map +1 -1
- package/dist/protocols/mcp/tools/InfrastructureTools.d.ts +56 -24
- package/dist/protocols/mcp/tools/InfrastructureTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/InfrastructureTools.js +117 -26
- package/dist/protocols/mcp/tools/InfrastructureTools.js.map +1 -1
- package/dist/protocols/mcp/tools/MemorySearchTools.d.ts +0 -3
- package/dist/protocols/mcp/tools/MemorySearchTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/MemorySearchTools.js +58 -1
- package/dist/protocols/mcp/tools/MemorySearchTools.js.map +1 -1
- package/dist/protocols/mcp/tools/OrparTools.d.ts +8 -0
- package/dist/protocols/mcp/tools/OrparTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/OrparTools.js +66 -0
- package/dist/protocols/mcp/tools/OrparTools.js.map +1 -1
- package/dist/protocols/mcp/tools/SafetyTools.d.ts +7 -525
- package/dist/protocols/mcp/tools/SafetyTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/SafetyTools.js +349 -514
- package/dist/protocols/mcp/tools/SafetyTools.js.map +1 -1
- package/dist/protocols/mcp/tools/TaskPlanningTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/TaskPlanningTools.js +56 -26
- package/dist/protocols/mcp/tools/TaskPlanningTools.js.map +1 -1
- package/dist/protocols/mcp/tools/TestTools.d.ts +15 -376
- package/dist/protocols/mcp/tools/TestTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/TestTools.js +241 -363
- package/dist/protocols/mcp/tools/TestTools.js.map +1 -1
- package/dist/protocols/mcp/tools/TypeScriptTools.d.ts +6 -276
- package/dist/protocols/mcp/tools/TypeScriptTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/TypeScriptTools.js +223 -337
- package/dist/protocols/mcp/tools/TypeScriptTools.js.map +1 -1
- package/dist/protocols/mcp/tools/WebTools.d.ts +15 -728
- package/dist/protocols/mcp/tools/WebTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/WebTools.js +151 -257
- package/dist/protocols/mcp/tools/WebTools.js.map +1 -1
- package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.d.ts +5 -3
- package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.js +31 -6
- package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.js.map +1 -1
- package/dist/schemas/EventPayloadSchema.d.ts +21 -0
- package/dist/schemas/EventPayloadSchema.d.ts.map +1 -1
- package/dist/schemas/EventPayloadSchema.js +14 -0
- package/dist/schemas/EventPayloadSchema.js.map +1 -1
- package/dist/services/BackgroundTaskManager.d.ts.map +1 -1
- package/dist/services/BackgroundTaskManager.js +12 -4
- package/dist/services/BackgroundTaskManager.js.map +1 -1
- package/dist/services/BrowserManager.d.ts +1 -1
- package/dist/services/BrowserManager.d.ts.map +1 -1
- package/dist/services/BrowserManager.js +26 -3
- package/dist/services/BrowserManager.js.map +1 -1
- package/dist/services/MemoryCompressor.d.ts +11 -2
- package/dist/services/MemoryCompressor.d.ts.map +1 -1
- package/dist/services/MemoryCompressor.js +8 -26
- package/dist/services/MemoryCompressor.js.map +1 -1
- package/dist/services/MemoryService.d.ts +16 -3
- package/dist/services/MemoryService.d.ts.map +1 -1
- package/dist/services/MemoryService.js +79 -55
- package/dist/services/MemoryService.js.map +1 -1
- package/dist/services/PredictiveAnalyticsService.d.ts +34 -4
- package/dist/services/PredictiveAnalyticsService.d.ts.map +1 -1
- package/dist/services/PredictiveAnalyticsService.js +41 -25
- package/dist/services/PredictiveAnalyticsService.js.map +1 -1
- package/dist/services/QValueManager.d.ts +7 -0
- package/dist/services/QValueManager.d.ts.map +1 -1
- package/dist/services/QValueManager.js +9 -0
- package/dist/services/QValueManager.js.map +1 -1
- package/dist/services/RewardSignalProcessor.d.ts +38 -1
- package/dist/services/RewardSignalProcessor.d.ts.map +1 -1
- package/dist/services/RewardSignalProcessor.js +109 -7
- package/dist/services/RewardSignalProcessor.js.map +1 -1
- package/dist/services/SharedStateService.d.ts +16 -2
- package/dist/services/SharedStateService.d.ts.map +1 -1
- package/dist/services/SharedStateService.js +44 -3
- package/dist/services/SharedStateService.js.map +1 -1
- package/dist/services/TaskEffectivenessService.d.ts +34 -18
- package/dist/services/TaskEffectivenessService.d.ts.map +1 -1
- package/dist/services/TaskEffectivenessService.js +91 -155
- package/dist/services/TaskEffectivenessService.js.map +1 -1
- package/dist/services/WebSearchService.d.ts.map +1 -1
- package/dist/services/WebSearchService.js.map +1 -1
- package/dist/services/dag/TaskDagService.d.ts.map +1 -1
- package/dist/services/dag/TaskDagService.js +2 -0
- package/dist/services/dag/TaskDagService.js.map +1 -1
- package/dist/services/orpar-memory/OrparMemoryCoordinator.d.ts +7 -0
- package/dist/services/orpar-memory/OrparMemoryCoordinator.d.ts.map +1 -1
- package/dist/services/orpar-memory/OrparMemoryCoordinator.js +71 -10
- package/dist/services/orpar-memory/OrparMemoryCoordinator.js.map +1 -1
- package/dist/types/MemoryUtilityTypes.d.ts +2 -0
- package/dist/types/MemoryUtilityTypes.d.ts.map +1 -1
- package/dist/types/MemoryUtilityTypes.js.map +1 -1
- package/dist/utils/Logger.d.ts +43 -3
- package/dist/utils/Logger.d.ts.map +1 -1
- package/dist/utils/Logger.js +78 -36
- package/dist/utils/Logger.js.map +1 -1
- package/dist/utils/MxpEncryption.d.ts +19 -6
- package/dist/utils/MxpEncryption.d.ts.map +1 -1
- package/dist/utils/MxpEncryption.js +48 -16
- package/dist/utils/MxpEncryption.js.map +1 -1
- package/package.json +19 -4
- package/src/adapters/FrameworkAdapter.ts +1 -1
- package/src/config/ConfigManager.ts +52 -19
- package/src/config/memory-strata.config.ts +136 -0
- package/src/constants/ToolNames.ts +4 -18
- package/src/database/DatabaseAdapterFactory.ts +23 -6
- package/src/database/adapters/mongodb/MongoBaseRepository.ts +16 -2
- package/src/events/ClientEventBus.ts +68 -403
- package/src/events/EventBus.ts +7 -8
- package/src/events/EventBusBase.ts +479 -116
- package/src/events/EventNames.ts +6 -0
- package/src/events/PublicEvents.ts +7 -4
- package/src/events/ServerEventBus.ts +78 -473
- package/src/events/event-definitions/LlmBudgetEvents.ts +74 -0
- package/src/interfaces/IMemoryPersistence.ts +51 -0
- package/src/middleware/MxpMiddleware.ts +51 -24
- package/src/models/channelKey.ts +18 -4
- package/src/models/memoryUtility.ts +64 -0
- package/src/models/user.ts +36 -4
- package/src/mxp/BinaryProtocolLayer.ts +108 -124
- package/src/mxp/ContextCompressionEngine.ts +219 -161
- package/src/mxp/MxpTokenOptimizer.ts +10 -10
- package/src/prompts/MxfAgentSystemPrompt.ts +45 -55
- package/src/protocols/mcp/ToolError.ts +201 -0
- package/src/protocols/mcp/defineTool.ts +379 -0
- package/src/protocols/mcp/security/HttpTargetGuard.ts +267 -0
- package/src/protocols/mcp/security/McpSecurityGuard.ts +10 -3
- package/src/protocols/mcp/security/McpToolPolicy.ts +221 -0
- package/src/protocols/mcp/services/ExternalMcpServerManager.ts +340 -322
- package/src/protocols/mcp/services/ExternalServerConfigs.ts +82 -19
- package/src/protocols/mcp/tools/AnalyticsTools.ts +1 -1
- package/src/protocols/mcp/tools/CodeAnalysisTools.ts +15 -0
- package/src/protocols/mcp/tools/EffectivenessTools.ts +3 -3
- package/src/protocols/mcp/tools/GitTools.ts +290 -569
- package/src/protocols/mcp/tools/InfrastructureTools.ts +189 -43
- package/src/protocols/mcp/tools/MemorySearchTools.ts +77 -1
- package/src/protocols/mcp/tools/OrparTools.ts +87 -0
- package/src/protocols/mcp/tools/SafetyTools.ts +501 -579
- package/src/protocols/mcp/tools/TaskPlanningTools.ts +81 -39
- package/src/protocols/mcp/tools/TestTools.ts +339 -419
- package/src/protocols/mcp/tools/TypeScriptTools.ts +316 -376
- package/src/protocols/mcp/tools/WebTools.ts +209 -307
- package/src/protocols/mcp/tools/shell/ShellExecuteHandler.ts +53 -14
- package/src/schemas/EventPayloadSchema.ts +37 -0
- package/src/services/BackgroundTaskManager.ts +12 -4
- package/src/services/BrowserManager.ts +41 -1
- package/src/services/MemoryCompressor.ts +20 -32
- package/src/services/MemoryService.ts +96 -58
- package/src/services/PredictiveAnalyticsService.ts +55 -32
- package/src/services/QValueManager.ts +10 -0
- package/src/services/RewardSignalProcessor.ts +138 -9
- package/src/services/SharedStateService.ts +56 -8
- package/src/services/TaskEffectivenessService.ts +114 -187
- package/src/services/WebSearchService.ts +2 -1
- package/src/services/dag/TaskDagService.ts +2 -0
- package/src/services/orpar-memory/OrparMemoryCoordinator.ts +86 -10
- package/src/types/MemoryUtilityTypes.ts +2 -0
- package/src/utils/Logger.ts +116 -40
- package/src/utils/MxpEncryption.ts +69 -34
- package/dist/mxp/MxpEventForwardingEnhancer.d.ts +0 -134
- package/dist/mxp/MxpEventForwardingEnhancer.d.ts.map +0 -1
- package/dist/mxp/MxpEventForwardingEnhancer.js +0 -361
- package/dist/mxp/MxpEventForwardingEnhancer.js.map +0 -1
- package/dist/protocols/mcp/services/ToolSchemaEnhancements.d.ts +0 -56
- package/dist/protocols/mcp/services/ToolSchemaEnhancements.d.ts.map +0 -1
- package/dist/protocols/mcp/services/ToolSchemaEnhancements.js +0 -57
- package/dist/protocols/mcp/services/ToolSchemaEnhancements.js.map +0 -1
- package/dist/protocols/mcp/tools/ControlLoopLifecycle.d.ts +0 -270
- package/dist/protocols/mcp/tools/ControlLoopLifecycle.d.ts.map +0 -1
- package/dist/protocols/mcp/tools/ControlLoopLifecycle.js +0 -256
- package/dist/protocols/mcp/tools/ControlLoopLifecycle.js.map +0 -1
- package/dist/protocols/mcp/tools/LspTools.d.ts +0 -495
- package/dist/protocols/mcp/tools/LspTools.d.ts.map +0 -1
- package/dist/protocols/mcp/tools/LspTools.js +0 -469
- package/dist/protocols/mcp/tools/LspTools.js.map +0 -1
- package/src/mxp/MxpEventForwardingEnhancer.ts +0 -471
- package/src/protocols/mcp/services/ToolSchemaEnhancements.ts +0 -92
- package/src/protocols/mcp/tools/ControlLoopLifecycle.ts +0 -302
- package/src/protocols/mcp/tools/LspTools.ts +0 -476
|
@@ -20,27 +20,41 @@
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* WebTools.ts
|
|
23
|
-
*
|
|
24
|
-
* Web search, navigation,
|
|
25
|
-
*
|
|
23
|
+
*
|
|
24
|
+
* Web search, navigation, content extraction, screenshots, and HTTP fetches.
|
|
25
|
+
*
|
|
26
|
+
* Every tool here is declared with defineTool, so a failure arrives as one
|
|
27
|
+
* envelope with `isError: true` rather than as a string starting with "Error:"
|
|
28
|
+
* that a caller has to parse.
|
|
29
|
+
*
|
|
30
|
+
* api_fetch runs from inside the server's trust boundary, so its target URL is
|
|
31
|
+
* checked by HttpTargetGuard before the request goes out — see that module for
|
|
32
|
+
* why an unrestricted fetch is a server-side request forgery hole.
|
|
26
33
|
*/
|
|
27
34
|
|
|
28
|
-
import { WEB_TOOLS } from '../../../constants/ToolNames.js';
|
|
35
|
+
import { WEB_TOOLS, TOOL_CATEGORIES } from '../../../constants/ToolNames.js';
|
|
29
36
|
import { WebSearchService } from '../../../services/WebSearchService.js';
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
37
|
+
import { defineTool } from '../defineTool.js';
|
|
38
|
+
import { ToolError } from '../ToolError.js';
|
|
39
|
+
import { checkHttpTarget } from '../security/HttpTargetGuard.js';
|
|
32
40
|
|
|
33
|
-
//
|
|
41
|
+
// WebSearchService owns the browser and content-processing plumbing these tools
|
|
42
|
+
// need; they do not touch BrowserManager or ContentProcessor directly.
|
|
34
43
|
const webSearchService = new WebSearchService();
|
|
35
|
-
const browserManager = new BrowserManager();
|
|
36
|
-
const contentProcessor = new ContentProcessor();
|
|
37
44
|
|
|
38
45
|
/**
|
|
39
|
-
*
|
|
46
|
+
* Search the web and optionally pull the content of each result.
|
|
40
47
|
*/
|
|
41
|
-
export const webSearchTool = {
|
|
48
|
+
export const webSearchTool = defineTool<{
|
|
49
|
+
query: string;
|
|
50
|
+
maxResults?: number;
|
|
51
|
+
searchEngine?: string;
|
|
52
|
+
extractContent?: boolean;
|
|
53
|
+
format?: string;
|
|
54
|
+
}, unknown>({
|
|
42
55
|
name: WEB_TOOLS.WEB_SEARCH,
|
|
43
|
-
|
|
56
|
+
category: TOOL_CATEGORIES.WEB,
|
|
57
|
+
description: 'Search the web and return results, optionally with the full text of each page.',
|
|
44
58
|
inputSchema: {
|
|
45
59
|
type: 'object',
|
|
46
60
|
properties: {
|
|
@@ -75,61 +89,31 @@ export const webSearchTool = {
|
|
|
75
89
|
},
|
|
76
90
|
required: ['query']
|
|
77
91
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}) => {
|
|
89
|
-
try {
|
|
90
|
-
const result = await webSearchService.search({
|
|
91
|
-
query: input.query,
|
|
92
|
-
maxResults: input.maxResults || 10,
|
|
93
|
-
searchEngine: input.searchEngine || 'google',
|
|
94
|
-
extractContent: input.extractContent ?? true,
|
|
95
|
-
format: input.format || 'structured'
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
content: {
|
|
100
|
-
type: 'text',
|
|
101
|
-
text: JSON.stringify(result, null, 2)
|
|
102
|
-
},
|
|
103
|
-
metadata: {
|
|
104
|
-
toolName: WEB_TOOLS.WEB_SEARCH,
|
|
105
|
-
requestId: context.requestId,
|
|
106
|
-
timestamp: new Date().toISOString()
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
} catch (error) {
|
|
110
|
-
return {
|
|
111
|
-
content: {
|
|
112
|
-
type: 'text',
|
|
113
|
-
text: `Error: ${error instanceof Error ? error.message : 'Web search failed'}`
|
|
114
|
-
},
|
|
115
|
-
metadata: {
|
|
116
|
-
toolName: WEB_TOOLS.WEB_SEARCH,
|
|
117
|
-
requestId: context.requestId,
|
|
118
|
-
timestamp: new Date().toISOString(),
|
|
119
|
-
error: true
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
enabled: true
|
|
125
|
-
};
|
|
92
|
+
run: async (input) => {
|
|
93
|
+
return webSearchService.search({
|
|
94
|
+
query: input.query,
|
|
95
|
+
maxResults: input.maxResults ?? 10,
|
|
96
|
+
searchEngine: input.searchEngine ?? 'google',
|
|
97
|
+
extractContent: input.extractContent ?? true,
|
|
98
|
+
format: input.format ?? 'structured'
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
126
102
|
|
|
127
103
|
/**
|
|
128
|
-
*
|
|
104
|
+
* Load a URL in a browser and extract its content.
|
|
129
105
|
*/
|
|
130
|
-
export const webNavigationTool = {
|
|
106
|
+
export const webNavigationTool = defineTool<{
|
|
107
|
+
url: string;
|
|
108
|
+
waitStrategy?: string;
|
|
109
|
+
includeScreenshot?: boolean;
|
|
110
|
+
screenshotFormat?: string;
|
|
111
|
+
extractContent?: boolean;
|
|
112
|
+
format?: string;
|
|
113
|
+
}, unknown>({
|
|
131
114
|
name: WEB_TOOLS.WEB_NAVIGATE,
|
|
132
|
-
|
|
115
|
+
category: TOOL_CATEGORIES.WEB,
|
|
116
|
+
description: 'Load a URL in a headless browser and extract its content, optionally with a screenshot.',
|
|
133
117
|
inputSchema: {
|
|
134
118
|
type: 'object',
|
|
135
119
|
properties: {
|
|
@@ -169,63 +153,29 @@ export const webNavigationTool = {
|
|
|
169
153
|
},
|
|
170
154
|
required: ['url']
|
|
171
155
|
},
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}) => {
|
|
184
|
-
try {
|
|
185
|
-
const result = await webSearchService.navigate({
|
|
186
|
-
url: input.url,
|
|
187
|
-
waitStrategy: input.waitStrategy || 'networkidle2',
|
|
188
|
-
includeScreenshot: input.includeScreenshot || false,
|
|
189
|
-
screenshotFormat: input.screenshotFormat || 'png',
|
|
190
|
-
extractContent: input.extractContent ?? true,
|
|
191
|
-
format: input.format || 'structured'
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
return {
|
|
195
|
-
content: {
|
|
196
|
-
type: 'text',
|
|
197
|
-
text: JSON.stringify(result, null, 2)
|
|
198
|
-
},
|
|
199
|
-
metadata: {
|
|
200
|
-
toolName: WEB_TOOLS.WEB_NAVIGATE,
|
|
201
|
-
requestId: context.requestId,
|
|
202
|
-
timestamp: new Date().toISOString()
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
} catch (error) {
|
|
206
|
-
return {
|
|
207
|
-
content: {
|
|
208
|
-
type: 'text',
|
|
209
|
-
text: `Error: ${error instanceof Error ? error.message : 'Web navigation failed'}`
|
|
210
|
-
},
|
|
211
|
-
metadata: {
|
|
212
|
-
toolName: WEB_TOOLS.WEB_NAVIGATE,
|
|
213
|
-
requestId: context.requestId,
|
|
214
|
-
timestamp: new Date().toISOString(),
|
|
215
|
-
error: true
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
enabled: true
|
|
221
|
-
};
|
|
156
|
+
run: async (input) => {
|
|
157
|
+
return webSearchService.navigate({
|
|
158
|
+
url: input.url,
|
|
159
|
+
waitStrategy: input.waitStrategy ?? 'networkidle2',
|
|
160
|
+
includeScreenshot: input.includeScreenshot ?? false,
|
|
161
|
+
screenshotFormat: input.screenshotFormat ?? 'png',
|
|
162
|
+
extractContent: input.extractContent ?? true,
|
|
163
|
+
format: input.format ?? 'structured'
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
});
|
|
222
167
|
|
|
223
168
|
/**
|
|
224
|
-
*
|
|
169
|
+
* Extract content from several URLs at once.
|
|
225
170
|
*/
|
|
226
|
-
export const webContentExtractionTool = {
|
|
171
|
+
export const webContentExtractionTool = defineTool<{
|
|
172
|
+
urls: string[];
|
|
173
|
+
concurrency?: number;
|
|
174
|
+
format?: string;
|
|
175
|
+
}, unknown>({
|
|
227
176
|
name: WEB_TOOLS.WEB_BULK_EXTRACT,
|
|
228
|
-
|
|
177
|
+
category: TOOL_CATEGORIES.WEB,
|
|
178
|
+
description: 'Extract the content of several URLs in one call.',
|
|
229
179
|
inputSchema: {
|
|
230
180
|
type: 'object',
|
|
231
181
|
properties: {
|
|
@@ -255,57 +205,28 @@ export const webContentExtractionTool = {
|
|
|
255
205
|
},
|
|
256
206
|
required: ['urls']
|
|
257
207
|
},
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}) => {
|
|
267
|
-
try {
|
|
268
|
-
const result = await webSearchService.bulkExtract({
|
|
269
|
-
urls: input.urls,
|
|
270
|
-
concurrency: input.concurrency || 3,
|
|
271
|
-
format: input.format || 'structured'
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
return {
|
|
275
|
-
content: {
|
|
276
|
-
type: 'text',
|
|
277
|
-
text: JSON.stringify(result, null, 2)
|
|
278
|
-
},
|
|
279
|
-
metadata: {
|
|
280
|
-
toolName: WEB_TOOLS.WEB_BULK_EXTRACT,
|
|
281
|
-
requestId: context.requestId,
|
|
282
|
-
timestamp: new Date().toISOString()
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
} catch (error) {
|
|
286
|
-
return {
|
|
287
|
-
content: {
|
|
288
|
-
type: 'text',
|
|
289
|
-
text: `Error: ${error instanceof Error ? error.message : 'Bulk content extraction failed'}`
|
|
290
|
-
},
|
|
291
|
-
metadata: {
|
|
292
|
-
toolName: WEB_TOOLS.WEB_BULK_EXTRACT,
|
|
293
|
-
requestId: context.requestId,
|
|
294
|
-
timestamp: new Date().toISOString(),
|
|
295
|
-
error: true
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
},
|
|
300
|
-
enabled: true
|
|
301
|
-
};
|
|
208
|
+
run: async (input) => {
|
|
209
|
+
return webSearchService.bulkExtract({
|
|
210
|
+
urls: input.urls,
|
|
211
|
+
concurrency: input.concurrency ?? 3,
|
|
212
|
+
format: input.format ?? 'structured'
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
302
216
|
|
|
303
217
|
/**
|
|
304
|
-
*
|
|
218
|
+
* Capture a screenshot of a page.
|
|
305
219
|
*/
|
|
306
|
-
export const webScreenshotTool = {
|
|
220
|
+
export const webScreenshotTool = defineTool<{
|
|
221
|
+
url: string;
|
|
222
|
+
format?: string;
|
|
223
|
+
fullPage?: boolean;
|
|
224
|
+
width?: number;
|
|
225
|
+
height?: number;
|
|
226
|
+
}, { url: string; format: string; byteLength: number }>({
|
|
307
227
|
name: WEB_TOOLS.WEB_SCREENSHOT,
|
|
308
|
-
|
|
228
|
+
category: TOOL_CATEGORIES.WEB,
|
|
229
|
+
description: 'Capture a screenshot of a web page.',
|
|
309
230
|
inputSchema: {
|
|
310
231
|
type: 'object',
|
|
311
232
|
properties: {
|
|
@@ -342,71 +263,56 @@ export const webScreenshotTool = {
|
|
|
342
263
|
},
|
|
343
264
|
required: ['url']
|
|
344
265
|
},
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
channelId?: string;
|
|
355
|
-
}) => {
|
|
356
|
-
try {
|
|
357
|
-
const result = await webSearchService.screenshot({
|
|
358
|
-
url: input.url,
|
|
359
|
-
format: input.format || 'png',
|
|
360
|
-
fullPage: input.fullPage || false,
|
|
361
|
-
width: input.width || 1280,
|
|
362
|
-
height: input.height || 720
|
|
363
|
-
});
|
|
266
|
+
run: async (input) => {
|
|
267
|
+
const format = input.format ?? 'png';
|
|
268
|
+
const screenshot = await webSearchService.screenshot({
|
|
269
|
+
url: input.url,
|
|
270
|
+
format,
|
|
271
|
+
fullPage: input.fullPage ?? false,
|
|
272
|
+
width: input.width ?? 1280,
|
|
273
|
+
height: input.height ?? 720
|
|
274
|
+
});
|
|
364
275
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
requestId: context.requestId,
|
|
373
|
-
timestamp: new Date().toISOString(),
|
|
374
|
-
screenshotSize: result.length
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
} catch (error) {
|
|
378
|
-
return {
|
|
379
|
-
content: {
|
|
380
|
-
type: 'text',
|
|
381
|
-
text: `Error: ${error instanceof Error ? error.message : 'Screenshot capture failed'}`
|
|
382
|
-
},
|
|
383
|
-
metadata: {
|
|
384
|
-
toolName: WEB_TOOLS.WEB_SCREENSHOT,
|
|
385
|
-
requestId: context.requestId,
|
|
386
|
-
timestamp: new Date().toISOString(),
|
|
387
|
-
error: true
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
},
|
|
392
|
-
enabled: true
|
|
393
|
-
};
|
|
276
|
+
return {
|
|
277
|
+
url: input.url,
|
|
278
|
+
format,
|
|
279
|
+
byteLength: screenshot.length
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
});
|
|
394
283
|
|
|
395
284
|
/**
|
|
396
|
-
*
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
* API
|
|
285
|
+
* Fetch a URL and return the response body.
|
|
286
|
+
*
|
|
287
|
+
* The target is checked before the request goes out: the server can reach the
|
|
288
|
+
* MXF API on localhost, Meilisearch, MongoDB, and a cloud metadata endpoint, and
|
|
289
|
+
* an unrestricted fetch would let an agent reach all of them through us.
|
|
400
290
|
*/
|
|
401
|
-
export const apiFetchTool = {
|
|
402
|
-
|
|
403
|
-
|
|
291
|
+
export const apiFetchTool = defineTool<{
|
|
292
|
+
url: string;
|
|
293
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
294
|
+
headers?: Record<string, string>;
|
|
295
|
+
body?: unknown;
|
|
296
|
+
timeout?: number;
|
|
297
|
+
}, {
|
|
298
|
+
status: number;
|
|
299
|
+
contentType: string;
|
|
300
|
+
dataType: 'json' | 'text';
|
|
301
|
+
url: string;
|
|
302
|
+
data: unknown;
|
|
303
|
+
}>({
|
|
304
|
+
name: WEB_TOOLS.API_FETCH,
|
|
305
|
+
category: TOOL_CATEGORIES.WEB_REQUEST,
|
|
306
|
+
description:
|
|
307
|
+
'Fetch a public HTTP(S) endpoint and return the response body, parsed as JSON when the ' +
|
|
308
|
+
'response says it is JSON. Use this for APIs; use web_navigate for HTML pages. ' +
|
|
309
|
+
'Private and loopback addresses are refused.',
|
|
404
310
|
inputSchema: {
|
|
405
311
|
type: 'object',
|
|
406
312
|
properties: {
|
|
407
313
|
url: {
|
|
408
314
|
type: 'string',
|
|
409
|
-
description: 'API endpoint URL',
|
|
315
|
+
description: 'API endpoint URL (http or https, public host)',
|
|
410
316
|
format: 'uri'
|
|
411
317
|
},
|
|
412
318
|
method: {
|
|
@@ -427,127 +333,123 @@ export const apiFetchTool = {
|
|
|
427
333
|
timeout: {
|
|
428
334
|
type: 'number',
|
|
429
335
|
description: 'Request timeout in milliseconds',
|
|
430
|
-
default: 30000
|
|
336
|
+
default: 30000,
|
|
337
|
+
minimum: 1,
|
|
338
|
+
maximum: 120000
|
|
431
339
|
}
|
|
432
340
|
},
|
|
433
341
|
required: ['url']
|
|
434
342
|
},
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
343
|
+
run: async (input) => {
|
|
344
|
+
// Refuse targets inside the trust boundary before opening a socket.
|
|
345
|
+
const targetCheck = await checkHttpTarget(input.url);
|
|
346
|
+
if (!targetCheck.allowed) {
|
|
347
|
+
throw ToolError.permissionDenied(
|
|
348
|
+
targetCheck.reason ?? `Refusing to fetch ${input.url}`,
|
|
349
|
+
{ url: input.url }
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const method = input.method ?? 'GET';
|
|
354
|
+
const controller = new AbortController();
|
|
355
|
+
const timeoutId = setTimeout(() => controller.abort(), input.timeout ?? 30000);
|
|
356
|
+
|
|
446
357
|
try {
|
|
447
|
-
const
|
|
448
|
-
|
|
358
|
+
const headers: Record<string, string> = {
|
|
359
|
+
Accept: 'application/json',
|
|
360
|
+
...input.headers
|
|
361
|
+
};
|
|
449
362
|
|
|
450
363
|
const fetchOptions: RequestInit = {
|
|
451
|
-
method
|
|
452
|
-
headers
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
364
|
+
method,
|
|
365
|
+
headers,
|
|
366
|
+
signal: controller.signal,
|
|
367
|
+
// A redirect can point back at a blocked host after the check above,
|
|
368
|
+
// so follow none of them — the agent can fetch the new location
|
|
369
|
+
// explicitly and have it checked in turn.
|
|
370
|
+
redirect: 'manual'
|
|
457
371
|
};
|
|
458
372
|
|
|
459
|
-
if (input.body && (
|
|
373
|
+
if (input.body !== undefined && (method === 'POST' || method === 'PUT')) {
|
|
460
374
|
fetchOptions.body = JSON.stringify(input.body);
|
|
461
|
-
|
|
462
|
-
...fetchOptions.headers,
|
|
463
|
-
'Content-Type': 'application/json'
|
|
464
|
-
};
|
|
375
|
+
headers['Content-Type'] = 'application/json';
|
|
465
376
|
}
|
|
466
377
|
|
|
467
378
|
const response = await fetch(input.url, fetchOptions);
|
|
468
|
-
|
|
379
|
+
|
|
380
|
+
if (response.status >= 300 && response.status < 400) {
|
|
381
|
+
const location = response.headers.get('location');
|
|
382
|
+
throw ToolError.upstream(
|
|
383
|
+
`${input.url} redirected to ${location ?? 'an unspecified location'}. ` +
|
|
384
|
+
`Redirects are not followed — call api_fetch again with that URL if you want it.`,
|
|
385
|
+
{ details: { status: response.status, location, url: input.url } }
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const responseText = await response.text();
|
|
390
|
+
const contentType = response.headers.get('content-type') ?? '';
|
|
469
391
|
|
|
470
392
|
if (!response.ok) {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
text: JSON.stringify({
|
|
476
|
-
error: true,
|
|
393
|
+
throw ToolError.upstream(
|
|
394
|
+
`${method} ${input.url} returned ${response.status} ${response.statusText}`,
|
|
395
|
+
{
|
|
396
|
+
details: {
|
|
477
397
|
status: response.status,
|
|
478
398
|
statusText: response.statusText,
|
|
479
399
|
url: input.url,
|
|
480
|
-
body:
|
|
481
|
-
}
|
|
482
|
-
},
|
|
483
|
-
metadata: {
|
|
484
|
-
toolName: 'api_fetch',
|
|
485
|
-
requestId: context.requestId,
|
|
486
|
-
timestamp: new Date().toISOString(),
|
|
487
|
-
error: true
|
|
400
|
+
body: responseText.slice(0, 500)
|
|
401
|
+
}
|
|
488
402
|
}
|
|
489
|
-
|
|
403
|
+
);
|
|
490
404
|
}
|
|
491
405
|
|
|
492
|
-
//
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
let data: any = responseText;
|
|
498
|
-
let dataType = 'text';
|
|
406
|
+
// Parse as JSON only when the response claims to be JSON. A body that
|
|
407
|
+
// says it is JSON but does not parse is an upstream error, not a
|
|
408
|
+
// string to hand back as if nothing happened.
|
|
409
|
+
let data: unknown = responseText;
|
|
410
|
+
let dataType: 'json' | 'text' = 'text';
|
|
499
411
|
|
|
500
412
|
if (contentType.includes('application/json') || contentType.includes('text/json')) {
|
|
501
413
|
try {
|
|
502
414
|
data = JSON.parse(responseText);
|
|
503
415
|
dataType = 'json';
|
|
504
|
-
} catch (
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
416
|
+
} catch (parseError) {
|
|
417
|
+
throw ToolError.upstream(
|
|
418
|
+
`${input.url} declared Content-Type "${contentType}" but the body is not valid JSON: ` +
|
|
419
|
+
`${parseError instanceof Error ? parseError.message : String(parseError)}`,
|
|
420
|
+
{ details: { url: input.url, contentType, bodyPreview: responseText.slice(0, 200) } }
|
|
421
|
+
);
|
|
508
422
|
}
|
|
509
423
|
}
|
|
510
424
|
|
|
511
425
|
return {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
contentType: contentType,
|
|
518
|
-
dataType: dataType,
|
|
519
|
-
url: input.url,
|
|
520
|
-
data: data
|
|
521
|
-
}, null, 2)
|
|
522
|
-
},
|
|
523
|
-
metadata: {
|
|
524
|
-
toolName: 'api_fetch',
|
|
525
|
-
requestId: context.requestId,
|
|
526
|
-
timestamp: new Date().toISOString()
|
|
527
|
-
}
|
|
426
|
+
status: response.status,
|
|
427
|
+
contentType,
|
|
428
|
+
dataType,
|
|
429
|
+
url: input.url,
|
|
430
|
+
data
|
|
528
431
|
};
|
|
529
432
|
|
|
530
433
|
} catch (error) {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
434
|
+
// A ToolError from the branches above is already the right shape.
|
|
435
|
+
if (error instanceof ToolError) {
|
|
436
|
+
throw error;
|
|
437
|
+
}
|
|
438
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
439
|
+
throw ToolError.upstream(
|
|
440
|
+
`${method} ${input.url} timed out after ${input.timeout ?? 30000}ms`,
|
|
441
|
+
{ details: { url: input.url } }
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
throw ToolError.upstream(
|
|
445
|
+
`${method} ${input.url} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
446
|
+
{ cause: error, details: { url: input.url } }
|
|
447
|
+
);
|
|
448
|
+
} finally {
|
|
449
|
+
clearTimeout(timeoutId);
|
|
547
450
|
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
};
|
|
451
|
+
}
|
|
452
|
+
});
|
|
551
453
|
|
|
552
454
|
export const webTools = [
|
|
553
455
|
webSearchTool,
|
|
@@ -555,4 +457,4 @@ export const webTools = [
|
|
|
555
457
|
webContentExtractionTool,
|
|
556
458
|
webScreenshotTool,
|
|
557
459
|
apiFetchTool
|
|
558
|
-
];
|
|
460
|
+
];
|