@agentforge/tools 0.15.12 → 0.15.13

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
@@ -10038,28 +10038,60 @@ var AskHumanInputSchema = zod.z.object({
10038
10038
  suggestions: zod.z.array(zod.z.string()).optional().describe("Suggested responses for the human")
10039
10039
  });
10040
10040
  var logLevel3 = process.env.LOG_LEVEL?.toLowerCase() || core.LogLevel.INFO;
10041
- var logger21 = core.createLogger("askHuman", { level: logLevel3 });
10042
- function createAskHumanTool() {
10043
- return core.toolBuilder().name("ask-human").description(
10044
- "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."
10045
- ).category(core.ToolCategory.UTILITY).schema(AskHumanInputSchema).implement(async (input) => {
10046
- const validatedInput = input;
10047
- const requestId = crypto.randomUUID();
10048
- const requestedAt = Date.now();
10049
- let interrupt;
10050
- try {
10051
- const langgraph = await import('@langchain/langgraph');
10052
- interrupt = langgraph.interrupt;
10053
- } catch (error) {
10041
+ var logger21 = core.createLogger("agentforge:tools:agent:ask-human", { level: logLevel3 });
10042
+ function isRecord(value) {
10043
+ return typeof value === "object" && value !== null;
10044
+ }
10045
+ function resolveInterrupt(module) {
10046
+ if (!isRecord(module)) {
10047
+ return void 0;
10048
+ }
10049
+ const candidate = module.interrupt;
10050
+ return typeof candidate === "function" ? candidate : void 0;
10051
+ }
10052
+ function isMissingLangGraphDependency(error) {
10053
+ if (!(error instanceof Error)) {
10054
+ return false;
10055
+ }
10056
+ 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"');
10057
+ }
10058
+ async function loadInterrupt() {
10059
+ try {
10060
+ const interrupt = resolveInterrupt(await import('@langchain/langgraph'));
10061
+ if (!interrupt) {
10054
10062
  throw new Error(
10055
- "askHuman tool requires @langchain/langgraph to be installed. Install it with: npm install @langchain/langgraph"
10063
+ "interrupt function not found in @langchain/langgraph. Make sure you are using a compatible version of LangGraph."
10056
10064
  );
10057
10065
  }
10058
- if (!interrupt) {
10066
+ return interrupt;
10067
+ } catch (error) {
10068
+ if (isMissingLangGraphDependency(error)) {
10059
10069
  throw new Error(
10060
- "interrupt function not found in @langchain/langgraph. Make sure you are using a compatible version of LangGraph."
10070
+ "askHuman tool requires @langchain/langgraph to be installed. Install it with: npm install @langchain/langgraph"
10061
10071
  );
10062
10072
  }
10073
+ throw error;
10074
+ }
10075
+ }
10076
+ function normalizeInterruptResponse(response) {
10077
+ if (response == null) {
10078
+ return "";
10079
+ }
10080
+ if (typeof response === "string") {
10081
+ return response;
10082
+ }
10083
+ throw new Error(
10084
+ `askHuman tool expected LangGraph interrupt() to resume with a string response. Received ${typeof response}.`
10085
+ );
10086
+ }
10087
+ function createAskHumanTool() {
10088
+ return core.toolBuilder().name("ask-human").description(
10089
+ "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."
10090
+ ).category(core.ToolCategory.UTILITY).schema(AskHumanInputSchema).implement(async (input) => {
10091
+ const validatedInput = AskHumanInputSchema.parse(input);
10092
+ const requestId = crypto.randomUUID();
10093
+ const requestedAt = Date.now();
10094
+ const interrupt = await loadInterrupt();
10063
10095
  const humanRequest = {
10064
10096
  id: requestId,
10065
10097
  question: validatedInput.question,
@@ -10087,7 +10119,11 @@ function createAskHumanTool() {
10087
10119
  let response;
10088
10120
  try {
10089
10121
  response = interrupt(humanRequest);
10090
- logger21.debug("interrupt() returned successfully", { response, responseType: typeof response });
10122
+ logger21.debug("interrupt() returned successfully", {
10123
+ responseType: typeof response,
10124
+ hasResponse: response != null,
10125
+ ...typeof response === "string" ? { responseLength: response.length } : {}
10126
+ });
10091
10127
  } catch (error) {
10092
10128
  logger21.debug("interrupt() threw error (expected for GraphInterrupt)", {
10093
10129
  ...error && typeof error === "object" && "constructor" in error ? { errorType: error.constructor?.name } : {},
@@ -10098,7 +10134,7 @@ function createAskHumanTool() {
10098
10134
  const respondedAt = Date.now();
10099
10135
  const duration = respondedAt - requestedAt;
10100
10136
  const timedOut = validatedInput.timeout > 0 && duration >= validatedInput.timeout;
10101
- const finalResponse = timedOut && validatedInput.defaultResponse ? validatedInput.defaultResponse : response || "";
10137
+ const finalResponse = timedOut && validatedInput.defaultResponse !== void 0 ? validatedInput.defaultResponse : normalizeInterruptResponse(response);
10102
10138
  return {
10103
10139
  response: finalResponse,
10104
10140
  metadata: {