@awiki/dsh-plugin 0.3.2 → 0.3.3

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/lib/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import { n as downloadedAttachment } from "./sdk-adapter-C0gdpg1u.mjs";
1
+ import { n as downloadedAttachment } from "./sdk-adapter-CDLTgHJA.mjs";
2
2
  import "@deepseek-ai/cordis";
3
+ import { existsSync } from "node:fs";
3
4
  import { homedir } from "node:os";
4
- import { isAbsolute, join } from "node:path";
5
+ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
5
6
  import z from "@deepseek-ai/schemastery";
6
7
  import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
7
8
  import { SettingsConflictError, settingsNamespace } from "@deepseek-ai/dsh-settings";
@@ -11,6 +12,7 @@ import { createHash, randomUUID } from "node:crypto";
11
12
  import { installModelSelection } from "@deepseek-ai/dsh-agent";
12
13
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
13
14
  import { SessionId } from "@deepseek-ai/dsh-session";
15
+ import { fileURLToPath } from "node:url";
14
16
  //#region lib/types/types.js
15
17
  /** Client-safe AWiki service and Remote data types. */
16
18
  /** Exact browser acknowledgement required before locally signing out. */
@@ -2092,6 +2094,40 @@ var AwikiAgentListener = class {
2092
2094
  }
2093
2095
  };
2094
2096
  //#endregion
2097
+ //#region lib/types/profile-state.js
2098
+ /** Match the profile-name boundary enforced by the DSH launcher. */
2099
+ function assertProfileName(value, source) {
2100
+ if (typeof value !== "string" || value.length === 0 || value.includes("/") || value.includes("\\") || value === "." || value === ".." || value === "node_modules") throw new TypeError(`awiki: ${source} supplied an invalid profile name`);
2101
+ return value;
2102
+ }
2103
+ /**
2104
+ * Resolve the active DSH profile without guessing it from argv or process type.
2105
+ * Desktop's generation-scoped service is authoritative. Ordinary DSH has no
2106
+ * corresponding service, so its Loader root is accepted only when it is the
2107
+ * exact `$DSH_HOME/profiles/<name>` directory.
2108
+ */
2109
+ function resolveAwikiProfileName(ctx, dshHome) {
2110
+ const desktopProfiles = ctx.get("desktopProfiles");
2111
+ if (desktopProfiles !== void 0) return assertProfileName(desktopProfiles.current?.name, "desktopProfiles.current");
2112
+ let profileDir;
2113
+ try {
2114
+ if (ctx.baseUrl === void 0) return void 0;
2115
+ const baseUrl = new URL(ctx.baseUrl);
2116
+ if (baseUrl.protocol !== "file:") return void 0;
2117
+ profileDir = resolve(fileURLToPath(baseUrl));
2118
+ } catch {
2119
+ return;
2120
+ }
2121
+ const profilesDir = resolve(dshHome, "profiles");
2122
+ if (dirname(profileDir) !== profilesDir) return void 0;
2123
+ return assertProfileName(basename(profileDir), "Loader profile directory");
2124
+ }
2125
+ /** Resolve the profile-local default while preserving the legacy fallback. */
2126
+ function resolveAwikiStateRoot(ctx, dshHome) {
2127
+ const profileName = resolveAwikiProfileName(ctx, dshHome);
2128
+ return profileName === void 0 ? join(dshHome, "awiki", "im-core") : join(dshHome, "awiki", profileName, "im-core");
2129
+ }
2130
+ //#endregion
2095
2131
  //#region lib/types/index.js
2096
2132
  /** Unified AWiki identity, messaging, attachment, Remote, and model-tool service. */
