@reachv2/sdk 0.3.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md 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),现统一为 **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
 
@@ -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 社媒运营看板 | 双域 |
@@ -143,7 +143,7 @@ const client = new ReachClient({
143
143
 
144
144
  | 资源 | 主要能力 | API 域 |
145
145
  |------|----------|--------|
146
- | `client.agents` | **统一 Agent 入口**(AgentApi):调用方 agent(list/get/capabilities/chat/prepareTransaction)+ AgentX 链上市场/订阅/状态/用量/发布/技能 + 市场 run/clone | 双域 |
146
+ | `client.agents` | **统一 Agent 入口**(AgentApi):调用方 agent(list/get/capabilities/chat/prepareTransaction)+ 市场搜索(listMarketplace → `/api/agents/marketplace/search`)+ 市场 run/clone | 双域 |
147
147
  | `client.project` | 项目 CRUD、列表 | Gateway |
148
148
  | `client.bot` | Bot(客服/销售/交易/自定义)CRUD、启停、统计 | Gateway |
149
149
  | `client.knowledge` | 知识文档 CRUD、推荐 | Gateway |
@@ -151,7 +151,7 @@ const client = new ReachClient({
151
151
  | `client.conversation` | 对话记录与消息 | Gateway |
152
152
  | `client.transaction` | 交易意图解析/构造/模拟、协议/合约/calldata 查询 | Gateway |
153
153
  | `client.chat` | 服务端对话(含 function calling tools、A2A 编排) | Server |
154
- | `client.lightrag` | RAG Key 管理 + 文档 CRUD + 查询(per-user namespace) | Gateway |
154
+ | `client.lightrag` | RAG Key 管理 + 文档 CRUD + 查询(per-user namespace;平台共享 namespace `market` / `onchain` 只读可查) | Gateway |
155
155
  | `client.scheduledTasks` | 主 agent 定时任务管理 | Server |
156
156
  | `client.internal` | 企业内 Agent:企业级共享知识库 + 监控连接器/事件(`internal` bot) | Server |
157
157
  | `client.abis` | 商户租户合约 ABI 管理:list/add/remove(交易 agent 上传 ABI 后即可按函数构造链上调用) | Server |
@@ -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,16 +172,41 @@ 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 不同。
191
+
192
+ ### 计费 / 配额 — P1(v0.5.0 新增)
193
+
194
+ | 资源 | 主要能力 | API 域 |
195
+ |------|----------|--------|
196
+ | `client.billing` | **社媒域计费(BillingResource)**:套餐 / Token 包 / 价格(公开)、Token 包购买(Stripe Checkout,未配置时落 pending)、Customer Portal、浏览器实例配额与购买流水(7 方法) | Server |
197
+ | `client.sharedBilling` | **统一计费(SharedBillingResource)**:订阅列表 / 当前订阅与本月用量、用量记账、Token 包购买(支持推广余额抵扣)、加密收款(通道 / 下单 / 列表 / 详情 / 取消 / 确认)(12 方法) | Server |
198
+ | `client.quota` | **社媒域本月配额(QuotaResource)**:`copywriting` / `tts` / `video` / `poster` 的 limit / used / remaining / allowed(1 方法) | Server |
199
+
200
+ > 两个计费资源路径不同:`client.billing` → `/api/billing/*`(社媒域),`client.sharedBilling` → `/api/shared/billing/*`(统一账本)。
201
+ > 订阅 / 用量 / 加密收款需 **账户 JWT + 租户成员**,`tenantId` 显式传参;`plans` / `token-packs` / `prices` / `crypto/methods` 公开。
202
+ > 已退役端点未封装:`POST /api/billing/checkout` 与 `POST /api/shared/billing/subscriptions` 恒 410(新购走 `/api/seats`);
203
+ > `webhook` / `payments-events` 为服务端验签回调,不属于 SDK 调用面。
179
204
 
180
205
  > crm 客服指标(原 `client.analytics`)与社媒运营看板(原 `client.dashboard`)已统一为 `client.dashboard`(DashboardApi);AgentX(原 `client.agentx`)与社媒 Agent 市场已统一为 `client.agents`(AgentApi)。
181
206
 
182
207
  ## 统一入口说明
183
208
 
184
- - **AgentApi(`client.agents`)**:唯一 Agent 入口(P2.4.3)。吸收 S agent(网关 `/api/v1/agents/*`:list/get/capabilities/chat/prepareTransaction)、S agentx(server `/api/agentx/*` + `/api/merchant/*`:市场/计划/订阅/状态/用量/上下文/发布/技能)与 A agents(server `/api/agents/*`:run/clone,marketplace→listMarketplace)。统一 Agent 资源模型见 REACH_MERGE_PLAN A.2.3/A.2.5。
209
+ - **AgentApi(`client.agents`)**:唯一 Agent 入口(P2.4.3)。吸收 S agent(网关 `/api/v1/agents/*`:list/get/capabilities/chat/prepareTransaction)、市场(server `/api/agents/marketplace/search`:listMarketplace)与 A agents(server `/api/agents/*`:run/clone)。`/api/agentx/*` 服务端未挂载,相关方法已于 v0.4.0 移除。统一 Agent 资源模型见 REACH_MERGE_PLAN A.2.3/A.2.5。
185
210
  - **DashboardApi(`client.dashboard`)**:唯一看板入口(P2.4.4)。crm 域(`global` / `dashboard(projectId)` / `botMetrics` / `summaryByUser`)+ social 域(`overview` / `quota` / `trend`)。
186
211
 
187
212
  ## Function Calling(工具回调)
@@ -202,7 +227,7 @@ npm test # node --test,覆盖 test/*.test.mjs
202
227
  | 测试文件 | 覆盖 |
203
228
  |----------|------|
204
229
  | `test/client.test.mjs` | ReachClient 核心行为:构造校验(`MISSING_AUTH`)、认证 Header、双 base 路由、body 序列化、错误语义 |
205
- | `test/resources.test.mjs` | **全量** 27 资源类 203 方法的 method / path / body 断言(要求每个方法至少被一条用例覆盖) |
230
+ | `test/resources.test.mjs` | **全量** 37 资源类 287 方法的 method / path / body 断言(要求每个方法至少被一条用例覆盖) |
206
231
  | `test/smoke.test.mjs` | 导出面 + 资源方法面快照 |
207
232
 
208
233
  > 测试跑 **`dist/` 产物**,改完 `src/` 必须先 `npm run build`。
package/dist/client.d.ts CHANGED
@@ -30,6 +30,12 @@ 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";
36
+ import { BillingResource } from "./resources/billing.js";
37
+ import { SharedBillingResource } from "./resources/shared-billing.js";
38
+ import { QuotaResource } from "./resources/quota.js";
33
39
  export declare class ReachClient {
34
40
  private apiKey?;
35
41
  private token?;
@@ -67,6 +73,12 @@ export declare class ReachClient {
67
73
  tenants: TenantsResource;
68
74
  team: TeamResource;
69
75
  health: HealthResource;
76
+ merchant: MerchantResource;
77
+ channelAdmin: ChannelAdminResource;
78
+ emailChannel: EmailChannelResource;
79
+ billing: BillingResource;
80
+ sharedBilling: SharedBillingResource;
81
+ quota: QuotaResource;
70
82
  constructor(config: ReachClientConfig);
71
83
  /** Set token after wallet login */
72
84
  setToken(token: string): void;
package/dist/client.js CHANGED
@@ -30,6 +30,12 @@ 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";
36
+ import { BillingResource } from "./resources/billing.js";
37
+ import { SharedBillingResource } from "./resources/shared-billing.js";
38
+ import { QuotaResource } from "./resources/quota.js";
33
39
  export class ReachClient {
34
40
  constructor(config) {
35
41
  if (!config.apiKey && !config.token) {
@@ -72,6 +78,12 @@ export class ReachClient {
72
78
  this.tenants = new TenantsResource(this.requestServer.bind(this));
73
79
  this.team = new TeamResource(this.requestServer.bind(this));
74
80
  this.health = new HealthResource(this.requestServer.bind(this));
81
+ this.merchant = new MerchantResource(this.requestServer.bind(this));
82
+ this.channelAdmin = new ChannelAdminResource(this.requestServer.bind(this));
83
+ this.emailChannel = new EmailChannelResource(this.requestServer.bind(this));
84
+ this.billing = new BillingResource(this.requestServer.bind(this));
85
+ this.sharedBilling = new SharedBillingResource(this.requestServer.bind(this));
86
+ this.quota = new QuotaResource(this.requestServer.bind(this));
75
87
  }
76
88
  /** Set token after wallet login */
77
89
  setToken(token) {
@@ -124,6 +136,9 @@ export class ReachClient {
124
136
  `Request failed with status ${response.status}`;
125
137
  throw new ReachError(message, "API_ERROR", response.status, errorBody);
126
138
  }
139
+ // 204 No Content(如 POST /api/auth/logout)没有响应体
140
+ if (response.status === 204)
141
+ return undefined;
127
142
  return response.json();
128
143
  }
129
144
  }
package/dist/index.d.ts CHANGED
@@ -31,5 +31,16 @@ 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 { BillingResource } from "./resources/billing.js";
38
+ export { SharedBillingResource } from "./resources/shared-billing.js";
39
+ export { QuotaResource } from "./resources/quota.js";
40
+ export type { ReachClientConfig, BotType, AgentType, BotStatus, ChannelType, ChannelStatus, KnowledgeStatus, Pagination, PaginatedResponse, Project, ProjectCreateParams, ProjectUpdateParams, TransactionBotConfig, Bot, BotStats, BotCreateParams, BotUpdateParams, KnowledgeDoc, KnowledgeRecommendation, Channel, ChannelConfigureParams, Conversation, Message, ChatParams, ChatResponse, ChatToolDefinition, ChatToolFunction, DashboardData, BotMetrics, TxIntent, TxStep, PreparedTransaction, ContractInfo, ContractMethod, SimulationResult, DecodedCalldata, ProtocolSummary, ProtocolRegistryEntry, ChainDeployment, ProtocolAction, ParamHint, WalletNonce, WalletLoginParams, AuthAccount, AuthResult, MfaRequiredResult, CaptchaResponse, CaptchaAnswer, AgentXAgent, AgentXAgentDetail, AgentXMarketplaceResult, AgentXSubscriptionPlans, AgentXSubscriptionCheck, AgentXAgentContext, AgentXPublishParams, AgentXPublishResult, AgentXSkill, AgentXSkillCreateParams, AgentXAgentStatus, AgentXAgentUsage, AgentXSubscriptionDetail, AgentXSubscriptionList, ServerChatParams, ServerChatResponse, ChatUsage, ChatUsageSummary, AgentSummary, AgentListResult, AgentListParams, AgentChainInfo, AgentActionType, AgentCapabilities, AgentChatParams, AgentChatResult, LightRAGKeyInfo, LightRAGDocumentParams, LightRAGQueryParams, LightRAGQueryResult, LightRAGBatchItem, LightRAGBatchError, LightRAGBatchResult, GlobalAnalytics, AdminDashboard, AdminMerchant, AdminMerchantDetail, AdminBillingRecord, AdminCreateBillingParams, LlmSettings, LlmUpdateParams, ConversationTask, ConversationTaskStatus, ConversationSession, ConversationCapabilities, ConversationMessage, OrchestrationTaskParams, OrchestrateParams, OrchestratedTaskResult, OrchestrateResult, ScheduledTask, ScheduledTaskStatus, ScheduledTaskTriggerType, MonitorConnectorKind, EnterpriseDoc, MonitorConnector, MonitorEvent, MerchantAbi, MerchantAbiCreateParams, SimpleResult, TenantType, TenantMemberRole, TenantMemberStatus, Tenant, TenantMemberInfo, TenantInvite, PublicInviteInfo, InviteAcceptResult, MemberRoleUpdateResult, TransferOwnerResult, TeamMemberItem, TeamInviteResult, HealthInfo, MerchantOnboardParams, MerchantAuthResult, MerchantInviteInfo, EmailCodeSendResult, EmailCodeLoginParams, AccountMeResult, MerchantDashboardStats, MerchantTicket, MerchantTicketUpdateParams, MerchantProject, MerchantBot, MerchantProjectCreateParams, MerchantBotCreateParams, MerchantLlmConfig, MerchantLlmConfigInput, MerchantChain, MerchantChainAddParams, MerchantChainList, MerchantTeamRole, MerchantTeamMember, MerchantTeamResult, MerchantTeamMemberAddParams, MerchantTeamInviteParams, MerchantTeamInviteResult, ChannelActionResult, SendTextParams, TelegramSendFileParams, DiscordDmParams, DiscordDmOptInParams, MerchantGroupList, EmailMailbox, EmailMailboxCreateParams, EmailThreadList, } from "./types.js";
35
41
  export type { ApiKeyInfo, ApiKeyCreated } from "./resources/api-key.js";
42
+ export type { SocialAccountCreateParams } from "./resources/accounts.js";
43
+ export type { EmailSendParams, EmailPollParams, EmailInboundParams, } from "./resources/email-channel.js";
44
+ export type { BillingPlan, BillingPlansResult, BillingTokenPack, BillingTokenPacksResult, BillingPrice, BillingPricesResult, TokenPackCheckoutResult, BrowserQuotaStatus, BrowserPackPurchase, BrowserPackPurchasesResult, } from "./resources/billing.js";
45
+ export type { SharedSubscriptionPlanRef, SharedSubscription, SubscriptionQuotaResource, SubscriptionUsage, RecordUsageParams, UsageRecordResult, SharedTokenPackPurchaseParams, SharedTokenPackPurchaseResult, CryptoMethodsResult, CryptoOrderParams, CryptoOrder, CryptoOrderListResult, CryptoOrderConfirmParams, } from "./resources/shared-billing.js";
46
+ export type { QuotaEntry, QuotaResourceKey, QuotaSummaryResult, } from "./resources/quota.js";
package/dist/index.js CHANGED
@@ -31,3 +31,9 @@ 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";
37
+ export { BillingResource } from "./resources/billing.js";
38
+ export { SharedBillingResource } from "./resources/shared-billing.js";
39
+ export { QuotaResource } from "./resources/quota.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
  }