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