Skip to content

feat: add AI Chat block with contextual prompting and persistence#6

Closed
flooryyyy wants to merge 1 commit intomainfrom
codex/implement-ai-chat-block-type
Closed

feat: add AI Chat block with contextual prompting and persistence#6
flooryyyy wants to merge 1 commit intomainfrom
codex/implement-ai-chat-block-type

Conversation

@flooryyyy
Copy link
Copy Markdown
Owner

Motivation

  • Provide an on-canvas AI assistant block that accepts a user prompt and can use selected blocks as context to produce helpful assistant responses.
  • Allow optional expansion of context to directly linked nodes (depth = 1) so users can surface nearby related content automatically.
  • Persist assistant messages and chat configuration on the block so conversations survive reloads and can be reviewed later.

Description

  • Add a new chat block type and UI AIChatBlock component with prompt input, checkboxes for Include selected blocks and Expand linked nodes (depth 1), assistant response display, and local styling (ai-chat-block.css).
  • Wire the block into the app: include chat in block type unions and the Add Block modal, register AIChatBlock in ProjectCanvas and PublicProjectCanvas, and pass allBlocks/allLinks into node data so the block can assemble selected context and linked-node expansion.
  • Persist chat state and assistant replies in block metadata.messages and initialize chat metadata defaults (includeSelectedContext: true, expandLinkedNodes: false) when creating new chat blocks.
  • Add backend endpoint POST /api/ai/chat that accepts prompt + assembled context, calls the OpenAI Responses API when OPENAI_API_KEY is configured, and returns a harmless fallback message when the key is not set.
  • Update type/schema layers and DB support: extend graph validation and blocks DB type union to include chat, and add migration 34AddChatBlockType.ts to allow chat as a valid blockType.
  • Add i18n keys for chat UI in en.json, fr.json, and it.json.

Testing

  • Ran static/type checks with npm run -s check which succeeded.
  • Ran the targeted unit tests npm run -s test -- src/app/lib/graph.test.ts which passed.
  • The full test suite (vitest run) failed in this environment with an existing local sqlite migration/test DB error (SqliteError: no such table: main.blocks_old), so the broader CI-style test run did not complete here due to that database state issue.

Codex Task

@flooryyyy flooryyyy closed this Apr 10, 2026
@flooryyyy flooryyyy deleted the codex/implement-ai-chat-block-type branch April 10, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant