فهرست منبع

update schemas

Yuki Takei 9 ماه پیش
والد
کامیت
522305563a

+ 21 - 19
apps/app/src/features/openai/interfaces/editor-assistant/llm-response-schemas.ts

@@ -1,31 +1,33 @@
 import { z } from 'zod';
 
 // -----------------------------------------------------------------------------
-// Type definitions
+// Streaming Response Schemas for Editor Assistant
 // -----------------------------------------------------------------------------
 
-// Schema definitions
+// Message schema for streaming communication
 export const LlmEditorAssistantMessageSchema = z.object({
   message: z.string().describe('A friendly message explaining what changes were made or suggested'),
 });
 
-export const LlmEditorAssistantDiffSchema = z
-  .object({
-    replace: z.string().describe('The text that should replace the current content'),
-  });
-  // .object({
-  //   insert: z.string().describe('The text that should insert the content in the current position'),
-  // })
-  // .or(
-  //   z.object({
-  //     delete: z.number().int().describe('The number of characters that should be deleted from the current position'),
-  //   }),
-  // )
-  // .or(
-  //   z.object({
-  //     retain: z.number().int().describe('The number of characters that should be retained in the current position'),
-  //   }),
-  // );
+// Search/Replace Diff Schema (roo-code compatible)
+export const LlmEditorAssistantDiffSchema = z.object({
+  search: z.string()
+    .min(1)
+    .describe('Exact content to search for (including whitespace and indentation)'),
+  replace: z.string()
+    .describe('Content to replace with'),
+  startLine: z.number()
+    .int()
+    .positive()
+    .optional()
+    .describe('Starting line number for search (1-based, optional)'),
+  endLine: z.number()
+    .int()
+    .positive()
+    .optional()
+    .describe('Ending line number for search (1-based, optional)'),
+});
+
 
 // Type definitions
 export type LlmEditorAssistantMessage = z.infer<typeof LlmEditorAssistantMessageSchema>;

+ 43 - 29
apps/app/src/features/openai/interfaces/editor-assistant/sse-schemas.ts

@@ -3,45 +3,59 @@ import { z } from 'zod';
 import { LlmEditorAssistantDiffSchema } from './llm-response-schemas';
 
 // -----------------------------------------------------------------------------
-// Type definitions
+// SSE Schemas for Streaming Editor Assistant
 // -----------------------------------------------------------------------------
 
-// Schema definitions
 export const SseMessageSchema = z.object({
-  appendedMessage: z.string().describe('The message that should be appended to the chat window'),
+  appendedMessage: z.string()
+    .describe('The message that should be appended to the chat window'),
 });
 
-export const SseDetectedDiffSchema = z
-  .object({
-    diff: LlmEditorAssistantDiffSchema,
-  });
+export const SseDetectedDiffSchema = z.object({
+  diff: LlmEditorAssistantDiffSchema,
+});
 
-export const SseFinalizedSchema = z
-  .object({
-    finalized: z.object({
-      message: z.string().describe('The final message that should be displayed in the chat window'),
-      replacements: z.array(LlmEditorAssistantDiffSchema),
-    }),
-  });
+// Enhanced finalized schema with detailed application results
+export const SseFinalizedSchema = z.object({
+  finalized: z.object({
+    message: z.string()
+      .describe('The final message that should be displayed in the chat window'),
+    replacements: z.array(LlmEditorAssistantDiffSchema),
+    // Enhanced error reporting from multi-search-replace processor
+    applicationResult: z.object({
+      success: z.boolean(),
+      appliedCount: z.number().int().min(0),
+      totalCount: z.number().int().min(0),
+      failedParts: z.array(z.object({
+        type: z.enum([
+          'SEARCH_NOT_FOUND',
+          'SIMILARITY_TOO_LOW',
+          'MULTIPLE_MATCHES',
+          'EMPTY_SEARCH',
+          'MARKER_SEQUENCE_ERROR',
+          'CONTENT_ERROR',
+        ]),
+        message: z.string(),
+        line: z.number().int().positive().optional(),
+        details: z.object({
+          searchContent: z.string(),
+          bestMatch: z.string().optional(),
+          similarity: z.number().min(0).max(1).optional(),
+          suggestions: z.array(z.string()),
+          correctFormat: z.string().optional(),
+          lineRange: z.string().optional(),
+        }),
+      })).optional(),
+    }).optional(),
+  }),
+});
 
 // Type definitions
 export type SseMessage = z.infer<typeof SseMessageSchema>;
 export type SseDetectedDiff = z.infer<typeof SseDetectedDiffSchema>;
 export type SseFinalized = z.infer<typeof SseFinalizedSchema>;
 
