mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 17:54:23 +01:00
share
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user