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.

refactor(web-app): drop exports that nothing outside their own file uses

Akarshan Biswas679a9e1b868d
diff --git a/web-app/src/components/ai-elements/conversation.tsx b/web-app/src/components/ai-elements/conversation.tsx
index 49593d02d..c399881fc 100644
--- a/web-app/src/components/ai-elements/conversation.tsx
+++ b/web-app/src/components/ai-elements/conversation.tsx
@@ -49,7 +49,7 @@ export const Conversation = memo(
Conversation.displayName = 'Conversation'
-export type ConversationContentProps = ComponentProps<typeof StickToBottom.Content> & {
+type ConversationContentProps = ComponentProps<typeof StickToBottom.Content> & {
column?: boolean
}
diff --git a/web-app/src/containers/ComposerModelPicker.tsx b/web-app/src/containers/ComposerModelPicker.tsx
index c37da92fe..c4e831ee1 100644
--- a/web-app/src/containers/ComposerModelPicker.tsx
+++ b/web-app/src/containers/ComposerModelPicker.tsx
@@ -16,7 +16,7 @@ import { route } from '@/constants/routes'
import { useTranslation } from '@/i18n/react-i18next-compat'
import { getLastUsedModel } from '@/utils/getModelToStart'
-export interface ComposerModelPickerProps {
+interface ComposerModelPickerProps {
model?: ThreadModel
useLastUsedModel?: boolean
onModelChange?: (model: ThreadModel) => void
@@ -24,7 +24,7 @@ export interface ComposerModelPickerProps {
disabled?: boolean
}
-export interface ComposerEffortChoice {
+interface ComposerEffortChoice {
value: string
/** English fallback; the picker renders the translated label for `value`. */
label: string
diff --git a/web-app/src/containers/CoworkPreviewPanel.tsx b/web-app/src/containers/CoworkPreviewPanel.tsx
index e8ddaff95..fc2cb59cd 100644
--- a/web-app/src/containers/CoworkPreviewPanel.tsx
+++ b/web-app/src/containers/CoworkPreviewPanel.tsx
@@ -332,7 +332,7 @@ function Notice({ children }: { children: React.ReactNode }) {
)
}
-export function PreviewBody({
+function PreviewBody({
state,
allowNetwork,
liveUrl,
diff --git a/web-app/src/lib/__tests__/chatClose.test.ts b/web-app/src/lib/__tests__/chatClose.test.ts
index 7ffad3a30..ba3de9340 100644
--- a/web-app/src/lib/__tests__/chatClose.test.ts
+++ b/web-app/src/lib/__tests__/chatClose.test.ts
@@ -6,7 +6,6 @@ import {
observeChatWork,
quiesceChats,
forgetChat,
- isChatClosing,
__resetChatCloseForTests,
resumeChatsAfterPreventedClose,
withChatCloseDeadline,
@@ -110,11 +109,13 @@ describe('ordinary Chat close barrier using installed SDK', () => {
it('refuses new operations while closing and accepts them again after a prevented close', async () => {
const stream = streamChat()
await quiesceChats()
- expect(isChatClosing()).toBe(true)
await stream.chat.sendMessage({ text: 'ignored' }) // guarded: no-op
expect(stream.chat.messages).toHaveLength(0)
resumeChatsAfterPreventedClose()
- expect(isChatClosing()).toBe(false)
+ void stream.chat.sendMessage({ text: 'accepted' })
+ await stream.started.promise
+ expect(stream.chat.messages).toHaveLength(1)
+ stream.chat.stop()
})
it('a forgotten chat no longer participates', async () => {
diff --git a/web-app/src/lib/__tests__/coworkSync.test.ts b/web-app/src/lib/__tests__/coworkSync.test.ts
index 54576aa71..74ef0f96a 100644
--- a/web-app/src/lib/__tests__/coworkSync.test.ts
+++ b/web-app/src/lib/__tests__/coworkSync.test.ts
@@ -109,15 +109,18 @@ vi.mock('@tauri-apps/api/window', () => ({
}))
import { useCoworkSessions } from '@/hooks/useCoworkSessions'
-import { registerCoworkRunForClose, isCoworkClosing } from '@/hooks/useCoworkRun'
+import {
+ registerCoworkRunForClose,
+ isCoworkClosing,
+ resumeCoworkAfterPreventedClose,
+} from '@/hooks/useCoworkRun'
+import { resumeChatsAfterPreventedClose } from '../chatClose'
import { useThreads } from '@/hooks/useThreads'
import { useMessages, __resetMessageWritesForTests } from '@/hooks/useMessages'
import {
startCoworkSync,
- flushCowork,
flushCoworkDeletes,
flushCoworkStartupWarnings,
- isCoworkMigrationDone,
COWORK_MIGRATION_BUDGET_MS,
COWORK_CLOSE_FAILURES_BEFORE_FORCE,
__resetCoworkSyncForTests,
@@ -145,6 +148,14 @@ const putBlob = (...sessions: Json[]) =>
JSON.stringify({ state: { sessions }, version: 1 })
)
+// Cowork writes are drained through the window-close handshake, the public way
+// to flush them; its closing barriers are lifted again so a test can keep editing.
+const flushCowork = async () => {
+ await closeWindow.callback!({ preventDefault: vi.fn() })
+ resumeCoworkAfterPreventedClose()
+ resumeChatsAfterPreventedClose()
+}
+
const reply = { id: 'm2', role: 'assistant', parts: [{ type: 'text', text: 'ok' }] }
describe('coworkSync', () => {
@@ -181,7 +192,7 @@ describe('coworkSync', () => {
expect(backend.threads.get('a')!.metadata.mode).toBe('cowork')
expect(useCoworkSessions.getState().sessions.map((s) => s.id).sort()).toEqual(['a', 'b'])
expect(backend.settings.get(COWORK_MIGRATION_FLAG_KEY)).toBe('true')
- expect(isCoworkMigrationDone()).toBe(true)
+ expect(backend.settings.get(COWORK_MIGRATION_FLAG_KEY)).toBe('true')
// The legacy blob is the rollback source and is never touched.
expect(backend.settings.has(CODE_SESSIONS_KEY)).toBe(true)
// Cowork threads reach the shared thread list (search, sidebar) exactly once.
@@ -348,7 +359,7 @@ describe('coworkSync', () => {
// Make the migration fail transiently so the blob stays live.
agentTools.copySessionWorkspaceToThread.mockRejectedValueOnce(new Error('disk busy'))
await startCoworkSync()
- expect(isCoworkMigrationDone()).toBe(false)
+ expect(backend.settings.get(COWORK_MIGRATION_FLAG_KEY)).not.toBe('true')
const blob = backend.settings.get(CODE_SESSIONS_KEY)
useCoworkSessions.getState().deleteSession('a')
await flushCoworkDeletes()
@@ -411,7 +422,7 @@ describe('coworkSync', () => {
const started = startCoworkSync()
await vi.advanceTimersByTimeAsync(COWORK_MIGRATION_BUDGET_MS + 100)
await started
- expect(isCoworkMigrationDone()).toBe(false)
+ expect(backend.settings.get(COWORK_MIGRATION_FLAG_KEY)).not.toBe('true')
// Legacy-only sessions are visible meanwhile, nothing is lost.
expect(useCoworkSessions.getState().sessions.map((s) => s.id).sort()).toEqual(['a', 'b'])
// The user edits a legacy session before the migration reaches it.
@@ -421,7 +432,7 @@ describe('coworkSync', () => {
release()
await vi.advanceTimersByTimeAsync(200)
await flushCowork()
- expect(isCoworkMigrationDone()).toBe(true)
+ expect(backend.settings.get(COWORK_MIGRATION_FLAG_KEY)).toBe('true')
// The newer write-through wins over the blob's older copy.
expect(backend.threads.get('a')!.title).toBe('Edited meanwhile')
expect(backend.threads.has('b')).toBe(true)
diff --git a/web-app/src/lib/chatClose.ts b/web-app/src/lib/chatClose.ts
index 6c02d0f9f..1ab729c42 100644
--- a/web-app/src/lib/chatClose.ts
+++ b/web-app/src/lib/chatClose.ts
@@ -3,7 +3,6 @@ import type { Chat, UIMessage } from '@ai-sdk/react'
type Participant = { stop: () => void | Promise<void>; settle: () => Promise<void> }
const participants = new Map<Chat<UIMessage>, Participant>()
let closing = false
-export const isChatClosing = () => closing
export function resumeChatsAfterPreventedClose() { closing = false }
/** Retained Chat objects, not mounted routes, own these registrations. */
diff --git a/web-app/src/lib/coworkHandoff.ts b/web-app/src/lib/coworkHandoff.ts
index 4253be92d..655ddb550 100644
--- a/web-app/src/lib/coworkHandoff.ts
+++ b/web-app/src/lib/coworkHandoff.ts
@@ -16,7 +16,7 @@ import type { Attachment } from '@/types/attachment'
export const COWORK_HANDOFF_PREFIX = 'cowork-initial-message:'
-export type CoworkHandoff = {
+type CoworkHandoff = {
text: string
draft?: string
files?: Array<{ type: 'file'; mediaType: string; url: string }>
diff --git a/web-app/src/lib/coworkPersistence.ts b/web-app/src/lib/coworkPersistence.ts
index ae79c2f52..5a5864a50 100644
--- a/web-app/src/lib/coworkPersistence.ts
+++ b/web-app/src/lib/coworkPersistence.ts
@@ -50,7 +50,7 @@ import {
export const COWORK_CURRENT_ID_KEY = 'cowork_current_id'
/** The metadata keys Cowork owns or reads; any other key must round-trip. */
-export type ThreadMetadata = {
+type ThreadMetadata = {
mode?: string
folder?: string | null
folderAccess?: string
@@ -208,7 +208,7 @@ function isConsumableSidecar(side: Partial<CoworkSidecar>): boolean {
/** Control flow only: the legacy blob does not need to be read. */
class SkipBlob extends Error {}
-export type LoadedCoworkSessions = {
+type LoadedCoworkSessions = {
sessions: CoworkSession[]
currentId: string | null
/** Sessions sourced from the legacy `code-sessions` blob, not yet threads. */
@@ -395,7 +395,7 @@ const LIVE_METADATA_KEYS = [
'titleSetManually',
] as const
-export function isPermanentError(error: unknown): boolean {
+function isPermanentError(error: unknown): boolean {
return toMessage(error).trimStart().startsWith(PERMANENT_ERROR_PREFIX)
}
diff --git a/web-app/src/lib/coworkSync.ts b/web-app/src/lib/coworkSync.ts
index bd2155b41..4ac4913b7 100644
--- a/web-app/src/lib/coworkSync.ts
+++ b/web-app/src/lib/coworkSync.ts
@@ -126,10 +126,6 @@ function diff(prev: CoworkSession[], next: CoworkSession[]) {
return { changed, removed }
}
-export function isCoworkMigrationDone(): boolean {
- return migrationSettled
-}
-
/** Await in-flight Cowork deletions (used before the window closes). */
export async function flushCoworkDeletes(): Promise<void> {
if (startPromise) await startPromise
@@ -141,14 +137,14 @@ export async function flushCoworkDeletes(): Promise<void> {
}
}
-/** Await queued and in-flight Cowork writes. */
-export async function flushCowork(): Promise<void> {
- await persistence?.flush()
-}
-
/** Everything the window must drain before it may go away. */
function flushAllWrites(): Promise<PromiseSettledResult<void>[]> {
- return Promise.allSettled([flushCowork(), flushCoworkDeletes(), flushMessageWrites()])
+ return Promise.allSettled([
+ // Queued and in-flight Cowork writes.
+ persistence?.flush(),
+ flushCoworkDeletes(),
+ flushMessageWrites(),
+ ])
}
/** Cowork needs the desktop host (native folder dialog, sandboxed tools). */
diff --git a/web-app/src/lib/coworkThreadMessages.ts b/web-app/src/lib/coworkThreadMessages.ts
index a2bd41ae7..39fac8783 100644
--- a/web-app/src/lib/coworkThreadMessages.ts
+++ b/web-app/src/lib/coworkThreadMessages.ts
@@ -26,7 +26,7 @@ import { SYSTEM_NOTICE_KEY, isPingOnly } from '@/lib/coworkPing'
* reloads a call as an error only when its error text is non-empty, so an
* empty one would come back as a call that never finished.
*/
-export const EMPTY_TOOL_ERROR = 'The tool failed without reporting an error.'
+const EMPTY_TOOL_ERROR = 'The tool failed without reporting an error.'
type Part = {
type?: unknown
@@ -188,7 +188,7 @@ function convertMessage(
return { content, toolErrors }
}
-export type ThreadMessagesOptions = {
+type ThreadMessagesOptions = {
/**
* Anchor for `created_at`, in ms: message `i` is stamped `anchorMs + i`.
* Without it the stamps end at `session.updated`, which is right for a
diff --git a/web-app/src/lib/coworkTodo.ts b/web-app/src/lib/coworkTodo.ts
index efd9159e7..4eadd407d 100644
--- a/web-app/src/lib/coworkTodo.ts
+++ b/web-app/src/lib/coworkTodo.ts
@@ -303,7 +303,7 @@ export function todoProgress(list: TodoList): { done: number; total: number } {
}
/** Shared snapshot validation for transcript projections without SDK/store imports. */
-export function isTodoList(value: unknown): value is TodoList {
+function isTodoList(value: unknown): value is TodoList {
if (
!value ||
typeof value !== 'object' ||
diff --git a/web-app/src/lib/extensions/contributions.ts b/web-app/src/lib/extensions/contributions.ts
index 556efbc2b..b9dc79897 100644
--- a/web-app/src/lib/extensions/contributions.ts
+++ b/web-app/src/lib/extensions/contributions.ts
@@ -22,7 +22,7 @@ import type { L10nTables } from './l10n'
export type RegisteredCommand = CommandContribution & {
handler?: CommandHandler
}
-export type RegisteredTool = ToolContribution & {
+type RegisteredTool = ToolContribution & {
handler?: ToolHandler
/**
* Host-assigned identity of the live binding: set on every bind, cleared on
diff --git a/web-app/src/lib/mergeHistory.ts b/web-app/src/lib/mergeHistory.ts
index 39b2e8193..b820f47a0 100644
--- a/web-app/src/lib/mergeHistory.ts
+++ b/web-app/src/lib/mergeHistory.ts
@@ -11,7 +11,7 @@ import type { CoworkSession } from '@/hooks/useCoworkSessions'
* (an unavailable session, which history is the only way to reach and delete).
*/
-export type HistoryRow =
+type HistoryRow =
| { kind: 'thread'; id: string; updated: number; thread: Thread }
| { kind: 'session'; id: string; updated: number; session: CoworkSession }
diff --git a/web-app/src/lib/migrateCoworkSessions.ts b/web-app/src/lib/migrateCoworkSessions.ts
index b48ae32d9..b8dc91a57 100644
--- a/web-app/src/lib/migrateCoworkSessions.ts
+++ b/web-app/src/lib/migrateCoworkSessions.ts
@@ -91,9 +91,9 @@ export type Invoke = <T = unknown>(
* so the migration stays a pure sequence of backend calls; the startup entry
* point wires it to the agent-tools plugin.
*/
-export type CopyWorkspace = (id: string) => Promise<{ copied: boolean }>
+type CopyWorkspace = (id: string) => Promise<{ copied: boolean }>
-export type MigrationDeps = { copyWorkspace?: CopyWorkspace }
+type MigrationDeps = { copyWorkspace?: CopyWorkspace }
export type CoworkMigrationResult = {
status: 'already-migrated' | 'nothing-to-migrate' | 'complete' | 'partial'
@@ -157,7 +157,7 @@ function canonical(v: unknown): string {
// Mirrors validate_thread_id in src-tauri/src/core/threads/utils.rs.
const WINDOWS_DEVICE = /^(con|prn|aux|nul|(com|lpt)\d)$/i
-export function isValidThreadId(id: unknown): id is string {
+function isValidThreadId(id: unknown): id is string {
return (
typeof id === 'string' &&
id.length > 0 &&
diff --git a/web-app/src/lib/threadMode.ts b/web-app/src/lib/threadMode.ts
index 7def3615a..969cbf729 100644
--- a/web-app/src/lib/threadMode.ts
+++ b/web-app/src/lib/threadMode.ts
@@ -4,7 +4,7 @@
* before Cowork was merged into threads is a chat. The mode only selects the
* runner: every thread, whatever its mode, uses the thread sandbox.
*/
-export type ThreadMode = 'chat' | 'cowork'
+type ThreadMode = 'chat' | 'cowork'
type WithMetadata =
| { metadata?: Record<string, unknown> | null }
diff --git a/web-app/src/lib/threadRouteClassification.ts b/web-app/src/lib/threadRouteClassification.ts
index 78b8035a4..a73ccd9d5 100644
--- a/web-app/src/lib/threadRouteClassification.ts
+++ b/web-app/src/lib/threadRouteClassification.ts
@@ -66,7 +66,7 @@ export const threadLookupDelayMs = (attempt: number): number =>
const defaultSleep = (ms: number) =>
new Promise<void>((resolve) => setTimeout(resolve, ms))
-export interface ResolveThreadForRouteOptions<T extends { id: string }> {
+interface ResolveThreadForRouteOptions<T extends { id: string }> {
threadId: string
/** Live store read; consulted before every attempt and after every fetch. */
readThread: () => T | undefined