@pluslabs/utils 0.3.1 → 0.4.0
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/module/cache/index.d.ts +4 -4
- package/dist/module/cache/index.d.ts.map +1 -1
- package/dist/module/cache/index.js.map +1 -1
- package/dist/module/index.d.ts +4 -4
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +4 -4
- package/dist/module/index.js.map +1 -1
- package/dist/module/langfuse-prompt-service/index.d.ts +103 -0
- package/dist/module/langfuse-prompt-service/index.d.ts.map +1 -0
- package/dist/module/langfuse-prompt-service/index.js +297 -0
- package/dist/module/langfuse-prompt-service/index.js.map +1 -0
- package/dist/module/logger/index.d.ts +12 -0
- package/dist/module/logger/index.d.ts.map +1 -0
- package/dist/module/logger/index.js +29 -0
- package/dist/module/logger/index.js.map +1 -0
- package/dist/module/stamp/index.d.ts.map +1 -1
- package/dist/module/stamp/index.js.map +1 -1
- package/package.json +53 -25
- package/src/index.ts +4 -4
- package/src/langfuse-prompt-service/index.ts +469 -0
- package/src/logger/index.ts +29 -0
- package/dist/main/cache/index.d.ts +0 -42
- package/dist/main/cache/index.d.ts.map +0 -1
- package/dist/main/cache/index.js +0 -118
- package/dist/main/cache/index.js.map +0 -1
- package/dist/main/gpt/index.d.ts +0 -18
- package/dist/main/gpt/index.d.ts.map +0 -1
- package/dist/main/gpt/index.js +0 -27
- package/dist/main/gpt/index.js.map +0 -1
- package/dist/main/index.d.ts +0 -6
- package/dist/main/index.d.ts.map +0 -1
- package/dist/main/index.js +0 -39
- package/dist/main/index.js.map +0 -1
- package/dist/main/stamp/index.d.ts +0 -23
- package/dist/main/stamp/index.d.ts.map +0 -1
- package/dist/main/stamp/index.js +0 -47
- package/dist/main/stamp/index.js.map +0 -1
package/dist/main/cache/index.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const DEFAULT_TTL = 10 * 60; // 10 minutes
|
|
13
|
-
class CacheKey {
|
|
14
|
-
constructor(prefix, ...args) {
|
|
15
|
-
var _a, _b;
|
|
16
|
-
/**
|
|
17
|
-
* The time to live for the cache key in seconds
|
|
18
|
-
*/
|
|
19
|
-
this.ttl = DEFAULT_TTL;
|
|
20
|
-
this.key = [prefix, (_b = (_a = process.env.NODE_ENV) === null || _a === void 0 ? void 0 : _a.substring(0, 4)) !== null && _b !== void 0 ? _b : 'dev', ...args];
|
|
21
|
-
}
|
|
22
|
-
setTtl(ttl) {
|
|
23
|
-
this.ttl = ttl;
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
add(...values) {
|
|
27
|
-
this.key.push(...((values === null || values === void 0 ? void 0 : values.map((value) => { var _a; return (_a = value === null || value === void 0 ? void 0 : value.toString()) !== null && _a !== void 0 ? _a : value; })) || []));
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
get() {
|
|
31
|
-
return this.key.join(':');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Creates a cache keys manager
|
|
36
|
-
* @param options - The options for the cache keys manager
|
|
37
|
-
* @param options.registry - The registry of cache keys
|
|
38
|
-
* @param options.namespace - The namespace for the cache keys
|
|
39
|
-
* @param options.redisClient - The redis client to use for the cache keys manager
|
|
40
|
-
* @returns The cache keys manager
|
|
41
|
-
*/
|
|
42
|
-
function createCacheKeysManager(options) {
|
|
43
|
-
const { registry, namespace, redisClient } = options;
|
|
44
|
-
function getCacheKey(root, node, ...identifiers) {
|
|
45
|
-
return new CacheKey(namespace, root.toString(), node, ...((identifiers === null || identifiers === void 0 ? void 0 : identifiers.map((arg) => { var _a; return (_a = arg === null || arg === void 0 ? void 0 : arg.toString()) !== null && _a !== void 0 ? _a : arg; })) || []));
|
|
46
|
-
}
|
|
47
|
-
function invalidateCacheKey(root, key, ...identifiers) {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
const cacheKey = getCacheKey(root, key, ...identifiers);
|
|
50
|
-
if (process.env.NODE_ENV !== 'production' && !redisClient) {
|
|
51
|
-
console.warn('[Cache Keys Manager] You tried to invalidate a cache key with no redis client');
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
yield (redisClient === null || redisClient === void 0 ? void 0 : redisClient.del(cacheKey.get()));
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
function getCachedData(options) {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
const { cacheKey, queryFn, ttl = DEFAULT_TTL } = options;
|
|
60
|
-
let cacheKeyString;
|
|
61
|
-
if (typeof cacheKey === 'string') {
|
|
62
|
-
cacheKeyString = cacheKey;
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
const keyTuple = cacheKey();
|
|
66
|
-
cacheKeyString = getCacheKey(keyTuple[0], keyTuple[1], ...keyTuple.slice(2)).get();
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
// Check cache first
|
|
70
|
-
const cachedData = yield (redisClient === null || redisClient === void 0 ? void 0 : redisClient.get(cacheKeyString));
|
|
71
|
-
if (cachedData) {
|
|
72
|
-
return cachedData;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
console.error({
|
|
77
|
-
error,
|
|
78
|
-
cacheKey: cacheKeyString,
|
|
79
|
-
message: 'Redis error, falling back to database'
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
// If not in cache or Redis error, get from database
|
|
83
|
-
try {
|
|
84
|
-
const data = yield queryFn();
|
|
85
|
-
if (!data) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
// Try to cache the result, but don't fail if Redis is down
|
|
89
|
-
try {
|
|
90
|
-
yield (redisClient === null || redisClient === void 0 ? void 0 : redisClient.set(cacheKeyString, data, { ex: ttl }));
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
console.error({
|
|
94
|
-
error,
|
|
95
|
-
cacheKey: cacheKeyString,
|
|
96
|
-
message: 'Failed to cache data, but continuing with database result'
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return data;
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
console.error({
|
|
103
|
-
error,
|
|
104
|
-
cacheKey: cacheKeyString,
|
|
105
|
-
message: 'Database query failed'
|
|
106
|
-
});
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
getCacheKey,
|
|
113
|
-
invalidateCacheKey,
|
|
114
|
-
getCachedData
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
exports.default = createCacheKeysManager;
|
|
118
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,MAAM,WAAW,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,aAAa;AAE1C,MAAM,QAAQ;IAQV,YAAY,MAAc,EAAE,GAAG,IAAc;;QAL7C;;WAEG;QACI,QAAG,GAAW,WAAW,CAAC;QAG7B,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,E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O,EAAE,CAAC;gBAE7B,IAAI,CAAC,IAAI,EAAE;oBACP,OAAO,IAAI,CAAC;iBACf;gBAED,2DAA2D;gBAC3D,IAAI;oBACA,MAAM,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,GAAG,CAAC,cAAc,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAA,CAAC;iBAC7D;gBAAC,OAAO,KAAU,EAAE;oBACjB,OAAO,CAAC,KAAK,CAAC;wBACV,KAAK;wBACL,QAAQ,EAAE,cAAc;wBACxB,OAAO,EAAE,2DAA2D;qBACvE,CAAC,CAAC;iBACN;gBAED,OAAO,IAAI,CAAC;aACf;YAAC,OAAO,KAAU,EAAE;gBACjB,OAAO,CAAC,KAAK,CAAC;oBACV,KAAK;oBACL,QAAQ,EAAE,cAAc;oBACxB,OAAO,EAAE,uBAAuB;iBACnC,CAAC,CAAC;gBAEH,OAAO,IAAI,CAAC;aACf;QACL,CAAC;KAAA;IAED,OAAO;QACH,WAAW;QACX,kBAAkB;QAClB,aAAa;KAChB,CAAC;AACN,CAAC;AAED,kBAAe,sBAAsB,CAAC"}
|
package/dist/main/gpt/index.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
type ProactiveRequestData = {
|
|
2
|
-
request_id: string;
|
|
3
|
-
assistant_id: string;
|
|
4
|
-
client_id: string;
|
|
5
|
-
client_phone_number: string;
|
|
6
|
-
};
|
|
7
|
-
export declare const gpt: {
|
|
8
|
-
extension: {
|
|
9
|
-
/**
|
|
10
|
-
* Send a proactive request to MagicGPT extension
|
|
11
|
-
* @param source String to identify the source of the request
|
|
12
|
-
* @param data ProactiveRequestData to send to the GPT
|
|
13
|
-
*/
|
|
14
|
-
proactiveRequest: (source: string, data: ProactiveRequestData) => void;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export {};
|
|
18
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/gpt/index.ts"],"names":[],"mappings":"AAAA,KAAK,oBAAoB,GAAG;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,eAAO,MAAM,GAAG;;QAER;;;;WAIG;mCACwB,MAAM,QAAQ,oBAAoB;;CAmBpE,CAAC"}
|
package/dist/main/gpt/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gpt = void 0;
|
|
4
|
-
exports.gpt = {
|
|
5
|
-
extension: {
|
|
6
|
-
/**
|
|
7
|
-
* Send a proactive request to MagicGPT extension
|
|
8
|
-
* @param source String to identify the source of the request
|
|
9
|
-
* @param data ProactiveRequestData to send to the GPT
|
|
10
|
-
*/
|
|
11
|
-
proactiveRequest: (source, data) => {
|
|
12
|
-
window.postMessage(JSON.stringify({
|
|
13
|
-
action: 'proactive.request',
|
|
14
|
-
data: btoa(JSON.stringify({
|
|
15
|
-
source,
|
|
16
|
-
data: {
|
|
17
|
-
request_id: data.request_id,
|
|
18
|
-
assistant_id: data.assistant_id,
|
|
19
|
-
client_id: data.client_id,
|
|
20
|
-
client_phone_number: data.client_phone_number
|
|
21
|
-
}
|
|
22
|
-
}))
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/gpt/index.ts"],"names":[],"mappings":";;;AAOa,QAAA,GAAG,GAAG;IACf,SAAS,EAAE;QACP;;;;WAIG;QACH,gBAAgB,EAAE,CAAC,MAAc,EAAE,IAA0B,EAAE,EAAE;YAC7D,MAAM,CAAC,WAAW,CACd,IAAI,CAAC,SAAS,CAAC;gBACX,MAAM,EAAE,mBAAmB;gBAC3B,IAAI,EAAE,IAAI,CACN,IAAI,CAAC,SAAS,CAAC;oBACX,MAAM;oBACN,IAAI,EAAE;wBACF,UAAU,EAAE,IAAI,CAAC,UAAU;wBAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;wBAC/B,SAAS,EAAE,IAAI,CAAC,SAAS;wBACzB,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;qBAChD;iBACJ,CAAC,CACL;aACJ,CAAC,CACL,CAAC;QACN,CAAC;KACJ;CACJ,CAAC"}
|
package/dist/main/index.d.ts
DELETED
package/dist/main/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,sBAAsB,MAAM,SAAS,CAAC;AAE7C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,GAAG,EAAE,sBAAsB,EAAE,CAAC"}
|
package/dist/main/index.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
-
};
|
|
28
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
-
};
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.createCacheKeysManager = exports.gpt = void 0;
|
|
33
|
-
const gpt = __importStar(require("./gpt"));
|
|
34
|
-
exports.gpt = gpt;
|
|
35
|
-
const cache_1 = __importDefault(require("./cache"));
|
|
36
|
-
exports.createCacheKeysManager = cache_1.default;
|
|
37
|
-
__exportStar(require("./stamp"), exports);
|
|
38
|
-
__exportStar(require("./cache"), exports);
|
|
39
|
-
//# sourceMappingURL=index.js.map
|
package/dist/main/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAMpB,kBAAG;AALZ,oDAA6C;AAK/B,iCALP,eAAsB,CAKO;AAHpC,0CAAwB;AACxB,0CAAwB"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
type context = {
|
|
2
|
-
id: string;
|
|
3
|
-
idx: string;
|
|
4
|
-
step: number;
|
|
5
|
-
now: number;
|
|
6
|
-
end: () => void;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* The idea is that you can create a stamp with an id, and then use that id to mark different steps in your code.
|
|
10
|
-
* `createStamp` should be called at the beginning of the execution context and then createStamp
|
|
11
|
-
* @param id String to identify the stamp
|
|
12
|
-
* @returns
|
|
13
|
-
*/
|
|
14
|
-
export declare const createStamp: (id?: string) => {
|
|
15
|
-
stamp: (name: string) => context;
|
|
16
|
-
end: () => context;
|
|
17
|
-
};
|
|
18
|
-
export declare function stamp(this: context, name: string): context;
|
|
19
|
-
export declare namespace stamp {
|
|
20
|
-
var end: (this: context) => context;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
23
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":"AAGA,KAAK,OAAO,GAAG;IACX,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;CAiBvB,CAAC;AAEF,wBAAgB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAahD;yBAbe,KAAK"}
|
package/dist/main/stamp/index.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copy/pasta from https://github.com/pluslabs/magic-professional/blob/main/packages/stamp/index.ts
|
|
3
|
-
// since yarn cant do subdirectories from a monorepo
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.stamp = exports.createStamp = void 0;
|
|
6
|
-
/**
|
|
7
|
-
* The idea is that you can create a stamp with an id, and then use that id to mark different steps in your code.
|
|
8
|
-
* `createStamp` should be called at the beginning of the execution context and then createStamp
|
|
9
|
-
* @param id String to identify the stamp
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
const createStamp = (id = '') => {
|
|
13
|
-
const ctx = {
|
|
14
|
-
id,
|
|
15
|
-
idx: (Date.now() * Math.random() * 1e6).toString(36),
|
|
16
|
-
now: Date.now(),
|
|
17
|
-
step: Date.now(),
|
|
18
|
-
end: () => { }
|
|
19
|
-
};
|
|
20
|
-
// Bind the end function to the context
|
|
21
|
-
// so we can curry it
|
|
22
|
-
ctx.end = end.bind(ctx);
|
|
23
|
-
return {
|
|
24
|
-
stamp: stamp.bind(ctx),
|
|
25
|
-
end: end.bind(ctx)
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
exports.createStamp = createStamp;
|
|
29
|
-
function stamp(name) {
|
|
30
|
-
if (!this.id) {
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
const diff = Date.now() - this.step;
|
|
34
|
-
this.step = Date.now();
|
|
35
|
-
console.log(`[STAMP][${this.idx}][${this.id}] ${name} took ${diff}ms, total: ${Date.now() - this.now}ms`);
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
exports.stamp = stamp;
|
|
39
|
-
stamp.end = end;
|
|
40
|
-
function end() {
|
|
41
|
-
this.id = '';
|
|
42
|
-
this.now = 0;
|
|
43
|
-
this.step = 0;
|
|
44
|
-
const ctx = this;
|
|
45
|
-
return ctx;
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":";AAAA,mGAAmG;AACnG,oDAAoD;;;AAUpD;;;;;GAKG;AACI,MAAM,WAAW,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;IACnC,MAAM,GAAG,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