@vellumai/assistant 0.8.10-dev.202606110112.319a8d3 → 0.8.10-dev.202606110240.ef9212e

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": "@vellumai/assistant",
3
- "version": "0.8.10-dev.202606110112.319a8d3",
3
+ "version": "0.8.10-dev.202606110240.ef9212e",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,4 +1,12 @@
1
- import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
1
+ import {
2
+ existsSync,
3
+ mkdirSync,
4
+ mkdtempSync,
5
+ readdirSync,
6
+ readFileSync,
7
+ rmSync,
8
+ writeFileSync,
9
+ } from "node:fs";
2
10
  import { tmpdir } from "node:os";
3
11
  import { join } from "node:path";
4
12
  import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
@@ -16,11 +24,13 @@ import { getDeviceId, resetDeviceIdCache } from "../util/device-id.js";
16
24
  const originalVellumEnvironment = process.env.VELLUM_ENVIRONMENT;
17
25
  const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
18
26
  const originalIsContainerized = process.env.IS_CONTAINERIZED;
27
+ const originalVellumDeviceId = process.env.VELLUM_DEVICE_ID;
19
28
 
20
29
  let tempDir: string;
21
30
 
22
31
  beforeEach(() => {
23
32
  tempDir = mkdtempSync(join(tmpdir(), "vellum-device-id-test-"));
33
+ delete process.env.VELLUM_DEVICE_ID;
24
34
  resetDeviceIdCache();
25
35
  });
26
36
 
@@ -42,6 +52,11 @@ afterEach(() => {
42
52
  } else {
43
53
  process.env.IS_CONTAINERIZED = originalIsContainerized;
44
54
  }
55
+ if (originalVellumDeviceId == null) {
56
+ delete process.env.VELLUM_DEVICE_ID;
57
+ } else {
58
+ process.env.VELLUM_DEVICE_ID = originalVellumDeviceId;
59
+ }
45
60
 
46
61
  try {
47
62
  rmSync(tempDir, { recursive: true, force: true });
@@ -110,3 +125,57 @@ describe("getDeviceId env-awareness", () => {
110
125
  expect(existsSync(xdgPath)).toBe(false);
111
126
  });
112
127
  });
128
+
129
+ describe("getDeviceId VELLUM_DEVICE_ID precedence", () => {
130
+ beforeEach(() => {
131
+ delete process.env.IS_CONTAINERIZED;
132
+ process.env.VELLUM_ENVIRONMENT = "dev";
133
+ process.env.XDG_CONFIG_HOME = tempDir;
134
+ });
135
+
136
+ test("env var set returns that value without writing device.json", () => {
137
+ process.env.VELLUM_DEVICE_ID = "abc-123";
138
+
139
+ expect(getDeviceId()).toBe("abc-123");
140
+ // Nothing written anywhere under the XDG tempdir.
141
+ expect(readdirSync(tempDir)).toEqual([]);
142
+ });
143
+
144
+ test("env var with surrounding whitespace returns the trimmed value", () => {
145
+ process.env.VELLUM_DEVICE_ID = " abc-123 ";
146
+
147
+ expect(getDeviceId()).toBe("abc-123");
148
+ });
149
+
150
+ test("empty/whitespace-only env var falls through to file resolution", () => {
151
+ process.env.VELLUM_DEVICE_ID = " ";
152
+
153
+ const id = getDeviceId();
154
+ expect(id.length).toBeGreaterThan(0);
155
+ expect(existsSync(join(tempDir, "vellum-dev", "device.json"))).toBe(true);
156
+ });
157
+
158
+ test("env var wins over an existing device.json without overwriting it", () => {
159
+ const dir = join(tempDir, "vellum-dev");
160
+ mkdirSync(dir, { recursive: true });
161
+ const filePath = join(dir, "device.json");
162
+ writeFileSync(filePath, JSON.stringify({ deviceId: "file-id" }));
163
+ process.env.VELLUM_DEVICE_ID = "env-id";
164
+
165
+ expect(getDeviceId()).toBe("env-id");
166
+ expect(JSON.parse(readFileSync(filePath, "utf-8")).deviceId).toBe(
167
+ "file-id",
168
+ );
169
+ });
170
+
171
+ test("env-resolved value stays cached until resetDeviceIdCache", () => {
172
+ process.env.VELLUM_DEVICE_ID = "env-id";
173
+ expect(getDeviceId()).toBe("env-id");
174
+
175
+ delete process.env.VELLUM_DEVICE_ID;
176
+ expect(getDeviceId()).toBe("env-id");
177
+
178
+ resetDeviceIdCache();
179
+ expect(getDeviceId()).not.toBe("env-id");
180
+ });
181
+ });
@@ -83,6 +83,16 @@ export function getDisablePlatform(): boolean {
83
83
  return flag("VELLUM_DISABLE_PLATFORM");
84
84
  }
