patent-editor 0.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/lib.d.ts ADDED
@@ -0,0 +1,573 @@
1
+ import { default as default_2 } from 'react';
2
+ import { Editor } from '@tiptap/react';
3
+ import { EditorOptions } from '@tiptap/react';
4
+ import { Extension } from '@tiptap/react';
5
+ import { JSONContent } from '@tiptap/react';
6
+ import { Mark } from '@tiptap/react';
7
+ import { Node as Node_2 } from '@tiptap/react';
8
+ import { Node as Node_3 } from '@tiptap/pm/model';
9
+ import { PluginKey } from '@tiptap/pm/state';
10
+ import { StoreApi } from 'zustand';
11
+ import { UseBoundStore } from 'zustand';
12
+
13
+ export declare function acceptAllPatches(editor: Editor): void;
14
+
15
+ export declare function acceptPatch(editor: Editor, patchId: string): boolean;
16
+
17
+ export declare type AIAction = 'generate';
18
+
19
+ export declare interface AIChatReference {
20
+ text: string;
21
+ source?: string;
22
+ from?: number;
23
+ to?: number;
24
+ }
25
+
26
+ export declare interface AIContext {
27
+ scope: 'selection' | 'section' | 'document';
28
+ sectionType?: PatentSectionType;
29
+ targetSectionPos?: number;
30
+ userInput?: string;
31
+ selectedText?: string;
32
+ dependencyContext?: {
33
+ sectionType: PatentSectionType;
34
+ content: string;
35
+ }[];
36
+ surroundingText?: string;
37
+ language: EditorLanguage;
38
+ }
39
+
40
+ export declare interface AIPatch {
41
+ id: string;
42
+ type: 'insert' | 'replace' | 'delete';
43
+ from: number;
44
+ to: number;
45
+ content: string;
46
+ originalText?: string;
47
+ reason?: string;
48
+ status: 'pending' | 'accepted' | 'rejected';
49
+ }
50
+
51
+ export declare interface AIPatchData {
52
+ op: 'replace' | 'insert' | 'delete';
53
+ target: AIPatchTarget;
54
+ search?: string;
55
+ content: string;
56
+ reason?: string;
57
+ from?: number;
58
+ to?: number;
59
+ }
60
+
61
+ export declare interface AIPatchTarget {
62
+ type: 'section' | 'ref' | 'search';
63
+ sectionType?: PatentSectionType;
64
+ refIndex?: number;
65
+ searchText?: string;
66
+ }
67
+
68
+ export declare interface AIRequest {
69
+ action: AIAction;
70
+ sectionType?: PatentSectionType;
71
+ instruction?: string;
72
+ content?: string;
73
+ dependencyContext?: {
74
+ sectionType: string;
75
+ content: string;
76
+ }[];
77
+ language: EditorLanguage;
78
+ }
79
+
80
+ export declare type AIResponseEvent = {
81
+ type: 'delta';
82
+ content: string;
83
+ } | {
84
+ type: 'patch';
85
+ patch: AIPatchData;
86
+ } | {
87
+ type: 'done';
88
+ usage?: {
89
+ tokens: number;
90
+ };
91
+ } | {
92
+ type: 'error';
93
+ message: string;
94
+ };
95
+
96
+ export declare interface AIServiceAdapter {
97
+ request(req: AIRequest): Promise<ReadableStream<AIResponseEvent>>;
98
+ abort(): void;
99
+ }
100
+
101
+ export declare type AIStatus = 'idle' | 'streaming' | 'loading' | 'error';
102
+
103
+ declare interface AIStreamingState {
104
+ status: AIStatus;
105
+ activeSectionType: string | null;
106
+ requestId: string | null;
107
+ abortFn: (() => void) | null;
108
+ }
109
+
110
+ /**
111
+ * Apply document-level diff decorations to a read-only editor.
112
+ *
113
+ * @param editor - The TipTap editor instance (should be loaded with the "current" document)
114
+ * @param originalText - Plain text of the original document, extracted using the same
115
+ * separator rules as ProseMirror's textBetween (\0 separators).
116
+ */
117
+ export declare function applyDocDiffDecorations(editor: Editor, originalText: string): void;
118
+
119
+ declare const applyTransactionBatch: (editor: Editor, operations: BatchOperation[]) => boolean;
120
+
121
+ export declare type AutoSaveStatus = 'idle' | 'saving' | 'saved' | 'error';
122
+
123
+ declare type BatchOperation = {
124
+ type: 'insertNode';
125
+ payload: InsertNodeInput;
126
+ } | {
127
+ type: 'updateNodeAttrs';
128
+ payload: UpdateNodeAttrsInput;
129
+ } | {
130
+ type: 'removeNode';
131
+ payload: RemoveNodeInput;
132
+ } | {
133
+ type: 'wrapSelection';
134
+ payload: WrapSelectionInput;
135
+ };
136
+
137
+ export declare function buildAIContext(editor: Editor, options?: {
138
+ scope?: AIContext['scope'];
139
+ sectionType?: PatentSectionType;
140
+ targetSectionPos?: number;
141
+ userInput?: string;
142
+ }): AIContext;
143
+
144
+ /**
145
+ * Build structured JSONContent for claims from text,
146
+ * suitable for use with editor.commands.insertContent() or diff comparison.
147
+ */
148
+ export declare function buildClaimsJSONContent(text: string): Array<{
149
+ type: string;
150
+ attrs: Record<string, unknown>;
151
+ content?: Array<{
152
+ type: string;
153
+ text: string;
154
+ }>;
155
+ }>;
156
+
157
+ export declare const buildPatentDocument: (patentType?: PatentType) => JSONContent;
158
+
159
+ declare interface ChatMessage {
160
+ messageId: string;
161
+ role: 'user' | 'assistant';
162
+ content: string;
163
+ references?: AIChatReference[];
164
+ patches?: AIPatchData[];
165
+ usage?: {
166
+ tokens: number;
167
+ };
168
+ status: 'processing' | 'done' | 'error';
169
+ createdAt: string;
170
+ }
171
+ export { ChatMessage as AIChatMessage }
172
+ export { ChatMessage }
173
+
174
+ export declare interface ChatMessageRequest {
175
+ content: string;
176
+ references?: AIChatReference[];
177
+ language: EditorLanguage;
178
+ }
179
+
180
+ export declare interface ChatMessageResponse {
181
+ messageId: string;
182
+ sessionId: string;
183
+ status: 'processing' | 'done' | 'error';
184
+ }
185
+
186
+ export declare interface ChatReference {
187
+ id: string;
188
+ text: string;
189
+ from?: number;
190
+ to?: number;
191
+ sectionType?: string;
192
+ }
193
+
194
+ export declare interface ChatSession {
195
+ sessionId: string;
196
+ patentId?: string;
197
+ title: string;
198
+ lastMessage?: string;
199
+ messageCount: number;
200
+ createdAt: string;
201
+ updatedAt: string;
202
+ }
203
+
204
+ export declare interface ChatSessionAPI {
205
+ createSession(patentId?: string, title?: string, language?: EditorLanguage): Promise<ChatSession>;
206
+ listSessions(patentId?: string, page?: number, pageSize?: number): Promise<{
207
+ total: number;
208
+ items: ChatSession[];
209
+ }>;
210
+ getMessages(sessionId: string, page?: number, pageSize?: number): Promise<{
211
+ total: number;
212
+ items: ChatMessage[];
213
+ }>;
214
+ deleteSession(sessionId: string): Promise<void>;
215
+ sendMessage(sessionId: string, req: ChatMessageRequest): Promise<ChatMessageResponse>;
216
+ subscribeStream(sessionId: string, messageId: string): Promise<ReadableStream<AIResponseEvent>>;
217
+ abort(): void;
218
+ }
219
+
220
+ export declare interface ClaimSnapshot {
221
+ claimId: string;
222
+ number: number;
223
+ dependsOn: number[];
224
+ dependsOnClaimIds: string[];
225
+ body: string;
226
+ pos: number;
227
+ }
228
+
229
+ export declare function clearPatches(): void;
230
+
231
+ declare interface CommandCompletionResult {
232
+ name: string;
233
+ success: boolean;
234
+ durationMs: number;
235
+ error?: unknown;
236
+ }
237
+
238
+ declare interface CommandExecutionContext {
239
+ editor: Editor;
240
+ selection: CommandSelection | null;
241
+ store: unknown;
242
+ }
243
+
244
+ declare interface CommandExecutionOptions {
245
+ transaction?: boolean;
246
+ rollbackOnFail?: boolean;
247
+ onComplete?: (result: CommandCompletionResult) => void;
248
+ }
249
+
250
+ declare type CommandExecutionResult = boolean | Promise<boolean>;
251
+
252
+ declare interface CommandSelection {
253
+ from: number;
254
+ to: number;
255
+ }
256
+
257
+ export declare function createChatSessionAPI(baseUrl: string, headers?: Record<string, string>): ChatSessionAPI;
258
+
259
+ export declare const createCommandExecutor: (editor: Editor) => {
260
+ execCommand: (name: string, payload?: unknown, options?: CommandExecutionOptions) => Promise<boolean>;
261
+ canExecCommand: (name: string, payload?: unknown) => boolean;
262
+ isCommandActive: (name: string) => boolean;
263
+ listCommands: () => string[];
264
+ insertNode: (input: Parameters<typeof insertNode>[1]) => boolean;
265
+ updateNodeAttrs: (input: Parameters<typeof updateNodeAttrs>[1]) => boolean;
266
+ removeNode: (input: Parameters<typeof removeNode>[1]) => boolean;
267
+ wrapSelection: (input: Parameters<typeof wrapSelection>[1]) => boolean;
268
+ applyTransactionBatch: (operations: Parameters<typeof applyTransactionBatch>[1]) => boolean;
269
+ findNodeByType: (typeName: Parameters<typeof findNodeByType>[1], scope?: Parameters<typeof findNodeByType>[2]) => NodeMatch;
270
+ findAncestorNode: (predicate: Parameters<typeof findAncestorNode>[1]) => NodeMatch;
271
+ findCurrentBlock: () => NodeMatch;
272
+ findNodesByPredicate: (predicate: Parameters<typeof findNodesByPredicate>[1], scope?: Parameters<typeof findNodesByPredicate>[2]) => NodeMatch[];
273
+ };
274
+
275
+ export declare const createEditorConfig: (options?: Partial<EditorOptions>) => Partial<EditorOptions>;
276
+
277
+ export declare function createMockAIService(): AIServiceAdapter;
278
+
279
+ export declare function createMockChatSessionAPI(): ChatSessionAPI;
280
+
281
+ export declare function createSSEAdapter(baseUrl: string, headers?: Record<string, string>): AIServiceAdapter;
282
+
283
+ declare type EditorCommand = (context: CommandExecutionContext, payload?: unknown) => CommandExecutionResult;
284
+
285
+ declare interface EditorCommandDefinition {
286
+ execute: EditorCommand;
287
+ canExecute?: (context: CommandExecutionContext, payload?: unknown) => boolean;
288
+ isActive?: (context: CommandExecutionContext) => boolean;
289
+ description?: string;
290
+ category?: string;
291
+ shortcut?: string;
292
+ }
293
+
294
+ export declare type EditorLanguage = 'zh' | 'en';
295
+
296
+ declare interface EditorPlugin {
297
+ name: string;
298
+ version: string;
299
+ extensions?: Extension[] | Node_2[] | Mark[];
300
+ commands?: Record<string, EditorCommand | EditorCommandDefinition>;
301
+ toolbarItems?: ToolbarItem[];
302
+ keymaps?: Record<string, string>;
303
+ onStateChange?: (editor: Editor) => void;
304
+ onSelectionChange?: (editor: Editor) => void;
305
+ dependsOn?: string[];
306
+ priority?: number;
307
+ init?: (editor: Editor) => void;
308
+ destroy?: (editor: Editor) => void;
309
+ }
310
+
311
+ declare interface EditorState {
312
+ editor: Editor | null;
313
+ document: JSONContent | null;
314
+ selection: {
315
+ from: number;
316
+ to: number;
317
+ } | null;
318
+ editorLanguage: EditorLanguage;
319
+ autoSaveStatus: AutoSaveStatus;
320
+ lastSavedAt: Date | null;
321
+ ai: AIStreamingState;
322
+ aiService: AIServiceAdapter | null;
323
+ chatSessionAPI: ChatSessionAPI | null;
324
+ chatSessionId: string | null;
325
+ rightPanel: RightPanelState;
326
+ setEditor: (editor: Editor) => void;
327
+ setDocument: (document: JSONContent) => void;
328
+ setSelection: (selection: {
329
+ from: number;
330
+ to: number;
331
+ }) => void;
332
+ setEditorLanguage: (language: EditorLanguage) => void;
333
+ setAutoSaveStatus: (status: AutoSaveStatus) => void;
334
+ setLastSavedAt: (date: Date | null) => void;
335
+ setAIStatus: (status: AIStatus, sectionType?: string | null) => void;
336
+ setAIAbort: (abortFn: (() => void) | null) => void;
337
+ resetAI: () => void;
338
+ setAIService: (adapter: AIServiceAdapter | null) => void;
339
+ setChatSessionAPI: (api: ChatSessionAPI | null) => void;
340
+ setChatSessionId: (id: string | null) => void;
341
+ setActiveSection: (sectionType: string, sectionPos: number) => void;
342
+ openDraftingPanel: (sectionType: string, sectionPos: number, regenerate?: boolean) => void;
343
+ openChatPanel: () => void;
344
+ setRightPanelTab: (tab: RightPanelTab) => void;
345
+ closeRightPanel: () => void;
346
+ addChatReference: (ref: Omit<ChatReference, 'id'>) => void;
347
+ removeChatReference: (id: string) => void;
348
+ clearChatReferences: () => void;
349
+ setPendingChatMessage: (msg: string | null) => void;
350
+ }
351
+
352
+ export declare const EditorView: default_2.FC<EditorViewProps>;
353
+
354
+ declare interface EditorViewProps {
355
+ initialContent?: JSONContent;
356
+ onChange?: (content: JSONContent) => void;
357
+ className?: string;
358
+ readOnly?: boolean;
359
+ onEditorReady?: (editor: Editor) => void;
360
+ onSelectionOptimize?: (selection: {
361
+ text: string;
362
+ from: number;
363
+ to: number;
364
+ sectionType?: string;
365
+ }) => void;
366
+ }
367
+
368
+ export declare function exportToPdf(editor: Editor): Promise<void>;
369
+
370
+ export declare function exportToWord(editor: Editor, language: EditorLanguage): Promise<void>;
371
+
372
+ export declare const extractClaimsFromEditor: (editor: Editor) => ClaimSnapshot[];
373
+
374
+ declare const findAncestorNode: (editor: Editor, predicate: string | ((node: Node_3) => boolean)) => NodeMatch | null;
375
+
376
+ declare const findNodeByType: (editor: Editor, typeName: string, scope?: NodeQueryScope) => NodeMatch | null;
377
+
378
+ declare const findNodesByPredicate: (editor: Editor, predicate: (node: Node_3, pos: number) => boolean, scope?: NodeQueryScope) => NodeMatch[];
379
+
380
+ export declare function findSectionAtCursor(editor: Editor): SectionInfo | null;
381
+
382
+ export declare function getAllSections(editor: Editor): SectionInfo[];
383
+
384
+ export declare function getMissingSectionDeps(targetSection: PatentSectionType, completedSections: Set<PatentSectionType>): PatentSectionType[];
385
+
386
+ export declare function getPatches(): AIPatch[];
387
+
388
+ declare const insertNode: (editor: Editor, input: InsertNodeInput) => boolean;
389
+
390
+ declare interface InsertNodeInput {
391
+ type: string;
392
+ attrs?: Record<string, unknown>;
393
+ content?: JSONBlockContent;
394
+ position?: number;
395
+ }
396
+
397
+ declare type JSONBlockContent = JSONContent | JSONContent[];
398
+
399
+ declare interface NodeMatch {
400
+ node: Node_3;
401
+ pos: number;
402
+ }
403
+
404
+ declare interface NodeQueryScope {
405
+ from?: number;
406
+ to?: number;
407
+ }
408
+
409
+ export declare function onPatchChange(listener: () => void): () => void;
410
+
411
+ export declare const PatchDiffPluginKey: PluginKey<any>;
412
+
413
+ export declare const PatentEditor: default_2.ForwardRefExoticComponent<PatentEditorProps & default_2.RefAttributes<PatentEditorRef>>;
414
+
415
+ export declare interface PatentEditorProps {
416
+ initialContent?: JSONContent;
417
+ patentType?: PatentType;
418
+ onChange?: (content: JSONContent) => void;
419
+ className?: string;
420
+ readOnly?: boolean;
421
+ language?: EditorLanguage;
422
+ aiService?: AIServiceAdapter;
423
+ chatSessionAPI?: ChatSessionAPI;
424
+ aiBaseUrl?: string;
425
+ aiHeaders?: Record<string, string>;
426
+ onSelectionOptimize?: (selection: {
427
+ text: string;
428
+ from: number;
429
+ to: number;
430
+ sectionType?: string;
431
+ }) => void;
432
+ }
433
+
434
+ export declare interface PatentEditorRef {
435
+ getContent: () => JSONContent | null;
436
+ setContent: (content: JSONContent) => void;
437
+ getEditor: () => any;
438
+ execCommand: (name: string, payload?: unknown) => Promise<unknown>;
439
+ focus: () => void;
440
+ }
441
+
442
+ export declare type PatentSectionType = 'technical_field' | 'background_art' | 'summary' | 'drawing_description' | 'detailed_description' | 'claims' | 'abstract' | 'abstract_drawing' | 'drawing_figures' | 'design_product_name' | 'design_usage' | 'design_description' | 'design_views' | 'design_brief';
443
+
444
+ export declare type PatentType = 'invention' | 'utility_model' | 'design';
445
+
446
+ declare type PluginLifecycleStage = 'register' | 'init' | 'stateSync' | 'destroy';
447
+
448
+ declare class PluginManager {
449
+ private plugins;
450
+ private lifecycleOrder;
451
+ private logLifecycle;
452
+ private getOrderedPlugins;
453
+ private registerPluginCommands;
454
+ register(plugin: EditorPlugin): void;
455
+ getExtensions(): (Extension | Node_2 | Mark)[];
456
+ initializePlugins(editor: Editor): void;
457
+ notifySelectionChange(editor: Editor): void;
458
+ notifyStateChange(editor: Editor): void;
459
+ executeCommand(name: string, context: CommandExecutionContext, payload?: unknown, options?: CommandExecutionOptions): Promise<boolean>;
460
+ canExecuteCommand(name: string, context: CommandExecutionContext, payload?: unknown): boolean;
461
+ isCommandActive(name: string, context: CommandExecutionContext): boolean;
462
+ getCommandNames(): string[];
463
+ getLifecycleOrder(): PluginLifecycleStage[];
464
+ getCommandMeta(name: string): EditorCommandDefinition;
465
+ getToolbarItems(): ToolbarItem[];
466
+ destroyPlugins(editor: Editor): void;
467
+ }
468
+
469
+ export declare const pluginManager: PluginManager;
470
+
471
+ export declare function rejectAllPatches(editor: Editor): void;
472
+
473
+ export declare function rejectPatch(editor: Editor, patchId: string): boolean;
474
+
475
+ /**
476
+ * Remove the doc-diff decoration plugin from the editor.
477
+ */
478
+ export declare function removeDocDiffDecorations(editor: Editor): void;
479
+
480
+ declare const removeNode: (editor: Editor, input: RemoveNodeInput) => boolean;
481
+
482
+ declare interface RemoveNodeInput {
483
+ type?: string;
484
+ position?: number;
485
+ }
486
+
487
+ /**
488
+ * Resolve an AIPatchData (with semantic target) into absolute from/to positions.
489
+ * Returns an AIPatch ready for decoration, or null if resolution fails.
490
+ */
491
+ export declare function resolvePatchTarget(editor: Editor, patchData: AIPatchData, refs: AIChatReference[], patchIndex: number, alreadyResolved?: AIPatch[]): AIPatch | null;
492
+
493
+ declare interface RightPanelState {
494
+ visible: boolean;
495
+ activeTab: RightPanelTab;
496
+ activeSectionType: string | null;
497
+ activeSectionPos: number | null;
498
+ regenerate: boolean;
499
+ chatReferences: ChatReference[];
500
+ pendingChatMessage: string | null;
501
+ }
502
+
503
+ export declare type RightPanelTab = 'drafting' | 'chat';
504
+
505
+ export declare const sectionContextDeps: Record<PatentSectionType, PatentSectionType[]>;
506
+
507
+ declare interface SectionInfo {
508
+ sectionType: PatentSectionType;
509
+ pos: number;
510
+ content: string;
511
+ }
512
+
513
+ export declare function setPatches(patches: AIPatch[]): void;
514
+
515
+ export declare type StreamWriteMode = 'cursor' | 'section';
516
+
517
+ export declare interface StreamWriterOptions {
518
+ mode: StreamWriteMode;
519
+ targetSectionPos?: number;
520
+ onStart?: () => void;
521
+ onChunk?: (text: string) => void;
522
+ onComplete?: () => void;
523
+ onError?: (error: Error) => void;
524
+ onAbort?: () => void;
525
+ }
526
+
527
+ declare interface ToolbarItem {
528
+ id: string;
529
+ label: string;
530
+ command: string;
531
+ group?: 'text' | 'structure' | 'technical' | 'patent' | string;
532
+ tooltip?: string;
533
+ shortcut?: string;
534
+ icon?: string;
535
+ enableWhen?: (context: CommandExecutionContext) => boolean;
536
+ }
537
+
538
+ declare const updateNodeAttrs: (editor: Editor, input: UpdateNodeAttrsInput) => boolean;
539
+
540
+ declare interface UpdateNodeAttrsInput {
541
+ type?: string;
542
+ position?: number;
543
+ attrs: Record<string, unknown>;
544
+ }
545
+
546
+ export declare const useEditorStore: UseBoundStore<StoreApi<EditorState>>;
547
+
548
+ export declare function validatePatentDocument(editor: Editor, language: EditorLanguage): ValidationIssue[];
549
+
550
+ export declare interface ValidationIssue {
551
+ id: string;
552
+ severity: ValidationSeverity;
553
+ message: string;
554
+ sectionType?: string;
555
+ pos?: number;
556
+ }
557
+
558
+ export declare type ValidationSeverity = 'error' | 'warning' | 'suggestion';
559
+
560
+ declare const wrapSelection: (editor: Editor, input: WrapSelectionInput) => boolean;
561
+
562
+ declare interface WrapSelectionInput {
563
+ type: string;
564
+ attrs?: Record<string, unknown>;
565
+ }
566
+
567
+ export declare function writeStream(editor: Editor, reader: ReadableStreamDefaultReader<string>, options: StreamWriterOptions): Promise<void>;
568
+
569
+ export declare function writeStreamFromSSE(editor: Editor, url: string, body: object, options: StreamWriterOptions): Promise<{
570
+ abort: () => void;
571
+ }>;
572
+
573
+ export { }