sub-agents-mcp 0.5.2 → 0.5.3
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 +12 -0
- package/dist/index.js +0 -0
- package/package.json +1 -1
- package/dist/execution/ExecutionLimits.d.ts +0 -141
- package/dist/execution/ExecutionLimits.d.ts.map +0 -1
- package/dist/execution/ExecutionLimits.js +0 -231
- package/dist/execution/ExecutionLimits.js.map +0 -1
- package/dist/execution/McpRequestTimeout.d.ts +0 -166
- package/dist/execution/McpRequestTimeout.d.ts.map +0 -1
- package/dist/execution/McpRequestTimeout.js +0 -278
- package/dist/execution/McpRequestTimeout.js.map +0 -1
- package/dist/execution/PromptController.d.ts +0 -92
- package/dist/execution/PromptController.d.ts.map +0 -1
- package/dist/execution/PromptController.js +0 -130
- package/dist/execution/PromptController.js.map +0 -1
- package/dist/execution/TimeoutManager.d.ts +0 -159
- package/dist/execution/TimeoutManager.d.ts.map +0 -1
- package/dist/execution/TimeoutManager.js +0 -283
- package/dist/execution/TimeoutManager.js.map +0 -1
- package/dist/session/ToonConverter.d.ts +0 -172
- package/dist/session/ToonConverter.d.ts.map +0 -1
- package/dist/session/ToonConverter.js +0 -593
- package/dist/session/ToonConverter.js.map +0 -1
- package/dist/session/ToonUtils.d.ts +0 -23
- package/dist/session/ToonUtils.d.ts.map +0 -1
- package/dist/session/ToonUtils.js +0 -75
- package/dist/session/ToonUtils.js.map +0 -1
- package/dist/types/ServerConfig.d.ts +0 -39
- package/dist/types/ServerConfig.d.ts.map +0 -1
- package/dist/types/ServerConfig.js +0 -3
- package/dist/types/ServerConfig.js.map +0 -1
- package/dist/types/index.d.ts +0 -19
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -3
- package/dist/types/index.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TimeoutManager.d.ts","sourceRoot":"","sources":["../../src/execution/TimeoutManager.ts"],"names":[],"mappings":"AA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;;;;OAOG;IACH,aAAa,CACX,WAAW,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,GAAE;QACP,SAAS,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAA;QACzC,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;KAC3B,GACL,cAAc;IAkBjB;;;;OAIG;IACH,SAAS,IAAI,aAAa;IAI1B;;;;OAIG;IACH,gBAAgB,IAAI,MAAM;IAQ1B;;;;OAIG;IACH,eAAe,IAAI;QACjB,gBAAgB,EAAE,MAAM,CAAA;QACxB,sBAAsB,EAAE,MAAM,CAAA;QAC9B,qBAAqB,EAAE,MAAM,CAAA;QAC7B,WAAW,EAAE,MAAM,CAAA;KACpB;IAaD;;;;;OAKG;IACH,qBAAqB,CAAC,aAAa,SAAY,GAAG,MAAM;IAmBxD;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;IAenB;;;;;OAKG;YACW,aAAa;IA0C3B;;;OAGG;IACH,OAAO,CAAC,KAAK,CAKZ;CACF"}
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Timeout management for agent execution with configurable limits and cleanup.
|
|
4
|
-
*
|
|
5
|
-
* Provides timeout enforcement with warning mechanisms, graceful cleanup,
|
|
6
|
-
* and integration with agent execution processes.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.TimeoutManager = exports.DEFAULT_TIMEOUT_CONFIG = void 0;
|
|
10
|
-
const ErrorHandler_1 = require("../utils/ErrorHandler");
|
|
11
|
-
/**
|
|
12
|
-
* Default timeout configuration.
|
|
13
|
-
*/
|
|
14
|
-
exports.DEFAULT_TIMEOUT_CONFIG = {
|
|
15
|
-
defaultTimeoutMs: 30000, // 30 seconds
|
|
16
|
-
warningThresholdPercent: 0.8, // 80%
|
|
17
|
-
enableWarnings: true,
|
|
18
|
-
cleanupGracePeriodMs: 5000, // 5 seconds
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Timeout manager for execution time monitoring and enforcement.
|
|
22
|
-
*
|
|
23
|
-
* Manages timeout enforcement with configurable limits, warning mechanisms,
|
|
24
|
-
* and graceful cleanup for agent execution processes.
|
|
25
|
-
*/
|
|
26
|
-
class TimeoutManager {
|
|
27
|
-
/**
|
|
28
|
-
* Creates a new TimeoutManager instance.
|
|
29
|
-
*
|
|
30
|
-
* @param config - Timeout configuration (uses defaults if not provided)
|
|
31
|
-
*/
|
|
32
|
-
constructor(config = {}) {
|
|
33
|
-
this.activeTimeouts = new Map();
|
|
34
|
-
/**
|
|
35
|
-
* Statistics tracking for timeout optimization.
|
|
36
|
-
* @private
|
|
37
|
-
*/
|
|
38
|
-
this.stats = {
|
|
39
|
-
totalOperations: 0,
|
|
40
|
-
totalCompletions: 0,
|
|
41
|
-
totalCompletionTime: 0,
|
|
42
|
-
totalTimeouts: 0,
|
|
43
|
-
};
|
|
44
|
-
this.config = { ...exports.DEFAULT_TIMEOUT_CONFIG, ...config };
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Starts timeout monitoring for an operation.
|
|
48
|
-
*
|
|
49
|
-
* @param context - Timeout context for the operation
|
|
50
|
-
* @returns Operation ID for tracking
|
|
51
|
-
* @throws {Error} If operation ID is already being tracked
|
|
52
|
-
*/
|
|
53
|
-
startTimeout(context) {
|
|
54
|
-
if (this.activeTimeouts.has(context.operationId)) {
|
|
55
|
-
throw new Error(`Timeout already active for operation: ${context.operationId}`);
|
|
56
|
-
}
|
|
57
|
-
// Set up warning timer if enabled and warning callback provided
|
|
58
|
-
let warningTimer;
|
|
59
|
-
if (this.config.enableWarnings && context.onWarning) {
|
|
60
|
-
const warningDelayMs = context.timeoutMs * this.config.warningThresholdPercent;
|
|
61
|
-
warningTimer = setTimeout(() => {
|
|
62
|
-
const elapsed = Date.now() - context.startTime.getTime();
|
|
63
|
-
const remaining = context.timeoutMs - elapsed;
|
|
64
|
-
context.onWarning?.(remaining);
|
|
65
|
-
}, warningDelayMs);
|
|
66
|
-
}
|
|
67
|
-
// Set up main timeout timer
|
|
68
|
-
const timer = setTimeout(async () => {
|
|
69
|
-
await this.handleTimeout(context);
|
|
70
|
-
}, context.timeoutMs);
|
|
71
|
-
this.activeTimeouts.set(context.operationId, {
|
|
72
|
-
timer,
|
|
73
|
-
warningTimer,
|
|
74
|
-
context,
|
|
75
|
-
});
|
|
76
|
-
return context.operationId;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Clears timeout monitoring for an operation.
|
|
80
|
-
*
|
|
81
|
-
* @param operationId - Operation ID to clear
|
|
82
|
-
* @returns True if timeout was cleared, false if not found
|
|
83
|
-
*/
|
|
84
|
-
clearTimeout(operationId) {
|
|
85
|
-
const timeoutData = this.activeTimeouts.get(operationId);
|
|
86
|
-
if (!timeoutData) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
// Update statistics for successful completion
|
|
90
|
-
this.updateStats(operationId, true);
|
|
91
|
-
clearTimeout(timeoutData.timer);
|
|
92
|
-
if (timeoutData.warningTimer) {
|
|
93
|
-
clearTimeout(timeoutData.warningTimer);
|
|
94
|
-
}
|
|
95
|
-
this.activeTimeouts.delete(operationId);
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Gets the remaining time for an operation.
|
|
100
|
-
*
|
|
101
|
-
* @param operationId - Operation ID to check
|
|
102
|
-
* @returns Remaining time in milliseconds, or null if not found
|
|
103
|
-
*/
|
|
104
|
-
getRemainingTime(operationId) {
|
|
105
|
-
const timeoutData = this.activeTimeouts.get(operationId);
|
|
106
|
-
if (!timeoutData) {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
const elapsed = Date.now() - timeoutData.context.startTime.getTime();
|
|
110
|
-
const remaining = timeoutData.context.timeoutMs - elapsed;
|
|
111
|
-
return Math.max(0, remaining);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Gets the elapsed time for an operation.
|
|
115
|
-
*
|
|
116
|
-
* @param operationId - Operation ID to check
|
|
117
|
-
* @returns Elapsed time in milliseconds, or null if not found
|
|
118
|
-
*/
|
|
119
|
-
getElapsedTime(operationId) {
|
|
120
|
-
const timeoutData = this.activeTimeouts.get(operationId);
|
|
121
|
-
if (!timeoutData) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
return Date.now() - timeoutData.context.startTime.getTime();
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Checks if an operation is currently being tracked.
|
|
128
|
-
*
|
|
129
|
-
* @param operationId - Operation ID to check
|
|
130
|
-
* @returns True if operation is being tracked
|
|
131
|
-
*/
|
|
132
|
-
isActive(operationId) {
|
|
133
|
-
return this.activeTimeouts.has(operationId);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Gets all active operation IDs.
|
|
137
|
-
*
|
|
138
|
-
* @returns Array of active operation IDs
|
|
139
|
-
*/
|
|
140
|
-
getActiveOperations() {
|
|
141
|
-
return Array.from(this.activeTimeouts.keys());
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Creates a timeout context with default values.
|
|
145
|
-
*
|
|
146
|
-
* @param operationId - Unique operation identifier
|
|
147
|
-
* @param timeoutMs - Timeout duration (uses default if not provided)
|
|
148
|
-
* @param options - Additional context options
|
|
149
|
-
* @returns Timeout context
|
|
150
|
-
*/
|
|
151
|
-
createContext(operationId, timeoutMs, options = {}) {
|
|
152
|
-
const context = {
|
|
153
|
-
operationId,
|
|
154
|
-
startTime: new Date(),
|
|
155
|
-
timeoutMs: timeoutMs ?? this.config.defaultTimeoutMs,
|
|
156
|
-
};
|
|
157
|
-
if (options.onWarning) {
|
|
158
|
-
context.onWarning = options.onWarning;
|
|
159
|
-
}
|
|
160
|
-
if (options.onCleanup) {
|
|
161
|
-
context.onCleanup = options.onCleanup;
|
|
162
|
-
}
|
|
163
|
-
return context;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Gets the current configuration.
|
|
167
|
-
*
|
|
168
|
-
* @returns Timeout configuration
|
|
169
|
-
*/
|
|
170
|
-
getConfig() {
|
|
171
|
-
return { ...this.config };
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Clears all active timeouts.
|
|
175
|
-
*
|
|
176
|
-
* @returns Number of timeouts cleared
|
|
177
|
-
*/
|
|
178
|
-
clearAllTimeouts() {
|
|
179
|
-
const count = this.activeTimeouts.size;
|
|
180
|
-
for (const [operationId] of this.activeTimeouts) {
|
|
181
|
-
this.clearTimeout(operationId);
|
|
182
|
-
}
|
|
183
|
-
return count;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Gets timeout statistics for monitoring and optimization.
|
|
187
|
-
*
|
|
188
|
-
* @returns Timeout statistics
|
|
189
|
-
*/
|
|
190
|
-
getTimeoutStats() {
|
|
191
|
-
return {
|
|
192
|
-
activeOperations: this.activeTimeouts.size,
|
|
193
|
-
totalOperationsStarted: this.stats.totalOperations,
|
|
194
|
-
averageCompletionTime: this.stats.totalCompletions > 0
|
|
195
|
-
? this.stats.totalCompletionTime / this.stats.totalCompletions
|
|
196
|
-
: 0,
|
|
197
|
-
timeoutRate: this.stats.totalOperations > 0 ? this.stats.totalTimeouts / this.stats.totalOperations : 0,
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Suggests optimal timeout based on historical data.
|
|
202
|
-
*
|
|
203
|
-
* @param operationType - Type of operation for historical analysis (reserved for future use)
|
|
204
|
-
* @returns Suggested timeout in milliseconds
|
|
205
|
-
*/
|
|
206
|
-
suggestOptimalTimeout(operationType = 'default') {
|
|
207
|
-
// operationType is reserved for future use when we implement operation-specific timeouts
|
|
208
|
-
void operationType;
|
|
209
|
-
const stats = this.getTimeoutStats();
|
|
210
|
-
const baseTimeout = this.config.defaultTimeoutMs;
|
|
211
|
-
// If no historical data, use default
|
|
212
|
-
if (stats.averageCompletionTime === 0) {
|
|
213
|
-
return baseTimeout;
|
|
214
|
-
}
|
|
215
|
-
// Add buffer based on completion time and timeout rate
|
|
216
|
-
const bufferMultiplier = 1 + stats.timeoutRate * 2; // More buffer for higher timeout rates
|
|
217
|
-
const suggestedTimeout = stats.averageCompletionTime * bufferMultiplier;
|
|
218
|
-
// Ensure it's within reasonable bounds
|
|
219
|
-
return Math.max(Math.min(suggestedTimeout, baseTimeout * 3), baseTimeout * 0.5);
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Updates timeout statistics.
|
|
223
|
-
*
|
|
224
|
-
* @param operationId - Operation that completed/timed out
|
|
225
|
-
* @param completed - Whether operation completed successfully
|
|
226
|
-
* @private
|
|
227
|
-
*/
|
|
228
|
-
updateStats(operationId, completed) {
|
|
229
|
-
const timeoutData = this.activeTimeouts.get(operationId);
|
|
230
|
-
if (!timeoutData)
|
|
231
|
-
return;
|
|
232
|
-
this.stats.totalOperations++;
|
|
233
|
-
if (completed) {
|
|
234
|
-
this.stats.totalCompletions++;
|
|
235
|
-
const completionTime = Date.now() - timeoutData.context.startTime.getTime();
|
|
236
|
-
this.stats.totalCompletionTime += completionTime;
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
this.stats.totalTimeouts++;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Handles timeout event with cleanup and error throwing.
|
|
244
|
-
*
|
|
245
|
-
* @param context - Timeout context
|
|
246
|
-
* @private
|
|
247
|
-
*/
|
|
248
|
-
async handleTimeout(context) {
|
|
249
|
-
// Update statistics
|
|
250
|
-
this.updateStats(context.operationId, false);
|
|
251
|
-
// Remove from active timeouts
|
|
252
|
-
this.activeTimeouts.delete(context.operationId);
|
|
253
|
-
// Perform cleanup if provided
|
|
254
|
-
if (context.onCleanup) {
|
|
255
|
-
try {
|
|
256
|
-
// Give cleanup a grace period
|
|
257
|
-
const cleanupPromise = context.onCleanup();
|
|
258
|
-
const cleanupTimeout = new Promise((_, reject) => {
|
|
259
|
-
setTimeout(() => {
|
|
260
|
-
reject(new Error('Cleanup timeout exceeded'));
|
|
261
|
-
}, this.config.cleanupGracePeriodMs);
|
|
262
|
-
});
|
|
263
|
-
await Promise.race([cleanupPromise, cleanupTimeout]);
|
|
264
|
-
}
|
|
265
|
-
catch (cleanupError) {
|
|
266
|
-
// Log cleanup error but don't prevent timeout error from being thrown
|
|
267
|
-
console.error(`Cleanup failed for operation ${context.operationId}:`, cleanupError);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
// Throw timeout error with enhanced context
|
|
271
|
-
const elapsed = Date.now() - context.startTime.getTime();
|
|
272
|
-
throw new ErrorHandler_1.TimeoutError(`Operation timed out after ${elapsed}ms (limit: ${context.timeoutMs}ms)`, 'EXECUTION_TIMEOUT', context.timeoutMs, {
|
|
273
|
-
operation: 'timeout_handling',
|
|
274
|
-
metadata: {
|
|
275
|
-
operationId: context.operationId,
|
|
276
|
-
actualDuration: elapsed,
|
|
277
|
-
configuredTimeout: context.timeoutMs,
|
|
278
|
-
},
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
exports.TimeoutManager = TimeoutManager;
|
|
283
|
-
//# sourceMappingURL=TimeoutManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TimeoutManager.js","sourceRoot":"","sources":["../../src/execution/TimeoutManager.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yDAAqD;AAuCrD;;GAEG;AACU,QAAA,sBAAsB,GAAkB;IACnD,gBAAgB,EAAE,KAAK,EAAE,aAAa;IACtC,uBAAuB,EAAE,GAAG,EAAE,MAAM;IACpC,cAAc,EAAE,IAAI;IACpB,oBAAoB,EAAE,IAAI,EAAE,YAAY;CACzC,CAAA;AAED;;;;;GAKG;AACH,MAAa,cAAc;IAWzB;;;;OAIG;IACH,YAAY,SAAiC,EAAE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EAAsE;gBACtE,OAAO,CAAC,KAAK,CAAC,gCAAgC,OAAO,CAAC,WAAW,GAAG,EAAE,YAAY,CAAC,CAAA;YACrF,CAAC;QACH,CAAC;QAED,4CAA4C;QAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,CAAA;QACxD,MAAM,IAAI,2BAAY,CACpB,6BAA6B,OAAO,cAAc,OAAO,CAAC,SAAS,KAAK,EACxE,mBAAmB,EACnB,OAAO,CAAC,SAAS,EACjB;YACE,SAAS,EAAE,kBAAkB;YAC7B,QAAQ,EAAE;gBACR,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,cAAc,EAAE,OAAO;gBACvB,iBAAiB,EAAE,OAAO,CAAC,SAAS;aACrC;SACF,CACF,CAAA;IACH,CAAC;CAYF;AA3TD,wCA2TC"}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TOON (Token Optimized Object Notation) converter utility.
|
|
3
|
-
*
|
|
4
|
-
* Converts JSON data to TOON format to reduce token consumption by 30-60%.
|
|
5
|
-
*
|
|
6
|
-
* Key optimizations:
|
|
7
|
-
* - Shortened key names (sessionId → sid, timestamp → ts, etc.)
|
|
8
|
-
* - Compact timestamp format (removes separators: 20250121 120000)
|
|
9
|
-
* - Filters out empty strings and empty arrays
|
|
10
|
-
* - Inline object representation {key:value,key2:value2}
|
|
11
|
-
* - Array format [count,]{item1,item2}
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const sessionData = {
|
|
16
|
-
* sessionId: 'abc123',
|
|
17
|
-
* agentType: 'rule-advisor',
|
|
18
|
-
* history: [...],
|
|
19
|
-
* createdAt: new Date('2025-01-21T12:00:00Z'),
|
|
20
|
-
* lastUpdatedAt: new Date('2025-01-21T12:00:00Z')
|
|
21
|
-
* }
|
|
22
|
-
* const toonStr = ToonConverter.convertToToon(sessionData)
|
|
23
|
-
* // Output: sid:abc123,agt:rule-advisor,h:[1,]{...},cat:20250121 120000,uat:20250121 120000
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare class ToonConverter {
|
|
27
|
-
/**
|
|
28
|
-
* Converts JSON-compatible data to TOON format.
|
|
29
|
-
*
|
|
30
|
-
* TOON format features:
|
|
31
|
-
* - Removes quotes from keys
|
|
32
|
-
* - Uses compact array notation: [length,] { items }
|
|
33
|
-
* - Reduces unnecessary brackets and commas
|
|
34
|
-
* - Maintains data structure and readability
|
|
35
|
-
*
|
|
36
|
-
* @param jsonData - JSON-compatible data to convert
|
|
37
|
-
* @returns TOON-formatted string
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* const data = { sessionId: 'abc123', agentType: 'rule-advisor' }
|
|
42
|
-
* const toon = ToonConverter.convertToToon(data)
|
|
43
|
-
* // Returns: "sessionId: abc123\nagentType: rule-advisor"
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
static convertToToon(jsonData: unknown): string;
|
|
47
|
-
/**
|
|
48
|
-
* Map of common long keys to short keys for token reduction.
|
|
49
|
-
* @private
|
|
50
|
-
*/
|
|
51
|
-
private static readonly KEY_MAP;
|
|
52
|
-
/**
|
|
53
|
-
* Recursively converts a value to TOON format string.
|
|
54
|
-
*
|
|
55
|
-
* @param value - Value to convert
|
|
56
|
-
* @param depth - Current nesting depth for indentation
|
|
57
|
-
* @returns TOON-formatted string
|
|
58
|
-
* @private
|
|
59
|
-
*/
|
|
60
|
-
private static toToonString;
|
|
61
|
-
/**
|
|
62
|
-
* Converts an object to compact TOON format (for array items).
|
|
63
|
-
*
|
|
64
|
-
* @param value - Object to convert
|
|
65
|
-
* @returns Compact TOON string
|
|
66
|
-
* @private
|
|
67
|
-
*/
|
|
68
|
-
private static toToonObjectCompact;
|
|
69
|
-
/**
|
|
70
|
-
* Formats a Date object to compact timestamp format.
|
|
71
|
-
*
|
|
72
|
-
* Converts ISO 8601 timestamp to compact format:
|
|
73
|
-
* - Input: 2025-01-21T12:00:00.000Z
|
|
74
|
-
* - Output: 20250121 120000
|
|
75
|
-
*
|
|
76
|
-
* This reduces token count by removing separators and milliseconds.
|
|
77
|
-
*
|
|
78
|
-
* @param date - Date object to format
|
|
79
|
-
* @returns Compact timestamp string
|
|
80
|
-
* @private
|
|
81
|
-
*/
|
|
82
|
-
private static formatCompactTimestamp;
|
|
83
|
-
/**
|
|
84
|
-
* Checks if a string value needs to be quoted in TOON format.
|
|
85
|
-
*
|
|
86
|
-
* Strings are quoted if they contain:
|
|
87
|
-
* - Spaces
|
|
88
|
-
* - Special characters (except hyphen and underscore)
|
|
89
|
-
* - Start with a number
|
|
90
|
-
* - Reserved keywords (null, undefined, true, false)
|
|
91
|
-
*
|
|
92
|
-
* @param value - String value to check
|
|
93
|
-
* @returns True if the string needs quotes
|
|
94
|
-
* @private
|
|
95
|
-
*/
|
|
96
|
-
private static needsQuotes;
|
|
97
|
-
/**
|
|
98
|
-
* Converts TOON format string back to JSON-compatible data.
|
|
99
|
-
*
|
|
100
|
-
* This method reverses the convertToToon operation, restoring the original data structure.
|
|
101
|
-
* - Expands short keys back to full keys
|
|
102
|
-
* - Parses compact timestamps back to Date objects
|
|
103
|
-
* - Reconstructs arrays and objects from TOON notation
|
|
104
|
-
*
|
|
105
|
-
* @param toonString - TOON-formatted string to convert
|
|
106
|
-
* @returns JSON-compatible data
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```typescript
|
|
110
|
-
* const toonStr = "sid:abc123,agt:rule-advisor,h:[1,]{ts:20250121 120000},cat:20250121 120000"
|
|
111
|
-
* const data = ToonConverter.convertToJson(toonStr)
|
|
112
|
-
* // Returns: { sessionId: 'abc123', agentType: 'rule-advisor', history: [...], ... }
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
static convertToJson(toonString: string): unknown;
|
|
116
|
-
/**
|
|
117
|
-
* Reverse map from short keys to original keys.
|
|
118
|
-
* @private
|
|
119
|
-
*/
|
|
120
|
-
private static readonly REVERSE_KEY_MAP;
|
|
121
|
-
/**
|
|
122
|
-
* Parses a TOON format string into a JSON-compatible value.
|
|
123
|
-
*
|
|
124
|
-
* @param input - TOON string to parse
|
|
125
|
-
* @returns Parsed value
|
|
126
|
-
* @private
|
|
127
|
-
*/
|
|
128
|
-
private static parseToonString;
|
|
129
|
-
/**
|
|
130
|
-
* Parses a compact timestamp string back to Date object.
|
|
131
|
-
*
|
|
132
|
-
* Converts compact format to ISO 8601:
|
|
133
|
-
* - Input: 20250121 120000
|
|
134
|
-
* - Output: Date('2025-01-21T12:00:00.000Z')
|
|
135
|
-
*
|
|
136
|
-
* @param timestamp - Compact timestamp string
|
|
137
|
-
* @returns Date object
|
|
138
|
-
* @private
|
|
139
|
-
*/
|
|
140
|
-
private static parseCompactTimestamp;
|
|
141
|
-
/**
|
|
142
|
-
* Parses TOON array notation.
|
|
143
|
-
*
|
|
144
|
-
* Format: [length,]item1,item2,item3
|
|
145
|
-
* or [length,]{item1},{item2}
|
|
146
|
-
*
|
|
147
|
-
* @param input - TOON array string
|
|
148
|
-
* @returns Parsed array
|
|
149
|
-
* @private
|
|
150
|
-
*/
|
|
151
|
-
private static parseArray;
|
|
152
|
-
/**
|
|
153
|
-
* Parses TOON object notation.
|
|
154
|
-
*
|
|
155
|
-
* Format: key1:value1,key2:value2
|
|
156
|
-
* or {key1:value1,key2:value2}
|
|
157
|
-
*
|
|
158
|
-
* @param input - TOON object string
|
|
159
|
-
* @returns Parsed object
|
|
160
|
-
* @private
|
|
161
|
-
*/
|
|
162
|
-
private static parseObject;
|
|
163
|
-
/**
|
|
164
|
-
* Parses a key:value pair and adds it to the result object.
|
|
165
|
-
*
|
|
166
|
-
* @param pair - Key:value pair string
|
|
167
|
-
* @param result - Result object to add to
|
|
168
|
-
* @private
|
|
169
|
-
*/
|
|
170
|
-
private static parseKeyValue;
|
|
171
|
-
}
|
|
172
|
-
//# sourceMappingURL=ToonConverter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToonConverter.d.ts","sourceRoot":"","sources":["../../src/session/ToonConverter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,qBAAa,aAAa;IACxB;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM;IAe/C;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAa9B;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAiE3B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAmDlC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;IASrC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAkB1B;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAgBjD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAEtC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAuD9B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAkBpC;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAqEzB;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAkG1B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;CA2C7B"}
|