@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,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response Analyzer
|
|
3
|
+
*
|
|
4
|
+
* Main class that orchestrates object type and format type detection.
|
|
5
|
+
* Analyzes normalized responses and provides enhanced metadata.
|
|
6
|
+
*/
|
|
7
|
+
import type { ResponseAnalyzerConfig, AnalysisResult, ObjectTypeDefinition } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Analyzes AI responses to detect object types and format types
|
|
10
|
+
*/
|
|
11
|
+
export declare class ResponseAnalyzer {
|
|
12
|
+
private objectDetector?;
|
|
13
|
+
private formatDetector;
|
|
14
|
+
private enableFormatDetection;
|
|
15
|
+
constructor(config?: ResponseAnalyzerConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Analyzes a response and returns enhanced metadata
|
|
18
|
+
*
|
|
19
|
+
* @param rawText - Raw text content from response
|
|
20
|
+
* @param parsedContent - Parsed content (object, array, or null)
|
|
21
|
+
* @returns Analysis result with detected types
|
|
22
|
+
*/
|
|
23
|
+
analyze(rawText?: string, parsedContent?: any): AnalysisResult;
|
|
24
|
+
/**
|
|
25
|
+
* Determines the content type of the response
|
|
26
|
+
*
|
|
27
|
+
* @param rawText - Raw text content
|
|
28
|
+
* @param parsedContent - Parsed content
|
|
29
|
+
* @returns Content type classification
|
|
30
|
+
*/
|
|
31
|
+
private determineContentType;
|
|
32
|
+
/**
|
|
33
|
+
* Updates object type definitions
|
|
34
|
+
*
|
|
35
|
+
* @param definitions - New object type definitions
|
|
36
|
+
*/
|
|
37
|
+
updateObjectTypeDefinitions(definitions: ObjectTypeDefinition[]): void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Response Analyzer
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Object type definition for matching against response objects
|
|
6
|
+
*/
|
|
7
|
+
export interface ObjectTypeDefinition {
|
|
8
|
+
/**
|
|
9
|
+
* Unique identifier for the type
|
|
10
|
+
*/
|
|
11
|
+
id: string;
|
|
12
|
+
/**
|
|
13
|
+
* Human-readable name
|
|
14
|
+
*/
|
|
15
|
+
name: string;
|
|
16
|
+
/**
|
|
17
|
+
* Properties that must be present for a match
|
|
18
|
+
*/
|
|
19
|
+
requiredProperties: string[];
|
|
20
|
+
/**
|
|
21
|
+
* Properties that boost confidence if present
|
|
22
|
+
*/
|
|
23
|
+
optionalProperties?: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Priority weight (higher = more important)
|
|
26
|
+
* Used to break ties when confidence is equal
|
|
27
|
+
* @default 1
|
|
28
|
+
*/
|
|
29
|
+
priority?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for ResponseAnalyzer
|
|
33
|
+
*/
|
|
34
|
+
export interface ResponseAnalyzerConfig {
|
|
35
|
+
/**
|
|
36
|
+
* Object type definitions to match against
|
|
37
|
+
*/
|
|
38
|
+
objectTypeDefinitions?: ObjectTypeDefinition[];
|
|
39
|
+
/**
|
|
40
|
+
* Enable format type detection for text responses
|
|
41
|
+
* @default true
|
|
42
|
+
*/
|
|
43
|
+
enableFormatDetection?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Minimum confidence threshold for object type matching
|
|
46
|
+
* Types below this threshold are filtered out
|
|
47
|
+
* @default 0.5
|
|
48
|
+
*/
|
|
49
|
+
minConfidenceThreshold?: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Matched object type with confidence score
|
|
53
|
+
*/
|
|
54
|
+
export interface MatchedObjectType {
|
|
55
|
+
/**
|
|
56
|
+
* The matched type definition
|
|
57
|
+
*/
|
|
58
|
+
type: ObjectTypeDefinition;
|
|
59
|
+
/**
|
|
60
|
+
* Confidence score (0-1)
|
|
61
|
+
*/
|
|
62
|
+
confidence: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Detected format type with confidence score
|
|
66
|
+
*/
|
|
67
|
+
export interface DetectedFormatType {
|
|
68
|
+
/**
|
|
69
|
+
* Format type identifier
|
|
70
|
+
*/
|
|
71
|
+
formatType: string;
|
|
72
|
+
/**
|
|
73
|
+
* Confidence score (0-1)
|
|
74
|
+
*/
|
|
75
|
+
confidence: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Analysis result containing all detected information
|
|
79
|
+
*/
|
|
80
|
+
export interface AnalysisResult {
|
|
81
|
+
/**
|
|
82
|
+
* Content type classification
|
|
83
|
+
*/
|
|
84
|
+
contentType: 'object' | 'text' | 'empty';
|
|
85
|
+
/**
|
|
86
|
+
* Best matching object type (highest confidence)
|
|
87
|
+
*/
|
|
88
|
+
bestObjectType?: MatchedObjectType;
|
|
89
|
+
/**
|
|
90
|
+
* All matching object types (sorted by confidence)
|
|
91
|
+
*/
|
|
92
|
+
allObjectTypes?: MatchedObjectType[];
|
|
93
|
+
/**
|
|
94
|
+
* Detected format type (for text responses)
|
|
95
|
+
*/
|
|
96
|
+
formatType?: DetectedFormatType;
|
|
97
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tryFixGatewayResponseToJsonText = tryFixGatewayResponseToJsonText;
|
|
4
|
+
function tryParseJson(text) {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(text);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function extractFirstFencedBlock(text) {
|
|
13
|
+
// Supports ```json ... ``` and ```markdown ... ``` (and unlabeled ``` ... ```)
|
|
14
|
+
const re = /```(?:json|markdown)?\s*\n?([\s\S]*?)\n?```/i;
|
|
15
|
+
const match = text.match(re);
|
|
16
|
+
return match?.[1]?.trim() || undefined;
|
|
17
|
+
}
|
|
18
|
+
function extractBalancedJsonSubstring(text) {
|
|
19
|
+
// Finds first balanced {...} or [...] substring while respecting JSON strings.
|
|
20
|
+
const s = text;
|
|
21
|
+
const startObj = s.indexOf('{');
|
|
22
|
+
const startArr = s.indexOf('[');
|
|
23
|
+
let start = -1;
|
|
24
|
+
let openChar = '';
|
|
25
|
+
let closeChar = '';
|
|
26
|
+
if (startObj === -1 && startArr === -1)
|
|
27
|
+
return undefined;
|
|
28
|
+
if (startObj !== -1 && (startArr === -1 || startObj < startArr)) {
|
|
29
|
+
start = startObj;
|
|
30
|
+
openChar = '{';
|
|
31
|
+
closeChar = '}';
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
start = startArr;
|
|
35
|
+
openChar = '[';
|
|
36
|
+
closeChar = ']';
|
|
37
|
+
}
|
|
38
|
+
let depth = 0;
|
|
39
|
+
let inString = false;
|
|
40
|
+
let escape = false;
|
|
41
|
+
for (let i = start; i < s.length; i++) {
|
|
42
|
+
const ch = s[i];
|
|
43
|
+
if (inString) {
|
|
44
|
+
if (escape) {
|
|
45
|
+
escape = false;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (ch === '\\') {
|
|
49
|
+
escape = true;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (ch === '"') {
|
|
53
|
+
inString = false;
|
|
54
|
+
}
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (ch === '"') {
|
|
58
|
+
inString = true;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (ch === openChar)
|
|
62
|
+
depth++;
|
|
63
|
+
if (ch === closeChar)
|
|
64
|
+
depth--;
|
|
65
|
+
if (depth === 0) {
|
|
66
|
+
const candidate = s.slice(start, i + 1).trim();
|
|
67
|
+
return candidate.length > 0 ? candidate : undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
function stripToFirstJsonLike(text) {
|
|
73
|
+
const s = text.trim();
|
|
74
|
+
const firstBrace = s.indexOf('{');
|
|
75
|
+
const firstBracket = s.indexOf('[');
|
|
76
|
+
if (firstBrace === -1 && firstBracket === -1)
|
|
77
|
+
return undefined;
|
|
78
|
+
const start = firstBrace !== -1 && (firstBracket === -1 || firstBrace < firstBracket) ? firstBrace : firstBracket;
|
|
79
|
+
const stripped = s.slice(start).trim();
|
|
80
|
+
return stripped.length > 0 ? stripped : undefined;
|
|
81
|
+
}
|
|
82
|
+
function tryFixGatewayResponseToJsonText(raw) {
|
|
83
|
+
const warnings = [];
|
|
84
|
+
const input = raw ?? '';
|
|
85
|
+
if (!input || !input.trim()) {
|
|
86
|
+
return { fixed: false, warnings: ['empty-input'] };
|
|
87
|
+
}
|
|
88
|
+
// 0) Already valid JSON
|
|
89
|
+
const trimmed = input.trim();
|
|
90
|
+
if (tryParseJson(trimmed) !== undefined) {
|
|
91
|
+
return {
|
|
92
|
+
fixed: true,
|
|
93
|
+
jsonText: trimmed,
|
|
94
|
+
fixApplied: 'strip-to-first-json',
|
|
95
|
+
confidence: 0.95,
|
|
96
|
+
warnings: ['input-already-valid-json']
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// 1) Fenced block extraction
|
|
100
|
+
const fenced = extractFirstFencedBlock(input);
|
|
101
|
+
if (fenced) {
|
|
102
|
+
if (tryParseJson(fenced) !== undefined) {
|
|
103
|
+
return { fixed: true, jsonText: fenced, fixApplied: 'extract-fenced-json', confidence: 0.7 };
|
|
104
|
+
}
|
|
105
|
+
warnings.push('fenced-block-found-but-not-json');
|
|
106
|
+
}
|
|
107
|
+
// 2) Balanced substring extraction
|
|
108
|
+
const balanced = extractBalancedJsonSubstring(input);
|
|
109
|
+
if (balanced) {
|
|
110
|
+
if (tryParseJson(balanced) !== undefined) {
|
|
111
|
+
return { fixed: true, jsonText: balanced, fixApplied: 'extract-balanced-json', confidence: 0.55 };
|
|
112
|
+
}
|
|
113
|
+
warnings.push('balanced-json-substring-found-but-not-json');
|
|
114
|
+
}
|
|
115
|
+
// 3) Strip leading prose to first { or [
|
|
116
|
+
const stripped = stripToFirstJsonLike(input);
|
|
117
|
+
if (stripped) {
|
|
118
|
+
// It might still have trailing junk; try balanced extraction again on stripped first.
|
|
119
|
+
const strippedBalanced = extractBalancedJsonSubstring(stripped) ?? stripped;
|
|
120
|
+
if (tryParseJson(strippedBalanced) !== undefined) {
|
|
121
|
+
return { fixed: true, jsonText: strippedBalanced, fixApplied: 'strip-to-first-json', confidence: 0.4 };
|
|
122
|
+
}
|
|
123
|
+
warnings.push('stripped-to-first-jsonlike-but-not-json');
|
|
124
|
+
}
|
|
125
|
+
return { fixed: false, warnings: warnings.length ? warnings : undefined };
|
|
126
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type GatewayFallbackFixResult = {
|
|
2
|
+
fixed: true;
|
|
3
|
+
jsonText: string;
|
|
4
|
+
fixApplied: 'extract-fenced-json' | 'extract-balanced-json' | 'strip-to-first-json';
|
|
5
|
+
confidence: number;
|
|
6
|
+
warnings?: string[];
|
|
7
|
+
} | {
|
|
8
|
+
fixed: false;
|
|
9
|
+
warnings?: string[];
|
|
10
|
+
};
|
|
11
|
+
export declare function tryFixGatewayResponseToJsonText(raw: string): GatewayFallbackFixResult;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runtimeObjects = void 0;
|
|
4
|
+
exports.setGatewayLastJobId = setGatewayLastJobId;
|
|
5
|
+
exports.setGatewayRuntimeClients = setGatewayRuntimeClients;
|
|
6
|
+
exports.getRuntimeObservabilityMode = getRuntimeObservabilityMode;
|
|
7
|
+
exports.runtimeObjects = createRuntimeObjectsForMode();
|
|
8
|
+
function setGatewayLastJobId(jobId) {
|
|
9
|
+
const objects = ensureRuntimeObjectsForCurrentMode();
|
|
10
|
+
if (!objects)
|
|
11
|
+
return;
|
|
12
|
+
objects.lastJobId = jobId;
|
|
13
|
+
}
|
|
14
|
+
function setGatewayRuntimeClients(input) {
|
|
15
|
+
const objects = ensureRuntimeObjectsForCurrentMode();
|
|
16
|
+
if (!objects)
|
|
17
|
+
return;
|
|
18
|
+
objects.activixClient = input.activix ? asActivixQueryableClient(input.activix) : undefined;
|
|
19
|
+
objects.logxerClient = input.logger ? asLogxerQueryableClient(input.logger) : undefined;
|
|
20
|
+
objects.packagesRuntimeObjects = [];
|
|
21
|
+
}
|
|
22
|
+
function getRuntimeObservabilityMode() {
|
|
23
|
+
const rawMode = process.env.mode ?? process.env.MODE;
|
|
24
|
+
return rawMode === 'prod' ? 'prod' : 'debug';
|
|
25
|
+
}
|
|
26
|
+
function ensureRuntimeObjectsForCurrentMode() {
|
|
27
|
+
if (getRuntimeObservabilityMode() === 'prod') {
|
|
28
|
+
exports.runtimeObjects = undefined;
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
exports.runtimeObjects ??= createRuntimeObjects();
|
|
32
|
+
return exports.runtimeObjects;
|
|
33
|
+
}
|
|
34
|
+
function createRuntimeObjectsForMode() {
|
|
35
|
+
return getRuntimeObservabilityMode() === 'debug' ? createRuntimeObjects() : undefined;
|
|
36
|
+
}
|
|
37
|
+
function createRuntimeObjects() {
|
|
38
|
+
return {
|
|
39
|
+
lastJobId: undefined,
|
|
40
|
+
activixClient: undefined,
|
|
41
|
+
logxerClient: undefined,
|
|
42
|
+
packagesRuntimeObjects: []
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function asActivixQueryableClient(activix) {
|
|
46
|
+
const candidate = activix;
|
|
47
|
+
return typeof candidate.getJobActivities === 'function' ? candidate : undefined;
|
|
48
|
+
}
|
|
49
|
+
function asLogxerQueryableClient(logger) {
|
|
50
|
+
const candidate = logger;
|
|
51
|
+
return typeof candidate.getJobLogs === 'function' ? candidate : undefined;
|
|
52
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Logxer } from '@x12i/logxer';
|
|
2
|
+
import type { Activix } from '@x12i/activix';
|
|
3
|
+
export type ActivixQueryableClient = {
|
|
4
|
+
getJobActivities(input: {
|
|
5
|
+
jobId: string;
|
|
6
|
+
graphId?: string;
|
|
7
|
+
nodeId?: string;
|
|
8
|
+
limit?: number;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
jobId: string;
|
|
11
|
+
graphRun?: unknown;
|
|
12
|
+
activities: unknown[];
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
15
|
+
export type LogxerQueryableClient = {
|
|
16
|
+
getJobLogs(input: {
|
|
17
|
+
jobId: string;
|
|
18
|
+
graphId?: string;
|
|
19
|
+
nodeId?: string;
|
|
20
|
+
limit?: number;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
jobId: string;
|
|
23
|
+
lines: Array<{
|
|
24
|
+
ts?: number | string;
|
|
25
|
+
level?: 'debug' | 'info' | 'warn' | 'error';
|
|
26
|
+
scope?: string;
|
|
27
|
+
packageName?: string;
|
|
28
|
+
nodeId?: string;
|
|
29
|
+
message: string;
|
|
30
|
+
data?: unknown;
|
|
31
|
+
}>;
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
34
|
+
export type PackageRuntimeObjects = {
|
|
35
|
+
name: string;
|
|
36
|
+
activixClient?: ActivixQueryableClient;
|
|
37
|
+
logxerClient?: LogxerQueryableClient;
|
|
38
|
+
};
|
|
39
|
+
export type RuntimeObjects = {
|
|
40
|
+
lastJobId?: string;
|
|
41
|
+
activixClient?: ActivixQueryableClient;
|
|
42
|
+
logxerClient?: LogxerQueryableClient;
|
|
43
|
+
packagesRuntimeObjects: PackageRuntimeObjects[];
|
|
44
|
+
};
|
|
45
|
+
export type RuntimeObservabilityMode = 'debug' | 'prod';
|
|
46
|
+
export declare let runtimeObjects: RuntimeObjects | undefined;
|
|
47
|
+
export declare function setGatewayLastJobId(jobId: string | undefined): void;
|
|
48
|
+
export declare function setGatewayRuntimeClients(input: {
|
|
49
|
+
activix?: Activix;
|
|
50
|
+
logger?: Logxer;
|
|
51
|
+
}): void;
|
|
52
|
+
export declare function getRuntimeObservabilityMode(): RuntimeObservabilityMode;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Template Parser
|
|
4
|
+
*
|
|
5
|
+
* Uses @x12i/rendrix (v4+) to parse templates with workingMemory.
|
|
6
|
+
* TemplateResolutionError from the parser is rethrown; other errors fall back to the raw template.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.parseTemplate = parseTemplate;
|
|
43
|
+
exports.isParserAvailable = isParserAvailable;
|
|
44
|
+
let rendrixModule = null;
|
|
45
|
+
let parserLoadPromise = null;
|
|
46
|
+
async function loadRendrix() {
|
|
47
|
+
if (rendrixModule !== null || parserLoadPromise) {
|
|
48
|
+
if (parserLoadPromise)
|
|
49
|
+
await parserLoadPromise;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
parserLoadPromise = (async () => {
|
|
53
|
+
try {
|
|
54
|
+
rendrixModule = await Promise.resolve().then(() => __importStar(require('@x12i/rendrix')));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
rendrixModule = null;
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
parserLoadPromise = null;
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
await parserLoadPromise;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Parses a template string using Rendrix with all memory contexts
|
|
67
|
+
*
|
|
68
|
+
* @param template - Template string to parse
|
|
69
|
+
* @param workingMemory - Working memory object for variable substitution (required for rendering)
|
|
70
|
+
* @param taskConfig - @deprecated Task configuration flags - no longer used by Rendrix 3.0.0+ (kept for backward compatibility)
|
|
71
|
+
* @param shortTermMemory - Short-term memory for session-specific overrides (optional)
|
|
72
|
+
* @param experienceMemory - Experience memory for learned knowledge (optional)
|
|
73
|
+
* @param knowledgeMemory - Knowledge memory for reference data (optional)
|
|
74
|
+
* @param templateRenderOptions - Passed to Rendrix `render` (v4+): templateId, subPathSearch, silentMissingMustTokens
|
|
75
|
+
* @returns Parsed template string
|
|
76
|
+
* @throws {Error} When the parser throws TemplateResolutionError (v4 MUST path missing after merge)
|
|
77
|
+
*/
|
|
78
|
+
async function parseTemplate(template, workingMemory, taskConfig, shortTermMemory, experienceMemory, knowledgeMemory, templateRenderOptions) {
|
|
79
|
+
// If no template or empty, return as-is
|
|
80
|
+
if (!template || typeof template !== 'string') {
|
|
81
|
+
return template || '';
|
|
82
|
+
}
|
|
83
|
+
// If no workingMemory, return template as-is (workingMemory is required for Rendrix)
|
|
84
|
+
if (!workingMemory) {
|
|
85
|
+
return template;
|
|
86
|
+
}
|
|
87
|
+
await loadRendrix();
|
|
88
|
+
if (!rendrixModule) {
|
|
89
|
+
return template;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const api = typeof rendrixModule.render === 'function'
|
|
93
|
+
? rendrixModule
|
|
94
|
+
: rendrixModule.default || rendrixModule;
|
|
95
|
+
if (typeof api.render === 'function') {
|
|
96
|
+
return await api.render(template, workingMemory, shortTermMemory, experienceMemory, knowledgeMemory, undefined, // functionsMap
|
|
97
|
+
undefined, // choiceOptions
|
|
98
|
+
undefined, // filesContent
|
|
99
|
+
templateRenderOptions);
|
|
100
|
+
}
|
|
101
|
+
if (typeof api.parse === 'function') {
|
|
102
|
+
return await api.parse(template, workingMemory);
|
|
103
|
+
}
|
|
104
|
+
else if (typeof api === 'function') {
|
|
105
|
+
const parser = new api();
|
|
106
|
+
if (typeof parser.parse === 'function') {
|
|
107
|
+
return await parser.parse(template, workingMemory);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return template;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
// @x12i/rendrix v4+: missing MUST paths throw TemplateResolutionError.
|
|
114
|
+
if (error instanceof Error &&
|
|
115
|
+
error.name === 'TemplateResolutionError') {
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
119
|
+
console.warn('Template parsing failed, using template as-is:', {
|
|
120
|
+
error: err.message,
|
|
121
|
+
templateLength: template.length,
|
|
122
|
+
hasWorkingMemory: !!workingMemory,
|
|
123
|
+
hasTaskConfig: !!taskConfig,
|
|
124
|
+
hasShortTermMemory: !!shortTermMemory,
|
|
125
|
+
hasExperienceMemory: !!experienceMemory,
|
|
126
|
+
hasKnowledgeMemory: !!knowledgeMemory
|
|
127
|
+
});
|
|
128
|
+
return template;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Checks if Rendrix (@x12i/rendrix) is available
|
|
133
|
+
*/
|
|
134
|
+
function isParserAvailable() {
|
|
135
|
+
return rendrixModule !== null;
|
|
136
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Parser
|
|
3
|
+
*
|
|
4
|
+
* Uses @x12i/rendrix (v4+) to parse templates with workingMemory.
|
|
5
|
+
* TemplateResolutionError from the parser is rethrown; other errors fall back to the raw template.
|
|
6
|
+
*/
|
|
7
|
+
import type { TemplateRenderOptions } from '@x12i/rendrix';
|
|
8
|
+
/**
|
|
9
|
+
* Task configuration type for template rendering
|
|
10
|
+
* @deprecated taskConfig is no longer used by Rendrix 3.0.0+
|
|
11
|
+
* Kept for backward compatibility only - will be ignored
|
|
12
|
+
*/
|
|
13
|
+
export interface TaskConfig {
|
|
14
|
+
includeThoughts?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Short-term memory type - flexible key-value storage
|
|
18
|
+
*/
|
|
19
|
+
export interface ShortTermMemory {
|
|
20
|
+
[key: string]: string | number | boolean | object | object[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Experience memory type - structured storage for learned experiences
|
|
24
|
+
*/
|
|
25
|
+
export interface ExperienceMemory {
|
|
26
|
+
knowHows?: object | object[] | string[] | string;
|
|
27
|
+
narratives?: object | object[] | string[] | string;
|
|
28
|
+
experiences?: object | object[] | string[] | string;
|
|
29
|
+
insights?: object | object[] | string[] | string;
|
|
30
|
+
learnings?: object | object[] | string[] | string;
|
|
31
|
+
lessons?: object | object[] | string[] | string;
|
|
32
|
+
frameworks?: object | object[] | string[] | string;
|
|
33
|
+
tools?: object | object[] | string[] | string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Knowledge memory type - flexible key-value storage for reference data
|
|
37
|
+
*/
|
|
38
|
+
export interface KnowledgeMemory {
|
|
39
|
+
[key: string]: string | number | boolean | object | object[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parses a template string using Rendrix with all memory contexts
|
|
43
|
+
*
|
|
44
|
+
* @param template - Template string to parse
|
|
45
|
+
* @param workingMemory - Working memory object for variable substitution (required for rendering)
|
|
46
|
+
* @param taskConfig - @deprecated Task configuration flags - no longer used by Rendrix 3.0.0+ (kept for backward compatibility)
|
|
47
|
+
* @param shortTermMemory - Short-term memory for session-specific overrides (optional)
|
|
48
|
+
* @param experienceMemory - Experience memory for learned knowledge (optional)
|
|
49
|
+
* @param knowledgeMemory - Knowledge memory for reference data (optional)
|
|
50
|
+
* @param templateRenderOptions - Passed to Rendrix `render` (v4+): templateId, subPathSearch, silentMissingMustTokens
|
|
51
|
+
* @returns Parsed template string
|
|
52
|
+
* @throws {Error} When the parser throws TemplateResolutionError (v4 MUST path missing after merge)
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseTemplate(template: string, workingMemory?: unknown, taskConfig?: TaskConfig, shortTermMemory?: ShortTermMemory, experienceMemory?: ExperienceMemory, knowledgeMemory?: KnowledgeMemory, templateRenderOptions?: TemplateRenderOptions): Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if Rendrix (@x12i/rendrix) is available
|
|
57
|
+
*/
|
|
58
|
+
export declare function isParserAvailable(): boolean;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Merge @x12i/rendrix TemplateRenderOptions from gateway defaults and per-request overrides.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mergeTemplateRenderOptions = mergeTemplateRenderOptions;
|
|
7
|
+
function hasMeaningfulOptions(o) {
|
|
8
|
+
if (o.templateId !== undefined)
|
|
9
|
+
return true;
|
|
10
|
+
if (o.silentMissingMustTokens !== undefined)
|
|
11
|
+
return true;
|
|
12
|
+
if (o.subPathSearch !== undefined) {
|
|
13
|
+
const s = o.subPathSearch;
|
|
14
|
+
return (s.enabled !== undefined ||
|
|
15
|
+
(Array.isArray(s.roots) && s.roots.length > 0));
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Deep-merge template render options. Request/gateway overrides win per field.
|
|
21
|
+
* For `subPathSearch`, `roots` on the override replace the base list when present.
|
|
22
|
+
*/
|
|
23
|
+
function mergeTemplateRenderOptions(base, override) {
|
|
24
|
+
if (!base && !override)
|
|
25
|
+
return undefined;
|
|
26
|
+
if (!base) {
|
|
27
|
+
const o = { ...override };
|
|
28
|
+
return hasMeaningfulOptions(o) ? o : undefined;
|
|
29
|
+
}
|
|
30
|
+
if (!override) {
|
|
31
|
+
const o = { ...base };
|
|
32
|
+
return hasMeaningfulOptions(o) ? o : undefined;
|
|
33
|
+
}
|
|
34
|
+
const merged = { ...base, ...override };
|
|
35
|
+
if (base.subPathSearch || override.subPathSearch) {
|
|
36
|
+
merged.subPathSearch = {
|
|
37
|
+
...(base.subPathSearch ?? {}),
|
|
38
|
+
...(override.subPathSearch ?? {}),
|
|
39
|
+
roots: override.subPathSearch?.roots ?? base.subPathSearch?.roots
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return hasMeaningfulOptions(merged) ? merged : undefined;
|
|
43
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merge @x12i/rendrix TemplateRenderOptions from gateway defaults and per-request overrides.
|
|
3
|
+
*/
|
|
4
|
+
import type { TemplateRenderOptions } from '@x12i/rendrix';
|
|
5
|
+
/**
|
|
6
|
+
* Deep-merge template render options. Request/gateway overrides win per field.
|
|
7
|
+
* For `subPathSearch`, `roots` on the override replace the base list when present.
|
|
8
|
+
*/
|
|
9
|
+
export declare function mergeTemplateRenderOptions(base?: TemplateRenderOptions, override?: TemplateRenderOptions): TemplateRenderOptions | undefined;
|