Compare commits

...

1 Commits

Author SHA1 Message Date
Aiden Cline 717cdeed41 feat(core): expose previous agent on selection events 2026-08-09 21:39:18 +00:00
5 changed files with 11 additions and 5 deletions
+5 -1
View File
@@ -339,7 +339,11 @@ export type Endpoint5_31Output =
readonly type: "session.agent.selected" readonly type: "session.agent.selected"
readonly durable: { readonly aggregateID: string; readonly seq: Event.Seq; readonly version: Event.Version } readonly durable: { readonly aggregateID: string; readonly seq: Event.Seq; readonly version: Event.Version }
readonly location?: Location.Ref | undefined readonly location?: Location.Ref | undefined
readonly data: { readonly sessionID: Session.ID; readonly agent: Agent.ID } readonly data: {
readonly sessionID: Session.ID
readonly agent: Agent.ID
readonly previous?: Agent.ID | undefined
}
} }
| { | {
readonly id: Event.ID readonly id: Event.ID
@@ -439,7 +439,7 @@ export type SessionAgentSelected = {
type: "session.agent.selected" type: "session.agent.selected"
durable: { aggregateID: string; seq: number; version: 1 } durable: { aggregateID: string; seq: number; version: 1 }
location?: LocationRef location?: LocationRef
data: { sessionID: string; agent: string } data: { sessionID: string; agent: string; previous?: string }
} }
export type SessionModelSelected = { export type SessionModelSelected = {
+2 -1
View File
@@ -716,10 +716,11 @@ const layer = Layer.effect(
.pipe(Effect.ignore, Effect.forkIn(scope, { startImmediately: true }), Effect.asVoid) .pipe(Effect.ignore, Effect.forkIn(scope, { startImmediately: true }), Effect.asVoid)
}), }),
switchAgent: Effect.fn("Session.switchAgent")(function* (input) { switchAgent: Effect.fn("Session.switchAgent")(function* (input) {
yield* result.get(input.sessionID) const session = yield* result.get(input.sessionID)
yield* bus.publish(SessionEvent.AgentSelected, { yield* bus.publish(SessionEvent.AgentSelected, {
sessionID: input.sessionID, sessionID: input.sessionID,
agent: input.agent, agent: input.agent,
previous: session.agent,
}) })
}), }),
switchModel: Effect.fn("Session.switchModel")(function* (input) { switchModel: Effect.fn("Session.switchModel")(function* (input) {
+2 -2
View File
@@ -648,14 +648,14 @@ describe("Session.create", () => {
it.effect("switches the selected agent through the durable Session event", () => it.effect("switches the selected agent through the durable Session event", () =>
Effect.gen(function* () { Effect.gen(function* () {
const session = yield* Session.Service const session = yield* Session.Service
const created = yield* session.create({ location }) const created = yield* session.create({ location, agent: Agent.defaultID })
yield* session.switchAgent({ sessionID: created.id, agent: Agent.ID.make("plan") }) yield* session.switchAgent({ sessionID: created.id, agent: Agent.ID.make("plan") })
expect(yield* session.get(created.id)).toMatchObject({ agent: "plan" }) expect(yield* session.get(created.id)).toMatchObject({ agent: "plan" })
expect( expect(
Array.from(yield* logEvents(session, created.id, true).pipe(Stream.drop(1), Stream.take(1), Stream.runCollect)), Array.from(yield* logEvents(session, created.id, true).pipe(Stream.drop(1), Stream.take(1), Stream.runCollect)),
).toMatchObject([{ type: "session.agent.selected", data: { agent: "plan" } }]) ).toMatchObject([{ type: "session.agent.selected", data: { agent: "plan", previous: "build" } }])
}), }),
) )
+1
View File
@@ -69,6 +69,7 @@ export const AgentSelected = Event.durable({
schema: { schema: {
...Base, ...Base,
agent: Agent.ID, agent: Agent.ID,
previous: Agent.ID.pipe(optional),
}, },
}) })
export type AgentSelected = typeof AgentSelected.Type export type AgentSelected = typeof AgentSelected.Type