Skip to content

Commit 581d520

Browse files
authored
feat: unwrap share namespaces to flat exports + barrel (anomalyco#22744)
1 parent a427a28 commit 581d520

10 files changed

Lines changed: 361 additions & 363 deletions

File tree

packages/opencode/src/cli/cmd/github.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { cmd } from "./cmd"
2121
import { ModelsDev } from "../../provider/models"
2222
import { Instance } from "@/project/instance"
2323
import { bootstrap } from "../bootstrap"
24-
import { SessionShare } from "@/share/session"
24+
import { SessionShare } from "@/share"
2525
import { Session } from "../../session"
2626
import type { SessionID } from "../../session/schema"
2727
import { MessageID, PartID } from "../../session/schema"

packages/opencode/src/cli/cmd/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { bootstrap } from "../bootstrap"
77
import { Database } from "../../storage/db"
88
import { SessionTable, MessageTable, PartTable } from "../../session/session.sql"
99
import { Instance } from "../../project/instance"
10-
import { ShareNext } from "../../share/share-next"
10+
import { ShareNext } from "../../share"
1111
import { EOL } from "os"
1212
import { Filesystem } from "../../util"
1313
import { AppRuntime } from "@/effect/app-runtime"

packages/opencode/src/effect/app-runtime.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ import { Vcs } from "@/project"
4545
import { Worktree } from "@/worktree"
4646
import { Pty } from "@/pty"
4747
import { Installation } from "@/installation"
48-
import { ShareNext } from "@/share/share-next"
49-
import { SessionShare } from "@/share/session"
48+
import { ShareNext } from "@/share"
49+
import { SessionShare } from "@/share"
5050

5151
export const AppLayer = Layer.mergeAll(
5252
AppFileSystem.defaultLayer,

packages/opencode/src/effect/bootstrap-runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Plugin } from "@/plugin"
55
import { LSP } from "@/lsp"
66
import { FileWatcher } from "@/file/watcher"
77
import { Format } from "@/format"
8-
import { ShareNext } from "@/share/share-next"
8+
import { ShareNext } from "@/share"
99
import { File } from "@/file"
1010
import { Vcs } from "@/project"
1111
import { Snapshot } from "@/snapshot"

packages/opencode/src/project/bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Command } from "../command"
1010
import { Instance } from "./instance"
1111
import { Log } from "@/util"
1212
import { FileWatcher } from "@/file/watcher"
13-
import { ShareNext } from "@/share/share-next"
13+
import { ShareNext } from "@/share"
1414
import * as Effect from "effect/Effect"
1515

