@studio8collective/patent-render 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@studio8collective/patent-render`. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses [Semantic Versioning](https://semver.org/).
4
+
5
+ ## [1.0.0] - 2026-11-13
6
+
7
+ First release.
8
+
9
+ ### Added
10
+
11
+ - `<PatentRender />` dialog: canvas, toolbox, layers, inspector and chat dock, with autosave (`onChange`) and compliance-gated embed (`onEmbed`).
12
+ - `createPatentRenderHandler()` route handler with drawer, planner and critic agents, figure-type skills (mechanical, perspective, circuit, chemical, diagram, detail, UI screen) and visual review passes.
13
+ - `llmModels()` to pin Anthropic, OpenAI or OpenRouter models per role, keyed by `PATENT_GFX_LLM_KEY`. A key whose prefix belongs to a different provider is rejected with a clear error instead of a provider 401.
14
+ - Compliance profiles for USPTO, PCT, EPO and IPO, and the deterministic `validate()` checker.
15
+ - `renderSvg()` and server-side `renderPng()` / `exportPatentPng()` at up to 600 dpi.
16
+ - Entry points: root (client), `/core` (framework-neutral), `/server`, `/server/actions`, `/theme.css`.
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ Copyright (c) 2026 Sachin Bhatnagar (studio8collective). All rights reserved.
2
+
3
+ @studio8collective/patent-render, including its source code, documentation,
4
+ compiled output and all associated materials, is the sole property of
5
+ Sachin Bhatnagar.
6
+
7
+ This software is proprietary. No license, express or implied, is granted to
8
+ use, copy, modify, merge, publish, distribute, sublicense or sell it, except
9
+ by prior written permission of Sachin Bhatnagar.
package/README.md CHANGED
@@ -1,3 +1,247 @@
1
- # Temporary Holding Version
1
+ # @studio8collective/patent-render
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ AI-assisted, editable patent drawings for React and Next.js. Users describe a figure in a sentence, an agent draws it as editable vector shapes with reference numerals and leader lines, a critic reviews the render, and a deterministic validator checks it against USPTO, PCT, EPO or IPO drawing rules before it can be embedded.
4
+
5
+ - Drop-in `<PatentRender />` dialog: canvas, layers, inspector, chat
6
+ - One route handler for the agent (Next.js App Router, or any `Request => Response` runtime)
7
+ - Swappable LLMs: Anthropic, OpenAI or any model on OpenRouter
8
+ - 300 dpi PNG export on the server, SVG everywhere
9
+ - Documents are plain JSON: store them, reopen them, diff them
10
+
11
+ > **Full Next.js guide:** [docs/nextjs.md](https://unpkg.com/@studio8collective/patent-render/docs/nextjs.md) covers styling, auth, saving and reopening figures, handling embeds, numeral consistency, server-side use, Vercel deployment and troubleshooting. It also ships in the package at `node_modules/@studio8collective/patent-render/docs/nextjs.md`. This README is the short version.
12
+
13
+ ## Requirements
14
+
15
+ | | Version |
16
+ |---|---|
17
+ | React | 19 |
18
+ | Next.js | 15 or later (App Router, for the route and server action) |
19
+ | Tailwind CSS | 4 |
20
+ | Node.js | 20 or later |
21
+
22
+ The UI uses shadcn-style design tokens (`--primary`, `--muted`, `--border`...) plus `--warning`, `--success` and `--info`. If your app already defines shadcn tokens, it inherits your theme. If not, import the bundled theme (step 3).
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ npm install @studio8collective/patent-render
28
+ ```
29
+
30
+ ## Setup
31
+
32
+ ### 1. API key
33
+
34
+ Add one key to `.env.local`. It must belong to the provider you pick in step 4.
35
+
36
+ ```bash
37
+ PATENT_GFX_LLM_KEY=sk-...
38
+ ```
39
+
40
+ ### 2. `next.config.ts`
41
+
42
+ PNG export uses a native rasteriser that must not be bundled:
43
+
44
+ ```ts
45
+ const nextConfig = {
46
+ serverExternalPackages: ["@resvg/resvg-js"],
47
+ };
48
+ export default nextConfig;
49
+ ```
50
+
51
+ ### 3. Styles
52
+
53
+ The components are styled with Tailwind classes, so Tailwind has to scan the package. In your global CSS, after `@import "tailwindcss";`:
54
+
55
+ ```css
56
+ @import "tailwindcss";
57
+ @source "../node_modules/@studio8collective/patent-render/dist";
58
+
59
+ /* Only if your app has no shadcn theme tokens of its own: */
60
+ @import "@studio8collective/patent-render/theme.css";
61
+ ```
62
+
63
+ The `@source` path is relative to the CSS file. Adjust the `../` depth if your global CSS lives deeper (e.g. `src/app/globals.css` needs `../../node_modules/...`).
64
+
65
+ ### 4. Route handler
66
+
67
+ ```ts
68
+ // app/api/patent-render/route.ts
69
+ import { createPatentRenderHandler, llmModels } from "@studio8collective/patent-render/server";
70
+
71
+ export const POST = createPatentRenderHandler({
72
+ models: llmModels({
73
+ provider: "anthropic",
74
+ drawer: "claude-opus-5-5",
75
+ planner: "claude-sonnet-5-5",
76
+ critic: "claude-sonnet-5-5",
77
+ }),
78
+ onUsage: ({ phase, usage }) => console.info("[patent-render]", phase, usage),
79
+ });
80
+ ```
81
+
82
+ Protect this route with your own auth middleware. The handler does no authentication.
83
+
84
+ ### 5. Component
85
+
86
+ `PatentRender` is a client component. Render it from a page or dialog and pass the PNG server action down from a server component:
87
+
88
+ ```tsx
89
+ // app/drawings/page.tsx (server component)
90
+ import { exportPatentPng } from "@studio8collective/patent-render/server/actions";
91
+ import { DrawingDialog } from "./DrawingDialog";
92
+
93
+ export default function Page() {
94
+ return <DrawingDialog exportPng={exportPatentPng} />;
95
+ }
96
+ ```
97
+
98
+ ```tsx
99
+ // app/drawings/DrawingDialog.tsx
100
+ "use client";
101
+ import { PatentRender, type EmbedResult } from "@studio8collective/patent-render";
102
+
103
+ export function DrawingDialog({ exportPng }: { exportPng: (doc: unknown) => Promise<{ dataUrl: string }> }) {
104
+ return (
105
+ <PatentRender
106
+ endpoint="/api/patent-render"
107
+ figureNumber="3"
108
+ jurisdiction="uspto"
109
+ context={{ title: "Wrist watch", claims: "1. A watch comprising..." }}
110
+ exportPng={exportPng}
111
+ onChange={(doc) => saveDraft(doc)}
112
+ onEmbed={(result: EmbedResult) => attachToApplication(result)}
113
+ onCancel={() => close()}
114
+ />
115
+ );
116
+ }
117
+ ```
118
+
119
+ That's a working integration. Open the page and type something like "USB-C hub with 2 USB-A ports, HDMI and an SD slot".
120
+
121
+ ## Choosing the LLM
122
+
123
+ `llmModels()` pins the provider and a model per role. The only env var is `PATENT_GFX_LLM_KEY`.
124
+
125
+ | Role | Job | Pick |
126
+ |---|---|---|
127
+ | `drawer` | Main drawing loop with many tool calls | Your strongest model |
128
+ | `planner` | Turns the user's sentence into a parts plan | Fast and cheaper is fine |
129
+ | `critic` | Looks at the rendered PNG and asks for fixes | Must accept images |
130
+
131
+ Every model must support tool calling.
132
+
133
+ ```ts
134
+ // Anthropic direct (key: sk-ant-...)
135
+ llmModels({ provider: "anthropic" }) // defaults: Opus 5.5 draws, Sonnet 5.5 plans/reviews
136
+
137
+ // Claude through OpenRouter (key: sk-or-...)
138
+ llmModels({
139
+ provider: "openrouter",
140
+ drawer: "anthropic/claude-opus-5.5",
141
+ planner: "anthropic/claude-sonnet-5.5",
142
+ critic: "anthropic/claude-sonnet-5.5",
143
+ });
144
+
145
+ // Mix vendors per role through OpenRouter (one OpenRouter key)
146
+ llmModels({
147
+ provider: "openrouter",
148
+ drawer: "openai/gpt-6-sol",
149
+ planner: "google/gemini-3.5-flash",
150
+ critic: "anthropic/claude-sonnet-5.5",
151
+ });
152
+
153
+ // OpenAI direct (key: sk-...)
154
+ llmModels({ provider: "openai", drawer: "gpt-6-sol", planner: "gpt-6-luna", critic: "gpt-6-luna" });
155
+ ```
156
+
157
+ Model id formats differ per provider: Anthropic uses `claude-opus-5-5`, OpenRouter uses `vendor/model` with dots (`anthropic/claude-opus-5.5`). Roles you omit use `DEFAULT_MODELS[provider]`. You can also pass any TanStack AI text adapter directly: `models: { drawer: myAdapter }`.
158
+
159
+ If the key is missing, the route answers `503` with a clear message instead of failing the build.
160
+
161
+ ## Entry points
162
+
163
+ | Import | Where | What |
164
+ |---|---|---|
165
+ | `@studio8collective/patent-render` | Client components | `PatentRender`, `PatentRenderEditor`, `EditorProvider`, `useEditor`, plus everything in `core` |
166
+ | `@studio8collective/patent-render/core` | Anywhere (server components, scripts, workers) | `createDocument`, `normalizeDocument`, `PatentDocument` (zod schema), `validate`, `PROFILES`, `renderSvg`, types |
167
+ | `@studio8collective/patent-render/server` | Server only | `createPatentRenderHandler`, `llmModels`, `DEFAULT_MODELS`, `renderPng` |
168
+ | `@studio8collective/patent-render/server/actions` | Server action (`"use server"`) | `exportPatentPng(document, dpi?)` |
169
+ | `@studio8collective/patent-render/theme.css` | Global CSS | Optional default theme tokens |
170
+
171
+ Use `/core` instead of the root import when you need the document model or validator in a server component: the root entry is a client module.
172
+
173
+ ## `<PatentRender />` props
174
+
175
+ | Prop | Type | Notes |
176
+ |---|---|---|
177
+ | `endpoint` | `string` | Route where you mounted the handler. Required. |
178
+ | `document` | `PatentDocument` | Reopen a saved figure. Omit for a new one. |
179
+ | `figureNumber` | `string` | Required for new figures: `"3"`, `"4A"`. |
180
+ | `jurisdiction` | `"ipo" \| "uspto" \| "pct" \| "epo"` | Rules for new figures. Default `"ipo"`. |
181
+ | `sheetLabel` | `string` | Sheet number shown top centre, e.g. `"2/5"`. |
182
+ | `context` | `PatentContext` | `title`, `claims`, `specExcerpt`, `numeralRegistry` (e.g. `{ "102": "housing" }`) so numerals stay consistent across figures. |
183
+ | `exportPng` | server action | Pass `exportPatentPng`. Without it the embed result has no PNG. |
184
+ | `onChange` | `(doc) => void` | Autosave hook. Receives the full document, including chat history. |
185
+ | `onEmbed` | `(result: EmbedResult) => void` | Required. Only reachable when the compliance check has no errors. |
186
+ | `onCancel` | `() => void` | Close the dialog. |
187
+ | `className` | `string` | Outer container classes. |
188
+
189
+ `EmbedResult`:
190
+
191
+ | Field | Notes |
192
+ |---|---|
193
+ | `document` | Full editable state. Store it to reopen the figure later. |
194
+ | `svg` | Final drawing as an SVG string. |
195
+ | `views` | `{ composite, exploded }` SVGs when the figure has an exploded view. |
196
+ | `png` | 300 dpi PNG data URL, when `exportPng` was provided. |
197
+ | `numerals` | New or changed reference numerals, to sync into the specification. |
198
+ | `complianceReport` | Validator output (warnings may remain, errors cannot). |
199
+
200
+ ## `createPatentRenderHandler` options
201
+
202
+ | Option | Default | Notes |
203
+ |---|---|---|
204
+ | `models` | Anthropic defaults | `llmModels({...})` or `{ drawer, planner, critic }` adapters. |
205
+ | `maxReviews` | `2` | Visual critic passes per run. `0` disables review. |
206
+ | `maxTurns` | `40` | Max model turns in the drawing loop. |
207
+ | `onUsage` | none | Token usage per phase (`drawer`, `planner`, `critic`). Never receives prompt or drawing content. |
208
+ | `fontFiles` | system fonts | Font file paths for PNG rendering on hosts without Arial (minimal Linux, serverless). |
209
+
210
+ ## Using the core without the UI
211
+
212
+ ```ts
213
+ import { createDocument, validate, renderSvg } from "@studio8collective/patent-render/core";
214
+ import { renderPng } from "@studio8collective/patent-render/server";
215
+
216
+ const doc = createDocument({ id: crypto.randomUUID(), figureNumber: "1", jurisdiction: "uspto" });
217
+ const report = validate(doc); // { ok, errors, warnings, jurisdiction }
218
+ const svg = renderSvg(doc); // string
219
+ const png = renderPng(doc, { dpi: 300 }); // Buffer (server only)
220
+ ```
221
+
222
+ ## Deploying
223
+
224
+ - **Vercel / serverless Linux:** Arial is usually missing. Ship a sans font with your app and pass `fontFiles: [path]` to the handler so PNG text renders.
225
+ - **Timeouts:** a full draw plus reviews can take a few minutes. Make sure the route's max duration allows it (`export const maxDuration = 300;` in the route file on Vercel).
226
+ - **Privacy:** prompts and drawings go to the LLM provider you configured and nowhere else. `onUsage` only reports token counts.
227
+
228
+ ## Troubleshooting
229
+
230
+ | Symptom | Fix |
231
+ |---|---|
232
+ | Editor renders unstyled | Missing `@source` line, or wrong `../` depth in it. |
233
+ | Colours look off or invisible | Your app has no shadcn tokens. Import `theme.css`. |
234
+ | `503 PatentRender model is not configured` | `PATENT_GFX_LLM_KEY` is missing, or belongs to a different provider. |
235
+ | Build error mentioning `resvg` or `.node` files | Add `@resvg/resvg-js` to `serverExternalPackages`. |
236
+ | "Functions cannot be passed to Client Components" | Import `exportPatentPng` from `/server/actions`, not `/server`, and pass it from a server component. |
237
+ | PNG has boxes instead of text | Pass `fontFiles` to the handler. |
238
+
239
+ ## Versioning
240
+
241
+ Semantic versioning. Breaking changes to props, the handler options or the document schema bump the major version, and `normalizeDocument` keeps older saved documents loadable. See [CHANGELOG.md](./CHANGELOG.md).
242
+
243
+ ## Author and license
244
+
245
+ Created and owned by **Sachin Bhatnagar** (studio8collective).
246
+
247
+ Copyright (c) 2026 Sachin Bhatnagar. All rights reserved. This is proprietary software: no license to use, copy, modify or distribute it is granted except by prior written permission of the author. See [LICENSE](./LICENSE).