Skip to content

Commit 2c759fe

Browse files
feat: 类型修复
1 parent c4d9217 commit 2c759fe

6 files changed

Lines changed: 38 additions & 19 deletions

File tree

src/components/Settings/Config.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { Dialog } from '../design-system/Dialog.js';
2727
import { Select } from '../CustomSelect/index.js';
2828
import { OutputStylePicker } from '../OutputStylePicker.js';
2929
import { LanguagePicker } from '../LanguagePicker.js';
30-
import { getExternalClaudeMdIncludes, getMemoryFiles, hasExternalClaudeMdIncludes } from 'src/utils/claudemd.js';
30+
import { getExternalClaudeMdIncludes, getMemoryFiles, hasExternalClaudeMdIncludes, type MemoryFileInfo } from 'src/utils/claudemd.js';
3131
import { KeyboardShortcutHint } from '../design-system/KeyboardShortcutHint.js';
3232
import { ConfigurableShortcutHint } from '../ConfigurableShortcutHint.js';
3333
import { Byline } from '../design-system/Byline.js';
@@ -197,7 +197,7 @@ export function Config({
197197
}, [ownsEsc, onIsSearchModeChange]);
198198
const isConnectedToIde = hasAccessToIDEExtensionDiffFeature(context.options.mcpClients);
199199
const isFileCheckpointingAvailable = !isEnvTruthy(process.env.CLAUDE_CODE_DISABLE_FILE_CHECKPOINTING);
200-
const memoryFiles = React.use(getMemoryFiles(true));
200+
const memoryFiles = React.use(getMemoryFiles(true)) as MemoryFileInfo[];
201201
const shouldShowExternalIncludesToggle = hasExternalClaudeMdIncludes(memoryFiles);
202202
const autoUpdaterDisabledReason = getAutoUpdaterDisabledReason();
203203
function onChangeMainModelConfig(value: string | null): void {
@@ -392,7 +392,7 @@ export function Config({
392392
}
393393
}] : []),
394394
// Speculation toggle (ant-only)
395-
...("external" === 'ant' ? [{
395+
...(("external" as string) === 'ant' ? [{
396396
id: 'speculationEnabled',
397397
label: 'Speculative execution',
398398
value: globalConfig.speculationEnabled ?? true,

src/components/Spinner.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Props = {
4646
pauseStartTimeRef: React.RefObject<number | null>;
4747
spinnerTip?: string;
4848
responseLengthRef: React.RefObject<number>;
49+
apiMetricsRef?: React.RefObject<Array<{ ttftMs: number; firstTokenTime: number; lastTokenTime: number; responseLengthBaseline: number; endResponseLength: number }>>;
4950
overrideColor?: keyof Theme | null;
5051
overrideShimmerColor?: keyof Theme | null;
5152
overrideMessage?: string | null;

src/screens/REPL.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ import type { ToolPermissionContext, Tool } from '../Tool.js';
123123
import { applyPermissionUpdate, applyPermissionUpdates, persistPermissionUpdate } from '../utils/permissions/PermissionUpdate.js';
124124
import { buildPermissionUpdates } from '../components/permissions/ExitPlanModePermissionRequest/ExitPlanModePermissionRequest.js';
125125
import { stripDangerousPermissionsForAutoMode } from '../utils/permissions/permissionSetup.js';
126+
import type { PermissionMode } from '../types/permissions.js';
126127
import { getScratchpadDir, isScratchpadEnabled } from '../utils/permissions/filesystem.js';
127128
import { WEB_FETCH_TOOL_NAME } from '../tools/WebFetchTool/prompt.js';
128129
import { SLEEP_TOOL_NAME } from '../tools/SleepTool/prompt.js';
@@ -1655,7 +1656,10 @@ export function REPL({
16551656
const onlySleepToolActive = useMemo(() => {
16561657
const lastAssistant = messages.findLast(m => m.type === 'assistant');
16571658
if (lastAssistant?.type !== 'assistant') return false;
1658-
const inProgressToolUses = lastAssistant.message.content.filter(b => b.type === 'tool_use' && inProgressToolUseIDs.has(b.id));
1659+
const content = lastAssistant.message.content;
1660+
if (typeof content === 'string') return false;
1661+
const contentArr = content as Array<{ type: string; id?: string; name?: string; [key: string]: unknown }>;
1662+
const inProgressToolUses = contentArr.filter(b => b.type === 'tool_use' && b.id && inProgressToolUseIDs.has(b.id));
16591663
return inProgressToolUses.length > 0 && inProgressToolUses.every(b => b.type === 'tool_use' && b.name === SLEEP_TOOL_NAME);
16601664
}, [messages, inProgressToolUseIDs]);
16611665
const {
@@ -2605,7 +2609,7 @@ export function REPL({
26052609
if (feature('PROACTIVE') || feature('KAIROS')) {
26062610
proactiveModule?.setContextBlocked(false);
26072611
}
2608-
} else if ((newMessage as MessageType).type === 'progress' && isEphemeralToolProgress((newMessage as ProgressMessage<unknown>).data.type)) {
2612+
} else if ((newMessage as MessageType).type === 'progress' && isEphemeralToolProgress(((newMessage as MessageType).data as { type: string }).type)) {
26092613
// Replace the previous ephemeral progress tick for the same tool
26102614
// call instead of appending. Sleep/Bash emit a tick per second and
26112615
// only the last one is rendered; appending blows up the messages
@@ -2618,7 +2622,7 @@ export function REPL({
26182622
// "Initializing…" because it renders the full progress trail.
26192623
setMessages(oldMessages => {
26202624
const last = oldMessages.at(-1);
2621-
if (last?.type === 'progress' && last.parentToolUseID === (newMessage as MessageType).parentToolUseID && last.data.type === (newMessage as ProgressMessage<unknown>).data.type) {
2625+
if (last?.type === 'progress' && (last as MessageType).parentToolUseID === (newMessage as MessageType).parentToolUseID && ((last as MessageType).data as { type: string }).type === ((newMessage as MessageType).data as { type: string }).type) {
26222626
const copy = oldMessages.slice();
26232627
copy[copy.length - 1] = newMessage;
26242628
return copy;
@@ -2683,7 +2687,7 @@ export function REPL({
26832687
// title silently fell through to the "Claude Code" default.
26842688
if (!titleDisabled && !sessionTitle && !agentTitle && !haikuTitleAttemptedRef.current) {
26852689
const firstUserMessage = newMessages.find(m => m.type === 'user' && !m.isMeta);
2686-
const text = firstUserMessage?.type === 'user' ? getContentText(firstUserMessage.message.content) : null;
2690+
const text = firstUserMessage?.type === 'user' ? getContentText(firstUserMessage.message.content as string | ContentBlockParam[]) : null;
26872691
// Skip synthetic breadcrumbs — slash-command output, prompt-skill
26882692
// expansions (/commit → <command-message>), local-command headers
26892693
// (/help → <command-name>), and bash-mode (!cmd → <bash-input>).
@@ -2873,7 +2877,7 @@ export function REPL({
28732877
// Extract and enqueue user message text, skipping meta messages
28742878
// (e.g. expanded skill content, tick prompts) that should not be
28752879
// replayed as user-visible text.
2876-
newMessages.filter((m): m is UserMessage => m.type === 'user' && !m.isMeta).map(_ => getContentText(_.message.content)).filter(_ => _ !== null).forEach((msg, i) => {
2880+
newMessages.filter((m): m is UserMessage => m.type === 'user' && !m.isMeta).map(_ => getContentText(_.message.content as string | ContentBlockParam[])).filter(_ => _ !== null).forEach((msg, i) => {
28772881
enqueue({
28782882
value: msg,
28792883
mode: 'prompt'
@@ -3081,7 +3085,7 @@ export function REPL({
30813085
toolPermissionContext: updatedToolPermissionContext,
30823086
...(shouldStorePlanForVerification && {
30833087
pendingPlanVerification: {
3084-
plan: initialMsg.message.planContent!,
3088+
plan: initialMsg.message.planContent as string,
30853089
verificationStarted: false,
30863090
verificationCompleted: false
30873091
}
@@ -3693,7 +3697,7 @@ export function REPL({
36933697
// Restore permission mode from the message
36943698
toolPermissionContext: message.permissionMode && prev.toolPermissionContext.mode !== message.permissionMode ? {
36953699
...prev.toolPermissionContext,
3696-
mode: message.permissionMode
3700+
mode: message.permissionMode as PermissionMode
36973701
} : prev.toolPermissionContext,
36983702
// Clear stale prompt suggestion from previous conversation state
36993703
promptSuggestion: {
@@ -3719,7 +3723,7 @@ export function REPL({
37193723

37203724
// Restore pasted images
37213725
if (Array.isArray(message.message.content) && message.message.content.some(block => block.type === 'image')) {
3722-
const imageBlocks: Array<ImageBlockParam> = message.message.content.filter(block => block.type === 'image');
3726+
const imageBlocks = message.message.content.filter(block => block.type === 'image') as Array<ImageBlockParam>;
37233727
if (imageBlocks.length > 0) {
37243728
const newPastedContents: Record<number, PastedContent> = {};
37253729
imageBlocks.forEach((block, index) => {

src/types/global.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ declare function ExperimentEnrollmentNotice(): JSX.Element | null
4949
declare const HOOK_TIMING_DISPLAY_THRESHOLD_MS: number
5050

5151
// Ultraplan (internal)
52-
declare function UltraplanChoiceDialog(): JSX.Element | null
53-
declare function UltraplanLaunchDialog(): JSX.Element | null
54-
declare function launchUltraplan(...args: unknown[]): void
52+
declare function UltraplanChoiceDialog(props: Record<string, unknown>): JSX.Element | null
53+
declare function UltraplanLaunchDialog(props: Record<string, unknown>): JSX.Element | null
54+
declare function launchUltraplan(...args: unknown[]): Promise<string>
5555

5656
// T — Generic type parameter leaked from React compiler output
5757
// (react/compiler-runtime emits compiled JSX that loses generic type params)

src/types/message.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,37 @@ export type Message = {
1414
isCompactSummary?: boolean
1515
toolUseResult?: unknown
1616
isVisibleInTranscriptOnly?: boolean
17+
attachment?: { type: string; toolUseID?: string; [key: string]: unknown }
1718
message?: {
1819
role?: string
19-
content?: string | Array<{ type: string; text?: string; [key: string]: unknown }>
20+
id?: string
21+
content?: string | Array<{ type: string; text?: string; id?: string; name?: string; tool_use_id?: string; [key: string]: unknown }>
2022
usage?: Record<string, unknown>
2123
[key: string]: unknown
2224
}
2325
[key: string]: unknown
2426
}
2527
export type AssistantMessage = Message & { type: 'assistant' };
26-
export type AttachmentMessage<T = unknown> = Message & { type: 'attachment' };
27-
export type ProgressMessage<T = unknown> = Message & { type: 'progress' };
28+
export type AttachmentMessage<T = unknown> = Message & { type: 'attachment'; attachment: { type: string; [key: string]: unknown } };
29+
export type ProgressMessage<T = unknown> = Message & { type: 'progress'; data: T };
2830
export type SystemLocalCommandMessage = Message & { type: 'system' };
2931
export type SystemMessage = Message & { type: 'system' };
3032
export type UserMessage = Message & { type: 'user' };
3133
export type NormalizedUserMessage = UserMessage;
3234
export type RequestStartEvent = { type: string; [key: string]: unknown };
3335
export type StreamEvent = { type: string; [key: string]: unknown };
34-
export type SystemCompactBoundaryMessage = Message & { type: 'system' };
36+
export type SystemCompactBoundaryMessage = Message & {
37+
type: 'system'
38+
compactMetadata: {
39+
preservedSegment?: {
40+
headUuid: UUID
41+
tailUuid: UUID
42+
anchorUuid: UUID
43+
[key: string]: unknown
44+
}
45+
[key: string]: unknown
46+
}
47+
};
3548
export type TombstoneMessage = Message;
3649
export type ToolUseSummaryMessage = Message;
3750
export type MessageOrigin = string;

src/utils/sessionStorage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ class Project {
10581058
entrypoint: getEntrypoint(),
10591059
cwd: getCwd(),
10601060
sessionId,
1061+
timestamp: new Date().toISOString(),
10611062
version: VERSION,
10621063
gitBranch,
10631064
slug,
@@ -2225,7 +2226,7 @@ export function checkResumeConsistency(chain: Message[]): void {
22252226
for (let i = chain.length - 1; i >= 0; i--) {
22262227
const m = chain[i]!
22272228
if (m.type !== 'system' || m.subtype !== 'turn_duration') continue
2228-
const expected = m.messageCount
2229+
const expected = m.messageCount as number | undefined
22292230
if (expected === undefined) return
22302231
// `i` is the 0-based index of the checkpoint in the reconstructed chain.
22312232
// The checkpoint was appended AFTER messageCount messages, so its own

0 commit comments

Comments
 (0)