@spatialwalk/avatarkit 1.0.0-beta.67 → 1.0.0-beta.69

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +33 -11
  2. package/README.md +102 -18
  3. package/dist/{StreamingAudioPlayer-CD9jBs6B.js → StreamingAudioPlayer-DiIRp5nx.js} +109 -1
  4. package/dist/animation/AnimationWebSocketClient.d.ts +26 -0
  5. package/dist/animation/utils/eventEmitter.d.ts +3 -0
  6. package/dist/animation/utils/flameConverter.d.ts +10 -3
  7. package/dist/audio/AnimationPlayer.d.ts +46 -0
  8. package/dist/audio/StreamingAudioPlayer.d.ts +93 -0
  9. package/dist/config/app-config.d.ts +5 -1
  10. package/dist/config/constants.d.ts +7 -1
  11. package/dist/config/sdk-config-loader.d.ts +11 -3
  12. package/dist/core/Avatar.d.ts +10 -0
  13. package/dist/core/AvatarController.d.ts +164 -2
  14. package/dist/core/AvatarDownloader.d.ts +10 -0
  15. package/dist/core/AvatarManager.d.ts +27 -1
  16. package/dist/core/AvatarSDK.d.ts +27 -0
  17. package/dist/core/AvatarView.d.ts +148 -3
  18. package/dist/core/NetworkLayer.d.ts +6 -0
  19. package/dist/generated/common/v1/models.d.ts +8 -1
  20. package/dist/generated/driveningress/v1/driveningress.d.ts +11 -1
  21. package/dist/generated/driveningress/v2/driveningress.d.ts +5 -2
  22. package/dist/generated/google/protobuf/struct.d.ts +38 -5
  23. package/dist/generated/google/protobuf/timestamp.d.ts +102 -1
  24. package/dist/{index-GRm00rtd.js → index-BT9yxWW8.js} +1468 -30
  25. package/dist/index.d.ts +3 -0
  26. package/dist/index.js +1 -1
  27. package/dist/renderer/RenderSystem.d.ts +8 -0
  28. package/dist/renderer/covariance.d.ts +11 -0
  29. package/dist/renderer/sortSplats.d.ts +10 -0
  30. package/dist/renderer/webgl/reorderData.d.ts +12 -0
  31. package/dist/renderer/webgl/webglRenderer.d.ts +53 -0
  32. package/dist/renderer/webgpu/webgpuRenderer.d.ts +38 -0
  33. package/dist/types/character-settings.d.ts +4 -0
  34. package/dist/types/character.d.ts +9 -3
  35. package/dist/types/index.d.ts +56 -23
  36. package/dist/utils/animation-interpolation.d.ts +30 -5
  37. package/dist/utils/client-id.d.ts +5 -0
  38. package/dist/utils/conversationId.d.ts +18 -0
  39. package/dist/utils/error-utils.d.ts +24 -1
  40. package/dist/utils/id-manager.d.ts +26 -0
  41. package/dist/utils/logger.d.ts +4 -1
  42. package/dist/utils/posthog-tracker.d.ts +27 -5
  43. package/dist/utils/pwa-cache-manager.d.ts +36 -0
  44. package/dist/utils/usage-tracker.d.ts +17 -2
  45. package/dist/vite.d.ts +16 -1
  46. package/dist/wasm/avatarCoreAdapter.d.ts +145 -0
  47. package/dist/wasm/avatarCoreMemory.d.ts +52 -0
  48. package/package.json +3 -3
  49. package/vite.js +45 -29
@@ -1,4 +1,4 @@
1
- import { Flame } from '../generated/driveningress/v1/driveningress';
1
+ import { KeyframeData } from '../types';
2
2
  import { Avatar } from './Avatar';
3
3
  import { AvatarController } from './AvatarController';
