@studio8collective/patent-render 1.0.0 → 1.1.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.
@@ -2,134 +2,175 @@
2
2
  "use server";
3
3
 
4
4
  // ../../src/patent-render/schema/document.ts
5
+ import { z as z2 } from "zod";
6
+
7
+ // ../../src/patent-render/schema/plan.ts
5
8
  import { z } from "zod";
9
+ var FigureType = z.enum([
10
+ "flowchart",
11
+ "blockDiagram",
12
+ "mechanical2d",
13
+ "uiScreen",
14
+ "perspective3d",
15
+ "circuit",
16
+ "chemical"
17
+ ]);
18
+ var FigurePlan = z.object({
19
+ figureType: FigureType,
20
+ /** e.g. "Cross-sectional view taken along line A-A of FIG. 2" */
21
+ view: z.string(),
22
+ summary: z.string(),
23
+ /**
24
+ * Full generation spec: overall form and proportions (mm), every component's
25
+ * shape, position and relationships, counts, surface details and what faces
26
+ * the viewer. Written so a draftsperson can draw without guessing.
27
+ */
28
+ spec: z.string().default(""),
29
+ components: z.array(z.object({
30
+ numeral: z.string(),
31
+ name: z.string(),
32
+ description: z.string().optional(),
33
+ reused: z.boolean().default(false)
34
+ // numeral came from the host registry
35
+ })),
36
+ layers: z.array(z.object({ id: z.string(), name: z.string() })),
37
+ notes: z.array(z.string()).default([])
38
+ });
39
+ var DrawingStyle = z.enum(["standard", "detailed", "minimal"]);
40
+ var GenerationPrefs = z.object({
41
+ figureType: FigureType.optional(),
42
+ // undefined = let the planner decide
43
+ style: DrawingStyle.default("standard")
44
+ });
45
+
46
+ // ../../src/patent-render/schema/document.ts
6
47
  function vec(n) {
7
- return z.array(z.number()).length(n);
48
+ return z2.array(z2.number()).length(n);
8
49
  }
9
50
  var Point = vec(2);
