@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.js CHANGED
@@ -85,7 +85,7 @@ var ALL_ACTION_KINDS = [
85
85
  // src/core/constants.ts
86
86
  function resolveSdkVersion() {
87
87
  {
88
- return "0.1.35";
88
+ return "0.1.36";
89
89
  }
90
90
  }
91
91
  var SDK_VERSION = resolveSdkVersion();
@@ -853,9 +853,18 @@ var CloudClient = class {
853
853
  avatarId: this.avatarId || void 0
854
854
  }
855
855
  );
856
- let response;
857
- try {
858
- response = await this.transport.request({
856
+ let token;
857
+ if (this.runtimeAuth) {
858
+ try {
859
+ token = await this.getAuthToken();
860
+ } catch {
861
+ token = this.activeToken;
862
+ }
863
+ } else {
864
+ token = this.activeToken;
865
+ }
866
+ const executeRequest = async (authToken) => {
867
+ return this.transport.request({
859
868
  path: runtimeAvatarUrl,
860
869
  method: "GET",
861
870
  idempotent: true,
@@ -865,10 +874,26 @@ var CloudClient = class {
865
874
  "X-Asiyst-Public-Key": this.publicKey,
866
875
  "X-Asiyst-Project-Key": this.publicKey,
867
876
  "X-Asiyst-Project-Id": this.projectId,
877
+ "X-Asiyst-SDK-Version": SDK_VERSION,
868
878
  ...this.avatarId ? { "X-Asiyst-Avatar-Id": this.avatarId } : {},
869
- ...etag ? { "If-None-Match": etag } : {}
879
+ ...etag ? { "If-None-Match": etag } : {},
880
+ ...authToken ? { Authorization: `Bearer ${authToken}` } : {},
881
+ ...this.sessionId ? { "X-Asiyst-Session-Id": this.sessionId } : {}
870
882
  }
871
883
  });
884
+ };
885
+ let response;
886
+ try {
887
+ response = await executeRequest(token);
888
+ if (response.status === 401 && this.runtimeAuth) {
889
+ this.runtimeAuth.invalidate();
890
+ try {
891
+ token = await this.runtimeAuth.getToken();
892
+ this.activeToken = token;
893
+ response = await executeRequest(token);
894
+ } catch {
895
+ }
896
+ }
872
897
  } catch (err) {
873
898
  throw new AsiystError({
874
899
  code: "CORS_OR_NETWORK_FAILURE",
@@ -8895,10 +8920,12 @@ var RuntimeAuth = class {
8895
8920
  if (!Number.isFinite(expiresAt) || expiresAt <= Date.now()) {
8896
8921
  throw new AuthenticationError("ASIYST runtime authorization has expired.");
8897
8922
  }
8923
+ const lifetimeMs = Math.max(0, expiresAt - Date.now());
8924
+ const refreshBufferMs = Math.min(3e4, Math.floor(lifetimeMs * 0.1));
8898
8925
  const token = {
8899
8926
  value: data.token,
8900
8927
  expiresAt,
8901
- refreshAfter: expiresAt
8928
+ refreshAfter: Math.max(Date.now(), expiresAt - refreshBufferMs)
8902
8929
  };
8903
8930
  this.token = token;
8904
8931
  return token;
@@ -12169,9 +12196,107 @@ var AsiystRuntime = class {
12169
12196
  this.map.replace(inspectDocument(doc));
12170
12197
  });
12171
12198
  }
12199
+ resolveLocalBasicIntent(rawText) {
12200
+ const text = rawText.trim().toLowerCase().replace(/[.,!?;:]/g, "").replace(/\s+/g, " ");
12201
+ if (!text) return null;
12202
+ if (text === "walk" || text === "walk around" || text === "walk forward" || text === "start walking") {
12203
+ return "walk";
12204
+ }
12205
+ if (text === "run" || text === "run around" || text === "start running") {
12206
+ return "run";
12207
+ }
12208
+ if (text === "stop" || text === "stop moving" || text === "halt" || text === "freeze" || text === "pause") {
12209
+ return "stop";
12210
+ }
12211
+ if (text === "idle" || text === "reset pose" || text === "reset" || text === "stand still" || text === "stand") {
12212
+ return "idle";
12213
+ }
12214
+ if (text === "turn left" || text === "look left" || text === "face left") {
12215
+ return "turn_left";
12216
+ }
12217
+ if (text === "turn right" || text === "look right" || text === "face right") {
12218
+ return "turn_right";
12219
+ }
12220
+ if (text === "turn front" || text === "turn forward" || text === "look forward" || text === "face front" || text === "face forward") {
12221
+ return "turn_front";
12222
+ }
12223
+ if (text === "wave" || text === "wave hand" || text === "wave at me") {
12224
+ return "wave";
12225
+ }
12226
+ if (text === "greet me" || text === "say hello" || text === "say hi" || text === "greet") {
12227
+ return "greet";
12228
+ }
12229
+ return null;
12230
+ }
12231
+ executeLocalIntent(intent, doc) {
12232
+ const win = doc.defaultView || (typeof window !== "undefined" ? window : void 0);
12233
+ const width = win?.innerWidth ?? 1024;
12234
+ const height = win?.innerHeight ?? 768;
12235
+ switch (intent) {
12236
+ case "walk": {
12237
+ const targetX = Math.round(Math.max(120, Math.min(width - 120, width * 0.5 + (Math.random() * 200 - 100))));
12238
+ const targetY = Math.round(Math.max(120, Math.min(height - 120, height * 0.65 + (Math.random() * 100 - 50))));
12239
+ void this.avatar.walkTo({ x: targetX, y: targetY }, 1);
12240
+ break;
12241
+ }
12242
+ case "run": {
12243
+ const targetX = Math.round(Math.max(120, Math.min(width - 120, width * 0.5 + (Math.random() * 200 - 100))));
12244
+ const targetY = Math.round(Math.max(120, Math.min(height - 120, height * 0.65 + (Math.random() * 100 - 50))));
12245
+ void this.avatar.runTo({ x: targetX, y: targetY }, 1.5);
12246
+ break;
12247
+ }
12248
+ case "stop": {
12249
+ this.avatar.stop();
12250
+ break;
12251
+ }
12252
+ case "idle": {
12253
+ this.avatar.stopAnimation();
12254
+ this.avatar.stop();
12255
+ this.avatar.turnTo("forward");
12256
+ this.avatar.setExpression("neutral");
12257
+ break;
12258
+ }
12259
+ case "turn_left": {
12260
+ this.avatar.turnTo("left");
12261
+ break;
12262
+ }
12263
+ case "turn_right": {
12264
+ this.avatar.turnTo("right");
12265
+ break;
12266
+ }
12267
+ case "turn_front": {
12268
+ this.avatar.turnTo("front");
12269
+ break;
12270
+ }
12271
+ case "wave":
12272
+ case "greet": {
12273
+ this.avatar.playGesture("wave");
12274
+ break;
12275
+ }
12276
+ }
12277
+ }
12172
12278
  async handleUserMessage(text, doc) {
12173
12279
  this.greetingManager.markUserInteracted();
12174
12280
  this.events.emit("asiyst:conversation:message", { role: "user", text });
12281
+ const localIntent = this.resolveLocalBasicIntent(text);
12282
+ if (localIntent) {
12283
+ this.executeLocalIntent(localIntent, doc);
12284
+ const confirmations = {
12285
+ walk: "Walking.",
12286
+ run: "Running.",
12287
+ stop: "Stopped.",
12288
+ idle: "Reset to idle pose.",
12289
+ turn_left: "Turning left.",
12290
+ turn_right: "Turning right.",
12291
+ turn_front: "Facing forward.",
12292
+ wave: "Waving hello!",
12293
+ greet: "Hello! Ready to help."
12294
+ };
12295
+ const localReply = confirmations[localIntent] ?? `Executed "${text.trim()}" locally.`;
12296
+ this.panel.append("assistant", localReply);
12297
+ this.events.emit("asiyst:conversation:message", { role: "assistant", text: localReply });
12298
+ return;
12299
+ }
12175
12300
  this.avatar.think();
12176
12301
  try {
12177
12302
  const reply = await this.cloud.sendConversationMessage(
@@ -12200,8 +12325,8 @@ var AsiystRuntime = class {
12200
12325
  this.events.emit("asiyst:conversation:message", { role: "assistant", text: reply.message.text });
12201
12326
  } catch (error) {
12202
12327
  const message = error instanceof Error ? error.message : "Asiyst Cloud is unavailable";
12203
- this.panel.append("assistant", message);
12204
12328
  this.events.emit("asiyst:error", { code: "conversation_failed", message });
12329
+ this.panel.append("assistant", message);
12205
12330
  this.avatar.speak(message);
12206
12331
  }
12207
12332
  }