@vellumai/assistant 0.11.7-dev.202608312114.5fab2e2 → 0.11.7-dev.202608312215.dd090a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/__tests__/channel-delivery-store.test.ts +48 -0
- package/src/__tests__/openai-provider.test.ts +63 -0
- package/src/__tests__/outbound-slack-persistence.test.ts +92 -2
- package/src/__tests__/retry-thinking-adaptive-only.test.ts +67 -0
- package/src/config/feature-flag-registry.json +0 -8
- package/src/daemon/conversation-agent-loop-handlers.ts +17 -0
- package/src/persistence/delivery-crud.ts +14 -12
- package/src/providers/fireworks/client.ts +9 -1
- package/src/providers/model-catalog.ts +67 -0
- package/src/providers/openai/chat-completions-provider.ts +44 -5
- package/src/providers/retry.ts +16 -11
- package/src/runtime/AGENTS.md +7 -2
- package/src/runtime/channel-reply-delivery.ts +44 -19
- package/src/runtime/routes/inbound-stages/reaction-intercept.test.ts +32 -3
- package/src/runtime/routes/inbound-stages/reaction-intercept.ts +5 -3
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ import { getDb } from "../persistence/db-connection.js";
|
|
|
10
10
|
import { initializeDb } from "../persistence/db-init.js";
|
|
11
11
|
import {
|
|
12
12
|
clearPayload,
|
|
13
|
+
findConversationByProviderMessageId,
|
|
13
14
|
findMessageBySourceId,
|
|
14
15
|
linkMessage,
|
|
15
16
|
recordInbound,
|
|
@@ -122,6 +123,53 @@ describe("channel-delivery-store", () => {
|
|
|
122
123
|
expect(row!.sourceMessageId).toBe("src-42");
|
|
123
124
|
});
|
|
124
125
|
|
|
126
|
+
test("resolves an assistant post by its provider id on a non-Slack channel", () => {
|
|
127
|
+
const chatId = "999000111222333444";
|
|
128
|
+
const minted = recordInbound("discord", chatId, "evt-seed");
|
|
129
|
+
const db = getDb();
|
|
130
|
+
db.insert(messages)
|
|
131
|
+
.values({
|
|
132
|
+
id: "assistant-post-1",
|
|
133
|
+
conversationId: minted.conversationId,
|
|
134
|
+
role: "assistant",
|
|
135
|
+
content: "outbound reply",
|
|
136
|
+
createdAt: Date.now(),
|
|
137
|
+
metadata: JSON.stringify({
|
|
138
|
+
providerMeta: JSON.stringify({
|
|
139
|
+
source: "discord",
|
|
140
|
+
conversationExternalId: chatId,
|
|
141
|
+
messageId: "1234567890123456789",
|
|
142
|
+
eventKind: "message",
|
|
143
|
+
}),
|
|
144
|
+
}),
|
|
145
|
+
})
|
|
146
|
+
.run();
|
|
147
|
+
|
|
148
|
+
expect(
|
|
149
|
+
findConversationByProviderMessageId(
|
|
150
|
+
"discord",
|
|
151
|
+
chatId,
|
|
152
|
+
"1234567890123456789",
|
|
153
|
+
),
|
|
154
|
+
).toBe(minted.conversationId);
|
|
155
|
+
// The scan is scoped to the reaction's own channel address: the same id
|
|
156
|
+
// is invisible from another channel's or another chat's key space.
|
|
157
|
+
expect(
|
|
158
|
+
findConversationByProviderMessageId(
|
|
159
|
+
"telegram",
|
|
160
|
+
chatId,
|
|
161
|
+
"1234567890123456789",
|
|
162
|
+
),
|
|
163
|
+
).toBeNull();
|
|
164
|
+
expect(
|
|
165
|
+
findConversationByProviderMessageId(
|
|
166
|
+
"discord",
|
|
167
|
+
"other-chat",
|
|
168
|
+
"1234567890123456789",
|
|
169
|
+
),
|
|
170
|
+
).toBeNull();
|
|
171
|
+
});
|
|
172
|
+
|
|
125
173
|
test("same chat on same channel reuses the same conversation", () => {
|
|
126
174
|
const r1 = recordInbound("telegram", "chat-1", "msg-1");
|
|
127
175
|
const r2 = recordInbound("telegram", "chat-1", "msg-2");
|
|
@@ -2051,3 +2051,66 @@ describe("FireworksProvider reasoning_effort ceiling", () => {
|
|
|
2051
2051
|
expect(lastCreateParams!.reasoning_effort).toBe("max");
|
|
2052
2052
|
});
|
|
2053
2053
|
});
|
|
2054
|
+
|
|
2055
|
+
// GLM 5.3 accepts only low|high|max and 4xxes on the in-between tiers, so
|
|
2056
|
+
// the catalog's `supportedEfforts` snaps them down (see
|
|
2057
|
+
// snapReasoningEffortToSupported).
|
|
2058
|
+
describe("FireworksProvider sparse reasoning_effort support (GLM 5.3)", () => {
|
|
2059
|
+
beforeEach(() => {
|
|
2060
|
+
fakeChunks = [];
|
|
2061
|
+
lastCreateParams = null;
|
|
2062
|
+
});
|
|
2063
|
+
|
|
2064
|
+
const send = async (
|
|
2065
|
+
model: string,
|
|
2066
|
+
effort: "none" | "low" | "medium" | "high" | "xhigh" | "max",
|
|
2067
|
+
) => {
|
|
2068
|
+
const fw = new FireworksProvider("fw-key", model);
|
|
2069
|
+
await fw.sendMessage([userMsg("hi")], {
|
|
2070
|
+
systemPrompt: "system",
|
|
2071
|
+
config: { effort },
|
|
2072
|
+
});
|
|
2073
|
+
return lastCreateParams!.reasoning_effort;
|
|
2074
|
+
};
|
|
2075
|
+
|
|
2076
|
+
test('GLM 5.3 snaps "medium" down to "low"', async () => {
|
|
2077
|
+
expect(await send("accounts/fireworks/models/glm-5p3", "medium")).toBe(
|
|
2078
|
+
"low",
|
|
2079
|
+
);
|
|
2080
|
+
});
|
|
2081
|
+
|
|
2082
|
+
test('GLM 5.3 snaps "xhigh" down to "high"', async () => {
|
|
2083
|
+
expect(await send("accounts/fireworks/models/glm-5p3", "xhigh")).toBe(
|
|
2084
|
+
"high",
|
|
2085
|
+
);
|
|
2086
|
+
});
|
|
2087
|
+
|
|
2088
|
+
test("GLM 5.3 forwards supported values verbatim", async () => {
|
|
2089
|
+
expect(await send("accounts/fireworks/models/glm-5p3", "low")).toBe("low");
|
|
2090
|
+
expect(await send("accounts/fireworks/models/glm-5p3", "high")).toBe(
|
|
2091
|
+
"high",
|
|
2092
|
+
);
|
|
2093
|
+
expect(await send("accounts/fireworks/models/glm-5p3", "max")).toBe("max");
|
|
2094
|
+
});
|
|
2095
|
+
|
|
2096
|
+
test('GLM 5.3 Flash snaps "medium"/"xhigh" the same way', async () => {
|
|
2097
|
+
expect(
|
|
2098
|
+
await send("accounts/fireworks/models/glm-5p3-flash", "medium"),
|
|
2099
|
+
).toBe("low");
|
|
2100
|
+
expect(await send("accounts/fireworks/models/glm-5p3-flash", "xhigh")).toBe(
|
|
2101
|
+
"high",
|
|
2102
|
+
);
|
|
2103
|
+
});
|
|
2104
|
+
|
|
2105
|
+
test('effort: "none" is not snapped (opt-out keeps its own handling)', async () => {
|
|
2106
|
+
expect(await send("accounts/fireworks/models/glm-5p3", "none")).toBe(
|
|
2107
|
+
"none",
|
|
2108
|
+
);
|
|
2109
|
+
});
|
|
2110
|
+
|
|
2111
|
+
test("models without supportedEfforts are unaffected", async () => {
|
|
2112
|
+
expect(
|
|
2113
|
+
await send("accounts/fireworks/models/deepseek-v4-pro", "medium"),
|
|
2114
|
+
).toBe("medium");
|
|
2115
|
+
});
|
|
2116
|
+
});
|
|
@@ -185,7 +185,7 @@ import { setConfig } from "./helpers/set-config.js";
|
|
|
185
185
|
function makeDeps(
|
|
186
186
|
conversationId: string,
|
|
187
187
|
overrides: {
|
|
188
|
-
assistantMessageChannel?: "slack" | "vellum" | "telegram";
|
|
188
|
+
assistantMessageChannel?: "slack" | "vellum" | "telegram" | "discord";
|
|
189
189
|
requesterChatId?: string;
|
|
190
190
|
requesterTimezoneLabel?: string;
|
|
191
191
|
clientTimezone?: string;
|
|
@@ -518,7 +518,97 @@ describe("outbound assistant Slack metadata persistence", () => {
|
|
|
518
518
|
|
|
519
519
|
const persisted = lastAssistantPersisted();
|
|
520
520
|
expect(persisted.metadata).toBeDefined();
|
|
521
|
-
// Non-Slack channels must leave the existing metadata shape untouched
|
|
521
|
+
// Non-Slack channels must leave the existing metadata shape untouched,
|
|
522
|
+
// and a vellum turn is not a provider message, so it gets no neutral
|
|
523
|
+
// envelope either.
|
|
522
524
|
expect(persisted.metadata?.slackMeta).toBeUndefined();
|
|
525
|
+
expect(persisted.metadata?.providerMeta).toBeUndefined();
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
test("stamps a partial neutral envelope on non-Slack channel replies", async () => {
|
|
529
|
+
const conversationId = "conv-discord-stamp";
|
|
530
|
+
const deps = makeDeps(conversationId, {
|
|
531
|
+
assistantMessageChannel: "discord",
|
|
532
|
+
requesterChatId: "9990001112223334445",
|
|
533
|
+
});
|
|
534
|
+
await handleLlmCallStarted(state, deps);
|
|
535
|
+
await handleMessageComplete(
|
|
536
|
+
state,
|
|
537
|
+
deps,
|
|
538
|
+
makeMessageCompleteEvent("discord reply"),
|
|
539
|
+
);
|
|
540
|
+
|
|
541
|
+
const persisted = lastAssistantPersisted();
|
|
542
|
+
const providerMetaRaw = persisted.metadata?.providerMeta;
|
|
543
|
+
expect(typeof providerMetaRaw).toBe("string");
|
|
544
|
+
const providerMeta = JSON.parse(providerMetaRaw as string) as Record<
|
|
545
|
+
string,
|
|
546
|
+
unknown
|
|
547
|
+
>;
|
|
548
|
+
expect(providerMeta.source).toBe("discord");
|
|
549
|
+
expect(providerMeta.conversationExternalId).toBe("9990001112223334445");
|
|
550
|
+
expect(providerMeta.eventKind).toBe("message");
|
|
551
|
+
// Persistence runs BEFORE the transport posts the message, so the
|
|
552
|
+
// provider-assigned id is not yet known; the post-send reconciliation in
|
|
553
|
+
// `deliverReplyViaCallback` fills `messageId` once the transport returns
|
|
554
|
+
// it. `threadId` is never stamped: a value there asserts a thread exists.
|
|
555
|
+
expect(providerMeta.messageId).toBeUndefined();
|
|
556
|
+
expect(providerMeta.threadId).toBeUndefined();
|
|
557
|
+
expect(persisted.metadata?.slackMeta).toBeUndefined();
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
test("post-send reconciliation patches messageId into the neutral envelope", async () => {
|
|
561
|
+
const conversationId = "conv-discord-reconcile";
|
|
562
|
+
const chatId = "9990001112223334445";
|
|
563
|
+
const deps = makeDeps(conversationId, {
|
|
564
|
+
assistantMessageChannel: "discord",
|
|
565
|
+
requesterChatId: chatId,
|
|
566
|
+
});
|
|
567
|
+
await handleLlmCallStarted(state, deps);
|
|
568
|
+
await handleMessageComplete(
|
|
569
|
+
state,
|
|
570
|
+
deps,
|
|
571
|
+
makeMessageCompleteEvent("discord reconciliation reply"),
|
|
572
|
+
);
|
|
573
|
+
|
|
574
|
+
const persisted = lastAssistantPersisted();
|
|
575
|
+
nextDeliveryTs = "1234567890123456789";
|
|
576
|
+
await deliverReplyViaCallback(
|
|
577
|
+
conversationId,
|
|
578
|
+
chatId,
|
|
579
|
+
"http://gateway/deliver/discord",
|
|
580
|
+
"assistant-1",
|
|
581
|
+
{ messageId: persisted.id },
|
|
582
|
+
);
|
|
583
|
+
|
|
584
|
+
const row = persistedRows.find(
|
|
585
|
+
(candidate) => candidate.id === persisted.id,
|
|
586
|
+
);
|
|
587
|
+
expect(typeof row?.metadata).toBe("string");
|
|
588
|
+
const envelope = JSON.parse(row!.metadata!) as Record<string, unknown>;
|
|
589
|
+
const reconciled = JSON.parse(envelope.providerMeta as string) as Record<
|
|
590
|
+
string,
|
|
591
|
+
unknown
|
|
592
|
+
>;
|
|
593
|
+
expect(reconciled.messageId).toBe("1234567890123456789");
|
|
594
|
+
expect(reconciled.source).toBe("discord");
|
|
595
|
+
expect(reconciled.conversationExternalId).toBe(chatId);
|
|
596
|
+
|
|
597
|
+
// A second delivery report must not overwrite the reconciled id.
|
|
598
|
+
nextDeliveryTs = "8888888888888888888";
|
|
599
|
+
await deliverReplyViaCallback(
|
|
600
|
+
conversationId,
|
|
601
|
+
chatId,
|
|
602
|
+
"http://gateway/deliver/discord",
|
|
603
|
+
"assistant-1",
|
|
604
|
+
{ messageId: persisted.id },
|
|
605
|
+
);
|
|
606
|
+
const rowAfter = persistedRows.find(
|
|
607
|
+
(candidate) => candidate.id === persisted.id,
|
|
608
|
+
);
|
|
609
|
+
const metaAfter = JSON.parse(
|
|
610
|
+
JSON.parse(rowAfter!.metadata!).providerMeta as string,
|
|
611
|
+
) as Record<string, unknown>;
|
|
612
|
+
expect(metaAfter.messageId).toBe("1234567890123456789");
|
|
523
613
|
});
|
|
524
614
|
});
|
|
@@ -148,6 +148,73 @@ describe("retry normalization: adaptive-only thinking models", () => {
|
|
|
148
148
|
expect(lastConfig()?.thinking).toEqual({ type: "adaptive" });
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
+
test("preserves effort when dropping stale disabled thinking for Fireworks GLM 5.3", async () => {
|
|
152
|
+
// GIVEN a profile that kept `thinking: { enabled: false }` after switching
|
|
153
|
+
// to an always-on GLM 5.3 model, plus an explicit effort
|
|
154
|
+
setLlmConfig({
|
|
155
|
+
callSites: {
|
|
156
|
+
memoryExtraction: {
|
|
157
|
+
provider: "fireworks",
|
|
158
|
+
model: "accounts/fireworks/models/glm-5p3",
|
|
159
|
+
thinking: { enabled: false },
|
|
160
|
+
effort: "high",
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
const { provider, lastConfig } = makePipeline("fireworks");
|
|
165
|
+
|
|
166
|
+
// WHEN a request resolves through the call-site config
|
|
167
|
+
await provider.sendMessage([userMessage], {
|
|
168
|
+
config: { callSite: "memoryExtraction" },
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// THEN the disabled thinking is dropped BEFORE it can be encoded as
|
|
172
|
+
// `effort: "none"` (which GLM 5.3 rejects), and the chosen effort survives
|
|
173
|
+
expect(lastConfig()?.thinking).toBeUndefined();
|
|
174
|
+
expect(lastConfig()?.effort).toBe("high");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("does not generate the opt-out effort for GLM 5.3 Flash with disabled thinking", async () => {
|
|
178
|
+
// GIVEN a pass-through caller with the wire-shape disabled config and no
|
|
179
|
+
// explicit effort
|
|
180
|
+
const { provider, lastConfig } = makePipeline("fireworks");
|
|
181
|
+
|
|
182
|
+
// WHEN sending against the always-on Flash model
|
|
183
|
+
await provider.sendMessage([userMessage], {
|
|
184
|
+
config: {
|
|
185
|
+
model: "accounts/fireworks/models/glm-5p3-flash",
|
|
186
|
+
thinking: { type: "disabled" },
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// THEN no `effort: "none"` is synthesized: the model runs at its own
|
|
191
|
+
// default instead of tripping the reasoning opt-out rejection retry
|
|
192
|
+
expect(lastConfig()?.thinking).toBeUndefined();
|
|
193
|
+
expect(lastConfig()?.effort).toBeUndefined();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("still encodes the opt-out for Fireworks models that support disabling thinking", async () => {
|
|
197
|
+
// GIVEN a disabled thinking config on GLM 5.2, which is not adaptive-only
|
|
198
|
+
setLlmConfig({
|
|
199
|
+
callSites: {
|
|
200
|
+
memoryExtraction: {
|
|
201
|
+
provider: "fireworks",
|
|
202
|
+
model: "accounts/fireworks/models/glm-5p2",
|
|
203
|
+
thinking: { enabled: false },
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
const { provider, lastConfig } = makePipeline("fireworks");
|
|
208
|
+
|
|
209
|
+
// WHEN a request resolves through the call-site config
|
|
210
|
+
await provider.sendMessage([userMessage], {
|
|
211
|
+
config: { callSite: "memoryExtraction" },
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// THEN the opt-out is still encoded through the effort knob
|
|
215
|
+
expect(lastConfig()?.effort).toBe("none");
|
|
216
|
+
});
|
|
217
|
+
|
|
151
218
|
test("preserves disabled thinking for models that support disabling it", async () => {
|
|
152
219
|
// GIVEN a call-site config disabling thinking for a non-adaptive-only model
|
|
153
220
|
setLlmConfig({
|
|
@@ -390,14 +390,6 @@
|
|
|
390
390
|
"defaultEnabled": "control",
|
|
391
391
|
"values": ["control", "terra", "glm-5p2"]
|
|
392
392
|
},
|
|
393
|
-
{
|
|
394
|
-
"id": "obscure-credits",
|
|
395
|
-
"scope": "client",
|
|
396
|
-
"key": "obscure-credits",
|
|
397
|
-
"label": "Obscure Credits",
|
|
398
|
-
"description": "Obscures raw credit dollar amounts across the web billing surfaces in favor of a usage-relative view. The Plan section's current-plan tile trades its price footer for a Usage Balance bar and its credits spec chip reads \"<Package> usage, reset monthly\"; the plans takeover, custom-plan modal, and Pro provisioning takeover swap dollar credit wording for the catalog's usage labels; the Credits balance tile and the chat preferences menu show only credit bought or earned beyond the plan's included grants. Chat low-balance and daily-limit banners still name credits. Off leaves every surface exactly as it ships today.",
|
|
399
|
-
"defaultEnabled": false
|
|
400
|
-
},
|
|
401
393
|
{
|
|
402
394
|
"id": "ios-avatar-app-icon",
|
|
403
395
|
"scope": "client",
|
|
@@ -22,6 +22,7 @@ import { getConfig } from "../config/loader.js";
|
|
|
22
22
|
import { recordEstimate } from "../context/estimator-calibration.js";
|
|
23
23
|
import { stripInjectionsForCompaction } from "../context/strip-injections.js";
|
|
24
24
|
import { getCalibrationProviderKey } from "../context/token-estimator.js";
|
|
25
|
+
import type { ProviderMessageMetadata } from "../messaging/provider-message-metadata.js";
|
|
25
26
|
import {
|
|
26
27
|
formatSlackTimezoneLabel,
|
|
27
28
|
isSlackTs,
|
|
@@ -1399,6 +1400,22 @@ function buildAssistantChannelMetadata(
|
|
|
1399
1400
|
partialSlackMeta as SlackMessageMetadata,
|
|
1400
1401
|
);
|
|
1401
1402
|
}
|
|
1403
|
+
} else if (deps.turnChannelContext.assistantMessageChannel !== "vellum") {
|
|
1404
|
+
// Every other channel row describes itself in the neutral envelope
|
|
1405
|
+
// `readProviderMetadata` serves, the shape a plugin channel writes too.
|
|
1406
|
+
// `messageId` stays absent here and is back-filled by the post-send
|
|
1407
|
+
// reconciliation once the transport returns the sent message's id, which
|
|
1408
|
+
// is what lets a later reaction on this row resolve back to it. No
|
|
1409
|
+
// `threadId`: a value there asserts a thread exists, and the reply's
|
|
1410
|
+
// routing thread is delivery state, not a fact about this row.
|
|
1411
|
+
const chatId = turnOrRestingTrust(deps.ctx)?.requesterChatId;
|
|
1412
|
+
if (chatId) {
|
|
1413
|
+
metadata.providerMeta = JSON.stringify({
|
|
1414
|
+
source: deps.turnChannelContext.assistantMessageChannel,
|
|
1415
|
+
conversationExternalId: chatId,
|
|
1416
|
+
eventKind: "message",
|
|
1417
|
+
} satisfies ProviderMessageMetadata);
|
|
1418
|
+
}
|
|
1402
1419
|
}
|
|
1403
1420
|
|
|
1404
1421
|
return metadata;
|
|
@@ -51,12 +51,12 @@ const SLACK_LEGACY_THREAD_EVIDENCE_BATCH_SIZE = 50;
|
|
|
51
51
|
const SLACK_LEGACY_THREAD_EVIDENCE_MAX_SCAN = 500;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* Rows examined when locating a
|
|
54
|
+
* Rows examined when locating a channel message the assistant itself posted.
|
|
55
55
|
* Bounded on purpose: the scan runs on the inbound path while the gateway
|
|
56
56
|
* waits for its ack, and reactions land on recent messages, so a cap costs
|
|
57
57
|
* almost no recall and keeps the cost flat as the database grows.
|
|
58
58
|
*/
|
|
59
|
-
const
|
|
59
|
+
const OUTBOUND_MESSAGE_ID_MAX_SCAN = 400;
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* Channels where an inbound thread id scopes the conversation: a Slack thread
|
|
@@ -295,8 +295,8 @@ export function findInboundEvent(
|
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
/**
|
|
298
|
-
* The conversation holding the message with this provider id, found by
|
|
299
|
-
* the metadata the assistant's own posts carry.
|
|
298
|
+
* The conversation holding the message with this provider id, found by
|
|
299
|
+
* reading the metadata the assistant's own posts carry, on any channel.
|
|
300
300
|
*
|
|
301
301
|
* Reads through `readProviderMetadata`, so it matches any channel that
|
|
302
302
|
* describes its rows in the neutral shape as well as Slack's own envelope.
|
|
@@ -305,16 +305,18 @@ export function findInboundEvent(
|
|
|
305
305
|
* event. It cannot see what the assistant posted, because an outbound reply
|
|
306
306
|
* opens no inbound event, so a reaction on the assistant's own message needs
|
|
307
307
|
* this. The search is confined to conversations already bound to the same
|
|
308
|
-
*
|
|
309
|
-
* rows among them; beyond that it gives
|
|
310
|
-
* annotation, which is the same outcome as never
|
|
308
|
+
* channel address and to the most recent
|
|
309
|
+
* {@link OUTBOUND_MESSAGE_ID_MAX_SCAN} rows among them; beyond that it gives
|
|
310
|
+
* up and the caller drops the annotation, which is the same outcome as never
|
|
311
|
+
* finding it at all.
|
|
311
312
|
*/
|
|
312
|
-
export function
|
|
313
|
+
export function findConversationByProviderMessageId(
|
|
314
|
+
sourceChannel: string,
|
|
313
315
|
externalChatId: string,
|
|
314
|
-
|
|
316
|
+
providerMessageId: string,
|
|
315
317
|
): string | null {
|
|
316
318
|
const db = getDb();
|
|
317
|
-
const keyPrefix = `${CONVERSATION_KEY_SCOPE}
|
|
319
|
+
const keyPrefix = `${CONVERSATION_KEY_SCOPE}:${sourceChannel}:${externalChatId}`;
|
|
318
320
|
const rows = db
|
|
319
321
|
.select({
|
|
320
322
|
conversationId: messages.conversationId,
|
|
@@ -338,14 +340,14 @@ export function findSlackConversationByMessageTs(
|
|
|
338
340
|
),
|
|
339
341
|
)
|
|
340
342
|
.orderBy(desc(messages.createdAt))
|
|
341
|
-
.limit(
|
|
343
|
+
.limit(OUTBOUND_MESSAGE_ID_MAX_SCAN)
|
|
342
344
|
.all();
|
|
343
345
|
|
|
344
346
|
for (const row of rows) {
|
|
345
347
|
const meta = readProviderMetadata(row.metadata, { allowFlatLegacy: true });
|
|
346
348
|
if (
|
|
347
349
|
meta?.conversationExternalId === externalChatId &&
|
|
348
|
-
meta.messageId ===
|
|
350
|
+
meta.messageId === providerMessageId
|
|
349
351
|
) {
|
|
350
352
|
return row.conversationId;
|
|
351
353
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
modelEffortCeilings,
|
|
3
|
+
modelSupportedEfforts,
|
|
4
|
+
} from "../model-catalog.js";
|
|
2
5
|
import { OpenAIChatCompletionsProvider } from "../openai/chat-completions-provider.js";
|
|
3
6
|
|
|
4
7
|
export interface FireworksProviderOptions {
|
|
@@ -10,6 +13,7 @@ export interface FireworksProviderOptions {
|
|
|
10
13
|
const DEFAULT_FIREWORKS_BASE_URL = "https://api.fireworks.ai/inference/v1";
|
|
11
14
|
|
|
12
15
|
const FIREWORKS_MODEL_EFFORT_CEILINGS = modelEffortCeilings("fireworks");
|
|
16
|
+
const FIREWORKS_MODEL_SUPPORTED_EFFORTS = modelSupportedEfforts("fireworks");
|
|
13
17
|
|
|
14
18
|
export class FireworksProvider extends OpenAIChatCompletionsProvider {
|
|
15
19
|
constructor(
|
|
@@ -39,4 +43,8 @@ export class FireworksProvider extends OpenAIChatCompletionsProvider {
|
|
|
39
43
|
): "high" | "xhigh" | "max" {
|
|
40
44
|
return FIREWORKS_MODEL_EFFORT_CEILINGS.get(model) ?? "high";
|
|
41
45
|
}
|
|
46
|
+
|
|
47
|
+
protected override resolveSupportedReasoningEfforts(model: string) {
|
|
48
|
+
return FIREWORKS_MODEL_SUPPORTED_EFFORTS.get(model);
|
|
49
|
+
}
|
|
42
50
|
}
|
|
@@ -83,6 +83,16 @@ export interface CatalogModel {
|
|
|
83
83
|
* default.
|
|
84
84
|
*/
|
|
85
85
|
maxEffort?: "high" | "xhigh" | "max";
|
|
86
|
+
/**
|
|
87
|
+
* Wire `reasoning_effort` values this model's upstream accepts, for models
|
|
88
|
+
* whose accepted set is sparse rather than a contiguous range under
|
|
89
|
+
* `maxEffort` (e.g. GLM 5.3 accepts only low/high/max). After the
|
|
90
|
+
* `maxEffort` ceiling clamp, provider clients snap an unsupported value
|
|
91
|
+
* down to the nearest listed value ("none" is exempt: it is the explicit
|
|
92
|
+
* opt-out and keeps its own rejection handling). Daemon-only: not
|
|
93
|
+
* projected into the client catalog (see scripts/sync-llm-catalog.ts).
|
|
94
|
+
*/
|
|
95
|
+
supportedEfforts?: readonly ("low" | "medium" | "high" | "xhigh" | "max")[];
|
|
86
96
|
/**
|
|
87
97
|
* Daemon-only: when true, the direct-OpenAI Responses transport sends
|
|
88
98
|
* explicit prompt-cache breakpoints for this model (GPT-5.6+ semantics:
|
|
@@ -917,6 +927,45 @@ const RAW_PROVIDER_CATALOG: ProviderCatalogEntry[] = [
|
|
|
917
927
|
cacheReadPer1mTokens: 0.26,
|
|
918
928
|
},
|
|
919
929
|
},
|
|
930
|
+
{
|
|
931
|
+
id: "accounts/fireworks/models/glm-5p3",
|
|
932
|
+
displayName: "GLM 5.3",
|
|
933
|
+
contextWindowTokens: 1040000,
|
|
934
|
+
maxOutputTokens: 131072,
|
|
935
|
+
supportsThinking: true,
|
|
936
|
+
// GLM 5.3 reasoning is always on (reasoning_effort low/high/max);
|
|
937
|
+
// it cannot be disabled upstream.
|
|
938
|
+
adaptiveThinkingOnly: true,
|
|
939
|
+
supportsCaching: true,
|
|
940
|
+
supportsVision: false,
|
|
941
|
+
supportsToolUse: true,
|
|
942
|
+
maxEffort: "max",
|
|
943
|
+
supportedEfforts: ["low", "high", "max"],
|
|
944
|
+
pricing: {
|
|
945
|
+
inputPer1mTokens: 1.4,
|
|
946
|
+
outputPer1mTokens: 4.4,
|
|
947
|
+
cacheReadPer1mTokens: 0.26,
|
|
948
|
+
},
|
|
949
|
+
},
|
|
950
|
+
{
|
|
951
|
+
id: "accounts/fireworks/models/glm-5p3-flash",
|
|
952
|
+
displayName: "GLM 5.3 Flash",
|
|
953
|
+
contextWindowTokens: 1040000,
|
|
954
|
+
maxOutputTokens: 131072,
|
|
955
|
+
supportsThinking: true,
|
|
956
|
+
// Same always-on reasoning as GLM 5.3.
|
|
957
|
+
adaptiveThinkingOnly: true,
|
|
958
|
+
supportsCaching: true,
|
|
959
|
+
supportsVision: true,
|
|
960
|
+
supportsToolUse: true,
|
|
961
|
+
maxEffort: "max",
|
|
962
|
+
supportedEfforts: ["low", "high", "max"],
|
|
963
|
+
pricing: {
|
|
964
|
+
inputPer1mTokens: 0.15,
|
|
965
|
+
outputPer1mTokens: 0.5,
|
|
966
|
+
cacheReadPer1mTokens: 0.029,
|
|
967
|
+
},
|
|
968
|
+
},
|
|
920
969
|
// Kimi K2.5 (accounts/fireworks/models/kimi-k2p5) is intentionally
|
|
921
970
|
// absent: Fireworks serves it on-demand/dedicated only, so serverless
|
|
922
971
|
// chat/completions calls 404 ("not found, inaccessible, and/or not
|
|
@@ -2390,6 +2439,24 @@ export function modelEffortCeilings(
|
|
|
2390
2439
|
);
|
|
2391
2440
|
}
|
|
2392
2441
|
|
|
2442
|
+
/**
|
|
2443
|
+
* Per-model sparse `reasoning_effort` support for a provider, keyed by model
|
|
2444
|
+
* ID (same derivation pattern as {@link modelEffortCeilings}). Models without
|
|
2445
|
+
* `supportedEfforts` are absent and accept any value under their ceiling.
|
|
2446
|
+
*/
|
|
2447
|
+
export function modelSupportedEfforts(
|
|
2448
|
+
providerId: string,
|
|
2449
|
+
): ReadonlyMap<
|
|
2450
|
+
string,
|
|
2451
|
+
readonly ("low" | "medium" | "high" | "xhigh" | "max")[]
|
|
2452
|
+
> {
|
|
2453
|
+
return new Map(
|
|
2454
|
+
PROVIDER_CATALOG.find((p) => p.id === providerId)?.models.flatMap((m) =>
|
|
2455
|
+
m.supportedEfforts ? ([[m.id, m.supportedEfforts]] as const) : [],
|
|
2456
|
+
) ?? [],
|
|
2457
|
+
);
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2393
2460
|
/**
|
|
2394
2461
|
* Return the catalog provider that owns a model ID, if known. When multiple
|
|
2395
2462
|
* providers list the same ID (e.g. OpenRouter and the Vercel AI Gateway share
|
|
@@ -225,6 +225,28 @@ export function clampReasoningEffort(
|
|
|
225
225
|
: value;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
+
/** Snap a wire effort onto a model's sparse accepted set: the nearest
|
|
229
|
+
* supported value at or below it, or the smallest supported value when the
|
|
230
|
+
* request sits below all of them. Models like GLM 5.3 accept only
|
|
231
|
+
* `low|high|max` and 4xx on the in-between tiers instead of rounding, so the
|
|
232
|
+
* client rounds for them. `"none"` is never snapped: it is the explicit
|
|
233
|
+
* opt-out and has its own rejection retry. */
|
|
234
|
+
export function snapReasoningEffortToSupported(
|
|
235
|
+
value: ReasoningEffortWire,
|
|
236
|
+
supported: readonly ReasoningEffortWire[],
|
|
237
|
+
): ReasoningEffortWire {
|
|
238
|
+
if (value === "none" || supported.includes(value)) {
|
|
239
|
+
return value;
|
|
240
|
+
}
|
|
241
|
+
const ranked = [...supported].sort(
|
|
242
|
+
(a, b) => REASONING_EFFORT_RANK[a] - REASONING_EFFORT_RANK[b],
|
|
243
|
+
);
|
|
244
|
+
const atOrBelow = ranked.filter(
|
|
245
|
+
(s) => REASONING_EFFORT_RANK[s] < REASONING_EFFORT_RANK[value],
|
|
246
|
+
);
|
|
247
|
+
return atOrBelow[atOrBelow.length - 1] ?? ranked[0] ?? value;
|
|
248
|
+
}
|
|
249
|
+
|
|
228
250
|
/** Human-readable text from an OpenAI-compatible error, including wrapped
|
|
229
251
|
* upstream detail (OpenRouter `metadata.raw`). Used by the one-shot
|
|
230
252
|
* compatibility retries so a generic SDK wrapper message cannot hide the
|
|
@@ -781,12 +803,16 @@ export class OpenAIChatCompletionsProvider implements Provider {
|
|
|
781
803
|
? EFFORT_TO_REASONING_EFFORT[effort]
|
|
782
804
|
: undefined;
|
|
783
805
|
if (reasoningEffort && typeof nestedReasoningEffort !== "string") {
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
);
|
|
787
|
-
params.reasoning_effort = clampReasoningEffort(
|
|
806
|
+
const effortModel = modelOverride ?? this.model;
|
|
807
|
+
const clamped = clampReasoningEffort(
|
|
788
808
|
reasoningEffort,
|
|
789
|
-
|
|
809
|
+
this.resolveMaxReasoningEffort(effortModel),
|
|
810
|
+
);
|
|
811
|
+
const supported = this.resolveSupportedReasoningEfforts(effortModel);
|
|
812
|
+
params.reasoning_effort = (
|
|
813
|
+
supported
|
|
814
|
+
? snapReasoningEffortToSupported(clamped, supported)
|
|
815
|
+
: clamped
|
|
790
816
|
) as OpenAI.Chat.Completions.ChatCompletionCreateParams["reasoning_effort"];
|
|
791
817
|
}
|
|
792
818
|
|
|
@@ -1352,6 +1378,19 @@ export class OpenAIChatCompletionsProvider implements Provider {
|
|
|
1352
1378
|
return this.maxReasoningEffort;
|
|
1353
1379
|
}
|
|
1354
1380
|
|
|
1381
|
+
/**
|
|
1382
|
+
* Per-model sparse `reasoning_effort` support. Subclasses return the
|
|
1383
|
+
* accepted values for models that 4xx on in-between tiers (e.g. GLM 5.3's
|
|
1384
|
+
* `low|high|max`); the outbound value is snapped onto that set after the
|
|
1385
|
+
* ceiling clamp (see {@link snapReasoningEffortToSupported}). Undefined
|
|
1386
|
+
* means any value under the ceiling is accepted.
|
|
1387
|
+
*/
|
|
1388
|
+
protected resolveSupportedReasoningEfforts(
|
|
1389
|
+
_model: string,
|
|
1390
|
+
): readonly ReasoningEffortWire[] | undefined {
|
|
1391
|
+
return undefined;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1355
1394
|
/** Convert neutral messages + system prompt to OpenAI message format. */
|
|
1356
1395
|
private async toOpenAIMessages(
|
|
1357
1396
|
messages: Message[],
|
package/src/providers/retry.ts
CHANGED
|
@@ -813,17 +813,15 @@ function normalizeSendMessageOptions(
|
|
|
813
813
|
}
|
|
814
814
|
}
|
|
815
815
|
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
//
|
|
824
|
-
//
|
|
825
|
-
// disabled thinking config for these models so they fall back to their
|
|
826
|
-
// always-on adaptive thinking; effort and other params are unaffected.
|
|
816
|
+
// Adaptive-thinking-only models (Claude Fable, Fireworks Kimi K3 / GLM 5.3)
|
|
817
|
+
// always reason and reject an explicit opt-out: Anthropic 400s
|
|
818
|
+
// `thinking: { type: "disabled" }`, and effort-encoding providers 4xx a
|
|
819
|
+
// generated `reasoning_effort: "none"`. Drop a disabled thinking config for
|
|
820
|
+
// these models BEFORE the opt-out is encoded as `effort: "none"` below, so
|
|
821
|
+
// they fall back to their always-on thinking with the user's chosen effort
|
|
822
|
+
// and other params unaffected. Profiles can retain a stale
|
|
823
|
+
// `thinking: { enabled: false }` after switching to such a model, so this
|
|
824
|
+
// state is reachable from the profile editor.
|
|
827
825
|
if (
|
|
828
826
|
typeof nextConfig.model === "string" &&
|
|
829
827
|
isAdaptiveThinkingOnlyModel(nextConfig.model) &&
|
|
@@ -832,6 +830,13 @@ function normalizeSendMessageOptions(
|
|
|
832
830
|
delete nextConfig.thinking;
|
|
833
831
|
}
|
|
834
832
|
|
|
833
|
+
if (
|
|
834
|
+
isThinkingConfigDisabled(nextConfig.thinking) &&
|
|
835
|
+
disabledThinkingForcesEffortNone(providerName, nextConfig.model)
|
|
836
|
+
) {
|
|
837
|
+
nextConfig.effort = "none";
|
|
838
|
+
}
|
|
839
|
+
|
|
835
840
|
// Pre-adaptive Claude models (Haiku 4.5, Opus 4.5, Sonnet 4.5) reject
|
|
836
841
|
// `thinking: { type: "adaptive" }` (Anthropic 400s the request), and Vellum
|
|
837
842
|
// never sends the legacy budget_tokens form. Drop an adaptive thinking
|
package/src/runtime/AGENTS.md
CHANGED
|
@@ -205,10 +205,15 @@ the gateway's Channel Identity Vocabulary, which covers the wire side.
|
|
|
205
205
|
channel belongs here rather than in a sixth key of its own.
|
|
206
206
|
|
|
207
207
|
Every channel except Slack writes it: a reaction row carries the whole
|
|
208
|
-
shape (`inbound-stages/reaction-intercept.ts`),
|
|
208
|
+
shape (`inbound-stages/reaction-intercept.ts`), an edit or a delete
|
|
209
209
|
stamps `editedAt` / `deletedAt` onto whatever the row already said about
|
|
210
210
|
itself through `mergeProviderMessageMetadata`
|
|
211
|
-
(`inbound-stages/edit-intercept.ts`, `inbound-message-handler.ts`)
|
|
211
|
+
(`inbound-stages/edit-intercept.ts`, `inbound-message-handler.ts`), and an
|
|
212
|
+
outbound assistant reply is stamped with a partial envelope at reserve time
|
|
213
|
+
(`buildAssistantChannelMetadata`) whose `messageId` the post-send
|
|
214
|
+
reconciliation in `channel-reply-delivery.ts` back-fills from the
|
|
215
|
+
transport's delivery result, which is what lets a later reaction on the
|
|
216
|
+
assistant's own post resolve back to its row. Slack
|
|
212
217
|
keeps writing `slackMeta`, and `readProviderMetadata` maps that envelope
|
|
213
218
|
onto this shape on read, so the channel-agnostic readers in
|
|
214
219
|
`persistence/delivery-crud.ts` (thread evidence, and finding the
|
|
@@ -3,6 +3,7 @@ import type { MessageAudience } from "@vellumai/gateway-client";
|
|
|
3
3
|
import { stripVellumLinks } from "../daemon/assistant-attachments.js";
|
|
4
4
|
import type { RenderedHistoryContent } from "../daemon/handlers/shared.js";
|
|
5
5
|
import { renderHistoryContent } from "../daemon/handlers/shared.js";
|
|
6
|
+
import { readProviderMessageMetadata } from "../messaging/provider-message-metadata.js";
|
|
6
7
|
import { editChannelMessage } from "../messaging/providers/index.js";
|
|
7
8
|
import { readSlackMetadata } from "../messaging/providers/slack/message-metadata.js";
|
|
8
9
|
import { getAttachmentMetadataForMessage } from "../persistence/attachments-store.js";
|
|
@@ -383,16 +384,17 @@ async function deliverPersistedAssistantMessageViaCallback(
|
|
|
383
384
|
return false;
|
|
384
385
|
}
|
|
385
386
|
|
|
386
|
-
// Compose an `onMessageTs` that reconciles
|
|
387
|
-
//
|
|
388
|
-
// assistant row was written BEFORE the gateway POST
|
|
389
|
-
//
|
|
387
|
+
// Compose an `onMessageTs` that reconciles the persisted assistant row's
|
|
388
|
+
// provider message id once the transport returns the authoritative one.
|
|
389
|
+
// The assistant row was written BEFORE the gateway POST, so its pre-send
|
|
390
|
+
// envelope names no id of its own: a Slack row's partial `slackMeta` is
|
|
390
391
|
// missing `channelTs` and would otherwise be rejected by
|
|
391
392
|
// `readSlackMetadata`, dropping the row out of chronological/thread-tag
|
|
392
|
-
// rendering
|
|
393
|
-
//
|
|
394
|
-
//
|
|
395
|
-
|
|
393
|
+
// rendering, and a neutral-envelope row is missing the `messageId` a later
|
|
394
|
+
// reaction on it resolves by. We only act on the FIRST ts (top-level
|
|
395
|
+
// segment); any subsequent split segments become independent provider
|
|
396
|
+
// messages with their own ids and are not represented as separate DB rows.
|
|
397
|
+
const reconcileOnMessageTs = makeSentMessageIdReconciler(msg.id);
|
|
396
398
|
const callerOnMessageTs = options?.onMessageTs;
|
|
397
399
|
const composedOnMessageTs = (ts: string): void => {
|
|
398
400
|
reconcileOnMessageTs(ts);
|
|
@@ -492,21 +494,23 @@ export async function deliverReplyViaCallback(
|
|
|
492
494
|
|
|
493
495
|
/**
|
|
494
496
|
* Build a one-shot `onMessageTs` handler that reconciles the persisted
|
|
495
|
-
* assistant
|
|
497
|
+
* assistant row's provider message id from the transport's authoritative id:
|
|
498
|
+
* `slackMeta.channelTs` for a Slack row, `providerMeta.messageId` for a row
|
|
499
|
+
* carrying the neutral envelope (Discord today, any transport whose delivery
|
|
500
|
+
* result reports the sent id). The back-filled id is what lets a later
|
|
501
|
+
* reaction on the assistant's own post resolve back to this row.
|
|
496
502
|
*
|
|
497
503
|
* Behavior:
|
|
498
504
|
* - Acts only on the first invocation per delivery (subsequent segments
|
|
499
|
-
* correspond to independent
|
|
500
|
-
* represented as separate DB rows).
|
|
501
|
-
* - No-op when the row was
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
* `readSlackMetadata` (channelTs already present, e.g. from a prior
|
|
505
|
-
* reconciliation).
|
|
505
|
+
* correspond to independent provider messages with their own ids and are
|
|
506
|
+
* not represented as separate DB rows).
|
|
507
|
+
* - No-op when the row was persisted with neither envelope (e.g. vellum
|
|
508
|
+
* outbound), and when the row's id is already present (a prior
|
|
509
|
+
* reconciliation ran, or backfill stamped the field).
|
|
506
510
|
* - Failures are logged and swallowed so a transient DB error cannot break
|
|
507
511
|
* the outbound delivery itself.
|
|
508
512
|
*/
|
|
509
|
-
function
|
|
513
|
+
function makeSentMessageIdReconciler(messageId: string): (ts: string) => void {
|
|
510
514
|
let applied = false;
|
|
511
515
|
return (ts: string): void => {
|
|
512
516
|
if (applied) {
|
|
@@ -519,11 +523,11 @@ function makeChannelTsReconciler(messageId: string): (ts: string) => void {
|
|
|
519
523
|
try {
|
|
520
524
|
// Re-read the row's current metadata so a concurrent edit-propagation
|
|
521
525
|
// write (e.g. `editedAt`) is not clobbered. `updateMessageMetadata`
|
|
522
|
-
// shallow-merges into the top-level envelope, and the
|
|
526
|
+
// shallow-merges into the top-level envelope, and the per-channel
|
|
523
527
|
// sub-object is merged manually below so we can preserve fields on
|
|
524
528
|
// the partial pre-send envelope (`mergeSlackMetadata` would call
|
|
525
529
|
// `readSlackMetadata` which rejects the partial form for lacking
|
|
526
|
-
// channelTs
|
|
530
|
+
// channelTs, exactly the state we are reconciling).
|
|
527
531
|
const row = getMessageById(messageId);
|
|
528
532
|
if (row === null || row.metadata === null) {
|
|
529
533
|
return;
|
|
@@ -537,6 +541,7 @@ function makeChannelTsReconciler(messageId: string): (ts: string) => void {
|
|
|
537
541
|
const slackMetaRaw =
|
|
538
542
|
typeof envelope.slackMeta === "string" ? envelope.slackMeta : null;
|
|
539
543
|
if (slackMetaRaw === null) {
|
|
544
|
+
reconcileProviderMessageId(messageId, envelope, ts);
|
|
540
545
|
return;
|
|
541
546
|
}
|
|
542
547
|
// If the existing slackMeta already parses cleanly via the strict
|
|
@@ -579,3 +584,23 @@ function makeChannelTsReconciler(messageId: string): (ts: string) => void {
|
|
|
579
584
|
}
|
|
580
585
|
};
|
|
581
586
|
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* The neutral-envelope arm of the reconciliation: patch the transport's
|
|
590
|
+
* sent-message id into a row's `providerMeta` when the pre-send stamp left
|
|
591
|
+
* it absent. A row whose envelope already names an id, or carries no valid
|
|
592
|
+
* neutral envelope at all, is left untouched.
|
|
593
|
+
*/
|
|
594
|
+
function reconcileProviderMessageId(
|
|
595
|
+
messageId: string,
|
|
596
|
+
envelope: Record<string, unknown>,
|
|
597
|
+
ts: string,
|
|
598
|
+
): void {
|
|
599
|
+
const providerMeta = readProviderMessageMetadata(envelope.providerMeta);
|
|
600
|
+
if (providerMeta === null || providerMeta.messageId !== undefined) {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
updateMessageMetadata(messageId, {
|
|
604
|
+
providerMeta: JSON.stringify({ ...providerMeta, messageId: ts }),
|
|
605
|
+
});
|
|
606
|
+
}
|
|
@@ -72,6 +72,7 @@ mock.module("../../../contacts/contact-store.js", () => ({
|
|
|
72
72
|
let recordInboundCalls: Array<{ conversationId?: string }> = [];
|
|
73
73
|
let recordedEvent: { eventId: string; conversationId: string } | null = null;
|
|
74
74
|
let outboundTargetConversationId: string | null = null;
|
|
75
|
+
let outboundLookupChannels: string[] = [];
|
|
75
76
|
let storedTarget: { messageId: string; conversationId: string } | null = null;
|
|
76
77
|
mock.module("../../../persistence/delivery-crud.js", () => ({
|
|
77
78
|
recordInbound: (
|
|
@@ -89,7 +90,10 @@ mock.module("../../../persistence/delivery-crud.js", () => ({
|
|
|
89
90
|
};
|
|
90
91
|
},
|
|
91
92
|
findMessageBySourceId: () => storedTarget,
|
|
92
|
-
|
|
93
|
+
findConversationByProviderMessageId: (sourceChannel: string) => {
|
|
94
|
+
outboundLookupChannels.push(sourceChannel);
|
|
95
|
+
return outboundTargetConversationId;
|
|
96
|
+
},
|
|
93
97
|
findInboundEvent: () => recordedEvent,
|
|
94
98
|
clearPayload: () => {},
|
|
95
99
|
linkMessage: () => {},
|
|
@@ -221,6 +225,7 @@ describe("reaction intercept consumes the stamped verdict directly", () => {
|
|
|
221
225
|
recordInboundCalls = [];
|
|
222
226
|
recordedEvent = null;
|
|
223
227
|
outboundTargetConversationId = null;
|
|
228
|
+
outboundLookupChannels = [];
|
|
224
229
|
addMessageCalls = 0;
|
|
225
230
|
guardianReplyCalls = [];
|
|
226
231
|
guardianReplyResponse = undefined;
|
|
@@ -265,8 +270,8 @@ describe("reaction intercept consumes the stamped verdict directly", () => {
|
|
|
265
270
|
expect(recordInboundCalls).toEqual([{ conversationId: "conv-target" }]);
|
|
266
271
|
});
|
|
267
272
|
|
|
268
|
-
test("a reaction on the assistant's own post resolves through
|
|
269
|
-
// Outbound posts open no inbound event, so the
|
|
273
|
+
test("a reaction on the assistant's own post resolves through its stored envelope", async () => {
|
|
274
|
+
// Outbound posts open no inbound event, so the id is only on the row.
|
|
270
275
|
storedTarget = null;
|
|
271
276
|
outboundTargetConversationId = "conv-assistant-post";
|
|
272
277
|
|
|
@@ -282,6 +287,30 @@ describe("reaction intercept consumes the stamped verdict directly", () => {
|
|
|
282
287
|
]);
|
|
283
288
|
expect(addMessageCalls).toBe(1);
|
|
284
289
|
expect(result).toMatchObject({ accepted: true, duplicate: false });
|
|
290
|
+
// The outbound-row lookup is scoped to the reaction's own channel: a
|
|
291
|
+
// Slack reaction never scans another channel's conversations.
|
|
292
|
+
expect(outboundLookupChannels).toEqual(["slack"]);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test("a non-Slack reaction resolves the assistant's post on its own channel", async () => {
|
|
296
|
+
storedTarget = null;
|
|
297
|
+
outboundTargetConversationId = "conv-discord-post";
|
|
298
|
+
|
|
299
|
+
const params = {
|
|
300
|
+
...buildParams({
|
|
301
|
+
rawSenderId: MEMBER_USER_ID,
|
|
302
|
+
trustVerdict: MEMBER_VERDICT,
|
|
303
|
+
}),
|
|
304
|
+
sourceChannel: "discord" as const,
|
|
305
|
+
sourceInterface: undefined,
|
|
306
|
+
};
|
|
307
|
+
const result = await handleReactionIntercept(params);
|
|
308
|
+
|
|
309
|
+
expect(outboundLookupChannels).toEqual(["discord"]);
|
|
310
|
+
expect(recordInboundCalls).toEqual([
|
|
311
|
+
{ conversationId: "conv-discord-post" },
|
|
312
|
+
]);
|
|
313
|
+
expect(result).toMatchObject({ accepted: true, duplicate: false });
|
|
285
314
|
});
|
|
286
315
|
|
|
287
316
|
test("a reaction on a message that is not stored is dropped without minting", async () => {
|
|
@@ -40,9 +40,9 @@ import {
|
|
|
40
40
|
provenanceFromTrustContext,
|
|
41
41
|
} from "../../../persistence/conversation-crud.js";
|
|
42
42
|
import {
|
|
43
|
+
findConversationByProviderMessageId,
|
|
43
44
|
findInboundEvent,
|
|
44
45
|
findMessageBySourceId,
|
|
45
|
-
findSlackConversationByMessageTs,
|
|
46
46
|
linkMessage,
|
|
47
47
|
recordInbound,
|
|
48
48
|
} from "../../../persistence/delivery-crud.js";
|
|
@@ -215,14 +215,16 @@ export async function handleReactionIntercept(
|
|
|
215
215
|
// reaction is dropped rather than given a conversation of its own.
|
|
216
216
|
// Inbound messages carry their provider id on the event that delivered
|
|
217
217
|
// them. The assistant's own posts open no inbound event, so a reaction on
|
|
218
|
-
// one is resolved through the
|
|
218
|
+
// one is resolved through the envelope those rows carry (`slackMeta` on
|
|
219
|
+
// Slack, the neutral `providerMeta` everywhere else).
|
|
219
220
|
const targetConversationId = reactedMessageTs
|
|
220
221
|
? (findMessageBySourceId(
|
|
221
222
|
sourceChannel,
|
|
222
223
|
conversationExternalId,
|
|
223
224
|
reactedMessageTs,
|
|
224
225
|
)?.conversationId ??
|
|
225
|
-
|
|
226
|
+
findConversationByProviderMessageId(
|
|
227
|
+
sourceChannel,
|
|
226
228
|
conversationExternalId,
|
|
227
229
|
reactedMessageTs,
|
|
228
230
|
))
|