@aprovan/patchwork-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.
@@ -0,0 +1,331 @@
1
+ import { Node } from '@tiptap/core';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { Compiler, VirtualProject, VirtualFile, VFSStore } from '@aprovan/patchwork-compiler';
4
+ import { ReactNode } from 'react';
5
+ import { ClassValue } from 'clsx';
6
+
7
+ declare const CodeBlockExtension: Node<any, any>;
8
+
9
+ interface CodePreviewProps {
10
+ code: string;
11
+ compiler: Compiler | null;
12
+ /** Available service namespaces for widget calls */
13
+ services?: string[];
14
+ /** Optional file path from code block attributes (e.g., "components/calculator.tsx") */
15
+ filePath?: string;
16
+ }
17
+ declare function CodePreview({ code: originalCode, compiler, services, filePath }: CodePreviewProps): react_jsx_runtime.JSX.Element;
18
+
19
+ interface MarkdownEditorProps {
20
+ value: string;
21
+ onChange: (value: string) => void;
22
+ onSubmit: () => void;
23
+ placeholder?: string;
24
+ disabled?: boolean;
25
+ className?: string;
26
+ }
27
+ declare function MarkdownEditor({ value, onChange, onSubmit, placeholder, disabled, className, }: MarkdownEditorProps): react_jsx_runtime.JSX.Element;
28
+
29
+ interface ServiceInfo {
30
+ name: string;
31
+ namespace: string;
32
+ procedure: string;
33
+ description: string;
34
+ parameters: {
35
+ jsonSchema: Record<string, unknown>;
36
+ };
37
+ }
38
+ interface ServicesInspectorProps {
39
+ namespaces: string[];
40
+ services?: ServiceInfo[];
41
+ /** Custom badge component for rendering the service count */
42
+ BadgeComponent?: React.ComponentType<{
43
+ children: React.ReactNode;
44
+ variant?: string;
45
+ className?: string;
46
+ }>;
47
+ /** Custom collapsible components */
48
+ CollapsibleComponent?: React.ComponentType<{
49
+ children: React.ReactNode;
50
+ defaultOpen?: boolean;
51
+ className?: string;
52
+ }>;
53
+ CollapsibleTriggerComponent?: React.ComponentType<{
54
+ children: React.ReactNode;
55
+ className?: string;
56
+ }>;
57
+ CollapsibleContentComponent?: React.ComponentType<{
58
+ children: React.ReactNode;
59
+ }>;
60
+ /** Custom dialog components */
61
+ DialogComponent?: React.ComponentType<{
62
+ children: React.ReactNode;
63
+ open?: boolean;
64
+ onOpenChange?: (open: boolean) => void;
65
+ }>;
66
+ DialogHeaderComponent?: React.ComponentType<{
67
+ children: React.ReactNode;
68
+ }>;
69
+ DialogContentComponent?: React.ComponentType<{
70
+ children: React.ReactNode;
71
+ }>;
72
+ DialogCloseComponent?: React.ComponentType<{
73
+ onClose?: () => void;
74
+ }>;
75
+ }
76
+ declare function ServicesInspector({ namespaces, services, BadgeComponent, DialogComponent, }: ServicesInspectorProps): react_jsx_runtime.JSX.Element | null;
77
+
78
+ interface EditHistoryEntry {
79
+ prompt: string;
80
+ summary: string;
81
+ isRetry?: boolean;
82
+ }
83
+ interface EditSessionState {
84
+ project: VirtualProject;
85
+ originalProject: VirtualProject;
86
+ activeFile: string;
87
+ history: EditHistoryEntry[];
88
+ isApplying: boolean;
89
+ error: string | null;
90
+ streamingNotes: string[];
91
+ pendingPrompt: string | null;
92
+ }
93
+ interface EditSessionActions {
94
+ submitEdit: (prompt: string) => Promise<void>;
95
+ revert: () => void;
96
+ updateActiveFile: (content: string) => void;
97
+ setActiveFile: (path: string) => void;
98
+ clearError: () => void;
99
+ }
100
+ declare function getActiveContent(state: EditSessionState): string;
101
+ declare function getFiles(project: VirtualProject): VirtualFile[];
102
+ interface EditRequest {
103
+ code: string;
104
+ prompt: string;
105
+ }
106
+ interface EditResponse {
107
+ newCode: string;
108
+ summary: string;
109
+ progressNotes: string[];
110
+ }
111
+ interface CompileResult {
112
+ success: boolean;
113
+ error?: string;
114
+ }
115
+ type CompileFn = (code: string) => Promise<CompileResult>;
116
+
117
+ interface EditApiOptions {
118
+ endpoint?: string;
119
+ onProgress?: (note: string) => void;
120
+ /** Automatically remove stray diff markers from output (default: true) */
121
+ sanitize?: boolean;
122
+ }
123
+ declare function sendEditRequest(request: EditRequest, options?: EditApiOptions): Promise<EditResponse>;
124
+
125
+ interface UseEditSessionOptions {
126
+ originalCode: string;
127
+ compile?: CompileFn;
128
+ apiEndpoint?: string;
129
+ }
130
+ declare function useEditSession(options: UseEditSessionOptions): EditSessionState & EditSessionActions;
131
+
132
+ interface EditHistoryProps {
133
+ entries: EditHistoryEntry[];
134
+ streamingNotes: string[];
135
+ isStreaming: boolean;
136
+ pendingPrompt?: string | null;
137
+ className?: string;
138
+ }
139
+ declare function EditHistory({ entries, streamingNotes, isStreaming, pendingPrompt, className, }: EditHistoryProps): react_jsx_runtime.JSX.Element;
140
+
141
+ interface EditModalProps extends UseEditSessionOptions {
142
+ isOpen: boolean;
143
+ onClose: (finalCode: string, editCount: number) => void;
144
+ renderPreview: (code: string) => ReactNode;
145
+ renderLoading?: () => ReactNode;
146
+ renderError?: (error: string) => ReactNode;
147
+ previewError?: string | null;
148
+ previewLoading?: boolean;
149
+ }
150
+ declare function EditModal({ isOpen, onClose, renderPreview, renderLoading, renderError, previewError, previewLoading, ...sessionOptions }: EditModalProps): react_jsx_runtime.JSX.Element | null;
151
+
152
+ interface FileTreeProps {
153
+ files: VirtualFile[];
154
+ activeFile: string;
155
+ onSelectFile: (path: string) => void;
156
+ }
157
+ declare function FileTree({ files, activeFile, onSelectFile }: FileTreeProps): react_jsx_runtime.JSX.Element;
158
+
159
+ type TextPart = {
160
+ type: 'text';
161
+ content: string;
162
+ };
163
+ type CodePart = {
164
+ type: 'code' | string;
165
+ content: string;
166
+ language: 'jsx' | 'tsx' | string;
167
+ attributes?: Record<string, string>;
168
+ };
169
+ type ParsedPart = TextPart | CodePart;
170
+ interface ExtractOptions {
171
+ /** Only extract these languages (default: all) */
172
+ filterLanguages?: Set<string>;
173
+ /** Include unclosed code blocks at the end (for streaming) */
174
+ includeUnclosed?: boolean;
175
+ }
176
+ /**
177
+ * Extract code blocks from markdown text.
178
+ */
179
+ declare function extractCodeBlocks(text: string, options?: ExtractOptions): ParsedPart[];
180
+ /**
181
+ * Find the first JSX/TSX block in the text.
182
+ * Returns null if no JSX block is found.
183
+ */
184
+ declare function findFirstCodeBlock(text: string): CodePart | null;
185
+ /**
186
+ * Check if text contains any JSX/TSX code blocks.
187
+ */
188
+ declare function hasCodeBlock(text: string): boolean;
189
+ /**
190
+ * Get all unique languages found in code blocks.
191
+ */
192
+ declare function getCodeBlockLanguages(text: string): Set<string>;
193
+ /**
194
+ * Extract code blocks as a VirtualProject.
195
+ * Groups files with path attributes into a multi-file project.
196
+ * Files without paths are treated as the main entry file.
197
+ */
198
+ declare function extractProject(text: string, options?: ExtractOptions): {
199
+ project: VirtualProject;
200
+ textParts: TextPart[];
201
+ };
202
+
203
+ interface CodeBlockAttributes {
204
+ /** Progress note for UI display (optional but encouraged, comes first) */
205
+ note?: string;
206
+ /** Virtual file path for multi-file generation (uses \@/ prefix) */
207
+ path?: string;
208
+ /** Additional arbitrary attributes */
209
+ [key: string]: string | undefined;
210
+ }
211
+ interface CodeBlock {
212
+ /** Language identifier (e.g., tsx, json, diff) */
213
+ language: string;
214
+ /** Parsed attributes from the fence line */
215
+ attributes: CodeBlockAttributes;
216
+ /** Raw content between the fence markers */
217
+ content: string;
218
+ }
219
+ interface DiffBlock {
220
+ search: string;
221
+ replace: string;
222
+ /** Progress note from the code fence attributes */
223
+ note?: string;
224
+ /** Target file path for multi-file edits */
225
+ path?: string;
226
+ }
227
+ /**
228
+ * Parse attributes from a code fence line.
229
+ *
230
+ * Example input: 'note="Adding handler" path="\@/components/Button.tsx"'
231
+ *
232
+ * Returns: an object with note, path, and any other attributes
233
+ */
234
+ declare function parseCodeBlockAttributes(attrString: string): CodeBlockAttributes;
235
+ /**
236
+ * Parse all code blocks from text, extracting language and attributes.
237
+ * Returns blocks in order of appearance.
238
+ */
239
+ declare function parseCodeBlocks(text: string): CodeBlock[];
240
+ /**
241
+ * Check if text contains any diff markers.
242
+ * Returns the first marker found, or null if clean.
243
+ */
244
+ declare function findDiffMarkers(text: string): string | null;
245
+ /**
246
+ * Remove stray diff markers from text.
247
+ * Use as a fallback when markers leak into output.
248
+ */
249
+ declare function sanitizeDiffMarkers(text: string): string;
250
+ interface ParsedEditResponse {
251
+ /** Progress notes extracted from code block attributes (in order of appearance) */
252
+ progressNotes: string[];
253
+ /** Parsed diff blocks with their attributes */
254
+ diffs: DiffBlock[];
255
+ /** Summary markdown text (content outside of code blocks) */
256
+ summary: string;
257
+ }
258
+ /**
259
+ * Parse progress notes and diffs from an edit response.
260
+ *
261
+ * New format uses tagged attributes on code fences:
262
+ * ```diff note="Adding handler" path="@/components/Button.tsx"
263
+ * <<<<<<< SEARCH
264
+ * exact code
265
+ * =======
266
+ * replacement
267
+ * >>>>>>> REPLACE
268
+ * ```
269
+ *
270
+ * Summary markdown is everything outside of code blocks.
271
+ */
272
+ declare function parseEditResponse(text: string): ParsedEditResponse;
273
+ /**
274
+ * Parse diff blocks from text, extracting attributes from code fences.
275
+ * Supports both fenced code blocks with attributes and raw diff markers.
276
+ */
277
+ declare function parseDiffs(text: string): DiffBlock[];
278
+ declare function applyDiffs(code: string, diffs: DiffBlock[], options?: {
279
+ sanitize?: boolean;
280
+ }): {
281
+ code: string;
282
+ applied: number;
283
+ failed: string[];
284
+ warning?: string;
285
+ };
286
+ declare function hasDiffBlocks(text: string): boolean;
287
+ declare function extractTextWithoutDiffs(text: string): string;
288
+ /**
289
+ * Extract the summary markdown from an edit response.
290
+ * Removes code blocks (with their attributes), and any leading/trailing whitespace.
291
+ * Preserves regular markdown prose outside of code blocks.
292
+ */
293
+ declare function extractSummary(text: string): string;
294
+
295
+ /**
296
+ * Get VFS configuration from the server.
297
+ * Caches the result for subsequent calls.
298
+ */
299
+ declare function getVFSConfig(): Promise<{
300
+ usePaths: boolean;
301
+ }>;
302
+ /**
303
+ * Get the VFS store instance (creates one if needed).
304
+ * Store uses LocalFSBackend to persist to the stitchery server.
305
+ */
306
+ declare function getVFSStore(): VFSStore;
307
+ /**
308
+ * Save a virtual project to disk via the stitchery server.
309
+ * Projects are saved under their ID in the VFS directory.
310
+ */
311
+ declare function saveProject(project: VirtualProject): Promise<void>;
312
+ /**
313
+ * Load a project from disk by ID.
314
+ */
315
+ declare function loadProject(id: string): Promise<VirtualProject | null>;
316
+ /**
317
+ * List all stored project IDs.
318
+ */
319
+ declare function listProjects(): Promise<string[]>;
320
+ /**
321
+ * Save a single file to the VFS.
322
+ */
323
+ declare function saveFile(file: VirtualFile): Promise<void>;
324
+ /**
325
+ * Check if VFS is available (stitchery server is running with vfs-dir enabled).
326
+ */
327
+ declare function isVFSAvailable(): Promise<boolean>;
328
+
329
+ declare function cn(...inputs: ClassValue[]): string;
330
+
331
+ export { type CodeBlock, type CodeBlockAttributes, CodeBlockExtension, type CodePart, CodePreview, type CompileFn, type CompileResult, type DiffBlock, type EditApiOptions, EditHistory, type EditHistoryEntry, EditModal, type EditModalProps, type EditRequest, type EditResponse, type EditSessionActions, type EditSessionState, type ExtractOptions, FileTree, type FileTreeProps, MarkdownEditor, type ParsedEditResponse, type ParsedPart, type ServiceInfo, ServicesInspector, type TextPart, type UseEditSessionOptions, applyDiffs, cn, extractCodeBlocks, extractProject, extractSummary, extractTextWithoutDiffs, findDiffMarkers, findFirstCodeBlock, getActiveContent, getCodeBlockLanguages, getFiles, getVFSConfig, getVFSStore, hasCodeBlock, hasDiffBlocks, isVFSAvailable, listProjects, loadProject, parseCodeBlockAttributes, parseCodeBlocks, parseDiffs, parseEditResponse, sanitizeDiffMarkers, saveFile, saveProject, sendEditRequest, useEditSession };