@serverless-dna/sop-agents 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -0
- package/dist/agents/tool-generator.d.ts +9 -0
- package/dist/agents/tool-generator.d.ts.map +1 -1
- package/dist/agents/tool-generator.js +35 -1
- package/dist/agents/tool-generator.js.map +1 -1
- package/dist/orchestrator/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/orchestrator.js +26 -6
- package/dist/orchestrator/orchestrator.js.map +1 -1
- package/dist/types/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +4 -2
- package/dist/agent-discovery.d.ts +0 -21
- package/dist/agent-discovery.d.ts.map +0 -1
- package/dist/agent-discovery.js +0 -97
- package/dist/agent-discovery.js.map +0 -1
- package/dist/default-orchestrator.d.ts +0 -7
- package/dist/default-orchestrator.d.ts.map +0 -1
- package/dist/default-orchestrator.js +0 -50
- package/dist/default-orchestrator.js.map +0 -1
- package/dist/errors.d.ts +0 -51
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -80
- package/dist/errors.js.map +0 -1
- package/dist/orchestrator.d.ts +0 -50
- package/dist/orchestrator.d.ts.map +0 -1
- package/dist/orchestrator.js +0 -281
- package/dist/orchestrator.js.map +0 -1
- package/dist/sop-loader.d.ts +0 -20
- package/dist/sop-loader.d.ts.map +0 -1
- package/dist/sop-loader.js +0 -150
- package/dist/sop-loader.js.map +0 -1
- package/dist/tool-generator.d.ts +0 -66
- package/dist/tool-generator.d.ts.map +0 -1
- package/dist/tool-generator.js +0 -171
- package/dist/tool-generator.js.map +0 -1
- package/dist/types.d.ts +0 -157
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/dist/errors.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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
|
package/dist/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
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
|
package/dist/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,OAAgC;QAEhD,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAyB;QAGhD,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACxB,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAA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,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"}
|
package/dist/orchestrator.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { InvokeResult, Orchestrator, OrchestratorConfig, OrchestratorStreamEvent, SOPDefinition } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* OrchestratorImpl class implementing the Orchestrator interface
|
|
4
|
-
*/
|
|
5
|
-
export declare class OrchestratorImpl implements Orchestrator {
|
|
6
|
-
private readonly _config;
|
|
7
|
-
private registry;
|
|
8
|
-
private orchestratorAgent;
|
|
9
|
-
private orchestratorSOP;
|
|
10
|
-
private logger;
|
|
11
|
-
private currentCorrelationId?;
|
|
12
|
-
constructor(config?: OrchestratorConfig);
|
|
13
|
-
/**
|
|
14
|
-
* Current configuration (readonly for inspection)
|
|
15
|
-
*/
|
|
16
|
-
get config(): OrchestratorConfig;
|
|
17
|
-
/**
|
|
18
|
-
* Initialize the orchestrator by discovering agents and creating tools
|
|
19
|
-
*/
|
|
20
|
-
initialize(): Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Process a request through the orchestrator agent
|
|
23
|
-
*/
|
|
24
|
-
invoke(request: string): Promise<string>;
|
|
25
|
-
/**
|
|
26
|
-
* Process a request and return detailed result including thinking
|
|
27
|
-
*/
|
|
28
|
-
invokeWithDetails(request: string): Promise<InvokeResult>;
|
|
29
|
-
/**
|
|
30
|
-
* Stream events from the orchestrator in real-time
|
|
31
|
-
*/
|
|
32
|
-
stream(request: string): AsyncGenerator<OrchestratorStreamEvent>;
|
|
33
|
-
/**
|
|
34
|
-
* Clear agent cache
|
|
35
|
-
*/
|
|
36
|
-
clearCache(): void;
|
|
37
|
-
/**
|
|
38
|
-
* Get the agent registry (for inspection/debugging)
|
|
39
|
-
*/
|
|
40
|
-
getRegistry(): Map<string, SOPDefinition>;
|
|
41
|
-
/**
|
|
42
|
-
* Wrap tools with error handling and logging
|
|
43
|
-
*/
|
|
44
|
-
private wrapToolsWithErrorHandling;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Factory function to create and initialize an orchestrator
|
|
48
|
-
*/
|
|
49
|
-
export declare function createOrchestrator(config?: OrchestratorConfig): Promise<Orchestrator>;
|
|
50
|
-
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAEX,YAAY,EAGZ,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,aAAa,EACb,MAAM,YAAY,CAAC;AAqBpB;;GAEG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAyC;IACzD,OAAO,CAAC,iBAAiB,CAAsB;IAC/C,OAAO,CAAC,eAAe,CAA8B;IACrD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,oBAAoB,CAAC,CAAS;gBAE1B,MAAM,GAAE,kBAAuB;IAmB3C;;OAEG;IACH,IAAI,MAAM,IAAI,kBAAkB,CAE/B;IAED;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAoCjC;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAK9C;;OAEG;IACG,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAgG/D;;OAEG;IACI,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAAC,uBAAuB,CAAC;IAiCvE;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;OAEG;IACH,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC;IAIzC;;OAEG;IACH,OAAO,CAAC,0BAA0B;CAwGlC;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,MAAM,GAAE,kBAAuB,GAC7B,OAAO,CAAC,YAAY,CAAC,CAIvB"}
|
package/dist/orchestrator.js
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
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
|
package/dist/orchestrator.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,OAAO,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AAC1E,CAAC;AAcD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACX,OAAO,CAA6B;IAC7C,QAAQ,GAA+B,IAAI,GAAG,EAAE,CAAC;IACjD,iBAAiB,GAAiB,IAAI,CAAC;IACvC,eAAe,GAAyB,IAAI,CAAC;IAC7C,MAAM,CAAS;IACf,oBAAoB,CAAU;IAEtC,YAAY,SAA6B,EAAE;QAC1C,IAAI,CAAC,OAAO,GAAG;YACd,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,QAAQ;YACvC,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,WAAW;YAC1C,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,MAAM;YACnC,YAAY,EAAE,MAAM,CAAC,YAAY;YAC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,CAAC;oBACT,gBAAgB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;gBACrC,CAAC;gBAED,YAAY,CAAC,IAAI,CAChB,8BAA8B,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,SAAS,MAAM,CACvE,CAAC;gBAEF,+DAA+D;gBAC/D,OAAO,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACzC,CAAC,CAAC;YAEF,8DAA8D;YAC9D,MAAM,WAAW,GAAmD;gBACnE,IAAI,EAAE,YAAY,CAAC,IAAI;gBACvB,WAAW,EAAE,YAAY,CAAC,WAAW;gBACrC,QAAQ,EAAE,YAAY,CAAC,QAAQ;gBAC/B,MAAM,EAAE,aAAa;gBACrB,MAAM,EAAE,aAAa;aACrB,CAAC;YAEF,OAAO,WAAW,CAAC;QACpB,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,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"}
|
package/dist/sop-loader.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
|
package/dist/sop-loader.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/sop-loader.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
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
|