@nx-ddd/common 16.1.1 → 16.3.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.
- package/README.md +37 -4
- package/domain/models.d.ts +52 -0
- package/domain/models.js +106 -4
- package/domain/models.js.map +1 -1
- package/domain/repository.js +3 -2
- package/domain/repository.js.map +1 -1
- package/infrastructure/externals/agent/agent.d.ts +49 -0
- package/infrastructure/externals/agent/agent.js +142 -0
- package/infrastructure/externals/agent/agent.js.map +1 -0
- package/infrastructure/externals/agent/index.d.ts +1 -0
- package/{injector → infrastructure/externals/agent}/index.js +1 -1
- package/infrastructure/externals/agent/index.js.map +1 -0
- package/infrastructure/externals/cloud-storage/cloud-storage.service.d.ts +13 -0
- package/infrastructure/externals/cloud-storage/cloud-storage.service.js +43 -0
- package/infrastructure/externals/cloud-storage/cloud-storage.service.js.map +1 -0
- package/infrastructure/externals/cloud-storage/index.d.ts +1 -0
- package/infrastructure/externals/cloud-storage/index.js +5 -0
- package/infrastructure/externals/cloud-storage/index.js.map +1 -0
- package/infrastructure/externals/openai/index.d.ts +2 -0
- package/infrastructure/externals/openai/index.js +6 -0
- package/infrastructure/externals/openai/index.js.map +1 -0
- package/infrastructure/externals/openai/open-ai.config.d.ts +6 -0
- package/infrastructure/externals/openai/open-ai.config.js +15 -0
- package/infrastructure/externals/openai/open-ai.config.js.map +1 -0
- package/infrastructure/externals/openai/open-ai.service.d.ts +4 -0
- package/infrastructure/externals/openai/open-ai.service.impl.d.ts +5 -0
- package/infrastructure/externals/openai/open-ai.service.impl.js +19 -0
- package/infrastructure/externals/openai/open-ai.service.impl.js.map +1 -0
- package/infrastructure/externals/openai/open-ai.service.js +11 -0
- package/infrastructure/externals/openai/open-ai.service.js.map +1 -0
- package/infrastructure/externals/stripe/index.d.ts +2 -0
- package/infrastructure/externals/stripe/index.js +6 -0
- package/infrastructure/externals/stripe/index.js.map +1 -0
- package/infrastructure/externals/stripe/stripe.config.d.ts +255 -0
- package/infrastructure/externals/stripe/stripe.config.js +15 -0
- package/infrastructure/externals/stripe/stripe.config.js.map +1 -0
- package/infrastructure/externals/stripe/stripe.service.d.ts +4 -0
- package/infrastructure/externals/stripe/stripe.service.impl.d.ts +5 -0
- package/infrastructure/externals/stripe/stripe.service.impl.js +44 -0
- package/infrastructure/externals/stripe/stripe.service.impl.js.map +1 -0
- package/infrastructure/externals/stripe/stripe.service.js +11 -0
- package/infrastructure/externals/stripe/stripe.service.js.map +1 -0
- package/infrastructure/index.d.ts +2 -0
- package/infrastructure/index.js +2 -0
- package/infrastructure/index.js.map +1 -1
- package/infrastructure/queries/cached-query.d.ts +45 -0
- package/infrastructure/queries/cached-query.js +47 -0
- package/infrastructure/queries/cached-query.js.map +1 -0
- package/infrastructure/queries/index.d.ts +1 -0
- package/infrastructure/queries/index.js +5 -0
- package/infrastructure/queries/index.js.map +1 -0
- package/infrastructure/synchronizer.d.ts +16 -0
- package/infrastructure/synchronizer.js +18 -0
- package/infrastructure/synchronizer.js.map +1 -0
- package/package.json +7 -2
- package/injector/index.d.ts +0 -1
- package/injector/index.js.map +0 -1
- package/injector/injector.d.ts +0 -36
- package/injector/injector.js +0 -56
- package/injector/injector.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,7 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# NxDDD Common
|
|
2
|
+
`@nx-ddd/common` is a library used for domain model annotations and related functionalities.
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
## Install
|
|
5
|
+
```sh
|
|
6
|
+
$ npm i @nx-ddd/common
|
|
7
|
+
```
|
|
4
8
|
|
|
5
|
-
##
|
|
9
|
+
## Usage
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
```ts
|
|
12
|
+
import { Domain, getAnnotations, getLangMap, getModelName } from './models';
|
|
13
|
+
|
|
14
|
+
@Domain.Entity({name: 'Profile'})
|
|
15
|
+
class Profile {
|
|
16
|
+
@Domain.Lang('名前') name: string;
|
|
17
|
+
@Domain.Lang('メールアドレス') email: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Domain.Entity({name: 'ユーザー'})
|
|
21
|
+
class User {
|
|
22
|
+
@Domain.Lang('ID') id: string;
|
|
23
|
+
@Domain.Type() profile: Profile;
|
|
24
|
+
@Domain.Lang('作成日時') createdAt: Date;
|
|
25
|
+
@Domain.Lang('更新日時') updatedAt: Date;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getLangMap(User);
|
|
29
|
+
/**
|
|
30
|
+
-> {
|
|
31
|
+
id: 'ID',
|
|
32
|
+
'profile.name': '名前',
|
|
33
|
+
'profile.email': 'メールアドレス',
|
|
34
|
+
createdAt: '作成日時',
|
|
35
|
+
updatedAt: '更新日時',
|
|
36
|
+
}
|
|
37
|
+
* */
|
|
38
|
+
|
|
39
|
+
getModelName(User) // -> 'ユーザー'
|
|
40
|
+
```
|
package/domain/models.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Dayjs } from 'dayjs';
|
|
2
|
+
export type Type<E> = {
|
|
3
|
+
new (): E;
|
|
4
|
+
};
|
|
2
5
|
export type DomainLangMap<Entity> = Partial<{
|
|
3
6
|
[K in keyof Entity]: string;
|
|
4
7
|
}>;
|
|
@@ -10,7 +13,56 @@ export interface Entity<Id = string> {
|
|
|
10
13
|
export type OmitGetter<T> = {
|
|
11
14
|
[P in keyof T as string extends P ? never : number extends P ? never : P]: T[P];
|
|
12
15
|
};
|
|
16
|
+
export type DeepPartial<T> = {
|
|
17
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
18
|
+
};
|
|
19
|
+
interface BaseDomainAnnotation {
|
|
20
|
+
type: 'model:lang' | 'prop:lang' | 'prop:type';
|
|
21
|
+
}
|
|
22
|
+
export interface DomainModelLangAnnotation extends BaseDomainAnnotation {
|
|
23
|
+
type: 'model:lang';
|
|
24
|
+
modelName: string;
|
|
25
|
+
name: string;
|
|
26
|
+
typeFactory?: () => any;
|
|
27
|
+
}
|
|
28
|
+
export interface DomainPropLangAnnotation extends BaseDomainAnnotation {
|
|
29
|
+
type: 'prop:lang';
|
|
30
|
+
propName: string;
|
|
31
|
+
name: string;
|
|
32
|
+
}
|
|
33
|
+
export interface DomainPropTypeAnnotation extends BaseDomainAnnotation {
|
|
34
|
+
type: 'prop:type';
|
|
35
|
+
propName: string;
|
|
36
|
+
typeFactory: () => any;
|
|
37
|
+
}
|
|
38
|
+
export type DomainAnnotation = DomainModelLangAnnotation | DomainPropLangAnnotation | DomainPropTypeAnnotation;
|
|
39
|
+
interface Target {
|
|
40
|
+
constructor: {
|
|
41
|
+
[Domain.ANNOTATIONS]?: DomainAnnotation[];
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export declare class Domain {
|
|
45
|
+
static readonly ANNOTATIONS: unique symbol;
|
|
46
|
+
static Lang(name: string): (target: any, propName: string) => void;
|
|
47
|
+
static Type<T>(typeFactory?: () => T): (target: any, propName: string) => void;
|
|
48
|
+
static Entity({ name }: {
|
|
49
|
+
name: string;
|
|
50
|
+
}): (target: any) => void;
|
|
51
|
+
static registerAnnotation(constructor: Target['constructor'], annotation: DomainAnnotation): void;
|
|
52
|
+
}
|
|
53
|
+
export type LangMap<E> = Partial<Record<keyof E, string>>;
|
|
54
|
+
export declare function getLangMap<E>(domain: Type<E>, mergeObj?: object): LangMap<E>;
|
|
55
|
+
export declare function getAnnotations<E>(target: Type<E>): DomainAnnotation[];
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated
|
|
58
|
+
* use getProps instead.
|
|
59
|
+
*/
|
|
60
|
+
export declare function getDomainProps<E>(target: Type<E>, deps?: number, path?: string): string[];
|
|
61
|
+
export declare function getProps<E>(target: Type<E>, deps?: number, path?: string): string[];
|
|
62
|
+
export declare function getModelName<E>(target: Type<E>): string;
|
|
13
63
|
export declare class Entity {
|
|
14
64
|
static fromObj<T extends Entity = Entity>(obj: object): T;
|
|
15
65
|
static toObj(entity: Entity): Entity;
|
|
16
66
|
}
|
|
67
|
+
export declare function TransformToDayjs(): PropertyDecorator;
|
|
68
|
+
export {};
|
package/domain/models.js
CHANGED
|
@@ -1,11 +1,103 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Entity = void 0;
|
|
3
|
+
exports.TransformToDayjs = exports.Entity = exports.getModelName = exports.getProps = exports.getDomainProps = exports.getAnnotations = exports.getLangMap = exports.Domain = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const utilities_1 = require("@nx-ddd/common/utilities");
|
|
6
|
+
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
7
|
+
const flat_1 = require("flat");
|
|
8
|
+
const class_transformer_1 = require("class-transformer");
|
|
9
|
+
const lodash_es_1 = require("lodash-es");
|
|
10
|
+
class Domain {
|
|
11
|
+
static Lang(name) {
|
|
12
|
+
return (target, propName) => {
|
|
13
|
+
this.registerAnnotation(target.constructor, { propName, type: 'prop:lang', name });
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
static Type(typeFactory) {
|
|
17
|
+
return (target, propName) => {
|
|
18
|
+
if (!typeFactory) {
|
|
19
|
+
const type = Reflect.getMetadata('design:type', target, propName);
|
|
20
|
+
typeFactory = () => type;
|
|
21
|
+
}
|
|
22
|
+
this.registerAnnotation(target.constructor, { propName, typeFactory, type: 'prop:type' });
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
// classをデコレートしてnameをアノテーションする
|
|
26
|
+
static Entity({ name }) {
|
|
27
|
+
return (target) => {
|
|
28
|
+
this.registerAnnotation(target, { name, type: 'model:lang', modelName: target.name });
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
static registerAnnotation(constructor, annotation) {
|
|
32
|
+
var _a;
|
|
33
|
+
var _b;
|
|
34
|
+
(_a = constructor[_b = this.ANNOTATIONS]) !== null && _a !== void 0 ? _a : (constructor[_b] = []);
|
|
35
|
+
constructor[this.ANNOTATIONS].push(annotation);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.Domain = Domain;
|
|
39
|
+
Domain.ANNOTATIONS = Symbol('annotations');
|
|
40
|
+
function getLangMap(domain, mergeObj = {}) {
|
|
41
|
+
return (0, lodash_es_1.merge)(_getLangMap(domain), mergeObj);
|
|
42
|
+
}
|
|
43
|
+
exports.getLangMap = getLangMap;
|
|
44
|
+
function _getLangMap(target) {
|
|
45
|
+
var _a;
|
|
46
|
+
return (0, flat_1.flatten)((_a = getAnnotations(target).reduce((acc, annotation) => {
|
|
47
|
+
var _a;
|
|
48
|
+
switch (annotation.type) {
|
|
49
|
+
case 'prop:lang': {
|
|
50
|
+
acc[annotation.propName] = annotation.name;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case 'prop:type': {
|
|
54
|
+
const type = (_a = annotation.typeFactory) === null || _a === void 0 ? void 0 : _a.call(annotation);
|
|
55
|
+
acc[annotation.propName] = getLangMap(type);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return acc;
|
|
60
|
+
}, {})) !== null && _a !== void 0 ? _a : {});
|
|
61
|
+
}
|
|
62
|
+
function getAnnotations(target) {
|
|
63
|
+
var _a;
|
|
64
|
+
return (_a = target === null || target === void 0 ? void 0 : target[Domain.ANNOTATIONS]) !== null && _a !== void 0 ? _a : [];
|
|
65
|
+
}
|
|
66
|
+
exports.getAnnotations = getAnnotations;
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated
|
|
69
|
+
* use getProps instead.
|
|
70
|
+
*/
|
|
71
|
+
function getDomainProps(target, deps = 3, path = '') {
|
|
72
|
+
return getProps(target, deps, path);
|
|
73
|
+
}
|
|
74
|
+
exports.getDomainProps = getDomainProps;
|
|
75
|
+
function getProps(target, deps = 3, path = '') {
|
|
76
|
+
return getAnnotations(target).map((annotation) => {
|
|
77
|
+
var _a;
|
|
78
|
+
switch (annotation.type) {
|
|
79
|
+
case 'prop:lang': {
|
|
80
|
+
return `${path}${annotation.propName}`;
|
|
81
|
+
}
|
|
82
|
+
case 'prop:type': {
|
|
83
|
+
if (deps > 0) {
|
|
84
|
+
const type = (_a = annotation.typeFactory) === null || _a === void 0 ? void 0 : _a.call(annotation);
|
|
85
|
+
return getProps(type, deps - 1, `${path}${annotation.propName}.`);
|
|
86
|
+
}
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}).flat();
|
|
91
|
+
}
|
|
92
|
+
exports.getProps = getProps;
|
|
93
|
+
function getModelName(target) {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
return (_b = (_a = getAnnotations(target).find(annotation => {
|
|
96
|
+
return annotation.type === 'model:lang';
|
|
97
|
+
})) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : target.name;
|
|
98
|
+
}
|
|
99
|
+
exports.getModelName = getModelName;
|
|
5
100
|
class Entity {
|
|
6
|
-
// static from<E extends Entity = any>(obj: Partial<OmitGetter<E>>): E {
|
|
7
|
-
// return Object.assign(new this(), obj) as E;
|
|
8
|
-
// }
|
|
9
101
|
static fromObj(obj) {
|
|
10
102
|
return Object.assign(new this(), Object.assign({ id: null, createdAt: null, updatedAt: null }, obj));
|
|
11
103
|
}
|
|
@@ -14,4 +106,14 @@ class Entity {
|
|
|
14
106
|
}
|
|
15
107
|
}
|
|
16
108
|
exports.Entity = Entity;
|
|
109
|
+
function TransformToDayjs() {
|
|
110
|
+
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
111
|
+
if (typeof value === 'undefined')
|
|
112
|
+
return undefined;
|
|
113
|
+
if ((0, dayjs_1.default)(value).isValid())
|
|
114
|
+
return (0, dayjs_1.default)(value);
|
|
115
|
+
return value;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
exports.TransformToDayjs = TransformToDayjs;
|
|
17
119
|
//# sourceMappingURL=models.js.map
|
package/domain/models.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/common/src/domain/models.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/common/src/domain/models.ts"],"names":[],"mappings":";;;;AAAA,wDAAoD;AACpD,0DAAqC;AACrC,+BAA+B;AAC/B,yDAA8C;AAC9C,yCAAkC;AAoDlC,MAAa,MAAM;IAGjB,MAAM,CAAC,IAAI,CAAC,IAAY;QACtB,OAAO,CAAC,MAAW,EAAE,QAAgB,EAAE,EAAE;YACvC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,WAAW,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC,CAAC;QACnF,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,IAAI,CAAI,WAAqB;QAClC,OAAO,CAAC,MAAW,EAAE,QAAgB,EAAE,EAAE;YACvC,IAAI,CAAC,WAAW,EAAE;gBAChB,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,MAAa,EAAE,QAAQ,CAAC,CAAC;gBACzE,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;aAC1B;YACD,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,WAAW,EAAE,EAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAC,CAAC,CAAC;QAC1F,CAAC,CAAC;IACJ,CAAC;IAED,8BAA8B;IAC9B,MAAM,CAAC,MAAM,CAAC,EAAC,IAAI,EAAiB;QAClC,OAAO,CAAC,MAAW,EAAE,EAAE;YACrB,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,EAAC,CAAC,CAAC;QACtF,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,WAAkC,EAAE,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C,KAAK,CAAC,MAAc;QACzB,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAW,CAAC;IACpC,CAAC;CACF;AAbD,wBAaC;AAED,SAAgB,gBAAgB;IAC9B,OAAO,IAAA,6BAAS,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;QAC7B,IAAI,OAAO,KAAK,KAAK,WAAW;YAAE,OAAO,SAAS,CAAC;QACnD,IAAI,IAAA,eAAK,EAAC,KAAK,CAAC,CAAC,OAAO,EAAE;YAAE,OAAO,IAAA,eAAK,EAAC,KAAK,CAAC,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC;AAND,4CAMC"}
|
package/domain/repository.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Repository = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const core_1 = require("@
|
|
6
|
-
let Repository =
|
|
5
|
+
const core_1 = require("@angular/core");
|
|
6
|
+
let Repository = class Repository {
|
|
7
7
|
list() {
|
|
8
8
|
throw new Error('is not implemented!');
|
|
9
9
|
}
|
|
@@ -24,6 +24,7 @@ let Repository = exports.Repository = class Repository {
|
|
|
24
24
|
}
|
|
25
25
|
;
|
|
26
26
|
};
|
|
27
|
+
exports.Repository = Repository;
|
|
27
28
|
exports.Repository = Repository = tslib_1.__decorate([
|
|
28
29
|
(0, core_1.Injectable)()
|
|
29
30
|
], Repository);
|
package/domain/repository.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/common/src/domain/repository.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/common/src/domain/repository.ts"],"names":[],"mappings":";;;;AAAA,wCAA2C;AAKpC,IAAe,UAAU,GAAzB,MAAe,UAAU;IAC9B,IAAI;QACF,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAAA,CAAC;IACF,GAAG,CAAC,MAAwB;QAC1B,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAAA,CAAC;IACF,MAAM,CAAC,MAAkB;QACvB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAAA,CAAC;IACF,MAAM,CAAC,MAAwB;QAC7B,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IACD,MAAM,CAAC,MAAwB;QAC7B,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAAA,CAAC;CACH,CAAA;AAhBqB,gCAAU;qBAAV,UAAU;IAD/B,IAAA,iBAAU,GAAE;GACS,UAAU,CAgB/B"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { OpenAiServiceImpl } from "@nx-ddd/common/infrastructure/externals/openai/open-ai.service.impl";
|
|
2
|
+
import { ChatCompletionMessageParam } from "openai/resources";
|
|
3
|
+
import { FunctionTool } from "openai/resources/beta/assistants";
|
|
4
|
+
import { ChatCompletionCreateParamsBase } from "openai/resources/chat/completions";
|
|
5
|
+
export declare function addTool(obj: object, tool: object): object;
|
|
6
|
+
export declare function getTools(obj: object): any[];
|
|
7
|
+
export declare function buildToolFromSchema(name: string, description: string, schema: Function): FunctionTool;
|
|
8
|
+
export declare function AiFunction(params?: {
|
|
9
|
+
description?: string;
|
|
10
|
+
}): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
11
|
+
export interface AiSystemConfig {
|
|
12
|
+
model?: ChatCompletionCreateParamsBase['model'];
|
|
13
|
+
instructions?: string;
|
|
14
|
+
shots?: {
|
|
15
|
+
input: string;
|
|
16
|
+
output: string;
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
export declare function setAiSystemConfig(obj: object, config: AiSystemConfig): object;
|
|
20
|
+
export declare function getAiSystemConfig(obj: object): AiSystemConfig;
|
|
21
|
+
export declare function AiSystem({ model, instructions, shots, }: AiSystemConfig): (target: any) => any;
|
|
22
|
+
export declare class AiToolsAgent {
|
|
23
|
+
protected openai: OpenAiServiceImpl;
|
|
24
|
+
constructor(openai: OpenAiServiceImpl);
|
|
25
|
+
messages: ChatCompletionMessageParam[];
|
|
26
|
+
results: any[];
|
|
27
|
+
get tools(): any[];
|
|
28
|
+
get config(): AiSystemConfig;
|
|
29
|
+
completion(tools?: any[]): Promise<void>;
|
|
30
|
+
execute<T = any>(message: string, options?: {
|
|
31
|
+
tools?: any[];
|
|
32
|
+
}): Promise<T>;
|
|
33
|
+
}
|
|
34
|
+
export declare class AnyFunction {
|
|
35
|
+
private openai;
|
|
36
|
+
constructor(openai: OpenAiServiceImpl);
|
|
37
|
+
call<I, T>(_input: I, args: {
|
|
38
|
+
new (): T;
|
|
39
|
+
}, { instructions, model, specs, }?: {
|
|
40
|
+
instructions?: string;
|
|
41
|
+
model?: string;
|
|
42
|
+
specs?: {
|
|
43
|
+
input: I;
|
|
44
|
+
output: T;
|
|
45
|
+
}[];
|
|
46
|
+
}): Promise<T>;
|
|
47
|
+
private convertToChatMessages;
|
|
48
|
+
private parseInput;
|
|
49
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnyFunction = exports.AiToolsAgent = exports.AiSystem = exports.getAiSystemConfig = exports.setAiSystemConfig = exports.AiFunction = exports.buildToolFromSchema = exports.getTools = exports.addTool = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const class_validator_jsonschema_1 = require("class-validator-jsonschema");
|
|
6
|
+
const AI_TOOLS = '[ai-tools]';
|
|
7
|
+
const AI_SYSTEM = '[ai-system]';
|
|
8
|
+
function addTool(obj, tool) {
|
|
9
|
+
var _a;
|
|
10
|
+
obj[AI_TOOLS] = (_a = obj[AI_TOOLS]) !== null && _a !== void 0 ? _a : [];
|
|
11
|
+
obj[AI_TOOLS].push(tool);
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
exports.addTool = addTool;
|
|
15
|
+
function getTools(obj) {
|
|
16
|
+
var _a;
|
|
17
|
+
return (_a = obj[AI_TOOLS]) !== null && _a !== void 0 ? _a : [];
|
|
18
|
+
}
|
|
19
|
+
exports.getTools = getTools;
|
|
20
|
+
function buildFunctionTool(params) {
|
|
21
|
+
return {
|
|
22
|
+
type: 'function',
|
|
23
|
+
function: {
|
|
24
|
+
name: params.name,
|
|
25
|
+
description: params.description,
|
|
26
|
+
parameters: params.parameters,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function buildToolFromSchema(name, description, schema) {
|
|
31
|
+
const parameters = (0, class_validator_jsonschema_1.targetConstructorToSchema)(schema);
|
|
32
|
+
return buildFunctionTool({ name, description, parameters });
|
|
33
|
+
}
|
|
34
|
+
exports.buildToolFromSchema = buildToolFromSchema;
|
|
35
|
+
function AiFunction(params) {
|
|
36
|
+
return function (target, propertyKey, descriptor) {
|
|
37
|
+
var _a;
|
|
38
|
+
// 引数の型を取得
|
|
39
|
+
const args = Reflect.getMetadata('design:paramtypes', target, propertyKey);
|
|
40
|
+
const tool = buildToolFromSchema(propertyKey, (_a = params === null || params === void 0 ? void 0 : params.description) !== null && _a !== void 0 ? _a : '', args[0]);
|
|
41
|
+
addTool(target, tool);
|
|
42
|
+
return descriptor;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.AiFunction = AiFunction;
|
|
46
|
+
function setAiSystemConfig(obj, config) {
|
|
47
|
+
obj[AI_SYSTEM] = config;
|
|
48
|
+
return obj;
|
|
49
|
+
}
|
|
50
|
+
exports.setAiSystemConfig = setAiSystemConfig;
|
|
51
|
+
function getAiSystemConfig(obj) {
|
|
52
|
+
return obj[AI_SYSTEM];
|
|
53
|
+
}
|
|
54
|
+
exports.getAiSystemConfig = getAiSystemConfig;
|
|
55
|
+
function AiSystem({ model = 'gpt-4-1106-preview', instructions = ``, shots = [], }) {
|
|
56
|
+
return function (target) {
|
|
57
|
+
setAiSystemConfig(target, { model, instructions, shots });
|
|
58
|
+
return target;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
exports.AiSystem = AiSystem;
|
|
62
|
+
class AiToolsAgent {
|
|
63
|
+
constructor(openai) {
|
|
64
|
+
this.openai = openai;
|
|
65
|
+
this.messages = [
|
|
66
|
+
{ role: 'system', content: '' },
|
|
67
|
+
];
|
|
68
|
+
this.results = [];
|
|
69
|
+
}
|
|
70
|
+
get tools() {
|
|
71
|
+
return getTools(this.constructor);
|
|
72
|
+
}
|
|
73
|
+
get config() {
|
|
74
|
+
return getAiSystemConfig(this.constructor);
|
|
75
|
+
}
|
|
76
|
+
completion(tools = this.tools) {
|
|
77
|
+
var _a, _b, _c, _d, _e;
|
|
78
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const message = yield this.openai.chat.completions.create({
|
|
80
|
+
model: this.config.model,
|
|
81
|
+
messages: this.messages,
|
|
82
|
+
tools,
|
|
83
|
+
});
|
|
84
|
+
for (const call of (_d = (_c = (_b = (_a = message.choices) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.tool_calls) !== null && _d !== void 0 ? _d : []) {
|
|
85
|
+
if (call.type === 'function') {
|
|
86
|
+
console.debug('call.function.name:', call.function.name);
|
|
87
|
+
const result = (_e = this[call.function.name]) === null || _e === void 0 ? void 0 : _e.call(this, JSON.parse(call.function.arguments));
|
|
88
|
+
this.results.push(result);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
execute(message, options = {}) {
|
|
94
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
this.messages.push({ role: 'user', content: message });
|
|
96
|
+
yield this.completion(options.tools);
|
|
97
|
+
return this.results.at(-1);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.AiToolsAgent = AiToolsAgent;
|
|
102
|
+
class AnyFunction {
|
|
103
|
+
constructor(openai) {
|
|
104
|
+
this.openai = openai;
|
|
105
|
+
}
|
|
106
|
+
call(_input, args, { instructions = '', model = 'gpt-4o', specs = [], } = {}) {
|
|
107
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const messages = [
|
|
109
|
+
{ role: 'system', content: instructions !== null && instructions !== void 0 ? instructions : '' },
|
|
110
|
+
...(this.convertToChatMessages(specs)),
|
|
111
|
+
{ role: 'user', content: this.parseInput(_input) },
|
|
112
|
+
];
|
|
113
|
+
const res = yield this.openai.chat.completions.create({
|
|
114
|
+
model,
|
|
115
|
+
messages,
|
|
116
|
+
tools: [
|
|
117
|
+
buildToolFromSchema('function', '', args),
|
|
118
|
+
],
|
|
119
|
+
tool_choice: {
|
|
120
|
+
type: 'function',
|
|
121
|
+
function: {
|
|
122
|
+
name: 'function'
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
return JSON.parse(res.choices[0].message.tool_calls[0].function.arguments);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
convertToChatMessages(specs) {
|
|
130
|
+
return specs.map(({ input, output }) => {
|
|
131
|
+
return [
|
|
132
|
+
{ role: 'user', content: this.parseInput(input) },
|
|
133
|
+
{ role: 'assistant', content: JSON.stringify(output) },
|
|
134
|
+
];
|
|
135
|
+
}).flat();
|
|
136
|
+
}
|
|
137
|
+
parseInput(input) {
|
|
138
|
+
return typeof input === 'string' ? input : JSON.stringify(input);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.AnyFunction = AnyFunction;
|
|
142
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../../../../../../packages/@nx-ddd/common/src/infrastructure/externals/agent/agent.ts"],"names":[],"mappings":";;;;AACA,2EAAuE;AAKvE,MAAM,QAAQ,GAAG,YAAqB,CAAC;AACvC,MAAM,SAAS,GAAG,aAAsB,CAAC;AAEzC,SAAgB,OAAO,CAAC,GAAW,EAAE,IAAY;;IAC/C,GAAG,CAAC,QAAQ,CAAC,GAAG,MAAA,GAAG,CAAC,QAAQ,CAAC,mCAAI,EAAE,CAAC;IACpC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,OAAO,GAAG,CAAC;AACb,CAAC;AAJD,0BAIC;AAED,SAAgB,QAAQ,CAAC,GAAW;;IAClC,OAAO,MAAA,GAAG,CAAC,QAAQ,CAAC,mCAAI,EAAE,CAAC;AAC7B,CAAC;AAFD,4BAEC;AAED,SAAS,iBAAiB,CAAC,MAI1B;IACC,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE;YACR,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B;KACF,CAAA;AACH,CAAC;AAED,SAAgB,mBAAmB,CAAC,IAAY,EAAE,WAAmB,EAAE,MAAgB;IACrF,MAAM,UAAU,GAAG,IAAA,sDAAyB,EAAC,MAAM,CAAuB,CAAC;IAC3E,OAAO,iBAAiB,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC;AAC9D,CAAC;AAHD,kDAGC;AAED,SAAgB,UAAU,CAAC,MAA+B;IACxD,OAAO,UAAU,MAAW,EAAE,WAAmB,EAAE,UAA8B;;QAC/E,UAAU;QACV,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC3E,MAAM,IA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Q,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnE,CAAC;CACF;AAjDD,kCAiDC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './agent';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/@nx-ddd/common/src/infrastructure/externals/agent/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UploadTask } from '@angular/fire/storage';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare class CloudStorageService {
|
|
4
|
+
private storage;
|
|
5
|
+
private task;
|
|
6
|
+
private task$;
|
|
7
|
+
readonly progress: import("@angular/core").Signal<number>;
|
|
8
|
+
readonly progress$: Observable<number>;
|
|
9
|
+
getDownloadUrl(filePath: string): Promise<string>;
|
|
10
|
+
private convertToObservable;
|
|
11
|
+
upload(path: string, file: File): UploadTask;
|
|
12
|
+
cancel(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CloudStorageService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@angular/core");
|
|
6
|
+
const storage_1 = require("@angular/fire/storage");
|
|
7
|
+
const rxjs_interop_1 = require("@angular/core/rxjs-interop");
|
|
8
|
+
const rxjs_1 = require("rxjs");
|
|
9
|
+
let CloudStorageService = class CloudStorageService {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.storage = (0, core_1.inject)(storage_1.Storage);
|
|
12
|
+
this.task = (0, core_1.signal)(null);
|
|
13
|
+
this.task$ = (0, rxjs_interop_1.toObservable)(this.task);
|
|
14
|
+
this.progress = (0, rxjs_interop_1.toSignal)(this.task$.pipe((0, rxjs_1.switchMap)(task => task ? this.convertToObservable(task) : (0, rxjs_1.of)(null))));
|
|
15
|
+
this.progress$ = (0, rxjs_interop_1.toObservable)(this.progress);
|
|
16
|
+
}
|
|
17
|
+
getDownloadUrl(filePath) {
|
|
18
|
+
return (0, storage_1.getDownloadURL)((0, storage_1.ref)(this.storage, filePath));
|
|
19
|
+
}
|
|
20
|
+
convertToObservable(task) {
|
|
21
|
+
return new rxjs_1.Observable(sub => {
|
|
22
|
+
task.on('state_changed', snapshot => sub.next(snapshot.bytesTransferred / snapshot.totalBytes * 100));
|
|
23
|
+
task.then(() => (sub.next(null), sub.complete()));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
upload(path, file) {
|
|
27
|
+
this.cancel();
|
|
28
|
+
const storageRef = (0, storage_1.ref)(this.storage, path);
|
|
29
|
+
const task = (0, storage_1.uploadBytesResumable)(storageRef, file);
|
|
30
|
+
this.task.set(task);
|
|
31
|
+
return task;
|
|
32
|
+
}
|
|
33
|
+
cancel() {
|
|
34
|
+
var _a;
|
|
35
|
+
(_a = this.task()) === null || _a === void 0 ? void 0 : _a.cancel();
|
|
36
|
+
this.task.set(null);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.CloudStorageService = CloudStorageService;
|
|
40
|
+
exports.CloudStorageService = CloudStorageService = tslib_1.__decorate([
|
|
41
|
+
(0, core_1.Injectable)({ providedIn: 'any' })
|
|
42
|
+
], CloudStorageService);
|
|
43
|
+
//# sourceMappingURL=cloud-storage.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-storage.service.js","sourceRoot":"","sources":["../../../../../../../packages/@nx-ddd/common/src/infrastructure/externals/cloud-storage/cloud-storage.service.ts"],"names":[],"mappings":";;;;AAAA,wCAA2D;AAC3D,mDAAuG;AACvG,6DAAoE;AACpE,+BAAiD;AAG1C,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAAzB;QACG,YAAO,GAAG,IAAA,aAAM,EAAC,i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AoB,EAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM;;QACJ,MAAA,IAAI,CAAC,IAAI,EAAE,0CAAE,MAAM,EAAE,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;CACF,CAAA;AAlCY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,iBAAU,EAAC,EAAC,UAAU,EAAE,KAAK,EAAC,CAAC;GACnB,mBAAmB,CAkC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cloud-storage.service';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/@nx-ddd/common/src/infrastructure/externals/cloud-storage/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./open-ai.config"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./open-ai.service"), exports);
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/@nx-ddd/common/src/infrastructure/externals/openai/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,4DAAkC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { InjectionToken, Provider } from "@angular/core";
|
|
2
|
+
export interface OpenAiConfig {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const OPEN_AI_CONFIG: InjectionToken<OpenAiConfig>;
|
|
6
|
+
export declare function provideOpenAiConfig(useFactory: () => OpenAiConfig): Provider[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.provideOpenAiConfig = exports.OPEN_AI_CONFIG = void 0;
|
|
4
|
+
const core_1 = require("@angular/core");
|
|
5
|
+
const open_ai_service_1 = require("./open-ai.service");
|
|
6
|
+
const open_ai_service_impl_1 = require("./open-ai.service.impl");
|
|
7
|
+
exports.OPEN_AI_CONFIG = new core_1.InjectionToken('OPENAI_CONFIG');
|
|
8
|
+
function provideOpenAiConfig(useFactory) {
|
|
9
|
+
return [
|
|
10
|
+
{ provide: open_ai_service_1.OPEN_AI_SERVICE, useClass: open_ai_service_impl_1.OpenAiServiceImpl, deps: [exports.OPEN_AI_CONFIG] },
|
|
11
|
+
{ provide: exports.OPEN_AI_CONFIG, useFactory },
|
|
12
|
+
];
|
|
13
|
+
}
|
|
14
|
+
exports.provideOpenAiConfig = provideOpenAiConfig;
|
|
15
|
+
//# sourceMappingURL=open-ai.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-ai.config.js","sourceRoot":"","sources":["../../../../../../../packages/@nx-ddd/common/src/infrastructure/externals/openai/open-ai.config.ts"],"names":[],"mappings":";;;AAAA,wCAAyD;AACzD,uDAAoD;AACpD,iEAA2D;AAK9C,QAAA,cAAc,GAAG,IAAI,qBAAc,CAAe,eAAe,CAAC,CAAC;AAEhF,SAAgB,mBAAmB,CAAC,UAA8B;IAChE,OAAO;QACL,EAAE,OAAO,EAAE,iCAAe,EAAE,QAAQ,EAAE,wCAAiB,EAAE,IAAI,EAAE,CAAC,sBAAc,CAAC,EAAE;QACjF,EAAE,OAAO,EAAE,sBAAc,EAAE,UAAU,EAAE;KACxC,CAAC;AACJ,CAAC;AALD,kDAKC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenAiServiceImpl = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@angular/core");
|
|
6
|
+
const openai_1 = require("openai");
|
|
7
|
+
const open_ai_config_1 = require("./open-ai.config");
|
|
8
|
+
let OpenAiServiceImpl = class OpenAiServiceImpl extends openai_1.OpenAI {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super({ apiKey: config.apiKey });
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
exports.OpenAiServiceImpl = OpenAiServiceImpl;
|
|
14
|
+
exports.OpenAiServiceImpl = OpenAiServiceImpl = tslib_1.__decorate([
|
|
15
|
+
(0, core_1.Injectable)({ providedIn: 'root' }),
|
|
16
|
+
tslib_1.__param(0, (0, core_1.Inject)(open_ai_config_1.OPEN_AI_CONFIG)),
|
|
17
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
18
|
+
], OpenAiServiceImpl);
|
|
19
|
+
//# sourceMappingURL=open-ai.service.impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-ai.service.impl.js","sourceRoot":"","sources":["../../../../../../../packages/@nx-ddd/common/src/infrastructure/externals/openai/open-ai.service.impl.ts"],"names":[],"mappings":";;;;AAAA,wCAAmD;AACnD,mCAAgC;AAChC,qDAAgE;AAGzD,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,eAAM;IAC3C,YAAoC,MAAoB;QACtD,KAAK,CAAC,EAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAC,CAAC,CAAC;IACjC,CAAC;CACF,CAAA;AAJY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,iBAAU,EAAC,EAAC,UAAU,EAAE,MAAM,EAAC,CAAC;IAElB,mBAAA,IAAA,aAAM,EAAC,+BAAc,CAAC,CAAA;;GADxB,iBAAiB,CAI7B"}
|