@agentforge/core 0.15.6 → 0.15.7
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/dist/index.cjs +32 -15
- package/dist/index.d.cts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +32 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -794,21 +794,42 @@ function toolBuilder() {
|
|
|
794
794
|
// src/langchain/converter.ts
|
|
795
795
|
var import_tools = require("@langchain/core/tools");
|
|
796
796
|
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
797
|
+
function serializeToolResult(result) {
|
|
798
|
+
if (typeof result === "string") {
|
|
799
|
+
return result;
|
|
800
|
+
}
|
|
801
|
+
if (typeof result === "object" && result !== null) {
|
|
802
|
+
return JSON.stringify(result, null, 2);
|
|
803
|
+
}
|
|
804
|
+
return String(result);
|
|
805
|
+
}
|
|
806
|
+
function isJsonSchemaObject(value) {
|
|
807
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
808
|
+
}
|
|
809
|
+
function isJsonSchemaDefinitionMap(value) {
|
|
810
|
+
if (!isJsonSchemaObject(value)) {
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
return Object.values(value).every(isJsonSchemaObject);
|
|
814
|
+
}
|
|
815
|
+
function extractToolSchema(jsonSchema) {
|
|
816
|
+
if (!isJsonSchemaObject(jsonSchema)) {
|
|
817
|
+
return {};
|
|
818
|
+
}
|
|
819
|
+
const ref = jsonSchema.$ref;
|
|
820
|
+
const definitions = jsonSchema.definitions;
|
|
821
|
+
if (typeof ref !== "string" || !isJsonSchemaDefinitionMap(definitions)) {
|
|
822
|
+
return jsonSchema;
|
|
823
|
+
}
|
|
824
|
+
const refName = ref.replace("#/definitions/", "");
|
|
825
|
+
return definitions[refName] ?? jsonSchema;
|
|
826
|
+
}
|
|
797
827
|
function toLangChainTool(tool) {
|
|
798
828
|
return new import_tools.DynamicStructuredTool({
|
|
799
829
|
name: tool.metadata.name,
|
|
800
830
|
description: tool.metadata.description,
|
|
801
831
|
schema: tool.schema,
|
|
802
|
-
func: async (input) =>
|
|
803
|
-
const result = await tool.invoke(input);
|
|
804
|
-
if (typeof result === "string") {
|
|
805
|
-
return result;
|
|
806
|
-
}
|
|
807
|
-
if (typeof result === "object" && result !== null) {
|
|
808
|
-
return JSON.stringify(result, null, 2);
|
|
809
|
-
}
|
|
810
|
-
return String(result);
|
|
811
|
-
}
|
|
832
|
+
func: async (input) => serializeToolResult(await tool.invoke(input))
|
|
812
833
|
});
|
|
813
834
|
}
|
|
814
835
|
function toLangChainTools(tools) {
|
|
@@ -820,11 +841,7 @@ function getToolJsonSchema(tool) {
|
|
|
820
841
|
$refStrategy: "none"
|
|
821
842
|
// Don't use $ref for nested schemas
|
|
822
843
|
});
|
|
823
|
-
|
|
824
|
-
const refName = jsonSchema.$ref.replace("#/definitions/", "");
|
|
825
|
-
return jsonSchema.definitions[refName] || jsonSchema;
|
|
826
|
-
}
|
|
827
|
-
return jsonSchema;
|
|
844
|
+
return extractToolSchema(jsonSchema);
|
|
828
845
|
}
|
|
829
846
|
function getToolDescription(tool) {
|
|
830
847
|
const { metadata } = tool;
|
package/dist/index.d.cts
CHANGED
|
@@ -1794,6 +1794,13 @@ declare function createToolSimulator(config: ToolSimulatorConfig): {
|
|
|
1794
1794
|
* ```
|
|
1795
1795
|
*/
|
|
1796
1796
|
|
|
1797
|
+
type RuntimeSchema<TInput = unknown> = z.ZodSchema<TInput>;
|
|
1798
|
+
type JsonSchemaObject = Record<string, unknown>;
|
|
1799
|
+
interface LangChainConvertibleTool<TInput = unknown, TOutput = unknown> {
|
|
1800
|
+
metadata: ToolMetadata;
|
|
1801
|
+
schema: RuntimeSchema<TInput>;
|
|
1802
|
+
invoke(input: TInput): Promise<TOutput>;
|
|
1803
|
+
}
|
|
1797
1804
|
/**
|
|
1798
1805
|
* Convert an AgentForge tool to a LangChain DynamicStructuredTool
|
|
1799
1806
|
*
|
|
@@ -1826,7 +1833,7 @@ declare function createToolSimulator(config: ToolSimulatorConfig): {
|
|
|
1826
1833
|
* });
|
|
1827
1834
|
* ```
|
|
1828
1835
|
*/
|
|
1829
|
-
declare function toLangChainTool(tool: Tool<
|
|
1836
|
+
declare function toLangChainTool<TInput, TOutput>(tool: Tool<TInput, TOutput>): DynamicStructuredTool<RuntimeSchema<TInput>, TInput, TInput, string>;
|
|
1830
1837
|
/**
|
|
1831
1838
|
* Convert multiple AgentForge tools to LangChain tools
|
|
1832
1839
|
*
|
|
@@ -1844,7 +1851,7 @@ declare function toLangChainTool(tool: Tool<any, any>): DynamicStructuredTool<an
|
|
|
1844
1851
|
* });
|
|
1845
1852
|
* ```
|
|
1846
1853
|
*/
|
|
1847
|
-
declare function toLangChainTools(tools:
|
|
1854
|
+
declare function toLangChainTools(tools: readonly LangChainConvertibleTool[]): DynamicStructuredTool[];
|
|
1848
1855
|
/**
|
|
1849
1856
|
* Get the JSON Schema representation of a tool's input schema
|
|
1850
1857
|
*
|
|
@@ -1859,7 +1866,7 @@ declare function toLangChainTools(tools: Tool<any, any>[]): DynamicStructuredToo
|
|
|
1859
1866
|
* console.log(JSON.stringify(schema, null, 2));
|
|
1860
1867
|
* ```
|
|
1861
1868
|
*/
|
|
1862
|
-
declare function getToolJsonSchema(tool: Tool<
|
|
1869
|
+
declare function getToolJsonSchema<TInput, TOutput>(tool: Tool<TInput, TOutput>): JsonSchemaObject;
|
|
1863
1870
|
/**
|
|
1864
1871
|
* Get tool metadata in a format suitable for LLM prompts
|
|
1865
1872
|
*
|
|
@@ -1880,7 +1887,7 @@ declare function getToolJsonSchema(tool: Tool<any, any>): Record<string, any>;
|
|
|
1880
1887
|
* // ...
|
|
1881
1888
|
* ```
|
|
1882
1889
|
*/
|
|
1883
|
-
declare function getToolDescription(tool: Tool<
|
|
1890
|
+
declare function getToolDescription<TInput, TOutput>(tool: Tool<TInput, TOutput>): string;
|
|
1884
1891
|
|
|
1885
1892
|
/**
|
|
1886
1893
|
* LangGraph State Utilities
|
package/dist/index.d.ts
CHANGED
|
@@ -1794,6 +1794,13 @@ declare function createToolSimulator(config: ToolSimulatorConfig): {
|
|
|
1794
1794
|
* ```
|
|
1795
1795
|
*/
|
|
1796
1796
|
|
|
1797
|
+
type RuntimeSchema<TInput = unknown> = z.ZodSchema<TInput>;
|
|
1798
|
+
type JsonSchemaObject = Record<string, unknown>;
|
|
1799
|
+
interface LangChainConvertibleTool<TInput = unknown, TOutput = unknown> {
|
|
1800
|
+
metadata: ToolMetadata;
|
|
1801
|
+
schema: RuntimeSchema<TInput>;
|
|
1802
|
+
invoke(input: TInput): Promise<TOutput>;
|
|
1803
|
+
}
|
|
1797
1804
|
/**
|
|
1798
1805
|
* Convert an AgentForge tool to a LangChain DynamicStructuredTool
|
|
1799
1806
|
*
|
|
@@ -1826,7 +1833,7 @@ declare function createToolSimulator(config: ToolSimulatorConfig): {
|
|
|
1826
1833
|
* });
|
|
1827
1834
|
* ```
|
|
1828
1835
|
*/
|
|
1829
|
-
declare function toLangChainTool(tool: Tool<
|
|
1836
|
+
declare function toLangChainTool<TInput, TOutput>(tool: Tool<TInput, TOutput>): DynamicStructuredTool<RuntimeSchema<TInput>, TInput, TInput, string>;
|
|
1830
1837
|
/**
|
|
1831
1838
|
* Convert multiple AgentForge tools to LangChain tools
|
|
1832
1839
|
*
|
|
@@ -1844,7 +1851,7 @@ declare function toLangChainTool(tool: Tool<any, any>): DynamicStructuredTool<an
|
|
|
1844
1851
|
* });
|
|
1845
1852
|
* ```
|
|
1846
1853
|
*/
|
|
1847
|
-
declare function toLangChainTools(tools:
|
|
1854
|
+
declare function toLangChainTools(tools: readonly LangChainConvertibleTool[]): DynamicStructuredTool[];
|
|
1848
1855
|
/**
|
|
1849
1856
|
* Get the JSON Schema representation of a tool's input schema
|
|
1850
1857
|
*
|
|
@@ -1859,7 +1866,7 @@ declare function toLangChainTools(tools: Tool<any, any>[]): DynamicStructuredToo
|
|
|
1859
1866
|
* console.log(JSON.stringify(schema, null, 2));
|
|
1860
1867
|
* ```
|
|
1861
1868
|
*/
|
|
1862
|
-
declare function getToolJsonSchema(tool: Tool<
|
|
1869
|
+
declare function getToolJsonSchema<TInput, TOutput>(tool: Tool<TInput, TOutput>): JsonSchemaObject;
|
|
1863
1870
|
/**
|
|
1864
1871
|
* Get tool metadata in a format suitable for LLM prompts
|
|
1865
1872
|
*
|
|
@@ -1880,7 +1887,7 @@ declare function getToolJsonSchema(tool: Tool<any, any>): Record<string, any>;
|
|
|
1880
1887
|
* // ...
|
|
1881
1888
|
* ```
|
|
1882
1889
|
*/
|
|
1883
|
-
declare function getToolDescription(tool: Tool<
|
|
1890
|
+
declare function getToolDescription<TInput, TOutput>(tool: Tool<TInput, TOutput>): string;
|
|
1884
1891
|
|
|
1885
1892
|
/**
|
|
1886
1893
|
* LangGraph State Utilities
|
package/dist/index.js
CHANGED
|
@@ -619,21 +619,42 @@ function toolBuilder() {
|
|
|
619
619
|
// src/langchain/converter.ts
|
|
620
620
|
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
621
621
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
622
|
+
function serializeToolResult(result) {
|
|
623
|
+
if (typeof result === "string") {
|
|
624
|
+
return result;
|
|
625
|
+
}
|
|
626
|
+
if (typeof result === "object" && result !== null) {
|
|
627
|
+
return JSON.stringify(result, null, 2);
|
|
628
|
+
}
|
|
629
|
+
return String(result);
|
|
630
|
+
}
|
|
631
|
+
function isJsonSchemaObject(value) {
|
|
632
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
633
|
+
}
|
|
634
|
+
function isJsonSchemaDefinitionMap(value) {
|
|
635
|
+
if (!isJsonSchemaObject(value)) {
|
|
636
|
+
return false;
|
|
637
|
+
}
|
|
638
|
+
return Object.values(value).every(isJsonSchemaObject);
|
|
639
|
+
}
|
|
640
|
+
function extractToolSchema(jsonSchema) {
|
|
641
|
+
if (!isJsonSchemaObject(jsonSchema)) {
|
|
642
|
+
return {};
|
|
643
|
+
}
|
|
644
|
+
const ref = jsonSchema.$ref;
|
|
645
|
+
const definitions = jsonSchema.definitions;
|
|
646
|
+
if (typeof ref !== "string" || !isJsonSchemaDefinitionMap(definitions)) {
|
|
647
|
+
return jsonSchema;
|
|
648
|
+
}
|
|
649
|
+
const refName = ref.replace("#/definitions/", "");
|
|
650
|
+
return definitions[refName] ?? jsonSchema;
|
|
651
|
+
}
|
|
622
652
|
function toLangChainTool(tool) {
|
|
623
653
|
return new DynamicStructuredTool({
|
|
624
654
|
name: tool.metadata.name,
|
|
625
655
|
description: tool.metadata.description,
|
|
626
656
|
schema: tool.schema,
|
|
627
|
-
func: async (input) =>
|
|
628
|
-
const result = await tool.invoke(input);
|
|
629
|
-
if (typeof result === "string") {
|
|
630
|
-
return result;
|
|
631
|
-
}
|
|
632
|
-
if (typeof result === "object" && result !== null) {
|
|
633
|
-
return JSON.stringify(result, null, 2);
|
|
634
|
-
}
|
|
635
|
-
return String(result);
|
|
636
|
-
}
|
|
657
|
+
func: async (input) => serializeToolResult(await tool.invoke(input))
|
|
637
658
|
});
|
|
638
659
|
}
|
|
639
660
|
function toLangChainTools(tools) {
|
|
@@ -645,11 +666,7 @@ function getToolJsonSchema(tool) {
|
|
|
645
666
|
$refStrategy: "none"
|
|
646
667
|
// Don't use $ref for nested schemas
|
|
647
668
|
});
|
|
648
|
-
|
|
649
|
-
const refName = jsonSchema.$ref.replace("#/definitions/", "");
|
|
650
|
-
return jsonSchema.definitions[refName] || jsonSchema;
|
|
651
|
-
}
|
|
652
|
-
return jsonSchema;
|
|
669
|
+
return extractToolSchema(jsonSchema);
|
|
653
670
|
}
|
|
654
671
|
function getToolDescription(tool) {
|
|
655
672
|
const { metadata } = tool;
|
package/package.json
CHANGED