@vellumai/assistant 0.11.3-dev.202608180132.6a0b3da → 0.11.3-dev.202608181609.6fec8f9
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/ARCHITECTURE.md +19 -4
- package/openapi.yaml +3 -75
- package/package.json +1 -1
- package/src/__tests__/assistant-feature-flag-guard.test.ts +25 -3
- package/src/__tests__/document-sync-tags.test.ts +0 -75
- package/src/__tests__/init-feature-flag-overrides.test.ts +49 -0
- package/src/config/__tests__/balanced-model-experiment.test.ts +278 -0
- package/src/config/assistant-feature-flags.ts +30 -15
- package/src/config/balanced-model-experiment.ts +35 -0
- package/src/config/default-profile-catalog.ts +96 -4
- package/src/config/feature-flag-registry.json +10 -10
- package/src/daemon/lifecycle.ts +14 -1
- package/src/documents/document-store.ts +5 -235
- package/src/ipc/gateway-flag-listener.ts +17 -3
- package/src/persistence/migrations/360-add-document-workspace-path.ts +5 -14
- package/src/persistence/schema/documents.ts +4 -4
- package/src/plugins/mtime-cache.ts +1 -1
- package/src/runtime/routes/__tests__/conversation-list-routes.test.ts +37 -1
- package/src/runtime/routes/__tests__/plugins-routes.test.ts +88 -35
- package/src/runtime/routes/conversation-list-routes.ts +2 -1
- package/src/runtime/routes/documents-routes.ts +3 -222
- package/src/runtime/routes/plugins-routes.ts +17 -5
- package/src/runtime/routes/workspace-routes.ts +0 -9
- package/src/runtime/routes/workspace-utils.ts +3 -13
- package/src/runtime/services/conversation-serializer.ts +7 -2
- package/src/__tests__/document-workspace-file.test.ts +0 -467
package/ARCHITECTURE.md
CHANGED
|
@@ -888,17 +888,29 @@ startup pass in `daemon/lifecycle.ts` (after plugin init, before the
|
|
|
888
888
|
scheduler starts), the end of `reconcilePluginSourcesNow()` in
|
|
889
889
|
`plugins/mtime-cache.ts` (install/uninstall/upgrade and sentinel-driven
|
|
890
890
|
changes), the plugin enable/disable routes, and a 60s backstop sweep
|
|
891
|
-
registered with the HTTP server's background sweeps.
|
|
891
|
+
registered with the HTTP server's background sweeps. The desired set is
|
|
892
|
+
gated on activation as well as on what is on disk:
|
|
893
|
+
`collectDesiredDeclarations` skips any plugin directory that
|
|
894
|
+
`isPluginDirActivated` (`plugins/mtime-cache.ts`) does not report as brought
|
|
895
|
+
up in this process, so a directory that merely exists under the plugins root
|
|
896
|
+
never arms a row.
|
|
892
897
|
|
|
893
898
|
Reconcile lag never lets a disabled plugin run. The disable path writes a
|
|
894
899
|
`.disabled` sentinel that only a reconcile pass turns into disarmed rows, so
|
|
895
900
|
the scheduler re-reads the sentinel at fire time and records a skipped run
|
|
896
901
|
instead of executing a claimed row whose plugin is off. Run-now applies the
|
|
897
|
-
same boundary through `
|
|
902
|
+
same boundary through `pluginScheduleSourceAvailable`
|
|
903
|
+
(`schedule/plugin-schedule-availability.ts`), which composes the activation
|
|
904
|
+
ledger with `declarationExistsOnDisk`. That disk probe also covers a plugin
|
|
898
905
|
whose manifest no longer parses, a declaration directory that is gone, and a
|
|
899
906
|
plugin root or declaration directory resolving outside the tree it belongs to
|
|
900
907
|
(the same `isInsidePluginRoot` containment the loader applies before importing
|
|
901
|
-
a plugin).
|
|
908
|
+
a plugin). Fire time in the scheduler and the user re-enable path in
|
|
909
|
+
`schedule-store.ts` deliberately use the disk probe on its own, because both
|
|
910
|
+
can run outside the daemon process, where the activation ledger is empty and
|
|
911
|
+
every plugin would read as unactivated. The reconciler's sweep disarms the
|
|
912
|
+
rows of a plugin it has not activated within one pass, which bounds what
|
|
913
|
+
those disk-only probes can let through.
|
|
902
914
|
|
|
903
915
|
A declaration that stops parsing keeps its execute row armed on the message
|
|
904
916
|
already stored in the row, but disarms its script rows: a script row fires its
|
|
@@ -911,7 +923,10 @@ timezone, message/script, retry policy, `definition_hash`); the execution
|
|
|
911
923
|
engine owns runtime columns (`next_run_at`, `status`, `last_*`,
|
|
912
924
|
`retry_count`) and its latches are never overridden; the user owns
|
|
913
925
|
`user_enabled`, a sticky override consulted when computing effective
|
|
914
|
-
`enabled`.
|
|
926
|
+
`enabled`. `definition_hash` is a sha256 over the relPath and bytes of
|
|
927
|
+
exactly two files, the declaration's `config.json` and its entrypoint, so
|
|
928
|
+
nothing else under `schedules/<name>/` can produce a definition change.
|
|
929
|
+
Nothing ever writes to plugin files. Execution itself is
|
|
915
930
|
unchanged: declared rows fire through the same `claimDueSchedules` path as
|
|
916
931
|
imperative ones.
|
|
917
932
|
|
package/openapi.yaml
CHANGED
|
@@ -6965,7 +6965,9 @@ paths:
|
|
|
6965
6965
|
get:
|
|
6966
6966
|
operationId: conversations_by_id_get
|
|
6967
6967
|
summary: Get conversation detail
|
|
6968
|
-
description:
|
|
6968
|
+
description:
|
|
6969
|
+
Retrieve a single conversation with full metadata. Rows the listing hides by type (legacy private rows) are
|
|
6970
|
+
not found here either.
|
|
6969
6971
|
tags:
|
|
6970
6972
|
- conversations
|
|
6971
6973
|
parameters:
|
|
@@ -10918,11 +10920,6 @@ paths:
|
|
|
10918
10920
|
type: number
|
|
10919
10921
|
updatedAt:
|
|
10920
10922
|
type: number
|
|
10921
|
-
workspacePath:
|
|
10922
|
-
anyOf:
|
|
10923
|
-
- type: string
|
|
10924
|
-
- type: "null"
|
|
10925
|
-
description: Workspace-relative file this document is bound to, or null
|
|
10926
10923
|
required:
|
|
10927
10924
|
- success
|
|
10928
10925
|
- surfaceId
|
|
@@ -10932,7 +10929,6 @@ paths:
|
|
|
10932
10929
|
- wordCount
|
|
10933
10930
|
- createdAt
|
|
10934
10931
|
- updatedAt
|
|
10935
|
-
- workspacePath
|
|
10936
10932
|
additionalProperties: false
|
|
10937
10933
|
/v1/documents/{id}/comments:
|
|
10938
10934
|
get:
|
|
@@ -11350,74 +11346,6 @@ paths:
|
|
|
11350
11346
|
schema:
|
|
11351
11347
|
type: string
|
|
11352
11348
|
format: binary
|
|
11353
|
-
/v1/documents/for-workspace-file:
|
|
11354
|
-
post:
|
|
11355
|
-
operationId: documents_forworkspacefile_post
|
|
11356
|
-
summary: Get or create the document for a workspace markdown file
|
|
11357
|
-
description:
|
|
11358
|
-
"Return the document bound to a workspace markdown file, creating it on first open. The file is the source
|
|
11359
|
-
of truth at open time: stored content that has drifted from the file is refreshed from disk before the document
|
|
11360
|
-
is returned."
|
|
11361
|
-
tags:
|
|
11362
|
-
- documents
|
|
11363
|
-
requestBody:
|
|
11364
|
-
required: true
|
|
11365
|
-
content:
|
|
11366
|
-
application/json:
|
|
11367
|
-
schema:
|
|
11368
|
-
type: object
|
|
11369
|
-
properties:
|
|
11370
|
-
path:
|
|
11371
|
-
type: string
|
|
11372
|
-
description: Workspace-relative path to a .md/.markdown file
|
|
11373
|
-
conversationId:
|
|
11374
|
-
type: string
|
|
11375
|
-
description: Conversation the document is opened from
|
|
11376
|
-
required:
|
|
11377
|
-
- path
|
|
11378
|
-
- conversationId
|
|
11379
|
-
responses:
|
|
11380
|
-
"200":
|
|
11381
|
-
description: Successful response
|
|
11382
|
-
content:
|
|
11383
|
-
application/json:
|
|
11384
|
-
schema:
|
|
11385
|
-
type: object
|
|
11386
|
-
properties:
|
|
11387
|
-
success:
|
|
11388
|
-
type: boolean
|
|
11389
|
-
surfaceId:
|
|
11390
|
-
type: string
|
|
11391
|
-
conversationId:
|
|
11392
|
-
type: string
|
|
11393
|
-
title:
|
|
11394
|
-
type: string
|
|
11395
|
-
content:
|
|
11396
|
-
type: string
|
|
11397
|
-
wordCount:
|
|
11398
|
-
type: number
|
|
11399
|
-
createdAt:
|
|
11400
|
-
type: number
|
|
11401
|
-
updatedAt:
|
|
11402
|
-
type: number
|
|
11403
|
-
workspacePath:
|
|
11404
|
-
anyOf:
|
|
11405
|
-
- type: string
|
|
11406
|
-
- type: "null"
|
|
11407
|
-
description: Workspace-relative file this document is bound to, or null
|
|
11408
|
-
required:
|
|
11409
|
-
- success
|
|
11410
|
-
- surfaceId
|
|
11411
|
-
- conversationId
|
|
11412
|
-
- title
|
|
11413
|
-
- content
|
|
11414
|
-
- wordCount
|
|
11415
|
-
- createdAt
|
|
11416
|
-
- updatedAt
|
|
11417
|
-
- workspacePath
|
|
11418
|
-
additionalProperties: false
|
|
11419
|
-
"422":
|
|
11420
|
-
description: Path is not a markdown file
|
|
11421
11349
|
/v1/domain/register:
|
|
11422
11350
|
post:
|
|
11423
11351
|
operationId: domain_register_post
|
package/package.json
CHANGED
|
@@ -40,7 +40,10 @@ interface RegistryFlag {
|
|
|
40
40
|
key: string;
|
|
41
41
|
label: string;
|
|
42
42
|
description: string;
|
|
43
|
-
|
|
43
|
+
/** Boolean for a gate; the winning variation's name for a multivariate flag. */
|
|
44
|
+
defaultEnabled: boolean | string;
|
|
45
|
+
/** Declared variations. Present only on multivariate flags. */
|
|
46
|
+
values?: string[];
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
interface Registry {
|
|
@@ -179,8 +182,27 @@ describe("assistant feature flag guard", () => {
|
|
|
179
182
|
const violations: string[] = [];
|
|
180
183
|
|
|
181
184
|
for (const flag of assistantFlags) {
|
|
182
|
-
|
|
183
|
-
|
|
185
|
+
// A gate declares a boolean default. A multivariate flag declares its
|
|
186
|
+
// variations in `values` and names the winning one in `defaultEnabled`,
|
|
187
|
+
// which the resolver serves verbatim to string consumers.
|
|
188
|
+
if (flag.values === undefined) {
|
|
189
|
+
if (typeof flag.defaultEnabled !== "boolean") {
|
|
190
|
+
violations.push(
|
|
191
|
+
`${flag.key}: missing or non-boolean 'defaultEnabled'`,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
} else if (
|
|
195
|
+
!Array.isArray(flag.values) ||
|
|
196
|
+
flag.values.length < 2 ||
|
|
197
|
+
flag.values.some((value) => typeof value !== "string")
|
|
198
|
+
) {
|
|
199
|
+
violations.push(
|
|
200
|
+
`${flag.key}: 'values' must list at least two string variations`,
|
|
201
|
+
);
|
|
202
|
+
} else if (!flag.values.includes(flag.defaultEnabled as string)) {
|
|
203
|
+
violations.push(
|
|
204
|
+
`${flag.key}: 'defaultEnabled' must name one of the declared 'values'`,
|
|
205
|
+
);
|
|
184
206
|
}
|
|
185
207
|
if (
|
|
186
208
|
typeof flag.description !== "string" ||
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
* the Library and the per-conversation assets list converge on every surface.
|
|
4
4
|
* Read routes and rejected writes must stay silent.
|
|
5
5
|
*/
|
|
6
|
-
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
7
|
-
import { join } from "node:path";
|
|
8
6
|
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
9
7
|
|
|
10
8
|
import type { AssistantEventEnvelope } from "../api/index.js";
|
|
@@ -24,9 +22,6 @@ import { resetDbForTesting } from "./db-test-helpers.js";
|
|
|
24
22
|
|
|
25
23
|
await initializeDb();
|
|
26
24
|
|
|
27
|
-
const workspaceDir = process.env.VELLUM_WORKSPACE_DIR!;
|
|
28
|
-
const notesDir = join(workspaceDir, "sync-notes");
|
|
29
|
-
|
|
30
25
|
const CONVERSATION_ID = "conv-doc-sync";
|
|
31
26
|
const OTHER_CONVERSATION_ID = "conv-doc-sync-other";
|
|
32
27
|
const MISSING_CONVERSATION_ID = "conv-doc-sync-missing";
|
|
@@ -110,15 +105,6 @@ async function saveViaRoute(
|
|
|
110
105
|
});
|
|
111
106
|
}
|
|
112
107
|
|
|
113
|
-
async function openWorkspaceFile(
|
|
114
|
-
path: string,
|
|
115
|
-
conversationId = CONVERSATION_ID,
|
|
116
|
-
): Promise<unknown> {
|
|
117
|
-
return await invoke("documentForWorkspaceFile", {
|
|
118
|
-
body: { path, conversationId },
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
108
|
async function linkViaRoute(
|
|
123
109
|
surfaceId: string,
|
|
124
110
|
conversationId: string,
|
|
@@ -136,12 +122,9 @@ beforeEach(() => {
|
|
|
136
122
|
db.run("DELETE FROM conversations");
|
|
137
123
|
createConversation({ id: CONVERSATION_ID });
|
|
138
124
|
createConversation({ id: OTHER_CONVERSATION_ID });
|
|
139
|
-
rmSync(notesDir, { recursive: true, force: true });
|
|
140
|
-
mkdirSync(notesDir, { recursive: true });
|
|
141
125
|
});
|
|
142
126
|
|
|
143
127
|
afterAll(() => {
|
|
144
|
-
rmSync(notesDir, { recursive: true, force: true });
|
|
145
128
|
resetDbForTesting();
|
|
146
129
|
});
|
|
147
130
|
|
|
@@ -220,67 +203,9 @@ describe("document write routes publish documents:list", () => {
|
|
|
220
203
|
expect(events).toHaveLength(1);
|
|
221
204
|
expect("originClientId" in events[0].message).toBe(false);
|
|
222
205
|
});
|
|
223
|
-
|
|
224
|
-
test("binding a workspace file publishes without an origin so the caller is not suppressed", async () => {
|
|
225
|
-
// `viewer-store.loadWorkspaceFileDocument` creates the row and invalidates
|
|
226
|
-
// nothing, so the client that opened the file is the one that most needs
|
|
227
|
-
// the invalidation.
|
|
228
|
-
writeFileSync(join(notesDir, "plan.md"), "# Plan");
|
|
229
|
-
|
|
230
|
-
const events = await captureSyncEvents(() =>
|
|
231
|
-
invoke("documentForWorkspaceFile", {
|
|
232
|
-
body: { path: "sync-notes/plan.md", conversationId: CONVERSATION_ID },
|
|
233
|
-
headers: { "x-vellum-client-id": "client-abc" },
|
|
234
|
-
}),
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
expect(events).toHaveLength(1);
|
|
238
|
-
expect("originClientId" in events[0].message).toBe(false);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
test("binding a workspace file to a new document publishes", async () => {
|
|
242
|
-
writeFileSync(join(notesDir, "plan.md"), "# Plan");
|
|
243
|
-
|
|
244
|
-
const events = await captureSyncEvents(() =>
|
|
245
|
-
openWorkspaceFile("sync-notes/plan.md"),
|
|
246
|
-
);
|
|
247
|
-
expectDocumentsChanged(events);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
test("reopening the file from another conversation publishes the new link", async () => {
|
|
251
|
-
writeFileSync(join(notesDir, "plan.md"), "# Plan");
|
|
252
|
-
await openWorkspaceFile("sync-notes/plan.md");
|
|
253
|
-
|
|
254
|
-
const events = await captureSyncEvents(() =>
|
|
255
|
-
openWorkspaceFile("sync-notes/plan.md", OTHER_CONVERSATION_ID),
|
|
256
|
-
);
|
|
257
|
-
expectDocumentsChanged(events);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
test("refreshing a document whose file changed on disk publishes", async () => {
|
|
261
|
-
const filePath = join(notesDir, "plan.md");
|
|
262
|
-
writeFileSync(filePath, "# Plan");
|
|
263
|
-
await openWorkspaceFile("sync-notes/plan.md");
|
|
264
|
-
writeFileSync(filePath, "# Plan\n\nedited outside the editor");
|
|
265
|
-
|
|
266
|
-
const events = await captureSyncEvents(() =>
|
|
267
|
-
openWorkspaceFile("sync-notes/plan.md"),
|
|
268
|
-
);
|
|
269
|
-
expectDocumentsChanged(events);
|
|
270
|
-
});
|
|
271
206
|
});
|
|
272
207
|
|
|
273
208
|
describe("document routes that change nothing the list shows stay silent", () => {
|
|
274
|
-
test("reopening an unchanged, already-linked file publishes nothing", async () => {
|
|
275
|
-
writeFileSync(join(notesDir, "plan.md"), "# Plan");
|
|
276
|
-
await openWorkspaceFile("sync-notes/plan.md");
|
|
277
|
-
|
|
278
|
-
const events = await captureSyncEvents(() =>
|
|
279
|
-
openWorkspaceFile("sync-notes/plan.md"),
|
|
280
|
-
);
|
|
281
|
-
expect(events).toEqual([]);
|
|
282
|
-
});
|
|
283
|
-
|
|
284
209
|
test("a save rejected by validation publishes nothing", async () => {
|
|
285
210
|
const events = await captureSyncEvents(async () => {
|
|
286
211
|
await expect(saveViaRoute({ title: undefined })).rejects.toThrow(
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
clearFeatureFlagOverridesCache,
|
|
12
12
|
initFeatureFlagOverrides,
|
|
13
13
|
isAssistantFeatureFlagEnabled,
|
|
14
|
+
refreshOverridesFromGateway,
|
|
14
15
|
} from "../config/assistant-feature-flags.js";
|
|
15
16
|
import { mockGatewayIpc, resetMockGatewayIpc } from "./mock-gateway-ipc.js";
|
|
16
17
|
|
|
@@ -110,3 +111,51 @@ describe("initFeatureFlagOverrides", () => {
|
|
|
110
111
|
expect(isAssistantFeatureFlagEnabled("second-call", config)).toBe(false);
|
|
111
112
|
});
|
|
112
113
|
});
|
|
114
|
+
|
|
115
|
+
describe("refreshOverridesFromGateway", () => {
|
|
116
|
+
it("replaces the cache with the new gateway values", async () => {
|
|
117
|
+
mockGatewayIpc({ "moving-flag": true });
|
|
118
|
+
await initFeatureFlagOverrides();
|
|
119
|
+
|
|
120
|
+
resetMockGatewayIpc();
|
|
121
|
+
mockGatewayIpc({ "moving-flag": false });
|
|
122
|
+
|
|
123
|
+
expect(await refreshOverridesFromGateway()).toBe(true);
|
|
124
|
+
|
|
125
|
+
const config = {} as any;
|
|
126
|
+
expect(isAssistantFeatureFlagEnabled("moving-flag", config)).toBe(false);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("keeps the last known values when the refresh fails", async () => {
|
|
130
|
+
mockGatewayIpc({ "moving-flag": true });
|
|
131
|
+
await initFeatureFlagOverrides();
|
|
132
|
+
|
|
133
|
+
resetMockGatewayIpc();
|
|
134
|
+
mockGatewayIpc(null, { error: true });
|
|
135
|
+
|
|
136
|
+
expect(await refreshOverridesFromGateway()).toBe(false);
|
|
137
|
+
|
|
138
|
+
// A failed refresh must not drop the flag to its registry default: a
|
|
139
|
+
// value the assistant selects behavior from (an experiment arm, a kill
|
|
140
|
+
// switch) would otherwise flip on one timed-out IPC call.
|
|
141
|
+
const config = {} as any;
|
|
142
|
+
expect(isAssistantFeatureFlagEnabled("moving-flag", config)).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("keeps the cache readable for the whole call", async () => {
|
|
146
|
+
mockGatewayIpc({ "moving-flag": true });
|
|
147
|
+
await initFeatureFlagOverrides();
|
|
148
|
+
|
|
149
|
+
resetMockGatewayIpc();
|
|
150
|
+
mockGatewayIpc({ "moving-flag": false });
|
|
151
|
+
|
|
152
|
+
const config = {} as any;
|
|
153
|
+
const inFlight = refreshOverridesFromGateway();
|
|
154
|
+
// A sync read landing mid-refresh sees the previous values, never an
|
|
155
|
+
// empty cache.
|
|
156
|
+
expect(isAssistantFeatureFlagEnabled("moving-flag", config)).toBe(true);
|
|
157
|
+
|
|
158
|
+
await inFlight;
|
|
159
|
+
expect(isAssistantFeatureFlagEnabled("moving-flag", config)).toBe(false);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
4
|
+
|
|
5
|
+
import type { z } from "zod";
|
|
6
|
+
|
|
7
|
+
import { setOverridesForTesting } from "../../__tests__/feature-flag-test-helpers.js";
|
|
8
|
+
import {
|
|
9
|
+
catalogMaxOutputTokens,
|
|
10
|
+
isModelInCatalog,
|
|
11
|
+
} from "../../providers/model-catalog.js";
|
|
12
|
+
import { getManagedUpstream } from "../../providers/vellum-model-routing.js";
|
|
13
|
+
import { BALANCED_MODEL_EXPERIMENT_FLAG_KEY } from "../balanced-model-experiment.js";
|
|
14
|
+
import {
|
|
15
|
+
CODE_DEFAULT_PROFILE_ENTRIES,
|
|
16
|
+
getEffectiveProfilesForProvider,
|
|
17
|
+
resolveDefaultProfileForProvider,
|
|
18
|
+
} from "../default-profile-catalog.js";
|
|
19
|
+
import { clearCachedOverrides } from "../feature-flag-cache.js";
|
|
20
|
+
import { resolveCallSiteConfig } from "../llm-resolver.js";
|
|
21
|
+
import {
|
|
22
|
+
type DefaultProviderConfig,
|
|
23
|
+
LLMSchema,
|
|
24
|
+
type ProfileEntry,
|
|
25
|
+
} from "../schemas/llm.js";
|
|
26
|
+
|
|
27
|
+
// The `experiment-balanced-model-2026-08-06` arm repoints the model the managed
|
|
28
|
+
// Balanced profile resolves to. Both the runtime resolver and the client-facing
|
|
29
|
+
// profile listing go through `defaultProfileBodyForProvider`, so both are
|
|
30
|
+
// exercised here: a disagreement between them shows the user one model beside a
|
|
31
|
+
// profile that runs another.
|
|
32
|
+
|
|
33
|
+
const FLAG = BALANCED_MODEL_EXPERIMENT_FLAG_KEY;
|
|
34
|
+
const SHIPPED_MODEL = "gpt-5.6-luna";
|
|
35
|
+
const GLM_MODEL = "accounts/fireworks/models/glm-5p2";
|
|
36
|
+
|
|
37
|
+
function setArm(value: boolean | string): void {
|
|
38
|
+
setOverridesForTesting({ [FLAG]: value });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const managed: DefaultProviderConfig = { provider: "vellum" };
|
|
42
|
+
|
|
43
|
+
function llmWithActiveBalanced(
|
|
44
|
+
overrides: Record<string, unknown> = {},
|
|
45
|
+
): z.infer<typeof LLMSchema> {
|
|
46
|
+
return LLMSchema.parse({
|
|
47
|
+
profiles: {},
|
|
48
|
+
profileOrder: [],
|
|
49
|
+
activeProfile: "balanced",
|
|
50
|
+
defaultProvider: managed,
|
|
51
|
+
...overrides,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
afterEach(() => {
|
|
56
|
+
clearCachedOverrides();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("balanced-model experiment arms", () => {
|
|
60
|
+
test("terra repoints mainAgent at gpt-5.6-terra on the managed connection", () => {
|
|
61
|
+
setArm("terra");
|
|
62
|
+
const resolved = resolveCallSiteConfig(
|
|
63
|
+
"mainAgent",
|
|
64
|
+
llmWithActiveBalanced(),
|
|
65
|
+
);
|
|
66
|
+
expect(resolved.model).toBe("gpt-5.6-terra");
|
|
67
|
+
expect(resolved.provider).toBe("vellum");
|
|
68
|
+
expect(getManagedUpstream("gpt-5.6-terra")).toBe("openai");
|
|
69
|
+
|
|
70
|
+
const entry = resolveDefaultProfileForProvider(
|
|
71
|
+
undefined,
|
|
72
|
+
"balanced",
|
|
73
|
+
managed,
|
|
74
|
+
);
|
|
75
|
+
expect(entry?.model).toBe("gpt-5.6-terra");
|
|
76
|
+
expect(entry?.provider).toBe("vellum");
|
|
77
|
+
// Routing-identity providers derive their connection per request.
|
|
78
|
+
expect(entry?.provider_connection).toBeUndefined();
|
|
79
|
+
expect(entry?.source).toBe("managed");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("glm-5p2 repoints mainAgent at GLM 5.2 within the model's output cap", () => {
|
|
83
|
+
setArm("glm-5p2");
|
|
84
|
+
const resolved = resolveCallSiteConfig(
|
|
85
|
+
"mainAgent",
|
|
86
|
+
llmWithActiveBalanced(),
|
|
87
|
+
);
|
|
88
|
+
expect(resolved.model).toBe(GLM_MODEL);
|
|
89
|
+
expect(resolved.provider).toBe("vellum");
|
|
90
|
+
|
|
91
|
+
const upstream = getManagedUpstream(GLM_MODEL);
|
|
92
|
+
expect(upstream).toBe("fireworks");
|
|
93
|
+
const cap = catalogMaxOutputTokens(upstream as string, GLM_MODEL);
|
|
94
|
+
expect(cap).toBeDefined();
|
|
95
|
+
expect(resolved.maxTokens).toBeLessThanOrEqual(cap as number);
|
|
96
|
+
// Only the model moves: the shipped token budget stands.
|
|
97
|
+
expect(resolved.maxTokens).toBe(
|
|
98
|
+
CODE_DEFAULT_PROFILE_ENTRIES.balanced.maxTokens as number,
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("an arm changes only the model of the managed balanced body", () => {
|
|
103
|
+
setArm("terra");
|
|
104
|
+
const entry = resolveDefaultProfileForProvider(
|
|
105
|
+
undefined,
|
|
106
|
+
"balanced",
|
|
107
|
+
managed,
|
|
108
|
+
);
|
|
109
|
+
const shipped = CODE_DEFAULT_PROFILE_ENTRIES.balanced;
|
|
110
|
+
expect(entry).toEqual({ ...shipped, model: "gpt-5.6-terra" });
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("the other default profiles are untouched by an arm", () => {
|
|
114
|
+
setArm("glm-5p2");
|
|
115
|
+
for (const key of [
|
|
116
|
+
"quality-optimized",
|
|
117
|
+
"cost-optimized",
|
|
118
|
+
"latency-optimized",
|
|
119
|
+
]) {
|
|
120
|
+
expect(
|
|
121
|
+
resolveDefaultProfileForProvider(undefined, key, managed)?.model,
|
|
122
|
+
).toBe(CODE_DEFAULT_PROFILE_ENTRIES[key].model);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("every pinned arm model is managed-routable and in its upstream catalog", () => {
|
|
127
|
+
for (const model of ["gpt-5.6-terra", GLM_MODEL]) {
|
|
128
|
+
const upstream = getManagedUpstream(model);
|
|
129
|
+
expect(upstream).not.toBeNull();
|
|
130
|
+
expect(isModelInCatalog(upstream as string, model)).toBe(true);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe("balanced-model experiment fallbacks", () => {
|
|
136
|
+
const shippedCases: [string, () => void][] = [
|
|
137
|
+
["the flag is unset", () => clearCachedOverrides()],
|
|
138
|
+
["no override is present", () => setOverridesForTesting({})],
|
|
139
|
+
["the arm is control", () => setArm("control")],
|
|
140
|
+
["the arm is an unknown string", () => setArm("gpt-9-does-not-exist")],
|
|
141
|
+
["the arm is the empty string", () => setArm("")],
|
|
142
|
+
["the value is boolean true", () => setArm(true)],
|
|
143
|
+
["the value is boolean false", () => setArm(false)],
|
|
144
|
+
// The arm is remote input, so it can name an Object.prototype member. The
|
|
145
|
+
// pin table is a Map, which has no such members to inherit.
|
|
146
|
+
["the arm is constructor", () => setArm("constructor")],
|
|
147
|
+
["the arm is toString", () => setArm("toString")],
|
|
148
|
+
["the arm is valueOf", () => setArm("valueOf")],
|
|
149
|
+
["the arm is __proto__", () => setArm("__proto__")],
|
|
150
|
+
["the arm is hasOwnProperty", () => setArm("hasOwnProperty")],
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
for (const [label, seed] of shippedCases) {
|
|
154
|
+
test(`balanced stays on the shipped model when ${label}`, () => {
|
|
155
|
+
seed();
|
|
156
|
+
expect(
|
|
157
|
+
resolveDefaultProfileForProvider(undefined, "balanced", managed)?.model,
|
|
158
|
+
).toBe(SHIPPED_MODEL);
|
|
159
|
+
expect(
|
|
160
|
+
resolveCallSiteConfig("mainAgent", llmWithActiveBalanced()).model,
|
|
161
|
+
).toBe(SHIPPED_MODEL);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
test("the shipped catalog body is the control arm", () => {
|
|
166
|
+
expect(CODE_DEFAULT_PROFILE_ENTRIES.balanced.model).toBe(SHIPPED_MODEL);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("the registry default is control, which the override-only flag read assumes", () => {
|
|
170
|
+
const registryPath = join(
|
|
171
|
+
import.meta.dirname,
|
|
172
|
+
"..",
|
|
173
|
+
"..",
|
|
174
|
+
"..",
|
|
175
|
+
"..",
|
|
176
|
+
"meta",
|
|
177
|
+
"feature-flags",
|
|
178
|
+
"feature-flag-registry.json",
|
|
179
|
+
);
|
|
180
|
+
const registry = JSON.parse(readFileSync(registryPath, "utf-8")) as {
|
|
181
|
+
flags: {
|
|
182
|
+
key: string;
|
|
183
|
+
scope: string;
|
|
184
|
+
defaultEnabled: boolean | string;
|
|
185
|
+
values?: string[];
|
|
186
|
+
}[];
|
|
187
|
+
};
|
|
188
|
+
const flag = registry.flags.find((entry) => entry.key === FLAG);
|
|
189
|
+
expect(flag).toBeDefined();
|
|
190
|
+
expect(flag?.scope).toBe("assistant");
|
|
191
|
+
expect(flag?.defaultEnabled).toBe("control");
|
|
192
|
+
expect(flag?.values).toEqual(["control", "terra", "glm-5p2"]);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe("balanced-model experiment boundaries", () => {
|
|
197
|
+
test("a user-owned balanced shadow wins over the arm", () => {
|
|
198
|
+
setArm("terra");
|
|
199
|
+
const profiles: Record<string, ProfileEntry> = {
|
|
200
|
+
balanced: { source: "user", provider: "openai", model: "gpt-5.5" },
|
|
201
|
+
};
|
|
202
|
+
expect(
|
|
203
|
+
resolveDefaultProfileForProvider(profiles, "balanced", managed),
|
|
204
|
+
).toEqual(profiles.balanced);
|
|
205
|
+
expect(
|
|
206
|
+
resolveCallSiteConfig("mainAgent", llmWithActiveBalanced({ profiles }))
|
|
207
|
+
.model,
|
|
208
|
+
).toBe("gpt-5.5");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("a managed-source stub still resolves to the arm's body", () => {
|
|
212
|
+
setArm("terra");
|
|
213
|
+
const profiles: Record<string, ProfileEntry> = {
|
|
214
|
+
balanced: { source: "managed", label: "My Balanced" },
|
|
215
|
+
};
|
|
216
|
+
const entry = resolveDefaultProfileForProvider(
|
|
217
|
+
profiles,
|
|
218
|
+
"balanced",
|
|
219
|
+
managed,
|
|
220
|
+
);
|
|
221
|
+
expect(entry?.model).toBe("gpt-5.6-terra");
|
|
222
|
+
expect(entry?.label).toBe("My Balanced");
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test("the chatgpt and BYOK columns stay out of the experiment", () => {
|
|
226
|
+
setArm("terra");
|
|
227
|
+
for (const provider of ["anthropic", "openai", "chatgpt"] as const) {
|
|
228
|
+
const armed = resolveDefaultProfileForProvider(undefined, "balanced", {
|
|
229
|
+
provider,
|
|
230
|
+
});
|
|
231
|
+
clearCachedOverrides();
|
|
232
|
+
const shipped = resolveDefaultProfileForProvider(undefined, "balanced", {
|
|
233
|
+
provider,
|
|
234
|
+
});
|
|
235
|
+
expect(armed).toEqual(shipped as ProfileEntry);
|
|
236
|
+
expect(armed?.provider).toBe(provider);
|
|
237
|
+
setArm("terra");
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("an install with no defaultProvider still picks up the arm", () => {
|
|
242
|
+
setArm("glm-5p2");
|
|
243
|
+
expect(
|
|
244
|
+
resolveDefaultProfileForProvider(undefined, "balanced", null)?.model,
|
|
245
|
+
).toBe(GLM_MODEL);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
describe("client-facing profile listing", () => {
|
|
250
|
+
test("reports the arm's model so the UI matches what runs", () => {
|
|
251
|
+
setArm("terra");
|
|
252
|
+
const profiles = getEffectiveProfilesForProvider(undefined, managed);
|
|
253
|
+
expect(profiles.balanced?.model).toBe("gpt-5.6-terra");
|
|
254
|
+
expect(profiles["quality-optimized"]?.model).toBe(
|
|
255
|
+
CODE_DEFAULT_PROFILE_ENTRIES["quality-optimized"].model,
|
|
256
|
+
);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("reports the shipped model on the control arm", () => {
|
|
260
|
+
setArm("control");
|
|
261
|
+
expect(
|
|
262
|
+
getEffectiveProfilesForProvider(undefined, managed).balanced?.model,
|
|
263
|
+
).toBe(SHIPPED_MODEL);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test("agrees with the runtime resolver on every arm", () => {
|
|
267
|
+
for (const arm of ["control", "terra", "glm-5p2", "nonsense"]) {
|
|
268
|
+
setArm(arm);
|
|
269
|
+
const listed = getEffectiveProfilesForProvider(undefined, managed)
|
|
270
|
+
.balanced?.model;
|
|
271
|
+
const resolved = resolveCallSiteConfig(
|
|
272
|
+
"mainAgent",
|
|
273
|
+
llmWithActiveBalanced(),
|
|
274
|
+
).model;
|
|
275
|
+
expect(listed).toBe(resolved as string);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
});
|