@x12i/ai-gateway 7.9.1
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/README.md +4259 -0
- package/config.defaults.json +31 -0
- package/dist/activity-manager.d.ts +206 -0
- package/dist/activity-manager.js +1051 -0
- package/dist/config/activity-tracking-config.d.ts +11 -0
- package/dist/config/activity-tracking-config.js +15 -0
- package/dist/config.defaults.json +31 -0
- package/dist/content-normalizer/content-normalizer.d.ts +46 -0
- package/dist/content-normalizer/content-normalizer.js +393 -0
- package/dist/content-normalizer/index.d.ts +7 -0
- package/dist/content-normalizer/index.js +6 -0
- package/dist/content-normalizer/types.d.ts +33 -0
- package/dist/content-normalizer/types.js +4 -0
- package/dist/defaults/instructions-blocks.json +61 -0
- package/dist/defaults/model-config.json +16 -0
- package/dist/defaults/template-rendering.json +6 -0
- package/dist/flex-md-loader.d.ts +109 -0
- package/dist/flex-md-loader.js +940 -0
- package/dist/gateway-config.d.ts +49 -0
- package/dist/gateway-config.js +292 -0
- package/dist/gateway-conversion.d.ts +29 -0
- package/dist/gateway-conversion.js +174 -0
- package/dist/gateway-instructions.d.ts +30 -0
- package/dist/gateway-instructions.js +62 -0
- package/dist/gateway-memory.d.ts +51 -0
- package/dist/gateway-memory.js +207 -0
- package/dist/gateway-messages.d.ts +23 -0
- package/dist/gateway-messages.js +83 -0
- package/dist/gateway-meta.d.ts +25 -0
- package/dist/gateway-meta.js +87 -0
- package/dist/gateway-provider-auto-register.d.ts +17 -0
- package/dist/gateway-provider-auto-register.js +159 -0
- package/dist/gateway-provider.d.ts +54 -0
- package/dist/gateway-provider.js +202 -0
- package/dist/gateway-rate-limiter-constants.d.ts +16 -0
- package/dist/gateway-rate-limiter-constants.js +16 -0
- package/dist/gateway-rate-limiter.d.ts +56 -0
- package/dist/gateway-rate-limiter.js +107 -0
- package/dist/gateway-retry.d.ts +49 -0
- package/dist/gateway-retry.js +204 -0
- package/dist/gateway-utils.d.ts +21 -0
- package/dist/gateway-utils.js +181 -0
- package/dist/gateway-validation.d.ts +13 -0
- package/dist/gateway-validation.js +50 -0
- package/dist/gateway.d.ts +39 -0
- package/dist/gateway.js +430 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +55 -0
- package/dist/instruction-errors.d.ts +16 -0
- package/dist/instruction-errors.js +29 -0
- package/dist/instruction-optimizer.d.ts +113 -0
- package/dist/instruction-optimizer.js +293 -0
- package/dist/instructions-parser.d.ts +31 -0
- package/dist/instructions-parser.js +56 -0
- package/dist/logger-factory.d.ts +17 -0
- package/dist/logger-factory.js +42 -0
- package/dist/message-builder.d.ts +41 -0
- package/dist/message-builder.js +522 -0
- package/dist/object-types-library-integration.d.ts +22 -0
- package/dist/object-types-library-integration.js +27 -0
- package/dist/object-types-library.d.ts +351 -0
- package/dist/object-types-library.js +210 -0
- package/dist/output-auditor.d.ts +44 -0
- package/dist/output-auditor.js +49 -0
- package/dist/request-report-generator.d.ts +60 -0
- package/dist/request-report-generator.js +169 -0
- package/dist/response-analyzer/format-type-detector.d.ts +35 -0
- package/dist/response-analyzer/format-type-detector.js +115 -0
- package/dist/response-analyzer/index.d.ts +9 -0
- package/dist/response-analyzer/index.js +8 -0
- package/dist/response-analyzer/object-type-detector.d.ts +42 -0
- package/dist/response-analyzer/object-type-detector.js +95 -0
- package/dist/response-analyzer/response-analyzer.d.ts +38 -0
- package/dist/response-analyzer/response-analyzer.js +97 -0
- package/dist/response-analyzer/types.d.ts +97 -0
- package/dist/response-analyzer/types.js +4 -0
- package/dist/response-fallback-fixer.d.ts +11 -0
- package/dist/response-fallback-fixer.js +123 -0
- package/dist/runtime-objects.d.ts +52 -0
- package/dist/runtime-objects.js +46 -0
- package/dist/template-parser.d.ts +58 -0
- package/dist/template-parser.js +99 -0
- package/dist/template-render-merge.d.ts +9 -0
- package/dist/template-render-merge.js +40 -0
- package/dist/troubleshooting-helper.d.ts +123 -0
- package/dist/troubleshooting-helper.js +596 -0
- package/dist/types.d.ts +1173 -0
- package/dist/types.js +6 -0
- package/dist/usage-tracker.d.ts +78 -0
- package/dist/usage-tracker.js +79 -0
- package/dist-cjs/activity-manager.cjs +1056 -0
- package/dist-cjs/activity-manager.d.ts +206 -0
- package/dist-cjs/config/activity-tracking-config.cjs +18 -0
- package/dist-cjs/config/activity-tracking-config.d.ts +11 -0
- package/dist-cjs/config.defaults.json +31 -0
- package/dist-cjs/content-normalizer/content-normalizer.cjs +398 -0
- package/dist-cjs/content-normalizer/content-normalizer.d.ts +46 -0
- package/dist-cjs/content-normalizer/index.cjs +12 -0
- package/dist-cjs/content-normalizer/index.d.ts +7 -0
- package/dist-cjs/content-normalizer/types.cjs +5 -0
- package/dist-cjs/content-normalizer/types.d.ts +33 -0
- package/dist-cjs/defaults/instructions-blocks.json +61 -0
- package/dist-cjs/defaults/model-config.json +16 -0
- package/dist-cjs/defaults/template-rendering.json +6 -0
- package/dist-cjs/flex-md-loader.cjs +986 -0
- package/dist-cjs/flex-md-loader.d.ts +109 -0
- package/dist-cjs/gateway-config.cjs +331 -0
- package/dist-cjs/gateway-config.d.ts +49 -0
- package/dist-cjs/gateway-conversion.cjs +212 -0
- package/dist-cjs/gateway-conversion.d.ts +29 -0
- package/dist-cjs/gateway-instructions.cjs +67 -0
- package/dist-cjs/gateway-instructions.d.ts +30 -0
- package/dist-cjs/gateway-memory.cjs +211 -0
- package/dist-cjs/gateway-memory.d.ts +51 -0
- package/dist-cjs/gateway-messages.cjs +86 -0
- package/dist-cjs/gateway-messages.d.ts +23 -0
- package/dist-cjs/gateway-meta.cjs +90 -0
- package/dist-cjs/gateway-meta.d.ts +25 -0
- package/dist-cjs/gateway-provider-auto-register.cjs +195 -0
- package/dist-cjs/gateway-provider-auto-register.d.ts +17 -0
- package/dist-cjs/gateway-provider.cjs +214 -0
- package/dist-cjs/gateway-provider.d.ts +54 -0
- package/dist-cjs/gateway-rate-limiter-constants.cjs +19 -0
- package/dist-cjs/gateway-rate-limiter-constants.d.ts +16 -0
- package/dist-cjs/gateway-rate-limiter.cjs +111 -0
- package/dist-cjs/gateway-rate-limiter.d.ts +56 -0
- package/dist-cjs/gateway-retry.cjs +212 -0
- package/dist-cjs/gateway-retry.d.ts +49 -0
- package/dist-cjs/gateway-utils.cjs +219 -0
- package/dist-cjs/gateway-utils.d.ts +21 -0
- package/dist-cjs/gateway-validation.cjs +54 -0
- package/dist-cjs/gateway-validation.d.ts +13 -0
- package/dist-cjs/gateway.cjs +434 -0
- package/dist-cjs/gateway.d.ts +39 -0
- package/dist-cjs/index.cjs +108 -0
- package/dist-cjs/index.d.ts +36 -0
- package/dist-cjs/instruction-errors.cjs +34 -0
- package/dist-cjs/instruction-errors.d.ts +16 -0
- package/dist-cjs/instruction-optimizer.cjs +299 -0
- package/dist-cjs/instruction-optimizer.d.ts +113 -0
- package/dist-cjs/instructions-parser.cjs +61 -0
- package/dist-cjs/instructions-parser.d.ts +31 -0
- package/dist-cjs/logger-factory.cjs +45 -0
- package/dist-cjs/logger-factory.d.ts +17 -0
- package/dist-cjs/message-builder.cjs +558 -0
- package/dist-cjs/message-builder.d.ts +41 -0
- package/dist-cjs/object-types-library-integration.cjs +32 -0
- package/dist-cjs/object-types-library-integration.d.ts +22 -0
- package/dist-cjs/object-types-library.cjs +215 -0
- package/dist-cjs/object-types-library.d.ts +351 -0
- package/dist-cjs/output-auditor.cjs +52 -0
- package/dist-cjs/output-auditor.d.ts +44 -0
- package/dist-cjs/request-report-generator.cjs +172 -0
- package/dist-cjs/request-report-generator.d.ts +60 -0
- package/dist-cjs/response-analyzer/format-type-detector.cjs +119 -0
- package/dist-cjs/response-analyzer/format-type-detector.d.ts +35 -0
- package/dist-cjs/response-analyzer/index.cjs +14 -0
- package/dist-cjs/response-analyzer/index.d.ts +9 -0
- package/dist-cjs/response-analyzer/object-type-detector.cjs +99 -0
- package/dist-cjs/response-analyzer/object-type-detector.d.ts +42 -0
- package/dist-cjs/response-analyzer/response-analyzer.cjs +101 -0
- package/dist-cjs/response-analyzer/response-analyzer.d.ts +38 -0
- package/dist-cjs/response-analyzer/types.cjs +5 -0
- package/dist-cjs/response-analyzer/types.d.ts +97 -0
- package/dist-cjs/response-fallback-fixer.cjs +126 -0
- package/dist-cjs/response-fallback-fixer.d.ts +11 -0
- package/dist-cjs/runtime-objects.cjs +52 -0
- package/dist-cjs/runtime-objects.d.ts +52 -0
- package/dist-cjs/template-parser.cjs +136 -0
- package/dist-cjs/template-parser.d.ts +58 -0
- package/dist-cjs/template-render-merge.cjs +43 -0
- package/dist-cjs/template-render-merge.d.ts +9 -0
- package/dist-cjs/troubleshooting-helper.cjs +611 -0
- package/dist-cjs/troubleshooting-helper.d.ts +123 -0
- package/dist-cjs/types.cjs +7 -0
- package/dist-cjs/types.d.ts +1173 -0
- package/dist-cjs/usage-tracker.cjs +83 -0
- package/dist-cjs/usage-tracker.d.ts +78 -0
- package/package.json +91 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Troubleshooting Helper Toolbox
|
|
3
|
+
*
|
|
4
|
+
* Utility functions to diagnose and test AI Gateway issues
|
|
5
|
+
* Based on TROUBLESHOOTING.md guide
|
|
6
|
+
*/
|
|
7
|
+
import type { AIRequest, ChatRequest, EnhancedLLMResponse } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Converts JSON Schema to simple, human-readable format for LLM instructions
|
|
10
|
+
*
|
|
11
|
+
* Supports both formats:
|
|
12
|
+
* - JSON Schema format: { "type": "object", "properties": {...} }
|
|
13
|
+
* - Simple format: { "emails": ["<string> description"] }
|
|
14
|
+
*
|
|
15
|
+
* If schema is already in simple format, returns it as-is.
|
|
16
|
+
* If schema is in JSON Schema format, converts it to simple format.
|
|
17
|
+
*
|
|
18
|
+
* Simple format example:
|
|
19
|
+
* {
|
|
20
|
+
* "emails": [
|
|
21
|
+
* "<string> A valid email address extracted from the input text"
|
|
22
|
+
* ]
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* Format rules:
|
|
26
|
+
* - Arrays: Show as array with single example item containing type hint + description
|
|
27
|
+
* - Objects: Show nested structure recursively
|
|
28
|
+
* - Primitives: Show as type hint with description
|
|
29
|
+
* - Required fields: Implicit (just present in structure)
|
|
30
|
+
*
|
|
31
|
+
* @param schema - Schema object (JSON Schema or simple format)
|
|
32
|
+
* @returns Schema in simple format
|
|
33
|
+
*/
|
|
34
|
+
export declare function convertSchemaToSimpleFormat(schema: Record<string, unknown>): Record<string, unknown>;
|
|
35
|
+
export interface ValidationResult {
|
|
36
|
+
valid: boolean;
|
|
37
|
+
errors: string[];
|
|
38
|
+
warnings: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface DiagnosticInfo {
|
|
41
|
+
request: {
|
|
42
|
+
hasJobId: boolean;
|
|
43
|
+
hasAgentId: boolean;
|
|
44
|
+
hasInstructions: boolean;
|
|
45
|
+
hasPrompt: boolean;
|
|
46
|
+
hasWorkingMemory: boolean;
|
|
47
|
+
hasConfig: boolean;
|
|
48
|
+
hasModel: boolean;
|
|
49
|
+
hasProvider: boolean;
|
|
50
|
+
};
|
|
51
|
+
response?: {
|
|
52
|
+
hasContent: boolean;
|
|
53
|
+
isJSON: boolean;
|
|
54
|
+
hasParsedContent: boolean;
|
|
55
|
+
contentType: string;
|
|
56
|
+
validationPassed?: boolean;
|
|
57
|
+
validationErrors?: string[];
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Validates AIRequest structure
|
|
62
|
+
*/
|
|
63
|
+
export declare function validateAIRequest(request: Partial<AIRequest>): ValidationResult;
|
|
64
|
+
/**
|
|
65
|
+
* Validates JSON string
|
|
66
|
+
*/
|
|
67
|
+
export declare function validateJSON(jsonString: string): ValidationResult;
|
|
68
|
+
/**
|
|
69
|
+
* Extracts JSON from text (handles markdown code blocks, etc.)
|
|
70
|
+
*/
|
|
71
|
+
export declare function extractJSON(text: string): {
|
|
72
|
+
json: string | null;
|
|
73
|
+
method: string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Validates response structure
|
|
77
|
+
*/
|
|
78
|
+
export declare function validateResponse(response: Partial<EnhancedLLMResponse>): ValidationResult;
|
|
79
|
+
/**
|
|
80
|
+
* Collects comprehensive diagnostic information
|
|
81
|
+
*/
|
|
82
|
+
export declare function diagnoseRequest(request: Partial<AIRequest | ChatRequest>): DiagnosticInfo;
|
|
83
|
+
/**
|
|
84
|
+
* Diagnoses response issues
|
|
85
|
+
*/
|
|
86
|
+
export declare function diagnoseResponse(response: Partial<EnhancedLLMResponse>): DiagnosticInfo['response'];
|
|
87
|
+
/**
|
|
88
|
+
* Tests if a provider/model combination supports JSON mode
|
|
89
|
+
*/
|
|
90
|
+
export declare function supportsJSONMode(provider?: string, model?: string): {
|
|
91
|
+
supported: boolean;
|
|
92
|
+
notes: string;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Creates a test AIRequest with minimal valid structure
|
|
96
|
+
*/
|
|
97
|
+
export declare function createTestAIRequest(overrides?: Partial<AIRequest>): AIRequest;
|
|
98
|
+
/**
|
|
99
|
+
* Creates test cases for validation
|
|
100
|
+
*/
|
|
101
|
+
export declare function createValidationTestCases(): Array<{
|
|
102
|
+
name: string;
|
|
103
|
+
request: Partial<AIRequest>;
|
|
104
|
+
shouldFail: boolean;
|
|
105
|
+
expectedErrors?: string[];
|
|
106
|
+
}>;
|
|
107
|
+
/**
|
|
108
|
+
* Runs all validation tests and returns results
|
|
109
|
+
*/
|
|
110
|
+
export declare function runValidationTests(): Array<{
|
|
111
|
+
name: string;
|
|
112
|
+
passed: boolean;
|
|
113
|
+
errors: string[];
|
|
114
|
+
warnings: string[];
|
|
115
|
+
}>;
|
|
116
|
+
/**
|
|
117
|
+
* Formats diagnostic information for display
|
|
118
|
+
*/
|
|
119
|
+
export declare function formatDiagnostic(diagnostic: DiagnosticInfo): string;
|
|
120
|
+
/**
|
|
121
|
+
* Quick validation helper - throws if invalid
|
|
122
|
+
*/
|
|
123
|
+
export declare function assertValidAIRequest(request: Partial<AIRequest>): void;
|