Skip to content

Conversation

@joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Aug 11, 2025


PR-Codex overview

This PR introduces enhancements to the AI section of the application, adding new API endpoints and refining the documentation for the chat API. It organizes sidebar links and improves the metadata and response handling for better user experience.

Detailed summary

  • Added Chat API and MCP Server links in the Header.
  • Created secretKeyHeaderParameter for API authentication.
  • Defined a structured sidebar for AI tools.
  • Updated Layout to utilize the new sidebar.
  • Enhanced Chat API documentation with examples and response handling.
  • Introduced EndpointMetadata for API details.
  • Expanded TypeScript examples for handling streamed responses.
  • Improved API parameter structure to support arrays in examples.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added Chat API docs (HTTP and OpenAI-client examples) and a new "Chat API" entry in AI navigation and header.
  • Improvements

    • Simplified API reference layout and broadened parameter example support to include arrays.
    • Updated AI section description and reorganized sidebar.
  • Documentation

    • Added Response Handling guide covering streamed vs non-streamed responses, SSE event types, examples, and a TypeScript consumption snippet.
    • Included endpoint metadata and authentication header guidance for the Chat API.

@changeset-bot
Copy link

changeset-bot bot commented Aug 11, 2025

⚠️ No Changeset found

Latest commit: 0554be3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Aug 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 11, 2025 5:35am
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
nebula ⬜️ Skipped (Inspect) Aug 11, 2025 5:35am
thirdweb_playground ⬜️ Skipped (Inspect) Aug 11, 2025 5:35am
thirdweb-www ⬜️ Skipped (Inspect) Aug 11, 2025 5:35am
wallet-ui ⬜️ Skipped (Inspect) Aug 11, 2025 5:35am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds AI Chat docs and a POST /ai/chat EndpointMetadata component, new SSE streaming response handling documentation with examples, a centralized AI sidebar and layout refactor, a shared secret-key header parameter, and adjustments to APIEndpoint types and UI rendering.

Changes

Cohort / File(s) Summary
AI Chat Docs & Endpoint
apps/portal/src/app/ai/chat/page.mdx, apps/portal/src/app/ai/chat/handling-responses/page.mdx, apps/portal/src/app/ai/chat/EndpointMetadata.tsx
New documentation pages for the Chat API (overview and streaming response handling) with examples and TypeScript consumption patterns; new React component EndpointMetadata describing POST /ai/chat (request schema including messages, stream, context parameter; x-secret-key header; example 200 response with actions).
AI Docs Layout & Navigation
apps/portal/src/app/ai/layout.tsx, apps/portal/src/app/ai/sidebar.tsx, apps/portal/src/app/Header.tsx
Moved inline sidebar to sidebar.tsx and imported it in layout.tsx; updated DocLayout usage and metadata description; added a "Chat API" entry to the header AI links and created an AI sidebar configuration.
APIEndpoint Metadata Components
apps/portal/src/components/Document/APIEndpointMeta/ApiEndpoint.tsx, apps/portal/src/components/Document/APIEndpointMeta/common.tsx
Expanded APIParameter.example type to accept arrays; simplified ApiEndpoint UI by removing rendered header/path/body parameter sections; added and exported secretKeyHeaderParameter describing the x-secret-key header parameter.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant API as Thirdweb API (/ai/chat)
  Client->>API: POST /ai/chat { messages, stream: true?, context?, headers: x-secret-key }
  alt stream=true
    API-->>Client: SSE event: init
    API-->>Client: SSE event: presence
    API-->>Client: SSE event: delta (content chunks)
    API-->>Client: SSE event: action (e.g., sign_transaction, sign_swap)
    API-->>Client: SSE event: image / context (optional)
    API-->>Client: SSE event: error (on failure)
  else stream=false
    API-->>Client: 200 JSON { message, session_id, request_id, actions[] }
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between acf6f38 and 0554be3.

📒 Files selected for processing (8)
  • apps/portal/src/app/Header.tsx (1 hunks)
  • apps/portal/src/app/ai/chat/EndpointMetadata.tsx (1 hunks)
  • apps/portal/src/app/ai/chat/handling-responses/page.mdx (1 hunks)
  • apps/portal/src/app/ai/chat/page.mdx (1 hunks)
  • apps/portal/src/app/ai/layout.tsx (1 hunks)
  • apps/portal/src/app/ai/sidebar.tsx (1 hunks)
  • apps/portal/src/components/Document/APIEndpointMeta/ApiEndpoint.tsx (4 hunks)
  • apps/portal/src/components/Document/APIEndpointMeta/common.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • apps/portal/src/app/Header.tsx
  • apps/portal/src/app/ai/chat/handling-responses/page.mdx
  • apps/portal/src/app/ai/chat/page.mdx
  • apps/portal/src/app/ai/chat/EndpointMetadata.tsx
  • apps/portal/src/app/ai/sidebar.tsx
  • apps/portal/src/components/Document/APIEndpointMeta/common.tsx
  • apps/portal/src/app/ai/layout.tsx
  • apps/portal/src/components/Document/APIEndpointMeta/ApiEndpoint.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Size
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Unit Tests
  • GitHub Check: Build Packages
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch _Docs_Add_AI_Chat_API_documentation_and_endpoint_metadata

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the Portal Involves changes to the Portal (docs) codebase. label Aug 11, 2025
Copy link
Member Author