1616
export const InstanceBootstrap = Effect.gen(function* () {

packages/opencode/src/server/instance/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { SessionPrompt } from "../../session/prompt"
99
import { SessionRunState } from "@/session/run-state"
1010
import { SessionCompaction } from "../../session/compaction"
1111
import { SessionRevert } from "../../session/revert"
12-
import { SessionShare } from "@/share/session"
12+
import { SessionShare } from "@/share"
1313
import { SessionStatus } from "@/session/status"
1414
import { SessionSummary } from "@/session/summary"
1515
import { Todo } from "../../session/todo"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * as ShareNext from "./share-next"
2+
export * as SessionShare from "./session"

packages/opencode/src/share/session.ts

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,54 @@ import { SyncEvent } from "@/sync"
44
import { Effect, Layer, Scope, Context } from "effect"
55
import { Config } from "../config"
66
import { Flag } from "../flag/flag"
7-
import { ShareNext } from "./share-next"
8-
9-
export namespace SessionShare {
10-
export interface Interface {
11-
readonly create: (input?: Session.CreateInput) => Effect.Effect<Session.Info>
12-
readonly share: (sessionID: SessionID) => Effect.Effect<{ url: string }, unknown>
13-
readonly unshare: (sessionID: SessionID) => Effect.Effect<void, unknown>
14-
}
15-
16-
export class Service extends Context.Service<Service, Interface>()("@opencode/SessionShare") {}
17-
18-
export const layer = Layer.effect(
19-
Service,
20-
Effect.gen(function* () {
21-
const cfg = yield* Config.Service
22-
const session = yield* Session.Service
23-
const shareNext = yield* ShareNext.Service
24-
const scope = yield* Scope.Scope
25-
26-
const share = Effect.fn("SessionShare.share")(function* (sessionID: SessionID) {
27-
const conf = yield* cfg.get()
28-
if (conf.share === "disabled") throw new Error("Sharing is disabled in configuration")
29-
const result = yield* shareNext.create(sessionID)
30-
yield* Effect.sync(() =>
31-
SyncEvent.run(Session.Event.Updated, { sessionID, info: { share: { url: result.url } } }),
32-
)
33-
return result
34-
})
35-
36-
const unshare = Effect.fn("SessionShare.unshare")(function* (sessionID: SessionID) {
37-
yield* shareNext.remove(sessionID)
38-
yield* Effect.sync(() => SyncEvent.run(Session.Event.Updated, { sessionID, info: { share: { url: null } } }))
39-
})
40-
41-
const create = Effect.fn("SessionShare.create")(function* (input?: Session.CreateInput) {
42-
const result = yield* session.create(input)
43-
if (result.parentID) return result
44-
const conf = yield* cfg.get()
45-
if (!(Flag.OPENCODE_AUTO_SHARE || conf.share === "auto")) return result
46-
yield* share(result.id).pipe(Effect.ignore, Effect.forkIn(scope))
47-
return result
48-
})
49-
50-
return Service.of({ create, share, unshare })
51-
}),
52-
)
53-
54-
export const defaultLayer = layer.pipe(
55-
Layer.provide(ShareNext.defaultLayer),
56-
Layer.provide(Session.defaultLayer),
57-
Layer.provide(Config.defaultLayer),
58-
)
7+
import { ShareNext } from "."
8+
9+
export interface Interface {
10+
readonly create: (input?: Session.CreateInput) => Effect.Effect<Session.Info>
11+
readonly share: (sessionID: SessionID) => Effect.Effect<{ url: string }, unknown>
12+
readonly unshare: (sessionID: SessionID) => Effect.Effect<void, unknown>
5913
}
14+
15+
export class Service extends Context.Service<Service, Interface>()("@opencode/SessionShare") {}
16+
17+
export const layer = Layer.effect(
18+
Service,
19+
Effect.gen(function* () {
20+
const cfg = yield* Config.Service
21+
const session = yield* Session.Service
22+
const shareNext = yield* ShareNext.Service
23+
const scope = yield* Scope.Scope
24+
25+
const share = Effect.fn("SessionShare.share")(function* (sessionID: SessionID) {
26+
const conf = yield* cfg.get()
27+
if (conf.share === "disabled") throw new Error("Sharing is disabled in configuration")
28+
const result = yield* shareNext.create(sessionID)
29+
yield* Effect.sync(() =>
30+
SyncEvent.run(Session.Event.Updated, { sessionID, info: { share: { url: result.url } } }),
31+
)
32+
return result
33+
})
34+
35+
const unshare = Effect.fn("SessionShare.unshare")(function* (sessionID: SessionID) {
36+
yield* shareNext.remove(sessionID)
37+
yield* Effect.sync(() => SyncEvent.run(Session.Event.Updated, { sessionID, info: { share: { url: null } } }))
38+
})
39+
40+
const create = Effect.fn("SessionShare.create")(function* (input?: Session.CreateInput) {
41+
const result = yield* session.create(input)
42+
if (result.parentID) return result
43+
const conf = yield* cfg.get()
44+
if (!(Flag.OPENCODE_AUTO_SHARE || conf.share === "auto")) return result
45+
yield* share(result.id).pipe(Effect.ignore, Effect.forkIn(scope))
46+
return result
47+
})
48+
49+
return Service.of({ create, share, unshare })
50+
}),
51+
)
52+
53+
export const defaultLayer = layer.pipe(
54+
Layer.provide(ShareNext.defaultLayer),
55+
Layer.provide(Session.defaultLayer),
56+
Layer.provide(Config.defaultLayer),
57+
)

0 commit comments

Comments
 (0)