Skip to content

Define Leadtype core and adapter boundary#51

Merged
KayleeWilliams merged 5 commits into
mainfrom
KayleeWilliams/p0-define-leadtype-core-and-framework-adapter-bo
May 15, 2026
Merged

Define Leadtype core and adapter boundary#51
KayleeWilliams merged 5 commits into
mainfrom
KayleeWilliams/p0-define-leadtype-core-and-framework-adapter-bo

Conversation

@KayleeWilliams
Copy link
Copy Markdown
Collaborator

@KayleeWilliams KayleeWilliams commented May 14, 2026

Summary

  • Adds the first thin Next.js adapter surfaces: leadtype/next and leadtype/next/client.
  • Documents and enforces the core/framework adapter boundary, including planned native shapes for Nuxt, SvelteKit, Astro, TanStack Start, Vue search, and Svelte search.
  • Updates package exports, Rollup entries, README positioning, framework recipes, and release notes.
  • Merges current main and preserves the new leadtype/i18n package surface alongside the Next adapter exports.

Closes #40.

Validation

  • bun test packages/leadtype/src/internal/package-surface.test.ts
  • bun test packages/leadtype/src/next/next.test.ts packages/leadtype/src/next/client.test.ts
  • bun test packages/leadtype/src/internal/package-surface.test.ts packages/leadtype/src/i18n/i18n.test.ts packages/leadtype/src/next/next.test.ts packages/leadtype/src/next/client.test.ts
  • bun run --filter leadtype check-types
  • bun x ultracite check
  • bun run --filter leadtype build
  • Pre-commit full test suite after merge: 232 tests passing

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b21c802e-e15f-4d4a-a933-02fc830d4e0e

📥 Commits

Reviewing files that changed from the base of the PR and between cf13ecf and b9f9fef.

📒 Files selected for processing (1)
  • packages/leadtype/src/next/index.ts
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use explicit types for function parameters and return values when they enhance clarity
Prefer unknown over any when the type is genuinely unknown
Use const assertions (as const) for immutable values and literal types
Leverage TypeScript's type narrowing instead of type assertions

Files:

  • packages/leadtype/src/next/index.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{js,ts,jsx,tsx}: Use meaningful variable names instead of magic numbers - extract constants with descriptive names
Use arrow functions for callbacks and short functions
Prefer for...of loops over .forEach() and indexed for loops
Use optional chaining (?.) and nullish coalescing (??) for safer property access
Prefer template literals over string concatenation
Use destructuring for object and array assignments
Use const by default, let only when reassignment is needed, never var
Always await promises in async functions - don't forget to use the return value
Use async/await syntax instead of promise chains for better readability
Handle errors appropriately in async code with try-catch blocks
Don't use async functions as Promise executors
Remove console.log, debugger, and alert statements from production code
Throw Error objects with descriptive messages, not strings or other values
Use try-catch blocks meaningfully - don't catch errors just to rethrow them
Prefer early returns over nested conditionals for error cases
Extract complex conditions into well-named boolean variables
Use early returns to reduce nesting
Prefer simple conditionals over nested ternary operators
Don't use eval() or assign directly to document.cookie
Avoid spread syntax in accumulators within loops
Use top-level regex literals instead of creating them in loops
Prefer specific imports over namespace imports
Use descriptive names for functions, variables, and types for meaningful naming
Add comments for complex logic, but prefer self-documenting code

Files:

  • packages/leadtype/src/next/index.ts
**/index.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid barrel files (index files that re-export everything)

Files:

  • packages/leadtype/src/next/index.ts
🔇 Additional comments (7)
packages/leadtype/src/next/index.ts (7)

1-14: LGTM!


16-70: LGTM!


72-87: LGTM!


89-105: LGTM!


107-113: LGTM!


115-138: LGTM!


140-180: LGTM!


📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Next.js App Router adapter: server helpers for static params, page loading, and serving docs/markdown (supports returning raw markdown)
    • Client-side search: framework-free search client with lazy-loaded indexes, BM25 ranking, and a React hook for debounced search state
  • Documentation

    • New architecture reference clarifying core/adapter boundaries and adapter requirements
    • Expanded integration guides and supported frameworks (Next, Nuxt, SvelteKit, Svelte, Vue)
  • Tests

    • Added tests enforcing adapter boundaries and search/client behaviors

Walkthrough

This PR introduces the leadtype/next Next.js App Router adapter and formalizes the core/adapter architectural boundary. It adds three server-only helpers, a React search hook, and framework-free search client utilities, backed by new architecture documentation and boundary-enforcement tests.

Changes

Next.js Adapter + Core/Adapter Boundary

Layer / File(s) Summary
Architecture Reference & Core/Adapter Boundary Enforcement
docs/reference/architecture.mdx, docs/methodology.mdx, packages/leadtype/src/internal/package-surface.test.ts
Documents the three-layer architecture (core, search runtime, framework adapters), establishes naming/dependency/DOM constraints, and adds tests that ensure core modules don't import banned framework runtimes and adapters don't import each other.
Next.js Server-Only Adapter Implementation
packages/leadtype/src/next/index.ts, packages/leadtype/src/next/next.test.ts
Adds createGenerateStaticParams, createLoadPageData, and createDocsRouteHandler with default filesystem markdown reader and path-escape checks; includes tests for route handler and loader behavior.
Next.js Client Search Utilities
packages/leadtype/src/next/client.ts, packages/leadtype/src/next/client.test.ts
Adds createSearchClient (lazy artifact loading, caching, BM25 search) and useLeadtypeSearch React hook (debounced searches, stale-result protection), plus tests covering artifact loading and error conditions.
Build Configuration & Package Metadata
packages/leadtype/package.json, packages/leadtype/rollup.config.ts
Exports ./next and ./next/client subpaths, marks react as an optional peer dependency (>=18.0.0), adds dev deps for React types, and updates Rollup entries to build the new bundles.
Documentation & Communication
.changeset/leadtype-next-adapter.md, docs/build/use-the-source-primitive.mdx, docs/docs.config.ts, packages/leadtype/README.md, README.md, docs/methodology.mdx
Adds a release note and architecture reference, updates examples and wiring guidance to prefer adapters, documents new adapter entry points, and clarifies ownership boundaries in methodology docs.

Sequence Diagram(s)

sequenceDiagram
  participant Request
  participant RouteHandler as createDocsRouteHandler
  participant Agent as createAgentMarkdownResponse
  participant Reader as readMarkdownFile

  Request->>RouteHandler: incoming Request + headers
  RouteHandler->>Agent: createAgentMarkdownResponse(requestHeaders, manifest)
  Agent->>Reader: request markdown artifact (manifest target)
  Reader-->>Agent: markdown string | null
  Agent-->>RouteHandler: AgentMarkdownResponse | null
  RouteHandler-->>Request: HTTP Response (markdown or 404)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • inthhq/leadtype#35: Prior core source primitives (DocsSource APIs) that the Next adapter helpers use.
  • inthhq/leadtype#19: Related Agent Readability runtime/markdown handling referenced by createDocsRouteHandler.
  • inthhq/leadtype#21: Earlier package-surface tightening that overlaps with the new boundary tests.

