Commit graph

7180 commits

Author SHA1 Message Date
Anish Sarkar
3ce759f1d6 refactor(auth): streamline session handling with authenticatedFetch 2026-06-26 22:05:11 +05:30
CREDO23
56826a63bc refactor(routes): rename to workspace + consolidate URL spellings (Phase 2 Wave E)
Hard cutover of the HTTP surface: collapse the three legacy spellings
(/searchspaces, /search-spaces, /search-space/{id}) onto canonical
/workspaces/{workspace_id}/..., rename the gateway field-setter sub-actions to
singular /workspace, rename search_spaces_routes.py -> workspaces_routes.py and the
search_spaces_router -> workspaces_router include, and flip search_space_id ->
workspace_id in bodies/params. No alias routers: the old URLs now 404 by design.
Full app constructs with zero legacy path spellings.
2026-06-26 18:35:08 +02:00
Anish Sarkar
4b6bcaeb1b refactor(auth): reuse desktop token cache in API clients 2026-06-26 22:04:59 +05:30
Anish Sarkar
652a25be37 refactor(chat): use shared authenticated fetch for chat requests 2026-06-26 22:04:33 +05:30
Anish Sarkar
4c257e9122 refactor(auth): route session and zero context through shared fetch 2026-06-26 22:04:23 +05:30
Anish Sarkar
9fc93e5e82 fix(auth): centralize session refresh retry 2026-06-26 22:03:59 +05:30
CREDO23
7fb0707933 refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D)
Scoped codemod over surfsense_backend/app (excluding routes/, Wave E): renames
search_space_id -> workspace_id, search_space -> workspace, SearchSpace -> Workspace
across services, utils, tasks, agents, gateway, event_bus, notifications, podcasts,
automations, observability params, and prompt .md files. Also flips the camelCase
payload key searchSpaceId -> workspaceId (no backend reader; hard cutover).

Preserved carve-outs (verbatim): Celery task names "delete_search_space_background"
and "ai_sort_search_space" (wire names), and the OTel/metric key "search_space.id"
(dashboards depend on it). Enum values 'SEARCH_SPACE' and SearchSourceConnector
untouched.
2026-06-26 18:30:47 +02:00
CREDO23
0c53d884eb refactor(schemas): rename SearchSpace -> Workspace in Pydantic schemas (Phase 2 Wave C)
Rename schemas/search_space.py -> schemas/workspace.py, the SearchSpace* classes
-> Workspace* (incl. UserSearchSpaceAccess -> UserWorkspaceAccess), and the
search_space_id / search_space_name fields -> workspace_id / workspace_name across
all schema modules. Under hard cutover the serialized JSON keys change outright
(no alias). Re-exports in schemas/__init__.py updated.
2026-06-26 18:23:43 +02:00
CREDO23
d948b769ba refactor(db): rename search_space to workspace in satellite ORM models (Phase 2 Wave B)
Flip search_space_id -> workspace_id and the workspace relationship/back_populates
in the automations, file_storage, notifications, and podcasts persistence models,
and drop the Phase 1 Column("workspace_id", ...) shim. Full SQLAlchemy mapper
configuration now passes (db.py + satellites consistent).
2026-06-26 18:20:28 +02:00
CREDO23
df03565940 refactor(db): rename SearchSpace ORM core to Workspace (Phase 2 Wave A)
Flip the symbolic name in db.py: classes SearchSpace/Role/Membership/Invite ->
Workspace*, attributes search_space_id -> workspace_id (and owner_*), relationship
attrs + back_populates pairs, and drop the Phase 1 Column("workspace_id", ...) shim
now that attribute name == column name. Enum values 'SEARCH_SPACE' and the
SearchSourceConnector class are intentionally untouched (carve-outs).

