@reachv2/sdk 0.3.3 → 0.4.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.
@@ -0,0 +1,143 @@
1
+ /**
2
+ * MerchantResource — 商户域(客服工作台 / 商户控制台)。
3
+ *
4
+ * 端点:Server API `/api/merchant/*`,全部要求 `role=merchant` 的 JWT
5
+ * (邮箱/钱包注册后需先 `auth.merchantOnboard()` 或接受商户邀请,见 v0.4.0 说明)。
6
+ *
7
+ * 注意:商户域直接返回 db 行(snake_case),与网关 `/api/v1` 的 camelCase 不同。
8
+ */
9
+ export class MerchantResource {
10
+ constructor(request) {
11
+ this.request = request;
12
+ }
13
+ // ═══ 看板 / 工单 ═══
14
+ /** 商户看板(项目/Bot/会话/文档/token 配额 + 近 14 天趋势) */
15
+ dashboard() {
16
+ return this.request("GET", "/api/merchant/dashboard");
17
+ }
18
+ /** 转人工工单列表(近期 200 条) */
19
+ listTickets() {
20
+ return this.request("GET", "/api/merchant/tickets");
21
+ }
22
+ /** 更新工单状态 / 处理人(resolved 会同步会话状态) */
23
+ updateTicket(id, params) {
24
+ return this.request("PATCH", `/api/merchant/tickets/${encodeURIComponent(id)}`, params);
25
+ }
26
+ // ═══ 项目 / Bot ═══
27
+ /** 项目列表(含 bot_count / total_tokens / total_conversations 聚合) */
28
+ listProjects() {
29
+ return this.request("GET", "/api/merchant/projects");
30
+ }
31
+ /** 项目详情 */
32
+ getProject(projectId) {
33
+ return this.request("GET", `/api/merchant/projects/${encodeURIComponent(projectId)}`);
34
+ }
35
+ /** 新建项目(默认名「新项目」) */
36
+ createProject(params) {
37
+ return this.request("POST", "/api/merchant/projects", params);
38
+ }
39
+ /** 更新项目(name / description 等) */
40
+ updateProject(projectId, patch) {
41
+ return this.request("PATCH", `/api/merchant/projects/${encodeURIComponent(projectId)}`, patch);
42
+ }
43
+ /** 项目下 Bot 列表 */
44
+ listBots(projectId) {
45
+ return this.request("GET", `/api/merchant/projects/${encodeURIComponent(projectId)}/bots`);
46
+ }
47
+ /** 在项目下新建 Bot(type 由服务端固定为 support) */
48
+ createBot(projectId, params) {
49
+ return this.request("POST", `/api/merchant/projects/${encodeURIComponent(projectId)}/bots`, params);
50
+ }
51
+ /** 更新 Bot(name / prompt / status 等) */
52
+ updateBot(projectId, botId, patch) {
53
+ return this.request("PATCH", `/api/merchant/projects/${encodeURIComponent(projectId)}/bots/${encodeURIComponent(botId)}`, patch);
54
+ }
55
+ // ═══ Bot LLM 配置(BYOK / 平台托管) ═══
56
+ /** 读取 Bot 的 LLM 配置(未配置返回 null) */
57
+ getLlmConfig(projectId, botId) {
58
+ return this.request("GET", `/api/merchant/projects/${encodeURIComponent(projectId)}/bots/${encodeURIComponent(botId)}/llm-config`);
59
+ }
60
+ /** 写入 Bot 的 LLM 配置(BYOK) */
61
+ setLlmConfig(projectId, botId, params) {
62
+ return this.request("POST", `/api/merchant/projects/${encodeURIComponent(projectId)}/bots/${encodeURIComponent(botId)}/llm-config`, params);
63
+ }
64
+ /** 重置回平台托管 LLM */
65
+ resetLlmConfig(projectId, botId) {
66
+ return this.request("DELETE", `/api/merchant/projects/${encodeURIComponent(projectId)}/bots/${encodeURIComponent(botId)}/llm-config`);
67
+ }
68
+ // ═══ 链 ═══
69
+ /** 可用链列表(内置链 + 商户自定义链) */
70
+ listChains() {
71
+ return this.request("GET", "/api/merchant/chains");
72
+ }
73
+ /** 添加自定义链 */
74
+ addChain(params) {
75
+ return this.request("POST", "/api/merchant/chains", params);
76
+ }
77
+ /** 删除自定义链 */
78
+ removeChain(chainId) {
79
+ return this.request("DELETE", `/api/merchant/chains/${chainId}`);
80
+ }
81
+ // ═══ 团队(owner/admin 可管理) ═══
82
+ /** 团队成员列表(owner + 成员 + 待接受邀请) */
83
+ getTeam() {
84
+ return this.request("GET", "/api/merchant/team");
85
+ }
86
+ /** 直接加人(目标账户需已注册;email 或 wallet 二选一) */
87
+ addTeamMember(params) {
88
+ return this.request("POST", "/api/merchant/team/members", params);
89
+ }
90
+ /** 生成邀请(邮箱未注册亦可;受邀者登录后接受) */
91
+ createTeamInvite(params) {
92
+ return this.request("POST", "/api/merchant/team/invites", params);
93
+ }
94
+ /** 撤销未接受的邀请 */
95
+ revokeTeamInvite(token) {
96
+ return this.request("POST", `/api/merchant/team/invites/${encodeURIComponent(token)}/revoke`);
97
+ }
98
+ /** 修改成员角色 */
99
+ updateTeamMemberRole(accountId, role) {
100
+ return this.request("PUT", `/api/merchant/team/members/${encodeURIComponent(accountId)}`, { role });
101
+ }
102
+ /** 移除成员 */
103
+ removeTeamMember(accountId) {
104
+ return this.request("DELETE", `/api/merchant/team/members/${encodeURIComponent(accountId)}`);
105
+ }
106
+ // ═══ 权限 / 审计(governance) ═══
107
+ /** 当前账户在本商户的权限码 */
108
+ myPermissions() {
109
+ return this.request("GET", "/api/merchant/my-permissions");
110
+ }
111
+ /** 角色目录(RBAC) */
112
+ listRoles() {
113
+ return this.request("GET", "/api/merchant/roles");
114
+ }
115
+ /** 可分配角色选项 */
116
+ roleOptions() {
117
+ return this.request("GET", "/api/merchant/role-options");
118
+ }
119
+ /** 成员及其角色 */
120
+ listMembers() {
121
+ return this.request("GET", "/api/merchant/members");
122
+ }
123
+ /** 修改成员角色集合 */
124
+ updateMemberRoles(userId, roles) {
125
+ return this.request("PUT", `/api/merchant/members/${encodeURIComponent(userId)}/roles`, { roles });
126
+ }
127
+ /** 审计日志(action / resourceType / status / limit / offset) */
128
+ listAuditLogs(params = {}) {
129
+ const query = new URLSearchParams();
130
+ if (params.action)
131
+ query.set("action", params.action);
132
+ if (params.resourceType)
133
+ query.set("resourceType", params.resourceType);
134
+ if (params.status)
135
+ query.set("status", params.status);
136
+ if (params.limit != null)
137
+ query.set("limit", String(params.limit));
138
+ if (params.offset != null)
139
+ query.set("offset", String(params.offset));
140
+ const qs = query.toString();
141
+ return this.request("GET", `/api/merchant/audit-logs${qs ? `?${qs}` : ""}`);
142
+ }
143
+ }
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/OxaChain 等) */
528
+ /** 目标链 id(Ethereum/BNB/Polygon/Arbitrum/Base/Optimism 等) */
529
529
  chainId?: number;
530
530
  agentxAgentId?: number;
531
531
  tools?: ChatToolDefinition[];
@@ -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.3.3",
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.4.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 邮件通道)+ 统一 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": [