@reachv2/sdk 0.3.3 → 0.5.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/README.md +35 -10
- package/dist/client.d.ts +12 -0
- package/dist/client.js +15 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.js +6 -0
- package/dist/resources/accounts.d.ts +16 -4
- package/dist/resources/accounts.js +11 -6
- package/dist/resources/agent-api.d.ts +11 -31
- package/dist/resources/agent-api.js +16 -55
- package/dist/resources/auth.d.ts +25 -1
- package/dist/resources/auth.js +41 -0
- package/dist/resources/billing.d.ts +142 -0
- package/dist/resources/billing.js +52 -0
- package/dist/resources/channel-admin.d.ts +94 -0
- package/dist/resources/channel-admin.js +155 -0
- package/dist/resources/data-sources.d.ts +5 -23
- package/dist/resources/data-sources.js +5 -43
- package/dist/resources/effect.d.ts +4 -10
- package/dist/resources/effect.js +4 -19
- package/dist/resources/email-channel.d.ts +87 -0
- package/dist/resources/email-channel.js +62 -0
- package/dist/resources/lightrag.d.ts +4 -0
- package/dist/resources/lightrag.js +4 -0
- package/dist/resources/merchant.d.ts +87 -0
- package/dist/resources/merchant.js +143 -0
- package/dist/resources/quota.d.ts +30 -0
- package/dist/resources/quota.js +15 -0
- package/dist/resources/shared-billing.d.ts +205 -0
- package/dist/resources/shared-billing.js +67 -0
- package/dist/types.d.ts +242 -3
- package/package.json +3 -2
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SharedBillingResource — 统一计费(Server API `/api/shared/billing/*`)。
|
|
3
|
+
*
|
|
4
|
+
* 鉴权:订阅 / 用量 / 加密收款端点均要求 **账户 JWT**(`requireAuth`)+ 租户成员
|
|
5
|
+
* (`tenantId` 显式传参,服务端用登录账号校验成员身份);`plans` / `token-packs` /
|
|
6
|
+
* `crypto/methods` 公开。
|
|
7
|
+
*
|
|
8
|
+
* 未封装:
|
|
9
|
+
* - `POST /subscriptions`(已退役,恒 410 PLATFORM_PLAN_RETIRED;新购走 `/api/seats`)
|
|
10
|
+
* - `POST /webhook` / `POST /payments-events`(Stripe/引擎回调,验签即认证,不属于 SDK 调用面)
|
|
11
|
+
*/
|
|
12
|
+
export class SharedBillingResource {
|
|
13
|
+
constructor(request) {
|
|
14
|
+
this.request = request;
|
|
15
|
+
}
|
|
16
|
+
/** 席位档位套餐列表(**裸数组**,与 `/api/billing/plans` 的 `{ plans }` 不同) */
|
|
17
|
+
listPlans() {
|
|
18
|
+
return this.request("GET", "/api/shared/billing/plans");
|
|
19
|
+
}
|
|
20
|
+
/** 可购买 Token 包列表(**裸数组**,含 cryptoAmount / price 等全字段) */
|
|
21
|
+
listTokenPacks() {
|
|
22
|
+
return this.request("GET", "/api/shared/billing/token-packs");
|
|
23
|
+
}
|
|
24
|
+
/** 租户平台订阅列表(含 plan 摘要,按创建时间倒序) */
|
|
25
|
+
listSubscriptions(tenantId) {
|
|
26
|
+
return this.request("GET", `/api/shared/billing/subscriptions?tenantId=${encodeURIComponent(tenantId)}`);
|
|
27
|
+
}
|
|
28
|
+
/** 当前订阅 + 本月用量 + 分资源配额 + 席位/token 池(无套餐且无席位时 subscription/quota 为 null) */
|
|
29
|
+
getCurrentSubscription(tenantId) {
|
|
30
|
+
return this.request("GET", `/api/shared/billing/subscriptions/current?tenantId=${encodeURIComponent(tenantId)}`);
|
|
31
|
+
}
|
|
32
|
+
/** 记录用量(统一账本;`llm_tokens` 的 token 数落在 quantity) */
|
|
33
|
+
recordUsage(params) {
|
|
34
|
+
return this.request("POST", "/api/shared/billing/usage", params);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 购买 Token 包(fiat Stripe Checkout;渠道未配置时落 pending 单并返回 `manual: true`)。
|
|
38
|
+
* `usePartnerBalance: true` 时用推广余额全额抵扣,成功即 completed。
|
|
39
|
+
*/
|
|
40
|
+
purchaseTokenPack(params) {
|
|
41
|
+
return this.request("POST", "/api/shared/billing/token-packs/purchase", params);
|
|
42
|
+
}
|
|
43
|
+
/** 已开放的加密收款通道(链 + 稳定币;未开放返回 `enabled: false`) */
|
|
44
|
+
listCryptoMethods() {
|
|
45
|
+
return this.request("GET", "/api/shared/billing/crypto/methods");
|
|
46
|
+
}
|
|
47
|
+
/** 创建加密订单(返回 payTo / amountWei / 过期时间,用户链上转账后用返回的 orderId confirm) */
|
|
48
|
+
createCryptoOrder(params) {
|
|
49
|
+
return this.request("POST", "/api/shared/billing/crypto/orders", params);
|
|
50
|
+
}
|
|
51
|
+
/** 我的加密订单列表(读取时惰性把超时 pending 单置 expired) */
|
|
52
|
+
listCryptoOrders(tenantId) {
|
|
53
|
+
return this.request("GET", `/api/shared/billing/crypto/orders?tenantId=${encodeURIComponent(tenantId)}`);
|
|
54
|
+
}
|
|
55
|
+
/** 加密订单详情 */
|
|
56
|
+
getCryptoOrder(orderId, tenantId) {
|
|
57
|
+
return this.request("GET", `/api/shared/billing/crypto/orders/${encodeURIComponent(orderId)}?tenantId=${encodeURIComponent(tenantId)}`);
|
|
58
|
+
}
|
|
59
|
+
/** 取消待付款订单(仅 pending/expired 可取消,已支付不可) */
|
|
60
|
+
cancelCryptoOrder(orderId, tenantId) {
|
|
61
|
+
return this.request("POST", `/api/shared/billing/crypto/orders/${encodeURIComponent(orderId)}/cancel`, { tenantId });
|
|
62
|
+
}
|
|
63
|
+
/** 提交链上 txHash 换取引擎回执并生效 */
|
|
64
|
+
confirmCryptoOrder(orderId, params) {
|
|
65
|
+
return this.request("POST", `/api/shared/billing/crypto/orders/${encodeURIComponent(orderId)}/confirm`, params);
|
|
66
|
+
}
|
|
67
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -525,7 +525,7 @@ export interface AgentChatParams {
|
|
|
525
525
|
conversationId?: string;
|
|
526
526
|
/** 钱包地址:交易/综合 agent 构造链上操作时必填 */
|
|
527
527
|
userAddress?: string;
|
|
528
|
-
/** 目标链 id(Ethereum/BNB/Polygon/Arbitrum/Base/Optimism
|
|
528
|
+
/** 目标链 id(Ethereum/BNB/Polygon/Arbitrum/Base/Optimism 等) */
|
|
529
529
|
chainId?: number;
|
|
530
530
|
agentxAgentId?: number;
|
|
531
531
|
tools?: ChatToolDefinition[];
|
|
@@ -570,13 +570,13 @@ export interface LightRAGKeyInfo {
|
|
|
570
570
|
export interface LightRAGDocumentParams {
|
|
571
571
|
text: string;
|
|
572
572
|
file_name?: string;
|
|
573
|
-
/** Per-user namespace within a bot (defaults to botId = shared) */
|
|
573
|
+
/** Per-user namespace within a bot (defaults to botId = shared). 平台共享 namespace `market` / `onchain` 只读(仅 query 可用) */
|
|
574
574
|
namespace?: string;
|
|
575
575
|
}
|
|
576
576
|
export interface LightRAGQueryParams {
|
|
577
577
|
query: string;
|
|
578
578
|
mode?: "mix" | "local" | "global" | "hybrid" | "naive";
|
|
579
|
-
/** Per-user namespace within a bot (defaults to botId = shared) */
|
|
579
|
+
/** Per-user namespace within a bot (defaults to botId = shared). 平台共享 namespace `market` / `onchain` 只读可查 */
|
|
580
580
|
namespace?: string;
|
|
581
581
|
}
|
|
582
582
|
export interface LightRAGQueryResult {
|
|
@@ -903,3 +903,242 @@ export interface HealthInfo {
|
|
|
903
903
|
uptime?: number;
|
|
904
904
|
[key: string]: unknown;
|
|
905
905
|
}
|
|
906
|
+
/** 商户入驻参数(POST /api/auth/merchant-onboard) */
|
|
907
|
+
export interface MerchantOnboardParams {
|
|
908
|
+
/** 商户名称(owner 未绑定时用于创建商户) */
|
|
909
|
+
name: string;
|
|
910
|
+
}
|
|
911
|
+
/** 商户入驻 / 接受邀请结果:在 AuthResult 基础上追加绑定信息 */
|
|
912
|
+
export interface MerchantAuthResult extends AuthResult {
|
|
913
|
+
merchantId?: string | number;
|
|
914
|
+
role?: string;
|
|
915
|
+
accepted?: boolean;
|
|
916
|
+
alreadyMember?: boolean;
|
|
917
|
+
alreadyProcessed?: boolean;
|
|
918
|
+
}
|
|
919
|
+
/** 公开商户邀请信息(GET /api/auth/merchant-invites/:token,登录前可读) */
|
|
920
|
+
export interface MerchantInviteInfo {
|
|
921
|
+
merchant: {
|
|
922
|
+
id: string | number;
|
|
923
|
+
name: string;
|
|
924
|
+
};
|
|
925
|
+
email: string | null;
|
|
926
|
+
role: string;
|
|
927
|
+
status: string;
|
|
928
|
+
}
|
|
929
|
+
/** 发送邮箱验证码(POST /api/auth/email-code/send) */
|
|
930
|
+
export interface EmailCodeSendResult {
|
|
931
|
+
sent: boolean;
|
|
932
|
+
ttlSec: number;
|
|
933
|
+
}
|
|
934
|
+
/** 验证码登录参数(POST /api/auth/email-code/login;启用 MFA 的账户需再带 mfaCode) */
|
|
935
|
+
export interface EmailCodeLoginParams {
|
|
936
|
+
email: string;
|
|
937
|
+
code: string;
|
|
938
|
+
mfaCode?: string;
|
|
939
|
+
}
|
|
940
|
+
/** 当前账户 + 租户成员关系(GET /api/auth/me) */
|
|
941
|
+
export interface AccountMeResult extends AuthAccount {
|
|
942
|
+
tenants: Array<{
|
|
943
|
+
id: string | number;
|
|
944
|
+
name: string;
|
|
945
|
+
slug: string;
|
|
946
|
+
role: string;
|
|
947
|
+
}>;
|
|
948
|
+
}
|
|
949
|
+
/** 商户看板(GET /api/merchant/dashboard;camelCase) */
|
|
950
|
+
export interface MerchantDashboardStats {
|
|
951
|
+
projects: number;
|
|
952
|
+
bots: number;
|
|
953
|
+
totalTokens: number;
|
|
954
|
+
totalConversations: number;
|
|
955
|
+
documentsCount: number;
|
|
956
|
+
activeAgents: number;
|
|
957
|
+
plan: string;
|
|
958
|
+
planLabel?: string | null;
|
|
959
|
+
seatCount?: number | null;
|
|
960
|
+
planStartedAt?: string | null;
|
|
961
|
+
planExpiresAt?: string | null;
|
|
962
|
+
docLimit?: number | null;
|
|
963
|
+
tokenQuota?: number | null;
|
|
964
|
+
tokensUsedThisMonth?: number;
|
|
965
|
+
tokensRemaining?: number | null;
|
|
966
|
+
conversationTrend?: unknown[];
|
|
967
|
+
botDistribution?: unknown[];
|
|
968
|
+
quality?: unknown;
|
|
969
|
+
groupActivity?: unknown;
|
|
970
|
+
}
|
|
971
|
+
/** 转人工工单(GET /api/merchant/tickets,camelCase) */
|
|
972
|
+
export interface MerchantTicket {
|
|
973
|
+
id: string;
|
|
974
|
+
conversationId: string | null;
|
|
975
|
+
botId: string | null;
|
|
976
|
+
merchantId: string;
|
|
977
|
+
channel: string | null;
|
|
978
|
+
title: string | null;
|
|
979
|
+
status: "open" | "in_progress" | "resolved" | "closed" | string;
|
|
980
|
+
handler: string | null;
|
|
981
|
+
createdAt: string;
|
|
982
|
+
updatedAt: string;
|
|
983
|
+
}
|
|
984
|
+
export interface MerchantTicketUpdateParams {
|
|
985
|
+
status?: "open" | "in_progress" | "resolved" | "closed";
|
|
986
|
+
handler?: string;
|
|
987
|
+
}
|
|
988
|
+
/** 商户项目(GET /api/merchant/projects;snake_case + 聚合计数) */
|
|
989
|
+
export interface MerchantProject {
|
|
990
|
+
id: string;
|
|
991
|
+
name: string;
|
|
992
|
+
description?: string | null;
|
|
993
|
+
bot_count?: number;
|
|
994
|
+
total_tokens?: number;
|
|
995
|
+
total_conversations?: number;
|
|
996
|
+
created_at?: string;
|
|
997
|
+
updated_at?: string;
|
|
998
|
+
[key: string]: unknown;
|
|
999
|
+
}
|
|
1000
|
+
/** 商户 Bot(GET /api/merchant/projects/:id/bots;snake_case) */
|
|
1001
|
+
export interface MerchantBot {
|
|
1002
|
+
id: string;
|
|
1003
|
+
project_id: string;
|
|
1004
|
+
name: string;
|
|
1005
|
+
type?: string;
|
|
1006
|
+
status?: string;
|
|
1007
|
+
description?: string | null;
|
|
1008
|
+
prompt?: string | null;
|
|
1009
|
+
[key: string]: unknown;
|
|
1010
|
+
}
|
|
1011
|
+
export interface MerchantProjectCreateParams {
|
|
1012
|
+
name: string;
|
|
1013
|
+
description?: string;
|
|
1014
|
+
}
|
|
1015
|
+
export interface MerchantBotCreateParams {
|
|
1016
|
+
name: string;
|
|
1017
|
+
description?: string;
|
|
1018
|
+
prompt?: string;
|
|
1019
|
+
}
|
|
1020
|
+
/** Bot LLM 配置(GET /api/merchant/.../llm-config 返回 snake_case;未配置时为 null) */
|
|
1021
|
+
export interface MerchantLlmConfig {
|
|
1022
|
+
provider: string;
|
|
1023
|
+
endpoint_url: string | null;
|
|
1024
|
+
api_key: string | null;
|
|
1025
|
+
model: string | null;
|
|
1026
|
+
}
|
|
1027
|
+
/** 写入 Bot LLM 配置(BYOK) */
|
|
1028
|
+
export interface MerchantLlmConfigInput {
|
|
1029
|
+
provider: string;
|
|
1030
|
+
endpointUrl?: string;
|
|
1031
|
+
apiKey?: string;
|
|
1032
|
+
model?: string;
|
|
1033
|
+
}
|
|
1034
|
+
export interface MerchantChain {
|
|
1035
|
+
chainId: number;
|
|
1036
|
+
name: string;
|
|
1037
|
+
rpcUrl: string;
|
|
1038
|
+
explorerUrl?: string | null;
|
|
1039
|
+
symbol?: string | null;
|
|
1040
|
+
decimals?: number | null;
|
|
1041
|
+
[key: string]: unknown;
|
|
1042
|
+
}
|
|
1043
|
+
export interface MerchantChainAddParams {
|
|
1044
|
+
chainId: number;
|
|
1045
|
+
name: string;
|
|
1046
|
+
rpcUrl: string;
|
|
1047
|
+
explorerUrl?: string;
|
|
1048
|
+
symbol?: string;
|
|
1049
|
+
decimals?: number;
|
|
1050
|
+
}
|
|
1051
|
+
/** GET /api/merchant/chains */
|
|
1052
|
+
export interface MerchantChainList {
|
|
1053
|
+
chains: MerchantChain[];
|
|
1054
|
+
/** 自定义链 id 列表(内置链之外) */
|
|
1055
|
+
custom: number[];
|
|
1056
|
+
}
|
|
1057
|
+
/** 可授予的商户团队角色(owner 仅商户所有者,不可授予) */
|
|
1058
|
+
export type MerchantTeamRole = "admin" | "editor" | "member" | "viewer";
|
|
1059
|
+
export interface MerchantTeamMember {
|
|
1060
|
+
key: string;
|
|
1061
|
+
accountId: string | null;
|
|
1062
|
+
role: "owner" | MerchantTeamRole;
|
|
1063
|
+
status: "active" | "invited" | string;
|
|
1064
|
+
username: string | null;
|
|
1065
|
+
email: string | null;
|
|
1066
|
+
wallet: string | null;
|
|
1067
|
+
joinedAt: string | null;
|
|
1068
|
+
/** 仅 owner/admin 可见:待接受邀请的 token */
|
|
1069
|
+
inviteToken?: string;
|
|
1070
|
+
}
|
|
1071
|
+
export interface MerchantTeamResult {
|
|
1072
|
+
merchantId: string;
|
|
1073
|
+
canManage: boolean;
|
|
1074
|
+
members: MerchantTeamMember[];
|
|
1075
|
+
}
|
|
1076
|
+
export interface MerchantTeamMemberAddParams {
|
|
1077
|
+
email?: string;
|
|
1078
|
+
wallet?: string;
|
|
1079
|
+
role?: MerchantTeamRole;
|
|
1080
|
+
}
|
|
1081
|
+
export interface MerchantTeamInviteParams {
|
|
1082
|
+
email: string;
|
|
1083
|
+
role?: MerchantTeamRole;
|
|
1084
|
+
}
|
|
1085
|
+
export interface MerchantTeamInviteResult {
|
|
1086
|
+
ok: boolean;
|
|
1087
|
+
id: string | number;
|
|
1088
|
+
email: string;
|
|
1089
|
+
role: MerchantTeamRole;
|
|
1090
|
+
status: "invited" | string;
|
|
1091
|
+
inviteToken: string;
|
|
1092
|
+
inviteUrl: string;
|
|
1093
|
+
}
|
|
1094
|
+
/** 通道连接 / 状态结果(各平台字段不同,保留索引签名) */
|
|
1095
|
+
export interface ChannelActionResult {
|
|
1096
|
+
success?: boolean;
|
|
1097
|
+
status?: string;
|
|
1098
|
+
message?: string;
|
|
1099
|
+
qr?: string | null;
|
|
1100
|
+
[key: string]: unknown;
|
|
1101
|
+
}
|
|
1102
|
+
export interface SendTextParams {
|
|
1103
|
+
chatId: string;
|
|
1104
|
+
text: string;
|
|
1105
|
+
}
|
|
1106
|
+
/** Telegram 文件发送:documentName 指向该 Bot 已上传的文档 */
|
|
1107
|
+
export interface TelegramSendFileParams {
|
|
1108
|
+
chatId: string;
|
|
1109
|
+
documentName: string;
|
|
1110
|
+
caption?: string;
|
|
1111
|
+
}
|
|
1112
|
+
export interface DiscordDmParams {
|
|
1113
|
+
userId: string;
|
|
1114
|
+
text: string;
|
|
1115
|
+
/** 默认 true:未 opt-in / 不可达则拒绝发送 */
|
|
1116
|
+
enforceOptIn?: boolean;
|
|
1117
|
+
}
|
|
1118
|
+
export interface DiscordDmOptInParams {
|
|
1119
|
+
userId: string;
|
|
1120
|
+
status: "opted_in" | "revoked" | string;
|
|
1121
|
+
source?: string;
|
|
1122
|
+
note?: string;
|
|
1123
|
+
}
|
|
1124
|
+
export interface MerchantGroupList {
|
|
1125
|
+
groups: Array<Record<string, unknown>>;
|
|
1126
|
+
botRunning?: boolean;
|
|
1127
|
+
botUsername?: string | null;
|
|
1128
|
+
botConnected?: boolean;
|
|
1129
|
+
[key: string]: unknown;
|
|
1130
|
+
}
|
|
1131
|
+
export interface EmailMailbox {
|
|
1132
|
+
id: string;
|
|
1133
|
+
botId: string;
|
|
1134
|
+
address: string;
|
|
1135
|
+
[key: string]: unknown;
|
|
1136
|
+
}
|
|
1137
|
+
export interface EmailMailboxCreateParams {
|
|
1138
|
+
address: string;
|
|
1139
|
+
[key: string]: unknown;
|
|
1140
|
+
}
|
|
1141
|
+
export interface EmailThreadList {
|
|
1142
|
+
threads: Array<Record<string, unknown>>;
|
|
1143
|
+
take: number;
|
|
1144
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reachv2/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Reach unified REST API client library for TypeScript — crm 域(AgentApi/Project/Bot/Knowledge/Channel/Conversation/Transaction/Auth/Chat/ApiKey/LightRAG/Orchestration/ScheduledTasks/Internal/Abis/Admin)+ social 域(Content/Tts/Accounts/ContentPlans 内容计划/PublishPlans 发布计划/BrowserTemplates 流程模板/AiMedia 视频脚本/Effect 效果追踪/SeoGeo SEO-GEO 矩阵/ContentRules 内容规则引擎/DataSources 数据源)+ 统一 DashboardApi(crm/social 看板)+ 统一租户成员模型(Tenants/Team/Health,G-1~G-3)",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Reach unified REST API client library for TypeScript — crm 域(AgentApi/Project/Bot/Knowledge/Channel/Conversation/Transaction/Auth/Chat/ApiKey/LightRAG/Orchestration/ScheduledTasks/Internal/Abis/Admin)+ social 域(Content/Tts/Accounts/ContentPlans 内容计划/PublishPlans 发布计划/BrowserTemplates 流程模板/AiMedia 视频脚本/Effect 效果追踪/SeoGeo SEO-GEO 矩阵/ContentRules 内容规则引擎/DataSources 数据源)+ 商户域(Merchant 控制台/ChannelAdmin 通道与群发/EmailChannel 邮件通道)+ 计费与配额(Billing 社媒计费/SharedBilling 统一订阅与加密收款/Quota 社媒配额)+ 统一 DashboardApi(crm/social 看板)+ 统一租户成员模型(Tenants/Team/Health,G-1~G-3)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"clean": "rm -rf dist",
|
|
19
19
|
"build": "npm run clean && tsc",
|
|
20
20
|
"test": "node --test",
|
|
21
|
+
"openapi": "node scripts/generate-openapi.mjs",
|
|
21
22
|
"prepublishOnly": "npm run build && npm test"
|
|
22
23
|
},
|
|
23
24
|
"keywords": [
|