@widgetic/chat 0.1.6 → 0.1.8

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.
@@ -1,6 +1,33 @@
1
1
  <script lang="ts">
2
2
  import { onMount } from 'svelte';
3
- import hljs from 'highlight.js';
3
+ import hljs from 'highlight.js/lib/core';
4
+ import javascript from 'highlight.js/lib/languages/javascript';
5
+ import typescript from 'highlight.js/lib/languages/typescript';
6
+ import xml from 'highlight.js/lib/languages/xml';
7
+ import css from 'highlight.js/lib/languages/css';
8
+ import json from 'highlight.js/lib/languages/json';
9
+ import python from 'highlight.js/lib/languages/python';
10
+ import bash from 'highlight.js/lib/languages/bash';
11
+ import markdown from 'highlight.js/lib/languages/markdown';
12
+ import sql from 'highlight.js/lib/languages/sql';
13
+
14
+ // Register essential programming languages for code rendering
15
+ hljs.registerLanguage('javascript', javascript);
16
+ hljs.registerLanguage('js', javascript);
17
+ hljs.registerLanguage('typescript', typescript);
18
+ hljs.registerLanguage('ts', typescript);
19
+ hljs.registerLanguage('xml', xml);
20
+ hljs.registerLanguage('html', xml);
21
+ hljs.registerLanguage('css', css);
22
+ hljs.registerLanguage('json', json);
23
+ hljs.registerLanguage('python', python);
24
+ hljs.registerLanguage('py', python);
25
+ hljs.registerLanguage('bash', bash);
26
+ hljs.registerLanguage('sh', bash);
27
+ hljs.registerLanguage('shell', bash);
28
+ hljs.registerLanguage('markdown', markdown);
29
+ hljs.registerLanguage('md', markdown);
30
+ hljs.registerLanguage('sql', sql);
4
31
 