"I'm a rabbit in code with whiskers bright,
I hop through adapters deep at night.
I guard the core from framework spills,
I fetch the index, race the mills.
Hooray — new routes and search take flight! 🐇"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.32% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: defining the core and adapter boundary for the Leadtype framework, which is the central objective of this PR.
Description check ✅ Passed The description comprehensively relates to the changeset, covering the Next.js adapter implementation, core/adapter boundary enforcement, documentation, and validation steps performed.
Linked Issues check ✅ Passed The PR successfully implements all key objectives from issue #40: documents the core/adapter boundary in architecture.mdx, enforces zero framework dependencies in core via package-surface tests, provides native Next.js conventions, and adds comprehensive framework recipes and adapter implementations.
Out of Scope Changes check ✅ Passed All code changes are directly related to defining the core/adapter boundary and implementing the first Next.js adapter as specified in issue #40; no unrelated or out-of-scope modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch KayleeWilliams/p0-define-leadtype-core-and-framework-adapter-bo

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Comment @coderabbitai help to get the list of available commands and usage tips.

@KayleeWilliams KayleeWilliams marked this pull request as ready for review May 14, 2026 22:25
…ine-leadtype-core-and-framework-adapter-bo

# Conflicts:
#	packages/leadtype/package.json
#	packages/leadtype/rollup.config.ts
#	packages/leadtype/src/internal/package-surface.test.ts
@KayleeWilliams KayleeWilliams marked this pull request as draft May 14, 2026 22:27
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0c70fde963

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

requestOrigin: url.origin,
cacheControl: config.cacheControl,
});
return response ?? new Response(null, { status: 404 });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Don’t return 404 for HTML docs requests

When this handler is mounted as documented on app/docs/[[...slug]]/route.ts, a normal browser GET with Accept: text/html makes createAgentMarkdownResponse return null, so this line returns a concrete 404. Next route handlers do not fall through to the page renderer after a Response, so every HTML docs page under that catch-all is served as 404 while only markdown/agent requests work.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@pullfrog pullfrog Bot left a comment

Choose a reason for hiding this comment

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

Caution

The documented Next.js recipe is broken: route.ts and page.tsx cannot coexist at the same App Router segment — next dev / next build errors with a route conflict. Both the docs and the JSDoc need a different layout (e.g. a sub-segment like raw/route.ts) before users can copy-paste this. A separate high-severity issue is that "use client" is silently stripped from the bundled dist/next/client.js.

TL;DR — Introduces the leadtype/next (server) and leadtype/next/client (React hook) adapter subpaths, formalises the core/adapter boundary in a new architecture doc, and enforces it with import-graph tests. The boundary doctrine and the surface tests are solid; the Next.js wiring shipped in the recipes does not match what Next.js allows.

Key changes

  • Add leadtype/next server adaptercreateGenerateStaticParams, createLoadPageData, and createDocsRouteHandler factories with no React imports.
  • Add leadtype/next/client React hookuseLeadtypeSearch plus a framework-free createSearchClient, both backed by a module-level artifact cache.
  • Document the core/adapter boundary — new docs/reference/architecture.mdx defining flat naming, no rendered DOM, and the optional-peer dependency rule; planned shapes for Nuxt/SvelteKit/Astro/TanStack Start named without exporting them yet.
  • Enforce the boundary in testspackage-surface.test.ts now scans every src/ file for banned framework runtime imports and cross-adapter imports.
  • Wire the new subpaths through the toolchainrollup.config.ts entries, package.json#exports, optional peer + dev react / @types/react, README and recipe updates.

Summary | 15 files | 1 commit | base: mainKayleeWilliams/p0-define-leadtype-core-and-framework-adapter-bo


Boundary enforcement is the strongest part of the PR

Before: the core/adapter contract was implicit — fumadocs was the only adapter, and there was no scan preventing core code from importing React or other framework runtimes.
After: package-surface.test.ts walks every non-test src/ file, flags banned specifiers in non-adapter dirs, and flags adapter-to-adapter relative imports.

The combination of the architecture doc, the optional-peer scheme, and the import-graph tests makes the contract enforceable as new adapters arrive. One small follow-up worth filing separately: the regex matches only static import/export statements, so a future dynamic import("react") in core would slip past the scan.

docs/reference/architecture.mdx · packages/leadtype/src/internal/package-surface.test.ts


Next.js recipe needs a different file layout

