proxy-api-mcp 1.0.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/.env.example +57 -0
- package/README.md +443 -0
- package/api-tools.json.example +226 -0
- package/dist/examples/env-in-json-usage.d.ts +43 -0
- package/dist/examples/env-in-json-usage.d.ts.map +1 -0
- package/dist/examples/env-in-json-usage.js +242 -0
- package/dist/examples/env-in-json-usage.js.map +1 -0
- package/dist/examples/env-usage.d.ts +7 -0
- package/dist/examples/env-usage.d.ts.map +1 -0
- package/dist/examples/env-usage.js +108 -0
- package/dist/examples/env-usage.js.map +1 -0
- package/dist/examples/preprocessor-usage.d.ts +14 -0
- package/dist/examples/preprocessor-usage.d.ts.map +1 -0
- package/dist/examples/preprocessor-usage.js +196 -0
- package/dist/examples/preprocessor-usage.js.map +1 -0
- package/dist/src/config/env.d.ts +97 -0
- package/dist/src/config/env.d.ts.map +1 -0
- package/dist/src/config/env.js +228 -0
- package/dist/src/config/env.js.map +1 -0
- package/dist/src/core/registry.d.ts +59 -0
- package/dist/src/core/registry.d.ts.map +1 -0
- package/dist/src/core/registry.js +126 -0
- package/dist/src/core/registry.js.map +1 -0
- package/dist/src/core/router.d.ts +34 -0
- package/dist/src/core/router.d.ts.map +1 -0
- package/dist/src/core/router.js +108 -0
- package/dist/src/core/router.js.map +1 -0
- package/dist/src/core/server.d.ts +55 -0
- package/dist/src/core/server.d.ts.map +1 -0
- package/dist/src/core/server.js +159 -0
- package/dist/src/core/server.js.map +1 -0
- package/dist/src/core/session.d.ts +70 -0
- package/dist/src/core/session.d.ts.map +1 -0
- package/dist/src/core/session.js +171 -0
- package/dist/src/core/session.js.map +1 -0
- package/dist/src/core/transports/http.d.ts +16 -0
- package/dist/src/core/transports/http.d.ts.map +1 -0
- package/dist/src/core/transports/http.js +169 -0
- package/dist/src/core/transports/http.js.map +1 -0
- package/dist/src/core/transports/stdio.d.ts +9 -0
- package/dist/src/core/transports/stdio.d.ts.map +1 -0
- package/dist/src/core/transports/stdio.js +32 -0
- package/dist/src/core/transports/stdio.js.map +1 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +22 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/server.d.ts +6 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +121 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/tools/api/builder.d.ts +34 -0
- package/dist/src/tools/api/builder.d.ts.map +1 -0
- package/dist/src/tools/api/builder.js +196 -0
- package/dist/src/tools/api/builder.js.map +1 -0
- package/dist/src/tools/api/executor.d.ts +57 -0
- package/dist/src/tools/api/executor.d.ts.map +1 -0
- package/dist/src/tools/api/executor.js +317 -0
- package/dist/src/tools/api/executor.js.map +1 -0
- package/dist/src/tools/api/index.d.ts +12 -0
- package/dist/src/tools/api/index.d.ts.map +1 -0
- package/dist/src/tools/api/index.js +12 -0
- package/dist/src/tools/api/index.js.map +1 -0
- package/dist/src/tools/api/json/kingdee/kingdee_caiwukuaiji_chunaguanli.json +879 -0
- package/dist/src/tools/api/json/kingdee/kingdee_caiwukuaiji_yingfukuanguanli.json +1673 -0
- package/dist/src/tools/api/json/kingdee/kingdee_caiwukuaiji_yingshoukuanguanli.json +1081 -0
- package/dist/src/tools/api/json/kingdee/kingdee_caiwukuaiji_zongzhang.json +976 -0
- package/dist/src/tools/api/json/kingdee/kingdee_chengbenguanli_biaozhunchengbenfenxi.json +1 -0
- package/dist/src/tools/api/json/kingdee/kingdee_chengbenguanli_chanpinchengbenhesuan.json +1 -0
- package/dist/src/tools/api/json/kingdee/kingdee_chengbenguanli_cunhuohesuan.json +1858 -0
- package/dist/src/tools/api/json/kingdee/kingdee_gongyinglianguanli_caigouguanli.json +1 -0
- package/dist/src/tools/api/json/kingdee/kingdee_gongyinglianguanli_gongyingshangguanli.json +616 -0
- package/dist/src/tools/api/json/kingdee/kingdee_gongyinglianguanli_kucunguanli.json +858 -0
- package/dist/src/tools/api/json/kingdee/kingdee_gongyinglianguanli_xiaoshouguanli.json +858 -0
- package/dist/src/tools/api/json/kingdee/kingdee_gongyinglianguanli_zuzhijianjiesuan.json +858 -0
- package/dist/src/tools/api/json/kingdee/kingdee_jichuguanli_jichuziliao.json +867 -0
- package/dist/src/tools/api/json/kingdee/kingdee_jichuguanli_xiaoxipingtai.json +374 -0
- package/dist/src/tools/api/json/kingdee/kingdee_shengchanzhizao_chejianguanli.json +923 -0
- package/dist/src/tools/api/json/kingdee/kingdee_shengchanzhizao_gongchengshujuguanli.json +923 -0
- package/dist/src/tools/api/json/kingdee/kingdee_shengchanzhizao_shengchanguanli.json +858 -0
- package/dist/src/tools/api/json/kingdee/kingdee_shuiwuguanli_fapiaoguanli.json +1081 -0
- package/dist/src/tools/api/json/kingdee/kingdee_yuangongfuwu_renrenbaoxiao.json +858 -0
- package/dist/src/tools/api/json/kingdee/kingdee_zichanguanli_gudingzichan.json +1 -0
- package/dist/src/tools/api/json-config-loader.d.ts +28 -0
- package/dist/src/tools/api/json-config-loader.d.ts.map +1 -0
- package/dist/src/tools/api/json-config-loader.js +123 -0
- package/dist/src/tools/api/json-config-loader.js.map +1 -0
- package/dist/src/tools/api/json-config-mapping.d.ts +41 -0
- package/dist/src/tools/api/json-config-mapping.d.ts.map +1 -0
- package/dist/src/tools/api/json-config-mapping.js +138 -0
- package/dist/src/tools/api/json-config-mapping.js.map +1 -0
- package/dist/src/tools/api/loader.d.ts +38 -0
- package/dist/src/tools/api/loader.d.ts.map +1 -0
- package/dist/src/tools/api/loader.js +240 -0
- package/dist/src/tools/api/loader.js.map +1 -0
- package/dist/src/tools/api/preprocessor.d.ts +39 -0
- package/dist/src/tools/api/preprocessor.d.ts.map +1 -0
- package/dist/src/tools/api/preprocessor.js +64 -0
- package/dist/src/tools/api/preprocessor.js.map +1 -0
- package/dist/src/tools/api/preprocessors/example.d.ts +59 -0
- package/dist/src/tools/api/preprocessors/example.d.ts.map +1 -0
- package/dist/src/tools/api/preprocessors/example.js +133 -0
- package/dist/src/tools/api/preprocessors/example.js.map +1 -0
- package/dist/src/tools/api/preprocessors/index.d.ts +10 -0
- package/dist/src/tools/api/preprocessors/index.d.ts.map +1 -0
- package/dist/src/tools/api/preprocessors/index.js +29 -0
- package/dist/src/tools/api/preprocessors/index.js.map +1 -0
- package/dist/src/tools/api/preprocessors/kingdee.d.ts +24 -0
- package/dist/src/tools/api/preprocessors/kingdee.d.ts.map +1 -0
- package/dist/src/tools/api/preprocessors/kingdee.js +149 -0
- package/dist/src/tools/api/preprocessors/kingdee.js.map +1 -0
- package/dist/src/tools/api/types.d.ts +174 -0
- package/dist/src/tools/api/types.d.ts.map +1 -0
- package/dist/src/tools/api/types.js +5 -0
- package/dist/src/tools/api/types.js.map +1 -0
- package/dist/src/tools/examples/echo.d.ts +6 -0
- package/dist/src/tools/examples/echo.d.ts.map +1 -0
- package/dist/src/tools/examples/echo.js +61 -0
- package/dist/src/tools/examples/echo.js.map +1 -0
- package/dist/src/tools/types.d.ts +104 -0
- package/dist/src/tools/types.d.ts.map +1 -0
- package/dist/src/tools/types.js +15 -0
- package/dist/src/tools/types.js.map +1 -0
- package/dist/src/tools/validator.d.ts +27 -0
- package/dist/src/tools/validator.d.ts.map +1 -0
- package/dist/src/tools/validator.js +133 -0
- package/dist/src/tools/validator.js.map +1 -0
- package/dist/src/utils/cache.d.ts +14 -0
- package/dist/src/utils/cache.d.ts.map +1 -0
- package/dist/src/utils/cache.js +42 -0
- package/dist/src/utils/cache.js.map +1 -0
- package/dist/src/utils/env-replacer.d.ts +86 -0
- package/dist/src/utils/env-replacer.d.ts.map +1 -0
- package/dist/src/utils/env-replacer.js +196 -0
- package/dist/src/utils/env-replacer.js.map +1 -0
- package/dist/src/utils/errors.d.ts +102 -0
- package/dist/src/utils/errors.d.ts.map +1 -0
- package/dist/src/utils/errors.js +164 -0
- package/dist/src/utils/errors.js.map +1 -0
- package/dist/src/utils/logger.d.ts +77 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/utils/logger.js +155 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { CACHE } from "../../../utils/cache";
|
|
2
|
+
import { env } from '../../../config/env';
|
|
3
|
+
import { ApiExecutor } from '../executor';
|
|
4
|
+
import * as crypto from "crypto";
|
|
5
|
+
export class KingdeeAsyncFetchTokenPreprocessor {
|
|
6
|
+
name = 'kingdee_Preprocessor';
|
|
7
|
+
cache;
|
|
8
|
+
domain = env.get('KINGDEE_DOMAIN');
|
|
9
|
+
appId = env.get('KINGDEE_APP_ID');
|
|
10
|
+
username = env.get('KINGDEE_USERNAME');
|
|
11
|
+
algorithm = env.get('KINGDEE_ALGORITHM');
|
|
12
|
+
secret = env.get('KINGDEE_SECRET');
|
|
13
|
+
lcid = env.get('KINGDEE_LCID');
|
|
14
|
+
acctId = env.get('KINGDEE_ACCT_ID');
|
|
15
|
+
constructor() {
|
|
16
|
+
this.cache = new CACHE();
|
|
17
|
+
}
|
|
18
|
+
async preprocess(requestData) {
|
|
19
|
+
const token = await this.getToken();
|
|
20
|
+
if (requestData.body) {
|
|
21
|
+
// kingdee_request
|
|
22
|
+
const body = requestData.body;
|
|
23
|
+
// kingdee_url
|
|
24
|
+
let kingdeeUrl = null;
|
|
25
|
+
const totalPath = this.domain + body.kingdee_path;
|
|
26
|
+
const lowerPath = totalPath.toLowerCase();
|
|
27
|
+
if (lowerPath.endsWith('.common.kdsvc')) {
|
|
28
|
+
kingdeeUrl = lowerPath;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
kingdeeUrl = `${lowerPath}.common.kdsvc`;
|
|
32
|
+
}
|
|
33
|
+
if (body.kingdee_query) {
|
|
34
|
+
const queryParams = Object.keys(body.kingdee_query)
|
|
35
|
+
.map(key => `${key}=${String(body.kingdee_query[key])}`)
|
|
36
|
+
.join("&");
|
|
37
|
+
const linkCode = kingdeeUrl.includes("?") ? "&" : "?";
|
|
38
|
+
kingdeeUrl = kingdeeUrl + linkCode + queryParams;
|
|
39
|
+
}
|
|
40
|
+
// timestamp
|
|
41
|
+
const timestamp = Date.now().toString();
|
|
42
|
+
// api_signature
|
|
43
|
+
const apigwSec = this.appId.split("_")[1];
|
|
44
|
+
const urlPath = encodeURIComponent(totalPath);
|
|
45
|
+
const context = `POST
|
|
46
|
+
${urlPath}
|
|
47
|
+
|
|
48
|
+
x-api-nonce:${timestamp}
|
|
49
|
+
x-api-timestamp:${timestamp}
|
|
50
|
+
`;
|
|
51
|
+
const signature = crypto
|
|
52
|
+
.createHmac('HmacSHA256', apigwSec)
|
|
53
|
+
.update(context)
|
|
54
|
+
.digest("base64");
|
|
55
|
+
// kdJson
|
|
56
|
+
const data = `${this.appId},${this.username},${this.lcid},`;
|
|
57
|
+
const dataSignature = crypto
|
|
58
|
+
.createHmac('HmacSHA256', this.secret)
|
|
59
|
+
.update(this.appId + data)
|
|
60
|
+
.digest('base64');
|
|
61
|
+
const kdJson = {
|
|
62
|
+
kd_appData: Buffer.from(data, "utf8").toString("base64"),
|
|
63
|
+
kd_signature: dataSignature
|
|
64
|
+
};
|
|
65
|
+
let requestBody = {};
|
|
66
|
+
if (body.kingdee_method === 'GET') {
|
|
67
|
+
requestBody = {};
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
requestBody = body;
|
|
71
|
+
}
|
|
72
|
+
let bodyToken = {};
|
|
73
|
+
if (typeof token === 'string') {
|
|
74
|
+
bodyToken = JSON.parse(token);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
bodyToken = token;
|
|
78
|
+
}
|
|
79
|
+
const cookie = `ASP.NET_SessionId=${String(bodyToken.SessionId)};kdservice-sessionid=${String(bodyToken.KDSVCSessionId)}`;
|
|
80
|
+
const apiExec = new ApiExecutor({
|
|
81
|
+
name: this.name,
|
|
82
|
+
description: '',
|
|
83
|
+
method: 'GET',
|
|
84
|
+
// TODO
|
|
85
|
+
path: this.domain,
|
|
86
|
+
headers: {
|
|
87
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
88
|
+
'Cookie': cookie,
|
|
89
|
+
'X-Api-ClientID': '2.0',
|
|
90
|
+
'x-api-timestamp': timestamp,
|
|
91
|
+
'x-api-nonce': timestamp,
|
|
92
|
+
"x-api-signheaders": "X-Api-TimeStamp,X-Api-Nonce",
|
|
93
|
+
"X-Api-Signature": signature,
|
|
94
|
+
'X-Kd-Appkey': this.appId,
|
|
95
|
+
"X-Kd-Appdata": kdJson.kd_appData,
|
|
96
|
+
"X-Kd-Signature": kdJson.kd_signature
|
|
97
|
+
},
|
|
98
|
+
baseUrl: this.domain,
|
|
99
|
+
});
|
|
100
|
+
await apiExec.execute(requestBody).then((resp) => {
|
|
101
|
+
return resp;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return requestData;
|
|
105
|
+
}
|
|
106
|
+
async getToken() {
|
|
107
|
+
let resultToken = {};
|
|
108
|
+
// kingdee_cache_key
|
|
109
|
+
const cachekey = `${this.acctId}:${this.appId}:${this.username}`;
|
|
110
|
+
// kingdee_hazelcast
|
|
111
|
+
resultToken = this.cache.get(cachekey);
|
|
112
|
+
if (resultToken) {
|
|
113
|
+
// nothing
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const apiExec = new ApiExecutor({
|
|
117
|
+
name: this.name,
|
|
118
|
+
description: '',
|
|
119
|
+
method: 'POST',
|
|
120
|
+
// TODO
|
|
121
|
+
path: `${this.domain}/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.AuthService.LoginBySign.common.kdsvc`,
|
|
122
|
+
baseUrl: this.domain,
|
|
123
|
+
});
|
|
124
|
+
// 请求body
|
|
125
|
+
const ts = Math.floor(Date.now() / 1000).toString();
|
|
126
|
+
const arr = [this.acctId, this.username, this.appId, this.secret, ts].sort();
|
|
127
|
+
const sign = crypto.createHash(this.algorithm)
|
|
128
|
+
.update(arr.join(""), 'utf8')
|
|
129
|
+
.digest('hex'); // 输出十六进制,可改为 'base64'
|
|
130
|
+
const parameters = [
|
|
131
|
+
this.acctId, this.username, this.appId, ts, sign, this.lcid
|
|
132
|
+
];
|
|
133
|
+
resultToken = await apiExec.execute({ parameters }).then((resp) => {
|
|
134
|
+
const result = resp;
|
|
135
|
+
if (result && result.LoginResultType === 1) {
|
|
136
|
+
const cacheValue = { "SessionId": result.Context.SessionId, "KDSVCSessionId": result.KDSVCSessionId };
|
|
137
|
+
this.cache.set(cachekey, cacheValue);
|
|
138
|
+
return cacheValue;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
// 报错
|
|
142
|
+
throw new Error("请求内容为空");
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return resultToken;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=kingdee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kingdee.js","sourceRoot":"","sources":["../../../../../src/tools/api/preprocessors/kingdee.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAUjC,MAAM,OAAO,kCAAkC;IAClC,IAAI,GAAG,sBAAsB,CAAC;IACvC,KAAK,CAAqB;IACjB,MAAM,GAAW,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC3C,KAAK,GAAW,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC1C,QAAQ,GAAW,GAAG,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC/C,SAAS,GAAW,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjD,MAAM,GAAW,GAAG,CAAC,GAAG,CAAC,gBAAgB,CA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,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,gBAAgB,EAAE,MAAM,CAAC,cAAc,EAAE,CAAA;oBACrG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;oBACpC,OAAO,UAAU,CAAA;gBACrB,CAAC;qBAAM,CAAC;oBACJ,KAAK;oBACL,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAC9B,CAAC;YACL,CAAC,CAAC,CAAA;QACN,CAAC;QACD,OAAO,WAAW,CAAA;IACtB,CAAC;CAEJ"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API 工具类型定义
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* HTTP 请求方法
|
|
6
|
+
*/
|
|
7
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
8
|
+
/**
|
|
9
|
+
* 参数位置
|
|
10
|
+
*/
|
|
11
|
+
export type ParameterLocation = 'query' | 'path' | 'header' | 'body';
|
|
12
|
+
/**
|
|
13
|
+
* 参数定义
|
|
14
|
+
*/
|
|
15
|
+
export interface ApiParameter {
|
|
16
|
+
/** 参数名称 */
|
|
17
|
+
name: string;
|
|
18
|
+
/** 参数位置 */
|
|
19
|
+
in: ParameterLocation;
|
|
20
|
+
/** 参数描述 */
|
|
21
|
+
description?: string;
|
|
22
|
+
/** 是否必需 */
|
|
23
|
+
required?: boolean;
|
|
24
|
+
/** 参数类型 */
|
|
25
|
+
type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
|
|
26
|
+
/** 默认值 */
|
|
27
|
+
default?: unknown;
|
|
28
|
+
/** 枚举值 */
|
|
29
|
+
enum?: unknown[];
|
|
30
|
+
/** 数组项类型(当 type='array' 时) */
|
|
31
|
+
items?: {
|
|
32
|
+
type: string;
|
|
33
|
+
properties?: Record<string, unknown>;
|
|
34
|
+
};
|
|
35
|
+
/** 对象属性(当 type='object' 时) */
|
|
36
|
+
properties?: Record<string, ApiParameter>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 请求体定义
|
|
40
|
+
*/
|
|
41
|
+
export interface ApiRequestBody {
|
|
42
|
+
/** 请求体描述 */
|
|
43
|
+
description?: string;
|
|
44
|
+
/** 是否必需 */
|
|
45
|
+
required?: boolean;
|
|
46
|
+
/** 内容类型 */
|
|
47
|
+
contentType?: string;
|
|
48
|
+
/** Schema 定义 */
|
|
49
|
+
schema: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 请求预处理上下文
|
|
53
|
+
*/
|
|
54
|
+
export interface RequestPreprocessContext {
|
|
55
|
+
/** 工具名称 */
|
|
56
|
+
toolName: string;
|
|
57
|
+
/** 原始参数 */
|
|
58
|
+
args: Record<string, unknown>;
|
|
59
|
+
/** API 工具配置 */
|
|
60
|
+
config: ApiToolConfig;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 请求数据 - 预处理器可以修改的所有请求数据
|
|
64
|
+
*/
|
|
65
|
+
export interface RequestData {
|
|
66
|
+
/** 请求 URL(可能包含路径参数占位符) */
|
|
67
|
+
url: string;
|
|
68
|
+
/** 查询参数 */
|
|
69
|
+
query: Record<string, unknown>;
|
|
70
|
+
/** 请求头 */
|
|
71
|
+
headers: Record<string, string>;
|
|
72
|
+
/** 请求体 */
|
|
73
|
+
body?: unknown;
|
|
74
|
+
/** 路径参数 */
|
|
75
|
+
pathParams: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 请求预处理器接口
|
|
79
|
+
*/
|
|
80
|
+
export interface RequestPreprocessor {
|
|
81
|
+
/**
|
|
82
|
+
* 预处理器名称(唯一标识)
|
|
83
|
+
*/
|
|
84
|
+
readonly name: string;
|
|
85
|
+
/**
|
|
86
|
+
* 预处理请求数据
|
|
87
|
+
* @param requestData - 请求数据(可修改)
|
|
88
|
+
* @param context - 预处理上下文
|
|
89
|
+
* @returns 处理后的请求数据或 Promise
|
|
90
|
+
*/
|
|
91
|
+
preprocess(requestData: RequestData, context: RequestPreprocessContext): RequestData | Promise<RequestData>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 响应转换配置
|
|
95
|
+
*/
|
|
96
|
+
export interface ResponseTransform {
|
|
97
|
+
/** 提取数据的 JSONPath 表达式 */
|
|
98
|
+
dataPath?: string;
|
|
99
|
+
/** 字段映射 { 新字段名: 原字段路径 } */
|
|
100
|
+
fieldMapping?: Record<string, string>;
|
|
101
|
+
/** 是否展平嵌套对象 */
|
|
102
|
+
flatten?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 认证配置
|
|
106
|
+
*/
|
|
107
|
+
export interface AuthConfig {
|
|
108
|
+
/** 认证类型 */
|
|
109
|
+
type: 'none' | 'bearer' | 'basic' | 'apikey' | 'custom';
|
|
110
|
+
/** Bearer Token */
|
|
111
|
+
token?: string;
|
|
112
|
+
/** Basic Auth 用户名 */
|
|
113
|
+
username?: string;
|
|
114
|
+
/** Basic Auth 密码 */
|
|
115
|
+
password?: string;
|
|
116
|
+
/** API Key 名称 */
|
|
117
|
+
apiKeyName?: string;
|
|
118
|
+
/** API Key 值 */
|
|
119
|
+
apiKeyValue?: string;
|
|
120
|
+
/** API Key 位置 */
|
|
121
|
+
apiKeyIn?: 'header' | 'query';
|
|
122
|
+
/** 自定义请求头 */
|
|
123
|
+
customHeaders?: Record<string, string>;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* API 工具配置定义
|
|
127
|
+
*/
|
|
128
|
+
export interface ApiToolConfig {
|
|
129
|
+
/** 工具唯一标识 */
|
|
130
|
+
name: string;
|
|
131
|
+
/** 工具标题 */
|
|
132
|
+
title?: string;
|
|
133
|
+
/** 工具描述 */
|
|
134
|
+
description: string;
|
|
135
|
+
/** HTTP 方法 */
|
|
136
|
+
method: HttpMethod;
|
|
137
|
+
/** API 基础 URL */
|
|
138
|
+
baseUrl: string;
|
|
139
|
+
/** API 路径(可包含路径参数,如 /users/{userId}) */
|
|
140
|
+
path: string;
|
|
141
|
+
/** 参数定义列表 */
|
|
142
|
+
parameters?: ApiParameter[];
|
|
143
|
+
/** 请求体定义 */
|
|
144
|
+
requestBody?: ApiRequestBody;
|
|
145
|
+
/** 默认请求头 */
|
|
146
|
+
headers?: Record<string, string>;
|
|
147
|
+
/** 认证配置 */
|
|
148
|
+
auth?: AuthConfig;
|
|
149
|
+
/** 预处理器名称 - 指定使用哪个预处理器 */
|
|
150
|
+
preprocessor?: string;
|
|
151
|
+
/** 响应转换配置 */
|
|
152
|
+
responseTransform?: ResponseTransform;
|
|
153
|
+
/** 超时时间(毫秒) */
|
|
154
|
+
timeout?: number;
|
|
155
|
+
/** 是否启用 */
|
|
156
|
+
enabled?: boolean;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* API 工具配置文件格式
|
|
160
|
+
*/
|
|
161
|
+
export interface ApiToolsConfigFile {
|
|
162
|
+
/** 配置文件版本 */
|
|
163
|
+
version: string;
|
|
164
|
+
/** 全局配置 */
|
|
165
|
+
globals?: {
|
|
166
|
+
baseUrl?: string;
|
|
167
|
+
timeout?: number;
|
|
168
|
+
headers?: Record<string, string>;
|
|
169
|
+
auth?: AuthConfig;
|
|
170
|
+
};
|
|
171
|
+
/** API 工具列表 */
|
|
172
|
+
tools: ApiToolConfig[];
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/tools/api/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAE1F;;GAEG;AACH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AE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,aAAa;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc;IACd,MAAM,EAAE,UAAU,CAAC;IACnB,iBAAiB;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,aAAa;IACb,UAAU,CAAC,EAAE,YAAY,EAAE,CAAC;IAC5B,YAAY;IACZ,WAAW,CAAC,EAAE,cAAc,CAAC;IAC7B,YAAY;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,WAAW;IACX,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,0BAA0B;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa;IACb,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,eAAe;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,aAAa;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW;IACX,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,EAAE,UAAU,CAAC;KACnB,CAAC;IACF,eAAe;IACf,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/tools/api/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"echo.d.ts","sourceRoot":"","sources":["../../../../src/tools/examples/echo.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,eAAO,MAAM,QAAQ,EAAE,UA8DtB,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Echo 工具 - 简单回显输入内容
|
|
3
|
+
*/
|
|
4
|
+
export const echoTool = {
|
|
5
|
+
name: 'echo',
|
|
6
|
+
title: 'Echo Tool',
|
|
7
|
+
description: 'Echoes back the input message. Useful for testing the MCP server.',
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: {
|
|
11
|
+
message: {
|
|
12
|
+
type: 'string',
|
|
13
|
+
description: 'The message to echo back',
|
|
14
|
+
},
|
|
15
|
+
uppercase: {
|
|
16
|
+
type: 'boolean',
|
|
17
|
+
description: 'Whether to convert the message to uppercase',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
required: ['message'],
|
|
21
|
+
},
|
|
22
|
+
outputSchema: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
original: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'The original message',
|
|
28
|
+
},
|
|
29
|
+
echoed: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
description: 'The echoed message',
|
|
32
|
+
},
|
|
33
|
+
timestamp: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
description: 'Timestamp of the echo',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
required: ['original', 'echoed', 'timestamp'],
|
|
39
|
+
},
|
|
40
|
+
handler: (args, context) => {
|
|
41
|
+
const message = args.message;
|
|
42
|
+
const uppercase = args.uppercase;
|
|
43
|
+
const echoed = uppercase ? message.toUpperCase() : message;
|
|
44
|
+
const timestamp = new Date(context.timestamp).toISOString();
|
|
45
|
+
const result = {
|
|
46
|
+
original: message,
|
|
47
|
+
echoed,
|
|
48
|
+
timestamp,
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: 'text',
|
|
54
|
+
text: `Echo: ${echoed}`,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
structuredContent: result,
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=echo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"echo.js","sourceRoot":"","sources":["../../../../src/tools/examples/echo.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,CAAC,MAAM,QAAQ,GAAe;IAClC,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,WAAW;IAClB,WAAW,EAAE,mEAAmE;IAEhF,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,OAAO,EAAE;gBACP,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,0BAA0B;aACxC;YACD,SAAS,EAAE;gBACT,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,6CAA6C;aAC3D;SACF;QACD,QAAQ,EAAE,CAAC,SAAS,CAAC;KACtB;IAED,YAAY,EAAE;QACZ,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,sBAAsB;aACpC;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,oBAAoB;aAClC;YACD,SAAS,EAAE;gBACT,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,uBAAuB;aACrC;SACF;QACD,QAAQ,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,WAAW,CAAC;KAC9C;IAED,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAiB,CAAC;QACvC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAgC,CAAC;QAExD,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QAC3D,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;QAE5D,MAAM,MAAM,GAAG;YACb,QAAQ,EAAE,OAAO;YACjB,MAAM;YACN,SAAS;SACV,CAAC;QAEF,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,SAAS,MAAM,EAAE;iBACxB;aACF;YACD,iBAAiB,EAAE,MAAM;SAC1B,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具类型定义
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 工具处理器执行上下文
|
|
6
|
+
*/
|
|
7
|
+
export interface ToolContext {
|
|
8
|
+
/** 会话 ID */
|
|
9
|
+
sessionId?: string;
|
|
10
|
+
/** 请求元数据 */
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
/** 工具调用的时间戳 */
|
|
13
|
+
timestamp: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 工具执行结果
|
|
17
|
+
*/
|
|
18
|
+
export interface ToolResult {
|
|
19
|
+
/** 文本内容数组,用于 LLM 展示 */
|
|
20
|
+
content: {
|
|
21
|
+
type: 'text' | 'image' | 'resource';
|
|
22
|
+
text?: string;
|
|
23
|
+
data?: string;
|
|
24
|
+
mimeType?: string;
|
|
25
|
+
}[];
|
|
26
|
+
/** 结构化数据对象(可选),符合 outputSchema */
|
|
27
|
+
structuredContent?: Record<string, unknown>;
|
|
28
|
+
/** 是否为错误结果 */
|
|
29
|
+
isError?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 工具处理器函数类型
|
|
33
|
+
*/
|
|
34
|
+
export type ToolHandler = (args: Record<string, unknown>, context: ToolContext) => Promise<ToolResult> | ToolResult;
|
|
35
|
+
/**
|
|
36
|
+
* 工具配置定义
|
|
37
|
+
*/
|
|
38
|
+
export interface ToolConfig {
|
|
39
|
+
/** 工具唯一标识符 */
|
|
40
|
+
name: string;
|
|
41
|
+
/** 工具的可读标题 */
|
|
42
|
+
title?: string;
|
|
43
|
+
/** 工具功能描述 */
|
|
44
|
+
description: string;
|
|
45
|
+
/** 输入参数的 JSON Schema */
|
|
46
|
+
inputSchema: Record<string, unknown>;
|
|
47
|
+
/** 输出结果的 JSON Schema(可选) */
|
|
48
|
+
outputSchema?: Record<string, unknown>;
|
|
49
|
+
/** 工具的业务逻辑处理函数 */
|
|
50
|
+
handler: ToolHandler;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 传输模式类型
|
|
54
|
+
*/
|
|
55
|
+
export type TransportMode = 'stdio' | 'sse' | 'http';
|
|
56
|
+
/**
|
|
57
|
+
* 服务配置
|
|
58
|
+
*/
|
|
59
|
+
export interface ServerConfig {
|
|
60
|
+
/** 服务名称 */
|
|
61
|
+
name: string;
|
|
62
|
+
/** 服务版本 */
|
|
63
|
+
version: string;
|
|
64
|
+
/** 传输模式 */
|
|
65
|
+
transport?: TransportMode;
|
|
66
|
+
/** HTTP 端口(HTTP/SSE 模式) */
|
|
67
|
+
port?: number;
|
|
68
|
+
/** 会话超时时间(毫秒) */
|
|
69
|
+
sessionTimeout?: number;
|
|
70
|
+
/** 日志级别 */
|
|
71
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
72
|
+
/** 工具配置数组 */
|
|
73
|
+
tools?: ToolConfig[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 中间件函数类型
|
|
77
|
+
*/
|
|
78
|
+
export type Middleware = (context: ToolContext, next: () => Promise<ToolResult>) => Promise<ToolResult>;
|
|
79
|
+
/**
|
|
80
|
+
* 会话状态
|
|
81
|
+
*/
|
|
82
|
+
export declare enum SessionStatus {
|
|
83
|
+
UNINITIALIZED = "uninitialized",
|
|
84
|
+
INITIALIZED = "initialized",
|
|
85
|
+
ACTIVE = "active",
|
|
86
|
+
TIMEOUT = "timeout",
|
|
87
|
+
CLOSED = "closed"
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 会话信息
|
|
91
|
+
*/
|
|
92
|
+
export interface Session {
|
|
93
|
+
/** 会话 ID */
|
|
94
|
+
id: string;
|
|
95
|
+
/** 会话状态 */
|
|
96
|
+
status: SessionStatus;
|
|
97
|
+
/** 创建时间 */
|
|
98
|
+
createdAt: number;
|
|
99
|
+
/** 最后活跃时间 */
|
|
100
|
+
lastActiveAt: number;
|
|
101
|
+
/** 会话上下文数据 */
|
|
102
|
+
context: Record<string, unknown>;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,YAAY;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,eAAe;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,uBAAuB;IACvB,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;QACpC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,EAAE,CAAC;IACJ,kCAAk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AE,MAAM,OAAO,CAAC,UAAU,CAAC,KAC5B,OAAO,CAAC,UAAU,CAAC,CAAC;AAEzB;;GAEG;AACH,oBAAY,aAAa;IACvB,aAAa,kBAAkB;IAC/B,WAAW,gBAAgB;IAC3B,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,MAAM,WAAW;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,YAAY;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,WAAW;IACX,MAAM,EAAE,aAAa,CAAC;IACtB,WAAW;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具类型定义
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 会话状态
|
|
6
|
+
*/
|
|
7
|
+
export var SessionStatus;
|
|
8
|
+
(function (SessionStatus) {
|
|
9
|
+
SessionStatus["UNINITIALIZED"] = "uninitialized";
|
|
10
|
+
SessionStatus["INITIALIZED"] = "initialized";
|
|
11
|
+
SessionStatus["ACTIVE"] = "active";
|
|
12
|
+
SessionStatus["TIMEOUT"] = "timeout";
|
|
13
|
+
SessionStatus["CLOSED"] = "closed";
|
|
14
|
+
})(SessionStatus || (SessionStatus = {}));
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AA0FH;;GAEG;AACH,MAAM,CAAN,IAAY,aAMX;AAND,WAAY,aAAa;IACvB,gDAA+B,CAAA;IAC/B,4CAA2B,CAAA;IAC3B,kCAAiB,CAAA;IACjB,oCAAmB,CAAA;IACnB,kCAAiB,CAAA;AACnB,CAAC,EANW,aAAa,KAAb,aAAa,QAMxB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema 验证器
|
|
3
|
+
*/
|
|
4
|
+
import { type ZodSchema } from 'zod';
|
|
5
|
+
/**
|
|
6
|
+
* JSON Schema 转 Zod Schema 的辅助函数
|
|
7
|
+
*/
|
|
8
|
+
export declare class SchemaValidator {
|
|
9
|
+
/**
|
|
10
|
+
* 从 JSON Schema 创建 Zod Schema
|
|
11
|
+
* 注意:这是一个简化的实现,仅支持基本类型
|
|
12
|
+
*/
|
|
13
|
+
static createZodSchema(jsonSchema: Record<string, unknown>): ZodSchema;
|
|
14
|
+
/**
|
|
15
|
+
* 验证输入数据
|
|
16
|
+
*/
|
|
17
|
+
static validateInput(data: unknown, schema: Record<string, unknown>): Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* 验证输出数据(宽松模式,只记录警告)
|
|
20
|
+
*/
|
|
21
|
+
static validateOutput(data: unknown, schema: Record<string, unknown>): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 验证 JSON Schema 本身的有效性
|
|
24
|
+
*/
|
|
25
|
+
static isValidSchema(schema: Record<string, unknown>): boolean;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../../src/tools/validator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAK,KAAK,SAAS,EAAY,MAAM,KAAK,CAAC;AAIlD;;GAEG;AACH,qBAAa,eAAe;IAC1B;;;OAGG;IACH,MAAM,CAAC,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAwEtE;;OAEG;IACH,MAAM,CAAC,aAAa,CAClB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAqB1B;;OAEG;IACH,MAAM,CAAC,cAAc,CACnB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO;IAoBV;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO;CAc/D"}
|