@kitn.ai/ui 0.28.0 → 0.29.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 (376) hide show
  1. package/README.md +1 -1
  2. package/dist/agent-tooling/construct/public.d.ts +15 -0
  3. package/dist/agent-tooling/construct/schema.d.ts +111 -0
  4. package/dist/construct-cli.es.js +3 -3
  5. package/dist/construct.d.ts +5 -0
  6. package/dist/construct.js +327 -0
  7. package/dist/core-C8fzo39E.js +1 -12
  8. package/dist/engine-javascript-C1x7zo1_.js +1 -141
  9. package/dist/mcp.es.js +1 -1
  10. package/package.json +16 -16
  11. package/bin/route.test.js +0 -58
  12. package/src/agent-tooling/README.md +0 -192
  13. package/src/agent-tooling/archetypes.ts +0 -205
  14. package/src/agent-tooling/catalog/README.md +0 -676
  15. package/src/agent-tooling/catalog/catalog-types.ts +0 -231
  16. package/src/agent-tooling/catalog/fabrications.ts +0 -96
  17. package/src/agent-tooling/catalog/invariants.ts +0 -284
  18. package/src/agent-tooling/catalog/labs-titles.ts +0 -114
  19. package/src/agent-tooling/catalog/scenarios.ts +0 -87
  20. package/src/agent-tooling/catalog/surfaces.ts +0 -347
  21. package/src/agent-tooling/construct/cli-entry.ts +0 -8
  22. package/src/agent-tooling/construct/cli.ts +0 -147
  23. package/src/agent-tooling/construct/codegen.ts +0 -1635
  24. package/src/agent-tooling/construct/construct.v1.schema.json +0 -319
  25. package/src/agent-tooling/construct/dev.ts +0 -148
  26. package/src/agent-tooling/construct/fixtures/demo-widget.construct.json +0 -7
  27. package/src/agent-tooling/construct/fixtures/ops-console.construct.json +0 -44
  28. package/src/agent-tooling/construct/fixtures/owner-widget.construct.json +0 -32
  29. package/src/agent-tooling/construct/schema.ts +0 -452
  30. package/src/agent-tooling/integrations/anthropic.ts +0 -442
  31. package/src/agent-tooling/integrations/cloudflare.ts +0 -218
  32. package/src/agent-tooling/integrations/langgraph.ts +0 -133
  33. package/src/agent-tooling/integrations/mastra.ts +0 -182
  34. package/src/agent-tooling/integrations/mock.ts +0 -148
  35. package/src/agent-tooling/integrations/ollama.ts +0 -97
  36. package/src/agent-tooling/integrations/openai.ts +0 -95
  37. package/src/agent-tooling/integrations/openrouter.ts +0 -82
  38. package/src/agent-tooling/integrations/pi.ts +0 -176
  39. package/src/agent-tooling/integrations/pydantic-ai.ts +0 -108
  40. package/src/agent-tooling/integrations/vercel-ai-sdk.ts +0 -398
  41. package/src/agent-tooling/mcp/css-raw.d.ts +0 -12
  42. package/src/agent-tooling/mcp/manifest.ts +0 -422
  43. package/src/agent-tooling/mcp/server.ts +0 -116
  44. package/src/agent-tooling/mcp/stdio.ts +0 -18
  45. package/src/agent-tooling/mcp/tools/construct.ts +0 -130
  46. package/src/agent-tooling/mcp/tools/debug.ts +0 -621
  47. package/src/agent-tooling/mcp/tools/reference.ts +0 -980
  48. package/src/agent-tooling/mcp/tools/scaffold.ts +0 -6708
  49. package/src/agent-tooling/mcp/tools/theme.ts +0 -456
  50. package/src/agent-tooling/mcp/tools/types.ts +0 -14
  51. package/src/agent-tooling/mcp/validate-args.ts +0 -141
  52. package/src/agent-tooling/recipes/composed-thread.ts +0 -714
  53. package/src/agent-tooling/recipes/index.ts +0 -22
  54. package/src/agent-tooling/recipes/types.ts +0 -32
  55. package/src/agent-tooling/registry.ts +0 -132
  56. package/src/agent-tooling/route-emit.ts +0 -305
  57. package/src/agent-tooling/types.ts +0 -390
  58. package/src/components/artifact-card.tsx +0 -120
  59. package/src/components/artifact.tsx +0 -914
  60. package/src/components/attachment-types.ts +0 -66
  61. package/src/components/attachments.tsx +0 -536
  62. package/src/components/audio-visualizer/audio-visualizer.voice-fixture.ts +0 -257
  63. package/src/components/audio-visualizer/aurora.glsl.ts +0 -330
  64. package/src/components/audio-visualizer/fit-scale.ts +0 -112
  65. package/src/components/audio-visualizer/index.tsx +0 -528
  66. package/src/components/audio-visualizer/labs/lab-choreography.ts +0 -187
  67. package/src/components/audio-visualizer/labs/lab-shaders.ts +0 -363
  68. package/src/components/audio-visualizer/labs/lab-visualizer.tsx +0 -102
  69. package/src/components/audio-visualizer/shader-canvas.tsx +0 -876
  70. package/src/components/audio-visualizer/sizes.ts +0 -54
  71. package/src/components/audio-visualizer/variant-aurora.tsx +0 -305
  72. package/src/components/audio-visualizer/variant-bar.tsx +0 -175
  73. package/src/components/audio-visualizer/variant-custom.tsx +0 -344
  74. package/src/components/audio-visualizer/variant-grid.tsx +0 -175
  75. package/src/components/audio-visualizer/variant-radial.tsx +0 -163
  76. package/src/components/audio-visualizer/variant-wave.tsx +0 -130
  77. package/src/components/audio-visualizer/wave.glsl.ts +0 -130
  78. package/src/components/card-fallback.tsx +0 -60
  79. package/src/components/card-renderer.tsx +0 -220
  80. package/src/components/card.tsx +0 -212
  81. package/src/components/chain-of-thought.tsx +0 -348
  82. package/src/components/chat-container.tsx +0 -89
  83. package/src/components/chat-scope-picker.tsx +0 -57
  84. package/src/components/chat-thread.tsx +0 -1014
  85. package/src/components/checkpoint.tsx +0 -88
  86. package/src/components/choice-card.tsx +0 -743
  87. package/src/components/coachmark.tsx +0 -249
  88. package/src/components/code-block.tsx +0 -181
  89. package/src/components/composer-dom.ts +0 -159
  90. package/src/components/composer-highlight.ts +0 -242
  91. package/src/components/composer-history.ts +0 -82
  92. package/src/components/composer.tsx +0 -1075
  93. package/src/components/confirm-card.tsx +0 -402
  94. package/src/components/context.tsx +0 -377
  95. package/src/components/conversation-item.tsx +0 -241
  96. package/src/components/conversation-list.tsx +0 -429
  97. package/src/components/conversation-panel.tsx +0 -118
  98. package/src/components/dismissed-stub.tsx +0 -80
  99. package/src/components/embed.tsx +0 -200
  100. package/src/components/empty.tsx +0 -177
  101. package/src/components/feedback-bar.tsx +0 -166
  102. package/src/components/file-tree.tsx +0 -530
  103. package/src/components/file-upload.tsx +0 -167
  104. package/src/components/form-widgets.tsx +0 -525
  105. package/src/components/form.tsx +0 -1296
  106. package/src/components/home-panel.tsx +0 -159
  107. package/src/components/image.tsx +0 -65
  108. package/src/components/link-preview.tsx +0 -195
  109. package/src/components/loader.tsx +0 -367
  110. package/src/components/markdown.tsx +0 -162
  111. package/src/components/message-skills.tsx +0 -40
  112. package/src/components/message.tsx +0 -765
  113. package/src/components/model-switcher.tsx +0 -132
  114. package/src/components/prompt-input.tsx +0 -188
  115. package/src/components/prompt-suggestion.tsx +0 -150
  116. package/src/components/reasoning.tsx +0 -293
  117. package/src/components/response-compare-types.ts +0 -152
  118. package/src/components/response-compare.tsx +0 -455
  119. package/src/components/response-stream.tsx +0 -109
  120. package/src/components/screen.tsx +0 -181
  121. package/src/components/scroll-button.tsx +0 -93
  122. package/src/components/source.tsx +0 -192
  123. package/src/components/tasks-card.tsx +0 -801
  124. package/src/components/text-shimmer.tsx +0 -37
  125. package/src/components/thinking-bar.tsx +0 -50
  126. package/src/components/thread.tsx +0 -228
  127. package/src/components/toast.tsx +0 -503
  128. package/src/components/tool-classify.ts +0 -26
  129. package/src/components/tool-types.ts +0 -49
  130. package/src/components/tool.tsx +0 -190
  131. package/src/components/use-card-resolution.ts +0 -44
  132. package/src/components/voice-input.tsx +0 -222
  133. package/src/components/voice-output.tsx +0 -242
  134. package/src/components/widget-tab-bar.tsx +0 -73
  135. package/src/components/workspace-shell.tsx +0 -285
  136. package/src/diagnostics/hook.ts +0 -352
  137. package/src/diagnostics/index.ts +0 -82
  138. package/src/diagnostics/report-request.ts +0 -296
  139. package/src/elements/agent-card.tsx +0 -67
  140. package/src/elements/artifact.tsx +0 -194
  141. package/src/elements/attachments.tsx +0 -140
  142. package/src/elements/audio-visualizer.tsx +0 -227
  143. package/src/elements/autoloader.ts +0 -89
  144. package/src/elements/avatar.tsx +0 -33
  145. package/src/elements/badge.tsx +0 -32
  146. package/src/elements/button.tsx +0 -149
  147. package/src/elements/card.tsx +0 -133
  148. package/src/elements/cards.tsx +0 -266
  149. package/src/elements/chain-of-thought.tsx +0 -141
  150. package/src/elements/chat-scope-picker.tsx +0 -65
  151. package/src/elements/chat-types.ts +0 -102
  152. package/src/elements/chat-workspace.tsx +0 -188
  153. package/src/elements/chat.tsx +0 -304
  154. package/src/elements/checkbox-group.tsx +0 -164
  155. package/src/elements/checkbox.tsx +0 -134
  156. package/src/elements/checkpoint.tsx +0 -47
  157. package/src/elements/choice.tsx +0 -100
  158. package/src/elements/coachmark.tsx +0 -90
  159. package/src/elements/code-block.tsx +0 -60
  160. package/src/elements/command.tsx +0 -197
  161. package/src/elements/compare.tsx +0 -111
  162. package/src/elements/compiled.css +0 -2
  163. package/src/elements/composer.tsx +0 -162
  164. package/src/elements/confirm-card.tsx +0 -76
  165. package/src/elements/context-meter.tsx +0 -107
  166. package/src/elements/conversation-item.tsx +0 -120
  167. package/src/elements/conversation-list.tsx +0 -203
  168. package/src/elements/css.ts +0 -5
  169. package/src/elements/default-input.tsx +0 -392
  170. package/src/elements/define-entry.ts +0 -12
  171. package/src/elements/define.tsx +0 -563
  172. package/src/elements/diagnostic-events.ts +0 -114
  173. package/src/elements/dialog.tsx +0 -145
  174. package/src/elements/disclosure.ts +0 -95
  175. package/src/elements/dock.tsx +0 -215
  176. package/src/elements/dropdown.tsx +0 -123
  177. package/src/elements/editable-label.tsx +0 -140
  178. package/src/elements/element-data-types.ts +0 -152
  179. package/src/elements/element-diagnostics.ts +0 -392
  180. package/src/elements/element-manifest.json +0 -354
  181. package/src/elements/element-nonscalar.json +0 -187
  182. package/src/elements/element-types.d.ts +0 -4353
  183. package/src/elements/embed.tsx +0 -35
  184. package/src/elements/empty.tsx +0 -29
  185. package/src/elements/feedback-bar.tsx +0 -66
  186. package/src/elements/file-tree.tsx +0 -62
  187. package/src/elements/file-upload.tsx +0 -44
  188. package/src/elements/form.tsx +0 -94
  189. package/src/elements/hover-card.tsx +0 -80
  190. package/src/elements/icon.tsx +0 -41
  191. package/src/elements/image.tsx +0 -32
  192. package/src/elements/input.tsx +0 -492
  193. package/src/elements/kbd.tsx +0 -45
  194. package/src/elements/link-preview.tsx +0 -34
  195. package/src/elements/loader.tsx +0 -25
  196. package/src/elements/markdown.tsx +0 -38
  197. package/src/elements/menu.tsx +0 -241
  198. package/src/elements/message-skills.tsx +0 -83
  199. package/src/elements/message.tsx +0 -361
  200. package/src/elements/model-switcher.tsx +0 -121
  201. package/src/elements/nav.tsx +0 -87
  202. package/src/elements/notice.tsx +0 -53
  203. package/src/elements/pane-grid.tsx +0 -111
  204. package/src/elements/pane-group.tsx +0 -119
  205. package/src/elements/pane.tsx +0 -129
  206. package/src/elements/popover.tsx +0 -81
  207. package/src/elements/progress-bar.tsx +0 -39
  208. package/src/elements/prompt-dock.tsx +0 -82
  209. package/src/elements/prompt-input.tsx +0 -240
  210. package/src/elements/prompt-suggestions.tsx +0 -113
  211. package/src/elements/radio-group.tsx +0 -129
  212. package/src/elements/reasoning.tsx +0 -71
  213. package/src/elements/register-impl.ts +0 -148
  214. package/src/elements/register.ts +0 -76
  215. package/src/elements/remote.tsx +0 -225
  216. package/src/elements/resizable.globals.d.ts +0 -36
  217. package/src/elements/resizable.tsx +0 -704
  218. package/src/elements/response-stream.tsx +0 -40
  219. package/src/elements/screen.tsx +0 -90
  220. package/src/elements/scroll-area.tsx +0 -33
  221. package/src/elements/scroll-button.tsx +0 -179
  222. package/src/elements/search.tsx +0 -185
  223. package/src/elements/segmented.tsx +0 -129
  224. package/src/elements/select.tsx +0 -165
  225. package/src/elements/separator.tsx +0 -36
  226. package/src/elements/setting-item.tsx +0 -50
  227. package/src/elements/settings-group.tsx +0 -37
  228. package/src/elements/skeleton.tsx +0 -45
  229. package/src/elements/slider.tsx +0 -171
  230. package/src/elements/slot-text.ts +0 -73
  231. package/src/elements/slots.ts +0 -787
  232. package/src/elements/source.tsx +0 -126
  233. package/src/elements/status.tsx +0 -42
  234. package/src/elements/styles.css +0 -328
  235. package/src/elements/switch.tsx +0 -118
  236. package/src/elements/tabs.tsx +0 -95
  237. package/src/elements/tasks.tsx +0 -103
  238. package/src/elements/text-shimmer.tsx +0 -28
  239. package/src/elements/thinking-bar.tsx +0 -43
  240. package/src/elements/thread.tsx +0 -139
  241. package/src/elements/toast.tsx +0 -106
  242. package/src/elements/tool.tsx +0 -78
  243. package/src/elements/tooltip.tsx +0 -85
  244. package/src/elements/validate-messages.ts +0 -76
  245. package/src/elements/voice-input.tsx +0 -100
  246. package/src/elements/voice-output.tsx +0 -82
  247. package/src/index.ts +0 -430
  248. package/src/primitives/audio-bands.ts +0 -174
  249. package/src/primitives/card-component-types.ts +0 -63
  250. package/src/primitives/card-contract.ts +0 -80
  251. package/src/primitives/card-data-types.ts +0 -361
  252. package/src/primitives/card-host.tsx +0 -37
  253. package/src/primitives/card-recovery.ts +0 -160
  254. package/src/primitives/card-registry.tsx +0 -78
  255. package/src/primitives/card-resolution.ts +0 -36
  256. package/src/primitives/card-routing.ts +0 -85
  257. package/src/primitives/card-schemas/artifact.schema.json +0 -92
  258. package/src/primitives/card-schemas/card-envelope.schema.json +0 -14
  259. package/src/primitives/card-schemas/card-event.schema.json +0 -12
  260. package/src/primitives/card-schemas/choice.schema.json +0 -75
  261. package/src/primitives/card-schemas/confirm.schema.json +0 -65
  262. package/src/primitives/card-schemas/embed.schema.json +0 -63
  263. package/src/primitives/card-schemas/form.result.schema.json +0 -7
  264. package/src/primitives/card-schemas/form.schema.json +0 -53
  265. package/src/primitives/card-schemas/link.schema.json +0 -54
  266. package/src/primitives/card-schemas/tasks.result.schema.json +0 -16
  267. package/src/primitives/card-schemas/tasks.schema.json +0 -83
  268. package/src/primitives/card-tags.ts +0 -61
  269. package/src/primitives/card-validate-cards.ts +0 -255
  270. package/src/primitives/card-validate-schemas.ts +0 -58
  271. package/src/primitives/card-validate.ts +0 -131
  272. package/src/primitives/chat-config.tsx +0 -103
  273. package/src/primitives/composer-model.ts +0 -49
  274. package/src/primitives/composer-triggers.ts +0 -35
  275. package/src/primitives/controllable.ts +0 -21
  276. package/src/primitives/conversation-store.ts +0 -248
  277. package/src/primitives/create-kai-chat.ts +0 -66
  278. package/src/primitives/create-tween.ts +0 -266
  279. package/src/primitives/embed-providers.ts +0 -254
  280. package/src/primitives/field-mask.ts +0 -256
  281. package/src/primitives/field-semantics.ts +0 -115
  282. package/src/primitives/highlighter.ts +0 -157
  283. package/src/primitives/input-mask.ts +0 -853
  284. package/src/primitives/link-preview.ts +0 -87
  285. package/src/primitives/message-feedback.ts +0 -124
  286. package/src/primitives/pdf-preview.ts +0 -121
  287. package/src/primitives/toast-store.ts +0 -338
  288. package/src/primitives/url-scheme-policy.ts +0 -70
  289. package/src/primitives/use-audio-analysis.ts +0 -340
  290. package/src/primitives/use-auto-resize.ts +0 -31
  291. package/src/primitives/use-resize-observer.ts +0 -45
  292. package/src/primitives/use-sequencer.ts +0 -72
  293. package/src/primitives/use-speech-recognition.ts +0 -146
  294. package/src/primitives/use-stick-to-bottom.ts +0 -75
  295. package/src/primitives/use-text-stream.ts +0 -143
  296. package/src/primitives/use-voice-recorder.ts +0 -62
  297. package/src/primitives/visualizer-sequences.ts +0 -350
  298. package/src/remote/host-embed.ts +0 -345
  299. package/src/remote/index.ts +0 -2
  300. package/src/remote/origin.ts +0 -30
  301. package/src/remote/provider-runtime.ts +0 -262
  302. package/src/remote/provider.ts +0 -2
  303. package/src/remote/validate.ts +0 -22
  304. package/src/remote/version.ts +0 -12
  305. package/src/remote/wire.ts +0 -48
  306. package/src/schemas/from-tool-call.ts +0 -151
  307. package/src/schemas/index.ts +0 -341
  308. package/src/schemas/provider-subsets.ts +0 -538
  309. package/src/schemas/registry.ts +0 -355
  310. package/src/schemas/tool-defs.ts +0 -793
  311. package/src/solid.ts +0 -173
  312. package/src/state/index.ts +0 -44
  313. package/src/state/messages.ts +0 -53
  314. package/src/state/mock.ts +0 -297
  315. package/src/state/parts.ts +0 -295
  316. package/src/state/persistence.ts +0 -180
  317. package/src/state/stream.ts +0 -246
  318. package/src/state/suggestions.ts +0 -9
  319. package/src/state/threads.ts +0 -142
  320. package/src/test-utils/fake-clock.ts +0 -88
  321. package/src/types.ts +0 -95
  322. package/src/ui/action-icons.ts +0 -53
  323. package/src/ui/agent-card.tsx +0 -218
  324. package/src/ui/avatar.tsx +0 -23
  325. package/src/ui/badge.tsx +0 -21
  326. package/src/ui/button.tsx +0 -49
  327. package/src/ui/card.tsx +0 -245
  328. package/src/ui/checkbox-group.tsx +0 -153
  329. package/src/ui/checkbox.tsx +0 -63
  330. package/src/ui/collapsible.tsx +0 -163
  331. package/src/ui/command.tsx +0 -103
  332. package/src/ui/dialog.tsx +0 -223
  333. package/src/ui/dock.tsx +0 -630
  334. package/src/ui/dropdown.tsx +0 -636
  335. package/src/ui/editable-label.tsx +0 -112
  336. package/src/ui/hover-card.tsx +0 -345
  337. package/src/ui/icon.tsx +0 -167
  338. package/src/ui/input.tsx +0 -391
  339. package/src/ui/kbd.tsx +0 -118
  340. package/src/ui/nav.tsx +0 -282
  341. package/src/ui/notice.tsx +0 -84
  342. package/src/ui/overlay.tsx +0 -277
  343. package/src/ui/pane-grid.tsx +0 -117
  344. package/src/ui/pane-group.tsx +0 -291
  345. package/src/ui/pane.tsx +0 -193
  346. package/src/ui/popover.tsx +0 -106
  347. package/src/ui/progress-bar.tsx +0 -83
  348. package/src/ui/prompt-dock.tsx +0 -145
  349. package/src/ui/radio.tsx +0 -150
  350. package/src/ui/resizable.tsx +0 -693
  351. package/src/ui/scroll-area.tsx +0 -26
  352. package/src/ui/segmented.tsx +0 -109
  353. package/src/ui/select.tsx +0 -168
  354. package/src/ui/separator.tsx +0 -10
  355. package/src/ui/settings-group.tsx +0 -67
  356. package/src/ui/skeleton.tsx +0 -73
  357. package/src/ui/slider.tsx +0 -178
  358. package/src/ui/status.tsx +0 -48
  359. package/src/ui/switch.tsx +0 -119
  360. package/src/ui/tabs.tsx +0 -168
  361. package/src/ui/textarea.tsx +0 -21
  362. package/src/ui/tooltip.tsx +0 -118
  363. package/src/utils/cn.ts +0 -30
  364. package/src/wire/chunk.ts +0 -248
  365. package/src/wire/consume.ts +0 -599
  366. package/src/wire/diagnostics.ts +0 -727
  367. package/src/wire/encode-probe.ts +0 -214
  368. package/src/wire/encode.ts +0 -947
  369. package/src/wire/files.ts +0 -342
  370. package/src/wire/formats/anthropic.ts +0 -274
  371. package/src/wire/formats/openai.ts +0 -228
  372. package/src/wire/index.ts +0 -95
  373. package/src/wire/media-types.ts +0 -344
  374. package/src/wire/read.ts +0 -396
  375. package/src/wire/sink-helpers.ts +0 -50
  376. package/src/wire/sse.ts +0 -153