85
85
 
86
+ /**
87
+ * VELLUM_DEVICE_ID — string, default: undefined
88
+ * Host-stable device id injected by the CLI into containerized deployments,
89
+ * where the container fs cannot persist device.json across recreation.
90
+ * Takes precedence over device.json resolution in util/device-id.ts.
91
+ */
92
+ export function getDeviceIdOverride(): string | undefined {
93
+ return str("VELLUM_DEVICE_ID");
94
+ }
95
+
86
96
  /**
87
97
  * VELLUM_WORKSPACE_DIR — string, default: undefined
88
98
  * Overrides the default workspace directory.
@@ -202,6 +212,7 @@ const KNOWN_VELLUM_VARS = new Set([
202
212
  "VELLUM_DEBUG",
203
213
  "VELLUM_DESKTOP_APP",
204
214
  "VELLUM_DEV",
215
+ "VELLUM_DEVICE_ID",
205
216
  "VELLUM_DISABLE_PLATFORM",
206
217
  "VELLUM_DOCS_BASE_URL",
207
218
  "VELLUM_ENVIRONMENT",
@@ -29,6 +29,7 @@ export const SAFE_ENV_VARS = [
29
29
  "GNUPGHOME",
30
30
  "VELLUM_DEV",
31
31
  "VELLUM_DEBUG",
32
+ "VELLUM_DEVICE_ID",
32
33
  "VELLUM_DISABLE_PLATFORM",
33
34
  "VELLUM_ENVIRONMENT",
34
35
 
@@ -6,6 +6,9 @@
6
6
  * extensible for future per-device metadata.
7
7
  *
8
8
  * Path resolution:
9
+ * - All modes: the `VELLUM_DEVICE_ID` env var takes precedence when set
10
+ * and is never written to device.json (see getDeviceIdOverride in
11
+ * config/env-registry.ts).
9
12
  * - Containerized (IS_CONTAINERIZED=true): `/home/assistant/.vellum/device.json`
10
13
  * — the assistant user's persistent home dir, kept off the shared data
11
14
  * volume. Not affected by VELLUM_ENVIRONMENT because the container fs
@@ -24,7 +27,10 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
24
27
  import { homedir } from "node:os";
25
28
  import { join } from "node:path";
26
29
 
27
- import { getIsContainerized } from "../config/env-registry.js";
30
+ import {
31
+ getDeviceIdOverride,
32
+ getIsContainerized,
33
+ } from "../config/env-registry.js";
28
34
  import { getLogger } from "./logger.js";
29
35
  import { getXdgVellumConfigDirName } from "./platform.js";
30
36
 
@@ -66,8 +72,9 @@ function resolveDeviceIdPaths(): { dir: string; file: string } {
66
72
  *
67
73
  * Resolution order:
68
74
  * 1. Cached in-memory value (populated on first call)
69
- * 2. `deviceId` field from device.json
70
- * 3. Generate a new UUID, persist it to device.json, and return it
75
+ * 2. `VELLUM_DEVICE_ID` env var (CLI-injected; see env-registry)
76
+ * 3. `deviceId` field from device.json
77
+ * 4. Generate a new UUID, persist it to device.json, and return it
71
78
  *
72
79
  * On any read/write error the generated UUID is still cached so the
73
80
  * process uses a consistent ID for the remainder of its lifetime.
@@ -77,6 +84,13 @@ export function getDeviceId(): string {
77
84
  return cached;
78
85
  }
79
86
 
87
+ const fromEnv = getDeviceIdOverride();
88
+ if (fromEnv) {
89
+ cached = fromEnv;
90
+ log.info({ deviceId: cached }, "Resolved device ID from VELLUM_DEVICE_ID");
91
+ return cached;
92
+ }
93
+
80
94
  const { dir: vellumDir, file: filePath } = resolveDeviceIdPaths();
81
95
  const generated = randomUUID();
82
96