@xmov/avatar 2.5.0-alpha.18 → 2.5.0-alpha.19

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.
@@ -1,5 +1,5 @@
1
1
  import type { AvatarStatus, RenderState, Layout, WalkConfig, ICapabilityCheckReport } from "../public-types.js";
2
- import type { XingyunAvatarAgentOptions, XingyunAvatarAgentInitParams, AgentASRStartOptions, AgentPCMChunk, AgentState, AgentASRState } from "./public-types.js";
2
+ import type { XingyunAvatarAgentOptions, XingyunAvatarAgentInitParams, AgentASRStartOptions, AgentPCMChunk, AgentState, AgentASRState, AgentDeviceEvent, AgentDeviceToolResultOptions, AgentDeviceToolResultStatus, AgentPerception } from "./public-types.js";
3
3
  export * from "./public-types.js";
4
4
  export default class XingyunAvatarAgent {
5
5
  static checkCapability(audioOnlyMode?: boolean, hardwareAcceleration?: string): Promise<ICapabilityCheckReport>;
@@ -16,6 +16,20 @@ export default class XingyunAvatarAgent {
16
16
  stopASR: () => Promise<void>;
17
17
  interrupt: () => number;
18
18
  interruptConversation: (reason?: string) => Promise<void>;
19
+ /**
20
+ * 回灌设备工具执行结果,callId 必须是 `onDeviceToolCall` 下发的原值。
21
+ * `options.error` 仅在执行链路异常时传递;正常/业务失败省略或传 null。
22
+ * `options.latencyMs` 对应 `latency_ms`;省略时按 SDK 收到 tool_call 的时间自动计算。
23
+ * 超过 `timeoutMs` 未回灌时 SDK 自动补 `status=timeout`;未连接时忽略。
24
+ */
25
+ respondToolResult: (callId: string, status: AgentDeviceToolResultStatus, result?: Record<string, unknown>, options?: AgentDeviceToolResultOptions) => void;
26
+ /** 上行设备进度/终态(working / completed / failed);未连接时忽略。 */
27
+ emitDeviceEvent: (event: AgentDeviceEvent) => void;
28
+ /**
29
+ * 上行单帧感知(E2E `perception`)。SDK 会补齐 8 个视觉字段 + `client_timestamp`,
30
+ * 未提供的字段写 null;未连接、已销毁时忽略,不缓存、不补发。
31
+ */
32
+ sendPerception: (perception: AgentPerception) => void;
19
33
  getAgentState: () => AgentState;
20
34
  /** @deprecated Use getAgentState instead. */
21
35
  getState: () => AgentState;
@@ -70,6 +70,70 @@ export interface AgentSemanticJudgeResult {
70
70
  action: string;
71
71
  raw?: unknown;
72
72
  }
73
+ /** 设备工具回灌状态(E2E 协议 `tool_result.status`)。 */
74
+ export type AgentDeviceToolResultStatus = "ok" | "error" | "timeout";
75
+ /**
76
+ * `respondToolResult` 的附加字段。
77
+ * `error` 仅用于执行链路异常;正常/业务失败省略或传 `null`,SDK 不会上行空 `error`。
78
+ * `latencyMs` 对应 `tool_result.message.latency_ms`,省略时按 SDK 收到 `tool_call` 的时间自动计算。
79
+ */
80
+ export interface AgentDeviceToolResultOptions {
81
+ /** 执行链路异常文案;业务正常或业务失败传 `null`。超过 4KB 由 SDK 截断。 */
82
+ error?: string | null;
83
+ /** 从收到 `tool_call` 到回灌的耗时(毫秒);省略时 SDK 按本地接收时间自动计算。 */
84
+ latencyMs?: number;
85
+ }
86
+ /** 设备进度/终态(E2E 协议 `device_event.status`)。 */
87
+ export type AgentDeviceEventStatus = "working" | "completed" | "failed";
88
+ /**
89
+ * 下行 `tool_call`。接入方执行完设备动作后**必须**调用
90
+ * `respondToolResult(call.callId, ...)` 回灌,callId 原样带回;
91
+ * 超过 `timeoutMs` 未回灌时 SDK 自动补 `status=timeout`。
92
+ */
93
+ export interface AgentDeviceToolCall {
94
+ callId: string;
95
+ name: string;
96
+ /** 工具入参。`arguments` 为 JSON 文本时已解析,无法解析时为空对象,原文见 `raw`。 */
97
+ arguments: Record<string, unknown>;
98
+ /** 回灌超时时间(毫秒);服务端未下发时使用 SDK 默认值 15000。 */
99
+ timeoutMs: number;
100
+ requireConfirm: boolean;
101
+ /** 服务端未下发时按 `true` 处理。 */
102
+ cancellable: boolean;
103
+ raw?: unknown;
104
+ }
105
+ /** 取消在途设备工具调用(如 `barge_in`),接入方据此停止硬件动作。 */
106
+ export interface AgentDeviceToolCancel {
107
+ callId: string;
108
+ reason?: string;
109
+ raw?: unknown;
110
+ }
111
+ /** 设备进度/终态上行。`failed` 且 `statusMessage` 含“阻挡/受阻/障碍”时服务端按安全事件抢占播报。 */
112
+ export interface AgentDeviceEvent {
113
+ taskId: string;
114
+ status: AgentDeviceEventStatus;
115
+ statusMessage?: string;
116
+ }
117
+ /** 感知置信度,协议要求严格大写。 */
118
+ export type AgentPerceptionConfidence = "NONE" | "LOW" | "MEDIUM" | "HIGH";
119
+ /**
120
+ * 单帧感知快照(E2E 协议 `perception`)。
121
+ * 与 Android 对齐:SDK 每次都会补齐 8 个视觉字段 + `client_timestamp`;
122
+ * 未提供的字段写 `null`,`client_timestamp` 省略时取当前时间。
123
+ * 只传结构化结论,不传原始图像、ASR 文本或概率值。
124
+ */
125
+ export interface AgentPerception {
126
+ face_present_confidence?: AgentPerceptionConfidence | null;
127
+ bbox_area_ratio?: number | null;
128
+ track_id?: string | null;
129
+ dwell_ms?: number | null;
130
+ lip_speaking_confidence?: AgentPerceptionConfidence | null;
131
+ identity_id?: string | null;
132
+ identity_confidence?: AgentPerceptionConfidence | null;
133
+ display_name?: string | null;
134
+ /** 客户端墙钟毫秒,与服务端 Tick 分离;省略时 SDK 取当前时间。 */
135
+ client_timestamp?: number | null;
136
+ }
73
137
  export interface AgentSpeakStateEvent {
74
138
  state: string;
75
139
  clientSpeakId?: string | number;
@@ -89,6 +153,12 @@ export interface XingyunAvatarAgentCallbacks {
89
153
  onSpeakStateChange?: (event: AgentSpeakStateEvent) => void;
90
154
  onConversationChange?: (event: AgentConversationEvent) => void;
91
155
  onSemanticJudgeResult?: (result: AgentSemanticJudgeResult) => void;
156
+ /** 设备工具调用(E2E `tool_call`);执行完必须调用 `respondToolResult` 回灌。 */
157
+ onDeviceToolCall?: (call: AgentDeviceToolCall) => void;
158
+ /** 设备工具取消(E2E `tool_call_cancel`);接入方停止动作,是否回灌由业务决定。 */
159
+ onDeviceToolCancel?: (cancel: AgentDeviceToolCancel) => void;
160
+ /** 服务端回显的 `device_event`(本地已上报的进度/终态)。 */
161
+ onDeviceEvent?: (event: AgentDeviceEvent) => void;
92
162
  onRenderChange?: (state: RenderState) => void;
93
163
  onNetworkInfo?: (info: INetworkInfo) => void;
94
164
  onError?: (error: AgentError) => void;