@axiom-lattice/local-stores 5.2.4 → 5.3.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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +26 -0
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +105 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/LocalOpenAuditStore.test.ts +43 -0
- package/src/__tests__/LocalThreadMessageQueueStore.monitor.test.ts +31 -0
- package/src/__tests__/LocalThreadStore.monitor.test.ts +29 -0
- package/src/stores/LocalOpenAuditStore.ts +30 -1
- package/src/stores/LocalThreadMessageQueueStore.ts +3 -2
- package/src/stores/LocalThreadStore.ts +47 -4
package/dist/index.mjs
CHANGED
|
@@ -269,6 +269,10 @@ var MigrationManager = class {
|
|
|
269
269
|
import { SqliteSaver } from "@langchain/langgraph-checkpoint-sqlite";
|
|
270
270
|
|
|
271
271
|
// src/stores/LocalThreadStore.ts
|
|
272
|
+
import {
|
|
273
|
+
classifyThreadMetadata,
|
|
274
|
+
toThreadMonitorRecord
|
|
275
|
+
} from "@axiom-lattice/protocols";
|
|
272
276
|
var STORE_NAME = "lt_threads";
|
|
273
277
|
var DDL = `
|
|
274
278
|
CREATE TABLE IF NOT EXISTS lt_threads (
|
|
@@ -318,6 +322,30 @@ var LocalThreadStore = class {
|
|
|
318
322
|
}
|
|
319
323
|
return threads;
|
|
320
324
|
}
|
|
325
|
+
async listThreadsByTenant(tenantId, query = {}) {
|
|
326
|
+
const limit = Math.min(200, Math.max(1, Math.floor(query.limit ?? 50)));
|
|
327
|
+
const offset = Math.max(0, Math.floor(query.offset ?? 0));
|
|
328
|
+
const createdAfter = query.createdAfter ? Date.parse(query.createdAfter) : void 0;
|
|
329
|
+
const rows2 = this.db.prepare(
|
|
330
|
+
`SELECT * FROM lt_threads WHERE tenant_id = ? ORDER BY created_at DESC, id DESC`
|
|
331
|
+
).all(tenantId);
|
|
332
|
+
const filtered = rows2.map(mapRowToThread).filter((thread) => {
|
|
333
|
+
if (query.assistantId && thread.assistantId !== query.assistantId) {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
if (createdAfter !== void 0 && Number.isFinite(createdAfter) && thread.createdAt.getTime() < createdAfter) {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
if (query.kind && classifyThreadMetadata(thread.metadata) !== query.kind) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
return true;
|
|
343
|
+
});
|
|
344
|
+
return {
|
|
345
|
+
records: filtered.slice(offset, offset + limit).map(toThreadMonitorRecord),
|
|
346
|
+
total: filtered.length
|
|
347
|
+
};
|
|
348
|
+
}
|
|
321
349
|
async getThreadById(tenantId, threadId) {
|
|
322
350
|
const row = this.db.prepare(
|
|
323
351
|
`SELECT * FROM lt_threads WHERE tenant_id = ? AND id = ?`
|
|
@@ -5885,6 +5913,24 @@ var LocalOpenAuditStore = class {
|
|
|
5885
5913
|
this.db = db;
|
|
5886
5914
|
ensureTable(db, DDL27);
|
|
5887
5915
|
}
|
|
5916
|
+
async get(tenantId, id) {
|
|
5917
|
+
const row = this.db.prepare("SELECT * FROM lt_open_audit WHERE tenant_id = ? AND id = ?").get(tenantId, id);
|
|
5918
|
+
if (!row) return null;
|
|
5919
|
+
return {
|
|
5920
|
+
id: row.id,
|
|
5921
|
+
tenantId: row.tenant_id,
|
|
5922
|
+
credentialId: row.credential_id,
|
|
5923
|
+
credentialKind: row.credential_kind,
|
|
5924
|
+
projectId: row.project_id,
|
|
5925
|
+
domain: row.domain,
|
|
5926
|
+
action: row.action,
|
|
5927
|
+
args: row.args ? JSON.parse(row.args) : void 0,
|
|
5928
|
+
status: row.status,
|
|
5929
|
+
errorCode: row.error_code ?? void 0,
|
|
5930
|
+
durationMs: row.duration_ms,
|
|
5931
|
+
createdAt: parseISO(row.created_at)
|
|
5932
|
+
};
|
|
5933
|
+
}
|
|
5888
5934
|
async query(params) {
|
|
5889
5935
|
const clauses = ["tenant_id = ?"];
|
|
5890
5936
|
const values = [params.tenantId];
|
|
@@ -5892,10 +5938,18 @@ var LocalOpenAuditStore = class {
|
|
|
5892
5938
|
clauses.push("credential_id = ?");
|
|
5893
5939
|
values.push(params.credentialId);
|
|
5894
5940
|
}
|
|
5941
|
+
if (params.projectId) {
|
|
5942
|
+
clauses.push("project_id = ?");
|
|
5943
|
+
values.push(params.projectId);
|
|
5944
|
+
}
|
|
5895
5945
|
if (params.domain) {
|
|
5896
5946
|
clauses.push("domain = ?");
|
|
5897
5947
|
values.push(params.domain);
|
|
5898
5948
|
}
|
|
5949
|
+
if (params.action) {
|
|
5950
|
+
clauses.push("action = ?");
|
|
5951
|
+
values.push(params.action);
|
|
5952
|
+
}
|
|
5899
5953
|
if (params.status) {
|
|
5900
5954
|
clauses.push("status = ?");
|
|
5901
5955
|
values.push(params.status);
|
|
@@ -6168,15 +6222,16 @@ var LocalThreadMessageQueueStore = class {
|
|
|
6168
6222
|
).get(threadId, ...filter.params);
|
|
6169
6223
|
return row.count;
|
|
6170
6224
|
}
|
|
6171
|
-
async getThreadsWithPendingMessages() {
|
|
6225
|
+
async getThreadsWithPendingMessages(tenantId) {
|
|
6172
6226
|
const rows2 = this.db.prepare(
|
|
6173
6227
|
`SELECT tenant_id, assistant_id, thread_id, workspace_id, project_id,
|
|
6174
6228
|
MAX(status = 'pending') AS has_pending
|
|
6175
6229
|
FROM lt_thread_message_queue
|
|
6176
6230
|
WHERE status IN ('pending', 'processing')
|
|
6231
|
+
${tenantId ? "AND tenant_id = ?" : ""}
|
|
6177
6232
|
GROUP BY tenant_id, assistant_id, thread_id, workspace_id, project_id
|
|
6178
6233
|
ORDER BY thread_id`
|
|
6179
|
-
).all();
|
|
6234
|
+
).all(...tenantId ? [tenantId] : []);
|
|
6180
6235
|
return rows2.map((r) => ({
|
|
6181
6236
|
tenantId: r.tenant_id,
|
|
6182
6237
|
assistantId: r.assistant_id,
|