@alfe.ai/agent-api-client 0.3.0 → 0.4.0
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 +16 -0
- package/dist/index.cjs +139 -0
- package/dist/index.d.cts +152 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +152 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +139 -0
- package/dist/index.js.map +1 -1
- package/package.json +10 -1
package/dist/index.js
CHANGED
|
@@ -595,6 +595,47 @@ var AgentApiClient = class {
|
|
|
595
595
|
body: JSON.stringify(data)
|
|
596
596
|
});
|
|
597
597
|
}
|
|
598
|
+
/** Update the agent's own name and/or voice config. Returns the updated agent. */
|
|
599
|
+
async updateSelf(update) {
|
|
600
|
+
return this.request("/agent/self", {
|
|
601
|
+
method: "PATCH",
|
|
602
|
+
body: JSON.stringify(update)
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Generate the agent's own avatar from a text prompt. The image is generated,
|
|
607
|
+
* stored, and set on the agent server-side; returns the updated agent.
|
|
608
|
+
*/
|
|
609
|
+
async generateAvatar(args) {
|
|
610
|
+
return this.request("/agent/avatar/generate", {
|
|
611
|
+
method: "POST",
|
|
612
|
+
body: JSON.stringify(args)
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Get a presigned PUT URL to upload a new avatar image. Upload the bytes to
|
|
617
|
+
* `uploadUrl`, then call `finalizeAvatar(s3Key)` to set it on the agent.
|
|
618
|
+
*/
|
|
619
|
+
async presignAvatar(args) {
|
|
620
|
+
return this.request("/agent/avatar/presign", {
|
|
621
|
+
method: "POST",
|
|
622
|
+
body: JSON.stringify(args)
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Finalize an avatar upload — validates ownership + size, then sets the
|
|
627
|
+
* agent's `avatarUrl` server-side. Returns the updated agent.
|
|
628
|
+
*/
|
|
629
|
+
async finalizeAvatar(s3Key) {
|
|
630
|
+
return this.request("/agent/avatar", {
|
|
631
|
+
method: "POST",
|
|
632
|
+
body: JSON.stringify({ s3Key })
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
/** List the platform voice catalogue (ElevenLabs) so the agent can pick its own voice. */
|
|
636
|
+
async listVoices() {
|
|
637
|
+
return this.request("/agent/voices");
|
|
638
|
+
}
|
|
598
639
|
/**
|
|
599
640
|
* Mint a fresh AES-256 data key for a specific (secret, field) pair. The
|
|
600
641
|
* encryption context is rebuilt server-side from `auth.tenantId` + the body
|
|
@@ -990,6 +1031,104 @@ var AgentApiClient = class {
|
|
|
990
1031
|
body: JSON.stringify(entry)
|
|
991
1032
|
}).catch(() => {});
|
|
992
1033
|
}
|
|
1034
|
+
async requestBrowserTakeover(args) {
|
|
1035
|
+
return this.request("/agent/remote/takeover", {
|
|
1036
|
+
method: "POST",
|
|
1037
|
+
body: JSON.stringify(args)
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
async getRemoteSession(sessionId) {
|
|
1041
|
+
return this.request(`/agent/remote/sessions/${encodeURIComponent(sessionId)}`);
|
|
1042
|
+
}
|
|
1043
|
+
async completeRemoteSession(sessionId) {
|
|
1044
|
+
return this.request(`/agent/remote/sessions/${encodeURIComponent(sessionId)}/complete`, {
|
|
1045
|
+
method: "POST",
|
|
1046
|
+
body: JSON.stringify({})
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Issue a request that returns the raw `Response` (no JSON parsing, no
|
|
1051
|
+
* forced Content-Type). The caller sets `Content-Type`/`Accept` on `headers`
|
|
1052
|
+
* and reads the body itself (`arrayBuffer()` / `json()`).
|
|
1053
|
+
*
|
|
1054
|
+
* A single retry fires only on the same transient statuses `request()`
|
|
1055
|
+
* retries (authorizer-timeout 500 + LB 502/503/504) and transient network
|
|
1056
|
+
* errors — before the route handler runs — so re-issuing a POST does not
|
|
1057
|
+
* risk a duplicate side effect. Voice TTS/STT are effectively idempotent
|
|
1058
|
+
* (re-synthesize / re-transcribe) and meter server-side keyed on the
|
|
1059
|
+
* gateway requestId, so a retried transcription doesn't double-bill.
|
|
1060
|
+
*/
|
|
1061
|
+
async rawFetch(path, init) {
|
|
1062
|
+
const url = `${this.apiUrl}${path}`;
|
|
1063
|
+
init.headers.set("Authorization", `Bearer ${this.apiKey}`);
|
|
1064
|
+
let lastError;
|
|
1065
|
+
for (let attempt = 1; attempt <= 2; attempt++) try {
|
|
1066
|
+
const res = await fetch(url, {
|
|
1067
|
+
method: init.method,
|
|
1068
|
+
headers: init.headers,
|
|
1069
|
+
body: init.body,
|
|
1070
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
1071
|
+
});
|
|
1072
|
+
if (!res.ok) {
|
|
1073
|
+
await res.text();
|
|
1074
|
+
const error = /* @__PURE__ */ new Error(`Agent API request failed (${String(res.status)})`);
|
|
1075
|
+
if (attempt === 1 && RETRYABLE_STATUS.has(res.status)) {
|
|
1076
|
+
lastError = error;
|
|
1077
|
+
await sleep(RETRY_DELAY_MS);
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
throw error;
|
|
1081
|
+
}
|
|
1082
|
+
return res;
|
|
1083
|
+
} catch (err) {
|
|
1084
|
+
if (attempt === 1 && isRetryableNetworkError(err)) {
|
|
1085
|
+
lastError = err;
|
|
1086
|
+
await sleep(RETRY_DELAY_MS);
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
throw err;
|
|
1090
|
+
}
|
|
1091
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Text-to-speech. Returns raw PCM audio bytes plus their framing — the
|
|
1095
|
+
* voice service defaults to 24 kHz / mono / 16-bit. Wrap in a WAV container
|
|
1096
|
+
* to produce a playable file. Metered per character against the tenant
|
|
1097
|
+
* credit pool server-side; TTS completes regardless of metering outcome.
|
|
1098
|
+
*/
|
|
1099
|
+
async tts(args) {
|
|
1100
|
+
const headers = new Headers();
|
|
1101
|
+
headers.set("Content-Type", "application/json");
|
|
1102
|
+
headers.set("Accept", "audio/pcm");
|
|
1103
|
+
const res = await this.rawFetch("/voice/tts", {
|
|
1104
|
+
method: "POST",
|
|
1105
|
+
headers,
|
|
1106
|
+
body: JSON.stringify(args)
|
|
1107
|
+
});
|
|
1108
|
+
return {
|
|
1109
|
+
audio: Buffer.from(await res.arrayBuffer()),
|
|
1110
|
+
sampleRate: parseInt(res.headers.get("x-sample-rate") ?? "24000", 10),
|
|
1111
|
+
channels: parseInt(res.headers.get("x-channels") ?? "1", 10),
|
|
1112
|
+
bitDepth: parseInt(res.headers.get("x-bit-depth") ?? "16", 10)
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Speech-to-text. Accepts raw linear16 (16-bit LE) mono PCM — NOT a WAV or
|
|
1117
|
+
* other container (the endpoint transcribes with a fixed linear16 encoding,
|
|
1118
|
+
* so a container header would be transcribed as noise). Strip any WAV header
|
|
1119
|
+
* and pass `sampleRate` from it before calling. Metered by transcribed
|
|
1120
|
+
* duration against the tenant credit pool server-side.
|
|
1121
|
+
*/
|
|
1122
|
+
async stt(args) {
|
|
1123
|
+
const headers = new Headers();
|
|
1124
|
+
headers.set("Content-Type", "application/octet-stream");
|
|
1125
|
+
headers.set("x-sample-rate", String(args.sampleRate));
|
|
1126
|
+
return (await (await this.rawFetch("/voice/stt", {
|
|
1127
|
+
method: "POST",
|
|
1128
|
+
headers,
|
|
1129
|
+
body: args.audio
|
|
1130
|
+
})).json()).data;
|
|
1131
|
+
}
|
|
993
1132
|
};
|
|
994
1133
|
//#endregion
|
|
995
1134
|
export { AgentApiClient };
|