@smithers-orchestrator/memory 0.16.9 → 0.18.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/package.json +17 -6
- package/src/MemoryProcessor.js +1 -1
- package/src/MemoryServiceApi.js +1 -1
- package/src/Summarizer.js +2 -2
- package/src/TokenLimiter.js +1 -1
- package/src/memoryFactReads.js +1 -2
- package/src/memoryFactWrites.js +1 -2
- package/src/memoryMessageSaves.js +1 -2
- package/src/memoryRecallDuration.js +1 -7
- package/src/memoryRecallQueries.js +1 -2
- package/src/namespaceToString.js +10 -1
- package/src/parseNamespace.js +13 -2
- package/src/schema.js +5 -38
- package/src/store/MemoryStore.js +1 -1
- package/src/store/MemoryStoreLive.js +1 -1
- package/src/store/createMemoryStoreLayer.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithers-orchestrator/memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Persistent and semantic memory services for Smithers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -15,6 +15,16 @@
|
|
|
15
15
|
"import": "./src/store/index.js",
|
|
16
16
|
"default": "./src/store/index.js"
|
|
17
17
|
},
|
|
18
|
+
"./metrics": {
|
|
19
|
+
"types": "./src/index.d.ts",
|
|
20
|
+
"import": "./src/metrics.js",
|
|
21
|
+
"default": "./src/metrics.js"
|
|
22
|
+
},
|
|
23
|
+
"./schema": {
|
|
24
|
+
"types": "./src/index.d.ts",
|
|
25
|
+
"import": "./src/schema.js",
|
|
26
|
+
"default": "./src/schema.js"
|
|
27
|
+
},
|
|
18
28
|
"./*": {
|
|
19
29
|
"types": "./src/index.d.ts",
|
|
20
30
|
"import": "./src/*.js",
|
|
@@ -28,11 +38,12 @@
|
|
|
28
38
|
"drizzle-orm": "^0.45.2",
|
|
29
39
|
"effect": "^3.21.1",
|
|
30
40
|
"zod": "^4.3.6",
|
|
31
|
-
"@smithers-orchestrator/db": "0.
|
|
32
|
-
"@smithers-orchestrator/
|
|
33
|
-
"@smithers-orchestrator/
|
|
34
|
-
"@smithers-orchestrator/observability": "0.
|
|
35
|
-
"@smithers-orchestrator/scheduler": "0.
|
|
41
|
+
"@smithers-orchestrator/db": "0.18.0",
|
|
42
|
+
"@smithers-orchestrator/driver": "0.18.0",
|
|
43
|
+
"@smithers-orchestrator/errors": "0.18.0",
|
|
44
|
+
"@smithers-orchestrator/observability": "0.18.0",
|
|
45
|
+
"@smithers-orchestrator/scheduler": "0.18.0",
|
|
46
|
+
"@smithers-orchestrator/graph": "0.18.0"
|
|
36
47
|
},
|
|
37
48
|
"devDependencies": {
|
|
38
49
|
"@types/bun": "latest",
|
package/src/MemoryProcessor.js
CHANGED
package/src/MemoryServiceApi.js
CHANGED
package/src/Summarizer.js
CHANGED
|
@@ -5,12 +5,12 @@ import { Effect } from "effect";
|
|
|
5
5
|
* @param {{ run: (prompt: string) => Promise<any> }} agent
|
|
6
6
|
* @returns {MemoryProcessor}
|
|
7
7
|
*/
|
|
8
|
-
export function Summarizer(
|
|
8
|
+
export function Summarizer(_agent) {
|
|
9
9
|
/**
|
|
10
10
|
* @param {MemoryStore} store
|
|
11
11
|
* @returns {Effect.Effect<void, SmithersError>}
|
|
12
12
|
*/
|
|
13
|
-
function processEffect(
|
|
13
|
+
function processEffect(_store) {
|
|
14
14
|
return Effect.gen(function* () {
|
|
15
15
|
// Summarizer operates on a specific thread's messages, compressing
|
|
16
16
|
// older messages into a summary. Without a thread context, it logs
|
package/src/TokenLimiter.js
CHANGED
|
@@ -12,7 +12,7 @@ export function TokenLimiter(maxTokens) {
|
|
|
12
12
|
* @param {MemoryStore} store
|
|
13
13
|
* @returns {Effect.Effect<void, SmithersError>}
|
|
14
14
|
*/
|
|
15
|
-
function processEffect(
|
|
15
|
+
function processEffect(_store) {
|
|
16
16
|
return Effect.gen(function* () {
|
|
17
17
|
// Token limiter operates at the thread level; without a specific thread
|
|
18
18
|
// context it logs and returns. In practice, this processor is invoked
|
package/src/memoryFactReads.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const memoryFactReads = Metric.counter("smithers.memory.fact_reads");
|
|
1
|
+
export { memoryFactReads } from "@smithers-orchestrator/observability/metrics";
|
package/src/memoryFactWrites.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const memoryFactWrites = Metric.counter("smithers.memory.fact_writes");
|
|
1
|
+
export { memoryFactWrites } from "@smithers-orchestrator/observability/metrics";
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const memoryMessageSaves = Metric.counter("smithers.memory.message_saves");
|
|
1
|
+
export { memoryMessageSaves } from "@smithers-orchestrator/observability/metrics";
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const durationBuckets = MetricBoundaries.exponential({
|
|
3
|
-
start: 1,
|
|
4
|
-
factor: 2,
|
|
5
|
-
count: 14,
|
|
6
|
-
}); // ~1ms to ~8s
|
|
7
|
-
export const memoryRecallDuration = Metric.histogram("smithers.memory.recall_duration_ms", durationBuckets);
|
|
1
|
+
export { memoryRecallDuration } from "@smithers-orchestrator/observability/metrics";
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const memoryRecallQueries = Metric.counter("smithers.memory.recall_queries");
|
|
1
|
+
export { memoryRecallQueries } from "@smithers-orchestrator/observability/metrics";
|
package/src/namespaceToString.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
|
|
2
2
|
/** @typedef {import("./MemoryNamespace.ts").MemoryNamespace} MemoryNamespace */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} id
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
function encodeNamespaceId(id) {
|
|
9
|
+
return id.replace(/%/g, "%25").replace(/:/g, "%3A");
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
/**
|
|
4
13
|
* @param {MemoryNamespace} ns
|
|
5
14
|
* @returns {string}
|
|
6
15
|
*/
|
|
7
16
|
export function namespaceToString(ns) {
|
|
8
|
-
return `${ns.kind}:${ns.id}`;
|
|
17
|
+
return `${ns.kind}:${encodeNamespaceId(ns.id)}`;
|
|
9
18
|
}
|
package/src/parseNamespace.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
|
|
2
2
|
/** @typedef {import("./MemoryNamespace.ts").MemoryNamespace} MemoryNamespace */
|
|
3
|
+
|
|
4
|
+
const MEMORY_NAMESPACE_KINDS = ["workflow", "agent", "user", "global"];
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} id
|
|
8
|
+
* @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
function decodeNamespaceId(id) {
|
|
11
|
+
return id.replace(/%3A/g, ":").replace(/%25/g, "%");
|
|
12
|
+
}
|
|
13
|
+
|
|
3
14
|
/**
|
|
4
15
|
* @param {string} str
|
|
5
16
|
* @returns {MemoryNamespace}
|
|
@@ -11,8 +22,8 @@ export function parseNamespace(str) {
|
|
|
11
22
|
}
|
|
12
23
|
const kind = str.slice(0, idx);
|
|
13
24
|
const id = str.slice(idx + 1);
|
|
14
|
-
if (!
|
|
25
|
+
if (!MEMORY_NAMESPACE_KINDS.includes(kind)) {
|
|
15
26
|
return { kind: "global", id: str };
|
|
16
27
|
}
|
|
17
|
-
return { kind, id };
|
|
28
|
+
return { kind, id: decodeNamespaceId(id) };
|
|
18
29
|
}
|
package/src/schema.js
CHANGED
|
@@ -1,38 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
namespace: text("namespace").notNull(),
|
|
7
|
-
key: text("key").notNull(),
|
|
8
|
-
valueJson: text("value_json").notNull(),
|
|
9
|
-
schemaSig: text("schema_sig"),
|
|
10
|
-
createdAtMs: integer("created_at_ms").notNull(),
|
|
11
|
-
updatedAtMs: integer("updated_at_ms").notNull(),
|
|
12
|
-
ttlMs: integer("ttl_ms"),
|
|
13
|
-
}, (t) => ({
|
|
14
|
-
pk: primaryKey({ columns: [t.namespace, t.key] }),
|
|
15
|
-
}));
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
// Memory Threads
|
|
18
|
-
// ---------------------------------------------------------------------------
|
|
19
|
-
export const smithersMemoryThreads = sqliteTable("_smithers_memory_threads", {
|
|
20
|
-
threadId: text("thread_id").primaryKey(),
|
|
21
|
-
namespace: text("namespace").notNull(),
|
|
22
|
-
title: text("title"),
|
|
23
|
-
metadataJson: text("metadata_json"),
|
|
24
|
-
createdAtMs: integer("created_at_ms").notNull(),
|
|
25
|
-
updatedAtMs: integer("updated_at_ms").notNull(),
|
|
26
|
-
});
|
|
27
|
-
// ---------------------------------------------------------------------------
|
|
28
|
-
// Memory Messages
|
|
29
|
-
// ---------------------------------------------------------------------------
|
|
30
|
-
export const smithersMemoryMessages = sqliteTable("_smithers_memory_messages", {
|
|
31
|
-
id: text("id").primaryKey(),
|
|
32
|
-
threadId: text("thread_id").notNull(),
|
|
33
|
-
role: text("role").notNull(),
|
|
34
|
-
contentJson: text("content_json").notNull(),
|
|
35
|
-
runId: text("run_id"),
|
|
36
|
-
nodeId: text("node_id"),
|
|
37
|
-
createdAtMs: integer("created_at_ms").notNull(),
|
|
38
|
-
});
|
|
1
|
+
export {
|
|
2
|
+
smithersMemoryFacts,
|
|
3
|
+
smithersMemoryThreads,
|
|
4
|
+
smithersMemoryMessages,
|
|
5
|
+
} from "@smithers-orchestrator/db/internal-schema";
|
package/src/store/MemoryStore.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { and,
|
|
1
|
+
import { and, eq, sql } from "drizzle-orm";
|
|
2
2
|
import { Effect, Layer, Metric } from "effect";
|
|
3
3
|
import { toSmithersError } from "@smithers-orchestrator/errors/toSmithersError";
|
|
4
4
|
import { dbQueryDuration } from "@smithers-orchestrator/observability/metrics";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
2
|
import { MemoryStoreDb } from "./MemoryStoreDb.js";
|
|
3
3
|
import { MemoryStoreLive } from "./MemoryStoreLive.js";
|
|
4
|
-
import { MemoryStoreService } from "./MemoryStoreService.js";
|
|
5
4
|
/** @typedef {import("drizzle-orm/bun-sqlite").BunSQLiteDatabase} BunSQLiteDatabase */
|
|
6
5
|
|
|
7
6
|
/**
|