@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 +5 -0
- package/dist/index.cjs +41 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +41 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -82,6 +82,8 @@ type TargetInput = string | TargetRef;
|
|
|
82
82
|
interface InitOptions {
|
|
83
83
|
projectId: string;
|
|
84
84
|
publicKey: string;
|
|
85
|
+
avatarId?: string;
|
|
86
|
+
position?: AnchorPosition;
|
|
85
87
|
apiBaseUrl?: string;
|
|
86
88
|
mode?: AssistantMode;
|
|
87
89
|
allowedActions?: ActionKind[];
|
|
@@ -215,6 +217,7 @@ declare const Asiyst: {
|
|
|
215
217
|
close(): void;
|
|
216
218
|
getConfig(): ProjectConfig;
|
|
217
219
|
getConnectionStatus(): "connected" | "disconnected" | "offline";
|
|
220
|
+
getVerificationStatus(): "connected" | "inactive" | "not_detected" | "error";
|
|
218
221
|
avatar: {
|
|
219
222
|
show(): void;
|
|
220
223
|
hide(): void;
|
|
@@ -290,9 +293,13 @@ declare function normalizeProjectConfig(raw: unknown): ProjectConfig;
|
|
|
290
293
|
declare function validateInitOptions(options: {
|
|
291
294
|
projectId?: unknown;
|
|
292
295
|
publicKey?: unknown;
|
|
296
|
+
avatarId?: unknown;
|
|
297
|
+
position?: unknown;
|
|
293
298
|
}): {
|
|
294
299
|
projectId: string;
|
|
295
300
|
publicKey: string;
|
|
301
|
+
avatarId?: string;
|
|
302
|
+
position?: AnchorPosition;
|
|
296
303
|
};
|
|
297
304
|
|
|
298
305
|
declare function isSafeSelector(selector: string): boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -82,6 +82,8 @@ type TargetInput = string | TargetRef;
|
|
|
82
82
|
interface InitOptions {
|
|
83
83
|
projectId: string;
|
|
84
84
|
publicKey: string;
|
|
85
|
+
avatarId?: string;
|
|
86
|
+
position?: AnchorPosition;
|
|
85
87
|
apiBaseUrl?: string;
|
|
86
88
|
mode?: AssistantMode;
|
|
87
89
|
allowedActions?: ActionKind[];
|
|
@@ -215,6 +217,7 @@ declare const Asiyst: {
|
|
|
215
217
|
close(): void;
|
|
216
218
|
getConfig(): ProjectConfig;
|
|
217
219
|
getConnectionStatus(): "connected" | "disconnected" | "offline";
|
|
220
|
+
getVerificationStatus(): "connected" | "inactive" | "not_detected" | "error";
|
|
218
221
|
avatar: {
|
|
219
222
|
show(): void;
|
|
220
223
|
hide(): void;
|
|
@@ -290,9 +293,13 @@ declare function normalizeProjectConfig(raw: unknown): ProjectConfig;
|
|
|
290
293
|
declare function validateInitOptions(options: {
|
|
291
294
|
projectId?: unknown;
|
|
292
295
|
publicKey?: unknown;
|
|
296
|
+
avatarId?: unknown;
|
|
297
|
+
position?: unknown;
|
|
293
298
|
}): {
|
|
294
299
|
projectId: string;
|
|
295
300
|
publicKey: string;
|
|
301
|
+
avatarId?: string;
|
|
302
|
+
position?: AnchorPosition;
|
|
296
303
|
};
|
|
297
304
|
|
|
298
305
|
declare function isSafeSelector(selector: string): boolean;
|
package/dist/index.js
CHANGED
|
@@ -69,7 +69,7 @@ var ALL_ACTION_KINDS = [
|
|
|
69
69
|
];
|
|
70
70
|
|
|
71
71
|
// src/core/constants.ts
|
|
72
|
-
var SDK_VERSION = "0.1.
|
|
72
|
+
var SDK_VERSION = "0.1.9" ;
|
|
73
73
|
var DEFAULT_API_BASE_URL = "https://nqhxpgsjofzqudyqkqib.supabase.co/functions/v1/api";
|
|
74
74
|
var CONFIG_SCHEMA_VERSION = 1;
|
|
75
75
|
var HOST_ELEMENT_ID = "asiyst-host";
|
|
@@ -368,9 +368,19 @@ function validateInitOptions(options) {
|
|
|
368
368
|
if (projectIdValue.length > 128 || options.publicKey.trim().length > 256) {
|
|
369
369
|
throw new ConfigurationError("project credentials exceed allowed length");
|
|
370
370
|
}
|
|
371
|
+
const avatarId = typeof options.avatarId === "string" ? options.avatarId.trim() : "";
|
|
372
|
+
if (options.avatarId !== void 0 && (!avatarId || avatarId.length > 128 || !/^[A-Za-z0-9_-]+$/.test(avatarId))) {
|
|
373
|
+
throw new ConfigurationError("Asiyst SDK: avatarId is invalid.");
|
|
374
|
+
}
|
|
375
|
+
const position = options.position === void 0 ? void 0 : ANCHORS.includes(options.position) ? options.position : void 0;
|
|
376
|
+
if (options.position !== void 0 && !position) {
|
|
377
|
+
throw new ConfigurationError("Asiyst SDK: position is invalid.");
|
|
378
|
+
}
|
|
371
379
|
return {
|
|
372
380
|
projectId: projectIdValue,
|
|
373
|
-
publicKey: options.publicKey.trim()
|
|
381
|
+
publicKey: options.publicKey.trim(),
|
|
382
|
+
avatarId: avatarId || void 0,
|
|
383
|
+
position
|
|
374
384
|
};
|
|
375
385
|
}
|
|
376
386
|
|
|
@@ -421,6 +431,7 @@ var HttpTransport = class {
|
|
|
421
431
|
"Content-Type": "application/json",
|
|
422
432
|
"X-Asiyst-Project-Id": this.options.projectId,
|
|
423
433
|
"X-Asiyst-Public-Key": this.options.publicKey,
|
|
434
|
+
...this.options.avatarId ? { "X-Asiyst-Avatar-Id": this.options.avatarId } : {},
|
|
424
435
|
"X-Asiyst-SDK-Version": SDK_VERSION
|
|
425
436
|
},
|
|
426
437
|
body: req.body === void 0 ? void 0 : JSON.stringify(req.body),
|
|
@@ -447,9 +458,10 @@ var HttpTransport = class {
|
|
|
447
458
|
|
|
448
459
|
// src/communication/CloudClient.ts
|
|
449
460
|
var CloudClient = class {
|
|
450
|
-
constructor(transport, projectId) {
|
|
461
|
+
constructor(transport, projectId, publicKey = "") {
|
|
451
462
|
this.transport = transport;
|
|
452
463
|
this.projectId = projectId;
|
|
464
|
+
this.publicKey = publicKey;
|
|
453
465
|
}
|
|
454
466
|
async fetchConfig() {
|
|
455
467
|
const response = await this.transport.request({
|
|
@@ -469,14 +481,22 @@ var CloudClient = class {
|
|
|
469
481
|
path: "/sdk/heartbeat",
|
|
470
482
|
method: "POST",
|
|
471
483
|
body: {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
484
|
+
project_id: this.projectId,
|
|
485
|
+
public_key: this.publicKey,
|
|
486
|
+
sdk_version: SDK_VERSION,
|
|
487
|
+
origin: metadata.origin,
|
|
475
488
|
environment: metadata.environment,
|
|
476
489
|
timestamp: metadata.timestamp
|
|
477
490
|
}
|
|
478
491
|
});
|
|
479
|
-
|
|
492
|
+
const body = response.data && typeof response.data === "object" && !Array.isArray(response.data) ? response.data : void 0;
|
|
493
|
+
const rawStatus = body?.status ?? body?.connectionStatus ?? body?.verificationStatus;
|
|
494
|
+
const verificationStatus = rawStatus === "connected" || rawStatus === "inactive" || rawStatus === "not_detected" || rawStatus === "error" ? rawStatus : void 0;
|
|
495
|
+
return {
|
|
496
|
+
ok: response.ok && (verificationStatus === void 0 || verificationStatus === "connected"),
|
|
497
|
+
status: response.status,
|
|
498
|
+
verificationStatus
|
|
499
|
+
};
|
|
480
500
|
}
|
|
481
501
|
async requestTask(userText, pageUrl) {
|
|
482
502
|
const response = await this.transport.request({
|
|
@@ -650,6 +670,7 @@ var ConfigManager = class {
|
|
|
650
670
|
return {
|
|
651
671
|
...base,
|
|
652
672
|
mode: this.options.mode ?? base.mode,
|
|
673
|
+
position: this.options.position ?? base.position,
|
|
653
674
|
allowedActions: this.options.allowedActions ?? base.allowedActions
|
|
654
675
|
};
|
|
655
676
|
}
|
|
@@ -2349,6 +2370,7 @@ var AsiystRuntime = class {
|
|
|
2349
2370
|
this.observer = new DomObserver(() => this.rescan());
|
|
2350
2371
|
this.destroyed = false;
|
|
2351
2372
|
this.connectionStatus = "disconnected";
|
|
2373
|
+
this.verificationStatus = "not_detected";
|
|
2352
2374
|
this.rescanDebounced = debounce(() => this.rescan(), DOM_SCAN_DEBOUNCE_MS);
|
|
2353
2375
|
if (!doc.body) {
|
|
2354
2376
|
throw new InitializationError("document.body is not available");
|
|
@@ -2357,9 +2379,10 @@ var AsiystRuntime = class {
|
|
|
2357
2379
|
const transport = new HttpTransport({
|
|
2358
2380
|
apiBaseUrl: options.apiBaseUrl ?? DEFAULT_API_BASE_URL,
|
|
2359
2381
|
projectId: options.projectId,
|
|
2360
|
-
publicKey: options.publicKey
|
|
2382
|
+
publicKey: options.publicKey,
|
|
2383
|
+
avatarId: options.avatarId
|
|
2361
2384
|
});
|
|
2362
|
-
this.cloud = new CloudClient(transport, options.projectId);
|
|
2385
|
+
this.cloud = new CloudClient(transport, options.projectId, options.publicKey);
|
|
2363
2386
|
this.config = new ConfigManager(options, this.cloud, this.events);
|
|
2364
2387
|
this.analytics = new Analytics(options.projectId, this.cloud);
|
|
2365
2388
|
this.host = new HostRoot(doc);
|
|
@@ -2417,6 +2440,7 @@ var AsiystRuntime = class {
|
|
|
2417
2440
|
const domainCheck = validateWebsiteDomain(cfg, window.location.href);
|
|
2418
2441
|
if (!domainCheck.allowed) {
|
|
2419
2442
|
this.connectionStatus = "disconnected";
|
|
2443
|
+
this.verificationStatus = "not_detected";
|
|
2420
2444
|
this.events.emit("asiyst:error", {
|
|
2421
2445
|
code: "domain_not_authorized",
|
|
2422
2446
|
message: "This website is not authorized for the current Asiyst project."
|
|
@@ -2432,14 +2456,19 @@ var AsiystRuntime = class {
|
|
|
2432
2456
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
2433
2457
|
});
|
|
2434
2458
|
this.connectionStatus = heartbeat.ok ? "connected" : "disconnected";
|
|
2459
|
+
this.verificationStatus = heartbeat.verificationStatus ?? (heartbeat.ok ? "connected" : "not_detected");
|
|
2435
2460
|
} catch {
|
|
2436
2461
|
this.connectionStatus = "offline";
|
|
2462
|
+
this.verificationStatus = "error";
|
|
2437
2463
|
}
|
|
2438
2464
|
this.events.emit("asiyst:ready", { projectId: this.options.projectId, configVersion: cfg.version });
|
|
2439
2465
|
}
|
|
2440
2466
|
getConnectionStatus() {
|
|
2441
2467
|
return this.connectionStatus;
|
|
2442
2468
|
}
|
|
2469
|
+
getVerificationStatus() {
|
|
2470
|
+
return this.verificationStatus;
|
|
2471
|
+
}
|
|
2443
2472
|
getConfig() {
|
|
2444
2473
|
return this.config.get();
|
|
2445
2474
|
}
|
|
@@ -2562,6 +2591,9 @@ var Asiyst = {
|
|
|
2562
2591
|
getConnectionStatus() {
|
|
2563
2592
|
return requireRuntime().getConnectionStatus();
|
|
2564
2593
|
},
|
|
2594
|
+
getVerificationStatus() {
|
|
2595
|
+
return requireRuntime().getVerificationStatus();
|
|
2596
|
+
},
|
|
2565
2597
|
avatar: {
|
|
2566
2598
|
show() {
|
|
2567
2599
|
withIsolation(() => requireRuntime().avatarApi().show());
|