@reachv2/sdk 0.1.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 +153 -0
- package/dist/client.d.ts +59 -0
- package/dist/client.js +107 -0
- package/dist/error.d.ts +6 -0
- package/dist/error.js +9 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +22 -0
- package/dist/resources/abis.d.ts +20 -0
- package/dist/resources/abis.js +17 -0
- package/dist/resources/accounts.d.ts +15 -0
- package/dist/resources/accounts.js +17 -0
- package/dist/resources/admin.d.ts +34 -0
- package/dist/resources/admin.js +41 -0
- package/dist/resources/agent-api.d.ts +61 -0
- package/dist/resources/agent-api.js +112 -0
- package/dist/resources/api-key.d.ts +42 -0
- package/dist/resources/api-key.js +17 -0
- package/dist/resources/auth.d.ts +24 -0
- package/dist/resources/auth.js +40 -0
- package/dist/resources/bot.d.ts +17 -0
- package/dist/resources/bot.js +29 -0
- package/dist/resources/channel.d.ts +23 -0
- package/dist/resources/channel.js +25 -0
- package/dist/resources/chat.d.ts +9 -0
- package/dist/resources/chat.js +9 -0
- package/dist/resources/content.d.ts +25 -0
- package/dist/resources/content.js +43 -0
- package/dist/resources/conversation.d.ts +19 -0
- package/dist/resources/conversation.js +24 -0
- package/dist/resources/dashboard-api.d.ts +31 -0
- package/dist/resources/dashboard-api.js +45 -0
- package/dist/resources/internalAgent.d.ts +70 -0
- package/dist/resources/internalAgent.js +60 -0
- package/dist/resources/knowledge.d.ts +17 -0
- package/dist/resources/knowledge.js +17 -0
- package/dist/resources/lightrag.d.ts +80 -0
- package/dist/resources/lightrag.js +92 -0
- package/dist/resources/orchestration.d.ts +46 -0
- package/dist/resources/orchestration.js +42 -0
- package/dist/resources/project.d.ts +14 -0
- package/dist/resources/project.js +20 -0
- package/dist/resources/scheduledTasks.d.ts +29 -0
- package/dist/resources/scheduledTasks.js +22 -0
- package/dist/resources/transaction.d.ts +28 -0
- package/dist/resources/transaction.js +24 -0
- package/dist/resources/tts.d.ts +17 -0
- package/dist/resources/tts.js +22 -0
- package/dist/types.d.ts +793 -0
- package/dist/types.js +1 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# @reachv2/sdk
|
|
2
|
+
|
|
3
|
+
Reach(reach.codes)统一平台的官方 TypeScript SDK —— 由 aiservicer SDK(crm 域,18 资源)与 aiops-saas SDK(social 域,5 资源)合并而来(P2.4)。一个客户端覆盖客服 / 销售引导、社群维护与社媒运营全部资源。
|
|
4
|
+
|
|
5
|
+
- 运行时:Node.js >= 18(ESM)
|
|
6
|
+
- 类型:完整 TypeScript 类型定义(自带 `dist/index.d.ts`)
|
|
7
|
+
- License:MIT
|
|
8
|
+
|
|
9
|
+
## 文档
|
|
10
|
+
|
|
11
|
+
- **[API Reference](docs/API-REFERENCE.md)**(P2.6):全部 20 个资源类 + `ReachClient` 共 **120 个方法**的签名 / 端点 / 参数 / 返回类型 / 错误 / 示例,与 `sdk/src` 源码一一对应。
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @reachv2/sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 快速开始
|
|
20
|
+
|
|
21
|
+
### 方式一:API Key(推荐,服务端 / 简单集成)
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { ReachClient } from "@reachv2/sdk";
|
|
25
|
+
|
|
26
|
+
const client = new ReachClient({
|
|
27
|
+
baseUrl: "https://reach.codes", // 统一网关根地址(生产域名,走 HTTPS)
|
|
28
|
+
apiKey: "reach-xxx", // 商户 API Key
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// 列出 crm 域 agent(唯一 Agent 入口)
|
|
32
|
+
const { agents } = await client.agents.list({ projectId: "project-xxx" });
|
|
33
|
+
|
|
34
|
+
// 与 agent 对话(RAG + 交易构造由服务端完成)
|
|
35
|
+
const { reply, transaction } = await client.agents.chat("bot-xxx", {
|
|
36
|
+
message: "我想在 Base 上铸造一个 NFT",
|
|
37
|
+
userAddress: "0x1234...",
|
|
38
|
+
chainId: 8453,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// 社媒域:生成文案
|
|
42
|
+
const post = await client.content.generate("AI trends", "twitter", "professional");
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 方式二:JWT 登录(需数学验证码)
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const client = new ReachClient({ baseUrl: "https://reach.codes", apiKey: "reach-xxx" });
|
|
49
|
+
|
|
50
|
+
const { token, svg } = await client.auth.getCaptcha();
|
|
51
|
+
const svgText = Buffer.from(svg.replace(/^data:image\/svg\+xml;base64,/, ""), "base64").toString("utf-8");
|
|
52
|
+
const m = svgText.match(/(\d+)\s*([+-])\s*(\d+)/)!;
|
|
53
|
+
const answer = m[2] === "+" ? Number(m[1]) + Number(m[3]) : Number(m[1]) - Number(m[3]);
|
|
54
|
+
|
|
55
|
+
const { token: jwt } = await client.auth.login("username", "password", { token, answer });
|
|
56
|
+
client.setToken(jwt); // SDK 不会自动接线,需手动 setToken 切换为 JWT 模式
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
> **JWT 续期约定**:`login` 签发 7 天有效 JWT 且无 refresh 机制,请提前 1 天重新登录并 `setToken`。
|
|
60
|
+
|
|
61
|
+
## 认证方式
|
|
62
|
+
|
|
63
|
+
| 方式 | 配置 | 生效域 |
|
|
64
|
+
|------|------|--------|
|
|
65
|
+
| API Key | `config.apiKey` | 所有请求带 `X-API-Key` Header |
|
|
66
|
+
| 商户 JWT | `client.setToken(jwt)` | 覆盖 API Key,带 `Authorization: Bearer` |
|
|
67
|
+
| 管理员 JWT | `client.admin` 前置 setToken(管理员账号) | Admin 资源(`/api/admin/*`) |
|
|
68
|
+
|
|
69
|
+
> `setToken()` 是全局切换,调用后所有资源请求优先使用 JWT。
|
|
70
|
+
|
|
71
|
+
## 统一网关(A.2.4)
|
|
72
|
+
|
|
73
|
+
合并后 Reach 采用**单后端 + 统一网关层**:`@reachv2/sdk` 只走网关。默认 `serverBaseUrl` 省略时等于 `baseUrl`,全部请求经统一网关;`serverBaseUrl` 仅作内部调试 override。
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const client = new ReachClient({
|
|
77
|
+
baseUrl: "https://reach.codes", // 统一网关
|
|
78
|
+
apiKey: "reach-xxx",
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 资源概览(client.*)
|
|
83
|
+
|
|
84
|
+
统一资源按 **crm 域 / social 域 / 共享基础** 组织(A.5.3):
|
|
85
|
+
|
|
86
|
+
### 共享基础
|
|
87
|
+
|
|
88
|
+
| 资源 | 主要能力 | API 域 |
|
|
89
|
+
|------|----------|--------|
|
|
90
|
+
| `client.auth` | 验证码(getCaptcha)、登录、注册、钱包登录(MFA/SSO) | Server |
|
|
91
|
+
| `client.admin` | 平台仪表盘、商户、计费、LLM 设置(需管理员 JWT) | Admin |
|
|
92
|
+
| `client.apiKeys` | API Key 创建/列表/吊销 | Gateway |
|
|
93
|
+
| `client.dashboard` | **统一看板**(DashboardApi):crm 客服指标 + social 社媒运营看板 | 双域 |
|
|
94
|
+
| `client.orchestration` | 对话编排(多 task × 多 agent) | Server |
|
|
95
|
+
|
|
96
|
+
### crm 域(源自 aiservicer)
|
|
97
|
+
|
|
98
|
+
| 资源 | 主要能力 | API 域 |
|
|
99
|
+
|------|----------|--------|
|
|
100
|
+
| `client.agents` | **统一 Agent 入口**(AgentApi):调用方 agent(list/get/capabilities/chat/prepareTransaction)+ AgentX 链上市场/订阅/状态/用量/发布/技能 + 市场 run/clone | 双域 |
|
|
101
|
+
| `client.project` | 项目 CRUD、列表 | Gateway |
|
|
102
|
+
| `client.bot` | Bot(客服/销售/交易/自定义)CRUD、启停、统计 | Gateway |
|
|
103
|
+
| `client.knowledge` | 知识文档 CRUD、推荐 | Gateway |
|
|
104
|
+
| `client.channel` | 渠道(telegram/whatsapp/webwidget)创建与配置 | Gateway |
|
|
105
|
+
| `client.conversation` | 对话记录与消息 | Gateway |
|
|
106
|
+
| `client.transaction` | 交易意图解析/构造/模拟、协议/合约/calldata 查询 | Gateway |
|
|
107
|
+
| `client.chat` | 服务端对话(含 function calling tools、A2A 编排) | Server |
|
|
108
|
+
| `client.lightrag` | RAG Key 管理 + 文档 CRUD + 查询(per-user namespace) | Gateway |
|
|
109
|
+
| `client.scheduledTasks` | 主 agent 定时任务管理 | Server |
|
|
110
|
+
| `client.internal` | 企业内 Agent:企业级共享知识库 + 监控连接器/事件(`internal` bot) | Server |
|
|
111
|
+
| `client.abis` | 商户租户合约 ABI 管理:list/add/remove(交易 agent 上传 ABI 后即可按函数构造链上调用) | Server |
|
|
112
|
+
|
|
113
|
+
### social 域(源自 aiops-saas)
|
|
114
|
+
|
|
115
|
+
| 资源 | 主要能力 | API 域 |
|
|
116
|
+
|------|----------|--------|
|
|
117
|
+
| `client.content` | 社媒文案生成(generate/list/platforms/styles/get/update/delete) | Server |
|
|
118
|
+
| `client.tts` | 文本转语音(synthesize/voices/history) | Server |
|
|
119
|
+
| `client.accounts` | 社媒账号矩阵(list/connect) | Server |
|
|
120
|
+
|
|
121
|
+
> crm 客服指标(原 `client.analytics`)与社媒运营看板(原 `client.dashboard`)已统一为 `client.dashboard`(DashboardApi);AgentX(原 `client.agentx`)与社媒 Agent 市场已统一为 `client.agents`(AgentApi)。
|
|
122
|
+
|
|
123
|
+
## 统一入口说明
|
|
124
|
+
|
|
125
|
+
- **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。
|
|
126
|
+
- **DashboardApi(`client.dashboard`)**:唯一看板入口(P2.4.4)。crm 域(`global` / `dashboard(projectId)` / `botMetrics` / `summaryByUser`)+ social 域(`overview` / `quota` / `trend`)。
|
|
127
|
+
|
|
128
|
+
## Function Calling(工具回调)
|
|
129
|
+
|
|
130
|
+
`chat.send` / `agents.chat` 支持 `tools` 参数(OpenAI function calling 兼容格式)。平台执行工具时 POST 到 `callback_url`,回调体 `{ tool, arguments }`,携带 `X-Tool-Key` 头。
|
|
131
|
+
|
|
132
|
+
> 平台**不代验签**——回调服务必须自行校验 `X-Tool-Key`(推荐 `timingSafeEqual`)。15s 超时 / 最多 5 轮循环。
|
|
133
|
+
|
|
134
|
+
## 开发 / 测试
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
cd sdk
|
|
138
|
+
npm install
|
|
139
|
+
npm run build # tsc → dist
|
|
140
|
+
npm test # node --test test/(冒烟:导出 + 资源方法面)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 发布流程(维护者)
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
cd sdk
|
|
147
|
+
npm version <minor> --no-git-tag-version # 小版本递增,紧贴 API 变更
|
|
148
|
+
npm run build # tsc → dist
|
|
149
|
+
npm pack # 本地验证发布产物(含 dist + README)
|
|
150
|
+
npm publish # token 在 ~/.npmrc(reachv2 组织)
|
|
151
|
+
cd .. && git add sdk/package.json sdk/package-lock.json
|
|
152
|
+
git commit -m "chore(sdk): 发布 @reachv2/sdk@<version>"
|
|
153
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ReachClientConfig, RequestMethod } from "./types.js";
|
|
2
|
+
import { ProjectResource } from "./resources/project.js";
|
|
3
|
+
import { BotResource } from "./resources/bot.js";
|
|
4
|
+
import { AgentApi } from "./resources/agent-api.js";
|
|
5
|
+
import { KnowledgeResource } from "./resources/knowledge.js";
|
|
6
|
+
import { ChannelResource } from "./resources/channel.js";
|
|
7
|
+
import { ConversationResource } from "./resources/conversation.js";
|
|
8
|
+
import { TransactionResource } from "./resources/transaction.js";
|
|
9
|
+
import { AuthResource } from "./resources/auth.js";
|
|
10
|
+
import { ChatResource } from "./resources/chat.js";
|
|
11
|
+
import { ApiKeyResource } from "./resources/api-key.js";
|
|
12
|
+
import { LightRAGResource } from "./resources/lightrag.js";
|
|
13
|
+
import { AdminResource } from "./resources/admin.js";
|
|
14
|
+
import { OrchestrationResource } from "./resources/orchestration.js";
|
|
15
|
+
import { ScheduledTasksResource } from "./resources/scheduledTasks.js";
|
|
16
|
+
import { InternalAgentResource } from "./resources/internalAgent.js";
|
|
17
|
+
import { AbiResource } from "./resources/abis.js";
|
|
18
|
+
import { ContentResource } from "./resources/content.js";
|
|
19
|
+
import { TtsResource } from "./resources/tts.js";
|
|
20
|
+
import { AccountsResource } from "./resources/accounts.js";
|
|
21
|
+
import { DashboardApi } from "./resources/dashboard-api.js";
|
|
22
|
+
export declare class ReachClient {
|
|
23
|
+
private apiKey?;
|
|
24
|
+
private token?;
|
|
25
|
+
private baseUrl;
|
|
26
|
+
private serverBaseUrl;
|
|
27
|
+
project: ProjectResource;
|
|
28
|
+
bot: BotResource;
|
|
29
|
+
/** 唯一 Agent 入口(P2.4.3 统一:S agent+agentx + A agents) */
|
|
30
|
+
agents: AgentApi;
|
|
31
|
+
knowledge: KnowledgeResource;
|
|
32
|
+
channel: ChannelResource;
|
|
33
|
+
conversation: ConversationResource;
|
|
34
|
+
transaction: TransactionResource;
|
|
35
|
+
auth: AuthResource;
|
|
36
|
+
chat: ChatResource;
|
|
37
|
+
apiKeys: ApiKeyResource;
|
|
38
|
+
lightrag: LightRAGResource;
|
|
39
|
+
orchestration: OrchestrationResource;
|
|
40
|
+
scheduledTasks: ScheduledTasksResource;
|
|
41
|
+
internal: InternalAgentResource;
|
|
42
|
+
abis: AbiResource;
|
|
43
|
+
admin: AdminResource;
|
|
44
|
+
dashboard: DashboardApi;
|
|
45
|
+
content: ContentResource;
|
|
46
|
+
tts: TtsResource;
|
|
47
|
+
accounts: AccountsResource;
|
|
48
|
+
constructor(config: ReachClientConfig);
|
|
49
|
+
/** Set token after wallet login */
|
|
50
|
+
setToken(token: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Perform an arbitrary Gateway API request.
|
|
53
|
+
* Advanced use — for endpoints not yet covered by a typed resource.
|
|
54
|
+
*/
|
|
55
|
+
request<T>(method: RequestMethod, path: string, body?: unknown): Promise<T>;
|
|
56
|
+
private requestGateway;
|
|
57
|
+
private requestServer;
|
|
58
|
+
private _request;
|
|
59
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ReachError } from "./error.js";
|
|
2
|
+
import { ProjectResource } from "./resources/project.js";
|
|
3
|
+
import { BotResource } from "./resources/bot.js";
|
|
4
|
+
import { AgentApi } from "./resources/agent-api.js";
|
|
5
|
+
import { KnowledgeResource } from "./resources/knowledge.js";
|
|
6
|
+
import { ChannelResource } from "./resources/channel.js";
|
|
7
|
+
import { ConversationResource } from "./resources/conversation.js";
|
|
8
|
+
import { TransactionResource } from "./resources/transaction.js";
|
|
9
|
+
import { AuthResource } from "./resources/auth.js";
|
|
10
|
+
import { ChatResource } from "./resources/chat.js";
|
|
11
|
+
import { ApiKeyResource } from "./resources/api-key.js";
|
|
12
|
+
import { LightRAGResource } from "./resources/lightrag.js";
|
|
13
|
+
import { AdminResource } from "./resources/admin.js";
|
|
14
|
+
import { OrchestrationResource } from "./resources/orchestration.js";
|
|
15
|
+
import { ScheduledTasksResource } from "./resources/scheduledTasks.js";
|
|
16
|
+
import { InternalAgentResource } from "./resources/internalAgent.js";
|
|
17
|
+
import { AbiResource } from "./resources/abis.js";
|
|
18
|
+
import { ContentResource } from "./resources/content.js";
|
|
19
|
+
import { TtsResource } from "./resources/tts.js";
|
|
20
|
+
import { AccountsResource } from "./resources/accounts.js";
|
|
21
|
+
import { DashboardApi } from "./resources/dashboard-api.js";
|
|
22
|
+
export class ReachClient {
|
|
23
|
+
constructor(config) {
|
|
24
|
+
if (!config.apiKey && !config.token) {
|
|
25
|
+
throw new ReachError("Either apiKey or token must be provided", "MISSING_AUTH", 0);
|
|
26
|
+
}
|
|
27
|
+
this.apiKey = config.apiKey;
|
|
28
|
+
this.token = config.token;
|
|
29
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
30
|
+
this.serverBaseUrl = config.serverBaseUrl
|
|
31
|
+
? config.serverBaseUrl.replace(/\/+$/, "")
|
|
32
|
+
: this.baseUrl;
|
|
33
|
+
this.project = new ProjectResource(this.requestGateway.bind(this));
|
|
34
|
+
this.bot = new BotResource(this.requestGateway.bind(this));
|
|
35
|
+
this.agents = new AgentApi(this.requestGateway.bind(this), this.requestServer.bind(this));
|
|
36
|
+
this.knowledge = new KnowledgeResource(this.requestGateway.bind(this));
|
|
37
|
+
this.channel = new ChannelResource(this.requestGateway.bind(this));
|
|
38
|
+
this.conversation = new ConversationResource(this.requestGateway.bind(this));
|
|
39
|
+
this.transaction = new TransactionResource(this.requestGateway.bind(this));
|
|
40
|
+
this.dashboard = new DashboardApi(this.requestGateway.bind(this), this.requestServer.bind(this));
|
|
41
|
+
this.auth = new AuthResource(this.requestServer.bind(this));
|
|
42
|
+
this.chat = new ChatResource(this.requestServer.bind(this));
|
|
43
|
+
this.apiKeys = new ApiKeyResource(this.requestGateway.bind(this));
|
|
44
|
+
this.lightrag = new LightRAGResource(this.requestGateway.bind(this));
|
|
45
|
+
this.admin = new AdminResource(this.requestServer.bind(this));
|
|
46
|
+
this.orchestration = new OrchestrationResource(this.requestServer.bind(this));
|
|
47
|
+
this.scheduledTasks = new ScheduledTasksResource(this.requestServer.bind(this));
|
|
48
|
+
this.internal = new InternalAgentResource(this.requestServer.bind(this));
|
|
49
|
+
this.abis = new AbiResource(this.requestServer.bind(this));
|
|
50
|
+
this.content = new ContentResource(this.requestServer.bind(this));
|
|
51
|
+
this.tts = new TtsResource(this.requestServer.bind(this));
|
|
52
|
+
this.accounts = new AccountsResource(this.requestServer.bind(this));
|
|
53
|
+
}
|
|
54
|
+
/** Set token after wallet login */
|
|
55
|
+
setToken(token) {
|
|
56
|
+
this.token = token;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Perform an arbitrary Gateway API request.
|
|
60
|
+
* Advanced use — for endpoints not yet covered by a typed resource.
|
|
61
|
+
*/
|
|
62
|
+
request(method, path, body) {
|
|
63
|
+
return this.requestGateway(method, path, body);
|
|
64
|
+
}
|
|
65
|
+
requestGateway(method, path, body) {
|
|
66
|
+
return this._request(this.baseUrl, method, path, body);
|
|
67
|
+
}
|
|
68
|
+
requestServer(method, path, body) {
|
|
69
|
+
return this._request(this.serverBaseUrl, method, path, body);
|
|
70
|
+
}
|
|
71
|
+
async _request(baseUrl, method, path, body) {
|
|
72
|
+
const url = `${baseUrl}${path}`;
|
|
73
|
+
const headers = {
|
|
74
|
+
"Content-Type": "application/json",
|
|
75
|
+
};
|
|
76
|
+
if (this.apiKey) {
|
|
77
|
+
headers["X-API-Key"] = this.apiKey;
|
|
78
|
+
}
|
|
79
|
+
if (this.token) {
|
|
80
|
+
headers["Authorization"] = `Bearer ${this.token}`;
|
|
81
|
+
}
|
|
82
|
+
let response;
|
|
83
|
+
try {
|
|
84
|
+
response = await fetch(url, {
|
|
85
|
+
method,
|
|
86
|
+
headers,
|
|
87
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
throw new ReachError("Network request failed", "NETWORK_ERROR", 0);
|
|
92
|
+
}
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
let errorBody;
|
|
95
|
+
try {
|
|
96
|
+
errorBody = await response.json();
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
errorBody = null;
|
|
100
|
+
}
|
|
101
|
+
const message = errorBody?.message ||
|
|
102
|
+
`Request failed with status ${response.status}`;
|
|
103
|
+
throw new ReachError(message, "API_ERROR", response.status, errorBody);
|
|
104
|
+
}
|
|
105
|
+
return response.json();
|
|
106
|
+
}
|
|
107
|
+
}
|
package/dist/error.d.ts
ADDED
package/dist/error.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { ReachClient } from "./client.js";
|
|
2
|
+
export { ReachError } from "./error.js";
|
|
3
|
+
export { ProjectResource } from "./resources/project.js";
|
|
4
|
+
export { BotResource } from "./resources/bot.js";
|
|
5
|
+
export { AgentApi } from "./resources/agent-api.js";
|
|
6
|
+
export { KnowledgeResource } from "./resources/knowledge.js";
|
|
7
|
+
export { ChannelResource } from "./resources/channel.js";
|
|
8
|
+
export { ConversationResource } from "./resources/conversation.js";
|
|
9
|
+
export { DashboardApi } from "./resources/dashboard-api.js";
|
|
10
|
+
export { TransactionResource } from "./resources/transaction.js";
|
|
11
|
+
export { AuthResource } from "./resources/auth.js";
|
|
12
|
+
export { ChatResource } from "./resources/chat.js";
|
|
13
|
+
export { ApiKeyResource } from "./resources/api-key.js";
|
|
14
|
+
export { LightRAGResource } from "./resources/lightrag.js";
|
|
15
|
+
export { AdminResource } from "./resources/admin.js";
|
|
16
|
+
export { OrchestrationResource } from "./resources/orchestration.js";
|
|
17
|
+
export { ScheduledTasksResource } from "./resources/scheduledTasks.js";
|
|
18
|
+
export { InternalAgentResource } from "./resources/internalAgent.js";
|
|
19
|
+
export { AbiResource } from "./resources/abis.js";
|
|
20
|
+
export { ContentResource } from "./resources/content.js";
|
|
21
|
+
export { TtsResource } from "./resources/tts.js";
|
|
22
|
+
export { AccountsResource } from "./resources/accounts.js";
|
|
23
|
+
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, WalletChallenge, WalletLoginParams, AuthResult, 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, } from "./types.js";
|
|
24
|
+
export type { ApiKeyInfo, ApiKeyCreated } from "./resources/api-key.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { ReachClient } from "./client.js";
|
|
2
|
+
export { ReachError } from "./error.js";
|
|
3
|
+
export { ProjectResource } from "./resources/project.js";
|
|
4
|
+
export { BotResource } from "./resources/bot.js";
|
|
5
|
+
export { AgentApi } from "./resources/agent-api.js";
|
|
6
|
+
export { KnowledgeResource } from "./resources/knowledge.js";
|
|
7
|
+
export { ChannelResource } from "./resources/channel.js";
|
|
8
|
+
export { ConversationResource } from "./resources/conversation.js";
|
|
9
|
+
export { DashboardApi } from "./resources/dashboard-api.js";
|
|
10
|
+
export { TransactionResource } from "./resources/transaction.js";
|
|
11
|
+
export { AuthResource } from "./resources/auth.js";
|
|
12
|
+
export { ChatResource } from "./resources/chat.js";
|
|
13
|
+
export { ApiKeyResource } from "./resources/api-key.js";
|
|
14
|
+
export { LightRAGResource } from "./resources/lightrag.js";
|
|
15
|
+
export { AdminResource } from "./resources/admin.js";
|
|
16
|
+
export { OrchestrationResource } from "./resources/orchestration.js";
|
|
17
|
+
export { ScheduledTasksResource } from "./resources/scheduledTasks.js";
|
|
18
|
+
export { InternalAgentResource } from "./resources/internalAgent.js";
|
|
19
|
+
export { AbiResource } from "./resources/abis.js";
|
|
20
|
+
export { ContentResource } from "./resources/content.js";
|
|
21
|
+
export { TtsResource } from "./resources/tts.js";
|
|
22
|
+
export { AccountsResource } from "./resources/accounts.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RequestMethod, MerchantAbi, MerchantAbiCreateParams } from "../types.js";
|
|
2
|
+
type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
|
|
3
|
+
export declare class AbiResource {
|
|
4
|
+
private request;
|
|
5
|
+
constructor(request: RequestFn);
|
|
6
|
+
/** 列出当前商户的所有合约 ABI */
|
|
7
|
+
list(): Promise<{
|
|
8
|
+
abis: MerchantAbi[];
|
|
9
|
+
}>;
|
|
10
|
+
/** 新增合约 ABI(上传后交易 agent 即具备调用该合约函数的能力) */
|
|
11
|
+
add(params: MerchantAbiCreateParams): Promise<{
|
|
12
|
+
success: boolean;
|
|
13
|
+
abi: MerchantAbi;
|
|
14
|
+
}>;
|
|
15
|
+
/** 删除合约 ABI(已存在的 agent 能力声明同步移除) */
|
|
16
|
+
remove(id: string): Promise<{
|
|
17
|
+
success: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class AbiResource {
|
|
2
|
+
constructor(request) {
|
|
3
|
+
this.request = request;
|
|
4
|
+
}
|
|
5
|
+
/** 列出当前商户的所有合约 ABI */
|
|
6
|
+
list() {
|
|
7
|
+
return this.request("GET", "/api/merchant/abis");
|
|
8
|
+
}
|
|
9
|
+
/** 新增合约 ABI(上传后交易 agent 即具备调用该合约函数的能力) */
|
|
10
|
+
add(params) {
|
|
11
|
+
return this.request("POST", "/api/merchant/abis", params);
|
|
12
|
+
}
|
|
13
|
+
/** 删除合约 ABI(已存在的 agent 能力声明同步移除) */
|
|
14
|
+
remove(id) {
|
|
15
|
+
return this.request("DELETE", `/api/merchant/abis/${encodeURIComponent(id)}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RequestMethod } from "../types.js";
|
|
2
|
+
type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
|
|
3
|
+
/**
|
|
4
|
+
* Accounts 资源 — 社媒账号矩阵(源自 aiops-saas @aiops/sdk AccountsApi)。
|
|
5
|
+
* 端点走 Server API(/api/accounts/*)。
|
|
6
|
+
*/
|
|
7
|
+
export declare class AccountsResource {
|
|
8
|
+
private request;
|
|
9
|
+
constructor(request: RequestFn);
|
|
10
|
+
/** 账号列表 */
|
|
11
|
+
list(): Promise<any>;
|
|
12
|
+
/** 连接平台账号(OAuth 凭据) */
|
|
13
|
+
connect(platform: string, credentials: Record<string, unknown>): Promise<any>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accounts 资源 — 社媒账号矩阵(源自 aiops-saas @aiops/sdk AccountsApi)。
|
|
3
|
+
* 端点走 Server API(/api/accounts/*)。
|
|
4
|
+
*/
|
|
5
|
+
export class AccountsResource {
|
|
6
|
+
constructor(request) {
|
|
7
|
+
this.request = request;
|
|
8
|
+
}
|
|
9
|
+
/** 账号列表 */
|
|
10
|
+
list() {
|
|
11
|
+
return this.request("GET", "/api/accounts");
|
|
12
|
+
}
|
|
13
|
+
/** 连接平台账号(OAuth 凭据) */
|
|
14
|
+
connect(platform, credentials) {
|
|
15
|
+
return this.request("POST", `/api/accounts/${platform}/connect`, credentials);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { RequestMethod, AdminDashboard, AdminMerchant, AdminMerchantDetail, AdminBillingRecord, AdminCreateBillingParams, LlmSettings, LlmUpdateParams } from "../types.js";
|
|
2
|
+
type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
|
|
3
|
+
/**
|
|
4
|
+
* Admin resource — 平台管理端点(server 域 /api/admin/*)。
|
|
5
|
+
* 需要 admin JWT Token(`client.setToken(...)` 或构造时传入 `token`)。
|
|
6
|
+
*/
|
|
7
|
+
export declare class AdminResource {
|
|
8
|
+
private request;
|
|
9
|
+
constructor(request: RequestFn);
|
|
10
|
+
/** 获取管理仪表盘统计(商户/项目/Token/对话/营收/月度趋势) */
|
|
11
|
+
getDashboard(): Promise<AdminDashboard>;
|
|
12
|
+
/** 列出所有商户(含套餐/状态/用量) */
|
|
13
|
+
listMerchants(): Promise<AdminMerchant[]>;
|
|
14
|
+
/** 获取商户详情(含其项目列表) */
|
|
15
|
+
getMerchant(id: string): Promise<AdminMerchantDetail>;
|
|
16
|
+
/** 更新商户套餐(如 starter / pro) */
|
|
17
|
+
updateMerchantPlan(id: string, plan: string): Promise<{
|
|
18
|
+
success: boolean;
|
|
19
|
+
merchantId: string;
|
|
20
|
+
plan: string;
|
|
21
|
+
}>;
|
|
22
|
+
/** 获取所有计费记录 */
|
|
23
|
+
listBilling(): Promise<AdminBillingRecord[]>;
|
|
24
|
+
/** 创建计费记录(同时更新对应商户套餐) */
|
|
25
|
+
createBilling(params: AdminCreateBillingParams): Promise<AdminBillingRecord>;
|
|
26
|
+
/** 获取 LLM 设置 */
|
|
27
|
+
getSettings(): Promise<LlmSettings>;
|
|
28
|
+
/** 更新 LLM 设置(api_key 必填) */
|
|
29
|
+
updateSettings(params: LlmUpdateParams): Promise<{
|
|
30
|
+
success: boolean;
|
|
31
|
+
settings: LlmSettings;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin resource — 平台管理端点(server 域 /api/admin/*)。
|
|
3
|
+
* 需要 admin JWT Token(`client.setToken(...)` 或构造时传入 `token`)。
|
|
4
|
+
*/
|
|
5
|
+
export class AdminResource {
|
|
6
|
+
constructor(request) {
|
|
7
|
+
this.request = request;
|
|
8
|
+
}
|
|
9
|
+
/** 获取管理仪表盘统计(商户/项目/Token/对话/营收/月度趋势) */
|
|
10
|
+
getDashboard() {
|
|
11
|
+
return this.request("GET", "/api/admin/dashboard");
|
|
12
|
+
}
|
|
13
|
+
/** 列出所有商户(含套餐/状态/用量) */
|
|
14
|
+
listMerchants() {
|
|
15
|
+
return this.request("GET", "/api/admin/merchants");
|
|
16
|
+
}
|
|
17
|
+
/** 获取商户详情(含其项目列表) */
|
|
18
|
+
getMerchant(id) {
|
|
19
|
+
return this.request("GET", `/api/admin/merchants/${id}`);
|
|
20
|
+
}
|
|
21
|
+
/** 更新商户套餐(如 starter / pro) */
|
|
22
|
+
updateMerchantPlan(id, plan) {
|
|
23
|
+
return this.request("POST", `/api/admin/merchants/${id}/plan`, { plan });
|
|
24
|
+
}
|
|
25
|
+
/** 获取所有计费记录 */
|
|
26
|
+
listBilling() {
|
|
27
|
+
return this.request("GET", "/api/admin/billing");
|
|
28
|
+
}
|
|
29
|
+
/** 创建计费记录(同时更新对应商户套餐) */
|
|
30
|
+
createBilling(params) {
|
|
31
|
+
return this.request("POST", "/api/admin/billing", params);
|
|
32
|
+
}
|
|
33
|
+
/** 获取 LLM 设置 */
|
|
34
|
+
getSettings() {
|
|
35
|
+
return this.request("GET", "/api/admin/settings");
|
|
36
|
+
}
|
|
37
|
+
/** 更新 LLM 设置(api_key 必填) */
|
|
38
|
+
updateSettings(params) {
|
|
39
|
+
return this.request("POST", "/api/admin/settings", params);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { RequestMethod, AgentListParams, AgentListResult, AgentSummary, AgentCapabilities, AgentChatParams, AgentChatResult, TxIntent, PreparedTransaction, AgentXMarketplaceResult, AgentXAgentDetail, AgentXSubscriptionPlans, AgentXSubscriptionCheck, AgentXAgentContext, AgentXPublishParams, AgentXPublishResult, AgentXSkill, AgentXSkillCreateParams, AgentXAgentStatus, AgentXAgentUsage, AgentXSubscriptionList } from "../types.js";
|
|
2
|
+
type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
|
|
3
|
+
/**
|
|
4
|
+
* AgentApi — Reach 唯一 Agent 入口(P2.4.3 统一)。
|
|
5
|
+
*
|
|
6
|
+
* 吸收三侧方法面(A.5.2/A.2.3 AgentX 合版):
|
|
7
|
+
* - S agent(网关 /api/v1/agents/*):list / get / capabilities / chat / prepareTransaction
|
|
8
|
+
* - S agentx(server /api/agentx/* + /api/merchant/*):链上市场 / 订阅 / 状态用量 / 发布 / 技能
|
|
9
|
+
* - A agents(server /api/agents/*):marketplace → listMarketplace、run / clone
|
|
10
|
+
*
|
|
11
|
+
* 端点保持两侧现状(agent 走网关 /api/v1、agentx/agents 走 server),
|
|
12
|
+
* 待 2.4.5 统一网关后全部走网关(A.2.4:SDK 只走网关)。
|
|
13
|
+
* 统一 Agent 资源模型:S「Bot 可发布为 Agent」+ A「平台原生 Agent 市场」,见 A.2.5。
|
|
14
|
+
*/
|
|
15
|
+
export declare class AgentApi {
|
|
16
|
+
private gatewayRequest;
|
|
17
|
+
private serverRequest;
|
|
18
|
+
constructor(gatewayRequest: RequestFn, serverRequest: RequestFn);
|
|
19
|
+
/** 列出调用方可用的 agent(可按 projectId / type 过滤) */
|
|
20
|
+
list(params?: AgentListParams): Promise<AgentListResult>;
|
|
21
|
+
/** 获取单个 agent 详情 */
|
|
22
|
+
get(id: string): Promise<AgentSummary>;
|
|
23
|
+
/** 该 agent 支持什么:类型、可用链、可执行的链上操作类型 */
|
|
24
|
+
capabilities(id: string): Promise<AgentCapabilities>;
|
|
25
|
+
/** 直接与该 agent 对话(RAG + 交易构造由服务端完成,返回 transaction 载荷) */
|
|
26
|
+
chat(id: string, params: AgentChatParams): Promise<AgentChatResult>;
|
|
27
|
+
/** 构造链上交易(不签名;返回步骤/calldata,由调用方 wallet 弹窗确认) */
|
|
28
|
+
prepareTransaction(id: string, intent: TxIntent): Promise<PreparedTransaction>;
|
|
29
|
+
/** 运行一个 agent(A:平台原生 Agent 市场模式) */
|
|
30
|
+
run(id: string, message: string, skillNames?: string[]): Promise<any>;
|
|
31
|
+
/** 克隆 agent 到工作区 */
|
|
32
|
+
clone(id: string): Promise<any>;
|
|
33
|
+
/** 列出 AgentX 链上市场中的 Agent(吸收 A agents.marketplace → /api/agents/marketplace/search) */
|
|
34
|
+
listMarketplace(params?: {
|
|
35
|
+
page?: number;
|
|
36
|
+
pageSize?: number;
|
|
37
|
+
search?: string;
|
|
38
|
+
type?: string;
|
|
39
|
+
}): Promise<AgentXMarketplaceResult>;
|
|
40
|
+
/** 获取 AgentX Agent 详情 */
|
|
41
|
+
getAgent(agentId: number): Promise<AgentXAgentDetail>;
|
|
42
|
+
/** 获取 Agent 的订阅计划 */
|
|
43
|
+
getPlans(agentId: number): Promise<AgentXSubscriptionPlans>;
|
|
44
|
+
/** 检查用户对 Agent 的订阅状态 */
|
|
45
|
+
checkSubscription(agentId: number, subscriberAddress: string): Promise<AgentXSubscriptionCheck>;
|
|
46
|
+
/** 列出用户的所有订阅 */
|
|
47
|
+
listSubscriptions(subscriberAddress: string): Promise<AgentXSubscriptionList>;
|
|
48
|
+
/** 获取 Agent 运行状态(在线/离线/延迟等) */
|
|
49
|
+
getAgentStatus(agentId: number): Promise<AgentXAgentStatus>;
|
|
50
|
+
/** 获取 Agent 用量统计(调用次数、Token 消耗、活跃订阅者) */
|
|
51
|
+
getAgentUsage(agentId: number): Promise<AgentXAgentUsage>;
|
|
52
|
+
/** 加载 Agent 上下文(需要有效订阅) */
|
|
53
|
+
loadAgentContext(agentId: number, subscriberAddress: string): Promise<AgentXAgentContext>;
|
|
54
|
+
/** 将 Bot 发布到 AgentX 市场,返回链上交易参数 */
|
|
55
|
+
publishBot(projectId: string, botId: string, params?: AgentXPublishParams): Promise<AgentXPublishResult>;
|
|
56
|
+
/** 获取 Bot 的 A2A 技能列表 */
|
|
57
|
+
listSkills(projectId: string, botId: string): Promise<AgentXSkill[]>;
|
|
58
|
+
/** 给 Bot 添加 A2A 技能(链接到另一个 AgentX Agent) */
|
|
59
|
+
addSkill(projectId: string, botId: string, params: AgentXSkillCreateParams): Promise<AgentXSkill>;
|
|
60
|
+
}
|
|
61
|
+
export {};
|