Part of the atomic SearchSpace -> Workspace rename; the suite goes green only once
Waves B-F land (no half-renamed steady state).
2026-06-26 18:18:50 +02:00
CREDO23
49d3001fbf docs(db): tighten migration 170 docstring, move publication invariant to call site
Trim the header to a one-line summary and relocate the "never raw DROP/CREATE
PUBLICATION" invariant (bug #1355, migration 116) to the apply_publication call
site where a refactor would actually occur. Comment/docstring only; no behavior
change.
2026-06-26 17:59:05 +02:00
Anish Sarkar
ef9b5b42a8 feat: update JWT token lifetime and enhance header management in chat page
- Increased ACCESS_TOKEN_LIFETIME_SECONDS from 30 minutes to 60 minutes for improved session duration.
- Introduced getRequestHeadersWithCurrentDesktopAuth function to streamline authorization header management across fetch requests in the chat page.
2026-06-26 21:25:27 +05:30
Anish Sarkar
013fae6eba feat: enhance session handling in useSession and auth-fetch
- Introduced fetchSession function to streamline session fetching logic.
- Updated useSession to handle 401 errors by refreshing the session when necessary.
- Modified getDesktopAccessToken to accept options for forced token refresh, improving desktop authentication flow.
2026-06-26 21:25:00 +05:30
Anish Sarkar
23c128dd0d feat: improve fetchZeroContext with enhanced session handling
- Refactored fetchZeroContext to include a buildHeaders function for better header management.
- Added a request function to handle 401 errors and refresh sessions as needed.
- Improved overall session management for desktop authentication.
2026-06-26 21:24:44 +05:30
Anish Sarkar
de4507f413 feat: enhance session management in chat page
- Implemented session refresh logic in the fetchWithTurnCancellingRetry function to handle 401 errors more gracefully.
- Added a new import for refreshSession utility to facilitate session renewal.
2026-06-26 21:00:55 +05:30
CREDO23
5090ed734d feat(db): rename searchspace schema to workspace (migration 170)
Phase 1 (rename DB) commit 3: single Alembic migration (down_revision=169)
that physically renames the SearchSpace schema to WorkSpace to match the
already-shimmed ORM. Renames 4 tables, 24 columns
(search_space_id->workspace_id, owner_search_space_id->owner_workspace_id),
37 named/auto FK/PK/unique constraints, 25 indexes, and 4 sequences. Guarded
forms (ALTER ... IF EXISTS / DO-block RENAME CONSTRAINT) tolerate
runtime-created and absent objects.

Zero publication is reconciled via the blessed path: neutralize the four
column-list tables (documents/automations/new_chat_threads/podcasts) from the
publication, rename, then apply_publication() re-emits SET TABLE with the new
workspace_id lists (no raw DROP/CREATE PUBLICATION, per migration 116).
Downgrade fully reverses the renames and restores the old search_space_id
publication shape via a hardcoded SET TABLE, never importing the live module.

Targets the existing-deployment upgrade path (169 -> 170). The from-scratch
alembic path is a separate, pre-existing concern (0_initial uses create_all).

Verified on a realistic legacy@169 DB (with publication): upgrade clean,
zero_publication --verify passes, autogenerate EMPTY on a create_all DB,
and upgrade->downgrade->upgrade round-trips (old shape + old publication
restored on downgrade). Single alembic head = 170.
2026-06-26 17:27:31 +02:00
CREDO23
464e28ea25 refactor(db): publish workspace_id column in zero_publication
Phase 1 (rename DB) commit 2: flip the search_space_id entries in the
canonical Zero publication column lists (documents, automations,
new_chat_threads, podcasts) to the renamed physical column workspace_id,
so ALTER PUBLICATION ... SET TABLE matches the post-rename schema.

No test references the publication shape; functional verification via
`python -m app.zero_publication --verify` runs after migration 170
builds/renames the publication against a live DB.
2026-06-26 16:56:39 +02:00
Anish Sarkar
a80cb8c060 feat: update authentication defaults to LOCAL
- Changed default AUTH_TYPE in backend configuration to "LOCAL".
- Updated frontend environment configuration to reflect the new default for packaged clients.
- Adjusted runtime authentication resolution to use "LOCAL" as the fallback value.
2026-06-26 18:52:42 +05:30
CREDO23
c6d4e5df7c refactor(db): rename searchspaces table to workspaces
Phase 1 (rename DB) commit 1i: rename the SearchSpace table to workspaces
and flip all 24 inbound FK target strings (20 in db.py + the 4 satellite
models), plus the raw-SQL searchspaces references in the obsidian and
google-unification integration fixtures.

