@widgetic/chat 0.1.16 → 0.1.18

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,12 +1,22 @@
1
1
  <script lang="ts">
2
2
  import type { ChatMessage, ChatContext } from '../types/index.js';
3
- import type { ClarificationSuggestion } from '../types/message.js';
3
+ import type { ClarificationSuggestion, DesignControlRequest } from '../types/message.js';
4
4
  import { MESSAGE_COLORS } from '../constants/colors.js';
5
5
  import { chatLog } from '../utils/logger.js';
6
6
  import { AttachmentDisplay, SuggestionButtons } from './index.js';
7
7
  import CodeBlock from './CodeBlock.svelte';
8
8
  import LoadingIndicator from './LoadingIndicator.svelte';
9
9
  import { onDestroy, onMount, tick } from 'svelte';
10
+ import type { Snippet } from 'svelte';
11
+ import { useChatLanguage } from '../i18n/language.js';
12
+ import { contextTypeLabel, versionLabelText } from '../i18n/labels.js';
13
+ import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
14
+
15
+ // The words of the messages area, in the language of the chat above
16
+ const { t } = useChatLanguage();
17
+
18
+ // The way the screen is read: what a person wrote reads by its own first letter on a right to left screen.
19
+ const textDirection = useTextDirection();
10
20
 
11
21
  // Props
12
22
  interface Props {
@@ -56,10 +66,20 @@
56
66
  onSuggestionSelected?: (suggestion: string) => void;
57
67
  onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
58
68
  onRetryMessage?: (content: string) => void;
69
+ /**
70
+ * What the "Upgrade" button of a failure about the plan or the credits does. Without it the button opens the
71
+ * billing page of the Widgetic site. A host that is a guest on somebody else's page (the creator in a partner's
72
+ * page) gives its own function: the page it is on is not the chat's to navigate away from.
73
+ */
74
+ onUpgradePlans?: () => void;
59
75
  /** Tapping a clarification-card suggestion chip sends it as the next user message,
60
76
  * carrying the chip's structured intent. Chips are disabled while the host
61
77
  * runs widget codegen (`isGenerating`). */
62
78
  onClarificationSuggestionSelected?: (suggestion: ClarificationSuggestion) => void;
79
+ /** Host-rendered inline design-control card for messages carrying `designControls`. */
80
+ renderDesignControls?: Snippet<[DesignControlRequest]>;
81
+ /** Host translation for lines saved in English (see Chat `storedLineLabel`). */
82
+ storedLineLabel?: (content: string) => string;
63
83
  }
64
84
 
65
85
  let {
@@ -81,15 +101,29 @@
81
101
  onSuggestionSelected,
82
102
  onRestoreCheckpoint,
83
103
  onRetryMessage,
104
+ onUpgradePlans,
84
105
  onClarificationSuggestionSelected,
106
+ renderDesignControls,
107
+ storedLineLabel,
85
108
  }: Props = $props();
86
109
 
110
+ /** What a visitor reads for stored assistant/system lines; matching still uses the English stored text. */
111
+ function visibleMessageContent(content: string): string {
112
+ if (!storedLineLabel) return content;
113
+ try {
114
+ return storedLineLabel(content);
115
+ } catch (error) {
116
+ console.warn('[Chat] storedLineLabel failed:', error);
117
+ return content;
118
+ }
119
+ }
120
+
87
121
  let messagesHasScrollbar = $state(false);
88
122
 
