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