-
Notifications
You must be signed in to change notification settings - Fork 139
feat: defined compat-specific consts and mappings #478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JakubWorek
merged 2 commits into
epic/1.0_breaking_changes
from
jakubworek/define-compat-specific-constants-and-mappings
May 15, 2026
+471
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| /** | ||
| * Compat-layer constants and method-name mappings for the legacy A2A v0.3 | ||
| * protocol. | ||
| */ | ||
|
|
||
| import { A2AError } from './server/error.js'; | ||
|
|
||
| /** | ||
| * The legacy A2A protocol version this compat layer targets. | ||
| * | ||
| * Mirrors the `protocolVersion` field on legacy v0.3 AgentCards. | ||
| */ | ||
| export const A2A_LEGACY_PROTOCOL_VERSION = '0.3'; | ||
|
|
||
| /** | ||
| * The HTTP extension header used by legacy v0.3. | ||
| * | ||
| * Note: v0.3 used the `X-` prefixed form; the v1.0 spec dropped the prefix | ||
| * (see `HTTP_EXTENSION_HEADER` in `src/constants.ts`). | ||
| */ | ||
| export const LEGACY_HTTP_EXTENSION_HEADER = 'X-A2A-Extensions'; | ||
|
|
||
| /** | ||
| * The JSON content type used by legacy v0.3 JSON-RPC and REST transports. | ||
| * | ||
| * Unlike v1.0 (which uses `application/a2a+json` for REST/push payloads), | ||
| * v0.3 used plain `application/json` everywhere. | ||
| */ | ||
| export const LEGACY_JSON_CONTENT_TYPE = 'application/json'; | ||
|
|
||
| export const LEGACY_METHOD_MESSAGE_SEND = 'message/send'; | ||
| export const LEGACY_METHOD_MESSAGE_STREAM = 'message/stream'; | ||
| export const LEGACY_METHOD_TASKS_GET = 'tasks/get'; | ||
| export const LEGACY_METHOD_TASKS_CANCEL = 'tasks/cancel'; | ||
| export const LEGACY_METHOD_TASKS_RESUBSCRIBE = 'tasks/resubscribe'; | ||
| export const LEGACY_METHOD_PUSH_NOTIFICATION_CONFIG_SET = 'tasks/pushNotificationConfig/set'; | ||
| export const LEGACY_METHOD_PUSH_NOTIFICATION_CONFIG_GET = 'tasks/pushNotificationConfig/get'; | ||
| export const LEGACY_METHOD_PUSH_NOTIFICATION_CONFIG_LIST = 'tasks/pushNotificationConfig/list'; | ||
| export const LEGACY_METHOD_PUSH_NOTIFICATION_CONFIG_DELETE = 'tasks/pushNotificationConfig/delete'; | ||
| export const LEGACY_METHOD_GET_AUTHENTICATED_EXTENDED_CARD = 'agent/getAuthenticatedExtendedCard'; | ||
|
|
||
| /** v0.3 JSON-RPC method string -> v1.0 PascalCase method name. */ | ||
| export const LEGACY_JSONRPC_TO_V1: Readonly<Record<string, string>> = Object.freeze({ | ||
| [LEGACY_METHOD_MESSAGE_SEND]: 'SendMessage', | ||
| [LEGACY_METHOD_MESSAGE_STREAM]: 'SendStreamingMessage', | ||
| [LEGACY_METHOD_TASKS_GET]: 'GetTask', | ||
| [LEGACY_METHOD_TASKS_CANCEL]: 'CancelTask', | ||
| [LEGACY_METHOD_TASKS_RESUBSCRIBE]: 'SubscribeToTask', | ||
| [LEGACY_METHOD_PUSH_NOTIFICATION_CONFIG_SET]: 'CreateTaskPushNotificationConfig', | ||
| [LEGACY_METHOD_PUSH_NOTIFICATION_CONFIG_GET]: 'GetTaskPushNotificationConfig', | ||
| [LEGACY_METHOD_PUSH_NOTIFICATION_CONFIG_LIST]: 'ListTaskPushNotificationConfigs', | ||
| [LEGACY_METHOD_PUSH_NOTIFICATION_CONFIG_DELETE]: 'DeleteTaskPushNotificationConfig', | ||
| [LEGACY_METHOD_GET_AUTHENTICATED_EXTENDED_CARD]: 'GetExtendedAgentCard', | ||
| }); | ||
|
|
||
| /** | ||
| * v1.0 PascalCase method names that exist in v1.0 but have NO equivalent in | ||
| * v0.3 (neither JSON-RPC nor gRPC). Translating one of these names into the | ||
| * v0.3 coordinate system yields a "method not implemented in v0.3" error | ||
| * (JSON-RPC code -32004 / `A2AError.unsupportedOperation`) instead of the | ||
| * generic invalid-request error. | ||
| * | ||
| * Per §3.5.6 of the v0.3 spec, `tasks/list` was gRPC/REST-only in v0.3 (no | ||
| * JSON-RPC binding), and the v0.3 protobuf shipped in this repo has no | ||
| * `ListTasks` RPC at all -- so for compat purposes the v1.0 `ListTasks` | ||
| * method is treated as fully absent. | ||
| */ | ||
| export const V1_METHODS_WITHOUT_LEGACY_EQUIVALENT: ReadonlySet<string> = new Set(['ListTasks']); | ||
|
|
||
| /** | ||
| * v1.0 PascalCase method name -> v0.3 JSON-RPC method string. | ||
| * | ||
| * Methods listed in {@link V1_METHODS_WITHOUT_LEGACY_EQUIVALENT} are omitted. | ||
| */ | ||
| export const V1_TO_LEGACY_JSONRPC: Readonly<Record<string, string>> = Object.freeze( | ||
| Object.fromEntries(Object.entries(LEGACY_JSONRPC_TO_V1).map(([k, v]) => [v, k])) | ||
| ); | ||
|
|
||
| /** v0.3 JSON-RPC method string -> v0.3 gRPC PascalCase method name. */ | ||
| export const LEGACY_JSONRPC_TO_LEGACY_GRPC: Readonly<Record<string, string>> = Object.freeze({ | ||
| [LEGACY_METHOD_MESSAGE_SEND]: 'SendMessage', | ||
| [LEGACY_METHOD_MESSAGE_STREAM]: 'SendStreamingMessage', | ||
| [LEGACY_METHOD_TASKS_GET]: 'GetTask', | ||
| [LEGACY_METHOD_TASKS_CANCEL]: 'CancelTask', | ||
| [LEGACY_METHOD_TASKS_RESUBSCRIBE]: 'TaskSubscription', | ||
| [LEGACY_METHOD_PUSH_NOTIFICATION_CONFIG_SET]: 'CreateTaskPushNotificationConfig', | ||
| [LEGACY_METHOD_PUSH_NOTIFICATION_CONFIG_GET]: 'GetTaskPushNotificationConfig', | ||
| [LEGACY_METHOD_PUSH_NOTIFICATION_CONFIG_LIST]: 'ListTaskPushNotificationConfig', | ||
| [LEGACY_METHOD_PUSH_NOTIFICATION_CONFIG_DELETE]: 'DeleteTaskPushNotificationConfig', | ||
| [LEGACY_METHOD_GET_AUTHENTICATED_EXTENDED_CARD]: 'GetAgentCard', | ||
| }); | ||
|
|
||
| /** v0.3 gRPC PascalCase method name -> v0.3 JSON-RPC method string. */ | ||
| export const LEGACY_GRPC_TO_LEGACY_JSONRPC: Readonly<Record<string, string>> = Object.freeze( | ||
| Object.fromEntries(Object.entries(LEGACY_JSONRPC_TO_LEGACY_GRPC).map(([k, v]) => [v, k])) | ||
| ); | ||
|
|
||
| /** v0.3 gRPC PascalCase method name -> v1.0 PascalCase method name. */ | ||
| export const LEGACY_GRPC_TO_V1: Readonly<Record<string, string>> = Object.freeze( | ||
| Object.fromEntries( | ||
| Object.entries(LEGACY_JSONRPC_TO_LEGACY_GRPC).map(([jsonRpc, grpc]) => [ | ||
| grpc, | ||
| LEGACY_JSONRPC_TO_V1[jsonRpc], | ||
| ]) | ||
| ) | ||
| ); | ||
|
|
||
| /** | ||
| * v1.0 PascalCase method name -> v0.3 gRPC PascalCase method name. | ||
| * | ||
| * Methods listed in {@link V1_METHODS_WITHOUT_LEGACY_EQUIVALENT} are omitted. | ||
| */ | ||
| export const V1_TO_LEGACY_GRPC: Readonly<Record<string, string>> = Object.freeze( | ||
| Object.fromEntries(Object.entries(LEGACY_GRPC_TO_V1).map(([k, v]) => [v, k])) | ||
| ); | ||
|
|
||
| const lookup = ( | ||
| table: Readonly<Record<string, string>>, | ||
| method: string, | ||
| direction: string | ||
| ): string => { | ||
| const mapped = table[method]; | ||
| if (mapped === undefined) { | ||
| throw A2AError.invalidRequest(`Unknown ${direction} method: "${method}"`); | ||
| } | ||
| return mapped; | ||
| }; | ||
|
JakubWorek marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Looks up `method` in `table`. If the lookup fails AND `method` is a known | ||
| * v1.0 method that has no v0.3 equivalent (per | ||
| * {@link V1_METHODS_WITHOUT_LEGACY_EQUIVALENT}), throws | ||
| * `A2AError.unsupportedOperation` (-32004) so callers can distinguish "this | ||
| * is a real v1.0 method but v0.3 simply does not implement it" from "this | ||
| * name is gibberish". Otherwise behaves like {@link lookup}. | ||
| */ | ||
| const lookupFromV1 = ( | ||
| table: Readonly<Record<string, string>>, | ||
| method: string, | ||
| legacyTransport: string | ||
| ): string => { | ||
| const mapped = table[method]; | ||
| if (mapped !== undefined) return mapped; | ||
| if (V1_METHODS_WITHOUT_LEGACY_EQUIVALENT.has(method)) { | ||
| throw A2AError.unsupportedOperation( | ||
| `v1.0 method "${method}" has no equivalent in v0.3 ${legacyTransport}` | ||
| ); | ||
| } | ||
| throw A2AError.invalidRequest(`Unknown v1.0 method: "${method}"`); | ||
| }; | ||
|
|
||
| /** Translate a v0.3 JSON-RPC method name to its v1.0 PascalCase equivalent. */ | ||
| export function legacyJsonRpcToV1Method(method: string): string { | ||
| return lookup(LEGACY_JSONRPC_TO_V1, method, 'legacy JSON-RPC'); | ||
| } | ||
|
|
||
| /** | ||
| * Translate a v1.0 PascalCase method name to its v0.3 JSON-RPC equivalent. | ||
| * | ||
| * Throws `A2AError.unsupportedOperation` (-32004) if `method` is a v1.0 name | ||
| * that has no v0.3 equivalent (e.g. `ListTasks`); throws | ||
| * `A2AError.invalidRequest` (-32600) if `method` is not a known v1.0 method | ||
| * at all. | ||
| */ | ||
| export function v1MethodToLegacyJsonRpc(method: string): string { | ||
| return lookupFromV1(V1_TO_LEGACY_JSONRPC, method, 'JSON-RPC'); | ||
| } | ||
|
|
||
| /** Translate a v0.3 JSON-RPC method name to its v0.3 gRPC equivalent. */ | ||
| export function legacyJsonRpcToLegacyGrpcMethod(method: string): string { | ||
| return lookup(LEGACY_JSONRPC_TO_LEGACY_GRPC, method, 'legacy JSON-RPC'); | ||
| } | ||
|
|
||
| /** Translate a v0.3 gRPC method name to its v0.3 JSON-RPC equivalent. */ | ||
| export function legacyGrpcToLegacyJsonRpcMethod(method: string): string { | ||
| return lookup(LEGACY_GRPC_TO_LEGACY_JSONRPC, method, 'legacy gRPC'); | ||
| } | ||
|
|
||
| /** Translate a v0.3 gRPC method name to its v1.0 PascalCase equivalent. */ | ||
| export function legacyGrpcToV1Method(method: string): string { | ||
| return lookup(LEGACY_GRPC_TO_V1, method, 'legacy gRPC'); | ||
| } | ||
|
|
||
| /** | ||
| * Translate a v1.0 PascalCase method name to its v0.3 gRPC equivalent. | ||
| * | ||
| * Throws `A2AError.unsupportedOperation` (-32004) if `method` is a v1.0 name | ||
| * that has no v0.3 equivalent (e.g. `ListTasks`); throws | ||
| * `A2AError.invalidRequest` (-32600) if `method` is not a known v1.0 method | ||
| * at all. | ||
| */ | ||
| export function v1MethodToLegacyGrpc(method: string): string { | ||
| return lookupFromV1(V1_TO_LEGACY_GRPC, method, 'gRPC'); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /** | ||
| * Compat-layer constants and method-name mappings for the legacy A2A v0.3 | ||
| * protocol. | ||
| */ | ||
|
|
||
| export * from './constants.js'; | ||
| export { A2AError as LegacyA2AError } from './server/error.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.