@antelopejs/dms-ai 0.1.3 → 0.1.5

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 (245) hide show
  1. package/README.md +48 -29
  2. package/dist/channels/bridge.d.ts +2 -8
  3. package/dist/channels/bridge.js +26 -42
  4. package/dist/channels/bridge.js.map +1 -1
  5. package/dist/channels/channel-service.d.ts +2 -2
  6. package/dist/channels/channel-service.js +12 -31
  7. package/dist/channels/channel-service.js.map +1 -1
  8. package/dist/channels/registry.d.ts +2 -2
  9. package/dist/channels/registry.js +7 -7
  10. package/dist/channels/registry.js.map +1 -1
  11. package/dist/config.d.ts +1 -0
  12. package/dist/config.js +8 -1
  13. package/dist/config.js.map +1 -1
  14. package/dist/constants/channels.d.ts +5 -10
  15. package/dist/constants/channels.js +6 -10
  16. package/dist/constants/channels.js.map +1 -1
  17. package/dist/constants/sidecar.d.ts +2 -1
  18. package/dist/constants/sidecar.js +3 -2
  19. package/dist/constants/sidecar.js.map +1 -1
  20. package/dist/index.js +8 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/lifecycle/build-id.d.ts +1 -0
  23. package/dist/lifecycle/build-id.js +32 -0
  24. package/dist/lifecycle/build-id.js.map +1 -0
  25. package/dist/lifecycle/sidecar-socket.d.ts +1 -1
  26. package/dist/lifecycle/sidecar-socket.js +2 -2
  27. package/dist/lifecycle/sidecar-socket.js.map +1 -1
  28. package/dist/lifecycle/spawn-sidecar.d.ts +0 -1
  29. package/dist/lifecycle/spawn-sidecar.js +5 -27
  30. package/dist/lifecycle/spawn-sidecar.js.map +1 -1
  31. package/dist/pages/settings/page.js.map +1 -1
  32. package/dist/routes/channels.d.ts +3 -3
  33. package/dist/routes/channels.js +11 -12
  34. package/dist/routes/channels.js.map +1 -1
  35. package/dist/routes/index.d.ts +0 -1
  36. package/dist/routes/index.js +0 -1
  37. package/dist/routes/index.js.map +1 -1
  38. package/frontend-vue/.prettierignore +3 -0
  39. package/frontend-vue/.prettierrc +10 -0
  40. package/frontend-vue/app/chat/components/ChatView.vue +582 -0
  41. package/frontend-vue/app/chat/components/ComposerInput.vue +742 -0
  42. package/frontend-vue/app/chat/components/ConnectionBanner.vue +105 -0
  43. package/frontend-vue/app/chat/components/ConversationDrawer.vue +266 -0
  44. package/frontend-vue/app/chat/components/MarkdownContent.vue +196 -0
  45. package/frontend-vue/app/chat/components/MessageList.vue +474 -0
  46. package/frontend-vue/app/chat/components/PermissionRequests.vue +323 -0
  47. package/frontend-vue/app/chat/components/QuestionPrompt.vue +275 -0
  48. package/frontend-vue/app/chat/components/QueuedMessages.vue +109 -0
  49. package/frontend-vue/app/chat/components/TodoList.vue +291 -0
  50. package/frontend-vue/app/chat/components/ToolCallEntry.vue +218 -0
  51. package/frontend-vue/app/chat/components/ToolCluster.vue +282 -0
  52. package/frontend-vue/app/chat/composables/useChatChannel.ts +116 -0
  53. package/frontend-vue/app/chat/composables/useConversation.ts +838 -0
  54. package/frontend-vue/app/chat/composables/useConversationId.ts +34 -0
  55. package/frontend-vue/app/chat/composables/useConversationList.ts +56 -0
  56. package/frontend-vue/app/chat/composables/usePermissionQueue.ts +59 -0
  57. package/frontend-vue/app/chat/composables/useQuestionQueue.ts +50 -0
  58. package/frontend-vue/app/chat/composables/useRunClock.ts +28 -0
  59. package/frontend-vue/app/chat/composables/useSettings.ts +67 -0
  60. package/frontend-vue/app/chat/constants/attachments.ts +16 -0
  61. package/frontend-vue/app/chat/constants/connection-banner.ts +7 -0
  62. package/frontend-vue/app/chat/constants/conversation-drawer.ts +13 -0
  63. package/frontend-vue/app/chat/constants/conversation.ts +75 -0
  64. package/frontend-vue/app/chat/constants/permissions.ts +50 -0
  65. package/frontend-vue/app/chat/constants/protocol.ts +48 -0
  66. package/frontend-vue/app/chat/constants/run-status.ts +50 -0
  67. package/frontend-vue/app/chat/constants/settings.ts +60 -0
  68. package/frontend-vue/app/chat/types/conversation.ts +87 -0
  69. package/frontend-vue/app/chat/types/permission.ts +7 -0
  70. package/frontend-vue/app/chat/types/question.ts +17 -0
  71. package/frontend-vue/app/chat/types/settings.ts +27 -0
  72. package/frontend-vue/app/chat/utils/attachments.ts +62 -0
  73. package/frontend-vue/app/chat/utils/format.ts +14 -0
  74. package/frontend-vue/app/chat/utils/ids.ts +34 -0
  75. package/frontend-vue/app/chat/utils/markdown.ts +188 -0
  76. package/frontend-vue/app/chat/utils/run-status.ts +90 -0
  77. package/frontend-vue/app/chat/utils/todos.ts +64 -0
  78. package/frontend-vue/app/chat/utils/tool-summary.ts +53 -0
  79. package/frontend-vue/app/components/ActivityView.vue +34 -34
  80. package/frontend-vue/app/components/ChatPanel.vue +276 -0
  81. package/frontend-vue/app/components/SettingsView.vue +127 -130
  82. package/frontend-vue/app/components/SkillsView.vue +55 -53
  83. package/frontend-vue/app/plugins/ai.client.ts +145 -129
  84. package/frontend-vue/app/runtime/assistant-session.ts +21 -0
  85. package/frontend-vue/app/runtime/backoff.ts +11 -14
  86. package/frontend-vue/app/runtime/channel-client.ts +130 -141
  87. package/frontend-vue/app/runtime/chat-transport.ts +25 -55
  88. package/frontend-vue/app/runtime/constants.ts +70 -60
  89. package/frontend-vue/app/runtime/current-page.ts +49 -15
  90. package/frontend-vue/app/runtime/event-stream.ts +35 -35
  91. package/frontend-vue/app/runtime/frame-router.ts +30 -0
  92. package/frontend-vue/app/runtime/header-action.ts +18 -18
  93. package/frontend-vue/app/runtime/host-commands.ts +57 -56
  94. package/frontend-vue/app/runtime/listeners.ts +31 -0
  95. package/frontend-vue/app/runtime/navigation-complete.ts +7 -7
  96. package/frontend-vue/app/runtime/overlay-prefs.ts +36 -36
  97. package/frontend-vue/app/runtime/panel-state.ts +88 -0
  98. package/frontend-vue/app/runtime/session-gate.ts +8 -8
  99. package/frontend-vue/app/runtime/shortcuts.ts +12 -12
  100. package/frontend-vue/app/runtime/sidecar-status.ts +61 -61
  101. package/frontend-vue/app/runtime/typed-message.ts +11 -0
  102. package/frontend-vue/dms.frontend.ts +12 -12
  103. package/frontend-vue/eslint.config.mjs +13 -13
  104. package/frontend-vue/package.json +11 -4
  105. package/frontend-vue/pnpm-lock.yaml +298 -96
  106. package/frontend-vue/tests/backoff.test.ts +26 -30
  107. package/frontend-vue/tests/channel-client.test.ts +187 -188
  108. package/frontend-vue/tests/chat/markdown.test.ts +271 -0
  109. package/frontend-vue/tests/chat/useChatChannel.test.ts +124 -0
  110. package/frontend-vue/tests/chat/useConversation.test.ts +283 -0
  111. package/frontend-vue/tests/chat-panel.test.ts +354 -0
  112. package/frontend-vue/tests/chat-transport.test.ts +84 -57
  113. package/frontend-vue/tests/host-commands.test.ts +126 -87
  114. package/frontend-vue/tests/navigation.test.ts +65 -34
  115. package/frontend-vue/tests/overlay-prefs.test.ts +49 -49
  116. package/frontend-vue/tests/panel-state.test.ts +58 -0
  117. package/frontend-vue/tests/session-gate.test.ts +33 -33
  118. package/frontend-vue/tests/sidecar-guest.test.ts +46 -46
  119. package/frontend-vue/tests/sidecar-status.test.ts +29 -29
  120. package/frontend-vue/tsconfig.chat.json +16 -0
  121. package/frontend-vue/vitest.config.ts +6 -4
  122. package/package.json +5 -5
  123. package/sidecar/dist/agent/effective-mode.d.ts +2 -2
  124. package/sidecar/dist/agent/effective-mode.js +1 -1
  125. package/sidecar/dist/agent/effective-mode.js.map +1 -1
  126. package/sidecar/dist/agent/host-context.js +7 -9
  127. package/sidecar/dist/agent/host-context.js.map +1 -1
  128. package/sidecar/dist/agent/permission-bus.d.ts +1 -1
  129. package/sidecar/dist/agent/permission-bus.js +2 -2
  130. package/sidecar/dist/agent/permission-bus.js.map +1 -1
  131. package/sidecar/dist/agent/provider.d.ts +2 -2
  132. package/sidecar/dist/agent/question-bus.d.ts +1 -1
  133. package/sidecar/dist/agent/question-bus.js +2 -2
  134. package/sidecar/dist/agent/question-bus.js.map +1 -1
  135. package/sidecar/dist/agent/runner.d.ts +2 -2
  136. package/sidecar/dist/agent/runner.js +24 -8
  137. package/sidecar/dist/agent/runner.js.map +1 -1
  138. package/sidecar/dist/agent/session.d.ts +2 -2
  139. package/sidecar/dist/agent/session.js +49 -9
  140. package/sidecar/dist/agent/session.js.map +1 -1
  141. package/sidecar/dist/agent/switching-runner.js +10 -5
  142. package/sidecar/dist/agent/switching-runner.js.map +1 -1
  143. package/sidecar/dist/agent/turn-end-reasons.d.ts +2 -0
  144. package/sidecar/dist/agent/turn-end-reasons.js +6 -1
  145. package/sidecar/dist/agent/turn-end-reasons.js.map +1 -1
  146. package/sidecar/dist/constants/agent.d.ts +4 -1
  147. package/sidecar/dist/constants/agent.js +4 -1
  148. package/sidecar/dist/constants/agent.js.map +1 -1
  149. package/sidecar/dist/constants/cli.d.ts +0 -1
  150. package/sidecar/dist/constants/cli.js +0 -1
  151. package/sidecar/dist/constants/cli.js.map +1 -1
  152. package/sidecar/dist/constants/codex.d.ts +5 -2
  153. package/sidecar/dist/constants/codex.js +5 -2
  154. package/sidecar/dist/constants/codex.js.map +1 -1
  155. package/sidecar/dist/constants/http.d.ts +0 -9
  156. package/sidecar/dist/constants/http.js +0 -19
  157. package/sidecar/dist/constants/http.js.map +1 -1
  158. package/sidecar/dist/constants/mcp.d.ts +1 -1
  159. package/sidecar/dist/constants/mcp.js +1 -1
  160. package/sidecar/dist/constants/mcp.js.map +1 -1
  161. package/sidecar/dist/constants/paths.d.ts +0 -1
  162. package/sidecar/dist/constants/paths.js +0 -1
  163. package/sidecar/dist/constants/paths.js.map +1 -1
  164. package/sidecar/dist/constants/ws.d.ts +3 -4
  165. package/sidecar/dist/constants/ws.js +3 -4
  166. package/sidecar/dist/constants/ws.js.map +1 -1
  167. package/sidecar/dist/index.d.ts +0 -1
  168. package/sidecar/dist/index.js +6 -10
  169. package/sidecar/dist/index.js.map +1 -1
  170. package/sidecar/dist/mcp/tools/find-pages-using.js +5 -10
  171. package/sidecar/dist/mcp/tools/find-pages-using.js.map +1 -1
  172. package/sidecar/dist/mcp/types.d.ts +1 -1
  173. package/sidecar/dist/pages/page-filepath.d.ts +4 -0
  174. package/sidecar/dist/pages/page-filepath.js +28 -0
  175. package/sidecar/dist/pages/page-filepath.js.map +1 -0
  176. package/sidecar/dist/prompts/agent.d.ts +1 -1
  177. package/sidecar/dist/prompts/agent.js +1 -1
  178. package/sidecar/dist/prompts/agent.js.map +1 -1
  179. package/sidecar/dist/protocol/events.js +2 -2
  180. package/sidecar/dist/protocol/events.js.map +1 -1
  181. package/sidecar/dist/protocol/messages.d.ts +4 -15
  182. package/sidecar/dist/protocol/messages.js +4 -11
  183. package/sidecar/dist/protocol/messages.js.map +1 -1
  184. package/sidecar/dist/providers/claude/config.d.ts +2 -2
  185. package/sidecar/dist/providers/claude/config.js +2 -2
  186. package/sidecar/dist/providers/claude/config.js.map +1 -1
  187. package/sidecar/dist/providers/claude/provider.js +1 -1
  188. package/sidecar/dist/providers/claude/provider.js.map +1 -1
  189. package/sidecar/dist/providers/codex/config.d.ts +3 -2
  190. package/sidecar/dist/providers/codex/config.js +3 -3
  191. package/sidecar/dist/providers/codex/config.js.map +1 -1
  192. package/sidecar/dist/providers/codex/process.js +107 -74
  193. package/sidecar/dist/providers/codex/process.js.map +1 -1
  194. package/sidecar/dist/providers/codex/provider.js +68 -31
  195. package/sidecar/dist/providers/codex/provider.js.map +1 -1
  196. package/sidecar/dist/providers/codex/skills.d.ts +1 -0
  197. package/sidecar/dist/providers/codex/skills.js +4 -1
  198. package/sidecar/dist/providers/codex/skills.js.map +1 -1
  199. package/sidecar/dist/providers/codex/stop.d.ts +4 -0
  200. package/sidecar/dist/providers/codex/stop.js +71 -0
  201. package/sidecar/dist/providers/codex/stop.js.map +1 -0
  202. package/sidecar/dist/server/{iframe-socket-registry.d.ts → chat-socket-registry.d.ts} +3 -2
  203. package/sidecar/dist/server/{iframe-socket-registry.js → chat-socket-registry.js} +4 -3
  204. package/sidecar/dist/server/chat-socket-registry.js.map +1 -0
  205. package/sidecar/dist/server/client-auth.js +2 -14
  206. package/sidecar/dist/server/client-auth.js.map +1 -1
  207. package/sidecar/dist/server/host-command-router.d.ts +5 -0
  208. package/sidecar/dist/server/host-command-router.js +4 -0
  209. package/sidecar/dist/server/host-command-router.js.map +1 -0
  210. package/sidecar/dist/server/host-socket-registry.d.ts +1 -1
  211. package/sidecar/dist/server/host-socket-registry.js +16 -13
  212. package/sidecar/dist/server/host-socket-registry.js.map +1 -1
  213. package/sidecar/dist/server/http.d.ts +0 -1
  214. package/sidecar/dist/server/http.js +1 -44
  215. package/sidecar/dist/server/http.js.map +1 -1
  216. package/sidecar/dist/server/routing.d.ts +5 -6
  217. package/sidecar/dist/server/routing.js +18 -28
  218. package/sidecar/dist/server/routing.js.map +1 -1
  219. package/sidecar/dist/server/ws.d.ts +2 -2
  220. package/sidecar/dist/server/ws.js +41 -39
  221. package/sidecar/dist/server/ws.js.map +1 -1
  222. package/sidecar/dist/state/host-state.d.ts +10 -2
  223. package/sidecar/dist/state/host-state.js +13 -3
  224. package/sidecar/dist/state/host-state.js.map +1 -1
  225. package/sidecar/dist/state/settings-store.js +2 -2
  226. package/sidecar/dist/state/settings-store.js.map +1 -1
  227. package/sidecar/dist/state/settings-types.d.ts +3 -3
  228. package/sidecar/dist/state/settings-types.js +1 -1
  229. package/sidecar/dist/state/settings-types.js.map +1 -1
  230. package/sidecar/package.json +3 -5
  231. package/dist/chatbox/passthrough.d.ts +0 -3
  232. package/dist/chatbox/passthrough.js +0 -53
  233. package/dist/chatbox/passthrough.js.map +0 -1
  234. package/dist/constants/chatbox.d.ts +0 -10
  235. package/dist/constants/chatbox.js +0 -35
  236. package/dist/constants/chatbox.js.map +0 -1
  237. package/dist/routes/chatbox.d.ts +0 -7
  238. package/dist/routes/chatbox.js +0 -47
  239. package/dist/routes/chatbox.js.map +0 -1
  240. package/frontend-vue/app/runtime/overlay.ts +0 -400
  241. package/frontend-vue/app/runtime/theme-bridge.ts +0 -189
  242. package/sidecar/chatbox/dist/assets/index-C8u7mkHn.css +0 -1
  243. package/sidecar/chatbox/dist/assets/index-tdZvY7ee.js +0 -52
  244. package/sidecar/chatbox/dist/index.html +0 -13
  245. package/sidecar/dist/server/iframe-socket-registry.js.map +0 -1
