@cloudbase/agent-shared 1.0.1-alpha.7 → 1.0.1-alpha.8

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/dist/index.d.mts CHANGED
@@ -2,6 +2,128 @@ import * as z from 'zod/v4';
2
2
  import * as z3 from 'zod/v3';
3
3
  import * as z4 from 'zod/v4/core';
4
4
 
5
+ /**
6
+ * Logger interface
7
+ *
8
+ * This follows the "Bring Your Own Logger" (BYOL) pattern:
9
+ * - Users can inject their own logger (Pino, Winston, console, etc.)
10
+ * - All methods are optional - if a method exists, we use it; if not, we skip it
11
+ * - The interface is a "slot" for users to plug in their logger
12
+ *
13
+ * The signature supports two common calling conventions:
14
+ * 1. Printf style (Winston/Console): logger.info("Port %d", 8080)
15
+ * 2. Structured style (Pino): logger.info({ port: 8080 }, "Server started")
16
+ */
17
+ /**
18
+ * Log method signature supporting both structured and printf-style logging.
19
+ *
20
+ * @example
21
+ * // Printf style
22
+ * logger.info("Hello %s", "world");
23
+ *
24
+ * // Structured style (Pino-compatible)
25
+ * logger.info({ userId: 123 }, "User logged in");
26
+ *
27
+ * // Simple message
28
+ * logger.info("Server started");
29
+ */
30
+ interface LogFn {
31
+ (msg: string, ...args: unknown[]): void;
32
+ (obj: object, msg?: string, ...args: unknown[]): void;
33
+ }
34
+ /**
35
+ * Logger interface - a minimal "slot" for users to plug in their logger.
36
+ *
37
+ * All methods are optional. If a method exists on the user's logger, we use it;
38
+ * if not, we simply skip it. This allows maximum compatibility with any logger.
39
+ *
40
+ * Compatible with: Pino, Winston, Bunyan, console, or any custom logger.
41
+ *
42
+ * @example
43
+ * // Inject Pino
44
+ * import pino from 'pino';
45
+ * createExpressServer({ createAgent, logger: pino() });
46
+ *
47
+ * // Inject Winston
48
+ * import winston from 'winston';
49
+ * createExpressServer({ createAgent, logger: winston.createLogger() });
50
+ *
51
+ * // Inject console (for development)
52
+ * createExpressServer({ createAgent, logger: console });
53
+ */
54
+ interface Logger {
55
+ /**
56
+ * Fatal level - system is unusable, immediate action required.
57
+ * Use for: unrecoverable errors, process about to crash.
58
+ */
59
+ fatal?: LogFn;
60
+ /**
61
+ * Error level - failures requiring attention.
62
+ * Use for: 5xx errors, unhandled exceptions, critical failures.
63
+ */
64
+ error?: LogFn;
65
+ /**
66
+ * Warn level - recoverable issues, deprecation notices.
67
+ * Use for: 4xx errors, missing config with fallback, retry attempts.
68
+ */
69
+ warn?: LogFn;
70
+ /**
71
+ * Info level - key lifecycle events (production default).
72
+ * Use for: server started, client connected, request completed.
73
+ */
74
+ info?: LogFn;
75
+ /**
76
+ * Debug level - diagnostic information for logic flow.
77
+ * Use for: request received, state changes, configuration loaded.
78
+ */
79
+ debug?: LogFn;
80
+ /**
81
+ * Trace level - extremely verbose, for library internals debugging.
82
+ * Use for: raw bytes, loop iterations, function entry/exit.
83
+ */
84
+ trace?: LogFn;
85
+ /**
86
+ * Creates a child logger with additional context.
87
+ * The child inherits all parent context and adds its own.
88
+ *
89
+ * @example
90
+ * const requestLogger = logger.child({ requestId: 'req-123' });
91
+ * requestLogger.info("Processing request"); // includes requestId in output
92
+ */
93
+ child?(bindings: Record<string, unknown>): Logger;
94
+ }
95
+ /**
96
+ * No-op logger implementation (Abstract Logging pattern).
97
+ *
98
+ * This is the default logger - it does nothing.
99
+ * This ensures:
100
+ * 1. The library is silent by default (respects user's console)
101
+ * 2. No performance overhead from console.log in production
102
+ * 3. No need for `if (logger)` checks throughout the code
103
+ *
104
+ * @example
105
+ * // Default: silent
106
+ * createExpressServer({ createAgent });
107
+ *
108
+ * // Development: see logs
109
+ * createExpressServer({ createAgent, logger: console });
110
+ *
111
+ * // Production: structured JSON logs
112
+ * import pino from 'pino';
113
+ * createExpressServer({ createAgent, logger: pino() });
114
+ */
115
+ declare const noopLogger: Logger;
116
+ /**
117
+ * Creates a console-based logger that wraps console methods.
118
+ * Useful for development when you want simple console output.
119
+ *
120
+ * Note: console.log is synchronous and blocking - avoid in high-throughput production.
121
+ *
122
+ * @example
123
+ * createExpressServer({ createAgent, logger: createConsoleLogger() });
124
+ */
125
+ declare function createConsoleLogger(): Logger;
126
+
5
127
  type Schema = z3.ZodTypeAny | z4.$ZodType;
6
128
  type ZodInfer<T> = T extends z3.ZodTypeAny ? z3.infer<T> : z4.infer<T>;
7
129
  declare function isV4Schema(schema: Schema): schema is z4.$ZodType;
@@ -124,4 +246,4 @@ type AssistantMessage = z.infer<typeof assistantMessageSchema>;
124
246
  type Tool = z.infer<typeof toolSchema>;
125
247
  type SendMessageEvent = z.infer<typeof sendMessageEventSchema>;
126
248
 
127
- export { type AssistantMessage, type ClientMessage, type Schema, type SendMessageEvent, type SendMessageInput, type SystemMessage, type Tool, type ToolMessage, type UserMessage, type ZodInfer, assistantMessageSchema, clientMessageSchema, isV4Schema, sendMessageEventSchema, sendMessageInputSchema, systemMessageSchema, toolMessageSchema, toolSchema, userMessageSchema };
249
+ export { type AssistantMessage, type ClientMessage, type LogFn, type Logger, type Schema, type SendMessageEvent, type SendMessageInput, type SystemMessage, type Tool, type ToolMessage, type UserMessage, type ZodInfer, assistantMessageSchema, clientMessageSchema, createConsoleLogger, isV4Schema, noopLogger, sendMessageEventSchema, sendMessageInputSchema, systemMessageSchema, toolMessageSchema, toolSchema, userMessageSchema };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,128 @@ import * as z from 'zod/v4';
2
2
  import * as z3 from 'zod/v3';
