diff --git a/packages/core/src/session.ts b/packages/core/src/session.ts index 3dc268385..a866d8dec 100644 --- a/packages/core/src/session.ts +++ b/packages/core/src/session.ts @@ -16,6 +16,7 @@ import { SessionProjector } from "./session/projector" import { SessionMessageTable, SessionTable } from "./session/sql" import { SessionSchema } from "./session/schema" import { AbsolutePath, RelativePath } from "./schema" +import { AgentV2 } from "./agent" // get project -> project.locations // @@ -141,14 +142,12 @@ export interface Interface { export class Service extends Context.Service()("@opencode/v2/Session") {} function fromRow(row: typeof SessionTable.$inferSelect): SessionSchema.Info { - return new SessionSchema.Info({ + return SessionSchema.Info.make({ id: SessionSchema.ID.make(row.id), projectID: ProjectV2.ID.make(row.project_id), - workspaceID: row.workspace_id ? WorkspaceV2.ID.make(row.workspace_id) : undefined, title: row.title, parentID: row.parent_id ? SessionSchema.ID.make(row.parent_id) : undefined, - path: row.path ?? "", - agent: row.agent ?? undefined, + agent: row.agent ? AgentV2.ID.make(row.agent) : undefined, model: row.model ? { id: ModelV2.ID.make(row.model.id), @@ -166,6 +165,11 @@ function fromRow(row: typeof SessionTable.$inferSelect): SessionSchema.Info { write: row.tokens_cache_write, }, }, + location: Location.Ref.make({ + directory: AbsolutePath.make(row.directory), + workspaceID: row.workspace_id ? WorkspaceV2.ID.make(row.workspace_id) : undefined, + }), + subpath: row.path ? RelativePath.make(row.path) : undefined, time: { created: DateTime.makeUnsafe(row.time_created), updated: DateTime.makeUnsafe(row.time_updated), diff --git a/packages/core/src/session/schema.ts b/packages/core/src/session/schema.ts index 8562a097e..c66d09b8a 100644 --- a/packages/core/src/session/schema.ts +++ b/packages/core/src/session/schema.ts @@ -5,9 +5,9 @@ import { Location } from "../location" import { ModelV2 } from "../model" import { ProjectV2 } from "../project" import { RelativePath, optionalOmitUndefined, withStatics } from "../schema" -import { WorkspaceV2 } from "../workspace" import { Identifier } from "../util/identifier" import { V2Schema } from "../v2-schema" +import { AgentV2 } from "../agent" export const Delivery = Schema.Literals(["immediate", "deferred"]).annotate({ identifier: "Session.Delivery", @@ -24,22 +24,12 @@ export const ID = Schema.String.check(Schema.isStartsWith("ses")).pipe( ) export type ID = typeof ID.Type -export const LegacyInfo = Schema.Struct({ +export class Info extends Schema.Class("SessionV2.Info")({ id: ID, - location: Location.Ref, - subpath: RelativePath, // derived from location - project: ProjectV2.ID, // derived from location -}) -export type LegacyInfo = typeof LegacyInfo.Type - -export class Info extends Schema.Class("Session.Info")({ - id: ID, - parentID: optionalOmitUndefined(ID), + parentID: ID.pipe(optionalOmitUndefined), projectID: ProjectV2.ID, - workspaceID: optionalOmitUndefined(WorkspaceV2.ID), - path: optionalOmitUndefined(Schema.String), - agent: optionalOmitUndefined(Schema.String), - model: ModelV2.Ref.pipe(optionalOmitUndefined), + agent: AgentV2.ID.pipe(Schema.optional), + model: ModelV2.Ref.pipe(Schema.optional), cost: Schema.Finite, tokens: Schema.Struct({ input: Schema.Finite, @@ -53,7 +43,9 @@ export class Info extends Schema.Class("Session.Info")({ time: Schema.Struct({ created: V2Schema.DateTimeUtcFromMillis, updated: V2Schema.DateTimeUtcFromMillis, - archived: optionalOmitUndefined(V2Schema.DateTimeUtcFromMillis), + archived: V2Schema.DateTimeUtcFromMillis.pipe(Schema.optional), }), title: Schema.String, + location: Location.Ref, + subpath: RelativePath.pipe(Schema.optional), }) {} diff --git a/packages/sdk/js/src/v2/gen/types.gen.ts b/packages/sdk/js/src/v2/gen/types.gen.ts index 61d106851..c753ac5eb 100644 --- a/packages/sdk/js/src/v2/gen/types.gen.ts +++ b/packages/sdk/js/src/v2/gen/types.gen.ts @@ -2494,7 +2494,7 @@ export type SessionBusyError = { } export type V2SessionsResponse = { - items: Array + items: Array cursor: { previous?: string next?: string @@ -3369,12 +3369,15 @@ export type ConfigV2ExperimentalPolicy = { resource: string } -export type SessionInfo = { +export type LocationRef = { + directory: string + workspaceID?: string +} + +export type SessionV2Info = { id: string parentID?: string projectID: string - workspaceID?: string - path?: string agent?: string model?: { id: string @@ -3397,6 +3400,8 @@ export type SessionInfo = { archived?: number } title: string + location: LocationRef + subpath?: string } export type SessionDelivery = "immediate" | "deferred"