@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.
@@ -0,0 +1,28 @@
1
+ /**
2
+ * agent 包单一错误展示文本(q-error-e1,设计 §3.2 / D2)。
3
+ *
4
+ * 收敛原散布 6 处的同形 `errorText`(service / team-service / inbox /
5
+ * conversation-store / conversation-budget / tool):统一调 core `errorSummary`。
6
+ * 拍扁文本只用于**展示**(日志字段 / 事件 reason),不再作为跨层**数据**——
7
+ * 跨层边界读结构化字段走 errorSummary / 注册表。
8
+ *
9
+ * 渲染口径(lead 裁定 B):message 原样;仅当 cause 链非空时追加链摘要
10
+ * (每层 code: message)。顶层不加 code 前缀。
11
+ * q-error-e2(§3.3/§3.6):收口点手拼前缀(spawn_failed:/create_failed: 等)
12
+ * 已废除,改 AgentError options 第三参携 cause/operation/details;cause 链
13
+ * 摘要由此函数渲染进展示文本,结构化链同时上 wire(details.cause)。
14
+ *
15
+ * @module @vessel-agent/agent
16
+ */
17
+
18
+ import { errorSummary } from '@vessel-agent/core';
19
+
20
+ /** 错误 → 单行展示文本(message 原样 + cause 链摘要,防环/截断由 errorSummary 保证) */
21
+ export function errorText(error: unknown): string {
22
+ const summary = errorSummary(error);
23
+ if (summary.chain.length === 0) return summary.message;
24
+ const chain = summary.chain
25
+ .map((link) => (link.code !== undefined ? `${link.code}: ${link.message}` : link.message))
26
+ .join(' <- ');
27
+ return `${summary.message} (cause: ${chain})`;
28
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * inbox 计数源 facade(q-sub-unify-p2 M4,设计 §3 / §4.3,D-2 落生产者旁)。
3
+ *
4
+ * 契约适配,内部机器原样:createInboxNoticeHook 仍直调 inbox.list / noticeContent
5
+ * (hook 不改道);本 facade 纯委托同一批现态函数,供 registry 按 SourceModule 统一
6
+ * 描述/诊断。依赖方向:packages/agent → core 叶类型(不 import 插件)。
7
+ *
8
+ * 键空间 `inbox:*` 与插件 implicit.ts 同口径(源级单条目,target 恒 '*';
9
+ * 字面量副本——packages/agent 不反向依赖插件,P1 friend-edges 同范式)。
10
+ *
11
+ * @module vessel/inbox-source
12
+ */
13
+
14
+ import type {
15
+ NoticeBudget,
16
+ NoticePayload,
17
+ Observation,
18
+ SourceModule,
19
+ TargetResolution,
20
+ } from '@vessel-agent/core';
21
+ import { type AgentInboxPort, noticeContent } from './inbox.js';
22
+
23
+ /** facade 观察上下文(hook options 同形状子集) */
24
+ export interface InboxSourceContext {
25
+ inbox: AgentInboxPort;
26
+ agentId: string;
27
+ }
28
+
29
+ /** 计数素材(detect material / format 入参同形状) */
30
+ export interface InboxCounts {
31
+ unread: number;
32
+ pending: number;
33
+ }
34
+
35
+ /**
36
+ * inbox 源 facade:detect 委托 inbox.list 计数三元组签名(hook 同口径,
37
+ * 全 0 ⇒ undefined 不报);format 委托 noticeContent([inbox] 线格式逐字保留)。
38
+ */
39
+ export const inboxSource: SourceModule<unknown, InboxSourceContext, InboxCounts> = {
40
+ source: 'inbox',
41
+ resolveTarget(input: string): TargetResolution {
42
+ const target = input.trim();
43
+ if (target !== '*') return { ok: false, error: 'invalid_target' };
44
+ return { ok: true, key: 'inbox:*', target };
45
+ },
46
+ async detect(_entry, ctx): Promise<Observation | undefined> {
47
+ const { unread, pending, messages } = ctx.inbox.list(ctx.agentId, { includeHeld: true });
48
+ let held = 0;
49
+ for (const entry of messages) if (entry.held) held += 1;
50
+ if (unread === 0 && pending === 0 && held === 0) return undefined;
51
+ return { rev: `${unread}:${pending}:${held}`, material: { unread, pending, held } };
52
+ },
53
+ cursor: { kind: 'count' },
54
+ format(changes: readonly InboxCounts[], _budget: NoticeBudget): NoticePayload {
55
+ const last = changes[changes.length - 1] ?? { unread: 0, pending: 0 };
56
+ return { scope: 'inbox', content: noticeContent(last.unread, last.pending) };
57
+ },
58
+ delivery: 'ambient',
59
+ };
60
+
61
+ /** 装配期断言(模块加载即跑,非测试形态):facade 契约不变量(P1 sources.ts 同范式)。 */
62
+ for (const mod of [inboxSource]) {
63
+ if (
64
+ typeof mod.resolveTarget !== 'function' ||
65
+ typeof mod.detect !== 'function' ||
66
+ typeof mod.format !== 'function'
67
+ ) {
68
+ throw new Error(`source-module invariant: ${mod.source} missing contract methods`);
69
+ }
70
+ if (mod.delivery !== 'ambient') {
71
+ throw new Error(`source-module invariant: ${mod.source} must be ambient (count hook)`);
72
+ }
73
+ }