@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.js
CHANGED
|
@@ -75,7 +75,7 @@ var ALL_ACTION_KINDS = [
|
|
|
75
75
|
// src/core/constants.ts
|
|
76
76
|
function resolveSdkVersion() {
|
|
77
77
|
{
|
|
78
|
-
return "0.1.
|
|
78
|
+
return "0.1.28";
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
var SDK_VERSION = resolveSdkVersion();
|
|
@@ -92,7 +92,8 @@ var VIEWPORT_HANDLER_THROTTLE_MS = 80;
|
|
|
92
92
|
var AVATAR_VIEWPORT_PADDING = 12;
|
|
93
93
|
var AVATAR_TARGET_GAP = 16;
|
|
94
94
|
var WEBSITE_MAP_TEXT_LIMIT = 80;
|
|
95
|
-
var CONFIG_CACHE_TTL_MS = 1e3 *
|
|
95
|
+
var CONFIG_CACHE_TTL_MS = 1e3 * 30;
|
|
96
|
+
var CONFIG_REVALIDATION_INTERVAL_MS = 3e4;
|
|
96
97
|
var HEARTBEAT_INTERVAL_MS = 45e3;
|
|
97
98
|
|
|
98
99
|
// src/security/selectors.ts
|
|
@@ -1038,7 +1039,7 @@ var ConfigCache = class {
|
|
|
1038
1039
|
constructor(storage) {
|
|
1039
1040
|
this.storage = storage;
|
|
1040
1041
|
}
|
|
1041
|
-
read(projectId) {
|
|
1042
|
+
read(projectId, ignoreTtl = false) {
|
|
1042
1043
|
const raw = this.storage.read("config");
|
|
1043
1044
|
if (!raw) {
|
|
1044
1045
|
return null;
|
|
@@ -1048,7 +1049,7 @@ var ConfigCache = class {
|
|
|
1048
1049
|
if (parsed.schemaVersion !== CONFIG_SCHEMA_VERSION || parsed.projectId !== projectId) {
|
|
1049
1050
|
return null;
|
|
1050
1051
|
}
|
|
1051
|
-
if (Date.now() - parsed.fetchedAt > CONFIG_CACHE_TTL_MS) {
|
|
1052
|
+
if (!ignoreTtl && Date.now() - parsed.fetchedAt > CONFIG_CACHE_TTL_MS) {
|
|
1052
1053
|
return null;
|
|
1053
1054
|
}
|
|
1054
1055
|
return normalizeProjectConfig(parsed.config);
|
|
@@ -1056,15 +1057,35 @@ var ConfigCache = class {
|
|
|
1056
1057
|
return null;
|
|
1057
1058
|
}
|
|
1058
1059
|
}
|
|
1059
|
-
|
|
1060
|
+
getEnvelope(projectId) {
|
|
1061
|
+
const raw = this.storage.read("config");
|
|
1062
|
+
if (!raw) {
|
|
1063
|
+
return null;
|
|
1064
|
+
}
|
|
1065
|
+
try {
|
|
1066
|
+
const parsed = JSON.parse(raw);
|
|
1067
|
+
if (parsed.schemaVersion !== CONFIG_SCHEMA_VERSION || parsed.projectId !== projectId) {
|
|
1068
|
+
return null;
|
|
1069
|
+
}
|
|
1070
|
+
return parsed;
|
|
1071
|
+
} catch {
|
|
1072
|
+
return null;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
write(projectId, config, meta) {
|
|
1060
1076
|
const envelope = {
|
|
1061
1077
|
schemaVersion: CONFIG_SCHEMA_VERSION,
|
|
1062
1078
|
projectId,
|
|
1063
1079
|
fetchedAt: Date.now(),
|
|
1080
|
+
etag: meta?.etag,
|
|
1081
|
+
revision: meta?.revision ?? config.version,
|
|
1064
1082
|
config
|
|
1065
1083
|
};
|
|
1066
1084
|
this.storage.write("config", JSON.stringify(envelope));
|
|
1067
1085
|
}
|
|
1086
|
+
clear() {
|
|
1087
|
+
this.storage.remove("config");
|
|
1088
|
+
}
|
|
1068
1089
|
};
|
|
1069
1090
|
|
|
1070
1091
|
// src/config/ConfigManager.ts
|
|
@@ -1073,6 +1094,7 @@ var ConfigManager = class {
|
|
|
1073
1094
|
this.options = options;
|
|
1074
1095
|
this.cloud = cloud;
|
|
1075
1096
|
this.events = events;
|
|
1097
|
+
this.inFlightRefresh = null;
|
|
1076
1098
|
const credentials = validateInitOptions(options);
|
|
1077
1099
|
this.options = { ...options, ...credentials };
|
|
1078
1100
|
this.cache = new ConfigCache(
|
|
@@ -1084,13 +1106,34 @@ var ConfigManager = class {
|
|
|
1084
1106
|
get() {
|
|
1085
1107
|
return this.current;
|
|
1086
1108
|
}
|
|
1087
|
-
async refresh() {
|
|
1109
|
+
async refresh(options) {
|
|
1110
|
+
if (this.inFlightRefresh) {
|
|
1111
|
+
return this.inFlightRefresh;
|
|
1112
|
+
}
|
|
1113
|
+
this.inFlightRefresh = this.executeRefresh(options);
|
|
1114
|
+
try {
|
|
1115
|
+
return await this.inFlightRefresh;
|
|
1116
|
+
} finally {
|
|
1117
|
+
this.inFlightRefresh = null;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
async executeRefresh(_options) {
|
|
1121
|
+
const prev = this.current;
|
|
1088
1122
|
try {
|
|
1089
1123
|
const remote = await this.cloud.fetchConfig();
|
|
1090
|
-
|
|
1091
|
-
this.
|
|
1124
|
+
const normalized = normalizeProjectConfig(remote);
|
|
1125
|
+
this.current = normalized;
|
|
1126
|
+
this.cache.write(this.options.projectId, normalized);
|
|
1127
|
+
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);
|
|
1128
|
+
if (hasChanged && this.onConfigUpdated) {
|
|
1129
|
+
this.onConfigUpdated(normalized, prev);
|
|
1130
|
+
}
|
|
1092
1131
|
return this.current;
|
|
1093
1132
|
} catch (error) {
|
|
1133
|
+
const lastKnownGood = this.cache.read(this.options.projectId, true);
|
|
1134
|
+
if (lastKnownGood) {
|
|
1135
|
+
this.current = lastKnownGood;
|
|
1136
|
+
}
|
|
1094
1137
|
this.events.emit("asiyst:error", {
|
|
1095
1138
|
code: "config_refresh_failed",
|
|
1096
1139
|
message: error instanceof Error ? error.message : "Failed to refresh configuration"
|
|
@@ -1098,6 +1141,18 @@ var ConfigManager = class {
|
|
|
1098
1141
|
return this.current;
|
|
1099
1142
|
}
|
|
1100
1143
|
}
|
|
1144
|
+
applyLocalUpdate(partial) {
|
|
1145
|
+
const prev = this.current;
|
|
1146
|
+
this.current = {
|
|
1147
|
+
...this.current,
|
|
1148
|
+
...partial
|
|
1149
|
+
};
|
|
1150
|
+
this.cache.write(this.options.projectId, this.current);
|
|
1151
|
+
if (this.onConfigUpdated) {
|
|
1152
|
+
this.onConfigUpdated(this.current, prev);
|
|
1153
|
+
}
|
|
1154
|
+
return this.current;
|
|
1155
|
+
}
|
|
1101
1156
|
localFallback() {
|
|
1102
1157
|
const base = fallbackConfig();
|
|
1103
1158
|
return {
|
|
@@ -1756,13 +1811,34 @@ var AssetLoader = class {
|
|
|
1756
1811
|
constructor() {
|
|
1757
1812
|
this.inFlightController = null;
|
|
1758
1813
|
this.createdObjectUrls = [];
|
|
1814
|
+
this.inFlightLoads = /* @__PURE__ */ new Map();
|
|
1815
|
+
this.cachedAssets = /* @__PURE__ */ new Map();
|
|
1759
1816
|
}
|
|
1760
1817
|
async load(assetUrl, options) {
|
|
1761
|
-
const startTime = Date.now();
|
|
1762
1818
|
const sanitizedUrl = sanitizeText(assetUrl.trim(), 2048);
|
|
1763
1819
|
if (!sanitizedUrl) {
|
|
1764
1820
|
throw new Error("Asset URL is required");
|
|
1765
1821
|
}
|
|
1822
|
+
const cached = this.cachedAssets.get(sanitizedUrl);
|
|
1823
|
+
if (cached) {
|
|
1824
|
+
return cached;
|
|
1825
|
+
}
|
|
1826
|
+
const inFlight = this.inFlightLoads.get(sanitizedUrl);
|
|
1827
|
+
if (inFlight) {
|
|
1828
|
+
return inFlight;
|
|
1829
|
+
}
|
|
1830
|
+
const loadPromise = this.performLoad(sanitizedUrl, options);
|
|
1831
|
+
this.inFlightLoads.set(sanitizedUrl, loadPromise);
|
|
1832
|
+
try {
|
|
1833
|
+
const asset = await loadPromise;
|
|
1834
|
+
this.cachedAssets.set(sanitizedUrl, asset);
|
|
1835
|
+
return asset;
|
|
1836
|
+
} finally {
|
|
1837
|
+
this.inFlightLoads.delete(sanitizedUrl);
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
async performLoad(sanitizedUrl, options) {
|
|
1841
|
+
const startTime = Date.now();
|
|
1766
1842
|
this.inFlightController = new AbortController();
|
|
1767
1843
|
const abortSignal = options?.signal ? anySignal([this.inFlightController.signal, options.signal]) : this.inFlightController.signal;
|
|
1768
1844
|
const timeoutMs = options?.timeoutMs ?? 6e4;
|
|
@@ -1805,6 +1881,9 @@ var AssetLoader = class {
|
|
|
1805
1881
|
throw new Error(`Avatar asset download failed: HTTP ${response.status} from ${sanitizedUrl}`);
|
|
1806
1882
|
}
|
|
1807
1883
|
const contentType = (response.headers.get("content-type") || "").toLowerCase();
|
|
1884
|
+
if (contentType.includes("text/html")) {
|
|
1885
|
+
throw new Error(`Avatar asset request returned HTML instead of 3D asset from ${sanitizedUrl}`);
|
|
1886
|
+
}
|
|
1808
1887
|
if (isJsonExtension || contentType.includes("application/json")) {
|
|
1809
1888
|
const text = await response.text();
|
|
1810
1889
|
let manifest;
|
|
@@ -1838,6 +1917,11 @@ var AssetLoader = class {
|
|
|
1838
1917
|
if (arrayBuffer.byteLength < 12) {
|
|
1839
1918
|
throw new Error("Avatar asset payload is too small to be a valid 3D container");
|
|
1840
1919
|
}
|
|
1920
|
+
const headerBytes = new Uint8Array(arrayBuffer, 0, Math.min(256, arrayBuffer.byteLength));
|
|
1921
|
+
const headerStr = new TextDecoder("utf-8", { fatal: false }).decode(headerBytes).trim();
|
|
1922
|
+
if (/^<!DOCTYPE\s+html/i.test(headerStr) || /^<html/i.test(headerStr)) {
|
|
1923
|
+
throw new Error(`Avatar asset payload contains HTML error page instead of binary 3D container from ${sanitizedUrl}`);
|
|
1924
|
+
}
|
|
1841
1925
|
if (isFbxExtension || this.isFbxBuffer(arrayBuffer) || !isGlbExtension && !this.isGlbBuffer(arrayBuffer)) {
|
|
1842
1926
|
const fbxHeader = this.parseFbxHeader(arrayBuffer);
|
|
1843
1927
|
const resourcePath = sanitizedUrl.includes("/") ? sanitizedUrl.substring(0, sanitizedUrl.lastIndexOf("/") + 1) : "";
|
|
@@ -2083,6 +2167,8 @@ var AssetLoader = class {
|
|
|
2083
2167
|
this.inFlightController.abort();
|
|
2084
2168
|
this.inFlightController = null;
|
|
2085
2169
|
}
|
|
2170
|
+
this.inFlightLoads.clear();
|
|
2171
|
+
this.cachedAssets.clear();
|
|
2086
2172
|
if (typeof URL !== "undefined" && typeof URL.revokeObjectURL === "function") {
|
|
2087
2173
|
for (const objUrl of this.createdObjectUrls) {
|
|
2088
2174
|
try {
|
|
@@ -2112,8 +2198,11 @@ var FbxRenderer = class {
|
|
|
2112
2198
|
this.scene = null;
|
|
2113
2199
|
this.camera = null;
|
|
2114
2200
|
this.modelRoot = null;
|
|
2201
|
+
this.rawObject = null;
|
|
2115
2202
|
this.mixer = null;
|
|
2116
2203
|
this.allAnimations = [];
|
|
2204
|
+
this.animationMetadataList = [];
|
|
2205
|
+
this.assetLoader = new AssetLoader();
|
|
2117
2206
|
this.currentAction = null;
|
|
2118
2207
|
this.animFrameId = null;
|
|
2119
2208
|
this.lastTime = 0;
|
|
@@ -2129,6 +2218,9 @@ var FbxRenderer = class {
|
|
|
2129
2218
|
this.canvas = doc.createElement("canvas");
|
|
2130
2219
|
this.canvas.className = "asiyst-avatar-canvas";
|
|
2131
2220
|
this.canvas.setAttribute("role", "presentation");
|
|
2221
|
+
this.canvas.style.opacity = "0";
|
|
2222
|
+
this.canvas.style.transition = "opacity 0.25s ease";
|
|
2223
|
+
this.canvas.style.background = "transparent";
|
|
2132
2224
|
const glContext = this.canvas.getContext("webgl2") || this.canvas.getContext("webgl");
|
|
2133
2225
|
if (!glContext) {
|
|
2134
2226
|
throw new Error("WebGLRenderingContext is not available or supported in this browser environment");
|
|
@@ -2148,6 +2240,7 @@ var FbxRenderer = class {
|
|
|
2148
2240
|
antialias: true,
|
|
2149
2241
|
powerPreference: "high-performance"
|
|
2150
2242
|
});
|
|
2243
|
+
this.renderer.setClearColor(0, 0);
|
|
2151
2244
|
this.renderer.setPixelRatio(Math.min(dpr, 2));
|
|
2152
2245
|
this.renderer.setSize(width, height, false);
|
|
2153
2246
|
this.renderer.outputColorSpace = THREE.SRGBColorSpace;
|
|
@@ -2242,20 +2335,34 @@ var FbxRenderer = class {
|
|
|
2242
2335
|
mesh.receiveShadow = true;
|
|
2243
2336
|
}
|
|
2244
2337
|
});
|
|
2245
|
-
this.
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2338
|
+
this.rawObject = rawObject;
|
|
2339
|
+
this.mixer = new THREE.AnimationMixer(rawObject);
|
|
2340
|
+
this.allAnimations = [...modelAnimations];
|
|
2341
|
+
const externalAnims = options?.config?.animations || options?.config?.avatar?.animations || [];
|
|
2342
|
+
if (externalAnims.length > 0) {
|
|
2343
|
+
try {
|
|
2344
|
+
await Promise.race([
|
|
2345
|
+
this.loadExternalAnimations(externalAnims, options?.config?.animation),
|
|
2346
|
+
new Promise((resolve) => setTimeout(resolve, 8e3))
|
|
2347
|
+
]);
|
|
2348
|
+
} catch (animErr) {
|
|
2349
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
2350
|
+
console.warn("[asiyst] External animation loading notice:", animErr);
|
|
2351
|
+
}
|
|
2252
2352
|
}
|
|
2253
2353
|
}
|
|
2354
|
+
this.startInitialIdleAnimation(options?.config);
|
|
2355
|
+
if (this.mixer) {
|
|
2356
|
+
this.mixer.update(0);
|
|
2357
|
+
}
|
|
2254
2358
|
container.replaceChildren();
|
|
2255
2359
|
container.appendChild(this.canvas);
|
|
2256
2360
|
try {
|
|
2257
2361
|
this.renderer.render(this.scene, this.camera);
|
|
2258
2362
|
this.initialRenderCompleted = true;
|
|
2363
|
+
if (this.canvas) {
|
|
2364
|
+
this.canvas.style.opacity = "1";
|
|
2365
|
+
}
|
|
2259
2366
|
} catch (renderErr) {
|
|
2260
2367
|
const msg = renderErr instanceof Error ? renderErr.message : String(renderErr);
|
|
2261
2368
|
throw new Error(`Initial FBX WebGL render failed: ${msg}`);
|
|
@@ -2270,7 +2377,7 @@ var FbxRenderer = class {
|
|
|
2270
2377
|
return {
|
|
2271
2378
|
meshCount,
|
|
2272
2379
|
vertexCount: totalVertices,
|
|
2273
|
-
animationCount:
|
|
2380
|
+
animationCount: this.allAnimations.length
|
|
2274
2381
|
};
|
|
2275
2382
|
}
|
|
2276
2383
|
setFacing(direction) {
|
|
@@ -2281,8 +2388,10 @@ var FbxRenderer = class {
|
|
|
2281
2388
|
}
|
|
2282
2389
|
setPose(pose) {
|
|
2283
2390
|
this.currentPose = pose;
|
|
2284
|
-
if (
|
|
2285
|
-
|
|
2391
|
+
if (this.playAnimation(pose)) {
|
|
2392
|
+
return;
|
|
2393
|
+
}
|
|
2394
|
+
if (this.mixer && this.allAnimations.length > 0) {
|
|
2286
2395
|
let targetClip;
|
|
2287
2396
|
if (pose === "speak") {
|
|
2288
2397
|
targetClip = this.allAnimations.find(
|
|
@@ -2293,7 +2402,7 @@ var FbxRenderer = class {
|
|
|
2293
2402
|
(c) => c.name.toLowerCase().includes("think")
|
|
2294
2403
|
);
|
|
2295
2404
|
} else {
|
|
2296
|
-
targetClip = this.allAnimations.find((c) => c.name.toLowerCase().includes("idle")) || this.allAnimations[0];
|
|
2405
|
+
targetClip = this.allAnimations.find((c) => c.name.toLowerCase().includes("idle")) || this.animationMetadataList[0]?.clip || this.allAnimations[0];
|
|
2297
2406
|
}
|
|
2298
2407
|
if (targetClip) {
|
|
2299
2408
|
const newAction = this.mixer.clipAction(targetClip);
|
|
@@ -2304,9 +2413,14 @@ var FbxRenderer = class {
|
|
|
2304
2413
|
}
|
|
2305
2414
|
this.currentAction = newAction;
|
|
2306
2415
|
return;
|
|
2416
|
+
} else if (!this.currentAction?.isRunning()) {
|
|
2417
|
+
this.currentAction?.play();
|
|
2418
|
+
return;
|
|
2307
2419
|
}
|
|
2420
|
+
return;
|
|
2308
2421
|
}
|
|
2309
2422
|
}
|
|
2423
|
+
if (!this.modelRoot) return;
|
|
2310
2424
|
switch (pose) {
|
|
2311
2425
|
case "point":
|
|
2312
2426
|
this.modelRoot.rotation.z = -0.15;
|
|
@@ -2332,6 +2446,209 @@ var FbxRenderer = class {
|
|
|
2332
2446
|
break;
|
|
2333
2447
|
}
|
|
2334
2448
|
}
|
|
2449
|
+
startInitialIdleAnimation(config) {
|
|
2450
|
+
if (!this.mixer) return false;
|
|
2451
|
+
const targetQuery = config?.animation?.trim();
|
|
2452
|
+
if (targetQuery && this.playAnimation(targetQuery)) {
|
|
2453
|
+
return true;
|
|
2454
|
+
}
|
|
2455
|
+
const idleByIntent = this.animationMetadataList.find(
|
|
2456
|
+
(m) => m.intent?.toLowerCase() === "idle"
|
|
2457
|
+
);
|
|
2458
|
+
if (idleByIntent && this.playAnimation(idleByIntent.id || idleByIntent.name)) {
|
|
2459
|
+
return true;
|
|
2460
|
+
}
|
|
2461
|
+
const idleByName = this.animationMetadataList.find(
|
|
2462
|
+
(m) => m.name.toLowerCase().includes("idle") || m.clipName && m.clipName.toLowerCase().includes("idle")
|
|
2463
|
+
);
|
|
2464
|
+
if (idleByName && this.playAnimation(idleByName.id || idleByName.name)) {
|
|
2465
|
+
return true;
|
|
2466
|
+
}
|
|
2467
|
+
const embeddedIdle = this.allAnimations.find(
|
|
2468
|
+
(c) => c.name.toLowerCase().includes("idle")
|
|
2469
|
+
);
|
|
2470
|
+
if (embeddedIdle) {
|
|
2471
|
+
const action = this.mixer.clipAction(embeddedIdle);
|
|
2472
|
+
if (this.currentAction !== action) {
|
|
2473
|
+
action.reset().fadeIn(0.25).play();
|
|
2474
|
+
if (this.currentAction) this.currentAction.fadeOut(0.25);
|
|
2475
|
+
this.currentAction = action;
|
|
2476
|
+
}
|
|
2477
|
+
return true;
|
|
2478
|
+
}
|
|
2479
|
+
if (this.animationMetadataList.length > 0) {
|
|
2480
|
+
const firstMeta = this.animationMetadataList[0];
|
|
2481
|
+
if (this.playAnimation(firstMeta.id || firstMeta.name)) {
|
|
2482
|
+
return true;
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
if (this.allAnimations.length > 0) {
|
|
2486
|
+
const firstClip = this.allAnimations[0];
|
|
2487
|
+
const action = this.mixer.clipAction(firstClip);
|
|
2488
|
+
if (this.currentAction !== action) {
|
|
2489
|
+
action.reset().fadeIn(0.25).play();
|
|
2490
|
+
if (this.currentAction) this.currentAction.fadeOut(0.25);
|
|
2491
|
+
this.currentAction = action;
|
|
2492
|
+
}
|
|
2493
|
+
return true;
|
|
2494
|
+
}
|
|
2495
|
+
return false;
|
|
2496
|
+
}
|
|
2497
|
+
async loadExternalAnimations(animations, targetAnimationName) {
|
|
2498
|
+
if (!this.rawObject || !this.mixer) return;
|
|
2499
|
+
for (const anim of animations) {
|
|
2500
|
+
if (!anim.assetUrl) continue;
|
|
2501
|
+
try {
|
|
2502
|
+
const loaded = await this.assetLoader.load(anim.assetUrl);
|
|
2503
|
+
let extractedClips = [];
|
|
2504
|
+
if (loaded.format === "fbx") {
|
|
2505
|
+
const loader = new FBXLoader();
|
|
2506
|
+
if (loaded.resourcePath) {
|
|
2507
|
+
loader.setResourcePath(loaded.resourcePath);
|
|
2508
|
+
}
|
|
2509
|
+
const parsed = loader.parse(loaded.buffer, loaded.resourcePath || "");
|
|
2510
|
+
extractedClips = parsed.animations || [];
|
|
2511
|
+
} else if (loaded.format === "glb") {
|
|
2512
|
+
const loader = new GLTFLoader();
|
|
2513
|
+
const gltf = await new Promise((resolve, reject) => {
|
|
2514
|
+
const glbBuffer = loaded.bin.buffer.slice(
|
|
2515
|
+
loaded.bin.byteOffset,
|
|
2516
|
+
loaded.bin.byteOffset + loaded.bin.byteLength
|
|
2517
|
+
);
|
|
2518
|
+
loader.parse(glbBuffer, loaded.url, resolve, reject);
|
|
2519
|
+
});
|
|
2520
|
+
extractedClips = gltf.animations || [];
|
|
2521
|
+
}
|
|
2522
|
+
for (const rawClip of extractedClips) {
|
|
2523
|
+
const retargeted = this.retargetClip(rawClip, this.rawObject);
|
|
2524
|
+
if (!retargeted) continue;
|
|
2525
|
+
retargeted.name = anim.clipName || anim.name || rawClip.name;
|
|
2526
|
+
this.allAnimations.push(retargeted);
|
|
2527
|
+
this.animationMetadataList.push({
|
|
2528
|
+
id: anim.id,
|
|
2529
|
+
name: anim.name,
|
|
2530
|
+
intent: anim.intent,
|
|
2531
|
+
clipName: anim.clipName,
|
|
2532
|
+
loopMode: anim.loopMode,
|
|
2533
|
+
clip: retargeted
|
|
2534
|
+
});
|
|
2535
|
+
}
|
|
2536
|
+
} catch (err) {
|
|
2537
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
2538
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2539
|
+
console.warn(`[asiyst] Failed to load external animation "${anim.name}": ${msg}`);
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
if (this.currentPose === "idle" || targetAnimationName) {
|
|
2544
|
+
this.startInitialIdleAnimation({ animation: targetAnimationName });
|
|
2545
|
+
if (this.mixer) {
|
|
2546
|
+
this.mixer.update(0);
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
retargetClip(clip, targetObject) {
|
|
2551
|
+
const targetNodeNames = /* @__PURE__ */ new Set();
|
|
2552
|
+
const boneLookup = /* @__PURE__ */ new Map();
|
|
2553
|
+
const cleanBoneName = (name) => {
|
|
2554
|
+
return name.replace(/^.*[:|/]/, "").replace(/^(mixamorig\d*|bip01|armature|root)[:_ ]?/i, "").replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
|
|
2555
|
+
};
|
|
2556
|
+
targetObject.traverse((node) => {
|
|
2557
|
+
if (node.name) {
|
|
2558
|
+
targetNodeNames.add(node.name);
|
|
2559
|
+
const lower = node.name.toLowerCase();
|
|
2560
|
+
const simpleClean = node.name.replace(/^.*[:|/]/, "").toLowerCase();
|
|
2561
|
+
const stripped = cleanBoneName(node.name);
|
|
2562
|
+
if (!boneLookup.has(lower)) boneLookup.set(lower, node.name);
|
|
2563
|
+
if (!boneLookup.has(simpleClean)) boneLookup.set(simpleClean, node.name);
|
|
2564
|
+
if (stripped && !boneLookup.has(stripped)) boneLookup.set(stripped, node.name);
|
|
2565
|
+
}
|
|
2566
|
+
});
|
|
2567
|
+
const isRootOrHips = (name) => {
|
|
2568
|
+
const clean = cleanBoneName(name);
|
|
2569
|
+
return clean === "hips" || clean === "pelvis" || clean === "root";
|
|
2570
|
+
};
|
|
2571
|
+
const validTracks = [];
|
|
2572
|
+
for (const track of clip.tracks) {
|
|
2573
|
+
const dotIdx = track.name.lastIndexOf(".");
|
|
2574
|
+
if (dotIdx === -1) continue;
|
|
2575
|
+
const nodePart = track.name.substring(0, dotIdx);
|
|
2576
|
+
const propPart = track.name.substring(dotIdx);
|
|
2577
|
+
let matchedNodeName;
|
|
2578
|
+
if (targetNodeNames.has(nodePart)) {
|
|
2579
|
+
matchedNodeName = nodePart;
|
|
2580
|
+
} else {
|
|
2581
|
+
const lower = nodePart.toLowerCase();
|
|
2582
|
+
const simpleClean = nodePart.replace(/^.*[:|/]/, "").toLowerCase();
|
|
2583
|
+
const stripped = cleanBoneName(nodePart);
|
|
2584
|
+
matchedNodeName = boneLookup.get(lower) || boneLookup.get(simpleClean) || boneLookup.get(stripped);
|
|
2585
|
+
}
|
|
2586
|
+
if (matchedNodeName) {
|
|
2587
|
+
if (propPart.toLowerCase().startsWith(".position") && !isRootOrHips(matchedNodeName)) {
|
|
2588
|
+
continue;
|
|
2589
|
+
}
|
|
2590
|
+
if (matchedNodeName === nodePart) {
|
|
2591
|
+
validTracks.push(track);
|
|
2592
|
+
} else {
|
|
2593
|
+
const clonedTrack = track.clone();
|
|
2594
|
+
clonedTrack.name = `${matchedNodeName}${propPart}`;
|
|
2595
|
+
validTracks.push(clonedTrack);
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
if (validTracks.length === 0 || clip.duration <= 0) {
|
|
2600
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
2601
|
+
console.warn(`[asiyst] External animation "${clip.name}" has no compatible bone tracks for this avatar skeleton.`);
|
|
2602
|
+
}
|
|
2603
|
+
return null;
|
|
2604
|
+
}
|
|
2605
|
+
return new THREE.AnimationClip(clip.name, clip.duration, validTracks);
|
|
2606
|
+
}
|
|
2607
|
+
playAnimation(nameOrIntent, loopMode, crossFadeDuration = 0.25) {
|
|
2608
|
+
if (!this.mixer) return false;
|
|
2609
|
+
const query = nameOrIntent.trim().toLowerCase();
|
|
2610
|
+
if (!query) return false;
|
|
2611
|
+
let matched = this.animationMetadataList.find((m) => m.id && m.id.toLowerCase() === query);
|
|
2612
|
+
if (!matched) {
|
|
2613
|
+
matched = this.animationMetadataList.find((m) => m.intent && m.intent.toLowerCase() === query);
|
|
2614
|
+
}
|
|
2615
|
+
if (!matched) {
|
|
2616
|
+
matched = this.animationMetadataList.find((m) => m.name && m.name.toLowerCase() === query);
|
|
2617
|
+
}
|
|
2618
|
+
if (!matched) {
|
|
2619
|
+
matched = this.animationMetadataList.find((m) => m.clipName && m.clipName.toLowerCase() === query);
|
|
2620
|
+
}
|
|
2621
|
+
let clip = matched?.clip;
|
|
2622
|
+
if (!clip) {
|
|
2623
|
+
clip = this.allAnimations.find((c) => c.name.toLowerCase() === query);
|
|
2624
|
+
}
|
|
2625
|
+
if (!clip) {
|
|
2626
|
+
clip = this.allAnimations.find((c) => c.name.toLowerCase().includes(query));
|
|
2627
|
+
}
|
|
2628
|
+
if (!clip) {
|
|
2629
|
+
return false;
|
|
2630
|
+
}
|
|
2631
|
+
const action = this.mixer.clipAction(clip);
|
|
2632
|
+
const effectiveLoop = loopMode || matched?.loopMode || "repeat";
|
|
2633
|
+
if (effectiveLoop === "once") {
|
|
2634
|
+
action.setLoop(THREE.LoopOnce, 1);
|
|
2635
|
+
action.clampWhenFinished = true;
|
|
2636
|
+
} else if (effectiveLoop === "pingpong") {
|
|
2637
|
+
action.setLoop(THREE.LoopPingPong, Infinity);
|
|
2638
|
+
} else {
|
|
2639
|
+
action.setLoop(THREE.LoopRepeat, Infinity);
|
|
2640
|
+
}
|
|
2641
|
+
if (this.currentAction !== action) {
|
|
2642
|
+
action.reset().fadeIn(crossFadeDuration).play();
|
|
2643
|
+
if (this.currentAction) {
|
|
2644
|
+
this.currentAction.fadeOut(crossFadeDuration);
|
|
2645
|
+
}
|
|
2646
|
+
this.currentAction = action;
|
|
2647
|
+
} else if (!action.isRunning()) {
|
|
2648
|
+
action.reset().play();
|
|
2649
|
+
}
|
|
2650
|
+
return true;
|
|
2651
|
+
}
|
|
2335
2652
|
isRendered() {
|
|
2336
2653
|
return this.initialRenderCompleted;
|
|
2337
2654
|
}
|
|
@@ -2418,6 +2735,11 @@ var FbxRenderer = class {
|
|
|
2418
2735
|
this.canvas.remove();
|
|
2419
2736
|
this.canvas = null;
|
|
2420
2737
|
}
|
|
2738
|
+
this.assetLoader.destroy();
|
|
2739
|
+
this.animationMetadataList.length = 0;
|
|
2740
|
+
this.allAnimations = [];
|
|
2741
|
+
this.currentAction = null;
|
|
2742
|
+
this.rawObject = null;
|
|
2421
2743
|
this.camera = null;
|
|
2422
2744
|
this.modelRoot = null;
|
|
2423
2745
|
this.initialRenderCompleted = false;
|
|
@@ -2464,20 +2786,23 @@ var AVATAR_CSS = `
|
|
|
2464
2786
|
transition: left 420ms cubic-bezier(0.22, 1, 0.36, 1), top 420ms cubic-bezier(0.22, 1, 0.36, 1);
|
|
2465
2787
|
}
|
|
2466
2788
|
.asiyst-figure {
|
|
2467
|
-
border-radius: 28px;
|
|
2468
2789
|
display: grid;
|
|
2469
2790
|
place-items: center;
|
|
2470
|
-
color: #fff;
|
|
2471
|
-
font: 700 14px/1.2 system-ui, sans-serif;
|
|
2472
|
-
box-shadow: 0 10px 30px rgba(15, 23, 42, 0.28);
|
|
2473
2791
|
position: relative;
|
|
2474
|
-
overflow: hidden;
|
|
2475
2792
|
cursor: pointer;
|
|
2476
2793
|
border: none;
|
|
2477
2794
|
padding: 0;
|
|
2478
2795
|
outline: none;
|
|
2796
|
+
background: transparent;
|
|
2797
|
+
overflow: visible;
|
|
2798
|
+
}
|
|
2799
|
+
.asiyst-figure.asiyst-compact-launcher {
|
|
2800
|
+
border-radius: 28px;
|
|
2801
|
+
color: #fff;
|
|
2802
|
+
font: 700 14px/1.2 system-ui, sans-serif;
|
|
2803
|
+
box-shadow: 0 10px 30px rgba(15, 23, 42, 0.28);
|
|
2804
|
+
overflow: hidden;
|
|
2479
2805
|
background: #2563eb;
|
|
2480
|
-
transition: width 0.3s ease, height 0.3s ease, background 0.3s ease;
|
|
2481
2806
|
}
|
|
2482
2807
|
.asiyst-figure.asiyst-3d-active {
|
|
2483
2808
|
width: 240px !important;
|
|
@@ -2519,13 +2844,23 @@ var AVATAR_CSS = `
|
|
|
2519
2844
|
pointer-events: none;
|
|
2520
2845
|
}
|
|
2521
2846
|
.asiyst-avatar-loader {
|
|
2522
|
-
width:
|
|
2523
|
-
height:
|
|
2524
|
-
border: 3px solid rgba(
|
|
2525
|
-
border-top-color: #
|
|
2847
|
+
width: 34px;
|
|
2848
|
+
height: 34px;
|
|
2849
|
+
border: 3px solid rgba(37, 99, 235, 0.2);
|
|
2850
|
+
border-top-color: #2563eb;
|
|
2526
2851
|
border-radius: 50%;
|
|
2527
2852
|
animation: asiyst-spin 0.8s linear infinite;
|
|
2528
2853
|
}
|
|
2854
|
+
.asiyst-avatar-loading-silhouette {
|
|
2855
|
+
display: flex;
|
|
2856
|
+
flex-direction: column;
|
|
2857
|
+
align-items: center;
|
|
2858
|
+
justify-content: center;
|
|
2859
|
+
width: 100%;
|
|
2860
|
+
height: 100%;
|
|
2861
|
+
min-height: 240px;
|
|
2862
|
+
pointer-events: none;
|
|
2863
|
+
}
|
|
2529
2864
|
@keyframes asiyst-spin {
|
|
2530
2865
|
to { transform: rotate(360deg); }
|
|
2531
2866
|
}
|
|
@@ -2634,18 +2969,19 @@ var AVATAR_CSS = `
|
|
|
2634
2969
|
var CssAvatarRenderer = class {
|
|
2635
2970
|
constructor() {
|
|
2636
2971
|
this.size = 96;
|
|
2637
|
-
this.hidden =
|
|
2972
|
+
this.hidden = true;
|
|
2638
2973
|
this.facing = "right";
|
|
2639
2974
|
this.pose = "idle";
|
|
2640
2975
|
this.accentColor = "#2563eb";
|
|
2641
2976
|
this.avatarName = "Asiyst";
|
|
2642
2977
|
this.isPanelOpen = false;
|
|
2978
|
+
this.has3dAssetConfigured = false;
|
|
2643
2979
|
// Asset loading & rendering state
|
|
2644
2980
|
this.assetLoader = new AssetLoader();
|
|
2645
2981
|
this.fbxRenderer = null;
|
|
2646
2982
|
this.renderState = "idle";
|
|
2647
2983
|
this.isAssetLoadedFlag = false;
|
|
2648
|
-
this.isFallbackFlag =
|
|
2984
|
+
this.isFallbackFlag = false;
|
|
2649
2985
|
}
|
|
2650
2986
|
mount(container, config) {
|
|
2651
2987
|
const doc = container.ownerDocument;
|
|
@@ -2655,6 +2991,9 @@ var CssAvatarRenderer = class {
|
|
|
2655
2991
|
this.root = doc.createElement("div");
|
|
2656
2992
|
this.root.className = "asiyst-avatar asiyst-animate";
|
|
2657
2993
|
this.root.setAttribute("role", "img");
|
|
2994
|
+
if (this.hidden) {
|
|
2995
|
+
this.root.style.display = "none";
|
|
2996
|
+
}
|
|
2658
2997
|
this.nameTagEl = doc.createElement("div");
|
|
2659
2998
|
this.nameTagEl.className = "asiyst-name-tag";
|
|
2660
2999
|
const sparkle = doc.createElement("span");
|
|
@@ -2717,6 +3056,11 @@ var CssAvatarRenderer = class {
|
|
|
2717
3056
|
this.size = config.size;
|
|
2718
3057
|
this.accentColor = config.theme.accent ?? "#2563eb";
|
|
2719
3058
|
this.avatarName = config.avatarName;
|
|
3059
|
+
const has3dAsset = Boolean(config.assetUrl || config.thumbnailUrl || config.avatarId);
|
|
3060
|
+
this.has3dAssetConfigured = has3dAsset;
|
|
3061
|
+
if (config.assetUrl || config.thumbnailUrl) {
|
|
3062
|
+
this.activeAssetUrl = config.assetUrl ?? config.thumbnailUrl ?? void 0;
|
|
3063
|
+
}
|
|
2720
3064
|
if (this.nameTextEl) {
|
|
2721
3065
|
renderSafeText(this.nameTextEl, config.avatarName);
|
|
2722
3066
|
}
|
|
@@ -2729,26 +3073,44 @@ var CssAvatarRenderer = class {
|
|
|
2729
3073
|
if (this.root) {
|
|
2730
3074
|
this.root.setAttribute("aria-label", config.avatarName);
|
|
2731
3075
|
}
|
|
2732
|
-
if (
|
|
3076
|
+
if (has3dAsset) {
|
|
3077
|
+
if (this.figure) {
|
|
3078
|
+
this.figure.classList.add("asiyst-3d-active");
|
|
3079
|
+
this.figure.classList.remove("asiyst-compact-launcher");
|
|
3080
|
+
this.figure.style.width = "";
|
|
3081
|
+
this.figure.style.height = "";
|
|
3082
|
+
this.figure.style.background = "transparent";
|
|
3083
|
+
}
|
|
3084
|
+
if (this.nameTagEl) {
|
|
3085
|
+
this.nameTagEl.style.display = this.isAssetLoadedFlag ? "inline-flex" : "none";
|
|
3086
|
+
}
|
|
3087
|
+
if (this.chatActionBtn) {
|
|
3088
|
+
this.chatActionBtn.style.display = this.isAssetLoadedFlag && !this.isPanelOpen ? "inline-flex" : "none";
|
|
3089
|
+
}
|
|
3090
|
+
if (!this.isAssetLoadedFlag && this.viewport) {
|
|
3091
|
+
if (this.renderState === "error") {
|
|
3092
|
+
this.renderFallback(true);
|
|
3093
|
+
} else {
|
|
3094
|
+
this.viewport.replaceChildren();
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
} else {
|
|
2733
3098
|
if (this.figure) {
|
|
2734
3099
|
this.figure.classList.remove("asiyst-3d-active");
|
|
3100
|
+
this.figure.classList.add("asiyst-compact-launcher");
|
|
2735
3101
|
this.figure.style.width = `${config.size}px`;
|
|
2736
3102
|
this.figure.style.height = `${config.size}px`;
|
|
2737
3103
|
this.figure.style.background = this.accentColor;
|
|
2738
3104
|
}
|
|
3105
|
+
if (this.nameTagEl) {
|
|
3106
|
+
this.nameTagEl.style.display = "none";
|
|
3107
|
+
}
|
|
2739
3108
|
if (this.chatActionBtn) {
|
|
2740
3109
|
this.chatActionBtn.style.display = "none";
|
|
2741
3110
|
}
|
|
2742
|
-
if (this.viewport) {
|
|
3111
|
+
if (this.viewport && !this.isAssetLoadedFlag) {
|
|
2743
3112
|
this.renderFallback();
|
|
2744
3113
|
}
|
|
2745
|
-
} else {
|
|
2746
|
-
if (this.figure) {
|
|
2747
|
-
this.figure.classList.add("asiyst-3d-active");
|
|
2748
|
-
}
|
|
2749
|
-
if (this.chatActionBtn) {
|
|
2750
|
-
this.chatActionBtn.style.display = this.isPanelOpen ? "none" : "inline-flex";
|
|
2751
|
-
}
|
|
2752
3114
|
}
|
|
2753
3115
|
}
|
|
2754
3116
|
setPanelOpen(open) {
|
|
@@ -2767,13 +3129,27 @@ var CssAvatarRenderer = class {
|
|
|
2767
3129
|
return false;
|
|
2768
3130
|
}
|
|
2769
3131
|
this.activeAssetUrl = assetUrl;
|
|
3132
|
+
this.has3dAssetConfigured = true;
|
|
2770
3133
|
this.renderState = "loading";
|
|
2771
3134
|
this.isFallbackFlag = false;
|
|
2772
3135
|
this.lastErrorMessage = void 0;
|
|
2773
3136
|
if (this.figure) {
|
|
2774
3137
|
this.figure.setAttribute("data-state", "loading");
|
|
3138
|
+
this.figure.classList.add("asiyst-3d-active");
|
|
3139
|
+
this.figure.classList.remove("asiyst-compact-launcher");
|
|
3140
|
+
this.figure.style.width = "";
|
|
3141
|
+
this.figure.style.height = "";
|
|
3142
|
+
this.figure.style.background = "transparent";
|
|
3143
|
+
}
|
|
3144
|
+
if (this.nameTagEl) {
|
|
3145
|
+
this.nameTagEl.style.display = "none";
|
|
3146
|
+
}
|
|
3147
|
+
if (this.chatActionBtn) {
|
|
3148
|
+
this.chatActionBtn.style.display = "none";
|
|
3149
|
+
}
|
|
3150
|
+
if (this.viewport) {
|
|
3151
|
+
this.renderLoader();
|
|
2775
3152
|
}
|
|
2776
|
-
this.renderLoader();
|
|
2777
3153
|
try {
|
|
2778
3154
|
const asset = await this.assetLoader.load(assetUrl, { timeoutMs: 6e4 });
|
|
2779
3155
|
await this.renderLoadedAsset(asset, config);
|
|
@@ -2784,10 +3160,14 @@ var CssAvatarRenderer = class {
|
|
|
2784
3160
|
if (this.figure) {
|
|
2785
3161
|
this.figure.setAttribute("data-state", "ready");
|
|
2786
3162
|
this.figure.classList.add("asiyst-3d-active");
|
|
3163
|
+
this.figure.classList.remove("asiyst-compact-launcher");
|
|
2787
3164
|
this.figure.style.width = "";
|
|
2788
3165
|
this.figure.style.height = "";
|
|
2789
3166
|
this.figure.style.background = "transparent";
|
|
2790
3167
|
}
|
|
3168
|
+
if (this.nameTagEl) {
|
|
3169
|
+
this.nameTagEl.style.display = "inline-flex";
|
|
3170
|
+
}
|
|
2791
3171
|
if (this.chatActionBtn) {
|
|
2792
3172
|
this.chatActionBtn.style.display = this.isPanelOpen ? "none" : "inline-flex";
|
|
2793
3173
|
}
|
|
@@ -2801,10 +3181,14 @@ var CssAvatarRenderer = class {
|
|
|
2801
3181
|
if (this.figure) {
|
|
2802
3182
|
this.figure.setAttribute("data-state", "error");
|
|
2803
3183
|
this.figure.classList.remove("asiyst-3d-active");
|
|
3184
|
+
this.figure.classList.add("asiyst-compact-launcher");
|
|
2804
3185
|
this.figure.style.width = `${this.size}px`;
|
|
2805
3186
|
this.figure.style.height = `${this.size}px`;
|
|
2806
3187
|
this.figure.style.background = this.accentColor;
|
|
2807
3188
|
}
|
|
3189
|
+
if (this.nameTagEl) {
|
|
3190
|
+
this.nameTagEl.style.display = "none";
|
|
3191
|
+
}
|
|
2808
3192
|
if (this.chatActionBtn) {
|
|
2809
3193
|
this.chatActionBtn.style.display = "none";
|
|
2810
3194
|
}
|
|
@@ -2816,10 +3200,13 @@ var CssAvatarRenderer = class {
|
|
|
2816
3200
|
if (!this.viewport) return;
|
|
2817
3201
|
this.viewport.replaceChildren();
|
|
2818
3202
|
const doc = this.viewport.ownerDocument;
|
|
3203
|
+
const container = doc.createElement("div");
|
|
3204
|
+
container.className = "asiyst-avatar-loading-silhouette";
|
|
2819
3205
|
const loader = doc.createElement("div");
|
|
2820
3206
|
loader.className = "asiyst-avatar-loader";
|
|
2821
3207
|
loader.setAttribute("aria-label", `Loading ${this.avatarName}`);
|
|
2822
|
-
|
|
3208
|
+
container.appendChild(loader);
|
|
3209
|
+
this.viewport.appendChild(container);
|
|
2823
3210
|
}
|
|
2824
3211
|
async renderLoadedAsset(asset, config) {
|
|
2825
3212
|
if (!this.viewport) return;
|
|
@@ -2925,12 +3312,15 @@ var CssAvatarRenderer = class {
|
|
|
2925
3312
|
renderSafeText(this.bubble, text);
|
|
2926
3313
|
}
|
|
2927
3314
|
getSize() {
|
|
2928
|
-
if (this.isAssetLoadedFlag
|
|
3315
|
+
if (this.isAssetLoadedFlag || this.has3dAssetConfigured) {
|
|
2929
3316
|
const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
|
|
2930
3317
|
return { width: isMobile ? 180 : 240, height: isMobile ? 390 : 490 };
|
|
2931
3318
|
}
|
|
2932
3319
|
return { width: this.size, height: this.size + 28 };
|
|
2933
3320
|
}
|
|
3321
|
+
playAnimation(nameOrIntent, loopMode) {
|
|
3322
|
+
return this.fbxRenderer?.playAnimation(nameOrIntent, loopMode) ?? false;
|
|
3323
|
+
}
|
|
2934
3324
|
setHidden(hidden) {
|
|
2935
3325
|
this.hidden = hidden;
|
|
2936
3326
|
if (this.root) {
|
|
@@ -4208,6 +4598,9 @@ var AsiystRuntime = class {
|
|
|
4208
4598
|
}) : void 0;
|
|
4209
4599
|
this.cloud = new CloudClient(transport, options.projectId, options.publicKey, runtimeAuth, this.visitorSessionId, options.avatarId);
|
|
4210
4600
|
this.config = new ConfigManager(options, this.cloud, this.events);
|
|
4601
|
+
this.config.onConfigUpdated = (newConfig, prevConfig) => {
|
|
4602
|
+
void this.applyUpdatedConfig(newConfig, prevConfig);
|
|
4603
|
+
};
|
|
4211
4604
|
this.analytics = new Analytics(options.projectId, this.cloud);
|
|
4212
4605
|
this.host = new HostRoot(doc);
|
|
4213
4606
|
this.resolver = new TargetResolver(
|
|
@@ -4256,7 +4649,6 @@ var AsiystRuntime = class {
|
|
|
4256
4649
|
this.movement.start();
|
|
4257
4650
|
this.analytics.start();
|
|
4258
4651
|
this.rescan();
|
|
4259
|
-
this.avatar.show();
|
|
4260
4652
|
const figure = this.renderer.getFigure();
|
|
4261
4653
|
if (figure) {
|
|
4262
4654
|
this.figureClickListener = () => this.open();
|
|
@@ -4281,7 +4673,7 @@ var AsiystRuntime = class {
|
|
|
4281
4673
|
return;
|
|
4282
4674
|
}
|
|
4283
4675
|
this.avatar.applyConfig(cfg);
|
|
4284
|
-
this.
|
|
4676
|
+
this.movement.goToAnchor();
|
|
4285
4677
|
this.lifecycle.emit("sdk.verification_started", {
|
|
4286
4678
|
projectId: this.options.projectId,
|
|
4287
4679
|
origin: window.location.origin,
|
|
@@ -4289,10 +4681,15 @@ var AsiystRuntime = class {
|
|
|
4289
4681
|
installationId: this.installationId,
|
|
4290
4682
|
sdkVersion: SDK_VERSION
|
|
4291
4683
|
});
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4684
|
+
void (async () => {
|
|
4685
|
+
try {
|
|
4686
|
+
await this.registerInstallation();
|
|
4687
|
+
await this.sendHeartbeat();
|
|
4688
|
+
const doc = this.host.host.ownerDocument;
|
|
4689
|
+
this.startHeartbeatScheduler(doc);
|
|
4690
|
+
} catch {
|
|
4691
|
+
}
|
|
4692
|
+
})();
|
|
4296
4693
|
this.events.emit("asiyst:ready", { projectId: this.options.projectId, configVersion: cfg.version });
|
|
4297
4694
|
void this.cloud.sendTelemetryEvent("avatar_runtime_initialized", {
|
|
4298
4695
|
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
@@ -4301,73 +4698,154 @@ var AsiystRuntime = class {
|
|
|
4301
4698
|
});
|
|
4302
4699
|
const assetTarget = cfg.assetUrl ?? cfg.thumbnailUrl;
|
|
4303
4700
|
if (assetTarget) {
|
|
4304
|
-
this.events.emit("asiyst:avatar:loading", {
|
|
4305
|
-
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4306
|
-
assetUrl: assetTarget
|
|
4307
|
-
});
|
|
4308
|
-
void this.cloud.sendTelemetryEvent("avatar_asset_loading_started", {
|
|
4309
|
-
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4310
|
-
assetUrl: assetTarget
|
|
4311
|
-
});
|
|
4312
4701
|
try {
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4702
|
+
await this.loadAvatarAsset(cfg, assetTarget);
|
|
4703
|
+
} finally {
|
|
4704
|
+
this.avatar.show();
|
|
4705
|
+
this.movement.goToAnchor();
|
|
4706
|
+
}
|
|
4707
|
+
} else {
|
|
4708
|
+
this.avatar.show();
|
|
4709
|
+
this.movement.goToAnchor();
|
|
4710
|
+
}
|
|
4711
|
+
this.startConfigRevalidationScheduler();
|
|
4712
|
+
}
|
|
4713
|
+
async loadAvatarAsset(cfg, assetTarget) {
|
|
4714
|
+
this.events.emit("asiyst:avatar:loading", {
|
|
4715
|
+
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4716
|
+
assetUrl: assetTarget
|
|
4717
|
+
});
|
|
4718
|
+
void this.cloud.sendTelemetryEvent("avatar_asset_loading_started", {
|
|
4719
|
+
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4720
|
+
assetUrl: assetTarget
|
|
4721
|
+
});
|
|
4722
|
+
try {
|
|
4723
|
+
const loaded = await this.renderer.loadAsset(cfg);
|
|
4724
|
+
if (loaded) {
|
|
4725
|
+
this.movement.goToAnchor();
|
|
4726
|
+
const format = this.renderer.getLoadedFormat();
|
|
4727
|
+
const assetUrl = this.renderer.getAssetUrl();
|
|
4728
|
+
const isRendered = this.renderer.isRendered();
|
|
4729
|
+
this.events.emit("asiyst:avatar:loaded", {
|
|
4730
|
+
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4731
|
+
assetUrl,
|
|
4732
|
+
format
|
|
4733
|
+
});
|
|
4734
|
+
void this.cloud.sendTelemetryEvent("avatar_asset_loaded", {
|
|
4735
|
+
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4736
|
+
avatarName: cfg.avatarName,
|
|
4737
|
+
assetUrl,
|
|
4738
|
+
format,
|
|
4739
|
+
publishedVersion: cfg.publishedVersion
|
|
4740
|
+
});
|
|
4741
|
+
if (isRendered) {
|
|
4742
|
+
this.events.emit("asiyst:avatar:rendered", {
|
|
4320
4743
|
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4321
|
-
assetUrl,
|
|
4322
4744
|
format
|
|
4323
4745
|
});
|
|
4324
|
-
void this.cloud.sendTelemetryEvent("
|
|
4746
|
+
void this.cloud.sendTelemetryEvent("avatar_rendered", {
|
|
4325
4747
|
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4326
4748
|
avatarName: cfg.avatarName,
|
|
4327
|
-
assetUrl,
|
|
4328
4749
|
format,
|
|
4329
4750
|
publishedVersion: cfg.publishedVersion
|
|
4330
4751
|
});
|
|
4331
|
-
if (isRendered) {
|
|
4332
|
-
this.events.emit("asiyst:avatar:rendered", {
|
|
4333
|
-
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4334
|
-
format
|
|
4335
|
-
});
|
|
4336
|
-
void this.cloud.sendTelemetryEvent("avatar_rendered", {
|
|
4337
|
-
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4338
|
-
avatarName: cfg.avatarName,
|
|
4339
|
-
format,
|
|
4340
|
-
publishedVersion: cfg.publishedVersion
|
|
4341
|
-
});
|
|
4342
|
-
}
|
|
4343
|
-
} else {
|
|
4344
|
-
const err = this.renderer.getLastError() ?? "Avatar asset loading failed";
|
|
4345
|
-
this.events.emit("asiyst:avatar:error", {
|
|
4346
|
-
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4347
|
-
error: err,
|
|
4348
|
-
stage: "renderer_init"
|
|
4349
|
-
});
|
|
4350
|
-
void this.cloud.sendTelemetryEvent("avatar_render_failed", {
|
|
4351
|
-
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4352
|
-
error: err,
|
|
4353
|
-
stage: "renderer_init"
|
|
4354
|
-
});
|
|
4355
4752
|
}
|
|
4356
|
-
|
|
4357
|
-
|
|
4753
|
+
return true;
|
|
4754
|
+
} else {
|
|
4755
|
+
const err = this.renderer.getLastError() ?? "Avatar asset loading failed";
|
|
4358
4756
|
this.events.emit("asiyst:avatar:error", {
|
|
4359
4757
|
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4360
4758
|
error: err,
|
|
4361
|
-
stage: "
|
|
4759
|
+
stage: "renderer_init"
|
|
4362
4760
|
});
|
|
4363
4761
|
void this.cloud.sendTelemetryEvent("avatar_render_failed", {
|
|
4364
4762
|
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4365
4763
|
error: err,
|
|
4366
|
-
stage: "
|
|
4764
|
+
stage: "renderer_init"
|
|
4367
4765
|
});
|
|
4766
|
+
return false;
|
|
4368
4767
|
}
|
|
4768
|
+
} catch (error) {
|
|
4769
|
+
const err = error instanceof Error ? error.message : "Avatar asset rendering failed";
|
|
4770
|
+
this.events.emit("asiyst:avatar:error", {
|
|
4771
|
+
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4772
|
+
error: err,
|
|
4773
|
+
stage: "asset_fetch"
|
|
4774
|
+
});
|
|
4775
|
+
void this.cloud.sendTelemetryEvent("avatar_render_failed", {
|
|
4776
|
+
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4777
|
+
error: err,
|
|
4778
|
+
stage: "asset_fetch"
|
|
4779
|
+
});
|
|
4780
|
+
return false;
|
|
4369
4781
|
}
|
|
4370
4782
|
}
|
|
4783
|
+
startConfigRevalidationScheduler() {
|
|
4784
|
+
if (this.configRevalidationTimer) {
|
|
4785
|
+
clearInterval(this.configRevalidationTimer);
|
|
4786
|
+
}
|
|
4787
|
+
this.configRevalidationTimer = setInterval(() => {
|
|
4788
|
+
if (!this.destroyed) {
|
|
4789
|
+
void this.config.refresh();
|
|
4790
|
+
}
|
|
4791
|
+
}, CONFIG_REVALIDATION_INTERVAL_MS);
|
|
4792
|
+
}
|
|
4793
|
+
async applyUpdatedConfig(newConfig, prevConfig) {
|
|
4794
|
+
if (this.destroyed) return;
|
|
4795
|
+
const domainCheck = validateWebsiteDomain(newConfig, window.location.href);
|
|
4796
|
+
if (!domainCheck.allowed) {
|
|
4797
|
+
this.connectionStatus = "disconnected";
|
|
4798
|
+
this.verificationStatus = "not_detected";
|
|
4799
|
+
this.events.emit("asiyst:error", {
|
|
4800
|
+
code: "domain_not_authorized",
|
|
4801
|
+
message: "This website is not authorized for the updated Asiyst configuration."
|
|
4802
|
+
});
|
|
4803
|
+
return;
|
|
4804
|
+
}
|
|
4805
|
+
const assetUrlChanged = newConfig.assetUrl !== prevConfig?.assetUrl || newConfig.thumbnailUrl !== prevConfig?.thumbnailUrl;
|
|
4806
|
+
if (assetUrlChanged && (newConfig.assetUrl || newConfig.thumbnailUrl)) {
|
|
4807
|
+
const target = newConfig.assetUrl ?? newConfig.thumbnailUrl ?? "";
|
|
4808
|
+
await this.loadAvatarAsset(newConfig, target);
|
|
4809
|
+
} else {
|
|
4810
|
+
const animationsChanged = JSON.stringify(newConfig.animations) !== JSON.stringify(prevConfig?.animations);
|
|
4811
|
+
if (animationsChanged && newConfig.animations && newConfig.animations.length > 0) {
|
|
4812
|
+
const fbxRenderer = this.renderer.getFbxRenderer();
|
|
4813
|
+
if (fbxRenderer) {
|
|
4814
|
+
void fbxRenderer.loadExternalAnimations(newConfig.animations);
|
|
4815
|
+
}
|
|
4816
|
+
}
|
|
4817
|
+
}
|
|
4818
|
+
this.avatar.applyConfig(newConfig);
|
|
4819
|
+
if (newConfig.position !== prevConfig?.position || newConfig.size !== prevConfig?.size) {
|
|
4820
|
+
this.movement.goToAnchor();
|
|
4821
|
+
}
|
|
4822
|
+
this.events.emit("asiyst:config:updated", {
|
|
4823
|
+
config: newConfig,
|
|
4824
|
+
previousVersion: prevConfig?.version
|
|
4825
|
+
});
|
|
4826
|
+
}
|
|
4827
|
+
async reloadConfig() {
|
|
4828
|
+
const updated = await this.config.refresh({ force: true });
|
|
4829
|
+
await this.applyUpdatedConfig(updated, this.config.get());
|
|
4830
|
+
return updated;
|
|
4831
|
+
}
|
|
4832
|
+
async updateConfig(partial) {
|
|
4833
|
+
const prev = this.config.get();
|
|
4834
|
+
const updated = this.config.applyLocalUpdate(partial);
|
|
4835
|
+
await this.applyUpdatedConfig(updated, prev);
|
|
4836
|
+
}
|
|
4837
|
+
playAnimation(nameOrIntent, options) {
|
|
4838
|
+
const played = this.renderer.playAnimation?.(nameOrIntent, options?.loopMode) ?? false;
|
|
4839
|
+
if (played) {
|
|
4840
|
+
this.events.emit("asiyst:animation:played", { name: nameOrIntent, intent: options?.loopMode });
|
|
4841
|
+
} else {
|
|
4842
|
+
this.events.emit("asiyst:animation:error", {
|
|
4843
|
+
name: nameOrIntent,
|
|
4844
|
+
error: `Animation "${nameOrIntent}" not found or incompatible with current skeleton`
|
|
4845
|
+
});
|
|
4846
|
+
}
|
|
4847
|
+
return played;
|
|
4848
|
+
}
|
|
4371
4849
|
getConnectionStatus() {
|
|
4372
4850
|
return this.connectionStatus;
|
|
4373
4851
|
}
|
|
@@ -4427,6 +4905,10 @@ var AsiystRuntime = class {
|
|
|
4427
4905
|
clearInterval(this.heartbeatTimer);
|
|
4428
4906
|
this.heartbeatTimer = void 0;
|
|
4429
4907
|
}
|
|
4908
|
+
if (this.configRevalidationTimer) {
|
|
4909
|
+
clearInterval(this.configRevalidationTimer);
|
|
4910
|
+
this.configRevalidationTimer = void 0;
|
|
4911
|
+
}
|
|
4430
4912
|
const doc = this.host.host.ownerDocument;
|
|
4431
4913
|
if (doc && this.visibilityListener) {
|
|
4432
4914
|
doc.removeEventListener("visibilitychange", this.visibilityListener);
|
|
@@ -4696,6 +5178,12 @@ var Asiyst = {
|
|
|
4696
5178
|
getConfig() {
|
|
4697
5179
|
return requireRuntime().getConfig();
|
|
4698
5180
|
},
|
|
5181
|
+
async reloadConfig() {
|
|
5182
|
+
return requireRuntime().reloadConfig();
|
|
5183
|
+
},
|
|
5184
|
+
async updateConfig(partial) {
|
|
5185
|
+
await requireRuntime().updateConfig(partial);
|
|
5186
|
+
},
|
|
4699
5187
|
getConnectionStatus() {
|
|
4700
5188
|
return requireRuntime().getConnectionStatus();
|
|
4701
5189
|
},
|
|
@@ -4730,6 +5218,9 @@ var Asiyst = {
|
|
|
4730
5218
|
celebrate() {
|
|
4731
5219
|
withIsolation(() => requireRuntime().avatarApi().celebrate());
|
|
4732
5220
|
},
|
|
5221
|
+
playAnimation(nameOrIntent, options) {
|
|
5222
|
+
return requireRuntime().playAnimation(nameOrIntent, options);
|
|
5223
|
+
},
|
|
4733
5224
|
setPosition(x, y) {
|
|
4734
5225
|
withIsolation(() => requireRuntime().avatarApi().setPosition(x, y));
|
|
4735
5226
|
}
|