web-dc-api 0.0.40 → 0.0.41
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/dc.min.js +2 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +132 -24
- package/dist/index.esm.js +1 -1
- package/lib/common/define.ts +32 -22
- package/lib/common/module-system.ts +1 -0
- package/lib/common/service-worker.ts +2 -1
- package/lib/common/types/types.ts +7 -1
- package/lib/dc.ts +74 -17
- package/lib/implements/aiproxy/client.ts +17 -13
- package/lib/implements/file/client.ts +8 -8
- package/lib/implements/file/manager.ts +6 -2
- package/lib/implements/threaddb/core/logstore.ts +4 -4
- package/lib/implements/threaddb/lsstoreds/metadata.ts +23 -22
- package/lib/implements/threaddb/net/net.ts +0 -1
- package/lib/implements/wallet/manager.ts +287 -160
- package/lib/index.ts +15 -3
- package/lib/interfaces/file-interface.ts +1 -1
- package/lib/interfaces/util-interface.ts +1 -1
- package/lib/modules/aiproxy-module.ts +40 -15
- package/lib/modules/auth-module.ts +6 -6
- package/lib/modules/database-module.ts +51 -3
- package/lib/modules/file-module.ts +12 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -16,8 +16,6 @@ import * as $protobuf from 'protobufjs';
|
|
|
16
16
|
import Long from 'long';
|
|
17
17
|
import { Link } from 'multiformats/link';
|
|
18
18
|
import { UnixFS } from '@helia/unixfs';
|
|
19
|
-
import { IAIProxyOperations } from 'lib/interfaces/aiproxy-interface';
|
|
20
|
-
import { IAppInfo as IAppInfo$1 } from 'lib/common/types/types';
|
|
21
19
|
import { HDKey } from '@scure/bip32';
|
|
22
20
|
|
|
23
21
|
declare class Client {
|
|
@@ -235,6 +233,7 @@ declare enum AIStreamResponseFlag {
|
|
|
235
233
|
/** Token数超限,需要继续请求 */
|
|
236
234
|
TOKEN_LIMIT_EXCEEDED = 5,
|
|
237
235
|
TOOLCALL = 6,
|
|
236
|
+
EXTERNAL_EXIT = 7,
|
|
238
237
|
/** 卡住了 */
|
|
239
238
|
STREAM_HANG = 88,
|
|
240
239
|
/** 其他错误 */
|
|
@@ -260,7 +259,11 @@ declare enum UploadStatus {
|
|
|
260
259
|
ENCRYPTING = 1,// 加密中
|
|
261
260
|
UPLOADING = 2,// 上传中
|
|
262
261
|
ERROR = 3,
|
|
263
|
-
ABNORMAL = 4
|
|
262
|
+
ABNORMAL = 4,
|
|
263
|
+
PULLERROR = 5,
|
|
264
|
+
FILESIZEERROR = 6,// 文件大小错误
|
|
265
|
+
FILECOUNTERROR = 7,// 文件总数错误
|
|
266
|
+
NOSPACE = 8
|
|
264
267
|
}
|
|
265
268
|
type ConnectReqMessage = {
|
|
266
269
|
type?: string;
|
|
@@ -2942,10 +2945,10 @@ interface DumpKeyBook {
|
|
|
2942
2945
|
}
|
|
2943
2946
|
interface DumpMetadata {
|
|
2944
2947
|
data: {
|
|
2945
|
-
int64: Record<string, number
|
|
2946
|
-
bool: Record<string, boolean
|
|
2947
|
-
string: Record<string, string
|
|
2948
|
-
bytes: Record<string, Uint8Array
|
|
2948
|
+
int64: Record<string, Record<string, number>>;
|
|
2949
|
+
bool: Record<string, Record<string, boolean>>;
|
|
2950
|
+
string: Record<string, Record<string, string>>;
|
|
2951
|
+
bytes: Record<string, Record<string, Uint8Array>>;
|
|
2949
2952
|
};
|
|
2950
2953
|
}
|
|
2951
2954
|
|
|
@@ -4121,10 +4124,10 @@ interface IFileOperations {
|
|
|
4121
4124
|
* 获取缓存统计信息
|
|
4122
4125
|
* @returns 包含缓存总数和键列表的统计对象
|
|
4123
4126
|
*/
|
|
4124
|
-
getCacheStats(): {
|
|
4127
|
+
getCacheStats(): [{
|
|
4125
4128
|
total: number;
|
|
4126
4129
|
keys: string[];
|
|
4127
|
-
};
|
|
4130
|
+
} | null, Error | null];
|
|
4128
4131
|
/**
|
|
4129
4132
|
* 获取文件内容
|
|
4130
4133
|
* @param cid 文件的内容标识符
|
|
@@ -27127,7 +27130,7 @@ interface IUtilOperations {
|
|
|
27127
27130
|
* @param rewarder
|
|
27128
27131
|
*/
|
|
27129
27132
|
setAppInfo(appId: string, domain: string, fid: string, owner?: string, rewarder?: string): Promise<[boolean | null, Error | null]>;
|
|
27130
|
-
getAppInfo(appId: string): Promise<[IAppInfo
|
|
27133
|
+
getAppInfo(appId: string): Promise<[IAppInfo | null, Error | null]>;
|
|
27131
27134
|
}
|
|
27132
27135
|
|
|
27133
27136
|
declare class DBManager {
|
|
@@ -27482,10 +27485,10 @@ declare class FileModule implements DCModule, IFileOperations {
|
|
|
27482
27485
|
/**
|
|
27483
27486
|
* 获取缓存统计信息
|
|
27484
27487
|
*/
|
|
27485
|
-
getCacheStats(): {
|
|
27488
|
+
getCacheStats(): [{
|
|
27486
27489
|
total: number;
|
|
27487
27490
|
keys: string[];
|
|
27488
|
-
};
|
|
27491
|
+
} | null, Error | null];
|
|
27489
27492
|
/**
|
|
27490
27493
|
* 获取文件内容
|
|
27491
27494
|
*/
|
|
@@ -27825,6 +27828,8 @@ declare class DatabaseModule implements DCModule, IDatabaseOperations {
|
|
|
27825
27828
|
* @returns 线程ID
|
|
27826
27829
|
*/
|
|
27827
27830
|
newDB(name: string, b32Rk: string, b32Sk: string, jsonCollections: ICollectionConfig[]): Promise<[string | null, Error | null]>;
|
|
27831
|
+
loadVerno(threadId: string): Promise<number>;
|
|
27832
|
+
saveVerno(threadId: string, verno: number): Promise<number>;
|
|
27828
27833
|
/**
|
|
27829
27834
|
* 从DC同步数据库
|
|
27830
27835
|
* @param threadid 线程ID
|
|
@@ -27841,7 +27846,7 @@ declare class DatabaseModule implements DCModule, IDatabaseOperations {
|
|
|
27841
27846
|
* @param threadid 数据库ID
|
|
27842
27847
|
* @returns 错误信息或null
|
|
27843
27848
|
*/
|
|
27844
|
-
refreshDBFromDC(threadid: string): Promise<Error | null>;
|
|
27849
|
+
refreshDBFromDC(threadid: string, verno?: number): Promise<Error | null>;
|
|
27845
27850
|
/**
|
|
27846
27851
|
* 同步数据库到DC
|
|
27847
27852
|
* @param tId 线程ID
|
|
@@ -28095,6 +28100,99 @@ declare class CacheModule implements DCModule, ICacheOperations {
|
|
|
28095
28100
|
private assertInitialized;
|
|
28096
28101
|
}
|
|
28097
28102
|
|
|
28103
|
+
/**
|
|
28104
|
+
* AI代理操作接口
|
|
28105
|
+
* 提供AI代理的配置和调用功能
|
|
28106
|
+
*/
|
|
28107
|
+
interface IAIProxyOperations {
|
|
28108
|
+
/**
|
|
28109
|
+
* 创建AI调用的Proxy配置
|
|
28110
|
+
* @param appId 应用ID
|
|
28111
|
+
* @param configTheme 配置主题
|
|
28112
|
+
* @returns [状态码, 错误信息]
|
|
28113
|
+
*/
|
|
28114
|
+
createProxyConfig(appId: string, configTheme: string): Promise<[number | null, Error | null]>;
|
|
28115
|
+
/**
|
|
28116
|
+
* 删除AI调用的Proxy配置
|
|
28117
|
+
* @param appId 应用ID
|
|
28118
|
+
* @param configTheme 配置主题
|
|
28119
|
+
* @returns [状态码, 错误信息]
|
|
28120
|
+
*/
|
|
28121
|
+
deleteProxyConfig(appId: string, configTheme: string): Promise<[number | null, Error | null]>;
|
|
28122
|
+
/**
|
|
28123
|
+
* 配置AI代理的访问配置
|
|
28124
|
+
* 如果serverConfig为空,则表示删除该serviceName的配置
|
|
28125
|
+
* @param appId 应用ID
|
|
28126
|
+
* @param configAuthor 配置作者的公钥
|
|
28127
|
+
* @param configTheme 配置主题
|
|
28128
|
+
* @param serviceName 服务名称
|
|
28129
|
+
* @param serviceConfig 服务配置(可选)
|
|
28130
|
+
* @param vaccount 虚拟账户(可选)
|
|
28131
|
+
* @returns [是否配置成功, 错误信息]
|
|
28132
|
+
*/
|
|
28133
|
+
configAIProxy(appId: string, configAuthor: string, configTheme: string, serviceName: string, serviceConfig?: AIProxyConfig, vaccount?: string): Promise<[boolean | null, Error | null]>;
|
|
28134
|
+
/**
|
|
28135
|
+
* 配置用户的访问权限
|
|
28136
|
+
* @param appId 应用ID
|
|
28137
|
+
* @param configAuthor 配置作者的公钥
|
|
28138
|
+
* @param configTheme 配置主题
|
|
28139
|
+
* @param authPubkey 被授权用户的公钥
|
|
28140
|
+
* @param permission 权限级别
|
|
28141
|
+
* @param authConfig 授权配置
|
|
28142
|
+
* @param vaccount 虚拟账户(可选)
|
|
28143
|
+
* @returns [状态码, 错误信息]
|
|
28144
|
+
*/
|
|
28145
|
+
configAuth(appId: string, configAuthor: string, configTheme: string, authPubkey: string, permission: AIProxyUserPermission, authConfig: ProxyCallConfig, vaccount?: string): Promise<[number | null, Error | null]>;
|
|
28146
|
+
/**
|
|
28147
|
+
* 获取AI代理的所有配置
|
|
28148
|
+
* 包括服务与授权列表
|
|
28149
|
+
* @param appId 应用ID
|
|
28150
|
+
* @param themeAuthor 主题作者的公钥
|
|
28151
|
+
* @param configTheme 配置主题
|
|
28152
|
+
* @param vaccount 虚拟账户(可选)
|
|
28153
|
+
* @returns [用户授权配置列表, AI代理配置列表, 错误信息]
|
|
28154
|
+
*/
|
|
28155
|
+
GetAIProxyConfig(appId: string, themeAuthor: string, configTheme: string, vaccount?: string): Promise<[UserProxyCallConfig[] | null, AIProxyConfig[] | null, Error | null]>;
|
|
28156
|
+
/**
|
|
28157
|
+
* 获取当前用户自身的AI代理授权信息
|
|
28158
|
+
* @param appId 应用ID
|
|
28159
|
+
* @param themeAuthor 主题作者的公钥
|
|
28160
|
+
* @param configTheme 配置主题
|
|
28161
|
+
* @returns [授权配置, 错误信息]
|
|
28162
|
+
*/
|
|
28163
|
+
GetUserOwnAIProxyAuth(appId: string, themeAuthor: string, configTheme: string): Promise<[ProxyCallConfig | null, Error | null]>;
|
|
28164
|
+
/**
|
|
28165
|
+
* 执行AI代理调用
|
|
28166
|
+
* 包括代理与AI的通信或者与MCPServer的通信
|
|
28167
|
+
* @param reqBody 请求体
|
|
28168
|
+
* @param forceRefresh 是否强制刷新,强制刷鞋会消耗一定数量的token,一般在更新了用户授权后,才需要强制刷新
|
|
28169
|
+
* @param onStreamResponse 流式响应回调函数
|
|
28170
|
+
* @param appId 应用ID(可选),为空时使用默认的调用配置中的appId
|
|
28171
|
+
* @param themeAuthor(可选) 主题作者的公钥,为空时使用默认的调用配置中的themeAuthor
|
|
28172
|
+
* @param configTheme(可选) 配置主题,为空时使用默认的调用配置中的configTheme
|
|
28173
|
+
* @param serviceName(可选) 服务器名称,为空时使用默认的调用配置中的serviceName
|
|
28174
|
+
* @param headers 请求头(可选),为空时使用默认的调用配置中的headers
|
|
28175
|
+
* @param path 请求路径(可选),为空时使用默认的调用配置中的path
|
|
28176
|
+
* @param model 模型名称(可选),为空时使用默认的调用配置中的model
|
|
28177
|
+
* @returns 调用状态码
|
|
28178
|
+
*/
|
|
28179
|
+
DoAIProxyCall(context: {
|
|
28180
|
+
signal?: AbortSignal;
|
|
28181
|
+
}, reqBody: string, forceRefresh: boolean, onStreamResponse: OnStreamResponseType, appId?: string, themeAuthor?: string, configTheme?: string, serviceName?: string, headers?: Record<string, string>, path?: string, model?: string): Promise<[number | null, Error | null]>;
|
|
28182
|
+
/**
|
|
28183
|
+
* 设置AI调用的配置
|
|
28184
|
+
* @param appId 应用ID
|
|
28185
|
+
* @param themeAuthor 主题作者的公钥
|
|
28186
|
+
* @param configTheme 配置主题
|
|
28187
|
+
* @param serviceName 服务名称
|
|
28188
|
+
* @param headers 请求头(可选)
|
|
28189
|
+
* @param path 请求路径(可选)
|
|
28190
|
+
* @param model 模型名称(可选)
|
|
28191
|
+
* @returns Promise<void>
|
|
28192
|
+
* */
|
|
28193
|
+
SetAICallConfig(callConfig: IAICallConfig): Promise<Error | null>;
|
|
28194
|
+
}
|
|
28195
|
+
|
|
28098
28196
|
/**
|
|
28099
28197
|
* AI代理模块
|
|
28100
28198
|
* 提供AI代理的配置和调用
|
|
@@ -28291,7 +28389,7 @@ declare class DC implements DCContext {
|
|
|
28291
28389
|
* @param moduleName 模块名称
|
|
28292
28390
|
* @returns 模块实例
|
|
28293
28391
|
*/
|
|
28294
|
-
getModule<T extends DCModule>(moduleName: string): T;
|
|
28392
|
+
getModule<T extends DCModule>(moduleName: string): T | null;
|
|
28295
28393
|
/**
|
|
28296
28394
|
* 断言DC已初始化
|
|
28297
28395
|
* @throws 如果DC未初始化则抛出错误
|
|
@@ -28301,52 +28399,52 @@ declare class DC implements DCContext {
|
|
|
28301
28399
|
* 获取文件模块
|
|
28302
28400
|
* @returns 文件模块实例
|
|
28303
28401
|
*/
|
|
28304
|
-
get file(): FileModule;
|
|
28402
|
+
get file(): FileModule | null;
|
|
28305
28403
|
/**
|
|
28306
28404
|
* 获取认证模块
|
|
28307
28405
|
* @returns 认证模块实例
|
|
28308
28406
|
*/
|
|
28309
|
-
get auth(): AuthModule;
|
|
28407
|
+
get auth(): AuthModule | null;
|
|
28310
28408
|
/**
|
|
28311
28409
|
* 获取评论模块
|
|
28312
28410
|
* @returns 评论模块实例
|
|
28313
28411
|
*/
|
|
28314
|
-
get comment(): CommentModule;
|
|
28412
|
+
get comment(): CommentModule | null;
|
|
28315
28413
|
/**
|
|
28316
28414
|
* 获取数据库模块
|
|
28317
28415
|
* @returns 数据库模块实例
|
|
28318
28416
|
*/
|
|
28319
|
-
get db(): DatabaseModule;
|
|
28417
|
+
get db(): DatabaseModule | null;
|
|
28320
28418
|
/**
|
|
28321
28419
|
* 获取消息模块
|
|
28322
28420
|
* @returns 消息模块实例
|
|
28323
28421
|
*/
|
|
28324
|
-
get message(): MessageModule;
|
|
28422
|
+
get message(): MessageModule | null;
|
|
28325
28423
|
/**
|
|
28326
28424
|
* 获取键值存储模块
|
|
28327
28425
|
* @returns 键值存储模块实例
|
|
28328
28426
|
*/
|
|
28329
|
-
get keyValue(): KeyValueModule;
|
|
28427
|
+
get keyValue(): KeyValueModule | null;
|
|
28330
28428
|
/**
|
|
28331
28429
|
* client
|
|
28332
28430
|
* @returns 客户端实例
|
|
28333
28431
|
*/
|
|
28334
|
-
get client(): ClientModule;
|
|
28432
|
+
get client(): ClientModule | null;
|
|
28335
28433
|
/**
|
|
28336
28434
|
* 缓存模块
|
|
28337
28435
|
* @returns 缓存模块实例
|
|
28338
28436
|
*/
|
|
28339
|
-
get cache(): CacheModule;
|
|
28437
|
+
get cache(): CacheModule | null;
|
|
28340
28438
|
/**
|
|
28341
28439
|
* AI代理模块
|
|
28342
28440
|
* @returns AI代理模块实例
|
|
28343
28441
|
*/
|
|
28344
|
-
get aiproxy(): AIProxyModule;
|
|
28442
|
+
get aiproxy(): AIProxyModule | null;
|
|
28345
28443
|
/**
|
|
28346
28444
|
* 工具模块
|
|
28347
28445
|
* @returns 工具模块实例
|
|
28348
28446
|
*/
|
|
28349
|
-
get util(): UtilModule;
|
|
28447
|
+
get util(): UtilModule | null;
|
|
28350
28448
|
}
|
|
28351
28449
|
|
|
28352
28450
|
/**
|
|
@@ -28443,5 +28541,15 @@ declare const Errors: {
|
|
|
28443
28541
|
NO_CHAIN_UTIL: AppError;
|
|
28444
28542
|
};
|
|
28445
28543
|
|
|
28544
|
+
declare global {
|
|
28545
|
+
interface PromiseConstructor {
|
|
28546
|
+
withResolvers<T = any>(): {
|
|
28547
|
+
promise: Promise<T>;
|
|
28548
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
28549
|
+
reject: (reason?: any) => void;
|
|
28550
|
+
};
|
|
28551
|
+
}
|
|
28552
|
+
}
|
|
28553
|
+
|
|
28446
28554
|
export { AIProxyModule, AIStreamResponseFlag, AuthModule, CacheModule, ClientModule, CommentModule, CommentType, CoreModuleName, DC, DatabaseModule, Direction, Ed25519PrivKey, Ed25519PubKey, Errors, FileModule, KeyManager, KeyValueModule, LogLevel, MessageModule, ModuleSystem, NFTBindStatus, OffChainOpTimes, OffChainOpTimesLimit, OffChainSpaceLimit, ThemePermission, UploadStatus, UtilModule, configureLogger, createLogger, dc_protocol, dial_timeout, isConnectReqMessage, isEIP712SignReqMessage, isServiceWorkerActive, isSignReqMessage, keyExpire, registerServiceWorker, updateServiceWorker, walletOrigin, walletUrl, walletWindowName };
|
|
28447
28555
|
export type { AIChatMessage, AIChatMessageRequest, AIMessageContent, AIMessageMediaSource, AIProxyConfig, APPInfo, Account, ConnectReqMessage, DCConnectInfo, DCContext, DCModule, EIP712SignReqMessage, FileTransmit, FunctionDef, IAICallConfig, IAppInfo, IAuthOperations, ICacheOperations, IClientOperations, ICommentOperations, IDatabaseOperations, IFileOperations, IKeyValueOperations, IMessageOperations, IUtilOperations, ModelConfig, OnStreamResponseType, ProxyCallConfig, ResponseMessage, SendMessage, SignHandler, SignReqMessage, SignReqMessageData, SignResponseMessage, ThemeAuthInfo, ThemeComment, ThemeObj, ToolDefinition, User, UserProxyCallConfig };
|