-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: native A2A protocol support (Phase 8) #4
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
Open
OlaCryto
wants to merge
5
commits into
iJaack:main
Choose a base branch
from
OlaCryto:a2a-phase8
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fc24a3e
feat: native A2A protocol support — Phase 8
OlaCryto 94309c4
fix: preserve canceled status after handler completes, return 400 for…
OlaCryto 1f91218
fix: address remaining Codex review comments on A2A server
OlaCryto d1e56c7
fix: enforce auth on task endpoints, preserve binary artifacts, safe …
OlaCryto e3086d6
fix: route on pathname not raw URL, honor auth placement, parse SSE d…
OlaCryto 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,192 @@ | ||
| /** | ||
| * A2A ↔ Evalanche Economy Adapters | ||
| * | ||
| * Maps A2A protocol concepts to evalanche economy primitives: | ||
| * - Agent Card skills → DiscoveryClient AgentService shape | ||
| * - A2A task submission → NegotiationClient.propose() | ||
| * - A2A task completion → settlement trigger | ||
| * - A2A task failure → negotiation rejection + escrow refund | ||
| * - AgentCard → AgentRegistration bridge | ||
| */ | ||
| import type { AgentService, DiscoveryQuery } from '../economy/types'; | ||
| import type { NegotiationClient } from '../economy/negotiation'; | ||
| import type { EscrowClient } from '../economy/escrow'; | ||
| import type { | ||
| AgentCard, | ||
| A2ASkill, | ||
| A2ATask, | ||
| AgentRegistration, | ||
| AgentServiceEntry, | ||
| } from './schemas'; | ||
|
|
||
| // ── Agent Card → Discovery Mapping ── | ||
|
|
||
| /** | ||
| * Convert an A2A Agent Card skill into an evalanche AgentService shape. | ||
| * This allows A2A-discovered agents to appear in evalanche's DiscoveryClient. | ||
| */ | ||
| export function skillToAgentService( | ||
| skill: A2ASkill, | ||
| card: AgentCard, | ||
| agentId: string, | ||
| ): AgentService { | ||
| return { | ||
| agentId, | ||
| capability: skill.id, | ||
| description: `${skill.name}: ${skill.description}`, | ||
| endpoint: card.url, | ||
| pricePerCall: '0', | ||
| chainId: 1, | ||
| registeredAt: Date.now(), | ||
| tags: skill.tags ?? [], | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Convert all skills from an Agent Card into evalanche AgentService entries. | ||
| */ | ||
| export function cardToAgentServices(card: AgentCard, agentId: string): AgentService[] { | ||
| return card.skills.map((skill) => skillToAgentService(skill, card, agentId)); | ||
| } | ||
|
|
||
| /** | ||
| * Bridge an A2A AgentCard to an ERC-8004 AgentRegistration shape. | ||
| * Useful for treating A2A and ERC-8004 as interchangeable discovery sources. | ||
| */ | ||
| export function cardToRegistration(card: AgentCard, walletAddress?: string): AgentRegistration { | ||
| const services: AgentServiceEntry[] = [ | ||
| { name: 'A2A', endpoint: card.url, version: card.version }, | ||
| ]; | ||
|
|
||
| return { | ||
| name: card.name, | ||
| description: card.description ?? '', | ||
| agentWallet: walletAddress ?? '', | ||
| active: true, | ||
| services, | ||
| x402Support: card.authentication?.type === 'x402', | ||
| supportedTrust: [], | ||
| registrations: [], | ||
| }; | ||
| } | ||
|
|
||
| // ── Task → Negotiation Mapping ── | ||
|
|
||
| /** Parameters for creating a negotiation proposal from an A2A task */ | ||
| export interface A2ATaskProposalParams { | ||
| /** The agent card of the target agent */ | ||
| card: AgentCard; | ||
| /** The skill to invoke */ | ||
| skillId: string; | ||
| /** Task input text */ | ||
| input: string; | ||
| /** Proposed price in wei */ | ||
| price: string; | ||
| /** Chain ID for payment */ | ||
| chainId: number; | ||
| /** ID of the proposing agent */ | ||
| fromAgentId: string; | ||
| /** ID of the target agent */ | ||
| toAgentId: string; | ||
| /** TTL for the proposal in ms */ | ||
| ttlMs?: number; | ||
| } | ||
|
|
||
| /** | ||
| * Create a negotiation proposal backed by an A2A task intent. | ||
| * Returns the proposal ID — use it to track the proposal lifecycle. | ||
| */ | ||
| export function createA2AProposal( | ||
| negotiation: NegotiationClient, | ||
| params: A2ATaskProposalParams, | ||
| ): string { | ||
| return negotiation.propose({ | ||
| fromAgentId: params.fromAgentId, | ||
| toAgentId: params.toAgentId, | ||
| task: `a2a:${params.skillId}`, | ||
| price: params.price, | ||
| chainId: params.chainId, | ||
| ttlMs: params.ttlMs, | ||
| }); | ||
| } | ||
|
|
||
| // ── Task Completion → Settlement ── | ||
|
|
||
| /** | ||
| * Handle A2A task completion — triggers settlement if proposal exists. | ||
| * | ||
| * When an A2A task completes successfully with artifacts, | ||
| * this maps it to the evalanche settlement flow. | ||
| */ | ||
| export function mapTaskCompletion(task: A2ATask): { | ||
| completed: boolean; | ||
| failed: boolean; | ||
| artifacts: Array<{ name?: string; mimeType?: string; text?: string; data?: string; uri?: string }>; | ||
| error?: string; | ||
| } { | ||
| const completed = task.status === 'completed'; | ||
| const failed = task.status === 'failed' || task.status === 'canceled'; | ||
|
|
||
| return { | ||
| completed, | ||
| failed, | ||
| artifacts: task.artifacts.map((a) => ({ | ||
| name: a.name, | ||
| mimeType: a.mimeType, | ||
| text: a.text, | ||
| data: a.data, | ||
| uri: a.uri, | ||
| })), | ||
| error: task.error?.message, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Handle A2A task failure — reject negotiation and refund escrow if funded. | ||
| */ | ||
| export async function handleTaskFailure( | ||
| task: A2ATask, | ||
| proposalId: string, | ||
| negotiation: NegotiationClient, | ||
| escrow?: EscrowClient, | ||
| jobId?: string, | ||
| ): Promise<void> { | ||
| // Reject the negotiation | ||
| try { | ||
| negotiation.reject(proposalId); | ||
| } catch { | ||
| // May already be in a terminal state — that's fine | ||
| } | ||
|
|
||
| // Refund escrow if it was funded | ||
| if (escrow && jobId) { | ||
| try { | ||
| await escrow.refund(jobId); | ||
| } catch { | ||
| // Escrow may not exist or already be released | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // ── Discovery Query Helpers ── | ||
|
|
||
| /** | ||
| * Build a DiscoveryQuery that matches A2A-sourced services. | ||
| */ | ||
| export function buildA2ADiscoveryQuery(options?: { | ||
| capability?: string; | ||
| tag?: string; | ||
| supportsStreaming?: boolean; | ||
| }): DiscoveryQuery { | ||
| const query: DiscoveryQuery = {}; | ||
|
|
||
| if (options?.capability) { | ||
| query.capability = options.capability; | ||
| } | ||
|
|
||
| if (options?.tag) { | ||
| query.tags = [options.tag]; | ||
| } | ||
|
|
||
| return query; | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mapTaskCompletionstrips each artifact down toname,mimeType,text, anduri, dropping thedatapayload fromA2AArtifact. Any task that returns binary/base64 artifacts will lose its output content at this adapter boundary, which can break downstream settlement/result consumers that need the full artifact.Useful? React with 👍 / 👎.