5
32
  interface Props {
6
33
  code: string;
@@ -15,22 +42,34 @@
15
42
  let codeElement: HTMLElement;
16
43
  let highlightedCode = $state('');
17
44
  let copied = $state(false);
45
+
46
+ function escapeHtml(text: string): string {
47
+ return text
48
+ .replace(/&/g, '&amp;')
49
+ .replace(/</g, '&lt;')
50
+ .replace(/>/g, '&gt;')
51
+ .replace(/"/g, '&quot;')
52
+ .replace(/'/g, '&#039;');
53
+ }
18
54
 
19
55
  onMount(() => {
20
- // Auto-detect language if not provided
21
- if (language === 'plaintext') {
22
- const detected = hljs.highlightAuto(code);
23
- highlightedCode = detected.value;
24
- language = detected.language || 'plaintext';
25
- } else {
56
+ const normalizedLang = (language || '').toLowerCase().trim();
57
+ if (normalizedLang && normalizedLang !== 'plaintext' && hljs.getLanguage(normalizedLang)) {
26
58
  try {
27
- const highlighted = hljs.highlight(code, { language });
59
+ const highlighted = hljs.highlight(code, { language: normalizedLang, ignoreIllegals: true });
28
60
  highlightedCode = highlighted.value;
29
- } catch (error) {
30
- // Fallback to auto-detect if specific language fails
61
+ } catch {
62
+ highlightedCode = escapeHtml(code);
63
+ }
64
+ } else {
65
+ try {
31
66
  const detected = hljs.highlightAuto(code);
32
67
  highlightedCode = detected.value;
33
- language = detected.language || 'plaintext';
68
+ if (detected.language) {
69
+ language = detected.language;
70
+ }
71
+ } catch {
72
+ highlightedCode = escapeHtml(code);
34
73
  }
35
74
  }
36
75
  });
@@ -48,19 +87,24 @@
48
87
  function getLanguageIcon(lang: string): string {
49
88
  const icons: Record<string, string> = {
50
89
  javascript: '🟨',
90
+ js: '🟨',
51
91
  typescript: '🔷',
92
+ ts: '🔷',
52
93
  python: '🐍',
94
+ py: '🐍',
53
95
  java: '☕',
54
96
  cpp: '⚙️',
55
97
  css: '🎨',
56
98
  html: '🌐',
99
+ xml: '📄',
57
100
  json: '📋',
58
101
  sql: '🗃️',
59
102
  bash: '💻',
103
+ sh: '💻',
60
104
  shell: '💻',
61
105
  yaml: '📄',
62
- xml: '📄',
63
- markdown: '📝'
106
+ markdown: '📝',
107
+ md: '📝'
64
108
  };
65
109
  return icons[lang] || '📄';
66
110
  }
@@ -112,11 +156,6 @@
112
156
  </div>
113
157
  </div>
114
158
 
115
- <!-- Import highlight.js CSS theme -->
116
- <svelte:head>
117
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css">
118
- </svelte:head>
119
-
120
159
  <style>
121
160
  .code-block {
122
161
  border: 1px solid #e5e7eb;
@@ -241,6 +280,85 @@
241
280
  background: transparent !important;
242
281
  padding: 0;
243
282
  }
283
+
284
+ /* Embedded highlight.js GitHub Light theme tokens */
285
+ :global(.hljs) {
286
+ color: #24292e;
287
+ background: transparent;
288
+ }
289
+ :global(.hljs-doctag),
290
+ :global(.hljs-keyword),
291
+ :global(.hljs-meta .hljs-keyword),
292
+ :global(.hljs-template-tag),
293
+ :global(.hljs-template-variable),
294
+ :global(.hljs-type),
295
+ :global(.hljs-variable.language_) {
296
+ color: #d73a49;
297
+ }
298
+ :global(.hljs-title),
299
+ :global(.hljs-title.class_),
300
+ :global(.hljs-title.class_.inherited__),
301
+ :global(.hljs-title.function_) {
302
+ color: #6f42c1;
303
+ }
304
+ :global(.hljs-attr),
305
+ :global(.hljs-attribute),
306
+ :global(.hljs-literal),
307
+ :global(.hljs-meta),
308
+ :global(.hljs-number),
309
+ :global(.hljs-operator),
310
+ :global(.hljs-variable),
311
+ :global(.hljs-selector-attr),
312
+ :global(.hljs-selector-class),
313
+ :global(.hljs-selector-id) {
314
+ color: #005cc5;
315
+ }
316
+ :global(.hljs-regexp),
317
+ :global(.hljs-string),
318
+ :global(.hljs-meta .hljs-string) {
319
+ color: #032f62;
320
+ }
321
+ :global(.hljs-built_in),
322
+ :global(.hljs-symbol) {
323
+ color: #e36209;
324
+ }
325
+ :global(.hljs-comment),
326
+ :global(.hljs-code),
327
+ :global(.hljs-formula) {
328
+ color: #6a737d;
329
+ }
330
+ :global(.hljs-name),
331
+ :global(.hljs-quote),
332
+ :global(.hljs-selector-tag),
333
+ :global(.hljs-selector-pseudo) {
334
+ color: #22863a;
335
+ }
336
+ :global(.hljs-subst) {
337
+ color: #24292e;
338
+ }
339
+ :global(.hljs-section) {
340
+ color: #005cc5;
341
+ font-weight: bold;
342
+ }
343
+ :global(.hljs-bullet) {
344
+ color: #735c0f;
345
+ }
346
+ :global(.hljs-emphasis) {
347
+ color: #24292e;
348
+ font-style: italic;
349
+ }
350
+ :global(.hljs-strong) {
351
+ color: #24292e;
352
+ font-weight: bold;
353
+ }
354
+ :global(.hljs-addition) {
355
+ color: #22863a;
356
+ background-color: #f0fff4;
357
+ }
358
+ :global(.hljs-deletion) {
359
+ color: #b31d28;
360
+ background-color: #ffeef0;
361
+ }
244
362
 
245
363
  /* Dark mode support */
246
364
  @media (prefers-color-scheme: dark) {
@@ -282,5 +400,14 @@
282
400
  border-color: #4b5563;
283
401
  color: #9ca3af;
284
402
  }
403
+
404
+ :global(.hljs) { color: #f3f4f6; }
405
+ :global(.hljs-keyword), :global(.hljs-doctag) { color: #ff7b72; }
406
+ :global(.hljs-title), :global(.hljs-title.function_) { color: #d2a8ff; }
407
+ :global(.hljs-attr), :global(.hljs-number), :global(.hljs-literal) { color: #79c0ff; }
408
+ :global(.hljs-string) { color: #a5d6ff; }
409
+ :global(.hljs-built_in) { color: #ffa657; }
410
+ :global(.hljs-comment) { color: #8b949e; }
411
+ :global(.hljs-name), :global(.hljs-selector-tag) { color: #7ee787; }
285
412
  }
286
- </style>
413
+ </style>
@@ -61,7 +61,7 @@
61
61
  }
62
62
 
63
63
  function handleSuggestionClick(suggestion: string) {
64
- chatLog('Suggestion clicked:', suggestion);
64
+ // chatLog('Suggestion clicked:', suggestion);
65
65
  dispatch('suggestionSelected', { suggestion });
66
66
  }
67
67
 
@@ -9,7 +9,7 @@ export class WidgeticChatService {
9
9
  constructor(configuration) {
10
10
  this.conversationsApi = new ConversationsApi(configuration);
11
11
  this.messagesApi = new MessagesApi(configuration);
12
- chatLog('ChatService initialized (mock mode)');
12
+ // chatLog('ChatService initialized (mock mode)');
13
13
  }
14
14
  /**
15
15
  * Get all conversations for a given context (canvas + component)
@@ -18,7 +18,7 @@ export class WidgeticChatService {
18
18
  const [canvasId, componentId] = this.parseContextId(contextId);
19
19
  try {
20
20
  // Mock implementation for now
21
- chatLog('Getting conversations for:', { canvasId, componentId });
21
+ // chatLog('Getting conversations for:', { canvasId, componentId });
22
22
  return [];
23
23
  }
24
24
  catch (error) {
@@ -36,7 +36,7 @@ export class WidgeticChatService {
36
36
  completed: false
37
37
  };
38
38
  try {
39
- chatLog('Creating conversation:', { canvasId, componentId, request });
39
+ // chatLog('Creating conversation:', { canvasId, componentId, request });
40
40
  // Mock response
41
41
  const mockConversation = {
42
42
  id: `conv_${Date.now()}`,
@@ -75,7 +75,7 @@ export class WidgeticChatService {
75
75
  */
76
76
  async getMessages(conversationId) {
77
77
  try {
78
- chatLog('Getting messages for conversation:', conversationId);
78
+ // chatLog('Getting messages for conversation:', conversationId);
79
79
  return [];
80
80
  }
81
81
  catch (error) {
@@ -90,7 +90,7 @@ export class WidgeticChatService {
90
90
  try {
91
91
  let processedAttachments = [];
92
92
  if (data.attachments && data.attachments.length > 0) {
93
- chatLog('Processing attachments:', data.attachments.length);
93
+ // chatLog('Processing attachments:', data.attachments.length);
94
94
  for (let i = 0; i < data.attachments.length; i++) {
95
95
  const attachment = data.attachments[i];
96
96
  if (attachment && typeof attachment === 'object' && 'file' in attachment) {
@@ -146,7 +146,7 @@ export class WidgeticChatService {
146
146
  messageType: 'user',
147
147
  attachments: processedAttachments
148
148
  };
149
- chatLog('Sending message:', { conversationId, request });
149
+ // chatLog('Sending message:', { conversationId, request });
150
150
  // Mock response
151
151
  const mockMessage = {
152
152
  id: `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
@@ -162,7 +162,7 @@ export class WidgeticChatService {
162
162
  _failed: false,
163
163
  _retryCount: 0
164
164
  };
165
- chatLog('Mock message created:', mockMessage);
165
+ // chatLog('Mock message created:', mockMessage);
166
166
  return mockMessage;
167
167
  }
168
168
  catch (error) {
@@ -174,21 +174,21 @@ export class WidgeticChatService {
174
174
  * Update a message
175
175
  */
176
176
  async updateMessage(messageId, updates) {
177
- chatLog('Update message not yet implemented:', messageId, updates);
177
+ // chatLog('Update message not yet implemented:', messageId, updates);
178
178
  throw new Error('Update message not yet implemented');
179
179
  }
180
180
  /**
181
181
  * Delete a message
182
182
  */
183
183
  async deleteMessage(messageId) {
184
- chatLog('Delete message not yet implemented:', messageId);
184
+ // chatLog('Delete message not yet implemented:', messageId);
185
185
  throw new Error('Delete message not yet implemented');
186
186
  }
187
187
  /**
188
188
  * Read a file as a data URL (persistable in DB until upload service exists).
189
189
  */
190
190
  async fileToDataUrl(file) {
191
- chatLog('Reading attachment as data URL:', file.name);
191
+ // chatLog('Reading attachment as data URL:', file.name);
192
192
  return new Promise((resolve, reject) => {
193
193
  const reader = new FileReader();
194
194
  reader.onload = () => resolve(String(reader.result));
@@ -221,7 +221,7 @@ export class WidgeticChatService {
221
221
  _failed: false,
222
222
  _retryCount: 0
223
223
  };
224
- chatLog('AI response generated:', aiResponse);
224
+ // chatLog('AI response generated:', aiResponse);
225
225
  return aiResponse;
226
226
  }
227
227
  /**
@@ -1,4 +1,4 @@
1
- import { writable } from 'svelte/store';
1
+ import { writable, get } from 'svelte/store';
2
2
  import { chatLog } from '../utils/logger.js';
3
3
  /**
4
4
  * Initial state for the chat store
@@ -49,7 +49,7 @@ function createChatStore() {
49
49
  */
50
50
  dispatch: (action) => {
51
51
  update(state => {
52
- chatLog(`Chat Action: ${action.type}`, action.payload);
52
+ // chatLog(`Chat Action: ${action.type}`, action.payload);
53
53
  switch (action.type) {
54
54
  case 'SET_ACTIVE_CONTEXT':
55
55
  return {
@@ -158,7 +158,7 @@ function createChatStore() {
158
158
  }
159
159
  };
160
160
  default:
161
- chatLog(`Unknown action type: ${action.type}`);
161
+ // chatLog(`Unknown action type: ${(action as any).type}`);
162
162
  return state;
163
163
  }
164
164
  });
@@ -306,9 +306,7 @@ export const uiState = {
306
306
  * Reactive getters for current state
307
307
  */
308
308
  export const getCurrentState = () => {
309
- let currentState;
310
- chatStore.subscribe(state => { currentState = state; })();
311
- return currentState;
309
+ return get(chatStore);
312
310
  };
313
311
  export const getCurrentMessages = (conversationId) => {
314
312
  const state = getCurrentState();
@@ -1,10 +1,9 @@
1
- let logsEnabled = true;
1
+ let logsEnabled = false;
2
2
  export function setLogsEnabled(enabled) {
3
3
  logsEnabled = enabled;
4
4
  }
5
5
  export function chatLog(...args) {
6
- if (logsEnabled)
7
- console.log(...args);
6
+ // if (logsEnabled) console.log(...args);
8
7
  }
9
8
  export function chatWarn(...args) {
10
9
  if (logsEnabled)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -49,9 +49,9 @@
49
49
  "format": "prettier --write ."
50
50
  },
51
51
  "peerDependencies": {
52
- "svelte": "^5.25.6",
53
52
  "@widgetic/api-sdk": "*",
54
- "@widgetic/design-system": ">=0.3.0"
53
+ "@widgetic/design-system": ">=0.3.0",
54
+ "svelte": "^5.25.6"
55
55
  },
56
56
  "dependencies": {
57
57
  "highlight.js": "^11.11.1",
@@ -65,6 +65,9 @@
65
65
  "@sveltejs/vite-plugin-svelte": "^5.0.3",
66
66
  "@tailwindcss/postcss": "^4.1.4",
67
67
  "@types/eslint": "^9.6.0",
68
+ "@types/node": "^26.4.1",
69
+ "@widgetic/api-sdk": "^1.0.10",
70
+ "@widgetic/design-system": "^0.3.89",
68
71
  "autoprefixer": "^10.4.20",
69
72
  "eslint": "^9.0.0",
70
73
  "eslint-config-prettier": "^9.1.0",
@@ -79,9 +82,7 @@
79
82
  "tailwindcss": "^4.1.4",
80
83
  "typescript": "^5.8.3",
81
84
  "typescript-eslint": "^8.0.0",
82
- "vite": "^6.2.6",
83
- "@widgetic/api-sdk": "^1.0.10",
84
- "@widgetic/design-system": "^0.3.89"
85
+ "vite": "^6.2.6"
85
86
  },
86
87
  "overrides": {
87
88
  "bits-ui": {