Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(control-ui): stop the edit page deleting spec.email from a channel

Jose Ramirez0ca528b0edd7
diff --git a/control-ui/lib/__tests__/communicationChannelEdit.test.ts b/control-ui/lib/__tests__/communicationChannelEdit.test.ts
index 4f434691c..531372d05 100644
--- a/control-ui/lib/__tests__/communicationChannelEdit.test.ts
+++ b/control-ui/lib/__tests__/communicationChannelEdit.test.ts
@@ -120,6 +120,7 @@ describe('communication channel edit helpers', () => {
it('omits inactive provider settings from the saved spec', () => {
const spec = buildCommunicationChannelSpec({
accessTeamIds: [],
+ email: [],
accessUserIds: ['user-1'],
hostRef: ' chatllm ',
slack: [],
@@ -155,6 +156,7 @@ describe('communication channel edit helpers', () => {
it('does not save providers that only have default boolean settings', () => {
const spec = buildCommunicationChannelSpec({
accessTeamIds: [],
+ email: [],
accessUserIds: ['user-1'],
hostRef: 'chatllm',
slack: [],
@@ -181,3 +183,64 @@ describe('communication channel edit helpers', () => {
})
})
})
+
+describe('spec fields the edit page does not model', () => {
+ // The edit page has no email controls, but the save is a full-spec PUT and
+ // control-api preserves only credentialsSecretRef. So anything the draft drops
+ // is deleted from the CR. Opening an email-backed channel and saving an
+ // unrelated change used to delete spec.email and stop the inbox being polled,
+ // with no error and nothing in the diff the operator looked at. See #386.
+ const emailGroups = [{ channelId: 'INBOX', emails: ['[email protected]'] }]
+
+ it('round-trips spec.email through the draft untouched', () => {
+ const item: CommunicationChannelItem = channel({
+ spec: {
+ hostRef: 'agent-a',
+ access: { users: [], teams: [] },
+ email: emailGroups,
+ telegram: [{ channelId: '424242', chatType: 'private' }],
+ telegramSettings: { botHandle: '@bot', replyOnlyWhenMentioned: true },
+ },
+ })
+
+ const spec = buildCommunicationChannelSpec(createCommunicationChannelDraft(item))
+
+ expect(spec.email).toEqual(emailGroups)
+ })
+
+ it('does not invent an empty email array on a channel that never had one', () => {
+ // An empty array is not the same as absent: channel-reader guards on
+ // `spec.email?.length`, and writing `email: []` onto every channel is what
+ // put the provider arrays in that state in the first place.
+ const item: CommunicationChannelItem = channel({
+ spec: {
+ hostRef: 'agent-a',
+ access: { users: [], teams: [] },
+ telegram: [{ channelId: '424242', chatType: 'private' }],
+ telegramSettings: { botHandle: '@bot', replyOnlyWhenMentioned: true },
+ },
+ })
+
+ const spec = buildCommunicationChannelSpec(createCommunicationChannelDraft(item))
+
+ expect('email' in spec).toBe(false)
+ })
+
+ it('keeps email when the modelled providers are edited around it', () => {
+ const item: CommunicationChannelItem = channel({
+ spec: {
+ hostRef: 'agent-a',
+ access: { users: [], teams: [] },
+ email: emailGroups,
+ telegram: [{ channelId: '424242', chatType: 'private' }],
+ telegramSettings: { botHandle: '@old', replyOnlyWhenMentioned: true },
+ },
+ })
+
+ const draft = createCommunicationChannelDraft(item)
+ const spec = buildCommunicationChannelSpec({ ...draft, telegramBotHandle: '@new' })
+
+ expect(spec.telegramSettings?.botHandle).toBe('@new')
+ expect(spec.email).toEqual(emailGroups)
+ })
+})
diff --git a/control-ui/lib/communicationChannelEdit.ts b/control-ui/lib/communicationChannelEdit.ts
index 321a355c9..1cde934c0 100644
--- a/control-ui/lib/communicationChannelEdit.ts
+++ b/control-ui/lib/communicationChannelEdit.ts
@@ -5,6 +5,14 @@ export type CommunicationChannelDraftState = {
accessTeamIds: string[]
accessUserIds: string[]
credentialsSecretRef?: { name: string }
+ /**
+ * Carried through untouched. The edit page has no email controls, but the
+ * save is a full-spec PUT and control-api preserves only
+ * `credentialsSecretRef`, so a field the draft drops is deleted from the CR.
+ * Before this was carried, opening an email-backed channel and saving an
+ * unrelated change silently stopped the inbox being polled (#386).
+ */
+ email: CommunicationChannelGroup[]
hostRef: string
slack: CommunicationChannelGroup[]
slackBotHandle: string
@@ -160,6 +168,7 @@ export function createCommunicationChannelDraft(
...(spec.credentialsSecretRef?.name
? { credentialsSecretRef: { name: spec.credentialsSecretRef.name } }
: {}),
+ email: spec.email || [],
hostRef: spec.hostRef || '',
slack: spec.slack || [],
slackBotHandle: slackBotHandleFromSpec || slackBotHandleFromLabel,
@@ -191,12 +200,49 @@ export function communicationChannelInitialTab(
return 'telegram'
}
+/**
+ * Every top-level `spec` field, and how the edit page treats it.
+ *
+ * `edited` means the draft models it and the operator can change it.
+ * `carried` means the page has no controls for it and passes it through
+ * untouched.
+ *
+ * This exists because the save is a full-spec PUT and control-api preserves
+ * only `credentialsSecretRef`, so a field missing from BOTH lists is deleted
+ * from the CR the next time anyone saves, silently. That is what happened to
+ * `email` (#386).
+ *
+ * `satisfies Record<CommunicationChannelSpecField, ...>` is the point: add a
+ * field to the spec type and `tsc --noEmit` fails here until someone decides
+ * which list it belongs in. It cannot catch a CRD field that was never added to
+ * the TypeScript type, but the UI cannot read such a field either.
+ */
+type CommunicationChannelSpecField = keyof NonNullable<CommunicationChannelItem['spec']>
+
+export const COMMUNICATION_CHANNEL_SPEC_FIELD_HANDLING = {
+ access: 'edited',
+ credentialsSecretRef: 'carried',
+ email: 'carried',
+ hostRef: 'edited',
+ slack: 'edited',
+ slackSettings: 'edited',
+ teams: 'edited',
+ teamsSettings: 'edited',
+ telegram: 'edited',
+ telegramSettings: 'edited',
+} satisfies Record<CommunicationChannelSpecField, 'edited' | 'carried'>
+
export function buildCommunicationChannelSpec(draft: CommunicationChannelDraftState) {
const telegramEnabled = hasTelegramConfig(draft)
const slackEnabled = hasSlackConfig(draft)
const teamsEnabled = hasTeamsConfig(draft)
return {
hostRef: draft.hostRef.trim(),
+ // Emitted only when populated. `email: []` is not the same as absent:
+ // channel-reader guards on `spec.email?.length`, and writing empty provider
+ // arrays onto every channel is the defect that made a Teams channel look
+ // like a misconfigured Telegram one.
+ ...(draft.email.length ? { email: draft.email } : {}),
...(draft.credentialsSecretRef?.name
? { credentialsSecretRef: { name: draft.credentialsSecretRef.name } }
: {}),
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 7148e15d0..d3c00d762 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.433",
+ "version": "0.1.434",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.433",
+ "version": "0.1.434",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index 2ac54986b..e66af8377 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.433",
+ "version": "0.1.434",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",