@agentforge/core 0.11.7 → 0.11.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +68 -0
- package/dist/index.d.cts +108 -1
- package/dist/index.d.ts +108 -1
- package/dist/index.js +65 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -124,6 +124,7 @@ __export(index_exports, {
|
|
|
124
124
|
isHumanRequestInterrupt: () => isHumanRequestInterrupt,
|
|
125
125
|
isMemoryCheckpointer: () => isMemoryCheckpointer,
|
|
126
126
|
isTracingEnabled: () => isTracingEnabled,
|
|
127
|
+
loadPrompt: () => loadPrompt,
|
|
127
128
|
map: () => map,
|
|
128
129
|
merge: () => merge,
|
|
129
130
|
mergeState: () => mergeState,
|
|
@@ -132,8 +133,10 @@ __export(index_exports, {
|
|
|
132
133
|
presets: () => presets,
|
|
133
134
|
production: () => production,
|
|
134
135
|
reduce: () => reduce,
|
|
136
|
+
renderTemplate: () => renderTemplate,
|
|
135
137
|
retry: () => retry,
|
|
136
138
|
safeValidateSchemaDescriptions: () => safeValidateSchemaDescriptions,
|
|
139
|
+
sanitizeValue: () => sanitizeValue,
|
|
137
140
|
sendMessage: () => sendMessage,
|
|
138
141
|
sequential: () => sequential,
|
|
139
142
|
sequentialBuilder: () => sequentialBuilder,
|
|
@@ -4930,6 +4933,68 @@ var CircuitBreaker = class {
|
|
|
4930
4933
|
function createCircuitBreaker(options) {
|
|
4931
4934
|
return new CircuitBreaker(options);
|
|
4932
4935
|
}
|
|
4936
|
+
|
|
4937
|
+
// src/prompt-loader/index.ts
|
|
4938
|
+
var import_fs = require("fs");
|
|
4939
|
+
var import_path = require("path");
|
|
4940
|
+
var MAX_VARIABLE_LENGTH = 500;
|
|
4941
|
+
function sanitizeValue(value) {
|
|
4942
|
+
if (value === void 0 || value === null) return "";
|
|
4943
|
+
let sanitized = String(value);
|
|
4944
|
+
sanitized = sanitized.replace(/^#+\s*/gm, "");
|
|
4945
|
+
sanitized = sanitized.replace(/[\r\n]+/g, " ");
|
|
4946
|
+
sanitized = sanitized.trim().replace(/\s+/g, " ");
|
|
4947
|
+
if (sanitized.length > MAX_VARIABLE_LENGTH) {
|
|
4948
|
+
sanitized = sanitized.substring(0, MAX_VARIABLE_LENGTH) + "...";
|
|
4949
|
+
}
|
|
4950
|
+
return sanitized;
|
|
4951
|
+
}
|
|
4952
|
+
function renderTemplate(template, options) {
|
|
4953
|
+
let rawVariables;
|
|
4954
|
+
let sanitizedVariables;
|
|
4955
|
+
if ("trustedVariables" in options || "untrustedVariables" in options) {
|
|
4956
|
+
const opts = options;
|
|
4957
|
+
rawVariables = {
|
|
4958
|
+
...opts.trustedVariables,
|
|
4959
|
+
...opts.untrustedVariables
|
|
4960
|
+
};
|
|
4961
|
+
const sanitizedUntrusted = {};
|
|
4962
|
+
if (opts.untrustedVariables) {
|
|
4963
|
+
for (const [key, value] of Object.entries(opts.untrustedVariables)) {
|
|
4964
|
+
sanitizedUntrusted[key] = sanitizeValue(value);
|
|
4965
|
+
}
|
|
4966
|
+
}
|
|
4967
|
+
sanitizedVariables = {
|
|
4968
|
+
...opts.trustedVariables,
|
|
4969
|
+
...sanitizedUntrusted
|
|
4970
|
+
};
|
|
4971
|
+
} else {
|
|
4972
|
+
rawVariables = options;
|
|
4973
|
+
sanitizedVariables = options;
|
|
4974
|
+
}
|
|
4975
|
+
let result = template;
|
|
4976
|
+
result = result.replace(/\{\{#if\s+(\w+)\}\}([\s\S]*?)\{\{\/if\}\}/g, (_, varName, content) => {
|
|
4977
|
+
return rawVariables[varName] ? content : "";
|
|
4978
|
+
});
|
|
4979
|
+
result = result.replace(/\{\{(\w+)\}\}/g, (_, varName) => {
|
|
4980
|
+
const value = sanitizedVariables[varName];
|
|
4981
|
+
if (value === void 0 || value === null) return "";
|
|
4982
|
+
return String(value);
|
|
4983
|
+
});
|
|
4984
|
+
return result;
|
|
4985
|
+
}
|
|
4986
|
+
function loadPrompt(promptName, options = {}, promptsDir) {
|
|
4987
|
+
const baseDir = promptsDir || (0, import_path.join)(process.cwd(), "prompts");
|
|
4988
|
+
const promptPath = (0, import_path.join)(baseDir, `${promptName}.md`);
|
|
4989
|
+
try {
|
|
4990
|
+
const template = (0, import_fs.readFileSync)(promptPath, "utf-8");
|
|
4991
|
+
return renderTemplate(template, options);
|
|
4992
|
+
} catch (error) {
|
|
4993
|
+
throw new Error(
|
|
4994
|
+
`Failed to load prompt "${promptName}" from ${promptPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
4995
|
+
);
|
|
4996
|
+
}
|
|
4997
|
+
}
|
|
4933
4998
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4934
4999
|
0 && (module.exports = {
|
|
4935
5000
|
AgentError,
|
|
@@ -5026,6 +5091,7 @@ function createCircuitBreaker(options) {
|
|
|
5026
5091
|
isHumanRequestInterrupt,
|
|
5027
5092
|
isMemoryCheckpointer,
|
|
5028
5093
|
isTracingEnabled,
|
|
5094
|
+
loadPrompt,
|
|
5029
5095
|
map,
|
|
5030
5096
|
merge,
|
|
5031
5097
|
mergeState,
|
|
@@ -5034,8 +5100,10 @@ function createCircuitBreaker(options) {
|
|
|
5034
5100
|
presets,
|
|
5035
5101
|
production,
|
|
5036
5102
|
reduce,
|
|
5103
|
+
renderTemplate,
|
|
5037
5104
|
retry,
|
|
5038
5105
|
safeValidateSchemaDescriptions,
|
|
5106
|
+
sanitizeValue,
|
|
5039
5107
|
sendMessage,
|
|
5040
5108
|
sequential,
|
|
5041
5109
|
sequentialBuilder,
|
package/dist/index.d.cts
CHANGED
|
@@ -5157,4 +5157,111 @@ declare class CircuitBreaker {
|
|
|
5157
5157
|
}
|
|
5158
5158
|
declare function createCircuitBreaker(options: CircuitBreakerOptions): CircuitBreaker;
|
|
5159
5159
|
|
|
5160
|
-
|
|
5160
|
+
/**
|
|
5161
|
+
* Prompt Template Loader
|
|
5162
|
+
*
|
|
5163
|
+
* Utility for loading and rendering prompt templates from .md files.
|
|
5164
|
+
* Supports variable substitution and conditional blocks.
|
|
5165
|
+
*
|
|
5166
|
+
* SECURITY: This module includes protection against prompt injection attacks
|
|
5167
|
+
* by sanitizing variable values before substitution.
|
|
5168
|
+
*/
|
|
5169
|
+
/**
|
|
5170
|
+
* Options for rendering templates with security controls
|
|
5171
|
+
*/
|
|
5172
|
+
interface RenderTemplateOptions {
|
|
5173
|
+
/**
|
|
5174
|
+
* Variables from trusted sources (config files, hardcoded values)
|
|
5175
|
+
* These will NOT be sanitized
|
|
5176
|
+
*/
|
|
5177
|
+
trustedVariables?: Record<string, any>;
|
|
5178
|
+
/**
|
|
5179
|
+
* Variables from untrusted sources (user input, API calls, databases)
|
|
5180
|
+
* These WILL be sanitized to prevent prompt injection
|
|
5181
|
+
*/
|
|
5182
|
+
untrustedVariables?: Record<string, any>;
|
|
5183
|
+
}
|
|
5184
|
+
/**
|
|
5185
|
+
* Sanitize a value to prevent prompt injection attacks
|
|
5186
|
+
*
|
|
5187
|
+
* Protections:
|
|
5188
|
+
* - Removes markdown headers (prevents structure hijacking)
|
|
5189
|
+
* - Removes newlines (prevents multi-line injection)
|
|
5190
|
+
* - Limits length (prevents prompt bloat)
|
|
5191
|
+
*
|
|
5192
|
+
* @param value - The value to sanitize
|
|
5193
|
+
* @returns Sanitized string safe for use in prompts
|
|
5194
|
+
*/
|
|
5195
|
+
declare function sanitizeValue(value: any): string;
|
|
5196
|
+
/**
|
|
5197
|
+
* Render a template string with variable substitution
|
|
5198
|
+
*
|
|
5199
|
+
* Supports:
|
|
5200
|
+
* - Simple variables: {{variableName}}
|
|
5201
|
+
* - Conditional blocks: {{#if variableName}}...{{/if}}
|
|
5202
|
+
*
|
|
5203
|
+
* SECURITY: Distinguishes between trusted and untrusted variables.
|
|
5204
|
+
* - Trusted variables (from config) are used as-is
|
|
5205
|
+
* - Untrusted variables (from user input) are sanitized
|
|
5206
|
+
*
|
|
5207
|
+
* @param template - Template string with {{variable}} placeholders
|
|
5208
|
+
* @param options - Variables and security options
|
|
5209
|
+
* @returns Rendered template string
|
|
5210
|
+
*
|
|
5211
|
+
* @example
|
|
5212
|
+
* ```typescript
|
|
5213
|
+
* // Safe: Trusted variables from config
|
|
5214
|
+
* const result = renderTemplate(template, {
|
|
5215
|
+
* trustedVariables: {
|
|
5216
|
+
* companyName: 'Acme Corp', // From config file
|
|
5217
|
+
* premium: true
|
|
5218
|
+
* }
|
|
5219
|
+
* });
|
|
5220
|
+
*
|
|
5221
|
+
* // Safe: Untrusted variables are sanitized
|
|
5222
|
+
* const result = renderTemplate(template, {
|
|
5223
|
+
* untrustedVariables: {
|
|
5224
|
+
* userName: req.body.name, // User input - will be sanitized
|
|
5225
|
+
* }
|
|
5226
|
+
* });
|
|
5227
|
+
*
|
|
5228
|
+
* // Mixed: Some trusted, some untrusted
|
|
5229
|
+
* const result = renderTemplate(template, {
|
|
5230
|
+
* trustedVariables: {
|
|
5231
|
+
* companyName: 'Acme Corp', // From config
|
|
5232
|
+
* },
|
|
5233
|
+
* untrustedVariables: {
|
|
5234
|
+
* userName: req.body.name, // User input
|
|
5235
|
+
* }
|
|
5236
|
+
* });
|
|
5237
|
+
* ```
|
|
5238
|
+
*/
|
|
5239
|
+
declare function renderTemplate(template: string, options: RenderTemplateOptions | Record<string, any>): string;
|
|
5240
|
+
/**
|
|
5241
|
+
* Load and render a prompt template from a .md file
|
|
5242
|
+
*
|
|
5243
|
+
* Looks for prompts in a `prompts/` directory relative to the caller's location.
|
|
5244
|
+
*
|
|
5245
|
+
* @param promptName - Name of the prompt file (without .md extension)
|
|
5246
|
+
* @param options - Variables and security options
|
|
5247
|
+
* @param promptsDir - Optional custom prompts directory path
|
|
5248
|
+
* @returns Rendered prompt string
|
|
5249
|
+
*
|
|
5250
|
+
* @example
|
|
5251
|
+
* ```typescript
|
|
5252
|
+
* // Backwards compatible: all variables treated as trusted
|
|
5253
|
+
* loadPrompt('system', { companyName: 'Acme' });
|
|
5254
|
+
*
|
|
5255
|
+
* // Explicit: separate trusted and untrusted
|
|
5256
|
+
* loadPrompt('system', {
|
|
5257
|
+
* trustedVariables: { companyName: 'Acme' },
|
|
5258
|
+
* untrustedVariables: { userName: userInput }
|
|
5259
|
+
* });
|
|
5260
|
+
*
|
|
5261
|
+
* // Custom prompts directory
|
|
5262
|
+
* loadPrompt('system', { companyName: 'Acme' }, '/path/to/prompts');
|
|
5263
|
+
* ```
|
|
5264
|
+
*/
|
|
5265
|
+
declare function loadPrompt(promptName: string, options?: RenderTemplateOptions | Record<string, any>, promptsDir?: string): string;
|
|
5266
|
+
|
|
5267
|
+
export { AgentError, type AgentResumedEventData, type AgentWaitingEventData, type AggregateNode, type AnyInterrupt, type ApprovalRequiredInterrupt, type BackoffStrategy, type BatchOptions, BatchProcessor, type BatchProcessorOptions, type BatchStats, type CacheKeyGenerator, type CachingOptions, type CheckInterruptOptions, type CheckpointHistoryOptions, type CheckpointerOptions, type ChunkOptions, CircuitBreaker, type CircuitBreakerOptions, type CircuitBreakerStats, type CircuitState, type ComposeGraphsOptions, type ComposeOptions, type ComposeToolConfig, type ComposedTool, type ConcurrencyOptions, type ConditionalConfig, type ConditionalRouter, type ConditionalRouterConfig, ConnectionPool, type ConnectionPoolOptions, type ConversationConfig, type CustomInterrupt, type DatabaseConfig, type DatabaseConnection, DatabasePool, type DatabasePoolOptions, type DevelopmentPresetOptions, type ErrorContext, type ErrorHandlerOptions, type ErrorReporter, type ErrorReporterOptions, type EventHandler, type EvictionStrategy, type ExecutionMetrics, type HealthCheckConfig, type HealthCheckResult, type HttpClient, type HttpConfig, HttpPool, type HttpPoolConfig, type HttpPoolOptions, type HttpResponse, type HumanInLoopEventData, type HumanInLoopEventType, type HumanRequest, type HumanRequestEventData, type HumanRequestInterrupt, type HumanRequestPriority, type HumanRequestStatus, type HumanResponseEventData, type InterruptData, type InterruptEventData, type InterruptType, type LangSmithConfig, type LogEntry, LogLevel, type Logger, type LoggerOptions, type LoggingOptions, ManagedTool, type ManagedToolConfig, type ManagedToolStats, MemoryManager, type MemoryManagerOptions, type MemoryStats, type MetricEntry, MetricType, type Metrics, type MetricsNodeOptions, type Middleware, MiddlewareChain, type MiddlewareContext, type MiddlewareFactory, type MiddlewareMetadata, type MiddlewareWithMetadata, MissingDescriptionError, type MockToolConfig, type MockToolResponse, type NodeFunction, type NodeFunctionWithContext, type ParallelNode, type ParallelWorkflowConfig, type ParallelWorkflowOptions, type PoolConfig, type PoolStats, type Priority$1 as Priority, type ProductionPresetOptions, type Progress, type ProgressTracker, type ProgressTrackerOptions, type PromptOptions, type RateLimitOptions, type RateLimitStrategy, type ReducerFunction, RegistryEvent, type RenderTemplateOptions, type RequestConfig, type ResumeCommand, type ResumeEventData, type ResumeOptions, type RetryOptions, type RetryPolicy, type RouteCondition, type RouteMap, type RouteName, type SSEEvent, type SSEFormatter, type SSEFormatterOptions, type SequentialNode, type SequentialWorkflowOptions, type SimpleMiddleware, type SqliteCheckpointerOptions, type StateChannelConfig, type SubgraphBuilder, type TestingPresetOptions, type ThreadConfig, type ThreadInfo, type ThreadStatus, type ThrottleOptions, TimeoutError, type TimeoutOptions, type Timer, type Tool, type BackoffStrategy$1 as ToolBackoffStrategy, ToolBuilder, ToolCategory, ToolCategorySchema, type ToolExample, ToolExampleSchema, type ToolExecution, type ToolExecutorConfig, type ToolInvocation, type ToolMetadata, ToolMetadataSchema, ToolNameSchema, ToolRegistry, type ToolRelations, ToolRelationsSchema, type ToolSimulatorConfig, type TracingOptions, type ValidationErrorHandler, type ValidationMode, type ValidationOptions, type ValidatorFunction, type WebSocketHandlerOptions, type WebSocketMessage, batch, broadcast, cache, chain, chunk, clearThread, collect, compose, composeGraphs, composeTool, composeWithOptions, conditional, configureLangSmith, createApprovalRequiredInterrupt, createBatchProcessor, createBinaryRouter, createCircuitBreaker, createConditionalRouter, createConnectionPool, createConversationConfig, createCustomInterrupt, createDatabasePool, createErrorReporter, createHeartbeat, createHttpPool, createHumanRequestInterrupt, createLogger, createManagedTool, createMemoryCheckpointer, createMemoryManager, createMessage, createMetrics, createMiddlewareContext, createMockTool, createMultiRouter, createParallelWorkflow, createProgressTracker, createSSEFormatter, createSequentialWorkflow, createSharedCache, createSharedConcurrencyController, createSharedRateLimiter, createSqliteCheckpointer, createStateAnnotation, createSubgraph, createThreadConfig, createTool, createToolExecutor, createToolSimulator, createToolUnsafe, createWebSocketHandler, development, filter, formatAgentResumedEvent, formatAgentWaitingEvent, formatHumanRequestEvent, formatHumanResponseEvent, formatInterruptEvent, formatResumeEvent, generateThreadId, getCheckpointHistory, getLangSmithConfig, getLatestCheckpoint, getMissingDescriptions, getThreadStatus, getToolDescription, getToolJsonSchema, isApprovalRequiredInterrupt, isCustomInterrupt, isHumanRequestInterrupt, isMemoryCheckpointer, isTracingEnabled, loadPrompt, map, merge, mergeState, parallel, parseSSEEvent, presets, production, reduce, renderTemplate, retry, safeValidateSchemaDescriptions, sanitizeValue, sendMessage, sequential, sequentialBuilder, take, testing, throttle, timeout, toLangChainTool, toLangChainTools, toolBuilder, validateSchemaDescriptions, validateState, validateTool, validateToolMetadata, validateToolName, withCache, withConcurrency, withErrorHandler, withLogging, withMetrics, withRateLimit, withRetry, withTimeout, withTracing, withValidation };
|
package/dist/index.d.ts
CHANGED
|
@@ -5157,4 +5157,111 @@ declare class CircuitBreaker {
|
|
|
5157
5157
|
}
|
|
5158
5158
|
declare function createCircuitBreaker(options: CircuitBreakerOptions): CircuitBreaker;
|
|
5159
5159
|
|
|
5160
|
-
|
|
5160
|
+
/**
|
|
5161
|
+
* Prompt Template Loader
|
|
5162
|
+
*
|
|
5163
|
+
* Utility for loading and rendering prompt templates from .md files.
|
|
5164
|
+
* Supports variable substitution and conditional blocks.
|
|
5165
|
+
*
|
|
5166
|
+
* SECURITY: This module includes protection against prompt injection attacks
|
|
5167
|
+
* by sanitizing variable values before substitution.
|
|
5168
|
+
*/
|
|
5169
|
+
/**
|
|
5170
|
+
* Options for rendering templates with security controls
|
|
5171
|
+
*/
|
|
5172
|
+
interface RenderTemplateOptions {
|
|
5173
|
+
/**
|
|
5174
|
+
* Variables from trusted sources (config files, hardcoded values)
|
|
5175
|
+
* These will NOT be sanitized
|
|
5176
|
+
*/
|
|
5177
|
+
trustedVariables?: Record<string, any>;
|
|
5178
|
+
/**
|
|
5179
|
+
* Variables from untrusted sources (user input, API calls, databases)
|
|
5180
|
+
* These WILL be sanitized to prevent prompt injection
|
|
5181
|
+
*/
|
|
5182
|
+
untrustedVariables?: Record<string, any>;
|
|
5183
|
+
}
|
|
5184
|
+
/**
|
|
5185
|
+
* Sanitize a value to prevent prompt injection attacks
|
|
5186
|
+
*
|
|
5187
|
+
* Protections:
|
|
5188
|
+
* - Removes markdown headers (prevents structure hijacking)
|
|
5189
|
+
* - Removes newlines (prevents multi-line injection)
|
|
5190
|
+
* - Limits length (prevents prompt bloat)
|
|
5191
|
+
*
|
|
5192
|
+
* @param value - The value to sanitize
|
|
5193
|
+
* @returns Sanitized string safe for use in prompts
|
|
5194
|
+
*/
|
|
5195
|
+
declare function sanitizeValue(value: any): string;
|
|
5196
|
+
/**
|
|
5197
|
+
* Render a template string with variable substitution
|
|
5198
|
+
*
|
|
5199
|
+
* Supports:
|
|
5200
|
+
* - Simple variables: {{variableName}}
|
|
5201
|
+
* - Conditional blocks: {{#if variableName}}...{{/if}}
|
|
5202
|
+
*
|
|
5203
|
+
* SECURITY: Distinguishes between trusted and untrusted variables.
|
|
5204
|
+
* - Trusted variables (from config) are used as-is
|
|
5205
|
+
* - Untrusted variables (from user input) are sanitized
|
|
5206
|
+
*
|
|
5207
|
+
* @param template - Template string with {{variable}} placeholders
|
|
5208
|
+
* @param options - Variables and security options
|
|
5209
|
+
* @returns Rendered template string
|
|
5210
|
+
*
|
|
5211
|
+
* @example
|
|
5212
|
+
* ```typescript
|
|
5213
|
+
* // Safe: Trusted variables from config
|
|
5214
|
+
* const result = renderTemplate(template, {
|
|
5215
|
+
* trustedVariables: {
|
|
5216
|
+
* companyName: 'Acme Corp', // From config file
|
|
5217
|
+
* premium: true
|
|
5218
|
+
* }
|
|
5219
|
+
* });
|
|
5220
|
+
*
|
|
5221
|
+
* // Safe: Untrusted variables are sanitized
|
|
5222
|
+
* const result = renderTemplate(template, {
|
|
5223
|
+
* untrustedVariables: {
|
|
5224
|
+
* userName: req.body.name, // User input - will be sanitized
|
|
5225
|
+
* }
|
|
5226
|
+
* });
|
|
5227
|
+
*
|
|
5228
|
+
* // Mixed: Some trusted, some untrusted
|
|
5229
|
+
* const result = renderTemplate(template, {
|
|
5230
|
+
* trustedVariables: {
|
|
5231
|
+
* companyName: 'Acme Corp', // From config
|
|
5232
|
+
* },
|
|
5233
|
+
* untrustedVariables: {
|
|
5234
|
+
* userName: req.body.name, // User input
|
|
5235
|
+
* }
|
|
5236
|
+
* });
|
|
5237
|
+
* ```
|
|
5238
|
+
*/
|
|
5239
|
+
declare function renderTemplate(template: string, options: RenderTemplateOptions | Record<string, any>): string;
|
|
5240
|
+
/**
|
|
5241
|
+
* Load and render a prompt template from a .md file
|
|
5242
|
+
*
|
|
5243
|
+
* Looks for prompts in a `prompts/` directory relative to the caller's location.
|
|
5244
|
+
*
|
|
5245
|
+
* @param promptName - Name of the prompt file (without .md extension)
|
|
5246
|
+
* @param options - Variables and security options
|
|
5247
|
+
* @param promptsDir - Optional custom prompts directory path
|
|
5248
|
+
* @returns Rendered prompt string
|
|
5249
|
+
*
|
|
5250
|
+
* @example
|
|
5251
|
+
* ```typescript
|
|
5252
|
+
* // Backwards compatible: all variables treated as trusted
|
|
5253
|
+
* loadPrompt('system', { companyName: 'Acme' });
|
|
5254
|
+
*
|
|
5255
|
+
* // Explicit: separate trusted and untrusted
|
|
5256
|
+
* loadPrompt('system', {
|
|
5257
|
+
* trustedVariables: { companyName: 'Acme' },
|
|
5258
|
+
* untrustedVariables: { userName: userInput }
|
|
5259
|
+
* });
|
|
5260
|
+
*
|
|
5261
|
+
* // Custom prompts directory
|
|
5262
|
+
* loadPrompt('system', { companyName: 'Acme' }, '/path/to/prompts');
|
|
5263
|
+
* ```
|
|
5264
|
+
*/
|
|
5265
|
+
declare function loadPrompt(promptName: string, options?: RenderTemplateOptions | Record<string, any>, promptsDir?: string): string;
|
|
5266
|
+
|
|
5267
|
+
export { AgentError, type AgentResumedEventData, type AgentWaitingEventData, type AggregateNode, type AnyInterrupt, type ApprovalRequiredInterrupt, type BackoffStrategy, type BatchOptions, BatchProcessor, type BatchProcessorOptions, type BatchStats, type CacheKeyGenerator, type CachingOptions, type CheckInterruptOptions, type CheckpointHistoryOptions, type CheckpointerOptions, type ChunkOptions, CircuitBreaker, type CircuitBreakerOptions, type CircuitBreakerStats, type CircuitState, type ComposeGraphsOptions, type ComposeOptions, type ComposeToolConfig, type ComposedTool, type ConcurrencyOptions, type ConditionalConfig, type ConditionalRouter, type ConditionalRouterConfig, ConnectionPool, type ConnectionPoolOptions, type ConversationConfig, type CustomInterrupt, type DatabaseConfig, type DatabaseConnection, DatabasePool, type DatabasePoolOptions, type DevelopmentPresetOptions, type ErrorContext, type ErrorHandlerOptions, type ErrorReporter, type ErrorReporterOptions, type EventHandler, type EvictionStrategy, type ExecutionMetrics, type HealthCheckConfig, type HealthCheckResult, type HttpClient, type HttpConfig, HttpPool, type HttpPoolConfig, type HttpPoolOptions, type HttpResponse, type HumanInLoopEventData, type HumanInLoopEventType, type HumanRequest, type HumanRequestEventData, type HumanRequestInterrupt, type HumanRequestPriority, type HumanRequestStatus, type HumanResponseEventData, type InterruptData, type InterruptEventData, type InterruptType, type LangSmithConfig, type LogEntry, LogLevel, type Logger, type LoggerOptions, type LoggingOptions, ManagedTool, type ManagedToolConfig, type ManagedToolStats, MemoryManager, type MemoryManagerOptions, type MemoryStats, type MetricEntry, MetricType, type Metrics, type MetricsNodeOptions, type Middleware, MiddlewareChain, type MiddlewareContext, type MiddlewareFactory, type MiddlewareMetadata, type MiddlewareWithMetadata, MissingDescriptionError, type MockToolConfig, type MockToolResponse, type NodeFunction, type NodeFunctionWithContext, type ParallelNode, type ParallelWorkflowConfig, type ParallelWorkflowOptions, type PoolConfig, type PoolStats, type Priority$1 as Priority, type ProductionPresetOptions, type Progress, type ProgressTracker, type ProgressTrackerOptions, type PromptOptions, type RateLimitOptions, type RateLimitStrategy, type ReducerFunction, RegistryEvent, type RenderTemplateOptions, type RequestConfig, type ResumeCommand, type ResumeEventData, type ResumeOptions, type RetryOptions, type RetryPolicy, type RouteCondition, type RouteMap, type RouteName, type SSEEvent, type SSEFormatter, type SSEFormatterOptions, type SequentialNode, type SequentialWorkflowOptions, type SimpleMiddleware, type SqliteCheckpointerOptions, type StateChannelConfig, type SubgraphBuilder, type TestingPresetOptions, type ThreadConfig, type ThreadInfo, type ThreadStatus, type ThrottleOptions, TimeoutError, type TimeoutOptions, type Timer, type Tool, type BackoffStrategy$1 as ToolBackoffStrategy, ToolBuilder, ToolCategory, ToolCategorySchema, type ToolExample, ToolExampleSchema, type ToolExecution, type ToolExecutorConfig, type ToolInvocation, type ToolMetadata, ToolMetadataSchema, ToolNameSchema, ToolRegistry, type ToolRelations, ToolRelationsSchema, type ToolSimulatorConfig, type TracingOptions, type ValidationErrorHandler, type ValidationMode, type ValidationOptions, type ValidatorFunction, type WebSocketHandlerOptions, type WebSocketMessage, batch, broadcast, cache, chain, chunk, clearThread, collect, compose, composeGraphs, composeTool, composeWithOptions, conditional, configureLangSmith, createApprovalRequiredInterrupt, createBatchProcessor, createBinaryRouter, createCircuitBreaker, createConditionalRouter, createConnectionPool, createConversationConfig, createCustomInterrupt, createDatabasePool, createErrorReporter, createHeartbeat, createHttpPool, createHumanRequestInterrupt, createLogger, createManagedTool, createMemoryCheckpointer, createMemoryManager, createMessage, createMetrics, createMiddlewareContext, createMockTool, createMultiRouter, createParallelWorkflow, createProgressTracker, createSSEFormatter, createSequentialWorkflow, createSharedCache, createSharedConcurrencyController, createSharedRateLimiter, createSqliteCheckpointer, createStateAnnotation, createSubgraph, createThreadConfig, createTool, createToolExecutor, createToolSimulator, createToolUnsafe, createWebSocketHandler, development, filter, formatAgentResumedEvent, formatAgentWaitingEvent, formatHumanRequestEvent, formatHumanResponseEvent, formatInterruptEvent, formatResumeEvent, generateThreadId, getCheckpointHistory, getLangSmithConfig, getLatestCheckpoint, getMissingDescriptions, getThreadStatus, getToolDescription, getToolJsonSchema, isApprovalRequiredInterrupt, isCustomInterrupt, isHumanRequestInterrupt, isMemoryCheckpointer, isTracingEnabled, loadPrompt, map, merge, mergeState, parallel, parseSSEEvent, presets, production, reduce, renderTemplate, retry, safeValidateSchemaDescriptions, sanitizeValue, sendMessage, sequential, sequentialBuilder, take, testing, throttle, timeout, toLangChainTool, toLangChainTools, toolBuilder, validateSchemaDescriptions, validateState, validateTool, validateToolMetadata, validateToolName, withCache, withConcurrency, withErrorHandler, withLogging, withMetrics, withRateLimit, withRetry, withTimeout, withTracing, withValidation };
|
package/dist/index.js
CHANGED
|
@@ -4766,6 +4766,68 @@ var CircuitBreaker = class {
|
|
|
4766
4766
|
function createCircuitBreaker(options) {
|
|
4767
4767
|
return new CircuitBreaker(options);
|
|
4768
4768
|
}
|
|
4769
|
+
|
|
4770
|
+
// src/prompt-loader/index.ts
|
|
4771
|
+
import { readFileSync } from "fs";
|
|
4772
|
+
import { join } from "path";
|
|
4773
|
+
var MAX_VARIABLE_LENGTH = 500;
|
|
4774
|
+
function sanitizeValue(value) {
|
|
4775
|
+
if (value === void 0 || value === null) return "";
|
|
4776
|
+
let sanitized = String(value);
|
|
4777
|
+
sanitized = sanitized.replace(/^#+\s*/gm, "");
|
|
4778
|
+
sanitized = sanitized.replace(/[\r\n]+/g, " ");
|
|
4779
|
+
sanitized = sanitized.trim().replace(/\s+/g, " ");
|
|
4780
|
+
if (sanitized.length > MAX_VARIABLE_LENGTH) {
|
|
4781
|
+
sanitized = sanitized.substring(0, MAX_VARIABLE_LENGTH) + "...";
|
|
4782
|
+
}
|
|
4783
|
+
return sanitized;
|
|
4784
|
+
}
|
|
4785
|
+
function renderTemplate(template, options) {
|
|
4786
|
+
let rawVariables;
|
|
4787
|
+
let sanitizedVariables;
|
|
4788
|
+
if ("trustedVariables" in options || "untrustedVariables" in options) {
|
|
4789
|
+
const opts = options;
|
|
4790
|
+
rawVariables = {
|
|
4791
|
+
...opts.trustedVariables,
|
|
4792
|
+
...opts.untrustedVariables
|
|
4793
|
+
};
|
|
4794
|
+
const sanitizedUntrusted = {};
|
|
4795
|
+
if (opts.untrustedVariables) {
|
|
4796
|
+
for (const [key, value] of Object.entries(opts.untrustedVariables)) {
|
|
4797
|
+
sanitizedUntrusted[key] = sanitizeValue(value);
|
|
4798
|
+
}
|
|
4799
|
+
}
|
|
4800
|
+
sanitizedVariables = {
|
|
4801
|
+
...opts.trustedVariables,
|
|
4802
|
+
...sanitizedUntrusted
|
|
4803
|
+
};
|
|
4804
|
+
} else {
|
|
4805
|
+
rawVariables = options;
|
|
4806
|
+
sanitizedVariables = options;
|
|
4807
|
+
}
|
|
4808
|
+
let result = template;
|
|
4809
|
+
result = result.replace(/\{\{#if\s+(\w+)\}\}([\s\S]*?)\{\{\/if\}\}/g, (_, varName, content) => {
|
|
4810
|
+
return rawVariables[varName] ? content : "";
|
|
4811
|
+
});
|
|
4812
|
+
result = result.replace(/\{\{(\w+)\}\}/g, (_, varName) => {
|
|
4813
|
+
const value = sanitizedVariables[varName];
|
|
4814
|
+
if (value === void 0 || value === null) return "";
|
|
4815
|
+
return String(value);
|
|
4816
|
+
});
|
|
4817
|
+
return result;
|
|
4818
|
+
}
|
|
4819
|
+
function loadPrompt(promptName, options = {}, promptsDir) {
|
|
4820
|
+
const baseDir = promptsDir || join(process.cwd(), "prompts");
|
|
4821
|
+
const promptPath = join(baseDir, `${promptName}.md`);
|
|
4822
|
+
try {
|
|
4823
|
+
const template = readFileSync(promptPath, "utf-8");
|
|
4824
|
+
return renderTemplate(template, options);
|
|
4825
|
+
} catch (error) {
|
|
4826
|
+
throw new Error(
|
|
4827
|
+
`Failed to load prompt "${promptName}" from ${promptPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
4828
|
+
);
|
|
4829
|
+
}
|
|
4830
|
+
}
|
|
4769
4831
|
export {
|
|
4770
4832
|
AgentError,
|
|
4771
4833
|
BatchProcessor,
|
|
@@ -4861,6 +4923,7 @@ export {
|
|
|
4861
4923
|
isHumanRequestInterrupt,
|
|
4862
4924
|
isMemoryCheckpointer,
|
|
4863
4925
|
isTracingEnabled,
|
|
4926
|
+
loadPrompt,
|
|
4864
4927
|
map,
|
|
4865
4928
|
merge,
|
|
4866
4929
|
mergeState,
|
|
@@ -4869,8 +4932,10 @@ export {
|
|
|
4869
4932
|
presets,
|
|
4870
4933
|
production,
|
|
4871
4934
|
reduce,
|
|
4935
|
+
renderTemplate,
|
|
4872
4936
|
retry,
|
|
4873
4937
|
safeValidateSchemaDescriptions,
|
|
4938
|
+
sanitizeValue,
|
|
4874
4939
|
sendMessage,
|
|
4875
4940
|
sequential,
|
|
4876
4941
|
sequentialBuilder,
|