文档Cloud SDK 参考

BEEOS CLOUD / DEVELOPER REFERENCE

设备绑定

智能体绑定会话与 portal 绑定会话。

概览

device bindings domain 涵盖把智能体与用户连接起来的绑定会话:agent 绑定会话,以及由 portal 创建、读取、撤销和解析的 portal 绑定会话。

6 个操作 · SDK 资源:TypeScript cloud.deviceBindings · Python cloud.device_bindings · Go cloud.DeviceBindings · API 总览

主要对象

agentBindDetailsWire

字段类型必填说明
bind_idstring是绑定会话的 ID。
hostnamestring是设备上报的主机名。
fingerprint_shortstring是设备密钥指纹的前 16 个字符。展示给用户,与设备上的比对。
harnessstring是设备所运行的 harness,与设备上报的一致。
os_typestring否设备上报的操作系统。未上报时省略。
expires_atinteger是会话过期的时间,Unix 秒。
statusstring是绑定会话的状态。已过期的会话会被删除,因此对已过期会话的查询会失败,返回 404 not_found。 可选值: "pending" — 由设备创建,等待用户确认; "confirming" — 用户已确认,正在为该设备创建实例; "bound" — 已确认:实例存在,设备可以连接它. (枚举表)
server_timeinteger是当前服务器时间,Unix 秒。与 expires_at 比较,可以在没有时钟偏差的情况下得到剩余时间。

完整字段和使用该对象的方法见附录。

agentBindWire

字段类型必填说明
statusstring是绑定会话的状态。确认成功后为 bound;仍在等待确认的会话报告 pending。 可选值: "pending" — 由设备创建,等待用户确认。正在确认的会话也报告 pending; "bound" — 已确认:实例存在,设备可以连接它. (枚举表)
bind_idstring否绑定会话的 ID。
instance_idstring否为设备创建的实例的 ID。会话绑定后出现。
public_keystring否设备为该会话注册的公钥。
hostnamestring否设备上报的主机名。
expires_atinteger否会话过期的时间,Unix 秒。
runtime_bindingbindRuntimeWire否已绑定的自托管智能体所连接的地址。会话绑定后出现。 可为 null。

完整字段和使用该对象的方法见附录。

portalBindWire

字段类型必填说明
provider_idstring否承载该实例的提供方的 ID。为设备创建了新实例时设置。
bind_idstring是绑定会话的 ID。以 portal_ 开头。
short_codestring是用户可以在设备上输入的短码,用于代替扫描二维码。使用大写字母和数字,不含易混淆的字符。
statusstring是portal 绑定会话的状态。已过期的会话会被删除,因此对已过期会话的查询会失败,返回 404 not_found。 取值见下表 portalBindWire.status 取值。
instance_idstring否绑定到设备的实例的 ID。会话绑定后出现。
expires_atinteger是会话过期的时间,Unix 秒。会话有效期为 10 分钟。
namestring是为设备创建的实例的显示名称。默认为 BeeRunner。
qr_payloadstring否要编码进设备所扫描二维码的链接。仅在创建会话时返回。
api_base_urlstring否设备所连接的 API 的基础 URL。仅在创建会话时返回。
relay_urlstring否设备通过其连接的中继的 URL。仅在创建会话时返回。
desired_statusstring否所创建实例被驱动到的生命周期阶段:running。为设备创建了新实例时设置。
connectivitystring否所创建实例的可达性:unknown、online 或 offline。为设备创建了新实例时设置。
resource_versioninteger否所创建实例的资源版本。为设备创建了新实例时设置。

portalBindWire.status 取值

取值含义
"pending"已创建,等待设备扫描二维码或输入短码。
"awaiting_confirmation"设备已认领该会话。请带 decision 调用 resolve 操作以继续。
"confirming"决定 create 已被接受,正在为设备创建新实例。
"bound"设备已绑定到一个实例,由 instance_id 给出。
"revoked"已用撤销操作撤销。已撤销的会话不能再被认领或处理。

完整字段和使用该对象的方法见附录。

Binding

字段类型必填说明
client_typestring是token 如何绑定到客户端。 可选值: "web" — 绑定到网页来源,在 origin 中返回; "native" — 绑定到设备密钥,其指纹在 cnf_jkt 中返回. (枚举表) 按 client_type 区分的结构:见变体表。
originstring否token 所绑定的来源。client_type 为 web 时返回。 约束: format=uri.
cnf_jktstring否token 所绑定的设备密钥的指纹。client_type 为 native 时返回。

完整字段和使用该对象的方法见附录。

典型流程

  1. 对 agent 绑定会话,先用 deviceBindings.getDetails 读取详情,再用 deviceBindings.confirm 确认。
  2. 对 portal,用 deviceBindings.createPortal 创建绑定会话,用 deviceBindings.getPortal 读取。
  3. 用 deviceBindings.resolvePortal(decision 为 recover 或 create)或 deviceBindings.revokePortal 结束。

方法

