Skip to content

Commit 19909ea

Browse files
Allow tuple header inputs in transport send options
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent dc48c61 commit 19909ea

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ describe("TriggerChatTransport", function () {
374374
messageId: undefined,
375375
messages: [],
376376
abortSignal: undefined,
377-
headers: [["x-tuple-header", "tuple-value"]] as unknown as Record<string, string>,
377+
headers: [["x-tuple-header", "tuple-value"]],
378378
});
379379

380380
const chunks = await readChunks(stream);

packages/ai/src/chatTransport.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ type TriggerTaskRequestBody = {
6262
options?: TriggerTaskRequestOptions;
6363
};
6464

65+
type TriggerChatRequestOptionsWithTupleHeaders = Omit<ChatRequestOptions, "headers"> & {
66+
headers?:
67+
| ChatRequestOptions["headers"]
68+
| Array<[string, string]>;
69+
};
70+
6571
type TriggerChatTransportCommonOptions<
6672
UI_MESSAGE extends UIMessage = UIMessage,
6773
> = {
@@ -158,7 +164,7 @@ export class TriggerChatTransport<
158164
messageId: string | undefined;
159165
messages: UI_MESSAGE[];
160166
abortSignal: AbortSignal | undefined;
161-
} & ChatRequestOptions
167+
} & TriggerChatRequestOptionsWithTupleHeaders
162168
): Promise<ReadableStream<UIMessageChunk>> {
163169
const transportRequest = createTransportRequest<UI_MESSAGE>(options);
164170
const payload = await this.payloadMapper(transportRequest);
@@ -342,7 +348,7 @@ function createTransportRequest<UI_MESSAGE extends UIMessage>(
342348
messageId: string | undefined;
343349
messages: UI_MESSAGE[];
344350
abortSignal: AbortSignal | undefined;
345-
} & ChatRequestOptions
351+
} & TriggerChatRequestOptionsWithTupleHeaders
346352
): TriggerChatTransportRequest<UI_MESSAGE> {
347353
return {
348354
chatId: options.chatId,

packages/ai/src/chatTransport.types.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,15 @@ it("accepts typed stream definition objects", function () {
122122

123123
expectTypeOf(transport).toBeObject();
124124
});
125+
126+
it("accepts tuple-style headers in sendMessages options", function () {
127+
const transport = new TriggerChatTransport({
128+
task: "ai-chat",
129+
accessToken: "pk_test",
130+
});
131+
132+
type SendMessagesParams = Parameters<typeof transport.sendMessages>[0];
133+
const tupleHeaders: SendMessagesParams["headers"] = [["x-header", "x-value"]];
134+
expectTypeOf(transport.sendMessages).toBeFunction();
135+
void tupleHeaders;
136+
});

0 commit comments

Comments
 (0)