@asiyst/sdk 0.1.0 → 0.1.4

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.d.cts CHANGED
@@ -187,6 +187,7 @@ declare const Asiyst: {
187
187
  open(): void;
188
188
  close(): void;
189
189
  getConfig(): ProjectConfig;
190
+ getConnectionStatus(): "connected" | "disconnected" | "offline";
190
191
  avatar: {
191
192
  show(): void;
192
193
  hide(): void;
package/dist/index.d.ts CHANGED
@@ -187,6 +187,7 @@ declare const Asiyst: {
187
187
  open(): void;
188
188
  close(): void;
189
189
  getConfig(): ProjectConfig;
190
+ getConnectionStatus(): "connected" | "disconnected" | "offline";
190
191
  avatar: {
191
192
  show(): void;
192
193
  hide(): void;
package/dist/index.js CHANGED
@@ -67,7 +67,7 @@ var ALL_ACTION_KINDS = [
67
67
 
68
68
  // src/core/constants.ts
69
69
  var SDK_VERSION = "0.1.0";
70
- var DEFAULT_API_BASE_URL = "https://api.asiyst.com";
70
+ var DEFAULT_API_BASE_URL = "https://asiyst.com/api/v1";
71
71
  var CONFIG_SCHEMA_VERSION = 1;
72
72
  var HOST_ELEMENT_ID = "asiyst-host";
73
73
  var DATA_ATTR = "data-asiyst";
@@ -341,7 +341,7 @@ var CloudClient = class {
341
341
  }
342
342
  async fetchConfig() {
343
343
  const response = await this.transport.request({
344
- path: `/v1/projects/${encodeURIComponent(this.projectId)}/config`,
344
+ path: `/projects/${encodeURIComponent(this.projectId)}/avatar`,
345
345
  method: "GET"
346
346
  });
347
347
  if (response.status === 401 || response.status === 403) {
@@ -352,9 +352,23 @@ var CloudClient = class {
352
352
  }
353
353
  return normalizeProjectConfig(response.data.config ?? response.data);
354
354
  }
355
+ async heartbeat(metadata) {
356
+ const response = await this.transport.request({
357
+ path: "/sdk/heartbeat",
358
+ method: "POST",
359
+ body: {
360
+ projectId: this.projectId,
361
+ sdkVersion: SDK_VERSION,
362
+ websiteOrigin: metadata.origin,
363
+ environment: metadata.environment,
364
+ timestamp: metadata.timestamp
365
+ }
366
+ });
367
+ return { ok: response.ok, status: response.status };
368
+ }
355
369
  async requestTask(userText, pageUrl) {
356
370
  const response = await this.transport.request({
357
- path: "/v1/tasks",
371
+ path: "/tasks",
358
372
  method: "POST",
359
373
  body: {
360
374
  projectId: this.projectId,
@@ -369,7 +383,7 @@ var CloudClient = class {
369
383
  }
370
384
  async fetchWorkflow(workflowId) {
371
385
  const response = await this.transport.request({
372
- path: `/v1/workflows/${encodeURIComponent(workflowId)}`,
386
+ path: `/workflows/${encodeURIComponent(workflowId)}`,
373
387
  method: "GET"
374
388
  });
375
389
  if (!response.ok || !response.data?.workflow?.id || !Array.isArray(response.data.workflow.steps)) {
@@ -379,7 +393,7 @@ var CloudClient = class {
379
393
  }
380
394
  async sendConversationMessage(text, pageUrl) {
381
395
  const response = await this.transport.request({
382
- path: "/v1/conversations/messages",
396
+ path: "/conversations/messages",
383
397
  method: "POST",
384
398
  body: { projectId: this.projectId, text, pageUrl }
385
399
  });
@@ -389,13 +403,13 @@ var CloudClient = class {
389
403
  return response.data;
390
404
  }
391
405
  async sendWebsiteMap(snapshot) {
392
- await this.safePost("/v1/website-maps", snapshot);
406
+ await this.safePost("/website-maps", snapshot);
393
407
  }
394
408
  async sendAnalytics(events) {
395
- await this.safePost("/v1/analytics", { events });
409
+ await this.safePost("/analytics", { events });
396
410
  }
397
411
  async sendTaskUpdate(taskId, status, stepId) {
398
- await this.safePost(`/v1/tasks/${encodeURIComponent(taskId)}/events`, {
412
+ await this.safePost(`/tasks/${encodeURIComponent(taskId)}/events`, {
399
413
  status,
400
414
  stepId
401
415
  });
@@ -2098,6 +2112,7 @@ var AsiystRuntime = class {
2098
2112
  this.map = new WebsiteMap();
2099
2113
  this.observer = new DomObserver(() => this.rescan());
2100
2114
  this.destroyed = false;
2115
+ this.connectionStatus = "disconnected";
2101
2116
  this.rescanDebounced = debounce(() => this.rescan(), DOM_SCAN_DEBOUNCE_MS);
2102
2117
  if (!doc.body) {
2103
2118
  throw new InitializationError("document.body is not available");
@@ -2165,8 +2180,21 @@ var AsiystRuntime = class {
2165
2180
  const cfg = await isolateAsync(() => this.config.refresh(), this.config.get());
2166
2181
  this.avatar.applyConfig(cfg);
2167
2182
  this.avatar.show();
2183
+ try {
2184
+ const heartbeat = await this.cloud.heartbeat({
2185
+ origin: window.location.origin,
2186
+ environment: this.options.apiBaseUrl ? "development" : "production",
2187
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
2188
+ });
2189
+ this.connectionStatus = heartbeat.ok ? "connected" : "disconnected";
2190
+ } catch {
2191
+ this.connectionStatus = "offline";
2192
+ }
2168
2193
  this.events.emit("asiyst:ready", { projectId: this.options.projectId, configVersion: cfg.version });
2169
2194
  }
2195
+ getConnectionStatus() {
2196
+ return this.connectionStatus;
2197
+ }
2170
2198
  getConfig() {
2171
2199
  return this.config.get();
2172
2200
  }
@@ -2286,6 +2314,9 @@ var Asiyst = {
2286
2314
  getConfig() {
2287
2315
  return requireRuntime().getConfig();
2288
2316
  },
2317
+ getConnectionStatus() {
2318
+ return requireRuntime().getConnectionStatus();
2319
+ },
2289
2320
  avatar: {
2290
2321
  show() {
2291
2322
  withIsolation(() => requireRuntime().avatarApi().show());