Before: users wired markdown content negotiation manually.
After: the recipe tells users to drop a route.ts next to page.tsx at app/docs/[[...slug]]/, but Next.js disallows that exact layout, so the recipe fails at next dev.

The Next.js Route Handlers docs state verbatim: "There cannot be a route.js file at the same route segment level as page.js" (source). The fix is to put the handler under a sub-segment (e.g. app/docs/[[...slug]]/raw/route.ts) or scope the markdown route to a different path entirely. The factory itself (createDocsRouteHandler in src/next/index.ts) is fine — only the documented placement and the JSDoc need to change.

docs/build/use-the-source-primitive.mdx · packages/leadtype/src/next/index.ts


Client bundle drops the "use client" directive

Before: N/A — new file.
After: src/next/client.ts carries "use client" at the top, but rollup.config.ts bundles in non-preserveModules mode with no rollup-plugin-preserve-directives, so the published dist/next/client.js will not retain the directive.

Rollup and esbuild both strip top-level string directives in bundled output. Without "use client" on the published file, consumers who don't already nest the import inside their own "use client" boundary will hit the RSC "hooks in server components" error. The canonical fix is rollup-plugin-preserve-directives together with preserveModules: true, or splitting the client entry into its own preserve-modules pass.

packages/leadtype/rollup.config.ts · packages/leadtype/src/next/client.ts

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using Claude Opus𝕏

Comment on lines +88 to 97
Add a sibling `route.ts` to serve raw markdown and content negotiation:

```ts title="app/docs/[[...slug]]/route.ts"
import { createDocsRouteHandler } from "leadtype/next";
import manifest from "@/generated/agent-readability.json" with { type: "json" };

export const GET = createDocsRouteHandler({
manifest: { ...manifest, version: 1 } as const,
});
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This recipe will not run. Next.js's App Router rejects a route.ts at the same segment as page.tsxnext dev and next build error out with a route conflict (docs: "There cannot be a route.js file at the same route segment level as page.js", https://nextjs.org/docs/app/getting-started/route-handlers).

Move the handler to a sub-segment, e.g. app/docs/[[...slug]]/raw/route.ts, and update the JSDoc example in packages/leadtype/src/next/index.ts to match.

Comment thread packages/leadtype/src/next/index.ts Outdated
*
* ```ts title="app/docs/[[...slug]]/route.ts"
* import { createDocsRouteHandler } from "leadtype/next";
* import manifest from "@/generated/agent-readability.json" assert { type: "json" };
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Two issues in this JSDoc block:

  1. The example places route.ts alongside page.tsx at the same segment — Next.js disallows this (see the same comment on the docs recipe).
  2. assert { type: "json" } is the deprecated import-attribute syntax. TS 5.3+ warns on it, and the mdx recipe added in this same PR uses the current with { type: "json" } form. Pick one — preferably with, since package.json declares typescript >=5.0 and the docs already use it.

Comment on lines +10 to +11
"next/index": "src/next/index.ts",
"next/client": "src/next/client.ts",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

src/next/client.ts starts with "use client", but this Rollup config bundles in non-preserveModules mode without rollup-plugin-preserve-directives, so both Rollup and esbuild will strip the directive from dist/next/client.js. Consumers who import useLeadtypeSearch from a server component will hit the RSC hooks-in-server-components error.

Add rollup-plugin-preserve-directives and set preserveModules: true (at minimum for the client entries), or split the client entry into its own build pass that preserves modules.

Comment on lines +62 to +66
/**
* Directory where the generate CLI wrote artifacts. Default: `./public`
* (resolved relative to `process.cwd()` at request time).
*/
publicDir?: string;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The JSDoc says publicDir is "resolved relative to process.cwd() at request time", but createDefaultMarkdownReader calls path.resolve(publicDir) once at handler-creation time (line 114) — cwd() is captured at module evaluation, not per request. Either defer the path.resolve into the returned async function or update the comment to say "at handler creation time".

