BEEOS CLOUD / DEVELOPER REFERENCE
会话回复与实时通道
发送并流式写入聊天回复、读取历史,以及订阅实时事件。
Cloud 聊天把每条用户提问作为 session/prompt 运行时方法投递,并预先创建处于 streaming 状态的回复消息。harness 用补丁写入内容,最后把它标记为 completed、failed、refused 或 cancelled。
BoundRuntimeChatReply
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
向 Cloud 已为聊天提示创建、处于 streaming 状态的回复行写入内容。变更会排队逐个发送,并各带幂等键;终态方法会回读已保存的行,不一致则失败。
class BoundRuntimeChatReply
new BoundRuntimeChatReply(readonly input: { authority: RuntimeChatAuthorityPort; http: RuntimeChatHttpPort; binding: RuntimeChatRetainedBinding; now?: () => number; })TypeScript · 构造
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
input | { authority: RuntimeChatAuthorityPort; http: RuntimeChatHttpPort; binding: RuntimeChatRetainedBinding; now?: () => number; } | 是 | authority 提供当前租约,http 负责发送请求,binding 标识回复行并提供幂等键,now 是可选的毫秒时钟。 |
属性
| 名称 | 类型 | 说明 |
|---|---|---|
readonly id | string | 回复消息的标识。 |
readonly isTerminated | boolean | 调用过终态方法(finalize、fail、refuse 或 cancel)之后为 true。 |
readonly initialPartCount | number | 绑定时回复行已有的消息片段数量。已有片段会原样保留。 |
initialize
读取回复行并记住其正文与消息片段(parts)。该行不处于 streaming 状态时拒绝。bindExistingRuntimeChatReply 会替你调用它。
async initialize(): Promise<void>TypeScript · 参数
无参数。
返回值 Promise<void>
opened
以初始化时读到的回复行快照完成。
opened(): Promise<RuntimeChatRetainedSnapshot>TypeScript · 参数
无参数。
返回值 Promise<RuntimeChatRetainedSnapshot>
flush
在所有排队的变更都已发送后完成。
flush(): Promise<void>TypeScript · 参数
无参数。
返回值 Promise<void>
assertTerminalSnapshot
检查回复的最终行是否仍保持回复结束时的状态、正文、停止原因与消息片段,不一致则抛出错误。
assertTerminalSnapshot(row: RuntimeChatRetainedSnapshot): voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
row | RuntimeChatRetainedSnapshot | 是 | 由回复的所有者读取到的回复最终行。 |
返回值 void
appendBody
向回复正文追加文本。变更会排队发送,并带上该文本起始处的字节偏移。
appendBody(chunk: string): voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
chunk | string | 是 | 要追加的文本。 |
返回值 void
setBody
用给定文本替换整个正文。
setBody(body: string): voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
body | string | 是 | 新的正文文本。 |
返回值 void
addPart
原样追加一个消息片段(例如工具调用)。
addPart(part: unknown): voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
part | unknown | 是 | 要追加的消息片段,为与 JSON 兼容的数据。 |
返回值 void
addToolResult
addPart 的别名,用于工具结果片段。
addToolResult(part: unknown): voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
part | unknown | 是 | 要追加的工具结果片段。 |
返回值 void
replacePart
替换给定下标处的消息片段。下标超出现有片段范围时抛出错误。
replacePart(index: number, part: unknown): voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
index | number | 是 | 要替换的片段的下标(从 0 开始)。 | |
part | unknown | 是 | 替换后的消息片段。 |
返回值 void
finalize
把回复置为 completed 状态,回读该行并返回。已保存的行不一致时拒绝。
finalize(options?: { stopReason?: string }): Promise<RuntimeChatRetainedSnapshot>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
options | { stopReason?: string } | 否 | stopReason 会随行保存。 |
返回值 Promise<RuntimeChatRetainedSnapshot>
fail
把回复置为 failed 状态(可同时替换正文),回读该行并返回。
fail(options?: { body?: string; stopReason?: string }): Promise<RuntimeChatRetainedSnapshot>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
options | { body?: string; stopReason?: string } | 否 | body 用于替换正文(例如换成错误文本);stopReason 会随行保存。 |
返回值 Promise<RuntimeChatRetainedSnapshot>
refuse
把回复置为 refused 状态,回读该行并返回。
refuse(options?: { stopReason?: string }): Promise<RuntimeChatRetainedSnapshot>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
options | { stopReason?: string } | 否 | stopReason 会随行保存。 |
返回值 Promise<RuntimeChatRetainedSnapshot>
cancel
把回复置为 cancelled 状态,回读该行并返回。
cancel(options?: { stopReason?: string }): Promise<RuntimeChatRetainedSnapshot>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
options | { stopReason?: string } | 否 | stopReason 会随行保存。 |
返回值 Promise<RuntimeChatRetainedSnapshot>
CentrifugeClientLike
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
SDK 所用到的 Centrifuge WebSocket 客户端的那一部分接口。想自带传输(例如测试中)时实现它。
interface CentrifugeClientLikeon
为客户端事件注册监听器:connected、connecting、disconnected、error 或 publication。
on(event: "publication", listener: (ctx: { data: unknown }) => void): voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
event | "publication" | 是 | 要监听的事件名。 | |
listener | (ctx: { data: unknown }) => void | 是 | 以事件上下文调用的回调。 |
返回值 void
connect
开始连接。
connect(): voidTypeScript · 参数
无参数。
返回值 void
disconnect
关闭连接。
disconnect(): voidTypeScript · 参数
无参数。
返回值 void
CentrifugeRealtimeFactory
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
创建实时客户端。默认工厂使用 centrifuge 包和 ws WebSocket。
interface CentrifugeRealtimeFactorycreate
为给定 URL 和连接令牌创建客户端。
create(options: { url: string; token: string }): CentrifugeClientLikeTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
options | { url: string; token: string } | 是 | 实时端点的 url 和连接 token。 |
RuntimeChatAuthorityPort
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
为聊天客户端提供当前租约。把你的注册协调器适配成它即可。
interface RuntimeChatAuthorityPortcurrentLease
返回含凭据的当前租约;没有时返回 null。
currentLease(): RuntimeChatLease | nullTypeScript · 参数
无参数。
返回值 RuntimeChatLease | null
subscribeLease
可选。注册监听器:租约变化时以新租约调用,租约丢失时以 null 调用。返回用于移除监听器的函数。
subscribeLease?( listener: (lease: RuntimeChatLease | null) => void, ): () => voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
listener | (lease: RuntimeChatLease | null) => void | 是 | 接收新租约(或 null)的回调。 |
返回值 () => void
RuntimeChatClient
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
基于当前租约的聊天客户端:实时接收聊天消息、发送消息与回复、读取历史。用 createRuntimeChatClient 创建。
interface RuntimeChatClient属性
| 名称 | 类型 | 说明 |
|---|---|---|
readonly connectionState | RuntimeChatConnectionState | 实时连接的当前状态。 |
readonly messages | { send(input: RuntimeChatSendInput): Promise<unknown>; startStream(input: RuntimeChatSendInput): RuntimeChatReplyStream; } | 发送:send 发出一条消息,startStream 开始一条可分段填充的回复。 |
history
读取你已知 ID 的会话的已保存历史的一页。没有列出实例下所有会话的调用,因此无法在这里发现未知的会话 ID。
history( conversationId: string, input?: RuntimeChatHistoryInput, ): Promise<RuntimeChatHistoryPage>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
conversationId | string | 是 | 会话的标识。 | |
input | RuntimeChatHistoryInput | 否 | 分页选项:上一页返回的 cursor 以及 limit。 |
返回值 Promise<RuntimeChatHistoryPage>
syncConversation
用当前租约为 session/new 操作创建或更新会话并返回。会话所有者由该操作推导,请求体中不携带。
syncConversation( input: RuntimeNativeConversationSyncRequest, ): Promise<RuntimeNativeConversationSyncResponse>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
input | RuntimeNativeConversationSyncRequest | 是 | 会话同步请求。 |
返回值 Promise<RuntimeNativeConversationSyncResponse>
on
注册监听器。事件:message(收到聊天消息)、error、connection(连接状态变化)、disconnect(套接字关闭,带 code 与 reason)。返回客户端本身。
on( event: "disconnect", listener: (info: { code: number; reason: string }) => void, ): thisTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
event | "disconnect" | 是 | 事件名:message、error、connection 或 disconnect。 | |
listener | (info: { code: number; reason: string }) => void | 是 | 以事件载荷调用的回调。 |
返回值 this
connect
用当前租约连接实时通道。断开后会带退避地重连,并在令牌或租约到期前续期会话。
connect(): Promise<void>TypeScript · 参数
无参数。
返回值 Promise<void>
disconnect
关闭实时连接。
disconnect(): Promise<void>TypeScript · 参数
无参数。
返回值 Promise<void>
dispose
关闭连接并移除所有监听器,之后不能再使用该客户端。
dispose(): voidTypeScript · 参数
无参数。
返回值 void
RuntimeChatHttpPort
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
聊天客户端所需的 HTTP 调用。createRuntimeChatHttpPort 以租约鉴权实现了它;想改变传输方式时可自行实现。
interface RuntimeChatHttpPortgetMessage
可选。以单个权威快照读取一条消息。bindExistingRuntimeChatReply 需要它。
getMessage?( lease: RuntimeChatLease, input: { conversationId: string; messageId: string }, ): Promise<RuntimeChatRetainedSnapshot>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
lease | RuntimeChatLease | 是 | 用其凭据为请求授权的当前运行时租约。 | |
input | { conversationId: string; messageId: string } | 是 | 消息所属的 conversationId 与 messageId。 |
返回值 Promise<RuntimeChatRetainedSnapshot>
personalToken
为租约申请实时连接令牌。应答包含令牌、实时端点 URL 和要订阅的频道。
personalToken(lease: RuntimeChatLease): Promise<{ token: string; realtimeUrl: string; channels: string[]; principalId?: string; expiresAt?: number; }>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
lease | RuntimeChatLease | 是 | 用其凭据为请求授权的当前运行时租约。 |
返回值 Promise<{ token: string; realtimeUrl: string; channels: string[]; principalId?: string; expiresAt?: number; }>
getHistory
读取某个会话已保存历史的一页。
getHistory( lease: RuntimeChatLease, input: { conversationId: string } & RuntimeChatHistoryInput, ): Promise<RuntimeChatHistoryPage>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
lease | RuntimeChatLease | 是 | 用其凭据为请求授权的当前运行时租约。 | |
input | { conversationId: string } & RuntimeChatHistoryInput | 是 | conversationId 加上分页选项 cursor 与 limit。 |
返回值 Promise<RuntimeChatHistoryPage>
syncConversation
为某个运行时操作创建或更新会话,并返回该会话。
syncConversation( lease: RuntimeChatLease, input: RuntimeNativeConversationSyncRequest, ): Promise<RuntimeNativeConversationSyncResponse>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
lease | RuntimeChatLease | 是 | 用其凭据为请求授权的当前运行时租约。 | |
input | RuntimeNativeConversationSyncRequest | 是 | 会话同步请求。 |
返回值 Promise<RuntimeNativeConversationSyncResponse>
sendMessage
向会话发送一条消息。应答包含消息 ID,以及(如有)处理结果。
sendMessage( lease: RuntimeChatLease, input: { conversationId: string; id: string; type: string; content: unknown; replyTo?: string; }, ): Promise<{ messageId: string; outcome?: string }>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
lease | RuntimeChatLease | 是 | 用其凭据为请求授权的当前运行时租约。 | |
input | { conversationId: string; id: string; type: string; content: unknown; replyTo?: string; } | 是 | conversationId、消息 id、其 type 与 content,以及可选的 replyTo(被回复消息的 ID)。 |
返回值 Promise<{ messageId: string; outcome?: string }>
openStream
创建一条处于 streaming 状态的消息,随后用 patchMessage 填充内容。
openStream( lease: RuntimeChatLease, input: { conversationId: string; id: string; type: string; content: unknown; replyTo?: string; }, ): Promise<{ messageId: string }>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
lease | RuntimeChatLease | 是 | 用其凭据为请求授权的当前运行时租约。 | |
input | { conversationId: string; id: string; type: string; content: unknown; replyTo?: string; } | 是 | conversationId、消息 id、其 type 与 content,以及可选的 replyTo(被回复消息的 ID)。 |
返回值 Promise<{ messageId: string }>
patchMessage
修改正在流式写入的消息:替换或追加正文、替换消息片段,或设置最终的 state 与 stopReason。
patchMessage( lease: RuntimeChatLease, input: { conversationId: string; messageId: string; body?: string; bodyAppend?: string; bodyFrom?: number; parts?: readonly unknown[]; state?: string; stopReason?: string; operationKey?: string; }, ): Promise<void>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
lease | RuntimeChatLease | 是 | 用其凭据为请求授权的当前运行时租约。 | |
input | { conversationId: string; messageId: string; body?: string; bodyAppend?: string; bodyFrom?: number; parts?: readonly unknown[]; state?: string; stopReason?: string; operationKey?: string; } | 是 | conversationId 与 messageId,加上具体变更:body,或 bodyAppend 配合字节偏移 bodyFrom,以及 parts、state、stopReason,还有使变更幂等的 operationKey。 |
返回值 Promise<void>
RuntimeChatRealtimePort
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
聊天客户端所需的实时传输。createCentrifugoRealtimePort 提供了实现。
interface RuntimeChatRealtimePortopen
打开实时连接,返回一个句柄,调用其 close() 结束连接。
open(input: { token: string; url: string; channel: string; onEvent(event: { type: string; data?: unknown }): void; onState(state: "connected" | "connecting" | "disconnected" | "failed"): void; onError(error: unknown): void; }): { close(): void }TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
input | { token: string; url: string; channel: string; onEvent(event: { type: string; data?: unknown }): void; onState(state: "connected" | "connecting" | "disconnected" | "failed"): void; onError(error: unknown): void; } | 是 | 连接 token、url 与 channel,以及回调 onEvent、onState、onError。 |
返回值 { close(): void }
RuntimeChatReplyStream
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
一条可分段填充、最后以四种状态之一结束的回复。用 client.messages.startStream 创建。
interface RuntimeChatReplyStream属性
| 名称 | 类型 | 说明 |
|---|---|---|
readonly id | string | 回复消息的标识。 |
readonly isTerminated | boolean | 调用过终态方法之后为 true。 |
readonly parts | readonly unknown[] | 目前已添加的消息片段。 |
opened
在回复消息创建完成后完成。
opened(): Promise<unknown>TypeScript · 参数
无参数。
返回值 Promise<unknown>
flush
在所有排队的变更都已发送后完成。
flush(): Promise<void>TypeScript · 参数
无参数。
返回值 Promise<void>
appendBody
向回复正文追加文本。
appendBody(chunk: string): voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
chunk | string | 是 | 要追加的文本。 |
返回值 void
setBody
用给定文本替换整个正文。
setBody(body: string): voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
body | string | 是 | 新的正文文本。 |
返回值 void
addToolResult
addPart 的别名,用于工具结果片段。
addToolResult(part: unknown): voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
part | unknown | 是 | 要追加的工具结果片段。 |
返回值 void
addPart
原样追加一个消息片段。
addPart(part: unknown): voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
part | unknown | 是 | 要追加的消息片段,为与 JSON 兼容的数据。 |
返回值 void
replacePart
替换给定下标处的消息片段。
replacePart(index: number, part: unknown): voidTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
index | number | 是 | 要替换的片段的下标(从 0 开始)。 | |
part | unknown | 是 | 替换后的消息片段。 |
返回值 void
finalize
把回复置为 completed 状态。
finalize(options?: { stopReason?: string }): Promise<unknown>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
options | { stopReason?: string } | 否 | stopReason 会随消息保存。 |
返回值 Promise<unknown>
fail
把回复置为 failed 状态,可同时替换正文。
fail(options?: { body?: string; stopReason?: string }): Promise<unknown>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
options | { body?: string; stopReason?: string } | 否 | body 用于替换正文(例如换成错误文本);stopReason 会随消息保存。 |
返回值 Promise<unknown>
refuse
把回复置为 refused 状态。
refuse(options?: { stopReason?: string }): Promise<unknown>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
options | { stopReason?: string } | 否 | stopReason 会随消息保存。 |
返回值 Promise<unknown>
cancel
把回复置为 cancelled 状态。
cancel(options?: { stopReason?: string }): Promise<unknown>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
options | { stopReason?: string } | 否 | stopReason 会随消息保存。 |
返回值 Promise<unknown>
RuntimeRealtimeSubscription
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
已打开的实时订阅的句柄。
interface RuntimeRealtimeSubscription属性
| 名称 | 类型 | 说明 |
|---|---|---|
token | RuntimeRealtimeToken | 打开该订阅所用的实时令牌。 |
close
关闭订阅。
close(): voidTypeScript · 参数
无参数。
返回值 void
bindExistingRuntimeChatReply
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
绑定到 Cloud 已创建、处于 streaming 状态的回复行,返回 BoundRuntimeChatReply。它自己从不创建或发送消息。
async function bindExistingRuntimeChatReply(input: { authority: RuntimeChatAuthorityPort; http: RuntimeChatHttpPort; binding: RuntimeChatRetainedBinding; now?: () => number; }): Promise<BoundRuntimeChatReply>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
input | { authority: RuntimeChatAuthorityPort; http: RuntimeChatHttpPort; binding: RuntimeChatRetainedBinding; now?: () => number; } | 是 | authority 提供当前租约,http 负责发送请求,binding 标识回复行并提供幂等键,now 是可选的毫秒时钟。 |
返回值 Promise<BoundRuntimeChatReply>
createCentrifugoRealtimePort
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
基于 Centrifuge 创建 RuntimeChatRealtimePort。它只监听令牌所授予频道的推送,自己不会订阅。
function createCentrifugoRealtimePort(options: CentrifugeRealtimePortOptions = {}): RuntimeChatRealtimePortTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
options | CentrifugeRealtimePortOptions | 否 | {} | 可选的 factory,用于创建 Centrifuge 客户端,默认使用真实客户端。 |
createRuntimeChatClient
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
创建 RuntimeChatClient。调用 connect() 开始接收消息。
function createRuntimeChatClient(options: RuntimeChatClientOptions): RuntimeChatClientTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
options | RuntimeChatClientOptions | 是 | authority、http 与 realtime 三个端口,以及可选的时钟、重连延迟函数和日志器。 |
createRuntimeChatHttpPort
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
创建 RuntimeChatHttpPort,每个请求都以租约凭据作为 Authorization: Bearer 发送。
function createRuntimeChatHttpPort(options: RuntimeChatHttpPortOptions): RuntimeChatHttpPortTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
options | RuntimeChatHttpPortOptions | 是 | 消息服务的 baseUrl,以及可选的 fetchImpl 和 now。 |
mintRuntimeRealtimeToken
TypeScript @beeos-ai/cloud-harness-sdk · Python beeos_cloud_harness_sdk.realtime
为租约申请实时连接令牌及要订阅的频道。应答不完整时抛出 HarnessProtocolError。
async function mintRuntimeRealtimeToken(http: RuntimeLeaseHttp, credential: RuntimeLeaseCredential, signal?: AbortSignal): Promise<RuntimeRealtimeToken>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
http | RuntimeLeaseHttp | 是 | 发送请求的、带租约鉴权的 HTTP 客户端。 | |
credential | RuntimeLeaseCredential | 是 | 为该调用授权的运行时租约凭据。 | |
signal | AbortSignal | 否 | 中止该信号会取消这次调用。 |
返回值 Promise<RuntimeRealtimeToken>
Python · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
http | RuntimeLeaseHttp | 是 | 发送请求的、带租约鉴权的 HTTP 客户端。 | |
credential | RuntimeLeaseCredential | 是 | 为该调用授权的运行时租约凭据。 |
normalizeMessage
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
把原始消息对象转换为 RuntimeChatMessage:保留未知字段,并根据 snake_case 或其他别名补全驼峰字段 id、conversationId、type、content、senderId、replyTo 与 createdAt。值不是对象或没有 id 时返回 null。
function normalizeMessage(value: unknown): RuntimeChatMessage | nullTypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
value | unknown | 是 | 来自实时通道或历史的原始消息对象。 |
返回值 RuntimeChatMessage | null
subscribeRuntimeRealtime
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
用租约申请实时令牌并打开实时连接。完成时返回一个持有令牌、可关闭订阅的句柄。
async function subscribeRuntimeRealtime(input: { origin: string; credential: RuntimeLeaseCredential; onEvent: (event: { type: string; data?: unknown }) => void; onState?: (state: "connecting" | "connected" | "disconnected" | "failed") => void; onError?: (error: unknown) => void; fetch?: typeof fetch; factory?: CentrifugeRealtimeFactory; signal?: AbortSignal; }): Promise<RuntimeRealtimeSubscription>TypeScript · 参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
input | { origin: string; credential: RuntimeLeaseCredential; onEvent: (event: { type: string; data?: unknown }) => void; onState?: (state: "connecting" | "connected" | "disconnected" | "failed") => void; onError?: (error: unknown) => void; fetch?: typeof fetch; factory?: CentrifugeRealtimeFactory; signal?: AbortSignal; } | 是 | 消息服务的 origin、租约 credential、回调 onEvent、onState、onError,以及可选的 fetch、factory、signal。 |
返回值 Promise<RuntimeRealtimeSubscription>
RUNTIME_CHAT_PATHS
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
聊天路由的路径,为字符串或函数。
const RUNTIME_CHAT_PATHS: Readonly<{ personalToken: string; conversations: string; conversationMessages: (conversationId: string) => string; conversationMessage: (conversationId: string, messageId: string) => string; }>条目
| 名称 | 类型 | 说明 |
|---|---|---|
personalToken | string | 申请实时令牌的路径。 |
conversations | string | 同步会话的路径。 |
conversationMessages | (conversationId: string) => string | 向某个会话发送消息的路径。 |
conversationMessage | (conversationId: string, messageId: string) => string | 修改某个会话中单条消息的路径。 |
RuntimeChatPreparedClearError
TypeScript @beeos-ai/cloud-harness-sdk · 仅 TypeScript
原始回复正在被清除时,HTTP 端口抛出该错误。回复随后停止写入并保留原始行;proof 用于标识这次清除。
class RuntimeChatPreparedClearError extends Error
new RuntimeChatPreparedClearError(readonly proof: RuntimeChatPreparedClearProof)TypeScript · 构造
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
proof | RuntimeChatPreparedClearProof | 是 | 标识使写入停止的那次清除。 |
属性
| 名称 | 类型 | 说明 |
|---|---|---|
readonly proof | RuntimeChatPreparedClearProof | 标识使写入停止的那次清除。 |
错误与异常
本模块定义的错误类型。每个方法的说明会写明它在什么情况下抛出哪种错误。
| 错误 | 语言 | 说明 |
|---|---|---|
| RuntimeChatPreparedClearError | TypeScript | 原始回复正在被清除时,HTTP 端口抛出该错误。回复随后停止写入并保留原始行;proof 用于标识这次清除。 |