89
123
  function detectMessagesScrollbar(node: HTMLElement) {
90
124
  function check() {
91
125
  messagesHasScrollbar = node.scrollHeight > node.clientHeight + 1;
92
- node.style.setProperty('padding-right', messagesHasScrollbar ? '0px' : '12px', 'important');
126
+ node.style.setProperty('padding-inline-end', messagesHasScrollbar ? '0px' : '12px', 'important');
93
127
  }
94
128
  const resizeObserver = new ResizeObserver(check);
95
129
  resizeObserver.observe(node);
@@ -110,9 +144,9 @@
110
144
  const hasScroll = candidates.some((el) => el.scrollHeight > el.clientHeight + 1);
111
145
  node.classList.toggle('message-bubble-has-scroll', hasScroll);
112
146
  if (hasScroll) {
113
- node.style.setProperty('padding-right', '0px', 'important');
147
+ node.style.setProperty('padding-inline-end', '0px', 'important');
114
148
  } else {
115
- node.style.removeProperty('padding-right');
149
+ node.style.removeProperty('padding-inline-end');
116
150
  }
117
151
  }
118
152
  const resizeObserver = new ResizeObserver(check);
@@ -495,6 +529,8 @@
495
529
  if (index < 0) return null;
496
530
  const prev = [...numbered.slice(0, index)].reverse().find((row) => row.n != null);
497
531
  const next = numbered.slice(index + 1).find((row) => row.n != null);
532
+ // A version the host gave no name for is named the way the host names them ("Version 4"): the number is read back out
533
+ // of these words, and `versionLabelText` says them in the page's language when they are drawn.
498
534
  if (prev?.n != null && next?.n != null && next.n - prev.n === 2) return `Version ${prev.n + 1}`;
499
535
  if (prev?.n != null && next == null) return `Version ${prev.n + 1}`;
500
536
  if (prev == null && next?.n != null && next.n > 1) return `Version ${next.n - 1}`;
@@ -685,6 +721,25 @@
685
721
  );
686
722
  });
687
723
 
724
+ /**
725
+ * Brings `element` into view inside `container` the way `element.scrollIntoView({ block: 'nearest', behavior: 'smooth' })`
726
+ * does, but moves the container only. `scrollIntoView` scrolls every scrollable ancestor as well, and one of them is the
727
+ * page the chat is on (a partner's page, when the creator is mounted into it).
728
+ */
729
+ function scrollIntoViewWithin(container: HTMLElement, element: Element) {
730
+ const containerBox = container.getBoundingClientRect();
731
+ const elementBox = element.getBoundingClientRect();
732
+ let distance = 0;
733
+ if (elementBox.top < containerBox.top) {
734
+ // It starts above the visible part: scroll up to its top.
735
+ distance = elementBox.top - containerBox.top;
736
+ } else if (elementBox.bottom > containerBox.bottom) {
737
+ // It ends below the visible part: scroll down just enough, but never past its own top (when it is taller than the container).
738
+ distance = Math.min(elementBox.bottom - containerBox.bottom, elementBox.top - containerBox.top);
739
+ }
740
+ if (distance !== 0) container.scrollBy({ top: distance, behavior: 'smooth' });
741
+ }
742
+
688
743
  /** Version dropdown changes which commit is "here" — bring that turn into view. */
689
744
  $effect(() => {
690
745
  const version = viewingVersion;
@@ -692,8 +747,8 @@
692
747
  if ((version == null && !sha) || !messagesContainer) return;
693
748
  void tick().then(() => {
694
749
  const here = messagesContainer?.querySelector('[data-you-are-here="true"]');
695
- if (here && typeof here.scrollIntoView === 'function') {
696
- here.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
750
+ if (here && messagesContainer) {
751
+ scrollIntoViewWithin(messagesContainer, here);
697
752
  }
698
753
  });
699
754
  });
@@ -719,6 +774,12 @@
719
774
  }
720
775
 
721
776
  function openUpgradePlans() {
777
+ // A host that is a guest on somebody else's page decides what "upgrade" means there; the billing page of the
778
+ // Widgetic site would take the visitor off the page they are on.
779
+ if (onUpgradePlans) {
780
+ onUpgradePlans();
781
+ return;
782
+ }
722
783
  window.location.assign('/workspaces/personal/settings/billing');
723
784
  }
724
785
 
@@ -1118,9 +1179,9 @@
1118
1179
 
1119
1180
  <div
