@agentforge/tools 0.5.1 → 0.5.3

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.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as _agentforge_core from '@agentforge/core';
2
+ import { HumanRequestPriority } from '@agentforge/core';
2
3
  import { z } from 'zod';
3
4
 
4
5
  /**
@@ -1389,4 +1390,146 @@ declare const uuidValidator: _agentforge_core.Tool<{
1389
1390
  message: string;
1390
1391
  }>;
1391
1392
 
1392
- export { DuckDuckGoProvider, type HttpResponse, type RetryConfig, type ScraperResult, type SearchProvider, type SearchResult, SerperProvider, type UrlValidationResult, type WebSearchInput, type WebSearchOutput, arrayFilter, arrayGroupBy, arrayMap, arraySort, calculator, createDuckDuckGoProvider, createSerperProvider, creditCardValidator, csvGenerator, csvParser, csvToJson, currentDateTime, dateArithmetic, dateComparison, dateDifference, dateFormatter, directoryCreate, directoryDelete, directoryList, emailValidator, extractImages, extractLinks, fileAppend, fileDelete, fileExists, fileReader, fileSearch, fileWriter, htmlParser, httpClient, httpGet, httpPost, ipValidator, jsonMerge, jsonParser, jsonQuery, jsonStringify, jsonToCsv, jsonToXml, jsonValidator, mathFunctions, objectOmit, objectPick, pathBasename, pathDirname, pathExtension, pathJoin, pathNormalize, pathParse, pathRelative, pathResolve, phoneValidator, randomNumber, searchResultSchema, statistics, stringCaseConverter, stringJoin, stringLength, stringReplace, stringSplit, stringSubstring, stringTrim, urlBuilder, urlQueryParser, urlValidator, urlValidatorSimple, uuidValidator, webScraper, webSearch, webSearchOutputSchema, webSearchSchema, xmlGenerator, xmlParser, xmlToJson };
1393
+ /**
1394
+ * Types for askHuman tool and human-in-the-loop workflows
1395
+ * @module tools/agent/ask-human/types
1396
+ */
1397
+
1398
+ /**
1399
+ * Input schema for askHuman tool
1400
+ */
1401
+ declare const AskHumanInputSchema: z.ZodObject<{
1402
+ /**
1403
+ * The question to ask the human
1404
+ */
1405
+ question: z.ZodString;
1406
+ /**
1407
+ * Optional context to help the human understand the question
1408
+ */
1409
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1410
+ /**
1411
+ * Priority level for this request
1412
+ */
1413
+ priority: z.ZodDefault<z.ZodEnum<["low", "normal", "high", "critical"]>>;
1414
+ /**
1415
+ * Timeout in milliseconds (0 = no timeout)
1416
+ */
1417
+ timeout: z.ZodDefault<z.ZodNumber>;
1418
+ /**
1419
+ * Default response if timeout occurs
1420
+ */
1421
+ defaultResponse: z.ZodOptional<z.ZodString>;
1422
+ /**
1423
+ * Suggested responses (for UI to show as options)
1424
+ */
1425
+ suggestions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1426
+ }, "strip", z.ZodTypeAny, {
1427
+ timeout: number;
1428
+ question: string;
1429
+ priority: "low" | "normal" | "high" | "critical";
1430
+ context?: Record<string, any> | undefined;
1431
+ defaultResponse?: string | undefined;
1432
+ suggestions?: string[] | undefined;
1433
+ }, {
1434
+ question: string;
1435
+ timeout?: number | undefined;
1436
+ context?: Record<string, any> | undefined;
1437
+ priority?: "low" | "normal" | "high" | "critical" | undefined;
1438
+ defaultResponse?: string | undefined;
1439
+ suggestions?: string[] | undefined;
1440
+ }>;
1441
+ /**
1442
+ * Input type for askHuman tool
1443
+ */
1444
+ type AskHumanInput = z.infer<typeof AskHumanInputSchema>;
1445
+ /**
1446
+ * Output from askHuman tool
1447
+ */
1448
+ interface AskHumanOutput {
1449
+ /**
1450
+ * The human's response
1451
+ */
1452
+ response: string;
1453
+ /**
1454
+ * Metadata about the interaction
1455
+ */
1456
+ metadata: {
1457
+ /**
1458
+ * Unique ID for this request
1459
+ */
1460
+ requestId: string;
1461
+ /**
1462
+ * When the request was created
1463
+ */
1464
+ requestedAt: number;
1465
+ /**
1466
+ * When the response was received
1467
+ */
1468
+ respondedAt: number;
1469
+ /**
1470
+ * How long it took to get a response (ms)
1471
+ */
1472
+ duration: number;
1473
+ /**
1474
+ * Whether this was a timeout response
1475
+ */
1476
+ timedOut: boolean;
1477
+ /**
1478
+ * Priority level
1479
+ */
1480
+ priority: HumanRequestPriority;
1481
+ };
1482
+ }
1483
+
1484
+ /**
1485
+ * Create the askHuman tool
1486
+ *
1487
+ * This tool enables human-in-the-loop workflows by pausing agent execution
1488
+ * and waiting for human input. It uses LangGraph's interrupt mechanism.
1489
+ *
1490
+ * @example
1491
+ * ```typescript
1492
+ * import { createAskHumanTool } from '@agentforge/tools';
1493
+ *
1494
+ * const askHuman = createAskHumanTool();
1495
+ *
1496
+ * // In your agent
1497
+ * const tools = [askHuman, ...otherTools];
1498
+ *
1499
+ * // The agent can call this tool to ask for human input
1500
+ * // When called, it will pause execution and wait for a response
1501
+ * ```
1502
+ *
1503
+ * @returns The askHuman tool
1504
+ */
1505
+ declare function createAskHumanTool(): _agentforge_core.Tool<{
1506
+ question: string;
1507
+ timeout?: number | undefined;
1508
+ context?: Record<string, any> | undefined;
1509
+ priority?: "low" | "normal" | "high" | "critical" | undefined;
1510
+ defaultResponse?: string | undefined;
1511
+ suggestions?: string[] | undefined;
1512
+ }, AskHumanOutput>;
1513
+ /**
1514
+ * Default instance of the askHuman tool
1515
+ *
1516
+ * @example
1517
+ * ```typescript
1518
+ * import { askHumanTool } from '@agentforge/core';
1519
+ *
1520
+ * const agent = createReActAgent({
1521
+ * llm,
1522
+ * tools: [askHumanTool, ...otherTools],
1523
+ * });
1524
+ * ```
1525
+ */
1526
+ declare const askHumanTool: _agentforge_core.Tool<{
1527
+ question: string;
1528
+ timeout?: number | undefined;
1529
+ context?: Record<string, any> | undefined;
1530
+ priority?: "low" | "normal" | "high" | "critical" | undefined;
1531
+ defaultResponse?: string | undefined;
1532
+ suggestions?: string[] | undefined;
1533
+ }, AskHumanOutput>;
1534
+
1535
+ export { type AskHumanInput, AskHumanInputSchema, type AskHumanOutput, DuckDuckGoProvider, type HttpResponse, type RetryConfig, type ScraperResult, type SearchProvider, type SearchResult, SerperProvider, type UrlValidationResult, type WebSearchInput, type WebSearchOutput, arrayFilter, arrayGroupBy, arrayMap, arraySort, askHumanTool, calculator, createAskHumanTool, createDuckDuckGoProvider, createSerperProvider, creditCardValidator, csvGenerator, csvParser, csvToJson, currentDateTime, dateArithmetic, dateComparison, dateDifference, dateFormatter, directoryCreate, directoryDelete, directoryList, emailValidator, extractImages, extractLinks, fileAppend, fileDelete, fileExists, fileReader, fileSearch, fileWriter, htmlParser, httpClient, httpGet, httpPost, ipValidator, jsonMerge, jsonParser, jsonQuery, jsonStringify, jsonToCsv, jsonToXml, jsonValidator, mathFunctions, objectOmit, objectPick, pathBasename, pathDirname, pathExtension, pathJoin, pathNormalize, pathParse, pathRelative, pathResolve, phoneValidator, randomNumber, searchResultSchema, statistics, stringCaseConverter, stringJoin, stringLength, stringReplace, stringSplit, stringSubstring, stringTrim, urlBuilder, urlQueryParser, urlValidator, urlValidatorSimple, uuidValidator, webScraper, webSearch, webSearchOutputSchema, webSearchSchema, xmlGenerator, xmlParser, xmlToJson };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as _agentforge_core from '@agentforge/core';
2
+ import { HumanRequestPriority } from '@agentforge/core';
2
3
  import { z } from 'zod';
