mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-08-26 17:13:32 +00:00
fix(sdk): support relative artifact download URLs (#9734)
Co-authored-by: 钉萁 <dingqi.jww@alibaba-inc.com>
This commit is contained in:
parent
db0519563d
commit
1007bcacfc
2 changed files with 28 additions and 5 deletions
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue