@minded-ai/mindedjs 1.0.62-patch2 → 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 +26 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/lambdaHandlerTemplate.d.ts +2 -4
- package/dist/cli/lambdaHandlerTemplate.d.ts.map +1 -1
- package/dist/cli/lambdaHandlerTemplate.js +7 -2
- package/dist/cli/lambdaHandlerTemplate.js.map +1 -1
- package/dist/cli/lambdaHandlerTemplate.ts +46 -0
- package/package.json +4 -2
- package/src/cli/index.ts +28 -7
- package/src/cli/lambdaHandlerTemplate.ts +10 -3
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,12 +94,33 @@ 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
|
|
123
|
+
templateContent = templateContent.replace(/const modulePath = '{MODULE_PATH}';/, `const modulePath = '${modulePath}';`);
|
|
104
124
|
// Write the Lambda handler to index.ts at the root
|
|
105
125
|
const outputPath = path.join(process.cwd(), 'index.ts');
|
|
106
126
|
fs.writeFileSync(outputPath, templateContent);
|
|
@@ -126,7 +146,7 @@ function main() {
|
|
|
126
146
|
generateLambdaHandler();
|
|
127
147
|
}
|
|
128
148
|
else {
|
|
129
|
-
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');
|
|
130
150
|
process.exit(1);
|
|
131
151
|
}
|
|
132
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ED,SAAS,IAAI;IACX,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAExB,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,eAAM,CAAC,KAAK,CAAC,wBAAwB,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"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
body: any;
|
|
4
|
-
}>;
|
|
1
|
+
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
|
2
|
+
export declare const handler: (event: APIGatewayProxyEvent, context: Context) => Promise<APIGatewayProxyResult>;
|
|
5
3
|
//# sourceMappingURL=lambdaHandlerTemplate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambdaHandlerTemplate.d.ts","sourceRoot":"","sources":["../../src/cli/lambdaHandlerTemplate.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,GAAU,OAAO,
|
|
1
|
+
{"version":3,"file":"lambdaHandlerTemplate.d.ts","sourceRoot":"","sources":["../../src/cli/lambdaHandlerTemplate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAElF,eAAO,MAAM,OAAO,GAAU,OAAO,oBAAoB,EAAE,SAAS,OAAO,KAAG,OAAO,CAAC,qBAAqB,CAwC1G,CAAC"}
|
|
@@ -8,7 +8,7 @@ const handler = async (event, context) => {
|
|
|
8
8
|
const resolvedPath = require.resolve(modulePath);
|
|
9
9
|
delete require.cache[resolvedPath];
|
|
10
10
|
const agent = require(modulePath).default;
|
|
11
|
-
const { agentFunctionName, agentFunctionBody } = event;
|
|
11
|
+
const { agentFunctionName, agentFunctionBody } = event.body ? JSON.parse(event.body) : event;
|
|
12
12
|
if (!agent[agentFunctionName]) {
|
|
13
13
|
throw new Error('Unknown agentFunctionName: ' + agentFunctionName);
|
|
14
14
|
}
|
|
@@ -32,7 +32,12 @@ const handler = async (event, context) => {
|
|
|
32
32
|
}
|
|
33
33
|
return {
|
|
34
34
|
statusCode: 200,
|
|
35
|
-
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
'Access-Control-Allow-Origin': '*',
|
|
38
|
+
'Access-Control-Allow-Credentials': true,
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify(responseBody),
|
|
36
41
|
};
|
|
37
42
|
};
|
|
38
43
|
exports.handler = handler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambdaHandlerTemplate.js","sourceRoot":"","sources":["../../src/cli/lambdaHandlerTemplate.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,sEAAsE;;;
|
|
1
|
+
{"version":3,"file":"lambdaHandlerTemplate.js","sourceRoot":"","sources":["../../src/cli/lambdaHandlerTemplate.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,sEAAsE;;;AAI/D,MAAM,OAAO,GAAG,KAAK,EAAE,KAA2B,EAAE,OAAgB,EAAkC,EAAE;IAC7G,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,8BAA8B;IAClE,MA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IAED,OAAO;QACL,UAAU,EAAE,GAAG;QACf,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,6BAA6B,EAAE,GAAG;YAClC,kCAAkC,EAAE,IAAI;SACzC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;KACnC,CAAC;AACJ,CAAC,CAAC;AAxCW,QAAA,OAAO,WAwClB"}
|
|
@@ -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",
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
"license": "ISC",
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@eslint/js": "^9.27.0",
|
|
30
|
+
"@types/aws-lambda": "^8.10.150",
|
|
29
31
|
"@types/chai": "^4.3.11",
|
|
30
32
|
"@types/mocha": "^10.0.6",
|
|
31
33
|
"@types/node": "^20.11.19",
|
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,14 +68,36 @@ 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
|
|
100
|
+
templateContent = templateContent.replace(/const modulePath = '{MODULE_PATH}';/, `const modulePath = '${modulePath}';`);
|
|
80
101
|
|
|
81
102
|
// Write the Lambda handler to index.ts at the root
|
|
82
103
|
const outputPath = path.join(process.cwd(), 'index.ts');
|
|
@@ -102,7 +123,7 @@ function main() {
|
|
|
102
123
|
} else if (command === 'generate-lambda-ts-handler') {
|
|
103
124
|
generateLambdaHandler();
|
|
104
125
|
} else {
|
|
105
|
-
logger.error('Unknown command. Available commands: token, generate-lambda-handler');
|
|
126
|
+
logger.error('Unknown command. Available commands: token, generate-lambda-ts-handler');
|
|
106
127
|
process.exit(1);
|
|
107
128
|
}
|
|
108
129
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// This is the template for the Lambda handler
|
|
2
2
|
// The {MODULE_PATH} placeholder will be replaced with the actual path
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
|
5
|
+
|
|
6
|
+
export const handler = async (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
|
|
5
7
|
const modulePath = '{MODULE_PATH}'; // Agent path from minded.json
|
|
6
8
|
const resolvedPath = require.resolve(modulePath);
|
|
7
9
|
delete require.cache[resolvedPath];
|
|
8
10
|
const agent = require(modulePath).default;
|
|
9
|
-
const { agentFunctionName, agentFunctionBody } = event;
|
|
11
|
+
const { agentFunctionName, agentFunctionBody } = event.body ? JSON.parse(event.body) : event;
|
|
10
12
|
|
|
11
13
|
if (!agent[agentFunctionName]) {
|
|
12
14
|
throw new Error('Unknown agentFunctionName: ' + agentFunctionName);
|
|
@@ -34,6 +36,11 @@ export const handler = async (event: any, context: any) => {
|
|
|
34
36
|
|
|
35
37
|
return {
|
|
36
38
|
statusCode: 200,
|
|
37
|
-
|
|
39
|
+
headers: {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
'Access-Control-Allow-Origin': '*',
|
|
42
|
+
'Access-Control-Allow-Credentials': true,
|
|
43
|
+
},
|
|
44
|
+
body: JSON.stringify(responseBody),
|
|
38
45
|
};
|
|
39
46
|
};
|