Skip to content

feat(developer-portal): integrate docs AI widget and landing updates#687

Merged
wabicai merged 49 commits intoonekeyfrom
codex/add-doc-ai-chat-widget
Mar 31, 2026
Merged

feat(developer-portal): integrate docs AI widget and landing updates#687
wabicai merged 49 commits intoonekeyfrom
codex/add-doc-ai-chat-widget

Conversation

@wabicai
Copy link
Copy Markdown
Member

@wabicai wabicai commented Mar 3, 2026

Changes

  • integrate the Docs AI widget into developer-portal and keep the modal available by default
  • route chat requests by deployment hostname, while still allowing NEXT_PUBLIC_DOCS_AI_API_URL to override for local or staging
  • sanitize retrieval scaffold text in assistant messages so the UI only shows the grounded answer content
  • fix source-only responses so copy and retry continue to work correctly, and keep source cards rendered separately
  • polish the Search / Ask AI panel visual design and keyboard navigation bridge
  • sync the landing page footer with the latest hardware-js-sdk PR fix(developer-portal): restore footer layout with SDK version and commit hash #692 layout updates

Validation

  • removed local Playwright screenshots and other test artifacts from the worktree before pushing
  • yarn build:docs
  • verified previously with local end-to-end flows against the RAG service for source display, copy, and retry behavior

Notes

  • this PR depends on the RAG service changes for direct Context7 answers, but the frontend now handles fallback responses correctly
  • direct answers from Context7 still depend on the final docs site origin being allowed in the widget settings

@revan-zhang
Copy link
Copy Markdown
Contributor

revan-zhang commented Mar 3, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@socket-security
Copy link
Copy Markdown

socket-security Bot commented Mar 3, 2026

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: npm @polkadot/util-crypto is 91.0% likely obfuscated

Confidence: 0.91

Location: Package overview

From: packages/connect-examples/expo-example/package.jsonnpm/@polkadot/util-crypto@13.1.1

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@polkadot/util-crypto@13.1.1. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm @react-native/debugger-frontend is 96.0% likely obfuscated

Confidence: 0.96

Location: Package overview

From: ?npm/@react-native/debugger-frontend@0.73.3

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@react-native/debugger-frontend@0.73.3. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

@wabicai wabicai changed the title feat(developer-portal): 接入 assistant-ui 文档 AI 对话弹窗 feat(developer-portal): 接入文档 AI 对话弹窗 Mar 3, 2026
@wabicai wabicai marked this pull request as draft March 3, 2026 08:22
@wabicai wabicai changed the title feat(developer-portal): 接入文档 AI 对话弹窗 feat(developer-portal): integrate docs AI chat widget Mar 5, 2026
@wabicai wabicai changed the title feat(developer-portal): integrate docs AI chat widget feat(developer-portal): integrate docs AI widget and landing updates Mar 11, 2026
@wabicai wabicai marked this pull request as ready for review March 11, 2026 04:59
- Add i18n to DeviceActionAnimation (7 hardcoded Chinese strings)
- Fix Chinese fallback text in PinDialog and PassphraseDialog t() calls
- Fix Chinese console.log/error messages in GlobalDialogManager, PinDialog, PassphraseDialog
- Fix Chinese default title in UnifiedLogger
- Add deviceAction i18n keys to en.ts and zh.ts
- Fix malformed code blocks in nip04.decrypt.mdx and nip04.encrypt.mdx
- Fix stray code block delimiter in devicesettings.mdx (en + zh)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@wabicai wabicai force-pushed the codex/add-doc-ai-chat-widget branch from 0bcf166 to 99d2b2d Compare March 13, 2026 03:37
wabicai and others added 6 commits March 14, 2026 14:49
…ator

- Add transformSourceUrl() to rewrite GitHub developer-portal content
  URLs to live docs page URLs via regex, e.g.
  github.com/.../developer-portal/content/en/hardware-sdk/foo.mdx
  → {origin}/en/hardware-sdk/foo
  No static mapping table needed; works across test and prod origins
  automatically via window.location.origin

