@vellumai/assistant 0.10.12-dev.202607281935.fa0f06f → 0.10.12-dev.202607282031.4f29afe

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/eslint.config.mjs CHANGED
@@ -49,6 +49,39 @@ const eslintConfig = defineConfig([
49
49
  "@typescript-eslint/no-explicit-any": "off",
50
50
  },
51
51
  },
52
+ // Managed-column profile resolution (`getEffectiveProfile(s)`) resolves
53
+ // default profiles against the vellum column only, ignoring
54
+ // `llm.defaultProvider`; on a BYO install that is not the body that
55
+ // dispatches. Runtime code must use `resolveDefaultProfileForProvider` /
56
+ // `getEffectiveProfilesForProvider` instead. The allowlist below is the
57
+ // full set of intentional managed-column consumers: the catalog itself,
58
+ // hatch-time seeding (writes managed stubs by design), and write-path
59
+ // validation.
60
+ {
61
+ files: ["src/**/*.ts"],
62
+ ignores: [
63
+ "src/config/default-profile-catalog.ts",
64
+ "src/config/seed-inference-profiles.ts",
65
+ "src/config/inference-profile-validation.ts",
66
+ "**/__tests__/**",
67
+ "**/*.test.ts",
68
+ ],
69
+ rules: {
70
+ "no-restricted-imports": [
71
+ "error",
72
+ {
73
+ patterns: [
74
+ {
75
+ group: ["**/default-profile-catalog.js"],
76
+ importNames: ["getEffectiveProfile", "getEffectiveProfiles"],
77
+ message:
78
+ "Managed-column resolution ignores llm.defaultProvider. Use resolveDefaultProfileForProvider / getEffectiveProfilesForProvider with the parsed config's llm.defaultProvider ?? null.",
79
+ },
80
+ ],
81
+ },
82
+ ],
83
+ },
84
+ },
52
85
  // `cli/no-daemon-internals` keeps daemon-internal modules out of the CLI's
53
86
  // static import graph, so `assistant …` invocations (including the bash-tool
54
87
  // fast path) don't pay the memory cost of loading daemon subsystems. Keep at
package/openapi.yaml CHANGED
@@ -24784,6 +24784,10 @@ paths:
24784
24784
  anyOf:
24785
24785
  - type: string
24786
24786
  - type: "null"
24787
+ groupId:
24788
+ anyOf:
24789
+ - type: string
24790
+ - type: "null"
24787
24791
  createdFromConversationId:
24788
24792
  anyOf:
24789
24793
  - type: string
@@ -24849,6 +24853,7 @@ paths:
24849
24853
  - retryBackoffMs
24850
24854
  - timeoutMs
24851
24855
  - inferenceProfile
24856
+ - groupId
24852
24857
  - createdFromConversationId
24853
24858
  - createdFromConversationExists
24854
24859
  - createdFromConversationArchivedAt
@@ -24991,6 +24996,10 @@ paths:
24991
24996
  anyOf:
24992
24997
  - type: string
24993
24998
  - type: "null"
24999
+ groupId:
25000
+ anyOf:
25001
+ - type: string
25002
+ - type: "null"
24994
25003
  createdFromConversationId:
24995
25004
  anyOf:
24996
25005
  - type: string
@@ -25056,6 +25065,7 @@ paths:
25056
25065
  - retryBackoffMs
25057
25066
  - timeoutMs
25058
25067
  - inferenceProfile
25068
+ - groupId
25059
25069
  - createdFromConversationId
25060
25070
  - createdFromConversationExists
25061
25071
  - createdFromConversationArchivedAt
@@ -25152,6 +25162,10 @@ paths:
25152
25162
  anyOf:
25153
25163
  - type: string
25154
25164
  - type: "null"
25165
+ groupId:
25166
+ anyOf:
25167
+ - type: string
25168
+ - type: "null"
25155
25169
  createdFromConversationId:
25156
25170
  anyOf:
25157
25171
  - type: string
@@ -25217,6 +25231,7 @@ paths:
25217
25231
  - retryBackoffMs
25218
25232
  - timeoutMs
25219
25233
  - inferenceProfile
