Skip to content

@codesoul-co/hypha-inference / prompt-profile

模块用法

用于使用该功能边界的公共契约与操作。Prompt profile 模块公开 1 类、3 常量、9 接口、2 类型。

从包入口导入

ts
import {
  PromptProfileRegistry,
  PROMPT_PROFILE_SOURCES,
  PROMPT_PROFILE_STATUSES,
  promptProfileInputSchema,
} from '@codesoul-co/hypha-inference';

import type {
  PromptProfile,
  PromptProfileArtifactPort,
  PromptProfileInput,
  PromptProfileLayer,
  PromptProfilePrincipal,
  PromptProfileRef,
  PromptProfileRegistryOptions,
  PromptProfileResolution,
} from '@codesoul-co/hypha-inference';

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

使用要点

  • 11 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 1 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。
  • 3 个常量/枚举提供稳定值、Schema、Definition 或默认配置;应复用这些导出,避免在应用中复制内部值。

运行时校验示例

ts
import { promptProfileInputSchema } from '@codesoul-co/hypha-inference';

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

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

公共导出

Symbol种类签名说明
PromptProfileRegistrynew PromptProfileRegistry(options?: PromptProfileRegistryOptions): PromptProfileRegistryImmutable Prompt Profile revisions plus a CAS-protected publication lifecycle. Active revisions are never overwritten, so a Run can safely keep an exact ref.
PROMPT_PROFILE_SOURCES常量const PROMPT_PROFILE_SOURCES: readonly ["system", "developer", "domain", "skill", "mcp", "user"]prompt-profile 模块导出的 PROMPT PROFILE SOURCES 常量。
PROMPT_PROFILE_STATUSES常量const PROMPT_PROFILE_STATUSES: readonly ["draft", "in_review", "active", "deprecated"]prompt-profile 模块导出的 PROMPT PROFILE STATUSES 常量。
promptProfileInputSchema常量const promptProfileInputSchema: z.ZodEffects<z.ZodObject<{ id: z.ZodString; version: z.ZodString; name: z.ZodString; description: z.ZodOptional<z.ZodString>; layers: z.ZodArray<z.ZodObject<{ id: z.ZodString; source: z.ZodEnum<["system", "developer", "domain", "skill", "mcp", "user"]>; content: z.ZodString; priority: z.ZodOptional<z.ZodNumber>; trustLevel: z.ZodOptional<z.ZodEnum<["trusted", "reviewed", "untrusted"...Prompt Profile Input 的运行时 Schema。
PromptProfile接口interface PromptProfile extends PromptProfileInputPrompt Profile 接口,共包含 31 个公开字段或方法。
PromptProfileArtifactPort接口interface PromptProfileArtifactPortPrompt Profile Artifact Port 接口,共包含 1 个公开字段或方法。
PromptProfileInput接口interface PromptProfileInputPrompt Profile Input 接口,共包含 19 个公开字段或方法。
PromptProfileLayer接口interface PromptProfileLayerPrompt Profile Layer 接口,共包含 7 个公开字段或方法。
PromptProfilePrincipal接口interface PromptProfilePrincipalPrompt Profile Principal 接口,共包含 7 个公开字段或方法。
PromptProfileRef接口interface PromptProfileRefPrompt Profile Ref 接口,共包含 3 个公开字段或方法。
PromptProfileRegistryOptions接口interface PromptProfileRegistryOptionsPrompt Profile Registry Options 接口,共包含 3 个公开字段或方法。
PromptProfileResolution接口interface PromptProfileResolutionPrompt Profile Resolution 接口,共包含 6 个公开字段或方法。
PromptProfileTraceSink接口interface PromptProfileTraceSinkPrompt Profile Trace Sink 接口,共包含 1 个公开字段或方法。
PromptProfileSource类型type PromptProfileSource = (typeof PROMPT_PROFILE_SOURCES)[number]Prompt Profile Source 公共类型别名;完整类型表达式见声明。
PromptProfileStatus类型type PromptProfileStatus = (typeof PROMPT_PROFILE_STATUSES)[number]Prompt Profile Status 公共类型别名;完整类型表达式见声明。

PromptProfileRegistry

Immutable Prompt Profile revisions plus a CAS-protected publication lifecycle. Active revisions are never overwritten, so a Run can safely keep an exact ref.

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

声明

text
export declare class PromptProfileRegistry {
    constructor(options?: PromptProfileRegistryOptions);
    create(input: PromptProfileInput): PromptProfile;
    restore(input: PromptProfile): PromptProfile;
    submitForReview(ref: Required<PromptProfileRef>, input: {
            expectedLifecycleRevision: number;
            reviewedBy: string;
        }): PromptProfile;
    activate(ref: Required<PromptProfileRef>, input: {
            expectedLifecycleRevision: number;
            activatedBy: string;
        }): PromptProfile;
    deprecate(ref: Required<PromptProfileRef>, input: {
            expectedLifecycleRevision: number;
            deprecatedBy: string;
        }): PromptProfile;
    get(ref: PromptProfileRef): PromptProfile | null;
    list(id?: string, version?: string): PromptProfile[];
    clear(): void;
    resolve(ref: PromptProfileRef, context: {
            variables: Record<string, unknown>;
            principal: PromptProfilePrincipal;
            maxInlineBytes?: number;
            policyRevision?: string;
            dependencySnapshotHash?: string;
        }): Promise<PromptProfileResolution>;
}

公开成员

成员种类签名说明
activate方法activate(ref: Required<PromptProfileRef>, input: { expectedLifecycleRevision: number; activatedBy: string; }): PromptProfile公开方法;参数与返回类型以签名列为准。
clear方法clear(): void公开方法;参数与返回类型以签名列为准。
constructor构造函数(options?: PromptProfileRegistryOptions): PromptProfileRegistry创建该类的实例。
create方法create(input: PromptProfileInput): PromptProfile公开方法;参数与返回类型以签名列为准。
deprecate方法deprecate(ref: Required<PromptProfileRef>, input: { expectedLifecycleRevision: number; deprecatedBy: string; }): PromptProfile公开方法;参数与返回类型以签名列为准。
get方法get(ref: PromptProfileRef): PromptProfile | null公开方法;参数与返回类型以签名列为准。
list方法list(id?: string, version?: string): PromptProfile[]公开方法;参数与返回类型以签名列为准。
resolve方法resolve(ref: PromptProfileRef, context: { variables: Record<string, unknown>; principal: PromptProfilePrincipal; maxInlineBytes?: number; policyRevision?: string; dependencySnapshotHash?: string; }): Promise<PromptProfileResolution>公开方法;参数与返回类型以签名列为准。
restore方法restore(input: PromptProfile): PromptProfile公开方法;参数与返回类型以签名列为准。
submitForReview方法submitForReview(ref: Required<PromptProfileRef>, input: { expectedLifecycleRevision: number; reviewedBy: string; }): PromptProfile公开方法;参数与返回类型以签名列为准。

PROMPT_PROFILE_SOURCES

prompt-profile 模块导出的 PROMPT PROFILE SOURCES 常量。

  • 种类: 常量
  • 导入: import { PROMPT_PROFILE_SOURCES } from '@codesoul-co/hypha-inference';
  • 源码模块: prompt-profile

声明

text
export declare const PROMPT_PROFILE_SOURCES: readonly ["system", "developer", "domain", "skill", "mcp", "user"];

PROMPT_PROFILE_STATUSES

prompt-profile 模块导出的 PROMPT PROFILE STATUSES 常量。

  • 种类: 常量
  • 导入: import { PROMPT_PROFILE_STATUSES } from '@codesoul-co/hypha-inference';
  • 源码模块: prompt-profile

声明

text
export declare const PROMPT_PROFILE_STATUSES: readonly ["draft", "in_review", "active", "deprecated"];

promptProfileInputSchema

Prompt Profile Input 的运行时 Schema。

  • 种类: 常量
  • 导入: import { promptProfileInputSchema } from '@codesoul-co/hypha-inference';
  • 源码模块: prompt-profile

声明

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

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

PromptProfile

Prompt Profile 接口,共包含 31 个公开字段或方法。

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

声明

text
export interface PromptProfile extends PromptProfileInput {
    revision: number;
    lifecycleRevision: number;
    status: PromptProfileStatus;
    contentHash: string;
    createdAt: string;
    updatedAt: string;
    reviewedBy?: string;
    reviewedAt?: string;
    activatedBy?: string;
    activatedAt?: string;
    deprecatedBy?: string;
    deprecatedAt?: string;
}

契约成员

成员种类签名说明
activatedAt属性activatedAt?: string公开属性;类型、只读和可选状态以签名列为准。
activatedBy属性activatedBy?: string公开属性;类型、只读和可选状态以签名列为准。
agentIds属性agentIds?: string[]公开属性;类型、只读和可选状态以签名列为准。
approvalExpiresAt属性approvalExpiresAt?: string公开属性;类型、只读和可选状态以签名列为准。
contentHash属性contentHash: string公开属性;类型、只读和可选状态以签名列为准。
createdAt属性createdAt: string公开属性;类型、只读和可选状态以签名列为准。
dependencySnapshotHash属性dependencySnapshotHash?: string公开属性;类型、只读和可选状态以签名列为准。
deprecatedAt属性deprecatedAt?: string公开属性;类型、只读和可选状态以签名列为准。
deprecatedBy属性deprecatedBy?: string公开属性;类型、只读和可选状态以签名列为准。
description属性description?: string公开属性;类型、只读和可选状态以签名列为准。
domainIds属性domainIds?: string[]公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
layers属性layers: PromptProfileLayer[]公开属性;类型、只读和可选状态以签名列为准。
lifecycleRevision属性lifecycleRevision: number公开属性;类型、只读和可选状态以签名列为准。
maxInlineBytes属性maxInlineBytes?: number公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
name属性name: string公开属性;类型、只读和可选状态以签名列为准。
ownerId属性ownerId?: string公开属性;类型、只读和可选状态以签名列为准。
policyRevision属性policyRevision?: string公开属性;类型、只读和可选状态以签名列为准。
reviewedAt属性reviewedAt?: string公开属性;类型、只读和可选状态以签名列为准。
reviewedBy属性reviewedBy?: string公开属性;类型、只读和可选状态以签名列为准。
revision属性revision: number公开属性;类型、只读和可选状态以签名列为准。
runId属性runId?: string公开属性;类型、只读和可选状态以签名列为准。
scope属性scope?: "domain" | "session" | "run" | "agent" | "user" | "tenant" | "owner" | "global"公开属性;类型、只读和可选状态以签名列为准。
sessionId属性sessionId?: string公开属性;类型、只读和可选状态以签名列为准。
status属性status: "draft" | "active" | "in_review" | "deprecated"公开属性;类型、只读和可选状态以签名列为准。
tenantId属性tenantId?: string公开属性;类型、只读和可选状态以签名列为准。
updatedAt属性updatedAt: string公开属性;类型、只读和可选状态以签名列为准。
userId属性userId?: string公开属性;类型、只读和可选状态以签名列为准。
variableNames属性variableNames?: string[]公开属性;类型、只读和可选状态以签名列为准。
version属性version: string公开属性;类型、只读和可选状态以签名列为准。

PromptProfileArtifactPort

Prompt Profile Artifact Port 接口,共包含 1 个公开字段或方法。

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

声明

text
export interface PromptProfileArtifactPort {
    store(input: {
        profile: Pick<PromptProfile, 'id' | 'version' | 'revision' | 'contentHash'>;
        bytes: Uint8Array;
        contentHash: string;
        mediaType: 'application/json';
        metadata: Record<string, unknown>;
    }): Promise<{
        artifactRef: string;
        contentHash: string;
        sizeBytes: number;
    }>;
}

契约成员

成员种类签名说明
store方法store(input: { profile: Pick<PromptProfile, "id" | "version" | "revision" | "contentHash">; bytes: Uint8Array; contentHash: string; mediaType: "application/json"; metadata: Record<string, unknown>; }): Promise<{ artifactRef: string; contentHash: string; sizeBytes: number; }>公开方法;参数与返回类型以签名列为准。

PromptProfileInput

Prompt Profile Input 接口,共包含 19 个公开字段或方法。

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

声明

text
export interface PromptProfileInput {
    id: string;
    version: string;
    name: string;
    description?: string;
    layers: PromptProfileLayer[];
    variableNames?: string[];
    scope?: 'global' | 'tenant' | 'owner' | 'user' | 'agent' | 'domain' | 'session' | 'run';
    tenantId?: string;
    ownerId?: string;
    userId?: string;
    sessionId?: string;
    runId?: string;
    agentIds?: string[];
    domainIds?: string[];
    policyRevision?: string;
    dependencySnapshotHash?: string;
    approvalExpiresAt?: string;
    maxInlineBytes?: number;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
agentIds属性agentIds?: string[]公开属性;类型、只读和可选状态以签名列为准。
approvalExpiresAt属性approvalExpiresAt?: string公开属性;类型、只读和可选状态以签名列为准。
dependencySnapshotHash属性dependencySnapshotHash?: string公开属性;类型、只读和可选状态以签名列为准。
description属性description?: string公开属性;类型、只读和可选状态以签名列为准。
domainIds属性domainIds?: string[]公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
layers属性layers: PromptProfileLayer[]公开属性;类型、只读和可选状态以签名列为准。
maxInlineBytes属性maxInlineBytes?: number公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
name属性name: string公开属性;类型、只读和可选状态以签名列为准。
ownerId属性ownerId?: string公开属性;类型、只读和可选状态以签名列为准。
policyRevision属性policyRevision?: string公开属性;类型、只读和可选状态以签名列为准。
runId属性runId?: string公开属性;类型、只读和可选状态以签名列为准。
scope属性scope?: "domain" | "session" | "run" | "agent" | "user" | "tenant" | "owner" | "global"公开属性;类型、只读和可选状态以签名列为准。
sessionId属性sessionId?: string公开属性;类型、只读和可选状态以签名列为准。
tenantId属性tenantId?: string公开属性;类型、只读和可选状态以签名列为准。
userId属性userId?: string公开属性;类型、只读和可选状态以签名列为准。
variableNames属性variableNames?: string[]公开属性;类型、只读和可选状态以签名列为准。
version属性version: string公开属性;类型、只读和可选状态以签名列为准。

PromptProfileLayer

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

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

声明

text
export interface PromptProfileLayer {
    id: string;
    source: PromptProfileSource;
    content: string;
    priority?: number;
    trustLevel?: 'trusted' | 'reviewed' | 'untrusted';
    provenance?: Record<string, unknown>;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
content属性content: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
priority属性priority?: number公开属性;类型、只读和可选状态以签名列为准。
provenance属性provenance?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
source属性source: "skill" | "domain" | "mcp" | "system" | "user" | "developer"公开属性;类型、只读和可选状态以签名列为准。
trustLevel属性trustLevel?: "trusted" | "reviewed" | "untrusted"公开属性;类型、只读和可选状态以签名列为准。

PromptProfilePrincipal

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

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

声明

text
export interface PromptProfilePrincipal {
    principalId: string;
    tenantId?: string;
    userId?: string;
    agentId?: string;
    domainId?: string;
    sessionId?: string;
    runId?: string;
}

契约成员

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

PromptProfileRef

Prompt Profile Ref 接口,共包含 3 个公开字段或方法。

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

声明

text
export interface PromptProfileRef {
    id: string;
    version?: string;
    revision?: number;
}

契约成员

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

PromptProfileRegistryOptions

Prompt Profile Registry Options 接口,共包含 3 个公开字段或方法。

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

声明

text
export interface PromptProfileRegistryOptions {
    now?: () => string;
    artifacts?: PromptProfileArtifactPort;
    trace?: PromptProfileTraceSink;
}

契约成员

成员种类签名说明
artifacts属性artifacts?: PromptProfileArtifactPort公开属性;类型、只读和可选状态以签名列为准。
now方法now?(): string公开方法;参数与返回类型以签名列为准。
trace属性trace?: PromptProfileTraceSink公开属性;类型、只读和可选状态以签名列为准。

PromptProfileResolution

Prompt Profile Resolution 接口,共包含 6 个公开字段或方法。

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

声明

text
export interface PromptProfileResolution {
    profileRef: Required<PromptProfileRef>;
    profileHash: string;
    messages: PromptMessage[];
    sizeBytes: number;
    cacheHit: boolean;
    artifactRef?: string;
}

契约成员

成员种类签名说明
artifactRef属性artifactRef?: string公开属性;类型、只读和可选状态以签名列为准。
cacheHit属性cacheHit: boolean公开属性;类型、只读和可选状态以签名列为准。
messages属性messages: PromptMessage[]公开属性;类型、只读和可选状态以签名列为准。
profileHash属性profileHash: string公开属性;类型、只读和可选状态以签名列为准。
profileRef属性profileRef: Required<PromptProfileRef>公开属性;类型、只读和可选状态以签名列为准。
sizeBytes属性sizeBytes: number公开属性;类型、只读和可选状态以签名列为准。

PromptProfileTraceSink

Prompt Profile Trace Sink 接口,共包含 1 个公开字段或方法。

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

声明

text
export interface PromptProfileTraceSink {
    record(event: {
        type: 'prompt.profile.resolved' | 'prompt.profile.cache_hit' | 'prompt.profile.externalized';
        profileId: string;
        version: string;
        revision: number;
        contentHash: string;
        principalScopeHash: string;
        sizeBytes: number;
        timestamp: string;
    }): Promise<void> | void;
}

契约成员

成员种类签名说明
record方法record(event: { type: "prompt.profile.resolved" | "prompt.profile.cache_hit" | "prompt.profile.externalized"; profileId: string; version: string; revision: number; contentHash: string; principalScopeHash: string; sizeBytes: number; timestamp: string; }): Promise<void> | void公开方法;参数与返回类型以签名列为准。

PromptProfileSource

Prompt Profile Source 公共类型别名;完整类型表达式见声明。

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

声明

text
export type PromptProfileSource = (typeof PROMPT_PROFILE_SOURCES)[number];

PromptProfileStatus

Prompt Profile Status 公共类型别名;完整类型表达式见声明。

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

声明

text
export type PromptProfileStatus = (typeof PROMPT_PROFILE_STATUSES)[number];