Skip to content

An open-source, faster Devin alternative

TypeScript

fix(web): match /v3 session-create + serializer shapes; agent key for credential

Igor Zalutskif32bf21e7d83
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index 3584c720..74702289 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -368,6 +368,9 @@ export const createAgent = (body: {
model: string
runtime: string
credential_id?: string
+ // `key` sugar: mints a model credential of the runtime's provider for this
+ // agent (write-only). Without it (and no org default) sessions 422 no_credential.
+ key?: string
}) =>
apiFetch(
'/v3/agents',
@@ -396,7 +399,8 @@ export const getSessions = (status?: string) =>
export const getSession = (id: string) =>
apiFetch(`/v3/sessions/${id}`, {}, S.SessionSchema)
-export const createSession = (body: { agent_id: string; message?: string }) =>
+// /v3 wants { agent: <id>, input } and input is required (the first task).
+export const createSession = (body: { agent: string; input: string }) =>
apiFetch(
'/v3/sessions',
{ method: 'POST', body: JSON.stringify(body) },
diff --git a/web/src/api/mock.ts b/web/src/api/mock.ts
index 0ad38a24..6e7f4d6a 100644
--- a/web/src/api/mock.ts
+++ b/web/src/api/mock.ts
@@ -399,7 +399,7 @@ const v3sessions = [
id: 'ses_a1b2c3',
status: 'running',
agent_id: 'agt_3kf9xz',
- event_seq: 24,
+ head: 24,
created_at: at(0, 1),
last_turn: { state: 'running' },
},
@@ -407,7 +407,7 @@ const v3sessions = [
id: 'ses_d4e5f6',
status: 'awaiting_input',
agent_id: 'agt_3kf9xz',
- event_seq: 12,
+ head: 12,
created_at: at(0, 3),
last_turn: { state: 'ok', yield_reason: 'needs_input' },
},
@@ -415,7 +415,7 @@ const v3sessions = [
id: 'ses_g7h8i9',
status: 'idle',
agent_id: 'agt_7mq2aa',
- event_seq: 41,
+ head: 41,
created_at: at(1, 2),
last_turn: { state: 'ok', yield_reason: 'completed' },
},
@@ -423,7 +423,7 @@ const v3sessions = [
id: 'ses_j1k2l3',
status: 'failed',
agent_id: 'agt_3kf9xz',
- event_seq: 8,
+ head: 8,
created_at: at(2, 5),
last_turn: { state: 'error', yield_reason: 'error' },
},
@@ -431,7 +431,7 @@ const v3sessions = [
id: 'ses_m4n5o6',
status: 'archived',
agent_id: 'agt_7mq2aa',
- event_seq: 60,
+ head: 60,
created_at: at(4, 1),
last_turn: { state: 'ok', yield_reason: 'completed' },
},
@@ -504,7 +504,7 @@ const v3destinations = [
const v3deliveries = [
{
id: 'dlv_1',
- destination_id: 'dst_1',
+ destination: 'dst_1',
event_id: 'evt_5',
event_seq: 5,
status: 'delivered',
@@ -515,7 +515,7 @@ const v3deliveries = [
},
{
id: 'dlv_2',
- destination_id: 'dst_1',
+ destination: 'dst_1',
event_id: 'evt_4',
event_seq: 4,
status: 'failed',
diff --git a/web/src/api/schemas.ts b/web/src/api/schemas.ts
index 8bcbbbe6..8d1c46d4 100644
--- a/web/src/api/schemas.ts
+++ b/web/src/api/schemas.ts
@@ -247,12 +247,12 @@ export const SandboxUsageSchema = z.object({
export const AgentSchema = z.object({
id: z.string(),
name: z.string(),
- prompt_hash: z.string().optional(),
+ prompt_hash: z.string().nullish(),
model: z.string(),
runtime: z.string(),
credential_id: z.string().nullable().optional(),
revision: z.number().optional(),
- limits: record.optional(),
+ limits: record.nullish(),
created_at: z.string(),
})
// /v3 list endpoints wrap rows in { data: [...], next_cursor? }.
@@ -266,11 +266,11 @@ export const SessionSchema = z.object({
status: z.string(),
agent_id: z.string().nullable().optional(),
credential_id: z.string().nullable().optional(),
- event_seq: z.number().optional(),
- last_turn: record.nullable().optional(),
- usage: record.optional(),
- limits: record.optional(),
- metadata: record.optional(),
+ head: z.number().optional(), // current event seq (the API calls it `head`)
+ last_turn: record.nullish(),
+ usage: record.nullish(),
+ limits: record.nullish(),
+ metadata: record.nullish(),
created_at: z.string(),
})
export const SessionListSchema = z.object({
@@ -291,8 +291,8 @@ export const SessionEventSchema = z.object({
level: z.string(),
actor: ActorSchema.optional(),
body: z.unknown().optional(),
- body_ref: z.string().nullable().optional(),
- refs: record.optional(),
+ content_ref: z.string().nullish(), // set when body spilled to blob storage
+ refs: record.nullish(),
source: z.string().optional(),
turn_id: z.string().nullable().optional(),
ts: z.string().optional(),
@@ -318,7 +318,7 @@ export const DestinationSchema = z.object({
id: z.string(),
url: z.string(),
level: z.string().optional(),
- types: z.array(z.string()).optional(),
+ types: z.array(z.string()).nullish(),
include_raw: z.boolean().optional(),
enabled: z.boolean(),
has_secret: z.boolean().optional(),
@@ -329,7 +329,7 @@ export const DestinationSchema = z.object({
export const DeliverySchema = z.object({
id: z.string(),
- destination_id: z.string(),
+ destination: z.string().optional(), // the API field is `destination`, not `destination_id`
event_id: z.string().optional(),
event_seq: z.number().optional(),
status: z.string(),
diff --git a/web/src/pages/Agents.tsx b/web/src/pages/Agents.tsx
index 1cd45d3f..5615b02a 100644
--- a/web/src/pages/Agents.tsx
+++ b/web/src/pages/Agents.tsx
@@ -32,11 +32,13 @@ export default function Agents() {
const [name, setName] = useState('')
const [prompt, setPrompt] = useState('')
const [model, setModel] = useState(DEFAULT_MODEL)
+ const [apiKey, setApiKey] = useState('')
const resetForm = () => {
setName('')
setPrompt('')
setModel(DEFAULT_MODEL)
+ setApiKey('')
}
const createMutation = useMutation({
@@ -46,6 +48,7 @@ export default function Agents() {
prompt: prompt.trim(),
model,
runtime: 'claude',
+ key: apiKey.trim() || undefined,
}),
onSuccess: () => {
void queryClient.invalidateQueries({ queryKey: ['agents'] })
@@ -192,6 +195,19 @@ export default function Agents() {
<Input id="agent-runtime" value="Claude" disabled />
</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."
+ >
+ <Input
+ id="agent-key"
+ type="password"
+ value={apiKey}
+ onChange={(e) => setApiKey(e.target.value)}
+ placeholder="sk-ant-…"
+ />
+ </Field>
<DialogFooter className="mt-2">
<Button
type="button"
diff --git a/web/src/pages/SessionDetail.tsx b/web/src/pages/SessionDetail.tsx
index d16d5cd1..27258f35 100644
--- a/web/src/pages/SessionDetail.tsx
+++ b/web/src/pages/SessionDetail.tsx
@@ -133,7 +133,7 @@ export default function SessionDetail() {
<StatusBadge status={status} />
</div>
<p className="text-muted-foreground text-xs">
- {session?.event_seq ?? 0} events · created{' '}
+ {session?.head ?? 0} events · created{' '}
{session?.created_at
? new Date(session.created_at).toLocaleString()
: '—'}
diff --git a/web/src/pages/Sessions.tsx b/web/src/pages/Sessions.tsx
index 009c1c41..8f8d164d 100644
--- a/web/src/pages/Sessions.tsx
+++ b/web/src/pages/Sessions.tsx
@@ -46,11 +46,7 @@ export default function Sessions() {
}
const startMutation = useMutation({
- mutationFn: () =>
- createSession({
- agent_id: agentId,
- message: message.trim() || undefined,
- }),
+ mutationFn: () => createSession({ agent: agentId, input: message.trim() }),
onSuccess: (session) => {
setShowStart(false)
void queryClient.invalidateQueries({ queryKey: ['sessions'] })
@@ -95,7 +91,7 @@ export default function Sessions() {
align: 'right',
cell: (s) => (
<span className="text-muted-foreground font-mono text-xs">
- {s.event_seq ?? 0}
+ {s.head ?? 0}
</span>
),
},
@@ -171,7 +167,7 @@ export default function Sessions() {
className="space-y-4"
onSubmit={(e) => {
e.preventDefault()
- if (agentId) startMutation.mutate()
+ if (agentId && message.trim()) startMutation.mutate()
}}
>
<div className="space-y-1.5">
@@ -190,9 +186,9 @@ export default function Sessions() {
</select>
</div>
<Field
- label="First message"
+ label="First task"
htmlFor="start-message"
- description="Optional — what should the agent do?"
+ description="What should the agent do? (required)"
>
<Textarea
id="start-message"
@@ -212,7 +208,9 @@ export default function Sessions() {
</Button>
<Button
type="submit"
- disabled={startMutation.isPending || !agentId}
+ disabled={
+ startMutation.isPending || !agentId || !message.trim()
+ }
>
{startMutation.isPending ? 'Starting…' : 'Start session'}
</Button>