@reachv2/sdk 0.4.0 → 0.5.1

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,9 @@
1
+ Reach SDK (@reachv2/sdk)
2
+ Copyright 2026 sftgroup
3
+
4
+ This product includes software developed at sftgroup (https://reach.codes).
5
+
6
+ Licensed under the Apache License, Version 2.0 (see LICENSE).
7
+
8
+ Third-party components:
9
+ - TypeScript (Apache-2.0) — build-time only, not distributed in the published package.
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
 
@@ -82,7 +82,7 @@ Reach 将自身能力以 **MCP(Model Context Protocol)** 形式对外开放
82
82
  - 权限(读 / 写门禁):只读 Key(scope 不含 `write` / `all` / `*`)**只能调用读工具**(工具名按 `_` 分词命中
83
83
  `list` / `get` / `status` / `query` / `summary` / `check` / `history` / `usage` … 即视为读,未命中一律按写拒绝);
84
84
  写工具需 `write` / `all` / `*` scope,否则 `tools/call` 返回 JSON-RPC `-32001 requires a write-scoped API key`
85
- - 工具规模:**255**(crm 87 + social 168),按域白名单裁剪(当前 `crm` / `social`),`tools/list` 返回实际可用集合
85
+ - 工具规模:**247**(crm 77 + social 170),按域白名单裁剪(当前 `crm` / `social`),`tools/list` 返回实际可用集合
86
86
 
87
87
  会话按 MCP Streamable HTTP 规范:先 `initialize` 取得 `mcp-session-id`,
88
88
  再发 `notifications/initialized`,之后 `tools/call`,结束时 `DELETE` 会话。
@@ -103,6 +103,25 @@ const res = await client.callTool({ name: "social_accounts_list", arguments: {}
103
103
  await transport.close(); // 释放会话
104
104
  ```
105
105
 
106
+ ### 本地客户端(只支持 stdio)
107
+
108
+ Claude Desktop / Cursor / Cline / Cherry Studio 等只支持 `command` + `args` 时,用
109
+ [`@reachv2/mcp`](https://github.com/sftgroup/reach/tree/main/mcp) 桥接(内部走上面的 Streamable HTTP):
110
+
111
+ ```json
112
+ {
113
+ "mcpServers": {
114
+ "reach": {
115
+ "command": "npx",
116
+ "args": ["-y", "@reachv2/mcp", "--preset", "social"],
117
+ "env": { "REACH_API_KEY": "sk-xxx" }
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ `--preset` / `--domains` / `--tools` / `--exclude` 可裁剪工具面(261 个工具全量注入会占用大量上下文)。
124
+
106
125
  > 平台内部闭环(reach server → mcp,`/api/bridge/mcp/discover|call`)走 `x-reach-internal-token`,
107
126
  > 不对外暴露;外部集成一律使用 API Key。
108
127
 
@@ -143,7 +162,7 @@ const client = new ReachClient({
143
162
 
144
163
  | 资源 | 主要能力 | API 域 |
145
164
  |------|----------|--------|
146
- | `client.agents` | **统一 Agent 入口**(AgentApi):调用方 agent(list/get/capabilities/chat/prepareTransaction)+ AgentX 链上市场/订阅/状态/用量/发布/技能 + 市场 run/clone | 双域 |
165
+ | `client.agents` | **统一 Agent 入口**(AgentApi):调用方 agent(list/get/capabilities/chat/prepareTransaction)+ 市场搜索(listMarketplace → `/api/agents/marketplace/search`)+ 市场 run/clone | 双域 |
147
166
  | `client.project` | 项目 CRUD、列表 | Gateway |
148
167
  | `client.bot` | Bot(客服/销售/交易/自定义)CRUD、启停、统计 | Gateway |
149
168
  | `client.knowledge` | 知识文档 CRUD、推荐 | Gateway |
@@ -151,7 +170,7 @@ const client = new ReachClient({
151
170
  | `client.conversation` | 对话记录与消息 | Gateway |
152
171
  | `client.transaction` | 交易意图解析/构造/模拟、协议/合约/calldata 查询 | Gateway |
153
172
  | `client.chat` | 服务端对话(含 function calling tools、A2A 编排) | Server |
154
- | `client.lightrag` | RAG Key 管理 + 文档 CRUD + 查询(per-user namespace) | Gateway |
173
+ | `client.lightrag` | RAG Key 管理 + 文档 CRUD + 查询(per-user namespace;平台共享 namespace `market` / `onchain` 只读可查) | Gateway |
155
174
  | `client.scheduledTasks` | 主 agent 定时任务管理 | Server |
156
175
  | `client.internal` | 企业内 Agent:企业级共享知识库 + 监控连接器/事件(`internal` bot) | Server |
157
176
  | `client.abis` | 商户租户合约 ABI 管理:list/add/remove(交易 agent 上传 ABI 后即可按函数构造链上调用) | Server |
@@ -189,11 +208,24 @@ const client = new ReachClient({
189
208
  > 或接受商户邀请(`client.auth.acceptMerchantInvite(token)`),再 `setToken(返回的 accessToken)`。
190
209
  > 商户域直接返回 db 行(多为 snake_case),与网关 `/api/v1` 的 camelCase 不同。
191
210
 
211
+ ### 计费 / 配额 — P1(v0.5.0 新增)
212
+
213
+ | 资源 | 主要能力 | API 域 |
214
+ |------|----------|--------|
215
+ | `client.billing` | **社媒域计费(BillingResource)**:套餐 / Token 包 / 价格(公开)、Token 包购买(Stripe Checkout,未配置时落 pending)、Customer Portal、浏览器实例配额与购买流水(7 方法) | Server |
216
+ | `client.sharedBilling` | **统一计费(SharedBillingResource)**:订阅列表 / 当前订阅与本月用量、用量记账、Token 包购买(支持推广余额抵扣)、加密收款(通道 / 下单 / 列表 / 详情 / 取消 / 确认)(12 方法) | Server |
217
+ | `client.quota` | **社媒域本月配额(QuotaResource)**:`copywriting` / `tts` / `video` / `poster` 的 limit / used / remaining / allowed(1 方法) | Server |
218
+
219
+ > 两个计费资源路径不同:`client.billing` → `/api/billing/*`(社媒域),`client.sharedBilling` → `/api/shared/billing/*`(统一账本)。
220
+ > 订阅 / 用量 / 加密收款需 **账户 JWT + 租户成员**,`tenantId` 显式传参;`plans` / `token-packs` / `prices` / `crypto/methods` 公开。
221
+ > 已退役端点未封装:`POST /api/billing/checkout` 与 `POST /api/shared/billing/subscriptions` 恒 410(新购走 `/api/seats`);
222
+ > `webhook` / `payments-events` 为服务端验签回调,不属于 SDK 调用面。
223
+
192
224
  > crm 客服指标(原 `client.analytics`)与社媒运营看板(原 `client.dashboard`)已统一为 `client.dashboard`(DashboardApi);AgentX(原 `client.agentx`)与社媒 Agent 市场已统一为 `client.agents`(AgentApi)。
193
225
 
194
226
  ## 统一入口说明
195
227
 
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。
228
+ - **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
229
  - **DashboardApi(`client.dashboard`)**:唯一看板入口(P2.4.4)。crm 域(`global` / `dashboard(projectId)` / `botMetrics` / `summaryByUser`)+ social 域(`overview` / `quota` / `trend`)。
198
230
 
199
231
  ## Function Calling(工具回调)
@@ -214,7 +246,7 @@ npm test # node --test,覆盖 test/*.test.mjs
214
246
  | 测试文件 | 覆盖 |
215
247
  |----------|------|
216
248
  | `test/client.test.mjs` | ReachClient 核心行为:构造校验(`MISSING_AUTH`)、认证 Header、双 base 路由、body 序列化、错误语义 |
217
- | `test/resources.test.mjs` | **全量** 34 资源类 267 方法的 method / path / body 断言(要求每个方法至少被一条用例覆盖) |
249
+ | `test/resources.test.mjs` | **全量** 37 资源类 287 方法的 method / path / body 断言(要求每个方法至少被一条用例覆盖) |
218
250
  | `test/smoke.test.mjs` | 导出面 + 资源方法面快照 |
219
251
 
220
252
  > 测试跑 **`dist/` 产物**,改完 `src/` 必须先 `npm run build`。
package/dist/client.d.ts CHANGED
@@ -23,6 +23,7 @@ import { SeoGeoResource } from "./resources/seo-geo.js";
23
23
  import { ContentPlansResource } from "./resources/content-plans.js";
24
24
  import { PublishPlansResource } from "./resources/publish-plans.js";
25
25
  import { BrowserTemplatesResource } from "./resources/browser-templates.js";
26
+ import { BrowserResource } from "./resources/browser.js";
26
27
  import { AiMediaResource } from "./resources/ai-media.js";
27
28
  import { ContentRulesResource } from "./resources/content-rules.js";
28
29
  import { DataSourcesResource } from "./resources/data-sources.js";
@@ -33,6 +34,9 @@ import { TeamResource } from "./resources/team.js";
33
34
  import { MerchantResource } from "./resources/merchant.js";
34
35
  import { ChannelAdminResource } from "./resources/channel-admin.js";
35
36
  import { EmailChannelResource } from "./resources/email-channel.js";
37
+ import { BillingResource } from "./resources/billing.js";
38
+ import { SharedBillingResource } from "./resources/shared-billing.js";
39
+ import { QuotaResource } from "./resources/quota.js";
36
40
  export declare class ReachClient {
37
41
  private apiKey?;
38
42
  private token?;
@@ -62,6 +66,8 @@ export declare class ReachClient {
62
66
  contentPlans: ContentPlansResource;
63
67
  publishPlans: PublishPlansResource;
64
68
  browserTemplates: BrowserTemplatesResource;
69
+ /** 浏览器实时会话(/api/browser/live/*) */
70
+ browser: BrowserResource;
65
71
  aiMedia: AiMediaResource;
66
72
  effect: EffectResource;
67
73
  seoGeo: SeoGeoResource;
@@ -73,6 +79,9 @@ export declare class ReachClient {
73
79
  merchant: MerchantResource;
74
80
  channelAdmin: ChannelAdminResource;
75
81
  emailChannel: EmailChannelResource;
82
+ billing: BillingResource;
83
+ sharedBilling: SharedBillingResource;
84
+ quota: QuotaResource;
76
85
  constructor(config: ReachClientConfig);
77
86
  /** Set token after wallet login */
78
87
  setToken(token: string): void;
package/dist/client.js CHANGED
@@ -23,6 +23,7 @@ import { SeoGeoResource } from "./resources/seo-geo.js";
23
23
  import { ContentPlansResource } from "./resources/content-plans.js";
24
24
  import { PublishPlansResource } from "./resources/publish-plans.js";
25
25
  import { BrowserTemplatesResource } from "./resources/browser-templates.js";
26
+ import { BrowserResource } from "./resources/browser.js";
26
27
  import { AiMediaResource } from "./resources/ai-media.js";
27
28
  import { ContentRulesResource } from "./resources/content-rules.js";
28
29
  import { DataSourcesResource } from "./resources/data-sources.js";
@@ -33,6 +34,9 @@ import { TeamResource } from "./resources/team.js";
33
34
  import { MerchantResource } from "./resources/merchant.js";
34
35
  import { ChannelAdminResource } from "./resources/channel-admin.js";
35
36
  import { EmailChannelResource } from "./resources/email-channel.js";
37
+ import { BillingResource } from "./resources/billing.js";
38
+ import { SharedBillingResource } from "./resources/shared-billing.js";
39
+ import { QuotaResource } from "./resources/quota.js";
36
40
  export class ReachClient {
37
41
  constructor(config) {
38
42
  if (!config.apiKey && !config.token) {
@@ -67,6 +71,7 @@ export class ReachClient {
67
71
  this.contentPlans = new ContentPlansResource(this.requestServer.bind(this));
68
72
  this.publishPlans = new PublishPlansResource(this.requestServer.bind(this));
69
73
  this.browserTemplates = new BrowserTemplatesResource(this.requestServer.bind(this));
74
+ this.browser = new BrowserResource(this.requestServer.bind(this));
70
75
  this.aiMedia = new AiMediaResource(this.requestServer.bind(this));
71
76
  this.effect = new EffectResource(this.requestServer.bind(this));
72
77
  this.seoGeo = new SeoGeoResource(this.requestServer.bind(this));
@@ -78,6 +83,9 @@ export class ReachClient {
78
83
  this.merchant = new MerchantResource(this.requestServer.bind(this));
79
84
  this.channelAdmin = new ChannelAdminResource(this.requestServer.bind(this));
80
85
  this.emailChannel = new EmailChannelResource(this.requestServer.bind(this));
86
+ this.billing = new BillingResource(this.requestServer.bind(this));
87
+ this.sharedBilling = new SharedBillingResource(this.requestServer.bind(this));
88
+ this.quota = new QuotaResource(this.requestServer.bind(this));
81
89
  }
82
90
  /** Set token after wallet login */
83
91
  setToken(token) {
package/dist/error.js CHANGED
@@ -1,3 +1,4 @@
1
+ // SPDX-License-Identifier: Apache-2.0
1
2
  export class ReachError extends Error {
2
3
  constructor(message, code, status, details) {
3
4
  super(message);
package/dist/index.d.ts CHANGED
@@ -25,6 +25,7 @@ export { SeoGeoResource } from "./resources/seo-geo.js";
25
25
  export { ContentPlansResource } from "./resources/content-plans.js";
26
26
  export { PublishPlansResource } from "./resources/publish-plans.js";
27
27
  export { BrowserTemplatesResource } from "./resources/browser-templates.js";
28
+ export { BrowserResource } from "./resources/browser.js";
28
29
  export { AiMediaResource } from "./resources/ai-media.js";
29
30
  export { ContentRulesResource } from "./resources/content-rules.js";
30
31
  export { DataSourcesResource } from "./resources/data-sources.js";
@@ -34,7 +35,15 @@ export { TeamResource } from "./resources/team.js";
34
35
  export { MerchantResource } from "./resources/merchant.js";
35
36
  export { ChannelAdminResource } from "./resources/channel-admin.js";
36
37
  export { EmailChannelResource } from "./resources/email-channel.js";
38
+ export { BillingResource } from "./resources/billing.js";
39
+ export { SharedBillingResource } from "./resources/shared-billing.js";
40
+ export { QuotaResource } from "./resources/quota.js";
37
41
  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
42
  export type { ApiKeyInfo, ApiKeyCreated } from "./resources/api-key.js";
39
- export type { SocialAccountCreateParams } from "./resources/accounts.js";
43
+ export type { BrandBusinessType, BrandProfileInput, BrandProfilePatch, } from "./resources/seo-geo.js";
44
+ export type { SocialAccountCreateParams, FingerprintProfileCreateParams, AccountEgressBindParams, } from "./resources/accounts.js";
45
+ export type { LiveSetCookiesParams } from "./resources/browser.js";
40
46
  export type { EmailSendParams, EmailPollParams, EmailInboundParams, } from "./resources/email-channel.js";
47
+ export type { BillingPlan, BillingPlansResult, BillingTokenPack, BillingTokenPacksResult, BillingPrice, BillingPricesResult, TokenPackCheckoutResult, BrowserQuotaStatus, BrowserPackPurchase, BrowserPackPurchasesResult, } from "./resources/billing.js";
48
+ export type { SharedSubscriptionPlanRef, SharedSubscription, SubscriptionQuotaResource, SubscriptionUsage, RecordUsageParams, UsageRecordResult, SharedTokenPackPurchaseParams, SharedTokenPackPurchaseResult, CryptoMethodsResult, CryptoOrderParams, CryptoOrder, CryptoOrderListResult, CryptoOrderConfirmParams, } from "./resources/shared-billing.js";
49
+ export type { QuotaEntry, QuotaResourceKey, QuotaSummaryResult, } from "./resources/quota.js";
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ // SPDX-License-Identifier: Apache-2.0
1
2
  export { ReachClient } from "./client.js";
2
3
  export { ReachError } from "./error.js";
3
4
  export { ProjectResource } from "./resources/project.js";
@@ -25,6 +26,7 @@ export { SeoGeoResource } from "./resources/seo-geo.js";
25
26
  export { ContentPlansResource } from "./resources/content-plans.js";
26
27
  export { PublishPlansResource } from "./resources/publish-plans.js";
27
28
  export { BrowserTemplatesResource } from "./resources/browser-templates.js";
29
+ export { BrowserResource } from "./resources/browser.js";
28
30
  export { AiMediaResource } from "./resources/ai-media.js";
29
31
  export { ContentRulesResource } from "./resources/content-rules.js";
30
32
  export { DataSourcesResource } from "./resources/data-sources.js";
@@ -34,3 +36,6 @@ export { TeamResource } from "./resources/team.js";
34
36
  export { MerchantResource } from "./resources/merchant.js";
35
37
  export { ChannelAdminResource } from "./resources/channel-admin.js";
36
38
  export { EmailChannelResource } from "./resources/email-channel.js";
39
+ export { BillingResource } from "./resources/billing.js";
40
+ export { SharedBillingResource } from "./resources/shared-billing.js";
41
+ export { QuotaResource } from "./resources/quota.js";
@@ -8,6 +8,20 @@ export interface SocialAccountCreateParams {
8
8
  credentials?: Record<string, unknown>;
9
9
  usageType?: "general" | "nurture" | "execute";
10
10
  }
11
+ export interface FingerprintProfileCreateParams {
12
+ /** Profile 标签(如 twitter-main) */
13
+ label: string;
14
+ /** 平台编码(twitter/facebook/instagram/...) */
15
+ platform: string;
16
+ }
17
+ export interface AccountEgressBindParams {
18
+ /** 住宅出口路由 ID(GET /api/egress/residential/routes) */
19
+ routeId: string;
20
+ /** 粘性会话时长(分钟,5-43200,默认 1440) */
21
+ stickyTtlMin?: number;
22
+ /** 换出口策略 */
23
+ rotatePolicy?: "manual" | "on_fail" | "daily";
24
+ }
11
25
  /**
12
26
  * Accounts 资源 — 社媒账号矩阵(源自 aiops-saas @aiops/sdk AccountsApi)。
13
27
  * 端点走 Server API(/api/accounts/*)。
@@ -15,13 +29,33 @@ export interface SocialAccountCreateParams {
15
29
  export declare class AccountsResource {
16
30
  private request;
17
31
  constructor(request: RequestFn);
18
- /** 账号列表(?usageType=general|nurture|execute) */
19
- list(usageType?: "general" | "nurture" | "execute"): Promise<any>;
32
+ /** 账号列表(?usageType=nurture|execute) */
33
+ list(usageType?: "nurture" | "execute"): Promise<any>;
20
34
  /**
21
35
  * 新增平台账号(POST /api/accounts;凭据服务端加密入库)。
22
36
  * v0.4.0 修复:旧 `connect(platform, credentials)` 指向不存在的
23
37
  * `/api/accounts/:platform/connect`,调用必 404。
24
38
  */
25
39
  create(params: SocialAccountCreateParams): Promise<any>;
40
+ /** 指纹 Profile 列表(GET /api/accounts/profiles) */
41
+ listProfiles(): Promise<any>;
42
+ /** 自助创建指纹 Profile(POST /api/accounts/profiles) */
43
+ createProfile(params: FingerprintProfileCreateParams): Promise<any>;
44
+ /**
45
+ * 粘贴 Cookie 导入/续期登录态(POST /api/accounts/:id/import-cookies)。
46
+ * 前置:账号已绑定 Profile,且该身份有在线浏览器实例。
47
+ */
48
+ importCookies(accountId: string, cookies: string | unknown[]): Promise<any>;
49
+ /** 账号当前住宅出口绑定(GET /api/accounts/:id/egress;密码不回显) */
50
+ getEgress(accountId: string): Promise<any>;
51
+ /** 绑定账号到住宅出口路由(PUT /api/accounts/:id/egress;账号↔路由 1:1) */
52
+ bindEgress(accountId: string, params: AccountEgressBindParams): Promise<any>;
53
+ /** 换出口(POST /api/accounts/:id/egress/rotate;新粘性会话,可同时换路由) */
54
+ rotateEgress(accountId: string, params?: {
55
+ routeId?: string;
56
+ reason?: string;
57
+ }): Promise<any>;
58
+ /** 解绑住宅出口,回落 Profile 出口(DELETE /api/accounts/:id/egress) */
59
+ unbindEgress(accountId: string): Promise<any>;
26
60
  }
27
61
  export {};
@@ -6,7 +6,7 @@ export class AccountsResource {
6
6
  constructor(request) {
7
7
  this.request = request;
8
8
  }
9
- /** 账号列表(?usageType=general|nurture|execute) */
9
+ /** 账号列表(?usageType=nurture|execute) */
10
10
  list(usageType) {
11
11
  const qs = usageType ? `?usageType=${encodeURIComponent(usageType)}` : "";
12
12
  return this.request("GET", `/api/accounts${qs}`);
@@ -19,4 +19,35 @@ export class AccountsResource {
19
19
  create(params) {
20
20
  return this.request("POST", "/api/accounts", params);
21
21
  }
22
+ /** 指纹 Profile 列表(GET /api/accounts/profiles) */
23
+ listProfiles() {
24
+ return this.request("GET", "/api/accounts/profiles");
25
+ }
26
+ /** 自助创建指纹 Profile(POST /api/accounts/profiles) */
27
+ createProfile(params) {
28
+ return this.request("POST", "/api/accounts/profiles", params);
29
+ }
30
+ /**
31
+ * 粘贴 Cookie 导入/续期登录态(POST /api/accounts/:id/import-cookies)。
32
+ * 前置:账号已绑定 Profile,且该身份有在线浏览器实例。
33
+ */
34
+ importCookies(accountId, cookies) {
35
+ return this.request("POST", `/api/accounts/${encodeURIComponent(accountId)}/import-cookies`, { cookies });
36
+ }
37
+ /** 账号当前住宅出口绑定(GET /api/accounts/:id/egress;密码不回显) */
38
+ getEgress(accountId) {
39
+ return this.request("GET", `/api/accounts/${encodeURIComponent(accountId)}/egress`);
40
+ }
41
+ /** 绑定账号到住宅出口路由(PUT /api/accounts/:id/egress;账号↔路由 1:1) */
42
+ bindEgress(accountId, params) {
43
+ return this.request("PUT", `/api/accounts/${encodeURIComponent(accountId)}/egress`, params);
44
+ }
45
+ /** 换出口(POST /api/accounts/:id/egress/rotate;新粘性会话,可同时换路由) */
46
+ rotateEgress(accountId, params = {}) {
47
+ return this.request("POST", `/api/accounts/${encodeURIComponent(accountId)}/egress/rotate`, params);
48
+ }
49
+ /** 解绑住宅出口,回落 Profile 出口(DELETE /api/accounts/:id/egress) */
50
+ unbindEgress(accountId) {
51
+ return this.request("DELETE", `/api/accounts/${encodeURIComponent(accountId)}/egress`);
52
+ }
22
53
  }
@@ -4,11 +4,11 @@ export declare class AuthResource {
4
4
  private request;
5
5
  constructor(request: RequestFn);
6
6
  /**
7
- * 获取钱包签名挑战(nonce)。
8
- * 服务端签发后存 Redis 10 分钟一次性;签名对象即返回的 nonce 字符串本体。
7
+ * 获取钱包登录挑战(nonce)。
8
+ * 服务端签发后存 Redis 10 分钟一次性;nonce 用作 SIWE 消息(EIP-4361)的 nonce 字段。
9
9
  */
10
10
  getChallenge(wallet: string): Promise<WalletNonce>;
11
- /** 钱包签名登录(server 契约:{ wallet, nonce, signature }) */
11
+ /** 钱包 SIWE(EIP-4361)签名登录(server 契约:{ message, signature }) */
12
12
  walletLogin(params: WalletLoginParams): Promise<AuthResult>;
13
13
  /**
14
14
  * 获取图形验证码(login/register 前置,可选)。
@@ -3,13 +3,13 @@ export class AuthResource {
3
3
  this.request = request;
4
4
  }
5
5
  /**
6
- * 获取钱包签名挑战(nonce)。
7
- * 服务端签发后存 Redis 10 分钟一次性;签名对象即返回的 nonce 字符串本体。
6
+ * 获取钱包登录挑战(nonce)。
7
+ * 服务端签发后存 Redis 10 分钟一次性;nonce 用作 SIWE 消息(EIP-4361)的 nonce 字段。
8
8
  */
9
9
  getChallenge(wallet) {
10
10
  return this.request("POST", "/api/auth/wallet-nonce", { wallet });
11
11
  }
12
- /** 钱包签名登录(server 契约:{ wallet, nonce, signature }) */
12
+ /** 钱包 SIWE(EIP-4361)签名登录(server 契约:{ message, signature }) */
13
13
  walletLogin(params) {
14
14
  return this.request("POST", "/api/auth/wallet-login", params);
15
15
  }