@hileeon/mcc 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +229 -127
  2. package/dist/accounts/store.d.ts +12 -0
  3. package/dist/accounts/store.d.ts.map +1 -1
  4. package/dist/accounts/store.js.map +1 -1
  5. package/dist/commands/launch.d.ts +9 -0
  6. package/dist/commands/launch.d.ts.map +1 -0
  7. package/dist/commands/launch.js +162 -0
  8. package/dist/commands/launch.js.map +1 -0
  9. package/dist/commands/mcp.d.ts +9 -0
  10. package/dist/commands/mcp.d.ts.map +1 -0
  11. package/dist/commands/mcp.js +112 -0
  12. package/dist/commands/mcp.js.map +1 -0
  13. package/dist/commands/profile-test.d.ts +17 -0
  14. package/dist/commands/profile-test.d.ts.map +1 -0
  15. package/dist/commands/profile-test.js +188 -0
  16. package/dist/commands/profile-test.js.map +1 -0
  17. package/dist/commands/profile.d.ts +8 -0
  18. package/dist/commands/profile.d.ts.map +1 -0
  19. package/dist/commands/profile.js +125 -0
  20. package/dist/commands/profile.js.map +1 -0
  21. package/dist/core/model-router.d.ts.map +1 -1
  22. package/dist/core/model-router.js +36 -3
  23. package/dist/core/model-router.js.map +1 -1
  24. package/dist/{dashboard-server.d.ts → dashboard/server.d.ts} +1 -1
  25. package/dist/dashboard/server.d.ts.map +1 -0
  26. package/dist/{dashboard-server.js → dashboard/server.js} +254 -48
  27. package/dist/dashboard/server.js.map +1 -0
  28. package/dist/mcc.d.ts +4 -2
  29. package/dist/mcc.d.ts.map +1 -1
  30. package/dist/mcc.js +127 -408
  31. package/dist/mcc.js.map +1 -1
  32. package/dist/mcp/installer.d.ts.map +1 -1
  33. package/dist/mcp/installer.js +5 -2
  34. package/dist/mcp/installer.js.map +1 -1
  35. package/dist/mcp/mcp-config.d.ts +33 -3
  36. package/dist/mcp/mcp-config.d.ts.map +1 -1
  37. package/dist/mcp/mcp-config.js +81 -29
  38. package/dist/mcp/mcp-config.js.map +1 -1
  39. package/dist/proxy/proxy-daemon.d.ts +1 -1
  40. package/dist/proxy/proxy-daemon.d.ts.map +1 -1
  41. package/dist/proxy/proxy-daemon.js +27 -7
  42. package/dist/proxy/proxy-daemon.js.map +1 -1
  43. package/dist/proxy/proxy-entry.js +11 -4
  44. package/dist/proxy/proxy-entry.js.map +1 -1
  45. package/dist/proxy/proxy-paths.d.ts +1 -0
  46. package/dist/proxy/proxy-paths.d.ts.map +1 -1
  47. package/dist/proxy/proxy-paths.js.map +1 -1
  48. package/dist/proxy/proxy-server.d.ts +1 -0
  49. package/dist/proxy/proxy-server.d.ts.map +1 -1
  50. package/dist/proxy/proxy-server.js +114 -6
  51. package/dist/proxy/proxy-server.js.map +1 -1
  52. package/dist/shared/config.d.ts +15 -0
  53. package/dist/shared/config.d.ts.map +1 -0
  54. package/dist/shared/config.js +79 -0
  55. package/dist/shared/config.js.map +1 -0
  56. package/dist/shared/logger.d.ts +23 -18
  57. package/dist/shared/logger.d.ts.map +1 -1
  58. package/dist/shared/logger.js +17 -178
  59. package/dist/shared/logger.js.map +1 -1
  60. package/dist/shared/provider-preset-catalog.d.ts +8 -2
  61. package/dist/shared/provider-preset-catalog.d.ts.map +1 -1
  62. package/dist/shared/provider-preset-catalog.js +61 -31
  63. package/dist/shared/provider-preset-catalog.js.map +1 -1
  64. package/dist/shared/test-image.d.ts +15 -0
  65. package/dist/shared/test-image.d.ts.map +1 -0
  66. package/dist/shared/test-image.js +89 -0
  67. package/dist/shared/test-image.js.map +1 -0
  68. package/dist/ui/assets/index-7kowlJw9.js +40 -0
  69. package/dist/ui/assets/index-DnC-lskL.css +1 -0
  70. package/dist/ui/index.html +21 -13
  71. package/dist/update.d.ts +31 -0
  72. package/dist/update.d.ts.map +1 -0
  73. package/dist/update.js +196 -0
  74. package/dist/update.js.map +1 -0
  75. package/lib/mcp/mcc-image-analysis-server.cjs +454 -454
  76. package/lib/mcp/mcc-websearch-server.cjs +339 -339
  77. package/lib/mcp-hooks/image-analysis-runtime.cjs +563 -510
  78. package/lib/mcp-hooks/image-analyzer-transformer.cjs +526 -526
  79. package/lib/mcp-hooks/websearch-transformer.cjs +1597 -1421
  80. package/lib/proxy/config/config-loader-facade.js +24 -24
  81. package/lib/proxy/glmt/delta-accumulator.js +362 -362
  82. package/lib/proxy/glmt/glmt-transformer.js +203 -203
  83. package/lib/proxy/glmt/index.js +40 -40
  84. package/lib/proxy/glmt/locale-enforcer.js +68 -68
  85. package/lib/proxy/glmt/pipeline/content-transformer.js +161 -161
  86. package/lib/proxy/glmt/pipeline/index.js +19 -19
  87. package/lib/proxy/glmt/pipeline/request-transformer.js +115 -115
  88. package/lib/proxy/glmt/pipeline/response-builder.js +204 -204
  89. package/lib/proxy/glmt/pipeline/stream-parser.js +233 -233
  90. package/lib/proxy/glmt/pipeline/tool-call-handler.js +77 -77
  91. package/lib/proxy/glmt/pipeline/types.js +5 -5
  92. package/lib/proxy/glmt/reasoning-enforcer.js +150 -150
  93. package/lib/proxy/glmt/sse-parser.js +101 -101
  94. package/lib/proxy/services/logging.js +13 -13
  95. package/lib/proxy/transformers/request-transformer.js +471 -471
  96. package/lib/proxy/transformers/sse-stream-transformer.js +198 -198
  97. package/lib/shared/logger.cjs +160 -138
  98. package/package.json +58 -41
  99. package/dist/dashboard-server.d.ts.map +0 -1
  100. package/dist/dashboard-server.js.map +0 -1
  101. package/dist/ui/assets/index-B16lhKZ6.js +0 -40
  102. package/dist/ui/assets/index-jEfiB6-h.css +0 -1
