@reachv2/sdk 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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),现统一为 **31 个资源类 / 210 个资源方法**。一个客户端覆盖客服 / 销售引导、社群维护与社媒运营全部资源(含效果追踪、SEO/GEO、内容规则与数据源)。
3
+ Reach(reach.codes)统一平台的官方 TypeScript SDK —— 由 aiservicer SDK(crm 域,18 资源)与 aiops-saas SDK(social 域,5 资源)合并而来(P2.4),现统一为 **34 个资源类 / 267 个资源方法**。一个客户端覆盖客服 / 销售引导、社群维护与社媒运营全部资源(含商户入驻与商户控制台、通道/群发、邮件通道、效果追踪、SEO/GEO、内容规则与数据源)。
4
4
 
5
5
  - 运行时:Node.js >= 18(ESM)
6
6
  - 类型:完整 TypeScript 类型定义(自带 `dist/index.d.ts`)
@@ -125,7 +125,7 @@ const client = new ReachClient({
125
125
 
126
126
  | 资源 | 主要能力 | API 域 |
127
127
  |------|----------|--------|
128
- | `client.auth` | 验证码(getCaptcha)、登录、注册、钱包登录(MFA/SSO) | Server |
128
+ | `client.auth` | 验证码(getCaptcha)、登录、注册、钱包登录、邮箱验证码登录、**商户入驻(merchantOnboard)/ 商户邀请**、refresh / logout / me(MFA/SSO) | Server |
129
129
  | `client.admin` | 平台仪表盘、商户、计费、LLM 设置(需管理员 JWT) | Admin |
130
130
  | `client.apiKeys` | API Key 创建/列表/吊销 | Gateway |
131
131
  | `client.dashboard` | **统一看板**(DashboardApi):crm 客服指标 + social 社媒运营看板 | 双域 |
@@ -162,7 +162,7 @@ const client = new ReachClient({
162
162
  |------|----------|--------|
163
163
  | `client.content` | 社媒文案生成(generate/list/platforms/styles/get/update/delete) | Server |
164
164
  | `client.tts` | 文本转语音(synthesize/voices/history) | Server |
165
- | `client.accounts` | 社媒账号矩阵(list/connect) | Server |
165
+ | `client.accounts` | 社媒账号矩阵(list/create) | Server |
166
166
  | `client.contentPlans` | **内容计划(ContentPlansResource)**:计划名 + 主题时间轴(list/create) | Server |
167
167
  | `client.publishPlans` | **发布计划(PublishPlansResource)**:多站点分步编排,get 返回每步待审草稿,approve/reject 完成审批(list/get/approve/reject) | Server |
168
168
  | `client.browserTemplates` | **浏览器操作模板(BrowserTemplatesResource)**:流程编排模板(list/update) | Server |
@@ -172,10 +172,22 @@ const client = new ReachClient({
172
172
 
173
173
  | 资源 | 主要能力 | API 域 |
174
174
  |------|----------|--------|
175
- | `client.effect` | **效果追踪(EffectResource)**:指标字典、日快照、目标、汇总/ROI/归因/周报、告警、GEO 探针问题集(22 方法) | Server |
175
+ | `client.effect` | **效果追踪(EffectResource)**:指标字典、日快照、汇总/ROI/归因/周报、告警、GEO 探针问题集(18 方法) | Server |
176
176
  | `client.seoGeo` | **SEO/GEO 域(SeoGeoResource)**:品牌档案 / 渠道集 / 内容矩阵(草稿→发布→回采)/ GEO 资产(24 方法) | Server |
177
177
  | `client.contentRules` | **内容规则引擎(ContentRulesResource)**:规则 CRUD + 发布前打分/优化 + 发布后效果/GEO 评估 + 记录趋势(12 方法) | Server |
178
- | `client.dataSources` | **数据源适配器(DataSourcesResource)**:明细/趋势/告警/定时同步(12 方法;无创建入口,内置源只读) | Server |
178
+ | `client.dataSources` | **数据源适配器(DataSourcesResource)**:指标明细 / 趋势(2 方法;其余 CRUD/适配器/同步/告警/调度已于 2026-09-19 下线) | Server |
179
+
180
+ ### 商户域 — P0(入驻 / 控制台 / 通道,v0.4.0 新增)
181
+
182
+ | 资源 | 主要能力 | API 域 |
183
+ |------|----------|--------|
184
+ | `client.merchant` | **商户控制台(MerchantResource)**:看板/工单、项目与 Bot、Bot LLM 配置(BYOK)、自定义链、团队与邀请、RBAC 权限/成员/审计(28 方法) | Server |
185
+ | `client.channelAdmin` | **通道管理(ChannelAdminResource)**:通道总览、Telegram / WhatsApp / Discord 连接与发消息、群组管理与群发、项目级异步群发任务(33 方法;不含 multipart `upload-send`) | Server |
186
+ | `client.emailChannel` | **客服邮件通道(EmailChannelResource)**:邮箱账号 CRUD、SMTP 发信、IMAP 拉取、原始邮件投递、邮件线程(10 方法) | Server |
187
+
188
+ > `/api/merchant/*` 全部要求 JWT 带 `role=merchant`:邮箱/钱包注册后需先 `client.auth.merchantOnboard({ name })`
189
+ > 或接受商户邀请(`client.auth.acceptMerchantInvite(token)`),再 `setToken(返回的 accessToken)`。
190
+ > 商户域直接返回 db 行(多为 snake_case),与网关 `/api/v1` 的 camelCase 不同。
179
191
 
180
192
  > crm 客服指标(原 `client.analytics`)与社媒运营看板(原 `client.dashboard`)已统一为 `client.dashboard`(DashboardApi);AgentX(原 `client.agentx`)与社媒 Agent 市场已统一为 `client.agents`(AgentApi)。
181
193
 
@@ -202,7 +214,7 @@ npm test # node --test,覆盖 test/*.test.mjs
202
214
  | 测试文件 | 覆盖 |
203
215
  |----------|------|
204
216
  | `test/client.test.mjs` | ReachClient 核心行为:构造校验(`MISSING_AUTH`)、认证 Header、双 base 路由、body 序列化、错误语义 |
205
- | `test/resources.test.mjs` | **全量** 27 资源类 203 方法的 method / path / body 断言(要求每个方法至少被一条用例覆盖) |
217
+ | `test/resources.test.mjs` | **全量** 34 资源类 267 方法的 method / path / body 断言(要求每个方法至少被一条用例覆盖) |
206
218
  | `test/smoke.test.mjs` | 导出面 + 资源方法面快照 |
207
219
 
208
220
  > 测试跑 **`dist/` 产物**,改完 `src/` 必须先 `npm run build`。
package/dist/client.d.ts CHANGED
@@ -30,6 +30,9 @@ import { DashboardApi } from "./resources/dashboard-api.js";
30
30
  import { HealthResource } from "./resources/health.js";
31
31
  import { TenantsResource } from "./resources/tenants.js";
32
32
  import { TeamResource } from "./resources/team.js";
33
+ import { MerchantResource } from "./resources/merchant.js";
34
+ import { ChannelAdminResource } from "./resources/channel-admin.js";
35
+ import { EmailChannelResource } from "./resources/email-channel.js";
33
36
  export declare class ReachClient {
34
37
  private apiKey?;
35
38
  private token?;
@@ -67,6 +70,9 @@ export declare class ReachClient {
67
70
  tenants: TenantsResource;
68
71
  team: TeamResource;
69
72
  health: HealthResource;
73
+ merchant: MerchantResource;
74
+ channelAdmin: ChannelAdminResource;
75
+ emailChannel: EmailChannelResource;
70
76
  constructor(config: ReachClientConfig);
71
77
  /** Set token after wallet login */
72
78
  setToken(token: string): void;
package/dist/client.js CHANGED
@@ -30,6 +30,9 @@ import { DashboardApi } from "./resources/dashboard-api.js";
30
30
  import { HealthResource } from "./resources/health.js";
31
31
  import { TenantsResource } from "./resources/tenants.js";
32
32
  import { TeamResource } from "./resources/team.js";
33
+ import { MerchantResource } from "./resources/merchant.js";
34
+ import { ChannelAdminResource } from "./resources/channel-admin.js";
35
+ import { EmailChannelResource } from "./resources/email-channel.js";
33
36
  export class ReachClient {
34
37
  constructor(config) {
35
38
  if (!config.apiKey && !config.token) {
@@ -72,6 +75,9 @@ export class ReachClient {
72
75
  this.tenants = new TenantsResource(this.requestServer.bind(this));
73
76
  this.team = new TeamResource(this.requestServer.bind(this));
74
77
  this.health = new HealthResource(this.requestServer.bind(this));
78
+ this.merchant = new MerchantResource(this.requestServer.bind(this));
79
+ this.channelAdmin = new ChannelAdminResource(this.requestServer.bind(this));
80
+ this.emailChannel = new EmailChannelResource(this.requestServer.bind(this));
75
81
  }
76
82
  /** Set token after wallet login */
77
83
  setToken(token) {
@@ -124,6 +130,9 @@ export class ReachClient {
124
130
  `Request failed with status ${response.status}`;
125
131
  throw new ReachError(message, "API_ERROR", response.status, errorBody);
126
132
  }
133
+ // 204 No Content(如 POST /api/auth/logout)没有响应体
134
+ if (response.status === 204)
135
+ return undefined;
127
136
  return response.json();
128
137
  }
129
138
  }
package/dist/index.d.ts CHANGED
@@ -31,5 +31,10 @@ export { DataSourcesResource } from "./resources/data-sources.js";
31
31
  export { HealthResource } from "./resources/health.js";
32
32
  export { TenantsResource } from "./resources/tenants.js";
33
33
  export { TeamResource } from "./resources/team.js";
34
- 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, } from "./types.js";
34
+ export { MerchantResource } from "./resources/merchant.js";
35
+ export { ChannelAdminResource } from "./resources/channel-admin.js";
36
+ export { EmailChannelResource } from "./resources/email-channel.js";
37
+ 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";
35
38
  export type { ApiKeyInfo, ApiKeyCreated } from "./resources/api-key.js";
39
+ export type { SocialAccountCreateParams } from "./resources/accounts.js";
40
+ export type { EmailSendParams, EmailPollParams, EmailInboundParams, } from "./resources/email-channel.js";
package/dist/index.js CHANGED
@@ -31,3 +31,6 @@ export { DataSourcesResource } from "./resources/data-sources.js";
31
31
  export { HealthResource } from "./resources/health.js";
32
32
  export { TenantsResource } from "./resources/tenants.js";
33
33
  export { TeamResource } from "./resources/team.js";
34
+ export { MerchantResource } from "./resources/merchant.js";
35
+ export { ChannelAdminResource } from "./resources/channel-admin.js";
36
+ export { EmailChannelResource } from "./resources/email-channel.js";
@@ -1,5 +1,13 @@
1
1
  import { RequestMethod } from "../types.js";
2
2
  type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
3
+ export interface SocialAccountCreateParams {
4
+ /** twitter / facebook / instagram / xiaohongshu / tiktok / linkedin / email */
5
+ platform: string;
6
+ /** 展示名(服务端必填) */
7
+ name: string;
8
+ credentials?: Record<string, unknown>;
9
+ usageType?: "general" | "nurture" | "execute";
10
+ }
3
11
  /**
4
12
  * Accounts 资源 — 社媒账号矩阵(源自 aiops-saas @aiops/sdk AccountsApi)。
5
13
  * 端点走 Server API(/api/accounts/*)。
@@ -7,9 +15,13 @@ type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Pro
7
15
  export declare class AccountsResource {
8
16
  private request;
9
17
  constructor(request: RequestFn);
10
- /** 账号列表 */
11
- list(): Promise<any>;
12
- /** 连接平台账号(OAuth 凭据) */
13
- connect(platform: string, credentials: Record<string, unknown>): Promise<any>;
18
+ /** 账号列表(?usageType=general|nurture|execute) */
19
+ list(usageType?: "general" | "nurture" | "execute"): Promise<any>;
20
+ /**
21
+ * 新增平台账号(POST /api/accounts;凭据服务端加密入库)。
22
+ * v0.4.0 修复:旧 `connect(platform, credentials)` 指向不存在的
23
+ * `/api/accounts/:platform/connect`,调用必 404。
24
+ */
25
+ create(params: SocialAccountCreateParams): Promise<any>;
14
26
  }
15
27
  export {};
@@ -6,12 +6,17 @@ export class AccountsResource {
6
6
  constructor(request) {
7
7
  this.request = request;
8
8
  }
9
- /** 账号列表 */
10
- list() {
11
- return this.request("GET", "/api/accounts");
9
+ /** 账号列表(?usageType=general|nurture|execute) */
10
+ list(usageType) {
11
+ const qs = usageType ? `?usageType=${encodeURIComponent(usageType)}` : "";
12
+ return this.request("GET", `/api/accounts${qs}`);
12
13
  }
13
- /** 连接平台账号(OAuth 凭据) */
14
- connect(platform, credentials) {
15
- return this.request("POST", `/api/accounts/${platform}/connect`, credentials);
14
+ /**
15
+ * 新增平台账号(POST /api/accounts;凭据服务端加密入库)。
16
+ * v0.4.0 修复:旧 `connect(platform, credentials)` 指向不存在的
17
+ * `/api/accounts/:platform/connect`,调用必 404。
18
+ */
19
+ create(params) {
20
+ return this.request("POST", "/api/accounts", params);
16
21
  }
17
22
  }
@@ -1,16 +1,15 @@
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";
1
+ import { RequestMethod, AgentListParams, AgentListResult, AgentSummary, AgentCapabilities, AgentChatParams, AgentChatResult, TxIntent, PreparedTransaction, AgentXMarketplaceResult } from "../types.js";
2
2
  type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
3
3
  /**
4
4
  * AgentApi — Reach 唯一 Agent 入口(P2.4.3 统一)。
5
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
6
+ * 方法面:
7
+ * - 调用方 Agent(网关 /api/v1/agents/*):list / get / capabilities / chat / prepareTransaction
8
+ * - 运行 / 克隆 + 市场搜索(server /api/agents/*):run / clone / listMarketplace
10
9
  *
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。
10
+ * 说明(v0.4.0):`/api/agentx/*` 与 `/api/merchant/.../publish-agentx|agentx-skills`
11
+ * 在本服务端并未挂载(调用必 404),相关方法已移除;Agent 市场统一走
12
+ * `/api/agents/marketplace/search`。
14
13
  */
15
14
  export declare class AgentApi {
16
15
  private gatewayRequest;
@@ -30,32 +29,13 @@ export declare class AgentApi {
30
29
  run(id: string, message: string, skillNames?: string[]): Promise<any>;
31
30
  /** 克隆 agent 到工作区 */
32
31
  clone(id: string): Promise<any>;
33
- /** 列出 AgentX 链上市场中的 Agent(吸收 A agents.marketplace → /api/agents/marketplace/search) */
32
+ /** 搜索 Agent 市场(keyword / category / 分页 / 排序) */
34
33
  listMarketplace(params?: {
34
+ keyword?: string;
35
+ category?: string;
36
+ sortBy?: string;
35
37
  page?: number;
36
38
  pageSize?: number;
37
- search?: string;
38
- type?: string;
39
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
40
  }
61
41
  export {};
@@ -1,14 +1,13 @@
1
1
  /**
2
2
  * AgentApi — Reach 唯一 Agent 入口(P2.4.3 统一)。
3
3
  *
4
- * 吸收三侧方法面(A.5.2/A.2.3 AgentX 合版):
5
- * - S agent(网关 /api/v1/agents/*):list / get / capabilities / chat / prepareTransaction
6
- * - S agentx(server /api/agentx/* + /api/merchant/*):链上市场 / 订阅 / 状态用量 / 发布 / 技能
7
- * - A agents(server /api/agents/*):marketplace → listMarketplace、run / clone
4
+ * 方法面:
5
+ * - 调用方 Agent(网关 /api/v1/agents/*):list / get / capabilities / chat / prepareTransaction
6
+ * - 运行 / 克隆 + 市场搜索(server /api/agents/*):run / clone / listMarketplace
8
7
  *
9
- * 端点保持两侧现状(agent 走网关 /api/v1、agentx/agents 走 server),
10
- * 待 2.4.5 统一网关后全部走网关(A.2.4:SDK 只走网关)。
11
- * 统一 Agent 资源模型:S「Bot 可发布为 Agent」+ A「平台原生 Agent 市场」,见 A.2.5。
8
+ * 说明(v0.4.0):`/api/agentx/*` 与 `/api/merchant/.../publish-agentx|agentx-skills`
9
+ * 在本服务端并未挂载(调用必 404),相关方法已移除;Agent 市场统一走
10
+ * `/api/agents/marketplace/search`。
12
11
  */
13
12
  export class AgentApi {
14
13
  constructor(gatewayRequest, serverRequest) {
@@ -54,59 +53,21 @@ export class AgentApi {
54
53
  clone(id) {
55
54
  return this.serverRequest("POST", `/api/agents/${id}/clone`, {});
56
55
  }
57
- // ═══ AgentX 链上市场(server /api/agentx/*,S agentx;marketplace 吸收 A agents.marketplace)═══
58
- /** 列出 AgentX 链上市场中的 Agent(吸收 A agents.marketplace → /api/agents/marketplace/search) */
56
+ // ═══ Agent 市场(server /api/agents/marketplace/search)═══
57
+ /** 搜索 Agent 市场(keyword / category / 分页 / 排序) */
59
58
  listMarketplace(params) {
60
59
  const query = new URLSearchParams();
60
+ if (params?.keyword)
61
+ query.set("keyword", params.keyword);
62
+ if (params?.category)
63
+ query.set("category", params.category);
64
+ if (params?.sortBy)
65
+ query.set("sortBy", params.sortBy);
61
66
  if (params?.page)
62
67
  query.set("page", String(params.page));
63
68
  if (params?.pageSize)
64
69
  query.set("pageSize", String(params.pageSize));
65
- if (params?.search)
66
- query.set("search", params.search);
67
- if (params?.type)
68
- query.set("type", params.type);
69
- return this.serverRequest("GET", `/api/agentx/marketplace?${query.toString()}`);
70
- }
71
- /** 获取 AgentX Agent 详情 */
72
- getAgent(agentId) {
73
- return this.serverRequest("GET", `/api/agentx/agents/${agentId}`);
74
- }
75
- /** 获取 Agent 的订阅计划 */
76
- getPlans(agentId) {
77
- return this.serverRequest("GET", `/api/agentx/agents/${agentId}/plans`);
78
- }
79
- /** 检查用户对 Agent 的订阅状态 */
80
- checkSubscription(agentId, subscriberAddress) {
81
- return this.serverRequest("GET", `/api/agentx/subscriptions/check?agentId=${agentId}&subscriberAddress=${encodeURIComponent(subscriberAddress)}`);
82
- }
83
- /** 列出用户的所有订阅 */
84
- listSubscriptions(subscriberAddress) {
85
- return this.serverRequest("GET", `/api/agentx/subscriptions/my?subscriberAddress=${encodeURIComponent(subscriberAddress)}`);
86
- }
87
- /** 获取 Agent 运行状态(在线/离线/延迟等) */
88
- getAgentStatus(agentId) {
89
- return this.serverRequest("GET", `/api/agentx/agents/${agentId}/status`);
90
- }
91
- /** 获取 Agent 用量统计(调用次数、Token 消耗、活跃订阅者) */
92
- getAgentUsage(agentId) {
93
- return this.serverRequest("GET", `/api/agentx/agents/${agentId}/usage`);
94
- }
95
- /** 加载 Agent 上下文(需要有效订阅) */
96
- loadAgentContext(agentId, subscriberAddress) {
97
- return this.serverRequest("POST", `/api/agentx/agents/${agentId}/load-context`, { subscriberAddress });
98
- }
99
- // ═══ AgentX 发布与技能(server /api/merchant/*,S agentx)═══
100
- /** 将 Bot 发布到 AgentX 市场,返回链上交易参数 */
101
- publishBot(projectId, botId, params) {
102
- return this.serverRequest("POST", `/api/merchant/projects/${projectId}/bots/${botId}/publish-agentx`, params || {});
103
- }
104
- /** 获取 Bot 的 A2A 技能列表 */
105
- listSkills(projectId, botId) {
106
- return this.serverRequest("GET", `/api/merchant/projects/${projectId}/bots/${botId}/agentx-skills`);
107
- }
108
- /** 给 Bot 添加 A2A 技能(链接到另一个 AgentX Agent) */
109
- addSkill(projectId, botId, params) {
110
- return this.serverRequest("POST", `/api/merchant/projects/${projectId}/bots/${botId}/agentx-skills`, params);
70
+ const qs = query.toString();
71
+ return this.serverRequest("GET", `/api/agents/marketplace/search${qs ? `?${qs}` : ""}`);
111
72
  }
112
73
  }
@@ -1,4 +1,4 @@
1
- import { RequestMethod, WalletNonce, WalletLoginParams, AuthResult, CaptchaResponse, CaptchaAnswer } from "../types.js";
1
+ import { RequestMethod, WalletNonce, WalletLoginParams, AuthResult, CaptchaResponse, CaptchaAnswer, MerchantAuthResult, MerchantInviteInfo, EmailCodeSendResult, EmailCodeLoginParams, AccountMeResult } from "../types.js";
2
2
  type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
3
3
  export declare class AuthResource {
4
4
  private request;
@@ -24,5 +24,29 @@ export declare class AuthResource {
24
24
  email?: string;
25
25
  captcha?: CaptchaAnswer;
26
26
  }): Promise<AuthResult>;
27
+ /**
28
+ * 个人账户升级为商户(owner):创建商户并重签带 merchant claims 的 token。
29
+ * 已绑定商户时幂等(直接续签)。**必须携带 access token**(端点在 requireAuth 之后)。
30
+ */
31
+ merchantOnboard(params: {
32
+ name: string;
33
+ }): Promise<MerchantAuthResult>;
34
+ /** 公开查询商户邀请(登录前即可展示商户名 / 角色 / 受邀邮箱) */
35
+ getMerchantInvite(token: string): Promise<MerchantInviteInfo>;
36
+ /** 登录后接受商户邀请(**必须携带 access token**),返回重签后的 token */
37
+ acceptMerchantInvite(token: string): Promise<MerchantAuthResult>;
38
+ /** 发送邮箱验证码(登录/注册共用;10 分钟有效,60s 冷却) */
39
+ sendEmailCode(email: string): Promise<EmailCodeSendResult>;
40
+ /**
41
+ * 验证码登录(验证码即凭证,新邮箱自动建档)。
42
+ * 启用 MFA 的账户首次调用返回 `{ mfaRequired: true }`,需带 mfaCode 重提(验证码不会被消费)。
43
+ */
44
+ emailCodeLogin(params: EmailCodeLoginParams): Promise<AuthResult>;
45
+ /** 轮换刷新令牌(一次性,旧 token 作废) */
46
+ refresh(refreshToken: string): Promise<AuthResult>;
47
+ /** 撤销刷新令牌(服务端 204) */
48
+ logout(refreshToken?: string): Promise<void>;
49
+ /** 当前账户 + 租户成员关系(需 access token) */
50
+ me(): Promise<AccountMeResult>;
27
51
  }
28
52
  export {};
@@ -40,4 +40,45 @@ export class AuthResource {
40
40
  captchaAnswer: opts?.captcha?.answer,
41
41
  });
42
42
  }
43
+ // ═══ 商户入驻 / 邀请 ═══
44
+ /**
45
+ * 个人账户升级为商户(owner):创建商户并重签带 merchant claims 的 token。
46
+ * 已绑定商户时幂等(直接续签)。**必须携带 access token**(端点在 requireAuth 之后)。
47
+ */
48
+ merchantOnboard(params) {
49
+ return this.request("POST", "/api/auth/merchant-onboard", params);
50
+ }
51
+ /** 公开查询商户邀请(登录前即可展示商户名 / 角色 / 受邀邮箱) */
52
+ getMerchantInvite(token) {
53
+ return this.request("GET", `/api/auth/merchant-invites/${encodeURIComponent(token)}`);
54
+ }
55
+ /** 登录后接受商户邀请(**必须携带 access token**),返回重签后的 token */
56
+ acceptMerchantInvite(token) {
57
+ return this.request("POST", `/api/auth/merchant-invites/${encodeURIComponent(token)}/accept`);
58
+ }
59
+ // ═══ 邮箱验证码登录 ═══
60
+ /** 发送邮箱验证码(登录/注册共用;10 分钟有效,60s 冷却) */
61
+ sendEmailCode(email) {
62
+ return this.request("POST", "/api/auth/email-code/send", { email });
63
+ }
64
+ /**
65
+ * 验证码登录(验证码即凭证,新邮箱自动建档)。
66
+ * 启用 MFA 的账户首次调用返回 `{ mfaRequired: true }`,需带 mfaCode 重提(验证码不会被消费)。
67
+ */
68
+ emailCodeLogin(params) {
69
+ return this.request("POST", "/api/auth/email-code/login", params);
70
+ }
71
+ // ═══ 会话 ═══
72
+ /** 轮换刷新令牌(一次性,旧 token 作废) */
73
+ refresh(refreshToken) {
74
+ return this.request("POST", "/api/auth/refresh", { refreshToken });
75
+ }
76
+ /** 撤销刷新令牌(服务端 204) */
77
+ logout(refreshToken) {
78
+ return this.request("POST", "/api/auth/logout", { refreshToken });
79
+ }
80
+ /** 当前账户 + 租户成员关系(需 access token) */
81
+ me() {
82
+ return this.request("GET", "/api/auth/me");
83
+ }
43
84
  }
@@ -0,0 +1,94 @@
1
+ import { RequestMethod, ChannelActionResult, SendTextParams, TelegramSendFileParams, DiscordDmParams, DiscordDmOptInParams, MerchantGroupList } from "../types.js";
2
+ type RequestFn = <T>(method: RequestMethod, path: string, body?: unknown) => Promise<T>;
3
+ type GroupMemberOp = {
4
+ userId: string;
5
+ } & Record<string, unknown>;
6
+ type PinOp = {
7
+ messageId: string | number;
8
+ } & Record<string, unknown>;
9
+ type BroadcastParams = {
10
+ chatIds?: string[];
11
+ text?: string;
12
+ imageUrl?: string;
13
+ [key: string]: unknown;
14
+ };
15
+ /**
16
+ * ChannelAdminResource — 商户侧通道管理(客服工作台 / 群运营)。
17
+ *
18
+ * 端点:Server API `/api/merchant/projects/:id/bots/:botId/channels/*` 与 `.../groups/*`,
19
+ * 全部要求 `role=merchant` 的 JWT(见 v0.4.0 商户入驻说明)。
20
+ *
21
+ * 不含 Telegram `upload-send`(multipart/form-data 文件直传),该端点请直接用 fetch。
22
+ */
23
+ export declare class ChannelAdminResource {
24
+ private request;
25
+ constructor(request: RequestFn);
26
+ private botBase;
27
+ /** 该 Bot 的通道配置(telegram / whatsapp / web;botToken 已脱敏) */
28
+ listChannels(projectId: string, botId: string): Promise<Record<string, unknown>>;
29
+ /** 配置 Telegram Bot Token(立即启动 Bot 并回写状态) */
30
+ connectTelegram(projectId: string, botId: string, botToken: string): Promise<ChannelActionResult>;
31
+ /** 断开 Telegram(删除配置) */
32
+ disconnectTelegram(projectId: string, botId: string): Promise<ChannelActionResult>;
33
+ /** Telegram 已入群列表 */
34
+ listTelegramGroups(projectId: string, botId: string): Promise<MerchantGroupList>;
35
+ /** 重新扫描 Telegram 群组 */
36
+ rescanTelegramGroups(projectId: string, botId: string): Promise<ChannelActionResult>;
37
+ /** Telegram 发送文本(群/私聊 chatId) */
38
+ sendTelegramText(projectId: string, botId: string, params: SendTextParams): Promise<ChannelActionResult>;
39
+ /** Telegram 发送该 Bot 已上传的文档 */
40
+ sendTelegramFile(projectId: string, botId: string, params: TelegramSendFileParams): Promise<ChannelActionResult>;
41
+ /** 发起 WhatsApp 配对(返回 status / qr;进度轮询 whatsappStatus) */
42
+ pairWhatsApp(projectId: string, botId: string): Promise<ChannelActionResult>;
43
+ /** WhatsApp 配对状态(QR / 手机号 / 连接状态) */
44
+ whatsappStatus(projectId: string, botId: string): Promise<ChannelActionResult>;
45
+ /** 断开 WhatsApp(已配对凭证保留,重新配对可恢复) */
46
+ disconnectWhatsApp(projectId: string, botId: string): Promise<ChannelActionResult>;
47
+ /** WhatsApp 群列表 */
48
+ listWhatsAppGroups(projectId: string, botId: string): Promise<MerchantGroupList>;
49
+ /** WhatsApp 发送文本(群/私聊 jid) */
50
+ sendWhatsAppText(projectId: string, botId: string, params: SendTextParams): Promise<ChannelActionResult>;
51
+ /** 配置 Discord Bot Token */
52
+ connectDiscord(projectId: string, botId: string, botToken: string): Promise<ChannelActionResult>;
53
+ /** 断开 Discord */
54
+ disconnectDiscord(projectId: string, botId: string): Promise<ChannelActionResult>;
55
+ /** Discord 频道(群)列表 */
56
+ listDiscordGroups(projectId: string, botId: string): Promise<MerchantGroupList>;
57
+ /** Discord 发送文本(频道 chatId) */
58
+ sendDiscordText(projectId: string, botId: string, params: SendTextParams): Promise<ChannelActionResult>;
59
+ /** 读取 Discord DM opt-in 状态 */
60
+ getDiscordDmOptIn(projectId: string, botId: string, userId: string): Promise<ChannelActionResult>;
61
+ /** 写入 / 撤回 Discord DM opt-in */
62
+ setDiscordDmOptIn(projectId: string, botId: string, params: DiscordDmOptInParams): Promise<ChannelActionResult>;
63
+ /** Discord DM 资格(opt-in / 历史入站 / 同 guild) */
64
+ getDiscordDmEligibility(projectId: string, botId: string, userId: string): Promise<ChannelActionResult>;
65
+ /** 发送 Discord 1v1 私信(默认强制 opt-in 校验) */
66
+ sendDiscordDm(projectId: string, botId: string, params: DiscordDmParams): Promise<ChannelActionResult>;
67
+ /** 群列表(可按 platform 过滤) */
68
+ listGroups(projectId: string, botId: string, platform?: string): Promise<MerchantGroupList>;
69
+ /** 群成员 */
70
+ groupMembers(projectId: string, botId: string, groupId: string): Promise<Record<string, unknown>>;
71
+ /** 更新群配置 */
72
+ updateGroupConfig(projectId: string, botId: string, groupId: string, patch: Record<string, unknown>): Promise<Record<string, unknown>>;
73
+ /** 群成员操作(ban / unban / kick / mute / unmute) */
74
+ groupMemberOp(projectId: string, botId: string, groupId: string, op: "ban" | "unban" | "kick" | "mute" | "unmute", params: GroupMemberOp): Promise<Record<string, unknown>>;
75
+ /** 置顶 / 取消置顶消息 */
76
+ pinMessage(projectId: string, botId: string, groupId: string, params: PinOp, pinned?: boolean): Promise<Record<string, unknown>>;
77
+ /** Bot 级群发(同一 Bot 的多个 chatId) */
78
+ broadcast(projectId: string, botId: string, params: BroadcastParams): Promise<Record<string, unknown>>;
79
+ /** 项目内全部群(跨 Bot 视图) */
80
+ listProjectGroups(projectId: string): Promise<Record<string, unknown>>;
81
+ /** 项目级群发(创建异步任务) */
82
+ broadcastProject(projectId: string, params: BroadcastParams): Promise<Record<string, unknown>>;
83
+ /** 群发任务列表 */
84
+ listBroadcastJobs(projectId: string): Promise<Record<string, unknown>>;
85
+ /** 群发任务详情 */
86
+ getBroadcastJob(projectId: string, jobId: string): Promise<Record<string, unknown>>;
87
+ /** 群发任务目标与逐群结果 */
88
+ getBroadcastJobTargets(projectId: string, jobId: string): Promise<Record<string, unknown>>;
89
+ /** 取消群发任务 */
90
+ cancelBroadcastJob(projectId: string, jobId: string): Promise<Record<string, unknown>>;
91
+ /** 重试群发任务(仅失败目标) */
92
+ retryBroadcastJob(projectId: string, jobId: string): Promise<Record<string, unknown>>;
93
+ }
94
+ export {};