@maximem/synap-js-sdk 0.5.14 → 0.5.16
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 +41 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1119,7 +1119,7 @@ function buildForgetBody(options) {
|
|
|
1119
1119
|
mode
|
|
1120
1120
|
};
|
|
1121
1121
|
}
|
|
1122
|
-
var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "error", "cancelled"]);
|
|
1122
|
+
var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "partial_success", "error", "cancelled"]);
|
|
1123
1123
|
function createMemoriesInterface(transport, onForgotten) {
|
|
1124
1124
|
return {
|
|
1125
1125
|
async create(options) {
|
|
@@ -1154,7 +1154,9 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1154
1154
|
}
|
|
1155
1155
|
const form = new FormData();
|
|
1156
1156
|
form.set("user_id", userId);
|
|
1157
|
-
|
|
1157
|
+
if (typeof customerId === "string" && customerId !== "") {
|
|
1158
|
+
form.set("customer_id", customerId);
|
|
1159
|
+
}
|
|
1158
1160
|
form.set("relationship_type", _nullishCoalesce(_nullishCoalesce(options.relationship_type, () => ( options.relationshipType)), () => ( "b2c")));
|
|
1159
1161
|
form.set("mode", String(_nullishCoalesce(options.mode, () => ( DEFAULT_INGEST_MODE))));
|
|
1160
1162
|
const documentType = _nullishCoalesce(options.document_type, () => ( options.documentType));
|
|
@@ -1162,6 +1164,9 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1162
1164
|
if (options.metadata !== void 0 && Object.keys(options.metadata).length > 0) {
|
|
1163
1165
|
form.set("metadata", JSON.stringify(options.metadata));
|
|
1164
1166
|
}
|
|
1167
|
+
if (options.scope && Object.keys(options.scope).length > 0) {
|
|
1168
|
+
form.set("scope", JSON.stringify(options.scope));
|
|
1169
|
+
}
|
|
1165
1170
|
if (filePath !== void 0) {
|
|
1166
1171
|
const { readFile } = await Promise.resolve().then(() => _interopRequireWildcard(require("fs/promises")));
|
|
1167
1172
|
const { basename } = await Promise.resolve().then(() => _interopRequireWildcard(require("path")));
|
|
@@ -1371,7 +1376,9 @@ function buildIngestTranscriptBody(options) {
|
|
|
1371
1376
|
if (startedAt !== void 0) body["started_at"] = startedAt;
|
|
1372
1377
|
if (endedAt !== void 0) body["ended_at"] = endedAt;
|
|
1373
1378
|
const scopePath = either2(o2, "scope_path", "scopePath");
|
|
1374
|
-
if (scopePath !== void 0)
|
|
1379
|
+
if (scopePath !== void 0 && scopePath !== null && Object.keys(scopePath).length > 0) {
|
|
1380
|
+
body["scope"] = scopePath;
|
|
1381
|
+
}
|
|
1375
1382
|
return body;
|
|
1376
1383
|
}
|
|
1377
1384
|
function buildCompactBody(options) {
|
|
@@ -1540,8 +1547,17 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1540
1547
|
return result;
|
|
1541
1548
|
},
|
|
1542
1549
|
async ingest_transcript(options) {
|
|
1550
|
+
const o2 = options;
|
|
1551
|
+
await transport.checkCustomerId(
|
|
1552
|
+
_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])),
|
|
1553
|
+
"conversation.ingest_transcript"
|
|
1554
|
+
);
|
|
1543
1555
|
const body = buildIngestTranscriptBody(options);
|
|
1544
|
-
const
|
|
1556
|
+
const raw = await transport.request("conversations_ingest", { body });
|
|
1557
|
+
const result = {
|
|
1558
|
+
...raw,
|
|
1559
|
+
warnings: Array.isArray(_optionalChain([raw, 'optionalAccess', _50 => _50.warnings])) ? raw.warnings.map(String) : []
|
|
1560
|
+
};
|
|
1545
1561
|
onWrite({
|
|
1546
1562
|
userId: body["user_id"],
|
|
1547
1563
|
customerId: body["customer_id"]
|
|
@@ -1584,8 +1600,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1584
1600
|
pathParams: { conversation_id: id },
|
|
1585
1601
|
query: { style }
|
|
1586
1602
|
});
|
|
1587
|
-
const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
1588
|
-
_optionalChain([localShortTerm, 'access',
|
|
1603
|
+
const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _51 => _51["context_for_prompt"]]), () => ( result)), () => ( {}));
|
|
1604
|
+
_optionalChain([localShortTerm, 'access', _52 => _52.reseed, 'optionalCall', _53 => _53(id, response)]);
|
|
1589
1605
|
return withHistory(response);
|
|
1590
1606
|
},
|
|
1591
1607
|
async compact(options) {
|
|
@@ -1778,8 +1794,8 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1778
1794
|
let onConversationState = null;
|
|
1779
1795
|
const internals = {
|
|
1780
1796
|
onCompactionUpdate(conversationId, bundle) {
|
|
1781
|
-
_optionalChain([applyCompaction, 'optionalCall',
|
|
1782
|
-
_optionalChain([dispatchCompaction, 'optionalCall',
|
|
1797
|
+
_optionalChain([applyCompaction, 'optionalCall', _54 => _54(bundle)]);
|
|
1798
|
+
_optionalChain([dispatchCompaction, 'optionalCall', _55 => _55(conversationId, bundle)]);
|
|
1783
1799
|
},
|
|
1784
1800
|
setCompactionApplier(apply) {
|
|
1785
1801
|
applyCompaction = apply;
|
|
@@ -1791,10 +1807,10 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1791
1807
|
onConversationState = handle;
|
|
1792
1808
|
},
|
|
1793
1809
|
sendContextUsed(event) {
|
|
1794
|
-
_optionalChain([client, 'optionalAccess',
|
|
1810
|
+
_optionalChain([client, 'optionalAccess', _56 => _56.sendContextUsed, 'call', _57 => _57(event)]);
|
|
1795
1811
|
},
|
|
1796
1812
|
sendContextAssembled(event) {
|
|
1797
|
-
_optionalChain([client, 'optionalAccess',
|
|
1813
|
+
_optionalChain([client, 'optionalAccess', _58 => _58.sendContextAssembled, 'call', _59 => _59(event)]);
|
|
1798
1814
|
},
|
|
1799
1815
|
setCompactionDispatcher(dispatch) {
|
|
1800
1816
|
dispatchCompaction = dispatch;
|
|
@@ -1825,7 +1841,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1825
1841
|
throw new (0, _chunkUXNVTP4Dcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
|
|
1826
1842
|
}
|
|
1827
1843
|
try {
|
|
1828
|
-
_optionalChain([onListen, 'optionalCall',
|
|
1844
|
+
_optionalChain([onListen, 'optionalCall', _60 => _60()]);
|
|
1829
1845
|
} catch (e10) {
|
|
1830
1846
|
}
|
|
1831
1847
|
const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-5GYUWETN.cjs")));
|
|
@@ -1843,17 +1859,17 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1843
1859
|
internals.onCompactionUpdate(conversationId, bundle);
|
|
1844
1860
|
},
|
|
1845
1861
|
onConversationState: (conversationId, messageCount) => {
|
|
1846
|
-
_optionalChain([onConversationState, 'optionalCall',
|
|
1862
|
+
_optionalChain([onConversationState, 'optionalCall', _61 => _61(conversationId, messageCount)]);
|
|
1847
1863
|
},
|
|
1848
1864
|
onStateChange: (state) => {
|
|
1849
1865
|
if (state !== "connected") openSessions.clear();
|
|
1850
1866
|
if (state === "reconnecting") {
|
|
1851
1867
|
reconnectAttempts += 1;
|
|
1852
|
-
_optionalChain([onReconnect, 'optionalCall',
|
|
1868
|
+
_optionalChain([onReconnect, 'optionalCall', _62 => _62(reconnectAttempts)]);
|
|
1853
1869
|
} else if (state === "disconnected") {
|
|
1854
|
-
const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess',
|
|
1870
|
+
const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _63 => _63.lastError]), () => ( null));
|
|
1855
1871
|
const reason = stopped === null ? "stream disconnected" : `credit_stop:${_nullishCoalesce(stopped.reason, () => ( "unknown"))}`;
|
|
1856
|
-
_optionalChain([onDisconnect, 'optionalCall',
|
|
1872
|
+
_optionalChain([onDisconnect, 'optionalCall', _64 => _64(reason)]);
|
|
1857
1873
|
}
|
|
1858
1874
|
}
|
|
1859
1875
|
});
|
|
@@ -1863,7 +1879,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1863
1879
|
} catch (error) {
|
|
1864
1880
|
if (error instanceof _chunkUXNVTP4Dcjs.SynapError) throw error;
|
|
1865
1881
|
throw new (0, _chunkUXNVTP4Dcjs.SynapError)(
|
|
1866
|
-
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
1882
|
+
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _65 => _65.message]), () => ( String(error)))}`,
|
|
1867
1883
|
{ cause: error }
|
|
1868
1884
|
);
|
|
1869
1885
|
}
|
|
@@ -1909,7 +1925,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1909
1925
|
_nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
|
|
1910
1926
|
);
|
|
1911
1927
|
if (eventType === "user_message" || eventType === "assistant_message") {
|
|
1912
|
-
_optionalChain([onTurn, 'optionalCall',
|
|
1928
|
+
_optionalChain([onTurn, 'optionalCall', _66 => _66({
|
|
1913
1929
|
conversationId,
|
|
1914
1930
|
role: _nullishCoalesce(options.role, () => ( "user")),
|
|
1915
1931
|
content: options.content
|
|
@@ -1955,7 +1971,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1955
1971
|
async record_tool_result(options) {
|
|
1956
1972
|
const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
|
|
1957
1973
|
if (conversationId) {
|
|
1958
|
-
_optionalChain([onToolResult, 'optionalCall',
|
|
1974
|
+
_optionalChain([onToolResult, 'optionalCall', _67 => _67({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
|
|
1959
1975
|
}
|
|
1960
1976
|
await namespace.send_message({
|
|
1961
1977
|
content: "",
|
|
@@ -2007,7 +2023,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
2007
2023
|
}
|
|
2008
2024
|
|
|
2009
2025
|
// src/version.ts
|
|
2010
|
-
var SDK_VERSION = "0.5.
|
|
2026
|
+
var SDK_VERSION = "0.5.16";
|
|
2011
2027
|
|
|
2012
2028
|
// src/registry.ts
|
|
2013
2029
|
var instances = /* @__PURE__ */ new Map();
|
|
@@ -2475,7 +2491,7 @@ var TurnStore = (_class3 = class {
|
|
|
2475
2491
|
}
|
|
2476
2492
|
/** Turns the server also holds: archived tool results are local only. Python: `count`. */
|
|
2477
2493
|
count(conversationId) {
|
|
2478
|
-
return (_nullishCoalesce(_optionalChain([this, 'access',
|
|
2494
|
+
return (_nullishCoalesce(_optionalChain([this, 'access', _68 => _68.#conversations, 'access', _69 => _69.get, 'call', _70 => _70(conversationId), 'optionalAccess', _71 => _71.turns]), () => ( []))).filter((t) => t.role !== "tool").length;
|
|
2479
2495
|
}
|
|
2480
2496
|
sizeBytes() {
|
|
2481
2497
|
let n2 = 0;
|
|
@@ -2654,7 +2670,7 @@ function askedKinds(query) {
|
|
|
2654
2670
|
}
|
|
2655
2671
|
function asksHowItStarted(query) {
|
|
2656
2672
|
const spec = _chunkICUFS3B5cjs.HISTORY_SEARCH.early_query;
|
|
2657
|
-
if (!_optionalChain([spec, 'optionalAccess',
|
|
2673
|
+
if (!_optionalChain([spec, 'optionalAccess', _72 => _72.pattern])) return false;
|
|
2658
2674
|
return new RegExp(spec.pattern, (_nullishCoalesce(spec.flags, () => ( ""))).includes("i") ? "i" : "").test(_nullishCoalesce(query, () => ( "")));
|
|
2659
2675
|
}
|
|
2660
2676
|
async function searchTurns(turns, query, options = {}) {
|
|
@@ -3867,7 +3883,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
3867
3883
|
this.#localEncoder = _nullishCoalesce(_nullishCoalesce(options.history_search_encoder, () => ( options.historySearchEncoder)), () => ( null));
|
|
3868
3884
|
const modelOption = options.history_search_model !== void 0 ? options.history_search_model : options.historySearchModel;
|
|
3869
3885
|
this.#localModelName = modelOption === void 0 ? "auto" : modelOption;
|
|
3870
|
-
if (_optionalChain([this, 'access',
|
|
3886
|
+
if (_optionalChain([this, 'access', _73 => _73.#localEncoder, 'optionalAccess', _74 => _74.model]) === _chunkICUFS3B5cjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
|
|
3871
3887
|
this.#turns = new TurnCounter();
|
|
3872
3888
|
this.conversation = createConversationNamespace(
|
|
3873
3889
|
this.#transport,
|
|
@@ -4363,14 +4379,14 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4363
4379
|
}))
|
|
4364
4380
|
);
|
|
4365
4381
|
const entry = this.#shortTerm.get(conversationId);
|
|
4366
|
-
const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess',
|
|
4382
|
+
const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _75 => _75.serverMessageCount]), () => ( 0))) || 0);
|
|
4367
4383
|
this.#maybeBackfillTurns(conversationId, total);
|
|
4368
4384
|
if (!r["context_block"]) return response;
|
|
4369
4385
|
const turns = store.turns(conversationId);
|
|
4370
4386
|
let q = query;
|
|
4371
4387
|
if (!q) {
|
|
4372
4388
|
const latest = [...recent].reverse().find((m) => m["role"] === "user");
|
|
4373
|
-
q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access',
|
|
4389
|
+
q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access', _76 => _76.reverse, 'call', _77 => _77(), 'access', _78 => _78.find, 'call', _79 => _79((t) => t.role === "user"), 'optionalAccess', _80 => _80.content]), () => ( ""));
|
|
4374
4390
|
}
|
|
4375
4391
|
if (!q) return response;
|
|
4376
4392
|
const exclude = /* @__PURE__ */ new Set();
|
|
@@ -4514,7 +4530,7 @@ function pick3(o2, snake, camel) {
|
|
|
4514
4530
|
function resolveBaseUrl(options) {
|
|
4515
4531
|
const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
|
|
4516
4532
|
if (explicit !== void 0) return explicit;
|
|
4517
|
-
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess',
|
|
4533
|
+
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _81 => _81.trim, 'call', _82 => _82()]);
|
|
4518
4534
|
return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
|
|
4519
4535
|
}
|
|
4520
4536
|
function resolveCredentials(options) {
|