@sema-agent/settings-schema 34.0.0 → 35.0.0
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/CHANGELOG.md +648 -0
- package/README.md +86 -39
- package/conformance/VERSION +1 -1
- package/conformance/cases/c100-a2a-inside-stale-fingerprint-dropped/expected.json +101 -0
- package/conformance/cases/c100-a2a-inside-stale-fingerprint-dropped/input.json +28 -0
- package/conformance/cases/c100-a2a-inside-stale-fingerprint-dropped/meta.json +6 -0
- package/conformance/cases/c101-a2a-inside-incomplete-dropped/expected.json +113 -0
- package/conformance/cases/c101-a2a-inside-incomplete-dropped/input.json +38 -0
- package/conformance/cases/c101-a2a-inside-incomplete-dropped/meta.json +6 -0
- package/conformance/cases/c102-a2a-inside-incomplete-zero-survivors/expected.json +85 -0
- package/conformance/cases/c102-a2a-inside-incomplete-zero-survivors/input.json +34 -0
- package/conformance/cases/c102-a2a-inside-incomplete-zero-survivors/meta.json +6 -0
- package/conformance/cases/c103-mcp-caller-meta-declared/expected.json +106 -0
- package/conformance/cases/c103-mcp-caller-meta-declared/input.json +28 -0
- package/conformance/cases/c103-mcp-caller-meta-declared/meta.json +6 -0
- package/conformance/cases/c98-a2a-registration-keys-carried/expected.json +163 -0
- package/conformance/cases/c98-a2a-registration-keys-carried/input.json +42 -0
- package/conformance/cases/c98-a2a-registration-keys-carried/meta.json +6 -0
- package/conformance/cases/c99-a2a-preapproval-on-outside-peer-dropped/expected.json +100 -0
- package/conformance/cases/c99-a2a-preapproval-on-outside-peer-dropped/input.json +23 -0
- package/conformance/cases/c99-a2a-preapproval-on-outside-peer-dropped/meta.json +6 -0
- package/dist/a2a-peer-identity.d.ts +116 -0
- package/dist/a2a-peer-identity.js +182 -0
- package/dist/api/credentials.d.ts +94 -14
- package/dist/api/credentials.js +33 -8
- package/dist/atomic-write.d.ts +9 -3
- package/dist/atomic-write.js +14 -6
- package/dist/catalog-manages.js +2 -2
- package/dist/config-d-file.d.ts +0 -3
- package/dist/config-d-file.js +1 -6
- package/dist/config-dir-migration.js +0 -1
- package/dist/config-document-refusal.d.ts +1 -1
- package/dist/config-fns.d.ts +21 -8
- package/dist/config-fns.js +16 -3
- package/dist/config-root-documents.d.ts +3 -54
- package/dist/config-root-documents.js +24 -21
- package/dist/config-root-node.d.ts +2 -96
- package/dist/config-root-node.js +15 -163
- package/dist/conformance/warnings.js +1 -1
- package/dist/conformance/web-admin-credential-lock.js +3 -2
- package/dist/cross-session.d.ts +2 -2
- package/dist/env-model-table.d.ts +3 -3
- package/dist/env-model-table.js +5 -5
- package/dist/fleet.d.ts +5 -5
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/mcp-request-entry.d.ts +19 -0
- package/dist/mcp-request-entry.js +15 -13
- package/dist/migration-receipt.d.ts +9 -11
- package/dist/migration-receipt.js +4 -5
- package/dist/node.d.ts +3 -3
- package/dist/node.js +3 -3
- package/dist/one-time-migrations.d.ts +3 -4
- package/dist/one-time-migrations.js +3 -28
- package/dist/plugin-id-segment.d.ts +15 -0
- package/dist/plugin-id-segment.js +15 -0
- package/dist/plugin-settings.d.ts +61 -0
- package/dist/plugin-settings.js +111 -0
- package/dist/retired-envs.js +5 -0
- package/dist/safety-merge-spec.d.ts +23 -2
- package/dist/safety-merge-spec.js +13 -0
- package/dist/scheduler-store-node.d.ts +14 -11
- package/dist/scheduler-store-node.js +22 -34
- package/dist/scheduler-store.d.ts +21 -6
- package/dist/scheduler-store.js +100 -19
- package/dist/settings-units.d.ts +9 -0
- package/dist/settings-units.js +12 -7
- package/dist/types.d.ts +53 -4
- package/dist/types.js +79 -4
- package/docs/API-SURFACE.md +51 -11
- package/docs/CC-DIVERGENCE.md +2 -1
- package/docs/CONFORMANCE.md +4 -4
- package/docs/CONSUMER-INTEGRATION.md +158 -13
- package/llms-full.txt +47 -18
- package/llms.txt +18 -7
- package/package.json +7 -3
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `a2a` 对端条目的**身份与登记**:内外两词与「缺席读外部」的唯一读法 · 身份戳(它的拼写、它的摘要半段怎么复算、它怎么铸)· 条目判的问题词闭集与
|
|
3
|
+
* 判法(接引擎原语包的完备性判官,本包只补两词)· 存量与提交两份名册的配对。都只在这里。叶子模块(只引 zod、引擎原语包与包内的摘要 / 稳定 JSON /
|
|
4
|
+
* 冻结几只):`./types` 的条目 schema 引它,它不引 `./types` 的值。
|
|
5
|
+
*
|
|
6
|
+
* **这枚戳由本包铸、别处只比较不铸。** 引擎把同一枚戳落在规则的每次添加上(以及撤销那一问、运行的挂载清单),与条目上的 `fingerprint` 是同一枚戳的
|
|
7
|
+
* 两个出现处:条目上的这一处是唯一的铸点。写口(管理台)与单机的「确认登记」入口调 {@link mintA2aPeerFingerprint};引擎、server、各副本只拿它与别处
|
|
8
|
+
* 那一枚逐字比较,从不自己算一枚。
|
|
9
|
+
*
|
|
10
|
+
* **戳不是凭据**:它是条目身份的版本号 —— 身份每被写一次就换一枚,于是「对这一版身份给过的放行」与「改过身份之后的条目」分得开。它不保密、不签名:
|
|
11
|
+
* 能写这份配置的人(包括被说动的模型用写文件工具)照样算得出一枚摘要对得上的戳 —— 挡的是失误与漂移,不挡蓄意。所以它不进任何凭据形判官、不进密钥
|
|
12
|
+
* 引用清单,出现在日志与读口上都没事。
|
|
13
|
+
*
|
|
14
|
+
* **形**({@link A2A_PEER_FINGERPRINT_RE}):`<摘要>.<随机>`,两半各 32 位小写十六进制(整串 65 字,在引擎对该成员的长界之内)。
|
|
15
|
+
* - **摘要半段**({@link a2aPeerFingerprintDigest})= SHA-256(域分隔前缀 + 身份字段的稳定 JSON)的前 32 位。身份字段恰是这四个(本包只在这里
|
|
16
|
+
* 写这一遍):`url`、`cardUrl`(缺席读 null)、`ownerTeam`(缺席读 null)、`boundary`(经 {@link a2aPeerBoundaryOf}:缺席读 `"outside"`,写明
|
|
17
|
+
* `outside` 不算换了身份)。`name`、`id`、`displayName`、`allowSkills`、`askEverySkills`、`principalHeader`、`headerRefs`、`scenarios`、`enabled`、
|
|
18
|
+
* `preApprovedFor` 一律不在内。
|
|
19
|
+
* - **随机半段** = 16 字节,取自运行时的 Web Crypto(`globalThis.crypto.getRandomValues`;浏览器与 Node ≥ 19 是同一个全局)。本模块在纯包根里
|
|
20
|
+
* (管理台的客户端组件也经包根取型),不引 `node:crypto`(与 `./sha256` 同一条纪律);取不到这个随机源 ⇒ 抛,从不退回任何更弱的随机。
|
|
21
|
+
*
|
|
22
|
+
* **条目判**(写在 `./types` 的 `A2aPeerSpec` 上,写面整份拒、视图面逐条丢,两面读那一只):问题词闭集 {@link A2A_PEER_ENTRY_PROBLEMS} = 引擎原语包
|
|
23
|
+
* `A2A_REGISTRATION_PROBLEMS` 原序展开 + 本包两词 `fingerprint_stale`(内部条目的戳摘要半段与身份字段对不上)、`id_missing`(内部条目没有 `id`)。
|
|
24
|
+
* 「完不完备」「读不读得出」的判官只有原语包那一只(`a2aRegistrationProblems`:`member` 组对每条都问,`inside` 组只问内部条目)—— 本包不另写一份,
|
|
25
|
+
* 也不在成员 schema 上再判一遍非空 / 长界。每个词一条 issue,词在 issue 的 `params.flaw`(与 URL 形判官、记录座位守卫同一个槽位);读腿按
|
|
26
|
+
* {@link registrationProblemsOf} 从同一次判决里取词,不读句子、不重判。
|
|
27
|
+
*
|
|
28
|
+
* **配对**({@link pairA2aPeers}):写一份名册时「这一条是存量里的哪一条」只有这一只读法 —— 铸戳(`prev` 从这里来)与写角色同读它。
|
|
29
|
+
*/
|
|
30
|
+
import { z } from "zod";
|
|
31
|
+
import type { A2aPeerSpec } from "./types.js";
|
|
32
|
+
/** 一个对端在不在本组织的信任边界之内:两词闭集。条目上缺席 = 外部({@link a2aPeerBoundaryOf})。 */
|
|
33
|
+
export declare const A2A_PEER_BOUNDARIES: readonly ["inside", "outside"];
|
|
34
|
+
export type A2aPeerBoundary = (typeof A2A_PEER_BOUNDARIES)[number];
|
|
35
|
+
/**
|
|
36
|
+
* 一条条目的内外 —— 「`boundary` 缺席读外部」的**唯一**读法(失败即关:读方从不把缺席读成内部)。读出形不替谁补这个键
|
|
37
|
+
* (缺席的条目读出来照样缺席,不带新键的旧条目逐字节不变),要问内外的读者都问这一只。
|
|
38
|
+
*/
|
|
39
|
+
export declare function a2aPeerBoundaryOf(peer: {
|
|
40
|
+
readonly boundary?: A2aPeerBoundary | undefined;
|
|
41
|
+
}): A2aPeerBoundary;
|
|
42
|
+
/** 身份戳的**唯一拼写**:`<32 位小写十六进制摘要>.<32 位小写十六进制随机>`。无旗标(`.test` 无状态,可共享这一只)。 */
|
|
43
|
+
export declare const A2A_PEER_FINGERPRINT_RE: RegExp;
|
|
44
|
+
/** {@link A2A_PEER_FINGERPRINT_RE} 作 schema —— 条目上装戳的两个座位(`fingerprint`、`preApprovedFor`)都引它。 */
|
|
45
|
+
export declare const A2aPeerFingerprint: z.ZodString;
|
|
46
|
+
/** 一条 `a2a` 条目的任意一组字段(读出的条目、管理台的草稿、单机文件里的一条都行):读它的函数只给它自己读的那几只写型,其余字段的值不读。 */
|
|
47
|
+
export type A2aPeerFields = {
|
|
48
|
+
readonly [K in keyof A2aPeerSpec]?: unknown;
|
|
49
|
+
};
|
|
50
|
+
/** 铸戳与复算摘要读的条目:任意一组条目字段,`url` 必在;读的只有身份字段与(上一版的)`fingerprint`。 */
|
|
51
|
+
export type A2aPeerIdentitySource = A2aPeerFields & {
|
|
52
|
+
readonly url: string;
|
|
53
|
+
readonly cardUrl?: string | undefined;
|
|
54
|
+
readonly ownerTeam?: string | undefined;
|
|
55
|
+
readonly boundary?: A2aPeerBoundary | undefined;
|
|
56
|
+
readonly fingerprint?: string | undefined;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* **复算摘要**(只此一只,铸戳与条目判的 `fingerprint_stale` 同读):一条条目身份字段的摘要半段 —— 覆盖哪几个字段见模块头,别处不复述。
|
|
60
|
+
* 纯函数:同输入同答,不读身份字段以外的任何键。
|
|
61
|
+
*/
|
|
62
|
+
export declare function a2aPeerFingerprintDigest(peer: A2aPeerIdentitySource): string;
|
|
63
|
+
/**
|
|
64
|
+
* **铸戳**(只此一只):写一条条目时,它该带哪一枚戳。`next` = 这次要存的条目,`prev` = 存着的同一条(由 {@link pairA2aPeers} 配出;新建时缺席)。
|
|
65
|
+
*
|
|
66
|
+
* 一条律:**`prev` 的戳就是 `next` 的身份的那一枚时原样交回,否则铸一枚新的** —— 「就是」= `prev` 带着一枚拼写合法的戳,它的摘要半段等于
|
|
67
|
+
* `prev` 自己身份字段的复算摘要,也等于 `next` 的。于是:新建 ⇒ 新戳;任一身份字段变 ⇒ 新戳;改走再改回 ⇒ 又一枚新的(上一版是改走后的身份,
|
|
68
|
+
* 改走之前那一枚从不复用);上一版没有戳、或它的戳与它自己的身份字段对不上(手改过文件)⇒ 新戳;只改非身份字段 ⇒ 原戳。
|
|
69
|
+
* `next.fingerprint` 从不被读:调用方自己带来的戳不算数(写口不许让调用方给自己铸戳)。
|
|
70
|
+
*/
|
|
71
|
+
export declare function mintA2aPeerFingerprint(next: A2aPeerIdentitySource, prev?: A2aPeerIdentitySource): string;
|
|
72
|
+
/**
|
|
73
|
+
* 一条条目的**问题词**闭集:引擎原语包的登记问题词(原序展开,本包不手抄)+ 尾插本包两词 —— `fingerprint_stale`(内部条目的戳摘要半段与它的身份字段
|
|
74
|
+
* 对不上:身份改过而戳没换)、`id_missing`(内部条目没有 `id`:读口、审计与配对按它认条目)。型由它派生。被丢条目的行
|
|
75
|
+
* ({@link DroppedEntry} 的 `registrationProblems`)与告警读的是这张表。
|
|
76
|
+
*/
|
|
77
|
+
export declare const A2A_PEER_ENTRY_PROBLEMS: readonly ["boundary_unreadable", "fingerprint_unreadable", "display_name_unreadable", "owner_team_unreadable", "fingerprint_missing", "allow_skills_missing", "principal_header_missing", "owner_team_missing", "url_plaintext", "card_url_plaintext", "fingerprint_stale", "id_missing"];
|
|
78
|
+
export type A2aPeerEntryProblem = (typeof A2A_PEER_ENTRY_PROBLEMS)[number];
|
|
79
|
+
/** 每个问题词点到条目的哪一只成员(写面 issue 的坐标)。穷举(闭集每个词一行,少一行 ⇒ 编译红)。包私有。 */
|
|
80
|
+
export declare const A2A_PEER_ENTRY_PROBLEM_MEMBER: Readonly<Record<A2aPeerEntryProblem, keyof A2aPeerSpec>>;
|
|
81
|
+
/**
|
|
82
|
+
* 条目判的**判法**(包私有;只由 `./types` 的 `A2aPeerSpec` 调,读方经那只 schema 问,不另调它):一条成员形已过的条目有哪些问题词,每个词一次、
|
|
83
|
+
* 按 {@link A2A_PEER_ENTRY_PROBLEMS} 的序;`[]` = 这一条可以生效。原语包的判官原样问(它自己只对 `boundary: "inside"` 问 `inside` 组);本包两词
|
|
84
|
+
* 只问内部条目(放宽只落在内部条目上;外部条目的戳只被比较,不放行任何东西)。戳缺席或拼写不合法不在 `fingerprint_stale` 这一格(拼写由成员形判,
|
|
85
|
+
* 缺席由原语包的 `fingerprint_missing` 判)。
|
|
86
|
+
*/
|
|
87
|
+
export declare function a2aPeerEntryProblems(peer: A2aPeerIdentitySource & {
|
|
88
|
+
readonly id?: string | undefined;
|
|
89
|
+
}): A2aPeerEntryProblem[];
|
|
90
|
+
/**
|
|
91
|
+
* 一次被拒判决里的问题词(包私有;逐条丢弃的判决点调它):`issues` 非空且**每一条**都是带问题词(`params.flaw`)的自铸 issue ⇒ 词表(每个词一次、
|
|
92
|
+
* 闭集序);有任何一条别的 issue(成员形错、别的判官)⇒ `undefined` —— 成员形先于完备性,那一条记成员形的丢法。只读结构化参数,不读句子、不重判。
|
|
93
|
+
*/
|
|
94
|
+
export declare function registrationProblemsOf(issues: readonly z.core.$ZodIssue[]): A2aPeerEntryProblem[] | undefined;
|
|
95
|
+
/** 配对读的条目:名必在,`id` 可缺;其余字段原样带回、不读。 */
|
|
96
|
+
export type A2aPeerPairable = A2aPeerFields & {
|
|
97
|
+
readonly name: string;
|
|
98
|
+
readonly id?: string | undefined;
|
|
99
|
+
};
|
|
100
|
+
/** {@link pairA2aPeers} 的答:`pairs` 按提交序,一条提交条目一行(`prev` 缺席 = 新建);`removed` = 没被任何提交条目配上的存量,按存量序。 */
|
|
101
|
+
export interface A2aPeerPairing<Prev extends A2aPeerPairable, Next extends A2aPeerPairable> {
|
|
102
|
+
readonly pairs: readonly {
|
|
103
|
+
readonly next: Next;
|
|
104
|
+
readonly prev?: Prev;
|
|
105
|
+
}[];
|
|
106
|
+
readonly removed: readonly Prev[];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* **配对**(只此一只):提交的名册 `after` 里每一条是存量 `before` 里的哪一条。铸戳({@link mintA2aPeerFingerprint} 的 `prev`)与写角色同读这一只,
|
|
110
|
+
* 不各自按名配。两趟、确定性:
|
|
111
|
+
* ① 只按 `id` 配:提交条目带 `id`、存量里有同 `id` 且还没被占的那一条(文档序第一条)。
|
|
112
|
+
* ② 只在第一趟没配上的提交条目与没被占的存量之间按名配(文档序第一条);**两边都带 `id` 且不相等 ⇒ 不配**(`id` 变了就是另一条:新建 + 删除)。
|
|
113
|
+
* 一条存量至多被配一次,由两趟共用的「已占」集合保证,不靠域判的名唯一 / `id` 唯一(名册读进来时那两道域判本来就成立;这里不假设它)。
|
|
114
|
+
* 只读 `name` / `id`;答案里的 `prev` / `next` 是入参里的同一个对象。
|
|
115
|
+
*/
|
|
116
|
+
export declare function pairA2aPeers<Prev extends A2aPeerPairable, Next extends A2aPeerPairable>(before: readonly Prev[], after: readonly Next[]): A2aPeerPairing<Prev, Next>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `a2a` 对端条目的**身份与登记**:内外两词与「缺席读外部」的唯一读法 · 身份戳(它的拼写、它的摘要半段怎么复算、它怎么铸)· 条目判的问题词闭集与
|
|
3
|
+
* 判法(接引擎原语包的完备性判官,本包只补两词)· 存量与提交两份名册的配对。都只在这里。叶子模块(只引 zod、引擎原语包与包内的摘要 / 稳定 JSON /
|
|
4
|
+
* 冻结几只):`./types` 的条目 schema 引它,它不引 `./types` 的值。
|
|
5
|
+
*
|
|
6
|
+
* **这枚戳由本包铸、别处只比较不铸。** 引擎把同一枚戳落在规则的每次添加上(以及撤销那一问、运行的挂载清单),与条目上的 `fingerprint` 是同一枚戳的
|
|
7
|
+
* 两个出现处:条目上的这一处是唯一的铸点。写口(管理台)与单机的「确认登记」入口调 {@link mintA2aPeerFingerprint};引擎、server、各副本只拿它与别处
|
|
8
|
+
* 那一枚逐字比较,从不自己算一枚。
|
|
9
|
+
*
|
|
10
|
+
* **戳不是凭据**:它是条目身份的版本号 —— 身份每被写一次就换一枚,于是「对这一版身份给过的放行」与「改过身份之后的条目」分得开。它不保密、不签名:
|
|
11
|
+
* 能写这份配置的人(包括被说动的模型用写文件工具)照样算得出一枚摘要对得上的戳 —— 挡的是失误与漂移,不挡蓄意。所以它不进任何凭据形判官、不进密钥
|
|
12
|
+
* 引用清单,出现在日志与读口上都没事。
|
|
13
|
+
*
|
|
14
|
+
* **形**({@link A2A_PEER_FINGERPRINT_RE}):`<摘要>.<随机>`,两半各 32 位小写十六进制(整串 65 字,在引擎对该成员的长界之内)。
|
|
15
|
+
* - **摘要半段**({@link a2aPeerFingerprintDigest})= SHA-256(域分隔前缀 + 身份字段的稳定 JSON)的前 32 位。身份字段恰是这四个(本包只在这里
|
|
16
|
+
* 写这一遍):`url`、`cardUrl`(缺席读 null)、`ownerTeam`(缺席读 null)、`boundary`(经 {@link a2aPeerBoundaryOf}:缺席读 `"outside"`,写明
|
|
17
|
+
* `outside` 不算换了身份)。`name`、`id`、`displayName`、`allowSkills`、`askEverySkills`、`principalHeader`、`headerRefs`、`scenarios`、`enabled`、
|
|
18
|
+
* `preApprovedFor` 一律不在内。
|
|
19
|
+
* - **随机半段** = 16 字节,取自运行时的 Web Crypto(`globalThis.crypto.getRandomValues`;浏览器与 Node ≥ 19 是同一个全局)。本模块在纯包根里
|
|
20
|
+
* (管理台的客户端组件也经包根取型),不引 `node:crypto`(与 `./sha256` 同一条纪律);取不到这个随机源 ⇒ 抛,从不退回任何更弱的随机。
|
|
21
|
+
*
|
|
22
|
+
* **条目判**(写在 `./types` 的 `A2aPeerSpec` 上,写面整份拒、视图面逐条丢,两面读那一只):问题词闭集 {@link A2A_PEER_ENTRY_PROBLEMS} = 引擎原语包
|
|
23
|
+
* `A2A_REGISTRATION_PROBLEMS` 原序展开 + 本包两词 `fingerprint_stale`(内部条目的戳摘要半段与身份字段对不上)、`id_missing`(内部条目没有 `id`)。
|
|
24
|
+
* 「完不完备」「读不读得出」的判官只有原语包那一只(`a2aRegistrationProblems`:`member` 组对每条都问,`inside` 组只问内部条目)—— 本包不另写一份,
|
|
25
|
+
* 也不在成员 schema 上再判一遍非空 / 长界。每个词一条 issue,词在 issue 的 `params.flaw`(与 URL 形判官、记录座位守卫同一个槽位);读腿按
|
|
26
|
+
* {@link registrationProblemsOf} 从同一次判决里取词,不读句子、不重判。
|
|
27
|
+
*
|
|
28
|
+
* **配对**({@link pairA2aPeers}):写一份名册时「这一条是存量里的哪一条」只有这一只读法 —— 铸戳(`prev` 从这里来)与写角色同读它。
|
|
29
|
+
*/
|
|
30
|
+
import { z } from "zod";
|
|
31
|
+
import { A2A_REGISTRATION_PROBLEMS, a2aRegistrationProblems } from "@sema-agent/primitives";
|
|
32
|
+
import { deepFreeze } from "./deep-freeze.js";
|
|
33
|
+
import { stableStringify } from "./hash.js";
|
|
34
|
+
import { sha256Hex } from "./sha256.js";
|
|
35
|
+
import { toHex } from "./sha256-core.js";
|
|
36
|
+
/** 一个对端在不在本组织的信任边界之内:两词闭集。条目上缺席 = 外部({@link a2aPeerBoundaryOf})。 */
|
|
37
|
+
export const A2A_PEER_BOUNDARIES = deepFreeze(["inside", "outside"]);
|
|
38
|
+
/**
|
|
39
|
+
* 一条条目的内外 —— 「`boundary` 缺席读外部」的**唯一**读法(失败即关:读方从不把缺席读成内部)。读出形不替谁补这个键
|
|
40
|
+
* (缺席的条目读出来照样缺席,不带新键的旧条目逐字节不变),要问内外的读者都问这一只。
|
|
41
|
+
*/
|
|
42
|
+
export function a2aPeerBoundaryOf(peer) {
|
|
43
|
+
return peer.boundary ?? "outside";
|
|
44
|
+
}
|
|
45
|
+
/** 戳的两半各几位十六进制。 */
|
|
46
|
+
const HALF_HEX_CHARS = 32;
|
|
47
|
+
/** 随机半段的字节数(16 字节 = 32 位十六进制)。 */
|
|
48
|
+
const RANDOM_BYTES = HALF_HEX_CHARS / 2;
|
|
49
|
+
/** 身份戳的**唯一拼写**:`<32 位小写十六进制摘要>.<32 位小写十六进制随机>`。无旗标(`.test` 无状态,可共享这一只)。 */
|
|
50
|
+
export const A2A_PEER_FINGERPRINT_RE = /^[0-9a-f]{32}\.[0-9a-f]{32}$/;
|
|
51
|
+
/** {@link A2A_PEER_FINGERPRINT_RE} 作 schema —— 条目上装戳的两个座位(`fingerprint`、`preApprovedFor`)都引它。 */
|
|
52
|
+
export const A2aPeerFingerprint = z.string().regex(A2A_PEER_FINGERPRINT_RE, "an a2a peer identity stamp is <32 lowercase hex digest>.<32 lowercase hex random>, minted by mintA2aPeerFingerprint");
|
|
53
|
+
/** 摘要输入的域分隔前缀:让这一只摘要与别处对同一串算的 SHA-256 对不上;身份字段的覆盖面若要改,换这个前缀里的版本。 */
|
|
54
|
+
const FINGERPRINT_DIGEST_DOMAIN = "sema-settings-schema/a2a-peer-fingerprint/v1\u0000";
|
|
55
|
+
/**
|
|
56
|
+
* **复算摘要**(只此一只,铸戳与条目判的 `fingerprint_stale` 同读):一条条目身份字段的摘要半段 —— 覆盖哪几个字段见模块头,别处不复述。
|
|
57
|
+
* 纯函数:同输入同答,不读身份字段以外的任何键。
|
|
58
|
+
*/
|
|
59
|
+
export function a2aPeerFingerprintDigest(peer) {
|
|
60
|
+
const identity = { url: peer.url, cardUrl: peer.cardUrl ?? null, ownerTeam: peer.ownerTeam ?? null, boundary: a2aPeerBoundaryOf(peer) };
|
|
61
|
+
return sha256Hex(`${FINGERPRINT_DIGEST_DOMAIN}${stableStringify(identity)}`).slice(0, HALF_HEX_CHARS);
|
|
62
|
+
}
|
|
63
|
+
/** 一枚戳的摘要半段 —— 拼写合法 ⇒ 点号前那 32 位;不合法 ⇒ `undefined`。包私有(不进包根):铸戳与条目判同读这一只。 */
|
|
64
|
+
function fingerprintDigestHalf(stamp) {
|
|
65
|
+
return typeof stamp === "string" && A2A_PEER_FINGERPRINT_RE.test(stamp) ? stamp.slice(0, HALF_HEX_CHARS) : undefined;
|
|
66
|
+
}
|
|
67
|
+
/** 随机半段 —— 只取运行时的 Web Crypto;取不到 ⇒ 抛(从不退回更弱的随机)。 */
|
|
68
|
+
function randomHalf() {
|
|
69
|
+
const source = globalThis.crypto?.getRandomValues;
|
|
70
|
+
if (typeof source !== "function") {
|
|
71
|
+
throw new Error("mintA2aPeerFingerprint: this runtime has no Web Crypto random source (globalThis.crypto.getRandomValues) — an identity stamp is never minted from a weaker one");
|
|
72
|
+
}
|
|
73
|
+
return toHex(globalThis.crypto.getRandomValues(new Uint8Array(RANDOM_BYTES)));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* **铸戳**(只此一只):写一条条目时,它该带哪一枚戳。`next` = 这次要存的条目,`prev` = 存着的同一条(由 {@link pairA2aPeers} 配出;新建时缺席)。
|
|
77
|
+
*
|
|
78
|
+
* 一条律:**`prev` 的戳就是 `next` 的身份的那一枚时原样交回,否则铸一枚新的** —— 「就是」= `prev` 带着一枚拼写合法的戳,它的摘要半段等于
|
|
79
|
+
* `prev` 自己身份字段的复算摘要,也等于 `next` 的。于是:新建 ⇒ 新戳;任一身份字段变 ⇒ 新戳;改走再改回 ⇒ 又一枚新的(上一版是改走后的身份,
|
|
80
|
+
* 改走之前那一枚从不复用);上一版没有戳、或它的戳与它自己的身份字段对不上(手改过文件)⇒ 新戳;只改非身份字段 ⇒ 原戳。
|
|
81
|
+
* `next.fingerprint` 从不被读:调用方自己带来的戳不算数(写口不许让调用方给自己铸戳)。
|
|
82
|
+
*/
|
|
83
|
+
export function mintA2aPeerFingerprint(next, prev) {
|
|
84
|
+
const digest = a2aPeerFingerprintDigest(next);
|
|
85
|
+
if (prev !== undefined && fingerprintDigestHalf(prev.fingerprint) === digest && a2aPeerFingerprintDigest(prev) === digest)
|
|
86
|
+
return prev.fingerprint;
|
|
87
|
+
return `${digest}.${randomHalf()}`;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 一条条目的**问题词**闭集:引擎原语包的登记问题词(原序展开,本包不手抄)+ 尾插本包两词 —— `fingerprint_stale`(内部条目的戳摘要半段与它的身份字段
|
|
91
|
+
* 对不上:身份改过而戳没换)、`id_missing`(内部条目没有 `id`:读口、审计与配对按它认条目)。型由它派生。被丢条目的行
|
|
92
|
+
* ({@link DroppedEntry} 的 `registrationProblems`)与告警读的是这张表。
|
|
93
|
+
*/
|
|
94
|
+
export const A2A_PEER_ENTRY_PROBLEMS = deepFreeze([...A2A_REGISTRATION_PROBLEMS, "fingerprint_stale", "id_missing"]);
|
|
95
|
+
/** 一个词是不是条目问题词(闭集成员判)。 */
|
|
96
|
+
function isA2aPeerEntryProblem(v) {
|
|
97
|
+
return typeof v === "string" && A2A_PEER_ENTRY_PROBLEMS.includes(v);
|
|
98
|
+
}
|
|
99
|
+
/** 每个问题词点到条目的哪一只成员(写面 issue 的坐标)。穷举(闭集每个词一行,少一行 ⇒ 编译红)。包私有。 */
|
|
100
|
+
export const A2A_PEER_ENTRY_PROBLEM_MEMBER = deepFreeze({
|
|
101
|
+
boundary_unreadable: "boundary",
|
|
102
|
+
fingerprint_unreadable: "fingerprint",
|
|
103
|
+
display_name_unreadable: "displayName",
|
|
104
|
+
owner_team_unreadable: "ownerTeam",
|
|
105
|
+
fingerprint_missing: "fingerprint",
|
|
106
|
+
allow_skills_missing: "allowSkills",
|
|
107
|
+
principal_header_missing: "principalHeader",
|
|
108
|
+
owner_team_missing: "ownerTeam",
|
|
109
|
+
url_plaintext: "url",
|
|
110
|
+
card_url_plaintext: "cardUrl",
|
|
111
|
+
fingerprint_stale: "fingerprint",
|
|
112
|
+
id_missing: "id",
|
|
113
|
+
});
|
|
114
|
+
/**
|
|
115
|
+
* 条目判的**判法**(包私有;只由 `./types` 的 `A2aPeerSpec` 调,读方经那只 schema 问,不另调它):一条成员形已过的条目有哪些问题词,每个词一次、
|
|
116
|
+
* 按 {@link A2A_PEER_ENTRY_PROBLEMS} 的序;`[]` = 这一条可以生效。原语包的判官原样问(它自己只对 `boundary: "inside"` 问 `inside` 组);本包两词
|
|
117
|
+
* 只问内部条目(放宽只落在内部条目上;外部条目的戳只被比较,不放行任何东西)。戳缺席或拼写不合法不在 `fingerprint_stale` 这一格(拼写由成员形判,
|
|
118
|
+
* 缺席由原语包的 `fingerprint_missing` 判)。
|
|
119
|
+
*/
|
|
120
|
+
export function a2aPeerEntryProblems(peer) {
|
|
121
|
+
const found = new Set(a2aRegistrationProblems(peer));
|
|
122
|
+
if (a2aPeerBoundaryOf(peer) === "inside") {
|
|
123
|
+
const held = fingerprintDigestHalf(peer.fingerprint);
|
|
124
|
+
if (held !== undefined && held !== a2aPeerFingerprintDigest(peer))
|
|
125
|
+
found.add("fingerprint_stale");
|
|
126
|
+
if (peer.id === undefined)
|
|
127
|
+
found.add("id_missing");
|
|
128
|
+
}
|
|
129
|
+
return A2A_PEER_ENTRY_PROBLEMS.filter((w) => found.has(w));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 一次被拒判决里的问题词(包私有;逐条丢弃的判决点调它):`issues` 非空且**每一条**都是带问题词(`params.flaw`)的自铸 issue ⇒ 词表(每个词一次、
|
|
133
|
+
* 闭集序);有任何一条别的 issue(成员形错、别的判官)⇒ `undefined` —— 成员形先于完备性,那一条记成员形的丢法。只读结构化参数,不读句子、不重判。
|
|
134
|
+
*/
|
|
135
|
+
export function registrationProblemsOf(issues) {
|
|
136
|
+
if (issues.length === 0)
|
|
137
|
+
return undefined;
|
|
138
|
+
const found = new Set();
|
|
139
|
+
for (const issue of issues) {
|
|
140
|
+
if (issue.code !== "custom")
|
|
141
|
+
return undefined;
|
|
142
|
+
const flaw = issue.params?.flaw;
|
|
143
|
+
if (!isA2aPeerEntryProblem(flaw))
|
|
144
|
+
return undefined;
|
|
145
|
+
found.add(flaw);
|
|
146
|
+
}
|
|
147
|
+
return A2A_PEER_ENTRY_PROBLEMS.filter((w) => found.has(w));
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* **配对**(只此一只):提交的名册 `after` 里每一条是存量 `before` 里的哪一条。铸戳({@link mintA2aPeerFingerprint} 的 `prev`)与写角色同读这一只,
|
|
151
|
+
* 不各自按名配。两趟、确定性:
|
|
152
|
+
* ① 只按 `id` 配:提交条目带 `id`、存量里有同 `id` 且还没被占的那一条(文档序第一条)。
|
|
153
|
+
* ② 只在第一趟没配上的提交条目与没被占的存量之间按名配(文档序第一条);**两边都带 `id` 且不相等 ⇒ 不配**(`id` 变了就是另一条:新建 + 删除)。
|
|
154
|
+
* 一条存量至多被配一次,由两趟共用的「已占」集合保证,不靠域判的名唯一 / `id` 唯一(名册读进来时那两道域判本来就成立;这里不假设它)。
|
|
155
|
+
* 只读 `name` / `id`;答案里的 `prev` / `next` 是入参里的同一个对象。
|
|
156
|
+
*/
|
|
157
|
+
export function pairA2aPeers(before, after) {
|
|
158
|
+
const taken = new Set();
|
|
159
|
+
const matched = after.map(() => undefined);
|
|
160
|
+
const claim = (i, accepts) => {
|
|
161
|
+
const j = before.findIndex((prev, k) => !taken.has(k) && accepts(prev));
|
|
162
|
+
if (j < 0)
|
|
163
|
+
return;
|
|
164
|
+
taken.add(j);
|
|
165
|
+
matched[i] = j;
|
|
166
|
+
};
|
|
167
|
+
after.forEach((next, i) => {
|
|
168
|
+
if (next.id !== undefined)
|
|
169
|
+
claim(i, (prev) => prev.id === next.id);
|
|
170
|
+
});
|
|
171
|
+
after.forEach((next, i) => {
|
|
172
|
+
if (matched[i] === undefined)
|
|
173
|
+
claim(i, (prev) => prev.name === next.name && !(prev.id !== undefined && next.id !== undefined && prev.id !== next.id));
|
|
174
|
+
});
|
|
175
|
+
return {
|
|
176
|
+
pairs: after.map((next, i) => {
|
|
177
|
+
const j = matched[i];
|
|
178
|
+
return j === undefined ? { next } : { next, prev: before[j] };
|
|
179
|
+
}),
|
|
180
|
+
removed: before.filter((_, k) => !taken.has(k)),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
* 取值口的另两种凭据(`model` / `mcp_static`)的请求与应答形不在本模块;它们落地时与本模块的 `sandbox_git` 形并成按 `kind` 判别的联合,
|
|
9
9
|
* 本模块的形不动(`kind` 字面量已经在)。
|
|
10
10
|
*
|
|
11
|
-
* ##
|
|
11
|
+
* ## 词表:每个词的行(状态集与 `permanence`)只在本文件里写一次
|
|
12
12
|
* · {@link SANDBOX_GIT_ORIGIN_VERDICTS} —— **逐 origin 判定序表**,11 行,序即判定序(首条命中即答;一个 origin 的结果不影响别的 origin)。
|
|
13
13
|
* 状态词({@link SANDBOX_GIT_ORIGIN_STATES},六个)与原因词({@link SANDBOX_GIT_ORIGIN_REASONS},十个)由它派生,没有第二张词表;`active` 行没有原因。
|
|
14
14
|
* 应答行({@link SandboxGitOriginAnswer})每个状态一个臂,臂里 `reason` 的值域 = 表里该状态的行 —— 状态与原因的配对由表定,臂不手写。
|
|
15
15
|
* 每一行的**条件**(什么事实使它命中)是 web-admin 的判定逻辑,写在 `docs/CONSUMER-INTEGRATION.md` 里,不进运行期表。
|
|
16
|
-
* · {@link
|
|
16
|
+
* · {@link CREDENTIAL_PLANE_REFUSALS} —— 凭据平面共享拒答表(九个词;同一平面的各只口从它派生,每个词的状态集与 `permanence` 只在这里写一次)。
|
|
17
|
+
* · {@link SANDBOX_GIT_REFUSALS} —— 整次拒答词(十一个)→ HTTP 状态集与 `permanence`,由凭据平面共享表 {@link CREDENTIAL_PLANE_REFUSALS}(九个)与本口自有的两个词按声明的次序派生(上一版的十个词原序、新词只在尾部);拒体里的 `permanence` 是错误词的函数,必须等于这一行的。
|
|
17
18
|
* · {@link SANDBOX_GIT_PERMANENCE} —— `terminal`(不按定时重试)/ `transient`(退避重试)两词,语义在本表定义。
|
|
18
19
|
*
|
|
19
20
|
* ## 解析一律剥未知键
|
|
@@ -208,18 +209,15 @@ export type SandboxGitCredentialAnswer = z.infer<typeof SandboxGitCredentialAnsw
|
|
|
208
209
|
export declare const SANDBOX_GIT_PERMANENCE: readonly ["terminal", "transient"];
|
|
209
210
|
export type SandboxGitPermanence = (typeof SANDBOX_GIT_PERMANENCE)[number];
|
|
210
211
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
212
|
+
* 凭据平面共享拒答表(九个词):同一凭据平面的各只口都从它派生(`sandbox_git` 凭据取值口如此,同一平面的后续取值口同样如此),
|
|
213
|
+
* 每个词的 HTTP 状态集与 `permanence` 只在这里写一次。
|
|
214
|
+
* `plane_misconfigured` = 凭据平面在答方配置错 —— `terminal`,按定时重试不会成功,必须由运维修正配置。
|
|
213
215
|
*/
|
|
214
|
-
export declare const
|
|
216
|
+
export declare const CREDENTIAL_PLANE_REFUSALS: {
|
|
215
217
|
readonly caller_not_admitted: {
|
|
216
218
|
readonly statuses: readonly [401, 403];
|
|
217
219
|
readonly permanence: "terminal";
|
|
218
220
|
};
|
|
219
|
-
readonly scope_mismatch: {
|
|
220
|
-
readonly statuses: readonly [403];
|
|
221
|
-
readonly permanence: "terminal";
|
|
222
|
-
};
|
|
223
221
|
readonly incarnation_mismatch: {
|
|
224
222
|
readonly statuses: readonly [403];
|
|
225
223
|
readonly permanence: "terminal";
|
|
@@ -244,32 +242,114 @@ export declare const SANDBOX_GIT_REFUSALS: {
|
|
|
244
242
|
readonly statuses: readonly [503];
|
|
245
243
|
readonly permanence: "terminal";
|
|
246
244
|
};
|
|
245
|
+
readonly vault_unavailable: {
|
|
246
|
+
readonly statuses: readonly [503];
|
|
247
|
+
readonly permanence: "transient";
|
|
248
|
+
};
|
|
249
|
+
readonly plane_misconfigured: {
|
|
250
|
+
readonly statuses: readonly [503];
|
|
251
|
+
readonly permanence: "terminal";
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
/** 凭据平面共享拒答词(闭集,九个)—— 类型由 {@link CREDENTIAL_PLANE_REFUSALS} 派生。 */
|
|
255
|
+
export type CredentialPlaneRefusalError = keyof typeof CREDENTIAL_PLANE_REFUSALS;
|
|
256
|
+
/** 凭据平面共享拒答词表(运行期;表的键,按表序)。 */
|
|
257
|
+
export declare const CREDENTIAL_PLANE_REFUSAL_ERRORS: readonly [CredentialPlaneRefusalError, ...CredentialPlaneRefusalError[]];
|
|
258
|
+
declare const SANDBOX_GIT_OWN_REFUSALS: {
|
|
259
|
+
readonly scope_mismatch: {
|
|
260
|
+
readonly statuses: readonly [403];
|
|
261
|
+
readonly permanence: "terminal";
|
|
262
|
+
};
|
|
247
263
|
readonly handle_invalid: {
|
|
248
264
|
readonly statuses: readonly [401];
|
|
249
265
|
readonly permanence: "transient";
|
|
250
266
|
};
|
|
251
|
-
|
|
267
|
+
};
|
|
268
|
+
/** 上一版的十个词保持原序,新词只追加在尾部 —— 调整既有词的次序是破坏性变更。 */
|
|
269
|
+
declare const SANDBOX_GIT_REFUSAL_ORDER: readonly ["caller_not_admitted", "scope_mismatch", "incarnation_mismatch", "request_invalid", "principal_not_live", "delegation_required", "vault_disabled", "vault_frozen", "handle_invalid", "vault_unavailable", "plane_misconfigured"];
|
|
270
|
+
type SandboxGitRefusalWord = (typeof SANDBOX_GIT_REFUSAL_ORDER)[number];
|
|
271
|
+
type SandboxGitRefusalSource = CredentialPlaneRefusalError | keyof typeof SANDBOX_GIT_OWN_REFUSALS;
|
|
272
|
+
/** 编译期核对,只在类型层(不留运行期语句):`T` 必须是 `true`,否则这一行编译即红。 */
|
|
273
|
+
type MustBeTrue<T extends true> = T;
|
|
274
|
+
/**
|
|
275
|
+
* 次序表与两张来源表「恰好」互为全集:来源里每个词都在次序表里(漏一个红)、次序表里每个词都在来源里(写进不存在的词红)、
|
|
276
|
+
* 共享表与自有表没有同名的词(重名红)。下面 `SANDBOX_GIT_REFUSALS` 的类型用到它,所以不成立 ⇒ 编译红。
|
|
277
|
+
*/
|
|
278
|
+
type SandboxGitRefusalOrderIsExact = MustBeTrue<[
|
|
279
|
+
Exclude<SandboxGitRefusalSource, SandboxGitRefusalWord>,
|
|
280
|
+
Exclude<SandboxGitRefusalWord, SandboxGitRefusalSource>,
|
|
281
|
+
Extract<CredentialPlaneRefusalError, keyof typeof SANDBOX_GIT_OWN_REFUSALS>
|
|
282
|
+
] extends [never, never, never] ? true : false>;
|
|
283
|
+
declare const SANDBOX_GIT_REFUSAL_ROWS: {
|
|
284
|
+
scope_mismatch: {
|
|
285
|
+
readonly statuses: readonly [403];
|
|
286
|
+
readonly permanence: "terminal";
|
|
287
|
+
};
|
|
288
|
+
handle_invalid: {
|
|
289
|
+
readonly statuses: readonly [401];
|
|
290
|
+
readonly permanence: "transient";
|
|
291
|
+
};
|
|
292
|
+
caller_not_admitted: {
|
|
293
|
+
readonly statuses: readonly [401, 403];
|
|
294
|
+
readonly permanence: "terminal";
|
|
295
|
+
};
|
|
296
|
+
incarnation_mismatch: {
|
|
297
|
+
readonly statuses: readonly [403];
|
|
298
|
+
readonly permanence: "terminal";
|
|
299
|
+
};
|
|
300
|
+
request_invalid: {
|
|
301
|
+
readonly statuses: readonly [400];
|
|
302
|
+
readonly permanence: "terminal";
|
|
303
|
+
};
|
|
304
|
+
principal_not_live: {
|
|
305
|
+
readonly statuses: readonly [403];
|
|
306
|
+
readonly permanence: "terminal";
|
|
307
|
+
};
|
|
308
|
+
delegation_required: {
|
|
309
|
+
readonly statuses: readonly [403];
|
|
310
|
+
readonly permanence: "terminal";
|
|
311
|
+
};
|
|
312
|
+
vault_disabled: {
|
|
313
|
+
readonly statuses: readonly [503];
|
|
314
|
+
readonly permanence: "terminal";
|
|
315
|
+
};
|
|
316
|
+
vault_frozen: {
|
|
317
|
+
readonly statuses: readonly [503];
|
|
318
|
+
readonly permanence: "terminal";
|
|
319
|
+
};
|
|
320
|
+
vault_unavailable: {
|
|
252
321
|
readonly statuses: readonly [503];
|
|
253
322
|
readonly permanence: "transient";
|
|
254
323
|
};
|
|
324
|
+
plane_misconfigured: {
|
|
325
|
+
readonly statuses: readonly [503];
|
|
326
|
+
readonly permanence: "terminal";
|
|
327
|
+
};
|
|
255
328
|
};
|
|
256
|
-
/**
|
|
329
|
+
/**
|
|
330
|
+
* 整次拒答词 → 它的 HTTP 状态集(中心答这个词时用其一)与 `permanence`。**一个错误词的 permanence 是固定的**,拒体里再带一份只为让收方不必查表 ——
|
|
331
|
+
* 两处不一致就是畸形应答({@link SandboxGitCredentialRefusal} 拒)。收方怎么处置某个词(例如哪些 terminal 可由用户动作恢复)是收方的状态机,不在这里。
|
|
332
|
+
* 表由 {@link CREDENTIAL_PLANE_REFUSALS} 与本口自有两词按声明的次序派生(复用同一行对象,不抄行)。
|
|
333
|
+
*/
|
|
334
|
+
export declare const SANDBOX_GIT_REFUSALS: { readonly [W in SandboxGitRefusalOrderIsExact extends true ? SandboxGitRefusalWord : never]: (typeof SANDBOX_GIT_REFUSAL_ROWS)[W]; };
|
|
335
|
+
/** 整次拒答词(闭集,十一个)—— 类型由 {@link SANDBOX_GIT_REFUSALS} 派生,次序来自声明的次序。 */
|
|
257
336
|
export type SandboxGitRefusalError = keyof typeof SANDBOX_GIT_REFUSALS;
|
|
258
|
-
/** 整次拒答词表(
|
|
337
|
+
/** 整次拒答词表(运行期;表的键,按声明的次序)。 */
|
|
259
338
|
export declare const SANDBOX_GIT_REFUSAL_ERRORS: readonly [SandboxGitRefusalError, ...SandboxGitRefusalError[]];
|
|
260
339
|
/** 整次拒答的体:`{ error, permanence, message }`。`message` 是中心的诊断句(收方不据它判,可为空串)。 */
|
|
261
340
|
export declare const SandboxGitCredentialRefusal: z.ZodObject<{
|
|
262
341
|
error: z.ZodEnum<{
|
|
263
342
|
caller_not_admitted: "caller_not_admitted";
|
|
264
|
-
scope_mismatch: "scope_mismatch";
|
|
265
343
|
incarnation_mismatch: "incarnation_mismatch";
|
|
266
344
|
request_invalid: "request_invalid";
|
|
267
345
|
principal_not_live: "principal_not_live";
|
|
268
346
|
delegation_required: "delegation_required";
|
|
269
347
|
vault_disabled: "vault_disabled";
|
|
270
348
|
vault_frozen: "vault_frozen";
|
|
271
|
-
handle_invalid: "handle_invalid";
|
|
272
349
|
vault_unavailable: "vault_unavailable";
|
|
350
|
+
plane_misconfigured: "plane_misconfigured";
|
|
351
|
+
scope_mismatch: "scope_mismatch";
|
|
352
|
+
handle_invalid: "handle_invalid";
|
|
273
353
|
}>;
|
|
274
354
|
permanence: z.ZodEnum<{
|
|
275
355
|
terminal: "terminal";
|
package/dist/api/credentials.js
CHANGED
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
* 取值口的另两种凭据(`model` / `mcp_static`)的请求与应答形不在本模块;它们落地时与本模块的 `sandbox_git` 形并成按 `kind` 判别的联合,
|
|
9
9
|
* 本模块的形不动(`kind` 字面量已经在)。
|
|
10
10
|
*
|
|
11
|
-
* ##
|
|
11
|
+
* ## 词表:每个词的行(状态集与 `permanence`)只在本文件里写一次
|
|
12
12
|
* · {@link SANDBOX_GIT_ORIGIN_VERDICTS} —— **逐 origin 判定序表**,11 行,序即判定序(首条命中即答;一个 origin 的结果不影响别的 origin)。
|
|
13
13
|
* 状态词({@link SANDBOX_GIT_ORIGIN_STATES},六个)与原因词({@link SANDBOX_GIT_ORIGIN_REASONS},十个)由它派生,没有第二张词表;`active` 行没有原因。
|
|
14
14
|
* 应答行({@link SandboxGitOriginAnswer})每个状态一个臂,臂里 `reason` 的值域 = 表里该状态的行 —— 状态与原因的配对由表定,臂不手写。
|
|
15
15
|
* 每一行的**条件**(什么事实使它命中)是 web-admin 的判定逻辑,写在 `docs/CONSUMER-INTEGRATION.md` 里,不进运行期表。
|
|
16
|
-
* · {@link
|
|
16
|
+
* · {@link CREDENTIAL_PLANE_REFUSALS} —— 凭据平面共享拒答表(九个词;同一平面的各只口从它派生,每个词的状态集与 `permanence` 只在这里写一次)。
|
|
17
|
+
* · {@link SANDBOX_GIT_REFUSALS} —— 整次拒答词(十一个)→ HTTP 状态集与 `permanence`,由凭据平面共享表 {@link CREDENTIAL_PLANE_REFUSALS}(九个)与本口自有的两个词按声明的次序派生(上一版的十个词原序、新词只在尾部);拒体里的 `permanence` 是错误词的函数,必须等于这一行的。
|
|
17
18
|
* · {@link SANDBOX_GIT_PERMANENCE} —— `terminal`(不按定时重试)/ `transient`(退避重试)两词,语义在本表定义。
|
|
18
19
|
*
|
|
19
20
|
* ## 解析一律剥未知键
|
|
@@ -121,22 +122,46 @@ export const SandboxGitCredentialAnswer = z.object({
|
|
|
121
122
|
/** `permanence` 两词:`terminal` = 不按定时重试;`transient` = 退避重试。 */
|
|
122
123
|
export const SANDBOX_GIT_PERMANENCE = deepFreeze(["terminal", "transient"]);
|
|
123
124
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
125
|
+
* 凭据平面共享拒答表(九个词):同一凭据平面的各只口都从它派生(`sandbox_git` 凭据取值口如此,同一平面的后续取值口同样如此),
|
|
126
|
+
* 每个词的 HTTP 状态集与 `permanence` 只在这里写一次。
|
|
127
|
+
* `plane_misconfigured` = 凭据平面在答方配置错 —— `terminal`,按定时重试不会成功,必须由运维修正配置。
|
|
126
128
|
*/
|
|
127
|
-
export const
|
|
129
|
+
export const CREDENTIAL_PLANE_REFUSALS = deepFreeze({
|
|
128
130
|
caller_not_admitted: { statuses: [401, 403], permanence: "terminal" },
|
|
129
|
-
scope_mismatch: { statuses: [403], permanence: "terminal" },
|
|
130
131
|
incarnation_mismatch: { statuses: [403], permanence: "terminal" },
|
|
131
132
|
request_invalid: { statuses: [400], permanence: "terminal" },
|
|
132
133
|
principal_not_live: { statuses: [403], permanence: "terminal" },
|
|
133
134
|
delegation_required: { statuses: [403], permanence: "terminal" },
|
|
134
135
|
vault_disabled: { statuses: [503], permanence: "terminal" },
|
|
135
136
|
vault_frozen: { statuses: [503], permanence: "terminal" },
|
|
136
|
-
handle_invalid: { statuses: [401], permanence: "transient" },
|
|
137
137
|
vault_unavailable: { statuses: [503], permanence: "transient" },
|
|
138
|
+
plane_misconfigured: { statuses: [503], permanence: "terminal" },
|
|
139
|
+
});
|
|
140
|
+
/** 凭据平面共享拒答词表(运行期;表的键,按表序)。 */
|
|
141
|
+
export const CREDENTIAL_PLANE_REFUSAL_ERRORS = deepFreeze(Object.keys(CREDENTIAL_PLANE_REFUSALS));
|
|
142
|
+
const SANDBOX_GIT_OWN_REFUSALS = deepFreeze({
|
|
143
|
+
scope_mismatch: { statuses: [403], permanence: "terminal" },
|
|
144
|
+
handle_invalid: { statuses: [401], permanence: "transient" },
|
|
138
145
|
});
|
|
139
|
-
/**
|
|
146
|
+
/** 同一个词写了两遍 ⇒ 模块加载即抛(次序表是公开事实,重复的词会让派生表静默少一行)。原样交回入参(元组类型不丢)。 */
|
|
147
|
+
function wordsListedOnce(words) {
|
|
148
|
+
if (new Set(words).size !== words.length)
|
|
149
|
+
throw new Error("SANDBOX_GIT_REFUSAL_ORDER lists a word twice");
|
|
150
|
+
return words;
|
|
151
|
+
}
|
|
152
|
+
/** 上一版的十个词保持原序,新词只追加在尾部 —— 调整既有词的次序是破坏性变更。 */
|
|
153
|
+
const SANDBOX_GIT_REFUSAL_ORDER = wordsListedOnce([
|
|
154
|
+
"caller_not_admitted", "scope_mismatch", "incarnation_mismatch", "request_invalid", "principal_not_live",
|
|
155
|
+
"delegation_required", "vault_disabled", "vault_frozen", "handle_invalid", "vault_unavailable", "plane_misconfigured",
|
|
156
|
+
]);
|
|
157
|
+
const SANDBOX_GIT_REFUSAL_ROWS = { ...CREDENTIAL_PLANE_REFUSALS, ...SANDBOX_GIT_OWN_REFUSALS };
|
|
158
|
+
/**
|
|
159
|
+
* 整次拒答词 → 它的 HTTP 状态集(中心答这个词时用其一)与 `permanence`。**一个错误词的 permanence 是固定的**,拒体里再带一份只为让收方不必查表 ——
|
|
160
|
+
* 两处不一致就是畸形应答({@link SandboxGitCredentialRefusal} 拒)。收方怎么处置某个词(例如哪些 terminal 可由用户动作恢复)是收方的状态机,不在这里。
|
|
161
|
+
* 表由 {@link CREDENTIAL_PLANE_REFUSALS} 与本口自有两词按声明的次序派生(复用同一行对象,不抄行)。
|
|
162
|
+
*/
|
|
163
|
+
export const SANDBOX_GIT_REFUSALS = deepFreeze(Object.fromEntries(SANDBOX_GIT_REFUSAL_ORDER.map((w) => [w, SANDBOX_GIT_REFUSAL_ROWS[w]])));
|
|
164
|
+
/** 整次拒答词表(运行期;表的键,按声明的次序)。 */
|
|
140
165
|
export const SANDBOX_GIT_REFUSAL_ERRORS = deepFreeze(Object.keys(SANDBOX_GIT_REFUSALS));
|
|
141
166
|
/** 整次拒答的体:`{ error, permanence, message }`。`message` 是中心的诊断句(收方不据它判,可为空串)。 */
|
|
142
167
|
export const SandboxGitCredentialRefusal = z
|
package/dist/atomic-write.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ConfigDocumentIoKind } from "./config-document-refusal.js";
|
|
1
2
|
/** 按文档类的模式表(闭集)。 */
|
|
2
3
|
export declare const ATOMIC_FILE_CLASSES: {
|
|
3
4
|
readonly "config-document": {
|
|
@@ -13,9 +14,10 @@ export type AtomicFileClass = keyof typeof ATOMIC_FILE_CLASSES;
|
|
|
13
14
|
/** 悬空符号链接的**唯一一句**(写器与目录迁移的读口抛同一句;不带 errno 码 —— 带了 `ENOENT` 的错会被「ENOENT = 缺席」的读者读成文件不在,
|
|
14
15
|
* 悬空链接恰恰不是缺席)。 */
|
|
15
16
|
export declare function danglingSymlinkSentence(link: string, pointsAt: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* `
|
|
18
|
-
|
|
17
|
+
/** `io` 拒的类词 —— **唯一铸点**(31.1.0;随凭据锁同读挪到本文件,与它判的悬空链接判官同处):抛出物是本包悬空链接判官抛的那只错(按对象身份问 {@link isDanglingSymlinkError})⇒ 悬空;其余一切抛出物(系统错、运行时自己抛的错、抛出的不是 `Error` 的值)⇒ `read_error` —— 这个词只说「读那一下抛了错、而且不是悬空判官抛的」,不说「是操作系统给的」。
|
|
18
|
+
* 按抛出物的**身份**判,不读句子(句子是给人看的,措辞可以改;句子一样的别的错也不算)。两处问它:读 `config.d` 文档的 `io` 拒(`./config-d-file`)与凭据锁在「解凭证路径」那一步失败的 `unreadable`({@link tryWebAdminCredentialFileLock})——
|
|
19
|
+
* 都对**原始抛出物**问(包装后的 {@link FsFailure} 不在悬空登记里,会被判成 `read_error`)。包内,不出任何子路径。 */
|
|
20
|
+
export declare function configDocumentIoKindOf(thrown: unknown): ConfigDocumentIoKind;
|
|
19
21
|
/** 读写的真目标 —— **一只判法**(写器与目录迁移的读口共用):`target` 是符号链接 ⇒ 解析到它指向的真文件(悬空 ⇒ 抛 {@link danglingSymlinkSentence} 那一句,并登记进 {@link DANGLING_SYMLINK_ERRORS});
|
|
20
22
|
* 不是链接或不存在 ⇒ 原样(不存在的由调用方的读 / 写照常报)。 */
|
|
21
23
|
export declare function resolveSymlinkTarget(target: string): string;
|
|
@@ -94,6 +96,9 @@ export interface WebAdminCredentialLockHeld {
|
|
|
94
96
|
* 之后的都答 `false`、没落 —— 写没写成由回调自己记下那两只方法的答案(放进 `value`),不要从 `lost` 推「没写成」。
|
|
95
97
|
* · `busy` —— 别人持着新鲜的锁(或 mtime 在未来),回调没跑。`heldForMs` = 那只锁的年龄(读到了且不在未来才有)。
|
|
96
98
|
* · `unreadable` —— 锁建不出 / 看不了 / 收不了,或锁内读不了真目标;回调没跑,什么都没写。`error.message` 是包里的文件系统失败句,errno 在 `error.code`。
|
|
99
|
+
* 可缺的诊断位 `ioKind`:**只在「解凭证路径」那一步失败时在场** —— 值按抛出物的身份铸({@link configDocumentIoKindOf},对原始抛出物问、不读句子):是本包悬空链接判官抛的 ⇒ `dangling_symlink`
|
|
100
|
+
* (凭证路径经软链到达、链接在而目标不在;出路 = 删掉悬空链接,或先重建目标),其余 ⇒ `read_error`(权限、成环的链接、路径上有一节不是目录 ……);别的 `unreadable`(锁建不出 / 锁名被占 /
|
|
101
|
+
* 锁内读不了真目标)不带这一键 —— 键不在场,不是 `undefined`。状态、回调跑不跑、文件副作用与有没有这一键无关。
|
|
97
102
|
*/
|
|
98
103
|
export type WebAdminCredentialLockOutcome<T> = {
|
|
99
104
|
readonly status: "acquired";
|
|
@@ -107,6 +112,7 @@ export type WebAdminCredentialLockOutcome<T> = {
|
|
|
107
112
|
} | {
|
|
108
113
|
readonly status: "unreadable";
|
|
109
114
|
readonly error: Error;
|
|
115
|
+
readonly ioKind?: ConfigDocumentIoKind;
|
|
110
116
|
};
|
|
111
117
|
/**
|
|
112
118
|
* 在 web-admin 凭证文件的单写者锁里跑一次「读 → 比较 → 写」(规则与锁的形见文件头同名一节)。只试一次,从不等待:忙 ⇒ `busy`,调用方按自己的退避再来。
|