@reachv2/sdk 0.4.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @reachv2/sdk
2
2
 
3
- Reach(reach.codes)统一平台的官方 TypeScript SDK —— 由 aiservicer SDK(crm 域,18 资源)与 aiops-saas SDK(social 域,5 资源)合并而来(P2.4),现统一为 **34 个资源类 / 267 个资源方法**。一个客户端覆盖客服 / 销售引导、社群维护与社媒运营全部资源(含商户入驻与商户控制台、通道/群发、邮件通道、效果追踪、SEO/GEO、内容规则与数据源)。
3
+ Reach(reach.codes)统一平台的官方 TypeScript SDK —— 由 aiservicer SDK(crm 域,18 资源)与 aiops-saas SDK(social 域,5 资源)合并而来(P2.4),现统一为 **37 个资源类 / 287 个资源方法**。一个客户端覆盖客服 / 销售引导、社群维护与社媒运营全部资源(含商户入驻与商户控制台、通道/群发、邮件通道、计费与配额、效果追踪、SEO/GEO、内容规则与数据源)。
4
4
 
5
5
  - 运行时:Node.js >= 18(ESM)
6
6
  - 类型:完整 TypeScript 类型定义(自带 `dist/index.d.ts`)
@@ -8,7 +8,7 @@ Reach(reach.codes)统一平台的官方 TypeScript SDK —— 由 aiservicer
8
8
 
9
9
  ## 文档
10
10
 
11
- - **[API Reference](docs/API-REFERENCE.md)**(P2.6,v0.3.0 补 P-REACH 四域):全部 27 个资源类 + `ReachClient` 共 **203 个资源方法**(另含 `ReachClient.setToken` / `request`)的签名 / 端点 / 参数 / 返回类型 / 错误 / 示例,与 `sdk/src` 源码一一对应。
11
+ - **[API Reference](docs/API-REFERENCE.md)**(P2.6,v0.3.0 补 P-REACH 四域,v0.4.0 补商户/通道,v0.5.0 补计费/配额):全部 37 个资源类 + `ReachClient` 共 **287 个资源方法**(另含 `ReachClient.setToken` / `request`)的签名 / 端点 / 参数 / 返回类型 / 错误 / 示例,与 `sdk/src` 源码一一对应。
12
12
 
13
13
  ## 安装
14
14
 