3
3
  import * as z4 from 'zod/v4/core';
4
4
 
5
+ /**
6
+ * Logger interface
7
+ *
8
+ * This follows the "Bring Your Own Logger" (BYOL) pattern:
9
+ * - Users can inject their own logger (Pino, Winston, console, etc.)
10
+ * - All methods are optional - if a method exists, we use it; if not, we skip it
11
+ * - The interface is a "slot" for users to plug in their logger
12
+ *
13
+ * The signature supports two common calling conventions:
14
+ * 1. Printf style (Winston/Console): logger.info("Port %d", 8080)
15
+ * 2. Structured style (Pino): logger.info({ port: 8080 }, "Server started")
16
+ */
17
+ /**
18
+ * Log method signature supporting both structured and printf-style logging.
19
+ *
20
+ * @example
21
+ * // Printf style
22
+ * logger.info("Hello %s", "world");
23
+ *
24
+ * // Structured style (Pino-compatible)
25
+ * logger.info({ userId: 123 }, "User logged in");
26
+ *
27
+ * // Simple message
28
+ * logger.info("Server started");
29
+ */
30
+ interface LogFn {
31
+ (msg: string, ...args: unknown[]): void;
32
+ (obj: object, msg?: string, ...args: unknown[]): void;
33
+ }
34
+ /**
35
+ * Logger interface - a minimal "slot" for users to plug in their logger.
36
+ *
37
+ * All methods are optional. If a method exists on the user's logger, we use it;
38
+ * if not, we simply skip it. This allows maximum compatibility with any logger.
39
+ *
40
+ * Compatible with: Pino, Winston, Bunyan, console, or any custom logger.
41
+ *
42
+ * @example
43
+ * // Inject Pino
44
+ * import pino from 'pino';
45
+ * createExpressServer({ createAgent, logger: pino() });
46
+ *
47
+ * // Inject Winston
48
+ * import winston from 'winston';
49
+ * createExpressServer({ createAgent, logger: winston.createLogger() });
50
+ *
51
+ * // Inject console (for development)
52
+ * createExpressServer({ createAgent, logger: console });
53
+ */
54
+ interface Logger {
55
+ /**
56
+ * Fatal level - system is unusable, immediate action required.
57
+ * Use for: unrecoverable errors, process about to crash.
58
+ */
59
+ fatal?: LogFn;
60
+ /**
61
+ * Error level - failures requiring attention.
62
+ * Use for: 5xx errors, unhandled exceptions, critical failures.
63
+ */
64
+ error?: LogFn;
65
+ /**
66
+ * Warn level - recoverable issues, deprecation notices.
67
+ * Use for: 4xx errors, missing config with fallback, retry attempts.
68
+ */
69
+ warn?: LogFn;
70
+ /**
71
+ * Info level - key lifecycle events (production default).
72
+ * Use for: server started, client connected, request completed.
73
+ */
74
+ info?: LogFn;
75
+ /**
76
+ * Debug level - diagnostic information for logic flow.
77
+ * Use for: request received, state changes, configuration loaded.
78
+ */
79
+ debug?: LogFn;
80
+ /**
81
+ * Trace level - extremely verbose, for library internals debugging.
82
+ * Use for: raw bytes, loop iterations, function entry/exit.
83
+ */
84
+ trace?: LogFn;
85
+ /**
86
+ * Creates a child logger with additional context.
87
+ * The child inherits all parent context and adds its own.
88
+ *
89
+ * @example
90
+ * const requestLogger = logger.child({ requestId: 'req-123' });
91
+ * requestLogger.info("Processing request"); // includes requestId in output
92
+ */
93
+ child?(bindings: Record<string, unknown>): Logger;
94
+ }
95
+ /**
96
+ * No-op logger implementation (Abstract Logging pattern).
97
+ *
98
+ * This is the default logger - it does nothing.
99
+ * This ensures:
100
+ * 1. The library is silent by default (respects user's console)
101
+ * 2. No performance overhead from console.log in production
102
+ * 3. No need for `if (logger)` checks throughout the code
103
+ *
104
+ * @example
105
+ * // Default: silent
106
+ * createExpressServer({ createAgent });
107
+ *
108
+ * // Development: see logs
109
+ * createExpressServer({ createAgent, logger: console });
110
+ *
111
+ * // Production: structured JSON logs
112
+ * import pino from 'pino';
113
+ * createExpressServer({ createAgent, logger: pino() });
114
+ */
115
+ declare const noopLogger: Logger;
116
+ /**
117
+ * Creates a console-based logger that wraps console methods.
118
+ * Useful for development when you want simple console output.
119
+ *
120
+ * Note: console.log is synchronous and blocking - avoid in high-throughput production.
121
+ *
122
+ * @example
123
+ * createExpressServer({ createAgent, logger: createConsoleLogger() });
124
+ */
125
+ declare function createConsoleLogger(): Logger;
126
+
5
127
  type Schema = z3.ZodTypeAny | z4.$ZodType;
6
128
  type ZodInfer<T> = T extends z3.ZodTypeAny ? z3.infer<T> : z4.infer<T>;
7
129
  declare function isV4Schema(schema: Schema): schema is z4.$ZodType;
@@ -124,4 +246,4 @@ type AssistantMessage = z.infer<typeof assistantMessageSchema>;
124
246
  type Tool = z.infer<typeof toolSchema>;
125
247
  type SendMessageEvent = z.infer<typeof sendMessageEventSchema>;
126
248
 
