mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-11 03:08:41 +00:00
acp: slash commands, agents, permissions, @ references, code cleanup (#3403)
Co-authored-by: yetone <yetoneful@gmail.com>
This commit is contained in:
@@ -7,20 +7,15 @@ import type { ACPSessionState } from "./types"
|
||||
export class ACPSessionManager {
|
||||
private sessions = new Map<string, ACPSessionState>()
|
||||
|
||||
async create(
|
||||
cwd: string,
|
||||
mcpServers: McpServer[],
|
||||
model?: ACPSessionState["model"],
|
||||
): Promise<ACPSessionState> {
|
||||
const sessionId = `acp_${Identifier.ascending("session")}`
|
||||
const openCodeSession = await Session.create({ title: `ACP Session ${sessionId}` })
|
||||
async create(cwd: string, mcpServers: McpServer[], model?: ACPSessionState["model"]): Promise<ACPSessionState> {
|
||||
const session = await Session.create({ title: `ACP Session ${crypto.randomUUID()}` })
|
||||
const sessionId = session.id
|
||||
const resolvedModel = model ?? (await Provider.defaultModel())
|
||||
|
||||
const state: ACPSessionState = {
|
||||
id: sessionId,
|
||||
cwd,
|
||||
mcpServers,
|
||||
openCodeSessionId: openCodeSession.id,
|
||||
createdAt: new Date(),
|
||||
model: resolvedModel,
|
||||
}
|
||||
@@ -29,54 +24,22 @@ export class ACPSessionManager {
|
||||
return state
|
||||
}
|
||||
|
||||
get(sessionId: string): ACPSessionState | undefined {
|
||||
get(sessionId: string) {
|
||||
return this.sessions.get(sessionId)
|
||||
}
|
||||
|
||||
async remove(sessionId: string): Promise<void> {
|
||||
async remove(sessionId: string) {
|
||||
const state = this.sessions.get(sessionId)
|
||||
if (!state) return
|
||||
|
||||
await Session.remove(state.openCodeSessionId).catch(() => {})
|
||||
await Session.remove(sessionId).catch(() => {})
|
||||
this.sessions.delete(sessionId)
|
||||
}
|
||||
|
||||
has(sessionId: string): boolean {
|
||||
has(sessionId: string) {
|
||||
return this.sessions.has(sessionId)
|
||||
}
|
||||
|
||||
async load(
|
||||
sessionId: string,
|
||||
cwd: string,
|
||||
mcpServers: McpServer[],
|
||||
model?: ACPSessionState["model"],
|
||||
): Promise<ACPSessionState> {
|
||||
const existing = this.sessions.get(sessionId)
|
||||
if (existing) {
|
||||
if (!existing.model) {
|
||||
const resolved = model ?? (await Provider.defaultModel())
|
||||
existing.model = resolved
|
||||
this.sessions.set(sessionId, existing)
|
||||
}
|
||||
return existing
|
||||
}
|
||||
|
||||
const openCodeSession = await Session.create({ title: `ACP Session ${sessionId} (loaded)` })
|
||||
const resolvedModel = model ?? (await Provider.defaultModel())
|
||||
|
||||
const state: ACPSessionState = {
|
||||
id: sessionId,
|
||||
cwd,
|
||||
mcpServers,
|
||||
openCodeSessionId: openCodeSession.id,
|
||||
createdAt: new Date(),
|
||||
model: resolvedModel,
|
||||
}
|
||||
|
||||
this.sessions.set(sessionId, state)
|
||||
return state
|
||||
}
|
||||
|
||||
getModel(sessionId: string) {
|
||||
const session = this.sessions.get(sessionId)
|
||||
if (!session) return
|
||||
@@ -90,4 +53,12 @@ export class ACPSessionManager {
|
||||
this.sessions.set(sessionId, session)
|
||||
return session
|
||||
}
|
||||
|
||||
setMode(sessionId: string, modeId: string) {
|
||||
const session = this.sessions.get(sessionId)
|
||||
if (!session) return
|
||||
session.modeId = modeId
|
||||
this.sessions.set(sessionId, session)
|
||||
return session
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user