Skip to content

@codesoul-co/hypha-core / contracts/runtime-capacity

模块用法

用于声明并运行时校验契约。Runtime capacity 模块公开 1 常量、12 接口、1 类型。

从包入口导入

ts
import {
  RUNTIME_CAPACITY_KINDS,
} from '@codesoul-co/hypha-core';

import type {
  RuntimeCapacityAcquireRequest,
  RuntimeCapacityAssertionRequest,
  RuntimeCapacityLease,
  RuntimeCapacityLeaseGuard,
  RuntimeCapacityLimit,
  RuntimeCapacityPolicy,
  RuntimeCapacityReleaseRequest,
  RuntimeCapacityRenewRequest,
} from '@codesoul-co/hypha-core';

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

使用要点

  • 13 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 1 个常量/枚举提供稳定值、Schema、Definition 或默认配置;应复用这些导出,避免在应用中复制内部值。

公共导出

Symbol种类签名说明
RUNTIME_CAPACITY_KINDS常量const RUNTIME_CAPACITY_KINDS: readonly ["model", "tool", "execution"]contracts/runtime-capacity 模块导出的 RUNTIME CAPACITY KINDS 常量。
RuntimeCapacityAcquireRequest接口interface RuntimeCapacityAcquireRequest extends RuntimeCapacityScopeRuntime Capacity Acquire Request 接口,共包含 10 个公开字段或方法。
RuntimeCapacityAssertionRequest接口interface RuntimeCapacityAssertionRequestRuntime Capacity Assertion Request 接口,共包含 4 个公开字段或方法。
RuntimeCapacityLease接口interface RuntimeCapacityLease extends RuntimeCapacityScopeRuntime Capacity Lease 接口,共包含 12 个公开字段或方法。
RuntimeCapacityLeaseGuard接口interface RuntimeCapacityLeaseGuardRuntime Capacity Lease Guard 接口,共包含 3 个公开字段或方法。
RuntimeCapacityLimit接口interface RuntimeCapacityLimitRuntime Capacity Limit 接口,共包含 2 个公开字段或方法。
RuntimeCapacityPolicy接口interface RuntimeCapacityPolicyRuntime Capacity Policy 接口,共包含 3 个公开字段或方法。
RuntimeCapacityReleaseRequest接口interface RuntimeCapacityReleaseRequestRuntime Capacity Release Request 接口,共包含 4 个公开字段或方法。
RuntimeCapacityRenewRequest接口interface RuntimeCapacityRenewRequestRuntime Capacity Renew Request 接口,共包含 5 个公开字段或方法。
RuntimeCapacityScope接口interface RuntimeCapacityScopeRuntime Capacity Scope 接口,共包含 3 个公开字段或方法。
RuntimeCapacitySemaphore接口interface RuntimeCapacitySemaphoreRuntime Capacity Semaphore 接口,共包含 5 个公开字段或方法。
RuntimeCapacityUsage接口interface RuntimeCapacityUsageRuntime Capacity Usage 接口,共包含 7 个公开字段或方法。
RuntimeCapacityUsageRequest接口interface RuntimeCapacityUsageRequestRuntime Capacity Usage Request 接口,共包含 4 个公开字段或方法。
RuntimeCapacityKind类型type RuntimeCapacityKind = (typeof RUNTIME_CAPACITY_KINDS)[number]Runtime Capacity Kind 公共类型别名;完整类型表达式见声明。

RUNTIME_CAPACITY_KINDS

contracts/runtime-capacity 模块导出的 RUNTIME CAPACITY KINDS 常量。

声明

text
export declare const RUNTIME_CAPACITY_KINDS: readonly ["model", "tool", "execution"];

RuntimeCapacityAcquireRequest

Runtime Capacity Acquire Request 接口,共包含 10 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RuntimeCapacityAcquireRequest } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-capacity

声明

text
export interface RuntimeCapacityAcquireRequest extends RuntimeCapacityScope {
    kind: RuntimeCapacityKind;
    operationId: string;
    requestedLeaseId: string;
    ownerId: string;
    acquiredAt: string;
    ttlMs: number;
    idempotencyKey: string;
}

契约成员

成员种类签名说明
acquiredAt属性acquiredAt: string公开属性;类型、只读和可选状态以签名列为准。
idempotencyKey属性idempotencyKey: string公开属性;类型、只读和可选状态以签名列为准。
kind属性kind: "tool" | "model" | "execution"公开属性;类型、只读和可选状态以签名列为准。
operationId属性operationId: string公开属性;类型、只读和可选状态以签名列为准。
ownerId属性ownerId: string公开属性;类型、只读和可选状态以签名列为准。
requestedLeaseId属性requestedLeaseId: string公开属性;类型、只读和可选状态以签名列为准。
runId属性runId: string公开属性;类型、只读和可选状态以签名列为准。
tenantId属性tenantId?: string公开属性;类型、只读和可选状态以签名列为准。
ttlMs属性ttlMs: number公开属性;类型、只读和可选状态以签名列为准。
userId属性userId: string公开属性;类型、只读和可选状态以签名列为准。

