-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathshared-utils.ts
More file actions
31 lines (27 loc) · 673 Bytes
/
shared-utils.ts
File metadata and controls
31 lines (27 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { Logger } from "./logger"
import { SessionState, WithParts } from "./state"
export const isMessageCompacted = (
state: SessionState,
msg: WithParts
): boolean => {
return msg.info.time.created < state.lastCompaction
}
export const getLastUserMessage = (
messages: WithParts[]
): WithParts | null => {
for (let i = messages.length - 1; i >= 0; i--) {
const msg = messages[i]
if (msg.info.role === 'user') {
return msg
}
}
return null
}
export const checkForCompaction = (
state: SessionState,
messages: WithParts[],
logger: Logger
): void => {
for (const msg of messages) {
}
}