Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): build the Slack Request URL from the draft, not the saved spec
Jose Ramirezedaf0ad15afa
diff --git a/control-ui/app/communication-channels/[name]/edit/page.tsx b/control-ui/app/communication-channels/[name]/edit/page.tsxindex 90bf9db52..0d4dbedf2 100644--- a/control-ui/app/communication-channels/[name]/edit/page.tsx+++ b/control-ui/app/communication-channels/[name]/edit/page.tsx@@ -27,6 +27,7 @@ import {buildCommunicationChannelSpec,communicationChannelInitialTab,createCommunicationChannelDraft,+ hasSlackConfig,} from '@lib/communicationChannelEdit'import {COMMUNICATION_CHANNEL_PROVIDERS,@@ -36,7 +37,7 @@ import {} from '@lib/communicationChannelProviders'import {type CommunicationChannelItem,- slackWebhookUrlForChannel,+ slackWebhookUrlForChannelName,teamsWebhookUrlForChannel,} from '@lib/communicationChannels'import { canGenerateSlackAppManifest, slackAppManifest } from '@lib/slackAppManifest'@@ -148,11 +149,25 @@ export default function EditCommunicationChannelPage() {const visibleChannelTypes = useMemo<ChannelType[]>(() => [activeTab], [activeTab])const activeConversations = draft ? conversationsForProvider(activeTab, draft) : []- const slackRequestUrl = item ? slackWebhookUrlForChannel(item) : null+ // Gated on the DRAFT, not the persisted item. Slack's own order is manifest+ // first, credentials second: the bot token only exists after the app has been+ // created and installed, so a manifest that needed a saved Slack spec could+ // only ever appear after the operator had already done the step it describes.+ // The URL depends only on namespace/name, both fixed at create time, and the+ // reader resolves that id regardless of slackSettings, so a draft-derived URL+ // is already server-truthful. The guard against a copyable dead end on a+ // non-Slack channel is kept: no Slack config in the draft, no URL.+ const slackRequestUrl =+ draft && hasSlackConfig(draft)+ ? slackWebhookUrlForChannelName(+ item?.metadata?.name?.trim() || name,+ item?.metadata?.namespace+ )+ : nullconst teamsRequestUrl = item ? teamsWebhookUrlForChannel(item) : null// A relative request_url is invalid to Slack, so warn instead of handing over a manifest that- // cannot work. slackWebhookUrlForChannel falls back to a bare path when the deployment has no- // public webhook address.+ // cannot work. slackWebhookUrlForChannelName falls back to a bare path when the deployment has+ // no public webhook address.const slackManifest =slackRequestUrl && canGenerateSlackAppManifest(slackRequestUrl)? slackAppManifest(draft?.slackBotHandle.trim() || DEFAULT_SLACK_APP_NAME, slackRequestUrl)@@ -454,7 +469,7 @@ export default function EditCommunicationChannelPage() {<span className="cu-field__label">Slack Request URL</span><div className="cu-copy-field"><div className="cu-readonly-field cu-copy-field__value">- {slackRequestUrl || 'Unavailable'}+ {slackRequestUrl || 'Available once this channel has a Slack App Name'}</div><buttontype="button"@@ -466,7 +481,9 @@ export default function EditCommunicationChannelPage() {</button></div><span className="cu-field__hint">- Use this URL for Slack Event Subscriptions and Interactivity.+ {slackRequestUrl+ ? 'Use this URL for Slack Event Subscriptions and Interactivity.'+ : 'Enter the Slack App Name above and this channel gets its Request URL and app manifest.'}</span></div>{slackRequestUrl ? (@@ -494,10 +511,11 @@ export default function EditCommunicationChannelPage() {</pre></div><span className="cu-field__hint">- In Slack, Create New App → From an app manifest. It fills in both- Request URLs, on Event Subscriptions and on Interactivity &- Shortcuts. Setting only Event Subscriptions leaves approval buttons dead- with nothing in the logs.+ Paste this into Slack, either at Create New App → From an app manifest+ for a new app, or in an existing app under Settings → App Manifest. It+ fills in both Request URLs, on Event Subscriptions and on Interactivity+ & Shortcuts. Setting only Event Subscriptions leaves approval+ buttons dead with nothing in the logs.</span></div>) : (diff --git a/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx b/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsxindex 6b381c84d..30cb19166 100644--- a/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx+++ b/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx@@ -144,7 +144,10 @@ describe('EditCommunicationChannelPage Slack app manifest', () => {expect(requestUrlLines).toHaveLength(2)expect(new Set(requestUrlLines).size).toBe(1)expect(requestUrlLines[0]).toContain('https://webhook.example.com/webhooks/slack/')- expect(manifest).toContain('name: Evenfire')+ expect(manifest.split('\n').filter(line => /^\s+(name|display_name):/.test(line))).toEqual([+ ' name: "Evenfire"',+ ' display_name: "Evenfire"',+ ])})it('warns instead of emitting a manifest when the Request URL is only a path', async () => {@@ -171,4 +174,56 @@ describe('EditCommunicationChannelPage Slack app manifest', () => {expect(screen.queryByText(/display_information:/)).not.toBeInTheDocument()expect(screen.queryByText(/no public webhook address/)).not.toBeInTheDocument()})++ it('names the cause and the next step instead of a bare Unavailable', async () => {+ // With the URL guard in place this is the DEFAULT state of the Slack tab, so+ // "Unavailable" with no cause, under a hint telling the operator to use a URL+ // that is not there, is the copy most operators will actually see.+ vi.stubEnv('NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL', 'https://webhook.example.com')+ mockChannel('teams-channel', { teamsSettings: { appName: 'evenfire' } })+ await renderLoadedPage()+ fireEvent.click(screen.getByRole('radio', { name: 'Slack' }))++ expect(screen.queryByText('Unavailable')).not.toBeInTheDocument()+ expect(screen.getByText('Available once this channel has a Slack App Name')).toBeInTheDocument()+ expect(+ screen.getByText(+ 'Enter the Slack App Name above and this channel gets its Request URL and app manifest.'+ )+ ).toBeInTheDocument()+ expect(+ screen.queryByText('Use this URL for Slack Event Subscriptions and Interactivity.')+ ).not.toBeInTheDocument()+ })++ it('offers the Request URL and manifest as soon as an App Name is typed, before any save', async () => {+ // Slack's order is manifest first, credentials second: the xoxb token only+ // exists once the app the manifest creates has been installed. Deriving the+ // manifest from the PERSISTED spec made it appear only after the operator had+ // already done, by hand, the step the manifest is for.+ vi.stubEnv('NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL', 'https://webhook.example.com')+ mockChannel('teams-channel', { teamsSettings: { appName: 'evenfire' } })+ await renderLoadedPage()+ fireEvent.click(screen.getByRole('radio', { name: 'Slack' }))++ expect(screen.queryByText('Slack App Manifest')).not.toBeInTheDocument()++ fireEvent.change(screen.getByLabelText(/Slack App Name/), { target: { value: 'Ops Bot' } })++ expect(screen.getByText('Slack App Manifest')).toBeInTheDocument()+ const manifest = screen.getByText(/display_information:/).textContent ?? ''+ const lines = manifest.split('\n')+ expect(lines.filter(line => /^\s+(name|display_name):/.test(line))).toEqual([+ ' name: "Ops Bot"',+ ' display_name: "Ops Bot"',+ ])+ const requestUrlLines = lines.filter(line => line.trim().startsWith('request_url:'))+ expect(requestUrlLines).toHaveLength(2)+ expect(new Set(requestUrlLines).size).toBe(1)+ expect(requestUrlLines[0]).toBe(+ ` request_url: ${screen.getByText(/^https:\/\/webhook\.example\.com\/webhooks\/slack\//).textContent}`+ )+ // Nothing was persisted to get here: no PUT, and the manifest is on screen.+ expect(vi.mocked(api.apiSend)).not.toHaveBeenCalled()+ })})diff --git a/control-ui/lib/__tests__/communicationChannels.test.ts b/control-ui/lib/__tests__/communicationChannels.test.tsindex 1b510eabd..4d1be523a 100644--- a/control-ui/lib/__tests__/communicationChannels.test.ts+++ b/control-ui/lib/__tests__/communicationChannels.test.ts@@ -1,5 +1,12 @@import { describe, expect, it } from 'vitest'-import { slackWebhookUrlForChannel } from '../communicationChannels'+import { slackWebhookUrlForChannel, slackWebhookUrlForChannelName } from '../communicationChannels'++/** The `{namespace, name}` the reader will decode back out of a target id. */+function decodeTargetId(url: string): unknown {+ const targetId = decodeURIComponent(url.slice(url.lastIndexOf('/') + 1))+ const payload = targetId.slice('slack:'.length).replace(/-/g, '+').replace(/_/g, '/')+ return JSON.parse(atob(payload))+}const telegramOnly = {metadata: { name: 'jose-tg', namespace: 'channels' },@@ -28,3 +35,28 @@ describe('slackWebhookUrlForChannel', () => {).toContain('/webhooks/slack/')})})++describe('slackWebhookUrlForChannelName', () => {+ it('encodes the same namespace and name the reader decodes', () => {+ // What makes a draft-derived URL safe to show before anything is saved: the+ // id carries only the channel's coordinates, and both are fixed at create+ // time. If this encoding drifts, the URL an operator pastes into Slack+ // resolves to nothing.+ const url = slackWebhookUrlForChannelName('slack-jose', 'channels')+ expect(url).not.toBeNull()+ expect(decodeTargetId(url!)).toEqual({ namespace: 'channels', name: 'slack-jose' })+ expect(url).toBe(slackWebhookUrlForChannel(slackConfigured))+ })++ it('defaults an absent namespace to channels', () => {+ expect(decodeTargetId(slackWebhookUrlForChannelName('slack-jose')!)).toEqual({+ namespace: 'channels',+ name: 'slack-jose',+ })+ })++ it('returns null without a channel name', () => {+ expect(slackWebhookUrlForChannelName('')).toBeNull()+ expect(slackWebhookUrlForChannelName(' ')).toBeNull()+ })+})diff --git a/control-ui/lib/__tests__/slackAppManifest.test.ts b/control-ui/lib/__tests__/slackAppManifest.test.tsindex 2dca199d5..1fbbaac0d 100644--- a/control-ui/lib/__tests__/slackAppManifest.test.ts+++ b/control-ui/lib/__tests__/slackAppManifest.test.ts@@ -22,6 +22,15 @@ function listItemsUnder(yaml: string, header: string): string[] {return items}+/**+ * The two lines that carry the app name, whole. `toContain('name: Evenfire')` is+ * satisfied by an unquoted scalar, by a suffixed one, and by only one of the two+ * lines being right.+ */+function nameLines(yaml: string): string[] {+ return yaml.split('\n').filter(line => /^\s+(name|display_name):/.test(line))+}+describe('slackAppManifest', () => {const yaml = slackAppManifest('Evenfire', URL)@@ -77,13 +86,37 @@ describe('slackAppManifest', () => {})it('uses the app name given', () => {- expect(yaml).toContain('name: Evenfire')+ expect(nameLines(yaml)).toEqual([' name: "Evenfire"', ' display_name: "Evenfire"'])})it('quotes an app name that would otherwise break the YAML', () => {const quoted = slackAppManifest('Acme: support bot', URL)- expect(quoted).toContain('name: "Acme: support bot"')- expect(quoted).not.toContain('name: Acme: support bot')+ expect(nameLines(quoted)).toEqual([+ ' name: "Acme: support bot"',+ ' display_name: "Acme: support bot"',+ ])+ })++ it('quotes an app name YAML would otherwise read as a boolean or a number', () => {+ // Unquoted, `no` is YAML 1.1 false and `123` is an integer, so Slack receives+ // a manifest whose app name is not a string at all.+ expect(nameLines(slackAppManifest('no', URL))).toEqual([+ ' name: "no"',+ ' display_name: "no"',+ ])+ expect(nameLines(slackAppManifest('123', URL))).toEqual([+ ' name: "123"',+ ' display_name: "123"',+ ])+ })++ it('escapes a newline in the app name instead of emitting a second line', () => {+ // A raw newline inside a quoted scalar would split the value across lines and+ // make the rest of the manifest unparseable.+ expect(nameLines(slackAppManifest('Acme\nBot', URL))).toEqual([+ ' name: "Acme\\nBot"',+ ' display_name: "Acme\\nBot"',+ ])})})diff --git a/control-ui/lib/communicationChannels.ts b/control-ui/lib/communicationChannels.tsindex 09f8c045f..8f46eeb42 100644--- a/control-ui/lib/communicationChannels.ts+++ b/control-ui/lib/communicationChannels.ts@@ -67,17 +67,61 @@ function base64UrlEncode(value: string): string {return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '')}+/**+ * Absolute webhook URL for a reader path, or the bare path when this deployment+ * has no public webhook address (the minikube case).+ */+function webhookUrlForPath(path: string): string {+ const base = process.env.NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL?.replace(/\/+$/, '')+ if (base) return `${base}${path}`+ if (typeof window !== 'undefined' && window.location.hostname.startsWith('app.')) {+ const rootDomain = window.location.hostname.slice('app.'.length)+ return `${window.location.protocol}//webhook.${rootDomain}${path}`+ }+ return path+}++/**+ * The Slack target id depends only on the channel's namespace and name, both+ * fixed when the channel is created, which is why callers may build this from an+ * unsaved edit draft: the reader resolves the id whether or not `slackSettings`+ * has been persisted yet. Deciding WHETHER a channel should show a Slack URL is+ * the caller's job, and it is a real decision — a URL on a channel with no Slack+ * provider is a copyable dead end.+ */+export function slackWebhookTargetIdForChannelName(+ name: string,+ namespace = 'channels'+): string | null {+ const trimmedName = name.trim()+ if (!trimmedName) return null+ return `slack:${base64UrlEncode(JSON.stringify({ namespace: namespace.trim() || 'channels', name: trimmedName }))}`+}++export function slackWebhookPathForChannelName(+ name: string,+ namespace = 'channels'+): string | null {+ const targetId = slackWebhookTargetIdForChannelName(name, namespace)+ return targetId ? `/webhooks/slack/${encodeURIComponent(targetId)}` : null+}++export function slackWebhookUrlForChannelName(name: string, namespace = 'channels'): string | null {+ const path = slackWebhookPathForChannelName(name, namespace)+ return path ? webhookUrlForPath(path) : null+}+export function slackWebhookTargetIdForChannel(item: CommunicationChannelItem): string | null {- const namespace = item.metadata?.namespace?.trim() || 'channels'- const name = item.metadata?.name?.trim()- if (!name) return nullconst spec = item.specconst slackConfigured =(spec?.slack?.length ?? 0) > 0 ||!!spec?.slackSettings?.workspaceId?.trim() ||!!spec?.slackSettings?.botHandle?.trim()if (!slackConfigured) return null- return `slack:${base64UrlEncode(JSON.stringify({ namespace, name }))}`+ return slackWebhookTargetIdForChannelName(+ item.metadata?.name ?? '',+ item.metadata?.namespace ?? 'channels'+ )}export function slackWebhookPathForChannel(item: CommunicationChannelItem): string | null {@@ -87,14 +131,7 @@ export function slackWebhookPathForChannel(item: CommunicationChannelItem): striexport function slackWebhookUrlForChannel(item: CommunicationChannelItem): string | null {const path = slackWebhookPathForChannel(item)- if (!path) return null- const base = process.env.NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL?.replace(/\/+$/, '')- if (base) return `${base}${path}`- if (typeof window !== 'undefined' && window.location.hostname.startsWith('app.')) {- const rootDomain = window.location.hostname.slice('app.'.length)- return `${window.location.protocol}//webhook.${rootDomain}${path}`- }- return path+ return path ? webhookUrlForPath(path) : null}export function teamsWebhookTargetIdForChannel(item: CommunicationChannelItem): string | null {@@ -123,14 +160,7 @@ export function teamsWebhookPathForChannelName(export function teamsWebhookUrlForChannel(item: CommunicationChannelItem): string | null {const path = teamsWebhookPathForChannel(item)- if (!path) return null- const base = process.env.NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL?.replace(/\/+$/, '')- if (base) return `${base}${path}`- if (typeof window !== 'undefined' && window.location.hostname.startsWith('app.')) {- const rootDomain = window.location.hostname.slice('app.'.length)- return `${window.location.protocol}//webhook.${rootDomain}${path}`- }- return path+ return path ? webhookUrlForPath(path) : null}export function teamsWebhookUrlForChannelName(name: string, namespace = 'channels'): string | null {diff --git a/control-ui/lib/slackAppManifest.ts b/control-ui/lib/slackAppManifest.tsindex 57d0c76af..4aa434e3b 100644--- a/control-ui/lib/slackAppManifest.ts+++ b/control-ui/lib/slackAppManifest.ts@@ -21,18 +21,25 @@ const BOT_EVENTS = ['message.mpim',]-/** Plain YAML scalars cannot carry ': ', '#', quotes, or leading punctuation. */-const YAML_PLAIN_SAFE = /^[A-Za-z0-9][A-Za-z0-9 ._-]*$/-+/**+ * A double-quoted YAML scalar, always. Quoting only what looks unsafe leaves the+ * YAML type traps behind: `123`, `no`, `true`, and `null` are all valid app+ * names and all parse as non-strings when written plain. Double quotes also give+ * the only style that carries escapes, which a name with a newline in it needs.+ */function yamlScalar(value: string): string {- const trimmed = value.trim()- if (YAML_PLAIN_SAFE.test(trimmed)) return trimmed- return `"${trimmed.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`+ const escaped = value+ .trim()+ .replace(/\\/g, '\\\\')+ .replace(/"/g, '\\"')+ .replace(/\r/g, '\\r')+ .replace(/\n/g, '\\n')+ return `"${escaped}"`}/**- * Slack rejects a manifest whose `request_url` is relative, and- * `slackWebhookUrlForChannel` falls back to a bare path when the deployment has+ * Slack rejects a manifest whose `request_url` is relative, and the+ * `slackWebhookUrlFor*` helpers fall back to a bare path when the deployment has* no public webhook address (the minikube case). Callers must warn instead of* handing over a manifest Slack cannot accept.*/diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 32c06008e..9bf210451 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.399",+ "version": "0.1.400","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.399",+ "version": "0.1.400","dependencies": {"@clerum/llm-providers": "file:../packages/llm-providers","@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",diff --git a/control-ui/package.json b/control-ui/package.jsonindex a50e7501e..efe1a22e8 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.399",+ "version": "0.1.400","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",