-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(sdk): chat sessions accept concurrencyKey and trigger-time named limits #4906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
matt-aitken
wants to merge
8
commits into
docs/queue-concurrency-features
from
feat/chat-session-concurrency
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bf2f7ad
feat(sdk,core,webapp): chat sessions accept concurrencyKey and trigge…
matt-aitken 17c7f68
fix(sdk): concurrency validation helpers live outside the task runtim…
matt-aitken 5d16aca
fix(core,sdk): bad limit names are rejected before the session row pe…
matt-aitken d8ca1ef
fix(core,webapp): every session config writer validates before persis…
matt-aitken 05e2cd2
fix(webapp): a broken webhook template only fails session creation, n…
matt-aitken 123b60a
fix(sdk): an empty or null concurrency value is rejected, not silentl…
matt-aitken 27b01b2
fix(sdk): a per-call null concurrency is rejected instead of inheriti…
matt-aitken d511299
docs(sdk): the chat concurrency changeset names both example key types
matt-aitken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| "@trigger.dev/sdk": patch | ||
| "@trigger.dev/core": patch | ||
| --- | ||
|
|
||
| Chat agents can now scope concurrency per session. Pass `concurrencyKey` (for example, your chat ID or tenant ID) and trigger-time named limits via `triggerConfig.concurrency` when starting a chat session, from `chat.createStartSessionAction`, the `AgentChat` client, or a handover. Keys are never defaulted, so a session without one shares the task's keyless pool. | ||
|
|
||
| ```ts | ||
| const start = chat.createStartSessionAction("support-chat", { | ||
| triggerConfig: { concurrencyKey: user.id }, | ||
| }); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * Concurrency helpers with no runtime dependencies, importable from the lean | ||
| * browser and route-handler entrypoints (chat-client, chat-server) without | ||
| * pulling the task runtime's module graph into those bundles. | ||
| */ | ||
|
|
||
| /** | ||
| * Trigger-time named limits: strings only, like `queue`. They replace the task's | ||
| * declared named limits for this run; the server resolves names to the run's gates. | ||
| */ | ||
| export function triggerConcurrencyBody(concurrency: string | string[] | undefined): { | ||
| concurrency?: string[]; | ||
| } { | ||
| if (concurrency === undefined) { | ||
| return {}; | ||
| } | ||
| const limits = Array.isArray(concurrency) ? concurrency : [concurrency]; | ||
| if (limits.length > 2) { | ||
| throw new Error("The concurrency option accepts at most two named limits."); | ||
| } | ||
| if (limits.some((name) => typeof name !== "string" || name.length === 0)) { | ||
| throw new Error("The concurrency option takes limit names: non-empty strings."); | ||
| } | ||
| for (const name of limits) { | ||
| validateConcurrencyLimitName(name); | ||
| } | ||
| return { concurrency: limits }; | ||
| } | ||
|
|
||
| export function validateConcurrencyLimitName(name: string): void { | ||
| if (!/^[a-zA-Z0-9_-]{1,122}$/.test(name)) { | ||
| throw new Error( | ||
| `Concurrency limit "${name}": names are 1-122 characters using only letters, numbers, underscores and hyphens.` | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.