dsh-mnemon-provider-openviking 0.5.10 → 0.5.12

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,5 @@
1
1
  //#endregion
2
2
  //#region src/descriptor.ts
3
- /** Browser-safe metadata owned by this Provider. */
4
3
  const descriptor = {
5
4
  "id": "openviking",
6
5
  "label": "OpenViking",
@@ -1,6 +1,5 @@
1
1
  import { MemoryProviderDescriptor } from "dsh-mnemon-source-memory-spaces/provider-sdk";
2
2
  //#region src/descriptor.d.ts
3
- /** Browser-safe metadata owned by this Provider. */
4
3
  declare const descriptor: MemoryProviderDescriptor;
5
4
  //#endregion
6
5
  export { descriptor };
package/lib/descriptor.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as descriptor } from "./descriptor-1h1ZrvkP.js";
1
+ import { t as descriptor } from "./descriptor-6sO1rrEx.js";
2
2
  export { descriptor };
package/lib/index.d.ts CHANGED
@@ -19,20 +19,8 @@ declare class OpenVikingProvider implements MemoryProviderAdapter {
19
19
  search(body: MemoryBody, request: SearchRequest, signal?: AbortSignal): Promise<ProviderSearchResult>;
20
20
  graph(body: MemoryBody, signal?: AbortSignal): Promise<MemoryGraphSnapshot>;
21
21
  list(body: MemoryBody, request: MemoryListRequest, signal?: AbortSignal): Promise<Insight[]>;
22
- /**
23
- * Each listed memory with its full content, leaving out one the server cannot read: its index
24
- * can still list a file it no longer holds. When none can be read, the first failure is the
25
- * answer, so a server that cannot be reached is never shown as an empty space, and a cancelled
26
- * turn stops at once.
27
- */
28
22
  private readAll;
29
23
  remember(body: MemoryBody, request: RememberRequest, signal?: AbortSignal): Promise<JsonValue>;
30
- /**
31
- * Label a verified memory. Tags only describe it - its category is in the URI too - so a server
32
- * without the endpoint, one that refuses or does not confirm the call, or one that is slow to
33
- * answer leaves an exact memory that is just untagged. The wait is short, as for `/health`:
34
- * the receipt is already true.
35
- */
36
24
  private tag;
37
25
  forget(body: MemoryBody, id: string, signal?: AbortSignal): Promise<JsonValue>;
38
26
  private connection;
package/lib/index.js CHANGED
@@ -1,20 +1,17 @@
1
- import { t as descriptor } from "./descriptor-1h1ZrvkP.js";
2
- import { CATEGORIES, MEMORY_SPACE_PROVIDER_API_VERSION, defineMemorySpaceProvider, defineMemorySpaceProviderDefinition } from "dsh-mnemon-source-memory-spaces/provider-sdk";
1
+ import { t as descriptor } from "./descriptor-6sO1rrEx.js";
2
+ import * as providerSdk from "dsh-mnemon-source-memory-spaces/provider-sdk";
3
+ import { CATEGORIES, MEMORY_SPACE_PROVIDER_API_VERSION, defineMemorySpaceProvider, defineMemorySpaceProviderDefinition, jsonNumber, jsonObject, jsonString } from "dsh-mnemon-source-memory-spaces/provider-sdk";
3
4
  import { randomUUID } from "node:crypto";
4
5
  //#region src/driver.ts
5
- function object(value) {
6
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
6
+ function normalizeBearerHeader(apiKey) {
7
+ if (typeof providerSdk.bearerAuthHeader === "function") return providerSdk.bearerAuthHeader(apiKey);
8
+ if (typeof apiKey !== "string") return void 0;
9
+ const stripped = apiKey.trim().replace(/^Bearer(?:\s+|$)/iu, "").trim();
10
+ return stripped === "" ? void 0 : `Bearer ${stripped}`;
7
11
  }
8
- function string(value) {
9
- return typeof value === "string" ? value : void 0;
10
- }
11
- function number(value) {
12
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
13
- }
14
- /** The categories Mnemon writes; anything else is stored, and read back, as general. */
15
12
  const CATEGORY_NAMES = new Set(CATEGORIES);
16
13
  function categoryOf(value) {
17
- const category = string(value)?.trim().toLowerCase();
14
+ const category = jsonString(value)?.trim().toLowerCase();
18
15
  return category !== void 0 && CATEGORY_NAMES.has(category) ? category : "general";
19
16
  }
20
17
  const MEMORY_FOLDERS = {
@@ -25,10 +22,6 @@ const MEMORY_FOLDERS = {
25
22
  fact: "entities",
26
23
  general: "entities"
27
24
  };
28
- /**
29
- * The slug's share of a file name, which Linux caps at 255 bytes: the stamp, the longest
30
- * category, the UUID and the separators take 66, so 48 characters of four bytes would not fit.
31
- */
32
25
  const SLUG_BYTES = 180;
33
26
  function memoryUri(root, category, content) {
34
27
  const folder = Object.hasOwn(MEMORY_FOLDERS, category) ? MEMORY_FOLDERS[category] : "entities";
@@ -45,7 +38,7 @@ function discoveryUser(connection) {
45
38
  const user = String(connection.discoveryUser ?? "").trim();
46
39
  if (user === "") return void 0;
47
40
  if (!safeUser(user) || !safeUser(String(connection.account ?? "").trim())) throw new Error("OpenViking user-key discovery requires an explicit account and a safe discovery user");
48
- if (String(connection.apiKey ?? "").trim() === "") throw new Error("OpenViking user-key discovery requires a user API key");
41
+ if (normalizeBearerHeader(connection.apiKey) === void 0) throw new Error("OpenViking user-key discovery requires a user API key");
49
42
  return user;
50
43
  }
51
44
  function isMemoryFile(uri, root) {
@@ -53,29 +46,26 @@ function isMemoryFile(uri, root) {
53
46
  return uri.slice(root.length + 1).split("/").every((part) => part !== "" && !part.startsWith(".") && part.trim() === part);
54
47
  }
55
48
  function queueFailed(value) {
56
- return Object.values(object(value) ?? {}).some((entry) => {
57
- const queue = object(entry);
58
- return (number(queue?.error_count) ?? 0) > 0 || Array.isArray(queue?.errors) && queue.errors.length > 0;
49
+ return Object.values(jsonObject(value) ?? {}).some((entry) => {
50
+ const queue = jsonObject(entry);
51
+ return (jsonNumber(queue?.error_count) ?? 0) > 0 || Array.isArray(queue?.errors) && queue.errors.length > 0;
59
52
  });
60
53
  }
61
- /** What a folder holds, for files written before the category was in the name or by OpenViking itself. */
62
54
  const FOLDER_CATEGORIES = {
63
55
  preferences: "preference",
64
56
  experiences: "insight",
65
57
  events: "context",
66
58
  entities: "fact"
67
59
  };
68
- /** The category in the file name Mnemon wrote, else one the server reports, else the folder's. */
69
60
  function categoryFromUri(uri, reported) {
70
61
  const named = /_([a-z]+)-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.md$/u.exec(uri)?.[1];
71
62
  if (named !== void 0 && CATEGORY_NAMES.has(named)) return named;
72
- const stated = string(reported);
63
+ const stated = jsonString(reported);
73
64
  if (stated !== void 0 && CATEGORY_NAMES.has(stated)) return stated;
74
65
  const marker = "/memories/";
75
66
  const folder = (uri.includes(marker) ? uri.slice(uri.indexOf(marker) + 10) : "").split("/")[0] ?? "";
76
67
  return Object.hasOwn(FOLDER_CATEGORIES, folder) ? FOLDER_CATEGORIES[folder] : "general";
77
68
  }
78
- /** Whether the server turned the request down as sent, so it wrote nothing: not a timeout or a server fault. */
79
69
  function refused(error) {
80
70
  const status = error?.status;
81
71
  return typeof status === "number" && status >= 400 && status < 500 && status !== 408 && status !== 409;
@@ -111,7 +101,7 @@ var OpenVikingProvider = class {
111
101
  if (account === "") {
112
102
  const accounts = await this.requestConnection(connection, "/api/v1/admin/accounts", {}, { signal });
113
103
  const ids = (Array.isArray(accounts) ? accounts : []).flatMap((value) => {
114
- const id = string(object(value)?.account_id) ?? string(object(value)?.id);
104
+ const id = jsonString(jsonObject(value)?.account_id) ?? jsonString(jsonObject(value)?.id);
115
105
  return id === void 0 ? [] : [id];
116
106
  });
117
107
  if (ids.length > 1) throw new Error("OpenViking exposes multiple accounts; configure the account to select one discovery scope");
@@ -122,13 +112,13 @@ var OpenVikingProvider = class {
122
112
  account
123
113
  }, `/api/v1/admin/accounts/${encodeURIComponent(account)}/users?limit=100`, {}, { signal });
124
114
  return (Array.isArray(users) ? users : []).flatMap((value) => {
125
- const item = object(value);
126
- const user = string(item?.user_id) ?? string(item?.id) ?? string(item?.name);
115
+ const item = jsonObject(value);
116
+ const user = jsonString(item?.user_id) ?? jsonString(item?.id) ?? jsonString(item?.name);
127
117
  if (user === void 0 || !safeUser(user)) return [];
128
118
  return [{
129
119
  externalId: `${account}:${user}`,
130
- name: string(item?.display_name) ?? string(item?.name) ?? user,
131
- description: string(item?.description) ?? string(item?.role) ?? `OpenViking memory namespace for ${user}`,
120
+ name: jsonString(item?.display_name) ?? jsonString(item?.name) ?? user,
121
+ description: jsonString(item?.description) ?? jsonString(item?.role) ?? `OpenViking memory namespace for ${user}`,
132
122
  connection: {
133
123
  targetUri: `viking://user/${user}/memories`,
134
124
  user,
@@ -161,9 +151,9 @@ var OpenVikingProvider = class {
161
151
  const keyword = request.mode === "keyword";
162
152
  signal?.throwIfAborted();
163
153
  if (keyword && request.query.trim() === "") return { results: [] };
164
- const limit = keyword ? Math.min(50, Math.max(1, Math.floor(number(request.limit) ?? 10))) : request.limit;
154
+ const limit = keyword ? Math.min(50, Math.max(1, Math.floor(jsonNumber(request.limit) ?? 10))) : request.limit;
165
155
  const memoryRoot = await this.memoryRoot(body, signal);
166
- const root = object(await this.request(body, keyword ? "/api/v1/search/grep" : "/api/v1/search/find", {
156
+ const result = await this.request(body, keyword ? "/api/v1/search/grep" : "/api/v1/search/find", {
167
157
  method: "POST",
168
158
  body: JSON.stringify(keyword ? {
169
159
  uri: memoryRoot,
@@ -176,22 +166,23 @@ var OpenVikingProvider = class {
176
166
  context_type: ["memory"],
177
167
  limit: request.limit
178
168
  })
179
- }, { signal }));
169
+ }, { signal });
170
+ const root = jsonObject(result);
180
171
  if (keyword && !Array.isArray(root?.matches)) throw new Error("OpenViking keyword search did not return matches");
181
172
  const values = keyword ? root?.matches : root?.memories;
182
173
  const entries = Array.isArray(values) ? values : [];
183
174
  const seen = /* @__PURE__ */ new Set();
184
175
  const matches = entries.flatMap((value) => {
185
- const item = object(value);
186
- const uri = string(item?.uri);
176
+ const item = jsonObject(value);
177
+ const uri = jsonString(item?.uri);
187
178
  if (uri === void 0 || !isMemoryFile(uri, memoryRoot)) return [];
188
179
  if (keyword && seen.has(uri)) return [];
189
180
  seen.add(uri);
190
- const score = keyword ? void 0 : number(item?.score);
181
+ const score = keyword ? void 0 : jsonNumber(item?.score);
191
182
  return [{
192
183
  id: uri,
193
184
  externalUri: uri,
194
- content: string(item?.overview) ?? string(item?.abstract) ?? uri,
185
+ content: jsonString(item?.overview) ?? jsonString(item?.abstract) ?? uri,
195
186
  category: categoryFromUri(uri, item?.category),
196
187
  source: "external",
197
188
  ...score === void 0 ? {} : { score }
@@ -224,8 +215,8 @@ var OpenVikingProvider = class {
224
215
  const entries = Array.isArray(result) ? result : [];
225
216
  const limit = Math.min(Math.max(request.limit ?? 200, 1), 1e3);
226
217
  const files = entries.flatMap((value) => {
227
- const item = object(value);
228
- const uri = string(item?.uri);
218
+ const item = jsonObject(value);
219
+ const uri = jsonString(item?.uri);
229
220
  return item === void 0 || uri === void 0 || item.isDir === true || !isMemoryFile(uri, memoryRoot) ? [] : [{
230
221
  item,
231
222
  uri
@@ -236,7 +227,7 @@ var OpenVikingProvider = class {
236
227
  item
237
228
  })), signal);
238
229
  return read.map(({ item, id, content }) => {
239
- const createdAt = string(item.modTime);
230
+ const createdAt = jsonString(item.modTime);
240
231
  return {
241
232
  id,
242
233
  externalUri: id,
@@ -247,12 +238,6 @@ var OpenVikingProvider = class {
247
238
  };
248
239
  });
249
240
  }
250
- /**
251
- * Each listed memory with its full content, leaving out one the server cannot read: its index
252
- * can still list a file it no longer holds. When none can be read, the first failure is the
253
- * answer, so a server that cannot be reached is never shown as an empty space, and a cancelled
254
- * turn stops at once.
255
- */
256
241
  async readAll(body, items, signal) {
257
242
  const settled = await Promise.allSettled(items.map(async (item) => ({
258
243
  ...item,
@@ -272,12 +257,12 @@ var OpenVikingProvider = class {
272
257
  const category = categoryOf(request.category);
273
258
  const uri = memoryUri(root, category, request.content);
274
259
  const tags = ["source=mnemon", `category=${category}`];
275
- const importance = number(request.importance);
260
+ const importance = jsonNumber(request.importance);
276
261
  if (importance !== void 0) tags.push(`importance=${importance}`);
277
262
  const writtenBytes = Buffer.byteLength(request.content, "utf8");
278
263
  let written;
279
264
  try {
280
- written = object(await this.request(body, "/api/v1/content/write", {
265
+ written = jsonObject(await this.request(body, "/api/v1/content/write", {
281
266
  method: "POST",
282
267
  body: JSON.stringify({
283
268
  uri,
@@ -291,7 +276,7 @@ var OpenVikingProvider = class {
291
276
  throw new Error(`OpenViking write was not verified at ${uri}; remote content may remain. Inspect this URI before retrying. ${error instanceof Error ? error.message : String(error)}`, { cause: error });
292
277
  }
293
278
  try {
294
- if (written?.uri !== uri || written.content_updated !== true || (number(written.written_bytes) ?? -1) < writtenBytes || written.mode !== "create" || written.context_type !== "memory" || written.vector_status !== "complete" || !["complete", "skipped"].includes(String(written.semantic_status)) || queueFailed(written.queue_status)) throw new Error("content API did not confirm this exact memory and completed indexing");
279
+ if (written?.uri !== uri || written.content_updated !== true || (jsonNumber(written.written_bytes) ?? -1) < writtenBytes || written.mode !== "create" || written.context_type !== "memory" || written.vector_status !== "complete" || !["complete", "skipped"].includes(String(written.semantic_status)) || queueFailed(written.queue_status)) throw new Error("content API did not confirm this exact memory and completed indexing");
295
280
  if (await this.readContent(body, uri, signal) !== request.content) throw new Error("stored content does not match the requested text");
296
281
  signal?.throwIfAborted();
297
282
  } catch (error) {
@@ -309,15 +294,9 @@ var OpenVikingProvider = class {
309
294
  tagsApplied: await this.tag(body, uri, tags, signal)
310
295
  };
311
296
  }
312
- /**
313
- * Label a verified memory. Tags only describe it - its category is in the URI too - so a server
314
- * without the endpoint, one that refuses or does not confirm the call, or one that is slow to
315
- * answer leaves an exact memory that is just untagged. The wait is short, as for `/health`:
316
- * the receipt is already true.
317
- */
318
297
  async tag(body, uri, tags, signal) {
319
298
  try {
320
- return object(await this.request(body, "/api/v1/content/set_tags", {
299
+ return jsonObject(await this.request(body, "/api/v1/content/set_tags", {
321
300
  method: "POST",
322
301
  body: JSON.stringify({
323
302
  uri,
@@ -340,14 +319,14 @@ var OpenVikingProvider = class {
340
319
  uri,
341
320
  recursive: "false"
342
321
  });
343
- const result = object(await this.request(body, `/api/v1/fs?${query}`, { method: "DELETE" }, { signal })) ?? {};
322
+ const result = jsonObject(await this.request(body, `/api/v1/fs?${query}`, { method: "DELETE" }, { signal })) ?? {};
344
323
  if (result.uri !== uri) throw new Error("OpenViking did not confirm deletion of the requested memory URI");
345
324
  return {
346
325
  action: "deleted",
347
326
  provider: this.id,
348
327
  id: uri,
349
328
  uri,
350
- ...number(result.estimated_deleted_count) === void 0 ? {} : { estimatedDeletedCount: number(result.estimated_deleted_count) }
329
+ ...jsonNumber(result.estimated_deleted_count) === void 0 ? {} : { estimatedDeletedCount: jsonNumber(result.estimated_deleted_count) }
351
330
  };
352
331
  }
353
332
  connection(body) {
@@ -371,7 +350,7 @@ var OpenVikingProvider = class {
371
350
  output: "original"
372
351
  });
373
352
  const result = await this.requestConnection(connection, `/api/v1/fs/ls?${query}`, {}, { signal });
374
- if (!Array.isArray(result) || result.some((item) => !string(object(item)?.uri)?.startsWith(`${root}/`))) throw new Error("OpenViking could not validate the selected memory namespace");
353
+ if (!Array.isArray(result) || result.some((item) => !jsonString(jsonObject(item)?.uri)?.startsWith(`${root}/`))) throw new Error("OpenViking could not validate the selected memory namespace");
375
354
  return root;
376
355
  }
377
356
  async memoryRoot(body, signal) {
@@ -386,7 +365,7 @@ var OpenVikingProvider = class {
386
365
  return `viking://user/${selectedUser}/memories`;
387
366
  }
388
367
  if (match[1] !== void 0) return root;
389
- const user = connection.user?.trim() || string(object(await this.request(body, "/api/v1/system/status", {}, { signal }))?.user) || "";
368
+ const user = connection.user?.trim() || jsonString(jsonObject(await this.request(body, "/api/v1/system/status", {}, { signal }))?.user) || "";
390
369
  if (!safeUser(user)) throw new Error("OpenViking could not resolve the memory owner; configure an explicit user memory URI");
391
370
  return `viking://user/${user}/memories`;
392
371
  }
@@ -407,11 +386,12 @@ var OpenVikingProvider = class {
407
386
  options.signal?.addEventListener("abort", relay, { once: true });
408
387
  const timer = setTimeout(() => controller.abort(/* @__PURE__ */ new Error("OpenViking request timed out")), options.timeoutMs ?? this.requestTimeoutMs);
409
388
  try {
389
+ const auth = normalizeBearerHeader(connection.apiKey);
410
390
  const response = await this.requestFetch(`${connection.endpoint}${path}`, {
411
391
  ...init,
412
392
  headers: {
413
393
  "Content-Type": "application/json",
414
- ...connection.apiKey === void 0 || connection.apiKey === "" ? {} : { Authorization: `Bearer ${connection.apiKey}` },
394
+ ...auth === void 0 ? {} : { Authorization: auth },
415
395
  ...keyBound || connection.account === void 0 || connection.account === "" ? {} : { "X-OpenViking-Account": String(connection.account) },
416
396
  ...keyBound || connection.user === void 0 || connection.user === "" ? {} : { "X-OpenViking-User": String(connection.user) },
417
397
  ...connection.actorPeerId === void 0 || connection.actorPeerId === "" ? {} : { "X-OpenViking-Actor-Peer": String(connection.actorPeerId) },
@@ -442,7 +422,7 @@ const definition = defineMemorySpaceProviderDefinition({
442
422
  kind: "provider",
443
423
  typeId: descriptor.id,
444
424
  packageName: "dsh-mnemon-provider-openviking",
445
- version: "0.5.10",
425
+ version: "0.5.12",
446
426
  label: descriptor.label,
447
427
  icon: descriptor.icon,
448
428
  summary: descriptor.summary,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mnemon-provider-openviking",
3
- "version": "0.5.10",
3
+ "version": "0.5.12",
4
4
  "description": "OpenViking Provider child for the Memory Spaces Source.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^22.0.0",
37
- "dsh-mnemon-source-memory-spaces": "^0.5.23",
37
+ "dsh-mnemon-source-memory-spaces": "^0.5.33",
38
38
  "tsdown": "^0.22.0",
39
39
  "typescript": "^5.9.0",
40
40
  "vitest": "^3.2.0"