@asiyst/sdk 0.1.35 → 0.1.36

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 CHANGED
@@ -107,7 +107,7 @@ var ALL_ACTION_KINDS = [
107
107
  // src/core/constants.ts
108
108
  function resolveSdkVersion() {
109
109
  {
110
- return "0.1.35";
110
+ return "0.1.36";
111
111
  }
112
112
  }
113
113
  var SDK_VERSION = resolveSdkVersion();
@@ -875,9 +875,18 @@ var CloudClient = class {
875
875
  avatarId: this.avatarId || void 0
876
876
  }
877
877
  );
878
- let response;
879
- try {
880
- response = await this.transport.request({
878
+ let token;
879
+ if (this.runtimeAuth) {
880
+ try {
881
+ token = await this.getAuthToken();
882
+ } catch {
883
+ token = this.activeToken;
884
+ }
885
+ } else {
886
+ token = this.activeToken;
887
+ }
888
+ const executeRequest = async (authToken) => {
889
+ return this.transport.request({
881
890
  path: runtimeAvatarUrl,
882
891
  method: "GET",
883
892
  idempotent: true,
@@ -887,10 +896,26 @@ var CloudClient = class {
887
896
  "X-Asiyst-Public-Key": this.publicKey,
888
897
  "X-Asiyst-Project-Key": this.publicKey,
889
898
  "X-Asiyst-Project-Id": this.projectId,
899
+ "X-Asiyst-SDK-Version": SDK_VERSION,
890
900
  ...this.avatarId ? { "X-Asiyst-Avatar-Id": this.avatarId } : {},
891
- ...etag ? { "If-None-Match": etag } : {}
901
+ ...etag ? { "If-None-Match": etag } : {},
902
+ ...authToken ? { Authorization: `Bearer ${authToken}` } : {},
903
+ ...this.sessionId ? { "X-Asiyst-Session-Id": this.sessionId } : {}
892
904
  }
893
905
  });
906
+ };
907
+ let response;
908
+ try {
909
+ response = await executeRequest(token);
910
+ if (response.status === 401 && this.runtimeAuth) {
911
+ this.runtimeAuth.invalidate();
912
+ try {
913
+ token = await this.runtimeAuth.getToken();
914
+ this.activeToken = token;
915
+ response = await executeRequest(token);
916
+ } catch {
917
+ }
918
+ }
894
919
  } catch (err) {
895
920
  throw new AsiystError({
896
921
  code: "CORS_OR_NETWORK_FAILURE",
@@ -8917,10 +8942,12 @@ var RuntimeAuth = class {
8917
8942
  if (!Number.isFinite(expiresAt) || expiresAt <= Date.now()) {
8918
8943
  throw new AuthenticationError("ASIYST runtime authorization has expired.");
8919
8944
  }
8945
+ const lifetimeMs = Math.max(0, expiresAt - Date.now());
8946
+ const refreshBufferMs = Math.min(3e4, Math.floor(lifetimeMs * 0.1));
8920
8947
  const token = {
8921
8948
  value: data.token,
8922
8949
  expiresAt,
8923
- refreshAfter: expiresAt
8950
+ refreshAfter: Math.max(Date.now(), expiresAt - refreshBufferMs)
8924
8951
  };
8925
8952
  this.token = token;
8926
8953
  return token;
@@ -12191,9 +12218,107 @@ var AsiystRuntime = class {
12191
12218
  this.map.replace(inspectDocument(doc));
12192
12219
  });
12193
12220
  }
12221
+ resolveLocalBasicIntent(rawText) {
12222
+ const text = rawText.trim().toLowerCase().replace(/[.,!?;:]/g, "").replace(/\s+/g, " ");
12223
+ if (!text) return null;
12224
+ if (text === "walk" || text === "walk around" || text === "walk forward" || text === "start walking") {
12225
+ return "walk";
12226
+ }
12227
+ if (text === "run" || text === "run around" || text === "start running") {
12228
+ return "run";
12229
+ }
12230
+ if (text === "stop" || text === "stop moving" || text === "halt" || text === "freeze" || text === "pause") {
12231
+ return "stop";
12232
+ }
12233
+ if (text === "idle" || text === "reset pose" || text === "reset" || text === "stand still" || text === "stand") {
12234
+ return "idle";
12235
+ }
12236
+ if (text === "turn left" || text === "look left" || text === "face left") {
12237
+ return "turn_left";
12238
+ }
12239
+ if (text === "turn right" || text === "look right" || text === "face right") {
12240
+ return "turn_right";
12241
+ }
12242
+ if (text === "turn front" || text === "turn forward" || text === "look forward" || text === "face front" || text === "face forward") {
12243
+ return "turn_front";
12244
+ }
12245
+ if (text === "wave" || text === "wave hand" || text === "wave at me") {
12246
+ return "wave";
12247
+ }
12248
+ if (text === "greet me" || text === "say hello" || text === "say hi" || text === "greet") {
12249
+ return "greet";
12250
+ }
12251
+ return null;
12252
+ }
12253
+ executeLocalIntent(intent, doc) {
12254
+ const win = doc.defaultView || (typeof window !== "undefined" ? window : void 0);
12255
+ const width = win?.innerWidth ?? 1024;
12256
+ const height = win?.innerHeight ?? 768;
12257
+ switch (intent) {
12258
+ case "walk": {
12259
+ const targetX = Math.round(Math.max(120, Math.min(width - 120, width * 0.5 + (Math.random() * 200 - 100))));
12260
+ const targetY = Math.round(Math.max(120, Math.min(height - 120, height * 0.65 + (Math.random() * 100 - 50))));
12261
+ void this.avatar.walkTo({ x: targetX, y: targetY }, 1);
12262
+ break;
12263
+ }
12264
+ case "run": {
12265
+ const targetX = Math.round(Math.max(120, Math.min(width - 120, width * 0.5 + (Math.random() * 200 - 100))));
12266
+ const targetY = Math.round(Math.max(120, Math.min(height - 120, height * 0.65 + (Math.random() * 100 - 50))));
12267
+ void this.avatar.runTo({ x: targetX, y: targetY }, 1.5);
12268
+ break;
12269
+ }
12270
+ case "stop": {
12271
+ this.avatar.stop();
12272
+ break;
12273
+ }
12274
+ case "idle": {
12275
+ this.avatar.stopAnimation();
12276
+ this.avatar.stop();
12277
+ this.avatar.turnTo("forward");
12278
+ this.avatar.setExpression("neutral");
12279
+ break;
12280
+ }
12281
+ case "turn_left": {
12282
+ this.avatar.turnTo("left");
12283
+ break;
12284
+ }
12285
+ case "turn_right": {
12286
+ this.avatar.turnTo("right");
12287
+ break;
12288
+ }
12289
+ case "turn_front": {
12290
+ this.avatar.turnTo("front");
12291
+ break;
12292
+ }
12293
+ case "wave":
12294
+ case "greet": {
12295
+ this.avatar.playGesture("wave");
12296
+ break;
12297
+ }
12298
+ }
12299
+ }
12194
12300
  async handleUserMessage(text, doc) {
12195
12301
  this.greetingManager.markUserInteracted();
12196
12302
  this.events.emit("asiyst:conversation:message", { role: "user", text });
12303
+ const localIntent = this.resolveLocalBasicIntent(text);
12304
+ if (localIntent) {
12305
+ this.executeLocalIntent(localIntent, doc);
12306
+ const confirmations = {
12307
+ walk: "Walking.",
12308
+ run: "Running.",
12309
+ stop: "Stopped.",
12310
+ idle: "Reset to idle pose.",
12311
+ turn_left: "Turning left.",
12312
+ turn_right: "Turning right.",
12313
+ turn_front: "Facing forward.",
12314
+ wave: "Waving hello!",
12315
+ greet: "Hello! Ready to help."
12316
+ };
12317
+ const localReply = confirmations[localIntent] ?? `Executed "${text.trim()}" locally.`;
12318
+ this.panel.append("assistant", localReply);
12319
+ this.events.emit("asiyst:conversation:message", { role: "assistant", text: localReply });
12320
+ return;
12321
+ }
12197
12322
  this.avatar.think();
12198
12323
  try {
12199
12324
  const reply = await this.cloud.sendConversationMessage(
@@ -12222,8 +12347,8 @@ var AsiystRuntime = class {
12222
12347
  this.events.emit("asiyst:conversation:message", { role: "assistant", text: reply.message.text });
12223
12348
  } catch (error) {
12224
12349
  const message = error instanceof Error ? error.message : "Asiyst Cloud is unavailable";
12225
- this.panel.append("assistant", message);
12226
12350
  this.events.emit("asiyst:error", { code: "conversation_failed", message });
12351
+ this.panel.append("assistant", message);
12227
12352
  this.avatar.speak(message);
12228
12353
  }
12229
12354
  }