@@ -143,7 +143,7 @@ const client = new ReachClient({
143
143
 
144
144
  | 资源 | 主要能力 | API 域 |
145
145
  |------|----------|--------|
146
- | `client.agents` | **统一 Agent 入口**(AgentApi):调用方 agent(list/get/capabilities/chat/prepareTransaction)+ AgentX 链上市场/订阅/状态/用量/发布/技能 + 市场 run/clone | 双域 |
146
+ | `client.agents` | **统一 Agent 入口**(AgentApi):调用方 agent(list/get/capabilities/chat/prepareTransaction)+ 市场搜索(listMarketplace → `/api/agents/marketplace/search`)+ 市场 run/clone | 双域 |
147
147
  | `client.project` | 项目 CRUD、列表 | Gateway |
148
148
  | `client.bot` | Bot(客服/销售/交易/自定义)CRUD、启停、统计 | Gateway |
149
149
  | `client.knowledge` | 知识文档 CRUD、推荐 | Gateway |
@@ -151,7 +151,7 @@ const client = new ReachClient({
151
151
  | `client.conversation` | 对话记录与消息 | Gateway |
152
152
  | `client.transaction` | 交易意图解析/构造/模拟、协议/合约/calldata 查询 | Gateway |
153
153
  | `client.chat` | 服务端对话(含 function calling tools、A2A 编排) | Server |
154
- | `client.lightrag` | RAG Key 管理 + 文档 CRUD + 查询(per-user namespace) | Gateway |
154
+ | `client.lightrag` | RAG Key 管理 + 文档 CRUD + 查询(per-user namespace;平台共享 namespace `market` / `onchain` 只读可查) | Gateway |
155
155
  | `client.scheduledTasks` | 主 agent 定时任务管理 | Server |
156
156
  | `client.internal` | 企业内 Agent:企业级共享知识库 + 监控连接器/事件(`internal` bot) | Server |
157
157
  | `client.abis` | 商户租户合约 ABI 管理:list/add/remove(交易 agent 上传 ABI 后即可按函数构造链上调用) | Server |
@@ -189,11 +189,24 @@ const client = new ReachClient({
189
189
  > 或接受商户邀请(`client.auth.acceptMerchantInvite(token)`),再 `setToken(返回的 accessToken)`。
190
190
  > 商户域直接返回 db 行(多为 snake_case),与网关 `/api/v1` 的 camelCase 不同。
191
191
 
192
+ ### 计费 / 配额 — P1(v0.5.0 新增)
193
+
194
+ | 资源 | 主要能力 | API 域 |
195
+ |------|----------|--------|
196
+ | `client.billing` | **社媒域计费(BillingResource)**:套餐 / Token 包 / 价格(公开)、Token 包购买(Stripe Checkout,未配置时落 pending)、Customer Portal、浏览器实例配额与购买流水(7 方法) | Server |
197
+ | `client.sharedBilling` | **统一计费(SharedBillingResource)**:订阅列表 / 当前订阅与本月用量、用量记账、Token 包购买(支持推广余额抵扣)、加密收款(通道 / 下单 / 列表 / 详情 / 取消 / 确认)(12 方法) | Server |
198
+ | `client.quota` | **社媒域本月配额(QuotaResource)**:`copywriting` / `tts` / `video` / `poster` 的 limit / used / remaining / allowed(1 方法) | Server |
199
+
200
+ > 两个计费资源路径不同:`client.billing` → `/api/billing/*`(社媒域),`client.sharedBilling` → `/api/shared/billing/*`(统一账本)。
201
+ > 订阅 / 用量 / 加密收款需 **账户 JWT + 租户成员**,`tenantId` 显式传参;`plans` / `token-packs` / `prices` / `crypto/methods` 公开。
202
+ > 已退役端点未封装:`POST /api/billing/checkout` 与 `POST /api/shared/billing/subscriptions` 恒 410(新购走 `/api/seats`);
203
+ > `webhook` / `payments-events` 为服务端验签回调,不属于 SDK 调用面。
204
+
192
205
  > crm 客服指标(原 `client.analytics`)与社媒运营看板(原 `client.dashboard`)已统一为 `client.dashboard`(DashboardApi);AgentX(原 `client.agentx`)与社媒 Agent 市场已统一为 `client.agents`(AgentApi)。
193
206
 
194
207
  ## 统一入口说明
195
208
 
196
- - **AgentApi(`client.agents`)**:唯一 Agent 入口(P2.4.3)。吸收 S agent(网关 `/api/v1/agents/*`:list/get/capabilities/chat/prepareTransaction)、S agentx(server `/api/agentx/*` + `/api/merchant/*`:市场/计划/订阅/状态/用量/上下文/发布/技能)与 A agents(server `/api/agents/*`:run/clone,marketplace→listMarketplace)。统一 Agent 资源模型见 REACH_MERGE_PLAN A.2.3/A.2.5。
209
+ - **AgentApi(`client.agents`)**:唯一 Agent 入口(P2.4.3)。吸收 S agent(网关 `/api/v1/agents/*`:list/get/capabilities/chat/prepareTransaction)、市场(server `/api/agents/marketplace/search`:listMarketplace)与 A agents(server `/api/agents/*`:run/clone)。`/api/agentx/*` 服务端未挂载,相关方法已于 v0.4.0 移除。统一 Agent 资源模型见 REACH_MERGE_PLAN A.2.3/A.2.5。
197
210
  - **DashboardApi(`client.dashboard`)**:唯一看板入口(P2.4.4)。crm 域(`global` / `dashboard(projectId)` / `botMetrics` / `summaryByUser`)+ social 域(`overview` / `quota` / `trend`)。
198
211
 
199
212
  ## Function Calling(工具回调)
@@ -214,7 +227,7 @@ npm test # node --test,覆盖 test/*.test.mjs
214
227
  | 测试文件 | 覆盖 |
215
228
  |----------|------|
216
229
  | `test/client.test.mjs` | ReachClient 核心行为:构造校验(`MISSING_AUTH`)、认证 Header、双 base 路由、body 序列化、错误语义 |
217
- | `test/resources.test.mjs` | **全量** 34 资源类 267 方法的 method / path / body 断言(要求每个方法至少被一条用例覆盖) |
230
+ | `test/resources.test.mjs` | **全量** 37 资源类 287 方法的 method / path / body 断言(要求每个方法至少被一条用例覆盖) |
218
231
  | `test/smoke.test.mjs` | 导出面 + 资源方法面快照 |
219
232
 
220
233
  > 测试跑 **`dist/` 产物**,改完 `src/` 必须先 `npm run build`。
package/dist/client.d.ts CHANGED
@@ -33,6 +33,9 @@ import { TeamResource } from "./resources/team.js";
33
33
  import { MerchantResource } from "./resources/merchant.js";
34
34
  import { ChannelAdminResource } from "./resources/channel-admin.js";
35
35
  import { EmailChannelResource } from "./resources/email-channel.js";
36
+ import { BillingResource } from "./resources/billing.js";
37
+ import { SharedBillingResource } from "./resources/shared-billing.js";
38
+ import { QuotaResource } from "./resources/quota.js";
36
39
  export declare class ReachClient {
37
40
  private apiKey?;
38
41
  private token?;
@@ -73,6 +76,9 @@ export declare class ReachClient {
73
76
  merchant: MerchantResource;
74
77
  channelAdmin: ChannelAdminResource;
75
78
  emailChannel: EmailChannelResource;
79
+ billing: BillingResource;
80
+ sharedBilling: SharedBillingResource;
81
+ quota: QuotaResource;
76
82
  constructor(config: ReachClientConfig);
77
83
  /** Set token after wallet login */
78
84
  setToken(token: string): void;
package/dist/client.js CHANGED
@@ -33,6 +33,9 @@ import { TeamResource } from "./resources/team.js";
33
33
  import { MerchantResource } from "./resources/merchant.js";
34
34
  import { ChannelAdminResource } from "./resources/channel-admin.js";
35
35
  import { EmailChannelResource } from "./resources/email-channel.js";
36
+ import { BillingResource } from "./resources/billing.js";
37
+ import { SharedBillingResource } from "./resources/shared-billing.js";
38
+ import { QuotaResource } from "./resources/quota.js";
36
39
  export class ReachClient {
37
40
  constructor(config) {
38
41
  if (!config.apiKey && !config.token) {
@@ -78,6 +81,9 @@ export class ReachClient {
78
81
  this.merchant = new MerchantResource(this.requestServer.bind(this));
79
82
  this.channelAdmin = new ChannelAdminResource(this.requestServer.bind(this));
80
83
  this.emailChannel = new EmailChannelResource(this.requestServer.bind(this));
84
+ this.billing = new BillingResource(this.requestServer.bind(this));
85
+ this.sharedBilling = new SharedBillingResource(this.requestServer.bind(this));
86
+ this.quota = new QuotaResource(this.requestServer.bind(this));
81
87
  }
82
88
  /** Set token after wallet login */
83
89
  setToken(token) {
package/dist/index.d.ts CHANGED
@@ -34,7 +34,13 @@ export { TeamResource } from "./resources/team.js";
34
34
  export { MerchantResource } from "./resources/merchant.js";
35
35
  export { ChannelAdminResource } from "./resources/channel-admin.js";
36
36
  export { EmailChannelResource } from "./resources/email-channel.js";
37
+ export { BillingResource } from "./resources/billing.js";
38
+ export { SharedBillingResource } from "./resources/shared-billing.js";
39
+ export { QuotaResource } from "./resources/quota.js";
37
40
  export type { ReachClientConfig, BotType, AgentType, BotStatus, ChannelType, ChannelStatus, KnowledgeStatus, Pagination, PaginatedResponse, Project, ProjectCreateParams, ProjectUpdateParams, TransactionBotConfig, Bot, BotStats, BotCreateParams, BotUpdateParams, KnowledgeDoc, KnowledgeRecommendation, Channel, ChannelConfigureParams, Conversation, Message, ChatParams, ChatResponse, ChatToolDefinition, ChatToolFunction, DashboardData, BotMetrics, TxIntent, TxStep, PreparedTransaction, ContractInfo, ContractMethod, SimulationResult, DecodedCalldata, ProtocolSummary, ProtocolRegistryEntry, ChainDeployment, ProtocolAction, ParamHint, WalletNonce, WalletLoginParams, AuthAccount, AuthResult, MfaRequiredResult, CaptchaResponse, CaptchaAnswer, AgentXAgent, AgentXAgentDetail, AgentXMarketplaceResult, AgentXSubscriptionPlans, AgentXSubscriptionCheck, AgentXAgentContext, AgentXPublishParams, AgentXPublishResult, AgentXSkill, AgentXSkillCreateParams, AgentXAgentStatus, AgentXAgentUsage, AgentXSubscriptionDetail, AgentXSubscriptionList, ServerChatParams, ServerChatResponse, ChatUsage, ChatUsageSummary, AgentSummary, AgentListResult, AgentListParams, AgentChainInfo, AgentActionType, AgentCapabilities, AgentChatParams, AgentChatResult, LightRAGKeyInfo, LightRAGDocumentParams, LightRAGQueryParams, LightRAGQueryResult, LightRAGBatchItem, LightRAGBatchError, LightRAGBatchResult, GlobalAnalytics, AdminDashboard, AdminMerchant, AdminMerchantDetail, AdminBillingRecord, AdminCreateBillingParams, LlmSettings, LlmUpdateParams, ConversationTask, ConversationTaskStatus, ConversationSession, ConversationCapabilities, ConversationMessage, OrchestrationTaskParams, OrchestrateParams, OrchestratedTaskResult, OrchestrateResult, ScheduledTask, ScheduledTaskStatus, ScheduledTaskTriggerType, MonitorConnectorKind, EnterpriseDoc, MonitorConnector, MonitorEvent, MerchantAbi, MerchantAbiCreateParams, SimpleResult, TenantType, TenantMemberRole, TenantMemberStatus, Tenant, TenantMemberInfo, TenantInvite, PublicInviteInfo, InviteAcceptResult, MemberRoleUpdateResult, TransferOwnerResult, TeamMemberItem, TeamInviteResult, HealthInfo, MerchantOnboardParams, MerchantAuthResult, MerchantInviteInfo, EmailCodeSendResult, EmailCodeLoginParams, AccountMeResult, MerchantDashboardStats, MerchantTicket, MerchantTicketUpdateParams, MerchantProject, MerchantBot, MerchantProjectCreateParams, MerchantBotCreateParams, MerchantLlmConfig, MerchantLlmConfigInput, MerchantChain, MerchantChainAddParams, MerchantChainList, MerchantTeamRole, MerchantTeamMember, MerchantTeamResult, MerchantTeamMemberAddParams, MerchantTeamInviteParams, MerchantTeamInviteResult, ChannelActionResult, SendTextParams, TelegramSendFileParams, DiscordDmParams, DiscordDmOptInParams, MerchantGroupList, EmailMailbox, EmailMailboxCreateParams, EmailThreadList, } from "./types.js";
38
41
  export type { ApiKeyInfo, ApiKeyCreated } from "./resources/api-key.js";
39
42
  export type { SocialAccountCreateParams } from "./resources/accounts.js";
40
43
  export type { EmailSendParams, EmailPollParams, EmailInboundParams, } from "./resources/email-channel.js";
44
+ export type { BillingPlan, BillingPlansResult, BillingTokenPack, BillingTokenPacksResult, BillingPrice, BillingPricesResult, TokenPackCheckoutResult, BrowserQuotaStatus, BrowserPackPurchase, BrowserPackPurchasesResult, } from "./resources/billing.js";
45
+ export type { SharedSubscriptionPlanRef, SharedSubscription, SubscriptionQuotaResource, SubscriptionUsage, RecordUsageParams, UsageRecordResult, SharedTokenPackPurchaseParams, SharedTokenPackPurchaseResult, CryptoMethodsResult, CryptoOrderParams, CryptoOrder, CryptoOrderListResult, CryptoOrderConfirmParams, } from "./resources/shared-billing.js";
46
+ export type { QuotaEntry, QuotaResourceKey, QuotaSummaryResult, } from "./resources/quota.js";
package/dist/index.js CHANGED
@@ -34,3 +34,6 @@ export { TeamResource } from "./resources/team.js";
34
34
  export { MerchantResource } from "./resources/merchant.js";
35
35
  export { ChannelAdminResource } from "./resources/channel-admin.js";
36
36
  export { EmailChannelResource } from "./resources/email-channel.js";
37
+ export { BillingResource } from "./resources/billing.js";
38
+ export { SharedBillingResource } from "./resources/shared-billing.js";
39
+ export { QuotaResource } from "./resources/quota.js";
@@ -0,0 +1,142 @@
1
+ import { RequestMethod } from "../types.js";
2
+ type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
3
+ /** 席位档位套餐(`/api/billing/plans` 返回的 shared.Plan 行) */
4
+ export interface BillingPlan {
5
+ id: string;
6
+ name: string;
7
+ displayName?: string;
8
+ description?: string | null;
9
+ kind?: string;
10
+ seatCount?: number;
11
+ price?: number;
12
+ introPrice?: number | null;
13
+ introPeriods?: number;
14
+ interval?: string;
15
+ rail?: string;
16
+ llmTokensPerMonth?: number;
17
+ features?: unknown[];
18
+ active?: boolean;
19
+ [key: string]: unknown;
20
+ }
21
+ export interface BillingPlansResult {
22
+ plans: BillingPlan[];
23
+ }
24
+ /** 可购买 Token 包(`/api/billing/token-packs` 精简字段) */
25
+ export interface BillingTokenPack {
26
+ id: string;
27
+ name: string;
28
+ tokens: number;
29
+ price: number;
30
+ cryptoAmount?: number;
31
+ sortOrder?: number;
32
+ active?: boolean;
33
+ [key: string]: unknown;
34
+ }
35
+ export interface BillingTokenPacksResult {
36
+ tokenPacks: BillingTokenPack[];
37
+ }
38
+ /** `/api/billing/prices` 的展示价格项 */
39
+ export interface BillingPrice {
40
+ id: string;
41
+ name: string;
42
+ /** 展示用字符串,如 `$29` / `Free` */
43
+ price: string;
44
+ /** 最小货币单位(分) */
45
+ amount: number;
46
+ interval: string;
47
+ kind?: string;
48
+ seatCount?: number;
49
+ introPrice?: number | null;
50
+ introPeriods?: number;
51
+ features: unknown[];
52
+ }
53
+ export interface BillingPricesResult {
54
+ prices: Record<string, BillingPrice>;
55
+ }
56
+ /** Token 包购买结果(Stripe Checkout / 人工待开通 pending 单) */
57
+ export interface TokenPackCheckoutResult {
58
+ id?: string;
59
+ tenantId?: string;
60
+ packId?: string | null;
61
+ packName?: string;
62
+ tokens?: number;
63
+ amountUsd?: number;
64
+ paymentMethod?: string;
65
+ status?: string;
66
+ /** 支付通道未配置时为 true(单已落 pending,待运营开通) */
67
+ manual?: boolean;
68
+ paymentId?: string;
69
+ sessionUrl?: string;
70
+ rail?: string;
71
+ pack?: Pick<BillingTokenPack, "id" | "name" | "tokens" | "price">;
72
+ [key: string]: unknown;
73
+ }
74
+ /** 浏览器实例配额概览 */
75
+ export interface BrowserQuotaStatus {
76
+ /** 套餐基础实例数 */
77
+ base: number;
78
+ /** 加购实例数(有效期内 BrowserPack) */
79
+ pack: number;
80
+ total: number;
81
+ used: number;
82
+ remaining: number;
83
+ /** 最近一份加购包的到期时间(无加购为 null) */
84
+ packExpiresAt: string | null;
85
+ [key: string]: unknown;
86
+ }
87
+ /** 浏览器实例包购买流水(存量只读) */
88
+ export interface BrowserPackPurchase {
89
+ id: string;
90
+ tenantId?: string;
91
+ packId?: string | null;
92
+ packName?: string;
93
+ instanceCount?: number;
94
+ amountUsd?: number;
95
+ status?: string;
96
+ periodStart?: string | null;
97
+ periodEnd?: string | null;
98
+ createdAt?: string;
99
+ [key: string]: unknown;
100
+ }
101
+ export interface BrowserPackPurchasesResult {
102
+ purchases: BrowserPackPurchase[];
103
+ }
104
+ /**
105
+ * BillingResource — 社媒域计费(Server API `/api/billing/*`)。
106
+ *
107
+ * - 公开:`plans` / `token-packs` / `prices`(无需登录)
108
+ * - JWT:`token-packs/purchase`(`authenticate`)、`portal`
109
+ * - API Key 或 JWT(只读):`browser-packs/quota`、`browser-packs/purchases`(`authAny`)
110
+ *
111
+ * 注意:`POST /api/billing/checkout` 已退役(恒返回 410 PLATFORM_PLAN_RETIRED),未封装;
112
+ * 平台套餐新购走 `/api/seats`(不在 SDK 覆盖范围)。
113
+ */
114
+ export declare class BillingResource {
115
+ private request;
116
+ constructor(request: RequestFn);
117
+ /** 席位档位套餐列表(`{ plans }`,active + orderBy sortOrder) */
118
+ listPlans(): Promise<BillingPlansResult>;
119
+ /** 可购买 Token 包列表(`{ tokenPacks }`) */
120
+ listTokenPacks(): Promise<BillingTokenPacksResult>;
121
+ /** 套餐展示价格(`{ prices }`,按套餐名索引) */
122
+ getPrices(): Promise<BillingPricesResult>;
123
+ /**
124
+ * 购买 Token 包(Stripe 一次性 Checkout)。
125
+ * 支付通道未配置时返回 `manual: true` 的 pending 单,待运营手动开通。
126
+ */
127
+ purchaseTokenPack(packId: string): Promise<TokenPackCheckoutResult>;
128
+ /**
129
+ * Stripe Customer Portal 会话。
130
+ * 当前 Stripe SDK 未纳入服务端依赖 → 恒 503 `STRIPE_SDK_NOT_AVAILABLE`;
131
+ * 无有效平台订阅时 404 `No active subscription found`。
132
+ */
133
+ getPortal(): Promise<{
134
+ url?: string;
135
+ [key: string]: unknown;
136
+ }>;
137
+ /** 我的浏览器实例配额概览(基础 / 加购 / 总计 / 已用 / 剩余) */
138
+ getBrowserQuota(): Promise<BrowserQuotaStatus>;
139
+ /** 我的浏览器实例包购买流水(最近 50 条,存量只读) */
140
+ listBrowserPurchases(): Promise<BrowserPackPurchasesResult>;
141
+ }
142
+ export {};
@@ -0,0 +1,52 @@
1
+ /**
2
+ * BillingResource — 社媒域计费(Server API `/api/billing/*`)。
3
+ *
4
+ * - 公开:`plans` / `token-packs` / `prices`(无需登录)
5
+ * - JWT:`token-packs/purchase`(`authenticate`)、`portal`
6
+ * - API Key 或 JWT(只读):`browser-packs/quota`、`browser-packs/purchases`(`authAny`)
7
+ *
8
+ * 注意:`POST /api/billing/checkout` 已退役(恒返回 410 PLATFORM_PLAN_RETIRED),未封装;
9
+ * 平台套餐新购走 `/api/seats`(不在 SDK 覆盖范围)。
10
+ */
11
+ export class BillingResource {
12
+ constructor(request) {
13
+ this.request = request;
14
+ }
15
+ /** 席位档位套餐列表(`{ plans }`,active + orderBy sortOrder) */
16
+ listPlans() {
17
+ return this.request("GET", "/api/billing/plans");
18
+ }
19
+ /** 可购买 Token 包列表(`{ tokenPacks }`) */
20
+ listTokenPacks() {
21
+ return this.request("GET", "/api/billing/token-packs");
22
+ }
23
+ /** 套餐展示价格(`{ prices }`,按套餐名索引) */
24
+ getPrices() {
25
+ return this.request("GET", "/api/billing/prices");
26
+ }
27
+ /**
28
+ * 购买 Token 包(Stripe 一次性 Checkout)。
29
+ * 支付通道未配置时返回 `manual: true` 的 pending 单,待运营手动开通。
30
+ */
31
+ purchaseTokenPack(packId) {
32
+ return this.request("POST", "/api/billing/token-packs/purchase", {
33
+ packId,
34
+ });
35
+ }
36
+ /**
37
+ * Stripe Customer Portal 会话。
38
+ * 当前 Stripe SDK 未纳入服务端依赖 → 恒 503 `STRIPE_SDK_NOT_AVAILABLE`;
39
+ * 无有效平台订阅时 404 `No active subscription found`。
40
+ */
41
+ getPortal() {
42
+ return this.request("GET", "/api/billing/portal");
43
+ }
44
+ /** 我的浏览器实例配额概览(基础 / 加购 / 总计 / 已用 / 剩余) */
45
+ getBrowserQuota() {
46
+ return this.request("GET", "/api/billing/browser-packs/quota");
47
+ }
48
+ /** 我的浏览器实例包购买流水(最近 50 条,存量只读) */
49
+ listBrowserPurchases() {
50
+ return this.request("GET", "/api/billing/browser-packs/purchases");
51
+ }
52
+ }
@@ -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,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 {};
@@ -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
@@ -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 {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reachv2/sdk",
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)",
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",