@alfe.ai/agent-api-client 0.3.0 → 0.5.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 +172 -0
- package/dist/index.d.cts +172 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +172 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +172 -0
- package/dist/index.js.map +1 -1
- package/package.json +10 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;AAiGwB,UAlDP,oBAAA,CAkDO;QAAf,EAAA,MAAA;EAAM,MAAA,EAAA,MAAA;AAGf;AAMiB,UApDA,iBAAA,CAoDmB;EAQnB,SAAA,EAAA,MAAA;EAQA,OAAA,EAAA,MAAA;EASA,OAAA,EAAA,SAAc,GAAA,UAAA;EAQd,MAAA,EAAA,eAAa,GAAA,gBAAA,GAAA,kBAAA,GAAA,UAAA,GAAA,WAAA,GAAA,SAAA,GAAA,QAAA;EASb,GAAA,CAAA,EAAA,MAAA;EAQA,YAAA,CAAA,EAAA,MAAkB;EAMlB,WAAA,CAAA,EAAA,MAAe;AAehC;AAEiB,UA1GA,aAAA,CA0Gc;EAMd,OAAA,EAAA,MAAA;EAcA,QAAA,EAAA,MAAA;EAMA,WAAA,EAAA,MAAA;EAKA,QAAA,EAAA,MAAA;EAAgB,MAAA,EAAA,OAAA,GAAA,SAAA,GAAA,QAAA;WACpB,CAAA,EAAA,MAAA;WAIJ,CAAA,EAAA,MAAA;EAAoB,QAAA,CAAA,EAAA,MAAA;AAK7B;AAWiB,UAnJA,iBAAA,CAmJY;EAkDZ,IAAA,EAAA,MAAA;EAaA,IAAA,EAAA,MAAS;EAUT,QAAA,EAAA,MAAA;EAYA,I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|
});
|
|
591
591
|
}
|
|
592
|
+
/**
|
|
593
|
+
* Generate an image from a text prompt and get back a STABLE, public URL
|
|
594
|
+
* (served from the agent-assets CDN — it does not expire). The image is
|
|
595
|
+
* generated + stored server-side; embed the returned `imageUrl` in a reply as
|
|
596
|
+
* markdown to show it to the user.
|
|
597
|
+
*
|
|
598
|
+
* Unlike most methods this reads the server's error body so a bad-request
|
|
599
|
+
* detail (e.g. an unsupported `size`) reaches the caller instead of an opaque
|
|
600
|
+
* "request failed (400)". Not retried — generation is expensive and
|
|
601
|
+
* non-idempotent.
|
|
602
|
+
*/
|
|
603
|
+
async generateImage(args) {
|
|
604
|
+
const headers = new Headers();
|
|
605
|
+
headers.set("Authorization", `Bearer ${this.apiKey}`);
|
|
606
|
+
headers.set("Content-Type", "application/json");
|
|
607
|
+
const res = await fetch(`${this.apiUrl}/agent/images/generate`, {
|
|
608
|
+
method: "POST",
|
|
609
|
+
headers,
|
|
610
|
+
body: JSON.stringify(args),
|
|
611
|
+
signal: AbortSignal.timeout(33e3)
|
|
612
|
+
});
|
|
613
|
+
if (!res.ok) {
|
|
614
|
+
const body = await res.text().catch(() => "");
|
|
615
|
+
let detail = "";
|
|
616
|
+
try {
|
|
617
|
+
const parsed = JSON.parse(body);
|
|
618
|
+
const msg = typeof parsed.message === "string" ? parsed.message : typeof parsed.error === "string" ? parsed.error : "";
|
|
619
|
+
if (msg) detail = `: ${msg}`;
|
|
620
|
+
} catch {}
|
|
621
|
+
throw new Error(`Image generation failed (${String(res.status)})${detail}`);
|
|
622
|
+
}
|
|
623
|
+
return (await res.json()).data;
|
|
624
|
+
}
|
|
592
625
|
async recordActivity(data) {
|
|
593
626
|
return this.request("/agent/activity", {
|
|
594
627
|
method: "POST",
|
|
595
628
|
body: JSON.stringify(data)
|
|
596
629
|
});
|
|
597
630
|
}
|
|
631
|
+
/** Update the agent's own name and/or voice config. Returns the updated agent. */
|
|
632
|
+
async updateSelf(update) {
|
|
633
|
+
return this.request("/agent/self", {
|
|
634
|
+
method: "PATCH",
|
|
635
|
+
body: JSON.stringify(update)
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Generate the agent's own avatar from a text prompt. The image is generated,
|
|
640
|
+
* stored, and set on the agent server-side; returns the updated agent.
|
|
641
|
+
*/
|
|
642
|
+
async generateAvatar(args) {
|
|
643
|
+
return this.request("/agent/avatar/generate", {
|
|
644
|
+
method: "POST",
|
|
645
|
+
body: JSON.stringify(args)
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Get a presigned PUT URL to upload a new avatar image. Upload the bytes to
|
|
650
|
+
* `uploadUrl`, then call `finalizeAvatar(s3Key)` to set it on the agent.
|
|
651
|
+
*/
|
|
652
|
+
async presignAvatar(args) {
|
|
653
|
+
return this.request("/agent/avatar/presign", {
|
|
654
|
+
method: "POST",
|
|
655
|
+
body: JSON.stringify(args)
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Finalize an avatar upload — validates ownership + size, then sets the
|
|
660
|
+
* agent's `avatarUrl` server-side. Returns the updated agent.
|
|
661
|
+
*/
|
|
662
|
+
async finalizeAvatar(s3Key) {
|
|
663
|
+
return this.request("/agent/avatar", {
|
|
664
|
+
method: "POST",
|
|
665
|
+
body: JSON.stringify({ s3Key })
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
/** List the platform voice catalogue (ElevenLabs) so the agent can pick its own voice. */
|
|
669
|
+
async listVoices() {
|
|
670
|
+
return this.request("/agent/voices");
|
|
671
|
+
}
|
|
598
672
|
/**
|
|
599
673
|
* Mint a fresh AES-256 data key for a specific (secret, field) pair. The
|
|
600
674
|
* encryption context is rebuilt server-side from `auth.tenantId` + the body
|
|
@@ -990,6 +1064,104 @@ var AgentApiClient = class {
|
|
|
990
1064
|
body: JSON.stringify(entry)
|
|
991
1065
|
}).catch(() => {});
|
|
992
1066
|
}
|
|
1067
|
+
async requestBrowserTakeover(args) {
|
|
1068
|
+
return this.request("/agent/remote/takeover", {
|
|
1069
|
+
method: "POST",
|
|
1070
|
+
body: JSON.stringify(args)
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
async getRemoteSession(sessionId) {
|
|
1074
|
+
return this.request(`/agent/remote/sessions/${encodeURIComponent(sessionId)}`);
|
|
1075
|
+
}
|
|
1076
|
+
async completeRemoteSession(sessionId) {
|
|
1077
|
+
return this.request(`/agent/remote/sessions/${encodeURIComponent(sessionId)}/complete`, {
|
|
1078
|
+
method: "POST",
|
|
1079
|
+
body: JSON.stringify({})
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Issue a request that returns the raw `Response` (no JSON parsing, no
|
|
1084
|
+
* forced Content-Type). The caller sets `Content-Type`/`Accept` on `headers`
|
|
1085
|
+
* and reads the body itself (`arrayBuffer()` / `json()`).
|
|
1086
|
+
*
|
|
1087
|
+
* A single retry fires only on the same transient statuses `request()`
|
|
1088
|
+
* retries (authorizer-timeout 500 + LB 502/503/504) and transient network
|
|
1089
|
+
* errors — before the route handler runs — so re-issuing a POST does not
|
|
1090
|
+
* risk a duplicate side effect. Voice TTS/STT are effectively idempotent
|
|
1091
|
+
* (re-synthesize / re-transcribe) and meter server-side keyed on the
|
|
1092
|
+
* gateway requestId, so a retried transcription doesn't double-bill.
|
|
1093
|
+
*/
|
|
1094
|
+
async rawFetch(path, init) {
|
|
1095
|
+
const url = `${this.apiUrl}${path}`;
|
|
1096
|
+
init.headers.set("Authorization", `Bearer ${this.apiKey}`);
|
|
1097
|
+
let lastError;
|
|
1098
|
+
for (let attempt = 1; attempt <= 2; attempt++) try {
|
|
1099
|
+
const res = await fetch(url, {
|
|
1100
|
+
method: init.method,
|
|
1101
|
+
headers: init.headers,
|
|
1102
|
+
body: init.body,
|
|
1103
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
1104
|
+
});
|
|
1105
|
+
if (!res.ok) {
|
|
1106
|
+
await res.text();
|
|
1107
|
+
const error = /* @__PURE__ */ new Error(`Agent API request failed (${String(res.status)})`);
|
|
1108
|
+
if (attempt === 1 && RETRYABLE_STATUS.has(res.status)) {
|
|
1109
|
+
lastError = error;
|
|
1110
|
+
await sleep(RETRY_DELAY_MS);
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1113
|
+
throw error;
|
|
1114
|
+
}
|
|
1115
|
+
return res;
|
|
1116
|
+
} catch (err) {
|
|
1117
|
+
if (attempt === 1 && isRetryableNetworkError(err)) {
|
|
1118
|
+
lastError = err;
|
|
1119
|
+
await sleep(RETRY_DELAY_MS);
|
|
1120
|
+
continue;
|
|
1121
|
+
}
|
|
1122
|
+
throw err;
|
|
1123
|
+
}
|
|
1124
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Text-to-speech. Returns raw PCM audio bytes plus their framing — the
|
|
1128
|
+
* voice service defaults to 24 kHz / mono / 16-bit. Wrap in a WAV container
|
|
1129
|
+
* to produce a playable file. Metered per character against the tenant
|
|
1130
|
+
* credit pool server-side; TTS completes regardless of metering outcome.
|
|
1131
|
+
*/
|
|
1132
|
+
async tts(args) {
|
|
1133
|
+
const headers = new Headers();
|
|
1134
|
+
headers.set("Content-Type", "application/json");
|
|
1135
|
+
headers.set("Accept", "audio/pcm");
|
|
1136
|
+
const res = await this.rawFetch("/voice/tts", {
|
|
1137
|
+
method: "POST",
|
|
1138
|
+
headers,
|
|
1139
|
+
body: JSON.stringify(args)
|
|
1140
|
+
});
|
|
1141
|
+
return {
|
|
1142
|
+
audio: Buffer.from(await res.arrayBuffer()),
|
|
1143
|
+
sampleRate: parseInt(res.headers.get("x-sample-rate") ?? "24000", 10),
|
|
1144
|
+
channels: parseInt(res.headers.get("x-channels") ?? "1", 10),
|
|
1145
|
+
bitDepth: parseInt(res.headers.get("x-bit-depth") ?? "16", 10)
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Speech-to-text. Accepts raw linear16 (16-bit LE) mono PCM — NOT a WAV or
|
|
1150
|
+
* other container (the endpoint transcribes with a fixed linear16 encoding,
|
|
1151
|
+
* so a container header would be transcribed as noise). Strip any WAV header
|
|
1152
|
+
* and pass `sampleRate` from it before calling. Metered by transcribed
|
|
1153
|
+
* duration against the tenant credit pool server-side.
|
|
1154
|
+
*/
|
|
1155
|
+
async stt(args) {
|
|
1156
|
+
const headers = new Headers();
|
|
1157
|
+
headers.set("Content-Type", "application/octet-stream");
|
|
1158
|
+
headers.set("x-sample-rate", String(args.sampleRate));
|
|
1159
|
+
return (await (await this.rawFetch("/voice/stt", {
|
|
1160
|
+
method: "POST",
|
|
1161
|
+
headers,
|
|
1162
|
+
body: args.audio
|
|
1163
|
+
})).json()).data;
|
|
1164
|
+
}
|
|
993
1165
|
};
|
|
994
1166
|
//#endregion
|
|
995
1167
|
export { AgentApiClient };
|