dsh-mnemon-provider-openviking 0.5.5 → 0.5.7

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/README.md CHANGED
@@ -8,7 +8,11 @@ The supported scope is `viking://user/<user>/memories`. Existing `viking://user/
8
8
 
9
9
  ## Use
10
10
 
11
- The default `dsh-mnemon` Starter already installs this package. Enable and configure the service in **Settings → Memory System**, then inspect its synchronized Memory Spaces.
11
+ The default `dsh-mnemon` Starter already installs this package. Enable and configure the service on the `dsh-mnemon` page under **Plugins**, then inspect its synchronized Memory Spaces.
12
+
13
+ For a user API key without Admin API access, including managed OpenViking Service endpoints, fill `endpoint`, `apiKey`, `account`, and **User key owner (skip admin)** (`discoveryUser`) with the supplied account/user identifiers. The adapter validates `viking://user/<discoveryUser>/memories` through the read-only `/api/v1/fs/ls` data API and synchronizes that one space. It sends no account/user identity headers in this mode: the key determines the authenticated tenant, and `account` identifies the local projection rather than overriding that identity. Use an existing accessible memory root; an absent root, rejected key, invalid response, or denied owner fails the save and preserves previous settings. Health-only success is insufficient. This path does not verify write permission or certify a particular cloud deployment; exact writes still require the content API above.
14
+
15
+ Leave `discoveryUser` empty for the existing admin discovery flow. There is no automatic fallback after an admin error. Nonempty `discoveryUser` requires a safe user ID, an explicit account, and an API key; manually configured memory owners must match it. The new setting uses the existing service registry format. Before downgrading to an adapter without this field, clear it using the current version and use admin-capable configuration, or disable the service and restore an older compatible configuration. Reconnection and downgrade never delete remote memories.
12
16
 
13
17
  For a custom composition, install this package alongside `dsh-mnemon-source-memory-spaces` and include it in that Source's `config.providers`:
14
18
 
@@ -26,6 +30,6 @@ This is a **Memory Spaces child module**, not a top-level Source or a complete S
26
30
 
27
31
  From a source checkout with the declared dependencies installed, run `pnpm verify`. Tests, build and public exports belong to this package, without importing another package's controllers or repository configuration. Use the Source's public `/testing` fixtures for child registration and driver conformance; live service tests require a separately authorized environment.
28
32
 
29
- To test a disposable local OpenViking service (never a personal store), run `MNEMON_OPENVIKING_TEST_ENDPOINT=http://127.0.0.1:1933 pnpm exec vitest run tests/integration.spec.ts`. Supply `MNEMON_OPENVIKING_TEST_API_KEY` when the service requires authentication. It creates one synthetic canary in the default user's namespace, reads/searches/browses it, and deletes its exact URI. Ordinary verification skips this optional integration test. On v0.4.20, UI discovery additionally requires an explicit account and an account-admin key; ROOT keys cannot access tenant data.
33
+ To test a disposable local OpenViking service (never a personal store), run `MNEMON_OPENVIKING_TEST_ENDPOINT=http://127.0.0.1:1933 pnpm exec vitest run tests/integration.spec.ts`. Supply `MNEMON_OPENVIKING_TEST_API_KEY` when the service requires authentication. It creates one synthetic canary in the default user's namespace, reads/searches/browses it, and deletes its exact URI. Ordinary verification skips this optional integration test. Admin discovery requires a key allowed to enumerate users; ROOT keys cannot access tenant data in `api_key` mode. The user-key regression uses deterministic responses, not a live cloud account.
30
34
 
