@vellumai/assistant 0.10.11-dev.202607241933.decb522 → 0.10.11-dev.202607242023.78fd032

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/openapi.yaml CHANGED
@@ -32459,8 +32459,10 @@ components:
32459
32459
  anyOf:
32460
32460
  - type: object
32461
32461
  properties:
32462
- mode:
32463
- $ref: "#/components/schemas/ServiceMode"
32462
+ provider:
32463
+ type: string
32464
+ model:
32465
+ type: string
32464
32466
  additionalProperties: {}
32465
32467
  - type: "null"
32466
32468
  inference:
@@ -33271,8 +33273,10 @@ components:
33271
33273
  image-generation:
33272
33274
  type: object
33273
33275
  properties:
33274
- mode:
33275
- $ref: "#/components/schemas/ServiceMode"
33276
+ provider:
33277
+ type: string
33278
+ model:
33279
+ type: string
33276
33280
  additionalProperties: {}
33277
33281
  inference:
33278
33282
  type: object
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.10.11-dev.202607241933.decb522",
3
+ "version": "0.10.11-dev.202607242023.78fd032",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -102,8 +102,9 @@ const SCHEMA_MANAGED_DEFAULT_SERVICES = [
102
102
  ] as const;
103
103
 
104
104
  // web-search is absent from both lists: it carries no mode at all.
