@a2aletheia/a2a 0.2.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.
- package/README.md +153 -0
- package/dist/agent-selector.d.ts +12 -0
- package/dist/agent-selector.d.ts.map +1 -0
- package/dist/agent-selector.js +37 -0
- package/dist/agent-selector.js.map +1 -0
- package/dist/aletheia-a2a.d.ts +42 -0
- package/dist/aletheia-a2a.d.ts.map +1 -0
- package/dist/aletheia-a2a.js +171 -0
- package/dist/aletheia-a2a.js.map +1 -0
- package/dist/context-store.d.ts +20 -0
- package/dist/context-store.d.ts.map +1 -0
- package/dist/context-store.js +44 -0
- package/dist/context-store.js.map +1 -0
- package/dist/errors.d.ts +36 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +45 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/peer-agent.d.ts +144 -0
- package/dist/peer-agent.d.ts.map +1 -0
- package/dist/peer-agent.js +190 -0
- package/dist/peer-agent.js.map +1 -0
- package/dist/trust-pipeline.d.ts +12 -0
- package/dist/trust-pipeline.d.ts.map +1 -0
- package/dist/trust-pipeline.js +72 -0
- package/dist/trust-pipeline.js.map +1 -0
- package/dist/trusted-agent.d.ts +52 -0
- package/dist/trusted-agent.d.ts.map +1 -0
- package/dist/trusted-agent.js +198 -0
- package/dist/trusted-agent.js.map +1 -0
- package/dist/types.d.ts +107 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +66 -0
- package/dist/types.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# @a2aletheia/a2a
|
|
2
|
+
|
|
3
|
+
Server-side package that wraps [`@a2a-js/sdk`](https://www.npmjs.com/package/@a2a-js/sdk) with Aletheia's trust and identity layer. Requestors import this instead of `@a2a-js/sdk` directly.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @a2aletheia/a2a
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { AletheiaA2A } from "@a2aletheia/a2a";
|
|
15
|
+
|
|
16
|
+
const a2a = new AletheiaA2A({
|
|
17
|
+
registryUrl: "https://aletheia.example.com",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// High-level: discover + verify + send in one call
|
|
21
|
+
const response = await a2a.sendByCapability(
|
|
22
|
+
"translate-text",
|
|
23
|
+
"Translate hello to Spanish",
|
|
24
|
+
);
|
|
25
|
+
console.log(response.response); // Task or Message
|
|
26
|
+
console.log(response.trustInfo); // DID verified, liveness, trust score
|
|
27
|
+
|
|
28
|
+
// Streaming
|
|
29
|
+
const stream = a2a.streamByCapability(
|
|
30
|
+
"translate-text",
|
|
31
|
+
"Translate this document...",
|
|
32
|
+
);
|
|
33
|
+
for await (const event of stream) {
|
|
34
|
+
console.log(event.kind, event.event);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Connection-based API
|
|
39
|
+
|
|
40
|
+
Get a handle to a verified agent and reuse it for multiple messages:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// Connect by DID (full trust verification)
|
|
44
|
+
const agent = await a2a.connect("did:web:translate.example.com");
|
|
45
|
+
const response = await agent.send("Translate hello to Spanish");
|
|
46
|
+
|
|
47
|
+
// Connect by URL (skip registry, limited trust info)
|
|
48
|
+
const agent = await a2a.connectByUrl("https://translate.example.com");
|
|
49
|
+
const response = await agent.send("Translate hello to Spanish");
|
|
50
|
+
|
|
51
|
+
// Streaming
|
|
52
|
+
for await (const event of agent.stream("Translate this document...")) {
|
|
53
|
+
console.log(event.kind, event.event);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Task management
|
|
57
|
+
const task = await agent.getTask("task-id");
|
|
58
|
+
const canceled = await agent.cancelTask("task-id");
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
interface AletheiaA2AConfig {
|
|
65
|
+
registryUrl: string; // Aletheia registry API URL
|
|
66
|
+
agentSelector?: AgentSelector; // Default: HighestTrustSelector
|
|
67
|
+
minTrustScore?: number; // Default: 0
|
|
68
|
+
requireLive?: boolean; // Default: true
|
|
69
|
+
livenessCheckBeforeSend?: boolean; // Default: false (rely on registry cache)
|
|
70
|
+
verifyIdentity?: boolean; // Default: true
|
|
71
|
+
authToken?: string; // SIWE session token
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Agent Selectors
|
|
76
|
+
|
|
77
|
+
Three built-in strategies for choosing among discovered agents:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import {
|
|
81
|
+
HighestTrustSelector, // Default — highest trustScore, tie-break by liveness
|
|
82
|
+
RandomSelector, // Random pick
|
|
83
|
+
FirstMatchSelector, // First result (registry ordering)
|
|
84
|
+
} from "@a2aletheia/a2a";
|
|
85
|
+
|
|
86
|
+
const a2a = new AletheiaA2A({
|
|
87
|
+
registryUrl: "https://aletheia.example.com",
|
|
88
|
+
agentSelector: new RandomSelector(),
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Trust Pipeline
|
|
93
|
+
|
|
94
|
+
Every `connect()` and `sendByCapability()` call runs through the trust pipeline:
|
|
95
|
+
|
|
96
|
+
1. **DID Resolution** — verifies the agent's DID resolves (skippable via `verifyIdentity: false`)
|
|
97
|
+
2. **Liveness Check** — confirms the agent is reachable (fresh check via `livenessCheckBeforeSend: true`, or cached via `requireLive: true`)
|
|
98
|
+
3. **Trust Score Gate** — rejects agents below `minTrustScore`
|
|
99
|
+
|
|
100
|
+
Trust verification happens at **connection time**, not per-message. Stream events carry the `TrustInfo` snapshot from connection.
|
|
101
|
+
|
|
102
|
+
## Error Handling
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import {
|
|
106
|
+
AletheiaA2AError, // Base class
|
|
107
|
+
AgentNotFoundError, // No agents match capability/criteria
|
|
108
|
+
DIDResolutionError, // DID resolution failed
|
|
109
|
+
AgentNotLiveError, // Agent not reachable
|
|
110
|
+
TrustScoreBelowThresholdError, // Trust score below threshold
|
|
111
|
+
A2AProtocolError, // JSON-RPC error from A2A protocol
|
|
112
|
+
} from "@a2aletheia/a2a";
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
await a2a.sendByCapability("translate-text", "Hello");
|
|
116
|
+
} catch (err) {
|
|
117
|
+
if (err instanceof AgentNotFoundError) {
|
|
118
|
+
// No agents with "translate-text" capability
|
|
119
|
+
}
|
|
120
|
+
if (err instanceof A2AProtocolError) {
|
|
121
|
+
console.error(err.rpcCode, err.message);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Re-exported Types
|
|
127
|
+
|
|
128
|
+
All essential A2A protocol types are re-exported so consumers never need to depend on `@a2a-js/sdk`:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import type {
|
|
132
|
+
AgentCard,
|
|
133
|
+
Message,
|
|
134
|
+
Task,
|
|
135
|
+
TaskState,
|
|
136
|
+
TaskStatus,
|
|
137
|
+
Part,
|
|
138
|
+
TextPart,
|
|
139
|
+
FilePart,
|
|
140
|
+
DataPart,
|
|
141
|
+
Artifact,
|
|
142
|
+
TaskStatusUpdateEvent,
|
|
143
|
+
TaskArtifactUpdateEvent,
|
|
144
|
+
A2AClient,
|
|
145
|
+
A2AStreamEventData,
|
|
146
|
+
} from "@a2aletheia/a2a";
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Scope (v0.1.0)
|
|
150
|
+
|
|
151
|
+
**Included:** Discovery, DID verification, liveness checks, trust score gating, send/stream messaging, connection handles, agent selection strategies.
|
|
152
|
+
|
|
153
|
+
**Not included:** Server-side agent hosting, retry/circuit-breaker, connection pooling, response caching, multi-agent fan-out, payment integration, response signature verification, push notifications.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Agent } from "@a2aletheia/types";
|
|
2
|
+
import type { AgentSelector } from "./types.js";
|
|
3
|
+
export declare class HighestTrustSelector implements AgentSelector {
|
|
4
|
+
select(agents: Agent[]): Agent;
|
|
5
|
+
}
|
|
6
|
+
export declare class RandomSelector implements AgentSelector {
|
|
7
|
+
select(agents: Agent[]): Agent;
|
|
8
|
+
}
|
|
9
|
+
export declare class FirstMatchSelector implements AgentSelector {
|
|
10
|
+
select(agents: Agent[]): Agent;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=agent-selector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-selector.d.ts","sourceRoot":"","sources":["../src/agent-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAShD,qBAAa,oBAAqB,YAAW,aAAa;IACxD,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK;CAc/B;AAED,qBAAa,cAAe,YAAW,aAAa;IAClD,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK;CAI/B;AAED,qBAAa,kBAAmB,YAAW,aAAa;IACtD,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK;CAI/B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AgentNotFoundError } from "./errors.js";
|
|
2
|
+
function ensureNonEmpty(agents) {
|
|
3
|
+
if (agents.length === 0) {
|
|
4
|
+
throw new AgentNotFoundError("No agents match the given criteria");
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export class HighestTrustSelector {
|
|
8
|
+
select(agents) {
|
|
9
|
+
ensureNonEmpty(agents);
|
|
10
|
+
return agents.reduce((best, current) => {
|
|
11
|
+
const bestScore = best.trustScore ?? -1;
|
|
12
|
+
const currentScore = current.trustScore ?? -1;
|
|
13
|
+
if (currentScore > bestScore)
|
|
14
|
+
return current;
|
|
15
|
+
if (currentScore === bestScore) {
|
|
16
|
+
const bestLiveness = best.lastLivenessCheck?.getTime() ?? 0;
|
|
17
|
+
const currentLiveness = current.lastLivenessCheck?.getTime() ?? 0;
|
|
18
|
+
if (currentLiveness > bestLiveness)
|
|
19
|
+
return current;
|
|
20
|
+
}
|
|
21
|
+
return best;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class RandomSelector {
|
|
26
|
+
select(agents) {
|
|
27
|
+
ensureNonEmpty(agents);
|
|
28
|
+
return agents[Math.floor(Math.random() * agents.length)];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class FirstMatchSelector {
|
|
32
|
+
select(agents) {
|
|
33
|
+
ensureNonEmpty(agents);
|
|
34
|
+
return agents[0];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=agent-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-selector.js","sourceRoot":"","sources":["../src/agent-selector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,SAAS,cAAc,CAAC,MAAe;IACrC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,kBAAkB,CAAC,oCAAoC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAED,MAAM,OAAO,oBAAoB;IAC/B,MAAM,CAAC,MAAe;QACpB,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;YACrC,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC;YACxC,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC;YAC9C,IAAI,YAAY,GAAG,SAAS;gBAAE,OAAO,OAAO,CAAC;YAC7C,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;gBAC/B,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;gBAC5D,MAAM,eAAe,GAAG,OAAO,CAAC,iBAAiB,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;gBAClE,IAAI,eAAe,GAAG,YAAY;oBAAE,OAAO,OAAO,CAAC;YACrD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,OAAO,cAAc;IACzB,MAAM,CAAC,MAAe;QACpB,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,CAAE,CAAC;IAC5D,CAAC;CACF;AAED,MAAM,OAAO,kBAAkB;IAC7B,MAAM,CAAC,MAAe;QACpB,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,OAAO,MAAM,CAAC,CAAC,CAAE,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Agent, AletheiaLogger } from "@a2aletheia/types";
|
|
2
|
+
import type { AletheiaA2AConfig, MessageInput, SendOptions, TrustedResponse, TrustedStreamEvent } from "./types.js";
|
|
3
|
+
import { TrustedAgent } from "./trusted-agent.js";
|
|
4
|
+
export declare class AletheiaA2A {
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly aletheiaClient;
|
|
7
|
+
private readonly selector;
|
|
8
|
+
private readonly pipelineConfig;
|
|
9
|
+
readonly logger: AletheiaLogger;
|
|
10
|
+
/**
|
|
11
|
+
* Cache of connected agents keyed by DID.
|
|
12
|
+
* Reusing a TrustedAgent preserves conversation context (contextId/taskId).
|
|
13
|
+
*/
|
|
14
|
+
private readonly _connectionCache;
|
|
15
|
+
/** Cache of URL-connected agents (no DID lookup). */
|
|
16
|
+
private readonly _urlConnectionCache;
|
|
17
|
+
constructor(config: AletheiaA2AConfig);
|
|
18
|
+
discover(params: {
|
|
19
|
+
capability?: string;
|
|
20
|
+
query?: string;
|
|
21
|
+
isLive?: boolean;
|
|
22
|
+
minTrustScore?: number;
|
|
23
|
+
limit?: number;
|
|
24
|
+
}): Promise<Agent[]>;
|
|
25
|
+
connect(did: string): Promise<TrustedAgent>;
|
|
26
|
+
connectByUrl(url: string, options?: {
|
|
27
|
+
scope?: string;
|
|
28
|
+
}): Promise<TrustedAgent>;
|
|
29
|
+
sendByCapability(capability: string, input: string | MessageInput, options?: SendOptions): Promise<TrustedResponse>;
|
|
30
|
+
streamByCapability(capability: string, input: string | MessageInput, options?: SendOptions): AsyncGenerator<TrustedStreamEvent>;
|
|
31
|
+
/**
|
|
32
|
+
* Clear cached connections. Next send/connect will create fresh connections.
|
|
33
|
+
*/
|
|
34
|
+
clearConnections(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Clear the cached connection for a specific DID.
|
|
37
|
+
*/
|
|
38
|
+
disconnectAgent(did: string): void;
|
|
39
|
+
private _discoverAndSelect;
|
|
40
|
+
private _connectAgent;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=aletheia-a2a.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aletheia-a2a.d.ts","sourceRoot":"","sources":["../src/aletheia-a2a.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,KAAK,EACV,iBAAiB,EAEjB,YAAY,EACZ,WAAW,EACX,eAAe,EACf,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAQpB,OAAO,EA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AAG,EAAE,MAAM,GAAG,IAAI;YAQpB,kBAAkB;YAYlB,aAAa;CA8C5B"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { AletheiaClient, ConsoleLogger } from "@a2aletheia/sdk";
|
|
2
|
+
import { A2AClient } from "@a2a-js/sdk/client";
|
|
3
|
+
import { buildTrustInfo } from "./types.js";
|
|
4
|
+
import { HighestTrustSelector } from "./agent-selector.js";
|
|
5
|
+
import { buildPipelineConfig, verifySendPreconditions, } from "./trust-pipeline.js";
|
|
6
|
+
import { TrustedAgent } from "./trusted-agent.js";
|
|
7
|
+
import { AgentNotFoundError } from "./errors.js";
|
|
8
|
+
export class AletheiaA2A {
|
|
9
|
+
config;
|
|
10
|
+
aletheiaClient;
|
|
11
|
+
selector;
|
|
12
|
+
pipelineConfig;
|
|
13
|
+
logger;
|
|
14
|
+
/**
|
|
15
|
+
* Cache of connected agents keyed by DID.
|
|
16
|
+
* Reusing a TrustedAgent preserves conversation context (contextId/taskId).
|
|
17
|
+
*/
|
|
18
|
+
_connectionCache = new Map();
|
|
19
|
+
/** Cache of URL-connected agents (no DID lookup). */
|
|
20
|
+
_urlConnectionCache = new Map();
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.config = config;
|
|
23
|
+
this.logger = config.logger ?? new ConsoleLogger(config.logLevel ?? "info");
|
|
24
|
+
this.aletheiaClient = new AletheiaClient({
|
|
25
|
+
apiUrl: config.registryUrl,
|
|
26
|
+
});
|
|
27
|
+
if (config.authToken) {
|
|
28
|
+
this.aletheiaClient.setAuthToken(config.authToken);
|
|
29
|
+
}
|
|
30
|
+
this.selector = config.agentSelector ?? new HighestTrustSelector();
|
|
31
|
+
this.pipelineConfig = buildPipelineConfig(config);
|
|
32
|
+
}
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Discovery
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
async discover(params) {
|
|
37
|
+
this.logger.debug("Discovering agents", params);
|
|
38
|
+
const result = await this.aletheiaClient.discoverAgents({
|
|
39
|
+
capability: params.capability,
|
|
40
|
+
query: params.query,
|
|
41
|
+
isLive: params.isLive ?? (this.pipelineConfig.requireLive ? true : false),
|
|
42
|
+
minTrustScore: params.minTrustScore ??
|
|
43
|
+
(this.pipelineConfig.minTrustScore || undefined),
|
|
44
|
+
limit: params.limit,
|
|
45
|
+
});
|
|
46
|
+
this.logger.debug("Discovery result", { count: result.items.length });
|
|
47
|
+
return result.items;
|
|
48
|
+
}
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Connection-based API
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
async connect(did) {
|
|
53
|
+
// Return cached connection if available
|
|
54
|
+
const cached = this._connectionCache.get(did);
|
|
55
|
+
if (cached) {
|
|
56
|
+
this.logger.debug("Reusing cached connection", { did });
|
|
57
|
+
return cached;
|
|
58
|
+
}
|
|
59
|
+
this.logger.debug("Connecting to agent", { did });
|
|
60
|
+
const agent = await this.aletheiaClient.getAgent(did);
|
|
61
|
+
return this._connectAgent(agent);
|
|
62
|
+
}
|
|
63
|
+
async connectByUrl(url, options) {
|
|
64
|
+
// Scope isolates context per-caller (e.g. per chat session).
|
|
65
|
+
// Without scope, all callers share one conversation context — wrong for multi-user.
|
|
66
|
+
const cacheKey = options?.scope ? `${url}#${options.scope}` : url;
|
|
67
|
+
const cached = this._urlConnectionCache.get(cacheKey);
|
|
68
|
+
if (cached) {
|
|
69
|
+
this.logger.debug("Reusing cached URL connection", {
|
|
70
|
+
url,
|
|
71
|
+
scope: options?.scope,
|
|
72
|
+
});
|
|
73
|
+
return cached;
|
|
74
|
+
}
|
|
75
|
+
this.logger.debug("Connecting to agent by URL", {
|
|
76
|
+
url,
|
|
77
|
+
scope: options?.scope,
|
|
78
|
+
});
|
|
79
|
+
const a2aClient = new A2AClient(url);
|
|
80
|
+
const agentCard = await a2aClient.getAgentCard();
|
|
81
|
+
const trustInfo = buildTrustInfo(null);
|
|
82
|
+
const storeKey = options?.scope ? `${options.scope}:${url}` : `url:${url}`;
|
|
83
|
+
const trustedAgent = new TrustedAgent({
|
|
84
|
+
a2aClient,
|
|
85
|
+
agentCard,
|
|
86
|
+
agent: null,
|
|
87
|
+
trustInfo,
|
|
88
|
+
contextStore: this.config.contextStore,
|
|
89
|
+
storeKey,
|
|
90
|
+
});
|
|
91
|
+
if (this.config.contextStore) {
|
|
92
|
+
await trustedAgent.restoreContext();
|
|
93
|
+
}
|
|
94
|
+
this._urlConnectionCache.set(cacheKey, trustedAgent);
|
|
95
|
+
return trustedAgent;
|
|
96
|
+
}
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
// High-level send/stream
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
async sendByCapability(capability, input, options) {
|
|
101
|
+
const agent = await this._discoverAndSelect(capability);
|
|
102
|
+
const trustedAgent = await this._connectAgent(agent);
|
|
103
|
+
return trustedAgent.send(input, options);
|
|
104
|
+
}
|
|
105
|
+
async *streamByCapability(capability, input, options) {
|
|
106
|
+
const agent = await this._discoverAndSelect(capability);
|
|
107
|
+
const trustedAgent = await this._connectAgent(agent);
|
|
108
|
+
yield* trustedAgent.stream(input, options);
|
|
109
|
+
}
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// Cache management
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
/**
|
|
114
|
+
* Clear cached connections. Next send/connect will create fresh connections.
|
|
115
|
+
*/
|
|
116
|
+
clearConnections() {
|
|
117
|
+
this._connectionCache.clear();
|
|
118
|
+
this._urlConnectionCache.clear();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Clear the cached connection for a specific DID.
|
|
122
|
+
*/
|
|
123
|
+
disconnectAgent(did) {
|
|
124
|
+
this._connectionCache.delete(did);
|
|
125
|
+
}
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
// Internal
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
async _discoverAndSelect(capability) {
|
|
130
|
+
const agents = await this.discover({ capability });
|
|
131
|
+
if (agents.length === 0) {
|
|
132
|
+
throw new AgentNotFoundError(`No agents found with capability "${capability}"`);
|
|
133
|
+
}
|
|
134
|
+
return this.selector.select(agents);
|
|
135
|
+
}
|
|
136
|
+
async _connectAgent(agent) {
|
|
137
|
+
// Return cached connection if available
|
|
138
|
+
if (agent.did) {
|
|
139
|
+
const cached = this._connectionCache.get(agent.did);
|
|
140
|
+
if (cached) {
|
|
141
|
+
this.logger.debug("Reusing cached connection", { did: agent.did });
|
|
142
|
+
return cached;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const trustInfo = await verifySendPreconditions(agent, this.aletheiaClient, this.pipelineConfig, this.logger);
|
|
146
|
+
const a2aClient = new A2AClient(agent.url);
|
|
147
|
+
const agentCard = await a2aClient.getAgentCard();
|
|
148
|
+
this.logger.info("Connected to agent", {
|
|
149
|
+
did: agent.did,
|
|
150
|
+
name: agent.name,
|
|
151
|
+
});
|
|
152
|
+
const storeKey = agent.did ? `did:${agent.did}` : undefined;
|
|
153
|
+
const trustedAgent = new TrustedAgent({
|
|
154
|
+
a2aClient,
|
|
155
|
+
agentCard,
|
|
156
|
+
agent,
|
|
157
|
+
trustInfo,
|
|
158
|
+
contextStore: storeKey ? this.config.contextStore : undefined,
|
|
159
|
+
storeKey,
|
|
160
|
+
});
|
|
161
|
+
if (this.config.contextStore && storeKey) {
|
|
162
|
+
await trustedAgent.restoreContext();
|
|
163
|
+
}
|
|
164
|
+
// Cache the connection by DID
|
|
165
|
+
if (agent.did) {
|
|
166
|
+
this._connectionCache.set(agent.did, trustedAgent);
|
|
167
|
+
}
|
|
168
|
+
return trustedAgent;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=aletheia-a2a.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aletheia-a2a.js","sourceRoot":"","sources":["../src/aletheia-a2a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QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;YAC7D,QAAQ;SACT,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,QAAQ,EAAE,CAAC;YACzC,MAAM,YAAY,CAAC,cAAc,EAAE,CAAC;QACtC,CAAC;QAED,8BAA8B;QAC9B,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ContextStore, RedisLike } from "./types.js";
|
|
2
|
+
export interface RedisContextStoreOptions {
|
|
3
|
+
/** Key prefix. Default: `"aletheia:ctx:"` */
|
|
4
|
+
prefix?: string;
|
|
5
|
+
/** TTL in seconds. Default: `3600` (1 hour). Set to `0` to disable. */
|
|
6
|
+
ttlSeconds?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Create a {@link ContextStore} backed by any Redis-like client.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import IORedis from "ioredis";
|
|
13
|
+
* import { redisContextStore } from "@a2aletheia/a2a";
|
|
14
|
+
*
|
|
15
|
+
* const redis = new IORedis("redis://localhost:6380");
|
|
16
|
+
* const store = redisContextStore(redis, { ttlSeconds: 1800 });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function redisContextStore(redis: RedisLike, options?: RedisContextStoreOptions): ContextStore;
|
|
20
|
+
//# sourceMappingURL=context-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-store.d.ts","sourceRoot":"","sources":["../src/context-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAiB,MAAM,YAAY,CAAC;AAKzE,MAAM,WAAW,wBAAwB;IACvC,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,SAAS,EAChB,OAAO,CAAC,EAAE,wBAAwB,GACjC,YAAY,CA6Bd"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const DEFAULT_PREFIX = "aletheia:ctx:";
|
|
2
|
+
const DEFAULT_TTL = 3600; // 1 hour
|
|
3
|
+
/**
|
|
4
|
+
* Create a {@link ContextStore} backed by any Redis-like client.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import IORedis from "ioredis";
|
|
8
|
+
* import { redisContextStore } from "@a2aletheia/a2a";
|
|
9
|
+
*
|
|
10
|
+
* const redis = new IORedis("redis://localhost:6380");
|
|
11
|
+
* const store = redisContextStore(redis, { ttlSeconds: 1800 });
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function redisContextStore(redis, options) {
|
|
15
|
+
const prefix = options?.prefix ?? DEFAULT_PREFIX;
|
|
16
|
+
const ttl = options?.ttlSeconds ?? DEFAULT_TTL;
|
|
17
|
+
return {
|
|
18
|
+
async get(key) {
|
|
19
|
+
const raw = await redis.get(`${prefix}${key}`);
|
|
20
|
+
if (!raw)
|
|
21
|
+
return null;
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(raw);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
async set(key, data) {
|
|
30
|
+
const fullKey = `${prefix}${key}`;
|
|
31
|
+
const value = JSON.stringify(data);
|
|
32
|
+
if (ttl > 0) {
|
|
33
|
+
await redis.set(fullKey, value, "EX", ttl);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
await redis.set(fullKey, value);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
async delete(key) {
|
|
40
|
+
await redis.del(`${prefix}${key}`);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=context-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-store.js","sourceRoot":"","sources":["../src/context-store.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc,GAAG,eAAe,CAAC;AACvC,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,SAAS;AASnC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAgB,EAChB,OAAkC;IAElC,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,cAAc,CAAC;IACjD,MAAM,GAAG,GAAG,OAAO,EAAE,UAAU,IAAI,WAAW,CAAC;IAE/C,OAAO;QACL,KAAK,CAAC,GAAG,CAAC,GAAW;YACnB,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,GAAG,EAAE,CAAC,CAAC;YAC/C,IAAI,CAAC,GAAG;gBAAE,OAAO,IAAI,CAAC;YACtB,IAAI,CAAC;gBACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAkB,CAAC;YAC1C,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,IAAmB;YACxC,MAAM,OAAO,GAAG,GAAG,MAAM,GAAG,GAAG,EAAE,CAAC;YAClC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACnC,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;gBACZ,MAAM,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;YAC7C,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,GAAW;YACtB,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,GAAG,EAAE,CAAC,CAAC;QACrC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare class AletheiaA2AError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
constructor(message: string, code: string, options?: {
|
|
4
|
+
cause?: Error;
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
export declare class AgentNotFoundError extends AletheiaA2AError {
|
|
8
|
+
constructor(message: string, options?: {
|
|
9
|
+
cause?: Error;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export declare class DIDResolutionError extends AletheiaA2AError {
|
|
13
|
+
constructor(message: string, options?: {
|
|
14
|
+
cause?: Error;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export declare class AgentNotLiveError extends AletheiaA2AError {
|
|
18
|
+
constructor(message: string, options?: {
|
|
19
|
+
cause?: Error;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export declare class TrustScoreBelowThresholdError extends AletheiaA2AError {
|
|
23
|
+
readonly trustScore: number | null;
|
|
24
|
+
readonly threshold: number;
|
|
25
|
+
constructor(trustScore: number | null, threshold: number, options?: {
|
|
26
|
+
cause?: Error;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export declare class A2AProtocolError extends AletheiaA2AError {
|
|
30
|
+
readonly rpcCode: number | undefined;
|
|
31
|
+
constructor(message: string, options?: {
|
|
32
|
+
cause?: Error;
|
|
33
|
+
rpcCode?: number;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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letheiaA2AError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(message, code, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = "AletheiaA2AError";
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class AgentNotFoundError extends AletheiaA2AError {
|
|
10
|
+
constructor(message, options) {
|
|
11
|
+
super(message, "AGENT_NOT_FOUND", options);
|
|
12
|
+
this.name = "AgentNotFoundError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class DIDResolutionError extends AletheiaA2AError {
|
|
16
|
+
constructor(message, options) {
|
|
17
|
+
super(message, "DID_RESOLUTION_FAILED", options);
|
|
18
|
+
this.name = "DIDResolutionError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class AgentNotLiveError extends AletheiaA2AError {
|
|
22
|
+
constructor(message, options) {
|
|
23
|
+
super(message, "AGENT_NOT_LIVE", options);
|
|
24
|
+
this.name = "AgentNotLiveError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class TrustScoreBelowThresholdError extends AletheiaA2AError {
|
|
28
|
+
trustScore;
|
|
29
|
+
threshold;
|
|
30
|
+
constructor(trustScore, threshold, options) {
|
|
31
|
+
super(`Agent trust score ${trustScore ?? "unknown"} is below threshold ${threshold}`, "TRUST_SCORE_BELOW_THRESHOLD", options);
|
|
32
|
+
this.name = "TrustScoreBelowThresholdError";
|
|
33
|
+
this.trustScore = trustScore;
|
|
34
|
+
this.threshold = threshold;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export class A2AProtocolError extends AletheiaA2AError {
|
|
38
|
+
rpcCode;
|
|
39
|
+
constructor(message, options) {
|
|
40
|
+
super(message, "A2A_PROTOCOL_ERROR", options);
|
|
41
|
+
this.name = "A2AProtocolError";
|
|
42
|
+
this.rpcCode = options?.rpcCode;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=errors.js.map
|
|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U,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,gBAAgB;IAC3C,OAAO,CAAqB;IAErC,YACE,OAAe,EACf,OAA6C;QAE7C,KAAK,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC;IAClC,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { AletheiaA2A } from "./aletheia-a2a.js";
|
|
2
|
+
export { PeerAgent } from "./peer-agent.js";
|
|
3
|
+
export type { PeerAgentConfig } from "./peer-agent.js";
|
|
4
|
+
export { TrustedAgent } from "./trusted-agent.js";
|
|
5
|
+
export { HighestTrustSelector, RandomSelector, FirstMatchSelector, } from "./agent-selector.js";
|
|
6
|
+
export { redisContextStore } from "./context-store.js";
|
|
7
|
+
export type { RedisContextStoreOptions } from "./context-store.js";
|
|
8
|
+
export { AletheiaA2AError, AgentNotFoundError, DIDResolutionError, AgentNotLiveError, TrustScoreBelowThresholdError, A2AProtocolError, } from "./errors.js";
|
|
9
|
+
export type { AletheiaA2AConfig, AgentSelector, MessageInput, SendOptions, TrustInfo, TrustedResponse, TrustedStreamEvent, TrustedTaskResponse, ContextStore, StoredContext, RedisLike, } from "./types.js";
|
|
10
|
+
export type { AgentCard, Message, Task, TaskState, TaskStatus, Part, TextPart, FilePart, DataPart, Artifact, TaskStatusUpdateEvent, TaskArtifactUpdateEvent, MessageSendParams, MessageSendConfiguration, A2AClient, A2AStreamEventData, } from "./types.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAGnE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,6BAA6B,EAC7B,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,WAAW,EACX,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,SAAS,GACV,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,SAAS,EACT,OAAO,EACP,IAAI,EACJ,SAAS,EACT,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,EACjB,wBAAwB,EACxB,SAAS,EACT,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Main entry point
|
|
2
|
+
export { AletheiaA2A } from "./aletheia-a2a.js";
|
|
3
|
+
// Peer agent (full-duplex: server + client)
|
|
4
|
+
export { PeerAgent } from "./peer-agent.js";
|
|
5
|
+
// Connection handle
|
|
6
|
+
export { TrustedAgent } from "./trusted-agent.js";
|
|
7
|
+
// Agent selectors
|
|
8
|
+
export { HighestTrustSelector, RandomSelector, FirstMatchSelector, } from "./agent-selector.js";
|
|
9
|
+
// Context persistence
|
|
10
|
+
export { redisContextStore } from "./context-store.js";
|
|
11
|
+
// Errors
|
|
12
|
+
export { AletheiaA2AError, AgentNotFoundError, DIDResolutionError, AgentNotLiveError, TrustScoreBelowThresholdError, A2AProtocolError, } from "./errors.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,4CAA4C;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,oBAAoB;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,kBAAkB;AAClB,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAE7B,sBAAsB;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAGvD,SAAS;AACT,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,6BAA6B,EAC7B,gBAAgB,GACjB,MAAM,aAAa,CAAC"}
|