Validate normalized baseURL cannot be empty
Co-authored-by: Eric Allam <eric@trigger.dev>
This commit is contained in:
@@ -654,7 +654,8 @@ Subsequent reconnect calls will retry stale inactive-state cleanup until it succ
|
||||
If `onError` is omitted, reconnect still returns `null` and continues without callback reporting.
|
||||
|
||||
`baseURL` supports optional path prefixes and trailing slashes; both trigger and stream URLs
|
||||
are normalized consistently, and surrounding whitespace is trimmed before normalization.
|
||||
are normalized consistently, surrounding whitespace is trimmed before normalization, and
|
||||
the resulting value must not be empty.
|
||||
|
||||
For richer TypeScript ergonomics in app code, `@trigger.dev/ai` also exports:
|
||||
|
||||
|
||||
@@ -21,3 +21,4 @@
|
||||
- Added retry semantics for stale inactive reconnect cleanup on subsequent reconnect attempts.
|
||||
- Added consistent baseURL normalization for trigger and stream endpoints (including path prefixes and trailing slashes).
|
||||
- Added surrounding-whitespace trimming for `baseURL` before endpoint normalization.
|
||||
- Added explicit validation that `baseURL` is non-empty after normalization.
|
||||
|
||||
@@ -160,6 +160,7 @@ both cleanup steps (`set` inactive state and `delete`) even if one of them fails
|
||||
- `baseURL` supports optional path prefixes (for example reverse-proxy mounts).
|
||||
- Trailing slashes are normalized automatically before trigger/stream requests.
|
||||
- Surrounding whitespace is trimmed before normalization.
|
||||
- `baseURL` must not be empty after trimming/normalization.
|
||||
|
||||
## `ai.tool(...)` example
|
||||
|
||||
|
||||
@@ -609,6 +609,17 @@ describe("TriggerChatTransport", function () {
|
||||
expect(observedStreamPath).toBe("/trimmed-prefix/realtime/v1/streams/run_trimmed_prefix/chat-stream");
|
||||
});
|
||||
|
||||
it("throws when baseURL is empty after trimming", function () {
|
||||
expect(function () {
|
||||
new TriggerChatTransport({
|
||||
task: "chat-task",
|
||||
accessToken: "pk_trigger",
|
||||
baseURL: " /// ",
|
||||
stream: "chat-stream",
|
||||
});
|
||||
}).toThrowError("baseURL must not be empty");
|
||||
});
|
||||
|
||||
it("combines path prefixes with run and stream URL encoding", async function () {
|
||||
let observedTriggerPath: string | undefined;
|
||||
let observedStreamPath: string | undefined;
|
||||
|
||||
@@ -460,7 +460,13 @@ function resolvePayloadMapper<
|
||||
}
|
||||
|
||||
function normalizeBaseUrl(baseURL: string) {
|
||||
return baseURL.trim().replace(/\/+$/, "");
|
||||
const normalizedBaseUrl = baseURL.trim().replace(/\/+$/, "");
|
||||
|
||||
if (normalizedBaseUrl.length === 0) {
|
||||
throw new Error("baseURL must not be empty");
|
||||
}
|
||||
|
||||
return normalizedBaseUrl;
|
||||
}
|
||||
|
||||
function createTransportRequest<UI_MESSAGE extends UIMessage>(
|
||||
|
||||
Reference in New Issue
Block a user