@juspay/neurolink 9.56.1 → 9.57.0
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/auth/AuthProviderFactory.d.ts +3 -3
- package/dist/auth/providers/BaseAuthProvider.d.ts +2 -2
- package/dist/auth/providers/BaseAuthProvider.js +1 -1
- package/dist/auth/serverBridge.d.ts +2 -2
- package/dist/browser/neurolink.min.js +306 -306
- package/dist/cli/factories/commandFactory.js +32 -8
- package/dist/cli/loop/optionsSchema.js +4 -0
- package/dist/cli/parser.js +3 -3
- package/dist/dynamic/dynamicResolver.d.ts +282 -0
- package/dist/dynamic/dynamicResolver.js +633 -0
- package/dist/dynamic/index.d.ts +10 -0
- package/dist/dynamic/index.js +12 -0
- package/dist/dynamic/resolution.d.ts +17 -0
- package/dist/dynamic/resolution.js +21 -0
- package/dist/evaluation/index.js +1 -1
- package/dist/files/fileReferenceRegistry.js +25 -10
- package/dist/index.js +19 -2
- package/dist/lib/auth/AuthProviderFactory.d.ts +3 -3
- package/dist/lib/auth/providers/BaseAuthProvider.d.ts +2 -2
- package/dist/lib/auth/providers/BaseAuthProvider.js +1 -1
- package/dist/lib/auth/serverBridge.d.ts +2 -2
- package/dist/lib/dynamic/dynamicResolver.d.ts +282 -0
- package/dist/lib/dynamic/dynamicResolver.js +634 -0
- package/dist/lib/dynamic/index.d.ts +10 -0
- package/dist/lib/dynamic/index.js +13 -0
- package/dist/lib/dynamic/resolution.d.ts +17 -0
- package/dist/lib/dynamic/resolution.js +22 -0
- package/dist/lib/evaluation/index.js +1 -1
- package/dist/lib/files/fileReferenceRegistry.js +25 -10
- package/dist/lib/index.js +19 -2
- package/dist/lib/mcp/mcpServerBase.d.ts +1 -1
- package/dist/lib/mcp/mcpServerBase.js +1 -1
- package/dist/lib/neurolink.d.ts +12 -4
- package/dist/lib/neurolink.js +79 -6
- package/dist/lib/observability/exporters/baseExporter.d.ts +1 -1
- package/dist/lib/observability/exporters/baseExporter.js +1 -1
- package/dist/lib/types/auth.d.ts +6 -6
- package/dist/lib/types/config.d.ts +4 -4
- package/dist/lib/types/dynamic.d.ts +98 -0
- package/dist/lib/types/dynamic.js +10 -0
- package/dist/lib/types/file.d.ts +10 -0
- package/dist/lib/types/fileReference.d.ts +9 -0
- package/dist/lib/types/generate.d.ts +29 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/index.js +2 -0
- package/dist/lib/types/scorer.d.ts +1 -1
- package/dist/lib/types/scorer.js +1 -1
- package/dist/lib/types/span.d.ts +1 -1
- package/dist/lib/types/span.js +1 -1
- package/dist/lib/types/stream.d.ts +6 -0
- package/dist/lib/utils/fileDetector.d.ts +7 -0
- package/dist/lib/utils/fileDetector.js +47 -0
- package/dist/lib/utils/messageBuilder.js +15 -1
- package/dist/lib/utils/mimeTypeHints.d.ts +40 -0
- package/dist/lib/utils/mimeTypeHints.js +122 -0
- package/dist/mcp/mcpServerBase.d.ts +1 -1
- package/dist/mcp/mcpServerBase.js +1 -1
- package/dist/neurolink.d.ts +12 -4
- package/dist/neurolink.js +79 -6
- package/dist/observability/exporters/baseExporter.d.ts +1 -1
- package/dist/observability/exporters/baseExporter.js +1 -1
- package/dist/types/auth.d.ts +6 -6
- package/dist/types/config.d.ts +4 -4
- package/dist/types/dynamic.d.ts +98 -0
- package/dist/types/dynamic.js +9 -0
- package/dist/types/file.d.ts +10 -0
- package/dist/types/fileReference.d.ts +9 -0
- package/dist/types/generate.d.ts +29 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/scorer.d.ts +1 -1
- package/dist/types/scorer.js +1 -1
- package/dist/types/span.d.ts +1 -1
- package/dist/types/span.js +1 -1
- package/dist/types/stream.d.ts +6 -0
- package/dist/utils/fileDetector.d.ts +7 -0
- package/dist/utils/fileDetector.js +47 -0
- package/dist/utils/messageBuilder.js +15 -1
- package/dist/utils/mimeTypeHints.d.ts +40 -0
- package/dist/utils/mimeTypeHints.js +121 -0
- package/package.json +1 -1
|
@@ -17,6 +17,7 @@ import { tmpdir } from "node:os";
|
|
|
17
17
|
import { basename, extname, join } from "node:path";
|
|
18
18
|
import { estimatePostProcessingTokens } from "../context/fileTokenBudget.js";
|
|
19
19
|
import { logger } from "../utils/logger.js";
|
|
20
|
+
import { mimeHintToExtension, mimeHintToFileType, normalizeMimeHint, } from "../utils/mimeTypeHints.js";
|
|
20
21
|
import { StreamingReader } from "./streamingReader.js";
|
|
21
22
|
import { SIZE_TIER_THRESHOLDS } from "../types/index.js";
|
|
22
23
|
/** Default maximum files in registry before LRU eviction */
|
|
@@ -89,19 +90,33 @@ export class FileReferenceRegistry {
|
|
|
89
90
|
const sizeMB = (sizeBytes / (1024 * 1024)).toFixed(1);
|
|
90
91
|
throw new Error(`File too large (${sizeMB} MB). Maximum accepted size is 2 GB.`);
|
|
91
92
|
}
|
|
93
|
+
// Normalize the caller-provided mimetype hint — shared helper drops
|
|
94
|
+
// `application/octet-stream` because that opaque sentinel would
|
|
95
|
+
// otherwise be trusted verbatim for the output mimeType and mask a
|
|
96
|
+
// better magic-byte-derived classification (e.g. PNG bytes hinted as
|
|
97
|
+
// octet-stream would record mimeType=octet-stream, not image/png).
|
|
98
|
+
const hintMime = normalizeMimeHint(options.mimetype);
|
|
99
|
+
const hintExt = hintMime ? mimeHintToExtension(hintMime) : "";
|
|
92
100
|
// Detect file type from magic bytes and extension.
|
|
93
|
-
// If the provided filename has no extension, append one guessed from
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
// If the provided filename has no extension, append one guessed from the
|
|
102
|
+
// mimetype hint first (more reliable for text formats than magic bytes),
|
|
103
|
+
// then fall back to magic bytes — so downstream processors (e.g.,
|
|
104
|
+
// VideoProcessor) can validate by extension. Compute once, reuse.
|
|
105
|
+
const synthDefaultExt = hintExt
|
|
106
|
+
? `.${hintExt}`
|
|
107
|
+
: this.guessExtension(buffer);
|
|
108
|
+
let filename = options.filename || `file-${Date.now()}${synthDefaultExt}`;
|
|
109
|
+
if (!extname(filename) && synthDefaultExt) {
|
|
110
|
+
filename = `${filename}${synthDefaultExt}`;
|
|
101
111
|
}
|
|
102
112
|
const ext = extname(filename).toLowerCase().replace(".", "");
|
|
103
|
-
const detectedType = options.fileType ||
|
|
104
|
-
|
|
113
|
+
const detectedType = options.fileType ||
|
|
114
|
+
(hintMime && mimeHintToFileType(hintMime)) ||
|
|
115
|
+
this.detectType(buffer, ext);
|
|
116
|
+
// Prefer the caller's hint verbatim for the output mimeType, but only
|
|
117
|
+
// when normalizeMimeHint accepted it (i.e. it is not the opaque
|
|
118
|
+
// octet-stream sentinel). Otherwise derive from the detected type.
|
|
119
|
+
const mimeType = hintMime || this.guessMimeType(detectedType, ext);
|
|
105
120
|
const sizeTier = FileReferenceRegistry.classifySizeTier(sizeBytes);
|
|
106
121
|
// Generate preview (fast — only reads first N chars)
|
|
107
122
|
const preview = this.extractPreview(buffer, detectedType, options.maxPreviewChars ?? this.defaultPreviewChars);
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ export { AIProviderFactory };
|
|
|
37
37
|
export { GoogleTTSHandler } from "./adapters/tts/googleTTSHandler.js";
|
|
38
38
|
// Config Manager export
|
|
39
39
|
export { NeuroLinkConfigManager as ConfigManager } from "./config/configManager.js";
|
|
40
|
-
// Core Infrastructure exports (
|
|
40
|
+
// Core Infrastructure exports (factory + registry patterns)
|
|
41
41
|
export { BaseFactory, BaseRegistry, NeuroLinkFeatureError, createErrorFactory, withRetry, TypedEventEmitter, } from "./core/infrastructure/index.js";
|
|
42
42
|
// ============================================================================
|
|
43
43
|
// CLIENT SDK EXPORTS - Type-safe API access for browser and Node.js
|
|
@@ -107,6 +107,23 @@ export { SpanSerializer } from "./observability/utils/spanSerializer.js";
|
|
|
107
107
|
// Middleware exports
|
|
108
108
|
// Version
|
|
109
109
|
export const VERSION = "1.0.0";
|
|
110
|
+
// ============================================================================
|
|
111
|
+
// Dynamic Arguments
|
|
112
|
+
// ============================================================================
|
|
113
|
+
//
|
|
114
|
+
// Dynamic arguments let you pass functions instead of static values to
|
|
115
|
+
// generate() and stream(). Resolution happens automatically before
|
|
116
|
+
// provider dispatch. Pass dynamicContext inline for per-request
|
|
117
|
+
// user/tenant/session context that dynamic functions can read.
|
|
118
|
+
//
|
|
119
|
+
// Example:
|
|
120
|
+
// await neurolink.generate({
|
|
121
|
+
// input: { text: "Hello" },
|
|
122
|
+
// model: (ctx) => ctx.requestContext.tenant?.plan === "enterprise"
|
|
123
|
+
// ? "gpt-4o" : "gpt-4o-mini",
|
|
124
|
+
// dynamicContext: { tenant: { id: "t1", plan: "enterprise" } },
|
|
125
|
+
// });
|
|
126
|
+
// ============================================================================
|
|
110
127
|
/**
|
|
111
128
|
* Quick start factory function for creating AI provider instances.
|
|
112
129
|
*
|
|
@@ -348,7 +365,7 @@ export async function getTelemetryStatus() {
|
|
|
348
365
|
export {
|
|
349
366
|
// Main Evaluator
|
|
350
367
|
Evaluator,
|
|
351
|
-
// Factory and Registry
|
|
368
|
+
// Factory and Registry
|
|
352
369
|
EvaluationAggregator, EvaluatorFactory, getEvaluatorFactory, getEvaluatorRegistry,
|
|
353
370
|
// Error utilities
|
|
354
371
|
evaluationErrors, isRetryableEvaluationError, isEvaluationError, createEvaluationFailedError, createParseError, createStrategyNotFoundError, createProviderError, createMaxRetriesExceededError, createBatchEvaluationError, createConfigurationError, contextToErrorContext,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* extension, no singleton instance. Providers are registered by
|
|
6
6
|
* AuthProviderRegistry using dynamic imports to avoid circular dependencies.
|
|
7
7
|
*/
|
|
8
|
-
import type { AuthProviderConfig, AuthProviderConstructor, AuthProviderMetadata,
|
|
8
|
+
import type { AuthProviderConfig, AuthProviderConstructor, AuthProviderMetadata, AuthProvider } from "../types/index.js";
|
|
9
9
|
/**
|
|
10
10
|
* AuthProviderFactory - Creates authentication provider instances
|
|
11
11
|
*
|
|
@@ -33,7 +33,7 @@ export declare class AuthProviderFactory {
|
|
|
33
33
|
/**
|
|
34
34
|
* Create a provider instance
|
|
35
35
|
*/
|
|
36
|
-
static createProvider(typeOrAlias: string, config: AuthProviderConfig): Promise<
|
|
36
|
+
static createProvider(typeOrAlias: string, config: AuthProviderConfig): Promise<AuthProvider>;
|
|
37
37
|
/**
|
|
38
38
|
* Check if a provider is registered
|
|
39
39
|
*/
|
|
@@ -66,4 +66,4 @@ export declare class AuthProviderFactory {
|
|
|
66
66
|
/**
|
|
67
67
|
* Create an auth provider using the factory
|
|
68
68
|
*/
|
|
69
|
-
export declare function createAuthProvider(type: string, config: AuthProviderConfig): Promise<
|
|
69
|
+
export declare function createAuthProvider(type: string, config: AuthProviderConfig): Promise<AuthProvider>;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* - Error handling via unified AuthError factory
|
|
11
11
|
*/
|
|
12
12
|
import { EventEmitter } from "events";
|
|
13
|
-
import type { AuthenticatedContext, AuthHealthCheck, AuthorizationResult, AuthProviderConfig, AuthProviderType, AuthRequestContext, AuthSession, AuthUser,
|
|
13
|
+
import type { AuthenticatedContext, AuthHealthCheck, AuthorizationResult, AuthProviderConfig, AuthProviderType, AuthRequestContext, AuthSession, AuthUser, AuthProvider, RBACConfig, SessionConfig, SessionStorage, SessionValidationResult, TokenClaims, TokenValidationResult } from "../../types/index.js";
|
|
14
14
|
/**
|
|
15
15
|
* @deprecated Use `AuthError` from `../errors.js` instead.
|
|
16
16
|
* Kept for backward compatibility with CognitoProvider / KeycloakProvider.
|
|
@@ -81,7 +81,7 @@ export declare class InMemorySessionStorage implements SessionStorage {
|
|
|
81
81
|
* - updateUserPermissions() - Update user permissions in provider
|
|
82
82
|
* - dispose() - Clean up resources
|
|
83
83
|
*/
|
|
84
|
-
export declare abstract class BaseAuthProvider implements
|
|
84
|
+
export declare abstract class BaseAuthProvider implements AuthProvider {
|
|
85
85
|
abstract readonly type: AuthProviderType;
|
|
86
86
|
readonly config: AuthProviderConfig;
|
|
87
87
|
protected sessionStorage: SessionStorage;
|
|
@@ -607,7 +607,7 @@ export class BaseAuthProvider {
|
|
|
607
607
|
logger.debug(`[BaseAuthProvider] Disposed ${this.type} provider`);
|
|
608
608
|
}
|
|
609
609
|
// ===========================================================================
|
|
610
|
-
// METHODS FROM
|
|
610
|
+
// METHODS FROM AuthProvider INTERFACE
|
|
611
611
|
// ===========================================================================
|
|
612
612
|
/**
|
|
613
613
|
* Check if a user is authorized to perform an action
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* Converts an auth provider's authenticateToken() into the validate
|
|
4
4
|
* callback expected by the existing createAuthMiddleware.
|
|
5
5
|
*/
|
|
6
|
-
import type {
|
|
6
|
+
import type { AuthProvider } from "../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Create a validate function for server auth middleware from an auth provider.
|
|
9
9
|
*/
|
|
10
|
-
export declare function createAuthValidatorFromProvider(provider:
|
|
10
|
+
export declare function createAuthValidatorFromProvider(provider: AuthProvider): (token: string, ctx: unknown) => Promise<{
|
|
11
11
|
id: string;
|
|
12
12
|
email?: string;
|
|
13
13
|
roles?: string[];
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic Argument Resolution Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for resolving dynamic arguments to their actual values,
|
|
5
|
+
* with support for caching, memoization, fallbacks, and conditional resolution.
|
|
6
|
+
*
|
|
7
|
+
* @module dynamic/dynamicResolver
|
|
8
|
+
*/
|
|
9
|
+
import type { DynamicArgument, DynamicResolutionContext, ResolutionOptions, ResolutionResult, DynamicConfig, ResolvedConfig } from "../types/index.js";
|
|
10
|
+
/**
|
|
11
|
+
* Resolution cache for dynamic arguments
|
|
12
|
+
*/
|
|
13
|
+
declare class ResolutionCache {
|
|
14
|
+
private cache;
|
|
15
|
+
private cleanupInterval;
|
|
16
|
+
constructor(cleanupIntervalMs?: number);
|
|
17
|
+
get<T>(key: string): T | undefined;
|
|
18
|
+
set<T>(key: string, value: T, ttl: number): void;
|
|
19
|
+
delete(key: string): boolean;
|
|
20
|
+
clear(): void;
|
|
21
|
+
size(): number;
|
|
22
|
+
private startCleanup;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
}
|
|
25
|
+
declare const globalCache: ResolutionCache;
|
|
26
|
+
/**
|
|
27
|
+
* Resolve a dynamic argument to its actual value
|
|
28
|
+
*
|
|
29
|
+
* @template T - The expected resolved type
|
|
30
|
+
* @param argument - The dynamic argument to resolve
|
|
31
|
+
* @param context - Resolution context (optional for static values)
|
|
32
|
+
* @param options - Resolution options
|
|
33
|
+
* @returns Resolution result with value and metadata
|
|
34
|
+
*
|
|
35
|
+
* @example Resolve static value
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const result = await resolveDynamicArgument("gpt-4o");
|
|
38
|
+
* console.log(result.value); // "gpt-4o"
|
|
39
|
+
* console.log(result.resolutionType); // "static"
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @example Resolve context-aware function
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const modelSelector = ({ requestContext }) =>
|
|
45
|
+
* requestContext.tenant?.plan === "enterprise" ? "claude-3-opus" : "claude-3-sonnet";
|
|
46
|
+
*
|
|
47
|
+
* const result = await resolveDynamicArgument(modelSelector, {
|
|
48
|
+
* requestContext: { requestId: "123", tenant: { id: "t1", plan: "enterprise" } }
|
|
49
|
+
* });
|
|
50
|
+
* console.log(result.value); // "claude-3-opus"
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveDynamicArgument<T>(argument: DynamicArgument<T>, context?: DynamicResolutionContext, options?: ResolutionOptions): Promise<ResolutionResult<T>>;
|
|
54
|
+
/**
|
|
55
|
+
* Resolve multiple dynamic arguments in parallel
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const [model, temperature] = await resolveDynamicArguments(
|
|
60
|
+
* [
|
|
61
|
+
* ({ requestContext }) => requestContext.user?.preferences?.preferredModel || "gpt-4o",
|
|
62
|
+
* 0.7,
|
|
63
|
+
* ],
|
|
64
|
+
* context
|
|
65
|
+
* );
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function resolveDynamicArguments<T extends readonly unknown[]>(arguments_: {
|
|
69
|
+
[K in keyof T]: DynamicArgument<T[K]>;
|
|
70
|
+
}, context?: DynamicResolutionContext, options?: ResolutionOptions): Promise<{
|
|
71
|
+
[K in keyof T]: T[K];
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* Resolve all properties of a dynamic configuration object
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const dynamicConfig = {
|
|
79
|
+
* model: ({ requestContext }) => requestContext.tenant?.settings?.defaultModel || "gpt-4o",
|
|
80
|
+
* temperature: 0.7,
|
|
81
|
+
* maxTokens: async () => (await fetchConfig()).maxTokens,
|
|
82
|
+
* };
|
|
83
|
+
*
|
|
84
|
+
* const resolved = await resolveDynamicConfig(dynamicConfig, context);
|
|
85
|
+
* // resolved.model, resolved.temperature, resolved.maxTokens are all resolved values
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function resolveDynamicConfig<T extends Record<string, unknown>>(config: DynamicConfig<T>, context?: DynamicResolutionContext, options?: ResolutionOptions): Promise<ResolvedConfig<T>>;
|
|
89
|
+
/**
|
|
90
|
+
* Create a memoized dynamic argument that caches its result
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const expensiveModelSelector = memoizeDynamicArgument(
|
|
95
|
+
* async ({ requestContext }) => {
|
|
96
|
+
* const config = await fetchTenantConfig(requestContext.tenant?.id);
|
|
97
|
+
* return config.preferredModel;
|
|
98
|
+
* },
|
|
99
|
+
* { cacheTtl: 300000 } // Cache for 5 minutes
|
|
100
|
+
* );
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function memoizeDynamicArgument<T>(argument: DynamicArgument<T>, options?: {
|
|
104
|
+
cacheTtl?: number;
|
|
105
|
+
cacheKey?: string;
|
|
106
|
+
}): DynamicArgument<T>;
|
|
107
|
+
/**
|
|
108
|
+
* Create a dynamic argument with fallback chain
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const modelWithFallback = withFallback(
|
|
113
|
+
* ({ requestContext }) => requestContext.user?.preferences?.preferredModel,
|
|
114
|
+
* ({ requestContext }) => requestContext.tenant?.settings?.defaultModel,
|
|
115
|
+
* "gpt-4o" // Final static fallback
|
|
116
|
+
* );
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function withFallback<T>(...arguments_: DynamicArgument<T | undefined | null>[]): DynamicArgument<T>;
|
|
120
|
+
/**
|
|
121
|
+
* Create a conditional dynamic argument
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const conditionalModel = conditional(
|
|
126
|
+
* ({ requestContext }) => requestContext.tenant?.plan === "enterprise",
|
|
127
|
+
* "claude-3-opus", // If true
|
|
128
|
+
* "claude-3-sonnet" // If false
|
|
129
|
+
* );
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare function conditional<T>(condition: DynamicArgument<boolean>, ifTrue: DynamicArgument<T>, ifFalse: DynamicArgument<T>): DynamicArgument<T>;
|
|
133
|
+
/**
|
|
134
|
+
* Create a mapped dynamic argument that transforms the result
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const upperCaseModel = mapDynamicArgument(
|
|
139
|
+
* ({ requestContext }) => requestContext.user?.preferences?.preferredModel,
|
|
140
|
+
* (model) => model?.toUpperCase()
|
|
141
|
+
* );
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare function mapDynamicArgument<T, U>(argument: DynamicArgument<T>, transform: (value: T) => U | Promise<U>): DynamicArgument<U>;
|
|
145
|
+
/**
|
|
146
|
+
* Create a dynamic argument that combines multiple arguments
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const combinedConfig = combineDynamicArguments(
|
|
151
|
+
* [
|
|
152
|
+
* ({ requestContext }) => requestContext.user?.preferences?.preferredModel,
|
|
153
|
+
* ({ requestContext }) => requestContext.tenant?.settings?.defaultTemperature,
|
|
154
|
+
* ],
|
|
155
|
+
* ([model, temperature]) => ({ model: model || "gpt-4o", temperature: temperature || 0.7 })
|
|
156
|
+
* );
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
export declare function combineDynamicArguments<T extends readonly unknown[], U>(arguments_: {
|
|
160
|
+
[K in keyof T]: DynamicArgument<T[K]>;
|
|
161
|
+
}, combiner: (values: T) => U | Promise<U>): DynamicArgument<U>;
|
|
162
|
+
/**
|
|
163
|
+
* Check if a value contains any dynamic arguments (is a function)
|
|
164
|
+
*/
|
|
165
|
+
export declare function hasDynamicArgument<T>(value: DynamicArgument<T>): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Check if an object has any dynamic properties
|
|
168
|
+
*/
|
|
169
|
+
export declare function hasDynamicProperties<T extends Record<string, unknown>>(config: DynamicConfig<T>): boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Clear the global resolution cache
|
|
172
|
+
*/
|
|
173
|
+
export declare function clearResolutionCache(): void;
|
|
174
|
+
/**
|
|
175
|
+
* Get resolution cache statistics
|
|
176
|
+
*/
|
|
177
|
+
export declare function getResolutionCacheStats(): {
|
|
178
|
+
size: number;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Destroy the resolver (cleanup intervals, etc.)
|
|
182
|
+
*/
|
|
183
|
+
export declare function destroyResolver(): void;
|
|
184
|
+
/**
|
|
185
|
+
* Interpolate environment variables in a string
|
|
186
|
+
*
|
|
187
|
+
* Supports syntax:
|
|
188
|
+
* - ${VAR} - Simple substitution
|
|
189
|
+
* - ${VAR:-default} - Use default if VAR is unset or empty
|
|
190
|
+
* - ${VAR:+replacement} - Use replacement if VAR is set and non-empty
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* interpolateEnvVars("Model: ${DEFAULT_MODEL:-gpt-4o}");
|
|
195
|
+
* // Returns "Model: gpt-4o" if DEFAULT_MODEL is not set
|
|
196
|
+
*
|
|
197
|
+
* interpolateEnvVars("API Key: ${OPENAI_API_KEY}");
|
|
198
|
+
* // Returns "API Key: sk-xxx..." if OPENAI_API_KEY is set
|
|
199
|
+
*
|
|
200
|
+
* interpolateEnvVars("Debug: ${DEBUG:+enabled}");
|
|
201
|
+
* // Returns "Debug: enabled" if DEBUG is set, "Debug: " otherwise
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
export declare function interpolateEnvVars(input: string, customEnv?: Record<string, string | undefined>): string;
|
|
205
|
+
/**
|
|
206
|
+
* Create a dynamic argument that interpolates environment variables
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const model = fromEnv("${PREFERRED_MODEL:-gpt-4o}");
|
|
211
|
+
* // Resolves to value of PREFERRED_MODEL or "gpt-4o" as fallback
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export declare function fromEnv(template: string): DynamicArgument<string>;
|
|
215
|
+
/**
|
|
216
|
+
* Create a dynamic argument from a single environment variable
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const apiKey = envVar("OPENAI_API_KEY");
|
|
221
|
+
* // Resolves to value of OPENAI_API_KEY or undefined
|
|
222
|
+
*
|
|
223
|
+
* const model = envVar("DEFAULT_MODEL", "gpt-4o");
|
|
224
|
+
* // Resolves to DEFAULT_MODEL value or "gpt-4o" as default
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
export declare function envVar<T extends string = string>(name: string, defaultValue?: T): DynamicArgument<T | undefined>;
|
|
228
|
+
/**
|
|
229
|
+
* Create a dynamic argument that selects from environment-based configurations
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const model = envSwitch("NODE_ENV", {
|
|
234
|
+
* development: "gpt-4o-mini",
|
|
235
|
+
* production: "gpt-4o",
|
|
236
|
+
* test: "gpt-3.5-turbo",
|
|
237
|
+
* }, "gpt-4o-mini");
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
export declare function envSwitch<T>(envVarName: string, options: Record<string, T>, defaultValue: T): DynamicArgument<T>;
|
|
241
|
+
/**
|
|
242
|
+
* Create a dynamic argument that parses a JSON value from an environment variable
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* // If RATE_LIMITS='{"requestsPerMinute": 100, "tokensPerDay": 50000}'
|
|
247
|
+
* const rateLimits = envJson<RateLimits>("RATE_LIMITS", { requestsPerMinute: 10 });
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
export declare function envJson<T>(name: string, defaultValue?: T): DynamicArgument<T | undefined>;
|
|
251
|
+
/**
|
|
252
|
+
* Create a dynamic argument that reads a number from an environment variable
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* const maxTokens = envNumber("MAX_TOKENS", 1000);
|
|
257
|
+
* const temperature = envNumber("TEMPERATURE", 0.7);
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
export declare function envNumber(name: string, defaultValue?: number): DynamicArgument<number | undefined>;
|
|
261
|
+
/**
|
|
262
|
+
* Create a dynamic argument that reads a boolean from an environment variable
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* const enableDebug = envBoolean("DEBUG", false);
|
|
267
|
+
* const enableTools = envBoolean("ENABLE_TOOLS", true);
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
export declare function envBoolean(name: string, defaultValue?: boolean): DynamicArgument<boolean | undefined>;
|
|
271
|
+
/**
|
|
272
|
+
* Create a dynamic argument that reads a comma-separated list from an environment variable
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* // If ALLOWED_PROVIDERS='openai,anthropic,vertex'
|
|
277
|
+
* const providers = envList("ALLOWED_PROVIDERS", ["openai"]);
|
|
278
|
+
* // Returns ["openai", "anthropic", "vertex"]
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
export declare function envList(name: string, defaultValue?: string[], separator?: string): DynamicArgument<string[] | undefined>;
|
|
282
|
+
export { globalCache as resolutionCache };
|