@minded-ai/mindedjs 1.0.62-patch3 → 1.0.62-patch4
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/dist/cli/index.js +24 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/lambdaHandlerTemplate.ts +46 -0
- package/package.json +3 -2
- package/src/cli/index.ts +26 -6
package/dist/cli/index.js
CHANGED
|
@@ -38,7 +38,6 @@ const fs = __importStar(require("fs"));
|
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const logger_1 = require("../utils/logger");
|
|
40
40
|
const ENV_FILE = '.env';
|
|
41
|
-
const MODULE_PATH_PLACEHOLDER = '{MODULE_PATH}';
|
|
42
41
|
function getEnvFilePath() {
|
|
43
42
|
return path.join(process.cwd(), ENV_FILE);
|
|
44
43
|
}
|
|
@@ -95,10 +94,30 @@ function generateLambdaHandler() {
|
|
|
95
94
|
// Remove .ts or .js extension if present and convert to relative path
|
|
96
95
|
const modulePath = agentPath.replace(/\.(ts|js)$/, '');
|
|
97
96
|
// Get the path to the template file
|
|
98
|
-
|
|
97
|
+
// Try multiple locations to support both development and npm package scenarios
|
|
98
|
+
const templatePaths = [
|
|
99
|
+
path.join(__dirname, 'lambdaHandlerTemplate.ts'), // For npm package
|
|
100
|
+
path.join(__dirname, '..', '..', 'src', 'cli', 'lambdaHandlerTemplate.ts'), // For development
|
|
101
|
+
];
|
|
102
|
+
let templateContent = null;
|
|
103
|
+
// Try each path until we find the template
|
|
104
|
+
for (const templatePath of templatePaths) {
|
|
105
|
+
try {
|
|
106
|
+
if (fs.existsSync(templatePath)) {
|
|
107
|
+
templateContent = fs.readFileSync(templatePath, 'utf8');
|
|
108
|
+
logger_1.logger.debug(`Found template at ${templatePath}`);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
// Continue to next path
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!templateContent) {
|
|
117
|
+
logger_1.logger.error('Could not find Lambda handler template file');
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
99
120
|
try {
|
|
100
|
-
// Read the template file
|
|
101
|
-
let templateContent = fs.readFileSync(templatePath, 'utf8');
|
|
102
121
|
// Replace the placeholder with the actual module path
|
|
103
122
|
// Using a string literal here to make sure we match exactly what's in the template
|
|
104
123
|
templateContent = templateContent.replace(/const modulePath = '{MODULE_PATH}';/, `const modulePath = '${modulePath}';`);
|
|
@@ -127,7 +146,7 @@ function main() {
|
|
|
127
146
|
generateLambdaHandler();
|
|
128
147
|
}
|
|
129
148
|
else {
|
|
130
|
-
logger_1.logger.error('Unknown command. Available commands: token, generate-lambda-handler');
|
|
149
|
+
logger_1.logger.error('Unknown command. Available commands: token, generate-lambda-ts-handler');
|
|
131
150
|
process.exit(1);
|
|
132
151
|
}
|
|
133
152
|
}
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,uCAAyB;AACzB,2CAA6B;AAC7B,4CAAyC;AAEzC,MAAM,QAAQ,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,uCAAyB;AACzB,2CAA6B;AAC7B,4CAAyC;AAEzC,MAAM,QAAQ,GAAG,MAAM,CAAC;AAExB,SAAS,cAAc;IACrB,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,QAAQ,CAAC,KAAa;IAC7B,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,MAAM,SAAS,GAAG,2BAA2B,KAA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B,CAAC,CAAC;YACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QACD,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;SAAM,IAAI,OAAO,KAAK,4BAA4B,EAAE,CAAC;QACpD,qBAAqB,EAAE,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,eAAM,CAAC,KAAK,CAAC,wEAAwE,CAAC,CAAC;QACvF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// This is the template for the Lambda handler
|
|
2
|
+
// The {MODULE_PATH} placeholder will be replaced with the actual path
|
|
3
|
+
|
|
4
|
+
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
|
5
|
+
|
|
6
|
+
export const handler = async (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
|
|
7
|
+
const modulePath = '{MODULE_PATH}'; // Agent path from minded.json
|
|
8
|
+
const resolvedPath = require.resolve(modulePath);
|
|
9
|
+
delete require.cache[resolvedPath];
|
|
10
|
+
const agent = require(modulePath).default;
|
|
11
|
+
const { agentFunctionName, agentFunctionBody } = event.body ? JSON.parse(event.body) : event;
|
|
12
|
+
|
|
13
|
+
if (!agent[agentFunctionName]) {
|
|
14
|
+
throw new Error('Unknown agentFunctionName: ' + agentFunctionName);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const response = await agent[agentFunctionName](agentFunctionBody);
|
|
18
|
+
|
|
19
|
+
// Safely stringify the response. If it fails (e.g., due to circular refs
|
|
20
|
+
// or non-serialisable class instances), fall back to null.
|
|
21
|
+
let responseBody = null;
|
|
22
|
+
try {
|
|
23
|
+
JSON.stringify(response);
|
|
24
|
+
responseBody = response;
|
|
25
|
+
} catch (_) {
|
|
26
|
+
// ignored - responseBody stays null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (agentFunctionName === 'startVoiceSession') {
|
|
30
|
+
const wait = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
31
|
+
while (context.getRemainingTimeInMillis() > 1000) {
|
|
32
|
+
console.log('Lambda remaining time in seconds: ', context.getRemainingTimeInMillis() / 1000);
|
|
33
|
+
await wait(1000); // sleep 1 s
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
statusCode: 200,
|
|
39
|
+
headers: {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
'Access-Control-Allow-Origin': '*',
|
|
42
|
+
'Access-Control-Allow-Credentials': true,
|
|
43
|
+
},
|
|
44
|
+
body: JSON.stringify(responseBody),
|
|
45
|
+
};
|
|
46
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minded-ai/mindedjs",
|
|
3
|
-
"version": "1.0.62-
|
|
3
|
+
"version": "1.0.62-patch4",
|
|
4
4
|
"description": "MindedJS is a TypeScript library for building agents.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"src"
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "tsc",
|
|
15
|
+
"build": "tsc && npm run copy-templates",
|
|
16
|
+
"copy-templates": "cp -r src/cli/lambdaHandlerTemplate.ts dist/cli/",
|
|
16
17
|
"watch": "tsc -w",
|
|
17
18
|
"test": "NODE_ENV=test mocha --parallel --jobs auto --retries 1 -r ts-node/register -r ./test/setup.ts \"test/**/*.test.ts\"",
|
|
18
19
|
"testFile": "NODE_ENV=test mocha -r ts-node/register -r ./test/setup.ts",
|
package/src/cli/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ import * as path from 'path';
|
|
|
5
5
|
import { logger } from '../utils/logger';
|
|
6
6
|
|
|
7
7
|
const ENV_FILE = '.env';
|
|
8
|
-
const MODULE_PATH_PLACEHOLDER = '{MODULE_PATH}';
|
|
9
8
|
|
|
10
9
|
function getEnvFilePath(): string {
|
|
11
10
|
return path.join(process.cwd(), ENV_FILE);
|
|
@@ -69,12 +68,33 @@ function generateLambdaHandler(): void {
|
|
|
69
68
|
const modulePath = agentPath.replace(/\.(ts|js)$/, '');
|
|
70
69
|
|
|
71
70
|
// Get the path to the template file
|
|
72
|
-
|
|
71
|
+
// Try multiple locations to support both development and npm package scenarios
|
|
72
|
+
const templatePaths = [
|
|
73
|
+
path.join(__dirname, 'lambdaHandlerTemplate.ts'), // For npm package
|
|
74
|
+
path.join(__dirname, '..', '..', 'src', 'cli', 'lambdaHandlerTemplate.ts'), // For development
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
let templateContent: string | null = null;
|
|
78
|
+
|
|
79
|
+
// Try each path until we find the template
|
|
80
|
+
for (const templatePath of templatePaths) {
|
|
81
|
+
try {
|
|
82
|
+
if (fs.existsSync(templatePath)) {
|
|
83
|
+
templateContent = fs.readFileSync(templatePath, 'utf8');
|
|
84
|
+
logger.debug(`Found template at ${templatePath}`);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
// Continue to next path
|
|
89
|
+
}
|
|
90
|
+
}
|
|
73
91
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
92
|
+
if (!templateContent) {
|
|
93
|
+
logger.error('Could not find Lambda handler template file');
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
77
96
|
|
|
97
|
+
try {
|
|
78
98
|
// Replace the placeholder with the actual module path
|
|
79
99
|
// Using a string literal here to make sure we match exactly what's in the template
|
|
80
100
|
templateContent = templateContent.replace(/const modulePath = '{MODULE_PATH}';/, `const modulePath = '${modulePath}';`);
|
|
@@ -103,7 +123,7 @@ function main() {
|
|
|
103
123
|
} else if (command === 'generate-lambda-ts-handler') {
|
|
104
124
|
generateLambdaHandler();
|
|
105
125
|
} else {
|
|
106
|
-
logger.error('Unknown command. Available commands: token, generate-lambda-handler');
|
|
126
|
+
logger.error('Unknown command. Available commands: token, generate-lambda-ts-handler');
|
|
107
127
|
process.exit(1);
|
|
108
128
|
}
|
|
109
129
|
}
|