@@ -1,151 +1,151 @@
1
- "use strict";
2
- /**
3
- * ReasoningEnforcer - Inject explicit reasoning instructions into prompts
4
- *
5
- * Purpose: Force GLM models to use structured reasoning output format (<reasoning_content>)
6
- * This complements API parameters (reasoning: true) with explicit prompt instructions.
7
- *
8
- * Strategy:
9
- * 1. If system prompt exists: Prepend reasoning instruction
10
- * 2. If no system prompt: Prepend to first user message
11
- * 3. Select prompt template based on effort level (low/medium/high/max)
12
- * 4. Preserve message structure (string vs array content)
13
- */
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.ReasoningEnforcer = void 0;
16
- class ReasoningEnforcer {
17
- constructor(options = {}) {
18
- this.enabled = options.enabled ?? false; // Opt-in by default
19
- this.prompts = options.prompts || this.getDefaultPrompts();
20
- }
21
- /**
22
- * Inject reasoning instruction into messages
23
- * @param messages - Messages array to modify
24
- * @param thinkingConfig - { thinking: boolean, effort: string }
25
- * @returns Modified messages array
26
- */
27
- injectInstruction(messages, thinkingConfig = {}) {
28
- // Only inject if enabled or thinking explicitly requested
29
- if (!this.enabled && !thinkingConfig.thinking) {
30
- return messages;
31
- }
32
- // Clone messages to avoid mutation
33
- const modifiedMessages = JSON.parse(JSON.stringify(messages));
34
- // Select prompt based on effort level
35
- const effort = (thinkingConfig.effort?.toLowerCase() || 'medium');
36
- const prompt = this.selectPrompt(effort);
37
- // Strategy 1: Inject into system prompt (preferred)
38
- const systemIndex = modifiedMessages.findIndex((m) => m.role === 'system');
39
- if (systemIndex >= 0) {
40
- const systemMsg = modifiedMessages[systemIndex];
41
- if (typeof systemMsg.content === 'string') {
42
- systemMsg.content = `${prompt}\n\n${systemMsg.content}`;
43
- }
44
- else if (Array.isArray(systemMsg.content)) {
45
- systemMsg.content.unshift({
46
- type: 'text',
47
- text: prompt,
48
- });
49
- }
50
- return modifiedMessages;
51
- }
52
- // Strategy 2: Prepend to first user message
53
- const userIndex = modifiedMessages.findIndex((m) => m.role === 'user');
54
- if (userIndex >= 0) {
55
- const userMsg = modifiedMessages[userIndex];
56
- if (typeof userMsg.content === 'string') {
57
- userMsg.content = `${prompt}\n\n${userMsg.content}`;
58
- }
59
- else if (Array.isArray(userMsg.content)) {
60
- userMsg.content.unshift({
61
- type: 'text',
62
- text: prompt,
63
- });
64
- }
65
- return modifiedMessages;
66
- }
67
- // No system or user messages found (edge case)
68
- return modifiedMessages;
69
- }
70
- /**
71
- * Select prompt template based on effort level
72
- */
73
- selectPrompt(effort) {
74
- return this.prompts[effort] || this.prompts.medium;
75
- }
76
- /**
77
- * Get default prompt templates
78
- */
79
- getDefaultPrompts() {
80
- return {
81
- low: `You are an expert reasoning model using GLM-4.6 architecture.
82
-
83
- CRITICAL: Before answering, write 2-3 sentences of reasoning in <reasoning_content> tags.
84
-
85
- OUTPUT FORMAT:
86
- <reasoning_content>
87
- (Brief analysis: what is the problem? what's the approach?)
88
- </reasoning_content>
89
-
90
- (Write your final answer here)`,
91
- medium: `You are an expert reasoning model using GLM-4.6 architecture.
92
-
93
- CRITICAL REQUIREMENTS:
94
- 1. Always think step-by-step before answering
95
- 2. Write your reasoning process explicitly in <reasoning_content> tags
96
- 3. Never skip your chain of thought, even for simple problems
97
-
98
- OUTPUT FORMAT:
99
- <reasoning_content>
100
- (Write your detailed thinking here: analyze the problem, explore approaches,
101
- evaluate trade-offs, and arrive at a conclusion)
102
- </reasoning_content>
103
-
104
- (Write your final answer here based on your reasoning above)`,
105
- high: `You are an expert reasoning model using GLM-4.6 architecture.
106
-
107
- CRITICAL REQUIREMENTS:
108
- 1. Think deeply and systematically before answering
109
- 2. Write comprehensive reasoning in <reasoning_content> tags
110
- 3. Explore multiple approaches and evaluate trade-offs
111
- 4. Show all steps in your problem-solving process
112
-
113
- OUTPUT FORMAT:
114
- <reasoning_content>
115
- (Write exhaustive analysis here:
116
- - Problem decomposition
117
- - Multiple approach exploration
118
- - Trade-off analysis for each approach
119
- - Edge case consideration
120
- - Final conclusion with justification)
121
- </reasoning_content>
122
-
123
- (Write your final answer here based on your systematic reasoning above)`,
124
- max: `You are an expert reasoning model using GLM-4.6 architecture.
125
-
126
- CRITICAL REQUIREMENTS:
127
- 1. Think exhaustively from first principles
128
- 2. Write extremely detailed reasoning in <reasoning_content> tags
129
- 3. Analyze ALL possible angles, approaches, and edge cases
130
- 4. Challenge your own assumptions and explore alternatives
131
- 5. Provide rigorous justification for every claim
132
-
133
- OUTPUT FORMAT:
134
- <reasoning_content>
135
- (Write comprehensive analysis here:
136
- - First principles breakdown
137
- - Exhaustive approach enumeration
138
- - Comparative analysis of all approaches
139
- - Edge case and failure mode analysis
140
- - Assumption validation
141
- - Counter-argument consideration
142
- - Final conclusion with rigorous justification)
143
- </reasoning_content>
144
-
145
- (Write your final answer here based on your exhaustive reasoning above)`,
146
- };
147
- }
148
- }
149
- exports.ReasoningEnforcer = ReasoningEnforcer;
150
- exports.default = ReasoningEnforcer;
1
+ "use strict";
2
+ /**
3
+ * ReasoningEnforcer - Inject explicit reasoning instructions into prompts
4
+ *
5
+ * Purpose: Force GLM models to use structured reasoning output format (<reasoning_content>)
6
+ * This complements API parameters (reasoning: true) with explicit prompt instructions.
7
+ *
8
+ * Strategy:
9
+ * 1. If system prompt exists: Prepend reasoning instruction
10
+ * 2. If no system prompt: Prepend to first user message
11
+ * 3. Select prompt template based on effort level (low/medium/high/max)
12
+ * 4. Preserve message structure (string vs array content)
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ReasoningEnforcer = void 0;
16
+ class ReasoningEnforcer {
17
+ constructor(options = {}) {
18
+ this.enabled = options.enabled ?? false; // Opt-in by default
19
+ this.prompts = options.prompts || this.getDefaultPrompts();
20
+ }
21
+ /**
22
+ * Inject reasoning instruction into messages
23
+ * @param messages - Messages array to modify
24
+ * @param thinkingConfig - { thinking: boolean, effort: string }
25
+ * @returns Modified messages array
26
+ */
27
+ injectInstruction(messages, thinkingConfig = {}) {
28
+ // Only inject if enabled or thinking explicitly requested
29
+ if (!this.enabled && !thinkingConfig.thinking) {
30
+ return messages;
31
+ }
32
+ // Clone messages to avoid mutation
33
+ const modifiedMessages = JSON.parse(JSON.stringify(messages));
34
+ // Select prompt based on effort level
35
+ const effort = (thinkingConfig.effort?.toLowerCase() || 'medium');
36
+ const prompt = this.selectPrompt(effort);
37
+ // Strategy 1: Inject into system prompt (preferred)
38
+ const systemIndex = modifiedMessages.findIndex((m) => m.role === 'system');
39
+ if (systemIndex >= 0) {
40
+ const systemMsg = modifiedMessages[systemIndex];
41
+ if (typeof systemMsg.content === 'string') {
42
+ systemMsg.content = `${prompt}\n\n${systemMsg.content}`;
43
+ }
44
+ else if (Array.isArray(systemMsg.content)) {
45
+ systemMsg.content.unshift({
46
+ type: 'text',
47
+ text: prompt,
48
+ });
49
+ }
50
+ return modifiedMessages;
51
+ }
52
+ // Strategy 2: Prepend to first user message
53
+ const userIndex = modifiedMessages.findIndex((m) => m.role === 'user');
54
+ if (userIndex >= 0) {
55
+ const userMsg = modifiedMessages[userIndex];
56
+ if (typeof userMsg.content === 'string') {
57
+ userMsg.content = `${prompt}\n\n${userMsg.content}`;
58
+ }
59
+ else if (Array.isArray(userMsg.content)) {
60
+ userMsg.content.unshift({
61
+ type: 'text',
62
+ text: prompt,
63
+ });
64
+ }
65
+ return modifiedMessages;
66
+ }
67
+ // No system or user messages found (edge case)
68
+ return modifiedMessages;
69
+ }
70
+ /**
71
+ * Select prompt template based on effort level
72
+ */
73
+ selectPrompt(effort) {
74
+ return this.prompts[effort] || this.prompts.medium;
75
+ }
76
+ /**
77
+ * Get default prompt templates
78
+ */
79
+ getDefaultPrompts() {
80
+ return {
81
+ low: `You are an expert reasoning model using GLM-4.6 architecture.
82
+
83
+ CRITICAL: Before answering, write 2-3 sentences of reasoning in <reasoning_content> tags.
84
+
85
+ OUTPUT FORMAT:
86
+ <reasoning_content>
87
+ (Brief analysis: what is the problem? what's the approach?)
88
+ </reasoning_content>
89
+
90
+ (Write your final answer here)`,
91
+ medium: `You are an expert reasoning model using GLM-4.6 architecture.
92
+
93
+ CRITICAL REQUIREMENTS:
94
+ 1. Always think step-by-step before answering
95
+ 2. Write your reasoning process explicitly in <reasoning_content> tags
96
+ 3. Never skip your chain of thought, even for simple problems
97
+
98
+ OUTPUT FORMAT:
99
+ <reasoning_content>
100
+ (Write your detailed thinking here: analyze the problem, explore approaches,
101
+ evaluate trade-offs, and arrive at a conclusion)
102
+ </reasoning_content>
103
+
104
+ (Write your final answer here based on your reasoning above)`,
105
+ high: `You are an expert reasoning model using GLM-4.6 architecture.
106
+
107
+ CRITICAL REQUIREMENTS:
108
+ 1. Think deeply and systematically before answering
109
+ 2. Write comprehensive reasoning in <reasoning_content> tags
110
+ 3. Explore multiple approaches and evaluate trade-offs
111
+ 4. Show all steps in your problem-solving process
112
+
113
+ OUTPUT FORMAT:
114
+ <reasoning_content>
115
+ (Write exhaustive analysis here:
116
+ - Problem decomposition
117
+ - Multiple approach exploration
118
+ - Trade-off analysis for each approach
119
+ - Edge case consideration
120
+ - Final conclusion with justification)
121
+ </reasoning_content>
122
+
123
+ (Write your final answer here based on your systematic reasoning above)`,
124
+ max: `You are an expert reasoning model using GLM-4.6 architecture.
125
+
126
+ CRITICAL REQUIREMENTS:
127
+ 1. Think exhaustively from first principles
128
+ 2. Write extremely detailed reasoning in <reasoning_content> tags
129
+ 3. Analyze ALL possible angles, approaches, and edge cases
130
+ 4. Challenge your own assumptions and explore alternatives
131
+ 5. Provide rigorous justification for every claim
132
+
133
+ OUTPUT FORMAT:
134
+ <reasoning_content>
135
+ (Write comprehensive analysis here:
136
+ - First principles breakdown
137
+ - Exhaustive approach enumeration
138
+ - Comparative analysis of all approaches
139
+ - Edge case and failure mode analysis
140
+ - Assumption validation
141
+ - Counter-argument consideration
142
+ - Final conclusion with rigorous justification)
143
+ </reasoning_content>
144
+
145
+ (Write your final answer here based on your exhaustive reasoning above)`,
146
+ };
147
+ }
148
+ }
149
+ exports.ReasoningEnforcer = ReasoningEnforcer;
150
+ exports.default = ReasoningEnforcer;
151
151
  //# sourceMappingURL=reasoning-enforcer.js.map
