langchain 1.0.0-alpha.3 → 1.0.0-alpha.5
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/agents/ReactAgent.cjs +1 -1
- package/dist/agents/ReactAgent.cjs.map +1 -1
- package/dist/agents/ReactAgent.d.cts +3 -3
- package/dist/agents/ReactAgent.d.cts.map +1 -1
- package/dist/agents/ReactAgent.d.ts +3 -3
- package/dist/agents/ReactAgent.d.ts.map +1 -1
- package/dist/agents/ReactAgent.js +2 -2
- package/dist/agents/ReactAgent.js.map +1 -1
- package/dist/agents/RunnableCallable.cjs +5 -0
- package/dist/agents/RunnableCallable.cjs.map +1 -1
- package/dist/agents/RunnableCallable.d.cts +2 -0
- package/dist/agents/RunnableCallable.d.cts.map +1 -1
- package/dist/agents/RunnableCallable.d.ts +2 -0
- package/dist/agents/RunnableCallable.d.ts.map +1 -1
- package/dist/agents/RunnableCallable.js +5 -0
- package/dist/agents/RunnableCallable.js.map +1 -1
- package/dist/agents/annotation.cjs +2 -2
- package/dist/agents/annotation.cjs.map +1 -1
- package/dist/agents/annotation.d.cts +4 -4
- package/dist/agents/annotation.d.cts.map +1 -1
- package/dist/agents/annotation.d.ts +3 -3
- package/dist/agents/annotation.d.ts.map +1 -1
- package/dist/agents/annotation.js +2 -2
- package/dist/agents/annotation.js.map +1 -1
- package/dist/agents/createAgent.cjs +10 -0
- package/dist/agents/createAgent.cjs.map +1 -0
- package/dist/agents/createAgent.js +10 -0
- package/dist/agents/createAgent.js.map +1 -0
- package/dist/agents/errors.cjs +1 -1
- package/dist/agents/errors.cjs.map +1 -1
- package/dist/agents/errors.js +1 -1
- package/dist/agents/errors.js.map +1 -1
- package/dist/agents/index.cjs +23 -4
- package/dist/agents/index.cjs.map +1 -1
- package/dist/agents/index.d.cts +96 -33
- package/dist/agents/index.d.cts.map +1 -1
- package/dist/agents/index.d.ts +96 -33
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +23 -4
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/middlewareAgent/ReactAgent.cjs +255 -0
- package/dist/agents/middlewareAgent/ReactAgent.cjs.map +1 -0
- package/dist/agents/middlewareAgent/ReactAgent.d.cts +68 -0
- package/dist/agents/middlewareAgent/ReactAgent.d.cts.map +1 -0
- package/dist/agents/middlewareAgent/ReactAgent.d.ts +68 -0
- package/dist/agents/middlewareAgent/ReactAgent.d.ts.map +1 -0
- package/dist/agents/middlewareAgent/ReactAgent.js +254 -0
- package/dist/agents/middlewareAgent/ReactAgent.js.map +1 -0
- package/dist/agents/middlewareAgent/annotation.cjs +39 -0
- package/dist/agents/middlewareAgent/annotation.cjs.map +1 -0
- package/dist/agents/middlewareAgent/annotation.js +38 -0
- package/dist/agents/middlewareAgent/annotation.js.map +1 -0
- package/dist/agents/middlewareAgent/index.cjs +11 -0
- package/dist/agents/middlewareAgent/index.cjs.map +1 -0
- package/dist/agents/middlewareAgent/index.js +11 -0
- package/dist/agents/middlewareAgent/index.js.map +1 -0
- package/dist/agents/middlewareAgent/middleware.cjs +47 -0
- package/dist/agents/middlewareAgent/middleware.cjs.map +1 -0
- package/dist/agents/middlewareAgent/middleware.d.cts +46 -0
- package/dist/agents/middlewareAgent/middleware.d.cts.map +1 -0
- package/dist/agents/middlewareAgent/middleware.d.ts +46 -0
- package/dist/agents/middlewareAgent/middleware.d.ts.map +1 -0
- package/dist/agents/middlewareAgent/middleware.js +46 -0
- package/dist/agents/middlewareAgent/middleware.js.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.cjs +235 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.cjs.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.d.cts +199 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.d.cts.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.d.ts +199 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.d.ts.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.js +234 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.js.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/index.cjs +8 -0
- package/dist/agents/middlewareAgent/middlewares/index.d.cts +4 -0
- package/dist/agents/middlewareAgent/middlewares/index.d.ts +4 -0
- package/dist/agents/middlewareAgent/middlewares/index.js +5 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.cjs +153 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.cjs.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.d.cts +152 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.d.cts.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.d.ts +152 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.d.ts.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.js +152 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.js.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.cjs +262 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.cjs.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.d.cts +89 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.d.cts.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.d.ts +89 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.d.ts.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.js +260 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.js.map +1 -0
- package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs +29 -0
- package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs.map +1 -0
- package/dist/agents/middlewareAgent/nodes/AfterModalNode.js +29 -0
- package/dist/agents/middlewareAgent/nodes/AfterModalNode.js.map +1 -0
- package/dist/agents/middlewareAgent/nodes/AgentNode.cjs +332 -0
- package/dist/agents/middlewareAgent/nodes/AgentNode.cjs.map +1 -0
- package/dist/agents/middlewareAgent/nodes/AgentNode.js +331 -0
- package/dist/agents/middlewareAgent/nodes/AgentNode.js.map +1 -0
- package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs +27 -0
- package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs.map +1 -0
- package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js +27 -0
- package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js.map +1 -0
- package/dist/agents/middlewareAgent/nodes/middleware.cjs +73 -0
- package/dist/agents/middlewareAgent/nodes/middleware.cjs.map +1 -0
- package/dist/agents/middlewareAgent/nodes/middleware.js +73 -0
- package/dist/agents/middlewareAgent/nodes/middleware.js.map +1 -0
- package/dist/agents/middlewareAgent/nodes/utils.cjs +74 -0
- package/dist/agents/middlewareAgent/nodes/utils.cjs.map +1 -0
- package/dist/agents/middlewareAgent/nodes/utils.js +70 -0
- package/dist/agents/middlewareAgent/nodes/utils.js.map +1 -0
- package/dist/agents/middlewareAgent/types.d.cts +393 -0
- package/dist/agents/middlewareAgent/types.d.cts.map +1 -0
- package/dist/agents/middlewareAgent/types.d.ts +393 -0
- package/dist/agents/middlewareAgent/types.d.ts.map +1 -0
- package/dist/agents/nodes/AgentNode.cjs.map +1 -1
- package/dist/agents/nodes/AgentNode.js.map +1 -1
- package/dist/agents/nodes/ToolNode.cjs +1 -1
- package/dist/agents/nodes/ToolNode.cjs.map +1 -1
- package/dist/agents/nodes/ToolNode.d.cts +4 -4
- package/dist/agents/nodes/ToolNode.d.cts.map +1 -1
- package/dist/agents/nodes/ToolNode.d.ts +1 -1
- package/dist/agents/nodes/ToolNode.d.ts.map +1 -1
- package/dist/agents/nodes/ToolNode.js +1 -1
- package/dist/agents/nodes/ToolNode.js.map +1 -1
- package/dist/agents/responses.cjs +1 -1
- package/dist/agents/responses.cjs.map +1 -1
- package/dist/agents/responses.d.cts +1 -1
- package/dist/agents/responses.d.cts.map +1 -1
- package/dist/agents/responses.d.ts +1 -1
- package/dist/agents/responses.d.ts.map +1 -1
- package/dist/agents/responses.js +1 -1
- package/dist/agents/responses.js.map +1 -1
- package/dist/agents/types.d.cts +12 -12
- package/dist/agents/types.d.cts.map +1 -1
- package/dist/agents/types.d.ts +8 -8
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/utils.cjs +1 -1
- package/dist/agents/utils.cjs.map +1 -1
- package/dist/agents/utils.js +1 -1
- package/dist/agents/utils.js.map +1 -1
- package/dist/agents/withAgentName.cjs +1 -1
- package/dist/agents/withAgentName.cjs.map +1 -1
- package/dist/agents/withAgentName.js +1 -1
- package/dist/agents/withAgentName.js.map +1 -1
- package/dist/chains/api/api_chain.d.cts +1 -1
- package/dist/chains/base.d.cts +1 -1
- package/dist/chains/combine_docs_chain.d.cts +1 -1
- package/dist/chains/combine_documents/stuff.d.cts +1 -1
- package/dist/chains/conversational_retrieval_chain.d.cts +1 -1
- package/dist/chains/graph_qa/cypher.d.cts +1 -1
- package/dist/chains/history_aware_retriever.d.cts +2 -2
- package/dist/chains/llm_chain.d.cts +3 -3
- package/dist/chains/openai_functions/base.d.cts +3 -3
- package/dist/chains/openai_functions/openapi.d.cts +1 -1
- package/dist/chains/openai_functions/structured_output.d.cts +3 -3
- package/dist/chains/openai_functions/tagging.d.cts +1 -1
- package/dist/chains/query_constructor/index.cjs +1 -1
- package/dist/chains/query_constructor/index.d.cts +2 -2
- package/dist/chains/query_constructor/index.d.ts +1 -1
- package/dist/chains/query_constructor/index.js +1 -1
- package/dist/chains/question_answering/load.d.ts +2 -2
- package/dist/chains/question_answering/load.d.ts.map +1 -1
- package/dist/chains/retrieval.d.cts +1 -1
- package/dist/chains/router/llm_router.d.cts +1 -1
- package/dist/chains/router/multi_prompt.cjs +1 -1
- package/dist/chains/router/multi_prompt.js +1 -1
- package/dist/chains/router/multi_retrieval_qa.cjs +1 -1
- package/dist/chains/router/multi_retrieval_qa.js +1 -1
- package/dist/chains/sql_db/sql_db_chain.d.cts +2 -2
- package/dist/chains/summarization/load.d.ts +2 -2
- package/dist/chains/summarization/load.d.ts.map +1 -1
- package/dist/chat_models/universal.d.cts +3 -3
- package/dist/evaluation/agents/trajectory.d.cts +3 -3
- package/dist/evaluation/agents/trajectory.d.ts.map +1 -1
- package/dist/evaluation/comparison/pairwise.d.cts +1 -1
- package/dist/evaluation/comparison/pairwise.d.ts.map +1 -1
- package/dist/evaluation/criteria/criteria.d.cts +1 -1
- package/dist/evaluation/qa/eval_chain.d.cts +1 -1
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +4 -3
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/load/import_map.cjs +1 -1
- package/dist/load/import_map.js +1 -1
- package/dist/memory/summary.d.cts +1 -1
- package/dist/output_parsers/fix.d.cts +1 -1
- package/dist/output_parsers/http_response.d.cts +1 -1
- package/dist/output_parsers/structured.cjs +1 -1
- package/dist/output_parsers/structured.d.cts +2 -2
- package/dist/output_parsers/structured.d.ts +1 -1
- package/dist/output_parsers/structured.js +1 -1
- package/dist/tools/fs.d.cts +1 -1
- package/dist/tools/json.d.cts +1 -1
- package/dist/tools/retriever.d.cts +1 -1
- package/dist/tools/vectorstore.d.cts +1 -1
- package/dist/tools/webbrowser.d.cts +1 -1
- package/package.json +14 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promptCaching.cjs","names":["z","middlewareOptions?: Partial<z.infer<typeof contextSchema>>","createMiddleware"],"sources":["../../../../src/agents/middlewareAgent/middlewares/promptCaching.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { createMiddleware } from \"../middleware.js\";\n\nconst contextSchema = z.object({\n // Configuration options\n enableCaching: z.boolean().default(true),\n ttl: z.enum([\"5m\", \"1h\"]).default(\"5m\"),\n minMessagesToCache: z.number().default(3),\n});\n\n/**\n * Creates a prompt caching middleware for Anthropic models to optimize API usage.\n *\n * This middleware automatically adds cache control headers to messages when using Anthropic models,\n * enabling their prompt caching feature. This can significantly reduce costs and latency for\n * applications with repetitive prompts, long system messages, or extensive conversation histories.\n *\n * ## How It Works\n *\n * The middleware intercepts model requests and adds cache control metadata that tells Anthropic's\n * API to cache processed prompt prefixes. On subsequent requests with matching prefixes, the\n * cached representations are reused, skipping redundant token processing.\n *\n * ## Benefits\n *\n * - **Cost Reduction**: Avoid reprocessing the same tokens repeatedly (up to 90% savings on cached portions)\n * - **Lower Latency**: Cached prompts are processed faster as embeddings are pre-computed\n * - **Better Scalability**: Reduced computational load enables handling more requests\n * - **Consistent Performance**: Stable response times for repetitive queries\n *\n * @param middlewareOptions - Configuration options for the caching behavior\n * @param middlewareOptions.enableCaching - Whether to enable prompt caching (default: `true`)\n * @param middlewareOptions.ttl - Cache time-to-live: `\"5m\"` for 5 minutes or `\"1h\"` for 1 hour (default: `\"5m\"`)\n * @param middlewareOptions.minMessagesToCache - Minimum number of messages required before caching is applied (default: `3`)\n *\n * @returns A middleware instance that can be passed to `createAgent`\n *\n * @throws {Error} If used with non-Anthropic models\n *\n * @example\n * Basic usage with default settings\n * ```typescript\n * import { createAgent } from \"langchain\";\n * import { anthropicPromptCachingMiddleware } from \"langchain/middleware\";\n *\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * middlewares: [\n * anthropicPromptCachingMiddleware()\n * ]\n * });\n * ```\n *\n * @example\n * Custom configuration for longer conversations\n * ```typescript\n * const cachingMiddleware = anthropicPromptCachingMiddleware({\n * ttl: \"1h\", // Cache for 1 hour instead of default 5 minutes\n * minMessagesToCache: 5 // Only cache after 5 messages\n * });\n *\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * systemMessage: \"You are a helpful assistant with deep knowledge of...\", // Long system prompt\n * middlewares: [cachingMiddleware]\n * });\n * ```\n *\n * @example\n * Conditional caching based on runtime context\n * ```typescript\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * middlewares: [\n * anthropicPromptCachingMiddleware({\n * enableCaching: true,\n * ttl: \"5m\"\n * })\n * ]\n * });\n *\n * // Disable caching for specific requests\n * await agent.invoke(\n * { messages: [new HumanMessage(\"Process this without caching\")] },\n * {\n * configurable: {\n * middleware_context: { enableCaching: false }\n * }\n * }\n * );\n * ```\n *\n * @example\n * Optimal setup for customer support chatbot\n * ```typescript\n * const supportAgent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * systemMessage: `You are a customer support agent for ACME Corp.\n *\n * Company policies:\n * - Always be polite and professional\n * - Refer to knowledge base for product information\n * - Escalate billing issues to human agents\n * ... (extensive policies and guidelines)\n * `,\n * tools: [searchKnowledgeBase, createTicket, checkOrderStatus],\n * middlewares: [\n * anthropicPromptCachingMiddleware({\n * ttl: \"1h\", // Long TTL for stable system prompt\n * minMessagesToCache: 1 // Cache immediately due to large system prompt\n * })\n * ]\n * });\n * ```\n *\n * @remarks\n * - **Anthropic Only**: This middleware only works with Anthropic models and will throw an error if used with other providers\n * - **Automatic Application**: Caching is applied automatically when message count exceeds `minMessagesToCache`\n * - **Cache Scope**: Caches are isolated per API key and cannot be shared across different keys\n * - **TTL Options**: Only supports \"5m\" (5 minutes) and \"1h\" (1 hour) as TTL values per Anthropic's API\n * - **Best Use Cases**: Long system prompts, multi-turn conversations, repetitive queries, RAG applications\n * - **Cost Impact**: Cached tokens are billed at 10% of the base input token price, cache writes are billed at 25% of the base\n *\n * @see {@link createAgent} for agent creation\n * @see {@link https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching} Anthropic's prompt caching documentation\n * @public\n */\nexport function anthropicPromptCachingMiddleware(\n middlewareOptions?: Partial<z.infer<typeof contextSchema>>\n) {\n return createMiddleware({\n name: \"PromptCachingMiddleware\",\n contextSchema,\n prepareModelRequest: (options, state, runtime) => {\n const enableCaching =\n runtime.context.enableCaching ?? middlewareOptions?.enableCaching;\n const ttl = runtime.context.ttl ?? middlewareOptions?.ttl;\n const minMessagesToCache =\n runtime.context.minMessagesToCache ??\n middlewareOptions?.minMessagesToCache;\n\n // Skip if caching is disabled\n if (!enableCaching) {\n return undefined;\n }\n\n if (options.model?.getName() !== \"anthropic\") {\n throw new Error(\n \"Prompt caching is only supported for Anthropic models\"\n );\n }\n\n const messagesCount =\n state.messages.length + (options.systemMessage ? 1 : 0);\n\n if (messagesCount < minMessagesToCache) {\n return options;\n }\n\n return {\n ...options,\n modelSettings: {\n cache_control: {\n type: \"ephemeral\",\n ttl,\n },\n },\n };\n },\n });\n}\n"],"mappings":";;;;;AAGA,MAAM,gBAAgBA,MAAE,OAAO;CAE7B,eAAeA,MAAE,SAAS,CAAC,QAAQ,KAAK;CACxC,KAAKA,MAAE,KAAK,CAAC,MAAM,IAAK,EAAC,CAAC,QAAQ,KAAK;CACvC,oBAAoBA,MAAE,QAAQ,CAAC,QAAQ,EAAE;AAC1C,EAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuHF,SAAgB,iCACdC,mBACA;AACA,QAAOC,oCAAiB;EACtB,MAAM;EACN;EACA,qBAAqB,CAAC,SAAS,OAAO,YAAY;GAChD,MAAM,gBACJ,QAAQ,QAAQ,iBAAiB,mBAAmB;GACtD,MAAM,MAAM,QAAQ,QAAQ,OAAO,mBAAmB;GACtD,MAAM,qBACJ,QAAQ,QAAQ,sBAChB,mBAAmB;AAGrB,OAAI,CAAC,cACH,QAAO;AAGT,OAAI,QAAQ,OAAO,SAAS,KAAK,YAC/B,OAAM,IAAI,MACR;GAIJ,MAAM,gBACJ,MAAM,SAAS,UAAU,QAAQ,gBAAgB,IAAI;AAEvD,OAAI,gBAAgB,mBAClB,QAAO;AAGT,UAAO;IACL,GAAG;IACH,eAAe,EACb,eAAe;KACb,MAAM;KACN;IACD,EACF;GACF;EACF;CACF,EAAC;AACH"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { AgentMiddleware } from "../types.cjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/agents/middlewareAgent/middlewares/promptCaching.d.ts
|
|
5
|
+
declare const contextSchema: z.ZodObject<{
|
|
6
|
+
// Configuration options
|
|
7
|
+
enableCaching: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
+
ttl: z.ZodDefault<z.ZodEnum<["5m", "1h"]>>;
|
|
9
|
+
minMessagesToCache: z.ZodDefault<z.ZodNumber>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
enableCaching: boolean;
|
|
12
|
+
ttl: "1h" | "5m";
|
|
13
|
+
minMessagesToCache: number;
|
|
14
|
+
}, {
|
|
15
|
+
enableCaching?: boolean | undefined;
|
|
16
|
+
ttl?: "1h" | "5m" | undefined;
|
|
17
|
+
minMessagesToCache?: number | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a prompt caching middleware for Anthropic models to optimize API usage.
|
|
21
|
+
*
|
|
22
|
+
* This middleware automatically adds cache control headers to messages when using Anthropic models,
|
|
23
|
+
* enabling their prompt caching feature. This can significantly reduce costs and latency for
|
|
24
|
+
* applications with repetitive prompts, long system messages, or extensive conversation histories.
|
|
25
|
+
*
|
|
26
|
+
* ## How It Works
|
|
27
|
+
*
|
|
28
|
+
* The middleware intercepts model requests and adds cache control metadata that tells Anthropic's
|
|
29
|
+
* API to cache processed prompt prefixes. On subsequent requests with matching prefixes, the
|
|
30
|
+
* cached representations are reused, skipping redundant token processing.
|
|
31
|
+
*
|
|
32
|
+
* ## Benefits
|
|
33
|
+
*
|
|
34
|
+
* - **Cost Reduction**: Avoid reprocessing the same tokens repeatedly (up to 90% savings on cached portions)
|
|
35
|
+
* - **Lower Latency**: Cached prompts are processed faster as embeddings are pre-computed
|
|
36
|
+
* - **Better Scalability**: Reduced computational load enables handling more requests
|
|
37
|
+
* - **Consistent Performance**: Stable response times for repetitive queries
|
|
38
|
+
*
|
|
39
|
+
* @param middlewareOptions - Configuration options for the caching behavior
|
|
40
|
+
* @param middlewareOptions.enableCaching - Whether to enable prompt caching (default: `true`)
|
|
41
|
+
* @param middlewareOptions.ttl - Cache time-to-live: `"5m"` for 5 minutes or `"1h"` for 1 hour (default: `"5m"`)
|
|
42
|
+
* @param middlewareOptions.minMessagesToCache - Minimum number of messages required before caching is applied (default: `3`)
|
|
43
|
+
*
|
|
44
|
+
* @returns A middleware instance that can be passed to `createAgent`
|
|
45
|
+
*
|
|
46
|
+
* @throws {Error} If used with non-Anthropic models
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* Basic usage with default settings
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import { createAgent } from "langchain";
|
|
52
|
+
* import { anthropicPromptCachingMiddleware } from "langchain/middleware";
|
|
53
|
+
*
|
|
54
|
+
* const agent = createAgent({
|
|
55
|
+
* model: "anthropic:claude-3-5-sonnet",
|
|
56
|
+
* middlewares: [
|
|
57
|
+
* anthropicPromptCachingMiddleware()
|
|
58
|
+
* ]
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* Custom configuration for longer conversations
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const cachingMiddleware = anthropicPromptCachingMiddleware({
|
|
66
|
+
* ttl: "1h", // Cache for 1 hour instead of default 5 minutes
|
|
67
|
+
* minMessagesToCache: 5 // Only cache after 5 messages
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* const agent = createAgent({
|
|
71
|
+
* model: "anthropic:claude-3-5-sonnet",
|
|
72
|
+
* systemMessage: "You are a helpful assistant with deep knowledge of...", // Long system prompt
|
|
73
|
+
* middlewares: [cachingMiddleware]
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* Conditional caching based on runtime context
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const agent = createAgent({
|
|
81
|
+
* model: "anthropic:claude-3-5-sonnet",
|
|
82
|
+
* middlewares: [
|
|
83
|
+
* anthropicPromptCachingMiddleware({
|
|
84
|
+
* enableCaching: true,
|
|
85
|
+
* ttl: "5m"
|
|
86
|
+
* })
|
|
87
|
+
* ]
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* // Disable caching for specific requests
|
|
91
|
+
* await agent.invoke(
|
|
92
|
+
* { messages: [new HumanMessage("Process this without caching")] },
|
|
93
|
+
* {
|
|
94
|
+
* configurable: {
|
|
95
|
+
* middleware_context: { enableCaching: false }
|
|
96
|
+
* }
|
|
97
|
+
* }
|
|
98
|
+
* );
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* Optimal setup for customer support chatbot
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const supportAgent = createAgent({
|
|
105
|
+
* model: "anthropic:claude-3-5-sonnet",
|
|
106
|
+
* systemMessage: `You are a customer support agent for ACME Corp.
|
|
107
|
+
*
|
|
108
|
+
* Company policies:
|
|
109
|
+
* - Always be polite and professional
|
|
110
|
+
* - Refer to knowledge base for product information
|
|
111
|
+
* - Escalate billing issues to human agents
|
|
112
|
+
* ... (extensive policies and guidelines)
|
|
113
|
+
* `,
|
|
114
|
+
* tools: [searchKnowledgeBase, createTicket, checkOrderStatus],
|
|
115
|
+
* middlewares: [
|
|
116
|
+
* anthropicPromptCachingMiddleware({
|
|
117
|
+
* ttl: "1h", // Long TTL for stable system prompt
|
|
118
|
+
* minMessagesToCache: 1 // Cache immediately due to large system prompt
|
|
119
|
+
* })
|
|
120
|
+
* ]
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @remarks
|
|
125
|
+
* - **Anthropic Only**: This middleware only works with Anthropic models and will throw an error if used with other providers
|
|
126
|
+
* - **Automatic Application**: Caching is applied automatically when message count exceeds `minMessagesToCache`
|
|
127
|
+
* - **Cache Scope**: Caches are isolated per API key and cannot be shared across different keys
|
|
128
|
+
* - **TTL Options**: Only supports "5m" (5 minutes) and "1h" (1 hour) as TTL values per Anthropic's API
|
|
129
|
+
* - **Best Use Cases**: Long system prompts, multi-turn conversations, repetitive queries, RAG applications
|
|
130
|
+
* - **Cost Impact**: Cached tokens are billed at 10% of the base input token price, cache writes are billed at 25% of the base
|
|
131
|
+
*
|
|
132
|
+
* @see {@link createAgent} for agent creation
|
|
133
|
+
* @see {@link https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching} Anthropic's prompt caching documentation
|
|
134
|
+
* @public
|
|
135
|
+
*/
|
|
136
|
+
declare function anthropicPromptCachingMiddleware(middlewareOptions?: Partial<z.infer<typeof contextSchema>>): AgentMiddleware<undefined, z.ZodObject<{
|
|
137
|
+
// Configuration options
|
|
138
|
+
enableCaching: z.ZodDefault<z.ZodBoolean>;
|
|
139
|
+
ttl: z.ZodDefault<z.ZodEnum<["5m", "1h"]>>;
|
|
140
|
+
minMessagesToCache: z.ZodDefault<z.ZodNumber>;
|
|
141
|
+
}, "strip", z.ZodTypeAny, {
|
|
142
|
+
enableCaching: boolean;
|
|
143
|
+
ttl: "1h" | "5m";
|
|
144
|
+
minMessagesToCache: number;
|
|
145
|
+
}, {
|
|
146
|
+
enableCaching?: boolean | undefined;
|
|
147
|
+
ttl?: "1h" | "5m" | undefined;
|
|
148
|
+
minMessagesToCache?: number | undefined;
|
|
149
|
+
}>, any>;
|
|
150
|
+
//#endregion
|
|
151
|
+
export { anthropicPromptCachingMiddleware };
|
|
152
|
+
//# sourceMappingURL=promptCaching.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promptCaching.d.cts","names":["z","contextSchema","ZodBoolean","ZodDefault","ZodEnum","ZodNumber","ZodTypeAny","ZodObject","anthropicPromptCachingMiddleware","infer","Partial","___types_js0","AgentMiddleware"],"sources":["../../../../src/agents/middlewareAgent/middlewares/promptCaching.d.ts"],"sourcesContent":["import { z } from \"zod\";\ndeclare const contextSchema: z.ZodObject<{\n // Configuration options\n enableCaching: z.ZodDefault<z.ZodBoolean>;\n ttl: z.ZodDefault<z.ZodEnum<[\"5m\", \"1h\"]>>;\n minMessagesToCache: z.ZodDefault<z.ZodNumber>;\n}, \"strip\", z.ZodTypeAny, {\n enableCaching: boolean;\n ttl: \"1h\" | \"5m\";\n minMessagesToCache: number;\n}, {\n enableCaching?: boolean | undefined;\n ttl?: \"1h\" | \"5m\" | undefined;\n minMessagesToCache?: number | undefined;\n}>;\n/**\n * Creates a prompt caching middleware for Anthropic models to optimize API usage.\n *\n * This middleware automatically adds cache control headers to messages when using Anthropic models,\n * enabling their prompt caching feature. This can significantly reduce costs and latency for\n * applications with repetitive prompts, long system messages, or extensive conversation histories.\n *\n * ## How It Works\n *\n * The middleware intercepts model requests and adds cache control metadata that tells Anthropic's\n * API to cache processed prompt prefixes. On subsequent requests with matching prefixes, the\n * cached representations are reused, skipping redundant token processing.\n *\n * ## Benefits\n *\n * - **Cost Reduction**: Avoid reprocessing the same tokens repeatedly (up to 90% savings on cached portions)\n * - **Lower Latency**: Cached prompts are processed faster as embeddings are pre-computed\n * - **Better Scalability**: Reduced computational load enables handling more requests\n * - **Consistent Performance**: Stable response times for repetitive queries\n *\n * @param middlewareOptions - Configuration options for the caching behavior\n * @param middlewareOptions.enableCaching - Whether to enable prompt caching (default: `true`)\n * @param middlewareOptions.ttl - Cache time-to-live: `\"5m\"` for 5 minutes or `\"1h\"` for 1 hour (default: `\"5m\"`)\n * @param middlewareOptions.minMessagesToCache - Minimum number of messages required before caching is applied (default: `3`)\n *\n * @returns A middleware instance that can be passed to `createAgent`\n *\n * @throws {Error} If used with non-Anthropic models\n *\n * @example\n * Basic usage with default settings\n * ```typescript\n * import { createAgent } from \"langchain\";\n * import { anthropicPromptCachingMiddleware } from \"langchain/middleware\";\n *\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * middlewares: [\n * anthropicPromptCachingMiddleware()\n * ]\n * });\n * ```\n *\n * @example\n * Custom configuration for longer conversations\n * ```typescript\n * const cachingMiddleware = anthropicPromptCachingMiddleware({\n * ttl: \"1h\", // Cache for 1 hour instead of default 5 minutes\n * minMessagesToCache: 5 // Only cache after 5 messages\n * });\n *\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * systemMessage: \"You are a helpful assistant with deep knowledge of...\", // Long system prompt\n * middlewares: [cachingMiddleware]\n * });\n * ```\n *\n * @example\n * Conditional caching based on runtime context\n * ```typescript\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * middlewares: [\n * anthropicPromptCachingMiddleware({\n * enableCaching: true,\n * ttl: \"5m\"\n * })\n * ]\n * });\n *\n * // Disable caching for specific requests\n * await agent.invoke(\n * { messages: [new HumanMessage(\"Process this without caching\")] },\n * {\n * configurable: {\n * middleware_context: { enableCaching: false }\n * }\n * }\n * );\n * ```\n *\n * @example\n * Optimal setup for customer support chatbot\n * ```typescript\n * const supportAgent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * systemMessage: `You are a customer support agent for ACME Corp.\n *\n * Company policies:\n * - Always be polite and professional\n * - Refer to knowledge base for product information\n * - Escalate billing issues to human agents\n * ... (extensive policies and guidelines)\n * `,\n * tools: [searchKnowledgeBase, createTicket, checkOrderStatus],\n * middlewares: [\n * anthropicPromptCachingMiddleware({\n * ttl: \"1h\", // Long TTL for stable system prompt\n * minMessagesToCache: 1 // Cache immediately due to large system prompt\n * })\n * ]\n * });\n * ```\n *\n * @remarks\n * - **Anthropic Only**: This middleware only works with Anthropic models and will throw an error if used with other providers\n * - **Automatic Application**: Caching is applied automatically when message count exceeds `minMessagesToCache`\n * - **Cache Scope**: Caches are isolated per API key and cannot be shared across different keys\n * - **TTL Options**: Only supports \"5m\" (5 minutes) and \"1h\" (1 hour) as TTL values per Anthropic's API\n * - **Best Use Cases**: Long system prompts, multi-turn conversations, repetitive queries, RAG applications\n * - **Cost Impact**: Cached tokens are billed at 10% of the base input token price, cache writes are billed at 25% of the base\n *\n * @see {@link createAgent} for agent creation\n * @see {@link https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching} Anthropic's prompt caching documentation\n * @public\n */\nexport declare function anthropicPromptCachingMiddleware(middlewareOptions?: Partial<z.infer<typeof contextSchema>>): import(\"../types.js\").AgentMiddleware<undefined, z.ZodObject<{\n // Configuration options\n enableCaching: z.ZodDefault<z.ZodBoolean>;\n ttl: z.ZodDefault<z.ZodEnum<[\"5m\", \"1h\"]>>;\n minMessagesToCache: z.ZodDefault<z.ZodNumber>;\n}, \"strip\", z.ZodTypeAny, {\n enableCaching: boolean;\n ttl: \"1h\" | \"5m\";\n minMessagesToCache: number;\n}, {\n enableCaching?: boolean | undefined;\n ttl?: \"1h\" | \"5m\" | undefined;\n minMessagesToCache?: number | undefined;\n}>, any>;\nexport {};\n"],"mappings":";;;;cACcC,eAAeD,CAAAA,CAAEO;;iBAEZP,CAAAA,CAAEG,WAAWH,CAAAA,CAAEE;EAFpBD,GAAAA,EAGLD,CAAAA,CAAEG,UAUT,CAVoBH,CAAAA,CAAEI,OAUtB,CAAA,CAAA,IAAA,EAAA,IAAA,CAAA,CAAA,CAAA;EAAA,kBAAA,EATsBJ,CAAAA,CAAEG,UASxB,CATmCH,CAAAA,CAAEK,SASrC,CAAA;CAAA,EAAA,OAXgCH,EAGtBF,CAAAA,CAAEM,UAHoBJ,EAAAA;EAAU,aAAvBC,EAAAA,OAAAA;EAAU,GACTH,EAAEI,IAAAA,GAAAA,IAAAA;EAAO,kBAApBD,EAAAA,MAAAA;CAAU,EAAA;EAC2B,aAAtBA,CAAAA,EAAAA,OAAAA,GAAAA,SAAAA;EAAU,GACxBH,CAAAA,EAAEM,IAAAA,GAAAA,IAAAA,GAAAA,SAAAA;EAAU,kBALOC,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;AAAS,CAAA,CAAA;AAmIxC;;;;;;;;;;;;;;AAA2J;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAnIC,gCAAAA,qBAAqDE,QAAQV,CAAAA,CAAES,aAAaR,kBAA8E,2BAAXD,CAAAA,CAAEO;;iBAEtJP,CAAAA,CAAEG,WAAWH,CAAAA,CAAEE;OACzBF,CAAAA,CAAEG,WAAWH,CAAAA,CAAEI;sBACAJ,CAAAA,CAAEG,WAAWH,CAAAA,CAAEK;YAC3BL,CAAAA,CAAEM"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { AgentMiddleware } from "../types.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/agents/middlewareAgent/middlewares/promptCaching.d.ts
|
|
5
|
+
declare const contextSchema: z.ZodObject<{
|
|
6
|
+
// Configuration options
|
|
7
|
+
enableCaching: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
+
ttl: z.ZodDefault<z.ZodEnum<["5m", "1h"]>>;
|
|
9
|
+
minMessagesToCache: z.ZodDefault<z.ZodNumber>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
enableCaching: boolean;
|
|
12
|
+
ttl: "1h" | "5m";
|
|
13
|
+
minMessagesToCache: number;
|
|
14
|
+
}, {
|
|
15
|
+
enableCaching?: boolean | undefined;
|
|
16
|
+
ttl?: "1h" | "5m" | undefined;
|
|
17
|
+
minMessagesToCache?: number | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a prompt caching middleware for Anthropic models to optimize API usage.
|
|
21
|
+
*
|
|
22
|
+
* This middleware automatically adds cache control headers to messages when using Anthropic models,
|
|
23
|
+
* enabling their prompt caching feature. This can significantly reduce costs and latency for
|
|
24
|
+
* applications with repetitive prompts, long system messages, or extensive conversation histories.
|
|
25
|
+
*
|
|
26
|
+
* ## How It Works
|
|
27
|
+
*
|
|
28
|
+
* The middleware intercepts model requests and adds cache control metadata that tells Anthropic's
|
|
29
|
+
* API to cache processed prompt prefixes. On subsequent requests with matching prefixes, the
|
|
30
|
+
* cached representations are reused, skipping redundant token processing.
|
|
31
|
+
*
|
|
32
|
+
* ## Benefits
|
|
33
|
+
*
|
|
34
|
+
* - **Cost Reduction**: Avoid reprocessing the same tokens repeatedly (up to 90% savings on cached portions)
|
|
35
|
+
* - **Lower Latency**: Cached prompts are processed faster as embeddings are pre-computed
|
|
36
|
+
* - **Better Scalability**: Reduced computational load enables handling more requests
|
|
37
|
+
* - **Consistent Performance**: Stable response times for repetitive queries
|
|
38
|
+
*
|
|
39
|
+
* @param middlewareOptions - Configuration options for the caching behavior
|
|
40
|
+
* @param middlewareOptions.enableCaching - Whether to enable prompt caching (default: `true`)
|
|
41
|
+
* @param middlewareOptions.ttl - Cache time-to-live: `"5m"` for 5 minutes or `"1h"` for 1 hour (default: `"5m"`)
|
|
42
|
+
* @param middlewareOptions.minMessagesToCache - Minimum number of messages required before caching is applied (default: `3`)
|
|
43
|
+
*
|
|
44
|
+
* @returns A middleware instance that can be passed to `createAgent`
|
|
45
|
+
*
|
|
46
|
+
* @throws {Error} If used with non-Anthropic models
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* Basic usage with default settings
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import { createAgent } from "langchain";
|
|
52
|
+
* import { anthropicPromptCachingMiddleware } from "langchain/middleware";
|
|
53
|
+
*
|
|
54
|
+
* const agent = createAgent({
|
|
55
|
+
* model: "anthropic:claude-3-5-sonnet",
|
|
56
|
+
* middlewares: [
|
|
57
|
+
* anthropicPromptCachingMiddleware()
|
|
58
|
+
* ]
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* Custom configuration for longer conversations
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const cachingMiddleware = anthropicPromptCachingMiddleware({
|
|
66
|
+
* ttl: "1h", // Cache for 1 hour instead of default 5 minutes
|
|
67
|
+
* minMessagesToCache: 5 // Only cache after 5 messages
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* const agent = createAgent({
|
|
71
|
+
* model: "anthropic:claude-3-5-sonnet",
|
|
72
|
+
* systemMessage: "You are a helpful assistant with deep knowledge of...", // Long system prompt
|
|
73
|
+
* middlewares: [cachingMiddleware]
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* Conditional caching based on runtime context
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const agent = createAgent({
|
|
81
|
+
* model: "anthropic:claude-3-5-sonnet",
|
|
82
|
+
* middlewares: [
|
|
83
|
+
* anthropicPromptCachingMiddleware({
|
|
84
|
+
* enableCaching: true,
|
|
85
|
+
* ttl: "5m"
|
|
86
|
+
* })
|
|
87
|
+
* ]
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* // Disable caching for specific requests
|
|
91
|
+
* await agent.invoke(
|
|
92
|
+
* { messages: [new HumanMessage("Process this without caching")] },
|
|
93
|
+
* {
|
|
94
|
+
* configurable: {
|
|
95
|
+
* middleware_context: { enableCaching: false }
|
|
96
|
+
* }
|
|
97
|
+
* }
|
|
98
|
+
* );
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* Optimal setup for customer support chatbot
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const supportAgent = createAgent({
|
|
105
|
+
* model: "anthropic:claude-3-5-sonnet",
|
|
106
|
+
* systemMessage: `You are a customer support agent for ACME Corp.
|
|
107
|
+
*
|
|
108
|
+
* Company policies:
|
|
109
|
+
* - Always be polite and professional
|
|
110
|
+
* - Refer to knowledge base for product information
|
|
111
|
+
* - Escalate billing issues to human agents
|
|
112
|
+
* ... (extensive policies and guidelines)
|
|
113
|
+
* `,
|
|
114
|
+
* tools: [searchKnowledgeBase, createTicket, checkOrderStatus],
|
|
115
|
+
* middlewares: [
|
|
116
|
+
* anthropicPromptCachingMiddleware({
|
|
117
|
+
* ttl: "1h", // Long TTL for stable system prompt
|
|
118
|
+
* minMessagesToCache: 1 // Cache immediately due to large system prompt
|
|
119
|
+
* })
|
|
120
|
+
* ]
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @remarks
|
|
125
|
+
* - **Anthropic Only**: This middleware only works with Anthropic models and will throw an error if used with other providers
|
|
126
|
+
* - **Automatic Application**: Caching is applied automatically when message count exceeds `minMessagesToCache`
|
|
127
|
+
* - **Cache Scope**: Caches are isolated per API key and cannot be shared across different keys
|
|
128
|
+
* - **TTL Options**: Only supports "5m" (5 minutes) and "1h" (1 hour) as TTL values per Anthropic's API
|
|
129
|
+
* - **Best Use Cases**: Long system prompts, multi-turn conversations, repetitive queries, RAG applications
|
|
130
|
+
* - **Cost Impact**: Cached tokens are billed at 10% of the base input token price, cache writes are billed at 25% of the base
|
|
131
|
+
*
|
|
132
|
+
* @see {@link createAgent} for agent creation
|
|
133
|
+
* @see {@link https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching} Anthropic's prompt caching documentation
|
|
134
|
+
* @public
|
|
135
|
+
*/
|
|
136
|
+
declare function anthropicPromptCachingMiddleware(middlewareOptions?: Partial<z.infer<typeof contextSchema>>): AgentMiddleware<undefined, z.ZodObject<{
|
|
137
|
+
// Configuration options
|
|
138
|
+
enableCaching: z.ZodDefault<z.ZodBoolean>;
|
|
139
|
+
ttl: z.ZodDefault<z.ZodEnum<["5m", "1h"]>>;
|
|
140
|
+
minMessagesToCache: z.ZodDefault<z.ZodNumber>;
|
|
141
|
+
}, "strip", z.ZodTypeAny, {
|
|
142
|
+
enableCaching: boolean;
|
|
143
|
+
ttl: "1h" | "5m";
|
|
144
|
+
minMessagesToCache: number;
|
|
145
|
+
}, {
|
|
146
|
+
enableCaching?: boolean | undefined;
|
|
147
|
+
ttl?: "1h" | "5m" | undefined;
|
|
148
|
+
minMessagesToCache?: number | undefined;
|
|
149
|
+
}>, any>;
|
|
150
|
+
//#endregion
|
|
151
|
+
export { anthropicPromptCachingMiddleware };
|
|
152
|
+
//# sourceMappingURL=promptCaching.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promptCaching.d.ts","names":["z","contextSchema","ZodBoolean","ZodDefault","ZodEnum","ZodNumber","ZodTypeAny","ZodObject","anthropicPromptCachingMiddleware","infer","Partial","___types_js0","AgentMiddleware"],"sources":["../../../../src/agents/middlewareAgent/middlewares/promptCaching.d.ts"],"sourcesContent":["import { z } from \"zod\";\ndeclare const contextSchema: z.ZodObject<{\n // Configuration options\n enableCaching: z.ZodDefault<z.ZodBoolean>;\n ttl: z.ZodDefault<z.ZodEnum<[\"5m\", \"1h\"]>>;\n minMessagesToCache: z.ZodDefault<z.ZodNumber>;\n}, \"strip\", z.ZodTypeAny, {\n enableCaching: boolean;\n ttl: \"1h\" | \"5m\";\n minMessagesToCache: number;\n}, {\n enableCaching?: boolean | undefined;\n ttl?: \"1h\" | \"5m\" | undefined;\n minMessagesToCache?: number | undefined;\n}>;\n/**\n * Creates a prompt caching middleware for Anthropic models to optimize API usage.\n *\n * This middleware automatically adds cache control headers to messages when using Anthropic models,\n * enabling their prompt caching feature. This can significantly reduce costs and latency for\n * applications with repetitive prompts, long system messages, or extensive conversation histories.\n *\n * ## How It Works\n *\n * The middleware intercepts model requests and adds cache control metadata that tells Anthropic's\n * API to cache processed prompt prefixes. On subsequent requests with matching prefixes, the\n * cached representations are reused, skipping redundant token processing.\n *\n * ## Benefits\n *\n * - **Cost Reduction**: Avoid reprocessing the same tokens repeatedly (up to 90% savings on cached portions)\n * - **Lower Latency**: Cached prompts are processed faster as embeddings are pre-computed\n * - **Better Scalability**: Reduced computational load enables handling more requests\n * - **Consistent Performance**: Stable response times for repetitive queries\n *\n * @param middlewareOptions - Configuration options for the caching behavior\n * @param middlewareOptions.enableCaching - Whether to enable prompt caching (default: `true`)\n * @param middlewareOptions.ttl - Cache time-to-live: `\"5m\"` for 5 minutes or `\"1h\"` for 1 hour (default: `\"5m\"`)\n * @param middlewareOptions.minMessagesToCache - Minimum number of messages required before caching is applied (default: `3`)\n *\n * @returns A middleware instance that can be passed to `createAgent`\n *\n * @throws {Error} If used with non-Anthropic models\n *\n * @example\n * Basic usage with default settings\n * ```typescript\n * import { createAgent } from \"langchain\";\n * import { anthropicPromptCachingMiddleware } from \"langchain/middleware\";\n *\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * middlewares: [\n * anthropicPromptCachingMiddleware()\n * ]\n * });\n * ```\n *\n * @example\n * Custom configuration for longer conversations\n * ```typescript\n * const cachingMiddleware = anthropicPromptCachingMiddleware({\n * ttl: \"1h\", // Cache for 1 hour instead of default 5 minutes\n * minMessagesToCache: 5 // Only cache after 5 messages\n * });\n *\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * systemMessage: \"You are a helpful assistant with deep knowledge of...\", // Long system prompt\n * middlewares: [cachingMiddleware]\n * });\n * ```\n *\n * @example\n * Conditional caching based on runtime context\n * ```typescript\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * middlewares: [\n * anthropicPromptCachingMiddleware({\n * enableCaching: true,\n * ttl: \"5m\"\n * })\n * ]\n * });\n *\n * // Disable caching for specific requests\n * await agent.invoke(\n * { messages: [new HumanMessage(\"Process this without caching\")] },\n * {\n * configurable: {\n * middleware_context: { enableCaching: false }\n * }\n * }\n * );\n * ```\n *\n * @example\n * Optimal setup for customer support chatbot\n * ```typescript\n * const supportAgent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * systemMessage: `You are a customer support agent for ACME Corp.\n *\n * Company policies:\n * - Always be polite and professional\n * - Refer to knowledge base for product information\n * - Escalate billing issues to human agents\n * ... (extensive policies and guidelines)\n * `,\n * tools: [searchKnowledgeBase, createTicket, checkOrderStatus],\n * middlewares: [\n * anthropicPromptCachingMiddleware({\n * ttl: \"1h\", // Long TTL for stable system prompt\n * minMessagesToCache: 1 // Cache immediately due to large system prompt\n * })\n * ]\n * });\n * ```\n *\n * @remarks\n * - **Anthropic Only**: This middleware only works with Anthropic models and will throw an error if used with other providers\n * - **Automatic Application**: Caching is applied automatically when message count exceeds `minMessagesToCache`\n * - **Cache Scope**: Caches are isolated per API key and cannot be shared across different keys\n * - **TTL Options**: Only supports \"5m\" (5 minutes) and \"1h\" (1 hour) as TTL values per Anthropic's API\n * - **Best Use Cases**: Long system prompts, multi-turn conversations, repetitive queries, RAG applications\n * - **Cost Impact**: Cached tokens are billed at 10% of the base input token price, cache writes are billed at 25% of the base\n *\n * @see {@link createAgent} for agent creation\n * @see {@link https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching} Anthropic's prompt caching documentation\n * @public\n */\nexport declare function anthropicPromptCachingMiddleware(middlewareOptions?: Partial<z.infer<typeof contextSchema>>): import(\"../types.js\").AgentMiddleware<undefined, z.ZodObject<{\n // Configuration options\n enableCaching: z.ZodDefault<z.ZodBoolean>;\n ttl: z.ZodDefault<z.ZodEnum<[\"5m\", \"1h\"]>>;\n minMessagesToCache: z.ZodDefault<z.ZodNumber>;\n}, \"strip\", z.ZodTypeAny, {\n enableCaching: boolean;\n ttl: \"1h\" | \"5m\";\n minMessagesToCache: number;\n}, {\n enableCaching?: boolean | undefined;\n ttl?: \"1h\" | \"5m\" | undefined;\n minMessagesToCache?: number | undefined;\n}>, any>;\nexport {};\n"],"mappings":";;;;cACcC,eAAeD,CAAAA,CAAEO;;iBAEZP,CAAAA,CAAEG,WAAWH,CAAAA,CAAEE;EAFpBD,GAAAA,EAGLD,CAAAA,CAAEG,UAUT,CAVoBH,CAAAA,CAAEI,OAUtB,CAAA,CAAA,IAAA,EAAA,IAAA,CAAA,CAAA,CAAA;EAAA,kBAAA,EATsBJ,CAAAA,CAAEG,UASxB,CATmCH,CAAAA,CAAEK,SASrC,CAAA;CAAA,EAAA,OAXgCH,EAGtBF,CAAAA,CAAEM,UAHoBJ,EAAAA;EAAU,aAAvBC,EAAAA,OAAAA;EAAU,GACTH,EAAEI,IAAAA,GAAAA,IAAAA;EAAO,kBAApBD,EAAAA,MAAAA;CAAU,EAAA;EAC2B,aAAtBA,CAAAA,EAAAA,OAAAA,GAAAA,SAAAA;EAAU,GACxBH,CAAAA,EAAEM,IAAAA,GAAAA,IAAAA,GAAAA,SAAAA;EAAU,kBALOC,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;AAAS,CAAA,CAAA;AAmIxC;;;;;;;;;;;;;;AAA2J;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAnIC,gCAAAA,qBAAqDE,QAAQV,CAAAA,CAAES,aAAaR,kBAA8E,2BAAXD,CAAAA,CAAEO;;iBAEtJP,CAAAA,CAAEG,WAAWH,CAAAA,CAAEE;OACzBF,CAAAA,CAAEG,WAAWH,CAAAA,CAAEI;sBACAJ,CAAAA,CAAEG,WAAWH,CAAAA,CAAEK;YAC3BL,CAAAA,CAAEM"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { createMiddleware } from "../middleware.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/agents/middlewareAgent/middlewares/promptCaching.ts
|
|
5
|
+
const contextSchema = z.object({
|
|
6
|
+
enableCaching: z.boolean().default(true),
|
|
7
|
+
ttl: z.enum(["5m", "1h"]).default("5m"),
|
|
8
|
+
minMessagesToCache: z.number().default(3)
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Creates a prompt caching middleware for Anthropic models to optimize API usage.
|
|
12
|
+
*
|
|
13
|
+
* This middleware automatically adds cache control headers to messages when using Anthropic models,
|
|
14
|
+
* enabling their prompt caching feature. This can significantly reduce costs and latency for
|
|
15
|
+
* applications with repetitive prompts, long system messages, or extensive conversation histories.
|
|
16
|
+
*
|
|
17
|
+
* ## How It Works
|
|
18
|
+
*
|
|
19
|
+
* The middleware intercepts model requests and adds cache control metadata that tells Anthropic's
|
|
20
|
+
* API to cache processed prompt prefixes. On subsequent requests with matching prefixes, the
|
|
21
|
+
* cached representations are reused, skipping redundant token processing.
|
|
22
|
+
*
|
|
23
|
+
* ## Benefits
|
|
24
|
+
*
|
|
25
|
+
* - **Cost Reduction**: Avoid reprocessing the same tokens repeatedly (up to 90% savings on cached portions)
|
|
26
|
+
* - **Lower Latency**: Cached prompts are processed faster as embeddings are pre-computed
|
|
27
|
+
* - **Better Scalability**: Reduced computational load enables handling more requests
|
|
28
|
+
* - **Consistent Performance**: Stable response times for repetitive queries
|
|
29
|
+
*
|
|
30
|
+
* @param middlewareOptions - Configuration options for the caching behavior
|
|
31
|
+
* @param middlewareOptions.enableCaching - Whether to enable prompt caching (default: `true`)
|
|
32
|
+
* @param middlewareOptions.ttl - Cache time-to-live: `"5m"` for 5 minutes or `"1h"` for 1 hour (default: `"5m"`)
|
|
33
|
+
* @param middlewareOptions.minMessagesToCache - Minimum number of messages required before caching is applied (default: `3`)
|
|
34
|
+
*
|
|
35
|
+
* @returns A middleware instance that can be passed to `createAgent`
|
|
36
|
+
*
|
|
37
|
+
* @throws {Error} If used with non-Anthropic models
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* Basic usage with default settings
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { createAgent } from "langchain";
|
|
43
|
+
* import { anthropicPromptCachingMiddleware } from "langchain/middleware";
|
|
44
|
+
*
|
|
45
|
+
* const agent = createAgent({
|
|
46
|
+
* model: "anthropic:claude-3-5-sonnet",
|
|
47
|
+
* middlewares: [
|
|
48
|
+
* anthropicPromptCachingMiddleware()
|
|
49
|
+
* ]
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* Custom configuration for longer conversations
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const cachingMiddleware = anthropicPromptCachingMiddleware({
|
|
57
|
+
* ttl: "1h", // Cache for 1 hour instead of default 5 minutes
|
|
58
|
+
* minMessagesToCache: 5 // Only cache after 5 messages
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* const agent = createAgent({
|
|
62
|
+
* model: "anthropic:claude-3-5-sonnet",
|
|
63
|
+
* systemMessage: "You are a helpful assistant with deep knowledge of...", // Long system prompt
|
|
64
|
+
* middlewares: [cachingMiddleware]
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* Conditional caching based on runtime context
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const agent = createAgent({
|
|
72
|
+
* model: "anthropic:claude-3-5-sonnet",
|
|
73
|
+
* middlewares: [
|
|
74
|
+
* anthropicPromptCachingMiddleware({
|
|
75
|
+
* enableCaching: true,
|
|
76
|
+
* ttl: "5m"
|
|
77
|
+
* })
|
|
78
|
+
* ]
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* // Disable caching for specific requests
|
|
82
|
+
* await agent.invoke(
|
|
83
|
+
* { messages: [new HumanMessage("Process this without caching")] },
|
|
84
|
+
* {
|
|
85
|
+
* configurable: {
|
|
86
|
+
* middleware_context: { enableCaching: false }
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
* );
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* Optimal setup for customer support chatbot
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const supportAgent = createAgent({
|
|
96
|
+
* model: "anthropic:claude-3-5-sonnet",
|
|
97
|
+
* systemMessage: `You are a customer support agent for ACME Corp.
|
|
98
|
+
*
|
|
99
|
+
* Company policies:
|
|
100
|
+
* - Always be polite and professional
|
|
101
|
+
* - Refer to knowledge base for product information
|
|
102
|
+
* - Escalate billing issues to human agents
|
|
103
|
+
* ... (extensive policies and guidelines)
|
|
104
|
+
* `,
|
|
105
|
+
* tools: [searchKnowledgeBase, createTicket, checkOrderStatus],
|
|
106
|
+
* middlewares: [
|
|
107
|
+
* anthropicPromptCachingMiddleware({
|
|
108
|
+
* ttl: "1h", // Long TTL for stable system prompt
|
|
109
|
+
* minMessagesToCache: 1 // Cache immediately due to large system prompt
|
|
110
|
+
* })
|
|
111
|
+
* ]
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* - **Anthropic Only**: This middleware only works with Anthropic models and will throw an error if used with other providers
|
|
117
|
+
* - **Automatic Application**: Caching is applied automatically when message count exceeds `minMessagesToCache`
|
|
118
|
+
* - **Cache Scope**: Caches are isolated per API key and cannot be shared across different keys
|
|
119
|
+
* - **TTL Options**: Only supports "5m" (5 minutes) and "1h" (1 hour) as TTL values per Anthropic's API
|
|
120
|
+
* - **Best Use Cases**: Long system prompts, multi-turn conversations, repetitive queries, RAG applications
|
|
121
|
+
* - **Cost Impact**: Cached tokens are billed at 10% of the base input token price, cache writes are billed at 25% of the base
|
|
122
|
+
*
|
|
123
|
+
* @see {@link createAgent} for agent creation
|
|
124
|
+
* @see {@link https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching} Anthropic's prompt caching documentation
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
function anthropicPromptCachingMiddleware(middlewareOptions) {
|
|
128
|
+
return createMiddleware({
|
|
129
|
+
name: "PromptCachingMiddleware",
|
|
130
|
+
contextSchema,
|
|
131
|
+
prepareModelRequest: (options, state, runtime) => {
|
|
132
|
+
const enableCaching = runtime.context.enableCaching ?? middlewareOptions?.enableCaching;
|
|
133
|
+
const ttl = runtime.context.ttl ?? middlewareOptions?.ttl;
|
|
134
|
+
const minMessagesToCache = runtime.context.minMessagesToCache ?? middlewareOptions?.minMessagesToCache;
|
|
135
|
+
if (!enableCaching) return void 0;
|
|
136
|
+
if (options.model?.getName() !== "anthropic") throw new Error("Prompt caching is only supported for Anthropic models");
|
|
137
|
+
const messagesCount = state.messages.length + (options.systemMessage ? 1 : 0);
|
|
138
|
+
if (messagesCount < minMessagesToCache) return options;
|
|
139
|
+
return {
|
|
140
|
+
...options,
|
|
141
|
+
modelSettings: { cache_control: {
|
|
142
|
+
type: "ephemeral",
|
|
143
|
+
ttl
|
|
144
|
+
} }
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
export { anthropicPromptCachingMiddleware };
|
|
152
|
+
//# sourceMappingURL=promptCaching.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promptCaching.js","names":["middlewareOptions?: Partial<z.infer<typeof contextSchema>>"],"sources":["../../../../src/agents/middlewareAgent/middlewares/promptCaching.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { createMiddleware } from \"../middleware.js\";\n\nconst contextSchema = z.object({\n // Configuration options\n enableCaching: z.boolean().default(true),\n ttl: z.enum([\"5m\", \"1h\"]).default(\"5m\"),\n minMessagesToCache: z.number().default(3),\n});\n\n/**\n * Creates a prompt caching middleware for Anthropic models to optimize API usage.\n *\n * This middleware automatically adds cache control headers to messages when using Anthropic models,\n * enabling their prompt caching feature. This can significantly reduce costs and latency for\n * applications with repetitive prompts, long system messages, or extensive conversation histories.\n *\n * ## How It Works\n *\n * The middleware intercepts model requests and adds cache control metadata that tells Anthropic's\n * API to cache processed prompt prefixes. On subsequent requests with matching prefixes, the\n * cached representations are reused, skipping redundant token processing.\n *\n * ## Benefits\n *\n * - **Cost Reduction**: Avoid reprocessing the same tokens repeatedly (up to 90% savings on cached portions)\n * - **Lower Latency**: Cached prompts are processed faster as embeddings are pre-computed\n * - **Better Scalability**: Reduced computational load enables handling more requests\n * - **Consistent Performance**: Stable response times for repetitive queries\n *\n * @param middlewareOptions - Configuration options for the caching behavior\n * @param middlewareOptions.enableCaching - Whether to enable prompt caching (default: `true`)\n * @param middlewareOptions.ttl - Cache time-to-live: `\"5m\"` for 5 minutes or `\"1h\"` for 1 hour (default: `\"5m\"`)\n * @param middlewareOptions.minMessagesToCache - Minimum number of messages required before caching is applied (default: `3`)\n *\n * @returns A middleware instance that can be passed to `createAgent`\n *\n * @throws {Error} If used with non-Anthropic models\n *\n * @example\n * Basic usage with default settings\n * ```typescript\n * import { createAgent } from \"langchain\";\n * import { anthropicPromptCachingMiddleware } from \"langchain/middleware\";\n *\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * middlewares: [\n * anthropicPromptCachingMiddleware()\n * ]\n * });\n * ```\n *\n * @example\n * Custom configuration for longer conversations\n * ```typescript\n * const cachingMiddleware = anthropicPromptCachingMiddleware({\n * ttl: \"1h\", // Cache for 1 hour instead of default 5 minutes\n * minMessagesToCache: 5 // Only cache after 5 messages\n * });\n *\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * systemMessage: \"You are a helpful assistant with deep knowledge of...\", // Long system prompt\n * middlewares: [cachingMiddleware]\n * });\n * ```\n *\n * @example\n * Conditional caching based on runtime context\n * ```typescript\n * const agent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * middlewares: [\n * anthropicPromptCachingMiddleware({\n * enableCaching: true,\n * ttl: \"5m\"\n * })\n * ]\n * });\n *\n * // Disable caching for specific requests\n * await agent.invoke(\n * { messages: [new HumanMessage(\"Process this without caching\")] },\n * {\n * configurable: {\n * middleware_context: { enableCaching: false }\n * }\n * }\n * );\n * ```\n *\n * @example\n * Optimal setup for customer support chatbot\n * ```typescript\n * const supportAgent = createAgent({\n * model: \"anthropic:claude-3-5-sonnet\",\n * systemMessage: `You are a customer support agent for ACME Corp.\n *\n * Company policies:\n * - Always be polite and professional\n * - Refer to knowledge base for product information\n * - Escalate billing issues to human agents\n * ... (extensive policies and guidelines)\n * `,\n * tools: [searchKnowledgeBase, createTicket, checkOrderStatus],\n * middlewares: [\n * anthropicPromptCachingMiddleware({\n * ttl: \"1h\", // Long TTL for stable system prompt\n * minMessagesToCache: 1 // Cache immediately due to large system prompt\n * })\n * ]\n * });\n * ```\n *\n * @remarks\n * - **Anthropic Only**: This middleware only works with Anthropic models and will throw an error if used with other providers\n * - **Automatic Application**: Caching is applied automatically when message count exceeds `minMessagesToCache`\n * - **Cache Scope**: Caches are isolated per API key and cannot be shared across different keys\n * - **TTL Options**: Only supports \"5m\" (5 minutes) and \"1h\" (1 hour) as TTL values per Anthropic's API\n * - **Best Use Cases**: Long system prompts, multi-turn conversations, repetitive queries, RAG applications\n * - **Cost Impact**: Cached tokens are billed at 10% of the base input token price, cache writes are billed at 25% of the base\n *\n * @see {@link createAgent} for agent creation\n * @see {@link https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching} Anthropic's prompt caching documentation\n * @public\n */\nexport function anthropicPromptCachingMiddleware(\n middlewareOptions?: Partial<z.infer<typeof contextSchema>>\n) {\n return createMiddleware({\n name: \"PromptCachingMiddleware\",\n contextSchema,\n prepareModelRequest: (options, state, runtime) => {\n const enableCaching =\n runtime.context.enableCaching ?? middlewareOptions?.enableCaching;\n const ttl = runtime.context.ttl ?? middlewareOptions?.ttl;\n const minMessagesToCache =\n runtime.context.minMessagesToCache ??\n middlewareOptions?.minMessagesToCache;\n\n // Skip if caching is disabled\n if (!enableCaching) {\n return undefined;\n }\n\n if (options.model?.getName() !== \"anthropic\") {\n throw new Error(\n \"Prompt caching is only supported for Anthropic models\"\n );\n }\n\n const messagesCount =\n state.messages.length + (options.systemMessage ? 1 : 0);\n\n if (messagesCount < minMessagesToCache) {\n return options;\n }\n\n return {\n ...options,\n modelSettings: {\n cache_control: {\n type: \"ephemeral\",\n ttl,\n },\n },\n };\n },\n });\n}\n"],"mappings":";;;;AAGA,MAAM,gBAAgB,EAAE,OAAO;CAE7B,eAAe,EAAE,SAAS,CAAC,QAAQ,KAAK;CACxC,KAAK,EAAE,KAAK,CAAC,MAAM,IAAK,EAAC,CAAC,QAAQ,KAAK;CACvC,oBAAoB,EAAE,QAAQ,CAAC,QAAQ,EAAE;AAC1C,EAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuHF,SAAgB,iCACdA,mBACA;AACA,QAAO,iBAAiB;EACtB,MAAM;EACN;EACA,qBAAqB,CAAC,SAAS,OAAO,YAAY;GAChD,MAAM,gBACJ,QAAQ,QAAQ,iBAAiB,mBAAmB;GACtD,MAAM,MAAM,QAAQ,QAAQ,OAAO,mBAAmB;GACtD,MAAM,qBACJ,QAAQ,QAAQ,sBAChB,mBAAmB;AAGrB,OAAI,CAAC,cACH,QAAO;AAGT,OAAI,QAAQ,OAAO,SAAS,KAAK,YAC/B,OAAM,IAAI,MACR;GAIJ,MAAM,gBACJ,MAAM,SAAS,UAAU,QAAQ,gBAAgB,IAAI;AAEvD,OAAI,gBAAgB,mBAClB,QAAO;AAGT,UAAO;IACL,GAAG;IACH,eAAe,EACb,eAAe;KACb,MAAM;KACN;IACD,EACF;GACF;EACF;CACF,EAAC;AACH"}
|