25234
+ - groupId
25220
25235
  - createdFromConversationId
25221
25236
  - createdFromConversationExists
25222
25237
  - createdFromConversationArchivedAt
@@ -25310,6 +25325,10 @@ paths:
25310
25325
  anyOf:
25311
25326
  - type: string
25312
25327
  - type: "null"
25328
+ groupId:
25329
+ anyOf:
25330
+ - type: string
25331
+ - type: "null"
25313
25332
  createdFromConversationId:
25314
25333
  anyOf:
25315
25334
  - type: string
@@ -25375,6 +25394,7 @@ paths:
25375
25394
  - retryBackoffMs
25376
25395
  - timeoutMs
25377
25396
  - inferenceProfile
25397
+ - groupId
25378
25398
  - createdFromConversationId
25379
25399
  - createdFromConversationExists
25380
25400
  - createdFromConversationArchivedAt
@@ -25527,6 +25547,10 @@ paths:
25527
25547
  anyOf:
25528
25548
  - type: string
25529
25549
  - type: "null"
25550
+ groupId:
25551
+ anyOf:
25552
+ - type: string
25553
+ - type: "null"
25530
25554
  createdFromConversationId:
25531
25555
  anyOf:
25532
25556
  - type: string
@@ -25592,6 +25616,7 @@ paths:
25592
25616
  - retryBackoffMs
25593
25617
  - timeoutMs
25594
25618
  - inferenceProfile
25619
+ - groupId
25595
25620
  - createdFromConversationId
25596
25621
  - createdFromConversationExists
25597
25622
  - createdFromConversationArchivedAt
@@ -25688,6 +25713,10 @@ paths:
25688
25713
  anyOf:
25689
25714
  - type: string
25690
25715
  - type: "null"
25716
+ groupId:
25717
+ anyOf:
25718
+ - type: string
25719
+ - type: "null"
25691
25720
  createdFromConversationId:
25692
25721
  anyOf:
25693
25722
  - type: string
@@ -25753,6 +25782,7 @@ paths:
25753
25782
  - retryBackoffMs
25754
25783
  - timeoutMs
25755
25784
  - inferenceProfile
25785
+ - groupId
25756
25786
  - createdFromConversationId
25757
25787
  - createdFromConversationExists
25758
25788
  - createdFromConversationArchivedAt
@@ -25849,6 +25879,10 @@ paths:
25849
25879
  anyOf:
25850
25880
  - type: string
25851
25881
  - type: "null"
25882
+ groupId:
25883
+ anyOf:
25884
+ - type: string
25885
+ - type: "null"
25852
25886
  createdFromConversationId:
25853
25887
  anyOf:
25854
25888
  - type: string
@@ -25914,6 +25948,7 @@ paths:
25914
25948
  - retryBackoffMs
25915
25949
  - timeoutMs
25916
25950
  - inferenceProfile
25951
+ - groupId
25917
25952
  - createdFromConversationId
25918
25953
  - createdFromConversationExists
25919
25954
  - createdFromConversationArchivedAt
@@ -26147,6 +26182,10 @@ paths:
26147
26182
  anyOf:
26148
26183
  - type: string
26149
26184
  - type: "null"
26185
+ groupId:
26186
+ anyOf:
26187
+ - type: string
26188
+ - type: "null"
26150
26189
  createdFromConversationId:
26151
26190
  anyOf:
26152
26191
  - type: string
@@ -26212,6 +26251,7 @@ paths:
26212
26251
  - retryBackoffMs
26213
26252
  - timeoutMs
26214
26253
  - inferenceProfile
26254
+ - groupId
26215
26255
  - createdFromConversationId
26216
26256
  - createdFromConversationExists
26217
26257
  - createdFromConversationArchivedAt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.10.12-dev.202607281935.fa0f06f",
3
+ "version": "0.10.12-dev.202607282031.4f29afe",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, test } from "bun:test";
3
3
  import type { AgentEvent } from "../agent/loop.js";
4
4
  import { AgentLoop } from "../agent/loop.js";
5
5
  import { resetPluginRegistryAndRegisterDefaults } from "../plugins/defaults/index.js";
