@aleph-alpha/chat-kit 6.2.0 → 6.4.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 (83) hide show
  1. package/dist/{CkHistory.vue_vue_type_script_setup_true_lang-DPCpIxWc.js → CkHistory.vue_vue_type_script_setup_true_lang-B0WUzTHa.js} +351 -164
  2. package/dist/chat-kit.css +111 -28
  3. package/dist/code-palette-DH_G7mZ5.js +21599 -0
  4. package/dist/components/base/CkCodeEditor/CkCodeEditor.stories.d.ts +49 -0
  5. package/dist/components/base/CkCodeEditor/CkCodeEditor.stories.d.ts.map +1 -0
  6. package/dist/components/base/CkCodeEditor/CkCodeEditor.vue.d.ts +40 -0
  7. package/dist/components/base/CkCodeEditor/CkCodeEditor.vue.d.ts.map +1 -0
  8. package/dist/components/base/CkCodeEditor/badgeDecoration.d.ts +47 -0
  9. package/dist/components/base/CkCodeEditor/badgeDecoration.d.ts.map +1 -0
  10. package/dist/components/base/CkCodeEditor/createCodeMirror.d.ts +48 -0
  11. package/dist/components/base/CkCodeEditor/createCodeMirror.d.ts.map +1 -0
  12. package/dist/components/base/CkCodeEditor/index.d.ts +3 -0
  13. package/dist/components/base/CkCodeEditor/index.d.ts.map +1 -0
  14. package/dist/components/base/CkCodeEditor/types.d.ts +149 -0
  15. package/dist/components/base/CkCodeEditor/types.d.ts.map +1 -0
  16. package/dist/components/base/CkMilkdownEditor/CkMilkdownEditor.stories.d.ts +6 -0
  17. package/dist/components/base/CkMilkdownEditor/CkMilkdownEditor.stories.d.ts.map +1 -1
  18. package/dist/components/base/CkMilkdownEditor/CkMilkdownEditor.vue.d.ts +1 -0
  19. package/dist/components/base/CkMilkdownEditor/CkMilkdownEditor.vue.d.ts.map +1 -1
  20. package/dist/components/base/CkMilkdownEditor/createCrepeEditor.d.ts +1 -0
  21. package/dist/components/base/CkMilkdownEditor/createCrepeEditor.d.ts.map +1 -1
  22. package/dist/components/base/CkMilkdownEditor/types.d.ts +8 -0
  23. package/dist/components/base/CkMilkdownEditor/types.d.ts.map +1 -1
  24. package/dist/components/base/index.d.ts +2 -0
  25. package/dist/components/base/index.d.ts.map +1 -1
  26. package/dist/components/index.d.ts +2 -2
  27. package/dist/components/index.d.ts.map +1 -1
  28. package/dist/components/index.js +27 -26
  29. package/dist/createCodeMirror-5iswYetS.js +169 -0
  30. package/dist/{createCrepeEditor-C9seqnzm.js → createCrepeEditor-C-AQ1w_e.js} +1433 -24739
  31. package/dist/handlers/index.js +1 -1
  32. package/dist/handlers/useChatKitLabels.d.ts +6 -0
  33. package/dist/handlers/useChatKitLabels.d.ts.map +1 -1
  34. package/dist/{components/base/CkMilkdownEditor/codeMirrorTheme.d.ts → helpers/codemirror/theme.d.ts} +1 -1
  35. package/dist/helpers/codemirror/theme.d.ts.map +1 -0
  36. package/dist/{index-DO8xk00f.js → index-ABUMl7H3.js} +3 -3
  37. package/dist/{index-DfvAv_Y2.js → index-BlIc9r0r.js} +3 -2
  38. package/dist/{index-VbqLf82s.js → index-BqWO6mvz.js} +4 -4
  39. package/dist/{index-Bxg0Q_mk.js → index-CFGO7LRz.js} +2 -2
  40. package/dist/index-CG8e3146.js +1825 -0
  41. package/dist/{index-C90_LSx6.js → index-CIF4qQzR.js} +4 -4
  42. package/dist/{index-DXTRMb09.js → index-CR2kGrpY.js} +3 -3
  43. package/dist/{index-B0nlcqqF.js → index-CWp_t8Wl.js} +2 -2
  44. package/dist/{index-CHtY7ztn.js → index-D0IZW-Up.js} +2 -2
  45. package/dist/{index-By7WdPbk.js → index-DKwEe_Tu.js} +4 -4
  46. package/dist/{index-DINJn4Mn.js → index-DLjsqQHx.js} +3 -3
  47. package/dist/{index-eZunhxNH.js → index-DPgw0Cf_.js} +2 -2
  48. package/dist/{index-D85elIIr.js → index-Db5-PJG-.js} +2 -2
  49. package/dist/{index-CFdcEeXx.js → index-Dbi75pKH.js} +3 -2
  50. package/dist/{index-8mYiDHFC.js → index-DfLCrnVq.js} +2 -2
  51. package/dist/{index-6PiPEjJd.js → index-GpSpJ3ti.js} +3 -2
  52. package/dist/{index-reQfKGuJ.js → index-Mh3WUU-6.js} +1 -1
  53. package/dist/{index-DLZcs4H8.js → index-QAs789O5.js} +2 -2
  54. package/dist/{index-DzpUblMx.js → index-S4ylc8JK.js} +3 -3
  55. package/dist/{index-DbVRgXxM.js → index-XZeturb3.js} +3 -3
  56. package/dist/{index-U4LYutvz.js → index-g2X42srv.js} +3 -2
  57. package/dist/{index-DNxEOsDD.js → index-hEJ_Bavx.js} +2 -2
  58. package/dist/{index-C5UC1wP7.js → index-hbS5PDHj.js} +3 -2
  59. package/dist/index.d.ts +2 -2
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +29 -28
  62. package/dist/{useChatKitLabels-Bz58tas9.js → useChatKitLabels-CatQSpfL.js} +2 -0
  63. package/package.json +4 -2
  64. package/src/components/base/CkCodeEditor/CkCodeEditor.spec.ts +284 -0
  65. package/src/components/base/CkCodeEditor/CkCodeEditor.stories.ts +405 -0
  66. package/src/components/base/CkCodeEditor/CkCodeEditor.vue +244 -0
  67. package/src/components/base/CkCodeEditor/badgeDecoration.ts +173 -0
  68. package/src/components/base/CkCodeEditor/createCodeMirror.ts +197 -0
  69. package/src/components/base/CkCodeEditor/index.ts +2 -0
  70. package/src/components/base/CkCodeEditor/types.ts +154 -0
  71. package/src/components/base/CkMilkdownEditor/CkMilkdownEditor.spec.ts +13 -0
  72. package/src/components/base/CkMilkdownEditor/CkMilkdownEditor.stories.ts +34 -0
  73. package/src/components/base/CkMilkdownEditor/CkMilkdownEditor.vue +3 -1
  74. package/src/components/base/CkMilkdownEditor/createCrepeEditor.ts +2 -1
  75. package/src/components/base/CkMilkdownEditor/milkdown-theme.css +39 -26
  76. package/src/components/base/CkMilkdownEditor/types.ts +8 -0
  77. package/src/components/base/index.ts +6 -0
  78. package/src/components/index.ts +4 -0
  79. package/src/handlers/useChatKitLabels.ts +6 -0
  80. package/src/helpers/codemirror/code-palette.css +49 -0
  81. package/src/{components/base/CkMilkdownEditor/codeMirrorTheme.ts → helpers/codemirror/theme.ts} +23 -12
  82. package/src/index.ts +4 -0
  83. package/dist/components/base/CkMilkdownEditor/codeMirrorTheme.d.ts.map +0 -1
