mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-09 22:31:10 +00:00
Fix batch payload shape and deselect-to-one bulk submit
- Send batch documents as {content} objects (matches the endpoint's existing callers) instead of a raw string array.
- Treat bulkUrls as the source of truth: 1 remaining selection saves via single-add instead of erroring.
This commit is contained in:
parent
13bb2732f5
commit
74dbd41e3d
3 changed files with 33 additions and 10 deletions
|
|
@ -188,11 +188,21 @@ export function AddDocument({
|
|||
|
||||
const handleLinkSubmit = useCallback(
|
||||
(data: LinkData) => {
|
||||
if (data.bulkUrls && data.bulkUrls.length >= 2) {
|
||||
bulkLinkMutation.mutate({
|
||||
urls: data.bulkUrls,
|
||||
project: localSelectedProject,
|
||||
})
|
||||
// In bulk mode the selection is the source of truth, not the raw textarea.
|
||||
if (data.bulkUrls) {
|
||||
if (data.bulkUrls.length >= 2) {
|
||||
bulkLinkMutation.mutate({
|
||||
urls: data.bulkUrls,
|
||||
project: localSelectedProject,
|
||||
})
|
||||
return
|
||||
}
|
||||
const [onlyUrl] = data.bulkUrls
|
||||
if (onlyUrl) {
|
||||
linkMutation.mutate({ url: onlyUrl, project: localSelectedProject })
|
||||
return
|
||||
}
|
||||
toast.error("Select at least one link")
|
||||
return
|
||||
}
|
||||
if (!data.url.trim()) {
|
||||
|
|
|
|||
|
|
@ -377,10 +377,12 @@ export function useDocumentMutations({
|
|||
const chunk = urls.slice(i, i + BULK_LINK_BATCH_SIZE)
|
||||
const response = await $fetch("@post/documents/batch", {
|
||||
body: {
|
||||
documents: chunk,
|
||||
containerTag: project,
|
||||
entityContext,
|
||||
metadata: { sm_source: "consumer" },
|
||||
documents: chunk.map((url) => ({
|
||||
content: url,
|
||||
containerTags: [project],
|
||||
entityContext,
|
||||
metadata: { sm_source: "consumer" },
|
||||
})),
|
||||
},
|
||||
})
|
||||
if (response.error) {
|
||||
|
|
|
|||
|
|
@ -193,7 +193,18 @@ export const apiSchema = createSchema({
|
|||
},
|
||||
"@post/documents/batch": {
|
||||
input: z.object({
|
||||
documents: z.array(z.string()).min(1).max(600),
|
||||
documents: z
|
||||
.array(
|
||||
z.object({
|
||||
content: z.string(),
|
||||
containerTags: z.array(z.string()).optional(),
|
||||
containerTag: z.string().optional(),
|
||||
entityContext: z.string().max(1500).optional(),
|
||||
metadata: z.record(z.unknown()).optional(),
|
||||
}),
|
||||
)
|
||||
.min(1)
|
||||
.max(600),
|
||||
containerTag: z.string().optional(),
|
||||
entityContext: z.string().max(1500).optional(),
|
||||
metadata: z.record(z.unknown()).optional(),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue