Commit graph

5 commits

Author SHA1 Message Date
Naeem Dosh
8c6c6c4016 SMB connector: per-source index document + filename citation labels
Two client-requested changes:

1. Table of contents per source. On each sync the connector writes one
   index document listing every file on the share, grouped by folder, so
   the assistant is aware of the full document set even when a search
   returns only some files. It re-upserts only when the file set changes,
   is excluded from the orphan-delete reconcile (shares the source prefix
   but is not a file), and is removed if SMB_WRITE_INDEX is turned off.

2. Shorter citation labels. semantic_identifier is now the file name, not
   the full path, so the chat/search citation shows "Angebot.pdf" instead
   of a long truncated Z:\... path. The full network path stays in `link`
   and metadata; the UI overlay copies it to the clipboard on click, in
   both the chat view and the licensed Search view. A DOC_FORMAT_VERSION
   bump re-upserts already-synced files once so existing docs get the new
   label without waiting for a content change.

Verified with a mock-client simulation: 17 checks covering filename
labels, full-path copy, index create/update/delete, reconcile whitelist,
add/remove sync, and the one-time format-version re-upsert.
2026-09-23 18:51:34 +05:00
Naeem Dosh
f3ab7f4cee SMB connector: fix stuck 'Initial Indexing', configurable name prefix + timeout
Four items from client feedback:

1. Stuck 'Initial Indexing' status. Root cause (by design in Onyx):
   docprocessing/utils.py never runs a classic index attempt for INGESTION_API
   connectors — documents are pushed via the API, not polled — so
   last_finished_status stays null and the badge is stuck even though the docs
   are indexed and searchable (also why it's safe: no risk of re-index deleting
   the pushed docs). Two-part fix:
   - Connector now sets each cc_pair ACTIVE after provisioning (set_cc_pair_active),
     which fixes the connector detail page + 'Active Connectors' count.
   - Frontend overlay (branding/smb/smb-ui.patch): the Ingestion table shows the
     real cc_pair_status for ingestion_api connectors instead of forcing
     'Initial Indexing'. Verified live: new cc_pair comes up ACTIVE.

2. Connector name now configurable: ONYX_CONNECTOR_NAME_PREFIX (default 'AIDO SMB').
3. HTTP timeout now configurable: ONYX_HTTP_TIMEOUT (default 60), for large embeds.
4. (Phase 2 already delivered in ab64692 — the preview/path overlay.)

Verified live against running Onyx: provisioning sets ACTIVE, custom prefix
'Livtec Docs - Sales' applied, timeout honoured, ä-filename still indexed. Full
overlay apply green, no conflict markers, connector modules parse.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-10 23:14:28 +05:00
Naeem Dosh
ee281da0e5 SMB connector: handle non-UTF-8 (Windows/Latin-1) filenames
Client hit a crash on every cycle: filenames with non-UTF-8 bytes (e.g. 0xE4 = ä)
arrive from os.walk surrogate-escaped ('\udce4'), and encoding them to UTF-8 for
the id hash / ingestion JSON / manifest raised UnicodeEncodeError.

Fix: normalise each relative path once via _fs_safe() — recover the real on-disk
bytes (os.fsencode reverses surrogateescape) and decode with the share's codepage
(SMB_FILENAME_ENCODING, default cp1252) — so the id hash, the ingestion payload
and the manifest are all UTF-8/JSON-safe and the filename displays correctly
(Angebot_März.txt, not a crash). New SMB_FILENAME_ENCODING env; the previously
added SMB_SOURCE_<N>_MOUNT_OPTS also lets you pass iocharset at mount time.

Verified E2E against live Onyx with a real 0xE4 filename: no crash, indexed
'Angebot_März.txt', logical path '\company\sales\Angebot_März.txt' stored
correctly, manifest persisted, restart → 0/0/all-unchanged (stable id).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-10 00:34:32 +05:00
Naeem Dosh
afac2c42ae SMB connector: mount CIFS shares inside the container (like Lobehub)
Client asked to mount the SMB share in Docker rather than on the host. Added an
opt-in in-container CIFS mount:
- entrypoint.sh mounts each source's share (mount -t cifs) from env
  (SMB_SOURCE_<N>_UNC or _SERVER+_SHARE, _USERNAME/_PASSWORD/_DOMAIN/_VERS),
  read-only, credentials via a 0600 file (never in the process list), then drops
  from root to the unprivileged app user via gosu and execs the sync app;
  unmounts cleanly on stop.
- Dockerfile installs cifs-utils + gosu, runs the mount entrypoint.
- docker-compose.smb.yml adds cap_add [SYS_ADMIN, DAC_READ_SEARCH] +
  apparmor:unconfined (privileged fallback noted).
- .env.example + README document in-container mode; legacy host-bind-mount mode
  still works (omit _UNC/_SERVER for that source).

Entrypoint logic validated (POSIX sh check + mocked dry-run: correct mount args,
guest fallback, creds file, privilege drop). Live CIFS round-trip to be run
against a real SMB server; the sync engine is already E2E-verified.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-08 23:14:46 +05:00
NaeemDosh
909a541c6b SMB connector Phase 1: sync + self-provisioning + multi-source (E2E-verified)
Production SMB->Onyx sync sidecar (public ingestion + admin APIs only; no Onyx
source changes; upgrade-safe). Verified end-to-end against a live Onyx v4.5.2.

Core (app/sync.py): per-cycle reconcile — upsert new/changed (stable url-safe
document ids so updates replace in place), delete files removed from the share,
plus manifest-independent reconcile against Onyx's own doc list. Content-hash change
detection; per-source + per-file failure isolation.

Self-provisioning (app/onyx_client.py): create/cache API key (admin bootstrap) and
one connector/cc_pair per source via connector-with-mock-credential; idempotent
reuse via the grouped indexing-status lookup.

Multi-source (app/config.py): JSON SMB_SOURCES or indexed SMB_SOURCE_N_*; logical
path mapping (mount -> \\company\share) shown in citations.

Extraction (app/extract.py): pdf/docx/xlsx/csv/txt/md/html, light deps. State manifest
(atomic), entrypoint loop w/ graceful shutdown + retry/backoff. Dockerfile, compose
snippet, .env.example, README.

Bugs caught + fixed during live E2E (missed by code review + stub tests):
- Onyx URL-encodes document ids -> switched to url-safe ids + store Onyx's returned
  canonical id, so delete/reconcile match.
- connector listing endpoint + provision-response parsing corrected (indexing-status
  is grouped by source; StatusResponse.data = cc_pair_id).
- Documented: auto API-key creation needs LICENSE_ENFORCEMENT_ENABLED=false (the
  /admin/api-key endpoint is EE-tier-gated); ingestion + connector creation are not.

E2E results (live Onyx): ingest 2 docs w/ logical paths; change->update-in-place with
stable ids; remove->delete synced; auto-provision create + idempotent reuse; multi-
source config both styles.
2026-09-01 23:18:33 +05:00