@vessel-agent/agent 0.0.0-stage → 2.3.0-beta.2
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
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vessel-agent/agent",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.3.0-beta.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"types": "src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.ts"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/egg-rolls/Vessel.git",
|
|
17
|
+
"directory": "packages/agent"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"bun": ">=1.3.9"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"typecheck": "tsc --noEmit"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@vessel-agent/config": "2.3.0-beta.2",
|
|
27
|
+
"@vessel-agent/core": "2.3.0-beta.2"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"typescript": "^7.0.2"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 地址显示格式(q-addr-display,用户裁定:name 优先、轻量有质感)。
|
|
3
|
+
*
|
|
4
|
+
* **显示与路由分离**:路由地址(`agent send` 的 `to` / federation 投递)永远用
|
|
5
|
+
* canonical full-id 三段;本模块只管「给人 / 模型看」的那一层。三档全局风格:
|
|
6
|
+
*
|
|
7
|
+
* - `name`(缺省):各段能用名就用名 —— `main@soulkiller:vessel`;
|
|
8
|
+
* - `compact`:principal 名 + node 短 id(前 8 位)+ team 名;
|
|
9
|
+
* - `full`:现行为,各段原样(full uuid)。
|
|
10
|
+
*
|
|
11
|
+
* 兜底链:name 不可用 → short-id(前 8 位)→ full-id。两条约束:
|
|
12
|
+
*
|
|
13
|
+
* 1. **replyable**(渲染结果会被模型原样抄进 `to` 的场景,如 runtime 来源行):
|
|
14
|
+
* principal 的 short-id 兜底**跳过**直达 full-id —— 解析侧
|
|
15
|
+
* (`resolveAddressMember` / `registry.resolve`)只做精确匹配,principal 短 id
|
|
16
|
+
* 是死地址。node 短 id 例外:`isLocalNodeSegment` 已支持本机 nodeId 的 ≥8 位
|
|
17
|
+
* 前缀匹配(只对本机一个 id,无前缀歧义),且 replyable 渲染只用于本机来源。
|
|
18
|
+
* 跨节点来源(federation 入站)不走本模块,保持 canonical。
|
|
19
|
+
* 2. **纯显示**(web 卡片 / 副行,replyable 缺省 false):走完整兜底链,
|
|
20
|
+
* 短 id 不可路由也无妨 —— 那一层本来就不供抄写。
|
|
21
|
+
*
|
|
22
|
+
* **零 import 的 leaf 模块**:runtime(packages/agent)与 web(apps/web 经
|
|
23
|
+
* tsconfig paths + vite alias 按源码消费,先例:plugin-ui)共用这一份实现,
|
|
24
|
+
* 不拖任何依赖图。per-segment 配置是留好的扩展位:`names` / `opts` 已按段组织,
|
|
25
|
+
* 将来加 perSegment 键不破签名。
|
|
26
|
+
*
|
|
27
|
+
* @module vessel/address-display
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** 地址显示风格三档(全局;缺省 name)。 */
|
|
31
|
+
export type AddressStyle = 'name' | 'compact' | 'full';
|
|
32
|
+
|
|
33
|
+
/** 缺省风格:name 优先(用户裁定)。 */
|
|
34
|
+
export const DEFAULT_ADDRESS_STYLE: AddressStyle = 'name';
|
|
35
|
+
|
|
36
|
+
/** 合法档位(config validator / gateway ENUM_KEYS / web 注册表共用同一份值)。 */
|
|
37
|
+
export const ADDRESS_STYLES: readonly AddressStyle[] = ['name', 'compact', 'full'];
|
|
38
|
+
|
|
39
|
+
/** 把任意输入归一化为合法档位;非法 / 缺省 → DEFAULT_ADDRESS_STYLE。 */
|
|
40
|
+
export function normalizeAddressStyle(value: unknown): AddressStyle {
|
|
41
|
+
return value === 'name' || value === 'compact' || value === 'full'
|
|
42
|
+
? value
|
|
43
|
+
: DEFAULT_ADDRESS_STYLE;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 地址三段(缺段不补占位符,与 runtime `formatMessageSource` 同口径)。 */
|
|
47
|
+
export interface AddressSegments {
|
|
48
|
+
principal?: string;
|
|
49
|
+
node?: string;
|
|
50
|
+
team?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* id → 展示名查找表(按段独立)。值可以是段本身已是名字的情形 ——
|
|
55
|
+
* 非 uuid 形状的段一律视为「已是名字」原样渲染,不查表。
|
|
56
|
+
*/
|
|
57
|
+
export interface AddressNameMaps {
|
|
58
|
+
node?: ReadonlyMap<string, string>;
|
|
59
|
+
principal?: ReadonlyMap<string, string>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface FormatAddressOptions {
|
|
63
|
+
/**
|
|
64
|
+
* 渲染结果会被原样抄进路由 `to`(runtime 来源行)。true 时 principal 兜底
|
|
65
|
+
* 跳过 short-id 直达 full-id(解析侧无前缀匹配,短 id 是死地址)。
|
|
66
|
+
* 缺省 false = 纯显示,走完整兜底链。
|
|
67
|
+
*/
|
|
68
|
+
replyable?: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** canonical uuid 形状(8-4-4-4-12 hex);只有 id 才需要查名 / 截短。 */
|
|
72
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
73
|
+
|
|
74
|
+
/** 段值是否 uuid 形状(= 是 id,不是名字)。 */
|
|
75
|
+
export function isUuidLike(value: string): boolean {
|
|
76
|
+
return UUID_RE.test(value);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 短 id:前 8 位(uuid 首段)。非 uuid 输入原样返回(名字不截断)。 */
|
|
80
|
+
export function shortAddressId(value: string): string {
|
|
81
|
+
return isUuidLike(value) ? value.slice(0, 8) : value;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 单段渲染。team 段恒原样:slug 本身就是名字,没有 id 形态。
|
|
86
|
+
*
|
|
87
|
+
* - full:原样;
|
|
88
|
+
* - 段已是名字(非 uuid 形状):原样(compact 的 node 也不截名字 —— 无从截起);
|
|
89
|
+
* - node:name 档查名,查不到兜底短 id;compact 档直接短 id;
|
|
90
|
+
* - principal:name / compact 都先查名;查不到时 replyable → full-id,
|
|
91
|
+
* 纯显示 → 短 id。
|
|
92
|
+
*/
|
|
93
|
+
function renderSegment(
|
|
94
|
+
value: string,
|
|
95
|
+
kind: 'principal' | 'node',
|
|
96
|
+
style: AddressStyle,
|
|
97
|
+
names: AddressNameMaps | undefined,
|
|
98
|
+
replyable: boolean,
|
|
99
|
+
): string {
|
|
100
|
+
if (style === 'full') return value;
|
|
101
|
+
if (!isUuidLike(value)) return value;
|
|
102
|
+
if (kind === 'node') {
|
|
103
|
+
if (style === 'compact') return shortAddressId(value);
|
|
104
|
+
const named = names?.node?.get(value);
|
|
105
|
+
return named !== undefined && named !== '' ? named : shortAddressId(value);
|
|
106
|
+
}
|
|
107
|
+
const named = names?.principal?.get(value);
|
|
108
|
+
if (named !== undefined && named !== '') return named;
|
|
109
|
+
return replyable ? value : shortAddressId(value);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 统一地址显示纯函数:解析好的三段 → 按 style 渲染 → 兜底。
|
|
114
|
+
*
|
|
115
|
+
* 拼接规则与 `formatMessageSource` 一致:有 node/team 才写 `@host`,
|
|
116
|
+
* host 内 node:team 用 `:` 连接;缺的段不补占位符。无 principal 时
|
|
117
|
+
* (web 工具卡路由副行只有 node:team)直接渲染 host。
|
|
118
|
+
*
|
|
119
|
+
* 不做字符集 / 可路由性校验:调用方负责保证输入段合法(runtime 侧已有
|
|
120
|
+
* `isAddressSafePrincipal` 闸;web 侧输入来自持久化事实)。
|
|
121
|
+
*/
|
|
122
|
+
export function formatAddress(
|
|
123
|
+
addr: AddressSegments,
|
|
124
|
+
style: AddressStyle = DEFAULT_ADDRESS_STYLE,
|
|
125
|
+
names?: AddressNameMaps,
|
|
126
|
+
opts?: FormatAddressOptions,
|
|
127
|
+
): string {
|
|
128
|
+
const replyable = opts?.replyable === true;
|
|
129
|
+
const principal =
|
|
130
|
+
addr.principal !== undefined && addr.principal !== ''
|
|
131
|
+
? renderSegment(addr.principal, 'principal', style, names, replyable)
|
|
132
|
+
: undefined;
|
|
133
|
+
const node =
|
|
134
|
+
addr.node !== undefined && addr.node !== ''
|
|
135
|
+
? renderSegment(addr.node, 'node', style, names, replyable)
|
|
136
|
+
: undefined;
|
|
137
|
+
const team = addr.team !== undefined && addr.team !== '' ? addr.team : undefined;
|
|
138
|
+
const host = [node, team].filter((part): part is string => part !== undefined).join(':');
|
|
139
|
+
if (principal === undefined) return host;
|
|
140
|
+
return host === '' ? principal : `${principal}@${host}`;
|
|
141
|
+
}
|