File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,23 +13,32 @@ export function generateSessionHeaders(
1313 payload : ChatCompletionsPayload ,
1414 mode : HeaderMode ,
1515) : RequestHeaders {
16+ const initiatorMap : Record <
17+ HeaderMode ,
18+ ( payload : ChatCompletionsPayload ) => "user" | "agent"
19+ > = {
20+ savings : getSavingsInitiator ,
21+ compatible : getCompatibleInitiator ,
22+ }
1623 return {
17- "X-Initiator" :
18- mode === "savings" ?
19- getSavingsInitiator ( payload )
20- : getCompatibleInitiator ( payload ) ,
24+ "X-Initiator" : initiatorMap [ mode ] ( payload ) ,
2125 }
2226}
2327
28+ /**
29+ * Check if a message role is an agent role
30+ */
31+ function isAgentRole ( role : string ) : boolean {
32+ return [ "assistant" , "tool" ] . includes ( role )
33+ }
34+
2435/**
2536 * Savings mode: if any message is assistant or tool, then it is agent
2637 */
2738function getSavingsInitiator (
2839 payload : ChatCompletionsPayload ,
2940) : "user" | "agent" {
30- return (
31- payload . messages . some ( ( msg ) => [ "assistant" , "tool" ] . includes ( msg . role ) )
32- ) ?
41+ return payload . messages . some ( ( msg ) => isAgentRole ( msg . role ) ) ?
3342 "agent"
3443 : "user"
3544}
You can’t perform that action at this time.
0 commit comments