diff --git a/frontend/server/cronjobs/__init__.py b/frontend/server/cronjobs/__init__.py index d960447b7..5ff2cbefb 100644 --- a/frontend/server/cronjobs/__init__.py +++ b/frontend/server/cronjobs/__init__.py @@ -20,7 +20,7 @@ Stored, TosCronjobRepository, ) -from .routes import mount_routes +from .routes import mount_routes, mount_storage_unavailable_routes from .schemas import ( CreateCronjobRequest, Cronjob, @@ -56,4 +56,5 @@ "TosCronjobRepository", "UpdateCronjobRequest", "mount_routes", + "mount_storage_unavailable_routes", ] diff --git a/frontend/server/cronjobs/routes.py b/frontend/server/cronjobs/routes.py index 032ab2150..2cfbbab97 100644 --- a/frontend/server/cronjobs/routes.py +++ b/frontend/server/cronjobs/routes.py @@ -40,6 +40,16 @@ IdentityResolver = Callable[[Request], CronjobIdentity] RuntimeAuthorizer = Callable[[Request, str, str], Any] +CRONJOB_STORAGE_NOT_CONFIGURED_MESSAGE = ( + "定时任务不可用:Studio 未挂载 TOS 持久化存储。" + "请配置 VEADK_STUDIO_TOS_BUCKET 和 VEADK_STUDIO_TOS_REGION," + "确认 Studio 有权访问该 Bucket,然后重新启动 Studio。" +) +CRONJOB_STORAGE_UNREACHABLE_MESSAGE = ( + "无法连接定时任务使用的 TOS 持久化存储。" + "请联系管理员检查 TOS Bucket、Region、Endpoint、访问凭据和网络连通性。" +) + def mount_routes( app: Any, @@ -203,6 +213,29 @@ async def cancel_cronjob_run( ) +def mount_storage_unavailable_routes(app: Any) -> None: + """Keep the cronjob API contract JSON-shaped when TOS is not mounted.""" + + async def unavailable() -> None: + raise HTTPException( + status_code=status.HTTP_503_SERVICE_UNAVAILABLE, + detail=CRONJOB_STORAGE_NOT_CONFIGURED_MESSAGE, + ) + + app.add_api_route( + "/web/cronjobs", + unavailable, + methods=["GET", "POST", "PATCH", "DELETE"], + include_in_schema=False, + ) + app.add_api_route( + "/web/cronjobs/{path:path}", + unavailable, + methods=["GET", "POST", "PATCH", "DELETE"], + include_in_schema=False, + ) + + async def _invoke(call: Callable[[], Any], *, list_response: bool = False) -> Any: try: result = await call() @@ -224,9 +257,16 @@ def _raise_api_error(error: Exception) -> None: if isinstance(error, CronjobRunQueueUnavailable): raise HTTPException(status_code=503, detail=str(error)) from error raise HTTPException( - status_code=502, - detail="定时任务服务暂时不可用,请稍后重试。", + status_code=503, + detail=CRONJOB_STORAGE_UNREACHABLE_MESSAGE, ) from error -__all__ = ["IdentityResolver", "RuntimeAuthorizer", "mount_routes"] +__all__ = [ + "CRONJOB_STORAGE_NOT_CONFIGURED_MESSAGE", + "CRONJOB_STORAGE_UNREACHABLE_MESSAGE", + "IdentityResolver", + "RuntimeAuthorizer", + "mount_routes", + "mount_storage_unavailable_routes", +] diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 80d6b344c..95e1bf8c0 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -283,7 +283,9 @@ interface NewChatCapabilitiesState { harnessEnabled?: boolean; builtinTools?: string[]; temporaryEnabled?: boolean; + temporaryUnavailableReason?: string; deepseekHarnessEnabled?: boolean; + deepseekHarnessUnavailableReason?: string; sandboxEndpointExportEnabled?: boolean; skillCustomizationEnabled?: boolean; } @@ -315,9 +317,17 @@ async function probeNewChatCapabilities( builtinTools: harnessResult.status === "fulfilled" ? harnessResult.value : [], temporaryEnabled: sandboxResult.status === "fulfilled" && sandboxResult.value.enabled, + temporaryUnavailableReason: + sandboxResult.status === "fulfilled" + ? sandboxResult.value.reason + : "无法读取 Codex Sandbox 配置,请检查 Studio 服务。", deepseekHarnessEnabled: deepseekHarnessResult.status === "fulfilled" && deepseekHarnessResult.value.enabled, + deepseekHarnessUnavailableReason: + deepseekHarnessResult.status === "fulfilled" + ? deepseekHarnessResult.value.reason + : "无法读取 DeepSeek Harness Sandbox 配置,请检查 Studio 服务。", sandboxEndpointExportEnabled: sandboxResult.status === "fulfilled" && sandboxResult.value.endpointExportEnabled === true, @@ -6316,10 +6326,20 @@ export default function App() { onSkillActionChange={setNewChatSkillAction} onSkillTargetChange={setNewChatSkillTarget} temporaryEnabled={newChatCapabilitiesReady && newChatCapabilities.temporaryEnabled} + temporaryUnavailableReason={ + newChatCapabilitiesReady + ? newChatCapabilities.temporaryUnavailableReason + : "正在检查 Codex Sandbox 配置" + } deepseekHarnessEnabled={ newChatCapabilitiesReady && newChatCapabilities.deepseekHarnessEnabled } + deepseekHarnessUnavailableReason={ + newChatCapabilitiesReady + ? newChatCapabilities.deepseekHarnessUnavailableReason + : "正在检查 DeepSeek Harness Sandbox 配置" + } harnessEnabled={newChatCapabilitiesReady && newChatCapabilities.harnessEnabled} builtinTools={ newChatCapabilitiesReady ? newChatCapabilities.builtinTools : [] diff --git a/frontend/src/adk/client.ts b/frontend/src/adk/client.ts index 14049cd40..bdb114cd2 100644 --- a/frontend/src/adk/client.ts +++ b/frontend/src/adk/client.ts @@ -3237,10 +3237,35 @@ function cronJobPath(jobId = ""): string { return `/web/cronjobs${jobId ? `/${encodeURIComponent(jobId)}` : ""}`; } +async function cronJobErrorMessage( + response: Response, + fallback: string, +): Promise { + const context = `${fallback}(HTTP ${response.status})`; + const text = await response.text().catch(() => ""); + if (!text) return context; + try { + const payload = JSON.parse(text) as { detail?: unknown; error?: unknown }; + const detail = payload.detail ?? payload.error; + if (typeof detail === "string" && detail.trim()) return detail.trim(); + if ( + detail && + typeof detail === "object" && + "message" in detail && + typeof (detail as { message?: unknown }).message === "string" + ) { + return (detail as { message: string }).message.trim() || context; + } + } catch { + // The Studio fallback route may be served by an older deployment. + } + return context; +} + export async function listCronJobs(signal?: AbortSignal): Promise { const response = await apiFetch(cronJobPath(), { signal }); if (!response.ok) { - throw new Error(await httpErrorMessage(response, "加载定时任务失败")); + throw new Error(await cronJobErrorMessage(response, "加载定时任务失败")); } const data = (await response.json()) as CronJobListResponse | CronJob[]; return Array.isArray(data) ? data : data.items ?? []; @@ -3252,7 +3277,7 @@ export async function getCronJob( ): Promise { const response = await apiFetch(cronJobPath(jobId), { signal }); if (!response.ok) { - throw new Error(await httpErrorMessage(response, "加载定时任务详情失败")); + throw new Error(await cronJobErrorMessage(response, "加载定时任务详情失败")); } return (await response.json()) as CronJob; } @@ -3264,7 +3289,7 @@ export async function createCronJob(input: CronJobInput): Promise { body: JSON.stringify(input), }); if (!response.ok) { - throw new Error(await httpErrorMessage(response, "创建定时任务失败")); + throw new Error(await cronJobErrorMessage(response, "创建定时任务失败")); } return (await response.json()) as CronJob; } @@ -3279,7 +3304,7 @@ export async function updateCronJob( body: JSON.stringify(input), }); if (!response.ok) { - throw new Error(await httpErrorMessage(response, "更新定时任务失败")); + throw new Error(await cronJobErrorMessage(response, "更新定时任务失败")); } return (await response.json()) as CronJob; } @@ -3294,7 +3319,7 @@ export async function setCronJobEnabled( }); if (!response.ok) { throw new Error( - await httpErrorMessage(response, enabled ? "启用定时任务失败" : "暂停定时任务失败"), + await cronJobErrorMessage(response, enabled ? "启用定时任务失败" : "暂停定时任务失败"), ); } return (await response.json()) as CronJob; @@ -3303,7 +3328,7 @@ export async function setCronJobEnabled( export async function runCronJobNow(jobId: string): Promise { const response = await apiFetch(`${cronJobPath(jobId)}/run`, { method: "POST" }); if (!response.ok) { - throw new Error(await httpErrorMessage(response, "立即执行定时任务失败")); + throw new Error(await cronJobErrorMessage(response, "立即执行定时任务失败")); } return (await response.json()) as CronJobRun; } @@ -3314,7 +3339,7 @@ export async function listCronJobRuns( ): Promise { const response = await apiFetch(`${cronJobPath(jobId)}/runs`, { signal }); if (!response.ok) { - throw new Error(await httpErrorMessage(response, "加载执行历史失败")); + throw new Error(await cronJobErrorMessage(response, "加载执行历史失败")); } const data = (await response.json()) as CronJobRunListResponse | CronJobRun[]; return Array.isArray(data) ? data : data.items ?? []; @@ -3329,7 +3354,7 @@ export async function cancelCronJobRun( { method: "POST" }, ); if (!response.ok) { - throw new Error(await httpErrorMessage(response, "终止执行失败")); + throw new Error(await cronJobErrorMessage(response, "终止执行失败")); } return (await response.json()) as CronJobRun; } @@ -3337,7 +3362,7 @@ export async function cancelCronJobRun( export async function deleteCronJob(jobId: string): Promise { const response = await apiFetch(cronJobPath(jobId), { method: "DELETE" }); if (!response.ok) { - throw new Error(await httpErrorMessage(response, "删除定时任务失败")); + throw new Error(await cronJobErrorMessage(response, "删除定时任务失败")); } } diff --git a/frontend/src/automations/website-integration/WebsiteIntegration.css b/frontend/src/automations/website-integration/WebsiteIntegration.css index d7c832eff..856b9f2c8 100644 --- a/frontend/src/automations/website-integration/WebsiteIntegration.css +++ b/frontend/src/automations/website-integration/WebsiteIntegration.css @@ -28,13 +28,12 @@ .website-integration-section-heading h2 { margin: 0; font-size: 14px; font-weight: 650; line-height: 1.4; } .website-integration-section-heading > small { color: hsl(var(--muted-foreground)); font-size: 11px; } -.website-integration-form { display: grid; grid-template-columns: minmax(200px, 1.2fr) minmax(220px, 1fr) auto; align-items: end; gap: 8px 12px; } -.website-integration-form > label { color: hsl(var(--muted-foreground)); font-size: 12px; font-weight: 600; line-height: 1.4; } -.website-integration-form > label:first-child { grid-column: 1; } -.website-integration-form > label:nth-of-type(2) { grid-column: 2; } -.website-integration-form > [id="website-runtime"] { grid-column: 1; grid-row: 2; } -.website-integration-form > input { grid-column: 2; grid-row: 2; } -.website-integration-form > button { grid-column: 3; grid-row: 2; min-width: 104px; } +.website-integration-form { display: grid; grid-template-columns: minmax(240px, 1.2fr) minmax(240px, 1fr) auto; align-items: end; gap: 12px; } +.website-integration-field { min-width: 0; display: flex; flex-direction: column; gap: 8px; } +.website-integration-field > label { color: hsl(var(--muted-foreground)); font-size: 12px; font-weight: 600; line-height: 1.4; } +.website-integration-field > input { width: 100%; } +.website-integration-form-action { display: flex; align-items: flex-end; } +.website-integration-form-action > button { min-width: 104px; } .website-integration-error { margin-top: 12px; padding: 9px 11px; border: 1px solid hsl(var(--destructive) / 0.22); border-radius: 8px; background: hsl(var(--destructive) / 0.05); color: hsl(var(--destructive)); font-size: 12px; line-height: 1.5; } .website-integration-loading { min-height: 96px; display: grid; place-items: center; color: hsl(var(--muted-foreground)); font-size: 12.5px; } @@ -61,13 +60,7 @@ @media (max-width: 820px) { .website-integration-page { padding: 20px 18px 0; } .website-integration-form { grid-template-columns: minmax(0, 1fr); } - .website-integration-form > label, - .website-integration-form > label:first-child, - .website-integration-form > label:nth-of-type(2), - .website-integration-form > [id="website-runtime"], - .website-integration-form > input, - .website-integration-form > button { grid-column: 1; grid-row: auto; } - .website-integration-form > label:nth-of-type(2) { margin-top: 4px; } + .website-integration-form-action > button { width: 100%; } .website-integration-row { grid-template-columns: minmax(0, 1fr) auto; } .website-integration-token, .website-integration-created { display: none; } .website-integration-embed { grid-template-columns: minmax(0, 1fr); } diff --git a/frontend/src/automations/website-integration/WebsiteIntegration.tsx b/frontend/src/automations/website-integration/WebsiteIntegration.tsx index 17daa184c..8c5c00cf7 100644 --- a/frontend/src/automations/website-integration/WebsiteIntegration.tsx +++ b/frontend/src/automations/website-integration/WebsiteIntegration.tsx @@ -192,39 +192,46 @@ export function WebsiteIntegration({ onBack }: WebsiteIntegrationProps) {
- - setDomain(event.target.value)} - placeholder="例如 xxxx.com 或 localhost:5173" - autoComplete="off" - disabled={submitting} - size="lg" - /> - +
+ + setDomain(event.target.value)} + placeholder="例如 xxxx.com 或 localhost:5173" + autoComplete="off" + disabled={submitting} + size="lg" + /> +
+
+ +
{error ?
{error}
: null} diff --git a/frontend/src/ui/Composer.tsx b/frontend/src/ui/Composer.tsx index 8315bdb90..52564b36d 100644 --- a/frontend/src/ui/Composer.tsx +++ b/frontend/src/ui/Composer.tsx @@ -159,7 +159,9 @@ export interface ComposerProps { onModeChange?: (value: NewChatMode) => void; onTaskChange?: (value: NewChatTask | null) => void; temporaryEnabled?: boolean; + temporaryUnavailableReason?: string; deepseekHarnessEnabled?: boolean; + deepseekHarnessUnavailableReason?: string; harnessEnabled?: boolean; builtinTools?: readonly string[]; showAgentPicker?: boolean; @@ -213,7 +215,9 @@ export function Composer({ onModeChange, onTaskChange, temporaryEnabled, + temporaryUnavailableReason, deepseekHarnessEnabled, + deepseekHarnessUnavailableReason, harnessEnabled = false, builtinTools = [], showAgentPicker = false, @@ -755,7 +759,9 @@ export function Composer({ onChange={onModeChange} disabled={busy} temporaryEnabled={temporaryEnabled} + temporaryUnavailableReason={temporaryUnavailableReason} deepseekHarnessEnabled={deepseekHarnessEnabled} + deepseekHarnessUnavailableReason={deepseekHarnessUnavailableReason} /> ) : null} diff --git a/frontend/src/ui/new-chat-modes/NewChatAgentPicker.tsx b/frontend/src/ui/new-chat-modes/NewChatAgentPicker.tsx index a531bb835..bf04324e0 100644 --- a/frontend/src/ui/new-chat-modes/NewChatAgentPicker.tsx +++ b/frontend/src/ui/new-chat-modes/NewChatAgentPicker.tsx @@ -422,7 +422,9 @@ export function NewChatAgentPicker({ aria-haspopup="menu" aria-expanded={activeType === type.id} className={`new-chat-agent-picker__type${keyboardNavigating && keyboardPanel === "types" && activeTypeIndex === index ? " is-keyboard-active" : ""}`} - onMouseEnter={() => activateType(index)} + onMouseEnter={() => { + if (window.innerWidth > 640) activateType(index); + }} onClick={() => { activateType(index); setKeyboardPanel("runtimes"); diff --git a/frontend/src/ui/new-chat-modes/NewChatModeSelector.tsx b/frontend/src/ui/new-chat-modes/NewChatModeSelector.tsx index 9fc986d54..b6d2bf369 100644 --- a/frontend/src/ui/new-chat-modes/NewChatModeSelector.tsx +++ b/frontend/src/ui/new-chat-modes/NewChatModeSelector.tsx @@ -59,7 +59,9 @@ export interface NewChatModeSelectorProps { onChange: (value: NewChatMode) => void; disabled?: boolean; temporaryEnabled?: boolean; + temporaryUnavailableReason?: string; deepseekHarnessEnabled?: boolean; + deepseekHarnessUnavailableReason?: string; } function ModeIcon({ mode }: { mode: NewChatMode }) { @@ -92,7 +94,9 @@ export function NewChatModeSelector({ onChange, disabled = false, temporaryEnabled, + temporaryUnavailableReason, deepseekHarnessEnabled, + deepseekHarnessUnavailableReason, }: NewChatModeSelectorProps) { const [open, setOpen] = useState(false); const [builtinOpen, setBuiltinOpen] = useState(false); @@ -125,10 +129,21 @@ export function NewChatModeSelector({ function modeDescription(mode: ModeOption): string { const enabled = modeEnabled(mode); if (enabled === undefined) return "正在检查配置"; - if (!enabled) return "管理员未配置"; + if (!enabled) { + return [temporaryUnavailableReason, deepseekHarnessUnavailableReason] + .filter((reason): reason is string => Boolean(reason)) + .join(";") || "管理员未配置可用的 Sandbox"; + } return mode.description; } + function builtinUnavailableReason(mode: NewChatMode): string { + if (mode === "temporary") { + return temporaryUnavailableReason || "管理员未配置 Codex Sandbox"; + } + return deepseekHarnessUnavailableReason || "管理员未配置 DeepSeek Harness Sandbox"; + } + useEffect(() => { if (!open) return; const close = (event: MouseEvent) => { @@ -287,7 +302,7 @@ export function NewChatModeSelector({ ? "正在检查配置" : enabled ? agent.description - : "管理员未配置"} + : builtinUnavailableReason(agent.value)} diff --git a/frontend/src/ui/new-chat-modes/new-chat-agent-picker.css b/frontend/src/ui/new-chat-modes/new-chat-agent-picker.css index 06934a8f1..3b268955a 100644 --- a/frontend/src/ui/new-chat-modes/new-chat-agent-picker.css +++ b/frontend/src/ui/new-chat-modes/new-chat-agent-picker.css @@ -198,7 +198,17 @@ } @media (max-width: 640px) { + .composer--new-chat .composer-box:has(.new-chat-agent-picker__trigger[aria-expanded="true"]) { + z-index: 50; + } + + .composer--new-chat .new-chat-agent-picker { + z-index: 50; + } + .new-chat-agent-picker__menus { + top: auto; + bottom: calc(100% + 7px); width: min(320px, calc(100vw - 88px)); max-height: min(420px, calc(100dvh - 168px)); flex-direction: column; diff --git a/frontend/tests/applications.test.mjs b/frontend/tests/applications.test.mjs index d4ee52c14..53b4ec751 100644 --- a/frontend/tests/applications.test.mjs +++ b/frontend/tests/applications.test.mjs @@ -66,6 +66,10 @@ const websiteIntegrationSource = readFileSync( new URL("../src/automations/website-integration/WebsiteIntegration.tsx", import.meta.url), "utf8", ); +const websiteIntegrationPanelStyles = readFileSync( + new URL("../src/automations/website-integration/WebsiteIntegration.css", import.meta.url), + "utf8", +); const websiteIntegrationApiSource = readFileSync( new URL("../src/adk/websiteIntegration.ts", import.meta.url), "utf8", @@ -277,6 +281,12 @@ test("Website integration creates an Origin-bound embed token and chat loader", assert.match(websiteIntegrationSource, /AgentKit Runtime/); assert.match(websiteIntegrationSource, /引入方法/); assert.match(websiteIntegrationSource, /CopyButton/); + assert.match(websiteIntegrationSource, /@openai\/apps-sdk-ui\/components\/Select/); + assert.match(websiteIntegrationSource, /@openai\/apps-sdk-ui\/components\/Input/); + assert.match(websiteIntegrationSource, /className="website-integration-field"[\s\S]*?");return e},D0t=({label:e})=>o.jsx(o.Fragment,{children:e}),P0t=({label:e})=>o.jsx(o.Fragment,{children:e}),M0t=({values:e,selectedAll:t})=>{const n=t?"All selected":e.length===0?"Select...":e.length===1?e[0].label:`${e.length} selected`;return o.jsx(o.Fragment,{children:n})},nT=e=>{const{id:t,required:n,value:i,name:r,multiple:s,variant:a="outline",size:l="md",dropdownIconType:c="dropdown",loading:u=!1,clearable:d=!1,disabled:f=!1,placeholder:h="Select...",loadingPlaceholder:p="Loading...",pill:b=!0,listWidth:g,options:O,actions:y=[],side:v="bottom",avoidCollisions:x=!0,onChange:w,optionClassName:E,OptionView:S=D0t,TriggerStartIcon:k,triggerClassName:T,opticallyAlign:_,TriggerView:C,searchPlaceholder:N="",searchPredicate:I=G0t,searchEmptyMessage:B="No results found.",listMaxWidth:D="auto"}=e,L=e.block??a!=="ghost",j=e.align??(L?"center":"start"),P=e.alignOffset??(j==="center"?0:-5),M=e.listMinWidth??(L?"auto":300),U=x2((ee,de)=>{if(s){if(!ee.value){w([]);return}if(de){const Oe=i.filter(Ie=>Ie!==ee.value),Ne=z3(O,Oe);w(Ne)}else{const Oe=z3(O,i);w(Oe.concat(ee))}}else w(ee)}),$=m.useRef(I);$.current=I;const G=m.useMemo(()=>y,[y.length]),z=m.useRef(y);z.current=y;const F=m.useCallback(ee=>{var de;(de=z.current.find(Oe=>Oe.id===ee))==null||de.onSelect(ee)},[]),q=m.useMemo(()=>U9(O)?O.reduce((ee,de)=>ee+de.options.length,0):O.length,[O]),ce=`select-trigger-${m.useId()}`,be=q>15,ue=m.useMemo(()=>s?{multiple:!0,value:i,TriggerView:C??M0t}:{multiple:!1,value:i,TriggerView:C??P0t},[s,i,C]),K=m.useMemo(()=>({...ue,triggerId:ce,id:t,name:r,required:n,options:O,placeholder:h,loadingPlaceholder:p,loading:u,clearable:d,variant:a,pill:b,size:l,dropdownIconType:c,block:L,align:j,alignOffset:P,side:v,avoidCollisions:x,listWidth:g,listMinWidth:M,listMaxWidth:D,searchPlaceholder:N,searchEmptyMessage:B,TriggerStartIcon:k,triggerClassName:T,opticallyAlign:_,optionClassName:E,OptionView:S,actions:G,onActionSelect:F,onSelectRef:U,searchPredicateRef:$,searchable:be,disabled:f}),[ue,ce,t,n,r,O,h,p,u,d,a,b,l,c,L,j,P,v,x,g,M,D,N,B,k,T,_,E,S,G,F,U,be,f]);return o.jsx(K0e.Provider,{value:K,children:o.jsx($0t,{})})},L0t=e=>{const{triggerId:t,id:n,required:i,value:r,multiple:s,options:a,loading:l,disabled:c,clearable:u,name:d,variant:f,pill:h,size:p,dropdownIconType:b,placeholder:g,loadingPlaceholder:O,block:y,opticallyAlign:v,triggerClassName:x,TriggerStartIcon:w,TriggerView:E,onSelectRef:S}=ep(),{onOpenChange:k,...T}=e,_=s?r[0]:r,C=l?O:g,N=m.useMemo(()=>W0t(a,_)||{value:"",label:C},[_,a,C]),I=s?r.length>0:!!r,B=l||!I,D=m.useMemo(()=>rbe(),[]),L=m.useMemo(()=>{if(!s)return{values:[],selectedAll:!1};const M=z3(a,r),U=a.flatMap($=>"options"in $?$.options:$);return{values:M.length?M:[{value:"",label:C}],selectedAll:U.length<=r.length}},[s,a,r,C]),j=M=>{const U=M.key;if(!s&&sbe(U)){const $=D(U);M.stopPropagation();const G=abe(a,$,_);G&&S.current(G)}},P=()=>{S.current({value:"",label:""}),k==null||k(!1)};return o.jsxs(m0t,{id:t,className:x,selected:!B,variant:f,pill:h,block:y,size:p,disabled:c,loading:l,StartIcon:w,opticallyAlign:v,dropdownIconType:b,onClearClick:u?P:void 0,onInteract:k,onKeyDown:j,...T,children:[s?o.jsx(E,{...L}):o.jsx(E,{...N}),(d||n)&&o.jsx("input",{id:n,name:d,value:_,tabIndex:-1,onFocus:()=>{var M;(M=document.getElementById(t))==null||M.focus()},onChange:()=>{},required:i,className:"sr-only w-full h-0 left-0 bottom-0 pointer-events-none","aria-hidden":"true"})]})},$0t=()=>{const{triggerId:e,loading:t,side:n,align:i,alignOffset:r,avoidCollisions:s,listWidth:a,listMinWidth:l,listMaxWidth:c}=ep(),[u,d]=m.useState(!1),f=m.useRef(null),h=p=>{const b=p===void 0?!u:p;d(b),b||setTimeout(()=>{var O;if(!f.current)return;const g=document.activeElement;g&&!f.current.contains(g)||(O=document.getElementById(e))==null||O.focus()})};return v6(u,()=>{h(!1)}),o.jsxs(gle,{open:u,onOpenChange:p=>{t&&p||h(p)},modal:!1,children:[o.jsx(ble,{asChild:!0,children:o.jsx(L0t,{onOpenChange:h})}),o.jsx(Ole,{forceMount:!0,children:o.jsx(CA,{className:or.Menu,enterDuration:350,exitDuration:200,disableAnimations:!0,children:u&&o.jsx(yle,{ref:f,forceMount:!0,className:or.MenuList,side:n,sideOffset:5,align:i,alignOffset:r,avoidCollisions:s,collisionPadding:{bottom:30,top:30},onOpenAutoFocus:cm,onCloseAutoFocus:cm,onEscapeKeyDown:cm,style:tw({"select-list-width":a,"select-list-min-width":l,"select-list-max-width":c}),children:o.jsx(B0t,{onOpenChange:h})},"dropdown")})})]})},J0e=m.createContext(null),LO=()=>{const e=m.use(J0e);if(!e)throw new Error("CustomSelectMenu components must be wrapped in ");return e},B0t=({onOpenChange:e})=>{const{multiple:t,value:n,options:i,searchable:r,searchPredicateRef:s}=ep(),a=m.useRef(()=>e(!1)),l=m.useRef(null),c=m.useRef(null),u=m.useRef(null),[d,f]=m.useState(""),[h,p]=m.useState(()=>{var _;return((t?n[0]:n)||((_=UE(i))==null?void 0:_.value))??""}),b=m.useMemo(()=>rbe(),[]),O=`select-list-${m.useId()}`,y=m.useRef(t?"":n),v=m.useMemo(()=>d.trim().toLocaleLowerCase(),[d]),x=m.useMemo(()=>Y0t(i,v,s.current),[i,v,s]),w=m.useMemo(()=>UE(x),[x]),E=m.useRef(!1),S=T=>{const _=T.key,C=t?n[0]:n,N=h||(w==null?void 0:w.value)||C,I=document.activeElement===u.current,B=l.current;if(!B)return;const D=()=>{const P=new PointerEvent("pointerup",{bubbles:!0,cancelable:!0,pointerType:"mouse"}),M=ud(h,B);M==null||M.dispatchEvent(P)},L=(P,M)=>{p(P),M.scrollIntoView({block:"nearest"})},j=()=>{const P=t?n[0]:n;if(P){const U=ud(P,B);if(U){L(P,U);return}}const M=UE(i);if(M){const U=ud(M.value,B);U&&L(M.value,U)}};switch(_){case"ArrowDown":{if(T.preventDefault(),!h||!ud(h,B)){j();return}const P=Z0t(h,B),M=P==null?void 0:P.getAttribute("data-option-id");P&&M&&L(M,P);return}case"ArrowUp":{if(T.preventDefault(),!h||!ud(h,B)){j();return}const P=K0t(N,B),M=P==null?void 0:P.getAttribute("data-option-id");P&&M&&L(M,P);return}case"Enter":T.preventDefault(),D();return;case" ":if(v&&I)return;T.preventDefault(),D();return}if(sbe(_)){if(I)return;const P=b(_);T.stopPropagation();const M=abe(i,P,h);if(M){const U=ud(M.value,B);U&&(p(M.value),U.scrollIntoView({block:"nearest"}))}}},k=m.useMemo(()=>({valueRef:y,listId:O,highlightedValue:h,setHighlightedValue:p,requestCloseRef:a,searchTerm:d,setSearchTerm:f,searchInputRef:u,listRef:c}),[O,h,p,d,f]);return m.useEffect(()=>{p2(()=>{if(!l.current)return;const _=ud(h,l.current);_==null||_.scrollIntoView({block:"center"})});const T=u.current||l.current;return T==null||T.focus({preventScroll:!0}),()=>{E.current=!1}},[]),m.useLayoutEffect(()=>{if(!E.current){E.current=!0;return}if(!c.current)return;c.current.scrollTop=0;const T=UE(x);T&&p(T.value)},[x]),o.jsx(J0e,{value:k,children:o.jsxs("div",{id:O,className:or.MenuInner,onKeyDown:S,ref:l,tabIndex:0,children:[r&&o.jsx(Q0t,{value:d,onChange:f}),o.jsx(F0t,{filteredOptions:x}),o.jsx(H0t,{})]})})},Q0t=({value:e,onChange:t})=>{const{searchPlaceholder:n}=ep(),{listId:i,searchInputRef:r}=LO(),s=a=>{t(a.target.value)};return o.jsx("div",{className:or.Search,children:o.jsx(Fp,{startAdornment:o.jsx(x2e,{width:16,height:16,className:"fill-secondary"}),ref:r,value:e,placeholder:n,onChange:s,autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-controls":i,"aria-expanded":!0})})},Rw=e=>"options"in e,U9=e=>e[0]&&Rw(e[0]),eb=300,F0t=({filteredOptions:e})=>{const{searchEmptyMessage:t}=ep(),{listRef:n}=LO();if(!e.length)return typeof t=="string"?o.jsx("p",{className:or.SearchEmpty,"data-text-only":!0,children:t}):o.jsx("div",{className:or.SearchEmpty,children:t});const i=U9(e),r=!i&&e.length>eb,s=i?e.map(a=>o.jsx(z0t,{...a},a.label)):e.slice(0,eb).map(a=>o.jsx(tbe,{...a},a.value));return o.jsxs("div",{className:or.OptionsList,ref:n,children:[s,r&&o.jsx(ebe,{numHidden:e.length-eb})]})},U0t={limit:100,label:"Show all"},z0t=({label:e,options:t,optionsLimit:n=U0t})=>{const i=m.useId(),{searchTerm:r,setHighlightedValue:s}=LO(),[a,l]=m.useState(!1),c=n.limit{l(!0),s(t[n.limit].value)};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:or.OptionGroupHeading,children:[o.jsx("div",{className:or.OptionIndicatorSlot}),e]}),d.map(h=>o.jsx(tbe,{...h},h.value)),c&&o.jsx(V0t,{value:`group-limit-${i}`,label:n.label,onPointerUp:f}),u&&o.jsx(ebe,{numHidden:t.length-eb})]})},ebe=({numHidden:e})=>o.jsxs("div",{className:or.OptionHardLimitHeading,children:[o.jsx("div",{className:or.OptionIndicatorSlot}),`…and ${e.toLocaleString()} more options. Use search to refine results further.`]}),V0t=({value:e,label:t,onPointerUp:n})=>{const{highlightedValue:i,setHighlightedValue:r}=LO(),s=e===i,a=()=>{s||r(e)},l=()=>{r(c=>c!==e?c:"")};return o.jsx("div",{className:Ii(or.Option,or.OptionsLimit),"data-option-id":e,"data-highlight":s?"":void 0,role:"option","aria-selected":s,onPointerUp:n,onPointerMove:a,onPointerLeave:l,children:o.jsxs("div",{className:Ii(or.PressableInner,or.OptionInner),children:[o.jsx("div",{className:or.OptionIndicatorSlot}),t]})})},q0t="data-option-id",tbe=e=>{const{optionClassName:t,OptionView:n,value:i,multiple:r,onSelectRef:s}=ep(),{valueRef:a,requestCloseRef:l,highlightedValue:c,setHighlightedValue:u}=LO(),{value:d,disabled:f,tooltip:h}=e,p=a.current,b=r?i.includes(d):d===p,g=d===c,O=()=>{var x;r?s.current(e,b):(s.current(e),(x=l.current)==null||x.call(l))},y=()=>{g||u(d)},v=()=>{u(x=>x!==d?x:"")};return o.jsx("div",{className:Ii(or.Option,t),"data-highlight":g?"":void 0,role:"option","aria-selected":g,"data-selected":b?"":void 0,[q0t]:d,onPointerUp:f?void 0:O,onPointerMove:f?void 0:y,onPointerLeave:f?void 0:v,"aria-disabled":f,"data-disabled":f?"":void 0,children:o.jsxs("div",{className:or.PressableInner,children:[o.jsxs("div",{className:or.OptionInner,children:[o.jsx("div",{className:or.OptionIndicatorSlot,children:b&&o.jsx(Q4,{className:or.OptionCheck})}),o.jsx(n,{...e}),h&&o.jsx(al,{content:h.content,maxWidth:h.maxWidth,side:"right",children:o.jsx(xne,{})})]}),e.description&&o.jsxs("div",{className:or.OptionInner,children:[o.jsx("div",{className:or.OptionIndicatorSlot}),e.description]})]})})},H0t=()=>{const{actions:e}=ep();return e.length===0?null:o.jsx("div",{className:or.ActionsContainer,children:e.map(t=>o.jsx(X0t,{...t},t.id))})},X0t=({id:e,label:t,Icon:n,className:i})=>{const{onActionSelect:r}=ep(),{requestCloseRef:s}=LO(),a=c=>{switch(c.key){case"Tab":break;case"Enter":case" ":c.stopPropagation(),l();break;default:c.stopPropagation()}},l=()=>{var c;r(e),(c=s.current)==null||c.call(s)};return o.jsx("div",{className:or.Action,onPointerUp:l,onKeyDown:a,tabIndex:0,children:o.jsxs("div",{className:Ii(or.ActionInner,i),children:[n&&o.jsx(n,{role:"presentation"}),t]})})},G0t=(e,t)=>e.label.toLowerCase().includes(t),Y0t=(e,t,n)=>{const i=t.trim().toLocaleLowerCase();if(!i)return e;const r=s=>n(s,i);return U9(e)?e.reduce((s,a)=>{const l=a.options.filter(r);return l.length&&s.push({...a,options:l}),s},[]):e.reduce((s,a)=>(r(a)&&s.push(a),s),[])},UE=e=>{if(!e.length)return;let t;for(const n of e)if(Rw(n)){const i=n.options.find(r=>!r.disabled);if(i){t=i;break}}else if(!n.disabled){t=n;break}return t},W0t=(e,t)=>{let n;for(const i of e)if(Rw(i)){const r=i.options.find(s=>s.value===t);if(r){n=r;break}}else if(i.value===t){n=i;break}return n},z3=(e,t)=>{let n=[];const i=new Set(t);for(const r of e)if(Rw(r)){const s=r.options.filter(a=>i.has(a.value));n=n.concat(s)}else i.has(r.value)&&n.push(r);return n},nbe=40,ud=(e,t)=>t.querySelector(`[data-option-id="${e}"]`),ibe=e=>e.matches("[data-option-id]:not([data-disabled])"),Z0t=(e,t)=>{const n=ud(e,t);let i=n==null?void 0:n.nextElementSibling,r=0;for(;i&&r{const n=ud(e,t);let i=n==null?void 0:n.previousElementSibling,r=0;for(;i&&r{let e="",t;return n=>(n=n.toLowerCase(),e+=n,t&&clearTimeout(t),t=setTimeout(()=>{e=""},500),n.repeat(e.length)===e?n:e)},sbe=e=>/^[a-zA-Z0-9]$/.test(e),abe=(e,t,n)=>{if(!e.length)return;let i,r,s=!n;const a=({disabled:l,label:c,value:u})=>u===n?(s=!0,!1):!l&&c.toLowerCase().startsWith(t);for(const l of e)if(Rw(l)){for(const c of l.options)if(a(c))if(s){r=c;break}else i=i||c}else if(a(l))if(s){r=l;break}else i=i||l;return r||i},J0t="_Container_1bl61_1",ebt="_Track_1bl61_16",tbt="_Thumb_1bl61_56",nbt="_Label_1bl61_78",zE={Container:J0t,Track:ebt,Thumb:tbt,Label:nbt},ibt=({className:e,label:t,id:n,disabled:i,labelPosition:r="end",...s})=>{const a=m.useId(),l=n??a;return o.jsxs("div",{className:Ii(zE.Container,e),"data-disabled":i?"":void 0,"data-has-label":t?"":void 0,"data-label-position":r,children:[o.jsx(uBe,{id:l,className:zE.Track,disabled:i,...s,children:o.jsx(fBe,{className:zE.Thumb})}),t&&o.jsx("label",{htmlFor:l,className:zE.Label,children:t})]})},rbt="_Container_13560_1",sbt="_Textarea_13560_174",qY={Container:rbt,Textarea:sbt},obe=e=>{const t=m.useRef(null),i=`search-ui-input-${m.useId()}`,{id:r,name:s,variant:a="outline",size:l="md",gutterSize:c,className:u,autoComplete:d,disabled:f=!1,readOnly:h=!1,invalid:p=!1,allowAutofillExtensions:b=!!s,onFocus:g,onBlur:O,onAnimationStart:y,onAutofill:v,autoSelect:x,rows:w=3,maxRows:E,autoResize:S,ref:k,onChange:T,..._}=e,[C,N]=m.useState(!1),I=S?Math.max(E??10,w):w;m.useEffect(()=>{var L;x&&((L=t.current)==null||L.select())},[x]);const B=L=>{y==null||y(L),L.animationName==="native-autofill-in"&&(v==null||v())},D=m.useCallback(()=>{if(!S||!t.current||I===void 0)return;t.current.style.height="0px";const L=t.current.scrollHeight;t.current.style.height=L+"px"},[S,I]);return m.useEffect(()=>{D()},[e.value,w,D]),o.jsx("div",{className:Ii(qY.Container,u),"data-variant":a,"data-size":l,"data-gutter-size":c,"data-focused":C,"data-disabled":f?"":void 0,"data-readonly":h?"":void 0,"data-invalid":p?"":void 0,style:tw({"textarea-min-rows":`${w}`,"textarea-max-rows":`${I}`}),children:o.jsx("textarea",{..._,onChange:L=>{T==null||T(L),D()},ref:ew([t,k]),id:r||(b?void 0:i),className:qY.Textarea,name:s,readOnly:h,disabled:f,rows:w,onFocus:L=>{N(!0),g==null||g(L)},onBlur:L=>{N(!1),O==null||O(L)},onAnimationStart:B,"data-lpignore":b?void 0:!0,"data-1p-ignore":b?void 0:!0})})};function kv({message:e,className:t="",onRetry:n,retryLabel:i="重试部署",defaultExpanded:r=!0}){const[s,a]=m.useState(r),[l,c]=m.useState(!1),u=async()=>{if(!(!n||l)){c(!0);try{await n()}finally{c(!1)}}};return o.jsxs("div",{className:`deploy-error-message${s?" is-expanded":""}${t?` ${t}`:""}`,role:"alert",children:[o.jsx("p",{className:"deploy-error-message-text",children:e}),o.jsxs("div",{className:"deploy-error-message-actions",children:[n&&o.jsxs(Cn,{type:"button",className:"deploy-error-retry",color:"danger",variant:"soft",size:"sm",pill:!1,loading:l,onClick:()=>void u(),children:[!l&&o.jsx(c2e,{}),l?"重试中…":i]}),o.jsx(Cn,{type:"button",color:"secondary",variant:"ghost",size:"sm",uniform:!0,pill:!1,title:s?"收起错误信息":"展开完整错误信息","aria-label":s?"收起错误信息":"展开完整错误信息",onClick:()=>a(d=>!d),children:s?o.jsx(h2e,{}):o.jsx(m2e,{})}),o.jsx(Lae,{copyValue:e,color:"secondary",variant:"ghost",size:"sm",uniform:!0,pill:!1,title:"复制完整错误信息","aria-label":"复制完整错误信息",children:({copied:d})=>d?o.jsx(Q4,{}):o.jsx(One,{})})]})]})}const abt={queued:"已排队",pending:"准备中",running:"执行中",retrying:"自动重试中",success:"成功",failed:"失败",cancelled:"已取消",skipped:"已跳过"},lbe=["周日","周一","周二","周三","周四","周五","周六"];function y_(e){if(!e)return"-";const t=new Date(e);return Number.isNaN(t.getTime())?e:new Intl.DateTimeFormat("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}).format(t).replace(/\//g,"-")}function obt(e){if(!e.startedAt)return"-";const t=Date.parse(e.startedAt),n=e.finishedAt?Date.parse(e.finishedAt):Date.now();if(!Number.isFinite(t)||!Number.isFinite(n)||n{const u=n.current;!u||i.current||l(u.scrollHeight>u.clientHeight+1)},[]);return m.useLayoutEffect(()=>{i.current=r,r||c()},[r,c,e]),m.useEffect(()=>{const u=n.current;if(!u||typeof ResizeObserver>"u")return;const d=new ResizeObserver(c);return d.observe(u),()=>d.disconnect()},[c]),o.jsxs("div",{className:`cronjobs-run-output-body${r?" is-expanded":""}`,children:[o.jsx("p",{id:t,ref:n,children:e}),a?o.jsx(Cn,{type:"button",className:"cronjobs-run-output-toggle",color:"secondary",variant:"ghost",size:"sm",pill:!1,"aria-expanded":r,"aria-controls":t,onClick:()=>s(u=>!u),children:r?"收起":"展开"}):null]})}const q3="Asia/Shanghai",cbt=3e3,ubt=["Asia/Shanghai","Asia/Singapore","Asia/Tokyo","Europe/London","America/Los_Angeles","America/New_York","UTC"];function dbt(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||q3}catch{return q3}}function fbt(){const e=dbt(),t=new Date(Date.now()+24*60*60*1e3);return t.setSeconds(0,0),{name:"",runtimeId:"",prompt:"",scheduleType:"daily",onceAt:new Date(t.getTime()-t.getTimezoneOffset()*6e4).toISOString().slice(0,16),time:"09:00",weekday:1,cron:"0 9 * * *",timezone:e,enabled:!0}}function hbt(e){return{name:e.name,runtimeId:e.runtimeId,prompt:e.prompt,scheduleType:e.schedule.type,onceAt:e.schedule.onceAt??"",time:e.schedule.time??"09:00",weekday:e.schedule.weekday??1,cron:e.schedule.cron??"0 9 * * *",timezone:e.schedule.timezone||q3,enabled:e.enabled}}function cbe({run:e}){const t=e?e.status==="success"?"success":e.status==="failed"?"danger":["queued","pending","running","retrying"].includes(e.status)?"info":"secondary":"secondary";return o.jsx(uO,{className:"cronjobs-status",color:t,variant:"soft",size:"sm",pill:!0,children:e?abt[e.status]:"尚未执行"})}function HY({job:e,runtimes:t,cloudProvider:n,busy:i,onClose:r,onSubmit:s}){const[a,l]=m.useState(()=>e?hbt(e):fbt()),[c,u]=m.useState(""),[d,f]=m.useState(!1),h=m.useRef(null),p=m.useRef(null),b=m.useRef(null),g=i||d,O=m.useRef(g),y=m.useRef(r),v=m.useMemo(()=>Array.from(new Set([a.timezone,...ubt])),[a.timezone]),x=m.useMemo(()=>t.map(k=>({value:k.runtimeId,label:k.name,description:_c(k.region,n)})),[n,t]),w=m.useMemo(()=>lbe.map((k,T)=>({value:String(T),label:k})),[]),E=m.useMemo(()=>v.map(k=>({value:k,label:k})),[v]);m.useEffect(()=>{O.current=g,y.current=r},[g,r]),m.useEffect(()=>{var C;const k=document.body.style.overflow,T=document.activeElement instanceof HTMLElement?document.activeElement:null;document.body.style.overflow="hidden",(C=p.current)==null||C.focus();const _=N=>{var j,P;if(N.key==="Escape"&&!O.current){y.current();return}if(N.key!=="Tab")return;const I=Array.from(((j=h.current)==null?void 0:j.querySelectorAll('button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))??[]).filter(M=>!M.hidden&&M.getClientRects().length>0);if(I.length===0){N.preventDefault();return}const B=I[0],D=I[I.length-1],L=document.activeElement;N.shiftKey&&(L===B||!((P=h.current)!=null&&P.contains(L)))?(N.preventDefault(),D.focus()):!N.shiftKey&&L===D&&(N.preventDefault(),B.focus())};return window.addEventListener("keydown",_),()=>{document.body.style.overflow=k,window.removeEventListener("keydown",_),T!=null&&T.isConnected&&T.focus()}},[]);const S=async k=>{k.preventDefault();const T=a.name.trim(),_=a.prompt.trim(),C=t.find(I=>I.runtimeId===a.runtimeId);if(!T)return u("请输入任务名称。");if(!C)return u("请选择可用的 Runtime Agent。");if(!_)return u("请输入每次执行时发送给 Agent 的文本。");if(a.scheduleType==="once"&&!a.onceAt||(a.scheduleType==="daily"||a.scheduleType==="weekly")&&!a.time)return u("请选择执行时间。");const N=a.cron.trim().split(/\s+/);if(a.scheduleType==="cron"&&N.length!==5)return u("Cron 表达式需要包含 5 个字段,例如 0 9 * * *。");u(""),f(!0);try{let I=(e==null?void 0:e.runtimeId)===C.runtimeId?e.agentName.trim():"";if(!I){const[B]=await Hv("","",{runtimeId:C.runtimeId,region:C.region});I=(B==null?void 0:B.trim())??""}if(!I)throw new Error("Runtime Agent 未返回可调用的 appName,请确认 Runtime 已就绪且版本兼容。");await s({name:T,runtimeId:C.runtimeId,runtimeName:C.name,agentName:I,region:C.region,prompt:_,enabled:a.enabled,schedule:{type:a.scheduleType,timezone:a.timezone,...a.scheduleType==="once"?{onceAt:a.onceAt}:{},...a.scheduleType==="daily"?{time:a.time}:{},...a.scheduleType==="weekly"?{time:a.time,weekday:a.weekday}:{},...a.scheduleType==="cron"?{cron:a.cron.trim()}:{}}})}catch(I){u(I instanceof Error?I.message:String(I)),window.requestAnimationFrame(()=>{var B;return(B=b.current)==null?void 0:B.focus()})}finally{f(!1)}};return o.jsx("div",{className:"cronjobs-drawer-backdrop",onMouseDown:k=>{k.target===k.currentTarget&&!g&&r()},children:o.jsxs("aside",{ref:h,className:"cronjobs-drawer",role:"dialog","aria-modal":"true","aria-labelledby":"cronjobs-drawer-title",children:[o.jsxs("header",{className:"cronjobs-drawer-head",children:[o.jsxs("div",{children:[o.jsx("h2",{id:"cronjobs-drawer-title",children:e?"编辑定时任务":"创建定时任务"}),o.jsx("p",{children:"每次触发都会为 Runtime Agent 创建独立 Session。"})]}),o.jsx(Cn,{type:"button",color:"secondary",variant:"ghost",size:"lg",uniform:!0,pill:!1,onClick:r,disabled:g,"aria-label":"关闭抽屉",children:o.jsx(U4,{})})]}),o.jsxs("form",{className:"cronjobs-form",onSubmit:k=>void S(k),children:[o.jsxs("div",{className:"cronjobs-form-scroll",children:[o.jsxs("label",{className:"cronjobs-field",children:[o.jsx("span",{children:"任务名称"}),o.jsx(Fp,{ref:p,size:"lg",value:a.name,maxLength:80,invalid:!!c&&!a.name.trim(),onChange:k=>l({...a,name:k.target.value}),placeholder:"例如:每日生成运营摘要"})]}),o.jsxs("label",{className:"cronjobs-field",children:[o.jsx("span",{children:"Runtime Agent"}),o.jsx(nT,{value:a.runtimeId,options:x,size:"lg",disabled:t.length===0,placeholder:t.length?"选择 Runtime Agent":"暂无可用 Runtime",onChange:k=>l({...a,runtimeId:k.value})}),o.jsx("small",{children:"任务始终跟随该 Runtime 当前生效版本。"})]}),o.jsxs("label",{className:"cronjobs-field",children:[o.jsx("span",{children:"执行文本"}),o.jsx(obe,{value:a.prompt,rows:5,maxRows:10,autoResize:!0,maxLength:2e4,invalid:!!c&&!a.prompt.trim(),onChange:k=>l({...a,prompt:k.target.value}),placeholder:"输入每次执行时发送给 Agent 的固定文本"}),o.jsxs("small",{className:"cronjobs-character-count",children:[a.prompt.length.toLocaleString()," / 20,000"]})]}),o.jsxs("fieldset",{className:"cronjobs-fieldset",children:[o.jsx("legend",{children:"执行计划"}),o.jsxs(Pl,{className:"cronjobs-schedule-types",value:a.scheduleType,size:"lg",block:!0,"aria-label":"执行计划类型",onChange:k=>l({...a,scheduleType:k}),children:[o.jsx(Pl.Option,{value:"once",children:"一次性"}),o.jsx(Pl.Option,{value:"daily",children:"每天"}),o.jsx(Pl.Option,{value:"weekly",children:"每周"}),o.jsx(Pl.Option,{value:"cron",children:"Cron"})]}),a.scheduleType==="once"?o.jsxs("label",{className:"cronjobs-field",children:[o.jsx("span",{children:"执行时间"}),o.jsx(Fp,{size:"lg",type:"datetime-local",value:a.onceAt,onChange:k=>l({...a,onceAt:k.target.value})})]}):null,a.scheduleType==="daily"?o.jsxs("label",{className:"cronjobs-field",children:[o.jsx("span",{children:"每天执行时间"}),o.jsx(Fp,{size:"lg",type:"time",value:a.time,onChange:k=>l({...a,time:k.target.value})})]}):null,a.scheduleType==="weekly"?o.jsxs("div",{className:"cronjobs-inline-fields",children:[o.jsxs("label",{className:"cronjobs-field",children:[o.jsx("span",{children:"星期"}),o.jsx(nT,{value:String(a.weekday),options:w,size:"lg",onChange:k=>l({...a,weekday:Number(k.value)})})]}),o.jsxs("label",{className:"cronjobs-field",children:[o.jsx("span",{children:"执行时间"}),o.jsx(Fp,{size:"lg",type:"time",value:a.time,onChange:k=>l({...a,time:k.target.value})})]})]}):null,a.scheduleType==="cron"?o.jsxs("label",{className:"cronjobs-field",children:[o.jsx("span",{children:"Cron 表达式"}),o.jsx(Fp,{size:"lg",value:a.cron,onChange:k=>l({...a,cron:k.target.value}),placeholder:"0 9 * * *"}),o.jsx("small",{children:"依次填写分钟、小时、日期、月份、星期。"})]}):null,o.jsxs("label",{className:"cronjobs-field",children:[o.jsx("span",{children:"时区"}),o.jsx(nT,{value:a.timezone,options:E,size:"lg",onChange:k=>l({...a,timezone:k.value})})]})]}),o.jsxs("div",{className:"cronjobs-switch-row",children:[o.jsxs("span",{children:[o.jsx("strong",{children:"创建后启用"}),o.jsx("small",{children:"启用后会从下一个计划时间开始执行。"})]}),o.jsx(ibt,{checked:a.enabled,onCheckedChange:k=>l({...a,enabled:k}),"aria-label":"创建后启用"})]}),c?o.jsx("div",{ref:b,className:"cronjobs-inline-error",tabIndex:-1,children:o.jsx(Lx,{color:"danger",variant:"soft",description:c})}):null]}),o.jsxs("footer",{className:"cronjobs-drawer-actions",children:[o.jsx(Cn,{type:"button",color:"secondary",variant:"ghost",size:"lg",pill:!1,onClick:r,disabled:g,children:"取消"}),o.jsx(Cn,{type:"submit",color:"primary",size:"lg",pill:!1,loading:g,disabled:t.length===0,"aria-busy":g||void 0,children:d?"正在连接 Runtime…":i?"保存中…":e?"保存更改":"创建任务"})]})]})]})})}function pbt({jobs:e,busyAction:t,onSelect:n,onEdit:i,onToggle:r,onRun:s}){return o.jsx("div",{className:"cronjobs-table-wrap",children:o.jsxs("table",{className:"cronjobs-table",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"任务名称"}),o.jsx("th",{children:"Runtime Agent"}),o.jsx("th",{children:"执行计划"}),o.jsx("th",{children:"状态"}),o.jsx("th",{children:"下次执行"}),o.jsx("th",{children:"最近结果"}),o.jsx("th",{children:o.jsx("span",{className:"sr-only",children:"操作"})})]})}),o.jsx("tbody",{children:e.map(a=>{const l=x_(a),c=t.includes(a.jobId);return o.jsxs("tr",{children:[o.jsx("td",{children:o.jsx(Cn,{type:"button",className:"cronjobs-name-button",color:"secondary",variant:"ghost",size:"md",pill:!1,opticallyAlign:"start",onClick:()=>n(a),title:a.name,children:a.name})}),o.jsx("td",{"data-label":"Runtime Agent",children:o.jsxs("span",{className:"cronjobs-agent",title:`${a.runtimeName} / ${a.agentName}`,children:[o.jsx(o2e,{}),a.runtimeName||a.agentName]})}),o.jsx("td",{"data-label":"执行计划",title:V3(a.schedule),children:V3(a.schedule)}),o.jsx("td",{"data-label":"状态",children:o.jsx(uO,{color:a.enabled?"success":"secondary",variant:"soft",size:"sm",pill:!0,children:a.enabled?"已启用":"已暂停"})}),o.jsx("td",{"data-label":"下次执行",children:a.enabled?y_(a.nextRunAt):"-"}),o.jsx("td",{"data-label":"最近结果",children:o.jsx(cbe,{run:a.latestRun})}),o.jsx("td",{className:"cronjobs-actions-cell",children:o.jsxs("div",{className:"cronjobs-row-actions",children:[o.jsx(al,{compact:!0,content:l?"已有执行正在进行":a.enabled?"立即执行":"请先启用任务",children:o.jsx(Cn,{type:"button",color:"secondary",variant:"ghost",size:"md",uniform:!0,pill:!1,onClick:()=>s(a),disabled:c||l||!a.enabled,"aria-label":`立即执行 ${a.name}`,children:o.jsx(HT,{})})}),o.jsx(al,{compact:!0,content:a.enabled?"暂停":"启用",children:o.jsx(Cn,{type:"button",color:"secondary",variant:"ghost",size:"md",uniform:!0,pill:!1,onClick:()=>r(a),disabled:c,"aria-label":`${a.enabled?"暂停":"启用"} ${a.name}`,children:a.enabled?o.jsx(vne,{}):o.jsx(HT,{})})}),o.jsx(al,{compact:!0,content:"编辑",children:o.jsx(Cn,{type:"button",color:"secondary",variant:"ghost",size:"md",uniform:!0,pill:!1,onClick:()=>i(a),disabled:c,"aria-label":`编辑 ${a.name}`,children:o.jsx(F4,{})})})]})})]},a.jobId)})})]})})}function mbt({job:e,runs:t,runsLoading:n,runsError:i,busyAction:r,onBack:s,onEdit:a,onToggle:l,onRun:c,onDelete:u,onCancel:d,onRetryRun:f,onRetryRuns:h}){const p=t.find(g=>g.status==="queued"||g.status==="running"||g.status==="retrying"||g.status==="pending")??(x_(e)?e.latestRun:void 0),b=r.includes(e.jobId);return o.jsxs("div",{className:"cronjobs-detail",children:[o.jsxs("header",{className:"cronjobs-detail-head",children:[o.jsxs("div",{className:"cronjobs-detail-title",children:[o.jsx(Cn,{type:"button",color:"secondary",variant:"ghost",size:"lg",uniform:!0,pill:!1,onClick:s,"aria-label":"返回定时任务列表",children:o.jsx(l2e,{})}),o.jsxs("div",{children:[o.jsx("h1",{children:e.name}),o.jsxs("p",{children:[e.runtimeName||e.agentName," · ",V3(e.schedule)]})]})]}),o.jsxs("div",{className:"cronjobs-detail-actions",children:[o.jsxs(Cn,{type:"button",color:"secondary",variant:"outline",size:"lg",pill:!1,onClick:a,disabled:b,children:[o.jsx(F4,{}),"编辑"]}),o.jsxs(Cn,{type:"button",color:"secondary",variant:"outline",size:"lg",pill:!1,onClick:l,disabled:b,children:[e.enabled?o.jsx(vne,{}):o.jsx(HT,{}),e.enabled?"暂停":"启用"]}),p?o.jsxs(Cn,{type:"button",color:"danger",variant:"soft",size:"lg",pill:!1,onClick:()=>d(p),disabled:b||!!p.cancellationRequestedAt,children:[o.jsx(w2e,{}),p.cancellationRequestedAt?p.status==="queued"?"取消中…":"终止中…":p.status==="queued"?"取消排队":"终止本次执行"]}):o.jsxs(Cn,{type:"button",color:"primary",size:"lg",pill:!1,onClick:c,disabled:b||!e.enabled,children:[o.jsx(HT,{}),"立即执行"]}),o.jsx(al,{compact:!0,content:p?p.status==="queued"?"请先取消排队":"请先终止当前执行":"删除任务",children:o.jsxs(Cn,{type:"button",color:"danger",variant:"ghost",size:"lg",pill:!1,onClick:u,disabled:b||!!p,"aria-label":"删除任务",children:[o.jsx(yne,{}),"删除"]})})]})]}),o.jsxs("div",{className:"cronjobs-detail-scroll",children:[o.jsxs("section",{className:"cronjobs-summary-grid","aria-label":"任务配置",children:[o.jsxs("dl",{children:[o.jsxs("div",{children:[o.jsx("dt",{children:"任务状态"}),o.jsx("dd",{children:e.enabled?"已启用":"已暂停"})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"下次执行"}),o.jsx("dd",{children:e.enabled?y_(e.nextRunAt):"-"})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"Runtime"}),o.jsx("dd",{title:e.runtimeName,children:e.runtimeName})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"地域"}),o.jsx("dd",{children:e.region})]})]}),o.jsxs("div",{className:"cronjobs-prompt",children:[o.jsx("span",{children:"执行文本"}),o.jsx("p",{children:e.prompt})]})]}),o.jsxs("section",{className:"cronjobs-history",children:[o.jsxs("header",{children:[o.jsxs("div",{children:[o.jsx("h2",{children:"执行历史"}),o.jsx("p",{children:"每次运行均使用独立 Session,结果与错误会永久保留。"})]}),o.jsx(al,{compact:!0,content:"刷新",children:o.jsx(Cn,{type:"button",color:"secondary",variant:"ghost",size:"lg",uniform:!0,pill:!1,onClick:h,disabled:n,"aria-label":"刷新执行历史",children:o.jsx(bne,{})})})]}),n&&t.length===0?o.jsxs("div",{className:"cronjobs-history-state cronjobs-loading",role:"status","aria-live":"polite",children:[o.jsx(AA,{size:20}),o.jsx("span",{children:"正在加载执行历史…"})]}):i?o.jsx(Lx,{className:"cronjobs-history-alert",color:"danger",variant:"soft",title:"无法加载执行历史",description:i,actions:o.jsx(Cn,{type:"button",color:"danger",variant:"soft",size:"sm",pill:!1,onClick:h,children:"重试"})}):t.length===0?o.jsxs(cn,{className:"cronjobs-history-state",fill:"none",children:[o.jsx(cn.Icon,{children:o.jsx(qT,{})}),o.jsx(cn.Title,{children:"暂无执行记录"}),o.jsx(cn.Description,{children:"任务触发或立即执行后,记录会显示在这里。"})]}):o.jsx("div",{className:"cronjobs-runs",children:t.map(g=>o.jsxs("article",{className:"cronjobs-run",children:[o.jsxs("div",{className:"cronjobs-run-main",children:[o.jsx(cbe,{run:g}),o.jsxs("div",{children:[o.jsx("strong",{children:y_(g.startedAt||g.scheduledAt)}),o.jsxs("span",{children:["耗时 ",obt(g),g.runtimeVersion?` · Runtime v${g.runtimeVersion}`:""]})]})]}),g.sessionId?o.jsxs("div",{className:"cronjobs-run-meta",children:[o.jsx("span",{children:"Session"}),o.jsx("strong",{title:g.sessionId,children:g.sessionId})]}):null,g.output?o.jsxs("div",{className:"cronjobs-run-output",children:[o.jsx("span",{children:"最终回答"}),o.jsx(lbt,{output:g.output})]}):null,g.error?o.jsxs("div",{className:"cronjobs-run-output is-error",children:[o.jsx("span",{children:"错误详情"}),o.jsx(kv,{message:g.error,className:"cronjobs-run-error-detail",defaultExpanded:!1,onRetry:g.status==="failed"?f:void 0,retryLabel:"重新执行"})]}):null,g.status==="queued"||g.status==="running"||g.status==="retrying"||g.status==="pending"?o.jsx(Cn,{type:"button",className:"cronjobs-run-cancel",color:"danger",variant:"soft",size:"sm",pill:!1,onClick:()=>d(g),disabled:b||!!g.cancellationRequestedAt,loading:!!g.cancellationRequestedAt,children:g.cancellationRequestedAt?"终止中…":g.status==="queued"?"取消排队":"终止执行"}):null]},g.runId))})]})]})]})}function gbt({cloudProvider:e}){const[t,n]=m.useState([]),[i,r]=m.useState([]),[s,a]=m.useState(!0),[l,c]=m.useState(""),[u,d]=m.useState(""),[f,h]=m.useState(void 0),[p,b]=m.useState([]),[g,O]=m.useState(!1),[y,v]=m.useState(""),[x,w]=m.useState(""),[E,S]=m.useState(""),[k,T]=m.useState(null),[_,C]=m.useState(""),N=t.find(z=>z.jobId===u),I=m.useCallback(async z=>{a(!0),c("");try{const[F,q]=await Promise.all([aP(z),cO({scope:"all",region:"all",pageSize:100})]);if(z!=null&&z.aborted)return;n(F),r(q.runtimes.filter(te=>te.status.toLowerCase()==="ready"))}catch(F){if(z!=null&&z.aborted)return;c(F instanceof Error?F.message:String(F))}finally{z!=null&&z.aborted||a(!1)}},[]);m.useEffect(()=>{const z=new AbortController;return I(z.signal),()=>z.abort()},[I]);const B=m.useCallback(async(z,F)=>{O(!0),v("");try{const q=await oP(z,F);F!=null&&F.aborted||b(q)}catch(q){F!=null&&F.aborted||v(q instanceof Error?q.message:String(q))}finally{F!=null&&F.aborted||O(!1)}},[]);m.useEffect(()=>{if(!u){b([]),v("");return}const z=new AbortController;return B(u,z.signal),()=>z.abort()},[B,u]);const D=t.some(x_);m.useEffect(()=>{!D&&E.includes("已排队")&&S("")},[D,E]),m.useEffect(()=>{if(!D)return;const z=new AbortController,F=async()=>{try{const[te,ce]=await Promise.all([aP(z.signal),u?oP(u,z.signal):Promise.resolve(null)]);if(z.signal.aborted)return;n(te),ce&&b(ce),te.some(x_)||S("")}catch(te){z.signal.aborted||S(te instanceof Error?te.message:String(te))}},q=window.setInterval(()=>void F(),cbt);return()=>{window.clearInterval(q),z.abort()}},[D,u]);const L=z=>n(F=>F.some(q=>q.jobId===z.jobId)?F.map(q=>q.jobId===z.jobId?z:q):[z,...F]),j=async(z,F,q,te=!1)=>{w(z),S("");try{await F(),S(q)}catch(ce){const be=ce instanceof Error?ce.message:String(ce);if(te)throw new Error(be);S(be)}finally{w("")}},P=async z=>{const F=f??null;await j(`${(F==null?void 0:F.jobId)??"new"}:save`,async()=>{const q=F?await Iie(F.jobId,z):await Rie(z);L(q),h(void 0),F&&d(q.jobId)},F?"任务已更新。":"任务已创建。",!0)},M=z=>void j(`${z.jobId}:toggle`,async()=>L(await Die(z.jobId,!z.enabled)),z.enabled?"任务已暂停。":"任务已启用。"),U=(z,F)=>j(`${z.jobId}:run`,async()=>{const q=await Pie(z.jobId);L({...z,latestRun:q}),u===z.jobId&&b(te=>[q,...te.filter(ce=>ce.runId!==q.runId)])},F),$=z=>void U(z,"任务已排队,将在一分钟内开始执行。"),G=()=>{if(!k)return;C("");const z=k;z.kind==="delete"?j(`${z.job.jobId}:delete`,async()=>{await Lie(z.job.jobId),n(F=>F.filter(q=>q.jobId!==z.job.jobId)),d(""),T(null)},"任务及其执行历史已删除。",!0).catch(F=>{C(F instanceof Error?F.message:String(F))}):j(`${z.job.jobId}:cancel`,async()=>{var q;const F=await Mie(z.job.jobId,z.run.runId);b(te=>te.map(ce=>ce.runId===F.runId?F:ce)),L({...z.job,latestRun:((q=z.job.latestRun)==null?void 0:q.runId)===F.runId?F:z.job.latestRun}),T(null)},"已提交终止请求。",!0).catch(F=>{C(F instanceof Error?F.message:String(F))})};return N?o.jsxs("div",{className:"cronjobs-page",children:[o.jsx(mbt,{job:N,runs:p,runsLoading:g,runsError:y,busyAction:x,onBack:()=>d(""),onEdit:()=>h(N),onToggle:()=>M(N),onRun:()=>$(N),onDelete:()=>{C(""),T({kind:"delete",job:N})},onCancel:z=>{C(""),T({kind:"cancel",job:N,run:z})},onRetryRun:()=>U(N,"任务已重新排队,将在一分钟内开始执行。"),onRetryRuns:()=>void B(N.jobId)}),E?o.jsx("div",{className:"cronjobs-notice",role:"status",children:o.jsx(Lx,{color:"info",variant:"soft",description:E})}):null,f!==void 0?o.jsx(HY,{job:f,runtimes:i,cloudProvider:e,busy:x.endsWith(":save"),onClose:()=>h(void 0),onSubmit:P}):null,k?o.jsx(zl,{title:k.kind==="delete"?"删除定时任务?":"终止本次执行?",description:k.kind==="delete"?`“${k.job.name}”及其全部执行历史将被永久删除。`:"本次 Session 将被取消,后续计划不会暂停。",error:_,confirmLabel:k.kind==="delete"?"删除任务":"终止执行",variant:"danger",busy:x.endsWith(k.kind),onCancel:()=>{C(""),T(null)},onConfirm:G}):null]}):o.jsxs("div",{className:"cronjobs-page",children:[o.jsx("header",{className:"cronjobs-page-head",children:o.jsxs("div",{children:[o.jsx("h1",{children:"定时任务"}),o.jsx("p",{children:"按计划调用 Runtime Agent,每次执行使用独立 Session。"})]})}),t.length>0?o.jsx("div",{className:"cronjobs-toolbar",children:o.jsxs(Cn,{type:"button",color:"primary",size:"lg",pill:!1,onClick:()=>h(null),disabled:s||i.length===0,title:i.length===0?"暂无可用的 Runtime Agent":"创建定时任务",children:[o.jsx($F,{}),"创建任务"]})}):null,E?o.jsx("div",{className:"cronjobs-banner",role:"status",children:o.jsx(Lx,{color:"info",variant:"soft",description:E})}):null,o.jsx("section",{className:"cronjobs-content",children:s&&t.length===0?o.jsxs("div",{className:"cronjobs-loading",role:"status","aria-live":"polite",children:[o.jsx(AA,{size:20}),o.jsx("span",{children:"正在加载定时任务…"})]}):l?o.jsxs(cn,{className:"cronjobs-state",fill:"none",children:[o.jsx(cn.Icon,{color:"danger",children:o.jsx(qT,{})}),o.jsx(cn.Title,{color:"danger",children:"无法加载定时任务"}),o.jsx(cn.Description,{children:l}),o.jsx(cn.ActionRow,{children:o.jsxs(Cn,{type:"button",color:"secondary",variant:"outline",size:"lg",pill:!1,onClick:()=>void I(),children:[o.jsx(bne,{}),"重试"]})})]}):t.length===0?o.jsxs(cn,{className:"cronjobs-state",fill:"none",children:[o.jsx(cn.Icon,{children:o.jsx(qT,{})}),o.jsx(cn.Title,{children:"还没有定时任务"}),o.jsx(cn.Description,{children:"创建任务后,系统会按计划调用选定的 Runtime Agent。"}),o.jsx(cn.ActionRow,{children:o.jsxs(Cn,{type:"button",color:"primary",size:"lg",pill:!1,onClick:()=>h(null),disabled:i.length===0,children:[o.jsx($F,{}),"创建第一个任务"]})}),i.length===0?o.jsx(cn.Description,{children:"暂无可用的 Runtime Agent,请先部署并等待 Runtime 就绪。"}):null]}):o.jsx(pbt,{jobs:t,busyAction:x,onSelect:z=>d(z.jobId),onEdit:z=>h(z),onToggle:M,onRun:$})}),f!==void 0?o.jsx(HY,{job:f,runtimes:i,cloudProvider:e,busy:x.endsWith(":save"),onClose:()=>h(void 0),onSubmit:P}):null]})}const bbt={volcengine:"https://console.volcengine.com",byteplus:"https://console.byteplus.com"};function Tv(e){return e.trim()}function z9(e){return bbt[e]}function Obt(e){const t=Tv(e);if(!t)return null;let n=t;try{n=new URL(t.includes("://")?t:`https://${t}`).hostname}catch{return null}const i=n.match(/^(.+)\.tos-([a-z0-9-]+)\.(?:volces|bytepluses)\.com$/i);return i?{bucket:i[1],region:i[2]}:null}function ybt(e,t){const n=Obt(t);if(!n)return null;const i=new URLSearchParams({id:n.bucket,region:n.region,type:"objects"});return`${z9(e)}/tos/bucket/setting?${i.toString()}`}function xbt(e,t,n){const i=Tv(t),r=Tv(n);return!i||!r?null:`${z9(e)}/agentkit/region:agentkit+${encodeURIComponent(i)}/builtintools/${encodeURIComponent(r)}/detail`}function vbt(e,t,n){const i=Tv(t),r=Tv(n);return!i||!r?null:`${z9(e)}/identity/region:identity+${encodeURIComponent(i)}/user-pools/${encodeURIComponent(r)}/info`}function JI({href:e,label:t,children:n}){return e?o.jsxs("a",{className:"system-info-resource-link",href:e,target:"_blank",rel:"noreferrer","aria-label":t,title:t,children:[o.jsx("span",{children:n}),o.jsxs("svg",{viewBox:"0 0 20 20","aria-hidden":"true",children:[o.jsx("path",{d:"M7.75 5.25h-2.5a1.5 1.5 0 0 0-1.5 1.5v8a1.5 1.5 0 0 0 1.5 1.5h8a1.5 1.5 0 0 0 1.5-1.5v-2.5"}),o.jsx("path",{d:"M10.25 3.75h6v6M16 4 9 11"})]})]}):o.jsx("span",{children:n})}function wbt(e){return e instanceof Error&&e.message.includes("Volcengine credentials not found")}function XY(e){return e==="codex"||e==="codex_snapshot"}function GY(){return{busy:!1,error:"",message:""}}function Sbt({version:e,localMode:t,role:n,provider:i,region:r,onBack:s}){const a=n==="admin",[l,c]=m.useState(""),[u,d]=m.useState([]),[f,h]=m.useState([]),[p,b]=m.useState(!0),[g,O]=m.useState(""),[y,v]=m.useState(!0),[x,w]=m.useState(""),[E,S]=m.useState(0),[k,T]=m.useState(0),_=m.useRef(!1),[C,N]=m.useState({});m.useEffect(()=>(_.current=!0,()=>{_.current=!1}),[]);function I(D,L){N(j=>({...j,[D]:{...GY(),...j[D],...L}}))}async function B(D){if(!(!XY(D.kind)||!D.toolId||(C[D.kind]??GY()).busy)){I(D.kind,{busy:!0,error:"",message:""});try{const j=await Oie(D.kind);if(!_.current)return;d(P=>P.map(M=>M.kind===D.kind?{...M,needsModelEnvUpdate:!1,canUpdateModelEnv:!1,modelEnvError:"",modelEnvErrorCode:""}:M)),I(D.kind,{busy:!1,error:"",message:j.updated?"已更新":"无需更新"})}catch(j){if(!_.current)return;I(D.kind,{busy:!1,error:j instanceof Error?j.message:String(j),message:""})}}}return m.useEffect(()=>{if(!a){c(""),d([]),b(!1),O("");return}const D=new AbortController;return b(!0),O(""),bie(D.signal).then(L=>{c(L.storage.tosAddress),d(L.sandboxTools)}).catch(L=>{(L==null?void 0:L.name)!=="AbortError"&&O(L instanceof Error?L.message:String(L))}).finally(()=>{D.signal.aborted||b(!1)}),()=>D.abort()},[a,E]),m.useEffect(()=>{if(!a){h([]),v(!1),w("");return}const D=new AbortController;return v(!0),w(""),d$(D.signal).then(L=>{h(L.filter(j=>j.isCurrent))}).catch(L=>{if((L==null?void 0:L.name)!=="AbortError"){if(t&&wbt(L)){h([]);return}w(L instanceof Error?L.message:String(L))}}).finally(()=>{D.signal.aborted||v(!1)}),()=>D.abort()},[a,t,k]),o.jsxs("div",{className:"system-info-page",children:[o.jsxs("header",{className:"system-info-page-header",children:[o.jsx(I9,{label:"返回上一页",onClick:s}),o.jsxs("div",{children:[o.jsx("h1",{children:"系统信息"}),o.jsx("p",{children:"查看当前 Studio 版本及关联的基础资源"})]})]}),o.jsxs("div",{className:"system-info-scroll",children:[o.jsxs("section",{className:"system-info-section","aria-labelledby":"studio-info-title",children:[o.jsx("h2",{id:"studio-info-title",children:"通用"}),o.jsx("dl",{className:"system-info-summary",children:o.jsxs("div",{children:[o.jsx("dt",{children:"当前版本"}),o.jsx("dd",{children:e||"—"})]})})]}),a?o.jsxs(o.Fragment,{children:[o.jsxs("section",{className:"system-info-section","aria-labelledby":"storage-info-title",children:[o.jsx("h2",{id:"storage-info-title",children:"存储"}),p?o.jsx("div",{className:"system-info-loading",role:"status","aria-live":"polite",children:o.jsx(Vn,{as:"span",children:"正在加载存储信息"})}):g?o.jsxs("div",{className:"system-info-error",role:"alert",children:[o.jsx("p",{children:g}),o.jsx("button",{type:"button",onClick:()=>S(D=>D+1),children:"重新加载"})]}):o.jsx("dl",{className:"system-info-summary",children:o.jsxs("div",{className:"system-info-resource-row",children:[o.jsx("dt",{children:"TOS 地址"}),o.jsx("dd",{className:`system-info-resource-value${l?"":" is-empty"}`,children:o.jsx(JI,{href:ybt(i,l),label:"在云控制台中打开 TOS 存储桶",children:l||"未配置"})})]})})]}),o.jsxs("section",{className:"system-info-section","aria-labelledby":"sandbox-tool-title",children:[o.jsx("h2",{id:"sandbox-tool-title",children:"沙箱信息"}),p?o.jsx("div",{className:"system-info-loading",role:"status","aria-live":"polite",children:o.jsx(Vn,{as:"span",children:"正在加载沙箱信息"})}):g?o.jsxs("div",{className:"system-info-error",role:"alert",children:[o.jsx("p",{children:g}),o.jsx("button",{type:"button",onClick:()=>S(D=>D+1),children:"重新加载"})]}):o.jsx("div",{className:"system-info-tool-list",children:u.map(D=>{const L=XY(D.kind)?D.kind:null,j=L?C[L]:void 0,P=L!==null&&!!D.toolId&&D.needsModelEnvUpdate&&D.canUpdateModelEnv,M=L?(j==null?void 0:j.error)||D.modelEnvError:"";return o.jsx("dl",{className:"system-info-tool",children:o.jsxs("div",{className:"system-info-resource-row",children:[o.jsxs("dt",{className:"system-info-tool-label",children:[o.jsx("span",{children:D.label}),D.snapshot?o.jsx("span",{className:"system-info-tool-badge",children:"快照版"}):null]}),o.jsxs("dd",{className:`system-info-resource-value${D.toolId?"":" is-empty"}`,children:[o.jsx(JI,{href:xbt(i,r,D.toolId),label:`在云控制台中打开${D.label}`,children:D.toolId||"未配置"}),P?o.jsx("button",{type:"button",className:"system-info-resource-update",disabled:j==null?void 0:j.busy,"aria-busy":(j==null?void 0:j.busy)||void 0,"aria-label":`更新${D.snapshot?"快照版 ":""}${D.label}模型环境变量`,title:`更新${D.snapshot?"快照版 ":""}${D.label}模型环境变量`,onClick:()=>void B(D),children:o.jsx(Ine,{"aria-hidden":"true",className:j!=null&&j.busy?"is-spinning":""})}):null,L&&(j!=null&&j.message)?o.jsx("span",{className:"system-info-inline-status",role:"status",children:j.message}):null,M?o.jsx("span",{className:"system-info-inline-error",role:"alert",children:M}):null]})]})},D.kind)})})]}),o.jsxs("section",{className:"system-info-section","aria-labelledby":"user-pool-title",children:[o.jsx("h2",{id:"user-pool-title",children:"用户池"}),y?o.jsx("div",{className:"system-info-loading",role:"status","aria-live":"polite",children:o.jsx(Vn,{as:"span",children:"正在加载用户池"})}):x?o.jsxs("div",{className:"system-info-error",role:"alert",children:[o.jsx("p",{children:x}),o.jsx("button",{type:"button",onClick:()=>T(D=>D+1),children:"重新加载"})]}):f.length>0?o.jsx("div",{className:"system-info-pool-list",children:f.map(D=>o.jsxs("dl",{className:"system-info-pool",children:[o.jsxs("div",{children:[o.jsx("dt",{children:"名称"}),o.jsx("dd",{className:"system-info-resource-value",children:o.jsx(JI,{href:vbt(i,D.region||r,D.uid),label:`在云控制台中打开用户池${D.name?`“${D.name}”`:""}`,children:D.name||"未命名用户池"})})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"ID"}),o.jsx("dd",{children:D.uid||"—"})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"域名"}),o.jsx("dd",{children:D.domain||"—"})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"区域"}),o.jsx("dd",{children:D.region||"—"})]})]},D.uid))}):o.jsx("p",{className:"system-info-empty",children:t?"本地模式未配置用户池":"当前 Studio 未配置用户池"})]})]}):null]})]})}function Ebt(e){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",...e,children:o.jsx("path",{d:"m9.8 3.5-4.5 4.5 4.5 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function kbt({hidden:e,...t}){return o.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...t,children:[o.jsx("path",{d:"M2.5 10s2.6-4 7.5-4 7.5 4 7.5 4-2.6 4-7.5 4-7.5-4-7.5-4Z"}),o.jsx("circle",{cx:"10",cy:"10",r:"1.8"}),e?o.jsx("path",{d:"m4 4 12 12"}):null]})}function YY(e){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",...e,children:o.jsx("path",{d:"M6.5 4H4.8A1.8 1.8 0 0 0 3 5.8v5.4A1.8 1.8 0 0 0 4.8 13h5.4a1.8 1.8 0 0 0 1.8-1.8V9.5M9 3h4v4M12.5 3.5 7.2 8.8",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}function Tbt(e){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",...e,children:o.jsx("path",{d:"m4 6 4 4 4-4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function _bt(e){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",...e,children:o.jsx("path",{d:"m3.5 8.2 2.8 2.8 6.2-6.2",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function eD(e,t,n){const i=t.trim();if(!i)return n?"此项不能为空":"";if(e==="repository"&&!/^(?:https:\/\/github\.com\/)?[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+(?:\.git)?$/.test(i))return"请输入 owner/repository 或完整 GitHub Repo URL";if(e==="baseBranch"&&(!/^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(i)||i.includes("..")))return"目标分支格式不正确";if(e==="projectPath"&&(i.startsWith("/")||i.split("/").includes("..")))return"请输入仓库内的相对目录";if(e==="runtimeName")return $C(i)??"";if(e==="runtimeId"&&!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(i))return"Runtime ID 格式不正确";if(e==="sandboxToolId"&&!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(i))return"Sandbox Tool ID 格式不正确";if(e==="modelName"&&!/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/.test(i))return"模型名称格式不正确";if(e==="modelBaseUrl")try{const r=new URL(i);if(r.protocol!=="https:"||r.username||r.password||r.search||r.hash)return"请输入不含凭据、查询参数或锚点的 HTTPS 地址"}catch{return"请输入有效的 HTTPS 地址"}return""}function Abt({automation:e,onBack:t}){const n=t0t(e),[i,r]=m.useState(()=>({...n.initialValues})),[s,a]=m.useState({}),[l,c]=m.useState(""),[u,d]=m.useState(!1),[f,h]=m.useState(!1),[p,b]=m.useState(!1),[g,O]=m.useState(null),y=m.useRef(null);m.useEffect(()=>()=>{var k;return(k=y.current)==null?void 0:k.abort()},[]);const v=(k,T)=>{r(_=>({..._,[k]:T})),s[k]&&a(_=>({..._,[k]:""}))},x=k=>{var C;const T=k==="token"||((C=n.fields.find(N=>N.name===k))==null?void 0:C.required)===!0,_=eD(k,i[k],T);a(N=>({...N,[k]:_}))},w=async k=>{var N;k.preventDefault();const T={};for(const I of n.fields){const B=eD(I.name,i[I.name],I.required);B&&(T[I.name]=B)}const _=eD("token",i.token,!0);if(_&&(T.token=_),a(T),Object.keys(T).length)return;(N=y.current)==null||N.abort();const C=new AbortController;y.current=C,d(!0),c(""),O(null);try{const I=await n.submit(i,C.signal);if(y.current!==C)return;O(I),r(B=>({...B,token:""}))}catch(I){if(C.signal.aborted||y.current!==C)return;c(I instanceof Error?I.message:String(I))}finally{y.current===C&&(y.current=null,d(!1))}},E=k=>{k.key==="Enter"&&(k.nativeEvent.isComposing||k.nativeEvent.keyCode===229)&&k.preventDefault()},S=k=>{const{name:T,label:_,placeholder:C,help:N,required:I}=k;return o.jsxs("div",{className:"github-field",children:[o.jsxs("label",{htmlFor:`github-${T}`,children:[o.jsx("span",{children:_}),o.jsx("span",{className:`github-field-requirement${I?" is-required":""}`,children:I?"必填":"可选"})]}),o.jsx("input",{id:`github-${T}`,value:i[T],onChange:B=>v(T,B.target.value),onBlur:()=>x(T),placeholder:C,required:I,"aria-invalid":!!s[T],"aria-describedby":`github-${T}-help${s[T]?` github-${T}-error`:""}`}),o.jsx("span",{id:`github-${T}-help`,className:"github-field-help",children:N}),s[T]?o.jsx("span",{id:`github-${T}-error`,className:"github-field-error",role:"alert",children:s[T]}):null]},T)};return o.jsxs("div",{className:"github-integration-page",children:[o.jsxs("header",{className:"github-integration-header",children:[o.jsx("button",{type:"button",className:"github-back",onClick:t,"aria-label":"返回自动化列表",children:o.jsx(Ebt,{})}),o.jsx(F9,{className:"github-integration-logo"}),o.jsxs("div",{children:[o.jsx("h1",{children:n.title}),o.jsx("p",{children:n.subtitle})]})]}),o.jsx("div",{className:"github-integration-layout",children:o.jsxs("section",{id:`github-panel-${e}`,className:"github-section-panel",children:[o.jsx("div",{className:"github-panel-heading",children:o.jsx("p",{children:n.panel})}),o.jsxs("form",{className:"github-release-form",onSubmit:w,onKeyDown:E,noValidate:!0,children:[o.jsxs("div",{className:"github-field-grid",children:[n.fields.map(S),o.jsxs("div",{className:"github-field",children:[o.jsxs("label",{id:"github-region-label",children:[o.jsx("span",{children:"地域"}),o.jsx("span",{className:"github-field-requirement is-required",children:"必填"})]}),o.jsxs("div",{className:"pp-network-region github-region-picker",onKeyDown:k=>{k.key==="Escape"&&b(!1)},children:[o.jsxs("button",{type:"button",className:"pp-region-trigger","aria-labelledby":"github-region-label","aria-haspopup":"listbox","aria-expanded":p,onClick:()=>b(k=>!k),children:[o.jsx("span",{children:i.region==="cn-shanghai"?"华东 2(上海)":"华北 2(北京)"}),o.jsx(Tbt,{className:`pp-region-chevron${p?" is-open":""}`})]}),p?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"menu-scrim",onClick:()=>b(!1)}),o.jsx("div",{className:"pp-region-menu",role:"listbox","aria-label":"地域",children:[{value:"cn-beijing",label:"华北 2(北京)"},{value:"cn-shanghai",label:"华东 2(上海)"}].map(k=>{const T=k.value===i.region;return o.jsxs("button",{type:"button",role:"option","aria-selected":T,className:`pp-region-option${T?" is-selected":""}`,onClick:()=>{v("region",k.value),b(!1)},children:[o.jsx("span",{children:k.label}),T?o.jsx(_bt,{}):null]},k.value)})})]}):null]}),o.jsx("span",{className:"github-field-help",children:n.regionHelp})]})]}),o.jsxs("div",{className:"github-field github-token-field",children:[o.jsxs("div",{className:"github-token-label-row",children:[o.jsxs("label",{htmlFor:"github-token",children:[o.jsx("span",{children:"GitHub Token"}),o.jsx("span",{className:"github-field-requirement is-required",children:"必填"})]}),o.jsxs("a",{href:"https://github.com/settings/personal-access-tokens/new?name=VeADK%20Studio&description=Create%20a%20GitHub%20automation%20pull%20request&contents=write&pull_requests=write",target:"_blank",rel:"noreferrer",children:["获取 Token",o.jsx(YY,{})]})]}),o.jsxs("div",{className:"github-token-input",children:[o.jsx("input",{id:"github-token",type:f?"text":"password",value:i.token,onChange:k=>v("token",k.target.value),onBlur:()=>x("token"),autoComplete:"off",required:!0,placeholder:"需要仓库 Contents 与 Pull requests 写权限","aria-invalid":!!s.token,"aria-describedby":`github-token-help${s.token?" github-token-error":""}`}),o.jsx("button",{type:"button",onClick:()=>h(k=>!k),"aria-label":f?"隐藏 Token":"显示 Token",title:f?"隐藏 Token":"显示 Token",children:o.jsx(kbt,{hidden:f})})]}),o.jsx("span",{id:"github-token-help",className:"github-field-help",children:"Token 仅用于本次提交,不会保存在浏览器或写入 PR"}),s.token?o.jsx("span",{id:"github-token-error",className:"github-field-error",role:"alert",children:s.token}):null]}),l?o.jsx("div",{className:"github-submit-message is-error",role:"alert",children:l}):null,g?o.jsxs("div",{className:"github-submit-message is-success",role:"status",children:[o.jsxs("span",{children:["PR #",g.number," 已创建"]}),o.jsxs("a",{href:g.url,target:"_blank",rel:"noreferrer",children:["在 GitHub 查看",o.jsx(YY,{})]})]}):null,o.jsxs("div",{className:"github-form-actions",children:[o.jsxs("div",{className:"github-secrets-note",children:[o.jsx("strong",{children:"合并 PR 前,请在仓库的 GitHub Actions Secrets 中配置:"}),n.secrets.map(k=>o.jsx("span",{children:k},k))]}),o.jsx("button",{type:"submit",disabled:u,children:u?"提交 PR 中…":n.submitLabel})]})]})]})})]})}const Cbt=1050062,WY="1.0",Nbt="https://lf-static.applogcdn.com/obj/applog-sdk-static/log-sdk/collect/5/collect.js";class jbt{constructor(){zr(this,"enabled",!1);zr(this,"initialized",!1);zr(this,"pending",[]);zr(this,"userUniqueId","");zr(this,"initPromise")}init(t){return this.enabled=t.enabled,this.enabled?this.initPromise?this.initPromise:(this.initPromise=Promise.resolve().then(()=>{const n=this.bootstrapCollector();n("init",{app_id:Cbt,channel:"cn",disable_auto_pv:1}),this.userUniqueId&&n("config",{user_unique_id:this.userUniqueId}),n("config",{_staging_flag:t.environment==="prod"?0:1}),n("start"),this.initialized=!0;const i=this.pending;this.pending=[];for(const[r,s]of i)this.collect(r,s)}),this.initPromise):(this.pending=[],Promise.resolve())}identify(t){this.userUniqueId=t,this.initialized&&this.collect("config",{user_unique_id:t})}emit(t,n){if(this.enabled){if(this.initialized){this.collect(t,n);return}this.pending=[...this.pending.slice(-49),[t,n]]}}bootstrapCollector(){if(window.collectEvent)return window.collectEvent;window.LogAnalyticsObject="collectEvent";const t=function(){var r;(r=t.q)==null||r.push(arguments)};t.q=[],t.l=Date.now(),window.collectEvent=t;const n=document.createElement("script");return n.async=!0,n.src=Nbt,n.onerror=()=>{this.enabled=!1,t.q=[],console.warn("[telemetry] TEA SDK script failed to load")},document.head.appendChild(n),t}collect(t,n){var i;(i=window.collectEvent)==null||i.call(window,t,n)}}function Rbt(e){if(typeof e!="string"&&typeof e!="number")return;const t=String(e).trim();return/^[A-Za-z0-9_.:-]{1,64}$/.test(t)?t:void 0}function Ju(e,t){return t===void 0?{errorKind:e}:{errorKind:e,errorCode:t}}function $a(e,t={}){const n=e!==null&&typeof e=="object"?e:{},i=Rbt(n.code),r=typeof n.name=="string"?n.name:"";if(r==="RuntimeProbeError")return Ju("runtime_probe_error",i);if(r==="AbortError")return Ju("abort",i);if(r==="RuntimeAccessDeniedError"||r==="AuthError")return Ju("auth",i);if(t.phase==="build")return Ju("build_failed",i);if(r==="TimeoutError")return Ju("timeout",i);if(r==="NetworkError"||r==="TypeError")return Ju("network",i);if(r==="ValidationError")return Ju("validation",i);if(r==="ServerError")return Ju("server",i);const s=typeof n.status=="number"&&Number.isInteger(n.status)?n.status:void 0;if(s===void 0||s<400||s>599)return Ju("unknown",i);const a=String(s);return s===401||s===403?{errorKind:"auth",errorCode:a}:s===400||s===409||s===422?{errorKind:"validation",errorCode:a}:s>=500?{errorKind:"server",errorCode:a}:{errorKind:"unknown",errorCode:a}}const Ibt=["schema_version","event_id","operation_id","user_pool_id","studio_deploy_id","vefaas_application_id","vefaas_function_id","studio_region","studio_project","studio_version","environment","cloud_provider","account_id","user_role","user_source","page_instance_id"],Dbt={studio_entry_viewed:["auth_state"],studio_session_started:["agents_source"],studio_agent_deploy:["status","agent_id","deploy_action","deploy_source","create_mode","ai_assisted","deploy_region","runtime_network_type","feishu_enabled","runtime_id","duration_ms","failed_phase","error_kind","error_code"],studio_sandbox_create:["status","sandbox_kind","sandbox_source","sandbox_id","duration_ms","error_kind","error_code"],studio_agent_debug:["status","agent_id","variant_type","debug_run_id","duration_ms","failed_phase","error_kind","error_code"],studio_agent_connect:["status","target_id","agent_kind","connect_source","runtime_region","runtime_is_mine","sandbox_status","duration_ms","error_kind","error_code"],studio_agent_message:["status","agent_id","agent_kind","message_source","session_state","session_id","duration_ms","failed_phase","error_kind","error_code"],studio_agent_source_download:["status","agent_id","deploy_action","deploy_source","create_mode","ai_assisted","duration_ms","file_count","zip_size_bytes","error_kind","error_code"]};function Pbt(e){return typeof e=="string"||typeof e=="number"&&Number.isFinite(e)}function ZY(e,t){const n=new Set([...Ibt,...Dbt[e]]),i={};for(const[r,s]of Object.entries(t))!n.has(r)||!Pbt(s)||(i[r]=typeof s=="string"?s.slice(0,256):s);return i}function Mbt(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`}function Lbt(){return typeof performance<"u"?performance.now():Date.now()}function _g(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}class $bt{constructor(t){zr(this,"sink");zr(this,"createId");zr(this,"now");zr(this,"pageInstanceId");zr(this,"context");zr(this,"identity");zr(this,"entryViewed",!1);zr(this,"sessionStarted",!1);this.sink=t.sink,this.createId=t.createId??Mbt,this.now=t.now??Lbt,this.pageInstanceId=this.createId()}setContext(t){var n;this.context={...t,accountId:((n=t.accountId)==null?void 0:n.trim())??""}}identify(t){var i,r,s;const n=t.userUniqueId.trim();n&&(this.identity&&this.identity.userUniqueId!==n&&(this.pageInstanceId=this.createId(),this.sessionStarted=!1),this.identity={...t,userUniqueId:n,accountId:((i=t.accountId)==null?void 0:i.trim())??""},(s=(r=this.sink).identify)==null||s.call(r,n))}trackStudioSessionStarted(t){this.sessionStarted||!this.context||!this.identity||(this.sessionStarted=!0,this.emit("studio_session_started",{agents_source:t.agentsSource}))}trackStudioEntryViewed(t){if(this.entryViewed||!this.context)return;this.entryViewed=!0;const n=ZY("studio_entry_viewed",_g({schema_version:WY,event_id:this.createId(),user_pool_id:this.context.userPoolId,studio_deploy_id:this.context.studioDeployId,vefaas_application_id:this.context.applicationId,vefaas_function_id:this.context.functionId,studio_region:this.context.studioRegion,studio_project:this.context.studioProject,studio_version:this.context.studioVersion,environment:this.context.environment,cloud_provider:this.context.cloudProvider,account_id:this.context.accountId,page_instance_id:this.pageInstanceId,auth_state:t.authState}));this.sink.emit("studio_entry_viewed",n)}beginAgentDeploy(t){return this.beginOperation("studio_agent_deploy",{agent_id:t.agentId,deploy_action:t.deployAction,deploy_source:t.deploySource,create_mode:t.createMode,ai_assisted:t.aiAssisted,deploy_region:t.deployRegion,runtime_network_type:t.runtimeNetworkType,feishu_enabled:t.feishuEnabled},n=>({runtime_id:n.runtimeId}),n=>({failed_phase:n.failedPhase,error_kind:n.errorKind,error_code:n.errorCode}))}beginSandboxCreate(t){return this.beginOperation("studio_sandbox_create",{sandbox_kind:t.sandboxKind,sandbox_source:t.sandboxSource},n=>({sandbox_id:n.sandboxId}),n=>({error_kind:n.errorKind,error_code:n.errorCode}))}beginAgentDebug(t){return this.beginOperation("studio_agent_debug",{agent_id:t.agentId,variant_type:t.variantType},n=>({debug_run_id:n.debugRunId}),n=>({failed_phase:n.failedPhase,error_kind:n.errorKind,error_code:n.errorCode}))}beginAgentConnect(t){return this.beginOperation("studio_agent_connect",{target_id:t.targetId,agent_kind:t.agentKind,connect_source:t.connectSource},n=>_g({runtime_region:n.runtimeRegion,runtime_is_mine:n.runtimeIsMine,sandbox_status:n.sandboxStatus}),n=>_g({error_kind:n.errorKind,error_code:n.errorCode}))}beginAgentMessage(t){return this.beginOperation("studio_agent_message",_g({agent_id:t.agentId,agent_kind:t.agentKind,message_source:t.messageSource,session_state:t.sessionState,session_id:t.sessionId}),n=>({session_id:n.sessionId}),n=>_g({session_id:n.sessionId,failed_phase:n.failedPhase,error_kind:n.errorKind,error_code:n.errorCode}))}beginAgentSourceDownload(t){return this.beginOperation("studio_agent_source_download",{agent_id:t.agentId,deploy_action:t.deployAction,deploy_source:t.deploySource,create_mode:t.createMode,ai_assisted:t.aiAssisted},n=>({file_count:n.fileCount,zip_size_bytes:n.zipSizeBytes}),n=>({file_count:n.fileCount,error_kind:n.errorKind,error_code:n.errorCode}))}beginOperation(t,n,i,r){const s=this.createId(),a=this.now(),l=!!(this.context&&this.identity);let c=!1;l&&this.emit(t,{...n,status:"started"},s);const u=(d,f)=>{c||(c=!0,l&&this.emit(t,{...n,...f,status:d,duration_ms:Math.max(0,this.now()-a)},s))};return{operationId:s,succeed:d=>u("succeeded",i(d)),fail:d=>u("failed",r(d))}}emit(t,n,i){if(!this.context||!this.identity)return;const r=ZY(t,_g({schema_version:WY,event_id:this.createId(),operation_id:i,user_pool_id:this.context.userPoolId,studio_deploy_id:this.context.studioDeployId,vefaas_application_id:this.context.applicationId,vefaas_function_id:this.context.functionId,studio_region:this.context.studioRegion,studio_project:this.context.studioProject,studio_version:this.context.studioVersion,environment:this.context.environment,cloud_provider:this.context.cloudProvider,account_id:this.identity.accountId,user_role:this.identity.userRole,user_source:this.identity.userSource,page_instance_id:this.pageInstanceId,...n}));this.sink.emit(t,r)}}const ube=new jbt,Fu=new $bt({sink:ube});function Bbt(e){return ube.init(e)}function Qbt(e){Fu.setContext(e)}function Fbt(e){Fu.identify(e)}function Ubt(e){Fu.trackStudioEntryViewed(e)}function zbt(e){Fu.trackStudioSessionStarted(e)}function dbe(e){return Fu.beginAgentDeploy(e)}function Vbt(e){return Fu.beginSandboxCreate(e)}function qbt(e){return Fu.beginAgentDebug(e)}function tD(e){return Fu.beginAgentConnect(e)}function KY(e){return Fu.beginAgentMessage(e)}function fbe(e){return Fu.beginAgentSourceDownload(e)}const Hbt=/^[A-Za-z_][A-Za-z0-9_]*$/;function _v(e){return e.trim().length===0?"名称为必填项":e==="user"?"user 是 Google ADK 保留名称,请使用其他名称":Hbt.test(e)?null:"名称须以英文字母或下划线开头,且只能包含英文字母、数字和下划线"}function Xbt(e){const t=new Set,n=new Set,i=r=>{_v(r.name)===null&&(t.has(r.name)?n.add(r.name):t.add(r.name)),r.subAgents.forEach(i)};return i(e),n}function Gbt(e){return{...sl(),name:e,description:"一个通过飞书接收消息并提供帮助的智能助手。",instruction:"你是一个通过飞书为用户提供帮助的智能助手。准确理解用户问题,给出简洁、可靠的回答;信息不足时先提问澄清,不要臆造事实。",deployment:{feishuEnabled:!0}}}async function Ybt(e){const t=Gbt(e.agentName),n=await p$(t);return lO(n.name,n.files,{region:e.region,projectName:"default"},{taskId:e.taskId,sessionStorage:"in-memory",minInstance:1,maxInstance:1,description:t.description,im:{feishu:{enabled:!0}},envs:[{key:"FEISHU_APP_ID",value:e.appId},{key:"FEISHU_APP_SECRET",value:e.appSecret}],onStage:e.onStage})}const cc=[{value:"cn-beijing",label:"北京"},{value:"cn-shanghai",label:"上海"}],hbe=[{phase:"prepare",label:"生成智能体"},{phase:"build",label:"构建镜像"},{phase:"deploy",label:"创建 Runtime"},{phase:"publish",label:"发布服务"}];function Wbt(e){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",...e,children:o.jsx("path",{d:"m9.8 3.5-4.5 4.5 4.5 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Zbt(e){return o.jsx("svg",{viewBox:"0 0 18 18",fill:"none","aria-hidden":"true",...e,children:o.jsx("path",{d:"m5 7 4 4 4-4",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})})}function JY(e){return o.jsx("svg",{viewBox:"0 0 18 18",fill:"none","aria-hidden":"true",...e,children:o.jsx("path",{d:"m4 9.2 3.1 3.1L14 5.8",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})})}function Kbt(e){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",...e,children:o.jsx("path",{d:"M6.5 4H4.8A1.8 1.8 0 0 0 3 5.8v5.4A1.8 1.8 0 0 0 4.8 13h5.4a1.8 1.8 0 0 0 1.8-1.8V9.5M9 3h4v4M12.5 3.5 7.2 8.8",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}function Jbt(e){if(!e||e==="upload")return 0;const t=hbe.findIndex(n=>n.phase===e);return t<0?0:t}function nD(e){switch(e){case"prepare":case"upload":case"build":case"deploy":case"publish":case"update":case"evaluation":return e;default:return"unknown"}}function eOt({onBack:e}){var ue;const[t,n]=m.useState("feishu_assistant"),[i,r]=m.useState(""),[s,a]=m.useState(""),[l,c]=m.useState(!1),[u,d]=m.useState("cn-beijing"),[f,h]=m.useState(!1),[p,b]=m.useState(""),[g,O]=m.useState(""),[y,v]=m.useState(""),[x,w]=m.useState("idle"),[E,S]=m.useState(null),[k,T]=m.useState(""),[_,C]=m.useState(null),N=m.useRef(null),I=m.useRef(null),B=m.useRef([]),D=m.useRef(0),L=m.useRef(null),j=m.useRef(null),P=m.useRef("prepare"),M=m.useRef(!1),U=m.useRef(!0),$=["preparing","running","cancelling"].includes(x);m.useEffect(()=>(U.current=!0,()=>{U.current=!1}),[]),m.useEffect(()=>{var de;if(!f)return;(de=B.current[D.current])==null||de.focus();const K=Oe=>{Oe.target instanceof Node&&N.current&&!N.current.contains(Oe.target)&&h(!1)},ee=Oe=>{var Ne;Oe.key==="Escape"&&(h(!1),(Ne=I.current)==null||Ne.focus())};return window.addEventListener("pointerdown",K),window.addEventListener("keydown",ee),()=>{window.removeEventListener("pointerdown",K),window.removeEventListener("keydown",ee)}},[f]);const G=K=>{K.key==="Enter"&&(K.nativeEvent.isComposing||K.nativeEvent.keyCode===229)&&K.preventDefault()},z=()=>{const K=_v(t.trim())??"",ee=i.trim()?"":"请输入飞书 App ID",de=s.trim()?"":"请输入飞书 App Secret";return b(K),O(ee),v(de),!K&&!ee&&!de},F=async K=>{if(K.preventDefault(),!z()||$)return;const ee=crypto.randomUUID();L.current=ee,P.current="prepare",M.current=!1,w("preparing"),S(null),T(""),C(null);const de=dbe({agentId:String(t.trim()),deployAction:"create",deploySource:"feishu_automation",createMode:"feishu_template",aiAssisted:0,deployRegion:String(u),runtimeNetworkType:"public",feishuEnabled:1});j.current=de;try{const Oe=await Ybt({agentName:t.trim(),appId:i.trim(),appSecret:s.trim(),region:u,taskId:ee,onStage:Ne=>{P.current=Ne.phase||"deploy",!(!U.current||M.current)&&(w("running"),S(Ne))}});if(M.current){de.fail({failedPhase:nD(P.current),errorKind:"abort"});return}if(de.succeed({runtimeId:String(Oe.runtimeId||"")}),!U.current)return;C(Oe),a(""),c(!1),w("succeeded")}catch(Oe){if(de.fail({failedPhase:nD(P.current),...M.current?{errorKind:"abort"}:$a(Oe,{phase:P.current})}),!U.current||M.current)return;w("failed"),T(Oe instanceof Error?Oe.message:String(Oe))}finally{L.current===ee&&(L.current=null),j.current===de&&(j.current=null)}},q=async()=>{var ee;const K=L.current;if(!(!K||x!=="running")&&window.confirm("取消部署将停止任务并清理已创建的 Runtime,确定继续吗?")){M.current=!0,w("cancelling"),T("");try{await kie(K),(ee=j.current)==null||ee.fail({failedPhase:nD(P.current),errorKind:"abort"}),U.current&&w("cancelled")}catch(de){if(M.current=!1,!U.current)return;w("failed"),T(de instanceof Error?de.message:String(de))}}},te=Jbt((E==null?void 0:E.phase)??null),ce=!!(t.trim()&&i.trim()&&s.trim()&&!$),be=cc.find(K=>K.value===u);return o.jsxs("div",{className:"feishu-integration-page",children:[o.jsxs("header",{className:"feishu-integration-header",children:[o.jsx("button",{type:"button",className:"feishu-back",onClick:e,"aria-label":"返回自动化列表",disabled:$,children:o.jsx(Wbt,{})}),o.jsx("img",{className:"feishu-integration-logo",src:BC,alt:"","aria-hidden":"true"}),o.jsxs("div",{children:[o.jsx("h1",{children:"飞书机器人"}),o.jsx("p",{children:"创建一个由 AgentKit Runtime 驱动的飞书智能体"})]})]}),o.jsx("div",{className:"feishu-integration-layout",children:o.jsxs("section",{className:"feishu-section-panel",children:[o.jsx("p",{className:"feishu-panel-description",children:"填写已发布飞书应用的凭据,Studio 将生成 basic 智能体、创建独立 Runtime,并启用飞书消息长连接。"}),o.jsxs("form",{className:"feishu-form",onSubmit:F,onKeyDown:G,noValidate:!0,children:[o.jsxs("div",{className:"feishu-field-grid",children:[o.jsxs("div",{className:"feishu-field",children:[o.jsx("label",{htmlFor:"feishu-agent-name",children:"智能体名称"}),o.jsx("input",{id:"feishu-agent-name",value:t,maxLength:64,disabled:$,onChange:K=>{n(K.target.value),p&&b("")},onBlur:()=>b(_v(t.trim())??""),"aria-invalid":!!p,"aria-describedby":`feishu-agent-name-help${p?" feishu-agent-name-error":""}`}),o.jsx("span",{id:"feishu-agent-name-help",className:"feishu-field-help",children:"将作为新 Runtime 中的根智能体名称"}),p?o.jsx("span",{id:"feishu-agent-name-error",className:"feishu-field-error",role:"alert",children:p}):null]}),o.jsxs("div",{className:"feishu-field",children:[o.jsx("label",{id:"feishu-region-label",children:"部署地域"}),o.jsxs("div",{className:"feishu-region-picker",ref:N,children:[o.jsxs("button",{ref:I,type:"button",className:"feishu-region-trigger",disabled:$,"aria-haspopup":"listbox","aria-expanded":f,"aria-labelledby":"feishu-region-label feishu-region-value",onClick:()=>{D.current=cc.findIndex(K=>K.value===u),h(K=>!K)},onKeyDown:K=>{K.key!=="ArrowDown"&&K.key!=="ArrowUp"||(K.preventDefault(),D.current=K.key==="ArrowUp"?cc.length-1:cc.findIndex(ee=>ee.value===u),h(!0))},children:[o.jsx("span",{id:"feishu-region-value",children:be.label}),o.jsx(Zbt,{})]}),f?o.jsx("div",{className:"feishu-region-menu",role:"listbox","aria-label":"部署地域",onKeyDown:K=>{var Oe;const ee=B.current.findIndex(Ne=>Ne===document.activeElement);let de=null;K.key==="ArrowDown"?de=(ee+1)%cc.length:K.key==="ArrowUp"?de=(ee-1+cc.length)%cc.length:K.key==="Home"?de=0:K.key==="End"?de=cc.length-1:K.key==="Tab"&&h(!1),de!==null&&(K.preventDefault(),(Oe=B.current[de])==null||Oe.focus())},children:cc.map(K=>o.jsx("button",{ref:ee=>{const de=cc.findIndex(Oe=>Oe.value===K.value);B.current[de]=ee},type:"button",role:"option","aria-selected":u===K.value,className:`feishu-region-option${u===K.value?" is-selected":""}`,onClick:()=>{var ee;d(K.value),h(!1),(ee=I.current)==null||ee.focus()},children:K.label},K.value))}):null]}),o.jsx("span",{className:"feishu-field-help",children:"Runtime 与构建产物将创建在该地域"})]}),o.jsxs("div",{className:"feishu-field",children:[o.jsx("label",{htmlFor:"feishu-app-id",children:"飞书 App ID"}),o.jsx("input",{id:"feishu-app-id",value:i,maxLength:128,autoComplete:"off",disabled:$,placeholder:"cli_xxxxxxxxxxxxxxxx",onChange:K=>{r(K.target.value),g&&O("")},onBlur:()=>O(i.trim()?"":"请输入飞书 App ID"),"aria-invalid":!!g,"aria-describedby":`feishu-app-id-help${g?" feishu-app-id-error":""}`}),o.jsx("span",{id:"feishu-app-id-help",className:"feishu-field-help",children:"来自飞书开放平台的应用凭证"}),g?o.jsx("span",{id:"feishu-app-id-error",className:"feishu-field-error",role:"alert",children:g}):null]}),o.jsxs("div",{className:"feishu-field",children:[o.jsx("label",{htmlFor:"feishu-app-secret",children:"飞书 App Secret"}),o.jsxs("div",{className:"feishu-secret-input",children:[o.jsx("input",{id:"feishu-app-secret",type:l?"text":"password",value:s,maxLength:256,autoComplete:"off",disabled:$,placeholder:"请输入 App Secret",onChange:K=>{a(K.target.value),y&&v("")},onBlur:()=>v(s.trim()?"":"请输入飞书 App Secret"),"aria-invalid":!!y,"aria-describedby":`feishu-app-secret-help${y?" feishu-app-secret-error":""}`}),o.jsx("button",{type:"button",disabled:$,onClick:()=>c(K=>!K),"aria-label":l?"隐藏 App Secret":"显示 App Secret",children:l?"隐藏":"显示"})]}),o.jsx("span",{id:"feishu-app-secret-help",className:"feishu-field-help",children:"仅写入新 Runtime 的环境变量"}),y?o.jsx("span",{id:"feishu-app-secret-error",className:"feishu-field-error",role:"alert",children:y}):null]})]}),x!=="idle"?o.jsxs("div",{className:`feishu-deployment-status is-${x}`,role:x==="failed"?"alert":"status",children:[o.jsxs("div",{className:"feishu-deployment-heading",children:[x==="preparing"?o.jsx(Vn,{as:"strong",children:"正在生成 basic 智能体"}):null,x==="running"?o.jsx(Vn,{as:"strong",children:(E==null?void 0:E.message)||"正在创建 Runtime"}):null,x==="cancelling"?o.jsx(Vn,{as:"strong",children:"正在取消部署"}):null,x==="succeeded"?o.jsxs("strong",{children:[o.jsx(JY,{}),"飞书机器人 Runtime 已创建"]}):null,x==="cancelled"?o.jsx("strong",{children:"部署已取消"}):null,x==="failed"?o.jsx("strong",{children:"创建失败"}):null]}),x==="preparing"||x==="running"||x==="cancelling"?o.jsx("ol",{className:"feishu-deployment-steps",children:hbe.map((K,ee)=>{const de=x==="running"&&eeK.value===(_.region||u)))==null?void 0:ue.label)||_.region}),_.consoleUrl?o.jsxs("a",{href:_.consoleUrl,target:"_blank",rel:"noreferrer",children:["打开 Runtime 控制台",o.jsx(Kbt,{})]}):null]}):null]}):null,o.jsxs("div",{className:"feishu-form-actions",children:[o.jsxs("div",{className:"feishu-secrets-note",children:[o.jsx("strong",{children:"凭据处理"}),o.jsx("span",{children:"App Secret 仅用于本次部署,不会写入生成源码或浏览器存储。"})]}),o.jsxs("div",{className:"feishu-action-buttons",children:[x==="running"?o.jsx("button",{type:"button",className:"feishu-cancel",onClick:()=>void q(),children:"取消部署"}):null,o.jsx("button",{type:"submit",className:"feishu-submit",disabled:!ce,children:$?"正在创建…":"创建飞书机器人 Runtime"})]})]})]})]})})]})}async function V9(e,t,n,i=Eo){var s;const r=await Bn(e,{...t,headers:{accept:"application/json",...t.headers},signal:n},i);if(!r.ok){let a="";try{a=((s=(await r.json()).detail)==null?void 0:s.trim())||""}catch{}throw new Error(a||`请求失败 (${r.status})`)}return r.json()}function tOt(e){return V9("/web/coding-agents/capabilities",{method:"GET"},e,X4)}function nOt(e,t){return V9(`/web/coding-agents/skills/${encodeURIComponent(e)}/preview`,{method:"GET"},t)}function iOt(e,t){return V9("/web/coding-agents/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)},t)}const rOt="data:image/svg+xml,%3csvg%20width='16'%20height='16'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3crect%20width='16'%20height='16'%20rx='3.692'%20fill='%231A1B1D'/%3e%3cpath%20d='M13.235%205.829V4.332H2.758v5.987h1.496v1.496h8.981V5.828Zm-1.497%204.49H4.254V5.83h7.484v4.49Z'%20fill='%2332F08C'/%3e%3cpath%20d='M6.937%206.993%205.88%208.051%206.937%209.11%207.995%208.05%206.937%206.993ZM9.931%206.992%208.873%208.05%209.931%209.11%2010.99%208.05%209.93%206.992Z'%20fill='%2332F08C'/%3e%3c/svg%3e";function sOt(){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:o.jsx("path",{d:"m4 4 8 8m0-8-8 8",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}function eW(){return o.jsxs("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[o.jsx("path",{d:"M4 1.8h5l3 3V14H4z",stroke:"currentColor",strokeWidth:"1.2",strokeLinejoin:"round"}),o.jsx("path",{d:"M9 1.8V5h3M6 8h4M6 10.5h4",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]})}function tW(){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:o.jsx("path",{d:"M1.8 4.5h4l1.2-1.3h2.2l1.2 1.3h3.8v8H1.8z",stroke:"currentColor",strokeWidth:"1.2",strokeLinejoin:"round"})})}function aOt(e){return e instanceof DOMException&&e.name==="AbortError"}function oOt(e){return e instanceof Error&&e.message?e.message:"读取 Skill 文件失败"}function lOt(e){return e<1024?`${e} B`:`${(e/1024).toFixed(e<10*1024?1:0)} KB`}function cOt(e){const t=e.split("/");return t[t.length-1]??e}function uOt(e){const t=new Map;for(const n of e){const i=n.path.split("/"),r=i.length>1?i.slice(0,-1).join("/"):"";t.set(r,[...t.get(r)??[],n])}return Array.from(t,([n,i])=>({directory:n,files:i})).sort((n,i)=>n.directory?i.directory?n.directory.localeCompare(i.directory):1:-1)}function dOt({skill:e,onClose:t}){const n=m.useRef(null),i=m.useRef(null),r=m.useId(),s=m.useId(),[a,l]=m.useState(null),[c,u]=m.useState(""),[d,f]=m.useState(!0),[h,p]=m.useState(""),[b,g]=m.useState(0);m.useEffect(()=>{i.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const v=n.current;return v&&!v.open&&v.showModal(),()=>{var x;v!=null&&v.open&&v.close(),(x=i.current)==null||x.focus()}},[]),m.useEffect(()=>{const v=new AbortController;return f(!0),p(""),l(null),u(""),nOt(e.id,v.signal).then(x=>{if(v.signal.aborted)return;l(x);const w=x.files.find(E=>E.path==="SKILL.md")??x.files[0];u((w==null?void 0:w.path)??"")}).catch(x=>{!v.signal.aborted&&!aOt(x)&&p(oOt(x))}).finally(()=>{v.signal.aborted||f(!1)}),()=>v.abort()},[b,e.id]);const O=m.useMemo(()=>uOt((a==null?void 0:a.files)??[]),[a]),y=(a==null?void 0:a.files.find(v=>v.path===c))??null;return o.jsxs("dialog",{ref:n,className:"coding-agents-preview-dialog","aria-labelledby":r,"aria-describedby":s,onCancel:v=>{v.preventDefault(),t()},onMouseDown:v=>{const x=v.currentTarget.getBoundingClientRect();(v.clientXx.right||v.clientYx.bottom)&&t()},children:[o.jsxs("header",{className:"coding-agents-preview-header",children:[o.jsx("span",{className:"coding-agents-preview-mark",children:o.jsx(tW,{})}),o.jsxs("div",{children:[o.jsx("h2",{id:r,children:e.name}),o.jsx("p",{id:s,children:"只读浏览随 Studio 提供的 Skill 文件"})]}),o.jsx("button",{type:"button",autoFocus:!0,"aria-label":"关闭文件预览",onClick:t,children:o.jsx(sOt,{})})]}),d?o.jsxs("div",{className:"coding-agents-preview-state",children:[o.jsx("i",{}),"正在读取文件…"]}):h?o.jsxs("div",{className:"coding-agents-preview-state is-error",role:"alert",children:[o.jsx("span",{children:h}),o.jsx("button",{type:"button",onClick:()=>g(v=>v+1),children:"重试"})]}):o.jsxs("div",{className:"coding-agents-preview-layout",children:[o.jsxs("nav",{className:"coding-agents-preview-tree","aria-label":`${e.name} 文件`,children:[o.jsxs("div",{className:"coding-agents-preview-tree-title",children:[o.jsx("span",{children:"文件"}),o.jsx("small",{children:(a==null?void 0:a.files.length)??0})]}),o.jsx("div",{className:"coding-agents-preview-tree-scroll",children:O.map(v=>v.directory?o.jsxs("details",{open:!0,children:[o.jsxs("summary",{children:[o.jsx(tW,{}),o.jsx("span",{children:v.directory})]}),o.jsx("div",{children:v.files.map(x=>o.jsxs("button",{type:"button",className:c===x.path?"is-selected":"","aria-current":c===x.path?"true":void 0,onClick:()=>u(x.path),children:[o.jsx(eW,{}),o.jsx("span",{children:cOt(x.path)})]},x.path))})]},v.directory):v.files.map(x=>o.jsxs("button",{type:"button",className:c===x.path?"is-selected":"","aria-current":c===x.path?"true":void 0,onClick:()=>u(x.path),children:[o.jsx(eW,{}),o.jsx("span",{children:x.path})]},x.path)))})]}),o.jsx("section",{className:"coding-agents-preview-file","aria-label":"文件内容",children:y?o.jsxs(o.Fragment,{children:[o.jsxs("header",{children:[o.jsx("strong",{children:y.path}),o.jsx("span",{children:lOt(y.size)})]}),y.previewable&&y.content!==null?o.jsx("pre",{tabIndex:0,children:o.jsx("code",{children:y.content})}):o.jsx("div",{className:"coding-agents-preview-unavailable",children:"此文件不是可预览的 UTF-8 文本。"})]}):o.jsx("div",{className:"coding-agents-preview-unavailable",children:"没有可预览的文件。"})})]})]})}function fOt(e){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",...e,children:o.jsx("path",{d:"m9.8 3.5-4.5 4.5 4.5 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function hOt(e){return o.jsxs("svg",{viewBox:"0 0 32 32",fill:"none","aria-hidden":"true",...e,children:[o.jsx("rect",{x:"3.5",y:"5",width:"16",height:"16",rx:"4.5",stroke:"currentColor",strokeWidth:"1.5"}),o.jsx("path",{d:"m8.5 11-2.4 2.4 2.4 2.4M11 16.5h3.8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),o.jsx("circle",{cx:"24.5",cy:"10.5",r:"2.5",stroke:"currentColor",strokeWidth:"1.5"}),o.jsx("circle",{cx:"24.5",cy:"24.5",r:"2.5",stroke:"currentColor",strokeWidth:"1.5"}),o.jsx("path",{d:"M19.5 10.5H22M18.2 19l4.3 3.7M24.5 13v9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}function pOt(e){return o.jsx("svg",{viewBox:"0 0 32 32",fill:"none","aria-hidden":"true",...e,children:o.jsxs("g",{stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",children:[o.jsx("path",{d:"M16 4.5v7M16 20.5v7"}),o.jsx("path",{d:"m9.3 6.3 3.5 6.1M19.2 19.6l3.5 6.1"}),o.jsx("path",{d:"m5.9 11.1 6.2 3.5M19.9 17.4l6.2 3.5"}),o.jsx("path",{d:"M4.7 16h7M20.3 16h7"}),o.jsx("path",{d:"m5.9 20.9 6.2-3.5M19.9 14.6l6.2-3.5"}),o.jsx("path",{d:"m9.3 25.7 3.5-6.1M19.2 12.4l3.5-6.1"})]})})}function mOt(e){return o.jsxs("svg",{viewBox:"0 0 32 32",fill:"none","aria-hidden":"true",...e,children:[o.jsx("path",{d:"M15.8 4.2c2.4 0 4.5 1.2 5.7 3.1 2.2-.3 4.5.8 5.6 2.9 1.1 2 .8 4.4-.5 6.1 1.2 1.8 1.3 4.3.1 6.2-1.2 2-3.4 3-5.6 2.6-1.3 1.8-3.5 2.9-5.8 2.7-2.2-.2-4.1-1.5-5.1-3.4-2.2.1-4.4-1-5.4-3.1-1-2-.6-4.4.8-6.1-1.1-1.9-1.1-4.3.2-6.1 1.3-1.9 3.6-2.7 5.7-2.2 1.1-1.7 2.6-2.7 4.3-2.7Z",stroke:"currentColor",strokeWidth:"1.7",strokeLinejoin:"round"}),o.jsx("path",{d:"m10.7 12.2 3.1 3.8-3.1 3.8M17.1 20h4.3",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}function nW(e){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",...e,children:o.jsx("path",{d:"m3.4 8.2 3 3L12.8 5",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})})}function gOt(e){return o.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":"true",...e,children:[o.jsx("path",{d:"M2.8 6.3h14.4v8.3a1.6 1.6 0 0 1-1.6 1.6H4.4a1.6 1.6 0 0 1-1.6-1.6V6.3Z",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round"}),o.jsx("path",{d:"M2.8 6.3V5.1a1.4 1.4 0 0 1 1.4-1.4h3.4l1.5 1.6h6.5a1.6 1.6 0 0 1 1.6 1.6",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round"})]})}function bOt({agentId:e}){return e==="trae"?o.jsx("img",{src:rOt,alt:"","aria-hidden":"true"}):e==="claude-code"?o.jsx(pOt,{}):o.jsx(mOt,{})}function iW(e){return e instanceof DOMException&&e.name==="AbortError"}function rW(e,t){return e instanceof Error&&e.message?e.message:t}function OOt({onBack:e}){var C;const[t,n]=m.useState(null),[i,r]=m.useState(!0),[s,a]=m.useState(""),[l,c]=m.useState(0),[u,d]=m.useState(new Set),[f,h]=m.useState(new Set),[p,b]=m.useState(null),[g,O]=m.useState(!1),[y,v]=m.useState(null),x=m.useRef(null);m.useEffect(()=>{const N=new AbortController;return r(!0),a(""),tOt(N.signal).then(I=>{if(N.signal.aborted)return;n(I);const B=I.agents.filter(D=>D.available);d(D=>{const L=B.filter(j=>D.has(j.id));return new Set((L.length?L:B.slice(0,1)).map(j=>j.id))}),h(D=>{const L=I.skills.filter(j=>D.has(j.id));return new Set((L.length?L:I.skills).map(j=>j.id))})}).catch(I=>{!iW(I)&&!N.signal.aborted&&(n(null),a(rW(I,"检测本机客户端失败")))}).finally(()=>{N.signal.aborted||r(!1)}),()=>N.abort()},[l]),m.useEffect(()=>()=>{var N;return(N=x.current)==null?void 0:N.abort()},[]);const w=m.useMemo(()=>(t==null?void 0:t.agents.filter(N=>N.available&&u.has(N.id)))||[],[t,u]),E=m.useMemo(()=>(t==null?void 0:t.skills.filter(N=>f.has(N.id)))||[],[t,f]),S=!!(!g&&w.length&&E.length),k=(N,I)=>{!I||g||(v(null),d(B=>{const D=new Set(B);return D.has(N)?D.delete(N):D.add(N),D}))},T=N=>{g||(v(null),h(I=>{const B=new Set(I);return B.has(N)?B.delete(N):B.add(N),B}))},_=async()=>{var I;if(!S)return;(I=x.current)==null||I.abort();const N=new AbortController;x.current=N,O(!0),v(null);try{const B=await iOt({agents:w.map(L=>L.id),skills:E.map(L=>L.id)},N.signal);if(N.signal.aborted)return;const D=B.installations;v({tone:"success",message:`已为 ${w.length} 个客户端配置 ${E.length} 个 Skill`,details:D.map(L=>`${L.agentName} · ${L.skill} → ${L.displayPath}`)})}catch(B){!iW(B)&&!N.signal.aborted&&v({tone:"error",message:rW(B,"配置失败,请检查用户目录权限后重试")})}finally{x.current===N&&(x.current=null),N.signal.aborted||O(!1)}};return o.jsxs("section",{className:"coding-agents-page",children:[o.jsxs("header",{className:"coding-agents-header",children:[o.jsx("button",{type:"button",className:"coding-agents-back",onClick:e,disabled:g,"aria-label":"返回自动化列表",children:o.jsx(fOt,{})}),o.jsx(hOt,{className:"coding-agents-logo"}),o.jsxs("div",{children:[o.jsx("h1",{children:"配置 Coding Agents"}),o.jsx("p",{children:"把随 Studio 提供的 AgentKit Skills 全局安装到本地编码客户端。"})]})]}),o.jsx("div",{className:"coding-agents-scroll",children:o.jsxs("div",{className:"coding-agents-content",children:[o.jsxs("section",{className:"coding-agents-section","aria-label":"选择 Coding Agent",children:[o.jsxs("div",{className:"coding-agents-section-heading",children:[o.jsxs("div",{children:[o.jsx("span",{children:"1"}),o.jsx("h2",{children:"本机客户端"})]}),o.jsx("button",{type:"button",onClick:()=>c(N=>N+1),disabled:i||g,children:"重新检测"})]}),i?o.jsxs("div",{className:"coding-agents-inline-state",children:[o.jsx("i",{}),"正在检测本机客户端…"]}):s?o.jsxs("div",{className:"coding-agents-error-row",role:"alert",children:[o.jsx("span",{children:s}),o.jsx("button",{type:"button",onClick:()=>c(N=>N+1),children:"重试"})]}):o.jsx("div",{className:"coding-agents-agent-grid",children:t==null?void 0:t.agents.map(N=>o.jsxs("button",{type:"button",className:`coding-agents-agent ${u.has(N.id)?"is-selected":""}`,"aria-pressed":u.has(N.id),disabled:!N.available||g,onClick:()=>k(N.id,N.available),title:N.available?N.name:N.reason,children:[o.jsx("span",{className:`coding-agents-agent-mark is-${N.id}`,children:o.jsx(bOt,{agentId:N.id})}),o.jsxs("span",{className:"coding-agents-agent-copy",children:[o.jsx("strong",{children:N.name}),o.jsx("small",{children:N.available?N.version||"已检测到客户端":N.reason})]}),o.jsx("span",{className:`coding-agents-status ${N.available?"is-ready":""}`,children:N.available?"可用":"未检测到"}),o.jsx("span",{className:"coding-agents-check",children:o.jsx(nW,{})})]},N.id))})]}),o.jsxs("section",{className:"coding-agents-section","aria-label":"选择内置 Skill",children:[o.jsx("div",{className:"coding-agents-section-heading",children:o.jsxs("div",{children:[o.jsx("span",{children:"2"}),o.jsx("h2",{children:"内置 Skills"})]})}),o.jsx("div",{className:"coding-agents-skill-list",children:t==null?void 0:t.skills.map(N=>o.jsxs("div",{className:`coding-agents-skill ${f.has(N.id)?"is-selected":""}`,children:[o.jsxs("label",{children:[o.jsx("input",{type:"checkbox",checked:f.has(N.id),onChange:()=>T(N.id),disabled:g}),o.jsx("span",{className:"coding-agents-skill-check","aria-hidden":"true",children:o.jsx(nW,{})}),o.jsxs("span",{children:[o.jsx("strong",{children:N.name}),o.jsx("small",{children:N.description})]})]}),o.jsx("button",{type:"button",onClick:()=>b(N),children:"查看文件"})]},N.id))}),o.jsxs("div",{className:"coding-agents-global","aria-label":"全局安装目录",children:[o.jsxs("div",{className:"coding-agents-global-heading",children:[o.jsx(gOt,{}),o.jsxs("div",{children:[o.jsx("strong",{children:"全局安装"}),o.jsx("span",{children:"配置后可在本机其他项目中使用"})]})]}),w.length?o.jsx("dl",{children:w.map(N=>o.jsxs("div",{children:[o.jsx("dt",{children:N.name}),o.jsx("dd",{children:N.globalSkillsPath})]},N.id))}):o.jsx("p",{children:"选择客户端后显示对应安装目录。"})]})]}),y?o.jsxs("div",{className:`coding-agents-result is-${y.tone}`,role:y.tone==="error"?"alert":"status",children:[o.jsx("strong",{children:y.message}),(C=y.details)!=null&&C.length?o.jsx("ul",{children:y.details.map(N=>o.jsx("li",{children:N},N))}):null]}):null,o.jsxs("div",{className:"coding-agents-actions",children:[o.jsx("span",{children:w.length?`已选择 ${w.length} 个客户端、${E.length} 个 Skill`:"请先选择客户端"}),o.jsx("button",{type:"button",onClick:()=>void _(),disabled:!S,children:g?"正在配置…":"配置"})]})]})}),p?o.jsx(dOt,{skill:p,onClose:()=>b(null)}):null]})}async function q9(e,t){const n=await e.json().catch(()=>null),i=typeof(n==null?void 0:n.detail)=="string"?n.detail:"";return new Error(i||`${t}(HTTP ${e.status})`)}async function yOt(e){const t=await Bn("/web/website-integrations",{cache:"no-store",signal:e});if(!t.ok)throw await q9(t,"加载网站集成失败");return(await t.json()).integrations??[]}async function xOt(e){const t=await Bn("/web/website-integrations",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw await q9(t,"创建网站集成失败");return t.json()}async function vOt(e){const t=await Bn(`/web/website-integrations/${encodeURIComponent(e)}`,{method:"DELETE"});if(!t.ok)throw await q9(t,"删除网站集成失败")}function wOt(e){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",...e,children:o.jsx("path",{d:"m9.8 3.5-4.5 4.5 4.5 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function sW(e){return o.jsxs("svg",{viewBox:"0 0 32 32",fill:"none","aria-hidden":"true",...e,children:[o.jsx("rect",{x:"3.5",y:"5",width:"20",height:"17",rx:"3.5",stroke:"currentColor",strokeWidth:"1.5"}),o.jsx("path",{d:"M4.5 10h18M8.5 7.5h.1M11.5 7.5h.1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),o.jsx("path",{d:"M17 18.5a5 5 0 0 1 5-5h1.5a5 5 0 0 1 5 5V23a5 5 0 0 1-5 5H22l-3.5 2.5v-3.3A5 5 0 0 1 17 23v-4.5Z",fill:"hsl(var(--background))",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round"}),o.jsx("path",{d:"M21 19h4M21 22.5h3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}function SOt(e){const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}async function EOt(e){const t=[];let n="";for(let i=0;i<10;i+=1){const r=await cO({nextToken:n||void 0,pageSize:100,region:"all",scope:"all"});if(e.aborted)return[];if(t.push(...r.runtimes),n=r.nextToken,!n)break}return t}function kOt({onBack:e}){const[t,n]=m.useState([]),[i,r]=m.useState([]),[s,a]=m.useState(""),[l,c]=m.useState(""),[u,d]=m.useState(""),[f,h]=m.useState(!0),[p,b]=m.useState(!1),[g,O]=m.useState(""),[y,v]=m.useState("");m.useEffect(()=>{const _=new AbortController;return h(!0),v(""),Promise.all([yOt(_.signal),EOt(_.signal)]).then(([C,N])=>{var B;if(_.signal.aborted)return;n(C),r(N),c(((B=C[0])==null?void 0:B.id)??"");const I=N[0];I&&a(`${I.region}::${I.runtimeId}`)}).catch(C=>{_.signal.aborted||v(C instanceof Error?C.message:"加载网站集成失败")}).finally(()=>{_.signal.aborted||h(!1)}),()=>_.abort()},[]);const x=m.useMemo(()=>i.map(_=>({value:`${_.region}::${_.runtimeId}`,label:_.name||_.runtimeId,description:`${_.region} · ${_.status}`,runtime:_})),[i]),w=m.useMemo(()=>new Map(x.map(_=>[_.value,_.runtime])),[x]),E=t.find(_=>_.id===l)??t[0],S=E?` - + +