Skip to content

Commit 4ae1207

Browse files
Validate normalized baseURL cannot be empty
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 29a8d6e commit 4ae1207

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

docs/tasks/streams.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,8 @@ Subsequent reconnect calls will retry stale inactive-state cleanup until it succ
654654
If `onError` is omitted, reconnect still returns `null` and continues without callback reporting.
655655

656656
`baseURL` supports optional path prefixes and trailing slashes; both trigger and stream URLs
657-
are normalized consistently, and surrounding whitespace is trimmed before normalization.
657+
are normalized consistently, surrounding whitespace is trimmed before normalization, and
658+
the resulting value must not be empty.
658659

659660
For richer TypeScript ergonomics in app code, `@trigger.dev/ai` also exports:
660661

packages/ai/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
- Added retry semantics for stale inactive reconnect cleanup on subsequent reconnect attempts.
2222
- Added consistent baseURL normalization for trigger and stream endpoints (including path prefixes and trailing slashes).
2323
- Added surrounding-whitespace trimming for `baseURL` before endpoint normalization.
24+
- Added explicit validation that `baseURL` is non-empty after normalization.

packages/ai/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ both cleanup steps (`set` inactive state and `delete`) even if one of them fails
160160
- `baseURL` supports optional path prefixes (for example reverse-proxy mounts).
161161
- Trailing slashes are normalized automatically before trigger/stream requests.
162162
- Surrounding whitespace is trimmed before normalization.
163+
- `baseURL` must not be empty after trimming/normalization.
163164

164165
## `ai.tool(...)` example
165166

packages/ai/src/chatTransport.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,17 @@ describe("TriggerChatTransport", function () {
609609
expect(observedStreamPath).toBe("/trimmed-prefix/realtime/v1/streams/run_trimmed_prefix/chat-stream");
610610
});
611611

612+
it("throws when baseURL is empty after trimming", function () {
613+
expect(function () {
614+
new TriggerChatTransport({
615+
task: "chat-task",
616+
accessToken: "pk_trigger",
617+
baseURL: " /// ",
618+
stream: "chat-stream",
619+
});
620+
}).toThrowError("baseURL must not be empty");
621+
});
622+
612623
it("combines path prefixes with run and stream URL encoding", async function () {
613624
let observedTriggerPath: string | undefined;
614625
let observedStreamPath: string | undefined;

packages/ai/src/chatTransport.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,13 @@ function resolvePayloadMapper<
460460
}
461461

462462
function normalizeBaseUrl(baseURL: string) {
463-
return baseURL.trim().replace(/\/+$/, "");
463+
const normalizedBaseUrl = baseURL.trim().replace(/\/+$/, "");
464+
465+
if (normalizedBaseUrl.length === 0) {
466+
throw new Error("baseURL must not be empty");
467+
}
468+
469+
return normalizedBaseUrl;
464470
}
465471

466472
function createTransportRequest<UI_MESSAGE extends UIMessage>(

0 commit comments

Comments
 (0)