4
4
  export declare class AvatarView {
@@ -32,40 +32,173 @@ export declare class AvatarView {
32
32
  private isPureRenderingMode;
33
33
  private avatarActiveTimer;
34
34
  private readonly AVATAR_ACTIVE_INTERVAL;
35
+ /**
36
+ * 对齐两端 Flame 维度:标量统一长度,expression 取最大长度并零填充
37
+ */
35
38
  private alignFlamePair;
39
+ /**
40
+ * 生成并对齐过渡帧,确保首尾帧与起止帧完全一致
41
+ * @param from 起始帧
42
+ * @param to 目标帧
43
+ * @param durationMs 过渡时长(开头或结尾)
44
+ * @param useLinearInterpolation 是否使用线性插值(旧实现),true 用于 idle->speaking,false 用于 speaking->idle(使用 Bezier 曲线)
45
+ */
36
46
  private generateAndAlignTransitionFrames;
47
+ /**
48
+ * 获取缓存的 Idle 首帧,如果未缓存则获取并缓存
49
+ */
37
50
  private getCachedIdleFirstFrame;
51
+ /**
52
+ * Constructor
53
+ * Creates a unified AvatarController, internally composes network layer based on configuration
54
+ * @param avatar - Avatar instance
55
+ * @param container - Canvas container element (required)
56
+ */
38
57
  constructor(avatar: Avatar, container: HTMLElement);
58
+ /**
59
+ * Get controller (public interface)
60
+ */
39
61
  get controller(): AvatarController;
62
+ /**
63
+ * 创建canvas元素
64
+ */
40
65
  private createCanvas;
66
+ /**
67
+ * 初始化视图系统
68
+ */
41
69
  private initializeView;
70
+ /**
71
+ * 初始化渲染系统
72
+ */
42
73
  private initializeRenderSystem;
74
+ /**
75
+ * 获取默认相机配置
76
+ */
43
77
  private getDefaultCameraConfig;
78
+ /**
79
+ * 根据资源解析最终的相机配置,优先使用角色设置,其次 camera.json
80
+ */
44
81
  private resolveCameraConfig;
82
+ /**
83
+ * 从角色设置中推导相机配置
84
+ */
45
85
  private deriveCameraConfigFromSettings;
86
+ /**
87
+ * 渲染第一帧
88
+ */
46
89
  private renderFirstFrame;
90
+ /**
91
+ * 更新 FPS 统计(在 requestAnimationFrame 回调中调用)
92
+ */
47
93
  private updateFPS;
94
+ /**
95
+ * 初始化 FPS 计算
96
+ */
48
97
  private initFPS;
98
+ /**
99
+ * 开始idle动画循环
100
+ */
49
101
  private startIdleAnimationLoop;
102
+ /**
103
+ * 开始实时对话动画循环
104
+ */
50
105
  private startRealtimeAnimationLoop;
106
+ /**
107
+ * 停止idle动画循环
108
+ */
51
109
  private stopIdleAnimationLoop;
110
+ /**
111
+ * 停止实时对话动画循环
112
+ */
52
113
  private stopRealtimeAnimationLoop;
114
+ /**
115
+ * 停止所有动画循环
116
+ */
53
117
  private stopAllAnimationLoops;
118
+ /**
119
+ * 渲染实时帧(由播放层回调调用)
120
+ */
54
121
  private renderRealtimeFrame;
122
+ /**
123
+ * 状态转换方法
124
+ * 统一管理状态转换,确保状态一致性
125
+ */
55
126
  private setState;
127
+ /**
128
+ * 检查是否在实时播放状态(Speaking 或过渡到 Speaking)
129
+ */
56
130
  private get isRealtimePlaying();
131
+ /**
132
+ * 检查是否在过渡中
133
+ */
57
134
  private get isTransitioning();
135
+ /**
136
+ * 检查过渡结束后是否回到 Idle
137
+ */
58
138
  private get endToIdleAfterTransition();
139
+ /**
140
+ * 处理打断
141
+ * 打断时应该生成过渡动画,而不是直接跳回 Idle
142
+ */
59
143
  private handleInterrupt;
144
+ /**
145
+ * 设置 AvatarController 事件监听器
146
+ */
60
147
  private setupControllerEventListeners;
148
+ /**
149
+ * 准备实时渲染(生成过渡到 Speaking)
150
+ * 统一逻辑:从当前正在播放的帧 -> Speaking 第一帧
151
+ */
61
152
  private prepareRealtimeRendering;
153
+ /**
154
+ * 开始实时渲染循环
155
+ */
62
156
  private startRealtimeRendering;
157
+ /**
158
+ * 停止实时对话渲染
159
+ */
63
160
  private stopRealtimeRendering;
161
+ /**
162
+ * Cleanup view resources
163
+ * Closes avatarController and cleans up all related resources
164
+ */
64
165
  dispose(): void;
65
- renderFlame(flame: Flame, enableIdleRendering?: boolean): Promise<void>;
66
- generateTransitionFromIdle(toFlame: Flame, frameCount: number, transitionType?: 'start' | 'end'): Promise<Flame[]>;
166
+ /**
167
+ * Render specified keyframe (pure rendering mode, no audio-animation synchronization)
168
+ * Suitable for scenarios where external application controls audio playback and animation playback
169
+ * @param keyframeData - Keyframe data
170
+ * @param enableIdleRendering - Whether to enable idle loop rendering. true: Enable idle rendering and return immediately (skip this keyframe); false: Disable idle rendering and process keyframe (default)
171
+ */
172
+ renderFlame(keyframeData: KeyframeData, enableIdleRendering?: boolean): Promise<void>;
173
+ /**
174
+ * Generate transition frame array from current idle frame to target keyframe (pure rendering mode)
175
+ * @param toKeyframeData - Target keyframe data
176
+ * @param frameCount - Number of transition frames
177
+ * @param transitionType - Transition type: 'start' means Idle -> toKeyframeData (start transition), 'end' means toKeyframeData -> Idle (end transition)
178
+ * @returns Transition frame array with length of frameCount
179
+ */
180
+ generateTransitionFromIdle(toKeyframeData: KeyframeData, frameCount: number, transitionType?: 'start' | 'end'): Promise<KeyframeData[]>;
181
+ /**
182
+ * 使用新的相机配置重新渲染当前帧(用于暂停状态下更新相机)
183
+ * 复用 AvatarController 的重新渲染逻辑,因为 renderCallback 会调用 renderRealtimeFrame,
184
+ * 而 renderRealtimeFrame 会使用已更新的相机配置(通过 renderSystem.updateCamera)
185
+ * @private
186
+ */
67
187
  private rerenderCurrentFrameWithNewCamera;
188
+ /**
189
+ * 处理尺寸变化:通知渲染系统更新视口与投影
190
+ */
68
191
  private handleResize;
192
+ /**
193
+ * Get or set avatar transform in canvas
194
+ *
195
+ * @example
196
+ * // Get current transform
197
+ * const current = avatarView.transform
198
+ *
199
+ * // Set transform
200
+ * avatarView.transform = { x: 0.5, y: 0, scale: 2.0 }
201
+ */
69
202
  get transform(): {
70
203
  x: number;
71
204
  y: number;
@@ -76,7 +209,19 @@ export declare class AvatarView {
76
209
  y: number;
77
210
  scale: number;
78
211
  });
212
+ /**
213
+ * 上报 avatar_active 埋点
214
+ * @private
215
+ */
79
216
  private reportAvatarActive;
217
+ /**
218
+ * 启动 avatar_active 心跳埋点(每10分钟一次)
219
+ * @private
220
+ */
80
221
  private startAvatarActiveHeartbeat;
222
+ /**
223
+ * 停止 avatar_active 心跳埋点
224
+ * @private
225
+ */
81
226
  private stopAvatarActiveHeartbeat;
82
227
  }
@@ -1 +1,7 @@
1
+ /**
2
+ * NetworkLayer - Network communication layer
3
+ * Responsible for WebSocket connections, protocol handling, and data retrieval
4
+ * Automatically calls AvatarController (playback layer) interfaces after obtaining data
5
+ * @internal Not part of public API
6
+ */
1
7
  export {};
@@ -1,10 +1,17 @@
1
1
  import { BinaryReader, BinaryWriter } from '@bufbuild/protobuf/wire';
2
2
  export declare const protobufPackage = "common.v1";
3
-
3
+ /**
4
+ * CustomAnimation 自定义动画配置
5
+ * 用于角色资产组的自定义动画定义
6
+ */
4
7
  export interface CustomAnimation {
8
+ /** 动画唯一标识 */
5
9
  key: string;
10
+ /** pb类型动画文件URL */
6
11
  pbUrl: string;
12
+ /** wav类型音频文件URL(可选) */
7
13
  wavUrl: string;
14
+ /** 备注说明 */
8
15
  remark: string;
9
16
  }
10
17
  export declare const CustomAnimation: MessageFns<CustomAnimation>;
@@ -9,19 +9,29 @@ export declare enum MessageType {
9
9
  }
10
10
  export declare function messageTypeFromJSON(object: any): MessageType;
11
11
  export declare function messageTypeToJSON(object: MessageType): string;
12
-
12
+ /**
13
+ * 兼容流式传输,只要 req_id 相同,客户端可以将音频分段发若干个 ClientAudioInputData
14
+ * 新 req_id 出现后,老 req_id 的请求将被忽略
15
+ */
13
16
  export interface ClientAudioInputData {
14
17
  reqId: string;
15
18
  audio: Uint8Array;
16
19
  end: boolean;
17
20
  }
18
21
  export interface Flame {
22
+ /** 平移 */
19
23
  translation: number[];
24
+ /** 旋转 */
20
25
  rotation: number[];
26
+ /** 脖子 */
21
27
  neckPose: number[];
28
+ /** 下巴 */
22
29
  jawPose: number[];
30
+ /** 眼睛 */
23
31
  eyePose: number[];
32
+ /** 眼皮 */
24
33
  eyeLid: number[];
34
+ /** 表情参数 */
25
35
  expression: number[];
26
36
  }
27
37
  export interface FlameAnimation {
@@ -4,9 +4,9 @@ import { Timestamp } from '../../google/protobuf/timestamp';
4
4
  export declare const protobufPackage = "driveningress.v2";
5
5
  export declare enum MessageType {
6
6
  MESSAGE_UNSPECIFIED = 0,
7
-
7
+ /** MESSAGE_CLIENT_CONFIGURE_SESSION - 协商会话参数 */
8
8
  MESSAGE_CLIENT_CONFIGURE_SESSION = 1,
9
-
9
+ /** MESSAGE_SERVER_CONFIRM_SESSION - 确认协商成功 */
10
10
  MESSAGE_SERVER_CONFIRM_SESSION = 2,
11
11
  MESSAGE_CLIENT_AUDIO_INPUT = 3,
12
12
  MESSAGE_SERVER_ERROR = 4,
@@ -31,7 +31,9 @@ export interface GetCharacterInfoRequest {
31
31
  characterId: string;
32
32
  }
33
33
  export interface CharacterAsset {
34
+ /** 资产ID,例如 "v1/xxx" */
34
35
  characterId: string;
36
+ /** 资产版本,例如 "1.0.0" */
35
37
  version: string;
36
38
  createdAt?: Timestamp | undefined;
37
39
  updatedAt?: Timestamp | undefined;
@@ -42,6 +44,7 @@ export interface CharacterAsset {
42
44
  characterSettings?: {
43
45
  [key: string]: any;
44
46
  } | undefined;
47
+ /** 自定义动画列表 */
45
48
  customAnimations: CustomAnimation[];
46
49
  }
47
50
  export interface Resource {
@@ -1,15 +1,30 @@
1
1
  import { BinaryReader, BinaryWriter } from '@bufbuild/protobuf/wire';
2
2
  export declare const protobufPackage = "google.protobuf";
3
-
3
+ /**
4
+ * `NullValue` is a singleton enumeration to represent the null value for the
5
+ * `Value` type union.
6
+ *
7
+ * The JSON representation for `NullValue` is JSON `null`.
8
+ */
4
9
  export declare enum NullValue {
5
-
10
+ /** NULL_VALUE - Null value. */
6
11
  NULL_VALUE = 0,
7
12
  UNRECOGNIZED = -1
8
13
  }
9
14
  export declare function nullValueFromJSON(object: any): NullValue;
10
15
  export declare function nullValueToJSON(object: NullValue): string;
11
-
16
+ /**
17
+ * `Struct` represents a structured data value, consisting of fields
18
+ * which map to dynamically typed values. In some languages, `Struct`
19
+ * might be supported by a native representation. For example, in
20
+ * scripting languages like JS a struct is represented as an
21
+ * object. The details of that representation are described together
22
+ * with the proto support for the language.
23
+ *
24
+ * The JSON representation for `Struct` is JSON object.
25
+ */
12
26
  export interface Struct {
27
+ /** Unordered map of dynamically typed values. */
13
28
  fields: {
14
29
  [key: string]: any | undefined;
15
30
  };
@@ -18,19 +33,37 @@ export interface Struct_FieldsEntry {
18
33
  key: string;
19
34
  value?: any | undefined;
20
35
  }
21
-
36
+ /**
37
+ * `Value` represents a dynamically typed value which can be either
38
+ * null, a number, a string, a boolean, a recursive struct value, or a
39
+ * list of values. A producer of value is expected to set one of these
40
+ * variants. Absence of any variant indicates an error.
41
+ *
42
+ * The JSON representation for `Value` is JSON value.
43
+ */
22
44
  export interface Value {
45
+ /** Represents a null value. */
23
46
  nullValue?: NullValue | undefined;
47
+ /** Represents a double value. */
24
48
  numberValue?: number | undefined;
49
+ /** Represents a string value. */
25
50
  stringValue?: string | undefined;
51
+ /** Represents a boolean value. */
26
52
  boolValue?: boolean | undefined;
53
+ /** Represents a structured value. */
27
54
  structValue?: {
28
55
  [key: string]: any;
29
56
  } | undefined;
57
+ /** Represents a repeated `Value`. */
30
58
  listValue?: Array<any> | undefined;
31
59
  }
32
-
60
+ /**
61
+ * `ListValue` is a wrapper around a repeated field of values.
62
+ *
63
+ * The JSON representation for `ListValue` is JSON array.
64
+ */
33
65
  export interface ListValue {
66
+ /** Repeated field of dynamically typed values. */
34
67
  values: any[];
35
68
  }
36
69
  export declare const Struct: MessageFns<Struct> & StructWrapperFns;
@@ -1,8 +1,109 @@
1
1
  import { BinaryReader, BinaryWriter } from '@bufbuild/protobuf/wire';
2
2
  export declare const protobufPackage = "google.protobuf";
3
-
3
+ /**
4
+ * A Timestamp represents a point in time independent of any time zone or local
5
+ * calendar, encoded as a count of seconds and fractions of seconds at
6
+ * nanosecond resolution. The count is relative to an epoch at UTC midnight on
7
+ * January 1, 1970, in the proleptic Gregorian calendar which extends the
8
+ * Gregorian calendar backwards to year one.
9
+ *
10
+ * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
11
+ * second table is needed for interpretation, using a [24-hour linear
12
+ * smear](https://developers.google.com/time/smear).
13
+ *
14
+ * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
15
+ * restricting to that range, we ensure that we can convert to and from [RFC
16
+ * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
17
+ *
18
+ * # Examples
19
+ *
20
+ * Example 1: Compute Timestamp from POSIX `time()`.
21
+ *
22
+ * Timestamp timestamp;
23
+ * timestamp.set_seconds(time(NULL));
24
+ * timestamp.set_nanos(0);
25
+ *
26
+ * Example 2: Compute Timestamp from POSIX `gettimeofday()`.
27
+ *
28
+ * struct timeval tv;
29
+ * gettimeofday(&tv, NULL);
30
+ *
31
+ * Timestamp timestamp;
32
+ * timestamp.set_seconds(tv.tv_sec);
33
+ * timestamp.set_nanos(tv.tv_usec * 1000);
34
+ *
35
+ * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
36
+ *
37
+ * FILETIME ft;
38
+ * GetSystemTimeAsFileTime(&ft);
39
+ * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
40
+ *
41
+ * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
42
+ * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
43
+ * Timestamp timestamp;
44
+ * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
45
+ * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
46
+ *
47
+ * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
48
+ *
49
+ * long millis = System.currentTimeMillis();
50
+ *
51
+ * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
52
+ * .setNanos((int) ((millis % 1000) * 1000000)).build();
53
+ *
54
+ * Example 5: Compute Timestamp from Java `Instant.now()`.
55
+ *
56
+ * Instant now = Instant.now();
57
+ *
58
+ * Timestamp timestamp =
59
+ * Timestamp.newBuilder().setSeconds(now.getEpochSecond())
60
+ * .setNanos(now.getNano()).build();
61
+ *
62
+ * Example 6: Compute Timestamp from current time in Python.
63
+ *
64
+ * timestamp = Timestamp()
65
+ * timestamp.GetCurrentTime()
66
+ *
67
+ * # JSON Mapping
68
+ *
69
+ * In JSON format, the Timestamp type is encoded as a string in the
70
+ * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
71
+ * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
72
+ * where {year} is always expressed using four digits while {month}, {day},
73
+ * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
74
+ * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
75
+ * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
76
+ * is required. A proto3 JSON serializer should always use UTC (as indicated by
77
+ * "Z") when printing the Timestamp type and a proto3 JSON parser should be
78
+ * able to accept both UTC and other timezones (as indicated by an offset).
79
+ *
80
+ * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
81
+ * 01:30 UTC on January 15, 2017.
82
+ *
83
+ * In JavaScript, one can convert a Date object to this format using the
84
+ * standard
85
+ * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
86
+ * method. In Python, a standard `datetime.datetime` object can be converted
87
+ * to this format using
88
+ * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
89
+ * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
90
+ * the Joda Time's [`ISODateTimeFormat.dateTime()`](
91
+ * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()
92
+ * ) to obtain a formatter capable of generating timestamps in this format.
93
+ */
4
94
  export interface Timestamp {
95
+ /**
96
+ * Represents seconds of UTC time since Unix epoch
97
+ * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
98
+ * 9999-12-31T23:59:59Z inclusive.
99
+ */
5
100
  seconds: string;
101
+ /**
102
+ * Non-negative fractions of a second at nanosecond resolution. Negative
103
+ * second values with fractions must still have non-negative nanos values
104
+ * that count forward in time. Must be from 0 to 999,999,999
105
+ * inclusive.
106
+ */
6
107
  nanos: number;
7
108
  }
8
109
  export declare const Timestamp: MessageFns<Timestamp>;