refactor(session): simplify effect workflows (#43956)
This commit is contained in:
@@ -964,7 +964,8 @@ const resolvePrompt = Effect.fn("Session.resolvePrompt")(function* (
|
||||
const requested = input.skills
|
||||
const selected = yield* Effect.gen(function* () {
|
||||
if (!requested?.length) return undefined
|
||||
const available = yield* (yield* skills).list()
|
||||
const skillService = yield* skills
|
||||
const available = yield* skillService.list()
|
||||
return yield* Effect.forEach(requested, (attachment) => {
|
||||
const skill = available.find((item) => item.id === attachment.id)
|
||||
if (!skill) return Effect.fail(new SkillNotFoundError({ skill: attachment.id }))
|
||||
|
||||
@@ -346,11 +346,10 @@ const make = (dependencies: Dependencies) => {
|
||||
reason: "auto",
|
||||
...content,
|
||||
})
|
||||
const error = { type: "compaction.unavailable" as const, message: "Nothing to compact yet" }
|
||||
return yield* failed({
|
||||
sessionID: input.session.id,
|
||||
reason: "auto",
|
||||
error,
|
||||
error: { type: "compaction.unavailable", message: "Nothing to compact yet" },
|
||||
})
|
||||
})
|
||||
const required = (input: RequiredInput) => {
|
||||
|
||||
@@ -319,7 +319,7 @@ export const makeLayer = (connector: WebSocketConnector) =>
|
||||
}).pipe(
|
||||
Effect.andThen(metric("connect_failure")),
|
||||
Effect.andThen(metric("fallback")),
|
||||
Effect.andThen(Effect.succeed(undefined)),
|
||||
Effect.asVoid,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -71,7 +71,7 @@ export const make = <Key, E, Reason = never>(options: {
|
||||
|
||||
const loop = (key: Key, execution: Execution<E, Reason>, force: boolean): Effect.Effect<void, E> =>
|
||||
Effect.suspend(() => options.drain(key, force, execution.scope)).pipe(
|
||||
Effect.flatMap(() =>
|
||||
Effect.andThen(
|
||||
Effect.suspend(() => {
|
||||
if (execution.stopping || execution.pendingWake === undefined) return Effect.void
|
||||
execution.scope = execution.pendingWake
|
||||
|
||||
@@ -405,7 +405,7 @@ const layer = Layer.effect(
|
||||
? []
|
||||
: yield* snapshots
|
||||
.files({ from: startSnapshot, to: snapshot })
|
||||
.pipe(Effect.catch(() => Effect.succeed(undefined)))
|
||||
.pipe(Effect.orElseSucceed(() => undefined))
|
||||
: undefined
|
||||
return { snapshot, files }
|
||||
})
|
||||
@@ -440,11 +440,13 @@ const layer = Layer.effect(
|
||||
Stream.runForEach((event) =>
|
||||
Effect.gen(function* () {
|
||||
if (overflowFailure || publisher.hasProviderError()) return
|
||||
if (LLMEvent.is.providerError(event)) {
|
||||
if (isContextOverflowFailure(event) && !publisher.record().outputStarted) {
|
||||
overflowFailure = event
|
||||
return
|
||||
}
|
||||
if (
|
||||
LLMEvent.is.providerError(event) &&
|
||||
isContextOverflowFailure(event) &&
|
||||
!publisher.record().outputStarted
|
||||
) {
|
||||
overflowFailure = event
|
||||
return
|
||||
}
|
||||
yield* publisher.publish(event)
|
||||
if (event.type !== "tool-call" || event.providerExecuted) return
|
||||
|
||||
@@ -316,9 +316,7 @@ export const createLLMEventPublisher = (bus: Pick<Bus.Interface, "publish">, inp
|
||||
})
|
||||
})
|
||||
|
||||
const flush = Effect.fn("SessionRunner.flush")(function* () {
|
||||
yield* flushFragments()
|
||||
})
|
||||
const flush = Effect.fn("SessionRunner.flush")(flushFragments)
|
||||
|
||||
const failTool = Effect.fnUntraced(function* (id: string, error: SessionError.Error, metadata?: Tool.Metadata) {
|
||||
const tool = tools.get(id)
|
||||
@@ -372,12 +370,9 @@ export const createLLMEventPublisher = (bus: Pick<Bus.Interface, "publish">, inp
|
||||
})
|
||||
})
|
||||
|
||||
const failUnsettledTools = Effect.fn("SessionRunner.failUnsettledTools")(function* (
|
||||
error: SessionError.Error,
|
||||
scope: "hosted" | "all" = "all",
|
||||
) {
|
||||
return yield* failTools(error, scope)
|
||||
})
|
||||
const failUnsettledTools = Effect.fn("SessionRunner.failUnsettledTools")(
|
||||
(error: SessionError.Error, scope: "hosted" | "all" = "all") => failTools(error, scope),
|
||||
)
|
||||
|
||||
const assistantMessageIDForTool = (id: string) => {
|
||||
const tool = tools.get(id)
|
||||
|
||||
@@ -117,7 +117,7 @@ const make = (dependencies: Dependencies) => {
|
||||
if (!firstUser) return
|
||||
const agent = yield* dependencies.agents.get(Agent.ID.make("title"))
|
||||
if (!agent) return
|
||||
const primary = yield* dependencies.models.resolve(session).pipe(Effect.catch(() => Effect.succeed(undefined)))
|
||||
const primary = yield* dependencies.models.resolve(session).pipe(Effect.orElseSucceed(() => undefined))
|
||||
const info = yield* Effect.gen(function* () {
|
||||
if (agent.model) return yield* dependencies.catalog.model.get(agent.model.providerID, agent.model.id)
|
||||
if (!primary) return
|
||||
@@ -136,7 +136,7 @@ const make = (dependencies: Dependencies) => {
|
||||
...(variant ? { variant } : {}),
|
||||
}),
|
||||
})
|
||||
.pipe(Effect.catch(() => Effect.succeed(undefined))))
|
||||
.pipe(Effect.orElseSucceed(() => undefined)))
|
||||
const selected = preferred ?? primary
|
||||
if (!selected) return
|
||||
const title =
|
||||
|
||||
Reference in New Issue
Block a user