@agentforge/testing 0.16.30 → 0.16.32
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 +46 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -25
- package/dist/index.d.ts +58 -25
- package/dist/index.js +46 -23
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -2,9 +2,8 @@ import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
|
2
2
|
import { BaseMessage } from '@langchain/core/messages';
|
|
3
3
|
import { ChatResult } from '@langchain/core/outputs';
|
|
4
4
|
import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
5
|
-
import * as _agentforge_core from '@agentforge/core';
|
|
6
|
-
import { ToolCategory, Tool, Logger } from '@agentforge/core';
|
|
7
5
|
import { z } from 'zod';
|
|
6
|
+
import { Tool, ToolCategory, Logger } from '@agentforge/core';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Configuration for MockLLM
|
|
@@ -80,10 +79,27 @@ declare function createEchoLLM(): MockLLM;
|
|
|
80
79
|
*/
|
|
81
80
|
declare function createErrorLLM(errorMessage?: string): MockLLM;
|
|
82
81
|
|
|
82
|
+
declare const defaultMockToolSchema: z.ZodObject<{
|
|
83
|
+
input: z.ZodString;
|
|
84
|
+
}, "strip", z.ZodTypeAny, {
|
|
85
|
+
input: string;
|
|
86
|
+
}, {
|
|
87
|
+
input: string;
|
|
88
|
+
}>;
|
|
89
|
+
type DefaultMockToolSchema = typeof defaultMockToolSchema;
|
|
90
|
+
type MockToolSchema = z.ZodTypeAny;
|
|
91
|
+
type MockToolInput<TSchema extends MockToolSchema> = z.infer<TSchema>;
|
|
92
|
+
type MockToolInstance<TSchema extends MockToolSchema> = Tool<MockToolInput<TSchema>, string>;
|
|
93
|
+
type MockToolConfigWithoutSchema = Omit<MockToolConfig<DefaultMockToolSchema>, 'schema'> & {
|
|
94
|
+
schema?: undefined;
|
|
95
|
+
};
|
|
96
|
+
type SchemaBackedMockToolConfig<TSchema extends MockToolSchema> = MockToolConfig<TSchema> & {
|
|
97
|
+
schema: TSchema;
|
|
98
|
+
};
|
|
83
99
|
/**
|
|
84
100
|
* Configuration for mock tool
|
|
85
101
|
*/
|
|
86
|
-
interface MockToolConfig<
|
|
102
|
+
interface MockToolConfig<TSchema extends MockToolSchema = DefaultMockToolSchema> {
|
|
87
103
|
/**
|
|
88
104
|
* Tool name
|
|
89
105
|
*/
|
|
@@ -99,11 +115,11 @@ interface MockToolConfig<T extends z.ZodType = z.ZodType> {
|
|
|
99
115
|
/**
|
|
100
116
|
* Input schema
|
|
101
117
|
*/
|
|
102
|
-
schema?:
|
|
118
|
+
schema?: TSchema;
|
|
103
119
|
/**
|
|
104
120
|
* Implementation function
|
|
105
121
|
*/
|
|
106
|
-
implementation?: (input:
|
|
122
|
+
implementation?: (input: MockToolInput<TSchema>) => Promise<string> | string;
|
|
107
123
|
/**
|
|
108
124
|
* Whether to throw an error
|
|
109
125
|
*/
|
|
@@ -117,38 +133,55 @@ interface MockToolConfig<T extends z.ZodType = z.ZodType> {
|
|
|
117
133
|
*/
|
|
118
134
|
delay?: number;
|
|
119
135
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
* @example
|
|
124
|
-
* ```typescript
|
|
125
|
-
* const tool = createMockTool({
|
|
126
|
-
* name: 'test_tool',
|
|
127
|
-
* schema: z.object({ input: z.string().describe('Input') }),
|
|
128
|
-
* implementation: async ({ input }) => `Processed: ${input}`
|
|
129
|
-
* });
|
|
130
|
-
*
|
|
131
|
-
* const result = await tool.execute({ input: 'test' });
|
|
132
|
-
* console.log(result); // 'Processed: test'
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
declare function createMockTool<T extends z.ZodType = any>(config?: MockToolConfig<T>): _agentforge_core.Tool<any, string>;
|
|
136
|
+
declare function createMockTool(): MockToolInstance<DefaultMockToolSchema>;
|
|
137
|
+
declare function createMockTool(config: MockToolConfigWithoutSchema): MockToolInstance<DefaultMockToolSchema>;
|
|
138
|
+
declare function createMockTool<TSchema extends MockToolSchema>(config: SchemaBackedMockToolConfig<TSchema>): MockToolInstance<TSchema>;
|
|
136
139
|
/**
|
|
137
140
|
* Create a mock tool that echoes its input
|
|
138
141
|
*/
|
|
139
|
-
declare function createEchoTool(name?: string):
|
|
142
|
+
declare function createEchoTool(name?: string): MockToolInstance<z.ZodObject<{
|
|
143
|
+
message: z.ZodString;
|
|
144
|
+
}, "strip", z.ZodTypeAny, {
|
|
145
|
+
message: string;
|
|
146
|
+
}, {
|
|
147
|
+
message: string;
|
|
148
|
+
}>>;
|
|
140
149
|
/**
|
|
141
150
|
* Create a mock tool that always errors
|
|
142
151
|
*/
|
|
143
|
-
declare function createErrorTool(name?: string, errorMessage?: string):
|
|
152
|
+
declare function createErrorTool(name?: string, errorMessage?: string): MockToolInstance<z.ZodObject<{
|
|
153
|
+
input: z.ZodString;
|
|
154
|
+
}, "strip", z.ZodTypeAny, {
|
|
155
|
+
input: string;
|
|
156
|
+
}, {
|
|
157
|
+
input: string;
|
|
158
|
+
}>>;
|
|
144
159
|
/**
|
|
145
160
|
* Create a mock tool with delay
|
|
146
161
|
*/
|
|
147
|
-
declare function createDelayedTool(name?: string, delay?: number):
|
|
162
|
+
declare function createDelayedTool(name?: string, delay?: number): MockToolInstance<z.ZodObject<{
|
|
163
|
+
input: z.ZodString;
|
|
164
|
+
}, "strip", z.ZodTypeAny, {
|
|
165
|
+
input: string;
|
|
166
|
+
}, {
|
|
167
|
+
input: string;
|
|
168
|
+
}>>;
|
|
148
169
|
/**
|
|
149
170
|
* Create a calculator mock tool
|
|
150
171
|
*/
|
|
151
|
-
declare function createCalculatorTool():
|
|
172
|
+
declare function createCalculatorTool(): MockToolInstance<z.ZodObject<{
|
|
173
|
+
operation: z.ZodEnum<["add", "subtract", "multiply", "divide"]>;
|
|
174
|
+
a: z.ZodNumber;
|
|
175
|
+
b: z.ZodNumber;
|
|
176
|
+
}, "strip", z.ZodTypeAny, {
|
|
177
|
+
operation: "add" | "subtract" | "multiply" | "divide";
|
|
178
|
+
a: number;
|
|
179
|
+
b: number;
|
|
180
|
+
}, {
|
|
181
|
+
operation: "add" | "subtract" | "multiply" | "divide";
|
|
182
|
+
a: number;
|
|
183
|
+
b: number;
|
|
184
|
+
}>>;
|
|
152
185
|
|
|
153
186
|
type StateBuilderFields = Record<string, unknown> & {
|
|
154
187
|
messages?: BaseMessage[];
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,8 @@ import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
|
2
2
|
import { BaseMessage } from '@langchain/core/messages';
|
|
3
3
|
import { ChatResult } from '@langchain/core/outputs';
|
|
4
4
|
import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
5
|
-
import * as _agentforge_core from '@agentforge/core';
|
|
6
|
-
import { ToolCategory, Tool, Logger } from '@agentforge/core';
|
|
7
5
|
import { z } from 'zod';
|
|
6
|
+
import { Tool, ToolCategory, Logger } from '@agentforge/core';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Configuration for MockLLM
|
|
@@ -80,10 +79,27 @@ declare function createEchoLLM(): MockLLM;
|
|
|
80
79
|
*/
|
|
81
80
|
declare function createErrorLLM(errorMessage?: string): MockLLM;
|
|
82
81
|
|
|
82
|
+
declare const defaultMockToolSchema: z.ZodObject<{
|
|
83
|
+
input: z.ZodString;
|
|
84
|
+
}, "strip", z.ZodTypeAny, {
|
|
85
|
+
input: string;
|
|
86
|
+
}, {
|
|
87
|
+
input: string;
|
|
88
|
+
}>;
|
|
89
|
+
type DefaultMockToolSchema = typeof defaultMockToolSchema;
|
|
90
|
+
type MockToolSchema = z.ZodTypeAny;
|
|
91
|
+
type MockToolInput<TSchema extends MockToolSchema> = z.infer<TSchema>;
|
|
92
|
+
type MockToolInstance<TSchema extends MockToolSchema> = Tool<MockToolInput<TSchema>, string>;
|
|
93
|
+
type MockToolConfigWithoutSchema = Omit<MockToolConfig<DefaultMockToolSchema>, 'schema'> & {
|
|
94
|
+
schema?: undefined;
|
|
95
|
+
};
|
|
96
|
+
type SchemaBackedMockToolConfig<TSchema extends MockToolSchema> = MockToolConfig<TSchema> & {
|
|
97
|
+
schema: TSchema;
|
|
98
|
+
};
|
|
83
99
|
/**
|
|
84
100
|
* Configuration for mock tool
|
|
85
101
|
*/
|
|
86
|
-
interface MockToolConfig<
|
|
102
|
+
interface MockToolConfig<TSchema extends MockToolSchema = DefaultMockToolSchema> {
|
|
87
103
|
/**
|
|
88
104
|
* Tool name
|
|
89
105
|
*/
|
|
@@ -99,11 +115,11 @@ interface MockToolConfig<T extends z.ZodType = z.ZodType> {
|
|
|
99
115
|
/**
|
|
100
116
|
* Input schema
|
|
101
117
|
*/
|
|
102
|
-
schema?:
|
|
118
|
+
schema?: TSchema;
|
|
103
119
|
/**
|
|
104
120
|
* Implementation function
|
|
105
121
|
*/
|
|
106
|
-
implementation?: (input:
|
|
122
|
+
implementation?: (input: MockToolInput<TSchema>) => Promise<string> | string;
|
|
107
123
|
/**
|
|
108
124
|
* Whether to throw an error
|
|
109
125
|
*/
|
|
@@ -117,38 +133,55 @@ interface MockToolConfig<T extends z.ZodType = z.ZodType> {
|
|
|
117
133
|
*/
|
|
118
134
|
delay?: number;
|
|
119
135
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
* @example
|
|
124
|
-
* ```typescript
|
|
125
|
-
* const tool = createMockTool({
|
|
126
|
-
* name: 'test_tool',
|
|
127
|
-
* schema: z.object({ input: z.string().describe('Input') }),
|
|
128
|
-
* implementation: async ({ input }) => `Processed: ${input}`
|
|
129
|
-
* });
|
|
130
|
-
*
|
|
131
|
-
* const result = await tool.execute({ input: 'test' });
|
|
132
|
-
* console.log(result); // 'Processed: test'
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
declare function createMockTool<T extends z.ZodType = any>(config?: MockToolConfig<T>): _agentforge_core.Tool<any, string>;
|
|
136
|
+
declare function createMockTool(): MockToolInstance<DefaultMockToolSchema>;
|
|
137
|
+
declare function createMockTool(config: MockToolConfigWithoutSchema): MockToolInstance<DefaultMockToolSchema>;
|
|
138
|
+
declare function createMockTool<TSchema extends MockToolSchema>(config: SchemaBackedMockToolConfig<TSchema>): MockToolInstance<TSchema>;
|
|
136
139
|
/**
|
|
137
140
|
* Create a mock tool that echoes its input
|
|
138
141
|
*/
|
|
139
|
-
declare function createEchoTool(name?: string):
|
|
142
|
+
declare function createEchoTool(name?: string): MockToolInstance<z.ZodObject<{
|
|
143
|
+
message: z.ZodString;
|
|
144
|
+
}, "strip", z.ZodTypeAny, {
|
|
145
|
+
message: string;
|
|
146
|
+
}, {
|
|
147
|
+
message: string;
|
|
148
|
+
}>>;
|
|
140
149
|
/**
|
|
141
150
|
* Create a mock tool that always errors
|
|
142
151
|
*/
|
|
143
|
-
declare function createErrorTool(name?: string, errorMessage?: string):
|
|
152
|
+
declare function createErrorTool(name?: string, errorMessage?: string): MockToolInstance<z.ZodObject<{
|
|
153
|
+
input: z.ZodString;
|
|
154
|
+
}, "strip", z.ZodTypeAny, {
|
|
155
|
+
input: string;
|
|
156
|
+
}, {
|
|
157
|
+
input: string;
|
|
158
|
+
}>>;
|
|
144
159
|
/**
|
|
145
160
|
* Create a mock tool with delay
|
|
146
161
|
*/
|
|
147
|
-
declare function createDelayedTool(name?: string, delay?: number):
|
|
162
|
+
declare function createDelayedTool(name?: string, delay?: number): MockToolInstance<z.ZodObject<{
|
|
163
|
+
input: z.ZodString;
|
|
164
|
+
}, "strip", z.ZodTypeAny, {
|
|
165
|
+
input: string;
|
|
166
|
+
}, {
|
|
167
|
+
input: string;
|
|
168
|
+
}>>;
|
|
148
169
|
/**
|
|
149
170
|
* Create a calculator mock tool
|
|
150
171
|
*/
|
|
151
|
-
declare function createCalculatorTool():
|
|
172
|
+
declare function createCalculatorTool(): MockToolInstance<z.ZodObject<{
|
|
173
|
+
operation: z.ZodEnum<["add", "subtract", "multiply", "divide"]>;
|
|
174
|
+
a: z.ZodNumber;
|
|
175
|
+
b: z.ZodNumber;
|
|
176
|
+
}, "strip", z.ZodTypeAny, {
|
|
177
|
+
operation: "add" | "subtract" | "multiply" | "divide";
|
|
178
|
+
a: number;
|
|
179
|
+
b: number;
|
|
180
|
+
}, {
|
|
181
|
+
operation: "add" | "subtract" | "multiply" | "divide";
|
|
182
|
+
a: number;
|
|
183
|
+
b: number;
|
|
184
|
+
}>>;
|
|
152
185
|
|
|
153
186
|
type StateBuilderFields = Record<string, unknown> & {
|
|
154
187
|
messages?: BaseMessage[];
|
package/dist/index.js
CHANGED
|
@@ -1538,58 +1538,81 @@ function createErrorLLM(errorMessage = "Mock error") {
|
|
|
1538
1538
|
errorMessage
|
|
1539
1539
|
});
|
|
1540
1540
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
schema,
|
|
1547
|
-
implementation,
|
|
1548
|
-
shouldError = false,
|
|
1549
|
-
errorMessage = "Mock tool error",
|
|
1550
|
-
delay = 0
|
|
1551
|
-
} = config2;
|
|
1552
|
-
const actualSchema = schema || z.object({ input: z.string().describe("Input parameter") });
|
|
1541
|
+
var defaultMockToolSchema = z.object({
|
|
1542
|
+
input: z.string().describe("Input parameter")
|
|
1543
|
+
});
|
|
1544
|
+
function buildMockTool(config2) {
|
|
1545
|
+
const { name, description, category, schema, implementation, shouldError, errorMessage, delay } = config2;
|
|
1553
1546
|
const defaultImplementation = async (input) => {
|
|
1547
|
+
return `Mock result: ${JSON.stringify(input)}`;
|
|
1548
|
+
};
|
|
1549
|
+
const actualImplementation = async (input) => {
|
|
1554
1550
|
if (delay > 0) {
|
|
1555
1551
|
await new Promise((resolve4) => setTimeout(resolve4, delay));
|
|
1556
1552
|
}
|
|
1557
1553
|
if (shouldError) {
|
|
1558
1554
|
throw new Error(errorMessage);
|
|
1559
1555
|
}
|
|
1560
|
-
return `Mock result: ${JSON.stringify(input)}`;
|
|
1561
|
-
};
|
|
1562
|
-
const actualImplementation = async (input) => {
|
|
1563
1556
|
if (implementation) {
|
|
1564
1557
|
const result = await Promise.resolve(implementation(input));
|
|
1565
1558
|
return result;
|
|
1566
1559
|
}
|
|
1567
1560
|
return defaultImplementation(input);
|
|
1568
1561
|
};
|
|
1569
|
-
return toolBuilder().name(name).description(description).category(category).schema(
|
|
1562
|
+
return toolBuilder().name(name).description(description).category(category).schema(schema).implement(actualImplementation).build();
|
|
1570
1563
|
}
|
|
1571
|
-
function
|
|
1572
|
-
|
|
1564
|
+
function createMockTool(config2 = {}) {
|
|
1565
|
+
const name = config2.name ?? "mock-tool";
|
|
1566
|
+
const description = config2.description ?? "A mock tool for testing";
|
|
1567
|
+
const category = config2.category ?? ToolCategory.UTILITY;
|
|
1568
|
+
const shouldError = config2.shouldError ?? false;
|
|
1569
|
+
const errorMessage = config2.errorMessage ?? "Mock tool error";
|
|
1570
|
+
const delay = config2.delay ?? 0;
|
|
1571
|
+
if ("schema" in config2 && config2.schema) {
|
|
1572
|
+
return buildMockTool({
|
|
1573
|
+
name,
|
|
1574
|
+
description,
|
|
1575
|
+
category,
|
|
1576
|
+
schema: config2.schema,
|
|
1577
|
+
implementation: config2.implementation,
|
|
1578
|
+
shouldError,
|
|
1579
|
+
errorMessage,
|
|
1580
|
+
delay
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
return buildMockTool({
|
|
1573
1584
|
name,
|
|
1585
|
+
description,
|
|
1586
|
+
category,
|
|
1587
|
+
schema: defaultMockToolSchema,
|
|
1588
|
+
implementation: config2.implementation,
|
|
1589
|
+
shouldError,
|
|
1590
|
+
errorMessage,
|
|
1591
|
+
delay
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
function createEchoTool(name = "echo-tool") {
|
|
1595
|
+
return createMockTool({
|
|
1596
|
+
name: name.replace(/_/g, "-"),
|
|
1574
1597
|
description: "Echoes the input",
|
|
1575
1598
|
schema: z.object({ message: z.string().describe("Message to echo") }),
|
|
1576
1599
|
implementation: async ({ message }) => `Echo: ${message}`
|
|
1577
1600
|
});
|
|
1578
1601
|
}
|
|
1579
|
-
function createErrorTool(name = "
|
|
1602
|
+
function createErrorTool(name = "error-tool", errorMessage = "Tool error") {
|
|
1580
1603
|
return createMockTool({
|
|
1581
|
-
name,
|
|
1604
|
+
name: name.replace(/_/g, "-"),
|
|
1582
1605
|
description: "A tool that always errors",
|
|
1583
1606
|
shouldError: true,
|
|
1584
1607
|
errorMessage
|
|
1585
1608
|
});
|
|
1586
1609
|
}
|
|
1587
|
-
function createDelayedTool(name = "
|
|
1610
|
+
function createDelayedTool(name = "delayed-tool", delay = 100) {
|
|
1588
1611
|
return createMockTool({
|
|
1589
|
-
name,
|
|
1612
|
+
name: name.replace(/_/g, "-"),
|
|
1590
1613
|
description: "A tool with artificial delay",
|
|
1591
1614
|
delay,
|
|
1592
|
-
schema:
|
|
1615
|
+
schema: defaultMockToolSchema,
|
|
1593
1616
|
implementation: async ({ input }) => `Delayed result: ${input}`
|
|
1594
1617
|
});
|
|
1595
1618
|
}
|