Skip to content

@codesoul-co/hypha-serving-cache / types

模块用法

用于声明并运行时校验契约。Types 模块公开 18 接口、11 类型。

从包入口导入

ts
import type {
  CachedLLMProviderOptions,
  CachedModelResponseProjection,
  CacheEntry,
  CacheLookupHit,
  CacheLookupMiss,
  CacheMetadata,
  CachePolicy,
  CacheScope,
} from '@codesoul-co/hypha-serving-cache';

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

使用要点

  • 29 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。

公共导出

Symbol种类签名说明
CachedLLMProviderOptions接口interface CachedLLMProviderOptionsCached LLM Provider Options 接口,共包含 8 个公开字段或方法。
CachedModelResponseProjection接口interface CachedModelResponseProjectionCached Model Response Projection 接口,共包含 6 个公开字段或方法。
CacheEntry接口interface CacheEntryCache Entry 接口,共包含 8 个公开字段或方法。
CacheLookupHit接口interface CacheLookupHitCache Lookup Hit 接口,共包含 4 个公开字段或方法。
CacheLookupMiss接口interface CacheLookupMissCache Lookup Miss 接口,共包含 3 个公开字段或方法。
CacheMetadata接口interface CacheMetadataCache Metadata 接口,共包含 12 个公开字段或方法。
CachePolicy接口interface CachePolicyCache Policy 接口,共包含 10 个公开字段或方法。
CacheScope接口interface CacheScopeCache Scope 接口,共包含 5 个公开字段或方法。
CacheStore接口interface CacheStoreCache Store 接口,共包含 8 个公开字段或方法。
CacheStoreHealth接口interface CacheStoreHealthCache Store Health 接口,共包含 3 个公开字段或方法。
CacheStoreStats接口interface CacheStoreStatsCache Store Stats 接口,共包含 3 个公开字段或方法。
LLMCacheKeyInput接口interface LLMCacheKeyInputLLM Cache Key Input 接口,共包含 8 个公开字段或方法。
ModelRequestCacheControl接口interface ModelRequestCacheControlModel Request Cache Control 接口,共包含 2 个公开字段或方法。
PrefixCacheShapeObservation接口interface PrefixCacheShapeObservationPrefix Cache Shape Observation 接口,共包含 17 个公开字段或方法。
PromptPrefixBlock接口interface PromptPrefixBlock extends Required<Pick<PromptPrefixBlockInput, 'id' | 'type' | 'hash'>>Prompt Prefix Block 接口,共包含 11 个公开字段或方法。
PromptPrefixBlockInput接口interface PromptPrefixBlockInputPrompt Prefix Block Input 接口,共包含 11 个公开字段或方法。
PromptPrefixMetadata接口interface PromptPrefixMetadataPrompt Prefix Metadata 接口,共包含 7 个公开字段或方法。
ProviderPrefixCacheUsage接口interface ProviderPrefixCacheUsageProvider Prefix Cache Usage 接口,共包含 5 个公开字段或方法。
CacheFailureMode类型type CacheFailureMode = 'bypass' | 'strict'Cache Failure Mode 公共类型别名;完整类型表达式见声明。
CacheLookupResult类型type CacheLookupResult = CacheLookupHit<T> | CacheLookupMissCache Lookup Result 公共类型别名;完整类型表达式见声明。
CacheMode类型type CacheMode = 'off' | 'read' | 'write' | 'readwrite'Cache Mode 公共类型别名;完整类型表达式见声明。
CacheScopeRequirement类型type CacheScopeRequirement = 'none' | 'user' | 'session'Cache Scope Requirement 公共类型别名;完整类型表达式见声明。
CacheType类型type CacheType = 'exact' | 'prefix-metadata' | 'semantic'Cache Type 公共类型别名;完整类型表达式见声明。
PrefixCacheChangeReason类型type PrefixCacheChangeReason = 'first_request' | 'prefix_changed' | 'tool_schema_changed' | 'domain_pack_changed' | 'dynamic_suffix_changed' | 'unchanged'Prefix Cache Change Reason 公共类型别名;完整类型表达式见声明。
PromptPrefixBlockType类型type PromptPrefixBlockType = 'system' | 'tool-schema' | 'project-context' | 'domain-pack' | 'memory' | 'prompt-template'Prompt Prefix Block Type 公共类型别名;完整类型表达式见声明。
ServingCacheEvent类型type ServingCacheEvent = { type: 'llm.cache.lookup'; key: string; provider: string; model: string; scope?: CacheScope; prefixCache?: PrefixCacheShapeObservation; runId?: string; stepId?: string; } | { type: 'llm.cache.hit'; key: string; ageMs: number; provider: string; model: string; scope?: CacheScope; prefixCache?: PrefixCacheShapeObservation; runId?: string; stepId?: string; } | { type: 'llm.cache.miss'; key: s...Serving Cache Event 公共类型别名;完整类型表达式见声明。
ServingCacheMissReason类型type ServingCacheMissReason = 'not_found' | 'expired' | 'disabled' | 'streaming' | 'no_cache' | 'mode_off' | 'read_disabled' | 'scope_missing' | 'store_unavailable' | 'entry_oversized' | 'corrupt'Serving Cache Miss Reason 公共类型别名;完整类型表达式见声明。
ServingCacheStoreKind类型type ServingCacheStoreKind = 'off' | 'noop' | 'memory' | 'sqlite' | 'redis'Serving Cache Store Kind 公共类型别名;完整类型表达式见声明。
ServingCacheTraceSink类型type ServingCacheTraceSink = (event: ServingCacheEvent) => void | Promise<void>Serving Cache Trace Sink 公共类型别名;完整类型表达式见声明。

CachedLLMProviderOptions

Cached LLM Provider Options 接口,共包含 8 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { CachedLLMProviderOptions } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface CachedLLMProviderOptions {
    policy?: Partial<CachePolicy>;
    trace?: ServingCacheTraceSink;
    providerResolver?: (request: ModelRequest, inner: ModelProvider<ModelRequest, ModelResponse>) => string;
    modelResolver?: (request: ModelRequest, inner: ModelProvider<ModelRequest, ModelResponse>) => string;
    scopeResolver?: (request: ModelRequest) => CacheScope | undefined;
    paramsResolver?: (request: ModelRequest) => Record<string, unknown> | undefined;
    promptBlocksResolver?: (request: ModelRequest) => PromptPrefixBlockInput[] | undefined;
    responseIdFactory?: (request: ModelRequest, key: string) => string;
}

契约成员

成员种类签名说明
modelResolver方法modelResolver?(request: ModelRequest, inner: ModelProvider<ModelRequest, ModelResponse>): string公开方法;参数与返回类型以签名列为准。
paramsResolver方法paramsResolver?(request: ModelRequest): Record<string, unknown> | undefined公开方法;参数与返回类型以签名列为准。
policy属性policy?: Partial<CachePolicy>公开属性;类型、只读和可选状态以签名列为准。
promptBlocksResolver方法promptBlocksResolver?(request: ModelRequest): PromptPrefixBlockInput[] | undefined公开方法;参数与返回类型以签名列为准。
providerResolver方法providerResolver?(request: ModelRequest, inner: ModelProvider<ModelRequest, ModelResponse>): string公开方法;参数与返回类型以签名列为准。
responseIdFactory方法responseIdFactory?(request: ModelRequest, key: string): string公开方法;参数与返回类型以签名列为准。
scopeResolver方法scopeResolver?(request: ModelRequest): CacheScope | undefined公开方法;参数与返回类型以签名列为准。
trace方法trace?(event: ServingCacheEvent): void | Promise<void>公开方法;参数与返回类型以签名列为准。

CachedModelResponseProjection

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

  • 种类: 接口
  • 导入: import type { CachedModelResponseProjection } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface CachedModelResponseProjection {
    schemaVersion: '1.0';
    providerId?: string;
    model?: string;
    content: ModelResponse['content'];
    toolCalls?: ModelResponse['toolCalls'];
    usage?: ModelResponse['usage'];
}

契约成员

成员种类签名说明
content属性content: string公开属性;类型、只读和可选状态以签名列为准。
model属性model?: string公开属性;类型、只读和可选状态以签名列为准。
providerId属性providerId?: string公开属性;类型、只读和可选状态以签名列为准。
schemaVersion属性schemaVersion: "1.0"公开属性;类型、只读和可选状态以签名列为准。
toolCalls属性toolCalls?: import("/Users/erwin/Downloads/codespace/Hypha/packages/models/dist/index").NormalizedToolCall[]公开属性;类型、只读和可选状态以签名列为准。
usage属性usage?: import("/Users/erwin/Downloads/codespace/Hypha/packages/models/dist/index").ModelUsage公开属性;类型、只读和可选状态以签名列为准。

CacheEntry

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

  • 种类: 接口
  • 导入: import type { CacheEntry } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface CacheEntry<T = unknown> {
    schemaVersion?: '1.0';
    keyVersion?: '1';
    key: string;
    value: T;
    createdAt: number;
    expiresAt?: number;
    sizeBytes?: number;
    metadata?: CacheMetadata;
}

契约成员

成员种类签名说明
createdAt属性createdAt: number公开属性;类型、只读和可选状态以签名列为准。
expiresAt属性expiresAt?: number公开属性;类型、只读和可选状态以签名列为准。
key属性key: string公开属性;类型、只读和可选状态以签名列为准。
keyVersion属性keyVersion?: "1"公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: CacheMetadata公开属性;类型、只读和可选状态以签名列为准。
schemaVersion属性schemaVersion?: "1.0"公开属性;类型、只读和可选状态以签名列为准。
sizeBytes属性sizeBytes?: number公开属性;类型、只读和可选状态以签名列为准。
value属性value: T公开属性;类型、只读和可选状态以签名列为准。

CacheLookupHit

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

  • 种类: 接口
  • 导入: import type { CacheLookupHit } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface CacheLookupHit<T = unknown> {
    hit: true;
    key: string;
    entry: CacheEntry<T>;
    ageMs: number;
}

契约成员

成员种类签名说明
ageMs属性ageMs: number公开属性;类型、只读和可选状态以签名列为准。
entry属性entry: CacheEntry<T>公开属性;类型、只读和可选状态以签名列为准。
hit属性hit: true公开属性;类型、只读和可选状态以签名列为准。
key属性key: string公开属性;类型、只读和可选状态以签名列为准。

CacheLookupMiss

Cache Lookup Miss 接口,共包含 3 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { CacheLookupMiss } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface CacheLookupMiss {
    hit: false;
    key: string;
    reason: 'not_found' | 'expired';
}

契约成员

成员种类签名说明
hit属性hit: false公开属性;类型、只读和可选状态以签名列为准。
key属性key: string公开属性;类型、只读和可选状态以签名列为准。
reason属性reason: "not_found" | "expired"公开属性;类型、只读和可选状态以签名列为准。

CacheMetadata

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

  • 种类: 接口
  • 导入: import type { CacheMetadata } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface CacheMetadata {
    provider: string;
    model: string;
    cacheType: CacheType;
    promptHash?: string;
    toolSchemaHash?: string;
    requestHash?: string;
    hitCount?: number;
    tags?: string[];
    scope?: CacheScope;
    projectionType?: string;
    classification?: 'public' | 'internal' | 'confidential' | 'restricted';
    prefixMetadata?: PromptPrefixMetadata;
}

契约成员

成员种类签名说明
cacheType属性cacheType: CacheType公开属性;类型、只读和可选状态以签名列为准。
classification属性classification?: "restricted" | "public" | "internal" | "confidential"公开属性;类型、只读和可选状态以签名列为准。
hitCount属性hitCount?: number公开属性;类型、只读和可选状态以签名列为准。
model属性model: string公开属性;类型、只读和可选状态以签名列为准。
prefixMetadata属性prefixMetadata?: PromptPrefixMetadata公开属性;类型、只读和可选状态以签名列为准。
projectionType属性projectionType?: string公开属性;类型、只读和可选状态以签名列为准。
promptHash属性promptHash?: string公开属性;类型、只读和可选状态以签名列为准。
provider属性provider: string公开属性;类型、只读和可选状态以签名列为准。
requestHash属性requestHash?: string公开属性;类型、只读和可选状态以签名列为准。
scope属性scope?: CacheScope公开属性;类型、只读和可选状态以签名列为准。
tags属性tags?: string[]公开属性;类型、只读和可选状态以签名列为准。
toolSchemaHash属性toolSchemaHash?: string公开属性;类型、只读和可选状态以签名列为准。

CachePolicy

Cache Policy 接口,共包含 10 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { CachePolicy } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface CachePolicy {
    enabled: boolean;
    mode: CacheMode;
    ttlMs?: number;
    respectNoCache?: boolean;
    failureMode?: CacheFailureMode;
    scopeRequirement?: CacheScopeRequirement;
    operationTimeoutMs?: number;
    singleflight?: boolean;
    maxEntryBytes?: number;
    circuitBreaker?: {
        failureThreshold: number;
        resetTimeoutMs: number;
    };
}

契约成员

成员种类签名说明
circuitBreaker属性circuitBreaker?: { failureThreshold: number; resetTimeoutMs: number; }公开属性;类型、只读和可选状态以签名列为准。
enabled属性enabled: boolean公开属性;类型、只读和可选状态以签名列为准。
failureMode属性failureMode?: CacheFailureMode公开属性;类型、只读和可选状态以签名列为准。
maxEntryBytes属性maxEntryBytes?: number公开属性;类型、只读和可选状态以签名列为准。
mode属性mode: CacheMode公开属性;类型、只读和可选状态以签名列为准。
operationTimeoutMs属性operationTimeoutMs?: number公开属性;类型、只读和可选状态以签名列为准。
respectNoCache属性respectNoCache?: boolean公开属性;类型、只读和可选状态以签名列为准。
scopeRequirement属性scopeRequirement?: CacheScopeRequirement公开属性;类型、只读和可选状态以签名列为准。
singleflight属性singleflight?: boolean公开属性;类型、只读和可选状态以签名列为准。
ttlMs属性ttlMs?: number公开属性;类型、只读和可选状态以签名列为准。

CacheScope

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

  • 种类: 接口
  • 导入: import type { CacheScope } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface CacheScope {
    tenantId?: string;
    userId?: string;
    projectId?: string;
    sessionId?: string;
    domainPackId?: string;
}

契约成员

成员种类签名说明
domainPackId属性domainPackId?: string公开属性;类型、只读和可选状态以签名列为准。
projectId属性projectId?: string公开属性;类型、只读和可选状态以签名列为准。
sessionId属性sessionId?: string公开属性;类型、只读和可选状态以签名列为准。
tenantId属性tenantId?: string公开属性;类型、只读和可选状态以签名列为准。
userId属性userId?: string公开属性;类型、只读和可选状态以签名列为准。

CacheStore

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

  • 种类: 接口
  • 导入: import type { CacheStore } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface CacheStore<T = unknown> {
    get<TValue = T>(key: string): Promise<CacheEntry<TValue> | null>;
    set<TValue = T>(key: string, entry: CacheEntry<TValue>): Promise<void>;
    delete(key: string): Promise<void>;
    clear?(): Promise<void>;
    touch?(key: string, timestamp: number): Promise<void>;
    stats?(): Promise<CacheStoreStats>;
    health?(): Promise<CacheStoreHealth>;
    close?(): Promise<void>;
}

契约成员

成员种类签名说明
clear方法clear?(): Promise<void>公开方法;参数与返回类型以签名列为准。
close方法close?(): Promise<void>公开方法;参数与返回类型以签名列为准。
delete方法delete(key: string): Promise<void>公开方法;参数与返回类型以签名列为准。
get方法get<TValue = T>(key: string): Promise<CacheEntry<TValue> | null>公开方法;参数与返回类型以签名列为准。
health方法health?(): Promise<CacheStoreHealth>公开方法;参数与返回类型以签名列为准。
set方法set<TValue = T>(key: string, entry: CacheEntry<TValue>): Promise<void>公开方法;参数与返回类型以签名列为准。
stats方法stats?(): Promise<CacheStoreStats>公开方法;参数与返回类型以签名列为准。
touch方法touch?(key: string, timestamp: number): Promise<void>公开方法;参数与返回类型以签名列为准。

CacheStoreHealth

Cache Store Health 接口,共包含 3 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { CacheStoreHealth } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface CacheStoreHealth {
    status: 'healthy' | 'degraded' | 'unavailable';
    checkedAt: string;
    details?: Record<string, unknown>;
}

契约成员

成员种类签名说明
checkedAt属性checkedAt: string公开属性;类型、只读和可选状态以签名列为准。
details属性details?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
status属性status: "healthy" | "degraded" | "unavailable"公开属性;类型、只读和可选状态以签名列为准。

CacheStoreStats

Cache Store Stats 接口,共包含 3 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { CacheStoreStats } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface CacheStoreStats {
    entries: number;
    sizeBytes?: number;
    evictions?: number;
}

契约成员

成员种类签名说明
entries属性entries: number公开属性;类型、只读和可选状态以签名列为准。
evictions属性evictions?: number公开属性;类型、只读和可选状态以签名列为准。
sizeBytes属性sizeBytes?: number公开属性;类型、只读和可选状态以签名列为准。

LLMCacheKeyInput

LLM Cache Key Input 接口,共包含 8 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { LLMCacheKeyInput } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface LLMCacheKeyInput {
    provider: string;
    model: string;
    messages: unknown[];
    system?: string;
    tools?: unknown[];
    params?: Record<string, unknown>;
    cacheScope?: CacheScope;
    promptBlocks?: PromptPrefixBlockInput[];
}

契约成员

成员种类签名说明
cacheScope属性cacheScope?: CacheScope公开属性;类型、只读和可选状态以签名列为准。
messages属性messages: unknown[]公开属性;类型、只读和可选状态以签名列为准。
model属性model: string公开属性;类型、只读和可选状态以签名列为准。
params属性params?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
promptBlocks属性promptBlocks?: PromptPrefixBlockInput[]公开属性;类型、只读和可选状态以签名列为准。
provider属性provider: string公开属性;类型、只读和可选状态以签名列为准。
system属性system?: string公开属性;类型、只读和可选状态以签名列为准。
tools属性tools?: unknown[]公开属性;类型、只读和可选状态以签名列为准。

ModelRequestCacheControl

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

  • 种类: 接口
  • 导入: import type { ModelRequestCacheControl } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface ModelRequestCacheControl {
    mode?: CacheMode;
    noCache?: boolean;
}

契约成员

成员种类签名说明
mode属性mode?: CacheMode公开属性;类型、只读和可选状态以签名列为准。
noCache属性noCache?: boolean公开属性;类型、只读和可选状态以签名列为准。

PrefixCacheShapeObservation

Prefix Cache Shape Observation 接口,共包含 17 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { PrefixCacheShapeObservation } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface PrefixCacheShapeObservation {
    provider: string;
    model: string;
    prefixHash: string;
    previousPrefixHash?: string;
    toolSchemaHash?: string;
    previousToolSchemaHash?: string;
    domainPackHash?: string;
    previousDomainPackHash?: string;
    dynamicSuffixHash?: string;
    previousDynamicSuffixHash?: string;
    requestHash?: string;
    prefixTokenEstimate?: number;
    blockCount: number;
    stablePrefixChanged: boolean;
    dynamicSuffixChanged: boolean;
    changedReasons: PrefixCacheChangeReason[];
    scope?: CacheScope;
}

契约成员

成员种类签名说明
blockCount属性blockCount: number公开属性;类型、只读和可选状态以签名列为准。
changedReasons属性changedReasons: PrefixCacheChangeReason[]公开属性;类型、只读和可选状态以签名列为准。
domainPackHash属性domainPackHash?: string公开属性;类型、只读和可选状态以签名列为准。
dynamicSuffixChanged属性dynamicSuffixChanged: boolean公开属性;类型、只读和可选状态以签名列为准。
dynamicSuffixHash属性dynamicSuffixHash?: string公开属性;类型、只读和可选状态以签名列为准。
model属性model: string公开属性;类型、只读和可选状态以签名列为准。
prefixHash属性prefixHash: string公开属性;类型、只读和可选状态以签名列为准。
prefixTokenEstimate属性prefixTokenEstimate?: number公开属性;类型、只读和可选状态以签名列为准。
previousDomainPackHash属性previousDomainPackHash?: string公开属性;类型、只读和可选状态以签名列为准。
previousDynamicSuffixHash属性previousDynamicSuffixHash?: string公开属性;类型、只读和可选状态以签名列为准。
previousPrefixHash属性previousPrefixHash?: string公开属性;类型、只读和可选状态以签名列为准。
previousToolSchemaHash属性previousToolSchemaHash?: string公开属性;类型、只读和可选状态以签名列为准。
provider属性provider: string公开属性;类型、只读和可选状态以签名列为准。
requestHash属性requestHash?: string公开属性;类型、只读和可选状态以签名列为准。
scope属性scope?: CacheScope公开属性;类型、只读和可选状态以签名列为准。
stablePrefixChanged属性stablePrefixChanged: boolean公开属性;类型、只读和可选状态以签名列为准。
toolSchemaHash属性toolSchemaHash?: string公开属性;类型、只读和可选状态以签名列为准。

PromptPrefixBlock

Prompt Prefix Block 接口,共包含 11 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { PromptPrefixBlock } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface PromptPrefixBlock extends Required<Pick<PromptPrefixBlockInput, 'id' | 'type' | 'hash'>> {
    stable: boolean;
    content?: string;
    tokenEstimate?: number;
    order?: number;
    source?: string;
    templateId?: string;
    templateVersion?: string;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
content属性content?: string公开属性;类型、只读和可选状态以签名列为准。
hash属性hash?: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
order属性order?: number公开属性;类型、只读和可选状态以签名列为准。
source属性source?: string公开属性;类型、只读和可选状态以签名列为准。
stable属性stable: boolean公开属性;类型、只读和可选状态以签名列为准。
templateId属性templateId?: string公开属性;类型、只读和可选状态以签名列为准。
templateVersion属性templateVersion?: string公开属性;类型、只读和可选状态以签名列为准。
tokenEstimate属性tokenEstimate?: number公开属性;类型、只读和可选状态以签名列为准。
type属性type: PromptPrefixBlockType公开属性;类型、只读和可选状态以签名列为准。

PromptPrefixBlockInput

Prompt Prefix Block Input 接口,共包含 11 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { PromptPrefixBlockInput } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface PromptPrefixBlockInput {
    id: string;
    type: PromptPrefixBlockType;
    stable?: boolean;
    hash?: string;
    content?: string;
    tokenEstimate?: number;
    order?: number;
    source?: string;
    templateId?: string;
    templateVersion?: string;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
content属性content?: string公开属性;类型、只读和可选状态以签名列为准。
hash属性hash?: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
order属性order?: number公开属性;类型、只读和可选状态以签名列为准。
source属性source?: string公开属性;类型、只读和可选状态以签名列为准。
stable属性stable?: boolean公开属性;类型、只读和可选状态以签名列为准。
templateId属性templateId?: string公开属性;类型、只读和可选状态以签名列为准。
templateVersion属性templateVersion?: string公开属性;类型、只读和可选状态以签名列为准。
tokenEstimate属性tokenEstimate?: number公开属性;类型、只读和可选状态以签名列为准。
type属性type: PromptPrefixBlockType公开属性;类型、只读和可选状态以签名列为准。

PromptPrefixMetadata

Prompt Prefix Metadata 接口,共包含 7 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { PromptPrefixMetadata } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface PromptPrefixMetadata {
    prefixHash: string;
    prefixTokenEstimate?: number;
    dynamicSuffixHash?: string;
    requestHash?: string;
    toolSchemaHash?: string;
    domainPackHash?: string;
    blocks: PromptPrefixBlock[];
}

契约成员

成员种类签名说明
blocks属性blocks: PromptPrefixBlock[]公开属性;类型、只读和可选状态以签名列为准。
domainPackHash属性domainPackHash?: string公开属性;类型、只读和可选状态以签名列为准。
dynamicSuffixHash属性dynamicSuffixHash?: string公开属性;类型、只读和可选状态以签名列为准。
prefixHash属性prefixHash: string公开属性;类型、只读和可选状态以签名列为准。
prefixTokenEstimate属性prefixTokenEstimate?: number公开属性;类型、只读和可选状态以签名列为准。
requestHash属性requestHash?: string公开属性;类型、只读和可选状态以签名列为准。
toolSchemaHash属性toolSchemaHash?: string公开属性;类型、只读和可选状态以签名列为准。

ProviderPrefixCacheUsage

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

  • 种类: 接口
  • 导入: import type { ProviderPrefixCacheUsage } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export interface ProviderPrefixCacheUsage {
    source: 'provider-usage' | 'hypha-serving-cache' | 'unknown';
    inputTokens?: number;
    hitTokens?: number;
    missTokens?: number;
    hitRate?: number;
}

契约成员

成员种类签名说明
hitRate属性hitRate?: number公开属性;类型、只读和可选状态以签名列为准。
hitTokens属性hitTokens?: number公开属性;类型、只读和可选状态以签名列为准。
inputTokens属性inputTokens?: number公开属性;类型、只读和可选状态以签名列为准。
missTokens属性missTokens?: number公开属性;类型、只读和可选状态以签名列为准。
source属性source: "unknown" | "provider-usage" | "hypha-serving-cache"公开属性;类型、只读和可选状态以签名列为准。

CacheFailureMode

Cache Failure Mode 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { CacheFailureMode } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export type CacheFailureMode = 'bypass' | 'strict';

CacheLookupResult

Cache Lookup Result 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { CacheLookupResult } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export type CacheLookupResult<T = unknown> = CacheLookupHit<T> | CacheLookupMiss;

CacheMode

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

  • 种类: 类型
  • 导入: import type { CacheMode } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export type CacheMode = 'off' | 'read' | 'write' | 'readwrite';

CacheScopeRequirement

Cache Scope Requirement 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { CacheScopeRequirement } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export type CacheScopeRequirement = 'none' | 'user' | 'session';

CacheType

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

  • 种类: 类型
  • 导入: import type { CacheType } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export type CacheType = 'exact' | 'prefix-metadata' | 'semantic';

PrefixCacheChangeReason

Prefix Cache Change Reason 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { PrefixCacheChangeReason } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export type PrefixCacheChangeReason = 'first_request' | 'prefix_changed' | 'tool_schema_changed' | 'domain_pack_changed' | 'dynamic_suffix_changed' | 'unchanged';

PromptPrefixBlockType

Prompt Prefix Block Type 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { PromptPrefixBlockType } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export type PromptPrefixBlockType = 'system' | 'tool-schema' | 'project-context' | 'domain-pack' | 'memory' | 'prompt-template';

ServingCacheEvent

Serving Cache Event 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { ServingCacheEvent } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export type ServingCacheEvent = {
    type: 'llm.cache.lookup';
    key: string;
    provider: string;
    model: string;
    scope?: CacheScope;
    prefixCache?: PrefixCacheShapeObservation;
    runId?: string;
    stepId?: string;
} | {
    type: 'llm.cache.hit';
    key: string;
    ageMs: number;
    provider: string;
    model: string;
    scope?: CacheScope;
    prefixCache?: PrefixCacheShapeObservation;
    runId?: string;
    stepId?: string;
} | {
    type: 'llm.cache.miss';
    key: string;
    reason: ServingCacheMissReason;
    provider: string;
    model: string;
    scope?: CacheScope;
    prefixCache?: PrefixCacheShapeObservation;
    runId?: string;
    stepId?: string;
} | {
    type: 'llm.cache.write';
    key: string;
    ttlMs?: number;
    provider: string;
    model: string;
    scope?: CacheScope;
    prefixMetadata?: PromptPrefixMetadata;
    prefixCache?: PrefixCacheShapeObservation;
    providerPrefixCache?: ProviderPrefixCacheUsage;
    runId?: string;
    stepId?: string;
} | {
    type: 'llm.cache.bypass';
    reason: ServingCacheMissReason;
    operation?: 'lookup' | 'write' | 'delete' | 'trace';
    code?: string;
    key?: string;
    provider?: string;
    model?: string;
    scope?: CacheScope;
    runId?: string;
    stepId?: string;
};

ServingCacheMissReason

Serving Cache Miss Reason 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { ServingCacheMissReason } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export type ServingCacheMissReason = 'not_found' | 'expired' | 'disabled' | 'streaming' | 'no_cache' | 'mode_off' | 'read_disabled' | 'scope_missing' | 'store_unavailable' | 'entry_oversized' | 'corrupt';

ServingCacheStoreKind

Serving Cache Store Kind 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { ServingCacheStoreKind } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export type ServingCacheStoreKind = 'off' | 'noop' | 'memory' | 'sqlite' | 'redis';

ServingCacheTraceSink

Serving Cache Trace Sink 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { ServingCacheTraceSink } from '@codesoul-co/hypha-serving-cache';
  • 源码模块: types

声明

text
export type ServingCacheTraceSink = (event: ServingCacheEvent) => void | Promise<void>;