Skip to content

@codesoul-co/hypha-inference / drivers

模块用法

用于使用该功能边界的公共契约与操作。Drivers 模块公开 3 类、7 接口、4 类型。

从包入口导入

ts
import {
  HttpLocalInferenceDriver,
  LocalInferenceDriverRegistry,
  NodeLocalInferenceProcessSupervisor,
} from '@codesoul-co/hypha-inference';

import type {
  LocalInferenceDriver,
  LocalInferenceDriverConfig,
  LocalInferenceDriverStatus,
  LocalInferenceHealthProbeRequest,
  LocalInferenceProcessHandle,
  LocalInferenceProcessSpec,
  LocalInferenceProcessSupervisor,
  LocalInferenceDriverMode,
} from '@codesoul-co/hypha-inference';

// 完整导出列表见下方。

使用要点

  • 11 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 3 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。

公共导出

Symbol种类签名说明
HttpLocalInferenceDrivernew HttpLocalInferenceDriver(config: LocalInferenceDriverConfig, supervisor?: LocalInferenceProcessSupervisor, healthProbe?: LocalInferenceHealthProbe): HttpLocalInferenceDriverHttp Local Inference Driver 类,共公开 10 个构造函数或成员;精确签名见本条目的声明与成员表。
LocalInferenceDriverRegistrynew LocalInferenceDriverRegistry(): LocalInferenceDriverRegistryLocal Inference Driver Registry 类,共公开 6 个构造函数或成员;精确签名见本条目的声明与成员表。
NodeLocalInferenceProcessSupervisornew NodeLocalInferenceProcessSupervisor(): NodeLocalInferenceProcessSupervisorNode Local Inference Process Supervisor 类,共公开 2 个构造函数或成员;精确签名见本条目的声明与成员表。
LocalInferenceDriver接口interface LocalInferenceDriverLocal Inference Driver 接口,共包含 9 个公开字段或方法。
LocalInferenceDriverConfig接口interface LocalInferenceDriverConfigLocal Inference Driver Config 接口,共包含 17 个公开字段或方法。
LocalInferenceDriverStatus接口interface LocalInferenceDriverStatusLocal Inference Driver Status 接口,共包含 9 个公开字段或方法。
LocalInferenceHealthProbeRequest接口interface LocalInferenceHealthProbeRequestLocal Inference Health Probe Request 接口,共包含 3 个公开字段或方法。
LocalInferenceProcessHandle接口interface LocalInferenceProcessHandleLocal Inference Process Handle 接口,共包含 3 个公开字段或方法。
LocalInferenceProcessSpec接口interface LocalInferenceProcessSpecLocal Inference Process Spec 接口,共包含 4 个公开字段或方法。
LocalInferenceProcessSupervisor接口interface LocalInferenceProcessSupervisorLocal Inference Process Supervisor 接口,共包含 1 个公开字段或方法。
LocalInferenceDriverMode类型type LocalInferenceDriverMode = 'connect' | 'managed'Local Inference Driver Mode 公共类型别名;完整类型表达式见声明。
LocalInferenceDriverState类型type LocalInferenceDriverState = 'idle' | 'starting' | 'ready' | 'stopping' | 'stopped' | 'failed'Local Inference Driver State 公共类型别名;完整类型表达式见声明。
LocalInferenceEngineKind类型type LocalInferenceEngineKind = 'ollama' | 'sglang' | 'vllm'Local Inference Engine Kind 公共类型别名;完整类型表达式见声明。
LocalInferenceHealthProbe类型type LocalInferenceHealthProbe = (request: LocalInferenceHealthProbeRequest) => Promise<boolean>Local Inference Health Probe 公共类型别名;完整类型表达式见声明。

HttpLocalInferenceDriver

