


























@@ -0,0 +1,89 @@
1+import {
2+buildInboundHistoryFromMap,
3+buildPendingHistoryContextFromMap,
4+clearHistoryEntriesIfEnabled,
5+recordPendingHistoryEntryIfEnabled,
6+recordPendingHistoryEntryWithMedia,
7+} from "../../auto-reply/reply/history.js";
8+import type { HistoryEntry, HistoryMediaEntry } from "../../auto-reply/reply/history.types.js";
9+10+type MaybePromise<T> = T | Promise<T>;
11+12+export type ChannelHistoryWindow = {
13+record: (params: {
14+historyKey: string;
15+entry?: HistoryEntry | null;
16+limit: number;
17+}) => HistoryEntry[];
18+recordWithMedia: (params: {
19+historyKey: string;
20+entry?: HistoryEntry | null;
21+limit: number;
22+media?:
23+| readonly HistoryMediaEntry[]
24+| null
25+| (() => MaybePromise<readonly HistoryMediaEntry[] | null | undefined>);
26+mediaLimit?: number;
27+messageId?: string;
28+shouldRecord?: () => boolean;
29+}) => Promise<HistoryEntry[]>;
30+buildPendingContext: (params: {
31+historyKey: string;
32+limit: number;
33+currentMessage: string;
34+formatEntry: (entry: HistoryEntry) => string;
35+lineBreak?: string;
36+}) => string;
37+buildInboundHistory: (params: {
38+historyKey: string;
39+limit: number;
40+}) => HistoryEntry[] | undefined;
41+clear: (params: { historyKey: string; limit: number }) => void;
42+};
43+44+export function createChannelHistoryWindow(params: {
45+historyMap: Map<string, HistoryEntry[]>;
46+}): ChannelHistoryWindow {
47+const { historyMap } = params;
48+return {
49+record: (recordParams) =>
50+recordPendingHistoryEntryIfEnabled({
51+ historyMap,
52+historyKey: recordParams.historyKey,
53+limit: recordParams.limit,
54+entry: recordParams.entry,
55+}),
56+recordWithMedia: (recordParams) =>
57+recordPendingHistoryEntryWithMedia({
58+ historyMap,
59+historyKey: recordParams.historyKey,
60+limit: recordParams.limit,
61+entry: recordParams.entry,
62+media: recordParams.media,
63+mediaLimit: recordParams.mediaLimit,
64+messageId: recordParams.messageId,
65+shouldRecord: recordParams.shouldRecord,
66+}),
67+buildPendingContext: (contextParams) =>
68+buildPendingHistoryContextFromMap({
69+ historyMap,
70+historyKey: contextParams.historyKey,
71+limit: contextParams.limit,
72+currentMessage: contextParams.currentMessage,
73+formatEntry: contextParams.formatEntry,
74+lineBreak: contextParams.lineBreak,
75+}),
76+buildInboundHistory: (historyParams) =>
77+buildInboundHistoryFromMap({
78+ historyMap,
79+historyKey: historyParams.historyKey,
80+limit: historyParams.limit,
81+}),
82+clear: (clearParams) =>
83+clearHistoryEntriesIfEnabled({
84+ historyMap,
85+historyKey: clearParams.historyKey,
86+limit: clearParams.limit,
87+}),
88+};
89+}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。