@asiyst/sdk 0.1.23 → 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.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.22";
78
+ return "0.1.24";
79
79
  }
80
80
  }
81
81
  var SDK_VERSION = resolveSdkVersion();
@@ -373,18 +373,22 @@ function normalizeProjectConfig(raw) {
373
373
  return base;
374
374
  }
375
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;
376
378
  const avatarId = asString(
377
- raw.avatarId ?? rawAvatarRecord?.avatarId ?? rawAvatarRecord?.id,
379
+ raw.avatarId ?? rawAvatarRecord?.avatarId ?? rawAvatarRecord?.id ?? rawConfigRecord?.avatarId,
378
380
  "",
379
381
  128
380
382
  ) || void 0;
381
- const assetUrl = typeof raw.assetUrl === "string" ? raw.assetUrl : typeof rawAvatarRecord?.assetUrl === "string" ? rawAvatarRecord.assetUrl : void 0;
382
- const thumbnailUrl = typeof raw.thumbnailUrl === "string" ? raw.thumbnailUrl : typeof rawAvatarRecord?.thumbnailUrl === "string" ? rawAvatarRecord.thumbnailUrl : rawAvatarRecord?.thumbnailUrl === null ? null : void 0;
383
- const publishedVersion = typeof raw.publishedVersion === "string" ? raw.publishedVersion : typeof rawAvatarRecord?.version === "string" ? rawAvatarRecord.version : void 0;
384
- const animations = parseAnimations(raw.animations ?? rawAvatarRecord?.animations);
385
- const branding = parseBranding(raw.branding);
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);
386
390
  const avatarName = asString(
387
- raw.avatarName ?? rawAvatarRecord?.name,
391
+ raw.avatarName ?? rawAvatarRecord?.name ?? rawConfigRecord?.avatarName ?? rawManifestRecord?.name,
388
392
  base.avatarName,
389
393
  40
390
394
  );
