@spatius/avatarkit 1.3.1-beta.2 → 1.3.1-beta.4
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/CHANGELOG.md +25 -0
- package/dist/AvatarDownloader-C2JJVqKm.js +525 -0
- package/dist/AvatarSDK-CuejGi0J.js +6797 -0
- package/dist/OpusCodec-Bv4kzdt8.js +41726 -0
- package/dist/OpusDecoderProxy-BTWRku-I.js +129 -0
- package/dist/OpusEncoderProxy-_AWpY7N6.js +135 -0
- package/dist/StreamingAudioPlayer-DmotFnXu.js +561 -0
- package/dist/assets/AvatarDownloader-C-CiIH1p.js +753 -0
- package/dist/assets/AvatarSDK-RVj90oMR.js +6585 -0
- package/dist/assets/OpusDecoderWorker.worker-Bd4svkEs.js +41373 -0
- package/dist/assets/OpusEncoderWorker.worker-BdxYhZZ9.js +41567 -0
- package/dist/assets/avatar_core_wasm-wdep7Ict.js +2536 -0
- package/dist/assets/logger-B-X9jUON.js +15043 -0
- package/dist/assets/rolldown-runtime-B-1-B7_t.js +33 -0
- package/dist/avatar_core_wasm-BvVa8lO4.js +2532 -0
- package/dist/core/AvatarController.d.ts +53 -2
- package/dist/core/AvatarView.d.ts +0 -2
- package/dist/error-utils-PtNzUHiL.js +85 -0
- package/dist/index.js +7186 -24
- package/dist/logger-C3fw-NWP.js +15129 -0
- package/dist/pwa-cache-manager-D3nj4sd5.js +151 -0
- package/dist/rolldown-runtime-B-1-B7_t.js +33 -0
- package/dist/types/character.d.ts +4 -4
- package/dist/types/index.d.ts +60 -0
- package/package.json +8 -3
- package/dist/StreamingAudioPlayer-2bLnaLam.js +0 -656
- package/dist/avatar_core_wasm-BIbE25D3.js +0 -2697
- package/dist/index-CPolDcOo.js +0 -22241
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { n as __exportAll } from "./rolldown-runtime-B-1-B7_t.js";
|
|
2
|
+
import { t as logger } from "./logger-C3fw-NWP.js";
|
|
3
|
+
//#region utils/pwa-cache-manager.ts
|
|
4
|
+
/**
|
|
5
|
+
* PWA Cache Manager
|
|
6
|
+
* Manages Service Worker Cache for character resources and template resources
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
var pwa_cache_manager_exports = /* @__PURE__ */ __exportAll({ PwaCacheManager: () => PwaCacheManager });
|
|
10
|
+
/**
|
|
11
|
+
* PWA Cache Manager
|
|
12
|
+
* Manages character resources cache (per character) and template resources cache (versioned)
|
|
13
|
+
*/
|
|
14
|
+
var PwaCacheManager = class PwaCacheManager {
|
|
15
|
+
static TEMPLATE_RESOURCE_VERSION = "1.0.0";
|
|
16
|
+
static TEMPLATE_CACHE_NAME = `spatius-sdk-template-cache-${PwaCacheManager.TEMPLATE_RESOURCE_VERSION}`;
|
|
17
|
+
static TEMPLATE_VERSION_STORAGE_KEY = "spatius-sdk-template-cache-version";
|
|
18
|
+
static CHARACTER_CACHE_PREFIX = "spatius-sdk-character-";
|
|
19
|
+
static CHARACTER_CACHE_SUFFIX = "-cache";
|
|
20
|
+
static MAX_CHARACTER_CACHE_ENTRIES = 1e3;
|
|
21
|
+
/**
|
|
22
|
+
* Check if Cache API is supported
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
static isSupported() {
|
|
26
|
+
return typeof caches !== "undefined";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get character cache name
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
static getCharacterCacheName(characterId) {
|
|
33
|
+
return `${PwaCacheManager.CHARACTER_CACHE_PREFIX}${characterId}${PwaCacheManager.CHARACTER_CACHE_SUFFIX}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get character resource from cache
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
static async getCharacterResource(characterId, url) {
|
|
40
|
+
if (!PwaCacheManager.isSupported()) return null;
|
|
41
|
+
try {
|
|
42
|
+
const cacheName = PwaCacheManager.getCharacterCacheName(characterId);
|
|
43
|
+
const response = await (await caches.open(cacheName)).match(url);
|
|
44
|
+
if (response) {
|
|
45
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
46
|
+
logger.log(`[PwaCacheManager] Character resource cache hit: ${url}`);
|
|
47
|
+
return arrayBuffer;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
logger.warn(`[PwaCacheManager] Failed to get character resource from cache:`, error);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Put character resource into cache
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
static async putCharacterResource(characterId, url, data) {
|
|
60
|
+
if (!PwaCacheManager.isSupported()) return;
|
|
61
|
+
try {
|
|
62
|
+
const cacheName = PwaCacheManager.getCharacterCacheName(characterId);
|
|
63
|
+
const cache = await caches.open(cacheName);
|
|
64
|
+
const keys = await cache.keys();
|
|
65
|
+
if (keys.length >= PwaCacheManager.MAX_CHARACTER_CACHE_ENTRIES) {
|
|
66
|
+
const oldestKey = keys[0];
|
|
67
|
+
await cache.delete(oldestKey);
|
|
68
|
+
logger.log(`[PwaCacheManager] Character cache full, deleted oldest entry: ${oldestKey.url}`);
|
|
69
|
+
}
|
|
70
|
+
await cache.put(url, new Response(data));
|
|
71
|
+
logger.log(`[PwaCacheManager] Character resource cached: ${url}`);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
logger.warn(`[PwaCacheManager] Failed to put character resource to cache:`, error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get template resource from cache
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
static async getTemplateResource(url) {
|
|
81
|
+
if (!PwaCacheManager.isSupported()) return null;
|
|
82
|
+
try {
|
|
83
|
+
const response = await (await caches.open(PwaCacheManager.TEMPLATE_CACHE_NAME)).match(url);
|
|
84
|
+
if (response) {
|
|
85
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
86
|
+
logger.log(`[PwaCacheManager] Template resource cache hit: ${url}`);
|
|
87
|
+
return arrayBuffer;
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
logger.warn(`[PwaCacheManager] Failed to get template resource from cache:`, error);
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Put template resource into cache
|
|
97
|
+
* Template resources have no quantity limit, permanently retained until version update
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
static async putTemplateResource(url, data) {
|
|
101
|
+
if (!PwaCacheManager.isSupported()) return;
|
|
102
|
+
try {
|
|
103
|
+
await (await caches.open(PwaCacheManager.TEMPLATE_CACHE_NAME)).put(url, new Response(data));
|
|
104
|
+
logger.log(`[PwaCacheManager] Template resource cached: ${url}`);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
logger.warn(`[PwaCacheManager] Failed to put template resource to cache:`, error);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Clear character cache
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
static async clearCharacterCache(characterId) {
|
|
114
|
+
if (!PwaCacheManager.isSupported()) return;
|
|
115
|
+
try {
|
|
116
|
+
const cacheName = PwaCacheManager.getCharacterCacheName(characterId);
|
|
117
|
+
await caches.delete(cacheName);
|
|
118
|
+
logger.log(`[PwaCacheManager] Character cache cleared: ${characterId}`);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
logger.warn(`[PwaCacheManager] Failed to clear character cache:`, error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Check template cache version, clear cache if version changed
|
|
125
|
+
* Uses independent template resource version (not dependent on SDK version), allowing different SDK versions to share the same template resource cache
|
|
126
|
+
* @returns true if version changed and cache was cleared, false otherwise
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
static async checkTemplateCacheVersion() {
|
|
130
|
+
if (!PwaCacheManager.isSupported()) return false;
|
|
131
|
+
try {
|
|
132
|
+
const currentTemplateVersion = PwaCacheManager.TEMPLATE_RESOURCE_VERSION;
|
|
133
|
+
const storedVersion = localStorage.getItem(PwaCacheManager.TEMPLATE_VERSION_STORAGE_KEY);
|
|
134
|
+
if (storedVersion !== currentTemplateVersion) {
|
|
135
|
+
if (storedVersion) {
|
|
136
|
+
const oldCacheName = `spatius-sdk-template-cache-${storedVersion}`;
|
|
137
|
+
await caches.delete(oldCacheName).catch(() => {});
|
|
138
|
+
}
|
|
139
|
+
localStorage.setItem(PwaCacheManager.TEMPLATE_VERSION_STORAGE_KEY, currentTemplateVersion);
|
|
140
|
+
logger.log(`[PwaCacheManager] Template cache version changed: ${storedVersion} -> ${currentTemplateVersion}, old cache cleared`);
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
logger.warn(`[PwaCacheManager] Failed to check template cache version:`, error);
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
//#endregion
|
|
151
|
+
export { pwa_cache_manager_exports as n, PwaCacheManager as t };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
9
|
+
var __exportAll = (all, no_symbols) => {
|
|
10
|
+
let target = {};
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
20
|
+
key = keys[i];
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
22
|
+
get: ((k) => from[k]).bind(null, key),
|
|
23
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
29
|
+
value: mod,
|
|
30
|
+
enumerable: true
|
|
31
|
+
}) : target, mod));
|
|
32
|
+
//#endregion
|
|
33
|
+
export { __exportAll as n, __toESM as r, __commonJSMin as t };
|
|
@@ -21,10 +21,10 @@ export interface Animations {
|
|
|
21
21
|
audioMono?: ResourceHolder;
|
|
22
22
|
}
|
|
23
23
|
export interface CustomAnimation {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
/** Animation clip name. */
|
|
25
|
+
name: string;
|
|
26
|
+
/** The clip's resource (local/remote URLs), mirroring other asset resources. */
|
|
27
|
+
resource?: Resource;
|
|
28
28
|
}
|
|
29
29
|
export interface CharacterAsset {
|
|
30
30
|
characterId: string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -35,6 +35,59 @@ export interface AudioFormat {
|
|
|
35
35
|
readonly channelCount: 1;
|
|
36
36
|
/** Sample rate, supported: 8000, 16000, 22050, 24000, 32000, 44100, 48000, default: 16000 */
|
|
37
37
|
readonly sampleRate: number;
|
|
38
|
+
/**
|
|
39
|
+
* Opus target bitrate in bits/sec, used when the SDK encodes the upstream to Opus.
|
|
40
|
+
* Defaults to 48000. Higher = better quality but more upload; tune against the
|
|
41
|
+
* bandwidth/quality tradeoff for your content.
|
|
42
|
+
*/
|
|
43
|
+
readonly opusBitrate?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Whether the SDK may compress the direct-mode uplink as Opus. Default false —
|
|
46
|
+
* the uplink is raw PCM unless you opt in.
|
|
47
|
+
*
|
|
48
|
+
* Opus cuts the upload to roughly an eighth, at the cost of encoding on the
|
|
49
|
+
* client. Off by default so bandwidth is traded for CPU only where that is
|
|
50
|
+
* wanted — low-end devices (e.g. learning tablets) should not be asked to
|
|
51
|
+
* encode audio they cannot afford to.
|
|
52
|
+
*
|
|
53
|
+
* Only effective in direct mode: host mode has no uplink, and Opus input is
|
|
54
|
+
* already Opus so there is nothing to encode. Independent of
|
|
55
|
+
* `inputAudioFormat`, which describes what the host feeds in.
|
|
56
|
+
*/
|
|
57
|
+
readonly opusUplinkEnabled?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Format of the audio the host feeds INTO the SDK (via `send` / `yieldAudioData`).
|
|
60
|
+
* Fixed at SDK initialization for the whole session; do not change it per call.
|
|
61
|
+
*
|
|
62
|
+
* - 'pcm' (default): the host provides raw PCM16 mono.
|
|
63
|
+
* - 'opus': the host provides Opus. The SDK decodes it back to PCM16 for local
|
|
64
|
+
* playback. Independent of the SDK's own upstream format to the driving
|
|
65
|
+
* service, which the SDK decides internally.
|
|
66
|
+
*
|
|
67
|
+
* Under 'opus', the SDK accepts either shape that TTS providers hand out, and
|
|
68
|
+
* tells them apart from the bytes — it is not declared separately:
|
|
69
|
+
*
|
|
70
|
+
* - **Ogg Opus**, as file-style APIs return it (Azure
|
|
71
|
+
* `ogg-48khz-16bit-mono-opus`, Google `OGG_OPUS`). Any chunk boundary is fine.
|
|
72
|
+
* - **Bare Opus packets, ONE PER CALL**, as streaming APIs push them over a
|
|
73
|
+
* WebSocket. The SDK wraps these into Ogg for you. They cannot be batched: an
|
|
74
|
+
* Opus packet carries no length of its own, so several concatenated into one
|
|
75
|
+
* buffer have no recoverable boundaries.
|
|
76
|
+
*
|
|
77
|
+
* Requirements, all reported via `onError` with
|
|
78
|
+
* {@link ErrorCode.invalidAudioInput} rather than failing silently:
|
|
79
|
+
*
|
|
80
|
+
* - **Mono only.** The driving service's lip-sync model consumes mono; request
|
|
81
|
+
* it from your provider rather than relying on a downmix.
|
|
82
|
+
* - **One shape per conversation.** Do not switch between Ogg and bare packets
|
|
83
|
+
* mid-round.
|
|
84
|
+
* - **Ogg or bare packets only.** WebM, MP4, WAV and CAF are not demuxed, even
|
|
85
|
+
* when the Opus inside them would be valid.
|
|
86
|
+
*
|
|
87
|
+
* The configured {@link sampleRate} does not apply: Opus always decodes at
|
|
88
|
+
* 48 kHz, and the SDK reports that rate for the session.
|
|
89
|
+
*/
|
|
90
|
+
readonly inputAudioFormat?: 'pcm' | 'opus';
|
|
38
91
|
}
|
|
39
92
|
export declare enum RenderQuality {
|
|
40
93
|
standard = "standard",
|
|
@@ -129,6 +182,13 @@ export declare enum ErrorCode {
|
|
|
129
182
|
audioOnlyInitFailed = "audioOnlyInitFailed",
|
|
130
183
|
/** No audio data to play */
|
|
131
184
|
noAudio = "noAudio",
|
|
185
|
+
/**
|
|
186
|
+
* Audio handed to the SDK does not match `audioFormat.inputAudioFormat`.
|
|
187
|
+
* Raised for Opus input that is neither Ogg Opus nor a bare Opus packet
|
|
188
|
+
* (e.g. WebM or MP4, which the SDK does not demux), is stereo, or switches
|
|
189
|
+
* shape mid-conversation. The error message names the specific problem.
|
|
190
|
+
*/
|
|
191
|
+
invalidAudioInput = "invalidAudioInput",
|
|
132
192
|
/** Audio context not initialized */
|
|
133
193
|
audioContextNotInitialized = "audioContextNotInitialized",
|
|
134
194
|
/** Animation player not initialized */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spatius/avatarkit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.3.1-beta.
|
|
4
|
+
"version": "1.3.1-beta.4",
|
|
5
5
|
"packageManager": "pnpm@10.18.2",
|
|
6
6
|
"description": "AvatarKit SDK - Real-time Avatar Rendering SDK for Web",
|
|
7
7
|
"author": "AvatarKit Team",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@webgpu/types": "*",
|
|
64
64
|
"next": ">=13.0.0",
|
|
65
|
-
"vite": "
|
|
65
|
+
"vite": ">=5.0.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependenciesMeta": {
|
|
68
68
|
"vite": {
|
|
@@ -78,10 +78,15 @@
|
|
|
78
78
|
"@opentelemetry/api": "^1.9.1",
|
|
79
79
|
"@opentelemetry/api-logs": "^0.218.0",
|
|
80
80
|
"@opentelemetry/exporter-logs-otlp-http": "^0.218.0",
|
|
81
|
+
"@opentelemetry/exporter-metrics-otlp-http": "0.218.0",
|
|
82
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.218.0",
|
|
81
83
|
"@opentelemetry/resources": "^2.7.1",
|
|
82
84
|
"@opentelemetry/sdk-logs": "^0.218.0",
|
|
85
|
+
"@opentelemetry/sdk-metrics": "2.7.1",
|
|
86
|
+
"@opentelemetry/sdk-trace-web": "2.7.1",
|
|
83
87
|
"@opentelemetry/semantic-conventions": "^1.41.1",
|
|
84
88
|
"nanoid": "^5.1.6",
|
|
89
|
+
"opusscript": "0.1.1",
|
|
85
90
|
"posthog-js": "^1.310.1"
|
|
86
91
|
},
|
|
87
92
|
"devDependencies": {
|
|
@@ -90,7 +95,7 @@
|
|
|
90
95
|
"fflate": "0.8.3",
|
|
91
96
|
"tsx": "^4.20.6",
|
|
92
97
|
"typescript": "^5.0.0",
|
|
93
|
-
"vite": "^
|
|
98
|
+
"vite": "^8.0.0",
|
|
94
99
|
"vite-plugin-dts": "^4.5.4"
|
|
95
100
|
}
|
|
96
101
|
}
|