@minded-ai/mindedjs 1.0.62-patch1 → 1.0.62-patch3
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 +19 -43
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/lambdaHandlerTemplate.d.ts +3 -0
- package/dist/cli/lambdaHandlerTemplate.d.ts.map +1 -0
- package/dist/cli/lambdaHandlerTemplate.js +44 -0
- package/dist/cli/lambdaHandlerTemplate.js.map +1 -0
- package/package.json +2 -1
- package/src/cli/index.ts +18 -41
- package/src/cli/lambdaHandlerTemplate.ts +46 -0
- package/dist/utils/extractToolMemoryResponse.d.ts +0 -4
- package/dist/utils/extractToolMemoryResponse.d.ts.map +0 -1
- package/dist/utils/extractToolMemoryResponse.js +0 -16
- package/dist/utils/extractToolMemoryResponse.js.map +0 -1
package/dist/cli/index.js
CHANGED
|
@@ -38,6 +38,7 @@ 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}';
|
|
41
42
|
function getEnvFilePath() {
|
|
42
43
|
return path.join(process.cwd(), ENV_FILE);
|
|
43
44
|
}
|
|
@@ -93,48 +94,23 @@ function generateLambdaHandler() {
|
|
|
93
94
|
}
|
|
94
95
|
// Remove .ts or .js extension if present and convert to relative path
|
|
95
96
|
const modulePath = agentPath.replace(/\.(ts|js)$/, '');
|
|
96
|
-
//
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
let responseBody = null;
|
|
113
|
-
try {
|
|
114
|
-
JSON.stringify(response);
|
|
115
|
-
responseBody = response;
|
|
116
|
-
} catch (_) {
|
|
117
|
-
// ignored - responseBody stays null
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (agentFunctionName === 'startVoiceSession') {
|
|
121
|
-
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
122
|
-
while (context.getRemainingTimeInMillis() > 1000) {
|
|
123
|
-
console.log('Lambda remaining time in seconds: ', context.getRemainingTimeInMillis() / 1000);
|
|
124
|
-
await wait(1000); // sleep 1 s
|
|
97
|
+
// Get the path to the template file
|
|
98
|
+
const templatePath = path.join(__dirname, 'lambdaHandlerTemplate.ts');
|
|
99
|
+
try {
|
|
100
|
+
// Read the template file
|
|
101
|
+
let templateContent = fs.readFileSync(templatePath, 'utf8');
|
|
102
|
+
// Replace the placeholder with the actual module path
|
|
103
|
+
// Using a string literal here to make sure we match exactly what's in the template
|
|
104
|
+
templateContent = templateContent.replace(/const modulePath = '{MODULE_PATH}';/, `const modulePath = '${modulePath}';`);
|
|
105
|
+
// Write the Lambda handler to index.ts at the root
|
|
106
|
+
const outputPath = path.join(process.cwd(), 'index.ts');
|
|
107
|
+
fs.writeFileSync(outputPath, templateContent);
|
|
108
|
+
logger_1.logger.info(`Generated Lambda handler at ${outputPath}`);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
logger_1.logger.error('Failed to generate Lambda handler:', error);
|
|
112
|
+
process.exit(1);
|
|
125
113
|
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
statusCode: 200,
|
|
130
|
-
body: responseBody,
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
`;
|
|
134
|
-
// Write the Lambda handler to index.js at the root
|
|
135
|
-
const outputPath = path.join(process.cwd(), 'index.js');
|
|
136
|
-
fs.writeFileSync(outputPath, lambdaHandlerContent);
|
|
137
|
-
logger_1.logger.info(`Generated Lambda handler at ${outputPath}`);
|
|
138
114
|
}
|
|
139
115
|
function main() {
|
|
140
116
|
const args = process.argv.slice(2);
|
|
@@ -147,11 +123,11 @@ function main() {
|
|
|
147
123
|
}
|
|
148
124
|
setToken(token);
|
|
149
125
|
}
|
|
150
|
-
else if (command === 'generate-lambda-
|
|
126
|
+
else if (command === 'generate-lambda-ts-handler') {
|
|
151
127
|
generateLambdaHandler();
|
|
152
128
|
}
|
|
153
129
|
else {
|
|
154
|
-
logger_1.logger.error('Unknown command. Available commands: token, generate-lambda');
|
|
130
|
+
logger_1.logger.error('Unknown command. Available commands: token, generate-lambda-handler');
|
|
155
131
|
process.exit(1);
|
|
156
132
|
}
|
|
157
133
|
}
|
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;AACxB,MAAM,uBAAuB,GAAG,eAAe,CAAC;AAEhD,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,KAAK,EAAE,CAAC;IAErD,4BAA4B;IAC5B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,kCAAkC;QAClC,EAAE,CAAC,aAAa,CAAC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AAE,CAAC;QACf,eAAM,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,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,qEAAqE,CAAC,CAAC;QACpF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This is the template for the Lambda handler
|
|
3
|
+
// The {MODULE_PATH} placeholder will be replaced with the actual path
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.handler = void 0;
|
|
6
|
+
const handler = async (event, context) => {
|
|
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
|
+
if (!agent[agentFunctionName]) {
|
|
13
|
+
throw new Error('Unknown agentFunctionName: ' + agentFunctionName);
|
|
14
|
+
}
|
|
15
|
+
const response = await agent[agentFunctionName](agentFunctionBody);
|
|
16
|
+
// Safely stringify the response. If it fails (e.g., due to circular refs
|
|
17
|
+
// or non-serialisable class instances), fall back to null.
|
|
18
|
+
let responseBody = null;
|
|
19
|
+
try {
|
|
20
|
+
JSON.stringify(response);
|
|
21
|
+
responseBody = response;
|
|
22
|
+
}
|
|
23
|
+
catch (_) {
|
|
24
|
+
// ignored - responseBody stays null
|
|
25
|
+
}
|
|
26
|
+
if (agentFunctionName === 'startVoiceSession') {
|
|
27
|
+
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
28
|
+
while (context.getRemainingTimeInMillis() > 1000) {
|
|
29
|
+
console.log('Lambda remaining time in seconds: ', context.getRemainingTimeInMillis() / 1000);
|
|
30
|
+
await wait(1000); // sleep 1 s
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
statusCode: 200,
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
'Access-Control-Allow-Origin': '*',
|
|
38
|
+
'Access-Control-Allow-Credentials': true,
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify(responseBody),
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
exports.handler = handler;
|
|
44
|
+
//# sourceMappingURL=lambdaHandler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E,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QACnE,OAAO,OAAO,CAAC,wBAAwB,EAAE,GAAG,IAAI,EAAE,CAAC;YACjD,OAAO,CAAC,GAAG,CAAC,oCAAoC,EAAE,OAAO,CAAC,wBAAwB,EAAE,GAAG,IAAI,CAAC,CAAC;YAC7F,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY;QAChC,CAAC;IACH,CAAC;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"}
|
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-patch3",
|
|
4
4
|
"description": "MindedJS is a TypeScript library for building agents.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@eslint/js": "^9.27.0",
|
|
29
|
+
"@types/aws-lambda": "^8.10.150",
|
|
29
30
|
"@types/chai": "^4.3.11",
|
|
30
31
|
"@types/mocha": "^10.0.6",
|
|
31
32
|
"@types/node": "^20.11.19",
|
package/src/cli/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ 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}';
|
|
8
9
|
|
|
9
10
|
function getEnvFilePath(): string {
|
|
10
11
|
return path.join(process.cwd(), ENV_FILE);
|
|
@@ -67,49 +68,25 @@ function generateLambdaHandler(): void {
|
|
|
67
68
|
// Remove .ts or .js extension if present and convert to relative path
|
|
68
69
|
const modulePath = agentPath.replace(/\.(ts|js)$/, '');
|
|
69
70
|
|
|
70
|
-
//
|
|
71
|
-
const
|
|
72
|
-
const modulePath = '${modulePath}'; // Agent path from minded.json
|
|
73
|
-
const resolvedPath = require.resolve(modulePath);
|
|
74
|
-
delete require.cache[resolvedPath];
|
|
75
|
-
const agent = require(modulePath).default;
|
|
76
|
-
const { agentFunctionName, agentFunctionBody } = event;
|
|
71
|
+
// Get the path to the template file
|
|
72
|
+
const templatePath = path.join(__dirname, 'lambdaHandlerTemplate.ts');
|
|
77
73
|
|
|
78
|
-
if (!agent[agentFunctionName]) {
|
|
79
|
-
throw new Error('Unknown agentFunctionName: ' + agentFunctionName);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const response = await agent[agentFunctionName](agentFunctionBody);
|
|
83
|
-
|
|
84
|
-
// Safely stringify the response. If it fails (e.g., due to circular refs
|
|
85
|
-
// or non-serialisable class instances), fall back to null.
|
|
86
|
-
let responseBody = null;
|
|
87
74
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
} catch (_) {
|
|
91
|
-
// ignored - responseBody stays null
|
|
92
|
-
}
|
|
75
|
+
// Read the template file
|
|
76
|
+
let templateContent = fs.readFileSync(templatePath, 'utf8');
|
|
93
77
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
console.log('Lambda remaining time in seconds: ', context.getRemainingTimeInMillis() / 1000);
|
|
98
|
-
await wait(1000); // sleep 1 s
|
|
99
|
-
}
|
|
100
|
-
}
|
|
78
|
+
// Replace the placeholder with the actual module path
|
|
79
|
+
// Using a string literal here to make sure we match exactly what's in the template
|
|
80
|
+
templateContent = templateContent.replace(/const modulePath = '{MODULE_PATH}';/, `const modulePath = '${modulePath}';`);
|
|
101
81
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const outputPath = path.join(process.cwd(), 'index.js');
|
|
111
|
-
fs.writeFileSync(outputPath, lambdaHandlerContent);
|
|
112
|
-
logger.info(`Generated Lambda handler at ${outputPath}`);
|
|
82
|
+
// Write the Lambda handler to index.ts at the root
|
|
83
|
+
const outputPath = path.join(process.cwd(), 'index.ts');
|
|
84
|
+
fs.writeFileSync(outputPath, templateContent);
|
|
85
|
+
logger.info(`Generated Lambda handler at ${outputPath}`);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
logger.error('Failed to generate Lambda handler:', error);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
113
90
|
}
|
|
114
91
|
|
|
115
92
|
function main() {
|
|
@@ -123,10 +100,10 @@ function main() {
|
|
|
123
100
|
process.exit(1);
|
|
124
101
|
}
|
|
125
102
|
setToken(token);
|
|
126
|
-
} else if (command === 'generate-lambda-
|
|
103
|
+
} else if (command === 'generate-lambda-ts-handler') {
|
|
127
104
|
generateLambdaHandler();
|
|
128
105
|
} else {
|
|
129
|
-
logger.error('Unknown command. Available commands: token, generate-lambda');
|
|
106
|
+
logger.error('Unknown command. Available commands: token, generate-lambda-handler');
|
|
130
107
|
process.exit(1);
|
|
131
108
|
}
|
|
132
109
|
}
|
|
@@ -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
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extractToolMemoryResponse.d.ts","sourceRoot":"","sources":["../../src/utils/extractToolMemoryResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,QAAA,MAAM,yBAAyB,GAAI,MAAM,EAAE,aAAa,WAAW,KAAG,OAAO,CAAC,MAAM,CAUnF,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const extractToolMemoryResponse = (toolMessage) => {
|
|
4
|
-
try {
|
|
5
|
-
const parsed = JSON.parse(toolMessage.content);
|
|
6
|
-
if (typeof parsed === 'object' && parsed !== null && 'memory' in parsed) {
|
|
7
|
-
return parsed.memory;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
catch (error) {
|
|
11
|
-
console.error('Error parsing tool memory response', error);
|
|
12
|
-
}
|
|
13
|
-
return {};
|
|
14
|
-
};
|
|
15
|
-
exports.default = extractToolMemoryResponse;
|
|
16
|
-
//# sourceMappingURL=extractToolMemoryResponse.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extractToolMemoryResponse.js","sourceRoot":"","sources":["../../src/utils/extractToolMemoryResponse.ts"],"names":[],"mappings":";;AAEA,MAAM,yBAAyB,GAAG,CAAS,WAAwB,EAAmB,EAAE;IACtF,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAiB,CAAC,CAAC;QACzD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;YACxE,OAAO,MAAM,CAAC,MAAM,CAAC;QACvB,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF,kBAAe,yBAAyB,CAAC"}
|