31
35
  [Plugin author guide](https://github.com/omdsh-dev/dsh-mnemon/blob/main/docs/en/development/extensions.md)
@@ -65,6 +65,17 @@ const descriptor = {
65
65
  "required": false,
66
66
  "i18nKey": "overview.providerAccount"
67
67
  },
68
+ {
69
+ "key": "discoveryUser",
70
+ "label": "User key owner (skip admin)",
71
+ "scope": "service",
72
+ "input": "text",
73
+ "required": false,
74
+ "maxLength": 200,
75
+ "pattern": "^(?!\\.{1,2}$)(?!.*@.*@)[a-zA-Z0-9_.@\\-]+$",
76
+ "validationMessage": "OpenViking discovery user must be a safe user ID",
77
+ "i18nKey": "overview.providerDiscoveryUser"
78
+ },
68
79
  {
69
80
  "key": "user",
70
81
  "label": "User",
package/lib/descriptor.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as descriptor } from "./descriptor-BGwdKZKn.js";
1
+ import { t as descriptor } from "./descriptor-1h1ZrvkP.js";
2
2
  export { descriptor };
package/lib/index.d.ts CHANGED
@@ -20,6 +20,7 @@ declare class OpenVikingProvider implements MemoryProviderAdapter {
20
20
  remember(body: MemoryBody, request: RememberRequest, signal?: AbortSignal): Promise<JsonValue>;
21
21
  forget(body: MemoryBody, id: string, signal?: AbortSignal): Promise<JsonValue>;
22
22
  private connection;
23
+ private validateUserNamespace;
23
24
  private memoryRoot;
24
25
  private readContent;
25
26
  private request;
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as descriptor } from "./descriptor-BGwdKZKn.js";
1
+ import { t as descriptor } from "./descriptor-1h1ZrvkP.js";
2
2
  import { MEMORY_SPACE_PROVIDER_API_VERSION, NORMALIZED_RELEVANCE_SCORE, defineMemorySpaceProvider, defineMemorySpaceProviderDefinition } from "dsh-mnemon-source-memory-spaces/provider-sdk";
3
3
  import { randomUUID } from "node:crypto";
4
4
  //#region src/driver.ts
@@ -28,6 +28,13 @@ function memoryUri(root, category, content) {
28
28
  function safeUser(user) {
29
29
  return /^[a-zA-Z0-9_.@-]+$/u.test(user) && user !== "." && user !== ".." && (user.match(/@/gu)?.length ?? 0) <= 1;
30
30
  }
31
+ function discoveryUser(connection) {
32
+ const user = String(connection.discoveryUser ?? "").trim();
33
+ if (user === "") return void 0;
34
+ if (!safeUser(user) || !safeUser(String(connection.account ?? "").trim())) throw new Error("OpenViking user-key discovery requires an explicit account and a safe discovery user");
35
+ if (String(connection.apiKey ?? "").trim() === "") throw new Error("OpenViking user-key discovery requires a user API key");
36
+ return user;
37
+ }
31
38
  function isMemoryFile(uri, root) {
32
39
  if (!uri.startsWith(`${root}/`) || !uri.endsWith(".md") || /[%?#\\\u0000-\u001f\u007f]/u.test(uri)) return false;
33
40
  return uri.slice(root.length + 1).split("/").every((part) => part !== "" && !part.startsWith(".") && part.trim() === part);
@@ -54,7 +61,22 @@ var OpenVikingProvider = class {
54
61
  this.requestTimeoutMs = options.requestTimeoutMs ?? 15e3;
55
62
  }
56
63
  async discover(connection, signal) {
64
+ signal?.throwIfAborted();
57
65
  let account = String(connection.account ?? "").trim();
66
+ const selectedUser = discoveryUser(connection);
67
+ if (selectedUser !== void 0) {
68
+ const targetUri = await this.validateUserNamespace(connection, selectedUser, signal);
69
+ return [{
70
+ externalId: `${account}:${selectedUser}`,
71
+ name: selectedUser,
72
+ description: `OpenViking memory namespace for ${selectedUser}`,
73
+ connection: {
74
+ targetUri,
75
+ user: selectedUser,
76
+ actorPeerId: "dsh"
77
+ }
78
+ }];
79
+ }
58
80
  if (account === "") {
59
81
  const accounts = await this.requestConnection(connection, "/api/v1/admin/accounts", {}, { signal });
60
82
  const ids = (Array.isArray(accounts) ? accounts : []).flatMap((value) => {
@@ -86,10 +108,16 @@ var OpenVikingProvider = class {
86
108
  }
87
109
  async status(body, signal) {
88
110
  try {
89
- await this.request(body, "/health", {}, {
111
+ const connection = this.connection(body);
112
+ const selectedUser = discoveryUser(connection);
113
+ if (selectedUser === void 0) await this.request(body, "/health", {}, {
90
114
  signal,
91
115
  timeoutMs: 5e3
92
116
  });
117
+ else {
118
+ await this.memoryRoot(body, signal);
119
+ await this.validateUserNamespace(connection, selectedUser, signal);
120
+ }
93
121
  return { healthy: true };
94
122
  } catch (error) {
95
123
  return {
@@ -233,15 +261,32 @@ var OpenVikingProvider = class {
233
261
  apiKey: String(connection.apiKey ?? ""),
234
262
  account: String(connection.account ?? ""),
235
263
  user: String(connection.user ?? ""),
236
- actorPeerId: String(connection.actorPeerId ?? "")
264
+ actorPeerId: String(connection.actorPeerId ?? ""),
265
+ discoveryUser: String(connection.discoveryUser ?? "")
237
266
  };
238
267
  }
268
+ async validateUserNamespace(connection, user, signal) {
269
+ const root = `viking://user/${user}/memories`;
270
+ const query = new URLSearchParams({
271
+ uri: root,
272
+ recursive: "false",
273
+ output: "original"
274
+ });
275
+ const result = await this.requestConnection(connection, `/api/v1/fs/ls?${query}`, {}, { signal });
276
+ if (!Array.isArray(result) || result.some((item) => !string(object(item)?.uri)?.startsWith(`${root}/`))) throw new Error("OpenViking could not validate the selected memory namespace");
277
+ return root;
278
+ }
239
279
  async memoryRoot(body, signal) {
240
280
  signal?.throwIfAborted();
241
281
  const connection = this.connection(body);
242
282
  const root = connection.targetUri.replace(/\/+$/u, "");
243
283
  const match = /^viking:\/\/user(?:\/([^/]+))?\/memories$/u.exec(root);
244
284
  if (match === null || match[1] !== void 0 && !safeUser(match[1])) throw new Error("OpenViking memory URI must be a safe viking://user/<user>/memories root");
285
+ const selectedUser = discoveryUser(connection);
286
+ if (selectedUser !== void 0) {
287
+ if (match[1] !== void 0 && match[1] !== selectedUser || connection.user?.trim() && connection.user.trim() !== selectedUser) throw new Error("OpenViking memory owner must match the configured discovery user");
288
+ return `viking://user/${selectedUser}/memories`;
289
+ }
245
290
  if (match[1] !== void 0) return root;
246
291
  const user = connection.user?.trim() || string(object(await this.request(body, "/api/v1/system/status", {}, { signal }))?.user) || "";
247
292
  if (!safeUser(user)) throw new Error("OpenViking could not resolve the memory owner; configure an explicit user memory URI");
@@ -258,6 +303,7 @@ var OpenVikingProvider = class {
258
303
  }
259
304
  async requestConnection(connection, path, init = {}, options = {}) {
260
305
  options.signal?.throwIfAborted();
306
+ const keyBound = discoveryUser(connection) !== void 0;
261
307
  const controller = new AbortController();
262
308
  const relay = () => controller.abort(options.signal?.reason);
263
309
  options.signal?.addEventListener("abort", relay, { once: true });
@@ -268,8 +314,8 @@ var OpenVikingProvider = class {
268
314
  headers: {
269
315
  "Content-Type": "application/json",
270
316
  ...connection.apiKey === void 0 || connection.apiKey === "" ? {} : { Authorization: `Bearer ${connection.apiKey}` },
271
- ...connection.account === void 0 || connection.account === "" ? {} : { "X-OpenViking-Account": String(connection.account) },
272
- ...connection.user === void 0 || connection.user === "" ? {} : { "X-OpenViking-User": String(connection.user) },
317
+ ...keyBound || connection.account === void 0 || connection.account === "" ? {} : { "X-OpenViking-Account": String(connection.account) },
318
+ ...keyBound || connection.user === void 0 || connection.user === "" ? {} : { "X-OpenViking-User": String(connection.user) },
273
319
  ...connection.actorPeerId === void 0 || connection.actorPeerId === "" ? {} : { "X-OpenViking-Actor-Peer": String(connection.actorPeerId) },
274
320
  ...init.headers
275
321
  },
@@ -298,7 +344,7 @@ const definition = defineMemorySpaceProviderDefinition({
298
344
  kind: "provider",
299
345
  typeId: descriptor.id,
300
346
  packageName: "dsh-mnemon-provider-openviking",
301
- version: "0.5.5",
347
+ version: "0.5.7",
302
348
  label: descriptor.label,
303
349
  icon: descriptor.icon,
304
350
  summary: descriptor.summary,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mnemon-provider-openviking",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
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.8",
37
+ "dsh-mnemon-source-memory-spaces": "^0.5.11",
38
38
  "tsdown": "^0.22.0",
39
39
  "typescript": "^5.9.0",
40
40
  "vitest": "^3.2.0"