feat(provider-hermes): add Hermes Agent as a first-party provider on v0.1.0
Ports the earlier (pre-refactor) Hermes Agent ACP integration onto the current per-provider-package architecture (packages/provider-<name>/), following packages/provider-grok and packages/provider-muse as templates. - packages/provider-hermes: settings schema, ACP support (spawns `hermes acp`), status/snapshot probing, text generation, orchestration v2 adapter, and driver -- mirrors the existing providers file-for-file so future upstream syncs can diff/update it the same way. - Registered in apps/server/src/provider/builtInDrivers.ts and the server/web/mobile provider-client registries (settingsSecrets.ts, providerDriverMeta.ts, providerClients.ts) so it surfaces as a normal selectable provider everywhere the server's provider list is consumed. - Added as a workspace dependency of apps/server, apps/web, apps/mobile. Deliberately left out: the old standalone 'Hermes Workspace' dashboard- chat-viewer tab (web/mobile) -- out of scope per explicit instruction; this is provider/model-picker support only. Verified: pnpm typecheck passes clean for provider-hermes, apps/server, apps/web, apps/mobile. pnpm --filter t3 build succeeds. A live server instance (isolated HOME/port) started cleanly and produced a normal .t3/caches/hermes.json snapshot identical in shape to every other built-in provider (grok/muse/cursor/opencode/antigravity/pi), proving the driver initializes and participates in the registry correctly.
This commit is contained in:
1 parent
81493efb71
commit
dd66f9e578
19 files changed
+1159
-9
No files matched your search
@@ -73,6 +73,7 @@
|
||||
"@t3tools/provider-core": "workspace:*",
|
||||
"@t3tools/provider-cursor": "workspace:*",
|
||||
"@t3tools/provider-grok": "workspace:*",
|
||||
"@t3tools/provider-hermes": "workspace:*",
|
||||
"@t3tools/provider-muse": "workspace:*",
|
||||
"@t3tools/provider-opencode": "workspace:*",
|
||||
"@t3tools/provider-pi": "workspace:*",
|
||||
|
||||
@@ -3,6 +3,7 @@ import { acpRegistryClient } from "@t3tools/provider-acp-registry/client";
|
||||
import { makeProviderClientRegistry } from "@t3tools/provider-core/client";
|
||||
import { cursorClient } from "@t3tools/provider-cursor/client";
|
||||
import { grokClient } from "@t3tools/provider-grok/client";
|
||||
import { hermesClient } from "@t3tools/provider-hermes/client";
|
||||
import { museClient } from "@t3tools/provider-muse/client";
|
||||
import { openCodeClient } from "@t3tools/provider-opencode/client";
|
||||
import { piClient } from "@t3tools/provider-pi/client";
|
||||
@@ -11,6 +12,7 @@ import { piClient } from "@t3tools/provider-pi/client";
|
||||
const providerClients = makeProviderClientRegistry([
|
||||
cursorClient,
|
||||
grokClient,
|
||||
hermesClient,
|
||||
museClient,
|
||||
openCodeClient,
|
||||
piClient,
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
"@t3tools/provider-core": "workspace:*",
|
||||
"@t3tools/provider-cursor": "workspace:*",
|
||||
"@t3tools/provider-grok": "workspace:*",
|
||||
"@t3tools/provider-hermes": "workspace:*",
|
||||
"@t3tools/provider-muse": "workspace:*",
|
||||
"@t3tools/provider-opencode": "workspace:*",
|
||||
"@t3tools/provider-pi": "workspace:*",
|
||||
|
||||
@@ -29,6 +29,7 @@ import { ClaudeDriver, type ClaudeDriverEnv } from "./Drivers/ClaudeDriver.ts";
|
||||
import { CodexDriver, type CodexDriverEnv } from "./Drivers/CodexDriver.ts";
|
||||
import { CursorDriver, type CursorDriverEnv } from "@t3tools/provider-cursor/server";
|
||||
import { GrokDriver, type GrokDriverEnv } from "@t3tools/provider-grok/server";
|
||||
import { HermesDriver, type HermesDriverEnv } from "@t3tools/provider-hermes/server";
|
||||
import { OpenCodeDriver, type OpenCodeDriverEnv } from "@t3tools/provider-opencode/server";
|
||||
import { MuseDriver, type MuseDriverEnv } from "@t3tools/provider-muse/server";
|
||||
import { PiDriver, type PiDriverEnv } from "@t3tools/provider-pi/server";
|
||||
@@ -49,6 +50,7 @@ export type BuiltInDriversEnv =
|
||||
| CodexDriverEnv
|
||||
| CursorDriverEnv
|
||||
| GrokDriverEnv
|
||||
| HermesDriverEnv
|
||||
| OpenCodeDriverEnv
|
||||
| PiDriverEnv
|
||||
| MuseDriverEnv;
|
||||
@@ -63,6 +65,7 @@ export const BUILT_IN_DRIVERS: ReadonlyArray<AnyProviderDriver<BuiltInDriversEnv
|
||||
ClaudeDriver,
|
||||
CursorDriver,
|
||||
GrokDriver,
|
||||
HermesDriver,
|
||||
OpenCodeDriver,
|
||||
AntigravityDriver,
|
||||
PiDriver,
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
import { acpRegistryClient } from "@t3tools/provider-acp-registry/client";
|
||||
import { cursorClient } from "@t3tools/provider-cursor/client";
|
||||
import { grokClient } from "@t3tools/provider-grok/client";
|
||||
import { hermesClient } from "@t3tools/provider-hermes/client";
|
||||
import { museClient } from "@t3tools/provider-muse/client";
|
||||
import { openCodeClient } from "@t3tools/provider-opencode/client";
|
||||
import { piClient } from "@t3tools/provider-pi/client";
|
||||
@@ -25,7 +26,15 @@ const providerSecretFields = new Map([
|
||||
["codex", secretSettingsFields(CodexSettings)],
|
||||
["claudeAgent", secretSettingsFields(ClaudeSettings)],
|
||||
["antigravity", secretSettingsFields(AntigravitySettings)],
|
||||
...[cursorClient, grokClient, museClient, openCodeClient, piClient, acpRegistryClient].map(
|
||||
...[
|
||||
cursorClient,
|
||||
grokClient,
|
||||
hermesClient,
|
||||
museClient,
|
||||
openCodeClient,
|
||||
piClient,
|
||||
acpRegistryClient,
|
||||
].map(
|
||||
(definition) =>
|
||||
[definition.driverKind, secretSettingsFields(definition.settingsSchema)] as const,
|
||||
),
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
"@t3tools/provider-core": "workspace:*",
|
||||
"@t3tools/provider-cursor": "workspace:*",
|
||||
"@t3tools/provider-grok": "workspace:*",
|
||||
"@t3tools/provider-hermes": "workspace:*",
|
||||
"@t3tools/provider-muse": "workspace:*",
|
||||
"@t3tools/provider-opencode": "workspace:*",
|
||||
"@t3tools/provider-pi": "workspace:*",
|
||||
|
||||
@@ -8,6 +8,7 @@ import { acpRegistryClient } from "@t3tools/provider-acp-registry/client";
|
||||
import { makeProviderClientRegistry } from "@t3tools/provider-core/client";
|
||||
import { cursorClient } from "@t3tools/provider-cursor/client";
|
||||
import { grokClient } from "@t3tools/provider-grok/client";
|
||||
import { hermesClient } from "@t3tools/provider-hermes/client";
|
||||
import { museClient } from "@t3tools/provider-muse/client";
|
||||
import { openCodeClient } from "@t3tools/provider-opencode/client";
|
||||
import { piClient } from "@t3tools/provider-pi/client";
|
||||
@@ -26,6 +27,7 @@ export const providerClients = makeProviderClientRegistry([
|
||||
},
|
||||
cursorClient,
|
||||
grokClient,
|
||||
hermesClient,
|
||||
openCodeClient,
|
||||
{
|
||||
driverKind: ProviderDriverKind.make("antigravity"),
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "@t3tools/provider-hermes",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./client": {
|
||||
"types": "./src/client.ts",
|
||||
"import": "./src/client.ts"
|
||||
},
|
||||
"./settings": {
|
||||
"types": "./src/settings.ts",
|
||||
"import": "./src/settings.ts"
|
||||
},
|
||||
"./server": {
|
||||
"types": "./src/server.ts",
|
||||
"import": "./src/server.ts"
|
||||
},
|
||||
"./testing": {
|
||||
"types": "./src/testing.ts",
|
||||
"import": "./src/testing.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc-rs --noEmit",
|
||||
"test": "vp test run --config ../../vite.config.ts --dir ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/provider-acp": "workspace:*",
|
||||
"@t3tools/provider-core": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"effect": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@effect/vitest": "catalog:",
|
||||
"@t3tools/provider-testing": "workspace:*",
|
||||
"@types/node": "catalog:",
|
||||
"effect-acp": "workspace:*",
|
||||
"vite-plus": "catalog:"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Hermes Agent's client definition: settings form, label, badge, and glyph.
|
||||
* Browser- and React Native-safe.
|
||||
*
|
||||
* @module provider-hermes/client
|
||||
*/
|
||||
import { ProviderDriverKind } from "@t3tools/contracts";
|
||||
import { defineProviderClient } from "@t3tools/provider-core/client";
|
||||
|
||||
import { HermesSettings } from "./settings.ts";
|
||||
|
||||
export const hermesClient = defineProviderClient({
|
||||
driverKind: ProviderDriverKind.make("hermes"),
|
||||
label: "Hermes",
|
||||
settingsSchema: HermesSettings,
|
||||
badgeLabel: "Experimental",
|
||||
// Simple stylized "H" glyph — Hermes has no official brand mark to mirror here.
|
||||
icon: {
|
||||
viewBox: "0 0 24 24",
|
||||
fill: { light: "#7c3aed", dark: "#a78bfa" },
|
||||
paths: [
|
||||
{
|
||||
d: "M5 3h3v8.2L12 7l4 4.2V3h3v18h-3v-8.2L12 17l-4-4.2V21H5V3z",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Hermes Agent's server entry: the driver the server registers, plus the
|
||||
* adapter factory the replay testkit and fixture recorder build on.
|
||||
*
|
||||
* @module provider-hermes/server
|
||||
*/
|
||||
export { HermesDriver, type HermesDriverEnv } from "./server/driver.ts";
|
||||
export { makeHermesAdapterV2, type HermesAdapterV2Options } from "./server/adapter.ts";
|
||||
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* Hermes Agent ACP support — spawns `hermes acp` and exposes the handful of
|
||||
* helpers the driver/adapter/status/textGeneration modules share.
|
||||
*
|
||||
* Hermes exposes a plain ACP agent with no provider-specific extensions
|
||||
* (unlike Grok's x.ai/* extensions), so this file is intentionally much
|
||||
* smaller than its Grok/OpenCode equivalents.
|
||||
*
|
||||
* @module provider-hermes/server/acpSupport
|
||||
*/
|
||||
import type { HermesSettings } from "../settings.ts";
|
||||
import * as Crypto from "effect/Crypto";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Scope from "effect/Scope";
|
||||
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
||||
import * as EffectAcpErrors from "effect-acp/errors";
|
||||
import type * as EffectAcpSchema from "effect-acp/compat";
|
||||
|
||||
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
|
||||
/** Auth method advertised by `hermes acp` for pre-configured runtime credentials. */
|
||||
const HERMES_AUTH_METHOD_ID = "custom";
|
||||
|
||||
/**
|
||||
* The product slug T3 publishes for "whatever model Hermes is configured to
|
||||
* use". It is never a real ACP model id, so it must never reach
|
||||
* `session/set_model` — selecting it keeps the session on its current model.
|
||||
*/
|
||||
export const HERMES_DEFAULT_MODEL_SLUG = "default";
|
||||
|
||||
type HermesAcpRuntimeHermesSettings = Pick<HermesSettings, "binaryPath">;
|
||||
|
||||
interface HermesAcpRuntimeInput extends Omit<
|
||||
AcpSessionRuntime.AcpSessionRuntimeOptions,
|
||||
"authMethodId" | "clientCapabilities" | "spawn"
|
||||
> {
|
||||
readonly hermesSettings: HermesAcpRuntimeHermesSettings | null | undefined;
|
||||
readonly environment?: NodeJS.ProcessEnv;
|
||||
}
|
||||
|
||||
export function buildHermesAcpSpawnInput(
|
||||
hermesSettings: HermesAcpRuntimeHermesSettings | null | undefined,
|
||||
cwd: string,
|
||||
environment?: NodeJS.ProcessEnv,
|
||||
): AcpSessionRuntime.AcpSpawnInput {
|
||||
return {
|
||||
command: hermesSettings?.binaryPath || "hermes",
|
||||
args: ["acp"],
|
||||
cwd,
|
||||
...(environment ? { env: environment } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export const makeHermesAcpRuntime = (
|
||||
input: HermesAcpRuntimeInput,
|
||||
): Effect.Effect<
|
||||
AcpSessionRuntime.AcpSessionRuntime["Service"],
|
||||
EffectAcpErrors.AcpError,
|
||||
ChildProcessSpawner.ChildProcessSpawner | Crypto.Crypto | Scope.Scope
|
||||
> =>
|
||||
Effect.gen(function* () {
|
||||
const acpContext = yield* Layer.build(
|
||||
AcpSessionRuntime.layer({
|
||||
...input,
|
||||
spawn: buildHermesAcpSpawnInput(input.hermesSettings, input.cwd, input.environment),
|
||||
authMethodId: HERMES_AUTH_METHOD_ID,
|
||||
}),
|
||||
);
|
||||
return yield* Effect.service(AcpSessionRuntime.AcpSessionRuntime).pipe(
|
||||
Effect.provide(acpContext),
|
||||
);
|
||||
});
|
||||
|
||||
export function resolveHermesAcpBaseModelId(model: string | null | undefined): string {
|
||||
const trimmed = model?.trim();
|
||||
return trimmed && trimmed.length > 0 ? trimmed : HERMES_DEFAULT_MODEL_SLUG;
|
||||
}
|
||||
|
||||
export function currentHermesModelIdFromSessionSetup(
|
||||
sessionSetupResult:
|
||||
| EffectAcpSchema.LoadSessionResponse
|
||||
| EffectAcpSchema.NewSessionResponse
|
||||
| EffectAcpSchema.ResumeSessionResponse,
|
||||
): string | undefined {
|
||||
return sessionSetupResult.models?.currentModelId?.trim() || undefined;
|
||||
}
|
||||
|
||||
type HermesAcpModelSelectionRuntime = Pick<
|
||||
AcpSessionRuntime.AcpSessionRuntime["Service"],
|
||||
"setSessionModel"
|
||||
>;
|
||||
|
||||
/**
|
||||
* 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 reasoning metadata to attach.
|
||||
* Nothing is sent when the selection is empty, is the `default` product slug
|
||||
* (which stands for the session's already-configured model, not a real ACP
|
||||
* id), or already matches the session's current model.
|
||||
*/
|
||||
export function applyHermesAcpModelSelection<E>(input: {
|
||||
readonly runtime: HermesAcpModelSelectionRuntime;
|
||||
readonly currentModelId: string | undefined;
|
||||
readonly model: string;
|
||||
readonly mapError: (cause: EffectAcpErrors.AcpError) => E;
|
||||
}): Effect.Effect<void, E> {
|
||||
const requestedModelId = input.model.trim();
|
||||
if (
|
||||
requestedModelId.length === 0 ||
|
||||
requestedModelId === HERMES_DEFAULT_MODEL_SLUG ||
|
||||
requestedModelId === input.currentModelId
|
||||
) {
|
||||
return Effect.void;
|
||||
}
|
||||
return input.runtime
|
||||
.setSessionModel(requestedModelId)
|
||||
.pipe(Effect.asVoid, Effect.mapError(input.mapError));
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
|
||||
import * as HostProcess from "@t3tools/shared/HostProcess";
|
||||
import { resolveSelfInvocation, type SelfInvocation } from "@t3tools/shared/nodeRuntime";
|
||||
import {
|
||||
defaultInstanceIdForDriver,
|
||||
ProviderDriverKind,
|
||||
type OrchestrationV2ProviderCapabilities,
|
||||
} from "@t3tools/contracts";
|
||||
import { HermesSettings } from "../settings.ts";
|
||||
import * as Crypto from "effect/Crypto";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Schema from "effect/Schema";
|
||||
import type * as Scope from "effect/Scope";
|
||||
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
||||
import * as EffectAcpErrors from "effect-acp/errors";
|
||||
|
||||
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
|
||||
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
|
||||
import { makeAcpNativeLoggerFactory } from "@t3tools/provider-acp/server/nativeLogging";
|
||||
import { makeHermesAcpRuntime, resolveHermesAcpBaseModelId } from "./acpSupport.ts";
|
||||
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
|
||||
import { acpPermissionDisposition } from "@t3tools/provider-acp/server/clientPolicy";
|
||||
import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers";
|
||||
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
|
||||
import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests";
|
||||
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
|
||||
import {
|
||||
ProviderAdapterDriverCreateError,
|
||||
type ProviderAdapterDriver,
|
||||
type ProviderAdapterDriverCreateInput,
|
||||
} from "@t3tools/provider-core/server/adapterDriver";
|
||||
import {
|
||||
AcpProviderCapabilitiesV2,
|
||||
makeAcpAdapterV2,
|
||||
type AcpAdapterV2Flavor,
|
||||
} from "@t3tools/provider-acp/server/adapter";
|
||||
|
||||
export const HERMES_PROVIDER = ProviderDriverKind.make("hermes");
|
||||
const HERMES_DRIVER_KIND = HERMES_PROVIDER;
|
||||
export const HERMES_DEFAULT_INSTANCE_ID = defaultInstanceIdForDriver(HERMES_DRIVER_KIND);
|
||||
const DEFAULT_HERMES_SETTINGS = Schema.decodeSync(HermesSettings)({});
|
||||
const isAcpRequestError = Schema.is(EffectAcpErrors.AcpRequestError);
|
||||
|
||||
/** Hermes exposes a plain ACP agent; it reports session/set_model support but no exotic features. */
|
||||
export const HermesProviderCapabilitiesV2 = {
|
||||
...AcpProviderCapabilitiesV2,
|
||||
sessions: {
|
||||
...AcpProviderCapabilitiesV2.sessions,
|
||||
supportsModelSwitchInSession: true,
|
||||
},
|
||||
} satisfies OrchestrationV2ProviderCapabilities;
|
||||
|
||||
export interface HermesAdapterV2Options {
|
||||
readonly instanceId: Parameters<typeof makeAcpAdapterV2>[0]["instanceId"];
|
||||
readonly settings: HermesSettings;
|
||||
readonly environment: NodeJS.ProcessEnv;
|
||||
readonly selfInvocation: SelfInvocation;
|
||||
readonly nativeLogging?: Parameters<typeof makeAcpAdapterV2>[0]["nativeLogging"];
|
||||
readonly continuationRequests?: Parameters<typeof makeAcpAdapterV2>[0]["continuationRequests"];
|
||||
readonly testHooks?: Parameters<typeof makeAcpAdapterV2>[0]["testHooks"];
|
||||
}
|
||||
|
||||
/** The flavor runs Hermes's launcher (`hermes acp`) through the adapter's spawner. */
|
||||
export function makeHermesAcpAdapterFlavor(options: HermesAdapterV2Options): AcpAdapterV2Flavor {
|
||||
return {
|
||||
driver: HERMES_PROVIDER,
|
||||
runtimeHarness: "Hermes",
|
||||
capabilities: HermesProviderCapabilitiesV2,
|
||||
resolveModelId: (selection) => resolveHermesAcpBaseModelId(selection.model),
|
||||
makeRuntime: ({ runtimePolicy: _runtimePolicy, ...input }) =>
|
||||
makeHermesAcpRuntime({
|
||||
...input,
|
||||
hermesSettings: options.settings,
|
||||
environment: options.environment,
|
||||
}),
|
||||
permissionDisposition: acpPermissionDisposition,
|
||||
promptFailure: (cause) =>
|
||||
makeProviderFailure({
|
||||
cause,
|
||||
...(isAcpRequestError(cause)
|
||||
? { message: cause.errorMessage, code: String(cause.code), class: "provider_error" }
|
||||
: { class: "provider_error" }),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export const makeHermesAdapterV2 = Effect.fn("makeHermesAdapterV2")(function* (
|
||||
options: HermesAdapterV2Options,
|
||||
) {
|
||||
return yield* makeAcpAdapterV2({
|
||||
instanceId: options.instanceId,
|
||||
flavor: makeHermesAcpAdapterFlavor(options),
|
||||
selfInvocation: options.selfInvocation,
|
||||
...(options.nativeLogging === undefined ? {} : { nativeLogging: options.nativeLogging }),
|
||||
...(options.continuationRequests === undefined
|
||||
? {}
|
||||
: { continuationRequests: options.continuationRequests }),
|
||||
...(options.testHooks === undefined ? {} : { testHooks: options.testHooks }),
|
||||
});
|
||||
});
|
||||
|
||||
export type HermesAdapterV2DriverEnv =
|
||||
| ChildProcessSpawner.ChildProcessSpawner
|
||||
| Crypto.Crypto
|
||||
| FileSystem.FileSystem
|
||||
| IdAllocator.IdAllocatorV2
|
||||
| Path.Path
|
||||
| McpProviderSessions.McpProviderSessions
|
||||
| ProviderEventLoggers.ProviderEventLoggers
|
||||
| ProviderHost.ProviderHost;
|
||||
|
||||
export const HermesAdapterV2Driver: ProviderAdapterDriver<
|
||||
HermesSettings,
|
||||
HermesAdapterV2DriverEnv
|
||||
> = {
|
||||
driverKind: HERMES_DRIVER_KIND,
|
||||
configSchema: HermesSettings,
|
||||
defaultConfig: (): HermesSettings => DEFAULT_HERMES_SETTINGS,
|
||||
create: Effect.fn("HermesAdapterV2Driver.create")(
|
||||
function* (input: ProviderAdapterDriverCreateInput<HermesSettings>) {
|
||||
const hostEnvironment = yield* HostProcess.Environment;
|
||||
const selfInvocation = yield* resolveSelfInvocation();
|
||||
const providerEventLoggers = yield* ProviderEventLoggers.ProviderEventLoggers;
|
||||
const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests;
|
||||
const makeNativeLogger = yield* makeAcpNativeLoggerFactory();
|
||||
return yield* makeHermesAdapterV2({
|
||||
instanceId: input.instanceId,
|
||||
settings: { ...input.config, enabled: input.enabled },
|
||||
environment: yield* mergeProviderInstanceEnvironment(input.environment, hostEnvironment),
|
||||
selfInvocation,
|
||||
continuationRequests,
|
||||
nativeLogging: (threadId) =>
|
||||
makeNativeLogger({
|
||||
nativeEventLogger: providerEventLoggers.native,
|
||||
provider: HERMES_PROVIDER,
|
||||
threadId,
|
||||
}),
|
||||
});
|
||||
},
|
||||
(effect, input) =>
|
||||
effect.pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new ProviderAdapterDriverCreateError({
|
||||
driver: HERMES_DRIVER_KIND,
|
||||
instanceId: input.instanceId,
|
||||
detail: "Failed to create Hermes ACP adapter.",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
};
|
||||
|
||||
const layer: Layer.Layer<
|
||||
ProviderAdapter.ProviderAdapterV2,
|
||||
never,
|
||||
| Path.Path
|
||||
| ChildProcessSpawner.ChildProcessSpawner
|
||||
| Crypto.Crypto
|
||||
| FileSystem.FileSystem
|
||||
| IdAllocator.IdAllocatorV2
|
||||
| McpProviderSessions.McpProviderSessions
|
||||
| ProviderEventLoggers.ProviderEventLoggers
|
||||
| ProviderHost.ProviderHost
|
||||
> = Layer.effect(
|
||||
ProviderAdapter.ProviderAdapterV2,
|
||||
Effect.gen(function* () {
|
||||
const hostEnvironment = yield* HostProcess.Environment;
|
||||
const selfInvocation = yield* resolveSelfInvocation();
|
||||
const providerEventLoggers = yield* ProviderEventLoggers.ProviderEventLoggers;
|
||||
const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests;
|
||||
const makeNativeLogger = yield* makeAcpNativeLoggerFactory();
|
||||
return yield* makeHermesAdapterV2({
|
||||
instanceId: HERMES_DEFAULT_INSTANCE_ID,
|
||||
settings: DEFAULT_HERMES_SETTINGS,
|
||||
environment: hostEnvironment,
|
||||
selfInvocation,
|
||||
continuationRequests,
|
||||
nativeLogging: (threadId) =>
|
||||
makeNativeLogger({
|
||||
nativeEventLogger: providerEventLoggers.native,
|
||||
provider: HERMES_PROVIDER,
|
||||
threadId,
|
||||
}),
|
||||
});
|
||||
}),
|
||||
);
|
||||
@@ -0,0 +1,171 @@
|
||||
import { ProviderDriverKind } from "@t3tools/contracts";
|
||||
import { HermesSettings } from "../settings.ts";
|
||||
import * as Crypto from "effect/Crypto";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as HttpClient from "effect/http/HttpClient";
|
||||
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
||||
|
||||
import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions";
|
||||
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
|
||||
import { makeHermesTextGeneration } from "./textGeneration.ts";
|
||||
import { HermesAdapterV2Driver, type HermesAdapterV2DriverEnv } from "./adapter.ts";
|
||||
import { ProviderDriverError } from "@t3tools/provider-core/server/errors";
|
||||
import {
|
||||
buildInitialHermesProviderSnapshot,
|
||||
checkHermesProviderStatus,
|
||||
enrichHermesSnapshot,
|
||||
} from "./status.ts";
|
||||
import { makeManagedServerProvider } from "@t3tools/provider-core/server/managedProvider";
|
||||
import {
|
||||
defaultProviderContinuationIdentity,
|
||||
type ProviderDriver,
|
||||
type ProviderInstance,
|
||||
} from "@t3tools/provider-core/server/driver";
|
||||
import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
|
||||
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
|
||||
import {
|
||||
makeCachedProviderMaintenanceResolution,
|
||||
makeManualOnlyProviderMaintenanceCapabilities,
|
||||
} from "@t3tools/provider-core/server/maintenanceResolver";
|
||||
import {
|
||||
haveProviderSnapshotSettingsChanged,
|
||||
makeProviderSnapshotSettingsSource,
|
||||
type ProviderSnapshotSettings,
|
||||
} from "@t3tools/provider-core/server/snapshotSettings";
|
||||
|
||||
const decodeHermesSettings = Schema.decodeSync(HermesSettings);
|
||||
|
||||
const DRIVER_KIND = ProviderDriverKind.make("hermes");
|
||||
|
||||
export type HermesDriverEnv =
|
||||
| HermesAdapterV2DriverEnv
|
||||
| ProviderHost.ProviderHost
|
||||
| ChildProcessSpawner.ChildProcessSpawner
|
||||
| Crypto.Crypto
|
||||
| FileSystem.FileSystem
|
||||
| HttpClient.HttpClient
|
||||
| ProviderLatestVersions.ProviderLatestVersions
|
||||
| Path.Path;
|
||||
|
||||
export const HermesDriver: ProviderDriver<HermesSettings, HermesDriverEnv> = {
|
||||
driverKind: DRIVER_KIND,
|
||||
metadata: {
|
||||
displayName: "Hermes",
|
||||
supportsMultipleInstances: true,
|
||||
},
|
||||
configSchema: HermesSettings,
|
||||
defaultConfig: (): HermesSettings => decodeHermesSettings({}),
|
||||
create: ({ instanceId, displayName, accentColor, environment, enabled, config }) =>
|
||||
Effect.gen(function* () {
|
||||
const crypto = yield* Crypto.Crypto;
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const httpClient = yield* HttpClient.HttpClient;
|
||||
const latestVersions = yield* ProviderLatestVersions.ProviderLatestVersions;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const host = yield* ProviderHost.ProviderHost;
|
||||
const { cwd } = host.paths;
|
||||
const processEnv = yield* mergeProviderInstanceEnvironment(environment);
|
||||
const continuationIdentity = defaultProviderContinuationIdentity({
|
||||
driverKind: DRIVER_KIND,
|
||||
instanceId,
|
||||
});
|
||||
const stampIdentity = withInstanceIdentity({
|
||||
instanceId,
|
||||
driverKind: DRIVER_KIND,
|
||||
displayName,
|
||||
accentColor,
|
||||
continuationGroupKey: continuationIdentity.continuationKey,
|
||||
});
|
||||
const effectiveConfig = { ...config, enabled } satisfies HermesSettings;
|
||||
|
||||
// Hermes is a first-party CLI, not an npm package T3 can auto-update, so
|
||||
// maintenance stays manual-only (no "update" button, no version polling).
|
||||
const resolveMaintenance = yield* makeCachedProviderMaintenanceResolution(
|
||||
Effect.succeed(
|
||||
makeManualOnlyProviderMaintenanceCapabilities({
|
||||
provider: DRIVER_KIND,
|
||||
packageName: null,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const orchestrationAdapter = yield* HermesAdapterV2Driver.create({
|
||||
instanceId,
|
||||
displayName,
|
||||
accentColor,
|
||||
environment,
|
||||
enabled,
|
||||
config,
|
||||
}).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new ProviderDriverError({
|
||||
driver: DRIVER_KIND,
|
||||
instanceId,
|
||||
detail: "Failed to build Hermes orchestration adapter.",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const textGeneration = yield* makeHermesTextGeneration(effectiveConfig, processEnv);
|
||||
|
||||
const checkProvider = checkHermesProviderStatus(effectiveConfig, processEnv).pipe(
|
||||
Effect.map(stampIdentity),
|
||||
Effect.provideService(HttpClient.HttpClient, httpClient),
|
||||
Effect.provideService(FileSystem.FileSystem, fileSystem),
|
||||
Effect.provideService(Path.Path, path),
|
||||
Effect.provideService(Crypto.Crypto, crypto),
|
||||
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
|
||||
);
|
||||
|
||||
const snapshotSettings = yield* makeProviderSnapshotSettingsSource(effectiveConfig);
|
||||
const snapshot = yield* makeManagedServerProvider<ProviderSnapshotSettings<HermesSettings>>({
|
||||
resolveMaintenance,
|
||||
getSettings: snapshotSettings.getSettings,
|
||||
streamSettings: snapshotSettings.streamSettings,
|
||||
haveSettingsChanged: haveProviderSnapshotSettingsChanged,
|
||||
initialSnapshot: (settings) =>
|
||||
buildInitialHermesProviderSnapshot(settings.provider).pipe(Effect.map(stampIdentity)),
|
||||
checkProvider,
|
||||
enrichSnapshot: ({ settings, snapshot: currentSnapshot, publishSnapshot }) =>
|
||||
resolveMaintenance().pipe(
|
||||
Effect.flatMap((maintenanceCapabilities) =>
|
||||
enrichHermesSnapshot({
|
||||
snapshot: currentSnapshot,
|
||||
maintenanceCapabilities,
|
||||
enableProviderUpdateChecks: settings.enableProviderUpdateChecks,
|
||||
publishSnapshot,
|
||||
}),
|
||||
),
|
||||
Effect.provideService(HttpClient.HttpClient, httpClient),
|
||||
Effect.provideService(ProviderLatestVersions.ProviderLatestVersions, latestVersions),
|
||||
),
|
||||
}).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new ProviderDriverError({
|
||||
driver: DRIVER_KIND,
|
||||
instanceId,
|
||||
detail: "Failed to build Hermes snapshot.",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
return {
|
||||
instanceId,
|
||||
driverKind: DRIVER_KIND,
|
||||
continuationIdentity,
|
||||
displayName,
|
||||
accentColor,
|
||||
enabled,
|
||||
snapshot,
|
||||
orchestrationAdapter,
|
||||
textGeneration,
|
||||
} satisfies ProviderInstance;
|
||||
}),
|
||||
};
|
||||
@@ -0,0 +1,351 @@
|
||||
import {
|
||||
type CustomModelSetting,
|
||||
type ModelCapabilities,
|
||||
type ServerProvider,
|
||||
type ServerProviderAuth,
|
||||
type ServerProviderModel,
|
||||
} from "@t3tools/contracts";
|
||||
import type { HermesSettings } from "../settings.ts";
|
||||
import type * as EffectAcpSchema from "effect-acp/compat";
|
||||
import { causeErrorTag } from "@t3tools/shared/observability";
|
||||
import * as Crypto from "effect/Crypto";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Result from "effect/Result";
|
||||
import * as HttpClient from "effect/http/HttpClient";
|
||||
import * as ChildProcess from "effect/process/ChildProcess";
|
||||
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
||||
import { createModelCapabilities } from "@t3tools/shared/model";
|
||||
import { resolveSpawnCommand } from "@t3tools/shared/shell";
|
||||
|
||||
import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions";
|
||||
import {
|
||||
buildServerProvider,
|
||||
isCommandMissingCause,
|
||||
parseGenericCliVersion,
|
||||
providerModelsFromSettings,
|
||||
spawnAndCollect,
|
||||
type ServerProviderDraft,
|
||||
} from "@t3tools/provider-core/server/snapshotProbe";
|
||||
import {
|
||||
enrichProviderSnapshotWithVersionAdvisory,
|
||||
type ProviderMaintenanceCapabilities,
|
||||
} from "@t3tools/provider-core/server/maintenanceResolver";
|
||||
import { HERMES_DEFAULT_MODEL_SLUG, makeHermesAcpRuntime } from "./acpSupport.ts";
|
||||
import { sessionModelStateFromInitialize } from "@t3tools/provider-acp/server/runtimeModel";
|
||||
|
||||
const HERMES_PRESENTATION = {
|
||||
displayName: "Hermes",
|
||||
badgeLabel: "Experimental",
|
||||
showInteractionModeToggle: false,
|
||||
} as const;
|
||||
const EMPTY_CAPABILITIES: ModelCapabilities = createModelCapabilities({
|
||||
optionDescriptors: [],
|
||||
});
|
||||
|
||||
const VERSION_PROBE_TIMEOUT_MS = 4_000;
|
||||
// `initialize` is a single local round trip, so this is generous even on slow machines.
|
||||
const HERMES_ACP_INITIALIZE_TIMEOUT_MS = 8_000;
|
||||
|
||||
const HERMES_BUILT_IN_MODELS: ReadonlyArray<ServerProviderModel> = [
|
||||
{
|
||||
slug: HERMES_DEFAULT_MODEL_SLUG,
|
||||
name: "Hermes (configured default)",
|
||||
isCustom: false,
|
||||
isDefault: true,
|
||||
capabilities: EMPTY_CAPABILITIES,
|
||||
},
|
||||
];
|
||||
|
||||
function hermesModelsFromSettings(
|
||||
customModels: ReadonlyArray<CustomModelSetting> | undefined,
|
||||
builtInModels: ReadonlyArray<ServerProviderModel> = HERMES_BUILT_IN_MODELS,
|
||||
): ReadonlyArray<ServerProviderModel> {
|
||||
return providerModelsFromSettings(builtInModels, customModels ?? [], EMPTY_CAPABILITIES);
|
||||
}
|
||||
|
||||
export function buildInitialHermesProviderSnapshot(
|
||||
hermesSettings: HermesSettings,
|
||||
): Effect.Effect<ServerProviderDraft> {
|
||||
return Effect.gen(function* () {
|
||||
const checkedAt = yield* Effect.map(DateTime.now, DateTime.formatIso);
|
||||
const models = hermesModelsFromSettings(hermesSettings.customModels);
|
||||
|
||||
if (!hermesSettings.enabled) {
|
||||
return buildServerProvider({
|
||||
presentation: HERMES_PRESENTATION,
|
||||
enabled: false,
|
||||
checkedAt,
|
||||
models,
|
||||
probe: {
|
||||
installed: false,
|
||||
version: null,
|
||||
status: "warning",
|
||||
auth: { status: "unknown" },
|
||||
message: "Hermes is disabled in T3 Code settings.",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return buildServerProvider({
|
||||
presentation: HERMES_PRESENTATION,
|
||||
enabled: true,
|
||||
checkedAt,
|
||||
models,
|
||||
probe: {
|
||||
installed: true,
|
||||
version: null,
|
||||
status: "warning",
|
||||
auth: { status: "unknown" },
|
||||
message: "Checking Hermes Agent availability...",
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** Models advertised by the ACP agent, with the session's current model marked as default. */
|
||||
function buildHermesModelsFromSessionModelState(
|
||||
modelState: EffectAcpSchema.SessionModelState | null | undefined,
|
||||
): ReadonlyArray<ServerProviderModel> {
|
||||
if (!modelState || modelState.availableModels.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const currentModelId = modelState.currentModelId?.trim();
|
||||
const seen = new Set<string>();
|
||||
return modelState.availableModels.flatMap((model): ServerProviderModel[] => {
|
||||
const slug = model.modelId.trim();
|
||||
if (!slug || seen.has(slug)) {
|
||||
return [];
|
||||
}
|
||||
seen.add(slug);
|
||||
return [
|
||||
{
|
||||
slug,
|
||||
name: model.name.trim() || slug,
|
||||
isCustom: false,
|
||||
...(slug === currentModelId ? { isDefault: true } : {}),
|
||||
capabilities: EMPTY_CAPABILITIES,
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads model metadata from `initialize._meta` / session setup. This never
|
||||
* calls `authenticate` or opens a browser login; a successful ACP initialize
|
||||
* (`hermes acp` authenticates via the `custom` method against the host's own
|
||||
* Hermes config) doubles as proof the CLI is usable.
|
||||
*/
|
||||
const discoverHermesMetadataViaAcpInitialize = (
|
||||
hermesSettings: HermesSettings,
|
||||
environment: NodeJS.ProcessEnv,
|
||||
) =>
|
||||
Effect.gen(function* () {
|
||||
const acp = yield* makeHermesAcpRuntime({
|
||||
hermesSettings,
|
||||
environment,
|
||||
cwd: process.cwd(),
|
||||
clientInfo: { name: "t3-code-provider-probe", version: "0.0.0" },
|
||||
});
|
||||
const initialized = yield* acp.initialize();
|
||||
return {
|
||||
models: buildHermesModelsFromSessionModelState(sessionModelStateFromInitialize(initialized)),
|
||||
};
|
||||
}).pipe(Effect.scoped);
|
||||
|
||||
/**
|
||||
* Extract the Hermes Agent version from `hermes --version` output.
|
||||
*
|
||||
* The first line looks like:
|
||||
* `Hermes Agent v0.21.0 (2026.8.31) · upstream f98f5e74`
|
||||
*
|
||||
* The generic parser would grab the parenthesised build date first, so we
|
||||
* prefer the `v`-prefixed semver token and fall back to the generic parser.
|
||||
*/
|
||||
export function parseHermesCliVersion(output: string): string | null {
|
||||
const match = output.match(/\bv(\d+\.\d+\.\d+)\b/);
|
||||
return match?.[1] ?? parseGenericCliVersion(output);
|
||||
}
|
||||
|
||||
const runHermesVersionCommand = (hermesSettings: HermesSettings, environment: NodeJS.ProcessEnv) =>
|
||||
Effect.gen(function* () {
|
||||
const command = hermesSettings.binaryPath || "hermes";
|
||||
const spawnCommand = yield* resolveSpawnCommand(command, ["--version"], { env: environment });
|
||||
return yield* spawnAndCollect(
|
||||
command,
|
||||
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
|
||||
env: environment,
|
||||
shell: spawnCommand.shell,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
function buildHermesCliCommandMissingMessage(binaryPath: string): string {
|
||||
return [
|
||||
`Hermes Agent command \`${binaryPath}\` was not found.`,
|
||||
`Install the Hermes Agent CLI, make sure \`${binaryPath}\` is on PATH, then restart T3 Code.`,
|
||||
].join(" ");
|
||||
}
|
||||
|
||||
export const checkHermesProviderStatus = Effect.fn("checkHermesProviderStatus")(function* (
|
||||
hermesSettings: HermesSettings,
|
||||
environment: NodeJS.ProcessEnv = process.env,
|
||||
): Effect.fn.Return<
|
||||
ServerProviderDraft,
|
||||
never,
|
||||
ChildProcessSpawner.ChildProcessSpawner | Crypto.Crypto
|
||||
> {
|
||||
const checkedAt = DateTime.formatIso(yield* DateTime.now);
|
||||
const fallbackModels = hermesModelsFromSettings(hermesSettings.customModels);
|
||||
|
||||
if (!hermesSettings.enabled) {
|
||||
return buildServerProvider({
|
||||
presentation: HERMES_PRESENTATION,
|
||||
enabled: false,
|
||||
checkedAt,
|
||||
models: fallbackModels,
|
||||
probe: {
|
||||
installed: false,
|
||||
version: null,
|
||||
status: "warning",
|
||||
auth: { status: "unknown" },
|
||||
message: "Hermes is disabled in T3 Code settings.",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const versionResult = yield* runHermesVersionCommand(hermesSettings, environment).pipe(
|
||||
Effect.timeoutOption(VERSION_PROBE_TIMEOUT_MS),
|
||||
Effect.result,
|
||||
);
|
||||
|
||||
if (Result.isFailure(versionResult)) {
|
||||
const error = versionResult.failure;
|
||||
yield* Effect.logWarning("Hermes Agent CLI health check failed.", { errorTag: error._tag });
|
||||
return buildServerProvider({
|
||||
presentation: HERMES_PRESENTATION,
|
||||
enabled: hermesSettings.enabled,
|
||||
checkedAt,
|
||||
models: fallbackModels,
|
||||
probe: {
|
||||
installed: !isCommandMissingCause(error),
|
||||
version: null,
|
||||
status: "error",
|
||||
auth: { status: "unknown" },
|
||||
message: isCommandMissingCause(error)
|
||||
? buildHermesCliCommandMissingMessage(hermesSettings.binaryPath || "hermes")
|
||||
: "Failed to execute Hermes Agent CLI health check.",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (Option.isNone(versionResult.success)) {
|
||||
return buildServerProvider({
|
||||
presentation: HERMES_PRESENTATION,
|
||||
enabled: hermesSettings.enabled,
|
||||
checkedAt,
|
||||
models: fallbackModels,
|
||||
probe: {
|
||||
installed: true,
|
||||
version: null,
|
||||
status: "error",
|
||||
auth: { status: "unknown" },
|
||||
message: "Hermes Agent CLI is installed but timed out while running `hermes --version`.",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const versionOutput = versionResult.success.value;
|
||||
const version = parseHermesCliVersion(`${versionOutput.stdout}\n${versionOutput.stderr}`);
|
||||
if (versionOutput.code !== 0) {
|
||||
return buildServerProvider({
|
||||
presentation: HERMES_PRESENTATION,
|
||||
enabled: hermesSettings.enabled,
|
||||
checkedAt,
|
||||
models: fallbackModels,
|
||||
probe: {
|
||||
installed: true,
|
||||
version,
|
||||
status: "error",
|
||||
auth: { status: "unknown" },
|
||||
message: "Hermes Agent CLI is installed but failed to run.",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Hermes has no standalone auth probe: `hermes acp` authenticates through
|
||||
// the "custom" method during startup, so a successful ACP discovery
|
||||
// doubles as proof of authentication.
|
||||
const acpExit = yield* discoverHermesMetadataViaAcpInitialize(hermesSettings, environment).pipe(
|
||||
Effect.timeoutOption(HERMES_ACP_INITIALIZE_TIMEOUT_MS),
|
||||
Effect.exit,
|
||||
);
|
||||
const acpMetadata = Exit.isSuccess(acpExit) ? Option.getOrUndefined(acpExit.value) : undefined;
|
||||
const acpFailed = Exit.isFailure(acpExit) || Option.isNone(acpExit.value);
|
||||
if (acpFailed) {
|
||||
yield* Effect.logWarning("Hermes ACP initialize probe failed or timed out.", {
|
||||
errorTag: Exit.isFailure(acpExit) ? causeErrorTag(acpExit.cause) : "Timeout",
|
||||
});
|
||||
}
|
||||
|
||||
const discoveredModels = acpMetadata?.models ?? [];
|
||||
const models =
|
||||
discoveredModels.length > 0
|
||||
? hermesModelsFromSettings(hermesSettings.customModels, discoveredModels)
|
||||
: fallbackModels;
|
||||
|
||||
const auth: ServerProviderAuth = acpFailed ? { status: "unknown" } : { status: "authenticated" };
|
||||
|
||||
return buildServerProvider({
|
||||
presentation: HERMES_PRESENTATION,
|
||||
enabled: hermesSettings.enabled,
|
||||
checkedAt,
|
||||
models,
|
||||
probe: {
|
||||
installed: true,
|
||||
version,
|
||||
// A failed metadata probe degrades the model picker, it does not make chats fail.
|
||||
status: acpFailed ? "warning" : "ready",
|
||||
auth,
|
||||
...(acpFailed
|
||||
? {
|
||||
message:
|
||||
"Hermes Agent CLI is installed but ACP initialize failed. Run `hermes setup` (or `hermes acp --setup`), then retry. Model options may be incomplete.",
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Background maintenance enrichment for a Hermes snapshot. Hermes has no
|
||||
* package-manager update channel (it is a first-party CLI, not an npm
|
||||
* package T3 can auto-update), so this only republishes version advisory
|
||||
* metadata — there is nothing else to discover periodically.
|
||||
*/
|
||||
export const enrichHermesSnapshot = (input: {
|
||||
readonly snapshot: ServerProvider;
|
||||
readonly maintenanceCapabilities: ProviderMaintenanceCapabilities;
|
||||
readonly enableProviderUpdateChecks?: boolean;
|
||||
readonly publishSnapshot: (snapshot: ServerProvider) => Effect.Effect<void>;
|
||||
}): Effect.Effect<
|
||||
void,
|
||||
never,
|
||||
HttpClient.HttpClient | ProviderLatestVersions.ProviderLatestVersions
|
||||
> => {
|
||||
const { snapshot, publishSnapshot } = input;
|
||||
|
||||
return enrichProviderSnapshotWithVersionAdvisory(snapshot, input.maintenanceCapabilities, {
|
||||
enableProviderUpdateChecks: input.enableProviderUpdateChecks,
|
||||
}).pipe(
|
||||
Effect.flatMap((enrichedSnapshot) => publishSnapshot(enrichedSnapshot)),
|
||||
Effect.catchCause((cause) =>
|
||||
Effect.logWarning("Hermes version advisory enrichment failed", {
|
||||
errorTag: causeErrorTag(cause),
|
||||
}),
|
||||
),
|
||||
Effect.asVoid,
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,128 @@
|
||||
import * as Crypto from "effect/Crypto";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
||||
import type * as EffectAcpErrors from "effect-acp/errors";
|
||||
|
||||
import { TextGenerationError } from "@t3tools/contracts";
|
||||
import type { HermesSettings } from "../settings.ts";
|
||||
|
||||
import * as TextGenerationOperations from "@t3tools/provider-core/server/textGenerationOperations";
|
||||
import {
|
||||
applyHermesAcpModelSelection,
|
||||
currentHermesModelIdFromSessionSetup,
|
||||
makeHermesAcpRuntime,
|
||||
resolveHermesAcpBaseModelId,
|
||||
} from "./acpSupport.ts";
|
||||
|
||||
const HERMES_TIMEOUT_MS = 180_000;
|
||||
|
||||
const isTextGenerationError = Schema.is(TextGenerationError);
|
||||
|
||||
/**
|
||||
* Build a Hermes text-generation closure bound to a specific
|
||||
* `HermesSettings` payload. This drives commit messages / branch names /
|
||||
* thread titles etc. — not the main chat path, which goes through
|
||||
* `orchestrationAdapter` instead.
|
||||
*/
|
||||
export const makeHermesTextGeneration = Effect.fn("makeHermesTextGeneration")(function* (
|
||||
hermesSettings: HermesSettings,
|
||||
environment: NodeJS.ProcessEnv = process.env,
|
||||
) {
|
||||
const crypto = yield* Crypto.Crypto;
|
||||
const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
|
||||
const runHermesJson: TextGenerationOperations.Runner = (request) => {
|
||||
const { operation, cwd, prompt, modelSelection } = request;
|
||||
return Effect.gen(function* () {
|
||||
const outputRef = yield* Ref.make("");
|
||||
const runtime = yield* makeHermesAcpRuntime({
|
||||
hermesSettings,
|
||||
environment,
|
||||
cwd,
|
||||
clientInfo: { name: "t3-code-git-text", version: "0.0.0" },
|
||||
}).pipe(
|
||||
Effect.provideService(Crypto.Crypto, crypto),
|
||||
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, commandSpawner),
|
||||
);
|
||||
|
||||
yield* runtime.handleSessionUpdate((notification) => {
|
||||
const update = notification.update;
|
||||
if (update.sessionUpdate !== "agent_message_chunk") {
|
||||
return Effect.void;
|
||||
}
|
||||
const content = update.content;
|
||||
if (content.type !== "text") {
|
||||
return Effect.void;
|
||||
}
|
||||
return Ref.update(outputRef, (current) => current + content.text);
|
||||
});
|
||||
|
||||
const promptResult = yield* Effect.gen(function* () {
|
||||
const resolvedModel = resolveHermesAcpBaseModelId(modelSelection.model);
|
||||
const started = yield* runtime.start();
|
||||
yield* applyHermesAcpModelSelection({
|
||||
runtime,
|
||||
currentModelId: currentHermesModelIdFromSessionSetup(started.sessionSetupResult),
|
||||
model: resolvedModel,
|
||||
mapError: (cause) =>
|
||||
new TextGenerationError({
|
||||
operation,
|
||||
detail: "Failed to set Hermes ACP model for text generation.",
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
return yield* runtime.prompt({
|
||||
prompt: [{ type: "text", text: prompt }],
|
||||
});
|
||||
}).pipe(
|
||||
Effect.timeoutOption(HERMES_TIMEOUT_MS),
|
||||
Effect.flatMap(
|
||||
Option.match({
|
||||
onNone: () =>
|
||||
Effect.fail(
|
||||
new TextGenerationError({ operation, detail: "Hermes ACP request timed out." }),
|
||||
),
|
||||
onSome: (value) => Effect.succeed(value),
|
||||
}),
|
||||
),
|
||||
Effect.mapError((cause: EffectAcpErrors.AcpError | TextGenerationError) =>
|
||||
isTextGenerationError(cause)
|
||||
? cause
|
||||
: new TextGenerationError({ operation, detail: "Hermes ACP request failed.", cause }),
|
||||
),
|
||||
);
|
||||
|
||||
const trimmed = (yield* Ref.get(outputRef)).trim();
|
||||
if (!trimmed) {
|
||||
return yield* new TextGenerationError({
|
||||
operation,
|
||||
detail:
|
||||
promptResult.stopReason === "cancelled"
|
||||
? "Hermes ACP request was cancelled."
|
||||
: "Hermes Agent returned empty output.",
|
||||
});
|
||||
}
|
||||
|
||||
return yield* TextGenerationOperations.decodeJsonReply(request, "Hermes Agent", trimmed);
|
||||
}).pipe(
|
||||
Effect.mapError((cause) =>
|
||||
isTextGenerationError(cause)
|
||||
? cause
|
||||
: new TextGenerationError({
|
||||
operation,
|
||||
detail: "Hermes ACP text generation failed.",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
Effect.scoped,
|
||||
);
|
||||
};
|
||||
|
||||
return TextGenerationOperations.fromRunner(
|
||||
"HermesTextGeneration",
|
||||
TextGenerationOperations.withoutInvestigation("Hermes", runHermesJson),
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Hermes Agent instance settings. Shared by the server driver and the
|
||||
* client settings form, so it holds only browser-safe schema code.
|
||||
*
|
||||
* @module provider-hermes/settings
|
||||
*/
|
||||
import {
|
||||
CustomModelSetting,
|
||||
makeBinaryPathSetting,
|
||||
makeProviderSettingsSchema,
|
||||
} from "@t3tools/contracts";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
export const HermesSettings = makeProviderSettingsSchema(
|
||||
{
|
||||
// Off by default (like Cursor, Grok, and OpenCode): the binding is not
|
||||
// yet stable enough to probe on every install. Users opt in from Settings.
|
||||
enabled: Schema.Boolean.pipe(
|
||||
Schema.withDecodingDefault(Effect.succeed(false)),
|
||||
Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
|
||||
),
|
||||
binaryPath: makeBinaryPathSetting("hermes").pipe(
|
||||
Schema.annotateKey({
|
||||
title: "Binary path",
|
||||
description: "Path to the Hermes Agent binary.",
|
||||
providerSettingsForm: { placeholder: "hermes", clearWhenEmpty: "omit" },
|
||||
}),
|
||||
),
|
||||
customModels: Schema.Array(CustomModelSetting).pipe(
|
||||
Schema.withDecodingDefault(Effect.succeed([])),
|
||||
Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
|
||||
),
|
||||
},
|
||||
{
|
||||
order: ["binaryPath"],
|
||||
},
|
||||
);
|
||||
export type HermesSettings = typeof HermesSettings.Type;
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Shared test fixtures for Hermes Agent provider tests.
|
||||
*
|
||||
* @module provider-hermes/testing
|
||||
*/
|
||||
export { HERMES_PROVIDER, HERMES_DEFAULT_INSTANCE_ID } from "./server/adapter.ts";
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Generated
+50
-8
@@ -386,6 +386,9 @@ importers:
|
||||
'@t3tools/provider-grok':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/provider-grok
|
||||
'@t3tools/provider-hermes':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/provider-hermes
|
||||
'@t3tools/provider-muse':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/provider-muse
|
||||
@@ -648,6 +651,9 @@ importers:
|
||||
'@t3tools/provider-grok':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/provider-grok
|
||||
'@t3tools/provider-hermes':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/provider-hermes
|
||||
'@t3tools/provider-muse':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/provider-muse
|
||||
@@ -817,6 +823,9 @@ importers:
|
||||
'@t3tools/provider-grok':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/provider-grok
|
||||
'@t3tools/provider-hermes':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/provider-hermes
|
||||
'@t3tools/provider-muse':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/provider-muse
|
||||
@@ -1364,6 +1373,43 @@ importers:
|
||||
specifier: 1.0.0
|
||||
version: 1.0.0(@types/[email protected])(@vitest/[email protected]([email protected]))([email protected])([email protected])([email protected])([email protected](@noble/[email protected]))([email protected](@types/[email protected])([email protected]))([email protected])([email protected])([email protected])([email protected])([email protected])
|
||||
|
||||
packages/provider-hermes:
|
||||
dependencies:
|
||||
'@t3tools/contracts':
|
||||
specifier: workspace:*
|
||||
version: link:../contracts
|
||||
'@t3tools/provider-acp':
|
||||
specifier: workspace:*
|
||||
version: link:../provider-acp
|
||||
'@t3tools/provider-core':
|
||||
specifier: workspace:*
|
||||
version: link:../provider-core
|
||||
'@t3tools/shared':
|
||||
specifier: workspace:*
|
||||
version: link:../shared
|
||||
effect:
|
||||
specifier: 4.0.4
|
||||
version: 4.0.4
|
||||
devDependencies:
|
||||
'@effect/platform-node':
|
||||
specifier: 4.0.4
|
||||
version: 4.0.4([email protected])([email protected])([email protected])([email protected])
|
||||
'@effect/vitest':
|
||||
specifier: 4.0.4
|
||||
version: 4.0.4(patch_hash=ebaec66c6bdd25e1b8d5bfd4a14f25ab959bdcca6e22ed8871d061e50e2db0ad)(@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected](@noble/[email protected]))([email protected](@types/[email protected])([email protected]))([email protected])([email protected])([email protected])([email protected])([email protected])
|
||||
'@t3tools/provider-testing':
|
||||
specifier: workspace:*
|
||||
version: link:../provider-testing
|
||||
'@types/node':
|
||||
specifier: 24.12.4
|
||||
version: 24.12.4
|
||||
effect-acp:
|
||||
specifier: workspace:*
|
||||
version: link:../effect-acp
|
||||
vite-plus:
|
||||
specifier: 1.0.0
|
||||
version: 1.0.0(@types/[email protected])(@vitest/[email protected]([email protected]))([email protected])([email protected])([email protected])([email protected](@noble/[email protected]))([email protected](@types/[email protected])([email protected]))([email protected])([email protected])([email protected])([email protected])([email protected])
|
||||
|
||||
packages/provider-muse:
|
||||
dependencies:
|
||||
'@muse-code/sdk':
|
||||
@@ -16308,7 +16354,7 @@ snapshots:
|
||||
'@shikijs/[email protected]':
|
||||
dependencies:
|
||||
'@shikijs/vscode-textmate': 10.0.2
|
||||
'@types/hast': 3.0.4
|
||||
'@types/hast': 3.0.5
|
||||
|
||||
'@shikijs/[email protected]':
|
||||
dependencies:
|
||||
@@ -19590,10 +19636,6 @@ snapshots:
|
||||
dependencies:
|
||||
walk-up-path: 4.0.0
|
||||
|
||||
[email protected]([email protected]):
|
||||
optionalDependencies:
|
||||
picomatch: 4.0.4
|
||||
|
||||
[email protected]([email protected]):
|
||||
optionalDependencies:
|
||||
picomatch: 4.0.7
|
||||
@@ -22697,7 +22739,7 @@ snapshots:
|
||||
'@shikijs/themes': 4.2.0
|
||||
'@shikijs/types': 4.2.0
|
||||
'@shikijs/vscode-textmate': 10.0.2
|
||||
'@types/hast': 3.0.4
|
||||
'@types/hast': 3.0.5
|
||||
|
||||
[email protected]:
|
||||
dependencies:
|
||||
@@ -23045,8 +23087,8 @@ snapshots:
|
||||
|
||||
[email protected]:
|
||||
dependencies:
|
||||
fdir: 6.5.0([email protected].4)
|
||||
picomatch: 4.0.4
|
||||
fdir: 6.5.0([email protected].7)
|
||||
picomatch: 4.0.7
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
|
||||
Reference in new issue
Block a user