This completes the ORM half of Phase 1. The SearchSpace class name,
relationship/back_populates attribute names, and the /searchspaces API
route URLs are intentionally left for Phase 2.

Verified: unit 2375 passed/1 skip, integration 346 passed (baseline
parity); create_all builds every table with the workspaces name and all
FKs resolving to workspaces.id.
2026-06-26 13:27:16 +02:00
CREDO23
35f80268df refactor(db): rename search_space_roles table to workspace_roles
Phase 1 (rename DB) commit 1h: rename the roles table and flip both
inbound FKs (memberships.role_id, invites.role_id), plus the matching
raw-SQL cleanup in the obsidian plugin test.
2026-06-26 12:31:49 +02:00
CREDO23
0ed043379d refactor(db): rename search_space_memberships table to workspace_memberships
Phase 1 (rename DB) commit 1g: rename the memberships table (no inbound
FKs reference it) and update the matching raw-SQL cleanup in the obsidian
plugin test. Relationship attribute names stay until Phase 2.
2026-06-26 12:30:38 +02:00
CREDO23
3b545540e9 refactor(db): rename search_space_invites table to workspace_invites
Phase 1 (rename DB) commit 1f: rename the invites table and flip the one
inbound FK (memberships.invited_by_invite_id). The invites row's own
role_id -> search_space_roles FK is left for the roles rename commit.
2026-06-26 12:29:29 +02:00
CREDO23
581ae693fc refactor(db): shim podcasts.search_space_id to physical workspace_id
Phase 1 (rename DB) commit 1e: attribute->physical column shim on the
podcasts satellite model. ORM attribute and relationship unchanged.
2026-06-26 12:12:13 +02:00
CREDO23
bb953e6857 refactor(db): shim notifications.search_space_id to physical workspace_id
Phase 1 (rename DB) commit 1d: attribute->physical column shim on the
notifications satellite model, plus the inbox-list index column-ref and
its name aligned to workspace (ix_notifications_user_workspace_created).
2026-06-26 12:12:13 +02:00
CREDO23
9271678c73 refactor(db): shim automations.search_space_id to physical workspace_id
Phase 1 (rename DB) commit 1c: attribute->physical column shim on the
automations satellite model. ORM attribute and relationship unchanged.
2026-06-26 12:12:13 +02:00
CREDO23
e2578e09bc refactor(db): shim document_files.search_space_id to physical workspace_id
Phase 1 (rename DB) commit 1b: same attribute->physical column shim as
1a, applied to the document_files satellite model. ORM attribute name
unchanged; FK target string left for the searchspaces rename commit.
2026-06-26 12:08:26 +02:00
CREDO23
533cdfcc81 refactor(db): map search_space_id ORM attrs to physical workspace_id column
Phase 1 (rename DB) commit 1a: shim every search_space_id /
owner_search_space_id column to the renamed physical column
(workspace_id / owner_workspace_id) via Column("workspace_id", ...),
keeping the ORM attribute name unchanged so existing callers are
untouched. Flip all Table-level references that resolve by column key
(inner __table_args__ strings, the ck_connections_scope_owner CHECK
text, and the _INDEX_DEFINITIONS runtime DDL) plus the searchspace-named
constraint/index names to workspace_id. Update the three raw-SQL test
fixtures that referenced the physical column.

