@serverless-dna/sop-agents 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +145 -0
  3. package/dist/agent-discovery.d.ts +21 -0
  4. package/dist/agent-discovery.d.ts.map +1 -0
  5. package/dist/agent-discovery.js +97 -0
  6. package/dist/agent-discovery.js.map +1 -0
  7. package/dist/agents/discovery.d.ts +21 -0
  8. package/dist/agents/discovery.d.ts.map +1 -0
  9. package/dist/agents/discovery.js +97 -0
  10. package/dist/agents/discovery.js.map +1 -0
  11. package/dist/agents/sop-loader.d.ts +20 -0
  12. package/dist/agents/sop-loader.d.ts.map +1 -0
  13. package/dist/agents/sop-loader.js +150 -0
  14. package/dist/agents/sop-loader.js.map +1 -0
  15. package/dist/agents/tool-generator.d.ts +66 -0
  16. package/dist/agents/tool-generator.d.ts.map +1 -0
  17. package/dist/agents/tool-generator.js +171 -0
  18. package/dist/agents/tool-generator.js.map +1 -0
  19. package/dist/default-orchestrator.d.ts +7 -0
  20. package/dist/default-orchestrator.d.ts.map +1 -0
  21. package/dist/default-orchestrator.js +50 -0
  22. package/dist/default-orchestrator.js.map +1 -0
  23. package/dist/errors.d.ts +51 -0
  24. package/dist/errors.d.ts.map +1 -0
  25. package/dist/errors.js +80 -0
  26. package/dist/errors.js.map +1 -0
  27. package/dist/index.d.ts +10 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +18 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/logger.d.ts +26 -0
  32. package/dist/logger.d.ts.map +1 -0
  33. package/dist/logger.js +89 -0
  34. package/dist/logger.js.map +1 -0
  35. package/dist/model-factory.d.ts +36 -0
  36. package/dist/model-factory.d.ts.map +1 -0
  37. package/dist/model-factory.js +55 -0
  38. package/dist/model-factory.js.map +1 -0
  39. package/dist/orchestrator/default-orchestrator.d.ts +7 -0
  40. package/dist/orchestrator/default-orchestrator.d.ts.map +1 -0
  41. package/dist/orchestrator/default-orchestrator.js +50 -0
  42. package/dist/orchestrator/default-orchestrator.js.map +1 -0
  43. package/dist/orchestrator/orchestrator.d.ts +47 -0
  44. package/dist/orchestrator/orchestrator.d.ts.map +1 -0
  45. package/dist/orchestrator/orchestrator.js +276 -0
  46. package/dist/orchestrator/orchestrator.js.map +1 -0
  47. package/dist/orchestrator.d.ts +50 -0
  48. package/dist/orchestrator.d.ts.map +1 -0
  49. package/dist/orchestrator.js +281 -0
  50. package/dist/orchestrator.js.map +1 -0
  51. package/dist/sop-loader.d.ts +20 -0
  52. package/dist/sop-loader.d.ts.map +1 -0
  53. package/dist/sop-loader.js +150 -0
  54. package/dist/sop-loader.js.map +1 -0
  55. package/dist/tool-generator.d.ts +66 -0
  56. package/dist/tool-generator.d.ts.map +1 -0
  57. package/dist/tool-generator.js +171 -0
  58. package/dist/tool-generator.js.map +1 -0
  59. package/dist/types/errors.d.ts +51 -0
  60. package/dist/types/errors.d.ts.map +1 -0
  61. package/dist/types/errors.js +80 -0
  62. package/dist/types/errors.js.map +1 -0
  63. package/dist/types/types.d.ts +160 -0
  64. package/dist/types/types.d.ts.map +1 -0
  65. package/dist/types/types.js +2 -0
  66. package/dist/types/types.js.map +1 -0
  67. package/dist/types.d.ts +157 -0
  68. package/dist/types.d.ts.map +1 -0
  69. package/dist/types.js +2 -0
  70. package/dist/types.js.map +1 -0
  71. package/package.json +68 -0