@@ -49,36 +49,12 @@
49
49
  --crepe-shadow-1: var(--shadow-md);
50
50
  --crepe-shadow-2: var(--shadow-lg);
51
51
 
52
- /* CodeMirror palette ≈ Shiki `github-light` (what UiCodeBlock renders). */
53
- --ck-cm-bg: #ffffff;
54
- --ck-cm-foreground: #24292f;
55
- --ck-cm-keyword: #cf222e;
56
- --ck-cm-string: #0a3069;
57
- --ck-cm-comment: #6e7781;
58
- --ck-cm-function: #8250df;
59
- --ck-cm-constant: #0550ae;
60
- /* UiCodeBlock rewrites Shiki's orange entity colour to the primary text token. */
61
- --ck-cm-entity: oklch(var(--content-on-surface-primary));
62
- --ck-cm-tag: #116329;
63
- --ck-cm-error: #82071e;
64
- --ck-cm-selection: oklch(var(--background-accent-soft));
52
+ /* The `--ck-cm-*` syntax palette comes from the shared `code-palette.css`
53
+ * via the `ck-code-surface` class on this same root. */
65
54
 
66
55
  position: relative;
67
56
  }
68
57
 
69
- /* CodeMirror palette ≈ Shiki `github-dark`. */
70
- html.dark .ck-milkdown {
71
- --ck-cm-bg: #24292e;
72
- --ck-cm-foreground: #c9d1d9;
73
- --ck-cm-keyword: #ff7b72;
74
- --ck-cm-string: #a5d6ff;
75
- --ck-cm-comment: #8b949e;
76
- --ck-cm-function: #d2a8ff;
77
- --ck-cm-constant: #79c0ff;
78
- --ck-cm-tag: #7ee787;
79
- --ck-cm-error: #ffa198;
80
- }
81
-
82
58
  /* ------------------------------------------------------------------------ */
