Skip to content
This repository was archived by the owner on Aug 14, 2025. It is now read-only.

Commit e2797ae

Browse files
chore: make some internal functions async
1 parent d7a07d2 commit e2797ae

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/core.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ export abstract class APIClient {
313313
return null;
314314
}
315315

316-
buildRequest<Req>(
316+
async buildRequest<Req>(
317317
inputOptions: FinalRequestOptions<Req>,
318318
{ retryCount = 0 }: { retryCount?: number } = {},
319-
): { req: RequestInit; url: string; timeout: number } {
319+
): Promise<{ req: RequestInit; url: string; timeout: number }> {
320320
const options = { ...inputOptions };
321321
const { method, path, query, defaultBaseURL, headers: headers = {} } = options;
322322

@@ -464,7 +464,9 @@ export abstract class APIClient {
464464

465465
await this.prepareOptions(options);
466466

467-
const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining });
467+
const { req, url, timeout } = await this.buildRequest(options, {
468+
retryCount: maxRetries - retriesRemaining,
469+
});
468470

469471
await this.prepareRequest(req, { url, options });
470472

tests/index.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ describe('instantiate client', () => {
2525
defaultHeaders: { 'X-My-Default-Header': '2' },
2626
});
2727

28-
test('they are used in the request', () => {
29-
const { req } = client.buildRequest({ path: '/foo', method: 'post' });
28+
test('they are used in the request', async () => {
29+
const { req } = await client.buildRequest({ path: '/foo', method: 'post' });
3030
expect((req.headers as Headers)['x-my-default-header']).toEqual('2');
3131
});
3232

33-
test('can ignore `undefined` and leave the default', () => {
34-
const { req } = client.buildRequest({
33+
test('can ignore `undefined` and leave the default', async () => {
34+
const { req } = await client.buildRequest({
3535
path: '/foo',
3636
method: 'post',
3737
headers: { 'X-My-Default-Header': undefined },
3838
});
3939
expect((req.headers as Headers)['x-my-default-header']).toEqual('2');
4040
});
4141

42-
test('can be removed with `null`', () => {
43-
const { req } = client.buildRequest({
42+
test('can be removed with `null`', async () => {
43+
const { req } = await client.buildRequest({
4444
path: '/foo',
4545
method: 'post',
4646
headers: { 'X-My-Default-Header': null },
@@ -209,20 +209,20 @@ describe('request building', () => {
209209
const client = new LlamaStackClient({});
210210

211211
describe('Content-Length', () => {
212-
test('handles multi-byte characters', () => {
213-
const { req } = client.buildRequest({ path: '/foo', method: 'post', body: { value: '—' } });
212+
test('handles multi-byte characters', async () => {
213+
const { req } = await client.buildRequest({ path: '/foo', method: 'post', body: { value: '—' } });
214214
expect((req.headers as Record<string, string>)['content-length']).toEqual('20');
215215
});
216216

217-
test('handles standard characters', () => {
218-
const { req } = client.buildRequest({ path: '/foo', method: 'post', body: { value: 'hello' } });
217+
test('handles standard characters', async () => {
218+
const { req } = await client.buildRequest({ path: '/foo', method: 'post', body: { value: 'hello' } });
219219
expect((req.headers as Record<string, string>)['content-length']).toEqual('22');
220220
});
221221
});
222222

223223
describe('custom headers', () => {
224-
test('handles undefined', () => {
225-
const { req } = client.buildRequest({
224+
test('handles undefined', async () => {
225+
const { req } = await client.buildRequest({
226226
path: '/foo',
227227
method: 'post',
228228
body: { value: 'hello' },

0 commit comments

Comments
 (0)