Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(agents): show the agent API key as optional (#9454)

Wolf Mermelstein3ad39a1d6504
diff --git a/apps/web/src/features/settings/Agents.test.tsx b/apps/web/src/features/settings/Agents.test.tsx
index 5da5753b5c..ea102ff48c 100644
--- a/apps/web/src/features/settings/Agents.test.tsx
+++ b/apps/web/src/features/settings/Agents.test.tsx
@@ -1290,6 +1290,7 @@ describe('Agents', () => {
fireEvent.input(within(dialog).getByLabelText('Name'), {
target: { value: 'Bug fixer' },
});
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Add key' }));
fireEvent.input(within(dialog).getByLabelText('Anthropic API key'), {
target: { value: 'sk-ant-api03-abc' },
});
@@ -1306,6 +1307,35 @@ describe('Agents', () => {
});
});
+ it('offers an optional API key without asking for one', async () => {
+ render(() => <Agents {...agentsPageProps} />);
+ fireEvent.click(screen.getByRole('button', { name: 'Add agent' }));
+
+ const dialog = screen.getByRole('region', { name: /^(New|Edit) agent$/ });
+ expect(within(dialog).queryByLabelText('Anthropic API key')).toBeNull();
+ expect(
+ within(dialog).getByText('Runs on Macro usage unless you add one.')
+ ).toBeTruthy();
+
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Add key' }));
+ fireEvent.click(
+ within(dialog).getByRole('button', { name: 'Cancel API key' })
+ );
+ expect(within(dialog).queryByLabelText('Anthropic API key')).toBeNull();
+
+ fireEvent.input(within(dialog).getByLabelText('Name'), {
+ target: { value: 'Bug fixer' },
+ });
+ fireEvent.click(
+ within(dialog).getByRole('button', { name: 'Create agent' })
+ );
+ await waitFor(() => {
+ expect(screen.queryByRole('dialog')).toBeNull();
+ });
+ expect(apiKeyMocks.save).not.toHaveBeenCalled();
+ expect(apiKeyMocks.remove).not.toHaveBeenCalled();
+ });
+
it("removes an agent's saved API key, and locks the field on a free plan", async () => {
agentMocks.query.data = [
{
@@ -1374,10 +1404,10 @@ describe('Agents', () => {
fireEvent.click(screen.getByRole('button', { name: 'Edit Bug fixer' }));
const dialog = screen.getByRole('region', { name: /^(New|Edit) agent$/ });
+ expect(within(dialog).queryByLabelText('Anthropic API key')).toBeNull();
expect(
- (within(dialog).getByLabelText('Anthropic API key') as HTMLInputElement)
- .disabled
- ).toBe(true);
+ within(dialog).queryByRole('button', { name: 'Add key' })
+ ).toBeNull();
expect(
within(dialog).getByText(
'Agent API keys are part of the Premium and Max plans.'
diff --git a/apps/web/src/features/settings/Agents.tsx b/apps/web/src/features/settings/Agents.tsx
index 81939a452b..8260fef412 100644
--- a/apps/web/src/features/settings/Agents.tsx
+++ b/apps/web/src/features/settings/Agents.tsx
@@ -942,42 +942,100 @@ function AgentEditorPage(props: {
: 'Agent API keys are part of the Premium and Max plans.';
if (saved && saved.provider !== provider.id)
return `The saved ${apiKeyProviderName(saved.provider)} key isn’t used with this model.`;
- return 'Bill usage to your own API key.';
+ return `Bills this agent’s usage to your ${provider.name} account instead of Macro. Leave it empty to run on Macro.`;
};
+ // Optional, so it stays a one-line offer until asked for or already set.
+ const [apiKeyOpen, setApiKeyOpen] = createSignal(false);
+ const apiKeyShown = () =>
+ apiKeyOpen() || savedApiKey() !== undefined || apiKeyDraft().length > 0;
const apiKeyField = () => (
<Show when={keyProvider()}>
{(provider) => (
- <div class="flex max-w-[420px] flex-col gap-1.5">
- <span class="text-xs font-medium text-ink-muted">
- {provider().name} API key
- </span>
- <div class="flex min-w-0 items-center gap-2">
- <ApiKeyInput
- aria-label={`${provider().name} API key`}
- class="flex-1"
- prefix={provider().prefix}
- saved={savedApiKey()?.provider === provider().id}
- disabled={busy() || apiKeyLocked()}
- value={apiKeyDraft()}
- onValueChange={setApiKeyDraft}
- />
- <Show when={savedApiKey()}>
- <Button
- type="button"
- variant="ghost"
- size="sm"
- disabled={busy()}
- onClick={() => {
- setApiKeyDraft('');
- setRemovingApiKey(true);
- }}
+ <Show
+ when={apiKeyShown()}
+ fallback={
+ <div class="flex max-w-[420px] items-center justify-between gap-3">
+ <div class="min-w-0">
+ <div class="text-xs font-medium text-ink-muted">
+ {provider().name} API key{' '}
+ <span class="whitespace-nowrap font-normal text-ink-extra-muted">
+ · Optional
+ </span>
+ </div>
+ <p class="mt-0.5 text-xs text-ink-extra-muted">
+ {apiKeyLocked()
+ ? apiKeyHelp(provider())
+ : 'Runs on Macro usage unless you add one.'}
+ </p>
+ </div>
+ <Show when={!apiKeyLocked()}>
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ class="shrink-0 text-ink"
+ disabled={busy()}
+ onClick={() => setApiKeyOpen(true)}
+ >
+ Add key
+ </Button>
+ </Show>
+ </div>
+ }
+ >
+ <div class="flex max-w-[420px] flex-col gap-1.5">
+ <span class="text-xs font-medium text-ink-muted">
+ {provider().name} API key{' '}
+ <span class="whitespace-nowrap font-normal text-ink-extra-muted">
+ · Optional
+ </span>
+ </span>
+ <div class="flex min-w-0 items-center gap-2">
+ <ApiKeyInput
+ aria-label={`${provider().name} API key`}
+ class="flex-1"
+ prefix={provider().prefix}
+ saved={savedApiKey()?.provider === provider().id}
+ disabled={busy() || apiKeyLocked()}
+ value={apiKeyDraft()}
+ onValueChange={setApiKeyDraft}
+ />
+ <Show
+ when={savedApiKey()}
+ fallback={
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ aria-label="Cancel API key"
+ disabled={busy()}
+ onClick={() => {
+ setApiKeyDraft('');
+ setApiKeyOpen(false);
+ }}
+ >
+ Cancel
+ </Button>
+ }
>
- Remove
- </Button>
- </Show>
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ disabled={busy()}
+ onClick={() => {
+ setApiKeyDraft('');
+ setApiKeyOpen(true);
+ setRemovingApiKey(true);
+ }}
+ >
+ Remove
+ </Button>
+ </Show>
+ </div>
+ <p class="text-xs text-ink-extra-muted">{apiKeyHelp(provider())}</p>
</div>
- <p class="text-xs text-ink-extra-muted">{apiKeyHelp(provider())}</p>
- </div>
+ </Show>
)}
</Show>
);
diff --git a/docs/agent-guide/settings.md b/docs/agent-guide/settings.md
index 60f33d0401..b84c42e5a9 100644
--- a/docs/agent-guide/settings.md
+++ b/docs/agent-guide/settings.md
@@ -712,6 +712,11 @@ mention picker; select text to open the formatting menu. Saved instructions
retain mention identities using the shared editor's Markdown format and reopen
with their formatting intact. Enter adds a new paragraph; use `Create agent` or
`Save changes` to submit. The form also includes runtime selectors.
+Under `In Macro`, an Anthropic or OpenAI model shows an optional
+`<Provider> API key · Optional` row with `Add key`; the agent runs on Macro
+usage without one. `Add key` reveals the write-only field (`Cancel` hides it
+again); a saved key starts expanded with `Remove`. On plans without agent keys
+the row only explains that keys are part of Premium and Max.
`Advanced` starts collapsed on desktop and mobile, showing only its heading,
summary, and `Show` action, without an empty card beneath it. `Show` reveals the
settings; `Hide` collapses them again and preserves the selected options.