@agentforge/testing 0.16.4 → 0.16.5
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 +38 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -45
- package/dist/index.d.ts +67 -45
- package/dist/index.js +39 -23
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -150,19 +150,54 @@ declare function createDelayedTool(name?: string, delay?: number): _agentforge_c
|
|
|
150
150
|
*/
|
|
151
151
|
declare function createCalculatorTool(): _agentforge_core.Tool<any, string>;
|
|
152
152
|
|
|
153
|
+
type StateBuilderFields = Record<string, unknown> & {
|
|
154
|
+
messages?: BaseMessage[];
|
|
155
|
+
};
|
|
156
|
+
type MessageState = {
|
|
157
|
+
messages: BaseMessage[];
|
|
158
|
+
};
|
|
159
|
+
type BuiltState<TState extends StateBuilderFields> = TState & Partial<MessageState>;
|
|
160
|
+
interface TestToolCall<TArgs = unknown> {
|
|
161
|
+
name: string;
|
|
162
|
+
args: TArgs;
|
|
163
|
+
}
|
|
164
|
+
interface TestToolResult<TResult = string> {
|
|
165
|
+
name: string;
|
|
166
|
+
result: TResult;
|
|
167
|
+
}
|
|
168
|
+
interface ReActTestState<TArgs = unknown, TResult = string> {
|
|
169
|
+
messages: BaseMessage[];
|
|
170
|
+
thoughts: string[];
|
|
171
|
+
toolCalls: Array<TestToolCall<TArgs>>;
|
|
172
|
+
toolResults: Array<TestToolResult<TResult>>;
|
|
173
|
+
scratchpad: string[];
|
|
174
|
+
iterations: number;
|
|
175
|
+
maxIterations: number;
|
|
176
|
+
}
|
|
177
|
+
interface PlanningStep<TStatus extends string = string> {
|
|
178
|
+
step: string;
|
|
179
|
+
status: TStatus;
|
|
180
|
+
}
|
|
181
|
+
interface PlanningTestState<TResultMap extends Record<string, unknown> = Record<string, unknown>, TStatus extends string = string> extends StateBuilderFields {
|
|
182
|
+
messages: BaseMessage[];
|
|
183
|
+
plan: Array<PlanningStep<TStatus>>;
|
|
184
|
+
currentStep: number;
|
|
185
|
+
results: Partial<TResultMap>;
|
|
186
|
+
}
|
|
153
187
|
/**
|
|
154
188
|
* Builder for creating test states
|
|
155
189
|
*/
|
|
156
|
-
declare class StateBuilder<
|
|
190
|
+
declare class StateBuilder<TState extends StateBuilderFields = StateBuilderFields> {
|
|
157
191
|
private state;
|
|
158
192
|
/**
|
|
159
193
|
* Set a field in the state
|
|
160
194
|
*/
|
|
161
|
-
set<K extends keyof
|
|
195
|
+
set<K extends keyof TState>(key: K, value: TState[K]): this;
|
|
162
196
|
/**
|
|
163
197
|
* Set multiple fields in the state
|
|
164
198
|
*/
|
|
165
|
-
setMany(fields: Partial<
|
|
199
|
+
setMany(fields: Partial<TState>): this;
|
|
200
|
+
private ensureMessages;
|
|
166
201
|
/**
|
|
167
202
|
* Add a message to the messages array
|
|
168
203
|
*/
|
|
@@ -170,7 +205,7 @@ declare class StateBuilder<T extends Record<string, any> = Record<string, any>>
|
|
|
170
205
|
/**
|
|
171
206
|
* Add multiple messages
|
|
172
207
|
*/
|
|
173
|
-
addMessages(messages: BaseMessage
|
|
208
|
+
addMessages(messages: ReadonlyArray<BaseMessage>): this;
|
|
174
209
|
/**
|
|
175
210
|
* Add a human message
|
|
176
211
|
*/
|
|
@@ -186,7 +221,7 @@ declare class StateBuilder<T extends Record<string, any> = Record<string, any>>
|
|
|
186
221
|
/**
|
|
187
222
|
* Build the state
|
|
188
223
|
*/
|
|
189
|
-
build():
|
|
224
|
+
build(): BuiltState<TState>;
|
|
190
225
|
/**
|
|
191
226
|
* Reset the builder
|
|
192
227
|
*/
|
|
@@ -195,48 +230,37 @@ declare class StateBuilder<T extends Record<string, any> = Record<string, any>>
|
|
|
195
230
|
/**
|
|
196
231
|
* Create a state builder
|
|
197
232
|
*/
|
|
198
|
-
declare function createStateBuilder<
|
|
233
|
+
declare function createStateBuilder<TState extends StateBuilderFields = StateBuilderFields>(): StateBuilder<TState>;
|
|
199
234
|
/**
|
|
200
235
|
* Create a simple conversation state
|
|
201
236
|
*/
|
|
202
|
-
declare function createConversationState(messages: string
|
|
203
|
-
messages: BaseMessage[];
|
|
204
|
-
};
|
|
237
|
+
declare function createConversationState(messages: ReadonlyArray<string>): MessageState;
|
|
205
238
|
/**
|
|
206
239
|
* Create a ReAct agent state
|
|
207
240
|
*/
|
|
208
|
-
declare function createReActState(config?:
|
|
209
|
-
messages?: BaseMessage[];
|
|
210
|
-
thoughts?: string[];
|
|
211
|
-
toolCalls?: Array<{
|
|
212
|
-
name: string;
|
|
213
|
-
args: any;
|
|
214
|
-
}>;
|
|
215
|
-
toolResults?: Array<{
|
|
216
|
-
name: string;
|
|
217
|
-
result: string;
|
|
218
|
-
}>;
|
|
219
|
-
scratchpad?: string[];
|
|
220
|
-
iterations?: number;
|
|
221
|
-
maxIterations?: number;
|
|
222
|
-
}): any;
|
|
241
|
+
declare function createReActState<TArgs = unknown, TResult = string>(config?: Partial<ReActTestState<TArgs, TResult>>): ReActTestState<TArgs, TResult>;
|
|
223
242
|
/**
|
|
224
243
|
* Create a planning agent state
|
|
225
244
|
*/
|
|
226
|
-
declare function createPlanningState(config?:
|
|
227
|
-
messages?: BaseMessage[];
|
|
228
|
-
plan?: Array<{
|
|
229
|
-
step: string;
|
|
230
|
-
status: string;
|
|
231
|
-
}>;
|
|
232
|
-
currentStep?: number;
|
|
233
|
-
results?: Record<string, any>;
|
|
234
|
-
}): any;
|
|
245
|
+
declare function createPlanningState<TResultMap extends Record<string, unknown> = Record<string, unknown>, TStatus extends string = string>(config?: Partial<PlanningTestState<TResultMap, TStatus>>): PlanningTestState<TResultMap, TStatus>;
|
|
235
246
|
|
|
247
|
+
type ToolCall<TArgs = unknown> = {
|
|
248
|
+
name: string;
|
|
249
|
+
args: TArgs;
|
|
250
|
+
};
|
|
251
|
+
type MessageLike<TType extends string = string> = {
|
|
252
|
+
content: unknown;
|
|
253
|
+
_getType: () => TType;
|
|
254
|
+
};
|
|
255
|
+
type AssertedMessage<TType extends string = string> = BaseMessage | MessageLike<TType>;
|
|
236
256
|
/**
|
|
237
257
|
* Assert that a value is a message of a specific type
|
|
238
258
|
*/
|
|
239
|
-
declare function assertIsMessage(value:
|
|
259
|
+
declare function assertIsMessage(value: unknown): asserts value is AssertedMessage;
|
|
260
|
+
declare function assertIsMessage(value: unknown, type: 'human'): asserts value is AssertedMessage<'human'>;
|
|
261
|
+
declare function assertIsMessage(value: unknown, type: 'ai'): asserts value is AssertedMessage<'ai'>;
|
|
262
|
+
declare function assertIsMessage(value: unknown, type: 'system'): asserts value is AssertedMessage<'system'>;
|
|
263
|
+
declare function assertIsMessage(value: unknown, type: 'tool'): asserts value is AssertedMessage<'tool'>;
|
|
240
264
|
/**
|
|
241
265
|
* Assert that messages array contains a message with specific content
|
|
242
266
|
*/
|
|
@@ -248,26 +272,24 @@ declare function assertLastMessageContains(messages: BaseMessage[], content: str
|
|
|
248
272
|
/**
|
|
249
273
|
* Assert that state has required fields
|
|
250
274
|
*/
|
|
251
|
-
declare function assertStateHasFields<
|
|
275
|
+
declare function assertStateHasFields<TState extends object>(state: TState, fields: ReadonlyArray<keyof TState & (string | number)>): void;
|
|
252
276
|
/**
|
|
253
277
|
* Assert that a tool was called with specific arguments
|
|
254
278
|
*/
|
|
255
|
-
declare function assertToolCalled(toolCalls:
|
|
256
|
-
|
|
257
|
-
args: any;
|
|
258
|
-
}>, toolName: string, args?: Record<string, any>): void;
|
|
279
|
+
declare function assertToolCalled(toolCalls: ReadonlyArray<ToolCall>, toolName: string): void;
|
|
280
|
+
declare function assertToolCalled<TArgs extends Record<string, unknown>>(toolCalls: ReadonlyArray<ToolCall<TArgs>>, toolName: string, args: Partial<TArgs>): void;
|
|
259
281
|
/**
|
|
260
282
|
* Assert that execution completed within time limit
|
|
261
283
|
*/
|
|
262
|
-
declare function assertCompletesWithin(fn: () => Promise<
|
|
284
|
+
declare function assertCompletesWithin(fn: () => Promise<unknown>, maxMs: number): Promise<void>;
|
|
263
285
|
/**
|
|
264
286
|
* Assert that a function throws an error with specific message
|
|
265
287
|
*/
|
|
266
|
-
declare function assertThrowsWithMessage(fn: () => Promise<
|
|
288
|
+
declare function assertThrowsWithMessage(fn: () => Promise<unknown>, message: string): Promise<void>;
|
|
267
289
|
/**
|
|
268
290
|
* Assert that state matches a snapshot
|
|
269
291
|
*/
|
|
270
|
-
declare function assertStateSnapshot(state:
|
|
292
|
+
declare function assertStateSnapshot<TState extends object>(state: TState, snapshot: Partial<TState>): void;
|
|
271
293
|
/**
|
|
272
294
|
* Assert that messages have alternating types (human, ai, human, ai, ...)
|
|
273
295
|
*/
|
|
@@ -275,7 +297,7 @@ declare function assertAlternatingMessages(messages: BaseMessage[]): void;
|
|
|
275
297
|
/**
|
|
276
298
|
* Assert that an array is not empty
|
|
277
299
|
*/
|
|
278
|
-
declare function assertNotEmpty<T>(array: T[]): void;
|
|
300
|
+
declare function assertNotEmpty<T>(array: readonly T[]): void;
|
|
279
301
|
/**
|
|
280
302
|
* Assert that a value is within a range
|
|
281
303
|
*/
|
|
@@ -287,7 +309,7 @@ declare function assertIterationsWithinLimit(iterations: number, maxIterations:
|
|
|
287
309
|
/**
|
|
288
310
|
* Assert that a result contains expected keys
|
|
289
311
|
*/
|
|
290
|
-
declare function assertHasKeys<
|
|
312
|
+
declare function assertHasKeys<TObject extends object>(obj: TObject, keys: ReadonlyArray<keyof TObject & string>): void;
|
|
291
313
|
|
|
292
314
|
/**
|
|
293
315
|
* Sample conversation: Simple greeting
|
|
@@ -705,4 +727,4 @@ declare function createStateDiff(state1: any, state2: any, config?: SnapshotConf
|
|
|
705
727
|
*/
|
|
706
728
|
declare function assertStateChanged(stateBefore: any, stateAfter: any, expectedChanges: string[], config?: SnapshotConfig): void;
|
|
707
729
|
|
|
708
|
-
export { type AgentTestConfig, type AgentTestResult, AgentTestRunner, type ConversationResult, ConversationSimulator, type ConversationSimulatorConfig, MockLLM, type MockLLMConfig, type MockToolConfig, type SnapshotConfig, StateBuilder, assertAlternatingMessages, assertCompletesWithin, assertHasKeys, assertInRange, assertIsMessage, assertIterationsWithinLimit, assertLastMessageContains, assertMatchesSnapshot, assertMessageContains, assertMessagesMatchSnapshot, assertNotEmpty, assertStateChanged, assertStateHasFields, assertStateSnapshot, assertThrowsWithMessage, assertToolCalled, calculatorTool, compareStates, complexReasoningConversation, createAgentTestRunner, createCalculatorTool, createConversation, createConversationSimulator, createConversationState, createConversationWithSystem, createDelayedTool, createEchoLLM, createEchoTool, createErrorLLM, createErrorTool, createMessageSnapshot, createMockLLM, createMockTool, createPlanningState, createReActState, createSnapshot, createStateBuilder, createStateDiff, databaseQueryTool, errorHandlingConversation, fileReaderTool, getToolByName, getToolsByCategory, longContextConversation, multiTurnConversation, sampleData, sampleTools, searchTool, simpleGreeting, timeTool, toolUsageConversation, weatherTool };
|
|
730
|
+
export { type AgentTestConfig, type AgentTestResult, AgentTestRunner, type AssertedMessage, type ConversationResult, ConversationSimulator, type ConversationSimulatorConfig, MockLLM, type MockLLMConfig, type MockToolConfig, type PlanningStep, type PlanningTestState, type ReActTestState, type SnapshotConfig, StateBuilder, type TestToolCall, type TestToolResult, assertAlternatingMessages, assertCompletesWithin, assertHasKeys, assertInRange, assertIsMessage, assertIterationsWithinLimit, assertLastMessageContains, assertMatchesSnapshot, assertMessageContains, assertMessagesMatchSnapshot, assertNotEmpty, assertStateChanged, assertStateHasFields, assertStateSnapshot, assertThrowsWithMessage, assertToolCalled, calculatorTool, compareStates, complexReasoningConversation, createAgentTestRunner, createCalculatorTool, createConversation, createConversationSimulator, createConversationState, createConversationWithSystem, createDelayedTool, createEchoLLM, createEchoTool, createErrorLLM, createErrorTool, createMessageSnapshot, createMockLLM, createMockTool, createPlanningState, createReActState, createSnapshot, createStateBuilder, createStateDiff, databaseQueryTool, errorHandlingConversation, fileReaderTool, getToolByName, getToolsByCategory, longContextConversation, multiTurnConversation, sampleData, sampleTools, searchTool, simpleGreeting, timeTool, toolUsageConversation, weatherTool };
|
package/dist/index.d.ts
CHANGED
|
@@ -150,19 +150,54 @@ declare function createDelayedTool(name?: string, delay?: number): _agentforge_c
|
|
|
150
150
|
*/
|
|
151
151
|
declare function createCalculatorTool(): _agentforge_core.Tool<any, string>;
|
|
152
152
|
|
|
153
|
+
type StateBuilderFields = Record<string, unknown> & {
|
|
154
|
+
messages?: BaseMessage[];
|
|
155
|
+
};
|
|
156
|
+
type MessageState = {
|
|
157
|
+
messages: BaseMessage[];
|
|
158
|
+
};
|
|
159
|
+
type BuiltState<TState extends StateBuilderFields> = TState & Partial<MessageState>;
|
|
160
|
+
interface TestToolCall<TArgs = unknown> {
|
|
161
|
+
name: string;
|
|
162
|
+
args: TArgs;
|
|
163
|
+
}
|
|
164
|
+
interface TestToolResult<TResult = string> {
|
|
165
|
+
name: string;
|
|
166
|
+
result: TResult;
|
|
167
|
+
}
|
|
168
|
+
interface ReActTestState<TArgs = unknown, TResult = string> {
|
|
169
|
+
messages: BaseMessage[];
|
|
170
|
+
thoughts: string[];
|
|
171
|
+
toolCalls: Array<TestToolCall<TArgs>>;
|
|
172
|
+
toolResults: Array<TestToolResult<TResult>>;
|
|
173
|
+
scratchpad: string[];
|
|
174
|
+
iterations: number;
|
|
175
|
+
maxIterations: number;
|
|
176
|
+
}
|
|
177
|
+
interface PlanningStep<TStatus extends string = string> {
|
|
178
|
+
step: string;
|
|
179
|
+
status: TStatus;
|
|
180
|
+
}
|
|
181
|
+
interface PlanningTestState<TResultMap extends Record<string, unknown> = Record<string, unknown>, TStatus extends string = string> extends StateBuilderFields {
|
|
182
|
+
messages: BaseMessage[];
|
|
183
|
+
plan: Array<PlanningStep<TStatus>>;
|
|
184
|
+
currentStep: number;
|
|
185
|
+
results: Partial<TResultMap>;
|
|
186
|
+
}
|
|
153
187
|
/**
|
|
154
188
|
* Builder for creating test states
|
|
155
189
|
*/
|
|
156
|
-
declare class StateBuilder<
|
|
190
|
+
declare class StateBuilder<TState extends StateBuilderFields = StateBuilderFields> {
|
|
157
191
|
private state;
|
|
158
192
|
/**
|
|
159
193
|
* Set a field in the state
|
|
160
194
|
*/
|
|
161
|
-
set<K extends keyof
|
|
195
|
+
set<K extends keyof TState>(key: K, value: TState[K]): this;
|
|
162
196
|
/**
|
|
163
197
|
* Set multiple fields in the state
|
|
164
198
|
*/
|
|
165
|
-
setMany(fields: Partial<
|
|
199
|
+
setMany(fields: Partial<TState>): this;
|
|
200
|
+
private ensureMessages;
|
|
166
201
|
/**
|
|
167
202
|
* Add a message to the messages array
|
|
168
203
|
*/
|
|
@@ -170,7 +205,7 @@ declare class StateBuilder<T extends Record<string, any> = Record<string, any>>
|
|
|
170
205
|
/**
|
|
171
206
|
* Add multiple messages
|
|
172
207
|
*/
|
|
173
|
-
addMessages(messages: BaseMessage
|
|
208
|
+
addMessages(messages: ReadonlyArray<BaseMessage>): this;
|
|
174
209
|
/**
|
|
175
210
|
* Add a human message
|
|
176
211
|
*/
|
|
@@ -186,7 +221,7 @@ declare class StateBuilder<T extends Record<string, any> = Record<string, any>>
|
|
|
186
221
|
/**
|
|
187
222
|
* Build the state
|
|
188
223
|
*/
|
|
189
|
-
build():
|
|
224
|
+
build(): BuiltState<TState>;
|
|
190
225
|
/**
|
|
191
226
|
* Reset the builder
|
|
192
227
|
*/
|
|
@@ -195,48 +230,37 @@ declare class StateBuilder<T extends Record<string, any> = Record<string, any>>
|
|
|
195
230
|
/**
|
|
196
231
|
* Create a state builder
|
|
197
232
|
*/
|
|
198
|
-
declare function createStateBuilder<
|
|
233
|
+
declare function createStateBuilder<TState extends StateBuilderFields = StateBuilderFields>(): StateBuilder<TState>;
|
|
199
234
|
/**
|
|
200
235
|
* Create a simple conversation state
|
|
201
236
|
*/
|
|
202
|
-
declare function createConversationState(messages: string
|
|
203
|
-
messages: BaseMessage[];
|
|
204
|
-
};
|
|
237
|
+
declare function createConversationState(messages: ReadonlyArray<string>): MessageState;
|
|
205
238
|
/**
|
|
206
239
|
* Create a ReAct agent state
|
|
207
240
|
*/
|
|
208
|
-
declare function createReActState(config?:
|
|
209
|
-
messages?: BaseMessage[];
|
|
210
|
-
thoughts?: string[];
|
|
211
|
-
toolCalls?: Array<{
|
|
212
|
-
name: string;
|
|
213
|
-
args: any;
|
|
214
|
-
}>;
|
|
215
|
-
toolResults?: Array<{
|
|
216
|
-
name: string;
|
|
217
|
-
result: string;
|
|
218
|
-
}>;
|
|
219
|
-
scratchpad?: string[];
|
|
220
|
-
iterations?: number;
|
|
221
|
-
maxIterations?: number;
|
|
222
|
-
}): any;
|
|
241
|
+
declare function createReActState<TArgs = unknown, TResult = string>(config?: Partial<ReActTestState<TArgs, TResult>>): ReActTestState<TArgs, TResult>;
|
|
223
242
|
/**
|
|
224
243
|
* Create a planning agent state
|
|
225
244
|
*/
|
|
226
|
-
declare function createPlanningState(config?:
|
|
227
|
-
messages?: BaseMessage[];
|
|
228
|
-
plan?: Array<{
|
|
229
|
-
step: string;
|
|
230
|
-
status: string;
|
|
231
|
-
}>;
|
|
232
|
-
currentStep?: number;
|
|
233
|
-
results?: Record<string, any>;
|
|
234
|
-
}): any;
|
|
245
|
+
declare function createPlanningState<TResultMap extends Record<string, unknown> = Record<string, unknown>, TStatus extends string = string>(config?: Partial<PlanningTestState<TResultMap, TStatus>>): PlanningTestState<TResultMap, TStatus>;
|
|
235
246
|
|
|
247
|
+
type ToolCall<TArgs = unknown> = {
|
|
248
|
+
name: string;
|
|
249
|
+
args: TArgs;
|
|
250
|
+
};
|
|
251
|
+
type MessageLike<TType extends string = string> = {
|
|
252
|
+
content: unknown;
|
|
253
|
+
_getType: () => TType;
|
|
254
|
+
};
|
|
255
|
+
type AssertedMessage<TType extends string = string> = BaseMessage | MessageLike<TType>;
|
|
236
256
|
/**
|
|
237
257
|
* Assert that a value is a message of a specific type
|
|
238
258
|
*/
|
|
239
|
-
declare function assertIsMessage(value:
|
|
259
|
+
declare function assertIsMessage(value: unknown): asserts value is AssertedMessage;
|
|
260
|
+
declare function assertIsMessage(value: unknown, type: 'human'): asserts value is AssertedMessage<'human'>;
|
|
261
|
+
declare function assertIsMessage(value: unknown, type: 'ai'): asserts value is AssertedMessage<'ai'>;
|
|
262
|
+
declare function assertIsMessage(value: unknown, type: 'system'): asserts value is AssertedMessage<'system'>;
|
|
263
|
+
declare function assertIsMessage(value: unknown, type: 'tool'): asserts value is AssertedMessage<'tool'>;
|
|
240
264
|
/**
|
|
241
265
|
* Assert that messages array contains a message with specific content
|
|
242
266
|
*/
|
|
@@ -248,26 +272,24 @@ declare function assertLastMessageContains(messages: BaseMessage[], content: str
|
|
|
248
272
|
/**
|
|
249
273
|
* Assert that state has required fields
|
|
250
274
|
*/
|
|
251
|
-
declare function assertStateHasFields<
|
|
275
|
+
declare function assertStateHasFields<TState extends object>(state: TState, fields: ReadonlyArray<keyof TState & (string | number)>): void;
|
|
252
276
|
/**
|
|
253
277
|
* Assert that a tool was called with specific arguments
|
|
254
278
|
*/
|
|
255
|
-
declare function assertToolCalled(toolCalls:
|
|
256
|
-
|
|
257
|
-
args: any;
|
|
258
|
-
}>, toolName: string, args?: Record<string, any>): void;
|
|
279
|
+
declare function assertToolCalled(toolCalls: ReadonlyArray<ToolCall>, toolName: string): void;
|
|
280
|
+
declare function assertToolCalled<TArgs extends Record<string, unknown>>(toolCalls: ReadonlyArray<ToolCall<TArgs>>, toolName: string, args: Partial<TArgs>): void;
|
|
259
281
|
/**
|
|
260
282
|
* Assert that execution completed within time limit
|
|
261
283
|
*/
|
|
262
|
-
declare function assertCompletesWithin(fn: () => Promise<
|
|
284
|
+
declare function assertCompletesWithin(fn: () => Promise<unknown>, maxMs: number): Promise<void>;
|
|
263
285
|
/**
|
|
264
286
|
* Assert that a function throws an error with specific message
|
|
265
287
|
*/
|
|
266
|
-
declare function assertThrowsWithMessage(fn: () => Promise<
|
|
288
|
+
declare function assertThrowsWithMessage(fn: () => Promise<unknown>, message: string): Promise<void>;
|
|
267
289
|
/**
|
|
268
290
|
* Assert that state matches a snapshot
|
|
269
291
|
*/
|
|
270
|
-
declare function assertStateSnapshot(state:
|
|
292
|
+
declare function assertStateSnapshot<TState extends object>(state: TState, snapshot: Partial<TState>): void;
|
|
271
293
|
/**
|
|
272
294
|
* Assert that messages have alternating types (human, ai, human, ai, ...)
|
|
273
295
|
*/
|
|
@@ -275,7 +297,7 @@ declare function assertAlternatingMessages(messages: BaseMessage[]): void;
|
|
|
275
297
|
/**
|
|
276
298
|
* Assert that an array is not empty
|
|
277
299
|
*/
|
|
278
|
-
declare function assertNotEmpty<T>(array: T[]): void;
|
|
300
|
+
declare function assertNotEmpty<T>(array: readonly T[]): void;
|
|
279
301
|
/**
|
|
280
302
|
* Assert that a value is within a range
|
|
281
303
|
*/
|
|
@@ -287,7 +309,7 @@ declare function assertIterationsWithinLimit(iterations: number, maxIterations:
|
|
|
287
309
|
/**
|
|
288
310
|
* Assert that a result contains expected keys
|
|
289
311
|
*/
|
|
290
|
-
declare function assertHasKeys<
|
|
312
|
+
declare function assertHasKeys<TObject extends object>(obj: TObject, keys: ReadonlyArray<keyof TObject & string>): void;
|
|
291
313
|
|
|
292
314
|
/**
|
|
293
315
|
* Sample conversation: Simple greeting
|
|
@@ -705,4 +727,4 @@ declare function createStateDiff(state1: any, state2: any, config?: SnapshotConf
|
|
|
705
727
|
*/
|
|
706
728
|
declare function assertStateChanged(stateBefore: any, stateAfter: any, expectedChanges: string[], config?: SnapshotConfig): void;
|
|
707
729
|
|
|
708
|
-
export { type AgentTestConfig, type AgentTestResult, AgentTestRunner, type ConversationResult, ConversationSimulator, type ConversationSimulatorConfig, MockLLM, type MockLLMConfig, type MockToolConfig, type SnapshotConfig, StateBuilder, assertAlternatingMessages, assertCompletesWithin, assertHasKeys, assertInRange, assertIsMessage, assertIterationsWithinLimit, assertLastMessageContains, assertMatchesSnapshot, assertMessageContains, assertMessagesMatchSnapshot, assertNotEmpty, assertStateChanged, assertStateHasFields, assertStateSnapshot, assertThrowsWithMessage, assertToolCalled, calculatorTool, compareStates, complexReasoningConversation, createAgentTestRunner, createCalculatorTool, createConversation, createConversationSimulator, createConversationState, createConversationWithSystem, createDelayedTool, createEchoLLM, createEchoTool, createErrorLLM, createErrorTool, createMessageSnapshot, createMockLLM, createMockTool, createPlanningState, createReActState, createSnapshot, createStateBuilder, createStateDiff, databaseQueryTool, errorHandlingConversation, fileReaderTool, getToolByName, getToolsByCategory, longContextConversation, multiTurnConversation, sampleData, sampleTools, searchTool, simpleGreeting, timeTool, toolUsageConversation, weatherTool };
|
|
730
|
+
export { type AgentTestConfig, type AgentTestResult, AgentTestRunner, type AssertedMessage, type ConversationResult, ConversationSimulator, type ConversationSimulatorConfig, MockLLM, type MockLLMConfig, type MockToolConfig, type PlanningStep, type PlanningTestState, type ReActTestState, type SnapshotConfig, StateBuilder, type TestToolCall, type TestToolResult, assertAlternatingMessages, assertCompletesWithin, assertHasKeys, assertInRange, assertIsMessage, assertIterationsWithinLimit, assertLastMessageContains, assertMatchesSnapshot, assertMessageContains, assertMessagesMatchSnapshot, assertNotEmpty, assertStateChanged, assertStateHasFields, assertStateSnapshot, assertThrowsWithMessage, assertToolCalled, calculatorTool, compareStates, complexReasoningConversation, createAgentTestRunner, createCalculatorTool, createConversation, createConversationSimulator, createConversationState, createConversationWithSystem, createDelayedTool, createEchoLLM, createEchoTool, createErrorLLM, createErrorTool, createMessageSnapshot, createMockLLM, createMockTool, createPlanningState, createReActState, createSnapshot, createStateBuilder, createStateDiff, databaseQueryTool, errorHandlingConversation, fileReaderTool, getToolByName, getToolsByCategory, longContextConversation, multiTurnConversation, sampleData, sampleTools, searchTool, simpleGreeting, timeTool, toolUsageConversation, weatherTool };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
-
import { HumanMessage, AIMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { HumanMessage, AIMessage, SystemMessage, BaseMessage } from '@langchain/core/messages';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { toolBuilder, ToolCategory } from '@agentforge/core';
|
|
5
5
|
import { isatty } from 'tty';
|
|
@@ -1632,14 +1632,18 @@ var StateBuilder = class {
|
|
|
1632
1632
|
Object.assign(this.state, fields);
|
|
1633
1633
|
return this;
|
|
1634
1634
|
}
|
|
1635
|
+
ensureMessages() {
|
|
1636
|
+
if (!this.state.messages) {
|
|
1637
|
+
const messages = [];
|
|
1638
|
+
this.state.messages = messages;
|
|
1639
|
+
}
|
|
1640
|
+
return this.state.messages;
|
|
1641
|
+
}
|
|
1635
1642
|
/**
|
|
1636
1643
|
* Add a message to the messages array
|
|
1637
1644
|
*/
|
|
1638
1645
|
addMessage(message) {
|
|
1639
|
-
|
|
1640
|
-
this.state.messages = [];
|
|
1641
|
-
}
|
|
1642
|
-
this.state.messages.push(message);
|
|
1646
|
+
this.ensureMessages().push(message);
|
|
1643
1647
|
return this;
|
|
1644
1648
|
}
|
|
1645
1649
|
/**
|
|
@@ -1685,7 +1689,7 @@ function createStateBuilder() {
|
|
|
1685
1689
|
return new StateBuilder();
|
|
1686
1690
|
}
|
|
1687
1691
|
function createConversationState(messages) {
|
|
1688
|
-
const builder = createStateBuilder();
|
|
1692
|
+
const builder = createStateBuilder().set("messages", []);
|
|
1689
1693
|
messages.forEach((msg, index) => {
|
|
1690
1694
|
if (index % 2 === 0) {
|
|
1691
1695
|
builder.addHumanMessage(msg);
|
|
@@ -1697,21 +1701,21 @@ function createConversationState(messages) {
|
|
|
1697
1701
|
}
|
|
1698
1702
|
function createReActState(config2 = {}) {
|
|
1699
1703
|
return {
|
|
1700
|
-
messages: config2.messages
|
|
1701
|
-
thoughts: config2.thoughts
|
|
1702
|
-
toolCalls: config2.toolCalls
|
|
1703
|
-
toolResults: config2.toolResults
|
|
1704
|
-
scratchpad: config2.scratchpad
|
|
1705
|
-
iterations: config2.iterations
|
|
1706
|
-
maxIterations: config2.maxIterations
|
|
1704
|
+
messages: config2.messages ?? [],
|
|
1705
|
+
thoughts: config2.thoughts ?? [],
|
|
1706
|
+
toolCalls: config2.toolCalls ?? [],
|
|
1707
|
+
toolResults: config2.toolResults ?? [],
|
|
1708
|
+
scratchpad: config2.scratchpad ?? [],
|
|
1709
|
+
iterations: config2.iterations ?? 0,
|
|
1710
|
+
maxIterations: config2.maxIterations ?? 10
|
|
1707
1711
|
};
|
|
1708
1712
|
}
|
|
1709
1713
|
function createPlanningState(config2 = {}) {
|
|
1710
1714
|
return {
|
|
1711
|
-
messages: config2.messages
|
|
1712
|
-
plan: config2.plan
|
|
1713
|
-
currentStep: config2.currentStep
|
|
1714
|
-
results: config2.results
|
|
1715
|
+
messages: config2.messages ?? [],
|
|
1716
|
+
plan: config2.plan ?? [],
|
|
1717
|
+
currentStep: config2.currentStep ?? 0,
|
|
1718
|
+
results: config2.results ?? {}
|
|
1715
1719
|
};
|
|
1716
1720
|
}
|
|
1717
1721
|
|
|
@@ -18342,13 +18346,25 @@ function getImporter(name) {
|
|
|
18342
18346
|
__toESM(require_dist());
|
|
18343
18347
|
|
|
18344
18348
|
// src/helpers/assertions.ts
|
|
18349
|
+
function isMessageLike(value) {
|
|
18350
|
+
if (typeof value !== "object" || value === null) {
|
|
18351
|
+
return false;
|
|
18352
|
+
}
|
|
18353
|
+
const candidate = value;
|
|
18354
|
+
return "content" in candidate && typeof candidate._getType === "function";
|
|
18355
|
+
}
|
|
18345
18356
|
function assertIsMessage(value, type3) {
|
|
18346
18357
|
globalExpect(value).toBeDefined();
|
|
18347
|
-
globalExpect(value).
|
|
18348
|
-
|
|
18349
|
-
|
|
18350
|
-
|
|
18351
|
-
|
|
18358
|
+
globalExpect(value).not.toBeNull();
|
|
18359
|
+
globalExpect(typeof value).toBe("object");
|
|
18360
|
+
const samePackageMessage = value instanceof BaseMessage;
|
|
18361
|
+
const structuralMessage = isMessageLike(value);
|
|
18362
|
+
globalExpect(samePackageMessage || structuralMessage).toBe(true);
|
|
18363
|
+
const message = value;
|
|
18364
|
+
const messageType = message._getType();
|
|
18365
|
+
globalExpect(typeof messageType).toBe("string");
|
|
18366
|
+
if (type3) {
|
|
18367
|
+
globalExpect(messageType).toBe(type3);
|
|
18352
18368
|
}
|
|
18353
18369
|
}
|
|
18354
18370
|
function assertMessageContains(messages, content) {
|
|
@@ -18364,7 +18380,7 @@ function assertLastMessageContains(messages, content) {
|
|
|
18364
18380
|
}
|
|
18365
18381
|
function assertStateHasFields(state, fields) {
|
|
18366
18382
|
fields.forEach((field) => {
|
|
18367
|
-
globalExpect(state).toHaveProperty(field);
|
|
18383
|
+
globalExpect(state).toHaveProperty(typeof field === "number" ? [field] : field);
|
|
18368
18384
|
});
|
|
18369
18385
|
}
|
|
18370
18386
|
function assertToolCalled(toolCalls, toolName, args) {
|