方法HTTP摘要
deviceBindings.confirmPOST /v1/agent/bind/{id}/confirm确认一个 agent 绑定会话
deviceBindings.getDetailsGET /v1/agent/bind/{id}/details获取 agent 绑定会话的详情
deviceBindings.createPortalPOST /v1/agent/portal/bind-sessions创建 portal 绑定会话
deviceBindings.getPortalGET /v1/agent/portal/bind-sessions/{id}获取 portal 绑定会话
deviceBindings.resolvePortalPOST /v1/agent/portal/bind-sessions/{id}/resolve解析 portal 绑定会话
deviceBindings.revokePortalPOST /v1/agent/portal/bind-sessions/{id}/revoke撤销 portal 绑定会话

deviceBindings.confirm

POST /v1/agent/bind/{id}/confirm · Operation ID confirmAgentBind

确认一个 agent 绑定会话

SDK 方法

语言方法签名
TypeScriptcloud.deviceBindings.confirmconfirm(id: string, input: Models.ConfirmAgentBindRequest): Promise<Models.ConfirmAgentBindResponse>
Pythoncloud.device_bindings.confirmdef confirm(self, id: str, input: ConfirmAgentBindRequest) -> ConfirmAgentBindResponse
Gocloud.DeviceBindings.Confirmfunc (r *DeviceBindingsResource) Confirm(ctx context.Context, id string, input ConfirmAgentBindRequest) (ConfirmAgentBindResponse, error)

参数

参数位置类型必填说明
idpathstring是要确认的智能体绑定会话的 ID,即设备创建它时返回的 bind_id。

请求体

application/json · 必填

字段类型必填说明
namestring否为设备创建的实例的显示名称,最多 128 个字符。默认为设备上报的主机名。
modelPrimarystring否可以提交,但会被忽略。实例沿用服务器的默认模型。
model_primarystring否modelPrimary 的 snake-case 别名,同样会被忽略。如果两者都发送,必须相等。

响应

200 · application/json

字段类型必填说明
successboolean是—
dataagentBindWire是—

错误

状态码Schema说明
其他(default)DeviceBindingErrorResponseCloud Server 错误

错误 schema 见错误。

示例

import { BeeOSClient } from "@beeos-ai/cloud-sdk";

const cloud = new BeeOSClient({
  baseURL: "https://api.cloud.beeos.ai/v1",
  apiKey: "YOUR_API_KEY", // bsk_ key: backend only
});
const result = await cloud.deviceBindings.confirm("id_123", {});
console.log(result);

deviceBindings.getDetails

GET /v1/agent/bind/{id}/details · Operation ID getAgentBindDetails

获取 agent 绑定会话的详情

SDK 方法

语言方法签名
TypeScriptcloud.deviceBindings.getDetailsgetDetails(id: string): Promise<Models.GetAgentBindDetailsResponse>
Pythoncloud.device_bindings.get_detailsdef get_details(self, id: str) -> GetAgentBindDetailsResponse
Gocloud.DeviceBindings.GetDetailsfunc (r *DeviceBindingsResource) GetDetails(ctx context.Context, id string) (GetAgentBindDetailsResponse, error)

参数

参数位置类型必填说明
idpathstring是智能体绑定会话的 ID,即设备创建它时返回的 bind_id。

响应

200 · application/json

字段类型必填说明
successboolean是—
dataagentBindDetailsWire是—

错误

状态码Schema说明
其他(default)DeviceBindingErrorResponseCloud Server 错误

错误 schema 见错误。

示例

import { BeeOSClient } from "@beeos-ai/cloud-sdk";

const cloud = new BeeOSClient({
  baseURL: "https://api.cloud.beeos.ai/v1",
  apiKey: "YOUR_API_KEY", // bsk_ key: backend only
});
const result = await cloud.deviceBindings.getDetails("id_123");
console.log(result);

deviceBindings.createPortal

POST /v1/agent/portal/bind-sessions · Operation ID createPortalBind

创建 portal 绑定会话

SDK 方法

语言方法签名
TypeScriptcloud.deviceBindings.createPortalcreatePortal(input: Models.CreatePortalBindRequest): Promise<Models.CreatePortalBindResponse>
Pythoncloud.device_bindings.create_portaldef create_portal(self, input: CreatePortalBindRequest) -> CreatePortalBindResponse
Gocloud.DeviceBindings.CreatePortalfunc (r *DeviceBindingsResource) CreatePortal(ctx context.Context, input CreatePortalBindRequest) (CreatePortalBindResponse, error)

请求体

application/json · 必填

字段类型必填说明
namestring否为设备创建的实例的显示名称,最多 128 个字符。默认为 BeeRunner。

响应

200 · application/json

字段类型必填说明
successboolean是—
dataportalBindWire是—

错误

状态码Schema说明
其他(default)DeviceBindingErrorResponseCloud Server 错误

错误 schema 见错误。

示例

import { BeeOSClient } from "@beeos-ai/cloud-sdk";