Http Local Inference Driver 类,共公开 10 个构造函数或成员;精确签名见本条目的声明与成员表。

  • 种类: 类
  • 导入: import { HttpLocalInferenceDriver } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export declare class HttpLocalInferenceDriver implements LocalInferenceDriver {
    readonly id: string;
    readonly kind: LocalInferenceEngineKind;
    constructor(config: LocalInferenceDriverConfig, supervisor?: LocalInferenceProcessSupervisor, healthProbe?: LocalInferenceHealthProbe);
    start(model?: string | undefined): Promise<LocalInferenceDriverStatus>;
    load(model: string): Promise<LocalInferenceDriverStatus>;
    unload(model?: string | undefined): Promise<LocalInferenceDriverStatus>;
    stop(): Promise<LocalInferenceDriverStatus>;
    health(): Promise<boolean>;
    status(): LocalInferenceDriverStatus;
    backend(): InferenceBackend;
}

公开成员

成员种类签名说明
backend方法backend(): InferenceBackend公开方法;参数与返回类型以签名列为准。
constructor构造函数(config: LocalInferenceDriverConfig, supervisor?: LocalInferenceProcessSupervisor, healthProbe?: LocalInferenceHealthProbe): HttpLocalInferenceDriver创建该类的实例。
health方法health(): Promise<boolean>公开方法;参数与返回类型以签名列为准。
id属性readonly id: string公开属性;类型、只读和可选状态以签名列为准。
kind属性readonly kind: LocalInferenceEngineKind公开属性;类型、只读和可选状态以签名列为准。
load方法load(model: string): Promise<LocalInferenceDriverStatus>公开方法;参数与返回类型以签名列为准。
start方法start(model?: string | undefined): Promise<LocalInferenceDriverStatus>公开方法;参数与返回类型以签名列为准。
status方法status(): LocalInferenceDriverStatus公开方法;参数与返回类型以签名列为准。
stop方法stop(): Promise<LocalInferenceDriverStatus>公开方法;参数与返回类型以签名列为准。
unload方法unload(model?: string | undefined): Promise<LocalInferenceDriverStatus>公开方法;参数与返回类型以签名列为准。

LocalInferenceDriverRegistry

Local Inference Driver Registry 类,共公开 6 个构造函数或成员;精确签名见本条目的声明与成员表。

  • 种类: 类
  • 导入: import { LocalInferenceDriverRegistry } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export declare class LocalInferenceDriverRegistry {
    register(driver: LocalInferenceDriver): void;
    get(id: string): LocalInferenceDriver | null;
    require(id: string): LocalInferenceDriver;
    list(): LocalInferenceDriver[];
    stopAll(): Promise<void>;
}

公开成员

成员种类签名说明
constructor构造函数(): LocalInferenceDriverRegistry创建该类的实例。
get方法get(id: string): LocalInferenceDriver | null公开方法;参数与返回类型以签名列为准。
list方法list(): LocalInferenceDriver[]公开方法;参数与返回类型以签名列为准。
register方法register(driver: LocalInferenceDriver): void公开方法;参数与返回类型以签名列为准。
require方法require(id: string): LocalInferenceDriver公开方法;参数与返回类型以签名列为准。
stopAll方法stopAll(): Promise<void>公开方法;参数与返回类型以签名列为准。

NodeLocalInferenceProcessSupervisor

Node Local Inference Process Supervisor 类,共公开 2 个构造函数或成员;精确签名见本条目的声明与成员表。

  • 种类: 类
  • 导入: import { NodeLocalInferenceProcessSupervisor } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export declare class NodeLocalInferenceProcessSupervisor implements LocalInferenceProcessSupervisor {
    start(spec: LocalInferenceProcessSpec): Promise<LocalInferenceProcessHandle>;
}

公开成员

成员种类签名说明
constructor构造函数(): NodeLocalInferenceProcessSupervisor创建该类的实例。
start方法start(spec: LocalInferenceProcessSpec): Promise<LocalInferenceProcessHandle>公开方法;参数与返回类型以签名列为准。

LocalInferenceDriver

