@dakera-ai/dakera 0.8.6 → 0.9.2
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.d.mts +380 -1
- package/dist/index.d.ts +380 -1
- package/dist/index.js +247 -0
- package/dist/index.mjs +247 -0
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1096,6 +1096,167 @@ var DakeraClient = class {
|
|
|
1096
1096
|
return this.request("POST", `/v1/agents/${agentId2}/memories/feedback`, request);
|
|
1097
1097
|
}
|
|
1098
1098
|
// ===========================================================================
|
|
1099
|
+
// Memory Feedback Loop — INT-1
|
|
1100
|
+
// ===========================================================================
|
|
1101
|
+
/**
|
|
1102
|
+
* Submit upvote/downvote/flag feedback on a memory (INT-1).
|
|
1103
|
+
*
|
|
1104
|
+
* - `upvote`: boosts importance ×1.15 (capped at 1.0).
|
|
1105
|
+
* - `downvote`: penalises importance ×0.85 (floor 0.0).
|
|
1106
|
+
* - `flag`: marks as irrelevant — accelerates decay on next cycle.
|
|
1107
|
+
*
|
|
1108
|
+
* @param memoryId The memory to give feedback on.
|
|
1109
|
+
* @param agentId The agent that owns the memory.
|
|
1110
|
+
* @param signal Feedback signal.
|
|
1111
|
+
*/
|
|
1112
|
+
async feedbackMemory(memoryId2, agentId2, signal) {
|
|
1113
|
+
return this.request("POST", `/v1/memories/${memoryId2}/feedback`, { agent_id: agentId2, signal });
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Get the full feedback history for a memory (INT-1).
|
|
1117
|
+
*
|
|
1118
|
+
* @param memoryId The memory whose feedback history to retrieve.
|
|
1119
|
+
*/
|
|
1120
|
+
async getMemoryFeedbackHistory(memoryId2) {
|
|
1121
|
+
return this.request("GET", `/v1/memories/${memoryId2}/feedback`);
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Get aggregate feedback counts and health score for an agent (INT-1).
|
|
1125
|
+
*
|
|
1126
|
+
* @param agentId The agent to summarise feedback for.
|
|
1127
|
+
*/
|
|
1128
|
+
async getAgentFeedbackSummary(agentId2) {
|
|
1129
|
+
return this.request("GET", `/v1/agents/${agentId2}/feedback/summary`);
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Directly override a memory's importance score (INT-1).
|
|
1133
|
+
*
|
|
1134
|
+
* @param memoryId The memory to update.
|
|
1135
|
+
* @param agentId The agent that owns the memory.
|
|
1136
|
+
* @param importance New importance value (0.0–1.0).
|
|
1137
|
+
*/
|
|
1138
|
+
async patchMemoryImportance(memoryId2, agentId2, importance) {
|
|
1139
|
+
return this.request("PATCH", `/v1/memories/${memoryId2}/importance`, { agent_id: agentId2, importance });
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Get overall feedback health score for an agent (INT-1).
|
|
1143
|
+
*
|
|
1144
|
+
* The health score is the mean importance of all non-expired memories (0.0–1.0).
|
|
1145
|
+
* A higher score indicates a healthier, more relevant memory store.
|
|
1146
|
+
*
|
|
1147
|
+
* @param agentId The agent to get health score for.
|
|
1148
|
+
*/
|
|
1149
|
+
async getFeedbackHealth(agentId2) {
|
|
1150
|
+
const params = new URLSearchParams({ agent_id: agentId2 });
|
|
1151
|
+
return this.request("GET", `/v1/feedback/health?${params}`);
|
|
1152
|
+
}
|
|
1153
|
+
// ===========================================================================
|
|
1154
|
+
// Memory Knowledge Graph Operations (CE-5 / SDK-9)
|
|
1155
|
+
// ===========================================================================
|
|
1156
|
+
/**
|
|
1157
|
+
* Traverse the knowledge graph from a memory node.
|
|
1158
|
+
*
|
|
1159
|
+
* Requires CE-5 (Memory Knowledge Graph) on the server.
|
|
1160
|
+
*
|
|
1161
|
+
* @param memoryId Root memory ID to start traversal from.
|
|
1162
|
+
* @param options `depth` (default 1, max 3) and optional `types` filter.
|
|
1163
|
+
*
|
|
1164
|
+
* @example
|
|
1165
|
+
* const graph = await client.memories.graph(memoryId, { depth: 2 });
|
|
1166
|
+
* console.log(`${graph.nodes.length} nodes, ${graph.edges.length} edges`);
|
|
1167
|
+
*/
|
|
1168
|
+
async memoryGraph(memoryId2, options) {
|
|
1169
|
+
const params = new URLSearchParams();
|
|
1170
|
+
params.set("depth", String(options?.depth ?? 1));
|
|
1171
|
+
if (options?.types?.length) {
|
|
1172
|
+
params.set("types", options.types.join(","));
|
|
1173
|
+
}
|
|
1174
|
+
return this.request("GET", `/v1/memories/${memoryId2}/graph?${params}`);
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Find the shortest path between two memories in the knowledge graph.
|
|
1178
|
+
*
|
|
1179
|
+
* Requires CE-5 (Memory Knowledge Graph) on the server.
|
|
1180
|
+
*
|
|
1181
|
+
* @param sourceId Starting memory ID.
|
|
1182
|
+
* @param targetId Destination memory ID.
|
|
1183
|
+
*/
|
|
1184
|
+
async memoryPath(sourceId, targetId) {
|
|
1185
|
+
return this.request("GET", `/v1/memories/${sourceId}/path?target=${encodeURIComponent(targetId)}`);
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Create an explicit edge between two memories.
|
|
1189
|
+
*
|
|
1190
|
+
* Requires CE-5 (Memory Knowledge Graph) on the server.
|
|
1191
|
+
*
|
|
1192
|
+
* @param sourceId Source memory ID.
|
|
1193
|
+
* @param targetId Target memory ID.
|
|
1194
|
+
* @param edgeType Edge type — must be `"linked_by"` for explicit links.
|
|
1195
|
+
*/
|
|
1196
|
+
async memoryLink(sourceId, targetId, edgeType = "linked_by") {
|
|
1197
|
+
return this.request("POST", `/v1/memories/${sourceId}/links`, {
|
|
1198
|
+
target_id: targetId,
|
|
1199
|
+
edge_type: edgeType
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Export the full knowledge graph for an agent.
|
|
1204
|
+
*
|
|
1205
|
+
* Requires CE-5 (Memory Knowledge Graph) on the server.
|
|
1206
|
+
*
|
|
1207
|
+
* @param agentId Agent whose graph to export.
|
|
1208
|
+
* @param format Export format — `"json"` (default), `"graphml"`, or `"csv"`.
|
|
1209
|
+
*/
|
|
1210
|
+
async agentGraphExport(agentId2, format = "json") {
|
|
1211
|
+
return this.request("GET", `/v1/agents/${agentId2}/graph/export?format=${format}`);
|
|
1212
|
+
}
|
|
1213
|
+
// =========================================================================
|
|
1214
|
+
// Entity Extraction Operations (CE-4)
|
|
1215
|
+
// =========================================================================
|
|
1216
|
+
/**
|
|
1217
|
+
* Configure entity extraction for a namespace.
|
|
1218
|
+
*
|
|
1219
|
+
* @param namespace - Target namespace
|
|
1220
|
+
* @param config - NER configuration (extract_entities flag + entity_types)
|
|
1221
|
+
* @returns Updated namespace config
|
|
1222
|
+
*
|
|
1223
|
+
* @note Requires CE-4 (GLiNER) on the server.
|
|
1224
|
+
*/
|
|
1225
|
+
async configureNamespaceNer(namespace, config) {
|
|
1226
|
+
return this.request(
|
|
1227
|
+
"PATCH",
|
|
1228
|
+
`/v1/namespaces/${namespace}/config`,
|
|
1229
|
+
config
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* Extract entities from arbitrary text without storing a memory.
|
|
1234
|
+
*
|
|
1235
|
+
* @param text - Text to extract entities from
|
|
1236
|
+
* @param entityTypes - Entity types to extract (defaults to server defaults)
|
|
1237
|
+
* @returns EntityExtractionResponse with extracted entities
|
|
1238
|
+
*
|
|
1239
|
+
* @note Requires CE-4 (GLiNER) on the server.
|
|
1240
|
+
*/
|
|
1241
|
+
async extractEntities(text, entityTypes) {
|
|
1242
|
+
const body = { text };
|
|
1243
|
+
if (entityTypes !== void 0) {
|
|
1244
|
+
body["entity_types"] = entityTypes;
|
|
1245
|
+
}
|
|
1246
|
+
return this.request("POST", "/v1/memories/extract", body);
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Get entity tags attached to a stored memory.
|
|
1250
|
+
*
|
|
1251
|
+
* @param memoryId - Memory ID to fetch entities for
|
|
1252
|
+
* @returns MemoryEntitiesResponse with entity list
|
|
1253
|
+
*
|
|
1254
|
+
* @note Requires CE-4 (GLiNER) on the server.
|
|
1255
|
+
*/
|
|
1256
|
+
async memoryEntities(memoryId2) {
|
|
1257
|
+
return this.request("GET", `/v1/memory/entities/${memoryId2}`);
|
|
1258
|
+
}
|
|
1259
|
+
// ===========================================================================
|
|
1099
1260
|
// Session Operations
|
|
1100
1261
|
// ===========================================================================
|
|
1101
1262
|
/** Start a new session */
|
|
@@ -1434,6 +1595,49 @@ var DakeraClient = class {
|
|
|
1434
1595
|
const url = `${this.baseUrl}/v1/events/stream`;
|
|
1435
1596
|
yield* this._streamSseMemory(url);
|
|
1436
1597
|
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Subscribe to real-time memory lifecycle events for a specific agent.
|
|
1600
|
+
*
|
|
1601
|
+
* Wraps `GET /v1/events/stream`, filtering events by `agentId` and
|
|
1602
|
+
* optional `tags`. Reconnects automatically on connection drop when
|
|
1603
|
+
* `reconnect` is `true`.
|
|
1604
|
+
*
|
|
1605
|
+
* Requires a Read-scoped API key.
|
|
1606
|
+
*
|
|
1607
|
+
* @param agentId - Agent whose events to receive.
|
|
1608
|
+
* @param options.tags - Optional tag filter: only events whose tags overlap
|
|
1609
|
+
* this array are yielded.
|
|
1610
|
+
* @param options.reconnect - Auto-reconnect on connection drop. Default `true`.
|
|
1611
|
+
* @param options.reconnectDelay - Milliseconds to wait between reconnection
|
|
1612
|
+
* attempts. Default `1000`.
|
|
1613
|
+
*
|
|
1614
|
+
* @example
|
|
1615
|
+
* ```ts
|
|
1616
|
+
* for await (const event of client.subscribeAgentMemories('my-bot', { tags: ['important'] })) {
|
|
1617
|
+
* console.log(event.event_type, event.memory_id);
|
|
1618
|
+
* }
|
|
1619
|
+
* ```
|
|
1620
|
+
*/
|
|
1621
|
+
async *subscribeAgentMemories(agentId2, options = {}) {
|
|
1622
|
+
const { tags, reconnect = true, reconnectDelay = 1e3 } = options;
|
|
1623
|
+
while (true) {
|
|
1624
|
+
try {
|
|
1625
|
+
for await (const event of this.streamMemoryEvents()) {
|
|
1626
|
+
if (event.event_type === "connected") continue;
|
|
1627
|
+
if (event.agent_id !== agentId2) continue;
|
|
1628
|
+
if (tags && tags.length > 0) {
|
|
1629
|
+
const eventTags = event.tags ?? [];
|
|
1630
|
+
if (!tags.some((t) => eventTags.includes(t))) continue;
|
|
1631
|
+
}
|
|
1632
|
+
yield event;
|
|
1633
|
+
}
|
|
1634
|
+
if (!reconnect) return;
|
|
1635
|
+
} catch (err) {
|
|
1636
|
+
if (!reconnect) throw err;
|
|
1637
|
+
}
|
|
1638
|
+
await new Promise((r) => setTimeout(r, reconnectDelay));
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1437
1641
|
/**
|
|
1438
1642
|
* Return a URL with `?api_key=<key>` appended for use with browser-native
|
|
1439
1643
|
* `EventSource`, which cannot send custom request headers.
|
|
@@ -1561,6 +1765,49 @@ var DakeraClient = class {
|
|
|
1561
1765
|
return null;
|
|
1562
1766
|
}
|
|
1563
1767
|
}
|
|
1768
|
+
// ===========================================================================
|
|
1769
|
+
// Namespace API Keys — SEC-1
|
|
1770
|
+
// ===========================================================================
|
|
1771
|
+
/**
|
|
1772
|
+
* Create a namespace-scoped API key (SEC-1).
|
|
1773
|
+
*
|
|
1774
|
+
* The `key` field in the response is shown **only once** — store it securely.
|
|
1775
|
+
*
|
|
1776
|
+
* @param namespace The namespace to scope this key to.
|
|
1777
|
+
* @param name Human-readable label for the key.
|
|
1778
|
+
* @param expiresInDays Optional expiry in days from now.
|
|
1779
|
+
*/
|
|
1780
|
+
async createNamespaceKey(namespace, name, expiresInDays) {
|
|
1781
|
+
const body = { name };
|
|
1782
|
+
if (expiresInDays !== void 0) body.expires_in_days = expiresInDays;
|
|
1783
|
+
return this.request("POST", `/v1/namespaces/${namespace}/keys`, body);
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* List all API keys scoped to a namespace (SEC-1).
|
|
1787
|
+
*
|
|
1788
|
+
* @param namespace The namespace whose keys to list.
|
|
1789
|
+
*/
|
|
1790
|
+
async listNamespaceKeys(namespace) {
|
|
1791
|
+
return this.request("GET", `/v1/namespaces/${namespace}/keys`);
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Revoke a namespace-scoped API key (SEC-1).
|
|
1795
|
+
*
|
|
1796
|
+
* @param namespace The namespace the key belongs to.
|
|
1797
|
+
* @param keyId The key to revoke.
|
|
1798
|
+
*/
|
|
1799
|
+
async deleteNamespaceKey(namespace, keyId) {
|
|
1800
|
+
return this.request("DELETE", `/v1/namespaces/${namespace}/keys/${keyId}`);
|
|
1801
|
+
}
|
|
1802
|
+
/**
|
|
1803
|
+
* Get usage statistics for a namespace-scoped API key (SEC-1).
|
|
1804
|
+
*
|
|
1805
|
+
* @param namespace The namespace the key belongs to.
|
|
1806
|
+
* @param keyId The key whose usage to retrieve.
|
|
1807
|
+
*/
|
|
1808
|
+
async getNamespaceKeyUsage(namespace, keyId) {
|
|
1809
|
+
return this.request("GET", `/v1/namespaces/${namespace}/keys/${keyId}/usage`);
|
|
1810
|
+
}
|
|
1564
1811
|
};
|
|
1565
1812
|
|
|
1566
1813
|
// src/types.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dakera-ai/dakera",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "TypeScript/JavaScript SDK for Dakera AI memory platform",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/node": "^20.10.0",
|
|
54
|
-
"eslint": "^
|
|
54
|
+
"eslint": "^10.1.0",
|
|
55
55
|
"tsup": "^8.0.1",
|
|
56
56
|
"typescript": "^5.3.0",
|
|
57
57
|
"vitest": "^4.1.0"
|