@@ -648,39 +652,58 @@ var CloudClient = class {
648
652
  const avatarAndKeyParams = `?projectId=${encodeURIComponent(this.projectId)}&publicKey=${encodeURIComponent(this.publicKey)}${this.avatarId ? `&avatarId=${encodeURIComponent(this.avatarId)}` : ""}`;
649
653
  const baseUrl = this.getApiBaseUrl();
650
654
  const resolveAssetUrls = (raw) => {
651
- const canonicalBase = baseUrl.includes("localhost") || baseUrl.includes("127.0.0.1") ? baseUrl.replace(/\/functions\/v1.*$/, "").replace(/\/api\/v1.*$/, "") : "https://asiyst.com";
652
- if (raw.avatar && typeof raw.avatar === "object" && !Array.isArray(raw.avatar)) {
653
- const av = { ...raw.avatar };
654
- if (typeof av.assetUrl === "string" && av.assetUrl.startsWith("/")) {
655
- av.assetUrl = new URL(av.assetUrl, canonicalBase).href;
655
+ let canonicalBase = "https://asiyst.com";
656
+ try {
657
+ if (baseUrl) {
658
+ const u = new URL(baseUrl);
659
+ canonicalBase = u.origin;
656
660
  }
657
- if (typeof av.thumbnailUrl === "string" && av.thumbnailUrl.startsWith("/")) {
658
- av.thumbnailUrl = new URL(av.thumbnailUrl, canonicalBase).href;
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;
659
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);
660
676
  if (Array.isArray(av.animations)) {
661
677
  av.animations = av.animations.map((item) => {
662
678
  if (item && typeof item === "object") {
663
679
  const animObj = item;
664
- if (typeof animObj.assetUrl === "string" && animObj.assetUrl.startsWith("/")) {
665
- return { ...animObj, assetUrl: new URL(animObj.assetUrl, canonicalBase).href };
666
- }
680
+ return { ...animObj, assetUrl: toAbsolute(animObj.assetUrl) };
667
681
  }
668
682
  return item;
669
683
  });
670
684
  }
671
685
  raw.avatar = av;
672
686
  }
673
- if (typeof raw.assetUrl === "string" && raw.assetUrl.startsWith("/")) {
674
- raw.assetUrl = new URL(raw.assetUrl, canonicalBase).href;
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;
675
693
  }
676
- if (typeof raw.thumbnailUrl === "string" && raw.thumbnailUrl.startsWith("/")) {
677
- raw.thumbnailUrl = new URL(raw.thumbnailUrl, canonicalBase).href;
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;
678
700
  }
701
+ raw.assetUrl = toAbsolute(raw.assetUrl);
702
+ raw.thumbnailUrl = toAbsolute(raw.thumbnailUrl);
703
+ raw.manifestUrl = toAbsolute(raw.manifestUrl);
679
704
  if (raw.branding && typeof raw.branding === "object" && !Array.isArray(raw.branding)) {
680
705
  const br = { ...raw.branding };
681
- if (typeof br.siteLogoUrl === "string" && br.siteLogoUrl.startsWith("/")) {
682
- br.siteLogoUrl = new URL(br.siteLogoUrl, canonicalBase).href;
683
- }
706
+ br.siteLogoUrl = toAbsolute(br.siteLogoUrl);
684
707
  raw.branding = br;
685
708
  }
686
709
  return raw;
@@ -693,8 +716,11 @@ var CloudClient = class {
693
716
  idempotent: true
694
717
  });
695
718
  if (response.ok && response.data) {
696
- const dataObj = response.data.config ?? response.data;
697
- return normalizeProjectConfig(resolveAssetUrls(dataObj));
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));
698
724
  }
699
725
  if (response.status === 404) {
700
726
  lastError = new ConfigurationError(`Project ${this.projectId} or avatar configuration not found`);
@@ -1739,7 +1765,7 @@ var AssetLoader = class {
1739
1765
  }
1740
1766
  this.inFlightController = new AbortController();
1741
1767
  const abortSignal = options?.signal ? anySignal([this.inFlightController.signal, options.signal]) : this.inFlightController.signal;
1742
- const timeoutMs = options?.timeoutMs ?? 15e3;
1768
+ const timeoutMs = options?.timeoutMs ?? 6e4;
1743
1769
  const timeoutId = setTimeout(() => {
1744
1770
  this.inFlightController?.abort();
1745
1771
  }, timeoutMs);
@@ -2087,6 +2113,8 @@ var FbxRenderer = class {
2087
2113
  this.camera = null;
2088
2114
  this.modelRoot = null;
2089
2115
  this.mixer = null;
2116
+ this.allAnimations = [];
2117
+ this.currentAction = null;
2090
2118
  this.animFrameId = null;
2091
2119
  this.lastTime = 0;
2092
2120
  this.facing = "right";
@@ -2105,35 +2133,53 @@ var FbxRenderer = class {
2105
2133
  if (!glContext) {
2106
2134
  throw new Error("WebGLRenderingContext is not available or supported in this browser environment");
2107
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);
2108
2139
  const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
2109
- const size = options?.config?.size || 96;
2110
- this.canvas.width = Math.round(size * dpr);
2111
- this.canvas.height = Math.round(size * dpr);
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`;
2112
2144
  try {
2113
2145
  this.renderer = new THREE.WebGLRenderer({
2114
2146
  canvas: this.canvas,
2115
2147
  alpha: true,
2116
2148
  antialias: true,
2117
- powerPreference: "low-power"
2149
+ powerPreference: "high-performance"
2118
2150
  });
2119
2151
  this.renderer.setPixelRatio(Math.min(dpr, 2));
2120
- this.renderer.setSize(size, size, false);
2152
+ this.renderer.setSize(width, height, false);
2121
2153
  this.renderer.outputColorSpace = THREE.SRGBColorSpace;
2154
+ this.renderer.shadowMap.enabled = true;
2155
+ this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
2122
2156
  } catch (err) {
2123
2157
  const msg = err instanceof Error ? err.message : String(err);
2124
2158
  throw new Error(`Failed to initialize WebGLRenderer: ${msg}`);
2125
2159
  }
2126
2160
  this.scene = new THREE.Scene();
2127
- this.camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
2128
- this.camera.position.set(0, 0, 3.4);
2161
+ this.camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 100);
2129
2162
  const ambientLight = new THREE.AmbientLight(16777215, 1.2);
2130
2163
  this.scene.add(ambientLight);
2131
- const keyLight = new THREE.DirectionalLight(16777215, 1.2);
2132
- keyLight.position.set(2, 3.5, 3);
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;
2133
2169
  this.scene.add(keyLight);
2134
- const fillLight = new THREE.DirectionalLight(10859772, 0.6);
2135
- fillLight.position.set(-2.5, -1, -1.5);
2170
+ const fillLight = new THREE.DirectionalLight(15459032, 1.2);
2171
+ fillLight.position.set(-3, 2, 2);
2136
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);
2137
2183
  let rawObject;
2138
2184
  let modelAnimations = [];
2139
2185
  if (asset.format === "fbx") {
@@ -2170,32 +2216,39 @@ var FbxRenderer = class {
2170
2216
  }
2171
2217
  }
2172
2218
  const { meshCount, vertexCount: totalVertices } = this.validateGeometry(rawObject);
2173
- const box = new THREE.Box3().setFromObject(rawObject);
2174
- if (box.isEmpty()) {
2219
+ const rawBox = new THREE.Box3().setFromObject(rawObject);
2220
+ if (rawBox.isEmpty()) {
2175
2221
  throw new Error("FBX asset geometry bounding box is empty");
2176
2222
  }
2177
- const center = new THREE.Vector3();
2178
- box.getCenter(center);
2179
- const boxSize = new THREE.Vector3();
2180
- box.getSize(boxSize);
2181
- rawObject.position.x -= center.x;
2182
- rawObject.position.y -= center.y;
2183
- 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;
2184
2229
  this.modelRoot = new THREE.Group();
2185
2230
  this.modelRoot.add(rawObject);
2231
+ this.modelRoot.scale.setScalar(targetScale);
2186
2232
  this.scene.add(this.modelRoot);
2187
- const maxDim = Math.max(boxSize.x, boxSize.y, boxSize.z);
2188
- if (maxDim > 0) {
2189
- const targetSpan = 1.85;
2190
- const scale = targetSpan / maxDim;
2191
- this.modelRoot.scale.setScalar(scale);
2192
- }
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;
2193
2246
  if (modelAnimations.length > 0) {
2194
2247
  this.mixer = new THREE.AnimationMixer(rawObject);
2195
- const clip = modelAnimations[0];
2196
- if (clip) {
2197
- const action = this.mixer.clipAction(clip);
2198
- action.play();
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();
2199
2252
  }
2200
2253
  }
2201
2254
  container.replaceChildren();
@@ -2210,6 +2263,10 @@ var FbxRenderer = class {
2210
2263
  this.startLoop();
2211
2264
  this.setFacing(this.facing);
2212
2265
  this.setPose(this.currentPose);
2266
+ if (typeof window !== "undefined") {
2267
+ this.resizeListener = () => this.handleResize();
2268
+ window.addEventListener("resize", this.resizeListener);
2269
+ }
2213
2270
  return {
2214
2271
  meshCount,
2215
2272
  vertexCount: totalVertices,
@@ -2225,6 +2282,31 @@ var FbxRenderer = class {
2225
2282
  setPose(pose) {
2226
2283
  this.currentPose = pose;
2227
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
+ }
2228
2310
  switch (pose) {
2229
2311
  case "point":
2230
2312
  this.modelRoot.rotation.z = -0.15;
@@ -2234,6 +2316,10 @@ var FbxRenderer = class {
2234
2316
  this.modelRoot.rotation.z = 0.12;
2235
2317
  this.modelRoot.rotation.x = -0.1;
2236
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;
2237
2323
  case "celebrate":
2238
2324
  this.modelRoot.rotation.z = 0;
2239
2325
  this.modelRoot.rotation.x = -0.15;
@@ -2242,6 +2328,7 @@ var FbxRenderer = class {
2242
2328
  default:
2243
2329
  this.modelRoot.rotation.z = 0;
2244
2330
  this.modelRoot.rotation.x = 0;
2331
+ this.modelRoot.rotation.y = this.facing === "left" ? -0.35 : 0.35;
2245
2332
  break;
2246
2333
  }
2247
2334
  }
@@ -2286,6 +2373,10 @@ var FbxRenderer = class {
2286
2373
  this.animFrameId = requestAnimationFrame(tick);
2287
2374
  }
2288
2375
  destroy() {
2376
+ if (typeof window !== "undefined" && this.resizeListener) {
2377
+ window.removeEventListener("resize", this.resizeListener);
2378
+ this.resizeListener = void 0;
2379
+ }
2289
2380
  if (this.animFrameId !== null && typeof cancelAnimationFrame !== "undefined") {
2290
2381
  cancelAnimationFrame(this.animFrameId);
2291
2382
  this.animFrameId = null;
@@ -2331,6 +2422,30 @@ var FbxRenderer = class {
2331
2422
  this.modelRoot = null;
2332
2423
  this.initialRenderCompleted = false;
2333
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
+ }
2334
2449
  };
2335
2450
 
2336
2451
  // src/avatar/CssAvatarRenderer.ts
@@ -2341,7 +2456,7 @@ var AVATAR_CSS = `
2341
2456
  display: flex;
2342
2457
  flex-direction: column;
2343
2458
  align-items: center;
2344
- gap: 6px;
2459
+ gap: 4px;
2345
2460
  pointer-events: auto;
2346
2461
  user-select: none;
2347
2462
  }
@@ -2362,28 +2477,38 @@ var AVATAR_CSS = `
2362
2477
  padding: 0;
2363
2478
  outline: none;
2364
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
+ }
2365
2495
  }
2366
- .asiyst-figure[data-pose="point"] { transform: rotate(-12deg); }
2367
- .asiyst-figure[data-pose="think"] { opacity: 0.85; }
2368
- .asiyst-figure[data-pose="celebrate"] { transform: scale(1.08); }
2369
2496
  .asiyst-avatar-viewport {
2370
- position: absolute;
2371
- inset: 0;
2497
+ position: relative;
2372
2498
  width: 100%;
2373
2499
  height: 100%;
2374
2500
  display: grid;
2375
2501
  place-items: center;
2376
2502
  border-radius: inherit;
2377
- overflow: hidden;
2378
- pointer-events: none;
2503
+ overflow: visible;
2504
+ pointer-events: auto;
2379
2505
  }
2380
2506
  .asiyst-avatar-canvas {
2381
2507
  width: 100%;
2382
2508
  height: 100%;
2383
2509
  object-fit: contain;
2384
- border-radius: inherit;
2385
2510
  display: block;
2386
- pointer-events: none;
2511
+ pointer-events: auto;
2387
2512
  }
2388
2513
  .asiyst-avatar-graphic {
2389
2514
  width: 100%;
@@ -2437,11 +2562,73 @@ var AVATAR_CSS = `
2437
2562
  padding: 8px 10px;
2438
2563
  font: 13px/1.4 system-ui, sans-serif;
2439
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;
2440
2627
  }
2441
- .asiyst-name { font: 600 12px/1 system-ui, sans-serif; color: #0f172a; }
2442
2628
  @media (prefers-reduced-motion: reduce) {
2443
2629
  .asiyst-avatar.asiyst-animate { transition: none; }
2444
2630
  .asiyst-avatar-loader { animation: none; }
2631
+ .asiyst-name-dot { animation: none; }
2445
2632
  }
2446
2633
  `;
2447
2634
  var CssAvatarRenderer = class {
@@ -2452,6 +2639,7 @@ var CssAvatarRenderer = class {
2452
2639
  this.pose = "idle";
2453
2640
  this.accentColor = "#2563eb";
2454
2641
  this.avatarName = "Asiyst";
2642
+ this.isPanelOpen = false;
2455
2643
  // Asset loading & rendering state
2456
2644
  this.assetLoader = new AssetLoader();
2457
2645
  this.fbxRenderer = null;
@@ -2467,6 +2655,20 @@ var CssAvatarRenderer = class {
2467
2655
  this.root = doc.createElement("div");
2468
2656
  this.root.className = "asiyst-avatar asiyst-animate";
2469
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);
2470
2672
  this.figure = doc.createElement("button");
2471
2673
  this.figure.type = "button";
2472
2674
  this.figure.className = "asiyst-figure";
@@ -2475,12 +2677,26 @@ var CssAvatarRenderer = class {
2475
2677
  this.viewport = doc.createElement("div");
2476
2678
  this.viewport.className = "asiyst-avatar-viewport";
2477
2679
  this.figure.appendChild(this.viewport);
2478
- this.nameEl = doc.createElement("div");
2479
- this.nameEl.className = "asiyst-name";
2480
2680
  this.bubble = doc.createElement("div");
2481
2681
  this.bubble.className = "asiyst-bubble";
2482
2682
  this.bubble.hidden = true;
2483
- this.root.append(this.bubble, this.figure, this.nameEl);
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);
2484
2700
  container.appendChild(this.root);
2485
2701
  this.applyConfig(config);
2486
2702
  }
@@ -2494,24 +2710,51 @@ var CssAvatarRenderer = class {
2494
2710
  this.root = void 0;
2495
2711
  this.figure = void 0;
2496
2712
  this.viewport = void 0;
2713
+ this.nameTagEl = void 0;
2714
+ this.chatActionBtn = void 0;
2497
2715
  }
2498
2716
  applyConfig(config) {
2499
2717
  this.size = config.size;
2500
2718
  this.accentColor = config.theme.accent ?? "#2563eb";
2501
2719
  this.avatarName = config.avatarName;
2502
- if (this.figure) {
2503
- this.figure.style.width = `${config.size}px`;
2504
- this.figure.style.height = `${config.size}px`;
2505
- this.figure.style.background = this.accentColor;
2720
+ if (this.nameTextEl) {
2721
+ renderSafeText(this.nameTextEl, config.avatarName);
2506
2722
  }
2507
- if (this.nameEl) {
2508
- renderSafeText(this.nameEl, config.avatarName);
2723
+ if (this.chatActionBtn) {
2724
+ const span = this.chatActionBtn.querySelector("span");
2725
+ if (span) {
2726
+ renderSafeText(span, `Chat with ${config.avatarName}`);
2727
+ }
2509
2728
  }
2510
2729
  if (this.root) {
2511
2730
  this.root.setAttribute("aria-label", config.avatarName);
2512
2731
  }
2513
- if (!this.isAssetLoadedFlag && this.viewport) {
2514
- this.renderFallback();
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";
2515
2758
  }
2516
2759
  }
2517
2760
  async loadAsset(config) {
@@ -2532,7 +2775,7 @@ var CssAvatarRenderer = class {
2532
2775
  }
2533
2776
  this.renderLoader();
2534
2777
  try {
2535
- const asset = await this.assetLoader.load(assetUrl);
2778
+ const asset = await this.assetLoader.load(assetUrl, { timeoutMs: 6e4 });
2536
2779
  await this.renderLoadedAsset(asset, config);
2537
2780
  this.renderState = "ready";
2538
2781
  this.isAssetLoadedFlag = true;
@@ -2540,6 +2783,13 @@ var CssAvatarRenderer = class {
2540
2783
  this.loadedFormat = asset.format;
2541
2784
  if (this.figure) {
2542
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";
2543
2793
  }
2544
2794
  return true;
2545
2795
  } catch (err) {
@@ -2550,6 +2800,13 @@ var CssAvatarRenderer = class {
2550
2800
  this.isFallbackFlag = true;
2551
2801
  if (this.figure) {
2552
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";
2553
2810
  }
2554
2811
  this.renderFallback(true);
2555
2812
  return false;
@@ -2571,10 +2828,15 @@ var CssAvatarRenderer = class {
2571
2828
  this.fbxRenderer = null;
2572
2829
  }
2573
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;
2574
2834
  this.fbxRenderer = new FbxRenderer();
2575
2835
  this.renderMetrics = await this.fbxRenderer.mount(this.viewport, asset, {
2576
2836
  accentColor: this.accentColor,
2577
- config
2837
+ config,
2838
+ width,
2839
+ height
2578
2840
  });
2579
2841
  this.fbxRenderer.setFacing(this.facing);
2580
2842
  this.fbxRenderer.setPose(this.pose);
@@ -2590,7 +2852,7 @@ var CssAvatarRenderer = class {
2590
2852
  const thumb = typeof asset.manifest.thumbnailUrl === "string" ? asset.manifest.thumbnailUrl : void 0;
2591
2853
  const modelUrl = typeof asset.manifest.assetUrl === "string" ? asset.manifest.assetUrl : typeof asset.manifest.modelUrl === "string" ? asset.manifest.modelUrl : void 0;
2592
2854
  if (modelUrl) {
2593
- const subAsset = await this.assetLoader.load(modelUrl);
2855
+ const subAsset = await this.assetLoader.load(modelUrl, { timeoutMs: 6e4 });
2594
2856
  await this.renderLoadedAsset(subAsset, config);
2595
2857
  } else if (thumb) {
2596
2858
  this.viewport.replaceChildren();
@@ -2622,7 +2884,6 @@ var CssAvatarRenderer = class {
2622
2884
  if (isError) {
2623
2885
  const badge = doc.createElement("span");
2624
2886
  badge.className = "asiyst-avatar-fallback-badge";
2625
- badge.setAttribute("title", "Avatar asset failed to load");
2626
2887
  badge.textContent = "!";
2627
2888
  fallback.appendChild(badge);
2628
2889
  }
@@ -2630,66 +2891,72 @@ var CssAvatarRenderer = class {
2630
2891
  }
2631
2892
  setPosition(x, y, animate) {
2632
2893
  if (!this.root) return;
2633
- this.root.classList.toggle("asiyst-animate", animate);
2634
- this.root.style.left = `${x}px`;
2635
- this.root.style.top = `${y}px`;
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`;
2636
2901
  }
2637
2902
  setFacing(direction) {
2638
2903
  this.facing = direction;
2639
2904
  this.fbxRenderer?.setFacing(direction);
2640
- this.syncTransform();
2641
2905
  }
2642
2906
  setPose(pose) {
2643
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
+ }
2644
2915
  this.fbxRenderer?.setPose(pose);
2645
- this.figure?.setAttribute("data-pose", pose);
2646
- this.syncTransform();
2647
- }
2648
- syncTransform() {
2649
- if (!this.figure) return;
2650
- const face = this.facing === "left" ? "scaleX(-1)" : "";
2651
- const pose = this.pose === "point" ? "rotate(-12deg)" : this.pose === "celebrate" ? "scale(1.08)" : "";
2652
- this.figure.style.transform = `${face} ${pose}`.trim();
2653
2916
  }
2654
2917
  setSpeech(text) {
2655
2918
  if (!this.bubble) return;
2656
2919
  if (!text) {
2657
2920
  this.bubble.hidden = true;
2658
- this.bubble.textContent = "";
2921
+ this.bubble.replaceChildren();
2659
2922
  return;
2660
2923
  }
2661
2924
  this.bubble.hidden = false;
2662
2925
  renderSafeText(this.bubble, text);
2663
2926
  }
2664
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
+ }
2665
2932
  return { width: this.size, height: this.size + 28 };
