Skip to content

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

模块用法

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

从包入口导入

ts
import {
  RUNTIME_INBOX_STATUSES,
  RUNTIME_MESSAGE_TYPES,
  RUNTIME_OUTBOX_STATES,
} from '@codesoul-co/hypha-core';

import type {
  RuntimeMessageEnvelope,
  RuntimeMessageEnvelopeInput,
  RuntimeMessageInboxRecord,
  RuntimeMessageOutboxRecord,
  RuntimeMessageInboxStatus,
  RuntimeMessageOutboxState,
  RuntimeMessageType,
} from '@codesoul-co/hypha-core';

使用要点

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

公共导出

Symbol种类签名说明
RUNTIME_INBOX_STATUSES常量const RUNTIME_INBOX_STATUSES: readonly ["processing", "applied", "ignored", "failed"]contracts/runtime-messages 模块导出的 RUNTIME INBOX STATUSES 常量。
RUNTIME_MESSAGE_TYPES常量const RUNTIME_MESSAGE_TYPES: readonly ["runtime.command.start", "runtime.command.resume", "runtime.command.cancel", "runtime.signal", "runtime.timer.fire", "runtime.activity.requested", "runtime.activity.completed", "runtime.activity.failed", "runtime.agent.message", "runtime.child.completed", "runtime.projection.rebuild", "runtime.recovery.requested", "runtime.custom"]contracts/runtime-messages 模块导出的 RUNTIME MESSAGE TYPES 常量。
RUNTIME_OUTBOX_STATES常量const RUNTIME_OUTBOX_STATES: readonly ["pending", "publishing", "published", "failed", "dead_letter"]contracts/runtime-messages 模块导出的 RUNTIME OUTBOX STATES 常量。
RuntimeMessageEnvelope接口interface RuntimeMessageEnvelopeRuntime Message Envelope 接口,共包含 28 个公开字段或方法。
RuntimeMessageEnvelopeInput接口interface RuntimeMessageEnvelopeInput extends Omit<RuntimeMessageEnvelope<TPayload>, 'payloadHash' | 'sequence'>Runtime Message Envelope Input 接口,共包含 28 个公开字段或方法。
RuntimeMessageInboxRecord接口interface RuntimeMessageInboxRecordRuntime Message Inbox Record 接口,共包含 12 个公开字段或方法。
RuntimeMessageOutboxRecord接口interface RuntimeMessageOutboxRecordRuntime Message Outbox Record 接口,共包含 14 个公开字段或方法。
RuntimeMessageInboxStatus类型type RuntimeMessageInboxStatus = (typeof RUNTIME_INBOX_STATUSES)[number]Runtime Message Inbox Status 公共类型别名;完整类型表达式见声明。
RuntimeMessageOutboxState类型type RuntimeMessageOutboxState = (typeof RUNTIME_OUTBOX_STATES)[number]Runtime Message Outbox State 公共类型别名;完整类型表达式见声明。
RuntimeMessageType类型type RuntimeMessageType = (typeof RUNTIME_MESSAGE_TYPES)[number]Runtime Message Type 公共类型别名;完整类型表达式见声明。

RUNTIME_INBOX_STATUSES

contracts/runtime-messages 模块导出的 RUNTIME INBOX STATUSES 常量。

声明

text
export declare const RUNTIME_INBOX_STATUSES: readonly ["processing", "applied", "ignored", "failed"];

RUNTIME_MESSAGE_TYPES

contracts/runtime-messages 模块导出的 RUNTIME MESSAGE TYPES 常量。

声明

text
export declare const RUNTIME_MESSAGE_TYPES: readonly ["runtime.command.start", "runtime.command.resume", "runtime.command.cancel", "runtime.signal", "runtime.timer.fire", "runtime.activity.requested", "runtime.activity.completed", "runtime.activity.failed", "runtime.agent.message", "runtime.child.completed", "runtime.projection.rebuild", "runtime.recovery.requested", "runtime.custom"];

RUNTIME_OUTBOX_STATES

contracts/runtime-messages 模块导出的 RUNTIME OUTBOX STATES 常量。

声明

text
export declare const RUNTIME_OUTBOX_STATES: readonly ["pending", "publishing", "published", "failed", "dead_letter"];

RuntimeMessageEnvelope

Runtime Message Envelope 接口,共包含 28 个公开字段或方法。

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

声明