Local Inference Driver 接口,共包含 9 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { LocalInferenceDriver } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export interface LocalInferenceDriver {
    readonly id: string;
    readonly kind: LocalInferenceEngineKind;
    start(model?: string): Promise<LocalInferenceDriverStatus>;
    load(model: string): Promise<LocalInferenceDriverStatus>;
    unload(model?: string): Promise<LocalInferenceDriverStatus>;
    stop(): Promise<LocalInferenceDriverStatus>;
    health(): Promise<boolean>;
    status(): LocalInferenceDriverStatus;
    backend(): InferenceBackend;
}

契约成员

成员种类签名说明
backend方法backend(): InferenceBackend公开方法;参数与返回类型以签名列为准。
health方法health(): Promise<boolean>公开方法;参数与返回类型以签名列为准。
id属性readonly id: string公开属性;类型、只读和可选状态以签名列为准。
kind属性readonly kind: LocalInferenceEngineKind公开属性;类型、只读和可选状态以签名列为准。
load方法load(model: string): Promise<LocalInferenceDriverStatus>公开方法;参数与返回类型以签名列为准。
start方法start(model?: string): Promise<LocalInferenceDriverStatus>公开方法;参数与返回类型以签名列为准。
status方法status(): LocalInferenceDriverStatus公开方法;参数与返回类型以签名列为准。
stop方法stop(): Promise<LocalInferenceDriverStatus>公开方法;参数与返回类型以签名列为准。
unload方法unload(model?: string): Promise<LocalInferenceDriverStatus>公开方法;参数与返回类型以签名列为准。

LocalInferenceDriverConfig

Local Inference Driver Config 接口,共包含 17 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { LocalInferenceDriverConfig } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export interface LocalInferenceDriverConfig {
    id?: string;
    kind: LocalInferenceEngineKind;
    mode?: LocalInferenceDriverMode;
    baseUrl?: string;
    endpoint?: string;
    model?: string;
    host?: string;
    port?: number;
    command?: string;
    args?: string[];
    cwd?: string;
    env?: Record<string, string>;
    startupTimeoutMs?: number;
    healthPollMs?: number;
    requestTimeoutMs?: number;
    apiKey?: string;
    apiKeyEnv?: string;
}

契约成员

成员种类签名说明
apiKey属性apiKey?: string公开属性;类型、只读和可选状态以签名列为准。
apiKeyEnv属性apiKeyEnv?: string公开属性;类型、只读和可选状态以签名列为准。
args属性args?: string[]公开属性;类型、只读和可选状态以签名列为准。
baseUrl属性baseUrl?: string公开属性;类型、只读和可选状态以签名列为准。
command属性command?: string公开属性;类型、只读和可选状态以签名列为准。
cwd属性cwd?: string公开属性;类型、只读和可选状态以签名列为准。
endpoint属性endpoint?: string公开属性;类型、只读和可选状态以签名列为准。
env属性env?: Record<string, string>公开属性;类型、只读和可选状态以签名列为准。
healthPollMs属性healthPollMs?: number公开属性;类型、只读和可选状态以签名列为准。
host属性host?: string公开属性;类型、只读和可选状态以签名列为准。
id属性id?: string公开属性;类型、只读和可选状态以签名列为准。
kind属性kind: LocalInferenceEngineKind公开属性;类型、只读和可选状态以签名列为准。
mode属性mode?: LocalInferenceDriverMode公开属性;类型、只读和可选状态以签名列为准。
model属性model?: string公开属性;类型、只读和可选状态以签名列为准。
port属性port?: number公开属性;类型、只读和可选状态以签名列为准。
requestTimeoutMs属性requestTimeoutMs?: number公开属性;类型、只读和可选状态以签名列为准。
startupTimeoutMs属性startupTimeoutMs?: number公开属性;类型、只读和可选状态以签名列为准。

LocalInferenceDriverStatus

Local Inference Driver Status 接口,共包含 9 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { LocalInferenceDriverStatus } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export interface LocalInferenceDriverStatus {
    id: string;
    kind: LocalInferenceEngineKind;
    mode: LocalInferenceDriverMode;
    state: LocalInferenceDriverState;
    baseUrl: string;
    model?: string;
    pid?: number;
    healthy: boolean;
    error?: string;
}

契约成员

