feat(server): add Hermes ACP adapter
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
4 files changed
+1142
-1
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* HermesAdapter — shape type for the Hermes provider adapter.
|
||||
*
|
||||
* The driver model ({@link ../Drivers/HermesDriver}) bundles one adapter per
|
||||
* instance as a captured closure, so this module only retains the shape
|
||||
* interface as a naming anchor for the driver bundle.
|
||||
*
|
||||
* @module HermesAdapter
|
||||
*/
|
||||
import type { ProviderAdapterError } from "../Errors.ts";
|
||||
import type { ProviderAdapterShape } from "./ProviderAdapter.ts";
|
||||
|
||||
/**
|
||||
* HermesAdapterShape — per-instance Hermes adapter contract.
|
||||
*/
|
||||
export interface HermesAdapterShape extends ProviderAdapterShape<ProviderAdapterError> {}
|
||||
@@ -1,6 +1,12 @@
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as EffectAcpErrors from "effect-acp/errors";
|
||||
|
||||
import { buildHermesAcpSpawnInput, HERMES_AUTH_METHOD_ID } from "./HermesAcpSupport.ts";
|
||||
import {
|
||||
applyHermesAcpModelSelection,
|
||||
buildHermesAcpSpawnInput,
|
||||
HERMES_AUTH_METHOD_ID,
|
||||
} from "./HermesAcpSupport.ts";
|
||||
|
||||
describe("buildHermesAcpSpawnInput", () => {
|
||||
it("spawns the configured binary with the acp subcommand", () => {
|
||||
@@ -43,3 +49,47 @@ describe("HERMES_AUTH_METHOD_ID", () => {
|
||||
expect(HERMES_AUTH_METHOD_ID).toBe("custom");
|
||||
});
|
||||
});
|
||||
|
||||
describe("applyHermesAcpModelSelection", () => {
|
||||
it.effect("passes the model id to session/set_model verbatim", () =>
|
||||
Effect.gen(function* () {
|
||||
const modelCalls: Array<string> = [];
|
||||
const runtime = {
|
||||
setModel: (model: string) =>
|
||||
Effect.sync(() => {
|
||||
modelCalls.push(model);
|
||||
}),
|
||||
};
|
||||
|
||||
yield* applyHermesAcpModelSelection({
|
||||
runtime,
|
||||
model: "anthropic:claude-fable-5",
|
||||
mapError: ({ cause }) => `failed to set model: ${cause.message}`,
|
||||
});
|
||||
|
||||
expect(modelCalls).toEqual(["anthropic:claude-fable-5"]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("maps set_model failures through mapError", () =>
|
||||
Effect.gen(function* () {
|
||||
const acpFailure = new EffectAcpErrors.AcpTransportError({
|
||||
detail: "set_model exploded",
|
||||
cause: new Error("set_model exploded"),
|
||||
});
|
||||
const runtime = {
|
||||
setModel: () => Effect.fail(acpFailure),
|
||||
};
|
||||
|
||||
const failure = yield* Effect.flip(
|
||||
applyHermesAcpModelSelection({
|
||||
runtime,
|
||||
model: "anthropic:claude-fable-5",
|
||||
mapError: ({ cause }) => ({ mapped: true as const, cause }),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(failure).toEqual({ mapped: true, cause: acpFailure });
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -58,3 +58,27 @@ export const makeHermesAcpRuntime = (
|
||||
Effect.provide(acpContext),
|
||||
);
|
||||
});
|
||||
|
||||
export interface HermesAcpModelSelectionErrorContext {
|
||||
readonly cause: EffectAcpErrors.AcpError;
|
||||
}
|
||||
|
||||
interface HermesAcpModelSelectionRuntime {
|
||||
readonly setModel: (model: string) => Effect.Effect<unknown, EffectAcpErrors.AcpError>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a model selection to a live Hermes ACP session. Hermes model ids
|
||||
* (e.g. `anthropic:claude-fable-5`) go to `session/set_model` verbatim —
|
||||
* there is no trait suffix to strip and no config-option fanout.
|
||||
*/
|
||||
export function applyHermesAcpModelSelection<E>(input: {
|
||||
readonly runtime: HermesAcpModelSelectionRuntime;
|
||||
readonly model: string;
|
||||
readonly mapError: (context: HermesAcpModelSelectionErrorContext) => E;
|
||||
}): Effect.Effect<void, E> {
|
||||
return input.runtime.setModel(input.model).pipe(
|
||||
Effect.asVoid,
|
||||
Effect.mapError((cause) => input.mapError({ cause })),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user