@asiyst/sdk 0.1.0 → 0.1.3
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 +2 -12
- package/dist/index.cjs +39 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +39 -8
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
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://
|
|
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: `/
|
|
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: "/
|
|
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: `/
|
|
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: "/
|
|
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("/
|
|
406
|
+
await this.safePost("/website-maps", snapshot);
|
|
393
407
|
}
|
|
394
408
|
async sendAnalytics(events) {
|
|
395
|
-
await this.safePost("/
|
|
409
|
+
await this.safePost("/analytics", { events });
|
|
396
410
|
}
|
|
397
411
|
async sendTaskUpdate(taskId, status, stepId) {
|
|
398
|
-
await this.safePost(`/
|
|
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());
|