83
59
  /* Minimal reset (replaces Crepe's reset.css) */
84
60
  /* ------------------------------------------------------------------------ */
@@ -407,10 +383,47 @@ html.dark .ck-milkdown {
407
383
  color: var(--ck-cm-foreground);
408
384
  }
409
385
 
386
+ /* Line-number gutter. CodeMirror's `basicSetup` (which Crepe always loads)
387
+ * always renders it, so `showLineNumbers` only toggles this class — no
388
+ * reconfiguration, and the change applies to code blocks already on screen.
389
+ * Hidden by default to match `UiCodeBlock`, whose `showLineNumbers` is also
390
+ * false by default, so a document reads the same in the editor and in
391
+ * `CkMarkdownRenderer`. */
410
392
  .ck-milkdown .milkdown .milkdown-code-block .cm-gutters {
411
393
  display: none;
412
394
  }
413
395
 
396
+ .ck-milkdown--line-numbers .milkdown .milkdown-code-block .cm-gutters {
397
+ display: flex;
398
+ }
399
+
400
+ /* `basicSetup` also installs a code-folding gutter. Its chevrons are noise in
401
+ * a prose editor and have no counterpart in `UiCodeBlock`, so only the numbers
402
+ * are ever shown. `!important` is required because CodeMirror's own base theme
403
+ * declares `.cm-gutter { display: flex !important }`, which no amount of
404
+ * specificity can outrank. Crepe always passes `basicSetup`, so the extension
405
+ * cannot simply be left out. */
406
+ .ck-milkdown .milkdown .milkdown-code-block .cm-foldGutter {
407
+ display: none !important;
408
+ }
409
+
410
+ .ck-milkdown--line-numbers
411
+ .milkdown
412
+ .milkdown-code-block
413
+ .cm-lineNumbers
414
+ .cm-gutterElement {
415
+ min-width: 2.25rem;
416
+ padding: 0 0.75rem 0 1rem;
417
+ color: oklch(var(--content-on-surface-muted));
418
+ text-align: right;
419
+ }
420
+
421
+ /* The gutter supplies the left inset once it is visible, so the code itself
422
+ * should not pay for it twice. */
423
+ .ck-milkdown--line-numbers .milkdown .milkdown-code-block .cm-content {
424
+ padding-left: 0;
425
+ }
426
+
414
427
  /* Shown while the CodeMirror instance is still mounting. */