joaquim-verges commented Aug 11, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 11, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 64.03 KB (0%) 1.3 s (0%) 150 ms (+117.55% 🔺) 1.5 s
thirdweb (cjs) 357.38 KB (0%) 7.2 s (0%) 277 ms (-2.22% 🔽) 7.5 s
thirdweb (minimal + tree-shaking) 5.72 KB (0%) 115 ms (0%) 72 ms (+737.95% 🔺) 187 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 27 ms (+743.34% 🔺) 38 ms
thirdweb/react (minimal + tree-shaking) 19.16 KB (0%) 384 ms (0%) 85 ms (+189.32% 🔺) 468 ms

<ApiEndpoint
metadata={{
description:
"Send requests to the thirdweb AI model and receive a responses.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a grammatical error in the description text. It should be "Send requests to the thirdweb AI model and receive responses." (without the article "a" before the plural noun "responses").

Suggested change
"Send requests to the thirdweb AI model and receive a responses.",
"Send requests to the thirdweb AI model and receive responses.",

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

@joaquim-verges joaquim-verges force-pushed the _Docs_Add_AI_Chat_API_documentation_and_endpoint_metadata branch from 559a578 to acf6f38 Compare August 11, 2025 04:45
@vercel vercel bot temporarily deployed to Preview – nebula August 11, 2025 04:45 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui August 11, 2025 04:45 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb-www August 11, 2025 04:45 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground August 11, 2025 04:45 Inactive
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (2)
apps/portal/src/components/Document/APIEndpointMeta/ApiEndpoint.tsx (2)

212-220: Bug: null check references the wrong identifier in header handling

The null check uses h instead of h.example, which is always truthy. This can produce incorrect serialization decisions.

-      return `-H "${h.name}:${
-        typeof h.example === "object" && h !== null
-          ? JSON.stringify(h.example)
-          : h.example
-      }"`;
+      return `-H "${h.name}:${
+        typeof h.example === "object" && h.example !== null
+          ? JSON.stringify(h.example)
+          : h.example
+      }"`;

261-269: Generate valid fetch examples: stringify body and set Content-Type

Currently the body is emitted as an object, which isn’t a valid fetch payload. Stringify JSON and ensure Content-Type is set when a body is present (unless already provided).

-  if (Object.keys(bodyObj).length > 0) {
-    fetchOptions.body = bodyObj;
-  }
+  if (Object.keys(bodyObj).length > 0) {
+    const existingHeaders =
+      (fetchOptions.headers as Record<string, string | number | boolean | object>) || {};
+    const headers: Record<string, string> = {};
+    for (const [k, v] of Object.entries(existingHeaders)) {
+      headers[k] = typeof v === "string" ? v : JSON.stringify(v);
+    }
+    if (!headers["Content-Type"]) {
+      headers["Content-Type"] = "application/json";
+    }
+    fetchOptions.headers = headers;
+    fetchOptions.body = JSON.stringify(bodyObj, null, 2);
+  }
🧹 Nitpick comments (5)
apps/portal/src/app/ai/chat/page.mdx (3)

20-21: Fix grammar in intro sentence

Small wording tweak for clarity.

-You can use the API with the API directly, or with any OpenAI-compatible client library.
+You can use the API directly, or with any OpenAI-compatible client library.

32-36: Cross-link streaming guidance

Consider linking to the new handling responses page here to help readers discover SSE streaming docs.

Example addition:

  • See handling streaming responses for more details: /ai/chat/handling-responses

36-51: Consistent indentation in the Python snippet

Minor consistency nit: replace the mix of tabs/spaces with spaces only.

-	client = OpenAI(
-	base_url="https://api.thirdweb.com",
-	api_key="<your-project-secret-key>",
-)
+client = OpenAI(
+  base_url="https://api.thirdweb.com",
+  api_key="<your-project-secret-key>",
+)
apps/portal/src/components/Document/APIEndpointMeta/ApiEndpoint.tsx (2)

14-20: Harden APIParameter example type with a reusable alias

Good call expanding support to arrays. To improve type clarity and reuse, define a dedicated alias and use ReadonlyArray to cover readonly literals.

 export type APIParameter =
   | {
       name: string;
       required: false;
       description: React.ReactNode;
       type?: string;
-      example?:
-        | string
-        | boolean
-        | number
-        | object
-        | Array<string | boolean | number | object>;
+      example?: ParameterExample;
     }
   | {
       name: string;
       required: true;
-      example:
-        | string
-        | boolean
-        | number
-        | object
-        | Array<string | boolean | number | object>;
+      example: ParameterExample;
       description: React.ReactNode;
       type?: string;
     };
+
+type ParameterPrimitive = string | boolean | number;
+type ParameterObject = Record<string, unknown>;
+type ParameterExample =
+  | ParameterPrimitive
+  | ParameterObject
+  | ReadonlyArray<ParameterPrimitive | ParameterObject>;

Also applies to: 24-30


152-206: Parameter sections removed — confirm intent or gate behind a prop

Commenting-out ParameterSection/ParameterItem removes discoverable docs for headers/path/body parameters. If simplification is intended, consider gating behind a prop (e.g., showParameters) so endpoints that need detailed parameter docs can enable it.

Example approach:

  • Propagate a boolean flag from EndpointMetadata to ApiEndpoint to re-enable parameter sections when needed.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 559a578 and acf6f38.

📒 Files selected for processing (8)
  • apps/portal/src/app/Header.tsx (1 hunks)
  • apps/portal/src/app/ai/chat/EndpointMetadata.tsx (1 hunks)
  • apps/portal/src/app/ai/chat/handling-responses/page.mdx (1 hunks)
  • apps/portal/src/app/ai/chat/page.mdx (1 hunks)
  • apps/portal/src/app/ai/layout.tsx (1 hunks)
  • apps/portal/src/app/ai/sidebar.tsx (1 hunks)
  • apps/portal/src/components/Document/APIEndpointMeta/ApiEndpoint.tsx (4 hunks)
  • apps/portal/src/components/Document/APIEndpointMeta/common.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/portal/src/app/ai/chat/handling-responses/page.mdx
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/portal/src/app/ai/layout.tsx
  • apps/portal/src/app/ai/sidebar.tsx
  • apps/portal/src/components/Document/APIEndpointMeta/common.tsx
  • apps/portal/src/app/ai/chat/EndpointMetadata.tsx
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose

Files:

  • apps/portal/src/app/Header.tsx
  • apps/portal/src/components/Document/APIEndpointMeta/ApiEndpoint.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)

Files:

  • apps/portal/src/app/Header.tsx
  • apps/portal/src/components/Document/APIEndpointMeta/ApiEndpoint.tsx
🧠 Learnings (1)
📚 Learning: 2025-07-18T19:19:55.613Z
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to apps/{dashboard,playground-web}/**/*.{ts,tsx} : Import UI primitives from `@/components/ui/*` (Button, Input, Select, Tabs, Card, Sidebar, Badge, Separator) in dashboard and playground apps

Applied to files:

  • apps/portal/src/components/Document/APIEndpointMeta/ApiEndpoint.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Size
🔇 Additional comments (3)
apps/portal/src/app/Header.tsx (1)

145-148: Add Chat API link — looks good

New AI link correctly wires the Chat API into both desktop dropdown and mobile menu via shared aiLinks.

apps/portal/src/app/ai/chat/page.mdx (1)

39-42: Verify OpenAI client base_url and auth expectations

Please confirm:

  • base_url is correct for your OpenAI-compatible route (the OpenAI Python SDK targets /v1/chat/completions under base_url).
  • Using api_key will send Authorization: Bearer . Ensure your service accepts that in addition to x-secret-key for HTTP requests.

If the service expects the OpenAI path prefix, base_url should remain https://api.thirdweb.com (the SDK appends /v1/...). If it expects a different prefix (e.g. /ai), update base_url accordingly.

apps/portal/src/components/Document/APIEndpointMeta/ApiEndpoint.tsx (1)

77-79: Header styling changes — LGTM

Simpler header (no border-bottom) and h2 level for title work well within the page hierarchy.

@joaquim-verges joaquim-verges force-pushed the _Docs_Add_AI_Chat_API_documentation_and_endpoint_metadata branch from acf6f38 to 0554be3 Compare August 11, 2025 05:27
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground August 11, 2025 05:27 Inactive
@vercel vercel bot temporarily deployed to Preview – nebula August 11, 2025 05:27 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui August 11, 2025 05:27 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb-www August 11, 2025 05:27 Inactive
@joaquim-verges joaquim-verges merged commit be28b0c into main Aug 12, 2025
22 checks passed
@joaquim-verges joaquim-verges deleted the _Docs_Add_AI_Chat_API_documentation_and_endpoint_metadata branch August 12, 2025 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Portal Involves changes to the Portal (docs) codebase.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants