mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-20 18:01:41 +00:00
Some checks are pending
publish / build-electron (map[host:windows-2025 platform_flag:--win --arm64 target:aarch64-pc-windows-msvc]) (push) Blocked by required conditions
publish / publish (push) Blocked by required conditions
storybook / storybook build (push) Waiting to run
test / unit (linux) (push) Waiting to run
test / unit (windows) (push) Waiting to run
test / e2e (linux) (push) Waiting to run
test / e2e (windows) (push) Waiting to run
typecheck / typecheck (push) Waiting to run
deploy / deploy (push) Waiting to run
generate / generate (push) Waiting to run
nix-eval / nix-eval (push) Waiting to run
nix-hashes / compute-hash (blacksmith-4vcpu-ubuntu-2404, x86_64-linux) (push) Waiting to run
nix-hashes / compute-hash (blacksmith-4vcpu-ubuntu-2404-arm, aarch64-linux) (push) Waiting to run
nix-hashes / compute-hash (macos-15-intel, x86_64-darwin) (push) Waiting to run
nix-hashes / compute-hash (macos-latest, aarch64-darwin) (push) Waiting to run
nix-hashes / update-hashes (push) Blocked by required conditions
publish / version (push) Waiting to run
publish / build-cli (push) Blocked by required conditions
publish / sign-cli-windows (push) Blocked by required conditions
publish / build-tauri (map[host:blacksmith-4vcpu-ubuntu-2404 target:x86_64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-tauri (map[host:blacksmith-4vcpu-windows-2025 target:x86_64-pc-windows-msvc]) (push) Blocked by required conditions
publish / build-tauri (map[host:blacksmith-8vcpu-ubuntu-2404-arm target:aarch64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-tauri (map[host:macos-latest target:aarch64-apple-darwin]) (push) Blocked by required conditions
publish / build-tauri (map[host:macos-latest target:x86_64-apple-darwin]) (push) Blocked by required conditions
publish / build-tauri (map[host:windows-2025 target:aarch64-pc-windows-msvc]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404 platform_flag:--linux target:aarch64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404 platform_flag:--linux target:x86_64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-windows-2025 platform_flag:--win target:x86_64-pc-windows-msvc]) (push) Blocked by required conditions
publish / build-electron (map[host:macos-latest platform_flag:--mac --arm64 target:aarch64-apple-darwin]) (push) Blocked by required conditions
publish / build-electron (map[host:macos-latest platform_flag:--mac --x64 target:x86_64-apple-darwin]) (push) Blocked by required conditions
53 lines
2.3 KiB
TypeScript
53 lines
2.3 KiB
TypeScript
import { Effect, Layer, ManagedRuntime } from "effect"
|
|
import * as Context from "effect/Context"
|
|
import { Instance } from "@/project/instance"
|
|
import { LocalContext } from "@/util/local-context"
|
|
import { InstanceRef, WorkspaceRef } from "./instance-ref"
|
|
import { Observability } from "./observability"
|
|
import { WorkspaceContext } from "@/control-plane/workspace-context"
|
|
import type { InstanceContext } from "@/project/instance"
|
|
|
|
export const memoMap = Layer.makeMemoMapUnsafe()
|
|
|
|
type Refs = {
|
|
instance?: InstanceContext
|
|
workspace?: string
|
|
}
|
|
|
|
export function attachWith<A, E, R>(effect: Effect.Effect<A, E, R>, refs: Refs): Effect.Effect<A, E, R> {
|
|
if (!refs.instance && !refs.workspace) return effect
|
|
if (!refs.instance) return effect.pipe(Effect.provideService(WorkspaceRef, refs.workspace))
|
|
if (!refs.workspace) return effect.pipe(Effect.provideService(InstanceRef, refs.instance))
|
|
return effect.pipe(
|
|
Effect.provideService(InstanceRef, refs.instance),
|
|
Effect.provideService(WorkspaceRef, refs.workspace),
|
|
)
|
|
}
|
|
|
|
export function attach<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> {
|
|
try {
|
|
return attachWith(effect, {
|
|
instance: Instance.current,
|
|
workspace: WorkspaceContext.workspaceID,
|
|
})
|
|
} catch (err) {
|
|
if (!(err instanceof LocalContext.NotFound)) throw err
|
|
}
|
|
return effect
|
|
}
|
|
|
|
export function makeRuntime<I, S, E>(service: Context.Service<I, S>, layer: Layer.Layer<I, E>) {
|
|
let rt: ManagedRuntime.ManagedRuntime<I, E> | undefined
|
|
const getRuntime = () => (rt ??= ManagedRuntime.make(Layer.provideMerge(layer, Observability.layer), { memoMap }))
|
|
|
|
return {
|
|
runSync: <A, Err>(fn: (svc: S) => Effect.Effect<A, Err, I>) => getRuntime().runSync(attach(service.use(fn))),
|
|
runPromiseExit: <A, Err>(fn: (svc: S) => Effect.Effect<A, Err, I>, options?: Effect.RunOptions) =>
|
|
getRuntime().runPromiseExit(attach(service.use(fn)), options),
|
|
runPromise: <A, Err>(fn: (svc: S) => Effect.Effect<A, Err, I>, options?: Effect.RunOptions) =>
|
|
getRuntime().runPromise(attach(service.use(fn)), options),
|
|
runFork: <A, Err>(fn: (svc: S) => Effect.Effect<A, Err, I>) => getRuntime().runFork(attach(service.use(fn))),
|
|
runCallback: <A, Err>(fn: (svc: S) => Effect.Effect<A, Err, I>) =>
|
|
getRuntime().runCallback(attach(service.use(fn))),
|
|
}
|
|
}
|