3
4
 
4
5
  /**
@@ -1389,4 +1390,146 @@ declare const uuidValidator: _agentforge_core.Tool<{
1389
1390
  message: string;
1390
1391
  }>;
1391
1392
 
1392
- export { DuckDuckGoProvider, type HttpResponse, type RetryConfig, type ScraperResult, type SearchProvider, type SearchResult, SerperProvider, type UrlValidationResult, type WebSearchInput, type WebSearchOutput, arrayFilter, arrayGroupBy, arrayMap, arraySort, calculator, createDuckDuckGoProvider, createSerperProvider, creditCardValidator, csvGenerator, csvParser, csvToJson, currentDateTime, dateArithmetic, dateComparison, dateDifference, dateFormatter, directoryCreate, directoryDelete, directoryList, emailValidator, extractImages, extractLinks, fileAppend, fileDelete, fileExists, fileReader, fileSearch, fileWriter, htmlParser, httpClient, httpGet, httpPost, ipValidator, jsonMerge, jsonParser, jsonQuery, jsonStringify, jsonToCsv, jsonToXml, jsonValidator, mathFunctions, objectOmit, objectPick, pathBasename, pathDirname, pathExtension, pathJoin, pathNormalize, pathParse, pathRelative, pathResolve, phoneValidator, randomNumber, searchResultSchema, statistics, stringCaseConverter, stringJoin, stringLength, stringReplace, stringSplit, stringSubstring, stringTrim, urlBuilder, urlQueryParser, urlValidator, urlValidatorSimple, uuidValidator, webScraper, webSearch, webSearchOutputSchema, webSearchSchema, xmlGenerator, xmlParser, xmlToJson };
1393
+ /**
1394
+ * Types for askHuman tool and human-in-the-loop workflows
1395
+ * @module tools/agent/ask-human/types
1396
+ */
1397
+
1398
+ /**
1399
+ * Input schema for askHuman tool
1400
+ */
1401
+ declare const AskHumanInputSchema: z.ZodObject<{
1402
+ /**
1403
+ * The question to ask the human
1404
+ */
1405
+ question: z.ZodString;
1406
+ /**
1407
+ * Optional context to help the human understand the question
1408
+ */
1409
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1410
+ /**
1411
+ * Priority level for this request
1412
+ */
1413
+ priority: z.ZodDefault<z.ZodEnum<["low", "normal", "high", "critical"]>>;
1414
+ /**
1415
+ * Timeout in milliseconds (0 = no timeout)
1416
+ */
1417
+ timeout: z.ZodDefault<z.ZodNumber>;
1418
+ /**
1419
+ * Default response if timeout occurs
1420
+ */
1421
+ defaultResponse: z.ZodOptional<z.ZodString>;
1422
+ /**
1423
+ * Suggested responses (for UI to show as options)
1424
+ */
1425
+ suggestions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1426
+ }, "strip", z.ZodTypeAny, {
1427
+ timeout: number;
1428
+ question: string;
1429
+ priority: "low" | "normal" | "high" | "critical";
1430
+ context?: Record<string, any> | undefined;
1431
+ defaultResponse?: string | undefined;
1432
+ suggestions?: string[] | undefined;
1433
+ }, {
1434
+ question: string;
1435
+ timeout?: number | undefined;
1436
+ context?: Record<string, any> | undefined;
1437
+ priority?: "low" | "normal" | "high" | "critical" | undefined;
1438
+ defaultResponse?: string | undefined;
1439
+ suggestions?: string[] | undefined;
1440
+ }>;
1441
+ /**
1442
+ * Input type for askHuman tool
1443
+ */
1444
+ type AskHumanInput = z.infer<typeof AskHumanInputSchema>;
1445
+ /**
1446
+ * Output from askHuman tool
1447
+ */
1448
+ interface AskHumanOutput {
1449
+ /**
1450
+ * The human's response
1451
+ */
1452
+ response: string;
1453
+ /**
1454
+ * Metadata about the interaction
1455
+ */
1456
+ metadata: {
1457
+ /**
1458
+ * Unique ID for this request
1459
+ */
1460
+ requestId: string;
1461
+ /**
1462
+ * When the request was created
1463
+ */
1464
+ requestedAt: number;
1465
+ /**
1466
+ * When the response was received
1467
+ */
1468
+ respondedAt: number;
1469
+ /**
1470
+ * How long it took to get a response (ms)
1471
+ */
1472
+ duration: number;
1473
+ /**
1474
+ * Whether this was a timeout response
1475
+ */
1476
+ timedOut: boolean;
1477
+ /**
1478
+ * Priority level
1479
+ */
1480
+ priority: HumanRequestPriority;
1481
+ };
1482
+ }
1483
+
1484
+ /**
1485
+ * Create the askHuman tool
1486
+ *
1487
+ * This tool enables human-in-the-loop workflows by pausing agent execution
1488
+ * and waiting for human input. It uses LangGraph's interrupt mechanism.
1489
+ *
1490
+ * @example
1491
+ * ```typescript
1492
+ * import { createAskHumanTool } from '@agentforge/tools';
1493
+ *
1494
+ * const askHuman = createAskHumanTool();
1495
+ *
1496
+ * // In your agent
1497
+ * const tools = [askHuman, ...otherTools];
1498
+ *
1499
+ * // The agent can call this tool to ask for human input
1500
+ * // When called, it will pause execution and wait for a response
1501
+ * ```
1502
+ *
1503
+ * @returns The askHuman tool
1504
+ */
1505
+ declare function createAskHumanTool(): _agentforge_core.Tool<{
1506
+ question: string;
1507
+ timeout?: number | undefined;
1508
+ context?: Record<string, any> | undefined;
1509
+ priority?: "low" | "normal" | "high" | "critical" | undefined;
1510
+ defaultResponse?: string | undefined;
1511
+ suggestions?: string[] | undefined;
1512
+ }, AskHumanOutput>;
1513
+ /**
1514
+ * Default instance of the askHuman tool
1515
+ *
1516
+ * @example
1517
+ * ```typescript
1518
+ * import { askHumanTool } from '@agentforge/core';
1519
+ *
1520
+ * const agent = createReActAgent({
1521
+ * llm,
1522
+ * tools: [askHumanTool, ...otherTools],
1523
+ * });
1524
+ * ```
1525
+ */
1526
+ declare const askHumanTool: _agentforge_core.Tool<{
1527
+ question: string;
1528
+ timeout?: number | undefined;
1529
+ context?: Record<string, any> | undefined;
1530
+ priority?: "low" | "normal" | "high" | "critical" | undefined;
1531
+ defaultResponse?: string | undefined;
1532
+ suggestions?: string[] | undefined;
1533
+ }, AskHumanOutput>;
1534
+
1535
+ export { type AskHumanInput, AskHumanInputSchema, type AskHumanOutput, DuckDuckGoProvider, type HttpResponse, type RetryConfig, type ScraperResult, type SearchProvider, type SearchResult, SerperProvider, type UrlValidationResult, type WebSearchInput, type WebSearchOutput, arrayFilter, arrayGroupBy, arrayMap, arraySort, askHumanTool, calculator, createAskHumanTool, createDuckDuckGoProvider, createSerperProvider, creditCardValidator, csvGenerator, csvParser, csvToJson, currentDateTime, dateArithmetic, dateComparison, dateDifference, dateFormatter, directoryCreate, directoryDelete, directoryList, emailValidator, extractImages, extractLinks, fileAppend, fileDelete, fileExists, fileReader, fileSearch, fileWriter, htmlParser, httpClient, httpGet, httpPost, ipValidator, jsonMerge, jsonParser, jsonQuery, jsonStringify, jsonToCsv, jsonToXml, jsonValidator, mathFunctions, objectOmit, objectPick, pathBasename, pathDirname, pathExtension, pathJoin, pathNormalize, pathParse, pathRelative, pathResolve, phoneValidator, randomNumber, searchResultSchema, statistics, stringCaseConverter, stringJoin, stringLength, stringReplace, stringSplit, stringSubstring, stringTrim, urlBuilder, urlQueryParser, urlValidator, urlValidatorSimple, uuidValidator, webScraper, webSearch, webSearchOutputSchema, webSearchSchema, xmlGenerator, xmlParser, xmlToJson };
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import { XMLParser, XMLBuilder } from 'fast-xml-parser';
8
8
  import { promises } from 'fs';
