ag-common 0.0.780 → 0.0.781
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -143,17 +143,31 @@ const resolveGroundedUrl = (url) => __awaiter(void 0, void 0, void 0, function*
|
|
|
143
143
|
}
|
|
144
144
|
try {
|
|
145
145
|
(0, log_1.debug)('resolving grounded url', url);
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
// Fetch the grounded URL with redirect following disabled
|
|
147
|
+
const response = yield fetch(url, {
|
|
148
|
+
method: 'HEAD',
|
|
149
|
+
redirect: 'manual',
|
|
150
|
+
});
|
|
151
|
+
// Check for redirect responses (301, 302, 307, 308)
|
|
152
|
+
if (response.status >= 300 && response.status < 400) {
|
|
153
|
+
const location = response.headers.get('location') || response.headers.get('Location');
|
|
154
|
+
if (location) {
|
|
155
|
+
(0, log_1.debug)('resolved grounded url to', location);
|
|
156
|
+
return location;
|
|
157
|
+
}
|
|
151
158
|
}
|
|
152
|
-
|
|
159
|
+
// If no redirect, try a GET request to follow any JavaScript redirects
|
|
160
|
+
const fullResponse = yield fetch(url, {
|
|
161
|
+
redirect: 'follow',
|
|
162
|
+
});
|
|
163
|
+
const finalUrl = fullResponse.url;
|
|
164
|
+
(0, log_1.debug)('resolved grounded url via GET to', finalUrl);
|
|
165
|
+
return finalUrl;
|
|
153
166
|
}
|
|
154
|
-
catch (
|
|
155
|
-
(0, log_1.debug)('error resolving grounded url',
|
|
167
|
+
catch (error) {
|
|
168
|
+
(0, log_1.debug)('error resolving grounded url', error);
|
|
169
|
+
// Return original URL if resolution fails
|
|
170
|
+
return url;
|
|
156
171
|
}
|
|
157
|
-
return url;
|
|
158
172
|
});
|
|
159
173
|
exports.resolveGroundedUrl = resolveGroundedUrl;
|
package/package.json
CHANGED