@cleocode/lafs 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -0
  3. package/dist/schemas/v1/conformance-profiles.json +39 -0
  4. package/dist/schemas/v1/envelope.schema.json +306 -0
  5. package/dist/schemas/v1/error-registry.json +162 -0
  6. package/dist/src/a2a/bindings/grpc.d.ts +67 -0
  7. package/dist/src/a2a/bindings/grpc.js +148 -0
  8. package/dist/src/a2a/bindings/http.d.ts +102 -0
  9. package/dist/src/a2a/bindings/http.js +120 -0
  10. package/dist/src/a2a/bindings/index.d.ts +35 -0
  11. package/dist/src/a2a/bindings/index.js +79 -0
  12. package/dist/src/a2a/bindings/jsonrpc.d.ts +77 -0
  13. package/dist/src/a2a/bindings/jsonrpc.js +114 -0
  14. package/dist/src/a2a/bridge.d.ts +175 -0
  15. package/dist/src/a2a/bridge.js +286 -0
  16. package/dist/src/a2a/extensions.d.ts +121 -0
  17. package/dist/src/a2a/extensions.js +205 -0
  18. package/dist/src/a2a/index.d.ts +40 -0
  19. package/dist/src/a2a/index.js +76 -0
  20. package/dist/src/a2a/streaming.d.ts +74 -0
  21. package/dist/src/a2a/streaming.js +265 -0
  22. package/dist/src/a2a/task-lifecycle.d.ts +109 -0
  23. package/dist/src/a2a/task-lifecycle.js +313 -0
  24. package/dist/src/budgetEnforcement.d.ts +84 -0
  25. package/dist/src/budgetEnforcement.js +328 -0
  26. package/dist/src/circuit-breaker/index.d.ts +121 -0
  27. package/dist/src/circuit-breaker/index.js +249 -0
  28. package/dist/src/cli.d.ts +16 -0
  29. package/dist/src/cli.js +63 -0
  30. package/dist/src/compliance.d.ts +31 -0
  31. package/dist/src/compliance.js +89 -0
  32. package/dist/src/conformance.d.ts +7 -0
  33. package/dist/src/conformance.js +248 -0
  34. package/dist/src/conformanceProfiles.d.ts +11 -0
  35. package/dist/src/conformanceProfiles.js +34 -0
  36. package/dist/src/deprecationRegistry.d.ts +13 -0
  37. package/dist/src/deprecationRegistry.js +39 -0
  38. package/dist/src/discovery.d.ts +286 -0
  39. package/dist/src/discovery.js +350 -0
  40. package/dist/src/envelope.d.ts +60 -0
  41. package/dist/src/envelope.js +136 -0
  42. package/dist/src/errorRegistry.d.ts +28 -0
  43. package/dist/src/errorRegistry.js +36 -0
  44. package/dist/src/fieldExtraction.d.ts +67 -0
  45. package/dist/src/fieldExtraction.js +133 -0
  46. package/dist/src/flagResolver.d.ts +46 -0
  47. package/dist/src/flagResolver.js +47 -0
  48. package/dist/src/flagSemantics.d.ts +16 -0
  49. package/dist/src/flagSemantics.js +45 -0
  50. package/dist/src/health/index.d.ts +105 -0
  51. package/dist/src/health/index.js +220 -0
  52. package/dist/src/index.d.ts +24 -0
  53. package/dist/src/index.js +34 -0
  54. package/dist/src/mcpAdapter.d.ts +28 -0
  55. package/dist/src/mcpAdapter.js +281 -0
  56. package/dist/src/mviProjection.d.ts +19 -0
  57. package/dist/src/mviProjection.js +116 -0
  58. package/dist/src/problemDetails.d.ts +34 -0
  59. package/dist/src/problemDetails.js +45 -0
  60. package/dist/src/shutdown/index.d.ts +69 -0
  61. package/dist/src/shutdown/index.js +160 -0
  62. package/dist/src/tokenEstimator.d.ts +87 -0
  63. package/dist/src/tokenEstimator.js +238 -0
  64. package/dist/src/types.d.ts +135 -0
  65. package/dist/src/types.js +12 -0
  66. package/dist/src/validateEnvelope.d.ts +15 -0
  67. package/dist/src/validateEnvelope.js +31 -0
  68. package/lafs.md +819 -0
  69. package/package.json +88 -0
  70. package/schemas/v1/agent-card.schema.json +230 -0
  71. package/schemas/v1/conformance-profiles.json +39 -0
  72. package/schemas/v1/context-ledger.schema.json +70 -0
  73. package/schemas/v1/discovery.schema.json +132 -0
  74. package/schemas/v1/envelope.schema.json +306 -0
  75. package/schemas/v1/error-registry.json +162 -0
