@copilotkit/angular 0.3.1-canary.rc-1 → 0.3.2-canary.1785866877

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.
@@ -5183,6 +5183,60 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.26", ngImpo
5183
5183
  }]
5184
5184
  }], propDecorators: { message: [{ type: i0.Input, args: [{ isSignal: true, alias: "message", required: true }] }], messages: [{ type: i0.Input, args: [{ isSignal: true, alias: "messages", required: true }] }], agentId: [{ type: i0.Input, args: [{ isSignal: true, alias: "agentId", required: false }] }], isLoading: [{ type: i0.Input, args: [{ isSignal: true, alias: "isLoading", required: false }] }] } });
5185
5185
 
5186
+ function processMathEquationsInHtml(html) {
5187
+ // First, temporarily replace code blocks with placeholders to protect them from math processing
5188
+ const codeBlocks = [];
5189
+ const placeholder = "___CODE_BLOCK_PLACEHOLDER_";
5190
+ // Store code blocks and replace with placeholders
5191
+ html = html.replace(/<pre><code[\s\S]*?<\/code><\/pre>/g, (match) => {
5192
+ const index = codeBlocks.length;
5193
+ codeBlocks.push(match);
5194
+ return `${placeholder}${index}___`;
5195
+ });
5196
+ // Also protect inline code
5197
+ const inlineCode = [];
5198
+ const inlinePlaceholder = "___INLINE_CODE_PLACEHOLDER_";
5199
+ html = html.replace(/<code>[\s\S]*?<\/code>/g, (match) => {
5200
+ const index = inlineCode.length;
5201
+ inlineCode.push(match);
5202
+ return `${inlinePlaceholder}${index}___`;
5203
+ });
5204
+ // Process display math $$ ... $$
5205
+ html = html.replace(/\$\$([\s\S]*?)\$\$/g, (match, equation) => {
5206
+ try {
5207
+ return katex.renderToString(equation, {
5208
+ displayMode: true,
5209
+ throwOnError: false,
5210
+ });
5211
+ }
5212
+ catch {
5213
+ return match;
5214
+ }
5215
+ });
5216
+ // A closing inline-math delimiter cannot be preceded by whitespace or
5217
+ // followed by a digit. Those delimiter rules keep ordinary currency ranges
5218
+ // such as "$349 ... $289" from becoming one large KaTeX expression.
5219
+ html = html.replace(/(?<!\\)\$(?!\s)([^$\n]*?\S)\$(?!\d)/g, (match, equation) => {
5220
+ try {
5221
+ return katex.renderToString(equation, {
5222
+ displayMode: false,
5223
+ throwOnError: false,
5224
+ });
5225
+ }
5226
+ catch {
5227
+ return match;
5228
+ }
5229
+ });
5230
+ // Restore code blocks
5231
+ codeBlocks.forEach((block, index) => {
5232
+ html = html.replace(`${placeholder}${index}___`, block);
5233
+ });
5234
+ // Restore inline code
5235
+ inlineCode.forEach((code, index) => {
5236
+ html = html.replace(`${inlinePlaceholder}${index}___`, code);
5237
+ });
5238
+ return html;
5239
+ }
5186
5240
  class CopilotChatAssistantMessageRenderer {
5187
5241
  content = input("", ...(ngDevMode ? [{ debugName: "content" }] : []));
5188
5242
  inputClass = input(...(ngDevMode ? [undefined, { debugName: "inputClass" }] : []));
@@ -5282,59 +5336,7 @@ class CopilotChatAssistantMessageRenderer {
5282
5336
  // Parse markdown
5283
5337
  let html = this.markedInstance.parse(content);
5284
5338
  // Process math equations
5285
- html = this.processMathEquations(html);
5286
- return html;
5287
- }
5288
- processMathEquations(html) {
5289
- // First, temporarily replace code blocks with placeholders to protect them from math processing
5290
- const codeBlocks = [];
5291
- const placeholder = "___CODE_BLOCK_PLACEHOLDER_";
5292
- // Store code blocks and replace with placeholders
5293
- html = html.replace(/<pre><code[\s\S]*?<\/code><\/pre>/g, (match) => {
5294
- const index = codeBlocks.length;
5295
- codeBlocks.push(match);
5296
- return `${placeholder}${index}___`;
5297
- });
5298
- // Also protect inline code
5299
- const inlineCode = [];
5300
- const inlinePlaceholder = "___INLINE_CODE_PLACEHOLDER_";
5301
- html = html.replace(/<code>[\s\S]*?<\/code>/g, (match) => {
5302
- const index = inlineCode.length;
5303
- inlineCode.push(match);
5304
- return `${inlinePlaceholder}${index}___`;
5305
- });
5306
- // Process display math $$ ... $$
5307
- html = html.replace(/\$\$([\s\S]*?)\$\$/g, (match, equation) => {
5308
- try {
5309
- return katex.renderToString(equation, {
5310
- displayMode: true,
5311
- throwOnError: false,
5312
- });
5313
- }
5314
- catch {
5315
- return match;
5316
- }
5317
- });
5318
- // Process inline math $ ... $
5319
- html = html.replace(/\$([^$]+)\$/g, (match, equation) => {
5320
- try {
5321
- return katex.renderToString(equation, {
5322
- displayMode: false,
5323
- throwOnError: false,
5324
- });
5325
- }
5326
- catch {
5327
- return match;
5328
- }
5329
- });
5330
- // Restore code blocks
5331
- codeBlocks.forEach((block, index) => {
5332
- html = html.replace(`${placeholder}${index}___`, block);
5333
- });
5334
- // Restore inline code
5335
- inlineCode.forEach((code, index) => {
5336
- html = html.replace(`${inlinePlaceholder}${index}___`, code);
5337
- });
5339
+ html = processMathEquationsInHtml(html);
5338
5340
  return html;
5339
5341
  }
5340
5342
  renderMathEquations() {