@a2a-wrapper/core 1.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.
Files changed (50) hide show
  1. package/README.md +186 -0
  2. package/dist/cli/scaffold.d.ts +237 -0
  3. package/dist/cli/scaffold.d.ts.map +1 -0
  4. package/dist/cli/scaffold.js +241 -0
  5. package/dist/cli/scaffold.js.map +1 -0
  6. package/dist/config/loader.d.ts +100 -0
  7. package/dist/config/loader.d.ts.map +1 -0
  8. package/dist/config/loader.js +130 -0
  9. package/dist/config/loader.js.map +1 -0
  10. package/dist/config/types.d.ts +317 -0
  11. package/dist/config/types.d.ts.map +1 -0
  12. package/dist/config/types.js +17 -0
  13. package/dist/config/types.js.map +1 -0
  14. package/dist/events/event-publisher.d.ts +205 -0
  15. package/dist/events/event-publisher.d.ts.map +1 -0
  16. package/dist/events/event-publisher.js +317 -0
  17. package/dist/events/event-publisher.js.map +1 -0
  18. package/dist/executor/types.d.ts +164 -0
  19. package/dist/executor/types.d.ts.map +1 -0
  20. package/dist/executor/types.js +30 -0
  21. package/dist/executor/types.js.map +1 -0
  22. package/dist/index.d.ts +37 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +34 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/server/agent-card.d.ts +66 -0
  27. package/dist/server/agent-card.d.ts.map +1 -0
  28. package/dist/server/agent-card.js +114 -0
  29. package/dist/server/agent-card.js.map +1 -0
  30. package/dist/server/factory.d.ts +159 -0
  31. package/dist/server/factory.d.ts.map +1 -0
  32. package/dist/server/factory.js +167 -0
  33. package/dist/server/factory.js.map +1 -0
  34. package/dist/session/base-session-manager.d.ts +218 -0
  35. package/dist/session/base-session-manager.d.ts.map +1 -0
  36. package/dist/session/base-session-manager.js +222 -0
  37. package/dist/session/base-session-manager.js.map +1 -0
  38. package/dist/utils/deep-merge.d.ts +83 -0
  39. package/dist/utils/deep-merge.d.ts.map +1 -0
  40. package/dist/utils/deep-merge.js +108 -0
  41. package/dist/utils/deep-merge.js.map +1 -0
  42. package/dist/utils/deferred.d.ts +97 -0
  43. package/dist/utils/deferred.d.ts.map +1 -0
  44. package/dist/utils/deferred.js +83 -0
  45. package/dist/utils/deferred.js.map +1 -0
  46. package/dist/utils/logger.d.ts +186 -0
  47. package/dist/utils/logger.d.ts.map +1 -0
  48. package/dist/utils/logger.js +244 -0
  49. package/dist/utils/logger.js.map +1 -0
  50. package/package.json +57 -0
