@trigger.dev/sdk 0.0.0-chat-prerelease-20260520150857 → 0.0.0-chat-prerelease-20260521151946
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/v3/ai.d.ts +28 -12
- package/dist/commonjs/v3/ai.js +20 -27
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/createStartSessionAction.test.d.ts +1 -0
- package/dist/commonjs/v3/createStartSessionAction.test.js +113 -0
- package/dist/commonjs/v3/createStartSessionAction.test.js.map +1 -0
- package/dist/commonjs/v3/runs.d.ts +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai.d.ts +28 -12
- package/dist/esm/v3/ai.js +20 -27
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/createStartSessionAction.test.d.ts +1 -0
- package/dist/esm/v3/createStartSessionAction.test.js +111 -0
- package/dist/esm/v3/createStartSessionAction.test.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/package.json +2 -2
package/dist/commonjs/v3/ai.d.ts
CHANGED
|
@@ -2591,9 +2591,17 @@ export type CreateChatStartSessionActionOptions = {
|
|
|
2591
2591
|
/**
|
|
2592
2592
|
* Params for the function returned by {@link createChatStartSessionAction}.
|
|
2593
2593
|
*/
|
|
2594
|
-
export type ChatStartSessionParams = {
|
|
2594
|
+
export type ChatStartSessionParams<TChat extends AnyTask = AnyTask> = {
|
|
2595
2595
|
/** Conversation id (mapped to the Session's `externalId`). */
|
|
2596
2596
|
chatId: string;
|
|
2597
|
+
/**
|
|
2598
|
+
* Typed client data — folded into the first run's `payload.metadata` so
|
|
2599
|
+
* `onPreload`, `onChatStart`, etc. see the same `clientData` shape on the
|
|
2600
|
+
* first turn as subsequent turns get via the transport's `clientData`
|
|
2601
|
+
* option. Typed via the agent's `clientDataSchema` when the action is
|
|
2602
|
+
* parameterised with `createStartSessionAction<typeof myChat>(...)`.
|
|
2603
|
+
*/
|
|
2604
|
+
clientData?: InferChatClientData<TChat>;
|
|
2597
2605
|
/**
|
|
2598
2606
|
* Per-call trigger config. Shallow-merged over the action's default
|
|
2599
2607
|
* `triggerConfig`. `basePayload` is the customer's wire payload (for
|
|
@@ -2601,7 +2609,11 @@ export type ChatStartSessionParams = {
|
|
|
2601
2609
|
* which the runtime injects automatically).
|
|
2602
2610
|
*/
|
|
2603
2611
|
triggerConfig?: Partial<SessionTriggerConfig>;
|
|
2604
|
-
/**
|
|
2612
|
+
/**
|
|
2613
|
+
* Opaque session-level metadata stored on the Session row. Separate from
|
|
2614
|
+
* the per-turn `clientData` above. Use this when you want to attach
|
|
2615
|
+
* server-side metadata that doesn't go through the agent's `clientDataSchema`.
|
|
2616
|
+
*/
|
|
2605
2617
|
metadata?: Record<string, unknown>;
|
|
2606
2618
|
};
|
|
2607
2619
|
/**
|
|
@@ -2627,29 +2639,33 @@ export type ChatStartSessionResult = {
|
|
|
2627
2639
|
* Wrap in a Next.js server action (or any server-side handler) so the
|
|
2628
2640
|
* customer's secret key never crosses to the browser.
|
|
2629
2641
|
*
|
|
2642
|
+
* Parameterise the action with `<typeof yourChatAgent>` to type the
|
|
2643
|
+
* `clientData` field against your agent's `clientDataSchema`.
|
|
2644
|
+
*
|
|
2630
2645
|
* @example
|
|
2631
2646
|
* ```ts
|
|
2632
2647
|
* // actions.ts
|
|
2633
2648
|
* "use server";
|
|
2634
2649
|
* import { chat } from "@trigger.dev/sdk/ai";
|
|
2650
|
+
* import type { myChat } from "@/trigger/chat";
|
|
2635
2651
|
*
|
|
2636
|
-
* export const startChatSession = chat.createStartSessionAction(
|
|
2637
|
-
*
|
|
2638
|
-
* }
|
|
2652
|
+
* export const startChatSession = chat.createStartSessionAction<typeof myChat>(
|
|
2653
|
+
* "my-chat",
|
|
2654
|
+
* { triggerConfig: { machine: "small-1x" } }
|
|
2655
|
+
* );
|
|
2639
2656
|
* ```
|
|
2640
2657
|
*
|
|
2641
|
-
* Then in the browser:
|
|
2658
|
+
* Then in the browser, threading the typed `clientData` from the transport:
|
|
2642
2659
|
* ```tsx
|
|
2643
|
-
* const transport = useTriggerChatTransport({
|
|
2660
|
+
* const transport = useTriggerChatTransport<typeof myChat>({
|
|
2644
2661
|
* task: "my-chat",
|
|
2645
|
-
* accessToken:
|
|
2646
|
-
*
|
|
2647
|
-
*
|
|
2648
|
-
* },
|
|
2662
|
+
* accessToken: ({ chatId }) => mintChatAccessToken(chatId),
|
|
2663
|
+
* startSession: ({ chatId, clientData }) =>
|
|
2664
|
+
* startChatSession({ chatId, clientData }),
|
|
2649
2665
|
* });
|
|
2650
2666
|
* ```
|
|
2651
2667
|
*/
|
|
2652
|
-
declare function createChatStartSessionAction(taskId: string, options?: CreateChatStartSessionActionOptions): (params: ChatStartSessionParams) => Promise<ChatStartSessionResult>;
|
|
2668
|
+
declare function createChatStartSessionAction<TChat extends AnyTask = AnyTask>(taskId: string, options?: CreateChatStartSessionActionOptions): (params: ChatStartSessionParams<TChat>) => Promise<ChatStartSessionResult>;
|
|
2653
2669
|
export declare const chat: {
|
|
2654
2670
|
/** Create a chat agent. See {@link chatAgent}. */
|
|
2655
2671
|
agent: typeof chatAgent;
|
package/dist/commonjs/v3/ai.js
CHANGED
|
@@ -114,19 +114,6 @@ async function findLatestSessionInCursor(chatId) {
|
|
|
114
114
|
}
|
|
115
115
|
return latestCursor;
|
|
116
116
|
}
|
|
117
|
-
/**
|
|
118
|
-
* S3 key suffix for a session's snapshot blob. The webapp's presigned-URL
|
|
119
|
-
* routes prefix this with `packets/{projectRef}/{envSlug}/` server-side, so
|
|
120
|
-
* the final S3 key lands at
|
|
121
|
-
* `packets/{projectRef}/{envSlug}/sessions/{sessionId}/snapshot.json`.
|
|
122
|
-
*
|
|
123
|
-
* Stable per session: the friendlyId persists across `chat.requestUpgrade`
|
|
124
|
-
* continuations and idle-suspend restarts.
|
|
125
|
-
* @internal
|
|
126
|
-
*/
|
|
127
|
-
function snapshotFilename(sessionId) {
|
|
128
|
-
return `sessions/${sessionId}/snapshot.json`;
|
|
129
|
-
}
|
|
130
117
|
let readChatSnapshotImpl;
|
|
131
118
|
function __setReadChatSnapshotImplForTests(impl) {
|
|
132
119
|
readChatSnapshotImpl = impl;
|
|
@@ -155,7 +142,7 @@ async function readChatSnapshot(sessionId) {
|
|
|
155
142
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
156
143
|
let presignedUrl;
|
|
157
144
|
try {
|
|
158
|
-
const resp = await apiClient.
|
|
145
|
+
const resp = await apiClient.getChatSnapshotUrl(sessionId);
|
|
159
146
|
presignedUrl = resp.presignedUrl;
|
|
160
147
|
}
|
|
161
148
|
catch (error) {
|
|
@@ -230,7 +217,7 @@ async function writeChatSnapshot(sessionId, snapshot) {
|
|
|
230
217
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
231
218
|
let presignedUrl;
|
|
232
219
|
try {
|
|
233
|
-
const resp = await apiClient.
|
|
220
|
+
const resp = await apiClient.createChatSnapshotUploadUrl(sessionId);
|
|
234
221
|
presignedUrl = resp.presignedUrl;
|
|
235
222
|
}
|
|
236
223
|
catch (error) {
|
|
@@ -5778,25 +5765,29 @@ function chatLocal(options) {
|
|
|
5778
5765
|
* Wrap in a Next.js server action (or any server-side handler) so the
|
|
5779
5766
|
* customer's secret key never crosses to the browser.
|
|
5780
5767
|
*
|
|
5768
|
+
* Parameterise the action with `<typeof yourChatAgent>` to type the
|
|
5769
|
+
* `clientData` field against your agent's `clientDataSchema`.
|
|
5770
|
+
*
|
|
5781
5771
|
* @example
|
|
5782
5772
|
* ```ts
|
|
5783
5773
|
* // actions.ts
|
|
5784
5774
|
* "use server";
|
|
5785
5775
|
* import { chat } from "@trigger.dev/sdk/ai";
|
|
5776
|
+
* import type { myChat } from "@/trigger/chat";
|
|
5786
5777
|
*
|
|
5787
|
-
* export const startChatSession = chat.createStartSessionAction(
|
|
5788
|
-
*
|
|
5789
|
-
* }
|
|
5778
|
+
* export const startChatSession = chat.createStartSessionAction<typeof myChat>(
|
|
5779
|
+
* "my-chat",
|
|
5780
|
+
* { triggerConfig: { machine: "small-1x" } }
|
|
5781
|
+
* );
|
|
5790
5782
|
* ```
|
|
5791
5783
|
*
|
|
5792
|
-
* Then in the browser:
|
|
5784
|
+
* Then in the browser, threading the typed `clientData` from the transport:
|
|
5793
5785
|
* ```tsx
|
|
5794
|
-
* const transport = useTriggerChatTransport({
|
|
5786
|
+
* const transport = useTriggerChatTransport<typeof myChat>({
|
|
5795
5787
|
* task: "my-chat",
|
|
5796
|
-
* accessToken:
|
|
5797
|
-
*
|
|
5798
|
-
*
|
|
5799
|
-
* },
|
|
5788
|
+
* accessToken: ({ chatId }) => mintChatAccessToken(chatId),
|
|
5789
|
+
* startSession: ({ chatId, clientData }) =>
|
|
5790
|
+
* startChatSession({ chatId, clientData }),
|
|
5800
5791
|
* });
|
|
5801
5792
|
* ```
|
|
5802
5793
|
*/
|
|
@@ -5811,20 +5802,22 @@ function createChatStartSessionAction(taskId, options) {
|
|
|
5811
5802
|
// `onPreload` fires, the runtime opens its `.in` subscription, the
|
|
5812
5803
|
// first user message arrives moments later via `.in/append`.
|
|
5813
5804
|
//
|
|
5814
|
-
// `
|
|
5815
|
-
//
|
|
5816
|
-
//
|
|
5805
|
+
// `clientData` is folded into `basePayload.metadata` so the agent's
|
|
5806
|
+
// `clientDataSchema` validates on the very first turn against the same
|
|
5807
|
+
// shape per-turn `metadata` carries via the transport.
|
|
5817
5808
|
// Auto-tag every chat.agent run with `chat:{chatId}` so the dashboard /
|
|
5818
5809
|
// run-list filter by chat works without the customer having to wire it
|
|
5819
5810
|
// up. Mirrors the browser-mediated `TriggerChatTransport.doStart` path.
|
|
5820
5811
|
const userTags = params.triggerConfig?.tags ?? options?.triggerConfig?.tags ?? [];
|
|
5821
5812
|
const tags = [`chat:${params.chatId}`, ...userTags].slice(0, 5);
|
|
5813
|
+
const clientDataMetadata = params.clientData !== undefined ? { metadata: params.clientData } : {};
|
|
5822
5814
|
const triggerConfig = {
|
|
5823
5815
|
basePayload: {
|
|
5824
5816
|
messages: [],
|
|
5825
5817
|
trigger: "preload",
|
|
5826
5818
|
...(options?.triggerConfig?.basePayload ?? {}),
|
|
5827
5819
|
...(params.triggerConfig?.basePayload ?? {}),
|
|
5820
|
+
...clientDataMetadata,
|
|
5828
5821
|
chatId: params.chatId,
|
|
5829
5822
|
},
|
|
5830
5823
|
...(options?.triggerConfig?.machine || params.triggerConfig?.machine
|