@studio8collective/patent-render 1.0.1 → 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/CHANGELOG.md +19 -0
- package/README.md +2 -1
- package/dist/core.d.ts +405 -0
- package/dist/core.js +185 -117
- package/dist/core.js.map +1 -1
- package/dist/index.d.ts +451 -4
- package/dist/index.js +781 -324
- package/dist/index.js.map +1 -1
- package/dist/server-actions.d.ts +367 -0
- package/dist/server-actions.js +185 -117
- package/dist/server-actions.js.map +1 -1
- package/dist/server.d.ts +367 -0
- package/dist/server.js +391 -322
- package/dist/server.js.map +1 -1
- package/docs/nextjs.md +58 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,137 +1,192 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// ../../src/patent-render/client/PatentRender.tsx
|
|
4
|
-
import { useEffect as useEffect6, useMemo as useMemo5, useRef as useRef7 } from "react";
|
|
4
|
+
import { useEffect as useEffect6, useLayoutEffect as useLayoutEffect3, useMemo as useMemo5, useRef as useRef7 } from "react";
|
|
5
5
|
|
|
6
6
|
// ../../src/patent-render/schema/document.ts
|
|
7
|
+
import { z as z2 } from "zod";
|
|
8
|
+
|
|
9
|
+
// ../../src/patent-render/schema/plan.ts
|
|
7
10
|
import { z } from "zod";
|
|
11
|
+
var FigureType = z.enum([
|
|
12
|
+
"flowchart",
|
|
13
|
+
"blockDiagram",
|
|
14
|
+
"mechanical2d",
|
|
15
|
+
"uiScreen",
|
|
16
|
+
"perspective3d",
|
|
17
|
+
"circuit",
|
|
18
|
+
"chemical"
|
|
19
|
+
]);
|
|
20
|
+
var FigurePlan = z.object({
|
|
21
|
+
figureType: FigureType,
|
|
22
|
+
/** e.g. "Cross-sectional view taken along line A-A of FIG. 2" */
|
|
23
|
+
view: z.string(),
|
|
24
|
+
summary: z.string(),
|
|
25
|
+
/**
|
|
26
|
+
* Full generation spec: overall form and proportions (mm), every component's
|
|
27
|
+
* shape, position and relationships, counts, surface details and what faces
|
|
28
|
+
* the viewer. Written so a draftsperson can draw without guessing.
|
|
29
|
+
*/
|
|
30
|
+
spec: z.string().default(""),
|
|
31
|
+
components: z.array(z.object({
|
|
32
|
+
numeral: z.string(),
|
|
33
|
+
name: z.string(),
|
|
34
|
+
description: z.string().optional(),
|
|
35
|
+
reused: z.boolean().default(false)
|
|
36
|
+
// numeral came from the host registry
|
|
37
|
+
})),
|
|
38
|
+
layers: z.array(z.object({ id: z.string(), name: z.string() })),
|
|
39
|
+
notes: z.array(z.string()).default([])
|
|
40
|
+
});
|
|
41
|
+
var DrawingStyle = z.enum(["standard", "detailed", "minimal"]);
|
|
42
|
+
var STYLE_LABEL = {
|
|
43
|
+
standard: { label: "Standard line art", hint: "Clean outlines and key details, as most filings" },
|
|
44
|
+
detailed: { label: "Detailed rendering", hint: "Shading strokes, glare, textures, fine features" },
|
|
45
|
+
minimal: { label: "Minimal outline", hint: "Essential outlines only, fewest lines" }
|
|
46
|
+
};
|
|
47
|
+
var GenerationPrefs = z.object({
|
|
48
|
+
figureType: FigureType.optional(),
|
|
49
|
+
// undefined = let the planner decide
|
|
50
|
+
style: DrawingStyle.default("standard")
|
|
51
|
+
});
|
|
52
|
+
var FIGURE_TYPE_LABEL = {
|
|
53
|
+
flowchart: "Flowchart",
|
|
54
|
+
blockDiagram: "Block diagram",
|
|
55
|
+
mechanical2d: "Mechanical 2D",
|
|
56
|
+
uiScreen: "UI screen",
|
|
57
|
+
perspective3d: "Perspective 3D",
|
|
58
|
+
circuit: "Circuit",
|
|
59
|
+
chemical: "Chemical structure"
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// ../../src/patent-render/schema/document.ts
|
|
8
63
|
function vec(n) {
|
|
9
|
-
return
|
|
64
|
+
return z2.array(z2.number()).length(n);
|
|
10
65
|
}
|
|
11
66
|
var Point = vec(2);
|
|
12
|
-
var StrokeStyle =
|
|
13
|
-
var Stroke =
|
|
14
|
-
width:
|
|
67
|
+
var StrokeStyle = z2.enum(["solid", "dashed", "centre", "phantom"]);
|
|
68
|
+
var Stroke = z2.object({
|
|
69
|
+
width: z2.number().positive().default(0.35),
|
|
15
70
|
style: StrokeStyle.default("solid")
|
|
16
71
|
});
|
|
17
|
-
var Fill =
|
|
72
|
+
var Fill = z2.enum(["none", "black", "white"]);
|
|
18
73
|
var base = {
|
|
19
|
-
id:
|
|
20
|
-
name:
|
|
74
|
+
id: z2.string().min(1),
|
|
75
|
+
name: z2.string().optional(),
|
|
21
76
|
/** Degrees, clockwise, about the item's bounding-box centre. */
|
|
22
|
-
rotation:
|
|
23
|
-
locked:
|
|
24
|
-
hidden:
|
|
77
|
+
rotation: z2.number().default(0),
|
|
78
|
+
locked: z2.boolean().default(false),
|
|
79
|
+
hidden: z2.boolean().default(false)
|
|
25
80
|
};
|
|
26
81
|
var stroked = { stroke: Stroke.default({ width: 0.35, style: "solid" }) };
|
|
27
|
-
var LineItem =
|
|
28
|
-
var PolylineItem =
|
|
82
|
+
var LineItem = z2.object({ ...base, ...stroked, type: z2.literal("line"), a: Point, b: Point });
|
|
83
|
+
var PolylineItem = z2.object({
|
|
29
84
|
...base,
|
|
30
85
|
...stroked,
|
|
31
|
-
type:
|
|
32
|
-
points:
|
|
33
|
-
closed:
|
|
86
|
+
type: z2.literal("polyline"),
|
|
87
|
+
points: z2.array(Point).min(2),
|
|
88
|
+
closed: z2.boolean().default(false),
|
|
34
89
|
fill: Fill.default("none")
|
|
35
90
|
});
|
|
36
|
-
var PathItem =
|
|
37
|
-
var RectItem =
|
|
91
|
+
var PathItem = z2.object({ ...base, ...stroked, type: z2.literal("path"), d: z2.string().min(1), fill: Fill.default("none") });
|
|
92
|
+
var RectItem = z2.object({
|
|
38
93
|
...base,
|
|
39
94
|
...stroked,
|
|
40
|
-
type:
|
|
41
|
-
x:
|
|
42
|
-
y:
|
|
43
|
-
w:
|
|
44
|
-
h:
|
|
45
|
-
radius:
|
|
95
|
+
type: z2.literal("rect"),
|
|
96
|
+
x: z2.number(),
|
|
97
|
+
y: z2.number(),
|
|
98
|
+
w: z2.number().positive(),
|
|
99
|
+
h: z2.number().positive(),
|
|
100
|
+
radius: z2.number().min(0).default(0),
|
|
46
101
|
fill: Fill.default("none")
|
|
47
102
|
});
|
|
48
|
-
var EllipseItem =
|
|
103
|
+
var EllipseItem = z2.object({
|
|
49
104
|
...base,
|
|
50
105
|
...stroked,
|
|
51
|
-
type:
|
|
52
|
-
cx:
|
|
53
|
-
cy:
|
|
54
|
-
rx:
|
|
55
|
-
ry:
|
|
106
|
+
type: z2.literal("ellipse"),
|
|
107
|
+
cx: z2.number(),
|
|
108
|
+
cy: z2.number(),
|
|
109
|
+
rx: z2.number().positive(),
|
|
110
|
+
ry: z2.number().positive(),
|
|
56
111
|
fill: Fill.default("none")
|
|
57
112
|
});
|
|
58
|
-
var ArcItem =
|
|
113
|
+
var ArcItem = z2.object({
|
|
59
114
|
...base,
|
|
60
115
|
...stroked,
|
|
61
|
-
type:
|
|
62
|
-
cx:
|
|
63
|
-
cy:
|
|
64
|
-
r:
|
|
116
|
+
type: z2.literal("arc"),
|
|
117
|
+
cx: z2.number(),
|
|
118
|
+
cy: z2.number(),
|
|
119
|
+
r: z2.number().positive(),
|
|
65
120
|
/** Degrees, 0 = +x axis, clockwise (SVG convention). */
|
|
66
|
-
start:
|
|
67
|
-
end:
|
|
121
|
+
start: z2.number(),
|
|
122
|
+
end: z2.number()
|
|
68
123
|
});
|
|
69
|
-
var TextAnchor =
|
|
70
|
-
var TextItem =
|
|
124
|
+
var TextAnchor = z2.enum(["start", "middle", "end"]);
|
|
125
|
+
var TextItem = z2.object({
|
|
71
126
|
...base,
|
|
72
|
-
type:
|
|
73
|
-
x:
|
|
74
|
-
y:
|
|
75
|
-
text:
|
|
127
|
+
type: z2.literal("text"),
|
|
128
|
+
x: z2.number(),
|
|
129
|
+
y: z2.number(),
|
|
130
|
+
text: z2.string().min(1),
|
|
76
131
|
/** Cap height in mm. */
|
|
77
|
-
size:
|
|
132
|
+
size: z2.number().positive().default(3.5),
|
|
78
133
|
anchor: TextAnchor.default("start")
|
|
79
134
|
});
|
|
80
|
-
var NumeralItem =
|
|
135
|
+
var NumeralItem = z2.object({
|
|
81
136
|
...base,
|
|
82
|
-
type:
|
|
137
|
+
type: z2.literal("numeral"),
|
|
83
138
|
/** Numeral text, e.g. "102" or "102a". Looked up in Document.numerals. */
|
|
84
|
-
n:
|
|
139
|
+
n: z2.string().regex(/^\d+[a-z']*$/i),
|
|
85
140
|
at: Point,
|
|
86
141
|
target: Point,
|
|
87
|
-
leader:
|
|
142
|
+
leader: z2.enum(["straight", "curved", "none"]).default("curved"),
|
|
88
143
|
/** When true, numeral is underlined (refers to the whole assembly). */
|
|
89
|
-
underline:
|
|
90
|
-
size:
|
|
144
|
+
underline: z2.boolean().default(false),
|
|
145
|
+
size: z2.number().positive().default(3.5)
|
|
91
146
|
});
|
|
92
|
-
var FigLabelItem =
|
|
147
|
+
var FigLabelItem = z2.object({
|
|
93
148
|
...base,
|
|
94
|
-
type:
|
|
95
|
-
x:
|
|
96
|
-
y:
|
|
97
|
-
size:
|
|
149
|
+
type: z2.literal("figLabel"),
|
|
150
|
+
x: z2.number(),
|
|
151
|
+
y: z2.number(),
|
|
152
|
+
size: z2.number().positive().default(5)
|
|
98
153
|
});
|
|
99
|
-
var Side =
|
|
100
|
-
var ConnectorEnd =
|
|
101
|
-
|
|
102
|
-
|
|
154
|
+
var Side = z2.enum(["top", "bottom", "left", "right"]);
|
|
155
|
+
var ConnectorEnd = z2.union([
|
|
156
|
+
z2.object({ itemId: z2.string() }),
|
|
157
|
+
z2.object({ point: Point })
|
|
103
158
|
]);
|
|
104
|
-
var ConnectorItem =
|
|
159
|
+
var ConnectorItem = z2.object({
|
|
105
160
|
...base,
|
|
106
161
|
...stroked,
|
|
107
|
-
type:
|
|
162
|
+
type: z2.literal("connector"),
|
|
108
163
|
from: ConnectorEnd,
|
|
109
164
|
to: ConnectorEnd,
|
|
110
|
-
routing:
|
|
165
|
+
routing: z2.enum(["straight", "orthogonal", "curved"]).default("orthogonal"),
|
|
111
166
|
/** Which side of an attached item the connector leaves/enters; auto when omitted. */
|
|
112
167
|
fromSide: Side.optional(),
|
|
113
168
|
toSide: Side.optional(),
|
|
114
|
-
arrow:
|
|
115
|
-
arrowStyle:
|
|
116
|
-
label:
|
|
169
|
+
arrow: z2.enum(["none", "end", "start", "both"]).default("end"),
|
|
170
|
+
arrowStyle: z2.enum(["filled", "open"]).default("filled"),
|
|
171
|
+
label: z2.string().optional()
|
|
117
172
|
});
|
|
118
|
-
var HatchItem =
|
|
173
|
+
var HatchItem = z2.object({
|
|
119
174
|
...base,
|
|
120
|
-
type:
|
|
121
|
-
points:
|
|
122
|
-
angle:
|
|
123
|
-
spacing:
|
|
124
|
-
lineWidth:
|
|
175
|
+
type: z2.literal("hatch"),
|
|
176
|
+
points: z2.array(Point).min(3),
|
|
177
|
+
angle: z2.number().default(45),
|
|
178
|
+
spacing: z2.number().positive().default(1.5),
|
|
179
|
+
lineWidth: z2.number().positive().default(0.25)
|
|
125
180
|
});
|
|
126
|
-
var SectionLineItem =
|
|
181
|
+
var SectionLineItem = z2.object({
|
|
127
182
|
...base,
|
|
128
183
|
...stroked,
|
|
129
|
-
type:
|
|
184
|
+
type: z2.literal("sectionLine"),
|
|
130
185
|
a: Point,
|
|
131
186
|
b: Point,
|
|
132
|
-
label:
|
|
187
|
+
label: z2.string().min(1).max(3)
|
|
133
188
|
});
|
|
134
|
-
var Item =
|
|
189
|
+
var Item = z2.discriminatedUnion("type", [
|
|
135
190
|
LineItem,
|
|
136
191
|
PolylineItem,
|
|
137
192
|
PathItem,
|
|
@@ -145,45 +200,72 @@ var Item = z.discriminatedUnion("type", [
|
|
|
145
200
|
HatchItem,
|
|
146
201
|
SectionLineItem
|
|
147
202
|
]);
|
|
148
|
-
var Offset =
|
|
149
|
-
var Layer =
|
|
150
|
-
id:
|
|
151
|
-
name:
|
|
152
|
-
visible:
|
|
153
|
-
locked:
|
|
203
|
+
var Offset = z2.object({ dx: z2.number(), dy: z2.number() });
|
|
204
|
+
var Layer = z2.object({
|
|
205
|
+
id: z2.string().min(1),
|
|
206
|
+
name: z2.string().min(1),
|
|
207
|
+
visible: z2.boolean().default(true),
|
|
208
|
+
locked: z2.boolean().default(false),
|
|
154
209
|
/** Where this component moves to in the exploded view (mm). */
|
|
155
210
|
explode: Offset.optional(),
|
|
156
|
-
items:
|
|
211
|
+
items: z2.array(Item).default([])
|
|
157
212
|
});
|
|
158
|
-
var JurisdictionId =
|
|
159
|
-
var SheetSize =
|
|
160
|
-
var Sheet =
|
|
213
|
+
var JurisdictionId = z2.enum(["uspto", "pct", "epo", "ipo"]);
|
|
214
|
+
var SheetSize = z2.enum(["a4", "letter"]);
|
|
215
|
+
var Sheet = z2.object({
|
|
161
216
|
size: SheetSize.default("a4"),
|
|
162
|
-
orientation:
|
|
217
|
+
orientation: z2.enum(["portrait", "landscape"]).default("portrait")
|
|
218
|
+
});
|
|
219
|
+
var LetteringStyle = z2.object({
|
|
220
|
+
numeralWeight: z2.enum(["regular", "bold"]).default("regular"),
|
|
221
|
+
figLabel: z2.enum(["sans-bold", "serif-italic"]).default("sans-bold")
|
|
163
222
|
});
|
|
164
|
-
var
|
|
165
|
-
|
|
166
|
-
|
|
223
|
+
var NumeralRegistry = z2.record(z2.string(), z2.string());
|
|
224
|
+
var ChatTranscript = z2.array(z2.unknown());
|
|
225
|
+
var DrawingSnapshot = z2.object({
|
|
226
|
+
jurisdiction: JurisdictionId,
|
|
227
|
+
sheet: Sheet,
|
|
228
|
+
layers: z2.array(Layer),
|
|
229
|
+
numerals: NumeralRegistry,
|
|
230
|
+
lettering: LetteringStyle,
|
|
231
|
+
view: z2.enum(["composite", "exploded"]),
|
|
232
|
+
explodeLines: z2.boolean(),
|
|
233
|
+
sheetLabel: z2.string().max(12).optional()
|
|
167
234
|
});
|
|
168
|
-
var
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
235
|
+
var RunRecord = z2.object({
|
|
236
|
+
id: z2.string().min(1),
|
|
237
|
+
/** "new" draws the figure, "edit" changes one that already had content. */
|
|
238
|
+
kind: z2.enum(["new", "edit"]),
|
|
239
|
+
request: z2.string(),
|
|
240
|
+
preferences: GenerationPrefs.optional(),
|
|
241
|
+
selection: z2.array(z2.string()).default([]),
|
|
242
|
+
/** Transcript length before the request, so a retry can replace the turn. */
|
|
243
|
+
chatLength: z2.number().int().nonnegative().default(0),
|
|
244
|
+
plan: FigurePlan.optional(),
|
|
245
|
+
steps: z2.array(z2.object({ label: z2.string(), status: z2.enum(["done", "active"]) })).default([]),
|
|
246
|
+
/** Number of individual changes the run made. */
|
|
247
|
+
edits: z2.number().int().nonnegative().default(0),
|
|
248
|
+
before: DrawingSnapshot
|
|
249
|
+
});
|
|
250
|
+
var PatentDocument = z2.object({
|
|
251
|
+
version: z2.literal(1).default(1),
|
|
252
|
+
id: z2.string().min(1),
|
|
253
|
+
figureNumber: z2.string().min(1),
|
|
174
254
|
/** Patent office whose drawing rules apply. Defaults to India (IPO). */
|
|
175
255
|
jurisdiction: JurisdictionId.default("ipo"),
|
|
176
256
|
sheet: Sheet.default({ size: "a4", orientation: "portrait" }),
|
|
177
|
-
layers:
|
|
257
|
+
layers: z2.array(Layer).default([]),
|
|
178
258
|
numerals: NumeralRegistry.default({}),
|
|
179
259
|
lettering: LetteringStyle.default({ numeralWeight: "regular", figLabel: "sans-bold" }),
|
|
180
260
|
/** Which view of the same model is shown and exported. */
|
|
181
|
-
view:
|
|
261
|
+
view: z2.enum(["composite", "exploded"]).default("composite"),
|
|
182
262
|
/** Exploded view: dash-dot alignment lines between separated components. */
|
|
183
|
-
explodeLines:
|
|
263
|
+
explodeLines: z2.boolean().default(true),
|
|
184
264
|
/** Sheet number shown top-centre inside the sight, e.g. "1/3" (37 CFR 1.84(t)). Set by the host. */
|
|
185
|
-
sheetLabel:
|
|
186
|
-
chat: ChatTranscript.default([])
|
|
265
|
+
sheetLabel: z2.string().max(12).optional(),
|
|
266
|
+
chat: ChatTranscript.default([]),
|
|
267
|
+
/** Unfinished assistant run. A record that can't be read is dropped, never a load error. */
|
|
268
|
+
run: RunRecord.optional().catch(void 0)
|
|
187
269
|
});
|
|
188
270
|
function normalizeDocument(input) {
|
|
189
271
|
const r = PatentDocument.safeParse(input);
|
|
@@ -210,25 +292,25 @@ function createDocument(init) {
|
|
|
210
292
|
import { createContext, useCallback, useContext, useMemo, useReducer } from "react";
|
|
211
293
|
|
|
212
294
|
// ../../src/patent-render/schema/patch.ts
|
|
213
|
-
import { z as
|
|
214
|
-
var ItemChanges =
|
|
295
|
+
import { z as z3 } from "zod";
|
|
296
|
+
var ItemChanges = z3.record(z3.string(), z3.unknown());
|
|
215
297
|
var LayerChanges = Layer.omit({ id: true, items: true }).partial();
|
|
216
|
-
var Patch =
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
298
|
+
var Patch = z3.discriminatedUnion("op", [
|
|
299
|
+
z3.object({ op: z3.literal("addLayer"), layer: Layer, index: z3.number().int().optional() }),
|
|
300
|
+
z3.object({ op: z3.literal("updateLayer"), id: z3.string(), changes: LayerChanges }),
|
|
301
|
+
z3.object({ op: z3.literal("removeLayer"), id: z3.string() }),
|
|
302
|
+
z3.object({ op: z3.literal("moveLayer"), id: z3.string(), toIndex: z3.number().int() }),
|
|
303
|
+
z3.object({ op: z3.literal("addItem"), layerId: z3.string(), item: Item, index: z3.number().int().optional() }),
|
|
304
|
+
z3.object({ op: z3.literal("updateItem"), id: z3.string(), changes: ItemChanges }),
|
|
305
|
+
z3.object({ op: z3.literal("removeItem"), id: z3.string() }),
|
|
306
|
+
z3.object({ op: z3.literal("moveItem"), id: z3.string(), toLayerId: z3.string(), toIndex: z3.number().int().optional() }),
|
|
307
|
+
z3.object({ op: z3.literal("setNumeral"), n: z3.string(), label: z3.string().nullable() }),
|
|
308
|
+
z3.object({ op: z3.literal("setSheet"), sheet: Sheet }),
|
|
309
|
+
z3.object({ op: z3.literal("setJurisdiction"), jurisdiction: JurisdictionId }),
|
|
310
|
+
z3.object({ op: z3.literal("setLettering"), lettering: LetteringStyle }),
|
|
311
|
+
z3.object({ op: z3.literal("setView"), view: z3.enum(["composite", "exploded"]), explodeLines: z3.boolean().optional() }),
|
|
312
|
+
z3.object({ op: z3.literal("setSheetLabel"), sheetLabel: z3.string().max(12).nullable() }),
|
|
313
|
+
z3.object({ op: z3.literal("batch"), patches: z3.array(z3.lazy(() => Patch)) })
|
|
232
314
|
]);
|
|
233
315
|
var PatchError = class extends Error {
|
|
234
316
|
};
|
|
@@ -2808,7 +2890,7 @@ function Canvas({ className }) {
|
|
|
2808
2890
|
return el ? el.getAttribute("data-hit-id") : null;
|
|
2809
2891
|
};
|
|
2810
2892
|
const interiorHit = (p) => {
|
|
2811
|
-
const
|
|
2893
|
+
const z5 = (viewRef.current ?? v).zoom;
|
|
2812
2894
|
let best = null;
|
|
2813
2895
|
for (const l of vdoc.layers) {
|
|
2814
2896
|
if (!l.visible || l.locked) continue;
|
|
@@ -2816,7 +2898,7 @@ function Canvas({ className }) {
|
|
|
2816
2898
|
const closed = it.type === "rect" || it.type === "ellipse" || it.type === "polyline" && it.closed || it.type === "path" && /z\s*$/i.test(it.d);
|
|
2817
2899
|
if (!closed || it.hidden || it.locked || !isItemEditable(doc, it.id)) continue;
|
|
2818
2900
|
const b = itemBoundsRotated(vdoc, it);
|
|
2819
|
-
if (b.w *
|
|
2901
|
+
if (b.w * z5 > INTERIOR_GRAB_MAX_PX || b.h * z5 > INTERIOR_GRAB_MAX_PX) continue;
|
|
2820
2902
|
if (p[0] < b.x || p[0] > b.x + b.w || p[1] < b.y || p[1] > b.y + b.h) continue;
|
|
2821
2903
|
const area = b.w * b.h;
|
|
2822
2904
|
if (!best || area < best.area) best = { id: it.id, area };
|
|
@@ -3352,7 +3434,7 @@ function CanvasMenu() {
|
|
|
3352
3434
|
] })
|
|
3353
3435
|
] });
|
|
3354
3436
|
}
|
|
3355
|
-
const
|
|
3437
|
+
const z5 = (move) => {
|
|
3356
3438
|
const ps = selection.map((id) => zOrderPatch(ed.state.doc, id, move)).filter((p) => !!p);
|
|
3357
3439
|
if (ps.length) ed.apply({ op: "batch", patches: ps });
|
|
3358
3440
|
};
|
|
@@ -3369,19 +3451,19 @@ function CanvasMenu() {
|
|
|
3369
3451
|
] })
|
|
3370
3452
|
] }),
|
|
3371
3453
|
/* @__PURE__ */ jsx8(ContextMenuSeparator, {}),
|
|
3372
|
-
/* @__PURE__ */ jsxs6(ContextMenuItem, { onSelect: () =>
|
|
3454
|
+
/* @__PURE__ */ jsxs6(ContextMenuItem, { onSelect: () => z5("front"), children: [
|
|
3373
3455
|
"Bring to front",
|
|
3374
3456
|
/* @__PURE__ */ jsx8(ContextMenuShortcut, { children: "\u21E7]" })
|
|
3375
3457
|
] }),
|
|
3376
|
-
/* @__PURE__ */ jsxs6(ContextMenuItem, { onSelect: () =>
|
|
3458
|
+
/* @__PURE__ */ jsxs6(ContextMenuItem, { onSelect: () => z5("forward"), children: [
|
|
3377
3459
|
"Bring forward",
|
|
3378
3460
|
/* @__PURE__ */ jsx8(ContextMenuShortcut, { children: "]" })
|
|
3379
3461
|
] }),
|
|
3380
|
-
/* @__PURE__ */ jsxs6(ContextMenuItem, { onSelect: () =>
|
|
3462
|
+
/* @__PURE__ */ jsxs6(ContextMenuItem, { onSelect: () => z5("backward"), children: [
|
|
3381
3463
|
"Send backward",
|
|
3382
3464
|
/* @__PURE__ */ jsx8(ContextMenuShortcut, { children: "[" })
|
|
3383
3465
|
] }),
|
|
3384
|
-
/* @__PURE__ */ jsxs6(ContextMenuItem, { onSelect: () =>
|
|
3466
|
+
/* @__PURE__ */ jsxs6(ContextMenuItem, { onSelect: () => z5("back"), children: [
|
|
3385
3467
|
"Send to back",
|
|
3386
3468
|
/* @__PURE__ */ jsx8(ContextMenuShortcut, { children: "\u21E7[" })
|
|
3387
3469
|
] }),
|
|
@@ -5122,7 +5204,7 @@ function HeaderBar({ onEmbed, onCancel, embedding, className }) {
|
|
|
5122
5204
|
import { useEffect as useEffect2, useRef as useRef3, useState as useState6 } from "react";
|
|
5123
5205
|
import {
|
|
5124
5206
|
ArrowUp,
|
|
5125
|
-
Check,
|
|
5207
|
+
Check as Check2,
|
|
5126
5208
|
ChevronDown as ChevronDown2,
|
|
5127
5209
|
ChevronUp,
|
|
5128
5210
|
Circle as Circle3,
|
|
@@ -5138,71 +5220,76 @@ import {
|
|
|
5138
5220
|
} from "lucide-react";
|
|
5139
5221
|
import { cn as cn23 } from "cn";
|
|
5140
5222
|
|
|
5141
|
-
// ../../src/patent-render/
|
|
5142
|
-
import {
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
"
|
|
5146
|
-
"
|
|
5147
|
-
"
|
|
5148
|
-
"perspective3d",
|
|
5149
|
-
"circuit",
|
|
5150
|
-
"chemical"
|
|
5151
|
-
]);
|
|
5152
|
-
var FigurePlan = z3.object({
|
|
5153
|
-
figureType: FigureType,
|
|
5154
|
-
/** e.g. "Cross-sectional view taken along line A-A of FIG. 2" */
|
|
5155
|
-
view: z3.string(),
|
|
5156
|
-
summary: z3.string(),
|
|
5157
|
-
/**
|
|
5158
|
-
* Full generation spec: overall form and proportions (mm), every component's
|
|
5159
|
-
* shape, position and relationships, counts, surface details and what faces
|
|
5160
|
-
* the viewer. Written so a draftsperson can draw without guessing.
|
|
5161
|
-
*/
|
|
5162
|
-
spec: z3.string().default(""),
|
|
5163
|
-
components: z3.array(z3.object({
|
|
5164
|
-
numeral: z3.string(),
|
|
5165
|
-
name: z3.string(),
|
|
5166
|
-
description: z3.string().optional(),
|
|
5167
|
-
reused: z3.boolean().default(false)
|
|
5168
|
-
// numeral came from the host registry
|
|
5169
|
-
})),
|
|
5170
|
-
layers: z3.array(z3.object({ id: z3.string(), name: z3.string() })),
|
|
5171
|
-
notes: z3.array(z3.string()).default([])
|
|
5172
|
-
});
|
|
5173
|
-
var DrawingStyle = z3.enum(["standard", "detailed", "minimal"]);
|
|
5174
|
-
var STYLE_LABEL = {
|
|
5175
|
-
standard: { label: "Standard line art", hint: "Clean outlines and key details, as most filings" },
|
|
5176
|
-
detailed: { label: "Detailed rendering", hint: "Shading strokes, glare, textures, fine features" },
|
|
5177
|
-
minimal: { label: "Minimal outline", hint: "Essential outlines only, fewest lines" }
|
|
5178
|
-
};
|
|
5179
|
-
var GenerationPrefs = z3.object({
|
|
5180
|
-
figureType: FigureType.optional(),
|
|
5181
|
-
// undefined = let the planner decide
|
|
5182
|
-
style: DrawingStyle.default("standard")
|
|
5183
|
-
});
|
|
5184
|
-
var FIGURE_TYPE_LABEL = {
|
|
5185
|
-
flowchart: "Flowchart",
|
|
5186
|
-
blockDiagram: "Block diagram",
|
|
5187
|
-
mechanical2d: "Mechanical 2D",
|
|
5188
|
-
uiScreen: "UI screen",
|
|
5189
|
-
perspective3d: "Perspective 3D",
|
|
5190
|
-
circuit: "Circuit",
|
|
5191
|
-
chemical: "Chemical structure"
|
|
5223
|
+
// ../../src/patent-render/client/InterruptedCard.tsx
|
|
5224
|
+
import { Check, CircleDashed as CircleDashed2, CirclePause } from "lucide-react";
|
|
5225
|
+
import { jsx as jsx25, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
5226
|
+
var TITLE = {
|
|
5227
|
+
planning: "Planning was interrupted",
|
|
5228
|
+
drawing: "Drawing was interrupted",
|
|
5229
|
+
edit: "Your change was interrupted"
|
|
5192
5230
|
};
|
|
5231
|
+
function choices(run) {
|
|
5232
|
+
if (run.kind === "drawing") {
|
|
5233
|
+
return [
|
|
5234
|
+
{ action: "continue", label: "Continue drawing" },
|
|
5235
|
+
{ action: "restart", label: "Start over" },
|
|
5236
|
+
{ action: "dismiss", label: "Keep as is" }
|
|
5237
|
+
];
|
|
5238
|
+
}
|
|
5239
|
+
if (run.kind === "edit" && run.edits > 0) {
|
|
5240
|
+
return [
|
|
5241
|
+
{ action: "continue", label: "Continue change" },
|
|
5242
|
+
{ action: "undo", label: "Undo these edits" },
|
|
5243
|
+
{ action: "dismiss", label: "Keep as is" }
|
|
5244
|
+
];
|
|
5245
|
+
}
|
|
5246
|
+
return [
|
|
5247
|
+
{ action: "retry", label: "Try again" },
|
|
5248
|
+
{ action: "edit", label: "Edit request" },
|
|
5249
|
+
{ action: "dismiss", label: "Dismiss" }
|
|
5250
|
+
];
|
|
5251
|
+
}
|
|
5252
|
+
function InterruptedCard({ run, onAction }) {
|
|
5253
|
+
return /* @__PURE__ */ jsxs16("section", { "aria-label": TITLE[run.kind], "data-slot": "pr-interrupted", className: "max-w-[min(36rem,100%)] rounded-lg border bg-card px-3 py-2.5 text-card-foreground", children: [
|
|
5254
|
+
/* @__PURE__ */ jsxs16("div", { className: "flex items-center gap-2 text-xs font-semibold", children: [
|
|
5255
|
+
/* @__PURE__ */ jsx25(CirclePause, { className: "size-3.5 text-muted-foreground" }),
|
|
5256
|
+
" ",
|
|
5257
|
+
TITLE[run.kind]
|
|
5258
|
+
] }),
|
|
5259
|
+
run.request && /* @__PURE__ */ jsxs16("p", { className: "mt-1 line-clamp-2 text-xs text-muted-foreground", children: [
|
|
5260
|
+
"\u201C",
|
|
5261
|
+
run.request,
|
|
5262
|
+
"\u201D"
|
|
5263
|
+
] }),
|
|
5264
|
+
run.kind === "drawing" && run.steps.length > 0 && /* @__PURE__ */ jsxs16("ol", { className: "mt-2 grid gap-1", children: [
|
|
5265
|
+
run.hiddenSteps > 0 && /* @__PURE__ */ jsxs16("li", { className: "pl-[22px] text-xs text-muted-foreground", children: [
|
|
5266
|
+
run.hiddenSteps,
|
|
5267
|
+
" earlier step",
|
|
5268
|
+
run.hiddenSteps === 1 ? "" : "s"
|
|
5269
|
+
] }),
|
|
5270
|
+
run.steps.map((s, i) => /* @__PURE__ */ jsxs16("li", { className: s.status === "done" ? "flex items-center gap-2 text-xs" : "flex items-center gap-2 text-xs text-muted-foreground", children: [
|
|
5271
|
+
s.status === "done" ? /* @__PURE__ */ jsx25(Check, { className: "size-3.5 shrink-0 text-success" }) : /* @__PURE__ */ jsx25(CircleDashed2, { className: "size-3.5 shrink-0" }),
|
|
5272
|
+
s.label
|
|
5273
|
+
] }, i))
|
|
5274
|
+
] }),
|
|
5275
|
+
run.kind === "planning" && /* @__PURE__ */ jsx25("p", { className: "mt-1.5 text-xs text-muted-foreground", children: "Nothing was drawn yet. Your request is saved." }),
|
|
5276
|
+
run.kind === "edit" && /* @__PURE__ */ jsx25("p", { className: "mt-1.5 text-xs text-muted-foreground", children: run.edits ? `${run.edits} edit${run.edits === 1 ? " was" : "s were"} made before it stopped.` : "No edits were made before it stopped." }),
|
|
5277
|
+
/* @__PURE__ */ jsx25("div", { className: "mt-2.5 flex flex-wrap gap-1.5", children: choices(run).map((c, i) => /* @__PURE__ */ jsx25(Button, { size: "sm", variant: i === 0 ? "default" : "outline", className: "h-7 text-xs", onClick: () => onAction(c.action), children: c.label }, c.action)) })
|
|
5278
|
+
] });
|
|
5279
|
+
}
|
|
5193
5280
|
|
|
5194
5281
|
// ../../src/patent-render/ui/collapsible.tsx
|
|
5195
5282
|
import { Collapsible as CollapsiblePrimitive } from "radix-ui";
|
|
5196
|
-
import { jsx as
|
|
5283
|
+
import { jsx as jsx26 } from "react/jsx-runtime";
|
|
5197
5284
|
function Collapsible({
|
|
5198
5285
|
...props
|
|
5199
5286
|
}) {
|
|
5200
|
-
return /* @__PURE__ */
|
|
5287
|
+
return /* @__PURE__ */ jsx26(CollapsiblePrimitive.Root, { "data-slot": "collapsible", ...props });
|
|
5201
5288
|
}
|
|
5202
5289
|
function CollapsibleTrigger({
|
|
5203
5290
|
...props
|
|
5204
5291
|
}) {
|
|
5205
|
-
return /* @__PURE__ */
|
|
5292
|
+
return /* @__PURE__ */ jsx26(
|
|
5206
5293
|
CollapsiblePrimitive.CollapsibleTrigger,
|
|
5207
5294
|
{
|
|
5208
5295
|
"data-slot": "collapsible-trigger",
|
|
@@ -5213,7 +5300,7 @@ function CollapsibleTrigger({
|
|
|
5213
5300
|
function CollapsibleContent({
|
|
5214
5301
|
...props
|
|
5215
5302
|
}) {
|
|
5216
|
-
return /* @__PURE__ */
|
|
5303
|
+
return /* @__PURE__ */ jsx26(
|
|
5217
5304
|
CollapsiblePrimitive.CollapsibleContent,
|
|
5218
5305
|
{
|
|
5219
5306
|
"data-slot": "collapsible-content",
|
|
@@ -5223,7 +5310,7 @@ function CollapsibleContent({
|
|
|
5223
5310
|
}
|
|
5224
5311
|
|
|
5225
5312
|
// ../../src/patent-render/client/ChatDock.tsx
|
|
5226
|
-
import { jsx as
|
|
5313
|
+
import { jsx as jsx27, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
5227
5314
|
var SUGGESTIONS = [
|
|
5228
5315
|
"Flowchart of the method in claim 1",
|
|
5229
5316
|
"Block diagram of the system with server, network and client devices",
|
|
@@ -5233,75 +5320,75 @@ var SUGGESTIONS = [
|
|
|
5233
5320
|
var MAX_IMAGE_BYTES = 8 * 1024 * 1024;
|
|
5234
5321
|
function PlanCard({ plan, onEdit, defaultOpen = true }) {
|
|
5235
5322
|
const [open, setOpen] = useState6(defaultOpen);
|
|
5236
|
-
return /* @__PURE__ */
|
|
5237
|
-
/* @__PURE__ */
|
|
5238
|
-
/* @__PURE__ */
|
|
5239
|
-
/* @__PURE__ */
|
|
5240
|
-
/* @__PURE__ */
|
|
5241
|
-
/* @__PURE__ */
|
|
5242
|
-
/* @__PURE__ */
|
|
5323
|
+
return /* @__PURE__ */ jsxs17(Collapsible, { open, onOpenChange: setOpen, className: "overflow-hidden rounded-lg border bg-card text-card-foreground", children: [
|
|
5324
|
+
/* @__PURE__ */ jsxs17(CollapsibleTrigger, { className: "flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-accent/40", children: [
|
|
5325
|
+
/* @__PURE__ */ jsx27(Sparkles, { className: "size-3.5 text-muted-foreground" }),
|
|
5326
|
+
/* @__PURE__ */ jsx27("span", { className: "text-xs font-semibold", children: "Figure plan" }),
|
|
5327
|
+
/* @__PURE__ */ jsx27(Badge, { variant: "secondary", className: "h-5 px-1.5 text-[10px]", children: FIGURE_TYPE_LABEL[plan.figureType] }),
|
|
5328
|
+
/* @__PURE__ */ jsx27("span", { className: "min-w-0 flex-1 truncate text-xs text-muted-foreground", children: plan.view }),
|
|
5329
|
+
/* @__PURE__ */ jsx27(ChevronDown2, { className: cn23("size-3.5 text-muted-foreground transition-transform", open && "rotate-180") })
|
|
5243
5330
|
] }),
|
|
5244
|
-
/* @__PURE__ */
|
|
5245
|
-
/* @__PURE__ */
|
|
5246
|
-
plan.spec && /* @__PURE__ */
|
|
5247
|
-
/* @__PURE__ */
|
|
5248
|
-
/* @__PURE__ */
|
|
5331
|
+
/* @__PURE__ */ jsx27(CollapsibleContent, { children: /* @__PURE__ */ jsxs17("div", { className: "grid gap-3 border-t px-3 py-2.5", children: [
|
|
5332
|
+
/* @__PURE__ */ jsx27("p", { className: "text-xs leading-relaxed", children: plan.summary }),
|
|
5333
|
+
plan.spec && /* @__PURE__ */ jsxs17("details", { className: "group rounded-md bg-muted/50 px-2 py-1.5", children: [
|
|
5334
|
+
/* @__PURE__ */ jsx27("summary", { className: "cursor-pointer text-[10px] font-semibold tracking-wide text-muted-foreground uppercase select-none", children: "Full spec" }),
|
|
5335
|
+
/* @__PURE__ */ jsx27("p", { className: "mt-1.5 text-xs leading-relaxed whitespace-pre-wrap", children: plan.spec })
|
|
5249
5336
|
] }),
|
|
5250
|
-
/* @__PURE__ */
|
|
5251
|
-
/* @__PURE__ */
|
|
5252
|
-
/* @__PURE__ */
|
|
5253
|
-
/* @__PURE__ */
|
|
5254
|
-
/* @__PURE__ */
|
|
5337
|
+
/* @__PURE__ */ jsxs17("div", { children: [
|
|
5338
|
+
/* @__PURE__ */ jsx27("div", { className: "mb-1 text-[10px] font-semibold tracking-wide text-muted-foreground uppercase", children: "Reference numerals" }),
|
|
5339
|
+
/* @__PURE__ */ jsx27("table", { className: "w-full text-xs", children: /* @__PURE__ */ jsx27("tbody", { children: plan.components.map((c) => /* @__PURE__ */ jsxs17("tr", { className: "align-top", children: [
|
|
5340
|
+
/* @__PURE__ */ jsx27("td", { className: "w-12 py-0.5 font-medium tabular-nums", children: c.numeral }),
|
|
5341
|
+
/* @__PURE__ */ jsxs17("td", { className: "py-0.5", children: [
|
|
5255
5342
|
c.name,
|
|
5256
|
-
c.reused && /* @__PURE__ */
|
|
5343
|
+
c.reused && /* @__PURE__ */ jsx27("span", { className: "ml-1.5 text-[10px] text-muted-foreground", children: "from spec" })
|
|
5257
5344
|
] })
|
|
5258
5345
|
] }, c.numeral)) }) })
|
|
5259
5346
|
] }),
|
|
5260
|
-
/* @__PURE__ */
|
|
5261
|
-
/* @__PURE__ */
|
|
5262
|
-
plan.layers.map((l) => /* @__PURE__ */
|
|
5347
|
+
/* @__PURE__ */ jsxs17("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
5348
|
+
/* @__PURE__ */ jsx27("span", { className: "mr-1 text-[10px] font-semibold tracking-wide text-muted-foreground uppercase", children: "Layers" }),
|
|
5349
|
+
plan.layers.map((l) => /* @__PURE__ */ jsx27(Badge, { variant: "outline", className: "h-5 px-1.5 text-[10px] font-normal", children: l.name }, l.id))
|
|
5263
5350
|
] }),
|
|
5264
|
-
plan.notes.length > 0 && /* @__PURE__ */
|
|
5351
|
+
plan.notes.length > 0 && /* @__PURE__ */ jsx27("ul", { className: "grid gap-0.5 text-[11px] text-muted-foreground", children: plan.notes.map((n, i) => /* @__PURE__ */ jsxs17("li", { children: [
|
|
5265
5352
|
"\xB7 ",
|
|
5266
5353
|
n
|
|
5267
5354
|
] }, i)) }),
|
|
5268
|
-
onEdit && /* @__PURE__ */
|
|
5269
|
-
/* @__PURE__ */
|
|
5355
|
+
onEdit && /* @__PURE__ */ jsx27("div", { children: /* @__PURE__ */ jsxs17(Button, { variant: "outline", size: "sm", className: "h-7 text-xs", onClick: () => onEdit(plan), children: [
|
|
5356
|
+
/* @__PURE__ */ jsx27(Pencil, { className: "size-3" }),
|
|
5270
5357
|
" Edit plan and redraw"
|
|
5271
5358
|
] }) })
|
|
5272
5359
|
] }) })
|
|
5273
5360
|
] });
|
|
5274
5361
|
}
|
|
5275
5362
|
function Progress({ steps }) {
|
|
5276
|
-
return /* @__PURE__ */
|
|
5277
|
-
s.status === "done" ? /* @__PURE__ */
|
|
5363
|
+
return /* @__PURE__ */ jsx27("ol", { className: "grid gap-1", children: steps.map((s, i) => /* @__PURE__ */ jsxs17("li", { className: cn23("flex items-center gap-2 text-xs", s.status === "pending" && "text-muted-foreground"), children: [
|
|
5364
|
+
s.status === "done" ? /* @__PURE__ */ jsx27(Check2, { className: "size-3.5 text-success" }) : s.status === "active" ? /* @__PURE__ */ jsx27(Loader22, { className: "size-3.5 animate-spin" }) : /* @__PURE__ */ jsx27(Circle3, { className: "size-3.5" }),
|
|
5278
5365
|
s.label
|
|
5279
5366
|
] }, i)) });
|
|
5280
5367
|
}
|
|
5281
5368
|
function withBold(text) {
|
|
5282
5369
|
return text.split(/(\*\*[^*]+\*\*)/g).map(
|
|
5283
|
-
(s, i) => s.startsWith("**") && s.endsWith("**") ? /* @__PURE__ */
|
|
5370
|
+
(s, i) => s.startsWith("**") && s.endsWith("**") ? /* @__PURE__ */ jsx27("strong", { children: s.slice(2, -2) }, i) : s
|
|
5284
5371
|
);
|
|
5285
5372
|
}
|
|
5286
5373
|
function Part({ part, onEditPlan }) {
|
|
5287
5374
|
switch (part.type) {
|
|
5288
5375
|
case "text":
|
|
5289
|
-
return /* @__PURE__ */
|
|
5376
|
+
return /* @__PURE__ */ jsx27("p", { className: "text-[13px] leading-relaxed whitespace-pre-wrap", children: withBold(part.text) });
|
|
5290
5377
|
case "image":
|
|
5291
5378
|
return (
|
|
5292
5379
|
// eslint-disable-next-line @next/next/no-img-element
|
|
5293
|
-
/* @__PURE__ */
|
|
5380
|
+
/* @__PURE__ */ jsx27("img", { src: part.url, alt: part.name, className: "max-h-32 rounded-md border object-contain" })
|
|
5294
5381
|
);
|
|
5295
5382
|
case "plan":
|
|
5296
|
-
return /* @__PURE__ */
|
|
5383
|
+
return /* @__PURE__ */ jsx27(PlanCard, { plan: part.plan, onEdit: onEditPlan });
|
|
5297
5384
|
case "progress":
|
|
5298
|
-
return /* @__PURE__ */
|
|
5385
|
+
return /* @__PURE__ */ jsx27(Progress, { steps: part.steps });
|
|
5299
5386
|
case "edits":
|
|
5300
|
-
return /* @__PURE__ */
|
|
5301
|
-
/* @__PURE__ */
|
|
5387
|
+
return /* @__PURE__ */ jsxs17("div", { className: "inline-flex items-center gap-1.5 rounded-md bg-muted px-2 py-1 text-xs", children: [
|
|
5388
|
+
/* @__PURE__ */ jsx27(Wand2, { className: "size-3" }),
|
|
5302
5389
|
" ",
|
|
5303
5390
|
part.summary,
|
|
5304
|
-
/* @__PURE__ */
|
|
5391
|
+
/* @__PURE__ */ jsxs17("span", { className: "text-muted-foreground", children: [
|
|
5305
5392
|
"\xB7 ",
|
|
5306
5393
|
part.count,
|
|
5307
5394
|
" change",
|
|
@@ -5309,8 +5396,8 @@ function Part({ part, onEditPlan }) {
|
|
|
5309
5396
|
] })
|
|
5310
5397
|
] });
|
|
5311
5398
|
case "error":
|
|
5312
|
-
return /* @__PURE__ */
|
|
5313
|
-
/* @__PURE__ */
|
|
5399
|
+
return /* @__PURE__ */ jsxs17("div", { className: "flex items-start gap-1.5 rounded-md border border-destructive/30 bg-destructive/10 px-2 py-1.5 text-xs text-destructive", children: [
|
|
5400
|
+
/* @__PURE__ */ jsx27(TriangleAlert2, { className: "mt-0.5 size-3.5 shrink-0" }),
|
|
5314
5401
|
" ",
|
|
5315
5402
|
part.message
|
|
5316
5403
|
] });
|
|
@@ -5318,32 +5405,32 @@ function Part({ part, onEditPlan }) {
|
|
|
5318
5405
|
}
|
|
5319
5406
|
function Message({ m, onEditPlan }) {
|
|
5320
5407
|
const user = m.role === "user";
|
|
5321
|
-
return /* @__PURE__ */
|
|
5408
|
+
return /* @__PURE__ */ jsx27("div", { className: cn23("flex", user ? "justify-end" : "justify-start"), children: /* @__PURE__ */ jsx27("div", { className: cn23("grid max-w-[min(36rem,85%)] gap-2", user && "justify-items-end rounded-2xl rounded-br-md bg-primary px-3 py-2 text-primary-foreground"), children: m.parts.map((p, i) => /* @__PURE__ */ jsx27(Part, { part: p, onEditPlan }, i)) }) });
|
|
5322
5409
|
}
|
|
5323
5410
|
function PrefPicker({ label, value, display, options, onChange, disabled }) {
|
|
5324
|
-
return /* @__PURE__ */
|
|
5325
|
-
/* @__PURE__ */
|
|
5411
|
+
return /* @__PURE__ */ jsxs17(DropdownMenu, { children: [
|
|
5412
|
+
/* @__PURE__ */ jsx27(DropdownMenuTrigger, { asChild: true, disabled, children: /* @__PURE__ */ jsxs17(
|
|
5326
5413
|
"button",
|
|
5327
5414
|
{
|
|
5328
5415
|
type: "button",
|
|
5329
5416
|
"aria-label": `${label}: ${display}`,
|
|
5330
5417
|
className: "inline-flex h-7 items-center gap-1 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-50",
|
|
5331
5418
|
children: [
|
|
5332
|
-
/* @__PURE__ */
|
|
5419
|
+
/* @__PURE__ */ jsxs17("span", { children: [
|
|
5333
5420
|
label,
|
|
5334
5421
|
":"
|
|
5335
5422
|
] }),
|
|
5336
|
-
/* @__PURE__ */
|
|
5337
|
-
/* @__PURE__ */
|
|
5423
|
+
/* @__PURE__ */ jsx27("span", { className: "font-medium text-foreground", children: display }),
|
|
5424
|
+
/* @__PURE__ */ jsx27(ChevronDown2, { className: "size-3" })
|
|
5338
5425
|
]
|
|
5339
5426
|
}
|
|
5340
5427
|
) }),
|
|
5341
|
-
/* @__PURE__ */
|
|
5342
|
-
/* @__PURE__ */
|
|
5343
|
-
/* @__PURE__ */
|
|
5344
|
-
/* @__PURE__ */
|
|
5345
|
-
/* @__PURE__ */
|
|
5346
|
-
o.hint && /* @__PURE__ */
|
|
5428
|
+
/* @__PURE__ */ jsxs17(DropdownMenuContent, { align: "start", side: "top", className: "w-60", children: [
|
|
5429
|
+
/* @__PURE__ */ jsx27(DropdownMenuLabel, { className: "text-xs", children: label }),
|
|
5430
|
+
/* @__PURE__ */ jsx27(DropdownMenuSeparator, {}),
|
|
5431
|
+
/* @__PURE__ */ jsx27(DropdownMenuRadioGroup, { value, onValueChange: onChange, children: options.map((o) => /* @__PURE__ */ jsx27(DropdownMenuRadioItem, { value: o.value, className: "items-start text-xs", children: /* @__PURE__ */ jsxs17("div", { children: [
|
|
5432
|
+
/* @__PURE__ */ jsx27("div", { children: o.label }),
|
|
5433
|
+
o.hint && /* @__PURE__ */ jsx27("div", { className: "text-[11px] text-muted-foreground", children: o.hint })
|
|
5347
5434
|
] }) }, o.value)) })
|
|
5348
5435
|
] })
|
|
5349
5436
|
] });
|
|
@@ -5358,7 +5445,9 @@ function ChatDock({
|
|
|
5358
5445
|
className,
|
|
5359
5446
|
historyHeight,
|
|
5360
5447
|
collapsed: collapsedProp,
|
|
5361
|
-
onCollapsedChange
|
|
5448
|
+
onCollapsedChange,
|
|
5449
|
+
interrupted,
|
|
5450
|
+
onInterrupted
|
|
5362
5451
|
}) {
|
|
5363
5452
|
const [text, setText] = useState6("");
|
|
5364
5453
|
const [files, setFiles] = useState6([]);
|
|
@@ -5371,10 +5460,10 @@ function ChatDock({
|
|
|
5371
5460
|
const fileRef = useRef3(null);
|
|
5372
5461
|
const taRef = useRef3(null);
|
|
5373
5462
|
const running = status !== "idle";
|
|
5374
|
-
const empty = messages.length === 0;
|
|
5463
|
+
const empty = messages.length === 0 && !interrupted;
|
|
5375
5464
|
useEffect2(() => {
|
|
5376
5465
|
scrollRef.current?.scrollTo({ top: scrollRef.current.scrollHeight, behavior: "smooth" });
|
|
5377
|
-
}, [messages]);
|
|
5466
|
+
}, [messages, interrupted?.id]);
|
|
5378
5467
|
useEffect2(() => {
|
|
5379
5468
|
const ta = taRef.current;
|
|
5380
5469
|
if (!ta) return;
|
|
@@ -5393,7 +5482,15 @@ function ChatDock({
|
|
|
5393
5482
|
setText("");
|
|
5394
5483
|
setFiles([]);
|
|
5395
5484
|
};
|
|
5396
|
-
|
|
5485
|
+
const onInterruptedAction = (action) => {
|
|
5486
|
+
if (action === "edit" && interrupted) {
|
|
5487
|
+
setText(interrupted.request);
|
|
5488
|
+
setFiles(interrupted.attachments);
|
|
5489
|
+
taRef.current?.focus();
|
|
5490
|
+
}
|
|
5491
|
+
onInterrupted?.(action);
|
|
5492
|
+
};
|
|
5493
|
+
return /* @__PURE__ */ jsxs17(
|
|
5397
5494
|
"div",
|
|
5398
5495
|
{
|
|
5399
5496
|
className: cn23("flex min-h-0 flex-col border-t bg-background", className),
|
|
@@ -5413,21 +5510,24 @@ function ChatDock({
|
|
|
5413
5510
|
setDragOver(false);
|
|
5414
5511
|
},
|
|
5415
5512
|
children: [
|
|
5416
|
-
(!empty || onCollapsedChange) && /* @__PURE__ */
|
|
5417
|
-
/* @__PURE__ */
|
|
5418
|
-
/* @__PURE__ */
|
|
5513
|
+
(!empty || onCollapsedChange) && /* @__PURE__ */ jsxs17("div", { className: "flex h-8 shrink-0 items-center justify-between px-3", children: [
|
|
5514
|
+
/* @__PURE__ */ jsx27("span", { className: "text-[11px] font-semibold tracking-wide text-muted-foreground uppercase", children: "Assistant" }),
|
|
5515
|
+
/* @__PURE__ */ jsx27(Button, { variant: "ghost", size: "icon", className: "size-6", "aria-label": collapsed ? "Expand chat" : "Collapse chat", onClick: () => setCollapsed(!collapsed), children: collapsed ? /* @__PURE__ */ jsx27(ChevronUp, { className: "size-3.5" }) : /* @__PURE__ */ jsx27(ChevronDown2, { className: "size-3.5" }) })
|
|
5419
5516
|
] }),
|
|
5420
|
-
!collapsed && !empty && /* @__PURE__ */
|
|
5517
|
+
!collapsed && !empty && /* @__PURE__ */ jsx27(
|
|
5421
5518
|
"div",
|
|
5422
5519
|
{
|
|
5423
5520
|
ref: scrollRef,
|
|
5424
5521
|
className: cn23("min-h-0 overflow-y-auto px-3 pb-2", historyHeight === void 0 && "max-h-[min(15rem,32vh)]"),
|
|
5425
5522
|
style: historyHeight !== void 0 ? { height: historyHeight } : void 0,
|
|
5426
|
-
children: /* @__PURE__ */
|
|
5523
|
+
children: /* @__PURE__ */ jsxs17("div", { className: "mx-auto grid max-w-3xl gap-3", children: [
|
|
5524
|
+
messages.map((m) => /* @__PURE__ */ jsx27(Message, { m, onEditPlan: running ? void 0 : onEditPlan }, m.id)),
|
|
5525
|
+
interrupted && /* @__PURE__ */ jsx27(InterruptedCard, { run: interrupted, onAction: onInterruptedAction })
|
|
5526
|
+
] })
|
|
5427
5527
|
}
|
|
5428
5528
|
),
|
|
5429
|
-
/* @__PURE__ */
|
|
5430
|
-
empty && !collapsed && /* @__PURE__ */
|
|
5529
|
+
/* @__PURE__ */ jsx27("div", { className: "shrink-0 px-3 pt-1 pb-3", children: /* @__PURE__ */ jsxs17("div", { className: "mx-auto max-w-3xl", children: [
|
|
5530
|
+
empty && !collapsed && /* @__PURE__ */ jsx27("div", { className: "mb-2 flex flex-wrap gap-1.5", children: SUGGESTIONS.map((s) => /* @__PURE__ */ jsx27(
|
|
5431
5531
|
"button",
|
|
5432
5532
|
{
|
|
5433
5533
|
type: "button",
|
|
@@ -5440,24 +5540,24 @@ function ChatDock({
|
|
|
5440
5540
|
},
|
|
5441
5541
|
s
|
|
5442
5542
|
)) }),
|
|
5443
|
-
/* @__PURE__ */
|
|
5543
|
+
/* @__PURE__ */ jsxs17("div", { className: cn23(
|
|
5444
5544
|
"rounded-xl border bg-background shadow-sm transition-shadow focus-within:ring-2 focus-within:ring-ring/40",
|
|
5445
5545
|
dragOver && "ring-2 ring-ring"
|
|
5446
5546
|
), children: [
|
|
5447
|
-
files.length > 0 && /* @__PURE__ */
|
|
5448
|
-
/* @__PURE__ */
|
|
5449
|
-
/* @__PURE__ */
|
|
5547
|
+
files.length > 0 && /* @__PURE__ */ jsx27("div", { className: "flex flex-wrap items-center gap-1.5 px-2 pt-2", children: files.map((f) => /* @__PURE__ */ jsxs17("div", { className: "group relative", children: [
|
|
5548
|
+
/* @__PURE__ */ jsx27("img", { src: f.url, alt: f.name, className: "size-12 rounded-md border object-cover" }),
|
|
5549
|
+
/* @__PURE__ */ jsx27(
|
|
5450
5550
|
"button",
|
|
5451
5551
|
{
|
|
5452
5552
|
type: "button",
|
|
5453
5553
|
"aria-label": `Remove ${f.name}`,
|
|
5454
5554
|
className: "absolute -top-1.5 -right-1.5 hidden size-4 items-center justify-center rounded-full bg-foreground text-background group-hover:flex",
|
|
5455
5555
|
onClick: () => setFiles(files.filter((x) => x.id !== f.id)),
|
|
5456
|
-
children: /* @__PURE__ */
|
|
5556
|
+
children: /* @__PURE__ */ jsx27(X, { className: "size-2.5" })
|
|
5457
5557
|
}
|
|
5458
5558
|
)
|
|
5459
5559
|
] }, f.id)) }),
|
|
5460
|
-
/* @__PURE__ */
|
|
5560
|
+
/* @__PURE__ */ jsx27(
|
|
5461
5561
|
"textarea",
|
|
5462
5562
|
{
|
|
5463
5563
|
ref: taRef,
|
|
@@ -5476,14 +5576,14 @@ function ChatDock({
|
|
|
5476
5576
|
className: "block w-full resize-none bg-transparent px-3 py-2.5 text-sm outline-none placeholder:text-muted-foreground"
|
|
5477
5577
|
}
|
|
5478
5578
|
),
|
|
5479
|
-
/* @__PURE__ */
|
|
5480
|
-
/* @__PURE__ */
|
|
5481
|
-
/* @__PURE__ */
|
|
5579
|
+
/* @__PURE__ */ jsxs17("div", { className: "flex items-center justify-between px-1.5 pb-1.5", children: [
|
|
5580
|
+
/* @__PURE__ */ jsxs17("div", { className: "flex min-w-0 items-center gap-1.5", children: [
|
|
5581
|
+
/* @__PURE__ */ jsx27("input", { ref: fileRef, type: "file", accept: "image/*", multiple: true, hidden: true, onChange: (e) => {
|
|
5482
5582
|
addFiles(e.target.files);
|
|
5483
5583
|
e.target.value = "";
|
|
5484
5584
|
} }),
|
|
5485
|
-
/* @__PURE__ */
|
|
5486
|
-
/* @__PURE__ */
|
|
5585
|
+
/* @__PURE__ */ jsx27(Button, { variant: "ghost", size: "icon", className: "size-7", "aria-label": "Attach reference image", disabled: running, onClick: () => fileRef.current?.click(), children: /* @__PURE__ */ jsx27(ImagePlus, { className: "size-4" }) }),
|
|
5586
|
+
/* @__PURE__ */ jsx27(
|
|
5487
5587
|
PrefPicker,
|
|
5488
5588
|
{
|
|
5489
5589
|
label: "Figure",
|
|
@@ -5494,7 +5594,7 @@ function ChatDock({
|
|
|
5494
5594
|
disabled: running
|
|
5495
5595
|
}
|
|
5496
5596
|
),
|
|
5497
|
-
/* @__PURE__ */
|
|
5597
|
+
/* @__PURE__ */ jsx27(
|
|
5498
5598
|
PrefPicker,
|
|
5499
5599
|
{
|
|
5500
5600
|
label: "Style",
|
|
@@ -5505,15 +5605,15 @@ function ChatDock({
|
|
|
5505
5605
|
disabled: running
|
|
5506
5606
|
}
|
|
5507
5607
|
),
|
|
5508
|
-
selectionCount > 0 && /* @__PURE__ */
|
|
5509
|
-
/* @__PURE__ */
|
|
5608
|
+
selectionCount > 0 && /* @__PURE__ */ jsxs17(Badge, { variant: "secondary", className: "h-6 gap-1 truncate text-[11px] font-normal", children: [
|
|
5609
|
+
/* @__PURE__ */ jsx27(MousePointerClick, { className: "size-3" }),
|
|
5510
5610
|
" Editing ",
|
|
5511
5611
|
selectionCount,
|
|
5512
5612
|
" selected item",
|
|
5513
5613
|
selectionCount === 1 ? "" : "s"
|
|
5514
5614
|
] })
|
|
5515
5615
|
] }),
|
|
5516
|
-
running ? /* @__PURE__ */
|
|
5616
|
+
running ? /* @__PURE__ */ jsx27(Button, { size: "icon", variant: "secondary", className: "size-7 rounded-full", "aria-label": "Stop", onClick: onStop, children: /* @__PURE__ */ jsx27(Square3, { className: "size-3 fill-current" }) }) : /* @__PURE__ */ jsx27(Button, { size: "icon", className: "size-7 rounded-full", "aria-label": "Send", disabled: !text.trim() && !files.length, onClick: send, children: /* @__PURE__ */ jsx27(ArrowUp, { className: "size-4" }) })
|
|
5517
5617
|
] })
|
|
5518
5618
|
] })
|
|
5519
5619
|
] }) })
|
|
@@ -5522,13 +5622,42 @@ function ChatDock({
|
|
|
5522
5622
|
);
|
|
5523
5623
|
}
|
|
5524
5624
|
|
|
5625
|
+
// ../../src/patent-render/ui/confirm-dialog.tsx
|
|
5626
|
+
import { AlertDialog as AlertDialogPrimitive } from "radix-ui";
|
|
5627
|
+
import { Fragment as Fragment6, jsx as jsx28, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
5628
|
+
function ConfirmDialog({ open, title, children, confirmLabel, cancelLabel, destructive, safe = "cancel", onConfirm, onCancel }) {
|
|
5629
|
+
return /* @__PURE__ */ jsxs18(AlertDialogPrimitive.Root, { open, onOpenChange: (o) => {
|
|
5630
|
+
if (!o) onCancel();
|
|
5631
|
+
}, children: [
|
|
5632
|
+
/* @__PURE__ */ jsx28(AlertDialogPrimitive.Overlay, { className: "absolute inset-0 z-50 bg-black/45" }),
|
|
5633
|
+
/* @__PURE__ */ jsx28("div", { className: "pointer-events-none absolute inset-0 z-50 grid place-items-center p-4", children: /* @__PURE__ */ jsxs18(
|
|
5634
|
+
AlertDialogPrimitive.Content,
|
|
5635
|
+
{
|
|
5636
|
+
"data-slot": "pr-confirm",
|
|
5637
|
+
className: "pointer-events-auto w-full max-w-sm rounded-xl border bg-background p-5 text-foreground shadow-lg outline-none",
|
|
5638
|
+
children: [
|
|
5639
|
+
/* @__PURE__ */ jsx28(AlertDialogPrimitive.Title, { className: "text-sm font-semibold", children: title }),
|
|
5640
|
+
/* @__PURE__ */ jsx28(AlertDialogPrimitive.Description, { className: "mt-1.5 text-[13px] leading-relaxed text-muted-foreground", children }),
|
|
5641
|
+
/* @__PURE__ */ jsx28("div", { className: "mt-4 flex flex-wrap justify-end gap-2", children: safe === "cancel" ? /* @__PURE__ */ jsxs18(Fragment6, { children: [
|
|
5642
|
+
/* @__PURE__ */ jsx28(AlertDialogPrimitive.Action, { asChild: true, children: /* @__PURE__ */ jsx28(Button, { variant: "outline", size: "sm", onClick: onConfirm, children: confirmLabel }) }),
|
|
5643
|
+
/* @__PURE__ */ jsx28(AlertDialogPrimitive.Cancel, { asChild: true, children: /* @__PURE__ */ jsx28(Button, { size: "sm", children: cancelLabel }) })
|
|
5644
|
+
] }) : /* @__PURE__ */ jsxs18(Fragment6, { children: [
|
|
5645
|
+
/* @__PURE__ */ jsx28(AlertDialogPrimitive.Cancel, { asChild: true, children: /* @__PURE__ */ jsx28(Button, { variant: "outline", size: "sm", children: cancelLabel }) }),
|
|
5646
|
+
/* @__PURE__ */ jsx28(AlertDialogPrimitive.Action, { asChild: true, children: /* @__PURE__ */ jsx28(Button, { variant: destructive ? "destructive" : "default", size: "sm", onClick: onConfirm, children: confirmLabel }) })
|
|
5647
|
+
] }) })
|
|
5648
|
+
]
|
|
5649
|
+
}
|
|
5650
|
+
) })
|
|
5651
|
+
] });
|
|
5652
|
+
}
|
|
5653
|
+
|
|
5525
5654
|
// ../../src/patent-render/client/PatentRenderEditor.tsx
|
|
5526
5655
|
import { PanelRightClose, PanelRightOpen } from "lucide-react";
|
|
5527
5656
|
|
|
5528
5657
|
// ../../src/patent-render/client/layout.tsx
|
|
5529
5658
|
import { useCallback as useCallback3, useEffect as useEffect3, useRef as useRef4, useState as useState7 } from "react";
|
|
5530
5659
|
import { cn as cn24 } from "cn";
|
|
5531
|
-
import { jsx as
|
|
5660
|
+
import { jsx as jsx29 } from "react/jsx-runtime";
|
|
5532
5661
|
var DEFAULT = { sideWidth: 288, sideOpen: true, split: 0.5, chatHeight: 220, chatOpen: true };
|
|
5533
5662
|
var KEY = "patent-render:layout:v1";
|
|
5534
5663
|
var LIMITS = { side: [220, 520], chat: [80, 560], split: [0.15, 0.85] };
|
|
@@ -5576,7 +5705,7 @@ function ResizeHandle({ axis, onDrag, onToggle, label, className }) {
|
|
|
5576
5705
|
last.current = null;
|
|
5577
5706
|
setActive(false);
|
|
5578
5707
|
};
|
|
5579
|
-
return /* @__PURE__ */
|
|
5708
|
+
return /* @__PURE__ */ jsx29(
|
|
5580
5709
|
"div",
|
|
5581
5710
|
{
|
|
5582
5711
|
role: "separator",
|
|
@@ -5609,7 +5738,7 @@ function ResizeHandle({ axis, onDrag, onToggle, label, className }) {
|
|
|
5609
5738
|
axis === "x" ? "-mx-1 w-2 cursor-col-resize" : "-my-1 h-2 cursor-row-resize",
|
|
5610
5739
|
className
|
|
5611
5740
|
),
|
|
5612
|
-
children: /* @__PURE__ */
|
|
5741
|
+
children: /* @__PURE__ */ jsx29("span", { className: cn24(
|
|
5613
5742
|
"absolute rounded-full bg-ring/0 transition-colors group-hover:bg-ring/50 group-focus-visible:bg-ring/70",
|
|
5614
5743
|
axis === "x" ? "inset-y-0 left-1/2 w-0.5 -translate-x-1/2" : "inset-x-0 top-1/2 h-0.5 -translate-y-1/2",
|
|
5615
5744
|
active && "bg-ring/70"
|
|
@@ -5619,14 +5748,14 @@ function ResizeHandle({ axis, onDrag, onToggle, label, className }) {
|
|
|
5619
5748
|
}
|
|
5620
5749
|
|
|
5621
5750
|
// ../../src/patent-render/client/PatentRenderEditor.tsx
|
|
5622
|
-
import { Fragment as
|
|
5751
|
+
import { Fragment as Fragment7, jsx as jsx30, jsxs as jsxs19 } from "react/jsx-runtime";
|
|
5623
5752
|
function PatentRenderEditor(props) {
|
|
5624
|
-
return /* @__PURE__ */
|
|
5625
|
-
/* @__PURE__ */
|
|
5753
|
+
return /* @__PURE__ */ jsx30(TooltipProvider, { delayDuration: 400, children: /* @__PURE__ */ jsxs19(EditorProvider, { doc: props.document, initial: { agent: props.agentStatus ?? "idle", ...props.initialState }, children: [
|
|
5754
|
+
/* @__PURE__ */ jsx30(PatentRenderShell, { ...props }),
|
|
5626
5755
|
props.children
|
|
5627
5756
|
] }) });
|
|
5628
5757
|
}
|
|
5629
|
-
function PatentRenderShell({ chat, agentStatus = "idle", onEmbed, onCancel, onChange, className }) {
|
|
5758
|
+
function PatentRenderShell({ chat, agentStatus = "idle", onEmbed, onCancel, onInterrupt, onChange, className }) {
|
|
5630
5759
|
const ed = useEditor();
|
|
5631
5760
|
const rootRef = useRef5(null);
|
|
5632
5761
|
const [embedding, setEmbedding] = useState8(false);
|
|
@@ -5644,6 +5773,17 @@ function PatentRenderShell({ chat, agentStatus = "idle", onEmbed, onCancel, onCh
|
|
|
5644
5773
|
}
|
|
5645
5774
|
onChange?.(ed.state.doc);
|
|
5646
5775
|
}, [ed.state.doc]);
|
|
5776
|
+
const running = agentStatus !== "idle";
|
|
5777
|
+
const [confirming, setConfirming] = useState8(null);
|
|
5778
|
+
const { interrupted, onInterrupted } = chat;
|
|
5779
|
+
const interruptedId = interrupted?.id;
|
|
5780
|
+
useEffect4(() => {
|
|
5781
|
+
if (interruptedId) update((l) => ({ chatOpen: true, chatHeight: Math.max(l.chatHeight, 180) }));
|
|
5782
|
+
}, [interruptedId, update]);
|
|
5783
|
+
const resolveInterrupted = (action) => {
|
|
5784
|
+
if (action === "restart" && interrupted?.drawn) setConfirming("restart");
|
|
5785
|
+
else onInterrupted?.(action);
|
|
5786
|
+
};
|
|
5647
5787
|
const embed = async () => {
|
|
5648
5788
|
if (!onEmbed || !ed.report.ok) return;
|
|
5649
5789
|
setEmbedding(true);
|
|
@@ -5655,25 +5795,32 @@ function PatentRenderShell({ chat, agentStatus = "idle", onEmbed, onCancel, onCh
|
|
|
5655
5795
|
setEmbedding(false);
|
|
5656
5796
|
}
|
|
5657
5797
|
};
|
|
5658
|
-
return /* @__PURE__ */
|
|
5798
|
+
return /* @__PURE__ */ jsxs19(
|
|
5659
5799
|
"div",
|
|
5660
5800
|
{
|
|
5661
5801
|
ref: rootRef,
|
|
5662
5802
|
tabIndex: -1,
|
|
5663
5803
|
onPointerDownCapture: (e) => {
|
|
5664
|
-
if (!e.target.closest("input, textarea, select, button, [role=option]")) rootRef.current?.focus({ preventScroll: true });
|
|
5804
|
+
if (!e.target.closest("input, textarea, select, button, [role=option], [role=alertdialog]")) rootRef.current?.focus({ preventScroll: true });
|
|
5665
5805
|
},
|
|
5666
|
-
className: cn25("flex h-full min-h-[560px] w-full flex-col overflow-hidden bg-background text-foreground outline-none", className),
|
|
5806
|
+
className: cn25("relative flex h-full min-h-[560px] w-full flex-col overflow-hidden bg-background text-foreground outline-none", className),
|
|
5667
5807
|
"data-slot": "patent-render",
|
|
5668
5808
|
children: [
|
|
5669
|
-
/* @__PURE__ */
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5809
|
+
/* @__PURE__ */ jsx30(
|
|
5810
|
+
HeaderBar,
|
|
5811
|
+
{
|
|
5812
|
+
onEmbed: onEmbed ? embed : void 0,
|
|
5813
|
+
embedding,
|
|
5814
|
+
onCancel: onCancel ? () => running ? setConfirming("cancel") : onCancel() : void 0
|
|
5815
|
+
}
|
|
5816
|
+
),
|
|
5817
|
+
/* @__PURE__ */ jsxs19("div", { className: "flex min-h-0 flex-1", children: [
|
|
5818
|
+
/* @__PURE__ */ jsxs19("div", { className: "flex min-w-0 flex-1 flex-col", children: [
|
|
5819
|
+
/* @__PURE__ */ jsxs19("div", { className: "relative min-h-0 flex-1", children: [
|
|
5820
|
+
/* @__PURE__ */ jsx30(Canvas, {}),
|
|
5821
|
+
/* @__PURE__ */ jsx30(Toolbox, { className: "absolute top-3 left-3" }),
|
|
5822
|
+
/* @__PURE__ */ jsx30(SelectionBar, { className: "absolute top-3 left-1/2 -translate-x-1/2" }),
|
|
5823
|
+
!layout.sideOpen && /* @__PURE__ */ jsx30(
|
|
5677
5824
|
Button,
|
|
5678
5825
|
{
|
|
5679
5826
|
variant: "outline",
|
|
@@ -5681,11 +5828,11 @@ function PatentRenderShell({ chat, agentStatus = "idle", onEmbed, onCancel, onCh
|
|
|
5681
5828
|
className: "absolute top-3 right-3 size-8 bg-background/95 shadow-sm",
|
|
5682
5829
|
"aria-label": "Show layers and inspector",
|
|
5683
5830
|
onClick: () => update(() => ({ sideOpen: true })),
|
|
5684
|
-
children: /* @__PURE__ */
|
|
5831
|
+
children: /* @__PURE__ */ jsx30(PanelRightOpen, {})
|
|
5685
5832
|
}
|
|
5686
5833
|
)
|
|
5687
5834
|
] }),
|
|
5688
|
-
/* @__PURE__ */
|
|
5835
|
+
/* @__PURE__ */ jsx30(
|
|
5689
5836
|
ResizeHandle,
|
|
5690
5837
|
{
|
|
5691
5838
|
axis: "y",
|
|
@@ -5694,10 +5841,11 @@ function PatentRenderShell({ chat, agentStatus = "idle", onEmbed, onCancel, onCh
|
|
|
5694
5841
|
onToggle: () => update((l) => ({ chatOpen: !l.chatOpen }))
|
|
5695
5842
|
}
|
|
5696
5843
|
),
|
|
5697
|
-
/* @__PURE__ */
|
|
5844
|
+
/* @__PURE__ */ jsx30(
|
|
5698
5845
|
ChatDock,
|
|
5699
5846
|
{
|
|
5700
5847
|
...chat,
|
|
5848
|
+
onInterrupted: resolveInterrupted,
|
|
5701
5849
|
status: agentStatus,
|
|
5702
5850
|
selectionCount: ed.state.selection.length,
|
|
5703
5851
|
historyHeight: layout.chatHeight,
|
|
@@ -5706,8 +5854,8 @@ function PatentRenderShell({ chat, agentStatus = "idle", onEmbed, onCancel, onCh
|
|
|
5706
5854
|
}
|
|
5707
5855
|
)
|
|
5708
5856
|
] }),
|
|
5709
|
-
layout.sideOpen && /* @__PURE__ */
|
|
5710
|
-
/* @__PURE__ */
|
|
5857
|
+
layout.sideOpen && /* @__PURE__ */ jsxs19(Fragment7, { children: [
|
|
5858
|
+
/* @__PURE__ */ jsx30(
|
|
5711
5859
|
ResizeHandle,
|
|
5712
5860
|
{
|
|
5713
5861
|
axis: "x",
|
|
@@ -5716,10 +5864,10 @@ function PatentRenderShell({ chat, agentStatus = "idle", onEmbed, onCancel, onCh
|
|
|
5716
5864
|
onToggle: () => update(() => ({ sideOpen: false }))
|
|
5717
5865
|
}
|
|
5718
5866
|
),
|
|
5719
|
-
/* @__PURE__ */
|
|
5720
|
-
/* @__PURE__ */
|
|
5721
|
-
/* @__PURE__ */
|
|
5722
|
-
/* @__PURE__ */
|
|
5867
|
+
/* @__PURE__ */ jsxs19("aside", { ref: asideRef, className: "flex shrink-0 flex-col border-l bg-background", style: { width: layout.sideWidth }, children: [
|
|
5868
|
+
/* @__PURE__ */ jsxs19("div", { className: "relative flex min-h-0 flex-col", style: { flex: `${layout.split} 1 0` }, children: [
|
|
5869
|
+
/* @__PURE__ */ jsx30(LayersPanel, { className: "min-h-0 flex-1" }),
|
|
5870
|
+
/* @__PURE__ */ jsx30(
|
|
5723
5871
|
Button,
|
|
5724
5872
|
{
|
|
5725
5873
|
variant: "ghost",
|
|
@@ -5727,11 +5875,11 @@ function PatentRenderShell({ chat, agentStatus = "idle", onEmbed, onCancel, onCh
|
|
|
5727
5875
|
className: "absolute top-1.5 right-9 size-6",
|
|
5728
5876
|
"aria-label": "Hide side panel",
|
|
5729
5877
|
onClick: () => update(() => ({ sideOpen: false })),
|
|
5730
|
-
children: /* @__PURE__ */
|
|
5878
|
+
children: /* @__PURE__ */ jsx30(PanelRightClose, { className: "size-3.5" })
|
|
5731
5879
|
}
|
|
5732
5880
|
)
|
|
5733
5881
|
] }),
|
|
5734
|
-
/* @__PURE__ */
|
|
5882
|
+
/* @__PURE__ */ jsx30(
|
|
5735
5883
|
ResizeHandle,
|
|
5736
5884
|
{
|
|
5737
5885
|
axis: "y",
|
|
@@ -5739,10 +5887,52 @@ function PatentRenderShell({ chat, agentStatus = "idle", onEmbed, onCancel, onCh
|
|
|
5739
5887
|
onDrag: (d) => update((l) => ({ split: l.split + d / Math.max(1, asideRef.current?.clientHeight ?? 600) }))
|
|
5740
5888
|
}
|
|
5741
5889
|
),
|
|
5742
|
-
/* @__PURE__ */
|
|
5890
|
+
/* @__PURE__ */ jsx30(Inspector, { className: "min-h-0 border-t", style: { flex: `${1 - layout.split} 1 0` } })
|
|
5743
5891
|
] })
|
|
5744
5892
|
] })
|
|
5745
|
-
] })
|
|
5893
|
+
] }),
|
|
5894
|
+
/* @__PURE__ */ jsxs19(
|
|
5895
|
+
ConfirmDialog,
|
|
5896
|
+
{
|
|
5897
|
+
open: confirming === "cancel" && running,
|
|
5898
|
+
title: "Stop drawing and close?",
|
|
5899
|
+
confirmLabel: "Stop and close",
|
|
5900
|
+
cancelLabel: "Keep drawing",
|
|
5901
|
+
onCancel: () => setConfirming(null),
|
|
5902
|
+
onConfirm: () => {
|
|
5903
|
+
setConfirming(null);
|
|
5904
|
+
onInterrupt?.();
|
|
5905
|
+
onCancel?.();
|
|
5906
|
+
},
|
|
5907
|
+
children: [
|
|
5908
|
+
"The assistant is still drawing FIG. ",
|
|
5909
|
+
ed.state.doc.figureNumber,
|
|
5910
|
+
".",
|
|
5911
|
+
" ",
|
|
5912
|
+
onChange ? "Finished steps are kept, and you can continue when you reopen this figure." : "Its unfinished work will be lost."
|
|
5913
|
+
]
|
|
5914
|
+
}
|
|
5915
|
+
),
|
|
5916
|
+
/* @__PURE__ */ jsxs19(
|
|
5917
|
+
ConfirmDialog,
|
|
5918
|
+
{
|
|
5919
|
+
open: confirming === "restart" && !!interrupted,
|
|
5920
|
+
title: "Start this drawing over?",
|
|
5921
|
+
safe: "confirm",
|
|
5922
|
+
destructive: true,
|
|
5923
|
+
confirmLabel: "Start over",
|
|
5924
|
+
cancelLabel: "Cancel",
|
|
5925
|
+
onCancel: () => setConfirming(null),
|
|
5926
|
+
onConfirm: () => {
|
|
5927
|
+
setConfirming(null);
|
|
5928
|
+
onInterrupted?.("restart");
|
|
5929
|
+
},
|
|
5930
|
+
children: [
|
|
5931
|
+
interrupted?.drawn === 1 ? "The 1 item drawn so far will be removed" : `The ${interrupted?.drawn ?? 0} items drawn so far will be removed`,
|
|
5932
|
+
", and the assistant will draw your request again."
|
|
5933
|
+
]
|
|
5934
|
+
}
|
|
5935
|
+
)
|
|
5746
5936
|
]
|
|
5747
5937
|
}
|
|
5748
5938
|
);
|
|
@@ -5758,7 +5948,7 @@ function useShortcuts(rootRef) {
|
|
|
5758
5948
|
if (!root) return;
|
|
5759
5949
|
const onKey = (e) => {
|
|
5760
5950
|
const t = e.target;
|
|
5761
|
-
if (t.closest("input, textarea, select, [contenteditable=true]")) return;
|
|
5951
|
+
if (t.closest("input, textarea, select, [contenteditable=true], [role=alertdialog]")) return;
|
|
5762
5952
|
const ed2 = edRef.current;
|
|
5763
5953
|
const { doc, selection } = ed2.state;
|
|
5764
5954
|
const mod = e.metaKey || e.ctrlKey;
|
|
@@ -5828,6 +6018,76 @@ function useShortcuts(rootRef) {
|
|
|
5828
6018
|
import { useCallback as useCallback4, useEffect as useEffect5, useMemo as useMemo4, useRef as useRef6, useState as useState9 } from "react";
|
|
5829
6019
|
import { fetchServerSentEvents, useChat } from "@tanstack/ai-react";
|
|
5830
6020
|
|
|
6021
|
+
// ../../src/patent-render/schema/run.ts
|
|
6022
|
+
import { z as z4 } from "zod";
|
|
6023
|
+
var RunResume = z4.object({
|
|
6024
|
+
kind: z4.enum(["new", "edit"]),
|
|
6025
|
+
request: z4.string(),
|
|
6026
|
+
plan: FigurePlan.optional(),
|
|
6027
|
+
steps: z4.array(z4.string()).default([])
|
|
6028
|
+
});
|
|
6029
|
+
function isNewFigure(doc) {
|
|
6030
|
+
return doc.layers.every((l) => l.items.every((i) => i.type === "figLabel"));
|
|
6031
|
+
}
|
|
6032
|
+
function snapshotOf(doc) {
|
|
6033
|
+
const { jurisdiction, sheet, layers, numerals, lettering, view, explodeLines, sheetLabel } = doc;
|
|
6034
|
+
return { jurisdiction, sheet, layers, numerals, lettering, view, explodeLines, ...sheetLabel ? { sheetLabel } : {} };
|
|
6035
|
+
}
|
|
6036
|
+
function restorePatch(doc, to) {
|
|
6037
|
+
const patches = [
|
|
6038
|
+
...doc.layers.map((l) => ({ op: "removeLayer", id: l.id })),
|
|
6039
|
+
...to.layers.map((layer) => ({ op: "addLayer", layer })),
|
|
6040
|
+
...Object.keys(doc.numerals).filter((n) => !(n in to.numerals)).map((n) => ({ op: "setNumeral", n, label: null })),
|
|
6041
|
+
...Object.entries(to.numerals).filter(([n, label]) => doc.numerals[n] !== label).map(([n, label]) => ({ op: "setNumeral", n, label })),
|
|
6042
|
+
{ op: "setSheet", sheet: to.sheet },
|
|
6043
|
+
{ op: "setJurisdiction", jurisdiction: to.jurisdiction },
|
|
6044
|
+
{ op: "setLettering", lettering: to.lettering },
|
|
6045
|
+
{ op: "setView", view: to.view, explodeLines: to.explodeLines },
|
|
6046
|
+
{ op: "setSheetLabel", sheetLabel: to.sheetLabel ?? null }
|
|
6047
|
+
];
|
|
6048
|
+
return { op: "batch", patches };
|
|
6049
|
+
}
|
|
6050
|
+
function countEdits(patch) {
|
|
6051
|
+
return patch.op === "batch" ? patch.patches.reduce((n, p) => n + countEdits(p), 0) : 1;
|
|
6052
|
+
}
|
|
6053
|
+
function drawnSince(doc, before) {
|
|
6054
|
+
const had = new Set(before.layers.flatMap((l) => l.items.map((i) => i.id)));
|
|
6055
|
+
return doc.layers.flatMap((l) => l.items).filter((i) => !had.has(i.id)).length;
|
|
6056
|
+
}
|
|
6057
|
+
function repairTranscript(messages) {
|
|
6058
|
+
let changed = false;
|
|
6059
|
+
const out = [];
|
|
6060
|
+
const answered = new Set(messages.flatMap((m) => m.parts ?? []).filter((p) => p.type === "tool-result").map((p) => p.toolCallId));
|
|
6061
|
+
messages.forEach((message, index) => {
|
|
6062
|
+
const m = message;
|
|
6063
|
+
if (m.role !== "assistant" || !Array.isArray(m.parts)) {
|
|
6064
|
+
out.push(message);
|
|
6065
|
+
return;
|
|
6066
|
+
}
|
|
6067
|
+
const parts = m.parts.filter((p) => p.type !== "tool-call" || answered.has(p.id));
|
|
6068
|
+
if (parts.length !== m.parts.length || index === messages.length - 1) {
|
|
6069
|
+
while (parts.at(-1)?.type === "thinking") parts.pop();
|
|
6070
|
+
}
|
|
6071
|
+
if (parts.length === m.parts.length) {
|
|
6072
|
+
out.push(message);
|
|
6073
|
+
return;
|
|
6074
|
+
}
|
|
6075
|
+
changed = true;
|
|
6076
|
+
const useful = parts.some((p) => p.type === "tool-call" || p.type === "text" && String(p.content ?? "").trim());
|
|
6077
|
+
if (useful) out.push({ ...message, parts });
|
|
6078
|
+
});
|
|
6079
|
+
return changed ? out : messages;
|
|
6080
|
+
}
|
|
6081
|
+
function doneLabel(label) {
|
|
6082
|
+
return label.replace(/^Planning /, "Planned ").replace(/^Drawing (?=\S)/, "Drew ").replace(/^Reviewing /, "Reviewed ").replace(/^Applying /, "Applied ");
|
|
6083
|
+
}
|
|
6084
|
+
var MAX_STEPS = 6;
|
|
6085
|
+
function interruptionSteps(run) {
|
|
6086
|
+
const labels = run.steps.filter((s, i) => s.label !== "Drawing" || i === run.steps.length - 1);
|
|
6087
|
+
const all = labels.map((s) => s.status === "active" ? { label: `Stopped while ${s.label.charAt(0).toLowerCase()}${s.label.slice(1)}`, status: "stopped" } : { label: doneLabel(s.label), status: "done" });
|
|
6088
|
+
return { steps: all.slice(-MAX_STEPS), hidden: Math.max(0, all.length - MAX_STEPS) };
|
|
6089
|
+
}
|
|
6090
|
+
|
|
5831
6091
|
// ../../src/patent-render/protocol.ts
|
|
5832
6092
|
var EVENTS = {
|
|
5833
6093
|
patch: "pr.patch",
|
|
@@ -5853,6 +6113,19 @@ function imageUrl(part) {
|
|
|
5853
6113
|
if (s.type === "data") return `data:${s.mimeType ?? "image/png"};base64,${s.value}`;
|
|
5854
6114
|
return null;
|
|
5855
6115
|
}
|
|
6116
|
+
function messageAttachments(m) {
|
|
6117
|
+
if (m?.role !== "user") return [];
|
|
6118
|
+
return m.parts.flatMap((p, i) => {
|
|
6119
|
+
const url = p.type === "image" ? imageUrl(p) : null;
|
|
6120
|
+
return url ? [{ id: `${m.id}-${i}`, name: "attachment", url }] : [];
|
|
6121
|
+
});
|
|
6122
|
+
}
|
|
6123
|
+
function finishedRun(chunk) {
|
|
6124
|
+
const c = chunk;
|
|
6125
|
+
if (c.metadata?.tanstack?.model === "connect-wrapper") return false;
|
|
6126
|
+
const reason = c.finishReason ?? c.metadata?.tanstack?.finishReason;
|
|
6127
|
+
return reason === void 0 || reason === null || reason === "stop";
|
|
6128
|
+
}
|
|
5856
6129
|
function friendlyError(e) {
|
|
5857
6130
|
const status = /status:? (\d{3})/.exec(e.message)?.[1];
|
|
5858
6131
|
if (status === "503") return "The drawing assistant isn't configured on the server yet (model API key missing). Manual editing still works.";
|
|
@@ -5860,32 +6133,60 @@ function friendlyError(e) {
|
|
|
5860
6133
|
if (status === "400") return "The assistant couldn't read this figure. Try again; if it persists, reopen the editor.";
|
|
5861
6134
|
if (status === "429") return "The assistant is busy (rate limited). Wait a moment and try again.";
|
|
5862
6135
|
if (status && status.startsWith("5")) return "The assistant hit a server error. Changes made so far are kept; try again.";
|
|
6136
|
+
if (/terminated|network|failed to fetch|fetch failed|load failed|connection|aborted/i.test(e.message)) return "The connection to the assistant was lost. Changes made so far are kept.";
|
|
5863
6137
|
return e.message || "The assistant hit an error. Changes made so far are kept.";
|
|
5864
6138
|
}
|
|
6139
|
+
var FAILED_START_MS = 1500;
|
|
5865
6140
|
function useAgentChat({ endpoint, context }) {
|
|
5866
6141
|
const ed = useEditor();
|
|
5867
6142
|
const edRef = useRef6(ed);
|
|
5868
6143
|
useEffect5(() => {
|
|
5869
6144
|
edRef.current = ed;
|
|
5870
6145
|
});
|
|
5871
|
-
const [
|
|
5872
|
-
const [turn, setTurn] = useState9(
|
|
5873
|
-
const turnRef = useRef6(
|
|
6146
|
+
const [initialChat] = useState9(() => repairTranscript(ed.state.doc.chat));
|
|
6147
|
+
const [turn, setTurn] = useState9(() => initialChat.filter((m) => m.role === "user").length);
|
|
6148
|
+
const turnRef = useRef6(turn);
|
|
6149
|
+
const [meta, setMeta] = useState9(() => {
|
|
6150
|
+
const plan = ed.state.doc.run?.plan;
|
|
6151
|
+
return plan ? { [turn]: { ...blankMeta(), plan } } : {};
|
|
6152
|
+
});
|
|
5874
6153
|
const updateMeta = useCallback4((fn) => {
|
|
5875
6154
|
const turn2 = turnRef.current;
|
|
5876
6155
|
setMeta((all) => ({ ...all, [turn2]: fn(all[turn2] ?? blankMeta()) }));
|
|
5877
6156
|
}, []);
|
|
6157
|
+
const [run, setRunState] = useState9(ed.state.doc.run ?? null);
|
|
6158
|
+
const runRef = useRef6(run);
|
|
6159
|
+
const setRun = useCallback4((next) => {
|
|
6160
|
+
runRef.current = next;
|
|
6161
|
+
setRunState(next);
|
|
6162
|
+
}, []);
|
|
6163
|
+
const updateRun = useCallback4((fn) => {
|
|
6164
|
+
if (runRef.current) setRun(fn(runRef.current));
|
|
6165
|
+
}, [setRun]);
|
|
6166
|
+
const addStep = useCallback4((label, status) => {
|
|
6167
|
+
updateRun((r) => ({ ...r, steps: [...r.steps.map((s) => ({ ...s, status: "done" })), { label, status }] }));
|
|
6168
|
+
}, [updateRun]);
|
|
6169
|
+
const [live, setLive] = useState9(false);
|
|
6170
|
+
const outcome = useRef6({ finished: false, stopped: false });
|
|
5878
6171
|
const connection = useMemo4(() => fetchServerSentEvents(endpoint), [endpoint]);
|
|
5879
6172
|
const chat = useChat({
|
|
5880
6173
|
connection,
|
|
5881
6174
|
threadId: ed.state.doc.id,
|
|
5882
|
-
initialMessages:
|
|
6175
|
+
initialMessages: initialChat,
|
|
6176
|
+
onChunk: (chunk) => {
|
|
6177
|
+
if (chunk.type === "RUN_FINISHED") outcome.current.finished = finishedRun(chunk);
|
|
6178
|
+
else if (chunk.type === "RUN_ERROR") outcome.current.finished = false;
|
|
6179
|
+
},
|
|
5883
6180
|
onCustomEvent: (type, data) => {
|
|
5884
6181
|
if (type === EVENTS.patch) {
|
|
5885
|
-
|
|
6182
|
+
const patch = data.patch;
|
|
6183
|
+
edRef.current.apply(patch, { record: "agent" });
|
|
5886
6184
|
updateMeta((m) => ({ ...m, patches: m.patches + 1 }));
|
|
6185
|
+
updateRun((r) => ({ ...r, edits: r.edits + countEdits(patch) }));
|
|
5887
6186
|
} else if (type === EVENTS.plan) {
|
|
5888
|
-
|
|
6187
|
+
const { plan } = data;
|
|
6188
|
+
updateMeta((m) => ({ ...m, plan }));
|
|
6189
|
+
updateRun((r) => ({ ...r, plan }));
|
|
5889
6190
|
} else if (type === EVENTS.status) {
|
|
5890
6191
|
const s = data;
|
|
5891
6192
|
updateMeta((m) => ({
|
|
@@ -5893,36 +6194,144 @@ function useAgentChat({ endpoint, context }) {
|
|
|
5893
6194
|
phase: s.phase,
|
|
5894
6195
|
steps: [...m.steps.map((x) => x.status === "active" ? { ...x, status: "done" } : x), { label: s.label, status: "active" }]
|
|
5895
6196
|
}));
|
|
6197
|
+
addStep(s.label, "active");
|
|
5896
6198
|
} else if (type === EVENTS.review) {
|
|
5897
6199
|
const r = data;
|
|
6200
|
+
const label = r.verdict === "ok" ? `Review ${r.round}: looks good` : `Review ${r.round}: ${r.findings.length} fix${r.findings.length === 1 ? "" : "es"}`;
|
|
5898
6201
|
updateMeta((m) => ({
|
|
5899
6202
|
...m,
|
|
5900
|
-
steps: [
|
|
5901
|
-
...m.steps.map((x) => x.status === "active" ? { ...x, status: "done" } : x),
|
|
5902
|
-
{ label: r.verdict === "ok" ? `Review ${r.round}: looks good` : `Review ${r.round}: ${r.findings.length} fix${r.findings.length === 1 ? "" : "es"}`, status: "done" }
|
|
5903
|
-
]
|
|
6203
|
+
steps: [...m.steps.map((x) => x.status === "active" ? { ...x, status: "done" } : x), { label, status: "done" }]
|
|
5904
6204
|
}));
|
|
6205
|
+
addStep(label, "done");
|
|
5905
6206
|
}
|
|
5906
6207
|
}
|
|
5907
6208
|
});
|
|
5908
6209
|
const running = chat.isLoading;
|
|
5909
6210
|
const currentMeta = meta[turn];
|
|
5910
6211
|
const agentStatus = running ? currentMeta?.phase ?? "drawing" : "idle";
|
|
5911
|
-
const
|
|
5912
|
-
const
|
|
5913
|
-
|
|
5914
|
-
|
|
6212
|
+
const start = useCallback4(async (o) => {
|
|
6213
|
+
const id = newId("run");
|
|
6214
|
+
outcome.current = { finished: false, stopped: false };
|
|
6215
|
+
setRun({ ...o.record, id, chatLength: o.record.chatLength ?? o.messages.length });
|
|
6216
|
+
setLive(true);
|
|
6217
|
+
const next = o.messages.filter((m) => m.role === "user").length + 1;
|
|
5915
6218
|
turnRef.current = next;
|
|
5916
6219
|
setTurn(next);
|
|
5917
6220
|
setMeta((all) => ({ ...all, [next]: blankMeta() }));
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
6221
|
+
let failed = false;
|
|
6222
|
+
try {
|
|
6223
|
+
const parts = (await Promise.all(o.attachments.map(fileToPart))).filter((p) => !!p);
|
|
6224
|
+
if (o.messages !== chat.messages) chat.setMessages(o.messages);
|
|
6225
|
+
const body = {
|
|
6226
|
+
document: { ...o.doc, chat: [], run: void 0 },
|
|
6227
|
+
selection: o.record.selection,
|
|
6228
|
+
context,
|
|
6229
|
+
preferences: o.record.preferences,
|
|
6230
|
+
resume: o.resume
|
|
6231
|
+
};
|
|
6232
|
+
const content = parts.length ? { content: [...o.text ? [{ type: "text", content: o.text }] : [], ...parts] } : o.text;
|
|
6233
|
+
await chat.sendMessage(content, { body });
|
|
6234
|
+
} catch {
|
|
6235
|
+
failed = true;
|
|
6236
|
+
}
|
|
6237
|
+
const r = runRef.current;
|
|
6238
|
+
if (r?.id !== id) return;
|
|
6239
|
+
setLive(false);
|
|
6240
|
+
if (!failed && (outcome.current.finished || outcome.current.stopped)) {
|
|
6241
|
+
setRun(null);
|
|
6242
|
+
} else if (!o.resume && !r.steps.length && !r.edits) {
|
|
6243
|
+
setTimeout(() => {
|
|
6244
|
+
if (runRef.current?.id === id) setRun(null);
|
|
6245
|
+
}, FAILED_START_MS);
|
|
6246
|
+
}
|
|
6247
|
+
}, [chat, context, setRun]);
|
|
6248
|
+
const send = useCallback4(async (text, attachments, preferences) => {
|
|
6249
|
+
const { doc: doc2, selection } = edRef.current.state;
|
|
6250
|
+
await start({
|
|
6251
|
+
text,
|
|
6252
|
+
attachments,
|
|
6253
|
+
doc: doc2,
|
|
6254
|
+
messages: repairTranscript(chat.messages),
|
|
6255
|
+
record: { kind: isNewFigure(doc2) ? "new" : "edit", request: text, preferences, selection, steps: [], edits: 0, before: snapshotOf(doc2) }
|
|
6256
|
+
});
|
|
6257
|
+
}, [chat.messages, start]);
|
|
6258
|
+
const interruptedRun = run && !live && !running ? run : null;
|
|
6259
|
+
const doc = ed.state.doc;
|
|
6260
|
+
const interrupted = useMemo4(() => {
|
|
6261
|
+
const r = interruptedRun;
|
|
6262
|
+
if (!r) return null;
|
|
6263
|
+
const { steps, hidden } = interruptionSteps(r);
|
|
6264
|
+
return {
|
|
6265
|
+
id: r.id,
|
|
6266
|
+
request: r.request,
|
|
6267
|
+
steps,
|
|
6268
|
+
hiddenSteps: hidden,
|
|
6269
|
+
edits: r.edits,
|
|
6270
|
+
kind: r.kind === "edit" ? "edit" : r.plan || r.edits ? "drawing" : "planning",
|
|
6271
|
+
attachments: messageAttachments(chat.messages[r.chatLength]),
|
|
6272
|
+
drawn: drawnSince(doc, r.before)
|
|
6273
|
+
};
|
|
6274
|
+
}, [interruptedRun, chat.messages, doc]);
|
|
6275
|
+
const resolveInterrupted = useCallback4((action) => {
|
|
6276
|
+
const r = runRef.current;
|
|
6277
|
+
if (!r) return;
|
|
6278
|
+
const ed2 = edRef.current;
|
|
6279
|
+
const { doc: doc2 } = ed2.state;
|
|
6280
|
+
const transcript = repairTranscript(chat.messages);
|
|
6281
|
+
const beforeTurn = transcript.slice(0, r.chatLength);
|
|
6282
|
+
switch (action) {
|
|
6283
|
+
case "dismiss":
|
|
6284
|
+
setRun(null);
|
|
6285
|
+
return;
|
|
6286
|
+
case "edit":
|
|
6287
|
+
chat.setMessages(beforeTurn);
|
|
6288
|
+
setRun(null);
|
|
6289
|
+
return;
|
|
6290
|
+
case "undo":
|
|
6291
|
+
ed2.apply(restorePatch(doc2, r.before));
|
|
6292
|
+
setRun(null);
|
|
6293
|
+
return;
|
|
6294
|
+
case "continue": {
|
|
6295
|
+
const ids = new Set(doc2.layers.flatMap((l) => l.items.map((i) => i.id)));
|
|
6296
|
+
void start({
|
|
6297
|
+
text: r.kind === "edit" ? "Continue this change" : "Continue drawing",
|
|
6298
|
+
attachments: [],
|
|
6299
|
+
doc: doc2,
|
|
6300
|
+
messages: transcript,
|
|
6301
|
+
record: { ...r, selection: r.selection.filter((i) => ids.has(i)), steps: r.steps.map((s) => ({ ...s, status: "done" })) },
|
|
6302
|
+
resume: { kind: r.kind, request: r.request, plan: r.plan, steps: r.steps.map((s) => s.label) }
|
|
6303
|
+
});
|
|
6304
|
+
return;
|
|
6305
|
+
}
|
|
6306
|
+
case "retry":
|
|
6307
|
+
case "restart": {
|
|
6308
|
+
const patch = restorePatch(doc2, r.before);
|
|
6309
|
+
const reset = r.edits > 0 || action === "restart";
|
|
6310
|
+
const clean = reset ? applyPatch(doc2, patch).doc : doc2;
|
|
6311
|
+
if (reset) ed2.apply(patch);
|
|
6312
|
+
void start({
|
|
6313
|
+
text: r.request,
|
|
6314
|
+
attachments: messageAttachments(chat.messages[r.chatLength]),
|
|
6315
|
+
doc: clean,
|
|
6316
|
+
messages: beforeTurn,
|
|
6317
|
+
record: { kind: r.kind, request: r.request, preferences: r.preferences, selection: r.selection, before: r.before, steps: [], edits: 0, plan: void 0 }
|
|
6318
|
+
});
|
|
6319
|
+
return;
|
|
6320
|
+
}
|
|
6321
|
+
}
|
|
6322
|
+
}, [chat, setRun, start]);
|
|
6323
|
+
const stop = useCallback4(() => {
|
|
6324
|
+
outcome.current.stopped = true;
|
|
6325
|
+
chat.stop();
|
|
6326
|
+
}, [chat]);
|
|
6327
|
+
const interrupt = useCallback4(() => {
|
|
6328
|
+
chat.stop();
|
|
6329
|
+
}, [chat]);
|
|
5922
6330
|
const messages = useMemo4(() => {
|
|
5923
6331
|
const out = [];
|
|
5924
6332
|
let t = 0;
|
|
5925
6333
|
let metaShownFor = -1;
|
|
6334
|
+
let editsShownFor = -1;
|
|
5926
6335
|
for (const m of chat.messages) {
|
|
5927
6336
|
if (m.role === "user") {
|
|
5928
6337
|
t += 1;
|
|
@@ -5946,7 +6355,8 @@ function useAgentChat({ endpoint, context }) {
|
|
|
5946
6355
|
if (steps.length) parts.push({ type: "progress", steps });
|
|
5947
6356
|
}
|
|
5948
6357
|
for (const p of m.parts) if (p.type === "text" && p.content.trim()) parts.push({ type: "text", text: p.content });
|
|
5949
|
-
if (rm && !rm.plan && rm.patches && !(running && t === turn) && metaShownFor === t &&
|
|
6358
|
+
if (rm && !rm.plan && rm.patches && !(running && t === turn) && metaShownFor === t && editsShownFor !== t) {
|
|
6359
|
+
editsShownFor = t;
|
|
5950
6360
|
parts.push({ type: "edits", summary: "Updated the drawing", count: rm.patches });
|
|
5951
6361
|
}
|
|
5952
6362
|
if (parts.length) out.push({ id: m.id, role: "assistant", parts });
|
|
@@ -5955,11 +6365,11 @@ function useAgentChat({ endpoint, context }) {
|
|
|
5955
6365
|
if (chat.error) out.push({ id: "error", role: "assistant", parts: [{ type: "error", message: friendlyError(chat.error) }] });
|
|
5956
6366
|
return out;
|
|
5957
6367
|
}, [chat.messages, chat.error, meta, running, turn]);
|
|
5958
|
-
return { messages, send, stop
|
|
6368
|
+
return { messages, send, stop, interrupt, agentStatus, rawMessages: chat.messages, run, interrupted, resolveInterrupted };
|
|
5959
6369
|
}
|
|
5960
6370
|
|
|
5961
6371
|
// ../../src/patent-render/client/PatentRender.tsx
|
|
5962
|
-
import { jsx as
|
|
6372
|
+
import { jsx as jsx31 } from "react/jsx-runtime";
|
|
5963
6373
|
function PatentRender(props) {
|
|
5964
6374
|
const { document: document2, figureNumber, jurisdiction, context, sheetLabel } = props;
|
|
5965
6375
|
const initial = useMemo5(
|
|
@@ -5976,32 +6386,79 @@ function PatentRender(props) {
|
|
|
5976
6386
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5977
6387
|
[]
|
|
5978
6388
|
);
|
|
5979
|
-
return /* @__PURE__ */
|
|
6389
|
+
return /* @__PURE__ */ jsx31(TooltipProvider, { delayDuration: 400, children: /* @__PURE__ */ jsx31(EditorProvider, { doc: initial, children: /* @__PURE__ */ jsx31(AgentShell, { ...props }) }) });
|
|
5980
6390
|
}
|
|
5981
|
-
function AgentShell({ endpoint, context, onEmbed, onCancel, onChange, exportPng, className }) {
|
|
6391
|
+
function AgentShell({ endpoint, context, onEmbed, onCancel, onChange, onBusyChange, exportPng, className }) {
|
|
5982
6392
|
const ed = useEditor();
|
|
5983
6393
|
const agent = useAgentChat({ endpoint, context });
|
|
5984
|
-
const
|
|
6394
|
+
const busy = agent.agentStatus !== "idle";
|
|
6395
|
+
const latest = useRef7({ chat: agent.rawMessages, run: agent.run, doc: ed.state.doc, onChange });
|
|
6396
|
+
useLayoutEffect3(() => {
|
|
6397
|
+
latest.current = { chat: agent.rawMessages, run: agent.run, doc: ed.state.doc, onChange };
|
|
6398
|
+
});
|
|
6399
|
+
const unsaved = useRef7(false);
|
|
6400
|
+
const withSession = (doc) => {
|
|
6401
|
+
const next = { ...doc, chat: latest.current.chat };
|
|
6402
|
+
if (latest.current.run) next.run = latest.current.run;
|
|
6403
|
+
else delete next.run;
|
|
6404
|
+
return next;
|
|
6405
|
+
};
|
|
6406
|
+
const save = (doc, reason) => {
|
|
6407
|
+
unsaved.current = reason === "edit";
|
|
6408
|
+
latest.current.onChange?.(withSession(doc), { reason });
|
|
6409
|
+
};
|
|
6410
|
+
const { run } = agent;
|
|
6411
|
+
const runKey = run ? `${run.id}:${run.steps.length}:${run.plan ? 1 : 0}` : "";
|
|
6412
|
+
const first = useRef7(true);
|
|
5985
6413
|
useEffect6(() => {
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
6414
|
+
if (first.current) {
|
|
6415
|
+
first.current = false;
|
|
6416
|
+
return;
|
|
6417
|
+
}
|
|
6418
|
+
save(latest.current.doc, "run");
|
|
6419
|
+
}, [runKey, busy]);
|
|
5990
6420
|
useEffect6(() => {
|
|
5991
|
-
const
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
6421
|
+
const onHide = () => {
|
|
6422
|
+
if (unsaved.current || latest.current.run) save(latest.current.doc, "close");
|
|
6423
|
+
};
|
|
6424
|
+
window.addEventListener("pagehide", onHide);
|
|
6425
|
+
return () => window.removeEventListener("pagehide", onHide);
|
|
6426
|
+
}, []);
|
|
6427
|
+
useEffect6(() => {
|
|
6428
|
+
if (!busy) return;
|
|
6429
|
+
const warn = (e) => {
|
|
6430
|
+
e.preventDefault();
|
|
6431
|
+
e.returnValue = "";
|
|
6432
|
+
};
|
|
6433
|
+
window.addEventListener("beforeunload", warn);
|
|
6434
|
+
return () => window.removeEventListener("beforeunload", warn);
|
|
6435
|
+
}, [busy]);
|
|
6436
|
+
const busyCallback = useRef7(onBusyChange);
|
|
6437
|
+
useLayoutEffect3(() => {
|
|
6438
|
+
busyCallback.current = onBusyChange;
|
|
6439
|
+
});
|
|
6440
|
+
useEffect6(() => {
|
|
6441
|
+
if (!busy) return;
|
|
6442
|
+
busyCallback.current?.(true);
|
|
6443
|
+
return () => busyCallback.current?.(false);
|
|
6444
|
+
}, [busy]);
|
|
6445
|
+
return /* @__PURE__ */ jsx31(
|
|
5996
6446
|
PatentRenderShell,
|
|
5997
6447
|
{
|
|
5998
6448
|
className,
|
|
5999
6449
|
agentStatus: agent.agentStatus,
|
|
6000
|
-
chat: {
|
|
6450
|
+
chat: {
|
|
6451
|
+
messages: agent.messages,
|
|
6452
|
+
onSend: agent.send,
|
|
6453
|
+
onStop: agent.stop,
|
|
6454
|
+
interrupted: agent.interrupted,
|
|
6455
|
+
onInterrupted: agent.resolveInterrupted
|
|
6456
|
+
},
|
|
6457
|
+
onInterrupt: agent.interrupt,
|
|
6001
6458
|
onCancel,
|
|
6002
|
-
onChange: onChange ? (doc) =>
|
|
6459
|
+
onChange: onChange ? (doc) => save(doc, "edit") : void 0,
|
|
6003
6460
|
onEmbed: async (r) => {
|
|
6004
|
-
const document2 =
|
|
6461
|
+
const document2 = withSession(r.document);
|
|
6005
6462
|
const png = exportPng ? (await exportPng(document2)).dataUrl : void 0;
|
|
6006
6463
|
await onEmbed({ ...r, document: document2, png });
|
|
6007
6464
|
}
|