9
9
  import * as path3 from 'path';
10
10
  import { format, parse as parse$1, isValid, add, sub, differenceInDays, differenceInHours, differenceInMinutes, isAfter, isBefore } from 'date-fns';
11
+ import { randomUUID } from 'crypto';
11
12
 
12
13
  // src/web/http-client.ts
13
14
  var HttpMethod = z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]);
@@ -1967,7 +1968,84 @@ var uuidValidator = toolBuilder().name("uuid-validator").description("Validate i
1967
1968
  message: valid ? `Valid UUID v${version}` : "Invalid UUID format"
1968
1969
  };
1969
1970
  }).build();
1971
+ var AskHumanInputSchema = z.object({
1972
+ /**
1973
+ * The question to ask the human
1974
+ */
1975
+ question: z.string().min(1).describe("The question to ask the human"),
1976
+ /**
1977
+ * Optional context to help the human understand the question
1978
+ */
1979
+ context: z.record(z.any()).optional().describe("Additional context for the question"),
1980
+ /**
1981
+ * Priority level for this request
1982
+ */
1983
+ priority: z.enum(["low", "normal", "high", "critical"]).default("normal").describe("Priority level for this request"),
1984
+ /**
1985
+ * Timeout in milliseconds (0 = no timeout)
1986
+ */
1987
+ timeout: z.number().min(0).default(0).describe("Timeout in milliseconds (0 = no timeout)"),
1988
+ /**
1989
+ * Default response if timeout occurs
1990
+ */
1991
+ defaultResponse: z.string().optional().describe("Default response if timeout occurs"),
1992
+ /**
1993
+ * Suggested responses (for UI to show as options)
1994
+ */
1995
+ suggestions: z.array(z.string()).optional().describe("Suggested responses for the human")
1996
+ });
1997
+ function createAskHumanTool() {
1998
+ return toolBuilder().name("ask-human").description(
1999
+ "Ask a human for input or approval. Use this when you need human guidance, approval for a critical action, or clarification on ambiguous requirements. The agent execution will pause until the human responds."
2000
+ ).category(ToolCategory.UTILITY).schema(AskHumanInputSchema).implement(async (input) => {
2001
+ const validatedInput = input;
2002
+ const requestId = randomUUID();
2003
+ const requestedAt = Date.now();
2004
+ let interrupt;
2005
+ try {
2006
+ const langgraph = await import('@langchain/langgraph');
2007
+ interrupt = langgraph.interrupt;
2008
+ } catch (error) {
2009
+ throw new Error(
2010
+ "askHuman tool requires @langchain/langgraph to be installed. Install it with: npm install @langchain/langgraph"
2011
+ );
2012
+ }
2013
+ if (!interrupt) {
2014
+ throw new Error(
2015
+ "interrupt function not found in @langchain/langgraph. Make sure you are using a compatible version of LangGraph."
2016
+ );
2017
+ }
2018
+ const humanRequest = {
2019
+ id: requestId,
2020
+ question: validatedInput.question,
2021
+ context: validatedInput.context,
2022
+ priority: validatedInput.priority,
2023
+ createdAt: requestedAt,
2024
+ timeout: validatedInput.timeout,
2025
+ defaultResponse: validatedInput.defaultResponse,
2026
+ suggestions: validatedInput.suggestions,
2027
+ status: "pending"
2028
+ };
2029
+ const response = interrupt(humanRequest);
2030
+ const respondedAt = Date.now();
2031
+ const duration = respondedAt - requestedAt;
2032
+ const timedOut = validatedInput.timeout > 0 && duration >= validatedInput.timeout;
2033
+ const finalResponse = timedOut && validatedInput.defaultResponse ? validatedInput.defaultResponse : response || "";
2034
+ return {
2035
+ response: finalResponse,
2036
+ metadata: {
2037
+ requestId,
2038
+ requestedAt,
2039
+ respondedAt,
2040
+ duration,
2041
+ timedOut,
2042
+ priority: validatedInput.priority
2043
+ }
2044
+ };
2045
+ }).build();
2046
+ }
2047
+ var askHumanTool = createAskHumanTool();
1970
2048
 
