@arke-institute/sdk 0.1.0 → 0.1.2

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.
Files changed (53) hide show
  1. package/dist/{index.d.mts → client-dAk3E64p.d.cts} +1 -7
  2. package/dist/client-dAk3E64p.d.ts +183 -0
  3. package/dist/{index.mjs → collections/index.cjs} +34 -5
  4. package/dist/collections/index.cjs.map +1 -0
  5. package/dist/collections/index.d.cts +9 -0
  6. package/dist/collections/index.d.ts +9 -1
  7. package/dist/collections/index.js +5 -32
  8. package/dist/collections/index.js.map +1 -1
  9. package/dist/content/index.cjs +506 -0
  10. package/dist/content/index.cjs.map +1 -0
  11. package/dist/content/index.d.cts +403 -0
  12. package/dist/content/index.d.ts +403 -0
  13. package/dist/content/index.js +473 -0
  14. package/dist/content/index.js.map +1 -0
  15. package/dist/edit/index.cjs +1029 -0
  16. package/dist/edit/index.cjs.map +1 -0
  17. package/dist/edit/index.d.cts +78 -0
  18. package/dist/edit/index.d.ts +78 -0
  19. package/dist/edit/index.js +983 -0
  20. package/dist/edit/index.js.map +1 -0
  21. package/dist/errors-3L7IiHcr.d.cts +480 -0
  22. package/dist/errors-B82BMmRP.d.cts +343 -0
  23. package/dist/errors-B82BMmRP.d.ts +343 -0
  24. package/dist/errors-BTe8GKRQ.d.ts +480 -0
  25. package/dist/graph/index.cjs +433 -0
  26. package/dist/graph/index.cjs.map +1 -0
  27. package/dist/graph/index.d.cts +456 -0
  28. package/dist/graph/index.d.ts +456 -0
  29. package/dist/graph/index.js +402 -0
  30. package/dist/graph/index.js.map +1 -0
  31. package/dist/index.cjs +3761 -0
  32. package/dist/index.cjs.map +1 -0
  33. package/dist/index.d.cts +7 -0
  34. package/dist/index.d.ts +7 -189
  35. package/dist/index.js +3502 -30
  36. package/dist/index.js.map +1 -1
  37. package/dist/query/index.cjs +289 -0
  38. package/dist/query/index.cjs.map +1 -0
  39. package/dist/query/index.d.cts +541 -0
  40. package/dist/query/index.d.ts +541 -0
  41. package/dist/query/index.js +261 -0
  42. package/dist/query/index.js.map +1 -0
  43. package/dist/upload/index.cjs +1634 -0
  44. package/dist/upload/index.cjs.map +1 -0
  45. package/dist/upload/index.d.cts +150 -0
  46. package/dist/upload/index.d.ts +150 -0
  47. package/dist/upload/index.js +1597 -0
  48. package/dist/upload/index.js.map +1 -0
  49. package/package.json +43 -8
  50. package/dist/collections/index.d.mts +0 -1
  51. package/dist/collections/index.mjs +0 -204
  52. package/dist/collections/index.mjs.map +0 -1
  53. package/dist/index.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/edit/index.ts","../../src/edit/errors.ts","../../src/edit/client.ts","../../src/edit/diff.ts","../../src/edit/prompts.ts","../../src/edit/session.ts"],"sourcesContent":["/**\n * Arke SDK - Edit Package\n *\n * Provides intelligent editing capabilities for Arke entities:\n * - Direct content editing with version control\n * - AI-powered regeneration of components (pinax, description, cheimarros)\n * - Cascade updates up the entity tree\n *\n * @example\n * ```typescript\n * import { EditClient, EditSession } from '@arke-institute/sdk/edit';\n *\n * const client = new EditClient({\n * gatewayUrl: 'https://gateway.arke.io',\n * authToken: 'your-jwt-token',\n * });\n *\n * // Create an edit session for an entity\n * const session = new EditSession(client, 'PI_HERE', {\n * mode: 'ai-prompt',\n * });\n *\n * // Load the entity\n * await session.load();\n *\n * // Set a prompt for AI regeneration\n * session.setPrompt('general', 'Fix any OCR errors and improve the description.');\n * session.setScope({ components: ['description', 'pinax'], cascade: true });\n *\n * // Submit and wait for completion\n * const result = await session.submit('Fix OCR errors');\n * const status = await session.waitForCompletion();\n * ```\n */\n\n// Client\nexport { EditClient, type EditClientConfig } from './client';\n\n// Session\nexport { EditSession } from './session';\n\n// Types\nexport type {\n // Configuration\n EditMode,\n EditSessionConfig,\n // Entity\n Entity,\n EntityUpdate,\n EntityVersion,\n // Edit\n RegeneratableComponent,\n EditScope,\n Correction,\n // Diff\n DiffType,\n TextDiff,\n ComponentDiff,\n // Prompt\n PromptTarget,\n EntityContext,\n CascadeContext,\n // Reprocess\n CustomPrompts,\n ReprocessRequest,\n ReprocessResult,\n ReprocessPhase,\n ReprocessProgress,\n ReprocessStatus,\n // Results\n SaveResult,\n EditResult,\n EditPhase,\n EditStatus,\n PollOptions,\n // Summary\n ChangeSummary,\n} from './types';\n\n// Errors\nexport {\n EditError,\n EntityNotFoundError,\n CASConflictError,\n ReprocessError,\n ValidationError,\n PermissionError,\n} from './errors';\n\n// Utilities (for advanced use cases)\nexport { DiffEngine } from './diff';\nexport { PromptBuilder } from './prompts';\n","/**\n * Error classes for edit operations\n */\n\nexport class EditError extends Error {\n constructor(\n message: string,\n public code: string = 'UNKNOWN_ERROR',\n public details?: unknown\n ) {\n super(message);\n this.name = 'EditError';\n }\n}\n\nexport class EntityNotFoundError extends EditError {\n constructor(pi: string) {\n super(`Entity not found: ${pi}`, 'ENTITY_NOT_FOUND', { pi });\n this.name = 'EntityNotFoundError';\n }\n}\n\nexport class CASConflictError extends EditError {\n constructor(pi: string, expectedTip: string, actualTip: string) {\n super(\n `CAS conflict: entity ${pi} was modified (expected ${expectedTip}, got ${actualTip})`,\n 'CAS_CONFLICT',\n { pi, expectedTip, actualTip }\n );\n this.name = 'CASConflictError';\n }\n}\n\nexport class ReprocessError extends EditError {\n constructor(message: string, batchId?: string) {\n super(message, 'REPROCESS_ERROR', { batchId });\n this.name = 'ReprocessError';\n }\n}\n\nexport class ValidationError extends EditError {\n constructor(message: string, field?: string) {\n super(message, 'VALIDATION_ERROR', { field });\n this.name = 'ValidationError';\n }\n}\n\nexport class PermissionError extends EditError {\n constructor(message: string, pi?: string) {\n super(message, 'PERMISSION_DENIED', { pi });\n this.name = 'PermissionError';\n }\n}\n","/**\n * EditClient - Low-level API client for Arke edit operations\n *\n * Routes through the gateway:\n * - /api/* -> IPFS Wrapper (entities, content, uploads)\n * - /reprocess/* -> Reprocess API\n */\n\nimport type {\n Entity,\n EntityUpdate,\n EntityVersion,\n ReprocessRequest,\n ReprocessResult,\n ReprocessStatus,\n} from './types';\nimport {\n EditError,\n EntityNotFoundError,\n CASConflictError,\n ReprocessError,\n PermissionError,\n} from './errors';\n\n/** Configuration for EditClient */\nexport interface EditClientConfig {\n /** Gateway URL (e.g., https://gateway.arke.io) */\n gatewayUrl: string;\n /** JWT auth token */\n authToken?: string;\n /** Optional transform for status URLs (e.g., for CORS proxy) */\n statusUrlTransform?: (url: string) => string;\n}\n\n/** Default retry options for status polling */\nconst DEFAULT_RETRY_OPTIONS = {\n maxRetries: 5,\n initialDelayMs: 2000, // Start with 2s delay (orchestrator needs time to initialize)\n maxDelayMs: 30000, // Cap at 30s\n backoffMultiplier: 2, // Double each retry\n};\n\nexport class EditClient {\n private gatewayUrl: string;\n private authToken?: string;\n private statusUrlTransform?: (url: string) => string;\n\n constructor(config: EditClientConfig) {\n this.gatewayUrl = config.gatewayUrl.replace(/\\/$/, '');\n this.authToken = config.authToken;\n this.statusUrlTransform = config.statusUrlTransform;\n }\n\n /**\n * Update the auth token (useful for token refresh)\n */\n setAuthToken(token: string): void {\n this.authToken = token;\n }\n\n /**\n * Sleep for a given number of milliseconds\n */\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * Execute a fetch with exponential backoff retry on transient errors\n */\n private async fetchWithRetry(\n url: string,\n options: RequestInit,\n retryOptions = DEFAULT_RETRY_OPTIONS\n ): Promise<Response> {\n let lastError: Error | null = null;\n let delay = retryOptions.initialDelayMs;\n\n for (let attempt = 0; attempt <= retryOptions.maxRetries; attempt++) {\n try {\n const response = await fetch(url, options);\n\n // Retry on 5xx errors (server errors)\n if (response.status >= 500 && attempt < retryOptions.maxRetries) {\n lastError = new Error(`Server error: ${response.status} ${response.statusText}`);\n await this.sleep(delay);\n delay = Math.min(delay * retryOptions.backoffMultiplier, retryOptions.maxDelayMs);\n continue;\n }\n\n return response;\n } catch (error) {\n // Network errors - retry\n lastError = error as Error;\n if (attempt < retryOptions.maxRetries) {\n await this.sleep(delay);\n delay = Math.min(delay * retryOptions.backoffMultiplier, retryOptions.maxDelayMs);\n }\n }\n }\n\n throw lastError || new Error('Request failed after retries');\n }\n\n private getHeaders(): HeadersInit {\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n };\n if (this.authToken) {\n headers['Authorization'] = `Bearer ${this.authToken}`;\n }\n return headers;\n }\n\n /**\n * Handle common error responses\n */\n private handleErrorResponse(response: Response, context: string): never {\n if (response.status === 403) {\n throw new PermissionError(`Permission denied: ${context}`);\n }\n throw new EditError(\n `${context}: ${response.statusText}`,\n 'API_ERROR',\n { status: response.status }\n );\n }\n\n // ===========================================================================\n // IPFS Wrapper Operations (via /api/*)\n // ===========================================================================\n\n /**\n * Fetch an entity by PI\n */\n async getEntity(pi: string): Promise<Entity> {\n const response = await fetch(`${this.gatewayUrl}/api/entities/${pi}`, {\n headers: this.getHeaders(),\n });\n\n if (response.status === 404) {\n throw new EntityNotFoundError(pi);\n }\n\n if (!response.ok) {\n this.handleErrorResponse(response, `Failed to fetch entity ${pi}`);\n }\n\n return response.json();\n }\n\n /**\n * Fetch content by CID\n */\n async getContent(cid: string): Promise<string> {\n const response = await fetch(`${this.gatewayUrl}/api/cat/${cid}`, {\n headers: this.getHeaders(),\n });\n\n if (!response.ok) {\n this.handleErrorResponse(response, `Failed to fetch content ${cid}`);\n }\n\n return response.text();\n }\n\n /**\n * Upload content and get CID\n */\n async uploadContent(content: string, filename: string): Promise<string> {\n const formData = new FormData();\n const blob = new Blob([content], { type: 'text/plain' });\n formData.append('file', blob, filename);\n\n const headers: HeadersInit = {};\n if (this.authToken) {\n headers['Authorization'] = `Bearer ${this.authToken}`;\n }\n\n const response = await fetch(`${this.gatewayUrl}/api/upload`, {\n method: 'POST',\n headers,\n body: formData,\n });\n\n if (!response.ok) {\n this.handleErrorResponse(response, 'Failed to upload content');\n }\n\n const result = await response.json();\n // Response format: [{ cid, name, size }]\n return result[0].cid;\n }\n\n /**\n * Update an entity with new components\n */\n async updateEntity(pi: string, update: EntityUpdate): Promise<EntityVersion> {\n const response = await fetch(`${this.gatewayUrl}/api/entities/${pi}/versions`, {\n method: 'POST',\n headers: this.getHeaders(),\n body: JSON.stringify({\n expect_tip: update.expect_tip,\n components: update.components,\n components_remove: update.components_remove,\n note: update.note,\n }),\n });\n\n if (response.status === 409) {\n // CAS conflict - entity was modified\n const entity = await this.getEntity(pi);\n throw new CASConflictError(\n pi,\n update.expect_tip,\n entity.manifest_cid\n );\n }\n\n if (!response.ok) {\n this.handleErrorResponse(response, `Failed to update entity ${pi}`);\n }\n\n return response.json();\n }\n\n // ===========================================================================\n // Reprocess API Operations (via /reprocess/*)\n // ===========================================================================\n\n /**\n * Trigger reprocessing for an entity\n */\n async reprocess(request: ReprocessRequest): Promise<ReprocessResult> {\n const response = await fetch(`${this.gatewayUrl}/reprocess/reprocess`, {\n method: 'POST',\n headers: this.getHeaders(),\n body: JSON.stringify({\n pi: request.pi,\n phases: request.phases,\n cascade: request.cascade,\n options: request.options,\n }),\n });\n\n if (response.status === 403) {\n const error = await response.json().catch(() => ({}));\n throw new PermissionError(\n error.message || `Permission denied to reprocess ${request.pi}`,\n request.pi\n );\n }\n\n if (!response.ok) {\n const error = await response.json().catch(() => ({}));\n throw new ReprocessError(\n error.message || `Reprocess failed: ${response.statusText}`,\n undefined\n );\n }\n\n return response.json();\n }\n\n /**\n * Get reprocessing status by batch ID\n *\n * Uses exponential backoff retry to handle transient 500 errors\n * that occur when the orchestrator is initializing.\n *\n * @param statusUrl - The status URL returned from reprocess()\n * @param isFirstPoll - If true, uses a longer initial delay (orchestrator warmup)\n */\n async getReprocessStatus(statusUrl: string, isFirstPoll = false): Promise<ReprocessStatus> {\n // Use longer initial delay for first poll after triggering reprocess\n const retryOptions = isFirstPoll\n ? { ...DEFAULT_RETRY_OPTIONS, initialDelayMs: 3000 }\n : DEFAULT_RETRY_OPTIONS;\n\n // Apply URL transform if configured (for CORS proxy)\n const fetchUrl = this.statusUrlTransform ? this.statusUrlTransform(statusUrl) : statusUrl;\n\n const response = await this.fetchWithRetry(\n fetchUrl,\n { headers: this.getHeaders() },\n retryOptions\n );\n\n if (!response.ok) {\n throw new EditError(\n `Failed to fetch reprocess status: ${response.statusText}`,\n 'STATUS_ERROR',\n { status: response.status }\n );\n }\n\n return response.json();\n }\n}\n","/**\n * DiffEngine - Text comparison and diff formatting\n */\n\nimport * as Diff from 'diff';\nimport type { TextDiff, ComponentDiff, Correction } from './types';\n\nexport class DiffEngine {\n /**\n * Compute diff between two strings\n */\n static diff(original: string, modified: string): TextDiff[] {\n const changes = Diff.diffLines(original, modified);\n const diffs: TextDiff[] = [];\n let lineNumber = 1;\n\n for (const change of changes) {\n if (change.added) {\n diffs.push({\n type: 'addition',\n modified: change.value.trimEnd(),\n lineNumber,\n });\n } else if (change.removed) {\n diffs.push({\n type: 'deletion',\n original: change.value.trimEnd(),\n lineNumber,\n });\n } else {\n // Track line numbers for unchanged content\n const lines = change.value.split('\\n').length - 1;\n lineNumber += lines;\n }\n\n // Update line number for added content\n if (change.added) {\n lineNumber += change.value.split('\\n').length - 1;\n }\n }\n\n return diffs;\n }\n\n /**\n * Compute word-level diff for more granular changes\n */\n static diffWords(original: string, modified: string): TextDiff[] {\n const changes = Diff.diffWords(original, modified);\n const diffs: TextDiff[] = [];\n\n for (const change of changes) {\n if (change.added) {\n diffs.push({\n type: 'addition',\n modified: change.value,\n });\n } else if (change.removed) {\n diffs.push({\n type: 'deletion',\n original: change.value,\n });\n }\n }\n\n return diffs;\n }\n\n /**\n * Create a ComponentDiff from original and modified content\n */\n static createComponentDiff(\n componentName: string,\n original: string,\n modified: string\n ): ComponentDiff {\n const diffs = this.diff(original, modified);\n const hasChanges = diffs.length > 0;\n\n let summary: string;\n if (!hasChanges) {\n summary = 'No changes';\n } else {\n const additions = diffs.filter((d) => d.type === 'addition').length;\n const deletions = diffs.filter((d) => d.type === 'deletion').length;\n const parts: string[] = [];\n if (additions > 0) parts.push(`${additions} addition${additions > 1 ? 's' : ''}`);\n if (deletions > 0) parts.push(`${deletions} deletion${deletions > 1 ? 's' : ''}`);\n summary = parts.join(', ');\n }\n\n return {\n componentName,\n diffs,\n summary,\n hasChanges,\n };\n }\n\n /**\n * Format diffs for AI prompt consumption\n */\n static formatForPrompt(diffs: TextDiff[]): string {\n if (diffs.length === 0) {\n return 'No changes detected.';\n }\n\n const lines: string[] = [];\n\n for (const diff of diffs) {\n const linePrefix = diff.lineNumber ? `Line ${diff.lineNumber}: ` : '';\n\n if (diff.type === 'addition') {\n lines.push(`${linePrefix}+ ${diff.modified}`);\n } else if (diff.type === 'deletion') {\n lines.push(`${linePrefix}- ${diff.original}`);\n } else if (diff.type === 'change') {\n lines.push(`${linePrefix}\"${diff.original}\" → \"${diff.modified}\"`);\n }\n }\n\n return lines.join('\\n');\n }\n\n /**\n * Format component diffs for AI prompt\n */\n static formatComponentDiffsForPrompt(componentDiffs: ComponentDiff[]): string {\n const sections: string[] = [];\n\n for (const cd of componentDiffs) {\n if (!cd.hasChanges) continue;\n\n sections.push(`## Changes to ${cd.componentName}:`);\n sections.push(this.formatForPrompt(cd.diffs));\n sections.push('');\n }\n\n return sections.join('\\n');\n }\n\n /**\n * Create a unified diff view\n */\n static unifiedDiff(\n original: string,\n modified: string,\n options?: { filename?: string; context?: number }\n ): string {\n const filename = options?.filename || 'content';\n const patch = Diff.createPatch(filename, original, modified, '', '', {\n context: options?.context ?? 3,\n });\n return patch;\n }\n\n /**\n * Extract corrections from diffs (specific text replacements)\n */\n static extractCorrections(\n original: string,\n modified: string,\n sourceFile?: string\n ): Correction[] {\n const wordDiffs = Diff.diffWords(original, modified);\n const corrections: Correction[] = [];\n\n let i = 0;\n while (i < wordDiffs.length) {\n const current = wordDiffs[i];\n\n // Look for removal followed by addition (a replacement)\n if (current.removed && i + 1 < wordDiffs.length && wordDiffs[i + 1].added) {\n const removed = current.value.trim();\n const added = wordDiffs[i + 1].value.trim();\n\n if (removed && added && removed !== added) {\n corrections.push({\n original: removed,\n corrected: added,\n sourceFile,\n });\n }\n i += 2;\n } else {\n i++;\n }\n }\n\n return corrections;\n }\n\n /**\n * Check if two strings are meaningfully different\n * (ignoring whitespace differences)\n */\n static hasSignificantChanges(original: string, modified: string): boolean {\n const normalizedOriginal = original.replace(/\\s+/g, ' ').trim();\n const normalizedModified = modified.replace(/\\s+/g, ' ').trim();\n return normalizedOriginal !== normalizedModified;\n }\n}\n","/**\n * PromptBuilder - Context-aware AI prompt construction\n */\n\nimport { DiffEngine } from './diff';\nimport type {\n RegeneratableComponent,\n EntityContext,\n CascadeContext,\n ComponentDiff,\n Correction,\n} from './types';\n\nexport class PromptBuilder {\n /**\n * Build prompt for AI-first mode (user provides instructions)\n */\n static buildAIPrompt(\n userPrompt: string,\n component: RegeneratableComponent,\n entityContext: EntityContext,\n currentContent?: string\n ): string {\n const sections: string[] = [];\n\n // User instruction\n sections.push(`## Instructions for ${component}`);\n sections.push(userPrompt);\n sections.push('');\n\n // Entity context\n sections.push('## Entity Context');\n sections.push(`- PI: ${entityContext.pi}`);\n sections.push(`- Current version: ${entityContext.ver}`);\n if (entityContext.parentPi) {\n sections.push(`- Parent: ${entityContext.parentPi}`);\n }\n if (entityContext.childrenCount > 0) {\n sections.push(`- Children: ${entityContext.childrenCount}`);\n }\n sections.push('');\n\n // Current content reference\n if (currentContent) {\n sections.push(`## Current ${component} content for reference:`);\n sections.push('```');\n sections.push(currentContent.slice(0, 2000)); // Truncate if very long\n if (currentContent.length > 2000) {\n sections.push('... [truncated]');\n }\n sections.push('```');\n }\n\n return sections.join('\\n');\n }\n\n /**\n * Build prompt incorporating manual edits and diffs\n */\n static buildEditReviewPrompt(\n componentDiffs: ComponentDiff[],\n corrections: Correction[],\n component: RegeneratableComponent,\n userInstructions?: string\n ): string {\n const sections: string[] = [];\n\n sections.push('## Manual Edits Made');\n sections.push('');\n sections.push('The following manual edits were made to this entity:');\n sections.push('');\n\n // Show diffs\n const diffContent = DiffEngine.formatComponentDiffsForPrompt(componentDiffs);\n if (diffContent) {\n sections.push(diffContent);\n }\n\n // Show corrections\n if (corrections.length > 0) {\n sections.push('## Corrections Identified');\n sections.push('');\n for (const correction of corrections) {\n const source = correction.sourceFile ? ` (in ${correction.sourceFile})` : '';\n sections.push(`- \"${correction.original}\" → \"${correction.corrected}\"${source}`);\n }\n sections.push('');\n }\n\n // User instructions\n sections.push('## Instructions');\n if (userInstructions) {\n sections.push(userInstructions);\n } else {\n sections.push(\n `Update the ${component} to accurately reflect these changes. ` +\n 'Ensure any corrections are incorporated and the content is consistent.'\n );\n }\n sections.push('');\n\n // Specific guidance per component\n sections.push('## Guidance');\n switch (component) {\n case 'pinax':\n sections.push(\n 'Update metadata fields to reflect any corrections. Pay special attention to dates, ' +\n 'names, and other factual information that may have been corrected.'\n );\n break;\n case 'description':\n sections.push(\n 'Regenerate the description incorporating the changes. Maintain the overall tone ' +\n 'and structure while ensuring accuracy based on the corrections.'\n );\n break;\n case 'cheimarros':\n sections.push(\n 'Update the knowledge graph to reflect any new or corrected entities, relationships, ' +\n 'and facts identified in the changes.'\n );\n break;\n }\n\n return sections.join('\\n');\n }\n\n /**\n * Build cascade-aware prompt additions\n */\n static buildCascadePrompt(basePrompt: string, cascadeContext: CascadeContext): string {\n const sections: string[] = [basePrompt];\n\n sections.push('');\n sections.push('## Cascade Context');\n sections.push('');\n sections.push(\n 'This edit is part of a cascading update. After updating this entity, ' +\n 'parent entities will also be updated to reflect these changes.'\n );\n sections.push('');\n\n if (cascadeContext.path.length > 1) {\n sections.push(`Cascade path: ${cascadeContext.path.join(' → ')}`);\n sections.push(`Depth: ${cascadeContext.depth}`);\n }\n\n if (cascadeContext.stopAtPi) {\n sections.push(`Cascade will stop at: ${cascadeContext.stopAtPi}`);\n }\n\n sections.push('');\n sections.push(\n 'Ensure the content accurately represents the source material so parent ' +\n 'aggregations will be correct.'\n );\n\n return sections.join('\\n');\n }\n\n /**\n * Build a general prompt combining multiple instructions\n */\n static buildCombinedPrompt(\n generalPrompt: string | undefined,\n componentPrompt: string | undefined,\n component: RegeneratableComponent\n ): string {\n const sections: string[] = [];\n\n if (generalPrompt) {\n sections.push('## General Instructions');\n sections.push(generalPrompt);\n sections.push('');\n }\n\n if (componentPrompt) {\n sections.push(`## Specific Instructions for ${component}`);\n sections.push(componentPrompt);\n sections.push('');\n }\n\n if (sections.length === 0) {\n return `Regenerate the ${component} based on the current entity content.`;\n }\n\n return sections.join('\\n');\n }\n\n /**\n * Build prompt for correction-based updates\n */\n static buildCorrectionPrompt(corrections: Correction[]): string {\n if (corrections.length === 0) {\n return '';\n }\n\n const sections: string[] = [];\n\n sections.push('## Corrections Applied');\n sections.push('');\n sections.push('The following corrections were made to the source content:');\n sections.push('');\n\n for (const correction of corrections) {\n const source = correction.sourceFile ? ` in ${correction.sourceFile}` : '';\n sections.push(`- \"${correction.original}\" was corrected to \"${correction.corrected}\"${source}`);\n if (correction.context) {\n sections.push(` Context: ${correction.context}`);\n }\n }\n\n sections.push('');\n sections.push(\n 'Update the metadata and description to reflect these corrections. ' +\n 'Previous content may have contained errors based on the incorrect text.'\n );\n\n return sections.join('\\n');\n }\n\n /**\n * Get component-specific regeneration guidance\n */\n static getComponentGuidance(component: RegeneratableComponent): string {\n switch (component) {\n case 'pinax':\n return (\n 'Extract and structure metadata including: institution, creator, title, ' +\n 'date range, subjects, type, and other relevant fields. Ensure accuracy ' +\n 'based on the source content.'\n );\n case 'description':\n return (\n 'Generate a clear, informative description that summarizes the entity content. ' +\n 'Focus on what the material contains, its historical significance, and context. ' +\n 'Write for a general audience unless otherwise specified.'\n );\n case 'cheimarros':\n return (\n 'Extract entities (people, places, organizations, events) and their relationships. ' +\n 'Build a knowledge graph that captures the key facts and connections in the content.'\n );\n default:\n return '';\n }\n }\n}\n","/**\n * EditSession - Stateful session managing an edit workflow\n */\n\nimport { EditClient } from './client';\nimport { DiffEngine } from './diff';\nimport { PromptBuilder } from './prompts';\nimport type {\n Entity,\n EditMode,\n EditSessionConfig,\n EditScope,\n Correction,\n ComponentDiff,\n RegeneratableComponent,\n PromptTarget,\n ChangeSummary,\n EditResult,\n EditStatus,\n PollOptions,\n CustomPrompts,\n} from './types';\nimport { ValidationError } from './errors';\n\nconst DEFAULT_SCOPE: EditScope = {\n components: [],\n cascade: false,\n};\n\nconst DEFAULT_POLL_OPTIONS: Required<Omit<PollOptions, 'onProgress'>> = {\n intervalMs: 2000,\n timeoutMs: 300000, // 5 minutes\n};\n\nexport class EditSession {\n readonly pi: string;\n readonly mode: EditMode;\n readonly aiReviewEnabled: boolean;\n\n private client: EditClient;\n private entity: Entity | null = null;\n private loadedComponents: Record<string, string> = {};\n\n // AI mode state\n private prompts: Record<string, string> = {};\n\n // Manual mode state\n private editedContent: Record<string, string> = {};\n private corrections: Correction[] = [];\n\n // Scope\n private scope: EditScope = { ...DEFAULT_SCOPE };\n\n // Execution state\n private submitting = false;\n private result: EditResult | null = null;\n private statusUrl: string | null = null;\n\n constructor(client: EditClient, pi: string, config?: EditSessionConfig) {\n this.client = client;\n this.pi = pi;\n this.mode = config?.mode ?? 'ai-prompt';\n this.aiReviewEnabled = config?.aiReviewEnabled ?? true;\n }\n\n // ===========================================================================\n // Loading\n // ===========================================================================\n\n /**\n * Load the entity and its key components\n */\n async load(): Promise<void> {\n this.entity = await this.client.getEntity(this.pi);\n\n // Load key components that are commonly edited\n const priorityComponents = ['description.md', 'pinax.json', 'cheimarros.json'];\n\n await Promise.all(\n priorityComponents.map(async (name) => {\n const cid = this.entity!.components[name];\n if (cid) {\n try {\n this.loadedComponents[name] = await this.client.getContent(cid);\n } catch {\n // Component may not exist, that's ok\n }\n }\n })\n );\n }\n\n /**\n * Load a specific component on demand\n */\n async loadComponent(name: string): Promise<string | undefined> {\n if (this.loadedComponents[name]) {\n return this.loadedComponents[name];\n }\n\n if (!this.entity) {\n throw new ValidationError('Session not loaded');\n }\n\n const cid = this.entity.components[name];\n if (!cid) {\n return undefined;\n }\n\n const content = await this.client.getContent(cid);\n this.loadedComponents[name] = content;\n return content;\n }\n\n /**\n * Get the loaded entity\n */\n getEntity(): Entity {\n if (!this.entity) {\n throw new ValidationError('Session not loaded. Call load() first.');\n }\n return this.entity;\n }\n\n /**\n * Get loaded component content\n */\n getComponents(): Record<string, string> {\n return { ...this.loadedComponents };\n }\n\n // ===========================================================================\n // AI Prompt Mode\n // ===========================================================================\n\n /**\n * Set a prompt for AI regeneration\n */\n setPrompt(target: PromptTarget, prompt: string): void {\n if (this.mode === 'manual-only') {\n throw new ValidationError('Cannot set prompts in manual-only mode');\n }\n this.prompts[target] = prompt;\n }\n\n /**\n * Get all prompts\n */\n getPrompts(): Record<string, string> {\n return { ...this.prompts };\n }\n\n /**\n * Clear a prompt\n */\n clearPrompt(target: PromptTarget): void {\n delete this.prompts[target];\n }\n\n // ===========================================================================\n // Manual Edit Mode\n // ===========================================================================\n\n /**\n * Set edited content for a component\n */\n setContent(componentName: string, content: string): void {\n if (this.mode === 'ai-prompt') {\n throw new ValidationError('Cannot set content in ai-prompt mode');\n }\n this.editedContent[componentName] = content;\n }\n\n /**\n * Get all edited content\n */\n getEditedContent(): Record<string, string> {\n return { ...this.editedContent };\n }\n\n /**\n * Clear edited content for a component\n */\n clearContent(componentName: string): void {\n delete this.editedContent[componentName];\n }\n\n /**\n * Add a correction (for OCR fixes, etc.)\n */\n addCorrection(original: string, corrected: string, sourceFile?: string): void {\n this.corrections.push({ original, corrected, sourceFile });\n }\n\n /**\n * Get all corrections\n */\n getCorrections(): Correction[] {\n return [...this.corrections];\n }\n\n /**\n * Clear corrections\n */\n clearCorrections(): void {\n this.corrections = [];\n }\n\n // ===========================================================================\n // Scope Configuration\n // ===========================================================================\n\n /**\n * Set the edit scope\n */\n setScope(scope: Partial<EditScope>): void {\n this.scope = { ...this.scope, ...scope };\n }\n\n /**\n * Get the current scope\n */\n getScope(): EditScope {\n return { ...this.scope };\n }\n\n // ===========================================================================\n // Preview & Summary\n // ===========================================================================\n\n /**\n * Get diffs for manual changes\n */\n getDiff(): ComponentDiff[] {\n const diffs: ComponentDiff[] = [];\n\n for (const [name, edited] of Object.entries(this.editedContent)) {\n const original = this.loadedComponents[name] || '';\n if (DiffEngine.hasSignificantChanges(original, edited)) {\n diffs.push(DiffEngine.createComponentDiff(name, original, edited));\n }\n }\n\n return diffs;\n }\n\n /**\n * Preview what prompts will be sent to AI\n */\n previewPrompt(): Record<RegeneratableComponent, string> {\n const result: Record<string, string> = {};\n\n if (!this.entity) return result as Record<RegeneratableComponent, string>;\n\n const entityContext = {\n pi: this.entity.pi,\n ver: this.entity.ver,\n parentPi: this.entity.parent_pi,\n childrenCount: this.entity.children_pi.length,\n currentContent: this.loadedComponents,\n };\n\n for (const component of this.scope.components) {\n let prompt: string;\n\n if (this.mode === 'ai-prompt') {\n // AI prompt mode: use user's prompt\n const componentPrompt = this.prompts[component];\n const generalPrompt = this.prompts['general'];\n const combined = PromptBuilder.buildCombinedPrompt(generalPrompt, componentPrompt, component);\n prompt = PromptBuilder.buildAIPrompt(\n combined,\n component,\n entityContext,\n this.loadedComponents[`${component}.json`] || this.loadedComponents[`${component}.md`]\n );\n } else {\n // Manual mode: build from diffs and corrections\n const diffs = this.getDiff();\n const userInstructions = this.prompts['general'] || this.prompts[component];\n prompt = PromptBuilder.buildEditReviewPrompt(diffs, this.corrections, component, userInstructions);\n }\n\n // Add cascade context if applicable\n if (this.scope.cascade) {\n prompt = PromptBuilder.buildCascadePrompt(prompt, {\n path: [this.entity.pi, this.entity.parent_pi || 'root'].filter(Boolean) as string[],\n depth: 0,\n stopAtPi: this.scope.stopAtPi,\n });\n }\n\n result[component] = prompt;\n }\n\n return result as Record<RegeneratableComponent, string>;\n }\n\n /**\n * Get a summary of pending changes\n */\n getChangeSummary(): ChangeSummary {\n const diffs = this.getDiff();\n const hasManualEdits = diffs.some((d) => d.hasChanges);\n\n return {\n mode: this.mode,\n hasManualEdits,\n editedComponents: Object.keys(this.editedContent),\n corrections: [...this.corrections],\n prompts: { ...this.prompts },\n scope: { ...this.scope },\n willRegenerate: [...this.scope.components],\n willCascade: this.scope.cascade,\n willSave: hasManualEdits,\n willReprocess: this.scope.components.length > 0,\n };\n }\n\n // ===========================================================================\n // Execution\n // ===========================================================================\n\n /**\n * Submit changes (saves first if manual edits, then reprocesses)\n */\n async submit(note: string): Promise<EditResult> {\n if (this.submitting) {\n throw new ValidationError('Submit already in progress');\n }\n if (!this.entity) {\n throw new ValidationError('Session not loaded. Call load() first.');\n }\n\n this.submitting = true;\n this.result = {};\n\n try {\n // Phase 1: Save manual edits if any\n const diffs = this.getDiff();\n const hasManualEdits = diffs.some((d) => d.hasChanges);\n\n if (hasManualEdits) {\n // Upload edited components and collect CIDs\n const componentUpdates: Record<string, string> = {};\n\n for (const [name, content] of Object.entries(this.editedContent)) {\n const original = this.loadedComponents[name] || '';\n if (DiffEngine.hasSignificantChanges(original, content)) {\n const cid = await this.client.uploadContent(content, name);\n componentUpdates[name] = cid;\n }\n }\n\n // Update entity\n const version = await this.client.updateEntity(this.pi, {\n expect_tip: this.entity.manifest_cid,\n components: componentUpdates,\n note,\n });\n\n this.result.saved = {\n pi: version.pi,\n newVersion: version.ver,\n newTip: version.tip,\n };\n\n // Update our entity reference\n this.entity.manifest_cid = version.tip;\n this.entity.ver = version.ver;\n }\n\n // Phase 2: Trigger reprocessing if components selected\n if (this.scope.components.length > 0) {\n const customPrompts = this.buildCustomPrompts();\n\n const reprocessResult = await this.client.reprocess({\n pi: this.pi,\n phases: this.scope.components,\n cascade: this.scope.cascade,\n options: {\n stop_at_pi: this.scope.stopAtPi,\n custom_prompts: customPrompts,\n custom_note: note,\n },\n });\n\n this.result.reprocess = reprocessResult;\n this.statusUrl = reprocessResult.status_url;\n }\n\n return this.result;\n } finally {\n this.submitting = false;\n }\n }\n\n /**\n * Wait for reprocessing to complete\n */\n async waitForCompletion(options?: PollOptions): Promise<EditStatus> {\n const opts = { ...DEFAULT_POLL_OPTIONS, ...options };\n\n if (!this.statusUrl) {\n return {\n phase: 'complete',\n saveComplete: true,\n };\n }\n\n const startTime = Date.now();\n let isFirstPoll = true;\n\n while (true) {\n // Pass isFirstPoll flag - the client will use longer retry delays on first poll\n // since the orchestrator often needs time to initialize after reprocess is triggered\n const status = await this.client.getReprocessStatus(this.statusUrl, isFirstPoll);\n isFirstPoll = false;\n\n const editStatus: EditStatus = {\n phase: status.status === 'DONE' ? 'complete' : status.status === 'ERROR' ? 'error' : 'reprocessing',\n saveComplete: true,\n reprocessStatus: status,\n error: status.error,\n };\n\n if (opts.onProgress) {\n opts.onProgress(editStatus);\n }\n\n if (status.status === 'DONE' || status.status === 'ERROR') {\n return editStatus;\n }\n\n if (Date.now() - startTime > opts.timeoutMs) {\n return {\n phase: 'error',\n saveComplete: true,\n reprocessStatus: status,\n error: 'Timeout waiting for reprocessing to complete',\n };\n }\n\n await new Promise((resolve) => setTimeout(resolve, opts.intervalMs));\n }\n }\n\n /**\n * Get current status without waiting\n */\n async getStatus(): Promise<EditStatus> {\n if (!this.statusUrl) {\n return {\n phase: this.result?.saved ? 'complete' : 'idle',\n saveComplete: !!this.result?.saved,\n };\n }\n\n const status = await this.client.getReprocessStatus(this.statusUrl);\n\n return {\n phase: status.status === 'DONE' ? 'complete' : status.status === 'ERROR' ? 'error' : 'reprocessing',\n saveComplete: true,\n reprocessStatus: status,\n error: status.error,\n };\n }\n\n // ===========================================================================\n // Private Helpers\n // ===========================================================================\n\n private buildCustomPrompts(): CustomPrompts {\n const custom: CustomPrompts = {};\n\n // In AI prompt mode, prompts go directly to reprocess API\n if (this.mode === 'ai-prompt') {\n if (this.prompts['general']) custom.general = this.prompts['general'];\n if (this.prompts['pinax']) custom.pinax = this.prompts['pinax'];\n if (this.prompts['description']) custom.description = this.prompts['description'];\n if (this.prompts['cheimarros']) custom.cheimarros = this.prompts['cheimarros'];\n } else {\n // Manual mode: build prompts from diffs, corrections, and user instructions\n const diffs = this.getDiff();\n const diffContext = DiffEngine.formatComponentDiffsForPrompt(diffs);\n const correctionContext = PromptBuilder.buildCorrectionPrompt(this.corrections);\n\n // Combine all context: diffs + corrections + user instructions\n const basePrompt = [diffContext, correctionContext, this.prompts['general']]\n .filter(Boolean)\n .join('\\n\\n');\n\n if (basePrompt) {\n custom.general = basePrompt;\n }\n\n // Component-specific prompts\n if (this.prompts['pinax']) custom.pinax = this.prompts['pinax'];\n if (this.prompts['description']) custom.description = this.prompts['description'];\n if (this.prompts['cheimarros']) custom.cheimarros = this.prompts['cheimarros'];\n }\n\n return custom;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,YAAN,cAAwB,MAAM;AAAA,EACnC,YACE,SACO,OAAe,iBACf,SACP;AACA,UAAM,OAAO;AAHN;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,sBAAN,cAAkC,UAAU;AAAA,EACjD,YAAY,IAAY;AACtB,UAAM,qBAAqB,EAAE,IAAI,oBAAoB,EAAE,GAAG,CAAC;AAC3D,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mBAAN,cAA+B,UAAU;AAAA,EAC9C,YAAY,IAAY,aAAqB,WAAmB;AAC9D;AAAA,MACE,wBAAwB,EAAE,2BAA2B,WAAW,SAAS,SAAS;AAAA,MAClF;AAAA,MACA,EAAE,IAAI,aAAa,UAAU;AAAA,IAC/B;AACA,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,iBAAN,cAA6B,UAAU;AAAA,EAC5C,YAAY,SAAiB,SAAkB;AAC7C,UAAM,SAAS,mBAAmB,EAAE,QAAQ,CAAC;AAC7C,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,kBAAN,cAA8B,UAAU;AAAA,EAC7C,YAAY,SAAiB,OAAgB;AAC3C,UAAM,SAAS,oBAAoB,EAAE,MAAM,CAAC;AAC5C,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,kBAAN,cA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AAA,IAChB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAMQ,qBAAoC;AAC1C,UAAM,SAAwB,CAAC;AAG/B,QAAI,KAAK,SAAS,aAAa;AAC7B,UAAI,KAAK,QAAQ,SAAS,EAAG,QAAO,UAAU,KAAK,QAAQ,SAAS;AACpE,UAAI,KAAK,QAAQ,OAAO,EAAG,QAAO,QAAQ,KAAK,QAAQ,OAAO;AAC9D,UAAI,KAAK,QAAQ,aAAa,EAAG,QAAO,cAAc,KAAK,QAAQ,aAAa;AAChF,UAAI,KAAK,QAAQ,YAAY,EAAG,QAAO,aAAa,KAAK,QAAQ,YAAY;AAAA,IAC/E,OAAO;AAEL,YAAM,QAAQ,KAAK,QAAQ;AAC3B,YAAM,cAAc,WAAW,8BAA8B,KAAK;AAClE,YAAM,oBAAoB,cAAc,sBAAsB,KAAK,WAAW;AAG9E,YAAM,aAAa,CAAC,aAAa,mBAAmB,KAAK,QAAQ,SAAS,CAAC,EACxE,OAAO,OAAO,EACd,KAAK,MAAM;AAEd,UAAI,YAAY;AACd,eAAO,UAAU;AAAA,MACnB;AAGA,UAAI,KAAK,QAAQ,OAAO,EAAG,QAAO,QAAQ,KAAK,QAAQ,OAAO;AAC9D,UAAI,KAAK,QAAQ,aAAa,EAAG,QAAO,cAAc,KAAK,QAAQ,aAAa;AAChF,UAAI,KAAK,QAAQ,YAAY,EAAG,QAAO,aAAa,KAAK,QAAQ,YAAY;AAAA,IAC/E;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,78 @@
