@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,349 @@
1
+ import { z } from "zod";
2
+ import type { Agent } from "../../agent/Agent.js";
3
+ import type { IMemory } from "../../agent/memory/index.js";
4
+ import type { IModel } from "../../agent/provider/index.js";
5
+ /**
6
+ * Additional prompt used to steer coordination/selection/transfer,
7
+ * not to rewrite the underlying agent instructions.
8
+ */
9
+ export type AdditionalPrompt = string;
10
+ /**
11
+ * Memory configuration for delegation (AgentAsTool).
12
+ */
13
+ export type DelegationMemoryConfig = {
14
+ type: "shared";
15
+ } | {
16
+ type: "isolated";
17
+ } | {
18
+ type: "custom";
19
+ memory: IMemory;
20
+ };
21
+ /**
22
+ * Edge definition for handoff graphs.
23
+ */
24
+ export type HandoffEdge = {
25
+ from: Agent;
26
+ to: Agent;
27
+ toolId: string;
28
+ description?: string;
29
+ };
30
+ /**
31
+ * RouterTeam configuration.
32
+ */
33
+ export type RouterTeamConfig = {
34
+ id: string;
35
+ name: string;
36
+ model: IModel;
37
+ children: Agent[];
38
+ fallback?: Agent;
39
+ memory?: IMemory;
40
+ additionalPrompt?: AdditionalPrompt;
41
+ maxRetries?: number;
42
+ timeoutMs?: number;
43
+ };
44
+ /**
45
+ * HandoffTeam configuration.
46
+ */
47
+ export type HandoffTeamConfig = {
48
+ id: string;
49
+ name: string;
50
+ agents: Agent[];
51
+ edges: HandoffEdge[];
52
+ initialAgent: Agent;
53
+ memory?: IMemory;
54
+ additionalPrompt?: AdditionalPrompt;
55
+ maxTransfers?: number;
56
+ timeoutMs?: number;
57
+ tokenBudget?: number;
58
+ allowedTransitions?: Record<string, string[]>;
59
+ onTransfer?: (from: Agent, to: Agent) => void | Promise<void>;
60
+ };
61
+ /**
62
+ * AgentAsTool configuration.
63
+ */
64
+ export type AgentAsToolConfig = {
65
+ agent: Agent;
66
+ id?: string;
67
+ description?: string;
68
+ additionalPrompt?: AdditionalPrompt;
69
+ memory?: DelegationMemoryConfig;
70
+ inputSchema?: z.ZodSchema;
71
+ };
72
+ /**
73
+ * Aggregation strategies for committee-like behavior.
74
+ */
75
+ export type AggregationStrategy = "vote" | "summarize" | "confidence" | "first";
76
+ /**
77
+ * HierarchicalTeam configuration.
78
+ */
79
+ export type HierarchicalTeamConfig = {
80
+ id: string;
81
+ name: string;
82
+ manager: Agent;
83
+ workers: Agent[];
84
+ memory?: IMemory;
85
+ additionalPrompt?: AdditionalPrompt;
86
+ allowHandoff?: boolean;
87
+ workerCollaboration?: boolean;
88
+ };
89
+ /**
90
+ * PipelineTeam configuration.
91
+ */
92
+ export type PipelineTeamConfig = {
93
+ id: string;
94
+ name: string;
95
+ stages: Agent[];
96
+ memory?: IMemory;
97
+ additionalPrompt?: AdditionalPrompt;
98
+ };
99
+ /**
100
+ * CommitteeTeam configuration.
101
+ */
102
+ export type CommitteeTeamConfig = {
103
+ id: string;
104
+ name: string;
105
+ coordinator: Agent;
106
+ members: Agent[];
107
+ strategy: AggregationStrategy;
108
+ memory?: IMemory;
109
+ additionalPrompt?: AdditionalPrompt;
110
+ parallel?: boolean;
111
+ };
112
+ export declare const delegationMemorySchema: z.ZodUnion<[z.ZodObject<{
113
+ type: z.ZodLiteral<"shared">;
114
+ }, "strip", z.ZodTypeAny, {
115
+ type: "shared";
116
+ }, {
117
+ type: "shared";
118
+ }>, z.ZodObject<{
119
+ type: z.ZodLiteral<"isolated">;
120
+ }, "strip", z.ZodTypeAny, {
121
+ type: "isolated";
122
+ }, {
123
+ type: "isolated";
124
+ }>, z.ZodObject<{
125
+ type: z.ZodLiteral<"custom">;
126
+ memory: z.ZodAny;
127
+ }, "strip", z.ZodTypeAny, {
128
+ type: "custom";
129
+ memory?: any;
130
+ }, {
131
+ type: "custom";
132
+ memory?: any;
133
+ }>]>;
134
+ export declare const handoffEdgeSchema: z.ZodObject<{
135
+ from: z.ZodAny;
136
+ to: z.ZodAny;
137
+ toolId: z.ZodString;
138
+ description: z.ZodOptional<z.ZodString>;
139
+ }, "strip", z.ZodTypeAny, {
140
+ toolId: string;
141
+ description?: string | undefined;
142
+ from?: any;
143
+ to?: any;
144
+ }, {
145
+ toolId: string;
146
+ description?: string | undefined;
147
+ from?: any;
148
+ to?: any;
149
+ }>;
150
+ export declare const routerTeamConfigSchema: z.ZodObject<{
151
+ model: z.ZodAny;
152
+ children: z.ZodArray<z.ZodAny, "many">;
153
+ fallback: z.ZodOptional<z.ZodAny>;
154
+ memory: z.ZodOptional<z.ZodAny>;
155
+ additionalPrompt: z.ZodOptional<z.ZodString>;
156
+ maxRetries: z.ZodOptional<z.ZodNumber>;
157
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
158
+ }, "strip", z.ZodTypeAny, {
159
+ children: any[];
160
+ model?: any;
161
+ memory?: any;
162
+ fallback?: any;
163
+ additionalPrompt?: string | undefined;
164
+ maxRetries?: number | undefined;
165
+ timeoutMs?: number | undefined;
166
+ }, {
167
+ children: any[];
168
+ model?: any;
169
+ memory?: any;
170
+ fallback?: any;
171
+ additionalPrompt?: string | undefined;
172
+ maxRetries?: number | undefined;
173
+ timeoutMs?: number | undefined;
174
+ }>;
175
+ export declare const handoffTeamConfigSchema: z.ZodObject<{
176
+ agents: z.ZodArray<z.ZodAny, "many">;
177
+ edges: z.ZodArray<z.ZodObject<{
178
+ from: z.ZodAny;
179
+ to: z.ZodAny;
180
+ toolId: z.ZodString;
181
+ description: z.ZodOptional<z.ZodString>;
182
+ }, "strip", z.ZodTypeAny, {
183
+ toolId: string;
184
+ description?: string | undefined;
185
+ from?: any;
186
+ to?: any;
187
+ }, {
188
+ toolId: string;
189
+ description?: string | undefined;
190
+ from?: any;
191
+ to?: any;
192
+ }>, "many">;
193
+ initialAgent: z.ZodAny;
194
+ memory: z.ZodOptional<z.ZodAny>;
195
+ additionalPrompt: z.ZodOptional<z.ZodString>;
196
+ maxTransfers: z.ZodOptional<z.ZodNumber>;
197
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
198
+ tokenBudget: z.ZodOptional<z.ZodNumber>;
199
+ allowedTransitions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
200
+ onTransfer: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
201
+ }, "strip", z.ZodTypeAny, {
202
+ edges: {
203
+ toolId: string;
204
+ description?: string | undefined;
205
+ from?: any;
206
+ to?: any;
207
+ }[];
208
+ agents: any[];
209
+ memory?: any;
210
+ additionalPrompt?: string | undefined;
211
+ timeoutMs?: number | undefined;
212
+ initialAgent?: any;
213
+ maxTransfers?: number | undefined;
214
+ tokenBudget?: number | undefined;
215
+ allowedTransitions?: Record<string, string[]> | undefined;
216
+ onTransfer?: ((...args: unknown[]) => unknown) | undefined;
217
+ }, {
218
+ edges: {
219
+ toolId: string;
220
+ description?: string | undefined;
221
+ from?: any;
222
+ to?: any;
223
+ }[];
224
+ agents: any[];
225
+ memory?: any;
226
+ additionalPrompt?: string | undefined;
227
+ timeoutMs?: number | undefined;
228
+ initialAgent?: any;
229
+ maxTransfers?: number | undefined;
230
+ tokenBudget?: number | undefined;
231
+ allowedTransitions?: Record<string, string[]> | undefined;
232
+ onTransfer?: ((...args: unknown[]) => unknown) | undefined;
233
+ }>;
234
+ export declare const agentAsToolConfigSchema: z.ZodObject<{
235
+ agent: z.ZodAny;
236
+ id: z.ZodOptional<z.ZodString>;
237
+ description: z.ZodOptional<z.ZodString>;
238
+ additionalPrompt: z.ZodOptional<z.ZodString>;
239
+ memory: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
240
+ type: z.ZodLiteral<"shared">;
241
+ }, "strip", z.ZodTypeAny, {
242
+ type: "shared";
243
+ }, {
244
+ type: "shared";
245
+ }>, z.ZodObject<{
246
+ type: z.ZodLiteral<"isolated">;
247
+ }, "strip", z.ZodTypeAny, {
248
+ type: "isolated";
249
+ }, {
250
+ type: "isolated";
251
+ }>, z.ZodObject<{
252
+ type: z.ZodLiteral<"custom">;
253
+ memory: z.ZodAny;
254
+ }, "strip", z.ZodTypeAny, {
255
+ type: "custom";
256
+ memory?: any;
257
+ }, {
258
+ type: "custom";
259
+ memory?: any;
260
+ }>]>>;
261
+ inputSchema: z.ZodOptional<z.ZodType<z.ZodType<any, z.ZodTypeDef, any>, z.ZodTypeDef, z.ZodType<any, z.ZodTypeDef, any>>>;
262
+ }, "strip", z.ZodTypeAny, {
263
+ agent?: any;
264
+ description?: string | undefined;
265
+ id?: string | undefined;
266
+ memory?: {
267
+ type: "shared";
268
+ } | {
269
+ type: "isolated";
270
+ } | {
271
+ type: "custom";
272
+ memory?: any;
273
+ } | undefined;
274
+ additionalPrompt?: string | undefined;
275
+ inputSchema?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
276
+ }, {
277
+ agent?: any;
278
+ description?: string | undefined;
279
+ id?: string | undefined;
280
+ memory?: {
281
+ type: "shared";
282
+ } | {
283
+ type: "isolated";
284
+ } | {
285
+ type: "custom";
286
+ memory?: any;
287
+ } | undefined;
288
+ additionalPrompt?: string | undefined;
289
+ inputSchema?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
290
+ }>;
291
+ export declare const hierarchicalTeamConfigSchema: z.ZodObject<{
292
+ manager: z.ZodAny;
293
+ workers: z.ZodArray<z.ZodAny, "many">;
294
+ memory: z.ZodOptional<z.ZodAny>;
295
+ additionalPrompt: z.ZodOptional<z.ZodString>;
296
+ allowHandoff: z.ZodOptional<z.ZodBoolean>;
297
+ workerCollaboration: z.ZodOptional<z.ZodBoolean>;
298
+ }, "strip", z.ZodTypeAny, {
299
+ workers: any[];
300
+ memory?: any;
301
+ additionalPrompt?: string | undefined;
302
+ manager?: any;
303
+ allowHandoff?: boolean | undefined;
304
+ workerCollaboration?: boolean | undefined;
305
+ }, {
306
+ workers: any[];
307
+ memory?: any;
308
+ additionalPrompt?: string | undefined;
309
+ manager?: any;
310
+ allowHandoff?: boolean | undefined;
311
+ workerCollaboration?: boolean | undefined;
312
+ }>;
313
+ export declare const pipelineTeamConfigSchema: z.ZodObject<{
314
+ stages: z.ZodArray<z.ZodAny, "many">;
315
+ memory: z.ZodOptional<z.ZodAny>;
316
+ additionalPrompt: z.ZodOptional<z.ZodString>;
317
+ }, "strip", z.ZodTypeAny, {
318
+ stages: any[];
319
+ memory?: any;
320
+ additionalPrompt?: string | undefined;
321
+ }, {
322
+ stages: any[];
323
+ memory?: any;
324
+ additionalPrompt?: string | undefined;
325
+ }>;
326
+ export declare const committeeTeamConfigSchema: z.ZodObject<{
327
+ coordinator: z.ZodAny;
328
+ members: z.ZodArray<z.ZodAny, "many">;
329
+ strategy: z.ZodEnum<["vote", "summarize", "confidence", "first"]>;
330
+ memory: z.ZodOptional<z.ZodAny>;
331
+ additionalPrompt: z.ZodOptional<z.ZodString>;
332
+ parallel: z.ZodOptional<z.ZodBoolean>;
333
+ }, "strip", z.ZodTypeAny, {
334
+ members: any[];
335
+ strategy: "vote" | "summarize" | "confidence" | "first";
336
+ parallel?: boolean | undefined;
337
+ memory?: any;
338
+ additionalPrompt?: string | undefined;
339
+ coordinator?: any;
340
+ }, {
341
+ members: any[];
342
+ strategy: "vote" | "summarize" | "confidence" | "first";
343
+ parallel?: boolean | undefined;
344
+ memory?: any;
345
+ additionalPrompt?: string | undefined;
346
+ coordinator?: any;
347
+ }>;
348
+ export declare const aggregationStrategySchema: z.ZodEnum<["vote", "summarize", "confidence", "first"]>;
349
+ export type { AgentAsToolConfig as AgentAsToolConfigType, RouterTeamConfig as RouterTeamConfigType, HandoffTeamConfig as HandoffTeamConfigType, HierarchicalTeamConfig as HierarchicalTeamConfigType, PipelineTeamConfig as PipelineTeamConfigType, CommitteeTeamConfig as CommitteeTeamConfigType, };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.aggregationStrategySchema = exports.committeeTeamConfigSchema = exports.pipelineTeamConfigSchema = exports.hierarchicalTeamConfigSchema = exports.agentAsToolConfigSchema = exports.handoffTeamConfigSchema = exports.routerTeamConfigSchema = exports.handoffEdgeSchema = exports.delegationMemorySchema = void 0;
4
+ const zod_1 = require("zod");
5
+ // =============================================================================
6
+ // Zod Schemas (runtime validation helpers)
7
+ // =============================================================================
8
+ const agentRef = zod_1.z.any(); // We avoid instanceof checks to prevent circular deps in runtime.
9
+ const memoryRef = zod_1.z.any();
10
+ exports.delegationMemorySchema = zod_1.z.union([
11
+ zod_1.z.object({ type: zod_1.z.literal("shared") }),
12
+ zod_1.z.object({ type: zod_1.z.literal("isolated") }),
13
+ zod_1.z.object({
14
+ type: zod_1.z.literal("custom"),
15
+ memory: memoryRef,
16
+ }),
17
+ ]);
18
+ exports.handoffEdgeSchema = zod_1.z.object({
19
+ from: agentRef,
20
+ to: agentRef,
21
+ toolId: zod_1.z.string(),
22
+ description: zod_1.z.string().optional(),
23
+ });
24
+ exports.routerTeamConfigSchema = zod_1.z.object({
25
+ model: zod_1.z.any(),
26
+ children: zod_1.z.array(agentRef).min(1),
27
+ fallback: agentRef.optional(),
28
+ memory: memoryRef.optional(),
29
+ additionalPrompt: zod_1.z.string().optional(),
30
+ maxRetries: zod_1.z.number().int().positive().optional(),
31
+ timeoutMs: zod_1.z.number().int().positive().optional(),
32
+ });
33
+ exports.handoffTeamConfigSchema = zod_1.z.object({
34
+ agents: zod_1.z.array(agentRef).min(1),
35
+ edges: zod_1.z.array(exports.handoffEdgeSchema).min(1),
36
+ initialAgent: agentRef,
37
+ memory: memoryRef.optional(),
38
+ additionalPrompt: zod_1.z.string().optional(),
39
+ maxTransfers: zod_1.z.number().int().positive().optional(),
40
+ timeoutMs: zod_1.z.number().int().positive().optional(),
41
+ tokenBudget: zod_1.z.number().positive().optional(),
42
+ allowedTransitions: zod_1.z.record(zod_1.z.array(zod_1.z.string())).optional(),
43
+ onTransfer: zod_1.z.function().optional(),
44
+ });
45
+ exports.agentAsToolConfigSchema = zod_1.z.object({
46
+ agent: agentRef,
47
+ id: zod_1.z.string().optional(),
48
+ description: zod_1.z.string().optional(),
49
+ additionalPrompt: zod_1.z.string().optional(),
50
+ memory: exports.delegationMemorySchema.optional(),
51
+ inputSchema: zod_1.z.custom().optional(),
52
+ });
53
+ exports.hierarchicalTeamConfigSchema = zod_1.z.object({
54
+ manager: agentRef,
55
+ workers: zod_1.z.array(agentRef).min(1),
56
+ memory: memoryRef.optional(),
57
+ additionalPrompt: zod_1.z.string().optional(),
58
+ allowHandoff: zod_1.z.boolean().optional(),
59
+ workerCollaboration: zod_1.z.boolean().optional(),
60
+ });
61
+ exports.pipelineTeamConfigSchema = zod_1.z.object({
62
+ stages: zod_1.z.array(agentRef).min(1),
63
+ memory: memoryRef.optional(),
64
+ additionalPrompt: zod_1.z.string().optional(),
65
+ });
66
+ exports.committeeTeamConfigSchema = zod_1.z.object({
67
+ coordinator: agentRef,
68
+ members: zod_1.z.array(agentRef).min(1),
69
+ strategy: zod_1.z.enum(["vote", "summarize", "confidence", "first"]),
70
+ memory: memoryRef.optional(),
71
+ additionalPrompt: zod_1.z.string().optional(),
72
+ parallel: zod_1.z.boolean().optional(),
73
+ });
74
+ exports.aggregationStrategySchema = zod_1.z.enum([
75
+ "vote",
76
+ "summarize",
77
+ "confidence",
78
+ "first",
79
+ ]);
@@ -0,0 +1,6 @@
1
+ export declare class GuardrailError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare function enforceMaxTransfers(current: number, max?: number): void;
5
+ export declare function enforceAllowedTransition(from: string, to: string, allowed?: Record<string, string[]>): void;
6
+ export declare function enforceTimeout<T>(promise: Promise<T>, timeoutMs?: number, label?: string): Promise<T>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuardrailError = void 0;
4
+ exports.enforceMaxTransfers = enforceMaxTransfers;
5
+ exports.enforceAllowedTransition = enforceAllowedTransition;
6
+ exports.enforceTimeout = enforceTimeout;
7
+ class GuardrailError extends Error {
8
+ constructor(message) {
9
+ super(message);
10
+ this.name = "GuardrailError";
11
+ }
12
+ }
13
+ exports.GuardrailError = GuardrailError;
14
+ function enforceMaxTransfers(current, max) {
15
+ if (max !== undefined && current >= max) {
16
+ throw new GuardrailError(`Max transfers exceeded (${max})`);
17
+ }
18
+ }
19
+ function enforceAllowedTransition(from, to, allowed) {
20
+ if (!allowed)
21
+ return;
22
+ const allowedTargets = allowed[from];
23
+ if (allowedTargets && !allowedTargets.includes(to)) {
24
+ throw new GuardrailError(`Transition from '${from}' to '${to}' is not allowed`);
25
+ }
26
+ }
27
+ function enforceTimeout(promise, timeoutMs, label = "operation") {
28
+ if (!timeoutMs)
29
+ return promise;
30
+ return Promise.race([
31
+ promise,
32
+ new Promise((_, reject) => setTimeout(() => reject(new GuardrailError(`${label} timed out after ${timeoutMs}ms`)), timeoutMs)),
33
+ ]);
34
+ }
@@ -0,0 +1,8 @@
1
+ import type { Agent } from "../../agent/Agent.js";
2
+ import type { IMemory } from "../../agent/memory/index.js";
3
+ import type { DelegationMemoryConfig } from "../types/index.js";
4
+ export declare function overrideAgentMemory(agent: Agent, memory?: IMemory): () => void;
5
+ export declare function resolveDelegationMemory(agent: Agent, config?: DelegationMemoryConfig, callingMemory?: IMemory): Promise<{
6
+ memory: IMemory;
7
+ restore: () => void;
8
+ }>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.overrideAgentMemory = overrideAgentMemory;
4
+ exports.resolveDelegationMemory = resolveDelegationMemory;
5
+ const in_memory_js_1 = require("../../agent/memory/in-memory.js");
6
+ function overrideAgentMemory(agent, memory) {
7
+ const original = agent.config.memory;
8
+ if (memory) {
9
+ agent.config.memory = memory;
10
+ }
11
+ return () => {
12
+ agent.config.memory = original;
13
+ };
14
+ }
15
+ async function resolveDelegationMemory(agent, config, callingMemory) {
16
+ const original = agent.config.memory;
17
+ if (!config) {
18
+ return { memory: original, restore: () => { } };
19
+ }
20
+ if (config.type === "shared") {
21
+ // Share calling history into the target's memory, without replacing it.
22
+ const memory = original;
23
+ if (callingMemory) {
24
+ const msgs = await callingMemory.getMessages();
25
+ for (const msg of msgs) {
26
+ await memory.addMessage(msg);
27
+ }
28
+ }
29
+ agent.config.memory = memory;
30
+ return { memory, restore: () => (agent.config.memory = original) };
31
+ }
32
+ if (config.type === "custom") {
33
+ agent.config.memory = config.memory;
34
+ return { memory: config.memory, restore: () => (agent.config.memory = original) };
35
+ }
36
+ // isolated
37
+ const isolated = new in_memory_js_1.InMemory();
38
+ agent.config.memory = isolated;
39
+ return { memory: isolated, restore: () => (agent.config.memory = original) };
40
+ }
@@ -0,0 +1,4 @@
1
+ import type { Agent } from "../../agent/Agent.js";
2
+ import type { AdditionalPrompt } from "../types/index.js";
3
+ export declare function buildRouterSystemPrompt(agents: Agent[], additionalPrompt?: AdditionalPrompt): string;
4
+ export declare function buildHandoffSystemPrompt(additionalPrompt?: AdditionalPrompt): string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildRouterSystemPrompt = buildRouterSystemPrompt;
4
+ exports.buildHandoffSystemPrompt = buildHandoffSystemPrompt;
5
+ function buildRouterSystemPrompt(agents, additionalPrompt) {
6
+ const lines = agents.map((a) => `- ${a.name}: ${a.config?.instructions ?? a.name}`);
7
+ return [
8
+ "You are a routing controller.",
9
+ "Choose the best agent for the user request.",
10
+ "Respond ONLY with JSON: {\"agent\": \"<name>\"}.",
11
+ additionalPrompt ? `Guidance: ${additionalPrompt}` : "",
12
+ "Available agents:",
13
+ ...lines,
14
+ ]
15
+ .filter(Boolean)
16
+ .join("\n");
17
+ }
18
+ function buildHandoffSystemPrompt(additionalPrompt) {
19
+ return [
20
+ "You are coordinating handoffs between agents.",
21
+ additionalPrompt ? `Guidance: ${additionalPrompt}` : "",
22
+ ]
23
+ .filter(Boolean)
24
+ .join("\n");
25
+ }
@@ -0,0 +1,89 @@
1
+ import type { ITelemetryExporter, TelemetrySpanKind, TelemetrySpanStatus } from "@nebulaos/types";
2
+ export interface TracingContext {
3
+ /** W3C trace-id: 32 lowercase hex chars */
4
+ traceId: string;
5
+ /** W3C span-id: 16 lowercase hex chars */
6
+ spanId: string;
7
+ parentId?: string;
8
+ }
9
+ export interface SpanStartInput<K extends TelemetrySpanKind = TelemetrySpanKind> {
10
+ kind: K;
11
+ name: string;
12
+ data?: Record<string, unknown>;
13
+ correlationId?: string;
14
+ executionId?: string;
15
+ }
16
+ export interface SpanEndInput<K extends TelemetrySpanKind = TelemetrySpanKind> {
17
+ status: TelemetrySpanStatus;
18
+ data?: Record<string, unknown>;
19
+ }
20
+ /**
21
+ * Abstract tracing provider that can be injected into the core.
22
+ * The client package can supply an OpenTelemetry-backed implementation
23
+ * so that span IDs originate from OTel and the hierarchy is preserved
24
+ * end-to-end.
25
+ *
26
+ * The core has NO dependency on OpenTelemetry – only on this interface.
27
+ */
28
+ export interface ITracingProvider {
29
+ /**
30
+ * Starts a new span and returns an ActiveSpan wrapper.
31
+ * The returned spanId MUST already be in W3C format (16 hex chars).
32
+ */
33
+ startSpan(input: SpanStartInput): ActiveSpan;
34
+ /**
35
+ * Returns the current trace context in W3C format, or undefined
36
+ * if there is no active span.
37
+ */
38
+ getContext(): TracingContext | undefined;
39
+ /**
40
+ * Runs a function within a new span context.
41
+ * The provider is responsible for context propagation (AsyncLocalStorage / OTel context).
42
+ */
43
+ withSpan<T>(input: SpanStartInput, fn: (span: ActiveSpan) => Promise<T>): Promise<T>;
44
+ }
45
+ export declare class ActiveSpan<K extends TelemetrySpanKind = TelemetrySpanKind> {
46
+ readonly traceId: string;
47
+ readonly spanId: string;
48
+ readonly parentSpanId: string | undefined;
49
+ readonly kind: K;
50
+ readonly name: string;
51
+ private readonly correlationId;
52
+ private readonly executionId;
53
+ private readonly exporter;
54
+ private ended;
55
+ constructor(traceId: string, spanId: string, parentSpanId: string | undefined, kind: K, name: string, correlationId: string | undefined, executionId: string | undefined, exporter: ITelemetryExporter);
56
+ end(input: SpanEndInput<K>): Promise<void>;
57
+ get isEnded(): boolean;
58
+ }
59
+ export declare class Tracing {
60
+ private static exporter;
61
+ private static provider;
62
+ static setExporter(exporter: ITelemetryExporter): void;
63
+ /**
64
+ * Injects an external tracing provider (e.g. OpenTelemetry).
65
+ * When set, `getContext()` and `withSpan()` delegate to the provider
66
+ * so that span IDs originate from OTel and the hierarchy is preserved.
67
+ */
68
+ static setProvider(provider: ITracingProvider): void;
69
+ /**
70
+ * Gets the current trace context.
71
+ * Returns undefined if called outside of a traced execution.
72
+ */
73
+ static getContext(): TracingContext | undefined;
74
+ /**
75
+ * Gets the current trace context or creates a dummy one if none exists.
76
+ * Useful for logging where you always want *some* ID.
77
+ */
78
+ static getContextOrDummy(): TracingContext;
79
+ /**
80
+ * Runs a function inside a new telemetry span and exports span lifecycle events.
81
+ *
82
+ * When a provider is set, delegates entirely to the provider so that the
83
+ * span IDs come from the external tracing system (e.g. OpenTelemetry).
84
+ * Otherwise, falls back to the built-in implementation that uses the
85
+ * ITelemetryExporter.
86
+ */
87
+ static withSpan<T, K extends TelemetrySpanKind>(input: SpanStartInput<K>, fn: (span: ActiveSpan<K>) => Promise<T>): Promise<T>;
88
+ private static defaultWithSpan;
89
+ }