127
- export { type AssistantMessage, type ClientMessage, type Schema, type SendMessageEvent, type SendMessageInput, type SystemMessage, type Tool, type ToolMessage, type UserMessage, type ZodInfer, assistantMessageSchema, clientMessageSchema, isV4Schema, sendMessageEventSchema, sendMessageInputSchema, systemMessageSchema, toolMessageSchema, toolSchema, userMessageSchema };
249
+ export { type AssistantMessage, type ClientMessage, type LogFn, type Logger, type Schema, type SendMessageEvent, type SendMessageInput, type SystemMessage, type Tool, type ToolMessage, type UserMessage, type ZodInfer, assistantMessageSchema, clientMessageSchema, createConsoleLogger, isV4Schema, noopLogger, sendMessageEventSchema, sendMessageInputSchema, systemMessageSchema, toolMessageSchema, toolSchema, userMessageSchema };
package/dist/index.js CHANGED
@@ -32,7 +32,9 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  assistantMessageSchema: () => assistantMessageSchema,
34
34
  clientMessageSchema: () => clientMessageSchema,
35
+ createConsoleLogger: () => createConsoleLogger,
35
36
  isV4Schema: () => isV4Schema,
37
+ noopLogger: () => noopLogger,
36
38
  sendMessageEventSchema: () => sendMessageEventSchema,
37
39
  sendMessageInputSchema: () => sendMessageInputSchema,
38
40
  systemMessageSchema: () => systemMessageSchema,
@@ -42,6 +44,60 @@ __export(index_exports, {
42
44
  });
43
45
  module.exports = __toCommonJS(index_exports);
44
46
  var z = __toESM(require("zod/v4"));
47
+
48
+ // src/logger.ts
49
+ var noop = (_msgOrObj, ..._args) => {
50
+ };
51
+ var noopLogger = {
52
+ fatal: noop,
53
+ error: noop,
54
+ warn: noop,
55
+ info: noop,
56
+ debug: noop,
57
+ trace: noop,
58
+ child: () => noopLogger
59
+ };
60
+ function createConsoleLogger() {
61
+ return createChildConsoleLogger({});
62
+ }
63
+ function createChildConsoleLogger(bindings) {
64
+ const hasBindings = Object.keys(bindings).length > 0;
65
+ function createLogMethod(level) {
66
+ const consoleMethod = level === "fatal" ? "error" : level === "trace" ? "debug" : level;
67
+ const consoleFn = console[consoleMethod] || console.log;
68
+ const prefix = `[${level.toUpperCase()}]`;
69
+ return (msgOrObj, ...args) => {
70
+ if (typeof msgOrObj === "string") {
71
+ if (hasBindings) {
72
+ consoleFn(prefix, bindings, msgOrObj, ...args);
73
+ } else {
74
+ consoleFn(prefix, msgOrObj, ...args);
75
+ }
76
+ } else {
77
+ const [msg, ...restArgs] = args;
78
+ const mergedObj = hasBindings ? { ...bindings, ...msgOrObj } : msgOrObj;
79
+ if (msg) {
80
+ consoleFn(prefix, mergedObj, msg, ...restArgs);
81
+ } else {
82
+ consoleFn(prefix, mergedObj);
83
+ }
84
+ }
85
+ };
86
+ }
87
+ return {
88
+ fatal: createLogMethod("fatal"),
89
+ error: createLogMethod("error"),
90
+ warn: createLogMethod("warn"),
91
+ info: createLogMethod("info"),
92
+ debug: createLogMethod("debug"),
93
+ trace: createLogMethod("trace"),
94
+ child: (newBindings) => {
95
+ return createChildConsoleLogger({ ...bindings, ...newBindings });
96
+ }
97
+ };
98
+ }
99
+
100
+ // src/index.ts
45
101
  function isV4Schema(schema) {
46
102
  return "_zod" in schema;
47
103
  }
