Repository navigation
Update/synco ai agent - #32
Merged
Merged
Conversation
AIService.ts gains chatAgentTurn/resumeAgentTurn, talking to the new
POST /api/orgs/:orgId/ai/chat (+ /tool-result) SSE endpoints — separate
from the existing chatOpenAICompatible/chatGemini regex-based paths,
which keep working unchanged for mistral/gemini/custom/local until
Phase 3 migrates them too.
OrgAI.vue: sendMessage branches to sendMessageViaAgent() when the
org's provider is 'openai'. consumeAgentStream() turns the new SSE
event vocabulary (text/tool_call_result/tool_call_pending/
tool_call_client_required/done/error) into message bubbles;
handleAgentToolDecision() answers a paused tool call — for a
server-mutating tool it just posts {accepted}, for a 'client' tool
(search_messages/create_thread/read_documentation/request_image_upload,
extracted into executeClientTool()) it actually runs the existing
client-side logic first and posts the real result. Session
persistence for this path lives entirely server-side now; syncSession
is only reached by the untouched legacy path.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Replaces the one-tool-call-per-bubble hack from the earlier agent loop integration with a proper structured-turn model: each assistant turn (OpenAI/Mistral/Gemini path) is a single message holding interleaved text/tool parts in arrival order, exactly like a real Claude turn — text, then a tool step, then more text, all in one continuous block instead of spawning a new bubble per tool call. New components (src/views/OrgSpace/components/ai/): - AgentTurn.vue: renders a turn's parts, markdown text via the shared MarkdownRender.vue, tool parts via ToolStepItem. - ToolStepItem.vue: the connected-dot/line timeline look (grey outline pending, pulsing primary while executing, filled primary when done, red on error/reject), collapsed by default, accept/refuse inline for mutating tools, dedicated slot for the interactive image-upload tool. - ToolResultBody.vue: per-tool result rendering — search_messages reuses ThreadMessage.vue so results look and behave like real messages, with a teleport-to-thread button; create_task/create_space/ create_thread get clickable cards; list_* tools get a plain list; everything else falls back to a readable JSON dump. OrgAI.vue: user bubbles stay bubbles, but assistant turns are now full-width (no boxed/mono chat-bubble look) for both the new structured path and the legacy per-provider-migration path (local/ custom), which keeps its existing single tool_call widget untouched functionally, just visually aligned with the new full-width style. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds EntityRow.vue (icon/logo-or-avatar + title + subtitle, hover chevron) as the shared building block for anything the agent lists: - list_spaces: grid of space cards (logo or icon), click navigates into the workspace. - list_threads / create_thread: salon cards (hash or vocal icon), click opens the thread. - list_members: member cards (avatar), click opens a DM with them. - read_tasks (flattened across lists + unlisted) / get_task / create_task: task cards, click opens TaskDetailsModal. - create_space: same card, click navigates into the new space. Read-only tool results (list_*, search_messages, read_tasks, get_task) now expand by default instead of staying collapsed behind a click — that's the actual payload the user asked for, not an implementation detail to hide. Mutating tools stay collapsed by default since their text confirmation already says what happened. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
loadSession() was assigning the backend's structured StoredMessage[]
(role 'user'/'assistant'/'tool', toolCalls arrays, toolCallId/
toolResult) straight into aiSessionMessages — a completely different
shape from the parts-based turns OrgAI.vue renders live, so every
reopened conversation silently lost its tool steps and results,
showing only... whatever happened to survive the shape mismatch.
convertStoredMessagesToChatMessages() rebuilds the same {viaAgentLoop,
parts: [...]} turns the live SSE consumer builds: one turn per
'user'-delimited run of assistant/tool messages, tool results matched
back to their call by toolCallId. A cheap heuristic
(isStructuredAgentTranscript) only applies this when the loaded
messages are actually in the new format, so old-format sessions
(local/custom's flat syncSession() writes) keep loading as before.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- Floating button appears once the user scrolls more than ~200px away from the bottom of the conversation, click jumps back down (mirrors the existing scrollToBottom()). - The composer textarea now grabs focus on mount too, not just on session switch (that watcher already existed). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
'../../../../../doc/*.md' from OrgAI.vue (src/views/OrgSpace/views/) resolves to the GitHub/ parent directory, not synco_app/doc/ where the 8 real .md files live — so import.meta.glob matched nothing and the tool always returned just the header, no chapters. Pre-existing bug (present in the old handleToolCall before this rework), carried over verbatim into executeClientTool. Fixed both occurrences to '../../../../doc/*.md' (4 levels up reaches synco_app/). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
AISettings.vue: new provider tile "Passerelle Synco AI (auto-hébergée)"
with two fields (gateway URL, Ollama URL — reusing endpointUrl) instead
of an API key, since auth is the user's own Synco/Keycloak token, not
a stored secret. Skips the cloud-data-transfer warning, same as
'custom' and 'local'.
AIService.ts: chatAgentTurn/resumeAgentTurn branch on
provider==='gateway' to call the gateway's own URL directly (plain
fetch with the Keycloak token attached by hand, since sfetch always
targets VITE_API_URL) instead of synco_api's /ai/chat — sending
{orgId, syncoApiUrl, ollamaUrl, modelId} alongside the usual payload
so the gateway can reach back to synco_api and Ollama with no
per-deployment config of its own.
OrgAI.vue: sendMessage's provider gate now includes 'gateway' —
nothing else changes, consumeAgentStream/AgentTurn already render
whichever backend drives the loop identically.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…or cloud providers listGatewayModels() (AIService.ts) calls the gateway's new GET /models?ollamaUrl=... to list what's already pulled on the org's Ollama, with the Keycloak token attached the same way chatAgentTurn does for that provider. AISettings.vue: entering the gateway/Ollama URL (debounced 500ms) auto-fetches that list and replaces the free-text model field with a <select>, with a loading state and a clear error if Ollama can't be reached or has no models pulled yet. OpenAI/Mistral/Gemini get the same <select> treatment using the existing curated recommendedModels list (expanded a bit) instead of the old suggestion-chip buttons. Every selector keeps an "Autre (saisie manuelle)" escape hatch so an already-configured model outside the list, or one Ollama doesn't expose via /v1/models, is never silently lost. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Matches the backend change: OLLAMA_URL is now the gateway's own deployment config (defaults to 127.0.0.1:11434, always correct for the all-in-one image), not something a Synco admin should ever need to know or type. AISettings.vue's "gateway" provider now shows a single field (the gateway's own URL); listGatewayModels() and chatAgentTurn/resumeAgentTurn no longer send an ollamaUrl the gateway never asked for. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Génération/distribution de la clé de session IA par org (réutilise le pattern ThreadKey/WorkspaceKey déjà en place), déchiffrement client des sessions gateway. Plan jumeau avec Synco_AI_Gateway/E2EE_PLAN.md et synco_api/E2EE_PLAN.md (même format wire, vecteur de test partagé). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Tasks created without a space and without an assignee (e.g. by the Synco AI agent's create_task tool, which never sets assigneeIds) were silently hidden: the frontend filter only checked assignees, ignoring the backend's listMyTasks() rule that a self-created, space-less task is also yours even if unassigned. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds generateAiSessionKey/wrapAiSessionKeyForMember/unwrapAiSessionKey (RSA-OAEP envelope for the per-org AES session key, mirroring the existing ThreadKey pattern) and encryptAiField/decryptAiField (the "gcm1:" AES-256-GCM wire format shared with Synco_AI_Gateway/synco_api, AAD-bound to session/message/field) per E2EE_PLAN.md §2-3. Test vector round-trips against the fixed wire_value from the plan. Note: the plan's "key (hex)" line is missing a trailing nibble (63 hex chars); the test derives the key from the accompanying base64 value instead, which does produce the documented wire_value. Test files are excluded from the app tsconfig (bun:test runs without type-checking; no test infra existed in this repo before).
…p/cache ensureAiSessionKey(orgId) fetches the caller's wrapped AiSessionKey (GET /api/orgs/:orgId/ai/key per synco_api's E2EE_PLAN.md §4.3), unwraps it with the user's RSA private key, and caches the imported CryptoKey + raw base64 in memory only (never localStorage, same convention as `privateKey` in crypto.ts). On 404 (no key provisioned yet for this org) it bootstraps: generates a new key, wraps it for self, and POSTs it — no separate admin check client-side, matching AISettings.vue/saveSettings() which also leaves that to the server. getAiSessionKeyRawBase64 exposes the raw key for the gateway's X-Session-Key header. shareAiSessionKeyWithMember re-wraps the already-cached key for another member's public key (used when onboarding a member who doesn't have a key yet). Tests cover the bootstrap path, the normal fetch+unwrap path, the locked-PIN error, and request de-duplication for concurrent callers — the concurrency test caught a real unhandled-rejection bug in the `pending` map's cleanup (`.finally()` returns an unawaited promise that must itself be caught).
- gatewayFetch now sends X-Session-Key (org's AI session key, raw base64) so Synco_AI_Gateway can decrypt/encrypt session fields — synco_api never sees this key or the plaintext content. Plumbed through chatAgentTurn/resumeAgentTurn, which already had orgId. - fetchSessions() decrypts each session's title (gateway-aes-gcm-v1, "gcm1:"-prefixed) for the sidebar; a still-plain default title (not yet PATCHed) is left as-is, a decrypt failure (locked PIN) falls back to a placeholder rather than showing ciphertext. - loadSession() now distinguishes 3 message-storage formats: legacy plain, legacy E2EE envelope (local/custom, unchanged), and the new gateway-aes-gcm-v1 — StoredMessage[] in clear JSON structure but with content/toolResult/toolCalls[].arguments as opaque "gcm1:" strings, decrypted per-field via decryptGatewaySessionMessages() before going through the existing turn-reconstruction path. A locked private key or any decrypt error falls back to the same "[🔒 ...]"/"[⚠️ ...]" placeholders already used for legacy E2EE, instead of crashing or leaking ciphertext. - setEncryptedSessionTitle(orgId, sessionId, plainTitle): encrypts and PATCHes the title for a gateway session (called from OrgAI.vue after the first message, next commit) — synco_api can no longer derive a title itself once content is opaque to it. - pendingToolCall.args is deliberately left encrypted in loadSession: no frontend code reads session.pendingToolCall today, so decrypting it would be dead work; noted inline for whoever wires that up. Tests cover all 3 loadSession branches plus their locked-PIN fallback paths, using fixtures built with the real crypto primitives (self grown AI session key wrapped for a test RSA identity, encrypted via encryptAiField) rather than hand-rolled ciphertext.
…ession consumeAgentStream() detects the transition from no active session to a freshly-assigned one (the 'session' SSE event) and, only for the 'gateway' provider, fires setEncryptedSessionTitle(orgId, sessionId, userText) with the text the user just typed — fire-and-forget, so a PATCH failure never blocks the chat. resumeAgentTurn's stream (tool decision replies) doesn't pass a title source, so it never re-triggers this on an already-active session. consumeAgentStream lives entirely client-side (live SSE from the gateway stays in clear, per E2EE_PLAN.md §5 — only loadSession's history reload goes through decryption), so this is the only hook that has the plaintext title text available at the moment the session id becomes known.
…eway' saveSettings() now calls ensureAiSessionKey(orgId) before writing activeModules.aiConfig whenever the selected provider is 'gateway' — first activation bootstraps a key, a later save on an already-key'd org just primes the cache (cheap, no extra request beyond the GET). A failure (locked PIN, no public key, server rejection) blocks the save with a clear toast instead of leaving the org in a provider='gateway'-but-no-key state where every member's first chat would fail silently (E2EE_PLAN.md §6). No new client-side permission check was added around this — mirrors saveSettings() itself, which already leaves authorization on activeModules.aiConfig entirely to the server.
…f decrypting Root cause (cross-repo, traced through synco_api and Synco_AI_Gateway): loadSession()/fetchSessions() only attempted decryption when `session.encryptionScheme === 'gateway-aes-gcm-v1'`, but Synco_AI_Gateway's SyncoClient never sends that field on create_session/patch_session (confirmed in synco_client.rs — its own crypto.rs even flags this as a known gap: "l'idée d'un marqueur encryptionScheme... reste possible plus tard"). synco_api dutifully stores and returns whatever it's given, i.e. permanently null for every gateway session. So the condition was never true, and encrypted sessions fell through to the "legacy plain" branch — ciphertext rendered as if it were the message. Fix (synco_app-only, no change needed in synco_api or the gateway): detect encrypted content by its own "gcm1:" prefix instead of the session-level marker — hasEncryptedGatewayFields() in loadSession(), and a direct prefix check (already partially there) in fetchSessions() for titles. This matches what the gateway itself actually does (decrypt_field_if_encrypted also keys off the per-field prefix, never the session marker). Since there's no longer a reliable session-level signal that "this whole session is uniformly encrypted", decryptGatewaySessionMessages now catches failures per-field instead of per-session: one corrupted or unexpectedly-plaintext field falls back to an inline placeholder for just that field, rather than replacing the entire visible history with the single "conversation illisible" placeholder. setEncryptedSessionTitle now also sends encryptionScheme: 'gateway-aes-gcm-v1' on its title PATCH — this is always true for a gateway session (the gateway encrypts unconditionally, no flag-gated fallback), so it's a safe, truthful, idempotent way to finally give synco_api's existing downgrade-guard something real to protect, even though synco_app itself no longer depends on reading it. Tests updated to set encryptionScheme: null in gateway-session fixtures (matching the real API response) — the case-3 tests are now the actual regression coverage for this bug — plus new coverage for per-field decrypt resilience and the same fetchSessions title bug.
gatewayFetch() awaited keycloak.updateToken() then, separately, the session key lookup — two independent operations (refreshing the auth token doesn't depend on the E2EE session key, and vice versa) chained sequentially. Matters most on a cold cache (first gateway message of a session, where getAiSessionKeyRawBase64 does a real GET/POST round trip), same class of fix as the gateway's session+tools-manifest parallelization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.