summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2026-04-13 17:33:17 -0400
committerDax Raad <[email protected]>2026-04-13 17:33:34 -0400
commit59c0fc28ee53b9e63381ebd1190bf35bd74353e5 (patch)
tree241ef3d932d2a635cc2381d515b08e56227d54fb /packages
parentb22add292c194697c1581baf1a323996f966d04b (diff)
downloadopencode-59c0fc28ee53b9e63381ebd1190bf35bd74353e5.tar.gz
opencode-59c0fc28ee53b9e63381ebd1190bf35bd74353e5.zip
ignore: v2 thoughts
Diffstat (limited to 'packages')
-rw-r--r--packages/opencode/src/session/session.sql.ts3
-rw-r--r--packages/opencode/src/v2/session-entry.ts45
2 files changed, 44 insertions, 4 deletions
diff --git a/packages/opencode/src/session/session.sql.ts b/packages/opencode/src/session/session.sql.ts
index 119ebeda3..35ed8fdda 100644
--- a/packages/opencode/src/session/session.sql.ts
+++ b/packages/opencode/src/session/session.sql.ts
@@ -11,7 +11,6 @@ import { Timestamps } from "../storage/schema.sql"
type PartData = Omit<MessageV2.Part, "id" | "sessionID" | "messageID">
type InfoData = Omit<MessageV2.Info, "id" | "sessionID">
-type EntryData = Omit<SessionEntry.Entry, "id" | "type">
export const SessionTable = sqliteTable(
"session",
@@ -104,7 +103,7 @@ export const SessionEntryTable = sqliteTable(
.$type<SessionID>()
.notNull()
.references(() => SessionTable.id, { onDelete: "cascade" }),
- type: text().notNull(),
+ type: text().$type<SessionEntry.Type>().notNull(),
...Timestamps,
data: text({ mode: "json" }).notNull().$type<Omit<SessionEntry.Entry, "type" | "id">>(),
},
diff --git a/packages/opencode/src/v2/session-entry.ts b/packages/opencode/src/v2/session-entry.ts
index b931a4c49..03c8a85b0 100644
--- a/packages/opencode/src/v2/session-entry.ts
+++ b/packages/opencode/src/v2/session-entry.ts
@@ -1,6 +1,10 @@
import { Identifier } from "@/id/id"
+import { Database } from "@/node"
+import type { SessionID } from "@/session/schema"
+import { SessionEntryTable } from "@/session/session.sql"
import { withStatics } from "@/util/schema"
-import { DateTime, Effect, Schema } from "effect"
+import { Context, DateTime, Effect, Layer, Schema } from "effect"
+import { eq } from "../storage/db"
export namespace SessionEntry {
export const ID = Schema.String.pipe(Schema.brand("Session.Entry.ID")).pipe(
@@ -181,6 +185,43 @@ export namespace SessionEntry {
overflow: Schema.Boolean.pipe(Schema.optional),
}) {}
- export const Entry = Schema.Union([User, Synthetic, Request, Tool, Text, Reasoning, Complete, Retry, Compaction])
+ export const Entry = Schema.Union([User, Synthetic, Request, Tool, Text, Reasoning, Complete, Retry, Compaction], {
+ mode: "oneOf",
+ })
export type Entry = Schema.Schema.Type<typeof Entry>
+
+ export type Type = Entry["type"]
+
+ export interface Interface {
+ readonly decode: (row: typeof SessionEntryTable.$inferSelect) => Entry
+ readonly fromSession: (sessionID: SessionID) => Effect.Effect<Entry[], never>
+ }
+
+ export class Service extends Context.Service<Service, Interface>()("@opencode/SessionEntry") {}
+
+ export const layer: Layer.Layer<Service, never, never> = Layer.effect(
+ Service,
+ Effect.gen(function* () {
+ const decodeEntry = Schema.decodeUnknownSync(Entry)
+
+ const decode: (typeof Service.Service)["decode"] = (row) => decodeEntry({ ...row, id: row.id, type: row.type })
+
+ const fromSession = Effect.fn("SessionEntry.fromSession")(function* (sessionID: SessionID) {
+ return Database.use((db) =>
+ db
+ .select()
+ .from(SessionEntryTable)
+ .where(eq(SessionEntryTable.session_id, sessionID))
+ .orderBy(SessionEntryTable.id)
+ .all()
+ .map((row) => decode(row)),
+ )
+ })
+
+ return Service.of({
+ decode,
+ fromSession,
+ })
+ }),
+ )
}