Files
JX-BPOS/api-report/packages/contracts/src/envelope.d.ts
T
JCAI Main AgentandClaude Opus 5 78dc03bb58 app 装配收尾:18 个模块接上,MVP 判据 1-2 端到端跑通
装配(app 是唯一组装层):
- wiring/engines.ts:skill/flow/loop/task/process/trigger 六个模块经端口接起来;
  两个范式引擎按统一 ParadigmEngine 契约暴露给 task —— 对上层不可区分
- agent-runner.ts:loop 的 Agent 回路经 ModelGateway(两缝之一,回放审看得见);
  出参过 schema 框住三型行动,不合规退化为「等人」而不是乱动世界
- container:interaction / human-tool / activity-registry / release 全部接上;
  event 的 TriggerMatcher 与 org 的 InFlightWorkProbe 以延迟绑定解环,端口不变
- workers/consumers.ts:派发器的两个消费者(任务监听推进旧单 / 触发器开新单,独立判定)
- tools/first-party.ts:查历史价(录制回放替身)+ 三分类打标(纯工具,DMN 确定性求值)
- seed-quote.ts:治理台四件事一次做完 —— 绑 LLM / 注册工具两审 / 经安装通道装活动包 /
  发布流程包(闭合校验通过)+ 配触发器与邮件通道

已验证(真机):
1. 治理台配置全过;活动包静态审 0 条提示、流程包闭合校验通过
2. 一封 RFQ 邮件入站 → 归属解析 → 触发器命中 1 → 起一条工作流 →
   A1 任务按岗位唯一人解析落到 BD 冯兵,runtime=running

修复:zod 判别式重复值(周期触发两型展开为 periodic-calendar / periodic-data,
triggerKindOf 对回三类分类学);活动构建脚本移出 activities(它要用 fs,
而活动包零环境能力 —— depcruise 拦下后按边界搬家)

358 个测试通过,门禁五道全绿

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
2026-07-27 02:24:36 +08:00

344 lines
13 KiB
TypeScript

