@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithers-orchestrator/memory",
3
- "version": "0.16.9",
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.16.9",
32
- "@smithers-orchestrator/errors": "0.16.9",
33
- "@smithers-orchestrator/driver": "0.16.9",
34
- "@smithers-orchestrator/observability": "0.16.9",
35
- "@smithers-orchestrator/scheduler": "0.16.9"
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",
@@ -2,4 +2,4 @@
2
2
  /** @typedef {import("./MemoryProcessor.ts").MemoryProcessor} MemoryProcessor */
3
3
  // @smithers-type-exports-end
4
4
 
5
- import { Effect } from "effect";
5
+ export {};
@@ -2,4 +2,4 @@
2
2
  /** @typedef {import("./MemoryServiceApi.ts").MemoryServiceApi} MemoryServiceApi */
3
3
  // @smithers-type-exports-end
4
4
 
5
- import { Effect } from "effect";
5
+ export {};
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(agent) {
8
+ export function Summarizer(_agent) {
9
9
  /**
10
10
  * @param {MemoryStore} store
11
11
  * @returns {Effect.Effect<void, SmithersError>}
12
12
  */
13
- function processEffect(store) {
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
@@ -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(store) {
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
@@ -1,2 +1 @@
1
- import { Metric } from "effect";
2
- export const memoryFactReads = Metric.counter("smithers.memory.fact_reads");
1
+ export { memoryFactReads } from "@smithers-orchestrator/observability/metrics";
@@ -1,2 +1 @@
1
- import { Metric } from "effect";
2
- export const memoryFactWrites = Metric.counter("smithers.memory.fact_writes");
1
+ export { memoryFactWrites } from "@smithers-orchestrator/observability/metrics";
@@ -1,2 +1 @@
1
- import { Metric } from "effect";
2
- export const memoryMessageSaves = Metric.counter("smithers.memory.message_saves");
1
+ export { memoryMessageSaves } from "@smithers-orchestrator/observability/metrics";
@@ -1,7 +1 @@
1
- import { Metric, MetricBoundaries } from "effect";
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
- import { Metric } from "effect";
2
- export const memoryRecallQueries = Metric.counter("smithers.memory.recall_queries");
1
+ export { memoryRecallQueries } from "@smithers-orchestrator/observability/metrics";
@@ -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
  }
@@ -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 (!["workflow", "agent", "user", "global"].includes(kind)) {
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
- import { integer, sqliteTable, text, primaryKey, } from "drizzle-orm/sqlite-core";
2
- // ---------------------------------------------------------------------------
3
- // Memory Facts -- (namespace, key) primary key
4
- // ---------------------------------------------------------------------------
5
- export const smithersMemoryFacts = sqliteTable("_smithers_memory_facts", {
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";
@@ -2,4 +2,4 @@
2
2
  /** @typedef {import("./MemoryStore.ts").MemoryStore} MemoryStore */
3
3
  // @smithers-type-exports-end
4
4
 
5
- import { Effect } from "effect";
5
+ export {};
@@ -1,4 +1,4 @@
1
- import { and, desc, eq, sql } from "drizzle-orm";
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
  /**