GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — opencode/packages/opencode/src/acp/directory.ts at dev · githubhjs/opencode Expand file tree/ Copy pathdirectory.tsMore file actions 212 lines (189 loc) · 7.1 KB / Copy pathdirectory.tsFile metadata and controls212 lines (189 loc) · 7.1 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 import { Agent } from "@/agent/agent" import { Command } from "@/command" import { InstanceRef } from "@/effect/instance-ref" import { InstanceBootstrap } from "@/project/bootstrap" import { InstanceStore } from "@/project/instance-store" import { LayerNode } from "@opencode-ai/core/effect/layer-node" import { ProviderV2 } from "@opencode-ai/core/provider" import { ModelV2 } from "@opencode-ai/core/model" import { Provider } from "@/provider/provider" import { Context, Effect, Layer, SynchronizedRef } from "effect" import type * as ACPError from "./error" export type ModelOption = { readonly providerID: ProviderV2.ID readonly providerName: string readonly modelID: ModelV2.ID readonly modelName: string } export type ModeOption = { readonly id: string readonly name: string readonly description?: string } export type ModelVariants = NonNullable<Provider.Model["variants"]> export type DefaultModel = { readonly providerID: ProviderV2.ID readonly modelID: ModelV2.ID } export type Snapshot = { readonly directory: string readonly providers: Record<ProviderV2.ID, Provider.Info> readonly modelOptions: readonly ModelOption[] readonly variantsByModel: Readonly<Record<string, ModelVariants>> readonly availableModes: readonly ModeOption[] readonly defaultModeID: string readonly availableCommands: readonly Command.Info[] readonly defaultModel?: DefaultModel } export interface LoaderInterface { readonly load: (directory: string) => Effect.Effect<Snapshot, ACPError.Error> } export interface Interface { readonly get: (directory: string) => Effect.Effect<Snapshot, ACPError.Error> readonly refresh: (directory: string) => Effect.Effect<Snapshot, ACPError.Error> readonly variants: (snapshot: Snapshot, model: DefaultModel) => ModelVariants | undefined } export class Loader extends Context.Service<Loader, LoaderInterface>()("@opencode/ACPDirectoryLoader") {} export class Service extends Context.Service<Service, Interface>()("@opencode/ACPDirectory") {} export const modelKey = (model: DefaultModel) => `${model.providerID}/${model.modelID}` export const variants = (snapshot: Snapshot, model: DefaultModel) => snapshot.variantsByModel[modelKey(model)] export const build = (input: { readonly directory: string readonly providers: Record<ProviderV2.ID, Provider.Info> readonly modes: readonly ModeOption[] readonly defaultModeID: string readonly commands: readonly Command.Info[] readonly defaultModel?: DefaultModel }): Snapshot => { const modelOptions = Provider.sort( Object.values(input.providers).flatMap((provider) => Object.values(provider.models).map((model) => ({ id: model.id, providerID: provider.id, providerName: provider.name, modelID: model.id, modelName: model.name, })), ), ).map((model) => ({ providerID: model.providerID, providerName: model.providerName, modelID: model.modelID, modelName: model.modelName, })) return { directory: input.directory, providers: input.providers, modelOptions, variantsByModel: Object.fromEntries( Object.values(input.providers).flatMap((provider) => Object.values(provider.models).flatMap((model) => model.variants ? [[modelKey({ providerID: provider.id, modelID: model.id }), model.variants]] : [], ), ), ), availableModes: input.modes, defaultModeID: input.modes.some((mode) => mode.id === input.defaultModeID) ? input.defaultModeID : (input.modes[0]?.id ?? input.defaultModeID), availableCommands: input.commands, ...(input.defaultModel ? { defaultModel: input.defaultModel } : {}), } } export const loaderLayer = Layer.effect( Loader, Effect.gen(function* () { const store = yield* InstanceStore.Service const provider = yield* Provider.Service const agent = yield* Agent.Service const command = yield* Command.Service return Loader.of({ load: Effect.fn("ACPDirectoryLoader.load")(function* (directory) { const ctx = yield* store.load({ directory }) return yield* Effect.gen(function* () { const providers = yield* provider.list() const [agents, defaultAgent, commands, defaultModel] = yield* Effect.all( [agent.list(), agent.defaultInfo(), command.list(), provider.defaultModel().pipe(Effect.option)], { concurrency: "unbounded" }, ) return build({ directory, providers, modes: agents .filter((item) => item.mode !== "subagent" && item.hidden !== true) .map((item) => ({ id: item.name, name: item.name, ...(item.description ? { description: item.description } : {}), })), defaultModeID: defaultAgent.name, commands: commands.toSorted((a, b) => a.name.localeCompare(b.name)), ...(defaultModel._tag === "Some" ? { defaultModel: defaultModel.value } : {}), }) }).pipe(Effect.provideService(InstanceRef, ctx)) }), }) }), ) const layer = Layer.effect( Service, Effect.gen(function* () { const loader = yield* Loader const snapshots = yield* SynchronizedRef.make(new Map<string, Effect.Effect<Snapshot, ACPError.Error>>()) const cached = Effect.fnUntraced(function* (directory: string) { return yield* SynchronizedRef.modifyEffect( snapshots, Effect.fnUntraced(function* (items) { const current = items.get(directory) if (current) return [current, items] as const const next = yield* Effect.cached( loader.load(directory).pipe( Effect.tapError(() => SynchronizedRef.update(snapshots, (state) => { const next = new Map(state) next.delete(directory) return next }), ), ), ) return [next, new Map(items).set(directory, next)] as const }), ) }) const get = Effect.fn("ACPDirectory.get")(function* (directory: string) { return yield* yield* cached(directory) }) const refresh = Effect.fn("ACPDirectory.refresh")(function* (directory: string) { return yield* SynchronizedRef.modifyEffect( snapshots, Effect.fnUntraced(function* (items) { const next = yield* Effect.cached( loader.load(directory).pipe( Effect.tapError(() => SynchronizedRef.update(snapshots, (state) => { const next = new Map(state) next.delete(directory) return next }), ), ), ) return [next, new Map(items).set(directory, next)] as const }), ).pipe(Effect.flatten) }) return Service.of({ get, refresh, variants, }) }), ) export const loaderNode = LayerNode.make({ service: Loader, layer: loaderLayer, deps: [Provider.node, Agent.node, Command.node, InstanceStore.node], }) export const node = LayerNode.make({ service: Service, layer, deps: [loaderNode] }) export * as Directory from "./directory" |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |