Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/client/src/effect/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export type SessionListInput = {
readonly order?: "asc" | "desc" | undefined
readonly search?: string | undefined
readonly parentID?: Session.ID | null | undefined
readonly archived?: boolean | undefined
readonly directory?: AbsolutePath | undefined
readonly project?: Project.ID | undefined
readonly subpath?: RelativePath | undefined
Expand Down Expand Up @@ -254,6 +255,7 @@ export type SessionUpdateInput = {
readonly title?: string | undefined
readonly metadata?: Session.Metadata | undefined
readonly permissions?: Permission.Ruleset | undefined
readonly archived?: boolean | undefined
}
export type SessionUpdateOutput = void
export type SessionUpdateOperation<E = never> = (input: SessionUpdateInput) => Effect.Effect<SessionUpdateOutput, E>
Expand Down Expand Up @@ -570,6 +572,34 @@ export type SessionLogOutput =
| undefined
readonly data: { readonly sessionID: Session.ID; readonly idle: number }
}
| {
readonly id: Event.ID
readonly created: number
readonly metadata?: { readonly [x: string]: unknown } | undefined
readonly type: "session.archived"
readonly durable: { readonly aggregateID: string; readonly seq: Event.Seq; readonly version: Event.Version }
readonly location?:
| {
readonly directory: AbsolutePath
readonly workspaceID?: (string & Brand.Brand<"Workspace.ID">) | undefined
}
| undefined
readonly data: { readonly sessionID: Session.ID }
}
| {
readonly id: Event.ID
readonly created: number
readonly metadata?: { readonly [x: string]: unknown } | undefined
readonly type: "session.unarchived"
readonly durable: { readonly aggregateID: string; readonly seq: Event.Seq; readonly version: Event.Version }
readonly location?:
| {
readonly directory: AbsolutePath
readonly workspaceID?: (string & Brand.Brand<"Workspace.ID">) | undefined
}
| undefined
readonly data: { readonly sessionID: Session.ID }
}
| {
readonly id: Event.ID
readonly created: number
Expand Down
8 changes: 7 additions & 1 deletion packages/client/src/effect/generated/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ const EndpointSessionList = (raw: RawClient["server.session"]) => (input?: Sessi
order: input?.["order"],
search: input?.["search"],
parentID: input?.["parentID"],
archived: input?.["archived"],
directory: input?.["directory"],
project: input?.["project"],
subpath: input?.["subpath"],
Expand Down Expand Up @@ -474,7 +475,12 @@ const EndpointSessionUpdate = (raw: RawClient["server.session"]) => (input: Sess
preserveEffect<SessionUpdateOutput>()(
raw["session.update"]({
params: { sessionID: input["sessionID"] },
payload: { title: input["title"], metadata: input["metadata"], permissions: input["permissions"] },
payload: {
title: input["title"],
metadata: input["metadata"],
permissions: input["permissions"],
archived: input["archived"],
},
}).pipe(Effect.mapError(mapClientError)),
)

Expand Down
8 changes: 7 additions & 1 deletion packages/client/src/promise/generated/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ export function make(options: ClientOptions) {
order: input?.["order"],
search: input?.["search"],
parentID: input?.["parentID"],
archived: input?.["archived"],
directory: input?.["directory"],
project: input?.["project"],
subpath: input?.["subpath"],
Expand Down Expand Up @@ -691,7 +692,12 @@ export function make(options: ClientOptions) {
{
method: "PATCH",
path: `/api/session/${encodeURIComponent(input.sessionID)}`,
body: { title: input["title"], metadata: input["metadata"], permissions: input["permissions"] },
body: {
title: input["title"],
metadata: input["metadata"],
permissions: input["permissions"],
archived: input["archived"],
},
successStatus: 204,
declaredStatuses: [400, 401, 404],
empty: true,
Expand Down
54 changes: 54 additions & 0 deletions packages/client/src/promise/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,26 @@ export type SessionViewed = {
data: { sessionID: string; idle: number }
}

export type SessionArchived = {
id: string
created: number
metadata?: { [x: string]: any }
type: "session.archived"
durable: { aggregateID: string; seq: number; version: 1 }
location?: LocationRef
data: { sessionID: string }
}

export type SessionUnarchived = {
id: string
created: number
metadata?: { [x: string]: any }
type: "session.unarchived"
durable: { aggregateID: string; seq: number; version: 1 }
location?: LocationRef
data: { sessionID: string }
}

export type SessionDeleted = {
id: string
created: number
Expand Down Expand Up @@ -2378,6 +2398,8 @@ export type SessionEventDurable =
| SessionMetadataUpdated
| SessionPermissions
| SessionViewed
| SessionArchived
| SessionUnarchived
| SessionDeleted
| SessionForked
| SessionInboxDelivered
Expand Down Expand Up @@ -2441,6 +2463,8 @@ export type V2Event =
| SessionMetadataUpdated
| SessionPermissions
| SessionViewed
| SessionArchived
| SessionUnarchived
| SessionUsageUpdated
| SessionDeleted
| SessionForked
Expand Down Expand Up @@ -2823,6 +2847,7 @@ export type SessionListInput = {
readonly order?: "asc" | "desc" | undefined
readonly search?: string | undefined
readonly parentID?: string | null | undefined
readonly archived?: boolean | undefined
readonly directory?: string | undefined
readonly project?: string | undefined
readonly subpath?: string | undefined
Expand All @@ -2833,6 +2858,7 @@ export type SessionListInput = {
readonly order?: "asc" | "desc" | undefined
readonly search?: string | undefined
readonly parentID?: string | null | undefined
readonly archived?: boolean | undefined
readonly directory?: string | undefined
readonly project?: string | undefined
readonly subpath?: string | undefined
Expand All @@ -2843,6 +2869,7 @@ export type SessionListInput = {
readonly order?: "asc" | "desc" | undefined
readonly search?: string | undefined
readonly parentID?: string | null | undefined
readonly archived?: boolean | undefined
readonly directory?: string | undefined
readonly project?: string | undefined
readonly subpath?: string | undefined
Expand All @@ -2853,16 +2880,29 @@ export type SessionListInput = {
readonly order?: "asc" | "desc" | undefined
readonly search?: string | undefined
readonly parentID?: string | null | undefined
readonly archived?: boolean | undefined
readonly directory?: string | undefined
readonly project?: string | undefined
readonly subpath?: string | undefined
readonly cursor?: string | undefined
}["parentID"]
readonly archived?: {
readonly limit?: number | undefined
readonly order?: "asc" | "desc" | undefined
readonly search?: string | undefined
readonly parentID?: string | null | undefined
readonly archived?: boolean | undefined
readonly directory?: string | undefined
readonly project?: string | undefined
readonly subpath?: string | undefined
readonly cursor?: string | undefined
}["archived"]
readonly directory?: {
readonly limit?: number | undefined
readonly order?: "asc" | "desc" | undefined
readonly search?: string | undefined
readonly parentID?: string | null | undefined
readonly archived?: boolean | undefined
readonly directory?: string | undefined
readonly project?: string | undefined
readonly subpath?: string | undefined
Expand All @@ -2873,6 +2913,7 @@ export type SessionListInput = {
readonly order?: "asc" | "desc" | undefined
readonly search?: string | undefined
readonly parentID?: string | null | undefined
readonly archived?: boolean | undefined
readonly directory?: string | undefined
readonly project?: string | undefined
readonly subpath?: string | undefined
Expand All @@ -2883,6 +2924,7 @@ export type SessionListInput = {
readonly order?: "asc" | "desc" | undefined
readonly search?: string | undefined
readonly parentID?: string | null | undefined
readonly archived?: boolean | undefined
readonly directory?: string | undefined
readonly project?: string | undefined
readonly subpath?: string | undefined
Expand All @@ -2893,6 +2935,7 @@ export type SessionListInput = {
readonly order?: "asc" | "desc" | undefined
readonly search?: string | undefined
readonly parentID?: string | null | undefined
readonly archived?: boolean | undefined
readonly directory?: string | undefined
readonly project?: string | undefined
readonly subpath?: string | undefined
Expand Down Expand Up @@ -4123,21 +4166,32 @@ export type SessionUpdateInput = {
readonly permissions?:
| ReadonlyArray<{ readonly action: string; readonly resource: string; readonly effect: "allow" | "deny" | "ask" }>
| undefined
readonly archived?: boolean | undefined
}["title"]
readonly metadata?: {
readonly title?: string | undefined
readonly metadata?: { readonly [x: string]: JsonValue } | undefined
readonly permissions?:
| ReadonlyArray<{ readonly action: string; readonly resource: string; readonly effect: "allow" | "deny" | "ask" }>
| undefined
readonly archived?: boolean | undefined
}["metadata"]
readonly permissions?: {
readonly title?: string | undefined
readonly metadata?: { readonly [x: string]: JsonValue } | undefined
readonly permissions?:
| ReadonlyArray<{ readonly action: string; readonly resource: string; readonly effect: "allow" | "deny" | "ask" }>
| undefined
readonly archived?: boolean | undefined
}["permissions"]
readonly archived?: {
readonly title?: string | undefined
readonly metadata?: { readonly [x: string]: JsonValue } | undefined
readonly permissions?:
| ReadonlyArray<{ readonly action: string; readonly resource: string; readonly effect: "allow" | "deny" | "ask" }>
| undefined
readonly archived?: boolean | undefined
}["archived"]
}

export type SessionUpdateOutput = void
Expand Down
8 changes: 8 additions & 0 deletions packages/client/src/solid/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,14 @@ export function createData(config: CreateDataInput) {
if (store.session.info[event.data.sessionID])
setStore("session", "info", event.data.sessionID, "permissions", event.data.permissions)
return
case "session.archived":
if (store.session.info[event.data.sessionID])
setStore("session", "info", event.data.sessionID, "time", "archived", event.created)
return
case "session.unarchived":
if (store.session.info[event.data.sessionID])
setStore("session", "info", event.data.sessionID, "time", "archived", undefined)
return
case "session.moved": {
const current = store.session.info[event.data.sessionID]
if (current) {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ export interface Interface {
readonly switchAgent: (input: { sessionID: SessionSchema.ID; agent: Agent.ID }) => Effect.Effect<void, NotFoundError>
readonly switchModel: (input: { sessionID: SessionSchema.ID; model: Model.Ref }) => Effect.Effect<void, NotFoundError>
readonly rename: (input: { sessionID: SessionSchema.ID; title: string }) => Effect.Effect<void, NotFoundError>
readonly archive: (sessionID: SessionSchema.ID) => Effect.Effect<void, NotFoundError>
readonly unarchive: (sessionID: SessionSchema.ID) => Effect.Effect<void, NotFoundError>
readonly setMetadata: (input: {
sessionID: SessionSchema.ID
metadata: SessionSchema.Metadata
Expand Down Expand Up @@ -433,6 +435,8 @@ const layer = Layer.effect(
switchAgent: (input) => sessions.forSession(input.sessionID).switchAgent(input),
switchModel: (input) => sessions.forSession(input.sessionID).switchModel(input),
rename: (input) => sessions.forSession(input.sessionID).rename(input),
archive: (sessionID) => sessions.forSession(sessionID).archive(),
unarchive: (sessionID) => sessions.forSession(sessionID).unarchive(),
setMetadata: (input) => sessions.forSession(input.sessionID).setMetadata(input),
setPermissions: (input) => sessions.forSession(input.sessionID).setPermissions(input),
move: moves.move,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/session/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function fromRow(row: typeof SessionTable.$inferSelect): SessionSchema.In
updated: DateTime.makeUnsafe(row.time_updated),
idle: row.time_idle === null ? undefined : DateTime.makeUnsafe(row.time_idle),
viewed: row.time_viewed === null ? undefined : DateTime.makeUnsafe(row.time_viewed),
archived: row.time_archived ? DateTime.makeUnsafe(row.time_archived) : undefined,
archived: row.time_archived === null ? undefined : DateTime.makeUnsafe(row.time_archived),
},
})
}
2 changes: 2 additions & 0 deletions packages/core/src/session/message-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export function update(adapter: Adapter, event: SessionEvent.DurableEvent) {
Match.discriminatorsExhaustive("type")({
"session.created": () => Effect.void,
"session.viewed": () => Effect.void,
"session.archived": () => Effect.void,
"session.unarchived": () => Effect.void,
"session.message.content.updated": (event) =>
updateOwnedAssistant(event.data.messageID, (draft) => {
draft.content = castDraft(
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/session/projector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,22 @@ const layer = Layer.effectDiscard(
.run()
.pipe(Effect.orDie)
})
yield* bus.project(SessionEvent.Archived, (event) =>
db
.update(SessionTable)
.set({ time_archived: event.created, time_updated: event.created })
.where(eq(SessionTable.id, event.data.sessionID))
.run()
.pipe(Effect.orDie),
)
yield* bus.project(SessionEvent.Unarchived, (event) =>
db
.update(SessionTable)
.set({ time_archived: null, time_updated: event.created })
.where(eq(SessionTable.id, event.data.sessionID))
.run()
.pipe(Effect.orDie),
)
yield* bus.project(SessionEvent.MessageContentUpdated, (event) => run(db, event))
yield* bus.project(SessionEvent.UsageRecorded, (event) => applyUsage(db, event.data.sessionID, event.data))
yield* bus.project(SessionEvent.Forked, (event) => projectFork(db, event))
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ export const make = Effect.fn("Session.make")(function* () {
yield* get(sessionID)
yield* bus.publish(SessionEvent.Renamed, { sessionID, title: input.title })
})
const archive = Effect.fn("Session.archive")(function* (sessionID: SessionSchema.ID) {
const session = yield* get(sessionID)
if (session.time.archived) return
yield* bus.publish(SessionEvent.Archived, { sessionID })
})
const unarchive = Effect.fn("Session.unarchive")(function* (sessionID: SessionSchema.ID) {
const session = yield* get(sessionID)
if (!session.time.archived) return
yield* bus.publish(SessionEvent.Unarchived, { sessionID })
})
const setMetadata = Effect.fn("Session.setMetadata")(function* (
sessionID: SessionSchema.ID,
input: { metadata: SessionSchema.Metadata },
Expand Down Expand Up @@ -348,6 +358,8 @@ export const make = Effect.fn("Session.make")(function* () {
message,
view,
rename,
archive,
unarchive,
setMetadata,
setPermissions,
switchAgent,
Expand All @@ -372,6 +384,8 @@ export const make = Effect.fn("Session.make")(function* () {
const message = operations.message.bind(undefined, sessionID)
const view = operations.view.bind(undefined, sessionID)
const rename = operations.rename.bind(undefined, sessionID)
const archive = operations.archive.bind(undefined, sessionID)
const unarchive = operations.unarchive.bind(undefined, sessionID)
const setMetadata = operations.setMetadata.bind(undefined, sessionID)
const setPermissions = operations.setPermissions.bind(undefined, sessionID)
const switchAgent = operations.switchAgent.bind(undefined, sessionID)
Expand Down Expand Up @@ -399,6 +413,8 @@ export const make = Effect.fn("Session.make")(function* () {
message,
view,
rename,
archive,
unarchive,
setMetadata,
setPermissions,
switchAgent,
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/session/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const ListInputBase = {
limit: PositiveInt.pipe(Schema.optional),
order: Schema.Literals(["asc", "desc"]).pipe(Schema.optional),
parentID: Schema.NullOr(Session.ID).pipe(Schema.optional),
archived: Schema.Boolean.pipe(Schema.optional),
anchor: Session.ListAnchor.pipe(Schema.optional),
}

Expand Down Expand Up @@ -111,6 +112,8 @@ const layer = Layer.effect(
conditions.push(
input.parentID === null ? isNull(SessionTable.parent_id) : eq(SessionTable.parent_id, input.parentID),
)
if (input.archived !== undefined)
conditions.push(input.archived ? isNotNull(SessionTable.time_archived) : isNull(SessionTable.time_archived))
if (input.anchor) {
conditions.push(
order === "asc"
Expand Down
Loading
Loading