@asiyst/sdk 0.1.18 → 0.1.20
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.cjs +69 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +69 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -71,7 +71,7 @@ var ALL_ACTION_KINDS = [
|
|
|
71
71
|
// src/core/constants.ts
|
|
72
72
|
function resolveSdkVersion() {
|
|
73
73
|
{
|
|
74
|
-
return "0.1.
|
|
74
|
+
return "0.1.19";
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
var SDK_VERSION = resolveSdkVersion();
|
|
@@ -370,7 +370,11 @@ function validateInitOptions(options) {
|
|
|
370
370
|
if (typeof options.publicKey !== "string" || !options.publicKey.trim()) {
|
|
371
371
|
throw new ConfigurationError("publicKey is required");
|
|
372
372
|
}
|
|
373
|
-
|
|
373
|
+
const trimmedKey = options.publicKey.trim();
|
|
374
|
+
if (trimmedKey.startsWith("as_")) {
|
|
375
|
+
throw new ConfigurationError("Secret project API keys (as_...) must never be used in browser client code. Use the public project key.");
|
|
376
|
+
}
|
|
377
|
+
if (projectIdValue.length > 128 || trimmedKey.length > 256) {
|
|
374
378
|
throw new ConfigurationError("project credentials exceed allowed length");
|
|
375
379
|
}
|
|
376
380
|
const avatarId = typeof options.avatarId === "string" ? options.avatarId.trim() : "";
|
|
@@ -559,18 +563,33 @@ var CloudClient = class {
|
|
|
559
563
|
return this.inFlightToken;
|
|
560
564
|
}
|
|
561
565
|
async fetchConfig() {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
566
|
+
try {
|
|
567
|
+
const response = await this.runtimeRequest({
|
|
568
|
+
path: `/projects/${encodeURIComponent(this.projectId)}/avatar`,
|
|
569
|
+
method: "GET",
|
|
570
|
+
idempotent: true
|
|
571
|
+
});
|
|
572
|
+
if (response.ok && response.data) {
|
|
573
|
+
return normalizeProjectConfig(response.data.config ?? response.data);
|
|
574
|
+
}
|
|
575
|
+
} catch {
|
|
569
576
|
}
|
|
570
|
-
|
|
571
|
-
|
|
577
|
+
try {
|
|
578
|
+
const res = await fetch(`https://asiyst.com/api/v1/runtime/avatar?projectId=${encodeURIComponent(this.projectId)}&publicKey=${encodeURIComponent(this.publicKey)}`, {
|
|
579
|
+
headers: { Accept: "application/json" }
|
|
580
|
+
});
|
|
581
|
+
if (res.ok) {
|
|
582
|
+
const body = await res.json();
|
|
583
|
+
if (body?.avatar) {
|
|
584
|
+
return normalizeProjectConfig({
|
|
585
|
+
avatarName: body.avatar.name,
|
|
586
|
+
avatarId: body.avatar.avatarId
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
} catch {
|
|
572
591
|
}
|
|
573
|
-
return normalizeProjectConfig(
|
|
592
|
+
return normalizeProjectConfig({});
|
|
574
593
|
}
|
|
575
594
|
async heartbeat(metadata) {
|
|
576
595
|
const response = await this.runtimeRequest({
|
|
@@ -652,6 +671,9 @@ var CloudClient = class {
|
|
|
652
671
|
conversationId: this.conversationId
|
|
653
672
|
}, "assistant:conversation");
|
|
654
673
|
if (!response.ok || !response.data?.message?.text) {
|
|
674
|
+
if (response.status === 401 || response.status === 403) {
|
|
675
|
+
throw new NetworkError("AI request authorization failed. The project credentials may be inactive, revoked, or inaccessible.");
|
|
676
|
+
}
|
|
655
677
|
throw new NetworkError("Conversation service is unavailable");
|
|
656
678
|
}
|
|
657
679
|
return response.data;
|
|
@@ -668,6 +690,33 @@ var CloudClient = class {
|
|
|
668
690
|
async sendAnalytics(events) {
|
|
669
691
|
await this.safePost("/analytics", { events });
|
|
670
692
|
}
|
|
693
|
+
async sendTelemetryEvent(eventType, metadata = {}) {
|
|
694
|
+
try {
|
|
695
|
+
const origin = typeof window !== "undefined" ? window.location.origin : void 0;
|
|
696
|
+
const installationId = this.runtimeAuth ? this.runtimeAuth.options?.installationId : void 0;
|
|
697
|
+
const payload = {
|
|
698
|
+
projectId: this.projectId,
|
|
699
|
+
publicKey: this.publicKey,
|
|
700
|
+
eventType,
|
|
701
|
+
installationId,
|
|
702
|
+
origin,
|
|
703
|
+
metadata: {
|
|
704
|
+
...metadata,
|
|
705
|
+
sdkVersion: SDK_VERSION
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
await fetch("https://asiyst.com/api/v1/events", {
|
|
709
|
+
method: "POST",
|
|
710
|
+
headers: {
|
|
711
|
+
"Content-Type": "application/json",
|
|
712
|
+
Accept: "application/json",
|
|
713
|
+
"x-asiyst-public-key": this.publicKey
|
|
714
|
+
},
|
|
715
|
+
body: JSON.stringify(payload)
|
|
716
|
+
});
|
|
717
|
+
} catch {
|
|
718
|
+
}
|
|
719
|
+
}
|
|
671
720
|
async sendTaskUpdate(taskId, status, stepId) {
|
|
672
721
|
await this.safePost(`/tasks/${encodeURIComponent(taskId)}/events`, {
|
|
673
722
|
status,
|
|
@@ -2951,6 +3000,14 @@ var AsiystRuntime = class {
|
|
|
2951
3000
|
}
|
|
2952
3001
|
}
|
|
2953
3002
|
this.events.emit("asiyst:ready", { projectId: this.options.projectId, configVersion: cfg.version });
|
|
3003
|
+
void this.cloud.sendTelemetryEvent("avatar_runtime_initialized", {
|
|
3004
|
+
avatarId: this.options.avatarId ?? cfg.avatarName,
|
|
3005
|
+
avatarName: cfg.avatarName
|
|
3006
|
+
});
|
|
3007
|
+
void this.cloud.sendTelemetryEvent("avatar_asset_loaded", {
|
|
3008
|
+
avatarId: this.options.avatarId ?? cfg.avatarName,
|
|
3009
|
+
avatarName: cfg.avatarName
|
|
3010
|
+
});
|
|
2954
3011
|
}
|
|
2955
3012
|
getConnectionStatus() {
|
|
2956
3013
|
return this.connectionStatus;
|