@@ -0,0 +1,66 @@
1
+ import type { InvokableTool } from "@strands-agents/sdk";
2
+ import { Agent } from "@strands-agents/sdk";
3
+ import { type ModelProvider } from "../model-factory.js";
4
+ import type { SOPDefinition } from "../types/types.js";
5
+ /**
6
+ * Builds a structured prompt for the agent from task and input parameters
7
+ * @param task - The specific task to perform
8
+ * @param inputs - Input parameters for the task
9
+ * @returns Formatted prompt string
10
+ */
11
+ export declare function buildAgentPrompt(task: string, inputs: Record<string, unknown>): string;
12
+ /**
13
+ * Gets or creates a cached agent instance for the given SOP
14
+ * @param sop - The SOP definition to create an agent for
15
+ * @param logger - Optional logger for logging agent creation
16
+ * @returns The agent instance (cached or newly created)
17
+ */
18
+ export declare function getOrCreateAgent(sop: SOPDefinition, logger?: {
19
+ info: (msg: string) => void;
20
+ }): Agent;
21
+ /**
22
+ * Sets the default model spec for creating new agents
23
+ * @param modelSpec - The model spec to use as default (e.g., "bedrock/us.anthropic.claude-sonnet-4-20250514-v1:0")
24
+ */
25
+ export declare function setDefaultModelSpec(modelSpec: string | undefined): void;
26
+ /**
27
+ * Gets the current default model spec (undefined means Strands default)
28
+ */
29
+ export declare function getDefaultModelSpec(): string | undefined;
30
+ /**
31
+ * Sets the default provider when model spec has no provider prefix
32
+ * @param provider - The default provider ("bedrock" or "openai")
33
+ */
34
+ export declare function setDefaultProvider(provider: ModelProvider): void;
35
+ /**
36
+ * Gets the current default provider
37
+ */
38
+ export declare function getDefaultProvider(): ModelProvider;
39
+ /**
40
+ * Sets whether agent output should be printed to console
41
+ * @param enabled - true to print output (debug), false to suppress (production)
42
+ */
43
+ export declare function setPrinterEnabled(enabled: boolean): void;
44
+ /**
45
+ * Gets whether printer is enabled
46
+ */
47
+ export declare function isPrinterEnabled(): boolean;
48
+ /**
49
+ * Clears the agent cache
50
+ */
51
+ export declare function clearCache(): void;
52
+ /**
53
+ * Creates a Strands tool from an SOP definition
54
+ * Tool name follows pattern: agent_{sop.name}
55
+ * Uses async generator to stream sub-agent output
56
+ * @param sop - The SOP definition to create a tool from
57
+ * @returns An InvokableTool that delegates to the agent
58
+ */
59
+ export declare function createTool(sop: SOPDefinition): InvokableTool<Record<string, unknown>, string>;
60
+ /**
61
+ * Creates tools for all agents in a registry
62
+ * @param registry - Map of agent names to SOP definitions
63
+ * @returns Array of InvokableTool instances
64
+ */
65
+ export declare function createAllTools(registry: Map<string, SOPDefinition>): InvokableTool<Record<string, unknown>, string>[];
66
+ //# sourceMappingURL=tool-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-generator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AC7B,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,GAClC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,CAQlD"}
@@ -0,0 +1,171 @@
1
+ import { Agent, tool } from "@strands-agents/sdk";
2
+ import { createModelFromSpec, parseModelSpec, } from "../model-factory.js";
3
+ /**
4
+ * Cache for agent instances to avoid recreating agents for repeated invocations
5
+ */
6
+ const agentCache = new Map();
7
+ /**
8
+ * Current default model spec for creating agents (undefined = use Strands default)
9
+ */
10
+ let currentDefaultModelSpec;
11
+ /**
12
+ * Current default provider when model spec has no provider prefix
13
+ */
14
+ let currentDefaultProvider = "bedrock";
15
+ /**
16
+ * Whether to print agent output to console (default: true, set false for non-debug)
17
+ */
18
+ let printerEnabled = true;
19
+ /**
20
+ * Builds a structured prompt for the agent from task and input parameters
21
+ * @param task - The specific task to perform
22
+ * @param inputs - Input parameters for the task
23
+ * @returns Formatted prompt string
24
+ */
25
+ export function buildAgentPrompt(task, inputs) {
26
+ const inputEntries = Object.entries(inputs).filter(([key]) => key !== "task");
27
+ if (inputEntries.length === 0) {
28
+ return `## Task\n${task}`;
29
+ }
30
+ const inputSection = inputEntries
31
+ .map(([key, value]) => `- ${key}: ${JSON.stringify(value)}`)
32
+ .join("\n");
33
+ return `## Task\n${task}\n\n## Input Parameters\n${inputSection}`;
34
+ }
35
+ /**
36
+ * Gets or creates a cached agent instance for the given SOP
37
+ * @param sop - The SOP definition to create an agent for
38
+ * @param logger - Optional logger for logging agent creation
39
+ * @returns The agent instance (cached or newly created)
40
+ */
41
+ export function getOrCreateAgent(sop, logger) {
42
+ const cached = agentCache.get(sop.name);
43
+ if (cached) {
44
+ return cached;
45
+ }
46
+ // Use SOP-specific model, then default, then Strands default (undefined)
47
+ const modelSpec = sop.model ?? currentDefaultModelSpec;
48
+ let modelDisplay;
49
+ const agentConfig = {
50
+ systemPrompt: sop.body,
51
+ tools: [],
52
+ printer: printerEnabled,
53
+ };
54
+ if (modelSpec) {
55
+ const parsed = parseModelSpec(modelSpec, currentDefaultProvider);
56
+ modelDisplay = `${parsed.provider}/${parsed.modelId}`;
57
+ agentConfig.model = createModelFromSpec(modelSpec, currentDefaultProvider);
58
+ }
59
+ else {
60
+ modelDisplay = "default (Strands SDK)";
61
+ }
62
+ if (logger) {
63
+ logger.info(`Creating agent with model: ${modelDisplay}`);
64
+ }
65
+ const agent = new Agent(agentConfig);
66
+ agentCache.set(sop.name, agent);
67
+ return agent;
68
+ }
69
+ /**
70
+ * Sets the default model spec for creating new agents
71
+ * @param modelSpec - The model spec to use as default (e.g., "bedrock/us.anthropic.claude-sonnet-4-20250514-v1:0")
72
+ */
73
+ export function setDefaultModelSpec(modelSpec) {
74
+ currentDefaultModelSpec = modelSpec;
75
+ }
76
+ /**
77
+ * Gets the current default model spec (undefined means Strands default)
78
+ */
79
+ export function getDefaultModelSpec() {
80
+ return currentDefaultModelSpec;
81
+ }
82
+ /**
83
+ * Sets the default provider when model spec has no provider prefix
84
+ * @param provider - The default provider ("bedrock" or "openai")
85
+ */
86
+ export function setDefaultProvider(provider) {
87
+ currentDefaultProvider = provider;
88
+ }
89
+ /**
90
+ * Gets the current default provider
91
+ */
92
+ export function getDefaultProvider() {
93
+ return currentDefaultProvider;
94
+ }
95
+ /**
96
+ * Sets whether agent output should be printed to console
97
+ * @param enabled - true to print output (debug), false to suppress (production)
98
+ */
99
+ export function setPrinterEnabled(enabled) {
100
+ printerEnabled = enabled;
101
+ }
102
+ /**
103
+ * Gets whether printer is enabled
104
+ */
105
+ export function isPrinterEnabled() {
106
+ return printerEnabled;
107
+ }
108
+ /**
109
+ * Clears the agent cache
110
+ */
111
+ export function clearCache() {
112
+ agentCache.clear();
113
+ }
114
+ /**
115
+ * Creates a Strands tool from an SOP definition
116
+ * Tool name follows pattern: agent_{sop.name}
117
+ * Uses async generator to stream sub-agent output
118
+ * @param sop - The SOP definition to create a tool from
119
+ * @returns An InvokableTool that delegates to the agent
120
+ */
121
+ export function createTool(sop) {
122
+ return tool({
123
+ name: `agent_${sop.name}`,
124
+ description: sop.description,
125
+ inputSchema: sop.zodSchema,
126
+ callback: async function* (input) {
127
+ const task = input.task;
128
+ const agent = getOrCreateAgent(sop);
129
+ const prompt = buildAgentPrompt(task, input);
130
+ // Stream from the sub-agent
131
+ const generator = agent.stream(prompt);
132
+ let result = await generator.next();
133
+ let fullText = "";
134
+ while (!result.done) {
135
+ // Process events from the sub-agent
136
+ // biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
137
+ const event = result.value;
138
+ if (event.type === "modelContentBlockDeltaEvent" &&
139
+ event.delta?.type === "textDelta") {
140
+ const text = event.delta.text ?? "";
141
+ fullText += text;
142
+ yield text;
143
+ }
144
+ result = await generator.next();
145
+ }
146
+ // Return the full text as the final result
147
+ const lastMessage = result.value.lastMessage;
148
+ if (lastMessage?.content?.[0]) {
149
+ const content = lastMessage.content[0];
150
+ if (content.type === "textBlock") {
151
+ return content.text;
152
+ }
153
+ return String(content);
154
+ }
155
+ return fullText;
156
+ },
157
+ });
158
+ }
159
+ /**
160
+ * Creates tools for all agents in a registry
161
+ * @param registry - Map of agent names to SOP definitions
162
+ * @returns Array of InvokableTool instances
163
+ */
164
+ export function createAllTools(registry) {
165
+ const tools = [];
166
+ for (const sop of registry.values()) {
167
+ tools.push(createTool(sop));
168
+ }
169
+ return tools;
170
+ }
171
+ //# sourceMappingURL=tool-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-generator.js","sourceRoot":"","sources":["../../src/agents/tool-generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EACN,mBAAmB,EAEnB,cAAc,GACd,MAAM,qBAAqB,CAAC;AAG7B;;GAEG;AACH,MAAM,UAAU,GAAG,IAAI,GAAG,EAAiB,CAAC;AAE5C;;GAEG;AACH,IAAI,uBAA2C,CAAC;AAEhD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,MAAM,CAAC,OAAO,CAAC,CAAC;YACxB,CAAC;YAED,OAAO,QAAQ,CAAC;QACjB,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC7B,QAAoC;IAEpC,MAAM,KAAK,GAAqD,EAAE,CAAC;IAEnE,KAAK,MAAM,GAAG,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;QACrC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { SOPDefinition } from "./types.js";
2
+ /**
3
+ * Default orchestrator SOP that ships with the package.
4
+ * Used when no orchestrator.md is found in the user's SOP directory.
5
+ */
6
+ export declare const DEFAULT_ORCHESTRATOR: SOPDefinition;
7
+ //# sourceMappingURL=default-orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-orchestrator.d.ts","sourceRoot":"","sources":["../src/default-orchestrator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,aA2ClC,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Default orchestrator SOP that ships with the package.
4
+ * Used when no orchestrator.md is found in the user's SOP directory.
5
+ */
6
+ export const DEFAULT_ORCHESTRATOR = {
7
+ name: "orchestrator",
8
+ description: "Master orchestrator that delegates tasks to specialized agents",
9
+ version: "1.0.0",
10
+ type: "orchestrator",
11
+ tools: [],
12
+ inputs: {},
13
+ filepath: "<built-in>",
14
+ zodSchema: z.object({ task: z.string().describe("The task to perform") }),
15
+ body: `# Task Orchestrator
16
+
17
+ ## Overview
18
+
19
+ You are a master orchestrator responsible for coordinating multiple specialized agents to complete complex tasks.
20
+
21
+ ## Steps
22
+
23
+ ### 1. Analyze Request
24
+
25
+ Parse the incoming request to understand what needs to be accomplished.
26
+
27
+ **Constraints:**
28
+ - You MUST identify all subtasks required to fulfill the request
29
+ - You SHOULD break complex requests into smaller, manageable tasks
30
+
31
+ ### 2. Delegate to Agents
32
+
33
+ Invoke the appropriate specialized agents for each subtask.
34
+
35
+ **Constraints:**
36
+ - You MUST choose the most appropriate agent for each subtask
37
+ - You MUST pass relevant context between agent calls
38
+ - You SHOULD handle agent errors gracefully
39
+ - You MUST ask the user for more detail if you do not have sufficient inputs for agent execution
40
+
41
+ ### 3. Synthesize Results
42
+
43
+ Combine outputs from all agents into a coherent response.
44
+
45
+ **Constraints:**
46
+ - You MUST include the actual content produced by agents (poems, jokes, stories, etc.) in your response because the user wants to see the content, not just a description of it
47
+ - You MUST provide a unified response that addresses the original request
48
+ - You MAY add brief context before or after the agent's output`,
49
+ };
50
+ //# sourceMappingURL=default-orchestrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-orchestrator.js","sourceRoot":"","sources":["../src/default-orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAkB;IAClD,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,gEAAgE;IAC7E,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,EAAE;IACV,QAAQ,EAAE,YAAY;IACtB,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC;IACzE,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+DAiCwD;CAC9D,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Base error class for all SOP-related errors
3
+ */
4
+ export declare class SOPError extends Error {
5
+ readonly code: string;
6
+ readonly context: Record<string, unknown>;
7
+ constructor(message: string, code: string, context: Record<string, unknown>);
8
+ }
9
+ /**
10
+ * Thrown when an SOP file cannot be found
11
+ */
12
+ export declare class FileNotFoundError extends SOPError {
13
+ constructor(filepath: string);
14
+ }
15
+ /**
16
+ * Thrown when frontmatter YAML is malformed
17
+ */
18
+ export declare class FrontmatterParseError extends SOPError {
19
+ constructor(filepath: string, parseError: string);
20
+ }
21
+ /**
22
+ * Thrown when frontmatter fails validation
23
+ */
24
+ export declare class FrontmatterValidationError extends SOPError {
25
+ constructor(filepath: string, field: string, reason: string);
26
+ }
27
+ /**
28
+ * Thrown when discovery directory doesn't exist
29
+ */
30
+ export declare class DirectoryNotFoundError extends SOPError {
31
+ constructor(directory: string);
32
+ }
33
+ /**
34
+ * Thrown when no orchestrator SOP is found
35
+ */
36
+ export declare class OrchestratorNotFoundError extends SOPError {
37
+ constructor(directory: string);
38
+ }
39
+ /**
40
+ * Thrown when multiple orchestrator SOPs are found
41
+ */
42
+ export declare class MultipleOrchestratorsError extends SOPError {
43
+ constructor(directory: string, files: string[]);
44
+ }
45
+ /**
46
+ * Thrown when an agent invocation fails
47
+ */
48
+ export declare class AgentInvocationError extends SOPError {
49
+ constructor(agentName: string, task: string, originalError: Error);
50
+ }
51
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;aAGjB,IAAI,EAAE,MAAM;aACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAFhD,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAKjD;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,QAAQ;gBAClC,QAAQ,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,QAAQ;gBACtC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAQhD;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,QAAQ;gBAC3C,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAQ3D;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,QAAQ;gBACvC,SAAS,EAAE,MAAM;CAM7B;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,QAAQ;gBAC1C,SAAS,EAAE,MAAM;CAQ7B;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,QAAQ;gBAC3C,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;CAQ9C;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,QAAQ;gBACrC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK;CASjE"}
package/dist/errors.js ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Base error class for all SOP-related errors
3
+ */
4
+ export class SOPError extends Error {
5
+ code;
6
+ context;
7
+ constructor(message, code, context) {
8
+ super(message);
9
+ this.code = code;
10
+ this.context = context;
11
+ this.name = "SOPError";
12
+ }
13
+ }
14
+ /**
15
+ * Thrown when an SOP file cannot be found
16
+ */
17
+ export class FileNotFoundError extends SOPError {
18
+ constructor(filepath) {
19
+ super(`SOP file not found: ${filepath}`, "FILE_NOT_FOUND", { filepath });
20
+ this.name = "FileNotFoundError";
21
+ }
22
+ }
23
+ /**
24
+ * Thrown when frontmatter YAML is malformed
25
+ */
26
+ export class FrontmatterParseError extends SOPError {
27
+ constructor(filepath, parseError) {
28
+ super(`Failed to parse frontmatter in ${filepath}: ${parseError}`, "FRONTMATTER_PARSE_ERROR", { filepath, parseError });
29
+ this.name = "FrontmatterParseError";
30
+ }
31
+ }
32
+ /**
33
+ * Thrown when frontmatter fails validation
34
+ */
35
+ export class FrontmatterValidationError extends SOPError {
36
+ constructor(filepath, field, reason) {
37
+ super(`Invalid frontmatter in ${filepath}: ${field} - ${reason}`, "FRONTMATTER_VALIDATION_ERROR", { filepath, field, reason });
38
+ this.name = "FrontmatterValidationError";
39
+ }
40
+ }
41
+ /**
42
+ * Thrown when discovery directory doesn't exist
43
+ */
44
+ export class DirectoryNotFoundError extends SOPError {
45
+ constructor(directory) {
46
+ super(`Directory not found: ${directory}`, "DIRECTORY_NOT_FOUND", {
47
+ directory,
48
+ });
49
+ this.name = "DirectoryNotFoundError";
50
+ }
51
+ }
52
+ /**
53
+ * Thrown when no orchestrator SOP is found
54
+ */
55
+ export class OrchestratorNotFoundError extends SOPError {
56
+ constructor(directory) {
57
+ super(`No orchestrator SOP found in ${directory}`, "ORCHESTRATOR_NOT_FOUND", { directory });
58
+ this.name = "OrchestratorNotFoundError";
59
+ }
60
+ }
61
+ /**
62
+ * Thrown when multiple orchestrator SOPs are found
63
+ */
64
+ export class MultipleOrchestratorsError extends SOPError {
65
+ constructor(directory, files) {
66
+ super(`Multiple orchestrator SOPs found in ${directory}: ${files.join(", ")}`, "MULTIPLE_ORCHESTRATORS", { directory, files });
67
+ this.name = "MultipleOrchestratorsError";
68
+ }
69
+ }
70
+ /**
71
+ * Thrown when an agent invocation fails
72
+ */
73
+ export class AgentInvocationError extends SOPError {
74
+ constructor(agentName, task, originalError) {
75
+ super(`Agent '${agentName}' failed: ${originalError.message}`, "AGENT_INVOCATION_ERROR", { agentName, task, originalError: originalError.message });
76
+ this.name = "AgentInvocationError";
77
+ this.cause = originalError;
78
+ }
79
+ }
80
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGjB;IACA;IAHjB,YACC,OAAe,EACC,IAAY,EACZ,OAA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YAAY,SAAiB;QAC5B,KAAK,CACJ,gCAAgC,SAAS,EAAE,EAC3C,wBAAwB,EACxB,EAAE,SAAS,EAAE,CACb,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IACzC,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,QAAQ;IACvD,YAAY,SAAiB,EAAE,KAAe;QAC7C,KAAK,CACJ,uCAAuC,SAAS,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EACvE,wBAAwB,EACxB,EAAE,SAAS,EAAE,KAAK,EAAE,CACpB,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC1C,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,QAAQ;IACjD,YAAY,SAAiB,EAAE,IAAY,EAAE,aAAoB;QAChE,KAAK,CACJ,UAAU,SAAS,aAAa,aAAa,CAAC,OAAO,EAAE,EACvD,wBAAwB,EACxB,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,CAAC,OAAO,EAAE,CACzD,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,aAAa,CAAC;IAC5B,CAAC;CACD"}
@@ -0,0 +1,10 @@
1
+ export { discoverAgents, findOrchestrator } from "./agents/discovery.js";
2
+ export { generateZodSchema, loadSOP, validateFrontmatter, } from "./agents/sop-loader.js";
3
+ export { buildAgentPrompt, clearCache, createAllTools, createTool, getDefaultModelSpec, getDefaultProvider, getOrCreateAgent, setDefaultModelSpec, setDefaultProvider, } from "./agents/tool-generator.js";
4
+ export { createLogger, LoggerImpl } from "./logger.js";
5
+ export { createModel, createModelFromSpec, parseModelSpec, } from "./model-factory.js";
6
+ export { DEFAULT_ORCHESTRATOR } from "./orchestrator/default-orchestrator.js";
7
+ export { createOrchestrator, OrchestratorImpl, } from "./orchestrator/orchestrator.js";
8
+ export { AgentInvocationError, DirectoryNotFoundError, FileNotFoundError, FrontmatterParseError, FrontmatterValidationError, MultipleOrchestratorsError, OrchestratorNotFoundError, SOPError, } from "./types/errors.js";
9
+ export type { ErrorMode, InputDef, InputType, InvokeOptions, LogEntry, Logger, LogLevel, ModelProvider, Orchestrator, OrchestratorConfig, SOPDefinition, SOPFrontmatter, } from "./types/types.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EACN,iBAAiB,EACjB,OAAO,EACP,mBAAmB,GACnB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACN,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GAClB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGvD,OAAO,EACN,WAAW,EACX,mBAAmB,EACnB,cAAc,GACd,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAE9E,OAAO,EACN,kBAAkB,EAClB,gBAAgB,GAChB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACN,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,QAAQ,GACR,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EACX,SAAS,EACT,QAAQ,EACR,SAAS,EACT,aAAa,EACb,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,cAAc,GACd,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ // Public API exports
2
+ // Agent Discovery
3
+ export { discoverAgents, findOrchestrator } from "./agents/discovery.js";
4
+ // SOP Loader
5
+ export { generateZodSchema, loadSOP, validateFrontmatter, } from "./agents/sop-loader.js";
6
+ // Tool Generator
7
+ export { buildAgentPrompt, clearCache, createAllTools, createTool, getDefaultModelSpec, getDefaultProvider, getOrCreateAgent, setDefaultModelSpec, setDefaultProvider, } from "./agents/tool-generator.js";
8
+ // Logger
9
+ export { createLogger, LoggerImpl } from "./logger.js";
10
+ // Model Factory
11
+ export { createModel, createModelFromSpec, parseModelSpec, } from "./model-factory.js";
12
+ // Default Orchestrator
13
+ export { DEFAULT_ORCHESTRATOR } from "./orchestrator/default-orchestrator.js";
14
+ // Factory function
15
+ export { createOrchestrator, OrchestratorImpl, } from "./orchestrator/orchestrator.js";
16
+ // Error classes
17
+ export { AgentInvocationError, DirectoryNotFoundError, FileNotFoundError, FrontmatterParseError, FrontmatterValidationError, MultipleOrchestratorsError, OrchestratorNotFoundError, SOPError, } from "./types/errors.js";
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qBAAqB;AAErB,kBAAkB;AAClB,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzE,aAAa;AACb,OAAO,EACN,iBAAiB,EACjB,OAAO,EACP,mBAAmB,GACnB,MAAM,wBAAwB,CAAC;AAChC,iBAAiB;AACjB,OAAO,EACN,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GAClB,MAAM,4BAA4B,CAAC;AAEpC,SAAS;AACT,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvD,gBAAgB;AAChB,OAAO,EACN,WAAW,EACX,mBAAmB,EACnB,cAAc,GACd,MAAM,oBAAoB,CAAC;AAC5B,uBAAuB;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAC9E,mBAAmB;AACnB,OAAO,EACN,kBAAkB,EAClB,gBAAgB,GAChB,MAAM,gCAAgC,CAAC;AACxC,gBAAgB;AAChB,OAAO,EACN,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,QAAQ,GACR,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { LogEntry, Logger, LogLevel } from "./types/types.js";
2
+ /**
3
+ * Logger implementation for orchestrator logging
4
+ */
5
+ export declare class LoggerImpl implements Logger {
6
+ private level;
7
+ private correlationId?;
8
+ private agentName?;
9
+ private output;
10
+ constructor(level?: LogLevel, correlationId?: string, agentName?: string, output?: (entry: LogEntry) => void);
11
+ private defaultOutput;
12
+ private shouldLog;
13
+ private log;
14
+ debug(message: string, metadata?: Record<string, unknown>): void;
15
+ info(message: string, metadata?: Record<string, unknown>): void;
16
+ warn(message: string, metadata?: Record<string, unknown>): void;
17
+ error(message: string, error?: Error, metadata?: Record<string, unknown>): void;
18
+ withCorrelationId(correlationId: string): Logger;
19
+ withAgent(agentName: string): Logger;
20
+ setLevel(level: LogLevel): void;
21
+ }
22
+ /**
23
+ * Create a new logger instance
24
+ */
25
+ export declare function createLogger(level?: LogLevel): Logger;
26
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAYnE;;GAEG;AACH,qBAAa,UAAW,YAAW,MAAM;IACxC,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,aAAa,CAAC,CAAS;IAC/B,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,MAAM,CAA4B;gBAGzC,KAAK,GAAE,QAAiB,EACxB,aAAa,CAAC,EAAE,MAAM,EACtB,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI;IAQnC,OAAO,CAAC,aAAa;IAoBrB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,GAAG;IAuBX,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIhE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI/D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI/D,KAAK,CACJ,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,KAAK,EACb,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,IAAI;IAIP,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAShD,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IASpC,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;CAG/B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,GAAE,QAAiB,GAAG,MAAM,CAE7D"}
package/dist/logger.js ADDED
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Log level priority for filtering
3
+ */
4
+ const LOG_LEVEL_PRIORITY = {
5
+ debug: 0,
6
+ info: 1,
7
+ warn: 2,
8
+ error: 3,
9
+ };
10
+ /**
11
+ * Logger implementation for orchestrator logging
12
+ */
13
+ export class LoggerImpl {
14
+ level;
15
+ correlationId;
16
+ agentName;
17
+ output;
18
+ constructor(level = "info", correlationId, agentName, output) {
19
+ this.level = level;
20
+ this.correlationId = correlationId;
21
+ this.agentName = agentName;
22
+ this.output = output ?? this.defaultOutput;
23
+ }
24
+ defaultOutput(entry) {
25
+ const parts = [
26
+ `[${entry.timestamp.toISOString()}]`,
27
+ `[${entry.level.toUpperCase()}]`,
28
+ entry.correlationId ? `[${entry.correlationId}]` : null,
29
+ entry.agentName ? `[${entry.agentName}]` : null,
30
+ entry.message,
31
+ ].filter(Boolean);
32
+ const line = parts.join(" ");
33
+ if (entry.duration !== undefined) {
34
+ console.log(`${line} (${entry.duration}ms)`);
35
+ }
36
+ else if (entry.error) {
37
+ console.log(`${line}\n${entry.error.stack ?? entry.error.message}`);
38
+ }
39
+ else {
40
+ console.log(line);
41
+ }
42
+ }
43
+ shouldLog(level) {
44
+ return LOG_LEVEL_PRIORITY[level] >= LOG_LEVEL_PRIORITY[this.level];
45
+ }
46
+ log(level, message, error, metadata) {
47
+ if (!this.shouldLog(level)) {
48
+ return;
49
+ }
50
+ const entry = {
51
+ timestamp: new Date(),
52
+ correlationId: this.correlationId ?? "",
53
+ level,
54
+ agentName: this.agentName,
55
+ message,
56
+ error,
57
+ metadata,
58
+ };
59
+ this.output(entry);
60
+ }
61
+ debug(message, metadata) {
62
+ this.log("debug", message, undefined, metadata);
63
+ }
64
+ info(message, metadata) {
65
+ this.log("info", message, undefined, metadata);
66
+ }
67
+ warn(message, metadata) {
68
+ this.log("warn", message, undefined, metadata);
69
+ }
70
+ error(message, error, metadata) {
71
+ this.log("error", message, error, metadata);
72
+ }
73
+ withCorrelationId(correlationId) {
74
+ return new LoggerImpl(this.level, correlationId, this.agentName, this.output);
75
+ }
76
+ withAgent(agentName) {
77
+ return new LoggerImpl(this.level, this.correlationId, agentName, this.output);
78
+ }
79
+ setLevel(level) {
80
+ this.level = level;
81
+ }
82
+ }
83
+ /**
84
+ * Create a new logger instance
85
+ */
86
+ export function createLogger(level = "info") {
87
+ return new LoggerImpl(level);
88
+ }
89
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,kBAAkB,GAA6B;IACpD,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACR,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,UAAU;IACd,KAAK,CAAW;IAChB,aAAa,CAAU;IACvB,SAAS,CAAU;IACnB,MAAM,CAA4B;IAE1C,YACC,QAAkB,MAAM,EACxB,aAAsB,EACtB,SAAkB,EAClB,MAAkC;QAElC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC,aAAa,CAAC;IAC5C,CAAC;IAEO,aAAa,CAAC,KAAe;QACpC,MAAM,KAAK,GAAG;YACb,IAAI,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,GAAG;YACpC,IAAI,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,GAAG;YAChC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,IAAI;YACvD,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,IAAI;YAC/C,KAAK,CAAC,OAAO;SACb,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAElB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE7B,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAClC,OAAO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