This commit is contained in:
Dax Raad
2025-05-23 16:20:21 -04:00
parent e2dc5a8faf
commit 5f750b7368
5 changed files with 72 additions and 13 deletions

View File

@@ -18,12 +18,14 @@ import * as tools from "../tool";
import ANTHROPIC_PROMPT from "./prompt/anthropic.txt";
import type { Tool } from "../tool/tool";
import { Share } from "../share/share";
export namespace Session {
const log = Log.create({ service: "session" });
export const Info = z.object({
id: Identifier.schema("session"),
shareID: z.string().optional(),
title: z.string(),
tokens: z.object({
input: z.number(),
@@ -77,6 +79,16 @@ export namespace Session {
return read as Info;
}
export async function share(id: string) {
const session = await get(id);
if (session.shareID) return session.shareID;
const shareID = await Share.create(id);
if (!shareID) return;
session.shareID = shareID;
await update(session);
return shareID;
}
export async function update(session: Info) {
state().sessions.set(session.id, session);
await Storage.writeJSON("session/info/" + session.id, session);