成员种类签名说明
baseUrl属性baseUrl: string公开属性;类型、只读和可选状态以签名列为准。
error属性error?: string公开属性;类型、只读和可选状态以签名列为准。
healthy属性healthy: boolean公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
kind属性kind: LocalInferenceEngineKind公开属性;类型、只读和可选状态以签名列为准。
mode属性mode: LocalInferenceDriverMode公开属性;类型、只读和可选状态以签名列为准。
model属性model?: string公开属性;类型、只读和可选状态以签名列为准。
pid属性pid?: number公开属性;类型、只读和可选状态以签名列为准。
state属性state: LocalInferenceDriverState公开属性;类型、只读和可选状态以签名列为准。

LocalInferenceHealthProbeRequest

Local Inference Health Probe Request 接口,共包含 3 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { LocalInferenceHealthProbeRequest } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export interface LocalInferenceHealthProbeRequest {
    url: string;
    headers: Record<string, string>;
    timeoutMs: number;
}

契约成员

成员种类签名说明
headers属性headers: Record<string, string>公开属性;类型、只读和可选状态以签名列为准。
timeoutMs属性timeoutMs: number公开属性;类型、只读和可选状态以签名列为准。
url属性url: string公开属性;类型、只读和可选状态以签名列为准。

LocalInferenceProcessHandle

Local Inference Process Handle 接口,共包含 3 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { LocalInferenceProcessHandle } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export interface LocalInferenceProcessHandle {
    readonly pid?: number;
    readonly exited: Promise<{
        code: number | null;
        signal: NodeJS.Signals | null;
    }>;
    stop(graceMs?: number): Promise<void>;
}

契约成员

成员种类签名说明
exited属性readonly exited: Promise<{ code: number | null; signal: NodeJS.Signals | null; }>公开属性;类型、只读和可选状态以签名列为准。
pid属性readonly pid?: number公开属性;类型、只读和可选状态以签名列为准。
stop方法stop(graceMs?: number): Promise<void>公开方法;参数与返回类型以签名列为准。

LocalInferenceProcessSpec

Local Inference Process Spec 接口,共包含 4 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { LocalInferenceProcessSpec } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export interface LocalInferenceProcessSpec {
    command: string;
    args: string[];
    cwd?: string;
    env?: Record<string, string>;
}

契约成员

成员种类签名说明
args属性args: string[]公开属性;类型、只读和可选状态以签名列为准。
command属性command: string公开属性;类型、只读和可选状态以签名列为准。
cwd属性cwd?: string公开属性;类型、只读和可选状态以签名列为准。
env属性env?: Record<string, string>公开属性;类型、只读和可选状态以签名列为准。

LocalInferenceProcessSupervisor

Local Inference Process Supervisor 接口,共包含 1 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { LocalInferenceProcessSupervisor } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export interface LocalInferenceProcessSupervisor {
    start(spec: LocalInferenceProcessSpec): Promise<LocalInferenceProcessHandle>;
}

契约成员

成员种类签名说明
start方法start(spec: LocalInferenceProcessSpec): Promise<LocalInferenceProcessHandle>公开方法;参数与返回类型以签名列为准。

LocalInferenceDriverMode

Local Inference Driver Mode 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { LocalInferenceDriverMode } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export type LocalInferenceDriverMode = 'connect' | 'managed';

LocalInferenceDriverState

Local Inference Driver State 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { LocalInferenceDriverState } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export type LocalInferenceDriverState = 'idle' | 'starting' | 'ready' | 'stopping' | 'stopped' | 'failed';

LocalInferenceEngineKind

Local Inference Engine Kind 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { LocalInferenceEngineKind } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export type LocalInferenceEngineKind = 'ollama' | 'sglang' | 'vllm';

LocalInferenceHealthProbe

Local Inference Health Probe 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { LocalInferenceHealthProbe } from '@codesoul-co/hypha-inference';
  • 源码模块: drivers

声明

text
export type LocalInferenceHealthProbe = (request: LocalInferenceHealthProbeRequest) => Promise<boolean>;