10
- var StrokeStyle = z.enum(["solid", "dashed", "centre", "phantom"]);
11
- var Stroke = z.object({
12
- width: z.number().positive().default(0.35),
51
+ var StrokeStyle = z2.enum(["solid", "dashed", "centre", "phantom"]);
52
+ var Stroke = z2.object({
53
+ width: z2.number().positive().default(0.35),
13
54
  style: StrokeStyle.default("solid")
14
55
  });
15
- var Fill = z.enum(["none", "black", "white"]);
56
+ var Fill = z2.enum(["none", "black", "white"]);
16
57
  var base = {
17
- id: z.string().min(1),
18
- name: z.string().optional(),
58
+ id: z2.string().min(1),
59
+ name: z2.string().optional(),
19
60
  /** Degrees, clockwise, about the item's bounding-box centre. */
20
- rotation: z.number().default(0),
21
- locked: z.boolean().default(false),
22
- hidden: z.boolean().default(false)
61
+ rotation: z2.number().default(0),
62
+ locked: z2.boolean().default(false),
63
+ hidden: z2.boolean().default(false)
23
64
  };
24
65
  var stroked = { stroke: Stroke.default({ width: 0.35, style: "solid" }) };
25
- var LineItem = z.object({ ...base, ...stroked, type: z.literal("line"), a: Point, b: Point });
26
- var PolylineItem = z.object({
66
+ var LineItem = z2.object({ ...base, ...stroked, type: z2.literal("line"), a: Point, b: Point });
67
+ var PolylineItem = z2.object({
27
68
  ...base,
28
69
  ...stroked,
29
- type: z.literal("polyline"),
30
- points: z.array(Point).min(2),
31
- closed: z.boolean().default(false),
70
+ type: z2.literal("polyline"),
71
+ points: z2.array(Point).min(2),
72
+ closed: z2.boolean().default(false),
32
73
  fill: Fill.default("none")
33
74
  });
34
- var PathItem = z.object({ ...base, ...stroked, type: z.literal("path"), d: z.string().min(1), fill: Fill.default("none") });
35
- var RectItem = z.object({
75
+ var PathItem = z2.object({ ...base, ...stroked, type: z2.literal("path"), d: z2.string().min(1), fill: Fill.default("none") });
76
+ var RectItem = z2.object({
36
77
  ...base,
37
78
  ...stroked,
38
- type: z.literal("rect"),
39
- x: z.number(),
40
- y: z.number(),
41
- w: z.number().positive(),
42
- h: z.number().positive(),
43
- radius: z.number().min(0).default(0),
79
+ type: z2.literal("rect"),
80
+ x: z2.number(),
81
+ y: z2.number(),
82
+ w: z2.number().positive(),
83
+ h: z2.number().positive(),
84
+ radius: z2.number().min(0).default(0),
44
85
  fill: Fill.default("none")
45
86
  });
46
- var EllipseItem = z.object({
87
+ var EllipseItem = z2.object({
47
88
  ...base,
48
89
  ...stroked,
49
- type: z.literal("ellipse"),
50
- cx: z.number(),
51
- cy: z.number(),
52
- rx: z.number().positive(),
53
- ry: z.number().positive(),
90
+ type: z2.literal("ellipse"),
91
+ cx: z2.number(),
92
+ cy: z2.number(),
93
+ rx: z2.number().positive(),
94
+ ry: z2.number().positive(),
54
95
  fill: Fill.default("none")
55
96
  });
56
- var ArcItem = z.object({
97
+ var ArcItem = z2.object({
57
98
  ...base,
58
99
  ...stroked,
59
- type: z.literal("arc"),
60
- cx: z.number(),
61
- cy: z.number(),
62
- r: z.number().positive(),
100
+ type: z2.literal("arc"),
101
+ cx: z2.number(),
102
+ cy: z2.number(),
103
+ r: z2.number().positive(),
63
104
  /** Degrees, 0 = +x axis, clockwise (SVG convention). */
64
- start: z.number(),
65
- end: z.number()
105
+ start: z2.number(),
106
+ end: z2.number()
66
107
  });
67
- var TextAnchor = z.enum(["start", "middle", "end"]);
68
- var TextItem = z.object({
108
+ var TextAnchor = z2.enum(["start", "middle", "end"]);
109
+ var TextItem = z2.object({
69
110
  ...base,
70
- type: z.literal("text"),
71
- x: z.number(),
72
- y: z.number(),
73
- text: z.string().min(1),
111
+ type: z2.literal("text"),
112
+ x: z2.number(),
113
+ y: z2.number(),
114
+ text: z2.string().min(1),
74
115
  /** Cap height in mm. */
75
- size: z.number().positive().default(3.5),
116
+ size: z2.number().positive().default(3.5),
76
117
  anchor: TextAnchor.default("start")
77
118
  });
78
- var NumeralItem = z.object({
119
+ var NumeralItem = z2.object({
79
120
  ...base,
80
- type: z.literal("numeral"),
121
+ type: z2.literal("numeral"),
81
122
  /** Numeral text, e.g. "102" or "102a". Looked up in Document.numerals. */
82
- n: z.string().regex(/^\d+[a-z']*$/i),
123
+ n: z2.string().regex(/^\d+[a-z']*$/i),
83
124
  at: Point,
84
125
  target: Point,
85
- leader: z.enum(["straight", "curved", "none"]).default("curved"),
126
+ leader: z2.enum(["straight", "curved", "none"]).default("curved"),
86
127
  /** When true, numeral is underlined (refers to the whole assembly). */
87
- underline: z.boolean().default(false),
88
- size: z.number().positive().default(3.5)
128
+ underline: z2.boolean().default(false),
129
+ size: z2.number().positive().default(3.5)
89
130
  });
90
- var FigLabelItem = z.object({
131
+ var FigLabelItem = z2.object({
91
132
  ...base,
92
- type: z.literal("figLabel"),
93
- x: z.number(),
94
- y: z.number(),
95
- size: z.number().positive().default(5)
133
+ type: z2.literal("figLabel"),
134
+ x: z2.number(),
135
+ y: z2.number(),
136
+ size: z2.number().positive().default(5)
96
137
  });
97
- var Side = z.enum(["top", "bottom", "left", "right"]);
98
- var ConnectorEnd = z.union([
99
- z.object({ itemId: z.string() }),
100
- z.object({ point: Point })
138
+ var Side = z2.enum(["top", "bottom", "left", "right"]);
139
+ var ConnectorEnd = z2.union([
140
+ z2.object({ itemId: z2.string() }),
141
+ z2.object({ point: Point })
101
142
  ]);
102
- var ConnectorItem = z.object({
143
+ var ConnectorItem = z2.object({
103
144
  ...base,
104
145
  ...stroked,
105
- type: z.literal("connector"),
146
+ type: z2.literal("connector"),
106
147
  from: ConnectorEnd,
107
148
  to: ConnectorEnd,
108
- routing: z.enum(["straight", "orthogonal", "curved"]).default("orthogonal"),
149
+ routing: z2.enum(["straight", "orthogonal", "curved"]).default("orthogonal"),
109
150
  /** Which side of an attached item the connector leaves/enters; auto when omitted. */
110
151
  fromSide: Side.optional(),
111
152
  toSide: Side.optional(),
112
- arrow: z.enum(["none", "end", "start", "both"]).default("end"),
113
- arrowStyle: z.enum(["filled", "open"]).default("filled"),
114
- label: z.string().optional()
153
+ arrow: z2.enum(["none", "end", "start", "both"]).default("end"),
154
+ arrowStyle: z2.enum(["filled", "open"]).default("filled"),
155
+ label: z2.string().optional()
115
156
  });
116
- var HatchItem = z.object({
157
+ var HatchItem = z2.object({
117
158
  ...base,
118
- type: z.literal("hatch"),
119
- points: z.array(Point).min(3),
120
- angle: z.number().default(45),
121
- spacing: z.number().positive().default(1.5),
122
- lineWidth: z.number().positive().default(0.25)
159
+ type: z2.literal("hatch"),
160
+ points: z2.array(Point).min(3),
161
+ angle: z2.number().default(45),
162
+ spacing: z2.number().positive().default(1.5),
163
+ lineWidth: z2.number().positive().default(0.25)
123
164
  });
124
- var SectionLineItem = z.object({
165
+ var SectionLineItem = z2.object({
125
166
  ...base,
126
167
  ...stroked,
127
- type: z.literal("sectionLine"),
168
+ type: z2.literal("sectionLine"),
128
169
  a: Point,
129
170
  b: Point,
130
- label: z.string().min(1).max(3)
171
+ label: z2.string().min(1).max(3)
131
172
  });
132
- var Item = z.discriminatedUnion("type", [
173
+ var Item = z2.discriminatedUnion("type", [
133
174
  LineItem,
134
175
  PolylineItem,
135
176
  PathItem,
@@ -143,67 +184,94 @@ var Item = z.discriminatedUnion("type", [
143
184
  HatchItem,
144
185
  SectionLineItem
145
186
  ]);
146
- var Offset = z.object({ dx: z.number(), dy: z.number() });
147
- var Layer = z.object({
148
- id: z.string().min(1),
149
- name: z.string().min(1),
150
- visible: z.boolean().default(true),
151
- locked: z.boolean().default(false),
187
+ var Offset = z2.object({ dx: z2.number(), dy: z2.number() });
188
+ var Layer = z2.object({
189
+ id: z2.string().min(1),
190
+ name: z2.string().min(1),
191
+ visible: z2.boolean().default(true),
192
+ locked: z2.boolean().default(false),
152
193
  /** Where this component moves to in the exploded view (mm). */
153
194
  explode: Offset.optional(),
154
- items: z.array(Item).default([])
195
+ items: z2.array(Item).default([])
155
196
  });
156
- var JurisdictionId = z.enum(["uspto", "pct", "epo", "ipo"]);
157
- var SheetSize = z.enum(["a4", "letter"]);
158
- var Sheet = z.object({
197
+ var JurisdictionId = z2.enum(["uspto", "pct", "epo", "ipo"]);
198
+ var SheetSize = z2.enum(["a4", "letter"]);
199
+ var Sheet = z2.object({
159
200
  size: SheetSize.default("a4"),
160
- orientation: z.enum(["portrait", "landscape"]).default("portrait")
201
+ orientation: z2.enum(["portrait", "landscape"]).default("portrait")
202
+ });
203
+ var LetteringStyle = z2.object({
204
+ numeralWeight: z2.enum(["regular", "bold"]).default("regular"),
205
+ figLabel: z2.enum(["sans-bold", "serif-italic"]).default("sans-bold")
161
206
  });
162
- var LetteringStyle = z.object({
163
- numeralWeight: z.enum(["regular", "bold"]).default("regular"),
164
- figLabel: z.enum(["sans-bold", "serif-italic"]).default("sans-bold")
207
+ var NumeralRegistry = z2.record(z2.string(), z2.string());
208
+ var ChatTranscript = z2.array(z2.unknown());
209
+ var DrawingSnapshot = z2.object({
210
+ jurisdiction: JurisdictionId,
211
+ sheet: Sheet,
212
+ layers: z2.array(Layer),
213
+ numerals: NumeralRegistry,
214
+ lettering: LetteringStyle,
215
+ view: z2.enum(["composite", "exploded"]),
216
+ explodeLines: z2.boolean(),
217
+ sheetLabel: z2.string().max(12).optional()
165
218
  });
166
- var NumeralRegistry = z.record(z.string(), z.string());
167
- var ChatTranscript = z.array(z.unknown());
168
- var PatentDocument = z.object({
169
- version: z.literal(1).default(1),
170
- id: z.string().min(1),
171
- figureNumber: z.string().min(1),
219
+ var RunRecord = z2.object({
220
+ id: z2.string().min(1),
221
+ /** "new" draws the figure, "edit" changes one that already had content. */
222
+ kind: z2.enum(["new", "edit"]),
223
+ request: z2.string(),
224
+ preferences: GenerationPrefs.optional(),
225
+ selection: z2.array(z2.string()).default([]),
226
+ /** Transcript length before the request, so a retry can replace the turn. */
227
+ chatLength: z2.number().int().nonnegative().default(0),
228
+ plan: FigurePlan.optional(),
229
+ steps: z2.array(z2.object({ label: z2.string(), status: z2.enum(["done", "active"]) })).default([]),
230
+ /** Number of individual changes the run made. */
231
+ edits: z2.number().int().nonnegative().default(0),
232
+ before: DrawingSnapshot
233
+ });
234
+ var PatentDocument = z2.object({
235
+ version: z2.literal(1).default(1),
236
+ id: z2.string().min(1),
237
+ figureNumber: z2.string().min(1),
172
238
  /** Patent office whose drawing rules apply. Defaults to India (IPO). */
173
239
  jurisdiction: JurisdictionId.default("ipo"),
174
240
  sheet: Sheet.default({ size: "a4", orientation: "portrait" }),
175
- layers: z.array(Layer).default([]),
241
+ layers: z2.array(Layer).default([]),
176
242
  numerals: NumeralRegistry.default({}),
177
243
  lettering: LetteringStyle.default({ numeralWeight: "regular", figLabel: "sans-bold" }),
178
244
  /** Which view of the same model is shown and exported. */
179
- view: z.enum(["composite", "exploded"]).default("composite"),
245
+ view: z2.enum(["composite", "exploded"]).default("composite"),
180
246
  /** Exploded view: dash-dot alignment lines between separated components. */
181
- explodeLines: z.boolean().default(true),
247
+ explodeLines: z2.boolean().default(true),
182
248
  /** Sheet number shown top-centre inside the sight, e.g. "1/3" (37 CFR 1.84(t)). Set by the host. */
183
- sheetLabel: z.string().max(12).optional(),
184
- chat: ChatTranscript.default([])
249
+ sheetLabel: z2.string().max(12).optional(),
250
+ chat: ChatTranscript.default([]),
251
+ /** Unfinished assistant run. A record that can't be read is dropped, never a load error. */
252
+ run: RunRecord.optional().catch(void 0)
185
253
  });
186
254
 
187
255
  // ../../src/patent-render/schema/patch.ts
188
- import { z as z2 } from "zod";
189
- var ItemChanges = z2.record(z2.string(), z2.unknown());
256
+ import { z as z3 } from "zod";
257
+ var ItemChanges = z3.record(z3.string(), z3.unknown());
190
258
  var LayerChanges = Layer.omit({ id: true, items: true }).partial();
191
- var Patch = z2.discriminatedUnion("op", [
192
- z2.object({ op: z2.literal("addLayer"), layer: Layer, index: z2.number().int().optional() }),
193
- z2.object({ op: z2.literal("updateLayer"), id: z2.string(), changes: LayerChanges }),
194
- z2.object({ op: z2.literal("removeLayer"), id: z2.string() }),
195
- z2.object({ op: z2.literal("moveLayer"), id: z2.string(), toIndex: z2.number().int() }),
196
- z2.object({ op: z2.literal("addItem"), layerId: z2.string(), item: Item, index: z2.number().int().optional() }),
197
- z2.object({ op: z2.literal("updateItem"), id: z2.string(), changes: ItemChanges }),
198
- z2.object({ op: z2.literal("removeItem"), id: z2.string() }),
199
- z2.object({ op: z2.literal("moveItem"), id: z2.string(), toLayerId: z2.string(), toIndex: z2.number().int().optional() }),
200
- z2.object({ op: z2.literal("setNumeral"), n: z2.string(), label: z2.string().nullable() }),
201
- z2.object({ op: z2.literal("setSheet"), sheet: Sheet }),
202
- z2.object({ op: z2.literal("setJurisdiction"), jurisdiction: JurisdictionId }),
203
- z2.object({ op: z2.literal("setLettering"), lettering: LetteringStyle }),
204
- z2.object({ op: z2.literal("setView"), view: z2.enum(["composite", "exploded"]), explodeLines: z2.boolean().optional() }),
205
- z2.object({ op: z2.literal("setSheetLabel"), sheetLabel: z2.string().max(12).nullable() }),
206
- z2.object({ op: z2.literal("batch"), patches: z2.array(z2.lazy(() => Patch)) })
259
+ var Patch = z3.discriminatedUnion("op", [
260
+ z3.object({ op: z3.literal("addLayer"), layer: Layer, index: z3.number().int().optional() }),
261
+ z3.object({ op: z3.literal("updateLayer"), id: z3.string(), changes: LayerChanges }),
262
+ z3.object({ op: z3.literal("removeLayer"), id: z3.string() }),
263
+ z3.object({ op: z3.literal("moveLayer"), id: z3.string(), toIndex: z3.number().int() }),
264
+ z3.object({ op: z3.literal("addItem"), layerId: z3.string(), item: Item, index: z3.number().int().optional() }),
265
+ z3.object({ op: z3.literal("updateItem"), id: z3.string(), changes: ItemChanges }),
266
+ z3.object({ op: z3.literal("removeItem"), id: z3.string() }),
267
+ z3.object({ op: z3.literal("moveItem"), id: z3.string(), toLayerId: z3.string(), toIndex: z3.number().int().optional() }),
268
+ z3.object({ op: z3.literal("setNumeral"), n: z3.string(), label: z3.string().nullable() }),
269
+ z3.object({ op: z3.literal("setSheet"), sheet: Sheet }),
270
+ z3.object({ op: z3.literal("setJurisdiction"), jurisdiction: JurisdictionId }),
271
+ z3.object({ op: z3.literal("setLettering"), lettering: LetteringStyle }),
272
+ z3.object({ op: z3.literal("setView"), view: z3.enum(["composite", "exploded"]), explodeLines: z3.boolean().optional() }),
273
+ z3.object({ op: z3.literal("setSheetLabel"), sheetLabel: z3.string().max(12).nullable() }),
274
+ z3.object({ op: z3.literal("batch"), patches: z3.array(z3.lazy(() => Patch)) })
207
275
  ]);
208
276
  function findItem(doc, id) {
209
277
  for (let li = 0; li < doc.layers.length; li++) {