RuntimeCapacityAssertionRequest

Runtime Capacity Assertion Request 接口,共包含 4 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RuntimeCapacityAssertionRequest } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-capacity

声明

text
export interface RuntimeCapacityAssertionRequest {
    scope: RuntimeCapacityScope;
    kind: RuntimeCapacityKind;
    guard: RuntimeCapacityLeaseGuard;
    checkedAt: string;
}

契约成员

成员种类签名说明
checkedAt属性checkedAt: string公开属性;类型、只读和可选状态以签名列为准。
guard属性guard: RuntimeCapacityLeaseGuard公开属性;类型、只读和可选状态以签名列为准。
kind属性kind: "tool" | "model" | "execution"公开属性;类型、只读和可选状态以签名列为准。
scope属性scope: RuntimeCapacityScope公开属性;类型、只读和可选状态以签名列为准。

RuntimeCapacityLease

Runtime Capacity Lease 接口,共包含 12 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RuntimeCapacityLease } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-capacity

声明

text
export interface RuntimeCapacityLease extends RuntimeCapacityScope {
    id: string;
    kind: RuntimeCapacityKind;
    operationId: string;
    ownerId: string;
    fencingToken: number;
    policyRevision: string;
    acquiredAt: string;
    heartbeatAt: string;
    expiresAt: string;
}

契约成员

成员种类签名说明
acquiredAt属性acquiredAt: string公开属性;类型、只读和可选状态以签名列为准。
expiresAt属性expiresAt: string公开属性;类型、只读和可选状态以签名列为准。
fencingToken属性fencingToken: number公开属性;类型、只读和可选状态以签名列为准。
heartbeatAt属性heartbeatAt: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
kind属性kind: "tool" | "model" | "execution"公开属性;类型、只读和可选状态以签名列为准。
operationId属性operationId: string公开属性;类型、只读和可选状态以签名列为准。
ownerId属性ownerId: string公开属性;类型、只读和可选状态以签名列为准。
policyRevision属性policyRevision: string公开属性;类型、只读和可选状态以签名列为准。
runId属性runId: string公开属性;类型、只读和可选状态以签名列为准。
tenantId属性tenantId?: string公开属性;类型、只读和可选状态以签名列为准。
userId属性userId: string公开属性;类型、只读和可选状态以签名列为准。

RuntimeCapacityLeaseGuard

Runtime Capacity Lease Guard 接口,共包含 3 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RuntimeCapacityLeaseGuard } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-capacity

声明

text
export interface RuntimeCapacityLeaseGuard {
    leaseId: string;
    ownerId: string;
    fencingToken: number;
}

契约成员

成员种类签名说明
fencingToken属性fencingToken: number公开属性;类型、只读和可选状态以签名列为准。
leaseId属性leaseId: string公开属性;类型、只读和可选状态以签名列为准。
ownerId属性ownerId: string公开属性;类型、只读和可选状态以签名列为准。

RuntimeCapacityLimit

Runtime Capacity Limit 接口,共包含 2 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RuntimeCapacityLimit } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-capacity

声明

text
export interface RuntimeCapacityLimit {
    global: number;
    perUser: number;
}

契约成员

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

RuntimeCapacityPolicy

Runtime Capacity Policy 接口,共包含 3 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RuntimeCapacityPolicy } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-capacity

声明

text
export interface RuntimeCapacityPolicy {
    version: '1.0.0';
    revision: string;
    limits: Record<RuntimeCapacityKind, RuntimeCapacityLimit>;
}

契约成员

成员种类签名说明
limits属性limits: Record<"tool" | "model" | "execution", RuntimeCapacityLimit>公开属性;类型、只读和可选状态以签名列为准。
revision属性revision: string公开属性;类型、只读和可选状态以签名列为准。
version属性version: "1.0.0"公开属性;类型、只读和可选状态以签名列为准。

RuntimeCapacityReleaseRequest

Runtime Capacity Release Request 接口,共包含 4 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RuntimeCapacityReleaseRequest } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-capacity

声明

text
export interface RuntimeCapacityReleaseRequest {
    scope: RuntimeCapacityScope;
    kind: RuntimeCapacityKind;
    guard: RuntimeCapacityLeaseGuard;
    releasedAt: string;
}

契约成员

成员种类签名说明
guard属性guard: RuntimeCapacityLeaseGuard公开属性;类型、只读和可选状态以签名列为准。
kind属性kind: "tool" | "model" | "execution"公开属性;类型、只读和可选状态以签名列为准。
releasedAt属性releasedAt: string公开属性;类型、只读和可选状态以签名列为准。
scope属性scope: RuntimeCapacityScope公开属性;类型、只读和可选状态以签名列为准。

