@artinet/sdk 0.5.17 → 0.5.18

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.
Files changed (151) hide show
  1. package/README.md +101 -26
  2. package/dist/browser/browser.d.ts +9 -0
  3. package/dist/browser/browser.js +10 -0
  4. package/dist/browser/client/a2a-client.d.ts +126 -0
  5. package/dist/browser/client/a2a-client.js +221 -0
  6. package/dist/browser/client/index.d.ts +1 -0
  7. package/dist/browser/client/index.js +1 -0
  8. package/dist/browser/services/a2a/helpers/message-builder.d.ts +12 -0
  9. package/dist/browser/services/a2a/helpers/message-builder.js +61 -0
  10. package/dist/browser/transport/rpc/parser.d.ts +15 -0
  11. package/dist/browser/transport/rpc/parser.js +48 -0
  12. package/dist/browser/transport/rpc/rpc-client.d.ts +80 -0
  13. package/dist/browser/transport/rpc/rpc-client.js +189 -0
  14. package/dist/browser/transport/streaming/event-stream.d.ts +25 -0
  15. package/dist/browser/transport/streaming/event-stream.js +99 -0
  16. package/dist/browser/types/ext.d.ts +13 -0
  17. package/dist/browser/types/ext.js +10 -0
  18. package/dist/browser/types/index.d.ts +4 -0
  19. package/dist/browser/types/index.js +4 -0
  20. package/dist/browser/types/interfaces/client.d.ts +135 -0
  21. package/dist/browser/types/interfaces/client.js +5 -0
  22. package/dist/browser/types/interfaces/index.d.ts +3 -0
  23. package/dist/browser/types/interfaces/index.js +3 -0
  24. package/dist/browser/types/interfaces/services/a2a/builder.d.ts +37 -0
  25. package/dist/browser/types/interfaces/services/a2a/builder.js +5 -0
  26. package/dist/browser/types/interfaces/services/a2a/context.d.ts +162 -0
  27. package/dist/browser/types/interfaces/services/a2a/context.js +5 -0
  28. package/dist/browser/types/interfaces/services/a2a/engine.d.ts +7 -0
  29. package/dist/browser/types/interfaces/services/a2a/engine.js +5 -0
  30. package/dist/browser/types/interfaces/services/a2a/index.d.ts +5 -0
  31. package/dist/browser/types/interfaces/services/a2a/index.js +5 -0
  32. package/dist/browser/types/interfaces/services/a2a/legacy.d.ts +93 -0
  33. package/dist/browser/types/interfaces/services/a2a/legacy.js +5 -0
  34. package/dist/browser/types/interfaces/services/a2a/service.d.ts +413 -0
  35. package/dist/browser/types/interfaces/services/a2a/service.js +5 -0
  36. package/dist/browser/types/interfaces/services/core/context/command.d.ts +25 -0
  37. package/dist/browser/types/interfaces/services/core/context/command.js +5 -0
  38. package/dist/browser/types/interfaces/services/core/context/context.d.ts +207 -0
  39. package/dist/browser/types/interfaces/services/core/context/context.js +5 -0
  40. package/dist/browser/types/interfaces/services/core/context/index.d.ts +3 -0
  41. package/dist/browser/types/interfaces/services/core/context/index.js +3 -0
  42. package/dist/browser/types/interfaces/services/core/context/types.d.ts +11 -0
  43. package/dist/browser/types/interfaces/services/core/context/types.js +5 -0
  44. package/dist/browser/types/interfaces/services/core/execution/engine.d.ts +106 -0
  45. package/dist/browser/types/interfaces/services/core/execution/engine.js +5 -0
  46. package/dist/browser/types/interfaces/services/core/execution/environment.d.ts +11 -0
  47. package/dist/browser/types/interfaces/services/core/execution/environment.js +5 -0
  48. package/dist/browser/types/interfaces/services/core/execution/execute.d.ts +7 -0
  49. package/dist/browser/types/interfaces/services/core/execution/execute.js +5 -0
  50. package/dist/browser/types/interfaces/services/core/execution/index.d.ts +3 -0
  51. package/dist/browser/types/interfaces/services/core/execution/index.js +3 -0
  52. package/dist/browser/types/interfaces/services/core/index.d.ts +4 -0
  53. package/dist/browser/types/interfaces/services/core/index.js +4 -0
  54. package/dist/browser/types/interfaces/services/core/managers/cancellation.d.ts +9 -0
  55. package/dist/browser/types/interfaces/services/core/managers/cancellation.js +5 -0
  56. package/dist/browser/types/interfaces/services/core/managers/connection.d.ts +9 -0
  57. package/dist/browser/types/interfaces/services/core/managers/connection.js +5 -0
  58. package/dist/browser/types/interfaces/services/core/managers/context.d.ts +17 -0
  59. package/dist/browser/types/interfaces/services/core/managers/context.js +5 -0
  60. package/dist/browser/types/interfaces/services/core/managers/event.d.ts +328 -0
  61. package/dist/browser/types/interfaces/services/core/managers/event.js +5 -0
  62. package/dist/browser/types/interfaces/services/core/managers/index.d.ts +6 -0
  63. package/dist/browser/types/interfaces/services/core/managers/index.js +6 -0
  64. package/dist/browser/types/interfaces/services/core/managers/stream.d.ts +217 -0
  65. package/dist/browser/types/interfaces/services/core/managers/stream.js +5 -0
  66. package/dist/browser/types/interfaces/services/core/managers/task.d.ts +9 -0
  67. package/dist/browser/types/interfaces/services/core/managers/task.js +1 -0
  68. package/dist/browser/types/interfaces/services/core/service.d.ts +115 -0
  69. package/dist/browser/types/interfaces/services/core/service.js +5 -0
  70. package/dist/browser/types/interfaces/services/index.d.ts +4 -0
  71. package/dist/browser/types/interfaces/services/index.js +4 -0
  72. package/dist/browser/types/interfaces/services/mcp/index.d.ts +1 -0
  73. package/dist/browser/types/interfaces/services/mcp/index.js +1 -0
  74. package/dist/browser/types/interfaces/services/mcp/service.d.ts +49 -0
  75. package/dist/browser/types/interfaces/services/mcp/service.js +5 -0
  76. package/dist/browser/types/interfaces/services/protocol.d.ts +33 -0
  77. package/dist/browser/types/interfaces/services/protocol.js +34 -0
  78. package/dist/browser/types/interfaces/storage.d.ts +8 -0
  79. package/dist/browser/types/interfaces/storage.js +5 -0
  80. package/dist/browser/types/schemas/a2a/agent.d.ts +2583 -0
  81. package/dist/browser/types/schemas/a2a/agent.js +323 -0
  82. package/dist/browser/types/schemas/a2a/auth.d.ts +908 -0
  83. package/dist/browser/types/schemas/a2a/auth.js +283 -0
  84. package/dist/browser/types/schemas/a2a/error.d.ts +396 -0
  85. package/dist/browser/types/schemas/a2a/error.js +163 -0
  86. package/dist/browser/types/schemas/a2a/index.d.ts +11 -0
  87. package/dist/browser/types/schemas/a2a/index.js +11 -0
  88. package/dist/browser/types/schemas/a2a/kind.d.ts +11 -0
  89. package/dist/browser/types/schemas/a2a/kind.js +20 -0
  90. package/dist/browser/types/schemas/a2a/message.d.ts +10343 -0
  91. package/dist/browser/types/schemas/a2a/message.js +130 -0
  92. package/dist/browser/types/schemas/a2a/notification.d.ts +1517 -0
  93. package/dist/browser/types/schemas/a2a/notification.js +203 -0
  94. package/dist/browser/types/schemas/a2a/parameters.d.ts +956 -0
  95. package/dist/browser/types/schemas/a2a/parameters.js +241 -0
  96. package/dist/browser/types/schemas/a2a/protocol.d.ts +14363 -0
  97. package/dist/browser/types/schemas/a2a/protocol.js +59 -0
  98. package/dist/browser/types/schemas/a2a/rpc.d.ts +182 -0
  99. package/dist/browser/types/schemas/a2a/rpc.js +126 -0
  100. package/dist/browser/types/schemas/a2a/task.d.ts +5886 -0
  101. package/dist/browser/types/schemas/a2a/task.js +134 -0
  102. package/dist/browser/types/schemas/a2a/transport.d.ts +31 -0
  103. package/dist/browser/types/schemas/a2a/transport.js +28 -0
  104. package/dist/browser/types/schemas/index.d.ts +1 -0
  105. package/dist/browser/types/schemas/index.js +1 -0
  106. package/dist/browser/types/utils/index.d.ts +1 -0
  107. package/dist/browser/types/utils/index.js +1 -0
  108. package/dist/browser/types/utils/transform.d.ts +64 -0
  109. package/dist/browser/types/utils/transform.js +35 -0
  110. package/dist/browser/utils/common/constants.d.ts +11 -0
  111. package/dist/browser/utils/common/constants.js +38 -0
  112. package/dist/browser/utils/common/errors.d.ts +24 -0
  113. package/dist/browser/utils/common/errors.js +42 -0
  114. package/dist/browser/utils/common/utils.d.ts +9 -0
  115. package/dist/browser/utils/common/utils.js +11 -0
  116. package/dist/browser/utils/logging/index.d.ts +2 -0
  117. package/dist/browser/utils/logging/index.js +2 -0
  118. package/dist/browser/utils/logging/log.d.ts +33 -0
  119. package/dist/browser/utils/logging/log.js +75 -0
  120. package/dist/browser/utils/logging/logger.d.ts +18 -0
  121. package/dist/browser/utils/logging/logger.js +18 -0
  122. package/dist/client/a2a-client.d.ts +2 -1
  123. package/dist/client/a2a-client.js +13 -4
  124. package/dist/server/express/errors.js +1 -1
  125. package/dist/server/express/middeware.d.ts +2 -2
  126. package/dist/server/express/middeware.js +26 -6
  127. package/dist/server/express/server.d.ts +2 -1
  128. package/dist/server/express/server.js +32 -6
  129. package/dist/services/a2a/factory/builder.js +6 -1
  130. package/dist/services/a2a/factory/service.js +1 -1
  131. package/dist/services/a2a/helpers/agentcard-builder.js +1 -0
  132. package/dist/services/a2a/helpers/history.d.ts +2 -0
  133. package/dist/services/a2a/helpers/history.js +3 -0
  134. package/dist/services/a2a/helpers/index.d.ts +2 -0
  135. package/dist/services/a2a/helpers/index.js +2 -0
  136. package/dist/services/a2a/methods/get-task.js +2 -0
  137. package/dist/services/a2a/methods/send-message.js +18 -1
  138. package/dist/services/a2a/service.d.ts +2 -1
  139. package/dist/services/a2a/service.js +20 -6
  140. package/dist/services/mcp/service.js +0 -1
  141. package/dist/transport/rpc/parser.js +2 -2
  142. package/dist/transport/rpc/rpc-client.js +2 -2
  143. package/dist/types/interfaces/services/a2a/service.d.ts +4 -0
  144. package/dist/utils/common/constants.js +1 -1
  145. package/dist/utils/common/errors.d.ts +2 -1
  146. package/dist/utils/common/errors.js +2 -1
  147. package/dist/utils/common/schema-validation.d.ts +2 -0
  148. package/dist/utils/common/schema-validation.js +12 -0
  149. package/dist/utils/index.d.ts +1 -0
  150. package/dist/utils/index.js +1 -0
  151. package/package.json +20 -17
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { z } from "zod";
6
+ import { MessageSchema, ArtifactSchema } from "./parameters.js";
7
+ import { JSONRPCErrorResponseSchema, JSONRPCRequestSchema, JSONRPCSuccessResponseSchema, } from "./rpc.js";
8
+ import { KindSchema } from "./kind.js";
9
+ /**
10
+ * @description Represents the state of a task within the A2A protocol.
11
+ */
12
+ export const TaskStateSchema = z
13
+ .enum([
14
+ "submitted",
15
+ "working",
16
+ "input-required",
17
+ "completed",
18
+ "canceled",
19
+ "failed",
20
+ "rejected",
21
+ "auth-required",
22
+ "unknown",
23
+ ])
24
+ .describe("Defines the lifecycle states of a Task.");
25
+ export const TaskState = TaskStateSchema.enum;
26
+ /**
27
+ * Basic parameters used for task ID operations.
28
+ */
29
+ export const TaskIdParamsSchema = z
30
+ .object({
31
+ id: z.string().describe("The ID of the task to query."),
32
+ metadata: z
33
+ .record(z.string(), z.unknown())
34
+ .optional()
35
+ .describe("Additional metadata to include in the request."),
36
+ })
37
+ .describe("Defines the parameters for a request to get a task.");
38
+ /**
39
+ * Parameters used for querying task-related information by ID.
40
+ */
41
+ export const TaskQueryParamsSchema = TaskIdParamsSchema.extend({
42
+ historyLength: z.number().optional(),
43
+ });
44
+ /**
45
+ * Represents the status of a task at a specific point in time.
46
+ */
47
+ export const TaskStatusSchema = z.object({
48
+ state: TaskStateSchema,
49
+ message: MessageSchema.optional(),
50
+ timestamp: z.string().datetime().optional(),
51
+ });
52
+ /**
53
+ * Represents a task being processed by an agent.
54
+ */
55
+ export const TaskSchema = z.object({
56
+ id: z.string(),
57
+ contextId: z.string(),
58
+ status: TaskStatusSchema,
59
+ history: z.array(MessageSchema).optional(),
60
+ artifacts: z.array(ArtifactSchema).optional(),
61
+ metadata: z.record(z.string(), z.unknown()).optional(),
62
+ kind: KindSchema.refine((kind) => kind === "task"),
63
+ });
64
+ /**
65
+ * Represents a status update event for a task, typically used in streaming scenarios.
66
+ */
67
+ export const TaskStatusUpdateEventSchema = z.object({
68
+ taskId: z.string(),
69
+ contextId: z.string(),
70
+ kind: KindSchema.refine((kind) => kind === "status-update"),
71
+ status: TaskStatusSchema,
72
+ final: z.boolean(),
73
+ metadata: z.record(z.string(), z.unknown()).optional(),
74
+ });
75
+ /**
76
+ * Represents an artifact update event for a task, typically used in streaming scenarios.
77
+ */
78
+ export const TaskArtifactUpdateEventSchema = z.object({
79
+ taskId: z.string(),
80
+ contextId: z.string(),
81
+ kind: KindSchema.refine((kind) => kind === "artifact-update"),
82
+ artifact: ArtifactSchema,
83
+ append: z.boolean().optional(),
84
+ lastChunk: z.boolean().optional(),
85
+ metadata: z.record(z.string(), z.unknown()).optional(),
86
+ });
87
+ /**
88
+ * @description Request to retrieve the current state of a task.
89
+ */
90
+ export const GetTaskRequestSchema = JSONRPCRequestSchema.extend({
91
+ method: z.literal("tasks/get"),
92
+ params: TaskQueryParamsSchema.describe("Defines the parameters for a request to get a task."),
93
+ }).describe("Represents a JSON-RPC request for the `tasks/get` method.");
94
+ /**
95
+ * @description Represents a successful JSON-RPC response for the `tasks/get` method.
96
+ */
97
+ export const GetTaskSuccessResponseSchema = JSONRPCSuccessResponseSchema.extend({
98
+ /**
99
+ * @required The result of the request, which can be a direct reply Message or the initial Task object.
100
+ */
101
+ result: TaskSchema.describe("The result of the request, which can be a direct reply Message or the initial Task object."),
102
+ }).describe("JSON-RPC success response model for the 'tasks/get' method.");
103
+ /**
104
+ * @description Represents a JSON-RPC response for the `tasks/get` method.
105
+ */
106
+ export const GetTaskResponseSchema = z
107
+ .union([GetTaskSuccessResponseSchema, JSONRPCErrorResponseSchema])
108
+ .describe("Represents a JSON-RPC response for the `tasks/get` method.");
109
+ /**
110
+ * @description Request to re-subscribe to a task's updates.
111
+ */
112
+ export const TaskResubscriptionRequestSchema = JSONRPCRequestSchema.extend({
113
+ method: z.literal("tasks/resubscribe"),
114
+ params: TaskIdParamsSchema.describe("Defines the parameters for a request to re-subscribe to a task's updates."),
115
+ }).describe("Represents a JSON-RPC request for the `tasks/resubscribe` method.");
116
+ /**
117
+ * @description Request to cancel a task.
118
+ */
119
+ export const CancelTaskRequestSchema = JSONRPCRequestSchema.extend({
120
+ method: z.literal("tasks/cancel"),
121
+ params: TaskIdParamsSchema.describe("Defines the parameters for a request to cancel a task."),
122
+ }).describe("Represents a JSON-RPC request for the `tasks/cancel` method.");
123
+ /**
124
+ * @description Represents a successful JSON-RPC response for the `tasks/cancel` method.
125
+ */
126
+ export const CancelTaskSuccessResponseSchema = JSONRPCSuccessResponseSchema.extend({
127
+ result: TaskSchema.describe("The result of the request, which can be a direct reply Message or the initial Task object."),
128
+ }).describe("JSON-RPC success response model for the 'tasks/cancel' method.");
129
+ /**
130
+ * @description Represents a JSON-RPC response for the `tasks/cancel` method.
131
+ */
132
+ export const CancelTaskResponseSchema = z
133
+ .union([CancelTaskSuccessResponseSchema, JSONRPCErrorResponseSchema])
134
+ .describe("Represents a JSON-RPC response for the `tasks/cancel` method.");
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { z } from "zod";
6
+ /**
7
+ * @description Supported A2A transport protocols.
8
+ */
9
+ export declare const TransportProtocolSchema: z.ZodEnum<["JSONRPC", "GRPC", "HTTP+JSON"]>;
10
+ export type TransportProtocol = z.infer<typeof TransportProtocolSchema>;
11
+ /**
12
+ * @description Declares a combination of a target URL and a transport protocol for interacting with the agent.
13
+ * This allows agents to expose the same functionality over multiple transport mechanisms.
14
+ */
15
+ export declare const AgentInterfaceSchema: z.ZodObject<{
16
+ /**
17
+ * @required The URL where this interface is available. Must be a valid absolute HTTPS URL in production.
18
+ */
19
+ url: z.ZodString;
20
+ /**
21
+ * @required The transport protocol supported at this URL.
22
+ */
23
+ transport: z.ZodUnion<[z.ZodEnum<["JSONRPC", "GRPC", "HTTP+JSON"]>, z.ZodString]>;
24
+ }, "strip", z.ZodTypeAny, {
25
+ url: string;
26
+ transport: string;
27
+ }, {
28
+ url: string;
29
+ transport: string;
30
+ }>;
31
+ export type AgentInterface = z.infer<typeof AgentInterfaceSchema>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { z } from "zod";
6
+ /**
7
+ * @description Supported A2A transport protocols.
8
+ */
9
+ export const TransportProtocolSchema = z.enum(["JSONRPC", "GRPC", "HTTP+JSON"]);
10
+ /**
11
+ * @description Declares a combination of a target URL and a transport protocol for interacting with the agent.
12
+ * This allows agents to expose the same functionality over multiple transport mechanisms.
13
+ */
14
+ export const AgentInterfaceSchema = z.object({
15
+ /**
16
+ * @required The URL where this interface is available. Must be a valid absolute HTTPS URL in production.
17
+ */
18
+ url: z
19
+ .string()
20
+ .url()
21
+ .describe("The URL where this interface is available. Must be a valid absolute HTTPS URL in production."),
22
+ /**
23
+ * @required The transport protocol supported at this URL.
24
+ */
25
+ transport: z
26
+ .union([TransportProtocolSchema, z.string()])
27
+ .describe("The transport protocol supported at this URL."),
28
+ });
@@ -0,0 +1 @@
1
+ export * from "./a2a/index.js";
@@ -0,0 +1 @@
1
+ export * from "./a2a/index.js";
@@ -0,0 +1 @@
1
+ export * from "./transform.js";
@@ -0,0 +1 @@
1
+ export * from "./transform.js";
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * Type-safe object key transformation utilities using built-in TypeScript utility types
7
+ */
8
+ /**
9
+ * Forces TypeScript to evaluate and flatten intersection types into a single object type
10
+ * This makes IDE tooltips and type displays much cleaner
11
+ */
12
+ type Simplify<T> = {
13
+ [K in keyof T]: T[K];
14
+ } & {};
15
+ /**
16
+ * Configuration for renaming keys - maps old key names to new key names
17
+ * For best results, use `as const` to preserve literal string types
18
+ */
19
+ export type RenameConfig<T extends object> = {
20
+ readonly [K in keyof T]?: string;
21
+ };
22
+ /**
23
+ * Transform object type by renaming specified keys using built-in utility types
24
+ * This combines Pick/Omit patterns with Record to achieve key renaming
25
+ * Uses Simplify to flatten the final type for cleaner IDE display
26
+ */
27
+ export type TransformKeys<T extends object, Config extends RenameConfig<T>> = Simplify<Omit<T, keyof Config> & {
28
+ [OriginalKey in keyof Config & keyof T as Config[OriginalKey] extends string ? Config[OriginalKey] : OriginalKey]: T[OriginalKey];
29
+ }>;
30
+ /**
31
+ * Runtime function to transform object keys based on configuration
32
+ * Uses the TransformKeys utility type for return type inference
33
+ */
34
+ export declare function transformKeys<T extends object, Config extends RenameConfig<T>>(obj: T, config: Config): TransformKeys<T, Config>;
35
+ /**
36
+ * Helper type to extract the transformed type for a given object and config
37
+ * Useful for declaring variables with the expected transformed type
38
+ * Uses Simplify to show clean, flattened types in IDE
39
+ */
40
+ export type Transformed<T extends object, Config extends RenameConfig<T>> = Simplify<TransformKeys<T, Config>>;
41
+ /**
42
+ * Utility to create a type-safe rename configuration with better intellisense
43
+ * The returned function preserves literal string types
44
+ */
45
+ export declare function createRenameConfig<T extends object>(): <Config extends RenameConfig<T>>(config: Config) => Config;
46
+ /**
47
+ * Common transformation patterns using built-in utility types
48
+ */
49
+ export declare namespace TransformPatterns {
50
+ /**
51
+ * Convert snake_case keys to camelCase
52
+ * This is a type-level template but would need runtime implementation
53
+ */
54
+ type SnakeToCamel<T extends string> = T extends `${infer First}_${infer Rest}` ? `${First}${Capitalize<SnakeToCamel<Rest>>}` : T;
55
+ /**
56
+ * Pick specific keys and optionally rename them
57
+ */
58
+ type PickAndRename<T extends object, Keys extends keyof T, Config extends Partial<Record<Keys, string>>> = Simplify<TransformKeys<Pick<T, Keys>, Config>>;
59
+ /**
60
+ * Omit specific keys and optionally rename remaining ones
61
+ */
62
+ type OmitAndRename<T extends object, OmitKeys extends keyof T, Config extends RenameConfig<Omit<T, OmitKeys>>> = Simplify<TransformKeys<Omit<T, OmitKeys>, Config>>;
63
+ }
64
+ export {};
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * Runtime function to transform object keys based on configuration
7
+ * Uses the TransformKeys utility type for return type inference
8
+ */
9
+ export function transformKeys(obj, config) {
10
+ const result = {};
11
+ // Process each property in the original object
12
+ for (const key in obj) {
13
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
14
+ const newKeyName = config[key];
15
+ if (typeof newKeyName === "string") {
16
+ // Rename the key
17
+ result[newKeyName] = obj[key];
18
+ }
19
+ else {
20
+ // Keep original key
21
+ result[key] = obj[key];
22
+ }
23
+ }
24
+ }
25
+ return result;
26
+ }
27
+ /**
28
+ * Utility to create a type-safe rename configuration with better intellisense
29
+ * The returned function preserves literal string types
30
+ */
31
+ export function createRenameConfig() {
32
+ return function (config) {
33
+ return config;
34
+ };
35
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { TaskState, TaskStatusUpdateEvent, Message } from "../../types/index.js";
6
+ export declare const STATUS_UPDATE: (taskId: string, contextId: string, status: TaskState, message?: Message, timestamp?: string, final?: boolean) => TaskStatusUpdateEvent;
7
+ export declare const WORKING_UPDATE: (taskId: string, contextId: string, message?: Message, timestamp?: string) => TaskStatusUpdateEvent;
8
+ export declare const CANCEL_UPDATE: (taskId: string, contextId: string, message?: Message, timestamp?: string) => TaskStatusUpdateEvent;
9
+ export declare const SUBMITTED_UPDATE: (taskId: string, contextId: string, message?: Message, timestamp?: string) => TaskStatusUpdateEvent;
10
+ export declare const FAILED_UPDATE_EVENT: (taskId: string, contextId: string, message?: Message, timestamp?: string) => TaskStatusUpdateEvent;
11
+ export declare const FINAL_STATES: TaskState[];
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { TaskState } from "../../types/index.js";
6
+ import { getCurrentTimestamp } from "./utils.js";
7
+ //todo: protocol specific so move to a2a folder
8
+ export const STATUS_UPDATE = (taskId, contextId, status, message, timestamp = getCurrentTimestamp(), final = false) => {
9
+ return {
10
+ taskId: taskId,
11
+ contextId: contextId,
12
+ kind: "status-update",
13
+ status: {
14
+ state: status,
15
+ message: message,
16
+ timestamp: timestamp,
17
+ },
18
+ final: final,
19
+ };
20
+ };
21
+ export const WORKING_UPDATE = (taskId, contextId, message, timestamp) => {
22
+ return STATUS_UPDATE(taskId, contextId, TaskState.working, message, timestamp);
23
+ };
24
+ export const CANCEL_UPDATE = (taskId, contextId, message, timestamp) => {
25
+ return STATUS_UPDATE(taskId, contextId, TaskState.canceled, message, timestamp, true);
26
+ };
27
+ export const SUBMITTED_UPDATE = (taskId, contextId, message, timestamp) => {
28
+ return STATUS_UPDATE(taskId, contextId, TaskState.submitted, message, timestamp);
29
+ };
30
+ export const FAILED_UPDATE_EVENT = (taskId, contextId, message, timestamp) => {
31
+ return STATUS_UPDATE(taskId, contextId, TaskState.failed, message, timestamp, true);
32
+ };
33
+ export const FINAL_STATES = [
34
+ TaskState.completed,
35
+ TaskState.failed,
36
+ TaskState.canceled,
37
+ TaskState.rejected,
38
+ ];
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { A2AError, InvalidParamsError, InvalidRequestError, JSONRPCError, MethodNotFoundError, InternalError, TaskNotFoundError, TaskNotCancelableError, ContentTypeNotSupportedError, InvalidAgentResponseError, TaskStatusUpdateEvent, JSONParseError, AuthenticatedExtendedCardNotConfiguredError } from "../../types/index.js";
6
+ export declare class SystemError<T extends JSONRPCError> extends Error {
7
+ message: string;
8
+ code: T["code"];
9
+ data: T["data"];
10
+ constructor(message: string, code: T["code"], data: T["data"]);
11
+ }
12
+ export declare const PARSE_ERROR: <T extends JSONParseError>(data: T["data"]) => SystemError<T>;
13
+ export declare const INVALID_REQUEST: <T extends InvalidRequestError>(data: T["data"]) => SystemError<T>;
14
+ export declare const METHOD_NOT_FOUND: <T extends MethodNotFoundError>(data: T["data"]) => SystemError<T>;
15
+ export declare const INVALID_PARAMS: <T extends InvalidParamsError>(data: T["data"]) => SystemError<T>;
16
+ export declare const INTERNAL_ERROR: <T extends InternalError>(data: T["data"]) => SystemError<T>;
17
+ export declare const TASK_NOT_FOUND: <T extends TaskNotFoundError>(data: T["data"]) => SystemError<T>;
18
+ export declare const TASK_NOT_CANCELABLE: <T extends TaskNotCancelableError>(data: T["data"]) => SystemError<T>;
19
+ export declare const PUSH_NOTIFICATION_NOT_SUPPORTED: <T extends A2AError>(data: T["data"]) => SystemError<T>;
20
+ export declare const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED: <T extends AuthenticatedExtendedCardNotConfiguredError>(data: T["data"]) => SystemError<T>;
21
+ export declare const UNSUPPORTED_OPERATION: <T extends A2AError>(data: T["data"]) => SystemError<T>;
22
+ export declare const CONTENT_TYPE_NOT_SUPPORTED: <T extends ContentTypeNotSupportedError>(data: T["data"]) => SystemError<T>;
23
+ export declare const INVALID_AGENT_RESPONSE: <T extends InvalidAgentResponseError>(data: T["data"]) => SystemError<T>;
24
+ export declare const FAILED_UPDATE: (taskId: string, contextId: string, messageId: string | undefined, errMessage: string) => TaskStatusUpdateEvent;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { ErrorCodeInternalError, ErrorCodeInvalidRequest, ErrorCodeMethodNotFound, ErrorCodeParseError, ErrorCodeInvalidParams, ErrorCodeTaskNotFound, ErrorCodeTaskNotCancelable, ErrorCodeUnsupportedOperation, ErrorCodePushNotificationNotSupported, ErrorCodeContentTypeNotSupported, ErrorCodeInvalidAgentResponse, TaskState, ErrorCodeAuthenticatedExtendedCardNotConfigured, } from "../../types/index.js";
6
+ export class SystemError extends Error {
7
+ constructor(message, code, data) {
8
+ super(message);
9
+ // this.name = "RpcError";
10
+ this.message = message;
11
+ this.code = code;
12
+ this.data = data;
13
+ }
14
+ }
15
+ // Factory methods for common errors
16
+ export const PARSE_ERROR = (data) => new SystemError("Invalid JSON payload", ErrorCodeParseError, data);
17
+ export const INVALID_REQUEST = (data) => new SystemError("Request payload validation error", ErrorCodeInvalidRequest, data);
18
+ export const METHOD_NOT_FOUND = (data) => new SystemError("Method not found", ErrorCodeMethodNotFound, data);
19
+ export const INVALID_PARAMS = (data) => new SystemError("Invalid parameters", ErrorCodeInvalidParams, data);
20
+ export const INTERNAL_ERROR = (data) => new SystemError("Internal error", ErrorCodeInternalError, data);
21
+ export const TASK_NOT_FOUND = (data) => new SystemError("Task not found", ErrorCodeTaskNotFound, data);
22
+ export const TASK_NOT_CANCELABLE = (data) => new SystemError("Task cannot be canceled", ErrorCodeTaskNotCancelable, data);
23
+ export const PUSH_NOTIFICATION_NOT_SUPPORTED = (data) => new SystemError("Push Notifications is not supported", ErrorCodePushNotificationNotSupported, data);
24
+ export const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED = (data) => new SystemError("Authenticated Extended Card is not configured", ErrorCodeAuthenticatedExtendedCardNotConfigured, data);
25
+ export const UNSUPPORTED_OPERATION = (data) => new SystemError("This operation is not supported", ErrorCodeUnsupportedOperation, data);
26
+ export const CONTENT_TYPE_NOT_SUPPORTED = (data) => new SystemError("Content type not supported", ErrorCodeContentTypeNotSupported, data);
27
+ export const INVALID_AGENT_RESPONSE = (data) => new SystemError("Invalid agent response", ErrorCodeInvalidAgentResponse, data);
28
+ export const FAILED_UPDATE = (taskId, contextId, messageId = "failed-update", errMessage) => ({
29
+ taskId,
30
+ contextId,
31
+ kind: "status-update",
32
+ final: true,
33
+ status: {
34
+ state: TaskState.failed,
35
+ message: {
36
+ messageId,
37
+ role: "agent",
38
+ parts: [{ kind: "text", text: errMessage }],
39
+ kind: "message",
40
+ },
41
+ },
42
+ });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * Generates a timestamp in ISO 8601 format.
7
+ * @returns The current timestamp as a string.
8
+ */
9
+ export declare function getCurrentTimestamp(): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * Generates a timestamp in ISO 8601 format.
7
+ * @returns The current timestamp as a string.
8
+ */
9
+ export function getCurrentTimestamp() {
10
+ return new Date().toISOString();
11
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./log.js";
2
+ export * from "./logger.js";
@@ -0,0 +1,2 @@
1
+ export * from "./log.js";
2
+ export * from "./logger.js";
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * Logger utility for server operations
7
+ * @param context The context of the log (e.g., "A2AServer", "TaskStore")
8
+ * @param message The message to log
9
+ * @param data Optional data to include in the log
10
+ */
11
+ export declare function logDebug(context: string, message: string, data?: unknown): void;
12
+ /**
13
+ * Logger utility for server errors
14
+ * @param context The context of the log (e.g., "A2AServer", "TaskStore")
15
+ * @param message The message to log
16
+ * @param error The error object
17
+ * @param data Optional additional data
18
+ */
19
+ export declare function logError(context: string, message: string, error: unknown, data?: unknown): void;
20
+ /**
21
+ * Logger utility for server warnings
22
+ * @param context The context of the log (e.g., "A2AServer", "TaskStore")
23
+ * @param message The message to log
24
+ * @param data Optional data to include in the log
25
+ */
26
+ export declare function logWarn(context: string, message: string, data?: unknown): void;
27
+ /**
28
+ * Logger utility for server information
29
+ * @param context The context of the log (e.g., "A2AServer", "TaskStore")
30
+ * @param message The message to log
31
+ * @param data Optional data to include in the log
32
+ */
33
+ export declare function logInfo(context: string, message: string, data?: unknown): void;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { logger, level } from "./logger.js";
6
+ /**
7
+ * Logger utility for server operations
8
+ * @param context The context of the log (e.g., "A2AServer", "TaskStore")
9
+ * @param message The message to log
10
+ * @param data Optional data to include in the log
11
+ */
12
+ export function logDebug(context, message, data) {
13
+ const logData = { component: context };
14
+ if (data !== undefined) {
15
+ logData.data = data;
16
+ }
17
+ if (level === "silent" || level === "warning" || level === "error" || level === "info") {
18
+ return;
19
+ }
20
+ logger.debug(logData, message);
21
+ }
22
+ /**
23
+ * Logger utility for server errors
24
+ * @param context The context of the log (e.g., "A2AServer", "TaskStore")
25
+ * @param message The message to log
26
+ * @param error The error object
27
+ * @param data Optional additional data
28
+ */
29
+ export function logError(context, message, error, data) {
30
+ const logData = {
31
+ component: context,
32
+ err: error instanceof Error ? error : new Error(String(error)),
33
+ };
34
+ if (data !== undefined) {
35
+ logData.data = data;
36
+ }
37
+ if (level === "silent") {
38
+ return;
39
+ }
40
+ logger.error(logData, message);
41
+ }
42
+ /**
43
+ * Logger utility for server warnings
44
+ * @param context The context of the log (e.g., "A2AServer", "TaskStore")
45
+ * @param message The message to log
46
+ * @param data Optional data to include in the log
47
+ */
48
+ export function logWarn(context, message, data) {
49
+ const logData = { component: context };
50
+ if (data !== undefined) {
51
+ logData.data = data;
52
+ }
53
+ if (level === "silent" || level === "error") {
54
+ return;
55
+ }
56
+ logger.warn(logData, message);
57
+ }
58
+ /**
59
+ * Logger utility for server information
60
+ * @param context The context of the log (e.g., "A2AServer", "TaskStore")
61
+ * @param message The message to log
62
+ * @param data Optional data to include in the log
63
+ */
64
+ export function logInfo(context, message, data) {
65
+ const logData = { component: context };
66
+ if (data !== undefined) {
67
+ logData.data = data;
68
+ }
69
+ if (level === "error" ||
70
+ level === "warning" ||
71
+ level === "silent") {
72
+ return;
73
+ }
74
+ logger.info(logData, message);
75
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * A lightweight cross-platform logger instance
7
+ */
8
+ export declare const logger: Console;
9
+ export declare let level: "trace" | "verbose" | "debug" | "info" | "warning" | "error" | "silent";
10
+ /**
11
+ * Configures the logger with the specified options
12
+ * @param options - Logger configuration options
13
+ */
14
+ export declare function configureLogger(options: {
15
+ level?: "trace" | "verbose" | "debug" | "info" | "warning" | "error" | "silent";
16
+ name?: string;
17
+ prettyPrint?: boolean;
18
+ }): Console;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * A lightweight cross-platform logger instance
7
+ */
8
+ export const logger = console;
9
+ export let level = "silent";
10
+ /**
11
+ * Configures the logger with the specified options
12
+ * @param options - Logger configuration options
13
+ */
14
+ export function configureLogger(options) {
15
+ level = options.level || "silent";
16
+ return logger;
17
+ }
18
+ configureLogger({ level: "silent" });
@@ -14,6 +14,7 @@ export declare class A2AClient implements Client {
14
14
  private customHeaders;
15
15
  private fallbackPath;
16
16
  private agentUrl;
17
+ private mergePath;
17
18
  /**
18
19
  * Creates a new A2AClient instance.
19
20
  * @param baseUrl The base URL for the A2A server.
@@ -28,7 +29,7 @@ export declare class A2AClient implements Client {
28
29
  * const card = await client.agentCard();
29
30
  * console.log(card);
30
31
  */
31
- constructor(baseUrl: URL | string, headers?: Record<string, string>, fallbackPath?: string);
32
+ constructor(baseUrl: URL | string, headers?: Record<string, string>, fallbackPath?: string, mergePath?: boolean);
32
33
  /**
33
34
  * Retrieves the AgentCard from the A2A server.
34
35
  * Caches the result after the first successful fetch.