2666
2933
  }
2667
2934
  setHidden(hidden) {
2668
2935
  this.hidden = hidden;
2669
2936
  if (this.root) {
2670
- this.root.hidden = hidden;
2937
+ this.root.style.display = hidden ? "none" : "";
2671
2938
  }
2672
2939
  }
2673
2940
  isHidden() {
2674
2941
  return this.hidden;
2675
2942
  }
2676
- getFigure() {
2677
- return this.figure;
2678
- }
2679
- getViewport() {
2680
- return this.viewport;
2943
+ getRenderState() {
2944
+ return this.renderState;
2681
2945
  }
2682
2946
  isAssetLoaded() {
2683
2947
  return this.isAssetLoadedFlag;
2684
2948
  }
2685
- isRendered() {
2686
- return this.isAssetLoadedFlag && (this.fbxRenderer ? this.fbxRenderer.isRendered() : true);
2949
+ getViewport() {
2950
+ return this.viewport;
2951
+ }
2952
+ isFallback() {
2953
+ return this.isFallbackFlag;
2687
2954
  }
2688
2955
  isFallbackActive() {
2689
2956
  return this.isFallbackFlag;
2690
2957
  }
2691
- getRenderState() {
2692
- return this.renderState;
2958
+ isRendered() {
2959
+ return this.isAssetLoadedFlag && (this.fbxRenderer ? this.fbxRenderer.isRendered() : true);
2693
2960
  }
2694
2961
  getLoadedFormat() {
2695
2962
  return this.loadedFormat;
@@ -2703,6 +2970,18 @@ var CssAvatarRenderer = class {
2703
2970
  getMetrics() {
2704
2971
  return this.renderMetrics;
2705
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
+ }
2706
2985
  };
2707
2986
 
2708
2987
  // src/accessibility/a11y.ts
@@ -2886,6 +3165,8 @@ var MovementEngine = class {
2886
3165
  this.onViewport = throttle(() => {
2887
3166
  if (this.followTarget) {
2888
3167
  this.placeBeside(this.followTarget, false);
3168
+ } else {
3169
+ this.goToAnchor();
2889
3170
  }
2890
3171
  }, VIEWPORT_HANDLER_THROTTLE_MS);
2891
3172
  }
@@ -3503,27 +3784,39 @@ var ConversationPanel = class {
3503
3784
  this.style.textContent = `
3504
3785
  .asiyst-panel {
3505
3786
  position: fixed;
3506
- right: 16px;
3507
- bottom: 16px;
3508
- width: min(360px, calc(100vw - 32px));
3509
- max-height: min(480px, 70vh);
3510
- background: #fff;
3787
+ right: 256px;
3788
+ bottom: 20px;
3789
+ width: min(380px, calc(100vw - 280px));
3790
+ max-height: min(560px, 75vh);
3791
+ background: #ffffff;
3511
3792
  color: #0f172a;
3512
- border-radius: 16px;
3513
- box-shadow: 0 16px 50px rgba(15, 23, 42, 0.22);
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);
3514
3795
  display: flex;
3515
3796
  flex-direction: column;
3516
- font: 14px/1.45 system-ui, sans-serif;
3797
+ font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
3517
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
+ }
3518
3810
  }
3519
3811
  .asiyst-panel[hidden] { display: none; }
3520
3812
  .asiyst-panel header {
3521
3813
  display: flex;
3522
3814
  justify-content: space-between;
3523
3815
  align-items: center;
3524
- padding: 12px 14px;
3816
+ padding: 14px 16px;
3525
3817
  background: #0f172a;
3526
3818
  color: #f8fafc;
3819
+ border-bottom: 1px solid rgba(255, 255, 255, 0.1);
3527
3820
  }
3528
3821
  .asiyst-log { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
3529
3822
  .asiyst-msg { padding: 8px 10px; border-radius: 10px; max-width: 90%; }
@@ -3923,6 +4216,7 @@ var AsiystRuntime = class {
3923
4216
  () => this.map.list()
3924
4217
  );
3925
4218
  this.renderer = new CssAvatarRenderer();
4219
+ this.renderer.onOpenChat = () => this.open();
3926
4220
  this.renderer.mount(this.host.chrome, this.config.get());
3927
4221
  this.highlights = new HighlightLayer(this.host.overlay, win);
3928
4222
  this.movement = new MovementEngine(win, doc, this.renderer, this.resolver, this.events, () => this.config.get());
@@ -3945,6 +4239,7 @@ var AsiystRuntime = class {
3945
4239
  (open) => {
3946
4240
  const convId = this.panel.getConversationId();
3947
4241
  this.cloud.setConversationId(convId);
4242
+ this.renderer.setPanelOpen(open);
3948
4243
  if (open) {
3949
4244
  this.analytics.track("assistant_opened");
3950
4245
  this.events.emit("asiyst:conversation:started", { conversationId: convId });
@@ -4017,6 +4312,7 @@ var AsiystRuntime = class {
4017
4312
  try {
4018
4313
  const loaded = await this.renderer.loadAsset(cfg);
4019
4314
  if (loaded) {
4315
+ this.movement.goToAnchor();
4020
4316
  const format = this.renderer.getLoadedFormat();
4021
4317
  const assetUrl = this.renderer.getAssetUrl();
4022
4318
  const isRendered = this.renderer.isRendered();
@@ -4084,9 +4380,14 @@ var AsiystRuntime = class {
4084
4380
  open() {
4085
4381
  this.panel.open();
4086
4382
  this.avatar.show();
4383
+ this.renderer.setPanelOpen(true);
4087
4384
  }
4088
4385
  close() {
4089
4386
  this.panel.close();
4387
+ this.renderer.setPanelOpen(false);
4388
+ }
4389
+ getRenderer() {
4390
+ return this.renderer;
4090
4391
  }
4091
4392
  avatarApi() {
4092
4393
  return this.avatar;