@asiyst/sdk 0.1.8 → 0.1.11

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/README.md CHANGED
@@ -28,11 +28,16 @@ import { Asiyst } from "@asiyst/sdk";
28
28
  await Asiyst.init({
29
29
  projectId: "<PUBLIC_PROJECT_ID>",
30
30
  publicKey: "<PUBLIC_KEY>",
31
+ avatarId: "<PUBLIC_AVATAR_ID>",
31
32
  });
32
33
  ```
33
34
 
34
35
  Do not pass a secret API key as `publicKey` or omit `projectId`.
35
36
 
37
+ `avatarId` selects the avatar that the dashboard configured for this project. It is a public identifier, not an authorization credential. The SDK sends it as a selection hint while the Asiyst API still authenticates and authorizes the project with the public project key.
38
+
39
+ Knowledge sources, including optional GitHub repositories, are configured in Asiyst Web. The SDK does not receive GitHub credentials and does not copy Knowledge Base content into the website. It initializes the verified project/avatar and retrieves authorized knowledge through the Asiyst backend.
40
+
36
41
  ```ts
37
42
  await Asiyst.init({
38
43
  publicKey: "<PUBLIC_KEY>",
package/dist/index.cjs CHANGED
@@ -71,7 +71,7 @@ var ALL_ACTION_KINDS = [
71
71
  ];
72
72
 
73
73
  // src/core/constants.ts
74
- var SDK_VERSION = "0.1.7" ;
74
+ var SDK_VERSION = "0.1.9" ;
75
75
  var DEFAULT_API_BASE_URL = "https://nqhxpgsjofzqudyqkqib.supabase.co/functions/v1/api";
76
76
  var CONFIG_SCHEMA_VERSION = 1;
77
77
  var HOST_ELEMENT_ID = "asiyst-host";
@@ -370,9 +370,19 @@ function validateInitOptions(options) {
370
370
  if (projectIdValue.length > 128 || options.publicKey.trim().length > 256) {
371
371
  throw new ConfigurationError("project credentials exceed allowed length");
372
372
  }
373
+ const avatarId = typeof options.avatarId === "string" ? options.avatarId.trim() : "";
374
+ if (options.avatarId !== void 0 && (!avatarId || avatarId.length > 128 || !/^[A-Za-z0-9_-]+$/.test(avatarId))) {
375
+ throw new ConfigurationError("Asiyst SDK: avatarId is invalid.");
376
+ }
377
+ const position = options.position === void 0 ? void 0 : ANCHORS.includes(options.position) ? options.position : void 0;
378
+ if (options.position !== void 0 && !position) {
379
+ throw new ConfigurationError("Asiyst SDK: position is invalid.");
380
+ }
373
381
  return {
374
382
  projectId: projectIdValue,
375
- publicKey: options.publicKey.trim()
383
+ publicKey: options.publicKey.trim(),
384
+ avatarId: avatarId || void 0,
385
+ position
376
386
  };
377
387
  }
378
388
 
@@ -423,6 +433,7 @@ var HttpTransport = class {
423
433
  "Content-Type": "application/json",
424
434
  "X-Asiyst-Project-Id": this.options.projectId,
425
435
  "X-Asiyst-Public-Key": this.options.publicKey,
436
+ ...this.options.avatarId ? { "X-Asiyst-Avatar-Id": this.options.avatarId } : {},
426
437
  "X-Asiyst-SDK-Version": SDK_VERSION
427
438
  },
428
439
  body: req.body === void 0 ? void 0 : JSON.stringify(req.body),
@@ -449,9 +460,10 @@ var HttpTransport = class {
449
460
 
450
461
  // src/communication/CloudClient.ts
451
462
  var CloudClient = class {
452
- constructor(transport, projectId) {
463
+ constructor(transport, projectId, publicKey = "") {
453
464
  this.transport = transport;
454
465
  this.projectId = projectId;
466
+ this.publicKey = publicKey;
455
467
  }
456
468
  async fetchConfig() {
457
469
  const response = await this.transport.request({
@@ -471,14 +483,22 @@ var CloudClient = class {
471
483
  path: "/sdk/heartbeat",
472
484
  method: "POST",
473
485
  body: {
474
- projectId: this.projectId,
475
- sdkVersion: SDK_VERSION,
476
- websiteOrigin: metadata.origin,
486
+ project_id: this.projectId,
487
+ public_key: this.publicKey,
488
+ sdk_version: SDK_VERSION,
489
+ origin: metadata.origin,
477
490
  environment: metadata.environment,
478
491
  timestamp: metadata.timestamp
479
492
  }
480
493
  });
481
- return { ok: response.ok, status: response.status };
494
+ const body = response.data && typeof response.data === "object" && !Array.isArray(response.data) ? response.data : void 0;
495
+ const rawStatus = body?.status ?? body?.connectionStatus ?? body?.verificationStatus;
496
+ const verificationStatus = rawStatus === "connected" || rawStatus === "inactive" || rawStatus === "not_detected" || rawStatus === "error" ? rawStatus : void 0;
497
+ return {
498
+ ok: response.ok && (verificationStatus === void 0 || verificationStatus === "connected"),
499
+ status: response.status,
500
+ verificationStatus
501
+ };
482
502
  }
483
503
  async requestTask(userText, pageUrl) {
484
504
  const response = await this.transport.request({
@@ -652,6 +672,7 @@ var ConfigManager = class {
652
672
  return {
653
673
  ...base,
654
674
  mode: this.options.mode ?? base.mode,
675
+ position: this.options.position ?? base.position,
655
676
  allowedActions: this.options.allowedActions ?? base.allowedActions
656
677
  };
657
678
  }
@@ -2351,6 +2372,7 @@ var AsiystRuntime = class {
2351
2372
  this.observer = new DomObserver(() => this.rescan());
2352
2373
  this.destroyed = false;
2353
2374
  this.connectionStatus = "disconnected";
2375
+ this.verificationStatus = "not_detected";
2354
2376
  this.rescanDebounced = debounce(() => this.rescan(), DOM_SCAN_DEBOUNCE_MS);
2355
2377
  if (!doc.body) {
2356
2378
  throw new InitializationError("document.body is not available");
@@ -2359,9 +2381,10 @@ var AsiystRuntime = class {
2359
2381
  const transport = new HttpTransport({
2360
2382
  apiBaseUrl: options.apiBaseUrl ?? DEFAULT_API_BASE_URL,
2361
2383
  projectId: options.projectId,
2362
- publicKey: options.publicKey
2384
+ publicKey: options.publicKey,
2385
+ avatarId: options.avatarId
2363
2386
  });
2364
- this.cloud = new CloudClient(transport, options.projectId);
2387
+ this.cloud = new CloudClient(transport, options.projectId, options.publicKey);
2365
2388
  this.config = new ConfigManager(options, this.cloud, this.events);
2366
2389
  this.analytics = new Analytics(options.projectId, this.cloud);
2367
2390
  this.host = new HostRoot(doc);
@@ -2419,6 +2442,7 @@ var AsiystRuntime = class {
2419
2442
  const domainCheck = validateWebsiteDomain(cfg, window.location.href);
2420
2443
  if (!domainCheck.allowed) {
2421
2444
  this.connectionStatus = "disconnected";
2445
+ this.verificationStatus = "not_detected";
2422
2446
  this.events.emit("asiyst:error", {
2423
2447
  code: "domain_not_authorized",
2424
2448
  message: "This website is not authorized for the current Asiyst project."
@@ -2434,14 +2458,19 @@ var AsiystRuntime = class {
2434
2458
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
2435
2459
  });
2436
2460
  this.connectionStatus = heartbeat.ok ? "connected" : "disconnected";
2461
+ this.verificationStatus = heartbeat.verificationStatus ?? (heartbeat.ok ? "connected" : "not_detected");
2437
2462
  } catch {
2438
2463
  this.connectionStatus = "offline";
2464
+ this.verificationStatus = "error";
2439
2465
  }
2440
2466
  this.events.emit("asiyst:ready", { projectId: this.options.projectId, configVersion: cfg.version });
2441
2467
  }
2442
2468
  getConnectionStatus() {
2443
2469
  return this.connectionStatus;
2444
2470
  }
2471
+ getVerificationStatus() {
2472
+ return this.verificationStatus;
2473
+ }
2445
2474
  getConfig() {
2446
2475
  return this.config.get();
2447
2476
  }
@@ -2564,6 +2593,9 @@ var Asiyst = {
2564
2593
  getConnectionStatus() {
2565
2594
  return requireRuntime().getConnectionStatus();
2566
2595
  },
2596
+ getVerificationStatus() {
2597
+ return requireRuntime().getVerificationStatus();
2598
+ },
2567
2599
  avatar: {
2568
2600
  show() {
2569
2601
  withIsolation(() => requireRuntime().avatarApi().show());