@codemieai/code 0.0.11 → 0.0.12
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 +20 -98
- package/dist/agents/codemie-code/agent.d.ts.map +1 -1
- package/dist/agents/codemie-code/agent.js +35 -4
- package/dist/agents/codemie-code/agent.js.map +1 -1
- package/dist/agents/codemie-code/tools/index.d.ts.map +1 -1
- package/dist/agents/codemie-code/tools/index.js +5 -3
- package/dist/agents/codemie-code/tools/index.js.map +1 -1
- package/dist/agents/core/AgentCLI.d.ts.map +1 -1
- package/dist/agents/core/AgentCLI.js +57 -11
- package/dist/agents/core/AgentCLI.js.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.d.ts +4 -4
- package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.js +31 -23
- package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
- package/dist/agents/plugins/codemie-code.plugin.js +1 -1
- package/dist/agents/plugins/codemie-code.plugin.js.map +1 -1
- package/dist/agents/plugins/gemini.plugin.js +1 -1
- package/dist/agents/plugins/gemini.plugin.js.map +1 -1
- package/dist/analytics/collector.d.ts +46 -0
- package/dist/analytics/collector.d.ts.map +1 -0
- package/dist/analytics/collector.js +83 -0
- package/dist/analytics/collector.js.map +1 -0
- package/dist/analytics/config.d.ts +14 -0
- package/dist/analytics/config.d.ts.map +1 -0
- package/dist/analytics/config.js +46 -0
- package/dist/analytics/config.js.map +1 -0
- package/dist/analytics/index.d.ts +108 -0
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/index.js +322 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/analytics/plugins/api-metrics.plugin.d.ts +23 -0
- package/dist/analytics/plugins/api-metrics.plugin.d.ts.map +1 -0
- package/dist/analytics/plugins/api-metrics.plugin.js +113 -0
- package/dist/analytics/plugins/api-metrics.plugin.js.map +1 -0
- package/dist/analytics/plugins/index.d.ts +15 -0
- package/dist/analytics/plugins/index.d.ts.map +1 -0
- package/dist/analytics/plugins/index.js +15 -0
- package/dist/analytics/plugins/index.js.map +1 -0
- package/dist/analytics/plugins/model-metrics.plugin.d.ts +36 -0
- package/dist/analytics/plugins/model-metrics.plugin.d.ts.map +1 -0
- package/dist/analytics/plugins/model-metrics.plugin.js +115 -0
- package/dist/analytics/plugins/model-metrics.plugin.js.map +1 -0
- package/dist/analytics/plugins/provider-metrics.plugin.d.ts +38 -0
- package/dist/analytics/plugins/provider-metrics.plugin.d.ts.map +1 -0
- package/dist/analytics/plugins/provider-metrics.plugin.js +138 -0
- package/dist/analytics/plugins/provider-metrics.plugin.js.map +1 -0
- package/dist/analytics/plugins/types.d.ts +63 -0
- package/dist/analytics/plugins/types.d.ts.map +1 -0
- package/dist/analytics/plugins/types.js +54 -0
- package/dist/analytics/plugins/types.js.map +1 -0
- package/dist/analytics/privacy.d.ts +10 -0
- package/dist/analytics/privacy.d.ts.map +1 -0
- package/dist/analytics/privacy.js +20 -0
- package/dist/analytics/privacy.js.map +1 -0
- package/dist/analytics/session.d.ts +56 -0
- package/dist/analytics/session.d.ts.map +1 -0
- package/dist/analytics/session.js +95 -0
- package/dist/analytics/session.js.map +1 -0
- package/dist/analytics/types.d.ts +104 -0
- package/dist/analytics/types.d.ts.map +1 -0
- package/dist/analytics/types.js +15 -0
- package/dist/analytics/types.js.map +1 -0
- package/dist/analytics/writer.d.ts +18 -0
- package/dist/analytics/writer.d.ts.map +1 -0
- package/dist/analytics/writer.js +44 -0
- package/dist/analytics/writer.js.map +1 -0
- package/dist/cli/commands/analytics.d.ts +3 -0
- package/dist/cli/commands/analytics.d.ts.map +1 -0
- package/dist/cli/commands/analytics.js +319 -0
- package/dist/cli/commands/analytics.js.map +1 -0
- package/dist/cli/commands/config.d.ts.map +1 -1
- package/dist/cli/commands/config.js +14 -0
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/profile.d.ts.map +1 -1
- package/dist/cli/commands/profile.js +41 -0
- package/dist/cli/commands/profile.js.map +1 -1
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/env/types.d.ts +2 -0
- package/dist/env/types.d.ts.map +1 -1
- package/dist/env/types.js.map +1 -1
- package/dist/utils/analytics-reader.d.ts +117 -0
- package/dist/utils/analytics-reader.d.ts.map +1 -0
- package/dist/utils/analytics-reader.js +421 -0
- package/dist/utils/analytics-reader.js.map +1 -0
- package/dist/utils/codemie-integration-validator.d.ts.map +1 -1
- package/dist/utils/codemie-integration-validator.js +3 -16
- package/dist/utils/codemie-integration-validator.js.map +1 -1
- package/dist/utils/codemie-proxy.d.ts +80 -0
- package/dist/utils/codemie-proxy.d.ts.map +1 -0
- package/dist/utils/codemie-proxy.js +335 -0
- package/dist/utils/codemie-proxy.js.map +1 -0
- package/dist/utils/config-loader.d.ts +7 -0
- package/dist/utils/config-loader.d.ts.map +1 -1
- package/dist/utils/config-loader.js +18 -0
- package/dist/utils/config-loader.js.map +1 -1
- package/dist/utils/date-formatter.d.ts +88 -0
- package/dist/utils/date-formatter.d.ts.map +1 -0
- package/dist/utils/date-formatter.js +133 -0
- package/dist/utils/date-formatter.js.map +1 -0
- package/dist/utils/installation-id.d.ts +10 -0
- package/dist/utils/installation-id.d.ts.map +1 -0
- package/dist/utils/installation-id.js +30 -0
- package/dist/utils/installation-id.js.map +1 -0
- package/dist/utils/logger.d.ts +1 -15
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +5 -86
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/proxy/errors.d.ts +45 -0
- package/dist/utils/proxy/errors.d.ts.map +1 -0
- package/dist/utils/proxy/errors.js +103 -0
- package/dist/utils/proxy/errors.js.map +1 -0
- package/dist/utils/proxy/http-client.d.ts +46 -0
- package/dist/utils/proxy/http-client.d.ts.map +1 -0
- package/dist/utils/proxy/http-client.js +133 -0
- package/dist/utils/proxy/http-client.js.map +1 -0
- package/dist/utils/proxy/interceptors.d.ts +69 -0
- package/dist/utils/proxy/interceptors.d.ts.map +1 -0
- package/dist/utils/proxy/interceptors.js +319 -0
- package/dist/utils/proxy/interceptors.js.map +1 -0
- package/dist/utils/proxy/types.d.ts +45 -0
- package/dist/utils/proxy/types.d.ts.map +1 -0
- package/dist/utils/proxy/types.js +7 -0
- package/dist/utils/proxy/types.js.map +1 -0
- package/package.json +38 -5
- package/dist/utils/sso-gateway.d.ts +0 -75
- package/dist/utils/sso-gateway.d.ts.map +0 -1
- package/dist/utils/sso-gateway.js +0 -453
- package/dist/utils/sso-gateway.js.map +0 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date formatting utilities for analytics
|
|
3
|
+
* Handles UTC to local timezone conversion for display
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Get local date string from UTC date
|
|
7
|
+
* Converts UTC date to user's local timezone and returns YYYY-MM-DD format
|
|
8
|
+
*
|
|
9
|
+
* @param utcDate - Date object or ISO string in UTC
|
|
10
|
+
* @returns Local date string in YYYY-MM-DD format
|
|
11
|
+
*/
|
|
12
|
+
export function getLocalDateString(utcDate = new Date()) {
|
|
13
|
+
const date = typeof utcDate === 'string' ? new Date(utcDate) : utcDate;
|
|
14
|
+
// Get local date components
|
|
15
|
+
const year = date.getFullYear();
|
|
16
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
17
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
18
|
+
return `${year}-${month}-${day}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get UTC date string from date
|
|
22
|
+
* Returns YYYY-MM-DD format in UTC timezone (for file operations)
|
|
23
|
+
*
|
|
24
|
+
* @param date - Date object
|
|
25
|
+
* @returns UTC date string in YYYY-MM-DD format
|
|
26
|
+
*/
|
|
27
|
+
export function getUTCDateString(date = new Date()) {
|
|
28
|
+
return date.toISOString().split('T')[0];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convert local date string to UTC date range
|
|
32
|
+
* Takes a local date (YYYY-MM-DD) and returns the UTC date range that covers it
|
|
33
|
+
*
|
|
34
|
+
* @param localDate - Local date string in YYYY-MM-DD format
|
|
35
|
+
* @returns Object with UTC start and end dates for the local day
|
|
36
|
+
*/
|
|
37
|
+
export function localDateToUTCRange(localDate) {
|
|
38
|
+
// Parse local date as local midnight
|
|
39
|
+
const [year, month, day] = localDate.split('-').map(Number);
|
|
40
|
+
const startOfDay = new Date(year, month - 1, day, 0, 0, 0, 0);
|
|
41
|
+
const endOfDay = new Date(year, month - 1, day, 23, 59, 59, 999);
|
|
42
|
+
return {
|
|
43
|
+
start: startOfDay,
|
|
44
|
+
end: endOfDay
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get local "today" date string
|
|
49
|
+
* Returns today's date in local timezone as YYYY-MM-DD
|
|
50
|
+
*
|
|
51
|
+
* @returns Today's date in local timezone
|
|
52
|
+
*/
|
|
53
|
+
export function getLocalToday() {
|
|
54
|
+
return getLocalDateString(new Date());
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get UTC files needed for a local date
|
|
58
|
+
* Returns array of UTC date strings (YYYY-MM-DD) that might contain events for the local date
|
|
59
|
+
* Accounts for timezone offset potentially spanning two UTC dates
|
|
60
|
+
*
|
|
61
|
+
* @param localDate - Local date string in YYYY-MM-DD format
|
|
62
|
+
* @returns Array of UTC date strings to check
|
|
63
|
+
*/
|
|
64
|
+
export function getUTCFilesForLocalDate(localDate) {
|
|
65
|
+
const { start, end } = localDateToUTCRange(localDate);
|
|
66
|
+
const startUTC = getUTCDateString(start);
|
|
67
|
+
const endUTC = getUTCDateString(end);
|
|
68
|
+
// If timezone offset causes the local day to span two UTC dates, return both
|
|
69
|
+
if (startUTC === endUTC) {
|
|
70
|
+
return [startUTC];
|
|
71
|
+
}
|
|
72
|
+
return [startUTC, endUTC];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get default date range in local timezone
|
|
76
|
+
* Returns last N days in local timezone
|
|
77
|
+
*
|
|
78
|
+
* @param days - Number of days to look back (default: 7)
|
|
79
|
+
* @returns Object with from and to dates in local timezone
|
|
80
|
+
*/
|
|
81
|
+
export function getDefaultLocalDateRange(days = 7) {
|
|
82
|
+
const today = new Date();
|
|
83
|
+
const from = new Date(today);
|
|
84
|
+
from.setDate(from.getDate() - days);
|
|
85
|
+
return {
|
|
86
|
+
from: getLocalDateString(from),
|
|
87
|
+
to: getLocalDateString(today)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Format timestamp for display in local timezone
|
|
92
|
+
* Converts UTC timestamp to local timezone string
|
|
93
|
+
*
|
|
94
|
+
* @param utcTimestamp - ISO timestamp string in UTC
|
|
95
|
+
* @param includeTime - Include time in output (default: true)
|
|
96
|
+
* @returns Formatted date/time string in local timezone
|
|
97
|
+
*/
|
|
98
|
+
export function formatLocalTimestamp(utcTimestamp, includeTime = true) {
|
|
99
|
+
const date = new Date(utcTimestamp);
|
|
100
|
+
if (includeTime) {
|
|
101
|
+
return date.toLocaleString();
|
|
102
|
+
}
|
|
103
|
+
return date.toLocaleDateString();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Convert local date string to UTC dates for file reading
|
|
107
|
+
* Determines which UTC date files to read for a given local date
|
|
108
|
+
*
|
|
109
|
+
* @param localDate - Local date string in YYYY-MM-DD format
|
|
110
|
+
* @returns Array of UTC date strings in YYYY-MM-DD format
|
|
111
|
+
*/
|
|
112
|
+
export function localDateToUTCDates(localDate) {
|
|
113
|
+
return getUTCFilesForLocalDate(localDate);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get local date range that covers UTC date range
|
|
117
|
+
* Expands UTC date range to ensure all local dates are covered
|
|
118
|
+
*
|
|
119
|
+
* @param utcFrom - UTC start date in YYYY-MM-DD format
|
|
120
|
+
* @param utcTo - UTC end date in YYYY-MM-DD format
|
|
121
|
+
* @returns Local date range
|
|
122
|
+
*/
|
|
123
|
+
export function expandUTCRangeToLocal(utcFrom, utcTo) {
|
|
124
|
+
// Parse UTC dates
|
|
125
|
+
const fromDate = new Date(utcFrom + 'T00:00:00.000Z');
|
|
126
|
+
const toDate = new Date(utcTo + 'T23:59:59.999Z');
|
|
127
|
+
// Convert to local dates
|
|
128
|
+
return {
|
|
129
|
+
from: getLocalDateString(fromDate),
|
|
130
|
+
to: getLocalDateString(toDate)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=date-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-formatter.js","sourceRoot":"","sources":["../../src/utils/date-formatter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAyB,IAAI,IAAI,EAAE;IACpE,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAEvE,4BAA4B;IAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3D,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAEpD,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAa,IAAI,IAAI,EAAE;IACtD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AA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B,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAEpC,OAAO;QACL,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC;QAC9B,EAAE,EAAE,kBAAkB,CAAC,KAAK,CAAC;KAC9B,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,YAAoB,EAAE,cAAuB,IAAI;IACpF,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC;IAEpC,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC,cAAc,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAiB;IACnD,OAAO,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAe,EAAE,KAAa;IAClE,kBAAkB;IAClB,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,OAAO,GAAG,gBAAgB,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,GAAG,gBAAgB,CAAC,CAAC;IAElD,yBAAyB;IACzB,OAAO;QACL,IAAI,EAAE,kBAAkB,CAAC,QAAQ,CAAC;QAClC,EAAE,EAAE,kBAAkB,CAAC,MAAM,CAAC;KAC/B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installation ID generator and manager
|
|
3
|
+
* Generates a persistent unique identifier for this CodeMie installation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Get or create installation ID
|
|
7
|
+
* Returns a persistent UUID that uniquely identifies this CodeMie installation
|
|
8
|
+
*/
|
|
9
|
+
export declare function getInstallationId(): Promise<string>;
|
|
10
|
+
//# sourceMappingURL=installation-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installation-id.d.ts","sourceRoot":"","sources":["../../src/utils/installation-id.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH;;;GAGG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAiBzD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installation ID generator and manager
|
|
3
|
+
* Generates a persistent unique identifier for this CodeMie installation
|
|
4
|
+
*/
|
|
5
|
+
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { randomUUID } from 'node:crypto';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
const INSTALLATION_ID_PATH = join(homedir(), '.codemie', 'installation-id');
|
|
10
|
+
/**
|
|
11
|
+
* Get or create installation ID
|
|
12
|
+
* Returns a persistent UUID that uniquely identifies this CodeMie installation
|
|
13
|
+
*/
|
|
14
|
+
export async function getInstallationId() {
|
|
15
|
+
try {
|
|
16
|
+
// Try to read existing ID
|
|
17
|
+
const id = await readFile(INSTALLATION_ID_PATH, 'utf-8');
|
|
18
|
+
return id.trim();
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Generate new ID if file doesn't exist
|
|
22
|
+
const id = randomUUID();
|
|
23
|
+
// Ensure directory exists
|
|
24
|
+
await mkdir(join(homedir(), '.codemie'), { recursive: true });
|
|
25
|
+
// Save for future use
|
|
26
|
+
await writeFile(INSTALLATION_ID_PATH, id, 'utf-8');
|
|
27
|
+
return id;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=installation-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installation-id.js","sourceRoot":"","sources":["../../src/utils/installation-id.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,oBAAoB,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC;AAE5E;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,IAAI,CAAC;QACH,0BAA0B;QAC1B,MAAM,EAAE,GAAG,MAAM,QAAQ,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;QACzD,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QACP,wCAAwC;QACxC,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;QAExB,0BAA0B;QAC1B,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAE9D,sBAAsB;QACtB,MAAM,SAAS,CAAC,oBAAoB,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QAEnD,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/dist/utils/logger.d.ts
CHANGED
|
@@ -5,28 +5,14 @@ export declare enum LogLevel {
|
|
|
5
5
|
ERROR = "error"
|
|
6
6
|
}
|
|
7
7
|
declare class Logger {
|
|
8
|
-
private debugEnabled;
|
|
9
|
-
private debugLogFile;
|
|
10
8
|
private sessionId;
|
|
11
9
|
constructor();
|
|
12
|
-
/**
|
|
13
|
-
* Enable debug mode and initialize debug logging
|
|
14
|
-
* @returns The debug session directory path
|
|
15
|
-
*/
|
|
16
|
-
enableDebugMode(): Promise<string | null>;
|
|
17
|
-
private initializeDebugLogging;
|
|
18
|
-
/**
|
|
19
|
-
* Get the current debug session directory
|
|
20
|
-
* @returns Session directory path or null if debug is not enabled
|
|
21
|
-
*/
|
|
22
|
-
getDebugSessionDir(): string | null;
|
|
23
10
|
/**
|
|
24
11
|
* Get the current session ID (UUID)
|
|
25
12
|
* @returns Session ID (always available)
|
|
26
13
|
*/
|
|
27
14
|
getSessionId(): string;
|
|
28
|
-
|
|
29
|
-
debug(message: string, ...args: unknown[]): void;
|
|
15
|
+
debug(_message: string, ..._args: unknown[]): void;
|
|
30
16
|
info(message: string, ...args: unknown[]): void;
|
|
31
17
|
success(message: string, ...args: unknown[]): void;
|
|
32
18
|
warn(message: string, ...args: unknown[]): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAGA,oBAAY,QAAQ;IAClB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,cAAM,MAAM;IACV,OAAO,CAAC,SAAS,CAAS;;IAO1B;;;OAGG;IACH,YAAY,IAAI,MAAM;IAItB,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI;IAIlD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI/C,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIlD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI/C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,IAAI;CActD;AAED,eAAO,MAAM,MAAM,QAAe,CAAC"}
|
package/dist/utils/logger.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import { promises as fs } from 'fs';
|
|
3
|
-
import { join } from 'path';
|
|
4
|
-
import { homedir } from 'os';
|
|
5
2
|
import { randomUUID } from 'crypto';
|
|
6
3
|
export var LogLevel;
|
|
7
4
|
(function (LogLevel) {
|
|
@@ -11,55 +8,10 @@ export var LogLevel;
|
|
|
11
8
|
LogLevel["ERROR"] = "error";
|
|
12
9
|
})(LogLevel || (LogLevel = {}));
|
|
13
10
|
class Logger {
|
|
14
|
-
debugEnabled;
|
|
15
|
-
debugLogFile = null;
|
|
16
11
|
sessionId;
|
|
17
12
|
constructor() {
|
|
18
|
-
// Always generate session ID
|
|
13
|
+
// Always generate session ID for analytics tracking
|
|
19
14
|
this.sessionId = randomUUID();
|
|
20
|
-
this.debugEnabled = process.env.CODEMIE_DEBUG === 'true' || process.env.CODEMIE_DEBUG === '1';
|
|
21
|
-
if (this.debugEnabled) {
|
|
22
|
-
this.initializeDebugLogging().catch(() => {
|
|
23
|
-
// Silent failure - logging to file is optional
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Enable debug mode and initialize debug logging
|
|
29
|
-
* @returns The debug session directory path
|
|
30
|
-
*/
|
|
31
|
-
async enableDebugMode() {
|
|
32
|
-
if (!this.debugEnabled) {
|
|
33
|
-
this.debugEnabled = true;
|
|
34
|
-
process.env.CODEMIE_DEBUG = '1';
|
|
35
|
-
}
|
|
36
|
-
if (!this.debugLogFile) {
|
|
37
|
-
await this.initializeDebugLogging();
|
|
38
|
-
}
|
|
39
|
-
return this.getDebugSessionDir();
|
|
40
|
-
}
|
|
41
|
-
async initializeDebugLogging() {
|
|
42
|
-
const baseDir = join(homedir(), '.codemie', 'debug');
|
|
43
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
44
|
-
// Use session ID in directory name for easy correlation
|
|
45
|
-
const sessionDir = join(baseDir, `session-${timestamp}-${this.sessionId}`);
|
|
46
|
-
const filename = 'application.log';
|
|
47
|
-
try {
|
|
48
|
-
await fs.mkdir(sessionDir, { recursive: true });
|
|
49
|
-
this.debugLogFile = join(sessionDir, filename);
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
this.debugLogFile = null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get the current debug session directory
|
|
57
|
-
* @returns Session directory path or null if debug is not enabled
|
|
58
|
-
*/
|
|
59
|
-
getDebugSessionDir() {
|
|
60
|
-
if (!this.debugLogFile)
|
|
61
|
-
return null;
|
|
62
|
-
return join(this.debugLogFile, '..');
|
|
63
15
|
}
|
|
64
16
|
/**
|
|
65
17
|
* Get the current session ID (UUID)
|
|
@@ -68,62 +20,29 @@ class Logger {
|
|
|
68
20
|
getSessionId() {
|
|
69
21
|
return this.sessionId;
|
|
70
22
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return;
|
|
74
|
-
try {
|
|
75
|
-
const timestamp = new Date().toISOString();
|
|
76
|
-
const logLine = `[${timestamp}] [${level.toUpperCase()}] ${message}${args.length > 0 ? ' ' + args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(' ') : ''}\n`;
|
|
77
|
-
await fs.appendFile(this.debugLogFile, logLine, 'utf-8');
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
// Silent failure
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
debug(message, ...args) {
|
|
84
|
-
if (this.debugEnabled) {
|
|
85
|
-
this.writeToFile('debug', message, ...args);
|
|
86
|
-
}
|
|
23
|
+
debug(_message, ..._args) {
|
|
24
|
+
// No-op: debug logging removed
|
|
87
25
|
}
|
|
88
26
|
info(message, ...args) {
|
|
89
27
|
console.log(chalk.blueBright(message), ...args);
|
|
90
|
-
if (this.debugEnabled) {
|
|
91
|
-
this.writeToFile('info', message, ...args);
|
|
92
|
-
}
|
|
93
28
|
}
|
|
94
29
|
success(message, ...args) {
|
|
95
30
|
console.log(chalk.green(`✓ ${message}`), ...args);
|
|
96
|
-
if (this.debugEnabled) {
|
|
97
|
-
this.writeToFile('info', `✓ ${message}`, ...args);
|
|
98
|
-
}
|
|
99
31
|
}
|
|
100
32
|
warn(message, ...args) {
|
|
101
33
|
console.warn(chalk.yellow(`⚠ ${message}`), ...args);
|
|
102
|
-
if (this.debugEnabled) {
|
|
103
|
-
this.writeToFile('warn', `⚠ ${message}`, ...args);
|
|
104
|
-
}
|
|
105
34
|
}
|
|
106
35
|
error(message, error) {
|
|
107
36
|
console.error(chalk.red(`✗ ${message}`));
|
|
108
|
-
if (this.debugEnabled) {
|
|
109
|
-
this.writeToFile('error', `✗ ${message}`);
|
|
110
|
-
}
|
|
111
37
|
if (error) {
|
|
112
38
|
if (error instanceof Error) {
|
|
113
39
|
console.error(chalk.red(error.message));
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
if (error.stack) {
|
|
117
|
-
console.error(chalk.white(error.stack));
|
|
118
|
-
this.writeToFile('error', error.stack);
|
|
119
|
-
}
|
|
40
|
+
if (error.stack) {
|
|
41
|
+
console.error(chalk.white(error.stack));
|
|
120
42
|
}
|
|
121
43
|
}
|
|
122
44
|
else {
|
|
123
45
|
console.error(chalk.red(String(error)));
|
|
124
|
-
if (this.debugEnabled) {
|
|
125
|
-
this.writeToFile('error', String(error));
|
|
126
|
-
}
|
|
127
46
|
}
|
|
128
47
|
}
|
|
129
48
|
}
|
package/dist/utils/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"logger.js","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B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;gBACxC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;oBAChB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC1C,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy Error Hierarchy
|
|
3
|
+
*
|
|
4
|
+
* Simple error classes for different failure scenarios.
|
|
5
|
+
* KISS principle: Only essential error types needed for debugging.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base class for all proxy errors
|
|
9
|
+
*/
|
|
10
|
+
export declare class ProxyError extends Error {
|
|
11
|
+
readonly statusCode: number;
|
|
12
|
+
readonly code: string;
|
|
13
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
14
|
+
constructor(message: string, statusCode: number, code: string, details?: Record<string, unknown> | undefined);
|
|
15
|
+
toJSON(): Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Authentication/Authorization errors (401)
|
|
19
|
+
*/
|
|
20
|
+
export declare class AuthenticationError extends ProxyError {
|
|
21
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Network connection errors (502)
|
|
25
|
+
*/
|
|
26
|
+
export declare class NetworkError extends ProxyError {
|
|
27
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Request timeout errors (504)
|
|
31
|
+
*/
|
|
32
|
+
export declare class TimeoutError extends ProxyError {
|
|
33
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Upstream API errors (preserves status code)
|
|
37
|
+
*/
|
|
38
|
+
export declare class UpstreamError extends ProxyError {
|
|
39
|
+
constructor(statusCode: number, message: string, details?: Record<string, unknown>);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Convert unknown errors to ProxyError
|
|
43
|
+
*/
|
|
44
|
+
export declare function normalizeError(error: unknown, context?: Record<string, unknown>): ProxyError;
|
|
45
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/utils/proxy/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;aAGjB,UAAU,EAAE,MAAM;aAClB,IAAI,EAAE,MAAM;aACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAHjD,OAAO,EAAE,MAAM,EACC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;IAOnD,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CASlC;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,UAAU;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI/D;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,UAAU;gBAC9B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI/D;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,UAAU;gBAC9B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI/D;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,UAAU;gBAC/B,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAInF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CA8C5F"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy Error Hierarchy
|
|
3
|
+
*
|
|
4
|
+
* Simple error classes for different failure scenarios.
|
|
5
|
+
* KISS principle: Only essential error types needed for debugging.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base class for all proxy errors
|
|
9
|
+
*/
|
|
10
|
+
export class ProxyError extends Error {
|
|
11
|
+
statusCode;
|
|
12
|
+
code;
|
|
13
|
+
details;
|
|
14
|
+
constructor(message, statusCode, code, details) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.statusCode = statusCode;
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.details = details;
|
|
19
|
+
this.name = 'ProxyError';
|
|
20
|
+
Error.captureStackTrace(this, this.constructor);
|
|
21
|
+
}
|
|
22
|
+
toJSON() {
|
|
23
|
+
return {
|
|
24
|
+
type: this.name,
|
|
25
|
+
code: this.code,
|
|
26
|
+
message: this.message,
|
|
27
|
+
statusCode: this.statusCode,
|
|
28
|
+
...this.details
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Authentication/Authorization errors (401)
|
|
34
|
+
*/
|
|
35
|
+
export class AuthenticationError extends ProxyError {
|
|
36
|
+
constructor(message, details) {
|
|
37
|
+
super(message, 401, 'AUTH_FAILED', details);
|
|
38
|
+
this.name = 'AuthenticationError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Network connection errors (502)
|
|
43
|
+
*/
|
|
44
|
+
export class NetworkError extends ProxyError {
|
|
45
|
+
constructor(message, details) {
|
|
46
|
+
super(message, 502, 'NETWORK_ERROR', details);
|
|
47
|
+
this.name = 'NetworkError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Request timeout errors (504)
|
|
52
|
+
*/
|
|
53
|
+
export class TimeoutError extends ProxyError {
|
|
54
|
+
constructor(message, details) {
|
|
55
|
+
super(message, 504, 'TIMEOUT', details);
|
|
56
|
+
this.name = 'TimeoutError';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Upstream API errors (preserves status code)
|
|
61
|
+
*/
|
|
62
|
+
export class UpstreamError extends ProxyError {
|
|
63
|
+
constructor(statusCode, message, details) {
|
|
64
|
+
super(message, statusCode, 'UPSTREAM_ERROR', details);
|
|
65
|
+
this.name = 'UpstreamError';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Convert unknown errors to ProxyError
|
|
70
|
+
*/
|
|
71
|
+
export function normalizeError(error, context) {
|
|
72
|
+
if (error instanceof ProxyError) {
|
|
73
|
+
return error;
|
|
74
|
+
}
|
|
75
|
+
if (error instanceof Error) {
|
|
76
|
+
// Network errors
|
|
77
|
+
if ('code' in error) {
|
|
78
|
+
const code = error.code;
|
|
79
|
+
if (code === 'ECONNREFUSED' || code === 'ENOTFOUND' || code === 'ECONNRESET') {
|
|
80
|
+
return new NetworkError(`Cannot connect to upstream server: ${error.message}`, {
|
|
81
|
+
originalError: error.message,
|
|
82
|
+
errorCode: code,
|
|
83
|
+
...context
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (code === 'ETIMEDOUT' || error.message.includes('timeout')) {
|
|
87
|
+
return new TimeoutError(`Request timeout: ${error.message}`, {
|
|
88
|
+
originalError: error.message,
|
|
89
|
+
errorCode: code,
|
|
90
|
+
...context
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Generic error
|
|
95
|
+
return new ProxyError(error.message, 500, 'INTERNAL_ERROR', {
|
|
96
|
+
originalError: error.message,
|
|
97
|
+
...context
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// Unknown error type
|
|
101
|
+
return new ProxyError(String(error), 500, 'UNKNOWN_ERROR', { originalError: String(error), ...context });
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/utils/proxy/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IAGjB;IACA;IACA;IAJlB,YACE,OAAe,EACC,UAAkB,EAClB,IAAY,EACZ,OAAiC;QAEjD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,eAAU,GAAV,UAAU,CAAQ;QAClB,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAA0B;QAGjD,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,GAAG,IAAI,CAAC,OAAO;SAChB,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACjD,YAAY,OAAe,EAAE,OAAiC;QAC5D,KAAK,CAAC,OAAO,EAAE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KAAK,CAAC,OAAO;oBAC5B,SAAS,EAAE,IAAI;oBACf,GAAG,OAAO;iBACX,CAAC,CAAC;YACL,CAAC;YAED,IAAI,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9D,OAAO,IAAI,YAAY,CAAC,oBAAoB,KAAK,CAAC,OAAO,EAAE,EAAE;oBAC3D,aAAa,EAAE,KAAK,CAAC,OAAO;oBAC5B,SAAS,EAAE,IAAI;oBACf,GAAG,OAAO;iBACX,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,gBAAgB;QAChB,OAAO,IAAI,UAAU,CACnB,KAAK,CAAC,OAAO,EACb,GAAG,EACH,gBAAgB,EAChB;YACE,aAAa,EAAE,KAAK,CAAC,OAAO;YAC5B,GAAG,OAAO;SACX,CACF,CAAC;IACJ,CAAC;IAED,qBAAqB;IACrB,OAAO,IAAI,UAAU,CACnB,MAAM,CAAC,KAAK,CAAC,EACb,GAAG,EACH,eAAe,EACf,EAAE,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,OAAO,EAAE,CAC7C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple Streaming HTTP Client
|
|
3
|
+
*
|
|
4
|
+
* KISS: Does one thing well - forwards HTTP requests with streaming.
|
|
5
|
+
* Memory efficient: Returns streams directly, no buffering.
|
|
6
|
+
*/
|
|
7
|
+
import http from 'http';
|
|
8
|
+
export interface HTTPClientOptions {
|
|
9
|
+
timeout?: number;
|
|
10
|
+
rejectUnauthorized?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface ForwardRequestOptions {
|
|
13
|
+
method: string;
|
|
14
|
+
headers: Record<string, string>;
|
|
15
|
+
body?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Simple streaming HTTP client for proxy forwarding
|
|
19
|
+
*/
|
|
20
|
+
export declare class ProxyHTTPClient {
|
|
21
|
+
private httpsAgent;
|
|
22
|
+
private httpAgent;
|
|
23
|
+
private timeout;
|
|
24
|
+
constructor(options?: HTTPClientOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Forward request with streaming - no buffering
|
|
27
|
+
* Returns response stream directly for memory efficiency
|
|
28
|
+
*/
|
|
29
|
+
forward(url: URL, options: ForwardRequestOptions): Promise<http.IncomingMessage>;
|
|
30
|
+
/**
|
|
31
|
+
* Stream response to client with backpressure handling
|
|
32
|
+
* Uses Node.js pipeline for automatic backpressure
|
|
33
|
+
*/
|
|
34
|
+
pipeResponse(upstream: http.IncomingMessage, downstream: http.ServerResponse, skipHeaders?: string[]): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Read response body into buffer
|
|
37
|
+
* Only use when body is needed (e.g., for analytics)
|
|
38
|
+
* WARNING: Buffers entire response in memory!
|
|
39
|
+
*/
|
|
40
|
+
readResponseBody(response: http.IncomingMessage): Promise<Buffer>;
|
|
41
|
+
/**
|
|
42
|
+
* Close HTTP client and cleanup agents
|
|
43
|
+
*/
|
|
44
|
+
close(): void;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=http-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../../src/utils/proxy/http-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,UAAU,CAAc;IAChC,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,GAAE,iBAAsB;IAmB3C;;;OAGG;IACG,OAAO,CACX,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC;IAyDhC;;;OAGG;IACG,YAAY,CAChB,QAAQ,EAAE,IAAI,CAAC,eAAe,EAC9B,UAAU,EAAE,IAAI,CAAC,cAAc,EAC/B,WAAW,GAAE,MAAM,EAAwC,GAC1D,OAAO,CAAC,IAAI,CAAC;IAsBhB;;;;OAIG;IACG,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAUvE;;OAEG;IACH,KAAK,IAAI,IAAI;CAId"}
|