1
+ import { T as TextDiff, C as ComponentDiff, l as Correction, R as RegeneratableComponent, m as EntityContext, n as CascadeContext } from '../errors-B82BMmRP.cjs';
2
+ export { z as CASConflictError, x as ChangeSummary, s as CustomPrompts, D as DiffType, E as EditClient, a as EditClientConfig, c as EditError, d as EditMode, i as EditPhase, g as EditResult, f as EditScope, b as EditSession, e as EditSessionConfig, h as EditStatus, o as Entity, y as EntityNotFoundError, p as EntityUpdate, q as EntityVersion, P as PermissionError, w as PollOptions, r as PromptTarget, A as ReprocessError, u as ReprocessPhase, v as ReprocessProgress, t as ReprocessRequest, j as ReprocessResult, k as ReprocessStatus, S as SaveResult, V as ValidationError } from '../errors-B82BMmRP.cjs';
3
+
4
+ /**
5
+ * DiffEngine - Text comparison and diff formatting
6
+ */
7
+
8
+ declare class DiffEngine {
9
+ /**
10
+ * Compute diff between two strings
11
+ */
12
+ static diff(original: string, modified: string): TextDiff[];
13
+ /**
14
+ * Compute word-level diff for more granular changes
15
+ */
16
+ static diffWords(original: string, modified: string): TextDiff[];
17
+ /**
18
+ * Create a ComponentDiff from original and modified content
19
+ */
20
+ static createComponentDiff(componentName: string, original: string, modified: string): ComponentDiff;
21
+ /**
22
+ * Format diffs for AI prompt consumption
23
+ */
24
+ static formatForPrompt(diffs: TextDiff[]): string;
25
+ /**
26
+ * Format component diffs for AI prompt
27
+ */
28
+ static formatComponentDiffsForPrompt(componentDiffs: ComponentDiff[]): string;
29
+ /**
30
+ * Create a unified diff view
31
+ */
32
+ static unifiedDiff(original: string, modified: string, options?: {
33
+ filename?: string;
34
+ context?: number;
35
+ }): string;
36
+ /**
37
+ * Extract corrections from diffs (specific text replacements)
38
+ */
39
+ static extractCorrections(original: string, modified: string, sourceFile?: string): Correction[];
40
+ /**
41
+ * Check if two strings are meaningfully different
42
+ * (ignoring whitespace differences)
43
+ */
44
+ static hasSignificantChanges(original: string, modified: string): boolean;
45
+ }
46
+
47
+ /**
48
+ * PromptBuilder - Context-aware AI prompt construction
49
+ */
50
+
51
+ declare class PromptBuilder {
52
+ /**
53
+ * Build prompt for AI-first mode (user provides instructions)
54
+ */
55
+ static buildAIPrompt(userPrompt: string, component: RegeneratableComponent, entityContext: EntityContext, currentContent?: string): string;
56
+ /**
57
+ * Build prompt incorporating manual edits and diffs
58
+ */
59
+ static buildEditReviewPrompt(componentDiffs: ComponentDiff[], corrections: Correction[], component: RegeneratableComponent, userInstructions?: string): string;
60
+ /**
61
+ * Build cascade-aware prompt additions
62
+ */
63
+ static buildCascadePrompt(basePrompt: string, cascadeContext: CascadeContext): string;
64
+ /**
65
+ * Build a general prompt combining multiple instructions
66
+ */
67
+ static buildCombinedPrompt(generalPrompt: string | undefined, componentPrompt: string | undefined, component: RegeneratableComponent): string;
68
+ /**
69
+ * Build prompt for correction-based updates
70
+ */
71
+ static buildCorrectionPrompt(corrections: Correction[]): string;
72
+ /**
73
+ * Get component-specific regeneration guidance
74
+ */
75
+ static getComponentGuidance(component: RegeneratableComponent): string;
76
+ }
77
+
78
+ export { CascadeContext, ComponentDiff, Correction, DiffEngine, EntityContext, PromptBuilder, RegeneratableComponent, TextDiff };
@@ -0,0 +1,78 @@
1
+ import { T as TextDiff, C as ComponentDiff, l as Correction, R as RegeneratableComponent, m as EntityContext, n as CascadeContext } from '../errors-B82BMmRP.js';
2
+ export { z as CASConflictError, x as ChangeSummary, s as CustomPrompts, D as DiffType, E as EditClient, a as EditClientConfig, c as EditError, d as EditMode, i as EditPhase, g as EditResult, f as EditScope, b as EditSession, e as EditSessionConfig, h as EditStatus, o as Entity, y as EntityNotFoundError, p as EntityUpdate, q as EntityVersion, P as PermissionError, w as PollOptions, r as PromptTarget, A as ReprocessError, u as ReprocessPhase, v as ReprocessProgress, t as ReprocessRequest, j as ReprocessResult, k as ReprocessStatus, S as SaveResult, V as ValidationError } from '../errors-B82BMmRP.js';
3
+
4
+ /**
5
+ * DiffEngine - Text comparison and diff formatting
6
+ */
7
+
8
+ declare class DiffEngine {
9
+ /**
10
+ * Compute diff between two strings
11
+ */
12
+ static diff(original: string, modified: string): TextDiff[];
13
+ /**
14
+ * Compute word-level diff for more granular changes
15
+ */
16
+ static diffWords(original: string, modified: string): TextDiff[];
17
+ /**
18
+ * Create a ComponentDiff from original and modified content
19
+ */
20
+ static createComponentDiff(componentName: string, original: string, modified: string): ComponentDiff;
21
+ /**
22
+ * Format diffs for AI prompt consumption
23
+ */
24
+ static formatForPrompt(diffs: TextDiff[]): string;
25
+ /**
26
+ * Format component diffs for AI prompt
27
+ */
28
+ static formatComponentDiffsForPrompt(componentDiffs: ComponentDiff[]): string;
29
+ /**
30
+ * Create a unified diff view
31
+ */
32
+ static unifiedDiff(original: string, modified: string, options?: {
33
+ filename?: string;
34
+ context?: number;
35
+ }): string;
36
+ /**
37
+ * Extract corrections from diffs (specific text replacements)
38
+ */
39
+ static extractCorrections(original: string, modified: string, sourceFile?: string): Correction[];
40
+ /**
41
+ * Check if two strings are meaningfully different
42
+ * (ignoring whitespace differences)
43
+ */
44
+ static hasSignificantChanges(original: string, modified: string): boolean;
45
+ }
46
+
47
+ /**
48
+ * PromptBuilder - Context-aware AI prompt construction
49
+ */
50
+
51
+ declare class PromptBuilder {
52
+ /**
53
+ * Build prompt for AI-first mode (user provides instructions)
54
+ */
55
+ static buildAIPrompt(userPrompt: string, component: RegeneratableComponent, entityContext: EntityContext, currentContent?: string): string;
56
+ /**
57
+ * Build prompt incorporating manual edits and diffs
58
+ */
59
+ static buildEditReviewPrompt(componentDiffs: ComponentDiff[], corrections: Correction[], component: RegeneratableComponent, userInstructions?: string): string;
60
+ /**
61
+ * Build cascade-aware prompt additions
62
+ */
63
+ static buildCascadePrompt(basePrompt: string, cascadeContext: CascadeContext): string;
64
+ /**
65
+ * Build a general prompt combining multiple instructions
66
+ */
67
+ static buildCombinedPrompt(generalPrompt: string | undefined, componentPrompt: string | undefined, component: RegeneratableComponent): string;
68
+ /**
69
+ * Build prompt for correction-based updates
70
+ */
71
+ static buildCorrectionPrompt(corrections: Correction[]): string;
72
+ /**
73
+ * Get component-specific regeneration guidance
74
+ */
75
+ static getComponentGuidance(component: RegeneratableComponent): string;
76
+ }
77
+
78
+ export { CascadeContext, ComponentDiff, Correction, DiffEngine, EntityContext, PromptBuilder, RegeneratableComponent, TextDiff };