Copy link
Copy Markdown

@pullfrog pullfrog Bot left a comment

Choose a reason for hiding this comment

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

Note

Incremental review: commit 45462ce is a clean merge of main that brings the previously-shipped leadtype/i18n subpath into the exports list, the Rollup entries, and the surface test. The conflict resolution between the new ./i18n export and the new ./next / ./next/client exports is correct. The four findings from the prior review (Next.js route.ts/page.tsx conflict, stripped "use client" directive, assert vs with syntax, and the publicDir JSDoc) still stand.

Pullfrog  | View workflow run | Using Claude Opus𝕏

Copy link
Copy Markdown

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/leadtype/src/internal/package-surface.test.ts`:
- Line 2: The test builds srcRoot using a URL.pathname which breaks on Windows
and for percent-encoded names; import and use fileURLToPath from "node:url" and
replace the URL.pathname usage when computing srcRoot (the variable referenced
in package-surface.test.ts) so you convert the URL to a proper platform path
(e.g., call fileURLToPath on the URL you currently use) instead of reading
.pathname or feeding raw URL path to glob(); update any references that
construct new URL(...) for the project root to use fileURLToPath(new URL(...,
import.meta.url)) accordingly.
- Around line 32-33: The current IMPORT_PATTERN only matches static
import/export and misses dynamic imports and CommonJS requires, so update
extractImportSpecifiers() to also detect dynamic import() calls and require(...)
calls: extend or add patterns alongside IMPORT_PATTERN to capture module strings
inside import("...") and require("...") (and their single-quoted variants), and
ensure these matches are fed into the same downstream boundary-check logic
(refer to IMPORT_PATTERN and the extractImportSpecifiers function name to locate
where to add the extra regexes/pattern handling).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c4f6b197-e000-40f1-9ba8-1d44c9dd2cf0

📥 Commits

Reviewing files that changed from the base of the PR and between c7fcbf6 and 45462ce.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (14)
  • .changeset/leadtype-next-adapter.md
  • README.md
  • docs/build/use-the-source-primitive.mdx
  • docs/docs.config.ts
  • docs/methodology.mdx
  • docs/reference/architecture.mdx
  • packages/leadtype/README.md
  • packages/leadtype/package.json
  • packages/leadtype/rollup.config.ts
  • packages/leadtype/src/internal/package-surface.test.ts
  • packages/leadtype/src/next/client.test.ts
  • packages/leadtype/src/next/client.ts
  • packages/leadtype/src/next/index.ts
  • packages/leadtype/src/next/next.test.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use explicit types for function parameters and return values when they enhance clarity
Prefer unknown over any when the type is genuinely unknown
Use const assertions (as const) for immutable values and literal types
Leverage TypeScript's type narrowing instead of type assertions

Files:

  • docs/docs.config.ts
  • packages/leadtype/rollup.config.ts
  • packages/leadtype/src/next/client.test.ts
  • packages/leadtype/src/next/next.test.ts
  • packages/leadtype/src/next/index.ts
  • packages/leadtype/src/next/client.ts
  • packages/leadtype/src/internal/package-surface.test.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{js,ts,jsx,tsx}: Use meaningful variable names instead of magic numbers - extract constants with descriptive names
Use arrow functions for callbacks and short functions
Prefer for...of loops over .forEach() and indexed for loops
Use optional chaining (?.) and nullish coalescing (??) for safer property access
Prefer template literals over string concatenation
Use destructuring for object and array assignments
Use const by default, let only when reassignment is needed, never var
Always await promises in async functions - don't forget to use the return value
Use async/await syntax instead of promise chains for better readability
Handle errors appropriately in async code with try-catch blocks
Don't use async functions as Promise executors
Remove console.log, debugger, and alert statements from production code
Throw Error objects with descriptive messages, not strings or other values
Use try-catch blocks meaningfully - don't catch errors just to rethrow them
Prefer early returns over nested conditionals for error cases
Extract complex conditions into well-named boolean variables
Use early returns to reduce nesting
Prefer simple conditionals over nested ternary operators
Don't use eval() or assign directly to document.cookie
Avoid spread syntax in accumulators within loops
Use top-level regex literals instead of creating them in loops
Prefer specific imports over namespace imports
Use descriptive names for functions, variables, and types for meaningful naming
Add comments for complex logic, but prefer self-documenting code

Files:

  • docs/docs.config.ts
  • packages/leadtype/rollup.config.ts
  • packages/leadtype/src/next/client.test.ts
  • packages/leadtype/src/next/next.test.ts
  • packages/leadtype/src/next/index.ts
  • packages/leadtype/src/next/client.ts
  • packages/leadtype/src/internal/package-surface.test.ts
**/*.{test,spec}.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{test,spec}.{js,ts,jsx,tsx}: Write assertions inside it() or test() blocks
Avoid done callbacks in async tests - use async/await instead
Don't use .only or .skip in committed code
Keep test suites reasonably flat - avoid excessive describe nesting

Files:

  • packages/leadtype/src/next/client.test.ts
  • packages/leadtype/src/next/next.test.ts
  • packages/leadtype/src/internal/package-surface.test.ts
**/index.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid barrel files (index files that re-export everything)

Files:

  • packages/leadtype/src/next/index.ts
🪛 LanguageTool
packages/leadtype/README.md

[grammar] ~68-~68: Ensure spelling is correct
Context: ...pe/search/svelte are tracked under [#41](https://github.com/inthhq/leadtype/issues/41) / [#45](https://github.com/inthhq/leadtype/issues/45)). The leadtypebinary wrapsgenerate` a...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

