web-dc-api 0.1.4 → 0.1.6
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/cjs/index.js +1 -1
- package/dist/dc.min.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +934 -878
- package/package.json +4 -8
- package/dist/cjs/helia-core-B1Xqha7a.js +0 -1
- package/dist/cjs/helia-core-D8Uv1KjQ.js +0 -1
- package/dist/cjs/polkadot-api-7PhQf3ws.js +0 -1
- package/dist/cjs/polkadot-api-CtrJVWuZ.js +0 -1
- package/dist/esm/chunks/helia-core-BxMqyK2Y.js +0 -1
- package/dist/esm/chunks/helia-core-DMXRpcO-.js +0 -1
- package/dist/esm/chunks/polkadot-api-5Y9Bw8VT.js +0 -1
- package/dist/esm/chunks/polkadot-api-D69Ioun_.js +0 -1
- package/lib/common/blowfish/block.ts +0 -259
- package/lib/common/blowfish/cipher.ts +0 -144
- package/lib/common/blowfish/const.ts +0 -195
- package/lib/common/chain.ts +0 -469
- package/lib/common/commonclient.ts +0 -202
- package/lib/common/constants.ts +0 -55
- package/lib/common/dc-key/ed25519.ts +0 -343
- package/lib/common/dc-key/keyManager.ts +0 -424
- package/lib/common/dcapi.ts +0 -98
- package/lib/common/dcutil.ts +0 -627
- package/lib/common/define.ts +0 -70
- package/lib/common/error.ts +0 -67
- package/lib/common/grpc-dc.ts +0 -104
- package/lib/common/module-system.ts +0 -184
- package/lib/common/service-worker.ts +0 -234
- package/lib/common/types/types.ts +0 -344
- package/lib/dc.ts +0 -701
- package/lib/implements/account/client.ts +0 -185
- package/lib/implements/account/manager.ts +0 -683
- package/lib/implements/aiproxy/client.ts +0 -357
- package/lib/implements/aiproxy/manager.ts +0 -670
- package/lib/implements/cache/client.ts +0 -105
- package/lib/implements/cache/manager.ts +0 -127
- package/lib/implements/comment/client.ts +0 -982
- package/lib/implements/comment/manager.ts +0 -1151
- package/lib/implements/dc/client.ts +0 -51
- package/lib/implements/dc/manager.ts +0 -33
- package/lib/implements/file/client.ts +0 -253
- package/lib/implements/file/file-cache-manager.ts +0 -142
- package/lib/implements/file/manager.ts +0 -1240
- package/lib/implements/file/seekableFileStream.ts +0 -344
- package/lib/implements/file/streamwriter.ts +0 -322
- package/lib/implements/keyvalue/client.ts +0 -376
- package/lib/implements/keyvalue/manager.ts +0 -759
- package/lib/implements/message/client.ts +0 -250
- package/lib/implements/message/manager.ts +0 -215
- package/lib/implements/threaddb/cbor/coding.ts +0 -62
- package/lib/implements/threaddb/cbor/event.ts +0 -336
- package/lib/implements/threaddb/cbor/node.ts +0 -542
- package/lib/implements/threaddb/cbor/record.ts +0 -398
- package/lib/implements/threaddb/common/AsyncMutex.ts +0 -24
- package/lib/implements/threaddb/common/addrinfo.ts +0 -135
- package/lib/implements/threaddb/common/dispatcher.ts +0 -81
- package/lib/implements/threaddb/common/idbstore-adapter.ts +0 -260
- package/lib/implements/threaddb/common/json-patcher.ts +0 -204
- package/lib/implements/threaddb/common/key.ts +0 -290
- package/lib/implements/threaddb/common/level-adapter.ts +0 -235
- package/lib/implements/threaddb/common/lineReader.ts +0 -79
- package/lib/implements/threaddb/common/logstore.ts +0 -215
- package/lib/implements/threaddb/common/transformed-datastore.ts +0 -308
- package/lib/implements/threaddb/core/app.ts +0 -206
- package/lib/implements/threaddb/core/core.ts +0 -230
- package/lib/implements/threaddb/core/db.ts +0 -249
- package/lib/implements/threaddb/core/event.ts +0 -54
- package/lib/implements/threaddb/core/head.ts +0 -89
- package/lib/implements/threaddb/core/identity.ts +0 -171
- package/lib/implements/threaddb/core/logstore.ts +0 -137
- package/lib/implements/threaddb/core/options.ts +0 -14
- package/lib/implements/threaddb/core/record.ts +0 -54
- package/lib/implements/threaddb/db/collection.ts +0 -1910
- package/lib/implements/threaddb/db/db.ts +0 -698
- package/lib/implements/threaddb/db/json2Query.ts +0 -192
- package/lib/implements/threaddb/db/query.ts +0 -524
- package/lib/implements/threaddb/dbclient.ts +0 -543
- package/lib/implements/threaddb/dbmanager.ts +0 -1906
- package/lib/implements/threaddb/lsstoreds/addr_book.ts +0 -549
- package/lib/implements/threaddb/lsstoreds/cache.ts +0 -36
- package/lib/implements/threaddb/lsstoreds/cyclic_batch.ts +0 -87
- package/lib/implements/threaddb/lsstoreds/global.ts +0 -151
- package/lib/implements/threaddb/lsstoreds/headbook.ts +0 -373
- package/lib/implements/threaddb/lsstoreds/keybook.ts +0 -297
- package/lib/implements/threaddb/lsstoreds/logstore.ts +0 -29
- package/lib/implements/threaddb/lsstoreds/metadata.ts +0 -223
- package/lib/implements/threaddb/net/define.ts +0 -149
- package/lib/implements/threaddb/net/grpcClient.ts +0 -589
- package/lib/implements/threaddb/net/grpcserver.ts +0 -146
- package/lib/implements/threaddb/net/net.ts +0 -2047
- package/lib/implements/threaddb/pb/lstore.proto +0 -38
- package/lib/implements/threaddb/pb/lstore.ts +0 -393
- package/lib/implements/threaddb/pb/lstore_pb.d.ts +0 -433
- package/lib/implements/threaddb/pb/lstore_pb.js +0 -1085
- package/lib/implements/threaddb/pb/net.proto +0 -194
- package/lib/implements/threaddb/pb/net_pb.d.ts +0 -2349
- package/lib/implements/threaddb/pb/net_pb.js +0 -5525
- package/lib/implements/threaddb/pb/proto-custom-types.ts +0 -212
- package/lib/implements/util/client.ts +0 -72
- package/lib/implements/util/manager.ts +0 -146
- package/lib/implements/wallet/manager.ts +0 -671
- package/lib/index.ts +0 -57
- package/lib/interfaces/DCContext.ts +0 -51
- package/lib/interfaces/aiproxy-interface.ts +0 -145
- package/lib/interfaces/auth-interface.ts +0 -118
- package/lib/interfaces/cache-interface.ts +0 -22
- package/lib/interfaces/client-interface.ts +0 -11
- package/lib/interfaces/comment-interface.ts +0 -167
- package/lib/interfaces/components/news-component.ts +0 -0
- package/lib/interfaces/database-interface.ts +0 -169
- package/lib/interfaces/file-interface.ts +0 -120
- package/lib/interfaces/index.ts +0 -10
- package/lib/interfaces/keyvalue-interface.ts +0 -156
- package/lib/interfaces/message-interface.ts +0 -22
- package/lib/interfaces/util-interface.ts +0 -31
- package/lib/modules/aiproxy-module.ts +0 -246
- package/lib/modules/auth-module.ts +0 -753
- package/lib/modules/cache-module.ts +0 -99
- package/lib/modules/client-module.ts +0 -71
- package/lib/modules/comment-module.ts +0 -429
- package/lib/modules/components/news-components.ts +0 -390
- package/lib/modules/database-module.ts +0 -598
- package/lib/modules/file-module.ts +0 -291
- package/lib/modules/index.ts +0 -13
- package/lib/modules/keyvalue-module.ts +0 -379
- package/lib/modules/message-module.ts +0 -107
- package/lib/modules/util-module.ts +0 -148
- package/lib/polyfills/process-env-browser.ts +0 -1
- package/lib/proto/datasource.ts +0 -93
- package/lib/proto/dcnet.proto +0 -1601
- package/lib/proto/dcnet_proto.d.ts +0 -22857
- package/lib/proto/dcnet_proto.js +0 -55204
- package/lib/proto/dcnet_proto_sparse.js +0 -55166
- package/lib/proto/oidfetch.proto +0 -25
- package/lib/proto/oidfetch_proto.d.ts +0 -585
- package/lib/proto/oidfetch_proto.js +0 -1247
- package/lib/serverless/babel-browser.ts +0 -39
- package/lib/serverless/base_entity.ts +0 -78
- package/lib/serverless/base_repository.ts +0 -414
- package/lib/serverless/browser_schema_extractor.ts +0 -283
- package/lib/serverless/decorator_factory.ts +0 -322
- package/lib/util/BrowserLineReader.ts +0 -73
- package/lib/util/base64.ts +0 -105
- package/lib/util/bcrypt.ts +0 -206
- package/lib/util/curve25519Encryption.ts +0 -418
- package/lib/util/dccrypt.ts +0 -73
- package/lib/util/logger.ts +0 -104
- package/lib/util/utils.ts +0 -289
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
// modules/keyvalue-module.ts
|
|
2
|
-
// 键值存储功能模块
|
|
3
|
-
|
|
4
|
-
import { DCContext } from "../../lib/interfaces/DCContext";
|
|
5
|
-
import { DCModule, CoreModuleName } from "../common/module-system";
|
|
6
|
-
import { createLogger } from "../util/logger";
|
|
7
|
-
import { AIProxyConfig, OnStreamResponseType, ProxyCallConfig, UserProxyCallConfig } from "../common/types/types";
|
|
8
|
-
import { AIProxyManager } from "../implements/aiproxy/manager";
|
|
9
|
-
import { AIProxyUserPermission } from "../common/constants";
|
|
10
|
-
|
|
11
|
-
const logger = createLogger('KeyValueModule');
|
|
12
|
-
|
|
13
|
-
import { IAICallConfig } from "../common/types/types";
|
|
14
|
-
import { IAIProxyOperations } from "../../lib/interfaces/aiproxy-interface";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* AI代理模块
|
|
19
|
-
* 提供AI代理的配置和调用
|
|
20
|
-
*/
|
|
21
|
-
export class AIProxyModule implements DCModule ,IAIProxyOperations{
|
|
22
|
-
readonly moduleName = CoreModuleName.AIPROXY;
|
|
23
|
-
private aiProxyManager!: AIProxyManager;
|
|
24
|
-
private initialized: boolean = false;
|
|
25
|
-
private aiCallConfig: IAICallConfig | null = null;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 初始化AI代理模块
|
|
29
|
-
* @param context DC上下文
|
|
30
|
-
* @returns 是否初始化成功
|
|
31
|
-
*/
|
|
32
|
-
async initialize(context: DCContext): Promise<boolean> {
|
|
33
|
-
try {
|
|
34
|
-
this.aiProxyManager = new AIProxyManager(
|
|
35
|
-
context.dcutil,
|
|
36
|
-
context.dcNodeClient as any, // Type assertion to bypass service map differences
|
|
37
|
-
context.dcChain,
|
|
38
|
-
context
|
|
39
|
-
);
|
|
40
|
-
this.initialized = true;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return true;
|
|
44
|
-
} catch (error) {
|
|
45
|
-
logger.error("AI代理模块初始化失败:", error);
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 关闭AI代理模块
|
|
52
|
-
*/
|
|
53
|
-
async shutdown(): Promise<void> {
|
|
54
|
-
this.initialized = false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// 创建AI调用的Proxy配置
|
|
59
|
-
async createProxyConfig(
|
|
60
|
-
appId: string,
|
|
61
|
-
configTheme: string,
|
|
62
|
-
): Promise<[number | null, Error | null]> {
|
|
63
|
-
try {
|
|
64
|
-
this.assertInitialized();
|
|
65
|
-
return this.aiProxyManager.createProxyConfig(appId, configTheme);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
return Promise.resolve([null, error as Error]);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async deleteProxyConfig(
|
|
72
|
-
appId: string,
|
|
73
|
-
configTheme: string,
|
|
74
|
-
): Promise<[number | null, Error | null]> {
|
|
75
|
-
try {
|
|
76
|
-
this.assertInitialized();
|
|
77
|
-
return this.aiProxyManager.deleteProxyConfig(appId, configTheme);
|
|
78
|
-
} catch (error) {
|
|
79
|
-
return Promise.resolve([null, error as Error]);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
//配置AI代理的访问配置,如果key的值设置为空,则表示删除该key的配置
|
|
86
|
-
configAIProxy(
|
|
87
|
-
appId: string,
|
|
88
|
-
configAuthor: string,
|
|
89
|
-
configTheme: string,
|
|
90
|
-
serviceName: string,
|
|
91
|
-
serviceConfig?: AIProxyConfig,
|
|
92
|
-
vaccount?: string
|
|
93
|
-
): Promise<[boolean | null, Error | null]> {
|
|
94
|
-
try {
|
|
95
|
-
this.assertInitialized();
|
|
96
|
-
return this.aiProxyManager.configAIProxy(appId, configAuthor, configTheme, serviceName, serviceConfig, vaccount);
|
|
97
|
-
} catch (error) {
|
|
98
|
-
return Promise.resolve([null, error as Error]);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
//配置用户的访问权限
|
|
104
|
-
async configAuth(
|
|
105
|
-
appId: string,
|
|
106
|
-
configAuthor: string,
|
|
107
|
-
configTheme: string,
|
|
108
|
-
authPubkey: string,
|
|
109
|
-
permission: AIProxyUserPermission,
|
|
110
|
-
authConfig: ProxyCallConfig,
|
|
111
|
-
vaccount?: string
|
|
112
|
-
): Promise<[number | null, Error | null]> {
|
|
113
|
-
try {
|
|
114
|
-
this.assertInitialized();
|
|
115
|
-
return this.aiProxyManager.configAuth(appId, configAuthor, configTheme, authPubkey, permission, authConfig, vaccount);
|
|
116
|
-
|
|
117
|
-
} catch (error) {
|
|
118
|
-
return Promise.resolve([null, error as Error]);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
//获取的ai代理的所有配置,包括服务与授权列表
|
|
124
|
-
async GetAIProxyConfig(
|
|
125
|
-
appId: string,
|
|
126
|
-
themeAuthor: string,
|
|
127
|
-
configTheme: string,
|
|
128
|
-
vaccount?: string
|
|
129
|
-
): Promise<[UserProxyCallConfig[] | null,AIProxyConfig[] | null, Error | null]> {
|
|
130
|
-
try {
|
|
131
|
-
this.assertInitialized();
|
|
132
|
-
return this.aiProxyManager.GetAIProxyConfig(appId, themeAuthor, configTheme, vaccount);
|
|
133
|
-
} catch (error) {
|
|
134
|
-
return Promise.resolve([null, null, error as Error]);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
async GetUserOwnAIProxyAuth(
|
|
140
|
-
appId: string,
|
|
141
|
-
themeAuthor: string,
|
|
142
|
-
configTheme: string,
|
|
143
|
-
): Promise<[authConfig: ProxyCallConfig | null, error: Error | null]> {
|
|
144
|
-
try {
|
|
145
|
-
this.assertInitialized();
|
|
146
|
-
return this.aiProxyManager.GetUserOwnAIProxyAuth(appId, themeAuthor, configTheme);
|
|
147
|
-
} catch (error) {
|
|
148
|
-
return Promise.resolve([null, error as Error]);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
//AI相关代理的调用,包括代理与AI的通信或者与MCPServer的通信
|
|
154
|
-
async DoAIProxyCall(
|
|
155
|
-
context: { signal?: AbortSignal },
|
|
156
|
-
reqBody: string,
|
|
157
|
-
forceRefresh: boolean,
|
|
158
|
-
onStreamResponse: OnStreamResponseType,
|
|
159
|
-
appId?: string,
|
|
160
|
-
themeAuthor?: string,
|
|
161
|
-
configTheme?: string,
|
|
162
|
-
serviceName?: string,
|
|
163
|
-
headers?: Record<string, string>,
|
|
164
|
-
path?: string,
|
|
165
|
-
model?: string): Promise<[number | null, Error | null]>
|
|
166
|
-
{
|
|
167
|
-
try{
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
this.assertInitialized();
|
|
171
|
-
if (this.aiCallConfig == null && (!appId || !themeAuthor || !configTheme || !serviceName)) {
|
|
172
|
-
throw new Error("AI调用配置未设置");
|
|
173
|
-
}
|
|
174
|
-
let headersStr = "";
|
|
175
|
-
if (headers) {
|
|
176
|
-
headersStr = JSON.stringify(headers);
|
|
177
|
-
}else if (this.aiCallConfig?.headers) {
|
|
178
|
-
headersStr = JSON.stringify(this.aiCallConfig.headers);
|
|
179
|
-
}
|
|
180
|
-
if (!configTheme) {
|
|
181
|
-
configTheme = this.aiCallConfig?.theme;
|
|
182
|
-
}
|
|
183
|
-
if (!configTheme) {
|
|
184
|
-
throw new Error("配置主题不能为空");
|
|
185
|
-
}
|
|
186
|
-
if (!appId) {
|
|
187
|
-
appId = this.aiCallConfig?.appId;
|
|
188
|
-
}
|
|
189
|
-
if (!appId) {
|
|
190
|
-
throw new Error("应用ID不能为空");
|
|
191
|
-
}
|
|
192
|
-
if (!themeAuthor) {
|
|
193
|
-
themeAuthor = this.aiCallConfig?.themeAuthor;
|
|
194
|
-
}
|
|
195
|
-
if (!themeAuthor) {
|
|
196
|
-
throw new Error("主题作者公钥不能为空");
|
|
197
|
-
}
|
|
198
|
-
if (!serviceName) {
|
|
199
|
-
serviceName = this.aiCallConfig?.service;
|
|
200
|
-
}
|
|
201
|
-
if (!serviceName) {
|
|
202
|
-
throw new Error("服务名称不能为空");
|
|
203
|
-
}
|
|
204
|
-
const res = await this.aiProxyManager.DoAIProxyCall(context,appId , themeAuthor, configTheme, serviceName, reqBody, forceRefresh, onStreamResponse, headersStr, path|| this.aiCallConfig?.path, model|| this.aiCallConfig?.model);
|
|
205
|
-
return [res, null];
|
|
206
|
-
} catch (error) {
|
|
207
|
-
logger.error("AI代理调用失败:", error);
|
|
208
|
-
return [null, error instanceof Error ? error : new Error(String(error))];
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* 设置AI调用的配置
|
|
215
|
-
* @param appId 应用ID
|
|
216
|
-
* @param themeAuthor 主题作者的公钥
|
|
217
|
-
* @param configTheme 配置主题
|
|
218
|
-
* @param serviceName 服务名称
|
|
219
|
-
* @param headers 请求头(可选)
|
|
220
|
-
* @param path 请求路径(可选)
|
|
221
|
-
* @param model 模型名称(可选)
|
|
222
|
-
* @returns Promise<void>
|
|
223
|
-
* */
|
|
224
|
-
async SetAICallConfig(
|
|
225
|
-
callConfig:IAICallConfig
|
|
226
|
-
): Promise<Error | null> {
|
|
227
|
-
try{
|
|
228
|
-
this.assertInitialized();
|
|
229
|
-
this.aiCallConfig = callConfig
|
|
230
|
-
return null
|
|
231
|
-
} catch (error) {
|
|
232
|
-
logger.error("设置AI调用配置失败:", error);
|
|
233
|
-
return error as Error;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* 断言模块已初始化
|
|
240
|
-
*/
|
|
241
|
-
private assertInitialized(): void {
|
|
242
|
-
if (!this.initialized) {
|
|
243
|
-
throw new Error("键值存储模块未初始化");
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|