feat(ai): auto-growing composer + graceful image attachments - #11
Merged
Conversation
Composer (ask-dock): - Replace the single-line <input> with an auto-growing <textarea>: taller default (min 46px), grows with content up to 168px, then scrolls. - Enter sends, Shift+Enter inserts a newline. - Add an image attachment affordance (paperclip) shown ONLY when the model supports vision (modelSupportsVision heuristic or explicit ai.vision flag). Up to 4 images, 5MB each; thumbnails as removable chips, rendered in the user bubble. Image data is stripped before persisting chat history so we never blow the localStorage quota. Plumbing: - transport.buildMessages() now accepts images and emits OpenAI-style multimodal content parts. - /api/ai proxy accepts and forwards up to 4 data:image/ URLs. - aiConfig() exposes vision (inferred from model id, overridable via ai.vision). Also folds in the earlier copy fixes: 'Ask questions about this page', generic page-relevant suggestions, neutral context chip (no hardcoded 'API Reference'), and a shorter disclaimer.
Titles: derive the chat title from the first question with summarizeTitle() — strip filler, capitalize, cut on a word boundary (no more mid-word 'beha…'), drop trailing punctuation. Deterministic, so it works even when the assistant is unavailable. Errors: never surface raw provider errors to readers. The proxy route logs the upstream detail server-side and returns a generic message (preserving 429 for rate limits); the client maps errors to safe, actionable text via friendlyError() and logs the raw detail to the console. Removes the old behavior that echoed the provider's 404 JSON (incl. openrouter.ai privacy URL) straight into the chat.
Before: the model received only a section-name string ('you are viewing the
"Releases" section') and pickSources() returned hardcoded fake labels — so it
had no actual content and replied 'the provided context does not cover this',
even on the very page that answered the question.
Now lib/ai/retrieval.ts grounds every answer in real docs, client-side:
- Always includes the current page's text (read from the DOM: .docs-prose /
.api-doc), so on-page questions are answered from the page.
- Ranks the build-time llms-full.txt corpus against the question (saturating
tf·idf + title boost, with a light stemmer so 'create a service' matches the
'Services' page) and attaches the top pages — so off-page questions are
answered too (Mintlify-style).
- 'Used N sources' now reflects the pages actually retrieved, not placeholders.
Pure client-side (one cached fetch of /llms-full.txt) — works in BYOK mode and
on pure-static hosting; degrades to current-page-only if llms-full.txt is
absent. Proxy context cap raised 8k→16k to fit the grounding context.
Known gap: llms-full.txt is docs-only, so API-reference operation bodies aren't
in the corpus yet (the current API page's DOM text is still included).
feat(ai): real retrieval — Ask AI answers from the docs
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.
What
Reworks the Ask AI composer per feedback: the input now grows as you type, sits taller by default, and (when the model supports it) accepts image attachments.
Composer
<input>→ auto-growing<textarea>: taller default (min 46px), grows with content up to 168px, then scrolls.Vision gating
aiConfig()now exposesvision, inferred from the model id (modelSupportsVisionheuristic: gpt-4o, claude-3+, gemini, llava, pixtral, *-vl, …) and overridable with an explicitai.vision: true|falseinmarkline.json.Plumbing
transport.buildMessages()acceptsimagesand emits OpenAI-style multimodalcontentparts./api/aiproxy accepts and forwards up to 4data:image/URLs.Also folded in (earlier copy fixes)
Ask questions about this page(was 'this API … your integration')Testing
tsc --noEmitclean;next lintclean (one pre-existingmessagesuseMemo warning, unrelated).