mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-05 00:23:10 +00:00
only display last 100 messages in TUI
This commit is contained in:
@@ -55,7 +55,7 @@ export namespace SessionCompaction {
|
||||
export async function prune(input: { sessionID: string }) {
|
||||
if (Flag.OPENCODE_DISABLE_PRUNE) return
|
||||
log.info("pruning")
|
||||
const msgs = await Session.messages(input.sessionID)
|
||||
const msgs = await Session.messages({ sessionID: input.sessionID })
|
||||
let total = 0
|
||||
let pruned = 0
|
||||
const toPrune = []
|
||||
@@ -111,7 +111,7 @@ export namespace SessionCompaction {
|
||||
draft.time.compacting = undefined
|
||||
})
|
||||
})
|
||||
const toSummarize = await Session.messages(input.sessionID).then(MessageV2.filterCompacted)
|
||||
const toSummarize = await Session.messages({ sessionID: input.sessionID }).then(MessageV2.filterCompacted)
|
||||
const model = await Provider.getModel(input.providerID, input.modelID)
|
||||
const system = [
|
||||
...SystemPrompt.summarize(model.providerID),
|
||||
|
||||
@@ -144,7 +144,7 @@ export namespace Session {
|
||||
const session = await createNext({
|
||||
directory: Instance.directory,
|
||||
})
|
||||
const msgs = await messages(input.sessionID)
|
||||
const msgs = await messages({ sessionID: input.sessionID })
|
||||
for (const msg of msgs) {
|
||||
if (input.messageID && msg.info.id >= input.messageID) break
|
||||
const cloned = await updateMessage({
|
||||
@@ -237,7 +237,7 @@ export namespace Session {
|
||||
})
|
||||
await Storage.write(["share", id], share)
|
||||
await Share.sync("session/info/" + id, session)
|
||||
for (const msg of await messages(id)) {
|
||||
for (const msg of await messages({ sessionID: id })) {
|
||||
await Share.sync("session/message/" + id + "/" + msg.info.id, msg.info)
|
||||
for (const part of msg.parts) {
|
||||
await Share.sync("session/part/" + id + "/" + msg.info.id + "/" + part.id, part)
|
||||
@@ -273,18 +273,26 @@ export namespace Session {
|
||||
return diffs ?? []
|
||||
})
|
||||
|
||||
export const messages = fn(Identifier.schema("session"), async (sessionID) => {
|
||||
const result = [] as MessageV2.WithParts[]
|
||||
for (const p of await Storage.list(["message", sessionID])) {
|
||||
const read = await Storage.read<MessageV2.Info>(p)
|
||||
result.push({
|
||||
info: read,
|
||||
parts: await getParts(read.id),
|
||||
})
|
||||
}
|
||||
result.sort((a, b) => (a.info.id > b.info.id ? 1 : -1))
|
||||
return result
|
||||
})
|
||||
export const messages = fn(
|
||||
z.object({
|
||||
sessionID: Identifier.schema("session"),
|
||||
limit: z.number().optional(),
|
||||
}),
|
||||
async (input) => {
|
||||
const result = [] as MessageV2.WithParts[]
|
||||
const list = (await Array.fromAsync(await Storage.list(["message", input.sessionID])))
|
||||
.toSorted((a, b) => a.at(-1)!.localeCompare(b.at(-1)!))
|
||||
.slice(-1 * (input.limit ?? 1_000_000))
|
||||
for (const p of list) {
|
||||
const read = await Storage.read<MessageV2.Info>(p)
|
||||
result.push({
|
||||
info: read,
|
||||
parts: await getParts(read.id),
|
||||
})
|
||||
}
|
||||
return result
|
||||
},
|
||||
)
|
||||
|
||||
export const getMessage = fn(
|
||||
z.object({
|
||||
|
||||
@@ -434,7 +434,7 @@ export namespace SessionPrompt {
|
||||
providerID: string
|
||||
signal: AbortSignal
|
||||
}) {
|
||||
let msgs = await Session.messages(input.sessionID).then(MessageV2.filterCompacted)
|
||||
let msgs = await Session.messages({ sessionID: input.sessionID }).then(MessageV2.filterCompacted)
|
||||
const lastAssistant = msgs.findLast((msg) => msg.info.role === "assistant")
|
||||
if (
|
||||
lastAssistant?.info.role === "assistant" &&
|
||||
|
||||
@@ -25,7 +25,7 @@ export namespace SessionRevert {
|
||||
sessionID: input.sessionID,
|
||||
})
|
||||
|
||||
const all = await Session.messages(input.sessionID)
|
||||
const all = await Session.messages({ sessionID: input.sessionID })
|
||||
let lastUser: MessageV2.User | undefined
|
||||
const session = await Session.get(input.sessionID)
|
||||
|
||||
@@ -88,7 +88,7 @@ export namespace SessionRevert {
|
||||
export async function cleanup(session: Session.Info) {
|
||||
if (!session.revert) return
|
||||
const sessionID = session.id
|
||||
let msgs = await Session.messages(sessionID)
|
||||
let msgs = await Session.messages({ sessionID })
|
||||
const messageID = session.revert.messageID
|
||||
const [preserve, remove] = splitWhen(msgs, (x) => x.info.id === messageID)
|
||||
msgs = preserve
|
||||
|
||||
@@ -23,7 +23,7 @@ export namespace SessionSummary {
|
||||
messageID: z.string(),
|
||||
}),
|
||||
async (input) => {
|
||||
const all = await Session.messages(input.sessionID)
|
||||
const all = await Session.messages({ sessionID: input.sessionID })
|
||||
await Promise.all([
|
||||
summarizeSession({ sessionID: input.sessionID, messages: all }),
|
||||
summarizeMessage({ messageID: input.messageID, messages: all }),
|
||||
@@ -151,7 +151,7 @@ export namespace SessionSummary {
|
||||
messageID: Identifier.schema("message").optional(),
|
||||
}),
|
||||
async (input) => {
|
||||
let all = await Session.messages(input.sessionID)
|
||||
let all = await Session.messages({ sessionID: input.sessionID })
|
||||
if (input.messageID)
|
||||
all = all.filter(
|
||||
(x) =>
|
||||
|
||||
Reference in New Issue
Block a user