- Replace status === 'submitted' streaming indicator condition with
  isWaitingForContent = isGenerating && no renderable text yet, so the
  "Generating…" dots stay visible until the first token actually renders
  in the message list, eliminating the blank gap between dot-disappear
  and text-appear during the LLM time-to-first-token window

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…format

- Remove passphrase12_*.ts indirection in addressTest/pubkeyTest count12_three:
  move actual data into passphrase_empty/1/2.ts, update normal.ts to spread
  passphrase_empty directly, delete normal12.ts and all passphrase12_*.ts files.
  All 9 datasets now have the same flat file structure.

- Fix stop button not giving immediate UI feedback: set progress.status to
  'paused' in stopAutomation so isAutomationRunningAtom updates instantly,
  unlocking the start button without waiting for the loop to exit.

- Change formatDuration to HH:MM:SS format for durations >= 1 minute
  (e.g. 1:23, 2:05:30 instead of 83.0s or 7530.0s).

- Simplify start/stop button styling to use Tamagui theme="green/red",
  removing verbose hardcoded backgroundColor/hoverStyle/pressStyle overrides.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add notifyLiveCaseUpdate to the dependency arrays of 5 useCallback hooks
that were using it but not declaring it, fixing react-hooks/exhaustive-deps
lint warnings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…docs

- Wrap @onekeyfe package names in backticks within markdown table links
  to prevent AI chat renderers from misinterpreting @ as mention syntax
