@botbotgo/agent-harness 0.0.154 → 0.0.156

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.
@@ -1,6 +1,9 @@
1
1
  import { mkdir, readFile, writeFile } from "node:fs/promises";
2
+ import { mkdirSync } from "node:fs";
2
3
  import path from "node:path";
3
4
  import { InMemoryStore } from "@langchain/langgraph";
5
+ import Database from "better-sqlite3";
6
+ const NAMESPACE_SEPARATOR = "\u001f";
4
7
  function encodeValue(value) {
5
8
  if (value instanceof Date) {
6
9
  return {
@@ -50,6 +53,18 @@ function decodeValue(value) {
50
53
  }
51
54
  return value;
52
55
  }
56
+ function serializeNamespace(namespace) {
57
+ return namespace.join(NAMESPACE_SEPARATOR);
58
+ }
59
+ function parseRow(row) {
60
+ return {
61
+ value: decodeValue(JSON.parse(row.value_json)),
62
+ key: row.key,
63
+ namespace: JSON.parse(row.namespace_json),
64
+ createdAt: new Date(row.created_at),
65
+ updatedAt: new Date(row.updated_at),
66
+ };
67
+ }
53
68
  export class FileBackedStore {
54
69
  filePath;
55
70
  delegate = new InMemoryStore();
@@ -131,6 +146,87 @@ export class FileBackedStore {
131
146
  });
132
147
  }
133
148
  }
149
+ export class SqliteBackedStore {
150
+ filePath;
151
+ db;
152
+ constructor(filePath) {
153
+ this.filePath = filePath;
154
+ mkdirSync(path.dirname(filePath), { recursive: true });
155
+ this.db = new Database(filePath);
156
+ this.db.pragma("journal_mode = WAL");
157
+ this.db.exec(`
158
+ CREATE TABLE IF NOT EXISTS store_entries (
159
+ namespace TEXT NOT NULL,
160
+ namespace_json TEXT NOT NULL,
161
+ key TEXT NOT NULL,
162
+ value_json TEXT NOT NULL,
163
+ created_at TEXT NOT NULL,
164
+ updated_at TEXT NOT NULL,
165
+ PRIMARY KEY (namespace, key)
166
+ );
167
+ CREATE INDEX IF NOT EXISTS idx_store_entries_namespace ON store_entries(namespace);
168
+ `);
169
+ }
170
+ async batch(operations) {
171
+ const results = this.db.transaction((items) => items.map((operation) => {
172
+ const namespace = Array.isArray(operation.namespace) ? operation.namespace.filter((item) => typeof item === "string") : [];
173
+ const key = typeof operation.key === "string" ? operation.key : "";
174
+ if ("value" in operation) {
175
+ this.putSync(namespace, key, operation.value);
176
+ return undefined;
177
+ }
178
+ if (operation.delete === true) {
179
+ this.deleteSync(namespace, key);
180
+ return undefined;
181
+ }
182
+ return this.getSync(namespace, key);
183
+ }))(operations);
184
+ return results;
185
+ }
186
+ async get(namespace, key) {
187
+ return this.getSync(namespace, key);
188
+ }
189
+ getSync(namespace, key) {
190
+ const row = this.db.prepare(`SELECT namespace, namespace_json, key, value_json, created_at, updated_at
191
+ FROM store_entries
192
+ WHERE namespace = ? AND key = ?`).get(serializeNamespace(namespace), key);
193
+ return row ? parseRow(row) : null;
194
+ }
195
+ async search(namespacePrefix) {
196
+ const prefix = serializeNamespace(namespacePrefix);
197
+ const rows = this.db.prepare(`SELECT namespace, namespace_json, key, value_json, created_at, updated_at
198
+ FROM store_entries
199
+ WHERE namespace = ? OR namespace LIKE ?
200
+ ORDER BY namespace ASC, key ASC`).all(prefix, `${prefix}${NAMESPACE_SEPARATOR}%`);
201
+ return rows.map((row) => parseRow(row));
202
+ }
203
+ async put(namespace, key, value, _index) {
204
+ this.putSync(namespace, key, value);
205
+ }
206
+ putSync(namespace, key, value) {
207
+ const now = new Date().toISOString();
208
+ const serializedNamespace = serializeNamespace(namespace);
209
+ const encodedValue = JSON.stringify(encodeValue(value));
210
+ this.db.prepare(`INSERT INTO store_entries (namespace, namespace_json, key, value_json, created_at, updated_at)
211
+ VALUES (?, ?, ?, ?, ?, ?)
212
+ ON CONFLICT(namespace, key) DO UPDATE SET
213
+ namespace_json = excluded.namespace_json,
214
+ value_json = excluded.value_json,
215
+ updated_at = excluded.updated_at`).run(serializedNamespace, JSON.stringify(namespace), key, encodedValue, now, now);
216
+ }
217
+ async delete(namespace, key) {
218
+ this.deleteSync(namespace, key);
219
+ }
220
+ deleteSync(namespace, key) {
221
+ this.db.prepare(`DELETE FROM store_entries WHERE namespace = ? AND key = ?`).run(serializeNamespace(namespace), key);
222
+ }
223
+ async listNamespaces() {
224
+ const rows = this.db.prepare(`SELECT DISTINCT namespace_json
225
+ FROM store_entries
226
+ ORDER BY namespace ASC`).all();
227
+ return rows.map((row) => JSON.parse(row.namespace_json));
228
+ }
229
+ }
134
230
  export function createInMemoryStore() {
135
231
  return new InMemoryStore();
136
232
  }
@@ -1,4 +1,4 @@
1
- import type { ApprovalRecord, CancelOptions, HarnessEvent, HarnessStreamItem, RuntimeHealthSnapshot, MessageContent, RunRecord, RunStartOptions, RestartConversationOptions, RuntimeAdapterOptions, ResumeOptions, RunOptions, RunResult, RunSummary, MemorizeInput, MemorizeResult, RecallInput, RecallResult, ThreadSummary, ThreadRecord, WorkspaceBundle } from "../contracts/types.js";
1
+ import type { ApprovalRecord, CancelOptions, HarnessEvent, HarnessStreamItem, RuntimeHealthSnapshot, ListMemoriesInput, ListMemoriesResult, MessageContent, RemoveMemoryInput, RunRecord, RunStartOptions, RestartConversationOptions, RuntimeAdapterOptions, ResumeOptions, RunOptions, RunResult, RunSummary, MemoryRecord, MemorizeInput, MemorizeResult, RecallInput, RecallResult, UpdateMemoryInput, ThreadSummary, ThreadRecord, WorkspaceBundle } from "../contracts/types.js";
2
2
  import { type ToolMcpServerOptions } from "../mcp.js";
3
3
  import { type InventoryAgentRecord, type InventorySkillRecord } from "./harness/system/inventory.js";
4
4
  import type { RequirementAssessmentOptions } from "./harness/system/skill-requirements.js";
@@ -29,6 +29,11 @@ export declare class AgentHarnessRuntime {
29
29
  private readonly unregisterRuntimeMemorySync;
30
30
  private readonly mem0IngestionSync;
31
31
  private readonly unregisterMem0IngestionSync;
32
+ private readonly mem0SemanticRecall;
33
+ private readonly runtimeMemoryFormationConfig;
34
+ private readonly runtimeMemoryManager;
35
+ private readonly runtimeMemoryFormationSync;
36
+ private readonly unregisterRuntimeMemoryFormationSync;
32
37
  private readonly resolvedRuntimeAdapterOptions;
33
38
  private readonly healthMonitor;
34
39
  private readonly recoveryConfig;
@@ -43,6 +48,7 @@ export declare class AgentHarnessRuntime {
43
48
  private closed;
44
49
  private readonly backgroundEventRuntime;
45
50
  private readonly runtimeEventOperations;
51
+ private resolveRuntimeMemoryVectorStore;
46
52
  private defaultRunRoot;
47
53
  private getDefaultRuntimeEntryAgentId;
48
54
  private resolveSelectedAgentId;
@@ -64,6 +70,9 @@ export declare class AgentHarnessRuntime {
64
70
  }): Promise<RunSummary[]>;
65
71
  memorize(input: MemorizeInput): Promise<MemorizeResult>;
66
72
  recall(input: RecallInput): Promise<RecallResult>;
73
+ listMemories(input?: ListMemoriesInput): Promise<ListMemoriesResult>;
74
+ updateMemory(input: UpdateMemoryInput): Promise<MemoryRecord>;
75
+ removeMemory(input: RemoveMemoryInput): Promise<MemoryRecord>;
67
76
  getRun(runId: string): Promise<RunRecord | null>;
68
77
  private getSession;
69
78
  getThread(threadId: string): Promise<ThreadRecord | null>;
@@ -96,9 +105,20 @@ export declare class AgentHarnessRuntime {
96
105
  private invokeWithHistory;
97
106
  private resolveMemoryNamespace;
98
107
  private getWorkspaceId;
108
+ private summarizeMemoryContent;
109
+ private matchesMemoryFilters;
99
110
  private resolveRecallScopes;
100
111
  private matchesRecallScope;
101
112
  private getMemoryScopeBoost;
113
+ private memoryFreshnessBoost;
114
+ private scoreStructuredRecord;
115
+ private normalizeMemoryDedupKey;
116
+ private inferMem0MemoryKind;
117
+ private inferMem0MemoryScope;
118
+ private createMem0MemoryRecord;
119
+ private rankRecallCandidates;
120
+ private rebuildRuntimeMemoryVectorIndex;
121
+ private refreshStructuredMemoryScope;
102
122
  private buildRuntimeMemoryContext;
103
123
  private persistRuntimeMemoryCandidates;
104
124
  private persistStructuredMemoryCandidates;