docs/reference/architecture.mdx

[style] ~41-~41: Consider using “who” when you are referring to a person instead of an object.
Context: ...optional peer dependency*. A consumer that doesn't use fumadocs never installs fum...

(THAT_WHO)


[style] ~41-~41: Consider using “who” when you are referring to a person instead of an object.
Context: ...ever installs fumadocs-core; a consumer that doesn't use Next never installs React. ...

(THAT_WHO)


[grammar] ~56-~56: Ensure spelling is correct
Context: ...h artifacts. | These are future public surfaces, not hidden exports. Until they ship, u...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🪛 markdownlint-cli2 (0.22.1)
.changeset/leadtype-next-adapter.md

[warning] 5-5: First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)

🔇 Additional comments (34)
packages/leadtype/package.json (1)

40-47: LGTM!

Also applies to: 137-137, 141-141, 156-156, 181-183

packages/leadtype/rollup.config.ts (1)

11-12: LGTM!

.changeset/leadtype-next-adapter.md (1)

1-11: LGTM!

docs/docs.config.ts (1)

23-23: LGTM!

README.md (1)

26-26: LGTM!

Also applies to: 66-66

packages/leadtype/README.md (1)

64-68: LGTM!

docs/build/use-the-source-primitive.mdx (1)

43-44: LGTM!

Also applies to: 62-66, 69-71, 75-75, 86-86, 88-99, 209-214, 215-233, 247-248, 260-260, 274-274

packages/leadtype/src/next/index.ts (7)

36-49: LGTM!


51-76: LGTM!


84-91: LGTM!


97-101: LGTM!


103-109: LGTM!


111-134: LGTM!


145-168: LGTM!

packages/leadtype/src/next/next.test.ts (4)

12-38: LGTM!


40-56: LGTM!


58-124: LGTM!


126-200: LGTM!

packages/leadtype/src/next/client.ts (9)

1-40: LGTM!


42-69: LGTM!


71-79: LGTM!


81-110: LGTM!


117-149: LGTM!


151-169: LGTM!


178-218: LGTM!


220-261: LGTM!


263-264: LGTM!

packages/leadtype/src/next/client.test.ts (5)