@@ -127,7 +183,9 @@ var sendMessageEventSchema = z.union([
127
183
  0 && (module.exports = {
128
184
  assistantMessageSchema,
129
185
  clientMessageSchema,
186
+ createConsoleLogger,
130
187
  isV4Schema,
188
+ noopLogger,
131
189
  sendMessageEventSchema,
132
190
  sendMessageInputSchema,
133
191
  systemMessageSchema,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import * as z from \"zod/v4\";\nimport * as z3 from \"zod/v3\";\nimport * as z4 from \"zod/v4/core\";\n\n// https://zod.dev/library-authors#how-to-support-zod-3-and-zod-4-simultaneously\nexport type Schema = z3.ZodTypeAny | z4.$ZodType;\nexport type ZodInfer<T> = T extends z3.ZodTypeAny ? z3.infer<T> : z4.infer<T>;\nexport function isV4Schema(schema: Schema): schema is z4.$ZodType {\n return \"_zod\" in schema;\n}\n\nexport const systemMessageSchema = z.object({\n role: z.literal(\"system\"),\n content: z.string(),\n});\n\nexport const userMessageSchema = z.object({\n role: z.literal(\"user\"),\n content: z.string(),\n});\n\nexport const toolMessageSchema = z.object({\n role: z.literal(\"tool\"),\n content: z.string(),\n toolCallId: z.string(),\n});\n\nexport const assistantMessageSchema = z.object({\n role: z.literal(\"assistant\"),\n content: z.string().optional(),\n toolCalls: z\n .array(\n z.object({\n id: z.string(),\n type: z.literal(\"function\"),\n function: z.object({\n name: z.string(),\n arguments: z.string(),\n }),\n })\n )\n .optional(),\n});\n\nexport const clientMessageSchema = z.union([\n systemMessageSchema,\n userMessageSchema,\n toolMessageSchema,\n assistantMessageSchema,\n]);\n\nexport const toolSchema = z.object({\n name: z.string(),\n description: z.string(),\n parameters: z.any(),\n});\n\nexport const sendMessageInputSchema = z.object({\n conversationId: z.string(),\n messages: z.array(clientMessageSchema).optional(),\n resume: z\n .object({\n interruptId: z.string(),\n payload: z.any(),\n })\n .optional(),\n tools: z.array(toolSchema).optional(),\n});\n\nexport const sendMessageEventSchema = z.union([\n z.object({\n type: z.literal(\"text\"),\n content: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-call-start\"),\n toolCallId: z.string(),\n toolCallName: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-call-args\"),\n toolCallId: z.string(),\n delta: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-call-end\"),\n toolCallId: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-result\"),\n toolCallId: z.string(),\n result: z.string(),\n }),\n z.object({\n type: z.literal(\"interrupt\"),\n id: z.string(),\n reason: z.string(),\n payload: z.any(),\n }),\n]);\n\nexport type SendMessageInput = z.infer<typeof sendMessageInputSchema>;\nexport type ClientMessage = z.infer<typeof clientMessageSchema>;\nexport type SystemMessage = z.infer<typeof systemMessageSchema>;\nexport type UserMessage = z.infer<typeof userMessageSchema>;\nexport type ToolMessage = z.infer<typeof toolMessageSchema>;\nexport type AssistantMessage = z.infer<typeof assistantMessageSchema>;\nexport type Tool = z.infer<typeof toolSchema>;\nexport type SendMessageEvent = z.infer<typeof sendMessageEventSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAAmB;AAOZ,SAAS,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AAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,iBAAiB;AAAA,IACjC,YAAc,SAAO;AAAA,IACrB,cAAgB,SAAO;AAAA,EACzB,CAAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,gBAAgB;AAAA,IAChC,YAAc,SAAO;AAAA,IACrB,OAAS,SAAO;AAAA,EAClB,CAAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,eAAe;AAAA,IAC/B,YAAc,SAAO;AAAA,EACvB,CAAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,aAAa;AAAA,IAC7B,YAAc,SAAO;AAAA,IACrB,QAAU,SAAO;AAAA,EACnB,CAAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,WAAW;AAAA,IAC3B,IAAM,SAAO;AAAA,IACb,QAAU,SAAO;AAAA,IACjB,SAAW,MAAI;AAAA,EACjB,CAAC;AACH,CAAC;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/logger.ts"],"sourcesContent":["import * as z from \"zod/v4\";\nimport * as z3 from \"zod/v3\";\nimport * as z4 from \"zod/v4/core\";\n\n// Logger exports\nexport { type Logger, type LogFn, noopLogger, createConsoleLogger } from \"./logger\";\n\n// https://zod.dev/library-authors#how-to-support-zod-3-and-zod-4-simultaneously\nexport type Schema = z3.ZodTypeAny | z4.$ZodType;\nexport type ZodInfer<T> = T extends z3.ZodTypeAny ? z3.infer<T> : z4.infer<T>;\nexport function isV4Schema(schema: Schema): schema is z4.$ZodType {\n return \"_zod\" in schema;\n}\n\nexport const systemMessageSchema = z.object({\n role: z.literal(\"system\"),\n content: z.string(),\n});\n\nexport const userMessageSchema = z.object({\n role: z.literal(\"user\"),\n content: z.string(),\n});\n\nexport const toolMessageSchema = z.object({\n role: z.literal(\"tool\"),\n content: z.string(),\n toolCallId: z.string(),\n});\n\nexport const assistantMessageSchema = z.object({\n role: z.literal(\"assistant\"),\n content: z.string().optional(),\n toolCalls: z\n .array(\n z.object({\n id: z.string(),\n type: z.literal(\"function\"),\n function: z.object({\n name: z.string(),\n arguments: z.string(),\n }),\n })\n )\n .optional(),\n});\n\nexport const clientMessageSchema = z.union([\n systemMessageSchema,\n userMessageSchema,\n toolMessageSchema,\n assistantMessageSchema,\n]);\n\nexport const toolSchema = z.object({\n name: z.string(),\n description: z.string(),\n parameters: z.any(),\n});\n\nexport const sendMessageInputSchema = z.object({\n conversationId: z.string(),\n messages: z.array(clientMessageSchema).optional(),\n resume: z\n .object({\n interruptId: z.string(),\n payload: z.any(),\n })\n .optional(),\n tools: z.array(toolSchema).optional(),\n});\n\nexport const sendMessageEventSchema = z.union([\n z.object({\n type: z.literal(\"text\"),\n content: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-call-start\"),\n toolCallId: z.string(),\n toolCallName: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-call-args\"),\n toolCallId: z.string(),\n delta: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-call-end\"),\n toolCallId: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-result\"),\n toolCallId: z.string(),\n result: z.string(),\n }),\n z.object({\n type: z.literal(\"interrupt\"),\n id: z.string(),\n reason: z.string(),\n payload: z.any(),\n }),\n]);\n\nexport type SendMessageInput = z.infer<typeof sendMessageInputSchema>;\nexport type ClientMessage = z.infer<typeof clientMessageSchema>;\nexport type SystemMessage = z.infer<typeof systemMessageSchema>;\nexport type UserMessage = z.infer<typeof userMessageSchema>;\nexport type ToolMessage = z.infer<typeof toolMessageSchema>;\nexport type AssistantMessage = z.infer<typeof assistantMessageSchema>;\nexport type Tool = z.infer<typeof toolSchema>;\nexport type SendMessageEvent = z.infer<typeof sendMessageEventSchema>;\n","/**\n * Logger interface\n *\n * This follows the \"Bring Your Own Logger\" (BYOL) pattern:\n * - Users can inject their own logger (Pino, Winston, console, etc.)\n * - All methods are optional - if a method exists, we use it; if not, we skip it\n * - The interface is a \"slot\" for users to plug in their logger\n *\n * The signature supports two common calling conventions:\n * 1. Printf style (Winston/Console): logger.info(\"Port %d\", 8080)\n * 2. Structured style (Pino): logger.info({ port: 8080 }, \"Server started\")\n */\n\n/**\n * Log method signature supporting both structured and printf-style logging.\n *\n * @example\n * // Printf style\n * logger.info(\"Hello %s\", \"world\");\n *\n * // Structured style (Pino-compatible)\n * logger.info({ userId: 123 }, \"User logged in\");\n *\n * // Simple message\n * logger.info(\"Server started\");\n */\nexport interface LogFn {\n // Printf style: message with format args\n (msg: string, ...args: unknown[]): void;\n // Structured style: object with optional message and format args\n (obj: object, msg?: string, ...args: unknown[]): void;\n}\n\n/**\n * Logger interface - a minimal \"slot\" for users to plug in their logger.\n *\n * All methods are optional. If a method exists on the user's logger, we use it;\n * if not, we simply skip it. This allows maximum compatibility with any logger.\n *\n * Compatible with: Pino, Winston, Bunyan, console, or any custom logger.\n *\n * @example\n * // Inject Pino\n * import pino from 'pino';\n * createExpressServer({ createAgent, logger: pino() });\n *\n * // Inject Winston\n * import winston from 'winston';\n * createExpressServer({ createAgent, logger: winston.createLogger() });\n *\n * // Inject console (for development)\n * createExpressServer({ createAgent, logger: console });\n */\nexport interface Logger {\n /**\n * Fatal level - system is unusable, immediate action required.\n * Use for: unrecoverable errors, process about to crash.\n */\n fatal?: LogFn;\n\n /**\n * Error level - failures requiring attention.\n * Use for: 5xx errors, unhandled exceptions, critical failures.\n */\n error?: LogFn;\n\n /**\n * Warn level - recoverable issues, deprecation notices.\n * Use for: 4xx errors, missing config with fallback, retry attempts.\n */\n warn?: LogFn;\n\n /**\n * Info level - key lifecycle events (production default).\n * Use for: server started, client connected, request completed.\n */\n info?: LogFn;\n\n /**\n * Debug level - diagnostic information for logic flow.\n * Use for: request received, state changes, configuration loaded.\n */\n debug?: LogFn;\n\n /**\n * Trace level - extremely verbose, for library internals debugging.\n * Use for: raw bytes, loop iterations, function entry/exit.\n */\n trace?: LogFn;\n\n /**\n * Creates a child logger with additional context.\n * The child inherits all parent context and adds its own.\n *\n * @example\n * const requestLogger = logger.child({ requestId: 'req-123' });\n * requestLogger.info(\"Processing request\"); // includes requestId in output\n */\n child?(bindings: Record<string, unknown>): Logger;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst noop: LogFn = (_msgOrObj: unknown, ..._args: unknown[]) => {};\n\n/**\n * No-op logger implementation (Abstract Logging pattern).\n *\n * This is the default logger - it does nothing.\n * This ensures:\n * 1. The library is silent by default (respects user's console)\n * 2. No performance overhead from console.log in production\n * 3. No need for `if (logger)` checks throughout the code\n *\n * @example\n * // Default: silent\n * createExpressServer({ createAgent });\n *\n * // Development: see logs\n * createExpressServer({ createAgent, logger: console });\n *\n * // Production: structured JSON logs\n * import pino from 'pino';\n * createExpressServer({ createAgent, logger: pino() });\n */\nexport const noopLogger: Logger = {\n fatal: noop,\n error: noop,\n warn: noop,\n info: noop,\n debug: noop,\n trace: noop,\n child: () => noopLogger,\n};\n\n/**\n * Creates a console-based logger that wraps console methods.\n * Useful for development when you want simple console output.\n *\n * Note: console.log is synchronous and blocking - avoid in high-throughput production.\n *\n * @example\n * createExpressServer({ createAgent, logger: createConsoleLogger() });\n */\nexport function createConsoleLogger(): Logger {\n return createChildConsoleLogger({});\n}\n\nfunction createChildConsoleLogger(bindings: Record<string, unknown>): Logger {\n const hasBindings = Object.keys(bindings).length > 0;\n\n function createLogMethod(\n level: \"fatal\" | \"error\" | \"warn\" | \"info\" | \"debug\" | \"trace\"\n ): LogFn {\n // Map fatal to error, trace to debug for console\n const consoleMethod =\n level === \"fatal\"\n ? \"error\"\n : level === \"trace\"\n ? \"debug\"\n : level;\n const consoleFn = console[consoleMethod] || console.log;\n const prefix = `[${level.toUpperCase()}]`;\n\n return (msgOrObj: unknown, ...args: unknown[]) => {\n if (typeof msgOrObj === \"string\") {\n // Printf style: logger.info(\"Hello %s\", \"world\")\n if (hasBindings) {\n consoleFn(prefix, bindings, msgOrObj, ...args);\n } else {\n consoleFn(prefix, msgOrObj, ...args);\n }\n } else {\n // Structured style: logger.info({ userId: 1 }, \"User logged in\")\n const [msg, ...restArgs] = args;\n const mergedObj = hasBindings\n ? { ...bindings, ...(msgOrObj as object) }\n : msgOrObj;\n if (msg) {\n consoleFn(prefix, mergedObj, msg, ...restArgs);\n } else {\n consoleFn(prefix, mergedObj);\n }\n }\n };\n }\n\n return {\n fatal: createLogMethod(\"fatal\"),\n error: createLogMethod(\"error\"),\n warn: createLogMethod(\"warn\"),\n info: createLogMethod(\"info\"),\n debug: createLogMethod(\"debug\"),\n trace: createLogMethod(\"trace\"),\n child: (newBindings: Record<string, unknown>) => {\n return createChildConsoleLogger({ ...bindings, ...newBindings });\n },\n };\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAAmB;;;ACsGnB,IAAM,OAAc,CAAC,cAAuB,UAAqB;AAAC;AAsB3D,IAAM,aAAqB;AAAA,EAChC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO,MAAM;AACf;AAWO,SAAS,sBAA8B;AAC5C,SAAO,yBAAyB,CAAC,CAAC;AACpC;AAEA,SAAS,yBAAyB,UAA2C;AAC3E,QAAM,cAAc,OAAO,KAAK,QAAQ,EAAE,SAAS;AAEnD,WAAS,gBACP,OACO;AAEP,UAAM,gBACJ,UAAU,UACN,UACA,UAAU,UACR,UACA;AACR,UAAM,YAAY,QAAQ,aAAa,KAAK,QAAQ;AACpD,UAAM,SAAS,IAAI,MAAM,YAAY,CAAC;AAEtC,WAAO,CAAC,aAAsB,SAAoB;AAChD,UAAI,OAAO,aAAa,UAAU;AAEhC,YAAI,aAAa;AACf,oBAAU,QAAQ,UAAU,UAAU,GAAG,IAAI;AAAA,QAC/C,OAAO;AACL,oBAAU,QAAQ,UAAU,GAAG,IAA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names":[]}
package/dist/index.mjs CHANGED
@@ -1,5 +1,59 @@
1
1
  // src/index.ts
2
2
  import * as z from "zod/v4";
3
+
4
+ // src/logger.ts
5
+ var noop = (_msgOrObj, ..._args) => {
6
+ };
7
+ var noopLogger = {
8
+ fatal: noop,
9
+ error: noop,
10
+ warn: noop,
11
+ info: noop,
12
+ debug: noop,
13
+ trace: noop,
14
+ child: () => noopLogger
15
+ };
16
+ function createConsoleLogger() {
17
+ return createChildConsoleLogger({});
18
+ }
19
+ function createChildConsoleLogger(bindings) {
20
+ const hasBindings = Object.keys(bindings).length > 0;
21
+ function createLogMethod(level) {
22
+ const consoleMethod = level === "fatal" ? "error" : level === "trace" ? "debug" : level;
23
+ const consoleFn = console[consoleMethod] || console.log;
24
+ const prefix = `[${level.toUpperCase()}]`;
25
+ return (msgOrObj, ...args) => {
26
+ if (typeof msgOrObj === "string") {
27
+ if (hasBindings) {
28
+ consoleFn(prefix, bindings, msgOrObj, ...args);
29
+ } else {
30
+ consoleFn(prefix, msgOrObj, ...args);
31
+ }
32
+ } else {
33
+ const [msg, ...restArgs] = args;
34
+ const mergedObj = hasBindings ? { ...bindings, ...msgOrObj } : msgOrObj;
35
+ if (msg) {
36
+ consoleFn(prefix, mergedObj, msg, ...restArgs);
37
+ } else {
38
+ consoleFn(prefix, mergedObj);
39
+ }
40
+ }
41
+ };
42
+ }
43
+ return {
44
+ fatal: createLogMethod("fatal"),
45
+ error: createLogMethod("error"),
46
+ warn: createLogMethod("warn"),
47
+ info: createLogMethod("info"),
48
+ debug: createLogMethod("debug"),
49
+ trace: createLogMethod("trace"),
50
+ child: (newBindings) => {
51
+ return createChildConsoleLogger({ ...bindings, ...newBindings });
52
+ }
53
+ };
54
+ }
55
+
56
+ // src/index.ts
3
57
  function isV4Schema(schema) {
4
58
  return "_zod" in schema;
5
59
  }
@@ -84,7 +138,9 @@ var sendMessageEventSchema = z.union([
84
138
  export {
85
139
  assistantMessageSchema,
86
140
  clientMessageSchema,
141
+ createConsoleLogger,
87
142
  isV4Schema,
143
+ noopLogger,
88
144
  sendMessageEventSchema,
89
145
  sendMessageInputSchema,
90
146
  systemMessageSchema,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import * as z from \"zod/v4\";\nimport * as z3 from \"zod/v3\";\nimport * as z4 from \"zod/v4/core\";\n\n// https://zod.dev/library-authors#how-to-support-zod-3-and-zod-4-simultaneously\nexport type Schema = z3.ZodTypeAny | z4.$ZodType;\nexport type ZodInfer<T> = T extends z3.ZodTypeAny ? z3.infer<T> : z4.infer<T>;\nexport function isV4Schema(schema: Schema): schema is z4.$ZodType {\n return \"_zod\" in schema;\n}\n\nexport const systemMessageSchema = z.object({\n role: z.literal(\"system\"),\n content: z.string(),\n});\n\nexport const userMessageSchema = z.object({\n role: z.literal(\"user\"),\n content: z.string(),\n});\n\nexport const toolMessageSchema = z.object({\n role: z.literal(\"tool\"),\n content: z.string(),\n toolCallId: z.string(),\n});\n\nexport const assistantMessageSchema = z.object({\n role: z.literal(\"assistant\"),\n content: z.string().optional(),\n toolCalls: z\n .array(\n z.object({\n id: z.string(),\n type: z.literal(\"function\"),\n function: z.object({\n name: z.string(),\n arguments: z.string(),\n }),\n })\n )\n .optional(),\n});\n\nexport const clientMessageSchema = z.union([\n systemMessageSchema,\n userMessageSchema,\n toolMessageSchema,\n assistantMessageSchema,\n]);\n\nexport const toolSchema = z.object({\n name: z.string(),\n description: z.string(),\n parameters: z.any(),\n});\n\nexport const sendMessageInputSchema = z.object({\n conversationId: z.string(),\n messages: z.array(clientMessageSchema).optional(),\n resume: z\n .object({\n interruptId: z.string(),\n payload: z.any(),\n })\n .optional(),\n tools: z.array(toolSchema).optional(),\n});\n\nexport const sendMessageEventSchema = z.union([\n z.object({\n type: z.literal(\"text\"),\n content: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-call-start\"),\n toolCallId: z.string(),\n toolCallName: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-call-args\"),\n toolCallId: z.string(),\n delta: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-call-end\"),\n toolCallId: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-result\"),\n toolCallId: z.string(),\n result: z.string(),\n }),\n z.object({\n type: z.literal(\"interrupt\"),\n id: z.string(),\n reason: z.string(),\n payload: z.any(),\n }),\n]);\n\nexport type SendMessageInput = z.infer<typeof sendMessageInputSchema>;\nexport type ClientMessage = z.infer<typeof clientMessageSchema>;\nexport type SystemMessage = z.infer<typeof systemMessageSchema>;\nexport type UserMessage = z.infer<typeof userMessageSchema>;\nexport type ToolMessage = z.infer<typeof toolMessageSchema>;\nexport type AssistantMessage = z.infer<typeof assistantMessageSchema>;\nexport type Tool = z.infer<typeof toolSchema>;\nexport type SendMessageEvent = z.infer<typeof sendMessageEventSchema>;\n"],"mappings":";AAAA,YAAY,OAAO;AAOZ,SAAS,WAAW,QAAuC;AAChE,SAAO,UAAU;AACnB;AAEO,IAAM,sBAAwB,SAAO;AAAA,EAC1C,MAAQ,UAAQ,QAAQ;AAAA,EACxB,SAAW,SAAO;AACpB,CAAC;AAEM,IAAM,oBAAsB,SAAO;AAAA,EACxC,MAAQ,UAAQ,MAAM;AAAA,EACtB,SAAW,SAAO;AACpB,CAAC;AAEM,IAAM,oBAAsB,SAAO;AAAA,EACxC,MAAQ,UAAQ,MAAM;AAAA,EACtB,SAAW,SAAO;AAAA,EAClB,YAAc,SAAO;AACvB,CAAC;AAEM,IAAM,yBAA2B,SAAO;AAAA,EAC7C,MAAQ,UAAQ,WAAW;AAAA,EAC3B,SAAW,SAAO,EAAE,SAAS;AAAA,EAC7B,WACG;AAAA,IACG,SAAO;AAAA,MACP,IAAM,SAAO;AAAA,MACb,MAAQ,UAAQ,UAAU;AAAA,MAC1B,UAAY,SAAO;AAAA,QACjB,MAAQ,SAAO;AAAA,QACf,WAAa,SAAO;AAAA,MACtB,CAAC;AAAA,IACH,CAAC;AAAA,EACH,EACC,SAAS;AACd,CAAC;AAEM,IAAM,sBAAwB,QAAM;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,aAAe,SAAO;AAAA,EACjC,MAAQ,SAAO;AAAA,EACf,aAAe,SAAO;AAAA,EACtB,YAAc,MAAI;AACpB,CAAC;AAEM,IAAM,yBAA2B,SAAO;AAAA,EAC7C,gBAAkB,SAAO;AAAA,EACzB,UAAY,QAAM,mBAAmB,EAAE,SAAS;AAAA,EAChD,QACG,SAAO;AAAA,IACN,aAAe,SAAO;AAAA,IACtB,SAAW,MAAI;AAAA,EACjB,CAAC,EACA,SAAS;AAAA,EACZ,OAAS,QAAM,UAAU,EAAE,SAAS;AACtC,CAAC;AAEM,IAAM,yBAA2B,QAAM;AAAA,EAC1C,SAAO;AAAA,IACP,MAAQ,UAAQ,MAAM;AAAA,IACtB,SAAW,SAAO;AAAA,EACpB,CAAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,iBAAiB;AAAA,IACjC,YAAc,SAAO;AAAA,IACrB,cAAgB,SAAO;AAAA,EACzB,CAAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,gBAAgB;AAAA,IAChC,YAAc,SAAO;AAAA,IACrB,OAAS,SAAO;AAAA,EAClB,CAAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,eAAe;AAAA,IAC/B,YAAc,SAAO;AAAA,EACvB,CAAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,aAAa;AAAA,IAC7B,YAAc,SAAO;AAAA,IACrB,QAAU,SAAO;AAAA,EACnB,CAAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,WAAW;AAAA,IAC3B,IAAM,SAAO;AAAA,IACb,QAAU,SAAO;AAAA,IACjB,SAAW,MAAI;AAAA,EACjB,CAAC;AACH,CAAC;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/logger.ts"],"sourcesContent":["import * as z from \"zod/v4\";\nimport * as z3 from \"zod/v3\";\nimport * as z4 from \"zod/v4/core\";\n\n// Logger exports\nexport { type Logger, type LogFn, noopLogger, createConsoleLogger } from \"./logger\";\n\n// https://zod.dev/library-authors#how-to-support-zod-3-and-zod-4-simultaneously\nexport type Schema = z3.ZodTypeAny | z4.$ZodType;\nexport type ZodInfer<T> = T extends z3.ZodTypeAny ? z3.infer<T> : z4.infer<T>;\nexport function isV4Schema(schema: Schema): schema is z4.$ZodType {\n return \"_zod\" in schema;\n}\n\nexport const systemMessageSchema = z.object({\n role: z.literal(\"system\"),\n content: z.string(),\n});\n\nexport const userMessageSchema = z.object({\n role: z.literal(\"user\"),\n content: z.string(),\n});\n\nexport const toolMessageSchema = z.object({\n role: z.literal(\"tool\"),\n content: z.string(),\n toolCallId: z.string(),\n});\n\nexport const assistantMessageSchema = z.object({\n role: z.literal(\"assistant\"),\n content: z.string().optional(),\n toolCalls: z\n .array(\n z.object({\n id: z.string(),\n type: z.literal(\"function\"),\n function: z.object({\n name: z.string(),\n arguments: z.string(),\n }),\n })\n )\n .optional(),\n});\n\nexport const clientMessageSchema = z.union([\n systemMessageSchema,\n userMessageSchema,\n toolMessageSchema,\n assistantMessageSchema,\n]);\n\nexport const toolSchema = z.object({\n name: z.string(),\n description: z.string(),\n parameters: z.any(),\n});\n\nexport const sendMessageInputSchema = z.object({\n conversationId: z.string(),\n messages: z.array(clientMessageSchema).optional(),\n resume: z\n .object({\n interruptId: z.string(),\n payload: z.any(),\n })\n .optional(),\n tools: z.array(toolSchema).optional(),\n});\n\nexport const sendMessageEventSchema = z.union([\n z.object({\n type: z.literal(\"text\"),\n content: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-call-start\"),\n toolCallId: z.string(),\n toolCallName: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-call-args\"),\n toolCallId: z.string(),\n delta: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-call-end\"),\n toolCallId: z.string(),\n }),\n z.object({\n type: z.literal(\"tool-result\"),\n toolCallId: z.string(),\n result: z.string(),\n }),\n z.object({\n type: z.literal(\"interrupt\"),\n id: z.string(),\n reason: z.string(),\n payload: z.any(),\n }),\n]);\n\nexport type SendMessageInput = z.infer<typeof sendMessageInputSchema>;\nexport type ClientMessage = z.infer<typeof clientMessageSchema>;\nexport type SystemMessage = z.infer<typeof systemMessageSchema>;\nexport type UserMessage = z.infer<typeof userMessageSchema>;\nexport type ToolMessage = z.infer<typeof toolMessageSchema>;\nexport type AssistantMessage = z.infer<typeof assistantMessageSchema>;\nexport type Tool = z.infer<typeof toolSchema>;\nexport type SendMessageEvent = z.infer<typeof sendMessageEventSchema>;\n","/**\n * Logger interface\n *\n * This follows the \"Bring Your Own Logger\" (BYOL) pattern:\n * - Users can inject their own logger (Pino, Winston, console, etc.)\n * - All methods are optional - if a method exists, we use it; if not, we skip it\n * - The interface is a \"slot\" for users to plug in their logger\n *\n * The signature supports two common calling conventions:\n * 1. Printf style (Winston/Console): logger.info(\"Port %d\", 8080)\n * 2. Structured style (Pino): logger.info({ port: 8080 }, \"Server started\")\n */\n\n/**\n * Log method signature supporting both structured and printf-style logging.\n *\n * @example\n * // Printf style\n * logger.info(\"Hello %s\", \"world\");\n *\n * // Structured style (Pino-compatible)\n * logger.info({ userId: 123 }, \"User logged in\");\n *\n * // Simple message\n * logger.info(\"Server started\");\n */\nexport interface LogFn {\n // Printf style: message with format args\n (msg: string, ...args: unknown[]): void;\n // Structured style: object with optional message and format args\n (obj: object, msg?: string, ...args: unknown[]): void;\n}\n\n/**\n * Logger interface - a minimal \"slot\" for users to plug in their logger.\n *\n * All methods are optional. If a method exists on the user's logger, we use it;\n * if not, we simply skip it. This allows maximum compatibility with any logger.\n *\n * Compatible with: Pino, Winston, Bunyan, console, or any custom logger.\n *\n * @example\n * // Inject Pino\n * import pino from 'pino';\n * createExpressServer({ createAgent, logger: pino() });\n *\n * // Inject Winston\n * import winston from 'winston';\n * createExpressServer({ createAgent, logger: winston.createLogger() });\n *\n * // Inject console (for development)\n * createExpressServer({ createAgent, logger: console });\n */\nexport interface Logger {\n /**\n * Fatal level - system is unusable, immediate action required.\n * Use for: unrecoverable errors, process about to crash.\n */\n fatal?: LogFn;\n\n /**\n * Error level - failures requiring attention.\n * Use for: 5xx errors, unhandled exceptions, critical failures.\n */\n error?: LogFn;\n\n /**\n * Warn level - recoverable issues, deprecation notices.\n * Use for: 4xx errors, missing config with fallback, retry attempts.\n */\n warn?: LogFn;\n\n /**\n * Info level - key lifecycle events (production default).\n * Use for: server started, client connected, request completed.\n */\n info?: LogFn;\n\n /**\n * Debug level - diagnostic information for logic flow.\n * Use for: request received, state changes, configuration loaded.\n */\n debug?: LogFn;\n\n /**\n * Trace level - extremely verbose, for library internals debugging.\n * Use for: raw bytes, loop iterations, function entry/exit.\n */\n trace?: LogFn;\n\n /**\n * Creates a child logger with additional context.\n * The child inherits all parent context and adds its own.\n *\n * @example\n * const requestLogger = logger.child({ requestId: 'req-123' });\n * requestLogger.info(\"Processing request\"); // includes requestId in output\n */\n child?(bindings: Record<string, unknown>): Logger;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst noop: LogFn = (_msgOrObj: unknown, ..._args: unknown[]) => {};\n\n/**\n * No-op logger implementation (Abstract Logging pattern).\n *\n * This is the default logger - it does nothing.\n * This ensures:\n * 1. The library is silent by default (respects user's console)\n * 2. No performance overhead from console.log in production\n * 3. No need for `if (logger)` checks throughout the code\n *\n * @example\n * // Default: silent\n * createExpressServer({ createAgent });\n *\n * // Development: see logs\n * createExpressServer({ createAgent, logger: console });\n *\n * // Production: structured JSON logs\n * import pino from 'pino';\n * createExpressServer({ createAgent, logger: pino() });\n */\nexport const noopLogger: Logger = {\n fatal: noop,\n error: noop,\n warn: noop,\n info: noop,\n debug: noop,\n trace: noop,\n child: () => noopLogger,\n};\n\n/**\n * Creates a console-based logger that wraps console methods.\n * Useful for development when you want simple console output.\n *\n * Note: console.log is synchronous and blocking - avoid in high-throughput production.\n *\n * @example\n * createExpressServer({ createAgent, logger: createConsoleLogger() });\n */\nexport function createConsoleLogger(): Logger {\n return createChildConsoleLogger({});\n}\n\nfunction createChildConsoleLogger(bindings: Record<string, unknown>): Logger {\n const hasBindings = Object.keys(bindings).length > 0;\n\n function createLogMethod(\n level: \"fatal\" | \"error\" | \"warn\" | \"info\" | \"debug\" | \"trace\"\n ): LogFn {\n // Map fatal to error, trace to debug for console\n const consoleMethod =\n level === \"fatal\"\n ? \"error\"\n : level === \"trace\"\n ? \"debug\"\n : level;\n const consoleFn = console[consoleMethod] || console.log;\n const prefix = `[${level.toUpperCase()}]`;\n\n return (msgOrObj: unknown, ...args: unknown[]) => {\n if (typeof msgOrObj === \"string\") {\n // Printf style: logger.info(\"Hello %s\", \"world\")\n if (hasBindings) {\n consoleFn(prefix, bindings, msgOrObj, ...args);\n } else {\n consoleFn(prefix, msgOrObj, ...args);\n }\n } else {\n // Structured style: logger.info({ userId: 1 }, \"User logged in\")\n const [msg, ...restArgs] = args;\n const mergedObj = hasBindings\n ? { ...bindings, ...(msgOrObj as object) }\n : msgOrObj;\n if (msg) {\n consoleFn(prefix, mergedObj, msg, ...restArgs);\n } else {\n consoleFn(prefix, mergedObj);\n }\n }\n };\n }\n\n return {\n fatal: createLogMethod(\"fatal\"),\n error: createLogMethod(\"error\"),\n warn: createLogMethod(\"warn\"),\n info: createLogMethod(\"info\"),\n debug: createLogMethod(\"debug\"),\n trace: createLogMethod(\"trace\"),\n child: (newBindings: Record<string, unknown>) => {\n return createChildConsoleLogger({ ...bindings, ...newBindings });\n },\n };\n}\n\n"],"mappings":";AAAA,YAAY,OAAO;;;ACsGnB,IAAM,OAAc,CAAC,cAAuB,UAAqB;AAAC;AAsB3D,IAAM,aAAqB;AAAA,EAChC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO,MAAM;AACf;AAWO,SAAS,sBAA8B;AAC5C,SAAO,yBAAyB,CAAC,CAAC;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;AAAA,IAChC,YAAc,SAAO;AAAA,IACrB,OAAS,SAAO;AAAA,EAClB,CAAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,eAAe;AAAA,IAC/B,YAAc,SAAO;AAAA,EACvB,CAAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,aAAa;AAAA,IAC7B,YAAc,SAAO;AAAA,IACrB,QAAU,SAAO;AAAA,EACnB,CAAC;AAAA,EACC,SAAO;AAAA,IACP,MAAQ,UAAQ,WAAW;AAAA,IAC3B,IAAM,SAAO;AAAA,IACb,QAAU,SAAO;AAAA,IACjB,SAAW,MAAI;AAAA,EACjB,CAAC;AACH,CAAC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/agent-shared",
3
- "version": "1.0.1-alpha.7",
3
+ "version": "1.0.1-alpha.8",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist/",