@vessel-agent/agent 0.0.0-stage → 2.3.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +30 -4
- package/src/address-display.ts +141 -0
- package/src/conversation-budget.ts +651 -0
- package/src/conversation-store.ts +351 -0
- package/src/distress.ts +161 -0
- package/src/env-info-scope.ts +153 -0
- package/src/error-text.ts +28 -0
- package/src/inbox-source.ts +73 -0
- package/src/inbox.ts +2335 -0
- package/src/index.ts +273 -0
- package/src/member-cwd.ts +128 -0
- package/src/member-ports.ts +162 -0
- package/src/refs.ts +51 -0
- package/src/registry.ts +741 -0
- package/src/runtime.ts +2501 -0
- package/src/self-card-delta.ts +428 -0
- package/src/service.ts +9212 -0
- package/src/snapshot.ts +614 -0
- package/src/team-address.ts +96 -0
- package/src/team-log.ts +487 -0
- package/src/team-service.ts +1966 -0
- package/src/team-slug.ts +167 -0
- package/src/team-store.ts +619 -0
- package/src/tool.ts +1306 -0
- package/src/types/budget.ts +168 -0
- package/src/types/constants.ts +17 -0
- package/src/types/dispatch.ts +133 -0
- package/src/types/events.ts +132 -0
- package/src/types/execution.ts +289 -0
- package/src/types/lifecycle.ts +372 -0
- package/src/types/member.ts +221 -0
- package/src/types/message.ts +113 -0
- package/src/types/results.ts +64 -0
- package/src/types/roster.ts +137 -0
- package/src/types/service.ts +702 -0
- package/src/types/session.ts +102 -0
- package/src/types/team.ts +558 -0
- package/src/types.ts +22 -0
- package/README.md +0 -3
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话预算契约(0.19 S4):维度 / 边 / 状态 / 端口。
|
|
3
|
+
* W1-4 纯移动自 types.ts(L610-770),零行为变更。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Usage } from '@vessel-agent/core';
|
|
7
|
+
|
|
8
|
+
// ─── Conversation budget(0.19 S4)──────────────────────────────
|
|
9
|
+
|
|
10
|
+
export type BudgetDimension = 'hops' | 'turns' | 'tokens' | 'wall_clock' | 'cycle';
|
|
11
|
+
|
|
12
|
+
export type BudgetBlockReason =
|
|
13
|
+
| 'budget_exceeded'
|
|
14
|
+
| 'cycle_detected'
|
|
15
|
+
| 'budget_unavailable'
|
|
16
|
+
| 'conversation_team_mismatch';
|
|
17
|
+
|
|
18
|
+
/** 有向边计数(环检测用;最多 32 条,按 last_ts 淘汰)。`count` 是最近一个 cooldown 窗口内的次数。 */
|
|
19
|
+
export interface ConversationBudgetEdge {
|
|
20
|
+
from: string;
|
|
21
|
+
to: string;
|
|
22
|
+
count: number;
|
|
23
|
+
last_ts: number;
|
|
24
|
+
/** 冷却截止时间;未触发时缺省 */
|
|
25
|
+
blocked_until?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** 一条 conversation 的预算视图;不含正文 */
|
|
29
|
+
export interface ConversationBudgetStatus {
|
|
30
|
+
conversation_id: string;
|
|
31
|
+
team_id?: string;
|
|
32
|
+
created_at: number;
|
|
33
|
+
last_activity: number;
|
|
34
|
+
hops: number;
|
|
35
|
+
turns: number;
|
|
36
|
+
total_tokens: number;
|
|
37
|
+
wall_clock_ms: number;
|
|
38
|
+
edges: ConversationBudgetEdge[];
|
|
39
|
+
overrides: Partial<
|
|
40
|
+
Record<BudgetDimension, { max: number; by: 'human'; via: 'cli' | 'api'; at: number }>
|
|
41
|
+
>;
|
|
42
|
+
blocked?: { dimension: BudgetDimension; reason: BudgetBlockReason; at: number };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 投递 / turn 的预算判定结果 */
|
|
46
|
+
export type BudgetCheckResult =
|
|
47
|
+
| { ok: true }
|
|
48
|
+
| {
|
|
49
|
+
ok: false;
|
|
50
|
+
dimension: BudgetDimension;
|
|
51
|
+
reason: BudgetBlockReason;
|
|
52
|
+
current: number;
|
|
53
|
+
max: number | null;
|
|
54
|
+
retry_after_ts?: number;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** 80% 预警(进程内待发布);service 经端口取走 */
|
|
58
|
+
export interface BudgetWarning {
|
|
59
|
+
conversation_id: string;
|
|
60
|
+
team_id?: string;
|
|
61
|
+
dimension: Exclude<BudgetDimension, 'cycle'>;
|
|
62
|
+
current: number;
|
|
63
|
+
max: number;
|
|
64
|
+
threshold: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** receiver-side turn 被挡时持久化的 blocked 状态 */
|
|
68
|
+
export interface BudgetTurnBlockedInput {
|
|
69
|
+
conversation_id: string;
|
|
70
|
+
team_id?: string;
|
|
71
|
+
dimension: BudgetDimension;
|
|
72
|
+
reason: BudgetBlockReason;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface BudgetDeliveryInput {
|
|
76
|
+
conversation_id: string;
|
|
77
|
+
team_id?: string;
|
|
78
|
+
/** true 表示 team_id 是显式 origin 声明;跨 Team 回复不设,沿用已存 origin */
|
|
79
|
+
origin_explicit?: boolean;
|
|
80
|
+
from: string;
|
|
81
|
+
to: string;
|
|
82
|
+
message_id?: string;
|
|
83
|
+
/**
|
|
84
|
+
* 检查模式(0.41):
|
|
85
|
+
* - delivery(缺省):完整检查并计数 hop / edge / last_activity;
|
|
86
|
+
* - read_only:只查 blocked / cycle / limits,不计数、不落库(message_id urgent);
|
|
87
|
+
* - wake:inbox 的 wake 投递模式用的口径 —— 只查 cycle(以及显式 origin 的
|
|
88
|
+
* team 一致性),不 ensure 新 conversation、不计 hop / wall-clock / turns / tokens、
|
|
89
|
+
* 不改 last_activity。
|
|
90
|
+
*/
|
|
91
|
+
mode?: 'delivery' | 'read_only' | 'wake';
|
|
92
|
+
/**
|
|
93
|
+
* cycle 边处理(0.41):
|
|
94
|
+
* - bump(缺省):检查并计数;
|
|
95
|
+
* - check:只检查;
|
|
96
|
+
* - skip:同一 run 已计过该边时整体跳过。
|
|
97
|
+
*/
|
|
98
|
+
edge?: 'bump' | 'check' | 'skip';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface BudgetTurnInput {
|
|
102
|
+
conversation_id: string;
|
|
103
|
+
team_id?: string;
|
|
104
|
+
agent_id: string;
|
|
105
|
+
session_id: string;
|
|
106
|
+
message_id: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface BudgetTurnStartedInput {
|
|
110
|
+
conversation_id: string;
|
|
111
|
+
team_id?: string;
|
|
112
|
+
agent_id: string;
|
|
113
|
+
message_id: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface BudgetTurnFinishedInput {
|
|
117
|
+
conversation_id: string;
|
|
118
|
+
team_id?: string;
|
|
119
|
+
agent_id: string;
|
|
120
|
+
message_id: string;
|
|
121
|
+
usage?: Usage;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface BudgetStatusInput {
|
|
125
|
+
team_id: string;
|
|
126
|
+
conversation_id?: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface BudgetOverrideInput {
|
|
130
|
+
team_id: string;
|
|
131
|
+
conversation_id: string;
|
|
132
|
+
dimension: BudgetDimension;
|
|
133
|
+
/** null = 清除人工 override,回到 team policy */
|
|
134
|
+
max: number | null;
|
|
135
|
+
/** 审计来源;缺省 api(canonical 入口),owner / CLI 传 cli */
|
|
136
|
+
via?: 'cli' | 'api';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface BudgetOverrideResult {
|
|
140
|
+
conversation_id: string;
|
|
141
|
+
dimension: BudgetDimension;
|
|
142
|
+
previous_max: number | null;
|
|
143
|
+
max: number | null;
|
|
144
|
+
status: ConversationBudgetStatus;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** AgentService.budget 的统一返回;按 action 区分 */
|
|
148
|
+
export type BudgetOverview =
|
|
149
|
+
| { action: 'status'; team_id: string; conversations: ConversationBudgetStatus[] }
|
|
150
|
+
| ({ action: 'override'; team_id: string } & BudgetOverrideResult);
|
|
151
|
+
|
|
152
|
+
/** 预算状态存储 / 判定端口;文件实现由 wiring 构造 */
|
|
153
|
+
export interface ConversationBudgetPort {
|
|
154
|
+
checkDelivery(input: BudgetDeliveryInput): BudgetCheckResult;
|
|
155
|
+
canStartTurn(input: BudgetTurnInput): BudgetCheckResult;
|
|
156
|
+
noteTurnStarted(input: BudgetTurnStartedInput): void;
|
|
157
|
+
noteTurnFinished(input: BudgetTurnFinishedInput): void;
|
|
158
|
+
status(input: BudgetStatusInput): ConversationBudgetStatus[];
|
|
159
|
+
override(input: BudgetOverrideInput): BudgetOverrideResult;
|
|
160
|
+
/** 清除该会话的接收侧 hold;返回需要重新 pump 的 agent id */
|
|
161
|
+
release(conversationId: string): string[];
|
|
162
|
+
/** 可选:service 发布预警 / 记账 receiver-side hold(实现可按需提供) */
|
|
163
|
+
takeWarnings?(conversationId: string): BudgetWarning[];
|
|
164
|
+
noteHold?(conversationId: string, agentId: string): void;
|
|
165
|
+
clearHold?(conversationId: string, agentId: string): void;
|
|
166
|
+
noteTurnBlocked?(input: BudgetTurnBlockedInput): void;
|
|
167
|
+
flush(): Promise<void>;
|
|
168
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 跨域共享常量。
|
|
3
|
+
* W1-4 纯移动自 types.ts(L2758-2769),零行为变更。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** 缺省成员 owner / 发送者 */
|
|
7
|
+
export const DEFAULT_OWNER = 'main';
|
|
8
|
+
|
|
9
|
+
/** 单条消息上限(字节) */
|
|
10
|
+
export const MAX_MESSAGE_BYTES = 64 * 1024;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Additive: upper bound for an explicit session title (sessions.create / rotate).
|
|
14
|
+
* Same order of magnitude as sessions.rename (512) but short enough to stay a
|
|
15
|
+
* sidebar label; the value is documented in the rotate schema and error text.
|
|
16
|
+
*/
|
|
17
|
+
export const MAX_SESSION_TITLE_LENGTH = 120;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 消息发送 / 派发 IO 契约。
|
|
3
|
+
* W1-4 纯移动自 types.ts(L1113-1238),零行为变更。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { MessageRef, RunTrigger } from '@vessel-agent/core';
|
|
7
|
+
|
|
8
|
+
/** 发送参数;`to` 可传成员 id 或 session id */
|
|
9
|
+
export interface SendInput {
|
|
10
|
+
to: string;
|
|
11
|
+
/** `interrupt + message_id` 时可为空:正文取自 inbox 里的既有消息。 */
|
|
12
|
+
content: string;
|
|
13
|
+
/** 发送者;缺省 DEFAULT_OWNER,private 成员只有 owner 能寻址 */
|
|
14
|
+
from?: string;
|
|
15
|
+
/** 会话分组;缺省由入口生成(0.19 S4) */
|
|
16
|
+
conversation_id?: string;
|
|
17
|
+
/**
|
|
18
|
+
* 0.32-D:取消目标 body 当前 active run(reason `interrupt`),把本次消息
|
|
19
|
+
* (或 `message_id` 指定的 inbox 消息)作为下一条输入,排在现有队列之前。
|
|
20
|
+
*/
|
|
21
|
+
interrupt?: boolean;
|
|
22
|
+
/** 指定要优先投递的 inbox 消息 id(无需重复 content;必须与 interrupt 同用)。 */
|
|
23
|
+
message_id?: string;
|
|
24
|
+
/**
|
|
25
|
+
* 0.41 wire 别名: `notify: true` ≡ inbox 的 **wake 投递模式**(只追加 inbox unread
|
|
26
|
+
* 并发一次摘要 wake;不 hold / submit / consume)。内部一律转成投递模式再走链路。
|
|
27
|
+
*/
|
|
28
|
+
notify?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* q-error-e2 §3.7(仅内部装配,不暴露为 wire 参数):RPC 触发的 run correlation。
|
|
31
|
+
* 只普通 send(非 interrupt/notify)有意义;透传进 admit → run.started。
|
|
32
|
+
*/
|
|
33
|
+
triggered_by?: RunTrigger;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 批量发送 */
|
|
37
|
+
export interface SendBatchInput {
|
|
38
|
+
messages: SendInput[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* dispatch:统一入口。`to` 可为 id / session_id / 唯一 name。
|
|
43
|
+
* 与 strict `send` 的区别:gone 成员会先 resume,rotating 成员先排队。
|
|
44
|
+
*/
|
|
45
|
+
export interface DispatchInput {
|
|
46
|
+
to: string;
|
|
47
|
+
/** urgent + message_id 时可省 / 为空:正文取自既有 inbox 消息。 */
|
|
48
|
+
content: string;
|
|
49
|
+
/**
|
|
50
|
+
* 附件引用(0.52,additive;内部透传,不扩 wire):只有路径与种类。
|
|
51
|
+
* 与 `AdmitInput.refs` 同一份形状,最终都写成 core `Message.refs`。
|
|
52
|
+
*/
|
|
53
|
+
refs?: MessageRef[];
|
|
54
|
+
from?: string;
|
|
55
|
+
/** 会话分组;缺省生成(0.19 S4) */
|
|
56
|
+
conversation_id?: string;
|
|
57
|
+
/**
|
|
58
|
+
* 显式 origin team(TeamService.post 用);与已存 conversation 的 team 不一致时拒绝。
|
|
59
|
+
* 成员 send / reply / owner dispatch 不传,由发送者或目标推导。
|
|
60
|
+
*/
|
|
61
|
+
origin_team_id?: string;
|
|
62
|
+
/**
|
|
63
|
+
* 来源 Team 日志条目的 message_id(仅内部装配,TeamService.post 填)。
|
|
64
|
+
* 透传进 admit → inbox 条目落盘,供「编辑 / 删除 team 消息」级联消费收件箱副本。
|
|
65
|
+
*/
|
|
66
|
+
team_message_id?: string;
|
|
67
|
+
/**
|
|
68
|
+
* 本次投递是否允许在 resume 失败后自动创建新 Agent。
|
|
69
|
+
* 缺省看 team policy `allowAutoCreate`(默认关闭);显式值覆盖 policy。
|
|
70
|
+
*/
|
|
71
|
+
allow_auto_create?: boolean;
|
|
72
|
+
/** 0.41:urgent(取消 active 并重投到队首)。 */
|
|
73
|
+
interrupt?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* 0.41 wire 别名: `notify: true` ≡ inbox 的 **wake 投递模式**(只追加 inbox unread +
|
|
76
|
+
* 摘要唤醒);与 interrupt 互斥。
|
|
77
|
+
*/
|
|
78
|
+
notify?: boolean;
|
|
79
|
+
/** 0.41:与 interrupt 同用时优先投递既有 inbox 消息。 */
|
|
80
|
+
message_id?: string;
|
|
81
|
+
/** 0.41:内部(非 wire、非持久)调用者 session / run;tool / TeamService 填充。 */
|
|
82
|
+
origin_session_id?: string;
|
|
83
|
+
origin_run_id?: string;
|
|
84
|
+
/** 0.41:内部(非 wire、非持久)一次 messages 数组的 wake 边计数 key。 */
|
|
85
|
+
batch_key?: string;
|
|
86
|
+
/**
|
|
87
|
+
* q-error-e3 §3.7(仅内部装配,不暴露为 RPC 参数):RPC 触发的 run correlation。
|
|
88
|
+
* 由 agents.dispatch handler / TeamService.post 从 ctx.request_id + ctx.method 构建;
|
|
89
|
+
* 透传进 admit → run.started.triggered_by(E2 同款 additive,缺省逐字节不变)。
|
|
90
|
+
*/
|
|
91
|
+
triggered_by?: RunTrigger;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** dispatch 结果:queued 表示已入队;notified 表示 wake 投递成功;rejected 是明确拒绝 */
|
|
95
|
+
export type DispatchResult =
|
|
96
|
+
| {
|
|
97
|
+
status: 'queued';
|
|
98
|
+
message_id: string;
|
|
99
|
+
resolved_to: string;
|
|
100
|
+
resolution: 'live' | 'resumed' | 'rotating' | 'created';
|
|
101
|
+
/** 0.19 S4;实现始终返回,类型保持 additive */
|
|
102
|
+
conversation_id?: string;
|
|
103
|
+
}
|
|
104
|
+
| {
|
|
105
|
+
status: 'notified';
|
|
106
|
+
message_id: string;
|
|
107
|
+
resolved_to: string;
|
|
108
|
+
conversation_id: string;
|
|
109
|
+
wake: boolean;
|
|
110
|
+
resolution: 'live' | 'gone';
|
|
111
|
+
}
|
|
112
|
+
| {
|
|
113
|
+
status: 'rejected';
|
|
114
|
+
code:
|
|
115
|
+
| 'agent_left'
|
|
116
|
+
| 'member_stale'
|
|
117
|
+
| 'invalid_input'
|
|
118
|
+
| 'resume_failed'
|
|
119
|
+
| 'auto_create_failed'
|
|
120
|
+
| 'auto_create_not_allowed'
|
|
121
|
+
| 'team_full'
|
|
122
|
+
| 'team_frozen'
|
|
123
|
+
| 'not_visible'
|
|
124
|
+
| 'budget_exceeded'
|
|
125
|
+
| 'budget_unavailable'
|
|
126
|
+
| 'conversation_team_mismatch'
|
|
127
|
+
/**
|
|
128
|
+
* 0.52 S1a:node 正在优雅退出且没有 durable inbox 可排队 ⇒ 明确可重试,
|
|
129
|
+
* 不要落到 resume_failed(那会让调用方以为 agent 有问题)。
|
|
130
|
+
*/
|
|
131
|
+
| 'node_draining';
|
|
132
|
+
reason: string;
|
|
133
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 成员事件 / 事件监听 / peer-stop 与 human-distress 信号契约。
|
|
3
|
+
* W1-4 纯移动自 types.ts(L1518-1631),零行为变更。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Usage } from '@vessel-agent/core';
|
|
7
|
+
import type { MemberPresence, MemberState, MemberVisibility } from './member.js';
|
|
8
|
+
import type { CreateSeed } from './session.js';
|
|
9
|
+
|
|
10
|
+
/** 一轮的结局;缺省 completed */
|
|
11
|
+
/** q-restart-p2a:'interrupted' = 安全点暂停(run.paused;重启后 auto-resume 续同一 run)。 */
|
|
12
|
+
export type TurnOutcome = 'completed' | 'failed' | 'cancelled' | 'interrupted';
|
|
13
|
+
|
|
14
|
+
/** 成员事件(开放字符串;字段 snake_case) */
|
|
15
|
+
export interface AgentEvent {
|
|
16
|
+
type: string;
|
|
17
|
+
agent_id: string;
|
|
18
|
+
session_id?: string;
|
|
19
|
+
parent_id?: string;
|
|
20
|
+
/** 成员可见性(/agents Self Card 用;spawned 等身份事件必带) */
|
|
21
|
+
visibility?: MemberVisibility;
|
|
22
|
+
/** 成员名(可选) */
|
|
23
|
+
name?: string;
|
|
24
|
+
/** 所属 Team(0.19 S3;unbound / system 事件可能缺省) */
|
|
25
|
+
team_id?: string;
|
|
26
|
+
/** 调用者 id(仅 `agent.spawned`;不持久化) */
|
|
27
|
+
spawned_by?: string;
|
|
28
|
+
/** CREATE-0.39:`agent.spawned` 带来源时的源 agent id(wire snake_case) */
|
|
29
|
+
source_agent_id?: string;
|
|
30
|
+
/** CREATE-0.39:种子方式(有来源创建) */
|
|
31
|
+
seed?: CreateSeed;
|
|
32
|
+
/** CREATE-0.39:请求的保留边界 / 实际复制条数 */
|
|
33
|
+
keep_messages?: number;
|
|
34
|
+
copied_messages?: number;
|
|
35
|
+
keep_projected?: number;
|
|
36
|
+
/** CREATE-0.39:`session.created` 的 new / source 两侧 */
|
|
37
|
+
side?: 'new' | 'source';
|
|
38
|
+
/** CREATE-0.39:文件回滚入口(仅 sessions.create mode=both) */
|
|
39
|
+
mode?: 'conversation' | 'both';
|
|
40
|
+
files_restored?: number;
|
|
41
|
+
files_skipped?: number;
|
|
42
|
+
/** 会话分组(0.19 S4;system 事件可能缺省) */
|
|
43
|
+
conversation_id?: string;
|
|
44
|
+
/** 本轮 usage(run.* 终态由 core 事件携带,AgentEvent 不再填) */
|
|
45
|
+
usage?: Usage;
|
|
46
|
+
/** 已废弃:0.27 删除 `agent.reply.posted`,AgentEvent 不再携带正文 */
|
|
47
|
+
content?: string;
|
|
48
|
+
state?: MemberState;
|
|
49
|
+
/** 进程内 presence(agent.stale / agent.resumed 等生命周期事件) */
|
|
50
|
+
presence?: MemberPresence;
|
|
51
|
+
/** 当前 ExecutionUnit epoch(agent.resumed) */
|
|
52
|
+
epoch?: number;
|
|
53
|
+
/** rotate:旧 / 新 Binding 的 session */
|
|
54
|
+
from_session_id?: string;
|
|
55
|
+
to_session_id?: string;
|
|
56
|
+
/** 事件所属 ExecutionUnit(旧轮终态 / retired / reply.stale) */
|
|
57
|
+
body_id?: string;
|
|
58
|
+
/** 旧 ExecutionUnit 轮末终态标记 */
|
|
59
|
+
stale?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* B′(0.52):退役时仍在 in-flight 的那一轮 run id(rotate 交棒轮)。
|
|
62
|
+
*
|
|
63
|
+
* 只在 `reason === 'rotation'` 的 `agent.retired` 上携带:交棒轮是合法收尾,
|
|
64
|
+
* 消费方(TeamService)据此把「自己交棒的那一轮」与「真迟到的旧轮」区分开,
|
|
65
|
+
* 只 fence 后者。
|
|
66
|
+
*/
|
|
67
|
+
retired_during_run_id?: string;
|
|
68
|
+
/**
|
|
69
|
+
* q-rotate-auto-follow:rotation 档 `agent.retired` additive 携带的新 primary session id。
|
|
70
|
+
*
|
|
71
|
+
* 只在 `reason === 'rotation'` 且退役时刻能取到 primary binding 时携带(取不到不带,
|
|
72
|
+
* fail-closed 不猜);close / TTL 回收等其它 reason 一律不带。retired 本就投递到旧会话
|
|
73
|
+
* 订阅者(会话等值过滤天然满足),补这个字段让「正在看旧会话的人」拿到新会话事实,
|
|
74
|
+
* 前端据此做自动跟随(apps/web/src/app/rotate-follow.ts)。过滤契约零改动。
|
|
75
|
+
*/
|
|
76
|
+
new_session_id?: string;
|
|
77
|
+
message_id?: string;
|
|
78
|
+
/** 消息来源(queued 事件) */
|
|
79
|
+
from?: string;
|
|
80
|
+
/** 事件目标(`agent.create.failed` / `agent.session.activated` 等;与 from 成对) */
|
|
81
|
+
to?: string;
|
|
82
|
+
tool?: string;
|
|
83
|
+
outcome?: TurnOutcome;
|
|
84
|
+
reason?: string;
|
|
85
|
+
request_id?: string;
|
|
86
|
+
decision?: 'allow' | 'deny';
|
|
87
|
+
ts: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 事件监听器;抛错会被隔离,不影响服务行为 */
|
|
91
|
+
export type AgentEventListener = (event: AgentEvent) => void;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 成员停下 / 被关闭的四种结局(装配层 peerStops 端口的载荷)。
|
|
95
|
+
*/
|
|
96
|
+
export type PeerStopKind = 'completed' | 'failed' | 'cancelled' | 'closed';
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 一条「成员真的停了」的变更。
|
|
100
|
+
*
|
|
101
|
+
* 由 AgentService 产出(它判「真的停了」:终态后没有新消息 / 新 run / rotate 窗口),
|
|
102
|
+
* 由装配层的 peer-notice router 转成一条定向到父 session 的 runtime.notice
|
|
103
|
+
* (scope agent,★D5 统一 agent 词):合并、延迟窗口、每轮一条都在 router 里。
|
|
104
|
+
*
|
|
105
|
+
* peer 成员(owner=self、无 parent)没有父级,不产生变更。
|
|
106
|
+
*/
|
|
107
|
+
export interface PeerStopChange {
|
|
108
|
+
/** 注入目标:父成员当前 primary body 的 session id */
|
|
109
|
+
parent_session_id: string;
|
|
110
|
+
agent_id: string;
|
|
111
|
+
/** 展示名(有就用,否则用 id) */
|
|
112
|
+
name?: string;
|
|
113
|
+
kind: PeerStopKind;
|
|
114
|
+
/** 失败原因(一行原文;展示时优先取稳定 code) */
|
|
115
|
+
error?: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** 装配层注入的成员停下通知端口;缺省不报(纯内存 / 测试)。 */
|
|
119
|
+
export type PeerStopSink = (change: PeerStopChange) => void;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 装配层注入的人类求救投递端口(q-distress-message 顶层 fallback)。
|
|
123
|
+
*
|
|
124
|
+
* 把遇难求救写进面向人类的本机 Team 日志(`to:['human']`、零 dispatch)。
|
|
125
|
+
* `from` = 遇难 agent id(自身身份);`teamId` = 遇难者所在 Team,缺省由装配层
|
|
126
|
+
* 解析默认 Team。投递失败抛错(service 记日志,不覆盖原始 run 错误)。
|
|
127
|
+
*/
|
|
128
|
+
export type HumanDistressSink = (input: {
|
|
129
|
+
from: string;
|
|
130
|
+
content: string;
|
|
131
|
+
teamId?: string;
|
|
132
|
+
}) => Promise<void>;
|