@memberjunction/ai-agents 2.60.0 → 2.62.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/README.md +47 -4
- package/dist/PayloadChangeAnalyzer.d.ts +71 -0
- package/dist/PayloadChangeAnalyzer.d.ts.map +1 -0
- package/dist/PayloadChangeAnalyzer.js +339 -0
- package/dist/PayloadChangeAnalyzer.js.map +1 -0
- package/dist/PayloadDiff.d.ts +42 -0
- package/dist/PayloadDiff.d.ts.map +1 -0
- package/dist/PayloadDiff.js +232 -0
- package/dist/PayloadDiff.js.map +1 -0
- package/dist/PayloadFeedbackManager.d.ts +39 -0
- package/dist/PayloadFeedbackManager.d.ts.map +1 -0
- package/dist/PayloadFeedbackManager.js +117 -0
- package/dist/PayloadFeedbackManager.js.map +1 -0
- package/dist/PayloadManager.d.ts +34 -0
- package/dist/PayloadManager.d.ts.map +1 -1
- package/dist/PayloadManager.js +168 -0
- package/dist/PayloadManager.js.map +1 -1
- package/dist/agent-types/base-agent-type.d.ts +0 -1
- package/dist/agent-types/base-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +3 -2
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +0 -2
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +3 -13
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/base-agent.d.ts +1 -0
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +139 -25
- package/dist/base-agent.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -41,6 +41,14 @@ Simple orchestrator that:
|
|
|
41
41
|
- Instantiates correct agent class using ClassFactory
|
|
42
42
|
- Executes agents with provided context
|
|
43
43
|
|
|
44
|
+
### PayloadManager
|
|
45
|
+
Advanced payload access control for hierarchical agent execution:
|
|
46
|
+
- Controls which payload paths sub-agents can read (downstream)
|
|
47
|
+
- Controls which payload paths sub-agents can write (upstream)
|
|
48
|
+
- Supports JSON path patterns with wildcards
|
|
49
|
+
- Detects suspicious changes with configurable rules
|
|
50
|
+
- Generates human-readable diffs for audit trails
|
|
51
|
+
|
|
44
52
|
## Installation
|
|
45
53
|
|
|
46
54
|
```bash
|
|
@@ -144,6 +152,38 @@ export class MyCustomAgentType extends BaseAgentType {
|
|
|
144
152
|
|
|
145
153
|
## Advanced Features
|
|
146
154
|
|
|
155
|
+
### Payload Management and Change Detection
|
|
156
|
+
|
|
157
|
+
The framework includes sophisticated payload management with automatic change detection:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// Payload changes are automatically analyzed
|
|
161
|
+
const changeResult = payloadManager.applyAgentChangeRequest(
|
|
162
|
+
originalPayload,
|
|
163
|
+
changeRequest,
|
|
164
|
+
{
|
|
165
|
+
analyzeChanges: true, // Detect suspicious changes
|
|
166
|
+
generateDiff: true, // Create audit trail
|
|
167
|
+
agentName: 'MyAgent'
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// Suspicious changes are flagged:
|
|
172
|
+
// - Content truncation (>70% reduction)
|
|
173
|
+
// - Non-empty key removal
|
|
174
|
+
// - Type changes (object→primitive)
|
|
175
|
+
// - Pattern anomalies (placeholder replacement)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Sub-agent Payload Access Control**:
|
|
179
|
+
```typescript
|
|
180
|
+
// In AIAgent entity configuration:
|
|
181
|
+
{
|
|
182
|
+
PayloadDownstreamPaths: ["customer.id", "order.*"], // What sub-agent can read
|
|
183
|
+
PayloadUpstreamPaths: ["analysis.*", "recommendations"] // What sub-agent can write
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
147
187
|
### Hierarchical Prompt Execution
|
|
148
188
|
```typescript
|
|
149
189
|
// System prompt provides base behavior
|
|
@@ -194,10 +234,15 @@ Key entities used by the agent framework:
|
|
|
194
234
|
|
|
195
235
|
- **AIAgentType**: Agent behavior patterns and system prompts
|
|
196
236
|
- **AIAgent**: Configured agent instances
|
|
237
|
+
- `PayloadDownstreamPaths`: JSON array of paths sub-agents can read
|
|
238
|
+
- `PayloadUpstreamPaths`: JSON array of paths sub-agents can write
|
|
197
239
|
- **AIPrompt**: Reusable prompt templates with placeholders
|
|
198
240
|
- **AIAgentPrompt**: Links agents to prompts with execution order
|
|
199
241
|
- **AIAgentRun**: Tracks complete agent executions
|
|
200
242
|
- **AIAgentRunStep**: Records individual steps within runs
|
|
243
|
+
- `PayloadAtStart`: JSON snapshot of payload before step
|
|
244
|
+
- `PayloadAtEnd`: JSON snapshot of payload after step
|
|
245
|
+
- `OutputData`: Includes `payloadChangeResult` with analysis
|
|
201
246
|
- **AIAgentRunStepAction**: Details of actions executed
|
|
202
247
|
- **AIAgentRunStepPrompt**: Prompt execution details
|
|
203
248
|
|
|
@@ -210,6 +255,8 @@ Key entities used by the agent framework:
|
|
|
210
255
|
5. **Comprehensive Tracking**: Leverage built-in tracking for debugging and analysis
|
|
211
256
|
6. **Context Efficiency**: Let the framework handle context compression automatically
|
|
212
257
|
7. **Error Handling**: Implement robust error handling in custom agent types
|
|
258
|
+
8. **Payload Security**: Use path-based access control for sub-agents
|
|
259
|
+
9. **Change Monitoring**: Review payload change warnings in OutputData
|
|
213
260
|
|
|
214
261
|
## Examples
|
|
215
262
|
|
|
@@ -252,10 +299,6 @@ export class DecisionTreeAgent extends BaseAgentType {
|
|
|
252
299
|
|
|
253
300
|
For detailed architecture information, see [agent-architecture.md](./agent-architecture.md).
|
|
254
301
|
|
|
255
|
-
## Payload and State Management
|
|
256
|
-
|
|
257
|
-
For comprehensive information about managing payload flow between agents and sub-agents, including access control and best practices, see [PAYLOAD_STATE_MANAGEMENT.md](./PAYLOAD_STATE_MANAGEMENT.md).
|
|
258
|
-
|
|
259
302
|
## Contributing
|
|
260
303
|
|
|
261
304
|
Contributions are welcome! Please see the main MemberJunction [contributing guide](../../../CONTRIBUTING.md).
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { AgentPayloadChangeRequest } from '@memberjunction/ai-core-plus';
|
|
2
|
+
export declare enum PayloadWarningType {
|
|
3
|
+
ContentTruncation = "content_truncation",
|
|
4
|
+
KeyRemoval = "key_removal",
|
|
5
|
+
TypeChange = "type_change",
|
|
6
|
+
PatternAnomaly = "pattern_anomaly",
|
|
7
|
+
UnintendedOverwrite = "unintended_overwrite"
|
|
8
|
+
}
|
|
9
|
+
export interface PayloadWarning {
|
|
10
|
+
type: PayloadWarningType;
|
|
11
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
12
|
+
path: string;
|
|
13
|
+
message: string;
|
|
14
|
+
requiresFeedback?: boolean;
|
|
15
|
+
details: any;
|
|
16
|
+
}
|
|
17
|
+
export interface ContentTruncationWarning extends PayloadWarning {
|
|
18
|
+
type: PayloadWarningType.ContentTruncation;
|
|
19
|
+
details: {
|
|
20
|
+
originalLength: number;
|
|
21
|
+
newLength: number;
|
|
22
|
+
reductionPercentage: number;
|
|
23
|
+
contentPreview: {
|
|
24
|
+
before: string;
|
|
25
|
+
after: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface KeyRemovalWarning extends PayloadWarning {
|
|
30
|
+
type: PayloadWarningType.KeyRemoval;
|
|
31
|
+
details: {
|
|
32
|
+
removedKeys: string[];
|
|
33
|
+
hadContent: boolean;
|
|
34
|
+
contentSize: number;
|
|
35
|
+
childKeysRemoved?: string[];
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface PayloadAnalyzerConfig {
|
|
39
|
+
contentReductionThreshold: number;
|
|
40
|
+
minContentLengthForAnalysis: number;
|
|
41
|
+
arrayReductionThreshold: number;
|
|
42
|
+
objectKeyReductionThreshold: number;
|
|
43
|
+
analyzeNestedChanges: boolean;
|
|
44
|
+
maxAnalysisDepth: number;
|
|
45
|
+
truncationPatterns: RegExp[];
|
|
46
|
+
}
|
|
47
|
+
export interface PayloadAnalysisResult {
|
|
48
|
+
warnings: PayloadWarning[];
|
|
49
|
+
criticalWarnings: PayloadWarning[];
|
|
50
|
+
requiresFeedback: boolean;
|
|
51
|
+
summary: {
|
|
52
|
+
totalWarnings: number;
|
|
53
|
+
warningsByType: Record<PayloadWarningType, number>;
|
|
54
|
+
suspiciousChanges: number;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export declare class PayloadChangeAnalyzer {
|
|
58
|
+
private config;
|
|
59
|
+
constructor(config?: Partial<PayloadAnalyzerConfig>);
|
|
60
|
+
analyzeChangeRequest<P = any>(originalPayload: P, changeRequest: AgentPayloadChangeRequest<P>, resultPayload: P): PayloadAnalysisResult;
|
|
61
|
+
private analyzeChanges;
|
|
62
|
+
private analyzeStringChange;
|
|
63
|
+
private analyzeArrayChange;
|
|
64
|
+
private analyzeObjectChange;
|
|
65
|
+
private analyzeRemoval;
|
|
66
|
+
private analyzeTypeChange;
|
|
67
|
+
private detectPatternAnomalies;
|
|
68
|
+
private walkPayload;
|
|
69
|
+
generateFeedbackQuestions(warnings: PayloadWarning[]): string[];
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=PayloadChangeAnalyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PayloadChangeAnalyzer.d.ts","sourceRoot":"","sources":["../src/PayloadChangeAnalyzer.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAKzE,oBAAY,kBAAkB;IAC1B,iBAAiB,uBAAuB;IACxC,UAAU,gBAAgB;IAC1B,UAAU,gBAAgB;IAC1B,cAAc,oBAAoB;IAClC,mBAAmB,yBAAyB;CAC/C;AAKD,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,kBAAkB,CAAC;IACzB,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AE,MAAM,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;QACnD,iBAAiB,EAAE,MAAM,CAAC;KAC7B,CAAC;CACL;AAKD,qBAAa,qBAAqB;IAC9B,OAAO,CAAC,MAAM,CAAwB;gBAE1B,MAAM,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC;IAsB5C,oBAAoB,CAAC,CAAC,GAAG,GAAG,EAC/B,eAAe,EAAE,CAAC,EAClB,aAAa,EAAE,yBAAyB,CAAC,CAAC,CAAC,EAC3C,aAAa,EAAE,CAAC,GACjB,qBAAqB;IA4CxB,OAAO,CAAC,cAAc;IA2BtB,OAAO,CAAC,mBAAmB;IA4D3B,OAAO,CAAC,kBAAkB;IA+C1B,OAAO,CAAC,mBAAmB;IA6D3B,OAAO,CAAC,cAAc;IA+BtB,OAAO,CAAC,iBAAiB;IAiCzB,OAAO,CAAC,sBAAsB;IA4D9B,OAAO,CAAC,WAAW;IA0BZ,yBAAyB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,MAAM,EAAE;CAuCzE"}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.PayloadChangeAnalyzer = exports.PayloadWarningType = void 0;
|
|
27
|
+
const _ = __importStar(require("lodash"));
|
|
28
|
+
var PayloadWarningType;
|
|
29
|
+
(function (PayloadWarningType) {
|
|
30
|
+
PayloadWarningType["ContentTruncation"] = "content_truncation";
|
|
31
|
+
PayloadWarningType["KeyRemoval"] = "key_removal";
|
|
32
|
+
PayloadWarningType["TypeChange"] = "type_change";
|
|
33
|
+
PayloadWarningType["PatternAnomaly"] = "pattern_anomaly";
|
|
34
|
+
PayloadWarningType["UnintendedOverwrite"] = "unintended_overwrite";
|
|
35
|
+
})(PayloadWarningType || (exports.PayloadWarningType = PayloadWarningType = {}));
|
|
36
|
+
class PayloadChangeAnalyzer {
|
|
37
|
+
constructor(config) {
|
|
38
|
+
this.config = {
|
|
39
|
+
contentReductionThreshold: 70,
|
|
40
|
+
minContentLengthForAnalysis: 100,
|
|
41
|
+
arrayReductionThreshold: 50,
|
|
42
|
+
objectKeyReductionThreshold: 50,
|
|
43
|
+
analyzeNestedChanges: true,
|
|
44
|
+
maxAnalysisDepth: 10,
|
|
45
|
+
truncationPatterns: [
|
|
46
|
+
/\.\.\.$/,
|
|
47
|
+
/\[truncated\]/i,
|
|
48
|
+
/\[shortened\]/i,
|
|
49
|
+
/etc\.?$/i,
|
|
50
|
+
/and more/i
|
|
51
|
+
],
|
|
52
|
+
...config
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
analyzeChangeRequest(originalPayload, changeRequest, resultPayload) {
|
|
56
|
+
const warnings = [];
|
|
57
|
+
this.analyzeChanges(originalPayload, resultPayload, changeRequest, [], warnings);
|
|
58
|
+
this.detectPatternAnomalies(originalPayload, resultPayload, warnings);
|
|
59
|
+
const criticalWarnings = warnings.filter(w => w.severity === 'critical' || w.severity === 'high');
|
|
60
|
+
const requiresFeedback = warnings.some(w => w.requiresFeedback);
|
|
61
|
+
const warningsByType = warnings.reduce((acc, warning) => {
|
|
62
|
+
acc[warning.type] = (acc[warning.type] || 0) + 1;
|
|
63
|
+
return acc;
|
|
64
|
+
}, {});
|
|
65
|
+
return {
|
|
66
|
+
warnings,
|
|
67
|
+
criticalWarnings,
|
|
68
|
+
requiresFeedback,
|
|
69
|
+
summary: {
|
|
70
|
+
totalWarnings: warnings.length,
|
|
71
|
+
warningsByType,
|
|
72
|
+
suspiciousChanges: criticalWarnings.length
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
analyzeChanges(original, result, changeRequest, path, warnings) {
|
|
77
|
+
if (path.length > this.config.maxAnalysisDepth)
|
|
78
|
+
return;
|
|
79
|
+
if (typeof original === 'string' && typeof result === 'string') {
|
|
80
|
+
this.analyzeStringChange(original, result, path, warnings);
|
|
81
|
+
}
|
|
82
|
+
else if (Array.isArray(original) && Array.isArray(result)) {
|
|
83
|
+
this.analyzeArrayChange(original, result, path, warnings);
|
|
84
|
+
}
|
|
85
|
+
else if (_.isObject(original) && _.isObject(result)) {
|
|
86
|
+
this.analyzeObjectChange(original, result, changeRequest, path, warnings);
|
|
87
|
+
}
|
|
88
|
+
else if (original !== undefined && result === undefined) {
|
|
89
|
+
this.analyzeRemoval(original, path, warnings);
|
|
90
|
+
}
|
|
91
|
+
else if (typeof original !== typeof result && original !== undefined && result !== undefined) {
|
|
92
|
+
this.analyzeTypeChange(original, result, path, warnings);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
analyzeStringChange(original, result, path, warnings) {
|
|
96
|
+
if (!original || !result)
|
|
97
|
+
return;
|
|
98
|
+
const originalLength = original.length;
|
|
99
|
+
const resultLength = result.length;
|
|
100
|
+
if (originalLength < this.config.minContentLengthForAnalysis)
|
|
101
|
+
return;
|
|
102
|
+
const reductionPercentage = ((originalLength - resultLength) / originalLength) * 100;
|
|
103
|
+
if (reductionPercentage > this.config.contentReductionThreshold) {
|
|
104
|
+
const warning = {
|
|
105
|
+
type: PayloadWarningType.ContentTruncation,
|
|
106
|
+
severity: reductionPercentage > 90 ? 'critical' : 'high',
|
|
107
|
+
path: path.join('.'),
|
|
108
|
+
message: `Content reduced by ${reductionPercentage.toFixed(1)}% (from ${originalLength} to ${resultLength} characters)`,
|
|
109
|
+
requiresFeedback: true,
|
|
110
|
+
details: {
|
|
111
|
+
originalLength,
|
|
112
|
+
newLength: resultLength,
|
|
113
|
+
reductionPercentage,
|
|
114
|
+
contentPreview: {
|
|
115
|
+
before: original.substring(0, 100) + (originalLength > 100 ? '...' : ''),
|
|
116
|
+
after: result.substring(0, 100) + (resultLength > 100 ? '...' : '')
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
warnings.push(warning);
|
|
121
|
+
}
|
|
122
|
+
const hasTruncationPattern = this.config.truncationPatterns.some(pattern => pattern.test(result) && !pattern.test(original));
|
|
123
|
+
if (hasTruncationPattern) {
|
|
124
|
+
warnings.push({
|
|
125
|
+
type: PayloadWarningType.PatternAnomaly,
|
|
126
|
+
severity: 'medium',
|
|
127
|
+
path: path.join('.'),
|
|
128
|
+
message: 'Content appears to be truncated (detected truncation pattern)',
|
|
129
|
+
requiresFeedback: true,
|
|
130
|
+
details: {
|
|
131
|
+
pattern: 'truncation_indicator',
|
|
132
|
+
resultEnding: result.slice(-50)
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
analyzeArrayChange(original, result, path, warnings) {
|
|
138
|
+
const originalLength = original.length;
|
|
139
|
+
const resultLength = result.length;
|
|
140
|
+
if (originalLength === 0)
|
|
141
|
+
return;
|
|
142
|
+
const reductionPercentage = ((originalLength - resultLength) / originalLength) * 100;
|
|
143
|
+
if (reductionPercentage > this.config.arrayReductionThreshold) {
|
|
144
|
+
warnings.push({
|
|
145
|
+
type: PayloadWarningType.PatternAnomaly,
|
|
146
|
+
severity: reductionPercentage > 80 ? 'high' : 'medium',
|
|
147
|
+
path: path.join('.'),
|
|
148
|
+
message: `Array reduced by ${reductionPercentage.toFixed(1)}% (from ${originalLength} to ${resultLength} items)`,
|
|
149
|
+
requiresFeedback: true,
|
|
150
|
+
details: {
|
|
151
|
+
pattern: 'array_reduction',
|
|
152
|
+
originalLength,
|
|
153
|
+
resultLength,
|
|
154
|
+
reductionPercentage
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (this.config.analyzeNestedChanges) {
|
|
159
|
+
const minLength = Math.min(originalLength, resultLength);
|
|
160
|
+
for (let i = 0; i < minLength; i++) {
|
|
161
|
+
this.analyzeChanges(original[i], result[i], {}, [...path, `[${i}]`], warnings);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
analyzeObjectChange(original, result, changeRequest, path, warnings) {
|
|
166
|
+
const originalKeys = Object.keys(original);
|
|
167
|
+
const resultKeys = Object.keys(result);
|
|
168
|
+
const removedKeys = originalKeys.filter(k => !resultKeys.includes(k));
|
|
169
|
+
if (removedKeys.length > 0) {
|
|
170
|
+
const keyReductionPercentage = (removedKeys.length / originalKeys.length) * 100;
|
|
171
|
+
if (keyReductionPercentage > this.config.objectKeyReductionThreshold) {
|
|
172
|
+
const removedWithContent = removedKeys.filter(k => {
|
|
173
|
+
const value = original[k];
|
|
174
|
+
return value !== null && value !== undefined && value !== '';
|
|
175
|
+
});
|
|
176
|
+
if (removedWithContent.length > 0) {
|
|
177
|
+
const warning = {
|
|
178
|
+
type: PayloadWarningType.KeyRemoval,
|
|
179
|
+
severity: keyReductionPercentage > 80 ? 'critical' : 'high',
|
|
180
|
+
path: path.join('.'),
|
|
181
|
+
message: `${removedWithContent.length} non-empty keys removed (${keyReductionPercentage.toFixed(1)}% reduction)`,
|
|
182
|
+
requiresFeedback: true,
|
|
183
|
+
details: {
|
|
184
|
+
removedKeys: removedWithContent,
|
|
185
|
+
hadContent: true,
|
|
186
|
+
contentSize: removedWithContent.reduce((size, key) => {
|
|
187
|
+
const value = original[key];
|
|
188
|
+
return size + (typeof value === 'string' ? value.length : JSON.stringify(value).length);
|
|
189
|
+
}, 0)
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
warnings.push(warning);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (this.config.analyzeNestedChanges) {
|
|
197
|
+
for (const key of resultKeys) {
|
|
198
|
+
if (key in original) {
|
|
199
|
+
this.analyzeChanges(original[key], result[key], changeRequest, [...path, key], warnings);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
analyzeRemoval(original, path, warnings) {
|
|
205
|
+
if (original === null || original === undefined || original === '')
|
|
206
|
+
return;
|
|
207
|
+
const contentSize = typeof original === 'string'
|
|
208
|
+
? original.length
|
|
209
|
+
: JSON.stringify(original).length;
|
|
210
|
+
if (contentSize > 50) {
|
|
211
|
+
warnings.push({
|
|
212
|
+
type: PayloadWarningType.KeyRemoval,
|
|
213
|
+
severity: contentSize > 500 ? 'high' : 'medium',
|
|
214
|
+
path: path.join('.'),
|
|
215
|
+
message: `Non-empty content removed (${contentSize} characters)`,
|
|
216
|
+
requiresFeedback: true,
|
|
217
|
+
details: {
|
|
218
|
+
removedKeys: [path[path.length - 1]],
|
|
219
|
+
hadContent: true,
|
|
220
|
+
contentSize
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
analyzeTypeChange(original, result, path, warnings) {
|
|
226
|
+
const originalType = Array.isArray(original) ? 'array' : typeof original;
|
|
227
|
+
const resultType = Array.isArray(result) ? 'array' : typeof result;
|
|
228
|
+
const isDataLoss = (originalType === 'object' || originalType === 'array') &&
|
|
229
|
+
(resultType === 'string' || resultType === 'number' || resultType === 'boolean');
|
|
230
|
+
if (isDataLoss) {
|
|
231
|
+
warnings.push({
|
|
232
|
+
type: PayloadWarningType.TypeChange,
|
|
233
|
+
severity: 'high',
|
|
234
|
+
path: path.join('.'),
|
|
235
|
+
message: `Type changed from ${originalType} to ${resultType} (potential data loss)`,
|
|
236
|
+
requiresFeedback: true,
|
|
237
|
+
details: {
|
|
238
|
+
originalType,
|
|
239
|
+
newType: resultType,
|
|
240
|
+
dataLoss: true
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
detectPatternAnomalies(original, result, warnings) {
|
|
246
|
+
if (_.isObject(original) && _.isObject(result)) {
|
|
247
|
+
const originalKeys = Object.keys(original);
|
|
248
|
+
const resultKeys = Object.keys(result);
|
|
249
|
+
const missingRatio = (originalKeys.length - resultKeys.length) / originalKeys.length;
|
|
250
|
+
if (missingRatio > 0.3 && originalKeys.length > 5) {
|
|
251
|
+
warnings.push({
|
|
252
|
+
type: PayloadWarningType.PatternAnomaly,
|
|
253
|
+
severity: 'high',
|
|
254
|
+
path: '',
|
|
255
|
+
message: `Significant portion of payload structure missing (${(missingRatio * 100).toFixed(1)}%)`,
|
|
256
|
+
requiresFeedback: true,
|
|
257
|
+
details: {
|
|
258
|
+
pattern: 'partial_state_return',
|
|
259
|
+
originalKeyCount: originalKeys.length,
|
|
260
|
+
resultKeyCount: resultKeys.length,
|
|
261
|
+
missingKeys: originalKeys.filter(k => !resultKeys.includes(k)).slice(0, 10)
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const placeholderPatterns = [
|
|
267
|
+
/^TODO:/i,
|
|
268
|
+
/^TBD$/i,
|
|
269
|
+
/^\[.*\]$/,
|
|
270
|
+
/^<.*>$/
|
|
271
|
+
];
|
|
272
|
+
this.walkPayload(result, [], (value, path) => {
|
|
273
|
+
if (typeof value === 'string' && placeholderPatterns.some(p => p.test(value))) {
|
|
274
|
+
const originalValue = _.get(original, path);
|
|
275
|
+
if (originalValue && typeof originalValue === 'string' && originalValue.length > 50) {
|
|
276
|
+
warnings.push({
|
|
277
|
+
type: PayloadWarningType.PatternAnomaly,
|
|
278
|
+
severity: 'medium',
|
|
279
|
+
path: path.join('.'),
|
|
280
|
+
message: 'Complex content replaced with placeholder',
|
|
281
|
+
requiresFeedback: true,
|
|
282
|
+
details: {
|
|
283
|
+
pattern: 'placeholder_replacement',
|
|
284
|
+
placeholder: value,
|
|
285
|
+
originalLength: originalValue.length
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
walkPayload(obj, path, callback) {
|
|
293
|
+
if (!obj || typeof obj !== 'object') {
|
|
294
|
+
callback(obj, path);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (Array.isArray(obj)) {
|
|
298
|
+
obj.forEach((item, index) => {
|
|
299
|
+
this.walkPayload(item, [...path, `[${index}]`], callback);
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
for (const key in obj) {
|
|
304
|
+
if (obj.hasOwnProperty(key)) {
|
|
305
|
+
this.walkPayload(obj[key], [...path, key], callback);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
generateFeedbackQuestions(warnings) {
|
|
311
|
+
const questions = [];
|
|
312
|
+
const feedbackWarnings = warnings.filter(w => w.requiresFeedback);
|
|
313
|
+
const grouped = _.groupBy(feedbackWarnings, 'type');
|
|
314
|
+
for (const [type, typeWarnings] of Object.entries(grouped)) {
|
|
315
|
+
switch (type) {
|
|
316
|
+
case PayloadWarningType.ContentTruncation:
|
|
317
|
+
const truncations = typeWarnings;
|
|
318
|
+
for (const warning of truncations) {
|
|
319
|
+
questions.push(`Did you intend to reduce the content at "${warning.path}" from ${warning.details.originalLength} to ${warning.details.newLength} characters (${warning.details.reductionPercentage.toFixed(1)}% reduction)?`);
|
|
320
|
+
}
|
|
321
|
+
break;
|
|
322
|
+
case PayloadWarningType.KeyRemoval:
|
|
323
|
+
const removals = typeWarnings;
|
|
324
|
+
for (const warning of removals) {
|
|
325
|
+
questions.push(`Did you intend to remove the following non-empty keys at "${warning.path}": ${warning.details.removedKeys.join(', ')}?`);
|
|
326
|
+
}
|
|
327
|
+
break;
|
|
328
|
+
case PayloadWarningType.TypeChange:
|
|
329
|
+
for (const warning of typeWarnings) {
|
|
330
|
+
questions.push(`Did you intend to change the type at "${warning.path}" from ${warning.details.originalType} to ${warning.details.newType}?`);
|
|
331
|
+
}
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return questions;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
exports.PayloadChangeAnalyzer = PayloadChangeAnalyzer;
|
|
339
|
+
//# sourceMappingURL=PayloadChangeAnalyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PayloadChangeAnalyzer.js","sourceRoot":"","sources":["../src/PayloadChangeAnalyzer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,0CAA4B;AAO5B,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC1B,8DAAwC,CAAA;IACxC,gDAA0B,CAAA;IAC1B,gDAA0B,CAAA;IAC1B,wDAAkC,CAAA;IAClC,kEAA4C,CAAA;AAChD,CAAC,EANW,kBAAkB,kCAAlB,kBAAkB,QAM7B;AAgFD,MAAa,qBAAqB;IAG9B,YAAY,MAAuC;QAC/C,IAAI,CAAC,MAAM,GAAG;YACV,yBAAyB,EAAE,EAAE;YAC7B,2BAA2B,EAAE,GAAG;YAChC,uBAAuB,EAAE,EAAE;YAC3B,2BA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Q,IAAI,EAAE,CAAC;gBACX,KAAK,kBAAkB,CAAC,iBAAiB;oBACrC,MAAM,WAAW,GAAG,YAA0C,CAAC;oBAC/D,KAAK,MAAM,OAAO,IAAI,WAAW,EAAE,CAAC;wBAChC,SAAS,CAAC,IAAI,CACV,4CAA4C,OAAO,CAAC,IAAI,UAAU,OAAO,CAAC,OAAO,CAAC,cAAc,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,gBAAgB,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAChN,CAAC;oBACN,CAAC;oBACD,MAAM;gBAEV,KAAK,kBAAkB,CAAC,UAAU;oBAC9B,MAAM,QAAQ,GAAG,YAAmC,CAAC;oBACrD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;wBAC7B,SAAS,CAAC,IAAI,CACV,6DAA6D,OAAO,CAAC,IAAI,MAAM,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC3H,CAAC;oBACN,CAAC;oBACD,MAAM;gBAEV,KAAK,kBAAkB,CAAC,UAAU;oBAC9B,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;wBACjC,SAAS,CAAC,IAAI,CACV,yCAAyC,OAAO,CAAC,IAAI,UAAU,OAAO,CAAC,OAAO,CAAC,YAAY,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG,CAC/H,CAAC;oBACN,CAAC;oBACD,MAAM;YACd,CAAC;QACL,CAAC;QAED,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AAzcD,sDAycC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare enum DiffChangeType {
|
|
2
|
+
Added = "added",
|
|
3
|
+
Removed = "removed",
|
|
4
|
+
Modified = "modified",
|
|
5
|
+
Unchanged = "unchanged"
|
|
6
|
+
}
|
|
7
|
+
export interface DiffChange {
|
|
8
|
+
path: string;
|
|
9
|
+
type: DiffChangeType;
|
|
10
|
+
oldValue?: any;
|
|
11
|
+
newValue?: any;
|
|
12
|
+
description: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PayloadDiff {
|
|
15
|
+
changes: DiffChange[];
|
|
16
|
+
summary: {
|
|
17
|
+
added: number;
|
|
18
|
+
removed: number;
|
|
19
|
+
modified: number;
|
|
20
|
+
unchanged: number;
|
|
21
|
+
totalPaths: number;
|
|
22
|
+
};
|
|
23
|
+
formatted: string;
|
|
24
|
+
}
|
|
25
|
+
export interface DiffConfig {
|
|
26
|
+
includeUnchanged: boolean;
|
|
27
|
+
maxDepth: number;
|
|
28
|
+
maxStringLength: number;
|
|
29
|
+
includeArrayIndices: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare class PayloadDiffer {
|
|
32
|
+
private config;
|
|
33
|
+
constructor(config?: Partial<DiffConfig>);
|
|
34
|
+
diff<T = any>(oldPayload: T, newPayload: T): PayloadDiff;
|
|
35
|
+
private generateDiff;
|
|
36
|
+
private diffArrays;
|
|
37
|
+
private diffObjects;
|
|
38
|
+
private describeValue;
|
|
39
|
+
private formatDiff;
|
|
40
|
+
generateCompactSummary(diff: PayloadDiff): string;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=PayloadDiff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PayloadDiff.d.ts","sourceRoot":"","sources":["../src/PayloadDiff.ts"],"names":[],"mappings":"AAgBA,oBAAY,cAAc;IACtB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,SAAS,cAAc;CAC1B;AAKD,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,cAAc,CAAC;IACrB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,QAAQ,CAAC,EAAE,GAAG,CAAC;IAEf,WAAW,EAAE,MAAM,CAAC;CACvB;AAKD,MAAM,WAAW,WAAW;IACxB,OAAO,E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