feat: generate DQL from natural language (bring-your-own-key AI)#416
Open
shaunpatterson wants to merge 4 commits into
Open
feat: generate DQL from natural language (bring-your-own-key AI)#416shaunpatterson wants to merge 4 commits into
shaunpatterson wants to merge 4 commits into
Conversation
Adds an 'AI' button to the editor toolbar that opens a modal:
describe the query in plain language, get DQL back, review/edit it,
insert into the editor.
- Bring-your-own-key: Anthropic API key entered by the user, stored
in localStorage only; requests go directly browser -> model API
(anthropic-dangerous-direct-browser-access) so nothing routes
through the Ratel server. Model selectable (Haiku default, Sonnet).
- The current schema (schema {}) is summarized compactly (predicates
with types/indexes, type definitions, dgraph.* filtered out) and
sent as context, so generated queries use real predicates.
- The system prompt constrains output to a single fenced DQL block;
extraction falls back to raw text. Generated DQL is editable before
inserting.
- lib/nl2dql.js is pure and fully unit-tested (12 tests: settings
persistence/sanitization, schema summarization, prompt content,
extraction, API call shape, key/error handling).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Generalizes the NL->DQL feature behind a provider registry: - Anthropic (Claude Haiku 4.5 / Sonnet 4.6), OpenAI (GPT-5 mini / GPT-5.1, chat completions with bearer auth) and Google Gemini (2.5 Flash / Pro, generateContent with the key in the x-goog-api-key header so it never appears in URLs). - Provider selector in the modal; API keys and model choice are stored per provider in localStorage. Legacy single-provider settings migrate into the anthropic slot automatically. - Each provider defines buildRequest/parseResponse/parseError; the generation flow, prompt and DQL extraction are shared. - 22 unit tests: request shapes for all three providers, response parsing, settings migration/sanitization, end-to-end mocks, error surfacing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
Contributor
Author
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
Adds an AI button to the editor toolbar: describe the query in plain language, get DQL back, review/edit it in the modal, insert into the editor. Comparable tools are shipping this (NebulaGraph Studio's AI assistant, etc.).
Privacy / key handling
Strictly bring-your-own-key: the user pastes their own API key, it's stored in
localStorageonly (per provider), and requests go directly browser → model API — nothing passes through the Ratel server and no key ever appears in a URL.Providers
A small provider registry (
buildRequest/parseResponse/parseErrorper provider; prompt, schema context and DQL extraction shared):anthropic-dangerous-direct-browser-accessopt-ingenerateContent, key in thex-goog-api-keyheader (not the query string)Schema-aware
On generate, the current
schema {}is summarized compactly (predicates with types/indexes/@reverse, type definitions,dgraph.*filtered) and sent as context, so generated queries use real predicates. The system prompt constrains output to a single fenced DQL block; extraction falls back to raw text; the result is editable before inserting.Testing
22 unit tests: request shapes for all three providers, response parsing, settings persistence/sanitization/migration, end-to-end mocked generation, error surfacing, missing-key/unknown-provider rejection.
npm run buildpasses.🤖 Generated with Claude Code