Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion apps/mcp-server/src/services/ILighthouseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
*/

import { UploadResult, DownloadResult, AccessCondition, Dataset } from "@lighthouse-tooling/types";
import { EnhancedAccessCondition } from "@lighthouse-tooling/sdk-wrapper";
import {
EnhancedAccessCondition,
BatchUploadOptions,
BatchDownloadOptions,
BatchOperationResult,
BatchDownloadFileResult,
FileInfo,
} from "@lighthouse-tooling/sdk-wrapper";

export interface StoredFile {
cid: string;
Expand Down Expand Up @@ -150,4 +157,20 @@ export interface ILighthouseService {
success: boolean;
error?: string;
}>;

/**
* Batch upload multiple files with configurable concurrency
*/
batchUploadFiles?(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both batch methods are marked as optional (?) on the interface, which forces every consumer to do a runtime check (if(!this.service.batchUploadFiles)). Since LighthouseService always implements them, how about we consider making them required to simplify call sites and get compile-time guarantees?

filePaths: string[],
options?: BatchUploadOptions,
): Promise<BatchOperationResult<FileInfo>>;

/**
* Batch download multiple files by CID with configurable concurrency
*/
batchDownloadFiles?(
cids: string[],
options?: BatchDownloadOptions,
): Promise<BatchOperationResult<BatchDownloadFileResult>>;
}
113 changes: 112 additions & 1 deletion apps/mcp-server/src/services/LighthouseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
* Real Lighthouse Service - Uses the unified SDK wrapper for actual Lighthouse operations
*/

import { LighthouseAISDK, EnhancedAccessCondition } from "@lighthouse-tooling/sdk-wrapper";
import {
LighthouseAISDK,
EnhancedAccessCondition,
BatchUploadOptions,
BatchDownloadOptions,
BatchOperationResult,
BatchDownloadFileResult,
BatchUploadInput,
BatchDownloadInput,
FileInfo,
} from "@lighthouse-tooling/sdk-wrapper";
import { UploadResult, DownloadResult, AccessCondition, Dataset } from "@lighthouse-tooling/types";
import { Logger } from "@lighthouse-tooling/shared";
import { ILighthouseService, StoredFile } from "./ILighthouseService.js";
Expand Down Expand Up @@ -879,6 +889,107 @@ export class LighthouseService implements ILighthouseService {
}
}

/**
* Batch upload multiple files with configurable concurrency
*/
async batchUploadFiles(
filePaths: string[],
options?: BatchUploadOptions,
): Promise<BatchOperationResult<FileInfo>> {
const startTime = Date.now();

try {
this.logger.info("Starting batch upload", {
fileCount: filePaths.length,
concurrency: options?.concurrency || 3,
});

// Convert string paths to BatchUploadInput objects
const inputs: BatchUploadInput[] = filePaths.map((filePath) => ({
filePath,
}));

const result = await this.sdk.batchUpload(inputs, options);

// Store successful uploads in cache and database
for (const fileResult of result.results) {
if (fileResult.success && fileResult.data) {
const storedFile: StoredFile = {
cid: fileResult.data.hash,
filePath: fileResult.data.name,
size: fileResult.data.size,
encrypted: fileResult.data.encrypted,
accessConditions: options?.accessConditions,
tags: options?.tags,
uploadedAt: fileResult.data.uploadedAt,
pinned: true,
hash: fileResult.data.hash,
};

this.storage.saveFile(storedFile);
this.fileCache.set(fileResult.data.hash, storedFile);
}
}

const executionTime = Date.now() - startTime;
this.logger.info("Batch upload completed", {
total: result.total,
successful: result.successful,
failed: result.failed,
successRate: result.successRate,
executionTime,
});

return result;
} catch (error) {
this.logger.error("Batch upload failed", error as Error, {
fileCount: filePaths.length,
});
throw error;
}
}

/**
* Batch download multiple files by CID with configurable concurrency
*/
async batchDownloadFiles(
cids: string[],
options?: BatchDownloadOptions,
): Promise<BatchOperationResult<BatchDownloadFileResult>> {
const startTime = Date.now();

try {
this.logger.info("Starting batch download", {
cidCount: cids.length,
concurrency: options?.concurrency || 3,
outputDir: options?.outputDir,
});

// Convert string CIDs to BatchDownloadInput objects
const inputs: BatchDownloadInput[] = cids.map((cid) => ({
cid,
}));

const result = await this.sdk.batchDownload(inputs, options);

const executionTime = Date.now() - startTime;
this.logger.info("Batch download completed", {
total: result.total,
successful: result.successful,
failed: result.failed,
successRate: result.successRate,
executionTime,
});

return result;
} catch (error) {
this.logger.error("Batch download failed", error as Error, {
cidCount: cids.length,
});
throw error;
}
}

/**
* Cleanup resources
*/
Expand Down
Loading
Loading