@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
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { buildMessageSendParams } from "./types.js";
|
|
2
|
+
import { A2AProtocolError } from "./errors.js";
|
|
3
|
+
export class TrustedAgent {
|
|
4
|
+
did;
|
|
5
|
+
agent;
|
|
6
|
+
agentCard;
|
|
7
|
+
trustInfo;
|
|
8
|
+
/** @internal */
|
|
9
|
+
_a2aClient;
|
|
10
|
+
/**
|
|
11
|
+
* Tracked conversation state — populated after the first send/stream.
|
|
12
|
+
* Subsequent calls reuse these to continue the same conversation.
|
|
13
|
+
*/
|
|
14
|
+
_contextId;
|
|
15
|
+
_lastTaskId;
|
|
16
|
+
/** Optional persistent store + key for surviving cold-starts. */
|
|
17
|
+
_contextStore;
|
|
18
|
+
_storeKey;
|
|
19
|
+
constructor(opts) {
|
|
20
|
+
this._a2aClient = opts.a2aClient;
|
|
21
|
+
this.agentCard = opts.agentCard;
|
|
22
|
+
this.agent = opts.agent;
|
|
23
|
+
this.did = opts.agent?.did ?? null;
|
|
24
|
+
this.trustInfo = opts.trustInfo;
|
|
25
|
+
this._contextStore = opts.contextStore;
|
|
26
|
+
this._storeKey = opts.storeKey;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Restore conversation context from the persistent store.
|
|
30
|
+
* Called by `AletheiaA2A` after constructing a new `TrustedAgent`.
|
|
31
|
+
*/
|
|
32
|
+
async restoreContext() {
|
|
33
|
+
if (!this._contextStore || !this._storeKey)
|
|
34
|
+
return;
|
|
35
|
+
const stored = await this._contextStore.get(this._storeKey);
|
|
36
|
+
if (stored) {
|
|
37
|
+
this._contextId = stored.contextId;
|
|
38
|
+
this._lastTaskId = stored.taskId;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
get supportsStreaming() {
|
|
42
|
+
return this.agentCard.capabilities?.streaming === true;
|
|
43
|
+
}
|
|
44
|
+
/** The contextId from the most recent exchange, if any. */
|
|
45
|
+
get contextId() {
|
|
46
|
+
return this._contextId;
|
|
47
|
+
}
|
|
48
|
+
/** The taskId from the most recent exchange, if any. */
|
|
49
|
+
get lastTaskId() {
|
|
50
|
+
return this._lastTaskId;
|
|
51
|
+
}
|
|
52
|
+
async send(input, options) {
|
|
53
|
+
const params = buildMessageSendParams(input, {
|
|
54
|
+
...options,
|
|
55
|
+
// Carry forward conversation context unless caller explicitly overrides
|
|
56
|
+
contextId: options?.contextId ?? this._contextId,
|
|
57
|
+
taskId: options?.taskId ?? this._lastTaskId,
|
|
58
|
+
blocking: options?.blocking ?? true,
|
|
59
|
+
});
|
|
60
|
+
const start = Date.now();
|
|
61
|
+
const response = await this._a2aClient.sendMessage(params);
|
|
62
|
+
const duration = Date.now() - start;
|
|
63
|
+
if (this._a2aClient.isErrorResponse(response)) {
|
|
64
|
+
const err = response.error;
|
|
65
|
+
throw new A2AProtocolError(err.message ?? "A2A protocol error", {
|
|
66
|
+
rpcCode: err.code,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const result = response.result;
|
|
70
|
+
// Track conversation state for follow-up messages.
|
|
71
|
+
// A2A responses carry taskId + contextId on both "task" and "message" kinds.
|
|
72
|
+
if (result.kind === "task") {
|
|
73
|
+
this._lastTaskId = result.id;
|
|
74
|
+
this._contextId = result.contextId;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
if ("taskId" in result && typeof result.taskId === "string") {
|
|
78
|
+
this._lastTaskId = result.taskId;
|
|
79
|
+
}
|
|
80
|
+
if ("contextId" in result && typeof result.contextId === "string") {
|
|
81
|
+
this._contextId = result.contextId;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
this._persistContext();
|
|
85
|
+
return {
|
|
86
|
+
response: result,
|
|
87
|
+
trustInfo: this.trustInfo,
|
|
88
|
+
agentDid: this.did,
|
|
89
|
+
agentName: this.agent?.name ?? this.agentCard.name,
|
|
90
|
+
duration,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
async *stream(input, options) {
|
|
94
|
+
const params = buildMessageSendParams(input, {
|
|
95
|
+
...options,
|
|
96
|
+
contextId: options?.contextId ?? this._contextId,
|
|
97
|
+
taskId: options?.taskId ?? this._lastTaskId,
|
|
98
|
+
blocking: options?.blocking ?? false,
|
|
99
|
+
});
|
|
100
|
+
const eventStream = this._a2aClient.sendMessageStream(params);
|
|
101
|
+
for await (const event of eventStream) {
|
|
102
|
+
// Track conversation state from streamed events
|
|
103
|
+
if (event.kind === "task") {
|
|
104
|
+
this._lastTaskId = event.id;
|
|
105
|
+
this._contextId = event.contextId;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if ("taskId" in event &&
|
|
109
|
+
typeof event.taskId === "string" &&
|
|
110
|
+
!this._lastTaskId) {
|
|
111
|
+
this._lastTaskId = event.taskId;
|
|
112
|
+
}
|
|
113
|
+
if ("contextId" in event &&
|
|
114
|
+
typeof event.contextId === "string" &&
|
|
115
|
+
!this._contextId) {
|
|
116
|
+
this._contextId = event.contextId;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
this._persistContext();
|
|
120
|
+
yield {
|
|
121
|
+
event,
|
|
122
|
+
kind: event.kind,
|
|
123
|
+
agentDid: this.did,
|
|
124
|
+
trustInfo: this.trustInfo,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async getTask(taskId) {
|
|
129
|
+
const response = await this._a2aClient.getTask({ id: taskId });
|
|
130
|
+
if (this._a2aClient.isErrorResponse(response)) {
|
|
131
|
+
const err = response.error;
|
|
132
|
+
throw new A2AProtocolError(err.message ?? "Failed to get task", {
|
|
133
|
+
rpcCode: err.code,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
response: response.result,
|
|
138
|
+
trustInfo: this.trustInfo,
|
|
139
|
+
agentDid: this.did,
|
|
140
|
+
agentName: this.agent?.name ?? this.agentCard.name,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
async cancelTask(taskId) {
|
|
144
|
+
const response = await this._a2aClient.cancelTask({ id: taskId });
|
|
145
|
+
if (this._a2aClient.isErrorResponse(response)) {
|
|
146
|
+
const err = response.error;
|
|
147
|
+
throw new A2AProtocolError(err.message ?? "Failed to cancel task", {
|
|
148
|
+
rpcCode: err.code,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
response: response.result,
|
|
153
|
+
trustInfo: this.trustInfo,
|
|
154
|
+
agentDid: this.did,
|
|
155
|
+
agentName: this.agent?.name ?? this.agentCard.name,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
async *resubscribeTask(taskId) {
|
|
159
|
+
const eventStream = this._a2aClient.resubscribeTask({ id: taskId });
|
|
160
|
+
for await (const event of eventStream) {
|
|
161
|
+
yield {
|
|
162
|
+
event,
|
|
163
|
+
kind: event.kind,
|
|
164
|
+
agentDid: this.did,
|
|
165
|
+
trustInfo: this.trustInfo,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async refreshCard() {
|
|
170
|
+
const card = await this._a2aClient.getAgentCard();
|
|
171
|
+
this.agentCard = card;
|
|
172
|
+
return card;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Reset conversation state. Next send() starts a fresh conversation.
|
|
176
|
+
*/
|
|
177
|
+
resetContext() {
|
|
178
|
+
this._contextId = undefined;
|
|
179
|
+
this._lastTaskId = undefined;
|
|
180
|
+
if (this._contextStore && this._storeKey) {
|
|
181
|
+
this._contextStore.delete(this._storeKey).catch(() => { });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/** Fire-and-forget persist of current context to the store. */
|
|
185
|
+
_persistContext() {
|
|
186
|
+
if (!this._contextStore || !this._storeKey)
|
|
187
|
+
return;
|
|
188
|
+
if (!this._contextId && !this._lastTaskId)
|
|
189
|
+
return;
|
|
190
|
+
this._contextStore
|
|
191
|
+
.set(this._storeKey, {
|
|
192
|
+
contextId: this._contextId,
|
|
193
|
+
taskId: this._lastTaskId,
|
|
194
|
+
})
|
|
195
|
+
.catch(() => { });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=trusted-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trusted-agent.js","sourceRoot":"","sources":["../src/trusted-agent.ts"],"names":[],"mappings":"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ACV,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC7B,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACzC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;IAED,+DAA+D;IACvD,eAAe;QACrB,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,OAAO;QACnD,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,OAAO;QAClD,IAAI,CAAC,aAAa;aACf,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,SAAS,EAAE,IAAI,CAAC,UAAU;YAC1B,MAAM,EAAE,IAAI,CAAC,WAAW;SACzB,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACrB,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { Agent, AletheiaLogger, AletheiaLogLevel } from "@a2aletheia/types";
|
|
2
|
+
import type { Message, Task, TaskStatusUpdateEvent, TaskArtifactUpdateEvent, Part } from "@a2a-js/sdk";
|
|
3
|
+
export type { AgentCard, Message, Task, TaskState, TaskStatus, Part, TextPart, FilePart, DataPart, Artifact, TaskStatusUpdateEvent, TaskArtifactUpdateEvent, MessageSendParams, MessageSendConfiguration, } from "@a2a-js/sdk";
|
|
4
|
+
export type { A2AClient } from "@a2a-js/sdk/client";
|
|
5
|
+
export type A2AStreamEventData = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
|
|
6
|
+
/** Stored conversation state for a single agent connection. */
|
|
7
|
+
export interface StoredContext {
|
|
8
|
+
contextId?: string;
|
|
9
|
+
taskId?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Pluggable store for persisting A2A conversation context across process
|
|
13
|
+
* restarts / serverless cold-starts. Implement this with Redis, a database,
|
|
14
|
+
* or any async key-value store.
|
|
15
|
+
*/
|
|
16
|
+
export interface ContextStore {
|
|
17
|
+
get(key: string): Promise<StoredContext | null>;
|
|
18
|
+
set(key: string, data: StoredContext): Promise<void>;
|
|
19
|
+
delete(key: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Minimal subset of a Redis client that `redisContextStore` needs.
|
|
23
|
+
* Compatible with ioredis, node-redis v4, and most Redis client libraries.
|
|
24
|
+
*/
|
|
25
|
+
export interface RedisLike {
|
|
26
|
+
get(key: string): Promise<string | null>;
|
|
27
|
+
set(key: string, value: string, ...args: unknown[]): Promise<unknown>;
|
|
28
|
+
del(...args: unknown[]): Promise<unknown>;
|
|
29
|
+
}
|
|
30
|
+
export interface AletheiaA2AConfig {
|
|
31
|
+
registryUrl: string;
|
|
32
|
+
agentSelector?: AgentSelector;
|
|
33
|
+
minTrustScore?: number;
|
|
34
|
+
requireLive?: boolean;
|
|
35
|
+
livenessCheckBeforeSend?: boolean;
|
|
36
|
+
verifyIdentity?: boolean;
|
|
37
|
+
authToken?: string;
|
|
38
|
+
logger?: AletheiaLogger;
|
|
39
|
+
logLevel?: AletheiaLogLevel;
|
|
40
|
+
/** Optional store for persisting conversation context (contextId/taskId). */
|
|
41
|
+
contextStore?: ContextStore;
|
|
42
|
+
}
|
|
43
|
+
export interface AgentSelector {
|
|
44
|
+
select(agents: Agent[]): Agent;
|
|
45
|
+
}
|
|
46
|
+
export interface MessageInput {
|
|
47
|
+
text?: string;
|
|
48
|
+
data?: Record<string, unknown>;
|
|
49
|
+
parts?: Part[];
|
|
50
|
+
contextId?: string;
|
|
51
|
+
taskId?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface SendOptions {
|
|
54
|
+
acceptedOutputModes?: string[];
|
|
55
|
+
blocking?: boolean;
|
|
56
|
+
contextId?: string;
|
|
57
|
+
taskId?: string;
|
|
58
|
+
timeoutMs?: number;
|
|
59
|
+
}
|
|
60
|
+
export interface TrustInfo {
|
|
61
|
+
didVerified: boolean;
|
|
62
|
+
isLive: boolean;
|
|
63
|
+
trustScore: number | null;
|
|
64
|
+
isBattleTested: boolean;
|
|
65
|
+
responseVerified: boolean | null;
|
|
66
|
+
verifiedAt: Date;
|
|
67
|
+
}
|
|
68
|
+
export interface TrustedResponse {
|
|
69
|
+
response: Task | Message;
|
|
70
|
+
trustInfo: TrustInfo;
|
|
71
|
+
agentDid: string | null;
|
|
72
|
+
agentName: string;
|
|
73
|
+
duration: number;
|
|
74
|
+
}
|
|
75
|
+
export interface TrustedStreamEvent {
|
|
76
|
+
event: A2AStreamEventData;
|
|
77
|
+
kind: "message" | "task" | "status-update" | "artifact-update";
|
|
78
|
+
agentDid: string | null;
|
|
79
|
+
trustInfo: TrustInfo;
|
|
80
|
+
}
|
|
81
|
+
export interface TrustedTaskResponse {
|
|
82
|
+
response: Task;
|
|
83
|
+
trustInfo: TrustInfo;
|
|
84
|
+
agentDid: string | null;
|
|
85
|
+
agentName: string;
|
|
86
|
+
}
|
|
87
|
+
export declare function buildTrustInfo(agent: Agent | null): TrustInfo;
|
|
88
|
+
export declare function buildMessageParts(input: string | MessageInput): {
|
|
89
|
+
parts: Part[];
|
|
90
|
+
contextId?: string;
|
|
91
|
+
taskId?: string;
|
|
92
|
+
};
|
|
93
|
+
export declare function buildMessageSendParams(input: string | MessageInput, options?: SendOptions): {
|
|
94
|
+
message: {
|
|
95
|
+
kind: "message";
|
|
96
|
+
role: "user";
|
|
97
|
+
messageId: `${string}-${string}-${string}-${string}-${string}`;
|
|
98
|
+
parts: Part[];
|
|
99
|
+
contextId: string | undefined;
|
|
100
|
+
taskId: string | undefined;
|
|
101
|
+
};
|
|
102
|
+
configuration: {
|
|
103
|
+
acceptedOutputModes: string[];
|
|
104
|
+
blocking: boolean | undefined;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,cAAc,EACd,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAEV,OAAO,EACP,IAAI,EACJ,qBAAqB,EACrB,uBAAuB,EACvB,IAAI,EACL,MAAM,aAAa,CAAC;AAMrB,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,GACzB,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD,MAAM,MAAM,kBAAkB,GAC1B,OAAO,GACP,IAAI,GACJ,qBAAqB,GACrB,uBAAuB,CAAC;AAM5B,+DAA+D;AAC/D,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;IAChD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CA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------------------------------------
|
|
2
|
+
// Helpers (internal)
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
export function buildTrustInfo(agent) {
|
|
5
|
+
if (!agent) {
|
|
6
|
+
return {
|
|
7
|
+
didVerified: false,
|
|
8
|
+
isLive: false,
|
|
9
|
+
trustScore: null,
|
|
10
|
+
isBattleTested: false,
|
|
11
|
+
responseVerified: null,
|
|
12
|
+
verifiedAt: new Date(),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
didVerified: true,
|
|
17
|
+
isLive: agent.isLive,
|
|
18
|
+
trustScore: agent.trustScore,
|
|
19
|
+
isBattleTested: agent.isBattleTested,
|
|
20
|
+
responseVerified: null, // Phase 2+
|
|
21
|
+
verifiedAt: new Date(),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function buildMessageParts(input) {
|
|
25
|
+
if (typeof input === "string") {
|
|
26
|
+
return {
|
|
27
|
+
parts: [{ kind: "text", text: input }],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const parts = [];
|
|
31
|
+
if (input.text) {
|
|
32
|
+
parts.push({ kind: "text", text: input.text });
|
|
33
|
+
}
|
|
34
|
+
if (input.data) {
|
|
35
|
+
parts.push({ kind: "data", data: input.data });
|
|
36
|
+
}
|
|
37
|
+
if (input.parts) {
|
|
38
|
+
parts.push(...input.parts);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
parts,
|
|
42
|
+
contextId: input.contextId,
|
|
43
|
+
taskId: input.taskId,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function buildMessageSendParams(input, options) {
|
|
47
|
+
const { parts, contextId, taskId } = buildMessageParts(input);
|
|
48
|
+
return {
|
|
49
|
+
message: {
|
|
50
|
+
kind: "message",
|
|
51
|
+
role: "user",
|
|
52
|
+
messageId: crypto.randomUUID(),
|
|
53
|
+
parts,
|
|
54
|
+
contextId: options?.contextId ?? contextId,
|
|
55
|
+
taskId: options?.taskId ?? taskId,
|
|
56
|
+
},
|
|
57
|
+
configuration: {
|
|
58
|
+
acceptedOutputModes: options?.acceptedOutputModes ?? [
|
|
59
|
+
"text/plain",
|
|
60
|
+
"application/json",
|
|
61
|
+
],
|
|
62
|
+
blocking: options?.blocking,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAgJA,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E,MAAM,UAAU,cAAc,CAAC,KAAmB;IAChD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO;YACL,WAAW,EAAE,KAAK;YAClB,MAAM,EAAE,KAAK;YACb,UAAU,EAAE,IAAI;YAChB,cAAc,EAAE,KAAK;YACrB,gBAAgB,EAAE,IAAI;YACtB,UAAU,EAAE,IAAI,IAAI,EAAE;SACvB,CAAC;IACJ,CAAC;IACD,OAAO;QACL,WAAW,EAAE,IAAI;QACjB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,gBAAgB,EAAE,IAAI,EAAE,WAAW;QACnC,UAAU,EAAE,IAAI,IAAI,EAAE;KACvB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAA4B;IAK5D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO;YACL,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;SAChD,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAW,EAAE,CAAC;IAEzB,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO;QACL,KAAK;QACL,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,KAA4B,EAC5B,OAAqB;IAErB,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAE9D,OAAO;QACL,OAAO,EAAE;YACP,IAAI,EAAE,SAAkB;YACxB,IAAI,EAAE,MAAe;YACrB,SAAS,EAAE,MAAM,CAAC,UAAU,EAAE;YAC9B,KAAK;YACL,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,SAAS;YAC1C,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,MAAM;SAClC;QACD,aAAa,EAAE;YACb,mBAAmB,EAAE,OAAO,EAAE,mBAAmB,IAAI;gBACnD,YAAY;gBACZ,kBAAkB;aACnB;YACD,QAAQ,EAAE,OAAO,EAAE,QAAQ;SAC5B;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@a2aletheia/a2a",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Aletheia trust-layer wrapper for the A2A (Agent-to-Agent) protocol",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"a2a",
|
|
20
|
+
"agent",
|
|
21
|
+
"trust",
|
|
22
|
+
"aletheia",
|
|
23
|
+
"multi-agent",
|
|
24
|
+
"ai-agents",
|
|
25
|
+
"agent-to-agent"
|
|
26
|
+
],
|
|
27
|
+
"author": "",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@a2a-js/sdk": "^0.2.5",
|
|
31
|
+
"@a2aletheia/sdk": "0.2.0",
|
|
32
|
+
"@a2aletheia/types": "0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"rimraf": "^6.0.1",
|
|
36
|
+
"@types/node": "^20",
|
|
37
|
+
"typescript": "^5.9.2",
|
|
38
|
+
"@a2aletheia/base-typescript-config": "0.0.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc",
|
|
42
|
+
"check-types": "tsc --noEmit",
|
|
43
|
+
"lint": "eslint .",
|
|
44
|
+
"clean": "rimraf dist"
|
|
45
|
+
}
|
|
46
|
+
}
|