Skip to content

Commit cf3acd1

Browse files
committed
fix(sdk): concurrency validation helpers live outside the task runtime module
triggerConcurrencyBody and validateConcurrencyLimitName move to a dependency-free module so the chat-server route-handler entrypoint stays lean instead of pulling the task runtime's import graph into customer bundles.
1 parent 51221f4 commit cf3acd1

4 files changed

Lines changed: 40 additions & 33 deletions

File tree

packages/trigger-sdk/src/v3/ai.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ import {
118118
sessions,
119119
type SessionSubscribeOptions,
120120
} from "./sessions.js";
121-
import { createTask, triggerConcurrencyBody } from "./shared.js";
121+
import { createTask } from "./shared.js";
122+
import { triggerConcurrencyBody } from "./concurrency-shared.js";
122123
import { markChatAgentRunForStreamsWarning } from "./streams.js";
123124
import { tracer } from "./tracer.js";
124125

packages/trigger-sdk/src/v3/chat-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import {
7272
import type { FinishReason, ModelMessage, Tool, UIMessage, UIMessageChunk } from "ai";
7373
import type { ChatInputChunk, ChatTaskWirePayload } from "./ai-shared.js";
7474
import { chatRunTags } from "./ai-shared.js";
75-
import { triggerConcurrencyBody } from "./shared.js";
75+
import { triggerConcurrencyBody } from "./concurrency-shared.js";
7676

7777
// `StreamTextResult` is defined locally rather than imported from `ai`: its
7878
// generic arity diverged (v6 `StreamTextResult<TOOLS, OUTPUT>`, v7
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Concurrency helpers with no runtime dependencies, importable from the lean
3+
* browser and route-handler entrypoints (chat-client, chat-server) without
4+
* pulling the task runtime's module graph into those bundles.
5+
*/
6+
7+
/**
8+
* Trigger-time named limits: strings only, like `queue`. They replace the task's
9+
* declared named limits for this run; the server resolves names to the run's gates.
10+
*/
11+
export function triggerConcurrencyBody(concurrency: string | string[] | undefined): {
12+
concurrency?: string[];
13+
} {
14+
if (!concurrency) {
15+
return {};
16+
}
17+
const limits = Array.isArray(concurrency) ? concurrency : [concurrency];
18+
if (limits.length > 2) {
19+
throw new Error("The concurrency option accepts at most two named limits.");
20+
}
21+
if (limits.some((name) => typeof name !== "string" || name.length === 0)) {
22+
throw new Error("The concurrency option takes limit names: non-empty strings.");
23+
}
24+
for (const name of limits) {
25+
validateConcurrencyLimitName(name);
26+
}
27+
return { concurrency: limits };
28+
}
29+
30+
export function validateConcurrencyLimitName(name: string): void {
31+
if (!/^[a-zA-Z0-9_-]{1,122}$/.test(name)) {
32+
throw new Error(
33+
`Concurrency limit "${name}": names are 1-122 characters using only letters, numbers, underscores and hyphens.`
34+
);
35+
}
36+
}

packages/trigger-sdk/src/v3/shared.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import {
9595
type ConcurrencyLimit,
9696
} from "@trigger.dev/core/v3";
9797
import { tracer } from "./tracer.js";
98+
import { triggerConcurrencyBody, validateConcurrencyLimitName } from "./concurrency-shared.js";
9899

99100
export type {
100101
AnyRunHandle,
@@ -213,29 +214,6 @@ function triggerQueueBody(
213214
return { queue: name ? { name } : undefined };
214215
}
215216

216-
/**
217-
* Trigger-time named limits: strings only, like `queue`. They replace the task's
218-
* declared named limits for this run; the server resolves names to the run's gates.
219-
*/
220-
export function triggerConcurrencyBody(concurrency: string | string[] | undefined): {
221-
concurrency?: string[];
222-
} {
223-
if (!concurrency) {
224-
return {};
225-
}
226-
const limits = Array.isArray(concurrency) ? concurrency : [concurrency];
227-
if (limits.length > 2) {
228-
throw new Error("The concurrency option accepts at most two named limits.");
229-
}
230-
if (limits.some((name) => typeof name !== "string" || name.length === 0)) {
231-
throw new Error("The concurrency option takes limit names: non-empty strings.");
232-
}
233-
for (const name of limits) {
234-
validateConcurrencyLimitName(name);
235-
}
236-
return { concurrency: limits };
237-
}
238-
239217
export function queue(options: QueueOptions): Queue {
240218
resourceCatalog.registerQueueMetadata(options);
241219

@@ -261,14 +239,6 @@ export function queue(options: QueueOptions): Queue {
261239
* });
262240
* ```
263241
*/
264-
function validateConcurrencyLimitName(name: string): void {
265-
if (!/^[a-zA-Z0-9_-]{1,122}$/.test(name)) {
266-
throw new Error(
267-
`Concurrency limit "${name}": names are 1-122 characters using only letters, numbers, underscores and hyphens.`
268-
);
269-
}
270-
}
271-
272242
export function concurrencyLimit(options: ConcurrencyLimitOptions): ConcurrencyLimit {
273243
validateConcurrencyLimitName(options.name);
274244

0 commit comments

Comments
 (0)