@nebulaos/core 0.1.1

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 (150) hide show
  1. package/README.md +206 -0
  2. package/dist/__tests__/mocks/mock-provider.d.ts +15 -0
  3. package/dist/__tests__/mocks/mock-provider.js +44 -0
  4. package/dist/agent/Agent.d.ts +96 -0
  5. package/dist/agent/Agent.js +861 -0
  6. package/dist/agent/BaseAgent.d.ts +53 -0
  7. package/dist/agent/BaseAgent.js +126 -0
  8. package/dist/agent/events/events.d.ts +14 -0
  9. package/dist/agent/events/events.js +2 -0
  10. package/dist/agent/events/events.spec.d.ts +1 -0
  11. package/dist/agent/events/events.spec.js +75 -0
  12. package/dist/agent/instruction/index.d.ts +23 -0
  13. package/dist/agent/instruction/index.js +76 -0
  14. package/dist/agent/memory/in-memory.d.ts +24 -0
  15. package/dist/agent/memory/in-memory.js +78 -0
  16. package/dist/agent/memory/index.d.ts +2 -0
  17. package/dist/agent/memory/index.js +18 -0
  18. package/dist/agent/memory/memory.d.ts +43 -0
  19. package/dist/agent/memory/memory.js +7 -0
  20. package/dist/agent/provider/file-parts.spec.d.ts +1 -0
  21. package/dist/agent/provider/file-parts.spec.js +83 -0
  22. package/dist/agent/provider/index.d.ts +130 -0
  23. package/dist/agent/provider/index.js +8 -0
  24. package/dist/agent/skills/index.d.ts +61 -0
  25. package/dist/agent/skills/index.js +9 -0
  26. package/dist/agent/tools/index.d.ts +35 -0
  27. package/dist/agent/tools/index.js +87 -0
  28. package/dist/cost/add-cost.d.ts +10 -0
  29. package/dist/cost/add-cost.js +80 -0
  30. package/dist/cost/add-cost.spec.d.ts +1 -0
  31. package/dist/cost/add-cost.spec.js +36 -0
  32. package/dist/cost/index.d.ts +1 -0
  33. package/dist/cost/index.js +17 -0
  34. package/dist/domain-events/index.d.ts +16 -0
  35. package/dist/domain-events/index.js +38 -0
  36. package/dist/eval/index.d.ts +19 -0
  37. package/dist/eval/index.js +24 -0
  38. package/dist/events/base.d.ts +5 -0
  39. package/dist/events/base.js +2 -0
  40. package/dist/events/schemas.d.ts +3463 -0
  41. package/dist/events/schemas.js +244 -0
  42. package/dist/execution-context/index.d.ts +21 -0
  43. package/dist/execution-context/index.js +17 -0
  44. package/dist/index.cjs +2958 -0
  45. package/dist/index.cjs.map +1 -0
  46. package/dist/index.d.cts +3425 -0
  47. package/dist/index.d.ts +22 -0
  48. package/dist/index.js +53 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/lgpd/index.d.ts +7 -0
  51. package/dist/lgpd/index.js +21 -0
  52. package/dist/logger/agent-logger.d.ts +16 -0
  53. package/dist/logger/agent-logger.js +110 -0
  54. package/dist/logger/formatters.d.ts +32 -0
  55. package/dist/logger/formatters.js +146 -0
  56. package/dist/logger/index.d.ts +30 -0
  57. package/dist/logger/index.js +88 -0
  58. package/dist/logger/styles.d.ts +46 -0
  59. package/dist/logger/styles.js +53 -0
  60. package/dist/logger/workflow-logger.d.ts +16 -0
  61. package/dist/logger/workflow-logger.js +79 -0
  62. package/dist/multi-agent/agent-as-tool/AgentAsTool.d.ts +16 -0
  63. package/dist/multi-agent/agent-as-tool/AgentAsTool.js +54 -0
  64. package/dist/multi-agent/agent-as-tool/AgentAsTool.spec.d.ts +1 -0
  65. package/dist/multi-agent/agent-as-tool/AgentAsTool.spec.js +76 -0
  66. package/dist/multi-agent/committee-team/CommitteeTeam.d.ts +16 -0
  67. package/dist/multi-agent/committee-team/CommitteeTeam.js +150 -0
  68. package/dist/multi-agent/committee-team/CommitteeTeam.spec.d.ts +1 -0
  69. package/dist/multi-agent/committee-team/CommitteeTeam.spec.js +43 -0
  70. package/dist/multi-agent/handoff-team/HandoffTeam.d.ts +16 -0
  71. package/dist/multi-agent/handoff-team/HandoffTeam.js +185 -0
  72. package/dist/multi-agent/handoff-team/HandoffTeam.spec.d.ts +1 -0
  73. package/dist/multi-agent/handoff-team/HandoffTeam.spec.js +105 -0
  74. package/dist/multi-agent/hierarchical-team/HierarchicalTeam.d.ts +18 -0
  75. package/dist/multi-agent/hierarchical-team/HierarchicalTeam.js +164 -0
  76. package/dist/multi-agent/hierarchical-team/HierarchicalTeam.spec.d.ts +1 -0
  77. package/dist/multi-agent/hierarchical-team/HierarchicalTeam.spec.js +53 -0
  78. package/dist/multi-agent/index.d.ts +10 -0
  79. package/dist/multi-agent/index.js +26 -0
  80. package/dist/multi-agent/pipeline-team/PipelineTeam.d.ts +13 -0
  81. package/dist/multi-agent/pipeline-team/PipelineTeam.js +104 -0
  82. package/dist/multi-agent/pipeline-team/PipelineTeam.spec.d.ts +1 -0
  83. package/dist/multi-agent/pipeline-team/PipelineTeam.spec.js +54 -0
  84. package/dist/multi-agent/router-team/RouterTeam.d.ts +15 -0
  85. package/dist/multi-agent/router-team/RouterTeam.js +153 -0
  86. package/dist/multi-agent/router-team/RouterTeam.spec.d.ts +1 -0
  87. package/dist/multi-agent/router-team/RouterTeam.spec.js +69 -0
  88. package/dist/multi-agent/types/index.d.ts +349 -0
  89. package/dist/multi-agent/types/index.js +79 -0
  90. package/dist/multi-agent/utils/guardrails.d.ts +6 -0
  91. package/dist/multi-agent/utils/guardrails.js +34 -0
  92. package/dist/multi-agent/utils/memory.d.ts +8 -0
  93. package/dist/multi-agent/utils/memory.js +40 -0
  94. package/dist/multi-agent/utils/prompts.d.ts +4 -0
  95. package/dist/multi-agent/utils/prompts.js +25 -0
  96. package/dist/tracing/index.d.ts +89 -0
  97. package/dist/tracing/index.js +188 -0
  98. package/dist/tsup.config.d.ts +2 -0
  99. package/dist/tsup.config.js +11 -0
  100. package/dist/utils/schema-to-zod.d.ts +7 -0
  101. package/dist/utils/schema-to-zod.js +36 -0
  102. package/dist/workflow/Workflow.d.ts +106 -0
  103. package/dist/workflow/Workflow.js +204 -0
  104. package/dist/workflow/adapters.d.ts +61 -0
  105. package/dist/workflow/adapters.js +29 -0
  106. package/dist/workflow/definition/DefinitionBuilder.d.ts +9 -0
  107. package/dist/workflow/definition/DefinitionBuilder.js +91 -0
  108. package/dist/workflow/definition/DefinitionBuilder.spec.d.ts +1 -0
  109. package/dist/workflow/definition/DefinitionBuilder.spec.js +66 -0
  110. package/dist/workflow/definition/DefinitionHasher.d.ts +8 -0
  111. package/dist/workflow/definition/DefinitionHasher.js +11 -0
  112. package/dist/workflow/definition/DefinitionHasher.spec.d.ts +1 -0
  113. package/dist/workflow/definition/DefinitionHasher.spec.js +28 -0
  114. package/dist/workflow/definition/types.d.ts +27 -0
  115. package/dist/workflow/definition/types.js +2 -0
  116. package/dist/workflow/events.d.ts +9 -0
  117. package/dist/workflow/events.js +2 -0
  118. package/dist/workflow/execution/AgentNodeIntegration.spec.d.ts +1 -0
  119. package/dist/workflow/execution/AgentNodeIntegration.spec.js +50 -0
  120. package/dist/workflow/execution/NodeExecutor.d.ts +9 -0
  121. package/dist/workflow/execution/NodeExecutor.js +43 -0
  122. package/dist/workflow/execution/NodeExecutor.spec.d.ts +1 -0
  123. package/dist/workflow/execution/NodeExecutor.spec.js +45 -0
  124. package/dist/workflow/execution/WorkflowEventBus.d.ts +14 -0
  125. package/dist/workflow/execution/WorkflowEventBus.js +42 -0
  126. package/dist/workflow/execution/WorkflowEventBus.spec.d.ts +1 -0
  127. package/dist/workflow/execution/WorkflowEventBus.spec.js +78 -0
  128. package/dist/workflow/execution/WorkflowRunner.d.ts +26 -0
  129. package/dist/workflow/execution/WorkflowRunner.js +212 -0
  130. package/dist/workflow/execution/WorkflowRunner.spec.d.ts +1 -0
  131. package/dist/workflow/execution/WorkflowRunner.spec.js +92 -0
  132. package/dist/workflow/execution/WorkflowTelemetry.d.ts +13 -0
  133. package/dist/workflow/execution/WorkflowTelemetry.js +43 -0
  134. package/dist/workflow/execution/WorkflowTelemetry.spec.d.ts +1 -0
  135. package/dist/workflow/execution/WorkflowTelemetry.spec.js +31 -0
  136. package/dist/workflow/graph/NodeNameRegistry.d.ts +20 -0
  137. package/dist/workflow/graph/NodeNameRegistry.js +21 -0
  138. package/dist/workflow/graph/NodeNameRegistry.spec.d.ts +1 -0
  139. package/dist/workflow/graph/NodeNameRegistry.spec.js +18 -0
  140. package/dist/workflow/graph/WorkflowGraph.d.ts +14 -0
  141. package/dist/workflow/graph/WorkflowGraph.js +23 -0
  142. package/dist/workflow/graph/nodes.d.ts +26 -0
  143. package/dist/workflow/graph/nodes.js +2 -0
  144. package/dist/workflow/queue/WorkflowQueueService.d.ts +22 -0
  145. package/dist/workflow/queue/WorkflowQueueService.js +47 -0
  146. package/dist/workflow/state/WorkflowStateService.d.ts +7 -0
  147. package/dist/workflow/state/WorkflowStateService.js +20 -0
  148. package/dist/workflow/types.d.ts +16 -0
  149. package/dist/workflow/types.js +2 -0
  150. package/package.json +56 -0