@@ -0,0 +1,244 @@
1
+ /**
2
+ * @module utils/logger
3
+ *
4
+ * Structured, leveled logging with child-logger support and configurable root names.
5
+ *
6
+ * This module provides the logging infrastructure for all A2A wrapper projects.
7
+ * Each wrapper creates its own root logger via {@link createLogger}, avoiding
8
+ * hardcoded singletons and enabling independent log hierarchies per project.
9
+ *
10
+ * Output format: `[ISO_timestamp] [LEVEL] [name] message {data}`
11
+ *
12
+ * - ERROR messages route to `console.error`
13
+ * - WARN messages route to `console.warn`
14
+ * - DEBUG and INFO messages route to `console.log`
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { createLogger, LogLevel } from '@a2a-wrapper/core';
19
+ *
20
+ * const logger = createLogger('a2a-copilot');
21
+ * logger.setLevel(LogLevel.DEBUG);
22
+ *
23
+ * const child = logger.child('session');
24
+ * child.info('session started', { contextId: 'abc-123' });
25
+ * // => [2024-01-15T10:30:00.000Z] [INFO] [a2a-copilot:session] session started {"contextId":"abc-123"}
26
+ * ```
27
+ */
28
+ /**
29
+ * Numeric log levels controlling message suppression.
30
+ *
31
+ * Messages are emitted only when their level is greater than or equal to the
32
+ * logger's configured minimum level. Lower numeric values represent more
33
+ * verbose output.
34
+ */
35
+ export var LogLevel;
36
+ (function (LogLevel) {
37
+ /** Verbose diagnostic output, typically disabled in production. */
38
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
39
+ /** General operational messages indicating normal behavior. */
40
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
41
+ /** Potentially harmful situations that deserve attention. */
42
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
43
+ /** Failures requiring immediate investigation. */
44
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
45
+ })(LogLevel || (LogLevel = {}));
46
+ /**
47
+ * Human-readable label for each {@link LogLevel}, used in formatted output.
48
+ *
49
+ * @internal
50
+ */
51
+ const LEVEL_NAMES = {
52
+ [LogLevel.DEBUG]: "DEBUG",
53
+ [LogLevel.INFO]: "INFO",
54
+ [LogLevel.WARN]: "WARN",
55
+ [LogLevel.ERROR]: "ERROR",
56
+ };
57
+ /**
58
+ * Structured logger with hierarchical naming and runtime level control.
59
+ *
60
+ * Each Logger instance has a `name` (used as a prefix in output) and a minimum
61
+ * {@link LogLevel}. Child loggers inherit the parent's level at creation time
62
+ * and format their name as `{parent}:{child}`.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const root = new Logger('myApp', LogLevel.DEBUG);
67
+ * const child = root.child('http');
68
+ * child.info('request received', { method: 'GET', path: '/' });
69
+ * ```
70
+ */
71
+ export class Logger {
72
+ /**
73
+ * Dot-colon-separated name identifying this logger in output.
74
+ *
75
+ * @readonly
76
+ */
77
+ name;
78
+ /**
79
+ * Current minimum log level. Messages below this level are suppressed.
80
+ */
81
+ level;
82
+ /**
83
+ * Creates a new Logger instance.
84
+ *
85
+ * @param name - Identifier included in every log line (e.g. `"a2a-copilot"` or `"a2a-copilot:session"`).
86
+ * @param level - Minimum log level; defaults to {@link LogLevel.INFO}.
87
+ */
88
+ constructor(name, level = LogLevel.INFO) {
89
+ this.name = name;
90
+ this.level = level;
91
+ }
92
+ /**
93
+ * Changes the minimum log level at runtime.
94
+ *
95
+ * All subsequent calls to {@link debug}, {@link info}, {@link warn}, and
96
+ * {@link error} will be filtered against the new level.
97
+ *
98
+ * @param level - The new minimum {@link LogLevel}.
99
+ */
100
+ setLevel(level) {
101
+ this.level = level;
102
+ }
103
+ /**
104
+ * Parses a string into a {@link LogLevel}.
105
+ *
106
+ * Matching is case-insensitive. The string `"warning"` is accepted as an
107
+ * alias for {@link LogLevel.WARN}. Unrecognized strings default to
108
+ * {@link LogLevel.INFO}.
109
+ *
110
+ * @param str - The string to parse (e.g. `"debug"`, `"WARN"`, `"error"`).
111
+ * @returns The corresponding {@link LogLevel} value.
112
+ */
113
+ static parseLevel(str) {
114
+ switch (str.toLowerCase()) {
115
+ case "debug":
116
+ return LogLevel.DEBUG;
117
+ case "warn":
118
+ case "warning":
119
+ return LogLevel.WARN;
120
+ case "error":
121
+ return LogLevel.ERROR;
122
+ default:
123
+ return LogLevel.INFO;
124
+ }
125
+ }
126
+ /**
127
+ * Creates a child logger that inherits this logger's current level.
128
+ *
129
+ * The child's name is formatted as `{parentName}:{childName}`, producing
130
+ * a colon-separated hierarchy visible in log output.
131
+ *
132
+ * @param childName - Short identifier appended to the parent name.
133
+ * @returns A new {@link Logger} instance with the composite name.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const root = createLogger('app');
138
+ * const child = root.child('db');
139
+ * const grandchild = child.child('query');
140
+ * // grandchild.name === 'app:db:query'
141
+ * ```
142
+ */
143
+ child(childName) {
144
+ return new Logger(`${this.name}:${childName}`, this.level);
145
+ }
146
+ /**
147
+ * Logs a message at {@link LogLevel.DEBUG}.
148
+ *
149
+ * @param msg - Human-readable log message.
150
+ * @param data - Optional structured data appended as JSON.
151
+ */
152
+ debug(msg, data) {
153
+ this.write(LogLevel.DEBUG, msg, data);
154
+ }
155
+ /**
156
+ * Logs a message at {@link LogLevel.INFO}.
157
+ *
158
+ * @param msg - Human-readable log message.
159
+ * @param data - Optional structured data appended as JSON.
160
+ */
161
+ info(msg, data) {
162
+ this.write(LogLevel.INFO, msg, data);
163
+ }
164
+ /**
165
+ * Logs a message at {@link LogLevel.WARN}.
166
+ *
167
+ * @param msg - Human-readable log message.
168
+ * @param data - Optional structured data appended as JSON.
169
+ */
170
+ warn(msg, data) {
171
+ this.write(LogLevel.WARN, msg, data);
172
+ }
173
+ /**
174
+ * Logs a message at {@link LogLevel.ERROR}.
175
+ *
176
+ * @param msg - Human-readable log message.
177
+ * @param data - Optional structured data appended as JSON.
178
+ */
179
+ error(msg, data) {
180
+ this.write(LogLevel.ERROR, msg, data);
181
+ }
182
+ /**
183
+ * Internal method that formats and emits a log line if the message level
184
+ * meets or exceeds the configured minimum.
185
+ *
186
+ * Output format: `[ISO_timestamp] [LEVEL] [name] message {data}`
187
+ *
188
+ * Routing:
189
+ * - {@link LogLevel.ERROR} → `console.error`
190
+ * - {@link LogLevel.WARN} → `console.warn`
191
+ * - All others → `console.log`
192
+ *
193
+ * @param level - The severity level of this message.
194
+ * @param msg - Human-readable log message.
195
+ * @param data - Optional structured data serialized as JSON.
196
+ *
197
+ * @internal
198
+ */
199
+ write(level, msg, data) {
200
+ if (level < this.level)
201
+ return;
202
+ const ts = new Date().toISOString();
203
+ const prefix = `[${ts}] [${LEVEL_NAMES[level]}] [${this.name}]`;
204
+ const line = data
205
+ ? `${prefix} ${msg} ${JSON.stringify(data)}`
206
+ : `${prefix} ${msg}`;
207
+ if (level === LogLevel.ERROR) {
208
+ console.error(line);
209
+ }
210
+ else if (level === LogLevel.WARN) {
211
+ console.warn(line);
212
+ }
213
+ else {
214
+ console.log(line);
215
+ }
216
+ }
217
+ }
218
+ /**
219
+ * Creates a new root {@link Logger} instance with the given name.
220
+ *
221
+ * This is the recommended entry point for obtaining a logger. Each wrapper
222
+ * project should call this once with its own root name, then use
223
+ * {@link Logger.child} to create scoped loggers for subsystems.
224
+ *
225
+ * Unlike a singleton, this factory allows multiple independent logger
226
+ * hierarchies to coexist — one per wrapper project or test suite.
227
+ *
228
+ * @param rootName - The root identifier for the logger hierarchy
229
+ * (e.g. `"a2a-copilot"`, `"a2a-opencode"`).
230
+ * @returns A new {@link Logger} instance with the default level {@link LogLevel.INFO}.
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * import { createLogger } from '@a2a-wrapper/core';
235
+ *
236
+ * const logger = createLogger('a2a-copilot');
237
+ * const sessionLog = logger.child('session');
238
+ * sessionLog.info('ready');
239
+ * ```
240
+ */
241
+ export function createLogger(rootName) {
242
+ return new Logger(rootName);
243
+ }
244
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,QASX;AATD,WAAY,QAAQ;IAClB,mEAAmE;IACnE,yCAAS,CAAA;IACT,+DAA+D;IAC/D,uCAAQ,CAAA;IACR,6DAA6D;IAC7D,uCAAQ,CAAA;IACR,kDAAkD;IAClD,yCAAS,CAAA;AACX,CAAC,EATW,QAAQ,KAAR,QAAQ,QASnB;AAED;;;;GAIG;AACH,MAAM,WAAW,GAA6B;IAC5C,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACvB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACvB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;CAC1B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,MAAM;IACjB;;;;OAIG;IACc,IAAI,CAAS;IAE9B;;OAEG;IACK,KAAK,CAAW;IAExB;;;;;OAKG;IACH,YAAY,IAAY,EAAE,QAAkB,QAAQ,CAAC,IAAI;QACvD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAe;QACtB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,UAAU,CAAC,GAAW;QAC3B,QAAQ,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC;YAC1B,KAAK,OAAO;gB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AG,IAAI,EAAE,MAAM,WAAW,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,GAAG,CAAC;QAChE,MAAM,IAAI,GAAG,IAAI;YACf,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC5C,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC;QAEvB,IAAI,KAAK,KAAK,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC7B,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;aAAM,IAAI,KAAK,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB;IAC3C,OAAO,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@a2a-wrapper/core",
3
+ "version": "1.2.0",
4
+ "description": "Shared infrastructure core for A2A protocol wrapper projects. Provides logging, configuration loading, event publishing, agent card building, server bootstrapping, session management, and CLI scaffolding.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "types": "./dist/index.d.ts",
13
+ "main": "./dist/index.js",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "typecheck": "tsc --noEmit",
20
+ "test": "vitest --run",
21
+ "clean": "rm -rf dist"
22
+ },
23
+ "peerDependencies": {
24
+ "@a2a-js/sdk": "^0.3.9",
25
+ "express": "^4.18.2",
26
+ "uuid": "^9.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "@a2a-js/sdk": "^0.3.13",
30
+ "@types/express": "^4.17.21",
31
+ "@types/node": "^20.10.0",
32
+ "@types/supertest": "^7.2.0",
33
+ "@types/uuid": "^9.0.7",
34
+ "express": "^5.2.1",
35
+ "fast-check": "^3.15.0",
36
+ "supertest": "^7.2.2",
37
+ "typescript": "^5.3.0",
38
+ "uuid": "^13.0.0",
39
+ "vitest": "^1.0.0"
40
+ },
41
+ "engines": {
42
+ "node": ">=18.0.0"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/shashikanth-gs/a2a-wrapper.git",
50
+ "directory": "packages/core"
51
+ },
52
+ "homepage": "https://github.com/shashikanth-gs/a2a-wrapper/tree/main/packages/core#readme",
53
+ "bugs": {
54
+ "url": "https://github.com/shashikanth-gs/a2a-wrapper/issues"
55
+ },
56
+ "license": "MIT"
57
+ }