Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae7d3852e2 | ||
|
|
3878dddaa7 | ||
|
|
dbf4a896c3 | ||
|
|
0ce74551ac | ||
|
|
eff81e4d8d |
@@ -158,7 +158,10 @@ deleted it, FK SET NULL) re-links every still-tracked file. A truncated
|
|||||||
listing (200 dirs / 1000 files / depth 12 caps) creates new members but
|
listing (200 dirs / 1000 files / depth 12 caps) creates new members but
|
||||||
never reconciles deletions. Dials are netguard-pinned (ports 80/443 outside
|
never reconciles deletions. Dials are netguard-pinned (ports 80/443 outside
|
||||||
tests), credentials travel only in a Basic `Authorization` header (never the
|
tests), credentials travel only in a Basic `Authorization` header (never the
|
||||||
URL), and redirects are refused outright. Creation AND every sync re-check
|
URL), and redirects are refused outright. Rate-limited answers (429/503) are
|
||||||
|
retried up to 3 times honoring `Retry-After` (capped at 30s), directory walks
|
||||||
|
are paced 100ms apart, and the engine's per-sync budget is 6 minutes — large
|
||||||
|
shares throttle instead of failing. Creation AND every sync re-check
|
||||||
`AllowConnector("webdav")` from the entitlement catalog; a downgrade
|
`AllowConnector("webdav")` from the entitlement catalog; a downgrade
|
||||||
suppresses syncs instead of deleting anything.
|
suppresses syncs instead of deleting anything.
|
||||||
|
|
||||||
@@ -242,7 +245,9 @@ against each protocol (parallel netguard-pinned probes sharing the siblings'
|
|||||||
that passes. This is orchestration, not a fourth connector: every sibling's
|
that passes. This is orchestration, not a fourth connector: every sibling's
|
||||||
plan gate, validation (including CardDAV's https/443 pin), caps and projections
|
plan gate, validation (including CardDAV's https/443 pin), caps and projections
|
||||||
apply unchanged, and materialization stays on the siblings' `/sync` surfaces.
|
apply unchanged, and materialization stays on the siblings' `/sync` surfaces.
|
||||||
The separate Contacts sync is untouched.
|
The separate Contacts sync API (`POST /api/contacts/sync`) is untouched, but
|
||||||
|
its settings tab was removed — the unified Nextcloud tab is the UI path, and
|
||||||
|
legacy `?tab=nextcloud` deep links redirect to it.
|
||||||
|
|
||||||
| Method | Path | Returns / behavior |
|
| Method | Path | Returns / behavior |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
|
|||||||
@@ -7,6 +7,39 @@ Versions correspond to git tags and to the published image set
|
|||||||
(the line was reset to 0.2.x at 0.2.14 — Superbrain is pre-beta).
|
(the line was reset to 0.2.x at 0.2.14 — Superbrain is pre-beta).
|
||||||
Dates are tag dates.
|
Dates are tag dates.
|
||||||
|
|
||||||
|
## 0.3.6 — 2026-11-24
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- **WebDAV on large shares**: Nextcloud throttles bursty PROPFIND walks, so
|
||||||
|
production's 1,000+ file share failed intermittently with "unexpected
|
||||||
|
answer (429)" and "context deadline exceeded". PROPFIND now retries
|
||||||
|
429/503 up to 3 times honoring `Retry-After` (capped at 30s, ctx-bound,
|
||||||
|
linear backoff without the header), the directory walk paces 100ms between
|
||||||
|
requests, and the engine's per-sync budget grows from 3 to 6 minutes.
|
||||||
|
Truncation semantics are unchanged (a capped walk still never reconciles
|
||||||
|
deletions); unit tests cover recover-after-429 and the bounded attempt
|
||||||
|
count.
|
||||||
|
|
||||||
|
## 0.3.5 — 2026-11-24
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- **CalDAV against real Nextcloud**: the calendar-query REPORT now sends
|
||||||
|
`comp-filter` (RFC 4791 §9.8) instead of `comp`. sabre/dav silently ignores
|
||||||
|
unknown elements inside `<filter>` and answers 400 ("The {caldav}filter
|
||||||
|
element is required") when no `comp-filter` parses, so every calendar's
|
||||||
|
event fetch failed against Nextcloud while discovery succeeded — syncs
|
||||||
|
recorded success with zero events and no `lastError`. Reproduced against
|
||||||
|
Nextcloud 34.0.3 (`comp` → 400, `comp-filter` → 207); `fakeCaldav` now
|
||||||
|
validates REPORT bodies like sabre so the integration suite catches this
|
||||||
|
class of bug.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- **Contacts sync settings tab**: the single-config Nextcloud Contacts sync
|
||||||
|
UI is gone — the unified Nextcloud tab is the UI path.
|
||||||
|
`POST /api/contacts/sync` is untouched (Contact rows still feed
|
||||||
|
contact-linking; the handler is stateless). Legacy `?tab=nextcloud` deep
|
||||||
|
links land on the unified tab.
|
||||||
|
|
||||||
## 0.3.4 — 2026-11-23
|
## 0.3.4 — 2026-11-23
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ SUPERBRAIN_APP_IP="192.168.0.94"
|
|||||||
SUPERBRAIN_MIGRATE_IP="192.168.0.95"
|
SUPERBRAIN_MIGRATE_IP="192.168.0.95"
|
||||||
# Release to install; the generic `upgrade` flow keeps .env in step with the
|
# Release to install; the generic `upgrade` flow keeps .env in step with the
|
||||||
# service file's VERSION afterwards.
|
# service file's VERSION afterwards.
|
||||||
SUPERBRAIN_IMAGE_VERSION="0.3.4"
|
SUPERBRAIN_IMAGE_VERSION="0.3.6"
|
||||||
|
|
||||||
# render_superbrain_compose writes the app-dir compose file. Called by
|
# render_superbrain_compose writes the app-dir compose file. Called by
|
||||||
# config_superbrain (install) and by deploy/federated/update.sh after a lib
|
# config_superbrain (install) and by deploy/federated/update.sh after a lib
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ NAME=superbrain
|
|||||||
DESCRIPTION="Bookmark & Knowledge Base"
|
DESCRIPTION="Bookmark & Knowledge Base"
|
||||||
DOCS=https://github.com/andrew/superbrain
|
DOCS=https://github.com/andrew/superbrain
|
||||||
CONTAINER=federatedcomputer/superbrain-app
|
CONTAINER=federatedcomputer/superbrain-app
|
||||||
VERSION=0.3.4
|
VERSION=0.3.6
|
||||||
INTERNAL_IP=192.168.0.93
|
INTERNAL_IP=192.168.0.93
|
||||||
DEPENDS="postgresql"
|
DEPENDS="postgresql"
|
||||||
PORTS=3000
|
PORTS=3000
|
||||||
|
|||||||
@@ -228,12 +228,17 @@ func Events(ctx context.Context, conn Conn, calURL string) (*EventResult, error)
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// calQueryBody uses comp-filter (RFC 4791 §9.8) — NOT "comp": sabre/dav
|
||||||
|
// (Nextcloud) silently ignores unknown elements inside <filter>, then 400s
|
||||||
|
// with "The {caldav}filter element is required" when no comp-filter parsed.
|
||||||
|
// The fakes once ignored REPORT bodies entirely and missed this; fakeCaldav
|
||||||
|
// now validates the body like sabre does.
|
||||||
const calQueryBody = `<?xml version="1.0" encoding="utf-8"?>` +
|
const calQueryBody = `<?xml version="1.0" encoding="utf-8"?>` +
|
||||||
`<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">` +
|
`<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">` +
|
||||||
`<D:prop><D:getetag/><C:calendar-data/></D:prop>` +
|
`<D:prop><D:getetag/><C:calendar-data/></D:prop>` +
|
||||||
`<C:filter><C:comp name="VCALENDAR"><C:comp name="VEVENT">` +
|
`<C:filter><C:comp-filter name="VCALENDAR"><C:comp-filter name="VEVENT">` +
|
||||||
`<C:time-range start="%s" end="%s"/>` +
|
`<C:time-range start="%s" end="%s"/>` +
|
||||||
`</C:comp></C:comp></C:filter></C:calendar-query>`
|
`</C:comp-filter></C:comp-filter></C:filter></C:calendar-query>`
|
||||||
|
|
||||||
// --- PROPFIND plumbing -------------------------------------------------------
|
// --- PROPFIND plumbing -------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,18 @@ func (f *fakeCaldav) serve(w http.ResponseWriter, r *http.Request) {
|
|||||||
<response><href>%s/personal/</href><propstat><prop xmlns:C="urn:ietf:params:xml:ns:caldav"><resourcetype><C:calendar/></resourcetype><displayname>Personal</displayname></prop></propstat></response>
|
<response><href>%s/personal/</href><propstat><prop xmlns:C="urn:ietf:params:xml:ns:caldav"><resourcetype><C:calendar/></resourcetype><displayname>Personal</displayname></prop></propstat></response>
|
||||||
</multistatus>`, f.root, f.root, f.root)
|
</multistatus>`, f.root, f.root, f.root)
|
||||||
case "REPORT":
|
case "REPORT":
|
||||||
|
// Validate the query body like sabre/dav does: a calendar-query
|
||||||
|
// without a <filter> containing <comp-filter> is a 400 ("The
|
||||||
|
// {caldav}filter element is required"). The old fake ignored the
|
||||||
|
// body, which let a wrong element name ("comp" instead of
|
||||||
|
// "comp-filter") ship and fail against real Nextcloud.
|
||||||
|
raw, _ := io.ReadAll(io.LimitReader(r.Body, 1<<20))
|
||||||
|
if !strings.Contains(string(raw), "comp-filter") {
|
||||||
|
w.Header().Set("Content-Type", "application/xml")
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
io.WriteString(w, `<?xml version="1.0"?><d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns"><s:exception>Sabre\DAV\Exception\BadRequest</s:exception><s:message>The {urn:ietf:params:xml:ns:caldav}filter element is required for this request</s:message></d:error>`)
|
||||||
|
return
|
||||||
|
}
|
||||||
key := strings.Trim(strings.TrimPrefix(r.URL.Path, f.root+"/"), "/")
|
key := strings.Trim(strings.TrimPrefix(r.URL.Path, f.root+"/"), "/")
|
||||||
collection := f.events
|
collection := f.events
|
||||||
if key == "personal" {
|
if key == "personal" {
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func httpClient(conn Conn) *http.Client {
|
|||||||
// ListTools connects, initializes and lists the server's tools, then closes
|
// ListTools connects, initializes and lists the server's tools, then closes
|
||||||
// the session. The context bounds the whole exchange.
|
// the session. The context bounds the whole exchange.
|
||||||
func ListTools(ctx context.Context, conn Conn) ([]Tool, error) {
|
func ListTools(ctx context.Context, conn Conn) ([]Tool, error) {
|
||||||
client := mcpsdk.NewClient(&mcpsdk.Implementation{Name: "superbrain", Version: "0.3.4"}, nil)
|
client := mcpsdk.NewClient(&mcpsdk.Implementation{Name: "superbrain", Version: "0.3.6"}, nil)
|
||||||
var transport mcpsdk.Transport
|
var transport mcpsdk.Transport
|
||||||
hc := httpClient(conn)
|
hc := httpClient(conn)
|
||||||
switch conn.Transport {
|
switch conn.Transport {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -146,6 +147,13 @@ func List(ctx context.Context, conn Conn) (*ListResult, error) {
|
|||||||
if rel != "" {
|
if rel != "" {
|
||||||
dirURL += "/"
|
dirURL += "/"
|
||||||
}
|
}
|
||||||
|
if dials > 1 {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil, ctx.Err()
|
||||||
|
case <-time.After(walkPace):
|
||||||
|
}
|
||||||
|
}
|
||||||
entries, err := propfindEntries(ctx, conn, dirURL)
|
entries, err := propfindEntries(ctx, conn, dirURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -218,18 +226,62 @@ type parsed struct {
|
|||||||
// propfind issues a PROPFIND with the given Depth and returns the raw
|
// propfind issues a PROPFIND with the given Depth and returns the raw
|
||||||
// response (caller closes the body). Both Check and List build the same
|
// response (caller closes the body). Both Check and List build the same
|
||||||
// request; only Depth differs.
|
// request; only Depth differs.
|
||||||
|
//
|
||||||
|
// Rate limits (429/503 — Nextcloud throttles bursty PROPFIND walks) are
|
||||||
|
// retried up to rateRetries times, honoring Retry-After (capped at
|
||||||
|
// rateWaitCap so a hostile server cannot pin the sync); without the header
|
||||||
|
// a short linear backoff applies. Every wait is ctx-bound.
|
||||||
func propfind(ctx context.Context, conn Conn, target, depth string) (*http.Response, error) {
|
func propfind(ctx context.Context, conn Conn, target, depth string) (*http.Response, error) {
|
||||||
req, err := http.NewRequestWithContext(ctx, "PROPFIND", target, strings.NewReader(propfindBody))
|
for attempt := 0; ; attempt++ {
|
||||||
if err != nil {
|
req, err := http.NewRequestWithContext(ctx, "PROPFIND", target, strings.NewReader(propfindBody))
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", "application/xml")
|
||||||
|
req.Header.Set("Depth", depth)
|
||||||
|
res, err := httpClient(conn).Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not reach the WebDAV share: %w", err)
|
||||||
|
}
|
||||||
|
if (res.StatusCode == http.StatusTooManyRequests || res.StatusCode == http.StatusServiceUnavailable) && attempt < rateRetries {
|
||||||
|
wait := rateLimitWait(res.Header.Get("Retry-After"), attempt)
|
||||||
|
_ = res.Body.Close()
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil, fmt.Errorf("could not reach the WebDAV share: %w", ctx.Err())
|
||||||
|
case <-time.After(wait):
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
}
|
}
|
||||||
req.Header.Set("Content-Type", "application/xml")
|
}
|
||||||
req.Header.Set("Depth", depth)
|
|
||||||
res, err := httpClient(conn).Do(req)
|
const (
|
||||||
if err != nil {
|
rateRetries = 3
|
||||||
return nil, fmt.Errorf("could not reach the WebDAV share: %w", err)
|
rateWaitCap = 30 * time.Second
|
||||||
|
rateWaitDefault = 5 * time.Second
|
||||||
|
// walkPace spaces directory PROPFINDs so a bounded walk stays under
|
||||||
|
// common server rate limits instead of tripping them and paying
|
||||||
|
// Retry-After waits on every request.
|
||||||
|
walkPace = 100 * time.Millisecond
|
||||||
|
)
|
||||||
|
|
||||||
|
// rateLimitWait parses Retry-After (delay-seconds form; the HTTP-date form
|
||||||
|
// falls back to the default) and caps it. attempt is zero-based.
|
||||||
|
func rateLimitWait(header string, attempt int) time.Duration {
|
||||||
|
if secs, err := strconv.Atoi(strings.TrimSpace(header)); err == nil && secs >= 0 {
|
||||||
|
d := time.Duration(secs) * time.Second
|
||||||
|
if d > rateWaitCap {
|
||||||
|
d = rateWaitCap
|
||||||
|
}
|
||||||
|
return d
|
||||||
}
|
}
|
||||||
return res, nil
|
d := rateWaitDefault * time.Duration(attempt+1)
|
||||||
|
if d > rateWaitCap {
|
||||||
|
d = rateWaitCap
|
||||||
|
}
|
||||||
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
const propfindBody = `<?xml version="1.0" encoding="utf-8"?>` +
|
const propfindBody = `<?xml version="1.0" encoding="utf-8"?>` +
|
||||||
|
|||||||
@@ -197,3 +197,52 @@ func TestNormalizeBasePercentSafety(t *testing.T) {
|
|||||||
t.Fatalf("double or missing encoding: %q", got)
|
t.Fatalf("double or missing encoding: %q", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A 429 with Retry-After is retried, not fatal: the walk recovers once the
|
||||||
|
// throttle window passes (Nextcloud rate-limits bursty PROPFIND walks).
|
||||||
|
func TestListRetriesRateLimit(t *testing.T) {
|
||||||
|
allowPrivate(t)
|
||||||
|
hits := 0
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
hits++
|
||||||
|
if hits == 1 {
|
||||||
|
w.Header().Set("Retry-After", "1")
|
||||||
|
http.Error(w, "slow down", http.StatusTooManyRequests)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Type", "application/xml")
|
||||||
|
w.WriteHeader(http.StatusMultiStatus)
|
||||||
|
_, _ = w.Write([]byte(`<multistatus xmlns="DAV:">` +
|
||||||
|
`<response><href>/dav/</href><propstat><prop><resourcetype><collection/></resourcetype></prop></propstat></response>` +
|
||||||
|
`<response><href>/dav/a.txt</href><propstat><prop><resourcetype/><getetag>"A1"</getetag></prop></propstat></response>` +
|
||||||
|
`</multistatus>`))
|
||||||
|
}))
|
||||||
|
t.Cleanup(ts.Close)
|
||||||
|
res, err := List(context.Background(), Conn{BaseURL: ts.URL + "/dav", Username: davUser, Password: davPass})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("429 then 207 must recover: %v", err)
|
||||||
|
}
|
||||||
|
if len(res.Files) != 1 || res.Files[0].Path != "a.txt" || hits != 2 {
|
||||||
|
t.Fatalf("retry walk wrong: files=%v hits=%d", res.Files, hits)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Persistent 429s stay bounded: exactly rateRetries+1 attempts, then the
|
||||||
|
// server's answer surfaces (no infinite retry loop pinning the sync tick).
|
||||||
|
func TestListRateLimitBounded(t *testing.T) {
|
||||||
|
allowPrivate(t)
|
||||||
|
hits := 0
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
hits++
|
||||||
|
w.Header().Set("Retry-After", "0")
|
||||||
|
http.Error(w, "slow down", http.StatusTooManyRequests)
|
||||||
|
}))
|
||||||
|
t.Cleanup(ts.Close)
|
||||||
|
_, err := List(context.Background(), Conn{BaseURL: ts.URL + "/dav", Username: davUser, Password: davPass})
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "429") {
|
||||||
|
t.Fatalf("persistent 429 must surface: %v", err)
|
||||||
|
}
|
||||||
|
if hits != rateRetries+1 {
|
||||||
|
t.Fatalf("attempts = %d, want %d", hits, rateRetries+1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const (
|
|||||||
tick = 5 * time.Minute // engine cadence
|
tick = 5 * time.Minute // engine cadence
|
||||||
syncEvery = 30 * time.Minute // per-connection freshness target
|
syncEvery = 30 * time.Minute // per-connection freshness target
|
||||||
perTick = 10 // connections claimed per tick
|
perTick = 10 // connections claimed per tick
|
||||||
syncTimeout = 3 * time.Minute // one full reconcile
|
syncTimeout = 6 * time.Minute // one full reconcile (large walks pace + retry 429s)
|
||||||
lastErrCap = 500
|
lastErrCap = 500
|
||||||
dialBudget = 10 // outbound.Reserve window per owner (tests + syncs)
|
dialBudget = 10 // outbound.Reserve window per owner (tests + syncs)
|
||||||
dialWindow = time.Minute
|
dialWindow = time.Minute
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ name = "superbrain-mcp"
|
|||||||
# Versioned in lockstep with the Superbrain release it speaks to (house
|
# Versioned in lockstep with the Superbrain release it speaks to (house
|
||||||
# tooling tracks one version per app); the federated mcpserver gateway
|
# tooling tracks one version per app); the federated mcpserver gateway
|
||||||
# installs this package and spawns `superbrain-mcp` per linked instance.
|
# installs this package and spawns `superbrain-mcp` per linked instance.
|
||||||
version = "0.3.4"
|
version = "0.3.6"
|
||||||
description = "MCP server for Superbrain — bookmarks, tags and pages over the Superbrain REST API"
|
description = "MCP server for Superbrain — bookmarks, tags and pages over the Superbrain REST API"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
"""Superbrain MCP server — bookmarks, tags and pages for AI tooling."""
|
"""Superbrain MCP server — bookmarks, tags and pages for AI tooling."""
|
||||||
|
|
||||||
__version__ = "0.3.4"
|
__version__ = "0.3.6"
|
||||||
|
|||||||
@@ -908,6 +908,11 @@ try {
|
|||||||
await page.goto(`${base}/settings`)
|
await page.goto(`${base}/settings`)
|
||||||
await page.getByRole('tab', { name: 'Profile' }).click()
|
await page.getByRole('tab', { name: 'Profile' }).click()
|
||||||
assert.equal(await page.getByRole('tab', { name: 'Automations', exact: true }).count(), 0, 'Automations tab still present in Settings')
|
assert.equal(await page.getByRole('tab', { name: 'Automations', exact: true }).count(), 0, 'Automations tab still present in Settings')
|
||||||
|
// The Contacts sync tab is removed too; its legacy deep link lands on the
|
||||||
|
// unified Nextcloud tab (the sync API itself remains).
|
||||||
|
assert.equal(await page.getByRole('tab', { name: 'Contacts sync' }).count(), 0, 'Contacts sync tab still present in Settings')
|
||||||
|
await page.goto(`${base}/settings?tab=nextcloud`)
|
||||||
|
await page.getByPlaceholder('https://cloud.example.com').waitFor()
|
||||||
console.log('PASS: Automations lives in the sidebar with a task dropdown, deep-links to /automations, and the legacy settings tab redirects')
|
console.log('PASS: Automations lives in the sidebar with a task dropdown, deep-links to /automations, and the legacy settings tab redirects')
|
||||||
|
|
||||||
// Mobile pass (390x844): the shell becomes a drawer, tables become cards,
|
// Mobile pass (390x844): the shell becomes a drawer, tables become cards,
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import { useSearchParams, useRouter } from 'next/navigation'
|
|||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'
|
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'
|
||||||
import { User, Mail, Server, Cloud, CloudCog, Shield, Bell, Bot, KeyRound, PlugZap, FolderSync, CalendarDays, BookUser, ArrowLeft, Check, X, AlertTriangle } from 'lucide-react'
|
import { User, Mail, Server, CloudCog, Shield, Bell, Bot, KeyRound, PlugZap, FolderSync, CalendarDays, BookUser, ArrowLeft, Check, X, AlertTriangle } from 'lucide-react'
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
import { invalidateReference } from '@/lib/reference-data'
|
|
||||||
import { NotificationsSettings } from '@/components/notifications-settings'
|
import { NotificationsSettings } from '@/components/notifications-settings'
|
||||||
import { ProfileSettings } from '@/components/profile-settings'
|
import { ProfileSettings } from '@/components/profile-settings'
|
||||||
import { AiSettings } from '@/components/ai-settings'
|
import { AiSettings } from '@/components/ai-settings'
|
||||||
@@ -36,7 +35,6 @@ const NAV_GROUPS = [
|
|||||||
{ value: 'webdav', label: 'WebDAV', icon: FolderSync },
|
{ value: 'webdav', label: 'WebDAV', icon: FolderSync },
|
||||||
{ value: 'caldav', label: 'CalDAV', icon: CalendarDays },
|
{ value: 'caldav', label: 'CalDAV', icon: CalendarDays },
|
||||||
{ value: 'carddav', label: 'CardDAV', icon: BookUser },
|
{ value: 'carddav', label: 'CardDAV', icon: BookUser },
|
||||||
{ value: 'nextcloud', label: 'Contacts sync', icon: Cloud },
|
|
||||||
{ value: 'imap', label: 'IMAP', icon: Mail },
|
{ value: 'imap', label: 'IMAP', icon: Mail },
|
||||||
] },
|
] },
|
||||||
{ label: 'AI & Automation', items: [
|
{ label: 'AI & Automation', items: [
|
||||||
@@ -57,15 +55,23 @@ export function SettingsClient({ oidc, callbackUrl }: { oidc: OidcStatus; callba
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
// Automations moved out of Settings to its own workspace; legacy deep
|
// Automations moved out of Settings to its own workspace; legacy deep
|
||||||
// links (?tab=automations) redirect there instead of falling back to profile.
|
// links (?tab=automations) redirect there instead of falling back to profile.
|
||||||
useEffect(() => { if (requestedTab === 'automations') router.replace('/automations') }, [requestedTab, router])
|
// The Contacts sync tab was removed — its legacy ?tab=nextcloud deep link
|
||||||
const initialSection = NAV_GROUPS.some(g => g.items.some(i => i.value === requestedTab))
|
// lands on the unified Nextcloud tab (the sync API itself remains).
|
||||||
? requestedTab
|
useEffect(() => {
|
||||||
|
if (requestedTab === 'automations') router.replace('/automations')
|
||||||
|
if (requestedTab === 'nextcloud') router.replace('/settings?tab=nextcloud-connect')
|
||||||
|
}, [requestedTab, router])
|
||||||
|
// The Contacts sync tab was removed — its legacy ?tab=nextcloud deep link
|
||||||
|
// lands on the unified Nextcloud tab (the sync API itself remains). Map the
|
||||||
|
// legacy value BEFORE deriving the initial section so the tab is selected
|
||||||
|
// on first render; the effect above only cleans the URL.
|
||||||
|
const mappedTab = requestedTab === 'nextcloud' ? 'nextcloud-connect' : requestedTab
|
||||||
|
const initialSection = NAV_GROUPS.some(g => g.items.some(i => i.value === mappedTab))
|
||||||
|
? mappedTab
|
||||||
: 'profile'
|
: 'profile'
|
||||||
const [imapConfig, setImapConfig] = useState({ host: '', port: 993, tls: true, username: '', password: '', folder: 'INBOX' })
|
const [imapConfig, setImapConfig] = useState({ host: '', port: 993, tls: true, username: '', password: '', folder: 'INBOX' })
|
||||||
const [ncConfig, setNcConfig] = useState({ nextcloudUrl: '', cardDavPath: '', username: '', password: '' })
|
|
||||||
const [savingImap, setSavingImap] = useState(false)
|
const [savingImap, setSavingImap] = useState(false)
|
||||||
const [testingImap, setTestingImap] = useState(false)
|
const [testingImap, setTestingImap] = useState(false)
|
||||||
const [syncingContacts, setSyncingContacts] = useState(false)
|
|
||||||
const [section, setSection] = useState(initialSection)
|
const [section, setSection] = useState(initialSection)
|
||||||
// Below md the grouped nav becomes a list -> detail flow (same
|
// Below md the grouped nav becomes a list -> detail flow (same
|
||||||
// master-detail pattern as collections/tags/contacts); at md+ the
|
// master-detail pattern as collections/tags/contacts); at md+ the
|
||||||
@@ -113,32 +119,6 @@ export function SettingsClient({ oidc, callbackUrl }: { oidc: OidcStatus; callba
|
|||||||
finally { setTestingImap(false) }
|
finally { setTestingImap(false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
const syncContacts = async () => {
|
|
||||||
if (!ncConfig.nextcloudUrl || !ncConfig.username || !ncConfig.password) {
|
|
||||||
toast.error('Fill in Nextcloud URL, username, and password')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setSyncingContacts(true)
|
|
||||||
try {
|
|
||||||
const res = await fetch('/api/contacts/sync', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify(ncConfig),
|
|
||||||
})
|
|
||||||
const data = await res.json().catch(() => null)
|
|
||||||
if (res.ok && data?.synced !== undefined) {
|
|
||||||
// Review CR-07: the sync mirrors the address book — remotely deleted
|
|
||||||
// contacts are removed too (scoped to this source, never from partial
|
|
||||||
// responses). Surface both counts so the policy is visible.
|
|
||||||
const removed = typeof data.removed === 'number' && data.removed > 0 ? `, removed ${data.removed} deleted on the server` : ''
|
|
||||||
toast.success(`Synced ${data.synced} contacts${removed}`)
|
|
||||||
invalidateReference('contacts')
|
|
||||||
}
|
|
||||||
else toast.error(data?.error ?? 'Sync failed')
|
|
||||||
} catch { toast.error('Sync failed') }
|
|
||||||
finally { setSyncingContacts(false) }
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="max-w-5xl space-y-6">
|
<div className="max-w-5xl space-y-6">
|
||||||
<div>
|
<div>
|
||||||
@@ -223,30 +203,6 @@ export function SettingsClient({ oidc, callbackUrl }: { oidc: OidcStatus; callba
|
|||||||
</TabsContent>
|
</TabsContent>
|
||||||
<TabsContent value="carddav" className="mt-0 space-y-4">
|
<TabsContent value="carddav" className="mt-0 space-y-4">
|
||||||
<CardDavSettings />
|
<CardDavSettings />
|
||||||
</TabsContent>
|
|
||||||
<TabsContent value="nextcloud" className="mt-0 space-y-4">
|
|
||||||
<div className="rounded-lg border p-4 space-y-3">
|
|
||||||
<h3 className="font-medium flex items-center gap-2"><Cloud className="h-4 w-4" /> Contacts sync (Nextcloud)</h3>
|
|
||||||
<div className="grid grid-cols-2 gap-3">
|
|
||||||
<div className="col-span-2">
|
|
||||||
<label className="text-xs font-medium text-muted-foreground">Nextcloud URL</label>
|
|
||||||
<Input value={ncConfig.nextcloudUrl} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setNcConfig(p => ({ ...p, nextcloudUrl: e.target.value }))} placeholder="https://nextcloud.example.com" />
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2">
|
|
||||||
<label className="text-xs font-medium text-muted-foreground">CardDAV Path (optional)</label>
|
|
||||||
<Input value={ncConfig.cardDavPath} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setNcConfig(p => ({ ...p, cardDavPath: e.target.value }))} placeholder="/remote.php/dav/addressbooks/users/USER/contacts/" />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label className="text-xs font-medium text-muted-foreground">Username</label>
|
|
||||||
<Input value={ncConfig.username} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setNcConfig(p => ({ ...p, username: e.target.value }))} />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label className="text-xs font-medium text-muted-foreground">App Password</label>
|
|
||||||
<Input type="password" value={ncConfig.password} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setNcConfig(p => ({ ...p, password: e.target.value }))} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<Button onClick={syncContacts} loading={syncingContacts}>Sync Contacts Now</Button>
|
|
||||||
</div>
|
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
<TabsContent value="imap" className="mt-0 space-y-4">
|
<TabsContent value="imap" className="mt-0 space-y-4">
|
||||||
<div className="rounded-lg border p-4 space-y-3">
|
<div className="rounded-lg border p-4 space-y-3">
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ const SECTIONS = [
|
|||||||
icon: FolderSync,
|
icon: FolderSync,
|
||||||
title: 'Connections',
|
title: 'Connections',
|
||||||
body: [
|
body: [
|
||||||
'Settings connects Superbrain to your services: WebDAV shares, CalDAV calendars, CardDAV address books, Nextcloud contacts sync, and IMAP mailboxes. Credentials are stored encrypted and are write-only — the app never shows them back to you.',
|
'Settings connects Superbrain to your services: a unified Nextcloud connect (files, calendars & contacts), WebDAV shares, CalDAV calendars, CardDAV address books, and IMAP mailboxes. Credentials are stored encrypted and are write-only — the app never shows them back to you.',
|
||||||
'On Core deployments with Nextcloud, the connection forms offer a one-click prefill for your account.',
|
'On Core deployments with Nextcloud, the connection forms offer a one-click prefill for your account.',
|
||||||
],
|
],
|
||||||
where: 'Settings → Connections',
|
where: 'Settings → Connections',
|
||||||
|
|||||||
@@ -167,8 +167,8 @@ export function CardDavSettings() {
|
|||||||
<p className="text-sm text-muted-foreground mt-1">
|
<p className="text-sm text-muted-foreground mt-1">
|
||||||
Connect an address book from any CardDAV service. Each book becomes a Collection, one
|
Connect an address book from any CardDAV service. Each book becomes a Collection, one
|
||||||
bookmark per contact, re-checked in the background every 30 minutes. Passwords are
|
bookmark per contact, re-checked in the background every 30 minutes. Passwords are
|
||||||
encrypted at rest and never shown again. (This is separate from Contacts sync, which
|
encrypted at rest and never shown again. (This is separate from the Contacts page,
|
||||||
feeds contact-linking.)
|
which feeds contact-linking.)
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{allowed && <Button size="sm" onClick={openCreate}><Plus className="h-4 w-4 mr-1" /> Connect address book</Button>}
|
{allowed && <Button size="sm" onClick={openCreate}><Plus className="h-4 w-4 mr-1" /> Connect address book</Button>}
|
||||||
|
|||||||
Reference in New Issue
Block a user