@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.
Files changed (134) hide show
  1. package/README.md +168 -0
  2. package/dist/checkpointing/index.d.ts +3 -0
  3. package/dist/checkpointing/index.js +10 -0
  4. package/dist/checkpointing/index.js.map +1 -0
  5. package/dist/checkpointing/jsonCheckpointer.d.ts +19 -0
  6. package/dist/checkpointing/jsonCheckpointer.js +164 -0
  7. package/dist/checkpointing/jsonCheckpointer.js.map +1 -0
  8. package/dist/checkpointing/statePersistence.d.ts +26 -0
  9. package/dist/checkpointing/statePersistence.js +117 -0
  10. package/dist/checkpointing/statePersistence.js.map +1 -0
  11. package/dist/checkpointing/workflowStateManager.d.ts +99 -0
  12. package/dist/checkpointing/workflowStateManager.js +206 -0
  13. package/dist/checkpointing/workflowStateManager.js.map +1 -0
  14. package/dist/common/fileSystem.d.ts +113 -0
  15. package/dist/common/fileSystem.js +62 -0
  16. package/dist/common/fileSystem.js.map +1 -0
  17. package/dist/common/metadata.d.ts +93 -0
  18. package/dist/common/metadata.js +40 -0
  19. package/dist/common/metadata.js.map +1 -0
  20. package/dist/common/propertyMetadata.d.ts +58 -0
  21. package/dist/common/propertyMetadata.js +8 -0
  22. package/dist/common/propertyMetadata.js.map +1 -0
  23. package/dist/common/types.d.ts +16 -0
  24. package/dist/common/types.js +8 -0
  25. package/dist/common/types.js.map +1 -0
  26. package/dist/index.d.ts +15 -0
  27. package/dist/index.js +37 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/logging/logger.d.ts +56 -0
  30. package/dist/logging/logger.js +113 -0
  31. package/dist/logging/logger.js.map +1 -0
  32. package/dist/nodes/abstractBaseNode.d.ts +27 -0
  33. package/dist/nodes/abstractBaseNode.js +34 -0
  34. package/dist/nodes/abstractBaseNode.js.map +1 -0
  35. package/dist/nodes/abstractToolNode.d.ts +32 -0
  36. package/dist/nodes/abstractToolNode.js +44 -0
  37. package/dist/nodes/abstractToolNode.js.map +1 -0
  38. package/dist/nodes/getUserInput/factory.d.ts +42 -0
  39. package/dist/nodes/getUserInput/factory.js +64 -0
  40. package/dist/nodes/getUserInput/factory.js.map +1 -0
  41. package/dist/nodes/getUserInput/index.d.ts +2 -0
  42. package/dist/nodes/getUserInput/index.js +3 -0
  43. package/dist/nodes/getUserInput/index.js.map +1 -0
  44. package/dist/nodes/getUserInput/node.d.ts +68 -0
  45. package/dist/nodes/getUserInput/node.js +41 -0
  46. package/dist/nodes/getUserInput/node.js.map +1 -0
  47. package/dist/nodes/index.d.ts +5 -0
  48. package/dist/nodes/index.js +12 -0
  49. package/dist/nodes/index.js.map +1 -0
  50. package/dist/nodes/toolExecutor.d.ts +22 -0
  51. package/dist/nodes/toolExecutor.js +19 -0
  52. package/dist/nodes/toolExecutor.js.map +1 -0
  53. package/dist/nodes/userInputExtraction/factory.d.ts +42 -0
  54. package/dist/nodes/userInputExtraction/factory.js +55 -0
  55. package/dist/nodes/userInputExtraction/factory.js.map +1 -0
  56. package/dist/nodes/userInputExtraction/index.d.ts +2 -0
  57. package/dist/nodes/userInputExtraction/index.js +3 -0
  58. package/dist/nodes/userInputExtraction/index.js.map +1 -0
  59. package/dist/nodes/userInputExtraction/node.d.ts +60 -0
  60. package/dist/nodes/userInputExtraction/node.js +24 -0
  61. package/dist/nodes/userInputExtraction/node.js.map +1 -0
  62. package/dist/routers/checkPropertiesFulfilledRouter.d.ts +74 -0
  63. package/dist/routers/checkPropertiesFulfilledRouter.js +106 -0
  64. package/dist/routers/checkPropertiesFulfilledRouter.js.map +1 -0
  65. package/dist/routers/index.d.ts +1 -0
  66. package/dist/routers/index.js +8 -0
  67. package/dist/routers/index.js.map +1 -0
  68. package/dist/services/abstractService.d.ts +71 -0
  69. package/dist/services/abstractService.js +83 -0
  70. package/dist/services/abstractService.js.map +1 -0
  71. package/dist/services/getInputService.d.ts +43 -0
  72. package/dist/services/getInputService.js +48 -0
  73. package/dist/services/getInputService.js.map +1 -0
  74. package/dist/services/index.d.ts +3 -0
  75. package/dist/services/index.js +10 -0
  76. package/dist/services/index.js.map +1 -0
  77. package/dist/services/inputExtractionService.d.ts +46 -0
  78. package/dist/services/inputExtractionService.js +133 -0
  79. package/dist/services/inputExtractionService.js.map +1 -0
  80. package/dist/storage/wellKnownDirectory.d.ts +79 -0
  81. package/dist/storage/wellKnownDirectory.js +121 -0
  82. package/dist/storage/wellKnownDirectory.js.map +1 -0
  83. package/dist/tools/base/abstractTool.d.ts +61 -0
  84. package/dist/tools/base/abstractTool.js +87 -0
  85. package/dist/tools/base/abstractTool.js.map +1 -0
  86. package/dist/tools/base/abstractWorkflowTool.d.ts +34 -0
  87. package/dist/tools/base/abstractWorkflowTool.js +94 -0
  88. package/dist/tools/base/abstractWorkflowTool.js.map +1 -0
  89. package/dist/tools/base/index.d.ts +2 -0
  90. package/dist/tools/base/index.js +9 -0
  91. package/dist/tools/base/index.js.map +1 -0
  92. package/dist/tools/orchestrator/config.d.ts +55 -0
  93. package/dist/tools/orchestrator/config.js +8 -0
  94. package/dist/tools/orchestrator/config.js.map +1 -0
  95. package/dist/tools/orchestrator/index.d.ts +3 -0
  96. package/dist/tools/orchestrator/index.js +9 -0
  97. package/dist/tools/orchestrator/index.js.map +1 -0
  98. package/dist/tools/orchestrator/metadata.d.ts +55 -0
  99. package/dist/tools/orchestrator/metadata.js +49 -0
  100. package/dist/tools/orchestrator/metadata.js.map +1 -0
  101. package/dist/tools/orchestrator/orchestratorTool.d.ts +39 -0
  102. package/dist/tools/orchestrator/orchestratorTool.js +186 -0
  103. package/dist/tools/orchestrator/orchestratorTool.js.map +1 -0
  104. package/dist/tools/utilities/getInput/factory.d.ts +43 -0
  105. package/dist/tools/utilities/getInput/factory.js +32 -0
  106. package/dist/tools/utilities/getInput/factory.js.map +1 -0
  107. package/dist/tools/utilities/getInput/index.d.ts +3 -0
  108. package/dist/tools/utilities/getInput/index.js +10 -0
  109. package/dist/tools/utilities/getInput/index.js.map +1 -0
  110. package/dist/tools/utilities/getInput/metadata.d.ts +78 -0
  111. package/dist/tools/utilities/getInput/metadata.js +43 -0
  112. package/dist/tools/utilities/getInput/metadata.js.map +1 -0
  113. package/dist/tools/utilities/getInput/tool.d.ts +89 -0
  114. package/dist/tools/utilities/getInput/tool.js +69 -0
  115. package/dist/tools/utilities/getInput/tool.js.map +1 -0
  116. package/dist/tools/utilities/index.d.ts +2 -0
  117. package/dist/tools/utilities/index.js +9 -0
  118. package/dist/tools/utilities/index.js.map +1 -0
  119. package/dist/tools/utilities/inputExtraction/factory.d.ts +43 -0
  120. package/dist/tools/utilities/inputExtraction/factory.js +32 -0
  121. package/dist/tools/utilities/inputExtraction/factory.js.map +1 -0
  122. package/dist/tools/utilities/inputExtraction/index.d.ts +3 -0
  123. package/dist/tools/utilities/inputExtraction/index.js +10 -0
  124. package/dist/tools/utilities/inputExtraction/index.js.map +1 -0
  125. package/dist/tools/utilities/inputExtraction/metadata.d.ts +66 -0
  126. package/dist/tools/utilities/inputExtraction/metadata.js +52 -0
  127. package/dist/tools/utilities/inputExtraction/metadata.js.map +1 -0
  128. package/dist/tools/utilities/inputExtraction/tool.d.ts +82 -0
  129. package/dist/tools/utilities/inputExtraction/tool.js +71 -0
  130. package/dist/tools/utilities/inputExtraction/tool.js.map +1 -0
  131. package/dist/utils/toolExecutionUtils.d.ts +55 -0
  132. package/dist/utils/toolExecutionUtils.js +70 -0
  133. package/dist/utils/toolExecutionUtils.js.map +1 -0
  134. package/package.json +42 -0
@@ -0,0 +1,48 @@
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 { AbstractService } from './abstractService.js';
8
+ import { createGetInputMetadata, GET_INPUT_WORKFLOW_RESULT_SCHEMA, } from '../tools/utilities/index.js';
9
+ /**
10
+ * Service for getting user input for a given question.
11
+ *
12
+ * This service extends AbstractService to leverage common tool execution
13
+ * patterns including standardized logging and result validation.
14
+ */
15
+ export class GetInputService extends AbstractService {
16
+ toolId;
17
+ /**
18
+ * Creates a new GetInputService.
19
+ *
20
+ * @param toolExecutor - Tool executor for invoking the input tool (injectable for testing)
21
+ * @param logger - Logger instance (injectable for testing)
22
+ */
23
+ constructor(toolId, toolExecutor, logger) {
24
+ super('GetInputService', toolExecutor, logger);
25
+ this.toolId = toolId;
26
+ }
27
+ getInput(unfulfilledProperties) {
28
+ this.logger.debug('Starting input request with properties', {
29
+ unfulfilledProperties,
30
+ });
31
+ const metadata = createGetInputMetadata(this.toolId);
32
+ // Create tool invocation data
33
+ const toolInvocationData = {
34
+ llmMetadata: {
35
+ name: metadata.toolId,
36
+ description: metadata.description,
37
+ inputSchema: metadata.inputSchema,
38
+ },
39
+ input: {
40
+ propertiesRequiringInput: unfulfilledProperties,
41
+ },
42
+ };
43
+ // Execute tool with logging and validation
44
+ const validatedResult = this.executeToolWithLogging(toolInvocationData, GET_INPUT_WORKFLOW_RESULT_SCHEMA);
45
+ return validatedResult.userUtterance;
46
+ }
47
+ }
48
+ //# sourceMappingURL=getInputService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getInputService.js","sourceRoot":"","sources":["../../src/services/getInputService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,sBAAsB,EAEtB,gCAAgC,GACjC,MAAM,6BAA6B,CAAC;AAgCrC;;;;;GAKG;AACH,MAAM,OAAO,eAAgB,SAAQ,eAAe;IAQ/B;IAPnB;;;;;OAKG;IACH,YACmB,MAAc,EAC/B,YAA2B,EAC3B,MAAe;QAEf,KAAK,CAAC,iBAAiB,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;QAJ9B,WAAM,GAAN,MAAM,CAAQ;IAKjC,CAAC;IAED,QAAQ,CAAC,qBAAyC;QAChD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wCAAwC,EAAE;YAC1D,qBAAqB;SACtB,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrD,8BAA8B;QAC9B,MAAM,kBAAkB,GAAkE;YACxF,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ,CAAC,MAAM;gBACrB,WAAW,EAAE,QAAQ,CAAC,WAAW;gBACjC,WAAW,EAAE,QAAQ,CAAC,WAAW;aAClC;YACD,KAAK,EAAE;gBACL,wBAAwB,EAAE,qBAAqB;aAChD;SACF,CAAC;QAEF,2CAA2C;QAC3C,MAAM,eAAe,GAAG,IAAI,CAAC,sBAAsB,CACjD,kBAAkB,EAClB,gCAAgC,CACjC,CAAC;QAEF,OAAO,eAAe,CAAC,aAAa,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export { AbstractService } from './abstractService.js';
2
+ export { InputExtractionService, InputExtractionServiceProvider, ExtractionResult, } from './inputExtractionService.js';
3
+ export { GetInputService, GetInputServiceProvider, GetInputProperty } from './getInputService.js';
@@ -0,0 +1,10 @@
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 { AbstractService } from './abstractService.js';
8
+ export { InputExtractionService, } from './inputExtractionService.js';
9
+ export { GetInputService } from './getInputService.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,sBAAsB,GAGvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAA6C,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { ToolExecutor } from '../nodes/toolExecutor.js';
2
+ import { AbstractService } from './abstractService.js';
3
+ import { PropertyMetadataCollection } from '../common/propertyMetadata.js';
4
+ import { Logger } from '../logging/logger.js';
5
+ /**
6
+ * Result from property extraction containing validated properties.
7
+ */
8
+ export interface ExtractionResult {
9
+ /** Record of extracted properties, keyed by property name */
10
+ extractedProperties: Record<string, unknown>;
11
+ }
12
+ /**
13
+ * Provider interface for property extraction service.
14
+ * This interface allows for dependency injection and testing.
15
+ */
16
+ export interface InputExtractionServiceProvider {
17
+ /**
18
+ * Extracts structured properties from user input.
19
+ *
20
+ * @param userInput - Raw user input (string, object, or any format)
21
+ * @param properties - Collection of properties to extract with their metadata
22
+ * @returns ExtractionResult containing validated extracted properties
23
+ */
24
+ extractProperties(userInput: unknown, properties: PropertyMetadataCollection): ExtractionResult;
25
+ }
26
+ /**
27
+ * Service for extracting structured properties from user input.
28
+ *
29
+ * This service extends AbstractService to leverage common tool execution
30
+ * patterns including standardized logging and result validation.
31
+ */
32
+ export declare class InputExtractionService extends AbstractService implements InputExtractionServiceProvider {
33
+ private readonly toolId;
34
+ /**
35
+ * Creates a new InputExtractionService.
36
+ *
37
+ * @param toolId - Tool ID for the input extraction tool
38
+ * @param toolExecutor - Tool executor for invoking the extraction tool (injectable for testing)
39
+ * @param logger - Logger instance (injectable for testing)
40
+ */
41
+ constructor(toolId: string, toolExecutor?: ToolExecutor, logger?: Logger);
42
+ extractProperties(userInput: unknown, properties: PropertyMetadataCollection): ExtractionResult;
43
+ private preparePropertiesForExtraction;
44
+ private preparePropertyResultsSchema;
45
+ private validateAndFilterResult;
46
+ }
@@ -0,0 +1,133 @@
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 z from 'zod';
8
+ import { zodToJsonSchema } from 'zod-to-json-schema';
9
+ import { AbstractService } from './abstractService.js';
10
+ import { createInputExtractionMetadata, } from '../tools/utilities/index.js';
11
+ /**
12
+ * Service for extracting structured properties from user input.
13
+ *
14
+ * This service extends AbstractService to leverage common tool execution
15
+ * patterns including standardized logging and result validation.
16
+ */
17
+ export class InputExtractionService extends AbstractService {
18
+ toolId;
19
+ /**
20
+ * Creates a new InputExtractionService.
21
+ *
22
+ * @param toolId - Tool ID for the input extraction tool
23
+ * @param toolExecutor - Tool executor for invoking the extraction tool (injectable for testing)
24
+ * @param logger - Logger instance (injectable for testing)
25
+ */
26
+ constructor(toolId, toolExecutor, logger) {
27
+ super('InputExtractionService', toolExecutor, logger);
28
+ this.toolId = toolId;
29
+ }
30
+ extractProperties(userInput, properties) {
31
+ this.logger.debug('Starting property extraction', {
32
+ userInput,
33
+ propertyCount: Object.keys(properties).length,
34
+ });
35
+ const propertiesToExtract = this.preparePropertiesForExtraction(properties);
36
+ const resultSchema = this.preparePropertyResultsSchema(properties);
37
+ const resultSchemaString = JSON.stringify(zodToJsonSchema(resultSchema));
38
+ const metadata = createInputExtractionMetadata(this.toolId);
39
+ const toolInvocationData = {
40
+ llmMetadata: {
41
+ name: metadata.toolId,
42
+ description: metadata.description,
43
+ inputSchema: metadata.inputSchema,
44
+ },
45
+ input: {
46
+ userUtterance: userInput,
47
+ propertiesToExtract,
48
+ resultSchema: resultSchemaString,
49
+ },
50
+ };
51
+ const validatedResult = this.executeToolWithLogging(toolInvocationData, resultSchema, (rawResult, schema) => this.validateAndFilterResult(rawResult, properties, schema));
52
+ this.logger.info('Property extraction completed', {
53
+ extractedCount: Object.keys(validatedResult.extractedProperties).length,
54
+ properties: Object.keys(validatedResult.extractedProperties),
55
+ });
56
+ return validatedResult;
57
+ }
58
+ preparePropertiesForExtraction(properties) {
59
+ const propertiesToExtract = [];
60
+ for (const [propertyName, metadata] of Object.entries(properties)) {
61
+ propertiesToExtract.push({
62
+ propertyName,
63
+ description: metadata.description,
64
+ });
65
+ }
66
+ this.logger.debug('Prepared properties for extraction', {
67
+ count: propertiesToExtract.length,
68
+ properties: propertiesToExtract.map(p => p.propertyName),
69
+ });
70
+ return propertiesToExtract;
71
+ }
72
+ preparePropertyResultsSchema(properties) {
73
+ const extractedPropertiesShape = {};
74
+ for (const [propertyName, metadata] of Object.entries(properties)) {
75
+ extractedPropertiesShape[propertyName] = metadata.zodType
76
+ .describe(metadata.description)
77
+ .nullable()
78
+ .catch((ctx) => ctx.input);
79
+ }
80
+ return z.object({ extractedProperties: z.object(extractedPropertiesShape).passthrough() });
81
+ }
82
+ validateAndFilterResult(rawResult, properties, resultSchema) {
83
+ const structureValidated = resultSchema.parse(rawResult);
84
+ const { extractedProperties } = structureValidated;
85
+ this.logger.debug('Validating extracted properties', {
86
+ extractedProperties,
87
+ });
88
+ const validatedProperties = {};
89
+ const invalidProperties = [];
90
+ for (const [propertyName, propertyValue] of Object.entries(extractedProperties)) {
91
+ if (propertyValue == null) {
92
+ this.logger.debug(`Skipping property with null/undefined value`, { propertyName });
93
+ continue;
94
+ }
95
+ const propertyMetadata = properties[propertyName];
96
+ if (!propertyMetadata) {
97
+ this.logger.warn(`Unknown property in extraction result`, { propertyName });
98
+ continue;
99
+ }
100
+ try {
101
+ const validatedValue = propertyMetadata.zodType.parse(propertyValue);
102
+ validatedProperties[propertyName] = validatedValue;
103
+ this.logger.debug(`Property validated successfully`, {
104
+ propertyName,
105
+ value: validatedValue,
106
+ });
107
+ }
108
+ catch (error) {
109
+ invalidProperties.push(propertyName);
110
+ if (error instanceof z.ZodError) {
111
+ this.logger.debug(`Property validation failed`, {
112
+ propertyName,
113
+ value: propertyValue,
114
+ errors: error.errors,
115
+ });
116
+ }
117
+ else {
118
+ const errorMsg = error instanceof Error ? error.message : String(error);
119
+ this.logger.error(`Unexpected validation error for ${propertyName}: ${errorMsg}`);
120
+ throw error;
121
+ }
122
+ }
123
+ }
124
+ if (invalidProperties.length > 0) {
125
+ this.logger.info(`Some properties failed validation`, {
126
+ invalidProperties,
127
+ validCount: Object.keys(validatedProperties).length,
128
+ });
129
+ }
130
+ return { extractedProperties: validatedProperties };
131
+ }
132
+ }
133
+ //# sourceMappingURL=inputExtractionService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputExtractionService.js","sourceRoot":"","sources":["../../src/services/inputExtractionService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EACL,6BAA6B,GAE9B,MAAM,6BAA6B,CAAC;AA2BrC;;;;;GAKG;AACH,MAAM,OAAO,sBACX,SAAQ,eAAe;IAWJ;IARnB;;;;;;OAMG;IACH,YACmB,MAAc,EAC/B,YAA2B,EAC3B,MAAe;QAEf,KAAK,CAAC,wBAAwB,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;QAJrC,WAAM,GAAN,MAAM,CAAQ;IAKjC,CAAC;IAED,iBAAiB,CAAC,SAAkB,EAAE,UAAsC;QAC1E,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE;YAChD,SAAS;YACT,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM;SAC9C,CAAC,CAAC;QAEH,MAAM,mBAAmB,GAAG,IAAI,CAAC,8BAA8B,CAAC,UAAU,CAAC,CAAC;QAC5E,MAAM,YAAY,GAAG,IAAI,CAAC,4BAA4B,CAAC,UAAU,CAAC,CAAC;QACnE,MAAM,kBAAkB,GAAG,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC;QACzE,MAAM,QAAQ,GAAG,6BAA6B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE5D,MAAM,kBAAkB,GACtB;YACE,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ,CAAC,MAAM;gBACrB,WAAW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FileSystemOperations } from '../common/fileSystem.js';
2
+ /**
3
+ * Well-known directory name - hidden directory at project root
4
+ */
5
+ export declare const WELL_KNOWN_DIR_NAME = ".magen";
6
+ /**
7
+ * Well-known file names within the .magen directory
8
+ */
9
+ export declare const WELL_KNOWN_FILES: {
10
+ readonly WORKFLOW_STATE_STORE_FILENAME: "workflow-state.json";
11
+ readonly WORKFLOW_LOGS: "workflow_logs.json";
12
+ };
13
+ /**
14
+ * Configuration for WellKnownDirectoryManager
15
+ */
16
+ export interface WellKnownDirectoryConfig {
17
+ /** Optional project path override (defaults to PROJECT_PATH env var or home directory) */
18
+ projectPath?: string;
19
+ /** Optional filesystem operations implementation (defaults to NodeFileSystemOperations) */
20
+ fileSystemOperations?: FileSystemOperations;
21
+ }
22
+ /**
23
+ * Class-based well-known directory manager with dependency injection support
24
+ */
25
+ export declare class WellKnownDirectoryManager {
26
+ private readonly fileSystemOperations;
27
+ private readonly baseDirPath;
28
+ constructor(config?: WellKnownDirectoryConfig);
29
+ /**
30
+ * Get the absolute path to the .magen directory
31
+ * @returns Absolute path to .magen directory
32
+ */
33
+ getWellKnownDirectoryPath(): string;
34
+ /**
35
+ * Ensure the .magen directory exists, creating it if necessary
36
+ * Safe to call multiple times - idempotent operation
37
+ *
38
+ * @returns Absolute path to the .magen directory
39
+ */
40
+ ensureWellKnownDirectory(): string;
41
+ /**
42
+ * Get the absolute path to a specific file within the .magen directory
43
+ * Ensures the directory exists before returning the path
44
+ *
45
+ * @param fileName - Name of the file within .magen directory
46
+ * @returns Absolute path to the specified file
47
+ */
48
+ getWellKnownFilePath(fileName: string): string;
49
+ /**
50
+ * Get the path to the workflow state database
51
+ * @returns Absolute path to workflow-state.json
52
+ */
53
+ getWorkflowStateStorePath(): string;
54
+ /**
55
+ * Get the path to the workflow logs file
56
+ * @returns Absolute path to workflow_logs.json
57
+ */
58
+ getWorkflowLogsPath(): string;
59
+ /**
60
+ * Check if the .magen directory exists
61
+ * @returns true if directory exists, false otherwise
62
+ */
63
+ wellKnownDirectoryExists(): boolean;
64
+ /**
65
+ * Get information about the .magen directory and its contents
66
+ * Useful for debugging and status reporting
67
+ *
68
+ * @returns Object with directory status and file information
69
+ */
70
+ getWellKnownDirectoryInfo(): {
71
+ exists: boolean;
72
+ path: string;
73
+ files: Array<{
74
+ name: string;
75
+ exists: boolean;
76
+ path: string;
77
+ }>;
78
+ };
79
+ }
@@ -0,0 +1,121 @@
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
+ * Well-Known Directory Management
9
+ *
10
+ * Centralized management of the .magen well-known directory structure for the
11
+ * Mobile Native MCP Server. This directory contains persistent project artifacts
12
+ * including workflow state, logging, and other cross-session data.
13
+ *
14
+ * Directory structure:
15
+ * .magen/
16
+ * ├── workflow-state.db # SQLite database for LangGraph workflow persistence
17
+ * ├── workflow_logs.json # Structured JSON logs for workflow operations
18
+ * └── [future artifacts] # Additional project artifacts as needed
19
+ */
20
+ import path from 'path';
21
+ import os from 'os';
22
+ import { NodeFileSystemOperations } from '../common/fileSystem.js';
23
+ /**
24
+ * Well-known directory name - hidden directory at project root
25
+ */
26
+ export const WELL_KNOWN_DIR_NAME = '.magen';
27
+ /**
28
+ * Well-known file names within the .magen directory
29
+ */
30
+ export const WELL_KNOWN_FILES = {
31
+ WORKFLOW_STATE_STORE_FILENAME: 'workflow-state.json',
32
+ WORKFLOW_LOGS: 'workflow_logs.json',
33
+ };
34
+ /**
35
+ * Class-based well-known directory manager with dependency injection support
36
+ */
37
+ export class WellKnownDirectoryManager {
38
+ fileSystemOperations;
39
+ baseDirPath;
40
+ constructor(config = {}) {
41
+ this.fileSystemOperations = config.fileSystemOperations ?? new NodeFileSystemOperations();
42
+ const baseDir = config.projectPath
43
+ ? path.resolve(config.projectPath)
44
+ : process.env.PROJECT_PATH
45
+ ? path.resolve(process.env.PROJECT_PATH)
46
+ : os.homedir();
47
+ this.baseDirPath = path.join(baseDir, WELL_KNOWN_DIR_NAME);
48
+ }
49
+ /**
50
+ * Get the absolute path to the .magen directory
51
+ * @returns Absolute path to .magen directory
52
+ */
53
+ getWellKnownDirectoryPath() {
54
+ return this.baseDirPath;
55
+ }
56
+ /**
57
+ * Ensure the .magen directory exists, creating it if necessary
58
+ * Safe to call multiple times - idempotent operation
59
+ *
60
+ * @returns Absolute path to the .magen directory
61
+ */
62
+ ensureWellKnownDirectory() {
63
+ if (!this.fileSystemOperations.existsSync(this.baseDirPath)) {
64
+ this.fileSystemOperations.mkdirSync(this.baseDirPath, { recursive: true });
65
+ }
66
+ return this.baseDirPath;
67
+ }
68
+ /**
69
+ * Get the absolute path to a specific file within the .magen directory
70
+ * Ensures the directory exists before returning the path
71
+ *
72
+ * @param fileName - Name of the file within .magen directory
73
+ * @returns Absolute path to the specified file
74
+ */
75
+ getWellKnownFilePath(fileName) {
76
+ const wellKnownDir = this.ensureWellKnownDirectory();
77
+ return path.join(wellKnownDir, fileName);
78
+ }
79
+ /**
80
+ * Get the path to the workflow state database
81
+ * @returns Absolute path to workflow-state.json
82
+ */
83
+ getWorkflowStateStorePath() {
84
+ return this.getWellKnownFilePath(WELL_KNOWN_FILES.WORKFLOW_STATE_STORE_FILENAME);
85
+ }
86
+ /**
87
+ * Get the path to the workflow logs file
88
+ * @returns Absolute path to workflow_logs.json
89
+ */
90
+ getWorkflowLogsPath() {
91
+ return this.getWellKnownFilePath(WELL_KNOWN_FILES.WORKFLOW_LOGS);
92
+ }
93
+ /**
94
+ * Check if the .magen directory exists
95
+ * @returns true if directory exists, false otherwise
96
+ */
97
+ wellKnownDirectoryExists() {
98
+ return this.fileSystemOperations.existsSync(this.baseDirPath);
99
+ }
100
+ /**
101
+ * Get information about the .magen directory and its contents
102
+ * Useful for debugging and status reporting
103
+ *
104
+ * @returns Object with directory status and file information
105
+ */
106
+ getWellKnownDirectoryInfo() {
107
+ const dirPath = this.getWellKnownDirectoryPath();
108
+ const exists = this.wellKnownDirectoryExists();
109
+ const files = Object.values(WELL_KNOWN_FILES).map(fileName => ({
110
+ name: fileName,
111
+ exists: exists && this.fileSystemOperations.existsSync(path.join(dirPath, fileName)),
112
+ path: path.join(dirPath, fileName),
113
+ }));
114
+ return {
115
+ exists,
116
+ path: dirPath,
117
+ files,
118
+ };
119
+ }
120
+ }
121
+ //# sourceMappingURL=wellKnownDirectory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wellKnownDirectory.js","sourceRoot":"","sources":["../../src/storage/wellKnownDirectory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;GAYG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAwB,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAEzF;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,QAAQ,CAAC;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,6BAA6B,EAAE,qBAAqB;IACpD,aAAa,EAAE,oBAAoB;CAC3B,CAAC;AAYX;;GAEG;AACH,MAAM,OAAO,yBAAyB;IACnB,oBAAoB,CAAuB;IAC3C,WAAW,CAAS;IAErC,YAAY,SAAmC,EAAE;QAC/C,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,oBAAoB,IAAI,IAAI,wBAAwB,EAAE,CAAC;QAE1F,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW;YAChC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC;YAClC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY;gBACxB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;gBACxC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;QAEnB,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AC,CAAC;YAC7D,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,MAAM,IAAI,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACpF,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;SACnC,CAAC,CAAC,CAAC;QAEJ,OAAO;YACL,MAAM;YACN,IAAI,EAAE,OAAO;YACb,KAAK;SACN,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,61 @@
1
+ import { McpServer, ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';
3
+ import z from 'zod';
4
+ import { Logger } from '../../logging/logger.js';
5
+ import { ToolMetadata } from '../../common/metadata.js';
6
+ /**
7
+ * Abstract base class for ALL MCP tools in the workflow engine
8
+ *
9
+ * Provides comprehensive functionality including:
10
+ * - Server instance management
11
+ * - Logging with component identification
12
+ * - Standardized registration pattern
13
+ * - Workflow state round-tripping support
14
+ * - Post-invocation instruction patterns
15
+ * - Shared utility methods
16
+ *
17
+ * @template TMetadata - Tool metadata type extending ToolMetadata
18
+ */
19
+ export declare abstract class AbstractTool<TMetadata extends ToolMetadata<z.ZodObject<z.ZodRawShape>, z.ZodObject<z.ZodRawShape>>> {
20
+ protected readonly server: McpServer;
21
+ readonly toolMetadata: TMetadata;
22
+ protected readonly logger: Logger;
23
+ constructor(server: McpServer, toolMetadata: TMetadata, loggerComponentName?: string, logger?: Logger);
24
+ /**
25
+ * Register the tool with the MCP server
26
+ * @param annotations Tool annotations for MCP client hints
27
+ */
28
+ register(annotations: ToolAnnotations): void;
29
+ /**
30
+ * Abstract method that implementing tools must provide for handling requests
31
+ *
32
+ * Uses the same typing pattern as registerTool() ToolCallback<InputArgs>.
33
+ * @param input The input to the callback
34
+ * @returns The return result of the tool
35
+ */
36
+ abstract handleRequest: ToolCallback<TMetadata['inputSchema']['shape']>;
37
+ /**
38
+ * Logs tool registration information
39
+ * @param annotations The tool annotations
40
+ */
41
+ protected logRegistration(annotations: ToolAnnotations): void;
42
+ /**
43
+ * Logs an error that occurred during tool execution
44
+ * @param message A descriptive error message
45
+ * @param error The error object
46
+ * @param data Additional context data
47
+ */
48
+ protected logError(message: string, error: Error, data?: unknown): void;
49
+ /**
50
+ * Creates a child logger for a specific operation within the tool
51
+ * @param operationName The name of the operation
52
+ * @returns A child logger instance
53
+ */
54
+ protected createOperationLogger(operationName: string): Logger;
55
+ /**
56
+ * Logs workflow-specific events with enhanced context
57
+ * @param event The workflow event description
58
+ * @param data Additional workflow context data
59
+ */
60
+ protected logWorkflowEvent(event: string, data?: Record<string, unknown>): void;
61
+ }
@@ -0,0 +1,87 @@
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 { createComponentLogger } from '../../logging/logger.js';
8
+ /**
9
+ * Abstract base class for ALL MCP tools in the workflow engine
10
+ *
11
+ * Provides comprehensive functionality including:
12
+ * - Server instance management
13
+ * - Logging with component identification
14
+ * - Standardized registration pattern
15
+ * - Workflow state round-tripping support
16
+ * - Post-invocation instruction patterns
17
+ * - Shared utility methods
18
+ *
19
+ * @template TMetadata - Tool metadata type extending ToolMetadata
20
+ */
21
+ export class AbstractTool {
22
+ server;
23
+ toolMetadata;
24
+ logger;
25
+ constructor(server, toolMetadata, loggerComponentName, logger) {
26
+ this.server = server;
27
+ this.toolMetadata = toolMetadata;
28
+ this.logger = logger || createComponentLogger(loggerComponentName || this.constructor.name);
29
+ }
30
+ /**
31
+ * Register the tool with the MCP server
32
+ * @param annotations Tool annotations for MCP client hints
33
+ */
34
+ register(annotations) {
35
+ this.logRegistration(annotations);
36
+ const enhancedAnnotations = {
37
+ ...annotations,
38
+ title: this.toolMetadata.title,
39
+ };
40
+ this.server.registerTool(this.toolMetadata.toolId, {
41
+ description: this.toolMetadata.description,
42
+ inputSchema: this.toolMetadata.inputSchema.shape,
43
+ outputSchema: this.toolMetadata.outputSchema.shape,
44
+ ...enhancedAnnotations,
45
+ }, this.handleRequest);
46
+ }
47
+ /**
48
+ * Logs tool registration information
49
+ * @param annotations The tool annotations
50
+ */
51
+ logRegistration(annotations) {
52
+ this.logger.info(`Registering MCP tool: ${this.toolMetadata.toolId}`, { annotations });
53
+ }
54
+ /**
55
+ * Logs an error that occurred during tool execution
56
+ * @param message A descriptive error message
57
+ * @param error The error object
58
+ * @param data Additional context data
59
+ */
60
+ logError(message, error, data) {
61
+ this.logger.error(message, error);
62
+ if (data) {
63
+ this.logger.debug('Error context data', data);
64
+ }
65
+ }
66
+ /**
67
+ * Creates a child logger for a specific operation within the tool
68
+ * @param operationName The name of the operation
69
+ * @returns A child logger instance
70
+ */
71
+ createOperationLogger(operationName) {
72
+ return this.logger.child({ operation: operationName });
73
+ }
74
+ /**
75
+ * Logs workflow-specific events with enhanced context
76
+ * @param event The workflow event description
77
+ * @param data Additional workflow context data
78
+ */
79
+ logWorkflowEvent(event, data) {
80
+ this.logger.info(event, {
81
+ ...(data || {}),
82
+ workflowTool: true,
83
+ toolId: this.toolMetadata.toolId,
84
+ });
85
+ }
86
+ }
87
+ //# sourceMappingURL=abstractTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstractTool.js","sourceRoot":"","sources":["../../../src/tools/base/abstractTool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAAU,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGxE;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,YAAY;IAMX;IACH;IAJC,MAAM,CAAS;IAElC,YACqB,MAAiB,EACpB,YAAuB,EACvC,mBAA4B,EAC5B,MAAe;QAHI,WAAM,GAAN,MAAM,CAAW;QACpB,iBAAY,GAAZ,YAAY,CAAW;QAIvC,IAAI,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gB,CAAC,KAAa,EAAE,IAA8B;QACtE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE;YACtB,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;YACf,YAAY,EAAE,IAAI;YAClB,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM;SACjC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,34 @@
1
+ import z from 'zod';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
4
+ import { AbstractTool } from './abstractTool.js';
5
+ import { MCP_WORKFLOW_TOOL_OUTPUT_SCHEMA, WORKFLOW_TOOL_BASE_INPUT_SCHEMA, WorkflowStateData, WorkflowToolMetadata } from '../../common/metadata.js';
6
+ import { Logger } from '../../logging/logger.js';
7
+ /**
8
+ * Abstract base class for all workflow-participating tools.
9
+ *
10
+ * Workflow tools return guidance prompts that instruct the LLM to invoke the
11
+ * orchestrator tool next, along with the necessary workflow state data.
12
+ *
13
+ * The orchestrator tool itself extends AbstractTool directly, as it controls
14
+ * the workflow rather than participating in it.
15
+ */
16
+ export declare abstract class AbstractWorkflowTool<TMetadata extends WorkflowToolMetadata<typeof WORKFLOW_TOOL_BASE_INPUT_SCHEMA, z.ZodObject<z.ZodRawShape>, typeof MCP_WORKFLOW_TOOL_OUTPUT_SCHEMA>> extends AbstractTool<TMetadata> {
17
+ protected readonly orchestratorToolId: string;
18
+ constructor(server: McpServer, toolMetadata: TMetadata, orchestratorToolId: string, // ID of the orchestrator managing this workflow
19
+ loggerComponentName?: string, logger?: Logger);
20
+ /**
21
+ * Utility method for tools to add post-invocation instructions
22
+ * that guide the LLM back to the orchestrator for workflow continuation.
23
+ *
24
+ * This does NOT invoke the orchestrator - it creates guidance prompts that
25
+ * instruct the LLM to invoke the orchestrator tool next.
26
+ *
27
+ * @param prompt The main tool response prompt
28
+ * @param workflowStateData Workflow state data to round-trip back to orchestrator
29
+ * @param resultSchema The optional result schema to format the LLM's output.
30
+ * If not provided, uses the tool's default result schema.
31
+ * @returns Complete prompt with post-invocation instructions
32
+ */
33
+ protected finalizeWorkflowToolOutput(prompt: string, workflowStateData: WorkflowStateData, resultSchema?: TMetadata['resultSchema'] | string): CallToolResult;
34
+ }