Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions core/http/react-ui/e2e/collections.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,33 @@ test.describe('Collections page', () => {
await input.fill('my-kb')
await expect(input).toHaveValue('my-kb')
})

test('posts the source update interval as a JSON number', async ({ page }) => {
const collectionName = 'interval-regression'
const collectionPath = encodeURIComponent(collectionName)
let postedBody

await page.route(`**/api/agents/collections/${collectionPath}/entries`, route =>
route.fulfill({ contentType: 'application/json', body: JSON.stringify({ entries: [] }) }))
await page.route(`**/api/agents/collections/${collectionPath}/sources`, async route => {
if (route.request().method() === 'POST') {
postedBody = route.request().postDataJSON()
await route.fulfill({ contentType: 'application/json', body: JSON.stringify({ status: 'ok' }) })
} else {
await route.fulfill({ contentType: 'application/json', body: JSON.stringify({ sources: [] }) })
}
})

await page.goto(`/app/collections/${collectionPath}`)
await page.getByRole('button', { name: 'Sources' }).click()
await page.locator('#source-url').fill('https://example.com/feed')
await page.locator('#source-interval').fill('3600')
await page.getByRole('button', { name: 'Add Source' }).click()

await expect.poll(() => postedBody).toEqual({
url: 'https://example.com/feed',
update_interval: 3600,
})
expect(typeof postedBody.update_interval).toBe('number')
})
})
6 changes: 4 additions & 2 deletions core/http/react-ui/src/pages/CollectionDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,12 @@ export default function CollectionDetails() {
<input
id="source-interval"
className="input"
type="text"
type="number"
min="1"
step="1"
value={newSourceInterval}
onChange={(e) => setNewSourceInterval(e.target.value)}
placeholder="e.g. 1h, 30m"
placeholder="e.g. 60 (minutes)"
/>
</div>
<button className="btn btn-primary" type="submit" disabled={!newSourceUrl.trim() || addingSource}>
Expand Down
5 changes: 4 additions & 1 deletion core/http/react-ui/src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,10 @@ export const agentCollectionsApi = {
reset: (name, userId) => postJSON(`/api/agents/collections/${enc(name)}/reset${userQ(userId)}`),
deleteEntry: (name, entry, userId) => fetchJSON(`/api/agents/collections/${enc(name)}/entry/delete${userQ(userId)}`, { method: 'DELETE', body: JSON.stringify({ entry }), headers: { 'Content-Type': 'application/json' } }),
sources: (name, userId) => fetchJSON(`/api/agents/collections/${enc(name)}/sources${userQ(userId)}`),
addSource: (name, url, interval, userId) => postJSON(`/api/agents/collections/${enc(name)}/sources${userQ(userId)}`, { url, update_interval: interval }),
addSource: (name, url, interval, userId) => postJSON(`/api/agents/collections/${enc(name)}/sources${userQ(userId)}`, {
url,
update_interval: interval === undefined ? undefined : Number(interval),
}),
removeSource: (name, url, userId) => fetchJSON(`/api/agents/collections/${enc(name)}/sources${userQ(userId)}`, { method: 'DELETE', body: JSON.stringify({ url }), headers: { 'Content-Type': 'application/json' } }),
}

Expand Down
3 changes: 3 additions & 0 deletions docs/content/features/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ All agent endpoints are grouped under `/api/agents/`:
| `POST` | `/api/agents/collections/:name/upload` | Upload a document |
| `GET` | `/api/agents/collections/:name/entries` | List entries |
| `POST` | `/api/agents/collections/:name/search` | Search a collection |
| `GET` | `/api/agents/collections/:name/sources` | List external sources |
| `POST` | `/api/agents/collections/:name/sources` | Add an external source (`update_interval` is an integer number of minutes; defaults to 60) |
| `DELETE` | `/api/agents/collections/:name/sources` | Remove an external source |
| `POST` | `/api/agents/collections/:name/reset` | Reset a collection |

### Actions
Expand Down