@sonzai-labs/agents 1.0.2 → 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 +250 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +371 -1
- package/dist/index.d.ts +371 -1
- package/dist/index.js +250 -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,59 @@ 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
|
+
}
|
|
1523
|
+
// -- Process (full pipeline) --
|
|
1524
|
+
/**
|
|
1525
|
+
* Run the full Context Engine pipeline on conversation messages without
|
|
1526
|
+
* generating a chat response. Extracts side effects via LLM, processes
|
|
1527
|
+
* behavioral updates (mood, personality, habits, interests, relationships),
|
|
1528
|
+
* stores memories, and runs session-end analysis.
|
|
1529
|
+
*/
|
|
1530
|
+
async process(agentId, options) {
|
|
1531
|
+
requireNonEmpty(agentId, "agentId");
|
|
1532
|
+
requireNonEmpty(options.userId, "options.userId");
|
|
1533
|
+
const body = {
|
|
1534
|
+
userId: options.userId,
|
|
1535
|
+
messages: options.messages
|
|
1536
|
+
};
|
|
1537
|
+
if (options.sessionId) body.sessionId = options.sessionId;
|
|
1538
|
+
if (options.instanceId) body.instanceId = options.instanceId;
|
|
1539
|
+
if (options.provider) body.provider = options.provider;
|
|
1540
|
+
if (options.model) body.model = options.model;
|
|
1541
|
+
if (options.includeExtractions) body.include_extractions = options.includeExtractions;
|
|
1542
|
+
return this.http.post(`/api/v1/agents/${agentId}/process`, body);
|
|
1543
|
+
}
|
|
1544
|
+
/** Get available LLM providers and models for the /process endpoint. */
|
|
1545
|
+
async getModels(agentId) {
|
|
1546
|
+
return this.http.get(`/api/v1/agents/${agentId}/models`);
|
|
1547
|
+
}
|
|
1548
|
+
// -- Context (single-call enriched context) --
|
|
1549
|
+
/**
|
|
1550
|
+
* Get the full enriched agent context in a single call.
|
|
1551
|
+
* Returns all 7 layers (personality, mood, memory, relationships, goals, etc.)
|
|
1552
|
+
* This replaces multiple individual API calls with one round-trip.
|
|
1553
|
+
*/
|
|
1554
|
+
async getContext(agentId, options) {
|
|
1555
|
+
requireNonEmpty(agentId, "agentId");
|
|
1556
|
+
requireNonEmpty(options.userId, "options.userId");
|
|
1557
|
+
const params = { userId: options.userId };
|
|
1558
|
+
if (options.sessionId) params.sessionId = options.sessionId;
|
|
1559
|
+
if (options.instanceId) params.instanceId = options.instanceId;
|
|
1560
|
+
if (options.query) params.query = options.query;
|
|
1561
|
+
if (options.language) params.language = options.language;
|
|
1562
|
+
if (options.timezone) params.timezone = options.timezone;
|
|
1563
|
+
return this.http.get(
|
|
1564
|
+
`/api/v1/agents/${agentId}/context`,
|
|
1565
|
+
params
|
|
1566
|
+
);
|
|
1567
|
+
}
|
|
1467
1568
|
// -- Consolidation --
|
|
1468
1569
|
/** Trigger memory consolidation for an agent. */
|
|
1469
1570
|
async consolidate(agentId, options) {
|
|
@@ -1484,6 +1585,17 @@ var Agents = class {
|
|
|
1484
1585
|
if (options.instanceId) params.instance_id = options.instanceId;
|
|
1485
1586
|
return this.http.get(`/api/v1/agents/${agentId}/timemachine`, params);
|
|
1486
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
|
+
}
|
|
1487
1599
|
buildChatBody(options) {
|
|
1488
1600
|
const body = { messages: options.messages };
|
|
1489
1601
|
if (options.userId) body.user_id = options.userId;
|
|
@@ -1510,6 +1622,30 @@ var Agents = class {
|
|
|
1510
1622
|
}
|
|
1511
1623
|
};
|
|
1512
1624
|
|
|
1625
|
+
// src/resources/custom-llm.ts
|
|
1626
|
+
var CustomLLM = class {
|
|
1627
|
+
constructor(http) {
|
|
1628
|
+
this.http = http;
|
|
1629
|
+
}
|
|
1630
|
+
/** Get the custom LLM config for a project. */
|
|
1631
|
+
async get(projectId) {
|
|
1632
|
+
return this.http.get(
|
|
1633
|
+
`/api/v1/projects/${projectId}/custom-llm`
|
|
1634
|
+
);
|
|
1635
|
+
}
|
|
1636
|
+
/** Set or update the custom LLM config. */
|
|
1637
|
+
async set(projectId, options) {
|
|
1638
|
+
return this.http.put(
|
|
1639
|
+
`/api/v1/projects/${projectId}/custom-llm`,
|
|
1640
|
+
options
|
|
1641
|
+
);
|
|
1642
|
+
}
|
|
1643
|
+
/** Delete the custom LLM config. */
|
|
1644
|
+
async delete(projectId) {
|
|
1645
|
+
await this.http.delete(`/api/v1/projects/${projectId}/custom-llm`);
|
|
1646
|
+
}
|
|
1647
|
+
};
|
|
1648
|
+
|
|
1513
1649
|
// src/resources/eval-runs.ts
|
|
1514
1650
|
var EvalRuns = class {
|
|
1515
1651
|
constructor(http) {
|
|
@@ -1814,6 +1950,72 @@ var Knowledge = class {
|
|
|
1814
1950
|
}
|
|
1815
1951
|
};
|
|
1816
1952
|
|
|
1953
|
+
// src/resources/project-config.ts
|
|
1954
|
+
var ProjectConfig = class {
|
|
1955
|
+
constructor(http) {
|
|
1956
|
+
this.http = http;
|
|
1957
|
+
}
|
|
1958
|
+
/** List all config entries for a project. */
|
|
1959
|
+
async list(projectId) {
|
|
1960
|
+
return this.http.get(
|
|
1961
|
+
`/api/v1/projects/${projectId}/config`
|
|
1962
|
+
);
|
|
1963
|
+
}
|
|
1964
|
+
/** Get a config value by key. Returns the raw JSON value. */
|
|
1965
|
+
async get(projectId, key) {
|
|
1966
|
+
return this.http.get(
|
|
1967
|
+
`/api/v1/projects/${projectId}/config/${key}`
|
|
1968
|
+
);
|
|
1969
|
+
}
|
|
1970
|
+
/** Set a config value. Body must be valid JSON. */
|
|
1971
|
+
async set(projectId, key, value) {
|
|
1972
|
+
return this.http.put(
|
|
1973
|
+
`/api/v1/projects/${projectId}/config/${key}`,
|
|
1974
|
+
value
|
|
1975
|
+
);
|
|
1976
|
+
}
|
|
1977
|
+
/** Delete a config entry. */
|
|
1978
|
+
async delete(projectId, key) {
|
|
1979
|
+
await this.http.delete(`/api/v1/projects/${projectId}/config/${key}`);
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
|
|
1983
|
+
// src/resources/project-notifications.ts
|
|
1984
|
+
var ProjectNotifications = class {
|
|
1985
|
+
constructor(http) {
|
|
1986
|
+
this.http = http;
|
|
1987
|
+
}
|
|
1988
|
+
/** List pending notifications for a project. */
|
|
1989
|
+
async list(projectId, options = {}) {
|
|
1990
|
+
const params = {};
|
|
1991
|
+
if (options.agentId) params.agent_id = options.agentId;
|
|
1992
|
+
if (options.eventType) params.event_type = options.eventType;
|
|
1993
|
+
if (options.limit) params.limit = String(options.limit);
|
|
1994
|
+
return this.http.get(
|
|
1995
|
+
`/api/v1/projects/${projectId}/notifications`,
|
|
1996
|
+
params
|
|
1997
|
+
);
|
|
1998
|
+
}
|
|
1999
|
+
/** Acknowledge specific notifications by ID. */
|
|
2000
|
+
async acknowledge(projectId, options) {
|
|
2001
|
+
return this.http.post(
|
|
2002
|
+
`/api/v1/projects/${projectId}/notifications/acknowledge`,
|
|
2003
|
+
{ notification_ids: options.notificationIds }
|
|
2004
|
+
);
|
|
2005
|
+
}
|
|
2006
|
+
/** Acknowledge all pending notifications for a project. */
|
|
2007
|
+
async acknowledgeAll(projectId, options = {}) {
|
|
2008
|
+
const params = {};
|
|
2009
|
+
if (options.agentId) params.agent_id = options.agentId;
|
|
2010
|
+
if (options.eventType) params.event_type = options.eventType;
|
|
2011
|
+
return this.http.post(
|
|
2012
|
+
`/api/v1/projects/${projectId}/notifications/acknowledge-all`,
|
|
2013
|
+
{},
|
|
2014
|
+
params
|
|
2015
|
+
);
|
|
2016
|
+
}
|
|
2017
|
+
};
|
|
2018
|
+
|
|
1817
2019
|
// src/resources/webhooks.ts
|
|
1818
2020
|
var Webhooks = class {
|
|
1819
2021
|
constructor(http) {
|
|
@@ -1850,6 +2052,42 @@ var Webhooks = class {
|
|
|
1850
2052
|
`/api/v1/webhooks/${eventType}/rotate-secret`
|
|
1851
2053
|
);
|
|
1852
2054
|
}
|
|
2055
|
+
// -- Project-scoped webhooks --
|
|
2056
|
+
/** Register (or update) a webhook for a specific project and event type. */
|
|
2057
|
+
async registerForProject(projectId, eventType, options) {
|
|
2058
|
+
const body = {
|
|
2059
|
+
webhook_url: options.webhookUrl
|
|
2060
|
+
};
|
|
2061
|
+
if (options.authHeader) body.auth_header = options.authHeader;
|
|
2062
|
+
return this.http.put(
|
|
2063
|
+
`/api/v1/projects/${projectId}/webhooks/${eventType}`,
|
|
2064
|
+
body
|
|
2065
|
+
);
|
|
2066
|
+
}
|
|
2067
|
+
/** List all webhooks for a project. */
|
|
2068
|
+
async listForProject(projectId) {
|
|
2069
|
+
return this.http.get(
|
|
2070
|
+
`/api/v1/projects/${projectId}/webhooks`
|
|
2071
|
+
);
|
|
2072
|
+
}
|
|
2073
|
+
/** Delete a webhook for a project event type. */
|
|
2074
|
+
async deleteForProject(projectId, eventType) {
|
|
2075
|
+
await this.http.delete(
|
|
2076
|
+
`/api/v1/projects/${projectId}/webhooks/${eventType}`
|
|
2077
|
+
);
|
|
2078
|
+
}
|
|
2079
|
+
/** List delivery attempts for a project webhook event type. */
|
|
2080
|
+
async listDeliveryAttemptsForProject(projectId, eventType) {
|
|
2081
|
+
return this.http.get(
|
|
2082
|
+
`/api/v1/projects/${projectId}/webhooks/${eventType}/attempts`
|
|
2083
|
+
);
|
|
2084
|
+
}
|
|
2085
|
+
/** Rotate the signing secret for a project webhook event type. */
|
|
2086
|
+
async rotateSecretForProject(projectId, eventType) {
|
|
2087
|
+
return this.http.post(
|
|
2088
|
+
`/api/v1/projects/${projectId}/webhooks/${eventType}/rotate-secret`
|
|
2089
|
+
);
|
|
2090
|
+
}
|
|
1853
2091
|
};
|
|
1854
2092
|
|
|
1855
2093
|
// src/client.ts
|
|
@@ -1896,6 +2134,12 @@ var Sonzai = class {
|
|
|
1896
2134
|
evalRuns;
|
|
1897
2135
|
voices;
|
|
1898
2136
|
webhooks;
|
|
2137
|
+
/** Project-scoped configuration (key-value store). */
|
|
2138
|
+
projectConfig;
|
|
2139
|
+
/** Project-scoped custom LLM provider configuration. */
|
|
2140
|
+
customLLM;
|
|
2141
|
+
/** Project-scoped notification polling for game backends. */
|
|
2142
|
+
projectNotifications;
|
|
1899
2143
|
http;
|
|
1900
2144
|
constructor(config) {
|
|
1901
2145
|
const apiKey = resolveApiKey(config);
|
|
@@ -1912,6 +2156,9 @@ var Sonzai = class {
|
|
|
1912
2156
|
this.evalRuns = new EvalRuns(this.http);
|
|
1913
2157
|
this.voices = new Voices(this.http);
|
|
1914
2158
|
this.webhooks = new Webhooks(this.http);
|
|
2159
|
+
this.projectConfig = new ProjectConfig(this.http);
|
|
2160
|
+
this.customLLM = new CustomLLM(this.http);
|
|
2161
|
+
this.projectNotifications = new ProjectNotifications(this.http);
|
|
1915
2162
|
}
|
|
1916
2163
|
};
|
|
1917
2164
|
|