Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions packages/client-typescript/src/cli/rocketride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1452,8 +1452,7 @@ export class RocketRideCLI {
});

// Upload files - progress events come through event subscription
// Server handles concurrency automatically
const results = await this.client!.sendFiles(fileObjects, taskToken!);
const results = await this.client!.sendFiles(fileObjects, taskToken!, this.args.max_concurrent);

const endTime = Date.now();

Expand Down
26 changes: 16 additions & 10 deletions packages/client-typescript/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1371,9 +1371,11 @@ export class RocketRideClient extends DAPClient {
objinfo?: Record<string, unknown>;
mimetype?: string;
}>,
token: string
token: string,
maxConcurrent = 5
): Promise<UPLOAD_RESULT[]> {
const results: UPLOAD_RESULT[] = new Array(files.length);
const concurrency = Math.max(1, Math.floor(maxConcurrent));

/**
* Helper function to send upload events through the event system.
Expand Down Expand Up @@ -1483,16 +1485,20 @@ export class RocketRideClient extends DAPClient {
results[index] = finalResult;
};

// Create a promise for every file - let server handle queuing
const uploadPromises = files.map((fileData, index) =>
uploadFile(fileData, index).catch((err) => {
// Ensure errors don't kill the whole batch
console.error(`Upload failed for ${fileData.file.name}:`, err);
})
);
let nextIndex = 0;
const workers = Array.from({ length: Math.min(concurrency, files.length) }, async () => {
while (nextIndex < files.length) {
const index = nextIndex;
nextIndex += 1;
const fileData = files[index]!;
await uploadFile(fileData, index).catch((err) => {
// Ensure errors don't kill the whole batch
console.error(`Upload failed for ${fileData.file.name}:`, err);
});
}
});

// Wait for all uploads to complete
await Promise.all(uploadPromises);
await Promise.all(workers);

return results;
}
Expand Down
31 changes: 31 additions & 0 deletions packages/client-typescript/tests/RocketRideClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2213,6 +2213,37 @@ describe('RocketRideClient URI normalization', () => {
});
});

describe('RocketRideClient sendFiles concurrency', () => {
it('honors maxConcurrent', async () => {
const client = new RocketRideClient({ auth: 'test-key', uri: 'http://localhost:5565' });
let active = 0;
let maxActive = 0;

(client as any).pipe = jest.fn(async () => {
active += 1;
maxActive = Math.max(maxActive, active);
return {
open: jest.fn(async () => undefined),
write: jest.fn(async () => undefined),
close: jest.fn(async () => {
await new Promise((resolve) => setTimeout(resolve, 10));
active -= 1;
return undefined;
}),
};
});

const files = Array.from({ length: 5 }, (_, index) => ({
file: new File([`file-${index}`], `file-${index}.txt`, { type: 'text/plain' }),
}));

await client.sendFiles(files, 'task-token', 2);

expect((client as any).pipe).toHaveBeenCalledTimes(5);
expect(maxActive).toBeLessThanOrEqual(2);
});
});

export async function isServerAvailable(): Promise<boolean> {
try {
const client = new RocketRideClient({
Expand Down
2 changes: 1 addition & 1 deletion packages/shell-api/versions/v0.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2862,7 +2862,7 @@ export declare class RocketRideClient extends DAPClient {
file: File;
objinfo?: Record<string, unknown>;
mimetype?: string;
}>, token: string): Promise<UPLOAD_RESULT[]>;
}>, token: string, maxConcurrent?: number): Promise<UPLOAD_RESULT[]>;
/**
* Ask a question to RocketRide's AI and get an intelligent response.
*/
Expand Down
Loading