Validate baseURL is an absolute URL

Co-authored-by: Eric Allam <eric@trigger.dev>
This commit is contained in:
Cursor Agent
2026-02-15 04:20:17 +00:00
parent edeed64296
commit 3a9047b59b
5 changed files with 42 additions and 1 deletions
+1 -1
View File
@@ -655,7 +655,7 @@ If `onError` is omitted, reconnect still returns `null` and continues without ca
`baseURL` supports optional path prefixes and trailing slashes; both trigger and stream URLs
are normalized consistently, surrounding whitespace is trimmed before normalization, and
the resulting value must not be empty.
the resulting value must not be empty. The value must also be a valid absolute URL.
For richer TypeScript ergonomics in app code, `@trigger.dev/ai` also exports:
+1
View File
@@ -22,3 +22,4 @@
- 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.
- Added explicit validation that `baseURL` is a valid absolute URL.
+1
View File
@@ -161,6 +161,7 @@ both cleanup steps (`set` inactive state and `delete`) even if one of them fails
- Trailing slashes are normalized automatically before trigger/stream requests.
- Surrounding whitespace is trimmed before normalization.
- `baseURL` must not be empty after trimming/normalization.
- `baseURL` must be a valid absolute URL.
## `ai.tool(...)` example
+33
View File
@@ -620,6 +620,28 @@ describe("TriggerChatTransport", function () {
}).toThrowError("baseURL must not be empty");
});
it("throws when baseURL is not a valid absolute URL", function () {
expect(function () {
new TriggerChatTransport({
task: "chat-task",
accessToken: "pk_trigger",
baseURL: "not-a-valid-url",
stream: "chat-stream",
});
}).toThrowError("baseURL must be a valid absolute URL");
});
it("throws when baseURL is a relative path", function () {
expect(function () {
new TriggerChatTransport({
task: "chat-task",
accessToken: "pk_trigger",
baseURL: "/relative/path",
stream: "chat-stream",
});
}).toThrowError("baseURL must be a valid absolute URL");
});
it("combines path prefixes with run and stream URL encoding", async function () {
let observedTriggerPath: string | undefined;
let observedStreamPath: string | undefined;
@@ -2745,6 +2767,17 @@ describe("TriggerChatTransport", function () {
}).toThrowError("baseURL must not be empty");
});
it("throws from factory when baseURL is not a valid absolute URL", function () {
expect(function () {
createTriggerChatTransport({
task: "chat-task",
accessToken: "pk_trigger",
baseURL: "invalid-base-url",
stream: "chat-stream",
});
}).toThrowError("baseURL must be a valid absolute URL");
});
it("continues streaming when onTriggeredRun callback throws", async function () {
let callbackCalled = false;
const errors: TriggerChatTransportError[] = [];
+6
View File
@@ -466,6 +466,12 @@ function normalizeBaseUrl(baseURL: string) {
throw new Error("baseURL must not be empty");
}
try {
new URL(normalizedBaseUrl);
} catch {
throw new Error("baseURL must be a valid absolute URL");
}
return normalizedBaseUrl;
}