@vellumai/assistant 0.11.4-dev.202608190416.3aa24ff → 0.11.4-dev.202608191511.29bfca9
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 +1 -1
- package/src/__tests__/openai-provider.test.ts +22 -0
- package/src/cli/commands/__tests__/inference-providers.test.ts +68 -0
- package/src/cli/commands/inference-providers.ts +9 -4
- package/src/cli/commands/inference.help.ts +9 -4
- package/src/config/feature-flag-registry.json +0 -8
- package/src/messaging/providers/slack/render-transcript.ts +1 -4
- package/src/providers/inference/__tests__/adapter-factory-ollama.test.ts +83 -0
- package/src/providers/inference/__tests__/base-url-route-validation.test.ts +38 -0
- package/src/providers/inference/__tests__/base-url-security.test.ts +10 -0
- package/src/providers/inference/__tests__/connections-ollama.test.ts +90 -0
- package/src/providers/inference/adapter-factory.ts +2 -1
- package/src/providers/inference/auth.ts +13 -2
- package/src/providers/inference/resolve-auth.ts +7 -7
- package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +52 -1
- package/src/runtime/routes/inference-provider-connection-routes.ts +9 -7
- package/src/tools/network/__tests__/web-search.test.ts +41 -1
- package/src/tools/network/web-search.ts +21 -3
package/package.json
CHANGED
|
@@ -348,6 +348,28 @@ describe("OpenAIProvider", () => {
|
|
|
348
348
|
}
|
|
349
349
|
});
|
|
350
350
|
|
|
351
|
+
test("ollama wrapper prefers an explicit baseURL over OLLAMA_BASE_URL", () => {
|
|
352
|
+
const previousBaseUrl = process.env.OLLAMA_BASE_URL;
|
|
353
|
+
try {
|
|
354
|
+
process.env.OLLAMA_BASE_URL = "http://127.0.0.1:11434/v1";
|
|
355
|
+
const ollama = new OllamaProvider("llama3.2", {
|
|
356
|
+
baseURL: "http://192.168.1.50:11434/v1",
|
|
357
|
+
});
|
|
358
|
+
expect(ollama.name).toBe("ollama");
|
|
359
|
+
expectOpenAIConstructorOptions({
|
|
360
|
+
apiKey: "ollama",
|
|
361
|
+
baseURL: "http://192.168.1.50:11434/v1",
|
|
362
|
+
timeout: DEFAULT_SDK_TIMEOUT_MS,
|
|
363
|
+
});
|
|
364
|
+
} finally {
|
|
365
|
+
if (previousBaseUrl !== undefined) {
|
|
366
|
+
process.env.OLLAMA_BASE_URL = previousBaseUrl;
|
|
367
|
+
} else {
|
|
368
|
+
delete process.env.OLLAMA_BASE_URL;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
|
|
351
373
|
test("ollama wrapper treats empty OLLAMA_BASE_URL as unset", () => {
|
|
352
374
|
const previousBaseUrl = process.env.OLLAMA_BASE_URL;
|
|
353
375
|
try {
|
|
@@ -120,6 +120,24 @@ describe("providers create — derived auth", () => {
|
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
+
test("forwards optional --base-url for ollama create", async () => {
|
|
124
|
+
await run([
|
|
125
|
+
"providers",
|
|
126
|
+
"create",
|
|
127
|
+
"ollama-home",
|
|
128
|
+
"--provider",
|
|
129
|
+
"ollama",
|
|
130
|
+
"--base-url",
|
|
131
|
+
"http://192.168.1.50:11434/v1",
|
|
132
|
+
]);
|
|
133
|
+
expect(lastIpcCall()?.params?.body).toEqual({
|
|
134
|
+
name: "ollama-home",
|
|
135
|
+
provider: "ollama",
|
|
136
|
+
auth: { type: "none" },
|
|
137
|
+
base_url: "http://192.168.1.50:11434/v1",
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
123
141
|
test("rejects a keyed provider without --credential before calling the daemon", async () => {
|
|
124
142
|
const { exitCode } = await run([
|
|
125
143
|
"providers",
|
|
@@ -332,6 +350,56 @@ describe("providers update", () => {
|
|
|
332
350
|
base_url: "http://localhost:5678/v1",
|
|
333
351
|
});
|
|
334
352
|
});
|
|
353
|
+
|
|
354
|
+
test("ollama update forwards --base-url after GET", async () => {
|
|
355
|
+
mockIpcResult = {
|
|
356
|
+
ok: true,
|
|
357
|
+
result: {
|
|
358
|
+
...CONNECTION_RESULT,
|
|
359
|
+
name: "ollama",
|
|
360
|
+
provider: "ollama",
|
|
361
|
+
auth: { type: "none" },
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
await run([
|
|
365
|
+
"providers",
|
|
366
|
+
"update",
|
|
367
|
+
"ollama",
|
|
368
|
+
"--base-url",
|
|
369
|
+
"http://192.168.1.50:11434/v1",
|
|
370
|
+
]);
|
|
371
|
+
expect(ipcCalls.map((c) => c.method)).toEqual([
|
|
372
|
+
"inference_provider_connections_get",
|
|
373
|
+
"inference_provider_connections_update",
|
|
374
|
+
]);
|
|
375
|
+
expect(lastIpcCall()?.params).toEqual({
|
|
376
|
+
pathParams: { name: "ollama" },
|
|
377
|
+
body: {
|
|
378
|
+
auth: { type: "none" },
|
|
379
|
+
base_url: "http://192.168.1.50:11434/v1",
|
|
380
|
+
},
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
describe("providers get output", () => {
|
|
386
|
+
test("prints base_url when the connection stores one", async () => {
|
|
387
|
+
mockIpcResult = {
|
|
388
|
+
ok: true,
|
|
389
|
+
result: {
|
|
390
|
+
name: "ollama",
|
|
391
|
+
provider: "ollama",
|
|
392
|
+
auth: { type: "none" },
|
|
393
|
+
baseUrl: "http://192.168.1.50:11434/v1",
|
|
394
|
+
createdAt: 0,
|
|
395
|
+
updatedAt: 0,
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
const { stdout } = await run(["providers", "get", "ollama"]);
|
|
399
|
+
expect(stdout).toContain("name: ollama");
|
|
400
|
+
expect(stdout).toContain("provider: ollama");
|
|
401
|
+
expect(stdout).toContain("base_url: http://192.168.1.50:11434/v1");
|
|
402
|
+
});
|
|
335
403
|
});
|
|
336
404
|
|
|
337
405
|
describe("providers list output", () => {
|
|
@@ -38,6 +38,7 @@ interface ProviderConnection {
|
|
|
38
38
|
name: string;
|
|
39
39
|
provider: string;
|
|
40
40
|
auth: AuthInfo;
|
|
41
|
+
baseUrl?: string | null;
|
|
41
42
|
createdAt: string;
|
|
42
43
|
updatedAt: string;
|
|
43
44
|
}
|
|
@@ -129,10 +130,11 @@ function collectRepeatable(value: string, previous: string[]): string[] {
|
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
/**
|
|
132
|
-
* Build the
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
133
|
+
* Build the custom-provider fields (`base_url`, `models`) from CLI flags,
|
|
134
|
+
* forwarded to the connection route under its exact field names. The daemon
|
|
135
|
+
* stays authoritative on whether they are required or allowed (openai-compatible
|
|
136
|
+
* requires both; ollama accepts an optional base URL); the CLI only
|
|
137
|
+
* shape-forwards what the user passed.
|
|
136
138
|
*/
|
|
137
139
|
function buildCustomProviderFields(opts: {
|
|
138
140
|
baseUrl?: string;
|
|
@@ -219,6 +221,9 @@ function attachGetSubcommand(parent: Command): void {
|
|
|
219
221
|
process.stdout.write(`name: ${conn.name}\n`);
|
|
220
222
|
process.stdout.write(`provider: ${conn.provider}\n`);
|
|
221
223
|
process.stdout.write(`auth: ${formatAuth(conn.auth)}\n`);
|
|
224
|
+
if (conn.baseUrl) {
|
|
225
|
+
process.stdout.write(`base_url: ${conn.baseUrl}\n`);
|
|
226
|
+
}
|
|
222
227
|
process.stdout.write(
|
|
223
228
|
`created: ${new Date(conn.createdAt).toISOString()}\n`,
|
|
224
229
|
);
|
|
@@ -218,8 +218,12 @@ Examples:
|
|
|
218
218
|
$ assistant inference providers create local-llm \\
|
|
219
219
|
--provider openai-compatible \\
|
|
220
220
|
--base-url http://localhost:1234/v1 --model my-model
|
|
221
|
+
$ assistant inference providers create ollama-home \\
|
|
222
|
+
--provider ollama --base-url http://192.168.1.50:11434/v1
|
|
221
223
|
$ assistant inference providers update anthropic-personal \\
|
|
222
224
|
--credential credential/anthropic/api_key
|
|
225
|
+
$ assistant inference providers update ollama \\
|
|
226
|
+
--base-url http://127.0.0.1:11434/v1
|
|
223
227
|
$ assistant inference providers delete anthropic-personal
|
|
224
228
|
|
|
225
229
|
After creating or updating a provider, validate it with a live call through
|
|
@@ -268,7 +272,7 @@ a profile that uses it:
|
|
|
268
272
|
{
|
|
269
273
|
flags: "--base-url <url>",
|
|
270
274
|
description:
|
|
271
|
-
"Endpoint base URL (required for
|
|
275
|
+
"Endpoint base URL (required for openai-compatible; optional for ollama)",
|
|
272
276
|
},
|
|
273
277
|
],
|
|
274
278
|
},
|
|
@@ -290,7 +294,8 @@ a profile that uses it:
|
|
|
290
294
|
},
|
|
291
295
|
{
|
|
292
296
|
flags: "--base-url <url>",
|
|
293
|
-
description:
|
|
297
|
+
description:
|
|
298
|
+
"Endpoint base URL (openai-compatible or ollama)",
|
|
294
299
|
},
|
|
295
300
|
],
|
|
296
301
|
},
|
|
@@ -345,7 +350,7 @@ matching \`assistant inference providers <verb>\` command.`,
|
|
|
345
350
|
{
|
|
346
351
|
flags: "--base-url <url>",
|
|
347
352
|
description:
|
|
348
|
-
"Endpoint base URL (required for
|
|
353
|
+
"Endpoint base URL (required for openai-compatible; optional for ollama)",
|
|
349
354
|
},
|
|
350
355
|
],
|
|
351
356
|
},
|
|
@@ -367,7 +372,7 @@ matching \`assistant inference providers <verb>\` command.`,
|
|
|
367
372
|
{
|
|
368
373
|
flags: "--base-url <url>",
|
|
369
374
|
description:
|
|
370
|
-
"Endpoint base URL (openai-compatible
|
|
375
|
+
"Endpoint base URL (openai-compatible or ollama)",
|
|
371
376
|
},
|
|
372
377
|
],
|
|
373
378
|
},
|
|
@@ -108,14 +108,6 @@
|
|
|
108
108
|
"description": "Auto-expand completed tool call step groups instead of showing them collapsed",
|
|
109
109
|
"defaultEnabled": false
|
|
110
110
|
},
|
|
111
|
-
{
|
|
112
|
-
"id": "collapse-assistant-intermediates",
|
|
113
|
-
"scope": "client",
|
|
114
|
-
"key": "collapse-assistant-intermediates",
|
|
115
|
-
"label": "Collapse Assistant Intermediates",
|
|
116
|
-
"description": "Collapse completed intermediary assistant activity behind Earlier activity while keeping the final response visible",
|
|
117
|
-
"defaultEnabled": false
|
|
118
|
-
},
|
|
119
111
|
{
|
|
120
112
|
"id": "backward-releases",
|
|
121
113
|
"scope": "assistant",
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* `{role, content}[]` chronologically ordered with compact Slack tags so the
|
|
7
7
|
* model can reason across sibling threads in one channel.
|
|
8
8
|
*
|
|
9
|
-
* The function is pure: no I/O, no implicit clock reads.
|
|
10
|
-
* `opts.now` only when needed for relative formatting. Sort and tag rendering
|
|
9
|
+
* The function is pure: no I/O, no implicit clock reads. Sort and tag rendering
|
|
11
10
|
* are deterministic.
|
|
12
11
|
*
|
|
13
12
|
* Consumers wire this into inbound history rendering and the compaction
|
|
@@ -63,8 +62,6 @@ export interface RenderableSlackMessage {
|
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
export interface RenderOptions {
|
|
66
|
-
/** Reserved for future relative-time rendering; currently unused. */
|
|
67
|
-
now?: Date;
|
|
68
65
|
/** Cap rendered reactions per parent message; default 5. */
|
|
69
66
|
maxReactionsPerMessage?: number;
|
|
70
67
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { OllamaProvider } from "../../ollama/client.js";
|
|
4
|
+
import {
|
|
5
|
+
buildProviderAdapter,
|
|
6
|
+
createAdapterFromConnection,
|
|
7
|
+
} from "../adapter-factory.js";
|
|
8
|
+
import type { ProviderConnection, ResolvedAuth } from "../auth.js";
|
|
9
|
+
|
|
10
|
+
interface RetryOptions {
|
|
11
|
+
credentialSource?: string;
|
|
12
|
+
connectionName?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function retryOptions(adapter: unknown): RetryOptions {
|
|
16
|
+
let node = adapter;
|
|
17
|
+
for (let depth = 0; node && depth < 8; depth++) {
|
|
18
|
+
const { options, inner } = node as {
|
|
19
|
+
options?: RetryOptions;
|
|
20
|
+
inner?: unknown;
|
|
21
|
+
};
|
|
22
|
+
if (options) {
|
|
23
|
+
return options;
|
|
24
|
+
}
|
|
25
|
+
node = inner;
|
|
26
|
+
}
|
|
27
|
+
throw new Error("no RetryProvider found in the adapter wrapper chain");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function innermostAdapter(adapter: unknown): unknown {
|
|
31
|
+
let node = adapter;
|
|
32
|
+
for (let depth = 0; node && depth < 8; depth++) {
|
|
33
|
+
const inner = (node as { inner?: unknown }).inner;
|
|
34
|
+
if (!inner) {
|
|
35
|
+
return node;
|
|
36
|
+
}
|
|
37
|
+
node = inner;
|
|
38
|
+
}
|
|
39
|
+
throw new Error("wrapper chain too deep");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe("adapter factory ollama", () => {
|
|
43
|
+
test("buildProviderAdapter returns an OllamaProvider", () => {
|
|
44
|
+
const adapter = buildProviderAdapter("ollama", {
|
|
45
|
+
apiKey: "",
|
|
46
|
+
model: "llama3.2",
|
|
47
|
+
streamTimeoutMs: 60_000,
|
|
48
|
+
baseURL: "http://192.168.1.50:11434/v1",
|
|
49
|
+
useNativeWebSearch: false,
|
|
50
|
+
});
|
|
51
|
+
expect(adapter).toBeInstanceOf(OllamaProvider);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("createAdapterFromConnection accepts keyless ollama with a stored baseUrl", () => {
|
|
55
|
+
const connection: ProviderConnection = {
|
|
56
|
+
name: "ollama",
|
|
57
|
+
provider: "ollama",
|
|
58
|
+
auth: { type: "none" },
|
|
59
|
+
label: null,
|
|
60
|
+
baseUrl: "http://192.168.1.50:11434/v1",
|
|
61
|
+
models: null,
|
|
62
|
+
createdAt: Date.now(),
|
|
63
|
+
updatedAt: Date.now(),
|
|
64
|
+
isManaged: false,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const resolvedAuth: ResolvedAuth = {
|
|
68
|
+
kind: "none",
|
|
69
|
+
baseUrl: "http://192.168.1.50:11434/v1",
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const adapter = createAdapterFromConnection(connection, resolvedAuth, {
|
|
73
|
+
model: "llama3.2",
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(adapter).not.toBeNull();
|
|
77
|
+
expect(innermostAdapter(adapter)).toBeInstanceOf(OllamaProvider);
|
|
78
|
+
expect(retryOptions(adapter)).toMatchObject({
|
|
79
|
+
credentialSource: "no-auth",
|
|
80
|
+
connectionName: "ollama",
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -184,6 +184,22 @@ describe("base_url provider-type gate (create)", () => {
|
|
|
184
184
|
);
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
+
test("accepts base_url on ollama provider", async () => {
|
|
188
|
+
mockResolvedAddresses = ["93.184.216.34"];
|
|
189
|
+
const result = await handleCreate({
|
|
190
|
+
body: {
|
|
191
|
+
name: "valid-ollama-remote",
|
|
192
|
+
provider: "ollama",
|
|
193
|
+
auth: { type: "none" },
|
|
194
|
+
base_url: "https://ollama.example.com/v1",
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
expect(result).toBeDefined();
|
|
198
|
+
expect((result as { baseUrl: string }).baseUrl).toBe(
|
|
199
|
+
"https://ollama.example.com/v1",
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
|
|
187
203
|
test("allows null base_url on non-openai-compatible provider", async () => {
|
|
188
204
|
// Setting base_url to null is always allowed (it's a no-op clear).
|
|
189
205
|
const result = await handleCreate({
|
|
@@ -433,4 +449,26 @@ describe("base_url provider-type gate (update)", () => {
|
|
|
433
449
|
}),
|
|
434
450
|
).rejects.toThrow(/base_url is only valid for openai-compatible/);
|
|
435
451
|
});
|
|
452
|
+
|
|
453
|
+
test("accepts adding base_url to an existing ollama connection", async () => {
|
|
454
|
+
mockResolvedAddresses = ["93.184.216.34"];
|
|
455
|
+
await handleCreate({
|
|
456
|
+
body: {
|
|
457
|
+
name: "update-test-ollama",
|
|
458
|
+
provider: "ollama",
|
|
459
|
+
auth: { type: "none" },
|
|
460
|
+
},
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
const result = await handleUpdate({
|
|
464
|
+
pathParams: { name: "update-test-ollama" },
|
|
465
|
+
body: {
|
|
466
|
+
auth: { type: "none" },
|
|
467
|
+
base_url: "https://ollama.example.com/v1",
|
|
468
|
+
},
|
|
469
|
+
});
|
|
470
|
+
expect((result as { baseUrl: string }).baseUrl).toBe(
|
|
471
|
+
"https://ollama.example.com/v1",
|
|
472
|
+
);
|
|
473
|
+
});
|
|
436
474
|
});
|
|
@@ -174,6 +174,16 @@ describe("resolveAuth defense-in-depth", () => {
|
|
|
174
174
|
}
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
+
test("preserves baseUrl for ollama none-auth", async () => {
|
|
178
|
+
const result = await resolveAuth({ type: "none" }, "ollama", {
|
|
179
|
+
baseUrl: "http://192.168.1.50:11434/v1",
|
|
180
|
+
});
|
|
181
|
+
expect(result.ok).toBe(true);
|
|
182
|
+
if (result.ok && result.resolved.kind === "none") {
|
|
183
|
+
expect(result.resolved.baseUrl).toBe("http://192.168.1.50:11434/v1");
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
177
187
|
test("handles null baseUrl gracefully for any provider", async () => {
|
|
178
188
|
const result = await resolveAuth(
|
|
179
189
|
{ type: "api_key", credential: "cred-test" },
|
|
@@ -0,0 +1,90 @@
|
|
|
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 * as schema from "../../../persistence/schema/index.js";
|
|
10
|
+
import {
|
|
11
|
+
createConnection,
|
|
12
|
+
getConnection,
|
|
13
|
+
updateConnection,
|
|
14
|
+
} from "../connections.js";
|
|
15
|
+
|
|
16
|
+
function createTestDb() {
|
|
17
|
+
const sqlite = new Database(":memory:");
|
|
18
|
+
sqlite.exec("PRAGMA journal_mode=WAL");
|
|
19
|
+
return drizzle(sqlite, { schema });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function bootDb() {
|
|
23
|
+
const db = createTestDb();
|
|
24
|
+
migrateCreateProviderConnections(db);
|
|
25
|
+
migrateProviderConnectionStatusLabel(db);
|
|
26
|
+
migrateProviderConnectionBaseUrlAndModels(db);
|
|
27
|
+
return db;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe("ollama connection CRUD", () => {
|
|
31
|
+
test("create without baseUrl leaves it null and does not require models", () => {
|
|
32
|
+
const db = bootDb();
|
|
33
|
+
const result = createConnection(db, {
|
|
34
|
+
name: "ollama-local",
|
|
35
|
+
provider: "ollama",
|
|
36
|
+
auth: { type: "none" },
|
|
37
|
+
});
|
|
38
|
+
expect(result.ok).toBe(true);
|
|
39
|
+
if (result.ok) {
|
|
40
|
+
expect(result.connection.baseUrl).toBeNull();
|
|
41
|
+
expect(result.connection.models).toBeNull();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("create persists an optional baseUrl", () => {
|
|
46
|
+
const db = bootDb();
|
|
47
|
+
const result = createConnection(db, {
|
|
48
|
+
name: "ollama-remote",
|
|
49
|
+
provider: "ollama",
|
|
50
|
+
auth: { type: "none" },
|
|
51
|
+
baseUrl: "http://192.168.1.50:11434/v1",
|
|
52
|
+
});
|
|
53
|
+
expect(result.ok).toBe(true);
|
|
54
|
+
if (result.ok) {
|
|
55
|
+
expect(result.connection.baseUrl).toBe("http://192.168.1.50:11434/v1");
|
|
56
|
+
expect(result.connection.models).toBeNull();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const fetched = getConnection(db, "ollama-remote");
|
|
60
|
+
expect(fetched).not.toBeNull();
|
|
61
|
+
expect(fetched!.baseUrl).toBe("http://192.168.1.50:11434/v1");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("update can change and then clear baseUrl", () => {
|
|
65
|
+
const db = bootDb();
|
|
66
|
+
createConnection(db, {
|
|
67
|
+
name: "ollama-local",
|
|
68
|
+
provider: "ollama",
|
|
69
|
+
auth: { type: "none" },
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const updated = updateConnection(db, "ollama-local", {
|
|
73
|
+
auth: { type: "none" },
|
|
74
|
+
baseUrl: "http://127.0.0.1:11434/v1",
|
|
75
|
+
});
|
|
76
|
+
expect(updated.ok).toBe(true);
|
|
77
|
+
if (updated.ok) {
|
|
78
|
+
expect(updated.connection.baseUrl).toBe("http://127.0.0.1:11434/v1");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const cleared = updateConnection(db, "ollama-local", {
|
|
82
|
+
auth: { type: "none" },
|
|
83
|
+
baseUrl: null,
|
|
84
|
+
});
|
|
85
|
+
expect(cleared.ok).toBe(true);
|
|
86
|
+
if (cleared.ok) {
|
|
87
|
+
expect(cleared.connection.baseUrl).toBeNull();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -96,12 +96,13 @@ const ADAPTER_FACTORIES: Record<string, AdapterFactory> = {
|
|
|
96
96
|
// Gemini routes managed proxies through `managedBaseUrl`, not `baseURL`.
|
|
97
97
|
...(baseURL ? { managedBaseUrl: baseURL } : {}),
|
|
98
98
|
}),
|
|
99
|
-
ollama: ({ apiKey, model, streamTimeoutMs }) =>
|
|
99
|
+
ollama: ({ apiKey, model, streamTimeoutMs, baseURL }) =>
|
|
100
100
|
new OllamaProvider(model, {
|
|
101
101
|
// Empty string means keyless — Ollama's client treats undefined as
|
|
102
102
|
// "no key provided" and defaults its internal placeholder.
|
|
103
103
|
apiKey: apiKey || undefined,
|
|
104
104
|
streamTimeoutMs,
|
|
105
|
+
...(baseURL ? { baseURL } : {}),
|
|
105
106
|
}),
|
|
106
107
|
fireworks: ({ apiKey, model, streamTimeoutMs, baseURL }) =>
|
|
107
108
|
new FireworksProvider(apiKey, model, {
|
|
@@ -175,12 +175,23 @@ export type ConnectionModel = z.infer<typeof ConnectionModelSchema>;
|
|
|
175
175
|
/**
|
|
176
176
|
* Providers whose connections require an explicit `baseUrl` and non-empty
|
|
177
177
|
* `models` list (openai-compatible endpoints have no fixed upstream, so the
|
|
178
|
-
* user must supply both).
|
|
179
|
-
* entry and rejects a client-supplied `baseUrl`.
|
|
178
|
+
* user must supply both).
|
|
180
179
|
*/
|
|
181
180
|
export const PROVIDERS_REQUIRING_BASE_URL_AND_MODELS: ReadonlySet<string> =
|
|
182
181
|
new Set(["openai-compatible"]);
|
|
183
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Providers that persist a client-supplied `baseUrl`. openai-compatible
|
|
185
|
+
* requires one (see above); ollama has a well-known local default and treats
|
|
186
|
+
* a stored URL as an optional override. Every other provider derives its
|
|
187
|
+
* upstream from the catalog and rejects a client-supplied `baseUrl` so a
|
|
188
|
+
* keyed connection cannot be pointed at an attacker-controlled host.
|
|
189
|
+
*/
|
|
190
|
+
export const PROVIDERS_ALLOWING_CUSTOM_BASE_URL: ReadonlySet<string> = new Set([
|
|
191
|
+
...PROVIDERS_REQUIRING_BASE_URL_AND_MODELS,
|
|
192
|
+
"ollama",
|
|
193
|
+
]);
|
|
194
|
+
|
|
184
195
|
// ---------------------------------------------------------------------------
|
|
185
196
|
// Full connection shape used by CRUD layer
|
|
186
197
|
// ---------------------------------------------------------------------------
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from "../platform-proxy/context.js";
|
|
18
18
|
import {
|
|
19
19
|
type Auth,
|
|
20
|
-
|
|
20
|
+
PROVIDERS_ALLOWING_CUSTOM_BASE_URL,
|
|
21
21
|
type ResolvedAuth,
|
|
22
22
|
} from "./auth.js";
|
|
23
23
|
|
|
@@ -36,14 +36,14 @@ export async function resolveAuth(
|
|
|
36
36
|
{ ok: true; resolved: ResolvedAuth } | { ok: false; error: ResolveAuthError }
|
|
37
37
|
> {
|
|
38
38
|
// Defense-in-depth: strip baseUrl for providers that should not accept one.
|
|
39
|
-
// The route layer rejects base_url for
|
|
40
|
-
//
|
|
41
|
-
//
|
|
39
|
+
// The route layer rejects base_url for those providers, but this guard
|
|
40
|
+
// catches any code path that bypasses route validation (e.g. corrupted DB
|
|
41
|
+
// rows, direct calls from internal code).
|
|
42
42
|
let safeBaseUrl = opts.baseUrl;
|
|
43
|
-
if (safeBaseUrl && !
|
|
43
|
+
if (safeBaseUrl && !PROVIDERS_ALLOWING_CUSTOM_BASE_URL.has(provider)) {
|
|
44
44
|
log.warn(
|
|
45
45
|
{ provider, baseUrl: safeBaseUrl },
|
|
46
|
-
`Stripping baseUrl for provider "${provider}"
|
|
46
|
+
`Stripping baseUrl for provider "${provider}": base_url is only valid for openai-compatible and ollama providers.`,
|
|
47
47
|
);
|
|
48
48
|
safeBaseUrl = null;
|
|
49
49
|
}
|
|
@@ -85,7 +85,7 @@ export async function resolveAuth(
|
|
|
85
85
|
|
|
86
86
|
case "none":
|
|
87
87
|
// Keyless endpoints still need their custom baseUrl threaded through
|
|
88
|
-
// (LM Studio / vLLM openai-compatible servers).
|
|
88
|
+
// (Ollama, LM Studio / vLLM openai-compatible servers).
|
|
89
89
|
return {
|
|
90
90
|
ok: true,
|
|
91
91
|
resolved: {
|
|
@@ -313,8 +313,59 @@ describe("POST inference/provider-connections (create)", () => {
|
|
|
313
313
|
auth: { type: "none" },
|
|
314
314
|
},
|
|
315
315
|
},
|
|
316
|
-
)) as { auth: object };
|
|
316
|
+
)) as { auth: object; baseUrl: string | null };
|
|
317
|
+
expect(result.auth).toEqual({ type: "none" });
|
|
318
|
+
expect(result.baseUrl).toBeNull();
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
test("creates an ollama connection with an optional base_url", async () => {
|
|
322
|
+
const result = (await call(
|
|
323
|
+
findHandler("inference_provider_connections_create"),
|
|
324
|
+
{
|
|
325
|
+
body: {
|
|
326
|
+
name: "ollama-remote",
|
|
327
|
+
provider: "ollama",
|
|
328
|
+
auth: { type: "none" },
|
|
329
|
+
base_url: "http://192.168.1.50:11434/v1",
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
)) as { auth: object; baseUrl: string | null };
|
|
317
333
|
expect(result.auth).toEqual({ type: "none" });
|
|
334
|
+
expect(result.baseUrl).toBe("http://192.168.1.50:11434/v1");
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test("updates an ollama connection base_url and can clear it", async () => {
|
|
338
|
+
await call(findHandler("inference_provider_connections_create"), {
|
|
339
|
+
body: {
|
|
340
|
+
name: "ollama-editable",
|
|
341
|
+
provider: "ollama",
|
|
342
|
+
auth: { type: "none" },
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
const updated = (await call(
|
|
347
|
+
findHandler("inference_provider_connections_update"),
|
|
348
|
+
{
|
|
349
|
+
pathParams: { name: "ollama-editable" },
|
|
350
|
+
body: {
|
|
351
|
+
auth: { type: "none" },
|
|
352
|
+
base_url: "http://127.0.0.1:11434/v1",
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
)) as { baseUrl: string | null };
|
|
356
|
+
expect(updated.baseUrl).toBe("http://127.0.0.1:11434/v1");
|
|
357
|
+
|
|
358
|
+
const cleared = (await call(
|
|
359
|
+
findHandler("inference_provider_connections_update"),
|
|
360
|
+
{
|
|
361
|
+
pathParams: { name: "ollama-editable" },
|
|
362
|
+
body: {
|
|
363
|
+
auth: { type: "none" },
|
|
364
|
+
base_url: null,
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
)) as { baseUrl: string | null };
|
|
368
|
+
expect(cleared.baseUrl).toBeNull();
|
|
318
369
|
});
|
|
319
370
|
|
|
320
371
|
test("derives api_key auth from provider + credential when auth is omitted", async () => {
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
ConnectionProviderSchema,
|
|
28
28
|
deriveAuthForProvider,
|
|
29
29
|
ProviderConnectionSchema,
|
|
30
|
-
|
|
30
|
+
PROVIDERS_ALLOWING_CUSTOM_BASE_URL,
|
|
31
31
|
VALID_CONNECTION_PROVIDERS,
|
|
32
32
|
} from "../../providers/inference/auth.js";
|
|
33
33
|
import {
|
|
@@ -72,14 +72,16 @@ const providerConnectionResponseSchema = ProviderConnectionSchema;
|
|
|
72
72
|
* Parse and validate `base_url` and `models` from the request body.
|
|
73
73
|
*
|
|
74
74
|
* `base_url` is only accepted for providers in
|
|
75
|
-
* `
|
|
75
|
+
* `PROVIDERS_ALLOWING_CUSTOM_BASE_URL` (openai-compatible and ollama).
|
|
76
76
|
* For all other providers, supplying `base_url` returns a 400. This prevents
|
|
77
77
|
* API-key exfiltration: an attacker cannot create an `anthropic` connection
|
|
78
78
|
* with a `base_url` pointing to their own server, which would redirect all
|
|
79
79
|
* LLM calls (and the API key) to the attacker.
|
|
80
80
|
*
|
|
81
|
-
* Even for
|
|
82
|
-
* networks or cloud metadata endpoints
|
|
81
|
+
* Even for allowed providers, a platform-hosted daemon rejects `base_url`
|
|
82
|
+
* values that point to private networks or cloud metadata endpoints
|
|
83
|
+
* (SSRF protection). Self-hosted daemons allow those addresses because
|
|
84
|
+
* localhost and LAN hosts are the expected target.
|
|
83
85
|
*/
|
|
84
86
|
async function parseCustomProviderFields(
|
|
85
87
|
body: Record<string, unknown>,
|
|
@@ -96,14 +98,14 @@ async function parseCustomProviderFields(
|
|
|
96
98
|
if ("base_url" in body) {
|
|
97
99
|
const raw = body.base_url;
|
|
98
100
|
|
|
99
|
-
// Gate: base_url is only valid for
|
|
101
|
+
// Gate: base_url is only valid for providers that persist a custom endpoint.
|
|
100
102
|
if (
|
|
101
103
|
raw !== null &&
|
|
102
104
|
raw !== undefined &&
|
|
103
|
-
!
|
|
105
|
+
!PROVIDERS_ALLOWING_CUSTOM_BASE_URL.has(provider)
|
|
104
106
|
) {
|
|
105
107
|
throw new BadRequestError(
|
|
106
|
-
`base_url is only valid for openai-compatible providers. Remove base_url or use
|
|
108
|
+
`base_url is only valid for openai-compatible and ollama providers. Remove base_url or use a provider that accepts a custom endpoint.`,
|
|
107
109
|
);
|
|
108
110
|
}
|
|
109
111
|
|
|
@@ -797,7 +797,8 @@ describe("web_search tool", () => {
|
|
|
797
797
|
{
|
|
798
798
|
title: "Keenable Result 1",
|
|
799
799
|
url: "https://example.com/keenable-1",
|
|
800
|
-
description: "
|
|
800
|
+
description: "",
|
|
801
|
+
snippet: "First Keenable result",
|
|
801
802
|
},
|
|
802
803
|
],
|
|
803
804
|
}),
|
|
@@ -814,6 +815,45 @@ describe("web_search tool", () => {
|
|
|
814
815
|
expect(result.content).toContain("https://example.com/keenable-1");
|
|
815
816
|
});
|
|
816
817
|
|
|
818
|
+
test("Keenable reads the page text from snippet, capped", async () => {
|
|
819
|
+
seedWebSearch("your-own", "keenable");
|
|
820
|
+
globalThis.fetch = (async () => {
|
|
821
|
+
return new Response(
|
|
822
|
+
JSON.stringify({
|
|
823
|
+
results: [
|
|
824
|
+
{
|
|
825
|
+
title: "Wrapped",
|
|
826
|
+
url: "https://example.com/wrapped",
|
|
827
|
+
description: "",
|
|
828
|
+
snippet: "line one\n\nline two",
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
title: "Long",
|
|
832
|
+
url: "https://example.com/long",
|
|
833
|
+
description: "",
|
|
834
|
+
snippet: "word ".repeat(400),
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
title: "Meta only",
|
|
838
|
+
url: "https://example.com/meta",
|
|
839
|
+
description: "only a meta description",
|
|
840
|
+
},
|
|
841
|
+
],
|
|
842
|
+
}),
|
|
843
|
+
{ status: 200, headers: { "content-type": "application/json" } },
|
|
844
|
+
);
|
|
845
|
+
}) as any;
|
|
846
|
+
|
|
847
|
+
const result = await execute({ query: "test" });
|
|
848
|
+
expect(result.content).toContain("line one line two");
|
|
849
|
+
expect(result.content).toContain("only a meta description");
|
|
850
|
+
const longLine = String(result.content)
|
|
851
|
+
.split("\n")
|
|
852
|
+
.find((line) => line.trim().startsWith("word"));
|
|
853
|
+
expect(longLine?.trim().length).toBeLessThanOrEqual(500);
|
|
854
|
+
expect(longLine?.trim().length).toBeGreaterThan(490);
|
|
855
|
+
});
|
|
856
|
+
|
|
817
857
|
test("Keenable uses the authenticated endpoint when a key is set", async () => {
|
|
818
858
|
seedWebSearch("your-own", "keenable");
|
|
819
859
|
mockKeenableSecureKey = "keen_test";
|
|
@@ -148,7 +148,10 @@ interface FirecrawlSearchResponse {
|
|
|
148
148
|
interface KeenableSearchResult {
|
|
149
149
|
title?: string;
|
|
150
150
|
url?: string;
|
|
151
|
+
/** The page's meta description. Empty for most pages; see keenableSnippet. */
|
|
151
152
|
description?: string;
|
|
153
|
+
/** The page text. This is what carries content on a Keenable result. */
|
|
154
|
+
snippet?: string;
|
|
152
155
|
published_at?: string;
|
|
153
156
|
acquired_at?: string;
|
|
154
157
|
}
|
|
@@ -488,6 +491,20 @@ function firecrawlTbsForFreshness(
|
|
|
488
491
|
}
|
|
489
492
|
}
|
|
490
493
|
|
|
494
|
+
/** Characters of page text kept per result. Keenable returns the whole page on
|
|
495
|
+
* every search result, an order of magnitude more than the other providers here
|
|
496
|
+
* return, so it is capped to keep one search from filling the context. */
|
|
497
|
+
const KEENABLE_SNIPPET_MAX_LENGTH = 500;
|
|
498
|
+
|
|
499
|
+
/** Keenable sends both `snippet` and `description` on every result: `snippet`
|
|
500
|
+
* carries the page text and `description` is the page's meta description, which
|
|
501
|
+
* is empty for most pages. `||` rather than `??`, since the empty description is
|
|
502
|
+
* present rather than nullish. */
|
|
503
|
+
function keenableSnippet(result: KeenableSearchResult): string {
|
|
504
|
+
const text = result.snippet || result.description || "";
|
|
505
|
+
return text.replace(/\s+/g, " ").trim().slice(0, KEENABLE_SNIPPET_MAX_LENGTH);
|
|
506
|
+
}
|
|
507
|
+
|
|
491
508
|
function formatKeenableResults(
|
|
492
509
|
data: KeenableSearchResponse,
|
|
493
510
|
query: string,
|
|
@@ -505,8 +522,9 @@ function formatKeenableResults(
|
|
|
505
522
|
if (r.url) {
|
|
506
523
|
lines.push(` URL: ${r.url}`);
|
|
507
524
|
}
|
|
508
|
-
|
|
509
|
-
|
|
525
|
+
const snippet = keenableSnippet(r);
|
|
526
|
+
if (snippet) {
|
|
527
|
+
lines.push(` ${snippet}`);
|
|
510
528
|
}
|
|
511
529
|
if (r.published_at) {
|
|
512
530
|
lines.push(` Published: ${r.published_at}`);
|
|
@@ -531,7 +549,7 @@ function buildKeenableMetadata(
|
|
|
531
549
|
url,
|
|
532
550
|
domain,
|
|
533
551
|
faviconUrl: faviconUrlForDomain(domain),
|
|
534
|
-
snippet: r
|
|
552
|
+
snippet: keenableSnippet(r),
|
|
535
553
|
};
|
|
536
554
|
});
|
|
537
555
|
return {
|