@eosway/lodestar-spec 0.0.0-stage → 0.1.0-rc.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/LICENSE +201 -0
- package/README.md +2 -2
- package/dist/index.d.ts +246 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +387 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas/binding.schema.json +58 -0
- package/dist/schemas/capset.schema.json +106 -0
- package/dist/schemas/tool.schema.json +190 -0
- package/package.json +39 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026-present yangxu52
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @eosway/lodestar-spec
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
零依赖的契约层:JSON Schema、TypeScript 类型、事件名、错误码与状态枚举,是其余所有包的唯一事实来源。
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 任务状态机:18 个状态、5 个策略类、状态迁移表。
|
|
3
|
+
*
|
|
4
|
+
* 约束:状态只能由服务端状态机写入,模型不得直接设置。
|
|
5
|
+
*/
|
|
6
|
+
/** 任务状态,共 18 个。 */
|
|
7
|
+
export declare const TASK_STATUSES: readonly ["Draft", "Created", "Planning", "AwaitingInput", "AwaitingConfirmation", "AwaitingApproval", "Queued", "Running", "AwaitingExternalAction", "Verifying", "PartiallyCompleted", "Compensating", "Paused", "NeedsManualIntervention", "Completed", "Failed", "Cancelled", "Expired"];
|
|
8
|
+
export type TaskStatus = (typeof TASK_STATUSES)[number];
|
|
9
|
+
/** 终态:不可回退,继续操作应新建任务。 */
|
|
10
|
+
export declare const TERMINAL_STATUSES: readonly ["Completed", "Failed", "Cancelled", "Expired"];
|
|
11
|
+
export type TerminalStatus = (typeof TERMINAL_STATUSES)[number];
|
|
12
|
+
/** 策略类:状态到允许工具形态的归并,用于实现与测试。 */
|
|
13
|
+
export declare const POLICY_CLASSES: readonly ["READONLY", "FROZEN", "EXECUTING", "COMPENSATING", "TERMINAL"];
|
|
14
|
+
export type PolicyClass = (typeof POLICY_CLASSES)[number];
|
|
15
|
+
/** 状态归属的策略类,覆盖全部 18 个状态。 */
|
|
16
|
+
export declare const POLICY_CLASS_OF: Record<TaskStatus, PolicyClass>;
|
|
17
|
+
export declare function policyClassOf(status: TaskStatus): PolicyClass;
|
|
18
|
+
export declare function isTerminal(status: TaskStatus): status is TerminalStatus;
|
|
19
|
+
/** 状态迁移表;空数组表示终态。 */
|
|
20
|
+
export declare const TASK_TRANSITIONS: Record<TaskStatus, readonly TaskStatus[]>;
|
|
21
|
+
export declare function canTransition(from: TaskStatus, to: TaskStatus): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 工具形态、能力粒度、风险等级与执行平面。
|
|
24
|
+
*/
|
|
25
|
+
/** 六类工具形态:执行契约的原型,不是语义分类。 */
|
|
26
|
+
export declare const TOOL_KINDS: readonly ["business.query", "business.command", "device.command", "knowledge.retrieve", "ui.navigate", "external.notify"];
|
|
27
|
+
export type ToolKind = (typeof TOOL_KINDS)[number];
|
|
28
|
+
/** 写类形态:必须幂等与审计,R2 起需确认。 */
|
|
29
|
+
export declare const WRITE_TOOL_KINDS: readonly ["business.command", "device.command", "external.notify"];
|
|
30
|
+
export type WriteToolKind = (typeof WRITE_TOOL_KINDS)[number];
|
|
31
|
+
export declare function isWriteKind(kind: ToolKind): kind is WriteToolKind;
|
|
32
|
+
/** 能力粒度:与工具形态正交。C1 不得搭配写类形态。 */
|
|
33
|
+
export declare const GRANULARITIES: readonly ["C1", "C2", "C3"];
|
|
34
|
+
export type Granularity = (typeof GRANULARITIES)[number];
|
|
35
|
+
/** 风险等级:多因子判定的结果,不是单一标签。 */
|
|
36
|
+
export declare const RISK_LEVELS: readonly ["R0", "R1", "R2", "R3", "R4"];
|
|
37
|
+
export type RiskLevel = (typeof RISK_LEVELS)[number];
|
|
38
|
+
/** 需要人工确认的最低风险等级。 */
|
|
39
|
+
export declare const CONFIRMATION_MIN_RISK: RiskLevel;
|
|
40
|
+
/** 执行平面:同一份工具清单,执行位置不同。 */
|
|
41
|
+
export declare const EXECUTION_PLANES: readonly ["backend", "device_gateway", "frontend"];
|
|
42
|
+
export type ExecutionPlane = (typeof EXECUTION_PLANES)[number];
|
|
43
|
+
export declare const DEFAULT_EXECUTION_PLANE: Record<ToolKind, ExecutionPlane>;
|
|
44
|
+
/** 语义通道:由形态推导,仅用于提示词分组、卡片渲染与统计,不参与授权。 */
|
|
45
|
+
export declare const CHANNELS: readonly ["knowledge", "query", "action"];
|
|
46
|
+
export type Channel = (typeof CHANNELS)[number];
|
|
47
|
+
export declare const CHANNEL_OF: Record<ToolKind, Channel>;
|
|
48
|
+
export declare function channelOf(kind: ToolKind): Channel;
|
|
49
|
+
/** 步骤状态:包含执行子态。 */
|
|
50
|
+
export declare const STEP_STATUSES: readonly ["pending", "running", "retry_waiting", "awaiting_callback", "completed", "failed", "skipped"];
|
|
51
|
+
export type StepStatus = (typeof STEP_STATUSES)[number];
|
|
52
|
+
/** 批量项结果。 */
|
|
53
|
+
export declare const BATCH_ITEM_STATUSES: readonly ["succeeded", "failed", "skipped"];
|
|
54
|
+
export type BatchItemStatus = (typeof BATCH_ITEM_STATUSES)[number];
|
|
55
|
+
/** 确认与审批是两个不同对象:前者是发起人动作,后者是业务授权。 */
|
|
56
|
+
export declare const APPROVAL_KINDS: readonly ["confirmation", "approval"];
|
|
57
|
+
export type ApprovalKind = (typeof APPROVAL_KINDS)[number];
|
|
58
|
+
export declare const APPROVAL_DECISIONS: readonly ["approved", "rejected", "expired"];
|
|
59
|
+
export type ApprovalDecision = (typeof APPROVAL_DECISIONS)[number];
|
|
60
|
+
export declare const CONFIRMATION_STRATEGIES: readonly ["single", "dual", "stepUp"];
|
|
61
|
+
export type ConfirmationStrategy = (typeof CONFIRMATION_STRATEGIES)[number];
|
|
62
|
+
/** 可逆性:不可从形态推导。 */
|
|
63
|
+
export declare const REVERSIBILITIES: readonly ["reversible", "compensatable", "irreversible"];
|
|
64
|
+
export type Reversibility = (typeof REVERSIBILITIES)[number];
|
|
65
|
+
/** 审计级别。 */
|
|
66
|
+
export declare const AUDIT_LEVELS: readonly ["none", "basic", "full"];
|
|
67
|
+
export type AuditLevel = (typeof AUDIT_LEVELS)[number];
|
|
68
|
+
/** 绑定层允许的 HTTP 方法。 */
|
|
69
|
+
export declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
70
|
+
export type HttpMethod = (typeof HTTP_METHODS)[number];
|
|
71
|
+
/**
|
|
72
|
+
* 统一错误码与 HTTP 映射。
|
|
73
|
+
*/
|
|
74
|
+
export declare const ERROR_CODES: readonly ["INVALID_ARGUMENT", "NOT_FOUND", "PERMISSION_DENIED", "UPSTREAM_UNAUTHORIZED", "CONFLICT", "PRECONDITION_FAILED", "RATE_LIMITED", "TIMEOUT", "UPSTREAM_UNAVAILABLE", "CONFIRMATION_REQUIRED", "CONFIRMATION_EXPIRED", "IDEMPOTENCY_CONFLICT", "STREAM_GAP", "STEP_LIMIT", "INTERNAL"];
|
|
75
|
+
export type ErrorCode = (typeof ERROR_CODES)[number];
|
|
76
|
+
export declare const ERROR_HTTP_STATUS: Record<ErrorCode, number>;
|
|
77
|
+
/** 可重试错误:读操作可直接重试,写操作默认不重试。 */
|
|
78
|
+
export declare const RETRYABLE_ERROR_CODES: readonly ["CONFLICT", "RATE_LIMITED", "TIMEOUT", "UPSTREAM_UNAVAILABLE"];
|
|
79
|
+
export type RetryableErrorCode = (typeof RETRYABLE_ERROR_CODES)[number];
|
|
80
|
+
export declare function isRetryable(code: ErrorCode): boolean;
|
|
81
|
+
/** 结构化错误体,与成功信封互斥。 */
|
|
82
|
+
export interface ErrorBody {
|
|
83
|
+
code: ErrorCode;
|
|
84
|
+
message: string;
|
|
85
|
+
retryable: boolean;
|
|
86
|
+
details?: Record<string, unknown>;
|
|
87
|
+
}
|
|
88
|
+
export declare function errorBody(code: ErrorCode, message: string, details?: Record<string, unknown>): ErrorBody;
|
|
89
|
+
/**
|
|
90
|
+
* SSE 事件协议。
|
|
91
|
+
*
|
|
92
|
+
* 兼容约束:客户端按空行切分、只取单行 data、把 event: ping 当心跳。
|
|
93
|
+
* 因此每条事件只有一行 data,事件类型放在 JSON 内。
|
|
94
|
+
*/
|
|
95
|
+
export declare const SSE_PROTOCOL_VERSION = 1;
|
|
96
|
+
export declare const SSE_EVENT_TYPES: readonly ["run.start", "message.delta", "message.end", "tool.start", "tool.end", "task.update", "approval.required", "ui.navigate", "error", "run.end"];
|
|
97
|
+
export type SseEventType = (typeof SSE_EVENT_TYPES)[number];
|
|
98
|
+
export interface SseEnvelope<T = unknown> {
|
|
99
|
+
v: typeof SSE_PROTOCOL_VERSION;
|
|
100
|
+
seq: number;
|
|
101
|
+
runId: string;
|
|
102
|
+
taskId?: string;
|
|
103
|
+
type: SseEventType;
|
|
104
|
+
at: string;
|
|
105
|
+
payload: T;
|
|
106
|
+
}
|
|
107
|
+
export interface MessageDeltaPayload {
|
|
108
|
+
text: string;
|
|
109
|
+
}
|
|
110
|
+
export interface ToolStartPayload {
|
|
111
|
+
toolCallId?: string;
|
|
112
|
+
toolName: string;
|
|
113
|
+
kind?: ToolKind;
|
|
114
|
+
argsSummary?: Record<string, unknown>;
|
|
115
|
+
}
|
|
116
|
+
export interface ToolEndPayload {
|
|
117
|
+
toolCallId?: string;
|
|
118
|
+
toolName: string;
|
|
119
|
+
ok: boolean;
|
|
120
|
+
elapsedMs?: number;
|
|
121
|
+
resultSummary?: string;
|
|
122
|
+
}
|
|
123
|
+
export interface TaskUpdatePayload {
|
|
124
|
+
status: TaskStatus;
|
|
125
|
+
statusReason?: string;
|
|
126
|
+
progress?: {
|
|
127
|
+
total: number;
|
|
128
|
+
done: number;
|
|
129
|
+
failed: number;
|
|
130
|
+
skipped: number;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export interface ApprovalRequiredPayload {
|
|
134
|
+
tokenId: string;
|
|
135
|
+
summary: string;
|
|
136
|
+
planVersion: number;
|
|
137
|
+
targetCount?: number;
|
|
138
|
+
expiresAt: string;
|
|
139
|
+
}
|
|
140
|
+
/** 页面跳转指令;由前端执行,运行时只下发。 */
|
|
141
|
+
export interface UiNavigatePayload {
|
|
142
|
+
route: string;
|
|
143
|
+
params?: Record<string, string | number>;
|
|
144
|
+
}
|
|
145
|
+
export interface ErrorPayload {
|
|
146
|
+
code: ErrorCode;
|
|
147
|
+
message: string;
|
|
148
|
+
retryable: boolean;
|
|
149
|
+
}
|
|
150
|
+
export declare const RUN_END_STATUSES: readonly ["completed", "failed", "cancelled", "expired"];
|
|
151
|
+
export type RunEndStatus = (typeof RUN_END_STATUSES)[number];
|
|
152
|
+
export interface RunStartPayload {
|
|
153
|
+
conversationId: string;
|
|
154
|
+
actor?: {
|
|
155
|
+
id: string;
|
|
156
|
+
name?: string;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export interface RunEndPayload {
|
|
160
|
+
status: RunEndStatus;
|
|
161
|
+
answer?: string;
|
|
162
|
+
}
|
|
163
|
+
export interface SsePayloadMap {
|
|
164
|
+
'run.start': RunStartPayload;
|
|
165
|
+
'message.delta': MessageDeltaPayload;
|
|
166
|
+
'message.end': MessageDeltaPayload;
|
|
167
|
+
'tool.start': ToolStartPayload;
|
|
168
|
+
'tool.end': ToolEndPayload;
|
|
169
|
+
'task.update': TaskUpdatePayload;
|
|
170
|
+
'approval.required': ApprovalRequiredPayload;
|
|
171
|
+
'ui.navigate': UiNavigatePayload;
|
|
172
|
+
error: ErrorPayload;
|
|
173
|
+
'run.end': RunEndPayload;
|
|
174
|
+
}
|
|
175
|
+
export type LodestarEvent = { [K in keyof SsePayloadMap]: SseEnvelope<SsePayloadMap[K]> & {
|
|
176
|
+
type: K;
|
|
177
|
+
}; }[keyof SsePayloadMap];
|
|
178
|
+
/** 任务进度:批量场景下的逐项统计。 */
|
|
179
|
+
export interface TaskProgress {
|
|
180
|
+
total: number;
|
|
181
|
+
done: number;
|
|
182
|
+
failed: number;
|
|
183
|
+
skipped: number;
|
|
184
|
+
}
|
|
185
|
+
/** 任务意图:观测字段,不参与授权。 */
|
|
186
|
+
export interface TaskIntent {
|
|
187
|
+
primary: Channel;
|
|
188
|
+
}
|
|
189
|
+
/** 任务记录:产品资产,优先级高于聊天记录。 */
|
|
190
|
+
export interface TaskRecord {
|
|
191
|
+
taskId: string;
|
|
192
|
+
goal: string;
|
|
193
|
+
intent: TaskIntent;
|
|
194
|
+
status: TaskStatus;
|
|
195
|
+
statusReason?: string;
|
|
196
|
+
planVersion: number;
|
|
197
|
+
progress: TaskProgress;
|
|
198
|
+
parentTaskId?: string;
|
|
199
|
+
compensationOf?: string;
|
|
200
|
+
createdBy: string;
|
|
201
|
+
createdAt: string;
|
|
202
|
+
startedAt?: string;
|
|
203
|
+
endedAt?: string;
|
|
204
|
+
traceId?: string;
|
|
205
|
+
}
|
|
206
|
+
/** 步骤记录:purpose 说明业务角色,status 说明执行到哪。 */
|
|
207
|
+
export interface TaskStepRecord {
|
|
208
|
+
stepId: string;
|
|
209
|
+
purpose: string;
|
|
210
|
+
status: StepStatus;
|
|
211
|
+
toolName?: string;
|
|
212
|
+
attempt: number;
|
|
213
|
+
startedAt?: string;
|
|
214
|
+
endedAt?: string;
|
|
215
|
+
}
|
|
216
|
+
/** 单次工具调用:重试与超时后的幂等判断依赖这一层。 */
|
|
217
|
+
export interface ToolInvocationRecord {
|
|
218
|
+
invocationId: string;
|
|
219
|
+
stepId: string;
|
|
220
|
+
retryIndex: number;
|
|
221
|
+
toolName: string;
|
|
222
|
+
inputHash: string;
|
|
223
|
+
responseCode?: string;
|
|
224
|
+
elapsedMs?: number;
|
|
225
|
+
startedAt: string;
|
|
226
|
+
endedAt?: string;
|
|
227
|
+
}
|
|
228
|
+
/** 批量中的一条业务记录结果。 */
|
|
229
|
+
export interface BatchItemRecord {
|
|
230
|
+
itemId: string;
|
|
231
|
+
status: BatchItemStatus;
|
|
232
|
+
reason?: string;
|
|
233
|
+
}
|
|
234
|
+
export declare function isTaskStatus(value: unknown): value is TaskStatus;
|
|
235
|
+
export declare function isToolKind(value: unknown): value is ToolKind;
|
|
236
|
+
/**
|
|
237
|
+
* 状态—形态策略矩阵。
|
|
238
|
+
*
|
|
239
|
+
* 由策略类推导,避免手写 18 × 6 的重复配置;矩阵本身可物化后作为测试真值表。
|
|
240
|
+
*/
|
|
241
|
+
export declare const TOOL_POLICIES: readonly ["allow", "conditional", "deny"];
|
|
242
|
+
export type ToolPolicy = (typeof TOOL_POLICIES)[number];
|
|
243
|
+
export declare function policyFor(status: TaskStatus, kind: ToolKind): ToolPolicy;
|
|
244
|
+
export declare const STATE_TOOL_MATRIX: Record<TaskStatus, Record<ToolKind, ToolPolicy>>;
|
|
245
|
+
export declare function canInvoke(status: TaskStatus, kind: ToolKind): boolean;
|
|
246
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/status.ts","../src/kind.ts","../src/errors.ts","../src/events.ts","../src/records.ts","../src/matrix.ts"],"mappings":";;;;;;qBAOa;YAqBD,qBAAqB;;qBAGpB;YAED,yBAAyB;;qBAGxB;YAED,sBAAsB;;qBAGrB,iBAAiB,OAAO,YAAY;wBAqBjC,cAAc,QAAQ,aAAa;wBAInC,WAAW,QAAQ,aAAa,UAAU;;qBAK7C,kBAAkB,OAAO,qBAAqB;wBAqB3C,cAAc,MAAM,YAAY,IAAI;;;;;qBCvFvC;YAED,mBAAmB;;qBAGlB;YAED,wBAAwB;wBAEpB,YAAY,MAAM,WAAW,QAAQ;;qBAKxC;YAED,sBAAsB;;qBAGrB;YAED,oBAAoB;;qBAGnB,uBAAuB;;qBAGvB;YAED,yBAAyB;qBAExB,yBAAyB,OAAO,UAAU;;qBAU1C;YAED,kBAAkB;qBAEjB,YAAY,OAAO,UAAU;wBAS1B,UAAU,MAAM,WAAW;;qBAK9B;YAED,qBAAqB;;qBAGpB;YAED,0BAA0B;;qBAGzB;YAED,uBAAuB;qBAEtB;YAED,2BAA2B;qBAE1B;YAED,+BAA+B;;qBAG9B;YAED,wBAAwB;;qBAGvB;YAED,qBAAqB;;qBAGpB;YAED,qBAAqB;;;;qBC/FpB;YAkBD,oBAAoB;qBAEnB,mBAAmB,OAAO;;qBAmB1B;YAED,6BAA6B;wBAEzB,YAAY,MAAM;;iBAKjB;EACf,MAAM;EACN;EACA;EACA,UAAU;;wBAGI,UAAU,MAAM,WAAW,iBAAiB,UAAU,0BAA0B;;;;;;;qBChDnF;qBAEA;YAaD,uBAAuB;iBAElB,YAAY;EAC3B,UAAU;EACV;EACA;EACA;EACA,MAAM;EACN;EACA,SAAS;;iBAGM;EACf;;iBAGe;EACf;EACA;EACA,OAAO;EACP,cAAc;;iBAGC;EACf;EACA;EACA;EACA;EACA;;iBAGe;EACf,QAAQ;EACR;EACA;IACE;IACA;IACA;IACA;;;iBAIa;EACf;EACA;EACA;EACA;EACA;;;iBAIe;EACf;EACA,SAAS;;iBAGM;EACf,MAAM;EACN;EACA;;qBAGW;YAED,uBAAuB;iBAElB;EACf;EACA;IAAU;IAAY;;;iBAGP;EACf,QAAQ;EACR;;iBAGe;EACf,aAAa;EACb,iBAAiB;EACjB,eAAe;EACf,cAAc;EACd,YAAY;EACZ,eAAe;EACf,qBAAqB;EACrB,eAAe;EACf,OAAO;EACP,WAAW;;YAGD,mBACT,WAAW,gBAAgB,YAAY,cAAc;EAAQ,MAAM;WAC9D;;iBCjHS;EACf;EACA;EACA;EACA;;;iBAIe;EACf,SAAS;;;iBAIM;EACf;EACA;EACA,QAAQ;EACR,QAAQ;EACR;EACA;EACA,UAAU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;;iBAIe;EACf;EACA;EACA,QAAQ;EACR;EACA;EACA;EACA;;;iBAIe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;iBAIe;EACf;EACA,QAAQ;EACR;;wBC3Dc,aAAa,iBAAiB,SAAS;wBAIvC,WAAW,iBAAiB,SAAS;;;;;;qBAUxC;YAED,qBAAqB;wBAYjB,UAAU,QAAQ,YAAY,MAAM,WAAW;qBAelD,mBAAmB,OAAO,YAAY,OAAO,UAAU;wBAEpD,UAAU,QAAQ,YAAY,MAAM"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
// src/status.ts
|
|
2
|
+
/**
|
|
3
|
+
* 任务状态机:18 个状态、5 个策略类、状态迁移表。
|
|
4
|
+
*
|
|
5
|
+
* 约束:状态只能由服务端状态机写入,模型不得直接设置。
|
|
6
|
+
*/
|
|
7
|
+
/** 任务状态,共 18 个。 */
|
|
8
|
+
const TASK_STATUSES = [
|
|
9
|
+
"Draft",
|
|
10
|
+
"Created",
|
|
11
|
+
"Planning",
|
|
12
|
+
"AwaitingInput",
|
|
13
|
+
"AwaitingConfirmation",
|
|
14
|
+
"AwaitingApproval",
|
|
15
|
+
"Queued",
|
|
16
|
+
"Running",
|
|
17
|
+
"AwaitingExternalAction",
|
|
18
|
+
"Verifying",
|
|
19
|
+
"PartiallyCompleted",
|
|
20
|
+
"Compensating",
|
|
21
|
+
"Paused",
|
|
22
|
+
"NeedsManualIntervention",
|
|
23
|
+
"Completed",
|
|
24
|
+
"Failed",
|
|
25
|
+
"Cancelled",
|
|
26
|
+
"Expired"
|
|
27
|
+
];
|
|
28
|
+
/** 终态:不可回退,继续操作应新建任务。 */
|
|
29
|
+
const TERMINAL_STATUSES = [
|
|
30
|
+
"Completed",
|
|
31
|
+
"Failed",
|
|
32
|
+
"Cancelled",
|
|
33
|
+
"Expired"
|
|
34
|
+
];
|
|
35
|
+
/** 策略类:状态到允许工具形态的归并,用于实现与测试。 */
|
|
36
|
+
const POLICY_CLASSES = [
|
|
37
|
+
"READONLY",
|
|
38
|
+
"FROZEN",
|
|
39
|
+
"EXECUTING",
|
|
40
|
+
"COMPENSATING",
|
|
41
|
+
"TERMINAL"
|
|
42
|
+
];
|
|
43
|
+
/** 状态归属的策略类,覆盖全部 18 个状态。 */
|
|
44
|
+
const POLICY_CLASS_OF = {
|
|
45
|
+
Draft: "READONLY",
|
|
46
|
+
Created: "FROZEN",
|
|
47
|
+
Planning: "READONLY",
|
|
48
|
+
AwaitingInput: "READONLY",
|
|
49
|
+
AwaitingConfirmation: "READONLY",
|
|
50
|
+
AwaitingApproval: "READONLY",
|
|
51
|
+
Queued: "FROZEN",
|
|
52
|
+
Running: "EXECUTING",
|
|
53
|
+
AwaitingExternalAction: "READONLY",
|
|
54
|
+
Verifying: "READONLY",
|
|
55
|
+
PartiallyCompleted: "READONLY",
|
|
56
|
+
Compensating: "COMPENSATING",
|
|
57
|
+
Paused: "READONLY",
|
|
58
|
+
NeedsManualIntervention: "READONLY",
|
|
59
|
+
Completed: "TERMINAL",
|
|
60
|
+
Failed: "TERMINAL",
|
|
61
|
+
Cancelled: "TERMINAL",
|
|
62
|
+
Expired: "TERMINAL"
|
|
63
|
+
};
|
|
64
|
+
function policyClassOf(status) {
|
|
65
|
+
return POLICY_CLASS_OF[status];
|
|
66
|
+
}
|
|
67
|
+
function isTerminal(status) {
|
|
68
|
+
return TERMINAL_STATUSES.includes(status);
|
|
69
|
+
}
|
|
70
|
+
/** 状态迁移表;空数组表示终态。 */
|
|
71
|
+
const TASK_TRANSITIONS = {
|
|
72
|
+
Draft: ["Created", "Cancelled"],
|
|
73
|
+
Created: ["Planning", "Cancelled"],
|
|
74
|
+
Planning: [
|
|
75
|
+
"AwaitingInput",
|
|
76
|
+
"AwaitingConfirmation",
|
|
77
|
+
"AwaitingApproval",
|
|
78
|
+
"Running",
|
|
79
|
+
"Queued",
|
|
80
|
+
"Failed",
|
|
81
|
+
"Cancelled"
|
|
82
|
+
],
|
|
83
|
+
AwaitingInput: [
|
|
84
|
+
"Planning",
|
|
85
|
+
"Expired",
|
|
86
|
+
"Cancelled"
|
|
87
|
+
],
|
|
88
|
+
AwaitingConfirmation: [
|
|
89
|
+
"Queued",
|
|
90
|
+
"Expired",
|
|
91
|
+
"Cancelled"
|
|
92
|
+
],
|
|
93
|
+
AwaitingApproval: [
|
|
94
|
+
"Queued",
|
|
95
|
+
"Failed",
|
|
96
|
+
"Expired",
|
|
97
|
+
"Cancelled"
|
|
98
|
+
],
|
|
99
|
+
Queued: ["Running", "Cancelled"],
|
|
100
|
+
Running: [
|
|
101
|
+
"Verifying",
|
|
102
|
+
"AwaitingExternalAction",
|
|
103
|
+
"AwaitingInput",
|
|
104
|
+
"Paused",
|
|
105
|
+
"Compensating",
|
|
106
|
+
"Failed",
|
|
107
|
+
"Cancelled"
|
|
108
|
+
],
|
|
109
|
+
AwaitingExternalAction: [
|
|
110
|
+
"Running",
|
|
111
|
+
"Expired",
|
|
112
|
+
"Cancelled"
|
|
113
|
+
],
|
|
114
|
+
Verifying: [
|
|
115
|
+
"Completed",
|
|
116
|
+
"PartiallyCompleted",
|
|
117
|
+
"Compensating",
|
|
118
|
+
"Failed",
|
|
119
|
+
"Cancelled"
|
|
120
|
+
],
|
|
121
|
+
PartiallyCompleted: [
|
|
122
|
+
"Running",
|
|
123
|
+
"Compensating",
|
|
124
|
+
"NeedsManualIntervention",
|
|
125
|
+
"Cancelled"
|
|
126
|
+
],
|
|
127
|
+
Compensating: ["Failed", "NeedsManualIntervention"],
|
|
128
|
+
Paused: ["Running", "Cancelled"],
|
|
129
|
+
NeedsManualIntervention: ["Running", "Cancelled"],
|
|
130
|
+
Completed: [],
|
|
131
|
+
Failed: [],
|
|
132
|
+
Cancelled: [],
|
|
133
|
+
Expired: []
|
|
134
|
+
};
|
|
135
|
+
function canTransition(from, to) {
|
|
136
|
+
return TASK_TRANSITIONS[from].includes(to);
|
|
137
|
+
}
|
|
138
|
+
// src/kind.ts
|
|
139
|
+
/**
|
|
140
|
+
* 工具形态、能力粒度、风险等级与执行平面。
|
|
141
|
+
*/
|
|
142
|
+
/** 六类工具形态:执行契约的原型,不是语义分类。 */
|
|
143
|
+
const TOOL_KINDS = [
|
|
144
|
+
"business.query",
|
|
145
|
+
"business.command",
|
|
146
|
+
"device.command",
|
|
147
|
+
"knowledge.retrieve",
|
|
148
|
+
"ui.navigate",
|
|
149
|
+
"external.notify"
|
|
150
|
+
];
|
|
151
|
+
/** 写类形态:必须幂等与审计,R2 起需确认。 */
|
|
152
|
+
const WRITE_TOOL_KINDS = [
|
|
153
|
+
"business.command",
|
|
154
|
+
"device.command",
|
|
155
|
+
"external.notify"
|
|
156
|
+
];
|
|
157
|
+
function isWriteKind(kind) {
|
|
158
|
+
return WRITE_TOOL_KINDS.includes(kind);
|
|
159
|
+
}
|
|
160
|
+
/** 能力粒度:与工具形态正交。C1 不得搭配写类形态。 */
|
|
161
|
+
const GRANULARITIES = [
|
|
162
|
+
"C1",
|
|
163
|
+
"C2",
|
|
164
|
+
"C3"
|
|
165
|
+
];
|
|
166
|
+
/** 风险等级:多因子判定的结果,不是单一标签。 */
|
|
167
|
+
const RISK_LEVELS = [
|
|
168
|
+
"R0",
|
|
169
|
+
"R1",
|
|
170
|
+
"R2",
|
|
171
|
+
"R3",
|
|
172
|
+
"R4"
|
|
173
|
+
];
|
|
174
|
+
/** 需要人工确认的最低风险等级。 */
|
|
175
|
+
const CONFIRMATION_MIN_RISK = "R2";
|
|
176
|
+
/** 执行平面:同一份工具清单,执行位置不同。 */
|
|
177
|
+
const EXECUTION_PLANES = [
|
|
178
|
+
"backend",
|
|
179
|
+
"device_gateway",
|
|
180
|
+
"frontend"
|
|
181
|
+
];
|
|
182
|
+
const DEFAULT_EXECUTION_PLANE = {
|
|
183
|
+
"business.query": "backend",
|
|
184
|
+
"business.command": "backend",
|
|
185
|
+
"device.command": "device_gateway",
|
|
186
|
+
"knowledge.retrieve": "backend",
|
|
187
|
+
"ui.navigate": "frontend",
|
|
188
|
+
"external.notify": "backend"
|
|
189
|
+
};
|
|
190
|
+
/** 语义通道:由形态推导,仅用于提示词分组、卡片渲染与统计,不参与授权。 */
|
|
191
|
+
const CHANNELS = [
|
|
192
|
+
"knowledge",
|
|
193
|
+
"query",
|
|
194
|
+
"action"
|
|
195
|
+
];
|
|
196
|
+
const CHANNEL_OF = {
|
|
197
|
+
"business.query": "query",
|
|
198
|
+
"business.command": "action",
|
|
199
|
+
"device.command": "action",
|
|
200
|
+
"knowledge.retrieve": "knowledge",
|
|
201
|
+
"ui.navigate": "action",
|
|
202
|
+
"external.notify": "action"
|
|
203
|
+
};
|
|
204
|
+
function channelOf(kind) {
|
|
205
|
+
return CHANNEL_OF[kind];
|
|
206
|
+
}
|
|
207
|
+
/** 步骤状态:包含执行子态。 */
|
|
208
|
+
const STEP_STATUSES = [
|
|
209
|
+
"pending",
|
|
210
|
+
"running",
|
|
211
|
+
"retry_waiting",
|
|
212
|
+
"awaiting_callback",
|
|
213
|
+
"completed",
|
|
214
|
+
"failed",
|
|
215
|
+
"skipped"
|
|
216
|
+
];
|
|
217
|
+
/** 批量项结果。 */
|
|
218
|
+
const BATCH_ITEM_STATUSES = [
|
|
219
|
+
"succeeded",
|
|
220
|
+
"failed",
|
|
221
|
+
"skipped"
|
|
222
|
+
];
|
|
223
|
+
/** 确认与审批是两个不同对象:前者是发起人动作,后者是业务授权。 */
|
|
224
|
+
const APPROVAL_KINDS = ["confirmation", "approval"];
|
|
225
|
+
const APPROVAL_DECISIONS = [
|
|
226
|
+
"approved",
|
|
227
|
+
"rejected",
|
|
228
|
+
"expired"
|
|
229
|
+
];
|
|
230
|
+
const CONFIRMATION_STRATEGIES = [
|
|
231
|
+
"single",
|
|
232
|
+
"dual",
|
|
233
|
+
"stepUp"
|
|
234
|
+
];
|
|
235
|
+
/** 可逆性:不可从形态推导。 */
|
|
236
|
+
const REVERSIBILITIES = [
|
|
237
|
+
"reversible",
|
|
238
|
+
"compensatable",
|
|
239
|
+
"irreversible"
|
|
240
|
+
];
|
|
241
|
+
/** 审计级别。 */
|
|
242
|
+
const AUDIT_LEVELS = [
|
|
243
|
+
"none",
|
|
244
|
+
"basic",
|
|
245
|
+
"full"
|
|
246
|
+
];
|
|
247
|
+
/** 绑定层允许的 HTTP 方法。 */
|
|
248
|
+
const HTTP_METHODS = [
|
|
249
|
+
"GET",
|
|
250
|
+
"POST",
|
|
251
|
+
"PUT",
|
|
252
|
+
"PATCH",
|
|
253
|
+
"DELETE"
|
|
254
|
+
];
|
|
255
|
+
// src/errors.ts
|
|
256
|
+
/**
|
|
257
|
+
* 统一错误码与 HTTP 映射。
|
|
258
|
+
*/
|
|
259
|
+
const ERROR_CODES = [
|
|
260
|
+
"INVALID_ARGUMENT",
|
|
261
|
+
"NOT_FOUND",
|
|
262
|
+
"PERMISSION_DENIED",
|
|
263
|
+
"UPSTREAM_UNAUTHORIZED",
|
|
264
|
+
"CONFLICT",
|
|
265
|
+
"PRECONDITION_FAILED",
|
|
266
|
+
"RATE_LIMITED",
|
|
267
|
+
"TIMEOUT",
|
|
268
|
+
"UPSTREAM_UNAVAILABLE",
|
|
269
|
+
"CONFIRMATION_REQUIRED",
|
|
270
|
+
"CONFIRMATION_EXPIRED",
|
|
271
|
+
"IDEMPOTENCY_CONFLICT",
|
|
272
|
+
"STREAM_GAP",
|
|
273
|
+
"STEP_LIMIT",
|
|
274
|
+
"INTERNAL"
|
|
275
|
+
];
|
|
276
|
+
const ERROR_HTTP_STATUS = {
|
|
277
|
+
INVALID_ARGUMENT: 400,
|
|
278
|
+
NOT_FOUND: 404,
|
|
279
|
+
PERMISSION_DENIED: 403,
|
|
280
|
+
UPSTREAM_UNAUTHORIZED: 502,
|
|
281
|
+
CONFLICT: 409,
|
|
282
|
+
PRECONDITION_FAILED: 412,
|
|
283
|
+
RATE_LIMITED: 429,
|
|
284
|
+
TIMEOUT: 504,
|
|
285
|
+
UPSTREAM_UNAVAILABLE: 502,
|
|
286
|
+
CONFIRMATION_REQUIRED: 409,
|
|
287
|
+
CONFIRMATION_EXPIRED: 409,
|
|
288
|
+
IDEMPOTENCY_CONFLICT: 409,
|
|
289
|
+
STREAM_GAP: 409,
|
|
290
|
+
STEP_LIMIT: 429,
|
|
291
|
+
INTERNAL: 500
|
|
292
|
+
};
|
|
293
|
+
/** 可重试错误:读操作可直接重试,写操作默认不重试。 */
|
|
294
|
+
const RETRYABLE_ERROR_CODES = [
|
|
295
|
+
"CONFLICT",
|
|
296
|
+
"RATE_LIMITED",
|
|
297
|
+
"TIMEOUT",
|
|
298
|
+
"UPSTREAM_UNAVAILABLE"
|
|
299
|
+
];
|
|
300
|
+
function isRetryable(code) {
|
|
301
|
+
return RETRYABLE_ERROR_CODES.includes(code);
|
|
302
|
+
}
|
|
303
|
+
function errorBody(code, message, details) {
|
|
304
|
+
return details === void 0 ? {
|
|
305
|
+
code,
|
|
306
|
+
message,
|
|
307
|
+
retryable: isRetryable(code)
|
|
308
|
+
} : {
|
|
309
|
+
code,
|
|
310
|
+
message,
|
|
311
|
+
retryable: isRetryable(code),
|
|
312
|
+
details
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
// src/events.ts
|
|
316
|
+
/**
|
|
317
|
+
* SSE 事件协议。
|
|
318
|
+
*
|
|
319
|
+
* 兼容约束:客户端按空行切分、只取单行 data、把 event: ping 当心跳。
|
|
320
|
+
* 因此每条事件只有一行 data,事件类型放在 JSON 内。
|
|
321
|
+
*/
|
|
322
|
+
const SSE_PROTOCOL_VERSION = 1;
|
|
323
|
+
const SSE_EVENT_TYPES = [
|
|
324
|
+
"run.start",
|
|
325
|
+
"message.delta",
|
|
326
|
+
"message.end",
|
|
327
|
+
"tool.start",
|
|
328
|
+
"tool.end",
|
|
329
|
+
"task.update",
|
|
330
|
+
"approval.required",
|
|
331
|
+
"ui.navigate",
|
|
332
|
+
"error",
|
|
333
|
+
"run.end"
|
|
334
|
+
];
|
|
335
|
+
const RUN_END_STATUSES = [
|
|
336
|
+
"completed",
|
|
337
|
+
"failed",
|
|
338
|
+
"cancelled",
|
|
339
|
+
"expired"
|
|
340
|
+
];
|
|
341
|
+
// src/matrix.ts
|
|
342
|
+
function isTaskStatus(value) {
|
|
343
|
+
return typeof value === "string" && TASK_STATUSES.includes(value);
|
|
344
|
+
}
|
|
345
|
+
function isToolKind(value) {
|
|
346
|
+
return typeof value === "string" && TOOL_KINDS.includes(value);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* 状态—形态策略矩阵。
|
|
350
|
+
*
|
|
351
|
+
* 由策略类推导,避免手写 18 × 6 的重复配置;矩阵本身可物化后作为测试真值表。
|
|
352
|
+
*/
|
|
353
|
+
const TOOL_POLICIES = [
|
|
354
|
+
"allow",
|
|
355
|
+
"conditional",
|
|
356
|
+
"deny"
|
|
357
|
+
];
|
|
358
|
+
const ALLOWED_BY_CLASS = {
|
|
359
|
+
READONLY: [
|
|
360
|
+
"business.query",
|
|
361
|
+
"knowledge.retrieve",
|
|
362
|
+
"ui.navigate"
|
|
363
|
+
],
|
|
364
|
+
FROZEN: [],
|
|
365
|
+
EXECUTING: TOOL_KINDS,
|
|
366
|
+
COMPENSATING: TOOL_KINDS,
|
|
367
|
+
TERMINAL: []
|
|
368
|
+
};
|
|
369
|
+
function policyFor(status, kind) {
|
|
370
|
+
if (!isTaskStatus(status) || !isToolKind(kind)) return "deny";
|
|
371
|
+
const policyClass = POLICY_CLASS_OF[status];
|
|
372
|
+
if (!ALLOWED_BY_CLASS[policyClass].includes(kind)) return "deny";
|
|
373
|
+
return policyClass === "COMPENSATING" && isWriteKind(kind) ? "conditional" : "allow";
|
|
374
|
+
}
|
|
375
|
+
function buildMatrix() {
|
|
376
|
+
const rows = TASK_STATUSES.map((status) => {
|
|
377
|
+
return [status, Object.fromEntries(TOOL_KINDS.map((kind) => [kind, policyFor(status, kind)]))];
|
|
378
|
+
});
|
|
379
|
+
return Object.fromEntries(rows);
|
|
380
|
+
}
|
|
381
|
+
const STATE_TOOL_MATRIX = buildMatrix();
|
|
382
|
+
function canInvoke(status, kind) {
|
|
383
|
+
return policyFor(status, kind) !== "deny";
|
|
384
|
+
}
|
|
385
|
+
export { APPROVAL_DECISIONS, APPROVAL_KINDS, AUDIT_LEVELS, BATCH_ITEM_STATUSES, CHANNELS, CHANNEL_OF, CONFIRMATION_MIN_RISK, CONFIRMATION_STRATEGIES, DEFAULT_EXECUTION_PLANE, ERROR_CODES, ERROR_HTTP_STATUS, EXECUTION_PLANES, GRANULARITIES, HTTP_METHODS, POLICY_CLASSES, POLICY_CLASS_OF, RETRYABLE_ERROR_CODES, REVERSIBILITIES, RISK_LEVELS, RUN_END_STATUSES, SSE_EVENT_TYPES, SSE_PROTOCOL_VERSION, STATE_TOOL_MATRIX, STEP_STATUSES, TASK_STATUSES, TASK_TRANSITIONS, TERMINAL_STATUSES, TOOL_KINDS, TOOL_POLICIES, WRITE_TOOL_KINDS, canInvoke, canTransition, channelOf, errorBody, isRetryable, isTaskStatus, isTerminal, isToolKind, isWriteKind, policyClassOf, policyFor };
|
|
386
|
+
|
|
387
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/status.ts","../src/kind.ts","../src/errors.ts","../src/events.ts","../src/matrix.ts"],"sourcesContent":["/**\n * 任务状态机:18 个状态、5 个策略类、状态迁移表。\n *\n * 约束:状态只能由服务端状态机写入,模型不得直接设置。\n */\n\n/** 任务状态,共 18 个。 */\nexport const TASK_STATUSES = [\n 'Draft',\n 'Created',\n 'Planning',\n 'AwaitingInput',\n 'AwaitingConfirmation',\n 'AwaitingApproval',\n 'Queued',\n 'Running',\n 'AwaitingExternalAction',\n 'Verifying',\n 'PartiallyCompleted',\n 'Compensating',\n 'Paused',\n 'NeedsManualIntervention',\n 'Completed',\n 'Failed',\n 'Cancelled',\n 'Expired',\n] as const\n\nexport type TaskStatus = (typeof TASK_STATUSES)[number]\n\n/** 终态:不可回退,继续操作应新建任务。 */\nexport const TERMINAL_STATUSES = ['Completed', 'Failed', 'Cancelled', 'Expired'] as const\n\nexport type TerminalStatus = (typeof TERMINAL_STATUSES)[number]\n\n/** 策略类:状态到允许工具形态的归并,用于实现与测试。 */\nexport const POLICY_CLASSES = ['READONLY', 'FROZEN', 'EXECUTING', 'COMPENSATING', 'TERMINAL'] as const\n\nexport type PolicyClass = (typeof POLICY_CLASSES)[number]\n\n/** 状态归属的策略类,覆盖全部 18 个状态。 */\nexport const POLICY_CLASS_OF: Record<TaskStatus, PolicyClass> = {\n Draft: 'READONLY',\n Created: 'FROZEN',\n Planning: 'READONLY',\n AwaitingInput: 'READONLY',\n AwaitingConfirmation: 'READONLY',\n AwaitingApproval: 'READONLY',\n Queued: 'FROZEN',\n Running: 'EXECUTING',\n AwaitingExternalAction: 'READONLY',\n Verifying: 'READONLY',\n PartiallyCompleted: 'READONLY',\n Compensating: 'COMPENSATING',\n Paused: 'READONLY',\n NeedsManualIntervention: 'READONLY',\n Completed: 'TERMINAL',\n Failed: 'TERMINAL',\n Cancelled: 'TERMINAL',\n Expired: 'TERMINAL',\n}\n\nexport function policyClassOf(status: TaskStatus): PolicyClass {\n return POLICY_CLASS_OF[status]\n}\n\nexport function isTerminal(status: TaskStatus): status is TerminalStatus {\n return (TERMINAL_STATUSES as readonly string[]).includes(status)\n}\n\n/** 状态迁移表;空数组表示终态。 */\nexport const TASK_TRANSITIONS: Record<TaskStatus, readonly TaskStatus[]> = {\n Draft: ['Created', 'Cancelled'],\n Created: ['Planning', 'Cancelled'],\n Planning: ['AwaitingInput', 'AwaitingConfirmation', 'AwaitingApproval', 'Running', 'Queued', 'Failed', 'Cancelled'],\n AwaitingInput: ['Planning', 'Expired', 'Cancelled'],\n AwaitingConfirmation: ['Queued', 'Expired', 'Cancelled'],\n AwaitingApproval: ['Queued', 'Failed', 'Expired', 'Cancelled'],\n Queued: ['Running', 'Cancelled'],\n Running: ['Verifying', 'AwaitingExternalAction', 'AwaitingInput', 'Paused', 'Compensating', 'Failed', 'Cancelled'],\n AwaitingExternalAction: ['Running', 'Expired', 'Cancelled'],\n Verifying: ['Completed', 'PartiallyCompleted', 'Compensating', 'Failed', 'Cancelled'],\n PartiallyCompleted: ['Running', 'Compensating', 'NeedsManualIntervention', 'Cancelled'],\n Compensating: ['Failed', 'NeedsManualIntervention'],\n Paused: ['Running', 'Cancelled'],\n NeedsManualIntervention: ['Running', 'Cancelled'],\n Completed: [],\n Failed: [],\n Cancelled: [],\n Expired: [],\n}\n\nexport function canTransition(from: TaskStatus, to: TaskStatus): boolean {\n return TASK_TRANSITIONS[from].includes(to)\n}\n","/**\n * 工具形态、能力粒度、风险等级与执行平面。\n */\n\n/** 六类工具形态:执行契约的原型,不是语义分类。 */\nexport const TOOL_KINDS = ['business.query', 'business.command', 'device.command', 'knowledge.retrieve', 'ui.navigate', 'external.notify'] as const\n\nexport type ToolKind = (typeof TOOL_KINDS)[number]\n\n/** 写类形态:必须幂等与审计,R2 起需确认。 */\nexport const WRITE_TOOL_KINDS = ['business.command', 'device.command', 'external.notify'] as const\n\nexport type WriteToolKind = (typeof WRITE_TOOL_KINDS)[number]\n\nexport function isWriteKind(kind: ToolKind): kind is WriteToolKind {\n return (WRITE_TOOL_KINDS as readonly string[]).includes(kind)\n}\n\n/** 能力粒度:与工具形态正交。C1 不得搭配写类形态。 */\nexport const GRANULARITIES = ['C1', 'C2', 'C3'] as const\n\nexport type Granularity = (typeof GRANULARITIES)[number]\n\n/** 风险等级:多因子判定的结果,不是单一标签。 */\nexport const RISK_LEVELS = ['R0', 'R1', 'R2', 'R3', 'R4'] as const\n\nexport type RiskLevel = (typeof RISK_LEVELS)[number]\n\n/** 需要人工确认的最低风险等级。 */\nexport const CONFIRMATION_MIN_RISK: RiskLevel = 'R2'\n\n/** 执行平面:同一份工具清单,执行位置不同。 */\nexport const EXECUTION_PLANES = ['backend', 'device_gateway', 'frontend'] as const\n\nexport type ExecutionPlane = (typeof EXECUTION_PLANES)[number]\n\nexport const DEFAULT_EXECUTION_PLANE: Record<ToolKind, ExecutionPlane> = {\n 'business.query': 'backend',\n 'business.command': 'backend',\n 'device.command': 'device_gateway',\n 'knowledge.retrieve': 'backend',\n 'ui.navigate': 'frontend',\n 'external.notify': 'backend',\n}\n\n/** 语义通道:由形态推导,仅用于提示词分组、卡片渲染与统计,不参与授权。 */\nexport const CHANNELS = ['knowledge', 'query', 'action'] as const\n\nexport type Channel = (typeof CHANNELS)[number]\n\nexport const CHANNEL_OF: Record<ToolKind, Channel> = {\n 'business.query': 'query',\n 'business.command': 'action',\n 'device.command': 'action',\n 'knowledge.retrieve': 'knowledge',\n 'ui.navigate': 'action',\n 'external.notify': 'action',\n}\n\nexport function channelOf(kind: ToolKind): Channel {\n return CHANNEL_OF[kind]\n}\n\n/** 步骤状态:包含执行子态。 */\nexport const STEP_STATUSES = ['pending', 'running', 'retry_waiting', 'awaiting_callback', 'completed', 'failed', 'skipped'] as const\n\nexport type StepStatus = (typeof STEP_STATUSES)[number]\n\n/** 批量项结果。 */\nexport const BATCH_ITEM_STATUSES = ['succeeded', 'failed', 'skipped'] as const\n\nexport type BatchItemStatus = (typeof BATCH_ITEM_STATUSES)[number]\n\n/** 确认与审批是两个不同对象:前者是发起人动作,后者是业务授权。 */\nexport const APPROVAL_KINDS = ['confirmation', 'approval'] as const\n\nexport type ApprovalKind = (typeof APPROVAL_KINDS)[number]\n\nexport const APPROVAL_DECISIONS = ['approved', 'rejected', 'expired'] as const\n\nexport type ApprovalDecision = (typeof APPROVAL_DECISIONS)[number]\n\nexport const CONFIRMATION_STRATEGIES = ['single', 'dual', 'stepUp'] as const\n\nexport type ConfirmationStrategy = (typeof CONFIRMATION_STRATEGIES)[number]\n\n/** 可逆性:不可从形态推导。 */\nexport const REVERSIBILITIES = ['reversible', 'compensatable', 'irreversible'] as const\n\nexport type Reversibility = (typeof REVERSIBILITIES)[number]\n\n/** 审计级别。 */\nexport const AUDIT_LEVELS = ['none', 'basic', 'full'] as const\n\nexport type AuditLevel = (typeof AUDIT_LEVELS)[number]\n\n/** 绑定层允许的 HTTP 方法。 */\nexport const HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'] as const\n\nexport type HttpMethod = (typeof HTTP_METHODS)[number]\n","/**\n * 统一错误码与 HTTP 映射。\n */\n\nexport const ERROR_CODES = [\n 'INVALID_ARGUMENT',\n 'NOT_FOUND',\n 'PERMISSION_DENIED',\n 'UPSTREAM_UNAUTHORIZED',\n 'CONFLICT',\n 'PRECONDITION_FAILED',\n 'RATE_LIMITED',\n 'TIMEOUT',\n 'UPSTREAM_UNAVAILABLE',\n 'CONFIRMATION_REQUIRED',\n 'CONFIRMATION_EXPIRED',\n 'IDEMPOTENCY_CONFLICT',\n 'STREAM_GAP',\n 'STEP_LIMIT',\n 'INTERNAL',\n] as const\n\nexport type ErrorCode = (typeof ERROR_CODES)[number]\n\nexport const ERROR_HTTP_STATUS: Record<ErrorCode, number> = {\n INVALID_ARGUMENT: 400,\n NOT_FOUND: 404,\n PERMISSION_DENIED: 403,\n UPSTREAM_UNAUTHORIZED: 502,\n CONFLICT: 409,\n PRECONDITION_FAILED: 412,\n RATE_LIMITED: 429,\n TIMEOUT: 504,\n UPSTREAM_UNAVAILABLE: 502,\n CONFIRMATION_REQUIRED: 409,\n CONFIRMATION_EXPIRED: 409,\n IDEMPOTENCY_CONFLICT: 409,\n STREAM_GAP: 409,\n STEP_LIMIT: 429,\n INTERNAL: 500,\n}\n\n/** 可重试错误:读操作可直接重试,写操作默认不重试。 */\nexport const RETRYABLE_ERROR_CODES = ['CONFLICT', 'RATE_LIMITED', 'TIMEOUT', 'UPSTREAM_UNAVAILABLE'] as const\n\nexport type RetryableErrorCode = (typeof RETRYABLE_ERROR_CODES)[number]\n\nexport function isRetryable(code: ErrorCode): boolean {\n return (RETRYABLE_ERROR_CODES as readonly string[]).includes(code)\n}\n\n/** 结构化错误体,与成功信封互斥。 */\nexport interface ErrorBody {\n code: ErrorCode\n message: string\n retryable: boolean\n details?: Record<string, unknown>\n}\n\nexport function errorBody(code: ErrorCode, message: string, details?: Record<string, unknown>): ErrorBody {\n return details === undefined ? { code, message, retryable: isRetryable(code) } : { code, message, retryable: isRetryable(code), details }\n}\n","import type { ErrorCode } from './errors.js'\nimport type { ToolKind } from './kind.js'\nimport type { TaskStatus } from './status.js'\n\n/**\n * SSE 事件协议。\n *\n * 兼容约束:客户端按空行切分、只取单行 data、把 event: ping 当心跳。\n * 因此每条事件只有一行 data,事件类型放在 JSON 内。\n */\n\nexport const SSE_PROTOCOL_VERSION = 1\n\nexport const SSE_EVENT_TYPES = [\n 'run.start',\n 'message.delta',\n 'message.end',\n 'tool.start',\n 'tool.end',\n 'task.update',\n 'approval.required',\n 'ui.navigate',\n 'error',\n 'run.end',\n] as const\n\nexport type SseEventType = (typeof SSE_EVENT_TYPES)[number]\n\nexport interface SseEnvelope<T = unknown> {\n v: typeof SSE_PROTOCOL_VERSION\n seq: number\n runId: string\n taskId?: string\n type: SseEventType\n at: string\n payload: T\n}\n\nexport interface MessageDeltaPayload {\n text: string\n}\n\nexport interface ToolStartPayload {\n toolCallId?: string\n toolName: string\n kind?: ToolKind\n argsSummary?: Record<string, unknown>\n}\n\nexport interface ToolEndPayload {\n toolCallId?: string\n toolName: string\n ok: boolean\n elapsedMs?: number\n resultSummary?: string\n}\n\nexport interface TaskUpdatePayload {\n status: TaskStatus\n statusReason?: string\n progress?: {\n total: number\n done: number\n failed: number\n skipped: number\n }\n}\n\nexport interface ApprovalRequiredPayload {\n tokenId: string\n summary: string\n planVersion: number\n targetCount?: number\n expiresAt: string\n}\n\n/** 页面跳转指令;由前端执行,运行时只下发。 */\nexport interface UiNavigatePayload {\n route: string\n params?: Record<string, string | number>\n}\n\nexport interface ErrorPayload {\n code: ErrorCode\n message: string\n retryable: boolean\n}\n\nexport const RUN_END_STATUSES = ['completed', 'failed', 'cancelled', 'expired'] as const\n\nexport type RunEndStatus = (typeof RUN_END_STATUSES)[number]\n\nexport interface RunStartPayload {\n conversationId: string\n actor?: { id: string; name?: string }\n}\n\nexport interface RunEndPayload {\n status: RunEndStatus\n answer?: string\n}\n\nexport interface SsePayloadMap {\n 'run.start': RunStartPayload\n 'message.delta': MessageDeltaPayload\n 'message.end': MessageDeltaPayload\n 'tool.start': ToolStartPayload\n 'tool.end': ToolEndPayload\n 'task.update': TaskUpdatePayload\n 'approval.required': ApprovalRequiredPayload\n 'ui.navigate': UiNavigatePayload\n error: ErrorPayload\n 'run.end': RunEndPayload\n}\n\nexport type LodestarEvent = {\n [K in keyof SsePayloadMap]: SseEnvelope<SsePayloadMap[K]> & { type: K }\n}[keyof SsePayloadMap]\n","import { isWriteKind, TOOL_KINDS, type ToolKind } from './kind.js'\nimport { POLICY_CLASS_OF, TASK_STATUSES, type PolicyClass, type TaskStatus } from './status.js'\n\nexport function isTaskStatus(value: unknown): value is TaskStatus {\n return typeof value === 'string' && (TASK_STATUSES as readonly string[]).includes(value)\n}\n\nexport function isToolKind(value: unknown): value is ToolKind {\n return typeof value === 'string' && (TOOL_KINDS as readonly string[]).includes(value)\n}\n\n/**\n * 状态—形态策略矩阵。\n *\n * 由策略类推导,避免手写 18 × 6 的重复配置;矩阵本身可物化后作为测试真值表。\n */\n\nexport const TOOL_POLICIES = ['allow', 'conditional', 'deny'] as const\n\nexport type ToolPolicy = (typeof TOOL_POLICIES)[number]\n\nconst READONLY_KINDS: readonly ToolKind[] = ['business.query', 'knowledge.retrieve', 'ui.navigate']\n\nconst ALLOWED_BY_CLASS: Record<PolicyClass, readonly ToolKind[]> = {\n READONLY: READONLY_KINDS,\n FROZEN: [],\n EXECUTING: TOOL_KINDS,\n COMPENSATING: TOOL_KINDS,\n TERMINAL: [],\n}\n\nexport function policyFor(status: TaskStatus, kind: ToolKind): ToolPolicy {\n if (!isTaskStatus(status) || !isToolKind(kind)) return 'deny'\n const policyClass = POLICY_CLASS_OF[status]\n if (!ALLOWED_BY_CLASS[policyClass].includes(kind)) return 'deny'\n return policyClass === 'COMPENSATING' && isWriteKind(kind) ? 'conditional' : 'allow'\n}\n\nfunction buildMatrix(): Record<TaskStatus, Record<ToolKind, ToolPolicy>> {\n const rows = TASK_STATUSES.map((status) => {\n const row = Object.fromEntries(TOOL_KINDS.map((kind) => [kind, policyFor(status, kind)])) as Record<ToolKind, ToolPolicy>\n return [status, row] as const\n })\n return Object.fromEntries(rows) as Record<TaskStatus, Record<ToolKind, ToolPolicy>>\n}\n\nexport const STATE_TOOL_MATRIX: Record<TaskStatus, Record<ToolKind, ToolPolicy>> = buildMatrix()\n\nexport function canInvoke(status: TaskStatus, kind: ToolKind): boolean {\n return policyFor(status, kind) !== 'deny'\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://eosway.dev/lodestar/schemas/binding.schema.json",
|
|
4
|
+
"title": "Lodestar Tool Binding",
|
|
5
|
+
"description": "工具到接口的映射。只允许参数映射、成功判定与核验断言,不允许条件分支。",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": ["tool", "request"],
|
|
9
|
+
"properties": {
|
|
10
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
11
|
+
"tool": { "type": "string", "pattern": "^[a-z][a-zA-Z0-9]*\\.[a-z][a-zA-Z0-9]*$" },
|
|
12
|
+
"request": {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"additionalProperties": false,
|
|
15
|
+
"required": ["type", "method", "path"],
|
|
16
|
+
"properties": {
|
|
17
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
18
|
+
"type": { "const": "http" },
|
|
19
|
+
"method": { "enum": ["GET", "POST", "PUT", "PATCH", "DELETE"] },
|
|
20
|
+
"path": { "type": "string", "pattern": "^/" },
|
|
21
|
+
"headers": { "type": "object", "additionalProperties": { "type": "string" } },
|
|
22
|
+
"query": { "type": "object" },
|
|
23
|
+
"body": { "type": "object" },
|
|
24
|
+
"successWhen": { "$ref": "#/$defs/assertion" },
|
|
25
|
+
"extract": { "type": "object" }
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"verify": {
|
|
29
|
+
"type": "object",
|
|
30
|
+
"additionalProperties": false,
|
|
31
|
+
"required": ["tool", "args", "expect"],
|
|
32
|
+
"properties": {
|
|
33
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
34
|
+
"tool": { "type": "string" },
|
|
35
|
+
"args": { "type": "object" },
|
|
36
|
+
"expect": { "$ref": "#/$defs/assertion" }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"$defs": {
|
|
41
|
+
"assertion": {
|
|
42
|
+
"type": "object",
|
|
43
|
+
"additionalProperties": false,
|
|
44
|
+
"required": ["path"],
|
|
45
|
+
"properties": {
|
|
46
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
47
|
+
"path": { "type": "string", "pattern": "^\\$\\." },
|
|
48
|
+
"equals": {},
|
|
49
|
+
"allEquals": {},
|
|
50
|
+
"in": { "type": "array" },
|
|
51
|
+
"notEmpty": { "type": "boolean" },
|
|
52
|
+
"empty": { "type": "boolean" },
|
|
53
|
+
"gte": { "type": "number" },
|
|
54
|
+
"lte": { "type": "number" }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://eosway.dev/lodestar/schemas/capset.schema.json",
|
|
4
|
+
"title": "Lodestar Capset Manifest",
|
|
5
|
+
"description": "资产清单定义单个域的能力;装配清单只列成员,两者互斥。",
|
|
6
|
+
"oneOf": [{ "$ref": "#/$defs/assetManifest" }, { "$ref": "#/$defs/indexManifest" }],
|
|
7
|
+
"$defs": {
|
|
8
|
+
"assetManifest": {
|
|
9
|
+
"title": "资产清单",
|
|
10
|
+
"type": "object",
|
|
11
|
+
"additionalProperties": false,
|
|
12
|
+
"required": ["name", "version", "requiresKernel", "capabilities"],
|
|
13
|
+
"properties": {
|
|
14
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
15
|
+
"name": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
|
|
16
|
+
"version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" },
|
|
17
|
+
"instance": { "type": "string" },
|
|
18
|
+
"requiresKernel": { "type": "string" },
|
|
19
|
+
"description": { "type": "string", "maxLength": 200 },
|
|
20
|
+
"sources": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"additionalProperties": { "$ref": "#/$defs/source" }
|
|
23
|
+
},
|
|
24
|
+
"capabilities": { "$ref": "#/$defs/capabilities" }
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"indexManifest": {
|
|
28
|
+
"title": "装配清单",
|
|
29
|
+
"type": "object",
|
|
30
|
+
"additionalProperties": false,
|
|
31
|
+
"required": ["name", "version", "requiresKernel", "members"],
|
|
32
|
+
"properties": {
|
|
33
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
34
|
+
"name": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
|
|
35
|
+
"version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" },
|
|
36
|
+
"instance": { "type": "string" },
|
|
37
|
+
"requiresKernel": { "type": "string" },
|
|
38
|
+
"description": { "type": "string", "maxLength": 200 },
|
|
39
|
+
"members": {
|
|
40
|
+
"type": "array",
|
|
41
|
+
"minItems": 1,
|
|
42
|
+
"uniqueItems": true,
|
|
43
|
+
"items": { "$ref": "#/$defs/member" }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"member": {
|
|
48
|
+
"type": "object",
|
|
49
|
+
"additionalProperties": false,
|
|
50
|
+
"required": ["dir"],
|
|
51
|
+
"properties": {
|
|
52
|
+
"dir": {
|
|
53
|
+
"type": "string",
|
|
54
|
+
"pattern": "^[a-z][a-z0-9-]*$",
|
|
55
|
+
"description": "成员目录名,只允许小写字母、数字与连字符"
|
|
56
|
+
},
|
|
57
|
+
"version": { "type": "string", "description": "预留的版本声明,当前只记录不校验" },
|
|
58
|
+
"optional": { "type": "boolean" }
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"capabilities": {
|
|
62
|
+
"type": "object",
|
|
63
|
+
"additionalProperties": false,
|
|
64
|
+
"required": ["supported"],
|
|
65
|
+
"properties": {
|
|
66
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
67
|
+
"supported": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
|
|
68
|
+
"degraded": { "type": "array", "items": { "$ref": "#/$defs/degraded" } },
|
|
69
|
+
"missing": { "type": "array", "items": { "$ref": "#/$defs/missing" } }
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"source": {
|
|
73
|
+
"type": "object",
|
|
74
|
+
"additionalProperties": false,
|
|
75
|
+
"required": ["method", "path"],
|
|
76
|
+
"properties": {
|
|
77
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
78
|
+
"method": { "enum": ["GET", "POST", "PUT", "PATCH", "DELETE"] },
|
|
79
|
+
"path": { "type": "string", "pattern": "^/" }
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"degraded": {
|
|
83
|
+
"type": "object",
|
|
84
|
+
"additionalProperties": false,
|
|
85
|
+
"required": ["tool", "reason"],
|
|
86
|
+
"properties": {
|
|
87
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
88
|
+
"tool": { "type": "string" },
|
|
89
|
+
"reason": { "type": "string" },
|
|
90
|
+
"limit": { "type": "string" }
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"missing": {
|
|
94
|
+
"type": "object",
|
|
95
|
+
"additionalProperties": false,
|
|
96
|
+
"required": ["tool", "reason", "resolution"],
|
|
97
|
+
"properties": {
|
|
98
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
99
|
+
"tool": { "type": "string" },
|
|
100
|
+
"reason": { "type": "string" },
|
|
101
|
+
"resolution": { "enum": ["not_exposed", "degraded", "planned"] },
|
|
102
|
+
"blocker": { "enum": ["backend", "gateway", "frontend", "none"] }
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://eosway.dev/lodestar/schemas/tool.schema.json",
|
|
4
|
+
"title": "Lodestar Tool Contract",
|
|
5
|
+
"description": "工具语义契约。不得包含接口地址与客户字段名。",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": [
|
|
9
|
+
"name",
|
|
10
|
+
"version",
|
|
11
|
+
"title",
|
|
12
|
+
"description",
|
|
13
|
+
"kind",
|
|
14
|
+
"granularity",
|
|
15
|
+
"domain",
|
|
16
|
+
"riskLevel",
|
|
17
|
+
"executionPlane",
|
|
18
|
+
"reversibility",
|
|
19
|
+
"permissions",
|
|
20
|
+
"inputSchema",
|
|
21
|
+
"outputSchema",
|
|
22
|
+
"timeoutMs",
|
|
23
|
+
"retry",
|
|
24
|
+
"audit"
|
|
25
|
+
],
|
|
26
|
+
"properties": {
|
|
27
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
28
|
+
"name": {
|
|
29
|
+
"type": "string",
|
|
30
|
+
"pattern": "^[a-z][a-zA-Z0-9]*\\.[a-z][a-zA-Z0-9]*$",
|
|
31
|
+
"description": "domain.verb,全局唯一"
|
|
32
|
+
},
|
|
33
|
+
"version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" },
|
|
34
|
+
"title": { "type": "string", "minLength": 1, "maxLength": 40 },
|
|
35
|
+
"description": { "type": "string", "minLength": 1, "maxLength": 400 },
|
|
36
|
+
"kind": {
|
|
37
|
+
"enum": ["business.query", "business.command", "device.command", "knowledge.retrieve", "ui.navigate", "external.notify"]
|
|
38
|
+
},
|
|
39
|
+
"granularity": { "enum": ["C1", "C2", "C3"] },
|
|
40
|
+
"domain": { "type": "string", "pattern": "^[a-z][a-zA-Z0-9]*$" },
|
|
41
|
+
"riskLevel": { "enum": ["R0", "R1", "R2", "R3", "R4"] },
|
|
42
|
+
"executionPlane": { "enum": ["backend", "device_gateway", "frontend"] },
|
|
43
|
+
"reversibility": { "enum": ["reversible", "compensatable", "irreversible"] },
|
|
44
|
+
"permissions": {
|
|
45
|
+
"type": "array",
|
|
46
|
+
"items": { "type": "string", "minLength": 1 },
|
|
47
|
+
"minItems": 1,
|
|
48
|
+
"uniqueItems": true
|
|
49
|
+
},
|
|
50
|
+
"resourceScope": { "type": "object" },
|
|
51
|
+
"inputSchema": { "type": "object" },
|
|
52
|
+
"outputSchema": { "type": "object" },
|
|
53
|
+
"semantics": { "$ref": "#/$defs/semantics" },
|
|
54
|
+
"confirmation": { "$ref": "#/$defs/confirmation" },
|
|
55
|
+
"idempotency": { "$ref": "#/$defs/idempotency" },
|
|
56
|
+
"compensation": { "$ref": "#/$defs/compensation" },
|
|
57
|
+
"evidencePolicy": { "$ref": "#/$defs/evidencePolicy" },
|
|
58
|
+
"timeoutMs": { "type": "integer", "minimum": 1000, "maximum": 600000 },
|
|
59
|
+
"retry": { "$ref": "#/$defs/retry" },
|
|
60
|
+
"audit": { "$ref": "#/$defs/audit" },
|
|
61
|
+
"ui": { "type": "object" }
|
|
62
|
+
},
|
|
63
|
+
"allOf": [
|
|
64
|
+
{
|
|
65
|
+
"if": { "required": ["kind"], "properties": { "kind": { "enum": ["business.command", "device.command", "external.notify"] } } },
|
|
66
|
+
"then": {
|
|
67
|
+
"required": ["idempotency", "audit"],
|
|
68
|
+
"properties": {
|
|
69
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
70
|
+
"idempotency": { "required": ["required"], "properties": { "required": { "const": true } } },
|
|
71
|
+
"audit": { "required": ["level"], "properties": { "level": { "const": "full" } } }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"if": { "required": ["kind"], "properties": { "kind": { "enum": ["business.command", "device.command", "external.notify"] } } },
|
|
77
|
+
"then": { "properties": { "granularity": { "not": { "const": "C1" } } } }
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"if": { "required": ["riskLevel"], "properties": { "riskLevel": { "enum": ["R2", "R3", "R4"] } } },
|
|
81
|
+
"then": {
|
|
82
|
+
"required": ["confirmation"],
|
|
83
|
+
"properties": { "confirmation": { "required": ["required"], "properties": { "required": { "const": true } } } }
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"if": { "required": ["kind"], "properties": { "kind": { "const": "knowledge.retrieve" } } },
|
|
88
|
+
"then": { "required": ["evidencePolicy"] }
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"if": { "required": ["kind"], "properties": { "kind": { "const": "ui.navigate" } } },
|
|
92
|
+
"then": {
|
|
93
|
+
"properties": {
|
|
94
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
95
|
+
"executionPlane": { "const": "frontend" },
|
|
96
|
+
"riskLevel": { "const": "R0" }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"if": { "required": ["kind"], "properties": { "kind": { "const": "device.command" } } },
|
|
102
|
+
"then": {
|
|
103
|
+
"properties": {
|
|
104
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
105
|
+
"executionPlane": { "const": "device_gateway" },
|
|
106
|
+
"reversibility": { "const": "irreversible" }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
"$defs": {
|
|
112
|
+
"semantics": {
|
|
113
|
+
"type": "object",
|
|
114
|
+
"additionalProperties": false,
|
|
115
|
+
"required": ["effect"],
|
|
116
|
+
"properties": {
|
|
117
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
118
|
+
"effect": { "type": "string", "minLength": 1, "maxLength": 200 },
|
|
119
|
+
"requires": { "type": "array", "items": { "type": "string" } },
|
|
120
|
+
"postcondition": { "type": "string", "maxLength": 200 }
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"confirmation": {
|
|
124
|
+
"type": "object",
|
|
125
|
+
"additionalProperties": false,
|
|
126
|
+
"required": ["required"],
|
|
127
|
+
"properties": {
|
|
128
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
129
|
+
"required": { "type": "boolean" },
|
|
130
|
+
"strategy": { "enum": ["single", "dual", "stepUp"] },
|
|
131
|
+
"ttlSeconds": { "type": "integer", "minimum": 30, "maximum": 3600 },
|
|
132
|
+
"summaryTemplate": { "type": "string", "maxLength": 200 },
|
|
133
|
+
"secondApprovalAbove": { "type": "integer", "minimum": 1 }
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
"idempotency": {
|
|
137
|
+
"type": "object",
|
|
138
|
+
"additionalProperties": false,
|
|
139
|
+
"required": ["required"],
|
|
140
|
+
"properties": {
|
|
141
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
142
|
+
"required": { "type": "boolean" },
|
|
143
|
+
"ttlSeconds": { "type": "integer", "minimum": 60, "maximum": 604800 },
|
|
144
|
+
"keyFrom": { "type": "array", "items": { "type": "string" } }
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"compensation": {
|
|
148
|
+
"type": "object",
|
|
149
|
+
"additionalProperties": false,
|
|
150
|
+
"required": ["tool"],
|
|
151
|
+
"properties": {
|
|
152
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
153
|
+
"tool": { "type": "string" },
|
|
154
|
+
"availableForSeconds": { "type": "integer", "minimum": 0 }
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
"evidencePolicy": {
|
|
158
|
+
"type": "object",
|
|
159
|
+
"additionalProperties": false,
|
|
160
|
+
"required": ["required"],
|
|
161
|
+
"properties": {
|
|
162
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
163
|
+
"required": { "type": "boolean" },
|
|
164
|
+
"includeVersion": { "type": "boolean" },
|
|
165
|
+
"includeEffectiveDate": { "type": "boolean" }
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
"retry": {
|
|
169
|
+
"type": "object",
|
|
170
|
+
"additionalProperties": false,
|
|
171
|
+
"required": ["maxAttempts"],
|
|
172
|
+
"properties": {
|
|
173
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
174
|
+
"maxAttempts": { "type": "integer", "minimum": 0, "maximum": 5 },
|
|
175
|
+
"retryableCodes": { "type": "array", "items": { "type": "string" } }
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
"audit": {
|
|
179
|
+
"type": "object",
|
|
180
|
+
"additionalProperties": false,
|
|
181
|
+
"required": ["level"],
|
|
182
|
+
"properties": {
|
|
183
|
+
"$schema": { "type": "string", "description": "编辑器校验用,运行期忽略" },
|
|
184
|
+
"level": { "enum": ["none", "basic", "full"] },
|
|
185
|
+
"logInput": { "type": "boolean" },
|
|
186
|
+
"logOutput": { "enum": [false, "summary", true] }
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eosway/lodestar-spec",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-rc.2",
|
|
4
|
+
"description": "Zero-dependency contract layer for Lodestar: JSON Schemas, TypeScript types, SSE events, error codes and task states.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"homepage": "https://github.com/eosway/lodestar",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/eosway/lodestar.git",
|
|
11
|
+
"directory": "packages/lodestar-spec"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./schemas/*": "./dist/schemas/*",
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^24.19.0",
|
|
29
|
+
"ajv": "^8.20.0",
|
|
30
|
+
"tsdown": "^0.23.7",
|
|
31
|
+
"typescript": "~6.0.3",
|
|
32
|
+
"vitest": "^5.1.2"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsdown",
|
|
36
|
+
"release": "commit-and-tag-version --path . -t lodestar-spec@",
|
|
37
|
+
"typecheck": "tsc -b --force",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"sweep": "rimraf dist node_modules/.tmp",
|
|
40
|
+
"test:unit": "vitest run"
|
|
41
|
+
}
|
|
6
42
|
}
|