6
+ import { registerPlugin } from "../plugins/registry.js";
6
7
  import type {
7
8
  Message,
8
9
  Provider,
@@ -105,4 +106,75 @@ describe("agent loop — built-in history-repair recovery", () => {
105
106
  expect(callCount()).toBe(2);
106
107
  expect(events.some((e) => e.type === "error")).toBe(true);
107
108
  });
109
+
110
+ test("dispatches post-model-call but lets native repair drive the ordering retry", async () => {
111
+ // A user hook that observes the rejection and blindly continues without
112
+ // repairing. It must still fire (the hook contract dispatches at every
113
+ // model-call outcome), but native ordering repair takes precedence, so the
114
+ // retry sends a repaired history rather than the hook's unrepaired continue.
115
+ let genericContinueFired = 0;
116
+ registerPlugin({
117
+ manifest: { name: "generic-continue", version: "0.0.1" },
118
+ hooks: {
119
+ "post-model-call": async (ctx) => {
120
+ if (ctx.error) {
121
+ genericContinueFired += 1;
122
+ ctx.decision = "continue";
123
+ }
124
+ },
125
+ },
126
+ });
127
+
128
+ // History with an orphan tool_use: deep repair appends a synthetic
129
+ // tool_result so the retry is well-formed.
130
+ const orphanHistory: Message[] = [
131
+ { role: "user", content: [{ type: "text", text: "hi" }] },
132
+ {
133
+ role: "assistant",
134
+ content: [{ type: "tool_use", id: "t1", name: "noop", input: {} }],
135
+ },
136
+ ];
137
+
138
+ let calls = 0;
139
+ let retryMessages: Message[] | null = null;
140
+ const provider: Provider = {
141
+ name: "test-ordering",
142
+ async sendMessage(messages): Promise<ProviderResponse> {
143
+ calls += 1;
144
+ if (calls === 1) {
145
+ throw new Error(ORDERING_REJECTION);
146
+ }
147
+ retryMessages = messages;
148
+ return textResponse("recovered");
149
+ },
150
+ };
151
+
152
+ const loop = new AgentLoop({
153
+ provider,
154
+ systemPrompt: "system",
155
+ conversationId: "test-conversation",
156
+ });
157
+
158
+ const events: AgentEvent[] = [];
159
+ await loop.run({
160
+ requestId: "test-request",
161
+ messages: orphanHistory,
162
+ onEvent: (e) => {
163
+ events.push(e);
164
+ },
165
+ trust: { sourceChannel: "vellum", trustClass: "unknown" },
166
+ });
167
+
168
+ // The hook observed the rejection (contract preserved).
169
+ expect(genericContinueFired).toBeGreaterThanOrEqual(1);
170
+ // Recovery happened in exactly one retry, and that retry used the repaired
171
+ // history: the orphan tool_use now has a matching tool_result. If the hook's
172
+ // unrepaired continue had driven the retry, this block would be absent.
173
+ expect(calls).toBe(2);
174
+ const repaired: Message[] = retryMessages ?? [];
175
+ const hasPairedResult = repaired.some((m) =>
176
+ m.content.some((b) => b.type === "tool_result" && b.tool_use_id === "t1"),
177
+ );
178
+ expect(hasPairedResult).toBe(true);
179
+ });
108
180
  });
@@ -257,7 +257,7 @@ describe("conversation_move_to_group tool", () => {
257
257
  expect(result.content).toContain("no conversation found");
258
258
  });
259
259
 