1120
1181
  bind:this={messagesContainer}
1121
- class="{className ? className : 'prompt-chat-messages-ct'} prompt-chat-messages-scroll flex flex-col overflow-y-auto space-y-4"
1182
+ class="{className ? className : 'prompt-chat-messages-ct'} prompt-chat-messages-scroll flex flex-col overflow-y-auto space-y-4 pb-3"
1122
1183
  class:loading={isLoading}
1123
- style="scroll-behavior: smooth; padding: 12px 0 12px 12px; padding-right: 12px;"
1184
+ style="scroll-behavior: smooth; padding: 12px;"
1124
1185
  use:detectMessagesScrollbar
1125
1186
  onscroll={handleScroll}
1126
1187
  >
@@ -1130,9 +1191,9 @@
1130
1191
  after send, so the list is briefly empty again). -->
1131
1192
  {#if isInitialized && messages.length === 0 && !isLoading && !isGenerating}
1132
1193
  <div class="empty-state-ct flex flex-col items-center justify-center text-center max-w-sm w-full" style="align-self: center;">
1133
- <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2">💬 Start a conversation</h3>
1194
+ <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2">💬 {$t('chat.messages.startTitle')}</h3>
1134
1195
  <p class="text-gray-600 dark:text-gray-400 text-sm mb-6">
1135
- Ask a question about your {context.type} to get started.
1196
+ {$t('chat.messages.startHint', { type: contextTypeLabel(context.type, $t) })}
1136
1197
  </p>
1137
1198
 
1138
1199
  <!-- Contextual suggestions -->
@@ -1161,16 +1222,16 @@
1161
1222
  >
1162
1223
  <div class="wc-user-bubble-row flex w-full items-start gap-2">
1163
1224
  {#if isViewingTurn(turn)}
1164
- <div class="checkpoint-label wc-head-commit-label mt-1 shrink-0" title="This is the version you are looking at">
1225
+ <div class="checkpoint-label wc-head-commit-label mt-1 shrink-0" title={$t('chat.messages.viewingTitle')}>
1165
1226
  <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
1166
1227
  <path d="M20 6L9 17l-5-5"/>
1167
1228
  </svg>
1168
- You are here
1169
- <span class="wc-head-commit-arrow" aria-hidden="true">→</span>
1229
+ {$t('chat.messages.viewing')}
1230
+ <span class="wc-head-commit-arrow" aria-hidden="true">{$textDirection === 'rtl' ? '←' : '→'}</span>
1170
1231
  </div>
1171
1232
  {/if}
1172
1233
  <div
1173
- class="message-bubble relative ml-auto w-fit max-w-[80%] rounded-lg shadow-sm text-sm leading-relaxed select-text"
1234
+ class="message-bubble relative ms-auto w-fit max-w-[94%] rounded-lg shadow-sm text-sm leading-relaxed select-text"
1174
1235
  class:p-3={shownAttachments.length === 0}
1175
1236
  class:p-0={shownAttachments.length > 0}
1176
1237
  class:bubble-fit-content={shownAttachments.length > 0}
@@ -1182,7 +1243,7 @@
1182
1243
  <div class="message-content-mixed p-3">
1183
1244
  {#each parseMessageContent(userMsg.messageContent) as part}
1184
1245
  {#if part.type === 'text'}
1185
- <p class="whitespace-pre-wrap mb-2 last:mb-0">{part.content}</p>
1246
+ <p class="whitespace-pre-wrap mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{part.content}</p>
1186
1247
  {:else if part.type === 'code'}
1187
1248
  <div class="my-3 first:mt-0 last:mb-0">
1188
1249
  <CodeBlock
@@ -1195,7 +1256,7 @@
1195
1256
  {/each}
1196
1257
  </div>
1197
1258
  {:else}
1198
- <p class="whitespace-pre-wrap p-3">{userMsg.messageContent}</p>
1259
+ <p class="whitespace-pre-wrap p-3" dir={dirForUserText($textDirection)}>{userMsg.messageContent}</p>
1199
1260
  {/if}
1200
1261
  {/if}
1201
1262
  {#if shownAttachments.length > 0}
@@ -1204,13 +1265,13 @@
1204
1265
  </div>
1205
1266
  {:else if userMsg.messageContent && messageImpliesAttachedFile(userMsg.messageContent)}
1206
1267
  <div class="wc-missing-attachment-placeholder message-attachments-container flex flex-col items-center gap-1 px-3 pb-3">
1207
- <div class="wc-missing-attachment-thumb flex h-20 w-28 flex-col items-center justify-center gap-1 rounded-md border border-dashed border-gray-300 bg-gray-100 text-gray-400" title="Attachment not available" aria-label="Missing file attachment">
1268
+ <div class="wc-missing-attachment-thumb flex h-20 w-28 flex-col items-center justify-center gap-1 rounded-md border border-dashed border-gray-300 bg-gray-100 text-gray-400" title={$t('chat.messages.attachmentMissingTitle')} aria-label={$t('chat.messages.attachmentMissingLabel')}>
1208
1269
  <svg class="h-8 w-8 shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
1209
1270
  <rect x="3" y="5" width="18" height="14" rx="2" />
1210
1271
  <path d="M4 4l16 16" stroke-linecap="round" />
1211
1272
  </svg>
1212
1273
  </div>
1213
- <p class="wc-missing-attachment-caption max-w-[12rem] text-center text-xs text-gray-500">Attachment not saved. Re-attach with Upload, then Retry.</p>
1274
+ <p class="wc-missing-attachment-caption max-w-[12rem] text-center text-xs text-gray-500">{$t('chat.messages.attachmentMissingCaption')}</p>
1214
1275
  </div>
1215
1276
  {/if}
1216
1277
  </div>
@@ -1220,13 +1281,13 @@
1220
1281
  <button
1221
1282
  class="retry-codegen-btn"
1222
1283
  onclick={() => handleRetryTurn(turn, turnIndex)}
1223
- title="Run this prompt again as its own message. The sketch stays with the model, not on the bubble."
1284
+ title={$t('chat.messages.retryPromptTitle')}
1224
1285
  >
1225
1286
  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1226
1287
  <path d="M21 12a9 9 0 1 1-2.64-6.36"/>
1227
1288
  <path d="M21 3v6h-6"/>
1228
1289
  </svg>
1229
- Retry
1290
+ {$t('chat.messages.retry')}
1230
1291
  </button>
1231
1292
  </div>
1232
1293
  {/if}
@@ -1243,12 +1304,12 @@
1243
1304
  <div class="wc-user-commit-meta-left flex items-center gap-2 min-w-0">
1244
1305
  {#if getTurnVersionLabel(turn)}
1245
1306
  <span class="wc-user-version-label text-xs text-gray-500">
1246
- {getTurnVersionLabel(turn)}
1307
+ {versionLabelText(getTurnVersionLabel(turn), $t)}
1247
1308
  </span>
1248
1309
  {/if}
1249
1310
  {#if showCommitMeta && getTurnCommitShort(turn)}
1250
- <span class="wc-user-commit-sha font-mono text-xs text-gray-500">
1251
- (commit id: {getTurnCommitShort(turn)})
1311
+ <span class="wc-user-commit-sha whitespace-nowrap font-mono text-xs text-gray-500">
1312
+ {$t('chat.messages.commitId', { id: getTurnCommitShort(turn) ?? '' })}
1252
1313
  </span>
1253
1314
  {/if}
1254
1315
  </div>
@@ -1262,14 +1323,14 @@
1262
1323
  handleRestoreCheckpoint(restoreTargetMessageId(turn, commitReply));
1263
1324
  }}
1264
1325
  title={restoreIsCurrentHead
1265
- ? 'This checkpoint is already HEAD'
1266
- : 'Restore widget code to this prompt\'s commit'}
1326
+ ? $t('chat.messages.alreadyHead')
1327
+ : $t('chat.messages.restoreTitle')}
1267
1328
  >
1268
1329
  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1269
1330
  <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
1270
1331
  <path d="M3 3v5h5"/>
1271
1332
  </svg>
1272
- Restore Checkpoint
1333
+ {$t('chat.messages.restore')}
1273
1334
  </button>
1274
1335
  {/if}
1275
1336
  </div>
@@ -1279,7 +1340,7 @@
1279
1340
 
1280
1341
  {#each turn.replies as reply (reply.id)}
1281
1342
  {#if shouldShowAssistantReply(reply)}
1282
- <div class="message-container wc-chat-turn-reply mr-auto w-fit max-w-[80%] flex flex-col items-stretch"
1343
+ <div class="message-container wc-chat-turn-reply me-auto w-fit max-w-[94%] flex flex-col items-stretch overflow-visible"
1283
1344
  class:opacity-75={reply._optimistic}
1284
1345
  class:opacity-50={reply._failed}
1285
1346
  class:current-checkpoint={isHeadCommitReply(reply)}
@@ -1295,7 +1356,7 @@
1295
1356
  <div class="message-content-mixed">
1296
1357
  {#each parseMessageContent(reply.messageContent) as part}
1297
1358
  {#if part.type === 'text'}
1298
- <p class="whitespace-pre-wrap mb-2 last:mb-0">{part.content}</p>
1359
+ <p class="whitespace-pre-wrap mb-2 last:mb-0" dir={dirForUserText($textDirection)}>{visibleMessageContent(part.content)}</p>
1299
1360
  {:else if part.type === 'code'}
1300
1361
  <div class="my-3 first:mt-0 last:mb-0">
1301
1362
  <CodeBlock
@@ -1308,11 +1369,17 @@
1308
1369
  {/each}
1309
1370
  </div>
1310
1371
  {:else}
1311
- <p class="whitespace-pre-wrap">{reply.messageContent}</p>
1372
+ <p class="whitespace-pre-wrap" dir={dirForUserText($textDirection)}>{visibleMessageContent(reply.messageContent)}</p>
1312
1373
  {/if}
1313
1374
  {/if}
1314
1375
  </div>
1315
1376
 
1377
+ {#if reply.designControls && renderDesignControls}
1378
+ <div class="wc-design-controls mt-1.5 w-fit max-w-full overflow-visible">
1379
+ {@render renderDesignControls(reply.designControls)}
1380
+ </div>
1381
+ {/if}
1382
+
1316
1383
  {#if reply.suggestions && reply.suggestions.length > 0}
1317
1384
  <div class="clarification-suggestions flex flex-wrap gap-1.5 mt-1.5">
1318
1385
  {#each reply.suggestions as suggestion, i (i)}
@@ -1335,21 +1402,21 @@
1335
1402
  <button
1336
1403
  class="retry-codegen-btn"
1337
1404
  onclick={openUpgradePlans}
1338
- title="Open plans and billing"
1405
+ title={$t('chat.messages.upgradeTitle')}
1339
1406
  >
1340
- Upgrade
1407
+ {$t('chat.messages.upgrade')}
1341
1408
  </button>
1342
1409
  {:else}
1343
1410
  <button
1344
1411
  class="retry-codegen-btn"
1345
1412
  onclick={() => handleRetryTurn(turn, turnIndex)}
1346
- title="Retry the last user prompt (same generation request)"
1413
+ title={$t('chat.messages.retryLastTitle')}
1347
1414
  >
1348
1415
  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1349
1416
  <path d="M21 12a9 9 0 1 1-2.64-6.36"/>
1350
1417
  <path d="M21 3v6h-6"/>
1351
1418
  </svg>
1352
- Retry
1419
+ {$t('chat.messages.retry')}
1353
1420
  </button>
1354
1421
  {/if}
1355
1422
  </div>
@@ -1375,7 +1442,7 @@
1375
1442
  class="suggestions-toggle-btn text-xs text-gray-400 hover:text-gray-600 px-3 py-1.5 rounded-full border border-gray-200 hover:border-gray-300 bg-white hover:bg-gray-50 transition-colors cursor-pointer"
1376
1443
  onclick={() => { showSuggestionsInline = true; }}
1377
1444
  >
1378
- Show suggestions
1445
+ {$t('chat.messages.showSuggestions')}
1379
1446
  </button>
1380
1447
  {/if}
1381
1448
  </div>
@@ -1386,7 +1453,7 @@
1386
1453
  <div class="loading-history-ct flex flex-1 items-center justify-center p-8">
1387
1454
  <div class="text-center">
1388
1455
  <div class="w-6 h-6 border-2 border-gray-300 border-t-blue-600 rounded-full animate-spin mx-auto mb-2"></div>
1389
- <p class="text-gray-500 text-xs">Loading chat history...</p>
1456
+ <p class="text-gray-500 text-xs">{$t('chat.messages.loadingHistory')}</p>
1390
1457
  </div>
1391
1458
  </div>
1392
1459
  {:else if isLoading}
@@ -1396,7 +1463,7 @@
1396
1463
  >
1397
1464
  <LoadingIndicator
1398
1465
  type="thinking"
1399
- text="Assistant is thinking..."
1466
+ text={$t('chat.messages.thinking')}
1400
1467
  color="secondary"
1401
1468
  size="md"
1402
1469
  />
@@ -1416,7 +1483,7 @@
1416
1483
  }
1417
1484
 
1418
1485
  .message-container {
1419
- max-width: 80%;
1486
+ max-width: 96%;
1420
1487
  }
1421
1488
 
1422
1489
  /* Messages with attachments: text full-width on top, images on a row below */
@@ -1481,7 +1548,7 @@
1481
1548
  font-size: 11px;
1482
1549
  line-height: 1;
1483
1550
  font-weight: 700;
1484
- margin-left: 2px;
1551
+ margin-inline-start: 2px;
1485
1552
  }
1486
1553
 
1487
1554
  .wc-head-commit-meta-ct .wc-head-commit-label {
@@ -1561,7 +1628,7 @@
1561
1628
  font-size: 12px;
1562
1629
  font-weight: 500;
1563
1630
  cursor: pointer;
1564
- text-align: left;
1631
+ text-align: start;
1565
1632
  overflow-wrap: anywhere;
1566
1633
  white-space: normal;
1567
1634
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
@@ -1620,7 +1687,7 @@
1620
1687
  max-width: 100%;
1621
1688
  }
1622
1689
  .message-bubble-has-scroll {
1623
- padding-right: 0px !important;
1690
+ padding-inline-end: 0px !important;
1624
1691
  }
1625
1692
  .message-bubble p,
1626
1693
  .message-content-mixed {
@@ -1,5 +1,6 @@
1
1
  import type { ChatMessage, ChatContext } from '../types/index.js';
2
- import type { ClarificationSuggestion } from '../types/message.js';
2
+ import type { ClarificationSuggestion, DesignControlRequest } from '../types/message.js';
3
+ import type { Snippet } from 'svelte';
3
4
  interface Props {
4
5
  class?: string;
5
6
  messages: ChatMessage[];
@@ -51,10 +52,20 @@ interface Props {
51
52
  onSuggestionSelected?: (suggestion: string) => void;
52
53
  onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
53
54
  onRetryMessage?: (content: string) => void;
55
+ /**
56
+ * What the "Upgrade" button of a failure about the plan or the credits does. Without it the button opens the
57
+ * billing page of the Widgetic site. A host that is a guest on somebody else's page (the creator in a partner's
58
+ * page) gives its own function: the page it is on is not the chat's to navigate away from.
59
+ */
60
+ onUpgradePlans?: () => void;
54
61
  /** Tapping a clarification-card suggestion chip sends it as the next user message,
55
62
  * carrying the chip's structured intent. Chips are disabled while the host
56
63
  * runs widget codegen (`isGenerating`). */
57
64
  onClarificationSuggestionSelected?: (suggestion: ClarificationSuggestion) => void;
65
+ /** Host-rendered inline design-control card for messages carrying `designControls`. */
66
+ renderDesignControls?: Snippet<[DesignControlRequest]>;
67
+ /** Host translation for lines saved in English (see Chat `storedLineLabel`). */
68
+ storedLineLabel?: (content: string) => string;
58
69
  }
59
70
  declare const ChatMessages: import("svelte").Component<Props, {}, "">;
60
71
  type ChatMessages = ReturnType<typeof ChatMessages>;
@@ -10,6 +10,7 @@
10
10
  import bash from 'highlight.js/lib/languages/bash';
11
11
  import markdown from 'highlight.js/lib/languages/markdown';
12
12
  import sql from 'highlight.js/lib/languages/sql';
13
+ import { useChatLanguage } from '../i18n/language.js';
13
14
 
14
15
  // Register essential programming languages for code rendering
15
16
  hljs.registerLanguage('javascript', javascript);
@@ -28,6 +29,9 @@
28
29
  hljs.registerLanguage('markdown', markdown);
29
30
  hljs.registerLanguage('md', markdown);
30
31
  hljs.registerLanguage('sql', sql);
32
+
33
+ // The words of the copy button, in the language of the chat above
34
+ const { t } = useChatLanguage();
31
35
 
32
36
  interface Props {
33
37
  code: string;
@@ -110,7 +114,8 @@
110
114
  }
111
115
  </script>
112
116
 
113
- <div class="code-block">
117
+ <!-- Code is read left to right whatever the language of the screen, so the whole block (the line numbers, the text and the copy button) is a left to right island. -->
118
+ <div class="code-block" dir="ltr">
114
119
  {#if title || language || copyable}
115
120
  <div class="code-header">
116
121
  <div class="code-info">
@@ -129,19 +134,19 @@
129
134
  class="copy-button"
130
135
  class:copied
131
136
  onclick={copyToClipboard}
132
- title={copied ? 'Copied!' : 'Copy code'}
137
+ title={copied ? $t('chat.code.copied') : $t('chat.code.copyTitle')}
133
138
  >
134
139
  {#if copied}
135
140
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
136
141
  <path d="M20 6L9 17l-5-5"/>
137
142
  </svg>
138
- Copied!
143
+ {$t('chat.code.copied')}
139
144
  {:else}
140
145
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
141
146
  <rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
142
147
  <path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/>
143
148
  </svg>
144
- Copy
149
+ {$t('chat.code.copy')}
145
150
  {/if}
146
151
  </button>
147
152
  {/if}
@@ -254,22 +259,22 @@
254
259
 
255
260
  /* Line numbers styling */
256
261
  .with-line-numbers :global(.hljs) {
257
- padding-left: 3em;
262
+ padding-left: 3em; /* rtl-ok: the numbers are at the left of the code, which is read left to right on every screen */
258
263
  position: relative;
259
264
  }
260
265
 
261
266
  .with-line-numbers :global(.hljs::before) {
262
267
  content: counter(line);
263
268
  position: absolute;
264
- left: 0;
269
+ left: 0; /* rtl-ok: the numbers are at the left of the code, which is read left to right on every screen */
265
270
  top: 0;
266
271
  bottom: 0;
267
272
  width: 2.5em;
268
273
  background: #f8f9fa;
269
- border-right: 1px solid #e9ecef;
274
+ border-right: 1px solid #e9ecef; /* rtl-ok: the edge of the numbers that faces the code */
270
275
  color: #6c757d;
271
- text-align: right;
272
- padding-right: 8px;
276
+ text-align: right; /* rtl-ok: the numbers are lined up against the code */
277
+ padding-right: 8px; /* rtl-ok: the space between the numbers and the code */
273
278
  font-size: 12px;
274
279
  line-height: inherit;
275
280
  user-select: none;
@@ -1,5 +1,10 @@
1
1
  <script lang="ts">
2
2
  import type { ChatContext } from '../types/index.js';
3
+ import { useChatLanguage } from '../i18n/language.js';
4
+ import { contextTypeLabel } from '../i18n/labels.js';
5
+
6
+ // The words of the card, in the language of the chat above
7
+ const { t } = useChatLanguage();
3
8
 
4
9
  interface Props {
5
10
  context: ChatContext;
@@ -16,9 +21,9 @@
16
21
  <!-- svelte-ignore a11y_click_events_have_key_events -->
17
22
  <!-- svelte-ignore a11y_no_static_element_interactions -->
18
23
  <button
19
- class="flex items-center justify-between p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-lg cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors shadow-sm hover:shadow-md w-full text-left"
24
+ class="flex items-center justify-between p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-lg cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors shadow-sm hover:shadow-md w-full text-start"
20
25
  onclick={handleClick}
21
- aria-label="Expand {context.title || context.id} chat context"
26
+ aria-label={$t('chat.contextPreview.expand', { name: context.title || context.id })}
22
27
  >
23
28
  <div class="flex items-center gap-3">
24
29
  {#if context.thumbnail}
@@ -48,7 +53,7 @@
48
53
  {context.title || context.id}
49
54
  </h4>
50
55
  <p class="text-xs text-gray-500 dark:text-gray-400 capitalize">
51
- {context.type} chat
56
+ {$t('chat.header.typeChat', { type: contextTypeLabel(context.type, $t) })}
52
57
  </p>
53
58
  </div>
54
59
  </div>
@@ -1,4 +1,9 @@
1
1
  <script lang="ts">
2
+ import { useChatLanguage } from '../i18n/language.js';
3
+
4
+ // The words of the indicator, in the language of the chat above
5
+ const { t } = useChatLanguage();
6
+
2
7
  interface Props {
3
8
  status: 'active' | 'completed' | 'loading' | 'error';
4
9
  messageCount?: number;
@@ -13,7 +18,7 @@
13
18
  case 'completed':
14
19
  return {
15
20
  icon: '✅',
16
- text: 'Completed',
21
+ text: $t('chat.status.completed'),
17
22
  color: 'text-green-600',
18
23
  bgColor: 'bg-green-100',
19
24
  borderColor: 'border-green-200'
@@ -21,7 +26,7 @@
21
26
  case 'loading':
22
27
  return {
23
28
  icon: '⏳',
24
- text: 'Processing...',
29
+ text: $t('chat.status.processing'),
25
30
  color: 'text-blue-600',
26
31
  bgColor: 'bg-blue-100',
27
32
  borderColor: 'border-blue-200'
@@ -29,7 +34,7 @@
29
34
  case 'error':
30
35
  return {
31
36
  icon: '❌',
32
- text: 'Error',
37
+ text: $t('chat.status.error'),
33
38
  color: 'text-red-600',
34
39
  bgColor: 'bg-red-100',
35
40
  borderColor: 'border-red-200'
@@ -37,7 +42,7 @@
37
42
  default: // active
38
43
  return {
39
44
  icon: '💬',
40
- text: 'Active',
45
+ text: $t('chat.status.active'),
41
46
  color: 'text-gray-600',
42
47
  bgColor: 'bg-gray-100',
43
48
  borderColor: 'border-gray-200'
@@ -72,7 +77,7 @@
72
77
  {config.text}
73
78
  {#if messageCount > 0 && status !== 'loading'}
74
79
  <span class="message-count opacity-75">
75
- ({messageCount} message{messageCount !== 1 ? 's' : ''})
80
+ {$t('chat.status.messageCount', { count: messageCount })}
76
81
  </span>
77
82
  {/if}
78
83
  </span>