/**
* 统一事件标准(编码规范 §8.1;语义出处 OS 06)。
*
* 系统向活动只以统一信封抛四类事件;一条事件流,三级消费(任务监听 / 触发器 / 消息)。
* 投递五诺(先持久后投递 / 同任务按序 / 至少一次 + 幂等 / 处理有回执 / 扇出与幂等)
* 是 `event` 模块的实现承诺,不在本文件表达 —— 本文件只定信封的形状。
*/
import { z } from 'zod';
export declare const EVENT_TYPES: readonly ["data", "time", "human", "control"];
export declare const eventTypeSchema: z.ZodEnum<{
human: "human";
data: "data";
time: "time";
control: "control";
}>;
export type EventType = z.infer<typeof eventTypeSchema>;
export declare const EVENT_TYPE_LABEL: Readonly<Record<EventType, string>>;
/** 消费目标四类(OS 6.1):任务 / 触发器 / 工作流 / 消息收件岗位 */
export declare const eventTargetSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
kind: z.ZodLiteral<"task">;
id: z.core.$ZodBranded<z.ZodString, "TaskId", "out">;
}, z.core.$strip>, z.ZodObject<{
kind: z.ZodLiteral<"trigger">;
id: z.core.$ZodBranded<z.ZodString, "TriggerId", "out">;
}, z.core.$strip>, z.ZodObject<{
kind: z.ZodLiteral<"workflow">;
id: z.core.$ZodBranded<z.ZodString, "WorkflowId", "out">;
}, z.core.$strip>, z.ZodObject<{
kind: z.ZodLiteral<"message-position">;
id: z.core.$ZodBranded<z.ZodString, "PositionId", "out">;
}, z.core.$strip>], "kind">;
export type EventTarget = z.infer<typeof eventTargetSchema>;
/** 起因:数据对象 / 卡 ID / 定时器 ID —— 「这条事件是被什么激起的」 */
export declare const eventCauseSchema: z.ZodObject<{
kind: z.ZodEnum<{
"ledger-write": "ledger-write";
"card-reply": "card-reply";
timer: "timer";
inbound: "inbound";
governance: "governance";
engine: "engine";
}>;
ref: z.ZodString;
}, z.core.$strip>;
export type EventCause = z.infer<typeof eventCauseSchema>;
export declare const EVENT_SOURCES: readonly ["channel", "engine", "desk", "governance"];
export declare const eventSourceKindSchema: z.ZodEnum<{
governance: "governance";
engine: "engine";
channel: "channel";
desk: "desk";
}>;
export type EventSourceKind = z.infer<typeof eventSourceKindSchema>;
export declare const eventSourceSchema: z.ZodObject<{
kind: z.ZodEnum<{
governance: "governance";
engine: "engine";
channel: "channel";
desk: "desk";
}>;
channelId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "ChannelId", "out">>;
detail: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
export type EventSource = z.infer<typeof eventSourceSchema>;
/** 载荷:schema 化内容 + 原件指针(如邮件原文的存档地址) */
export declare const eventPayloadSchema: z.ZodObject<{
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
originRef: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
export type EventPayload = z.infer<typeof eventPayloadSchema>;
export declare const envelopeSchema: z.ZodObject<{
id: z.core.$ZodBranded<z.ZodString, "EventId", "out">;
type: z.ZodEnum<{
human: "human";
data: "data";
time: "time";
control: "control";
}>;
correlation: z.ZodObject<{
target: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
kind: z.ZodLiteral<"task">;
id: z.core.$ZodBranded<z.ZodString, "TaskId", "out">;
}, z.core.$strip>, z.ZodObject<{
kind: z.ZodLiteral<"trigger">;
id: z.core.$ZodBranded<z.ZodString, "TriggerId", "out">;
}, z.core.$strip>, z.ZodObject<{
kind: z.ZodLiteral<"workflow">;
id: z.core.$ZodBranded<z.ZodString, "WorkflowId", "out">;
}, z.core.$strip>, z.ZodObject<{
kind: z.ZodLiteral<"message-position">;
id: z.core.$ZodBranded<z.ZodString, "PositionId", "out">;
}, z.core.$strip>], "kind">>;
cause: z.ZodObject<{
kind: z.ZodEnum<{
"ledger-write": "ledger-write";
"card-reply": "card-reply";
timer: "timer";
inbound: "inbound";
governance: "governance";
engine: "engine";
}>;
ref: z.ZodString;
}, z.core.$strip>;
keys: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
}, z.core.$strip>;
payload: z.ZodObject<{
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
originRef: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
occurredAt: z.ZodISODateTime;
source: z.ZodObject<{
kind: z.ZodEnum<{
governance: "governance";
engine: "engine";
channel: "channel";
desk: "desk";
}>;
channelId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "ChannelId", "out">>;
detail: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
trace: z.ZodObject<{
storeRef: z.ZodString;
taskMemoryRef: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
}, z.core.$strip>;
export type Envelope = z.infer<typeof envelopeSchema>;
/**
* 尚未落存储的信封草稿 —— `publish` 的入参。
*
* `target` 在此**可空**:原始事件未必知道自己该被谁消费。归属解析(6.2)与三级消费判定
* (任务监听 / 触发器 / 消息兜底,6.3)由 `event` 模块完成,并为每个命中目标生成一份
* 独立投递 —— 投递出去的信封「关联 = 单目标」,这正是扇出与幂等承诺的形态。
* `storeRef` 由 event adapter 落库时补。
*/
export declare const envelopeDraftSchema: z.ZodObject<{
type: z.ZodEnum<{
human: "human";
data: "data";
time: "time";
control: "control";
}>;
payload: z.ZodObject<{
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
originRef: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
source: z.ZodObject<{
kind: z.ZodEnum<{
governance: "governance";
engine: "engine";
channel: "channel";
desk: "desk";
}>;
channelId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "ChannelId", "out">>;
detail: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
correlation: z.ZodObject<{
target: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
kind: z.ZodLiteral<"task">;
id: z.core.$ZodBranded<z.ZodString, "TaskId", "out">;
}, z.core.$strip>, z.ZodObject<{
kind: z.ZodLiteral<"trigger">;
id: z.core.$ZodBranded<z.ZodString, "TriggerId", "out">;
}, z.core.$strip>, z.ZodObject<{
kind: z.ZodLiteral<"workflow">;
id: z.core.$ZodBranded<z.ZodString, "WorkflowId", "out">;
}, z.core.$strip>, z.ZodObject<{
kind: z.ZodLiteral<"message-position">;
id: z.core.$ZodBranded<z.ZodString, "PositionId", "out">;
}, z.core.$strip>], "kind">>;
cause: z.ZodObject<{
kind: z.ZodEnum<{
"ledger-write": "ledger-write";
"card-reply": "card-reply";
timer: "timer";
inbound: "inbound";
governance: "governance";
engine: "engine";
}>;
ref: z.ZodString;
}, z.core.$strip>;
keys: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
}, z.core.$strip>;
occurredAt: z.ZodISODateTime;
id: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "EventId", "out">>;
}, z.core.$strip>;
export type EnvelopeDraft = z.infer<typeof envelopeDraftSchema>;
/** 控制事件载荷:三语义 + 发起人 */
export declare const controlPayloadSchema: z.ZodObject<{
semantic: z.ZodEnum<{
pause: "pause";
halt: "halt";
terminate: "terminate";
}>;
reason: z.ZodOptional<z.ZodString>;
issuedBy: z.ZodString;
}, z.core.$strip>;
export type ControlPayload = z.infer<typeof controlPayloadSchema>;
/** 时间事件载荷:哪个监听 / 定时器到点 */
export declare const timePayloadSchema: z.ZodObject<{
listenerId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "ListenerId", "out">>;
timerRef: z.ZodString;
escalation: z.ZodOptional<z.ZodEnum<{
nudge: "nudge";
reroute: "reroute";
escalate: "escalate";
}>>;
}, z.core.$strip>;
export type TimePayload = z.infer<typeof timePayloadSchema>;
/** 数据事件载荷:域.对象.主键 的正式版写入 —— 草稿写不抛事件(OS 09) */
export declare const dataPayloadSchema: z.ZodObject<{
domain: z.ZodString;
object: z.ZodString;
primaryKey: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
changed: z.ZodDefault<z.ZodArray<z.ZodString>>;
operation: z.ZodEnum<{
insert: "insert";
update: "update";
delete: "delete";
}>;
}, z.core.$strip>;
export type DataPayload = z.infer<typeof dataPayloadSchema>;
/**
* 处理语义:loop 事件即观察 / flow 事件即步的完成条件。
* 这是**引擎层**的区分,交互层不可见(编码规范 §9 双层边界)。
*/
export declare const LISTENER_SEMANTICS: readonly ["observe", "complete-step"];
export declare const listenerSemanticSchema: z.ZodEnum<{
observe: "observe";
"complete-step": "complete-step";
}>;
export type ListenerSemantic = z.infer<typeof listenerSemanticSchema>;
export declare const listenerSpecSchema: z.ZodObject<{
origin: z.ZodEnum<{
static: "static";
dynamic: "dynamic";
}>;
eventType: z.ZodEnum<{
human: "human";
data: "data";
time: "time";
control: "control";
}>;
keyFilter: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
condition: z.ZodOptional<z.ZodString>;
semantic: z.ZodEnum<{
observe: "observe";
"complete-step": "complete-step";
}>;
deadline: z.ZodString;
escalation: z.ZodDefault<z.ZodArray<z.ZodEnum<{
nudge: "nudge";
reroute: "reroute";
escalate: "escalate";
}>>>;
}, z.core.$strip>;
export type ListenerSpec = z.infer<typeof listenerSpecSchema>;
export declare const registeredListenerSchema: z.ZodObject<{
origin: z.ZodEnum<{
static: "static";
dynamic: "dynamic";
}>;
eventType: z.ZodEnum<{
human: "human";
data: "data";
time: "time";
control: "control";
}>;
keyFilter: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
condition: z.ZodOptional<z.ZodString>;
semantic: z.ZodEnum<{
observe: "observe";
"complete-step": "complete-step";
}>;
deadline: z.ZodString;
escalation: z.ZodDefault<z.ZodArray<z.ZodEnum<{
nudge: "nudge";
reroute: "reroute";
escalate: "escalate";
}>>>;
id: z.core.$ZodBranded<z.ZodString, "ListenerId", "out">;
taskId: z.core.$ZodBranded<z.ZodString, "TaskId", "out">;
registeredAt: z.ZodISODateTime;
expiresAt: z.ZodISODateTime;
state: z.ZodEnum<{
armed: "armed";
fired: "fired";
expired: "expired";
cancelled: "cancelled";
}>;
}, z.core.$strip>;
export type RegisteredListener = z.infer<typeof registeredListenerSchema>;
export declare const deliverySchema: z.ZodObject<{
id: z.core.$ZodBranded<z.ZodString, "DeliveryId", "out">;
eventId: z.core.$ZodBranded<z.ZodString, "EventId", "out">;
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
kind: z.ZodLiteral<"task">;
id: z.core.$ZodBranded<z.ZodString, "TaskId", "out">;
}, z.core.$strip>, z.ZodObject<{
kind: z.ZodLiteral<"trigger">;
id: z.core.$ZodBranded<z.ZodString, "TriggerId", "out">;
}, z.core.$strip>, z.ZodObject<{
kind: z.ZodLiteral<"workflow">;
id: z.core.$ZodBranded<z.ZodString, "WorkflowId", "out">;
}, z.core.$strip>, z.ZodObject<{
kind: z.ZodLiteral<"message-position">;
id: z.core.$ZodBranded<z.ZodString, "PositionId", "out">;
}, z.core.$strip>], "kind">;
attempt: z.ZodNumber;
state: z.ZodEnum<{
pending: "pending";
delivered: "delivered";
failed: "failed";
"dead-letter": "dead-letter";
}>;
lastError: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
export type Delivery = z.infer<typeof deliverySchema>;
/** 匹配次序确定、逐级短路:① 线程精确 ② 关联键命中监听 ③ 地址 + 时间窗 */
export declare const OWNERSHIP_RULES: readonly ["thread", "listener-key", "address-window"];
export declare const ownershipRuleSchema: z.ZodEnum<{
thread: "thread";
"listener-key": "listener-key";
"address-window": "address-window";
}>;
export type OwnershipRule = z.infer<typeof ownershipRuleSchema>;
export declare const ownershipResolutionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
outcome: z.ZodLiteral<"owned">;
rule: z.ZodEnum<{
thread: "thread";
"listener-key": "listener-key";
"address-window": "address-window";
}>;
taskId: z.core.$ZodBranded<z.ZodString, "TaskId", "out">;
}, z.core.$strip>, z.ZodObject<{
outcome: z.ZodLiteral<"unowned">;
reason: z.ZodEnum<{
"no-match": "no-match";
ambiguous: "ambiguous";
"extract-failed": "extract-failed";
}>;
fallbackPosition: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "PositionId", "out">>;
}, z.core.$strip>], "outcome">;
export type OwnershipResolution = z.infer<typeof ownershipResolutionSchema>;