@salesforce/magen-mcp-workflow 0.0.1
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 +168 -0
- package/dist/checkpointing/index.d.ts +3 -0
- package/dist/checkpointing/index.js +10 -0
- package/dist/checkpointing/index.js.map +1 -0
- package/dist/checkpointing/jsonCheckpointer.d.ts +19 -0
- package/dist/checkpointing/jsonCheckpointer.js +164 -0
- package/dist/checkpointing/jsonCheckpointer.js.map +1 -0
- package/dist/checkpointing/statePersistence.d.ts +26 -0
- package/dist/checkpointing/statePersistence.js +117 -0
- package/dist/checkpointing/statePersistence.js.map +1 -0
- package/dist/checkpointing/workflowStateManager.d.ts +99 -0
- package/dist/checkpointing/workflowStateManager.js +206 -0
- package/dist/checkpointing/workflowStateManager.js.map +1 -0
- package/dist/common/fileSystem.d.ts +113 -0
- package/dist/common/fileSystem.js +62 -0
- package/dist/common/fileSystem.js.map +1 -0
- package/dist/common/metadata.d.ts +93 -0
- package/dist/common/metadata.js +40 -0
- package/dist/common/metadata.js.map +1 -0
- package/dist/common/propertyMetadata.d.ts +58 -0
- package/dist/common/propertyMetadata.js +8 -0
- package/dist/common/propertyMetadata.js.map +1 -0
- package/dist/common/types.d.ts +16 -0
- package/dist/common/types.js +8 -0
- package/dist/common/types.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/logger.d.ts +56 -0
- package/dist/logging/logger.js +113 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/nodes/abstractBaseNode.d.ts +27 -0
- package/dist/nodes/abstractBaseNode.js +34 -0
- package/dist/nodes/abstractBaseNode.js.map +1 -0
- package/dist/nodes/abstractToolNode.d.ts +32 -0
- package/dist/nodes/abstractToolNode.js +44 -0
- package/dist/nodes/abstractToolNode.js.map +1 -0
- package/dist/nodes/getUserInput/factory.d.ts +42 -0
- package/dist/nodes/getUserInput/factory.js +64 -0
- package/dist/nodes/getUserInput/factory.js.map +1 -0
- package/dist/nodes/getUserInput/index.d.ts +2 -0
- package/dist/nodes/getUserInput/index.js +3 -0
- package/dist/nodes/getUserInput/index.js.map +1 -0
- package/dist/nodes/getUserInput/node.d.ts +68 -0
- package/dist/nodes/getUserInput/node.js +41 -0
- package/dist/nodes/getUserInput/node.js.map +1 -0
- package/dist/nodes/index.d.ts +5 -0
- package/dist/nodes/index.js +12 -0
- package/dist/nodes/index.js.map +1 -0
- package/dist/nodes/toolExecutor.d.ts +22 -0
- package/dist/nodes/toolExecutor.js +19 -0
- package/dist/nodes/toolExecutor.js.map +1 -0
- package/dist/nodes/userInputExtraction/factory.d.ts +42 -0
- package/dist/nodes/userInputExtraction/factory.js +55 -0
- package/dist/nodes/userInputExtraction/factory.js.map +1 -0
- package/dist/nodes/userInputExtraction/index.d.ts +2 -0
- package/dist/nodes/userInputExtraction/index.js +3 -0
- package/dist/nodes/userInputExtraction/index.js.map +1 -0
- package/dist/nodes/userInputExtraction/node.d.ts +60 -0
- package/dist/nodes/userInputExtraction/node.js +24 -0
- package/dist/nodes/userInputExtraction/node.js.map +1 -0
- package/dist/routers/checkPropertiesFulfilledRouter.d.ts +74 -0
- package/dist/routers/checkPropertiesFulfilledRouter.js +106 -0
- package/dist/routers/checkPropertiesFulfilledRouter.js.map +1 -0
- package/dist/routers/index.d.ts +1 -0
- package/dist/routers/index.js +8 -0
- package/dist/routers/index.js.map +1 -0
- package/dist/services/abstractService.d.ts +71 -0
- package/dist/services/abstractService.js +83 -0
- package/dist/services/abstractService.js.map +1 -0
- package/dist/services/getInputService.d.ts +43 -0
- package/dist/services/getInputService.js +48 -0
- package/dist/services/getInputService.js.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +10 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/inputExtractionService.d.ts +46 -0
- package/dist/services/inputExtractionService.js +133 -0
- package/dist/services/inputExtractionService.js.map +1 -0
- package/dist/storage/wellKnownDirectory.d.ts +79 -0
- package/dist/storage/wellKnownDirectory.js +121 -0
- package/dist/storage/wellKnownDirectory.js.map +1 -0
- package/dist/tools/base/abstractTool.d.ts +61 -0
- package/dist/tools/base/abstractTool.js +87 -0
- package/dist/tools/base/abstractTool.js.map +1 -0
- package/dist/tools/base/abstractWorkflowTool.d.ts +34 -0
- package/dist/tools/base/abstractWorkflowTool.js +94 -0
- package/dist/tools/base/abstractWorkflowTool.js.map +1 -0
- package/dist/tools/base/index.d.ts +2 -0
- package/dist/tools/base/index.js +9 -0
- package/dist/tools/base/index.js.map +1 -0
- package/dist/tools/orchestrator/config.d.ts +55 -0
- package/dist/tools/orchestrator/config.js +8 -0
- package/dist/tools/orchestrator/config.js.map +1 -0
- package/dist/tools/orchestrator/index.d.ts +3 -0
- package/dist/tools/orchestrator/index.js +9 -0
- package/dist/tools/orchestrator/index.js.map +1 -0
- package/dist/tools/orchestrator/metadata.d.ts +55 -0
- package/dist/tools/orchestrator/metadata.js +49 -0
- package/dist/tools/orchestrator/metadata.js.map +1 -0
- package/dist/tools/orchestrator/orchestratorTool.d.ts +39 -0
- package/dist/tools/orchestrator/orchestratorTool.js +186 -0
- package/dist/tools/orchestrator/orchestratorTool.js.map +1 -0
- package/dist/tools/utilities/getInput/factory.d.ts +43 -0
- package/dist/tools/utilities/getInput/factory.js +32 -0
- package/dist/tools/utilities/getInput/factory.js.map +1 -0
- package/dist/tools/utilities/getInput/index.d.ts +3 -0
- package/dist/tools/utilities/getInput/index.js +10 -0
- package/dist/tools/utilities/getInput/index.js.map +1 -0
- package/dist/tools/utilities/getInput/metadata.d.ts +78 -0
- package/dist/tools/utilities/getInput/metadata.js +43 -0
- package/dist/tools/utilities/getInput/metadata.js.map +1 -0
- package/dist/tools/utilities/getInput/tool.d.ts +89 -0
- package/dist/tools/utilities/getInput/tool.js +69 -0
- package/dist/tools/utilities/getInput/tool.js.map +1 -0
- package/dist/tools/utilities/index.d.ts +2 -0
- package/dist/tools/utilities/index.js +9 -0
- package/dist/tools/utilities/index.js.map +1 -0
- package/dist/tools/utilities/inputExtraction/factory.d.ts +43 -0
- package/dist/tools/utilities/inputExtraction/factory.js +32 -0
- package/dist/tools/utilities/inputExtraction/factory.js.map +1 -0
- package/dist/tools/utilities/inputExtraction/index.d.ts +3 -0
- package/dist/tools/utilities/inputExtraction/index.js +10 -0
- package/dist/tools/utilities/inputExtraction/index.js.map +1 -0
- package/dist/tools/utilities/inputExtraction/metadata.d.ts +66 -0
- package/dist/tools/utilities/inputExtraction/metadata.js +52 -0
- package/dist/tools/utilities/inputExtraction/metadata.js.map +1 -0
- package/dist/tools/utilities/inputExtraction/tool.d.ts +82 -0
- package/dist/tools/utilities/inputExtraction/tool.js +71 -0
- package/dist/tools/utilities/inputExtraction/tool.js.map +1 -0
- package/dist/utils/toolExecutionUtils.d.ts +55 -0
- package/dist/utils/toolExecutionUtils.js +70 -0
- package/dist/utils/toolExecutionUtils.js.map +1 -0
- package/package.json +42 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
|
+
*/
|
|
7
|
+
// Common - Filesystem Operations
|
|
8
|
+
export { NodeFileSystemOperations } from './common/fileSystem.js';
|
|
9
|
+
// Storage (Well-Known Directory)
|
|
10
|
+
export { WELL_KNOWN_DIR_NAME, WELL_KNOWN_FILES, WellKnownDirectoryManager, } from './storage/wellKnownDirectory.js';
|
|
11
|
+
// Logging
|
|
12
|
+
export { PinoLogger, createLogger, createComponentLogger, createWorkflowLogger, } from './logging/logger.js';
|
|
13
|
+
// Common Metadata
|
|
14
|
+
export { WORKFLOW_STATE_DATA_SCHEMA, WORKFLOW_PROPERTY_NAMES, WORKFLOW_TOOL_BASE_INPUT_SCHEMA, MCP_WORKFLOW_TOOL_OUTPUT_SCHEMA, } from './common/metadata.js';
|
|
15
|
+
// Tool Execution Infrastructure
|
|
16
|
+
export { LangGraphToolExecutor } from './nodes/toolExecutor.js';
|
|
17
|
+
// Tool Execution Utils
|
|
18
|
+
export { executeToolWithLogging } from './utils/toolExecutionUtils.js';
|
|
19
|
+
// Base Tool Classes
|
|
20
|
+
export { AbstractTool, AbstractWorkflowTool } from './tools/base/index.js';
|
|
21
|
+
// Utility Tools
|
|
22
|
+
export {
|
|
23
|
+
// Get Input Tool
|
|
24
|
+
GetInputTool, createGetInputTool, createGetInputMetadata, GET_INPUT_PROPERTY_SCHEMA, GET_INPUT_WORKFLOW_INPUT_SCHEMA, GET_INPUT_WORKFLOW_RESULT_SCHEMA,
|
|
25
|
+
// Input Extraction Tool
|
|
26
|
+
InputExtractionTool, createInputExtractionTool, createInputExtractionMetadata, INPUT_EXTRACTION_WORKFLOW_INPUT_SCHEMA, INPUT_EXTRACTION_WORKFLOW_RESULT_SCHEMA, } from './tools/utilities/index.js';
|
|
27
|
+
// Base Node Classes
|
|
28
|
+
export { BaseNode, AbstractToolNode, createGetUserInputNode, createUserInputExtractionNode, } from './nodes/index.js';
|
|
29
|
+
// Routers
|
|
30
|
+
export { CheckPropertiesFulfilledRouter } from './routers/index.js';
|
|
31
|
+
// Base Service Classes
|
|
32
|
+
export { AbstractService } from './services/index.js';
|
|
33
|
+
// Checkpointing Infrastructure
|
|
34
|
+
export { JsonCheckpointSaver, WorkflowStatePersistence, WorkflowStateManager, } from './checkpointing/index.js';
|
|
35
|
+
// Orchestrator Tool
|
|
36
|
+
export { OrchestratorTool, createOrchestratorToolMetadata, ORCHESTRATOR_INPUT_SCHEMA, ORCHESTRATOR_OUTPUT_SCHEMA, } from './tools/orchestrator/index.js';
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,iCAAiC;AACjC,OAAO,EAA6B,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAE7F,iCAAiC;AACjC,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAEhB,yBAAyB,GAC1B,MAAM,iCAAiC,CAAC;AAEzC,UAAU;AACV,OAAO,EAEL,UAAU,EACV,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAE7B,kBAAkB;AAClB,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,EACvB,+BAA+B,EAC/B,+BAA+B,GAMhC,MAAM,sBAAsB,CAAC;AAU9B,gCAAgC;AAChC,OAAO,EAAqB,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEnF,uBAAuB;AACvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,oBAAoB;AACpB,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE3E,gBAAgB;AAChB,OAAO;AACL,iBAAiB;AACjB,YAAY,EACZ,kBAAkB,EAClB,sBAAsB,EAItB,yBAAyB,EACzB,+BAA+B,EAC/B,gCAAgC;AAChC,wBAAwB;AACxB,mBAAmB,EACnB,yBAAyB,EACzB,6BAA6B,EAI7B,sCAAsC,EACtC,uCAAuC,GACxC,MAAM,4BAA4B,CAAC;AAEpC,oBAAoB;AACpB,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,sBAAsB,EACtB,6BAA6B,GAG9B,MAAM,kBAAkB,CAAC;AAE1B,UAAU;AACV,OAAO,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AAEpE,uBAAuB;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,+BAA+B;AAC/B,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,GAGrB,MAAM,0BAA0B,CAAC;AAElC,oBAAoB;AACpB,OAAO,EACL,gBAAgB,EAChB,8BAA8B,EAK9B,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logging module for the Mobile Native MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Provides a production-ready logging solution using pino with proper dependency injection
|
|
5
|
+
* support for testing and reuse across all MCP tools and facilities.
|
|
6
|
+
*/
|
|
7
|
+
import pino from 'pino';
|
|
8
|
+
/**
|
|
9
|
+
* Logger interface for dependency injection - compatible with pino
|
|
10
|
+
* This interface allows for clean testing and consistent logging across all components
|
|
11
|
+
*/
|
|
12
|
+
export interface Logger {
|
|
13
|
+
info(message: string, data?: unknown): void;
|
|
14
|
+
debug(message: string, data?: unknown): void;
|
|
15
|
+
error(message: string, error?: Error): void;
|
|
16
|
+
warn(message: string, data?: unknown): void;
|
|
17
|
+
child(bindings: Record<string, unknown>): Logger;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Pino-based logger implementation
|
|
21
|
+
* Wraps pino instances to provide our Logger interface while maintaining all pino benefits
|
|
22
|
+
*/
|
|
23
|
+
export declare class PinoLogger implements Logger {
|
|
24
|
+
private pinoInstance;
|
|
25
|
+
constructor(pinoInstance: pino.Logger);
|
|
26
|
+
info(message: string, data?: unknown): void;
|
|
27
|
+
debug(message: string, data?: unknown): void;
|
|
28
|
+
error(message: string, error?: Error): void;
|
|
29
|
+
warn(message: string, data?: unknown): void;
|
|
30
|
+
child(bindings: Record<string, unknown>): Logger;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Factory function to create a logger that writes to .magen directory
|
|
34
|
+
*
|
|
35
|
+
* @param level - Log level (default: from LOG_LEVEL env var or 'info')
|
|
36
|
+
* @param options - Additional pino configuration options
|
|
37
|
+
* @returns Logger instance configured for file logging
|
|
38
|
+
*/
|
|
39
|
+
export declare function createLogger(level?: string, options?: pino.LoggerOptions): Logger;
|
|
40
|
+
/**
|
|
41
|
+
* Create a logger for a specific MCP tool or component
|
|
42
|
+
*
|
|
43
|
+
* @param componentName - Name of the component (e.g., 'TemplateDiscovery', 'BuildTool')
|
|
44
|
+
* @param level - Log level override
|
|
45
|
+
* @returns Logger instance with component context
|
|
46
|
+
*/
|
|
47
|
+
export declare function createComponentLogger(componentName: string, level?: string): Logger;
|
|
48
|
+
/**
|
|
49
|
+
* Create a specialized logger for workflow orchestration and MCP tool interactions
|
|
50
|
+
*
|
|
51
|
+
* @param componentName - Name of the workflow component
|
|
52
|
+
* @param level - Log level (default: 'info')
|
|
53
|
+
* @param serviceName - Service name for log metadata (default: 'mcp-workflow')
|
|
54
|
+
* @returns Logger instance configured for workflow logging with additional metadata
|
|
55
|
+
*/
|
|
56
|
+
export declare function createWorkflowLogger(componentName: string, level?: string, serviceName?: string): Logger;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Logging module for the Mobile Native MCP Server
|
|
9
|
+
*
|
|
10
|
+
* Provides a production-ready logging solution using pino with proper dependency injection
|
|
11
|
+
* support for testing and reuse across all MCP tools and facilities.
|
|
12
|
+
*/
|
|
13
|
+
import pino from 'pino';
|
|
14
|
+
import { WellKnownDirectoryManager } from '../storage/wellKnownDirectory.js';
|
|
15
|
+
/**
|
|
16
|
+
* Pino-based logger implementation
|
|
17
|
+
* Wraps pino instances to provide our Logger interface while maintaining all pino benefits
|
|
18
|
+
*/
|
|
19
|
+
export class PinoLogger {
|
|
20
|
+
pinoInstance;
|
|
21
|
+
constructor(pinoInstance) {
|
|
22
|
+
this.pinoInstance = pinoInstance;
|
|
23
|
+
}
|
|
24
|
+
info(message, data) {
|
|
25
|
+
if (data) {
|
|
26
|
+
this.pinoInstance.info(data, message);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.pinoInstance.info(message);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
debug(message, data) {
|
|
33
|
+
if (data) {
|
|
34
|
+
this.pinoInstance.debug(data, message);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
this.pinoInstance.debug(message);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
error(message, error) {
|
|
41
|
+
if (error) {
|
|
42
|
+
this.pinoInstance.error({ err: error }, message);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.pinoInstance.error(message);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
warn(message, data) {
|
|
49
|
+
if (data) {
|
|
50
|
+
this.pinoInstance.warn(data, message);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.pinoInstance.warn(message);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
child(bindings) {
|
|
57
|
+
return new PinoLogger(this.pinoInstance.child(bindings));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Factory function to create a logger that writes to .magen directory
|
|
62
|
+
*
|
|
63
|
+
* @param level - Log level (default: from LOG_LEVEL env var or 'info')
|
|
64
|
+
* @param options - Additional pino configuration options
|
|
65
|
+
* @returns Logger instance configured for file logging
|
|
66
|
+
*/
|
|
67
|
+
export function createLogger(level = process.env.LOG_LEVEL || 'info', options = {}) {
|
|
68
|
+
const wellKnownDirManager = new WellKnownDirectoryManager();
|
|
69
|
+
const logFilePath = wellKnownDirManager.getWorkflowLogsPath();
|
|
70
|
+
const pinoInstance = pino({
|
|
71
|
+
level,
|
|
72
|
+
// Use structured JSON output for file logging
|
|
73
|
+
...options,
|
|
74
|
+
}, pino.destination({
|
|
75
|
+
dest: logFilePath,
|
|
76
|
+
sync: false, // Async logging for better performance
|
|
77
|
+
}));
|
|
78
|
+
return new PinoLogger(pinoInstance);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a logger for a specific MCP tool or component
|
|
82
|
+
*
|
|
83
|
+
* @param componentName - Name of the component (e.g., 'TemplateDiscovery', 'BuildTool')
|
|
84
|
+
* @param level - Log level override
|
|
85
|
+
* @returns Logger instance with component context
|
|
86
|
+
*/
|
|
87
|
+
export function createComponentLogger(componentName, level) {
|
|
88
|
+
const baseLogger = createLogger(level);
|
|
89
|
+
return baseLogger.child({ component: componentName });
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Create a specialized logger for workflow orchestration and MCP tool interactions
|
|
93
|
+
*
|
|
94
|
+
* @param componentName - Name of the workflow component
|
|
95
|
+
* @param level - Log level (default: 'info')
|
|
96
|
+
* @param serviceName - Service name for log metadata (default: 'mcp-workflow')
|
|
97
|
+
* @returns Logger instance configured for workflow logging with additional metadata
|
|
98
|
+
*/
|
|
99
|
+
export function createWorkflowLogger(componentName, level, serviceName) {
|
|
100
|
+
const service = serviceName || 'mcp-workflow';
|
|
101
|
+
const baseLogger = createLogger(level, {
|
|
102
|
+
// Add workflow-specific metadata to all log entries
|
|
103
|
+
base: {
|
|
104
|
+
service,
|
|
105
|
+
logType: 'workflow',
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
return baseLogger.child({
|
|
109
|
+
component: componentName,
|
|
110
|
+
workflowSession: true,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logging/logger.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { StateType, StateDefinition } from '@langchain/langgraph';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all workflow nodes
|
|
4
|
+
*
|
|
5
|
+
* @template TState - The state type for the workflow (defaults to StateType<StateDefinition>)
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ```
|
|
9
|
+
* const MyWorkflowState = Annotation.Root({ count: Annotation<number> });
|
|
10
|
+
* type State = typeof MyWorkflowState.State; // This is StateType<typeof MyWorkflowState.spec>
|
|
11
|
+
*
|
|
12
|
+
* class IncrementNode extends BaseNode<State> {
|
|
13
|
+
* constructor() {
|
|
14
|
+
* super('increment');
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* execute = (state: State) => {
|
|
18
|
+
* return { count: state.count + 1 };
|
|
19
|
+
* };
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class BaseNode<TState extends StateType<StateDefinition>> {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
constructor(name: string);
|
|
26
|
+
abstract execute: (state: TState) => Partial<TState>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base class for all workflow nodes
|
|
9
|
+
*
|
|
10
|
+
* @template TState - The state type for the workflow (defaults to StateType<StateDefinition>)
|
|
11
|
+
*
|
|
12
|
+
* Example:
|
|
13
|
+
* ```
|
|
14
|
+
* const MyWorkflowState = Annotation.Root({ count: Annotation<number> });
|
|
15
|
+
* type State = typeof MyWorkflowState.State; // This is StateType<typeof MyWorkflowState.spec>
|
|
16
|
+
*
|
|
17
|
+
* class IncrementNode extends BaseNode<State> {
|
|
18
|
+
* constructor() {
|
|
19
|
+
* super('increment');
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* execute = (state: State) => {
|
|
23
|
+
* return { count: state.count + 1 };
|
|
24
|
+
* };
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export class BaseNode {
|
|
29
|
+
name;
|
|
30
|
+
constructor(name) {
|
|
31
|
+
this.name = name;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=abstractBaseNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstractBaseNode.js","sourceRoot":"","sources":["../../src/nodes/abstractBaseNode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAgB,QAAQ;IACZ,IAAI,CAAS;IAE7B,YAAY,IAAY;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CAGF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import { StateType, StateDefinition } from '@langchain/langgraph';
|
|
3
|
+
import { BaseNode } from './abstractBaseNode.js';
|
|
4
|
+
import { MCPToolInvocationData } from '../common/metadata.js';
|
|
5
|
+
import { Logger } from '../logging/logger.js';
|
|
6
|
+
import { ToolExecutor } from './toolExecutor.js';
|
|
7
|
+
/**
|
|
8
|
+
* Abstract base class for nodes that execute MCP tools
|
|
9
|
+
*
|
|
10
|
+
* @template TState - The state type for the workflow (defaults to StateType<StateDefinition>)
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class AbstractToolNode<TState extends StateType<StateDefinition>> extends BaseNode<TState> {
|
|
13
|
+
protected readonly logger: Logger;
|
|
14
|
+
protected readonly componentName: string;
|
|
15
|
+
protected readonly toolExecutor: ToolExecutor;
|
|
16
|
+
constructor(name: string, toolExecutor?: ToolExecutor, logger?: Logger);
|
|
17
|
+
/**
|
|
18
|
+
* Protected method to execute a tool with logging and validation.
|
|
19
|
+
*
|
|
20
|
+
* By default, results are validated using the provided Zod schema's parse method.
|
|
21
|
+
* Pass a custom validator function to implement additional validation logic.
|
|
22
|
+
*
|
|
23
|
+
* This method uses the common toolExecutionUtils.executeToolWithLogging function
|
|
24
|
+
* to ensure consistent behavior across all tool invocations in the codebase.
|
|
25
|
+
*
|
|
26
|
+
* @param toolInvocationData The tool invocation data to pass to the tool executor
|
|
27
|
+
* @param resultSchema The schema to validate the result against
|
|
28
|
+
* @param validator Optional custom validator function
|
|
29
|
+
* @returns The validated result from the tool execution
|
|
30
|
+
*/
|
|
31
|
+
protected executeToolWithLogging<TResultSchema extends z.ZodObject<z.ZodRawShape>>(toolInvocationData: MCPToolInvocationData<z.ZodObject<z.ZodRawShape>>, resultSchema: TResultSchema, validator?: (result: unknown, schema: TResultSchema) => z.infer<TResultSchema>): z.infer<TResultSchema>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
|
+
*/
|
|
7
|
+
import { BaseNode } from './abstractBaseNode.js';
|
|
8
|
+
import { createComponentLogger } from '../logging/logger.js';
|
|
9
|
+
import { LangGraphToolExecutor } from './toolExecutor.js';
|
|
10
|
+
import { executeToolWithLogging } from '../utils/toolExecutionUtils.js';
|
|
11
|
+
/**
|
|
12
|
+
* Abstract base class for nodes that execute MCP tools
|
|
13
|
+
*
|
|
14
|
+
* @template TState - The state type for the workflow (defaults to StateType<StateDefinition>)
|
|
15
|
+
*/
|
|
16
|
+
export class AbstractToolNode extends BaseNode {
|
|
17
|
+
logger;
|
|
18
|
+
componentName;
|
|
19
|
+
toolExecutor;
|
|
20
|
+
constructor(name, toolExecutor, logger) {
|
|
21
|
+
super(name);
|
|
22
|
+
this.componentName = `WorkflowNode:${this.constructor.name}`;
|
|
23
|
+
this.logger = logger ?? createComponentLogger(this.componentName);
|
|
24
|
+
this.toolExecutor = toolExecutor ?? new LangGraphToolExecutor();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Protected method to execute a tool with logging and validation.
|
|
28
|
+
*
|
|
29
|
+
* By default, results are validated using the provided Zod schema's parse method.
|
|
30
|
+
* Pass a custom validator function to implement additional validation logic.
|
|
31
|
+
*
|
|
32
|
+
* This method uses the common toolExecutionUtils.executeToolWithLogging function
|
|
33
|
+
* to ensure consistent behavior across all tool invocations in the codebase.
|
|
34
|
+
*
|
|
35
|
+
* @param toolInvocationData The tool invocation data to pass to the tool executor
|
|
36
|
+
* @param resultSchema The schema to validate the result against
|
|
37
|
+
* @param validator Optional custom validator function
|
|
38
|
+
* @returns The validated result from the tool execution
|
|
39
|
+
*/
|
|
40
|
+
executeToolWithLogging(toolInvocationData, resultSchema, validator) {
|
|
41
|
+
return executeToolWithLogging(this.toolExecutor, this.logger, toolInvocationData, resultSchema, validator);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=abstractToolNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstractToolNode.js","sourceRoot":"","sources":["../../src/nodes/abstractToolNode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAU,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAgB,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE;;;;GAIG;AACH,MAAM,OAAgB,gBAEpB,SAAQ,QAAgB;IACL,MAAM,CAAS;IACf,aAAa,CAAS;IACtB,YAAY,CAAe;IAE9C,YAAY,IAAY,EAAE,YAA2B,EAAE,MAAe;QACpE,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,aAAa,GAAG,gBAAgB,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAC7D,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,qBAAqB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAClE,IAAI,CAAC,YAAY,GAAG,YAAY,IAAI,IAAI,qBAAqB,EAAE,CAAC;IAClE,CAAC;IAED;;;;;;;;;;;;;OAaG;IACO,sBAAsB,CAC9B,kBAAqE,EACrE,YAA2B,EAC3B,SAA8E;QAE9E,OAAO,sBAAsB,CAC3B,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,MAAM,EACX,kBAAkB,EAClB,YAAY,EACZ,SAAS,CACV,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { StateType, StateDefinition } from '@langchain/langgraph';
|
|
2
|
+
import { BaseNode } from '../abstractBaseNode.js';
|
|
3
|
+
import { GetUserInputNodeOptions } from './node.js';
|
|
4
|
+
/**
|
|
5
|
+
* Factory function to create a Get User Input Node
|
|
6
|
+
*
|
|
7
|
+
* This node requests user input for any unfulfilled required properties.
|
|
8
|
+
* It determines which properties are missing, calls the GetInputService to
|
|
9
|
+
* prompt the user, and returns the user's response.
|
|
10
|
+
*
|
|
11
|
+
* @template TState - The state type for the workflow
|
|
12
|
+
* @param options - Configuration options for the node
|
|
13
|
+
* @returns A configured Get User Input Node instance
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const MyState = Annotation.Root({
|
|
18
|
+
* userInput: Annotation<unknown>,
|
|
19
|
+
* platform: Annotation<string>,
|
|
20
|
+
* projectName: Annotation<string>,
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* const properties = {
|
|
24
|
+
* platform: {
|
|
25
|
+
* zodType: z.enum(['iOS', 'Android']),
|
|
26
|
+
* description: 'Target platform',
|
|
27
|
+
* friendlyName: 'platform',
|
|
28
|
+
* },
|
|
29
|
+
* projectName: {
|
|
30
|
+
* zodType: z.string(),
|
|
31
|
+
* description: 'Project name',
|
|
32
|
+
* friendlyName: 'project name',
|
|
33
|
+
* },
|
|
34
|
+
* };
|
|
35
|
+
*
|
|
36
|
+
* const node = createGetUserInputNode({
|
|
37
|
+
* requiredProperties: properties,
|
|
38
|
+
* getInputService: myGetInputService,
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function createGetUserInputNode<TState extends StateType<StateDefinition>>(options: GetUserInputNodeOptions<TState>): BaseNode<TState>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
|
+
*/
|
|
7
|
+
import { LangGraphToolExecutor } from '../toolExecutor.js';
|
|
8
|
+
import { createComponentLogger } from '../../logging/logger.js';
|
|
9
|
+
import { GetInputService } from '../../services/getInputService.js';
|
|
10
|
+
import { GetUserInputNode } from './node.js';
|
|
11
|
+
/**
|
|
12
|
+
* Factory function to create a Get User Input Node
|
|
13
|
+
*
|
|
14
|
+
* This node requests user input for any unfulfilled required properties.
|
|
15
|
+
* It determines which properties are missing, calls the GetInputService to
|
|
16
|
+
* prompt the user, and returns the user's response.
|
|
17
|
+
*
|
|
18
|
+
* @template TState - The state type for the workflow
|
|
19
|
+
* @param options - Configuration options for the node
|
|
20
|
+
* @returns A configured Get User Input Node instance
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const MyState = Annotation.Root({
|
|
25
|
+
* userInput: Annotation<unknown>,
|
|
26
|
+
* platform: Annotation<string>,
|
|
27
|
+
* projectName: Annotation<string>,
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* const properties = {
|
|
31
|
+
* platform: {
|
|
32
|
+
* zodType: z.enum(['iOS', 'Android']),
|
|
33
|
+
* description: 'Target platform',
|
|
34
|
+
* friendlyName: 'platform',
|
|
35
|
+
* },
|
|
36
|
+
* projectName: {
|
|
37
|
+
* zodType: z.string(),
|
|
38
|
+
* description: 'Project name',
|
|
39
|
+
* friendlyName: 'project name',
|
|
40
|
+
* },
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* const node = createGetUserInputNode({
|
|
44
|
+
* requiredProperties: properties,
|
|
45
|
+
* getInputService: myGetInputService,
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function createGetUserInputNode(options) {
|
|
50
|
+
const { requiredProperties, toolId, getInputService, toolExecutor = new LangGraphToolExecutor(), logger = createComponentLogger('GetUserInputNode'), isPropertyFulfilled = (state, propertyName) => {
|
|
51
|
+
const isFulfilled = !!state[propertyName];
|
|
52
|
+
if (isFulfilled) {
|
|
53
|
+
return { isFulfilled: true };
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
isFulfilled: false,
|
|
57
|
+
reason: `Property '${propertyName}' is missing from the workflow state.`,
|
|
58
|
+
};
|
|
59
|
+
}, userInputProperty, } = options;
|
|
60
|
+
// Create default service implementation if not provided
|
|
61
|
+
const service = getInputService ?? new GetInputService(toolId, toolExecutor, logger);
|
|
62
|
+
return new GetUserInputNode(service, requiredProperties, isPropertyFulfilled, userInputProperty);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/nodes/getUserInput/factory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,eAAe,EAA2B,MAAM,mCAAmC,CAAC;AAC7F,OAAO,EAA2B,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAGtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAAwC;IAExC,MAAM,EACJ,kBAAkB,EAClB,MAAM,EACN,eAAe,EACf,YAAY,GAAG,IAAI,qBAAqB,EAAE,EAC1C,MAAM,GAAG,qBAAqB,CAAC,kBAAkB,CAAC,EAClD,mBAAmB,GAAG,CAAC,KAAa,EAAE,YAAoB,EAA2B,EAAE;QACrF,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAC1C,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QAC/B,CAAC;QACD,OAAO;YACL,WAAW,EAAE,KAAK;YAClB,MAAM,EAAE,aAAa,YAAY,uCAAuC;SACzE,CAAC;IACJ,CAAC,EACD,iBAAiB,GAClB,GAAG,OAAO,CAAC;IAEZ,wDAAwD;IACxD,MAAM,OAAO,GACX,eAAe,IAAI,IAAI,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IAEvE,OAAO,IAAI,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,iBAAiB,CAAC,CAAC;AACnG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/nodes/getUserInput/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { StateType, StateDefinition } from '@langchain/langgraph';
|
|
2
|
+
import { BaseNode } from '../abstractBaseNode.js';
|
|
3
|
+
import { PropertyMetadataCollection } from '../../common/propertyMetadata.js';
|
|
4
|
+
import { IsPropertyFulfilled } from '../../common/types.js';
|
|
5
|
+
import { ToolExecutor } from '../toolExecutor.js';
|
|
6
|
+
import { Logger } from '../../logging/logger.js';
|
|
7
|
+
import { GetInputServiceProvider } from '../../services/getInputService.js';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration options for creating a Get User Input Node
|
|
10
|
+
*/
|
|
11
|
+
export interface GetUserInputNodeOptions<TState extends StateType<StateDefinition>> {
|
|
12
|
+
/**
|
|
13
|
+
* Collection of properties that must be collected from the user
|
|
14
|
+
*/
|
|
15
|
+
requiredProperties: PropertyMetadataCollection;
|
|
16
|
+
/**
|
|
17
|
+
* Tool ID for the get input tool (e.g., 'magen-get-input', 'sfmobile-native-get-input')
|
|
18
|
+
* Required if getInputService is not provided
|
|
19
|
+
*/
|
|
20
|
+
toolId: string;
|
|
21
|
+
/**
|
|
22
|
+
* Service provider for getting user input (injectable for testing)
|
|
23
|
+
* If not provided, a default implementation will be created using toolId
|
|
24
|
+
*/
|
|
25
|
+
getInputService?: GetInputServiceProvider;
|
|
26
|
+
/**
|
|
27
|
+
* Tool executor for services (optional, defaults to LangGraphToolExecutor)
|
|
28
|
+
*/
|
|
29
|
+
toolExecutor?: ToolExecutor;
|
|
30
|
+
/**
|
|
31
|
+
* Logger instance (optional, defaults to component logger)
|
|
32
|
+
*/
|
|
33
|
+
logger?: Logger;
|
|
34
|
+
/**
|
|
35
|
+
* Function to check if a property is fulfilled in the state
|
|
36
|
+
* Default: checks if property exists and is truthy
|
|
37
|
+
*/
|
|
38
|
+
isPropertyFulfilled?: IsPropertyFulfilled<TState>;
|
|
39
|
+
/**
|
|
40
|
+
* Property name in state that contains user input to extract from.
|
|
41
|
+
* Must be a valid property of TState.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
*
|
|
45
|
+
* // State has a 'userInput' property
|
|
46
|
+
* createGetUserInputNode({
|
|
47
|
+
* userInputProperty: 'userInput',
|
|
48
|
+
* ...
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* // State has a 'currentUtterance' property
|
|
52
|
+
* createGetUserInputNode({
|
|
53
|
+
* userInputProperty: 'currentUtterance',
|
|
54
|
+
* ...
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
userInputProperty: keyof TState;
|
|
59
|
+
}
|
|
60
|
+
export declare class GetUserInputNode<TState extends StateType<StateDefinition>> extends BaseNode<TState> {
|
|
61
|
+
private readonly getInputService;
|
|
62
|
+
private readonly requiredProperties;
|
|
63
|
+
private readonly isPropertyFulfilled;
|
|
64
|
+
private readonly userInputProperty;
|
|
65
|
+
constructor(getInputService: GetInputServiceProvider, requiredProperties: PropertyMetadataCollection, isPropertyFulfilled: IsPropertyFulfilled<TState>, userInputProperty: keyof TState);
|
|
66
|
+
execute: (state: TState) => Partial<TState>;
|
|
67
|
+
private getUnfulfilledProperties;
|
|
68
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
|
+
*/
|
|
7
|
+
import { BaseNode } from '../abstractBaseNode.js';
|
|
8
|
+
export class GetUserInputNode extends BaseNode {
|
|
9
|
+
getInputService;
|
|
10
|
+
requiredProperties;
|
|
11
|
+
isPropertyFulfilled;
|
|
12
|
+
userInputProperty;
|
|
13
|
+
constructor(getInputService, requiredProperties, isPropertyFulfilled, userInputProperty) {
|
|
14
|
+
super('getUserInput');
|
|
15
|
+
this.getInputService = getInputService;
|
|
16
|
+
this.requiredProperties = requiredProperties;
|
|
17
|
+
this.isPropertyFulfilled = isPropertyFulfilled;
|
|
18
|
+
this.userInputProperty = userInputProperty;
|
|
19
|
+
}
|
|
20
|
+
execute = (state) => {
|
|
21
|
+
const unfulfilledProperties = this.getUnfulfilledProperties(state);
|
|
22
|
+
const userResponse = this.getInputService.getInput(unfulfilledProperties);
|
|
23
|
+
return { [this.userInputProperty]: userResponse };
|
|
24
|
+
};
|
|
25
|
+
getUnfulfilledProperties(state) {
|
|
26
|
+
const propertyArray = [];
|
|
27
|
+
for (const [propertyName, metadata] of Object.entries(this.requiredProperties)) {
|
|
28
|
+
const fulfillmentResult = this.isPropertyFulfilled(state, propertyName);
|
|
29
|
+
if (!fulfillmentResult.isFulfilled) {
|
|
30
|
+
propertyArray.push({
|
|
31
|
+
propertyName,
|
|
32
|
+
friendlyName: metadata.friendlyName,
|
|
33
|
+
description: metadata.description,
|
|
34
|
+
reason: fulfillmentResult.reason,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return propertyArray;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/nodes/getUserInput/node.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAkElD,MAAM,OAAO,gBAA4D,SAAQ,QAAgB;IAE5E;IACA;IACA;IACA;IAJnB,YACmB,eAAwC,EACxC,kBAA8C,EAC9C,mBAAgD,EAChD,iBAA+B;QAEhD,KAAK,CAAC,cAAc,CAAC,CAAC;QALL,oBAAe,GAAf,eAAe,CAAyB;QACxC,uBAAkB,GAAlB,kBAAkB,CAA4B;QAC9C,wBAAmB,GAAnB,mBAAmB,CAA6B;QAChD,sBAAiB,GAAjB,iBAAiB,CAAc;IAGlD,CAAC;IAED,OAAO,GAAG,CAAC,KAAa,EAAmB,EAAE;QAC3C,MAAM,qBAAqB,GAAG,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;QACnE,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;QAC1E,OAAO,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE,YAAY,EAAgC,CAAC;IAClF,CAAC,CAAC;IAEM,wBAAwB,CAAC,KAAa;QAC5C,MAAM,aAAa,GAAuB,EAAE,CAAC;QAC7C,KAAK,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CACnD,IAAI,CAAC,kBAAgD,CACtD,EAAE,CAAC;YACF,MAAM,iBAAiB,GAAG,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YAExE,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAC;gBACnC,aAAa,CAAC,IAAI,CAAC;oBACjB,YAAY;oBACZ,YAAY,EAAE,QAAQ,CAAC,YAAY;oBACnC,WAAW,EAAE,QAAQ,CAAC,WAAW;oBACjC,MAAM,EAAE,iBAAiB,CAAC,MAAM;iBACjC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { BaseNode } from './abstractBaseNode.js';
|
|
2
|
+
export { AbstractToolNode } from './abstractToolNode.js';
|
|
3
|
+
export { type ToolExecutor, LangGraphToolExecutor } from './toolExecutor.js';
|
|
4
|
+
export * from './getUserInput/index.js';
|
|
5
|
+
export * from './userInputExtraction/index.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
|
+
*/
|
|
7
|
+
export { BaseNode } from './abstractBaseNode.js';
|
|
8
|
+
export { AbstractToolNode } from './abstractToolNode.js';
|
|
9
|
+
export { LangGraphToolExecutor } from './toolExecutor.js';
|
|
10
|
+
export * from './getUserInput/index.js';
|
|
11
|
+
export * from './userInputExtraction/index.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nodes/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAqB,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import { MCPToolInvocationData } from '../common/metadata.js';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for tool execution mechanism.
|
|
5
|
+
* Abstracts the LangGraph interrupt mechanism to enable dependency injection and testing.
|
|
6
|
+
*/
|
|
7
|
+
export interface ToolExecutor {
|
|
8
|
+
/**
|
|
9
|
+
* Executes a tool by invoking the underlying mechanism (e.g., LangGraph interrupt).
|
|
10
|
+
*
|
|
11
|
+
* @param toolInvocationData The tool invocation data to pass to the execution mechanism
|
|
12
|
+
* @returns The result from the tool execution (as unknown, to be validated by caller)
|
|
13
|
+
*/
|
|
14
|
+
execute(toolInvocationData: MCPToolInvocationData<z.ZodObject<z.ZodRawShape>>): unknown;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Production implementation of ToolExecutor that uses LangGraph's interrupt mechanism.
|
|
18
|
+
* This is the default implementation used in production workflows.
|
|
19
|
+
*/
|
|
20
|
+
export declare class LangGraphToolExecutor implements ToolExecutor {
|
|
21
|
+
execute(toolInvocationData: MCPToolInvocationData<z.ZodObject<z.ZodRawShape>>): unknown;
|
|
22
|
+
}
|