RuntimeCapacityRenewRequest

Runtime Capacity Renew Request 接口,共包含 5 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RuntimeCapacityRenewRequest } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-capacity

声明

text
export interface RuntimeCapacityRenewRequest {
    scope: RuntimeCapacityScope;
    kind: RuntimeCapacityKind;
    guard: RuntimeCapacityLeaseGuard;
    renewedAt: string;
    ttlMs: number;
}

契约成员

成员种类签名说明
guard属性guard: RuntimeCapacityLeaseGuard公开属性;类型、只读和可选状态以签名列为准。
kind属性kind: "tool" | "model" | "execution"公开属性;类型、只读和可选状态以签名列为准。
renewedAt属性renewedAt: string公开属性;类型、只读和可选状态以签名列为准。
scope属性scope: RuntimeCapacityScope公开属性;类型、只读和可选状态以签名列为准。
ttlMs属性ttlMs: number公开属性;类型、只读和可选状态以签名列为准。

RuntimeCapacityScope

Runtime Capacity Scope 接口,共包含 3 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RuntimeCapacityScope } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-capacity

声明

text
export interface RuntimeCapacityScope {
    tenantId?: string;
    userId: string;
    runId: string;
}

契约成员

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

RuntimeCapacitySemaphore

Runtime Capacity Semaphore 接口,共包含 5 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RuntimeCapacitySemaphore } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-capacity

声明

text
export interface RuntimeCapacitySemaphore {
    acquire(request: RuntimeCapacityAcquireRequest): Promise<RuntimeCapacityLease | null>;
    renew(request: RuntimeCapacityRenewRequest): Promise<RuntimeCapacityLease>;
    release(request: RuntimeCapacityReleaseRequest): Promise<void>;
    assertCurrent(request: RuntimeCapacityAssertionRequest): Promise<RuntimeCapacityLease>;
    usage(request: RuntimeCapacityUsageRequest): Promise<RuntimeCapacityUsage>;
}

契约成员

成员种类签名说明
acquire方法acquire(request: RuntimeCapacityAcquireRequest): Promise<RuntimeCapacityLease | null>公开方法;参数与返回类型以签名列为准。
assertCurrent方法assertCurrent(request: RuntimeCapacityAssertionRequest): Promise<RuntimeCapacityLease>公开方法;参数与返回类型以签名列为准。
release方法release(request: RuntimeCapacityReleaseRequest): Promise<void>公开方法;参数与返回类型以签名列为准。
renew方法renew(request: RuntimeCapacityRenewRequest): Promise<RuntimeCapacityLease>公开方法;参数与返回类型以签名列为准。
usage方法usage(request: RuntimeCapacityUsageRequest): Promise<RuntimeCapacityUsage>公开方法;参数与返回类型以签名列为准。

RuntimeCapacityUsage

Runtime Capacity Usage 接口,共包含 7 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RuntimeCapacityUsage } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-capacity

声明

text
export interface RuntimeCapacityUsage {
    kind: RuntimeCapacityKind;
    policyRevision: string;
    globalActive: number;
    userActive: number;
    globalLimit: number;
    userLimit: number;
    checkedAt: string;
}

契约成员

成员种类签名说明
checkedAt属性checkedAt: string公开属性;类型、只读和可选状态以签名列为准。
globalActive属性globalActive: number公开属性;类型、只读和可选状态以签名列为准。
globalLimit属性globalLimit: number公开属性;类型、只读和可选状态以签名列为准。
kind属性kind: "tool" | "model" | "execution"公开属性;类型、只读和可选状态以签名列为准。
policyRevision属性policyRevision: string公开属性;类型、只读和可选状态以签名列为准。
userActive属性userActive: number公开属性;类型、只读和可选状态以签名列为准。
userLimit属性userLimit: number公开属性;类型、只读和可选状态以签名列为准。

RuntimeCapacityUsageRequest

Runtime Capacity Usage Request 接口,共包含 4 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RuntimeCapacityUsageRequest } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-capacity

声明

text
export interface RuntimeCapacityUsageRequest {
    tenantId?: string;
    userId: string;
    kind: RuntimeCapacityKind;
    checkedAt: string;
}

契约成员

成员种类签名说明
checkedAt属性checkedAt: string公开属性;类型、只读和可选状态以签名列为准。
kind属性kind: "tool" | "model" | "execution"公开属性;类型、只读和可选状态以签名列为准。
tenantId属性tenantId?: string公开属性;类型、只读和可选状态以签名列为准。
userId属性userId: string公开属性;类型、只读和可选状态以签名列为准。

RuntimeCapacityKind

Runtime Capacity Kind 公共类型别名;完整类型表达式见声明。

声明

text
export type RuntimeCapacityKind = (typeof RUNTIME_CAPACITY_KINDS)[number];