@@ -0,0 +1,162 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "version": "1.0.0",
4
+ "codes": [
5
+ {
6
+ "code": "E_FORMAT_CONFLICT",
7
+ "category": "CONTRACT",
8
+ "description": "Mutually exclusive format flags requested",
9
+ "retryable": false,
10
+ "httpStatus": 400,
11
+ "grpcStatus": "INVALID_ARGUMENT",
12
+ "cliExit": 2,
13
+ "agentAction": "stop",
14
+ "typeUri": "https://lafs.dev/errors/v1/format-conflict",
15
+ "docUrl": "https://lafs.dev/docs/errors/format-conflict"
16
+ },
17
+ {
18
+ "code": "E_VALIDATION_SCHEMA",
19
+ "category": "VALIDATION",
20
+ "description": "Input failed schema validation",
21
+ "retryable": false,
22
+ "httpStatus": 400,
23
+ "grpcStatus": "INVALID_ARGUMENT",
24
+ "cliExit": 2,
25
+ "agentAction": "retry_modified",
26
+ "typeUri": "https://lafs.dev/errors/v1/validation-schema",
27
+ "docUrl": "https://lafs.dev/docs/errors/validation-schema"
28
+ },
29
+ {
30
+ "code": "E_NOT_FOUND_RESOURCE",
31
+ "category": "NOT_FOUND",
32
+ "description": "Referenced resource was not found",
33
+ "retryable": false,
34
+ "httpStatus": 404,
35
+ "grpcStatus": "NOT_FOUND",
36
+ "cliExit": 4,
37
+ "agentAction": "stop",
38
+ "typeUri": "https://lafs.dev/errors/v1/not-found-resource",
39
+ "docUrl": "https://lafs.dev/docs/errors/not-found-resource"
40
+ },
41
+ {
42
+ "code": "E_CONFLICT_VERSION",
43
+ "category": "CONFLICT",
44
+ "description": "Version or concurrency conflict",
45
+ "retryable": true,
46
+ "httpStatus": 409,
47
+ "grpcStatus": "ABORTED",
48
+ "cliExit": 7,
49
+ "agentAction": "refresh_context",
50
+ "typeUri": "https://lafs.dev/errors/v1/conflict-version",
51
+ "docUrl": "https://lafs.dev/docs/errors/conflict-version"
52
+ },
53
+ {
54
+ "code": "E_RATE_LIMITED",
55
+ "category": "RATE_LIMIT",
56
+ "description": "Rate limit exceeded",
57
+ "retryable": true,
58
+ "httpStatus": 429,
59
+ "grpcStatus": "RESOURCE_EXHAUSTED",
60
+ "cliExit": 8,
61
+ "agentAction": "wait",
62
+ "typeUri": "https://lafs.dev/errors/v1/rate-limited",
63
+ "docUrl": "https://lafs.dev/docs/errors/rate-limited"
64
+ },
65
+ {
66
+ "code": "E_TRANSIENT_UPSTREAM",
67
+ "category": "TRANSIENT",
68
+ "description": "Upstream dependency temporary failure",
69
+ "retryable": true,
70
+ "httpStatus": 503,
71
+ "grpcStatus": "UNAVAILABLE",
72
+ "cliExit": 9,
73
+ "agentAction": "retry",
74
+ "typeUri": "https://lafs.dev/errors/v1/transient-upstream",
75
+ "docUrl": "https://lafs.dev/docs/errors/transient-upstream"
76
+ },
77
+ {
78
+ "code": "E_INTERNAL_UNEXPECTED",
79
+ "category": "INTERNAL",
80
+ "description": "Unexpected internal failure",
81
+ "retryable": false,
82
+ "httpStatus": 500,
83
+ "grpcStatus": "INTERNAL",
84
+ "cliExit": 1,
85
+ "agentAction": "escalate",
86
+ "typeUri": "https://lafs.dev/errors/v1/internal-unexpected",
87
+ "docUrl": "https://lafs.dev/docs/errors/internal-unexpected"
88
+ },
89
+ {
90
+ "code": "E_CONTEXT_MISSING",
91
+ "category": "CONTRACT",
92
+ "description": "Required context ledger fields are missing",
93
+ "retryable": false,
94
+ "httpStatus": 400,
95
+ "grpcStatus": "FAILED_PRECONDITION",
96
+ "cliExit": 6,
97
+ "agentAction": "retry_modified",
98
+ "typeUri": "https://lafs.dev/errors/v1/context-missing",
99
+ "docUrl": "https://lafs.dev/docs/errors/context-missing"
100
+ },
101
+ {
102
+ "code": "E_CONTEXT_STALE",
103
+ "category": "CONFLICT",
104
+ "description": "Context ledger or references are stale",
105
+ "retryable": true,
106
+ "httpStatus": 409,
107
+ "grpcStatus": "ABORTED",
108
+ "cliExit": 7,
109
+ "agentAction": "refresh_context",
110
+ "typeUri": "https://lafs.dev/errors/v1/context-stale",
111
+ "docUrl": "https://lafs.dev/docs/errors/context-stale"
112
+ },
113
+ {
114
+ "code": "E_MIGRATION_UNSUPPORTED_VERSION",
115
+ "category": "MIGRATION",
116
+ "description": "Requested protocol/schema version unsupported",
117
+ "retryable": false,
118
+ "httpStatus": 426,
119
+ "grpcStatus": "FAILED_PRECONDITION",
120
+ "cliExit": 10,
121
+ "agentAction": "stop",
122
+ "typeUri": "https://lafs.dev/errors/v1/migration-unsupported-version",
123
+ "docUrl": "https://lafs.dev/docs/errors/migration-unsupported-version"
124
+ },
125
+ {
126
+ "code": "E_DISCLOSURE_UNKNOWN_FIELD",
127
+ "category": "VALIDATION",
128
+ "description": "Unrecognized expansion field in _expand parameter",
129
+ "retryable": false,
130
+ "httpStatus": 400,
131
+ "grpcStatus": "INVALID_ARGUMENT",
132
+ "cliExit": 2,
133
+ "agentAction": "retry_modified",
134
+ "typeUri": "https://lafs.dev/errors/v1/disclosure-unknown-field",
135
+ "docUrl": "https://lafs.dev/docs/errors/disclosure-unknown-field"
136
+ },
137
+ {
138
+ "code": "E_MVI_BUDGET_EXCEEDED",
139
+ "category": "VALIDATION",
140
+ "description": "Response exceeds declared MVI budget (token, byte, or item limit)",
141
+ "retryable": false,
142
+ "httpStatus": 413,
143
+ "grpcStatus": "RESOURCE_EXHAUSTED",
144
+ "cliExit": 2,
145
+ "agentAction": "retry_modified",
146
+ "typeUri": "https://lafs.dev/errors/v1/mvi-budget-exceeded",
147
+ "docUrl": "https://lafs.dev/docs/errors/mvi-budget-exceeded"
148
+ },
149
+ {
150
+ "code": "E_FIELD_CONFLICT",
151
+ "category": "CONTRACT",
152
+ "description": "Mutually exclusive field selection modes (single-field extraction and multi-field filtering cannot be combined)",
153
+ "retryable": false,
154
+ "httpStatus": 400,
155
+ "grpcStatus": "INVALID_ARGUMENT",
156
+ "cliExit": 2,
157
+ "agentAction": "stop",
158
+ "typeUri": "https://lafs.dev/errors/v1/field-conflict",
159
+ "docUrl": "https://lafs.dev/docs/errors/field-conflict"
160
+ }
161
+ ]
162
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * A2A gRPC Protocol Binding
3
+ *
4
+ * Status codes, error reasons, service method definitions, and metadata
5
+ * constants for gRPC transport. Types and helpers only — no @grpc/grpc-js
6
+ * runtime dependency.
7
+ *
8
+ * Reference: A2A spec Section 10.3-10.6
9
+ */
10
+ import type { A2AErrorType } from './jsonrpc.js';
11
+ /** Standard gRPC status codes (numeric values 0-16) */
12
+ export declare const GRPC_STATUS_CODE: {
13
+ readonly OK: 0;
14
+ readonly CANCELLED: 1;
15
+ readonly UNKNOWN: 2;
16
+ readonly INVALID_ARGUMENT: 3;
17
+ readonly DEADLINE_EXCEEDED: 4;
18
+ readonly NOT_FOUND: 5;
19
+ readonly ALREADY_EXISTS: 6;
20
+ readonly PERMISSION_DENIED: 7;
21
+ readonly RESOURCE_EXHAUSTED: 8;
22
+ readonly FAILED_PRECONDITION: 9;
23
+ readonly ABORTED: 10;
24
+ readonly OUT_OF_RANGE: 11;
25
+ readonly UNIMPLEMENTED: 12;
26
+ readonly INTERNAL: 13;
27
+ readonly UNAVAILABLE: 14;
28
+ readonly DATA_LOSS: 15;
29
+ readonly UNAUTHENTICATED: 16;
30
+ };
31
+ export type GrpcStatusCode = (typeof GRPC_STATUS_CODE)[keyof typeof GRPC_STATUS_CODE];
32
+ export type GrpcStatusName = keyof typeof GRPC_STATUS_CODE;
33
+ /** Maps A2A error types to gRPC status names */
34
+ export declare const A2A_GRPC_STATUS_CODES: Record<A2AErrorType, GrpcStatusName>;
35
+ /** UPPER_SNAKE_CASE error reasons without "Error" suffix */
36
+ export declare const A2A_GRPC_ERROR_REASONS: Record<A2AErrorType, string>;
37
+ /** Error domain for A2A gRPC errors */
38
+ export declare const A2A_GRPC_ERROR_DOMAIN: "a2a-protocol.org";
39
+ /** gRPC service method descriptor */
40
+ export interface GrpcServiceMethod {
41
+ request: string;
42
+ response: string;
43
+ streaming: boolean;
44
+ }
45
+ /** gRPC service method definitions for the A2A protocol */
46
+ export declare const GRPC_SERVICE_METHODS: Record<string, GrpcServiceMethod>;
47
+ /** gRPC metadata key for A2A protocol version */
48
+ export declare const GRPC_METADATA_VERSION_KEY: "a2a-version";
49
+ /** gRPC metadata key for activated A2A extensions */
50
+ export declare const GRPC_METADATA_EXTENSIONS_KEY: "a2a-extensions";
51
+ /** gRPC Status object for A2A errors */
52
+ export interface GrpcStatus {
53
+ code: GrpcStatusCode;
54
+ message: string;
55
+ details?: GrpcErrorInfo[];
56
+ }
57
+ /** google.rpc.ErrorInfo equivalent */
58
+ export interface GrpcErrorInfo {
59
+ reason: string;
60
+ domain: string;
61
+ metadata?: Record<string, string>;
62
+ }
63
+ /**
64
+ * Create a gRPC Status object for an A2A error type.
65
+ * Includes ErrorInfo details with reason and domain.
66
+ */
67
+ export declare function createGrpcStatus(errorType: A2AErrorType, message: string, metadata?: Record<string, string>): GrpcStatus;
@@ -0,0 +1,148 @@
1
+ /**
2
+ * A2A gRPC Protocol Binding
3
+ *
4
+ * Status codes, error reasons, service method definitions, and metadata
5
+ * constants for gRPC transport. Types and helpers only — no @grpc/grpc-js
6
+ * runtime dependency.
7
+ *
8
+ * Reference: A2A spec Section 10.3-10.6
9
+ */
10
+ // ============================================================================
11
+ // gRPC Status Codes (standard)
12
+ // ============================================================================
13
+ /** Standard gRPC status codes (numeric values 0-16) */
14
+ export const GRPC_STATUS_CODE = {
15
+ OK: 0,
16
+ CANCELLED: 1,
17
+ UNKNOWN: 2,
18
+ INVALID_ARGUMENT: 3,
19
+ DEADLINE_EXCEEDED: 4,
20
+ NOT_FOUND: 5,
21
+ ALREADY_EXISTS: 6,
22
+ PERMISSION_DENIED: 7,
23
+ RESOURCE_EXHAUSTED: 8,
24
+ FAILED_PRECONDITION: 9,
25
+ ABORTED: 10,
26
+ OUT_OF_RANGE: 11,
27
+ UNIMPLEMENTED: 12,
28
+ INTERNAL: 13,
29
+ UNAVAILABLE: 14,
30
+ DATA_LOSS: 15,
31
+ UNAUTHENTICATED: 16,
32
+ };
33
+ // ============================================================================
34
+ // A2A gRPC Status Mapping (spec Section 5.4)
35
+ // ============================================================================
36
+ /** Maps A2A error types to gRPC status names */
37
+ export const A2A_GRPC_STATUS_CODES = {
38
+ TaskNotFound: 'NOT_FOUND',
39
+ TaskNotCancelable: 'FAILED_PRECONDITION',
40
+ PushNotificationNotSupported: 'UNIMPLEMENTED',
41
+ UnsupportedOperation: 'UNIMPLEMENTED',
42
+ ContentTypeNotSupported: 'INVALID_ARGUMENT',
43
+ InvalidAgentResponse: 'INTERNAL',
44
+ AuthenticatedExtendedCardNotConfigured: 'NOT_FOUND',
45
+ ExtensionSupportRequired: 'FAILED_PRECONDITION',
46
+ VersionNotSupported: 'FAILED_PRECONDITION',
47
+ };
48
+ // ============================================================================
49
+ // Error Reasons (spec Section 10.6)
50
+ // ============================================================================
51
+ /** UPPER_SNAKE_CASE error reasons without "Error" suffix */
52
+ export const A2A_GRPC_ERROR_REASONS = {
53
+ TaskNotFound: 'TASK_NOT_FOUND',
54
+ TaskNotCancelable: 'TASK_NOT_CANCELABLE',
55
+ PushNotificationNotSupported: 'PUSH_NOTIFICATION_NOT_SUPPORTED',
56
+ UnsupportedOperation: 'UNSUPPORTED_OPERATION',
57
+ ContentTypeNotSupported: 'CONTENT_TYPE_NOT_SUPPORTED',
58
+ InvalidAgentResponse: 'INVALID_AGENT_RESPONSE',
59
+ AuthenticatedExtendedCardNotConfigured: 'AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED',
60
+ ExtensionSupportRequired: 'EXTENSION_SUPPORT_REQUIRED',
61
+ VersionNotSupported: 'VERSION_NOT_SUPPORTED',
62
+ };
63
+ /** Error domain for A2A gRPC errors */
64
+ export const A2A_GRPC_ERROR_DOMAIN = 'a2a-protocol.org';
65
+ /** gRPC service method definitions for the A2A protocol */
66
+ export const GRPC_SERVICE_METHODS = {
67
+ SendMessage: {
68
+ request: 'MessageSendParams',
69
+ response: 'SendMessageResponse',
70
+ streaming: false,
71
+ },
72
+ SendStreamingMessage: {
73
+ request: 'MessageSendParams',
74
+ response: 'SendStreamingMessageResponse',
75
+ streaming: true,
76
+ },
77
+ GetTask: {
78
+ request: 'TaskQueryParams',
79
+ response: 'GetTaskResponse',
80
+ streaming: false,
81
+ },
82
+ ListTasks: {
83
+ request: 'TaskQueryParams',
84
+ response: 'ListTasksResponse',
85
+ streaming: false,
86
+ },
87
+ CancelTask: {
88
+ request: 'TaskIdParams',
89
+ response: 'CancelTaskResponse',
90
+ streaming: false,
91
+ },
92
+ SubscribeToTask: {
93
+ request: 'TaskIdParams',
94
+ response: 'SubscribeToTaskResponse',
95
+ streaming: true,
96
+ },
97
+ SetTaskPushNotificationConfig: {
98
+ request: 'TaskPushNotificationConfig',
99
+ response: 'SetTaskPushNotificationConfigResponse',
100
+ streaming: false,
101
+ },
102
+ GetTaskPushNotificationConfig: {
103
+ request: 'GetTaskPushNotificationConfigParams',
104
+ response: 'GetTaskPushNotificationConfigResponse',
105
+ streaming: false,
106
+ },
107
+ ListTaskPushNotificationConfig: {
108
+ request: 'ListTaskPushNotificationConfigParams',
109
+ response: 'ListTaskPushNotificationConfigResponse',
110
+ streaming: false,
111
+ },
112
+ DeleteTaskPushNotificationConfig: {
113
+ request: 'DeleteTaskPushNotificationConfigParams',
114
+ response: 'DeleteTaskPushNotificationConfigResponse',
115
+ streaming: false,
116
+ },
117
+ GetExtendedAgentCard: {
118
+ request: 'GetAuthenticatedExtendedCardRequest',
119
+ response: 'GetAuthenticatedExtendedCardResponse',
120
+ streaming: false,
121
+ },
122
+ };
123
+ // ============================================================================
124
+ // gRPC Metadata Constants
125
+ // ============================================================================
126
+ /** gRPC metadata key for A2A protocol version */
127
+ export const GRPC_METADATA_VERSION_KEY = 'a2a-version';
128
+ /** gRPC metadata key for activated A2A extensions */
129
+ export const GRPC_METADATA_EXTENSIONS_KEY = 'a2a-extensions';
130
+ /**
131
+ * Create a gRPC Status object for an A2A error type.
132
+ * Includes ErrorInfo details with reason and domain.
133
+ */
134
+ export function createGrpcStatus(errorType, message, metadata) {
135
+ const statusName = A2A_GRPC_STATUS_CODES[errorType];
136
+ const code = GRPC_STATUS_CODE[statusName];
137
+ return {
138
+ code,
139
+ message,
140
+ details: [
141
+ {
142
+ reason: A2A_GRPC_ERROR_REASONS[errorType],
143
+ domain: A2A_GRPC_ERROR_DOMAIN,
144
+ ...(metadata && { metadata }),
145
+ },
146
+ ],
147
+ };
148
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * A2A HTTP Protocol Binding
3
+ *
4
+ * HTTP endpoint definitions, status codes, error type URIs,
5
+ * and RFC 9457 Problem Details support per A2A spec Section 11.3-11.5.
6
+ */
7
+ import type { A2AErrorType } from './jsonrpc.js';
8
+ import type { LAFSError } from '../../types.js';
9
+ /** HTTP+JSON endpoint definitions for each A2A operation */
10
+ export declare const HTTP_ENDPOINTS: {
11
+ readonly SendMessage: {
12
+ readonly method: "POST";
13
+ readonly path: "/message:send";
14
+ };
15
+ readonly SendStreamingMessage: {
16
+ readonly method: "POST";
17
+ readonly path: "/message:stream";
18
+ };
19
+ readonly GetTask: {
20
+ readonly method: "GET";
21
+ readonly path: "/tasks/:id";
22
+ };
23
+ readonly ListTasks: {
24
+ readonly method: "GET";
25
+ readonly path: "/tasks";
26
+ };
27
+ readonly CancelTask: {
28
+ readonly method: "POST";
29
+ readonly path: "/tasks/:id:cancel";
30
+ };
31
+ readonly SubscribeToTask: {
32
+ readonly method: "GET";
33
+ readonly path: "/tasks/:id:subscribe";
34
+ };
35
+ readonly SetTaskPushNotificationConfig: {
36
+ readonly method: "POST";
37
+ readonly path: "/tasks/:id/pushNotificationConfig";
38
+ };
39
+ readonly GetTaskPushNotificationConfig: {
40
+ readonly method: "GET";
41
+ readonly path: "/tasks/:id/pushNotificationConfig";
42
+ };
43
+ readonly ListTaskPushNotificationConfig: {
44
+ readonly method: "GET";
45
+ readonly path: "/tasks/:id/pushNotificationConfig:list";
46
+ };
47
+ readonly DeleteTaskPushNotificationConfig: {
48
+ readonly method: "DELETE";
49
+ readonly path: "/tasks/:id/pushNotificationConfig/:configId";
50
+ };
51
+ readonly GetExtendedAgentCard: {
52
+ readonly method: "GET";
53
+ readonly path: "/agent/authenticatedExtendedCard";
54
+ };
55
+ };
56
+ export type HttpEndpoint = (typeof HTTP_ENDPOINTS)[keyof typeof HTTP_ENDPOINTS];
57
+ /** Maps A2A error types to HTTP status codes */
58
+ export declare const A2A_HTTP_STATUS_CODES: Record<A2AErrorType, number>;
59
+ /** RFC 9457 Problem Details type URIs for A2A errors */
60
+ export declare const A2A_ERROR_TYPE_URIS: Record<A2AErrorType, string>;
61
+ /** RFC 9457 Problem Details object */
62
+ export interface ProblemDetails {
63
+ type: string;
64
+ title: string;
65
+ status: number;
66
+ detail: string;
67
+ [key: string]: unknown;
68
+ }
69
+ /**
70
+ * Create an RFC 9457 Problem Details object for an A2A error.
71
+ * @param errorType - The A2A error type name
72
+ * @param detail - Human-readable explanation of the error
73
+ * @param extensions - Additional members to include in the response
74
+ */
75
+ export declare function createProblemDetails(errorType: A2AErrorType, detail: string, extensions?: Record<string, unknown>): ProblemDetails;
76
+ /**
77
+ * Create an RFC 9457 Problem Details object bridging A2A error types with LAFS error data.
78
+ * Includes LAFS agent-actionable extension fields from the LAFSError.
79
+ *
80
+ * @param errorType - The A2A error type name
81
+ * @param lafsError - The LAFS error object to extract extension fields from
82
+ * @param requestId - Optional request identifier for the `instance` field
83
+ */
84
+ export declare function createLafsProblemDetails(errorType: A2AErrorType, lafsError: LAFSError, requestId?: string): ProblemDetails;
85
+ /**
86
+ * Build a URL by substituting path parameters.
87
+ * @param endpoint - HTTP endpoint definition (from HTTP_ENDPOINTS)
88
+ * @param params - Path parameter values (keys without leading colon)
89
+ */
90
+ export declare function buildUrl(endpoint: HttpEndpoint, params?: Record<string, string>): string;
91
+ /** Parsed query parameters for ListTasks (spec Section 11.5) */
92
+ export interface ListTasksQueryParams {
93
+ contextId?: string;
94
+ state?: string;
95
+ limit?: number;
96
+ pageToken?: string;
97
+ }
98
+ /**
99
+ * Parse camelCase query parameters for the ListTasks endpoint.
100
+ * Handles type coercion for numeric fields.
101
+ */
102
+ export declare function parseListTasksQuery(query: Record<string, string | undefined>): ListTasksQueryParams;
@@ -0,0 +1,120 @@
1
+ /**
2
+ * A2A HTTP Protocol Binding
3
+ *
4
+ * HTTP endpoint definitions, status codes, error type URIs,
5
+ * and RFC 9457 Problem Details support per A2A spec Section 11.3-11.5.
6
+ */
7
+ // ============================================================================
8
+ // Endpoint Constants (spec Section 11.3)
9
+ // ============================================================================
10
+ /** HTTP+JSON endpoint definitions for each A2A operation */
11
+ export const HTTP_ENDPOINTS = {
12
+ SendMessage: { method: 'POST', path: '/message:send' },
13
+ SendStreamingMessage: { method: 'POST', path: '/message:stream' },
14
+ GetTask: { method: 'GET', path: '/tasks/:id' },
15
+ ListTasks: { method: 'GET', path: '/tasks' },
16
+ CancelTask: { method: 'POST', path: '/tasks/:id:cancel' },
17
+ SubscribeToTask: { method: 'GET', path: '/tasks/:id:subscribe' },
18
+ SetTaskPushNotificationConfig: { method: 'POST', path: '/tasks/:id/pushNotificationConfig' },
19
+ GetTaskPushNotificationConfig: { method: 'GET', path: '/tasks/:id/pushNotificationConfig' },
20
+ ListTaskPushNotificationConfig: { method: 'GET', path: '/tasks/:id/pushNotificationConfig:list' },
21
+ DeleteTaskPushNotificationConfig: { method: 'DELETE', path: '/tasks/:id/pushNotificationConfig/:configId' },
22
+ GetExtendedAgentCard: { method: 'GET', path: '/agent/authenticatedExtendedCard' },
23
+ };
24
+ // ============================================================================
25
+ // HTTP Status Codes (spec Section 5.4)
26
+ // ============================================================================
27
+ /** Maps A2A error types to HTTP status codes */
28
+ export const A2A_HTTP_STATUS_CODES = {
29
+ TaskNotFound: 404,
30
+ TaskNotCancelable: 409,
31
+ PushNotificationNotSupported: 400,
32
+ UnsupportedOperation: 400,
33
+ ContentTypeNotSupported: 415,
34
+ InvalidAgentResponse: 502,
35
+ AuthenticatedExtendedCardNotConfigured: 404,
36
+ ExtensionSupportRequired: 400,
37
+ VersionNotSupported: 400,
38
+ };
39
+ // ============================================================================
40
+ // Error Type URIs (spec Section 5.4)
41
+ // ============================================================================
42
+ /** RFC 9457 Problem Details type URIs for A2A errors */
43
+ export const A2A_ERROR_TYPE_URIS = {
44
+ TaskNotFound: 'https://a2a-protocol.org/errors/task-not-found',
45
+ TaskNotCancelable: 'https://a2a-protocol.org/errors/task-not-cancelable',
46
+ PushNotificationNotSupported: 'https://a2a-protocol.org/errors/push-notification-not-supported',
47
+ UnsupportedOperation: 'https://a2a-protocol.org/errors/unsupported-operation',
48
+ ContentTypeNotSupported: 'https://a2a-protocol.org/errors/content-type-not-supported',
49
+ InvalidAgentResponse: 'https://a2a-protocol.org/errors/invalid-agent-response',
50
+ AuthenticatedExtendedCardNotConfigured: 'https://a2a-protocol.org/errors/authenticated-extended-card-not-configured',
51
+ ExtensionSupportRequired: 'https://a2a-protocol.org/errors/extension-support-required',
52
+ VersionNotSupported: 'https://a2a-protocol.org/errors/version-not-supported',
53
+ };
54
+ /**
55
+ * Create an RFC 9457 Problem Details object for an A2A error.
56
+ * @param errorType - The A2A error type name
57
+ * @param detail - Human-readable explanation of the error
58
+ * @param extensions - Additional members to include in the response
59
+ */
60
+ export function createProblemDetails(errorType, detail, extensions) {
61
+ // Convert PascalCase to Title Case: "TaskNotFound" -> "Task Not Found"
62
+ const title = errorType.replace(/([A-Z])/g, ' $1').trim();
63
+ return {
64
+ type: A2A_ERROR_TYPE_URIS[errorType],
65
+ title,
66
+ status: A2A_HTTP_STATUS_CODES[errorType],
67
+ detail,
68
+ ...extensions,
69
+ };
70
+ }
71
+ /**
72
+ * Create an RFC 9457 Problem Details object bridging A2A error types with LAFS error data.
73
+ * Includes LAFS agent-actionable extension fields from the LAFSError.
74
+ *
75
+ * @param errorType - The A2A error type name
76
+ * @param lafsError - The LAFS error object to extract extension fields from
77
+ * @param requestId - Optional request identifier for the `instance` field
78
+ */
79
+ export function createLafsProblemDetails(errorType, lafsError, requestId) {
80
+ const base = createProblemDetails(errorType, lafsError.message);
81
+ return {
82
+ ...base,
83
+ ...(requestId != null && { instance: requestId }),
84
+ retryable: lafsError.retryable,
85
+ ...(lafsError.agentAction != null && { agentAction: lafsError.agentAction }),
86
+ ...(lafsError.retryAfterMs != null && { retryAfterMs: lafsError.retryAfterMs }),
87
+ ...(lafsError.escalationRequired != null && { escalationRequired: lafsError.escalationRequired }),
88
+ ...(lafsError.suggestedAction != null && { suggestedAction: lafsError.suggestedAction }),
89
+ ...(lafsError.docUrl != null && { docUrl: lafsError.docUrl }),
90
+ };
91
+ }
92
+ // ============================================================================
93
+ // URL Building
94
+ // ============================================================================
95
+ /**
96
+ * Build a URL by substituting path parameters.
97
+ * @param endpoint - HTTP endpoint definition (from HTTP_ENDPOINTS)
98
+ * @param params - Path parameter values (keys without leading colon)
99
+ */
100
+ export function buildUrl(endpoint, params) {
101
+ let path = endpoint.path;
102
+ if (params) {
103
+ for (const [key, value] of Object.entries(params)) {
104
+ path = path.replace(`:${key}`, encodeURIComponent(value));
105
+ }
106
+ }
107
+ return path;
108
+ }
109
+ /**
110
+ * Parse camelCase query parameters for the ListTasks endpoint.
111
+ * Handles type coercion for numeric fields.
112
+ */
113
+ export function parseListTasksQuery(query) {
114
+ return {
115
+ contextId: query['contextId'],
116
+ state: query['state'],
117
+ limit: query['limit'] ? parseInt(query['limit'], 10) : undefined,
118
+ pageToken: query['pageToken'],
119
+ };
120
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A2A Protocol Bindings - Barrel Export
3
+ *
4
+ * Re-exports all binding modules and provides cross-binding
5
+ * error code mapping for consistent error handling across transports.
6
+ */
7
+ export * from './jsonrpc.js';
8
+ export * from './http.js';
9
+ export * from './grpc.js';
10
+ import { type A2AErrorType } from './jsonrpc.js';
11
+ /** Complete error code mapping across all three transports */
12
+ export interface ErrorCodeMapping {
13
+ /** JSON-RPC numeric error code */
14
+ jsonRpcCode: number;
15
+ /** HTTP response status code */
16
+ httpStatus: number;
17
+ /** RFC 9457 Problem Details type URI */
18
+ httpTypeUri: string;
19
+ /** gRPC status name (e.g. NOT_FOUND) */
20
+ grpcStatus: string;
21
+ /** gRPC numeric status code */
22
+ grpcCode: number;
23
+ }
24
+ /** Precomputed cross-binding error mapping for all 9 A2A error types */
25
+ export declare const A2A_ERROR_MAPPINGS: ReadonlyMap<A2AErrorType, ErrorCodeMapping>;
26
+ /**
27
+ * Get the complete error code mapping for a given A2A error type.
28
+ * Returns consistent values across JSON-RPC, HTTP, and gRPC.
29
+ */
30
+ export declare function getErrorCodeMapping(errorType: A2AErrorType): ErrorCodeMapping;
31
+ export { A2A_GRPC_ERROR_REASONS } from './grpc.js';
32
+ export declare const SUPPORTED_A2A_VERSIONS: readonly ["1.0"];
33
+ export declare const DEFAULT_A2A_VERSION: "1.0";
34
+ export declare function parseA2AVersionHeader(headerValue: string | undefined): string[];
35
+ export declare function negotiateA2AVersion(requestedVersions: string[]): string | null;