9-39: LGTM!


41-53: LGTM!


55-66: LGTM!


68-141: LGTM!


143-165: LGTM!

docs/reference/architecture.mdx (1)

1-93: LGTM!

docs/methodology.mdx (1)

27-27: LGTM!

Also applies to: 35-36

Comment thread packages/leadtype/src/internal/package-surface.test.ts
Comment thread packages/leadtype/src/internal/package-surface.test.ts
@KayleeWilliams KayleeWilliams marked this pull request as ready for review May 15, 2026 00:24
@pullfrog
Copy link
Copy Markdown

pullfrog Bot commented May 15, 2026

API Error: Repeated 529 Overloaded errors · check status.claude.com

Pullfrog  | Rerun failed job ➔View workflow run | via Pullfrog | Using Claude Opus𝕏

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bd9b314f96

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +88 to +90
Add a sibling `route.ts` to serve raw markdown and content negotiation:

```ts title="app/docs/[[...slug]]/route.ts"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Don’t document a sibling route.ts for the docs page

In the documented Next App Router setup, this route.ts is added in the same app/docs/[[...slug]] segment as the preceding page.tsx, but Next does not allow a route handler and a page at the same route segment level. Consumers following the recommended adapter path will hit a routing/build error before markdown negotiation can work; the handler needs to be mounted at a different segment or implemented via middleware/proxy instead.

Useful? React with 👍 / 👎.

@@ -0,0 +1,317 @@
"use client";

import { useCallback, useEffect, useRef, useState } from "react";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Split the vanilla client from the React hook

When consumers use the documented createSearchClient in a worker, plain script, or non-React web component, this top-level React import is resolved before they ever access the hook. Because React is only an optional peer, installs that only want the “framework-free” factory can fail with a missing react module; the vanilla fetch/search client needs to live in a subpath/module that does not import React.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@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: 1

♻️ Duplicate comments (1)
packages/leadtype/src/next/index.ts (1)

145-148: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

JSDoc example still suggests invalid Next.js route placement.

The remark says to place the handler "next to the matching page.tsx," but Next.js App Router does not allow both route.ts and page.tsx at the same segment—they are mutually exclusive. Either remove the reference to page.tsx or clarify that the route handler should be at a path that does not have a page.tsx.

📝 Suggested JSDoc fix
  * `@remarks`
- * Place the generated handler at `app/docs/[[...slug]]/route.ts` next to the
- * matching `page.tsx`. It returns markdown when the request is agent-readable
+ * Place the generated handler at `app/docs/[[...slug]]/route.ts`. It returns markdown when the request is agent-readable
  * and a 404 response otherwise.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/leadtype/src/next/index.ts` around lines 145 - 148, Update the JSDoc
