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

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @cloudbase/agent-shared
2
2
 
3
+ ## 1.0.1-alpha.8
4
+
5
+ ### Patch Changes
6
+
7
+ - alpha release 0.1.2-alpha.1
8
+ - Update all public packages to version 0.1.2-alpha.1
9
+ - Trigger automated alpha release workflow
10
+ - Includes latest features and improvements
11
+
12
+ ## 1.0.1-alpha.7
13
+
14
+ ### Patch Changes
15
+
16
+ - alpha release 0.1.2-alpha.1
17
+ - Update all public packages to version 0.1.2-alpha.1
18
+ - Trigger automated alpha release workflow
19
+ - Includes latest features and improvements
20
+
3
21
  ## 1.0.1-alpha.6
4
22
 
5
23
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -2,6 +2,135 @@ 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
+
127
+ /**
128
+ * Type guard to check if an error has a code property.
129
+ */
130
+ declare function isErrorWithCode(error: unknown): error is Error & {
131
+ code: string;
132
+ };
133
+
5
134
  type Schema = z3.ZodTypeAny | z4.$ZodType;
6
135
  type ZodInfer<T> = T extends z3.ZodTypeAny ? z3.infer<T> : z4.infer<T>;
7
136
  declare function isV4Schema(schema: Schema): schema is z4.$ZodType;
@@ -124,4 +253,4 @@ type AssistantMessage = z.infer<typeof assistantMessageSchema>;
124
253
  type Tool = z.infer<typeof toolSchema>;
125
254
  type SendMessageEvent = z.infer<typeof sendMessageEventSchema>;
126
255
 
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 };
256
+ 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, isErrorWithCode, isV4Schema, noopLogger, sendMessageEventSchema, sendMessageInputSchema, systemMessageSchema, toolMessageSchema, toolSchema, userMessageSchema };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,135 @@ 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
+
127
+ /**
128
+ * Type guard to check if an error has a code property.
129
+ */
130
+ declare function isErrorWithCode(error: unknown): error is Error & {
131
+ code: string;
132
+ };
133
+
5
134
  type Schema = z3.ZodTypeAny | z4.$ZodType;
6
135
  type ZodInfer<T> = T extends z3.ZodTypeAny ? z3.infer<T> : z4.infer<T>;
7
136
  declare function isV4Schema(schema: Schema): schema is z4.$ZodType;
@@ -124,4 +253,4 @@ type AssistantMessage = z.infer<typeof assistantMessageSchema>;
124
253
  type Tool = z.infer<typeof toolSchema>;
125
254
  type SendMessageEvent = z.infer<typeof sendMessageEventSchema>;
126
255
 
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 };
256
+ 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, isErrorWithCode, isV4Schema, noopLogger, sendMessageEventSchema, sendMessageInputSchema, systemMessageSchema, toolMessageSchema, toolSchema, userMessageSchema };
package/dist/index.js CHANGED
@@ -32,7 +32,10 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  assistantMessageSchema: () => assistantMessageSchema,
34
34
  clientMessageSchema: () => clientMessageSchema,
35
+ createConsoleLogger: () => createConsoleLogger,
36
+ isErrorWithCode: () => isErrorWithCode,
35
37
  isV4Schema: () => isV4Schema,
38
+ noopLogger: () => noopLogger,
36
39
  sendMessageEventSchema: () => sendMessageEventSchema,
37
40
  sendMessageInputSchema: () => sendMessageInputSchema,
38
41
  systemMessageSchema: () => systemMessageSchema,
@@ -42,6 +45,65 @@ __export(index_exports, {
42
45
  });
43
46
  module.exports = __toCommonJS(index_exports);
44
47
  var z = __toESM(require("zod/v4"));
