@agnt-id/a2a 0.1.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,51 @@
1
+ import type { AgentCard, ToAgentCardOptions } from "./types.js";
2
+ /**
3
+ * Minimal shape of an .agnt record — matches @agnt-id/resolve AgntRecord
4
+ * without requiring the dependency at compile time.
5
+ */
6
+ export type AgntRecordLike = {
7
+ wallets?: Record<string, string>;
8
+ agentId?: string;
9
+ a2a?: string;
10
+ mcp?: string;
11
+ texts?: Record<string, string>;
12
+ identity?: string;
13
+ wallet?: string;
14
+ did?: string;
15
+ skills?: string[];
16
+ domains?: string[];
17
+ a2aVersion?: string;
18
+ profileURI?: string;
19
+ x402Support?: boolean;
20
+ };
21
+ /**
22
+ * Minimal shape of a resolved .agnt name.
23
+ */
24
+ export type AgntNameLike = {
25
+ name: string;
26
+ owner: string;
27
+ records: AgntRecordLike;
28
+ };
29
+ /**
30
+ * Convert a resolved .agnt name to a Google A2A Agent Card.
31
+ *
32
+ * @param agnt - Resolved .agnt name data
33
+ * @param options - Optional overrides and additions
34
+ * @returns A well-formed A2A AgentCard
35
+ */
36
+ export declare function toAgentCard(agnt: AgntNameLike, options?: ToAgentCardOptions): AgentCard;
37
+ /**
38
+ * Serialize an A2A Agent Card to JSON (pretty-printed).
39
+ */
40
+ export declare function agentCardToJSON(card: AgentCard): string;
41
+ /**
42
+ * Resolve a .agnt name and return its A2A Agent Card.
43
+ * Requires @agnt-id/resolve to be installed.
44
+ *
45
+ * @param name - .agnt name or label (e.g. "alice" or "alice.agnt")
46
+ * @param options - Agent card options + optional gateway/chainId
47
+ */
48
+ export declare function fromAgnt(name: string, options?: ToAgentCardOptions & {
49
+ gateway?: string;
50
+ chainId?: string;
51
+ }): Promise<AgentCard | null>;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Convert a resolved .agnt name to a Google A2A Agent Card.
3
+ *
4
+ * @param agnt - Resolved .agnt name data
5
+ * @param options - Optional overrides and additions
6
+ * @returns A well-formed A2A AgentCard
7
+ */
8
+ export function toAgentCard(agnt, options = {}) {
9
+ const rec = agnt.records;
10
+ const description = rec.texts?.description ?? `AI agent registered as ${agnt.name}`;
11
+ const avatar = rec.texts?.avatar;
12
+ // Derive skills from OASF slugs
13
+ const skills = (rec.skills ?? []).map((slug) => ({
14
+ id: slug,
15
+ name: slug.replaceAll("_", " ").replaceAll("/", " — "),
16
+ description: slug,
17
+ tags: rec.domains ?? [],
18
+ }));
19
+ if (options.extraSkills) {
20
+ skills.push(...options.extraSkills);
21
+ }
22
+ // If no skills at all, add a generic one based on name
23
+ if (skills.length === 0) {
24
+ skills.push({
25
+ id: "default",
26
+ name: agnt.name,
27
+ description,
28
+ tags: rec.domains ?? [],
29
+ });
30
+ }
31
+ // Build the interface list — A2A endpoint is required
32
+ const a2aUrl = rec.a2a;
33
+ const binding = options.protocolBinding ?? "JSONRPC";
34
+ const protocolVersion = options.protocolVersion ?? "1.0";
35
+ const card = {
36
+ name: agnt.name,
37
+ description,
38
+ version: options.version ?? "1.0.0",
39
+ supportedInterfaces: a2aUrl
40
+ ? [{ url: a2aUrl, protocolBinding: binding, protocolVersion }]
41
+ : [],
42
+ skills,
43
+ defaultInputModes: options.defaultInputModes ?? ["text/plain"],
44
+ defaultOutputModes: options.defaultOutputModes ?? ["text/plain"],
45
+ };
46
+ if (avatar)
47
+ card.iconUrl = avatar;
48
+ if (rec.profileURI)
49
+ card.documentationUrl = rec.profileURI;
50
+ if (options.provider)
51
+ card.provider = options.provider;
52
+ if (options.capabilities)
53
+ card.capabilities = options.capabilities;
54
+ if (options.securitySchemes)
55
+ card.securitySchemes = options.securitySchemes;
56
+ if (options.securityRequirements)
57
+ card.securityRequirements = options.securityRequirements;
58
+ return card;
59
+ }
60
+ /**
61
+ * Serialize an A2A Agent Card to JSON (pretty-printed).
62
+ */
63
+ export function agentCardToJSON(card) {
64
+ return JSON.stringify(card, null, 2);
65
+ }
66
+ /**
67
+ * Resolve a .agnt name and return its A2A Agent Card.
68
+ * Requires @agnt-id/resolve to be installed.
69
+ *
70
+ * @param name - .agnt name or label (e.g. "alice" or "alice.agnt")
71
+ * @param options - Agent card options + optional gateway/chainId
72
+ */
73
+ export async function fromAgnt(name, options = {}) {
74
+ // Dynamic import so @agnt-id/resolve stays an optional peer dep
75
+ const { AgntClient } = await import("@agnt-id/resolve");
76
+ const client = new AgntClient({
77
+ gateway: options.gateway,
78
+ chainId: options.chainId,
79
+ });
80
+ const result = await client.resolve(name);
81
+ if (!result)
82
+ return null;
83
+ return toAgentCard(result, options);
84
+ }
@@ -0,0 +1,3 @@
1
+ export type { AgntNameLike, AgntRecordLike } from "./convert.js";
2
+ export { agentCardToJSON, fromAgnt, toAgentCard } from "./convert.js";
3
+ export type { AgentCapabilities, AgentCard, AgentCardSignature, AgentExtension, AgentInterface, AgentProvider, AgentSkill, APIKeySecurityScheme, HTTPAuthSecurityScheme, OAuth2SecurityScheme, OAuthFlows, OpenIdConnectSecurityScheme, SecurityRequirement, SecurityScheme, ToAgentCardOptions, } from "./types.js";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { agentCardToJSON, fromAgnt, toAgentCard } from "./convert.js";
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Google A2A protocol types — Agent Card and related structures.
3
+ * Based on the A2A specification v1.0 / v0.3.
4
+ * @see https://a2a-protocol.org/latest/specification/
5
+ */
6
+ /** Top-level A2A Agent Card. */
7
+ export type AgentCard = {
8
+ /** Human-readable agent name. */
9
+ name: string;
10
+ /** Description of what the agent does. */
11
+ description: string;
12
+ /** Semantic version string. */
13
+ version: string;
14
+ /** URL to an icon image. */
15
+ iconUrl?: string;
16
+ /** URL to additional documentation. */
17
+ documentationUrl?: string;
18
+ /** Service provider information. */
19
+ provider?: AgentProvider;
20
+ /** Protocol bindings ordered by preference. */
21
+ supportedInterfaces: AgentInterface[];
22
+ /** Feature flags. */
23
+ capabilities?: AgentCapabilities;
24
+ /** Agent abilities / tools. */
25
+ skills: AgentSkill[];
26
+ /** Accepted input media types (default: ["text/plain"]). */
27
+ defaultInputModes?: string[];
28
+ /** Produced output media types (default: ["text/plain"]). */
29
+ defaultOutputModes?: string[];
30
+ /** Named security scheme definitions. */
31
+ securitySchemes?: Record<string, SecurityScheme>;
32
+ /** Required security — references keys in securitySchemes. */
33
+ securityRequirements?: SecurityRequirement[];
34
+ /** JWS signatures for card integrity. */
35
+ signatures?: AgentCardSignature[];
36
+ };
37
+ export type AgentProvider = {
38
+ url: string;
39
+ organization: string;
40
+ };
41
+ export type AgentInterface = {
42
+ /** Absolute HTTPS URL. */
43
+ url: string;
44
+ /** "JSONRPC" | "GRPC" | "HTTP+JSON" */
45
+ protocolBinding: string;
46
+ /** Optional tenant identifier. */
47
+ tenant?: string;
48
+ /** Protocol version — "0.3" | "1.0". */
49
+ protocolVersion?: string;
50
+ };
51
+ export type AgentCapabilities = {
52
+ streaming?: boolean;
53
+ pushNotifications?: boolean;
54
+ extensions?: AgentExtension[];
55
+ extendedAgentCard?: boolean;
56
+ };
57
+ export type AgentExtension = {
58
+ uri: string;
59
+ description?: string;
60
+ required?: boolean;
61
+ };
62
+ export type AgentSkill = {
63
+ id: string;
64
+ name: string;
65
+ description: string;
66
+ tags?: string[];
67
+ examples?: string[];
68
+ inputModes?: string[];
69
+ outputModes?: string[];
70
+ };
71
+ export type SecurityScheme = APIKeySecurityScheme | HTTPAuthSecurityScheme | OAuth2SecurityScheme | OpenIdConnectSecurityScheme;
72
+ export type APIKeySecurityScheme = {
73
+ type: "apiKey";
74
+ description?: string;
75
+ location: "query" | "header" | "cookie";
76
+ name: string;
77
+ };
78
+ export type HTTPAuthSecurityScheme = {
79
+ type: "http";
80
+ description?: string;
81
+ scheme: string;
82
+ bearerFormat?: string;
83
+ };
84
+ export type OAuth2SecurityScheme = {
85
+ type: "oauth2";
86
+ description?: string;
87
+ flows: OAuthFlows;
88
+ };
89
+ export type OpenIdConnectSecurityScheme = {
90
+ type: "openIdConnect";
91
+ description?: string;
92
+ openIdConnectUrl: string;
93
+ };
94
+ export type OAuthFlows = {
95
+ authorizationCode?: {
96
+ authorizationUrl: string;
97
+ tokenUrl: string;
98
+ refreshUrl?: string;
99
+ scopes: Record<string, string>;
100
+ };
101
+ clientCredentials?: {
102
+ tokenUrl: string;
103
+ refreshUrl?: string;
104
+ scopes: Record<string, string>;
105
+ };
106
+ };
107
+ export type SecurityRequirement = Record<string, string[]>;
108
+ export type AgentCardSignature = {
109
+ /** JWS compact serialisation. */
110
+ value: string;
111
+ /** Key ID or URL. */
112
+ keyId?: string;
113
+ };
114
+ /** Options for converting a .agnt record to an A2A Agent Card. */
115
+ export type ToAgentCardOptions = {
116
+ /** Override the agent version (default: "1.0.0"). */
117
+ version?: string;
118
+ /** Override the A2A protocol binding (default: "JSONRPC"). */
119
+ protocolBinding?: "JSONRPC" | "GRPC" | "HTTP+JSON";
120
+ /** Override the protocol version (default: "1.0"). */
121
+ protocolVersion?: string;
122
+ /** Provider details to include. */
123
+ provider?: AgentProvider;
124
+ /** Extra capabilities to set. */
125
+ capabilities?: AgentCapabilities;
126
+ /** Security schemes to add. */
127
+ securitySchemes?: Record<string, SecurityScheme>;
128
+ /** Security requirements to add. */
129
+ securityRequirements?: SecurityRequirement[];
130
+ /** Extra skills to append beyond those derived from records. */
131
+ extraSkills?: AgentSkill[];
132
+ /** Custom input modes. */
133
+ defaultInputModes?: string[];
134
+ /** Custom output modes. */
135
+ defaultOutputModes?: string[];
136
+ };
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Google A2A protocol types — Agent Card and related structures.
3
+ * Based on the A2A specification v1.0 / v0.3.
4
+ * @see https://a2a-protocol.org/latest/specification/
5
+ */
6
+ export {};
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@agnt-id/a2a",
3
+ "version": "0.1.0",
4
+ "description": "Generate Google A2A Agent Cards from .agnt names",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "prepublishOnly": "tsc"
21
+ },
22
+ "keywords": [
23
+ "agnt",
24
+ "a2a",
25
+ "agent",
26
+ "agent-card",
27
+ "agent-to-agent",
28
+ "google-a2a",
29
+ "naming",
30
+ "resolve"
31
+ ],
32
+ "license": "MIT",
33
+ "peerDependencies": {
34
+ "@agnt-id/resolve": ">=0.1.0"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "@agnt-id/resolve": {
38
+ "optional": true
39
+ }
40
+ },
41
+ "devDependencies": {
42
+ "typescript": "^5.9.3"
43
+ }
44
+ }