@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,281 @@
1
+ import { Agent as StrandsAgent } from "@strands-agents/sdk";
2
+ import { discoverAgents, findOrchestrator } from "./agent-discovery.js";
3
+ import { AgentInvocationError } from "./errors.js";
4
+ import { LoggerImpl } from "./logger.js";
5
+ import { createModelFromSpec } from "./model-factory.js";
6
+ import { clearCache as clearToolCache, createAllTools, getOrCreateAgent, setDefaultModelSpec, setDefaultProvider, setPrinterEnabled, } from "./tool-generator.js";
7
+ /**
8
+ * Generate a unique correlation ID for request tracing
9
+ */
10
+ function generateCorrelationId() {
11
+ return `req-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
12
+ }
13
+ /**
14
+ * OrchestratorImpl class implementing the Orchestrator interface
15
+ */
16
+ export class OrchestratorImpl {
17
+ _config;
18
+ registry = new Map();
19
+ orchestratorAgent = null;
20
+ orchestratorSOP = null;
21
+ logger;
22
+ currentCorrelationId;
23
+ constructor(config = {}) {
24
+ this._config = {
25
+ directory: config.directory ?? "./sops",
26
+ errorMode: config.errorMode ?? "fail-fast",
27
+ logLevel: config.logLevel ?? "info",
28
+ defaultModel: config.defaultModel,
29
+ defaultProvider: config.defaultProvider ?? "bedrock",
30
+ showThinking: config.showThinking ?? false,
31
+ };
32
+ this.logger = new LoggerImpl(this._config.logLevel);
33
+ // Set the default model and provider for tool-generator
34
+ setDefaultModelSpec(this._config.defaultModel);
35
+ setDefaultProvider(this._config.defaultProvider);
36
+ // Only print agent output to console in debug mode
37
+ setPrinterEnabled(this._config.logLevel === "debug");
38
+ }
39
+ /**
40
+ * Current configuration (readonly for inspection)
41
+ */
42
+ get config() {
43
+ return { ...this._config };
44
+ }
45
+ /**
46
+ * Initialize the orchestrator by discovering agents and creating tools
47
+ */
48
+ async initialize() {
49
+ const directory = this._config.directory ?? "./sops";
50
+ // Discover agents
51
+ this.registry = await discoverAgents(directory);
52
+ // Find orchestrator SOP
53
+ this.orchestratorSOP = await findOrchestrator(directory);
54
+ // Create tools for all agents
55
+ const tools = createAllTools(this.registry);
56
+ // Wrap tools with error handling and logging
57
+ const wrappedTools = this.wrapToolsWithErrorHandling(tools);
58
+ // Determine model for orchestrator (SOP-specific, config default, or Strands default)
59
+ const orchestratorModelSpec = this.orchestratorSOP.model ?? this._config.defaultModel;
60
+ // Create orchestrator agent with SOP body as system prompt
61
+ const agentConfig = {
62
+ systemPrompt: this.orchestratorSOP.body,
63
+ tools: wrappedTools,
64
+ printer: this._config.logLevel === "debug",
65
+ };
66
+ if (orchestratorModelSpec) {
67
+ agentConfig.model = createModelFromSpec(orchestratorModelSpec, this._config.defaultProvider);
68
+ }
69
+ this.orchestratorAgent = new StrandsAgent(agentConfig);
70
+ }
71
+ /**
72
+ * Process a request through the orchestrator agent
73
+ */
74
+ async invoke(request) {
75
+ const result = await this.invokeWithDetails(request);
76
+ return result.response;
77
+ }
78
+ /**
79
+ * Process a request and return detailed result including thinking
80
+ */
81
+ async invokeWithDetails(request) {
82
+ if (!this.orchestratorAgent) {
83
+ throw new Error("Orchestrator not initialized. Call initialize() first.");
84
+ }
85
+ // Generate correlation ID for request and store it for tool access
86
+ const correlationId = generateCorrelationId();
87
+ this.currentCorrelationId = correlationId;
88
+ const requestLogger = this.logger.withCorrelationId(correlationId);
89
+ // Log request start
90
+ requestLogger.info(`Processing request: ${request.substring(0, 100)}...`, {
91
+ requestLength: request.length,
92
+ });
93
+ const startTime = Date.now();
94
+ const thinking = [];
95
+ const toolCalls = [];
96
+ let responseText = "";
97
+ try {
98
+ // Use streaming to capture thinking and tool calls
99
+ for await (const event of this.orchestratorAgent.stream(request)) {
100
+ // Capture thinking/reasoning content
101
+ if (event.type === "modelContentBlockDeltaEvent" &&
102
+ // biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
103
+ event.delta?.type === "thinkingDelta") {
104
+ // biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
105
+ const thinkingText = event.delta?.thinking;
106
+ if (thinkingText && this._config.showThinking) {
107
+ thinking.push(thinkingText);
108
+ requestLogger.debug(`Thinking: ${thinkingText.substring(0, 100)}...`);
109
+ }
110
+ }
111
+ // Capture text content
112
+ if (event.type === "modelContentBlockDeltaEvent" &&
113
+ // biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
114
+ event.delta?.type === "textDelta") {
115
+ // biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
116
+ responseText += event.delta?.text ?? "";
117
+ }
118
+ // Capture tool use starts
119
+ if (event.type === "modelContentBlockStartEvent" &&
120
+ // biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
121
+ event.start?.type === "toolUseStart") {
122
+ // biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
123
+ const toolName = event.start?.name;
124
+ if (toolName) {
125
+ requestLogger.debug(`Tool selected: ${toolName}`);
126
+ }
127
+ }
128
+ // Capture tool calls from beforeToolsEvent
129
+ if (event.type === "beforeToolsEvent") {
130
+ // biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
131
+ const toolUses = event.toolUses;
132
+ if (Array.isArray(toolUses)) {
133
+ for (const toolUse of toolUses) {
134
+ toolCalls.push({
135
+ name: toolUse.name,
136
+ input: toolUse.input,
137
+ });
138
+ }
139
+ }
140
+ }
141
+ }
142
+ const duration = Date.now() - startTime;
143
+ requestLogger.info(`Request completed in ${duration}ms`);
144
+ return {
145
+ response: responseText,
146
+ thinking: thinking.length > 0 ? thinking : undefined,
147
+ toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
148
+ };
149
+ }
150
+ catch (error) {
151
+ const duration = Date.now() - startTime;
152
+ requestLogger.error(`Request failed after ${duration}ms`, error instanceof Error ? error : new Error(String(error)));
153
+ throw error;
154
+ }
155
+ }
156
+ /**
157
+ * Stream events from the orchestrator in real-time
158
+ */
159
+ async *stream(request) {
160
+ if (!this.orchestratorAgent) {
161
+ throw new Error("Orchestrator not initialized. Call initialize() first.");
162
+ }
163
+ // Generate correlation ID for request and store it for tool access
164
+ const correlationId = generateCorrelationId();
165
+ this.currentCorrelationId = correlationId;
166
+ const requestLogger = this.logger.withCorrelationId(correlationId);
167
+ requestLogger.info(`Streaming request: ${request.substring(0, 100)}...`, {
168
+ requestLength: request.length,
169
+ });
170
+ const startTime = Date.now();
171
+ try {
172
+ for await (const event of this.orchestratorAgent.stream(request)) {
173
+ yield event;
174
+ }
175
+ const duration = Date.now() - startTime;
176
+ requestLogger.info(`Stream completed in ${duration}ms`);
177
+ }
178
+ catch (error) {
179
+ const duration = Date.now() - startTime;
180
+ requestLogger.error(`Stream failed after ${duration}ms`, error instanceof Error ? error : new Error(String(error)));
181
+ throw error;
182
+ }
183
+ }
184
+ /**
185
+ * Clear agent cache
186
+ */
187
+ clearCache() {
188
+ clearToolCache();
189
+ }
190
+ /**
191
+ * Get the agent registry (for inspection/debugging)
192
+ */
193
+ getRegistry() {
194
+ return new Map(this.registry);
195
+ }
196
+ /**
197
+ * Wrap tools with error handling and logging
198
+ */
199
+ wrapToolsWithErrorHandling(tools) {
200
+ return tools.map((originalTool) => {
201
+ const agentName = originalTool.name.replace(/^agent_/, "");
202
+ const sop = this.registry.get(agentName);
203
+ const wrappedInvoke = async (input) => {
204
+ // Get logger with current correlation ID and agent name
205
+ const agentLogger = this.currentCorrelationId
206
+ ? this.logger
207
+ .withCorrelationId(this.currentCorrelationId)
208
+ .withAgent(agentName)
209
+ : this.logger.withAgent(agentName);
210
+ const task = input.task;
211
+ const startTime = Date.now();
212
+ agentLogger.debug("Tool invoke called", { input });
213
+ // Ensure agent is created with logger for model info
214
+ if (sop) {
215
+ getOrCreateAgent(sop, agentLogger);
216
+ }
217
+ agentLogger.info(`Invoking agent with task: "${task?.substring(0, 80) ?? "NO TASK"}..."`);
218
+ try {
219
+ const result = await originalTool.invoke(input);
220
+ const duration = Date.now() - startTime;
221
+ // Log completion with output preview
222
+ const outputPreview = result.substring(0, 200);
223
+ agentLogger.info(`Completed in ${duration}ms (${result.length} chars)`);
224
+ agentLogger.debug(`Output preview: ${outputPreview}...`);
225
+ return result;
226
+ }
227
+ catch (error) {
228
+ const duration = Date.now() - startTime;
229
+ const originalError = error instanceof Error ? error : new Error(String(error));
230
+ agentLogger.error(`Failed after ${duration}ms: ${originalError.message}`, originalError);
231
+ if (this._config.errorMode === "fail-fast") {
232
+ throw new AgentInvocationError(agentName, task, originalError);
233
+ }
234
+ return JSON.stringify({
235
+ success: false,
236
+ agentName,
237
+ error: {
238
+ message: originalError.message,
239
+ code: "AGENT_INVOCATION_ERROR",
240
+ },
241
+ });
242
+ }
243
+ };
244
+ // Wrapped stream generator with logging
245
+ const wrappedStream = (toolContext) => {
246
+ const streamLogger = this.currentCorrelationId
247
+ ? this.logger
248
+ .withCorrelationId(this.currentCorrelationId)
249
+ .withAgent(agentName)
250
+ : this.logger.withAgent(agentName);
251
+ const input = toolContext.toolUse.input;
252
+ const task = input?.task;
253
+ // Ensure agent is created with logger for model info
254
+ if (sop) {
255
+ getOrCreateAgent(sop, streamLogger);
256
+ }
257
+ streamLogger.info(`Invoking agent with task: "${task?.substring(0, 80) ?? "NO TASK"}..."`);
258
+ // Return the original stream - logging happens at invoke level
259
+ return originalTool.stream(toolContext);
260
+ };
261
+ // Create a new tool object with the wrapped invoke and stream
262
+ const wrappedTool = {
263
+ name: originalTool.name,
264
+ description: originalTool.description,
265
+ toolSpec: originalTool.toolSpec,
266
+ invoke: wrappedInvoke,
267
+ stream: wrappedStream,
268
+ };
269
+ return wrappedTool;
270
+ });
271
+ }
272
+ }
273
+ /**
274
+ * Factory function to create and initialize an orchestrator
275
+ */
276
+ export async function createOrchestrator(config = {}) {
277
+ const orchestrator = new OrchestratorImpl(config);
278
+ await orchestrator.initialize();
279
+ return orchestrator;
280
+ }
281
+ //# sourceMappingURL=orchestrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAsB,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EACN,UAAU,IAAI,cAAc,EAC5B,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,qBAAqB,CAAC;AAY7B;;GAEG;AACH,SAAS,qBAAqB;IAC7B,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SAA6B,EAAE;IAE/B,MAAM,YAAY,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClD,MAAM,YAAY,CAAC,UAAU,EAAE,CAAC;IAChC,OAAO,YAAY,CAAC;AACrB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { z } from "zod";
2
+ import type { InputDef, SOPDefinition, SOPFrontmatter } from "./types.js";
3
+ /**
4
+ * Validates frontmatter data against the SOPFrontmatter schema
5
+ * @throws FrontmatterValidationError if validation fails
6
+ */
7
+ export declare function validateFrontmatter(data: unknown, filepath: string): SOPFrontmatter;
8
+ /**
9
+ * Generates a Zod schema from input definitions
10
+ * Always includes a required 'task' field
11
+ */
12
+ export declare function generateZodSchema(inputs?: Record<string, InputDef>): z.ZodObject<z.ZodRawShape>;
13
+ /**
14
+ * Loads and parses an SOP file
15
+ * @throws FileNotFoundError if file doesn't exist
16
+ * @throws FrontmatterParseError if YAML is malformed
17
+ * @throws FrontmatterValidationError if frontmatter validation fails
18
+ */
19
+ export declare function loadSOP(filepath: string): Promise<SOPDefinition>;
20
+ //# sourceMappingURL=sop-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sop-loader.d.ts","sourceRoot":"","sources":["../src/sop-loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE1E;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,MAAM,GACd,cAAc,CA4EhB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAC/B,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAoD5B;AAED;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CA6CtE"}
@@ -0,0 +1,150 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import matter from "gray-matter";
4
+ import { z } from "zod";
5
+ import { FileNotFoundError, FrontmatterParseError, FrontmatterValidationError, } from "./errors.js";
6
+ /**
7
+ * Validates frontmatter data against the SOPFrontmatter schema
8
+ * @throws FrontmatterValidationError if validation fails
9
+ */
10
+ export function validateFrontmatter(data, filepath) {
11
+ if (typeof data !== "object" || data === null) {
12
+ throw new FrontmatterValidationError(filepath, "frontmatter", "must be an object");
13
+ }
14
+ const obj = data;
15
+ // Validate required 'name' field
16
+ if (!("name" in obj) || obj.name === undefined || obj.name === null) {
17
+ throw new FrontmatterValidationError(filepath, "name", "is required but missing");
18
+ }
19
+ if (typeof obj.name !== "string" || obj.name.trim() === "") {
20
+ throw new FrontmatterValidationError(filepath, "name", "must be a non-empty string");
21
+ }
22
+ // Validate required 'description' field
23
+ if (!("description" in obj) ||
24
+ obj.description === undefined ||
25
+ obj.description === null) {
26
+ throw new FrontmatterValidationError(filepath, "description", "is required but missing");
27
+ }
28
+ if (typeof obj.description !== "string" || obj.description.trim() === "") {
29
+ throw new FrontmatterValidationError(filepath, "description", "must be a non-empty string");
30
+ }
31
+ // Validate 'type' field if present
32
+ if ("type" in obj && obj.type !== undefined) {
33
+ if (obj.type !== "agent" && obj.type !== "orchestrator") {
34
+ throw new FrontmatterValidationError(filepath, "type", 'must be either "agent" or "orchestrator"');
35
+ }
36
+ }
37
+ // Validate optional fields
38
+ const version = typeof obj.version === "string" ? obj.version : undefined;
39
+ const tools = Array.isArray(obj.tools) ? obj.tools : undefined;
40
+ const inputs = typeof obj.inputs === "object" && obj.inputs !== null
41
+ ? obj.inputs
42
+ : undefined;
43
+ const model = typeof obj.model === "string" ? obj.model : undefined;
44
+ return {
45
+ name: obj.name,
46
+ description: obj.description,
47
+ version,
48
+ tools,
49
+ inputs,
50
+ type: obj.type ?? "agent", // Default to "agent"
51
+ model,
52
+ };
53
+ }
54
+ /**
55
+ * Generates a Zod schema from input definitions
56
+ * Always includes a required 'task' field
57
+ */
58
+ export function generateZodSchema(inputs) {
59
+ const shape = {
60
+ task: z.string().describe("The specific task to perform"),
61
+ };
62
+ if (inputs) {
63
+ for (const [fieldName, inputDef] of Object.entries(inputs)) {
64
+ let fieldSchema;
65
+ // Map InputDef type to Zod type
66
+ switch (inputDef.type) {
67
+ case "string":
68
+ fieldSchema = z.string();
69
+ break;
70
+ case "number":
71
+ fieldSchema = z.number();
72
+ break;
73
+ case "boolean":
74
+ fieldSchema = z.boolean();
75
+ break;
76
+ case "enum":
77
+ if (inputDef.values && inputDef.values.length > 0) {
78
+ fieldSchema = z.enum(inputDef.values);
79
+ }
80
+ else {
81
+ fieldSchema = z.string();
82
+ }
83
+ break;
84
+ case "list":
85
+ fieldSchema = z.array(z.string());
86
+ break;
87
+ default:
88
+ fieldSchema = z.string();
89
+ }
90
+ // Apply description
91
+ fieldSchema = fieldSchema.describe(inputDef.description);
92
+ // Apply default value if specified
93
+ if (inputDef.default !== undefined) {
94
+ fieldSchema = fieldSchema.default(inputDef.default);
95
+ }
96
+ // Apply optional if required is false
97
+ if (inputDef.required === false) {
98
+ fieldSchema = fieldSchema.optional();
99
+ }
100
+ shape[fieldName] = fieldSchema;
101
+ }
102
+ }
103
+ return z.object(shape);
104
+ }
105
+ /**
106
+ * Loads and parses an SOP file
107
+ * @throws FileNotFoundError if file doesn't exist
108
+ * @throws FrontmatterParseError if YAML is malformed
109
+ * @throws FrontmatterValidationError if frontmatter validation fails
110
+ */
111
+ export async function loadSOP(filepath) {
112
+ // Check if file exists
113
+ if (!fs.existsSync(filepath)) {
114
+ throw new FileNotFoundError(filepath);
115
+ }
116
+ // Read file content
117
+ const content = fs.readFileSync(filepath, "utf-8");
118
+ // Parse with gray-matter
119
+ let parsed;
120
+ try {
121
+ parsed = matter(content);
122
+ }
123
+ catch (error) {
124
+ const errorMessage = error instanceof Error ? error.message : String(error);
125
+ throw new FrontmatterParseError(filepath, errorMessage);
126
+ }
127
+ // Validate frontmatter
128
+ const frontmatter = validateFrontmatter(parsed.data, filepath);
129
+ // Check if name matches filename (log warning if not)
130
+ const filename = path.basename(filepath, ".md");
131
+ if (frontmatter.name !== filename) {
132
+ console.warn(`Warning: SOP name "${frontmatter.name}" does not match filename "${filename}" in ${filepath}`);
133
+ }
134
+ // Generate Zod schema from inputs
135
+ const zodSchema = generateZodSchema(frontmatter.inputs);
136
+ // Return complete SOPDefinition
137
+ return {
138
+ name: frontmatter.name,
139
+ description: frontmatter.description,
140
+ version: frontmatter.version ?? "1.0.0",
141
+ tools: frontmatter.tools ?? [],
142
+ inputs: frontmatter.inputs ?? {},
143
+ body: parsed.content.trim(),
144
+ filepath,
145
+ type: frontmatter.type ?? "agent",
146
+ zodSchema,
147
+ model: frontmatter.model,
148
+ };
149
+ }
150
+ //# sourceMappingURL=sop-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sop-loader.js","sourceRoot":"","sources":["../src/sop-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACN,iBAAiB,EACjB,qBAAqB,EACrB,0BAA0B,GAC1B,MAAM,aAAa,CAAC;AAGrB;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAClC,IAAa,EACb,QAAgB;IAEhB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC/C,MAAM,IAAI,0BAA0B,CACnC,QAAQ,EACR,aAAa,EACb,mBAAmB,CACnB,CAAC;IACH,CAAC;IAED,MAAM,GAAG,GAAG,IAA+B,CAAC;IAE5C,iCAAiC;IACjC,IAAI,CAAC,CAAC,MA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;QACR,IAAI,EAAE,WAAW,CAAC,IAAI,IAAI,OAAO;QACjC,SAAS;QACT,KAAK,EAAE,WAAW,CAAC,KAAK;KACxB,CAAC;AACH,CAAC"}
@@ -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.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.d.ts","sourceRoot":"","sources":["../src/tool-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAQ,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAEN,KAAK,aAAa,EAElB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAsBhD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAYR;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,aAAa,EAClB,MAAM,CAAC,EAAE;IAAE,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,GACtC,KAAK,CA+BP;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAEvE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,GAAG,SAAS,CAExD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CA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