@asiyst/sdk 0.1.28 → 0.1.29

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.js CHANGED
@@ -2209,6 +2209,7 @@ var FbxRenderer = class {
2209
2209
  this.facing = "right";
2210
2210
  this.currentPose = "idle";
2211
2211
  this.initialRenderCompleted = false;
2212
+ this.baseScale = 1;
2212
2213
  }
2213
2214
  async mount(container, asset, options) {
2214
2215
  const doc = container.ownerDocument;
@@ -2226,13 +2227,17 @@ var FbxRenderer = class {
2226
2227
  throw new Error("WebGLRenderingContext is not available or supported in this browser environment");
2227
2228
  }
2228
2229
  const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
2229
- const width = options?.width || (isMobile ? 180 : 240);
2230
- const height = options?.height || (isMobile ? 360 : 460);
2230
+ const width = options?.width || (isMobile ? 140 : 190);
2231
+ const height = options?.height || (isMobile ? 280 : 360);
2231
2232
  const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
2232
2233
  this.canvas.width = Math.round(width * dpr);
2233
2234
  this.canvas.height = Math.round(height * dpr);
2234
2235
  this.canvas.style.width = `${width}px`;
2235
2236
  this.canvas.style.height = `${height}px`;
2237
+ this.canvas.style.pointerEvents = "none";
2238
+ this.canvas.style.border = "none";
2239
+ this.canvas.style.outline = "none";
2240
+ this.canvas.style.boxShadow = "none";
2236
2241
  try {
2237
2242
  this.renderer = new THREE.WebGLRenderer({
2238
2243
  canvas: this.canvas,
@@ -2259,6 +2264,13 @@ var FbxRenderer = class {
2259
2264
  keyLight.castShadow = true;
2260
2265
  keyLight.shadow.mapSize.width = 512;
2261
2266
  keyLight.shadow.mapSize.height = 512;
2267
+ keyLight.shadow.camera.near = 0.5;
2268
+ keyLight.shadow.camera.far = 15;
2269
+ keyLight.shadow.camera.left = -1.5;
2270
+ keyLight.shadow.camera.right = 1.5;
2271
+ keyLight.shadow.camera.top = 2.5;
2272
+ keyLight.shadow.camera.bottom = -0.5;
2273
+ keyLight.shadow.bias = -5e-4;
2262
2274
  this.scene.add(keyLight);
2263
2275
  const fillLight = new THREE.DirectionalLight(15459032, 1.2);
2264
2276
  fillLight.position.set(-3, 2, 2);
@@ -2267,7 +2279,13 @@ var FbxRenderer = class {
2267
2279
  rimLight.position.set(0, 4, -3);
2268
2280
  this.scene.add(rimLight);
2269
2281
  const shadowGeo = new THREE.PlaneGeometry(3, 3);
2270
- const shadowMat = new THREE.ShadowMaterial({ opacity: 0.15 });
2282
+ const shadowMat = new THREE.ShadowMaterial({
2283
+ opacity: 0.12,
2284
+ depthWrite: false
2285
+ });
2286
+ shadowMat.polygonOffset = true;
2287
+ shadowMat.polygonOffsetFactor = -1;
2288
+ shadowMat.polygonOffsetUnits = -4;
2271
2289
  const shadowPlane = new THREE.Mesh(shadowGeo, shadowMat);
2272
2290
  shadowPlane.rotation.x = -Math.PI / 2;
2273
2291
  shadowPlane.position.y = 0;
@@ -2319,14 +2337,18 @@ var FbxRenderer = class {
2319
2337
  rawObject.position.set(-rawCenter.x, -rawBox.min.y, -rawCenter.z);
2320
2338
  const targetVisualHeight = 1.8;
2321
2339
  const targetScale = targetVisualHeight / rawHeight;
2340
+ this.baseScale = targetScale;
2322
2341
  this.modelRoot = new THREE.Group();
2323
2342
  this.modelRoot.add(rawObject);
2324
2343
  this.modelRoot.scale.setScalar(targetScale);
2325
2344
  this.scene.add(this.modelRoot);
2326
- const visualCenterY = targetVisualHeight * 0.52;
2345
+ const visualCenterY = targetVisualHeight * 0.5;
2327
2346
  const fovRadians = this.camera.fov * Math.PI / 180;
2328
- const fitDist = Math.max(2.4, targetVisualHeight / 2 / Math.tan(fovRadians / 2) * 1.25);
2329
- this.camera.position.set(0, visualCenterY + 0.1, fitDist);
2347
+ const aspect = width / height;
2348
+ const fitDistV = targetVisualHeight * 1.35 / 2 / Math.tan(fovRadians / 2);
2349
+ const fitDistH = 1.1 / 2 / (aspect * Math.tan(fovRadians / 2));
2350
+ const fitDist = Math.max(fitDistV, fitDistH, 2.85);
2351
+ this.camera.position.set(0, visualCenterY, fitDist);
2330
2352
  this.camera.lookAt(0, visualCenterY, 0);
2331
2353
  rawObject.traverse((child) => {
2332
2354
  const mesh = child;
@@ -2335,20 +2357,25 @@ var FbxRenderer = class {
2335
2357
  mesh.receiveShadow = true;
2336
2358
  }
2337
2359
  });
2360
+ options?.metricsTracker?.record("sceneInitComplete");
2338
2361
  this.rawObject = rawObject;
2339
2362
  this.mixer = new THREE.AnimationMixer(rawObject);
2340
2363
  this.allAnimations = [...modelAnimations];
2341
2364
  const externalAnims = options?.config?.animations || options?.config?.avatar?.animations || [];
2342
2365
  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);
2366
+ if (modelAnimations.length === 0) {
2367
+ try {
2368
+ await Promise.race([
2369
+ this.loadExternalAnimations(externalAnims, options?.config?.animation),
2370
+ new Promise((resolve) => setTimeout(resolve, 2500))
2371
+ ]);
2372
+ } catch (animErr) {
2373
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
2374
+ console.warn("[asiyst] External animation loading notice:", animErr);
2375
+ }
2351
2376
  }
2377
+ } else {
2378
+ void this.loadExternalAnimations(externalAnims, options?.config?.animation);
2352
2379
  }
2353
2380
  }
2354
2381
  this.startInitialIdleAnimation(options?.config);
@@ -2360,9 +2387,11 @@ var FbxRenderer = class {
2360
2387
  try {
2361
2388
  this.renderer.render(this.scene, this.camera);
2362
2389
  this.initialRenderCompleted = true;
2390
+ options?.metricsTracker?.record("firstRenderedFrame");
2363
2391
  if (this.canvas) {
2364
2392
  this.canvas.style.opacity = "1";
2365
2393
  }
2394
+ options?.metricsTracker?.record("firstVisibleCorrectlyFramed");
2366
2395
  } catch (renderErr) {
2367
2396
  const msg = renderErr instanceof Error ? renderErr.message : String(renderErr);
2368
2397
  throw new Error(`Initial FBX WebGL render failed: ${msg}`);
@@ -2401,6 +2430,18 @@ var FbxRenderer = class {
2401
2430
  targetClip = this.allAnimations.find(
2402
2431
  (c) => c.name.toLowerCase().includes("think")
2403
2432
  );
2433
+ } else if (pose === "walk") {
2434
+ targetClip = this.allAnimations.find(
2435
+ (c) => c.name.toLowerCase().includes("walk") || c.name.toLowerCase().includes("run")
2436
+ );
2437
+ } else if (pose === "point") {
2438
+ targetClip = this.allAnimations.find(
2439
+ (c) => c.name.toLowerCase().includes("point")
2440
+ );
2441
+ } else if (pose === "celebrate") {
2442
+ targetClip = this.allAnimations.find(
2443
+ (c) => c.name.toLowerCase().includes("celebrat") || c.name.toLowerCase().includes("wave") || c.name.toLowerCase().includes("cheer") || c.name.toLowerCase().includes("jump")
2444
+ );
2404
2445
  } else {
2405
2446
  targetClip = this.allAnimations.find((c) => c.name.toLowerCase().includes("idle")) || this.animationMetadataList[0]?.clip || this.allAnimations[0];
2406
2447
  }
@@ -2421,23 +2462,28 @@ var FbxRenderer = class {
2421
2462
  }
2422
2463
  }
2423
2464
  if (!this.modelRoot) return;
2465
+ this.modelRoot.scale.setScalar(this.baseScale);
2424
2466
  switch (pose) {
2425
2467
  case "point":
2426
- this.modelRoot.rotation.z = -0.15;
2427
- this.modelRoot.rotation.x = 0.08;
2468
+ this.modelRoot.rotation.z = -0.06;
2469
+ this.modelRoot.rotation.x = 0.03;
2428
2470
  break;
2429
2471
  case "think":
2430
- this.modelRoot.rotation.z = 0.12;
2431
- this.modelRoot.rotation.x = -0.1;
2472
+ this.modelRoot.rotation.z = 0.05;
2473
+ this.modelRoot.rotation.x = -0.04;
2432
2474
  break;
2433
2475
  case "speak":
2434
2476
  this.modelRoot.rotation.y = this.facing === "left" ? -0.22 : 0.22;
2435
- this.modelRoot.rotation.x = 0.04;
2477
+ this.modelRoot.rotation.x = 0.03;
2436
2478
  break;
2437
2479
  case "celebrate":
2438
2480
  this.modelRoot.rotation.z = 0;
2439
- this.modelRoot.rotation.x = -0.15;
2440
- this.modelRoot.scale.multiplyScalar(1.05);
2481
+ this.modelRoot.rotation.x = -0.06;
2482
+ break;
2483
+ case "walk":
2484
+ this.modelRoot.rotation.z = 0;
2485
+ this.modelRoot.rotation.x = 0.03;
2486
+ this.modelRoot.rotation.y = this.facing === "left" ? -0.35 : 0.35;
2441
2487
  break;
2442
2488
  default:
2443
2489
  this.modelRoot.rotation.z = 0;
@@ -2496,49 +2542,61 @@ var FbxRenderer = class {
2496
2542
  }
2497
2543
  async loadExternalAnimations(animations, targetAnimationName) {
2498
2544
  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
- }
2545
+ const pending = animations.filter(
2546
+ (anim) => {
2547
+ if (!anim.assetUrl) return false;
2548
+ const key = (anim.id || anim.name).toLowerCase();
2549
+ return !this.animationMetadataList.some(
2550
+ (m) => m.id && m.id.toLowerCase() === key || m.name.toLowerCase() === key
2551
+ );
2541
2552
  }
2553
+ );
2554
+ if (pending.length > 0) {
2555
+ await Promise.allSettled(
2556
+ pending.map(async (anim) => {
2557
+ try {
2558
+ const loaded = await this.assetLoader.load(anim.assetUrl);
2559
+ let extractedClips = [];
2560
+ if (loaded.format === "fbx") {
2561
+ const loader = new FBXLoader();
2562
+ if (loaded.resourcePath) {
2563
+ loader.setResourcePath(loaded.resourcePath);
2564
+ }
2565
+ const parsed = loader.parse(loaded.buffer, loaded.resourcePath || "");
2566
+ extractedClips = parsed.animations || [];
2567
+ } else if (loaded.format === "glb") {
2568
+ const loader = new GLTFLoader();
2569
+ const gltf = await new Promise((resolve, reject) => {
2570
+ const glbBuffer = loaded.bin.buffer.slice(
2571
+ loaded.bin.byteOffset,
2572
+ loaded.bin.byteOffset + loaded.bin.byteLength
2573
+ );
2574
+ loader.parse(glbBuffer, loaded.url, resolve, reject);
2575
+ });
2576
+ extractedClips = gltf.animations || [];
2577
+ }
2578
+ for (const rawClip of extractedClips) {
2579
+ const retargeted = this.retargetClip(rawClip, this.rawObject);
2580
+ if (!retargeted) continue;
2581
+ retargeted.name = anim.clipName || anim.name || rawClip.name;
2582
+ this.allAnimations.push(retargeted);
2583
+ this.animationMetadataList.push({
2584
+ id: anim.id,
2585
+ name: anim.name,
2586
+ intent: anim.intent,
2587
+ clipName: anim.clipName,
2588
+ loopMode: anim.loopMode,
2589
+ clip: retargeted
2590
+ });
2591
+ }
2592
+ } catch (err) {
2593
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
2594
+ const msg = err instanceof Error ? err.message : String(err);
2595
+ console.warn(`[asiyst] Failed to load external animation "${anim.name}": ${msg}`);
2596
+ }
2597
+ }
2598
+ })
2599
+ );
2542
2600
  }
2543
2601
  if (this.currentPose === "idle" || targetAnimationName) {
2544
2602
  this.startInitialIdleAnimation({ animation: targetAnimationName });
@@ -2675,9 +2733,17 @@ var FbxRenderer = class {
2675
2733
  }
2676
2734
  startLoop() {
2677
2735
  if (typeof requestAnimationFrame === "undefined") return;
2736
+ if (this.animFrameId !== null && typeof cancelAnimationFrame !== "undefined") {
2737
+ cancelAnimationFrame(this.animFrameId);
2738
+ this.animFrameId = null;
2739
+ }
2678
2740
  this.lastTime = typeof performance !== "undefined" ? performance.now() : Date.now();
2679
2741
  const tick = (now) => {
2680
2742
  if (!this.renderer || !this.scene || !this.camera) return;
2743
+ if (typeof document !== "undefined" && document.hidden) {
2744
+ this.animFrameId = requestAnimationFrame(tick);
2745
+ return;
2746
+ }
2681
2747
  const current = now || (typeof performance !== "undefined" ? performance.now() : Date.now());
2682
2748
  const delta = Math.min(Math.max((current - this.lastTime) / 1e3, 0), 0.1);
2683
2749
  this.lastTime = current;
@@ -2747,14 +2813,23 @@ var FbxRenderer = class {
2747
2813
  handleResize() {
2748
2814
  if (!this.canvas || !this.renderer || !this.camera) return;
2749
2815
  const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
2750
- const width = isMobile ? 180 : 240;
2751
- const height = isMobile ? 360 : 460;
2816
+ const width = isMobile ? 140 : 190;
2817
+ const height = isMobile ? 280 : 360;
2752
2818
  const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
2753
2819
  this.canvas.width = Math.round(width * dpr);
2754
2820
  this.canvas.height = Math.round(height * dpr);
2755
2821
  this.canvas.style.width = `${width}px`;
2756
2822
  this.canvas.style.height = `${height}px`;
2757
- this.camera.aspect = width / height;
2823
+ const aspect = width / height;
2824
+ this.camera.aspect = aspect;
2825
+ const targetVisualHeight = 1.8;
2826
+ const visualCenterY = targetVisualHeight * 0.5;
2827
+ const fovRadians = this.camera.fov * Math.PI / 180;
2828
+ const fitDistV = targetVisualHeight * 1.35 / 2 / Math.tan(fovRadians / 2);
2829
+ const fitDistH = 1.1 / 2 / (aspect * Math.tan(fovRadians / 2));
2830
+ const fitDist = Math.max(fitDistV, fitDistH, 2.85);
2831
+ this.camera.position.set(0, visualCenterY, fitDist);
2832
+ this.camera.lookAt(0, visualCenterY, 0);
2758
2833
  this.camera.updateProjectionMatrix();
2759
2834
  this.renderer.setPixelRatio(Math.min(dpr, 2));
2760
2835
  this.renderer.setSize(width, height, false);
@@ -2779,7 +2854,7 @@ var AVATAR_CSS = `
2779
2854
  flex-direction: column;
2780
2855
  align-items: center;
2781
2856
  gap: 4px;
2782
- pointer-events: auto;
2857
+ pointer-events: none;
2783
2858
  user-select: none;
2784
2859
  }
2785
2860
  .asiyst-avatar.asiyst-animate {
@@ -2790,11 +2865,27 @@ var AVATAR_CSS = `
2790
2865
  place-items: center;
2791
2866
  position: relative;
2792
2867
  cursor: pointer;
2793
- border: none;
2868
+ border: 0 !important;
2794
2869
  padding: 0;
2795
- outline: none;
2796
- background: transparent;
2870
+ margin: 0;
2871
+ outline: none !important;
2872
+ background: transparent !important;
2873
+ box-shadow: none !important;
2797
2874
  overflow: visible;
2875
+ -webkit-appearance: none;
2876
+ appearance: none;
2877
+ -webkit-tap-highlight-color: transparent;
2878
+ }
2879
+ .asiyst-figure:focus,
2880
+ .asiyst-figure:focus-visible,
2881
+ .asiyst-figure:active {
2882
+ outline: none !important;
2883
+ border: 0 !important;
2884
+ box-shadow: none !important;
2885
+ }
2886
+ .asiyst-figure::-moz-focus-inner {
2887
+ border: 0 !important;
2888
+ padding: 0;
2798
2889
  }
2799
2890
  .asiyst-figure.asiyst-compact-launcher {
2800
2891
  border-radius: 28px;
@@ -2802,20 +2893,24 @@ var AVATAR_CSS = `
2802
2893
  font: 700 14px/1.2 system-ui, sans-serif;
2803
2894
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.28);
2804
2895
  overflow: hidden;
2805
- background: #2563eb;
2896
+ background: #2563eb !important;
2897
+ pointer-events: auto;
2806
2898
  }
2807
2899
  .asiyst-figure.asiyst-3d-active {
2808
- width: 240px !important;
2809
- height: 460px !important;
2900
+ width: 190px !important;
2901
+ height: 360px !important;
2810
2902
  background: transparent !important;
2903
+ border: 0 !important;
2811
2904
  border-radius: 0 !important;
2812
2905
  box-shadow: none !important;
2906
+ outline: none !important;
2813
2907
  overflow: visible !important;
2908
+ pointer-events: none;
2814
2909
  }
2815
2910
  @media (max-width: 640px) {
2816
2911
  .asiyst-figure.asiyst-3d-active {
2817
- width: 180px !important;
2818
- height: 360px !important;
2912
+ width: 140px !important;
2913
+ height: 280px !important;
2819
2914
  }
2820
2915
  }
2821
2916
  .asiyst-avatar-viewport {
@@ -2824,16 +2919,23 @@ var AVATAR_CSS = `
2824
2919
  height: 100%;
2825
2920
  display: grid;
2826
2921
  place-items: center;
2922
+ border: 0 !important;
2923
+ outline: none !important;
2924
+ background: transparent !important;
2827
2925
  border-radius: inherit;
2828
2926
  overflow: visible;
2829
- pointer-events: auto;
2927
+ pointer-events: none;
2830
2928
  }
2831
2929
  .asiyst-avatar-canvas {
2832
2930
  width: 100%;
2833
2931
  height: 100%;
2834
2932
  object-fit: contain;
2835
2933
  display: block;
2836
- pointer-events: auto;
2934
+ border: 0 !important;
2935
+ outline: none !important;
2936
+ background: transparent !important;
2937
+ box-shadow: none !important;
2938
+ pointer-events: none;
2837
2939
  }
2838
2940
  .asiyst-avatar-graphic {
2839
2941
  width: 100%;
@@ -2983,6 +3085,9 @@ var CssAvatarRenderer = class {
2983
3085
  this.isAssetLoadedFlag = false;
2984
3086
  this.isFallbackFlag = false;
2985
3087
  }
3088
+ setMetricsTracker(tracker) {
3089
+ this.metricsTracker = tracker;
3090
+ }
2986
3091
  mount(container, config) {
2987
3092
  const doc = container.ownerDocument;
2988
3093
  const style = doc.createElement("style");
@@ -3119,7 +3224,10 @@ var CssAvatarRenderer = class {
3119
3224
  this.chatActionBtn.style.display = open ? "none" : "inline-flex";
3120
3225
  }
3121
3226
  }
3122
- async loadAsset(config) {
3227
+ async loadAsset(config, metricsTracker) {
3228
+ if (metricsTracker) {
3229
+ this.metricsTracker = metricsTracker;
3230
+ }
3123
3231
  const assetUrl = config.assetUrl ?? config.thumbnailUrl;
3124
3232
  if (!assetUrl) {
3125
3233
  this.renderState = "idle";
@@ -3151,8 +3259,16 @@ var CssAvatarRenderer = class {
3151
3259
  this.renderLoader();
3152
3260
  }
3153
3261
  try {
3262
+ this.metricsTracker?.record("assetRequestStart");
3154
3263
  const asset = await this.assetLoader.load(assetUrl, { timeoutMs: 6e4 });
3264
+ this.metricsTracker?.record("assetDownloadComplete");
3265
+ const byteSize = asset.buffer?.byteLength ?? asset.bin?.byteLength ?? asset.size;
3266
+ this.metricsTracker?.setAssetInfo({
3267
+ format: asset.format,
3268
+ byteSize: typeof byteSize === "number" ? byteSize : void 0
3269
+ });
3155
3270
  await this.renderLoadedAsset(asset, config);
3271
+ this.metricsTracker?.record("parseAndDecodeComplete");
3156
3272
  this.renderState = "ready";
3157
3273
  this.isAssetLoadedFlag = true;
3158
3274
  this.isFallbackFlag = false;
@@ -3216,14 +3332,20 @@ var CssAvatarRenderer = class {
3216
3332
  }
3217
3333
  if (asset.format === "fbx" || asset.format === "glb") {
3218
3334
  const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
3219
- const width = isMobile ? 180 : 240;
3220
- const height = isMobile ? 360 : 460;
3335
+ const width = isMobile ? 140 : 190;
3336
+ const height = isMobile ? 280 : 360;
3221
3337
  this.fbxRenderer = new FbxRenderer();
3222
3338
  this.renderMetrics = await this.fbxRenderer.mount(this.viewport, asset, {
3223
3339
  accentColor: this.accentColor,
3224
3340
  config,
3225
3341
  width,
3226
- height
3342
+ height,
3343
+ metricsTracker: this.metricsTracker
3344
+ });
3345
+ this.metricsTracker?.setAssetInfo({
3346
+ meshCount: this.renderMetrics.meshCount,
3347
+ vertexCount: this.renderMetrics.vertexCount,
3348
+ animationCount: this.renderMetrics.animationCount
3227
3349
  });
3228
3350
  this.fbxRenderer.setFacing(this.facing);
3229
3351
  this.fbxRenderer.setPose(this.pose);
@@ -3314,7 +3436,7 @@ var CssAvatarRenderer = class {
3314
3436
  getSize() {
3315
3437
  if (this.isAssetLoadedFlag || this.has3dAssetConfigured) {
3316
3438
  const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
3317
- return { width: isMobile ? 180 : 240, height: isMobile ? 390 : 490 };
3439
+ return { width: isMobile ? 140 : 190, height: isMobile ? 310 : 390 };
3318
3440
  }
3319
3441
  return { width: this.size, height: this.size + 28 };
3320
3442
  }
@@ -4174,9 +4296,9 @@ var ConversationPanel = class {
4174
4296
  this.style.textContent = `
4175
4297
  .asiyst-panel {
4176
4298
  position: fixed;
4177
- right: 256px;
4299
+ right: 216px;
4178
4300
  bottom: 20px;
4179
- width: min(380px, calc(100vw - 280px));
4301
+ width: min(380px, calc(100vw - 240px));
4180
4302
  max-height: min(560px, 75vh);
4181
4303
  background: #ffffff;
4182
4304
  color: #0f172a;
@@ -4560,10 +4682,59 @@ function createSdkLifecycleEmitter(sink) {
4560
4682
  return new LifecycleEmitter(new UnsupportedLifecycleSink());
4561
4683
  }
4562
4684
 
4685
+ // src/avatar/AvatarMetrics.ts
4686
+ var AvatarMetricsTracker = class {
4687
+ constructor() {
4688
+ this.timestamps = {};
4689
+ this.assetInfo = {};
4690
+ }
4691
+ record(step, timestamp = typeof performance !== "undefined" ? performance.now() : Date.now()) {
4692
+ if (!this.timestamps[step]) {
4693
+ this.timestamps[step] = timestamp;
4694
+ }
4695
+ }
4696
+ setAssetInfo(info) {
4697
+ this.assetInfo = { ...this.assetInfo, ...info };
4698
+ }
4699
+ getMetrics() {
4700
+ const t = this.timestamps;
4701
+ const base = t.sdkInit ?? t.containerCreated ?? 0;
4702
+ const downloadStart = t.assetRequestStart ?? base;
4703
+ const downloadEnd = t.assetDownloadComplete ?? downloadStart;
4704
+ const parseEnd = t.parseAndDecodeComplete ?? downloadEnd;
4705
+ const sceneEnd = t.sceneInitComplete ?? parseEnd;
4706
+ const firstRender = t.firstRenderedFrame ?? sceneEnd;
4707
+ const firstVisible = t.firstVisibleCorrectlyFramed ?? firstRender;
4708
+ return {
4709
+ timestamps: {
4710
+ sdkInit: t.sdkInit ?? base,
4711
+ containerCreated: t.containerCreated ?? base,
4712
+ configRetrieved: t.configRetrieved ?? base,
4713
+ assetRequestStart: downloadStart,
4714
+ assetDownloadComplete: downloadEnd,
4715
+ parseAndDecodeComplete: parseEnd,
4716
+ sceneInitComplete: sceneEnd,
4717
+ firstRenderedFrame: firstRender,
4718
+ firstVisibleCorrectlyFramed: firstVisible
4719
+ },
4720
+ durations: {
4721
+ configRetrievalMs: Math.max(0, (t.configRetrieved ?? base) - base),
4722
+ downloadDurationMs: Math.max(0, downloadEnd - downloadStart),
4723
+ parseDurationMs: Math.max(0, parseEnd - downloadEnd),
4724
+ sceneInitDurationMs: Math.max(0, sceneEnd - parseEnd),
4725
+ firstRenderDurationMs: Math.max(0, firstRender - sceneEnd),
4726
+ timeToFirstVisibleMs: Math.max(0, firstVisible - base)
4727
+ },
4728
+ asset: { ...this.assetInfo }
4729
+ };
4730
+ }
4731
+ };
4732
+
4563
4733
  // src/core/Runtime.ts
4564
4734
  var AsiystRuntime = class {
4565
4735
  constructor(options, doc, win) {
4566
4736
  this.events = new EventBus();
4737
+ this.metricsTracker = new AvatarMetricsTracker();
4567
4738
  this.map = new WebsiteMap();
4568
4739
  this.observer = new DomObserver(() => this.rescan());
4569
4740
  this.lifecycle = createSdkLifecycleEmitter();
@@ -4611,6 +4782,9 @@ var AsiystRuntime = class {
4611
4782
  this.renderer = new CssAvatarRenderer();
4612
4783
  this.renderer.onOpenChat = () => this.open();
4613
4784
  this.renderer.mount(this.host.chrome, this.config.get());
4785
+ this.metricsTracker.record("sdkInit");
4786
+ this.metricsTracker.record("containerCreated");
4787
+ this.renderer.setMetricsTracker(this.metricsTracker);
4614
4788
  this.highlights = new HighlightLayer(this.host.overlay, win);
4615
4789
  this.movement = new MovementEngine(win, doc, this.renderer, this.resolver, this.events, () => this.config.get());
4616
4790
  const live = createLiveRegion(this.host.shadow);
@@ -4661,7 +4835,10 @@ var AsiystRuntime = class {
4661
4835
  }
4662
4836
  async start() {
4663
4837
  this.events.emit("asiyst:initialized", { projectId: this.options.projectId });
4838
+ this.avatar.show();
4839
+ this.movement.goToAnchor();
4664
4840
  const cfg = await isolateAsync(() => this.config.refresh(), this.config.get());
4841
+ this.metricsTracker.record("configRetrieved");
4665
4842
  const domainCheck = validateWebsiteDomain(cfg, window.location.href);
4666
4843
  if (!domainCheck.allowed) {
4667
4844
  this.connectionStatus = "disconnected";
@@ -4720,7 +4897,7 @@ var AsiystRuntime = class {
4720
4897
  assetUrl: assetTarget
4721
4898
  });
4722
4899
  try {
4723
- const loaded = await this.renderer.loadAsset(cfg);
4900
+ const loaded = await this.renderer.loadAsset(cfg, this.metricsTracker);
4724
4901
  if (loaded) {
4725
4902
  this.movement.goToAnchor();
4726
4903
  const format = this.renderer.getLoadedFormat();
@@ -4739,15 +4916,19 @@ var AsiystRuntime = class {
4739
4916
  publishedVersion: cfg.publishedVersion
4740
4917
  });
4741
4918
  if (isRendered) {
4919
+ const metrics = this.metricsTracker.getMetrics();
4920
+ const durationMs = metrics?.durations.timeToFirstVisibleMs;
4742
4921
  this.events.emit("asiyst:avatar:rendered", {
4743
4922
  avatarId: this.options.avatarId ?? cfg.avatarId,
4744
- format
4923
+ format,
4924
+ durationMs
4745
4925
  });
4746
4926
  void this.cloud.sendTelemetryEvent("avatar_rendered", {
4747
4927
  avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
4748
4928
  avatarName: cfg.avatarName,
4749
4929
  format,
4750
- publishedVersion: cfg.publishedVersion
4930
+ publishedVersion: cfg.publishedVersion,
4931
+ durationMs
4751
4932
  });
4752
4933
  }
4753
4934
  return true;
@@ -4867,6 +5048,9 @@ var AsiystRuntime = class {
4867
5048
  getRenderer() {
4868
5049
  return this.renderer;
4869
5050
  }
5051
+ getAvatarPerformanceMetrics() {
5052
+ return this.metricsTracker.getMetrics();
5053
+ }
4870
5054
  avatarApi() {
4871
5055
  return this.avatar;
4872
5056
  }
@@ -5193,6 +5377,9 @@ var Asiyst = {
5193
5377
  isRuntimeConnected() {
5194
5378
  return requireRuntime().getConnectionStatus() === "connected";
5195
5379
  },
5380
+ getAvatarPerformanceMetrics() {
5381
+ return requireRuntime().getAvatarPerformanceMetrics();
5382
+ },
5196
5383
  avatar: {
5197
5384
  show() {
5198
5385
  withIsolation(() => requireRuntime().avatarApi().show());
@@ -5251,6 +5438,6 @@ var Asiyst = {
5251
5438
  }
5252
5439
  };
5253
5440
 
5254
- export { ActionNotAllowedError, Asiyst, AsiystError, AssetLoader, AuthenticationError, ConfigurationError, CssAvatarRenderer, FbxRenderer, InitializationError, NetworkError, SDK_VERSION, TargetNotFoundError, TaskExecutionError, TaskStatus, anchorToViewport, canNavigateTo, canTransition, computeAvatarDestination, evaluateActionPermission, fallbackConfig, isActionAllowed, isSafeSelector, normalizeProjectConfig, sanitizeText, validateInitOptions, validateWebsiteDomain };
5441
+ export { ActionNotAllowedError, Asiyst, AsiystError, AssetLoader, AuthenticationError, AvatarMetricsTracker, ConfigurationError, CssAvatarRenderer, FbxRenderer, InitializationError, NetworkError, SDK_VERSION, TargetNotFoundError, TaskExecutionError, TaskStatus, anchorToViewport, canNavigateTo, canTransition, computeAvatarDestination, evaluateActionPermission, fallbackConfig, isActionAllowed, isSafeSelector, normalizeProjectConfig, sanitizeText, validateInitOptions, validateWebsiteDomain };
5255
5442
  //# sourceMappingURL=index.js.map
5256
5443
  //# sourceMappingURL=index.js.map