text
export interface RuntimeMessageEnvelope<TPayload = unknown> {
    messageId: string;
    messageType: RuntimeMessageType;
    schemaVersion: string;
    topic: string;
    partitionKey: string;
    orderingKey?: string;
    sequence?: number;
    tenantId?: string;
    workspaceId?: string;
    userId?: string;
    sessionId?: string;
    runId?: string;
    stepId?: string;
    activityId?: string;
    agentId?: string;
    correlationId?: string;
    causationId?: string;
    traceId?: string;
    principal?: RuntimePrincipal;
    payload: TPayload;
    payloadHash: string;
    priority?: number;
    availableAt?: string;
    expiresAt?: string;
    publishedAt: string;
    producerId: string;
    producerRevision?: string;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
activityId属性activityId?: string公开属性;类型、只读和可选状态以签名列为准。
agentId属性agentId?: string公开属性;类型、只读和可选状态以签名列为准。
availableAt属性availableAt?: string公开属性;类型、只读和可选状态以签名列为准。
causationId属性causationId?: string公开属性;类型、只读和可选状态以签名列为准。
correlationId属性correlationId?: string公开属性;类型、只读和可选状态以签名列为准。
expiresAt属性expiresAt?: string公开属性;类型、只读和可选状态以签名列为准。
messageId属性messageId: string公开属性;类型、只读和可选状态以签名列为准。
messageType属性messageType: "runtime.activity.requested" | "runtime.activity.completed" | "runtime.activity.failed" | "runtime.command.start" | "runtime.command.resume" | "runtime.command.cancel" | "runtime.signal" | "runtime.timer.fire" | "runtime.agent.message" | "runtime.child.completed" | "runtime.projection.rebuild" | "runtime.recovery.requested" | "runtime.custom"公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
orderingKey属性orderingKey?: string公开属性;类型、只读和可选状态以签名列为准。
partitionKey属性partitionKey: string公开属性;类型、只读和可选状态以签名列为准。
payload属性payload: TPayload公开属性;类型、只读和可选状态以签名列为准。
payloadHash属性payloadHash: string公开属性;类型、只读和可选状态以签名列为准。
principal属性principal?: RuntimePrincipal公开属性;类型、只读和可选状态以签名列为准。
priority属性priority?: number公开属性;类型、只读和可选状态以签名列为准。
producerId属性producerId: string公开属性;类型、只读和可选状态以签名列为准。
producerRevision属性producerRevision?: string公开属性;类型、只读和可选状态以签名列为准。
publishedAt属性publishedAt: string公开属性;类型、只读和可选状态以签名列为准。
runId属性runId?: string公开属性;类型、只读和可选状态以签名列为准。
schemaVersion属性schemaVersion: string公开属性;类型、只读和可选状态以签名列为准。
sequence属性sequence?: number公开属性;类型、只读和可选状态以签名列为准。
sessionId属性sessionId?: string公开属性;类型、只读和可选状态以签名列为准。
stepId属性stepId?: string公开属性;类型、只读和可选状态以签名列为准。
tenantId属性tenantId?: string公开属性;类型、只读和可选状态以签名列为准。
topic属性topic: string公开属性;类型、只读和可选状态以签名列为准。
traceId属性traceId?: string公开属性;类型、只读和可选状态以签名列为准。
userId属性userId?: string公开属性;类型、只读和可选状态以签名列为准。
workspaceId属性workspaceId?: string公开属性;类型、只读和可选状态以签名列为准。

RuntimeMessageEnvelopeInput

Runtime Message Envelope Input 接口,共包含 28 个公开字段或方法。

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

声明

text
export interface RuntimeMessageEnvelopeInput<TPayload = unknown> extends Omit<RuntimeMessageEnvelope<TPayload>, 'payloadHash' | 'sequence'> {
    payloadHash?: string;
    sequence?: number;
}

契约成员

成员种类签名说明
activityId属性activityId?: string公开属性;类型、只读和可选状态以签名列为准。
agentId属性agentId?: string公开属性;类型、只读和可选状态以签名列为准。
availableAt属性availableAt?: string公开属性;类型、只读和可选状态以签名列为准。
causationId属性causationId?: string公开属性;类型、只读和可选状态以签名列为准。
correlationId属性correlationId?: string公开属性;类型、只读和可选状态以签名列为准。
expiresAt属性expiresAt?: string公开属性;类型、只读和可选状态以签名列为准。
messageId属性messageId: string公开属性;类型、只读和可选状态以签名列为准。
messageType属性messageType: "runtime.activity.requested" | "runtime.activity.completed" | "runtime.activity.failed" | "runtime.command.start" | "runtime.command.resume" | "runtime.command.cancel" | "runtime.signal" | "runtime.timer.fire" | "runtime.agent.message" | "runtime.child.completed" | "runtime.projection.rebuild" | "runtime.recovery.requested" | "runtime.custom"公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
orderingKey属性orderingKey?: string公开属性;类型、只读和可选状态以签名列为准。
partitionKey属性partitionKey: string公开属性;类型、只读和可选状态以签名列为准。
payload属性payload: TPayload公开属性;类型、只读和可选状态以签名列为准。
payloadHash属性payloadHash?: string公开属性;类型、只读和可选状态以签名列为准。
principal属性principal?: RuntimePrincipal公开属性;类型、只读和可选状态以签名列为准。
priority属性priority?: number公开属性;类型、只读和可选状态以签名列为准。
producerId属性producerId: string公开属性;类型、只读和可选状态以签名列为准。
producerRevision属性producerRevision?: string公开属性;类型、只读和可选状态以签名列为准。
publishedAt属性publishedAt: string公开属性;类型、只读和可选状态以签名列为准。
runId属性runId?: string公开属性;类型、只读和可选状态以签名列为准。
schemaVersion属性schemaVersion: string公开属性;类型、只读和可选状态以签名列为准。
sequence属性sequence?: number公开属性;类型、只读和可选状态以签名列为准。
sessionId属性sessionId?: string公开属性;类型、只读和可选状态以签名列为准。
stepId属性stepId?: string公开属性;类型、只读和可选状态以签名列为准。
tenantId属性tenantId?: string公开属性;类型、只读和可选状态以签名列为准。
topic属性topic: string公开属性;类型、只读和可选状态以签名列为准。
traceId属性traceId?: string公开属性;类型、只读和可选状态以签名列为准。
userId属性userId?: string公开属性;类型、只读和可选状态以签名列为准。
workspaceId属性workspaceId?: string公开属性;类型、只读和可选状态以签名列为准。

RuntimeMessageInboxRecord

Runtime Message Inbox Record 接口,共包含 12 个公开字段或方法。

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

声明

text
export interface RuntimeMessageInboxRecord {
    consumerId: string;
    messageId: string;
    payloadHash: string;
    status: RuntimeMessageInboxStatus;
    appliedEventIds?: string[];
    firstReceivedAt: string;
    lastReceivedAt: string;
    attempts: number;
    expiresAt?: string;
    processingOwner?: string;
    processingExpiresAt?: string;
    lastError?: NormalizedRuntimeError;
}

契约成员

成员种类签名说明
appliedEventIds属性appliedEventIds?: string[]公开属性;类型、只读和可选状态以签名列为准。
attempts属性attempts: number公开属性;类型、只读和可选状态以签名列为准。
consumerId属性consumerId: string公开属性;类型、只读和可选状态以签名列为准。
expiresAt属性expiresAt?: string公开属性;类型、只读和可选状态以签名列为准。
firstReceivedAt属性firstReceivedAt: string公开属性;类型、只读和可选状态以签名列为准。
lastError属性lastError?: NormalizedRuntimeError公开属性;类型、只读和可选状态以签名列为准。
lastReceivedAt属性lastReceivedAt: string公开属性;类型、只读和可选状态以签名列为准。
messageId属性messageId: string公开属性;类型、只读和可选状态以签名列为准。
payloadHash属性payloadHash: string公开属性;类型、只读和可选状态以签名列为准。
processingExpiresAt属性processingExpiresAt?: string公开属性;类型、只读和可选状态以签名列为准。
processingOwner属性processingOwner?: string公开属性;类型、只读和可选状态以签名列为准。
status属性status: "failed" | "processing" | "applied" | "ignored"公开属性;类型、只读和可选状态以签名列为准。

RuntimeMessageOutboxRecord

Runtime Message Outbox Record 接口,共包含 14 个公开字段或方法。

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

声明

text
export interface RuntimeMessageOutboxRecord {
    id: string;
    eventId?: string;
    messageId: string;
    topic: string;
    partitionKey: string;
    envelope: RuntimeMessageEnvelope;
    state: RuntimeMessageOutboxState;
    attempts: number;
    availableAt: string;
    leaseOwner?: string;
    leaseExpiresAt?: string;
    lastError?: NormalizedRuntimeError;
    createdAt: string;
    updatedAt: string;
}

契约成员

成员种类签名说明
attempts属性attempts: number公开属性;类型、只读和可选状态以签名列为准。
availableAt属性availableAt: string公开属性;类型、只读和可选状态以签名列为准。
createdAt属性createdAt: string公开属性;类型、只读和可选状态以签名列为准。
envelope属性envelope: RuntimeMessageEnvelope<unknown>公开属性;类型、只读和可选状态以签名列为准。
eventId属性eventId?: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
lastError属性lastError?: NormalizedRuntimeError公开属性;类型、只读和可选状态以签名列为准。
leaseExpiresAt属性leaseExpiresAt?: string公开属性;类型、只读和可选状态以签名列为准。
leaseOwner属性leaseOwner?: string公开属性;类型、只读和可选状态以签名列为准。
messageId属性messageId: string公开属性;类型、只读和可选状态以签名列为准。
partitionKey属性partitionKey: string公开属性;类型、只读和可选状态以签名列为准。
state属性state: "failed" | "pending" | "publishing" | "published" | "dead_letter"公开属性;类型、只读和可选状态以签名列为准。
topic属性topic: string公开属性;类型、只读和可选状态以签名列为准。
updatedAt属性updatedAt: string公开属性;类型、只读和可选状态以签名列为准。

RuntimeMessageInboxStatus

Runtime Message Inbox Status 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { RuntimeMessageInboxStatus } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-messages

声明

text
export type RuntimeMessageInboxStatus = (typeof RUNTIME_INBOX_STATUSES)[number];

RuntimeMessageOutboxState

Runtime Message Outbox State 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { RuntimeMessageOutboxState } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/runtime-messages

声明

text
export type RuntimeMessageOutboxState = (typeof RUNTIME_OUTBOX_STATES)[number];

RuntimeMessageType

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

声明

text
export type RuntimeMessageType = (typeof RUNTIME_MESSAGE_TYPES)[number];