@@ -0,0 +1,16 @@
1
+ import { Agent } from "../agent/Agent.js";
2
+ import { ILogger } from "./index.js";
3
+ /**
4
+ * AgentLogger binds to Agent events and formats them for logging
5
+ *
6
+ * This class is responsible for:
7
+ * - Listening to agent lifecycle events
8
+ * - Formatting event data into structured logs
9
+ * - Delegating actual logging to an ILogger implementation
10
+ */
11
+ export declare class AgentLogger {
12
+ private agent;
13
+ private logger;
14
+ constructor(agent: Agent, logger: ILogger);
15
+ private bindEvents;
16
+ }
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentLogger = void 0;
4
+ /**
5
+ * AgentLogger binds to Agent events and formats them for logging
6
+ *
7
+ * This class is responsible for:
8
+ * - Listening to agent lifecycle events
9
+ * - Formatting event data into structured logs
10
+ * - Delegating actual logging to an ILogger implementation
11
+ */
12
+ class AgentLogger {
13
+ agent;
14
+ logger;
15
+ constructor(agent, logger) {
16
+ this.agent = agent;
17
+ this.logger = logger;
18
+ this.bindEvents();
19
+ }
20
+ bindEvents() {
21
+ // Debug Events (Verbose details)
22
+ this.agent.on("agent:llm:call", (event) => {
23
+ const { data, trace } = event;
24
+ this.logger.debug(`LLM Call #${data.step}`, {
25
+ Messages: data.messages.length,
26
+ "Tools Available": data.tools?.length || 0,
27
+ }, data.agentName, "agent", trace);
28
+ });
29
+ this.agent.on("agent:llm:response", (event) => {
30
+ const { data, trace } = event;
31
+ const usage = data.usage
32
+ ? `${data.usage.promptTokens} prompt + ${data.usage.completionTokens} completion = ${data.usage.totalTokens} total`
33
+ : "N/A";
34
+ const meta = {
35
+ Tokens: usage,
36
+ "Tool Calls": data.toolCalls?.length || 0,
37
+ };
38
+ // Show content if present
39
+ if (data.content) {
40
+ meta["Content"] = data.content;
41
+ }
42
+ // Show tool calls details if present
43
+ if (data.toolCalls && data.toolCalls.length > 0) {
44
+ data.toolCalls.forEach((tc, idx) => {
45
+ meta[`Tool ${idx + 1}`] = `${tc.function.name}(${tc.function.arguments})`;
46
+ });
47
+ }
48
+ this.logger.debug(`LLM Response (Step ${data.step})`, meta, data.agentName, "agent", trace);
49
+ });
50
+ this.agent.on("agent:tool:result", (event) => {
51
+ const { data, trace } = event;
52
+ const status = data.error ? "❌ Failed" : "✓ Success";
53
+ const meta = {
54
+ Duration: `${data.durationMs}ms`,
55
+ };
56
+ // Show output or error
57
+ if (data.error) {
58
+ meta["Error"] = data.error;
59
+ }
60
+ else {
61
+ meta["Output"] =
62
+ typeof data.output === "string" ? data.output : JSON.stringify(data.output);
63
+ }
64
+ this.logger.debug(`Tool Result: ${data.toolName} ${status}`, meta, data.agentName, "agent", trace);
65
+ });
66
+ // Info Events (High Level Flow)
67
+ this.agent.on("agent:execution:start", (event) => {
68
+ const { data, trace, correlationId } = event;
69
+ // Note: provider/model info is now in llm:call, but we can log generic start
70
+ this.logger.info(`Execution Started`, {
71
+ CorrelationId: correlationId,
72
+ Input: data.input,
73
+ }, data.agentName, "agent", trace);
74
+ });
75
+ this.agent.on("agent:execution:end", (event) => {
76
+ const { data, trace } = event;
77
+ const duration = (data.durationMs / 1000).toFixed(2) + "s";
78
+ const usage = data.usage
79
+ ? `${data.usage.totalTokens} tokens (${data.usage.promptTokens} prompt + ${data.usage.completionTokens} completion${data.usage.reasoningTokens ? ` + ${data.usage.reasoningTokens} reasoning` : ""})`
80
+ : "N/A";
81
+ this.logger.info(`Execution Finished ${data.status === "success" ? "✓" : data.status === "truncated" ? "⚠" : "❌"}`, {
82
+ Duration: duration,
83
+ Usage: usage,
84
+ }, data.agentName, "agent", trace);
85
+ });
86
+ this.agent.on("agent:tool:call", (event) => {
87
+ const { data, trace } = event;
88
+ // Parse input if it's a JSON string for better readability
89
+ let parsedInput = data.args;
90
+ if (typeof data.args === "string") {
91
+ try {
92
+ parsedInput = JSON.parse(data.args);
93
+ }
94
+ catch {
95
+ parsedInput = data.args;
96
+ }
97
+ }
98
+ this.logger.info(`Tool Call: ${data.toolName}`, {
99
+ Input: typeof parsedInput === "string" ? parsedInput : JSON.stringify(parsedInput),
100
+ }, data.agentName, "agent", trace);
101
+ });
102
+ // Error Events
103
+ this.agent.on("agent:execution:error", (event) => {
104
+ const { data, trace } = event;
105
+ this.logger.error(`Execution Error`, data.error, // Pass the sanitized error object
106
+ data.agentName, "agent", trace);
107
+ });
108
+ }
109
+ }
110
+ exports.AgentLogger = AgentLogger;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Logging formatters module
3
+ *
4
+ * Contains pure functions for formatting log messages.
5
+ * Each formatter is composable and testable.
6
+ */
7
+ import type { LogLevel } from "./index.js";
8
+ import type { TraceContext } from "../events/schemas.js";
9
+ /**
10
+ * Formats a complete log line.
11
+ *
12
+ * New standard:
13
+ * - timestamp first
14
+ * - then source/context
15
+ *
16
+ * Examples:
17
+ * - 2026-01-13 14:58:46.188 [nebulaos/core | Workflow: Test Agent Workflow] DEBUG Execution Started
18
+ * - 2026-01-13 14:58:46.188 [nebulaos/client] DEBUG HTTP telemetry sent
19
+ */
20
+ export declare function formatLogLine(level: LogLevel, entityName: string | null, message: string, entityType?: "agent" | "workflow" | null, trace?: TraceContext, source?: string): string;
21
+ /**
22
+ * Formats metadata as nested tree structure
23
+ *
24
+ * @param meta - Object with key-value pairs
25
+ * @param isLastGroup - If true, uses └─ for last item, otherwise ├─
26
+ * @returns Array of formatted lines
27
+ */
28
+ export declare function formatMetadata(meta: Record<string, any>, isLastGroup?: boolean): string[];
29
+ /**
30
+ * Formats an error with stack trace
31
+ */
32
+ export declare function formatError(error: Error | any): string[];
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ /**
3
+ * Logging formatters module
4
+ *
5
+ * Contains pure functions for formatting log messages.
6
+ * Each formatter is composable and testable.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.formatLogLine = formatLogLine;
10
+ exports.formatMetadata = formatMetadata;
11
+ exports.formatError = formatError;
12
+ const styles_js_1 = require("./styles.js");
13
+ /**
14
+ * Formats a complete log line.
15
+ *
16
+ * New standard:
17
+ * - timestamp first
18
+ * - then source/context
19
+ *
20
+ * Examples:
21
+ * - 2026-01-13 14:58:46.188 [nebulaos/core | Workflow: Test Agent Workflow] DEBUG Execution Started
22
+ * - 2026-01-13 14:58:46.188 [nebulaos/client] DEBUG HTTP telemetry sent
23
+ */
24
+ function formatLogLine(level, entityName, message, entityType = null, trace, source = "nebulaos/core") {
25
+ const timestamp = new Date().toISOString().replace("T", " ").replace("Z", "");
26
+ const levelColor = (level === "none" ? styles_js_1.COLORS.reset : styles_js_1.LOG_LEVEL_COLORS[level]) || styles_js_1.COLORS.reset;
27
+ const levelUpper = level.toUpperCase();
28
+ // timestamp first
29
+ const timestampStr = `${styles_js_1.COLORS.dim}${timestamp}${styles_js_1.COLORS.reset}`;
30
+ // Build the bracketed scope/context
31
+ let scope = source;
32
+ if (entityName) {
33
+ const entityLabel = entityType === "workflow" ? "Workflow" : "Agent";
34
+ scope = `${source} | ${entityLabel}: ${entityName}`;
35
+ }
36
+ const scopeStr = `${styles_js_1.COLORS.bold}[${scope}]${styles_js_1.COLORS.reset}`;
37
+ // Keep level visible (and colored), but do not bake it into the bracket.
38
+ const levelStr = `${levelColor}${styles_js_1.COLORS.bold}${levelUpper}${styles_js_1.COLORS.reset}`;
39
+ return `${timestampStr} ${scopeStr} ${levelStr} ${message}${styles_js_1.COLORS.reset}`;
40
+ }
41
+ /**
42
+ * Formats metadata as nested tree structure
43
+ *
44
+ * @param meta - Object with key-value pairs
45
+ * @param isLastGroup - If true, uses └─ for last item, otherwise ├─
46
+ * @returns Array of formatted lines
47
+ */
48
+ function formatMetadata(meta, isLastGroup = true) {
49
+ const entries = Object.entries(meta);
50
+ if (entries.length === 0)
51
+ return [];
52
+ return entries.map(([key, value], index) => {
53
+ const isLast = index === entries.length - 1;
54
+ const char = isLast && isLastGroup ? styles_js_1.TREE_CHARS.last : styles_js_1.TREE_CHARS.branch;
55
+ const formattedValue = formatValue(value);
56
+ return ` ${styles_js_1.COLORS.dim}${char}${styles_js_1.COLORS.reset} ${styles_js_1.COLORS.bold}${key}:${styles_js_1.COLORS.reset} ${formattedValue}`;
57
+ });
58
+ }
59
+ /**
60
+ * Formats a single value for display
61
+ * Handles different types appropriately
62
+ */
63
+ function formatValue(value) {
64
+ if (value === null)
65
+ return `${styles_js_1.COLORS.dim}null${styles_js_1.COLORS.reset}`;
66
+ if (value === undefined)
67
+ return `${styles_js_1.COLORS.dim}undefined${styles_js_1.COLORS.reset}`;
68
+ if (typeof value === "string") {
69
+ // Highlight important values
70
+ if (value.includes("✓") || value.includes("Success")) {
71
+ return `${styles_js_1.COLORS.green}${value}${styles_js_1.COLORS.reset}`;
72
+ }
73
+ if (value.includes("❌") || value.includes("Error")) {
74
+ return `${styles_js_1.COLORS.red}${value}${styles_js_1.COLORS.reset}`;
75
+ }
76
+ return value;
77
+ }
78
+ if (typeof value === "number") {
79
+ return `${styles_js_1.COLORS.yellow}${value}${styles_js_1.COLORS.reset}`;
80
+ }
81
+ if (typeof value === "boolean") {
82
+ return value
83
+ ? `${styles_js_1.COLORS.green}${value}${styles_js_1.COLORS.reset}`
84
+ : `${styles_js_1.COLORS.red}${value}${styles_js_1.COLORS.reset}`;
85
+ }
86
+ // Objects and arrays
87
+ try {
88
+ return `${styles_js_1.COLORS.dim}${JSON.stringify(value)}${styles_js_1.COLORS.reset}`;
89
+ }
90
+ catch {
91
+ return `${styles_js_1.COLORS.dim}[Object]${styles_js_1.COLORS.reset}`;
92
+ }
93
+ }
94
+ /**
95
+ * Formats an error with stack trace
96
+ */
97
+ function formatError(error) {
98
+ const lines = [];
99
+ const pushMessageAndStack = (message, stack) => {
100
+ lines.push(` ${styles_js_1.TREE_CHARS.branch} ${styles_js_1.COLORS.red}${message}${styles_js_1.COLORS.reset}`);
101
+ if (stack) {
102
+ const stackLines = stack.split("\n").slice(0, 4); // keep it short
103
+ // If the stack already contains the message on line 0, skip it.
104
+ const trimmed = stackLines[0]?.includes(message) ? stackLines.slice(1) : stackLines;
105
+ trimmed.slice(0, 3).forEach((line, index) => {
106
+ const isLast = index === Math.min(2, trimmed.length - 1);
107
+ const char = isLast ? styles_js_1.TREE_CHARS.last : styles_js_1.TREE_CHARS.branch;
108
+ lines.push(` ${styles_js_1.COLORS.dim}${char} ${line.trim()}${styles_js_1.COLORS.reset}`);
109
+ });
110
+ }
111
+ };
112
+ // 1) Native Error
113
+ if (error instanceof Error) {
114
+ pushMessageAndStack(error.message, error.stack);
115
+ return lines;
116
+ }
117
+ // 2) Sanitized error objects (common in our event payloads): { message, stack, name, code, ... }
118
+ if (error && typeof error === "object") {
119
+ const maybeMessage = typeof error.message === "string"
120
+ ? error.message
121
+ : typeof error.error === "string"
122
+ ? error.error
123
+ : undefined;
124
+ const maybeStack = typeof error.stack === "string" ? error.stack : undefined;
125
+ const maybeCode = typeof error.code === "string" ? error.code : undefined;
126
+ const maybeName = typeof error.name === "string" ? error.name : undefined;
127
+ if (maybeMessage) {
128
+ const prefix = maybeCode ? `[${maybeCode}] ` : "";
129
+ const namePrefix = maybeName && maybeName !== "Error" ? `${maybeName}: ` : "";
130
+ pushMessageAndStack(`${prefix}${namePrefix}${maybeMessage}`, maybeStack);
131
+ return lines;
132
+ }
133
+ // If it's an object but has no message, JSON stringify for debugging.
134
+ try {
135
+ lines.push(` ${styles_js_1.TREE_CHARS.last} ${styles_js_1.COLORS.red}${JSON.stringify(error)}${styles_js_1.COLORS.reset}`);
136
+ return lines;
137
+ }
138
+ catch {
139
+ lines.push(` ${styles_js_1.TREE_CHARS.last} ${styles_js_1.COLORS.red}[Object]${styles_js_1.COLORS.reset}`);
140
+ return lines;
141
+ }
142
+ }
143
+ // 3) Fallback (string, number, boolean, null/undefined)
144
+ lines.push(` ${styles_js_1.TREE_CHARS.last} ${styles_js_1.COLORS.red}${String(error)}${styles_js_1.COLORS.reset}`);
145
+ return lines;
146
+ }
@@ -0,0 +1,30 @@
1
+ import type { TraceContext } from "../events/schemas.js";
2
+ export type LogLevel = "debug" | "info" | "warn" | "error" | "none";
3
+ export * from "./formatters.js";
4
+ export * from "./styles.js";
5
+ export { AgentLogger } from "./agent-logger.js";
6
+ export { WorkflowLogger } from "./workflow-logger.js";
7
+ /**
8
+ * Logger interface
9
+ * All loggers must implement these methods
10
+ */
11
+ export interface ILogger {
12
+ debug(message: string, meta?: any, entityName?: string, entityType?: "agent" | "workflow", trace?: TraceContext): void;
13
+ info(message: string, meta?: any, entityName?: string, entityType?: "agent" | "workflow", trace?: TraceContext): void;
14
+ warn(message: string, meta?: any, entityName?: string, entityType?: "agent" | "workflow", trace?: TraceContext): void;
15
+ error(message: string, error?: any, entityName?: string, entityType?: "agent" | "workflow", trace?: TraceContext): void;
16
+ }
17
+ /**
18
+ * Console-based logger implementation
19
+ * Formats logs with colors, tree structure, and proper timestamps
20
+ */
21
+ export declare class ConsoleLogger implements ILogger {
22
+ private minLevel;
23
+ private readonly source;
24
+ constructor(minLevel?: LogLevel, source?: string);
25
+ private shouldLog;
26
+ debug(message: string, meta?: any, entityName?: string, entityType?: "agent" | "workflow", trace?: TraceContext): void;
27
+ info(message: string, meta?: any, entityName?: string, entityType?: "agent" | "workflow", trace?: TraceContext): void;
28
+ warn(message: string, meta?: any, entityName?: string, entityType?: "agent" | "workflow", trace?: TraceContext): void;
29
+ error(message: string, error?: any, entityName?: string, entityType?: "agent" | "workflow", trace?: TraceContext): void;
30
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ConsoleLogger = exports.WorkflowLogger = exports.AgentLogger = void 0;
18
+ const formatters_js_1 = require("./formatters.js");
19
+ // Re-export formatters and styles for extensibility
20
+ __exportStar(require("./formatters.js"), exports);
21
+ __exportStar(require("./styles.js"), exports);
22
+ var agent_logger_js_1 = require("./agent-logger.js");
23
+ Object.defineProperty(exports, "AgentLogger", { enumerable: true, get: function () { return agent_logger_js_1.AgentLogger; } });
24
+ var workflow_logger_js_1 = require("./workflow-logger.js");
25
+ Object.defineProperty(exports, "WorkflowLogger", { enumerable: true, get: function () { return workflow_logger_js_1.WorkflowLogger; } });
26
+ const LEVEL_WEIGHTS = {
27
+ debug: 0,
28
+ info: 1,
29
+ warn: 2,
30
+ error: 3,
31
+ none: 4,
32
+ };
33
+ /**
34
+ * Console-based logger implementation
35
+ * Formats logs with colors, tree structure, and proper timestamps
36
+ */
37
+ class ConsoleLogger {
38
+ minLevel;
39
+ source;
40
+ constructor(minLevel = "info", source = "nebulaos/core") {
41
+ this.minLevel = minLevel;
42
+ this.source = source;
43
+ }
44
+ shouldLog(level) {
45
+ return LEVEL_WEIGHTS[level] >= LEVEL_WEIGHTS[this.minLevel];
46
+ }
47
+ debug(message, meta, entityName, entityType, trace) {
48
+ if (!this.shouldLog("debug"))
49
+ return;
50
+ const mainLine = (0, formatters_js_1.formatLogLine)("debug", entityName || null, message, entityType || null, trace, this.source);
51
+ console.debug(mainLine);
52
+ if (meta && typeof meta === "object" && Object.keys(meta).length > 0) {
53
+ const metaLines = (0, formatters_js_1.formatMetadata)(meta);
54
+ metaLines.forEach(line => console.debug(line));
55
+ }
56
+ }
57
+ info(message, meta, entityName, entityType, trace) {
58
+ if (!this.shouldLog("info"))
59
+ return;
60
+ const mainLine = (0, formatters_js_1.formatLogLine)("info", entityName || null, message, entityType || null, trace, this.source);
61
+ console.info(mainLine);
62
+ if (meta && typeof meta === "object" && Object.keys(meta).length > 0) {
63
+ const metaLines = (0, formatters_js_1.formatMetadata)(meta);
64
+ metaLines.forEach(line => console.info(line));
65
+ }
66
+ }
67
+ warn(message, meta, entityName, entityType, trace) {
68
+ if (!this.shouldLog("warn"))
69
+ return;
70
+ const mainLine = (0, formatters_js_1.formatLogLine)("warn", entityName || null, message, entityType || null, trace, this.source);
71
+ console.warn(mainLine);
72
+ if (meta && typeof meta === "object" && Object.keys(meta).length > 0) {
73
+ const metaLines = (0, formatters_js_1.formatMetadata)(meta);
74
+ metaLines.forEach(line => console.warn(line));
75
+ }
76
+ }
77
+ error(message, error, entityName, entityType, trace) {
78
+ if (!this.shouldLog("error"))
79
+ return;
80
+ const mainLine = (0, formatters_js_1.formatLogLine)("error", entityName || null, message, entityType || null, trace, this.source);
81
+ console.error(mainLine);
82
+ if (error) {
83
+ const errorLines = (0, formatters_js_1.formatError)(error);
84
+ errorLines.forEach(line => console.error(line));
85
+ }
86
+ }
87
+ }
88
+ exports.ConsoleLogger = ConsoleLogger;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * ANSI escape codes for terminal styling
3
+ * Separated for maintainability and reusability
4
+ */
5
+ export declare const COLORS: {
6
+ readonly black: "\u001B[30m";
7
+ readonly red: "\u001B[31m";
8
+ readonly green: "\u001B[32m";
9
+ readonly yellow: "\u001B[33m";
10
+ readonly blue: "\u001B[34m";
11
+ readonly magenta: "\u001B[35m";
12
+ readonly cyan: "\u001B[36m";
13
+ readonly white: "\u001B[37m";
14
+ readonly gray: "\u001B[90m";
15
+ readonly brightRed: "\u001B[91m";
16
+ readonly brightGreen: "\u001B[92m";
17
+ readonly brightYellow: "\u001B[93m";
18
+ readonly brightBlue: "\u001B[94m";
19
+ readonly brightMagenta: "\u001B[95m";
20
+ readonly brightCyan: "\u001B[96m";
21
+ readonly pink: "\u001B[38;5;213m";
22
+ readonly reset: "\u001B[0m";
23
+ readonly bold: "\u001B[1m";
24
+ readonly dim: "\u001B[2m";
25
+ readonly italic: "\u001B[3m";
26
+ readonly underline: "\u001B[4m";
27
+ };
28
+ /**
29
+ * Predefined color schemes for different log levels
30
+ * Using bright variants for better visibility
31
+ */
32
+ export declare const LOG_LEVEL_COLORS: {
33
+ readonly debug: "\u001B[38;5;213m";
34
+ readonly info: "\u001B[92m";
35
+ readonly warn: "\u001B[93m";
36
+ readonly error: "\u001B[91m";
37
+ };
38
+ /**
39
+ * Tree characters for nested log lines
40
+ */
41
+ export declare const TREE_CHARS: {
42
+ readonly branch: "├─";
43
+ readonly last: "└─";
44
+ readonly vertical: "│ ";
45
+ readonly space: " ";
46
+ };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /**
3
+ * ANSI escape codes for terminal styling
4
+ * Separated for maintainability and reusability
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.TREE_CHARS = exports.LOG_LEVEL_COLORS = exports.COLORS = void 0;
8
+ exports.COLORS = {
9
+ // Foreground colors
10
+ black: "\x1b[30m",
11
+ red: "\x1b[31m",
12
+ green: "\x1b[32m",
13
+ yellow: "\x1b[33m",
14
+ blue: "\x1b[34m",
15
+ magenta: "\x1b[35m",
16
+ cyan: "\x1b[36m",
17
+ white: "\x1b[37m",
18
+ gray: "\x1b[90m",
19
+ // Bright variants
20
+ brightRed: "\x1b[91m",
21
+ brightGreen: "\x1b[92m",
22
+ brightYellow: "\x1b[93m",
23
+ brightBlue: "\x1b[94m",
24
+ brightMagenta: "\x1b[95m",
25
+ brightCyan: "\x1b[96m",
26
+ // Custom colors (256-color mode)
27
+ pink: "\x1b[38;5;213m", // Rosa/Pink - estilo NestJS
28
+ // Styles
29
+ reset: "\x1b[0m",
30
+ bold: "\x1b[1m",
31
+ dim: "\x1b[2m",
32
+ italic: "\x1b[3m",
33
+ underline: "\x1b[4m",
34
+ };
35
+ /**
36
+ * Predefined color schemes for different log levels
37
+ * Using bright variants for better visibility
38
+ */
39
+ exports.LOG_LEVEL_COLORS = {
40
+ debug: exports.COLORS.pink, // Rosa/Pink (NestJS style)
41
+ info: exports.COLORS.brightGreen, // Verde (success/positive)
42
+ warn: exports.COLORS.brightYellow, // Amarelo (warning)
43
+ error: exports.COLORS.brightRed, // Vermelho (error)
44
+ };
45
+ /**
46
+ * Tree characters for nested log lines
47
+ */
48
+ exports.TREE_CHARS = {
49
+ branch: "├─",
50
+ last: "└─",
51
+ vertical: "│ ",
52
+ space: " ",
53
+ };
@@ -0,0 +1,16 @@
1
+ import { Workflow } from "../workflow/Workflow.js";
2
+ import { ILogger } from "./index.js";
3
+ /**
4
+ * WorkflowLogger binds to Workflow events and formats them for logging
5
+ *
6
+ * This class is responsible for:
7
+ * - Listening to workflow lifecycle events
8
+ * - Formatting event data into structured logs
9
+ * - Delegating actual logging to an ILogger implementation
10
+ */
11
+ export declare class WorkflowLogger {
12
+ private workflow;
13
+ private logger;
14
+ constructor(workflow: Workflow, logger: ILogger);
15
+ private bindEvents;
16
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkflowLogger = void 0;
4
+ /**
5
+ * WorkflowLogger binds to Workflow events and formats them for logging
6
+ *
7
+ * This class is responsible for:
8
+ * - Listening to workflow lifecycle events
9
+ * - Formatting event data into structured logs
10
+ * - Delegating actual logging to an ILogger implementation
11
+ */
12
+ class WorkflowLogger {
13
+ workflow;
14
+ logger;
15
+ constructor(workflow, logger) {
16
+ this.workflow = workflow;
17
+ this.logger = logger;
18
+ this.bindEvents();
19
+ }
20
+ bindEvents() {
21
+ const workflowName = this.workflow.name || this.workflow.id;
22
+ // Debug Events (Verbose details)
23
+ this.workflow.on("workflow:node:start", (event) => {
24
+ const { data, trace, executionId } = event;
25
+ this.logger.debug(`Node Started: ${data.nodeId}`, {
26
+ "Node ID": data.nodeId,
27
+ "Node Type": data.nodeType,
28
+ "Attempt": data.attempt,
29
+ "Execution ID": executionId,
30
+ }, workflowName, "workflow", trace);
31
+ });
32
+ this.workflow.on("workflow:node:end", (event) => {
33
+ const { data, trace, executionId } = event;
34
+ const duration = (data.durationMs / 1000).toFixed(2) + "s";
35
+ if (data.status === "success") {
36
+ this.logger.debug(`Node Completed: ${data.nodeId}`, {
37
+ "Node Type": data.nodeType,
38
+ "Attempt": data.attempt,
39
+ "Duration": duration,
40
+ "Execution ID": executionId,
41
+ }, workflowName, "workflow", trace);
42
+ return;
43
+ }
44
+ this.logger.warn(`Node Failed: ${data.nodeId}`, {
45
+ "Node Type": data.nodeType,
46
+ "Attempt": data.attempt,
47
+ "Duration": duration,
48
+ "Execution ID": executionId,
49
+ "Error": data.error?.message,
50
+ }, workflowName, "workflow", trace);
51
+ });
52
+ // Info Events (High Level Flow)
53
+ this.workflow.on("workflow:run:start", (event) => {
54
+ const { data, trace, executionId } = event;
55
+ this.logger.info(`Execution Started`, {
56
+ "Workflow ID": data.workflowId,
57
+ "Execution ID": executionId,
58
+ "Definition Version": data.definitionVersion,
59
+ "Input": typeof data.input === "string" ? data.input : JSON.stringify(data.input),
60
+ }, workflowName, "workflow", trace);
61
+ });
62
+ this.workflow.on("workflow:run:end", (event) => {
63
+ const { data, trace } = event;
64
+ const duration = (data.durationMs / 1000).toFixed(2) + "s";
65
+ this.logger.info(`Execution Completed ${data.status === "success" ? "✓" : "❌"}`, {
66
+ "Duration": duration,
67
+ "Status": data.status,
68
+ "Definition Version": data.definitionVersion,
69
+ "Output": typeof data.output === "string" ? data.output : JSON.stringify(data.output),
70
+ }, workflowName, "workflow", trace);
71
+ });
72
+ // Error Events
73
+ this.workflow.on("workflow:run:error", (event) => {
74
+ const { data, trace } = event;
75
+ this.logger.error(`Execution Error`, data.error, workflowName, "workflow", trace);
76
+ });
77
+ }
78
+ }
79
+ exports.WorkflowLogger = WorkflowLogger;
@@ -0,0 +1,16 @@
1
+ import type { IMemory } from "../../agent/memory/index.js";
2
+ import { Tool } from "../../agent/tools/index.js";
3
+ import type { AgentAsToolConfig } from "../types/index.js";
4
+ export declare class AgentAsTool extends Tool {
5
+ private callingMemory?;
6
+ private readonly target;
7
+ private readonly memoryConfig?;
8
+ private readonly extraPrompt?;
9
+ constructor(config: AgentAsToolConfig);
10
+ /**
11
+ * Allows orchestrators to set the calling agent/team memory when using
12
+ * `memory: { type: "shared" }`.
13
+ */
14
+ setCallingMemory(memory?: IMemory): void;
15
+ private runDelegated;
16
+ }