Skip to content

An open-source, faster Devin alternative

TypeScript

feat(web): Credentials page + inline credential picker in the agent dialog

Igor Zalutski8f40e966a774
diff --git a/web/src/App.tsx b/web/src/App.tsx
index a00e5d73..ea70e96b 100644
--- a/web/src/App.tsx
+++ b/web/src/App.tsx
@@ -8,6 +8,7 @@ import AppShell from './components/app-shell'
// deps (xterm, in Terminal/LogsPanel) only load on SandboxDetail when opened.
const Dashboard = lazy(() => import('./pages/Dashboard'))
const Agents = lazy(() => import('./pages/Agents'))
+const Credentials = lazy(() => import('./pages/Credentials'))
const Sessions = lazy(() => import('./pages/Sessions'))
const SessionDetail = lazy(() => import('./pages/SessionDetail'))
const Sandboxes = lazy(() => import('./pages/Sandboxes'))
@@ -28,6 +29,7 @@ export default function App() {
<Route index element={<Dashboard />} />
{/* Agent plane */}
<Route path="agents" element={<Agents />} />
+ <Route path="credentials" element={<Credentials />} />
<Route path="sessions" element={<Sessions />} />
<Route path="sessions/:sessionId" element={<SessionDetail />} />
{/* Sandbox plane */}
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index 386f8738..37815d8b 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -33,6 +33,7 @@ export type {
Delivery,
SandboxWebhook,
SandboxWebhookDelivery,
+ Credential,
} from './schemas'
const API_BASE = '/api/dashboard'
@@ -392,6 +393,35 @@ export const updateAgent = (
S.AgentSchema,
)
+// Credentials — reusable model-provider keys (the raw key is write-only). An
+// agent pins one (credential_id); sessions resolve the agent's, else the org
+// default for the provider.
+export const getCredentials = () =>
+ apiFetch('/v3/credentials', {}, S.CredentialListSchema).then((r) => r.data)
+
+export const createCredential = (body: {
+ key: string
+ provider?: string
+ name?: string
+ is_default?: boolean
+}) =>
+ apiFetch(
+ '/v3/credentials',
+ { method: 'POST', body: JSON.stringify(body) },
+ S.CredentialSchema,
+ )
+
+export const deleteCredential = (id: string) =>
+ apiFetch<void>(`/v3/credentials/${id}`, { method: 'DELETE' })
+
+// Set the org default credential for its provider (the one sessions fall back to).
+export const setDefaultCredential = (id: string) =>
+ apiFetch(
+ '/v3/credentials/default',
+ { method: 'PUT', body: JSON.stringify({ credential: id }) },
+ S.CredentialSchema,
+ )
+
// Sessions — the durable runs.
export const getSessions = (status?: string) =>
apiFetch(
@@ -416,7 +446,9 @@ export const createSession = (
body: JSON.stringify(body),
// sessions-api dedups create on the Idempotency-Key header (the edge proxy
// forwards it) so a retried start-session is safe.
- headers: idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : undefined,
+ headers: idempotencyKey
+ ? { 'Idempotency-Key': idempotencyKey }
+ : undefined,
},
z.object({ session: S.SessionSchema, client_token: z.string().optional() }),
).then((r) => r.session)
diff --git a/web/src/api/mock.ts b/web/src/api/mock.ts
index c449abee..15467d3e 100644
--- a/web/src/api/mock.ts
+++ b/web/src/api/mock.ts
@@ -394,6 +394,25 @@ const v3agents = [
},
]
+const v3credentials = [
+ {
+ id: 'cred_anth_1',
+ provider: 'anthropic',
+ name: 'Production',
+ last4: 'a1b2',
+ is_default: true,
+ created_at: at(20),
+ },
+ {
+ id: 'cred_anth_2',
+ provider: 'anthropic',
+ name: 'Staging',
+ last4: 'c3d4',
+ is_default: false,
+ created_at: at(8),
+ },
+]
+
const v3sessions = [
{
id: 'ses_a1b2c3',
@@ -596,6 +615,7 @@ const ROUTES: Array<[RegExp, Handler]> = [
// Durable Agent Sessions (/v3) — lists return the { data: [...] } envelope.
[/^\/v3\/agents\/[^/]+$/, () => v3agents[0]],
[/^\/v3\/agents$/, () => ({ data: v3agents })],
+ [/^\/v3\/credentials$/, () => ({ data: v3credentials })],
[/^\/v3\/sessions\/[^/]+\/events/, () => ({ data: v3events })],
[/^\/v3\/sessions\/[^/]+\/destinations$/, () => ({ data: v3destinations })],
[/^\/v3\/sessions\/[^/]+\/deliveries$/, () => ({ data: v3deliveries })],
diff --git a/web/src/api/schemas.ts b/web/src/api/schemas.ts
index 5067b7f9..9b6ed241 100644
--- a/web/src/api/schemas.ts
+++ b/web/src/api/schemas.ts
@@ -290,6 +290,21 @@ export const AgentListSchema = z.object({
next_cursor: z.string().nullish(),
})
+// Credentials — the reusable model-provider keys an agent/session resolves. The
+// raw key is write-only; the API returns only metadata (last4 for display).
+export const CredentialSchema = z.object({
+ id: z.string(),
+ provider: z.string(),
+ name: z.string().nullish(),
+ last4: z.string().nullable().optional(),
+ is_default: z.boolean().optional(),
+ created_at: z.string(),
+})
+export const CredentialListSchema = z.object({
+ data: z.array(CredentialSchema),
+ next_cursor: z.string().nullish(),
+})
+
export const SessionSchema = z.object({
id: z.string(),
status: z.string(),
@@ -378,6 +393,7 @@ export const DeliverySchema = z.object({
})
export type Agent = z.infer<typeof AgentSchema>
+export type Credential = z.infer<typeof CredentialSchema>
export type Session = z.infer<typeof SessionSchema>
export type SessionEvent = z.infer<typeof SessionEventSchema>
export type Turn = z.infer<typeof TurnSchema>
diff --git a/web/src/components/app-shell.tsx b/web/src/components/app-shell.tsx
index 455e28f6..c0985805 100644
--- a/web/src/components/app-shell.tsx
+++ b/web/src/components/app-shell.tsx
@@ -10,6 +10,7 @@ import {
Package,
Webhook,
KeyRound,
+ KeySquare,
CreditCard,
Settings,
LogOut,
@@ -63,6 +64,12 @@ const NAV: NavGroup[] = [
icon: MessagesSquare,
preview: true,
},
+ {
+ to: '/credentials',
+ label: 'Credentials',
+ icon: KeySquare,
+ preview: true,
+ },
],
},
{
diff --git a/web/src/pages/Agents.tsx b/web/src/pages/Agents.tsx
index ac294698..a662f83e 100644
--- a/web/src/pages/Agents.tsx
+++ b/web/src/pages/Agents.tsx
@@ -2,7 +2,14 @@ import { useState } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { Bot, Plus } from 'lucide-react'
import { notifyError } from '@/lib/errors'
-import { getAgents, createAgent, updateAgent, type Agent } from '@/api/client'
+import {
+ getAgents,
+ createAgent,
+ updateAgent,
+ getCredentials,
+ createCredential,
+ type Agent,
+} from '@/api/client'
import { PageHeader } from '@/components/page-header'
import { Panel } from '@/components/panel'
import { Button } from '@/components/ui/button'
@@ -27,37 +34,100 @@ const MODELS = [
]
const DEFAULT_MODEL = MODELS[0].value
+// Agents run on the "claude" runtime → anthropic credentials. Sentinels for the
+// credential picker's two non-credential choices.
+const CRED_PROVIDER = 'anthropic'
+const NEW_CRED = '__new__'
+const ORG_DEFAULT = '__default__'
+
export default function Agents() {
const queryClient = useQueryClient()
const { data: agents, isLoading } = useQuery({
queryKey: ['agents'],
queryFn: getAgents,
})
+ // Credentials for the picker (so creating an agent doesn't need a fresh key each time).
+ const { data: credentials } = useQuery({
+ queryKey: ['credentials'],
+ queryFn: getCredentials,
+ })
+ const anthropicCreds = (credentials ?? []).filter(
+ (c) => c.provider === CRED_PROVIDER,
+ )
+ const hasDefault = anthropicCreds.some((c) => c.is_default)
const [showCreate, setShowCreate] = useState(false)
const [name, setName] = useState('')
const [prompt, setPrompt] = useState('')
const [model, setModel] = useState(DEFAULT_MODEL)
- const [apiKey, setApiKey] = useState('')
+ // Credential selection: a credential id, NEW_CRED (create inline), or ORG_DEFAULT
+ // (rely on the org default). '' is resolved to a sensible default on dialog open.
+ const [credChoice, setCredChoice] = useState('')
+ const [newCredName, setNewCredName] = useState('')
+ const [newCredKey, setNewCredKey] = useState('')
+
+ // Pick the lowest-friction default each time the dialog opens: the org default
+ // credential if any, else the first existing one, else "new credential".
+ const initialCredChoice = () =>
+ anthropicCreds.find((c) => c.is_default)?.id ??
+ anthropicCreds[0]?.id ??
+ NEW_CRED
const resetForm = () => {
setName('')
setPrompt('')
setModel(DEFAULT_MODEL)
- setApiKey('')
+ setCredChoice('')
+ setNewCredName('')
+ setNewCredKey('')
+ }
+
+ const openCreate = () => {
+ setCredChoice(initialCredChoice())
+ setShowCreate(true)
}
+ // Build options: existing creds + "New credential…" + (when one exists) "Use org default".
+ const credOptions = [
+ ...anthropicCreds.map((c) => ({
+ value: c.id,
+ label: `${c.name || 'Unnamed'}${c.last4 ? ` ·· ${c.last4}` : ''}${
+ c.is_default ? ' (default)' : ''
+ }`,
+ })),
+ { value: NEW_CRED, label: '+ New credential…' },
+ ...(hasDefault ? [{ value: ORG_DEFAULT, label: 'Use org default' }] : []),
+ ]
+
const createMutation = useMutation({
- mutationFn: () =>
- createAgent({
+ mutationFn: async () => {
+ // Resolve the agent's credential without leaving the dialog:
+ // - NEW_CRED → create the credential first, pin the new id.
+ // - ORG_DEFAULT → pin nothing (sessions fall back to the org default).
+ // - else → pin the chosen existing credential.
+ let credentialId: string | undefined
+ if (credChoice === NEW_CRED) {
+ const cred = await createCredential({
+ key: newCredKey.trim(),
+ provider: CRED_PROVIDER,
+ name: newCredName.trim() || undefined,
+ is_default: !hasDefault, // first key becomes the org default
+ })
+ credentialId = cred.id
+ } else if (credChoice && credChoice !== ORG_DEFAULT) {
+ credentialId = credChoice
+ }
+ return createAgent({
name: name.trim(),
prompt: prompt.trim(),
model,
runtime: 'claude',
- key: apiKey.trim() || undefined,
- }),
+ credential_id: credentialId,
+ })
+ },
onSuccess: () => {
void queryClient.invalidateQueries({ queryKey: ['agents'] })
+ void queryClient.invalidateQueries({ queryKey: ['credentials'] })
setShowCreate(false)
resetForm()
},
@@ -142,7 +212,10 @@ export default function Agents() {
},
]
- const canCreate = name.trim().length > 0 && prompt.trim().length > 0
+ const canCreate =
+ name.trim().length > 0 &&
+ prompt.trim().length > 0 &&
+ (credChoice !== NEW_CRED || newCredKey.trim().length > 0)
return (
<div>
@@ -156,7 +229,7 @@ export default function Agents() {
docs: 'https://docs.opencomputer.dev/agent-sessions/agents',
}}
actions={
- <Button onClick={() => setShowCreate(true)}>
+ <Button onClick={openCreate}>
<Plus className="size-4" />
Create agent
</Button>
@@ -176,7 +249,7 @@ export default function Agents() {
title="No agents yet"
description="An agent is the reusable “what” — define it once, then start sessions from it."
action={
- <Button size="sm" onClick={() => setShowCreate(true)}>
+ <Button size="sm" onClick={openCreate}>
<Plus className="size-4" />
Create agent
</Button>
@@ -190,7 +263,7 @@ export default function Agents() {
open={showCreate}
onOpenChange={(open) => {
setShowCreate(open)
- if (!open) setApiKey('') // never leave a model key in state after close
+ if (!open) setNewCredKey('') // never leave a model key in state after close
}}
>
<DialogContent>
@@ -247,18 +320,47 @@ export default function Agents() {
</Field>
</div>
<Field
- label="Anthropic API key"
- htmlFor="agent-key"
- description="Stored write-only. Needed to run sessions unless your org already has a default credential."
+ label="Credential"
+ htmlFor="agent-cred"
+ description={
+ credChoice === ORG_DEFAULT
+ ? 'Sessions use your org default Anthropic credential.'
+ : 'The Anthropic key this agent runs on. Reuse one from Credentials, or add a new one here.'
+ }
>
- <Input
- id="agent-key"
- type="password"
- value={apiKey}
- onChange={(e) => setApiKey(e.target.value)}
- placeholder="sk-ant-…"
+ <Select
+ id="agent-cred"
+ value={credChoice}
+ onValueChange={setCredChoice}
+ options={credOptions}
+ placeholder="Choose a credential"
/>
</Field>
+ {credChoice === NEW_CRED ? (
+ <div className="border-border bg-panel-2 grid grid-cols-1 gap-4 rounded-md border p-3 sm:grid-cols-2">
+ <Field label="Credential name" htmlFor="new-cred-name">
+ <Input
+ id="new-cred-name"
+ value={newCredName}
+ onChange={(e) => setNewCredName(e.target.value)}
+ placeholder="e.g. Production"
+ />
+ </Field>
+ <Field
+ label="Anthropic API key"
+ htmlFor="new-cred-key"
+ description="Stored write-only."
+ >
+ <Input
+ id="new-cred-key"
+ type="password"
+ value={newCredKey}
+ onChange={(e) => setNewCredKey(e.target.value)}
+ placeholder="sk-ant-…"
+ />
+ </Field>
+ </div>
+ ) : null}
<DialogFooter className="mt-2">
<Button
type="button"
diff --git a/web/src/pages/Credentials.tsx b/web/src/pages/Credentials.tsx
new file mode 100644
index 00000000..60ced88b
--- /dev/null
+++ b/web/src/pages/Credentials.tsx
@@ -0,0 +1,309 @@
+import { useState } from 'react'
+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
+import { KeySquare, Plus } from 'lucide-react'
+import { notifyError } from '@/lib/errors'
+import {
+ createCredential,
+ deleteCredential,
+ getCredentials,
+ setDefaultCredential,
+ type Credential,
+} from '@/api/client'
+import { PageHeader } from '@/components/page-header'
+import { Panel } from '@/components/panel'
+import { Button } from '@/components/ui/button'
+import { Badge } from '@/components/ui/badge'
+import { Checkbox } from '@/components/ui/checkbox'
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from '@/components/ui/dialog'
+import { Field, Input, Label, Select } from '@/components/form'
+import { EmptyState } from '@/components/empty-state'
+import { ConfirmDialog } from '@/components/confirm-dialog'
+import { ResourceTable, type Column } from '@/components/resource-table'
+
+// Providers an agent runtime can use. claude → anthropic; openai lands when the
+// codex runtime ships, but a key can be stored ahead of it.
+const PROVIDERS = [
+ { value: 'anthropic', label: 'Anthropic' },
+ { value: 'openai', label: 'OpenAI' },
+]
+const KEY_HINT: Record<string, string> = {
+ anthropic: 'sk-ant-…',
+ openai: 'sk-…',
+}
+
+export default function Credentials() {
+ const queryClient = useQueryClient()
+ const { data: credentials, isLoading } = useQuery({
+ queryKey: ['credentials'],
+ queryFn: getCredentials,
+ })
+
+ const [showCreate, setShowCreate] = useState(false)
+ const [name, setName] = useState('')
+ const [provider, setProvider] = useState('anthropic')
+ const [key, setKey] = useState('')
+ const [makeDefault, setMakeDefault] = useState(true)
+ const [toDelete, setToDelete] = useState<Credential | null>(null)
+
+ const resetForm = () => {
+ setName('')
+ setProvider('anthropic')
+ setKey('')
+ setMakeDefault(true)
+ }
+
+ const createMutation = useMutation({
+ mutationFn: () =>
+ createCredential({
+ key: key.trim(),
+ provider,
+ name: name.trim() || undefined,
+ is_default: makeDefault,
+ }),
+ onSuccess: () => {
+ void queryClient.invalidateQueries({ queryKey: ['credentials'] })
+ setShowCreate(false)
+ resetForm()
+ },
+ onError: (e) => notifyError("Couldn't add the credential.", e),
+ })
+
+ const defaultMutation = useMutation({
+ mutationFn: (id: string) => setDefaultCredential(id),
+ onError: (e) => notifyError("Couldn't set the default.", e),
+ onSettled: () =>
+ queryClient.invalidateQueries({ queryKey: ['credentials'] }),
+ })
+
+ const deleteMutation = useMutation({
+ mutationFn: (id: string) => deleteCredential(id),
+ onError: (e) => notifyError("Couldn't delete the credential.", e),
+ onSettled: () =>
+ queryClient.invalidateQueries({ queryKey: ['credentials'] }),
+ })
+
+ const columns: Column<Credential>[] = [
+ {
+ key: 'name',
+ header: 'Name',
+ cell: (c) => (
+ <span className="flex items-center gap-2">
+ <span className="text-foreground font-medium">
+ {c.name || <span className="text-muted-foreground">Unnamed</span>}
+ </span>
+ {c.is_default ? <Badge variant="secondary">Default</Badge> : null}
+ </span>
+ ),
+ },
+ {
+ key: 'provider',
+ header: 'Provider',
+ cell: (c) => (
+ <span className="text-muted-foreground text-xs capitalize">
+ {c.provider}
+ </span>
+ ),
+ },
+ {
+ key: 'key',
+ header: 'Key',
+ cell: (c) => (
+ <code className="text-muted-foreground font-mono text-xs">
+ {c.last4 ? `··· ${c.last4}` : '—'}
+ </code>
+ ),
+ },
+ {
+ key: 'created',
+ header: 'Created',
+ cell: (c) => (
+ <span className="text-muted-foreground font-mono text-xs">
+ {new Date(c.created_at).toLocaleDateString()}
+ </span>
+ ),
+ },
+ {
+ key: 'actions',
+ header: '',
+ align: 'right',
+ cell: (c) => (
+ <div className="flex items-center justify-end gap-1">
+ {!c.is_default ? (
+ <Button
+ variant="ghost"
+ size="sm"
+ disabled={defaultMutation.isPending}
+ onClick={() => defaultMutation.mutate(c.id)}
+ >
+ Set default
+ </Button>
+ ) : null}
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-status-error underline-offset-2 hover:bg-transparent hover:underline"
+ onClick={() => setToDelete(c)}
+ >
+ Delete
+ </Button>
+ </div>
+ ),
+ },
+ ]
+
+ const canCreate = key.trim().length > 0
+
+ return (
+ <div>
+ <PageHeader
+ title="Credentials"
+ description="Model-provider keys your agents run on. Stored write-only; pick one per agent or set an org default."
+ api={{
+ method: 'POST',
+ path: '/v3/credentials',
+ sdk: 'oc.credentials.create()',
+ docs: 'https://docs.opencomputer.dev/agent-sessions/credentials',
+ }}
+ actions={
+ <Button onClick={() => setShowCreate(true)}>
+ <Plus className="size-4" />
+ Add credential
+ </Button>
+ }
+ />
+
+ <Panel className="overflow-hidden">
+ <ResourceTable
+ columns={columns}
+ rows={credentials ?? []}
+ rowKey={(c) => c.id}
+ loading={isLoading}
+ empty={
+ <EmptyState
+ icon={KeySquare}
+ title="No credentials yet"
+ description="Add a model-provider key once, then reuse it across agents — no need to paste it every time."
+ action={
+ <Button size="sm" onClick={() => setShowCreate(true)}>
+ <Plus className="size-4" />
+ Add credential
+ </Button>
+ }
+ />
+ }
+ />
+ </Panel>
+
+ <Dialog
+ open={showCreate}
+ onOpenChange={(open) => {
+ setShowCreate(open)
+ if (!open) setKey('') // never leave a key in state after close
+ }}
+ >
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Add credential</DialogTitle>
+ <DialogDescription>
+ The key is stored write-only — you won&apos;t be able to read it
+ back, only rotate or delete it.
+ </DialogDescription>
+ </DialogHeader>
+ <form
+ className="space-y-4"
+ onSubmit={(e) => {
+ e.preventDefault()
+ if (canCreate) createMutation.mutate()
+ }}
+ >
+ <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
+ <Field label="Name" htmlFor="cred-name">
+ <Input
+ id="cred-name"
+ value={name}
+ onChange={(e) => setName(e.target.value)}
+ placeholder="e.g. Production"
+ />
+ </Field>
+ <Field label="Provider" htmlFor="cred-provider">
+ <Select
+ id="cred-provider"
+ value={provider}
+ onValueChange={setProvider}
+ options={PROVIDERS}
+ />
+ </Field>
+ </div>
+ <Field label="API key" htmlFor="cred-key">
+ <Input
+ id="cred-key"
+ type="password"
+ value={key}
+ onChange={(e) => setKey(e.target.value)}
+ placeholder={KEY_HINT[provider] ?? 'sk-…'}
+ />
+ </Field>
+ <div className="flex items-center gap-2">
+ <Checkbox
+ id="cred-default"
+ checked={makeDefault}
+ onCheckedChange={(v) => setMakeDefault(v === true)}
+ />
+ <Label
+ htmlFor="cred-default"
+ className="cursor-pointer font-normal"
+ >
+ Set as the org default for {provider}
+ <span className="text-muted-foreground">
+ {' '}
+ — used when an agent doesn&apos;t pin its own.
+ </span>
+ </Label>
+ </div>
+ <DialogFooter className="mt-2">
+ <Button
+ type="button"
+ variant="ghost"
+ onClick={() => {
+ setShowCreate(false)
+ resetForm()
+ }}
+ >
+ Cancel
+ </Button>
+ <Button
+ type="submit"
+ disabled={createMutation.isPending || !canCreate}
+ >
+ {createMutation.isPending ? 'Adding…' : 'Add credential'}
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+
+ <ConfirmDialog
+ open={toDelete !== null}
+ onOpenChange={(open) => !open && setToDelete(null)}
+ title={`Delete ${toDelete?.name ? `"${toDelete.name}"` : 'this credential'}?`}
+ description="Agents pinned to it, and sessions that fall back to it, will stop running until you point them at another credential. This can't be undone."
+ confirmLabel="Delete credential"
+ destructive
+ pending={deleteMutation.isPending}
+ onConfirm={() => {
+ if (!toDelete) return
+ deleteMutation.mutate(toDelete.id, {
+ onSuccess: () => setToDelete(null),
+ })
+ }}
+ />
+ </div>
+ )
+}