@cleocode/lafs 2026.3.74 → 2026.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/README.md +97 -68
- package/dist/schemas/v1/agent-card.schema.json +230 -0
- package/dist/schemas/v1/conformance-profiles.json +0 -0
- package/dist/schemas/v1/context-ledger.schema.json +70 -0
- package/dist/schemas/v1/discovery.schema.json +132 -0
- package/dist/schemas/v1/envelope.schema.json +0 -0
- package/dist/schemas/v1/error-registry.json +0 -0
- package/dist/src/a2a/bindings/grpc.d.ts +118 -11
- package/dist/src/a2a/bindings/grpc.d.ts.map +1 -0
- package/dist/src/a2a/bindings/grpc.js +80 -8
- package/dist/src/a2a/bindings/grpc.js.map +1 -0
- package/dist/src/a2a/bindings/http.d.ts +131 -15
- package/dist/src/a2a/bindings/http.d.ts.map +1 -0
- package/dist/src/a2a/bindings/http.js +101 -14
- package/dist/src/a2a/bindings/http.js.map +1 -0
- package/dist/src/a2a/bindings/index.d.ts +83 -9
- package/dist/src/a2a/bindings/index.d.ts.map +1 -0
- package/dist/src/a2a/bindings/index.js +74 -6
- package/dist/src/a2a/bindings/index.js.map +1 -0
- package/dist/src/a2a/bindings/jsonrpc.d.ts +194 -9
- package/dist/src/a2a/bindings/jsonrpc.d.ts.map +1 -0
- package/dist/src/a2a/bindings/jsonrpc.js +155 -10
- package/dist/src/a2a/bindings/jsonrpc.js.map +1 -0
- package/dist/src/a2a/bridge.d.ts +237 -44
- package/dist/src/a2a/bridge.d.ts.map +1 -0
- package/dist/src/a2a/bridge.js +187 -48
- package/dist/src/a2a/bridge.js.map +1 -0
- package/dist/src/a2a/extensions.d.ts +222 -12
- package/dist/src/a2a/extensions.d.ts.map +1 -0
- package/dist/src/a2a/extensions.js +178 -13
- package/dist/src/a2a/extensions.js.map +1 -0
- package/dist/src/a2a/index.d.ts +10 -7
- package/dist/src/a2a/index.d.ts.map +1 -0
- package/dist/src/a2a/index.js +24 -27
- package/dist/src/a2a/index.js.map +1 -0
- package/dist/src/a2a/streaming.d.ts +276 -3
- package/dist/src/a2a/streaming.d.ts.map +1 -0
- package/dist/src/a2a/streaming.js +255 -11
- package/dist/src/a2a/streaming.js.map +1 -0
- package/dist/src/a2a/task-lifecycle.d.ts +341 -20
- package/dist/src/a2a/task-lifecycle.d.ts.map +1 -0
- package/dist/src/a2a/task-lifecycle.js +327 -26
- package/dist/src/a2a/task-lifecycle.js.map +1 -0
- package/dist/src/budgetEnforcement.d.ts +93 -20
- package/dist/src/budgetEnforcement.d.ts.map +1 -0
- package/dist/src/budgetEnforcement.js +146 -31
- package/dist/src/budgetEnforcement.js.map +1 -0
- package/dist/src/circuit-breaker/index.d.ts +260 -10
- package/dist/src/circuit-breaker/index.d.ts.map +1 -0
- package/dist/src/circuit-breaker/index.js +226 -14
- package/dist/src/circuit-breaker/index.js.map +1 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +12 -11
- package/dist/src/cli.js.map +1 -0
- package/dist/src/compliance.d.ts +180 -3
- package/dist/src/compliance.d.ts.map +1 -0
- package/dist/src/compliance.js +114 -13
- package/dist/src/compliance.js.map +1 -0
- package/dist/src/conformance.d.ts +55 -2
- package/dist/src/conformance.d.ts.map +1 -0
- package/dist/src/conformance.js +124 -76
- package/dist/src/conformance.js.map +1 -0
- package/dist/src/conformanceProfiles.d.ts +68 -1
- package/dist/src/conformanceProfiles.d.ts.map +1 -0
- package/dist/src/conformanceProfiles.js +53 -1
- package/dist/src/conformanceProfiles.js.map +1 -0
- package/dist/src/deprecationRegistry.d.ts +82 -1
- package/dist/src/deprecationRegistry.d.ts.map +1 -0
- package/dist/src/deprecationRegistry.js +58 -7
- package/dist/src/deprecationRegistry.js.map +1 -0
- package/dist/src/discovery.d.ts +347 -65
- package/dist/src/discovery.d.ts.map +1 -0
- package/dist/src/discovery.js +130 -72
- package/dist/src/discovery.js.map +1 -0
- package/dist/src/envelope.d.ts +262 -9
- package/dist/src/envelope.d.ts.map +1 -0
- package/dist/src/envelope.js +179 -15
- package/dist/src/envelope.js.map +1 -0
- package/dist/src/errorRegistry.d.ts +163 -3
- package/dist/src/errorRegistry.d.ts.map +1 -0
- package/dist/src/errorRegistry.js +119 -3
- package/dist/src/errorRegistry.js.map +1 -0
- package/dist/src/fieldExtraction.d.ts +128 -27
- package/dist/src/fieldExtraction.d.ts.map +1 -0
- package/dist/src/fieldExtraction.js +100 -27
- package/dist/src/fieldExtraction.js.map +1 -0
- package/dist/src/flagResolver.d.ts +77 -10
- package/dist/src/flagResolver.d.ts.map +1 -0
- package/dist/src/flagResolver.js +22 -5
- package/dist/src/flagResolver.js.map +1 -0
- package/dist/src/flagSemantics.d.ts +80 -4
- package/dist/src/flagSemantics.d.ts.map +1 -0
- package/dist/src/flagSemantics.js +78 -11
- package/dist/src/flagSemantics.js.map +1 -0
- package/dist/src/health/index.d.ts +103 -9
- package/dist/src/health/index.d.ts.map +1 -0
- package/dist/src/health/index.js +75 -26
- package/dist/src/health/index.js.map +1 -0
- package/dist/src/index.d.ts +34 -23
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +40 -28
- package/dist/src/index.js.map +1 -0
- package/dist/src/mviProjection.d.ts +43 -6
- package/dist/src/mviProjection.d.ts.map +1 -0
- package/dist/src/mviProjection.js +32 -5
- package/dist/src/mviProjection.js.map +1 -0
- package/dist/src/native-loader.d.ts +49 -0
- package/dist/src/native-loader.d.ts.map +1 -0
- package/dist/src/native-loader.js +56 -0
- package/dist/src/native-loader.js.map +1 -0
- package/dist/src/problemDetails.d.ts +71 -4
- package/dist/src/problemDetails.d.ts.map +1 -0
- package/dist/src/problemDetails.js +27 -3
- package/dist/src/problemDetails.js.map +1 -0
- package/dist/src/shutdown/index.d.ts +103 -9
- package/dist/src/shutdown/index.d.ts.map +1 -0
- package/dist/src/shutdown/index.js +78 -12
- package/dist/src/shutdown/index.js.map +1 -0
- package/dist/src/tokenEstimator.d.ts +98 -11
- package/dist/src/tokenEstimator.d.ts.map +1 -0
- package/dist/src/tokenEstimator.js +91 -13
- package/dist/src/tokenEstimator.js.map +1 -0
- package/dist/src/types.d.ts +477 -11
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +76 -2
- package/dist/src/types.js.map +1 -0
- package/dist/src/validateEnvelope.d.ts +61 -2
- package/dist/src/validateEnvelope.d.ts.map +1 -0
- package/dist/src/validateEnvelope.js +81 -14
- package/dist/src/validateEnvelope.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/lafs.md +3 -4
- package/package.json +14 -12
- package/schemas/v1/agent-card.schema.json +0 -0
- package/schemas/v1/conformance-profiles.json +0 -0
- package/schemas/v1/context-ledger.schema.json +0 -0
- package/schemas/v1/discovery.schema.json +0 -0
- package/schemas/v1/envelope.schema.json +0 -0
- package/schemas/v1/error-registry.json +0 -0
- package/dist/src/mcpAdapter.d.ts +0 -28
- package/dist/src/mcpAdapter.js +0 -281
package/dist/src/compliance.d.ts
CHANGED
|
@@ -1,31 +1,208 @@
|
|
|
1
|
-
import type { ConformanceReport, FlagInput, LAFSEnvelope } from
|
|
2
|
-
import { type EnvelopeValidationResult } from
|
|
3
|
-
|
|
1
|
+
import type { ConformanceReport, FlagInput, LAFSEnvelope } from './types.js';
|
|
2
|
+
import { type EnvelopeValidationResult } from './validateEnvelope.js';
|
|
3
|
+
/**
|
|
4
|
+
* Identifies which stage of the compliance pipeline produced an issue.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Used by {@link ComplianceIssue} to classify where a failure originated
|
|
8
|
+
* during multi-stage LAFS compliance enforcement.
|
|
9
|
+
*/
|
|
10
|
+
export type ComplianceStage = 'schema' | 'envelope' | 'flags' | 'format';
|
|
11
|
+
/**
|
|
12
|
+
* Describes a single compliance failure detected during enforcement.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Each issue maps to a specific pipeline stage and includes a human-readable
|
|
16
|
+
* message with an optional detail string for diagnostics.
|
|
17
|
+
*/
|
|
4
18
|
export interface ComplianceIssue {
|
|
19
|
+
/** The pipeline stage that produced this issue. */
|
|
5
20
|
stage: ComplianceStage;
|
|
21
|
+
/** A short, human-readable description of the failure. */
|
|
6
22
|
message: string;
|
|
23
|
+
/**
|
|
24
|
+
* Additional diagnostic information about the failure.
|
|
25
|
+
* @defaultValue undefined
|
|
26
|
+
*/
|
|
7
27
|
detail?: string;
|
|
8
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Options controlling which compliance stages are executed.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* All options default to safe values so callers can pass an empty object
|
|
34
|
+
* and still get schema validation.
|
|
35
|
+
*/
|
|
9
36
|
export interface EnforceComplianceOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Whether to run envelope conformance checks after schema validation.
|
|
39
|
+
* @defaultValue true
|
|
40
|
+
*/
|
|
10
41
|
checkConformance?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Whether to run flag conformance checks.
|
|
44
|
+
* @defaultValue false
|
|
45
|
+
*/
|
|
11
46
|
checkFlags?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Flag input to validate when {@link checkFlags} is enabled.
|
|
49
|
+
* @defaultValue undefined
|
|
50
|
+
*/
|
|
12
51
|
flags?: FlagInput;
|
|
52
|
+
/**
|
|
53
|
+
* When true, asserts that the resolved output format is JSON.
|
|
54
|
+
* @defaultValue false
|
|
55
|
+
*/
|
|
13
56
|
requireJsonOutput?: boolean;
|
|
14
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Aggregated result of a full LAFS compliance run.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* Contains the overall pass/fail status, per-stage reports, and the
|
|
63
|
+
* parsed envelope when schema validation succeeds.
|
|
64
|
+
*/
|
|
15
65
|
export interface ComplianceResult {
|
|
66
|
+
/** True when every executed stage passes with zero issues. */
|
|
16
67
|
ok: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* The parsed envelope, present only when schema validation succeeds.
|
|
70
|
+
* @defaultValue undefined
|
|
71
|
+
*/
|
|
17
72
|
envelope?: LAFSEnvelope;
|
|
73
|
+
/** Schema validation result from the native validator (or AJV fallback). */
|
|
18
74
|
validation: EnvelopeValidationResult;
|
|
75
|
+
/**
|
|
76
|
+
* Envelope conformance report, present when {@link EnforceComplianceOptions.checkConformance} is true.
|
|
77
|
+
* @defaultValue undefined
|
|
78
|
+
*/
|
|
19
79
|
envelopeConformance?: ConformanceReport;
|
|
80
|
+
/**
|
|
81
|
+
* Flag conformance report, present when {@link EnforceComplianceOptions.checkFlags} is true.
|
|
82
|
+
* @defaultValue undefined
|
|
83
|
+
*/
|
|
20
84
|
flagConformance?: ConformanceReport;
|
|
85
|
+
/** All issues collected across every executed stage. */
|
|
21
86
|
issues: ComplianceIssue[];
|
|
22
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Error thrown when {@link assertCompliance} or {@link withCompliance} detects failures.
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* Extends `Error` with a structured `issues` array so callers can
|
|
93
|
+
* programmatically inspect each failure without parsing the message string.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* try {
|
|
98
|
+
* assertCompliance(envelope);
|
|
99
|
+
* } catch (err) {
|
|
100
|
+
* if (err instanceof ComplianceError) {
|
|
101
|
+
* console.log(err.issues);
|
|
102
|
+
* }
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
23
106
|
export declare class ComplianceError extends Error {
|
|
107
|
+
/** The structured list of compliance issues that caused this error. */
|
|
24
108
|
readonly issues: ComplianceIssue[];
|
|
109
|
+
/**
|
|
110
|
+
* Creates a new ComplianceError from a list of issues.
|
|
111
|
+
*
|
|
112
|
+
* @param issues - The compliance issues that triggered this error.
|
|
113
|
+
*/
|
|
25
114
|
constructor(issues: ComplianceIssue[]);
|
|
26
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Runs the full LAFS compliance pipeline against an unknown input value.
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
* Executes stages in order: schema validation, envelope conformance,
|
|
121
|
+
* flag conformance, and output-format assertion. Each stage is gated
|
|
122
|
+
* by the corresponding option. Schema validation always runs first;
|
|
123
|
+
* if it fails, later stages are skipped.
|
|
124
|
+
*
|
|
125
|
+
* @param input - The raw value to validate as a LAFS envelope.
|
|
126
|
+
* @param options - Controls which optional stages execute.
|
|
127
|
+
* @returns A {@link ComplianceResult} with the aggregate pass/fail status and per-stage reports.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const result = enforceCompliance(rawJson, { checkFlags: true, flags: { jsonFlag: true } });
|
|
132
|
+
* if (!result.ok) {
|
|
133
|
+
* console.error(result.issues);
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
27
137
|
export declare function enforceCompliance(input: unknown, options?: EnforceComplianceOptions): ComplianceResult;
|
|
138
|
+
/**
|
|
139
|
+
* Validates input and throws {@link ComplianceError} on any failure.
|
|
140
|
+
*
|
|
141
|
+
* @remarks
|
|
142
|
+
* Thin wrapper around {@link enforceCompliance} that converts a non-ok
|
|
143
|
+
* result into an exception. Useful in pipelines where compliance is a
|
|
144
|
+
* hard gate.
|
|
145
|
+
*
|
|
146
|
+
* @param input - The raw value to validate as a LAFS envelope.
|
|
147
|
+
* @param options - Controls which optional stages execute.
|
|
148
|
+
* @returns The validated {@link LAFSEnvelope} when all stages pass.
|
|
149
|
+
* @throws {@link ComplianceError} When any compliance stage fails.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* const envelope = assertCompliance(rawJson);
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
28
156
|
export declare function assertCompliance(input: unknown, options?: EnforceComplianceOptions): LAFSEnvelope;
|
|
157
|
+
/**
|
|
158
|
+
* Wraps an envelope-producing function with automatic compliance enforcement.
|
|
159
|
+
*
|
|
160
|
+
* @remarks
|
|
161
|
+
* Returns a new async function that calls the producer, then pipes the
|
|
162
|
+
* result through {@link assertCompliance}. If the producer returns a
|
|
163
|
+
* non-compliant envelope, the wrapper throws {@link ComplianceError}.
|
|
164
|
+
*
|
|
165
|
+
* @typeParam TArgs - Argument types forwarded to the producer function.
|
|
166
|
+
* @typeParam TResult - The envelope subtype returned by the producer.
|
|
167
|
+
* @param producer - A sync or async function that produces a LAFS envelope.
|
|
168
|
+
* @param options - Compliance options forwarded to {@link assertCompliance}.
|
|
169
|
+
* @returns An async function with the same signature that enforces compliance on every call.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* const safeFetch = withCompliance(fetchEnvelope, { checkConformance: true });
|
|
174
|
+
* const envelope = await safeFetch('/api/data');
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
29
177
|
export declare function withCompliance<TArgs extends unknown[], TResult extends LAFSEnvelope>(producer: (...args: TArgs) => TResult | Promise<TResult>, options?: EnforceComplianceOptions): (...args: TArgs) => Promise<LAFSEnvelope>;
|
|
178
|
+
/**
|
|
179
|
+
* Middleware signature for intercepting LAFS envelopes in a pipeline.
|
|
180
|
+
*
|
|
181
|
+
* @remarks
|
|
182
|
+
* Follows a standard middleware pattern: receive the current envelope,
|
|
183
|
+
* call `next()` to continue the chain, then optionally transform the result.
|
|
184
|
+
*
|
|
185
|
+
* @param envelope - The envelope entering this middleware.
|
|
186
|
+
* @param next - Callback that invokes the next middleware or terminal handler.
|
|
187
|
+
* @returns The (possibly transformed) envelope to pass upstream.
|
|
188
|
+
*/
|
|
30
189
|
export type ComplianceMiddleware = (envelope: LAFSEnvelope, next: () => LAFSEnvelope | Promise<LAFSEnvelope>) => Promise<LAFSEnvelope> | LAFSEnvelope;
|
|
190
|
+
/**
|
|
191
|
+
* Creates a {@link ComplianceMiddleware} that enforces LAFS compliance on the next handler's output.
|
|
192
|
+
*
|
|
193
|
+
* @remarks
|
|
194
|
+
* The returned middleware calls `next()`, then pipes the candidate envelope
|
|
195
|
+
* through {@link assertCompliance}. Non-compliant envelopes cause a
|
|
196
|
+
* {@link ComplianceError} to propagate.
|
|
197
|
+
*
|
|
198
|
+
* @param options - Compliance options forwarded to {@link assertCompliance}.
|
|
199
|
+
* @returns A middleware function that validates the downstream envelope.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* const mw = createComplianceMiddleware({ checkConformance: true });
|
|
204
|
+
* const result = await mw(currentEnvelope, () => produceEnvelope());
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
31
207
|
export declare function createComplianceMiddleware(options?: EnforceComplianceOptions): ComplianceMiddleware;
|
|
208
|
+
//# sourceMappingURL=compliance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compliance.d.ts","sourceRoot":"","sources":["../../src/compliance.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAEL,KAAK,wBAAwB,EAE9B,MAAM,uBAAuB,CAAC;AAE/B;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD,KAAK,EAAE,eAAe,CAAC;IACvB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG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CACjC,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,KAC7C,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;AAE1C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,wBAA6B,GACrC,oBAAoB,CAKtB"}
|
package/dist/src/compliance.js
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
|
-
import { runEnvelopeConformance, runFlagConformance } from
|
|
2
|
-
import { resolveOutputFormat } from
|
|
3
|
-
import { assertEnvelope, validateEnvelope } from
|
|
1
|
+
import { runEnvelopeConformance, runFlagConformance } from './conformance.js';
|
|
2
|
+
import { resolveOutputFormat } from './flagSemantics.js';
|
|
3
|
+
import { assertEnvelope, validateEnvelope, } from './validateEnvelope.js';
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when {@link assertCompliance} or {@link withCompliance} detects failures.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Extends `Error` with a structured `issues` array so callers can
|
|
9
|
+
* programmatically inspect each failure without parsing the message string.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* try {
|
|
14
|
+
* assertCompliance(envelope);
|
|
15
|
+
* } catch (err) {
|
|
16
|
+
* if (err instanceof ComplianceError) {
|
|
17
|
+
* console.log(err.issues);
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
4
22
|
export class ComplianceError extends Error {
|
|
23
|
+
/** The structured list of compliance issues that caused this error. */
|
|
5
24
|
issues;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new ComplianceError from a list of issues.
|
|
27
|
+
*
|
|
28
|
+
* @param issues - The compliance issues that triggered this error.
|
|
29
|
+
*/
|
|
6
30
|
constructor(issues) {
|
|
7
|
-
super(`LAFS compliance failed: ${issues.map((issue) => issue.message).join(
|
|
8
|
-
this.name =
|
|
31
|
+
super(`LAFS compliance failed: ${issues.map((issue) => issue.message).join('; ')}`);
|
|
32
|
+
this.name = 'ComplianceError';
|
|
9
33
|
this.issues = issues;
|
|
10
34
|
}
|
|
11
35
|
}
|
|
@@ -18,14 +42,35 @@ function conformanceIssues(report, stage) {
|
|
|
18
42
|
detail: check.detail,
|
|
19
43
|
}));
|
|
20
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Runs the full LAFS compliance pipeline against an unknown input value.
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* Executes stages in order: schema validation, envelope conformance,
|
|
50
|
+
* flag conformance, and output-format assertion. Each stage is gated
|
|
51
|
+
* by the corresponding option. Schema validation always runs first;
|
|
52
|
+
* if it fails, later stages are skipped.
|
|
53
|
+
*
|
|
54
|
+
* @param input - The raw value to validate as a LAFS envelope.
|
|
55
|
+
* @param options - Controls which optional stages execute.
|
|
56
|
+
* @returns A {@link ComplianceResult} with the aggregate pass/fail status and per-stage reports.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const result = enforceCompliance(rawJson, { checkFlags: true, flags: { jsonFlag: true } });
|
|
61
|
+
* if (!result.ok) {
|
|
62
|
+
* console.error(result.issues);
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
21
66
|
export function enforceCompliance(input, options = {}) {
|
|
22
|
-
const { checkConformance = true, checkFlags = false, flags, requireJsonOutput = false
|
|
67
|
+
const { checkConformance = true, checkFlags = false, flags, requireJsonOutput = false } = options;
|
|
23
68
|
const issues = [];
|
|
24
69
|
const validation = validateEnvelope(input);
|
|
25
70
|
if (!validation.valid) {
|
|
26
71
|
issues.push(...validation.errors.map((error) => ({
|
|
27
|
-
stage:
|
|
28
|
-
message:
|
|
72
|
+
stage: 'schema',
|
|
73
|
+
message: 'schema validation failed',
|
|
29
74
|
detail: error,
|
|
30
75
|
})));
|
|
31
76
|
return {
|
|
@@ -39,22 +84,22 @@ export function enforceCompliance(input, options = {}) {
|
|
|
39
84
|
if (checkConformance) {
|
|
40
85
|
envelopeConformance = runEnvelopeConformance(envelope);
|
|
41
86
|
if (!envelopeConformance.ok) {
|
|
42
|
-
issues.push(...conformanceIssues(envelopeConformance,
|
|
87
|
+
issues.push(...conformanceIssues(envelopeConformance, 'envelope'));
|
|
43
88
|
}
|
|
44
89
|
}
|
|
45
90
|
let flagConformance;
|
|
46
91
|
if (checkFlags && flags) {
|
|
47
92
|
flagConformance = runFlagConformance(flags);
|
|
48
93
|
if (!flagConformance.ok) {
|
|
49
|
-
issues.push(...conformanceIssues(flagConformance,
|
|
94
|
+
issues.push(...conformanceIssues(flagConformance, 'flags'));
|
|
50
95
|
}
|
|
51
96
|
}
|
|
52
97
|
if (requireJsonOutput) {
|
|
53
98
|
const resolved = resolveOutputFormat(flags ?? {});
|
|
54
|
-
if (resolved.format !==
|
|
99
|
+
if (resolved.format !== 'json') {
|
|
55
100
|
issues.push({
|
|
56
|
-
stage:
|
|
57
|
-
message:
|
|
101
|
+
stage: 'format',
|
|
102
|
+
message: 'non-json output format resolved',
|
|
58
103
|
detail: `resolved format is ${resolved.format}`,
|
|
59
104
|
});
|
|
60
105
|
}
|
|
@@ -68,6 +113,24 @@ export function enforceCompliance(input, options = {}) {
|
|
|
68
113
|
issues,
|
|
69
114
|
};
|
|
70
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Validates input and throws {@link ComplianceError} on any failure.
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
* Thin wrapper around {@link enforceCompliance} that converts a non-ok
|
|
121
|
+
* result into an exception. Useful in pipelines where compliance is a
|
|
122
|
+
* hard gate.
|
|
123
|
+
*
|
|
124
|
+
* @param input - The raw value to validate as a LAFS envelope.
|
|
125
|
+
* @param options - Controls which optional stages execute.
|
|
126
|
+
* @returns The validated {@link LAFSEnvelope} when all stages pass.
|
|
127
|
+
* @throws {@link ComplianceError} When any compliance stage fails.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const envelope = assertCompliance(rawJson);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
71
134
|
export function assertCompliance(input, options = {}) {
|
|
72
135
|
const result = enforceCompliance(input, options);
|
|
73
136
|
if (!result.ok || !result.envelope) {
|
|
@@ -75,15 +138,53 @@ export function assertCompliance(input, options = {}) {
|
|
|
75
138
|
}
|
|
76
139
|
return result.envelope;
|
|
77
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Wraps an envelope-producing function with automatic compliance enforcement.
|
|
143
|
+
*
|
|
144
|
+
* @remarks
|
|
145
|
+
* Returns a new async function that calls the producer, then pipes the
|
|
146
|
+
* result through {@link assertCompliance}. If the producer returns a
|
|
147
|
+
* non-compliant envelope, the wrapper throws {@link ComplianceError}.
|
|
148
|
+
*
|
|
149
|
+
* @typeParam TArgs - Argument types forwarded to the producer function.
|
|
150
|
+
* @typeParam TResult - The envelope subtype returned by the producer.
|
|
151
|
+
* @param producer - A sync or async function that produces a LAFS envelope.
|
|
152
|
+
* @param options - Compliance options forwarded to {@link assertCompliance}.
|
|
153
|
+
* @returns An async function with the same signature that enforces compliance on every call.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* const safeFetch = withCompliance(fetchEnvelope, { checkConformance: true });
|
|
158
|
+
* const envelope = await safeFetch('/api/data');
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
78
161
|
export function withCompliance(producer, options = {}) {
|
|
79
162
|
return async (...args) => {
|
|
80
163
|
const envelope = await producer(...args);
|
|
81
164
|
return assertCompliance(envelope, options);
|
|
82
165
|
};
|
|
83
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Creates a {@link ComplianceMiddleware} that enforces LAFS compliance on the next handler's output.
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* The returned middleware calls `next()`, then pipes the candidate envelope
|
|
172
|
+
* through {@link assertCompliance}. Non-compliant envelopes cause a
|
|
173
|
+
* {@link ComplianceError} to propagate.
|
|
174
|
+
*
|
|
175
|
+
* @param options - Compliance options forwarded to {@link assertCompliance}.
|
|
176
|
+
* @returns A middleware function that validates the downstream envelope.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* const mw = createComplianceMiddleware({ checkConformance: true });
|
|
181
|
+
* const result = await mw(currentEnvelope, () => produceEnvelope());
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
84
184
|
export function createComplianceMiddleware(options = {}) {
|
|
85
185
|
return async (_envelope, next) => {
|
|
86
186
|
const candidate = await next();
|
|
87
187
|
return assertCompliance(candidate, options);
|
|
88
188
|
};
|
|
89
189
|
}
|
|
190
|
+
//# sourceMappingURL=compliance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compliance.js","sourceRoot":"","sources":["../../src/compliance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EACL,cAAc,EAEd,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AA2F/B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,uEAAuE;IAC9D,MAAM,CAAoB;IAEnC;;;;OAIG;IACH,YAAY,MAAyB;QACnC,KAAK,CAAC,2BAA2B,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACpF,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,SAAS,iBAAiB,CAAC,MAAyB,EAAE,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D,EACxD,UAAoC,EAAE;IAEtC,OAAO,KAAK,EAAE,GAAG,IAAW,EAAyB,EAAE;QACrD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;QACzC,OAAO,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC,CAAC;AACJ,CAAC;AAkBD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,0BAA0B,CACxC,UAAoC,EAAE;IAEtC,OAAO,KAAK,EAAE,SAAuB,EAAE,IAAgD,EAAE,EAAE;QACzF,MAAM,SAAS,GAAG,MAAM,IAAI,EAAE,CAAC;QAC/B,OAAO,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,60 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { type ConformanceTier } from './conformanceProfiles.js';
|
|
2
|
+
import type { ConformanceReport, FlagInput } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Options for configuring envelope conformance checking.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* When a tier is specified, only the checks belonging to that tier (and below)
|
|
8
|
+
* are included in the final report.
|
|
9
|
+
*/
|
|
3
10
|
export interface EnvelopeConformanceOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The conformance tier to filter checks by.
|
|
13
|
+
* @defaultValue undefined
|
|
14
|
+
*/
|
|
4
15
|
tier?: ConformanceTier;
|
|
5
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Runs the full suite of LAFS envelope conformance checks.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Validates schema, envelope invariants, error-code registration,
|
|
22
|
+
* agent-action validity, transport mapping consistency, context mutation
|
|
23
|
+
* rules, MVI level, strict-mode behavior, pagination mode consistency,
|
|
24
|
+
* strict-mode enforcement, and context preservation. When a
|
|
25
|
+
* {@link EnvelopeConformanceOptions.tier} is specified, only checks
|
|
26
|
+
* belonging to that tier are included in the returned report.
|
|
27
|
+
*
|
|
28
|
+
* @param envelope - The raw value to validate as a LAFS envelope.
|
|
29
|
+
* @param options - Optional tier filter for the conformance checks.
|
|
30
|
+
* @returns A {@link ConformanceReport} with individual check results and an overall pass/fail.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const report = runEnvelopeConformance(parsedJson, { tier: 'core' });
|
|
35
|
+
* if (!report.ok) {
|
|
36
|
+
* console.error(report.checks.filter(c => !c.pass));
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
6
40
|
export declare function runEnvelopeConformance(envelope: unknown, options?: EnvelopeConformanceOptions): ConformanceReport;
|
|
41
|
+
/**
|
|
42
|
+
* Runs LAFS flag-semantics conformance checks against a set of flag inputs.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Verifies that conflicting flags (`--human` + `--json`) are properly rejected,
|
|
46
|
+
* the protocol default resolves to JSON, and project/user config overrides are
|
|
47
|
+
* respected. Catches {@link LAFSFlagError} with code `E_FORMAT_CONFLICT` as a
|
|
48
|
+
* valid conformance outcome.
|
|
49
|
+
*
|
|
50
|
+
* @param flags - The flag input to validate.
|
|
51
|
+
* @returns A {@link ConformanceReport} with individual check results and an overall pass/fail.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const report = runFlagConformance({ humanFlag: true, jsonFlag: false });
|
|
56
|
+
* console.log(report.ok); // true
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
7
59
|
export declare function runFlagConformance(flags: FlagInput): ConformanceReport;
|
|
60
|
+
//# sourceMappingURL=conformance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conformance.d.ts","sourceRoot":"","sources":["../../src/conformance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAoB,MAAM,0BAA0B,CAAC;AAGlF,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAa/D;;;;;;GAMG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,OAAO,EACjB,OAAO,GAAE,0BAA+B,GACvC,iBAAiB,CA8UnB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,GAAG,iBAAiB,CA+CtE"}
|