@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/README.md
CHANGED
|
@@ -41,19 +41,9 @@ Mark important controls so the assistant can find them across layouts:
|
|
|
41
41
|
</button>
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
The production API base is `https://asiyst.com/api/v1`. It is used by default and can only be overridden explicitly through `apiBaseUrl` for a controlled non-production deployment.
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
```ts
|
|
49
|
-
await Asiyst.init({
|
|
50
|
-
projectId: "dev_project",
|
|
51
|
-
publicKey: "dev_public_key",
|
|
52
|
-
apiBaseUrl: "http://localhost:8787",
|
|
53
|
-
});
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
If Cloud is unreachable, the SDK keeps a fallback avatar configuration and continues to run local APIs (`avatar.moveTo`, highlighting, events). Conversation replies and task plans are not invented locally; those requests fail until Cloud responds.
|
|
46
|
+
If Cloud is unreachable, the SDK keeps a fallback avatar configuration and exposes `getConnectionStatus()` as `offline`. Conversation replies and task plans are not invented locally; those requests fail until Cloud responds.
|
|
57
47
|
|
|
58
48
|
## Documentation
|
|
59
49
|
|
package/dist/index.cjs
CHANGED
|
@@ -69,7 +69,7 @@ var ALL_ACTION_KINDS = [
|
|
|
69
69
|
|
|
70
70
|
// src/core/constants.ts
|
|
71
71
|
var SDK_VERSION = "0.1.0";
|
|
72
|
-
var DEFAULT_API_BASE_URL = "https://
|
|
72
|
+
var DEFAULT_API_BASE_URL = "https://asiyst.com/api/v1";
|
|
73
73
|
var CONFIG_SCHEMA_VERSION = 1;
|
|
74
74
|
var HOST_ELEMENT_ID = "asiyst-host";
|
|
75
75
|
var DATA_ATTR = "data-asiyst";
|
|
@@ -343,7 +343,7 @@ var CloudClient = class {
|
|
|
343
343
|
}
|
|
344
344
|
async fetchConfig() {
|
|
345
345
|
const response = await this.transport.request({
|
|
346
|
-
path: `/
|
|
346
|
+
path: `/projects/${encodeURIComponent(this.projectId)}/avatar`,
|
|
347
347
|
method: "GET"
|
|
348
348
|
});
|
|
349
349
|
if (response.status === 401 || response.status === 403) {
|
|
@@ -354,9 +354,23 @@ var CloudClient = class {
|
|
|
354
354
|
}
|
|
355
355
|
return normalizeProjectConfig(response.data.config ?? response.data);
|
|
356
356
|
}
|
|
357
|
+
async heartbeat(metadata) {
|
|
358
|
+
const response = await this.transport.request({
|
|
359
|
+
path: "/sdk/heartbeat",
|
|
360
|
+
method: "POST",
|
|
361
|
+
body: {
|
|
362
|
+
projectId: this.projectId,
|
|
363
|
+
sdkVersion: SDK_VERSION,
|
|
364
|
+
websiteOrigin: metadata.origin,
|
|
365
|
+
environment: metadata.environment,
|
|
366
|
+
timestamp: metadata.timestamp
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
return { ok: response.ok, status: response.status };
|
|
370
|
+
}
|
|
357
371
|
async requestTask(userText, pageUrl) {
|
|
358
372
|
const response = await this.transport.request({
|
|
359
|
-
path: "/
|
|
373
|
+
path: "/tasks",
|
|
360
374
|
method: "POST",
|
|
361
375
|
body: {
|
|
362
376
|
projectId: this.projectId,
|
|
@@ -371,7 +385,7 @@ var CloudClient = class {
|
|
|
371
385
|
}
|
|
372
386
|
async fetchWorkflow(workflowId) {
|
|
373
387
|
const response = await this.transport.request({
|
|
374
|
-
path: `/
|
|
388
|
+
path: `/workflows/${encodeURIComponent(workflowId)}`,
|
|
375
389
|
method: "GET"
|
|
376
390
|
});
|
|
377
391
|
if (!response.ok || !response.data?.workflow?.id || !Array.isArray(response.data.workflow.steps)) {
|
|
@@ -381,7 +395,7 @@ var CloudClient = class {
|
|
|
381
395
|
}
|
|
382
396
|
async sendConversationMessage(text, pageUrl) {
|
|
383
397
|
const response = await this.transport.request({
|
|
384
|
-
path: "/
|
|
398
|
+
path: "/conversations/messages",
|
|
385
399
|
method: "POST",
|
|
386
400
|
body: { projectId: this.projectId, text, pageUrl }
|
|
387
401
|
});
|
|
@@ -391,13 +405,13 @@ var CloudClient = class {
|
|
|
391
405
|
return response.data;
|
|
392
406
|
}
|
|
393
407
|
async sendWebsiteMap(snapshot) {
|
|
394
|
-
await this.safePost("/
|
|
408
|
+
await this.safePost("/website-maps", snapshot);
|
|
395
409
|
}
|
|
396
410
|
async sendAnalytics(events) {
|
|
397
|
-
await this.safePost("/
|
|
411
|
+
await this.safePost("/analytics", { events });
|
|
398
412
|
}
|
|
399
413
|
async sendTaskUpdate(taskId, status, stepId) {
|
|
400
|
-
await this.safePost(`/
|
|
414
|
+
await this.safePost(`/tasks/${encodeURIComponent(taskId)}/events`, {
|
|
401
415
|
status,
|
|
402
416
|
stepId
|
|
403
417
|
});
|
|
@@ -2100,6 +2114,7 @@ var AsiystRuntime = class {
|
|
|
2100
2114
|
this.map = new WebsiteMap();
|
|
2101
2115
|
this.observer = new DomObserver(() => this.rescan());
|
|
2102
2116
|
this.destroyed = false;
|
|
2117
|
+
this.connectionStatus = "disconnected";
|
|
2103
2118
|
this.rescanDebounced = debounce(() => this.rescan(), DOM_SCAN_DEBOUNCE_MS);
|
|
2104
2119
|
if (!doc.body) {
|
|
2105
2120
|
throw new InitializationError("document.body is not available");
|
|
@@ -2167,8 +2182,21 @@ var AsiystRuntime = class {
|
|
|
2167
2182
|
const cfg = await isolateAsync(() => this.config.refresh(), this.config.get());
|
|
2168
2183
|
this.avatar.applyConfig(cfg);
|
|
2169
2184
|
this.avatar.show();
|
|
2185
|
+
try {
|
|
2186
|
+
const heartbeat = await this.cloud.heartbeat({
|
|
2187
|
+
origin: window.location.origin,
|
|
2188
|
+
environment: this.options.apiBaseUrl ? "development" : "production",
|
|
2189
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
2190
|
+
});
|
|
2191
|
+
this.connectionStatus = heartbeat.ok ? "connected" : "disconnected";
|
|
2192
|
+
} catch {
|
|
2193
|
+
this.connectionStatus = "offline";
|
|
2194
|
+
}
|
|
2170
2195
|
this.events.emit("asiyst:ready", { projectId: this.options.projectId, configVersion: cfg.version });
|
|
2171
2196
|
}
|
|
2197
|
+
getConnectionStatus() {
|
|
2198
|
+
return this.connectionStatus;
|
|
2199
|
+
}
|
|
2172
2200
|
getConfig() {
|
|
2173
2201
|
return this.config.get();
|
|
2174
2202
|
}
|
|
@@ -2288,6 +2316,9 @@ var Asiyst = {
|
|
|
2288
2316
|
getConfig() {
|
|
2289
2317
|
return requireRuntime().getConfig();
|
|
2290
2318
|
},
|
|
2319
|
+
getConnectionStatus() {
|
|
2320
|
+
return requireRuntime().getConnectionStatus();
|
|
2321
|
+
},
|
|
2291
2322
|
avatar: {
|
|
2292
2323
|
show() {
|
|
2293
2324
|
withIsolation(() => requireRuntime().avatarApi().show());
|