Repository navigation
Description
Overview
Implement the ai-chat node type as a first-class knowledge graph node. Conversations (both local agent and ACP) are stored as nodes with messages in nested properties, following the same pattern as playbook rules[]. This enables semantic search across chat history, Stamped ACL permissions, cloud sync, and end-to-end development traceability.
Architecture decisions: ADR-028 (message storage), ADR-029 (behavior-owned embedding)
Full specification: AI Chat Node Architecture (supersedes archived spec)
Acceptance Criteria
-
AiChatNodeBehaviorimplementsNodeBehaviortrait - Core schema defined in
core_schemas.rswithmessages[]array property -
get_embeddable_content()extracts user + assistant text fromproperties.messages[], skips tool calls -
get_parent_contribution()returnsNone -
aiChatNodePluginregistered incore-plugins.tswith/ai-chatslash command -
AiChatNodeViewer.svelterenders conversation with streaming support - Tool calls render as collapsible cards (tool name, args, result summary, duration)
- Tool result archival at write time: full results kept in memory during session, only
result_summarypersisted to DB, fullresultnulled - Write buffering: messages buffered in memory, debounced flush every 5-10s, immediate flush on close/navigate-away/app-exit
- Soft message cap: UX nudge at ~500 messages suggesting a new conversation (not a hard limit)
- Node references in assistant messages decorated as clickable
NodeReferencecomponents -
referenced_nodes[]tracked per message,mentionsrelationships created - Provenance: nodes created by agent get
created_byandsource_chat_nodeproperties - Side nav AI item creates/opens an
ai-chatnode - First-launch onboarding dialog (ACP provider vs local model download)
- Unit tests for behavior, schema validation, content extraction, and tool result archival
- Code passes
bun run quality:fix
Technical Specifications
Schema (nested properties pattern — ADR-028)
{
"node_type": "ai-chat",
"content": "Chat title",
"properties": {
"provider": "native | anthropic | gemini | mistral",
"model": "ministral-3b-instruct-q4_k_m",
"status": "active | archived",
"last_active": "2026-04-03T10:30:00Z",
"context_tokens": 4200,
"created_nodes": ["node:abc123"],
"messages": [
{
"role": "user",
"content": "Implement the webhook handler",
"referenced_nodes": ["node:spec-789"],
"timestamp": "2026-04-03T10:28:00Z"
},
{
"role": "tool_call",
"tool": "search_semantic",
"args": { "query": "billing webhook" },
"status": "completed",
"result_summary": "Found 3 nodes matching 'billing webhook'",
"result": null,
"duration_ms": 340,
"timestamp": "2026-04-03T10:28:01Z"
},
{
"role": "assistant",
"content": "Based on the spec, here is my approach...",
"referenced_nodes": ["node:abc123"],
"timestamp": "2026-04-03T10:28:05Z"
}
]
}
}Guardrails (from ADR-028 and architect review)
Tool result archival: Tool call results archived at write time. During active session, full result kept in memory for display. When flushing to DB, result nulled out, result_summary preserved. Full results are reproducible by re-running the tool.
Write buffering: Messages buffered in memory during active conversation. Frontend in-memory state is source of truth. Debounced flush to SurrealDB every 5-10 seconds. Immediate flush on: conversation close, navigate-away, app exit.
Soft message cap: At ~500 messages, gentle UX prompt suggests starting a new conversation. Not a hard limit. If conversation splitting is ever needed, it should be user-initiated (not automatic). Documented as deferred in ADR-028.
NodeBehavior Implementation
pub struct AiChatNodeBehavior;
impl NodeBehavior for AiChatNodeBehavior {
fn type_name(&self) -> &'static str { "ai-chat" }
fn can_have_children(&self) -> bool { false }
fn supports_markdown(&self) -> bool { false }
fn get_embeddable_content(&self, node: &Node) -> Option<String> {
// Behaviors operate on flattened API format (see flatten_properties_for_api)
let messages = node.properties.get("messages")?.as_array()?;
let text: Vec<&str> = messages.iter()
.filter_map(|m| match m.get("role")?.as_str()? {
"user" | "assistant" => m.get("content")?.as_str(),
_ => None,
})
.collect();
if text.is_empty() { None } else { Some(text.join("\n\n")) }
}
fn get_parent_contribution(&self, _node: &Node) -> Option<String> {
None
}
}Frontend Components
AiChatNodeViewer.svelte— page-level viewer (followsQueryNodeViewerpattern)ChatMessage.svelte— message bubble with streaming supportToolCallDisplay.svelte— collapsible card for tool executionsAiOnboardingDialog.svelte— first-launch modal (ACP vs local model)- Side nav AI item in sidebar
Reference Files
packages/core/src/behaviors/mod.rs—NodeBehaviortraitpackages/core/src/models/core_schemas.rs— core schema definitionspackages/desktop-app/src/lib/plugins/core-plugins.ts— plugin registrationpackages/desktop-app/src/lib/components/viewers/query-node-viewer.svelte— page-level viewer patternpackages/desktop-app/src/lib/design/icons/registry.ts— ai-chat icon already registered
Dependencies
- Shared types, traits, and interface contracts for agent subsystems #998 (shared types/traits — for TypeScript interfaces)
- Refactor embedding service to use NodeBehavior via NodeService for content extraction #1018 (embedding refactor — for behavior-owned embedding to work end-to-end, but ai-chat behavior can be implemented before this)
Related Issues
- ACP Integration and Local LLM Capability #997 (parent epic)
- Frontend: Chat UI, agent panel, model settings, and AI onboarding #1003 (frontend chat UI — coordinate on AiChatNodeViewer vs standalone components)
- Local agent ReAct loop with history management and context budgeting #1006 (local agent loop — produces messages for this node type)
- Tauri command layer: wire frontend to agent backend services #1008 (Tauri commands — wires frontend to agent services)
Activity
malibio commentedon Apr 3, 2026
Scope Boundary: #1017 vs #1003
#1017 (this issue) owns the chat experience:
AiChatNodeViewer.svelte(page-level viewer)ChatMessage.svelte,ChatInput.svelte,ToolCallDisplay.svelteAiOnboardingDialog.svelte(first-launch modal)chatStore.ts(conversation state, write buffering, message cap)aiChatNodePluginin core-plugins.tsAiChatNodeBehaviorin behaviors/mod.rs#1003 owns agent/model management:
agentStore.ts,modelStore.tsThe
AiChatNodeViewerconsumes the agent selector and model picker from #1003.Backend Implementation Guide
NodeBehavior Registration
Read
packages/core/src/behaviors/mod.rs:BehaviorRegistry(around line 1050) —HashMap<String, Box<dyn NodeBehavior>>BehaviorRegistry::new()registers all built-in typesAiChatNodeBehaviorregistration alongside othersCore Schema
Read
packages/core/src/models/core_schemas.rs:get_core_schemas()returns all built-in schemasprovider,model,status,last_active,context_tokens,created_nodes,messagesValidation in NodeService
Read
packages/core/src/services/node_service.rs:validate_playbook_rules()(line 1784) — shows how type-specific validation is called on create/updatemalibio commentedon Apr 3, 2026
Archived Design System Reference
There is a comprehensive archived chat UI implementation guide with full Svelte component code, CSS styling, and state management patterns:
Chat UI Implementation Guide:
nodespace-docs/archived/architecture/ai/chat-ui-implementation-guide.mdChatPanel.svelte— main container with provider selector, chat history, inputChatHistory.svelte— scrollable message list with auto-scroll on new messagesAssistantMessage.svelte— with inline node reference parsing and NodePill renderingToolCallBlock— collapsible tool execution display (pending/success/error states)ChatInput— with@mentionautocomplete integrationNodePill.svelte— type-aware clickable node badges with loading/error statesnode-reference-parser.ts— parsesnodespace://links and raw UUIDs from contentChatStateinterface — conversation entries, streaming state, UI preferences--surface-1,--space-4,--text-muted, etc.)Node Reference System in Chat:
nodespace-docs/archived/architecture/ai/node-reference-system-in-chat.md@mentions→ agentnodespace://links)mentionsrelationship creationNote: These archived docs assume child-node message storage (superseded by ADR-028). The UI component patterns, CSS, and node reference system are still directly applicable — only the data loading needs to change from "fetch child nodes" to "read
properties.messages[]".Use these as the starting point for
AiChatNodeViewerimplementation.malibio commentedon Apr 3, 2026
Baseline: 123 test files, 3816 tests passed. Starting implementation.
feat: AI Chat node type with schema, behavior, plugin, and viewer (cl…
feat: AI Chat node type with schema, behavior, plugin, and viewer (cl…
feat: AI Chat node type with schema, behavior, plugin, and viewer (#1028