@agentforge/tools 0.15.12 → 0.15.14

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.js CHANGED
@@ -10011,28 +10011,60 @@ var AskHumanInputSchema = z.object({
10011
10011
  suggestions: z.array(z.string()).optional().describe("Suggested responses for the human")
10012
10012
  });
10013
10013
  var logLevel3 = process.env.LOG_LEVEL?.toLowerCase() || LogLevel.INFO;
10014
- var logger21 = createLogger("askHuman", { level: logLevel3 });
10015
- function createAskHumanTool() {
10016
- return toolBuilder().name("ask-human").description(
10017
- "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."
10018
- ).category(ToolCategory.UTILITY).schema(AskHumanInputSchema).implement(async (input) => {
10019
- const validatedInput = input;
10020
- const requestId = randomUUID();
10021
- const requestedAt = Date.now();
10022
- let interrupt;
10023
- try {
10024
- const langgraph = await import('@langchain/langgraph');
10025
- interrupt = langgraph.interrupt;
10026
- } catch (error) {
10014
+ var logger21 = createLogger("agentforge:tools:agent:ask-human", { level: logLevel3 });
10015
+ function isRecord(value) {
10016
+ return typeof value === "object" && value !== null;
10017
+ }
10018
+ function resolveInterrupt(module) {
10019
+ if (!isRecord(module)) {
10020
+ return void 0;
10021
+ }
10022
+ const candidate = module.interrupt;
10023
+ return typeof candidate === "function" ? candidate : void 0;
10024
+ }
10025
+ function isMissingLangGraphDependency(error) {
10026
+ if (!(error instanceof Error)) {
10027
+ return false;
10028
+ }
10029
+ return error.message.includes("Cannot find package '@langchain/langgraph'") || error.message.includes("Cannot find module '@langchain/langgraph'") || error.message.includes('Failed to resolve module specifier "@langchain/langgraph"');
10030
+ }
10031
+ async function loadInterrupt() {
10032
+ try {
10033
+ const interrupt = resolveInterrupt(await import('@langchain/langgraph'));
10034
+ if (!interrupt) {
10027
10035
  throw new Error(
10028
- "askHuman tool requires @langchain/langgraph to be installed. Install it with: npm install @langchain/langgraph"
10036
+ "interrupt function not found in @langchain/langgraph. Make sure you are using a compatible version of LangGraph."
10029
10037
  );
10030
10038
  }
10031
- if (!interrupt) {
10039
+ return interrupt;
10040
+ } catch (error) {
10041
+ if (isMissingLangGraphDependency(error)) {
10032
10042
  throw new Error(
10033
- "interrupt function not found in @langchain/langgraph. Make sure you are using a compatible version of LangGraph."
10043
+ "askHuman tool requires @langchain/langgraph to be installed. Install it with: npm install @langchain/langgraph"
10034
10044
  );
10035
10045
  }
10046
+ throw error;
10047
+ }
10048
+ }
10049
+ function normalizeInterruptResponse(response) {
10050
+ if (response == null) {
10051
+ return "";
10052
+ }
10053
+ if (typeof response === "string") {
10054
+ return response;
10055
+ }
10056
+ throw new Error(
10057
+ `askHuman tool expected LangGraph interrupt() to resume with a string response. Received ${typeof response}.`
10058
+ );
10059
+ }
10060
+ function createAskHumanTool() {
10061
+ return toolBuilder().name("ask-human").description(
10062
+ "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."
10063
+ ).category(ToolCategory.UTILITY).schema(AskHumanInputSchema).implement(async (input) => {
10064
+ const validatedInput = AskHumanInputSchema.parse(input);
10065
+ const requestId = randomUUID();
10066
+ const requestedAt = Date.now();
10067
+ const interrupt = await loadInterrupt();
10036
10068
  const humanRequest = {
10037
10069
  id: requestId,
10038
10070
  question: validatedInput.question,
@@ -10060,7 +10092,11 @@ function createAskHumanTool() {
10060
10092
  let response;
10061
10093
  try {
10062
10094
  response = interrupt(humanRequest);
10063
- logger21.debug("interrupt() returned successfully", { response, responseType: typeof response });
10095
+ logger21.debug("interrupt() returned successfully", {
10096
+ responseType: typeof response,
10097
+ hasResponse: response != null,
10098
+ ...typeof response === "string" ? { responseLength: response.length } : {}
10099
+ });
10064
10100
  } catch (error) {
10065
10101
  logger21.debug("interrupt() threw error (expected for GraphInterrupt)", {
10066
10102
  ...error && typeof error === "object" && "constructor" in error ? { errorType: error.constructor?.name } : {},
@@ -10071,7 +10107,7 @@ function createAskHumanTool() {
10071
10107
  const respondedAt = Date.now();
10072
10108
  const duration = respondedAt - requestedAt;
10073
10109
  const timedOut = validatedInput.timeout > 0 && duration >= validatedInput.timeout;
10074
- const finalResponse = timedOut && validatedInput.defaultResponse ? validatedInput.defaultResponse : response || "";
10110
+ const finalResponse = timedOut && validatedInput.defaultResponse !== void 0 ? validatedInput.defaultResponse : normalizeInterruptResponse(response);
10075
10111
  return {
10076
10112
  response: finalResponse,
10077
10113
  metadata: {