105
+ // image-generation and web-search are absent from both lists: they carry
106
+ // no mode at all.
105
107
  const SCHEMA_YOUR_OWN_DEFAULT_SERVICES = [
106
- "image-generation",
107
108
  "outlook-oauth",
108
109
  "linear-oauth",
109
110
  "github-oauth",
@@ -214,13 +215,16 @@ describe("platform-managed config defaults", () => {
214
215
 
215
216
  const written = readConfig() as { services?: Record<string, unknown> };
216
217
  expect(written.services).toBeDefined();
217
- // The existing value must be preserved — backfill path, not fresh-write path
218
+ // The raw value must be preserved — backfill path, not fresh-write path.
219
+ // (Migration 134 rewrites this legacy shape at daemon startup; the loader
220
+ // itself must simply leave it alone.)
218
221
  expect(
219
222
  (written.services!["image-generation"] as { mode?: string })?.mode,
220
223
  ).toBe("your-own");
221
- // ...and the in-memory config must mirror the explicit user choice (the
222
- // fill-defaults pass must not override an explicit "your-own").
223
- expect(config.services["image-generation"].mode).toBe("your-own");
224
+ // The parsed config strips the legacy key and carries the filled
225
+ // provider; no mode survives the schema.
226
+ expect(config.services["image-generation"]).not.toHaveProperty("mode");
227
+ expect(config.services["image-generation"].provider).toBe("vellum");
224
228
  });
225
229
 
226
230
  test("IS_PLATFORM=true, config file with explicit notion-oauth mode='your-own' → preserved (schema default is 'managed')", () => {
@@ -323,11 +327,11 @@ describe("platform-managed config defaults", () => {
323
327
  const imageGen = (
324
328
  config.services as unknown as Record<
325
329
  string,
326
- { mode: string; provider?: string }
330
+ { mode?: string; provider?: string }
327
331
  >
328
332
  )["image-generation"]!;
329
333
  expect(imageGen.provider).toBe("openai");
330
- expect(imageGen.mode).toBe("your-own");
334
+ expect(imageGen).not.toHaveProperty("mode");
331
335
  });
332
336
 
333
337
  test("IS_PLATFORM=false, config file exists without services key → in-memory config keeps schema defaults (your-own except google/notion-oauth which are managed)", () => {
@@ -430,9 +434,11 @@ describe("GET /v1/config handler — context-default fill on raw response", () =
430
434
  test("IS_PLATFORM=true, raw config has explicit services.image-generation.mode='your-own' → preserved", () => {
431
435
  process.env.IS_PLATFORM = "true";
432
436
 
433
- // User has explicitly chosen "your-own" for image-generation via the macOS
434
- // Save flow. The patch handler persisted that to disk; the fill pass must
435
- // not override an explicit user choice.
437
+ // A legacy raw shape: mode with no provider leaf. Migration 134 rewrites
438
+ // it (pinning provider gemini) before any real request reaches this
439
+ // function, so the fill's only obligation here is to be non-destructive:
440
+ // existing keys pass through untouched, absent leaves get the platform
441
+ // default.
436
442
  const raw: Record<string, unknown> = {
437
443
  services: {
438
444
  "image-generation": { mode: "your-own" },
@@ -443,8 +449,12 @@ describe("GET /v1/config handler — context-default fill on raw response", () =
443
449
  string,
444
450
  unknown
445
451
  >;
446
- const services = result["services"] as Record<string, { mode: string }>;
452
+ const services = result["services"] as Record<
453
+ string,
454
+ { mode?: string; provider?: string }
455
+ >;
447
456
  expect(services["image-generation"]!.mode).toBe("your-own");
457
+ expect(services["image-generation"]!.provider).toBe("vellum");
448
458
  // web-search is not context-filled: a filled `mode` would override BYOK
449
459
  // configs on every load.
450
460
  expect(services["web-search"]).toBeUndefined();
@@ -68,7 +68,7 @@ describe("AssistantConfigSchema", () => {
68
68
  expect(result.services["image-generation"].model).toBe(
69
69
  "gemini-3.1-flash-image-preview",
70
70
  );
71
- expect(result.services["image-generation"].mode).toBe("your-own");
71
+ expect(result.services["image-generation"]).not.toHaveProperty("mode");
72
72
  expect(result.services["web-search"].provider).toBe(
73
73
  "inference-provider-native",
74
74
  );
@@ -174,8 +174,10 @@ describe("config set - platform connection guard for service mode paths", () =>
174
174
  mockIpcResult = { ok: true, result: { ok: true } };
175
175
  });
176
176
 
177
- test("config set services.image-generation.mode your-own - succeeds without platform connection", async () => {
178
- const { exitCode } = await runCli([
177
+ test("config set services.image-generation.mode - rejected with provider guidance, no IPC write emitted", async () => {
178
+ // The image-generation schema has no mode field; a raw write would be
179
+ // stripped at parse while the CLI reported success.
180
+ const { exitCode, stdout } = await runCli([
179
181
  "node",
180
182
  "assistant",
181
183
  "--json",
@@ -185,16 +187,13 @@ describe("config set - platform connection guard for service mode paths", () =>
185
187
  "your-own",
186
188
  ]);
187
189
 
188
- expect(exitCode).toBe(0);
189
- // The CLI should have emitted exactly one config_set IPC call.
190
- const setCalls = mockIpcCalls.filter((c) => c.method === "config_set");
191
- expect(setCalls).toHaveLength(1);
192
- expect(setCalls[0]!.params).toEqual({
193
- body: {
194
- path: "services.image-generation.mode",
195
- value: "your-own",
196
- },
197
- });
190
+ expect(exitCode).toBe(1);
191
+ const parsed = JSON.parse(stdout);
192
+ expect(parsed.ok).toBe(false);
193
+ expect(parsed.error).toContain("services.image-generation.provider vellum");
194
+ expect(mockIpcCalls.filter((c) => c.method === "config_set")).toHaveLength(
195
+ 0,
196
+ );
198
197
  });
199
198
 
200
199
  test("config set calls.enabled true - succeeds without platform connection and parses to boolean", async () => {
@@ -40,7 +40,7 @@ describe("resolveImageGenCredentials", () => {
40
40
 
41
41
  const result = await resolveImageGenCredentials({
42
42
  provider: "gemini",
43
- mode: "managed",
43
+ managed: true,
44
44
  });
45
45
 
46
46
  expect(result.errorHint).toBeUndefined();
@@ -57,7 +57,7 @@ describe("resolveImageGenCredentials", () => {
57
57
 
58
58
  const result = await resolveImageGenCredentials({
59
59
  provider: "gemini",
60
- mode: "managed",
60
+ managed: true,
61
61
  });
62
62
 
63
63
  expect(result.credentials).toBeUndefined();
@@ -71,7 +71,7 @@ describe("resolveImageGenCredentials", () => {
71
71
 
72
72
  const result = await resolveImageGenCredentials({
73
73
  provider: "gemini",
74
- mode: "managed",
74
+ managed: true,
75
75
  });
76
76
 
77
77
  expect(result.credentials).toBeUndefined();
@@ -86,7 +86,7 @@ describe("resolveImageGenCredentials", () => {
86
86
 
87
87
  const result = await resolveImageGenCredentials({
88
88
  provider: "gemini",
89
- mode: "your-own",
89
+ managed: false,
90
90
  });
91
91
 
92
92
  expect(result.errorHint).toBeUndefined();
@@ -101,7 +101,7 @@ describe("resolveImageGenCredentials", () => {
101
101
 
102
102
  const result = await resolveImageGenCredentials({
103
103
  provider: "gemini",
104
- mode: "your-own",
104
+ managed: false,
105
105
  });
106
106
 
107
107
  expect(result.credentials).toBeUndefined();
@@ -114,7 +114,7 @@ describe("resolveImageGenCredentials", () => {
114
114
 
115
115
  const result = await resolveImageGenCredentials({
116
116
  provider: "openai",
117
- mode: "your-own",
117
+ managed: false,
118
118
  });
119
119
 
120
120
  expect(result.errorHint).toBeUndefined();
@@ -129,7 +129,7 @@ describe("resolveImageGenCredentials", () => {
129
129
 
130
130
  const result = await resolveImageGenCredentials({
131
131
  provider: "openai",
132
- mode: "your-own",
132
+ managed: false,
133
133
  });
134
134
 
135
135
  expect(result.credentials).toBeUndefined();
@@ -164,24 +164,10 @@ describe("resolveImageGenRouting", () => {
164
164
  ).toEqual({ backendProvider: "openai", managed: true });
165
165
  });
166
166
 
167
- test("a legacy managed mode routes managed for BYOK providers", () => {
168
- expect(
169
- resolveImageGenRouting({
170
- provider: "gemini",
171
- model: "gemini-3.1-flash-image-preview",
172
- mode: "managed",
173
- }),
174
- ).toEqual({ backendProvider: "gemini", managed: true });
175
- });
176
-
177
167
  test("BYOK providers keep the override re-routing without managed", () => {
178
168
  expect(
179
169
  resolveImageGenRouting(
180
- {
181
- provider: "gemini",
182
- model: "gemini-3.1-flash-image-preview",
183
- mode: "your-own",
184
- },
170
+ { provider: "gemini", model: "gemini-3.1-flash-image-preview" },
185
171
  "gpt-image-2",
186
172
  ),
187
173
  ).toEqual({ backendProvider: "openai", managed: false });
@@ -199,7 +185,7 @@ describe("resolveImageGenRouting", () => {
199
185
  });
200
186
  const result = await resolveImageGenCredentials({
201
187
  provider: routing.backendProvider,
202
- mode: routing.managed ? "managed" : "your-own",
188
+ managed: routing.managed,
203
189
  });
204
190
 
205
191
  expect(result.credentials).toBeUndefined();
@@ -1298,3 +1298,30 @@ describe("code-owned default profiles — echoes over stale on-disk bodies", ()
1298
1298
  expectNothingCommitted();
1299
1299
  });
1300
1300
  });
1301
+
1302
+ // ---------------------------------------------------------------------------
1303
+ // PATCH /v1/config — legacy service-mode scrub
1304
+ // ---------------------------------------------------------------------------
1305
+
1306
+ describe("PATCH /v1/config — provider-only services scrub legacy mode", () => {
1307
+ test("a paired provider+mode write persists without the mode key", async () => {
1308
+ // Web clients pair provider writes with `mode` so their saves stay valid
1309
+ // on daemons whose schemas still carry it; the raw config must not
1310
+ // resurrect the removed field on every save.
1311
+ await patchRoute.handler({
1312
+ body: {
1313
+ services: {
1314
+ "image-generation": { provider: "vellum", mode: "managed" },
1315
+ "web-search": { provider: "vellum", mode: "managed" },
1316
+ },
1317
+ },
1318
+ } as never);
1319
+
1320
+ const raw = committedRaw() as Record<
1321
+ string,
1322
+ Record<string, Record<string, unknown>>
1323
+ >;
1324
+ expect(raw.services["image-generation"]).toEqual({ provider: "vellum" });
1325
+ expect(raw.services["web-search"]).toEqual({ provider: "vellum" });
1326
+ });
1327
+ });
@@ -24,12 +24,11 @@ let lastGenerateCredentials: unknown = null;
24
24
 
25
25
  /**
26
26
  * Seed the image-generation service entry in the real workspace config.
27
- * Omitted fields fall back to the schema defaults (`mode: "your-own"`,
28
- * `provider: "gemini"`, model `gemini-3.1-flash-image-preview`).
27
+ * Omitted fields fall back to the schema defaults (`provider: "gemini"`,
28
+ * model `gemini-3.1-flash-image-preview`).
29
29
  */
30
30
  function seedImageGenService(
31
31
  overrides: {
32
- mode?: "your-own" | "managed";
33
32
  provider?: "vellum" | "gemini" | "openai";
34
33
  model?: string;
35
34
  } = {},
@@ -152,8 +151,8 @@ describe("image-studio skill script wrapper", () => {
152
151
  expect(result.content).toContain("No Gemini API key");
153
152
  });
154
153
 
155
- test("managed mode uses managed proxy credentials", async () => {
156
- seedImageGenService({ mode: "managed" });
154
+ test("provider vellum uses managed proxy credentials", async () => {
155
+ seedImageGenService({ provider: "vellum" });
157
156
  mockManagedBaseUrl = "https://platform.example.com/v1/runtime-proxy/gemini";
158
157
  mockManagedProxyContext = {
159
158
  enabled: true,
@@ -224,8 +223,8 @@ describe("image-studio skill script wrapper", () => {
224
223
  expect(lastGenerateProvider).toBeNull();
225
224
  });
226
225
 
227
- test("managed mode returns error when managed proxy is unavailable", async () => {
228
- seedImageGenService({ mode: "managed" });
226
+ test("provider vellum returns error when managed proxy is unavailable", async () => {
227
+ seedImageGenService({ provider: "vellum" });
229
228
  mockGeminiKey = "direct-key"; // should be ignored in managed mode
230
229
  mockManagedBaseUrl = undefined;
231
230
 
@@ -236,7 +235,7 @@ describe("image-studio skill script wrapper", () => {
236
235
  });
237
236
 
238
237
  test("your-own mode uses direct API key", async () => {
239
- seedImageGenService({ mode: "your-own" });
238
+ seedImageGenService({ provider: "gemini" });
240
239
  mockGeminiKey = "direct-key";
241
240
  mockManagedBaseUrl = "https://platform.example.com/v1/runtime-proxy/gemini";
242
241
  mockManagedProxyContext = {
@@ -417,8 +416,8 @@ describe("image-studio skill script wrapper", () => {
417
416
  );
418
417
  });
419
418
 
420
- test("managed mode credential error includes guidance not to change service config", async () => {
421
- seedImageGenService({ mode: "managed" });
419
+ test("provider vellum credential error includes guidance not to change service config", async () => {
420
+ seedImageGenService({ provider: "vellum" });
422
421
  mockManagedBaseUrl = undefined;
423
422
 
424
423
  const result = await run({ prompt: "a cat" }, fakeContext);
@@ -153,7 +153,6 @@ function makeProvidersConfig(
153
153
  services: {
154
154
  inference: {},
155
155
  "image-generation": {
156
- mode: "your-own",
157
156
  provider: "gemini",
158
157
  model: "gemini-3.1-flash-image-preview",
159
158
  },
@@ -30,9 +30,27 @@ function flattenConfig(
30
30
  return result;
31
31
  }
32
32
 
33
- /** Matches config paths like `services.image-generation.mode`, `services.web-search.mode`, etc. */
33
+ /** Matches config paths like `services.google-oauth.mode` (mode-based services). */
34
34
  const SERVICE_MODE_PATH_RE = /^services\.[^.]+\.mode$/;
35
35
 
36
+ /**
37
+ * Services configured by provider alone: their schemas strip a raw `mode`
38
+ * write, so the CLI rejects it with the provider-based replacement instead
39
+ * of printing success on a no-op.
40
+ */
41
+ const REMOVED_MODE_PATHS: Record<string, string> = {
42
+ "services.web-search.mode":
43
+ "services.web-search.mode does not exist; web search is configured by provider alone. For managed search run `config set services.web-search.provider vellum`.",
44
+ "services.image-generation.mode":
45
+ "services.image-generation.mode does not exist; image generation is configured by provider alone. For managed image generation run `config set services.image-generation.provider vellum`.",
46
+ };
47
+
48
+ /** Provider paths whose "vellum" value requires a platform connection. */
49
+ const VELLUM_PROVIDER_PATHS = new Set([
50
+ "services.web-search.provider",
51
+ "services.image-generation.provider",
52
+ ]);
53
+
36
54
  /**
37
55
  * Fetch the full raw config from the assistant via IPC.
38
56
  * On transport / connection error, prints a helpful message and exits.
@@ -69,13 +87,10 @@ export function registerConfigCommand(program: Command): void {
69
87
  // Web-search has no mode field: the schema strips it, so a write
70
88
  // here would print success while changing nothing. Reject it with
71
89
  // the provider-based replacement instead.
72
- if (key === "services.web-search.mode") {
90
+ const removedModePath = REMOVED_MODE_PATHS[key];
91
+ if (removedModePath) {
73
92
  const { writeOutput } = await import("../output.js");
74
- writeOutput(cmd, {
75
- ok: false,
76
- error:
77
- "services.web-search.mode does not exist; web search is configured by provider alone. For managed search run `config set services.web-search.provider vellum`.",
78
- });
93
+ writeOutput(cmd, { ok: false, error: removedModePath });
79
94
  process.exitCode = 1;
80
95
  return;
81
96
  }
@@ -85,7 +100,7 @@ export function registerConfigCommand(program: Command): void {
85
100
  // web search.
86
101
  const requiresPlatform =
87
102
  (SERVICE_MODE_PATH_RE.test(key) && parsed === "managed") ||
88
- (key === "services.web-search.provider" && parsed === "vellum");
103
+ (VELLUM_PROVIDER_PATHS.has(key) && parsed === "vellum");
89
104
  if (requiresPlatform) {
90
105
  const { requirePlatformConnection } =
91
106
  await import("./oauth/shared.js");
@@ -49,7 +49,7 @@ export async function run(
49
49
  );
50
50
  const { credentials, errorHint } = await resolveImageGenCredentials({
51
51
  provider,
52
- mode: managed ? "managed" : "your-own",
52
+ managed,
53
53
  });
54
54
  if (!credentials) {
55
55
  return {
@@ -4,7 +4,7 @@
4
4
  * Ensures the `services` and service-level objects exist before writing,
5
5
  * so callers don't need to guard against undefined intermediate keys.
6
6
  *
7
- * Example: `setServiceField(raw, "image-generation", "mode", "managed")`
7
+ * Example: `setServiceField(raw, "image-generation", "provider", "vellum")`
8
8
  * produces `raw.services["image-generation"].mode = "managed"`.
9
9
  */
10
10
  export function setServiceField(
@@ -53,7 +53,13 @@ const BaseServiceSchema = z.object({
53
53
  */
54
54
  const InferenceServiceSchema = z.object({});
55
55
 
56
- const ImageGenerationServiceSchema = BaseServiceSchema.extend({
56
+ /**
57
+ * Image generation carries no `mode`: `provider` is the only axis. `"vellum"`
58
+ * generates through the platform runtime proxy for the model-appropriate
59
+ * backend, billed to Vellum credits; `"gemini"`/`"openai"` use the user's
60
+ * key. A `mode` key sent by an older client is stripped at parse.
61
+ */
62
+ const ImageGenerationServiceSchema = z.object({
57
63
  provider: z.enum(VALID_IMAGE_GEN_PROVIDERS).default("gemini"),
58
64
  model: z.string().default(DEFAULT_IMAGE_MODEL),
59
65
  });
@@ -37,7 +37,7 @@ export async function generateAppIcon(
37
37
  const { backendProvider, managed } = resolveImageGenRouting(svc);
38
38
  const { credentials, errorHint } = await resolveImageGenCredentials({
39
39
  provider: backendProvider,
40
- mode: managed ? "managed" : "your-own",
40
+ managed,
41
41
  });
42
42
  if (!credentials) {
43
43
  log.debug(
@@ -15,7 +15,7 @@ export async function generateAvatar(
15
15
  const { backendProvider, managed } = resolveImageGenRouting(svc);
16
16
  const { credentials, errorHint } = await resolveImageGenCredentials({
17
17
  provider: backendProvider,
18
- mode: managed ? "managed" : "your-own",
18
+ managed,
19
19
  });
20
20
 
21
21
  if (!credentials) {
@@ -23,14 +23,13 @@ import { providerForImageModelPrefix, providerForModel } from "./types.js";
23
23
  * proxies. Managed routing never falls back to a stored BYOK key, and a BYOK
24
24
  * provider never falls back to the proxy — billing follows the explicit
25
25
  * provider choice. Other providers use the caller's key, with an explicit
26
- * model override re-routing to the model's backend. A legacy
27
- * `mode: "managed"` also routes managed.
26
+ * model override re-routing to the model's backend.
28
27
  */
29
28
  export function resolveImageGenRouting(
30
- svc: { provider: string; model: string; mode?: string },
29
+ svc: { provider: string; model: string },
31
30
  modelOverride?: unknown,
32
31
  ): { backendProvider: ImageGenProvider; managed: boolean } {
33
- const managed = svc.provider === "vellum" || svc.mode === "managed";
32
+ const managed = svc.provider === "vellum";
34
33
  if (svc.provider === "vellum") {
35
34
  const model =
36
35
  typeof modelOverride === "string" && modelOverride
@@ -50,20 +49,20 @@ export function resolveImageGenRouting(
50
49
  /**
51
50
  * Resolve credentials for an image-generation request.
52
51
  *
53
- * - `mode === "managed"`: returns managed-proxy credentials when the
54
- * platform URL and assistant API key are both configured, otherwise
55
- * returns a hint telling the user to log in or switch modes.
56
- * - `mode === "your-own"`: returns direct credentials when the provider
57
- * API key is present in secure storage (or the env-var fallback),
58
- * otherwise returns a provider-aware hint pointing at Settings.
52
+ * - `managed`: returns managed-proxy credentials when the platform URL and
53
+ * assistant API key are both configured, otherwise a hint telling the
54
+ * user to log in.
55
+ * - otherwise: returns direct credentials when the provider API key is
56
+ * present in secure storage (or the env-var fallback), otherwise a
57
+ * provider-aware hint pointing at Settings.
59
58
  */
60
59
  export async function resolveImageGenCredentials(opts: {
61
60
  provider: ImageGenProvider;
62
- mode: "managed" | "your-own";
61
+ managed: boolean;
63
62
  }): Promise<{ credentials?: ImageGenCredentials; errorHint?: string }> {
64
- const { provider, mode } = opts;
63
+ const { provider, managed } = opts;
65
64
 
66
- if (mode === "managed") {
65
+ if (managed) {
67
66
  // Resolve platform URL + assistant API key from a single snapshot so
68
67
  // baseUrl and assistantApiKey can't diverge if the credential is cleared
69
68
  // between lookups.
@@ -89,7 +88,6 @@ export async function resolveImageGenCredentials(opts: {
89
88
  };
90
89
  }
91
90
 
92
- // mode === "your-own"
93
91
  const apiKey = await getProviderKeyAsync(provider);
94
92
  if (apiKey) {
95
93
  return { credentials: { type: "direct", apiKey } };
@@ -52,7 +52,6 @@ function makeConfig(): ProvidersConfig {
52
52
  services: {
53
53
  inference: {},
54
54
  "image-generation": {
55
- mode: "your-own",
56
55
  provider: "gemini",
57
56
  model: "gemini-3.1-flash-image-preview",
58
57
  },
@@ -0,0 +1,87 @@
1
+ import { Database } from "bun:sqlite";
2
+ import { describe, expect, test } from "bun:test";
3
+
4
+ import { drizzle } from "drizzle-orm/bun-sqlite";
5
+
6
+ import { migrateCreateProviderConnections } from "../../../persistence/migrations/243-provider-connections.js";
7
+ import { migrateProviderConnectionStatusLabel } from "../../../persistence/migrations/244-provider-connection-status-label.js";
8
+ import { migrateProviderConnectionBaseUrlAndModels } from "../../../persistence/migrations/250-provider-connection-base-url-and-models.js";
9
+ import { migrateDropProviderConnectionStatus } from "../../../persistence/migrations/265-drop-provider-connection-status.js";
10
+ import * as schema from "../../../persistence/schema/index.js";
11
+ import { providerConnections } from "../../../persistence/schema/inference.js";
12
+ import { normalizeCredentialRef } from "../../../security/credential-key.js";
13
+ import { createConnection, getConnection } from "../connections.js";
14
+
15
+ function bootDb() {
16
+ const sqlite = new Database(":memory:");
17
+ sqlite.exec("PRAGMA journal_mode=WAL");
18
+ const db = drizzle(sqlite, { schema });
19
+ migrateCreateProviderConnections(db);
20
+ migrateProviderConnectionStatusLabel(db);
21
+ migrateDropProviderConnectionStatus(db);
22
+ migrateProviderConnectionBaseUrlAndModels(db);
23
+ return db;
24
+ }
25
+
26
+ describe("normalizeCredentialRef", () => {
27
+ test("maps the secrets-API wire name to the vault key", () => {
28
+ expect(normalizeCredentialRef("openrouter:api_key")).toBe(
29
+ "credential/openrouter/api_key",
30
+ );
31
+ });
32
+
33
+ test("splits compound service names at the last colon", () => {
34
+ expect(normalizeCredentialRef("integration:google:access_token")).toBe(
35
+ "credential/integration:google/access_token",
36
+ );
37
+ });
38
+
39
+ test("leaves vault keys and other refs untouched", () => {
40
+ expect(normalizeCredentialRef("credential/openrouter/api_key")).toBe(
41
+ "credential/openrouter/api_key",
42
+ );
43
+ expect(normalizeCredentialRef("openrouter")).toBe("openrouter");
44
+ expect(normalizeCredentialRef("openrouter:")).toBe("openrouter:");
45
+ expect(normalizeCredentialRef(":api_key")).toBe(":api_key");
46
+ });
47
+ });
48
+
49
+ describe("connection credential normalization", () => {
50
+ test("createConnection stores the vault-key form for a wire-name credential", () => {
51
+ const db = bootDb();
52
+ const result = createConnection(db, {
53
+ name: "openrouter-conn",
54
+ provider: "openrouter",
55
+ auth: { type: "api_key", credential: "openrouter:api_key" },
56
+ });
57
+ expect(result.ok).toBe(true);
58
+ if (result.ok && result.connection.auth.type === "api_key") {
59
+ expect(result.connection.auth.credential).toBe(
60
+ "credential/openrouter/api_key",
61
+ );
62
+ }
63
+ });
64
+
65
+ test("getConnection heals a stored wire-name credential without a migration", () => {
66
+ const db = bootDb();
67
+ const now = Date.now();
68
+ db.insert(providerConnections)
69
+ .values({
70
+ name: "legacy-openrouter",
71
+ provider: "openrouter",
72
+ auth: JSON.stringify({
73
+ type: "api_key",
74
+ credential: "openrouter:api_key",
75
+ }),
76
+ createdAt: now,
77
+ updatedAt: now,
78
+ })
79
+ .run();
80
+
81
+ const conn = getConnection(db, "legacy-openrouter");
82
+ expect(conn).not.toBeNull();
83
+ if (conn?.auth.type === "api_key") {
84
+ expect(conn.auth.credential).toBe("credential/openrouter/api_key");
85
+ }
86
+ });
87
+ });
@@ -3,6 +3,7 @@ import { z } from "zod";
3
3
 
4
4
  import type { DrizzleDb } from "../../persistence/db-connection.js";
5
5
  import { providerConnections } from "../../persistence/schema/inference.js";
6
+ import { normalizeCredentialRef } from "../../security/credential-key.js";
6
7
  import { getLogger } from "../../util/logger.js";
7
8
  import { clearConnectionProviderCache } from "../registry.js";
8
9
  import {
@@ -29,6 +30,21 @@ const log = getLogger("providers/inference/connections");
29
30
  // Helpers
30
31
  // ---------------------------------------------------------------------------
31
32
 
33
+ /**
34
+ * Parse an auth value (stored JSON or caller input), normalizing any
35
+ * credential reference to the vault-key form. Normalizing on read as well as
36
+ * write heals rows that were stored with the secrets-API wire name (e.g.
37
+ * `openrouter:api_key`) without a migration.
38
+ */
39
+ function parseAuth(raw: unknown): Auth | null {
40
+ const parsed = AuthSchema.safeParse(raw);
41
+ if (!parsed.success) return null;
42
+ const auth = parsed.data;
43
+ return "credential" in auth
44
+ ? { ...auth, credential: normalizeCredentialRef(auth.credential) }
45
+ : auth;
46
+ }
47
+
32
48
  function parseModelsColumn(raw: string | null): ConnectionModel[] | null {
33
49
  if (raw === null || raw === "") return null;
34
50
  try {
@@ -56,14 +72,14 @@ export function listConnections(
56
72
  : db.select().from(providerConnections).all();
57
73
 
58
74
  return rows.flatMap((row) => {
59
- const auth = AuthSchema.safeParse(JSON.parse(row.auth));
60
- if (!auth.success) return [];
75
+ const auth = parseAuth(JSON.parse(row.auth));
76
+ if (!auth) return [];
61
77
  const provider = ConnectionProviderSchema.safeParse(row.provider);
62
78
  if (!provider.success) return [];
63
79
  return [
64
80
  {
65
81
  ...row,
66
- auth: auth.data,
82
+ auth,
67
83
  provider: provider.data,
68
84
  label: row.label ?? null,
69
85
  baseUrl: row.baseUrl ?? null,
@@ -85,13 +101,13 @@ export function getConnection(
85
101
  .get();
86
102
 
87
103
  if (!row) return null;
88
- const auth = AuthSchema.safeParse(JSON.parse(row.auth));
89
- if (!auth.success) return null;
104
+ const auth = parseAuth(JSON.parse(row.auth));
105
+ if (!auth) return null;
90
106
  const provider = ConnectionProviderSchema.safeParse(row.provider);
91
107
  if (!provider.success) return null;
92
108
  return {
93
109
  ...row,
94
- auth: auth.data,
110
+ auth,
95
111
  provider: provider.data,
96
112
  label: row.label ?? null,
97
113
  baseUrl: row.baseUrl ?? null,
@@ -152,8 +168,8 @@ export function createConnection(
152
168
  // Safe cast: VALID_CONNECTION_PROVIDERS.includes() guards above.
153
169
  const provider = input.provider as ConnectionProvider;
154
170
 
155
- const authResult = AuthSchema.safeParse(input.auth);
156
- if (!authResult.success) {
171
+ const auth = parseAuth(input.auth);
172
+ if (!auth) {
157
173
  return { ok: false, error: { code: "invalid_auth" } };
158
174
  }
159
175
 
@@ -182,7 +198,7 @@ export function createConnection(
182
198
  .values({
183
199
  name: input.name,
184
200
  provider,
185
- auth: JSON.stringify(authResult.data),
201
+ auth: JSON.stringify(auth),
186
202
  label,
187
203
  baseUrl,
188
204
  models: models === null ? null : JSON.stringify(models),
@@ -200,7 +216,7 @@ export function createConnection(
200
216
  connection: {
201
217
  name: input.name,
202
218
  provider,
203
- auth: authResult.data,
219
+ auth,
204
220
  label,
205
221
  baseUrl,
206
222
  models,
@@ -223,8 +239,8 @@ export function updateConnection(
223
239
  return { ok: false, error: { code: "not_found" } };
224
240
  }
225
241
 
226
- const authResult = AuthSchema.safeParse(input.auth);
227
- if (!authResult.success) {
242
+ const auth = parseAuth(input.auth);
243
+ if (!auth) {
228
244
  return { ok: false, error: { code: "invalid_auth" } };
229
245
  }
230
246
 
@@ -248,7 +264,7 @@ export function updateConnection(
248
264
  label?: string | null;
249
265
  baseUrl?: string | null;
250
266
  models?: string | null;
251
- } = { auth: JSON.stringify(authResult.data), updatedAt: now };
267
+ } = { auth: JSON.stringify(auth), updatedAt: now };
252
268
  if (input.label !== undefined) setClause.label = input.label;
253
269
  if (input.baseUrl !== undefined) setClause.baseUrl = input.baseUrl;
254
270
  if (input.models !== undefined)
@@ -267,7 +283,7 @@ export function updateConnection(
267
283
  ok: true,
268
284
  connection: {
269
285
  ...existing,
270
- auth: authResult.data,
286
+ auth,
271
287
  label: input.label !== undefined ? input.label : existing.label,
272
288
  baseUrl: nextBaseUrl,
273
289
  models: nextModels,
@@ -75,7 +75,6 @@ export interface ProvidersConfig {
75
75
  services: {
76
76
  inference: Record<string, never>;
77
77
  "image-generation": {
78
- mode: "managed" | "your-own";
79
78
  provider: string;
80
79
  model: string;
81
80
  };
@@ -703,7 +703,10 @@ const ConfigGetResponseSchema = z
703
703
  .passthrough()
704
704
  .optional(),
705
705
  "image-generation": z
706
- .object({ mode: ServiceModeSchema.optional() })
706
+ .object({
707
+ provider: z.string().optional(),
708
+ model: z.string().optional(),
709
+ })
707
710
  .passthrough()
708
711
  .optional(),
709
712
  inference: z
@@ -807,7 +810,10 @@ const ConfigPatchRequestSchema = z
807
810
  .nullable()
808
811
  .optional(),
809
812
  "image-generation": z
810
- .object({ mode: ServiceModeSchema.optional() })
813
+ .object({
814
+ provider: z.string().optional(),
815
+ model: z.string().optional(),
816
+ })
811
817
  .passthrough()
812
818
  .nullable()
813
819
  .optional(),
@@ -1449,6 +1455,28 @@ export async function commitConfigWrite(
1449
1455
  }
1450
1456
  }
1451
1457
 
1458
+ /**
1459
+ * Web clients pair provider writes with a legacy `mode` key so their saves
1460
+ * stay valid on daemons whose schemas still carry it. The provider-only
1461
+ * services (web-search, image-generation) parse-strip that key, but the
1462
+ * deep-merge would still persist it to raw config.json on every save —
1463
+ * scrub it so the removed field cannot be resurrected on disk.
1464
+ */
1465
+ function scrubRemovedServiceModes(raw: Record<string, unknown>): void {
1466
+ const services = raw.services as
1467
+ | Record<string, Record<string, unknown> | undefined>
1468
+ | undefined;
1469
+ if (!services) {
1470
+ return;
1471
+ }
1472
+ for (const key of ["web-search", "image-generation"]) {
1473
+ const entry = services[key];
1474
+ if (entry && typeof entry === "object" && "mode" in entry) {
1475
+ delete entry.mode;
1476
+ }
1477
+ }
1478
+ }
1479
+
1452
1480
  async function handlePatchConfig({ body }: RouteHandlerArgs) {
1453
1481
  if (
1454
1482
  !body ||
@@ -1467,6 +1495,7 @@ async function handlePatchConfig({ body }: RouteHandlerArgs) {
1467
1495
  const patch = body as Record<string, unknown>;
1468
1496
  backfillNewCallSiteEntries(raw, patch);
1469
1497
  deepMergeOverwrite(raw, patch);
1498
+ scrubRemovedServiceModes(raw);
1470
1499
 
1471
1500
  await commitConfigWrite(raw, "patch");
1472
1501
 
@@ -104,7 +104,7 @@ async function handleImageGenerationGenerate(
104
104
  // Resolve credentials
105
105
  const { credentials, errorHint } = await resolveImageGenCredentials({
106
106
  provider,
107
- mode: managed ? "managed" : "your-own",
107
+ managed,
108
108
  });
109
109
 
110
110
  if (!credentials) {
@@ -12,3 +12,20 @@
12
12
  export function credentialKey(service: string, field: string): string {
13
13
  return `credential/${service}/${field}`;
14
14
  }
15
+
16
+ /**
17
+ * Normalize a credential reference to the vault-key form.
18
+ *
19
+ * The secrets API names credentials `{service}:{field}` on the wire (e.g.
20
+ * `openrouter:api_key`), while the vault stores them as
21
+ * `credential/{service}/{field}`. Callers routinely reuse the wire name where
22
+ * a vault key is expected, producing references that never resolve. Map the
23
+ * wire name to the vault key (same lastIndexOf split the secrets routes use);
24
+ * leave anything else untouched.
25
+ */
26
+ export function normalizeCredentialRef(ref: string): string {
27
+ if (ref.startsWith("credential/")) return ref;
28
+ const colonIdx = ref.lastIndexOf(":");
29
+ if (colonIdx < 1 || colonIdx === ref.length - 1) return ref;
30
+ return credentialKey(ref.slice(0, colonIdx), ref.slice(colonIdx + 1));
31
+ }