The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 2 | import { assert, it } from "@effect/vitest"; |
| 3 | import { ProviderInstanceId, type ModelSelection } from "@t3tools/contracts"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as Layer from "effect/Layer"; |
| 6 | import * as Ref from "effect/Ref"; |
| 7 | |
| 8 | import * as ProviderRegistry from "../provider/ProviderRegistry.ts"; |
| 9 | import * as ServerSettings from "../serverSettings.ts"; |
| 10 | import * as TextGeneration from "../textGeneration/TextGeneration.ts"; |
| 11 | import * as SpeechPostProcessing from "./postProcessing.ts"; |
| 12 | |
| 13 | const textGenerationSelection = { |
| 14 | instanceId: ProviderInstanceId.make("fakeapi"), |
| 15 | model: "fake-model", |
| 16 | }; |
| 17 | const acpSelection = { instanceId: ProviderInstanceId.make("acp_local"), model: "default" }; |
| 18 | |
| 19 | it.effect("cleanup pinned to a provider that cannot generate text uses the text model", () => |
| 20 | Effect.gen(function* () { |
| 21 | const used = yield* Ref.make<ModelSelection | null>(null); |
| 22 | const layer = SpeechPostProcessing.layer.pipe( |
| 23 | Layer.provide( |
| 24 | Layer.succeed(TextGeneration.TextGeneration, { |
| 25 | generateTranscriptionPostProcessing: (input: { modelSelection: ModelSelection }) => |
| 26 | Ref.set(used, input.modelSelection).pipe(Effect.as({ transcription: "Hello, world." })), |
| 27 | } as unknown as TextGeneration.TextGeneration["Service"]), |
| 28 | ), |
| 29 | Layer.provide( |
| 30 | Layer.succeed(ProviderRegistry.ProviderRegistry, { |
| 31 | getProviders: Effect.succeed([ |
| 32 | { |
| 33 | instanceId: acpSelection.instanceId, |
| 34 | driver: "acpRegistry", |
| 35 | enabled: true, |
| 36 | installed: true, |
| 37 | supportsTextGeneration: false, |
| 38 | }, |
| 39 | ]), |
| 40 | } as unknown as ProviderRegistry.ProviderRegistry["Service"]), |
| 41 | ), |
| 42 | Layer.provide( |
| 43 | ServerSettings.layerTest({ |
| 44 | providerInstances: { |
| 45 | [acpSelection.instanceId]: { |
| 46 | driver: "acpRegistry", |
| 47 | enabled: true, |
| 48 | config: { source: "local", commandPath: "acp-agent" }, |
| 49 | }, |
| 50 | }, |
| 51 | textGenerators: { |
| 52 | [textGenerationSelection.instanceId]: { |
| 53 | kind: "openaiCompatible", |
| 54 | baseUrl: "http://127.0.0.1:18999/v1", |
| 55 | enabled: true, |
| 56 | }, |
| 57 | }, |
| 58 | textGenerationModelSelection: textGenerationSelection, |
| 59 | speechPostProcessingModelSelection: acpSelection, |
| 60 | }), |
| 61 | ), |
| 62 | Layer.provide(NodeServices.layer), |
| 63 | ); |
| 64 | yield* Effect.gen(function* () { |
| 65 | const postProcessing = yield* SpeechPostProcessing.SpeechPostProcessing; |
| 66 | yield* postProcessing.process({ |
| 67 | options: { |
| 68 | speechCustomWords: [], |
| 69 | speechPostProcessingPrompt: { mode: "default", customInstructions: "" }, |
| 70 | }, |
| 71 | transcript: "um hello world", |
| 72 | draft: { text: "", selection: { start: 0, end: 0 } }, |
| 73 | } as never); |
| 74 | }).pipe(Effect.provide(layer)); |
| 75 | const selection = yield* Ref.get(used); |
| 76 | assert.deepStrictEqual( |
| 77 | { instanceId: selection?.instanceId, model: selection?.model }, |
| 78 | textGenerationSelection, |
| 79 | ); |
| 80 | }), |
| 81 | ); |