@agentforge/core 0.16.25 → 0.16.27

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 CHANGED
@@ -2244,6 +2244,12 @@ function cache(tool, ttl) {
2244
2244
  }
2245
2245
 
2246
2246
  // src/tools/testing.ts
2247
+ function matchesMockInput(matcher, input) {
2248
+ if (typeof matcher === "function") {
2249
+ return matcher(input);
2250
+ }
2251
+ return JSON.stringify(matcher) === JSON.stringify(input);
2252
+ }
2247
2253
  function createMockTool(config) {
2248
2254
  const {
2249
2255
  name,
@@ -2273,12 +2279,7 @@ function createMockTool(config) {
2273
2279
  });
2274
2280
  throw error2;
2275
2281
  }
2276
- const matchingResponse = responses.find((r) => {
2277
- if (typeof r.input === "function") {
2278
- return r.input(input);
2279
- }
2280
- return JSON.stringify(r.input) === JSON.stringify(input);
2281
- });
2282
+ const matchingResponse = responses.find((response) => matchesMockInput(response.input, input));
2282
2283
  if (matchingResponse) {
2283
2284
  if (matchingResponse.error) {
2284
2285
  invocations.push({
@@ -2382,7 +2383,8 @@ function createToolSimulator(config) {
2382
2383
  }
2383
2384
  },
2384
2385
  getInvocations: (toolName) => {
2385
- return invocations.get(toolName) ? [...invocations.get(toolName)] : [];
2386
+ const toolInvocations = invocations.get(toolName) ?? [];
2387
+ return [...toolInvocations];
2386
2388
  },
2387
2389
  getAllInvocations: () => {
2388
2390
  const all = {};
package/dist/index.d.cts CHANGED
@@ -1748,34 +1748,48 @@ declare function cache<TInput = unknown, TOutput = unknown>(tool: ComposedTool<T
1748
1748
  * Tool Mocking & Testing - Mock tools for testing
1749
1749
  * @module tools/testing
1750
1750
  */
1751
- interface MockToolResponse {
1752
- input: any;
1753
- output?: any;
1754
- error?: Error;
1755
- }
1756
- interface MockToolConfig {
1757
- name: string;
1751
+ type MockToolMatcher<TInput> = TInput | ((input: TInput) => boolean);
1752
+ interface MockToolSuccessResponse<TInput, TOutput> {
1753
+ input: MockToolMatcher<TInput>;
1754
+ output: TOutput;
1755
+ error?: never;
1756
+ }
1757
+ interface MockToolErrorResponse<TInput> {
1758
+ input: MockToolMatcher<TInput>;
1759
+ output?: never;
1760
+ error: Error;
1761
+ }
1762
+ type MockToolResponse<TInput = unknown, TOutput = unknown> = MockToolSuccessResponse<TInput, TOutput> | MockToolErrorResponse<TInput>;
1763
+ interface MockToolConfig<TName extends string = string, TInput = unknown, TOutput = unknown> {
1764
+ name: TName;
1758
1765
  description?: string;
1759
- responses?: MockToolResponse[];
1760
- defaultResponse?: any;
1766
+ responses?: MockToolResponse<TInput, TOutput>[];
1767
+ defaultResponse?: TOutput;
1761
1768
  latency?: {
1762
1769
  min: number;
1763
1770
  max: number;
1764
1771
  } | number;
1765
1772
  errorRate?: number;
1766
1773
  }
1767
- interface ToolInvocation {
1768
- input: any;
1769
- output?: any;
1774
+ interface ToolInvocation<TInput = unknown, TOutput = unknown> {
1775
+ input: TInput;
1776
+ output?: TOutput;
1770
1777
  error?: Error;
1771
1778
  timestamp: number;
1772
1779
  duration: number;
1773
1780
  }
1774
- interface ToolSimulatorConfig {
1775
- tools: Array<{
1776
- name: string;
1777
- invoke: (input: any) => Promise<any>;
1778
- }>;
1781
+ interface SimulatedTool<TName extends string = string, TInput = unknown, TOutput = unknown> {
1782
+ name: TName;
1783
+ invoke(input: TInput): Promise<TOutput>;
1784
+ }
1785
+ type ToolName<TTools extends readonly SimulatedTool[]> = TTools[number]['name'] & string;
1786
+ type ToolByName<TTools extends readonly SimulatedTool[], TName extends ToolName<TTools>> = Extract<TTools[number], {
1787
+ name: TName;
1788
+ }>;
1789
+ type ToolInputFor<TTools extends readonly SimulatedTool[], TName extends ToolName<TTools>> = ToolByName<TTools, TName> extends SimulatedTool<string, infer TInput, unknown> ? TInput : never;
1790
+ type ToolOutputFor<TTools extends readonly SimulatedTool[], TName extends ToolName<TTools>> = ToolByName<TTools, TName> extends SimulatedTool<string, unknown, infer TOutput> ? TOutput : never;
1791
+ interface ToolSimulatorConfig<TTools extends readonly SimulatedTool[] = readonly SimulatedTool[]> {
1792
+ tools: TTools;
1779
1793
  errorRate?: number;
1780
1794
  latency?: {
1781
1795
  mean: number;
@@ -1783,24 +1797,23 @@ interface ToolSimulatorConfig {
1783
1797
  };
1784
1798
  recordInvocations?: boolean;
1785
1799
  }
1800
+ interface MockTool<TName extends string = string, TInput = unknown, TOutput = unknown> extends SimulatedTool<TName, TInput, TOutput> {
1801
+ description: string;
1802
+ getInvocations: () => ToolInvocation<TInput, TOutput>[];
1803
+ clearInvocations: () => void;
1804
+ }
1786
1805
  /**
1787
1806
  * Create a mock tool for testing
1788
1807
  */
1789
- declare function createMockTool(config: MockToolConfig): {
1790
- name: string;
1791
- description: string;
1792
- invoke: (input: any) => Promise<any>;
1793
- getInvocations: () => ToolInvocation[];
1794
- clearInvocations: () => void;
1795
- };
1808
+ declare function createMockTool<TName extends string, TInput = unknown, TOutput = unknown>(config: MockToolConfig<TName, TInput, TOutput>): MockTool<TName, TInput, TOutput>;
1796
1809
  /**
1797
1810
  * Create a tool simulator for testing
1798
1811
  */
1799
- declare function createToolSimulator(config: ToolSimulatorConfig): {
1800
- execute: (toolName: string, input: any) => Promise<any>;
1801
- getInvocations: (toolName: string) => ToolInvocation[];
1802
- getAllInvocations: () => Record<string, ToolInvocation[]>;
1803
- clearInvocations: (toolName?: string) => void;
1812
+ declare function createToolSimulator<const TTools extends readonly SimulatedTool[]>(config: ToolSimulatorConfig<TTools>): {
1813
+ execute: <TName extends ToolName<TTools>>(toolName: TName, input: ToolInputFor<TTools, TName>) => Promise<ToolOutputFor<TTools, TName>>;
1814
+ getInvocations: <TName extends ToolName<TTools>>(toolName: TName) => ToolInvocation<ToolInputFor<TTools, TName>, ToolOutputFor<TTools, TName>>[];
1815
+ getAllInvocations: () => Partial<Record<TTools[number]["name"], ToolInvocation<unknown, unknown>[]>>;
1816
+ clearInvocations: (toolName?: ToolName<TTools>) => void;
1804
1817
  };
1805
1818
 
1806
1819
  /**
@@ -4901,7 +4914,7 @@ interface InterruptEventData {
4901
4914
  interface ResumeEventData {
4902
4915
  type: 'resume';
4903
4916
  interruptId: string;
4904
- value: any;
4917
+ value: InterruptPayload;
4905
4918
  threadId: string;
4906
4919
  }
4907
4920
  /**
@@ -4963,7 +4976,7 @@ declare function formatInterruptEvent(interrupt: AnyInterrupt, threadId: string)
4963
4976
  * @param threadId - The thread ID
4964
4977
  * @returns An SSE event
4965
4978
  */
4966
- declare function formatResumeEvent(interruptId: string, value: any, threadId: string): SSEEvent;
4979
+ declare function formatResumeEvent(interruptId: string, value: InterruptPayload, threadId: string): SSEEvent;
4967
4980
  /**
4968
4981
  * Format an agent waiting event as an SSE event
4969
4982
  *
package/dist/index.d.ts CHANGED
@@ -1748,34 +1748,48 @@ declare function cache<TInput = unknown, TOutput = unknown>(tool: ComposedTool<T
1748
1748
  * Tool Mocking & Testing - Mock tools for testing
1749
1749
  * @module tools/testing
1750
1750
  */
1751
- interface MockToolResponse {
1752
- input: any;
1753
- output?: any;
1754
- error?: Error;
1755
- }
1756
- interface MockToolConfig {
1757
- name: string;
1751
+ type MockToolMatcher<TInput> = TInput | ((input: TInput) => boolean);
1752
+ interface MockToolSuccessResponse<TInput, TOutput> {
1753
+ input: MockToolMatcher<TInput>;
1754
+ output: TOutput;
1755
+ error?: never;
1756
+ }
1757
+ interface MockToolErrorResponse<TInput> {
1758
+ input: MockToolMatcher<TInput>;
1759
+ output?: never;
1760
+ error: Error;
1761
+ }
1762
+ type MockToolResponse<TInput = unknown, TOutput = unknown> = MockToolSuccessResponse<TInput, TOutput> | MockToolErrorResponse<TInput>;
1763
+ interface MockToolConfig<TName extends string = string, TInput = unknown, TOutput = unknown> {
1764
+ name: TName;
1758
1765
  description?: string;
1759
- responses?: MockToolResponse[];
1760
- defaultResponse?: any;
1766
+ responses?: MockToolResponse<TInput, TOutput>[];
1767
+ defaultResponse?: TOutput;
1761
1768
  latency?: {
1762
1769
  min: number;
1763
1770
  max: number;
1764
1771
  } | number;
1765
1772
  errorRate?: number;
1766
1773
  }
1767
- interface ToolInvocation {
1768
- input: any;
1769
- output?: any;
1774
+ interface ToolInvocation<TInput = unknown, TOutput = unknown> {
1775
+ input: TInput;
1776
+ output?: TOutput;
1770
1777
  error?: Error;
1771
1778
  timestamp: number;
1772
1779
  duration: number;
1773
1780
  }
1774
- interface ToolSimulatorConfig {
1775
- tools: Array<{
1776
- name: string;
1777
- invoke: (input: any) => Promise<any>;
1778
- }>;
1781
+ interface SimulatedTool<TName extends string = string, TInput = unknown, TOutput = unknown> {
1782
+ name: TName;
1783
+ invoke(input: TInput): Promise<TOutput>;
1784
+ }
1785
+ type ToolName<TTools extends readonly SimulatedTool[]> = TTools[number]['name'] & string;
1786
+ type ToolByName<TTools extends readonly SimulatedTool[], TName extends ToolName<TTools>> = Extract<TTools[number], {
1787
+ name: TName;
1788
+ }>;
1789
+ type ToolInputFor<TTools extends readonly SimulatedTool[], TName extends ToolName<TTools>> = ToolByName<TTools, TName> extends SimulatedTool<string, infer TInput, unknown> ? TInput : never;
1790
+ type ToolOutputFor<TTools extends readonly SimulatedTool[], TName extends ToolName<TTools>> = ToolByName<TTools, TName> extends SimulatedTool<string, unknown, infer TOutput> ? TOutput : never;
1791
+ interface ToolSimulatorConfig<TTools extends readonly SimulatedTool[] = readonly SimulatedTool[]> {
1792
+ tools: TTools;
1779
1793
  errorRate?: number;
1780
1794
  latency?: {
1781
1795
  mean: number;
@@ -1783,24 +1797,23 @@ interface ToolSimulatorConfig {
1783
1797
  };
1784
1798
  recordInvocations?: boolean;
1785
1799
  }
1800
+ interface MockTool<TName extends string = string, TInput = unknown, TOutput = unknown> extends SimulatedTool<TName, TInput, TOutput> {
1801
+ description: string;
1802
+ getInvocations: () => ToolInvocation<TInput, TOutput>[];
1803
+ clearInvocations: () => void;
1804
+ }
1786
1805
  /**
1787
1806
  * Create a mock tool for testing
1788
1807
  */
1789
- declare function createMockTool(config: MockToolConfig): {
1790
- name: string;
1791
- description: string;
1792
- invoke: (input: any) => Promise<any>;
1793
- getInvocations: () => ToolInvocation[];
1794
- clearInvocations: () => void;
1795
- };
1808
+ declare function createMockTool<TName extends string, TInput = unknown, TOutput = unknown>(config: MockToolConfig<TName, TInput, TOutput>): MockTool<TName, TInput, TOutput>;
1796
1809
  /**
1797
1810
  * Create a tool simulator for testing
1798
1811
  */
1799
- declare function createToolSimulator(config: ToolSimulatorConfig): {
1800
- execute: (toolName: string, input: any) => Promise<any>;
1801
- getInvocations: (toolName: string) => ToolInvocation[];
1802
- getAllInvocations: () => Record<string, ToolInvocation[]>;
1803
- clearInvocations: (toolName?: string) => void;
1812
+ declare function createToolSimulator<const TTools extends readonly SimulatedTool[]>(config: ToolSimulatorConfig<TTools>): {
1813
+ execute: <TName extends ToolName<TTools>>(toolName: TName, input: ToolInputFor<TTools, TName>) => Promise<ToolOutputFor<TTools, TName>>;
1814
+ getInvocations: <TName extends ToolName<TTools>>(toolName: TName) => ToolInvocation<ToolInputFor<TTools, TName>, ToolOutputFor<TTools, TName>>[];
1815
+ getAllInvocations: () => Partial<Record<TTools[number]["name"], ToolInvocation<unknown, unknown>[]>>;
1816
+ clearInvocations: (toolName?: ToolName<TTools>) => void;
1804
1817
  };
1805
1818
 
1806
1819
  /**
@@ -4901,7 +4914,7 @@ interface InterruptEventData {
4901
4914
  interface ResumeEventData {
4902
4915
  type: 'resume';
4903
4916
  interruptId: string;
4904
- value: any;
4917
+ value: InterruptPayload;
4905
4918
  threadId: string;
4906
4919
  }
4907
4920
  /**
@@ -4963,7 +4976,7 @@ declare function formatInterruptEvent(interrupt: AnyInterrupt, threadId: string)
4963
4976
  * @param threadId - The thread ID
4964
4977
  * @returns An SSE event
4965
4978
  */
4966
- declare function formatResumeEvent(interruptId: string, value: any, threadId: string): SSEEvent;
4979
+ declare function formatResumeEvent(interruptId: string, value: InterruptPayload, threadId: string): SSEEvent;
4967
4980
  /**
4968
4981
  * Format an agent waiting event as an SSE event
4969
4982
  *
package/dist/index.js CHANGED
@@ -2069,6 +2069,12 @@ function cache(tool, ttl) {
2069
2069
  }
2070
2070
 
2071
2071
  // src/tools/testing.ts
2072
+ function matchesMockInput(matcher, input) {
2073
+ if (typeof matcher === "function") {
2074
+ return matcher(input);
2075
+ }
2076
+ return JSON.stringify(matcher) === JSON.stringify(input);
2077
+ }
2072
2078
  function createMockTool(config) {
2073
2079
  const {
2074
2080
  name,
@@ -2098,12 +2104,7 @@ function createMockTool(config) {
2098
2104
  });
2099
2105
  throw error2;
2100
2106
  }
2101
- const matchingResponse = responses.find((r) => {
2102
- if (typeof r.input === "function") {
2103
- return r.input(input);
2104
- }
2105
- return JSON.stringify(r.input) === JSON.stringify(input);
2106
- });
2107
+ const matchingResponse = responses.find((response) => matchesMockInput(response.input, input));
2107
2108
  if (matchingResponse) {
2108
2109
  if (matchingResponse.error) {
2109
2110
  invocations.push({
@@ -2207,7 +2208,8 @@ function createToolSimulator(config) {
2207
2208
  }
2208
2209
  },
2209
2210
  getInvocations: (toolName) => {
2210
- return invocations.get(toolName) ? [...invocations.get(toolName)] : [];
2211
+ const toolInvocations = invocations.get(toolName) ?? [];
2212
+ return [...toolInvocations];
2211
2213
  },
2212
2214
  getAllInvocations: () => {
2213
2215
  const all = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge/core",
3
- "version": "0.16.25",
3
+ "version": "0.16.27",
4
4
  "description": "Production-ready TypeScript agent framework built on LangGraph with orchestration, middleware, and typed abstractions.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",