@vellumai/assistant 0.10.9-dev.202607161445.5757c2f → 0.10.9-dev.202607161634.43bca24
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 +0 -4
- package/package.json +1 -1
- package/src/__tests__/config-schema.test.ts +22 -27
- package/src/__tests__/conversation-agent-loop-fatal-cleanup.test.ts +208 -0
- package/src/__tests__/run-conversation-turn-persistence.test.ts +31 -14
- package/src/__tests__/voice-config-update.test.ts +46 -0
- package/src/__tests__/workspace-migration-131-drop-web-fetch-mode.test.ts +120 -0
- package/src/config/bundled-skills/settings/tools/voice-config-update.ts +18 -10
- package/src/config/schemas/__tests__/stt.test.ts +6 -3
- package/src/config/schemas/services.ts +6 -3
- package/src/config/schemas/stt.ts +13 -18
- package/src/config/schemas/tts.ts +13 -18
- package/src/daemon/conversation-agent-loop.ts +16 -13
- package/src/daemon/conversation-store.ts +35 -0
- package/src/daemon/conversation.ts +4 -4
- package/src/daemon/handlers/shared.ts +9 -1
- package/src/daemon/providers-setup.ts +8 -0
- package/src/persistence/conversation-crud.ts +1 -1
- package/src/plugin-api/conversation-turn.ts +25 -18
- package/src/providers/fetch-provider-catalog.ts +4 -2
- package/src/runtime/routes/conversation-query-routes.ts +0 -2
- package/src/tools/network/__tests__/web-fetch-firecrawl.test.ts +1 -1
- package/src/tts/provider-catalog.ts +2 -4
- package/src/workspace/migrations/131-drop-web-fetch-mode.ts +61 -0
- package/src/workspace/migrations/registry.ts +2 -0
package/openapi.yaml
CHANGED
|
@@ -31594,8 +31594,6 @@ components:
|
|
|
31594
31594
|
anyOf:
|
|
31595
31595
|
- type: object
|
|
31596
31596
|
properties:
|
|
31597
|
-
mode:
|
|
31598
|
-
$ref: "#/components/schemas/ServiceMode"
|
|
31599
31597
|
provider:
|
|
31600
31598
|
type: string
|
|
31601
31599
|
additionalProperties: {}
|
|
@@ -32394,8 +32392,6 @@ components:
|
|
|
32394
32392
|
web-fetch:
|
|
32395
32393
|
type: object
|
|
32396
32394
|
properties:
|
|
32397
|
-
mode:
|
|
32398
|
-
$ref: "#/components/schemas/ServiceMode"
|
|
32399
32395
|
provider:
|
|
32400
32396
|
type: string
|
|
32401
32397
|
additionalProperties: {}
|
package/package.json
CHANGED
|
@@ -128,7 +128,7 @@ describe("AssistantConfigSchema", () => {
|
|
|
128
128
|
test("accepts Firecrawl as a web fetch provider", () => {
|
|
129
129
|
const result = AssistantConfigSchema.parse({
|
|
130
130
|
services: {
|
|
131
|
-
"web-fetch": {
|
|
131
|
+
"web-fetch": { provider: "firecrawl" },
|
|
132
132
|
},
|
|
133
133
|
});
|
|
134
134
|
|
|
@@ -143,6 +143,18 @@ describe("AssistantConfigSchema", () => {
|
|
|
143
143
|
).toThrow();
|
|
144
144
|
});
|
|
145
145
|
|
|
146
|
+
// Legacy config objects on disk may carry a `mode` key; parsing must strip
|
|
147
|
+
// it rather than reject the whole config.
|
|
148
|
+
test("ignores a legacy web-fetch mode key", () => {
|
|
149
|
+
const result = AssistantConfigSchema.parse({
|
|
150
|
+
services: {
|
|
151
|
+
"web-fetch": { mode: "your-own", provider: "firecrawl" },
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
expect(result.services["web-fetch"]).toEqual({ provider: "firecrawl" });
|
|
156
|
+
});
|
|
157
|
+
|
|
146
158
|
test("accepts valid complete config", () => {
|
|
147
159
|
const input = {
|
|
148
160
|
llm: {
|
|
@@ -1283,15 +1295,11 @@ describe("AssistantConfigSchema", () => {
|
|
|
1283
1295
|
expect(result.success).toBe(true);
|
|
1284
1296
|
});
|
|
1285
1297
|
|
|
1286
|
-
test("
|
|
1298
|
+
test("accepts tts provider vellum regardless of mode", () => {
|
|
1287
1299
|
const result = AssistantConfigSchema.safeParse({
|
|
1288
1300
|
services: { tts: { mode: "your-own", provider: "vellum" } },
|
|
1289
1301
|
});
|
|
1290
|
-
expect(result.success).toBe(
|
|
1291
|
-
if (!result.success) {
|
|
1292
|
-
const msgs = result.error.issues.map((i) => i.message);
|
|
1293
|
-
expect(msgs.some((m) => m.includes("managed"))).toBe(true);
|
|
1294
|
-
}
|
|
1302
|
+
expect(result.success).toBe(true);
|
|
1295
1303
|
});
|
|
1296
1304
|
|
|
1297
1305
|
// ── hostBrowser.cdpInspect.desktopAuto config ───────────────────────
|
|
@@ -1446,15 +1454,11 @@ describe("AssistantConfigSchema", () => {
|
|
|
1446
1454
|
expect(result.success).toBe(true);
|
|
1447
1455
|
});
|
|
1448
1456
|
|
|
1449
|
-
test("
|
|
1457
|
+
test("accepts stt provider vellum regardless of mode", () => {
|
|
1450
1458
|
const result = AssistantConfigSchema.safeParse({
|
|
1451
1459
|
services: { stt: { mode: "your-own", provider: "vellum" } },
|
|
1452
1460
|
});
|
|
1453
|
-
expect(result.success).toBe(
|
|
1454
|
-
if (!result.success) {
|
|
1455
|
-
const msgs = result.error.issues.map((i) => i.message);
|
|
1456
|
-
expect(msgs.some((m) => m.includes("managed"))).toBe(true);
|
|
1457
|
-
}
|
|
1461
|
+
expect(result.success).toBe(true);
|
|
1458
1462
|
});
|
|
1459
1463
|
|
|
1460
1464
|
test("rejects invalid services.stt.provider", () => {
|
|
@@ -1717,25 +1721,16 @@ describe("resolveTtsConfig", () => {
|
|
|
1717
1721
|
// ---------------------------------------------------------------------------
|
|
1718
1722
|
|
|
1719
1723
|
describe("TTS provider catalog integration", () => {
|
|
1720
|
-
test("TTS_PROVIDER_IDS matches
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
expect(TTS_PROVIDER_IDS).toContain(id);
|
|
1725
|
-
}
|
|
1726
|
-
// …and the only canonical ID hidden from the display catalog is
|
|
1727
|
-
// vellum: managed mode is selected via services.tts.mode, not the
|
|
1728
|
-
// provider picker.
|
|
1729
|
-
const hidden = TTS_PROVIDER_IDS.filter((id) => !catalogIds.includes(id));
|
|
1730
|
-
expect(hidden).toEqual(["vellum"]);
|
|
1724
|
+
test("TTS_PROVIDER_IDS matches the display catalog exactly", () => {
|
|
1725
|
+
expect([...listCatalogProviderIds()].sort()).toEqual(
|
|
1726
|
+
[...TTS_PROVIDER_IDS].sort(),
|
|
1727
|
+
);
|
|
1731
1728
|
});
|
|
1732
1729
|
|
|
1733
1730
|
test("schema accepts all catalog provider IDs as services.tts.provider", () => {
|
|
1734
1731
|
for (const providerId of listCatalogProviderIds()) {
|
|
1735
|
-
// vellum is connection-based and only valid under managed mode.
|
|
1736
|
-
const mode = providerId === "vellum" ? "managed" : "your-own";
|
|
1737
1732
|
const result = AssistantConfigSchema.safeParse({
|
|
1738
|
-
services: { tts: {
|
|
1733
|
+
services: { tts: { provider: providerId } },
|
|
1739
1734
|
});
|
|
1740
1735
|
expect(result.success).toBe(true);
|
|
1741
1736
|
if (result.success) {
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression test for ATL-1009: clear `processing_started_at` on fatal
|
|
3
|
+
* agent-loop failure.
|
|
4
|
+
*
|
|
5
|
+
* The agent-loop `finally` block clears the conversation's processing flag
|
|
6
|
+
* (`ctx.setProcessing(false)` → `processing_started_at = NULL`) first, before
|
|
7
|
+
* any cleanup step that can throw (the turn-boundary commit, profiling). The
|
|
8
|
+
* clear is the release that unwedges the conversation: if a later step threw
|
|
9
|
+
* ahead of it, the row would stay "mid-turn" forever — the next send times out
|
|
10
|
+
* with "did not respond in time" and queued messages never drain.
|
|
11
|
+
*
|
|
12
|
+
* These tests drive `runAgentLoopImpl` to a fatal failure (agent loop throws)
|
|
13
|
+
* and assert the processing flag is cleared even when the turn-boundary commit
|
|
14
|
+
* itself throws afterward.
|
|
15
|
+
*/
|
|
16
|
+
import { afterAll, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
17
|
+
|
|
18
|
+
import { CompactionCircuit } from "../agent/compaction-circuit.js";
|
|
19
|
+
import type { AgentLoop } from "../agent/loop.js";
|
|
20
|
+
import type { Conversation } from "../daemon/conversation.js";
|
|
21
|
+
import type { DiskPressureStatus } from "../daemon/disk-pressure-guard.js";
|
|
22
|
+
import type { ServerMessage } from "../daemon/message-protocol.js";
|
|
23
|
+
import { setConfig } from "./helpers/set-config.js";
|
|
24
|
+
|
|
25
|
+
// Short turn-boundary commit wait and no second-pass retitling keep the loop
|
|
26
|
+
// teardown fast and deterministic.
|
|
27
|
+
setConfig("workspaceGit", { turnCommitMaxWaitMs: 10 });
|
|
28
|
+
setConfig("conversations", { skipAutoRetitling: true });
|
|
29
|
+
|
|
30
|
+
// Disk pressure is disabled so the loop proceeds past the gate, marks the turn
|
|
31
|
+
// started, and runs the real `finally` (including the turn-boundary commit).
|
|
32
|
+
const disabledDiskPressureStatus: DiskPressureStatus = {
|
|
33
|
+
enabled: false,
|
|
34
|
+
state: "disabled",
|
|
35
|
+
locked: false,
|
|
36
|
+
acknowledged: false,
|
|
37
|
+
overrideActive: false,
|
|
38
|
+
effectivelyLocked: false,
|
|
39
|
+
lockId: null,
|
|
40
|
+
usagePercent: null,
|
|
41
|
+
thresholdPercent: 95,
|
|
42
|
+
path: null,
|
|
43
|
+
lastCheckedAt: null,
|
|
44
|
+
blockedCapabilities: [],
|
|
45
|
+
error: null,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
mock.module("../daemon/disk-pressure-guard.js", () => ({
|
|
49
|
+
getDiskPressureStatus: () => disabledDiskPressureStatus,
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
mock.module("../persistence/conversation-crud.js", () => ({
|
|
53
|
+
setConversationProcessingStartedAt: () => {},
|
|
54
|
+
isConversationProcessing: () => false,
|
|
55
|
+
getConversation: () => ({
|
|
56
|
+
id: "conv-fatal",
|
|
57
|
+
conversationType: "background",
|
|
58
|
+
source: "memory",
|
|
59
|
+
}),
|
|
60
|
+
getLastUserTimestampBefore: () => 0,
|
|
61
|
+
getMessageById: () => null,
|
|
62
|
+
getConversationOriginChannel: () => null,
|
|
63
|
+
getConversationOriginInterface: () => null,
|
|
64
|
+
resolveOverrideProfile: () => null,
|
|
65
|
+
provenanceFromTrustContext: () => ({}),
|
|
66
|
+
setConversationHistoryStrippedAt: () => {},
|
|
67
|
+
updateConversationContextWindow: () => {},
|
|
68
|
+
updateConversationSlackContextWatermark: () => {},
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
import { runAgentLoopImpl } from "../daemon/conversation-agent-loop.js";
|
|
72
|
+
|
|
73
|
+
function makeCtx(overrides: Partial<Context> = {}): Conversation {
|
|
74
|
+
let processing = true;
|
|
75
|
+
return {
|
|
76
|
+
conversationId: "conv-fatal",
|
|
77
|
+
messages: [{ role: "user", content: [{ type: "text", text: "hello" }] }],
|
|
78
|
+
isProcessing: () => processing,
|
|
79
|
+
setProcessing: (value: boolean) => {
|
|
80
|
+
processing = value;
|
|
81
|
+
},
|
|
82
|
+
abortController: new AbortController(),
|
|
83
|
+
currentRequestId: "req-fatal",
|
|
84
|
+
agentLoop: {
|
|
85
|
+
// Simulate a fatal agent-loop failure (e.g. an unhandled runtime crash).
|
|
86
|
+
run: async () => {
|
|
87
|
+
throw new Error("fatal agent loop failure");
|
|
88
|
+
},
|
|
89
|
+
getToolTokenBudget: () => 0,
|
|
90
|
+
getResolvedTools: () => [],
|
|
91
|
+
getActiveModel: () => undefined,
|
|
92
|
+
compactionCircuit: new CompactionCircuit("conv-fatal"),
|
|
93
|
+
} as unknown as AgentLoop,
|
|
94
|
+
provider: { name: "mock-provider" } as Context["provider"],
|
|
95
|
+
systemPrompt: "system",
|
|
96
|
+
contextWindowManager: {
|
|
97
|
+
updateConfig: () => {},
|
|
98
|
+
resetOverflowRecovery: () => {},
|
|
99
|
+
shouldCompact: () => ({ needed: false, estimatedTokens: 0 }),
|
|
100
|
+
maybeCompact: async () => ({ compacted: false }),
|
|
101
|
+
} as unknown as Context["contextWindowManager"],
|
|
102
|
+
contextCompactedMessageCount: 0,
|
|
103
|
+
contextCompactedAt: null,
|
|
104
|
+
conversationType: "background",
|
|
105
|
+
source: "memory",
|
|
106
|
+
currentActiveSurfaceId: undefined,
|
|
107
|
+
currentPage: undefined,
|
|
108
|
+
surfaceState: new Map(),
|
|
109
|
+
pendingSurfaceActions: new Map(),
|
|
110
|
+
surfaceActionRequestIds: new Set<string>(),
|
|
111
|
+
currentTurnSurfaces: [],
|
|
112
|
+
workingDir: "/tmp",
|
|
113
|
+
channelCapabilities: undefined,
|
|
114
|
+
commandIntent: undefined,
|
|
115
|
+
trustContext: undefined,
|
|
116
|
+
allowedToolNames: undefined,
|
|
117
|
+
preactivatedSkillIds: undefined,
|
|
118
|
+
skillProjectionState: new Map(),
|
|
119
|
+
skillProjectionCache: new Map() as Context["skillProjectionCache"],
|
|
120
|
+
usageStats: {
|
|
121
|
+
totalInputTokens: 0,
|
|
122
|
+
totalOutputTokens: 0,
|
|
123
|
+
totalEstimatedCost: 0,
|
|
124
|
+
model: "",
|
|
125
|
+
},
|
|
126
|
+
turnCount: 0,
|
|
127
|
+
lastAssistantAttachments: [],
|
|
128
|
+
lastAttachmentWarnings: [],
|
|
129
|
+
hasNoClient: false,
|
|
130
|
+
prompter: {} as Context["prompter"],
|
|
131
|
+
queue: {} as Context["queue"],
|
|
132
|
+
markWorkspaceTopLevelDirty: () => {},
|
|
133
|
+
emitActivityState: () => {},
|
|
134
|
+
getQueueDepth: () => 0,
|
|
135
|
+
hasQueuedMessages: () => false,
|
|
136
|
+
canHandoffAtCheckpoint: () => false,
|
|
137
|
+
drainQueue: async () => {},
|
|
138
|
+
getTurnInterfaceContext: () => null,
|
|
139
|
+
getTurnChannelContext: () => null,
|
|
140
|
+
buildCurrentSystemPrompt: () => "system prompt",
|
|
141
|
+
syncLoopSystemPrompt: () => {},
|
|
142
|
+
modelOverride: undefined,
|
|
143
|
+
graphMemory: {} as Context["graphMemory"],
|
|
144
|
+
...overrides,
|
|
145
|
+
} as unknown as Conversation;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
type Context = Conversation;
|
|
149
|
+
|
|
150
|
+
describe("runAgentLoopImpl fatal-failure cleanup (ATL-1009)", () => {
|
|
151
|
+
beforeEach(() => {
|
|
152
|
+
// no-op; each test builds its own ctx
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
afterAll(() => {
|
|
156
|
+
// restore nothing — disk pressure stays disabled for this suite
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("clears the processing flag before the turn-boundary commit, so a commit that throws cannot latch it", async () => {
|
|
160
|
+
const events: ServerMessage[] = [];
|
|
161
|
+
// The turn-boundary commit throwing inside the `finally` is precisely the
|
|
162
|
+
// ATL-1007 failure mode. Because the flag is cleared first, the throw can
|
|
163
|
+
// no longer leave `processing_started_at` latched.
|
|
164
|
+
const commitTurnChanges = mock(() => {
|
|
165
|
+
throw new Error("commit crashed (simulated Bun memoryUsage bug)");
|
|
166
|
+
});
|
|
167
|
+
const ctx = makeCtx({
|
|
168
|
+
commitTurnChanges:
|
|
169
|
+
commitTurnChanges as unknown as Context["commitTurnChanges"],
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// The commit throw still surfaces (it runs after the clear), but the flag
|
|
173
|
+
// was already released.
|
|
174
|
+
await expect(
|
|
175
|
+
runAgentLoopImpl(ctx, "background task", "msg-fatal", (event) =>
|
|
176
|
+
events.push(event),
|
|
177
|
+
),
|
|
178
|
+
).rejects.toThrow("commit crashed");
|
|
179
|
+
|
|
180
|
+
// The commit was reached (turn was marked started before the loop threw).
|
|
181
|
+
expect(commitTurnChanges).toHaveBeenCalled();
|
|
182
|
+
// The processing flag was cleared despite the commit throwing — the
|
|
183
|
+
// conversation is no longer wedged mid-turn.
|
|
184
|
+
expect(ctx.isProcessing()).toBe(false);
|
|
185
|
+
expect(ctx.abortController).toBeNull();
|
|
186
|
+
// The user still saw a terminal error for the fatal failure.
|
|
187
|
+
expect(events.some((event) => event.type === "error")).toBe(true);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("clears the processing flag on a clean fatal failure (commit succeeds)", async () => {
|
|
191
|
+
const events: ServerMessage[] = [];
|
|
192
|
+
const drainQueue = mock(async (_reason: unknown) => {});
|
|
193
|
+
const commitTurnChanges = mock(async () => {});
|
|
194
|
+
const ctx = makeCtx({
|
|
195
|
+
drainQueue,
|
|
196
|
+
commitTurnChanges:
|
|
197
|
+
commitTurnChanges as unknown as Context["commitTurnChanges"],
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
await runAgentLoopImpl(ctx, "background task", "msg-fatal-2", (event) =>
|
|
201
|
+
events.push(event),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
expect(ctx.isProcessing()).toBe(false);
|
|
205
|
+
expect(ctx.abortController).toBeNull();
|
|
206
|
+
expect(drainQueue).toHaveBeenCalledWith("loop_complete");
|
|
207
|
+
});
|
|
208
|
+
});
|
|
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
createConversation,
|
|
5
|
+
ensureConversationExists,
|
|
5
6
|
getConversation,
|
|
6
7
|
} from "../persistence/conversation-crud.js";
|
|
7
8
|
import { getDb } from "../persistence/db-connection.js";
|
|
@@ -25,22 +26,38 @@ mock.module("../runtime/sync/resource-sync-events.js", () => ({
|
|
|
25
26
|
// Stub the heavy machinery: the in-memory conversation build (provider wiring,
|
|
26
27
|
// system prompt, history hydration) and the SSE event fan-out. The agent turn
|
|
27
28
|
// itself is a no-op — this test only asserts that the `conversations` row is
|
|
28
|
-
// persisted before the turn runs
|
|
29
|
-
//
|
|
30
|
-
// `ensureConversationExists
|
|
29
|
+
// persisted before the turn runs. The real `getOrCreateConversation` now
|
|
30
|
+
// creates the DB row before hydrating, so the mock mirrors that by calling
|
|
31
|
+
// `ensureConversationExists`. The persistence module is intentionally NOT
|
|
32
|
+
// mocked so the real `ensureConversationExists` runs against the real DB.
|
|
31
33
|
let lastProcessMessageConversationId: string | undefined;
|
|
32
34
|
mock.module("../daemon/conversation-store.js", () => ({
|
|
33
|
-
getOrCreateConversation: async (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
getOrCreateConversation: async (
|
|
36
|
+
conversationId: string,
|
|
37
|
+
options?: { conversationType?: string },
|
|
38
|
+
) => {
|
|
39
|
+
if (!getConversation(conversationId)) {
|
|
40
|
+
if (options?.conversationType) {
|
|
41
|
+
createConversation({
|
|
42
|
+
id: conversationId,
|
|
43
|
+
conversationType: options.conversationType as "standard" | "background",
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
ensureConversationExists(conversationId);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
abortController: undefined,
|
|
51
|
+
isProcessing: () => false,
|
|
52
|
+
async processMessage() {
|
|
53
|
+
// The row must already exist by the time the turn persists its user
|
|
54
|
+
// message — record the id so the FK precondition can be asserted.
|
|
55
|
+
lastProcessMessageConversationId = conversationId;
|
|
56
|
+
return "user-message-id";
|
|
57
|
+
},
|
|
58
|
+
enqueueMessage: () => ({ rejected: false }),
|
|
59
|
+
};
|
|
60
|
+
},
|
|
44
61
|
}));
|
|
45
62
|
|
|
46
63
|
mock.module("../runtime/assistant-event-hub.js", () => ({
|
|
@@ -120,6 +120,37 @@ describe("voice_config_update — tts_provider", () => {
|
|
|
120
120
|
expect(result.content).toContain("tts_provider must be one of");
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
+
test("tts_provider resets a stale managed mode", async () => {
|
|
124
|
+
// A lingering `mode: "managed"` takes precedence over the BYOK provider,
|
|
125
|
+
// so a provider switch that left it in place would be silently ignored.
|
|
126
|
+
writeConfig({ services: { tts: { mode: "managed", provider: "vellum" } } });
|
|
127
|
+
invalidateConfigCache();
|
|
128
|
+
|
|
129
|
+
const result = await run(
|
|
130
|
+
{ setting: "tts_provider", value: "elevenlabs" },
|
|
131
|
+
makeContext(),
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
expect(result.isError).toBe(false);
|
|
135
|
+
const tts = (readConfig().services as any).tts;
|
|
136
|
+
expect(tts.provider).toBe("elevenlabs");
|
|
137
|
+
expect(tts.mode).toBe("your-own");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("tts_provider vellum writes the managed pair", async () => {
|
|
141
|
+
mockManagedSpeechAvailable = true;
|
|
142
|
+
|
|
143
|
+
const result = await run(
|
|
144
|
+
{ setting: "tts_provider", value: "vellum" },
|
|
145
|
+
makeContext(),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
expect(result.isError).toBe(false);
|
|
149
|
+
const tts = (readConfig().services as any).tts;
|
|
150
|
+
expect(tts.provider).toBe("vellum");
|
|
151
|
+
expect(tts.mode).toBe("managed");
|
|
152
|
+
});
|
|
153
|
+
|
|
123
154
|
test("broadcasts ttsProvider to client", async () => {
|
|
124
155
|
const messages: any[] = [];
|
|
125
156
|
const ctx = makeContext({
|
|
@@ -446,7 +477,22 @@ describe("voice_config_update — stt_mode / tts_mode", () => {
|
|
|
446
477
|
// ---------------------------------------------------------------------------
|
|
447
478
|
|
|
448
479
|
describe("voice_config_update — catalog-driven provider validation", () => {
|
|
480
|
+
test("rejects tts_provider vellum without a platform connection", async () => {
|
|
481
|
+
mockManagedSpeechAvailable = false;
|
|
482
|
+
|
|
483
|
+
const result = await run(
|
|
484
|
+
{ setting: "tts_provider", value: "vellum" },
|
|
485
|
+
makeContext(),
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
expect(result.isError).toBe(true);
|
|
489
|
+
expect(result.content).toContain("assistant platform connect");
|
|
490
|
+
expect((readConfig().services as any)?.tts?.provider).toBeUndefined();
|
|
491
|
+
});
|
|
492
|
+
|
|
449
493
|
test("accepts every provider ID in the catalog", async () => {
|
|
494
|
+
// The catalog includes vellum, which is gated on a platform connection.
|
|
495
|
+
mockManagedSpeechAvailable = true;
|
|
450
496
|
const catalogIds = listCatalogProviderIds();
|
|
451
497
|
expect(catalogIds.length).toBeGreaterThanOrEqual(1);
|
|
452
498
|
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
mkdirSync,
|
|
4
|
+
readFileSync,
|
|
5
|
+
rmSync,
|
|
6
|
+
writeFileSync,
|
|
7
|
+
} from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
11
|
+
|
|
12
|
+
import { dropWebFetchModeMigration } from "../workspace/migrations/131-drop-web-fetch-mode.js";
|
|
13
|
+
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Helpers
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
let workspaceDir: string;
|
|
19
|
+
|
|
20
|
+
function freshWorkspace(): void {
|
|
21
|
+
workspaceDir = join(
|
|
22
|
+
tmpdir(),
|
|
23
|
+
`vellum-migration-131-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
24
|
+
);
|
|
25
|
+
mkdirSync(workspaceDir, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function writeConfig(data: Record<string, unknown>): void {
|
|
29
|
+
writeFileSync(
|
|
30
|
+
join(workspaceDir, "config.json"),
|
|
31
|
+
JSON.stringify(data, null, 2) + "\n",
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function readConfig(): Record<string, unknown> {
|
|
36
|
+
return JSON.parse(readFileSync(join(workspaceDir, "config.json"), "utf-8"));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Setup / teardown
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
freshWorkspace();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
afterEach(() => {
|
|
48
|
+
if (existsSync(workspaceDir)) {
|
|
49
|
+
rmSync(workspaceDir, { recursive: true, force: true });
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Tests
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
describe("131-drop-web-fetch-mode", () => {
|
|
58
|
+
test("strips mode and keeps the provider", () => {
|
|
59
|
+
writeConfig({
|
|
60
|
+
services: { "web-fetch": { mode: "your-own", provider: "firecrawl" } },
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
dropWebFetchModeMigration.run(workspaceDir);
|
|
64
|
+
|
|
65
|
+
expect((readConfig().services as any)["web-fetch"]).toEqual({
|
|
66
|
+
provider: "firecrawl",
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("leaves an entry with no mode untouched", () => {
|
|
71
|
+
writeConfig({ services: { "web-fetch": { provider: "firecrawl" } } });
|
|
72
|
+
|
|
73
|
+
dropWebFetchModeMigration.run(workspaceDir);
|
|
74
|
+
|
|
75
|
+
expect(readConfig()).toEqual({
|
|
76
|
+
services: { "web-fetch": { provider: "firecrawl" } },
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("does not touch other services' mode", () => {
|
|
81
|
+
writeConfig({
|
|
82
|
+
services: {
|
|
83
|
+
"web-fetch": { mode: "your-own", provider: "default" },
|
|
84
|
+
"web-search": { mode: "managed", provider: "brave" },
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
dropWebFetchModeMigration.run(workspaceDir);
|
|
89
|
+
|
|
90
|
+
const services = readConfig().services as any;
|
|
91
|
+
expect(services["web-fetch"]).toEqual({ provider: "default" });
|
|
92
|
+
expect(services["web-search"]).toEqual({
|
|
93
|
+
mode: "managed",
|
|
94
|
+
provider: "brave",
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("is idempotent", () => {
|
|
99
|
+
writeConfig({
|
|
100
|
+
services: { "web-fetch": { mode: "your-own", provider: "firecrawl" } },
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
dropWebFetchModeMigration.run(workspaceDir);
|
|
104
|
+
const once = readConfig();
|
|
105
|
+
dropWebFetchModeMigration.run(workspaceDir);
|
|
106
|
+
|
|
107
|
+
expect(readConfig()).toEqual(once);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("survives a missing config, malformed JSON, and a sparse config", () => {
|
|
111
|
+
expect(() => dropWebFetchModeMigration.run(workspaceDir)).not.toThrow();
|
|
112
|
+
|
|
113
|
+
writeFileSync(join(workspaceDir, "config.json"), "{ not json");
|
|
114
|
+
expect(() => dropWebFetchModeMigration.run(workspaceDir)).not.toThrow();
|
|
115
|
+
|
|
116
|
+
writeConfig({});
|
|
117
|
+
expect(() => dropWebFetchModeMigration.run(workspaceDir)).not.toThrow();
|
|
118
|
+
expect(readConfig()).toEqual({});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -186,11 +186,11 @@ export async function run(
|
|
|
186
186
|
return { content: `Error: ${validation.error}`, isError: true };
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
|
|
190
|
-
(setting === "stt_mode" || setting === "tts_mode") &&
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
) {
|
|
189
|
+
const wantsManagedSpeech =
|
|
190
|
+
((setting === "stt_mode" || setting === "tts_mode") &&
|
|
191
|
+
validation.coerced === "managed") ||
|
|
192
|
+
(setting === "tts_provider" && validation.coerced === "vellum");
|
|
193
|
+
if (wantsManagedSpeech && !(await managedSpeechAvailable())) {
|
|
194
194
|
return {
|
|
195
195
|
content:
|
|
196
196
|
"Error: managed speech requires a Vellum platform connection. Run 'assistant platform connect' first.",
|
|
@@ -217,6 +217,14 @@ export async function run(
|
|
|
217
217
|
|
|
218
218
|
if (setting === "tts_provider") {
|
|
219
219
|
setNestedValue(raw, "services.tts.provider", validation.coerced);
|
|
220
|
+
// Written as a pair, like the settings cards: a stale `mode: "managed"`
|
|
221
|
+
// takes precedence over a BYOK provider, so switching providers must
|
|
222
|
+
// also reset it — otherwise the requested switch is silently ignored.
|
|
223
|
+
setNestedValue(
|
|
224
|
+
raw,
|
|
225
|
+
"services.tts.mode",
|
|
226
|
+
validation.coerced === "vellum" ? "managed" : "your-own",
|
|
227
|
+
);
|
|
220
228
|
saveRawConfig(raw);
|
|
221
229
|
invalidateConfigCache();
|
|
222
230
|
}
|
|
@@ -253,10 +261,10 @@ export async function run(
|
|
|
253
261
|
|
|
254
262
|
if (setting === "stt_mode") {
|
|
255
263
|
setNestedValue(raw, "services.stt.mode", validation.coerced);
|
|
256
|
-
// SttServiceSchema requires `provider` whenever the stt object exists
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
//
|
|
264
|
+
// SttServiceSchema requires `provider` whenever the stt object exists, so
|
|
265
|
+
// writing `mode` alone would invalidate a sparse config. And a provider of
|
|
266
|
+
// "vellum" routes to managed regardless of mode, so switching to your-own
|
|
267
|
+
// must also replace it with a BYOK provider.
|
|
260
268
|
const currentProvider = getConfig().services.stt.provider;
|
|
261
269
|
setNestedValue(
|
|
262
270
|
raw,
|
|
@@ -271,7 +279,7 @@ export async function run(
|
|
|
271
279
|
|
|
272
280
|
if (setting === "tts_mode") {
|
|
273
281
|
setNestedValue(raw, "services.tts.mode", validation.coerced);
|
|
274
|
-
//
|
|
282
|
+
// A provider of "vellum" routes to managed regardless of mode, so
|
|
275
283
|
// switching to your-own must also replace a vellum provider.
|
|
276
284
|
if (
|
|
277
285
|
validation.coerced === "your-own" &&
|
|
@@ -61,15 +61,18 @@ describe("managed mode", () => {
|
|
|
61
61
|
expect(parsed.provider).toBe("vellum");
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
test("
|
|
64
|
+
test("accepts provider vellum regardless of mode", () => {
|
|
65
65
|
const result = SttServiceSchema.safeParse({
|
|
66
66
|
mode: "your-own",
|
|
67
67
|
provider: "vellum",
|
|
68
68
|
});
|
|
69
|
-
expect(result.success).toBe(
|
|
69
|
+
expect(result.success).toBe(true);
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
test("effectiveSttProvider routes managed mode to vellum
|
|
72
|
+
test("effectiveSttProvider routes provider vellum and managed mode to vellum, preserves BYOK otherwise", () => {
|
|
73
|
+
expect(
|
|
74
|
+
effectiveSttProvider({ mode: "your-own", provider: "vellum" }),
|
|
75
|
+
).toBe("vellum");
|
|
73
76
|
expect(
|
|
74
77
|
effectiveSttProvider({ mode: "managed", provider: "deepgram" }),
|
|
75
78
|
).toBe("vellum");
|
|
@@ -66,12 +66,15 @@ const WebSearchServiceSchema = BaseServiceSchema.extend({
|
|
|
66
66
|
.default("inference-provider-native"),
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Web-fetch carries no `mode`: there is no managed proxy for it, so the only
|
|
71
|
+
* axis is which provider backs the tool.
|
|
72
|
+
*/
|
|
73
|
+
const WebFetchServiceSchema = z.object({
|
|
70
74
|
// Provider that backs the `web_fetch` tool. `default` is the daemon's
|
|
71
75
|
// built-in HTTP fetch + extract path (no key). BYOK providers (e.g.
|
|
72
76
|
// `firecrawl`) scrape via their hosted API and reuse the same stored key as
|
|
73
|
-
// their web-search counterpart.
|
|
74
|
-
// `BaseServiceSchema` for symmetry; web-fetch has no managed proxy today.
|
|
77
|
+
// their web-search counterpart.
|
|
75
78
|
provider: z.enum(VALID_WEB_FETCH_PROVIDERS).default("default"),
|
|
76
79
|
});
|
|
77
80
|
|
|
@@ -33,11 +33,12 @@ export type SttProviders = z.infer<typeof SttProvidersSchema>;
|
|
|
33
33
|
/**
|
|
34
34
|
* Canonical STT service configuration.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
36
|
+
* Managed transcription (through the user's Vellum account, billed to Vellum
|
|
37
|
+
* credits) is selectable two ways: `provider: "vellum"` directly, or
|
|
38
|
+
* `mode: "managed"` alongside a BYOK `provider` — the form the mode toggle
|
|
39
|
+
* writes, which leaves the BYOK choice untouched so switching back to
|
|
40
|
+
* `"your-own"` restores it. Use {@link effectiveSttProvider} to resolve
|
|
41
|
+
* which provider is actually active.
|
|
41
42
|
*/
|
|
42
43
|
export const SttServiceSchema = z
|
|
43
44
|
.object({
|
|
@@ -56,16 +57,6 @@ export const SttServiceSchema = z
|
|
|
56
57
|
.describe("Active STT provider used for speech-to-text transcription"),
|
|
57
58
|
providers: SttProvidersSchema.default({}),
|
|
58
59
|
})
|
|
59
|
-
.superRefine((service, ctx) => {
|
|
60
|
-
if (service.provider === "vellum" && service.mode !== "managed") {
|
|
61
|
-
ctx.addIssue({
|
|
62
|
-
code: "custom",
|
|
63
|
-
path: ["provider"],
|
|
64
|
-
message:
|
|
65
|
-
'services.stt.provider "vellum" requires services.stt.mode "managed"',
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
60
|
.describe(
|
|
70
61
|
"Speech-to-text service configuration -- provider selection and per-provider settings",
|
|
71
62
|
);
|
|
@@ -75,13 +66,17 @@ export type SttService = z.infer<typeof SttServiceSchema>;
|
|
|
75
66
|
/**
|
|
76
67
|
* Resolve the provider that is actually active for the service config.
|
|
77
68
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* `"your-own"` restores
|
|
69
|
+
* `provider: "vellum"` selects managed transcription directly. Otherwise
|
|
70
|
+
* `mode: "managed"` routes to `vellum` while leaving the user's BYOK
|
|
71
|
+
* `provider` choice untouched, so toggling back to `"your-own"` restores
|
|
72
|
+
* their previous setup.
|
|
81
73
|
*/
|
|
82
74
|
export function effectiveSttProvider(service: {
|
|
83
75
|
mode: SttService["mode"];
|
|
84
76
|
provider: string;
|
|
85
77
|
}): string {
|
|
78
|
+
if (service.provider === "vellum") {
|
|
79
|
+
return "vellum";
|
|
80
|
+
}
|
|
86
81
|
return service.mode === "managed" ? "vellum" : service.provider;
|
|
87
82
|
}
|
|
@@ -273,11 +273,12 @@ for (const id of schemaKeys) {
|
|
|
273
273
|
/**
|
|
274
274
|
* Canonical TTS service configuration.
|
|
275
275
|
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* `
|
|
279
|
-
*
|
|
280
|
-
*
|
|
276
|
+
* Managed synthesis (through the user's Vellum account, billed to Vellum
|
|
277
|
+
* credits) is selectable two ways: `provider: "vellum"` directly, or
|
|
278
|
+
* `mode: "managed"` alongside a BYOK `provider` — the form the mode toggle
|
|
279
|
+
* writes, which leaves the BYOK choice untouched so switching back to
|
|
280
|
+
* `"your-own"` restores it. Use {@link effectiveTtsProvider} to resolve
|
|
281
|
+
* which provider is actually active.
|
|
281
282
|
*/
|
|
282
283
|
export const TtsServiceSchema = z
|
|
283
284
|
.object({
|
|
@@ -297,16 +298,6 @@ export const TtsServiceSchema = z
|
|
|
297
298
|
.describe("Active TTS provider used for speech synthesis"),
|
|
298
299
|
providers: TtsProvidersSchema.default(TtsProvidersSchema.parse({})),
|
|
299
300
|
})
|
|
300
|
-
.superRefine((service, ctx) => {
|
|
301
|
-
if (service.provider === "vellum" && service.mode !== "managed") {
|
|
302
|
-
ctx.addIssue({
|
|
303
|
-
code: "custom",
|
|
304
|
-
path: ["provider"],
|
|
305
|
-
message:
|
|
306
|
-
'services.tts.provider "vellum" requires services.tts.mode "managed"',
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
})
|
|
310
301
|
.describe(
|
|
311
302
|
"Text-to-speech service configuration — provider selection and per-provider settings",
|
|
312
303
|
);
|
|
@@ -316,14 +307,18 @@ export type TtsService = z.infer<typeof TtsServiceSchema>;
|
|
|
316
307
|
/**
|
|
317
308
|
* Resolve the provider that is actually active for the service config.
|
|
318
309
|
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
* `"your-own"` restores
|
|
310
|
+
* `provider: "vellum"` selects managed synthesis directly. Otherwise
|
|
311
|
+
* `mode: "managed"` routes to `vellum` while leaving the user's BYOK
|
|
312
|
+
* `provider` choice untouched, so toggling back to `"your-own"` restores
|
|
313
|
+
* their previous setup.
|
|
322
314
|
*/
|
|
323
315
|
export function effectiveTtsProvider(service: {
|
|
324
316
|
mode: TtsService["mode"];
|
|
325
317
|
provider?: string;
|
|
326
318
|
}): string {
|
|
319
|
+
if (service.provider === "vellum") {
|
|
320
|
+
return "vellum";
|
|
321
|
+
}
|
|
327
322
|
if (service.mode === "managed") {
|
|
328
323
|
return "vellum";
|
|
329
324
|
}
|
|
@@ -1583,6 +1583,21 @@ export async function runAgentLoopImpl(
|
|
|
1583
1583
|
publishLoopMessagesChanged();
|
|
1584
1584
|
}
|
|
1585
1585
|
} finally {
|
|
1586
|
+
// Clear the processing flag first. It is the release that frees the
|
|
1587
|
+
// conversation for its next turn, so nothing that can throw (the
|
|
1588
|
+
// turn-boundary commit, profiling) is allowed to run ahead of it and leave
|
|
1589
|
+
// the row latched "mid-turn". Stamp the turn's abnormal outcome first
|
|
1590
|
+
// because the telemetry reporter's settled-turn barrier only releases this
|
|
1591
|
+
// turn once processing stops; null `abortController` first so a concurrent
|
|
1592
|
+
// abort takes the force-clear branch rather than signalling a dead one.
|
|
1593
|
+
if (abnormalOutcome) {
|
|
1594
|
+
stampTurnOutcome(userMessageId, abnormalOutcome.outcome, {
|
|
1595
|
+
failureCode: abnormalOutcome.failureCode,
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
ctx.abortController = null;
|
|
1599
|
+
ctx.setProcessing(false);
|
|
1600
|
+
|
|
1586
1601
|
if (turnStarted) {
|
|
1587
1602
|
ctx.turnCount++;
|
|
1588
1603
|
const config = getConfig();
|
|
@@ -1618,24 +1633,12 @@ export async function runAgentLoopImpl(
|
|
|
1618
1633
|
|
|
1619
1634
|
emitToolProfilingSummary(ctx.conversationId, reqId);
|
|
1620
1635
|
|
|
1621
|
-
// Tear down
|
|
1636
|
+
// Tear down the remaining per-turn state. Abort reliably drives the loop to
|
|
1622
1637
|
// this `finally` within a bounded time — cooperative signal propagation
|
|
1623
1638
|
// (provider fetch + tool race) backed by the abort watchdog — so a
|
|
1624
1639
|
// cancelled turn always unwinds before any resend can start a new one.
|
|
1625
1640
|
// There is therefore only ever one turn alive, and clearing the shared
|
|
1626
1641
|
// state below cannot clobber a concurrent turn.
|
|
1627
|
-
// Stamp the turn's abnormal outcome (failed / cancelled) onto its
|
|
1628
|
-
// user-message row BEFORE processing clears: the telemetry reporter's
|
|
1629
|
-
// settled-turn barrier only releases this turn once the conversation
|
|
1630
|
-
// stops processing, so ordering the stamp first guarantees the turn
|
|
1631
|
-
// event ships with the outcome. A normally-replied turn stamps nothing.
|
|
1632
|
-
if (abnormalOutcome) {
|
|
1633
|
-
stampTurnOutcome(userMessageId, abnormalOutcome.outcome, {
|
|
1634
|
-
failureCode: abnormalOutcome.failureCode,
|
|
1635
|
-
});
|
|
1636
|
-
}
|
|
1637
|
-
ctx.abortController = null;
|
|
1638
|
-
ctx.setProcessing(false);
|
|
1639
1642
|
ctx.onConfirmationOutcome = undefined;
|
|
1640
1643
|
ctx.surfaceActionRequestIds.delete(ctx.currentRequestId ?? "");
|
|
1641
1644
|
ctx.approvedViaPromptThisTurn = false;
|
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { getConfig } from "../config/loader.js";
|
|
16
|
+
import {
|
|
17
|
+
ADOPTABLE_CONVERSATION_ID_RE,
|
|
18
|
+
createConversation,
|
|
19
|
+
ensureConversationExists,
|
|
20
|
+
getConversation,
|
|
21
|
+
} from "../persistence/conversation-crud.js";
|
|
16
22
|
import { wrapWithCallSiteRouting } from "../providers/call-site-routing.js";
|
|
17
23
|
import {
|
|
18
24
|
mainAgentResolutionError,
|
|
@@ -157,6 +163,35 @@ export async function getOrCreateConversation(
|
|
|
157
163
|
},
|
|
158
164
|
);
|
|
159
165
|
newConversation.updateClient(sendToClient, true);
|
|
166
|
+
|
|
167
|
+
// Ensure the conversations row exists before hydrating from DB.
|
|
168
|
+
// `getOrCreateConversation` builds the in-memory Conversation, but
|
|
169
|
+
// the persisted row is what `loadFromDb` reads for conversationType,
|
|
170
|
+
// source, and other metadata. If the row doesn't exist yet (brand-new
|
|
171
|
+
// conversation), create it now so hydration caches the right fields.
|
|
172
|
+
//
|
|
173
|
+
// When `conversationType` is provided (e.g. "background" for
|
|
174
|
+
// plugin-driven conversations), create the row with that type so it
|
|
175
|
+
// is hidden from the sidebar. The ID is validated against the same
|
|
176
|
+
// pattern as `ensureConversationExists` to prevent path traversal.
|
|
177
|
+
// Otherwise use `ensureConversationExists` directly, which validates
|
|
178
|
+
// and creates a standard row.
|
|
179
|
+
if (!getConversation(conversationId)) {
|
|
180
|
+
if (storedOptions?.conversationType) {
|
|
181
|
+
if (!ADOPTABLE_CONVERSATION_ID_RE.test(conversationId)) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`Refusing to adopt unsafe conversation id: ${JSON.stringify(conversationId)}`,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
createConversation({
|
|
187
|
+
id: conversationId,
|
|
188
|
+
conversationType: storedOptions.conversationType,
|
|
189
|
+
});
|
|
190
|
+
} else {
|
|
191
|
+
ensureConversationExists(conversationId);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
160
195
|
await newConversation.loadFromDb();
|
|
161
196
|
if (storedOptions?.assistantId) {
|
|
162
197
|
newConversation.setAssistantId(storedOptions.assistantId);
|
|
@@ -1500,10 +1500,10 @@ export class Conversation {
|
|
|
1500
1500
|
* Mutate the server-authoritative `processing` flag. Web/Capacitor/CLI
|
|
1501
1501
|
* caches treat this flag as the source of truth for the avatar streaming
|
|
1502
1502
|
* ring and thinking indicator, so the `true → false` clear must announce
|
|
1503
|
-
* itself: the daemon flips it in the agent-loop `finally
|
|
1504
|
-
*
|
|
1505
|
-
*
|
|
1506
|
-
*
|
|
1503
|
+
* itself: the daemon flips it in the agent-loop `finally`, which runs after
|
|
1504
|
+
* the user-visible terminal SSE events, and a racing metadata refetch can
|
|
1505
|
+
* otherwise re-read the not-yet-cleared `true` and clobber the client's
|
|
1506
|
+
* optimistic `false`.
|
|
1507
1507
|
*
|
|
1508
1508
|
* Emitting a metadata invalidation on the clear lets every client GET the
|
|
1509
1509
|
* authoritative `false`, per the multi-client-sync contract in AGENTS.md
|
|
@@ -15,6 +15,7 @@ import { getConfig } from "../../config/loader.js";
|
|
|
15
15
|
import type { LLMCallSite, Speed } from "../../config/schemas/llm.js";
|
|
16
16
|
import { ipcCall as gatewayIpcCall } from "../../ipc/gateway-client.js";
|
|
17
17
|
import type { SecretPromptResult } from "../../permissions/secret-prompt-types.js";
|
|
18
|
+
import type { ConversationCreateType } from "../../persistence/conversation-types.js";
|
|
18
19
|
import { resolveMediaSourceData } from "../../providers/media-resolve.js";
|
|
19
20
|
import { isPlaceholderSentinelText } from "../../providers/placeholder-sentinels.js";
|
|
20
21
|
import type { MediaSource } from "../../providers/types.js";
|
|
@@ -184,6 +185,13 @@ export interface ConversationCreateOptions {
|
|
|
184
185
|
* chronological renderer to consume.
|
|
185
186
|
*/
|
|
186
187
|
slackInbound?: SlackInboundMessageMetadata;
|
|
188
|
+
/**
|
|
189
|
+
* Conversation type for newly created conversations. When omitted,
|
|
190
|
+
* defaults to `"standard"` (visible in the sidebar). Set to
|
|
191
|
+
* `"background"` for plugin-driven conversations that should not
|
|
192
|
+
* appear in the sidebar's Recents grouping.
|
|
193
|
+
*/
|
|
194
|
+
conversationType?: ConversationCreateType;
|
|
187
195
|
}
|
|
188
196
|
|
|
189
197
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
@@ -696,7 +704,7 @@ export function renderHistoryContent(
|
|
|
696
704
|
continue;
|
|
697
705
|
}
|
|
698
706
|
const resolved = resolveMediaSourceData(source);
|
|
699
|
-
if (resolved) imageDataList.push(resolved.data);
|
|
707
|
+
if (resolved) {imageDataList.push(resolved.data);}
|
|
700
708
|
}
|
|
701
709
|
}
|
|
702
710
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { maybeDefaultSpeechToManaged } from "../config/managed-speech-defaults.js";
|
|
1
2
|
import { rehydratePlatformCredentials } from "../config/platform-rehydration.js";
|
|
2
3
|
import type { AssistantConfig } from "../config/types.js";
|
|
3
4
|
import { getMcpServerManager } from "../mcp/manager.js";
|
|
@@ -32,6 +33,13 @@ export async function initializeProvidersAndTools(
|
|
|
32
33
|
// overrides are normally only set by the secret-routes handlers at runtime.
|
|
33
34
|
await rehydratePlatformCredentials();
|
|
34
35
|
|
|
36
|
+
// Speech defaulting normally fires when the platform credentials land
|
|
37
|
+
// (secret-routes); evaluating it once per boot also covers assistants whose
|
|
38
|
+
// connection predates that trigger, so voice works for every connected
|
|
39
|
+
// assistant with no configured speech credentials. Idempotent, and detached
|
|
40
|
+
// per the startup philosophy — must not block boot.
|
|
41
|
+
void maybeDefaultSpeechToManaged();
|
|
42
|
+
|
|
35
43
|
await initializeProviders(config);
|
|
36
44
|
// initializeTools() also loads workspace tool overrides from
|
|
37
45
|
// `<workspaceDir>/tools/` once core tools have settled, so they own
|
|
@@ -879,7 +879,7 @@ export function createConversation(
|
|
|
879
879
|
* web client's `crypto.randomUUID()` / `draft-<ts>-<hex>` drafts while
|
|
880
880
|
* rejecting anything with path separators, `..`, or other traversal vectors.
|
|
881
881
|
*/
|
|
882
|
-
const ADOPTABLE_CONVERSATION_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
882
|
+
export const ADOPTABLE_CONVERSATION_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
883
883
|
|
|
884
884
|
/**
|
|
885
885
|
* Ensure a `conversations` row exists for `id`, creating one with default
|
|
@@ -45,6 +45,15 @@ export interface RunConversationTurnOptions {
|
|
|
45
45
|
* controller fires, terminating the in-flight agent loop.
|
|
46
46
|
*/
|
|
47
47
|
signal?: AbortSignal;
|
|
48
|
+
/**
|
|
49
|
+
* Conversation type for newly created conversations. When omitted,
|
|
50
|
+
* defaults to `"standard"` (visible in the sidebar). Set to
|
|
51
|
+
* `"background"` for plugin-driven conversations that should not
|
|
52
|
+
* appear in the sidebar's Recents grouping.
|
|
53
|
+
*
|
|
54
|
+
* Ignored when `conversationId` references an existing conversation.
|
|
55
|
+
*/
|
|
56
|
+
conversationType?: "standard" | "background";
|
|
48
57
|
}
|
|
49
58
|
|
|
50
59
|
export interface RunConversationTurnResult {
|
|
@@ -134,27 +143,25 @@ export async function runConversationTurn(
|
|
|
134
143
|
await import("../runtime/assistant-event-hub.js");
|
|
135
144
|
const { resolveMediaSourceData } =
|
|
136
145
|
await import("../providers/media-resolve.js");
|
|
137
|
-
const {
|
|
138
|
-
|
|
146
|
+
const { getConversation, getMessageById, getMessages } =
|
|
147
|
+
await import("../persistence/conversation-crud.js");
|
|
139
148
|
const { publishConversationListAndMetadataChanged } =
|
|
140
|
-
|
|
149
|
+
await import("../runtime/sync/resource-sync-events.js");
|
|
141
150
|
|
|
142
151
|
const conversationId = options.conversationId ?? uuidv7();
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
// "created" list invalidation that route does so they see it without
|
|
157
|
-
// waiting for a reload.
|
|
152
|
+
const rowExisted = getConversation(conversationId) != null;
|
|
153
|
+
const conversation = await getOrCreateConversation(conversationId, {
|
|
154
|
+
...(options.conversationType
|
|
155
|
+
? { conversationType: options.conversationType }
|
|
156
|
+
: {}),
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// `getOrCreateConversation` creates the DB row (with conversationType if
|
|
160
|
+
// provided) before hydrating. The normal send-message route emits a
|
|
161
|
+
// "created" list invalidation so sibling clients/sidebars learn about new
|
|
162
|
+
// conversations — emit it here too, but only when the row is actually new
|
|
163
|
+
// so we don't spam invalidations for existing conversations.
|
|
164
|
+
if (!rowExisted) {
|
|
158
165
|
publishConversationListAndMetadataChanged("created", conversationId);
|
|
159
166
|
}
|
|
160
167
|
|
|
@@ -50,8 +50,10 @@ export interface FetchProviderCatalogEntry {
|
|
|
50
50
|
export const FETCH_PROVIDER_CATALOG: readonly FetchProviderCatalogEntry[] = [
|
|
51
51
|
{
|
|
52
52
|
id: "default",
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
// Display-only: fetching runs in the daemon, not through the platform
|
|
54
|
+
// proxy. The id stays `default` until a managed fetch route exists.
|
|
55
|
+
displayName: "Vellum",
|
|
56
|
+
displayNameLong: "Vellum built-in fetcher",
|
|
55
57
|
kind: "builtin",
|
|
56
58
|
},
|
|
57
59
|
{
|
|
@@ -695,7 +695,6 @@ const ConfigGetResponseSchema = z
|
|
|
695
695
|
.optional(),
|
|
696
696
|
"web-fetch": z
|
|
697
697
|
.object({
|
|
698
|
-
mode: ServiceModeSchema.optional(),
|
|
699
698
|
provider: z.string().optional(),
|
|
700
699
|
})
|
|
701
700
|
.passthrough()
|
|
@@ -800,7 +799,6 @@ const ConfigPatchRequestSchema = z
|
|
|
800
799
|
.optional(),
|
|
801
800
|
"web-fetch": z
|
|
802
801
|
.object({
|
|
803
|
-
mode: ServiceModeSchema.optional(),
|
|
804
802
|
provider: z.string().optional(),
|
|
805
803
|
})
|
|
806
804
|
.passthrough()
|
|
@@ -7,7 +7,7 @@ let mockFirecrawlSecureKey: string | undefined;
|
|
|
7
7
|
|
|
8
8
|
/** Seed the active web-fetch provider into the workspace config for real. */
|
|
9
9
|
function seedWebFetch(provider: string): void {
|
|
10
|
-
setConfig("services", { "web-fetch": {
|
|
10
|
+
setConfig("services", { "web-fetch": { provider } });
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
mock.module("../../../security/secure-keys.js", () => ({
|
|
@@ -54,11 +54,9 @@ const DEFINITIONS = {
|
|
|
54
54
|
/**
|
|
55
55
|
* Definitions in display order (e.g. settings dropdowns).
|
|
56
56
|
*/
|
|
57
|
-
// vellum is
|
|
58
|
-
// `services.tts.mode`, not the provider picker — today's settings UI writes
|
|
59
|
-
// only `provider` + an API key, which the schema rejects for vellum. The
|
|
60
|
-
// definition stays in DEFINITIONS so managed-mode resolution works.
|
|
57
|
+
// vellum leads: it is the managed option, selected like any other provider.
|
|
61
58
|
const CATALOG: readonly TtsProviderDefinition[] = [
|
|
59
|
+
DEFINITIONS.vellum,
|
|
62
60
|
DEFINITIONS.elevenlabs,
|
|
63
61
|
DEFINITIONS["fish-audio"],
|
|
64
62
|
DEFINITIONS.deepgram,
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { WorkspaceMigration } from "./types.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Strip the now-removed `services.web-fetch.mode` field from existing
|
|
8
|
+
* `config.json` files. Web fetch has no managed proxy, so the field never
|
|
9
|
+
* governed anything — provider is the only axis — and the schema no longer
|
|
10
|
+
* recognizes it.
|
|
11
|
+
*
|
|
12
|
+
* Purely tidying: the schema strips unknown keys, so a lingering `mode` is
|
|
13
|
+
* inert at runtime. This exists so upgraded configs on disk match the schema
|
|
14
|
+
* rather than carrying a dead key indefinitely.
|
|
15
|
+
*
|
|
16
|
+
* Idempotent: re-running when `mode` is already absent is a no-op.
|
|
17
|
+
*/
|
|
18
|
+
export const dropWebFetchModeMigration: WorkspaceMigration = {
|
|
19
|
+
id: "131-drop-web-fetch-mode",
|
|
20
|
+
description:
|
|
21
|
+
"Strip services.web-fetch.mode from config.json (mode field removed from schema)",
|
|
22
|
+
run(workspaceDir: string): void {
|
|
23
|
+
const configPath = join(workspaceDir, "config.json");
|
|
24
|
+
if (!existsSync(configPath)) return;
|
|
25
|
+
|
|
26
|
+
let config: Record<string, unknown>;
|
|
27
|
+
try {
|
|
28
|
+
const raw = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
29
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return;
|
|
30
|
+
config = raw as Record<string, unknown>;
|
|
31
|
+
} catch {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const services = config.services;
|
|
36
|
+
if (
|
|
37
|
+
services === null ||
|
|
38
|
+
typeof services !== "object" ||
|
|
39
|
+
Array.isArray(services)
|
|
40
|
+
)
|
|
41
|
+
return;
|
|
42
|
+
|
|
43
|
+
const webFetch = (services as Record<string, unknown>)["web-fetch"];
|
|
44
|
+
if (
|
|
45
|
+
webFetch === null ||
|
|
46
|
+
typeof webFetch !== "object" ||
|
|
47
|
+
Array.isArray(webFetch)
|
|
48
|
+
)
|
|
49
|
+
return;
|
|
50
|
+
|
|
51
|
+
const webFetchObj = webFetch as Record<string, unknown>;
|
|
52
|
+
if (!("mode" in webFetchObj)) return;
|
|
53
|
+
|
|
54
|
+
delete webFetchObj.mode;
|
|
55
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
56
|
+
},
|
|
57
|
+
down(_workspaceDir: string): void {
|
|
58
|
+
// Forward-only: re-adding mode would reintroduce a field the schema no
|
|
59
|
+
// longer recognizes.
|
|
60
|
+
},
|
|
61
|
+
};
|
|
@@ -127,6 +127,7 @@ import { stripManagedProfileBodiesMigration } from "./126-strip-managed-profile-
|
|
|
127
127
|
import { backfillDefaultProviderMigration } from "./127-backfill-default-provider.js";
|
|
128
128
|
import { repairStaleOpenrouterGrokModelIdsMigration } from "./128-repair-stale-openrouter-grok-model-ids.js";
|
|
129
129
|
import { removeAnalyzeConversationConfigMigration } from "./129-remove-analyze-conversation-config.js";
|
|
130
|
+
import { dropWebFetchModeMigration } from "./131-drop-web-fetch-mode.js";
|
|
130
131
|
import { migrateToWorkspaceVolumeMigration } from "./migrate-to-workspace-volume.js";
|
|
131
132
|
import type { WorkspaceMigration } from "./types.js";
|
|
132
133
|
|
|
@@ -265,4 +266,5 @@ export const WORKSPACE_MIGRATIONS: WorkspaceMigration[] = [
|
|
|
265
266
|
backfillDefaultProviderMigration,
|
|
266
267
|
repairStaleOpenrouterGrokModelIdsMigration,
|
|
267
268
|
removeAnalyzeConversationConfigMigration,
|
|
269
|
+
dropWebFetchModeMigration,
|
|
268
270
|
];
|