@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/upload/utils/errors.ts","../src/upload/platforms/common.ts","../src/upload/lib/validation.ts","../src/upload/utils/hash.ts","../src/upload/types/processing.ts","../src/upload/platforms/node.ts","../src/upload/platforms/browser.ts","../src/index.ts","../src/collections/errors.ts","../src/collections/client.ts","../src/upload/lib/worker-client-fetch.ts","../src/upload/utils/retry.ts","../src/upload/uploader.ts","../src/upload/lib/simple-fetch.ts","../src/upload/lib/multipart-fetch.ts","../src/upload/client.ts","../src/query/errors.ts","../src/query/client.ts","../src/edit/errors.ts","../src/edit/client.ts","../src/edit/diff.ts","../src/edit/prompts.ts","../src/edit/session.ts","../src/content/errors.ts","../src/content/client.ts","../src/graph/errors.ts","../src/graph/client.ts"],"sourcesContent":["/**\n * Custom error classes for better error handling\n */\n\nexport class WorkerAPIError extends Error {\n constructor(\n message: string,\n public statusCode?: number,\n public details?: any\n ) {\n super(message);\n this.name = 'WorkerAPIError';\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\nexport class UploadError extends Error {\n constructor(\n message: string,\n public fileName?: string,\n public statusCode?: number,\n public cause?: Error\n ) {\n super(message);\n this.name = 'UploadError';\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\nexport class ValidationError extends Error {\n constructor(message: string, public field?: string) {\n super(message);\n this.name = 'ValidationError';\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\nexport class NetworkError extends Error {\n constructor(message: string, public cause?: Error) {\n super(message);\n this.name = 'NetworkError';\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\nexport class ScanError extends Error {\n constructor(message: string, public path?: string) {\n super(message);\n this.name = 'ScanError';\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\n/**\n * Determine if an error is retryable\n */\nexport function isRetryableError(error: any): boolean {\n // Network errors are retryable\n if (error instanceof NetworkError) {\n return true;\n }\n\n // Worker API 5xx errors are retryable\n if (error instanceof WorkerAPIError) {\n return error.statusCode ? error.statusCode >= 500 : false;\n }\n\n // Upload errors with 5xx or 429 status codes are retryable\n if (error instanceof UploadError) {\n if (error.statusCode) {\n return error.statusCode >= 500 || error.statusCode === 429;\n }\n return false;\n }\n\n // Network-level errors (Node.js)\n if (error.code === 'ECONNRESET' ||\n error.code === 'ETIMEDOUT' ||\n error.code === 'ENOTFOUND' ||\n error.code === 'ECONNREFUSED') {\n return true;\n }\n\n return false;\n}\n","/**\n * Common platform types and utilities\n */\n\nimport type { FileInfo } from '../types/file.js';\nimport type { ProcessingConfig } from '../types/processing.js';\n\n/**\n * Platform-specific file source\n * Can be a path string (Node.js) or File object (Browser)\n */\nexport type FileSource = string | File;\n\n/**\n * Platform-specific scanner interface\n */\nexport interface PlatformScanner {\n /**\n * Scan files from the provided source\n * @param source - File source (path for Node.js, File[] for browser)\n * @param options - Scan options\n */\n scanFiles(\n source: FileSource | FileSource[],\n options: PlatformScanOptions\n ): Promise<FileInfo[]>;\n\n /**\n * Read file contents as ArrayBuffer\n * @param file - FileInfo with platform-specific localPath\n */\n readFile(file: FileInfo): Promise<ArrayBuffer>;\n}\n\n/**\n * Options for platform scanning\n */\nexport interface PlatformScanOptions {\n /**\n * Logical root path for the batch\n */\n rootPath: string;\n\n /**\n * Follow symbolic links (Node.js only)\n */\n followSymlinks?: boolean;\n\n /**\n * Default processing configuration\n */\n defaultProcessingConfig?: ProcessingConfig;\n}\n\n/**\n * Detect current runtime platform\n */\nexport function detectPlatform(): 'node' | 'browser' | 'unknown' {\n // Check for Node.js\n if (\n typeof process !== 'undefined' &&\n process.versions != null &&\n process.versions.node != null\n ) {\n return 'node';\n }\n\n // Check for browser\n if (typeof window !== 'undefined' && typeof document !== 'undefined') {\n return 'browser';\n }\n\n return 'unknown';\n}\n\n/**\n * Normalize path separators to forward slashes\n */\nexport function normalizePath(p: string): string {\n return p.replace(/\\\\/g, '/');\n}\n\n/**\n * Get file extension from filename\n */\nexport function getExtension(filename: string): string {\n const lastDot = filename.lastIndexOf('.');\n return lastDot === -1 ? '' : filename.slice(lastDot + 1).toLowerCase();\n}\n\n/**\n * Get MIME type from filename\n */\nexport function getMimeType(filename: string): string {\n const ext = getExtension(filename);\n\n // Basic MIME type mapping\n const mimeTypes: Record<string, string> = {\n // Images\n 'jpg': 'image/jpeg',\n 'jpeg': 'image/jpeg',\n 'png': 'image/png',\n 'gif': 'image/gif',\n 'webp': 'image/webp',\n 'tif': 'image/tiff',\n 'tiff': 'image/tiff',\n 'bmp': 'image/bmp',\n 'svg': 'image/svg+xml',\n\n // Documents\n 'pdf': 'application/pdf',\n 'txt': 'text/plain',\n 'json': 'application/json',\n 'xml': 'application/xml',\n 'html': 'text/html',\n 'htm': 'text/html',\n 'css': 'text/css',\n 'js': 'application/javascript',\n\n // Archives\n 'zip': 'application/zip',\n 'tar': 'application/x-tar',\n 'gz': 'application/gzip',\n\n // Audio\n 'mp3': 'audio/mpeg',\n 'wav': 'audio/wav',\n 'ogg': 'audio/ogg',\n\n // Video\n 'mp4': 'video/mp4',\n 'webm': 'video/webm',\n 'mov': 'video/quicktime',\n };\n\n return mimeTypes[ext] || 'application/octet-stream';\n}\n","/**\n * Validation utilities for paths, files, and configuration\n */\n\nimport { ValidationError } from '../utils/errors.js';\nimport type { CustomPrompts } from '../types/config.js';\n\n// Size limits per API spec\nconst MAX_FILE_SIZE = 5 * 1024 * 1024 * 1024; // 5 GB\nconst MAX_BATCH_SIZE = 100 * 1024 * 1024 * 1024; // 100 GB\n\n// Invalid path characters\nconst INVALID_PATH_CHARS = /[<>:\"|?*\\x00-\\x1f]/;\n\n// Image MIME types that will be processed by OCR\nconst OCR_PROCESSABLE_TYPES = [\n 'image/jpeg',\n 'image/png',\n 'image/webp',\n];\n\n/**\n * Get file extension (including the dot)\n */\nexport function getFileExtension(fileName: string): string {\n const match = fileName.match(/\\.[^.]+$/);\n return match ? match[0] : '';\n}\n\n/**\n * Validate file size\n */\nexport function validateFileSize(size: number): void {\n if (size <= 0) {\n throw new ValidationError('File size must be greater than 0');\n }\n if (size > MAX_FILE_SIZE) {\n throw new ValidationError(\n `File size (${formatBytes(size)}) exceeds maximum allowed size (${formatBytes(MAX_FILE_SIZE)})`\n );\n }\n}\n\n/**\n * Validate batch size\n */\nexport function validateBatchSize(totalSize: number): void {\n if (totalSize > MAX_BATCH_SIZE) {\n throw new ValidationError(\n `Total batch size (${formatBytes(totalSize)}) exceeds maximum allowed size (${formatBytes(MAX_BATCH_SIZE)})`\n );\n }\n}\n\n/**\n * Validate logical path format\n */\nexport function validateLogicalPath(path: string): void {\n // Must start with /\n if (!path.startsWith('/')) {\n throw new ValidationError('Logical path must start with /', 'path');\n }\n\n // No invalid characters\n if (INVALID_PATH_CHARS.test(path)) {\n throw new ValidationError(\n 'Logical path contains invalid characters',\n 'path'\n );\n }\n\n // Allow \"/\" as root path, otherwise require at least one segment\n const segments = path.split('/').filter((s) => s.length > 0);\n if (segments.length === 0 && path !== '/') {\n throw new ValidationError('Logical path cannot be empty', 'path');\n }\n\n // No . or .. segments (directory traversal)\n for (const segment of segments) {\n if (segment === '.' || segment === '..') {\n throw new ValidationError(\n 'Logical path cannot contain . or .. segments',\n 'path'\n );\n }\n }\n}\n\n/**\n * Validate worker URL\n */\nexport function validateWorkerUrl(url: string): void {\n try {\n const parsed = new URL(url);\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n throw new Error('Protocol must be http or https');\n }\n } catch (error: any) {\n throw new ValidationError(`Invalid worker URL: ${error.message}`, 'workerUrl');\n }\n}\n\n/**\n * Validate uploader name\n */\nexport function validateUploader(uploader: string): void {\n if (!uploader || uploader.trim().length === 0) {\n throw new ValidationError('Uploader name cannot be empty', 'uploader');\n }\n}\n\n/**\n * Validate parent PI format\n * Note: Existence validation happens at worker level\n */\nexport function validateParentPi(pi: string): void {\n // PI must be exactly 26 characters (ULID format)\n if (pi.length !== 26) {\n throw new ValidationError(\n 'parent_pi must be exactly 26 characters',\n 'parent_pi'\n );\n }\n\n // PI must be alphanumeric (case-insensitive)\n if (!/^[0-9A-Z]{26}$/i.test(pi)) {\n throw new ValidationError(\n 'parent_pi must contain only alphanumeric characters (0-9, A-Z)',\n 'parent_pi'\n );\n }\n}\n\n/**\n * Validate metadata JSON\n */\nexport function validateMetadata(metadata: string): Record<string, any> {\n try {\n const parsed = JSON.parse(metadata);\n if (typeof parsed !== 'object' || Array.isArray(parsed)) {\n throw new Error('Metadata must be a JSON object');\n }\n return parsed;\n } catch (error: any) {\n throw new ValidationError(`Invalid metadata JSON: ${error.message}`, 'metadata');\n }\n}\n\n/**\n * Validate .ref.json file content\n *\n * Required fields:\n * - url: Publicly accessible HTTP(S) URL to the referenced resource\n *\n * Optional fields:\n * - type: MIME type (e.g., 'image/jpeg', 'application/pdf')\n * - size: File size in bytes\n * - filename: Original filename for display\n * - ocr: Pre-existing OCR text (if already processed)\n *\n * Note: All other fields are allowed and will be passed through to the worker.\n */\nexport function validateRefJson(content: string, fileName: string, logger?: any): void {\n let parsed: any;\n\n // Parse JSON\n try {\n parsed = JSON.parse(content);\n } catch (error: any) {\n throw new ValidationError(\n `Invalid JSON in ${fileName}: ${error.message}`,\n 'ref'\n );\n }\n\n // Must be an object\n if (typeof parsed !== 'object' || Array.isArray(parsed) || parsed === null) {\n throw new ValidationError(\n `${fileName} must contain a JSON object`,\n 'ref'\n );\n }\n\n // Required field: url\n if (!parsed.url || typeof parsed.url !== 'string') {\n throw new ValidationError(\n `${fileName} must contain a 'url' field with a string value`,\n 'ref'\n );\n }\n\n // Validate URL format\n try {\n const url = new URL(parsed.url);\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n throw new Error('URL must use HTTP or HTTPS protocol');\n }\n } catch (error: any) {\n throw new ValidationError(\n `Invalid URL in ${fileName}: ${error.message}`,\n 'ref'\n );\n }\n\n // Warn if type field is missing\n if (!parsed.type) {\n if (logger) {\n logger.warn(`${fileName}: Missing 'type' field (optional but recommended)`);\n }\n }\n\n // Warn if type is OCR-processable but extension not in filename\n if (parsed.type && OCR_PROCESSABLE_TYPES.includes(parsed.type)) {\n const typeToExt: { [key: string]: string } = {\n 'image/jpeg': '.jpg',\n 'image/png': '.png',\n 'image/webp': '.webp',\n };\n\n const expectedExt = typeToExt[parsed.type];\n if (expectedExt && !fileName.includes(`${expectedExt}.ref.json`)) {\n if (logger) {\n logger.warn(\n `${fileName}: Type is '${parsed.type}' but filename doesn't include '${expectedExt}.ref.json' pattern. ` +\n `This file may not be processed by OCR. Consider renaming to include the extension (e.g., 'photo${expectedExt}.ref.json').`\n );\n }\n }\n }\n}\n\n/**\n * Format bytes to human-readable string\n */\nexport function formatBytes(bytes: number): string {\n if (bytes === 0) return '0 B';\n\n const k = 1024;\n const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;\n}\n\n/**\n * Normalize path to POSIX format (forward slashes)\n */\nexport function normalizePath(path: string): string {\n return path.replace(/\\\\/g, '/');\n}\n\n/**\n * Validate TIFF quality (for future preprocessor configuration)\n */\nexport function validateTiffQuality(quality: number): void {\n if (isNaN(quality) || quality < 1 || quality > 100) {\n throw new ValidationError(\n 'TIFF quality must be a number between 1 and 100',\n 'tiffQuality'\n );\n }\n}\n\n/**\n * Validate custom prompts\n */\nexport function validateCustomPrompts(prompts?: CustomPrompts): void {\n if (!prompts) return;\n\n const MAX_LENGTH = 50000; // 50KB per field - supports metadata file uploads\n const MAX_TOTAL_LENGTH = 75000; // 75KB total - stays under 128KB queue message limit\n const fields: Array<keyof CustomPrompts> = [\n 'general',\n 'reorganization',\n 'pinax',\n 'description',\n 'cheimarros',\n ];\n\n let totalLength = 0;\n\n for (const field of fields) {\n const value = prompts[field];\n if (value) {\n if (value.length > MAX_LENGTH) {\n throw new ValidationError(\n `Custom prompt '${field}' exceeds maximum length of ${MAX_LENGTH} characters (current: ${value.length})`,\n 'customPrompts'\n );\n }\n totalLength += value.length;\n }\n }\n\n if (totalLength > MAX_TOTAL_LENGTH) {\n throw new ValidationError(\n `Total custom prompts length (${totalLength}) exceeds maximum of ${MAX_TOTAL_LENGTH} characters`,\n 'customPrompts'\n );\n }\n}\n\n/**\n * Validate that customPrompts is not incorrectly placed in processing config\n */\nexport function validateCustomPromptsLocation(processingConfig?: any): void {\n if (!processingConfig) return;\n\n // Check if customPrompts was incorrectly placed inside processing config\n if ('customPrompts' in processingConfig) {\n throw new ValidationError(\n 'customPrompts must be a top-level field in UploaderConfig, not inside the processing config. ' +\n 'Use: new ArkeUploader({ customPrompts: {...}, processing: {...} }) ' +\n 'NOT: new ArkeUploader({ processing: { customPrompts: {...} } })',\n 'processing'\n );\n }\n}\n","/**\n * Hash and CID computation utilities\n */\n\nimport { CID } from 'multiformats/cid';\nimport * as raw from 'multiformats/codecs/raw';\nimport { sha256 } from 'multiformats/hashes/sha2';\n\n/**\n * Compute IPFS CID v1 for a file (Node.js only)\n * Uses raw codec and SHA-256 hash\n * Returns base32-encoded CID string\n */\nexport async function computeFileCID(filePath: string): Promise<string> {\n // Dynamic import to avoid bundling fs in browser builds\n const fs = await import('fs/promises');\n\n try {\n // Read file contents\n const fileBuffer = await fs.readFile(filePath);\n\n // Compute SHA-256 hash\n const hash = await sha256.digest(fileBuffer);\n\n // Create CID v1 with raw codec\n const cid = CID.create(1, raw.code, hash);\n\n // Return base32-encoded string (default for v1)\n return cid.toString();\n } catch (error: any) {\n throw new Error(`CID computation failed: ${error.message}`);\n }\n}\n\n/**\n * Compute CID for a buffer (works in all environments)\n */\nexport async function computeBufferCID(buffer: Buffer): Promise<string> {\n const hash = await sha256.digest(buffer);\n const cid = CID.create(1, raw.code, hash);\n return cid.toString();\n}\n\n/**\n * Compute CID from Uint8Array (browser-compatible)\n */\nexport async function computeCIDFromBuffer(data: Uint8Array): Promise<string> {\n const hash = await sha256.digest(data);\n const cid = CID.create(1, raw.code, hash);\n return cid.toString();\n}\n","/**\n * Processing configuration types for per-directory control\n */\n\n/**\n * Configuration for processing stages applied to files\n */\nexport interface ProcessingConfig {\n /** Enable OCR on eligible files */\n ocr: boolean;\n\n /** Enable description/summary generation */\n describe: boolean;\n\n /** Enable pinax metadata generation */\n pinax: boolean;\n}\n\n/**\n * Default processing configuration\n */\nexport const DEFAULT_PROCESSING_CONFIG: ProcessingConfig = {\n ocr: true,\n describe: true,\n pinax: true,\n};\n","/**\n * Node.js platform adapter for file scanning\n */\n\nimport fs from 'fs/promises';\nimport path from 'path';\nimport type { FileInfo } from '../types/file.js';\nimport { ScanError } from '../utils/errors.js';\nimport { validateFileSize, validateLogicalPath, validateRefJson } from '../lib/validation.js';\nimport { computeFileCID } from '../utils/hash.js';\nimport { DEFAULT_PROCESSING_CONFIG, type ProcessingConfig } from '../types/processing.js';\nimport type { PlatformScanner, PlatformScanOptions } from './common.js';\nimport { normalizePath, getMimeType } from './common.js';\n\n/**\n * Node.js file scanner implementation\n */\nexport class NodeScanner implements PlatformScanner {\n /**\n * Scan directory recursively and collect file metadata\n */\n async scanFiles(\n source: string | string[],\n options: PlatformScanOptions\n ): Promise<FileInfo[]> {\n const dirPath = Array.isArray(source) ? source[0] : source;\n\n if (!dirPath || typeof dirPath !== 'string') {\n throw new ScanError('Node.js scanner requires a directory path', '');\n }\n\n const files: FileInfo[] = [];\n\n // Validate directory exists\n try {\n const stats = await fs.stat(dirPath);\n if (!stats.isDirectory()) {\n throw new ScanError(`Path is not a directory: ${dirPath}`, dirPath);\n }\n } catch (error: any) {\n if (error.code === 'ENOENT') {\n throw new ScanError(`Directory not found: ${dirPath}`, dirPath);\n }\n throw new ScanError(`Cannot access directory: ${error.message}`, dirPath);\n }\n\n // Validate logical path\n validateLogicalPath(options.rootPath);\n\n const globalProcessingConfig = options.defaultProcessingConfig || DEFAULT_PROCESSING_CONFIG;\n\n /**\n * Load processing config from directory\n */\n async function loadDirectoryProcessingConfig(\n dirPath: string\n ): Promise<ProcessingConfig | null> {\n const configPath = path.join(dirPath, '.arke-process.json');\n try {\n const content = await fs.readFile(configPath, 'utf-8');\n return JSON.parse(content);\n } catch (error: any) {\n if (error.code !== 'ENOENT') {\n console.warn(`Error reading processing config ${configPath}: ${error.message}`);\n }\n return null;\n }\n }\n\n /**\n * Merge configs\n */\n function mergeProcessingConfig(\n defaults: ProcessingConfig,\n override: Partial<ProcessingConfig> | null\n ): ProcessingConfig {\n if (!override) return defaults;\n return {\n ocr: override.ocr ?? defaults.ocr,\n describe: override.describe ?? defaults.describe,\n pinax: override.pinax ?? defaults.pinax,\n };\n }\n\n /**\n * Recursive walker\n */\n async function walk(currentPath: string, relativePath: string = ''): Promise<void> {\n const dirConfigOverride = await loadDirectoryProcessingConfig(currentPath);\n const currentProcessingConfig = mergeProcessingConfig(\n globalProcessingConfig,\n dirConfigOverride\n );\n\n let entries;\n try {\n entries = await fs.readdir(currentPath, { withFileTypes: true });\n } catch (error: any) {\n console.warn(`Cannot read directory: ${currentPath}`, error.message);\n return;\n }\n\n for (const entry of entries) {\n const fullPath = path.join(currentPath, entry.name);\n const relPath = path.join(relativePath, entry.name);\n\n try {\n // Handle symlinks\n if (entry.isSymbolicLink()) {\n if (!options.followSymlinks) {\n continue;\n }\n\n const stats = await fs.stat(fullPath);\n if (stats.isDirectory()) {\n await walk(fullPath, relPath);\n } else if (stats.isFile()) {\n await processFile(fullPath, relPath, stats.size, currentProcessingConfig);\n }\n continue;\n }\n\n // Handle directories\n if (entry.isDirectory()) {\n await walk(fullPath, relPath);\n continue;\n }\n\n // Handle regular files\n if (entry.isFile()) {\n const stats = await fs.stat(fullPath);\n await processFile(fullPath, relPath, stats.size, currentProcessingConfig);\n }\n } catch (error: any) {\n if (error instanceof ScanError && error.message.includes('.ref.json')) {\n throw error;\n }\n console.warn(`Error processing ${fullPath}: ${error.message}`);\n continue;\n }\n }\n }\n\n /**\n * Process single file\n */\n async function processFile(\n fullPath: string,\n relativePath: string,\n size: number,\n processingConfig: ProcessingConfig\n ): Promise<void> {\n const fileName = path.basename(fullPath);\n\n // Skip processing config files\n if (fileName === '.arke-process.json') {\n return;\n }\n\n // Validate .ref.json files\n if (fileName.endsWith('.ref.json')) {\n try {\n const content = await fs.readFile(fullPath, 'utf-8');\n validateRefJson(content, fileName, console);\n } catch (error: any) {\n throw new ScanError(\n `Invalid .ref.json file: ${fileName} - ${error.message}`,\n fullPath\n );\n }\n }\n\n // Validate file size\n try {\n validateFileSize(size);\n } catch (error: any) {\n console.warn(`Skipping file that exceeds size limit: ${fileName}`, error.message);\n return;\n }\n\n // Construct logical path\n const normalizedRelPath = normalizePath(relativePath);\n const logicalPath = path.posix.join(options.rootPath, normalizedRelPath);\n\n // Validate logical path\n try {\n validateLogicalPath(logicalPath);\n } catch (error: any) {\n console.warn(`Skipping file with invalid logical path: ${logicalPath}`, error.message);\n return;\n }\n\n // Determine content type\n const contentType = getMimeType(fileName);\n\n // Check if file is readable\n try {\n await fs.access(fullPath, fs.constants.R_OK);\n } catch (error) {\n console.warn(`Skipping unreadable file: ${fullPath}`);\n return;\n }\n\n // Compute CID (optional - continue without if computation fails)\n let cid: string | undefined;\n try {\n cid = await computeFileCID(fullPath);\n } catch (error: any) {\n console.warn(`Warning: CID computation failed for ${fullPath}, continuing without CID:`, error.message);\n cid = undefined;\n }\n\n // Add to results\n files.push({\n localPath: fullPath,\n logicalPath,\n fileName,\n size,\n contentType,\n cid,\n processingConfig,\n });\n }\n\n // Start scan\n await walk(dirPath);\n\n // Sort by size (smallest first)\n files.sort((a, b) => a.size - b.size);\n\n return files;\n }\n\n /**\n * Read file contents as ArrayBuffer\n */\n async readFile(file: FileInfo): Promise<ArrayBuffer> {\n const buffer = await fs.readFile(file.localPath);\n return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);\n }\n}\n","/**\n * Browser platform adapter for file handling\n */\n\nimport type { FileInfo } from '../types/file.js';\nimport { ScanError } from '../utils/errors.js';\nimport { validateFileSize, validateLogicalPath } from '../lib/validation.js';\nimport { computeCIDFromBuffer } from '../utils/hash.js';\nimport { DEFAULT_PROCESSING_CONFIG } from '../types/processing.js';\nimport type { PlatformScanner, PlatformScanOptions } from './common.js';\nimport { normalizePath, getMimeType } from './common.js';\n\n/**\n * Browser file scanner implementation\n */\nexport class BrowserScanner implements PlatformScanner {\n /**\n * Scan files from File or FileList\n */\n async scanFiles(\n source: File | File[],\n options: PlatformScanOptions\n ): Promise<FileInfo[]> {\n const fileList = Array.isArray(source) ? source : [source];\n\n if (fileList.length === 0) {\n throw new ScanError('No files provided', '');\n }\n\n // Validate logical path\n validateLogicalPath(options.rootPath);\n\n const globalProcessingConfig = options.defaultProcessingConfig || DEFAULT_PROCESSING_CONFIG;\n const files: FileInfo[] = [];\n\n for (const file of fileList) {\n try {\n const fileInfo = await this.processFile(file, options.rootPath, globalProcessingConfig);\n if (fileInfo) {\n files.push(fileInfo);\n }\n } catch (error: any) {\n console.warn(`Error processing ${file.name}: ${error.message}`);\n continue;\n }\n }\n\n // Sort by size (smallest first)\n files.sort((a, b) => a.size - b.size);\n\n return files;\n }\n\n /**\n * Process a single File object\n */\n private async processFile(\n file: File,\n rootPath: string,\n processingConfig: any\n ): Promise<FileInfo | null> {\n const fileName = file.name;\n const size = file.size;\n\n // Skip hidden files (starting with .) - includes .DS_Store, .gitignore, etc.\n // These often have permission issues or are constantly modified by the OS\n if (fileName.startsWith('.')) {\n return null;\n }\n\n // Skip common system/temp files that shouldn't be uploaded\n const skipFiles = ['Thumbs.db', 'desktop.ini', '__MACOSX'];\n if (skipFiles.includes(fileName)) {\n return null;\n }\n\n // Skip processing config files\n if (fileName === '.arke-process.json') {\n return null;\n }\n\n // Validate file size\n try {\n validateFileSize(size);\n } catch (error: any) {\n console.warn(`Skipping file that exceeds size limit: ${fileName}`, error.message);\n return null;\n }\n\n // Extract relative path from file.webkitRelativePath or use just the filename\n let relativePath = '';\n if ('webkitRelativePath' in file && file.webkitRelativePath) {\n // For directory uploads, extract relative path\n const parts = file.webkitRelativePath.split('/');\n // Remove the first part (directory name) and join the rest\n if (parts.length > 1) {\n relativePath = parts.slice(1).join('/');\n } else {\n relativePath = fileName;\n }\n } else {\n relativePath = fileName;\n }\n\n // Construct logical path\n const normalizedRelPath = normalizePath(relativePath);\n const logicalPath = `${rootPath}/${normalizedRelPath}`.replace(/\\/+/g, '/');\n\n // Validate logical path\n try {\n validateLogicalPath(logicalPath);\n } catch (error: any) {\n console.warn(`Skipping file with invalid logical path: ${logicalPath}`, error.message);\n return null;\n }\n\n // Determine content type\n const contentType = file.type || getMimeType(fileName);\n\n // Compute CID (optional - continue without if computation fails)\n let cid: string | undefined;\n try {\n const buffer = await file.arrayBuffer();\n cid = await computeCIDFromBuffer(new Uint8Array(buffer));\n } catch (error: any) {\n console.warn(`Warning: CID computation failed for ${fileName}, continuing without CID:`, error.message);\n cid = undefined;\n }\n\n // For browser files, we store the File object itself as a special marker\n // The actual File object will be passed separately during upload\n return {\n localPath: `__browser_file__${fileName}`, // Special marker for browser files\n logicalPath,\n fileName,\n size,\n contentType,\n cid,\n processingConfig,\n };\n }\n\n /**\n * Read file contents as ArrayBuffer\n * Note: In browser context, the File object should be passed directly\n */\n async readFile(file: FileInfo): Promise<ArrayBuffer> {\n throw new Error('Browser scanner requires File objects to be provided directly during upload');\n }\n}\n","/**\n * @arke-institute/sdk - TypeScript SDK for building applications on the Arke platform\n *\n * @example\n * ```typescript\n * import {\n * CollectionsClient,\n * UploadClient,\n * QueryClient,\n * EditClient,\n * ContentClient,\n * GraphClient\n * } from '@arke-institute/sdk';\n *\n * // Collections management\n * const collections = new CollectionsClient({\n * gatewayUrl: 'https://gateway.arke.institute',\n * authToken: 'your-jwt-token',\n * });\n *\n * // Upload with collections integration\n * const upload = new UploadClient({\n * gatewayUrl: 'https://gateway.arke.institute',\n * authToken: 'your-jwt-token',\n * uploader: 'my-app',\n * });\n *\n * // Query the knowledge graph (no auth required)\n * const query = new QueryClient({\n * gatewayUrl: 'https://gateway.arke.institute',\n * });\n *\n * // Content access (no auth required)\n * const content = new ContentClient({\n * gatewayUrl: 'https://gateway.arke.institute',\n * });\n *\n * // Graph relationships (no auth required)\n * const graph = new GraphClient({\n * gatewayUrl: 'https://gateway.arke.institute',\n * });\n *\n * // Get an entity and its content\n * const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');\n * const imageBlob = await content.download(entity.components.source);\n *\n * // Get entities with relationships from the knowledge graph\n * const entities = await graph.getEntitiesWithRelationships(entity.pi);\n *\n * // Execute a path query\n * const results = await query.path('\"alice austen\" -[*]{,4}-> type:person');\n * ```\n */\n\n// Collections\nexport {\n CollectionsClient,\n type CollectionsClientConfig,\n} from './collections/client';\nexport { CollectionsError } from './collections/errors';\nexport type {\n Collection,\n CollectionDetails,\n CollectionRole,\n CollectionVisibility,\n CreateCollectionPayload,\n UpdateCollectionPayload,\n RegisterRootPayload,\n ChangeRootPayload,\n ChangeRootResponse,\n Member,\n MemberUser,\n MembersResponse,\n Invitation,\n InvitationUser,\n InvitationsResponse,\n MyAccessResponse,\n MyCollectionsResponse,\n PaginatedCollections,\n PiPermissions,\n RootResponse,\n SuccessResponse,\n} from './collections/types';\n\n// Upload\nexport {\n UploadClient,\n type UploadClientConfig,\n type CreateCollectionUploadOptions,\n type AddToCollectionOptions,\n type CreateCollectionUploadResult,\n} from './upload/client';\nexport { ArkeUploader } from './upload/uploader';\nexport type {\n UploaderConfig,\n UploadOptions,\n UploadProgress,\n BatchResult,\n CustomPrompts,\n ProcessingConfig,\n FileInfo,\n} from './upload/types/index';\nexport {\n ValidationError,\n ScanError,\n WorkerAPIError,\n NetworkError,\n UploadError,\n} from './upload/utils/errors';\n\n// Query\nexport { QueryClient, type QueryClientConfig } from './query/client';\nexport { QueryError } from './query/errors';\nexport type {\n // Request types\n LineageFilter,\n PathQueryOptions,\n NaturalQueryOptions,\n // Response types\n EnrichedContent,\n Entity,\n PathStep,\n QueryResultItem,\n LineageMetadata,\n QueryMetadata,\n QueryResult,\n TranslationInfo,\n NaturalQueryResult,\n TranslateResult,\n // Parse types\n ASTNodeType,\n EntryAST,\n FilterAST,\n HopAST,\n PathAST,\n ParseResult,\n ParseError,\n // Syntax documentation types\n EntryPointDoc,\n EdgeTypeDoc,\n VariableDepthDoc,\n FilterTypeDoc,\n ParameterDoc,\n ExampleDoc,\n SyntaxDocumentation,\n} from './query/types';\n\n// Edit\nexport { EditClient, type EditClientConfig } from './edit/client';\nexport { EditSession } from './edit/session';\nexport { EditError, PermissionError } from './edit/errors';\nexport type {\n EditMode,\n EditSessionConfig,\n EditScope,\n RegeneratableComponent,\n EditResult,\n EditStatus,\n EditPhase,\n ReprocessResult,\n ReprocessStatus,\n} from './edit/types';\n\n// Content\nexport { ContentClient, type ContentClientConfig } from './content/client';\nexport {\n ContentError,\n EntityNotFoundError,\n ContentNotFoundError,\n ComponentNotFoundError,\n VersionNotFoundError,\n NetworkError as ContentNetworkError,\n} from './content/errors';\nexport type {\n Entity as ContentEntity,\n EntitySummary,\n EntityVersion,\n ListOptions,\n ListResponse,\n VersionsOptions,\n VersionsResponse,\n ResolveResponse,\n} from './content/types';\n\n// Graph\nexport { GraphClient, type GraphClientConfig } from './graph/client';\nexport {\n GraphError,\n GraphEntityNotFoundError,\n NoPathFoundError,\n NetworkError as GraphNetworkError,\n} from './graph/errors';\nexport type {\n GraphEntity,\n Relationship,\n EntityWithRelationships,\n PathEdge,\n Path,\n PathOptions,\n ReachableOptions,\n ListFromPiOptions,\n EntityQueryResponse,\n EntitiesWithRelationshipsResponse,\n PathsResponse,\n LineagePiEntry,\n LineageResultSet,\n LineageResponse,\n} from './graph/types';\n","export class CollectionsError extends Error {\n constructor(\n message: string,\n public code: string = 'UNKNOWN_ERROR',\n public details?: unknown\n ) {\n super(message);\n this.name = 'CollectionsError';\n }\n}\n","import { CollectionsError } from './errors';\nimport type {\n ChangeRootPayload,\n ChangeRootResponse,\n Collection,\n CollectionDetails,\n CollectionRole,\n CreateCollectionPayload,\n Invitation,\n InvitationsResponse,\n Member,\n MembersResponse,\n MyAccessResponse,\n MyCollectionsResponse,\n PaginatedCollections,\n PiPermissions,\n RegisterRootPayload,\n RootResponse,\n SuccessResponse,\n UpdateCollectionPayload,\n} from './types';\n\nexport interface CollectionsClientConfig {\n /**\n * Gateway base URL (e.g., https://api.arke.institute).\n * Must already point at the Arke gateway that proxies /collections/*.\n */\n gatewayUrl: string;\n /**\n * Optional bearer token for authenticated routes.\n * Public routes will still include it if provided.\n */\n authToken?: string;\n /**\n * Optional custom fetch (useful for testing).\n */\n fetchImpl?: typeof fetch;\n}\n\ntype JsonBody = Record<string, unknown>;\n\nexport class CollectionsClient {\n private baseUrl: string;\n private authToken?: string;\n private fetchImpl: typeof fetch;\n\n constructor(config: CollectionsClientConfig) {\n this.baseUrl = config.gatewayUrl.replace(/\\/$/, '');\n this.authToken = config.authToken;\n this.fetchImpl = config.fetchImpl ?? fetch;\n }\n\n setAuthToken(token?: string) {\n this.authToken = token;\n }\n\n // ---------------------------------------------------------------------------\n // Request helpers\n // ---------------------------------------------------------------------------\n\n private buildUrl(path: string, query?: Record<string, string | number | undefined>) {\n const url = new URL(`${this.baseUrl}${path}`);\n if (query) {\n Object.entries(query).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n });\n }\n return url.toString();\n }\n\n private getHeaders(authRequired: boolean): HeadersInit {\n const headers: HeadersInit = { 'Content-Type': 'application/json' };\n if (authRequired || this.authToken) {\n if (!this.authToken && authRequired) {\n throw new CollectionsError('Authentication required for this operation', 'AUTH_REQUIRED');\n }\n if (this.authToken) {\n headers['Authorization'] = `Bearer ${this.authToken}`;\n }\n }\n return headers;\n }\n\n private async request<T>(\n path: string,\n options: RequestInit & {\n authRequired?: boolean;\n query?: Record<string, string | number | undefined>;\n } = {}\n ): Promise<T> {\n const authRequired = options.authRequired ?? false;\n const url = this.buildUrl(path, options.query);\n const headers = new Headers(this.getHeaders(authRequired));\n if (options.headers) {\n Object.entries(options.headers).forEach(([k, v]) => {\n if (v !== undefined) headers.set(k, v as string);\n });\n }\n\n const response = await this.fetchImpl(url, { ...options, headers });\n\n if (response.ok) {\n if (response.status === 204) {\n return undefined as T;\n }\n const contentType = response.headers.get('content-type') || '';\n if (contentType.includes('application/json')) {\n return (await response.json()) as T;\n }\n return (await response.text()) as unknown as T;\n }\n\n let body: unknown;\n const text = await response.text();\n try {\n body = JSON.parse(text);\n } catch {\n body = text;\n }\n\n const message =\n (body as JsonBody)?.error && typeof (body as JsonBody).error === 'string'\n ? ((body as JsonBody).error as string)\n : `Request failed with status ${response.status}`;\n\n throw new CollectionsError(message, 'HTTP_ERROR', {\n status: response.status,\n body,\n });\n }\n\n // ---------------------------------------------------------------------------\n // Collections\n // ---------------------------------------------------------------------------\n\n async listCollections(params?: { limit?: number; offset?: number }): Promise<PaginatedCollections> {\n return this.request('/collections', {\n method: 'GET',\n query: { limit: params?.limit, offset: params?.offset },\n });\n }\n\n async getCollection(id: string): Promise<CollectionDetails> {\n return this.request(`/collections/${id}`, { method: 'GET' });\n }\n\n async getCollectionRoot(id: string): Promise<RootResponse> {\n return this.request(`/collections/${id}/root`, { method: 'GET' });\n }\n\n async getMyAccess(id: string): Promise<MyAccessResponse> {\n return this.request(`/collections/${id}/my-access`, { method: 'GET', authRequired: true });\n }\n\n async createCollection(payload: CreateCollectionPayload): Promise<Collection> {\n return this.request('/collections', {\n method: 'POST',\n authRequired: true,\n body: JSON.stringify(payload),\n });\n }\n\n async registerRoot(payload: RegisterRootPayload): Promise<Collection & { rootPi: string }> {\n return this.request('/collections/register-root', {\n method: 'POST',\n authRequired: true,\n body: JSON.stringify(payload),\n });\n }\n\n async updateCollection(id: string, payload: UpdateCollectionPayload): Promise<Collection> {\n return this.request(`/collections/${id}`, {\n method: 'PATCH',\n authRequired: true,\n body: JSON.stringify(payload),\n });\n }\n\n async changeRoot(id: string, payload: ChangeRootPayload): Promise<ChangeRootResponse> {\n return this.request(`/collections/${id}/change-root`, {\n method: 'PATCH',\n authRequired: true,\n body: JSON.stringify(payload),\n });\n }\n\n async deleteCollection(id: string): Promise<SuccessResponse> {\n return this.request(`/collections/${id}`, {\n method: 'DELETE',\n authRequired: true,\n });\n }\n\n // ---------------------------------------------------------------------------\n // Members\n // ---------------------------------------------------------------------------\n\n async listMembers(collectionId: string): Promise<MembersResponse> {\n return this.request(`/collections/${collectionId}/members`, { method: 'GET' });\n }\n\n async updateMemberRole(\n collectionId: string,\n userId: string,\n role: CollectionRole\n ): Promise<{ success: true; role: CollectionRole }> {\n return this.request(`/collections/${collectionId}/members/${userId}`, {\n method: 'PATCH',\n authRequired: true,\n body: JSON.stringify({ role }),\n });\n }\n\n async removeMember(collectionId: string, userId: string): Promise<SuccessResponse> {\n return this.request(`/collections/${collectionId}/members/${userId}`, {\n method: 'DELETE',\n authRequired: true,\n });\n }\n\n // ---------------------------------------------------------------------------\n // Invitations\n // ---------------------------------------------------------------------------\n\n async createInvitation(collectionId: string, email: string, role: CollectionRole): Promise<Invitation> {\n return this.request(`/collections/${collectionId}/invitations`, {\n method: 'POST',\n authRequired: true,\n body: JSON.stringify({ email, role }),\n });\n }\n\n async listInvitations(collectionId: string): Promise<InvitationsResponse> {\n return this.request(`/collections/${collectionId}/invitations`, {\n method: 'GET',\n authRequired: true,\n });\n }\n\n async acceptInvitation(invitationId: string): Promise<{ success: true; role: CollectionRole }> {\n return this.request(`/invitations/${invitationId}/accept`, {\n method: 'POST',\n authRequired: true,\n });\n }\n\n async declineInvitation(invitationId: string): Promise<SuccessResponse> {\n return this.request(`/invitations/${invitationId}/decline`, {\n method: 'POST',\n authRequired: true,\n });\n }\n\n async revokeInvitation(invitationId: string): Promise<SuccessResponse> {\n return this.request(`/invitations/${invitationId}`, {\n method: 'DELETE',\n authRequired: true,\n });\n }\n\n // ---------------------------------------------------------------------------\n // Current user\n // ---------------------------------------------------------------------------\n\n async getMyCollections(): Promise<MyCollectionsResponse> {\n return this.request('/me/collections', { method: 'GET', authRequired: true });\n }\n\n async getMyInvitations(): Promise<InvitationsResponse> {\n return this.request('/me/invitations', { method: 'GET', authRequired: true });\n }\n\n // ---------------------------------------------------------------------------\n // PI permissions\n // ---------------------------------------------------------------------------\n\n async getPiPermissions(pi: string): Promise<PiPermissions> {\n return this.request(`/pi/${pi}/permissions`, { method: 'GET' });\n }\n}\n","/**\n * API client for communicating with the Arke Ingest Worker (fetch-based)\n */\n\nimport type {\n InitBatchRequest,\n InitBatchResponse,\n StartFileUploadRequest,\n StartFileUploadResponse,\n CompleteFileUploadRequest,\n CompleteFileUploadResponse,\n FinalizeBatchResponse,\n BatchStatusResponse,\n ErrorResponse,\n} from '../types/api.js';\nimport { WorkerAPIError, NetworkError } from '../utils/errors.js';\nimport { retryWithBackoff } from '../utils/retry.js';\n\nexport interface WorkerClientConfig {\n baseUrl: string;\n authToken?: string;\n timeout?: number;\n maxRetries?: number;\n retryInitialDelay?: number;\n retryMaxDelay?: number;\n retryJitter?: boolean;\n debug?: boolean;\n}\n\nexport class WorkerClient {\n private baseUrl: string;\n private authToken?: string;\n private timeout: number;\n private maxRetries: number;\n private retryInitialDelay: number;\n private retryMaxDelay: number;\n private retryJitter: boolean;\n private debug: boolean;\n\n constructor(config: WorkerClientConfig) {\n this.baseUrl = config.baseUrl.replace(/\\/$/, '');\n this.authToken = config.authToken;\n this.timeout = config.timeout ?? 30000; // 30 seconds\n this.maxRetries = config.maxRetries ?? 3;\n this.retryInitialDelay = config.retryInitialDelay ?? 1000; // 1 second\n this.retryMaxDelay = config.retryMaxDelay ?? 30000; // 30 seconds\n this.retryJitter = config.retryJitter ?? true;\n this.debug = config.debug ?? false;\n }\n\n setAuthToken(token?: string) {\n this.authToken = token;\n }\n\n /**\n * Make HTTP request with fetch\n */\n private async request<T>(\n method: string,\n path: string,\n body?: unknown\n ): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n\n if (this.debug) {\n console.log(`HTTP Request: ${method} ${url}`, body);\n }\n\n try {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n if (this.authToken) {\n headers['Authorization'] = `Bearer ${this.authToken}`;\n }\n\n const response = await fetch(url, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n const data = await response.json();\n\n if (this.debug) {\n console.log(`HTTP Response: ${response.status}`, data);\n }\n\n if (!response.ok) {\n const errorData = data as ErrorResponse;\n throw new WorkerAPIError(\n errorData.error || 'Request failed',\n response.status,\n errorData.details\n );\n }\n\n return data as T;\n } catch (error: any) {\n if (error instanceof WorkerAPIError) {\n throw error;\n }\n\n if (error.name === 'AbortError') {\n throw new NetworkError(`Request timeout after ${this.timeout}ms`);\n }\n\n throw new NetworkError(`Network request failed: ${error.message}`);\n }\n }\n\n /**\n * Initialize a new batch upload\n */\n async initBatch(params: InitBatchRequest): Promise<InitBatchResponse> {\n return retryWithBackoff(\n () => this.request<InitBatchResponse>('POST', '/ingest/batches/init', params),\n {\n maxRetries: this.maxRetries,\n initialDelay: this.retryInitialDelay,\n maxDelay: this.retryMaxDelay,\n jitter: this.retryJitter,\n }\n );\n }\n\n /**\n * Request presigned URLs for a file upload\n */\n async startFileUpload(\n batchId: string,\n params: StartFileUploadRequest\n ): Promise<StartFileUploadResponse> {\n return retryWithBackoff(\n () =>\n this.request<StartFileUploadResponse>(\n 'POST',\n `/ingest/batches/${batchId}/files/start`,\n params\n ),\n {\n maxRetries: this.maxRetries,\n initialDelay: this.retryInitialDelay,\n maxDelay: this.retryMaxDelay,\n jitter: this.retryJitter,\n }\n );\n }\n\n /**\n * Mark a file upload as complete\n */\n async completeFileUpload(\n batchId: string,\n params: CompleteFileUploadRequest\n ): Promise<CompleteFileUploadResponse> {\n return retryWithBackoff(\n () =>\n this.request<CompleteFileUploadResponse>(\n 'POST',\n `/ingest/batches/${batchId}/files/complete`,\n params\n ),\n {\n maxRetries: this.maxRetries,\n initialDelay: this.retryInitialDelay,\n maxDelay: this.retryMaxDelay,\n jitter: this.retryJitter,\n }\n );\n }\n\n /**\n * Finalize the batch after all files are uploaded\n * Returns root_pi immediately for small batches, or status='discovery' for large batches\n */\n async finalizeBatch(batchId: string): Promise<FinalizeBatchResponse> {\n return retryWithBackoff(\n () =>\n this.request<FinalizeBatchResponse>(\n 'POST',\n `/ingest/batches/${batchId}/finalize`,\n {}\n ),\n {\n maxRetries: this.maxRetries,\n initialDelay: this.retryInitialDelay,\n maxDelay: this.retryMaxDelay,\n jitter: this.retryJitter,\n }\n );\n }\n\n /**\n * Get current batch status (used for polling during async discovery)\n */\n async getBatchStatus(batchId: string): Promise<BatchStatusResponse> {\n return retryWithBackoff(\n () =>\n this.request<BatchStatusResponse>(\n 'GET',\n `/ingest/batches/${batchId}/status`\n ),\n {\n maxRetries: this.maxRetries,\n initialDelay: this.retryInitialDelay,\n maxDelay: this.retryMaxDelay,\n jitter: this.retryJitter,\n }\n );\n }\n}\n","/**\n * Retry logic with exponential backoff\n */\n\nimport { isRetryableError } from './errors.js';\n\nexport interface RetryOptions {\n maxRetries: number;\n initialDelay: number;\n maxDelay: number;\n shouldRetry?: (error: any) => boolean;\n jitter?: boolean; // Add randomization to prevent thundering herd\n}\n\nconst DEFAULT_OPTIONS: RetryOptions = {\n maxRetries: 3,\n initialDelay: 1000, // 1 second\n maxDelay: 30000, // 30 seconds\n shouldRetry: isRetryableError,\n jitter: true,\n};\n\n/**\n * Retry a function with exponential backoff\n */\nexport async function retryWithBackoff<T>(\n fn: () => Promise<T>,\n options: Partial<RetryOptions> = {}\n): Promise<T> {\n const opts = { ...DEFAULT_OPTIONS, ...options };\n\n let lastError: any;\n\n for (let attempt = 0; attempt <= opts.maxRetries; attempt++) {\n try {\n return await fn();\n } catch (error: any) {\n lastError = error;\n\n // Don't retry if we've exhausted attempts\n if (attempt >= opts.maxRetries) {\n throw error;\n }\n\n // Check if error is retryable\n if (opts.shouldRetry && !opts.shouldRetry(error)) {\n throw error;\n }\n\n // Handle 429 Rate Limit with Retry-After header\n let delay: number;\n if (error.statusCode === 429 && error.retryAfter) {\n // Use Retry-After header if present (in seconds)\n delay = Math.min(error.retryAfter * 1000, opts.maxDelay);\n } else {\n // Calculate delay with exponential backoff\n delay = Math.min(\n opts.initialDelay * Math.pow(2, attempt),\n opts.maxDelay\n );\n }\n\n // Add jitter to prevent thundering herd (±25% randomization)\n if (opts.jitter) {\n const jitterAmount = delay * 0.25;\n delay = delay + (Math.random() * jitterAmount * 2 - jitterAmount);\n }\n\n await sleep(Math.floor(delay));\n }\n }\n\n throw lastError;\n}\n\n/**\n * Sleep for a given number of milliseconds\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","/**\n * Main ArkeUploader SDK class\n */\n\nimport type {\n UploaderConfig,\n UploadOptions,\n UploadProgress,\n BatchResult,\n} from './types/config.js';\nimport type { FileInfo } from './types/file.js';\nimport { WorkerClient } from './lib/worker-client-fetch.js';\nimport { detectPlatform, type PlatformScanner, type FileSource } from './platforms/common.js';\nimport { uploadSimple } from './lib/simple-fetch.js';\nimport { uploadMultipart } from './lib/multipart-fetch.js';\nimport { ValidationError } from './utils/errors.js';\nimport { validateBatchSize, validateCustomPrompts, validateCustomPromptsLocation } from './lib/validation.js';\n\nconst MULTIPART_THRESHOLD = 5 * 1024 * 1024; // 5 MB\n\n/**\n * Upload client for Arke Institute's ingest service\n * Works in Node.js, browsers, and other JavaScript runtimes\n */\nexport class ArkeUploader {\n private config: UploaderConfig;\n private workerClient: WorkerClient;\n private scanner: PlatformScanner | null = null;\n private platform: 'node' | 'browser' | 'unknown';\n\n constructor(config: UploaderConfig) {\n // Validate that customPrompts is not incorrectly placed in processing config\n validateCustomPromptsLocation(config.processing);\n\n this.config = {\n rootPath: '/uploads', // Must have at least one segment (not just '/')\n parallelUploads: 5,\n parallelParts: 3,\n ...config,\n };\n\n this.workerClient = new WorkerClient({\n baseUrl: config.gatewayUrl,\n authToken: config.authToken,\n timeout: config.timeout,\n maxRetries: config.maxRetries,\n retryInitialDelay: config.retryInitialDelay,\n retryMaxDelay: config.retryMaxDelay,\n retryJitter: config.retryJitter,\n debug: false,\n });\n\n this.platform = detectPlatform();\n }\n\n /**\n * Get platform-specific scanner\n */\n private async getScanner(): Promise<PlatformScanner> {\n if (this.scanner) {\n return this.scanner;\n }\n\n if (this.platform === 'node') {\n const { NodeScanner } = await import('./platforms/node.js');\n this.scanner = new NodeScanner();\n } else if (this.platform === 'browser') {\n const { BrowserScanner } = await import('./platforms/browser.js');\n this.scanner = new BrowserScanner();\n } else {\n throw new ValidationError('Unsupported platform');\n }\n\n return this.scanner;\n }\n\n /**\n * Upload a batch of files\n * @param source - Directory path (Node.js) or File[]/FileList (browser)\n * @param options - Upload options\n */\n async uploadBatch(\n source: FileSource | FileSource[],\n options: UploadOptions = {}\n ): Promise<BatchResult> {\n const startTime = Date.now();\n const { onProgress, dryRun = false } = options;\n\n // Phase 1: Scanning\n this.reportProgress(onProgress, {\n phase: 'scanning',\n filesTotal: 0,\n filesUploaded: 0,\n bytesTotal: 0,\n bytesUploaded: 0,\n percentComplete: 0,\n });\n\n const scanner = await this.getScanner();\n const files = await scanner.scanFiles(source, {\n rootPath: this.config.rootPath || '/',\n followSymlinks: true,\n defaultProcessingConfig: this.config.processing,\n });\n\n if (files.length === 0) {\n throw new ValidationError('No files found to upload');\n }\n\n const totalSize = files.reduce((sum, f) => sum + f.size, 0);\n validateBatchSize(totalSize);\n\n // Validate custom prompts if provided\n if (this.config.customPrompts) {\n validateCustomPrompts(this.config.customPrompts);\n\n // Log which custom prompts are being used\n const promptFields = Object.keys(this.config.customPrompts).filter(\n key => this.config.customPrompts![key as keyof typeof this.config.customPrompts]\n );\n console.log(`[Arke Upload SDK] Custom prompts configured: ${promptFields.join(', ')}`);\n }\n\n if (dryRun) {\n return {\n batchId: 'dry-run',\n rootPi: 'dry-run',\n filesUploaded: files.length,\n bytesUploaded: totalSize,\n durationMs: Date.now() - startTime,\n };\n }\n\n // Phase 2: Initialize batch\n const { batch_id } = await this.workerClient.initBatch({\n uploader: this.config.uploader,\n root_path: this.config.rootPath || '/',\n parent_pi: this.config.parentPi || '',\n metadata: this.config.metadata,\n file_count: files.length,\n total_size: totalSize,\n custom_prompts: this.config.customPrompts,\n });\n\n // Confirm custom prompts were sent\n if (this.config.customPrompts) {\n console.log(`[Arke Upload SDK] Custom prompts sent to worker for batch ${batch_id}`);\n }\n\n // Phase 3: Upload files\n this.reportProgress(onProgress, {\n phase: 'uploading',\n filesTotal: files.length,\n filesUploaded: 0,\n bytesTotal: totalSize,\n bytesUploaded: 0,\n percentComplete: 0,\n });\n\n let filesUploaded = 0;\n let bytesUploaded = 0;\n\n // Upload files with concurrency control\n const { failedFiles } = await this.uploadFilesWithConcurrency(\n batch_id,\n files,\n source,\n this.config.parallelUploads || 5,\n (file, bytes) => {\n filesUploaded++;\n bytesUploaded += bytes;\n\n this.reportProgress(onProgress, {\n phase: 'uploading',\n filesTotal: files.length,\n filesUploaded,\n bytesTotal: totalSize,\n bytesUploaded,\n currentFile: file.fileName,\n percentComplete: Math.round((bytesUploaded / totalSize) * 100),\n });\n }\n );\n\n // Check if all files failed\n if (failedFiles.length === files.length) {\n throw new ValidationError(\n `All ${files.length} files failed to upload. First error: ${failedFiles[0]?.error || 'Unknown'}`\n );\n }\n\n // Log warning if some files failed but continue with finalization\n if (failedFiles.length > 0) {\n console.warn(\n `Warning: ${failedFiles.length} of ${files.length} files failed to upload:`,\n failedFiles.map(f => `${f.file.fileName}: ${f.error}`).join(', ')\n );\n }\n\n // Phase 4: Finalize and get root_pi\n this.reportProgress(onProgress, {\n phase: 'finalizing',\n filesTotal: files.length,\n filesUploaded,\n bytesTotal: totalSize,\n bytesUploaded,\n percentComplete: 95,\n });\n\n const finalizeResult = await this.workerClient.finalizeBatch(batch_id);\n\n // Get root_pi - either immediately (sync discovery) or via polling (async discovery)\n let rootPi: string;\n\n if (finalizeResult.root_pi) {\n // Sync path - root_pi available immediately\n rootPi = finalizeResult.root_pi;\n } else if (finalizeResult.status === 'discovery') {\n // Async path - poll until discovery completes\n this.reportProgress(onProgress, {\n phase: 'discovery',\n filesTotal: files.length,\n filesUploaded,\n bytesTotal: totalSize,\n bytesUploaded,\n percentComplete: 97,\n });\n\n rootPi = await this.pollForRootPi(batch_id, onProgress, files.length, totalSize, bytesUploaded);\n } else {\n // Unexpected state - this shouldn't happen but handle gracefully\n throw new ValidationError(\n `Finalization returned unexpected status: ${finalizeResult.status} without root_pi`\n );\n }\n\n // Complete\n this.reportProgress(onProgress, {\n phase: 'complete',\n filesTotal: files.length,\n filesUploaded,\n bytesTotal: totalSize,\n bytesUploaded,\n percentComplete: 100,\n });\n\n return {\n batchId: batch_id,\n rootPi,\n filesUploaded,\n bytesUploaded,\n durationMs: Date.now() - startTime,\n };\n }\n\n /**\n * Poll for root_pi during async discovery\n */\n private async pollForRootPi(\n batchId: string,\n onProgress: ((progress: UploadProgress) => void) | undefined,\n filesTotal: number,\n bytesTotal: number,\n bytesUploaded: number\n ): Promise<string> {\n const POLL_INTERVAL_MS = 2000;\n const MAX_POLL_TIME_MS = 30 * 60 * 1000; // 30 minutes\n const startTime = Date.now();\n\n while (Date.now() - startTime < MAX_POLL_TIME_MS) {\n const status = await this.workerClient.getBatchStatus(batchId);\n\n if (status.root_pi) {\n return status.root_pi;\n }\n\n if (status.status === 'failed') {\n throw new ValidationError(`Batch discovery failed`);\n }\n\n // Report discovery progress if available\n if (status.discovery_progress && onProgress) {\n const { total, published } = status.discovery_progress;\n const discoveryPercent = total > 0 ? Math.round((published / total) * 100) : 0;\n this.reportProgress(onProgress, {\n phase: 'discovery',\n filesTotal,\n filesUploaded: filesTotal,\n bytesTotal,\n bytesUploaded,\n percentComplete: 95 + Math.round(discoveryPercent * 0.04), // 95-99%\n });\n }\n\n // Wait before polling again\n await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL_MS));\n }\n\n throw new ValidationError(`Discovery timed out after ${MAX_POLL_TIME_MS / 1000} seconds`);\n }\n\n /**\n * Upload files with controlled concurrency\n */\n private async uploadFilesWithConcurrency(\n batchId: string,\n files: FileInfo[],\n source: FileSource | FileSource[],\n concurrency: number,\n onFileComplete: (file: FileInfo, bytes: number) => void\n ): Promise<{ failedFiles: Array<{ file: FileInfo; error: string }> }> {\n const queue = [...files];\n const workers: Promise<void>[] = [];\n const failedFiles: Array<{ file: FileInfo; error: string }> = [];\n\n const processNext = async () => {\n while (queue.length > 0) {\n const file = queue.shift()!;\n try {\n await this.uploadSingleFile(batchId, file, source);\n onFileComplete(file, file.size);\n } catch (error: any) {\n // Log the error but continue with other files\n const errorMessage = error.message || 'Unknown error';\n console.error(`Failed to upload ${file.fileName}: ${errorMessage}`);\n failedFiles.push({ file, error: errorMessage });\n // Don't re-throw - continue processing other files\n }\n }\n };\n\n // Start concurrent workers\n for (let i = 0; i < Math.min(concurrency, files.length); i++) {\n workers.push(processNext());\n }\n\n await Promise.all(workers);\n return { failedFiles };\n }\n\n /**\n * Upload a single file\n */\n private async uploadSingleFile(\n batchId: string,\n file: FileInfo,\n source: FileSource | FileSource[]\n ): Promise<void> {\n // Request presigned URL(s)\n const uploadInfo = await this.workerClient.startFileUpload(batchId, {\n file_name: file.fileName,\n file_size: file.size,\n logical_path: file.logicalPath,\n content_type: file.contentType,\n cid: file.cid,\n processing_config: file.processingConfig,\n });\n\n // Get file data\n const fileData = await this.getFileData(file, source);\n\n // Prepare retry options\n const retryOptions = {\n maxRetries: this.config.maxRetries,\n retryInitialDelay: this.config.retryInitialDelay,\n retryMaxDelay: this.config.retryMaxDelay,\n retryJitter: this.config.retryJitter,\n };\n\n // Upload to R2\n if (uploadInfo.upload_type === 'simple') {\n await uploadSimple(fileData, uploadInfo.presigned_url!, file.contentType, retryOptions);\n } else {\n // Multipart upload - map presigned URLs to array of URL strings\n const partUrls = uploadInfo.presigned_urls!.map((p) => p.url);\n const parts = await uploadMultipart(\n fileData,\n partUrls,\n this.config.parallelParts || 3,\n retryOptions\n );\n\n // Complete multipart upload\n await this.workerClient.completeFileUpload(batchId, {\n r2_key: uploadInfo.r2_key,\n upload_id: uploadInfo.upload_id!,\n parts,\n });\n\n return;\n }\n\n // Complete simple upload\n await this.workerClient.completeFileUpload(batchId, {\n r2_key: uploadInfo.r2_key,\n });\n }\n\n /**\n * Get file data based on platform\n */\n private async getFileData(\n file: FileInfo,\n source: FileSource | FileSource[]\n ): Promise<ArrayBuffer> {\n if (this.platform === 'node') {\n // Read from filesystem\n const fs = await import('fs/promises');\n const buffer = await fs.readFile(file.localPath);\n return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);\n } else if (this.platform === 'browser') {\n // Find the File object from source\n const files = Array.isArray(source) ? source : [source];\n const browserFile = files.find(\n (f) => f instanceof File && f.name === file.fileName\n ) as File | undefined;\n\n if (!browserFile) {\n throw new Error(`Could not find browser File object for ${file.fileName}`);\n }\n\n return browserFile.arrayBuffer();\n }\n\n throw new Error('Unsupported platform for file reading');\n }\n\n /**\n * Report progress to callback\n */\n private reportProgress(\n callback: ((progress: UploadProgress) => void) | undefined,\n progress: UploadProgress\n ): void {\n if (callback) {\n callback(progress);\n }\n }\n}\n","/**\n * Simple upload logic for files < 5 MB (fetch-based)\n */\n\nimport { UploadError } from '../utils/errors.js';\nimport { retryWithBackoff } from '../utils/retry.js';\n\nexport interface SimpleUploadOptions {\n maxRetries?: number;\n retryInitialDelay?: number;\n retryMaxDelay?: number;\n retryJitter?: boolean;\n}\n\n/**\n * Upload file data using simple PUT to presigned URL\n */\nexport async function uploadSimple(\n fileData: ArrayBuffer,\n presignedUrl: string,\n contentType?: string,\n options: SimpleUploadOptions = {}\n): Promise<void> {\n const { maxRetries = 3, retryInitialDelay, retryMaxDelay, retryJitter } = options;\n\n await retryWithBackoff(\n async () => {\n let response: Response;\n try {\n response = await fetch(presignedUrl, {\n method: 'PUT',\n body: fileData,\n headers: {\n ...(contentType ? { 'Content-Type': contentType } : {}),\n },\n });\n } catch (error: any) {\n // Network-level errors (connection refused, timeout, etc.)\n throw new UploadError(`Upload failed: ${error.message}`, undefined, undefined, error);\n }\n\n if (!response.ok) {\n // Extract Retry-After header for 429 responses\n const retryAfter = response.headers.get('retry-after');\n const error = new UploadError(\n `Upload failed with status ${response.status}: ${response.statusText}`,\n undefined,\n response.status\n );\n\n // Attach retry-after if present (convert to seconds)\n if (retryAfter && response.status === 429) {\n (error as any).retryAfter = parseInt(retryAfter, 10);\n }\n\n throw error;\n }\n },\n {\n maxRetries,\n initialDelay: retryInitialDelay,\n maxDelay: retryMaxDelay,\n jitter: retryJitter,\n }\n );\n}\n","/**\n * Multipart upload logic for files ≥ 5 MB (fetch-based)\n */\n\nimport type { PartInfo } from '../types/api.js';\nimport { UploadError } from '../utils/errors.js';\nimport { retryWithBackoff } from '../utils/retry.js';\n\nconst DEFAULT_PART_SIZE = 10 * 1024 * 1024; // 10 MB\n\nexport interface MultipartUploadOptions {\n maxRetries?: number;\n retryInitialDelay?: number;\n retryMaxDelay?: number;\n retryJitter?: boolean;\n}\n\n/**\n * Upload file data using multipart upload with presigned URLs\n * @param fileData - File data as ArrayBuffer\n * @param presignedUrls - Array of presigned URLs for each part\n * @param concurrency - Number of parts to upload in parallel\n * @param options - Upload retry options\n * @returns Array of PartInfo with ETags\n */\nexport async function uploadMultipart(\n fileData: ArrayBuffer,\n presignedUrls: string[],\n concurrency: number = 3,\n options: MultipartUploadOptions = {}\n): Promise<PartInfo[]> {\n const totalSize = fileData.byteLength;\n const partSize = Math.ceil(totalSize / presignedUrls.length);\n\n // Create upload tasks for each part\n const parts: PartInfo[] = [];\n const queue: Array<() => Promise<void>> = [];\n\n const { maxRetries = 3, retryInitialDelay, retryMaxDelay, retryJitter } = options;\n\n for (let i = 0; i < presignedUrls.length; i++) {\n const partNumber = i + 1;\n const start = i * partSize;\n const end = Math.min(start + partSize, totalSize);\n const partData = fileData.slice(start, end);\n const url = presignedUrls[i];\n\n queue.push(async () => {\n const etag = await uploadPart(partData, url, partNumber, maxRetries, {\n initialDelay: retryInitialDelay,\n maxDelay: retryMaxDelay,\n jitter: retryJitter,\n });\n parts.push({ part_number: partNumber, etag });\n });\n }\n\n // Execute uploads with concurrency control\n await executeWithConcurrency(queue, concurrency);\n\n // Sort parts by part number\n parts.sort((a, b) => a.part_number - b.part_number);\n\n return parts;\n}\n\n/**\n * Upload a single part\n */\nasync function uploadPart(\n partData: ArrayBuffer,\n presignedUrl: string,\n partNumber: number,\n maxRetries: number = 3,\n retryOptions: { initialDelay?: number; maxDelay?: number; jitter?: boolean } = {}\n): Promise<string> {\n return retryWithBackoff(\n async () => {\n let response: Response;\n try {\n response = await fetch(presignedUrl, {\n method: 'PUT',\n body: partData,\n });\n } catch (error: any) {\n // Network-level errors (connection refused, timeout, etc.)\n throw new UploadError(\n `Part ${partNumber} upload failed: ${error.message}`,\n undefined,\n undefined,\n error\n );\n }\n\n if (!response.ok) {\n // Extract Retry-After header for 429 responses\n const retryAfter = response.headers.get('retry-after');\n const error = new UploadError(\n `Part ${partNumber} upload failed with status ${response.status}: ${response.statusText}`,\n undefined,\n response.status\n );\n\n // Attach retry-after if present (convert to seconds)\n if (retryAfter && response.status === 429) {\n (error as any).retryAfter = parseInt(retryAfter, 10);\n }\n\n throw error;\n }\n\n // Get ETag from response headers\n const etag = response.headers.get('etag');\n if (!etag) {\n throw new UploadError(\n `Part ${partNumber} upload succeeded but no ETag returned`,\n undefined,\n response.status\n );\n }\n\n // Clean ETag (remove quotes if present)\n return etag.replace(/\"/g, '');\n },\n {\n maxRetries,\n initialDelay: retryOptions.initialDelay,\n maxDelay: retryOptions.maxDelay,\n jitter: retryOptions.jitter,\n }\n );\n}\n\n/**\n * Execute tasks with controlled concurrency\n */\nasync function executeWithConcurrency(\n tasks: Array<() => Promise<void>>,\n concurrency: number\n): Promise<void> {\n const queue = [...tasks];\n const workers: Promise<void>[] = [];\n\n const processNext = async () => {\n while (queue.length > 0) {\n const task = queue.shift()!;\n await task();\n }\n };\n\n // Start concurrent workers\n for (let i = 0; i < Math.min(concurrency, tasks.length); i++) {\n workers.push(processNext());\n }\n\n await Promise.all(workers);\n}\n","/**\n * Upload Client with Collections Integration\n * Provides high-level upload operations with permission checks\n */\n\nimport type {\n UploaderConfig,\n UploadOptions,\n UploadProgress,\n BatchResult,\n CustomPrompts,\n} from './types/config';\nimport type { ProcessingConfig } from './types/processing';\nimport { ArkeUploader } from './uploader';\nimport { CollectionsClient, type CollectionsClientConfig } from '../collections/client';\nimport type { CreateCollectionPayload, Collection, PiPermissions } from '../collections/types';\n\nexport interface UploadClientConfig {\n /**\n * Gateway base URL (e.g., https://api.arke.institute)\n */\n gatewayUrl: string;\n /**\n * Bearer token for authentication\n */\n authToken: string;\n /**\n * Name of person/service uploading files (defaults to user ID from JWT)\n */\n uploader?: string;\n /**\n * Custom fetch implementation (optional, for testing)\n */\n fetchImpl?: typeof fetch;\n}\n\n/**\n * Extract user ID from JWT token (without verification)\n */\nfunction getUserIdFromToken(token: string): string | null {\n try {\n const parts = token.split('.');\n if (parts.length !== 3) return null;\n\n // Decode base64url payload\n const payload = parts[1]\n .replace(/-/g, '+')\n .replace(/_/g, '/');\n\n // Handle browser vs Node.js\n let decoded: string;\n if (typeof atob === 'function') {\n decoded = atob(payload);\n } else {\n decoded = Buffer.from(payload, 'base64').toString('utf-8');\n }\n\n const data = JSON.parse(decoded);\n return data.sub || null;\n } catch {\n return null;\n }\n}\n\nexport interface CreateCollectionUploadOptions {\n /**\n * Files to upload - directory path (Node.js) or File[]/FileList (browser)\n */\n files: string | File[] | FileList;\n /**\n * Collection metadata\n */\n collectionMetadata: CreateCollectionPayload;\n /**\n * Custom prompts for AI processing\n */\n customPrompts?: CustomPrompts;\n /**\n * Processing options (OCR, IIIF, etc.)\n */\n processing?: ProcessingConfig;\n /**\n * Progress callback\n */\n onProgress?: (progress: UploadProgress) => void;\n /**\n * Dry run mode\n */\n dryRun?: boolean;\n}\n\nexport interface AddToCollectionOptions {\n /**\n * Files to upload - directory path (Node.js) or File[]/FileList (browser)\n */\n files: string | File[] | FileList;\n /**\n * Parent PI to add files under (must be within a collection you can edit)\n */\n parentPi: string;\n /**\n * Custom prompts for AI processing\n */\n customPrompts?: CustomPrompts;\n /**\n * Processing options (OCR, IIIF, etc.)\n */\n processing?: ProcessingConfig;\n /**\n * Progress callback\n */\n onProgress?: (progress: UploadProgress) => void;\n /**\n * Dry run mode\n */\n dryRun?: boolean;\n}\n\nexport interface CreateCollectionUploadResult extends BatchResult {\n /**\n * The created collection\n */\n collection: Collection & { rootPi: string };\n}\n\n/**\n * High-level upload client with collections integration\n *\n * @example\n * ```typescript\n * import { UploadClient } from '@arke-institute/sdk';\n *\n * const client = new UploadClient({\n * gatewayUrl: 'https://api.arke.institute',\n * authToken: 'your-jwt-token',\n * uploader: 'my-app',\n * });\n *\n * // Create a new collection from files\n * const result = await client.createCollection({\n * files: './photos',\n * collectionMetadata: { title: 'My Archive', slug: 'my-archive' },\n * });\n *\n * // Add files to an existing collection\n * await client.addToCollection({\n * files: './more-photos',\n * parentPi: result.collection.rootPi,\n * });\n * ```\n */\nexport class UploadClient {\n private config: UploadClientConfig & { uploader: string };\n private collectionsClient: CollectionsClient;\n\n constructor(config: UploadClientConfig) {\n // Default uploader to user ID from JWT if not provided\n const uploader = config.uploader || getUserIdFromToken(config.authToken) || 'unknown';\n\n this.config = { ...config, uploader };\n this.collectionsClient = new CollectionsClient({\n gatewayUrl: config.gatewayUrl,\n authToken: config.authToken,\n fetchImpl: config.fetchImpl,\n });\n }\n\n /**\n * Update the auth token (e.g., after token refresh)\n */\n setAuthToken(token: string) {\n this.config = { ...this.config, authToken: token };\n this.collectionsClient.setAuthToken(token);\n }\n\n /**\n * Create a new collection and upload files to it\n *\n * Anyone authenticated can create a new collection.\n * The root PI of the uploaded files becomes the collection's root.\n */\n async createCollection(\n options: CreateCollectionUploadOptions\n ): Promise<CreateCollectionUploadResult> {\n const { files, collectionMetadata, customPrompts, processing, onProgress, dryRun } = options;\n\n // Default visibility to 'public' if not specified\n const metadata = {\n ...collectionMetadata,\n visibility: collectionMetadata.visibility || 'public',\n };\n\n // Create uploader for the batch\n const uploader = new ArkeUploader({\n gatewayUrl: this.config.gatewayUrl,\n authToken: this.config.authToken,\n uploader: this.config.uploader,\n customPrompts,\n processing,\n });\n\n // Upload the files first\n const batchResult = await uploader.uploadBatch(files as any, {\n onProgress,\n dryRun,\n });\n\n if (dryRun) {\n return {\n ...batchResult,\n collection: {\n id: 'dry-run',\n title: metadata.title,\n slug: metadata.slug,\n description: metadata.description,\n visibility: metadata.visibility,\n rootPi: 'dry-run',\n },\n };\n }\n\n // Register the root PI as a collection\n // The uploader returns the real rootPi after discovery completes\n const collection = await this.collectionsClient.registerRoot({\n ...metadata,\n rootPi: batchResult.rootPi,\n });\n\n return {\n ...batchResult,\n collection,\n };\n }\n\n /**\n * Add files to an existing collection\n *\n * Requires owner or editor role on the collection containing the parent PI.\n * Use this to add a folder or files to an existing collection hierarchy.\n *\n * Note: Permission checks are enforced server-side by the ingest worker.\n * The server will return 403 if the user lacks edit access to the parent PI.\n */\n async addToCollection(options: AddToCollectionOptions): Promise<BatchResult> {\n const { files, parentPi, customPrompts, processing, onProgress, dryRun } = options;\n\n // Create uploader with the parent PI\n const uploader = new ArkeUploader({\n gatewayUrl: this.config.gatewayUrl,\n authToken: this.config.authToken,\n uploader: this.config.uploader,\n parentPi,\n customPrompts,\n processing,\n });\n\n // Upload the files\n return uploader.uploadBatch(files as any, {\n onProgress,\n dryRun,\n });\n }\n\n /**\n * Check if you can edit a specific PI (i.e., add files to its collection)\n */\n async canEdit(pi: string): Promise<PiPermissions> {\n return this.collectionsClient.getPiPermissions(pi);\n }\n\n /**\n * Get access to the underlying collections client for other operations\n */\n get collections(): CollectionsClient {\n return this.collectionsClient;\n }\n}\n","/**\n * Error class for query operations\n */\nexport class QueryError extends Error {\n constructor(\n message: string,\n public code: string = 'UNKNOWN_ERROR',\n public details?: unknown\n ) {\n super(message);\n this.name = 'QueryError';\n }\n}\n","import { QueryError } from './errors';\nimport type {\n PathQueryOptions,\n NaturalQueryOptions,\n QueryResult,\n NaturalQueryResult,\n TranslateResult,\n ParseResult,\n ParseError,\n SyntaxDocumentation,\n CollectionSearchOptions,\n CollectionSearchResponse,\n} from './types';\n\n/**\n * Configuration for QueryClient\n */\nexport interface QueryClientConfig {\n /**\n * Gateway base URL (e.g., https://gateway.arke.institute).\n * The client will call /query/* endpoints.\n */\n gatewayUrl: string;\n /**\n * Optional custom fetch implementation (useful for testing).\n */\n fetchImpl?: typeof fetch;\n}\n\ntype JsonBody = Record<string, unknown>;\n\n/**\n * Client for querying the Arke knowledge graph.\n *\n * All query endpoints are public and do not require authentication.\n *\n * @example\n * ```typescript\n * const query = new QueryClient({\n * gatewayUrl: 'https://gateway.arke.institute',\n * });\n *\n * // Direct path query\n * const results = await query.path('\"alice austen\" -[*]{,4}-> type:person');\n *\n * // Natural language query\n * const nlResults = await query.natural('Find photographers connected to Alice Austen');\n *\n * // Get syntax documentation\n * const syntax = await query.syntax();\n * ```\n */\nexport class QueryClient {\n private baseUrl: string;\n private fetchImpl: typeof fetch;\n\n constructor(config: QueryClientConfig) {\n this.baseUrl = config.gatewayUrl.replace(/\\/$/, '');\n this.fetchImpl = config.fetchImpl ?? fetch;\n }\n\n // ---------------------------------------------------------------------------\n // Request helpers\n // ---------------------------------------------------------------------------\n\n private buildUrl(path: string, query?: Record<string, string | undefined>) {\n const url = new URL(`${this.baseUrl}${path}`);\n if (query) {\n Object.entries(query).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n });\n }\n return url.toString();\n }\n\n private async request<T>(\n path: string,\n options: RequestInit & {\n query?: Record<string, string | undefined>;\n } = {}\n ): Promise<T> {\n const url = this.buildUrl(path, options.query);\n const headers = new Headers({ 'Content-Type': 'application/json' });\n if (options.headers) {\n Object.entries(options.headers).forEach(([k, v]) => {\n if (v !== undefined) headers.set(k, v as string);\n });\n }\n\n const response = await this.fetchImpl(url, { ...options, headers });\n\n if (response.ok) {\n const contentType = response.headers.get('content-type') || '';\n if (contentType.includes('application/json')) {\n return (await response.json()) as T;\n }\n return (await response.text()) as unknown as T;\n }\n\n let body: unknown;\n const text = await response.text();\n try {\n body = JSON.parse(text);\n } catch {\n body = text;\n }\n\n const message =\n (body as JsonBody)?.error && typeof (body as JsonBody).error === 'string'\n ? ((body as JsonBody).error as string)\n : (body as JsonBody)?.message && typeof (body as JsonBody).message === 'string'\n ? ((body as JsonBody).message as string)\n : `Request failed with status ${response.status}`;\n\n throw new QueryError(message, 'HTTP_ERROR', {\n status: response.status,\n body,\n });\n }\n\n // ---------------------------------------------------------------------------\n // Query methods\n // ---------------------------------------------------------------------------\n\n /**\n * Execute a path query against the knowledge graph.\n *\n * @param pathQuery - The path query string (e.g., '\"alice austen\" -[*]{,4}-> type:person')\n * @param options - Query options (k, k_explore, lineage, enrich, etc.)\n * @returns Query results with entities, paths, and metadata\n *\n * @example\n * ```typescript\n * // Simple semantic search\n * const results = await query.path('\"Washington\" type:person');\n *\n * // Multi-hop traversal\n * const results = await query.path('\"alice austen\" -[*]{,4}-> type:person ~ \"photographer\"');\n *\n * // With lineage filtering (collection scope)\n * const results = await query.path('\"letters\" type:document', {\n * lineage: { sourcePi: 'arke:my_collection', direction: 'descendants' },\n * k: 10,\n * });\n * ```\n */\n async path(pathQuery: string, options: PathQueryOptions = {}): Promise<QueryResult> {\n return this.request<QueryResult>('/query/path', {\n method: 'POST',\n body: JSON.stringify({\n path: pathQuery,\n ...options,\n }),\n });\n }\n\n /**\n * Execute a natural language query.\n *\n * The query is translated to a path query using an LLM, then executed.\n *\n * @param question - Natural language question\n * @param options - Query options including custom_instructions for the LLM\n * @returns Query results with translation info\n *\n * @example\n * ```typescript\n * const results = await query.natural('Find photographers connected to Alice Austen');\n * console.log('Generated query:', results.translation.path);\n * console.log('Explanation:', results.translation.explanation);\n * ```\n */\n async natural(question: string, options: NaturalQueryOptions = {}): Promise<NaturalQueryResult> {\n const { custom_instructions, ...queryOptions } = options;\n return this.request<NaturalQueryResult>('/query/natural', {\n method: 'POST',\n body: JSON.stringify({\n query: question,\n custom_instructions,\n ...queryOptions,\n }),\n });\n }\n\n /**\n * Translate a natural language question to a path query without executing it.\n *\n * Useful for understanding how questions are translated or for manual execution later.\n *\n * @param question - Natural language question\n * @param customInstructions - Optional additional instructions for the LLM\n * @returns Translation result with path query and explanation\n *\n * @example\n * ```typescript\n * const result = await query.translate('Who wrote letters from Philadelphia?');\n * console.log('Path query:', result.path);\n * // '\"letters\" <-[authored, wrote]- type:person -[located]-> \"Philadelphia\"'\n * ```\n */\n async translate(question: string, customInstructions?: string): Promise<TranslateResult> {\n return this.request<TranslateResult>('/query/translate', {\n method: 'POST',\n body: JSON.stringify({\n query: question,\n custom_instructions: customInstructions,\n }),\n });\n }\n\n /**\n * Parse and validate a path query without executing it.\n *\n * Returns the AST (Abstract Syntax Tree) if valid, or throws an error.\n *\n * @param pathQuery - The path query to parse\n * @returns Parsed AST\n * @throws QueryError if the query has syntax errors\n *\n * @example\n * ```typescript\n * try {\n * const result = await query.parse('\"test\" -[*]-> type:person');\n * console.log('Valid query, AST:', result.ast);\n * } catch (err) {\n * console.error('Invalid query:', err.message);\n * }\n * ```\n */\n async parse(pathQuery: string): Promise<ParseResult> {\n const url = this.buildUrl('/query/parse', { path: pathQuery });\n const response = await this.fetchImpl(url, {\n method: 'GET',\n headers: { 'Content-Type': 'application/json' },\n });\n\n const body = await response.json() as ParseResult | ParseError;\n\n // Check if it's an error response (parse errors return 400)\n if ('error' in body && body.error === 'Parse error') {\n throw new QueryError(\n (body as ParseError).message,\n 'PARSE_ERROR',\n { position: (body as ParseError).position }\n );\n }\n\n if (!response.ok) {\n throw new QueryError(\n (body as any).error || `Request failed with status ${response.status}`,\n 'HTTP_ERROR',\n { status: response.status, body }\n );\n }\n\n return body as ParseResult;\n }\n\n /**\n * Get the path query syntax documentation.\n *\n * Returns comprehensive documentation including entry points, edge traversal,\n * filters, examples, and constraints.\n *\n * @returns Syntax documentation\n *\n * @example\n * ```typescript\n * const syntax = await query.syntax();\n *\n * // List all entry point types\n * syntax.entryPoints.types.forEach(ep => {\n * console.log(`${ep.syntax} - ${ep.description}`);\n * });\n *\n * // Show examples\n * syntax.examples.forEach(ex => {\n * console.log(`${ex.description}: ${ex.query}`);\n * });\n * ```\n */\n async syntax(): Promise<SyntaxDocumentation> {\n return this.request<SyntaxDocumentation>('/query/syntax', {\n method: 'GET',\n });\n }\n\n /**\n * Check the health of the query service.\n *\n * @returns Health status\n */\n async health(): Promise<{ status: string; service: string; version: string }> {\n return this.request('/query/health', { method: 'GET' });\n }\n\n /**\n * Search for collections by semantic similarity.\n *\n * Searches the dedicated collections index for fast semantic matching.\n *\n * @param query - Search query text\n * @param options - Search options (limit, visibility filter)\n * @returns Matching collections with similarity scores\n *\n * @example\n * ```typescript\n * // Search for photography-related collections\n * const results = await query.searchCollections('photography');\n * console.log(results.collections[0].title);\n *\n * // Search only public collections\n * const publicResults = await query.searchCollections('history', {\n * visibility: 'public',\n * limit: 20,\n * });\n * ```\n */\n async searchCollections(\n query: string,\n options: CollectionSearchOptions = {}\n ): Promise<CollectionSearchResponse> {\n return this.request<CollectionSearchResponse>('/query/search/collections', {\n method: 'GET',\n query: {\n q: query,\n limit: options.limit?.toString(),\n visibility: options.visibility,\n },\n });\n }\n}\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","/**\n * Content package error classes for the Arke SDK\n */\n\n/**\n * Base error class for content operations\n */\nexport class ContentError extends Error {\n constructor(\n message: string,\n public code: string = 'CONTENT_ERROR',\n public details?: unknown\n ) {\n super(message);\n this.name = 'ContentError';\n }\n}\n\n/**\n * Thrown when an entity is not found by PI\n */\nexport class EntityNotFoundError extends ContentError {\n constructor(pi: string) {\n super(`Entity not found: ${pi}`, 'ENTITY_NOT_FOUND', { pi });\n this.name = 'EntityNotFoundError';\n }\n}\n\n/**\n * Thrown when content is not found by CID\n */\nexport class ContentNotFoundError extends ContentError {\n constructor(cid: string) {\n super(`Content not found: ${cid}`, 'CONTENT_NOT_FOUND', { cid });\n this.name = 'ContentNotFoundError';\n }\n}\n\n/**\n * Thrown when a component is not found on an entity\n */\nexport class ComponentNotFoundError extends ContentError {\n constructor(pi: string, componentName: string) {\n super(\n `Component '${componentName}' not found on entity ${pi}`,\n 'COMPONENT_NOT_FOUND',\n { pi, componentName }\n );\n this.name = 'ComponentNotFoundError';\n }\n}\n\n/**\n * Thrown when a version is not found\n */\nexport class VersionNotFoundError extends ContentError {\n constructor(pi: string, selector: string) {\n super(\n `Version not found: ${selector} for entity ${pi}`,\n 'VERSION_NOT_FOUND',\n { pi, selector }\n );\n this.name = 'VersionNotFoundError';\n }\n}\n\n/**\n * Thrown when a network error occurs\n */\nexport class NetworkError extends ContentError {\n constructor(message: string, public statusCode?: number) {\n super(message, 'NETWORK_ERROR', { statusCode });\n this.name = 'NetworkError';\n }\n}\n","import {\n ContentError,\n EntityNotFoundError,\n ContentNotFoundError,\n ComponentNotFoundError,\n NetworkError,\n} from './errors.js';\nimport type {\n Entity,\n EntityVersion,\n ListOptions,\n ListResponse,\n VersionsOptions,\n VersionsResponse,\n ResolveResponse,\n} from './types.js';\n\n/**\n * Configuration for ContentClient\n */\nexport interface ContentClientConfig {\n /**\n * Gateway base URL (e.g., https://gateway.arke.institute).\n * The client will call /api/* endpoints for IPFS Wrapper.\n */\n gatewayUrl: string;\n /**\n * Optional custom fetch implementation (useful for testing).\n */\n fetchImpl?: typeof fetch;\n}\n\ntype JsonBody = Record<string, unknown>;\n\n/**\n * Client for accessing entities and content from the Arke archive.\n *\n * All endpoints are public and do not require authentication.\n *\n * @example\n * ```typescript\n * const content = new ContentClient({\n * gatewayUrl: 'https://gateway.arke.institute',\n * });\n *\n * // Get an entity\n * const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');\n *\n * // Download content by CID\n * const blob = await content.download('bafybeihkoviema7g3gxyt6la7vd5ho32jywf7b4c4z3qtwcabpjqxwsumu');\n *\n * // Get component content\n * const pinax = await content.getComponent(entity, 'pinax');\n * ```\n */\nexport class ContentClient {\n private baseUrl: string;\n private fetchImpl: typeof fetch;\n\n constructor(config: ContentClientConfig) {\n this.baseUrl = config.gatewayUrl.replace(/\\/$/, '');\n this.fetchImpl = config.fetchImpl ?? fetch;\n }\n\n // ---------------------------------------------------------------------------\n // Request helpers\n // ---------------------------------------------------------------------------\n\n private buildUrl(path: string, query?: Record<string, string | number | boolean | undefined>) {\n const url = new URL(`${this.baseUrl}${path}`);\n if (query) {\n Object.entries(query).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n });\n }\n return url.toString();\n }\n\n private async request<T>(\n path: string,\n options: RequestInit & {\n query?: Record<string, string | number | boolean | undefined>;\n } = {}\n ): Promise<T> {\n const url = this.buildUrl(path, options.query);\n const headers = new Headers({ 'Content-Type': 'application/json' });\n if (options.headers) {\n Object.entries(options.headers).forEach(([k, v]) => {\n if (v !== undefined) headers.set(k, v as string);\n });\n }\n\n let response: Response;\n try {\n response = await this.fetchImpl(url, { ...options, headers });\n } catch (err) {\n throw new NetworkError(\n err instanceof Error ? err.message : 'Network request failed'\n );\n }\n\n if (response.ok) {\n const contentType = response.headers.get('content-type') || '';\n if (contentType.includes('application/json')) {\n return (await response.json()) as T;\n }\n return (await response.text()) as unknown as T;\n }\n\n let body: unknown;\n const text = await response.text();\n try {\n body = JSON.parse(text);\n } catch {\n body = text;\n }\n\n // Handle 404 specifically\n if (response.status === 404) {\n const errorCode = (body as JsonBody)?.error;\n if (errorCode === 'NOT_FOUND' || errorCode === 'ENTITY_NOT_FOUND') {\n throw new ContentError(\n (body as JsonBody)?.message as string || 'Not found',\n 'NOT_FOUND',\n body\n );\n }\n }\n\n const message =\n (body as JsonBody)?.error && typeof (body as JsonBody).error === 'string'\n ? ((body as JsonBody).error as string)\n : (body as JsonBody)?.message && typeof (body as JsonBody).message === 'string'\n ? ((body as JsonBody).message as string)\n : `Request failed with status ${response.status}`;\n\n throw new ContentError(message, 'HTTP_ERROR', {\n status: response.status,\n body,\n });\n }\n\n // ---------------------------------------------------------------------------\n // Entity Operations\n // ---------------------------------------------------------------------------\n\n /**\n * Get an entity by its Persistent Identifier (PI).\n *\n * @param pi - Persistent Identifier (ULID or test PI with II prefix)\n * @returns Full entity manifest\n * @throws EntityNotFoundError if the entity doesn't exist\n *\n * @example\n * ```typescript\n * const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');\n * console.log('Version:', entity.ver);\n * console.log('Components:', Object.keys(entity.components));\n * ```\n */\n async get(pi: string): Promise<Entity> {\n try {\n return await this.request<Entity>(`/api/entities/${encodeURIComponent(pi)}`);\n } catch (err) {\n if (err instanceof ContentError && err.code === 'NOT_FOUND') {\n throw new EntityNotFoundError(pi);\n }\n throw err;\n }\n }\n\n /**\n * List entities with pagination.\n *\n * @param options - Pagination and metadata options\n * @returns Paginated list of entity summaries\n *\n * @example\n * ```typescript\n * // Get first page\n * const page1 = await content.list({ limit: 20, include_metadata: true });\n *\n * // Get next page\n * if (page1.next_cursor) {\n * const page2 = await content.list({ cursor: page1.next_cursor });\n * }\n * ```\n */\n async list(options: ListOptions = {}): Promise<ListResponse> {\n return this.request<ListResponse>('/api/entities', {\n query: {\n limit: options.limit,\n cursor: options.cursor,\n include_metadata: options.include_metadata,\n },\n });\n }\n\n /**\n * Get version history for an entity.\n *\n * @param pi - Persistent Identifier\n * @param options - Pagination options\n * @returns Version history (newest first)\n *\n * @example\n * ```typescript\n * const history = await content.versions('01K75HQQXNTDG7BBP7PS9AWYAN');\n * console.log('Total versions:', history.items.length);\n * history.items.forEach(v => {\n * console.log(`v${v.ver}: ${v.ts} - ${v.note || 'no note'}`);\n * });\n * ```\n */\n async versions(pi: string, options: VersionsOptions = {}): Promise<VersionsResponse> {\n try {\n return await this.request<VersionsResponse>(\n `/api/entities/${encodeURIComponent(pi)}/versions`,\n {\n query: {\n limit: options.limit,\n cursor: options.cursor,\n },\n }\n );\n } catch (err) {\n if (err instanceof ContentError && err.code === 'NOT_FOUND') {\n throw new EntityNotFoundError(pi);\n }\n throw err;\n }\n }\n\n /**\n * Get a specific version of an entity.\n *\n * @param pi - Persistent Identifier\n * @param selector - Version selector: 'ver:N' for version number or 'cid:...' for CID\n * @returns Entity manifest for the specified version\n *\n * @example\n * ```typescript\n * // Get version 2\n * const v2 = await content.getVersion('01K75HQQXNTDG7BBP7PS9AWYAN', 'ver:2');\n *\n * // Get by CID\n * const vByCid = await content.getVersion('01K75HQQXNTDG7BBP7PS9AWYAN', 'cid:bafybeih...');\n * ```\n */\n async getVersion(pi: string, selector: string): Promise<Entity> {\n try {\n return await this.request<Entity>(\n `/api/entities/${encodeURIComponent(pi)}/versions/${encodeURIComponent(selector)}`\n );\n } catch (err) {\n if (err instanceof ContentError && err.code === 'NOT_FOUND') {\n throw new EntityNotFoundError(pi);\n }\n throw err;\n }\n }\n\n /**\n * Resolve a PI to its tip CID (fast lookup without fetching manifest).\n *\n * @param pi - Persistent Identifier\n * @returns PI and tip CID\n *\n * @example\n * ```typescript\n * const { tip } = await content.resolve('01K75HQQXNTDG7BBP7PS9AWYAN');\n * console.log('Latest manifest CID:', tip);\n * ```\n */\n async resolve(pi: string): Promise<ResolveResponse> {\n try {\n return await this.request<ResolveResponse>(`/api/resolve/${encodeURIComponent(pi)}`);\n } catch (err) {\n if (err instanceof ContentError && err.code === 'NOT_FOUND') {\n throw new EntityNotFoundError(pi);\n }\n throw err;\n }\n }\n\n /**\n * Get the list of child PIs for an entity (fast, returns only PIs).\n *\n * @param pi - Persistent Identifier of parent entity\n * @returns Array of child PIs\n *\n * @example\n * ```typescript\n * const childPis = await content.children('01K75HQQXNTDG7BBP7PS9AWYAN');\n * console.log('Children:', childPis);\n * ```\n */\n async children(pi: string): Promise<string[]> {\n const entity = await this.get(pi);\n return entity.children_pi || [];\n }\n\n /**\n * Get all child entities for a parent (fetches full entity for each child).\n *\n * @param pi - Persistent Identifier of parent entity\n * @returns Array of child entities\n *\n * @example\n * ```typescript\n * const childEntities = await content.childrenEntities('01K75HQQXNTDG7BBP7PS9AWYAN');\n * childEntities.forEach(child => {\n * console.log(`${child.pi}: v${child.ver}`);\n * });\n * ```\n */\n async childrenEntities(pi: string): Promise<Entity[]> {\n const childPis = await this.children(pi);\n if (childPis.length === 0) {\n return [];\n }\n\n // Fetch all children in parallel\n const results = await Promise.allSettled(\n childPis.map(childPi => this.get(childPi))\n );\n\n // Return only successful fetches\n return results\n .filter((r): r is PromiseFulfilledResult<Entity> => r.status === 'fulfilled')\n .map(r => r.value);\n }\n\n /**\n * Get the Arke origin block (root of the archive tree).\n *\n * @returns Arke origin entity\n *\n * @example\n * ```typescript\n * const origin = await content.arke();\n * console.log('Arke origin:', origin.pi);\n * ```\n */\n async arke(): Promise<Entity> {\n return this.request<Entity>('/api/arke');\n }\n\n // ---------------------------------------------------------------------------\n // Content Download\n // ---------------------------------------------------------------------------\n\n /**\n * Download content by CID.\n *\n * Returns Blob in browser environments, Buffer in Node.js.\n *\n * @param cid - Content Identifier\n * @returns Content as Blob (browser) or Buffer (Node)\n * @throws ContentNotFoundError if the content doesn't exist\n *\n * @example\n * ```typescript\n * const content = await client.download('bafybeih...');\n *\n * // In browser\n * const url = URL.createObjectURL(content as Blob);\n *\n * // In Node.js\n * fs.writeFileSync('output.bin', content as Buffer);\n * ```\n */\n async download(cid: string): Promise<Blob | Buffer> {\n const url = this.buildUrl(`/api/cat/${encodeURIComponent(cid)}`);\n\n let response: Response;\n try {\n response = await this.fetchImpl(url);\n } catch (err) {\n throw new NetworkError(\n err instanceof Error ? err.message : 'Network request failed'\n );\n }\n\n if (!response.ok) {\n if (response.status === 404) {\n throw new ContentNotFoundError(cid);\n }\n throw new ContentError(\n `Failed to download content: ${response.status}`,\n 'DOWNLOAD_ERROR',\n { status: response.status }\n );\n }\n\n // Platform-aware response handling\n if (typeof window !== 'undefined') {\n // Browser environment\n return response.blob();\n } else {\n // Node.js environment\n const arrayBuffer = await response.arrayBuffer();\n return Buffer.from(arrayBuffer);\n }\n }\n\n /**\n * Get a direct URL for content by CID.\n *\n * This is useful for embedding in img tags or for direct downloads.\n *\n * @param cid - Content Identifier\n * @returns URL string\n *\n * @example\n * ```typescript\n * const url = content.getUrl('bafybeih...');\n * // Use in img tag: <img src={url} />\n * ```\n */\n getUrl(cid: string): string {\n return `${this.baseUrl}/api/cat/${encodeURIComponent(cid)}`;\n }\n\n /**\n * Stream content by CID.\n *\n * @param cid - Content Identifier\n * @returns ReadableStream of the content\n * @throws ContentNotFoundError if the content doesn't exist\n *\n * @example\n * ```typescript\n * const stream = await content.stream('bafybeih...');\n * const reader = stream.getReader();\n * while (true) {\n * const { done, value } = await reader.read();\n * if (done) break;\n * // Process chunk\n * }\n * ```\n */\n async stream(cid: string): Promise<ReadableStream<Uint8Array>> {\n const url = this.buildUrl(`/api/cat/${encodeURIComponent(cid)}`);\n\n let response: Response;\n try {\n response = await this.fetchImpl(url);\n } catch (err) {\n throw new NetworkError(\n err instanceof Error ? err.message : 'Network request failed'\n );\n }\n\n if (!response.ok) {\n if (response.status === 404) {\n throw new ContentNotFoundError(cid);\n }\n throw new ContentError(\n `Failed to stream content: ${response.status}`,\n 'STREAM_ERROR',\n { status: response.status }\n );\n }\n\n if (!response.body) {\n throw new ContentError('Response body is not available', 'STREAM_ERROR');\n }\n\n return response.body;\n }\n\n // ---------------------------------------------------------------------------\n // Component Helpers\n // ---------------------------------------------------------------------------\n\n /**\n * Download a component from an entity.\n *\n * @param entity - Entity containing the component\n * @param componentName - Name of the component (e.g., 'pinax', 'description', 'source')\n * @returns Component content as Blob (browser) or Buffer (Node)\n * @throws ComponentNotFoundError if the component doesn't exist\n *\n * @example\n * ```typescript\n * const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');\n * const pinax = await content.getComponent(entity, 'pinax');\n * ```\n */\n async getComponent(entity: Entity, componentName: string): Promise<Blob | Buffer> {\n const cid = entity.components[componentName];\n if (!cid) {\n throw new ComponentNotFoundError(entity.pi, componentName);\n }\n return this.download(cid);\n }\n\n /**\n * Get the URL for a component from an entity.\n *\n * @param entity - Entity containing the component\n * @param componentName - Name of the component\n * @returns URL string\n * @throws ComponentNotFoundError if the component doesn't exist\n *\n * @example\n * ```typescript\n * const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');\n * const imageUrl = content.getComponentUrl(entity, 'source');\n * // Use in img tag: <img src={imageUrl} />\n * ```\n */\n getComponentUrl(entity: Entity, componentName: string): string {\n const cid = entity.components[componentName];\n if (!cid) {\n throw new ComponentNotFoundError(entity.pi, componentName);\n }\n return this.getUrl(cid);\n }\n}\n","/**\n * Graph package error classes for the Arke SDK\n */\n\n/**\n * Base error class for graph operations\n */\nexport class GraphError extends Error {\n constructor(\n message: string,\n public code: string = 'GRAPH_ERROR',\n public details?: unknown\n ) {\n super(message);\n this.name = 'GraphError';\n }\n}\n\n/**\n * Thrown when an entity is not found by canonical ID\n */\nexport class GraphEntityNotFoundError extends GraphError {\n constructor(canonicalId: string) {\n super(`Graph entity not found: ${canonicalId}`, 'ENTITY_NOT_FOUND', { canonicalId });\n this.name = 'GraphEntityNotFoundError';\n }\n}\n\n/**\n * Thrown when no paths are found between entities\n */\nexport class NoPathFoundError extends GraphError {\n constructor(sourceIds: string[], targetIds: string[]) {\n super(\n `No path found between sources and targets`,\n 'NO_PATH_FOUND',\n { sourceIds, targetIds }\n );\n this.name = 'NoPathFoundError';\n }\n}\n\n/**\n * Thrown when a network error occurs\n */\nexport class NetworkError extends GraphError {\n constructor(message: string, public statusCode?: number) {\n super(message, 'NETWORK_ERROR', { statusCode });\n this.name = 'NetworkError';\n }\n}\n","import {\n GraphError,\n GraphEntityNotFoundError,\n NetworkError,\n} from './errors.js';\nimport type {\n GraphEntity,\n EntityWithRelationships,\n Relationship,\n Path,\n PathOptions,\n ReachableOptions,\n ListFromPiOptions,\n EntityQueryResponse,\n EntitiesWithRelationshipsResponse,\n PathsResponse,\n LineageResponse,\n} from './types.js';\n\n/**\n * Configuration for GraphClient\n */\nexport interface GraphClientConfig {\n /**\n * Gateway base URL (e.g., https://gateway.arke.institute).\n * The client will call /graphdb/* endpoints for GraphDB Gateway.\n */\n gatewayUrl: string;\n /**\n * Optional custom fetch implementation (useful for testing).\n */\n fetchImpl?: typeof fetch;\n}\n\ntype JsonBody = Record<string, unknown>;\n\n/**\n * Client for querying entity relationships from the Arke knowledge graph.\n *\n * All endpoints are public and do not require authentication.\n *\n * @example\n * ```typescript\n * const graph = new GraphClient({\n * gatewayUrl: 'https://gateway.arke.institute',\n * });\n *\n * // Get entity by ID\n * const entity = await graph.getEntity('uuid-123');\n *\n * // Find entities by code\n * const results = await graph.queryByCode('person_john');\n *\n * // Get entities with relationships from a PI\n * const entities = await graph.getEntitiesWithRelationships('01K75HQQXNTDG7BBP7PS9AWYAN');\n *\n * // Find paths between entities\n * const paths = await graph.findPaths(['uuid-1'], ['uuid-2'], { max_depth: 4 });\n * ```\n */\nexport class GraphClient {\n private baseUrl: string;\n private fetchImpl: typeof fetch;\n\n constructor(config: GraphClientConfig) {\n this.baseUrl = config.gatewayUrl.replace(/\\/$/, '');\n this.fetchImpl = config.fetchImpl ?? fetch;\n }\n\n // ---------------------------------------------------------------------------\n // Request helpers\n // ---------------------------------------------------------------------------\n\n private buildUrl(path: string, query?: Record<string, string | number | boolean | undefined>) {\n const url = new URL(`${this.baseUrl}${path}`);\n if (query) {\n Object.entries(query).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n });\n }\n return url.toString();\n }\n\n private async request<T>(\n path: string,\n options: RequestInit & {\n query?: Record<string, string | number | boolean | undefined>;\n } = {}\n ): Promise<T> {\n const url = this.buildUrl(path, options.query);\n const headers = new Headers({ 'Content-Type': 'application/json' });\n if (options.headers) {\n Object.entries(options.headers).forEach(([k, v]) => {\n if (v !== undefined) headers.set(k, v as string);\n });\n }\n\n let response: Response;\n try {\n response = await this.fetchImpl(url, { ...options, headers });\n } catch (err) {\n throw new NetworkError(\n err instanceof Error ? err.message : 'Network request failed'\n );\n }\n\n if (response.ok) {\n const contentType = response.headers.get('content-type') || '';\n if (contentType.includes('application/json')) {\n return (await response.json()) as T;\n }\n return (await response.text()) as unknown as T;\n }\n\n let body: unknown;\n const text = await response.text();\n try {\n body = JSON.parse(text);\n } catch {\n body = text;\n }\n\n // Handle 404 specifically\n if (response.status === 404) {\n throw new GraphError(\n (body as JsonBody)?.message as string || 'Not found',\n 'NOT_FOUND',\n body\n );\n }\n\n const message =\n (body as JsonBody)?.error && typeof (body as JsonBody).error === 'string'\n ? ((body as JsonBody).error as string)\n : (body as JsonBody)?.message && typeof (body as JsonBody).message === 'string'\n ? ((body as JsonBody).message as string)\n : `Request failed with status ${response.status}`;\n\n throw new GraphError(message, 'HTTP_ERROR', {\n status: response.status,\n body,\n });\n }\n\n // ---------------------------------------------------------------------------\n // Entity Operations\n // ---------------------------------------------------------------------------\n\n /**\n * Get an entity by its canonical ID.\n *\n * @param canonicalId - Entity UUID\n * @returns Entity data\n * @throws GraphEntityNotFoundError if the entity doesn't exist\n *\n * @example\n * ```typescript\n * const entity = await graph.getEntity('uuid-123');\n * console.log('Entity:', entity.label, entity.type);\n * ```\n */\n async getEntity(canonicalId: string): Promise<GraphEntity> {\n const response = await this.request<{ found: boolean; entity?: GraphEntity }>(\n `/graphdb/entity/${encodeURIComponent(canonicalId)}`\n );\n\n if (!response.found || !response.entity) {\n throw new GraphEntityNotFoundError(canonicalId);\n }\n\n return response.entity;\n }\n\n /**\n * Check if an entity exists by its canonical ID.\n *\n * @param canonicalId - Entity UUID\n * @returns True if entity exists\n *\n * @example\n * ```typescript\n * if (await graph.entityExists('uuid-123')) {\n * console.log('Entity exists');\n * }\n * ```\n */\n async entityExists(canonicalId: string): Promise<boolean> {\n const response = await this.request<{ exists: boolean }>(\n `/graphdb/entity/exists/${encodeURIComponent(canonicalId)}`\n );\n return response.exists;\n }\n\n /**\n * Query entities by code with optional type filter.\n *\n * @param code - Entity code to search for\n * @param type - Optional entity type filter\n * @returns Matching entities\n *\n * @example\n * ```typescript\n * // Find by code\n * const entities = await graph.queryByCode('person_john');\n *\n * // With type filter\n * const people = await graph.queryByCode('john', 'person');\n * ```\n */\n async queryByCode(code: string, type?: string): Promise<GraphEntity[]> {\n const response = await this.request<EntityQueryResponse>(\n '/graphdb/entity/query',\n {\n method: 'POST',\n body: JSON.stringify({ code, type }),\n }\n );\n\n if (!response.found || !response.entity) {\n return [];\n }\n\n return [response.entity];\n }\n\n /**\n * Look up entities by code across all PIs.\n *\n * @param code - Entity code to search for\n * @param type - Optional entity type filter\n * @returns Matching entities\n *\n * @example\n * ```typescript\n * const entities = await graph.lookupByCode('alice_austen', 'person');\n * ```\n */\n async lookupByCode(code: string, type?: string): Promise<GraphEntity[]> {\n const response = await this.request<{ entities: GraphEntity[] }>(\n '/graphdb/entities/lookup-by-code',\n {\n method: 'POST',\n body: JSON.stringify({ code, type }),\n }\n );\n return response.entities || [];\n }\n\n // ---------------------------------------------------------------------------\n // PI-based Operations\n // ---------------------------------------------------------------------------\n\n /**\n * List entities from a specific PI or multiple PIs.\n *\n * @param pi - Single PI or array of PIs\n * @param options - Filter options\n * @returns Entities from the PI(s)\n *\n * @example\n * ```typescript\n * // From single PI\n * const entities = await graph.listEntitiesFromPi('01K75HQQXNTDG7BBP7PS9AWYAN');\n *\n * // With type filter\n * const people = await graph.listEntitiesFromPi('01K75HQQXNTDG7BBP7PS9AWYAN', { type: 'person' });\n *\n * // From multiple PIs\n * const all = await graph.listEntitiesFromPi(['pi-1', 'pi-2']);\n * ```\n */\n async listEntitiesFromPi(\n pi: string | string[],\n options: ListFromPiOptions = {}\n ): Promise<GraphEntity[]> {\n const pis = Array.isArray(pi) ? pi : [pi];\n const response = await this.request<{ entities: GraphEntity[] }>(\n '/graphdb/entities/list',\n {\n method: 'POST',\n body: JSON.stringify({\n pis,\n type: options.type,\n }),\n }\n );\n return response.entities || [];\n }\n\n /**\n * Get entities with their relationships from a PI.\n *\n * This is an optimized query that returns entities along with all their\n * relationship data in a single request.\n *\n * @param pi - Persistent Identifier\n * @param type - Optional entity type filter\n * @returns Entities with relationships\n *\n * @example\n * ```typescript\n * const entities = await graph.getEntitiesWithRelationships('01K75HQQXNTDG7BBP7PS9AWYAN');\n * entities.forEach(e => {\n * console.log(`${e.label} has ${e.relationships.length} relationships`);\n * });\n * ```\n */\n async getEntitiesWithRelationships(\n pi: string,\n type?: string\n ): Promise<EntityWithRelationships[]> {\n const response = await this.request<EntitiesWithRelationshipsResponse>(\n '/graphdb/pi/entities-with-relationships',\n {\n method: 'POST',\n body: JSON.stringify({ pi, type }),\n }\n );\n return response.entities || [];\n }\n\n /**\n * Get the lineage (ancestors and/or descendants) of a PI.\n *\n * @param pi - Source PI\n * @param direction - 'ancestors', 'descendants', or 'both'\n * @returns Lineage data\n *\n * @example\n * ```typescript\n * // Get ancestors\n * const lineage = await graph.getLineage('01K75HQQXNTDG7BBP7PS9AWYAN', 'ancestors');\n *\n * // Get both directions\n * const full = await graph.getLineage('01K75HQQXNTDG7BBP7PS9AWYAN', 'both');\n * ```\n */\n async getLineage(\n pi: string,\n direction: 'ancestors' | 'descendants' | 'both' = 'both',\n maxHops: number = 10\n ): Promise<LineageResponse> {\n return this.request<LineageResponse>('/graphdb/pi/lineage', {\n method: 'POST',\n body: JSON.stringify({ sourcePi: pi, direction, maxHops }),\n });\n }\n\n // ---------------------------------------------------------------------------\n // Relationship Operations\n // ---------------------------------------------------------------------------\n\n /**\n * Get all relationships for an entity.\n *\n * @param canonicalId - Entity UUID\n * @returns Array of relationships\n *\n * @example\n * ```typescript\n * const relationships = await graph.getRelationships('uuid-123');\n * relationships.forEach(r => {\n * console.log(`${r.direction}: ${r.predicate} -> ${r.target_label}`);\n * });\n * ```\n */\n async getRelationships(canonicalId: string): Promise<Relationship[]> {\n const response = await this.request<{\n found: boolean;\n canonical_id?: string;\n relationships?: Array<{\n direction: 'outgoing' | 'incoming';\n predicate: string;\n target_id: string;\n target_code?: string;\n target_label: string;\n target_type: string;\n properties?: Record<string, unknown>;\n source_pi?: string;\n created_at?: string;\n }>;\n }>(`/graphdb/relationships/${encodeURIComponent(canonicalId)}`);\n\n if (!response.found || !response.relationships) {\n return [];\n }\n\n return response.relationships.map(rel => ({\n direction: rel.direction,\n predicate: rel.predicate,\n target_id: rel.target_id,\n target_code: rel.target_code || '',\n target_label: rel.target_label,\n target_type: rel.target_type,\n properties: rel.properties,\n source_pi: rel.source_pi,\n created_at: rel.created_at,\n }));\n }\n\n // ---------------------------------------------------------------------------\n // Path Finding\n // ---------------------------------------------------------------------------\n\n /**\n * Find shortest paths between sets of entities.\n *\n * @param sourceIds - Starting entity IDs\n * @param targetIds - Target entity IDs\n * @param options - Path finding options\n * @returns Found paths\n *\n * @example\n * ```typescript\n * const paths = await graph.findPaths(\n * ['uuid-alice'],\n * ['uuid-bob'],\n * { max_depth: 4, direction: 'both' }\n * );\n *\n * paths.forEach(path => {\n * console.log(`Path of length ${path.length}:`);\n * path.edges.forEach(e => {\n * console.log(` ${e.subject_label} -[${e.predicate}]-> ${e.object_label}`);\n * });\n * });\n * ```\n */\n async findPaths(\n sourceIds: string[],\n targetIds: string[],\n options: PathOptions = {}\n ): Promise<Path[]> {\n const response = await this.request<PathsResponse>('/graphdb/paths/between', {\n method: 'POST',\n body: JSON.stringify({\n source_ids: sourceIds,\n target_ids: targetIds,\n max_depth: options.max_depth,\n direction: options.direction,\n limit: options.limit,\n }),\n });\n return response.paths || [];\n }\n\n /**\n * Find entities of a specific type reachable from starting entities.\n *\n * @param startIds - Starting entity IDs\n * @param targetType - Type of entities to find\n * @param options - Search options\n * @returns Reachable entities of the specified type\n *\n * @example\n * ```typescript\n * // Find all people reachable from an event\n * const people = await graph.findReachable(\n * ['uuid-event'],\n * 'person',\n * { max_depth: 3 }\n * );\n * ```\n */\n async findReachable(\n startIds: string[],\n targetType: string,\n options: ReachableOptions = {}\n ): Promise<GraphEntity[]> {\n const response = await this.request<{ entities: GraphEntity[] }>(\n '/graphdb/paths/reachable',\n {\n method: 'POST',\n body: JSON.stringify({\n start_ids: startIds,\n target_type: targetType,\n max_depth: options.max_depth,\n direction: options.direction,\n limit: options.limit,\n }),\n }\n );\n return response.entities || [];\n }\n\n /**\n * Check the health of the graph service.\n *\n * @returns Health status\n */\n async health(): Promise<{ status: string; service: string; version: string }> {\n return this.request('/graphdb/health', { method: 'GET' });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDO,SAAS,iBAAiB,OAAqB;AAEpD,MAAI,iBAAiB,cAAc;AACjC,WAAO;AAAA,EACT;AAGA,MAAI,iBAAiB,gBAAgB;AACnC,WAAO,MAAM,aAAa,MAAM,cAAc,MAAM;AAAA,EACtD;AAGA,MAAI,iBAAiB,aAAa;AAChC,QAAI,MAAM,YAAY;AACpB,aAAO,MAAM,cAAc,OAAO,MAAM,eAAe;AAAA,IACzD;AACA,WAAO;AAAA,EACT;AAGA,MAAI,MAAM,SAAS,gBACf,MAAM,SAAS,eACf,MAAM,SAAS,eACf,MAAM,SAAS,gBAAgB;AACjC,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AApFA,IAIa,gBAYA,aAaA,iBAQA,cAQA;AA7Cb;AAAA;AAAA;AAIO,IAAM,iBAAN,cAA6B,MAAM;AAAA,MACxC,YACE,SACO,YACA,SACP;AACA,cAAM,OAAO;AAHN;AACA;AAGP,aAAK,OAAO;AACZ,cAAM,kBAAkB,MAAM,KAAK,WAAW;AAAA,MAChD;AAAA,IACF;AAEO,IAAM,cAAN,cAA0B,MAAM;AAAA,MACrC,YACE,SACO,UACA,YACA,OACP;AACA,cAAM,OAAO;AAJN;AACA;AACA;AAGP,aAAK,OAAO;AACZ,cAAM,kBAAkB,MAAM,KAAK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AC;AAAA,MACH;AAAA,IACF;AACA,WAAO,SAAS,YAAY,CAAC;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAwE;AAC5E,WAAO,KAAK,QAAQ,mBAAmB,EAAE,QAAQ,MAAM,CAAC;AAAA,EAC1D;AACF;","names":["path","path","fs","fs","dirPath","path","NetworkError","EntityNotFoundError","code","path","path","NodeScanner","BrowserScanner","fs","code","path","code","ValidationError","ValidationError","code","EntityNotFoundError","NetworkError","path","NetworkError","EntityNotFoundError","code","NetworkError","path","NetworkError","code"]}
@@ -0,0 +1,7 @@
1
+ export { g as ChangeRootPayload, h as ChangeRootResponse, b as Collection, c as CollectionDetails, d as CollectionRole, e as CollectionVisibility, C as CollectionsClient, a as CollectionsClientConfig, f as CreateCollectionPayload, I as Invitation, k as InvitationUser, l as InvitationsResponse, M as Member, i as MemberUser, j as MembersResponse, m as MyAccessResponse, n as MyCollectionsResponse, P as PaginatedCollections, o as PiPermissions, R as RegisterRootPayload, p as RootResponse, S as SuccessResponse, U as UpdateCollectionPayload } from './client-dAk3E64p.cjs';
2
+ export { CollectionsError } from './collections/index.cjs';
3
+ export { A as AddToCollectionOptions, c as ArkeUploader, B as BatchResult, C as CreateCollectionUploadOptions, b as CreateCollectionUploadResult, g as CustomPrompts, F as FileInfo, N as NetworkError, P as ProcessingConfig, S as ScanError, U as UploadClient, a as UploadClientConfig, h as UploadError, e as UploadOptions, f as UploadProgress, d as UploaderConfig, V as ValidationError, W as WorkerAPIError } from './errors-3L7IiHcr.cjs';
4
+ export { ASTNodeType, EdgeTypeDoc, EnrichedContent, Entity, EntryAST, EntryPointDoc, ExampleDoc, FilterAST, FilterTypeDoc, HopAST, LineageFilter, LineageMetadata, NaturalQueryOptions, NaturalQueryResult, ParameterDoc, ParseError, ParseResult, PathAST, PathQueryOptions, PathStep, QueryClient, QueryClientConfig, QueryError, QueryMetadata, QueryResult, QueryResultItem, SyntaxDocumentation, TranslateResult, TranslationInfo, VariableDepthDoc } from './query/index.cjs';
5
+ export { 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, P as PermissionError, R as RegeneratableComponent, j as ReprocessResult, k as ReprocessStatus } from './errors-B82BMmRP.cjs';
6
+ export { ComponentNotFoundError, ContentClient, ContentClientConfig, Entity as ContentEntity, ContentError, NetworkError as ContentNetworkError, ContentNotFoundError, EntityNotFoundError, EntitySummary, EntityVersion, ListOptions, ListResponse, ResolveResponse, VersionNotFoundError, VersionsOptions, VersionsResponse } from './content/index.cjs';
7
+ export { EntitiesWithRelationshipsResponse, EntityQueryResponse, EntityWithRelationships, GraphClient, GraphClientConfig, GraphEntity, GraphEntityNotFoundError, GraphError, NetworkError as GraphNetworkError, LineagePiEntry, LineageResponse, LineageResultSet, ListFromPiOptions, NoPathFoundError, Path, PathEdge, PathOptions, PathsResponse, ReachableOptions, Relationship } from './graph/index.cjs';