@vellumai/assistant 0.12.1-dev.202609151714.4f7c874 → 0.12.1-dev.202609151913.a151da3
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 +44 -0
- package/package.json +1 -1
- package/src/__tests__/oauth-commands-routes.test.ts +27 -0
- package/src/__tests__/oauth-provider-serializer.test.ts +22 -0
- package/src/__tests__/oauth-providers-routes.test.ts +1 -0
- package/src/config/feature-flag-registry.json +1 -1
- package/src/oauth/__tests__/seed-providers-managed.test.ts +10 -0
- package/src/oauth/provider-serializer.ts +9 -0
- package/src/oauth/seed-providers.ts +16 -3
- package/src/providers/inference/__tests__/adapter-factory-opencode.test.ts +89 -3
- package/src/providers/inference/__tests__/endpoint-probe.test.ts +55 -0
- package/src/providers/inference/adapter-factory.ts +15 -4
- package/src/providers/inference/auth.ts +28 -0
- package/src/providers/inference/endpoint-probe.ts +49 -13
- package/src/providers/openai/chat-completions-provider.ts +10 -0
- package/src/providers/openai/responses-provider.ts +9 -2
- package/src/providers/opencode/client.test.ts +178 -0
- package/src/providers/opencode/client.ts +107 -4
- package/src/providers/openrouter/client.ts +0 -9
- package/src/providers/vercel-ai-gateway/client.ts +0 -9
- package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +36 -0
- package/src/runtime/routes/inference-provider-connection-routes.ts +11 -0
- package/src/runtime/routes/oauth-commands-routes.ts +9 -0
- package/src/runtime/routes/oauth-providers.ts +7 -0
package/openapi.yaml
CHANGED
|
@@ -24481,6 +24481,22 @@ paths:
|
|
|
24481
24481
|
anyOf:
|
|
24482
24482
|
- type: string
|
|
24483
24483
|
- type: "null"
|
|
24484
|
+
tenant_host:
|
|
24485
|
+
anyOf:
|
|
24486
|
+
- type: object
|
|
24487
|
+
properties:
|
|
24488
|
+
pattern:
|
|
24489
|
+
type: string
|
|
24490
|
+
label:
|
|
24491
|
+
type: string
|
|
24492
|
+
placeholder:
|
|
24493
|
+
type: string
|
|
24494
|
+
required:
|
|
24495
|
+
- pattern
|
|
24496
|
+
- label
|
|
24497
|
+
- placeholder
|
|
24498
|
+
additionalProperties: false
|
|
24499
|
+
- type: "null"
|
|
24484
24500
|
acts_as:
|
|
24485
24501
|
type: string
|
|
24486
24502
|
enum:
|
|
@@ -24497,6 +24513,7 @@ paths:
|
|
|
24497
24513
|
- supports_managed_mode
|
|
24498
24514
|
- managed_service_is_paid
|
|
24499
24515
|
- feature_flag
|
|
24516
|
+
- tenant_host
|
|
24500
24517
|
- acts_as
|
|
24501
24518
|
additionalProperties: false
|
|
24502
24519
|
- type: "null"
|
|
@@ -25015,6 +25032,22 @@ paths:
|
|
|
25015
25032
|
anyOf:
|
|
25016
25033
|
- type: string
|
|
25017
25034
|
- type: "null"
|
|
25035
|
+
tenant_host:
|
|
25036
|
+
anyOf:
|
|
25037
|
+
- type: object
|
|
25038
|
+
properties:
|
|
25039
|
+
pattern:
|
|
25040
|
+
type: string
|
|
25041
|
+
label:
|
|
25042
|
+
type: string
|
|
25043
|
+
placeholder:
|
|
25044
|
+
type: string
|
|
25045
|
+
required:
|
|
25046
|
+
- pattern
|
|
25047
|
+
- label
|
|
25048
|
+
- placeholder
|
|
25049
|
+
additionalProperties: false
|
|
25050
|
+
- type: "null"
|
|
25018
25051
|
acts_as:
|
|
25019
25052
|
type: string
|
|
25020
25053
|
enum:
|
|
@@ -25031,6 +25064,7 @@ paths:
|
|
|
25031
25064
|
- supports_managed_mode
|
|
25032
25065
|
- managed_service_is_paid
|
|
25033
25066
|
- feature_flag
|
|
25067
|
+
- tenant_host
|
|
25034
25068
|
- acts_as
|
|
25035
25069
|
additionalProperties: false
|
|
25036
25070
|
required:
|
|
@@ -38269,6 +38303,11 @@ components:
|
|
|
38269
38303
|
displayName:
|
|
38270
38304
|
type: string
|
|
38271
38305
|
minLength: 1
|
|
38306
|
+
transport:
|
|
38307
|
+
type: string
|
|
38308
|
+
enum:
|
|
38309
|
+
- chat_completions
|
|
38310
|
+
- responses
|
|
38272
38311
|
required:
|
|
38273
38312
|
- id
|
|
38274
38313
|
TelemetryJsonValue:
|
|
@@ -39400,6 +39439,11 @@ components:
|
|
|
39400
39439
|
displayName:
|
|
39401
39440
|
type: string
|
|
39402
39441
|
minLength: 1
|
|
39442
|
+
transport:
|
|
39443
|
+
type: string
|
|
39444
|
+
enum:
|
|
39445
|
+
- chat_completions
|
|
39446
|
+
- responses
|
|
39403
39447
|
required:
|
|
39404
39448
|
- id
|
|
39405
39449
|
additionalProperties: false
|
package/package.json
CHANGED
|
@@ -1165,6 +1165,33 @@ describe("POST oauth/managed-connect/start", () => {
|
|
|
1165
1165
|
expect(result.connect_url).toBe("https://app.vellum.ai/connect/abc");
|
|
1166
1166
|
});
|
|
1167
1167
|
|
|
1168
|
+
test("forwards tenant_host to the platform only when one is supplied", async () => {
|
|
1169
|
+
// Shopify's endpoints live on the merchant's host, which the platform
|
|
1170
|
+
// substitutes into its templates; other providers must not see the key.
|
|
1171
|
+
const bodies: Array<Record<string, unknown>> = [];
|
|
1172
|
+
mockFetchImpl = async (_path, init) => {
|
|
1173
|
+
bodies.push(JSON.parse(String(init?.body)) as Record<string, unknown>);
|
|
1174
|
+
return {
|
|
1175
|
+
ok: true,
|
|
1176
|
+
status: 200,
|
|
1177
|
+
json: async () => ({
|
|
1178
|
+
connect_url: "https://app.vellum.ai/connect/abc",
|
|
1179
|
+
}),
|
|
1180
|
+
text: async () => "",
|
|
1181
|
+
};
|
|
1182
|
+
};
|
|
1183
|
+
await getRoute("POST", "oauth/managed-connect/start").handler(
|
|
1184
|
+
makeArgs({
|
|
1185
|
+
body: { provider: "shopify", tenant_host: " my-store.myshopify.com " },
|
|
1186
|
+
}),
|
|
1187
|
+
);
|
|
1188
|
+
await getRoute("POST", "oauth/managed-connect/start").handler(
|
|
1189
|
+
makeArgs({ body: { provider: "google", tenant_host: " " } }),
|
|
1190
|
+
);
|
|
1191
|
+
expect(bodies[0]?.tenant_host).toBe("my-store.myshopify.com");
|
|
1192
|
+
expect(bodies[1]).not.toHaveProperty("tenant_host");
|
|
1193
|
+
});
|
|
1194
|
+
|
|
1168
1195
|
test("raises InternalError when platform returns 401", async () => {
|
|
1169
1196
|
mockFetchImpl = async () => ({
|
|
1170
1197
|
ok: false,
|
|
@@ -291,10 +291,32 @@ describe("serializeProviderSummary", () => {
|
|
|
291
291
|
supports_managed_mode: true,
|
|
292
292
|
managed_service_is_paid: false,
|
|
293
293
|
feature_flag: null,
|
|
294
|
+
tenant_host: null,
|
|
294
295
|
acts_as: "user",
|
|
295
296
|
});
|
|
296
297
|
});
|
|
297
298
|
|
|
299
|
+
test("exposes the tenant host a per-tenant provider needs at connect", () => {
|
|
300
|
+
// Shopify's OAuth endpoints live on the merchant's own host, so a client
|
|
301
|
+
// has to collect it before the managed flow can start. The summary is the
|
|
302
|
+
// only provider metadata the web client reads, so it carries the ask.
|
|
303
|
+
const shopify = serializeProviderSummary(makeRow({ provider: "shopify" }))!;
|
|
304
|
+
expect(shopify.tenant_host).toEqual({
|
|
305
|
+
pattern: "^[a-z0-9][a-z0-9-]*\\.myshopify\\.com$",
|
|
306
|
+
label: "Shop domain",
|
|
307
|
+
placeholder: "your-store.myshopify.com",
|
|
308
|
+
});
|
|
309
|
+
expect(
|
|
310
|
+
new RegExp(shopify.tenant_host!.pattern).test("my-store.myshopify.com"),
|
|
311
|
+
).toBe(true);
|
|
312
|
+
expect(new RegExp(shopify.tenant_host!.pattern).test("evil.com")).toBe(
|
|
313
|
+
false,
|
|
314
|
+
);
|
|
315
|
+
expect(
|
|
316
|
+
serializeProviderSummary(makeRow({ provider: "github" }))!.tenant_host,
|
|
317
|
+
).toBeNull();
|
|
318
|
+
});
|
|
319
|
+
|
|
298
320
|
test("names which sense of connected a provider represents", () => {
|
|
299
321
|
// The provider key does not say, and the naming actively misleads:
|
|
300
322
|
// `slack` is the user integration while its bot is `slack_channel`, but
|
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
"scope": "client",
|
|
176
176
|
"key": "teleport",
|
|
177
177
|
"label": "Teleport",
|
|
178
|
-
"description": "Enable teleport UI in General settings
|
|
178
|
+
"description": "Enable the local-to-platform teleport UI in General settings. Platform-to-local teleport is GA and not gated by this flag",
|
|
179
179
|
"defaultEnabled": false
|
|
180
180
|
},
|
|
181
181
|
{
|
|
@@ -70,6 +70,16 @@ describe("PROVIDER_SEED_DATA managed mode wiring", () => {
|
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
// `file_code_connect:write` is only offered to apps owned by an
|
|
74
|
+
// Organization-plan team. Managed apps in other environments are not,
|
|
75
|
+
// so requesting it fails the whole authorization there.
|
|
76
|
+
expect(figma.defaultScopes).not.toContain("file_code_connect:write");
|
|
77
|
+
if (Array.isArray(availableScopes)) {
|
|
78
|
+
expect(availableScopes.map(({ scope }) => scope)).toContain(
|
|
79
|
+
"file_code_connect:write",
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
73
83
|
// GET /v1/me backs both the ping and the identity label.
|
|
74
84
|
expect(figma.defaultScopes).toContain("current_user:read");
|
|
75
85
|
});
|
|
@@ -20,6 +20,8 @@ export type SerializedProvider = ReturnType<typeof serializeProvider> &
|
|
|
20
20
|
|
|
21
21
|
import { isChannelBotProvider } from "@vellumai/service-contracts/channels";
|
|
22
22
|
|
|
23
|
+
import { PROVIDER_SEED_DATA } from "./seed-providers.js";
|
|
24
|
+
|
|
23
25
|
/**
|
|
24
26
|
* Lightweight summary projection of an OAuth provider, suitable for API
|
|
25
27
|
* list responses where full detail is not needed. All keys are snake_case
|
|
@@ -36,6 +38,12 @@ export interface SerializedProviderSummary {
|
|
|
36
38
|
supports_managed_mode: boolean;
|
|
37
39
|
managed_service_is_paid: boolean;
|
|
38
40
|
feature_flag: string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Per-tenant providers only (Shopify): what a client must collect before
|
|
43
|
+
* starting a managed connect, since the provider's OAuth endpoints live on
|
|
44
|
+
* the customer's own host. `null` for providers with one global host.
|
|
45
|
+
*/
|
|
46
|
+
tenant_host: { pattern: string; label: string; placeholder: string } | null;
|
|
39
47
|
/**
|
|
40
48
|
* Which sense of "connected" this provider represents: `assistant` for a bot
|
|
41
49
|
* credential people reach the assistant through, `user` for a grant letting
|
|
@@ -164,6 +172,7 @@ export function serializeProviderSummary(
|
|
|
164
172
|
supports_managed_mode: !!row.managedServiceConfigKey,
|
|
165
173
|
managed_service_is_paid: !!row.managedServiceIsPaid,
|
|
166
174
|
feature_flag: row.featureFlag ?? null,
|
|
175
|
+
tenant_host: PROVIDER_SEED_DATA[row.provider]?.tenantHost ?? null,
|
|
167
176
|
acts_as: isChannelBotProvider(row.provider) ? "assistant" : "user",
|
|
168
177
|
};
|
|
169
178
|
}
|
|
@@ -90,6 +90,13 @@ export const PROVIDER_SEED_DATA: Record<
|
|
|
90
90
|
}>;
|
|
91
91
|
appType?: string;
|
|
92
92
|
setupNotes?: string[];
|
|
93
|
+
/**
|
|
94
|
+
* Per-tenant providers only: the host the user supplies at connect time,
|
|
95
|
+
* which the platform substitutes into `{tenant_host}` URL placeholders.
|
|
96
|
+
* `pattern` mirrors the platform registry's validation so clients can
|
|
97
|
+
* reject a malformed host before the request leaves the browser.
|
|
98
|
+
*/
|
|
99
|
+
tenantHost?: { pattern: string; label: string; placeholder: string };
|
|
93
100
|
identityUrl?: string;
|
|
94
101
|
identityMethod?: string;
|
|
95
102
|
identityHeaders?: Record<string, string>;
|
|
@@ -1006,8 +1013,9 @@ export const PROVIDER_SEED_DATA: Record<
|
|
|
1006
1013
|
// requesting it would fail the entire authorization. `folders:read` is
|
|
1007
1014
|
// withheld likewise: Figma documents it, but the app's scope picker only
|
|
1008
1015
|
// offers `folder_metadata:read` under Folders. `file_code_connect:write`
|
|
1009
|
-
// is
|
|
1010
|
-
// Organization-plan
|
|
1016
|
+
// is withheld because Figma only offers it to apps owned by an
|
|
1017
|
+
// Organization-plan team, which not every managed app is, and nothing
|
|
1018
|
+
// here uses Code Connect; it stays in availableScopes for BYO apps.
|
|
1011
1019
|
defaultScopes: [
|
|
1012
1020
|
"current_user:read",
|
|
1013
1021
|
"file_content:read",
|
|
@@ -1017,7 +1025,6 @@ export const PROVIDER_SEED_DATA: Record<
|
|
|
1017
1025
|
"file_comments:write",
|
|
1018
1026
|
"file_dev_resources:read",
|
|
1019
1027
|
"file_dev_resources:write",
|
|
1020
|
-
"file_code_connect:write",
|
|
1021
1028
|
"folder_metadata:read",
|
|
1022
1029
|
"library_content:read",
|
|
1023
1030
|
"library_assets:read",
|
|
@@ -1493,6 +1500,12 @@ export const PROVIDER_SEED_DATA: Record<
|
|
|
1493
1500
|
],
|
|
1494
1501
|
loopbackPort: 17341,
|
|
1495
1502
|
managedServiceConfigKey: "shopify-oauth",
|
|
1503
|
+
// Mirrors `extra_config.tenant_host` in the platform provider registry.
|
|
1504
|
+
tenantHost: {
|
|
1505
|
+
pattern: "^[a-z0-9][a-z0-9-]*\\.myshopify\\.com$",
|
|
1506
|
+
label: "Shop domain",
|
|
1507
|
+
placeholder: "your-store.myshopify.com",
|
|
1508
|
+
},
|
|
1496
1509
|
injectionTemplates: [
|
|
1497
1510
|
{
|
|
1498
1511
|
hostPattern: "*.myshopify.com",
|
|
@@ -6,11 +6,25 @@ import {
|
|
|
6
6
|
OPENCODE_ZEN_BASE_URL,
|
|
7
7
|
OpenCodeProvider,
|
|
8
8
|
} from "../../opencode/client.js";
|
|
9
|
+
import type { Provider } from "../../types.js";
|
|
9
10
|
import {
|
|
10
11
|
buildProviderAdapter,
|
|
11
12
|
createAdapterFromConnection,
|
|
12
13
|
} from "../adapter-factory.js";
|
|
13
14
|
import type { ProviderConnection, ResolvedAuth } from "../auth.js";
|
|
15
|
+
import { collectModelTransports } from "../auth.js";
|
|
16
|
+
|
|
17
|
+
/** Peel the retry/usage wrappers off a connection adapter. */
|
|
18
|
+
function unwrapAdapter(provider: Provider): Provider {
|
|
19
|
+
let current = provider;
|
|
20
|
+
for (;;) {
|
|
21
|
+
const inner = (current as unknown as { inner?: Provider }).inner;
|
|
22
|
+
if (!inner) {
|
|
23
|
+
return current;
|
|
24
|
+
}
|
|
25
|
+
current = inner;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
14
28
|
|
|
15
29
|
describe("opencode adapter factory", () => {
|
|
16
30
|
test("buildProviderAdapter returns an OpenCodeProvider", () => {
|
|
@@ -32,9 +46,8 @@ describe("opencode adapter factory", () => {
|
|
|
32
46
|
streamTimeoutMs: 60_000,
|
|
33
47
|
useNativeWebSearch: false,
|
|
34
48
|
}) as OpenCodeProvider;
|
|
35
|
-
const client = (
|
|
36
|
-
|
|
37
|
-
).client;
|
|
49
|
+
const client = (adapter as unknown as { client: { baseURL?: string } })
|
|
50
|
+
.client;
|
|
38
51
|
expect(client.baseURL).toBe(OPENCODE_ZEN_BASE_URL);
|
|
39
52
|
});
|
|
40
53
|
|
|
@@ -65,6 +78,79 @@ describe("opencode adapter factory", () => {
|
|
|
65
78
|
expect(adapter).not.toBeNull();
|
|
66
79
|
});
|
|
67
80
|
|
|
81
|
+
test("buildProviderAdapter resolves the transport per model", () => {
|
|
82
|
+
const adapter = buildProviderAdapter("opencode", {
|
|
83
|
+
apiKey: "sk-opencode-test",
|
|
84
|
+
model: "mimo-v2.5-free",
|
|
85
|
+
streamTimeoutMs: 60_000,
|
|
86
|
+
useNativeWebSearch: false,
|
|
87
|
+
}) as OpenCodeProvider;
|
|
88
|
+
expect(adapter.resolveTransport("mimo-v2.5-free")).toBe("chat_completions");
|
|
89
|
+
expect(adapter.resolveTransport("muse-spark-1.2-contributor-free")).toBe(
|
|
90
|
+
"responses",
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("buildProviderAdapter honors explicit per-model transports", () => {
|
|
95
|
+
const adapter = buildProviderAdapter("opencode", {
|
|
96
|
+
apiKey: "sk-opencode-test",
|
|
97
|
+
model: "mimo-v2.5-free",
|
|
98
|
+
streamTimeoutMs: 60_000,
|
|
99
|
+
useNativeWebSearch: false,
|
|
100
|
+
modelTransports: {
|
|
101
|
+
"mimo-v2.5-free": "responses",
|
|
102
|
+
"muse-spark-1.2-contributor-free": "chat_completions",
|
|
103
|
+
},
|
|
104
|
+
}) as OpenCodeProvider;
|
|
105
|
+
expect(adapter.resolveTransport("mimo-v2.5-free")).toBe("responses");
|
|
106
|
+
expect(adapter.resolveTransport("muse-spark-1.2-contributor-free")).toBe(
|
|
107
|
+
"chat_completions",
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("collectModelTransports keeps only the entries that declare a transport", () => {
|
|
112
|
+
expect(
|
|
113
|
+
collectModelTransports([
|
|
114
|
+
{ id: "mimo-v2.5-free" },
|
|
115
|
+
{ id: "muse-spark-1.2-contributor-free", transport: "responses" },
|
|
116
|
+
{ id: "gpt-5.4", transport: "chat_completions" },
|
|
117
|
+
]),
|
|
118
|
+
).toEqual({
|
|
119
|
+
"muse-spark-1.2-contributor-free": "responses",
|
|
120
|
+
"gpt-5.4": "chat_completions",
|
|
121
|
+
});
|
|
122
|
+
expect(collectModelTransports([{ id: "mimo-v2.5-free" }])).toBeUndefined();
|
|
123
|
+
expect(collectModelTransports(null)).toBeUndefined();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("createAdapterFromConnection reads the transport from the connection's model entries", () => {
|
|
127
|
+
const connection: ProviderConnection = {
|
|
128
|
+
name: "opencode-zen",
|
|
129
|
+
provider: "opencode",
|
|
130
|
+
auth: { type: "api_key", credential: "cred-opencode" },
|
|
131
|
+
label: "OpenCode Zen",
|
|
132
|
+
baseUrl: null,
|
|
133
|
+
models: [{ id: "mimo-v2.5-free", transport: "responses" }],
|
|
134
|
+
createdAt: Date.now(),
|
|
135
|
+
updatedAt: Date.now(),
|
|
136
|
+
isManaged: false,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const adapter = createAdapterFromConnection(
|
|
140
|
+
connection,
|
|
141
|
+
{
|
|
142
|
+
kind: "header",
|
|
143
|
+
headers: { Authorization: "Bearer sk-opencode-key" },
|
|
144
|
+
},
|
|
145
|
+
{ model: "mimo-v2.5-free", streamTimeoutMs: 60_000 },
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
expect(adapter).not.toBeNull();
|
|
149
|
+
const raw = unwrapAdapter(adapter!) as OpenCodeProvider;
|
|
150
|
+
expect(raw).toBeInstanceOf(OpenCodeProvider);
|
|
151
|
+
expect(raw.resolveTransport("mimo-v2.5-free")).toBe("responses");
|
|
152
|
+
});
|
|
153
|
+
|
|
68
154
|
test("createAdapterFromConnection rejects none auth for opencode", () => {
|
|
69
155
|
const connection: ProviderConnection = {
|
|
70
156
|
name: "opencode-keyless",
|
|
@@ -129,3 +129,58 @@ describe("testInferenceConnection", () => {
|
|
|
129
129
|
).toBeNull();
|
|
130
130
|
});
|
|
131
131
|
});
|
|
132
|
+
|
|
133
|
+
describe("testInferenceConnection on OpenCode", () => {
|
|
134
|
+
const OPENCODE = {
|
|
135
|
+
provider: "opencode",
|
|
136
|
+
auth: { type: "none" } as const,
|
|
137
|
+
baseUrl: "https://opencode.ai/zen/v1",
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
test("probes /responses for a responses-only model", async () => {
|
|
141
|
+
const calls: ProbeCall[] = [];
|
|
142
|
+
const result = await testInferenceConnection(
|
|
143
|
+
{ ...OPENCODE, models: [{ id: "muse-spark-1.2-contributor-free" }] },
|
|
144
|
+
stubFetch(200, calls),
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
expect(result).toMatchObject({
|
|
148
|
+
ok: true,
|
|
149
|
+
resolved_url: "https://opencode.ai/zen/v1/responses",
|
|
150
|
+
});
|
|
151
|
+
expect(calls[0].body).toMatchObject({
|
|
152
|
+
model: "muse-spark-1.2-contributor-free",
|
|
153
|
+
input: "ping",
|
|
154
|
+
max_output_tokens: 16,
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("keeps a chat-completions model on /chat/completions", async () => {
|
|
159
|
+
const calls: ProbeCall[] = [];
|
|
160
|
+
const result = await testInferenceConnection(
|
|
161
|
+
{ ...OPENCODE, models: [{ id: "mimo-v2.5-free" }] },
|
|
162
|
+
stubFetch(200, calls),
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
expect(result?.resolved_url).toBe(
|
|
166
|
+
"https://opencode.ai/zen/v1/chat/completions",
|
|
167
|
+
);
|
|
168
|
+
expect(calls[0].body).toMatchObject({
|
|
169
|
+
model: "mimo-v2.5-free",
|
|
170
|
+
max_tokens: 1,
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("an explicit transport on the model entry picks the probed endpoint", async () => {
|
|
175
|
+
const calls: ProbeCall[] = [];
|
|
176
|
+
const result = await testInferenceConnection(
|
|
177
|
+
{
|
|
178
|
+
...OPENCODE,
|
|
179
|
+
models: [{ id: "mimo-v2.5-free", transport: "responses" }],
|
|
180
|
+
},
|
|
181
|
+
stubFetch(200, calls),
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
expect(result?.resolved_url).toBe("https://opencode.ai/zen/v1/responses");
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -56,9 +56,12 @@ import {
|
|
|
56
56
|
VELLUM_MANAGED_PROVIDER,
|
|
57
57
|
} from "../vellum-model-routing.js";
|
|
58
58
|
import { VercelAIGatewayProvider } from "../vercel-ai-gateway/client.js";
|
|
59
|
-
import type {
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
import type {
|
|
60
|
+
ConnectionModelTransport,
|
|
61
|
+
ProviderConnection,
|
|
62
|
+
ResolvedAuth,
|
|
63
|
+
} from "./auth.js";
|
|
64
|
+
import { collectModelTransports, effectiveConnectionAuth } from "./auth.js";
|
|
62
65
|
import { MissingCredentialGuardProvider } from "./missing-credential-guard.js";
|
|
63
66
|
import { resolveAuth } from "./resolve-auth.js";
|
|
64
67
|
|
|
@@ -73,6 +76,12 @@ export interface AdapterCreateOpts {
|
|
|
73
76
|
useNativeWebSearch: boolean;
|
|
74
77
|
/** When true, the OpenAI adapter targets the Codex subscription endpoint. */
|
|
75
78
|
codexSubscription?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Explicit wire transport per model id, from the connection's model
|
|
81
|
+
* entries (`ConnectionModel.transport`). Consumed by providers that serve
|
|
82
|
+
* both OpenAI-style APIs from one origin (OpenCode); others ignore it.
|
|
83
|
+
*/
|
|
84
|
+
modelTransports?: Readonly<Record<string, ConnectionModelTransport>>;
|
|
76
85
|
}
|
|
77
86
|
|
|
78
87
|
type AdapterFactory = (opts: AdapterCreateOpts) => Provider;
|
|
@@ -166,9 +175,10 @@ const ADAPTER_FACTORIES: Record<string, AdapterFactory> = {
|
|
|
166
175
|
assistantReasoningField: "reasoning_content",
|
|
167
176
|
...(baseURL ? { baseURL } : {}),
|
|
168
177
|
}),
|
|
169
|
-
opencode: ({ apiKey, model, streamTimeoutMs, baseURL }) =>
|
|
178
|
+
opencode: ({ apiKey, model, streamTimeoutMs, baseURL, modelTransports }) =>
|
|
170
179
|
new OpenCodeProvider(apiKey, model, {
|
|
171
180
|
streamTimeoutMs,
|
|
181
|
+
modelTransports,
|
|
172
182
|
...(baseURL ? { baseURL } : {}),
|
|
173
183
|
}),
|
|
174
184
|
// Keyless openai-compatible endpoints (e.g. LM Studio) ignore the key; the
|
|
@@ -600,6 +610,7 @@ function buildConnectionAdapter(
|
|
|
600
610
|
baseURL,
|
|
601
611
|
useNativeWebSearch: opts.useNativeWebSearch ?? false,
|
|
602
612
|
codexSubscription,
|
|
613
|
+
modelTransports: collectModelTransports(connection.models),
|
|
603
614
|
});
|
|
604
615
|
if (!adapter) {
|
|
605
616
|
return null;
|
|
@@ -163,14 +163,42 @@ export const ConnectionProviderSchema = z
|
|
|
163
163
|
// Per-connection model entries (openai-compatible)
|
|
164
164
|
// ---------------------------------------------------------------------------
|
|
165
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Wire API a connection model is served over. Only OpenCode serves both
|
|
168
|
+
* OpenAI-style transports from one origin and consults this; every other
|
|
169
|
+
* provider fixes its transport in the adapter factory. Absent, OpenCode
|
|
170
|
+
* falls back to its built-in per-model default.
|
|
171
|
+
*/
|
|
172
|
+
export const ConnectionModelTransportSchema = z.enum([
|
|
173
|
+
"chat_completions",
|
|
174
|
+
"responses",
|
|
175
|
+
]);
|
|
176
|
+
export type ConnectionModelTransport = z.infer<
|
|
177
|
+
typeof ConnectionModelTransportSchema
|
|
178
|
+
>;
|
|
179
|
+
|
|
166
180
|
export const ConnectionModelSchema = z
|
|
167
181
|
.object({
|
|
168
182
|
id: z.string().min(1),
|
|
169
183
|
displayName: z.string().min(1).optional(),
|
|
184
|
+
transport: ConnectionModelTransportSchema.optional(),
|
|
170
185
|
})
|
|
171
186
|
.meta({ id: "ConnectionModel" });
|
|
172
187
|
export type ConnectionModel = z.infer<typeof ConnectionModelSchema>;
|
|
173
188
|
|
|
189
|
+
/**
|
|
190
|
+
* The explicit transports declared on a connection's model entries, keyed by
|
|
191
|
+
* model id. `undefined` when no entry declares one.
|
|
192
|
+
*/
|
|
193
|
+
export function collectModelTransports(
|
|
194
|
+
models: readonly ConnectionModel[] | null | undefined,
|
|
195
|
+
): Readonly<Record<string, ConnectionModelTransport>> | undefined {
|
|
196
|
+
const entries = (models ?? []).flatMap((m) =>
|
|
197
|
+
m.transport ? [[m.id, m.transport] as const] : [],
|
|
198
|
+
);
|
|
199
|
+
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
200
|
+
}
|
|
201
|
+
|
|
174
202
|
/**
|
|
175
203
|
* Providers whose connections require an explicit `baseUrl` and non-empty
|
|
176
204
|
* `models` list (openai-compatible endpoints have no fixed upstream, so the
|
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
|
|
12
12
|
import { getLogger } from "../../util/logger.js";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
resolveOpenCodeRequestHeaders,
|
|
15
|
+
resolveOpenCodeTransport,
|
|
16
|
+
} from "../opencode/client.js";
|
|
14
17
|
import type { Auth, ConnectionModel } from "./auth.js";
|
|
15
18
|
import { resolveAuth } from "./resolve-auth.js";
|
|
16
19
|
|
|
@@ -46,10 +49,47 @@ function hintForStatus(status: number): string {
|
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
52
|
+
* Minimal request for the transport the model is served over. Only OpenCode
|
|
53
|
+
* serves both OpenAI-style APIs from one origin; every other custom endpoint
|
|
54
|
+
* is probed as chat completions. Responses requires at least 16 output
|
|
55
|
+
* tokens.
|
|
56
|
+
*/
|
|
57
|
+
function buildProbeRequest(
|
|
58
|
+
provider: string,
|
|
59
|
+
model: ConnectionModel,
|
|
60
|
+
): { path: string; body: Record<string, unknown> } {
|
|
61
|
+
if (
|
|
62
|
+
provider === "opencode" &&
|
|
63
|
+
resolveOpenCodeTransport(model.id, model.transport) === "responses"
|
|
64
|
+
) {
|
|
65
|
+
return {
|
|
66
|
+
path: "/responses",
|
|
67
|
+
body: {
|
|
68
|
+
model: model.id,
|
|
69
|
+
input: "ping",
|
|
70
|
+
max_output_tokens: 16,
|
|
71
|
+
stream: false,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
path: "/chat/completions",
|
|
77
|
+
body: {
|
|
78
|
+
model: model.id,
|
|
79
|
+
messages: [{ role: "user", content: "ping" }],
|
|
80
|
+
max_tokens: 1,
|
|
81
|
+
stream: false,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Probe a connection's custom endpoint with a minimal request on the
|
|
88
|
+
* transport its first model uses (chat completions with `max_tokens: 1`
|
|
89
|
+
* unless the model is served by the Responses API). Returns `null` when
|
|
90
|
+
* there is nothing to probe: no custom base URL, no model id to send, or auth
|
|
91
|
+
* that cannot be resolved (a missing credential surfaces through its own
|
|
92
|
+
* error path).
|
|
53
93
|
*/
|
|
54
94
|
export async function testInferenceConnection(
|
|
55
95
|
connection: {
|
|
@@ -60,7 +100,7 @@ export async function testInferenceConnection(
|
|
|
60
100
|
},
|
|
61
101
|
fetchImpl: typeof fetch = fetch,
|
|
62
102
|
): Promise<EndpointCheck | null> {
|
|
63
|
-
const model = connection.models?.[0]
|
|
103
|
+
const model = connection.models?.[0];
|
|
64
104
|
if (!connection.baseUrl || !model) {
|
|
65
105
|
return null;
|
|
66
106
|
}
|
|
@@ -78,7 +118,8 @@ export async function testInferenceConnection(
|
|
|
78
118
|
const providerHeaders =
|
|
79
119
|
connection.provider === "opencode" ? resolveOpenCodeRequestHeaders() : {};
|
|
80
120
|
|
|
81
|
-
const
|
|
121
|
+
const probe = buildProbeRequest(connection.provider, model);
|
|
122
|
+
const url = `${connection.baseUrl.replace(/\/+$/, "")}${probe.path}`;
|
|
82
123
|
try {
|
|
83
124
|
const res = await fetchImpl(url, {
|
|
84
125
|
method: "POST",
|
|
@@ -87,12 +128,7 @@ export async function testInferenceConnection(
|
|
|
87
128
|
...providerHeaders,
|
|
88
129
|
"Content-Type": "application/json",
|
|
89
130
|
},
|
|
90
|
-
body: JSON.stringify(
|
|
91
|
-
model,
|
|
92
|
-
messages: [{ role: "user", content: "ping" }],
|
|
93
|
-
max_tokens: 1,
|
|
94
|
-
stream: false,
|
|
95
|
-
}),
|
|
131
|
+
body: JSON.stringify(probe.body),
|
|
96
132
|
signal: AbortSignal.timeout(PROBE_TIMEOUT_MS),
|
|
97
133
|
});
|
|
98
134
|
void res.body?.cancel();
|
|
@@ -859,6 +859,16 @@ export class OpenAIChatCompletionsProvider implements Provider {
|
|
|
859
859
|
return this.model;
|
|
860
860
|
}
|
|
861
861
|
|
|
862
|
+
/** The model a send targets: a non-blank per-call `config.model` override, else the constructed one. */
|
|
863
|
+
protected resolveEffectiveModel(options?: SendMessageOptions): string {
|
|
864
|
+
const config = options?.config as Record<string, unknown> | undefined;
|
|
865
|
+
const override =
|
|
866
|
+
typeof config?.model === "string" && config.model.trim().length > 0
|
|
867
|
+
? config.model.trim()
|
|
868
|
+
: undefined;
|
|
869
|
+
return override ?? this.model;
|
|
870
|
+
}
|
|
871
|
+
|
|
862
872
|
async sendMessage(
|
|
863
873
|
messages: Message[],
|
|
864
874
|
options?: SendMessageOptions,
|
|
@@ -109,7 +109,9 @@ function mapResponsesReasoningEffort(
|
|
|
109
109
|
return "none";
|
|
110
110
|
}
|
|
111
111
|
const clamped = clampReasoningEffort(raw, effortCeilingForModel(model));
|
|
112
|
-
return supported
|
|
112
|
+
return supported
|
|
113
|
+
? snapReasoningEffortToSupported(clamped, supported)
|
|
114
|
+
: clamped;
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
/** Values accepted by the Responses API `text.verbosity` parameter. */
|
|
@@ -280,7 +282,11 @@ export class OpenAIResponsesProvider implements Provider {
|
|
|
280
282
|
const effort = configObj?.effort as string | undefined;
|
|
281
283
|
const verbosity = configObj?.verbosity as string | undefined;
|
|
282
284
|
const usageAttributionHeaders = configObj?.usageAttributionHeaders as
|
|
283
|
-
Record<string, string>
|
|
285
|
+
| Record<string, string>
|
|
286
|
+
| undefined;
|
|
287
|
+
const perRequestHeaders = configObj?.requestHeaders as
|
|
288
|
+
| Record<string, string>
|
|
289
|
+
| undefined;
|
|
284
290
|
const disableCache = configObj?.disableCache === true;
|
|
285
291
|
const disableTurnStartCache = configObj?.disableTurnStartCache === true;
|
|
286
292
|
const promptCacheKey =
|
|
@@ -463,6 +469,7 @@ export class OpenAIResponsesProvider implements Provider {
|
|
|
463
469
|
const requestHeaders = {
|
|
464
470
|
...this.requestHeaders,
|
|
465
471
|
...(usageAttributionHeaders ?? {}),
|
|
472
|
+
...(perRequestHeaders ?? {}),
|
|
466
473
|
};
|
|
467
474
|
const stream = await responsesApi.create(
|
|
468
475
|
{ ...params, stream: true },
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
EMPTY_ASSISTANT_TURN_PLACEHOLDER,
|
|
10
10
|
OpenAIChatCompletionsProvider,
|
|
11
11
|
} from "../openai/chat-completions-provider.js";
|
|
12
|
+
import { OpenAIResponsesProvider } from "../openai/responses-provider.js";
|
|
13
|
+
import type { Message } from "../types.js";
|
|
12
14
|
import {
|
|
13
15
|
buildOpenCodeRequestHeaders,
|
|
14
16
|
OPENCODE_GO_BASE_URL,
|
|
@@ -16,11 +18,63 @@ import {
|
|
|
16
18
|
OPENCODE_SESSION_HEADER,
|
|
17
19
|
OPENCODE_ZEN_BASE_URL,
|
|
18
20
|
OpenCodeProvider,
|
|
21
|
+
OpenCodeResponsesProvider,
|
|
19
22
|
resetOpenCodeFallbackSessionForTests,
|
|
20
23
|
resolveOpenCodeBaseURL,
|
|
21
24
|
resolveOpenCodeRequestHeaders,
|
|
25
|
+
resolveOpenCodeTransport,
|
|
22
26
|
} from "./client.js";
|
|
23
27
|
|
|
28
|
+
const USER_TURN: Message[] = [
|
|
29
|
+
{ role: "user", content: [{ type: "text", text: "question" }] },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
/** Stub both wires on an OpenCodeProvider and record which one was called. */
|
|
33
|
+
function stubTransports(provider: OpenCodeProvider) {
|
|
34
|
+
const chat: unknown[] = [];
|
|
35
|
+
const responses: Array<{ params: unknown; options: unknown }> = [];
|
|
36
|
+
(provider as unknown as { client: unknown }).client = {
|
|
37
|
+
chat: {
|
|
38
|
+
completions: {
|
|
39
|
+
create: async (params: unknown) => {
|
|
40
|
+
chat.push(params);
|
|
41
|
+
return {
|
|
42
|
+
async *[Symbol.asyncIterator]() {
|
|
43
|
+
yield {
|
|
44
|
+
choices: [{ delta: { content: "ok" }, finish_reason: "stop" }],
|
|
45
|
+
usage: { prompt_tokens: 2, completion_tokens: 1 },
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const inner = (
|
|
54
|
+
provider as unknown as { getResponsesInner(): OpenCodeResponsesProvider }
|
|
55
|
+
).getResponsesInner();
|
|
56
|
+
(inner as unknown as { client: unknown }).client = {
|
|
57
|
+
responses: {
|
|
58
|
+
create: async (params: unknown, options: unknown) => {
|
|
59
|
+
responses.push({ params, options });
|
|
60
|
+
return {
|
|
61
|
+
async *[Symbol.asyncIterator]() {
|
|
62
|
+
yield { type: "response.output_text.delta", delta: "ok" };
|
|
63
|
+
yield {
|
|
64
|
+
type: "response.completed",
|
|
65
|
+
response: {
|
|
66
|
+
status: "completed",
|
|
67
|
+
usage: { input_tokens: 2, output_tokens: 1 },
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
return { chat, responses };
|
|
76
|
+
}
|
|
77
|
+
|
|
24
78
|
describe("resolveOpenCodeBaseURL", () => {
|
|
25
79
|
test("defaults to OpenCode Zen", () => {
|
|
26
80
|
expect(resolveOpenCodeBaseURL()).toBe(OPENCODE_ZEN_BASE_URL);
|
|
@@ -241,3 +295,127 @@ describe("OpenCodeProvider", () => {
|
|
|
241
295
|
expect(assistantMsg.content).toBe(EMPTY_ASSISTANT_TURN_PLACEHOLDER);
|
|
242
296
|
});
|
|
243
297
|
});
|
|
298
|
+
|
|
299
|
+
describe("resolveOpenCodeTransport", () => {
|
|
300
|
+
test("routes the known responses-only models to the Responses API", () => {
|
|
301
|
+
expect(resolveOpenCodeTransport("muse-spark-1.2-contributor-free")).toBe(
|
|
302
|
+
"responses",
|
|
303
|
+
);
|
|
304
|
+
expect(resolveOpenCodeTransport("muse-spark-1.3-contributor-free")).toBe(
|
|
305
|
+
"responses",
|
|
306
|
+
);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test("defaults every other model to chat completions", () => {
|
|
310
|
+
expect(resolveOpenCodeTransport("mimo-v2.5-free")).toBe("chat_completions");
|
|
311
|
+
expect(resolveOpenCodeTransport("gpt-5.4")).toBe("chat_completions");
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
test("an explicit transport wins over the built-in default", () => {
|
|
315
|
+
expect(resolveOpenCodeTransport("mimo-v2.5-free", "responses")).toBe(
|
|
316
|
+
"responses",
|
|
317
|
+
);
|
|
318
|
+
expect(
|
|
319
|
+
resolveOpenCodeTransport(
|
|
320
|
+
"muse-spark-1.2-contributor-free",
|
|
321
|
+
"chat_completions",
|
|
322
|
+
),
|
|
323
|
+
).toBe("chat_completions");
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
describe("OpenCodeResponsesProvider", () => {
|
|
328
|
+
test("is the Responses transport under the opencode name on OpenCode Zen", () => {
|
|
329
|
+
const provider = new OpenCodeResponsesProvider(
|
|
330
|
+
"sk-test",
|
|
331
|
+
"muse-spark-1.2-contributor-free",
|
|
332
|
+
);
|
|
333
|
+
expect(provider).toBeInstanceOf(OpenAIResponsesProvider);
|
|
334
|
+
expect(provider.name).toBe("opencode");
|
|
335
|
+
expect(
|
|
336
|
+
(provider as unknown as { client: { baseURL?: string } }).client.baseURL,
|
|
337
|
+
).toBe(OPENCODE_ZEN_BASE_URL);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test("keeps a configured OpenCode Go origin", () => {
|
|
341
|
+
const provider = new OpenCodeResponsesProvider(
|
|
342
|
+
"sk-test",
|
|
343
|
+
"muse-spark-1.2-contributor-free",
|
|
344
|
+
{ baseURL: OPENCODE_GO_BASE_URL },
|
|
345
|
+
);
|
|
346
|
+
expect(
|
|
347
|
+
(provider as unknown as { client: { baseURL?: string } }).client.baseURL,
|
|
348
|
+
).toBe(OPENCODE_GO_BASE_URL);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
describe("OpenCodeProvider transport selection", () => {
|
|
353
|
+
test("sends a responses-only model through the Responses API with OpenCode headers", async () => {
|
|
354
|
+
const provider = new OpenCodeProvider(
|
|
355
|
+
"sk-test",
|
|
356
|
+
"muse-spark-1.2-contributor-free",
|
|
357
|
+
);
|
|
358
|
+
const { chat, responses } = stubTransports(provider);
|
|
359
|
+
|
|
360
|
+
const result = await provider.sendMessage(USER_TURN, {
|
|
361
|
+
config: {
|
|
362
|
+
requestHeaders: {
|
|
363
|
+
[OPENCODE_SESSION_HEADER]: "conv-xyz",
|
|
364
|
+
[OPENCODE_REQUEST_HEADER]: "req-123",
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
expect(chat).toHaveLength(0);
|
|
370
|
+
expect(responses).toHaveLength(1);
|
|
371
|
+
expect((responses[0]!.params as { model: string }).model).toBe(
|
|
372
|
+
"muse-spark-1.2-contributor-free",
|
|
373
|
+
);
|
|
374
|
+
const options = responses[0]!.options as {
|
|
375
|
+
headers?: Record<string, string>;
|
|
376
|
+
};
|
|
377
|
+
expect(options.headers?.[OPENCODE_SESSION_HEADER]).toBe("conv-xyz");
|
|
378
|
+
expect(options.headers?.[OPENCODE_REQUEST_HEADER]).toBe("req-123");
|
|
379
|
+
expect(options.headers).not.toHaveProperty("session_id");
|
|
380
|
+
expect(result.content).toEqual([{ type: "text", text: "ok" }]);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test("keeps a chat-completions model on the chat wire", async () => {
|
|
384
|
+
const provider = new OpenCodeProvider("sk-test", "mimo-v2.5-free");
|
|
385
|
+
const { chat, responses } = stubTransports(provider);
|
|
386
|
+
|
|
387
|
+
await provider.sendMessage(USER_TURN);
|
|
388
|
+
|
|
389
|
+
expect(chat).toHaveLength(1);
|
|
390
|
+
expect(responses).toHaveLength(0);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
test("a per-call model override picks the transport that model needs", async () => {
|
|
394
|
+
const provider = new OpenCodeProvider("sk-test", "mimo-v2.5-free");
|
|
395
|
+
const { chat, responses } = stubTransports(provider);
|
|
396
|
+
|
|
397
|
+
await provider.sendMessage(USER_TURN, {
|
|
398
|
+
config: { model: "muse-spark-1.2-contributor-free" },
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
expect(chat).toHaveLength(0);
|
|
402
|
+
expect(responses).toHaveLength(1);
|
|
403
|
+
expect((responses[0]!.params as { model: string }).model).toBe(
|
|
404
|
+
"muse-spark-1.2-contributor-free",
|
|
405
|
+
);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test("an explicit connection transport overrides the built-in default", () => {
|
|
409
|
+
const provider = new OpenCodeProvider("sk-test", "mimo-v2.5-free", {
|
|
410
|
+
modelTransports: {
|
|
411
|
+
"mimo-v2.5-free": "responses",
|
|
412
|
+
"muse-spark-1.2-contributor-free": "chat_completions",
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
expect(provider.resolveTransport("mimo-v2.5-free")).toBe("responses");
|
|
416
|
+
expect(provider.resolveTransport("muse-spark-1.2-contributor-free")).toBe(
|
|
417
|
+
"chat_completions",
|
|
418
|
+
);
|
|
419
|
+
expect(provider.resolveTransport("gpt-5.4")).toBe("chat_completions");
|
|
420
|
+
});
|
|
421
|
+
});
|
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
|
|
3
3
|
import { getExistingDeviceId } from "../../util/device-id.js";
|
|
4
4
|
import { OpenAIChatCompletionsProvider } from "../openai/chat-completions-provider.js";
|
|
5
|
+
import { OpenAIResponsesProvider } from "../openai/responses-provider.js";
|
|
5
6
|
import type {
|
|
6
7
|
Message,
|
|
7
8
|
ProviderResponse,
|
|
@@ -13,9 +14,46 @@ export const OPENCODE_GO_BASE_URL = "https://opencode.ai/zen/go/v1";
|
|
|
13
14
|
export const OPENCODE_SESSION_HEADER = "x-opencode-session";
|
|
14
15
|
export const OPENCODE_REQUEST_HEADER = "x-opencode-request";
|
|
15
16
|
|
|
17
|
+
/** Wire API an OpenCode model is served over. */
|
|
18
|
+
export type OpenCodeTransport = "chat_completions" | "responses";
|
|
19
|
+
|
|
16
20
|
export interface OpenCodeProviderOptions {
|
|
17
21
|
baseURL?: string;
|
|
18
22
|
streamTimeoutMs?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Explicit per-model transport from the connection's model entries
|
|
25
|
+
* (`ConnectionModel.transport`). Wins over the built-in
|
|
26
|
+
* {@link OPENCODE_RESPONSES_ONLY_MODELS} default for that model.
|
|
27
|
+
*/
|
|
28
|
+
modelTransports?: Readonly<Record<string, OpenCodeTransport>>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* OpenCode Zen models served only by the Responses API: Zen answers
|
|
33
|
+
* `/chat/completions` for them with HTTP 500 and completes the same request
|
|
34
|
+
* on `/responses`. OpenCode's own client picks the transport per model from
|
|
35
|
+
* its catalog's `api.endpoint`; the assistant has no such feed, so the known
|
|
36
|
+
* ids live here and a connection model entry can override the choice.
|
|
37
|
+
*/
|
|
38
|
+
export const OPENCODE_RESPONSES_ONLY_MODELS: ReadonlySet<string> = new Set([
|
|
39
|
+
"muse-spark-1.2-contributor-free",
|
|
40
|
+
"muse-spark-1.3-contributor-free",
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Transport for an OpenCode model: an explicit connection-level choice wins,
|
|
45
|
+
* otherwise the built-in responses-only list decides.
|
|
46
|
+
*/
|
|
47
|
+
export function resolveOpenCodeTransport(
|
|
48
|
+
model: string,
|
|
49
|
+
configured?: OpenCodeTransport,
|
|
50
|
+
): OpenCodeTransport {
|
|
51
|
+
if (configured) {
|
|
52
|
+
return configured;
|
|
53
|
+
}
|
|
54
|
+
return OPENCODE_RESPONSES_ONLY_MODELS.has(model)
|
|
55
|
+
? "responses"
|
|
56
|
+
: "chat_completions";
|
|
19
57
|
}
|
|
20
58
|
|
|
21
59
|
/**
|
|
@@ -82,7 +120,44 @@ export function resolveOpenCodeRequestHeaders(
|
|
|
82
120
|
});
|
|
83
121
|
}
|
|
84
122
|
|
|
123
|
+
type OpenCodeTransportOptions = Pick<
|
|
124
|
+
OpenCodeProviderOptions,
|
|
125
|
+
"baseURL" | "streamTimeoutMs"
|
|
126
|
+
>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Responses-API transport for OpenCode. Shares the chat client's origin
|
|
130
|
+
* resolution and provider name, so `RetryProvider` stamps the same
|
|
131
|
+
* `x-opencode-session` / `x-opencode-request` headers on its requests.
|
|
132
|
+
*/
|
|
133
|
+
export class OpenCodeResponsesProvider extends OpenAIResponsesProvider {
|
|
134
|
+
constructor(
|
|
135
|
+
apiKey: string,
|
|
136
|
+
model: string,
|
|
137
|
+
options: OpenCodeTransportOptions = {},
|
|
138
|
+
) {
|
|
139
|
+
super(apiKey, model, {
|
|
140
|
+
baseURL: resolveOpenCodeBaseURL(options.baseURL),
|
|
141
|
+
providerName: "opencode",
|
|
142
|
+
providerLabel: "OpenCode",
|
|
143
|
+
streamTimeoutMs: options.streamTimeoutMs,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* OpenCode adapter. Chat completions is the default wire; models resolved to
|
|
150
|
+
* the Responses transport (see {@link resolveOpenCodeTransport}) are delegated
|
|
151
|
+
* to an {@link OpenCodeResponsesProvider} on the same origin. The choice is
|
|
152
|
+
* made per send from the effective model, so a per-call model override lands
|
|
153
|
+
* on the transport that model needs.
|
|
154
|
+
*/
|
|
85
155
|
export class OpenCodeProvider extends OpenAIChatCompletionsProvider {
|
|
156
|
+
private readonly openCodeApiKey: string;
|
|
157
|
+
private readonly transportOptions: OpenCodeTransportOptions;
|
|
158
|
+
private readonly modelTransports: ReadonlyMap<string, OpenCodeTransport>;
|
|
159
|
+
private responsesInner: OpenCodeResponsesProvider | undefined;
|
|
160
|
+
|
|
86
161
|
constructor(
|
|
87
162
|
apiKey: string,
|
|
88
163
|
model: string,
|
|
@@ -96,20 +171,33 @@ export class OpenCodeProvider extends OpenAIChatCompletionsProvider {
|
|
|
96
171
|
assistantReasoningField: "reasoning_content",
|
|
97
172
|
omitToolChoiceWhenReasoning: true,
|
|
98
173
|
});
|
|
174
|
+
this.openCodeApiKey = apiKey;
|
|
175
|
+
this.transportOptions = {
|
|
176
|
+
baseURL: options.baseURL,
|
|
177
|
+
streamTimeoutMs: options.streamTimeoutMs,
|
|
178
|
+
};
|
|
179
|
+
this.modelTransports = new Map(
|
|
180
|
+
Object.entries(options.modelTransports ?? {}),
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Transport a model is sent over through this adapter. */
|
|
185
|
+
resolveTransport(model: string): OpenCodeTransport {
|
|
186
|
+
return resolveOpenCodeTransport(model, this.modelTransports.get(model));
|
|
99
187
|
}
|
|
100
188
|
|
|
101
189
|
/**
|
|
102
190
|
* Transport-level backstop so a call that reaches this provider without
|
|
103
191
|
* going through `RetryProvider` (or with no config at all) still carries
|
|
104
|
-
* the session and request headers zen/go requires. Headers
|
|
105
|
-
* already resolved (conversation-derived) win.
|
|
192
|
+
* the session and request headers zen/go requires on either wire. Headers
|
|
193
|
+
* the caller already resolved (conversation-derived) win.
|
|
106
194
|
*/
|
|
107
195
|
override async sendMessage(
|
|
108
196
|
messages: Message[],
|
|
109
197
|
options?: SendMessageOptions,
|
|
110
198
|
): Promise<ProviderResponse> {
|
|
111
199
|
const config = options?.config ?? {};
|
|
112
|
-
|
|
200
|
+
const stamped: SendMessageOptions = {
|
|
113
201
|
...options,
|
|
114
202
|
config: {
|
|
115
203
|
...config,
|
|
@@ -118,6 +206,21 @@ export class OpenCodeProvider extends OpenAIChatCompletionsProvider {
|
|
|
118
206
|
...config.requestHeaders,
|
|
119
207
|
},
|
|
120
208
|
},
|
|
121
|
-
}
|
|
209
|
+
};
|
|
210
|
+
if (
|
|
211
|
+
this.resolveTransport(this.resolveEffectiveModel(options)) === "responses"
|
|
212
|
+
) {
|
|
213
|
+
return this.getResponsesInner().sendMessage(messages, stamped);
|
|
214
|
+
}
|
|
215
|
+
return super.sendMessage(messages, stamped);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private getResponsesInner(): OpenCodeResponsesProvider {
|
|
219
|
+
this.responsesInner ??= new OpenCodeResponsesProvider(
|
|
220
|
+
this.openCodeApiKey,
|
|
221
|
+
this.defaultModel,
|
|
222
|
+
this.transportOptions,
|
|
223
|
+
);
|
|
224
|
+
return this.responsesInner;
|
|
122
225
|
}
|
|
123
226
|
}
|
|
@@ -270,15 +270,6 @@ export class OpenRouterProvider extends OpenAIChatCompletionsProvider {
|
|
|
270
270
|
return openRouterOutputTokenLimitField(model);
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
-
private resolveEffectiveModel(options?: SendMessageOptions): string {
|
|
274
|
-
const config = options?.config as Record<string, unknown> | undefined;
|
|
275
|
-
const override =
|
|
276
|
-
typeof config?.model === "string" && config.model.trim().length > 0
|
|
277
|
-
? config.model.trim()
|
|
278
|
-
: undefined;
|
|
279
|
-
return override ?? this.defaultModel;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
273
|
private getAnthropicInner(): AnthropicProvider {
|
|
283
274
|
if (!this.anthropicInner) {
|
|
284
275
|
this.anthropicInner = new AnthropicProvider(
|
|
@@ -112,15 +112,6 @@ export class VercelAIGatewayProvider extends OpenAIChatCompletionsProvider {
|
|
|
112
112
|
return Object.keys(reasoning).length > 0 ? { reasoning } : {};
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
private resolveEffectiveModel(options?: SendMessageOptions): string {
|
|
116
|
-
const config = options?.config as Record<string, unknown> | undefined;
|
|
117
|
-
const override =
|
|
118
|
-
typeof config?.model === "string" && config.model.trim().length > 0
|
|
119
|
-
? config.model.trim()
|
|
120
|
-
: undefined;
|
|
121
|
-
return override ?? this.defaultModel;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
115
|
private getAnthropicInner(): AnthropicProvider {
|
|
125
116
|
if (!this.anthropicInner) {
|
|
126
117
|
this.anthropicInner = new AnthropicProvider(
|
|
@@ -1709,3 +1709,39 @@ describe("Route policy declarations", () => {
|
|
|
1709
1709
|
expect(route.policy!.requiredScopes).toContain("settings.write");
|
|
1710
1710
|
});
|
|
1711
1711
|
});
|
|
1712
|
+
|
|
1713
|
+
describe("models[].transport", () => {
|
|
1714
|
+
test("persists an explicit transport on an opencode connection", async () => {
|
|
1715
|
+
const result = (await call(
|
|
1716
|
+
findHandler("inference_provider_connections_create"),
|
|
1717
|
+
{
|
|
1718
|
+
body: {
|
|
1719
|
+
name: "opencode-transport",
|
|
1720
|
+
provider: "opencode",
|
|
1721
|
+
auth: { type: "api_key", credential: "vault/opencode/key" },
|
|
1722
|
+
models: [
|
|
1723
|
+
{ id: "custom-muse", transport: "responses" },
|
|
1724
|
+
{ id: "mimo-v2.5-free" },
|
|
1725
|
+
],
|
|
1726
|
+
},
|
|
1727
|
+
},
|
|
1728
|
+
)) as { models: unknown };
|
|
1729
|
+
expect(result.models).toEqual([
|
|
1730
|
+
{ id: "custom-muse", transport: "responses" },
|
|
1731
|
+
{ id: "mimo-v2.5-free" },
|
|
1732
|
+
]);
|
|
1733
|
+
});
|
|
1734
|
+
|
|
1735
|
+
test("rejects transport on a provider that fixes its transport", async () => {
|
|
1736
|
+
await expect(
|
|
1737
|
+
call(findHandler("inference_provider_connections_create"), {
|
|
1738
|
+
body: {
|
|
1739
|
+
name: "compat-transport",
|
|
1740
|
+
provider: "openai-compatible",
|
|
1741
|
+
base_url: "http://localhost:1234/v1",
|
|
1742
|
+
models: [{ id: "my-model", transport: "responses" }],
|
|
1743
|
+
},
|
|
1744
|
+
}),
|
|
1745
|
+
).rejects.toThrow(/transport is only valid for opencode/);
|
|
1746
|
+
});
|
|
1747
|
+
});
|
|
@@ -183,6 +183,17 @@ async function parseCustomProviderFields(
|
|
|
183
183
|
if (!parsed.success) {
|
|
184
184
|
throw new BadRequestError(`Invalid models: ${parsed.error.message}`);
|
|
185
185
|
}
|
|
186
|
+
// Only OpenCode serves both OpenAI-style transports from one origin;
|
|
187
|
+
// every other provider fixes its transport, so a stored value there
|
|
188
|
+
// would be a setting with no effect.
|
|
189
|
+
if (
|
|
190
|
+
provider !== "opencode" &&
|
|
191
|
+
parsed.data.some((m) => m.transport !== undefined)
|
|
192
|
+
) {
|
|
193
|
+
throw new BadRequestError(
|
|
194
|
+
`models[].transport is only valid for opencode connections. Remove transport from the model entries.`,
|
|
195
|
+
);
|
|
196
|
+
}
|
|
186
197
|
out.models = parsed.data;
|
|
187
198
|
}
|
|
188
199
|
}
|
|
@@ -1060,6 +1060,8 @@ async function handleManagedConnect({ body = {} }: RouteHandlerArgs) {
|
|
|
1060
1060
|
provider: string;
|
|
1061
1061
|
scopes?: string[];
|
|
1062
1062
|
redirect_after_connect?: string;
|
|
1063
|
+
/** Per-tenant providers (Shopify): the customer's own host. */
|
|
1064
|
+
tenant_host?: string;
|
|
1063
1065
|
};
|
|
1064
1066
|
|
|
1065
1067
|
if (!b.provider) {
|
|
@@ -1076,6 +1078,13 @@ async function handleManagedConnect({ body = {} }: RouteHandlerArgs) {
|
|
|
1076
1078
|
}
|
|
1077
1079
|
reqBody.redirect_after_connect =
|
|
1078
1080
|
b.redirect_after_connect ?? "/account/oauth/complete";
|
|
1081
|
+
// Only forwarded when present: the platform validates it against the
|
|
1082
|
+
// provider's pattern and rejects per-tenant providers that omit it.
|
|
1083
|
+
const tenantHost =
|
|
1084
|
+
typeof b.tenant_host === "string" ? b.tenant_host.trim() : "";
|
|
1085
|
+
if (tenantHost) {
|
|
1086
|
+
reqBody.tenant_host = tenantHost;
|
|
1087
|
+
}
|
|
1079
1088
|
|
|
1080
1089
|
const response = await client.fetch(startPath, {
|
|
1081
1090
|
method: "POST",
|
|
@@ -397,6 +397,13 @@ export const oauthProviderSummarySchema = z.object({
|
|
|
397
397
|
supports_managed_mode: z.boolean(),
|
|
398
398
|
managed_service_is_paid: z.boolean(),
|
|
399
399
|
feature_flag: z.string().nullable(),
|
|
400
|
+
tenant_host: z
|
|
401
|
+
.object({
|
|
402
|
+
pattern: z.string(),
|
|
403
|
+
label: z.string(),
|
|
404
|
+
placeholder: z.string(),
|
|
405
|
+
})
|
|
406
|
+
.nullable(),
|
|
400
407
|
acts_as: z.enum(["user", "assistant"]),
|
|
401
408
|
});
|
|
402
409
|
|