fix(opencode): Update directory and path fields of imported session (#27516)
This commit is contained in:
@@ -7,8 +7,10 @@ import { SessionTable, MessageTable, PartTable } from "../../session/session.sql
|
|||||||
import { InstanceRef } from "@/effect/instance-ref"
|
import { InstanceRef } from "@/effect/instance-ref"
|
||||||
import { ShareNext } from "@/share/share-next"
|
import { ShareNext } from "@/share/share-next"
|
||||||
import { EOL } from "os"
|
import { EOL } from "os"
|
||||||
|
import path from "path"
|
||||||
import { AppFileSystem } from "@opencode-ai/core/filesystem"
|
import { AppFileSystem } from "@opencode-ai/core/filesystem"
|
||||||
import { Effect, Schema } from "effect"
|
import { Effect, Schema } from "effect"
|
||||||
|
import type { InstanceContext } from "@/project/instance-context"
|
||||||
|
|
||||||
const decodeMessageInfo = Schema.decodeUnknownSync(MessageV2.Info)
|
const decodeMessageInfo = Schema.decodeUnknownSync(MessageV2.Info)
|
||||||
const decodePart = Schema.decodeUnknownSync(MessageV2.Part)
|
const decodePart = Schema.decodeUnknownSync(MessageV2.Part)
|
||||||
@@ -89,11 +91,11 @@ export const ImportCommand = effectCmd({
|
|||||||
handler: Effect.fn("Cli.import")(function* (args) {
|
handler: Effect.fn("Cli.import")(function* (args) {
|
||||||
const ctx = yield* InstanceRef
|
const ctx = yield* InstanceRef
|
||||||
if (!ctx) return yield* Effect.die("InstanceRef not provided")
|
if (!ctx) return yield* Effect.die("InstanceRef not provided")
|
||||||
return yield* runImport(args.file, ctx.project.id)
|
return yield* runImport(args.file, ctx)
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
const runImport = Effect.fn("Cli.import.body")(function* (file: string, projectID: string) {
|
const runImport = Effect.fn("Cli.import.body")(function* (file: string, ctx: InstanceContext) {
|
||||||
const share = yield* ShareNext.Service
|
const share = yield* ShareNext.Service
|
||||||
const fs = yield* AppFileSystem.Service
|
const fs = yield* AppFileSystem.Service
|
||||||
|
|
||||||
@@ -168,14 +170,19 @@ const runImport = Effect.fn("Cli.import.body")(function* (file: string, projectI
|
|||||||
|
|
||||||
const info = Schema.decodeUnknownSync(Session.Info)({
|
const info = Schema.decodeUnknownSync(Session.Info)({
|
||||||
...exportData.info,
|
...exportData.info,
|
||||||
projectID,
|
projectID: ctx.project.id,
|
||||||
|
directory: ctx.directory,
|
||||||
|
path: path.relative(path.resolve(ctx.worktree), ctx.directory).replaceAll("\\", "/"),
|
||||||
}) as Session.Info
|
}) as Session.Info
|
||||||
const row = Session.toRow(info)
|
const row = Session.toRow(info)
|
||||||
Database.use((db) =>
|
Database.use((db) =>
|
||||||
db
|
db
|
||||||
.insert(SessionTable)
|
.insert(SessionTable)
|
||||||
.values(row)
|
.values(row)
|
||||||
.onConflictDoUpdate({ target: SessionTable.id, set: { project_id: row.project_id } })
|
.onConflictDoUpdate({
|
||||||
|
target: SessionTable.id,
|
||||||
|
set: { project_id: row.project_id, directory: row.directory, path: row.path },
|
||||||
|
})
|
||||||
.run(),
|
.run(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user