const cloud = new BeeOSClient({
  baseURL: "https://api.cloud.beeos.ai/v1",
  apiKey: "YOUR_API_KEY", // bsk_ key: backend only
});
const result = await cloud.deviceBindings.createPortal({});
console.log(result);

deviceBindings.getPortal

GET /v1/agent/portal/bind-sessions/{id} · Operation ID getPortalBind

获取 portal 绑定会话

SDK 方法

语言方法签名
TypeScriptcloud.deviceBindings.getPortalgetPortal(id: string): Promise<Models.GetPortalBindResponse>
Pythoncloud.device_bindings.get_portaldef get_portal(self, id: str) -> GetPortalBindResponse
Gocloud.DeviceBindings.GetPortalfunc (r *DeviceBindingsResource) GetPortal(ctx context.Context, id string) (GetPortalBindResponse, error)

参数

参数位置类型必填说明
idpathstring是portal 绑定会话的 ID,即创建它时返回的 bind_id。以 portal_ 开头。

响应

200 · application/json

字段类型必填说明
successboolean是—
dataportalBindWire是—

错误

状态码Schema说明
其他(default)DeviceBindingErrorResponseCloud Server 错误

错误 schema 见错误。

示例

import { BeeOSClient } from "@beeos-ai/cloud-sdk";

const cloud = new BeeOSClient({
  baseURL: "https://api.cloud.beeos.ai/v1",
  apiKey: "YOUR_API_KEY", // bsk_ key: backend only
});
const result = await cloud.deviceBindings.getPortal("id_123");
console.log(result);

deviceBindings.resolvePortal

POST /v1/agent/portal/bind-sessions/{id}/resolve · Operation ID resolvePortalBind

解析 portal 绑定会话

SDK 方法

语言方法签名
TypeScriptcloud.deviceBindings.resolvePortalresolvePortal(id: string, input: Models.ResolvePortalBindRequest): Promise<Models.ResolvePortalBindResponse>
Pythoncloud.device_bindings.resolve_portaldef resolve_portal(self, id: str, input: ResolvePortalBindRequest) -> ResolvePortalBindResponse
Gocloud.DeviceBindings.ResolvePortalfunc (r *DeviceBindingsResource) ResolvePortal(ctx context.Context, id string, input ResolvePortalBindRequest) (ResolvePortalBindResponse, error)

参数

参数位置类型必填说明
idpathstring是portal 绑定会话的 ID,即创建它时返回的 bind_id。以 portal_ 开头。

请求体

application/json · 必填

字段类型必填说明
decisionstring是如何处理认领了该会话的设备。必填。 可选值: "recover" — 把设备绑定到 instance_id 所指的现有实例; "create" — 为设备创建新实例. (枚举表)
instance_idstring否要绑定设备的现有实例的 ID。decision 为 recover 时必填;create 时忽略。

响应

200 · application/json

字段类型必填说明
successboolean是—
dataportalBindWire是—

错误

状态码Schema说明
其他(default)DeviceBindingErrorResponseCloud Server 错误

错误 schema 见错误。

示例

import { BeeOSClient } from "@beeos-ai/cloud-sdk";

const cloud = new BeeOSClient({
  baseURL: "https://api.cloud.beeos.ai/v1",
  apiKey: "YOUR_API_KEY", // bsk_ key: backend only
});
const result = await cloud.deviceBindings.resolvePortal("id_123", { decision: "recover" });
console.log(result);

deviceBindings.revokePortal

POST /v1/agent/portal/bind-sessions/{id}/revoke · Operation ID revokePortalBind

撤销 portal 绑定会话

SDK 方法

语言方法签名
TypeScriptcloud.deviceBindings.revokePortalrevokePortal(id: string): Promise<Models.RevokePortalBindResponse>
Pythoncloud.device_bindings.revoke_portaldef revoke_portal(self, id: str) -> RevokePortalBindResponse
Gocloud.DeviceBindings.RevokePortalfunc (r *DeviceBindingsResource) RevokePortal(ctx context.Context, id string) (RevokePortalBindResponse, error)

参数

参数位置类型必填说明
idpathstring是portal 绑定会话的 ID,即创建它时返回的 bind_id。以 portal_ 开头。

响应

200 · application/json

字段类型必填说明
successboolean是—
dataportalBindWire是—

错误

状态码Schema说明
其他(default)DeviceBindingErrorResponseCloud Server 错误

错误 schema 见错误。

示例

import { BeeOSClient } from "@beeos-ai/cloud-sdk";

const cloud = new BeeOSClient({
  baseURL: "https://api.cloud.beeos.ai/v1",
  apiKey: "YOUR_API_KEY", // bsk_ key: backend only
});
const result = await cloud.deviceBindings.revokePortal("id_123");
console.log(result);

按判别字段区分的结构

Binding 按 client_type 区分

Binding 的结构取决于它自己的 client_type 值。

client_type 的取值说明结构
"web"绑定到网页来源,在 origin 中返回。BindingWeb
"native"绑定到设备密钥,其指纹在 cnf_jkt 中返回。BindingNative