@@ -0,0 +1,282 @@
1
+ <script setup lang="ts">
2
+ import { computed, onUnmounted, ref, watch } from "vue";
3
+ import {
4
+ TOOL_CLUSTER_COLLAPSE_LINGER_MS,
5
+ TOOL_CLUSTER_LABEL,
6
+ TOOL_CLUSTER_VISIBLE_LIMIT,
7
+ TOOL_STATUS,
8
+ } from "../constants/conversation";
9
+ import type { ToolCallMessage, ToolStatus } from "../types/conversation";
10
+ import { toolSummary } from "../utils/tool-summary";
11
+ import ToolCallEntry from "./ToolCallEntry.vue";
12
+
13
+ interface Props {
14
+ tools: ToolCallMessage[];
15
+ /** True while this is the trailing tool activity of a running turn. */
16
+ live: boolean;
17
+ }
18
+
19
+ const props = defineProps<Props>();
20
+
21
+ const override = ref<boolean | null>(null);
22
+ const showAll = ref(false);
23
+
24
+ const lingering = ref(false);
25
+ let lingerTimer: ReturnType<typeof setTimeout> | null = null;
26
+
27
+ watch(
28
+ () => props.live,
29
+ (isLive, wasLive) => {
30
+ if (isLive) {
31
+ lingering.value = false;
32
+ if (lingerTimer !== null) clearTimeout(lingerTimer);
33
+ lingerTimer = null;
34
+ return;
35
+ }
36
+ if (!wasLive) return;
37
+ lingering.value = true;
38
+ if (lingerTimer !== null) clearTimeout(lingerTimer);
39
+ lingerTimer = setTimeout(() => {
40
+ lingering.value = false;
41
+ lingerTimer = null;
42
+ }, TOOL_CLUSTER_COLLAPSE_LINGER_MS);
43
+ },
44
+ );
45
+
46
+ onUnmounted(() => {
47
+ if (lingerTimer !== null) clearTimeout(lingerTimer);
48
+ });
49
+
50
+ const rollupStatus = computed<ToolStatus>(() => {
51
+ if (props.tools.some((t) => t.status === TOOL_STATUS.PENDING)) {
52
+ return TOOL_STATUS.PENDING;
53
+ }
54
+ if (props.tools.some((t) => t.status === TOOL_STATUS.ERROR)) {
55
+ return TOOL_STATUS.ERROR;
56
+ }
57
+ return TOOL_STATUS.SUCCESS;
58
+ });
59
+
60
+ const hasError = computed<boolean>(() =>
61
+ props.tools.some((t) => t.status === TOOL_STATUS.ERROR),
62
+ );
63
+
64
+ const autoOpen = computed<boolean>(
65
+ () => props.live || lingering.value || hasError.value,
66
+ );
67
+ const isOpen = computed<boolean>(() =>
68
+ override.value !== null ? override.value : autoOpen.value,
69
+ );
70
+ const isFull = computed<boolean>(
71
+ () => override.value === true || showAll.value,
72
+ );
73
+
74
+ const visibleTools = computed<ToolCallMessage[]>(() =>
75
+ isFull.value ? props.tools : props.tools.slice(-TOOL_CLUSTER_VISIBLE_LIMIT),
76
+ );
77
+ const hiddenCount = computed<number>(
78
+ () => props.tools.length - visibleTools.value.length,
79
+ );
80
+
81
+ const glyphStatus = computed<ToolStatus>(() =>
82
+ props.live ? TOOL_STATUS.PENDING : rollupStatus.value,
83
+ );
84
+
85
+ const headline = computed<string>(() => {
86
+ const active =
87
+ props.tools.find((t) => t.status === TOOL_STATUS.PENDING) ??
88
+ props.tools.at(-1);
89
+ if (active === undefined) return "";
90
+ return toolSummary(active.toolName, active.args);
91
+ });
92
+
93
+ const countLabel = computed<string>(
94
+ () => `${TOOL_CLUSTER_LABEL} ${props.tools.length} tools`,
95
+ );
96
+
97
+ function toggle(): void {
98
+ override.value = !isOpen.value;
99
+ }
100
+
101
+ function revealEarlier(): void {
102
+ showAll.value = true;
103
+ }
104
+ </script>
105
+
106
+ <template>
107
+ <section class="tool-cluster" :data-status="rollupStatus">
108
+ <button
109
+ type="button"
110
+ class="cluster-header"
111
+ :aria-expanded="isOpen"
112
+ @click="toggle"
113
+ >
114
+ <span class="cluster-toggle">{{ isOpen ? "▾" : "▸" }}</span>
115
+ <span class="cluster-glyph" :data-status="glyphStatus" aria-hidden="true">
116
+ <svg
117
+ v-if="glyphStatus === 'pending'"
118
+ class="cluster-spin"
119
+ viewBox="0 0 24 24"
120
+ width="13"
121
+ height="13"
122
+ fill="none"
123
+ stroke="currentColor"
124
+ stroke-width="2.5"
125
+ stroke-linecap="round"
126
+ >
127
+ <path d="M21 12a9 9 0 1 1-6.2-8.6" />
128
+ </svg>
129
+ <svg
130
+ v-else-if="glyphStatus === 'error'"
131
+ viewBox="0 0 24 24"
132
+ width="13"
133
+ height="13"
134
+ fill="none"
135
+ stroke="currentColor"
136
+ stroke-width="2.5"
137
+ stroke-linecap="round"
138
+ stroke-linejoin="round"
139
+ >
140
+ <path d="M18 6 6 18M6 6l12 12" />
141
+ </svg>
142
+ <svg
143
+ v-else
144
+ viewBox="0 0 24 24"
145
+ width="13"
146
+ height="13"
147
+ fill="none"
148
+ stroke="currentColor"
149
+ stroke-width="2.5"
150
+ stroke-linecap="round"
151
+ stroke-linejoin="round"
152
+ >
153
+ <path d="M20 6 9 17l-5-5" />
154
+ </svg>
155
+ </span>
156
+ <span class="cluster-count">{{ countLabel }}</span>
157
+ <span v-if="!isOpen && headline.length > 0" class="cluster-headline">
158
+ {{ headline }}
159
+ </span>
160
+ </button>
161
+ <div v-if="isOpen" class="cluster-body">
162
+ <button
163
+ v-if="hiddenCount > 0"
164
+ type="button"
165
+ class="cluster-earlier"
166
+ @click="revealEarlier"
167
+ >
168
+ ▴ {{ hiddenCount }} earlier
169
+ </button>
170
+ <ToolCallEntry
171
+ v-for="tool in visibleTools"
172
+ :key="tool.id"
173
+ :message="tool"
174
+ />
175
+ </div>
176
+ </section>
177
+ </template>
178
+
179
+ <style scoped>
180
+ .tool-cluster {
181
+ border: 1px solid var(--hair);
182
+ border-radius: var(--corner-md);
183
+ background: var(--surface-card);
184
+ overflow: hidden;
185
+ }
186
+
187
+ .cluster-header {
188
+ display: flex;
189
+ align-items: center;
190
+ gap: 8px;
191
+ width: 100%;
192
+ padding: 8px 10px;
193
+ background: transparent;
194
+ border: none;
195
+ cursor: pointer;
196
+ font: inherit;
197
+ text-align: left;
198
+ color: var(--fg);
199
+ }
200
+
201
+ .cluster-header:hover {
202
+ background: var(--surface-card-2);
203
+ }
204
+
205
+ .cluster-toggle {
206
+ color: var(--fg-tertiary);
207
+ font-size: 11px;
208
+ flex: 0 0 auto;
209
+ }
210
+
211
+ .cluster-glyph {
212
+ width: 20px;
213
+ height: 20px;
214
+ flex: 0 0 auto;
215
+ display: grid;
216
+ place-items: center;
217
+ border-radius: 6px;
218
+ }
219
+
220
+ .cluster-glyph[data-status="pending"] {
221
+ color: var(--warning-400);
222
+ }
223
+
224
+ .cluster-glyph[data-status="success"] {
225
+ color: var(--success-400);
226
+ }
227
+
228
+ .cluster-glyph[data-status="error"] {
229
+ color: var(--danger-400);
230
+ }
231
+
232
+ .cluster-spin {
233
+ animation: cluster-spin 0.9s linear infinite;
234
+ }
235
+
236
+ @keyframes cluster-spin {
237
+ to {
238
+ transform: rotate(360deg);
239
+ }
240
+ }
241
+
242
+ .cluster-count {
243
+ font-weight: 600;
244
+ font-size: 12.5px;
245
+ flex: 0 0 auto;
246
+ }
247
+
248
+ .cluster-headline {
249
+ font-family: var(--font-code);
250
+ font-size: 11px;
251
+ color: var(--fg-tertiary);
252
+ white-space: nowrap;
253
+ overflow: hidden;
254
+ text-overflow: ellipsis;
255
+ min-width: 0;
256
+ flex: 1;
257
+ }
258
+
259
+ .cluster-body {
260
+ display: flex;
261
+ flex-direction: column;
262
+ gap: 6px;
263
+ padding: 6px;
264
+ border-top: 1px solid var(--hair);
265
+ background: var(--surface-inset);
266
+ }
267
+
268
+ .cluster-earlier {
269
+ align-self: flex-start;
270
+ background: none;
271
+ border: none;
272
+ padding: 2px 2px 0;
273
+ font: inherit;
274
+ font-size: 11px;
275
+ color: var(--fg-tertiary);
276
+ cursor: pointer;
277
+ }
278
+
279
+ .cluster-earlier:hover {
280
+ color: var(--accent);
281
+ }
282
+ </style>
@@ -0,0 +1,116 @@
1
+ import { onBeforeUnmount, onMounted, type Ref, ref } from "vue";
2
+ import type { ChatTransport } from "../../runtime/chat-transport";
3
+ import { createListeners } from "../../runtime/listeners";
4
+ import {
5
+ CHAT_ROLE,
6
+ CLIENT_MESSAGE_TYPES,
7
+ CONNECTION_STATUSES,
8
+ type ConnectionStatus,
9
+ } from "../constants/protocol";
10
+
11
+ export interface UseChatChannelOptions {
12
+ transport: ChatTransport;
13
+ getConversationId: () => string;
14
+ }
15
+
16
+ export type ChannelMessageHandler = (msg: unknown) => void;
17
+
18
+ export interface UseChatChannelResult {
19
+ /** False when the message was dropped: the stream is not connected. */
20
+ send: (msg: object) => boolean;
21
+ onMessage: (handler: ChannelMessageHandler) => () => void;
22
+ reconnect: () => void;
23
+ reidentify: () => void;
24
+ isConnected: Ref<boolean>;
25
+ connectionStatus: Ref<ConnectionStatus>;
26
+ }
27
+
28
+ interface ChannelState {
29
+ options: UseChatChannelOptions;
30
+ dispatch: ChannelMessageHandler;
31
+ isConnected: Ref<boolean>;
32
+ connectionStatus: Ref<ConnectionStatus>;
33
+ isAttached: boolean;
34
+ detachers: Array<() => void>;
35
+ }
36
+
37
+ const KNOWN_STATUSES = new Set<string>(Object.values(CONNECTION_STATUSES));
38
+
39
+ function setStatus(state: ChannelState, status: string): void {
40
+ if (!KNOWN_STATUSES.has(status)) return;
41
+ state.connectionStatus.value = status as ConnectionStatus;
42
+ state.isConnected.value = status === CONNECTION_STATUSES.CONNECTED;
43
+ }
44
+
45
+ function sendHello(state: ChannelState): void {
46
+ state.options.transport.send({
47
+ type: CLIENT_MESSAGE_TYPES.HELLO,
48
+ role: CHAT_ROLE,
49
+ conversationId: state.options.getConversationId(),
50
+ });
51
+ }
52
+
53
+ function attach(state: ChannelState): void {
54
+ const { transport } = state.options;
55
+ state.isAttached = true;
56
+ state.detachers = [
57
+ transport.onMessage(state.dispatch),
58
+ transport.onReady(() => sendHello(state)),
59
+ transport.onStatus((status) => setStatus(state, status)),
60
+ ];
61
+ setStatus(state, transport.getStatus());
62
+ if (state.isConnected.value) sendHello(state);
63
+ }
64
+
65
+ function detach(state: ChannelState): void {
66
+ state.isAttached = false;
67
+ for (const stop of state.detachers) stop();
68
+ state.detachers = [];
69
+ }
70
+
71
+ export interface ChatChannel {
72
+ result: UseChatChannelResult;
73
+ /** Listens to the dashboard's stream and says hello once it is connected. */
74
+ start: () => void;
75
+ /** Stops listening: no message reaches the chat after this. */
76
+ stop: () => void;
77
+ }
78
+
79
+ /** The chat's channel without the component lifecycle, which `useChatChannel` adds. */
80
+ export function createChatChannel(options: UseChatChannelOptions): ChatChannel {
81
+ const subscribers = createListeners<unknown>();
82
+ const state: ChannelState = {
83
+ options,
84
+ dispatch: subscribers.emit,
85
+ isConnected: ref(false),
86
+ connectionStatus: ref<ConnectionStatus>(CONNECTION_STATUSES.CONNECTING),
87
+ isAttached: false,
88
+ detachers: [],
89
+ };
90
+ return {
91
+ result: {
92
+ send: (msg) => state.isAttached && options.transport.send(msg),
93
+ onMessage: subscribers.add,
94
+ reconnect: () => options.transport.reconnect(),
95
+ reidentify: () => sendHello(state),
96
+ isConnected: state.isConnected,
97
+ connectionStatus: state.connectionStatus,
98
+ },
99
+ start: () => attach(state),
100
+ stop: () => detach(state),
101
+ };
102
+ }
103
+
104
+ /**
105
+ * The chat's channel to the sidecar: its side of the dashboard's one stream per
106
+ * tab. A `hello` with the conversation goes out on every (re)connection, and
107
+ * the chat stops listening when it unmounts.
108
+ */
109
+ export function useChatChannel(
110
+ options: UseChatChannelOptions,
111
+ ): UseChatChannelResult {
112
+ const channel = createChatChannel(options);
113
+ onMounted(channel.start);
114
+ onBeforeUnmount(channel.stop);
115
+ return channel.result;
116
+ }