260
- test("notes hidden conversation types", async () => {
260
+ test("no hidden-type note when filing a background conversation into a custom group", async () => {
261
261
  createConversation({ id: "conv-bg", conversationType: "background" });
262
262
  await executeConversationGroupCreate({ name: "Visible" }, ctx);
263
263
 
@@ -267,7 +267,46 @@ describe("conversation_move_to_group tool", () => {
267
267
  );
268
268
 
269
269
  expect(result.isError).toBe(false);
270
- expect(result.content).toContain("hidden from the sidebar");
270
+ expect(result.content).not.toContain("hidden");
271
+ expect(result.content).not.toContain("standard listing");
272
+ });
273
+
274
+ test("notes that subagent conversations stay hidden", async () => {
275
+ createConversation({
276
+ id: "conv-sub",
277
+ conversationType: "background",
278
+ source: "subagent",
279
+ });
280
+ await executeConversationGroupCreate({ name: "Agents" }, ctx);
281
+
282
+ const result = await executeConversationMoveToGroup(
283
+ { group: "Agents", conversation_id: "conv-sub" },
284
+ ctx,
285
+ );
286
+
287
+ expect(result.isError).toBe(false);
288
+ expect(result.content).toContain(
289
+ "subagent conversations stay hidden from the sidebar",
290
+ );
291
+ });
292
+
293
+ test("notes non-standard types stay out of the standard listing when moved to a system group", async () => {
294
+ createConversation({
295
+ id: "conv-bg-recents",
296
+ conversationType: "background",
297
+ source: "task",
298
+ groupId: "system:background",
299
+ });
300
+
301
+ const result = await executeConversationMoveToGroup(
302
+ { group: "Recents", conversation_id: "conv-bg-recents" },
303
+ ctx,
304
+ );
305
+
306
+ expect(result.isError).toBe(false);
307
+ expect(result.content).toContain(
308
+ "stays out of the standard listing unless filed into a custom group",
309
+ );
271
310
  });
272
311
 
273
312
  test("rejects missing group", async () => {
@@ -0,0 +1,93 @@
1
+ import type { Database } from "bun:sqlite";
2
+ import { beforeEach, describe, expect, test } from "bun:test";
3
+
4
+ import { createConversation } from "../persistence/conversation-crud.js";
5
+ import { ensureGroupMigration } from "../persistence/conversation-group-migration.js";
6
+ import { listConversations } from "../persistence/conversation-queries.js";
7
+ import { getDb } from "../persistence/db-connection.js";
8
+ import { initializeDb } from "../persistence/db-init.js";
9
+ import { createGroup } from "../persistence/group-crud.js";
10
+
11
+ await initializeDb();
12
+ ensureGroupMigration();
13
+
14
+ function getRawDb(): Database {
15
+ return (getDb() as unknown as { $client: Database }).$client;
16
+ }
17
+
18
+ /**
19
+ * Custom-group arm of standard-listing visibility: a row filed into a
20
+ * user-created group renders in the standard (Recents) listing regardless of
21
+ * conversation type, so custom groups survive a cold sidebar load. System
22
+ * groups keep the type-based exclusions, and private/subagent rows stay
23
+ * hidden unconditionally.
24
+ */
25
+ describe("custom-group standard-listing visibility", () => {
26
+ let groupId: string;
27
+
28
+ beforeEach(() => {
29
+ const raw = getRawDb();
30
+ raw.run("DELETE FROM conversations");
31
+ raw.run("DELETE FROM conversation_groups WHERE is_system_group = 0");
32
+ groupId = createGroup("Briefs").id;
33
+ });
34
+
35
+ function listedIds(): string[] {
36
+ return listConversations(undefined, "standard").map((c) => c.id);
37
+ }
38
+
39
+ test("scheduled conversation in a custom group is listed", () => {
40
+ createConversation({
41
+ id: "conv-sched-custom",
42
+ conversationType: "scheduled",
43
+ source: "schedule",
44
+ groupId,
45
+ });
46
+
47
+ expect(listedIds()).toContain("conv-sched-custom");
48
+ });
49
+
50
+ test("background conversation in a custom group is listed", () => {
51
+ createConversation({
52
+ id: "conv-bg-custom",
53
+ conversationType: "background",
54
+ source: "task",
55
+ groupId,
56
+ });
57
+
58
+ expect(listedIds()).toContain("conv-bg-custom");
59
+ });
60
+
61
+ test("scheduled conversation in system:scheduled stays excluded", () => {
62
+ createConversation({
63
+ id: "conv-sched-system",
64
+ conversationType: "scheduled",
65
+ source: "schedule",
66
+ groupId: "system:scheduled",
67
+ });
68
+
69
+ expect(listedIds()).not.toContain("conv-sched-system");
70
+ });
71
+
72
+ test("subagent conversation stays hidden even in a custom group", () => {
73
+ createConversation({
74
+ id: "conv-subagent-custom",
75
+ conversationType: "background",
76
+ source: "subagent",
77
+ groupId,
78
+ });
79
+
80
+ expect(listedIds()).not.toContain("conv-subagent-custom");
81
+ });
82
+
83
+ test("private conversation stays hidden even in a custom group", () => {
84
+ // "private" is not a creatable type (legacy rows only, see the
85
+ // conversationTypeClause docstring), so simulate a legacy row directly.
86
+ createConversation({ id: "conv-private-custom", groupId });
87
+ getRawDb().run(
88
+ "UPDATE conversations SET conversation_type = 'private' WHERE id = 'conv-private-custom'",
89
+ );
90
+
91
+ expect(listedIds()).not.toContain("conv-private-custom");
92
+ });
93
+ });
@@ -54,6 +54,7 @@ describe("schedule_syntax column migration", () => {
54
54
  workflow_args_json TEXT,
55
55
  timeout_ms INTEGER,
56
56
  inference_profile TEXT,
57
+ group_id TEXT,
57
58
  capabilities_json TEXT,
58
59
  description TEXT NOT NULL DEFAULT '',
59
60
  created_at INTEGER NOT NULL,
@@ -2,8 +2,14 @@ import type { Database } from "bun:sqlite";
2
2
  import { afterAll, beforeEach, describe, expect, test } from "bun:test";
3
3
 
4
4
  import { RiskLevel } from "../permissions/types.js";
5
+ import { ensureGroupMigration } from "../persistence/conversation-group-migration.js";
5
6
  import { getDb } from "../persistence/db-connection.js";
6
7
  import { initializeDb } from "../persistence/db-init.js";
8
+ import { createGroup, deleteGroup } from "../persistence/group-crud.js";
9
+ import {
10
+ getSchedule,
11
+ resolveScheduleConversationGroupId,
12
+ } from "../schedule/schedule-store.js";
7
13
  import {
8
14
  __clearRegistryForTesting,
9
15
  __resetRegistryForTesting,
@@ -2057,3 +2063,103 @@ describe("schedule tools — model-input schema validation", () => {
2057
2063
  );
2058
2064
  });
2059
2065
  });
2066
+
2067
+ // ── schedule_create / schedule_update group ─────────────────────────
2068
+
2069
+ describe("schedule_create / schedule_update group", () => {
2070
+ beforeEach(() => {
2071
+ ensureGroupMigration();
2072
+ getRawDb().run("DELETE FROM cron_runs");
2073
+ getRawDb().run("DELETE FROM cron_jobs");
2074
+ getRawDb().run("DELETE FROM conversation_groups WHERE is_system_group = 0");
2075
+ });
2076
+
2077
+ function extractJobId(content: string): string {
2078
+ const match = content.match(/ID: (\S+)/);
2079
+ expect(match).not.toBeNull();
2080
+ return match![1];
2081
+ }
2082
+
2083
+ test("creates a schedule filed into a custom group by name", async () => {
2084
+ const group = createGroup("Briefs");
2085
+
2086
+ const result = await executeScheduleCreate(
2087
+ {
2088
+ name: "Morning brief",
2089
+ expression: "0 8 * * *",
2090
+ message: "Compile the morning brief.",
2091
+ group: "briefs",
2092
+ },
2093
+ ctx,
2094
+ );
2095
+
2096
+ expect(result.isError).toBeFalsy();
2097
+ expect(result.content).toContain("Conversation group: Briefs");
2098
+ const job = getSchedule(extractJobId(result.content));
2099
+ expect(job?.groupId).toBe(group.id);
2100
+ expect(resolveScheduleConversationGroupId(job!)).toBe(group.id);
2101
+ });
2102
+
2103
+ test("rejects an unknown group with the available list", async () => {
2104
+ const result = await executeScheduleCreate(
2105
+ {
2106
+ name: "Orphan",
2107
+ expression: "0 8 * * *",
2108
+ message: "msg",
2109
+ group: "Nonexistent",
2110
+ },
2111
+ ctx,
2112
+ );
2113
+
2114
+ expect(result.isError).toBe(true);
2115
+ expect(result.content).toContain('No group named "Nonexistent"');
2116
+ });
2117
+
2118
+ test("update sets and clears the group", async () => {
2119
+ const group = createGroup("Reports");
2120
+ const created = await executeScheduleCreate(
2121
+ { name: "Weekly report", expression: "0 9 * * 1", message: "msg" },
2122
+ ctx,
2123
+ );
2124
+ const jobId = extractJobId(created.content);
2125
+ expect(getSchedule(jobId)?.groupId).toBeNull();
2126
+
2127
+ const updated = await executeScheduleUpdate(
2128
+ { job_id: jobId, group: "Reports" },
2129
+ ctx,
2130
+ );
2131
+ expect(updated.isError).toBeFalsy();
2132
+ expect(getSchedule(jobId)?.groupId).toBe(group.id);
2133
+
2134
+ const cleared = await executeScheduleUpdate(
2135
+ { job_id: jobId, group: null },
2136
+ ctx,
2137
+ );
2138
+ expect(cleared.isError).toBeFalsy();
2139
+ expect(getSchedule(jobId)?.groupId).toBeNull();
2140
+ });
2141
+
2142
+ test("run conversations fall back to system:scheduled when the group is deleted", async () => {
2143
+ const group = createGroup("Ephemeral");
2144
+ const created = await executeScheduleCreate(
2145
+ {
2146
+ name: "Doomed group",
2147
+ expression: "0 9 * * *",
2148
+ message: "msg",
2149
+ group: group.id,
2150
+ },
2151
+ ctx,
2152
+ );
2153
+ const job = getSchedule(extractJobId(created.content));
2154
+ expect(job?.groupId).toBe(group.id);
2155
+
2156
+ deleteGroup(group.id);
2157
+ expect(resolveScheduleConversationGroupId(job!)).toBe("system:scheduled");
2158
+ });
2159
+
2160
+ test("resolveScheduleConversationGroupId defaults to system:scheduled", () => {
2161
+ expect(resolveScheduleConversationGroupId({ groupId: null })).toBe(
2162
+ "system:scheduled",
2163
+ );
2164
+ });
2165
+ });
@@ -1,5 +1,11 @@
1
1
  import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
2
2
 
3
+ import {
4
+ invalidateConfigCache,
5
+ loadRawConfig,
6
+ saveRawConfig,
7
+ setNestedValue,
8
+ } from "../config/loader.js";
3
9
  import { credentialKey } from "../security/credential-key.js";
4
10
 
5
11
  let secureKeyStore: Record<string, string> = {};
@@ -8,9 +14,28 @@ let oauthConnectionStore: Record<
8
14
  { id: string; status: string; accountInfo?: string | null }
9
15
  > = {};
10
16
  const syncCalls: Array<{ provider: string; accountInfo?: string }> = [];
17
+ let platformContextEnabled = false;
11
18
 
19
+ const registerCallbackRouteMock = mock(
20
+ async (callbackPath: string, _type: string) =>
21
+ `https://gateway.vellum.ai/assistant-123/${callbackPath}`,
22
+ );
23
+
24
+ // Spread the real module: it is a shared barrel and replacing it wholesale
25
+ // breaks unrelated importers pulled in by the module under test.
26
+ const actualPlatformCallbackRegistration =
27
+ await import("../inbound/platform-callback-registration.js");
12
28
  mock.module("../inbound/platform-callback-registration.js", () => ({
13
- registerCallbackRoute: async () => {},
29
+ ...actualPlatformCallbackRegistration,
30
+ registerCallbackRoute: registerCallbackRouteMock,
31
+ resolvePlatformCallbackRegistrationContext: async () => ({
32
+ isPlatform: false,
33
+ platformBaseUrl: platformContextEnabled ? "https://api.vellum.ai" : "",
34
+ assistantId: platformContextEnabled ? "assistant-123" : "",
35
+ hasAssistantApiKey: platformContextEnabled,
36
+ authHeader: platformContextEnabled ? "Api-Key secret" : null,
37
+ enabled: platformContextEnabled,
38
+ }),
14
39
  }));
15
40
 
16
41
  mock.module("../daemon/handlers/shared.js", () => ({
@@ -77,13 +102,37 @@ mock.module("../tools/credentials/metadata-store.js", () => ({
77
102
 
78
103
  const originalFetch = globalThis.fetch;
79
104
 
80
- import { getTelegramConfig } from "../daemon/handlers/config-telegram.js";
105
+ const { getTelegramConfig, setTelegramConfig } =
106
+ await import("../daemon/handlers/config-telegram.js");
107
+
108
+ function mockTelegramApi(): typeof fetch {
109
+ return (async (input: RequestInfo | URL) => {
110
+ const url = String(input);
111
+ if (url.includes("/getMe")) {
112
+ return new Response(
113
+ JSON.stringify({ ok: true, result: { id: 42, username: "testbot" } }),
114
+ { status: 200 },
115
+ );
116
+ }
117
+ return new Response(JSON.stringify({ ok: true }), { status: 200 });
118
+ }) as typeof fetch;
119
+ }
120
+
121
+ function setIngressPublicBaseUrl(url: string): void {
122
+ const raw = loadRawConfig();
123
+ setNestedValue(raw, "ingress.publicBaseUrl", url);
124
+ saveRawConfig(raw);
125
+ invalidateConfigCache();
126
+ }
81
127
 
82
128
  describe("Telegram config handler", () => {
83
129
  beforeEach(() => {
84
130
  secureKeyStore = {};
85
131
  oauthConnectionStore = {};
86
132
  syncCalls.length = 0;
133
+ platformContextEnabled = false;
134
+ registerCallbackRouteMock.mockClear();
135
+ setIngressPublicBaseUrl("");
87
136
  globalThis.fetch = originalFetch;
88
137
  });
89
138
 
@@ -105,4 +154,49 @@ describe("Telegram config handler", () => {
105
154
  ]);
106
155
  expect(oauthConnectionStore["telegram"]?.accountInfo).toBe("@testbot");
107
156
  });
157
+
158
+ // A platform-connected local assistant (IS_PLATFORM unset, valid platform
159
+ // credentials, no public ingress) receives Telegram webhooks only through
160
+ // managed platform callbacks, so saving the bot token must register the
161
+ // route.
162
+ test("set registers the platform callback route for a platform-connected local assistant", async () => {
163
+ platformContextEnabled = true;
164
+ globalThis.fetch = mockTelegramApi();
165
+
166
+ const result = await setTelegramConfig(
167
+ "123456789:AAtesttoken_testtoken_testtoken_test",
168
+ );
169
+
170
+ expect(result.success).toBe(true);
171
+ expect(registerCallbackRouteMock).toHaveBeenCalledWith(
172
+ "webhooks/telegram",
173
+ "telegram",
174
+ );
175
+ });
176
+
177
+ test("set does not register a platform callback route when not platform-connected", async () => {
178
+ globalThis.fetch = mockTelegramApi();
179
+
180
+ const result = await setTelegramConfig(
181
+ "123456789:AAtesttoken_testtoken_testtoken_test",
182
+ );
183
+
184
+ expect(result.success).toBe(true);
185
+ expect(registerCallbackRouteMock).not.toHaveBeenCalled();
186
+ });
187
+
188
+ // A logged-in local assistant holds platform credentials for the LLM proxy,
189
+ // so credential presence must not override an explicitly configured ingress.
190
+ test("set does not register a platform callback route when a public ingress is configured", async () => {
191
+ platformContextEnabled = true;
192
+ setIngressPublicBaseUrl("https://abc.ngrok.io");
193
+ globalThis.fetch = mockTelegramApi();
194
+
195
+ const result = await setTelegramConfig(
196
+ "123456789:AAtesttoken_testtoken_testtoken_test",
197
+ );
198
+
199
+ expect(result.success).toBe(true);
200
+ expect(registerCallbackRouteMock).not.toHaveBeenCalled();
201
+ });
108
202
  });