@loopman/langchain-sdk 1.7.0 → 1.12.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.
- package/README.md +78 -5
- package/dist/agents/loopman-agent.d.ts.map +1 -1
- package/dist/agents/loopman-agent.js +51 -92
- package/dist/agents/loopman-agent.js.map +1 -1
- package/dist/client/loopman-api.d.ts +19 -64
- package/dist/client/loopman-api.d.ts.map +1 -1
- package/dist/client/loopman-api.js +85 -248
- package/dist/client/loopman-api.js.map +1 -1
- package/dist/helpers/prompt-orchestrator.js +17 -17
- package/dist/helpers/prompt-orchestrator.js.map +1 -1
- package/dist/helpers/template-generator-static.d.ts +27 -0
- package/dist/helpers/template-generator-static.d.ts.map +1 -0
- package/dist/helpers/template-generator-static.js +52 -0
- package/dist/helpers/template-generator-static.js.map +1 -0
- package/dist/helpers/template-generator.d.ts +50 -0
- package/dist/helpers/template-generator.d.ts.map +1 -0
- package/dist/helpers/template-generator.js +85 -0
- package/dist/helpers/template-generator.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/langgraph/helpers.d.ts +171 -0
- package/dist/langgraph/helpers.d.ts.map +1 -0
- package/dist/langgraph/helpers.js +216 -0
- package/dist/langgraph/helpers.js.map +1 -0
- package/dist/langgraph/index.d.ts +16 -0
- package/dist/langgraph/index.d.ts.map +1 -0
- package/dist/langgraph/index.js +17 -0
- package/dist/langgraph/index.js.map +1 -0
- package/dist/langgraph/loopman-conditional-edge.d.ts +58 -0
- package/dist/langgraph/loopman-conditional-edge.d.ts.map +1 -0
- package/dist/langgraph/loopman-conditional-edge.js +77 -0
- package/dist/langgraph/loopman-conditional-edge.js.map +1 -0
- package/dist/langgraph/loopman-context-node.d.ts +74 -0
- package/dist/langgraph/loopman-context-node.d.ts.map +1 -0
- package/dist/langgraph/loopman-context-node.js +143 -0
- package/dist/langgraph/loopman-context-node.js.map +1 -0
- package/dist/langgraph/loopman-validation-node.d.ts +119 -0
- package/dist/langgraph/loopman-validation-node.d.ts.map +1 -0
- package/dist/langgraph/loopman-validation-node.js +420 -0
- package/dist/langgraph/loopman-validation-node.js.map +1 -0
- package/dist/langgraph/types.d.ts +75 -0
- package/dist/langgraph/types.d.ts.map +1 -0
- package/dist/langgraph/types.js +74 -0
- package/dist/langgraph/types.js.map +1 -0
- package/dist/loopman-agent-wrapper.d.ts +18 -0
- package/dist/loopman-agent-wrapper.d.ts.map +1 -1
- package/dist/loopman-agent-wrapper.js +31 -21
- package/dist/loopman-agent-wrapper.js.map +1 -1
- package/dist/loopman-middleware.d.ts +0 -5
- package/dist/loopman-middleware.d.ts.map +1 -1
- package/dist/loopman-middleware.js +22 -23
- package/dist/loopman-middleware.js.map +1 -1
- package/dist/mcp/loopman-mcp-client.d.ts.map +1 -1
- package/dist/mcp/loopman-mcp-client.js +5 -0
- package/dist/mcp/loopman-mcp-client.js.map +1 -1
- package/dist/mcp/tool-registry.d.ts +7 -1
- package/dist/mcp/tool-registry.d.ts.map +1 -1
- package/dist/mcp/tool-registry.js +23 -16
- package/dist/mcp/tool-registry.js.map +1 -1
- package/dist/services/logger.service.d.ts.map +1 -1
- package/dist/services/logger.service.js +4 -12
- package/dist/services/logger.service.js.map +1 -1
- package/dist/services/loopman.service.d.ts +25 -11
- package/dist/services/loopman.service.d.ts.map +1 -1
- package/dist/services/loopman.service.js +74 -45
- package/dist/services/loopman.service.js.map +1 -1
- package/dist/services/polling.service.d.ts +7 -3
- package/dist/services/polling.service.d.ts.map +1 -1
- package/dist/services/polling.service.js +61 -47
- package/dist/services/polling.service.js.map +1 -1
- package/dist/templates.json +20 -0
- package/dist/types.d.ts +9 -35
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/examples/README.md +346 -0
- package/examples/templates/README.md +285 -0
- package/examples/templates/langchain-full-review/.env.example +3 -0
- package/examples/templates/langchain-full-review/README.md +165 -0
- package/examples/templates/langchain-full-review/index.ts +54 -0
- package/examples/templates/langchain-full-review/package.json +29 -0
- package/examples/templates/langchain-full-review/tsconfig.json +22 -0
- package/examples/templates/langchain-tool-validation/.env.example +3 -0
- package/examples/templates/langchain-tool-validation/README.md +137 -0
- package/examples/templates/langchain-tool-validation/index.ts +65 -0
- package/examples/templates/langchain-tool-validation/package.json +29 -0
- package/examples/templates/langchain-tool-validation/tsconfig.json +22 -0
- package/examples/templates/langgraph-hello-world/.env.example +3 -0
- package/examples/templates/langgraph-hello-world/README.md +71 -0
- package/examples/templates/langgraph-hello-world/index.ts +147 -0
- package/examples/templates/langgraph-hello-world/package.json +27 -0
- package/examples/templates/langgraph-hello-world/tsconfig.json +22 -0
- package/package.json +12 -7
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Generator Utility (Static Version)
|
|
3
|
+
*
|
|
4
|
+
* This is a browser-compatible version that uses pre-exported templates
|
|
5
|
+
* instead of reading from the file system.
|
|
6
|
+
*
|
|
7
|
+
* This version is used by the web application.
|
|
8
|
+
*/
|
|
9
|
+
// Import the pre-exported templates JSON
|
|
10
|
+
// This file is generated during build by scripts/export-templates.js
|
|
11
|
+
import templates from '../../dist/templates.json';
|
|
12
|
+
/**
|
|
13
|
+
* Get the LangGraph Hello World template files with variable substitution
|
|
14
|
+
*
|
|
15
|
+
* This uses pre-exported templates and applies variable substitution.
|
|
16
|
+
*
|
|
17
|
+
* @param config - Template configuration with workflowId, apiKey, and sdkVersion
|
|
18
|
+
* @returns Array of template files ready to be zipped
|
|
19
|
+
*/
|
|
20
|
+
export function getLangGraphHelloWorldTemplate(config) {
|
|
21
|
+
const { workflowId, apiKey, sdkVersion } = config;
|
|
22
|
+
// Get the template from the pre-exported JSON
|
|
23
|
+
const template = templates['langgraph-hello-world'];
|
|
24
|
+
if (!template) {
|
|
25
|
+
throw new Error('LangGraph Hello World template not found');
|
|
26
|
+
}
|
|
27
|
+
// Get template files
|
|
28
|
+
const indexTs = template['index.ts'];
|
|
29
|
+
const packageJson = template['package.json'];
|
|
30
|
+
const tsconfig = template['tsconfig.json'];
|
|
31
|
+
const readme = template['README.md'];
|
|
32
|
+
// Generate .env.example
|
|
33
|
+
const envExample = `OPENAI_API_KEY=your-openai-api-key-here
|
|
34
|
+
LOOPMAN_API_KEY=${apiKey || "your-loopman-api-key-here"}
|
|
35
|
+
LOOPMAN_WORKFLOW_ID=${workflowId}
|
|
36
|
+
`;
|
|
37
|
+
// Apply replacements to package.json if sdkVersion is provided
|
|
38
|
+
let processedPackageJson = packageJson;
|
|
39
|
+
if (sdkVersion) {
|
|
40
|
+
const pkgData = JSON.parse(packageJson);
|
|
41
|
+
pkgData.dependencies["@loopman/langchain-sdk"] = `^${sdkVersion}`;
|
|
42
|
+
processedPackageJson = JSON.stringify(pkgData, null, 2) + "\n";
|
|
43
|
+
}
|
|
44
|
+
return [
|
|
45
|
+
{ path: "index.ts", content: indexTs },
|
|
46
|
+
{ path: "package.json", content: processedPackageJson },
|
|
47
|
+
{ path: "tsconfig.json", content: tsconfig },
|
|
48
|
+
{ path: ".env.example", content: envExample },
|
|
49
|
+
{ path: "README.md", content: readme },
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=template-generator-static.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-generator-static.js","sourceRoot":"","sources":["../../src/helpers/template-generator-static.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,yCAAyC;AACzC,qEAAqE;AACrE,OAAO,SAAS,MAAM,2BAA2B,CAAC;AAalD;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B,CAC5C,MAAsB;IAEtB,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAElD,8CAA8C;IAC9C,MAAM,QAAQ,GAAG,SAAS,CAAC,uBAAuB,CAAC,CAAC;IAEpD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED,qBAAqB;IACrB,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;IACrC,MAAM,WAAW,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;IAErC,wBAAwB;IACxB,MAAM,UAAU,GAAG;kBACH,MAAM,IAAI,2BAA2B;sBACjC,UAAU;CAC/B,CAAC;IAEA,+DAA+D;IAC/D,IAAI,oBAAoB,GAAG,WAAW,CAAC;IACvC,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACxC,OAAO,CAAC,YAAY,CAAC,wBAAwB,CAAC,GAAG,IAAI,UAAU,EAAE,CAAC;QAClE,oBAAoB,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;IACjE,CAAC;IAED,OAAO;QACL,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE;QACtC,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,oBAAoB,EAAE;QACvD,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE;QAC5C,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE;QAC7C,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE;KACvC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Generator Utility
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities to generate project templates from the SDK examples.
|
|
5
|
+
* These templates are used by the Loopman Web UI to generate downloadable starter projects.
|
|
6
|
+
*
|
|
7
|
+
* The templates are stored as real, functional examples in examples/templates/ that can be
|
|
8
|
+
* tested and run independently. This ensures they always work correctly.
|
|
9
|
+
*/
|
|
10
|
+
export interface TemplateConfig {
|
|
11
|
+
workflowId: string;
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
sdkVersion?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface TemplateFile {
|
|
16
|
+
path: string;
|
|
17
|
+
content: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get the LangGraph Hello World template files with variable substitution
|
|
21
|
+
*
|
|
22
|
+
* This reads the actual working example from examples/templates/langgraph-hello-world
|
|
23
|
+
* and replaces placeholders with the provided configuration.
|
|
24
|
+
*
|
|
25
|
+
* @param config - Template configuration with workflowId, apiKey, and sdkVersion
|
|
26
|
+
* @returns Array of template files ready to be zipped
|
|
27
|
+
*/
|
|
28
|
+
export declare function getLangGraphHelloWorldTemplate(config: TemplateConfig): TemplateFile[];
|
|
29
|
+
/**
|
|
30
|
+
* Get the LangChain Tool Validation template files with variable substitution
|
|
31
|
+
*
|
|
32
|
+
* @param config - Template configuration with workflowId, apiKey, and sdkVersion
|
|
33
|
+
* @returns Array of template files ready to be zipped
|
|
34
|
+
*/
|
|
35
|
+
export declare function getLangChainToolValidationTemplate(config: TemplateConfig): TemplateFile[];
|
|
36
|
+
/**
|
|
37
|
+
* Get the LangChain Full Review template files with variable substitution
|
|
38
|
+
*
|
|
39
|
+
* @param config - Template configuration with workflowId, apiKey, and sdkVersion
|
|
40
|
+
* @returns Array of template files ready to be zipped
|
|
41
|
+
*/
|
|
42
|
+
export declare function getLangChainFullReviewTemplate(config: TemplateConfig): TemplateFile[];
|
|
43
|
+
/**
|
|
44
|
+
* Get the latest SDK version from package.json
|
|
45
|
+
* This can be used to automatically set the SDK version in templates
|
|
46
|
+
*
|
|
47
|
+
* @returns The current SDK version
|
|
48
|
+
*/
|
|
49
|
+
export declare function getSdkVersion(): string;
|
|
50
|
+
//# sourceMappingURL=template-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-generator.d.ts","sourceRoot":"","sources":["../../src/helpers/template-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAoDD;;;;;;;;GAQG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,cAAc,GACrB,YAAY,EAAE,CAEhB;AAED;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAChD,MAAM,EAAE,cAAc,GACrB,YAAY,EAAE,CAEhB;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,cAAc,GACrB,YAAY,EAAE,CAEhB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAItC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Generator Utility
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities to generate project templates from the SDK examples.
|
|
5
|
+
* These templates are used by the Loopman Web UI to generate downloadable starter projects.
|
|
6
|
+
*
|
|
7
|
+
* The templates are stored as real, functional examples in examples/templates/ that can be
|
|
8
|
+
* tested and run independently. This ensures they always work correctly.
|
|
9
|
+
*/
|
|
10
|
+
import * as fs from "fs";
|
|
11
|
+
import * as path from "path";
|
|
12
|
+
/**
|
|
13
|
+
* Helper function to get template files from a specific template directory
|
|
14
|
+
*/
|
|
15
|
+
function getTemplateFiles(templateName, config) {
|
|
16
|
+
const { workflowId, apiKey, sdkVersion } = config;
|
|
17
|
+
// Path to the template directory (relative to this file)
|
|
18
|
+
const templateDir = path.join(__dirname, `../../examples/templates/${templateName}`);
|
|
19
|
+
// Read template files
|
|
20
|
+
const indexTs = fs.readFileSync(path.join(templateDir, "index.ts"), "utf-8");
|
|
21
|
+
const packageJson = fs.readFileSync(path.join(templateDir, "package.json"), "utf-8");
|
|
22
|
+
const tsconfig = fs.readFileSync(path.join(templateDir, "tsconfig.json"), "utf-8");
|
|
23
|
+
const readme = fs.readFileSync(path.join(templateDir, "README.md"), "utf-8");
|
|
24
|
+
// Generate .env.example
|
|
25
|
+
const envExample = `OPENAI_API_KEY=your-openai-api-key-here
|
|
26
|
+
LOOPMAN_API_KEY=${apiKey || "your-loopman-api-key-here"}
|
|
27
|
+
LOOPMAN_WORKFLOW_ID=${workflowId}
|
|
28
|
+
`;
|
|
29
|
+
// Apply replacements to package.json if sdkVersion is provided
|
|
30
|
+
let processedPackageJson = packageJson;
|
|
31
|
+
if (sdkVersion) {
|
|
32
|
+
const pkgData = JSON.parse(packageJson);
|
|
33
|
+
pkgData.dependencies["@loopman/langchain-sdk"] = `^${sdkVersion}`;
|
|
34
|
+
processedPackageJson = JSON.stringify(pkgData, null, 2) + "\n";
|
|
35
|
+
}
|
|
36
|
+
return [
|
|
37
|
+
{ path: "index.ts", content: indexTs },
|
|
38
|
+
{ path: "package.json", content: processedPackageJson },
|
|
39
|
+
{ path: "tsconfig.json", content: tsconfig },
|
|
40
|
+
{ path: ".env.example", content: envExample },
|
|
41
|
+
{ path: "README.md", content: readme },
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get the LangGraph Hello World template files with variable substitution
|
|
46
|
+
*
|
|
47
|
+
* This reads the actual working example from examples/templates/langgraph-hello-world
|
|
48
|
+
* and replaces placeholders with the provided configuration.
|
|
49
|
+
*
|
|
50
|
+
* @param config - Template configuration with workflowId, apiKey, and sdkVersion
|
|
51
|
+
* @returns Array of template files ready to be zipped
|
|
52
|
+
*/
|
|
53
|
+
export function getLangGraphHelloWorldTemplate(config) {
|
|
54
|
+
return getTemplateFiles("langgraph-hello-world", config);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get the LangChain Tool Validation template files with variable substitution
|
|
58
|
+
*
|
|
59
|
+
* @param config - Template configuration with workflowId, apiKey, and sdkVersion
|
|
60
|
+
* @returns Array of template files ready to be zipped
|
|
61
|
+
*/
|
|
62
|
+
export function getLangChainToolValidationTemplate(config) {
|
|
63
|
+
return getTemplateFiles("langchain-tool-validation", config);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the LangChain Full Review template files with variable substitution
|
|
67
|
+
*
|
|
68
|
+
* @param config - Template configuration with workflowId, apiKey, and sdkVersion
|
|
69
|
+
* @returns Array of template files ready to be zipped
|
|
70
|
+
*/
|
|
71
|
+
export function getLangChainFullReviewTemplate(config) {
|
|
72
|
+
return getTemplateFiles("langchain-full-review", config);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get the latest SDK version from package.json
|
|
76
|
+
* This can be used to automatically set the SDK version in templates
|
|
77
|
+
*
|
|
78
|
+
* @returns The current SDK version
|
|
79
|
+
*/
|
|
80
|
+
export function getSdkVersion() {
|
|
81
|
+
const packageJsonPath = path.join(__dirname, "../../package.json");
|
|
82
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
83
|
+
return packageJson.version;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=template-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-generator.js","sourceRoot":"","sources":["../../src/helpers/template-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAa7B;;GAEG;AACH,SAAS,gBAAgB,CACvB,YAAoB,EACpB,MAAsB;IAEtB,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IA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E,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE;QAC7C,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE;KACvC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,8BAA8B,CAC5C,MAAsB;IAEtB,OAAO,gBAAgB,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kCAAkC,CAChD,MAAsB;IAEtB,OAAO,gBAAgB,CAAC,2BAA2B,EAAE,MAAM,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAC5C,MAAsB;IAEtB,OAAO,gBAAgB,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;IACnE,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1E,OAAO,WAAW,CAAC,OAAO,CAAC;AAC7B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,9 +9,14 @@ export { createLoopmanAgent as createLoopmanAgentWrapper, createLoopmanAgent as
|
|
|
9
9
|
streamWithRetry, } from "./loopman-agent-wrapper";
|
|
10
10
|
export { createLoopmanAgent, LoopmanAgent } from "./agents/loopman-agent";
|
|
11
11
|
export { buildLoopmanSystemPrompt, extractConfidence, extractTaskId, } from "./helpers/prompt-orchestrator";
|
|
12
|
+
export { getLangGraphHelloWorldTemplate, getLangChainToolValidationTemplate, getLangChainFullReviewTemplate, } from "./helpers/template-generator";
|
|
13
|
+
export { getLangGraphHelloWorldTemplate as getLangGraphHelloWorldTemplateStatic, } from "./helpers/template-generator-static";
|
|
14
|
+
export type { TemplateConfig, TemplateFile, } from "./helpers/template-generator";
|
|
12
15
|
export { LoopmanMcpClient } from "./mcp/loopman-mcp-client";
|
|
16
|
+
export { LoopmanGraphState, createLoopmanValidationNode, createLoopmanConditionalEdge, createLoopmanContextNode, enrichSystemPrompt, formatGuidelines, formatDecisionContext, hasLoopmanContext, getCriticalGuidelines, getLatestDecision, } from "./langgraph";
|
|
17
|
+
export type { LoopmanValidationNodeConfig, LoopmanContextNodeConfig, LoopmanGuideline, LoopmanDecision as LoopmanDecisionContext, EnrichSystemPromptOptions, } from "./langgraph";
|
|
13
18
|
export { LoopmanApiClient } from "./client/loopman-api";
|
|
14
19
|
export * from "./services";
|
|
15
|
-
export type {
|
|
20
|
+
export type { LoopmanConfig, LoopmanUser, } from "./types";
|
|
16
21
|
export { LoopmanConnectionError, LoopmanError, LoopmanTimeoutError, LoopmanValidationError, } from "./types";
|
|
17
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EACV,eAAe,EACf,uBAAuB,EACvB,QAAQ,GACT,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,kBAAkB,IAAI,yBAAyB,EAC/C,kBAAkB,IAAI,4BAA4B,EAClD,eAAe,EAAE,kDAAkD;AACnE,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG1E,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,aAAa,GACd,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG5D,OAAO,EAAE,gBAAgB,EAAE,MA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EACb,WAAW,GACZ,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12,8 +12,14 @@ streamWithRetry, } from "./loopman-agent-wrapper";
|
|
|
12
12
|
export { createLoopmanAgent, LoopmanAgent } from "./agents/loopman-agent";
|
|
13
13
|
// Prompt helpers
|
|
14
14
|
export { buildLoopmanSystemPrompt, extractConfidence, extractTaskId, } from "./helpers/prompt-orchestrator";
|
|
15
|
+
// Template generator (for Node.js/server-side)
|
|
16
|
+
export { getLangGraphHelloWorldTemplate, getLangChainToolValidationTemplate, getLangChainFullReviewTemplate, } from "./helpers/template-generator";
|
|
17
|
+
// Template generator static (for web/browser)
|
|
18
|
+
export { getLangGraphHelloWorldTemplate as getLangGraphHelloWorldTemplateStatic, } from "./helpers/template-generator-static";
|
|
15
19
|
// MCP utilities
|
|
16
20
|
export { LoopmanMcpClient } from "./mcp/loopman-mcp-client";
|
|
21
|
+
// LangGraph integration (re-export from centralized index)
|
|
22
|
+
export { LoopmanGraphState, createLoopmanValidationNode, createLoopmanConditionalEdge, createLoopmanContextNode, enrichSystemPrompt, formatGuidelines, formatDecisionContext, hasLoopmanContext, getCriticalGuidelines, getLatestDecision, } from "./langgraph";
|
|
17
23
|
// Client exports
|
|
18
24
|
export { LoopmanApiClient } from "./client/loopman-api";
|
|
19
25
|
// Service exports (import from services/index.ts for centralized exports)
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qBAAqB;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAOzD,+DAA+D;AAC/D,OAAO,EACL,kBAAkB,IAAI,yBAAyB,EAC/C,kBAAkB,IAAI,4BAA4B,EAClD,eAAe,EAA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AClB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AASrB,iBAAiB;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,0EAA0E;AAC1E,cAAc,YAAY,CAAC;AAQ3B,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions for LangGraph integration with Loopman
|
|
3
|
+
*/
|
|
4
|
+
import type { LoopmanDecision, LoopmanGuideline } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for enriching system prompts
|
|
7
|
+
*/
|
|
8
|
+
export interface EnrichSystemPromptOptions {
|
|
9
|
+
/** Whether to include guidelines (default: true) */
|
|
10
|
+
includeGuidelines?: boolean;
|
|
11
|
+
/** Whether to include decision context (default: true) */
|
|
12
|
+
includeDecisionContext?: boolean;
|
|
13
|
+
/** Maximum number of historical decisions to show (default: 3) */
|
|
14
|
+
maxDecisions?: number;
|
|
15
|
+
/** Custom header for guidelines section */
|
|
16
|
+
guidelinesHeader?: string;
|
|
17
|
+
/** Custom header for decision context section */
|
|
18
|
+
decisionContextHeader?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Enriches a system prompt with Loopman guidelines and decision context
|
|
22
|
+
*
|
|
23
|
+
* This helper function automatically formats and appends validation guidelines
|
|
24
|
+
* and historical decision context to your agent's system prompt.
|
|
25
|
+
*
|
|
26
|
+
* **Works with any state**: This function accepts any state object and only
|
|
27
|
+
* checks for `guidelines` and `decisionContext` properties. You don't need
|
|
28
|
+
* to use `LoopmanGraphState` - it works with your custom state too!
|
|
29
|
+
*
|
|
30
|
+
* @param basePrompt - The base system prompt to enrich
|
|
31
|
+
* @param state - Any state object (checks for guidelines and decisionContext)
|
|
32
|
+
* @param options - Optional configuration for formatting
|
|
33
|
+
* @returns Enriched system prompt with Loopman context
|
|
34
|
+
*
|
|
35
|
+
* @example With LoopmanGraphState
|
|
36
|
+
* ```typescript
|
|
37
|
+
* async function agentNode(state: typeof LoopmanGraphState.State) {
|
|
38
|
+
* const systemPrompt = enrichSystemPrompt(
|
|
39
|
+
* "You are a helpful email assistant.",
|
|
40
|
+
* state // Pass entire state, extracts what it needs
|
|
41
|
+
* );
|
|
42
|
+
*
|
|
43
|
+
* const response = await model.invoke([
|
|
44
|
+
* { role: "system", content: systemPrompt },
|
|
45
|
+
* ...messages,
|
|
46
|
+
* ]);
|
|
47
|
+
*
|
|
48
|
+
* return { messages: [response] };
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example With custom state
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const MyCustomState = Annotation.Root({
|
|
55
|
+
* messages: Annotation<BaseMessage[]>({ ... }),
|
|
56
|
+
* myCustomField: Annotation<string>({ ... }),
|
|
57
|
+
* guidelines: Annotation<LoopmanGuideline[]>({ ... }), // Optional Loopman field
|
|
58
|
+
* decisionContext: Annotation<LoopmanDecision[]>({ ... }), // Optional Loopman field
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* async function agentNode(state: typeof MyCustomState.State) {
|
|
62
|
+
* // Works seamlessly with custom state!
|
|
63
|
+
* const systemPrompt = enrichSystemPrompt(
|
|
64
|
+
* "You are a helpful assistant.",
|
|
65
|
+
* state
|
|
66
|
+
* );
|
|
67
|
+
*
|
|
68
|
+
* return { messages: [response] };
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example With custom options
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const systemPrompt = enrichSystemPrompt(
|
|
75
|
+
* "You are a helpful assistant.",
|
|
76
|
+
* state,
|
|
77
|
+
* {
|
|
78
|
+
* maxDecisions: 5,
|
|
79
|
+
* guidelinesHeader: "📋 Company Policies",
|
|
80
|
+
* includeDecisionContext: false, // Skip decision history
|
|
81
|
+
* }
|
|
82
|
+
* );
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function enrichSystemPrompt(basePrompt: string, state: any, // Accept any state object
|
|
86
|
+
options?: EnrichSystemPromptOptions): string;
|
|
87
|
+
/**
|
|
88
|
+
* Formats guidelines as a structured string for logging or display
|
|
89
|
+
*
|
|
90
|
+
* @param guidelines - Array of Loopman guidelines
|
|
91
|
+
* @returns Formatted string representation of guidelines
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const formatted = formatGuidelines(state.guidelines);
|
|
96
|
+
* console.log(formatted);
|
|
97
|
+
* // Output:
|
|
98
|
+
* // 📋 3 Guideline(s):
|
|
99
|
+
* // - [CRITICAL] Never send emails without approval
|
|
100
|
+
* // - [MAJOR] Always validate email addresses
|
|
101
|
+
* // - [MINOR] Include signature in all emails
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare function formatGuidelines(guidelines: LoopmanGuideline[]): string;
|
|
105
|
+
/**
|
|
106
|
+
* Formats decision context as a structured string for logging or display
|
|
107
|
+
*
|
|
108
|
+
* @param decisions - Array of Loopman decisions
|
|
109
|
+
* @param maxDecisions - Maximum number of decisions to show (default: all)
|
|
110
|
+
* @returns Formatted string representation of decision history
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const formatted = formatDecisionContext(state.decisionContext, 3);
|
|
115
|
+
* console.log(formatted);
|
|
116
|
+
* // Output:
|
|
117
|
+
* // 📜 3 Recent Decision(s):
|
|
118
|
+
* // - APPROVED by USER: "Looks good"
|
|
119
|
+
* // - NEEDS_CHANGES by USER: "Fix the subject line"
|
|
120
|
+
* // - APPROVED by USER
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function formatDecisionContext(decisions: LoopmanDecision[], maxDecisions?: number): string;
|
|
124
|
+
/**
|
|
125
|
+
* Checks if the state contains any Loopman context (guidelines or decisions)
|
|
126
|
+
*
|
|
127
|
+
* Works with any state object - simply checks for the presence of
|
|
128
|
+
* `guidelines` or `decisionContext` properties.
|
|
129
|
+
*
|
|
130
|
+
* @param state - Any state object (checks for guidelines and decisionContext)
|
|
131
|
+
* @returns True if state has guidelines or decision context
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* if (hasLoopmanContext(state)) {
|
|
136
|
+
* console.log("Using Loopman context for enhanced decision-making");
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function hasLoopmanContext(state: any): boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Extracts critical guidelines from a list
|
|
143
|
+
*
|
|
144
|
+
* @param guidelines - Array of Loopman guidelines
|
|
145
|
+
* @returns Array containing only critical severity guidelines
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const criticalGuidelines = getCriticalGuidelines(state.guidelines);
|
|
150
|
+
* if (criticalGuidelines.length > 0) {
|
|
151
|
+
* console.warn(`${criticalGuidelines.length} critical guideline(s) must be followed!`);
|
|
152
|
+
* }
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare function getCriticalGuidelines(guidelines: LoopmanGuideline[]): LoopmanGuideline[];
|
|
156
|
+
/**
|
|
157
|
+
* Gets the latest decision from decision context
|
|
158
|
+
*
|
|
159
|
+
* @param decisions - Array of Loopman decisions
|
|
160
|
+
* @returns The most recent decision, or null if empty
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const latestDecision = getLatestDecision(state.decisionContext);
|
|
165
|
+
* if (latestDecision?.status === "NEEDS_CHANGES") {
|
|
166
|
+
* console.log("Previous attempt needs changes:", latestDecision.comment);
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function getLatestDecision(decisions: LoopmanDecision[]): LoopmanDecision | null;
|
|
171
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/langgraph/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,0DAA0D;IAC1D,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iDAAiD;IACjD,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,GAAG,EAAE,0BAA0B;AACtC,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAwCR;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAUvE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,eAAe,EAAE,EAC5B,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,CAkBR;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAKrD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,gBAAgB,EAAE,GAC7B,gBAAgB,EAAE,CAEpB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,eAAe,EAAE,GAC3B,eAAe,GAAG,IAAI,CAKxB"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions for LangGraph integration with Loopman
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Enriches a system prompt with Loopman guidelines and decision context
|
|
6
|
+
*
|
|
7
|
+
* This helper function automatically formats and appends validation guidelines
|
|
8
|
+
* and historical decision context to your agent's system prompt.
|
|
9
|
+
*
|
|
10
|
+
* **Works with any state**: This function accepts any state object and only
|
|
11
|
+
* checks for `guidelines` and `decisionContext` properties. You don't need
|
|
12
|
+
* to use `LoopmanGraphState` - it works with your custom state too!
|
|
13
|
+
*
|
|
14
|
+
* @param basePrompt - The base system prompt to enrich
|
|
15
|
+
* @param state - Any state object (checks for guidelines and decisionContext)
|
|
16
|
+
* @param options - Optional configuration for formatting
|
|
17
|
+
* @returns Enriched system prompt with Loopman context
|
|
18
|
+
*
|
|
19
|
+
* @example With LoopmanGraphState
|
|
20
|
+
* ```typescript
|
|
21
|
+
* async function agentNode(state: typeof LoopmanGraphState.State) {
|
|
22
|
+
* const systemPrompt = enrichSystemPrompt(
|
|
23
|
+
* "You are a helpful email assistant.",
|
|
24
|
+
* state // Pass entire state, extracts what it needs
|
|
25
|
+
* );
|
|
26
|
+
*
|
|
27
|
+
* const response = await model.invoke([
|
|
28
|
+
* { role: "system", content: systemPrompt },
|
|
29
|
+
* ...messages,
|
|
30
|
+
* ]);
|
|
31
|
+
*
|
|
32
|
+
* return { messages: [response] };
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example With custom state
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const MyCustomState = Annotation.Root({
|
|
39
|
+
* messages: Annotation<BaseMessage[]>({ ... }),
|
|
40
|
+
* myCustomField: Annotation<string>({ ... }),
|
|
41
|
+
* guidelines: Annotation<LoopmanGuideline[]>({ ... }), // Optional Loopman field
|
|
42
|
+
* decisionContext: Annotation<LoopmanDecision[]>({ ... }), // Optional Loopman field
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* async function agentNode(state: typeof MyCustomState.State) {
|
|
46
|
+
* // Works seamlessly with custom state!
|
|
47
|
+
* const systemPrompt = enrichSystemPrompt(
|
|
48
|
+
* "You are a helpful assistant.",
|
|
49
|
+
* state
|
|
50
|
+
* );
|
|
51
|
+
*
|
|
52
|
+
* return { messages: [response] };
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example With custom options
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const systemPrompt = enrichSystemPrompt(
|
|
59
|
+
* "You are a helpful assistant.",
|
|
60
|
+
* state,
|
|
61
|
+
* {
|
|
62
|
+
* maxDecisions: 5,
|
|
63
|
+
* guidelinesHeader: "📋 Company Policies",
|
|
64
|
+
* includeDecisionContext: false, // Skip decision history
|
|
65
|
+
* }
|
|
66
|
+
* );
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function enrichSystemPrompt(basePrompt, state, // Accept any state object
|
|
70
|
+
options = {}) {
|
|
71
|
+
const { includeGuidelines = true, includeDecisionContext = true, maxDecisions = 3, guidelinesHeader = "**Guidelines**", decisionContextHeader = "**Previous Decisions**", } = options;
|
|
72
|
+
let enrichedPrompt = basePrompt;
|
|
73
|
+
// Add guidelines if available and enabled
|
|
74
|
+
if (includeGuidelines && state.guidelines && state.guidelines.length > 0) {
|
|
75
|
+
enrichedPrompt += `\n\n${guidelinesHeader}:\n`;
|
|
76
|
+
state.guidelines.forEach((g) => {
|
|
77
|
+
enrichedPrompt += `- [${g.severity.toUpperCase()}] ${g.description}\n`;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// Add decision context if available and enabled
|
|
81
|
+
if (includeDecisionContext &&
|
|
82
|
+
state.decisionContext &&
|
|
83
|
+
state.decisionContext.length > 0) {
|
|
84
|
+
enrichedPrompt += `\n\n${decisionContextHeader}:\n`;
|
|
85
|
+
// Show only the most recent N decisions
|
|
86
|
+
const recentDecisions = state.decisionContext.slice(-maxDecisions);
|
|
87
|
+
recentDecisions.forEach((d) => {
|
|
88
|
+
enrichedPrompt += `- ${d.status} by ${d.userType}`;
|
|
89
|
+
if (d.comment) {
|
|
90
|
+
enrichedPrompt += `: "${d.comment}"`;
|
|
91
|
+
}
|
|
92
|
+
enrichedPrompt += "\n";
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return enrichedPrompt;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Formats guidelines as a structured string for logging or display
|
|
99
|
+
*
|
|
100
|
+
* @param guidelines - Array of Loopman guidelines
|
|
101
|
+
* @returns Formatted string representation of guidelines
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const formatted = formatGuidelines(state.guidelines);
|
|
106
|
+
* console.log(formatted);
|
|
107
|
+
* // Output:
|
|
108
|
+
* // 📋 3 Guideline(s):
|
|
109
|
+
* // - [CRITICAL] Never send emails without approval
|
|
110
|
+
* // - [MAJOR] Always validate email addresses
|
|
111
|
+
* // - [MINOR] Include signature in all emails
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export function formatGuidelines(guidelines) {
|
|
115
|
+
if (!guidelines || guidelines.length === 0) {
|
|
116
|
+
return "No guidelines available";
|
|
117
|
+
}
|
|
118
|
+
let output = `${guidelines.length} Guideline(s):\n`;
|
|
119
|
+
guidelines.forEach((g) => {
|
|
120
|
+
output += ` - [${g.severity.toUpperCase()}] ${g.description}\n`;
|
|
121
|
+
});
|
|
122
|
+
return output.trim();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Formats decision context as a structured string for logging or display
|
|
126
|
+
*
|
|
127
|
+
* @param decisions - Array of Loopman decisions
|
|
128
|
+
* @param maxDecisions - Maximum number of decisions to show (default: all)
|
|
129
|
+
* @returns Formatted string representation of decision history
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const formatted = formatDecisionContext(state.decisionContext, 3);
|
|
134
|
+
* console.log(formatted);
|
|
135
|
+
* // Output:
|
|
136
|
+
* // 📜 3 Recent Decision(s):
|
|
137
|
+
* // - APPROVED by USER: "Looks good"
|
|
138
|
+
* // - NEEDS_CHANGES by USER: "Fix the subject line"
|
|
139
|
+
* // - APPROVED by USER
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export function formatDecisionContext(decisions, maxDecisions) {
|
|
143
|
+
if (!decisions || decisions.length === 0) {
|
|
144
|
+
return "No decision history available";
|
|
145
|
+
}
|
|
146
|
+
const displayDecisions = maxDecisions
|
|
147
|
+
? decisions.slice(-maxDecisions)
|
|
148
|
+
: decisions;
|
|
149
|
+
let output = `${displayDecisions.length} Recent Decision(s):\n`;
|
|
150
|
+
displayDecisions.forEach((d) => {
|
|
151
|
+
output += ` - ${d.status} by ${d.userType}`;
|
|
152
|
+
if (d.comment) {
|
|
153
|
+
output += `: "${d.comment}"`;
|
|
154
|
+
}
|
|
155
|
+
output += "\n";
|
|
156
|
+
});
|
|
157
|
+
return output.trim();
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Checks if the state contains any Loopman context (guidelines or decisions)
|
|
161
|
+
*
|
|
162
|
+
* Works with any state object - simply checks for the presence of
|
|
163
|
+
* `guidelines` or `decisionContext` properties.
|
|
164
|
+
*
|
|
165
|
+
* @param state - Any state object (checks for guidelines and decisionContext)
|
|
166
|
+
* @returns True if state has guidelines or decision context
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* if (hasLoopmanContext(state)) {
|
|
171
|
+
* console.log("Using Loopman context for enhanced decision-making");
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export function hasLoopmanContext(state) {
|
|
176
|
+
return ((state.guidelines && state.guidelines.length > 0) ||
|
|
177
|
+
(state.decisionContext && state.decisionContext.length > 0));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Extracts critical guidelines from a list
|
|
181
|
+
*
|
|
182
|
+
* @param guidelines - Array of Loopman guidelines
|
|
183
|
+
* @returns Array containing only critical severity guidelines
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const criticalGuidelines = getCriticalGuidelines(state.guidelines);
|
|
188
|
+
* if (criticalGuidelines.length > 0) {
|
|
189
|
+
* console.warn(`${criticalGuidelines.length} critical guideline(s) must be followed!`);
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export function getCriticalGuidelines(guidelines) {
|
|
194
|
+
return guidelines.filter((g) => g.severity === "critical");
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Gets the latest decision from decision context
|
|
198
|
+
*
|
|
199
|
+
* @param decisions - Array of Loopman decisions
|
|
200
|
+
* @returns The most recent decision, or null if empty
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const latestDecision = getLatestDecision(state.decisionContext);
|
|
205
|
+
* if (latestDecision?.status === "NEEDS_CHANGES") {
|
|
206
|
+
* console.log("Previous attempt needs changes:", latestDecision.comment);
|
|
207
|
+
* }
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export function getLatestDecision(decisions) {
|
|
211
|
+
if (!decisions || decisions.length === 0) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
return decisions[decisions.length - 1];
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/langgraph/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;A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