48
+
49
+ // src/logger.ts
50
+ var noop = (_msgOrObj, ..._args) => {
51
+ };
52
+ var noopLogger = {
53
+ fatal: noop,
54
+ error: noop,
55
+ warn: noop,
56
+ info: noop,
57
+ debug: noop,
58
+ trace: noop,
59
+ child: () => noopLogger
60
+ };
61
+ function createConsoleLogger() {
62
+ return createChildConsoleLogger({});
63
+ }
64
+ function createChildConsoleLogger(bindings) {
65
+ const hasBindings = Object.keys(bindings).length > 0;
66
+ function createLogMethod(level) {
67
+ const consoleMethod = level === "fatal" ? "error" : level === "trace" ? "debug" : level;
68
+ const consoleFn = console[consoleMethod] || console.log;
69
+ const prefix = `[${level.toUpperCase()}]`;
70
+ return (msgOrObj, ...args) => {
71
+ if (typeof msgOrObj === "string") {
72
+ if (hasBindings) {
73
+ consoleFn(prefix, bindings, msgOrObj, ...args);
74
+ } else {
75
+ consoleFn(prefix, msgOrObj, ...args);
76
+ }
77
+ } else {
78
+ const [msg, ...restArgs] = args;
79
+ const mergedObj = hasBindings ? { ...bindings, ...msgOrObj } : msgOrObj;
80
+ if (msg) {
81
+ consoleFn(prefix, mergedObj, msg, ...restArgs);
82
+ } else {
83
+ consoleFn(prefix, mergedObj);
84
+ }
85
+ }
86
+ };
87
+ }
88
+ return {
89
+ fatal: createLogMethod("fatal"),
90
+ error: createLogMethod("error"),
91
+ warn: createLogMethod("warn"),
92
+ info: createLogMethod("info"),
93
+ debug: createLogMethod("debug"),
94
+ trace: createLogMethod("trace"),
95
+ child: (newBindings) => {
96
+ return createChildConsoleLogger({ ...bindings, ...newBindings });
97
+ }
98
+ };
99
+ }
100
+
101
+ // src/errors.ts
102
+ function isErrorWithCode(error) {
103
+ return error instanceof Error && "code" in error && typeof error.code === "string";
104
+ }
105
+
106
+ // src/index.ts
45
107
  function isV4Schema(schema) {
46
108
  return "_zod" in schema;
47
109
  }
@@ -127,7 +189,10 @@ var sendMessageEventSchema = z.union([
127
189
  0 && (module.exports = {
128
190
  assistantMessageSchema,
129
191
  clientMessageSchema,
192
+ createConsoleLogger,
193
+ isErrorWithCode,
130
194
  isV4Schema,
195
+ noopLogger,
131
196
  sendMessageEventSchema,
132
197
  sendMessageInputSchema,
133
198
  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,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,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AO;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","../src/errors.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// Error handling exports\nexport { isErrorWithCode } from \"./errors\";\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","/**\n * Type guard to check if an error has a code property.\n */\nexport function isErrorWithCode(\n error: unknown\n): error is Error & { code: string } {\n return (\n error instanceof Error &&\n \"code\" in error &&\n typeof error.code === \"string\"\n );\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;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,IAAI;AAAA,QACrC;AAAA,MACF,OAAO;AAEL,cAAM,CAAC,KAAK,GAAG,QAAQ,IAAI;AAC3B,cAAM,YAAY,cACd,EAAE,GAAG,UAAU,GAAI,SAAoB,IACvC;AACJ,YAAI,KAAK;AACP,oBAAU,QAAQ,WAAW,KAAK,GAAG,QAAQ;AAAA,QAC/C,OAAO;AACL,oBAAU,QAAQ,SAAS;AAAA,QAC7B;AAAA,MACF;AAAA,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AAA,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":[]}
package/dist/index.mjs CHANGED
@@ -1,5 +1,64 @@
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/errors.ts
57
+ function isErrorWithCode(error) {
58
+ return error instanceof Error && "code" in error && typeof error.code === "string";
59
+ }
60
+
61
+ // src/index.ts
3
62
  function isV4Schema(schema) {
4
63
  return "_zod" in schema;
5
64
  }
@@ -84,7 +143,10 @@ var sendMessageEventSchema = z.union([
84
143
  export {
85
144
  assistantMessageSchema,
86
145
  clientMessageSchema,
146
+ createConsoleLogger,
147
+ isErrorWithCode,
87
148
  isV4Schema,
149
+ noopLogger,
88
150
  sendMessageEventSchema,
89
151
  sendMessageInputSchema,
90
152
  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","../src/errors.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// Error handling exports\nexport { isErrorWithCode } from \"./errors\";\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","/**\n * Type guard to check if an error has a code property.\n */\nexport function isErrorWithCode(\n error: unknown\n): error is Error & { code: string } {\n return (\n error instanceof Error &&\n \"code\" in error &&\n typeof error.code === \"string\"\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;AA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AA,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":[]}
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.9",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist/",