@@ -1,162 +0,0 @@
1
- import { createSignal } from 'solid-js';
2
- import { defineWebComponent } from './define';
3
- import type { ComposerDoc, EntityRef } from '../primitives/composer-model';
4
- import type { TriggerDef, TriggerItem, HighlightRule, ComposerChange, ComposerController } from '../components/composer';
5
- import { Composer } from '../components/composer';
6
-
7
- /**
8
- * Parse a single light-DOM `<kai-trigger-item>` element into a TriggerItem.
9
- * Attribute mapping:
10
- * - `item-id` → TriggerItem.id (required; empty string fallback)
11
- * - textContent → TriggerItem.label (primary); `label` attr as fallback
12
- * - `icon` → TriggerItem.icon
13
- * - `prompt-text` → TriggerItem.promptText
14
- * - `data` is left undefined (complex object, not representable as an attribute)
15
- *
16
- * @param n The `<kai-trigger-item>` element to parse.
17
- * @param char The trigger character this item belongs to (e.g. `/` or `@`).
18
- * @param kind The entity kind for this trigger (e.g. `'skill'` or `'mention'`).
19
- */
20
- export function parseKaiTriggerItemElement(n: Element, char: string, kind: string): TriggerItem {
21
- // char and kind inform the consumer but are not stored on TriggerItem itself.
22
- void char;
23
- void kind;
24
- return {
25
- id: n.getAttribute('item-id') ?? '',
26
- label: n.textContent?.trim() || n.getAttribute('label') || n.getAttribute('item-id') || '',
27
- icon: n.getAttribute('icon') ?? undefined,
28
- promptText: n.getAttribute('prompt-text') ?? undefined,
29
- data: undefined,
30
- };
31
- }
32
-
33
- interface Props extends Record<string, unknown> {
34
- /** Controlled value: a string or a full ComposerDoc (set as JS property). */
35
- value?: string | ComposerDoc;
36
- /** Placeholder text shown when the composer is empty. */
37
- placeholder?: string;
38
- /** Disable the composer entirely (non-interactive). */
39
- disabled?: boolean;
40
- /** Show a loading/streaming state and block submit. */
41
- loading?: boolean;
42
- /** Maximum height in px before the content scrolls. Default 240. */
43
- maxHeight?: number | string;
44
- /** Whether pressing Enter (without Shift) submits. Default true. */
45
- submitOnEnter?: boolean;
46
- /** Trigger definitions. Set as a JS property. */
47
- triggers?: TriggerDef[];
48
- /** Keyword highlight rules. Set as a JS property. */
49
- highlights?: HighlightRule[];
50
- /** Default icon per entity kind (kind → image URL/data-URI) for items without
51
- * their own `icon`. Overrides the built-in agent/plugin glyphs. JS property. */
52
- kindIcons?: Record<string, string>;
53
- }
54
-
55
- /** Events fired by `<kai-composer>`. */
56
- interface Events {
57
- /** The user submitted the composer (Enter or programmatic submit). Note the
58
- * detail carries no `attachments`; `<kai-composer>` is the bare editing
59
- * surface: no send button, toolbar, or attachments. For a drop-in composer
60
- * row with all three, reach for `<kai-prompt-input>`, which is built on this. */
61
- 'kai-submit': { doc: ComposerDoc; text: string; entities: EntityRef[] };
62
- /** The content changed (fires on every input event). */
63
- 'kai-value-change': { doc: ComposerDoc; text: string; entities: EntityRef[] };
64
- /** An entity pill was inserted into the composer. */
65
- 'kai-entity-add': { entity: EntityRef };
66
- /** An entity pill was deleted from the composer. */
67
- 'kai-entity-remove': { entity: EntityRef };
68
- /** A trigger character was detected at the caret (e.g. `/` or `@`). */
69
- 'kai-trigger': { char: string; query: string; rect: DOMRect };
70
- /** The active trigger was dismissed (Escape, space, or outside click). */
71
- 'kai-trigger-close': Record<string, never>;
72
- /** The composer gained focus. `focus`/`blur` are NOT composed natively, so they
73
- * don't escape the shadow root; these re-expose them on the host. (For
74
- * `keydown`/`paste`/`focusin`/`focusout`, listen NATIVELY on `<kai-composer>`:
75
- * they're composed and already cross the shadow boundary.) */
76
- 'kai-focus': { originalEvent: FocusEvent };
77
- /** The composer lost focus. */
78
- 'kai-blur': { originalEvent: FocusEvent };
79
- }
80
-
81
- /**
82
- * `<kai-composer>` — the bare editing surface: rich text, entity pills,
83
- * trigger menus, Enter-to-submit, and nothing else. No send button, no
84
- * toolbar, no attachments — that division is deliberate. For a drop-in chat
85
- * composer with a send button, toolbar, and attachment staging, reach for
86
- * `<kai-prompt-input>`, which is built on this element. Keep `<kai-composer>`
87
- * when you are composing the input row yourself and want to own those pieces.
88
- */
89
- defineWebComponent<Props, Events>('kai-composer', {
90
- value: undefined,
91
- placeholder: undefined,
92
- disabled: false,
93
- loading: false,
94
- maxHeight: 240,
95
- submitOnEnter: true,
96
- triggers: undefined,
97
- highlights: undefined,
98
- kindIcons: undefined,
99
- }, (props, { dispatch, flag, expose }) => {
100
- // Internal signal for uncontrolled value; when the consumer sets `value` as a
101
- // JS property the controlled path takes precedence (same pattern as prompt-input).
102
- const [internal, setInternal] = createSignal<string | ComposerDoc | undefined>(props.value);
103
-
104
- const current = () => props.value ?? internal();
105
-
106
- // ── Imperative API (instance methods on the host) ──────────────────────────
107
- // Pattern C: the Composer component owns the editable + doc state and hands up
108
- // a controller; the facade captures it and exposes delegating methods. The
109
- // composer's own callbacks still fire (clear → onChange → kai-value-change;
110
- // send → onSubmit → kai-submit; insertEntity → onEntityAdd → kai-entity-add).
111
- let controller: ComposerController | undefined;
112
- expose({
113
- /** Focus the editable element. `focus`/`blur` are NOT composed natively, so a
114
- * host-level focus() can't reach the editable inside the shadow root. This is
115
- * the only way to focus the composer programmatically. */
116
- focus: (options?: FocusOptions) => controller?.focus(options),
117
- /** Blur the editable element. */
118
- blur: () => controller?.blur(),
119
- /** Empty the composer to a blank doc (resets the internal value + history
120
- * baseline; fires kai-value-change). */
121
- clear: () => controller?.clear(),
122
- /** Submit the current content programmatically, on the same path as Enter
123
- * (fires kai-submit). Named `send`, not `submit`, to match the shared
124
- * vocabulary and avoid any submit collision. */
125
- send: () => controller?.send(),
126
- /** Insert an atomic entity pill (skill/agent/plugin) at the caret without
127
- * typing a trigger (fires kai-entity-add). */
128
- insertEntity: (entity: EntityRef) => controller?.insertEntity(entity),
129
- });
130
-
131
- const handleChange = (change: ComposerChange) => {
132
- setInternal(change.doc);
133
- dispatch('kai-value-change', { doc: change.doc, text: change.text, entities: change.entities });
134
- };
135
-
136
- const handleSubmit = (change: ComposerChange) => {
137
- dispatch('kai-submit', { doc: change.doc, text: change.text, entities: change.entities });
138
- };
139
-
140
- return (
141
- <Composer
142
- value={current()}
143
- placeholder={props.placeholder}
144
- disabled={flag('disabled')}
145
- loading={flag('loading')}
146
- maxHeight={props.maxHeight as number | string | undefined}
147
- submitOnEnter={flag('submitOnEnter')}
148
- triggers={props.triggers}
149
- highlights={props.highlights}
150
- kindIcons={props.kindIcons as Record<string, string> | undefined}
151
- onChange={handleChange}
152
- onSubmit={handleSubmit}
153
- onEntityAdd={(entity) => dispatch('kai-entity-add', { entity })}
154
- onEntityRemove={(entity) => dispatch('kai-entity-remove', { entity })}
155
- onTrigger={(info) => dispatch('kai-trigger', info)}
156
- onTriggerClose={() => dispatch('kai-trigger-close', {})}
157
- onFocus={(e) => dispatch('kai-focus', { originalEvent: e })}
158
- onBlur={(e) => dispatch('kai-blur', { originalEvent: e })}
159
- controllerRef={(c) => (controller = c)}
160
- />
161
- );
162
- });
@@ -1,76 +0,0 @@
1
- import { defineWebComponent } from './define';
2
- import { ConfirmCard, type ConfirmCardData, type ConfirmController } from '../components/confirm-card';
3
- import type { CardResolution } from '../primitives/card-contract';
4
-
5
- interface Props extends Record<string, unknown> {
6
- /** The confirm definition (the CardEnvelope.data). Set as a JS PROPERTY:
7
- * `el.data = { body, tone, actions:[…] }`. Import `ConfirmCardData` from
8
- * `@kitn.ai/ui` for the full shape. */
9
- data?: ConfirmCardData;
10
- /** Stable card id correlating every emitted CardEvent. Attribute: `card-id`. */
11
- cardId?: string;
12
- /** Heading rendered in the card chrome (= CardEnvelope.title). Attribute: `heading`. */
13
- heading?: string;
14
- /** Focus the default action on mount (off by default, so nothing steals
15
- * focus). Attribute: `autofocus`. */
16
- autofocus?: boolean;
17
- /** Set when the user resolved this card; renders the read-only view. Property:
18
- * `el.resolution = { kind:'action', action:'…' }`. */
19
- resolution?: Record<string, unknown>;
20
- }
21
-
22
- /**
23
- * `<kai-confirm>` — a named-intent **approval** card (set via the `data` property):
24
- * a title + body + a small set of action buttons. Activating an action emits the
25
- * Card contract's **`action`** verb up a bubbling **`kai-card`** CustomEvent
26
- * (`{ kind:'action', cardId, action, payload }`) and resolves the card so the same
27
- * approval can't double-fire. Also emits `ready` on mount, `dismiss` for the
28
- * optional close affordance, and `error` for a malformed definition (inline error).
29
- * Routes through a `CardProvider` when present, else the bubbling `kai-card` event.
30
- * Isolated in Shadow DOM; theme-aware via the shared kit tokens.
31
- *
32
- * Exposes instance methods `focus()`/`confirm(actionId?)`/`dismiss()`/`reopen()`
33
- * that drive the same internal paths as the buttons.
34
- */
35
- defineWebComponent<Props>(
36
- 'kai-confirm',
37
- {
38
- data: undefined,
39
- cardId: undefined,
40
- heading: undefined,
41
- autofocus: false,
42
- resolution: undefined,
43
- },
44
- (props, { element, flag, expose }) => {
45
- // Pattern C: the ConfirmCard owns the action/dismiss state and hands up a
46
- // controller; the facade captures it and exposes delegating methods. The card's
47
- // own paths still fire (confirm → kai-card `action`; dismiss/reopen → kai-card
48
- // `dismiss`/`reopen`).
49
- let controller: ConfirmController | undefined;
50
- expose({
51
- /** Focus the default action button (or the first action if none is default).
52
- * The same target `autofocus` focuses on mount, but on demand. */
53
- focus: (options?: FocusOptions) => controller?.focus(options),
54
- /** Activate an action by id: emits the `action` verb on kai-card and resolves
55
- * the card (single-shot). With no id, invokes the default action. */
56
- confirm: (actionId?: string) => controller?.confirm(actionId),
57
- /** Trigger the dismiss path: emits `dismiss` on kai-card and optimistically
58
- * collapses the card to its re-openable stub. */
59
- dismiss: () => controller?.dismiss(),
60
- /** Re-open a dismissed card from its stub: emits `reopen` on kai-card. */
61
- reopen: () => controller?.reopen(),
62
- });
63
-
64
- return (
65
- <ConfirmCard
66
- data={props.data}
67
- cardId={props.cardId ?? (element.id || 'kai-confirm')}
68
- heading={props.heading}
69
- autofocus={flag('autofocus')}
70
- resolution={props.resolution as CardResolution | undefined}
71
- controllerRef={(c) => (controller = c)}
72
- hostElement={element}
73
- />
74
- );
75
- },
76
- );
@@ -1,107 +0,0 @@
1
- import { Show, createEffect, createMemo, on } from 'solid-js';
2
- import { defineWebComponent } from './define';
3
- import {
4
- Context,
5
- ContextTrigger,
6
- ContextContent,
7
- ContextContentHeader,
8
- ContextContentBody,
9
- ContextContentFooter,
10
- ContextInputUsage,
11
- ContextOutputUsage,
12
- ContextReasoningUsage,
13
- ContextCacheUsage,
14
- computeSeverity,
15
- DEFAULT_WARN_THRESHOLD,
16
- DEFAULT_DANGER_THRESHOLD,
17
- type ContextSeverity,
18
- } from '../components/context';
19
- // Public shape of the `context` prop; lives in ./element-data-types so the ROOT
20
- // entry can re-export it (see that file's header).
21
- import type { KaiContextUsage } from './element-data-types';
22
-
23
- interface Props extends Record<string, unknown> {
24
- /** Token-usage data. Set as a JS property. */
25
- context?: KaiContextUsage;
26
- /**
27
- * Fraction (0–1) above which the meter turns yellow.
28
- * Defaults to `0.7` (70%).
29
- */
30
- warnThreshold?: number;
31
- /**
32
- * Fraction (0–1) above which the meter turns red.
33
- * Defaults to `0.9` (90%).
34
- */
35
- dangerThreshold?: number;
36
- }
37
-
38
- /** Events fired by `<kai-context>`. */
39
- interface Events {
40
- /**
41
- * Fires when the computed severity level changes (ok → warn → danger or back).
42
- * `detail.level` is `'ok'`, `'warn'`, or `'danger'`.
43
- */
44
- 'kai-threshold-change': { level: ContextSeverity };
45
- }
46
-
47
- /**
48
- * `<kai-context>` — a token/context-window usage meter with a hover-card
49
- * breakdown (input/output/reasoning/cache + estimated cost). Data via the
50
- * `context` property.
51
- *
52
- * **Color thresholds** are configurable via `warnThreshold` (default `0.7`)
53
- * and `dangerThreshold` (default `0.9`). When the computed severity level
54
- * changes, a `kai-threshold-change` event fires with `detail.level` set to
55
- * `'ok'`, `'warn'`, or `'danger'`.
56
- */
57
- defineWebComponent<Props, Events>('kai-context', {
58
- context: undefined,
59
- warnThreshold: undefined,
60
- dangerThreshold: undefined,
61
- }, (props, { dispatch }) => {
62
- const warn = () => (props.warnThreshold as number | undefined) ?? DEFAULT_WARN_THRESHOLD;
63
- const danger = () => (props.dangerThreshold as number | undefined) ?? DEFAULT_DANGER_THRESHOLD;
64
-
65
- const severity = createMemo<ContextSeverity>(() => {
66
- const ctx = props.context;
67
- if (!ctx) return 'ok';
68
- return computeSeverity(ctx.usedTokens / ctx.maxTokens, warn(), danger());
69
- });
70
-
71
- // Fire kai-threshold-change only when the level actually changes.
72
- createEffect(on(severity, (level, prev) => {
73
- if (prev !== undefined && level !== prev) {
74
- dispatch('kai-threshold-change', { level });
75
- }
76
- }));
77
-
78
- return (
79
- <Show when={props.context}>
80
- <Context
81
- usedTokens={props.context!.usedTokens}
82
- maxTokens={props.context!.maxTokens}
83
- inputTokens={props.context!.inputTokens}
84
- outputTokens={props.context!.outputTokens}
85
- reasoningTokens={props.context!.reasoningTokens}
86
- cacheTokens={props.context!.cacheTokens}
87
- estimatedCost={props.context!.estimatedCost}
88
- warnThreshold={warn()}
89
- dangerThreshold={danger()}
90
- >
91
- <ContextTrigger />
92
- <ContextContent>
93
- <ContextContentHeader />
94
- <ContextContentBody>
95
- <div class="space-y-1.5">
96
- <ContextInputUsage />
97
- <ContextOutputUsage />
98
- <Show when={props.context!.reasoningTokens}><ContextReasoningUsage /></Show>
99
- <Show when={props.context!.cacheTokens}><ContextCacheUsage /></Show>
100
- </div>
101
- </ContextContentBody>
102
- <ContextContentFooter />
103
- </ContextContent>
104
- </Context>
105
- </Show>
106
- );
107
- });
@@ -1,120 +0,0 @@
1
- import { createSignal, onCleanup, onMount } from 'solid-js';
2
- import { defineWebComponent } from './define';
3
- import { readSlots, CONVERSATION_ITEM_SLOTS } from './slots';
4
- import { SlottedConversationItem } from '../components/conversation-item';
5
- import { isStandaloneConversationItem, readConversationItemId } from '../components/conversation-list';
6
-
7
- interface Props extends Record<string, unknown> {
8
- /** The row's identity: the `conversation-id` attribute (host `id` is the
9
- * fallback). Inside `<kai-conversations>` it is handed to the container's
10
- * selection contract (`kai-conversation-select`); standalone it is the `id`
11
- * in this element's own `kai-select` detail. */
12
- conversationId?: string;
13
- /** Selected state. Reflected as `aria-current` on the row body and a
14
- * `data-active` styling hook on the row; inside a container the container
15
- * drives it from its `activeId`, standalone you set it yourself. */
16
- active?: boolean;
17
- /** Dense single-line row padding. */
18
- compact?: boolean;
19
- }
20
-
21
- interface Events {
22
- /** STANDALONE activation only: the row was activated (click, Enter or Space on its body) while the item is NOT a
23
- * direct child of `<kai-conversations>`. `id` is the row's identity: the
24
- * `conversation-id` attribute, else the host `id`. Inside a container this
25
- * never fires: activation surfaces once, as `kai-conversation-select` on the
26
- * container. */
27
- 'kai-select': { id: string };
28
- }
29
-
30
- /**
31
- * `<kai-conversation-item>` — one composed row of a consumer-owned conversation
32
- * loop. Two placements, one activation event each:
33
- *
34
- * SLOTTED into `<kai-conversations>`' light DOM (a direct child): the consumer
35
- * owns the loop (framework-native `map`, `<For>`, `v-for`); the container
36
- * detects these children, skips its data rendering, and runs the parent-item
37
- * contract over them — selection state flowing container to item, roving
38
- * tabindex, arrow-key traversal, and the accessible list/row relationship
39
- * (list rows with button bodies and `aria-current` marking the active one;
40
- * axe's nested-interactive and aria-required-children
41
- * rules are why this is not listbox/option). Activation (click, Enter, Space)
42
- * surfaces as `kai-conversation-select` on the container, and the item itself
43
- * fires nothing — no double event.
44
- *
45
- * STANDALONE (anywhere else — a hand-composed rail, or wrapped in another
46
- * element even inside a container, since the container manages only direct
47
- * children): the row activates ITSELF.
48
- * Its shadow body is a tabbable `role="button"`, and click / Enter / Space
49
- * fire `kai-select` on this element with `{ id }` — non-bubbling, like every
50
- * `kai-*` event, so listen on the item itself. What a standalone row does NOT
51
- * have is the container's LIST story: roving tabindex across rows, arrow-key
52
- * traversal, and the shared `role="list"` relationship — each standalone row
53
- * is an ordinary tab stop, and a hand-composed rail brings its own list
54
- * semantics (or slots the rows into `<kai-conversations>` and gets them for
55
- * free).
56
- *
57
- * Slots: the default slot is the title; `leading`, `meta` and `menu` are the
58
- * named regions. The `menu` slot takes your OWN popover (rename, fork, archive
59
- * live there); the element provides only the region plus focus and ARIA
60
- * plumbing, never a declarative actions prop, and a click inside it never
61
- * selects the row — in either placement.
62
- */
63
- defineWebComponent<Props, Events>('kai-conversation-item', {
64
- conversationId: undefined,
65
- active: undefined,
66
- compact: undefined,
67
- }, (props, { element, flag, reflectFlag, dispatch }) => {
68
- // Which named regions the consumer has filled; drives the conditional
69
- // wrappers so an empty region leaves no stray box behind.
70
- const [slots, setSlots] = createSignal<Record<string, boolean>>({});
71
- // Standalone vs container-managed, decided at mount (an item is not
72
- // reparented in practice; the activation handler re-checks at event time so
73
- // a row moved INTO a container can never double-fire).
74
- const [standalone, setStandalone] = createSignal(false);
75
- onMount(() => {
76
- const read = () => setSlots(readSlots(element, CONVERSATION_ITEM_SLOTS));
77
- read();
78
- const observer = new MutationObserver(read);
79
- observer.observe(element, { childList: true, attributes: true, subtree: true });
80
- onCleanup(() => observer.disconnect());
81
-
82
- // The HOST is the row LISTITEM:
83
- // it wraps the activation body AND the consumer's tabbable menu, so it must
84
- // never be the activation control itself — axe nested-interactive bans
85
- // focusable descendants of a control. The button role, aria-current and the
86
- // tabindex live on the shadow BODY (`data-kai-item-body`): inside a
87
- // container its controller stamps them; standalone the component renders
88
- // them itself. An authored role wins.
89
- if (!element.hasAttribute('role')) element.setAttribute('role', 'listitem');
90
-
91
- setStandalone(isStandaloneConversationItem(element));
92
- });
93
-
94
- // Standalone activation → the per-item `kai-select` event. The re-check at
95
- // event time keeps this dead the moment the item becomes a container's direct
96
- // child, so the container's `kai-conversation-select` stays the only event.
97
- const activate = () => {
98
- if (!isStandaloneConversationItem(element)) return;
99
- dispatch('kai-select', { id: readConversationItemId(element) });
100
- };
101
-
102
- // Property and attribute stay in agreement for `active`; the body's
103
- // aria-current follows it reactively (nothing is written to the host).
104
- reflectFlag('active');
105
-
106
- return (
107
- <SlottedConversationItem
108
- conversationId={props.conversationId as string | undefined}
109
- active={flag('active')}
110
- compact={flag('compact')}
111
- hostSemantics
112
- onActivate={standalone() ? activate : undefined}
113
- leading={slots().leading ? <slot name="leading" /> : undefined}
114
- meta={slots().meta ? <slot name="meta" /> : undefined}
115
- menu={slots().menu ? <slot name="menu" /> : undefined}
116
- >
117
- <slot />
118
- </SlottedConversationItem>
119
- );
120
- });
@@ -1,203 +0,0 @@
1
- import { createSignal, createEffect, onMount, onCleanup, Show } from 'solid-js';
2
- import { defineWebComponent } from './define';
3
- import { createControllableSignal } from '../primitives/controllable';
4
- import { readSlots, CONVERSATIONS_SLOTS } from './slots';
5
- import {
6
- ConversationList, CollapsedRail, createConversationItemsController,
7
- type ConversationListController,
8
- } from '../components/conversation-list';
9
- import type { ConversationGroup, ConversationSummary } from '../types';
10
-
11
- interface Props extends Record<string, unknown> {
12
- /** The list's section headers (`{ id, name, sortOrder, createdAt }`), rendered
13
- * in array order. A group carries no conversations of its own; it is matched
14
- * against `conversations` by id, so the two props are complementary rather
15
- * than alternatives. Omit for an ungrouped list. Set as a JS property. */
16
- groups?: ConversationGroup[];
17
- /** Every conversation the list renders, flat. Each one is filed under the group
18
- * whose `id` equals its `groupId`; one with no `groupId`, or with a `groupId`
19
- * matching no entry in `groups`, falls into a trailing "Ungrouped" section, so
20
- * nothing you pass in is ever dropped. There is no recency bucketing. Set as a
21
- * JS property. Omit to supply them as `<kai-conversation>` light-DOM children
22
- * instead, or for the empty state. A search query that matches nothing shows a
23
- * visible "No conversations match your search" state, distinct from the
24
- * zero-conversations empty state. Slotted `<kai-conversation-item>` children
25
- * switch the list into item mode instead: your own rows win and this array is
26
- * not rendered. */
27
- conversations?: ConversationSummary[];
28
- /** The id of the currently-open conversation, highlighted in the list. */
29
- activeId?: string;
30
- /** Controlled collapsed state. Set as a JS property (`el.collapsed = true`) to
31
- * drive the rail from your app, updating it in response to `kai-collapse-toggle`.
32
- * Omit for uncontrolled (the element manages it). Collapsed shrinks the rail to
33
- * a floating reopen button. */
34
- collapsed?: boolean;
35
- /** Initial collapsed state when uncontrolled (default false). Use the
36
- * `default-collapsed` attribute to start collapsed in plain HTML. */
37
- defaultCollapsed?: boolean;
38
- /** Dense single-line rows (a leading dot + title, no message count). */
39
- compact?: boolean;
40
- }
41
-
42
- interface Events {
43
- /** A conversation was selected. The selection event in BOTH modes: a
44
- * batteries data row, or an activated `<kai-conversation-item>` child
45
- * (click, Enter or Space). */
46
- 'kai-conversation-select': { id: string };
47
- /** The "New chat" button was clicked. */
48
- 'kai-new-chat': Record<string, never>;
49
- /** The sidebar toggle was clicked. */
50
- 'kai-toggle-sidebar': Record<string, never>;
51
- /** The rail was collapsed or expanded (via the toggle, the reopen button, or a
52
- * `collapse()`/`expand()`/`toggle()` call). */
53
- 'kai-collapse-toggle': { collapsed: boolean };
54
- /** The built-in search box query changed (typing, or a programmatic `clear()`
55
- * which fires it with `''`). Lets a consumer mirror or server-side the filter. */
56
- 'kai-search': { query: string };
57
- }
58
-
59
- /** Parse a single light-DOM `<kai-conversation>` element into a `ConversationSummary`.
60
- * Attribute mapping:
61
- * - `id` → ConversationSummary.id
62
- * - `group-id` → ConversationSummary.groupId (optional)
63
- * - textContent → ConversationSummary.title
64
- * Fields not expressible as HTML attributes are NOT fabricated: the
65
- * optional `scope` and `lastMessageAt` stay absent, and the required
66
- * `messageCount`/`updatedAt` get honest defaults — zero messages, and an empty
67
- * `updatedAt` from which no trailing relative time is derived (the epoch it
68
- * used to fabricate rendered a bogus "many days ago" on every declarative row).
69
- */
70
- export function parseKaiConversationElement(n: Element): ConversationSummary {
71
- return {
72
- id: n.getAttribute('id') ?? '',
73
- title: n.textContent?.trim() ?? '',
74
- groupId: n.getAttribute('group-id') ?? undefined,
75
- messageCount: 0,
76
- updatedAt: '',
77
- };
78
- }
79
-
80
- defineWebComponent<Props, Events>('kai-conversations', {
81
- groups: [],
82
- conversations: [],
83
- activeId: undefined,
84
- collapsed: undefined,
85
- defaultCollapsed: undefined,
86
- compact: undefined,
87
- }, (props, { dispatch, element, expose, flag }) => {
88
- // Read declarative <kai-conversation> children from light DOM.
89
- // Shadow DOM with no <slot> suppresses them visually — they're invisible data carriers.
90
- const [slottedConversations, setSlottedConversations] = createSignal<ConversationSummary[]>([]);
91
- // Item mode: light-DOM <kai-conversation-item> children
92
- // mean the CONSUMER owns the loop — the container skips its data rendering and
93
- // runs the parent-item contract over the hosts instead.
94
- const [itemHosts, setItemHosts] = createSignal<HTMLElement[]>([]);
95
- // Which composition slots (header/empty/footer) the consumer has filled.
96
- const [slots, setSlots] = createSignal<Record<string, boolean>>({});
97
- onMount(() => {
98
- const read = () => {
99
- const nodes = [...element.querySelectorAll('kai-conversation')];
100
- setSlottedConversations(nodes.map(parseKaiConversationElement));
101
- // Reference-stable: a fresh array every observer tick would re-run the
102
- // sync effect (whose writes the observer sees) in a feedback loop.
103
- const hosts = [...element.querySelectorAll<HTMLElement>(':scope > kai-conversation-item')];
104
- setItemHosts((prev) =>
105
- prev.length === hosts.length && hosts.every((h, i) => h === prev[i]) ? prev : hosts,
106
- );
107
- setSlots(readSlots(element, CONVERSATIONS_SLOTS));
108
- // Re-sync on EVERY mutation, not only membership changes: an item host
109
- // that upgrades after the first sync mutates its own attributes (the
110
- // facade's mount), which lands here — and its shadow body needs stamping
111
- // even though the hosts array is reference-stable. sync() writes
112
- // on-change only, so this cannot feed the observer a loop.
113
- if (hosts.length) itemsController.sync();
114
- };
115
- read();
116
- const observer = new MutationObserver(read);
117
- observer.observe(element, { childList: true, attributes: true, subtree: true });
118
- onCleanup(() => observer.disconnect());
119
- });
120
-
121
- const itemMode = () => itemHosts().length > 0;
122
-
123
- // Prop conversations take precedence; slotted children are appended after.
124
- const allConversations = () => [...(props.conversations ?? []), ...slottedConversations()];
125
-
126
- // The parent-item contract: selection flowing container→item, roving tabindex,
127
- // ARIA list-row bookkeeping — pure DOM, host-agnostic (see the controller's JSDoc in
128
- // components/conversation-list.tsx). Solid context cannot cross the element
129
- // boundary, so the channel is DOM traversal by construction.
130
- const itemsController = createConversationItemsController({
131
- getItems: itemHosts,
132
- getActiveId: () => props.activeId as string | undefined,
133
- onSelect: (id) => dispatch('kai-conversation-select', { id }),
134
- });
135
- // Re-derive the bookkeeping whenever the children change (the MutationObserver
136
- // and the shadow slot's slotchange both funnel into itemHosts) or activeId moves.
137
- createEffect(() => {
138
- if (itemMode()) itemsController.sync();
139
- });
140
-
141
- // ── Rail collapse (controlled/uncontrolled, same pattern as kai-workspace) ──
142
- // `collapsed` (when set) wins; otherwise the element manages its own state,
143
- // seeded from `defaultCollapsed`. `setCollapsedTo` always writes the internal
144
- // value (a no-op visually while controlled) and emits `kai-collapse-toggle` so
145
- // a controlling app can update its own state. Collapsed → the shared
146
- // CollapsedRail (the same floating reopen button kai-workspace renders).
147
- const [collapsed, setCollapsed] = createControllableSignal(
148
- () => props.collapsed as boolean | undefined,
149
- flag('defaultCollapsed'),
150
- );
151
- const setCollapsedTo = (next: boolean) => { setCollapsed(next); dispatch('kai-collapse-toggle', { collapsed: next }); };
152
-
153
- // ── Imperative API (instance methods on the host) ──────────────────────────
154
- // The search box's query lives inside ConversationList; we capture its
155
- // controller (Pattern C) to focus / clear it from the facade.
156
- let controller: ConversationListController | undefined;
157
- expose({
158
- /** Focus the built-in search input inside the shadow root. */
159
- focus: (options?: FocusOptions) => {
160
- // Prefer the captured controller; fall back to a shadow query (the search
161
- // box only renders when there are conversations).
162
- if (controller) controller.focus(options);
163
- else element.shadowRoot?.querySelector<HTMLInputElement>('input')?.focus(options);
164
- },
165
- /** Clear the internal search query (resets the list filter) and fire
166
- * kai-search with an empty string. */
167
- clear: () => controller?.clearSearch(),
168
- /** Programmatically select a conversation by id. The mirror of the
169
- * kai-conversation-select event (a convenience over driving `activeId`). */
170
- select: (id: string) => dispatch('kai-conversation-select', { id }),
171
- /** Collapse the rail to its floating reopen button (fires `kai-collapse-toggle`). */
172
- collapse: () => setCollapsedTo(true),
173
- /** Expand the rail back to the full list (fires `kai-collapse-toggle`). */
174
- expand: () => setCollapsedTo(false),
175
- /** Toggle the rail collapsed/expanded (fires `kai-collapse-toggle`). */
176
- toggle: () => setCollapsedTo(!collapsed()),
177
- });
178
-
179
- return (
180
- <Show
181
- when={!collapsed()}
182
- fallback={<CollapsedRail onExpand={() => setCollapsedTo(false)} />}
183
- >
184
- <ConversationList
185
- groups={props.groups ?? []}
186
- conversations={allConversations()}
187
- activeId={props.activeId}
188
- onSelect={(id) => dispatch('kai-conversation-select', { id })}
189
- onNewChat={() => dispatch('kai-new-chat')}
190
- onToggleSidebar={() => { dispatch('kai-toggle-sidebar'); setCollapsedTo(true); }}
191
- compact={flag('compact')}
192
- onSearchChange={(query) => dispatch('kai-search', { query })}
193
- controllerRef={(c) => (controller = c)}
194
- items={itemMode() ? <slot /> : undefined}
195
- itemsKeyDown={itemsController.handleKeyDown}
196
- itemsClick={itemsController.handleClick}
197
- header={slots().header ? <slot name="header" /> : undefined}
198
- footer={slots().footer ? <slot name="footer" /> : undefined}
199
- empty={slots().empty ? <slot name="empty" /> : undefined}
200
- />
201
- </Show>
202
- );
203
- });