This commit is contained in:
@@ -39,6 +39,16 @@ export namespace Session {
|
|||||||
).test(title)
|
).test(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getForkedTitle(title: string): string {
|
||||||
|
const match = title.match(/^(.+) \(fork #(\d+)\)$/)
|
||||||
|
if (match) {
|
||||||
|
const base = match[1]
|
||||||
|
const num = parseInt(match[2], 10)
|
||||||
|
return `${base} (fork #${num + 1})`
|
||||||
|
}
|
||||||
|
return `${title} (fork #1)`
|
||||||
|
}
|
||||||
|
|
||||||
export const Info = z
|
export const Info = z
|
||||||
.object({
|
.object({
|
||||||
id: Identifier.schema("session"),
|
id: Identifier.schema("session"),
|
||||||
@@ -151,8 +161,12 @@ export namespace Session {
|
|||||||
messageID: Identifier.schema("message").optional(),
|
messageID: Identifier.schema("message").optional(),
|
||||||
}),
|
}),
|
||||||
async (input) => {
|
async (input) => {
|
||||||
|
const original = await get(input.sessionID)
|
||||||
|
if (!original) throw new Error("session not found")
|
||||||
|
const title = getForkedTitle(original.title)
|
||||||
const session = await createNext({
|
const session = await createNext({
|
||||||
directory: Instance.directory,
|
directory: Instance.directory,
|
||||||
|
title,
|
||||||
})
|
})
|
||||||
const msgs = await messages({ sessionID: input.sessionID })
|
const msgs = await messages({ sessionID: input.sessionID })
|
||||||
const idMap = new Map<string, string>()
|
const idMap = new Map<string, string>()
|
||||||
|
|||||||
Reference in New Issue
Block a user