@asiyst/sdk 0.1.22 → 0.1.25
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 +632 -207
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -10
- package/dist/index.d.ts +42 -10
- package/dist/index.js +632 -207
- 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.24";
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
var SDK_VERSION = resolveSdkVersion();
|
|
@@ -93,6 +93,7 @@ var AVATAR_VIEWPORT_PADDING = 12;
|
|
|
93
93
|
var AVATAR_TARGET_GAP = 16;
|
|
94
94
|
var WEBSITE_MAP_TEXT_LIMIT = 80;
|
|
95
95
|
var CONFIG_CACHE_TTL_MS = 1e3 * 60 * 10;
|
|
96
|
+
var HEARTBEAT_INTERVAL_MS = 45e3;
|
|
96
97
|
|
|
97
98
|
// src/security/selectors.ts
|
|
98
99
|
var DANGEROUS_SELECTOR = /javascript:|expression\(|@import|url\s*\(|behavior:|binding:|<script/i;
|
|
@@ -135,11 +136,12 @@ var ANCHORS = [
|
|
|
135
136
|
"top-left"
|
|
136
137
|
];
|
|
137
138
|
var PUBLIC_IDENTIFIER_PATTERN = /^(?=.{1,128}$)[A-Za-z0-9_][A-Za-z0-9_-]*$/;
|
|
139
|
+
var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
138
140
|
function isValidPublicIdentifier(value) {
|
|
139
141
|
if (typeof value !== "string") return false;
|
|
140
142
|
const trimmed = value.trim();
|
|
141
143
|
if (!trimmed || trimmed.length > 128) return false;
|
|
142
|
-
if (
|
|
144
|
+
if (UUID_PATTERN.test(trimmed)) {
|
|
143
145
|
return false;
|
|
144
146
|
}
|
|
145
147
|
return PUBLIC_IDENTIFIER_PATTERN.test(trimmed);
|
|
@@ -371,18 +373,22 @@ function normalizeProjectConfig(raw) {
|
|
|
371
373
|
return base;
|
|
372
374
|
}
|
|
373
375
|
const rawAvatarRecord = isRecord(raw.avatar) ? raw.avatar : void 0;
|
|
376
|
+
const rawConfigRecord = isRecord(raw.config) ? raw.config : void 0;
|
|
377
|
+
const rawManifestRecord = isRecord(raw.manifest) ? raw.manifest : void 0;
|
|
374
378
|
const avatarId = asString(
|
|
375
|
-
raw.avatarId ?? rawAvatarRecord?.avatarId ?? rawAvatarRecord?.id,
|
|
379
|
+
raw.avatarId ?? rawAvatarRecord?.avatarId ?? rawAvatarRecord?.id ?? rawConfigRecord?.avatarId,
|
|
376
380
|
"",
|
|
377
381
|
128
|
|
378
382
|
) || void 0;
|
|
379
|
-
const assetUrl = typeof raw.assetUrl === "string" ? raw.assetUrl : typeof rawAvatarRecord?.assetUrl === "string" ? rawAvatarRecord.assetUrl : void 0;
|
|
380
|
-
const thumbnailUrl = typeof raw.thumbnailUrl === "string" ? raw.thumbnailUrl : typeof rawAvatarRecord?.thumbnailUrl === "string" ? rawAvatarRecord.thumbnailUrl : rawAvatarRecord?.thumbnailUrl === null ? null : void 0;
|
|
381
|
-
const publishedVersion = typeof raw.publishedVersion === "string" ? raw.publishedVersion : typeof rawAvatarRecord?.version === "string" ? rawAvatarRecord.version : void 0;
|
|
382
|
-
const animations = parseAnimations(
|
|
383
|
-
|
|
383
|
+
const assetUrl = typeof raw.assetUrl === "string" && raw.assetUrl ? raw.assetUrl : typeof rawAvatarRecord?.assetUrl === "string" && rawAvatarRecord.assetUrl ? rawAvatarRecord.assetUrl : typeof rawAvatarRecord?.modelUrl === "string" && rawAvatarRecord.modelUrl ? rawAvatarRecord.modelUrl : typeof rawConfigRecord?.assetUrl === "string" && rawConfigRecord.assetUrl ? rawConfigRecord.assetUrl : typeof rawManifestRecord?.assetUrl === "string" && rawManifestRecord.assetUrl ? rawManifestRecord.assetUrl : typeof rawManifestRecord?.modelUrl === "string" && rawManifestRecord.modelUrl ? rawManifestRecord.modelUrl : void 0;
|
|
384
|
+
const thumbnailUrl = typeof raw.thumbnailUrl === "string" ? raw.thumbnailUrl : typeof rawAvatarRecord?.thumbnailUrl === "string" ? rawAvatarRecord.thumbnailUrl : typeof rawConfigRecord?.thumbnailUrl === "string" ? rawConfigRecord.thumbnailUrl : typeof rawManifestRecord?.thumbnailUrl === "string" ? rawManifestRecord.thumbnailUrl : rawAvatarRecord?.thumbnailUrl === null ? null : void 0;
|
|
385
|
+
const publishedVersion = typeof raw.publishedVersion === "string" ? raw.publishedVersion : typeof rawAvatarRecord?.version === "string" ? rawAvatarRecord.version : typeof rawManifestRecord?.version === "string" ? rawManifestRecord.version : void 0;
|
|
386
|
+
const animations = parseAnimations(
|
|
387
|
+
raw.animations ?? rawAvatarRecord?.animations ?? rawConfigRecord?.animations
|
|
388
|
+
);
|
|
389
|
+
const branding = parseBranding(raw.branding ?? rawAvatarRecord?.branding);
|
|
384
390
|
const avatarName = asString(
|
|
385
|
-
raw.avatarName ?? rawAvatarRecord?.name,
|
|
391
|
+
raw.avatarName ?? rawAvatarRecord?.name ?? rawConfigRecord?.avatarName ?? rawManifestRecord?.name,
|
|
386
392
|
base.avatarName,
|
|
387
393
|
40
|
|
388
394
|
);
|
|
@@ -646,39 +652,58 @@ var CloudClient = class {
|
|
|
646
652
|
const avatarAndKeyParams = `?projectId=${encodeURIComponent(this.projectId)}&publicKey=${encodeURIComponent(this.publicKey)}${this.avatarId ? `&avatarId=${encodeURIComponent(this.avatarId)}` : ""}`;
|
|
647
653
|
const baseUrl = this.getApiBaseUrl();
|
|
648
654
|
const resolveAssetUrls = (raw) => {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
655
|
+
let canonicalBase = "https://asiyst.com";
|
|
656
|
+
try {
|
|
657
|
+
if (baseUrl) {
|
|
658
|
+
const u = new URL(baseUrl);
|
|
659
|
+
canonicalBase = u.origin;
|
|
654
660
|
}
|
|
655
|
-
|
|
656
|
-
|
|
661
|
+
} catch {
|
|
662
|
+
canonicalBase = "https://asiyst.com";
|
|
663
|
+
}
|
|
664
|
+
const toAbsolute = (url) => {
|
|
665
|
+
if (typeof url === "string" && url.startsWith("/")) {
|
|
666
|
+
return new URL(url, canonicalBase).href;
|
|
657
667
|
}
|
|
668
|
+
return url;
|
|
669
|
+
};
|
|
670
|
+
if (raw.avatar && typeof raw.avatar === "object" && !Array.isArray(raw.avatar)) {
|
|
671
|
+
const av = { ...raw.avatar };
|
|
672
|
+
av.assetUrl = toAbsolute(av.assetUrl);
|
|
673
|
+
av.thumbnailUrl = toAbsolute(av.thumbnailUrl);
|
|
674
|
+
av.modelUrl = toAbsolute(av.modelUrl);
|
|
675
|
+
av.manifestUrl = toAbsolute(av.manifestUrl);
|
|
658
676
|
if (Array.isArray(av.animations)) {
|
|
659
677
|
av.animations = av.animations.map((item) => {
|
|
660
678
|
if (item && typeof item === "object") {
|
|
661
679
|
const animObj = item;
|
|
662
|
-
|
|
663
|
-
return { ...animObj, assetUrl: new URL(animObj.assetUrl, canonicalBase).href };
|
|
664
|
-
}
|
|
680
|
+
return { ...animObj, assetUrl: toAbsolute(animObj.assetUrl) };
|
|
665
681
|
}
|
|
666
682
|
return item;
|
|
667
683
|
});
|
|
668
684
|
}
|
|
669
685
|
raw.avatar = av;
|
|
670
686
|
}
|
|
671
|
-
if (typeof raw.
|
|
672
|
-
|
|
687
|
+
if (raw.config && typeof raw.config === "object" && !Array.isArray(raw.config)) {
|
|
688
|
+
const cfg = { ...raw.config };
|
|
689
|
+
cfg.assetUrl = toAbsolute(cfg.assetUrl);
|
|
690
|
+
cfg.thumbnailUrl = toAbsolute(cfg.thumbnailUrl);
|
|
691
|
+
cfg.manifestUrl = toAbsolute(cfg.manifestUrl);
|
|
692
|
+
raw.config = cfg;
|
|
673
693
|
}
|
|
674
|
-
if (typeof raw.
|
|
675
|
-
|
|
694
|
+
if (raw.manifest && typeof raw.manifest === "object" && !Array.isArray(raw.manifest)) {
|
|
695
|
+
const mf = { ...raw.manifest };
|
|
696
|
+
mf.assetUrl = toAbsolute(mf.assetUrl);
|
|
697
|
+
mf.thumbnailUrl = toAbsolute(mf.thumbnailUrl);
|
|
698
|
+
mf.modelUrl = toAbsolute(mf.modelUrl);
|
|
699
|
+
raw.manifest = mf;
|
|
676
700
|
}
|
|
701
|
+
raw.assetUrl = toAbsolute(raw.assetUrl);
|
|
702
|
+
raw.thumbnailUrl = toAbsolute(raw.thumbnailUrl);
|
|
703
|
+
raw.manifestUrl = toAbsolute(raw.manifestUrl);
|
|
677
704
|
if (raw.branding && typeof raw.branding === "object" && !Array.isArray(raw.branding)) {
|
|
678
705
|
const br = { ...raw.branding };
|
|
679
|
-
|
|
680
|
-
br.siteLogoUrl = new URL(br.siteLogoUrl, canonicalBase).href;
|
|
681
|
-
}
|
|
706
|
+
br.siteLogoUrl = toAbsolute(br.siteLogoUrl);
|
|
682
707
|
raw.branding = br;
|
|
683
708
|
}
|
|
684
709
|
return raw;
|
|
@@ -691,8 +716,11 @@ var CloudClient = class {
|
|
|
691
716
|
idempotent: true
|
|
692
717
|
});
|
|
693
718
|
if (response.ok && response.data) {
|
|
694
|
-
const
|
|
695
|
-
|
|
719
|
+
const fullData = response.data && typeof response.data === "object" && !Array.isArray(response.data) ? {
|
|
720
|
+
...response.data,
|
|
721
|
+
...response.data.config && typeof response.data.config === "object" ? response.data.config : {}
|
|
722
|
+
} : {};
|
|
723
|
+
return normalizeProjectConfig(resolveAssetUrls(fullData));
|
|
696
724
|
}
|
|
697
725
|
if (response.status === 404) {
|
|
698
726
|
lastError = new ConfigurationError(`Project ${this.projectId} or avatar configuration not found`);
|
|
@@ -754,7 +782,7 @@ var CloudClient = class {
|
|
|
754
782
|
throw new ConfigurationError(`Failed to resolve avatar configuration for project ${this.projectId}`);
|
|
755
783
|
}
|
|
756
784
|
async heartbeat(metadata) {
|
|
757
|
-
|
|
785
|
+
let response = await this.runtimeRequest({
|
|
758
786
|
path: "/sdk/heartbeat",
|
|
759
787
|
method: "POST",
|
|
760
788
|
idempotent: true,
|
|
@@ -767,6 +795,21 @@ var CloudClient = class {
|
|
|
767
795
|
timestamp: metadata.timestamp
|
|
768
796
|
}
|
|
769
797
|
}, "assistant:heartbeat");
|
|
798
|
+
if (response.status === 404) {
|
|
799
|
+
response = await this.runtimeRequest({
|
|
800
|
+
path: "/api/v1/sdk/heartbeat",
|
|
801
|
+
method: "POST",
|
|
802
|
+
idempotent: true,
|
|
803
|
+
body: {
|
|
804
|
+
project_id: this.projectId,
|
|
805
|
+
public_key: this.publicKey,
|
|
806
|
+
sdk_version: SDK_VERSION,
|
|
807
|
+
origin: metadata.origin,
|
|
808
|
+
environment: metadata.environment,
|
|
809
|
+
timestamp: metadata.timestamp
|
|
810
|
+
}
|
|
811
|
+
}, "assistant:heartbeat");
|
|
812
|
+
}
|
|
770
813
|
const body = response.data && typeof response.data === "object" && !Array.isArray(response.data) ? response.data : void 0;
|
|
771
814
|
const rawStatus = body?.status ?? body?.connectionStatus ?? body?.verificationStatus ?? (body?.verified === true ? "verified" : void 0);
|
|
772
815
|
const verificationStatus = rawStatus === "connected" || rawStatus === "verified" || rawStatus === "inactive" || rawStatus === "not_detected" || rawStatus === "error" ? rawStatus : void 0;
|
|
@@ -779,13 +822,22 @@ var CloudClient = class {
|
|
|
779
822
|
};
|
|
780
823
|
}
|
|
781
824
|
async registerInstallation(registration) {
|
|
782
|
-
|
|
825
|
+
let response = await this.transport.request({
|
|
783
826
|
path: "/sdk/installations/register",
|
|
784
827
|
method: "POST",
|
|
785
828
|
body: registration,
|
|
786
829
|
idempotent: true,
|
|
787
830
|
sessionId: this.sessionId
|
|
788
831
|
});
|
|
832
|
+
if (response.status === 404) {
|
|
833
|
+
response = await this.transport.request({
|
|
834
|
+
path: "/api/v1/sdk/installations/register",
|
|
835
|
+
method: "POST",
|
|
836
|
+
body: registration,
|
|
837
|
+
idempotent: true,
|
|
838
|
+
sessionId: this.sessionId
|
|
839
|
+
});
|
|
840
|
+
}
|
|
789
841
|
if (!response.ok) {
|
|
790
842
|
throw new NetworkError(`SDK installation registration failed (${response.status}).`);
|
|
791
843
|
}
|
|
@@ -1713,7 +1765,7 @@ var AssetLoader = class {
|
|
|
1713
1765
|
}
|
|
1714
1766
|
this.inFlightController = new AbortController();
|
|
1715
1767
|
const abortSignal = options?.signal ? anySignal([this.inFlightController.signal, options.signal]) : this.inFlightController.signal;
|
|
1716
|
-
const timeoutMs = options?.timeoutMs ??
|
|
1768
|
+
const timeoutMs = options?.timeoutMs ?? 6e4;
|
|
1717
1769
|
const timeoutId = setTimeout(() => {
|
|
1718
1770
|
this.inFlightController?.abort();
|
|
1719
1771
|
}, timeoutMs);
|
|
@@ -2061,6 +2113,8 @@ var FbxRenderer = class {
|
|
|
2061
2113
|
this.camera = null;
|
|
2062
2114
|
this.modelRoot = null;
|
|
2063
2115
|
this.mixer = null;
|
|
2116
|
+
this.allAnimations = [];
|
|
2117
|
+
this.currentAction = null;
|
|
2064
2118
|
this.animFrameId = null;
|
|
2065
2119
|
this.lastTime = 0;
|
|
2066
2120
|
this.facing = "right";
|
|
@@ -2079,35 +2133,53 @@ var FbxRenderer = class {
|
|
|
2079
2133
|
if (!glContext) {
|
|
2080
2134
|
throw new Error("WebGLRenderingContext is not available or supported in this browser environment");
|
|
2081
2135
|
}
|
|
2136
|
+
const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
|
|
2137
|
+
const width = options?.width || (isMobile ? 180 : 240);
|
|
2138
|
+
const height = options?.height || (isMobile ? 360 : 460);
|
|
2082
2139
|
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
2083
|
-
|
|
2084
|
-
this.canvas.
|
|
2085
|
-
this.canvas.
|
|
2140
|
+
this.canvas.width = Math.round(width * dpr);
|
|
2141
|
+
this.canvas.height = Math.round(height * dpr);
|
|
2142
|
+
this.canvas.style.width = `${width}px`;
|
|
2143
|
+
this.canvas.style.height = `${height}px`;
|
|
2086
2144
|
try {
|
|
2087
2145
|
this.renderer = new THREE.WebGLRenderer({
|
|
2088
2146
|
canvas: this.canvas,
|
|
2089
2147
|
alpha: true,
|
|
2090
2148
|
antialias: true,
|
|
2091
|
-
powerPreference: "
|
|
2149
|
+
powerPreference: "high-performance"
|
|
2092
2150
|
});
|
|
2093
2151
|
this.renderer.setPixelRatio(Math.min(dpr, 2));
|
|
2094
|
-
this.renderer.setSize(
|
|
2152
|
+
this.renderer.setSize(width, height, false);
|
|
2095
2153
|
this.renderer.outputColorSpace = THREE.SRGBColorSpace;
|
|
2154
|
+
this.renderer.shadowMap.enabled = true;
|
|
2155
|
+
this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
2096
2156
|
} catch (err) {
|
|
2097
2157
|
const msg = err instanceof Error ? err.message : String(err);
|
|
2098
2158
|
throw new Error(`Failed to initialize WebGLRenderer: ${msg}`);
|
|
2099
2159
|
}
|
|
2100
2160
|
this.scene = new THREE.Scene();
|
|
2101
|
-
this.camera = new THREE.PerspectiveCamera(
|
|
2102
|
-
this.camera.position.set(0, 0, 3.4);
|
|
2161
|
+
this.camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 100);
|
|
2103
2162
|
const ambientLight = new THREE.AmbientLight(16777215, 1.2);
|
|
2104
2163
|
this.scene.add(ambientLight);
|
|
2105
|
-
const keyLight = new THREE.DirectionalLight(
|
|
2106
|
-
keyLight.position.set(
|
|
2164
|
+
const keyLight = new THREE.DirectionalLight(16774634, 2);
|
|
2165
|
+
keyLight.position.set(3, 4, 3);
|
|
2166
|
+
keyLight.castShadow = true;
|
|
2167
|
+
keyLight.shadow.mapSize.width = 512;
|
|
2168
|
+
keyLight.shadow.mapSize.height = 512;
|
|
2107
2169
|
this.scene.add(keyLight);
|
|
2108
|
-
const fillLight = new THREE.DirectionalLight(
|
|
2109
|
-
fillLight.position.set(-
|
|
2170
|
+
const fillLight = new THREE.DirectionalLight(15459032, 1.2);
|
|
2171
|
+
fillLight.position.set(-3, 2, 2);
|
|
2110
2172
|
this.scene.add(fillLight);
|
|
2173
|
+
const rimLight = new THREE.DirectionalLight(16771286, 1.5);
|
|
2174
|
+
rimLight.position.set(0, 4, -3);
|
|
2175
|
+
this.scene.add(rimLight);
|
|
2176
|
+
const shadowGeo = new THREE.PlaneGeometry(3, 3);
|
|
2177
|
+
const shadowMat = new THREE.ShadowMaterial({ opacity: 0.15 });
|
|
2178
|
+
const shadowPlane = new THREE.Mesh(shadowGeo, shadowMat);
|
|
2179
|
+
shadowPlane.rotation.x = -Math.PI / 2;
|
|
2180
|
+
shadowPlane.position.y = 0;
|
|
2181
|
+
shadowPlane.receiveShadow = true;
|
|
2182
|
+
this.scene.add(shadowPlane);
|
|
2111
2183
|
let rawObject;
|
|
2112
2184
|
let modelAnimations = [];
|
|
2113
2185
|
if (asset.format === "fbx") {
|
|
@@ -2144,32 +2216,39 @@ var FbxRenderer = class {
|
|
|
2144
2216
|
}
|
|
2145
2217
|
}
|
|
2146
2218
|
const { meshCount, vertexCount: totalVertices } = this.validateGeometry(rawObject);
|
|
2147
|
-
const
|
|
2148
|
-
if (
|
|
2219
|
+
const rawBox = new THREE.Box3().setFromObject(rawObject);
|
|
2220
|
+
if (rawBox.isEmpty()) {
|
|
2149
2221
|
throw new Error("FBX asset geometry bounding box is empty");
|
|
2150
2222
|
}
|
|
2151
|
-
const
|
|
2152
|
-
|
|
2153
|
-
const
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
rawObject.position.z -= center.z;
|
|
2223
|
+
const rawSize = rawBox.getSize(new THREE.Vector3());
|
|
2224
|
+
const rawCenter = rawBox.getCenter(new THREE.Vector3());
|
|
2225
|
+
const rawHeight = rawSize.y > 0 ? rawSize.y : 1.8;
|
|
2226
|
+
rawObject.position.set(-rawCenter.x, -rawBox.min.y, -rawCenter.z);
|
|
2227
|
+
const targetVisualHeight = 1.8;
|
|
2228
|
+
const targetScale = targetVisualHeight / rawHeight;
|
|
2158
2229
|
this.modelRoot = new THREE.Group();
|
|
2159
2230
|
this.modelRoot.add(rawObject);
|
|
2231
|
+
this.modelRoot.scale.setScalar(targetScale);
|
|
2160
2232
|
this.scene.add(this.modelRoot);
|
|
2161
|
-
const
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2233
|
+
const visualCenterY = targetVisualHeight * 0.52;
|
|
2234
|
+
const fovRadians = this.camera.fov * Math.PI / 180;
|
|
2235
|
+
const fitDist = Math.max(2.4, targetVisualHeight / 2 / Math.tan(fovRadians / 2) * 1.25);
|
|
2236
|
+
this.camera.position.set(0, visualCenterY + 0.1, fitDist);
|
|
2237
|
+
this.camera.lookAt(0, visualCenterY, 0);
|
|
2238
|
+
rawObject.traverse((child) => {
|
|
2239
|
+
const mesh = child;
|
|
2240
|
+
if (mesh.isMesh) {
|
|
2241
|
+
mesh.castShadow = true;
|
|
2242
|
+
mesh.receiveShadow = true;
|
|
2243
|
+
}
|
|
2244
|
+
});
|
|
2245
|
+
this.allAnimations = modelAnimations;
|
|
2167
2246
|
if (modelAnimations.length > 0) {
|
|
2168
2247
|
this.mixer = new THREE.AnimationMixer(rawObject);
|
|
2169
|
-
const
|
|
2170
|
-
if (
|
|
2171
|
-
|
|
2172
|
-
|
|
2248
|
+
const idleClip = modelAnimations.find((c) => c.name.toLowerCase().includes("idle")) || modelAnimations[0];
|
|
2249
|
+
if (idleClip) {
|
|
2250
|
+
this.currentAction = this.mixer.clipAction(idleClip);
|
|
2251
|
+
this.currentAction.play();
|
|
2173
2252
|
}
|
|
2174
2253
|
}
|
|
2175
2254
|
container.replaceChildren();
|
|
@@ -2184,6 +2263,10 @@ var FbxRenderer = class {
|
|
|
2184
2263
|
this.startLoop();
|
|
2185
2264
|
this.setFacing(this.facing);
|
|
2186
2265
|
this.setPose(this.currentPose);
|
|
2266
|
+
if (typeof window !== "undefined") {
|
|
2267
|
+
this.resizeListener = () => this.handleResize();
|
|
2268
|
+
window.addEventListener("resize", this.resizeListener);
|
|
2269
|
+
}
|
|
2187
2270
|
return {
|
|
2188
2271
|
meshCount,
|
|
2189
2272
|
vertexCount: totalVertices,
|
|
@@ -2199,6 +2282,31 @@ var FbxRenderer = class {
|
|
|
2199
2282
|
setPose(pose) {
|
|
2200
2283
|
this.currentPose = pose;
|
|
2201
2284
|
if (!this.modelRoot) return;
|
|
2285
|
+
if (this.mixer && this.allAnimations.length > 1) {
|
|
2286
|
+
let targetClip;
|
|
2287
|
+
if (pose === "speak") {
|
|
2288
|
+
targetClip = this.allAnimations.find(
|
|
2289
|
+
(c) => c.name.toLowerCase().includes("talk") || c.name.toLowerCase().includes("speak")
|
|
2290
|
+
);
|
|
2291
|
+
} else if (pose === "think") {
|
|
2292
|
+
targetClip = this.allAnimations.find(
|
|
2293
|
+
(c) => c.name.toLowerCase().includes("think")
|
|
2294
|
+
);
|
|
2295
|
+
} else {
|
|
2296
|
+
targetClip = this.allAnimations.find((c) => c.name.toLowerCase().includes("idle")) || this.allAnimations[0];
|
|
2297
|
+
}
|
|
2298
|
+
if (targetClip) {
|
|
2299
|
+
const newAction = this.mixer.clipAction(targetClip);
|
|
2300
|
+
if (newAction !== this.currentAction) {
|
|
2301
|
+
newAction.reset().fadeIn(0.25).play();
|
|
2302
|
+
if (this.currentAction) {
|
|
2303
|
+
this.currentAction.fadeOut(0.25);
|
|
2304
|
+
}
|
|
2305
|
+
this.currentAction = newAction;
|
|
2306
|
+
return;
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2202
2310
|
switch (pose) {
|
|
2203
2311
|
case "point":
|
|
2204
2312
|
this.modelRoot.rotation.z = -0.15;
|
|
@@ -2208,6 +2316,10 @@ var FbxRenderer = class {
|
|
|
2208
2316
|
this.modelRoot.rotation.z = 0.12;
|
|
2209
2317
|
this.modelRoot.rotation.x = -0.1;
|
|
2210
2318
|
break;
|
|
2319
|
+
case "speak":
|
|
2320
|
+
this.modelRoot.rotation.y = this.facing === "left" ? -0.22 : 0.22;
|
|
2321
|
+
this.modelRoot.rotation.x = 0.04;
|
|
2322
|
+
break;
|
|
2211
2323
|
case "celebrate":
|
|
2212
2324
|
this.modelRoot.rotation.z = 0;
|
|
2213
2325
|
this.modelRoot.rotation.x = -0.15;
|
|
@@ -2216,6 +2328,7 @@ var FbxRenderer = class {
|
|
|
2216
2328
|
default:
|
|
2217
2329
|
this.modelRoot.rotation.z = 0;
|
|
2218
2330
|
this.modelRoot.rotation.x = 0;
|
|
2331
|
+
this.modelRoot.rotation.y = this.facing === "left" ? -0.35 : 0.35;
|
|
2219
2332
|
break;
|
|
2220
2333
|
}
|
|
2221
2334
|
}
|
|
@@ -2260,6 +2373,10 @@ var FbxRenderer = class {
|
|
|
2260
2373
|
this.animFrameId = requestAnimationFrame(tick);
|
|
2261
2374
|
}
|
|
2262
2375
|
destroy() {
|
|
2376
|
+
if (typeof window !== "undefined" && this.resizeListener) {
|
|
2377
|
+
window.removeEventListener("resize", this.resizeListener);
|
|
2378
|
+
this.resizeListener = void 0;
|
|
2379
|
+
}
|
|
2263
2380
|
if (this.animFrameId !== null && typeof cancelAnimationFrame !== "undefined") {
|
|
2264
2381
|
cancelAnimationFrame(this.animFrameId);
|
|
2265
2382
|
this.animFrameId = null;
|
|
@@ -2305,6 +2422,30 @@ var FbxRenderer = class {
|
|
|
2305
2422
|
this.modelRoot = null;
|
|
2306
2423
|
this.initialRenderCompleted = false;
|
|
2307
2424
|
}
|
|
2425
|
+
handleResize() {
|
|
2426
|
+
if (!this.canvas || !this.renderer || !this.camera) return;
|
|
2427
|
+
const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
|
|
2428
|
+
const width = isMobile ? 180 : 240;
|
|
2429
|
+
const height = isMobile ? 360 : 460;
|
|
2430
|
+
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
2431
|
+
this.canvas.width = Math.round(width * dpr);
|
|
2432
|
+
this.canvas.height = Math.round(height * dpr);
|
|
2433
|
+
this.canvas.style.width = `${width}px`;
|
|
2434
|
+
this.canvas.style.height = `${height}px`;
|
|
2435
|
+
this.camera.aspect = width / height;
|
|
2436
|
+
this.camera.updateProjectionMatrix();
|
|
2437
|
+
this.renderer.setPixelRatio(Math.min(dpr, 2));
|
|
2438
|
+
this.renderer.setSize(width, height, false);
|
|
2439
|
+
}
|
|
2440
|
+
getCamera() {
|
|
2441
|
+
return this.camera;
|
|
2442
|
+
}
|
|
2443
|
+
getModelRoot() {
|
|
2444
|
+
return this.modelRoot;
|
|
2445
|
+
}
|
|
2446
|
+
getMixer() {
|
|
2447
|
+
return this.mixer;
|
|
2448
|
+
}
|
|
2308
2449
|
};
|
|
2309
2450
|
|
|
2310
2451
|
// src/avatar/CssAvatarRenderer.ts
|
|
@@ -2315,7 +2456,7 @@ var AVATAR_CSS = `
|
|
|
2315
2456
|
display: flex;
|
|
2316
2457
|
flex-direction: column;
|
|
2317
2458
|
align-items: center;
|
|
2318
|
-
gap:
|
|
2459
|
+
gap: 4px;
|
|
2319
2460
|
pointer-events: auto;
|
|
2320
2461
|
user-select: none;
|
|
2321
2462
|
}
|
|
@@ -2336,28 +2477,38 @@ var AVATAR_CSS = `
|
|
|
2336
2477
|
padding: 0;
|
|
2337
2478
|
outline: none;
|
|
2338
2479
|
background: #2563eb;
|
|
2480
|
+
transition: width 0.3s ease, height 0.3s ease, background 0.3s ease;
|
|
2481
|
+
}
|
|
2482
|
+
.asiyst-figure.asiyst-3d-active {
|
|
2483
|
+
width: 240px !important;
|
|
2484
|
+
height: 460px !important;
|
|
2485
|
+
background: transparent !important;
|
|
2486
|
+
border-radius: 0 !important;
|
|
2487
|
+
box-shadow: none !important;
|
|
2488
|
+
overflow: visible !important;
|
|
2489
|
+
}
|
|
2490
|
+
@media (max-width: 640px) {
|
|
2491
|
+
.asiyst-figure.asiyst-3d-active {
|
|
2492
|
+
width: 180px !important;
|
|
2493
|
+
height: 360px !important;
|
|
2494
|
+
}
|
|
2339
2495
|
}
|
|
2340
|
-
.asiyst-figure[data-pose="point"] { transform: rotate(-12deg); }
|
|
2341
|
-
.asiyst-figure[data-pose="think"] { opacity: 0.85; }
|
|
2342
|
-
.asiyst-figure[data-pose="celebrate"] { transform: scale(1.08); }
|
|
2343
2496
|
.asiyst-avatar-viewport {
|
|
2344
|
-
position:
|
|
2345
|
-
inset: 0;
|
|
2497
|
+
position: relative;
|
|
2346
2498
|
width: 100%;
|
|
2347
2499
|
height: 100%;
|
|
2348
2500
|
display: grid;
|
|
2349
2501
|
place-items: center;
|
|
2350
2502
|
border-radius: inherit;
|
|
2351
|
-
overflow:
|
|
2352
|
-
pointer-events:
|
|
2503
|
+
overflow: visible;
|
|
2504
|
+
pointer-events: auto;
|
|
2353
2505
|
}
|
|
2354
2506
|
.asiyst-avatar-canvas {
|
|
2355
2507
|
width: 100%;
|
|
2356
2508
|
height: 100%;
|
|
2357
2509
|
object-fit: contain;
|
|
2358
|
-
border-radius: inherit;
|
|
2359
2510
|
display: block;
|
|
2360
|
-
pointer-events:
|
|
2511
|
+
pointer-events: auto;
|
|
2361
2512
|
}
|
|
2362
2513
|
.asiyst-avatar-graphic {
|
|
2363
2514
|
width: 100%;
|
|
@@ -2411,11 +2562,73 @@ var AVATAR_CSS = `
|
|
|
2411
2562
|
padding: 8px 10px;
|
|
2412
2563
|
font: 13px/1.4 system-ui, sans-serif;
|
|
2413
2564
|
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2);
|
|
2565
|
+
margin-bottom: 4px;
|
|
2566
|
+
}
|
|
2567
|
+
.asiyst-name-tag {
|
|
2568
|
+
display: inline-flex;
|
|
2569
|
+
align-items: center;
|
|
2570
|
+
gap: 6px;
|
|
2571
|
+
background: rgba(255, 255, 255, 0.95);
|
|
2572
|
+
backdrop-filter: blur(8px);
|
|
2573
|
+
border: 1px solid rgba(226, 232, 240, 0.9);
|
|
2574
|
+
border-radius: 9999px;
|
|
2575
|
+
padding: 4px 12px;
|
|
2576
|
+
font-size: 11px;
|
|
2577
|
+
font-weight: 700;
|
|
2578
|
+
color: #1e293b;
|
|
2579
|
+
box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
|
|
2580
|
+
user-select: none;
|
|
2581
|
+
margin-bottom: 2px;
|
|
2582
|
+
pointer-events: none;
|
|
2583
|
+
transition: opacity 0.2s ease;
|
|
2584
|
+
}
|
|
2585
|
+
.asiyst-name-sparkle { color: #f59e0b; font-size: 12px; font-weight: 900; }
|
|
2586
|
+
.asiyst-name-dot {
|
|
2587
|
+
width: 6px;
|
|
2588
|
+
height: 6px;
|
|
2589
|
+
border-radius: 50%;
|
|
2590
|
+
background: #10b981;
|
|
2591
|
+
display: inline-block;
|
|
2592
|
+
animation: asiyst-pulse 2s infinite;
|
|
2593
|
+
}
|
|
2594
|
+
.asiyst-name-status {
|
|
2595
|
+
font-size: 10px;
|
|
2596
|
+
color: #64748b;
|
|
2597
|
+
font-weight: 500;
|
|
2598
|
+
text-transform: uppercase;
|
|
2599
|
+
}
|
|
2600
|
+
@keyframes asiyst-pulse {
|
|
2601
|
+
0%, 100% { opacity: 1; transform: scale(1); }
|
|
2602
|
+
50% { opacity: 0.4; transform: scale(1.3); }
|
|
2603
|
+
}
|
|
2604
|
+
.asiyst-open-chat-btn {
|
|
2605
|
+
display: inline-flex;
|
|
2606
|
+
align-items: center;
|
|
2607
|
+
gap: 6px;
|
|
2608
|
+
background: #0f172a;
|
|
2609
|
+
color: #fbbf24;
|
|
2610
|
+
border: 1px solid rgba(245, 158, 11, 0.6);
|
|
2611
|
+
border-radius: 9999px;
|
|
2612
|
+
padding: 6px 14px;
|
|
2613
|
+
font-size: 12px;
|
|
2614
|
+
font-weight: 700;
|
|
2615
|
+
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
|
|
2616
|
+
cursor: pointer;
|
|
2617
|
+
margin-top: 4px;
|
|
2618
|
+
pointer-events: auto;
|
|
2619
|
+
transition: transform 0.15s ease, background-color 0.15s ease;
|
|
2620
|
+
}
|
|
2621
|
+
.asiyst-open-chat-btn:hover {
|
|
2622
|
+
transform: scale(1.05);
|
|
2623
|
+
background: #1e293b;
|
|
2624
|
+
}
|
|
2625
|
+
.asiyst-open-chat-btn svg {
|
|
2626
|
+
stroke: #fbbf24;
|
|
2414
2627
|
}
|
|
2415
|
-
.asiyst-name { font: 600 12px/1 system-ui, sans-serif; color: #0f172a; }
|
|
2416
2628
|
@media (prefers-reduced-motion: reduce) {
|
|
2417
2629
|
.asiyst-avatar.asiyst-animate { transition: none; }
|
|
2418
2630
|
.asiyst-avatar-loader { animation: none; }
|
|
2631
|
+
.asiyst-name-dot { animation: none; }
|
|
2419
2632
|
}
|
|
2420
2633
|
`;
|
|
2421
2634
|
var CssAvatarRenderer = class {
|
|
@@ -2426,6 +2639,7 @@ var CssAvatarRenderer = class {
|
|
|
2426
2639
|
this.pose = "idle";
|
|
2427
2640
|
this.accentColor = "#2563eb";
|
|
2428
2641
|
this.avatarName = "Asiyst";
|
|
2642
|
+
this.isPanelOpen = false;
|
|
2429
2643
|
// Asset loading & rendering state
|
|
2430
2644
|
this.assetLoader = new AssetLoader();
|
|
2431
2645
|
this.fbxRenderer = null;
|
|
@@ -2441,6 +2655,20 @@ var CssAvatarRenderer = class {
|
|
|
2441
2655
|
this.root = doc.createElement("div");
|
|
2442
2656
|
this.root.className = "asiyst-avatar asiyst-animate";
|
|
2443
2657
|
this.root.setAttribute("role", "img");
|
|
2658
|
+
this.nameTagEl = doc.createElement("div");
|
|
2659
|
+
this.nameTagEl.className = "asiyst-name-tag";
|
|
2660
|
+
const sparkle = doc.createElement("span");
|
|
2661
|
+
sparkle.className = "asiyst-name-sparkle";
|
|
2662
|
+
sparkle.textContent = "\u2726";
|
|
2663
|
+
this.nameTextEl = doc.createElement("span");
|
|
2664
|
+
this.nameTextEl.className = "asiyst-name-text";
|
|
2665
|
+
this.nameTextEl.textContent = config.avatarName;
|
|
2666
|
+
const dot = doc.createElement("span");
|
|
2667
|
+
dot.className = "asiyst-name-dot";
|
|
2668
|
+
this.statusTextEl = doc.createElement("span");
|
|
2669
|
+
this.statusTextEl.className = "asiyst-name-status";
|
|
2670
|
+
this.statusTextEl.textContent = "(IDLE)";
|
|
2671
|
+
this.nameTagEl.append(sparkle, this.nameTextEl, dot, this.statusTextEl);
|
|
2444
2672
|
this.figure = doc.createElement("button");
|
|
2445
2673
|
this.figure.type = "button";
|
|
2446
2674
|
this.figure.className = "asiyst-figure";
|
|
@@ -2449,12 +2677,26 @@ var CssAvatarRenderer = class {
|
|
|
2449
2677
|
this.viewport = doc.createElement("div");
|
|
2450
2678
|
this.viewport.className = "asiyst-avatar-viewport";
|
|
2451
2679
|
this.figure.appendChild(this.viewport);
|
|
2452
|
-
this.nameEl = doc.createElement("div");
|
|
2453
|
-
this.nameEl.className = "asiyst-name";
|
|
2454
2680
|
this.bubble = doc.createElement("div");
|
|
2455
2681
|
this.bubble.className = "asiyst-bubble";
|
|
2456
2682
|
this.bubble.hidden = true;
|
|
2457
|
-
this.
|
|
2683
|
+
this.chatActionBtn = doc.createElement("button");
|
|
2684
|
+
this.chatActionBtn.type = "button";
|
|
2685
|
+
this.chatActionBtn.className = "asiyst-open-chat-btn";
|
|
2686
|
+
this.chatActionBtn.innerHTML = `
|
|
2687
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
2688
|
+
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path>
|
|
2689
|
+
</svg>
|
|
2690
|
+
<span>Chat with ${config.avatarName}</span>
|
|
2691
|
+
`;
|
|
2692
|
+
this.chatActionBtn.addEventListener("click", (e) => {
|
|
2693
|
+
e.stopPropagation();
|
|
2694
|
+
this.onOpenChat?.();
|
|
2695
|
+
});
|
|
2696
|
+
this.figure.addEventListener("click", () => {
|
|
2697
|
+
this.onOpenChat?.();
|
|
2698
|
+
});
|
|
2699
|
+
this.root.append(this.bubble, this.nameTagEl, this.figure, this.chatActionBtn);
|
|
2458
2700
|
container.appendChild(this.root);
|
|
2459
2701
|
this.applyConfig(config);
|
|
2460
2702
|
}
|
|
@@ -2468,24 +2710,51 @@ var CssAvatarRenderer = class {
|
|
|
2468
2710
|
this.root = void 0;
|
|
2469
2711
|
this.figure = void 0;
|
|
2470
2712
|
this.viewport = void 0;
|
|
2713
|
+
this.nameTagEl = void 0;
|
|
2714
|
+
this.chatActionBtn = void 0;
|
|
2471
2715
|
}
|
|
2472
2716
|
applyConfig(config) {
|
|
2473
2717
|
this.size = config.size;
|
|
2474
2718
|
this.accentColor = config.theme.accent ?? "#2563eb";
|
|
2475
2719
|
this.avatarName = config.avatarName;
|
|
2476
|
-
if (this.
|
|
2477
|
-
this.
|
|
2478
|
-
this.figure.style.height = `${config.size}px`;
|
|
2479
|
-
this.figure.style.background = this.accentColor;
|
|
2720
|
+
if (this.nameTextEl) {
|
|
2721
|
+
renderSafeText(this.nameTextEl, config.avatarName);
|
|
2480
2722
|
}
|
|
2481
|
-
if (this.
|
|
2482
|
-
|
|
2723
|
+
if (this.chatActionBtn) {
|
|
2724
|
+
const span = this.chatActionBtn.querySelector("span");
|
|
2725
|
+
if (span) {
|
|
2726
|
+
renderSafeText(span, `Chat with ${config.avatarName}`);
|
|
2727
|
+
}
|
|
2483
2728
|
}
|
|
2484
2729
|
if (this.root) {
|
|
2485
2730
|
this.root.setAttribute("aria-label", config.avatarName);
|
|
2486
2731
|
}
|
|
2487
|
-
if (!this.isAssetLoadedFlag
|
|
2488
|
-
this.
|
|
2732
|
+
if (!this.isAssetLoadedFlag) {
|
|
2733
|
+
if (this.figure) {
|
|
2734
|
+
this.figure.classList.remove("asiyst-3d-active");
|
|
2735
|
+
this.figure.style.width = `${config.size}px`;
|
|
2736
|
+
this.figure.style.height = `${config.size}px`;
|
|
2737
|
+
this.figure.style.background = this.accentColor;
|
|
2738
|
+
}
|
|
2739
|
+
if (this.chatActionBtn) {
|
|
2740
|
+
this.chatActionBtn.style.display = "none";
|
|
2741
|
+
}
|
|
2742
|
+
if (this.viewport) {
|
|
2743
|
+
this.renderFallback();
|
|
2744
|
+
}
|
|
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
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
setPanelOpen(open) {
|
|
2755
|
+
this.isPanelOpen = open;
|
|
2756
|
+
if (this.chatActionBtn && this.isAssetLoadedFlag) {
|
|
2757
|
+
this.chatActionBtn.style.display = open ? "none" : "inline-flex";
|
|
2489
2758
|
}
|
|
2490
2759
|
}
|
|
2491
2760
|
async loadAsset(config) {
|
|
@@ -2506,7 +2775,7 @@ var CssAvatarRenderer = class {
|
|
|
2506
2775
|
}
|
|
2507
2776
|
this.renderLoader();
|
|
2508
2777
|
try {
|
|
2509
|
-
const asset = await this.assetLoader.load(assetUrl);
|
|
2778
|
+
const asset = await this.assetLoader.load(assetUrl, { timeoutMs: 6e4 });
|
|
2510
2779
|
await this.renderLoadedAsset(asset, config);
|
|
2511
2780
|
this.renderState = "ready";
|
|
2512
2781
|
this.isAssetLoadedFlag = true;
|
|
@@ -2514,6 +2783,13 @@ var CssAvatarRenderer = class {
|
|
|
2514
2783
|
this.loadedFormat = asset.format;
|
|
2515
2784
|
if (this.figure) {
|
|
2516
2785
|
this.figure.setAttribute("data-state", "ready");
|
|
2786
|
+
this.figure.classList.add("asiyst-3d-active");
|
|
2787
|
+
this.figure.style.width = "";
|
|
2788
|
+
this.figure.style.height = "";
|
|
2789
|
+
this.figure.style.background = "transparent";
|
|
2790
|
+
}
|
|
2791
|
+
if (this.chatActionBtn) {
|
|
2792
|
+
this.chatActionBtn.style.display = this.isPanelOpen ? "none" : "inline-flex";
|
|
2517
2793
|
}
|
|
2518
2794
|
return true;
|
|
2519
2795
|
} catch (err) {
|
|
@@ -2524,6 +2800,13 @@ var CssAvatarRenderer = class {
|
|
|
2524
2800
|
this.isFallbackFlag = true;
|
|
2525
2801
|
if (this.figure) {
|
|
2526
2802
|
this.figure.setAttribute("data-state", "error");
|
|
2803
|
+
this.figure.classList.remove("asiyst-3d-active");
|
|
2804
|
+
this.figure.style.width = `${this.size}px`;
|
|
2805
|
+
this.figure.style.height = `${this.size}px`;
|
|
2806
|
+
this.figure.style.background = this.accentColor;
|
|
2807
|
+
}
|
|
2808
|
+
if (this.chatActionBtn) {
|
|
2809
|
+
this.chatActionBtn.style.display = "none";
|
|
2527
2810
|
}
|
|
2528
2811
|
this.renderFallback(true);
|
|
2529
2812
|
return false;
|
|
@@ -2545,10 +2828,15 @@ var CssAvatarRenderer = class {
|
|
|
2545
2828
|
this.fbxRenderer = null;
|
|
2546
2829
|
}
|
|
2547
2830
|
if (asset.format === "fbx" || asset.format === "glb") {
|
|
2831
|
+
const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
|
|
2832
|
+
const width = isMobile ? 180 : 240;
|
|
2833
|
+
const height = isMobile ? 360 : 460;
|
|
2548
2834
|
this.fbxRenderer = new FbxRenderer();
|
|
2549
2835
|
this.renderMetrics = await this.fbxRenderer.mount(this.viewport, asset, {
|
|
2550
2836
|
accentColor: this.accentColor,
|
|
2551
|
-
config
|
|
2837
|
+
config,
|
|
2838
|
+
width,
|
|
2839
|
+
height
|
|
2552
2840
|
});
|
|
2553
2841
|
this.fbxRenderer.setFacing(this.facing);
|
|
2554
2842
|
this.fbxRenderer.setPose(this.pose);
|
|
@@ -2564,7 +2852,7 @@ var CssAvatarRenderer = class {
|
|
|
2564
2852
|
const thumb = typeof asset.manifest.thumbnailUrl === "string" ? asset.manifest.thumbnailUrl : void 0;
|
|
2565
2853
|
const modelUrl = typeof asset.manifest.assetUrl === "string" ? asset.manifest.assetUrl : typeof asset.manifest.modelUrl === "string" ? asset.manifest.modelUrl : void 0;
|
|
2566
2854
|
if (modelUrl) {
|
|
2567
|
-
const subAsset = await this.assetLoader.load(modelUrl);
|
|
2855
|
+
const subAsset = await this.assetLoader.load(modelUrl, { timeoutMs: 6e4 });
|
|
2568
2856
|
await this.renderLoadedAsset(subAsset, config);
|
|
2569
2857
|
} else if (thumb) {
|
|
2570
2858
|
this.viewport.replaceChildren();
|
|
@@ -2596,7 +2884,6 @@ var CssAvatarRenderer = class {
|
|
|
2596
2884
|
if (isError) {
|
|
2597
2885
|
const badge = doc.createElement("span");
|
|
2598
2886
|
badge.className = "asiyst-avatar-fallback-badge";
|
|
2599
|
-
badge.setAttribute("title", "Avatar asset failed to load");
|
|
2600
2887
|
badge.textContent = "!";
|
|
2601
2888
|
fallback.appendChild(badge);
|
|
2602
2889
|
}
|
|
@@ -2604,66 +2891,72 @@ var CssAvatarRenderer = class {
|
|
|
2604
2891
|
}
|
|
2605
2892
|
setPosition(x, y, animate) {
|
|
2606
2893
|
if (!this.root) return;
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2894
|
+
if (animate) {
|
|
2895
|
+
this.root.classList.add("asiyst-animate");
|
|
2896
|
+
} else {
|
|
2897
|
+
this.root.classList.remove("asiyst-animate");
|
|
2898
|
+
}
|
|
2899
|
+
this.root.style.left = `${Math.round(x)}px`;
|
|
2900
|
+
this.root.style.top = `${Math.round(y)}px`;
|
|
2610
2901
|
}
|
|
2611
2902
|
setFacing(direction) {
|
|
2612
2903
|
this.facing = direction;
|
|
2613
2904
|
this.fbxRenderer?.setFacing(direction);
|
|
2614
|
-
this.syncTransform();
|
|
2615
2905
|
}
|
|
2616
2906
|
setPose(pose) {
|
|
2617
2907
|
this.pose = pose;
|
|
2908
|
+
if (this.figure) {
|
|
2909
|
+
this.figure.setAttribute("data-pose", pose);
|
|
2910
|
+
}
|
|
2911
|
+
if (this.statusTextEl) {
|
|
2912
|
+
const displayStatus = pose === "speak" ? "(SPEAKING)" : pose === "think" ? "(THINKING)" : pose === "celebrate" ? "(CELEBRATING)" : "(IDLE)";
|
|
2913
|
+
this.statusTextEl.textContent = displayStatus;
|
|
2914
|
+
}
|
|
2618
2915
|
this.fbxRenderer?.setPose(pose);
|
|
2619
|
-
this.figure?.setAttribute("data-pose", pose);
|
|
2620
|
-
this.syncTransform();
|
|
2621
|
-
}
|
|
2622
|
-
syncTransform() {
|
|
2623
|
-
if (!this.figure) return;
|
|
2624
|
-
const face = this.facing === "left" ? "scaleX(-1)" : "";
|
|
2625
|
-
const pose = this.pose === "point" ? "rotate(-12deg)" : this.pose === "celebrate" ? "scale(1.08)" : "";
|
|
2626
|
-
this.figure.style.transform = `${face} ${pose}`.trim();
|
|
2627
2916
|
}
|
|
2628
2917
|
setSpeech(text) {
|
|
2629
2918
|
if (!this.bubble) return;
|
|
2630
2919
|
if (!text) {
|
|
2631
2920
|
this.bubble.hidden = true;
|
|
2632
|
-
this.bubble.
|
|
2921
|
+
this.bubble.replaceChildren();
|
|
2633
2922
|
return;
|
|
2634
2923
|
}
|
|
2635
2924
|
this.bubble.hidden = false;
|
|
2636
2925
|
renderSafeText(this.bubble, text);
|
|
2637
2926
|
}
|
|
2638
2927
|
getSize() {
|
|
2928
|
+
if (this.isAssetLoadedFlag && (this.loadedFormat === "fbx" || this.loadedFormat === "glb")) {
|
|
2929
|
+
const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
|
|
2930
|
+
return { width: isMobile ? 180 : 240, height: isMobile ? 390 : 490 };
|
|
2931
|
+
}
|
|
2639
2932
|
return { width: this.size, height: this.size + 28 };
|
|
2640
2933
|
}
|
|
2641
2934
|
setHidden(hidden) {
|
|
2642
2935
|
this.hidden = hidden;
|
|
2643
2936
|
if (this.root) {
|
|
2644
|
-
this.root.
|
|
2937
|
+
this.root.style.display = hidden ? "none" : "";
|
|
2645
2938
|
}
|
|
2646
2939
|
}
|
|
2647
2940
|
isHidden() {
|
|
2648
2941
|
return this.hidden;
|
|
2649
2942
|
}
|
|
2650
|
-
|
|
2651
|
-
return this.
|
|
2652
|
-
}
|
|
2653
|
-
getViewport() {
|
|
2654
|
-
return this.viewport;
|
|
2943
|
+
getRenderState() {
|
|
2944
|
+
return this.renderState;
|
|
2655
2945
|
}
|
|
2656
2946
|
isAssetLoaded() {
|
|
2657
2947
|
return this.isAssetLoadedFlag;
|
|
2658
2948
|
}
|
|
2659
|
-
|
|
2660
|
-
return this.
|
|
2949
|
+
getViewport() {
|
|
2950
|
+
return this.viewport;
|
|
2951
|
+
}
|
|
2952
|
+
isFallback() {
|
|
2953
|
+
return this.isFallbackFlag;
|
|
2661
2954
|
}
|
|
2662
2955
|
isFallbackActive() {
|
|
2663
2956
|
return this.isFallbackFlag;
|
|
2664
2957
|
}
|
|
2665
|
-
|
|
2666
|
-
return this.
|
|
2958
|
+
isRendered() {
|
|
2959
|
+
return this.isAssetLoadedFlag && (this.fbxRenderer ? this.fbxRenderer.isRendered() : true);
|
|
2667
2960
|
}
|
|
2668
2961
|
getLoadedFormat() {
|
|
2669
2962
|
return this.loadedFormat;
|
|
@@ -2677,6 +2970,18 @@ var CssAvatarRenderer = class {
|
|
|
2677
2970
|
getMetrics() {
|
|
2678
2971
|
return this.renderMetrics;
|
|
2679
2972
|
}
|
|
2973
|
+
getFigure() {
|
|
2974
|
+
return this.figure;
|
|
2975
|
+
}
|
|
2976
|
+
getFbxRenderer() {
|
|
2977
|
+
return this.fbxRenderer;
|
|
2978
|
+
}
|
|
2979
|
+
getChatActionBtn() {
|
|
2980
|
+
return this.chatActionBtn;
|
|
2981
|
+
}
|
|
2982
|
+
getNameTag() {
|
|
2983
|
+
return this.nameTagEl;
|
|
2984
|
+
}
|
|
2680
2985
|
};
|
|
2681
2986
|
|
|
2682
2987
|
// src/accessibility/a11y.ts
|
|
@@ -2860,6 +3165,8 @@ var MovementEngine = class {
|
|
|
2860
3165
|
this.onViewport = throttle(() => {
|
|
2861
3166
|
if (this.followTarget) {
|
|
2862
3167
|
this.placeBeside(this.followTarget, false);
|
|
3168
|
+
} else {
|
|
3169
|
+
this.goToAnchor();
|
|
2863
3170
|
}
|
|
2864
3171
|
}, VIEWPORT_HANDLER_THROTTLE_MS);
|
|
2865
3172
|
}
|
|
@@ -3014,6 +3321,9 @@ function isLikelyJavaScriptUrl(value) {
|
|
|
3014
3321
|
const lower = value.trim().toLowerCase();
|
|
3015
3322
|
return lower.startsWith("javascript:") || lower.startsWith("data:") || lower.startsWith("vbscript:") || lower.includes("eval(") || lower.includes("new function") || lower.includes("document.cookie");
|
|
3016
3323
|
}
|
|
3324
|
+
function isLocalHost(host) {
|
|
3325
|
+
return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]";
|
|
3326
|
+
}
|
|
3017
3327
|
function validateWebsiteDomain(config, currentUrl) {
|
|
3018
3328
|
const allowedDomains = config.allowedDomains.map((domain) => normalizeHost(domain));
|
|
3019
3329
|
if (allowedDomains.length === 0) {
|
|
@@ -3022,7 +3332,16 @@ function validateWebsiteDomain(config, currentUrl) {
|
|
|
3022
3332
|
try {
|
|
3023
3333
|
const parsed = new URL(currentUrl);
|
|
3024
3334
|
const host = normalizeHost(parsed.host);
|
|
3025
|
-
const
|
|
3335
|
+
const hostIsLocal = isLocalHost(host);
|
|
3336
|
+
const allowed = allowedDomains.some((domain) => {
|
|
3337
|
+
if (host === domain || host.endsWith(`.${domain}`)) {
|
|
3338
|
+
return true;
|
|
3339
|
+
}
|
|
3340
|
+
if (hostIsLocal && isLocalHost(domain)) {
|
|
3341
|
+
return true;
|
|
3342
|
+
}
|
|
3343
|
+
return false;
|
|
3344
|
+
});
|
|
3026
3345
|
if (!allowed) {
|
|
3027
3346
|
return { allowed: false, reason: "DOMAIN_NOT_AUTHORIZED" };
|
|
3028
3347
|
}
|
|
@@ -3465,27 +3784,39 @@ var ConversationPanel = class {
|
|
|
3465
3784
|
this.style.textContent = `
|
|
3466
3785
|
.asiyst-panel {
|
|
3467
3786
|
position: fixed;
|
|
3468
|
-
right:
|
|
3469
|
-
bottom:
|
|
3470
|
-
width: min(
|
|
3471
|
-
max-height: min(
|
|
3472
|
-
background: #
|
|
3787
|
+
right: 256px;
|
|
3788
|
+
bottom: 20px;
|
|
3789
|
+
width: min(380px, calc(100vw - 280px));
|
|
3790
|
+
max-height: min(560px, 75vh);
|
|
3791
|
+
background: #ffffff;
|
|
3473
3792
|
color: #0f172a;
|
|
3474
|
-
border-radius:
|
|
3475
|
-
box-shadow: 0
|
|
3793
|
+
border-radius: 18px;
|
|
3794
|
+
box-shadow: 0 20px 48px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(15, 23, 42, 0.08);
|
|
3476
3795
|
display: flex;
|
|
3477
3796
|
flex-direction: column;
|
|
3478
|
-
font: 14px/1.45 system-ui, sans-serif;
|
|
3797
|
+
font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
3479
3798
|
overflow: hidden;
|
|
3799
|
+
z-index: 100000;
|
|
3800
|
+
transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
|
|
3801
|
+
}
|
|
3802
|
+
@media (max-width: 640px) {
|
|
3803
|
+
.asiyst-panel {
|
|
3804
|
+
right: 12px;
|
|
3805
|
+
bottom: 12px;
|
|
3806
|
+
left: 12px;
|
|
3807
|
+
width: auto;
|
|
3808
|
+
max-height: 70vh;
|
|
3809
|
+
}
|
|
3480
3810
|
}
|
|
3481
3811
|
.asiyst-panel[hidden] { display: none; }
|
|
3482
3812
|
.asiyst-panel header {
|
|
3483
3813
|
display: flex;
|
|
3484
3814
|
justify-content: space-between;
|
|
3485
3815
|
align-items: center;
|
|
3486
|
-
padding:
|
|
3816
|
+
padding: 14px 16px;
|
|
3487
3817
|
background: #0f172a;
|
|
3488
3818
|
color: #f8fafc;
|
|
3819
|
+
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
|
3489
3820
|
}
|
|
3490
3821
|
.asiyst-log { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
|
|
3491
3822
|
.asiyst-msg { padding: 8px 10px; border-radius: 10px; max-width: 90%; }
|
|
@@ -3674,23 +4005,36 @@ var RuntimeAuth = class {
|
|
|
3674
4005
|
const timeout = setTimeout(() => controller.abort(), 1e4);
|
|
3675
4006
|
let response;
|
|
3676
4007
|
try {
|
|
3677
|
-
|
|
4008
|
+
const baseUrl = this.options.apiBaseUrl.replace(/\/$/, "");
|
|
4009
|
+
const payload = JSON.stringify({
|
|
4010
|
+
projectId: this.options.projectId,
|
|
4011
|
+
publicKey: this.options.publicKey,
|
|
4012
|
+
installationId: this.options.installationId,
|
|
4013
|
+
origin: this.options.origin,
|
|
4014
|
+
environment: this.options.environment,
|
|
4015
|
+
sdkVersion: SDK_VERSION,
|
|
4016
|
+
capabilities: [...RUNTIME_CAPABILITIES]
|
|
4017
|
+
});
|
|
4018
|
+
response = await fetch(`${baseUrl}/sdk/runtime/token`, {
|
|
3678
4019
|
method: "POST",
|
|
3679
4020
|
headers: {
|
|
3680
4021
|
Accept: "application/json",
|
|
3681
4022
|
"Content-Type": "application/json"
|
|
3682
4023
|
},
|
|
3683
|
-
body:
|
|
3684
|
-
projectId: this.options.projectId,
|
|
3685
|
-
publicKey: this.options.publicKey,
|
|
3686
|
-
installationId: this.options.installationId,
|
|
3687
|
-
origin: this.options.origin,
|
|
3688
|
-
environment: this.options.environment,
|
|
3689
|
-
sdkVersion: SDK_VERSION,
|
|
3690
|
-
capabilities: [...RUNTIME_CAPABILITIES]
|
|
3691
|
-
}),
|
|
4024
|
+
body: payload,
|
|
3692
4025
|
signal: controller.signal
|
|
3693
4026
|
});
|
|
4027
|
+
if (response.status === 404) {
|
|
4028
|
+
response = await fetch(`${baseUrl}/api/v1/sdk/runtime/token`, {
|
|
4029
|
+
method: "POST",
|
|
4030
|
+
headers: {
|
|
4031
|
+
Accept: "application/json",
|
|
4032
|
+
"Content-Type": "application/json"
|
|
4033
|
+
},
|
|
4034
|
+
body: payload,
|
|
4035
|
+
signal: controller.signal
|
|
4036
|
+
});
|
|
4037
|
+
}
|
|
3694
4038
|
} catch {
|
|
3695
4039
|
throw new NetworkError("ASIYST runtime authentication is unavailable.");
|
|
3696
4040
|
} finally {
|
|
@@ -3837,6 +4181,9 @@ var AsiystRuntime = class {
|
|
|
3837
4181
|
this.connectionStatus = "disconnected";
|
|
3838
4182
|
this.verificationStatus = "not_detected";
|
|
3839
4183
|
this.rescanDebounced = debounce(() => this.rescan(), DOM_SCAN_DEBOUNCE_MS);
|
|
4184
|
+
this.isHeartbeatInFlight = false;
|
|
4185
|
+
this.lastHeartbeatTime = 0;
|
|
4186
|
+
this.registrationSucceeded = false;
|
|
3840
4187
|
if (!doc.body) {
|
|
3841
4188
|
throw new InitializationError("document.body is not available");
|
|
3842
4189
|
}
|
|
@@ -3844,7 +4191,7 @@ var AsiystRuntime = class {
|
|
|
3844
4191
|
this.installationId = loadOrCreateInstallationId(options.projectId);
|
|
3845
4192
|
this.visitorSessionId = options.visitorSessionId || `vsess_${Math.random().toString(36).slice(2, 10)}_${Date.now().toString(36)}`;
|
|
3846
4193
|
const isLocalOrigin = /^(localhost|127(?:\.\d{1,3}){3}|\[::1\])$/i.test(win.location.hostname);
|
|
3847
|
-
this.environment = options.
|
|
4194
|
+
this.environment = options.environment || (isLocalOrigin ? "development" : "production");
|
|
3848
4195
|
const transport = new HttpTransport({
|
|
3849
4196
|
apiBaseUrl: options.apiBaseUrl ?? DEFAULT_API_BASE_URL,
|
|
3850
4197
|
projectId: options.projectId,
|
|
@@ -3869,6 +4216,7 @@ var AsiystRuntime = class {
|
|
|
3869
4216
|
() => this.map.list()
|
|
3870
4217
|
);
|
|
3871
4218
|
this.renderer = new CssAvatarRenderer();
|
|
4219
|
+
this.renderer.onOpenChat = () => this.open();
|
|
3872
4220
|
this.renderer.mount(this.host.chrome, this.config.get());
|
|
3873
4221
|
this.highlights = new HighlightLayer(this.host.overlay, win);
|
|
3874
4222
|
this.movement = new MovementEngine(win, doc, this.renderer, this.resolver, this.events, () => this.config.get());
|
|
@@ -3891,6 +4239,7 @@ var AsiystRuntime = class {
|
|
|
3891
4239
|
(open) => {
|
|
3892
4240
|
const convId = this.panel.getConversationId();
|
|
3893
4241
|
this.cloud.setConversationId(convId);
|
|
4242
|
+
this.renderer.setPanelOpen(open);
|
|
3894
4243
|
if (open) {
|
|
3895
4244
|
this.analytics.track("assistant_opened");
|
|
3896
4245
|
this.events.emit("asiyst:conversation:started", { conversationId: convId });
|
|
@@ -3941,82 +4290,9 @@ var AsiystRuntime = class {
|
|
|
3941
4290
|
sdkVersion: SDK_VERSION
|
|
3942
4291
|
});
|
|
3943
4292
|
await this.registerInstallation();
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
origin: window.location.origin,
|
|
3948
|
-
environment: this.environment,
|
|
3949
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3950
|
-
});
|
|
3951
|
-
this.connectionStatus = heartbeat.ok ? "connected" : "disconnected";
|
|
3952
|
-
this.verificationStatus = heartbeat.verificationStatus === "verified" ? "connected" : heartbeat.verificationStatus ?? (heartbeat.ok ? "connected" : "not_detected");
|
|
3953
|
-
if (heartbeat.ok) {
|
|
3954
|
-
this.lifecycle.emit("sdk.connected", {
|
|
3955
|
-
projectId: this.options.projectId,
|
|
3956
|
-
origin: window.location.origin,
|
|
3957
|
-
environment: this.environment,
|
|
3958
|
-
installationId: this.installationId,
|
|
3959
|
-
sdkVersion: SDK_VERSION
|
|
3960
|
-
});
|
|
3961
|
-
if (heartbeat.verificationStatus === "connected" || heartbeat.verificationStatus === "verified") {
|
|
3962
|
-
this.lifecycle.emit("sdk.verified", {
|
|
3963
|
-
projectId: this.options.projectId,
|
|
3964
|
-
origin: window.location.origin,
|
|
3965
|
-
environment: this.environment,
|
|
3966
|
-
installationId: this.installationId,
|
|
3967
|
-
sdkVersion: SDK_VERSION
|
|
3968
|
-
});
|
|
3969
|
-
}
|
|
3970
|
-
if (heartbeat.versionOutdated) {
|
|
3971
|
-
this.lifecycle.emit("sdk.version_outdated", {
|
|
3972
|
-
projectId: this.options.projectId,
|
|
3973
|
-
origin: window.location.origin,
|
|
3974
|
-
environment: this.environment,
|
|
3975
|
-
installationId: this.installationId,
|
|
3976
|
-
sdkVersion: SDK_VERSION
|
|
3977
|
-
});
|
|
3978
|
-
}
|
|
3979
|
-
} else {
|
|
3980
|
-
const reason = heartbeat.verificationStatus ?? "unverified";
|
|
3981
|
-
this.lifecycle.emit("sdk.verification_failed", {
|
|
3982
|
-
projectId: this.options.projectId,
|
|
3983
|
-
origin: window.location.origin,
|
|
3984
|
-
environment: this.environment,
|
|
3985
|
-
status: reason,
|
|
3986
|
-
reason: "heartbeat_failed"
|
|
3987
|
-
});
|
|
3988
|
-
if (previousConnection) {
|
|
3989
|
-
this.lifecycle.emit("sdk.disconnected", {
|
|
3990
|
-
projectId: this.options.projectId,
|
|
3991
|
-
origin: window.location.origin,
|
|
3992
|
-
environment: this.environment,
|
|
3993
|
-
installationId: this.installationId,
|
|
3994
|
-
reason: "heartbeat_failed",
|
|
3995
|
-
status: reason
|
|
3996
|
-
});
|
|
3997
|
-
}
|
|
3998
|
-
}
|
|
3999
|
-
} catch (error) {
|
|
4000
|
-
this.connectionStatus = "offline";
|
|
4001
|
-
this.verificationStatus = "error";
|
|
4002
|
-
this.lifecycle.emit("sdk.verification_failed", {
|
|
4003
|
-
projectId: this.options.projectId,
|
|
4004
|
-
origin: window.location.origin,
|
|
4005
|
-
environment: this.environment,
|
|
4006
|
-
installationId: this.installationId,
|
|
4007
|
-
reason: "heartbeat_failed",
|
|
4008
|
-
category: error instanceof AuthenticationError ? "authorization" : "network"
|
|
4009
|
-
});
|
|
4010
|
-
if (previousConnection) {
|
|
4011
|
-
this.lifecycle.emit("sdk.disconnected", {
|
|
4012
|
-
projectId: this.options.projectId,
|
|
4013
|
-
origin: window.location.origin,
|
|
4014
|
-
environment: this.environment,
|
|
4015
|
-
reason: "heartbeat_failed",
|
|
4016
|
-
category: "network"
|
|
4017
|
-
});
|
|
4018
|
-
}
|
|
4019
|
-
}
|
|
4293
|
+
await this.sendHeartbeat();
|
|
4294
|
+
const doc = this.host.host.ownerDocument;
|
|
4295
|
+
this.startHeartbeatScheduler(doc);
|
|
4020
4296
|
this.events.emit("asiyst:ready", { projectId: this.options.projectId, configVersion: cfg.version });
|
|
4021
4297
|
void this.cloud.sendTelemetryEvent("avatar_runtime_initialized", {
|
|
4022
4298
|
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
@@ -4036,6 +4312,7 @@ var AsiystRuntime = class {
|
|
|
4036
4312
|
try {
|
|
4037
4313
|
const loaded = await this.renderer.loadAsset(cfg);
|
|
4038
4314
|
if (loaded) {
|
|
4315
|
+
this.movement.goToAnchor();
|
|
4039
4316
|
const format = this.renderer.getLoadedFormat();
|
|
4040
4317
|
const assetUrl = this.renderer.getAssetUrl();
|
|
4041
4318
|
const isRendered = this.renderer.isRendered();
|
|
@@ -4103,9 +4380,14 @@ var AsiystRuntime = class {
|
|
|
4103
4380
|
open() {
|
|
4104
4381
|
this.panel.open();
|
|
4105
4382
|
this.avatar.show();
|
|
4383
|
+
this.renderer.setPanelOpen(true);
|
|
4106
4384
|
}
|
|
4107
4385
|
close() {
|
|
4108
4386
|
this.panel.close();
|
|
4387
|
+
this.renderer.setPanelOpen(false);
|
|
4388
|
+
}
|
|
4389
|
+
getRenderer() {
|
|
4390
|
+
return this.renderer;
|
|
4109
4391
|
}
|
|
4110
4392
|
avatarApi() {
|
|
4111
4393
|
return this.avatar;
|
|
@@ -4141,6 +4423,16 @@ var AsiystRuntime = class {
|
|
|
4141
4423
|
return;
|
|
4142
4424
|
}
|
|
4143
4425
|
this.destroyed = true;
|
|
4426
|
+
if (this.heartbeatTimer) {
|
|
4427
|
+
clearInterval(this.heartbeatTimer);
|
|
4428
|
+
this.heartbeatTimer = void 0;
|
|
4429
|
+
}
|
|
4430
|
+
const doc = this.host.host.ownerDocument;
|
|
4431
|
+
if (doc && this.visibilityListener) {
|
|
4432
|
+
doc.removeEventListener("visibilitychange", this.visibilityListener);
|
|
4433
|
+
this.visibilityListener = void 0;
|
|
4434
|
+
}
|
|
4435
|
+
this.isHeartbeatInFlight = false;
|
|
4144
4436
|
if (this.pagehideListener) {
|
|
4145
4437
|
win.removeEventListener("pagehide", this.pagehideListener);
|
|
4146
4438
|
}
|
|
@@ -4160,6 +4452,135 @@ var AsiystRuntime = class {
|
|
|
4160
4452
|
this.events.removeAll();
|
|
4161
4453
|
await this.analytics.destroy();
|
|
4162
4454
|
}
|
|
4455
|
+
startHeartbeatScheduler(doc) {
|
|
4456
|
+
if (this.heartbeatTimer) {
|
|
4457
|
+
clearInterval(this.heartbeatTimer);
|
|
4458
|
+
}
|
|
4459
|
+
this.heartbeatTimer = setInterval(() => {
|
|
4460
|
+
if (!this.destroyed) {
|
|
4461
|
+
void this.sendHeartbeat(true);
|
|
4462
|
+
}
|
|
4463
|
+
}, HEARTBEAT_INTERVAL_MS);
|
|
4464
|
+
if (doc && typeof doc.addEventListener === "function") {
|
|
4465
|
+
this.visibilityListener = () => {
|
|
4466
|
+
if (!this.destroyed && doc.visibilityState === "visible" && Date.now() - this.lastHeartbeatTime > 3e4) {
|
|
4467
|
+
void this.sendHeartbeat(true);
|
|
4468
|
+
}
|
|
4469
|
+
};
|
|
4470
|
+
doc.addEventListener("visibilitychange", this.visibilityListener);
|
|
4471
|
+
}
|
|
4472
|
+
}
|
|
4473
|
+
async sendHeartbeat(_isPeriodic = false) {
|
|
4474
|
+
if (this.destroyed || this.isHeartbeatInFlight) {
|
|
4475
|
+
return false;
|
|
4476
|
+
}
|
|
4477
|
+
this.isHeartbeatInFlight = true;
|
|
4478
|
+
const previousConnection = this.connectionStatus === "connected";
|
|
4479
|
+
const origin = window.location.origin;
|
|
4480
|
+
const environment = this.environment;
|
|
4481
|
+
const installationId = this.installationId;
|
|
4482
|
+
try {
|
|
4483
|
+
if (!this.registrationSucceeded && installationId) {
|
|
4484
|
+
await this.registerInstallation();
|
|
4485
|
+
}
|
|
4486
|
+
const heartbeat = await this.cloud.heartbeat({
|
|
4487
|
+
origin,
|
|
4488
|
+
environment,
|
|
4489
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4490
|
+
});
|
|
4491
|
+
this.lastHeartbeatTime = Date.now();
|
|
4492
|
+
this.connectionStatus = heartbeat.ok ? "connected" : "disconnected";
|
|
4493
|
+
this.verificationStatus = heartbeat.verificationStatus === "verified" ? "connected" : heartbeat.verificationStatus ?? (heartbeat.ok ? "connected" : "not_detected");
|
|
4494
|
+
if (heartbeat.ok) {
|
|
4495
|
+
if (!previousConnection) {
|
|
4496
|
+
this.events.emit("asiyst:runtime:connected", {
|
|
4497
|
+
projectId: this.options.projectId,
|
|
4498
|
+
status: "connected",
|
|
4499
|
+
environment,
|
|
4500
|
+
origin
|
|
4501
|
+
});
|
|
4502
|
+
this.lifecycle.emit("sdk.connected", {
|
|
4503
|
+
projectId: this.options.projectId,
|
|
4504
|
+
origin,
|
|
4505
|
+
environment,
|
|
4506
|
+
installationId,
|
|
4507
|
+
sdkVersion: SDK_VERSION
|
|
4508
|
+
});
|
|
4509
|
+
}
|
|
4510
|
+
if (heartbeat.verificationStatus === "connected" || heartbeat.verificationStatus === "verified") {
|
|
4511
|
+
this.lifecycle.emit("sdk.verified", {
|
|
4512
|
+
projectId: this.options.projectId,
|
|
4513
|
+
origin,
|
|
4514
|
+
environment,
|
|
4515
|
+
installationId,
|
|
4516
|
+
sdkVersion: SDK_VERSION
|
|
4517
|
+
});
|
|
4518
|
+
}
|
|
4519
|
+
if (heartbeat.versionOutdated) {
|
|
4520
|
+
this.lifecycle.emit("sdk.version_outdated", {
|
|
4521
|
+
projectId: this.options.projectId,
|
|
4522
|
+
origin,
|
|
4523
|
+
environment,
|
|
4524
|
+
installationId,
|
|
4525
|
+
sdkVersion: SDK_VERSION
|
|
4526
|
+
});
|
|
4527
|
+
}
|
|
4528
|
+
return true;
|
|
4529
|
+
} else {
|
|
4530
|
+
const reason = heartbeat.verificationStatus ?? "unverified";
|
|
4531
|
+
this.lifecycle.emit("sdk.verification_failed", {
|
|
4532
|
+
projectId: this.options.projectId,
|
|
4533
|
+
origin,
|
|
4534
|
+
environment,
|
|
4535
|
+
status: reason,
|
|
4536
|
+
reason: "heartbeat_failed"
|
|
4537
|
+
});
|
|
4538
|
+
if (previousConnection) {
|
|
4539
|
+
this.events.emit("asiyst:runtime:disconnected", {
|
|
4540
|
+
projectId: this.options.projectId,
|
|
4541
|
+
reason: "heartbeat_failed"
|
|
4542
|
+
});
|
|
4543
|
+
this.lifecycle.emit("sdk.disconnected", {
|
|
4544
|
+
projectId: this.options.projectId,
|
|
4545
|
+
origin,
|
|
4546
|
+
environment,
|
|
4547
|
+
installationId,
|
|
4548
|
+
reason: "heartbeat_failed",
|
|
4549
|
+
status: reason
|
|
4550
|
+
});
|
|
4551
|
+
}
|
|
4552
|
+
return false;
|
|
4553
|
+
}
|
|
4554
|
+
} catch (error) {
|
|
4555
|
+
this.connectionStatus = "offline";
|
|
4556
|
+
this.verificationStatus = "error";
|
|
4557
|
+
this.lifecycle.emit("sdk.verification_failed", {
|
|
4558
|
+
projectId: this.options.projectId,
|
|
4559
|
+
origin,
|
|
4560
|
+
environment,
|
|
4561
|
+
installationId,
|
|
4562
|
+
reason: "heartbeat_failed",
|
|
4563
|
+
category: error instanceof AuthenticationError ? "authorization" : "network"
|
|
4564
|
+
});
|
|
4565
|
+
if (previousConnection) {
|
|
4566
|
+
this.events.emit("asiyst:runtime:disconnected", {
|
|
4567
|
+
projectId: this.options.projectId,
|
|
4568
|
+
reason: "heartbeat_failed"
|
|
4569
|
+
});
|
|
4570
|
+
this.lifecycle.emit("sdk.disconnected", {
|
|
4571
|
+
projectId: this.options.projectId,
|
|
4572
|
+
origin,
|
|
4573
|
+
environment,
|
|
4574
|
+
installationId,
|
|
4575
|
+
reason: "heartbeat_failed",
|
|
4576
|
+
category: "network"
|
|
4577
|
+
});
|
|
4578
|
+
}
|
|
4579
|
+
return false;
|
|
4580
|
+
} finally {
|
|
4581
|
+
this.isHeartbeatInFlight = false;
|
|
4582
|
+
}
|
|
4583
|
+
}
|
|
4163
4584
|
async registerInstallation() {
|
|
4164
4585
|
const origin = window.location.origin;
|
|
4165
4586
|
const environment = this.environment;
|
|
@@ -4181,6 +4602,7 @@ var AsiystRuntime = class {
|
|
|
4181
4602
|
environment,
|
|
4182
4603
|
sdk_version: SDK_VERSION
|
|
4183
4604
|
});
|
|
4605
|
+
this.registrationSucceeded = true;
|
|
4184
4606
|
return;
|
|
4185
4607
|
} catch (error) {
|
|
4186
4608
|
lastError = error;
|
|
@@ -4280,6 +4702,9 @@ var Asiyst = {
|
|
|
4280
4702
|
getVerificationStatus() {
|
|
4281
4703
|
return requireRuntime().getVerificationStatus();
|
|
4282
4704
|
},
|
|
4705
|
+
isRuntimeConnected() {
|
|
4706
|
+
return requireRuntime().getConnectionStatus() === "connected";
|
|
4707
|
+
},
|
|
4283
4708
|
avatar: {
|
|
4284
4709
|
show() {
|
|
4285
4710
|
withIsolation(() => requireRuntime().avatarApi().show());
|