@marimo-team/islands 0.23.17-dev32 → 0.23.17-dev34

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 (52) hide show
  1. package/dist/{ConnectedDataExplorerComponent-BEb8RZam.js → ConnectedDataExplorerComponent-emE_tsrt.js} +11 -11
  2. package/dist/{ErrorBoundary-8ZHte0h9.js → ErrorBoundary-o6wEnSCc.js} +2 -2
  3. package/dist/{any-language-editor-CioNaP-T.js → any-language-editor-Cls8lx9d.js} +4 -4
  4. package/dist/chat-ui-1-XgwfDv.js +8620 -0
  5. package/dist/{check-CCvJTB2E.js → check-D-BaEjEh.js} +1 -1
  6. package/dist/{common-XU-hyhVj.js → common-Czr-rNF3.js} +18 -18
  7. package/dist/{copy-D45ZUY3j.js → copy-BkA3t7rJ.js} +1 -1
  8. package/dist/{dist-DgzzIPS4.js → dist-DarwE0ZO.js} +10 -10
  9. package/dist/{error-banner-DHfPl1w3.js → error-banner-dmkbm21G.js} +1 -1
  10. package/dist/{esm-DJsE6wi-.js → esm-CfyRntAe.js} +1 -1
  11. package/dist/{extends-xQ_2Cylt.js → extends-DzpiytFg.js} +3 -3
  12. package/dist/{formats-D10vOEsT.js → formats-DcO6TofP.js} +1 -1
  13. package/dist/{glide-data-editor-FiwJJzrV.js → glide-data-editor-C99Bp4Hk.js} +8 -8
  14. package/dist/{html-to-image-Bgb6aaXi.js → html-to-image-CgznkzKG.js} +13 -13
  15. package/dist/{input-DtTqU0xh.js → input-CwPuFkJt.js} +5 -5
  16. package/dist/{label-5IC840tS.js → label-CzHncDvS.js} +1 -1
  17. package/dist/main.js +29 -29
  18. package/dist/{mermaid-BNhC-PrB.js → mermaid-Sy0p3RJY.js} +4 -4
  19. package/dist/{process-output-D2Oxf11p.js → process-output-DUNqOGZS.js} +3 -3
  20. package/dist/{reveal-component-DEpX3cZP.js → reveal-component-CZ2AHfVt.js} +9 -9
  21. package/dist/{spec-C7rMyZ_8.js → spec-Be9MhFWh.js} +4 -4
  22. package/dist/{strings-CITcoFNY.js → strings-BUDhKc0s.js} +298 -298
  23. package/dist/{toDate-kxcuDOWd.js → toDate-eW__SzBR.js} +2 -2
  24. package/dist/{tooltip-BkSv4x8S.js → tooltip-CkCWlUOf.js} +2 -2
  25. package/dist/{types-kNUyqkDD.js → types-uENjXsiC.js} +1 -1
  26. package/dist/{useAsyncData-Uo4VFafD.js → useAsyncData-B8UxSH4O.js} +1 -1
  27. package/dist/{useDateFormatter-ZCfHadYP.js → useDateFormatter-BeN3fHMH.js} +2 -2
  28. package/dist/{useDeepCompareMemoize-s3ZvmdK3.js → useDeepCompareMemoize-BnhKck7C.js} +1 -1
  29. package/dist/{useLifecycle-CLPBATCv.js → useLifecycle-B7J7yvFt.js} +2 -2
  30. package/dist/{useTheme-CEMsu1Js.js → useTheme-BUY7pfI9.js} +1 -1
  31. package/dist/{vega-component-DGkcoXu3.js → vega-component-BOeMnvAb.js} +8 -8
  32. package/dist/{zod-DdNi9290.js → zod-yTHHzJiv.js} +36 -37
  33. package/package.json +3 -3
  34. package/src/components/chat/__tests__/chat-abort.test.ts +51 -0
  35. package/src/components/chat/chat-abort.ts +44 -0
  36. package/src/components/chat/chat-display.tsx +17 -0
  37. package/src/components/chat/chat-panel.tsx +85 -37
  38. package/src/components/chat/chat-utils.ts +1 -1
  39. package/src/components/editor/actions/export-dialog/export-command.ts +4 -9
  40. package/src/components/editor/ai/add-cell-with-ai.tsx +2 -2
  41. package/src/components/editor/ai/ai-completion-editor.tsx +2 -2
  42. package/src/core/ai/constants.ts +7 -0
  43. package/src/core/ai/staged-cells.ts +3 -0
  44. package/src/core/network/__tests__/api.test.ts +132 -17
  45. package/src/core/network/__tests__/export-filename.test.ts +43 -0
  46. package/src/core/network/api.ts +47 -12
  47. package/src/core/network/export-filename.ts +37 -0
  48. package/src/core/network/markdown-export.ts +19 -0
  49. package/src/core/network/requests-network.ts +29 -5
  50. package/src/core/network/types.ts +3 -0
  51. package/src/plugins/impl/chat/chat-ui.tsx +51 -3
  52. package/dist/chat-ui-Cjd9kIcO.js +0 -8369