415
428
  .ck-milkdown .milkdown .milkdown-code-block .milkdown-code-block-placeholder {
416
429
  margin: 0;
@@ -71,6 +71,14 @@ export interface CkMilkdownEditorProps {
71
71
  * @default false
72
72
  */
73
73
  autofocus?: boolean;
74
+ /**
75
+ * Show a line-number gutter on fenced code blocks. Matches the prop of the
76
+ * same name on `UiCodeBlock`, so one flag can drive the editor and the
77
+ * rendered message alike. Applies to code blocks already on screen.
78
+ *
79
+ * @default false
80
+ */
81
+ showLineNumbers?: boolean;
74
82
  }
75
83
 
76
84
  /** Events emitted by {@link CkMilkdownEditor}. */
@@ -86,3 +86,9 @@ export type {
86
86
  CkMilkdownEditorExposed,
87
87
  CkMilkdownEditorProps,
88
88
  } from './CkMilkdownEditor';
89
+ export { CkCodeEditor } from './CkCodeEditor';
90
+ export type {
91
+ CkCodeEditorEmits,
92
+ CkCodeEditorExposed,
93
+ CkCodeEditorProps,
94
+ } from './CkCodeEditor';
@@ -28,6 +28,7 @@ export {
28
28
  CkUserMessage,
29
29
  CkEditableUserMessage,
30
30
  CkMilkdownEditor,
31
+ CkCodeEditor,
31
32
  } from './base';
32
33
  export type {
33
34
  CkAgentMessageHeaderProps,
@@ -70,6 +71,9 @@ export type {
70
71
  CkMilkdownEditorEmits,
71
72
  CkMilkdownEditorExposed,
72
73
  CkMilkdownEditorProps,
74
+ CkCodeEditorEmits,
75
+ CkCodeEditorExposed,
76
+ CkCodeEditorProps,
73
77
  } from './base';
74
78
 
75
79
  // Composed (pattern) components
@@ -111,6 +111,10 @@ export type ChatKitLabels = {
111
111
  * set and more conversations exist than the limit.
112
112
  */
113
113
  historyShowAll?: string;
114
+ /** Accessible name of the copy button in the `CkCodeEditor` header. */
115
+ codeEditorCopy?: string;
116
+ /** Accessible name of the `CkCodeEditor` copy button just after a copy. */
117
+ codeEditorCopied?: string;
114
118
  /** Accessible name of the "Bold" button in the `CkMilkdownEditor` toolbar. */
115
119
  markdownEditorBold?: string;
116
120
  /** Accessible name of the "Italic" button in the `CkMilkdownEditor` toolbar. */
@@ -168,6 +172,8 @@ export const defaultChatKitLabels = {
168
172
  historyItemEditAction: 'Edit',
169
173
  historyItemDeleteAction: 'Delete',
170
174
  historyShowAll: 'Show all',
175
+ codeEditorCopy: 'Copy code',
176
+ codeEditorCopied: 'Copied',
171
177
  markdownEditorBold: 'Bold',
172
178
  markdownEditorItalic: 'Italic',
173
179
  markdownEditorStrikethrough: 'Strikethrough',
@@ -0,0 +1,49 @@
1
+ /*
2
+ * Syntax palette shared by every CodeMirror surface in chat-kit — the code
3
+ * blocks inside `CkMilkdownEditor` and the standalone `CkCodeEditor`.
4
+ *
5
+ * The values are Shiki's `github-light` and `github-dark`, which is what
6
+ * `UiCodeBlock` renders inside `CkMarkdownRenderer`, read off a rendered block
7
+ * rather than copied from memory. A snippet therefore keeps its colours whether
8
+ * it is being read or edited. `theme.ts` maps CodeMirror's syntax tags onto
9
+ * these variables; nothing else should hardcode a code colour.
10
+ *
11
+ * Apply `.ck-code-surface` to the root of any component hosting a CodeMirror
12
+ * instance. The dark values follow `html.dark`, matching how `UiCodeBlock`
13
+ * switches its own Shiki theme.
14
+ *
15
+ * Exact parity is not achievable for every token: Shiki classifies with
16
+ * TextMate grammars and CodeMirror with Lezer, and the two disagree at the
17
+ * edges. The mapping in `theme.ts` targets the classes that actually occur in
18
+ * everyday code.
19
+ */
20
+
21
+ .ck-code-surface {
22
+ --ck-cm-bg: #ffffff;
23
+ --ck-cm-foreground: #24292e;
24
+ --ck-cm-keyword: #d73a49;
25
+ --ck-cm-string: #032f62;
26
+ --ck-cm-comment: #6a737d;
27
+ /* Declared functions, classes and interfaces. */
28
+ --ck-cm-function: #6f42c1;
29
+ /* Built-in types, literals and plain variables. */
30
+ --ck-cm-constant: #005cc5;
31
+ /* `UiCodeBlock` rewrites Shiki's orange (#e36209 / #ffab70) to the primary
32
+ * text token, which is what declared property names end up as. */
33
+ --ck-cm-property: oklch(var(--content-on-surface-primary));
34
+ --ck-cm-tag: #22863a;
35
+ --ck-cm-error: #b31d28;
36
+ --ck-cm-selection: oklch(var(--background-accent-soft));
37
+ }
38
+
39
+ html.dark .ck-code-surface {
40
+ --ck-cm-bg: #24292e;
41
+ --ck-cm-foreground: #e1e4e8;
42
+ --ck-cm-keyword: #f97583;
43
+ --ck-cm-string: #9ecbff;
44
+ --ck-cm-comment: #6a737d;
45
+ --ck-cm-function: #b392f0;
46
+ --ck-cm-constant: #79b8ff;
47
+ --ck-cm-tag: #85e89d;
48
+ --ck-cm-error: #fdaeb7;
49
+ }
@@ -21,6 +21,7 @@ const cssVar = (name: string): string => `var(--ck-cm-${name})`;
21
21
  * editor and in `CkMarkdownRenderer`.
22
22
  */
23
23
  export const ckHighlightStyle = HighlightStyle.define([
24
+ // Keywords, and the operators GitHub colours like keywords (`=`, `:`).
24
25
  {
25
26
  tag: [
26
27
  t.keyword,
@@ -29,6 +30,7 @@ export const ckHighlightStyle = HighlightStyle.define([
29
30
  t.definitionKeyword,
30
31
  t.moduleKeyword,
31
32
  t.operatorKeyword,
33
+ t.operator,
32
34
  ],
33
35
  color: cssVar('keyword'),
34
36
  },
@@ -40,14 +42,20 @@ export const ckHighlightStyle = HighlightStyle.define([
40
42
  tag: [t.comment, t.lineComment, t.blockComment, t.docComment],
41
43
  color: cssVar('comment'),
42
44
  },
45
+ // Things being declared: functions, classes, interfaces.
43
46
  {
44
47
  tag: [
45
48
  t.function(t.variableName),
46
49
  t.function(t.propertyName),
47
50
  t.definition(t.function(t.variableName)),
51
+ t.definition(t.typeName),
52
+ t.className,
53
+ t.namespace,
54
+ t.self,
48
55
  ],
49
56
  color: cssVar('function'),
50
57
  },
58
+ // Built-in types, literals and ordinary variables.
51
59
  {
52
60
  tag: [
53
61
  t.number,
@@ -56,25 +64,20 @@ export const ckHighlightStyle = HighlightStyle.define([
56
64
  t.atom,
57
65
  t.constant(t.name),
58
66
  t.constant(t.variableName),
67
+ t.definition(t.variableName),
68
+ t.typeName,
69
+ t.standard(t.typeName),
59
70
  t.propertyName,
60
71
  t.attributeName,
61
72
  t.attributeValue,
62
73
  ],
63
74
  color: cssVar('constant'),
64
75
  },
65
- {
66
- tag: [
67
- t.typeName,
68
- t.className,
69
- t.namespace,
70
- t.definition(t.variableName),
71
- t.self,
72
- ],
73
- color: cssVar('entity'),
74
- },
76
+ // A declared property name, which UiCodeBlock renders in the text token.
77
+ { tag: t.definition(t.propertyName), color: cssVar('property') },
75
78
  { tag: [t.tagName, t.angleBracket], color: cssVar('tag') },
76
79
  {
77
- tag: [t.variableName, t.operator, t.punctuation, t.bracket, t.separator],
80
+ tag: [t.variableName, t.punctuation, t.bracket, t.separator],
78
81
  color: cssVar('foreground'),
79
82
  },
80
83
  { tag: t.heading, fontWeight: 'bold' },
@@ -107,8 +110,16 @@ export const ckCodeMirrorTheme: Extension = [
107
110
  '.cm-line': {
108
111
  padding: '0',
109
112
  },
113
+ // Gutter visibility is driven by the `showLineNumbers` prop through a root
114
+ // class in `milkdown-theme.css`, not from here, so it can toggle without
115
+ // reconfiguring CodeMirror. Only the chrome is set here.
110
116
  '.cm-gutters': {
111
- display: 'none',
117
+ backgroundColor: 'transparent',
118
+ borderRight: 'none',
119
+ color: cssVar('comment'),
120
+ },
121
+ '.cm-activeLineGutter': {
122
+ backgroundColor: 'transparent',
112
123
  },
113
124
  '.cm-cursor, .cm-dropCursor': {
114
125
  borderLeftColor: cssVar('foreground'),
package/src/index.ts CHANGED
@@ -100,6 +100,7 @@ export {
100
100
  CkUserMessage,
101
101
  CkEditableUserMessage,
102
102
  CkMilkdownEditor,
103
+ CkCodeEditor,
103
104
  } from './components';
104
105
  export type {
105
106
  CkAgentMessageHeaderProps,
@@ -145,6 +146,9 @@ export type {
145
146
  CkMilkdownEditorEmits,
146
147
  CkMilkdownEditorExposed,
147
148
  CkMilkdownEditorProps,
149
+ CkCodeEditorEmits,
150
+ CkCodeEditorExposed,
151
+ CkCodeEditorProps,
148
152
  } from './components';
149
153
 
150
154
  // Helpers
@@ -1 +0,0 @@
1
- {"version":3,"file":"codeMirrorTheme.d.ts","sourceRoot":"","sources":["../../../../src/components/base/CkMilkdownEditor/codeMirrorTheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAsB,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAInD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,2FAC6D,CAAC;AAO3F;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,gBA8D3B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAwC/B,CAAC"}