@@ -1,102 +1,102 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- /**
4
- * SSEParser - Parse Server-Sent Events (SSE) stream
5
- *
6
- * Handles:
7
- * - Incomplete events across chunks
8
- * - Multiple events in single chunk
9
- * - Malformed data (skip gracefully)
10
- * - [DONE] marker
11
- *
12
- * Usage:
13
- * const parser = new SSEParser();
14
- * stream.on('data', chunk => {
15
- * const events = parser.parse(chunk);
16
- * events.forEach(event => { ... });
17
- * });
18
- */
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.SSEParser = void 0;
21
- class SSEParser {
22
- constructor(options = {}) {
23
- this.buffer = '';
24
- this.eventCount = 0;
25
- this.maxBufferSize = options.maxBufferSize || 1024 * 1024; // 1MB default
26
- this.throwOnMalformedJson = options.throwOnMalformedJson === true;
27
- }
28
- /**
29
- * Parse chunk and extract SSE events
30
- * @param chunk - Data chunk from stream
31
- * @returns Array of parsed events
32
- */
33
- parse(chunk) {
34
- this.buffer += chunk.toString().replace(/\r\n?/g, '\n');
35
- // C-01 Fix: Prevent unbounded buffer growth (DoS protection)
36
- if (this.buffer.length > this.maxBufferSize) {
37
- throw new Error(`SSE buffer exceeded ${this.maxBufferSize} bytes (DoS protection)`);
38
- }
39
- const events = [];
40
- const segments = this.buffer.split('\n\n');
41
- this.buffer = segments.pop() || '';
42
- for (const segment of segments) {
43
- const lines = segment.split('\n');
44
- const currentEvent = { event: 'message', data: '' };
45
- const dataLines = [];
46
- for (const rawLine of lines) {
47
- const line = rawLine.trimEnd();
48
- if (!line || line.startsWith(':')) {
49
- continue;
50
- }
51
- if (line.startsWith('event: ')) {
52
- currentEvent.event = line.substring(7).trim();
53
- continue;
54
- }
55
- if (line.startsWith('data:')) {
56
- dataLines.push(line.substring(5).trimStart());
57
- continue;
58
- }
59
- if (line.startsWith('id: ')) {
60
- currentEvent.id = line.substring(4).trim();
61
- continue;
62
- }
63
- if (line.startsWith('retry: ')) {
64
- currentEvent.retry = parseInt(line.substring(7), 10);
65
- }
66
- }
67
- const data = dataLines.join('\n');
68
- if (!data) {
69
- continue;
70
- }
71
- if (data === '[DONE]') {
72
- this.eventCount++;
73
- events.push({ event: 'done', data: null, index: this.eventCount });
74
- continue;
75
- }
76
- try {
77
- currentEvent.data = JSON.parse(data);
78
- this.eventCount++;
79
- currentEvent.index = this.eventCount;
80
- events.push({ ...currentEvent });
81
- }
82
- catch (e) {
83
- if (typeof console !== 'undefined' && console.error) {
84
- console.error('[SSEParser] Malformed JSON event:', e.message, 'Data:', data.substring(0, 100));
85
- }
86
- if (this.throwOnMalformedJson) {
87
- throw new Error(`Malformed SSE JSON event: ${e.message}`);
88
- }
89
- }
90
- }
91
- return events;
92
- }
93
- /**
94
- * Reset parser state (for reuse)
95
- */
96
- reset() {
97
- this.buffer = '';
98
- this.eventCount = 0;
99
- }
100
- }
101
- exports.SSEParser = SSEParser;
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * SSEParser - Parse Server-Sent Events (SSE) stream
5
+ *
6
+ * Handles:
7
+ * - Incomplete events across chunks
8
+ * - Multiple events in single chunk
9
+ * - Malformed data (skip gracefully)
10
+ * - [DONE] marker
11
+ *
12
+ * Usage:
13
+ * const parser = new SSEParser();
14
+ * stream.on('data', chunk => {
15
+ * const events = parser.parse(chunk);
16
+ * events.forEach(event => { ... });
17
+ * });
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.SSEParser = void 0;
21
+ class SSEParser {
22
+ constructor(options = {}) {
23
+ this.buffer = '';
24
+ this.eventCount = 0;
25
+ this.maxBufferSize = options.maxBufferSize || 1024 * 1024; // 1MB default
26
+ this.throwOnMalformedJson = options.throwOnMalformedJson === true;
27
+ }
28
+ /**
29
+ * Parse chunk and extract SSE events
30
+ * @param chunk - Data chunk from stream
31
+ * @returns Array of parsed events
32
+ */
33
+ parse(chunk) {
34
+ this.buffer += chunk.toString().replace(/\r\n?/g, '\n');
35
+ // C-01 Fix: Prevent unbounded buffer growth (DoS protection)
36
+ if (this.buffer.length > this.maxBufferSize) {
37
+ throw new Error(`SSE buffer exceeded ${this.maxBufferSize} bytes (DoS protection)`);
38
+ }
39
+ const events = [];
40
+ const segments = this.buffer.split('\n\n');
41
+ this.buffer = segments.pop() || '';
42
+ for (const segment of segments) {
43
+ const lines = segment.split('\n');
44
+ const currentEvent = { event: 'message', data: '' };
45
+ const dataLines = [];
46
+ for (const rawLine of lines) {
47
+ const line = rawLine.trimEnd();
48
+ if (!line || line.startsWith(':')) {
49
+ continue;
50
+ }
51
+ if (line.startsWith('event: ')) {
52
+ currentEvent.event = line.substring(7).trim();
53
+ continue;
54
+ }
55
+ if (line.startsWith('data:')) {
56
+ dataLines.push(line.substring(5).trimStart());
57
+ continue;
58
+ }
59
+ if (line.startsWith('id: ')) {
60
+ currentEvent.id = line.substring(4).trim();
61
+ continue;
62
+ }
63
+ if (line.startsWith('retry: ')) {
64
+ currentEvent.retry = parseInt(line.substring(7), 10);
65
+ }
66
+ }
67
+ const data = dataLines.join('\n');
68
+ if (!data) {
69
+ continue;
70
+ }
71
+ if (data === '[DONE]') {
72
+ this.eventCount++;
73
+ events.push({ event: 'done', data: null, index: this.eventCount });
74
+ continue;
75
+ }
76
+ try {
77
+ currentEvent.data = JSON.parse(data);
78
+ this.eventCount++;
79
+ currentEvent.index = this.eventCount;
80
+ events.push({ ...currentEvent });
81
+ }
82
+ catch (e) {
83
+ if (typeof console !== 'undefined' && console.error) {
84
+ console.error('[SSEParser] Malformed JSON event:', e.message, 'Data:', data.substring(0, 100));
85
+ }
86
+ if (this.throwOnMalformedJson) {
87
+ throw new Error(`Malformed SSE JSON event: ${e.message}`);
88
+ }
89
+ }
90
+ }
91
+ return events;
92
+ }
93
+ /**
94
+ * Reset parser state (for reuse)
95
+ */
96
+ reset() {
97
+ this.buffer = '';
98
+ this.eventCount = 0;
99
+ }
100
+ }
101
+ exports.SSEParser = SSEParser;
102
102
  //# sourceMappingURL=sse-parser.js.map
@@ -1,13 +1,13 @@
1
- /**
2
- * Stub for CCS services/logging - provides no-op logger
3
- */
4
- function createLogger(_name) {
5
- return {
6
- info: () => {},
7
- warn: () => {},
8
- error: () => {},
9
- debug: () => {},
10
- stage: () => {},
11
- };
12
- }
13
- module.exports = { createLogger };
1
+ /**
2
+ * Stub for CCS services/logging - provides no-op logger
3
+ */
4
+ function createLogger(_name) {
5
+ return {
6
+ info: () => {},
7
+ warn: () => {},
8
+ error: () => {},
9
+ debug: () => {},
10
+ stage: () => {},
11
+ };
12
+ }
13
+ module.exports = { createLogger };