fix(sdk): support relative artifact download URLs (#9734)

Co-authored-by: 钉萁 <dingqi.jww@alibaba-inc.com>
This commit is contained in:
ytahdn 2026-08-22 23:42:22 +00:00 committed by GitHub
parent db0519563d
commit 1007bcacfc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 5 deletions

View file

@ -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');

View file

@ -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',