2097
2133
  var __runInitializers = function(thisArg, initializers, value) {
@@ -2179,6 +2215,7 @@ const FAILURE_CODES = /* @__PURE__ */ new Set([
2179
2215
  "forbidden",
2180
2216
  "identity-recovery-required",
2181
2217
  "conflict",
2218
+ "state-in-use",
2182
2219
  "rate-limited",
2183
2220
  "group-membership-required",
2184
2221
  "group-identity-stale",
@@ -2208,6 +2245,7 @@ const FAILURE_MESSAGES = {
2208
2245
  "forbidden": "The AWiki operation is not permitted.",
2209
2246
  "identity-recovery-required": "The local AWiki identity must be recovered before it can be used again.",
2210
2247
  "conflict": "The AWiki operation conflicts with current state.",
2248
+ "state-in-use": "AWiki data is already open in another client.",
2211
2249
  "rate-limited": "The AWiki service rate-limited the request.",
2212
2250
  "group-membership-required": "The active AWiki identity is not a member of this group.",
2213
2251
  "group-identity-stale": "The AWiki group identity binding is still recovering.",
@@ -2293,12 +2331,14 @@ function listenerAllowedPeers(raw, enabled) {
2293
2331
  return peers;
2294
2332
  }
2295
2333
  /** Resolve and validate every deployment choice before publishing the service. */
2296
- function resolveConfig(config) {
2334
+ function resolveConfig(ctx, config) {
2297
2335
  const allowInsecureLoopbackForTesting = config.allowInsecureLoopbackForTesting ?? false;
2298
2336
  const configuredStateRoot = config.stateRoot?.trim();
2299
2337
  const configuredDshHome = process.env.DSH_HOME?.trim();
2300
2338
  const dshHome = configuredDshHome === void 0 || configuredDshHome.length === 0 ? join(homedir(), ".dsh") : configuredDshHome;
2301
- const stateRoot = configuredStateRoot === void 0 || configuredStateRoot.length === 0 ? join(dshHome, "awiki", "im-core") : configuredStateRoot;
2339
+ const profileName = configuredStateRoot === void 0 || configuredStateRoot.length === 0 ? resolveAwikiProfileName(ctx, dshHome) : void 0;
2340
+ const stateRoot = configuredStateRoot === void 0 || configuredStateRoot.length === 0 ? resolveAwikiStateRoot(ctx, dshHome) : configuredStateRoot;
2341
+ const legacySharedStateDetected = profileName !== void 0 && existsSync(join(dshHome, "awiki", "im-core"));
2302
2342
  if (!isAbsolute(stateRoot)) throw new TypeError("awiki: stateRoot must be an absolute path");
2303
2343
  const attachmentMaxBytes = config.attachmentMaxBytes ?? 10485760;
2304
2344
  if (!Number.isSafeInteger(attachmentMaxBytes) || attachmentMaxBytes < 1) throw new TypeError("awiki: attachmentMaxBytes must be a positive safe integer");
@@ -2329,6 +2369,10 @@ function resolveConfig(config) {
2329
2369
  attachmentMaxBytes,
2330
2370
  imageAttachmentCacheMaxBytes,
2331
2371
  pollIntervalMs,
2372
+ ...profileName === void 0 ? {} : {
2373
+ profileName,
2374
+ legacySharedStateDetected
2375
+ },
2332
2376
  listenerEnabled,
2333
2377
  listener: {
2334
2378
  allowedPeers,
@@ -3273,7 +3317,7 @@ let AwikiService = (() => {
3273
3317
  constructor(ctx, config) {
3274
3318
  super(ctx, "awiki");
3275
3319
  this.hostContext = ctx;
3276
- this.resolved = resolveConfig(config);
3320
+ this.resolved = resolveConfig(ctx, config);
3277
3321
  this.externalHttpAuth = createAwikiExternalHttpAuth(() => this.acquireExternalHttpAuthSession());
3278
3322
  this.sessionStore = new AwikiSessionStore(this.resolved.stateRoot);
3279
3323
  this.imageAttachmentCache = new AwikiImageAttachmentCache(this.resolved.stateRoot, this.resolved.attachmentMaxBytes, this.resolved.imageAttachmentCacheMaxBytes);
@@ -3381,7 +3425,11 @@ let AwikiService = (() => {
3381
3425
  ok: true,
3382
3426
  value: {
3383
3427
  pollIntervalMs: this.resolved.pollIntervalMs,
3384
- attachmentMaxBytes: this.resolved.attachmentMaxBytes
3428
+ attachmentMaxBytes: this.resolved.attachmentMaxBytes,
3429
+ ...this.resolved.profileName === void 0 ? {} : {
3430
+ profileName: this.resolved.profileName,
3431
+ legacySharedStateDetected: this.resolved.legacySharedStateDetected
3432
+ }
3385
3433
  }
3386
3434
  });
3387
3435
  }
package/lib/provider.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RustSdkAdapter } from "./sdk-adapter-C0gdpg1u.mjs";
1
+ import { t as RustSdkAdapter } from "./sdk-adapter-CDLTgHJA.mjs";
2
2
  import { openImCoreNodeClient } from "@awiki/im-core-node";
3
3
  //#region lib/types/provider.js
4
4
  /** Production AWiki provider backed by the versioned Rust IM Core Node bridge. */
@@ -20,7 +20,7 @@ const RUST_FAILURE_CODES = {
20
20
  auth_revoked: "identity-recovery-required",
21
21
  conflict: "conflict",
22
22
  join_required: "handle-unavailable",
23
- state_in_use: "conflict",
23
+ state_in_use: "state-in-use",
24
24
  rate_limited: "rate-limited",
25
25
  timeout: "network",
26
26
  transport_unavailable: "network",