@well-known-js/agent-card 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bryan Ledda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # @well-known-js/agent-card
2
+
3
+ Generate and validate Agent2Agent (A2A) Agent Cards for
4
+ `/.well-known/agent-card.json`.
5
+
6
+ The schema follows the A2A Protocol 1.0 Agent Card model, including supported interfaces,
7
+ capabilities, skills, security schemes, security requirements, and optional JWS signatures.
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ pnpm add @well-known-js/agent-card
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import { agentCard } from "@well-known-js/agent-card";
19
+
20
+ agentCard({
21
+ name: "Research Agent",
22
+ description: "Finds and summarizes primary sources.",
23
+ supportedInterfaces: [
24
+ {
25
+ url: "https://agent.example.com/a2a/v1",
26
+ protocolBinding: "HTTP+JSON",
27
+ protocolVersion: "1.0",
28
+ },
29
+ ],
30
+ version: "1.0.0",
31
+ capabilities: { streaming: true },
32
+ defaultInputModes: ["text/plain"],
33
+ defaultOutputModes: ["text/plain", "application/json"],
34
+ skills: [
35
+ {
36
+ id: "research",
37
+ name: "Research",
38
+ description: "Researches a question using primary sources.",
39
+ tags: ["research", "citations"],
40
+ },
41
+ ],
42
+ });
43
+ ```
44
+
45
+ The generated file uses `application/json` at:
46
+
47
+ ```text
48
+ /.well-known/agent-card.json
49
+ ```
50
+
51
+ The schema preserves unknown fields for forward compatibility with future A2A additions.
52
+
53
+ [A2A specification](https://a2a-protocol.org/latest/specification/) ·
54
+ [GitHub](https://github.com/louchebem06/well-known)
@@ -0,0 +1,350 @@
1
+ import { WellKnownProviderInstance, WellKnownProvider } from '@well-known-js/core';
2
+ import { z } from 'zod';
3
+
4
+ declare const agentCardOAuthFlowsSchema: z.ZodObject<{
5
+ authorizationCode: z.ZodOptional<z.ZodObject<{
6
+ authorizationUrl: z.ZodString;
7
+ tokenUrl: z.ZodString;
8
+ refreshUrl: z.ZodOptional<z.ZodString>;
9
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
10
+ pkceRequired: z.ZodOptional<z.ZodBoolean>;
11
+ }, z.core.$loose>>;
12
+ clientCredentials: z.ZodOptional<z.ZodObject<{
13
+ tokenUrl: z.ZodString;
14
+ refreshUrl: z.ZodOptional<z.ZodString>;
15
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
16
+ }, z.core.$loose>>;
17
+ implicit: z.ZodOptional<z.ZodObject<{
18
+ authorizationUrl: z.ZodOptional<z.ZodString>;
19
+ refreshUrl: z.ZodOptional<z.ZodString>;
20
+ scopes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
21
+ }, z.core.$loose>>;
22
+ password: z.ZodOptional<z.ZodObject<{
23
+ tokenUrl: z.ZodOptional<z.ZodString>;
24
+ refreshUrl: z.ZodOptional<z.ZodString>;
25
+ scopes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
26
+ }, z.core.$loose>>;
27
+ deviceCode: z.ZodOptional<z.ZodObject<{
28
+ deviceAuthorizationUrl: z.ZodString;
29
+ tokenUrl: z.ZodString;
30
+ refreshUrl: z.ZodOptional<z.ZodString>;
31
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
32
+ }, z.core.$loose>>;
33
+ }, z.core.$loose>;
34
+ declare const agentCardSecuritySchemeSchema: z.ZodObject<{
35
+ apiKeySecurityScheme: z.ZodOptional<z.ZodObject<{
36
+ description: z.ZodOptional<z.ZodString>;
37
+ location: z.ZodEnum<{
38
+ query: "query";
39
+ header: "header";
40
+ cookie: "cookie";
41
+ }>;
42
+ name: z.ZodString;
43
+ }, z.core.$loose>>;
44
+ httpAuthSecurityScheme: z.ZodOptional<z.ZodObject<{
45
+ description: z.ZodOptional<z.ZodString>;
46
+ scheme: z.ZodString;
47
+ bearerFormat: z.ZodOptional<z.ZodString>;
48
+ }, z.core.$loose>>;
49
+ oauth2SecurityScheme: z.ZodOptional<z.ZodObject<{
50
+ description: z.ZodOptional<z.ZodString>;
51
+ flows: z.ZodObject<{
52
+ authorizationCode: z.ZodOptional<z.ZodObject<{
53
+ authorizationUrl: z.ZodString;
54
+ tokenUrl: z.ZodString;
55
+ refreshUrl: z.ZodOptional<z.ZodString>;
56
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
57
+ pkceRequired: z.ZodOptional<z.ZodBoolean>;
58
+ }, z.core.$loose>>;
59
+ clientCredentials: z.ZodOptional<z.ZodObject<{
60
+ tokenUrl: z.ZodString;
61
+ refreshUrl: z.ZodOptional<z.ZodString>;
62
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
63
+ }, z.core.$loose>>;
64
+ implicit: z.ZodOptional<z.ZodObject<{
65
+ authorizationUrl: z.ZodOptional<z.ZodString>;
66
+ refreshUrl: z.ZodOptional<z.ZodString>;
67
+ scopes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
68
+ }, z.core.$loose>>;
69
+ password: z.ZodOptional<z.ZodObject<{
70
+ tokenUrl: z.ZodOptional<z.ZodString>;
71
+ refreshUrl: z.ZodOptional<z.ZodString>;
72
+ scopes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
73
+ }, z.core.$loose>>;
74
+ deviceCode: z.ZodOptional<z.ZodObject<{
75
+ deviceAuthorizationUrl: z.ZodString;
76
+ tokenUrl: z.ZodString;
77
+ refreshUrl: z.ZodOptional<z.ZodString>;
78
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
79
+ }, z.core.$loose>>;
80
+ }, z.core.$loose>;
81
+ oauth2MetadataUrl: z.ZodOptional<z.ZodString>;
82
+ }, z.core.$loose>>;
83
+ openIdConnectSecurityScheme: z.ZodOptional<z.ZodObject<{
84
+ description: z.ZodOptional<z.ZodString>;
85
+ openIdConnectUrl: z.ZodString;
86
+ }, z.core.$loose>>;
87
+ mtlsSecurityScheme: z.ZodOptional<z.ZodObject<{
88
+ description: z.ZodOptional<z.ZodString>;
89
+ }, z.core.$loose>>;
90
+ }, z.core.$loose>;
91
+ declare const agentCardSchema: z.ZodObject<{
92
+ name: z.ZodString;
93
+ description: z.ZodString;
94
+ supportedInterfaces: z.ZodArray<z.ZodObject<{
95
+ url: z.ZodString;
96
+ protocolBinding: z.ZodString;
97
+ tenant: z.ZodOptional<z.ZodString>;
98
+ protocolVersion: z.ZodString;
99
+ }, z.core.$loose>>;
100
+ provider: z.ZodOptional<z.ZodObject<{
101
+ url: z.ZodString;
102
+ organization: z.ZodString;
103
+ }, z.core.$loose>>;
104
+ version: z.ZodString;
105
+ documentationUrl: z.ZodOptional<z.ZodString>;
106
+ capabilities: z.ZodObject<{
107
+ streaming: z.ZodOptional<z.ZodBoolean>;
108
+ pushNotifications: z.ZodOptional<z.ZodBoolean>;
109
+ extensions: z.ZodOptional<z.ZodArray<z.ZodObject<{
110
+ uri: z.ZodString;
111
+ description: z.ZodOptional<z.ZodString>;
112
+ required: z.ZodOptional<z.ZodBoolean>;
113
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
114
+ }, z.core.$loose>>>;
115
+ extendedAgentCard: z.ZodOptional<z.ZodBoolean>;
116
+ }, z.core.$loose>;
117
+ securitySchemes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
118
+ apiKeySecurityScheme: z.ZodOptional<z.ZodObject<{
119
+ description: z.ZodOptional<z.ZodString>;
120
+ location: z.ZodEnum<{
121
+ query: "query";
122
+ header: "header";
123
+ cookie: "cookie";
124
+ }>;
125
+ name: z.ZodString;
126
+ }, z.core.$loose>>;
127
+ httpAuthSecurityScheme: z.ZodOptional<z.ZodObject<{
128
+ description: z.ZodOptional<z.ZodString>;
129
+ scheme: z.ZodString;
130
+ bearerFormat: z.ZodOptional<z.ZodString>;
131
+ }, z.core.$loose>>;
132
+ oauth2SecurityScheme: z.ZodOptional<z.ZodObject<{
133
+ description: z.ZodOptional<z.ZodString>;
134
+ flows: z.ZodObject<{
135
+ authorizationCode: z.ZodOptional<z.ZodObject<{
136
+ authorizationUrl: z.ZodString;
137
+ tokenUrl: z.ZodString;
138
+ refreshUrl: z.ZodOptional<z.ZodString>;
139
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
140
+ pkceRequired: z.ZodOptional<z.ZodBoolean>;
141
+ }, z.core.$loose>>;
142
+ clientCredentials: z.ZodOptional<z.ZodObject<{
143
+ tokenUrl: z.ZodString;
144
+ refreshUrl: z.ZodOptional<z.ZodString>;
145
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
146
+ }, z.core.$loose>>;
147
+ implicit: z.ZodOptional<z.ZodObject<{
148
+ authorizationUrl: z.ZodOptional<z.ZodString>;
149
+ refreshUrl: z.ZodOptional<z.ZodString>;
150
+ scopes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
151
+ }, z.core.$loose>>;
152
+ password: z.ZodOptional<z.ZodObject<{
153
+ tokenUrl: z.ZodOptional<z.ZodString>;
154
+ refreshUrl: z.ZodOptional<z.ZodString>;
155
+ scopes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
156
+ }, z.core.$loose>>;
157
+ deviceCode: z.ZodOptional<z.ZodObject<{
158
+ deviceAuthorizationUrl: z.ZodString;
159
+ tokenUrl: z.ZodString;
160
+ refreshUrl: z.ZodOptional<z.ZodString>;
161
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
162
+ }, z.core.$loose>>;
163
+ }, z.core.$loose>;
164
+ oauth2MetadataUrl: z.ZodOptional<z.ZodString>;
165
+ }, z.core.$loose>>;
166
+ openIdConnectSecurityScheme: z.ZodOptional<z.ZodObject<{
167
+ description: z.ZodOptional<z.ZodString>;
168
+ openIdConnectUrl: z.ZodString;
169
+ }, z.core.$loose>>;
170
+ mtlsSecurityScheme: z.ZodOptional<z.ZodObject<{
171
+ description: z.ZodOptional<z.ZodString>;
172
+ }, z.core.$loose>>;
173
+ }, z.core.$loose>>>;
174
+ securityRequirements: z.ZodOptional<z.ZodArray<z.ZodObject<{
175
+ schemes: z.ZodRecord<z.ZodString, z.ZodObject<{
176
+ list: z.ZodArray<z.ZodString>;
177
+ }, z.core.$loose>>;
178
+ }, z.core.$loose>>>;
179
+ defaultInputModes: z.ZodArray<z.ZodString>;
180
+ defaultOutputModes: z.ZodArray<z.ZodString>;
181
+ skills: z.ZodArray<z.ZodObject<{
182
+ id: z.ZodString;
183
+ name: z.ZodString;
184
+ description: z.ZodString;
185
+ tags: z.ZodArray<z.ZodString>;
186
+ examples: z.ZodOptional<z.ZodArray<z.ZodString>>;
187
+ inputModes: z.ZodOptional<z.ZodArray<z.ZodString>>;
188
+ outputModes: z.ZodOptional<z.ZodArray<z.ZodString>>;
189
+ securityRequirements: z.ZodOptional<z.ZodArray<z.ZodObject<{
190
+ schemes: z.ZodRecord<z.ZodString, z.ZodObject<{
191
+ list: z.ZodArray<z.ZodString>;
192
+ }, z.core.$loose>>;
193
+ }, z.core.$loose>>>;
194
+ }, z.core.$loose>>;
195
+ signatures: z.ZodOptional<z.ZodArray<z.ZodObject<{
196
+ protected: z.ZodString;
197
+ signature: z.ZodString;
198
+ header: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
199
+ }, z.core.$loose>>>;
200
+ iconUrl: z.ZodOptional<z.ZodString>;
201
+ }, z.core.$loose>;
202
+ type AgentCardInput = z.input<typeof agentCardSchema>;
203
+ type AgentCardOutput = z.output<typeof agentCardSchema>;
204
+ interface AgentCardJsonOptions {
205
+ pretty?: boolean;
206
+ }
207
+ interface GeneratedAgentCard {
208
+ filename: "agent-card.json";
209
+ path: "/.well-known/agent-card.json";
210
+ contentType: "application/json";
211
+ data: AgentCardOutput;
212
+ body: string;
213
+ }
214
+ declare function generateAgentCard(input: unknown): AgentCardOutput;
215
+ declare function safeGenerateAgentCard(input: unknown): z.ZodSafeParseResult<{
216
+ [x: string]: unknown;
217
+ name: string;
218
+ description: string;
219
+ supportedInterfaces: {
220
+ [x: string]: unknown;
221
+ url: string;
222
+ protocolBinding: string;
223
+ protocolVersion: string;
224
+ tenant?: string | undefined;
225
+ }[];
226
+ version: string;
227
+ capabilities: {
228
+ [x: string]: unknown;
229
+ streaming?: boolean | undefined;
230
+ pushNotifications?: boolean | undefined;
231
+ extensions?: {
232
+ [x: string]: unknown;
233
+ uri: string;
234
+ description?: string | undefined;
235
+ required?: boolean | undefined;
236
+ params?: Record<string, unknown> | undefined;
237
+ }[] | undefined;
238
+ extendedAgentCard?: boolean | undefined;
239
+ };
240
+ defaultInputModes: string[];
241
+ defaultOutputModes: string[];
242
+ skills: {
243
+ [x: string]: unknown;
244
+ id: string;
245
+ name: string;
246
+ description: string;
247
+ tags: string[];
248
+ examples?: string[] | undefined;
249
+ inputModes?: string[] | undefined;
250
+ outputModes?: string[] | undefined;
251
+ securityRequirements?: {
252
+ [x: string]: unknown;
253
+ schemes: Record<string, {
254
+ [x: string]: unknown;
255
+ list: string[];
256
+ }>;
257
+ }[] | undefined;
258
+ }[];
259
+ provider?: {
260
+ [x: string]: unknown;
261
+ url: string;
262
+ organization: string;
263
+ } | undefined;
264
+ documentationUrl?: string | undefined;
265
+ securitySchemes?: Record<string, {
266
+ [x: string]: unknown;
267
+ apiKeySecurityScheme?: {
268
+ [x: string]: unknown;
269
+ location: "query" | "header" | "cookie";
270
+ name: string;
271
+ description?: string | undefined;
272
+ } | undefined;
273
+ httpAuthSecurityScheme?: {
274
+ [x: string]: unknown;
275
+ scheme: string;
276
+ description?: string | undefined;
277
+ bearerFormat?: string | undefined;
278
+ } | undefined;
279
+ oauth2SecurityScheme?: {
280
+ [x: string]: unknown;
281
+ flows: {
282
+ [x: string]: unknown;
283
+ authorizationCode?: {
284
+ [x: string]: unknown;
285
+ authorizationUrl: string;
286
+ tokenUrl: string;
287
+ scopes: Record<string, string>;
288
+ refreshUrl?: string | undefined;
289
+ pkceRequired?: boolean | undefined;
290
+ } | undefined;
291
+ clientCredentials?: {
292
+ [x: string]: unknown;
293
+ tokenUrl: string;
294
+ scopes: Record<string, string>;
295
+ refreshUrl?: string | undefined;
296
+ } | undefined;
297
+ implicit?: {
298
+ [x: string]: unknown;
299
+ authorizationUrl?: string | undefined;
300
+ refreshUrl?: string | undefined;
301
+ scopes?: Record<string, string> | undefined;
302
+ } | undefined;
303
+ password?: {
304
+ [x: string]: unknown;
305
+ tokenUrl?: string | undefined;
306
+ refreshUrl?: string | undefined;
307
+ scopes?: Record<string, string> | undefined;
308
+ } | undefined;
309
+ deviceCode?: {
310
+ [x: string]: unknown;
311
+ deviceAuthorizationUrl: string;
312
+ tokenUrl: string;
313
+ scopes: Record<string, string>;
314
+ refreshUrl?: string | undefined;
315
+ } | undefined;
316
+ };
317
+ description?: string | undefined;
318
+ oauth2MetadataUrl?: string | undefined;
319
+ } | undefined;
320
+ openIdConnectSecurityScheme?: {
321
+ [x: string]: unknown;
322
+ openIdConnectUrl: string;
323
+ description?: string | undefined;
324
+ } | undefined;
325
+ mtlsSecurityScheme?: {
326
+ [x: string]: unknown;
327
+ description?: string | undefined;
328
+ } | undefined;
329
+ }> | undefined;
330
+ securityRequirements?: {
331
+ [x: string]: unknown;
332
+ schemes: Record<string, {
333
+ [x: string]: unknown;
334
+ list: string[];
335
+ }>;
336
+ }[] | undefined;
337
+ signatures?: {
338
+ [x: string]: unknown;
339
+ protected: string;
340
+ signature: string;
341
+ header?: Record<string, unknown> | undefined;
342
+ }[] | undefined;
343
+ iconUrl?: string | undefined;
344
+ }>;
345
+ declare function generateAgentCardJson(input: unknown, options?: AgentCardJsonOptions): string;
346
+ declare function generateAgentCardFile(input: unknown, options?: AgentCardJsonOptions): GeneratedAgentCard;
347
+ declare const agentCardProvider: WellKnownProvider<AgentCardInput>;
348
+ declare function agentCard(config: AgentCardInput): WellKnownProviderInstance;
349
+
350
+ export { type AgentCardInput, type AgentCardJsonOptions, type AgentCardOutput, type GeneratedAgentCard, agentCard, agentCardOAuthFlowsSchema, agentCardProvider, agentCardSchema, agentCardSecuritySchemeSchema, generateAgentCard, generateAgentCardFile, generateAgentCardJson, safeGenerateAgentCard };
package/dist/index.js ADDED
@@ -0,0 +1,221 @@
1
+ // src/index.ts
2
+ import { z } from "zod";
3
+ var nonEmptyString = z.string().min(1);
4
+ var url = z.string().url();
5
+ var httpsUrl = url.refine((value) => new URL(value).protocol === "https:", {
6
+ message: "URL must use HTTPS."
7
+ });
8
+ var scopesSchema = z.record(nonEmptyString, z.string());
9
+ var securityRequirementSchema = z.object({
10
+ schemes: z.record(nonEmptyString, z.object({ list: z.array(nonEmptyString) }).loose())
11
+ }).loose();
12
+ var authorizationCodeFlowSchema = z.object({
13
+ authorizationUrl: httpsUrl,
14
+ tokenUrl: httpsUrl,
15
+ refreshUrl: httpsUrl.optional(),
16
+ scopes: scopesSchema,
17
+ pkceRequired: z.boolean().optional()
18
+ }).loose();
19
+ var clientCredentialsFlowSchema = z.object({
20
+ tokenUrl: httpsUrl,
21
+ refreshUrl: httpsUrl.optional(),
22
+ scopes: scopesSchema
23
+ }).loose();
24
+ var implicitFlowSchema = z.object({
25
+ authorizationUrl: httpsUrl.optional(),
26
+ refreshUrl: httpsUrl.optional(),
27
+ scopes: scopesSchema.optional()
28
+ }).loose();
29
+ var passwordFlowSchema = z.object({
30
+ tokenUrl: httpsUrl.optional(),
31
+ refreshUrl: httpsUrl.optional(),
32
+ scopes: scopesSchema.optional()
33
+ }).loose();
34
+ var deviceCodeFlowSchema = z.object({
35
+ deviceAuthorizationUrl: httpsUrl,
36
+ tokenUrl: httpsUrl,
37
+ refreshUrl: httpsUrl.optional(),
38
+ scopes: scopesSchema
39
+ }).loose();
40
+ var agentCardOAuthFlowsSchema = z.object({
41
+ authorizationCode: authorizationCodeFlowSchema.optional(),
42
+ clientCredentials: clientCredentialsFlowSchema.optional(),
43
+ implicit: implicitFlowSchema.optional(),
44
+ password: passwordFlowSchema.optional(),
45
+ deviceCode: deviceCodeFlowSchema.optional()
46
+ }).loose().superRefine((flows, context) => {
47
+ const configured = [
48
+ flows.authorizationCode,
49
+ flows.clientCredentials,
50
+ flows.implicit,
51
+ flows.password,
52
+ flows.deviceCode
53
+ ].filter((flow) => flow !== void 0);
54
+ if (configured.length !== 1) {
55
+ context.addIssue({
56
+ code: "custom",
57
+ message: "OAuth flows must contain exactly one flow."
58
+ });
59
+ }
60
+ });
61
+ var apiKeySecurityScheme = z.object({
62
+ description: z.string().optional(),
63
+ location: z.enum(["query", "header", "cookie"]),
64
+ name: nonEmptyString
65
+ }).loose();
66
+ var httpAuthSecurityScheme = z.object({
67
+ description: z.string().optional(),
68
+ scheme: nonEmptyString,
69
+ bearerFormat: nonEmptyString.optional()
70
+ }).loose();
71
+ var oauth2SecurityScheme = z.object({
72
+ description: z.string().optional(),
73
+ flows: agentCardOAuthFlowsSchema,
74
+ oauth2MetadataUrl: httpsUrl.optional()
75
+ }).loose();
76
+ var openIdConnectSecurityScheme = z.object({
77
+ description: z.string().optional(),
78
+ openIdConnectUrl: httpsUrl
79
+ }).loose();
80
+ var mutualTlsSecurityScheme = z.object({ description: z.string().optional() }).loose();
81
+ var agentCardSecuritySchemeSchema = z.object({
82
+ apiKeySecurityScheme: apiKeySecurityScheme.optional(),
83
+ httpAuthSecurityScheme: httpAuthSecurityScheme.optional(),
84
+ oauth2SecurityScheme: oauth2SecurityScheme.optional(),
85
+ openIdConnectSecurityScheme: openIdConnectSecurityScheme.optional(),
86
+ mtlsSecurityScheme: mutualTlsSecurityScheme.optional()
87
+ }).loose().superRefine((scheme, context) => {
88
+ const configured = [
89
+ scheme.apiKeySecurityScheme,
90
+ scheme.httpAuthSecurityScheme,
91
+ scheme.oauth2SecurityScheme,
92
+ scheme.openIdConnectSecurityScheme,
93
+ scheme.mtlsSecurityScheme
94
+ ].filter((value) => value !== void 0);
95
+ if (configured.length !== 1) {
96
+ context.addIssue({
97
+ code: "custom",
98
+ message: "Security scheme must contain exactly one scheme."
99
+ });
100
+ }
101
+ });
102
+ var agentCardSchema = z.object({
103
+ name: nonEmptyString,
104
+ description: nonEmptyString,
105
+ supportedInterfaces: z.array(
106
+ z.object({
107
+ url,
108
+ protocolBinding: nonEmptyString,
109
+ tenant: nonEmptyString.optional(),
110
+ protocolVersion: z.string().regex(/^\d+\.\d+$/, {
111
+ message: "Protocol version must use Major.Minor format."
112
+ })
113
+ }).loose()
114
+ ).min(1),
115
+ provider: z.object({
116
+ url,
117
+ organization: nonEmptyString
118
+ }).loose().optional(),
119
+ version: nonEmptyString,
120
+ documentationUrl: url.optional(),
121
+ capabilities: z.object({
122
+ streaming: z.boolean().optional(),
123
+ pushNotifications: z.boolean().optional(),
124
+ extensions: z.array(
125
+ z.object({
126
+ uri: url,
127
+ description: z.string().optional(),
128
+ required: z.boolean().optional(),
129
+ params: z.record(z.string(), z.unknown()).optional()
130
+ }).loose()
131
+ ).optional(),
132
+ extendedAgentCard: z.boolean().optional()
133
+ }).loose(),
134
+ securitySchemes: z.record(nonEmptyString, agentCardSecuritySchemeSchema).optional(),
135
+ securityRequirements: z.array(securityRequirementSchema).optional(),
136
+ defaultInputModes: z.array(nonEmptyString).min(1),
137
+ defaultOutputModes: z.array(nonEmptyString).min(1),
138
+ skills: z.array(
139
+ z.object({
140
+ id: nonEmptyString,
141
+ name: nonEmptyString,
142
+ description: nonEmptyString,
143
+ tags: z.array(nonEmptyString),
144
+ examples: z.array(nonEmptyString).optional(),
145
+ inputModes: z.array(nonEmptyString).optional(),
146
+ outputModes: z.array(nonEmptyString).optional(),
147
+ securityRequirements: z.array(securityRequirementSchema).optional()
148
+ }).loose()
149
+ ),
150
+ signatures: z.array(
151
+ z.object({
152
+ protected: nonEmptyString,
153
+ signature: nonEmptyString,
154
+ header: z.record(z.string(), z.unknown()).optional()
155
+ }).loose()
156
+ ).optional(),
157
+ iconUrl: url.optional()
158
+ }).loose().superRefine((card, context) => {
159
+ const declaredSchemes = new Set(Object.keys(card.securitySchemes ?? {}));
160
+ const requirements = [
161
+ ...card.securityRequirements ?? [],
162
+ ...card.skills.flatMap((skill) => skill.securityRequirements ?? [])
163
+ ];
164
+ for (const requirement of requirements) {
165
+ for (const scheme of Object.keys(requirement.schemes)) {
166
+ if (!declaredSchemes.has(scheme)) {
167
+ context.addIssue({
168
+ code: "custom",
169
+ path: ["securityRequirements"],
170
+ message: `Security requirement references undeclared scheme "${scheme}".`
171
+ });
172
+ }
173
+ }
174
+ }
175
+ });
176
+ function generateAgentCard(input) {
177
+ return agentCardSchema.parse(input);
178
+ }
179
+ function safeGenerateAgentCard(input) {
180
+ return agentCardSchema.safeParse(input);
181
+ }
182
+ function generateAgentCardJson(input, options = {}) {
183
+ return JSON.stringify(
184
+ generateAgentCard(input),
185
+ null,
186
+ options.pretty === false ? void 0 : " "
187
+ );
188
+ }
189
+ function generateAgentCardFile(input, options = {}) {
190
+ const data = generateAgentCard(input);
191
+ return {
192
+ filename: "agent-card.json",
193
+ path: "/.well-known/agent-card.json",
194
+ contentType: "application/json",
195
+ data,
196
+ body: generateAgentCardJson(data, options)
197
+ };
198
+ }
199
+ var agentCardProvider = {
200
+ name: "agent-card",
201
+ path: "/.well-known/agent-card.json",
202
+ generate: generateAgentCardFile
203
+ };
204
+ function agentCard(config) {
205
+ return {
206
+ name: agentCardProvider.name,
207
+ path: agentCardProvider.path,
208
+ generate: () => agentCardProvider.generate(config)
209
+ };
210
+ }
211
+ export {
212
+ agentCard,
213
+ agentCardOAuthFlowsSchema,
214
+ agentCardProvider,
215
+ agentCardSchema,
216
+ agentCardSecuritySchemeSchema,
217
+ generateAgentCard,
218
+ generateAgentCardFile,
219
+ generateAgentCardJson,
220
+ safeGenerateAgentCard
221
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@well-known-js/agent-card",
3
+ "version": "1.0.0",
4
+ "description": "Generate Agent2Agent Agent Card discovery documents.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/louchebem06/well-known.git",
9
+ "directory": "packages/agent-card"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "dependencies": {
24
+ "zod": "^4.6.2",
25
+ "@well-known-js/core": "1.0.2"
26
+ },
27
+ "engines": {
28
+ "node": ">=20"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "scripts": {
34
+ "build": "tsup src/index.ts --tsconfig tsconfig.build.json --format esm --dts --clean",
35
+ "dev": "tsup src/index.ts --tsconfig tsconfig.build.json --format esm --dts --watch",
36
+ "typecheck": "tsc -b",
37
+ "test": "vitest run",
38
+ "test:watch": "vitest",
39
+ "test:coverage": "vitest run --coverage"
40
+ }
41
+ }