1971
- export { DuckDuckGoProvider, SerperProvider, arrayFilter, arrayGroupBy, arrayMap, arraySort, calculator, createDuckDuckGoProvider, createSerperProvider, creditCardValidator, csvGenerator, csvParser, csvToJson, currentDateTime, dateArithmetic, dateComparison, dateDifference, dateFormatter, directoryCreate, directoryDelete, directoryList, emailValidator, extractImages, extractLinks, fileAppend, fileDelete, fileExists, fileReader, fileSearch, fileWriter, htmlParser, httpClient, httpGet, httpPost, ipValidator, jsonMerge, jsonParser, jsonQuery, jsonStringify, jsonToCsv, jsonToXml, jsonValidator, mathFunctions, objectOmit, objectPick, pathBasename, pathDirname, pathExtension, pathJoin, pathNormalize, pathParse, pathRelative, pathResolve, phoneValidator, randomNumber, searchResultSchema, statistics, stringCaseConverter, stringJoin, stringLength, stringReplace, stringSplit, stringSubstring, stringTrim, urlBuilder, urlQueryParser, urlValidator, urlValidatorSimple, uuidValidator, webScraper, webSearch, webSearchOutputSchema, webSearchSchema, xmlGenerator, xmlParser, xmlToJson };
2049
+ export { AskHumanInputSchema, DuckDuckGoProvider, SerperProvider, arrayFilter, arrayGroupBy, arrayMap, arraySort, askHumanTool, calculator, createAskHumanTool, createDuckDuckGoProvider, createSerperProvider, creditCardValidator, csvGenerator, csvParser, csvToJson, currentDateTime, dateArithmetic, dateComparison, dateDifference, dateFormatter, directoryCreate, directoryDelete, directoryList, emailValidator, extractImages, extractLinks, fileAppend, fileDelete, fileExists, fileReader, fileSearch, fileWriter, htmlParser, httpClient, httpGet, httpPost, ipValidator, jsonMerge, jsonParser, jsonQuery, jsonStringify, jsonToCsv, jsonToXml, jsonValidator, mathFunctions, objectOmit, objectPick, pathBasename, pathDirname, pathExtension, pathJoin, pathNormalize, pathParse, pathRelative, pathResolve, phoneValidator, randomNumber, searchResultSchema, statistics, stringCaseConverter, stringJoin, stringLength, stringReplace, stringSplit, stringSubstring, stringTrim, urlBuilder, urlQueryParser, urlValidator, urlValidatorSimple, uuidValidator, webScraper, webSearch, webSearchOutputSchema, webSearchSchema, xmlGenerator, xmlParser, xmlToJson };
1972
2050
  //# sourceMappingURL=index.js.map
1973
2051
  //# sourceMappingURL=index.js.map