@@ -27,6 +27,7 @@ import { Label } from "@/components/ui/label";
27
27
  import { Switch } from "@/components/ui/switch";
28
28
  import { Tooltip } from "@/components/ui/tooltip";
29
29
  import { toast } from "@/components/ui/use-toast";
30
+ import { AI_SDK_UI_THROTTLE_MS } from "@/core/ai/constants";
30
31
  import { stripWrappingBackticks } from "@/core/ai/strip-wrapping-backticks";
31
32
  import { type AiCompletionCell, includeOtherCellsAtom } from "@/core/ai/state";
32
33
  import type { CellId } from "@/core/cells/ids";
@@ -124,8 +125,7 @@ export const AiCompletionEditor: React.FC<Props> = ({
124
125
  api: runtimeManager.getAiURL("completion").toString(),
125
126
  headers: runtimeManager.headers(),
126
127
  initialInput: initialPrompt,
127
- // Throttle the messages and data updates to 100ms
128
- experimental_throttle: 100,
128
+ throttle: AI_SDK_UI_THROTTLE_MS,
129
129
  body: {
130
130
  ...(Object.keys(completionBody).length > 0
131
131
  ? completionBody
@@ -0,0 +1,7 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ /**
4
+ * Throttle wait (ms) for AI SDK React hooks (`useChat` / `useCompletion`).
5
+ * Limits UI re-renders while streaming tokens.
6
+ */
7
+ export const AI_SDK_UI_THROTTLE_MS = 100;
@@ -176,14 +176,17 @@ export function useStagedCells(store: JotaiStore) {
176
176
  case "message-metadata":
177
177
  case "tool-input-available":
178
178
  case "tool-output-available":
179
+ case "tool-approval-response":
179
180
  case "reasoning-start":
180
181
  case "reasoning-delta":
181
182
  case "reasoning-end":
182
183
  case "file":
184
+ case "reasoning-file":
183
185
  case "source-document":
184
186
  case "source-url":
185
187
  case "tool-input-start":
186
188
  case "tool-input-delta":
189
+ case "custom":
187
190
  Logger.debug(chunk.type, { chunk });
188
191
  break;
189
192
  default:
@@ -105,7 +105,10 @@ describe("API", () => {
105
105
  });
106
106
 
107
107
  await expect(
108
- API.handleExportResponse({ data: "markdown", response }),
108
+ API.handleExportResponse(
109
+ { data: "markdown", response },
110
+ { defaultFilename: "download.md" },
111
+ ),
109
112
  ).resolves.toEqual({
110
113
  contents: "markdown",
111
114
  filename: "résumé.qmd",
@@ -113,27 +116,139 @@ describe("API", () => {
113
116
  });
114
117
  });
115
118
 
116
- it("rejects export responses without a filename", async () => {
119
+ it("parses quoted Content-Disposition filenames", async () => {
120
+ const response = new Response("html", {
121
+ headers: {
122
+ "Content-Disposition": 'inline; filename="notebook.html"',
123
+ "Content-Type": "text/html; charset=utf-8",
124
+ },
125
+ });
126
+
117
127
  await expect(
118
- API.handleExportResponse({
119
- data: "markdown",
120
- response: new Response(null, {
121
- headers: { "Content-Type": "text/plain" },
122
- }),
123
- }),
124
- ).rejects.toThrow("Export response is missing a filename");
128
+ API.handleExportResponse(
129
+ { data: "html", response },
130
+ { defaultFilename: "download.html" },
131
+ ),
132
+ ).resolves.toEqual({
133
+ contents: "html",
134
+ filename: "notebook.html",
135
+ mediaType: "text/html; charset=utf-8",
136
+ });
137
+ });
138
+
139
+ it("parses unquoted Content-Disposition filenames", async () => {
140
+ const response = new Response("pdf", {
141
+ headers: {
142
+ "Content-Disposition": "attachment; filename=notebook.pdf",
143
+ "Content-Type": "application/pdf",
144
+ },
145
+ });
146
+
147
+ await expect(
148
+ API.handleExportResponse(
149
+ { data: "pdf", response },
150
+ { defaultFilename: "download.pdf" },
151
+ ),
152
+ ).resolves.toEqual({
153
+ contents: "pdf",
154
+ filename: "notebook.pdf",
155
+ mediaType: "application/pdf",
156
+ });
157
+ });
158
+
159
+ it("prefers RFC 5987 filenames over quoted fallbacks", async () => {
160
+ const response = new Response("markdown", {
161
+ headers: {
162
+ "Content-Disposition":
163
+ "attachment; filename=\"wrong.md\"; filename*=UTF-8''notebook.md",
164
+ "Content-Type": "text/plain; charset=utf-8",
165
+ },
166
+ });
167
+
168
+ await expect(
169
+ API.handleExportResponse(
170
+ { data: "markdown", response },
171
+ { defaultFilename: "download.md" },
172
+ ),
173
+ ).resolves.toEqual({
174
+ contents: "markdown",
175
+ filename: "notebook.md",
176
+ mediaType: "text/plain; charset=utf-8",
177
+ });
178
+ });
179
+
180
+ it("falls back to a default filename when headers are missing", async () => {
181
+ const response = new Response("markdown", {
182
+ headers: {
183
+ "Content-Type": "text/plain; charset=utf-8",
184
+ },
185
+ });
186
+
187
+ await expect(
188
+ API.handleExportResponse(
189
+ { data: "markdown", response },
190
+ { defaultFilename: "download.md" },
191
+ ),
192
+ ).resolves.toEqual({
193
+ contents: "markdown",
194
+ filename: "download.md",
195
+ mediaType: "text/plain; charset=utf-8",
196
+ });
197
+ });
198
+
199
+ it("falls back to a default filename when Content-Disposition is unparsable", async () => {
200
+ const response = new Response("markdown", {
201
+ headers: {
202
+ "Content-Disposition": "attachment",
203
+ "Content-Type": "text/plain; charset=utf-8",
204
+ },
205
+ });
206
+
207
+ await expect(
208
+ API.handleExportResponse(
209
+ { data: "markdown", response },
210
+ { defaultFilename: "download.md" },
211
+ ),
212
+ ).resolves.toEqual({
213
+ contents: "markdown",
214
+ filename: "download.md",
215
+ mediaType: "text/plain; charset=utf-8",
216
+ });
217
+ });
218
+
219
+ it("falls back to a default filename when RFC 5987 encoding is malformed", async () => {
220
+ const response = new Response("markdown", {
221
+ headers: {
222
+ "Content-Disposition": "attachment; filename*=UTF-8''%E0%A4%A",
223
+ "Content-Type": "text/plain; charset=utf-8",
224
+ },
225
+ });
226
+
227
+ await expect(
228
+ API.handleExportResponse(
229
+ { data: "markdown", response },
230
+ { defaultFilename: "download.md" },
231
+ ),
232
+ ).resolves.toEqual({
233
+ contents: "markdown",
234
+ filename: "download.md",
235
+ mediaType: "text/plain; charset=utf-8",
236
+ });
125
237
  });
126
238
 
127
239
  it("rejects export responses without a media type", async () => {
128
240
  await expect(
129
- API.handleExportResponse({
130
- data: "markdown",
131
- response: new Response(null, {
132
- headers: {
133
- "Content-Disposition": "attachment; filename*=UTF-8''notebook.md",
134
- },
135
- }),
136
- }),
241
+ API.handleExportResponse(
242
+ {
243
+ data: "markdown",
244
+ response: new Response(null, {
245
+ headers: {
246
+ "Content-Disposition": "attachment; filename*=UTF-8''notebook.md",
247
+ },
248
+ }),
249
+ },
250
+ { defaultFilename: "download.md" },
251
+ ),
137
252
  ).rejects.toThrow("Export response is missing a media type");
138
253
  });
139
254
  });
@@ -0,0 +1,43 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { beforeEach, describe, expect, it } from "vitest";
4
+ import { filenameAtom } from "@/core/saving/file-state";
5
+ import { store } from "@/core/state/jotai";
6
+ import {
7
+ getDefaultExportFilename,
8
+ getDefaultMarkdownExportFilename,
9
+ } from "../export-filename";
10
+
11
+ describe("default export filenames", () => {
12
+ beforeEach(() => {
13
+ store.set(filenameAtom, "folder/my_notebook.py");
14
+ });
15
+
16
+ it("derives filenames from the notebook name", () => {
17
+ expect(getDefaultExportFilename("html")).toBe("my_notebook.html");
18
+ expect(getDefaultExportFilename("pdf")).toBe("my_notebook.pdf");
19
+ });
20
+
21
+ it("handles Windows-style notebook paths", () => {
22
+ store.set(filenameAtom, "C:\\Users\\me\\my_notebook.py");
23
+ expect(getDefaultExportFilename("html")).toBe("my_notebook.html");
24
+ });
25
+
26
+ it("derives markdown filenames from the selected flavor", () => {
27
+ expect(getDefaultMarkdownExportFilename("qmd")).toBe("my_notebook.qmd");
28
+ expect(getDefaultMarkdownExportFilename("mystmd")).toBe(
29
+ "my_notebook.myst.md",
30
+ );
31
+ });
32
+
33
+ it("derives script export filenames from the notebook name", () => {
34
+ expect(getDefaultExportFilename("script.py")).toBe("my_notebook.script.py");
35
+ });
36
+
37
+ it("falls back to download.* when the notebook is unnamed", () => {
38
+ store.set(filenameAtom, null);
39
+ expect(getDefaultExportFilename("html")).toBe("download.html");
40
+ expect(getDefaultMarkdownExportFilename("qmd")).toBe("download.qmd");
41
+ expect(getDefaultExportFilename("script.py")).toBe("download.script.py");
42
+ });
43
+ });
@@ -16,13 +16,45 @@ function getBaseUriWithoutQueryParams(): string {
16
16
  return url.toString();
17
17
  }
18
18
 
19
- function getExportFilename(response: Response): string {
20
- const contentDisposition = response.headers.get("Content-Disposition");
21
- const match = contentDisposition?.match(/filename\*=UTF-8''([^;]+)/i);
22
- if (!match) {
23
- throw new Error("Export response is missing a filename");
19
+ function parseContentDispositionFilename(
20
+ contentDisposition: string | null,
21
+ ): string | undefined {
22
+ if (!contentDisposition) {
23
+ return undefined;
24
24
  }
25
- return decodeURIComponent(match[1]);
25
+
26
+ const rfc5987Match = contentDisposition.match(/filename\*=UTF-8''([^;]+)/i);
27
+ if (rfc5987Match) {
28
+ try {
29
+ return decodeURIComponent(rfc5987Match[1]);
30
+ } catch {
31
+ return undefined;
32
+ }
33
+ }
34
+
35
+ const quotedMatch = contentDisposition.match(/filename="([^"]+)"/i);
36
+ if (quotedMatch) {
37
+ return quotedMatch[1];
38
+ }
39
+
40
+ const unquotedMatch = contentDisposition.match(/filename=([^;]+)/i);
41
+ if (unquotedMatch) {
42
+ return unquotedMatch[1].trim();
43
+ }
44
+
45
+ return undefined;
46
+ }
47
+
48
+ function getExportFilename(response: Response): string | undefined {
49
+ const filename = parseContentDispositionFilename(
50
+ response.headers.get("Content-Disposition"),
51
+ );
52
+ if (!filename) {
53
+ Logger.warn(
54
+ "Export response is missing a readable Content-Disposition filename",
55
+ );
56
+ }
57
+ return filename;
26
58
  }
27
59
 
28
60
  /**
@@ -129,11 +161,14 @@ export const API = {
129
161
  }
130
162
  return Promise.resolve(response.data as T);
131
163
  },
132
- handleExportResponse: async <T extends BlobPart>(response: {
133
- data?: T | undefined;
134
- error?: Record<string, unknown>;
135
- response: Response;
136
- }): Promise<ExportedFile<T>> => {
164
+ handleExportResponse: async <T extends BlobPart>(
165
+ response: {
166
+ data?: T | undefined;
167
+ error?: Record<string, unknown>;
168
+ response: Response;
169
+ },
170
+ opts: { defaultFilename: string },
171
+ ): Promise<ExportedFile<T>> => {
137
172
  const contents = await API.handleResponse<T>(response);
138
173
  const mediaType = response.response.headers.get("Content-Type");
139
174
  if (!mediaType) {
@@ -142,7 +177,7 @@ export const API = {
142
177
 
143
178
  return {
144
179
  contents,
145
- filename: getExportFilename(response.response),
180
+ filename: getExportFilename(response.response) ?? opts.defaultFilename,
146
181
  mediaType,
147
182
  };
148
183
  },
@@ -0,0 +1,37 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { filenameAtom } from "@/core/saving/file-state";
4
+ import { store } from "@/core/state/jotai";
5
+ import { Filenames } from "@/utils/filenames";
6
+ import { Paths } from "@/utils/paths";
7
+ import {
8
+ DEFAULT_MARKDOWN_FLAVOR,
9
+ MARKDOWN_EXTENSIONS,
10
+ } from "./markdown-export";
11
+ import type { ExportAsMarkdownRequest } from "./types";
12
+
13
+ const DEFAULT_EXPORT_FILENAME = "download";
14
+
15
+ function getNotebookStem(): string | undefined {
16
+ const filename = store.get(filenameAtom);
17
+ if (!filename) {
18
+ return undefined;
19
+ }
20
+ const basename = Paths.basename(filename);
21
+ return Filenames.withoutExtension(basename);
22
+ }
23
+
24
+ export function getDefaultExportFilename(extension: string): string {
25
+ const stem = getNotebookStem();
26
+ if (stem) {
27
+ return `${stem}.${extension}`;
28
+ }
29
+ return `${DEFAULT_EXPORT_FILENAME}.${extension}`;
30
+ }
31
+
32
+ export function getDefaultMarkdownExportFilename(
33
+ flavor: ExportAsMarkdownRequest["flavor"],
34
+ ): string {
35
+ const extension = MARKDOWN_EXTENSIONS[flavor ?? DEFAULT_MARKDOWN_FLAVOR];
36
+ return getDefaultExportFilename(extension);
37
+ }
@@ -0,0 +1,19 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import type { MarkdownExportFlavor } from "./types";
4
+
5
+ export const MARKDOWN_EXTENSIONS = {
6
+ pymdown: "md",
7
+ qmd: "qmd",
8
+ mystmd: "myst.md",
9
+ mdx: "mdx",
10
+ } satisfies Record<MarkdownExportFlavor, string>;
11
+ export const MARKDOWN_SUFFIXES = [
12
+ ".myst.md",
13
+ ".markdown",
14
+ ".qmd",
15
+ ".mdx",
16
+ ".md",
17
+ ];
18
+
19
+ export const DEFAULT_MARKDOWN_FLAVOR: MarkdownExportFlavor = "pymdown";
@@ -3,6 +3,10 @@
3
3
  import { once } from "@/utils/once";
4
4
  import { getRuntimeManager } from "../runtime/config";
5
5
  import { API, createClientWithRuntimeManager } from "./api";
6
+ import {
7
+ getDefaultExportFilename,
8
+ getDefaultMarkdownExportFilename,
9
+ } from "./export-filename";
6
10
  import {
7
11
  waitForConnectionOpen,
8
12
  waitForConnectionOpenIfNotebook,
@@ -426,7 +430,11 @@ export function createNetworkRequests(): EditRequests & RunRequests {
426
430
  parseAs: "text",
427
431
  params: getParams(),
428
432
  })
429
- .then(handleExportResponse);
433
+ .then((response) =>
434
+ handleExportResponse(response, {
435
+ defaultFilename: getDefaultExportFilename("html"),
436
+ }),
437
+ );
430
438
  },
431
439
  exportAsMarkdown: async (request) => {
432
440
  return getClient()
@@ -435,7 +443,11 @@ export function createNetworkRequests(): EditRequests & RunRequests {
435
443
  parseAs: "text",
436
444
  params: getParams(),
437
445
  })
438
- .then(handleExportResponse);
446
+ .then((response) =>
447
+ handleExportResponse(response, {
448
+ defaultFilename: getDefaultMarkdownExportFilename(request.flavor),
449
+ }),
450
+ );
439
451
  },
440
452
  exportAsScript: async (request) => {
441
453
  return getClient()
@@ -444,7 +456,11 @@ export function createNetworkRequests(): EditRequests & RunRequests {
444
456
  parseAs: "text",
445
457
  params: getParams(),
446
458
  })
447
- .then(handleExportResponse);
459
+ .then((response) =>
460
+ handleExportResponse(response, {
461
+ defaultFilename: getDefaultExportFilename("script.py"),
462
+ }),
463
+ );
448
464
  },
449
465
  exportAsIPYNB: async (request) => {
450
466
  return getClient()
@@ -453,7 +469,11 @@ export function createNetworkRequests(): EditRequests & RunRequests {
453
469
  parseAs: "text",
454
470
  params: getParams(),
455
471
  })
456
- .then(handleExportResponse);
472
+ .then((response) =>
473
+ handleExportResponse(response, {
474
+ defaultFilename: getDefaultExportFilename("ipynb"),
475
+ }),
476
+ );
457
477
  },
458
478
  exportAsPDF: async (request) => {
459
479
  return getClient()
@@ -462,7 +482,11 @@ export function createNetworkRequests(): EditRequests & RunRequests {
462
482
  parseAs: "blob",
463
483
  params: getParams(),
464
484
  })
465
- .then(handleExportResponse);
485
+ .then((response) =>
486
+ handleExportResponse(response, {
487
+ defaultFilename: getDefaultExportFilename("pdf"),
488
+ }),
489
+ );
466
490
  },
467
491
  autoExportAsHTML: async (request) => {
468
492
  return getClient()
@@ -22,6 +22,9 @@ export type AutoExportAsMarkdownRequest =
22
22
  schemas["AutoExportAsMarkdownRequest"];
23
23
  export type ExportAsHTMLRequest = schemas["ExportAsHTMLRequest"];
24
24
  export type ExportAsMarkdownRequest = schemas["ExportAsMarkdownRequest"];
25
+ export type MarkdownExportFlavor = NonNullable<
26
+ ExportAsMarkdownRequest["flavor"]
27
+ >;
25
28
  export type ExportAsIPYNBRequest = schemas["ExportAsIPYNBRequest"];
26
29
  export type ExportAsScriptRequest = schemas["ExportAsScriptRequest"];
27
30
  export type ExportAsPDFRequest = schemas["ExportAsPDFRequest"];
@@ -26,6 +26,11 @@ import {
26
26
  } from "lucide-react";
27
27
  import React, { useEffect, useRef, useState } from "react";
28
28
  import { z } from "zod";
29
+ import {
30
+ describeChatAbortReason,
31
+ getAbortReasonFromChunk,
32
+ resolveChatAbortReason,
33
+ } from "@/components/chat/chat-abort";
29
34
  import { renderUIMessage } from "@/components/chat/chat-display";
30
35
  import {
31
36
  convertToFileUIPart,
@@ -168,6 +173,12 @@ export const Chatbot: React.FC<Props> = (props) => {
168
173
  // different message_id are stale (from an aborted-but-not-yet-cancelled run
169
174
  // on the kernel) and must be dropped
170
175
  const activeRequestIdRef = useRef<string | null>(null);
176
+ const lastAbortReasonRef = useRef<string | null>(null);
177
+ const [abortNotice, setAbortNotice] = useState<string | null>(null);
178
+ const clearAbortState = () => {
179
+ lastAbortReasonRef.current = null;
180
+ setAbortNotice(null);
181
+ };
171
182
 
172
183
  const { data: backendMessages } = useAsyncData(async () => {
173
184
  const response = await props.get_chat_history({});
@@ -231,6 +242,7 @@ export const Chatbot: React.FC<Props> = (props) => {
231
242
  // Client-generated id used to (a) route chunks back to this stream
232
243
  // and (b) ask the kernel to cancel just this run on Stop.
233
244
  const requestId = generateUUID();
245
+ clearAbortState();
234
246
 
235
247
  const stream = new ReadableStream<UIMessageChunk>({
236
248
  start(controller) {
@@ -297,15 +309,30 @@ export const Chatbot: React.FC<Props> = (props) => {
297
309
  },
298
310
  }),
299
311
  messages: initialMessages,
300
- onFinish: (message) => {
312
+ onFinish: ({ messages, isAbort, finishReason }) => {
301
313
  setFiles(undefined);
302
314
 
303
315
  if (fileInputRef.current) {
304
316
  fileInputRef.current.value = "";
305
317
  }
306
- Logger.debug("Finished streaming message:", message);
318
+ Logger.debug("Finished streaming message:", { finishReason, isAbort });
319
+
320
+ if (isAbort) {
321
+ const reason = resolveChatAbortReason({
322
+ isAbort: true,
323
+ streamReason: lastAbortReasonRef.current,
324
+ });
325
+ clearAbortState();
326
+ if (reason != null) {
327
+ const description = describeChatAbortReason(reason);
328
+ Logger.debug("Chat stream aborted", { reason, finishReason });
329
+ setAbortNotice(description);
330
+ }
331
+ } else {
332
+ clearAbortState();
333
+ }
307
334
 
308
- props.setValue(message.messages);
335
+ props.setValue(messages);
309
336
  },
310
337
  onError: (error) => {
311
338
  Logger.error("An error occurred:", error);
@@ -323,6 +350,17 @@ export const Chatbot: React.FC<Props> = (props) => {
323
350
  if (!parsedMessage.success) {
324
351
  return;
325
352
  }
353
+ // Only record abort reasons for the active request. Late chunks from a
354
+ // cancelled run must not overwrite the next turn's reason
355
+ if (
356
+ parsedMessage.data.content &&
357
+ parsedMessage.data.message_id === activeRequestIdRef.current
358
+ ) {
359
+ const abortReason = getAbortReasonFromChunk(parsedMessage.data.content);
360
+ if (abortReason !== undefined) {
361
+ lastAbortReasonRef.current = abortReason;
362
+ }
363
+ }
326
364
  routeIncomingChatChunk(parsedMessage.data, {
327
365
  controllerRef: frontendStreamControllerRef,
328
366
  activeRequestIdRef,
@@ -340,6 +378,9 @@ export const Chatbot: React.FC<Props> = (props) => {
340
378
  setMessages(newMessages);
341
379
 
342
380
  props.setValue(newMessages);
381
+ if (newMessages.length === 0) {
382
+ clearAbortState();
383
+ }
343
384
  }
344
385
  };
345
386
 
@@ -389,6 +430,7 @@ export const Chatbot: React.FC<Props> = (props) => {
389
430
  props.setValue([]);
390
431
  props.delete_chat_history({});
391
432
  clearError();
433
+ clearAbortState();
392
434
  };
393
435
 
394
436
  return (
@@ -483,6 +525,12 @@ export const Chatbot: React.FC<Props> = (props) => {
483
525
  </Button>
484
526
  </div>
485
527
  )}
528
+
529
+ {abortNotice && !isLoading && !error && (
530
+ <div className="flex justify-center py-2">
531
+ <span className="text-xs text-muted-foreground">{abortNotice}</span>
532
+ </div>
533
+ )}
486
534
  </div>
487
535
  <form
488
536
  onSubmit={async (evt) => {