@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,87 @@
|
|
|
1
|
+
import { RequestMethod, EmailMailbox, EmailMailboxCreateParams, EmailThreadList } from "../types.js";
|
|
2
|
+
type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
|
|
3
|
+
export interface EmailSendParams {
|
|
4
|
+
to: string | string[];
|
|
5
|
+
subject: string;
|
|
6
|
+
text?: string;
|
|
7
|
+
html?: string;
|
|
8
|
+
cc?: string[];
|
|
9
|
+
bcc?: string[];
|
|
10
|
+
inReplyTo?: string | null;
|
|
11
|
+
references?: string[];
|
|
12
|
+
attachments?: unknown[];
|
|
13
|
+
conversationId?: string | null;
|
|
14
|
+
agentKey?: string;
|
|
15
|
+
idempotencyKey?: string | null;
|
|
16
|
+
}
|
|
17
|
+
export interface EmailPollParams {
|
|
18
|
+
limit?: number;
|
|
19
|
+
/** 默认 true */
|
|
20
|
+
storeAttachments?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface EmailInboundParams {
|
|
23
|
+
/** 原始邮件(RFC822 / 原始 source) */
|
|
24
|
+
source: string;
|
|
25
|
+
uid?: string | null;
|
|
26
|
+
storeAttachments?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* EmailChannelResource — 客服邮件通道(C9-1)。
|
|
30
|
+
*
|
|
31
|
+
* 端点:`/api/merchant/projects/:id/bots/:botId/channels/email/*`,
|
|
32
|
+
* 要求 `role=merchant` 的 JWT。邮箱凭证加密入库,对外永不返回密码。
|
|
33
|
+
*/
|
|
34
|
+
export declare class EmailChannelResource {
|
|
35
|
+
private request;
|
|
36
|
+
constructor(request: RequestFn);
|
|
37
|
+
private base;
|
|
38
|
+
/** 邮箱账号列表 */
|
|
39
|
+
listMailboxes(projectId: string, botId: string): Promise<{
|
|
40
|
+
mailboxes: EmailMailbox[];
|
|
41
|
+
}>;
|
|
42
|
+
/** 新增邮箱账号(SMTP/IMAP 凭证) */
|
|
43
|
+
createMailbox(projectId: string, botId: string, params: EmailMailboxCreateParams): Promise<{
|
|
44
|
+
mailbox: EmailMailbox;
|
|
45
|
+
binding: unknown;
|
|
46
|
+
}>;
|
|
47
|
+
/** 邮箱账号详情 */
|
|
48
|
+
getMailbox(projectId: string, botId: string, mailboxId: string): Promise<{
|
|
49
|
+
mailbox: EmailMailbox;
|
|
50
|
+
}>;
|
|
51
|
+
/** 更新邮箱账号(地址变更会同步通道绑定) */
|
|
52
|
+
updateMailbox(projectId: string, botId: string, mailboxId: string, patch: Partial<EmailMailboxCreateParams>): Promise<{
|
|
53
|
+
mailbox: EmailMailbox;
|
|
54
|
+
}>;
|
|
55
|
+
/** 删除邮箱账号(同时解绑通道) */
|
|
56
|
+
deleteMailbox(projectId: string, botId: string, mailboxId: string): Promise<{
|
|
57
|
+
success: boolean;
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}>;
|
|
60
|
+
/** 通过 SMTP 发信 */
|
|
61
|
+
sendMail(projectId: string, botId: string, mailboxId: string, params: EmailSendParams): Promise<{
|
|
62
|
+
success: boolean;
|
|
63
|
+
[key: string]: unknown;
|
|
64
|
+
}>;
|
|
65
|
+
/** 立即通过 IMAP 拉取一次收件 */
|
|
66
|
+
pollMailbox(projectId: string, botId: string, mailboxId: string, params?: EmailPollParams): Promise<{
|
|
67
|
+
success: boolean;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
}>;
|
|
70
|
+
/** 投递原始邮件(调试 / 外部收信 webhook;幂等键 = Message-ID) */
|
|
71
|
+
inboundEmail(projectId: string, botId: string, mailboxId: string, params: EmailInboundParams): Promise<{
|
|
72
|
+
success: boolean;
|
|
73
|
+
[key: string]: unknown;
|
|
74
|
+
}>;
|
|
75
|
+
/** 邮件线程列表(limit 默认 50,上限 200) */
|
|
76
|
+
listThreads(projectId: string, botId: string, mailboxId: string, params?: {
|
|
77
|
+
limit?: number;
|
|
78
|
+
threadKey?: string;
|
|
79
|
+
conversationId?: string;
|
|
80
|
+
}): Promise<EmailThreadList>;
|
|
81
|
+
/** 线程详情(含消息列表) */
|
|
82
|
+
getThread(projectId: string, botId: string, mailboxId: string, threadId: string): Promise<{
|
|
83
|
+
thread: Record<string, unknown>;
|
|
84
|
+
messages: unknown[];
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EmailChannelResource — 客服邮件通道(C9-1)。
|
|
3
|
+
*
|
|
4
|
+
* 端点:`/api/merchant/projects/:id/bots/:botId/channels/email/*`,
|
|
5
|
+
* 要求 `role=merchant` 的 JWT。邮箱凭证加密入库,对外永不返回密码。
|
|
6
|
+
*/
|
|
7
|
+
export class EmailChannelResource {
|
|
8
|
+
constructor(request) {
|
|
9
|
+
this.request = request;
|
|
10
|
+
}
|
|
11
|
+
base(projectId, botId) {
|
|
12
|
+
return `/api/merchant/projects/${encodeURIComponent(projectId)}/bots/${encodeURIComponent(botId)}/channels/email`;
|
|
13
|
+
}
|
|
14
|
+
/** 邮箱账号列表 */
|
|
15
|
+
listMailboxes(projectId, botId) {
|
|
16
|
+
return this.request("GET", `${this.base(projectId, botId)}/mailboxes`);
|
|
17
|
+
}
|
|
18
|
+
/** 新增邮箱账号(SMTP/IMAP 凭证) */
|
|
19
|
+
createMailbox(projectId, botId, params) {
|
|
20
|
+
return this.request("POST", `${this.base(projectId, botId)}/mailboxes`, params);
|
|
21
|
+
}
|
|
22
|
+
/** 邮箱账号详情 */
|
|
23
|
+
getMailbox(projectId, botId, mailboxId) {
|
|
24
|
+
return this.request("GET", `${this.base(projectId, botId)}/mailboxes/${encodeURIComponent(mailboxId)}`);
|
|
25
|
+
}
|
|
26
|
+
/** 更新邮箱账号(地址变更会同步通道绑定) */
|
|
27
|
+
updateMailbox(projectId, botId, mailboxId, patch) {
|
|
28
|
+
return this.request("PUT", `${this.base(projectId, botId)}/mailboxes/${encodeURIComponent(mailboxId)}`, patch);
|
|
29
|
+
}
|
|
30
|
+
/** 删除邮箱账号(同时解绑通道) */
|
|
31
|
+
deleteMailbox(projectId, botId, mailboxId) {
|
|
32
|
+
return this.request("DELETE", `${this.base(projectId, botId)}/mailboxes/${encodeURIComponent(mailboxId)}`);
|
|
33
|
+
}
|
|
34
|
+
/** 通过 SMTP 发信 */
|
|
35
|
+
sendMail(projectId, botId, mailboxId, params) {
|
|
36
|
+
return this.request("POST", `${this.base(projectId, botId)}/mailboxes/${encodeURIComponent(mailboxId)}/send`, params);
|
|
37
|
+
}
|
|
38
|
+
/** 立即通过 IMAP 拉取一次收件 */
|
|
39
|
+
pollMailbox(projectId, botId, mailboxId, params = {}) {
|
|
40
|
+
return this.request("POST", `${this.base(projectId, botId)}/mailboxes/${encodeURIComponent(mailboxId)}/poll`, params);
|
|
41
|
+
}
|
|
42
|
+
/** 投递原始邮件(调试 / 外部收信 webhook;幂等键 = Message-ID) */
|
|
43
|
+
inboundEmail(projectId, botId, mailboxId, params) {
|
|
44
|
+
return this.request("POST", `${this.base(projectId, botId)}/mailboxes/${encodeURIComponent(mailboxId)}/inbound`, params);
|
|
45
|
+
}
|
|
46
|
+
/** 邮件线程列表(limit 默认 50,上限 200) */
|
|
47
|
+
listThreads(projectId, botId, mailboxId, params = {}) {
|
|
48
|
+
const query = new URLSearchParams();
|
|
49
|
+
if (params.limit != null)
|
|
50
|
+
query.set("limit", String(params.limit));
|
|
51
|
+
if (params.threadKey)
|
|
52
|
+
query.set("threadKey", params.threadKey);
|
|
53
|
+
if (params.conversationId)
|
|
54
|
+
query.set("conversationId", params.conversationId);
|
|
55
|
+
const qs = query.toString();
|
|
56
|
+
return this.request("GET", `${this.base(projectId, botId)}/mailboxes/${encodeURIComponent(mailboxId)}/threads${qs ? `?${qs}` : ""}`);
|
|
57
|
+
}
|
|
58
|
+
/** 线程详情(含消息列表) */
|
|
59
|
+
getThread(projectId, botId, mailboxId, threadId) {
|
|
60
|
+
return this.request("GET", `${this.base(projectId, botId)}/mailboxes/${encodeURIComponent(mailboxId)}/threads/${encodeURIComponent(threadId)}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -9,6 +9,10 @@ type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Pro
|
|
|
9
9
|
*
|
|
10
10
|
* Per-user isolation: pass `namespace` to scope documents/queries to a specific user.
|
|
11
11
|
* Defaults to botId (shared knowledge).
|
|
12
|
+
*
|
|
13
|
+
* Platform shared namespaces: Keel RAG 侧维护共享 namespace 白名单(默认 `market` / `onchain`,
|
|
14
|
+
* 用于跨租户只读的行情 / 链上知识)。查询时可直接作为 `namespace` 传入;
|
|
15
|
+
* 写入(insertDocument / insertDocuments)到这两个 namespace 会被 Keel 以只读拒绝。
|
|
12
16
|
*/
|
|
13
17
|
export declare class LightRAGResource {
|
|
14
18
|
private request;
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Per-user isolation: pass `namespace` to scope documents/queries to a specific user.
|
|
9
9
|
* Defaults to botId (shared knowledge).
|
|
10
|
+
*
|
|
11
|
+
* Platform shared namespaces: Keel RAG 侧维护共享 namespace 白名单(默认 `market` / `onchain`,
|
|
12
|
+
* 用于跨租户只读的行情 / 链上知识)。查询时可直接作为 `namespace` 传入;
|
|
13
|
+
* 写入(insertDocument / insertDocuments)到这两个 namespace 会被 Keel 以只读拒绝。
|
|
10
14
|
*/
|
|
11
15
|
export class LightRAGResource {
|
|
12
16
|
constructor(request) {
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { RequestMethod, MerchantDashboardStats, MerchantTicket, MerchantTicketUpdateParams, MerchantProject, MerchantBot, MerchantProjectCreateParams, MerchantBotCreateParams, MerchantLlmConfig, MerchantLlmConfigInput, MerchantChain, MerchantChainAddParams, MerchantChainList, MerchantTeamResult, MerchantTeamMemberAddParams, MerchantTeamInviteParams, MerchantTeamInviteResult, MerchantTeamRole, SimpleResult } from "../types.js";
|
|
2
|
+
type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
|
|
3
|
+
/**
|
|
4
|
+
* MerchantResource — 商户域(客服工作台 / 商户控制台)。
|
|
5
|
+
*
|
|
6
|
+
* 端点:Server API `/api/merchant/*`,全部要求 `role=merchant` 的 JWT
|
|
7
|
+
* (邮箱/钱包注册后需先 `auth.merchantOnboard()` 或接受商户邀请,见 v0.4.0 说明)。
|
|
8
|
+
*
|
|
9
|
+
* 注意:商户域直接返回 db 行(snake_case),与网关 `/api/v1` 的 camelCase 不同。
|
|
10
|
+
*/
|
|
11
|
+
export declare class MerchantResource {
|
|
12
|
+
private request;
|
|
13
|
+
constructor(request: RequestFn);
|
|
14
|
+
/** 商户看板(项目/Bot/会话/文档/token 配额 + 近 14 天趋势) */
|
|
15
|
+
dashboard(): Promise<MerchantDashboardStats>;
|
|
16
|
+
/** 转人工工单列表(近期 200 条) */
|
|
17
|
+
listTickets(): Promise<{
|
|
18
|
+
tickets: MerchantTicket[];
|
|
19
|
+
}>;
|
|
20
|
+
/** 更新工单状态 / 处理人(resolved 会同步会话状态) */
|
|
21
|
+
updateTicket(id: string, params: MerchantTicketUpdateParams): Promise<MerchantTicket>;
|
|
22
|
+
/** 项目列表(含 bot_count / total_tokens / total_conversations 聚合) */
|
|
23
|
+
listProjects(): Promise<MerchantProject[]>;
|
|
24
|
+
/** 项目详情 */
|
|
25
|
+
getProject(projectId: string): Promise<MerchantProject>;
|
|
26
|
+
/** 新建项目(默认名「新项目」) */
|
|
27
|
+
createProject(params: MerchantProjectCreateParams): Promise<MerchantProject>;
|
|
28
|
+
/** 更新项目(name / description 等) */
|
|
29
|
+
updateProject(projectId: string, patch: Record<string, unknown>): Promise<MerchantProject>;
|
|
30
|
+
/** 项目下 Bot 列表 */
|
|
31
|
+
listBots(projectId: string): Promise<MerchantBot[]>;
|
|
32
|
+
/** 在项目下新建 Bot(type 由服务端固定为 support) */
|
|
33
|
+
createBot(projectId: string, params: MerchantBotCreateParams): Promise<MerchantBot>;
|
|
34
|
+
/** 更新 Bot(name / prompt / status 等) */
|
|
35
|
+
updateBot(projectId: string, botId: string, patch: Record<string, unknown>): Promise<MerchantBot>;
|
|
36
|
+
/** 读取 Bot 的 LLM 配置(未配置返回 null) */
|
|
37
|
+
getLlmConfig(projectId: string, botId: string): Promise<MerchantLlmConfig | null>;
|
|
38
|
+
/** 写入 Bot 的 LLM 配置(BYOK) */
|
|
39
|
+
setLlmConfig(projectId: string, botId: string, params: MerchantLlmConfigInput): Promise<SimpleResult & Record<string, unknown>>;
|
|
40
|
+
/** 重置回平台托管 LLM */
|
|
41
|
+
resetLlmConfig(projectId: string, botId: string): Promise<SimpleResult & Record<string, unknown>>;
|
|
42
|
+
/** 可用链列表(内置链 + 商户自定义链) */
|
|
43
|
+
listChains(): Promise<MerchantChainList>;
|
|
44
|
+
/** 添加自定义链 */
|
|
45
|
+
addChain(params: MerchantChainAddParams): Promise<{
|
|
46
|
+
success: boolean;
|
|
47
|
+
chain: MerchantChain;
|
|
48
|
+
}>;
|
|
49
|
+
/** 删除自定义链 */
|
|
50
|
+
removeChain(chainId: number): Promise<SimpleResult>;
|
|
51
|
+
/** 团队成员列表(owner + 成员 + 待接受邀请) */
|
|
52
|
+
getTeam(): Promise<MerchantTeamResult>;
|
|
53
|
+
/** 直接加人(目标账户需已注册;email 或 wallet 二选一) */
|
|
54
|
+
addTeamMember(params: MerchantTeamMemberAddParams): Promise<Record<string, unknown>>;
|
|
55
|
+
/** 生成邀请(邮箱未注册亦可;受邀者登录后接受) */
|
|
56
|
+
createTeamInvite(params: MerchantTeamInviteParams): Promise<MerchantTeamInviteResult>;
|
|
57
|
+
/** 撤销未接受的邀请 */
|
|
58
|
+
revokeTeamInvite(token: string): Promise<SimpleResult>;
|
|
59
|
+
/** 修改成员角色 */
|
|
60
|
+
updateTeamMemberRole(accountId: string, role: MerchantTeamRole): Promise<SimpleResult>;
|
|
61
|
+
/** 移除成员 */
|
|
62
|
+
removeTeamMember(accountId: string): Promise<SimpleResult>;
|
|
63
|
+
/** 当前账户在本商户的权限码 */
|
|
64
|
+
myPermissions(): Promise<{
|
|
65
|
+
permissions: string[];
|
|
66
|
+
}>;
|
|
67
|
+
/** 角色目录(RBAC) */
|
|
68
|
+
listRoles(): Promise<unknown>;
|
|
69
|
+
/** 可分配角色选项 */
|
|
70
|
+
roleOptions(): Promise<unknown>;
|
|
71
|
+
/** 成员及其角色 */
|
|
72
|
+
listMembers(): Promise<unknown>;
|
|
73
|
+
/** 修改成员角色集合 */
|
|
74
|
+
updateMemberRoles(userId: string, roles: string[]): Promise<unknown>;
|
|
75
|
+
/** 审计日志(action / resourceType / status / limit / offset) */
|
|
76
|
+
listAuditLogs(params?: {
|
|
77
|
+
action?: string;
|
|
78
|
+
resourceType?: string;
|
|
79
|
+
status?: string;
|
|
80
|
+
limit?: number;
|
|
81
|
+
offset?: number;
|
|
82
|
+
}): Promise<{
|
|
83
|
+
items: unknown[];
|
|
84
|
+
total: number;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
export {};
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { RequestMethod } from "../types.js";
|
|
2
|
+
type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
|
|
3
|
+
/** 单资源配额项 */
|
|
4
|
+
export interface QuotaEntry {
|
|
5
|
+
/** 本月额度(0 = 未配置/不限) */
|
|
6
|
+
limit: number;
|
|
7
|
+
used: number;
|
|
8
|
+
remaining: number;
|
|
9
|
+
allowed: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** `/api/quota/summary` 的输出 key(前端契约) */
|
|
12
|
+
export type QuotaResourceKey = "copywriting" | "tts" | "video" | "poster";
|
|
13
|
+
export interface QuotaSummaryResult {
|
|
14
|
+
/** 当前生效套餐名(无套餐时为 free) */
|
|
15
|
+
plan: string;
|
|
16
|
+
quotas: Record<QuotaResourceKey, QuotaEntry>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* QuotaResource — 社媒域本月配额(Server API `/api/quota/*`)。
|
|
20
|
+
*
|
|
21
|
+
* `GET /api/quota/summary` 支持 API Key 或 JWT(`authAny`),按登录主体所属租户统计。
|
|
22
|
+
* 注意:与网关侧 `dashboard.quota()`(`/api/v1/quota`,crm 域)不是同一端点。
|
|
23
|
+
*/
|
|
24
|
+
export declare class QuotaResource {
|
|
25
|
+
private request;
|
|
26
|
+
constructor(request: RequestFn);
|
|
27
|
+
/** 本月各资源配额用量(copywriting / tts / video / poster) */
|
|
28
|
+
summary(): Promise<QuotaSummaryResult>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QuotaResource — 社媒域本月配额(Server API `/api/quota/*`)。
|
|
3
|
+
*
|
|
4
|
+
* `GET /api/quota/summary` 支持 API Key 或 JWT(`authAny`),按登录主体所属租户统计。
|
|
5
|
+
* 注意:与网关侧 `dashboard.quota()`(`/api/v1/quota`,crm 域)不是同一端点。
|
|
6
|
+
*/
|
|
7
|
+
export class QuotaResource {
|
|
8
|
+
constructor(request) {
|
|
9
|
+
this.request = request;
|
|
10
|
+
}
|
|
11
|
+
/** 本月各资源配额用量(copywriting / tts / video / poster) */
|
|
12
|
+
summary() {
|
|
13
|
+
return this.request("GET", "/api/quota/summary");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { RequestMethod } from "../types.js";
|
|
2
|
+
type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
|
|
3
|
+
/** 订阅关联的套餐摘要 */
|
|
4
|
+
export interface SharedSubscriptionPlanRef {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
displayName?: string;
|
|
8
|
+
llmTokensPerMonth?: number;
|
|
9
|
+
}
|
|
10
|
+
/** 平台/席位订阅行(`GET /api/shared/billing/subscriptions`) */
|
|
11
|
+
export interface SharedSubscription {
|
|
12
|
+
id: string;
|
|
13
|
+
tenantId: string;
|
|
14
|
+
planId?: string | null;
|
|
15
|
+
planName: string;
|
|
16
|
+
scope?: "platform" | "seat" | string;
|
|
17
|
+
seatNo?: number | null;
|
|
18
|
+
agentKey?: string;
|
|
19
|
+
status?: string;
|
|
20
|
+
rail?: string;
|
|
21
|
+
autoRenew?: boolean;
|
|
22
|
+
currentPeriodStart?: string | null;
|
|
23
|
+
currentPeriodEnd?: string | null;
|
|
24
|
+
amountUsd?: number | null;
|
|
25
|
+
plan?: SharedSubscriptionPlanRef;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** 单资源配额(`/subscriptions/current` → quota.resources) */
|
|
29
|
+
export interface SubscriptionQuotaResource {
|
|
30
|
+
quota: number;
|
|
31
|
+
used: number;
|
|
32
|
+
remaining: number | null;
|
|
33
|
+
}
|
|
34
|
+
/** 当前订阅 + 本月用量 + 统一 token 池 */
|
|
35
|
+
export interface SubscriptionUsage {
|
|
36
|
+
subscription: SharedSubscription | null;
|
|
37
|
+
quota: null | {
|
|
38
|
+
plan: {
|
|
39
|
+
name: string;
|
|
40
|
+
llmTokensPerMonth: number;
|
|
41
|
+
};
|
|
42
|
+
usage: Record<string, {
|
|
43
|
+
quantity: number;
|
|
44
|
+
tokensUsed: number;
|
|
45
|
+
}>;
|
|
46
|
+
resources: Record<string, SubscriptionQuotaResource>;
|
|
47
|
+
tokensUsedThisMonth: number;
|
|
48
|
+
tokensRemaining: number;
|
|
49
|
+
seats: {
|
|
50
|
+
active: number;
|
|
51
|
+
monthlyQuota: number;
|
|
52
|
+
tokenBalance: number;
|
|
53
|
+
pool: number;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface RecordUsageParams {
|
|
58
|
+
tenantId: string;
|
|
59
|
+
/** 资源类型,如 `llm_tokens` / `content:generate` / `tts:synthesize` */
|
|
60
|
+
resourceType: string;
|
|
61
|
+
quantity?: number;
|
|
62
|
+
tokensUsed?: number;
|
|
63
|
+
metadata?: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
export interface UsageRecordResult {
|
|
66
|
+
id: string;
|
|
67
|
+
tenantId: string;
|
|
68
|
+
accountId?: string | null;
|
|
69
|
+
resourceType: string;
|
|
70
|
+
quantity: number;
|
|
71
|
+
tokensUsed?: number | null;
|
|
72
|
+
metadata?: Record<string, unknown>;
|
|
73
|
+
createdAt?: string;
|
|
74
|
+
[key: string]: unknown;
|
|
75
|
+
}
|
|
76
|
+
export interface SharedTokenPackPurchaseParams {
|
|
77
|
+
tenantId: string;
|
|
78
|
+
packId: string;
|
|
79
|
+
successUrl?: string;
|
|
80
|
+
cancelUrl?: string;
|
|
81
|
+
/** 用站内推广余额全额抵扣本人自购 */
|
|
82
|
+
usePartnerBalance?: boolean;
|
|
83
|
+
}
|
|
84
|
+
export interface SharedTokenPackPurchaseResult {
|
|
85
|
+
id?: string;
|
|
86
|
+
tenantId?: string;
|
|
87
|
+
packId?: string | null;
|
|
88
|
+
packName?: string;
|
|
89
|
+
tokens?: number;
|
|
90
|
+
amountUsd?: number;
|
|
91
|
+
paymentMethod?: string;
|
|
92
|
+
status?: string;
|
|
93
|
+
/** 支付通道未配置时为 true(pending 单待运营开通) */
|
|
94
|
+
manual?: boolean;
|
|
95
|
+
sessionUrl?: string;
|
|
96
|
+
paymentId?: string;
|
|
97
|
+
remark?: string;
|
|
98
|
+
[key: string]: unknown;
|
|
99
|
+
}
|
|
100
|
+
/** 已开放的加密收款通道(`{ enabled, chains }`) */
|
|
101
|
+
export interface CryptoMethodsResult {
|
|
102
|
+
enabled: boolean;
|
|
103
|
+
chains: Array<Record<string, unknown>>;
|
|
104
|
+
}
|
|
105
|
+
export interface CryptoOrderParams {
|
|
106
|
+
tenantId: string;
|
|
107
|
+
/** 商品类型:plan / seat / seat_add / token_pack / browser_pack */
|
|
108
|
+
kind: string;
|
|
109
|
+
targetId: string;
|
|
110
|
+
chain: string;
|
|
111
|
+
asset: string;
|
|
112
|
+
payerWallet?: string;
|
|
113
|
+
seatCount?: number;
|
|
114
|
+
taxCountry?: string;
|
|
115
|
+
}
|
|
116
|
+
/** 加密订单对外视图(不含 enginePaymentId / receipt 原文) */
|
|
117
|
+
export interface CryptoOrder {
|
|
118
|
+
orderId: string;
|
|
119
|
+
kind: string;
|
|
120
|
+
targetId: string;
|
|
121
|
+
targetName?: string;
|
|
122
|
+
chain: string;
|
|
123
|
+
chainId?: number | string;
|
|
124
|
+
assetSymbol: string;
|
|
125
|
+
assetAddress?: string;
|
|
126
|
+
decimals?: number;
|
|
127
|
+
payTo?: string;
|
|
128
|
+
amountWei?: string;
|
|
129
|
+
amountDisplay?: string;
|
|
130
|
+
amountUsd?: number;
|
|
131
|
+
seatCount?: number;
|
|
132
|
+
seatKind?: string | null;
|
|
133
|
+
periodStart?: string | null;
|
|
134
|
+
periodEnd?: string | null;
|
|
135
|
+
tax?: {
|
|
136
|
+
country: string | null;
|
|
137
|
+
rate: number;
|
|
138
|
+
amount: number;
|
|
139
|
+
inclusive: boolean;
|
|
140
|
+
};
|
|
141
|
+
pspFee?: number;
|
|
142
|
+
reserveAmount?: number;
|
|
143
|
+
netAmount?: number;
|
|
144
|
+
status: string;
|
|
145
|
+
txHash?: string | null;
|
|
146
|
+
creditedWei?: string | null;
|
|
147
|
+
expiresAt?: string;
|
|
148
|
+
createdAt?: string;
|
|
149
|
+
/** confirm 时订单已支付 */
|
|
150
|
+
alreadyPaid?: boolean;
|
|
151
|
+
/** confirm 时本次生效结果 */
|
|
152
|
+
activated?: unknown;
|
|
153
|
+
duplicate?: boolean;
|
|
154
|
+
[key: string]: unknown;
|
|
155
|
+
}
|
|
156
|
+
export interface CryptoOrderListResult {
|
|
157
|
+
orders: CryptoOrder[];
|
|
158
|
+
}
|
|
159
|
+
export interface CryptoOrderConfirmParams {
|
|
160
|
+
tenantId: string;
|
|
161
|
+
txHash: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* SharedBillingResource — 统一计费(Server API `/api/shared/billing/*`)。
|
|
165
|
+
*
|
|
166
|
+
* 鉴权:订阅 / 用量 / 加密收款端点均要求 **账户 JWT**(`requireAuth`)+ 租户成员
|
|
167
|
+
* (`tenantId` 显式传参,服务端用登录账号校验成员身份);`plans` / `token-packs` /
|
|
168
|
+
* `crypto/methods` 公开。
|
|
169
|
+
*
|
|
170
|
+
* 未封装:
|
|
171
|
+
* - `POST /subscriptions`(已退役,恒 410 PLATFORM_PLAN_RETIRED;新购走 `/api/seats`)
|
|
172
|
+
* - `POST /webhook` / `POST /payments-events`(Stripe/引擎回调,验签即认证,不属于 SDK 调用面)
|
|
173
|
+
*/
|
|
174
|
+
export declare class SharedBillingResource {
|
|
175
|
+
private request;
|
|
176
|
+
constructor(request: RequestFn);
|
|
177
|
+
/** 席位档位套餐列表(**裸数组**,与 `/api/billing/plans` 的 `{ plans }` 不同) */
|
|
178
|
+
listPlans(): Promise<Array<Record<string, unknown>>>;
|
|
179
|
+
/** 可购买 Token 包列表(**裸数组**,含 cryptoAmount / price 等全字段) */
|
|
180
|
+
listTokenPacks(): Promise<Array<Record<string, unknown>>>;
|
|
181
|
+
/** 租户平台订阅列表(含 plan 摘要,按创建时间倒序) */
|
|
182
|
+
listSubscriptions(tenantId: string): Promise<SharedSubscription[]>;
|
|
183
|
+
/** 当前订阅 + 本月用量 + 分资源配额 + 席位/token 池(无套餐且无席位时 subscription/quota 为 null) */
|
|
184
|
+
getCurrentSubscription(tenantId: string): Promise<SubscriptionUsage>;
|
|
185
|
+
/** 记录用量(统一账本;`llm_tokens` 的 token 数落在 quantity) */
|
|
186
|
+
recordUsage(params: RecordUsageParams): Promise<UsageRecordResult>;
|
|
187
|
+
/**
|
|
188
|
+
* 购买 Token 包(fiat Stripe Checkout;渠道未配置时落 pending 单并返回 `manual: true`)。
|
|
189
|
+
* `usePartnerBalance: true` 时用推广余额全额抵扣,成功即 completed。
|
|
190
|
+
*/
|
|
191
|
+
purchaseTokenPack(params: SharedTokenPackPurchaseParams): Promise<SharedTokenPackPurchaseResult>;
|
|
192
|
+
/** 已开放的加密收款通道(链 + 稳定币;未开放返回 `enabled: false`) */
|
|
193
|
+
listCryptoMethods(): Promise<CryptoMethodsResult>;
|
|
194
|
+
/** 创建加密订单(返回 payTo / amountWei / 过期时间,用户链上转账后用返回的 orderId confirm) */
|
|
195
|
+
createCryptoOrder(params: CryptoOrderParams): Promise<CryptoOrder>;
|
|
196
|
+
/** 我的加密订单列表(读取时惰性把超时 pending 单置 expired) */
|
|
197
|
+
listCryptoOrders(tenantId: string): Promise<CryptoOrderListResult>;
|
|
198
|
+
/** 加密订单详情 */
|
|
199
|
+
getCryptoOrder(orderId: string, tenantId: string): Promise<CryptoOrder>;
|
|
200
|
+
/** 取消待付款订单(仅 pending/expired 可取消,已支付不可) */
|
|
201
|
+
cancelCryptoOrder(orderId: string, tenantId: string): Promise<CryptoOrder>;
|
|
202
|
+
/** 提交链上 txHash 换取引擎回执并生效 */
|
|
203
|
+
confirmCryptoOrder(orderId: string, params: CryptoOrderConfirmParams): Promise<CryptoOrder>;
|
|
204
|
+
}
|
|
205
|
+
export {};
|