- Remove bare @ in search-devices.mdx code comments (en/zh)
- Expand cancel-request.mdx (en/zh) from a stub into a full guide with:
  - Cancel vs disconnect explanation
  - Usage scenarios (timeout, unmount, retry)
  - Code examples (basic, React cleanup, timeout pattern)
  - Error code reference

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Revert the backtick wrapping of @onekeyfe package names in markdown
links — the @ rendering issue is in the AI chat widget (PR #687),
not in the documentation itself.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…estions, expand cancel docs

- Add wrapBarePackageNames() to DocAIMarkdownMessage sanitizer: wraps
  bare @onekeyfe/... package names in backticks so remark-gfm doesn't
  mangle them as autolinks. Skips content already in backticks or
  fenced code blocks.
- Update default AI chat suggestions (en + zh) to more practical
  developer questions: WebUSB connection, React Native BLE setup,
  and EVM transaction signing with full code examples.
- Expand cancel-request.mdx (en + zh) from a minimal stub to a
  comprehensive guide with cancel vs disconnect comparison, usage
  scenarios, React cleanup patterns, and error code reference.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0xchloe996 and others added 17 commits March 26, 2026 14:47
…kdown rendering

- Fix streaming freeze: replace memo-based throttle with leading+trailing edge
  state-based throttle so UI always catches up within 150ms
- Fix @ symbol: broaden scoped package wrapping to all @scope/pkg patterns
- Fix syntax highlighting: use ESM import, remove color !important override
- Increase markdown font size (13px→14px) for better readability
- Redesign header: inline search input with tab switcher on one row
- Fix search bottom padding: wrap content in inner div (reliable for scroll containers)
- Add keyboard navigation: arrow keys switch selection, ↵ icon follows active item
- Move onKeyDown to panel level so arrow keys work regardless of focus
- Add scroll-into-view for both search results and bridge row
- Style navbar search hotkey as separate ⌘ K keycaps like Inkeep
- Fix SSR hydration: defer resolveApiUrl to useEffect
- Soften input placeholder styling

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…disabled endpoint

The previous hydration fix used useState with env var fallback, but when
NEXT_PUBLIC_DOCS_AI_API_URL is not set, the initial state was '' causing
chatApiUrl to be '/api/__docs_ai_disabled'. The transport was created with
this URL before useEffect could resolve the real URL from window.location.

Now: useState('') + useEffect(resolveApiUrl) ensures no request is made to
the disabled endpoint because the widget is closed (returns null) during
the first render, and the real URL is set before any user interaction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…utton for user messages

Root cause: DefaultChatTransport was always created with a URL, even when
apiUrl was empty (''). The fallback '/api/__docs_ai_disabled' triggered a
405 POST. Now transport is undefined when no API URL is available — useChat
receives no transport and makes no requests until the real URL resolves.

Also adds a copy button to user messages so both sides of the conversation
can be copied.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ton color

- Remove useState/useEffect for API URL — call resolveApiUrl() directly
  during render. The URL is derived from env var or window.location hostname,
  same as the sources endpoint. SSR returns '' but widget is closed so no
  hydration mismatch.
- Move user message copy button outside .bubble div to avoid color being
  overridden by .userMessage .bubble * { color: inherit !important }.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Changed .userMessage from horizontal flex to vertical column so the copy
button appears below the bubble instead of beside it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… streaming

Two root causes for streaming lag:
1. SyntaxHighlighter (Prism) runs expensive parsing on every throttled
   render during streaming — a large TypeScript block can take 50-100ms
   per render, blocking the main thread and causing visible stalling.
2. The `components` object was recreated on every render, forcing
   ReactMarkdown to re-process even when displayText hadn't changed.

Fixes:
- Disable syntax highlighting during streaming (disableHighlight=true) —
  code blocks render as plain <pre><code> which is nearly instant.
  Full Prism highlighting activates once streaming ends.
- Memoize the components object and move remarkPlugins to module scope
  so ReactMarkdown skips unnecessary re-processing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…eact-renderer

Switch from react-syntax-highlighter (~200KB, heavy Prism bundle) to
prism-react-renderer (~3KB) — the same library Inkeep/Docusaurus use.

Key improvements:
- Syntax highlighting now works DURING streaming without lag
- Bundle size reduced significantly
- Throttle interval lowered to 120ms (was 150ms) since rendering is cheaper
- Removed disableHighlight flag — no longer needed
- Registered bash/shell/java grammars manually for coverage
- Cleaned up CSS: removed react-syntax-highlighter-specific :global overrides

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
EditorCodeBlock also depended on react-syntax-highlighter which was
removed. Migrated to prism-react-renderer while preserving all features:
line numbers, active line highlight, breakpoint indicators, dark/light
mode theming.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ebpack

remark-gfm@4 and its dependencies (unist-util-visit@5, unist-util-visit-parents@6)
are ESM-only modules that cause webpack code generation errors. Adding them to
transpilePackages lets Next.js transform them for compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace horizontal scrolling cards with a vertical list layout:
- Simple row per source: index badge + title + arrow icon
- Removed CODE type badge and excerpt text for cleaner look
- Bordered list with dividers between items
- Arrow icon animates on hover (translate + accent color)
- Title text truncates with ellipsis on overflow

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…-up messages

1. Prism global CSS leak: Nextra loads prismjs CSS globally which adds
   `background: #ffffff80` to `.token.operator/.entity/.url` — visible as
   white selection-like highlights on operators in chat code blocks.
   Added `.codeScroll :global(.token) { background: none }` reset.

2. Font: removed Fira Code from monospace stack, use system monospace
   (ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas) instead.

3. 403 on follow-up: long assistant responses were sent back verbatim
   in conversation history, making the request body too large for the
   RAG API. Now truncates older assistant messages to 2000 chars.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…and enrich passphrase docs

- Wrap markdown tables in scrollable div to fix width not filling container
- Neutralize Nextra global Prism CSS (.token background) in EditorCodeBlock
- Enrich passphrase docs with device support matrix, interaction flow diagrams, and FAQ (en/zh)
- Remove security risk descriptions about software input from passphrase docs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ce ASCII diagrams

- Remove BLE/USB/Air-Gap rows from device matrix (not passphrase-specific)
- Remove recommendation callout
- Replace ASCII sequence diagrams with clean numbered step lists

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace step lists with Mermaid sequenceDiagram for proactive, reactive,
and session caching flows (en/zh). Nextra 4.6.0 has built-in mermaid
support via @theguild/remark-mermaid.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove dev:docs:webpack and dev:docs:ai-gateway shortcuts from root
package.json — these can be run directly in developer-portal.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@socket-security
Copy link
Copy Markdown

@wabicai wabicai merged commit 5c13c07 into onekey Mar 31, 2026
9 checks passed
@wabicai wabicai deleted the codex/add-doc-ai-chat-widget branch March 31, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants