Skip to content

@codesoul-co/hypha-models / index

模块用法

聚合 @codesoul-co/hypha-models 的公共入口导出;应用应从包入口导入这些 Symbol,不应依赖内部文件路径。

从包入口导入

ts
import {
  MockModelProvider,
  ModelRegistry,
  modelAliasSpecDefinition,
  modelAliasSpecExample,
  modelAliasSpecJsonSchema,
  modelAliasSpecSchema,
  modelCapabilitiesSchema,
  modelProviderSpecDefinition,
} from '@codesoul-co/hypha-models';

import type {
  ModelAliasSpec,
  ModelCacheControl,
  ModelCapabilities,
  ModelMessage,
  ModelProvider,
  ModelProviderSpec,
  ModelRequest,
  ModelResponse,
} from '@codesoul-co/hypha-models';

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

使用要点

  • 15 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 2 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。
  • 3 个函数是该模块的直接操作入口;每个 overload 的必需/可选参数与返回类型均在下方列出。
  • 16 个常量/枚举提供稳定值、Schema、Definition 或默认配置;应复用这些导出,避免在应用中复制内部值。

运行时校验示例

ts
import { modelAliasSpecSchema } from '@codesoul-co/hypha-models';

declare function loadExternalInput(): unknown;
const input: unknown = loadExternalInput();
const parsed = modelAliasSpecSchema.parse(input);

配置、网络请求或持久化数据等不可信输入应先通过 Runtime Schema,再传给只接受已校验契约的函数或类。

公共导出

