Skip to content
Merged
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
9 changes: 4 additions & 5 deletions packages/sdk-typescript/src/daemon/DaemonClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1827,16 +1827,15 @@ export class DaemonClient {
opts: { offset?: number; maxBytes?: number } = {},
clientId?: string,
): Promise<DaemonWorkspaceFileBytes> {
const url = new URL(`${this.baseUrl}/file/bytes`);
url.searchParams.set('path', filePath);
const query = new URLSearchParams({ path: filePath });
if (opts.offset !== undefined) {
url.searchParams.set('offset', String(opts.offset));
query.set('offset', String(opts.offset));
}
if (opts.maxBytes !== undefined) {
url.searchParams.set('maxBytes', String(opts.maxBytes));
query.set('maxBytes', String(opts.maxBytes));
}
return await this.fetchWithTimeout(
url.toString(),
`${this.baseUrl}/file/bytes?${query.toString()}`,
{ headers: this.headers({}, clientId) },
async (res) => {
if (!res.ok) throw await this.failOnError(res, 'GET /file/bytes');
Expand Down
24 changes: 24 additions & 0 deletions packages/sdk-typescript/test/unit/DaemonClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,30 @@ describe('DaemonClient', () => {
);
});

it('reads raw bytes with a relative base URL', async () => {
const payload = {
kind: 'file_bytes' as const,
path: 'reports/report.pdf',
offset: 0,
sizeBytes: 2,
returnedBytes: 2,
truncated: false,
contentBase64: Buffer.from([1, 2]).toString('base64'),
};
const { fetch, calls } = recordingFetch(() => jsonResponse(200, payload));
const client = new DaemonClient({ baseUrl: '/daemon', fetch });

await expect(
client.readWorkspaceFileBytes('reports/report.pdf', {
offset: 0,
maxBytes: 2,
}),
).resolves.toEqual(payload);
expect(calls[0]?.url).toBe(
'/daemon/file/bytes?path=reports%2Freport.pdf&offset=0&maxBytes=2',
);
});

it('writes and edits files with JSON bodies and client identity', async () => {
const writeResult = {
kind: 'file_write',
Expand Down
Loading