@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.
@@ -0,0 +1,144 @@
1
+ import type { Agent } from "@a2aletheia/types";
2
+ import type { AletheiaLogger, AletheiaLogLevel, AletheiaEventType, AletheiaEventHandler } from "@a2aletheia/types";
3
+ import type { AgentCard, AgentSkill, AgentCapabilities, A2AResponse } from "@a2a-js/sdk";
4
+ import type { TaskStore, A2ARequestHandler } from "@a2a-js/sdk/server";
5
+ import { AletheiaAgent, type AletheiaExtensions, type AgentHandler, type CancelHandler } from "@a2aletheia/sdk/agent";
6
+ import { AletheiaA2A } from "./aletheia-a2a.js";
7
+ import type { AgentSelector, MessageInput, SendOptions, TrustedResponse, TrustedStreamEvent } from "./types.js";
8
+ import type { TrustedAgent } from "./trusted-agent.js";
9
+ export interface PeerAgentConfig {
10
+ registryUrl: string;
11
+ name: string;
12
+ version: string;
13
+ url: string;
14
+ description: string;
15
+ skills: AgentSkill[];
16
+ defaultInputModes?: string[];
17
+ defaultOutputModes?: string[];
18
+ capabilities?: Partial<AgentCapabilities>;
19
+ iconUrl?: string;
20
+ documentationUrl?: string;
21
+ provider?: {
22
+ organization: string;
23
+ url: string;
24
+ };
25
+ aletheiaExtensions?: AletheiaExtensions;
26
+ taskStore?: TaskStore;
27
+ agentSelector?: AgentSelector;
28
+ minTrustScore?: number;
29
+ requireLive?: boolean;
30
+ livenessCheckBeforeSend?: boolean;
31
+ verifyIdentity?: boolean;
32
+ authToken?: string;
33
+ logger?: AletheiaLogger;
34
+ logLevel?: AletheiaLogLevel;
35
+ }
36
+ /**
37
+ * A full-duplex peer that can both host an A2A agent (inbound) and
38
+ * send trust-verified requests to other agents (outbound).
39
+ *
40
+ * Composes `AletheiaAgent` (server) + `AletheiaA2A` (client).
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * import { PeerAgent } from "@a2aletheia/a2a";
45
+ *
46
+ * const peer = new PeerAgent({
47
+ * registryUrl: "https://registry.aletheia.dev",
48
+ * name: "Orchestrator",
49
+ * version: "1.0.0",
50
+ * url: "https://orchestrator.example.com",
51
+ * description: "Routes work to specialist agents",
52
+ * skills: [{ id: "orchestrate", name: "orchestrate", description: "Orchestrate tasks", tags: [] }],
53
+ * minTrustScore: 0.7,
54
+ * });
55
+ *
56
+ * peer.handle(async (context, response) => {
57
+ * // Use outbound client inside the handler
58
+ * const result = await peer.sendByCapability("translate", context.textContent);
59
+ * response.text(result.response);
60
+ * });
61
+ *
62
+ * await peer.start(4000);
63
+ * ```
64
+ */
65
+ export declare class PeerAgent {
66
+ private readonly agent;
67
+ private readonly client;
68
+ constructor(config: PeerAgentConfig);
69
+ /**
70
+ * Register the message handler for incoming requests.
71
+ */
72
+ handle(handler: AgentHandler): this;
73
+ /**
74
+ * Register an optional cancel handler.
75
+ */
76
+ onCancel(handler: CancelHandler): this;
77
+ /**
78
+ * Handle a JSON-RPC request body (framework-agnostic).
79
+ */
80
+ handleRequest(body: unknown): Promise<A2AResponse | AsyncGenerator<A2AResponse, void, undefined>>;
81
+ /**
82
+ * Subscribe to lifecycle events. Returns an unsubscribe function.
83
+ */
84
+ on(event: AletheiaEventType | "*", handler: AletheiaEventHandler): () => void;
85
+ /**
86
+ * Discover agents by capability, query, or trust criteria.
87
+ */
88
+ discover(params: {
89
+ capability?: string;
90
+ query?: string;
91
+ isLive?: boolean;
92
+ minTrustScore?: number;
93
+ limit?: number;
94
+ }): Promise<Agent[]>;
95
+ /**
96
+ * Connect to an agent by DID with trust verification.
97
+ */
98
+ connect(did: string): Promise<TrustedAgent>;
99
+ /**
100
+ * Connect to an agent by URL (no trust verification).
101
+ */
102
+ connectByUrl(url: string): Promise<TrustedAgent>;
103
+ /**
104
+ * Discover, select, and send a message by capability.
105
+ */
106
+ sendByCapability(capability: string, input: string | MessageInput, options?: SendOptions): Promise<TrustedResponse>;
107
+ /**
108
+ * Discover, select, and stream a response by capability.
109
+ */
110
+ streamByCapability(capability: string, input: string | MessageInput, options?: SendOptions): AsyncGenerator<TrustedStreamEvent>;
111
+ /**
112
+ * Start a standalone Express server.
113
+ */
114
+ start(port: number): Promise<void>;
115
+ /**
116
+ * Stop the standalone server if running.
117
+ */
118
+ stop(): void;
119
+ /**
120
+ * Get the agent's AgentCard.
121
+ */
122
+ getAgentCard(): AgentCard;
123
+ /**
124
+ * Get the underlying request handler for custom integrations.
125
+ */
126
+ getRequestHandler(): A2ARequestHandler;
127
+ /**
128
+ * Get the task store.
129
+ */
130
+ getTaskStore(): TaskStore;
131
+ /**
132
+ * Get Aletheia-specific extensions.
133
+ */
134
+ getAletheiaExtensions(): AletheiaExtensions | undefined;
135
+ /**
136
+ * Get the underlying AletheiaAgent (escape hatch).
137
+ */
138
+ getAgent(): AletheiaAgent;
139
+ /**
140
+ * Get the underlying AletheiaA2A client (escape hatch).
141
+ */
142
+ getClient(): AletheiaA2A;
143
+ }
144
+ //# sourceMappingURL=peer-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peer-agent.d.ts","sourceRoot":"","sources":["../src/peer-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,WAAW,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EACL,aAAa,EAEb,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,aAAa,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,WAAW,EACX,eAAe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IAAI,iBAAiB;IAItC;;OAEG;IACH,YAAY,IAAI,SAAS;IAIzB;;OAEG;IACH,qBAAqB,IAAI,kBAAkB,GAAG,SAAS;IAIvD;;OAEG;IACH,QAAQ,IAAI,aAAa;IAIzB;;OAEG;IACH,SAAS,IAAI,WAAW;CAGzB"}
@@ -0,0 +1,190 @@
1
+ import { AletheiaAgent, } from "@a2aletheia/sdk/agent";
2
+ import { AletheiaA2A } from "./aletheia-a2a.js";
3
+ // ---------------------------------------------------------------------------
4
+ // PeerAgent
5
+ // ---------------------------------------------------------------------------
6
+ /**
7
+ * A full-duplex peer that can both host an A2A agent (inbound) and
8
+ * send trust-verified requests to other agents (outbound).
9
+ *
10
+ * Composes `AletheiaAgent` (server) + `AletheiaA2A` (client).
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { PeerAgent } from "@a2aletheia/a2a";
15
+ *
16
+ * const peer = new PeerAgent({
17
+ * registryUrl: "https://registry.aletheia.dev",
18
+ * name: "Orchestrator",
19
+ * version: "1.0.0",
20
+ * url: "https://orchestrator.example.com",
21
+ * description: "Routes work to specialist agents",
22
+ * skills: [{ id: "orchestrate", name: "orchestrate", description: "Orchestrate tasks", tags: [] }],
23
+ * minTrustScore: 0.7,
24
+ * });
25
+ *
26
+ * peer.handle(async (context, response) => {
27
+ * // Use outbound client inside the handler
28
+ * const result = await peer.sendByCapability("translate", context.textContent);
29
+ * response.text(result.response);
30
+ * });
31
+ *
32
+ * await peer.start(4000);
33
+ * ```
34
+ */
35
+ export class PeerAgent {
36
+ agent;
37
+ client;
38
+ constructor(config) {
39
+ const agentConfig = {
40
+ name: config.name,
41
+ version: config.version,
42
+ url: config.url,
43
+ description: config.description,
44
+ skills: config.skills,
45
+ defaultInputModes: config.defaultInputModes,
46
+ defaultOutputModes: config.defaultOutputModes,
47
+ capabilities: config.capabilities,
48
+ iconUrl: config.iconUrl,
49
+ documentationUrl: config.documentationUrl,
50
+ provider: config.provider,
51
+ aletheiaExtensions: config.aletheiaExtensions,
52
+ registryUrl: config.registryUrl,
53
+ taskStore: config.taskStore,
54
+ logger: config.logger,
55
+ logLevel: config.logLevel,
56
+ };
57
+ this.agent = new AletheiaAgent(agentConfig);
58
+ this.client = new AletheiaA2A({
59
+ registryUrl: config.registryUrl,
60
+ agentSelector: config.agentSelector,
61
+ minTrustScore: config.minTrustScore,
62
+ requireLive: config.requireLive,
63
+ livenessCheckBeforeSend: config.livenessCheckBeforeSend,
64
+ verifyIdentity: config.verifyIdentity,
65
+ authToken: config.authToken,
66
+ logger: config.logger,
67
+ logLevel: config.logLevel,
68
+ });
69
+ }
70
+ // ---------------------------------------------------------------------------
71
+ // Inbound (delegated to AletheiaAgent)
72
+ // ---------------------------------------------------------------------------
73
+ /**
74
+ * Register the message handler for incoming requests.
75
+ */
76
+ handle(handler) {
77
+ this.agent.handle(handler);
78
+ return this;
79
+ }
80
+ /**
81
+ * Register an optional cancel handler.
82
+ */
83
+ onCancel(handler) {
84
+ this.agent.onCancel(handler);
85
+ return this;
86
+ }
87
+ /**
88
+ * Handle a JSON-RPC request body (framework-agnostic).
89
+ */
90
+ async handleRequest(body) {
91
+ return this.agent.handleRequest(body);
92
+ }
93
+ // ---------------------------------------------------------------------------
94
+ // Lifecycle event hooks
95
+ // ---------------------------------------------------------------------------
96
+ /**
97
+ * Subscribe to lifecycle events. Returns an unsubscribe function.
98
+ */
99
+ on(event, handler) {
100
+ return this.agent.on(event, handler);
101
+ }
102
+ // ---------------------------------------------------------------------------
103
+ // Outbound (delegated to AletheiaA2A)
104
+ // ---------------------------------------------------------------------------
105
+ /**
106
+ * Discover agents by capability, query, or trust criteria.
107
+ */
108
+ async discover(params) {
109
+ return this.client.discover(params);
110
+ }
111
+ /**
112
+ * Connect to an agent by DID with trust verification.
113
+ */
114
+ async connect(did) {
115
+ return this.client.connect(did);
116
+ }
117
+ /**
118
+ * Connect to an agent by URL (no trust verification).
119
+ */
120
+ async connectByUrl(url) {
121
+ return this.client.connectByUrl(url);
122
+ }
123
+ /**
124
+ * Discover, select, and send a message by capability.
125
+ */
126
+ async sendByCapability(capability, input, options) {
127
+ return this.client.sendByCapability(capability, input, options);
128
+ }
129
+ /**
130
+ * Discover, select, and stream a response by capability.
131
+ */
132
+ async *streamByCapability(capability, input, options) {
133
+ yield* this.client.streamByCapability(capability, input, options);
134
+ }
135
+ // ---------------------------------------------------------------------------
136
+ // Lifecycle
137
+ // ---------------------------------------------------------------------------
138
+ /**
139
+ * Start a standalone Express server.
140
+ */
141
+ async start(port) {
142
+ return this.agent.start(port);
143
+ }
144
+ /**
145
+ * Stop the standalone server if running.
146
+ */
147
+ stop() {
148
+ this.agent.stop();
149
+ }
150
+ // ---------------------------------------------------------------------------
151
+ // Accessors
152
+ // ---------------------------------------------------------------------------
153
+ /**
154
+ * Get the agent's AgentCard.
155
+ */
156
+ getAgentCard() {
157
+ return this.agent.getAgentCard();
158
+ }
159
+ /**
160
+ * Get the underlying request handler for custom integrations.
161
+ */
162
+ getRequestHandler() {
163
+ return this.agent.getRequestHandler();
164
+ }
165
+ /**
166
+ * Get the task store.
167
+ */
168
+ getTaskStore() {
169
+ return this.agent.getTaskStore();
170
+ }
171
+ /**
172
+ * Get Aletheia-specific extensions.
173
+ */
174
+ getAletheiaExtensions() {
175
+ return this.agent.getAletheiaExtensions();
176
+ }
177
+ /**
178
+ * Get the underlying AletheiaAgent (escape hatch).
179
+ */
180
+ getAgent() {
181
+ return this.agent;
182
+ }
183
+ /**
184
+ * Get the underlying AletheiaA2A client (escape hatch).
185
+ */
186
+ getClient() {
187
+ return this.client;
188
+ }
189
+ }
190
+ //# sourceMappingURL=peer-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peer-agent.js","sourceRoot":"","sources":["../src/peer-agent.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,aAAa,GAKd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA8ChD,8EAA8E;AAC9E,YAAY;AACZ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E,OAAO,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,CAAC,kBAAkB,CACvB,UAAkB,EAClB,KAA4B,EAC5B,OAAqB;QAErB,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;IAED,8EAA8E;IAC9E,YAAY;IACZ,8EAA8E;IAE9E;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,IAAY;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAI;QACF,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACpB,CAAC;IAED,8EAA8E;IAC9E,YAAY;IACZ,8EAA8E;IAE9E;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,qBAAqB;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import type { Agent, AletheiaLogger } from "@a2aletheia/types";
2
+ import type { AletheiaClient } from "@a2aletheia/sdk";
3
+ import type { AletheiaA2AConfig, TrustInfo } from "./types.js";
4
+ export interface TrustPipelineConfig {
5
+ verifyIdentity: boolean;
6
+ livenessCheckBeforeSend: boolean;
7
+ minTrustScore: number;
8
+ requireLive: boolean;
9
+ }
10
+ export declare function buildPipelineConfig(config: AletheiaA2AConfig): TrustPipelineConfig;
11
+ export declare function verifySendPreconditions(agent: Agent, client: AletheiaClient, pipelineConfig: TrustPipelineConfig, logger?: AletheiaLogger): Promise<TrustInfo>;
12
+ //# sourceMappingURL=trust-pipeline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trust-pipeline.d.ts","sourceRoot":"","sources":["../src/trust-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAQ/D,MAAM,WAAW,mBAAmB;IAClC,cAAc,EAAE,OAAO,CAAC;IACxB,uBAAuB,EAAE,OAAO,CAAC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,iBAAiB,GACxB,mBAAmB,CAOrB;AAED,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,cAAc,EACtB,cAAc,EAAE,mBAAmB,EACnC,MAAM,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,SAAS,CAAC,CAsEpB"}
@@ -0,0 +1,72 @@
1
+ import { buildTrustInfo } from "./types.js";
2
+ import { DIDResolutionError, AgentNotLiveError, TrustScoreBelowThresholdError, } from "./errors.js";
3
+ export function buildPipelineConfig(config) {
4
+ return {
5
+ verifyIdentity: config.verifyIdentity ?? true,
6
+ livenessCheckBeforeSend: config.livenessCheckBeforeSend ?? false,
7
+ minTrustScore: config.minTrustScore ?? 0,
8
+ requireLive: config.requireLive ?? true,
9
+ };
10
+ }
11
+ export async function verifySendPreconditions(agent, client, pipelineConfig, logger) {
12
+ // 1. DID resolution
13
+ if (pipelineConfig.verifyIdentity) {
14
+ logger?.debug("Verifying DID identity", { did: agent.did });
15
+ try {
16
+ await client.resolveDID(agent.did);
17
+ logger?.debug("DID verified", { did: agent.did });
18
+ }
19
+ catch (err) {
20
+ logger?.warn("DID resolution failed", {
21
+ did: agent.did,
22
+ error: String(err),
23
+ });
24
+ throw new DIDResolutionError(`Failed to resolve DID: ${agent.did}`, {
25
+ cause: err instanceof Error ? err : new Error(String(err)),
26
+ });
27
+ }
28
+ }
29
+ // 2. Liveness check
30
+ if (pipelineConfig.livenessCheckBeforeSend) {
31
+ logger?.debug("Checking liveness", { did: agent.did });
32
+ try {
33
+ const isLive = await client.checkLiveness(agent.did);
34
+ if (!isLive) {
35
+ logger?.warn("Agent not live", { did: agent.did });
36
+ throw new AgentNotLiveError(`Agent ${agent.did} is not live`);
37
+ }
38
+ logger?.debug("Liveness confirmed", { did: agent.did });
39
+ }
40
+ catch (err) {
41
+ if (err instanceof AgentNotLiveError)
42
+ throw err;
43
+ logger?.warn("Liveness check failed", {
44
+ did: agent.did,
45
+ error: String(err),
46
+ });
47
+ throw new AgentNotLiveError(`Liveness check failed for agent ${agent.did}`, { cause: err instanceof Error ? err : new Error(String(err)) });
48
+ }
49
+ }
50
+ else if (pipelineConfig.requireLive && !agent.isLive) {
51
+ logger?.warn("Agent not live (cached)", { did: agent.did });
52
+ throw new AgentNotLiveError(`Agent ${agent.did} is not live (cached status)`);
53
+ }
54
+ // 3. Trust score gate
55
+ if (pipelineConfig.minTrustScore > 0 &&
56
+ (agent.trustScore === null ||
57
+ agent.trustScore < pipelineConfig.minTrustScore)) {
58
+ logger?.warn("Trust score below threshold", {
59
+ did: agent.did,
60
+ score: agent.trustScore,
61
+ threshold: pipelineConfig.minTrustScore,
62
+ });
63
+ throw new TrustScoreBelowThresholdError(agent.trustScore, pipelineConfig.minTrustScore);
64
+ }
65
+ logger?.info("Trust pipeline passed", {
66
+ did: agent.did,
67
+ trustScore: agent.trustScore,
68
+ isLive: agent.isLive,
69
+ });
70
+ return buildTrustInfo(agent);
71
+ }
72
+ //# sourceMappingURL=trust-pipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trust-pipeline.js","sourceRoot":"","sources":["../src/trust-pipeline.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AASrB,MAAM,UAAU,mBAAmB,CACjC,MAAyB;IAEzB,OAAO;QACL,cAAc,EAAE,MAAM,CAAC,cAAc,IAAI,IAAI;QAC7C,uBAAuB,EAAE,MAAM,CAAC,uBAAuB,IAAI,KAAK;QAChE,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,CAAC;QACxC,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,IAAI;KACxC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAY,EACZ,MAAsB,EACtB,cAAmC,EACnC,MAAuB;IAEvB,oBAAoB;IACpB,IAAI,cAAc,CAAC,cAAc,EAAE,CAAC;QAClC,MAAM,EAAE,KAAK,CAAC,wBAAwB,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnC,MAAM,EAAE,KAAK,CAAC,cAAc,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;QACpD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,EAAE,IAAI,CAAC,uBAAuB,EAAE;gBACpC,GAAG,EAAE,KAAK,CAAC,GAAG;gBACd,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC;aACnB,CAAC,CAAC;YACH,MAAM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AG,CAAC,CAAC,EAAE,CAC/D,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,IAAI,cAAc,CAAC,WAAW,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACvD,MAAM,EAAE,IAAI,CAAC,yBAAyB,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;QAC5D,MAAM,IAAI,iBAAiB,CACzB,SAAS,KAAK,CAAC,GAAG,8BAA8B,CACjD,CAAC;IACJ,CAAC;IAED,sBAAsB;IACtB,IACE,cAAc,CAAC,aAAa,GAAG,CAAC;QAChC,CAAC,KAAK,CAAC,UAAU,KAAK,IAAI;YACxB,KAAK,CAAC,UAAU,GAAG,cAAc,CAAC,aAAa,CAAC,EAClD,CAAC;QACD,MAAM,EAAE,IAAI,CAAC,6BAA6B,EAAE;YAC1C,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,KAAK,EAAE,KAAK,CAAC,UAAU;YACvB,SAAS,EAAE,cAAc,CAAC,aAAa;SACxC,CAAC,CAAC;QACH,MAAM,IAAI,6BAA6B,CACrC,KAAK,CAAC,UAAU,EAChB,cAAc,CAAC,aAAa,CAC7B,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,IAAI,CAAC,uBAAuB,EAAE;QACpC,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { Agent } from "@a2aletheia/types";
2
+ import type { AgentCard } from "@a2a-js/sdk";
3
+ import { A2AClient } from "@a2a-js/sdk/client";
4
+ import type { TrustInfo, TrustedResponse, TrustedStreamEvent, TrustedTaskResponse, MessageInput, SendOptions, ContextStore } from "./types.js";
5
+ export declare class TrustedAgent {
6
+ readonly did: string | null;
7
+ readonly agent: Agent | null;
8
+ readonly agentCard: AgentCard;
9
+ readonly trustInfo: TrustInfo;
10
+ /** @internal */
11
+ readonly _a2aClient: A2AClient;
12
+ /**
13
+ * Tracked conversation state — populated after the first send/stream.
14
+ * Subsequent calls reuse these to continue the same conversation.
15
+ */
16
+ private _contextId;
17
+ private _lastTaskId;
18
+ /** Optional persistent store + key for surviving cold-starts. */
19
+ private readonly _contextStore;
20
+ private readonly _storeKey;
21
+ constructor(opts: {
22
+ a2aClient: A2AClient;
23
+ agentCard: AgentCard;
24
+ agent: Agent | null;
25
+ trustInfo: TrustInfo;
26
+ contextStore?: ContextStore;
27
+ storeKey?: string;
28
+ });
29
+ /**
30
+ * Restore conversation context from the persistent store.
31
+ * Called by `AletheiaA2A` after constructing a new `TrustedAgent`.
32
+ */
33
+ restoreContext(): Promise<void>;
34
+ get supportsStreaming(): boolean;
35
+ /** The contextId from the most recent exchange, if any. */
36
+ get contextId(): string | undefined;
37
+ /** The taskId from the most recent exchange, if any. */
38
+ get lastTaskId(): string | undefined;
39
+ send(input: string | MessageInput, options?: SendOptions): Promise<TrustedResponse>;
40
+ stream(input: string | MessageInput, options?: SendOptions): AsyncGenerator<TrustedStreamEvent>;
41
+ getTask(taskId: string): Promise<TrustedTaskResponse>;
42
+ cancelTask(taskId: string): Promise<TrustedTaskResponse>;
43
+ resubscribeTask(taskId: string): AsyncGenerator<TrustedStreamEvent>;
44
+ refreshCard(): Promise<AgentCard>;
45
+ /**
46
+ * Reset conversation state. Next send() starts a fresh conversation.
47
+ */
48
+ resetContext(): void;
49
+ /** Fire-and-forget persist of current context to the store. */
50
+ private _persistContext;
51
+ }
52
+ //# sourceMappingURL=trusted-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trusted-agent.d.ts","sourceRoot":"","sources":["../src/trusted-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAA8B,MAA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