Note: SQLAlchemy defaults a column's key to its name, so passing an
explicit "workspace_id" name moves the Table.c key to workspace_id;
Table-level string refs must therefore change in this phase (the
opposite of the original plan's finding 1). The ORM attribute, the
SearchSpace class, relationships, table names, and FK target strings are
intentionally left for later commits/Phase 2.

Verified: unit 2375 passed/1 skip, integration 346 passed (baseline
parity); create_all builds every table with workspace_id.
2026-06-26 12:05:52 +02:00
CREDO23
3b31352e19 fix: make migration 168 idempotent for from-scratch upgrades
Migration 168 used bare add_column/drop_column, so `alembic upgrade head`
from an empty DB failed at 168 ("column revoked_at already exists"): the
0_initial_schema migration bootstraps via Base.metadata.create_all (the live
ORM shape), which already includes the hardened refresh_tokens columns, and
168's unguarded ALTERs then collided.

Guard every step (ADD COLUMN IF NOT EXISTS, DROP COLUMN IF EXISTS, existence-
checked backfill) so 168 no-ops on already-hardened (create_all) databases
while still fully transforming legacy is_revoked-shape databases. Matches the
guarded style already used by migrations 92/149/169. Net schema effect is
unchanged. Restores a clean from-scratch `alembic upgrade head` to head.
2026-06-26 11:35:30 +02:00
DESKTOP-RTLN3BA\$punk
34216d05de chore: synced plans 2026-06-25 23:40:34 -07:00
DESKTOP-RTLN3BA\$punk
aee3ffe4af Merge commit '5b5e95971e' into ci_mvp 2026-06-25 22:48:38 -07:00
Rohan Verma
5b5e95971e
Merge pull request #1541 from MODSetter/dev
feat(version): session auth revamp, API keys, citation system overhaul, artifacts & chat references
2026-06-25 21:17:07 -07:00
DESKTOP-RTLN3BA\$punk
e1ffbfea27 feat: bumped version to 0.0.30 2026-06-25 21:05:04 -07:00
DESKTOP-RTLN3BA\$punk
c3f242a6b2 feat: fix desktop auth issues
- Added logging for JSON parsing failures in structured output to aid in debugging.
- Updated the TranscriptTurn model to ignore unknown keys, improving flexibility for future model variations.
2026-06-25 20:58:50 -07:00
DESKTOP-RTLN3BA\$punk
1bf7f116d6 chore: linting 2026-06-25 20:20:26 -07:00
DESKTOP-RTLN3BA\$punk
9642d7ced0 feat: antropic model added fix & kb tooling fixes
- Updated main-agent middleware to clarify that both filesystem reads/writes and knowledge-base retrieval are handled by the `knowledge_base` subagent.
- Introduced `_forward_mention_pins` function to carry `@`-mention pins into subagent state.
- Revised system prompts to reflect the new retrieval method and ensure proper citation handling.
- Removed the `search_knowledge_base` tool and its related tests, consolidating functionality under the `task` tool.
- Enhanced documentation to guide usage of the new retrieval approach and citation practices.
2026-06-25 20:19:44 -07:00
Rohan Verma
b4af67f77d
Merge pull request #1540 from DhruvTilva/fix/table-element-text-as-html-keyerror
fix: handle missing text_as_html metadata for Unstructured table elements
2026-06-25 13:35:41 -07:00
Rohan Verma
94fdb8a113
Merge pull request #1539 from CREDO23/improve-chat-agent-context-and-citations
[FEAT] Unified [n] citation registry for KB + web, pull-based retrieval
2026-06-25 13:34:52 -07:00
Rohan Verma
5a6ea29610
Merge pull request #1537 from DhruvTilva/test/validators-unit-tests
test: cover validation helpers with unit tests
2026-06-25 13:33:03 -07:00
Rohan Verma
96e42a1003
Merge pull request #1536 from CREDO23/feature-mention-chat-in-chat
[Feat] Chat : Reference past chats via @-mention as read-only context
2026-06-25 13:32:25 -07:00
Rohan Verma
efa9efc80b
Merge pull request #1532 from CREDO23/imporve-artifacts-accessibility
[Feat] Artifacts sidebar for chat deliverables
2026-06-25 13:31:45 -07:00
Rohan Verma
6950646bf1
Merge pull request #1535 from AnishSarkar22/feat/auth-revamp
feat(auth): complete session auth cutover with desktop oauth support
2026-06-25 13:31:02 -07:00
DhruvTilva
bf805fd81e fix: use token-safe truncation for document embeddings
The document saving logic used a hardcoded character slice ([:4000]) for
the document summary content fed to the embedder. For UTF-8 documents
(e.g., Arabic, Chinese, Japanese), characters above U+007F take multiple
bytes but count as 1 character in a slice, potentially producing text
that exceeds the token limit of the embedding model.

Replaced the arbitrary slice with 	runcate_for_embedding(), which safely
bounds the text using the embedding model's actual tokenizer.
2026-06-26 00:09:11 +05:30
DhruvTilva
147c690051 fix: prevent spurious leading spaces in nested codeBlock interior lines
When a codeBlock is nested inside an indented structure like a
bulletListItem, the \_render_block\ function prepends the block's
indentation \prefix\ to every line.

However, for codeBlock elements, only the fence markers (the opening
and closing \\\) should carry the block indentation. Interior code
lines must not have the prefix prepended, because markdown parsers
treat leading spaces inside a code fence as part of the code content.

This fix removes the prefix from interior code lines to prevent
code snippets stored in notes from gaining spurious whitespace.
2026-06-26 00:04:41 +05:30
DhruvTilva
e16e4e2c5c fix: guard missing text_as_html in Table element markdown conversion
When the Unstructured API returns a Table element without text_as_html
in its metadata (e.g. local install or free-tier API), the lambda was
raising KeyError: 'text_as_html', crashing the entire document
indexing pipeline for any file containing tables.

Guard the key access with .get() and fall back to the plain extracted
text content (x) so the pipeline continues and the table content is
still indexed, just without HTML formatting.
2026-06-25 23:52:15 +05:30
Anish Sarkar
d5e2540e51 refactor(api): rename personal access tokens to API keys and update related UI components for consistency 2026-06-25 23:22:11 +05:30
CREDO23
232cc937c5 docs: remove ADR 0001 (RAG/citation architecture shipped)
The RAG/citation/context redesign in ADR 0001 is implemented and validated
(KB + web on the unified [n] citation spine, pull-based retrieval, eager path
retired). Drop the ADR and the one stale docstring reference to it.
2026-06-25 18:50:58 +02:00
CREDO23
2beafbdec8 agent: retire eager KB priority/planner path and its dead flags
The pull-based KB design (on-demand search_knowledge_base tool + pre-injected
workspace tree) fully replaced the old eager retrieval path. Remove its last
remnants:

- Delete KnowledgePriorityMiddleware (knowledge_search.py) and its tests.
- Drop the kb_priority state field + reducer default; trim
  KbContextProjectionMiddleware to project only workspace_tree_text.
- Remove the now-dead feature flags enable_kb_priority_preinjection and
  enable_kb_planner_runnable across backend (flags, route schema, tests,
  env examples) and frontend (settings toggle, zod schema).
- Scrub <priority_documents> and stale KnowledgePriorityMiddleware references
  from prompts, docstrings, and the ADR.

No functional change: nothing wrote kb_priority and neither flag gated live
behavior after the cutover. Full backend suite green (pre-existing unrelated
failures aside).
2026-06-25 18:37:14 +02:00
CREDO23
0148647b98 prompts: remove orphaned system_prompt_composer surface
The legacy system_prompt_composer fragments and its default_system_instructions
wrapper were no longer referenced by any live code path (the main-agent prompt
builder owns composition now). Delete the whole orphaned tree and its test.
2026-06-25 18:37:04 +02:00
CREDO23
5bda944321 citations: normalize word-glued [n] markers
The model frequently writes citations glued to the preceding word
(docs[17]); the (?<!\w) lookbehind (added to dodge arr[1] array indexing)
silently skipped these, leaving raw [n] that fails to render and reads
like array access. Drop the lookbehind so glued citations resolve; genuine
code/array syntax stays protected by the existing code-region carve-out and
unresolved ordinals still drop harmlessly.
2026-06-25 16:28:31 +02:00
CREDO23
ce15016533 citations: consolidate prompts, retire eager path, refresh ADR
Rewrite the main-agent citation contract to a single [n] channel and sync
the orphaned system_prompt_composer surface to match; drop stale
[citation:chunk_id] / <chunk_index> references from dynamic_context and
provider hints. Reuse the shared hybrid search in the deliverables report
(citations omitted for now) and delete the orphaned report KB helper.
Remove the dead eager KnowledgePriorityMiddleware wiring (knowledge_priority
+ stack) and its legacy browse test. Update ADR 0001 to reflect the cutover.
2026-06-25 15:27:09 +02:00