refactor(session): remove revert async facade exports (#22339)
This commit is contained in:
@@ -551,28 +551,38 @@ export const SessionRoutes = lazy(() =>
|
|||||||
async (c) => {
|
async (c) => {
|
||||||
const sessionID = c.req.valid("param").sessionID
|
const sessionID = c.req.valid("param").sessionID
|
||||||
const body = c.req.valid("json")
|
const body = c.req.valid("json")
|
||||||
const session = await Session.get(sessionID)
|
await AppRuntime.runPromise(
|
||||||
await SessionRevert.cleanup(session)
|
Effect.gen(function* () {
|
||||||
const msgs = await Session.messages({ sessionID })
|
const session = yield* Session.Service
|
||||||
const defaultAgent = await AppRuntime.runPromise(Agent.Service.use((svc) => svc.defaultAgent()))
|
const revert = yield* SessionRevert.Service
|
||||||
let currentAgent = defaultAgent
|
const compact = yield* SessionCompaction.Service
|
||||||
for (let i = msgs.length - 1; i >= 0; i--) {
|
const prompt = yield* SessionPrompt.Service
|
||||||
const info = msgs[i].info
|
const agent = yield* Agent.Service
|
||||||
if (info.role === "user") {
|
|
||||||
currentAgent = info.agent || defaultAgent
|
yield* revert.cleanup(yield* session.get(sessionID))
|
||||||
break
|
const msgs = yield* session.messages({ sessionID })
|
||||||
}
|
const defaultAgent = yield* agent.defaultAgent()
|
||||||
}
|
let currentAgent = defaultAgent
|
||||||
await SessionCompaction.create({
|
for (let i = msgs.length - 1; i >= 0; i--) {
|
||||||
sessionID,
|
const info = msgs[i].info
|
||||||
agent: currentAgent,
|
if (info.role === "user") {
|
||||||
model: {
|
currentAgent = info.agent || defaultAgent
|
||||||
providerID: body.providerID,
|
break
|
||||||
modelID: body.modelID,
|
}
|
||||||
},
|
}
|
||||||
auto: body.auto,
|
|
||||||
})
|
yield* compact.create({
|
||||||
await SessionPrompt.loop({ sessionID })
|
sessionID,
|
||||||
|
agent: currentAgent,
|
||||||
|
model: {
|
||||||
|
providerID: body.providerID,
|
||||||
|
modelID: body.modelID,
|
||||||
|
},
|
||||||
|
auto: body.auto,
|
||||||
|
})
|
||||||
|
yield* prompt.loop({ sessionID })
|
||||||
|
}),
|
||||||
|
)
|
||||||
return c.json(true)
|
return c.json(true)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -990,10 +1000,14 @@ export const SessionRoutes = lazy(() =>
|
|||||||
async (c) => {
|
async (c) => {
|
||||||
const sessionID = c.req.valid("param").sessionID
|
const sessionID = c.req.valid("param").sessionID
|
||||||
log.info("revert", c.req.valid("json"))
|
log.info("revert", c.req.valid("json"))
|
||||||
const session = await SessionRevert.revert({
|
const session = await AppRuntime.runPromise(
|
||||||
sessionID,
|
SessionRevert.Service.use((svc) =>
|
||||||
...c.req.valid("json"),
|
svc.revert({
|
||||||
})
|
sessionID,
|
||||||
|
...c.req.valid("json"),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
return c.json(session)
|
return c.json(session)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -1023,7 +1037,7 @@ export const SessionRoutes = lazy(() =>
|
|||||||
),
|
),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const sessionID = c.req.valid("param").sessionID
|
const sessionID = c.req.valid("param").sessionID
|
||||||
const session = await SessionRevert.unrevert({ sessionID })
|
const session = await AppRuntime.runPromise(SessionRevert.Service.use((svc) => svc.unrevert({ sessionID })))
|
||||||
return c.json(session)
|
return c.json(session)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import z from "zod"
|
import z from "zod"
|
||||||
import { Effect, Layer, Context } from "effect"
|
import { Effect, Layer, Context } from "effect"
|
||||||
import { makeRuntime } from "@/effect/run-service"
|
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { Snapshot } from "../snapshot"
|
import { Snapshot } from "../snapshot"
|
||||||
import { Storage } from "@/storage/storage"
|
import { Storage } from "@/storage/storage"
|
||||||
@@ -160,18 +159,4 @@ export namespace SessionRevert {
|
|||||||
Layer.provide(SessionSummary.defaultLayer),
|
Layer.provide(SessionSummary.defaultLayer),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const { runPromise } = makeRuntime(Service, defaultLayer)
|
|
||||||
|
|
||||||
export async function revert(input: RevertInput) {
|
|
||||||
return runPromise((svc) => svc.revert(input))
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function unrevert(input: { sessionID: SessionID }) {
|
|
||||||
return runPromise((svc) => svc.unrevert(input))
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function cleanup(session: Session.Info) {
|
|
||||||
return runPromise((svc) => svc.cleanup(session))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user