Symbol种类签名说明
MockModelProvidernew MockModelProvider(id?: string): MockModelProviderMock Model Provider 类,共公开 6 个构造函数或成员;精确签名见本条目的声明与成员表。
ModelRegistrynew ModelRegistry(): ModelRegistryModel Registry 类,共公开 4 个构造函数或成员;精确签名见本条目的声明与成员表。
modelAliasSpecDefinition常量const modelAliasSpecDefinition: SpecSchemaDefinition<ModelAliasSpec>Model Alias Spec 的运行时校验入口,组合 Parser、Example 与 JSON Schema。
modelAliasSpecExample常量const modelAliasSpecExample: ModelAliasSpecModel Alias Spec 的有效示例值。
modelAliasSpecJsonSchema常量const modelAliasSpecJsonSchema: JsonSchemaModel Alias Spec 的 JSON Schema。
modelAliasSpecSchema常量const modelAliasSpecSchema: z.ZodObject<{ id: z.ZodString; version: z.ZodString; } & { name: z.ZodOptional<z.ZodString>; description: z.ZodOptional<z.ZodString>; owner: z.ZodOptional<z.ZodString>; tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; createdAt: z.ZodOptional<z.ZodString>; updatedAt: z.ZodOptional<z.ZodString>; } & { alias: z.ZodString; providerId: z.ZodString; providerModel: z.ZodString; }, "strip...Model Alias Spec 的运行时 Schema。
modelCapabilitiesSchema常量const modelCapabilitiesSchema: z.ZodObject<{ chat: z.ZodOptional<z.ZodBoolean>; streaming: z.ZodOptional<z.ZodBoolean>; toolCalling: z.ZodOptional<z.ZodBoolean>; jsonMode: z.ZodOptional<z.ZodBoolean>; embeddings: z.ZodOptional<z.ZodBoolean>; reasoning: z.ZodOptional<z.ZodBoolean>; prefixCaching: z.ZodOptional<z.ZodBoolean>; kvCaching: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { chat?: boolean | undefi...Model Capabilities 的运行时 Schema。
modelProviderSpecDefinition常量const modelProviderSpecDefinition: SpecSchemaDefinition<ModelProviderSpec>Model Provider Spec 的运行时校验入口,组合 Parser、Example 与 JSON Schema。
modelProviderSpecExample常量const modelProviderSpecExample: ModelProviderSpecModel Provider Spec 的有效示例值。
modelProviderSpecJsonSchema常量const modelProviderSpecJsonSchema: JsonSchemaModel Provider Spec 的 JSON Schema。
modelProviderSpecSchema常量const modelProviderSpecSchema: z.ZodObject<{ id: z.ZodString; version: z.ZodString; } & { name: z.ZodOptional<z.ZodString>; description: z.ZodOptional<z.ZodString>; owner: z.ZodOptional<z.ZodString>; tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; createdAt: z.ZodOptional<z.ZodString>; updatedAt: z.ZodOptional<z.ZodString>; } & { type: z.ZodString; defaultModelAlias: z.ZodOptional<z.ZodString>; capabilities:...Model Provider Spec 的运行时 Schema。
modelRequestSchema常量const modelRequestSchema: z.ZodObject<{ runId: z.ZodString; stepId: z.ZodString; modelAlias: z.ZodString; instructions: z.ZodOptional<z.ZodString>; input: z.ZodUnknown; tools: z.ZodOptional<z.ZodArray<z.ZodObject<{ id: z.ZodString; name: z.ZodString; description: z.ZodString; inputSchema: z.ZodType<JsonSchema, z.ZodTypeDef, JsonSchema>; }, "strip", z.ZodTypeAny, { id: string; name: string; description: string; inp...Model Request 的运行时 Schema。
modelRoutingSpecDefinition常量const modelRoutingSpecDefinition: SpecSchemaDefinition<ModelRoutingSpec>Model Routing Spec 的运行时校验入口,组合 Parser、Example 与 JSON Schema。
modelRoutingSpecExample常量const modelRoutingSpecExample: ModelRoutingSpecModel Routing Spec 的有效示例值。
modelRoutingSpecJsonSchema常量const modelRoutingSpecJsonSchema: JsonSchemaModel Routing Spec 的 JSON Schema。
modelRoutingSpecSchema常量const modelRoutingSpecSchema: z.ZodObject<{ id: z.ZodString; version: z.ZodString; } & { name: z.ZodOptional<z.ZodString>; description: z.ZodOptional<z.ZodString>; owner: z.ZodOptional<z.ZodString>; tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; createdAt: z.ZodOptional<z.ZodString>; updatedAt: z.ZodOptional<z.ZodString>; } & { defaultAlias: z.ZodString; aliases: z.ZodArray<z.ZodObject<{ id: z.ZodString; ve...Model Routing Spec 的运行时 Schema。
modelSpecDefinitions常量const modelSpecDefinitions: readonly [SpecSchemaDefinition<ModelProviderSpec>, SpecSchemaDefinition<ModelAliasSpec>, SpecSchemaDefinition<ModelRoutingSpec>]index 模块导出的 Model Spec Definitions 常量。
modelSpecJsonSchemas常量const modelSpecJsonSchemas: Record<string, JsonSchema>index 模块导出的 Model Spec JSON Schemas 常量。
validateModelAliasSpec函数validateModelAliasSpec(input: unknown): ModelAliasSpecValidate Model Alias Spec 函数,提供 1 个公开调用签名;参数与返回类型见下表。
validateModelProviderSpec函数validateModelProviderSpec(input: unknown): ModelProviderSpecValidate Model Provider Spec 函数,提供 1 个公开调用签名;参数与返回类型见下表。
validateModelRoutingSpec函数validateModelRoutingSpec(input: unknown): ModelRoutingSpecValidate Model Routing Spec 函数,提供 1 个公开调用签名;参数与返回类型见下表。
ModelAliasSpec接口interface ModelAliasSpec extends VersionedSpec, SpecMetadataModel Alias Spec 接口,共包含 11 个公开字段或方法。
ModelCacheControl接口interface ModelCacheControlModel Cache Control 接口,共包含 4 个公开字段或方法。
ModelCapabilities接口interface ModelCapabilitiesModel Capabilities 接口,共包含 8 个公开字段或方法。
ModelMessage接口interface ModelMessageModel Message 接口,共包含 4 个公开字段或方法。
ModelProvider接口interface ModelProviderModel Provider 接口,共包含 5 个公开字段或方法。
ModelProviderSpec接口interface ModelProviderSpec extends VersionedSpec, SpecMetadataModel Provider Spec 接口,共包含 14 个公开字段或方法。
ModelRequest接口interface ModelRequestModel Request 接口,共包含 12 个公开字段或方法。
ModelResponse接口interface ModelResponseModel Response 接口,共包含 8 个公开字段或方法。
ModelRoutingSpec接口interface ModelRoutingSpec extends VersionedSpec, SpecMetadataModel Routing Spec 接口,共包含 11 个公开字段或方法。
ModelStreamEvent接口interface ModelStreamEventModel Stream Event 接口,共包含 5 个公开字段或方法。
ModelToolDescriptor接口interface ModelToolDescriptorModel Tool Descriptor 接口,共包含 4 个公开字段或方法。
ModelUsage接口interface ModelUsageModel Usage 接口,共包含 5 个公开字段或方法。
NormalizedToolCall接口interface NormalizedToolCallNormalized Tool Call 接口,共包含 3 个公开字段或方法。
ReasoningOptions接口interface ReasoningOptionsReasoning Options 接口,共包含 2 个公开字段或方法。
ModelProviderType类型type ModelProviderType = 'openai' | 'openai-compatible' | 'mock' | stringModel Provider Type 公共类型别名;完整类型表达式见声明。

MockModelProvider

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

  • 种类: 类
  • 导入: import { MockModelProvider } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare class MockModelProvider implements ModelProvider {
    readonly id: string;
    constructor(id?: string);
    capabilities(): ModelCapabilities;
    generate(request: ModelRequest): Promise<ModelResponse>;
    stream(request: ModelRequest): AsyncIterable<ModelStreamEvent>;
    countTokens(input: unknown): Promise<ModelUsage>;
}

公开成员

成员种类签名说明
capabilities方法capabilities(): ModelCapabilities公开方法;参数与返回类型以签名列为准。
constructor构造函数(id?: string): MockModelProvider创建该类的实例。
countTokens方法countTokens(input: unknown): Promise<ModelUsage>公开方法;参数与返回类型以签名列为准。
generate方法generate(request: ModelRequest): Promise<ModelResponse>公开方法;参数与返回类型以签名列为准。
id属性readonly id: string公开属性;类型、只读和可选状态以签名列为准。
stream方法stream(request: ModelRequest): AsyncIterable<ModelStreamEvent>公开方法;参数与返回类型以签名列为准。

ModelRegistry

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

  • 种类: 类
  • 导入: import { ModelRegistry } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare class ModelRegistry {
    register(provider: ModelProvider): void;
    get(providerId: string): ModelProvider | null;
    list(): ModelProvider[];
}

公开成员

成员种类签名说明
constructor构造函数(): ModelRegistry创建该类的实例。
get方法get(providerId: string): ModelProvider | null公开方法;参数与返回类型以签名列为准。
list方法list(): ModelProvider[]公开方法;参数与返回类型以签名列为准。
register方法register(provider: ModelProvider): void公开方法;参数与返回类型以签名列为准。

modelAliasSpecDefinition

Model Alias Spec 的运行时校验入口,组合 Parser、Example 与 JSON Schema。

  • 种类: 常量
  • 导入: import { modelAliasSpecDefinition } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelAliasSpecDefinition: SpecSchemaDefinition<ModelAliasSpec>;

modelAliasSpecExample

Model Alias Spec 的有效示例值。

  • 种类: 常量
  • 导入: import { modelAliasSpecExample } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelAliasSpecExample: ModelAliasSpec;

modelAliasSpecJsonSchema

Model Alias Spec 的 JSON Schema。

  • 种类: 常量
  • 导入: import { modelAliasSpecJsonSchema } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelAliasSpecJsonSchema: JsonSchema;

modelAliasSpecSchema

Model Alias Spec 的运行时 Schema。

  • 种类: 常量
  • 导入: import { modelAliasSpecSchema } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelAliasSpecSchema: z.ZodObject<{ id: z.ZodString; version: z.ZodString; } & { name: z.ZodOptional<z.ZodString>; description: z.ZodOptional<z.ZodString>; owner: z.ZodOptional<z.ZodString>; tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; createdAt: z.ZodOptional<z.ZodString>; updatedAt: z.ZodOptional<z.ZodString>; } & { alias: z.ZodString; providerId: z.ZodString; providerModel: z.ZodString; }, "strip", z.ZodTypeAny, { id: string; version: string; alias: string; providerId: string; providerModel: string; name?: string | undefined; description?: string | undefined; owner?: string | undefined; tags?: string[] | undefined; createdAt?: string | undefined; updatedAt?: string | undefined; }, { id: string; version: string; alias: string; providerId: string; providerModel: string; name?: string | undefined; description?: string | undefined; owner?: string | undefined; tags?: string[] | undefined; createdAt?: string | undefined; updatedAt?: string | undefined; }>;

modelCapabilitiesSchema

Model Capabilities 的运行时 Schema。

  • 种类: 常量
  • 导入: import { modelCapabilitiesSchema } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelCapabilitiesSchema: z.ZodObject<{ chat: z.ZodOptional<z.ZodBoolean>; streaming: z.ZodOptional<z.ZodBoolean>; toolCalling: z.ZodOptional<z.ZodBoolean>; jsonMode: z.ZodOptional<z.ZodBoolean>; embeddings: z.ZodOptional<z.ZodBoolean>; reasoning: z.ZodOptional<z.ZodBoolean>; prefixCaching: z.ZodOptional<z.ZodBoolean>; kvCaching: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { chat?: boolean | undefined; streaming?: boolean | undefined; toolCalling?: boolean | undefined; jsonMode?: boolean | undefined; embeddings?: boolean | undefined; reasoning?: boolean | undefined; prefixCaching?: boolean | undefined; kvCaching?: boolean | undefined; }, { chat?: boolean | undefined; streaming?: boolean | undefined; toolCalling?: boolean | undefined; jsonMode?: boolean | undefined; embeddings?: boolean | undefined; reasoning?: boolean | undefined; prefixCaching?: boolean | undefined; kvCaching?: boolean | undefined; }>;

modelProviderSpecDefinition

Model Provider Spec 的运行时校验入口,组合 Parser、Example 与 JSON Schema。

  • 种类: 常量
  • 导入: import { modelProviderSpecDefinition } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelProviderSpecDefinition: SpecSchemaDefinition<ModelProviderSpec>;

modelProviderSpecExample

Model Provider Spec 的有效示例值。

  • 种类: 常量
  • 导入: import { modelProviderSpecExample } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelProviderSpecExample: ModelProviderSpec;

modelProviderSpecJsonSchema

Model Provider Spec 的 JSON Schema。

  • 种类: 常量
  • 导入: import { modelProviderSpecJsonSchema } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelProviderSpecJsonSchema: JsonSchema;

modelProviderSpecSchema

Model Provider Spec 的运行时 Schema。

  • 种类: 常量
  • 导入: import { modelProviderSpecSchema } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelProviderSpecSchema: z.ZodObject<{ id: z.ZodString; version: z.ZodString; } & { name: z.ZodOptional<z.ZodString>; description: z.ZodOptional<z.ZodString>; owner: z.ZodOptional<z.ZodString>; tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; createdAt: z.ZodOptional<z.ZodString>; updatedAt: z.ZodOptional<z.ZodString>; } & { type: z.ZodString; defaultModelAlias: z.ZodOptional<z.ZodString>; capabilities: z.ZodOptional<z.ZodObject<{ chat: z.ZodOptional<z.ZodBoolean>; streaming: z.ZodOptional<z.ZodBoolean>; toolCalling: z.ZodOptional<z.ZodBoolean>; jsonMode: z.ZodOptional<z.ZodBoolean>; embeddings: z.ZodOptional<z.ZodBoolean>; reasoning: z.ZodOptional<z.ZodBoolean>; prefixCaching: z.ZodOptional<z.ZodBoolean>; kvCaching: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { chat?: boolean | undefined; streaming?: boolean | undefined; toolCalling?: boolean | undefined; jsonMode?: boolean | undefined; embeddings?: boolean | undefined; reasoning?: boolean | undefined; prefixCaching?: boolean | undefined; kvCaching?: boolean | undefined; }, { chat?: boolean | undefined; streaming?: boolean | undefined; toolCalling?: boolean | undefined; jsonMode?: boolean | undefined; embeddings?: boolean | undefined; reasoning?: boolean | undefined; prefixCaching?: boolean | undefined; kvCaching?: boolean | undefined; }>>; apiKeyEnv: z.ZodOptional<z.ZodString>; baseUrl: z.ZodOptional<z.ZodString>; timeoutMs: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { type: string; id: string; version: string; name?: string | undefined; description?: string | undefined; owner?: string | undefined; tags?: string[] | undefined; createdAt?: string | undefined; updatedAt?: string | undefined; defaultModelAlias?: string | undefined; capabilities?: { chat?: boolean | undefined; streaming?: boolean | undefined; toolCalling?: boolean | undefined; jsonMode?: boolean | undefined; embeddings?: boolean | undefined; reasoning?: boolean | undefined; prefixCaching?: boolean | undefined; kvCaching?: boolean | undefined; } | undefined; apiKeyEnv?: string | undefined; baseUrl?: string | undefined; timeoutMs?: number | undefined; }, { type: string; id: string; version: string; name?: string | undefined; description?: string | undefined; owner?: string | undefined; tags?: string[] | undefined; createdAt?: string | undefined; updatedAt?: string | undefined; defaultModelAlias?: string | undefined; capabilities?: { chat?: boolean | undefined; streaming?: boolean | undefined; toolCalling?: boolean | undefined; jsonMode?: boolean | undefined; embeddings?: boolean | undefined; reasoning?: boolean | undefined; prefixCaching?: boolean | undefined; kvCaching?: boolean | undefined; } | undefined; apiKeyEnv?: string | undefined; baseUrl?: string | undefined; timeoutMs?: number | undefined; }>;

modelRequestSchema

Model Request 的运行时 Schema。

  • 种类: 常量
  • 导入: import { modelRequestSchema } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
// 精确类型由包入口解析;完整编译器展开定义见源码链接。
export declare const modelRequestSchema: (typeof import('@codesoul-co/hypha-models'))['modelRequestSchema'];

该常量的编译器展开类型已压缩;它的公共名称、顶层类型与源码位置仍保留在本条目中。相关输入/输出字段请使用同模块导出的接口、类型或 Runtime Schema。

modelRoutingSpecDefinition

Model Routing Spec 的运行时校验入口,组合 Parser、Example 与 JSON Schema。

  • 种类: 常量
  • 导入: import { modelRoutingSpecDefinition } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelRoutingSpecDefinition: SpecSchemaDefinition<ModelRoutingSpec>;

modelRoutingSpecExample

Model Routing Spec 的有效示例值。

  • 种类: 常量
  • 导入: import { modelRoutingSpecExample } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelRoutingSpecExample: ModelRoutingSpec;

modelRoutingSpecJsonSchema

Model Routing Spec 的 JSON Schema。

  • 种类: 常量
  • 导入: import { modelRoutingSpecJsonSchema } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelRoutingSpecJsonSchema: JsonSchema;

modelRoutingSpecSchema

Model Routing Spec 的运行时 Schema。

  • 种类: 常量
  • 导入: import { modelRoutingSpecSchema } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelRoutingSpecSchema: z.ZodObject<{ id: z.ZodString; version: z.ZodString; } & { name: z.ZodOptional<z.ZodString>; description: z.ZodOptional<z.ZodString>; owner: z.ZodOptional<z.ZodString>; tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; createdAt: z.ZodOptional<z.ZodString>; updatedAt: z.ZodOptional<z.ZodString>; } & { defaultAlias: z.ZodString; aliases: z.ZodArray<z.ZodObject<{ id: z.ZodString; version: z.ZodString; } & { name: z.ZodOptional<z.ZodString>; description: z.ZodOptional<z.ZodString>; owner: z.ZodOptional<z.ZodString>; tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; createdAt: z.ZodOptional<z.ZodString>; updatedAt: z.ZodOptional<z.ZodString>; } & { alias: z.ZodString; providerId: z.ZodString; providerModel: z.ZodString; }, "strip", z.ZodTypeAny, { id: string; version: string; alias: string; providerId: string; providerModel: string; name?: string | undefined; description?: string | undefined; owner?: string | undefined; tags?: string[] | undefined; createdAt?: string | undefined; updatedAt?: string | undefined; }, { id: string; version: string; alias: string; providerId: string; providerModel: string; name?: string | undefined; description?: string | undefined; owner?: string | undefined; tags?: string[] | undefined; createdAt?: string | undefined; updatedAt?: string | undefined; }>, "many">; fallbackAliases: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; }, "strip", z.ZodTypeAny, { id: string; version: string; defaultAlias: string; aliases: { id: string; version: string; alias: string; providerId: string; providerModel: string; name?: string | undefined; description?: string | undefined; owner?: string | undefined; tags?: string[] | undefined; createdAt?: string | undefined; updatedAt?: string | undefined; }[]; name?: string | undefined; description?: string | undefined; owner?: string | undefined; tags?: string[] | undefined; createdAt?: string | undefined; updatedAt?: string | undefined; fallbackAliases?: string[] | undefined; }, { id: string; version: string; defaultAlias: string; aliases: { id: string; version: string; alias: string; providerId: string; providerModel: string; name?: string | undefined; description?: string | undefined; owner?: string | undefined; tags?: string[] | undefined; createdAt?: string | undefined; updatedAt?: string | undefined; }[]; name?: string | undefined; description?: string | undefined; owner?: string | undefined; tags?: string[] | undefined; createdAt?: string | undefined; updatedAt?: string | undefined; fallbackAliases?: string[] | undefined; }>;

modelSpecDefinitions

index 模块导出的 Model Spec Definitions 常量。

  • 种类: 常量
  • 导入: import { modelSpecDefinitions } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelSpecDefinitions: readonly [SpecSchemaDefinition<ModelProviderSpec>, SpecSchemaDefinition<ModelAliasSpec>, SpecSchemaDefinition<ModelRoutingSpec>];

modelSpecJsonSchemas

index 模块导出的 Model Spec JSON Schemas 常量。

  • 种类: 常量
  • 导入: import { modelSpecJsonSchemas } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare const modelSpecJsonSchemas: Record<string, JsonSchema>;

validateModelAliasSpec

Validate Model Alias Spec 函数,提供 1 个公开调用签名;参数与返回类型见下表。

  • 种类: 函数
  • 导入: import { validateModelAliasSpec } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare function validateModelAliasSpec(input: unknown): ModelAliasSpec;

调用签名

text
validateModelAliasSpec(input: unknown): ModelAliasSpec

参数

参数类型必需说明
inputunknown必需参数;接受的值由类型列定义。

返回值

  • 类型: ModelAliasSpec
  • 说明: 返回值契约由上述类型定义。

validateModelProviderSpec

Validate Model Provider Spec 函数,提供 1 个公开调用签名;参数与返回类型见下表。

  • 种类: 函数
  • 导入: import { validateModelProviderSpec } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare function validateModelProviderSpec(input: unknown): ModelProviderSpec;

调用签名

text
validateModelProviderSpec(input: unknown): ModelProviderSpec

参数

参数类型必需说明
inputunknown必需参数;接受的值由类型列定义。

返回值

  • 类型: ModelProviderSpec
  • 说明: 返回值契约由上述类型定义。

validateModelRoutingSpec

Validate Model Routing Spec 函数,提供 1 个公开调用签名;参数与返回类型见下表。

  • 种类: 函数
  • 导入: import { validateModelRoutingSpec } from '@codesoul-co/hypha-models';
  • 源码模块: index

声明

text
export declare function validateModelRoutingSpec(input: unknown): ModelRoutingSpec;

调用签名

text
validateModelRoutingSpec(input: unknown): ModelRoutingSpec

参数

参数类型必需说明
inputunknown必需参数;接受的值由类型列定义。

返回值

  • 类型: ModelRoutingSpec
  • 说明: 返回值契约由上述类型定义。

ModelAliasSpec

Model Alias Spec 接口,共包含 11 个公开字段或方法。

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

声明

text
export interface ModelAliasSpec extends VersionedSpec, SpecMetadata {
    alias: string;
    providerId: string;
    providerModel: string;
}

契约成员

成员种类签名说明
alias属性alias: string公开属性;类型、只读和可选状态以签名列为准。
createdAt属性createdAt?: string公开属性;类型、只读和可选状态以签名列为准。
description属性description?: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
name属性name?: string公开属性;类型、只读和可选状态以签名列为准。
owner属性owner?: string公开属性;类型、只读和可选状态以签名列为准。
providerId属性providerId: string公开属性;类型、只读和可选状态以签名列为准。
providerModel属性providerModel: string公开属性;类型、只读和可选状态以签名列为准。
tags属性tags?: string[]公开属性;类型、只读和可选状态以签名列为准。
updatedAt属性updatedAt?: string公开属性;类型、只读和可选状态以签名列为准。
version属性version: string公开属性;类型、只读和可选状态以签名列为准。

ModelCacheControl

Model Cache Control 接口,共包含 4 个公开字段或方法。

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

声明

text
export interface ModelCacheControl {
    prefixContent?: string;
    kvCacheValue?: unknown;
    kvCacheRef?: {
        id: string;
        provider: string;
        modelAlias: string;
        scope: 'run' | 'session' | 'workspace';
        expiresAt?: string;
        metadata?: Record<string, unknown>;
    };
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
kvCacheRef属性kvCacheRef?: { id: string; provider: string; modelAlias: string; scope: "run" | "session" | "workspace"; expiresAt?: string; metadata?: Record<string, unknown>; }公开属性;类型、只读和可选状态以签名列为准。
kvCacheValue属性kvCacheValue?: unknown公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
prefixContent属性prefixContent?: string公开属性;类型、只读和可选状态以签名列为准。

ModelCapabilities

Model Capabilities 接口,共包含 8 个公开字段或方法。

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

声明

text
export interface ModelCapabilities {
    chat?: boolean;
    streaming?: boolean;
    toolCalling?: boolean;
    jsonMode?: boolean;
    embeddings?: boolean;
    reasoning?: boolean;
    prefixCaching?: boolean;
    kvCaching?: boolean;
}

契约成员

成员种类签名说明
chat属性chat?: boolean公开属性;类型、只读和可选状态以签名列为准。
embeddings属性embeddings?: boolean公开属性;类型、只读和可选状态以签名列为准。
jsonMode属性jsonMode?: boolean公开属性;类型、只读和可选状态以签名列为准。
kvCaching属性kvCaching?: boolean公开属性;类型、只读和可选状态以签名列为准。
prefixCaching属性prefixCaching?: boolean公开属性;类型、只读和可选状态以签名列为准。
reasoning属性reasoning?: boolean公开属性;类型、只读和可选状态以签名列为准。
streaming属性streaming?: boolean公开属性;类型、只读和可选状态以签名列为准。
toolCalling属性toolCalling?: boolean公开属性;类型、只读和可选状态以签名列为准。

ModelMessage

Model Message 接口,共包含 4 个公开字段或方法。

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

声明

text
export interface ModelMessage {
    role: 'system' | 'user' | 'assistant' | 'tool';
    content: string;
    name?: string;
    toolCallId?: string;
}

契约成员

成员种类签名说明
content属性content: string公开属性;类型、只读和可选状态以签名列为准。
name属性name?: string公开属性;类型、只读和可选状态以签名列为准。
role属性role: "system" | "tool" | "user" | "assistant"公开属性;类型、只读和可选状态以签名列为准。
toolCallId属性toolCallId?: string公开属性;类型、只读和可选状态以签名列为准。

ModelProvider

Model Provider 接口,共包含 5 个公开字段或方法。

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

声明

text
export interface ModelProvider<TRequest = ModelRequest, TResponse = ModelResponse> {
    id: string;
    capabilities(): ModelCapabilities;
    generate(request: TRequest): Promise<TResponse>;
    stream?(request: TRequest): AsyncIterable<ModelStreamEvent>;
    countTokens?(input: unknown): Promise<ModelUsage>;
}

契约成员

成员种类签名说明
capabilities方法capabilities(): ModelCapabilities公开方法;参数与返回类型以签名列为准。
countTokens方法countTokens?(input: unknown): Promise<ModelUsage>公开方法;参数与返回类型以签名列为准。
generate方法generate(request: TRequest): Promise<TResponse>公开方法;参数与返回类型以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
stream方法stream?(request: TRequest): AsyncIterable<ModelStreamEvent>公开方法;参数与返回类型以签名列为准。

ModelProviderSpec

Model Provider Spec 接口,共包含 14 个公开字段或方法。

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

声明

text
export interface ModelProviderSpec extends VersionedSpec, SpecMetadata {
    id: string;
    type: ModelProviderType;
    defaultModelAlias?: string;
    capabilities?: ModelCapabilities;
    apiKeyEnv?: string;
    baseUrl?: string;
    timeoutMs?: number;
}

契约成员

成员种类签名说明
apiKeyEnv属性apiKeyEnv?: string公开属性;类型、只读和可选状态以签名列为准。
baseUrl属性baseUrl?: string公开属性;类型、只读和可选状态以签名列为准。
capabilities属性capabilities?: ModelCapabilities公开属性;类型、只读和可选状态以签名列为准。
createdAt属性createdAt?: string公开属性;类型、只读和可选状态以签名列为准。
defaultModelAlias属性defaultModelAlias?: string公开属性;类型、只读和可选状态以签名列为准。
description属性description?: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
name属性name?: string公开属性;类型、只读和可选状态以签名列为准。
owner属性owner?: string公开属性;类型、只读和可选状态以签名列为准。
tags属性tags?: string[]公开属性;类型、只读和可选状态以签名列为准。
timeoutMs属性timeoutMs?: number公开属性;类型、只读和可选状态以签名列为准。
type属性type: string公开属性;类型、只读和可选状态以签名列为准。
updatedAt属性updatedAt?: string公开属性;类型、只读和可选状态以签名列为准。
version属性version: string公开属性;类型、只读和可选状态以签名列为准。

ModelRequest

Model Request 接口,共包含 12 个公开字段或方法。

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

声明

text
export interface ModelRequest<TInput = unknown> {
    runId: string;
    stepId: string;
    modelAlias: string;
    instructions?: string;
    input: TInput;
    tools?: ModelToolDescriptor[];
    responseFormat?: SpecRef | JsonSchema;
    reasoning?: ReasoningOptions;
    temperature?: number;
    maxTokens?: number;
    cache?: ModelCacheControl;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
cache属性cache?: ModelCacheControl公开属性;类型、只读和可选状态以签名列为准。
input属性input: TInput公开属性;类型、只读和可选状态以签名列为准。
instructions属性instructions?: string公开属性;类型、只读和可选状态以签名列为准。
maxTokens属性maxTokens?: number公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
modelAlias属性modelAlias: string公开属性;类型、只读和可选状态以签名列为准。
reasoning属性reasoning?: ReasoningOptions公开属性;类型、只读和可选状态以签名列为准。
responseFormat属性responseFormat?: SpecRef | JsonSchema公开属性;类型、只读和可选状态以签名列为准。
runId属性runId: string公开属性;类型、只读和可选状态以签名列为准。
stepId属性stepId: string公开属性;类型、只读和可选状态以签名列为准。
temperature属性temperature?: number公开属性;类型、只读和可选状态以签名列为准。
tools属性tools?: ModelToolDescriptor[]公开属性;类型、只读和可选状态以签名列为准。

ModelResponse

Model Response 接口,共包含 8 个公开字段或方法。

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

声明

text
export interface ModelResponse<TContent = string> {
    id: string;
    providerId?: string;
    model?: string;
    content: TContent;
    toolCalls?: NormalizedToolCall[];
    usage?: ModelUsage;
    metadata?: Record<string, unknown>;
    raw?: unknown;
}

契约成员

成员种类签名说明
content属性content: TContent公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
model属性model?: string公开属性;类型、只读和可选状态以签名列为准。
providerId属性providerId?: string公开属性;类型、只读和可选状态以签名列为准。
raw属性raw?: unknown公开属性;类型、只读和可选状态以签名列为准。
toolCalls属性toolCalls?: NormalizedToolCall[]公开属性;类型、只读和可选状态以签名列为准。
usage属性usage?: ModelUsage公开属性;类型、只读和可选状态以签名列为准。

ModelRoutingSpec

Model Routing Spec 接口,共包含 11 个公开字段或方法。

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

声明

text
export interface ModelRoutingSpec extends VersionedSpec, SpecMetadata {
    defaultAlias: string;
    aliases: ModelAliasSpec[];
    fallbackAliases?: string[];
}

契约成员

成员种类签名说明
aliases属性aliases: ModelAliasSpec[]公开属性;类型、只读和可选状态以签名列为准。
createdAt属性createdAt?: string公开属性;类型、只读和可选状态以签名列为准。
defaultAlias属性defaultAlias: string公开属性;类型、只读和可选状态以签名列为准。
description属性description?: string公开属性;类型、只读和可选状态以签名列为准。
fallbackAliases属性fallbackAliases?: string[]公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
name属性name?: string公开属性;类型、只读和可选状态以签名列为准。
owner属性owner?: string公开属性;类型、只读和可选状态以签名列为准。
tags属性tags?: string[]公开属性;类型、只读和可选状态以签名列为准。
updatedAt属性updatedAt?: string公开属性;类型、只读和可选状态以签名列为准。
version属性version: string公开属性;类型、只读和可选状态以签名列为准。

ModelStreamEvent

Model Stream Event 接口,共包含 5 个公开字段或方法。

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

声明

text
export interface ModelStreamEvent<TContent = string> {
    type: 'delta' | 'tool_call' | 'usage' | 'done' | 'error';
    content?: TContent;
    toolCall?: NormalizedToolCall;
    usage?: ModelUsage;
    error?: unknown;
}

契约成员

成员种类签名说明
content属性content?: TContent公开属性;类型、只读和可选状态以签名列为准。
error属性error?: unknown公开属性;类型、只读和可选状态以签名列为准。
toolCall属性toolCall?: NormalizedToolCall公开属性;类型、只读和可选状态以签名列为准。
type属性type: "error" | "delta" | "tool_call" | "usage" | "done"公开属性;类型、只读和可选状态以签名列为准。
usage属性usage?: ModelUsage公开属性;类型、只读和可选状态以签名列为准。

ModelToolDescriptor

Model Tool Descriptor 接口,共包含 4 个公开字段或方法。

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

声明

text
export interface ModelToolDescriptor {
    id: string;
    name: string;
    description: string;
    inputSchema: JsonSchema;
}

契约成员

成员种类签名说明
description属性description: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
inputSchema属性inputSchema: JsonSchema公开属性;类型、只读和可选状态以签名列为准。
name属性name: string公开属性;类型、只读和可选状态以签名列为准。

ModelUsage

Model Usage 接口,共包含 5 个公开字段或方法。

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

声明

text
export interface ModelUsage {
    inputTokens?: number;
    outputTokens?: number;
    totalTokens?: number;
    cacheHitTokens?: number;
    cacheMissTokens?: number;
}

契约成员

成员种类签名说明
cacheHitTokens属性cacheHitTokens?: number公开属性;类型、只读和可选状态以签名列为准。
cacheMissTokens属性cacheMissTokens?: number公开属性;类型、只读和可选状态以签名列为准。
inputTokens属性inputTokens?: number公开属性;类型、只读和可选状态以签名列为准。
outputTokens属性outputTokens?: number公开属性;类型、只读和可选状态以签名列为准。
totalTokens属性totalTokens?: number公开属性;类型、只读和可选状态以签名列为准。

NormalizedToolCall

Normalized Tool Call 接口,共包含 3 个公开字段或方法。

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

声明

text
export interface NormalizedToolCall {
    id: string;
    toolId: string;
    arguments: unknown;
}

契约成员

成员种类签名说明
arguments属性arguments: unknown公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
toolId属性toolId: string公开属性;类型、只读和可选状态以签名列为准。

ReasoningOptions

Reasoning Options 接口,共包含 2 个公开字段或方法。

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

声明

text
export interface ReasoningOptions {
    effort?: 'low' | 'medium' | 'high';
    budgetTokens?: number;
}

契约成员

成员种类签名说明
budgetTokens属性budgetTokens?: number公开属性;类型、只读和可选状态以签名列为准。
effort属性effort?: "low" | "medium" | "high"公开属性;类型、只读和可选状态以签名列为准。

ModelProviderType

Model Provider Type 公共类型别名;完整类型表达式见声明。

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

声明

text
export type ModelProviderType = 'openai' | 'openai-compatible' | 'mock' | string;