Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(cowork): smooth CoT collapse, system-note chip, green test suite

Akarshan Biswasb0401442aaa7
diff --git a/extensions/llamacpp-extension/src/test/setup.ts b/extensions/llamacpp-extension/src/test/setup.ts
index 2cda11fda..4a83621f0 100644
--- a/extensions/llamacpp-extension/src/test/setup.ts
+++ b/extensions/llamacpp-extension/src/test/setup.ts
@@ -1,5 +1,26 @@
import { vi } from 'vitest'
+// `Promise.withResolvers` (Node 22+) is used by tests that resolve a promise
+// from outside its executor. Polyfilled for the Node 20 runtime; a no-op where
+// the runtime already ships it.
+if (typeof (Promise as { withResolvers?: unknown }).withResolvers !== 'function') {
+ (
+ Promise as unknown as { withResolvers: <T>() => {
+ promise: Promise<T>
+ resolve: (value: T | PromiseLike<T>) => void
+ reject: (reason?: unknown) => void
+ } }
+ ).withResolvers = function withResolvers<T>() {
+ let resolve!: (value: T | PromiseLike<T>) => void
+ let reject!: (reason?: unknown) => void
+ const promise = new Promise<T>((res, rej) => {
+ resolve = res
+ reject = rej
+ })
+ return { promise, resolve, reject }
+ }
+}
+
// Mock localStorage
const localStorageMock = {
getItem: vi.fn(),
diff --git a/web-app/src/components/ai-elements/chain-of-thought.tsx b/web-app/src/components/ai-elements/chain-of-thought.tsx
index 8fec85290..acc3f7a73 100644
--- a/web-app/src/components/ai-elements/chain-of-thought.tsx
+++ b/web-app/src/components/ai-elements/chain-of-thought.tsx
@@ -313,7 +313,11 @@ export const ChainOfThoughtContent = memo(
<CollapsibleContent
className={cn(
'mt-4 text-sm relative',
- 'data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in',
+ // Expand animates in; collapse unmounts synchronously (no exit
+ // animation). A lingering exit keeps the content's height while the
+ // root has already snapped to the folded w-fit/rounded-full pill,
+ // which renders a tall narrow rounded box as a circle for that frame.
+ 'data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=open]:animate-in',
className
)}
{...props}
diff --git a/web-app/src/containers/MessageItem.tsx b/web-app/src/containers/MessageItem.tsx
index 287fe6e7f..b92fd8e57 100644
--- a/web-app/src/containers/MessageItem.tsx
+++ b/web-app/src/containers/MessageItem.tsx
@@ -26,8 +26,9 @@ import {
IconAlertTriangle,
IconChevronLeft,
IconChevronRight,
- IconSparkles,
+ IconBellRinging,
} from '@tabler/icons-react'
+import { PING_OPEN, PING_CLOSE } from '@/lib/coworkPing'
import { EditMessageDialog } from '@/containers/dialogs/EditMessageDialog'
import { DeleteMessageDialog } from '@/containers/dialogs/DeleteMessageDialog'
import TokenSpeedIndicator from '@/containers/TokenSpeedIndicator'
@@ -536,12 +537,16 @@ export const MessageItem = memo(
// what the next turn is replying to -- a turn that reacts to a subagent
// finishing reads as a non sequitur without it.
if (message.role === 'system') {
+ const note = getFullTextContent()
+ .split(PING_OPEN)
+ .join('')
+ .split(PING_CLOSE)
+ .join('')
+ .trim()
return (
- <div className="mb-4 flex items-start gap-2 rounded-md border border-border/50 bg-muted/30 px-3 py-2 text-xs text-muted-foreground">
- <IconSparkles size={14} className="mt-0.5 shrink-0 text-primary" />
- <span className="min-w-0 whitespace-pre-wrap">
- {getFullTextContent()}
- </span>
+ <div className="mb-4 inline-flex w-fit max-w-full items-center gap-2 self-start rounded-full border border-border/50 bg-main-view-fg/2 px-2.5 py-1 text-xs text-muted-foreground">
+ <IconBellRinging size={14} className="shrink-0" />
+ <span className="min-w-0 truncate">{note}</span>
</div>
)
}
diff --git a/web-app/src/containers/__tests__/ChatInput.test.tsx b/web-app/src/containers/__tests__/ChatInput.test.tsx
index b46b7eee3..e53ab6824 100644
--- a/web-app/src/containers/__tests__/ChatInput.test.tsx
+++ b/web-app/src/containers/__tests__/ChatInput.test.tsx
@@ -717,7 +717,9 @@ describe('ChatInput', () => {
})
const controls = screen.getByText('folder').parentElement
- expect(controls).toHaveClass('overflow-x-auto', 'scrollbar-hide')
+ // The controls wrap onto a second line when the composer narrows rather
+ // than hiding behind a horizontal scroll, so no control is unreachable.
+ expect(controls).toHaveClass('flex-wrap')
expect(controls).toHaveClass('min-w-0', 'flex-1')
})
})
diff --git a/web-app/src/containers/__tests__/MessageItem.test.tsx b/web-app/src/containers/__tests__/MessageItem.test.tsx
index ae1bbc6e8..93f157ce7 100644
--- a/web-app/src/containers/__tests__/MessageItem.test.tsx
+++ b/web-app/src/containers/__tests__/MessageItem.test.tsx
@@ -695,15 +695,18 @@ describe('MessageItem', () => {
expect(headers).toContain('beta')
})
- it('still truncates a non-pending earlier tool step while streaming', () => {
- // No pending approval: streaming truncation keeps only the latest step.
+ it('still truncates a non-pending earlier tool step outside the frontier while streaming', () => {
+ // No pending approval, and reasoning splits the two calls so they are not
+ // one trailing batch: streaming truncation keeps only the current step
+ // (the trailing tool), dropping the earlier tool that a step has moved past.
pendingApprovalsRef.current = {}
render(
<MessageItem
message={
makeMsg({
parts: [
- { type: 'tool-alpha', state: 'input-available', toolCallId: 'tc-alpha', input: {} },
+ { type: 'tool-alpha', state: 'output-available', toolCallId: 'tc-alpha', input: {}, output: 'done' },
+ { type: 'reasoning', text: 'now the next thing' },
{ type: 'tool-beta', state: 'input-available', toolCallId: 'tc-beta', input: {} },
],
}) as any
diff --git a/web-app/src/test/setup.ts b/web-app/src/test/setup.ts
index 3c07d64d3..84baf4b71 100644
--- a/web-app/src/test/setup.ts
+++ b/web-app/src/test/setup.ts
@@ -155,6 +155,27 @@ vi.mock('@/hooks/useServiceHub', () => ({
isServiceHubInitialized: () => true,
}))
+// `Promise.withResolvers` (Node 22+) is used by tests that need to resolve a
+// promise from outside its executor. Polyfilled for the Node 20 runtime; a
+// no-op where the runtime already ships it.
+if (typeof (Promise as { withResolvers?: unknown }).withResolvers !== 'function') {
+ (
+ Promise as unknown as { withResolvers: <T>() => {
+ promise: Promise<T>
+ resolve: (value: T | PromiseLike<T>) => void
+ reject: (reason?: unknown) => void
+ } }
+ ).withResolvers = function withResolvers<T>() {
+ let resolve!: (value: T | PromiseLike<T>) => void
+ let reject!: (reason?: unknown) => void
+ const promise = new Promise<T>((res, rej) => {
+ resolve = res
+ reject = rej
+ })
+ return { promise, resolve, reject }
+ }
+}
+
// Radix's floating primitives (Tooltip, Popover, Select) measure with
// ResizeObserver, which jsdom does not implement. Stubbed globally rather than
// per test file, where it was already copied three times.