@ai-sdk/harness-deepagents 1.0.68 → 1.0.70
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/CHANGELOG.md +12 -0
- package/dist/bridge/index.mjs +835 -28
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +23 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/bridge/create-emit-stream-event.ts +11 -1
- package/src/bridge/index.ts +66 -5
- package/src/deepagents-bridge-protocol.ts +15 -0
- package/src/deepagents-harness.ts +34 -0
- package/src/index.ts +4 -1
package/dist/bridge/index.mjs
CHANGED
|
@@ -467,13 +467,775 @@ function serialiseError(err) {
|
|
|
467
467
|
|
|
468
468
|
// src/bridge/index.ts
|
|
469
469
|
import { ChatAnthropic } from "@langchain/anthropic";
|
|
470
|
-
import { tool } from "@langchain/core/tools";
|
|
471
|
-
import { Command, MemorySaver } from "@langchain/langgraph";
|
|
470
|
+
import { tool as tool3 } from "@langchain/core/tools";
|
|
471
|
+
import { Command as Command5, MemorySaver as MemorySaver2 } from "@langchain/langgraph";
|
|
472
472
|
import {
|
|
473
473
|
MultiServerMCPClient
|
|
474
474
|
} from "@langchain/mcp-adapters";
|
|
475
475
|
import { createDeepAgent } from "deepagents";
|
|
476
476
|
|
|
477
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/chat_models/universal.js
|
|
478
|
+
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
479
|
+
import { RunnableBinding, ensureConfig } from "@langchain/core/runnables";
|
|
480
|
+
import { AsyncGeneratorWithSetup, IterableReadableStream } from "@langchain/core/utils/stream";
|
|
481
|
+
import { ChatModelStream } from "@langchain/core/language_models/stream";
|
|
482
|
+
var MODEL_PROVIDER_CONFIG = {
|
|
483
|
+
openai: {
|
|
484
|
+
package: "@langchain/openai",
|
|
485
|
+
className: "ChatOpenAI"
|
|
486
|
+
},
|
|
487
|
+
anthropic: {
|
|
488
|
+
package: "@langchain/anthropic",
|
|
489
|
+
className: "ChatAnthropic"
|
|
490
|
+
},
|
|
491
|
+
azure_openai: {
|
|
492
|
+
package: "@langchain/openai",
|
|
493
|
+
className: "AzureChatOpenAI"
|
|
494
|
+
},
|
|
495
|
+
cohere: {
|
|
496
|
+
package: "@langchain/cohere",
|
|
497
|
+
className: "ChatCohere"
|
|
498
|
+
},
|
|
499
|
+
google: {
|
|
500
|
+
package: "@langchain/google",
|
|
501
|
+
className: "ChatGoogle"
|
|
502
|
+
},
|
|
503
|
+
"google-vertexai": {
|
|
504
|
+
package: "@langchain/google-vertexai",
|
|
505
|
+
className: "ChatVertexAI"
|
|
506
|
+
},
|
|
507
|
+
"google-vertexai-web": {
|
|
508
|
+
package: "@langchain/google-vertexai-web",
|
|
509
|
+
className: "ChatVertexAI"
|
|
510
|
+
},
|
|
511
|
+
"google-genai": {
|
|
512
|
+
package: "@langchain/google-genai",
|
|
513
|
+
className: "ChatGoogleGenerativeAI"
|
|
514
|
+
},
|
|
515
|
+
ollama: {
|
|
516
|
+
package: "@langchain/ollama",
|
|
517
|
+
className: "ChatOllama"
|
|
518
|
+
},
|
|
519
|
+
mistralai: {
|
|
520
|
+
package: "@langchain/mistralai",
|
|
521
|
+
className: "ChatMistralAI"
|
|
522
|
+
},
|
|
523
|
+
mistral: {
|
|
524
|
+
package: "@langchain/mistralai",
|
|
525
|
+
className: "ChatMistralAI"
|
|
526
|
+
},
|
|
527
|
+
groq: {
|
|
528
|
+
package: "@langchain/groq",
|
|
529
|
+
className: "ChatGroq"
|
|
530
|
+
},
|
|
531
|
+
bedrock: {
|
|
532
|
+
package: "@langchain/aws",
|
|
533
|
+
className: "ChatBedrockConverse"
|
|
534
|
+
},
|
|
535
|
+
aws: {
|
|
536
|
+
package: "@langchain/aws",
|
|
537
|
+
className: "ChatBedrockConverse"
|
|
538
|
+
},
|
|
539
|
+
deepseek: {
|
|
540
|
+
package: "@langchain/deepseek",
|
|
541
|
+
className: "ChatDeepSeek"
|
|
542
|
+
},
|
|
543
|
+
xai: {
|
|
544
|
+
package: "@langchain/xai",
|
|
545
|
+
className: "ChatXAI"
|
|
546
|
+
},
|
|
547
|
+
cerebras: {
|
|
548
|
+
package: "@langchain/cerebras",
|
|
549
|
+
className: "ChatCerebras"
|
|
550
|
+
},
|
|
551
|
+
fireworks: {
|
|
552
|
+
package: "@langchain/fireworks",
|
|
553
|
+
className: "ChatFireworks"
|
|
554
|
+
},
|
|
555
|
+
together: {
|
|
556
|
+
package: "@langchain/together-ai",
|
|
557
|
+
className: "ChatTogetherAI",
|
|
558
|
+
hasCircularDependency: true
|
|
559
|
+
},
|
|
560
|
+
perplexity: {
|
|
561
|
+
package: "@langchain/perplexity",
|
|
562
|
+
className: "ChatPerplexity"
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
var SUPPORTED_PROVIDERS = Object.keys(MODEL_PROVIDER_CONFIG);
|
|
566
|
+
|
|
567
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/tools/headless.js
|
|
568
|
+
import { tool } from "@langchain/core/tools";
|
|
569
|
+
|
|
570
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/errors.js
|
|
571
|
+
import { isGraphBubbleUp } from "@langchain/langgraph";
|
|
572
|
+
|
|
573
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/responses.js
|
|
574
|
+
import { isInteropZodObject, isInteropZodSchema } from "@langchain/core/utils/types";
|
|
575
|
+
import { Validator, toJsonSchema } from "@langchain/core/utils/json_schema";
|
|
576
|
+
import { isSerializableSchema } from "@langchain/core/utils/standard_schema";
|
|
577
|
+
|
|
578
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/utils.js
|
|
579
|
+
import { AIMessage, ToolMessage } from "@langchain/core/messages";
|
|
580
|
+
import { isLangChainTool } from "@langchain/core/tools";
|
|
581
|
+
import { convertToOpenAITool } from "@langchain/core/utils/function_calling";
|
|
582
|
+
|
|
583
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/transformers/tool-call.js
|
|
584
|
+
import { ToolMessage as ToolMessage2 } from "@langchain/core/messages";
|
|
585
|
+
import { StreamChannel } from "@langchain/langgraph";
|
|
586
|
+
|
|
587
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/transformers/subagent.js
|
|
588
|
+
import { StreamChannel as StreamChannel2, createMessagesTransformer } from "@langchain/langgraph";
|
|
589
|
+
|
|
590
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/types.js
|
|
591
|
+
var MIDDLEWARE_BRAND = /* @__PURE__ */ Symbol.for("AgentMiddleware");
|
|
592
|
+
|
|
593
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware.js
|
|
594
|
+
function createMiddleware(config) {
|
|
595
|
+
return {
|
|
596
|
+
[MIDDLEWARE_BRAND]: true,
|
|
597
|
+
name: config.name,
|
|
598
|
+
stateSchema: config.stateSchema,
|
|
599
|
+
contextSchema: config.contextSchema,
|
|
600
|
+
wrapToolCall: config.wrapToolCall,
|
|
601
|
+
wrapModelCall: config.wrapModelCall,
|
|
602
|
+
beforeAgent: config.beforeAgent,
|
|
603
|
+
beforeModel: config.beforeModel,
|
|
604
|
+
afterModel: config.afterModel,
|
|
605
|
+
afterAgent: config.afterAgent,
|
|
606
|
+
tools: config.tools,
|
|
607
|
+
streamTransformers: config.streamTransformers
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/tests/utils.js
|
|
612
|
+
import { AIMessage as AIMessage2, HumanMessage } from "@langchain/core/messages";
|
|
613
|
+
import { BaseChatModel as BaseChatModel2 } from "@langchain/core/language_models/chat_models";
|
|
614
|
+
import { RunnableLambda } from "@langchain/core/runnables";
|
|
615
|
+
import "@langchain/core/tools";
|
|
616
|
+
|
|
617
|
+
// ../../node_modules/.pnpm/@langchain+langgraph-checkpoint@1.1.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@o_9d1ca3436e2b1590f95d73b362aab59a/node_modules/@langchain/langgraph-checkpoint/dist/id.js
|
|
618
|
+
import { v5, v6 } from "@langchain/core/utils/uuid";
|
|
619
|
+
|
|
620
|
+
// ../../node_modules/.pnpm/@langchain+langgraph-checkpoint@1.1.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@o_9d1ca3436e2b1590f95d73b362aab59a/node_modules/@langchain/langgraph-checkpoint/dist/serde/types.js
|
|
621
|
+
var ERROR = "__error__";
|
|
622
|
+
var SCHEDULED = "__scheduled__";
|
|
623
|
+
var INTERRUPT = "__interrupt__";
|
|
624
|
+
var RESUME = "__resume__";
|
|
625
|
+
|
|
626
|
+
// ../../node_modules/.pnpm/@langchain+langgraph-checkpoint@1.1.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@o_9d1ca3436e2b1590f95d73b362aab59a/node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js
|
|
627
|
+
import { load } from "@langchain/core/load";
|
|
628
|
+
|
|
629
|
+
// ../../node_modules/.pnpm/@langchain+langgraph-checkpoint@1.1.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@o_9d1ca3436e2b1590f95d73b362aab59a/node_modules/@langchain/langgraph-checkpoint/dist/base.js
|
|
630
|
+
var WRITES_IDX_MAP = {
|
|
631
|
+
[ERROR]: -1,
|
|
632
|
+
[SCHEDULED]: -2,
|
|
633
|
+
[INTERRUPT]: -3,
|
|
634
|
+
[RESUME]: -4
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/tests/utils.js
|
|
638
|
+
import "zod/v3";
|
|
639
|
+
|
|
640
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/annotation.js
|
|
641
|
+
import { MessagesValue, ReducedValue, StateSchema, UntrackedValue } from "@langchain/langgraph";
|
|
642
|
+
import { schemaMetaRegistry } from "@langchain/langgraph/zod";
|
|
643
|
+
import { getInteropZodObjectShape, isInteropZodObject as isInteropZodObject2, isZodSchemaV4 } from "@langchain/core/utils/types";
|
|
644
|
+
|
|
645
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/utils.js
|
|
646
|
+
import { AIMessage as AIMessage3, AIMessageChunk, SystemMessage, ToolMessage as ToolMessage3 } from "@langchain/core/messages";
|
|
647
|
+
import { Runnable, RunnableBinding as RunnableBinding2, RunnableSequence } from "@langchain/core/runnables";
|
|
648
|
+
import { StateSchema as StateSchema2, isCommand } from "@langchain/langgraph";
|
|
649
|
+
import { interopParse, isInteropZodSchema as isInteropZodSchema2 } from "@langchain/core/utils/types";
|
|
650
|
+
|
|
651
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/nodes/utils.js
|
|
652
|
+
import { END, ReducedValue as ReducedValue2, StateSchema as StateSchema3 } from "@langchain/langgraph";
|
|
653
|
+
import { getInteropZodObjectShape as getInteropZodObjectShape2, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, isInteropZodObject as isInteropZodObject3, isZodSchemaV4 as isZodSchemaV42 } from "@langchain/core/utils/types";
|
|
654
|
+
import { z } from "zod/v4";
|
|
655
|
+
|
|
656
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/RunnableCallable.js
|
|
657
|
+
import { Runnable as Runnable2, mergeConfigs } from "@langchain/core/runnables";
|
|
658
|
+
import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
|
|
659
|
+
|
|
660
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/withAgentName.js
|
|
661
|
+
import { RunnableLambda as RunnableLambda2, RunnableSequence as RunnableSequence2 } from "@langchain/core/runnables";
|
|
662
|
+
|
|
663
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/nodes/AgentNode.js
|
|
664
|
+
import { AIMessage as AIMessage4, SystemMessage as SystemMessage2, ToolMessage as ToolMessage4 } from "@langchain/core/messages";
|
|
665
|
+
import { raceWithSignal } from "@langchain/core/runnables";
|
|
666
|
+
import { Command, isCommand as isCommand2 } from "@langchain/langgraph";
|
|
667
|
+
import { getSchemaDescription, interopParse as interopParse2 } from "@langchain/core/utils/types";
|
|
668
|
+
|
|
669
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/nodes/ToolNode.js
|
|
670
|
+
import { AIMessage as AIMessage5, BaseMessage, ToolMessage as ToolMessage5 } from "@langchain/core/messages";
|
|
671
|
+
import { ToolInputParsingException } from "@langchain/core/tools";
|
|
672
|
+
import { Command as Command2, Send, isCommand as isCommand3, isGraphInterrupt } from "@langchain/langgraph";
|
|
673
|
+
|
|
674
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/nodes/middleware.js
|
|
675
|
+
import { getInteropZodObjectShape as getInteropZodObjectShape3, interopParse as interopParse3, isInteropZodObject as isInteropZodObject4 } from "@langchain/core/utils/types";
|
|
676
|
+
|
|
677
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/ReactAgent.js
|
|
678
|
+
import { AIMessage as AIMessage6, ToolMessage as ToolMessage6 } from "@langchain/core/messages";
|
|
679
|
+
import { mergeConfigs as mergeConfigs2 } from "@langchain/core/runnables";
|
|
680
|
+
import { Command as Command3, END as END2, START, Send as Send2, StateGraph } from "@langchain/langgraph";
|
|
681
|
+
|
|
682
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/hitl.js
|
|
683
|
+
import { AIMessage as AIMessage7, ToolMessage as ToolMessage7 } from "@langchain/core/messages";
|
|
684
|
+
import { interrupt } from "@langchain/langgraph";
|
|
685
|
+
import { interopParse as interopParse4 } from "@langchain/core/utils/types";
|
|
686
|
+
import { z as z2 } from "zod/v3";
|
|
687
|
+
var WhenFunctionSchema = z2.function().args(z2.custom()).returns(z2.union([z2.boolean(), z2.promise(z2.boolean())]));
|
|
688
|
+
var DescriptionFunctionSchema = z2.function().args(z2.custom(), z2.custom(), z2.custom()).returns(z2.union([z2.string(), z2.promise(z2.string())]));
|
|
689
|
+
var ALLOWED_DECISIONS = [
|
|
690
|
+
"approve",
|
|
691
|
+
"edit",
|
|
692
|
+
"reject"
|
|
693
|
+
];
|
|
694
|
+
var DecisionType = z2.enum(ALLOWED_DECISIONS);
|
|
695
|
+
var InterruptOnConfigSchema = z2.object({
|
|
696
|
+
/**
|
|
697
|
+
* The decisions that are allowed for this action.
|
|
698
|
+
*/
|
|
699
|
+
allowedDecisions: z2.array(DecisionType),
|
|
700
|
+
/**
|
|
701
|
+
* The description attached to the request for human input.
|
|
702
|
+
* Can be either:
|
|
703
|
+
* - A static string describing the approval request
|
|
704
|
+
* - A callable that dynamically generates the description based on agent state,
|
|
705
|
+
* runtime, and tool call information
|
|
706
|
+
*
|
|
707
|
+
* @example
|
|
708
|
+
* Static string description
|
|
709
|
+
* ```typescript
|
|
710
|
+
* import type { InterruptOnConfig } from "langchain";
|
|
711
|
+
*
|
|
712
|
+
* const config: InterruptOnConfig = {
|
|
713
|
+
* allowedDecisions: ["approve", "reject"],
|
|
714
|
+
* description: "Please review this tool execution"
|
|
715
|
+
* };
|
|
716
|
+
* ```
|
|
717
|
+
*
|
|
718
|
+
* @example
|
|
719
|
+
* Dynamic callable description
|
|
720
|
+
* ```typescript
|
|
721
|
+
* import type {
|
|
722
|
+
* AgentBuiltInState,
|
|
723
|
+
* Runtime,
|
|
724
|
+
* DescriptionFactory,
|
|
725
|
+
* ToolCall,
|
|
726
|
+
* InterruptOnConfig
|
|
727
|
+
* } from "langchain";
|
|
728
|
+
*
|
|
729
|
+
* const formatToolDescription: DescriptionFactory = (
|
|
730
|
+
* toolCall: ToolCall,
|
|
731
|
+
* state: AgentBuiltInState,
|
|
732
|
+
* runtime: Runtime<unknown>
|
|
733
|
+
* ) => {
|
|
734
|
+
* return `Tool: ${toolCall.name}\nArguments:\n${JSON.stringify(toolCall.args, null, 2)}`;
|
|
735
|
+
* };
|
|
736
|
+
*
|
|
737
|
+
* const config: InterruptOnConfig = {
|
|
738
|
+
* allowedDecisions: ["approve", "edit"],
|
|
739
|
+
* description: formatToolDescription
|
|
740
|
+
* };
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
description: z2.union([z2.string(), DescriptionFunctionSchema]).optional(),
|
|
744
|
+
/**
|
|
745
|
+
* JSON schema for the arguments associated with the action, if edits are allowed.
|
|
746
|
+
*/
|
|
747
|
+
argsSchema: z2.record(z2.any()).optional(),
|
|
748
|
+
/**
|
|
749
|
+
* Optional predicate controlling whether to interrupt for a given tool call.
|
|
750
|
+
*
|
|
751
|
+
* Receives a {@link ToolCallRequest} and returns `true` to interrupt or
|
|
752
|
+
* `false` to auto-approve the tool call.
|
|
753
|
+
*
|
|
754
|
+
* The request is constructed with `tool` set to `undefined` and `runtime` set
|
|
755
|
+
* to the node-level {@link Runtime}, so `request.tool` is not available.
|
|
756
|
+
*
|
|
757
|
+
* @example
|
|
758
|
+
* ```typescript
|
|
759
|
+
* import type { InterruptOnConfig } from "langchain";
|
|
760
|
+
*
|
|
761
|
+
* // Only interrupt delete_file calls targeting /etc
|
|
762
|
+
* const config: InterruptOnConfig = {
|
|
763
|
+
* allowedDecisions: ["approve", "reject"],
|
|
764
|
+
* when: (request) =>
|
|
765
|
+
* String(request.toolCall.args.path ?? "").startsWith("/etc"),
|
|
766
|
+
* };
|
|
767
|
+
* ```
|
|
768
|
+
*/
|
|
769
|
+
when: WhenFunctionSchema.optional()
|
|
770
|
+
});
|
|
771
|
+
var contextSchema = z2.object({
|
|
772
|
+
/**
|
|
773
|
+
* Mapping of tool name to allowed reviewer responses.
|
|
774
|
+
* If a tool doesn't have an entry, it's auto-approved by default.
|
|
775
|
+
*
|
|
776
|
+
* - `true` -> pause for approval and allow approve/edit/reject decisions
|
|
777
|
+
* - `false` -> auto-approve (no human review)
|
|
778
|
+
* - `InterruptOnConfig` -> explicitly specify which decisions are allowed for this tool
|
|
779
|
+
*/
|
|
780
|
+
interruptOn: z2.record(z2.union([z2.boolean(), InterruptOnConfigSchema])).optional(),
|
|
781
|
+
/**
|
|
782
|
+
* Prefix used when constructing human-facing approval messages.
|
|
783
|
+
* Provides context about the tool call being reviewed; does not change the underlying action.
|
|
784
|
+
*
|
|
785
|
+
* Note: This prefix is only applied for tools that do not provide a custom
|
|
786
|
+
* `description` via their {@link InterruptOnConfig}. If a tool specifies a custom
|
|
787
|
+
* `description`, that per-tool text is used and this prefix is ignored.
|
|
788
|
+
*/
|
|
789
|
+
descriptionPrefix: z2.string().default("Tool execution requires approval")
|
|
790
|
+
});
|
|
791
|
+
|
|
792
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/summarization.js
|
|
793
|
+
import { AIMessage as AIMessage8, HumanMessage as HumanMessage2, RemoveMessage, SystemMessage as SystemMessage3, ToolMessage as ToolMessage8, getBufferString, trimMessages } from "@langchain/core/messages";
|
|
794
|
+
import { mergeConfigs as mergeConfigs3, pickRunnableConfigKeys } from "@langchain/core/runnables";
|
|
795
|
+
import { REMOVE_ALL_MESSAGES } from "@langchain/langgraph";
|
|
796
|
+
import { interopSafeParse } from "@langchain/core/utils/types";
|
|
797
|
+
import { z as z3 } from "zod/v4";
|
|
798
|
+
import { z as z$1 } from "zod/v3";
|
|
799
|
+
import { v4 } from "@langchain/core/utils/uuid";
|
|
800
|
+
import { getModelContextSize } from "@langchain/core/language_models/base";
|
|
801
|
+
var DEFAULT_SUMMARY_PROMPT = `<role>
|
|
802
|
+
Context Extraction Assistant
|
|
803
|
+
</role>
|
|
804
|
+
|
|
805
|
+
<primary_objective>
|
|
806
|
+
Your sole objective in this task is to extract the highest quality/most relevant context from the conversation history below.
|
|
807
|
+
</primary_objective>
|
|
808
|
+
|
|
809
|
+
<objective_information>
|
|
810
|
+
You're nearing the total number of input tokens you can accept, so you must extract the highest quality/most relevant pieces of information from your conversation history.
|
|
811
|
+
This context will then overwrite the conversation history presented below. Because of this, ensure the context you extract is only the most important information to your overall goal.
|
|
812
|
+
</objective_information>
|
|
813
|
+
|
|
814
|
+
<instructions>
|
|
815
|
+
The conversation history below will be replaced with the context you extract in this step. Because of this, you must do your very best to extract and record all of the most important context from the conversation history.
|
|
816
|
+
You want to ensure that you don't repeat any actions you've already completed, so the context you extract from the conversation history should be focused on the most important information to your overall goal.
|
|
817
|
+
</instructions>
|
|
818
|
+
|
|
819
|
+
The user will message you with the full message history you'll be extracting context from, to then replace. Carefully read over it all, and think deeply about what information is most important to your overall goal that should be saved:
|
|
820
|
+
|
|
821
|
+
With all of this in mind, please carefully read over the entire conversation history, and extract the most important and relevant context to replace it so that you can free up space in the conversation history.
|
|
822
|
+
Respond ONLY with the extracted context. Do not include any additional information, or text before or after the extracted context.
|
|
823
|
+
|
|
824
|
+
<messages>
|
|
825
|
+
Messages to summarize:
|
|
826
|
+
{messages}
|
|
827
|
+
</messages>`;
|
|
828
|
+
var tokenCounterSchema = z$1.function().args(z$1.array(z$1.custom())).returns(z$1.union([z$1.number(), z$1.promise(z$1.number())]));
|
|
829
|
+
var contextSizeSchema = z$1.object({
|
|
830
|
+
/**
|
|
831
|
+
* Fraction of the model's context size to use as the trigger
|
|
832
|
+
*/
|
|
833
|
+
fraction: z$1.number().gt(0, "Fraction must be greater than 0").max(1, "Fraction must be less than or equal to 1").optional(),
|
|
834
|
+
/**
|
|
835
|
+
* Number of tokens to use as the trigger
|
|
836
|
+
*/
|
|
837
|
+
tokens: z$1.number().positive("Tokens must be greater than 0").optional(),
|
|
838
|
+
/**
|
|
839
|
+
* Number of messages to use as the trigger
|
|
840
|
+
*/
|
|
841
|
+
messages: z$1.number().int("Messages must be an integer").positive("Messages must be greater than 0").optional()
|
|
842
|
+
}).refine((data) => {
|
|
843
|
+
return [
|
|
844
|
+
data.fraction,
|
|
845
|
+
data.tokens,
|
|
846
|
+
data.messages
|
|
847
|
+
].filter((v) => v !== void 0).length >= 1;
|
|
848
|
+
}, { message: "At least one of fraction, tokens, or messages must be provided" });
|
|
849
|
+
var keepSchema = z$1.object({
|
|
850
|
+
/**
|
|
851
|
+
* Fraction of the model's context size to keep
|
|
852
|
+
*/
|
|
853
|
+
fraction: z$1.number().min(0, "Messages must be non-negative").max(1, "Fraction must be less than or equal to 1").optional(),
|
|
854
|
+
/**
|
|
855
|
+
* Number of tokens to keep
|
|
856
|
+
*/
|
|
857
|
+
tokens: z$1.number().min(0, "Tokens must be greater than or equal to 0").optional(),
|
|
858
|
+
messages: z$1.number().int("Messages must be an integer").min(0, "Messages must be non-negative").optional()
|
|
859
|
+
}).refine((data) => {
|
|
860
|
+
return [
|
|
861
|
+
data.fraction,
|
|
862
|
+
data.tokens,
|
|
863
|
+
data.messages
|
|
864
|
+
].filter((v) => v !== void 0).length === 1;
|
|
865
|
+
}, { message: "Exactly one of fraction, tokens, or messages must be provided" });
|
|
866
|
+
var contextSchema2 = z$1.object({
|
|
867
|
+
/**
|
|
868
|
+
* Model to use for summarization
|
|
869
|
+
*/
|
|
870
|
+
model: z$1.custom(),
|
|
871
|
+
/**
|
|
872
|
+
* Trigger conditions for summarization.
|
|
873
|
+
* Can be a single condition object (all properties must be met) or an array of conditions (any condition must be met).
|
|
874
|
+
*
|
|
875
|
+
* @example
|
|
876
|
+
* ```ts
|
|
877
|
+
* // Single condition: trigger if tokens >= 5000 AND messages >= 3
|
|
878
|
+
* trigger: { tokens: 5000, messages: 3 }
|
|
879
|
+
*
|
|
880
|
+
* // Multiple conditions: trigger if (tokens >= 5000 AND messages >= 3) OR (tokens >= 3000 AND messages >= 6)
|
|
881
|
+
* trigger: [
|
|
882
|
+
* { tokens: 5000, messages: 3 },
|
|
883
|
+
* { tokens: 3000, messages: 6 }
|
|
884
|
+
* ]
|
|
885
|
+
* ```
|
|
886
|
+
*/
|
|
887
|
+
trigger: z$1.union([contextSizeSchema, z$1.array(contextSizeSchema)]).optional(),
|
|
888
|
+
/**
|
|
889
|
+
* Keep conditions for summarization
|
|
890
|
+
*/
|
|
891
|
+
keep: keepSchema.optional(),
|
|
892
|
+
/**
|
|
893
|
+
* Token counter function to use for summarization
|
|
894
|
+
*/
|
|
895
|
+
tokenCounter: tokenCounterSchema.optional(),
|
|
896
|
+
/**
|
|
897
|
+
* Summary prompt to use for summarization
|
|
898
|
+
* @default {@link DEFAULT_SUMMARY_PROMPT}
|
|
899
|
+
*/
|
|
900
|
+
summaryPrompt: z$1.string().default(DEFAULT_SUMMARY_PROMPT),
|
|
901
|
+
/**
|
|
902
|
+
* Number of tokens to trim to before summarizing
|
|
903
|
+
*/
|
|
904
|
+
trimTokensToSummarize: z$1.number().optional(),
|
|
905
|
+
/**
|
|
906
|
+
* Prefix to add to the summary
|
|
907
|
+
*/
|
|
908
|
+
summaryPrefix: z$1.string().optional(),
|
|
909
|
+
/**
|
|
910
|
+
* @deprecated Use `trigger: { tokens: value }` instead.
|
|
911
|
+
*/
|
|
912
|
+
maxTokensBeforeSummary: z$1.number().optional(),
|
|
913
|
+
/**
|
|
914
|
+
* @deprecated Use `keep: { messages: value }` instead.
|
|
915
|
+
*/
|
|
916
|
+
messagesToKeep: z$1.number().optional()
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/dynamicSystemPrompt.js
|
|
920
|
+
import { SystemMessage as SystemMessage4 } from "@langchain/core/messages";
|
|
921
|
+
|
|
922
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/llmToolSelector.js
|
|
923
|
+
import { HumanMessage as HumanMessage3 } from "@langchain/core/messages";
|
|
924
|
+
import { mergeConfigs as mergeConfigs4, pickRunnableConfigKeys as pickRunnableConfigKeys2 } from "@langchain/core/runnables";
|
|
925
|
+
import { z as z4 } from "zod/v3";
|
|
926
|
+
import { BaseLanguageModel } from "@langchain/core/language_models/base";
|
|
927
|
+
var LLMToolSelectorOptionsSchema = z4.object({
|
|
928
|
+
/**
|
|
929
|
+
* The language model to use for tool selection (default: the provided model from the agent options).
|
|
930
|
+
*/
|
|
931
|
+
model: z4.string().or(z4.instanceof(BaseLanguageModel)).optional(),
|
|
932
|
+
/**
|
|
933
|
+
* System prompt for the tool selection model.
|
|
934
|
+
*/
|
|
935
|
+
systemPrompt: z4.string().optional(),
|
|
936
|
+
/**
|
|
937
|
+
* Maximum number of tools to select. If the model selects more,
|
|
938
|
+
* only the first maxTools will be used. No limit if not specified.
|
|
939
|
+
*/
|
|
940
|
+
maxTools: z4.number().optional(),
|
|
941
|
+
/**
|
|
942
|
+
* Tool names to always include regardless of selection.
|
|
943
|
+
* These do not count against the maxTools limit.
|
|
944
|
+
*/
|
|
945
|
+
alwaysInclude: z4.array(z4.string()).optional()
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/pii.js
|
|
949
|
+
import { AIMessage as AIMessage9, HumanMessage as HumanMessage4, ToolMessage as ToolMessage9 } from "@langchain/core/messages";
|
|
950
|
+
import { z as z5 } from "zod/v3";
|
|
951
|
+
import { sha256 } from "@langchain/core/utils/hash";
|
|
952
|
+
var contextSchema3 = z5.object({
|
|
953
|
+
/**
|
|
954
|
+
* Whether to check user messages before model call
|
|
955
|
+
*/
|
|
956
|
+
applyToInput: z5.boolean().optional(),
|
|
957
|
+
/**
|
|
958
|
+
* Whether to check AI messages after model call
|
|
959
|
+
*/
|
|
960
|
+
applyToOutput: z5.boolean().optional(),
|
|
961
|
+
/**
|
|
962
|
+
* Whether to check tool result messages after tool execution
|
|
963
|
+
*/
|
|
964
|
+
applyToToolResults: z5.boolean().optional()
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/piiRedaction.js
|
|
968
|
+
import { AIMessage as AIMessage10, HumanMessage as HumanMessage5, RemoveMessage as RemoveMessage2, SystemMessage as SystemMessage5, ToolMessage as ToolMessage10 } from "@langchain/core/messages";
|
|
969
|
+
import { z as z6 } from "zod/v3";
|
|
970
|
+
var contextSchema4 = z6.object({
|
|
971
|
+
/**
|
|
972
|
+
* A record of PII detection rules to apply
|
|
973
|
+
* @default DEFAULT_PII_RULES (with enabled rules only)
|
|
974
|
+
*/
|
|
975
|
+
rules: z6.record(z6.string(), z6.instanceof(RegExp).describe("Regular expression pattern to match PII")).optional()
|
|
976
|
+
});
|
|
977
|
+
|
|
978
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/contextEditing.js
|
|
979
|
+
import { AIMessage as AIMessage11, SystemMessage as SystemMessage6, ToolMessage as ToolMessage11 } from "@langchain/core/messages";
|
|
980
|
+
|
|
981
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/toolCallLimit.js
|
|
982
|
+
import { AIMessage as AIMessage12, ToolMessage as ToolMessage12 } from "@langchain/core/messages";
|
|
983
|
+
import { z as z7 } from "zod/v4";
|
|
984
|
+
import { z as z$12 } from "zod/v3";
|
|
985
|
+
var VALID_EXIT_BEHAVIORS = [
|
|
986
|
+
"continue",
|
|
987
|
+
"error",
|
|
988
|
+
"end"
|
|
989
|
+
];
|
|
990
|
+
var DEFAULT_EXIT_BEHAVIOR = "continue";
|
|
991
|
+
var exitBehaviorSchema = z$12.enum(VALID_EXIT_BEHAVIORS).default(DEFAULT_EXIT_BEHAVIOR);
|
|
992
|
+
z$12.object({
|
|
993
|
+
/**
|
|
994
|
+
* Name of the specific tool to limit. If undefined, limits apply to all tools.
|
|
995
|
+
*/
|
|
996
|
+
toolName: z$12.string().optional(),
|
|
997
|
+
/**
|
|
998
|
+
* Maximum number of tool calls allowed per thread.
|
|
999
|
+
* undefined means no limit.
|
|
1000
|
+
*/
|
|
1001
|
+
threadLimit: z$12.number().optional(),
|
|
1002
|
+
/**
|
|
1003
|
+
* Maximum number of tool calls allowed per run.
|
|
1004
|
+
* undefined means no limit.
|
|
1005
|
+
*/
|
|
1006
|
+
runLimit: z$12.number().optional(),
|
|
1007
|
+
/**
|
|
1008
|
+
* What to do when limits are exceeded.
|
|
1009
|
+
* - "continue": Block exceeded tools with error messages, let other tools continue (default)
|
|
1010
|
+
* - "error": Raise a ToolCallLimitExceededError exception
|
|
1011
|
+
* - "end": Stop execution immediately, injecting a ToolMessage and an AI message
|
|
1012
|
+
* for the single tool call that exceeded the limit. Raises NotImplementedError
|
|
1013
|
+
* if there are multiple tool calls.
|
|
1014
|
+
*
|
|
1015
|
+
* @default "continue"
|
|
1016
|
+
*/
|
|
1017
|
+
exitBehavior: exitBehaviorSchema
|
|
1018
|
+
});
|
|
1019
|
+
var stateSchema = z$12.object({
|
|
1020
|
+
threadToolCallCount: z$12.record(z$12.string(), z$12.number()).default({}),
|
|
1021
|
+
runToolCallCount: z$12.record(z$12.string(), z$12.number()).default({})
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/todoListMiddleware.js
|
|
1025
|
+
import { AIMessage as AIMessage13, ToolMessage as ToolMessage13 } from "@langchain/core/messages";
|
|
1026
|
+
import { tool as tool2 } from "@langchain/core/tools";
|
|
1027
|
+
import { Command as Command4 } from "@langchain/langgraph";
|
|
1028
|
+
import { z as z8 } from "zod/v3";
|
|
1029
|
+
var TodoStatus = z8.enum([
|
|
1030
|
+
"pending",
|
|
1031
|
+
"in_progress",
|
|
1032
|
+
"completed"
|
|
1033
|
+
]).describe("Status of the todo");
|
|
1034
|
+
var TodoSchema = z8.object({
|
|
1035
|
+
content: z8.string().describe("Content of the todo item"),
|
|
1036
|
+
status: TodoStatus
|
|
1037
|
+
});
|
|
1038
|
+
var stateSchema2 = z8.object({ todos: z8.array(TodoSchema).default([]) });
|
|
1039
|
+
|
|
1040
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/modelCallLimit.js
|
|
1041
|
+
import { AIMessage as AIMessage14 } from "@langchain/core/messages";
|
|
1042
|
+
import { z as z9 } from "zod/v3";
|
|
1043
|
+
var contextSchema5 = z9.object({
|
|
1044
|
+
/**
|
|
1045
|
+
* The maximum number of model calls allowed per thread.
|
|
1046
|
+
*/
|
|
1047
|
+
threadLimit: z9.number().optional(),
|
|
1048
|
+
/**
|
|
1049
|
+
* The maximum number of model calls allowed per run.
|
|
1050
|
+
*/
|
|
1051
|
+
runLimit: z9.number().optional(),
|
|
1052
|
+
/**
|
|
1053
|
+
* The behavior to take when the limit is exceeded.
|
|
1054
|
+
* - "error" will throw an error and stop the agent.
|
|
1055
|
+
* - "end" will end the agent.
|
|
1056
|
+
* @default "end"
|
|
1057
|
+
*/
|
|
1058
|
+
exitBehavior: z9.enum(["error", "end"]).optional()
|
|
1059
|
+
});
|
|
1060
|
+
var stateSchema3 = z9.object({
|
|
1061
|
+
threadModelCallCount: z9.number().default(0),
|
|
1062
|
+
runModelCallCount: z9.number().default(0)
|
|
1063
|
+
});
|
|
1064
|
+
|
|
1065
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/constants.js
|
|
1066
|
+
import { z as z10 } from "zod/v3";
|
|
1067
|
+
var RetrySchema = z10.object({
|
|
1068
|
+
/**
|
|
1069
|
+
* Maximum number of retry attempts after the initial call.
|
|
1070
|
+
* Default is 2 retries (3 total attempts). Must be >= 0.
|
|
1071
|
+
*/
|
|
1072
|
+
maxRetries: z10.number().min(0).default(2),
|
|
1073
|
+
/**
|
|
1074
|
+
* Either an array of error constructors to retry on, or a function
|
|
1075
|
+
* that takes an error and returns `true` if it should be retried.
|
|
1076
|
+
* Default is to retry on all errors.
|
|
1077
|
+
*/
|
|
1078
|
+
retryOn: z10.union([z10.function().args(z10.instanceof(Error)).returns(z10.boolean()), z10.array(z10.custom())]).default(() => () => true),
|
|
1079
|
+
/**
|
|
1080
|
+
* Multiplier for exponential backoff. Each retry waits
|
|
1081
|
+
* `initialDelayMs * (backoffFactor ** retryNumber)` milliseconds.
|
|
1082
|
+
* Set to 0.0 for constant delay. Default is 2.0.
|
|
1083
|
+
*/
|
|
1084
|
+
backoffFactor: z10.number().min(0).default(2),
|
|
1085
|
+
/**
|
|
1086
|
+
* Initial delay in milliseconds before first retry. Default is 1000 (1 second).
|
|
1087
|
+
*/
|
|
1088
|
+
initialDelayMs: z10.number().min(0).default(1e3),
|
|
1089
|
+
/**
|
|
1090
|
+
* Maximum delay in milliseconds between retries. Caps exponential
|
|
1091
|
+
* backoff growth. Default is 60000 (60 seconds).
|
|
1092
|
+
*/
|
|
1093
|
+
maxDelayMs: z10.number().min(0).default(6e4),
|
|
1094
|
+
/**
|
|
1095
|
+
* Whether to add random jitter (±25%) to delay to avoid thundering herd.
|
|
1096
|
+
* Default is `true`.
|
|
1097
|
+
*/
|
|
1098
|
+
jitter: z10.boolean().default(true)
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1101
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/error.js
|
|
1102
|
+
import { z as z11 } from "zod/v4";
|
|
1103
|
+
|
|
1104
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/modelRetry.js
|
|
1105
|
+
import { AIMessage as AIMessage15 } from "@langchain/core/messages";
|
|
1106
|
+
import { z as z12 } from "zod/v3";
|
|
1107
|
+
var ModelRetryMiddlewareOptionsSchema = z12.object({
|
|
1108
|
+
/**
|
|
1109
|
+
* Behavior when all retries are exhausted. Options:
|
|
1110
|
+
* - `"continue"` (default): Return an AIMessage with error details, allowing
|
|
1111
|
+
* the agent to potentially handle the failure gracefully.
|
|
1112
|
+
* - `"error"`: Re-raise the exception, stopping agent execution.
|
|
1113
|
+
* - Custom function: Function that takes the exception and returns a string
|
|
1114
|
+
* for the AIMessage content, allowing custom error formatting.
|
|
1115
|
+
*/
|
|
1116
|
+
onFailure: z12.union([
|
|
1117
|
+
z12.literal("error"),
|
|
1118
|
+
z12.literal("continue"),
|
|
1119
|
+
z12.function().args(z12.instanceof(Error)).returns(z12.string())
|
|
1120
|
+
]).default("continue")
|
|
1121
|
+
}).merge(RetrySchema);
|
|
1122
|
+
|
|
1123
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/toolRetry.js
|
|
1124
|
+
import { ToolMessage as ToolMessage14 } from "@langchain/core/messages";
|
|
1125
|
+
import { z as z13 } from "zod/v3";
|
|
1126
|
+
var ToolRetryMiddlewareOptionsSchema = z13.object({
|
|
1127
|
+
/**
|
|
1128
|
+
* Optional list of tools or tool names to apply retry logic to.
|
|
1129
|
+
* Can be a list of `BaseTool` instances or tool name strings.
|
|
1130
|
+
* If `undefined`, applies to all tools. Default is `undefined`.
|
|
1131
|
+
*/
|
|
1132
|
+
tools: z13.array(z13.union([
|
|
1133
|
+
z13.custom(),
|
|
1134
|
+
z13.custom(),
|
|
1135
|
+
z13.string()
|
|
1136
|
+
])).optional(),
|
|
1137
|
+
/**
|
|
1138
|
+
* Behavior when all retries are exhausted. Options:
|
|
1139
|
+
* - `"continue"` (default): Return an AIMessage with error details, allowing
|
|
1140
|
+
* the agent to potentially handle the failure gracefully.
|
|
1141
|
+
* - `"error"`: Re-raise the exception, stopping agent execution.
|
|
1142
|
+
* - Custom function: Function that takes the exception and returns a string
|
|
1143
|
+
* for the AIMessage content, allowing custom error formatting.
|
|
1144
|
+
*
|
|
1145
|
+
* Deprecated values:
|
|
1146
|
+
* - `"raise"`: use `"error"` instead.
|
|
1147
|
+
* - `"return_message"`: use `"continue"` instead.
|
|
1148
|
+
*/
|
|
1149
|
+
onFailure: z13.union([
|
|
1150
|
+
z13.literal("error"),
|
|
1151
|
+
z13.literal("continue"),
|
|
1152
|
+
z13.literal("raise"),
|
|
1153
|
+
z13.literal("return_message"),
|
|
1154
|
+
z13.function().args(z13.instanceof(Error)).returns(z13.string())
|
|
1155
|
+
]).default("continue")
|
|
1156
|
+
}).merge(RetrySchema);
|
|
1157
|
+
|
|
1158
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/toolEmulator.js
|
|
1159
|
+
import { HumanMessage as HumanMessage6, ToolMessage as ToolMessage15 } from "@langchain/core/messages";
|
|
1160
|
+
|
|
1161
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/providerToolSearch.js
|
|
1162
|
+
import { isLangChainTool as isLangChainTool2 } from "@langchain/core/utils/function_calling";
|
|
1163
|
+
|
|
1164
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/provider/openai/moderation.js
|
|
1165
|
+
import { AIMessage as AIMessage16, HumanMessage as HumanMessage7, ToolMessage as ToolMessage16 } from "@langchain/core/messages";
|
|
1166
|
+
|
|
1167
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/provider/anthropic/promptCaching.js
|
|
1168
|
+
import { z as z14 } from "zod/v3";
|
|
1169
|
+
var contextSchema6 = z14.object({
|
|
1170
|
+
/**
|
|
1171
|
+
* Whether to enable prompt caching.
|
|
1172
|
+
* @default true
|
|
1173
|
+
*/
|
|
1174
|
+
enableCaching: z14.boolean().optional(),
|
|
1175
|
+
/**
|
|
1176
|
+
* The time-to-live for the cached prompt.
|
|
1177
|
+
* @default "5m"
|
|
1178
|
+
*/
|
|
1179
|
+
ttl: z14.enum(["5m", "1h"]).optional(),
|
|
1180
|
+
/**
|
|
1181
|
+
* The minimum number of messages required before caching is applied.
|
|
1182
|
+
* @default 3
|
|
1183
|
+
*/
|
|
1184
|
+
minMessagesToCache: z14.number().optional(),
|
|
1185
|
+
/**
|
|
1186
|
+
* The behavior to take when an unsupported model is used.
|
|
1187
|
+
* - "ignore" will ignore the unsupported model and continue without caching.
|
|
1188
|
+
* - "warn" will warn the user and continue without caching.
|
|
1189
|
+
* - "raise" will raise an error and stop the agent.
|
|
1190
|
+
* @default "warn"
|
|
1191
|
+
*/
|
|
1192
|
+
unsupportedModelBehavior: z14.enum([
|
|
1193
|
+
"ignore",
|
|
1194
|
+
"warn",
|
|
1195
|
+
"raise"
|
|
1196
|
+
]).optional()
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/agents/middleware/provider/aws/promptCaching.js
|
|
1200
|
+
import { z as z15 } from "zod/v3";
|
|
1201
|
+
var contextSchema7 = z15.object({
|
|
1202
|
+
/**
|
|
1203
|
+
* Whether to enable prompt caching.
|
|
1204
|
+
* @default true
|
|
1205
|
+
*/
|
|
1206
|
+
enableCaching: z15.boolean().optional(),
|
|
1207
|
+
/**
|
|
1208
|
+
* The time-to-live for the cached prompt.
|
|
1209
|
+
* @default "5m"
|
|
1210
|
+
*/
|
|
1211
|
+
ttl: z15.enum(["5m", "1h"]).optional(),
|
|
1212
|
+
/**
|
|
1213
|
+
* The minimum number of messages required before caching is applied.
|
|
1214
|
+
* @default 1
|
|
1215
|
+
*/
|
|
1216
|
+
minMessagesToCache: z15.number().optional(),
|
|
1217
|
+
/**
|
|
1218
|
+
* The behavior to take when an unsupported model is used.
|
|
1219
|
+
* - "ignore" will ignore the unsupported model and continue without caching.
|
|
1220
|
+
* - "warn" will warn the user and continue without caching.
|
|
1221
|
+
* - "raise" will raise an error and stop the agent.
|
|
1222
|
+
* @default "warn"
|
|
1223
|
+
*/
|
|
1224
|
+
unsupportedModelBehavior: z15.enum([
|
|
1225
|
+
"ignore",
|
|
1226
|
+
"warn",
|
|
1227
|
+
"raise"
|
|
1228
|
+
]).optional()
|
|
1229
|
+
});
|
|
1230
|
+
|
|
1231
|
+
// ../../node_modules/.pnpm/langchain@1.5.3_@langchain+core@1.2.3_@opentelemetry+api@1.9.1_@opentelemetry+exporter-_011198cadd42343990cf27f9dea0e154/node_modules/langchain/dist/index.js
|
|
1232
|
+
import { AIMessage as AIMessage17, AIMessageChunk as AIMessageChunk2, BaseMessage as BaseMessage2, BaseMessageChunk, HumanMessage as HumanMessage8, HumanMessageChunk, SystemMessage as SystemMessage7, SystemMessageChunk, ToolMessage as ToolMessage17, ToolMessageChunk, filterMessages, trimMessages as trimMessages2 } from "@langchain/core/messages";
|
|
1233
|
+
import { DynamicStructuredTool, DynamicTool, StructuredTool, Tool } from "@langchain/core/tools";
|
|
1234
|
+
import { context } from "@langchain/core/utils/context";
|
|
1235
|
+
import { InMemoryStore as InMemoryStore2 } from "@langchain/core/stores";
|
|
1236
|
+
import { Document } from "@langchain/core/documents";
|
|
1237
|
+
import { fakeModel, langchainMatchers } from "@langchain/core/testing";
|
|
1238
|
+
|
|
477
1239
|
// src/bridge/approvals.ts
|
|
478
1240
|
var NATIVE_TOOL_KIND = {
|
|
479
1241
|
read_file: "readonly",
|
|
@@ -519,8 +1281,8 @@ function buildInterruptOn(permissionMode, builtinToolFiltering) {
|
|
|
519
1281
|
}
|
|
520
1282
|
function collectActionRequests(interrupts) {
|
|
521
1283
|
const out = [];
|
|
522
|
-
for (const
|
|
523
|
-
const value =
|
|
1284
|
+
for (const interrupt2 of interrupts) {
|
|
1285
|
+
const value = interrupt2.value;
|
|
524
1286
|
for (const action of value?.actionRequests ?? []) {
|
|
525
1287
|
out.push({ name: action.name, args: action.args ?? {} });
|
|
526
1288
|
}
|
|
@@ -592,10 +1354,12 @@ function createEmitStreamEvent({
|
|
|
592
1354
|
for (const block of content) {
|
|
593
1355
|
if (block && typeof block === "object") {
|
|
594
1356
|
const value = block;
|
|
595
|
-
if (value.type === "text" && value.text) {
|
|
1357
|
+
if ((value.type === "text" || value.type === "text-delta") && value.text) {
|
|
596
1358
|
emitText({ state, emit, delta: value.text });
|
|
597
1359
|
} else if (value.type === "thinking" && value.thinking) {
|
|
598
1360
|
emitReasoning({ state, emit, delta: value.thinking });
|
|
1361
|
+
} else if ((value.type === "reasoning" || value.type === "reasoning-delta") && value.reasoning) {
|
|
1362
|
+
emitReasoning({ state, emit, delta: value.reasoning });
|
|
599
1363
|
}
|
|
600
1364
|
}
|
|
601
1365
|
}
|
|
@@ -752,10 +1516,10 @@ function toToolCallInput(raw) {
|
|
|
752
1516
|
}
|
|
753
1517
|
|
|
754
1518
|
// src/bridge/json-schema-to-zod.ts
|
|
755
|
-
import { z } from "zod/v4";
|
|
1519
|
+
import { z as z16 } from "zod/v4";
|
|
756
1520
|
function jsonSchemaToZodObject(input) {
|
|
757
1521
|
const schema = input && typeof input === "object" ? input : {};
|
|
758
|
-
return
|
|
1522
|
+
return z16.object(toZodShape(schema));
|
|
759
1523
|
}
|
|
760
1524
|
function toZodShape(schema) {
|
|
761
1525
|
if (!schema.properties) return {};
|
|
@@ -768,33 +1532,33 @@ function toZodShape(schema) {
|
|
|
768
1532
|
return shape;
|
|
769
1533
|
}
|
|
770
1534
|
function toZodType(schema) {
|
|
771
|
-
if (!schema) return
|
|
1535
|
+
if (!schema) return z16.any();
|
|
772
1536
|
const types = Array.isArray(schema.type) ? schema.type.filter((t) => t !== "null") : [schema.type].filter(Boolean);
|
|
773
1537
|
let zType;
|
|
774
1538
|
switch (types[0]) {
|
|
775
1539
|
case "string":
|
|
776
|
-
zType =
|
|
1540
|
+
zType = z16.string();
|
|
777
1541
|
break;
|
|
778
1542
|
case "number":
|
|
779
|
-
zType =
|
|
1543
|
+
zType = z16.number();
|
|
780
1544
|
break;
|
|
781
1545
|
case "integer":
|
|
782
|
-
zType =
|
|
1546
|
+
zType = z16.number().int();
|
|
783
1547
|
break;
|
|
784
1548
|
case "boolean":
|
|
785
|
-
zType =
|
|
1549
|
+
zType = z16.boolean();
|
|
786
1550
|
break;
|
|
787
1551
|
case "array":
|
|
788
|
-
zType =
|
|
1552
|
+
zType = z16.array(toZodType(schema.items));
|
|
789
1553
|
break;
|
|
790
1554
|
case "object":
|
|
791
|
-
zType =
|
|
1555
|
+
zType = z16.object(toZodShape(schema));
|
|
792
1556
|
break;
|
|
793
1557
|
case "null":
|
|
794
|
-
zType =
|
|
1558
|
+
zType = z16.null();
|
|
795
1559
|
break;
|
|
796
1560
|
default:
|
|
797
|
-
zType =
|
|
1561
|
+
zType = z16.any();
|
|
798
1562
|
}
|
|
799
1563
|
if (schema.description) zType = zType.describe(schema.description);
|
|
800
1564
|
if (schema.nullable) zType = zType.nullable();
|
|
@@ -818,10 +1582,10 @@ function createLocalShellBackend({
|
|
|
818
1582
|
|
|
819
1583
|
// src/bridge/tool-filtering.ts
|
|
820
1584
|
import {
|
|
821
|
-
AIMessage,
|
|
822
|
-
ToolMessage
|
|
1585
|
+
AIMessage as AIMessage18,
|
|
1586
|
+
ToolMessage as ToolMessage18
|
|
823
1587
|
} from "@langchain/core/messages";
|
|
824
|
-
var
|
|
1588
|
+
var MIDDLEWARE_BRAND2 = /* @__PURE__ */ Symbol.for("AgentMiddleware");
|
|
825
1589
|
function getBuiltinToolFilteringDenialReason(input) {
|
|
826
1590
|
return `Tool '${input.toolName}' is inactive due to the HarnessAgent tool filtering policy.`;
|
|
827
1591
|
}
|
|
@@ -840,12 +1604,12 @@ function isInactiveBuiltinToolCall(input) {
|
|
|
840
1604
|
function createBuiltinToolFilteringMiddleware(input) {
|
|
841
1605
|
if (input.builtinToolFiltering == null) return void 0;
|
|
842
1606
|
return {
|
|
843
|
-
[
|
|
1607
|
+
[MIDDLEWARE_BRAND2]: true,
|
|
844
1608
|
name: "HarnessBuiltinToolFilteringMiddleware",
|
|
845
1609
|
afterModel: {
|
|
846
1610
|
canJumpTo: ["model"],
|
|
847
1611
|
hook: (state) => {
|
|
848
|
-
const lastMessage = [...state.messages].reverse().find((message) =>
|
|
1612
|
+
const lastMessage = [...state.messages].reverse().find((message) => AIMessage18.isInstance(message));
|
|
849
1613
|
if (!lastMessage?.tool_calls?.length) return void 0;
|
|
850
1614
|
let hasActiveToolCalls = false;
|
|
851
1615
|
const deniedToolMessages = [];
|
|
@@ -876,7 +1640,7 @@ function createBuiltinToolFilteringMiddleware(input) {
|
|
|
876
1640
|
result: reason
|
|
877
1641
|
});
|
|
878
1642
|
deniedToolMessages.push(
|
|
879
|
-
new
|
|
1643
|
+
new ToolMessage18({
|
|
880
1644
|
content: reason,
|
|
881
1645
|
name: nativeName,
|
|
882
1646
|
tool_call_id: toolCall.id,
|
|
@@ -908,12 +1672,18 @@ function parseArgs(rawArgs) {
|
|
|
908
1672
|
}
|
|
909
1673
|
return out;
|
|
910
1674
|
}
|
|
911
|
-
function buildModel(
|
|
1675
|
+
function buildModel({
|
|
1676
|
+
rawModel,
|
|
1677
|
+
thinking,
|
|
1678
|
+
effort
|
|
1679
|
+
}) {
|
|
912
1680
|
if (!rawModel) return void 0;
|
|
913
1681
|
const baseUrl = procEnv2.ANTHROPIC_BASE_URL;
|
|
914
1682
|
const model = baseUrl ? rawModel : rawModel.replace(/^anthropic[/:]/, "");
|
|
915
1683
|
return new ChatAnthropic({
|
|
916
1684
|
model,
|
|
1685
|
+
...thinking ? { thinking } : {},
|
|
1686
|
+
...effort ? { outputConfig: { effort } } : {},
|
|
917
1687
|
...procEnv2.ANTHROPIC_API_KEY ? { apiKey: procEnv2.ANTHROPIC_API_KEY } : {},
|
|
918
1688
|
...baseUrl ? { anthropicApiUrl: baseUrl } : {},
|
|
919
1689
|
...procEnv2.AI_GATEWAY_API_KEY && HARNESS_CLIENT_APP ? {
|
|
@@ -926,6 +1696,31 @@ function buildModel(rawModel) {
|
|
|
926
1696
|
} : {}
|
|
927
1697
|
});
|
|
928
1698
|
}
|
|
1699
|
+
function createReasoningMiddleware({
|
|
1700
|
+
thinking,
|
|
1701
|
+
effort
|
|
1702
|
+
}) {
|
|
1703
|
+
if (!thinking && !effort) return void 0;
|
|
1704
|
+
return createMiddleware({
|
|
1705
|
+
name: "harnessReasoning",
|
|
1706
|
+
wrapModelCall: async (request, handler) => {
|
|
1707
|
+
let model = request.model;
|
|
1708
|
+
if ("_getModelInstance" in model && typeof model._getModelInstance === "function") {
|
|
1709
|
+
model = await model._getModelInstance();
|
|
1710
|
+
}
|
|
1711
|
+
if (!(model instanceof ChatAnthropic)) {
|
|
1712
|
+
throw new Error("Deep Agents reasoning requires ChatAnthropic");
|
|
1713
|
+
}
|
|
1714
|
+
const configuredModel = buildModel({
|
|
1715
|
+
rawModel: model.model,
|
|
1716
|
+
thinking,
|
|
1717
|
+
effort
|
|
1718
|
+
});
|
|
1719
|
+
if (!configuredModel) throw new Error("Deep Agents model is missing");
|
|
1720
|
+
return handler({ ...request, model: configuredModel });
|
|
1721
|
+
}
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
929
1724
|
var args = parseArgs(argv.slice(2));
|
|
930
1725
|
var workdir = args.workdir;
|
|
931
1726
|
var bridgeStateDir = args.bridgeStateDir;
|
|
@@ -939,7 +1734,7 @@ var mcpClient;
|
|
|
939
1734
|
var mcpToolNames = /* @__PURE__ */ new Set();
|
|
940
1735
|
function buildHostTools(toolSchemas) {
|
|
941
1736
|
return (toolSchemas ?? []).map(
|
|
942
|
-
(schema) =>
|
|
1737
|
+
(schema) => tool3(
|
|
943
1738
|
async (input) => {
|
|
944
1739
|
const turn = currentTurn;
|
|
945
1740
|
if (!turn) throw new Error("no active turn");
|
|
@@ -970,7 +1765,15 @@ async function runTurn(start, turn) {
|
|
|
970
1765
|
start.builtinToolFiltering
|
|
971
1766
|
);
|
|
972
1767
|
if (!agent) {
|
|
973
|
-
const model = buildModel(
|
|
1768
|
+
const model = buildModel({
|
|
1769
|
+
rawModel: start.model,
|
|
1770
|
+
thinking: start.thinking,
|
|
1771
|
+
effort: start.effort
|
|
1772
|
+
});
|
|
1773
|
+
const reasoningMiddleware = model ? void 0 : createReasoningMiddleware({
|
|
1774
|
+
thinking: start.thinking,
|
|
1775
|
+
effort: start.effort
|
|
1776
|
+
});
|
|
974
1777
|
const builtinToolFilteringMiddleware = createBuiltinToolFilteringMiddleware(
|
|
975
1778
|
{
|
|
976
1779
|
builtinToolFiltering: start.builtinToolFiltering,
|
|
@@ -981,6 +1784,10 @@ async function runTurn(start, turn) {
|
|
|
981
1784
|
}
|
|
982
1785
|
}
|
|
983
1786
|
);
|
|
1787
|
+
const middleware = [
|
|
1788
|
+
...reasoningMiddleware ? [reasoningMiddleware] : [],
|
|
1789
|
+
...builtinToolFilteringMiddleware ? [builtinToolFilteringMiddleware] : []
|
|
1790
|
+
];
|
|
984
1791
|
const hostTools = buildHostTools(start.tools);
|
|
985
1792
|
const hostToolNames2 = new Set(hostTools.map((hostTool) => hostTool.name));
|
|
986
1793
|
const externalTools = await loadMcpTools({
|
|
@@ -998,11 +1805,11 @@ async function runTurn(start, turn) {
|
|
|
998
1805
|
systemPrompt: start.instructions ? { suffix: start.instructions } : void 0,
|
|
999
1806
|
// Native skills loaded from the source dirs ($HOME-materialized + <workDir> for repo-provided skills).
|
|
1000
1807
|
...start.skillsPaths?.length ? { skills: start.skillsPaths } : {},
|
|
1001
|
-
...
|
|
1808
|
+
...middleware.length > 0 ? { middleware } : {},
|
|
1002
1809
|
// Gate built-in tools behind HITL approval when the permission mode requires it.
|
|
1003
1810
|
...interruptOn ? { interruptOn } : {},
|
|
1004
1811
|
// Real instance (LangGraph rejects `true` for root graphs); gives multi-turn memory.
|
|
1005
|
-
checkpointer: new
|
|
1812
|
+
checkpointer: new MemorySaver2()
|
|
1006
1813
|
});
|
|
1007
1814
|
}
|
|
1008
1815
|
const hostToolNames = new Set((start.tools ?? []).map((t) => t.name));
|
|
@@ -1080,7 +1887,7 @@ async function runTurn(start, turn) {
|
|
|
1080
1887
|
});
|
|
1081
1888
|
}
|
|
1082
1889
|
}
|
|
1083
|
-
resumeInput = new
|
|
1890
|
+
resumeInput = new Command5({ resume: { decisions } });
|
|
1084
1891
|
}
|
|
1085
1892
|
endTextBlock({ state: streamEventState, emit });
|
|
1086
1893
|
endReasoningBlock({ state: streamEventState, emit });
|