@retab/node 0.0.48 → 0.0.52
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 +8 -215
- package/dist/api/client.d.ts +2 -2
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +2 -2
- package/dist/api/documents/client.d.ts +3 -3
- package/dist/api/documents/client.d.ts.map +1 -1
- package/dist/api/documents/client.js +3 -3
- package/dist/api/projects/client.d.ts +15 -0
- package/dist/api/projects/client.d.ts.map +1 -0
- package/dist/api/projects/client.js +43 -0
- package/dist/api/projects/documents/client.d.ts +12 -0
- package/dist/api/projects/documents/client.d.ts.map +1 -0
- package/dist/api/projects/documents/client.js +39 -0
- package/dist/api/projects/iterations/client.d.ts +17 -0
- package/dist/api/projects/iterations/client.d.ts.map +1 -0
- package/dist/api/projects/iterations/client.js +64 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +6 -1
- package/dist/generated_types.d.ts +17837 -40090
- package/dist/generated_types.d.ts.map +1 -1
- package/dist/generated_types.js +309 -979
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/types.d.ts +188 -80
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +22 -1
- package/package.json +6 -9
- package/dist/api/consensus/client.d.ts +0 -7
- package/dist/api/consensus/client.d.ts.map +0 -1
- package/dist/api/consensus/client.js +0 -14
- package/dist/errors.d.ts +0 -34
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -53
- package/dist/resource.d.ts +0 -12
- package/dist/resource.d.ts.map +0 -1
- package/dist/resource.js +0 -19
- package/dist/resources/consensus/completions.d.ts +0 -66
- package/dist/resources/consensus/completions.d.ts.map +0 -1
- package/dist/resources/consensus/completions.js +0 -84
- package/dist/resources/consensus/index.d.ts +0 -72
- package/dist/resources/consensus/index.d.ts.map +0 -1
- package/dist/resources/consensus/index.js +0 -76
- package/dist/resources/consensus/responses.d.ts +0 -69
- package/dist/resources/consensus/responses.d.ts.map +0 -1
- package/dist/resources/consensus/responses.js +0 -99
- package/dist/resources/documents/extractions.d.ts +0 -74
- package/dist/resources/documents/extractions.d.ts.map +0 -1
- package/dist/resources/documents/extractions.js +0 -196
- package/dist/resources/documents/index.d.ts +0 -21
- package/dist/resources/documents/index.d.ts.map +0 -1
- package/dist/resources/documents/index.js +0 -55
- package/dist/resources/evaluations/documents.d.ts +0 -40
- package/dist/resources/evaluations/documents.d.ts.map +0 -1
- package/dist/resources/evaluations/documents.js +0 -123
- package/dist/resources/evaluations/index.d.ts +0 -14
- package/dist/resources/evaluations/index.d.ts.map +0 -1
- package/dist/resources/evaluations/index.js +0 -17
- package/dist/resources/evaluations/iterations.d.ts +0 -50
- package/dist/resources/evaluations/iterations.d.ts.map +0 -1
- package/dist/resources/evaluations/iterations.js +0 -156
- package/dist/resources/files.d.ts +0 -82
- package/dist/resources/files.d.ts.map +0 -1
- package/dist/resources/files.js +0 -150
- package/dist/resources/finetuning.d.ts +0 -105
- package/dist/resources/finetuning.d.ts.map +0 -1
- package/dist/resources/finetuning.js +0 -181
- package/dist/resources/index.d.ts +0 -11
- package/dist/resources/index.d.ts.map +0 -1
- package/dist/resources/index.js +0 -10
- package/dist/resources/models.d.ts +0 -57
- package/dist/resources/models.d.ts.map +0 -1
- package/dist/resources/models.js +0 -72
- package/dist/resources/processors/automations/endpoints.d.ts +0 -90
- package/dist/resources/processors/automations/endpoints.d.ts.map +0 -1
- package/dist/resources/processors/automations/endpoints.js +0 -145
- package/dist/resources/processors/automations/index.d.ts +0 -7
- package/dist/resources/processors/automations/index.d.ts.map +0 -1
- package/dist/resources/processors/automations/index.js +0 -6
- package/dist/resources/processors/automations/links.d.ts +0 -90
- package/dist/resources/processors/automations/links.d.ts.map +0 -1
- package/dist/resources/processors/automations/links.js +0 -149
- package/dist/resources/processors/automations/logs.d.ts +0 -35
- package/dist/resources/processors/automations/logs.d.ts.map +0 -1
- package/dist/resources/processors/automations/logs.js +0 -60
- package/dist/resources/processors/automations/mailboxes.d.ts +0 -102
- package/dist/resources/processors/automations/mailboxes.d.ts.map +0 -1
- package/dist/resources/processors/automations/mailboxes.js +0 -157
- package/dist/resources/processors/automations/outlook.d.ts +0 -114
- package/dist/resources/processors/automations/outlook.d.ts.map +0 -1
- package/dist/resources/processors/automations/outlook.js +0 -170
- package/dist/resources/processors/automations/tests.d.ts +0 -58
- package/dist/resources/processors/automations/tests.d.ts.map +0 -1
- package/dist/resources/processors/automations/tests.js +0 -90
- package/dist/resources/processors/index.d.ts +0 -303
- package/dist/resources/processors/index.d.ts.map +0 -1
- package/dist/resources/processors/index.js +0 -261
- package/dist/resources/schemas.d.ts +0 -63
- package/dist/resources/schemas.d.ts.map +0 -1
- package/dist/resources/schemas.js +0 -183
- package/dist/resources/secrets/external_api_keys.d.ts +0 -61
- package/dist/resources/secrets/external_api_keys.d.ts.map +0 -1
- package/dist/resources/secrets/external_api_keys.js +0 -120
- package/dist/resources/secrets/index.d.ts +0 -14
- package/dist/resources/secrets/index.d.ts.map +0 -1
- package/dist/resources/secrets/index.js +0 -17
- package/dist/resources/secrets/webhooks.d.ts +0 -73
- package/dist/resources/secrets/webhooks.d.ts.map +0 -1
- package/dist/resources/secrets/webhooks.js +0 -145
- package/dist/resources/usage.d.ts +0 -223
- package/dist/resources/usage.d.ts.map +0 -1
- package/dist/resources/usage.js +0 -310
- package/dist/types/ai_models.d.ts +0 -389
- package/dist/types/ai_models.d.ts.map +0 -1
- package/dist/types/ai_models.js +0 -145
- package/dist/types/automations/cron.d.ts +0 -28
- package/dist/types/automations/cron.d.ts.map +0 -1
- package/dist/types/automations/cron.js +0 -1
- package/dist/types/automations/endpoints.d.ts +0 -13
- package/dist/types/automations/endpoints.d.ts.map +0 -1
- package/dist/types/automations/endpoints.js +0 -1
- package/dist/types/automations/index.d.ts +0 -7
- package/dist/types/automations/index.d.ts.map +0 -1
- package/dist/types/automations/index.js +0 -6
- package/dist/types/automations/links.d.ts +0 -15
- package/dist/types/automations/links.d.ts.map +0 -1
- package/dist/types/automations/links.js +0 -1
- package/dist/types/automations/mailboxes.d.ts +0 -18
- package/dist/types/automations/mailboxes.d.ts.map +0 -1
- package/dist/types/automations/mailboxes.js +0 -1
- package/dist/types/automations/outlook.d.ts +0 -37
- package/dist/types/automations/outlook.d.ts.map +0 -1
- package/dist/types/automations/outlook.js +0 -1
- package/dist/types/automations/webhooks.d.ts +0 -13
- package/dist/types/automations/webhooks.d.ts.map +0 -1
- package/dist/types/automations/webhooks.js +0 -1
- package/dist/types/browser_canvas.d.ts +0 -4
- package/dist/types/browser_canvas.d.ts.map +0 -1
- package/dist/types/browser_canvas.js +0 -2
- package/dist/types/chat.d.ts +0 -99
- package/dist/types/chat.d.ts.map +0 -1
- package/dist/types/chat.js +0 -20
- package/dist/types/consensus.d.ts +0 -10
- package/dist/types/consensus.d.ts.map +0 -1
- package/dist/types/consensus.js +0 -1
- package/dist/types/db/annotations.d.ts +0 -108
- package/dist/types/db/annotations.d.ts.map +0 -1
- package/dist/types/db/annotations.js +0 -6
- package/dist/types/db/files.d.ts +0 -133
- package/dist/types/db/files.d.ts.map +0 -1
- package/dist/types/db/files.js +0 -5
- package/dist/types/documents/extractions.d.ts +0 -1849
- package/dist/types/documents/extractions.d.ts.map +0 -1
- package/dist/types/documents/extractions.js +0 -211
- package/dist/types/documents/processing.d.ts +0 -249
- package/dist/types/documents/processing.d.ts.map +0 -1
- package/dist/types/documents/processing.js +0 -6
- package/dist/types/evaluations/iterations.d.ts +0 -41
- package/dist/types/evaluations/iterations.d.ts.map +0 -1
- package/dist/types/evaluations/iterations.js +0 -1
- package/dist/types/jobs/base.d.ts +0 -162
- package/dist/types/jobs/base.d.ts.map +0 -1
- package/dist/types/jobs/base.js +0 -6
- package/dist/types/jobs/specialized.d.ts +0 -200
- package/dist/types/jobs/specialized.d.ts.map +0 -1
- package/dist/types/jobs/specialized.js +0 -37
- package/dist/types/logs.d.ts +0 -92
- package/dist/types/logs.d.ts.map +0 -1
- package/dist/types/logs.js +0 -1
- package/dist/types/mime.d.ts +0 -426
- package/dist/types/mime.d.ts.map +0 -1
- package/dist/types/mime.js +0 -48
- package/dist/types/modalities.d.ts +0 -31
- package/dist/types/modalities.d.ts.map +0 -1
- package/dist/types/modalities.js +0 -109
- package/dist/types/pagination.d.ts +0 -5
- package/dist/types/pagination.d.ts.map +0 -1
- package/dist/types/pagination.js +0 -1
- package/dist/types/schemas/enhancement.d.ts +0 -250
- package/dist/types/schemas/enhancement.d.ts.map +0 -1
- package/dist/types/schemas/enhancement.js +0 -6
- package/dist/types/schemas/generate.d.ts +0 -160
- package/dist/types/schemas/generate.d.ts.map +0 -1
- package/dist/types/schemas/generate.js +0 -19
- package/dist/types/schemas/object.d.ts +0 -116
- package/dist/types/schemas/object.d.ts.map +0 -1
- package/dist/types/schemas/object.js +0 -861
- package/dist/types/secrets/external_api_keys.d.ts +0 -27
- package/dist/types/secrets/external_api_keys.d.ts.map +0 -1
- package/dist/types/secrets/external_api_keys.js +0 -11
- package/dist/types/secrets/index.d.ts +0 -2
- package/dist/types/secrets/index.d.ts.map +0 -1
- package/dist/types/secrets/index.js +0 -1
- package/dist/types/standards.d.ts +0 -37
- package/dist/types/standards.d.ts.map +0 -1
- package/dist/types/standards.js +0 -1
- package/dist/utils/ai_models.d.ts +0 -10
- package/dist/utils/ai_models.d.ts.map +0 -1
- package/dist/utils/ai_models.js +0 -183
- package/dist/utils/batch_processing.d.ts +0 -227
- package/dist/utils/batch_processing.d.ts.map +0 -1
- package/dist/utils/batch_processing.js +0 -268
- package/dist/utils/benchmarking.d.ts +0 -115
- package/dist/utils/benchmarking.d.ts.map +0 -1
- package/dist/utils/benchmarking.js +0 -355
- package/dist/utils/chat.d.ts +0 -70
- package/dist/utils/chat.d.ts.map +0 -1
- package/dist/utils/chat.js +0 -79
- package/dist/utils/cost_calculation.d.ts +0 -26
- package/dist/utils/cost_calculation.d.ts.map +0 -1
- package/dist/utils/cost_calculation.js +0 -99
- package/dist/utils/datasets.d.ts +0 -135
- package/dist/utils/datasets.d.ts.map +0 -1
- package/dist/utils/datasets.js +0 -359
- package/dist/utils/display.d.ts +0 -108
- package/dist/utils/display.d.ts.map +0 -1
- package/dist/utils/display.js +0 -244
- package/dist/utils/hash.d.ts +0 -18
- package/dist/utils/hash.d.ts.map +0 -1
- package/dist/utils/hash.js +0 -31
- package/dist/utils/hashing.d.ts +0 -18
- package/dist/utils/hashing.d.ts.map +0 -1
- package/dist/utils/hashing.js +0 -28
- package/dist/utils/index.d.ts +0 -8
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -10
- package/dist/utils/json_schema.d.ts +0 -18
- package/dist/utils/json_schema.d.ts.map +0 -1
- package/dist/utils/json_schema.js +0 -334
- package/dist/utils/json_schema_utils.d.ts +0 -42
- package/dist/utils/json_schema_utils.d.ts.map +0 -1
- package/dist/utils/json_schema_utils.js +0 -212
- package/dist/utils/jsonl.d.ts +0 -60
- package/dist/utils/jsonl.d.ts.map +0 -1
- package/dist/utils/jsonl.js +0 -259
- package/dist/utils/mime.d.ts +0 -6
- package/dist/utils/mime.d.ts.map +0 -1
- package/dist/utils/mime.js +0 -129
- package/dist/utils/model_cards.d.ts +0 -219
- package/dist/utils/model_cards.d.ts.map +0 -1
- package/dist/utils/model_cards.js +0 -462
- package/dist/utils/prompt_optimization.d.ts +0 -96
- package/dist/utils/prompt_optimization.d.ts.map +0 -1
- package/dist/utils/prompt_optimization.js +0 -275
- package/dist/utils/responses.d.ts +0 -35
- package/dist/utils/responses.d.ts.map +0 -1
- package/dist/utils/responses.js +0 -37
- package/dist/utils/stream.d.ts +0 -13
- package/dist/utils/stream.d.ts.map +0 -1
- package/dist/utils/stream.js +0 -64
- package/dist/utils/stream_context_managers.d.ts +0 -147
- package/dist/utils/stream_context_managers.d.ts.map +0 -1
- package/dist/utils/stream_context_managers.js +0 -380
- package/dist/utils/usage.d.ts +0 -57
- package/dist/utils/usage.d.ts.map +0 -1
- package/dist/utils/usage.js +0 -97
- package/dist/utils/webhook_secrets.d.ts +0 -59
- package/dist/utils/webhook_secrets.d.ts.map +0 -1
- package/dist/utils/webhook_secrets.js +0 -107
- package/dist/utils/zod_to_json_schema.d.ts +0 -11
- package/dist/utils/zod_to_json_schema.d.ts.map +0 -1
- package/dist/utils/zod_to_json_schema.js +0 -123
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prompt optimization utilities for improving AI model performance
|
|
3
|
-
* Equivalent to Python's prompt_optimization.py
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Estimate token count for a prompt (rough approximation)
|
|
7
|
-
*/
|
|
8
|
-
export function estimateTokenCount(text) {
|
|
9
|
-
// Rough estimation: 4 characters per token on average
|
|
10
|
-
return Math.ceil(text.length / 4);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Calculate prompt clarity score based on readability metrics
|
|
14
|
-
*/
|
|
15
|
-
export function calculateClarity(prompt) {
|
|
16
|
-
const sentences = prompt.split(/[.!?]+/).filter(s => s.trim().length > 0);
|
|
17
|
-
const words = prompt.split(/\s+/).filter(w => w.length > 0);
|
|
18
|
-
if (sentences.length === 0 || words.length === 0)
|
|
19
|
-
return 0;
|
|
20
|
-
const avgWordsPerSentence = words.length / sentences.length;
|
|
21
|
-
const avgWordLength = words.reduce((sum, word) => sum + word.length, 0) / words.length;
|
|
22
|
-
// Flesch Reading Ease inspired calculation (simplified)
|
|
23
|
-
const clarityScore = Math.max(0, Math.min(100, 206.835 - (1.015 * avgWordsPerSentence) - (84.6 * avgWordLength / 5)));
|
|
24
|
-
return clarityScore / 100;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Calculate prompt specificity score
|
|
28
|
-
*/
|
|
29
|
-
export function calculateSpecificity(prompt) {
|
|
30
|
-
const specificityKeywords = [
|
|
31
|
-
'specific', 'exactly', 'precise', 'detailed', 'step-by-step',
|
|
32
|
-
'format', 'structure', 'example', 'template', 'must', 'should',
|
|
33
|
-
'required', 'necessary', 'important', 'key', 'essential'
|
|
34
|
-
];
|
|
35
|
-
const words = prompt.toLowerCase().split(/\s+/);
|
|
36
|
-
const specificityWords = words.filter(word => specificityKeywords.some(keyword => word.includes(keyword)));
|
|
37
|
-
return Math.min(1, specificityWords.length / words.length * 10);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Calculate prompt complexity score
|
|
41
|
-
*/
|
|
42
|
-
export function calculateComplexity(prompt) {
|
|
43
|
-
const complexityIndicators = [
|
|
44
|
-
'however', 'although', 'whereas', 'furthermore', 'moreover',
|
|
45
|
-
'consequently', 'therefore', 'nevertheless', 'nonetheless',
|
|
46
|
-
'if', 'unless', 'provided', 'assuming', 'considering'
|
|
47
|
-
];
|
|
48
|
-
const words = prompt.toLowerCase().split(/\s+/);
|
|
49
|
-
const complexWords = words.filter(word => complexityIndicators.some(indicator => word.includes(indicator)));
|
|
50
|
-
const sentences = prompt.split(/[.!?]+/).filter(s => s.trim().length > 0);
|
|
51
|
-
const avgSentenceLength = words.length / sentences.length;
|
|
52
|
-
return Math.min(1, (complexWords.length / words.length * 5) + (avgSentenceLength / 50));
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Estimate cost based on token count and model
|
|
56
|
-
*/
|
|
57
|
-
export function estimateCost(tokenCount, model = 'gpt-4o-mini') {
|
|
58
|
-
// Rough cost estimates per 1K tokens (as of 2024)
|
|
59
|
-
const costPer1KTokens = {
|
|
60
|
-
'gpt-4o': 0.03,
|
|
61
|
-
'gpt-4o-mini': 0.00015,
|
|
62
|
-
'gpt-4': 0.03,
|
|
63
|
-
'gpt-3.5-turbo': 0.002,
|
|
64
|
-
'claude-3-opus': 0.015,
|
|
65
|
-
'claude-3-sonnet': 0.003,
|
|
66
|
-
'claude-3-haiku': 0.00025,
|
|
67
|
-
};
|
|
68
|
-
const rate = costPer1KTokens[model] || 0.002;
|
|
69
|
-
return (tokenCount / 1000) * rate;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Estimate latency based on token count and model
|
|
73
|
-
*/
|
|
74
|
-
export function estimateLatency(tokenCount, model = 'gpt-4o-mini') {
|
|
75
|
-
// Rough latency estimates in milliseconds
|
|
76
|
-
const baseLatency = {
|
|
77
|
-
'gpt-4o': 500,
|
|
78
|
-
'gpt-4o-mini': 300,
|
|
79
|
-
'gpt-4': 800,
|
|
80
|
-
'gpt-3.5-turbo': 200,
|
|
81
|
-
'claude-3-opus': 1000,
|
|
82
|
-
'claude-3-sonnet': 600,
|
|
83
|
-
'claude-3-haiku': 400,
|
|
84
|
-
};
|
|
85
|
-
const base = baseLatency[model] || 400;
|
|
86
|
-
return base + (tokenCount * 2); // ~2ms per token
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Calculate comprehensive prompt metrics
|
|
90
|
-
*/
|
|
91
|
-
export function calculateMetrics(prompt, model = 'gpt-4o-mini') {
|
|
92
|
-
const tokenCount = estimateTokenCount(prompt);
|
|
93
|
-
return {
|
|
94
|
-
tokenCount,
|
|
95
|
-
clarity: calculateClarity(prompt),
|
|
96
|
-
specificity: calculateSpecificity(prompt),
|
|
97
|
-
complexity: calculateComplexity(prompt),
|
|
98
|
-
estimatedCost: estimateCost(tokenCount, model),
|
|
99
|
-
estimatedLatency: estimateLatency(tokenCount, model),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Optimize prompt for brevity while maintaining clarity
|
|
104
|
-
*/
|
|
105
|
-
export function optimizeForBrevity(prompt) {
|
|
106
|
-
return prompt
|
|
107
|
-
// Remove redundant phrases
|
|
108
|
-
.replace(/\b(please|kindly|if you would|if you could)\b/gi, '')
|
|
109
|
-
// Simplify conjunctions
|
|
110
|
-
.replace(/\bin order to\b/gi, 'to')
|
|
111
|
-
.replace(/\bdue to the fact that\b/gi, 'because')
|
|
112
|
-
.replace(/\bat this point in time\b/gi, 'now')
|
|
113
|
-
// Remove excessive politeness
|
|
114
|
-
.replace(/\bthank you\b/gi, '')
|
|
115
|
-
.replace(/\bi would appreciate\b/gi, '')
|
|
116
|
-
// Clean up extra spaces
|
|
117
|
-
.replace(/\s+/g, ' ')
|
|
118
|
-
.trim();
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Optimize prompt for clarity and structure
|
|
122
|
-
*/
|
|
123
|
-
export function optimizeForClarity(prompt) {
|
|
124
|
-
// Add clear structure markers
|
|
125
|
-
let optimized = prompt;
|
|
126
|
-
// Add numbering to instructions if they appear to be steps
|
|
127
|
-
if (prompt.includes('\n') && !prompt.match(/^\d+\./m)) {
|
|
128
|
-
const lines = prompt.split('\n');
|
|
129
|
-
const instructionLines = lines.filter(line => line.trim().length > 0 &&
|
|
130
|
-
(line.includes('please') || line.includes('should') || line.includes('must')));
|
|
131
|
-
if (instructionLines.length > 1) {
|
|
132
|
-
optimized = lines.map((line) => {
|
|
133
|
-
const trimmed = line.trim();
|
|
134
|
-
if (trimmed.length > 0 && instructionLines.includes(line)) {
|
|
135
|
-
return `${instructionLines.indexOf(line) + 1}. ${trimmed}`;
|
|
136
|
-
}
|
|
137
|
-
return line;
|
|
138
|
-
}).join('\n');
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
// Add clear formatting
|
|
142
|
-
optimized = optimized
|
|
143
|
-
.replace(/\b(important|key|essential|critical|note):\s*/gi, '**$1**: ')
|
|
144
|
-
.replace(/\b(example|for example|e\.g\.)\s*/gi, '\n**Example**: ')
|
|
145
|
-
.replace(/\b(format|structure|template)\s*/gi, '\n**$1**: ');
|
|
146
|
-
return optimized;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Optimize prompt for specific AI model characteristics
|
|
150
|
-
*/
|
|
151
|
-
export function optimizeForModel(prompt, model) {
|
|
152
|
-
let optimized = prompt;
|
|
153
|
-
switch (model) {
|
|
154
|
-
case 'gpt-4o':
|
|
155
|
-
case 'gpt-4':
|
|
156
|
-
// GPT-4 responds well to structured prompts
|
|
157
|
-
optimized = optimizeForClarity(prompt);
|
|
158
|
-
break;
|
|
159
|
-
case 'gpt-4o-mini':
|
|
160
|
-
case 'gpt-3.5-turbo':
|
|
161
|
-
// Smaller models benefit from brevity
|
|
162
|
-
optimized = optimizeForBrevity(prompt);
|
|
163
|
-
break;
|
|
164
|
-
case 'claude-3-opus':
|
|
165
|
-
case 'claude-3-sonnet':
|
|
166
|
-
// Claude models prefer more conversational tone
|
|
167
|
-
optimized = prompt.replace(/\byou must\b/gi, 'please');
|
|
168
|
-
break;
|
|
169
|
-
case 'claude-3-haiku':
|
|
170
|
-
// Haiku benefits from very concise prompts
|
|
171
|
-
optimized = optimizeForBrevity(prompt);
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
return optimized;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Main optimization function
|
|
178
|
-
*/
|
|
179
|
-
export function optimizePrompt(prompt, config = {}) {
|
|
180
|
-
const { model = 'gpt-4o-mini', optimizationGoal = 'balanced', preserveStructure = false, } = config;
|
|
181
|
-
const originalMetrics = calculateMetrics(prompt, model);
|
|
182
|
-
let optimized = prompt;
|
|
183
|
-
const improvements = [];
|
|
184
|
-
// Apply optimizations based on goal
|
|
185
|
-
switch (optimizationGoal) {
|
|
186
|
-
case 'accuracy':
|
|
187
|
-
optimized = optimizeForClarity(optimized);
|
|
188
|
-
improvements.push('Enhanced clarity and structure');
|
|
189
|
-
break;
|
|
190
|
-
case 'speed':
|
|
191
|
-
optimized = optimizeForBrevity(optimized);
|
|
192
|
-
improvements.push('Reduced token count for faster processing');
|
|
193
|
-
break;
|
|
194
|
-
case 'cost':
|
|
195
|
-
optimized = optimizeForBrevity(optimized);
|
|
196
|
-
improvements.push('Minimized token usage to reduce costs');
|
|
197
|
-
break;
|
|
198
|
-
case 'balanced':
|
|
199
|
-
optimized = optimizeForModel(optimized, model);
|
|
200
|
-
improvements.push('Balanced optimization for model characteristics');
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
// Apply model-specific optimizations
|
|
204
|
-
if (!preserveStructure) {
|
|
205
|
-
optimized = optimizeForModel(optimized, model);
|
|
206
|
-
improvements.push(`Optimized for ${model} characteristics`);
|
|
207
|
-
}
|
|
208
|
-
const optimizedMetrics = calculateMetrics(optimized, model);
|
|
209
|
-
// Calculate confidence based on improvement metrics
|
|
210
|
-
const tokenImprovement = (originalMetrics.tokenCount - optimizedMetrics.tokenCount) / originalMetrics.tokenCount;
|
|
211
|
-
const clarityImprovement = optimizedMetrics.clarity - originalMetrics.clarity;
|
|
212
|
-
const costImprovement = (originalMetrics.estimatedCost - optimizedMetrics.estimatedCost) / originalMetrics.estimatedCost;
|
|
213
|
-
const confidence = Math.max(0, Math.min(1, (tokenImprovement * 0.3) + (clarityImprovement * 0.4) + (costImprovement * 0.3)));
|
|
214
|
-
return {
|
|
215
|
-
originalPrompt: prompt,
|
|
216
|
-
optimizedPrompt: optimized,
|
|
217
|
-
improvements,
|
|
218
|
-
metrics: {
|
|
219
|
-
before: originalMetrics,
|
|
220
|
-
after: optimizedMetrics,
|
|
221
|
-
},
|
|
222
|
-
confidence,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Test prompt variations and return the best one
|
|
227
|
-
*/
|
|
228
|
-
export async function testPromptVariations(basePrompt, variations, testFunction, // Should return a score
|
|
229
|
-
config = {}) {
|
|
230
|
-
const results = [];
|
|
231
|
-
// Test base prompt
|
|
232
|
-
const baseScore = await testFunction(basePrompt);
|
|
233
|
-
results.push({
|
|
234
|
-
prompt: basePrompt,
|
|
235
|
-
score: baseScore,
|
|
236
|
-
metrics: calculateMetrics(basePrompt, config.model),
|
|
237
|
-
});
|
|
238
|
-
// Test variations
|
|
239
|
-
for (const variation of variations) {
|
|
240
|
-
const score = await testFunction(variation);
|
|
241
|
-
results.push({
|
|
242
|
-
prompt: variation,
|
|
243
|
-
score,
|
|
244
|
-
metrics: calculateMetrics(variation, config.model),
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
// Find best performing variation
|
|
248
|
-
const best = results.reduce((best, current) => current.score > best.score ? current : best);
|
|
249
|
-
const baseMetrics = calculateMetrics(basePrompt, config.model);
|
|
250
|
-
return {
|
|
251
|
-
originalPrompt: basePrompt,
|
|
252
|
-
optimizedPrompt: best.prompt,
|
|
253
|
-
improvements: ['Selected best performing variation from testing'],
|
|
254
|
-
metrics: {
|
|
255
|
-
before: baseMetrics,
|
|
256
|
-
after: best.metrics,
|
|
257
|
-
},
|
|
258
|
-
confidence: 0.9, // High confidence since it's tested
|
|
259
|
-
score: best.score,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
export default {
|
|
263
|
-
estimateTokenCount,
|
|
264
|
-
calculateClarity,
|
|
265
|
-
calculateSpecificity,
|
|
266
|
-
calculateComplexity,
|
|
267
|
-
estimateCost,
|
|
268
|
-
estimateLatency,
|
|
269
|
-
calculateMetrics,
|
|
270
|
-
optimizeForBrevity,
|
|
271
|
-
optimizeForClarity,
|
|
272
|
-
optimizeForModel,
|
|
273
|
-
optimizePrompt,
|
|
274
|
-
testPromptVariations,
|
|
275
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Response processing utilities
|
|
3
|
-
* Equivalent to Python's utils/responses.py
|
|
4
|
-
*/
|
|
5
|
-
export interface ResponseMetadata {
|
|
6
|
-
request_id: string;
|
|
7
|
-
timestamp: Date;
|
|
8
|
-
processing_time_ms: number;
|
|
9
|
-
model_used: string;
|
|
10
|
-
provider: string;
|
|
11
|
-
tokens_used: {
|
|
12
|
-
input: number;
|
|
13
|
-
output: number;
|
|
14
|
-
total: number;
|
|
15
|
-
};
|
|
16
|
-
cost_usd?: number;
|
|
17
|
-
}
|
|
18
|
-
export interface ProcessedResponse<T = any> {
|
|
19
|
-
data: T;
|
|
20
|
-
metadata: ResponseMetadata;
|
|
21
|
-
raw_response?: any;
|
|
22
|
-
validation_errors?: string[];
|
|
23
|
-
confidence_score?: number;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Process raw API response and extract metadata
|
|
27
|
-
*/
|
|
28
|
-
export declare function processResponse<T>(rawResponse: any): ProcessedResponse<T>;
|
|
29
|
-
declare function extractResponseData(rawResponse: any): any;
|
|
30
|
-
declare const _default: {
|
|
31
|
-
processResponse: typeof processResponse;
|
|
32
|
-
extractResponseData: typeof extractResponseData;
|
|
33
|
-
};
|
|
34
|
-
export default _default;
|
|
35
|
-
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/utils/responses.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;IAChB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE;QACX,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,GAAG;IACxC,IAAI,EAAE,CAAC,CAAC;IACR,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAKzE;AAED,iBAAS,mBAAmB,CAAC,WAAW,EAAE,GAAG,GAAG,GAAG,CAKlD;;;;;AAiBD,wBAGE"}
|
package/dist/utils/responses.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Response processing utilities
|
|
3
|
-
* Equivalent to Python's utils/responses.py
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Process raw API response and extract metadata
|
|
7
|
-
*/
|
|
8
|
-
export function processResponse(rawResponse) {
|
|
9
|
-
return {
|
|
10
|
-
data: extractResponseData(rawResponse),
|
|
11
|
-
metadata: extractResponseMetadata(rawResponse),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
function extractResponseData(rawResponse) {
|
|
15
|
-
if (rawResponse.choices && rawResponse.choices.length > 0) {
|
|
16
|
-
return rawResponse.choices[0].message?.content || rawResponse.choices[0].text;
|
|
17
|
-
}
|
|
18
|
-
return rawResponse.content || rawResponse.data || rawResponse;
|
|
19
|
-
}
|
|
20
|
-
function extractResponseMetadata(rawResponse) {
|
|
21
|
-
return {
|
|
22
|
-
request_id: rawResponse.id || 'unknown',
|
|
23
|
-
timestamp: new Date(),
|
|
24
|
-
processing_time_ms: rawResponse.processing_time_ms || 0,
|
|
25
|
-
model_used: rawResponse.model || 'unknown',
|
|
26
|
-
provider: 'unknown',
|
|
27
|
-
tokens_used: {
|
|
28
|
-
input: rawResponse.usage?.prompt_tokens || 0,
|
|
29
|
-
output: rawResponse.usage?.completion_tokens || 0,
|
|
30
|
-
total: rawResponse.usage?.total_tokens || 0,
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export default {
|
|
35
|
-
processResponse,
|
|
36
|
-
extractResponseData,
|
|
37
|
-
};
|
package/dist/utils/stream.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare class StreamContextManager {
|
|
2
|
-
private generator;
|
|
3
|
-
private isFinished;
|
|
4
|
-
constructor(generator: AsyncGenerator<any, void, unknown>);
|
|
5
|
-
[Symbol.asyncIterator](): AsyncGenerator<any, void, unknown>;
|
|
6
|
-
close(): Promise<void>;
|
|
7
|
-
collect(): Promise<any[]>;
|
|
8
|
-
first(): Promise<any | null>;
|
|
9
|
-
last(): Promise<any | null>;
|
|
10
|
-
}
|
|
11
|
-
export declare function createStreamContextManager(generator: AsyncGenerator<any, void, unknown>): StreamContextManager;
|
|
12
|
-
export declare function withStreamContext<T>(generator: AsyncGenerator<any, void, unknown>, handler: (stream: StreamContextManager) => Promise<T>): Promise<T>;
|
|
13
|
-
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,UAAU,CAAkB;gBAExB,SAAS,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC;IAIlD,CAAC,MAAM,CAAC,aAAa,CAAC;IAevB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAWtB,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAQzB,KAAK,IAAI,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IAO5B,IAAI,IAAI,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;CAOlC;AAED,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,oBAAoB,CAE9G;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,SAAS,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,EAC7C,OAAO,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,OAAO,CAAC,CAAC,CAAC,GACpD,OAAO,CAAC,CAAC,CAAC,CAOZ"}
|
package/dist/utils/stream.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
export class StreamContextManager {
|
|
2
|
-
constructor(generator) {
|
|
3
|
-
this.isFinished = false;
|
|
4
|
-
this.generator = generator;
|
|
5
|
-
}
|
|
6
|
-
async *[Symbol.asyncIterator]() {
|
|
7
|
-
try {
|
|
8
|
-
while (!this.isFinished) {
|
|
9
|
-
const { value, done } = await this.generator.next();
|
|
10
|
-
if (done) {
|
|
11
|
-
this.isFinished = true;
|
|
12
|
-
break;
|
|
13
|
-
}
|
|
14
|
-
yield value;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
finally {
|
|
18
|
-
await this.close();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
async close() {
|
|
22
|
-
if (!this.isFinished) {
|
|
23
|
-
try {
|
|
24
|
-
await this.generator.return(undefined);
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
// Ignore errors during cleanup
|
|
28
|
-
}
|
|
29
|
-
this.isFinished = true;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
async collect() {
|
|
33
|
-
const results = [];
|
|
34
|
-
for await (const item of this) {
|
|
35
|
-
results.push(item);
|
|
36
|
-
}
|
|
37
|
-
return results;
|
|
38
|
-
}
|
|
39
|
-
async first() {
|
|
40
|
-
for await (const item of this) {
|
|
41
|
-
return item;
|
|
42
|
-
}
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
async last() {
|
|
46
|
-
let lastItem = null;
|
|
47
|
-
for await (const item of this) {
|
|
48
|
-
lastItem = item;
|
|
49
|
-
}
|
|
50
|
-
return lastItem;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export function createStreamContextManager(generator) {
|
|
54
|
-
return new StreamContextManager(generator);
|
|
55
|
-
}
|
|
56
|
-
export async function withStreamContext(generator, handler) {
|
|
57
|
-
const stream = new StreamContextManager(generator);
|
|
58
|
-
try {
|
|
59
|
-
return await handler(stream);
|
|
60
|
-
}
|
|
61
|
-
finally {
|
|
62
|
-
await stream.close();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stream context management utilities for proper resource cleanup
|
|
3
|
-
* Equivalent to Python's stream_context_managers.py
|
|
4
|
-
*/
|
|
5
|
-
export interface AsyncDisposable {
|
|
6
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
7
|
-
}
|
|
8
|
-
export interface Disposable {
|
|
9
|
-
[Symbol.dispose](): void;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* AsyncGenerator context manager for proper cleanup
|
|
13
|
-
*/
|
|
14
|
-
export declare class AsyncGeneratorContextManager<T> implements AsyncDisposable {
|
|
15
|
-
private generator;
|
|
16
|
-
private isFinalized;
|
|
17
|
-
constructor(generator: AsyncGenerator<T, void, unknown>);
|
|
18
|
-
[Symbol.asyncIterator](): AsyncGenerator<T, void, unknown>;
|
|
19
|
-
next(): Promise<IteratorResult<T, void>>;
|
|
20
|
-
return(value?: void): Promise<IteratorResult<T, void>>;
|
|
21
|
-
throw(error?: any): Promise<IteratorResult<T, void>>;
|
|
22
|
-
private cleanup;
|
|
23
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Synchronous generator context manager
|
|
27
|
-
*/
|
|
28
|
-
export declare class GeneratorContextManager<T> implements Disposable {
|
|
29
|
-
private generator;
|
|
30
|
-
private isFinalized;
|
|
31
|
-
constructor(generator: Generator<T, void, unknown>);
|
|
32
|
-
[Symbol.iterator](): Generator<T, void, unknown>;
|
|
33
|
-
next(): IteratorResult<T, void>;
|
|
34
|
-
return(value?: void): IteratorResult<T, void>;
|
|
35
|
-
throw(error?: any): IteratorResult<T, void>;
|
|
36
|
-
private cleanup;
|
|
37
|
-
[Symbol.dispose](): void;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Decorator to wrap async generator functions with context management
|
|
41
|
-
*/
|
|
42
|
-
export declare function asAsyncContextManager<T extends any[], R>(generatorFunction: (...args: T) => AsyncGenerator<R, void, unknown>): (...args: T) => AsyncGeneratorContextManager<R>;
|
|
43
|
-
/**
|
|
44
|
-
* Decorator to wrap sync generator functions with context management
|
|
45
|
-
*/
|
|
46
|
-
export declare function asContextManager<T extends any[], R>(generatorFunction: (...args: T) => Generator<R, void, unknown>): (...args: T) => GeneratorContextManager<R>;
|
|
47
|
-
/**
|
|
48
|
-
* Stream wrapper that provides automatic cleanup and error handling
|
|
49
|
-
*/
|
|
50
|
-
export declare class StreamWrapper<T> implements AsyncDisposable {
|
|
51
|
-
protected stream: AsyncGenerator<T, void, unknown>;
|
|
52
|
-
protected isActive: boolean;
|
|
53
|
-
private cleanup;
|
|
54
|
-
constructor(stream: AsyncGenerator<T, void, unknown>, cleanup?: () => Promise<void>);
|
|
55
|
-
[Symbol.asyncIterator](): AsyncGenerator<T, void, unknown>;
|
|
56
|
-
close(): Promise<void>;
|
|
57
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Timeout wrapper for streams
|
|
61
|
-
*/
|
|
62
|
-
export declare class StreamTimeoutWrapper<T> extends StreamWrapper<T> {
|
|
63
|
-
private timeout;
|
|
64
|
-
private lastActivity;
|
|
65
|
-
private timeoutId;
|
|
66
|
-
constructor(stream: AsyncGenerator<T, void, unknown>, timeoutMs: number, cleanup?: () => Promise<void>);
|
|
67
|
-
[Symbol.asyncIterator](): AsyncGenerator<T, void, unknown>;
|
|
68
|
-
private startTimeout;
|
|
69
|
-
private clearTimeout;
|
|
70
|
-
private updateActivity;
|
|
71
|
-
close(): Promise<void>;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Batch processing wrapper for streams
|
|
75
|
-
*/
|
|
76
|
-
export declare class StreamBatchProcessor<T> implements AsyncDisposable {
|
|
77
|
-
private stream;
|
|
78
|
-
private batchSize;
|
|
79
|
-
private currentBatch;
|
|
80
|
-
private isActive;
|
|
81
|
-
private cleanup;
|
|
82
|
-
constructor(stream: AsyncGenerator<T, void, unknown>, batchSize: number, cleanup?: () => Promise<void>);
|
|
83
|
-
[Symbol.asyncIterator](): AsyncGenerator<T[], void, unknown>;
|
|
84
|
-
close(): Promise<void>;
|
|
85
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Error recovery wrapper for streams
|
|
89
|
-
*/
|
|
90
|
-
export declare class StreamErrorRecovery<T> extends StreamWrapper<T> {
|
|
91
|
-
private maxRetries;
|
|
92
|
-
private retryCount;
|
|
93
|
-
private errorHandler;
|
|
94
|
-
constructor(stream: AsyncGenerator<T, void, unknown>, maxRetries?: number, errorHandler?: (error: Error) => boolean, cleanup?: () => Promise<void>);
|
|
95
|
-
[Symbol.asyncIterator](): AsyncGenerator<T, void, unknown>;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Utility functions for creating context-managed streams
|
|
99
|
-
*/
|
|
100
|
-
export declare const streamUtils: {
|
|
101
|
-
/**
|
|
102
|
-
* Wrap an async generator with automatic cleanup
|
|
103
|
-
*/
|
|
104
|
-
wrap: <T>(stream: AsyncGenerator<T, void, unknown>, cleanup?: () => Promise<void>) => StreamWrapper<T>;
|
|
105
|
-
/**
|
|
106
|
-
* Add timeout handling to a stream
|
|
107
|
-
*/
|
|
108
|
-
withTimeout: <T>(stream: AsyncGenerator<T, void, unknown>, timeoutMs: number, cleanup?: () => Promise<void>) => StreamTimeoutWrapper<T>;
|
|
109
|
-
/**
|
|
110
|
-
* Add batch processing to a stream
|
|
111
|
-
*/
|
|
112
|
-
withBatching: <T>(stream: AsyncGenerator<T, void, unknown>, batchSize: number, cleanup?: () => Promise<void>) => StreamBatchProcessor<T>;
|
|
113
|
-
/**
|
|
114
|
-
* Add error recovery to a stream
|
|
115
|
-
*/
|
|
116
|
-
withErrorRecovery: <T>(stream: AsyncGenerator<T, void, unknown>, maxRetries?: number, errorHandler?: (error: Error) => boolean, cleanup?: () => Promise<void>) => StreamErrorRecovery<T>;
|
|
117
|
-
};
|
|
118
|
-
declare const _default: {
|
|
119
|
-
AsyncGeneratorContextManager: typeof AsyncGeneratorContextManager;
|
|
120
|
-
GeneratorContextManager: typeof GeneratorContextManager;
|
|
121
|
-
StreamWrapper: typeof StreamWrapper;
|
|
122
|
-
StreamTimeoutWrapper: typeof StreamTimeoutWrapper;
|
|
123
|
-
StreamBatchProcessor: typeof StreamBatchProcessor;
|
|
124
|
-
StreamErrorRecovery: typeof StreamErrorRecovery;
|
|
125
|
-
asAsyncContextManager: typeof asAsyncContextManager;
|
|
126
|
-
asContextManager: typeof asContextManager;
|
|
127
|
-
streamUtils: {
|
|
128
|
-
/**
|
|
129
|
-
* Wrap an async generator with automatic cleanup
|
|
130
|
-
*/
|
|
131
|
-
wrap: <T>(stream: AsyncGenerator<T, void, unknown>, cleanup?: () => Promise<void>) => StreamWrapper<T>;
|
|
132
|
-
/**
|
|
133
|
-
* Add timeout handling to a stream
|
|
134
|
-
*/
|
|
135
|
-
withTimeout: <T>(stream: AsyncGenerator<T, void, unknown>, timeoutMs: number, cleanup?: () => Promise<void>) => StreamTimeoutWrapper<T>;
|
|
136
|
-
/**
|
|
137
|
-
* Add batch processing to a stream
|
|
138
|
-
*/
|
|
139
|
-
withBatching: <T>(stream: AsyncGenerator<T, void, unknown>, batchSize: number, cleanup?: () => Promise<void>) => StreamBatchProcessor<T>;
|
|
140
|
-
/**
|
|
141
|
-
* Add error recovery to a stream
|
|
142
|
-
*/
|
|
143
|
-
withErrorRecovery: <T>(stream: AsyncGenerator<T, void, unknown>, maxRetries?: number, errorHandler?: (error: Error) => boolean, cleanup?: () => Promise<void>) => StreamErrorRecovery<T>;
|
|
144
|
-
};
|
|
145
|
-
};
|
|
146
|
-
export default _default;
|
|
147
|
-
//# sourceMappingURL=stream_context_managers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream_context_managers.d.ts","sourceRoot":"","sources":["../../src/utils/stream_context_managers.ts"],"names":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