@sonzai-labs/agents 1.0.3 → 1.0.6
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 +71 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +175 -1
- package/dist/index.d.ts +175 -1
- package/dist/index.js +71 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -71,7 +71,7 @@ var HTTPClient = class {
|
|
|
71
71
|
this.headers = {
|
|
72
72
|
Authorization: `Bearer ${options.apiKey}`,
|
|
73
73
|
"Content-Type": "application/json",
|
|
74
|
-
"User-Agent": "sonzai-typescript/1.
|
|
74
|
+
"User-Agent": "sonzai-typescript/1.0.3"
|
|
75
75
|
};
|
|
76
76
|
this.timeout = options.timeout;
|
|
77
77
|
this.maxRetries = options.maxRetries;
|
|
@@ -115,8 +115,9 @@ var HTTPClient = class {
|
|
|
115
115
|
throw new InternalServerError("Max retries exceeded");
|
|
116
116
|
}
|
|
117
117
|
async backoff(attempt) {
|
|
118
|
-
const
|
|
119
|
-
|
|
118
|
+
const base = Math.min(100 * 2 ** attempt, 5e3);
|
|
119
|
+
const jitter = Math.random() * base;
|
|
120
|
+
await new Promise((resolve) => setTimeout(resolve, base + jitter));
|
|
120
121
|
}
|
|
121
122
|
isNetworkError(error) {
|
|
122
123
|
if (error instanceof SonzaiError) return false;
|
|
@@ -886,6 +887,53 @@ var Voice = class {
|
|
|
886
887
|
async stream(token) {
|
|
887
888
|
return VoiceStreamInstance.connect(token);
|
|
888
889
|
}
|
|
890
|
+
/**
|
|
891
|
+
* Convert text to speech audio.
|
|
892
|
+
*
|
|
893
|
+
* @example
|
|
894
|
+
* ```ts
|
|
895
|
+
* const result = await client.agents.voice.tts(agentId, {
|
|
896
|
+
* text: "Hello, how are you?",
|
|
897
|
+
* voiceName: "Kore",
|
|
898
|
+
* outputFormat: "wav",
|
|
899
|
+
* });
|
|
900
|
+
* // result.audio is base64-encoded WAV
|
|
901
|
+
* ```
|
|
902
|
+
*/
|
|
903
|
+
async tts(agentId, options) {
|
|
904
|
+
const body = { text: options.text };
|
|
905
|
+
if (options.voiceName) body.voiceName = options.voiceName;
|
|
906
|
+
if (options.language) body.language = options.language;
|
|
907
|
+
if (options.outputFormat) body.outputFormat = options.outputFormat;
|
|
908
|
+
return this.http.post(
|
|
909
|
+
`/api/v1/agents/${agentId}/voice/tts`,
|
|
910
|
+
body
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Transcribe audio to text.
|
|
915
|
+
*
|
|
916
|
+
* @example
|
|
917
|
+
* ```ts
|
|
918
|
+
* const result = await client.agents.voice.stt(agentId, {
|
|
919
|
+
* audio: base64Audio,
|
|
920
|
+
* audioFormat: "audio/wav",
|
|
921
|
+
* language: "en-US",
|
|
922
|
+
* });
|
|
923
|
+
* console.log(result.transcript);
|
|
924
|
+
* ```
|
|
925
|
+
*/
|
|
926
|
+
async stt(agentId, options) {
|
|
927
|
+
const body = {
|
|
928
|
+
audio: options.audio,
|
|
929
|
+
audioFormat: options.audioFormat
|
|
930
|
+
};
|
|
931
|
+
if (options.language) body.language = options.language;
|
|
932
|
+
return this.http.post(
|
|
933
|
+
`/api/v1/agents/${agentId}/voice/stt`,
|
|
934
|
+
body
|
|
935
|
+
);
|
|
936
|
+
}
|
|
889
937
|
};
|
|
890
938
|
var VoiceStreamInstance = class _VoiceStreamInstance {
|
|
891
939
|
ws;
|
|
@@ -1464,6 +1512,14 @@ var Agents = class {
|
|
|
1464
1512
|
async deleteCustomTool(agentId, toolName) {
|
|
1465
1513
|
return this.http.delete(`/api/v1/agents/${agentId}/tools/${toolName}`);
|
|
1466
1514
|
}
|
|
1515
|
+
// -- Avatar Generation --
|
|
1516
|
+
/** Trigger avatar generation for an agent. */
|
|
1517
|
+
async generateAvatar(agentId, options) {
|
|
1518
|
+
return this.http.post(
|
|
1519
|
+
`/api/v1/agents/${agentId}/avatar/generate`,
|
|
1520
|
+
options ?? {}
|
|
1521
|
+
);
|
|
1522
|
+
}
|
|
1467
1523
|
// -- Process (full pipeline) --
|
|
1468
1524
|
/**
|
|
1469
1525
|
* Run the full Context Engine pipeline on conversation messages without
|
|
@@ -1482,6 +1538,7 @@ var Agents = class {
|
|
|
1482
1538
|
if (options.instanceId) body.instanceId = options.instanceId;
|
|
1483
1539
|
if (options.provider) body.provider = options.provider;
|
|
1484
1540
|
if (options.model) body.model = options.model;
|
|
1541
|
+
if (options.includeExtractions) body.include_extractions = options.includeExtractions;
|
|
1485
1542
|
return this.http.post(`/api/v1/agents/${agentId}/process`, body);
|
|
1486
1543
|
}
|
|
1487
1544
|
/** Get available LLM providers and models for the /process endpoint. */
|
|
@@ -1528,6 +1585,17 @@ var Agents = class {
|
|
|
1528
1585
|
if (options.instanceId) params.instance_id = options.instanceId;
|
|
1529
1586
|
return this.http.get(`/api/v1/agents/${agentId}/timemachine`, params);
|
|
1530
1587
|
}
|
|
1588
|
+
// -- Knowledge Search (tool endpoint) --
|
|
1589
|
+
/** Search the knowledge base for an agent. */
|
|
1590
|
+
async knowledgeSearch(agentId, options) {
|
|
1591
|
+
requireNonEmpty(agentId, "agentId");
|
|
1592
|
+
const body = { query: options.query };
|
|
1593
|
+
if (options.limit != null) body.limit = options.limit;
|
|
1594
|
+
return this.http.post(
|
|
1595
|
+
`/api/v1/agents/${agentId}/tools/knowledge-search`,
|
|
1596
|
+
body
|
|
1597
|
+
);
|
|
1598
|
+
}
|
|
1531
1599
|
buildChatBody(options) {
|
|
1532
1600
|
const body = { messages: options.messages };
|
|
1533
1601
|
if (options.userId) body.user_id = options.userId;
|