remark that currently instructs to "Place the generated handler at
`app/docs/[[...slug]]/route.ts` next to the matching `page.tsx`": replace the
phrase about being "next to the matching `page.tsx`" with a clear statement that
the route handler must be placed in a segment that does not have a `page.tsx`
(or simply remove the `page.tsx` reference), so the remark unambiguously
indicates the handler should be in a path without a `page.tsx` (edit the remark
block above the generated handler documentation in the JSDoc).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/leadtype/src/next/index.ts`:
- Around line 169-171: The header-copy loop in index.ts that iterates over
request.headers and assigns to the headers object can be simplified; replace the
manual forEach loop with a single assignment using
Object.fromEntries(request.headers) (or
Object.fromEntries(request.headers.entries())) to produce the plain object,
i.e., set headers = Object.fromEntries(request.headers) where headers and
request.headers are referenced.

---

Duplicate comments:
In `@packages/leadtype/src/next/index.ts`:
- Around line 145-148: Update the JSDoc remark that currently instructs to
"Place the generated handler at `app/docs/[[...slug]]/route.ts` next to the
matching `page.tsx`": replace the phrase about being "next to the matching
`page.tsx`" with a clear statement that the route handler must be placed in a
segment that does not have a `page.tsx` (or simply remove the `page.tsx`
reference), so the remark unambiguously indicates the handler should be in a
path without a `page.tsx` (edit the remark block above the generated handler
documentation in the JSDoc).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 377b5403-3d27-4e86-9255-a507f2205aa7

📥 Commits

Reviewing files that changed from the base of the PR and between 45462ce and bd9b314.

📒 Files selected for processing (2)
  • packages/leadtype/src/next/client.ts
  • packages/leadtype/src/next/index.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use explicit types for function parameters and return values when they enhance clarity
Prefer unknown over any when the type is genuinely unknown
Use const assertions (as const) for immutable values and literal types
Leverage TypeScript's type narrowing instead of type assertions

Files:

  • packages/leadtype/src/next/index.ts
  • packages/leadtype/src/next/client.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{js,ts,jsx,tsx}: Use meaningful variable names instead of magic numbers - extract constants with descriptive names
Use arrow functions for callbacks and short functions
Prefer for...of loops over .forEach() and indexed for loops
Use optional chaining (?.) and nullish coalescing (??) for safer property access
Prefer template literals over string concatenation
Use destructuring for object and array assignments
Use const by default, let only when reassignment is needed, never var
Always await promises in async functions - don't forget to use the return value
Use async/await syntax instead of promise chains for better readability
Handle errors appropriately in async code with try-catch blocks
Don't use async functions as Promise executors
Remove console.log, debugger, and alert statements from production code
Throw Error objects with descriptive messages, not strings or other values
Use try-catch blocks meaningfully - don't catch errors just to rethrow them
Prefer early returns over nested conditionals for error cases
Extract complex conditions into well-named boolean variables
Use early returns to reduce nesting
Prefer simple conditionals over nested ternary operators
Don't use eval() or assign directly to document.cookie
Avoid spread syntax in accumulators within loops
Use top-level regex literals instead of creating them in loops
Prefer specific imports over namespace imports
Use descriptive names for functions, variables, and types for meaningful naming
Add comments for complex logic, but prefer self-documenting code

Files:

  • packages/leadtype/src/next/index.ts
  • packages/leadtype/src/next/client.ts
**/index.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid barrel files (index files that re-export everything)

Files:

  • packages/leadtype/src/next/index.ts
🔇 Additional comments (2)
packages/leadtype/src/next/index.ts (1)

1-14: LGTM!

Also applies to: 16-87, 89-138, 160-183

packages/leadtype/src/next/client.ts (1)

1-317: LGTM!

Comment thread packages/leadtype/src/next/index.ts Outdated
Copy link
Copy Markdown

@pullfrog pullfrog Bot left a comment

Choose a reason for hiding this comment

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

No new issues. Reviewed the following changes:

  • Tightened the package-surface.test.ts boundary scan to also flag dynamic import(...) and require(...) specifiers, and switched srcRoot to fileURLToPath so the scan resolves correctly on Windows.
  • Reworked leadtype/next and leadtype/next/client JSDoc into per-symbol blocks with @param, @defaultValue, @remarks, and @example tags.
  • Corrected the createDocsRouteHandler JSDoc to require a route segment without a sibling page.tsx, swapped the import-attributes example from assert to with, and dropped the inaccurate "resolved at request time" claim on publicDir.
  • Replaced the headers forEach accumulator in the route handler with Object.fromEntries(request.headers).

Pullfrog  | Fix it ➔View workflow run | Using Claude Opus𝕏

@KayleeWilliams KayleeWilliams merged commit e923e9f into main May 15, 2026
3 checks passed
@KayleeWilliams KayleeWilliams deleted the KayleeWilliams/p0-define-leadtype-core-and-framework-adapter-bo branch May 15, 2026 01:13
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.

[P0] Define Leadtype core and framework adapter boundary

1 participant