-// Type guard for SseDetectedDiff
-// export const isInsertDiff = (diff: SseDetectedDiff): diff is { diff: { insert: string } } => {
-//   return 'insert' in diff.diff;
-// };
-
-// export const isDeleteDiff = (diff: SseDetectedDiff): diff is { diff: { delete: number } } => {
-//   return 'delete' in diff.diff;
-// };
-
-// export const isRetainDiff = (diff: SseDetectedDiff): diff is { diff : { retain: number} } => {
-//   return 'retain' in diff.diff;
-// };
-
-export const isReplaceDiff = (diff: SseDetectedDiff): diff is { diff: { replace: string } } => {
-  return 'replace' in diff.diff;
+// Helper functions for response type checking
+export const hasApplicationResult = (finalized: SseFinalized): boolean => {
+  return finalized.finalized.applicationResult !== undefined;
 };

+ 127 - 0
apps/app/src/features/openai/interfaces/editor-assistant/types.ts

@@ -0,0 +1,127 @@
+/**
+ * Enhanced types for GROWI Editor Assistant with roo-code compatible Search/Replace functionality
+ */
+
+// -----------------------------------------------------------------------------
+// Configuration Types
+// -----------------------------------------------------------------------------
+
+export interface ProcessorConfig {
+  /** Fuzzy matching threshold (0.0 to 1.0, default: 0.8) */
+  fuzzyThreshold?: number;
+  /** Number of buffer lines for context (default: 40) */
+  bufferLines?: number;
+  /** Whether to preserve original indentation (default: true) */
+  preserveIndentation?: boolean;
+  /** Whether to strip line numbers from content (default: true) */
+  stripLineNumbers?: boolean;
+  /** Enable aggressive matching for edge cases (default: false) */
+  enableAggressiveMatching?: boolean;
+  /** Maximum number of diff blocks per request (default: 10) */
+  maxDiffBlocks?: number;
+}
+
+// -----------------------------------------------------------------------------
+// Error Types
+// -----------------------------------------------------------------------------
+
+export type DiffErrorType =
+  | 'SEARCH_NOT_FOUND'
+  | 'SIMILARITY_TOO_LOW'
+  | 'MULTIPLE_MATCHES'
+  | 'EMPTY_SEARCH'
+  | 'MARKER_SEQUENCE_ERROR'
+  | 'CONTENT_ERROR';
+
+export interface DiffError {
+  type: DiffErrorType;
+  message: string;
+  line?: number;
+  details: {
+    searchContent: string;
+    bestMatch?: string;
+    similarity?: number;
+    suggestions: string[];
+    correctFormat?: string;
+    lineRange?: string;
+  };
+}
+
+// -----------------------------------------------------------------------------
+// Result Types
+// -----------------------------------------------------------------------------
+
+export interface DiffApplicationResult {
+  /** Whether the diff application was successful */
+  success: boolean;
+  /** Number of diffs successfully applied */
+  appliedCount: number;
+  /** Updated content if any diffs were applied */
+  content?: string;
+  /** Details of failed diff parts */
+  failedParts?: DiffError[];
+}
+
+export interface SingleDiffResult {
+  /** Whether this single diff was successful */
+  success: boolean;
+  /** Updated lines if successful */
+  updatedLines?: string[];
+  /** Line delta change (can be negative) */
+  lineDelta?: number;
+  /** Error details if failed */
+  error?: DiffError;
+}
+
+// -----------------------------------------------------------------------------
+// Fuzzy Matching Types
+// -----------------------------------------------------------------------------
+
+export interface MatchResult {
+  /** Whether a match was found above threshold */
+  found: boolean;
+  /** Similarity score (0.0 to 1.0) */
+  score: number;
+  /** Starting line index of the match */
+  index: number;
+  /** Matched content */
+  content: string;
+  /** Threshold used for matching */
+  threshold: number;
+}
+
+export interface SearchContext {
+  /** Starting line number for search (1-based) */
+  startLine?: number;
+  /** Ending line number for search (1-based) */
+  endLine?: number;
+  /** Additional context lines around the search area */
+  bufferLines: number;
+}
+
+// -----------------------------------------------------------------------------
+// Validation Types
+// -----------------------------------------------------------------------------
+
+export interface ValidationResult {
+  /** Whether validation passed */
+  success: boolean;
+  /** Error message if validation failed */
+  error?: string;
+  /** Line number where error occurred */
+  line?: number;
+  /** Suggested fixes */
+  suggestions?: string[];
+}
+
+// -----------------------------------------------------------------------------
+// Legacy Compatibility
+// -----------------------------------------------------------------------------
+
+/**
+ * @deprecated Use the new Search/Replace format instead
+ * Kept for backward compatibility during migration
+ */
+export interface LegacyReplaceOperation {
+  replace: string;
+}