mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 00:35:51 +00:00
style: 完成所有文件的lint
This commit is contained in:
@@ -1,70 +1,56 @@
|
||||
import React, { useCallback, useRef, useState } from 'react'
|
||||
import { Select } from '../../components/CustomSelect/select.js'
|
||||
import { Box, Dialog, Text } from '@anthropic/ink'
|
||||
import React, { useCallback, useRef, useState } from 'react';
|
||||
import { Select } from '../../components/CustomSelect/select.js';
|
||||
import { Box, Dialog, Text } from '@anthropic/ink';
|
||||
|
||||
type Props = {
|
||||
onProceed: (signal: AbortSignal) => Promise<void>
|
||||
onCancel: () => void
|
||||
}
|
||||
onProceed: (signal: AbortSignal) => Promise<void>;
|
||||
onCancel: () => void;
|
||||
};
|
||||
|
||||
export function UltrareviewOverageDialog({
|
||||
onProceed,
|
||||
onCancel,
|
||||
}: Props): React.ReactNode {
|
||||
const [isLaunching, setIsLaunching] = useState(false)
|
||||
const abortControllerRef = useRef(new AbortController())
|
||||
export function UltrareviewOverageDialog({ onProceed, onCancel }: Props): React.ReactNode {
|
||||
const [isLaunching, setIsLaunching] = useState(false);
|
||||
const abortControllerRef = useRef(new AbortController());
|
||||
|
||||
const handleSelect = useCallback(
|
||||
(value: string) => {
|
||||
if (value === 'proceed') {
|
||||
setIsLaunching(true)
|
||||
setIsLaunching(true);
|
||||
// If onProceed rejects (e.g. launchRemoteReview throws), onDone is
|
||||
// never called and the dialog stays mounted — restore the Select so
|
||||
// the user can retry or cancel instead of staring at "Launching…".
|
||||
void onProceed(abortControllerRef.current.signal).catch(() =>
|
||||
setIsLaunching(false),
|
||||
)
|
||||
void onProceed(abortControllerRef.current.signal).catch(() => setIsLaunching(false));
|
||||
} else {
|
||||
onCancel()
|
||||
onCancel();
|
||||
}
|
||||
},
|
||||
[onProceed, onCancel],
|
||||
)
|
||||
);
|
||||
|
||||
// Escape during launch aborts the in-flight onProceed via signal so the
|
||||
// caller can skip side effects (confirmOverage, onDone) — otherwise a
|
||||
// fire-and-forget launch would keep running and bill despite "cancelled".
|
||||
const handleCancel = useCallback(() => {
|
||||
abortControllerRef.current.abort()
|
||||
onCancel()
|
||||
}, [onCancel])
|
||||
abortControllerRef.current.abort();
|
||||
onCancel();
|
||||
}, [onCancel]);
|
||||
|
||||
const options = [
|
||||
{ label: 'Proceed with Extra Usage billing', value: 'proceed' },
|
||||
{ label: 'Cancel', value: 'cancel' },
|
||||
]
|
||||
];
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
title="Ultrareview billing"
|
||||
onCancel={handleCancel}
|
||||
color="background"
|
||||
>
|
||||
<Dialog title="Ultrareview billing" onCancel={handleCancel} color="background">
|
||||
<Box flexDirection="column" gap={1}>
|
||||
<Text>
|
||||
Your free ultrareviews for this organization are used. Further reviews
|
||||
bill as Extra Usage (pay-per-use).
|
||||
Your free ultrareviews for this organization are used. Further reviews bill as Extra Usage (pay-per-use).
|
||||
</Text>
|
||||
{isLaunching ? (
|
||||
<Text color="background">Launching…</Text>
|
||||
) : (
|
||||
<Select
|
||||
options={options}
|
||||
onChange={handleSelect}
|
||||
onCancel={handleCancel}
|
||||
/>
|
||||
<Select options={options} onChange={handleSelect} onCancel={handleCancel} />
|
||||
)}
|
||||
</Box>
|
||||
</Dialog>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -137,9 +137,9 @@ export async function launchRemoteReview(
|
||||
// consume at session creation routes billing: first N zero-rate, then
|
||||
// anthropic:cccr org-service-key (overage-only).
|
||||
if (!eligibility.eligible) {
|
||||
const blockers = (eligibility as { eligible: false; errors: Array<{ type: string }> }).errors.filter(
|
||||
e => e.type !== 'no_remote_environment',
|
||||
)
|
||||
const blockers = (
|
||||
eligibility as { eligible: false; errors: Array<{ type: string }> }
|
||||
).errors.filter(e => e.type !== 'no_remote_environment')
|
||||
if (blockers.length > 0) {
|
||||
logEvent('tengu_review_remote_precondition_failed', {
|
||||
precondition_errors: blockers
|
||||
@@ -148,7 +148,9 @@ export async function launchRemoteReview(
|
||||
',',
|
||||
) as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
})
|
||||
const reasons = (blockers as BackgroundRemoteSessionPrecondition[]).map(formatPreconditionError).join('\n')
|
||||
const reasons = (blockers as BackgroundRemoteSessionPrecondition[])
|
||||
.map(formatPreconditionError)
|
||||
.join('\n')
|
||||
return [
|
||||
{
|
||||
type: 'text',
|
||||
|
||||
@@ -1,21 +1,14 @@
|
||||
import type { ContentBlockParam } from '@anthropic-ai/sdk/resources/messages.js'
|
||||
import React from 'react'
|
||||
import type {
|
||||
LocalJSXCommandCall,
|
||||
LocalJSXCommandOnDone,
|
||||
} from '../../types/command.js'
|
||||
import {
|
||||
checkOverageGate,
|
||||
confirmOverage,
|
||||
launchRemoteReview,
|
||||
} from './reviewRemote.js'
|
||||
import { UltrareviewOverageDialog } from './UltrareviewOverageDialog.js'
|
||||
import type { ContentBlockParam } from '@anthropic-ai/sdk/resources/messages.js';
|
||||
import React from 'react';
|
||||
import type { LocalJSXCommandCall, LocalJSXCommandOnDone } from '../../types/command.js';
|
||||
import { checkOverageGate, confirmOverage, launchRemoteReview } from './reviewRemote.js';
|
||||
import { UltrareviewOverageDialog } from './UltrareviewOverageDialog.js';
|
||||
|
||||
function contentBlocksToString(blocks: ContentBlockParam[]): string {
|
||||
return blocks
|
||||
.map(b => (b.type === 'text' ? b.text : ''))
|
||||
.filter(Boolean)
|
||||
.join('\n')
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
async function launchAndDone(
|
||||
@@ -25,65 +18,57 @@ async function launchAndDone(
|
||||
billingNote: string,
|
||||
signal?: AbortSignal,
|
||||
): Promise<void> {
|
||||
const result = await launchRemoteReview(args, context, billingNote)
|
||||
const result = await launchRemoteReview(args, context, billingNote);
|
||||
// User hit Escape during the ~5s launch — the dialog already showed
|
||||
// "cancelled" and unmounted, so skip onDone (would write to a dead
|
||||
// transcript slot) and let the caller skip confirmOverage.
|
||||
if (signal?.aborted) return
|
||||
if (signal?.aborted) return;
|
||||
if (result) {
|
||||
onDone(contentBlocksToString(result), { shouldQuery: true })
|
||||
onDone(contentBlocksToString(result), { shouldQuery: true });
|
||||
} else {
|
||||
// Precondition failures now return specific ContentBlockParam[] above.
|
||||
// null only reaches here on teleport failure (PR mode) or non-github
|
||||
// repo — both are CCR/repo connectivity issues.
|
||||
onDone(
|
||||
'Ultrareview failed to launch the remote session. Check that this is a GitHub repo and try again.',
|
||||
{ display: 'system' },
|
||||
)
|
||||
onDone('Ultrareview failed to launch the remote session. Check that this is a GitHub repo and try again.', {
|
||||
display: 'system',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const call: LocalJSXCommandCall = async (onDone, context, args) => {
|
||||
const gate = await checkOverageGate()
|
||||
const gate = await checkOverageGate();
|
||||
|
||||
if (gate.kind === 'not-enabled') {
|
||||
onDone(
|
||||
'Free ultrareviews used. Enable Extra Usage at https://claude.ai/settings/billing to continue.',
|
||||
{ display: 'system' },
|
||||
)
|
||||
return null
|
||||
onDone('Free ultrareviews used. Enable Extra Usage at https://claude.ai/settings/billing to continue.', {
|
||||
display: 'system',
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
if (gate.kind === 'low-balance') {
|
||||
onDone(
|
||||
`Balance too low to launch ultrareview ($${gate.available.toFixed(2)} available, $10 minimum). Top up at https://claude.ai/settings/billing`,
|
||||
{ display: 'system' },
|
||||
)
|
||||
return null
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (gate.kind === 'needs-confirm') {
|
||||
return (
|
||||
<UltrareviewOverageDialog
|
||||
onProceed={async signal => {
|
||||
await launchAndDone(
|
||||
args,
|
||||
context,
|
||||
onDone,
|
||||
' This review bills as Extra Usage.',
|
||||
signal,
|
||||
)
|
||||
await launchAndDone(args, context, onDone, ' This review bills as Extra Usage.', signal);
|
||||
// Only persist the confirmation flag after a non-aborted launch —
|
||||
// otherwise Escape-during-launch would leave the flag set and
|
||||
// skip this dialog on the next attempt.
|
||||
if (!signal.aborted) confirmOverage()
|
||||
if (!signal.aborted) confirmOverage();
|
||||
}}
|
||||
onCancel={() => onDone('Ultrareview cancelled.', { display: 'system' })}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// gate.kind === 'proceed'
|
||||
await launchAndDone(args, context, onDone, gate.billingNote)
|
||||
return null
|
||||
}
|
||||
await launchAndDone(args, context, onDone, gate.billingNote);
|
||||
return null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user