fix: autosave a new agent's first edit and list agents past one page

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-09-24 09:35:17 +02:00
co-authored by Claude Opus 5.5
parent 0d6f2c3bf1
commit 09bc536b78
3 changed files with 21 additions and 9 deletions
@@ -29,7 +29,7 @@
deploymentDrawer: DeployWorkspaceDrawer
deleteConfirmedCallback?: (() => void) | undefined
depth?: number
menuOpen?: boolean
menuOpen: boolean
keyboardSelected?: boolean
}
@@ -41,7 +41,7 @@
deploymentDrawer,
deleteConfirmedCallback = $bindable(),
depth = 0,
menuOpen = $bindable(false),
menuOpen = $bindable(),
keyboardSelected = false
}: Props = $props()
@@ -333,7 +333,7 @@ export function useAgentDraft(opts: AgentDraftOptions): AgentDraftHandle {
loading = false
await sync.maybeRestore()
},
(err) => {
async (err) => {
if (loadedFor !== key) return
// Nothing is written until the first edit: the sync saves only on user input, and
// the first deploy creates the resource at whatever path the form then holds.
@@ -349,6 +349,9 @@ export function useAgentDraft(opts: AgentDraftOptions): AgentDraftHandle {
wsSpecific: false
}
loading = false
// Seeds the draft cell with the empty agent, or its first-write guard swallows the
// first edit.
await sync.maybeRestore()
return
}
// A failed load knows neither the resource's type nor its value, so it refuses:
@@ -379,13 +379,22 @@
agentOwnerCounts = {}
return
}
let rows: ListableResource[]
const rows: ListableResource[] = []
try {
rows = await ResourceService.listResource({
workspace: ws,
resourceType: 'ai_agent',
includeDraftOnly: true
})
// Paged even though search and scoping run over the whole set here: the listing caps a
// page, and only the first carries the draft-only rows, so a short page ends it.
const perPage = 1000
for (let page = 1; ; page++) {
const batch = await ResourceService.listResource({
workspace: ws,
resourceType: 'ai_agent',
includeDraftOnly: true,
page,
perPage
})
rows.push(...batch)
if (batch.length < perPage || gen !== agentsGen) break
}
} catch (e: any) {
if (gen !== agentsGen) return
sendUserToast(`Failed to load agents: ${e?.body ?? e?.message ?? e}`, true)