@asiyst/sdk 0.1.25 → 0.1.28
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/dist/index.cjs +587 -96
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +587 -96
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -97,7 +97,7 @@ var ALL_ACTION_KINDS = [
|
|
|
97
97
|
// src/core/constants.ts
|
|
98
98
|
function resolveSdkVersion() {
|
|
99
99
|
{
|
|
100
|
-
return "0.1.
|
|
100
|
+
return "0.1.28";
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
var SDK_VERSION = resolveSdkVersion();
|
|
@@ -114,7 +114,8 @@ var VIEWPORT_HANDLER_THROTTLE_MS = 80;
|
|
|
114
114
|
var AVATAR_VIEWPORT_PADDING = 12;
|
|
115
115
|
var AVATAR_TARGET_GAP = 16;
|
|
116
116
|
var WEBSITE_MAP_TEXT_LIMIT = 80;
|
|
117
|
-
var CONFIG_CACHE_TTL_MS = 1e3 *
|
|
117
|
+
var CONFIG_CACHE_TTL_MS = 1e3 * 30;
|
|
118
|
+
var CONFIG_REVALIDATION_INTERVAL_MS = 3e4;
|
|
118
119
|
var HEARTBEAT_INTERVAL_MS = 45e3;
|
|
119
120
|
|
|
120
121
|
// src/security/selectors.ts
|
|
@@ -1060,7 +1061,7 @@ var ConfigCache = class {
|
|
|
1060
1061
|
constructor(storage) {
|
|
1061
1062
|
this.storage = storage;
|
|
1062
1063
|
}
|
|
1063
|
-
read(projectId) {
|
|
1064
|
+
read(projectId, ignoreTtl = false) {
|
|
1064
1065
|
const raw = this.storage.read("config");
|
|
1065
1066
|
if (!raw) {
|
|
1066
1067
|
return null;
|
|
@@ -1070,7 +1071,7 @@ var ConfigCache = class {
|
|
|
1070
1071
|
if (parsed.schemaVersion !== CONFIG_SCHEMA_VERSION || parsed.projectId !== projectId) {
|
|
1071
1072
|
return null;
|
|
1072
1073
|
}
|
|
1073
|
-
if (Date.now() - parsed.fetchedAt > CONFIG_CACHE_TTL_MS) {
|
|
1074
|
+
if (!ignoreTtl && Date.now() - parsed.fetchedAt > CONFIG_CACHE_TTL_MS) {
|
|
1074
1075
|
return null;
|
|
1075
1076
|
}
|
|
1076
1077
|
return normalizeProjectConfig(parsed.config);
|
|
@@ -1078,15 +1079,35 @@ var ConfigCache = class {
|
|
|
1078
1079
|
return null;
|
|
1079
1080
|
}
|
|
1080
1081
|
}
|
|
1081
|
-
|
|
1082
|
+
getEnvelope(projectId) {
|
|
1083
|
+
const raw = this.storage.read("config");
|
|
1084
|
+
if (!raw) {
|
|
1085
|
+
return null;
|
|
1086
|
+
}
|
|
1087
|
+
try {
|
|
1088
|
+
const parsed = JSON.parse(raw);
|
|
1089
|
+
if (parsed.schemaVersion !== CONFIG_SCHEMA_VERSION || parsed.projectId !== projectId) {
|
|
1090
|
+
return null;
|
|
1091
|
+
}
|
|
1092
|
+
return parsed;
|
|
1093
|
+
} catch {
|
|
1094
|
+
return null;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
write(projectId, config, meta) {
|
|
1082
1098
|
const envelope = {
|
|
1083
1099
|
schemaVersion: CONFIG_SCHEMA_VERSION,
|
|
1084
1100
|
projectId,
|
|
1085
1101
|
fetchedAt: Date.now(),
|
|
1102
|
+
etag: meta?.etag,
|
|
1103
|
+
revision: meta?.revision ?? config.version,
|
|
1086
1104
|
config
|
|
1087
1105
|
};
|
|
1088
1106
|
this.storage.write("config", JSON.stringify(envelope));
|
|
1089
1107
|
}
|
|
1108
|
+
clear() {
|
|
1109
|
+
this.storage.remove("config");
|
|
1110
|
+
}
|
|
1090
1111
|
};
|
|
1091
1112
|
|
|
1092
1113
|
// src/config/ConfigManager.ts
|
|
@@ -1095,6 +1116,7 @@ var ConfigManager = class {
|
|
|
1095
1116
|
this.options = options;
|
|
1096
1117
|
this.cloud = cloud;
|
|
1097
1118
|
this.events = events;
|
|
1119
|
+
this.inFlightRefresh = null;
|
|
1098
1120
|
const credentials = validateInitOptions(options);
|
|
1099
1121
|
this.options = { ...options, ...credentials };
|
|
1100
1122
|
this.cache = new ConfigCache(
|
|
@@ -1106,13 +1128,34 @@ var ConfigManager = class {
|
|
|
1106
1128
|
get() {
|
|
1107
1129
|
return this.current;
|
|
1108
1130
|
}
|
|
1109
|
-
async refresh() {
|
|
1131
|
+
async refresh(options) {
|
|
1132
|
+
if (this.inFlightRefresh) {
|
|
1133
|
+
return this.inFlightRefresh;
|
|
1134
|
+
}
|
|
1135
|
+
this.inFlightRefresh = this.executeRefresh(options);
|
|
1136
|
+
try {
|
|
1137
|
+
return await this.inFlightRefresh;
|
|
1138
|
+
} finally {
|
|
1139
|
+
this.inFlightRefresh = null;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
async executeRefresh(_options) {
|
|
1143
|
+
const prev = this.current;
|
|
1110
1144
|
try {
|
|
1111
1145
|
const remote = await this.cloud.fetchConfig();
|
|
1112
|
-
|
|
1113
|
-
this.
|
|
1146
|
+
const normalized = normalizeProjectConfig(remote);
|
|
1147
|
+
this.current = normalized;
|
|
1148
|
+
this.cache.write(this.options.projectId, normalized);
|
|
1149
|
+
const hasChanged = prev.version !== normalized.version || prev.avatarName !== normalized.avatarName || prev.position !== normalized.position || prev.size !== normalized.size || prev.assetUrl !== normalized.assetUrl || prev.thumbnailUrl !== normalized.thumbnailUrl || JSON.stringify(prev.theme) !== JSON.stringify(normalized.theme) || JSON.stringify(prev.animations) !== JSON.stringify(normalized.animations);
|
|
1150
|
+
if (hasChanged && this.onConfigUpdated) {
|
|
1151
|
+
this.onConfigUpdated(normalized, prev);
|
|
1152
|
+
}
|
|
1114
1153
|
return this.current;
|
|
1115
1154
|
} catch (error) {
|
|
1155
|
+
const lastKnownGood = this.cache.read(this.options.projectId, true);
|
|
1156
|
+
if (lastKnownGood) {
|
|
1157
|
+
this.current = lastKnownGood;
|
|
1158
|
+
}
|
|
1116
1159
|
this.events.emit("asiyst:error", {
|
|
1117
1160
|
code: "config_refresh_failed",
|
|
1118
1161
|
message: error instanceof Error ? error.message : "Failed to refresh configuration"
|
|
@@ -1120,6 +1163,18 @@ var ConfigManager = class {
|
|
|
1120
1163
|
return this.current;
|
|
1121
1164
|
}
|
|
1122
1165
|
}
|
|
1166
|
+
applyLocalUpdate(partial) {
|
|
1167
|
+
const prev = this.current;
|
|
1168
|
+
this.current = {
|
|
1169
|
+
...this.current,
|
|
1170
|
+
...partial
|
|
1171
|
+
};
|
|
1172
|
+
this.cache.write(this.options.projectId, this.current);
|
|
1173
|
+
if (this.onConfigUpdated) {
|
|
1174
|
+
this.onConfigUpdated(this.current, prev);
|
|
1175
|
+
}
|
|
1176
|
+
return this.current;
|
|
1177
|
+
}
|
|
1123
1178
|
localFallback() {
|
|
1124
1179
|
const base = fallbackConfig();
|
|
1125
1180
|
return {
|
|
@@ -1778,13 +1833,34 @@ var AssetLoader = class {
|
|
|
1778
1833
|
constructor() {
|
|
1779
1834
|
this.inFlightController = null;
|
|
1780
1835
|
this.createdObjectUrls = [];
|
|
1836
|
+
this.inFlightLoads = /* @__PURE__ */ new Map();
|
|
1837
|
+
this.cachedAssets = /* @__PURE__ */ new Map();
|
|
1781
1838
|
}
|
|
1782
1839
|
async load(assetUrl, options) {
|
|
1783
|
-
const startTime = Date.now();
|
|
1784
1840
|
const sanitizedUrl = sanitizeText(assetUrl.trim(), 2048);
|
|
1785
1841
|
if (!sanitizedUrl) {
|
|
1786
1842
|
throw new Error("Asset URL is required");
|
|
1787
1843
|
}
|
|
1844
|
+
const cached = this.cachedAssets.get(sanitizedUrl);
|
|
1845
|
+
if (cached) {
|
|
1846
|
+
return cached;
|
|
1847
|
+
}
|
|
1848
|
+
const inFlight = this.inFlightLoads.get(sanitizedUrl);
|
|
1849
|
+
if (inFlight) {
|
|
1850
|
+
return inFlight;
|
|
1851
|
+
}
|
|
1852
|
+
const loadPromise = this.performLoad(sanitizedUrl, options);
|
|
1853
|
+
this.inFlightLoads.set(sanitizedUrl, loadPromise);
|
|
1854
|
+
try {
|
|
1855
|
+
const asset = await loadPromise;
|
|
1856
|
+
this.cachedAssets.set(sanitizedUrl, asset);
|
|
1857
|
+
return asset;
|
|
1858
|
+
} finally {
|
|
1859
|
+
this.inFlightLoads.delete(sanitizedUrl);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
async performLoad(sanitizedUrl, options) {
|
|
1863
|
+
const startTime = Date.now();
|
|
1788
1864
|
this.inFlightController = new AbortController();
|
|
1789
1865
|
const abortSignal = options?.signal ? anySignal([this.inFlightController.signal, options.signal]) : this.inFlightController.signal;
|
|
1790
1866
|
const timeoutMs = options?.timeoutMs ?? 6e4;
|
|
@@ -1827,6 +1903,9 @@ var AssetLoader = class {
|
|
|
1827
1903
|
throw new Error(`Avatar asset download failed: HTTP ${response.status} from ${sanitizedUrl}`);
|
|
1828
1904
|
}
|
|
1829
1905
|
const contentType = (response.headers.get("content-type") || "").toLowerCase();
|
|
1906
|
+
if (contentType.includes("text/html")) {
|
|
1907
|
+
throw new Error(`Avatar asset request returned HTML instead of 3D asset from ${sanitizedUrl}`);
|
|
1908
|
+
}
|
|
1830
1909
|
if (isJsonExtension || contentType.includes("application/json")) {
|
|
1831
1910
|
const text = await response.text();
|
|
1832
1911
|
let manifest;
|
|
@@ -1860,6 +1939,11 @@ var AssetLoader = class {
|
|
|
1860
1939
|
if (arrayBuffer.byteLength < 12) {
|
|
1861
1940
|
throw new Error("Avatar asset payload is too small to be a valid 3D container");
|
|
1862
1941
|
}
|
|
1942
|
+
const headerBytes = new Uint8Array(arrayBuffer, 0, Math.min(256, arrayBuffer.byteLength));
|
|
1943
|
+
const headerStr = new TextDecoder("utf-8", { fatal: false }).decode(headerBytes).trim();
|
|
1944
|
+
if (/^<!DOCTYPE\s+html/i.test(headerStr) || /^<html/i.test(headerStr)) {
|
|
1945
|
+
throw new Error(`Avatar asset payload contains HTML error page instead of binary 3D container from ${sanitizedUrl}`);
|
|
1946
|
+
}
|
|
1863
1947
|
if (isFbxExtension || this.isFbxBuffer(arrayBuffer) || !isGlbExtension && !this.isGlbBuffer(arrayBuffer)) {
|
|
1864
1948
|
const fbxHeader = this.parseFbxHeader(arrayBuffer);
|
|
1865
1949
|
const resourcePath = sanitizedUrl.includes("/") ? sanitizedUrl.substring(0, sanitizedUrl.lastIndexOf("/") + 1) : "";
|
|
@@ -2105,6 +2189,8 @@ var AssetLoader = class {
|
|
|
2105
2189
|
this.inFlightController.abort();
|
|
2106
2190
|
this.inFlightController = null;
|
|
2107
2191
|
}
|
|
2192
|
+
this.inFlightLoads.clear();
|
|
2193
|
+
this.cachedAssets.clear();
|
|
2108
2194
|
if (typeof URL !== "undefined" && typeof URL.revokeObjectURL === "function") {
|
|
2109
2195
|
for (const objUrl of this.createdObjectUrls) {
|
|
2110
2196
|
try {
|
|
@@ -2134,8 +2220,11 @@ var FbxRenderer = class {
|
|
|
2134
2220
|
this.scene = null;
|
|
2135
2221
|
this.camera = null;
|
|
2136
2222
|
this.modelRoot = null;
|
|
2223
|
+
this.rawObject = null;
|
|
2137
2224
|
this.mixer = null;
|
|
2138
2225
|
this.allAnimations = [];
|
|
2226
|
+
this.animationMetadataList = [];
|
|
2227
|
+
this.assetLoader = new AssetLoader();
|
|
2139
2228
|
this.currentAction = null;
|
|
2140
2229
|
this.animFrameId = null;
|
|
2141
2230
|
this.lastTime = 0;
|
|
@@ -2151,6 +2240,9 @@ var FbxRenderer = class {
|
|
|
2151
2240
|
this.canvas = doc.createElement("canvas");
|
|
2152
2241
|
this.canvas.className = "asiyst-avatar-canvas";
|
|
2153
2242
|
this.canvas.setAttribute("role", "presentation");
|
|
2243
|
+
this.canvas.style.opacity = "0";
|
|
2244
|
+
this.canvas.style.transition = "opacity 0.25s ease";
|
|
2245
|
+
this.canvas.style.background = "transparent";
|
|
2154
2246
|
const glContext = this.canvas.getContext("webgl2") || this.canvas.getContext("webgl");
|
|
2155
2247
|
if (!glContext) {
|
|
2156
2248
|
throw new Error("WebGLRenderingContext is not available or supported in this browser environment");
|
|
@@ -2170,6 +2262,7 @@ var FbxRenderer = class {
|
|
|
2170
2262
|
antialias: true,
|
|
2171
2263
|
powerPreference: "high-performance"
|
|
2172
2264
|
});
|
|
2265
|
+
this.renderer.setClearColor(0, 0);
|
|
2173
2266
|
this.renderer.setPixelRatio(Math.min(dpr, 2));
|
|
2174
2267
|
this.renderer.setSize(width, height, false);
|
|
2175
2268
|
this.renderer.outputColorSpace = THREE__namespace.SRGBColorSpace;
|
|
@@ -2264,20 +2357,34 @@ var FbxRenderer = class {
|
|
|
2264
2357
|
mesh.receiveShadow = true;
|
|
2265
2358
|
}
|
|
2266
2359
|
});
|
|
2267
|
-
this.
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2360
|
+
this.rawObject = rawObject;
|
|
2361
|
+
this.mixer = new THREE__namespace.AnimationMixer(rawObject);
|
|
2362
|
+
this.allAnimations = [...modelAnimations];
|
|
2363
|
+
const externalAnims = options?.config?.animations || options?.config?.avatar?.animations || [];
|
|
2364
|
+
if (externalAnims.length > 0) {
|
|
2365
|
+
try {
|
|
2366
|
+
await Promise.race([
|
|
2367
|
+
this.loadExternalAnimations(externalAnims, options?.config?.animation),
|
|
2368
|
+
new Promise((resolve) => setTimeout(resolve, 8e3))
|
|
2369
|
+
]);
|
|
2370
|
+
} catch (animErr) {
|
|
2371
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
2372
|
+
console.warn("[asiyst] External animation loading notice:", animErr);
|
|
2373
|
+
}
|
|
2274
2374
|
}
|
|
2275
2375
|
}
|
|
2376
|
+
this.startInitialIdleAnimation(options?.config);
|
|
2377
|
+
if (this.mixer) {
|
|
2378
|
+
this.mixer.update(0);
|
|
2379
|
+
}
|
|
2276
2380
|
container.replaceChildren();
|
|
2277
2381
|
container.appendChild(this.canvas);
|
|
2278
2382
|
try {
|
|
2279
2383
|
this.renderer.render(this.scene, this.camera);
|
|
2280
2384
|
this.initialRenderCompleted = true;
|
|
2385
|
+
if (this.canvas) {
|
|
2386
|
+
this.canvas.style.opacity = "1";
|
|
2387
|
+
}
|
|
2281
2388
|
} catch (renderErr) {
|
|
2282
2389
|
const msg = renderErr instanceof Error ? renderErr.message : String(renderErr);
|
|
2283
2390
|
throw new Error(`Initial FBX WebGL render failed: ${msg}`);
|
|
@@ -2292,7 +2399,7 @@ var FbxRenderer = class {
|
|
|
2292
2399
|
return {
|
|
2293
2400
|
meshCount,
|
|
2294
2401
|
vertexCount: totalVertices,
|
|
2295
|
-
animationCount:
|
|
2402
|
+
animationCount: this.allAnimations.length
|
|
2296
2403
|
};
|
|
2297
2404
|
}
|
|
2298
2405
|
setFacing(direction) {
|
|
@@ -2303,8 +2410,10 @@ var FbxRenderer = class {
|
|
|
2303
2410
|
}
|
|
2304
2411
|
setPose(pose) {
|
|
2305
2412
|
this.currentPose = pose;
|
|
2306
|
-
if (
|
|
2307
|
-
|
|
2413
|
+
if (this.playAnimation(pose)) {
|
|
2414
|
+
return;
|
|
2415
|
+
}
|
|
2416
|
+
if (this.mixer && this.allAnimations.length > 0) {
|
|
2308
2417
|
let targetClip;
|
|
2309
2418
|
if (pose === "speak") {
|
|
2310
2419
|
targetClip = this.allAnimations.find(
|
|
@@ -2315,7 +2424,7 @@ var FbxRenderer = class {
|
|
|
2315
2424
|
(c) => c.name.toLowerCase().includes("think")
|
|
2316
2425
|
);
|
|
2317
2426
|
} else {
|
|
2318
|
-
targetClip = this.allAnimations.find((c) => c.name.toLowerCase().includes("idle")) || this.allAnimations[0];
|
|
2427
|
+
targetClip = this.allAnimations.find((c) => c.name.toLowerCase().includes("idle")) || this.animationMetadataList[0]?.clip || this.allAnimations[0];
|
|
2319
2428
|
}
|
|
2320
2429
|
if (targetClip) {
|
|
2321
2430
|
const newAction = this.mixer.clipAction(targetClip);
|
|
@@ -2326,9 +2435,14 @@ var FbxRenderer = class {
|
|
|
2326
2435
|
}
|
|
2327
2436
|
this.currentAction = newAction;
|
|
2328
2437
|
return;
|
|
2438
|
+
} else if (!this.currentAction?.isRunning()) {
|
|
2439
|
+
this.currentAction?.play();
|
|
2440
|
+
return;
|
|
2329
2441
|
}
|
|
2442
|
+
return;
|
|
2330
2443
|
}
|
|
2331
2444
|
}
|
|
2445
|
+
if (!this.modelRoot) return;
|
|
2332
2446
|
switch (pose) {
|
|
2333
2447
|
case "point":
|
|
2334
2448
|
this.modelRoot.rotation.z = -0.15;
|
|
@@ -2354,6 +2468,209 @@ var FbxRenderer = class {
|
|
|
2354
2468
|
break;
|
|
2355
2469
|
}
|
|
2356
2470
|
}
|
|
2471
|
+
startInitialIdleAnimation(config) {
|
|
2472
|
+
if (!this.mixer) return false;
|
|
2473
|
+
const targetQuery = config?.animation?.trim();
|
|
2474
|
+
if (targetQuery && this.playAnimation(targetQuery)) {
|
|
2475
|
+
return true;
|
|
2476
|
+
}
|
|
2477
|
+
const idleByIntent = this.animationMetadataList.find(
|
|
2478
|
+
(m) => m.intent?.toLowerCase() === "idle"
|
|
2479
|
+
);
|
|
2480
|
+
if (idleByIntent && this.playAnimation(idleByIntent.id || idleByIntent.name)) {
|
|
2481
|
+
return true;
|
|
2482
|
+
}
|
|
2483
|
+
const idleByName = this.animationMetadataList.find(
|
|
2484
|
+
(m) => m.name.toLowerCase().includes("idle") || m.clipName && m.clipName.toLowerCase().includes("idle")
|
|
2485
|
+
);
|
|
2486
|
+
if (idleByName && this.playAnimation(idleByName.id || idleByName.name)) {
|
|
2487
|
+
return true;
|
|
2488
|
+
}
|
|
2489
|
+
const embeddedIdle = this.allAnimations.find(
|
|
2490
|
+
(c) => c.name.toLowerCase().includes("idle")
|
|
2491
|
+
);
|
|
2492
|
+
if (embeddedIdle) {
|
|
2493
|
+
const action = this.mixer.clipAction(embeddedIdle);
|
|
2494
|
+
if (this.currentAction !== action) {
|
|
2495
|
+
action.reset().fadeIn(0.25).play();
|
|
2496
|
+
if (this.currentAction) this.currentAction.fadeOut(0.25);
|
|
2497
|
+
this.currentAction = action;
|
|
2498
|
+
}
|
|
2499
|
+
return true;
|
|
2500
|
+
}
|
|
2501
|
+
if (this.animationMetadataList.length > 0) {
|
|
2502
|
+
const firstMeta = this.animationMetadataList[0];
|
|
2503
|
+
if (this.playAnimation(firstMeta.id || firstMeta.name)) {
|
|
2504
|
+
return true;
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
if (this.allAnimations.length > 0) {
|
|
2508
|
+
const firstClip = this.allAnimations[0];
|
|
2509
|
+
const action = this.mixer.clipAction(firstClip);
|
|
2510
|
+
if (this.currentAction !== action) {
|
|
2511
|
+
action.reset().fadeIn(0.25).play();
|
|
2512
|
+
if (this.currentAction) this.currentAction.fadeOut(0.25);
|
|
2513
|
+
this.currentAction = action;
|
|
2514
|
+
}
|
|
2515
|
+
return true;
|
|
2516
|
+
}
|
|
2517
|
+
return false;
|
|
2518
|
+
}
|
|
2519
|
+
async loadExternalAnimations(animations, targetAnimationName) {
|
|
2520
|
+
if (!this.rawObject || !this.mixer) return;
|
|
2521
|
+
for (const anim of animations) {
|
|
2522
|
+
if (!anim.assetUrl) continue;
|
|
2523
|
+
try {
|
|
2524
|
+
const loaded = await this.assetLoader.load(anim.assetUrl);
|
|
2525
|
+
let extractedClips = [];
|
|
2526
|
+
if (loaded.format === "fbx") {
|
|
2527
|
+
const loader = new FBXLoader_js.FBXLoader();
|
|
2528
|
+
if (loaded.resourcePath) {
|
|
2529
|
+
loader.setResourcePath(loaded.resourcePath);
|
|
2530
|
+
}
|
|
2531
|
+
const parsed = loader.parse(loaded.buffer, loaded.resourcePath || "");
|
|
2532
|
+
extractedClips = parsed.animations || [];
|
|
2533
|
+
} else if (loaded.format === "glb") {
|
|
2534
|
+
const loader = new GLTFLoader_js.GLTFLoader();
|
|
2535
|
+
const gltf = await new Promise((resolve, reject) => {
|
|
2536
|
+
const glbBuffer = loaded.bin.buffer.slice(
|
|
2537
|
+
loaded.bin.byteOffset,
|
|
2538
|
+
loaded.bin.byteOffset + loaded.bin.byteLength
|
|
2539
|
+
);
|
|
2540
|
+
loader.parse(glbBuffer, loaded.url, resolve, reject);
|
|
2541
|
+
});
|
|
2542
|
+
extractedClips = gltf.animations || [];
|
|
2543
|
+
}
|
|
2544
|
+
for (const rawClip of extractedClips) {
|
|
2545
|
+
const retargeted = this.retargetClip(rawClip, this.rawObject);
|
|
2546
|
+
if (!retargeted) continue;
|
|
2547
|
+
retargeted.name = anim.clipName || anim.name || rawClip.name;
|
|
2548
|
+
this.allAnimations.push(retargeted);
|
|
2549
|
+
this.animationMetadataList.push({
|
|
2550
|
+
id: anim.id,
|
|
2551
|
+
name: anim.name,
|
|
2552
|
+
intent: anim.intent,
|
|
2553
|
+
clipName: anim.clipName,
|
|
2554
|
+
loopMode: anim.loopMode,
|
|
2555
|
+
clip: retargeted
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2558
|
+
} catch (err) {
|
|
2559
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
2560
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2561
|
+
console.warn(`[asiyst] Failed to load external animation "${anim.name}": ${msg}`);
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
if (this.currentPose === "idle" || targetAnimationName) {
|
|
2566
|
+
this.startInitialIdleAnimation({ animation: targetAnimationName });
|
|
2567
|
+
if (this.mixer) {
|
|
2568
|
+
this.mixer.update(0);
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
retargetClip(clip, targetObject) {
|
|
2573
|
+
const targetNodeNames = /* @__PURE__ */ new Set();
|
|
2574
|
+
const boneLookup = /* @__PURE__ */ new Map();
|
|
2575
|
+
const cleanBoneName = (name) => {
|
|
2576
|
+
return name.replace(/^.*[:|/]/, "").replace(/^(mixamorig\d*|bip01|armature|root)[:_ ]?/i, "").replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
|
|
2577
|
+
};
|
|
2578
|
+
targetObject.traverse((node) => {
|
|
2579
|
+
if (node.name) {
|
|
2580
|
+
targetNodeNames.add(node.name);
|
|
2581
|
+
const lower = node.name.toLowerCase();
|
|
2582
|
+
const simpleClean = node.name.replace(/^.*[:|/]/, "").toLowerCase();
|
|
2583
|
+
const stripped = cleanBoneName(node.name);
|
|
2584
|
+
if (!boneLookup.has(lower)) boneLookup.set(lower, node.name);
|
|
2585
|
+
if (!boneLookup.has(simpleClean)) boneLookup.set(simpleClean, node.name);
|
|
2586
|
+
if (stripped && !boneLookup.has(stripped)) boneLookup.set(stripped, node.name);
|
|
2587
|
+
}
|
|
2588
|
+
});
|
|
2589
|
+
const isRootOrHips = (name) => {
|
|
2590
|
+
const clean = cleanBoneName(name);
|
|
2591
|
+
return clean === "hips" || clean === "pelvis" || clean === "root";
|
|
2592
|
+
};
|
|
2593
|
+
const validTracks = [];
|
|
2594
|
+
for (const track of clip.tracks) {
|
|
2595
|
+
const dotIdx = track.name.lastIndexOf(".");
|
|
2596
|
+
if (dotIdx === -1) continue;
|
|
2597
|
+
const nodePart = track.name.substring(0, dotIdx);
|
|
2598
|
+
const propPart = track.name.substring(dotIdx);
|
|
2599
|
+
let matchedNodeName;
|
|
2600
|
+
if (targetNodeNames.has(nodePart)) {
|
|
2601
|
+
matchedNodeName = nodePart;
|
|
2602
|
+
} else {
|
|
2603
|
+
const lower = nodePart.toLowerCase();
|
|
2604
|
+
const simpleClean = nodePart.replace(/^.*[:|/]/, "").toLowerCase();
|
|
2605
|
+
const stripped = cleanBoneName(nodePart);
|
|
2606
|
+
matchedNodeName = boneLookup.get(lower) || boneLookup.get(simpleClean) || boneLookup.get(stripped);
|
|
2607
|
+
}
|
|
2608
|
+
if (matchedNodeName) {
|
|
2609
|
+
if (propPart.toLowerCase().startsWith(".position") && !isRootOrHips(matchedNodeName)) {
|
|
2610
|
+
continue;
|
|
2611
|
+
}
|
|
2612
|
+
if (matchedNodeName === nodePart) {
|
|
2613
|
+
validTracks.push(track);
|
|
2614
|
+
} else {
|
|
2615
|
+
const clonedTrack = track.clone();
|
|
2616
|
+
clonedTrack.name = `${matchedNodeName}${propPart}`;
|
|
2617
|
+
validTracks.push(clonedTrack);
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
if (validTracks.length === 0 || clip.duration <= 0) {
|
|
2622
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
2623
|
+
console.warn(`[asiyst] External animation "${clip.name}" has no compatible bone tracks for this avatar skeleton.`);
|
|
2624
|
+
}
|
|
2625
|
+
return null;
|
|
2626
|
+
}
|
|
2627
|
+
return new THREE__namespace.AnimationClip(clip.name, clip.duration, validTracks);
|
|
2628
|
+
}
|
|
2629
|
+
playAnimation(nameOrIntent, loopMode, crossFadeDuration = 0.25) {
|
|
2630
|
+
if (!this.mixer) return false;
|
|
2631
|
+
const query = nameOrIntent.trim().toLowerCase();
|
|
2632
|
+
if (!query) return false;
|
|
2633
|
+
let matched = this.animationMetadataList.find((m) => m.id && m.id.toLowerCase() === query);
|
|
2634
|
+
if (!matched) {
|
|
2635
|
+
matched = this.animationMetadataList.find((m) => m.intent && m.intent.toLowerCase() === query);
|
|
2636
|
+
}
|
|
2637
|
+
if (!matched) {
|
|
2638
|
+
matched = this.animationMetadataList.find((m) => m.name && m.name.toLowerCase() === query);
|
|
2639
|
+
}
|
|
2640
|
+
if (!matched) {
|
|
2641
|
+
matched = this.animationMetadataList.find((m) => m.clipName && m.clipName.toLowerCase() === query);
|
|
2642
|
+
}
|
|
2643
|
+
let clip = matched?.clip;
|
|
2644
|
+
if (!clip) {
|
|
2645
|
+
clip = this.allAnimations.find((c) => c.name.toLowerCase() === query);
|
|
2646
|
+
}
|
|
2647
|
+
if (!clip) {
|
|
2648
|
+
clip = this.allAnimations.find((c) => c.name.toLowerCase().includes(query));
|
|
2649
|
+
}
|
|
2650
|
+
if (!clip) {
|
|
2651
|
+
return false;
|
|
2652
|
+
}
|
|
2653
|
+
const action = this.mixer.clipAction(clip);
|
|
2654
|
+
const effectiveLoop = loopMode || matched?.loopMode || "repeat";
|
|
2655
|
+
if (effectiveLoop === "once") {
|
|
2656
|
+
action.setLoop(THREE__namespace.LoopOnce, 1);
|
|
2657
|
+
action.clampWhenFinished = true;
|
|
2658
|
+
} else if (effectiveLoop === "pingpong") {
|
|
2659
|
+
action.setLoop(THREE__namespace.LoopPingPong, Infinity);
|
|
2660
|
+
} else {
|
|
2661
|
+
action.setLoop(THREE__namespace.LoopRepeat, Infinity);
|
|
2662
|
+
}
|
|
2663
|
+
if (this.currentAction !== action) {
|
|
2664
|
+
action.reset().fadeIn(crossFadeDuration).play();
|
|
2665
|
+
if (this.currentAction) {
|
|
2666
|
+
this.currentAction.fadeOut(crossFadeDuration);
|
|
2667
|
+
}
|
|
2668
|
+
this.currentAction = action;
|
|
2669
|
+
} else if (!action.isRunning()) {
|
|
2670
|
+
action.reset().play();
|
|
2671
|
+
}
|
|
2672
|
+
return true;
|
|
2673
|
+
}
|
|
2357
2674
|
isRendered() {
|
|
2358
2675
|
return this.initialRenderCompleted;
|
|
2359
2676
|
}
|
|
@@ -2440,6 +2757,11 @@ var FbxRenderer = class {
|
|
|
2440
2757
|
this.canvas.remove();
|
|
2441
2758
|
this.canvas = null;
|
|
2442
2759
|
}
|
|
2760
|
+
this.assetLoader.destroy();
|
|
2761
|
+
this.animationMetadataList.length = 0;
|
|
2762
|
+
this.allAnimations = [];
|
|
2763
|
+
this.currentAction = null;
|
|
2764
|
+
this.rawObject = null;
|
|
2443
2765
|
this.camera = null;
|
|
2444
2766
|
this.modelRoot = null;
|
|
2445
2767
|
this.initialRenderCompleted = false;
|
|
@@ -2486,20 +2808,23 @@ var AVATAR_CSS = `
|
|
|
2486
2808
|
transition: left 420ms cubic-bezier(0.22, 1, 0.36, 1), top 420ms cubic-bezier(0.22, 1, 0.36, 1);
|
|
2487
2809
|
}
|
|
2488
2810
|
.asiyst-figure {
|
|
2489
|
-
border-radius: 28px;
|
|
2490
2811
|
display: grid;
|
|
2491
2812
|
place-items: center;
|
|
2492
|
-
color: #fff;
|
|
2493
|
-
font: 700 14px/1.2 system-ui, sans-serif;
|
|
2494
|
-
box-shadow: 0 10px 30px rgba(15, 23, 42, 0.28);
|
|
2495
2813
|
position: relative;
|
|
2496
|
-
overflow: hidden;
|
|
2497
2814
|
cursor: pointer;
|
|
2498
2815
|
border: none;
|
|
2499
2816
|
padding: 0;
|
|
2500
2817
|
outline: none;
|
|
2818
|
+
background: transparent;
|
|
2819
|
+
overflow: visible;
|
|
2820
|
+
}
|
|
2821
|
+
.asiyst-figure.asiyst-compact-launcher {
|
|
2822
|
+
border-radius: 28px;
|
|
2823
|
+
color: #fff;
|
|
2824
|
+
font: 700 14px/1.2 system-ui, sans-serif;
|
|
2825
|
+
box-shadow: 0 10px 30px rgba(15, 23, 42, 0.28);
|
|
2826
|
+
overflow: hidden;
|
|
2501
2827
|
background: #2563eb;
|
|
2502
|
-
transition: width 0.3s ease, height 0.3s ease, background 0.3s ease;
|
|
2503
2828
|
}
|
|
2504
2829
|
.asiyst-figure.asiyst-3d-active {
|
|
2505
2830
|
width: 240px !important;
|
|
@@ -2541,13 +2866,23 @@ var AVATAR_CSS = `
|
|
|
2541
2866
|
pointer-events: none;
|
|
2542
2867
|
}
|
|
2543
2868
|
.asiyst-avatar-loader {
|
|
2544
|
-
width:
|
|
2545
|
-
height:
|
|
2546
|
-
border: 3px solid rgba(
|
|
2547
|
-
border-top-color: #
|
|
2869
|
+
width: 34px;
|
|
2870
|
+
height: 34px;
|
|
2871
|
+
border: 3px solid rgba(37, 99, 235, 0.2);
|
|
2872
|
+
border-top-color: #2563eb;
|
|
2548
2873
|
border-radius: 50%;
|
|
2549
2874
|
animation: asiyst-spin 0.8s linear infinite;
|
|
2550
2875
|
}
|
|
2876
|
+
.asiyst-avatar-loading-silhouette {
|
|
2877
|
+
display: flex;
|
|
2878
|
+
flex-direction: column;
|
|
2879
|
+
align-items: center;
|
|
2880
|
+
justify-content: center;
|
|
2881
|
+
width: 100%;
|
|
2882
|
+
height: 100%;
|
|
2883
|
+
min-height: 240px;
|
|
2884
|
+
pointer-events: none;
|
|
2885
|
+
}
|
|
2551
2886
|
@keyframes asiyst-spin {
|
|
2552
2887
|
to { transform: rotate(360deg); }
|
|
2553
2888
|
}
|
|
@@ -2656,18 +2991,19 @@ var AVATAR_CSS = `
|
|
|
2656
2991
|
var CssAvatarRenderer = class {
|
|
2657
2992
|
constructor() {
|
|
2658
2993
|
this.size = 96;
|
|
2659
|
-
this.hidden =
|
|
2994
|
+
this.hidden = true;
|
|
2660
2995
|
this.facing = "right";
|
|
2661
2996
|
this.pose = "idle";
|
|
2662
2997
|
this.accentColor = "#2563eb";
|
|
2663
2998
|
this.avatarName = "Asiyst";
|
|
2664
2999
|
this.isPanelOpen = false;
|
|
3000
|
+
this.has3dAssetConfigured = false;
|
|
2665
3001
|
// Asset loading & rendering state
|
|
2666
3002
|
this.assetLoader = new AssetLoader();
|
|
2667
3003
|
this.fbxRenderer = null;
|
|
2668
3004
|
this.renderState = "idle";
|
|
2669
3005
|
this.isAssetLoadedFlag = false;
|
|
2670
|
-
this.isFallbackFlag =
|
|
3006
|
+
this.isFallbackFlag = false;
|
|
2671
3007
|
}
|
|
2672
3008
|
mount(container, config) {
|
|
2673
3009
|
const doc = container.ownerDocument;
|
|
@@ -2677,6 +3013,9 @@ var CssAvatarRenderer = class {
|
|
|
2677
3013
|
this.root = doc.createElement("div");
|
|
2678
3014
|
this.root.className = "asiyst-avatar asiyst-animate";
|
|
2679
3015
|
this.root.setAttribute("role", "img");
|
|
3016
|
+
if (this.hidden) {
|
|
3017
|
+
this.root.style.display = "none";
|
|
3018
|
+
}
|
|
2680
3019
|
this.nameTagEl = doc.createElement("div");
|
|
2681
3020
|
this.nameTagEl.className = "asiyst-name-tag";
|
|
2682
3021
|
const sparkle = doc.createElement("span");
|
|
@@ -2739,6 +3078,11 @@ var CssAvatarRenderer = class {
|
|
|
2739
3078
|
this.size = config.size;
|
|
2740
3079
|
this.accentColor = config.theme.accent ?? "#2563eb";
|
|
2741
3080
|
this.avatarName = config.avatarName;
|
|
3081
|
+
const has3dAsset = Boolean(config.assetUrl || config.thumbnailUrl || config.avatarId);
|
|
3082
|
+
this.has3dAssetConfigured = has3dAsset;
|
|
3083
|
+
if (config.assetUrl || config.thumbnailUrl) {
|
|
3084
|
+
this.activeAssetUrl = config.assetUrl ?? config.thumbnailUrl ?? void 0;
|
|
3085
|
+
}
|
|
2742
3086
|
if (this.nameTextEl) {
|
|
2743
3087
|
renderSafeText(this.nameTextEl, config.avatarName);
|
|
2744
3088
|
}
|
|
@@ -2751,26 +3095,44 @@ var CssAvatarRenderer = class {
|
|
|
2751
3095
|
if (this.root) {
|
|
2752
3096
|
this.root.setAttribute("aria-label", config.avatarName);
|
|
2753
3097
|
}
|
|
2754
|
-
if (
|
|
3098
|
+
if (has3dAsset) {
|
|
3099
|
+
if (this.figure) {
|
|
3100
|
+
this.figure.classList.add("asiyst-3d-active");
|
|
3101
|
+
this.figure.classList.remove("asiyst-compact-launcher");
|
|
3102
|
+
this.figure.style.width = "";
|
|
3103
|
+
this.figure.style.height = "";
|
|
3104
|
+
this.figure.style.background = "transparent";
|
|
3105
|
+
}
|
|
3106
|
+
if (this.nameTagEl) {
|
|
3107
|
+
this.nameTagEl.style.display = this.isAssetLoadedFlag ? "inline-flex" : "none";
|
|
3108
|
+
}
|
|
3109
|
+
if (this.chatActionBtn) {
|
|
3110
|
+
this.chatActionBtn.style.display = this.isAssetLoadedFlag && !this.isPanelOpen ? "inline-flex" : "none";
|
|
3111
|
+
}
|
|
3112
|
+
if (!this.isAssetLoadedFlag && this.viewport) {
|
|
3113
|
+
if (this.renderState === "error") {
|
|
3114
|
+
this.renderFallback(true);
|
|
3115
|
+
} else {
|
|
3116
|
+
this.viewport.replaceChildren();
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
} else {
|
|
2755
3120
|
if (this.figure) {
|
|
2756
3121
|
this.figure.classList.remove("asiyst-3d-active");
|
|
3122
|
+
this.figure.classList.add("asiyst-compact-launcher");
|
|
2757
3123
|
this.figure.style.width = `${config.size}px`;
|
|
2758
3124
|
this.figure.style.height = `${config.size}px`;
|
|
2759
3125
|
this.figure.style.background = this.accentColor;
|
|
2760
3126
|
}
|
|
3127
|
+
if (this.nameTagEl) {
|
|
3128
|
+
this.nameTagEl.style.display = "none";
|
|
3129
|
+
}
|
|
2761
3130
|
if (this.chatActionBtn) {
|
|
2762
3131
|
this.chatActionBtn.style.display = "none";
|
|
2763
3132
|
}
|
|
2764
|
-
if (this.viewport) {
|
|
3133
|
+
if (this.viewport && !this.isAssetLoadedFlag) {
|
|
2765
3134
|
this.renderFallback();
|
|
2766
3135
|
}
|
|
2767
|
-
} else {
|
|
2768
|
-
if (this.figure) {
|
|
2769
|
-
this.figure.classList.add("asiyst-3d-active");
|
|
2770
|
-
}
|
|
2771
|
-
if (this.chatActionBtn) {
|
|
2772
|
-
this.chatActionBtn.style.display = this.isPanelOpen ? "none" : "inline-flex";
|
|
2773
|
-
}
|
|
2774
3136
|
}
|
|
2775
3137
|
}
|
|
2776
3138
|
setPanelOpen(open) {
|
|
@@ -2789,13 +3151,27 @@ var CssAvatarRenderer = class {
|
|
|
2789
3151
|
return false;
|
|
2790
3152
|
}
|
|
2791
3153
|
this.activeAssetUrl = assetUrl;
|
|
3154
|
+
this.has3dAssetConfigured = true;
|
|
2792
3155
|
this.renderState = "loading";
|
|
2793
3156
|
this.isFallbackFlag = false;
|
|
2794
3157
|
this.lastErrorMessage = void 0;
|
|
2795
3158
|
if (this.figure) {
|
|
2796
3159
|
this.figure.setAttribute("data-state", "loading");
|
|
3160
|
+
this.figure.classList.add("asiyst-3d-active");
|
|
3161
|
+
this.figure.classList.remove("asiyst-compact-launcher");
|
|
3162
|
+
this.figure.style.width = "";
|
|
3163
|
+
this.figure.style.height = "";
|
|
3164
|
+
this.figure.style.background = "transparent";
|
|
3165
|
+
}
|
|
3166
|
+
if (this.nameTagEl) {
|
|
3167
|
+
this.nameTagEl.style.display = "none";
|
|
3168
|
+
}
|
|
3169
|
+
if (this.chatActionBtn) {
|
|
3170
|
+
this.chatActionBtn.style.display = "none";
|
|
3171
|
+
}
|
|
3172
|
+
if (this.viewport) {
|
|
3173
|
+
this.renderLoader();
|
|
2797
3174
|
}
|
|
2798
|
-
this.renderLoader();
|
|
2799
3175
|
try {
|
|
2800
3176
|
const asset = await this.assetLoader.load(assetUrl, { timeoutMs: 6e4 });
|
|
2801
3177
|
await this.renderLoadedAsset(asset, config);
|
|
@@ -2806,10 +3182,14 @@ var CssAvatarRenderer = class {
|
|
|
2806
3182
|
if (this.figure) {
|
|
2807
3183
|
this.figure.setAttribute("data-state", "ready");
|
|
2808
3184
|
this.figure.classList.add("asiyst-3d-active");
|
|
3185
|
+
this.figure.classList.remove("asiyst-compact-launcher");
|
|
2809
3186
|
this.figure.style.width = "";
|
|
2810
3187
|
this.figure.style.height = "";
|
|
2811
3188
|
this.figure.style.background = "transparent";
|
|
2812
3189
|
}
|
|
3190
|
+
if (this.nameTagEl) {
|
|
3191
|
+
this.nameTagEl.style.display = "inline-flex";
|
|
3192
|
+
}
|
|
2813
3193
|
if (this.chatActionBtn) {
|
|
2814
3194
|
this.chatActionBtn.style.display = this.isPanelOpen ? "none" : "inline-flex";
|
|
2815
3195
|
}
|
|
@@ -2823,10 +3203,14 @@ var CssAvatarRenderer = class {
|
|
|
2823
3203
|
if (this.figure) {
|
|
2824
3204
|
this.figure.setAttribute("data-state", "error");
|
|
2825
3205
|
this.figure.classList.remove("asiyst-3d-active");
|
|
3206
|
+
this.figure.classList.add("asiyst-compact-launcher");
|
|
2826
3207
|
this.figure.style.width = `${this.size}px`;
|
|
2827
3208
|
this.figure.style.height = `${this.size}px`;
|
|
2828
3209
|
this.figure.style.background = this.accentColor;
|
|
2829
3210
|
}
|
|
3211
|
+
if (this.nameTagEl) {
|
|
3212
|
+
this.nameTagEl.style.display = "none";
|
|
3213
|
+
}
|
|
2830
3214
|
if (this.chatActionBtn) {
|
|
2831
3215
|
this.chatActionBtn.style.display = "none";
|
|
2832
3216
|
}
|
|
@@ -2838,10 +3222,13 @@ var CssAvatarRenderer = class {
|
|
|
2838
3222
|
if (!this.viewport) return;
|
|
2839
3223
|
this.viewport.replaceChildren();
|
|
2840
3224
|
const doc = this.viewport.ownerDocument;
|
|
3225
|
+
const container = doc.createElement("div");
|
|
3226
|
+
container.className = "asiyst-avatar-loading-silhouette";
|
|
2841
3227
|
const loader = doc.createElement("div");
|
|
2842
3228
|
loader.className = "asiyst-avatar-loader";
|
|
2843
3229
|
loader.setAttribute("aria-label", `Loading ${this.avatarName}`);
|
|
2844
|
-
|
|
3230
|
+
container.appendChild(loader);
|
|
3231
|
+
this.viewport.appendChild(container);
|
|
2845
3232
|
}
|
|
2846
3233
|
async renderLoadedAsset(asset, config) {
|
|
2847
3234
|
if (!this.viewport) return;
|
|
@@ -2947,12 +3334,15 @@ var CssAvatarRenderer = class {
|
|
|
2947
3334
|
renderSafeText(this.bubble, text);
|
|
2948
3335
|
}
|
|
2949
3336
|
getSize() {
|
|
2950
|
-
if (this.isAssetLoadedFlag
|
|
3337
|
+
if (this.isAssetLoadedFlag || this.has3dAssetConfigured) {
|
|
2951
3338
|
const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
|
|
2952
3339
|
return { width: isMobile ? 180 : 240, height: isMobile ? 390 : 490 };
|
|
2953
3340
|
}
|
|
2954
3341
|
return { width: this.size, height: this.size + 28 };
|
|
2955
3342
|
}
|
|
3343
|
+
playAnimation(nameOrIntent, loopMode) {
|
|
3344
|
+
return this.fbxRenderer?.playAnimation(nameOrIntent, loopMode) ?? false;
|
|
3345
|
+
}
|
|
2956
3346
|
setHidden(hidden) {
|
|
2957
3347
|
this.hidden = hidden;
|
|
2958
3348
|
if (this.root) {
|
|
@@ -4230,6 +4620,9 @@ var AsiystRuntime = class {
|
|
|
4230
4620
|
}) : void 0;
|
|
4231
4621
|
this.cloud = new CloudClient(transport, options.projectId, options.publicKey, runtimeAuth, this.visitorSessionId, options.avatarId);
|
|
4232
4622
|
this.config = new ConfigManager(options, this.cloud, this.events);
|
|
4623
|
+
this.config.onConfigUpdated = (newConfig, prevConfig) => {
|
|
4624
|
+
void this.applyUpdatedConfig(newConfig, prevConfig);
|
|
4625
|
+
};
|
|
4233
4626
|
this.analytics = new Analytics(options.projectId, this.cloud);
|
|
4234
4627
|
this.host = new HostRoot(doc);
|
|
4235
4628
|
this.resolver = new TargetResolver(
|
|
@@ -4278,7 +4671,6 @@ var AsiystRuntime = class {
|
|
|
4278
4671
|
this.movement.start();
|
|
4279
4672
|
this.analytics.start();
|
|
4280
4673
|
this.rescan();
|
|
4281
|
-
this.avatar.show();
|
|
4282
4674
|
const figure = this.renderer.getFigure();
|
|
4283
4675
|
if (figure) {
|
|
4284
4676
|
this.figureClickListener = () => this.open();
|
|
@@ -4303,7 +4695,7 @@ var AsiystRuntime = class {
|
|
|
4303
4695
|
return;
|
|
4304
4696
|
}
|
|
4305
4697
|
this.avatar.applyConfig(cfg);
|
|
4306
|
-
this.
|
|
4698
|
+
this.movement.goToAnchor();
|
|
4307
4699
|
this.lifecycle.emit("sdk.verification_started", {
|
|
4308
4700
|
projectId: this.options.projectId,
|
|
4309
4701
|
origin: window.location.origin,
|
|
@@ -4311,10 +4703,15 @@ var AsiystRuntime = class {
|
|
|
4311
4703
|
installationId: this.installationId,
|
|
4312
4704
|
sdkVersion: SDK_VERSION
|
|
4313
4705
|
});
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4706
|
+
void (async () => {
|
|
4707
|
+
try {
|
|
4708
|
+
await this.registerInstallation();
|
|
4709
|
+
await this.sendHeartbeat();
|
|
4710
|
+
const doc = this.host.host.ownerDocument;
|
|
4711
|
+
this.startHeartbeatScheduler(doc);
|
|
4712
|
+
} catch {
|
|
4713
|
+
}
|
|
4714
|
+
})();
|
|
4318
4715
|
this.events.emit("asiyst:ready", { projectId: this.options.projectId, configVersion: cfg.version });
|
|
4319
4716
|
void this.cloud.sendTelemetryEvent("avatar_runtime_initialized", {
|
|
4320
4717
|
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
@@ -4323,73 +4720,154 @@ var AsiystRuntime = class {
|
|
|
4323
4720
|
});
|
|
4324
4721
|
const assetTarget = cfg.assetUrl ?? cfg.thumbnailUrl;
|
|
4325
4722
|
if (assetTarget) {
|
|
4326
|
-
this.events.emit("asiyst:avatar:loading", {
|
|
4327
|
-
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4328
|
-
assetUrl: assetTarget
|
|
4329
|
-
});
|
|
4330
|
-
void this.cloud.sendTelemetryEvent("avatar_asset_loading_started", {
|
|
4331
|
-
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4332
|
-
assetUrl: assetTarget
|
|
4333
|
-
});
|
|
4334
4723
|
try {
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4724
|
+
await this.loadAvatarAsset(cfg, assetTarget);
|
|
4725
|
+
} finally {
|
|
4726
|
+
this.avatar.show();
|
|
4727
|
+
this.movement.goToAnchor();
|
|
4728
|
+
}
|
|
4729
|
+
} else {
|
|
4730
|
+
this.avatar.show();
|
|
4731
|
+
this.movement.goToAnchor();
|
|
4732
|
+
}
|
|
4733
|
+
this.startConfigRevalidationScheduler();
|
|
4734
|
+
}
|
|
4735
|
+
async loadAvatarAsset(cfg, assetTarget) {
|
|
4736
|
+
this.events.emit("asiyst:avatar:loading", {
|
|
4737
|
+
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4738
|
+
assetUrl: assetTarget
|
|
4739
|
+
});
|
|
4740
|
+
void this.cloud.sendTelemetryEvent("avatar_asset_loading_started", {
|
|
4741
|
+
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4742
|
+
assetUrl: assetTarget
|
|
4743
|
+
});
|
|
4744
|
+
try {
|
|
4745
|
+
const loaded = await this.renderer.loadAsset(cfg);
|
|
4746
|
+
if (loaded) {
|
|
4747
|
+
this.movement.goToAnchor();
|
|
4748
|
+
const format = this.renderer.getLoadedFormat();
|
|
4749
|
+
const assetUrl = this.renderer.getAssetUrl();
|
|
4750
|
+
const isRendered = this.renderer.isRendered();
|
|
4751
|
+
this.events.emit("asiyst:avatar:loaded", {
|
|
4752
|
+
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4753
|
+
assetUrl,
|
|
4754
|
+
format
|
|
4755
|
+
});
|
|
4756
|
+
void this.cloud.sendTelemetryEvent("avatar_asset_loaded", {
|
|
4757
|
+
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4758
|
+
avatarName: cfg.avatarName,
|
|
4759
|
+
assetUrl,
|
|
4760
|
+
format,
|
|
4761
|
+
publishedVersion: cfg.publishedVersion
|
|
4762
|
+
});
|
|
4763
|
+
if (isRendered) {
|
|
4764
|
+
this.events.emit("asiyst:avatar:rendered", {
|
|
4342
4765
|
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4343
|
-
assetUrl,
|
|
4344
4766
|
format
|
|
4345
4767
|
});
|
|
4346
|
-
void this.cloud.sendTelemetryEvent("
|
|
4768
|
+
void this.cloud.sendTelemetryEvent("avatar_rendered", {
|
|
4347
4769
|
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4348
4770
|
avatarName: cfg.avatarName,
|
|
4349
|
-
assetUrl,
|
|
4350
4771
|
format,
|
|
4351
4772
|
publishedVersion: cfg.publishedVersion
|
|
4352
4773
|
});
|
|
4353
|
-
if (isRendered) {
|
|
4354
|
-
this.events.emit("asiyst:avatar:rendered", {
|
|
4355
|
-
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4356
|
-
format
|
|
4357
|
-
});
|
|
4358
|
-
void this.cloud.sendTelemetryEvent("avatar_rendered", {
|
|
4359
|
-
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4360
|
-
avatarName: cfg.avatarName,
|
|
4361
|
-
format,
|
|
4362
|
-
publishedVersion: cfg.publishedVersion
|
|
4363
|
-
});
|
|
4364
|
-
}
|
|
4365
|
-
} else {
|
|
4366
|
-
const err = this.renderer.getLastError() ?? "Avatar asset loading failed";
|
|
4367
|
-
this.events.emit("asiyst:avatar:error", {
|
|
4368
|
-
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4369
|
-
error: err,
|
|
4370
|
-
stage: "renderer_init"
|
|
4371
|
-
});
|
|
4372
|
-
void this.cloud.sendTelemetryEvent("avatar_render_failed", {
|
|
4373
|
-
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4374
|
-
error: err,
|
|
4375
|
-
stage: "renderer_init"
|
|
4376
|
-
});
|
|
4377
4774
|
}
|
|
4378
|
-
|
|
4379
|
-
|
|
4775
|
+
return true;
|
|
4776
|
+
} else {
|
|
4777
|
+
const err = this.renderer.getLastError() ?? "Avatar asset loading failed";
|
|
4380
4778
|
this.events.emit("asiyst:avatar:error", {
|
|
4381
4779
|
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4382
4780
|
error: err,
|
|
4383
|
-
stage: "
|
|
4781
|
+
stage: "renderer_init"
|
|
4384
4782
|
});
|
|
4385
4783
|
void this.cloud.sendTelemetryEvent("avatar_render_failed", {
|
|
4386
4784
|
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4387
4785
|
error: err,
|
|
4388
|
-
stage: "
|
|
4786
|
+
stage: "renderer_init"
|
|
4389
4787
|
});
|
|
4788
|
+
return false;
|
|
4390
4789
|
}
|
|
4790
|
+
} catch (error) {
|
|
4791
|
+
const err = error instanceof Error ? error.message : "Avatar asset rendering failed";
|
|
4792
|
+
this.events.emit("asiyst:avatar:error", {
|
|
4793
|
+
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4794
|
+
error: err,
|
|
4795
|
+
stage: "asset_fetch"
|
|
4796
|
+
});
|
|
4797
|
+
void this.cloud.sendTelemetryEvent("avatar_render_failed", {
|
|
4798
|
+
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4799
|
+
error: err,
|
|
4800
|
+
stage: "asset_fetch"
|
|
4801
|
+
});
|
|
4802
|
+
return false;
|
|
4391
4803
|
}
|
|
4392
4804
|
}
|
|
4805
|
+
startConfigRevalidationScheduler() {
|
|
4806
|
+
if (this.configRevalidationTimer) {
|
|
4807
|
+
clearInterval(this.configRevalidationTimer);
|
|
4808
|
+
}
|
|
4809
|
+
this.configRevalidationTimer = setInterval(() => {
|
|
4810
|
+
if (!this.destroyed) {
|
|
4811
|
+
void this.config.refresh();
|
|
4812
|
+
}
|
|
4813
|
+
}, CONFIG_REVALIDATION_INTERVAL_MS);
|
|
4814
|
+
}
|
|
4815
|
+
async applyUpdatedConfig(newConfig, prevConfig) {
|
|
4816
|
+
if (this.destroyed) return;
|
|
4817
|
+
const domainCheck = validateWebsiteDomain(newConfig, window.location.href);
|
|
4818
|
+
if (!domainCheck.allowed) {
|
|
4819
|
+
this.connectionStatus = "disconnected";
|
|
4820
|
+
this.verificationStatus = "not_detected";
|
|
4821
|
+
this.events.emit("asiyst:error", {
|
|
4822
|
+
code: "domain_not_authorized",
|
|
4823
|
+
message: "This website is not authorized for the updated Asiyst configuration."
|
|
4824
|
+
});
|
|
4825
|
+
return;
|
|
4826
|
+
}
|
|
4827
|
+
const assetUrlChanged = newConfig.assetUrl !== prevConfig?.assetUrl || newConfig.thumbnailUrl !== prevConfig?.thumbnailUrl;
|
|
4828
|
+
if (assetUrlChanged && (newConfig.assetUrl || newConfig.thumbnailUrl)) {
|
|
4829
|
+
const target = newConfig.assetUrl ?? newConfig.thumbnailUrl ?? "";
|
|
4830
|
+
await this.loadAvatarAsset(newConfig, target);
|
|
4831
|
+
} else {
|
|
4832
|
+
const animationsChanged = JSON.stringify(newConfig.animations) !== JSON.stringify(prevConfig?.animations);
|
|
4833
|
+
if (animationsChanged && newConfig.animations && newConfig.animations.length > 0) {
|
|
4834
|
+
const fbxRenderer = this.renderer.getFbxRenderer();
|
|
4835
|
+
if (fbxRenderer) {
|
|
4836
|
+
void fbxRenderer.loadExternalAnimations(newConfig.animations);
|
|
4837
|
+
}
|
|
4838
|
+
}
|
|
4839
|
+
}
|
|
4840
|
+
this.avatar.applyConfig(newConfig);
|
|
4841
|
+
if (newConfig.position !== prevConfig?.position || newConfig.size !== prevConfig?.size) {
|
|
4842
|
+
this.movement.goToAnchor();
|
|
4843
|
+
}
|
|
4844
|
+
this.events.emit("asiyst:config:updated", {
|
|
4845
|
+
config: newConfig,
|
|
4846
|
+
previousVersion: prevConfig?.version
|
|
4847
|
+
});
|
|
4848
|
+
}
|
|
4849
|
+
async reloadConfig() {
|
|
4850
|
+
const updated = await this.config.refresh({ force: true });
|
|
4851
|
+
await this.applyUpdatedConfig(updated, this.config.get());
|
|
4852
|
+
return updated;
|
|
4853
|
+
}
|
|
4854
|
+
async updateConfig(partial) {
|
|
4855
|
+
const prev = this.config.get();
|
|
4856
|
+
const updated = this.config.applyLocalUpdate(partial);
|
|
4857
|
+
await this.applyUpdatedConfig(updated, prev);
|
|
4858
|
+
}
|
|
4859
|
+
playAnimation(nameOrIntent, options) {
|
|
4860
|
+
const played = this.renderer.playAnimation?.(nameOrIntent, options?.loopMode) ?? false;
|
|
4861
|
+
if (played) {
|
|
4862
|
+
this.events.emit("asiyst:animation:played", { name: nameOrIntent, intent: options?.loopMode });
|
|
4863
|
+
} else {
|
|
4864
|
+
this.events.emit("asiyst:animation:error", {
|
|
4865
|
+
name: nameOrIntent,
|
|
4866
|
+
error: `Animation "${nameOrIntent}" not found or incompatible with current skeleton`
|
|
4867
|
+
});
|
|
4868
|
+
}
|
|
4869
|
+
return played;
|
|
4870
|
+
}
|
|
4393
4871
|
getConnectionStatus() {
|
|
4394
4872
|
return this.connectionStatus;
|
|
4395
4873
|
}
|
|
@@ -4449,6 +4927,10 @@ var AsiystRuntime = class {
|
|
|
4449
4927
|
clearInterval(this.heartbeatTimer);
|
|
4450
4928
|
this.heartbeatTimer = void 0;
|
|
4451
4929
|
}
|
|
4930
|
+
if (this.configRevalidationTimer) {
|
|
4931
|
+
clearInterval(this.configRevalidationTimer);
|
|
4932
|
+
this.configRevalidationTimer = void 0;
|
|
4933
|
+
}
|
|
4452
4934
|
const doc = this.host.host.ownerDocument;
|
|
4453
4935
|
if (doc && this.visibilityListener) {
|
|
4454
4936
|
doc.removeEventListener("visibilitychange", this.visibilityListener);
|
|
@@ -4718,6 +5200,12 @@ var Asiyst = {
|
|
|
4718
5200
|
getConfig() {
|
|
4719
5201
|
return requireRuntime().getConfig();
|
|
4720
5202
|
},
|
|
5203
|
+
async reloadConfig() {
|
|
5204
|
+
return requireRuntime().reloadConfig();
|
|
5205
|
+
},
|
|
5206
|
+
async updateConfig(partial) {
|
|
5207
|
+
await requireRuntime().updateConfig(partial);
|
|
5208
|
+
},
|
|
4721
5209
|
getConnectionStatus() {
|
|
4722
5210
|
return requireRuntime().getConnectionStatus();
|
|
4723
5211
|
},
|
|
@@ -4752,6 +5240,9 @@ var Asiyst = {
|
|
|
4752
5240
|
celebrate() {
|
|
4753
5241
|
withIsolation(() => requireRuntime().avatarApi().celebrate());
|
|
4754
5242
|
},
|
|
5243
|
+
playAnimation(nameOrIntent, options) {
|
|
5244
|
+
return requireRuntime().playAnimation(nameOrIntent, options);
|
|
5245
|
+
},
|
|
4755
5246
|
setPosition(x, y) {
|
|
4756
5247
|
withIsolation(() => requireRuntime().avatarApi().setPosition(x, y));
|
|
4757
5248
|
}
|