Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(control-ui): show the Teams setup command on edit and warn when the origin is unknown
Jose Ramirezfc5c4521cd60
diff --git a/control-ui/app/communication-channels/[name]/edit/page.tsx b/control-ui/app/communication-channels/[name]/edit/page.tsxindex 0248423ca..aa660983c 100644--- a/control-ui/app/communication-channels/[name]/edit/page.tsx+++ b/control-ui/app/communication-channels/[name]/edit/page.tsx@@ -42,6 +42,11 @@ import {teamsWebhookUrlForChannelName,} from '@lib/communicationChannels'import { canGenerateSlackAppManifest, slackAppManifest } from '@lib/slackAppManifest'+import {+ LOCAL_TEAMS_ENDPOINT_ORIGIN,+ buildTeamsAppCreateCommand,+ canGenerateTeamsCommand,+} from '@lib/teamsSetup'type ChannelProvider = CommunicationChannelProvidertype DraftState = CommunicationChannelDraftState@@ -245,6 +250,18 @@ export default function EditCommunicationChannelPage() {slackRequestUrl && canGenerateSlackAppManifest(slackRequestUrl)? slackAppManifest(draft?.slackBotHandle.trim() || DEFAULT_SLACK_APP_NAME, slackRequestUrl): null+ // Same reasoning as the Slack manifest above: a relative endpoint would point+ // the Teams CLI at a host that does not exist, so warn instead of handing over+ // a command built from a placeholder. This is also the repair path when a+ // channel is recreated under a new name: retyping the Name field alone is+ // enough to regenerate this command.+ const teamsAppCreateCommand =+ teamsRequestUrl && canGenerateTeamsCommand(teamsRequestUrl)+ ? buildTeamsAppCreateCommand({+ botName: draft?.teamsAppName || '',+ endpoint: teamsRequestUrl,+ })+ : nullasync function persistDraft(nextDraft: DraftState, successMessage: string) {setSaving(true)@@ -329,6 +346,17 @@ export default function EditCommunicationChannelPage() {)}+ async function copyTeamsAppCreateCommand() {+ if (!teamsAppCreateCommand) return+ const copied = await copyTextToClipboard(teamsAppCreateCommand)+ showToast(+ copied+ ? 'Teams bot command copied.'+ : 'Could not copy to clipboard. Select the command and copy it manually.',+ { tone: copied ? 'success' : 'error' }+ )+ }+return (<AuthGate><DashboardLayout isDetailPage>@@ -710,6 +738,46 @@ export default function EditCommunicationChannelPage() {Use this URL as the Messaging endpoint for the Teams bot app.</span></div>+ {teamsRequestUrl ? (+ teamsAppCreateCommand ? (+ <div className="cu-field">+ <span className="cu-field__label">Create the Teams bot</span>+ <div className="cu-command-block">+ <div className="cu-command-block__toolbar">+ <span>Bash</span>+ <Button+ type="button"+ variant="secondary"+ size="sm"+ className="cu-command-block__copy"+ onClick={copyTeamsAppCreateCommand}+ disabled={saving}+ aria-label="Copy Teams bot create command"+ >+ <IconCopy width={15} height={15} />+ Copy+ </Button>+ </div>+ <pre className="cu-command-block__pre">+ <code>{teamsAppCreateCommand}</code>+ </pre>+ </div>+ <span className="cu-field__hint">+ Run this to create or recreate the Teams bot, then paste the generated+ CLIENT_ID, TENANT_ID, and CLIENT_SECRET above. This is also the repair+ path when this channel was recreated under a new name.+ </span>+ </div>+ ) : (+ <div className="cu-banner cu-banner--warning">+ This deployment has no public webhook origin, so the command below cannot+ be generated. Set{' '}+ <code>NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL</code>, or substitute+ your own public origin for <code>{LOCAL_TEAMS_ENDPOINT_ORIGIN}</code>{' '}+ before running it.+ </div>+ )+ ) : null}</>)}<ChannelCredentialsPaneldiff --git a/control-ui/app/communication-channels/new/page.tsx b/control-ui/app/communication-channels/new/page.tsxindex 4b7c132be..3905e9b04 100644--- a/control-ui/app/communication-channels/new/page.tsx+++ b/control-ui/app/communication-channels/new/page.tsx@@ -35,6 +35,11 @@ import {} from '@lib/communicationChannels'import { canGenerateSlackAppManifest, slackAppManifest } from '@lib/slackAppManifest'import { toKebabCase, toKebabInput } from '@lib/string'+import {+ LOCAL_TEAMS_ENDPOINT_ORIGIN,+ buildTeamsAppCreateCommand,+ canGenerateTeamsCommand,+} from '@lib/teamsSetup'type HostItem = {metadata?: { name?: string }@@ -59,7 +64,6 @@ type DraftState = {const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iconst TEAMS_BOT_NAME_RE = /^[a-z][a-z0-9-]{1,62}[a-z0-9]$/-const LOCAL_TEAMS_ENDPOINT_ORIGIN = 'https://<public-webhook-origin>'const STEPS = ['Channel', 'Provider'] as constconst STEP_DETAILS = [@@ -104,22 +108,6 @@ function isValidTeamsBotName(value: string): boolean {return TEAMS_BOT_NAME_RE.test(value.trim())}-function commandEndpointForTeams(webhookUrl: string | null): string {- if (!webhookUrl) return `${LOCAL_TEAMS_ENDPOINT_ORIGIN}/webhooks/teams/<target>`- if (/^https?:\/\//i.test(webhookUrl)) return webhookUrl- return `${LOCAL_TEAMS_ENDPOINT_ORIGIN}${webhookUrl.startsWith('/') ? webhookUrl : `/${webhookUrl}`}`-}--function buildTeamsAppCreateCommand(params: { botName: string; endpoint: string }): string {- const botName = params.botName.trim() || '<bot-name>'- return [- 'teams app create \\',- ` --name "${botName}" \\`,- ` --endpoint "${params.endpoint}" \\`,- ' --env .env',- ].join('\n')-}-function providerSettings(provider: ChannelProvider, draft: DraftState) {if (provider === 'telegram') {return {@@ -217,14 +205,13 @@ export default function CreateCommunicationChannelPage() {: null,[canUseBrowserWebhookOrigin, normalizedChannelName])- const teamsAppCreateCommand = useMemo(- () =>- buildTeamsAppCreateCommand({- botName: draft.teamsAppName,- endpoint: commandEndpointForTeams(teamsWebhookUrl),- }),- [draft.teamsAppName, teamsWebhookUrl]- )+ // A relative endpoint would register a Teams bot pointing at a host that does+ // not exist, so a deployment with no public webhook origin warns instead of+ // handing over a command built from a placeholder.+ const teamsAppCreateCommand = useMemo(() => {+ if (!teamsWebhookUrl || !canGenerateTeamsCommand(teamsWebhookUrl)) return null+ return buildTeamsAppCreateCommand({ botName: draft.teamsAppName, endpoint: teamsWebhookUrl })+ }, [draft.teamsAppName, teamsWebhookUrl])// Slack's order is manifest first, credentials second: the bot token only exists// after the app is installed, so a manifest offered only once the channel is saved// arrives after the step it describes. The Request URL encodes namespace and name@@ -357,6 +344,7 @@ export default function CreateCommunicationChannelPage() {}async function copyTeamsAppCreateCommand() {+ if (!teamsAppCreateCommand) returnconst copied = await copyTextToClipboard(teamsAppCreateCommand)showToast(copied@@ -756,26 +744,36 @@ export default function CreateCommunicationChannelPage() {</li><li>Paste CLIENT_ID, TENANT_ID, and CLIENT_SECRET below.</li></ol>- <div className="cu-command-block">- <div className="cu-command-block__toolbar">- <span>Bash</span>- <Button- type="button"- variant="secondary"- size="sm"- className="cu-command-block__copy"- onClick={copyTeamsAppCreateCommand}- disabled={saving || !teamsBotNameIsValid}- aria-label="Copy Teams bot create command"- >- <IconCopy width={15} height={15} />- Copy- </Button>+ {teamsAppCreateCommand ? (+ <div className="cu-command-block">+ <div className="cu-command-block__toolbar">+ <span>Bash</span>+ <Button+ type="button"+ variant="secondary"+ size="sm"+ className="cu-command-block__copy"+ onClick={copyTeamsAppCreateCommand}+ disabled={saving || !teamsBotNameIsValid}+ aria-label="Copy Teams bot create command"+ >+ <IconCopy width={15} height={15} />+ Copy+ </Button>+ </div>+ <pre className="cu-command-block__pre">+ <code>{teamsAppCreateCommand}</code>+ </pre></div>- <pre className="cu-command-block__pre">- <code>{teamsAppCreateCommand}</code>- </pre>- </div>+ ) : (+ <div className="cu-banner cu-banner--warning">+ This deployment has no public webhook origin, so the command below+ cannot be generated. Set{' '}+ <code>NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL</code>, or+ substitute your own public origin for{' '}+ <code>{LOCAL_TEAMS_ENDPOINT_ORIGIN}</code> before running it.+ </div>+ )}</section><Fielddescription="CLIENT_ID from the generated .env file."diff --git a/control-ui/components/__tests__/CreateCommunicationChannelPage.test.tsx b/control-ui/components/__tests__/CreateCommunicationChannelPage.test.tsxindex 574fad4eb..5fe61fd38 100644--- a/control-ui/components/__tests__/CreateCommunicationChannelPage.test.tsx+++ b/control-ui/components/__tests__/CreateCommunicationChannelPage.test.tsx@@ -190,6 +190,10 @@ describe('CreateCommunicationChannelPage — provider setup', () => {vi.mocked(api.apiSend).mockResolvedValue({})})+ afterEach(() => {+ vi.unstubAllEnvs()+ })+it('shows provider-scoped credentials without route or Email controls', async () => {render(<ToastProvider>@@ -224,6 +228,7 @@ describe('CreateCommunicationChannelPage — provider setup', () => {})it('shows a Teams bot create command using generated .env labels and channel endpoint', async () => {+ vi.stubEnv('NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL', 'https://webhook.example.com')render(<ToastProvider><CreateCommunicationChannelPage />@@ -250,7 +255,7 @@ describe('CreateCommunicationChannelPage — provider setup', () => {const command = screen.getByText(/teams app create/).closest('pre')expect(command).toHaveTextContent('teams app create')expect(command).toHaveTextContent('--name "evenfire-bot"')- expect(command).toHaveTextContent('/webhooks/teams/')+ expect(command).toHaveTextContent('--endpoint "https://webhook.example.com/webhooks/teams/')expect(command).toHaveTextContent('--env .env')expect(screen.getByLabelText(/^CLIENT_ID/)).toBeInTheDocument()expect(screen.getByLabelText(/^TENANT_ID/)).toBeInTheDocument()@@ -258,6 +263,34 @@ describe('CreateCommunicationChannelPage — provider setup', () => {expect(screen.getByRole('button', { name: 'Copy Teams bot create command' })).toBeEnabled()})+ it('warns instead of showing a command when the deployment has no public webhook origin', async () => {+ // No NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL and jsdom's hostname is+ // localhost (not app.*), which is the minikube case. The endpoint the CLI+ // would need is a bare path here, and registering a Teams bot against a bare+ // path points it at a host that does not exist -- warn instead of handing+ // over a command built from a placeholder origin.+ render(+ <ToastProvider>+ <CreateCommunicationChannelPage />+ </ToastProvider>+ )++ await fillStep1AndContinue()+ fireEvent.click(screen.getByRole('radio', { name: 'Microsoft Teams' }))+ fireEvent.change(screen.getByLabelText(/^Name/), {+ target: { value: 'Evenfire Bot!' },+ })++ expect(screen.queryByText(/teams app create/)).not.toBeInTheDocument()+ expect(+ screen.queryByRole('button', { name: 'Copy Teams bot create command' })+ ).not.toBeInTheDocument()+ const panel = document.querySelector('.cu-channel-provider-panel')+ expect(panel?.textContent ?? '').toMatch(+ /NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL|no public webhook origin/i+ )+ })+it('validates Teams CLIENT_ID and TENANT_ID before submission', async () => {render(<ToastProvider>diff --git a/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx b/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsxindex f3cba4880..06229e56c 100644--- a/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx+++ b/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx@@ -562,3 +562,77 @@ describe('EditCommunicationChannelPage Teams request URL', () => {expect(await screen.findByText(/\/webhooks\/teams\/teams%3A/)).toBeInTheDocument()})})++/**+ * The `teams app create` command previously existed only on the create page, so+ * an operator returning to fix or recreate a saved Teams channel had no way back+ * to it -- including the repair path when a channel is recreated under a new+ * name, which only needs the Name field retyped to regenerate a correct command.+ */+describe('EditCommunicationChannelPage Teams setup command', () => {+ it('renders the create command with an absolute endpoint once the webhook origin is public', async () => {+ vi.stubEnv('NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL', 'https://webhook.example.com')+ mockChannel('teams-channel', {+ teamsSettings: { appName: 'evenfire', appId: '', tenantId: '' },+ })+ await renderLoadedPage()++ const user = userEvent.setup()+ await user.click(await screen.findByRole('radio', { name: /microsoft teams/i }))++ expect(screen.getByText('Create the Teams bot')).toBeInTheDocument()+ const command = screen.getByText(/teams app create/).closest('pre')+ expect(command).toHaveTextContent('--name "evenfire"')+ expect(command).toHaveTextContent('--endpoint "https://webhook.example.com/webhooks/teams/')+ expect(command).toHaveTextContent('--env .env')+ expect(screen.getByRole('button', { name: 'Copy Teams bot create command' })).toBeEnabled()+ expect(screen.queryByText(/no public webhook origin/)).not.toBeInTheDocument()++ // Repair path: retyping the Name field, as when a channel is recreated under+ // a new name, regenerates the command with the new name and the same origin.+ await user.clear(screen.getByLabelText(/name/i))+ await user.type(screen.getByLabelText(/name/i), 'evenfire-bot-2')+ const updatedCommand = screen.getByText(/teams app create/).closest('pre')+ expect(updatedCommand).toHaveTextContent('--name "evenfire-bot-2"')+ })++ it('warns instead of showing a command when the deployment has no public webhook origin', async () => {+ // No NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL and jsdom's hostname is+ // localhost, which is the minikube case: the Teams Request URL above renders+ // as a bare path, and registering a bot against that path would point the+ // CLI at a host that does not exist. Warn instead of handing over a command+ // built from a placeholder origin.+ mockChannel('teams-channel', {+ teamsSettings: { appName: 'evenfire', appId: '', tenantId: '' },+ })+ await renderLoadedPage()++ const user = userEvent.setup()+ await user.click(await screen.findByRole('radio', { name: /microsoft teams/i }))++ expect(screen.queryByText('Create the Teams bot')).not.toBeInTheDocument()+ expect(screen.queryByText(/teams app create/)).not.toBeInTheDocument()+ expect(+ screen.queryByRole('button', { name: 'Copy Teams bot create command' })+ ).not.toBeInTheDocument()+ const warning = document.querySelector('.cu-banner--warning')+ expect(warning?.textContent ?? '').toMatch(/no public webhook origin/)+ expect(screen.getByText('NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL')).toBeInTheDocument()+ })++ it('renders neither the command nor the warning until this channel has Teams config', async () => {+ // Mirrors the Slack manifest gate: a URL or a command on a channel with no+ // real Teams provider is a copyable dead end, so both wait for the draft to+ // carry actual Teams config.+ mockChannel('telegram-channel', { telegramSettings: { botHandle: '@ops_bot' } })+ await renderLoadedPage()++ const user = userEvent.setup()+ await user.click(await screen.findByRole('radio', { name: /microsoft teams/i }))++ expect(screen.getByText('Unavailable')).toBeInTheDocument()+ expect(screen.queryByText('Create the Teams bot')).not.toBeInTheDocument()+ expect(screen.queryByText(/teams app create/)).not.toBeInTheDocument()+ expect(screen.queryByText(/no public webhook origin/)).not.toBeInTheDocument()+ })+})diff --git a/control-ui/lib/__tests__/teamsSetup.test.ts b/control-ui/lib/__tests__/teamsSetup.test.tsnew file mode 100644index 000000000..17278121c--- /dev/null+++ b/control-ui/lib/__tests__/teamsSetup.test.ts@@ -0,0 +1,28 @@+import { describe, expect, it } from 'vitest'+import { buildTeamsAppCreateCommand, canGenerateTeamsCommand } from '../teamsSetup'++describe('canGenerateTeamsCommand', () => {+ it('accepts an absolute https URL', () => {+ expect(canGenerateTeamsCommand('https://webhook.dev.example.com/webhooks/teams/x')).toBe(true)+ })++ it('rejects a bare path, which is what a non-app deployment produces', () => {+ expect(canGenerateTeamsCommand('/webhooks/teams/x')).toBe(false)+ })++ it('rejects null', () => {+ expect(canGenerateTeamsCommand(null)).toBe(false)+ })+})++describe('buildTeamsAppCreateCommand', () => {+ it('renders the command with the bot name and endpoint', () => {+ const cmd = buildTeamsAppCreateCommand({+ botName: 'evenfire-bot',+ endpoint: 'https://webhook.dev.example.com/webhooks/teams/x',+ })+ expect(cmd).toContain('--name "evenfire-bot"')+ expect(cmd).toContain('--endpoint "https://webhook.dev.example.com/webhooks/teams/x"')+ expect(cmd).toContain('--env .env')+ })+})diff --git a/control-ui/lib/teamsSetup.ts b/control-ui/lib/teamsSetup.tsnew file mode 100644index 000000000..da222b185--- /dev/null+++ b/control-ui/lib/teamsSetup.ts@@ -0,0 +1,33 @@+/**+ * Placeholder origin shown in guidance copy when the deployment has no public+ * webhook address to substitute. Never used to build a real command: a+ * generated command either carries a real absolute endpoint or is not+ * generated at all.+ */+export const LOCAL_TEAMS_ENDPOINT_ORIGIN = 'https://<public-webhook-origin>'++/**+ * The Teams CLI needs an absolute endpoint. A deployment with no+ * NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL and a hostname that does not+ * start with `app.` produces a bare path, which would register a bot pointing+ * at a host that does not exist. Mirrors canGenerateSlackAppManifest.+ */+export function canGenerateTeamsCommand(endpoint: string | null | undefined): boolean {+ return /^https?:\/\//i.test(endpoint ?? '')+}++/**+ * `teams app create` command that writes the generated CLIENT_ID, TENANT_ID,+ * and CLIENT_SECRET into `.env`. `endpoint` must be absolute; callers gate on+ * canGenerateTeamsCommand and render a warning instead of calling this with a+ * relative path.+ */+export function buildTeamsAppCreateCommand(params: { botName: string; endpoint: string }): string {+ const botName = params.botName.trim() || '<bot-name>'+ return [+ 'teams app create \\',+ ` --name "${botName}" \\`,+ ` --endpoint "${params.endpoint}" \\`,+ ' --env .env',+ ].join('\n')+}diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 9fa4b3bac..0a12528c3 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.415",+ "version": "0.1.416","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.415",+ "version": "0.1.416","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 2bc2f3c7b..1836bdf09 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.415",+ "version": "0.1.416","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",