@cleocode/lafs 2026.4.0 → 2026.4.4
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/README.md +97 -68
- package/dist/src/a2a/bindings/grpc.d.ts +117 -11
- package/dist/src/a2a/bindings/grpc.d.ts.map +1 -1
- package/dist/src/a2a/bindings/grpc.js +79 -8
- package/dist/src/a2a/bindings/grpc.js.map +1 -1
- package/dist/src/a2a/bindings/http.d.ts +129 -14
- package/dist/src/a2a/bindings/http.d.ts.map +1 -1
- package/dist/src/a2a/bindings/http.js +93 -12
- package/dist/src/a2a/bindings/http.js.map +1 -1
- package/dist/src/a2a/bindings/index.d.ts +80 -7
- package/dist/src/a2a/bindings/index.d.ts.map +1 -1
- package/dist/src/a2a/bindings/index.js +69 -2
- package/dist/src/a2a/bindings/index.js.map +1 -1
- package/dist/src/a2a/bindings/jsonrpc.d.ts +193 -9
- package/dist/src/a2a/bindings/jsonrpc.d.ts.map +1 -1
- package/dist/src/a2a/bindings/jsonrpc.js +152 -9
- package/dist/src/a2a/bindings/jsonrpc.js.map +1 -1
- package/dist/src/a2a/bridge.d.ts +232 -37
- package/dist/src/a2a/bridge.d.ts.map +1 -1
- package/dist/src/a2a/bridge.js +172 -24
- package/dist/src/a2a/bridge.js.map +1 -1
- package/dist/src/a2a/extensions.d.ts +221 -12
- package/dist/src/a2a/extensions.d.ts.map +1 -1
- package/dist/src/a2a/extensions.js +175 -11
- package/dist/src/a2a/extensions.js.map +1 -1
- package/dist/src/a2a/index.d.ts +2 -0
- package/dist/src/a2a/index.d.ts.map +1 -1
- package/dist/src/a2a/index.js +2 -0
- package/dist/src/a2a/index.js.map +1 -1
- package/dist/src/a2a/streaming.d.ts +274 -2
- package/dist/src/a2a/streaming.d.ts.map +1 -1
- package/dist/src/a2a/streaming.js +245 -2
- package/dist/src/a2a/streaming.js.map +1 -1
- package/dist/src/a2a/task-lifecycle.d.ts +339 -19
- package/dist/src/a2a/task-lifecycle.d.ts.map +1 -1
- package/dist/src/a2a/task-lifecycle.js +302 -19
- package/dist/src/a2a/task-lifecycle.js.map +1 -1
- package/dist/src/budgetEnforcement.d.ts +88 -14
- package/dist/src/budgetEnforcement.d.ts.map +1 -1
- package/dist/src/budgetEnforcement.js +132 -19
- package/dist/src/budgetEnforcement.js.map +1 -1
- package/dist/src/circuit-breaker/index.d.ts +254 -9
- package/dist/src/circuit-breaker/index.d.ts.map +1 -1
- package/dist/src/circuit-breaker/index.js +218 -9
- package/dist/src/circuit-breaker/index.js.map +1 -1
- package/dist/src/compliance.d.ts +176 -0
- package/dist/src/compliance.d.ts.map +1 -1
- package/dist/src/compliance.js +100 -0
- package/dist/src/compliance.js.map +1 -1
- package/dist/src/conformance.d.ts +52 -0
- package/dist/src/conformance.d.ts.map +1 -1
- package/dist/src/conformance.js +41 -0
- package/dist/src/conformance.js.map +1 -1
- package/dist/src/conformanceProfiles.d.ts +66 -0
- package/dist/src/conformanceProfiles.d.ts.map +1 -1
- package/dist/src/conformanceProfiles.js +51 -0
- package/dist/src/conformanceProfiles.js.map +1 -1
- package/dist/src/deprecationRegistry.d.ts +80 -0
- package/dist/src/deprecationRegistry.d.ts.map +1 -1
- package/dist/src/deprecationRegistry.js +50 -0
- package/dist/src/deprecationRegistry.js.map +1 -1
- package/dist/src/discovery.d.ts +344 -63
- package/dist/src/discovery.d.ts.map +1 -1
- package/dist/src/discovery.js +67 -13
- package/dist/src/discovery.js.map +1 -1
- package/dist/src/envelope.d.ts +252 -0
- package/dist/src/envelope.d.ts.map +1 -1
- package/dist/src/envelope.js +165 -0
- package/dist/src/envelope.js.map +1 -1
- package/dist/src/errorRegistry.d.ts +159 -0
- package/dist/src/errorRegistry.d.ts.map +1 -1
- package/dist/src/errorRegistry.js +115 -0
- package/dist/src/errorRegistry.js.map +1 -1
- package/dist/src/fieldExtraction.d.ts +125 -25
- package/dist/src/fieldExtraction.d.ts.map +1 -1
- package/dist/src/fieldExtraction.js +85 -16
- package/dist/src/fieldExtraction.js.map +1 -1
- package/dist/src/flagResolver.d.ts +75 -9
- package/dist/src/flagResolver.d.ts.map +1 -1
- package/dist/src/flagResolver.js +20 -4
- package/dist/src/flagResolver.js.map +1 -1
- package/dist/src/flagSemantics.d.ts +76 -1
- package/dist/src/flagSemantics.d.ts.map +1 -1
- package/dist/src/flagSemantics.js +66 -0
- package/dist/src/flagSemantics.js.map +1 -1
- package/dist/src/health/index.d.ts +87 -6
- package/dist/src/health/index.d.ts.map +1 -1
- package/dist/src/health/index.js +54 -6
- package/dist/src/health/index.js.map +1 -1
- package/dist/src/index.d.ts +12 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +12 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/mviProjection.d.ts +42 -6
- package/dist/src/mviProjection.d.ts.map +1 -1
- package/dist/src/mviProjection.js +31 -5
- package/dist/src/mviProjection.js.map +1 -1
- 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 +70 -4
- package/dist/src/problemDetails.d.ts.map +1 -1
- package/dist/src/problemDetails.js +21 -3
- package/dist/src/problemDetails.js.map +1 -1
- package/dist/src/shutdown/index.d.ts +96 -7
- package/dist/src/shutdown/index.d.ts.map +1 -1
- package/dist/src/shutdown/index.js +72 -7
- package/dist/src/shutdown/index.js.map +1 -1
- package/dist/src/tokenEstimator.d.ts +97 -11
- package/dist/src/tokenEstimator.d.ts.map +1 -1
- package/dist/src/tokenEstimator.js +90 -11
- package/dist/src/tokenEstimator.js.map +1 -1
- package/dist/src/types.d.ts +467 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +64 -0
- package/dist/src/types.js.map +1 -1
- package/dist/src/validateEnvelope.d.ts +59 -1
- package/dist/src/validateEnvelope.d.ts.map +1 -1
- package/dist/src/validateEnvelope.js +75 -9
- package/dist/src/validateEnvelope.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/lafs.md +3 -4
- package/package.json +6 -3
- package/dist/src/mcpAdapter.d.ts +0 -29
- package/dist/src/mcpAdapter.d.ts.map +0 -1
- package/dist/src/mcpAdapter.js +0 -286
- package/dist/src/mcpAdapter.js.map +0 -1
- package/schemas/v1/conformance-profiles.d.ts +0 -15
- package/schemas/v1/envelope.schema.d.ts +0 -14
- package/schemas/v1/error-registry.d.ts +0 -24
package/dist/src/discovery.js
CHANGED
|
@@ -22,7 +22,16 @@ catch {
|
|
|
22
22
|
// Utility Functions
|
|
23
23
|
// ============================================================================
|
|
24
24
|
/**
|
|
25
|
-
* Build absolute URL from base and path
|
|
25
|
+
* Build an absolute URL from a base and path.
|
|
26
|
+
*
|
|
27
|
+
* @param base - Base URL prefix (may be `undefined` to infer from request)
|
|
28
|
+
* @param path - Relative or absolute path
|
|
29
|
+
* @param req - Optional Express request for protocol/host inference
|
|
30
|
+
* @returns Absolute URL string
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Resolution order: if `path` is already absolute, return as-is; otherwise
|
|
34
|
+
* combine with `base`, or fall back to request headers.
|
|
26
35
|
*/
|
|
27
36
|
function buildUrl(base, path, req) {
|
|
28
37
|
if (path.startsWith('http://') || path.startsWith('https://')) {
|
|
@@ -41,13 +50,29 @@ function buildUrl(base, path, req) {
|
|
|
41
50
|
return path.startsWith('/') ? path : `/${path}`;
|
|
42
51
|
}
|
|
43
52
|
/**
|
|
44
|
-
* Generate ETag from content
|
|
53
|
+
* Generate an ETag from content.
|
|
54
|
+
*
|
|
55
|
+
* @param content - Serialized content string
|
|
56
|
+
* @returns Quoted SHA-256 ETag (first 32 hex chars)
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* Uses SHA-256 truncated to 32 hex characters for a compact but
|
|
60
|
+
* collision-resistant ETag value.
|
|
45
61
|
*/
|
|
46
62
|
function generateETag(content) {
|
|
47
63
|
return `"${createHash('sha256').update(content).digest('hex').slice(0, 32)}"`;
|
|
48
64
|
}
|
|
49
65
|
/**
|
|
50
|
-
* Build A2A Agent Card from configuration
|
|
66
|
+
* Build an A2A Agent Card from configuration.
|
|
67
|
+
*
|
|
68
|
+
* @param config - Discovery configuration
|
|
69
|
+
* @param req - Optional Express request for URL construction
|
|
70
|
+
* @returns Fully-populated {@link AgentCard}
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* Handles automatic migration from legacy `service` config to the A2A v1.0 format
|
|
74
|
+
* with a console deprecation warning. When `autoIncludeLafsExtension` is set, the
|
|
75
|
+
* LAFS extension is appended to the card's capabilities.
|
|
51
76
|
*/
|
|
52
77
|
function buildAgentCard(config, req) {
|
|
53
78
|
const schemaUrl = config.schemaUrl || 'https://lafs.dev/schemas/v1/agent-card.schema.json';
|
|
@@ -105,8 +130,17 @@ function buildAgentCard(config, req) {
|
|
|
105
130
|
return card;
|
|
106
131
|
}
|
|
107
132
|
/**
|
|
108
|
-
* Build legacy discovery document for backward compatibility
|
|
109
|
-
*
|
|
133
|
+
* Build a legacy discovery document for backward compatibility.
|
|
134
|
+
*
|
|
135
|
+
* @param config - Discovery configuration
|
|
136
|
+
* @param req - Optional Express request for URL construction
|
|
137
|
+
* @returns Legacy {@link DiscoveryDocument}
|
|
138
|
+
*
|
|
139
|
+
* @remarks
|
|
140
|
+
* Generates the pre-A2A discovery document format from either the legacy
|
|
141
|
+
* `service` config or the modern `agent` config.
|
|
142
|
+
*
|
|
143
|
+
* @deprecated Will be removed in v2.0.0.
|
|
110
144
|
*/
|
|
111
145
|
function buildLegacyDiscoveryDocument(config, req) {
|
|
112
146
|
const schemaUrl = config.schemaUrl || 'https://lafs.dev/schemas/v1/discovery.schema.json';
|
|
@@ -140,14 +174,17 @@ function buildLegacyDiscoveryDocument(config, req) {
|
|
|
140
174
|
// Middleware
|
|
141
175
|
// ============================================================================
|
|
142
176
|
/**
|
|
143
|
-
* Create Express middleware for serving A2A Agent Card
|
|
144
|
-
*
|
|
145
|
-
* Serves A2A-compliant Agent Card at /.well-known/agent-card.json
|
|
146
|
-
* Maintains backward compatibility with legacy /.well-known/lafs.json
|
|
177
|
+
* Create Express middleware for serving A2A Agent Card.
|
|
147
178
|
*
|
|
148
179
|
* @param config - Discovery configuration (A2A v1.0 format)
|
|
149
|
-
* @param options - Middleware options
|
|
150
|
-
* @returns Express RequestHandler
|
|
180
|
+
* @param options - Middleware options for path routing and caching
|
|
181
|
+
* @returns Express RequestHandler that serves the Agent Card
|
|
182
|
+
*
|
|
183
|
+
* @remarks
|
|
184
|
+
* Serves an A2A-compliant Agent Card at `/.well-known/agent-card.json`.
|
|
185
|
+
* Maintains backward compatibility with the legacy `/.well-known/lafs.json`
|
|
186
|
+
* path (with deprecation warnings). Supports ETag-based conditional requests,
|
|
187
|
+
* HEAD requests, and configurable cache headers.
|
|
151
188
|
*
|
|
152
189
|
* @example
|
|
153
190
|
* ```typescript
|
|
@@ -301,10 +338,27 @@ export function discoveryMiddleware(config, options = {}) {
|
|
|
301
338
|
};
|
|
302
339
|
}
|
|
303
340
|
/**
|
|
304
|
-
* Fastify plugin for A2A Agent Card discovery
|
|
341
|
+
* Fastify plugin for A2A Agent Card discovery.
|
|
305
342
|
*
|
|
306
343
|
* @param fastify - Fastify instance
|
|
307
|
-
* @param options - Plugin options
|
|
344
|
+
* @param options - Plugin options containing `config` and optional `path`
|
|
345
|
+
* @returns Promise that resolves when the plugin is registered
|
|
346
|
+
*
|
|
347
|
+
* @remarks
|
|
348
|
+
* Registers a route on the Fastify instance to serve the A2A Agent Card
|
|
349
|
+
* with proper caching headers. The actual route registration depends on
|
|
350
|
+
* the Fastify API; this provides a type-safe plugin signature.
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* ```typescript
|
|
354
|
+
* import Fastify from "fastify";
|
|
355
|
+
* import { discoveryFastifyPlugin } from "@cleocode/lafs/discovery";
|
|
356
|
+
*
|
|
357
|
+
* const app = Fastify();
|
|
358
|
+
* app.register(discoveryFastifyPlugin, {
|
|
359
|
+
* config: { agent: { name: "my-agent", ... } },
|
|
360
|
+
* });
|
|
361
|
+
* ```
|
|
308
362
|
*/
|
|
309
363
|
export async function discoveryFastifyPlugin(fastify, options) {
|
|
310
364
|
const _path = options.path || '/.well-known/agent-card.json';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,8EAA8E;AAC9E,IAAI,GAAwB,CAAC;AAC7B,IAAI,CAAC;IACH,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACnC,CAAC;AAAC,MAAM,CAAC;IACP,GAAG,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACtC,CAAC;
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,8EAA8E;AAC9E,IAAI,GAAwB,CAAC;AAC7B,IAAI,CAAC;IACH,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACnC,CAAC;AAAC,MAAM,CAAC;IACP,GAAG,GAAG,OAA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AC;IAE/C,MAAM,QAAQ,GAAG,KAAK,EACpB,OAA0B,EAC1B,KAAiD,EACjD,EAAE;QACF,MAAM,GAAG,GAAG,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAChD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QAEhC,KAAK,CAAC,MAAM,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QACjD,KAAK,CAAC,MAAM,CAAC,eAAe,EAAE,mBAAmB,WAAW,EAAE,CAAC,CAAC;QAChE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAE3B,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;IAEF,2DAA2D;IAC3D,+CAA+C;AACjD,CAAC;AAED,+EAA+E;AAC/E,iCAAiC;AACjC,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,eAAe,mBAAmB,CAAC"}
|
package/dist/src/envelope.d.ts
CHANGED
|
@@ -1,28 +1,131 @@
|
|
|
1
1
|
import type { LAFSAgentAction, LAFSEnvelope, LAFSError, LAFSErrorCategory, LAFSMeta, LAFSTransport, MVILevel } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Canonical JSON Schema URL for the LAFS v1 envelope.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Every LAFS envelope includes this URL in its `$schema` field so that
|
|
7
|
+
* validators and tooling can locate the authoritative schema definition.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { LAFS_SCHEMA_URL } from '@cleocode/lafs';
|
|
12
|
+
* console.log(LAFS_SCHEMA_URL);
|
|
13
|
+
* // => 'https://lafs.dev/schemas/v1/envelope.schema.json'
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
2
16
|
export declare const LAFS_SCHEMA_URL: "https://lafs.dev/schemas/v1/envelope.schema.json";
|
|
17
|
+
/**
|
|
18
|
+
* Input for constructing the `_meta` block of a LAFS envelope.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Only `operation` and `requestId` are required; all other fields have
|
|
22
|
+
* sensible defaults (see {@link createEnvelope} for the resolution logic).
|
|
23
|
+
*/
|
|
3
24
|
export interface CreateEnvelopeMetaInput {
|
|
25
|
+
/** Dot-delimited operation identifier (e.g. `"tasks.list"`). */
|
|
4
26
|
operation: string;
|
|
27
|
+
/** Unique identifier for correlating this request/response pair. */
|
|
5
28
|
requestId: string;
|
|
29
|
+
/**
|
|
30
|
+
* Transport protocol for this envelope.
|
|
31
|
+
*
|
|
32
|
+
* @defaultValue 'sdk'
|
|
33
|
+
*/
|
|
6
34
|
transport?: LAFSTransport;
|
|
35
|
+
/**
|
|
36
|
+
* LAFS spec version to stamp on the envelope.
|
|
37
|
+
*
|
|
38
|
+
* @defaultValue '1.0.0'
|
|
39
|
+
*/
|
|
7
40
|
specVersion?: string;
|
|
41
|
+
/**
|
|
42
|
+
* JSON Schema version to stamp on the envelope.
|
|
43
|
+
*
|
|
44
|
+
* @defaultValue '1.0.0'
|
|
45
|
+
*/
|
|
8
46
|
schemaVersion?: string;
|
|
47
|
+
/**
|
|
48
|
+
* ISO 8601 timestamp; auto-generated when omitted.
|
|
49
|
+
*
|
|
50
|
+
* @defaultValue undefined
|
|
51
|
+
*/
|
|
9
52
|
timestamp?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Whether strict schema validation should be applied.
|
|
55
|
+
*
|
|
56
|
+
* @defaultValue true
|
|
57
|
+
*/
|
|
10
58
|
strict?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* MVI level as a string, or `true` for `'minimal'` / `false` for `'standard'`.
|
|
61
|
+
*
|
|
62
|
+
* @defaultValue 'standard'
|
|
63
|
+
*/
|
|
11
64
|
mvi?: MVILevel | boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Context ledger version the caller is operating against.
|
|
67
|
+
*
|
|
68
|
+
* @defaultValue 0
|
|
69
|
+
*/
|
|
12
70
|
contextVersion?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Session identifier for multi-step workflow correlation.
|
|
73
|
+
*
|
|
74
|
+
* @defaultValue undefined
|
|
75
|
+
*/
|
|
13
76
|
sessionId?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Non-fatal warnings to attach to the envelope metadata.
|
|
79
|
+
*
|
|
80
|
+
* @defaultValue undefined
|
|
81
|
+
*/
|
|
14
82
|
warnings?: LAFSMeta['warnings'];
|
|
15
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Input for creating a successful LAFS envelope.
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* When `success` is `true`, the `result` field carries the operation payload
|
|
89
|
+
* and `error` is forced to `null` in the output envelope.
|
|
90
|
+
*/
|
|
16
91
|
export interface CreateEnvelopeSuccessInput {
|
|
92
|
+
/** Discriminant marking this as a success input. */
|
|
17
93
|
success: true;
|
|
94
|
+
/** Operation result payload (object, array, or `null`). */
|
|
18
95
|
result: LAFSEnvelope['result'];
|
|
96
|
+
/**
|
|
97
|
+
* Pagination metadata for collection results.
|
|
98
|
+
*
|
|
99
|
+
* @defaultValue undefined
|
|
100
|
+
*/
|
|
19
101
|
page?: LAFSEnvelope['page'];
|
|
102
|
+
/**
|
|
103
|
+
* Must be `null` for success inputs; exists for type uniformity with error inputs.
|
|
104
|
+
*
|
|
105
|
+
* @defaultValue undefined
|
|
106
|
+
*/
|
|
20
107
|
error?: null;
|
|
108
|
+
/**
|
|
109
|
+
* Vendor or protocol extension data.
|
|
110
|
+
*
|
|
111
|
+
* @defaultValue undefined
|
|
112
|
+
*/
|
|
21
113
|
_extensions?: LAFSEnvelope['_extensions'];
|
|
114
|
+
/** Metadata input for constructing the envelope's `_meta` block. */
|
|
22
115
|
meta: CreateEnvelopeMetaInput;
|
|
23
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Input for creating a failing LAFS envelope.
|
|
119
|
+
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* When `success` is `false`, the `error` field is required and will be
|
|
122
|
+
* normalized (category, agent action, doc URL) via the error registry.
|
|
123
|
+
* An optional `result` can carry actionable data alongside the error.
|
|
124
|
+
*/
|
|
24
125
|
export interface CreateEnvelopeErrorInput {
|
|
126
|
+
/** Discriminant marking this as an error input. */
|
|
25
127
|
success: false;
|
|
128
|
+
/** Partial error object; at minimum `code` and `message` are required. */
|
|
26
129
|
error: Partial<LAFSError> & Pick<LAFSError, 'code' | 'message'>;
|
|
27
130
|
/**
|
|
28
131
|
* Optional result payload to include alongside the error.
|
|
@@ -32,30 +135,179 @@ export interface CreateEnvelopeErrorInput {
|
|
|
32
135
|
* and the detailed result in a single response.
|
|
33
136
|
*
|
|
34
137
|
* When omitted or null, the envelope emits `result: null` (default behavior).
|
|
138
|
+
*
|
|
139
|
+
* @defaultValue undefined
|
|
35
140
|
*/
|
|
36
141
|
result?: LAFSEnvelope['result'] | null;
|
|
142
|
+
/**
|
|
143
|
+
* Pagination metadata, if applicable even in error scenarios.
|
|
144
|
+
*
|
|
145
|
+
* @defaultValue undefined
|
|
146
|
+
*/
|
|
37
147
|
page?: LAFSEnvelope['page'];
|
|
148
|
+
/**
|
|
149
|
+
* Vendor or protocol extension data.
|
|
150
|
+
*
|
|
151
|
+
* @defaultValue undefined
|
|
152
|
+
*/
|
|
38
153
|
_extensions?: LAFSEnvelope['_extensions'];
|
|
154
|
+
/** Metadata input for constructing the envelope's `_meta` block. */
|
|
39
155
|
meta: CreateEnvelopeMetaInput;
|
|
40
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Discriminated union of success and error inputs for {@link createEnvelope}.
|
|
159
|
+
*
|
|
160
|
+
* @remarks
|
|
161
|
+
* The `success` boolean discriminant determines which branch is active and
|
|
162
|
+
* which fields are required.
|
|
163
|
+
*/
|
|
41
164
|
export type CreateEnvelopeInput = CreateEnvelopeSuccessInput | CreateEnvelopeErrorInput;
|
|
165
|
+
/**
|
|
166
|
+
* Default agent action for each error category.
|
|
167
|
+
*
|
|
168
|
+
* @remarks
|
|
169
|
+
* When a {@link LAFSError} does not specify an explicit `agentAction` and the
|
|
170
|
+
* error registry has no override, this map provides the fallback recommendation
|
|
171
|
+
* based on the error's category.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { CATEGORY_ACTION_MAP } from '@cleocode/lafs';
|
|
176
|
+
* const action = CATEGORY_ACTION_MAP['RATE_LIMIT']; // => 'wait'
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
42
179
|
export declare const CATEGORY_ACTION_MAP: Record<LAFSErrorCategory, LAFSAgentAction>;
|
|
180
|
+
/**
|
|
181
|
+
* Create a fully validated LAFS envelope from a success or error input.
|
|
182
|
+
*
|
|
183
|
+
* @param input - Discriminated union of success or error input data.
|
|
184
|
+
* @returns A complete {@link LAFSEnvelope} ready for serialization.
|
|
185
|
+
*
|
|
186
|
+
* @remarks
|
|
187
|
+
* This is the primary factory for LAFS envelopes. It delegates to
|
|
188
|
+
* internal `createMeta` for metadata construction and `normalizeError`
|
|
189
|
+
* for error normalization. Optional fields (`page`, `_extensions`) are only
|
|
190
|
+
* included when explicitly provided, keeping the envelope minimal.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* import { createEnvelope } from '@cleocode/lafs';
|
|
195
|
+
*
|
|
196
|
+
* const envelope = createEnvelope({
|
|
197
|
+
* success: true,
|
|
198
|
+
* result: { items: [] },
|
|
199
|
+
* meta: { operation: 'tasks.list', requestId: 'req-1' },
|
|
200
|
+
* });
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
43
203
|
export declare function createEnvelope(input: CreateEnvelopeInput): LAFSEnvelope;
|
|
204
|
+
/**
|
|
205
|
+
* Error subclass that carries the full {@link LAFSError} payload.
|
|
206
|
+
*
|
|
207
|
+
* @remarks
|
|
208
|
+
* Thrown by {@link parseLafsResponse} when the envelope indicates failure.
|
|
209
|
+
* Implements {@link LAFSError} so consumers can access structured error
|
|
210
|
+
* metadata directly on the caught error instance. The `registered` flag
|
|
211
|
+
* indicates whether the error code exists in the canonical error registry.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* try {
|
|
216
|
+
* parseLafsResponse(envelope);
|
|
217
|
+
* } catch (err) {
|
|
218
|
+
* if (err instanceof LafsError) {
|
|
219
|
+
* console.log(err.code, err.agentAction);
|
|
220
|
+
* }
|
|
221
|
+
* }
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
44
224
|
export declare class LafsError extends Error implements LAFSError {
|
|
225
|
+
/** Stable, machine-readable error code. */
|
|
45
226
|
code: string;
|
|
227
|
+
/** High-level classification of the error. */
|
|
46
228
|
category: LAFSErrorCategory;
|
|
229
|
+
/** Whether the operation can be retried without modification. */
|
|
47
230
|
retryable: boolean;
|
|
231
|
+
/** Suggested delay in milliseconds before retrying, or `null` if not applicable. */
|
|
48
232
|
retryAfterMs: number | null;
|
|
233
|
+
/** Arbitrary key-value pairs with additional context about the error. */
|
|
49
234
|
details: Record<string, unknown>;
|
|
235
|
+
/** Whether this error code exists in the canonical error registry. */
|
|
50
236
|
registered: boolean;
|
|
237
|
+
/**
|
|
238
|
+
* Recommended action for the consuming agent.
|
|
239
|
+
*
|
|
240
|
+
* @defaultValue undefined
|
|
241
|
+
*/
|
|
51
242
|
agentAction?: LAFSAgentAction;
|
|
243
|
+
/**
|
|
244
|
+
* Whether the error requires human or higher-privilege intervention.
|
|
245
|
+
*
|
|
246
|
+
* @defaultValue undefined
|
|
247
|
+
*/
|
|
52
248
|
escalationRequired?: boolean;
|
|
249
|
+
/**
|
|
250
|
+
* Free-text description of a suggested recovery action.
|
|
251
|
+
*
|
|
252
|
+
* @defaultValue undefined
|
|
253
|
+
*/
|
|
53
254
|
suggestedAction?: string;
|
|
255
|
+
/**
|
|
256
|
+
* URL pointing to documentation about this error code.
|
|
257
|
+
*
|
|
258
|
+
* @defaultValue undefined
|
|
259
|
+
*/
|
|
54
260
|
docUrl?: string;
|
|
261
|
+
/**
|
|
262
|
+
* Create a new `LafsError` from a structured {@link LAFSError} payload.
|
|
263
|
+
*
|
|
264
|
+
* @param error - The structured error data to wrap.
|
|
265
|
+
*
|
|
266
|
+
* @remarks
|
|
267
|
+
* Copies all fields from the input and sets `registered` by checking the
|
|
268
|
+
* error code against the canonical registry via {@link isRegisteredErrorCode}.
|
|
269
|
+
*/
|
|
55
270
|
constructor(error: LAFSError);
|
|
56
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Options for {@link parseLafsResponse}.
|
|
274
|
+
*
|
|
275
|
+
* @remarks
|
|
276
|
+
* Controls how strictly the parser validates the error code against the
|
|
277
|
+
* canonical error registry.
|
|
278
|
+
*/
|
|
57
279
|
export interface ParseLafsResponseOptions {
|
|
280
|
+
/**
|
|
281
|
+
* When `true`, unregistered error codes cause an additional `Error` to be
|
|
282
|
+
* thrown instead of the normal {@link LafsError}.
|
|
283
|
+
*
|
|
284
|
+
* @defaultValue undefined
|
|
285
|
+
*/
|
|
58
286
|
requireRegisteredErrorCode?: boolean;
|
|
59
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Parse and unwrap a raw LAFS envelope, returning the result or throwing on error.
|
|
290
|
+
*
|
|
291
|
+
* @typeParam T - Expected type of the result payload.
|
|
292
|
+
* @param input - Raw value expected to be a valid {@link LAFSEnvelope}.
|
|
293
|
+
* @param options - Parsing options controlling error-code validation.
|
|
294
|
+
* @returns The `result` field of the envelope cast to `T`.
|
|
295
|
+
* @throws {LafsError} When the envelope indicates failure (`success=false`).
|
|
296
|
+
* @throws {Error} When the envelope is structurally invalid or
|
|
297
|
+
* `requireRegisteredErrorCode` is `true` and the code is unregistered.
|
|
298
|
+
*
|
|
299
|
+
* @remarks
|
|
300
|
+
* Delegates to {@link assertEnvelope} for schema validation before inspecting
|
|
301
|
+
* the `success` flag. On success, the `result` is returned directly. On
|
|
302
|
+
* failure, the `error` payload is wrapped in a {@link LafsError} and thrown.
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```ts
|
|
306
|
+
* import { parseLafsResponse } from '@cleocode/lafs';
|
|
307
|
+
*
|
|
308
|
+
* interface TaskList { items: Task[] }
|
|
309
|
+
* const tasks = parseLafsResponse<TaskList>(rawEnvelope);
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
60
312
|
export declare function parseLafsResponse<T = unknown>(input: unknown, options?: ParseLafsResponseOptions): T;
|
|
61
313
|
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/envelope.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,aAAa,EACb,QAAQ,EACT,MAAM,YAAY,CAAC;AAGpB,eAAO,MAAM,eAAe,EAAG,kDAA2D,CAAC;AAE3F,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,YAAY,CAAC,QAAQ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