Skip to content

Commit e8781b2

Browse files
fix: do not use RN URL to construct url
1 parent 3b082d0 commit e8781b2

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

packages/ai/lib/requests/request.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,18 @@ export class RequestUrl {
6060
}
6161
return emulatorUrl;
6262
}
63-
const url = new URL(this.baseUrl); // Throws if the URL is invalid
64-
url.pathname = `/${this.apiVersion}/${this.modelPath}:${this.task}`;
65-
url.search = this.queryParams.toString();
66-
return url.toString();
63+
64+
// Manually construct URL to avoid React Native URL API issues
65+
let baseUrl = this.baseUrl;
66+
// Remove trailing slash if present
67+
if (baseUrl.endsWith('/')) {
68+
baseUrl = baseUrl.slice(0, -1);
69+
}
70+
71+
const pathname = `/${this.apiVersion}/${this.modelPath}:${this.task}`;
72+
const queryString = this.queryParams;
73+
74+
return `${baseUrl}${pathname}${queryString ? `?${queryString}` : ''}`;
6775
}
6876

6977
private get baseUrl(): string {
@@ -87,10 +95,10 @@ export class RequestUrl {
8795
}
8896
}
8997

90-
private get queryParams(): URLSearchParams {
91-
const params = new URLSearchParams();
98+
private get queryParams(): string {
99+
let params = '';
92100
if (this.stream) {
93-
params.set('alt', 'sse');
101+
params += 'alt=sse';
94102
}
95103

96104
return params;

0 commit comments

Comments
 (0)