mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-10-06 13:44:21 +08:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6170778de9 |
Generated
+1
-1
@@ -1128,7 +1128,7 @@ checksum = "52560adf09603e58c9a7ee1fe1dcb95a16927b17c127f0ac02d6e768a0e25bc1"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cursor-byok-desktop"
|
name = "cursor-byok-desktop"
|
||||||
version = "0.1.0-beta.2"
|
version = "0.1.0-beta.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"cursor-server",
|
"cursor-server",
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "cursor-byok-desktop",
|
"name": "cursor-byok-desktop",
|
||||||
"version": "0.1.0-beta.2",
|
"version": "0.1.0-beta.3",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "cursor-byok-desktop",
|
"name": "cursor-byok-desktop",
|
||||||
"version": "0.1.0-beta.2",
|
"version": "0.1.0-beta.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@floating-ui/dom": "^1.8.0",
|
"@floating-ui/dom": "^1.8.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cursor-byok-desktop",
|
"name": "cursor-byok-desktop",
|
||||||
"version": "0.1.0-beta.2",
|
"version": "0.1.0-beta.3",
|
||||||
"description": "Cursor BYOK desktop management application",
|
"description": "Cursor BYOK desktop management application",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cursor-byok-desktop"
|
name = "cursor-byok-desktop"
|
||||||
version = "0.1.0-beta.2"
|
version = "0.1.0-beta.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "Cursor BYOK",
|
"productName": "Cursor BYOK",
|
||||||
"version": "0.1.0-beta.2",
|
"version": "0.1.0-beta.3",
|
||||||
"identifier": "dev.cursorbyok.desktop",
|
"identifier": "dev.cursorbyok.desktop",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "npm run dev",
|
"beforeDevCommand": "npm run dev",
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import { CursorSettingsPage } from "./pages/CursorSettingsPage";
|
|||||||
import { HomePage } from "./pages/HomePage";
|
import { HomePage } from "./pages/HomePage";
|
||||||
import { ProvidersPage } from "./pages/ProvidersPage";
|
import { ProvidersPage } from "./pages/ProvidersPage";
|
||||||
import { SettingsPage } from "./pages/SettingsPage";
|
import { SettingsPage } from "./pages/SettingsPage";
|
||||||
import { checkForUpdate, hasNativeAppLifecycle } from "./native/appLifecycle";
|
|
||||||
import { useAppStore } from "./store/appStore";
|
import { useAppStore } from "./store/appStore";
|
||||||
|
import { updateStore } from "./store/updateStore";
|
||||||
|
|
||||||
export function App() {
|
export function App() {
|
||||||
return (
|
return (
|
||||||
@@ -47,11 +47,9 @@ function AppMessages() {
|
|||||||
}, [error, showMessage]);
|
}, [error, showMessage]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!hasNativeAppLifecycle()) return;
|
void updateStore.check().then((version) => {
|
||||||
void checkForUpdate().then(async (update) => {
|
if (!version) return;
|
||||||
if (!update) return;
|
showMessage(t("发现新版本 {version},可在设置中安装", { version }), { duration: 6_000 });
|
||||||
showMessage(t("发现新版本 {version},可在设置中安装", { version: update.version }), { duration: 6_000 });
|
|
||||||
await update.close();
|
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
// Startup checks are best-effort; manual checks in Settings report errors.
|
// Startup checks are best-effort; manual checks in Settings report errors.
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,3 +21,11 @@
|
|||||||
font-size: type.$font-size-xs;
|
font-size: type.$font-size-xs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.updateDot {
|
||||||
|
width: 7px;
|
||||||
|
height: 7px;
|
||||||
|
flex: 0 0 7px;
|
||||||
|
background: #ef4444;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import type { Update } from "@tauri-apps/plugin-updater";
|
|
||||||
import {
|
import {
|
||||||
checkForUpdate,
|
|
||||||
currentAppVersion,
|
currentAppVersion,
|
||||||
hasNativeAppLifecycle,
|
hasNativeAppLifecycle,
|
||||||
installUpdate,
|
|
||||||
readAutostart,
|
readAutostart,
|
||||||
writeAutostart,
|
writeAutostart,
|
||||||
} from "../../native/appLifecycle";
|
} from "../../native/appLifecycle";
|
||||||
|
import { updateStore, useUpdateStore } from "../../store/updateStore";
|
||||||
import { Button } from "../ui/Button";
|
import { Button } from "../ui/Button";
|
||||||
import { Switch } from "../ui/Switch";
|
import { Switch } from "../ui/Switch";
|
||||||
import { TitledCard } from "../ui/TitledCard";
|
import { TitledCard } from "../ui/TitledCard";
|
||||||
@@ -17,13 +15,10 @@ import styles from "./AppLifecycleSettingsCard.module.scss";
|
|||||||
export function AppLifecycleSettingsCard() {
|
export function AppLifecycleSettingsCard() {
|
||||||
const message = useMessage();
|
const message = useMessage();
|
||||||
const native = hasNativeAppLifecycle();
|
const native = hasNativeAppLifecycle();
|
||||||
const updateRef = useRef<Update | null>(null);
|
const { availableVersion, checking, installing } = useUpdateStore();
|
||||||
const [version, setVersion] = useState("…");
|
const [version, setVersion] = useState("…");
|
||||||
const [autostart, setAutostart] = useState(false);
|
const [autostart, setAutostart] = useState(false);
|
||||||
const [loadingAutostart, setLoadingAutostart] = useState(native);
|
const [loadingAutostart, setLoadingAutostart] = useState(native);
|
||||||
const [checking, setChecking] = useState(false);
|
|
||||||
const [installing, setInstalling] = useState(false);
|
|
||||||
const [availableVersion, setAvailableVersion] = useState<string | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let disposed = false;
|
let disposed = false;
|
||||||
@@ -34,12 +29,7 @@ export function AppLifecycleSettingsCard() {
|
|||||||
.catch((cause) => message(cause instanceof Error ? cause.message : String(cause)))
|
.catch((cause) => message(cause instanceof Error ? cause.message : String(cause)))
|
||||||
.finally(() => { if (!disposed) setLoadingAutostart(false); });
|
.finally(() => { if (!disposed) setLoadingAutostart(false); });
|
||||||
}
|
}
|
||||||
return () => {
|
return () => { disposed = true; };
|
||||||
disposed = true;
|
|
||||||
const update = updateRef.current;
|
|
||||||
updateRef.current = null;
|
|
||||||
if (update) void update.close();
|
|
||||||
};
|
|
||||||
}, [message, native]);
|
}, [message, native]);
|
||||||
|
|
||||||
const toggleAutostart = async (enabled: boolean) => {
|
const toggleAutostart = async (enabled: boolean) => {
|
||||||
@@ -57,29 +47,17 @@ export function AppLifecycleSettingsCard() {
|
|||||||
|
|
||||||
const checkUpdate = async () => {
|
const checkUpdate = async () => {
|
||||||
try {
|
try {
|
||||||
setChecking(true);
|
const nextVersion = await updateStore.check();
|
||||||
const previous = updateRef.current;
|
message(nextVersion ? t("发现新版本 {version}", { version: nextVersion }) : t("当前已是最新版本"));
|
||||||
updateRef.current = null;
|
|
||||||
if (previous) await previous.close();
|
|
||||||
const update = await checkForUpdate();
|
|
||||||
updateRef.current = update;
|
|
||||||
setAvailableVersion(update?.version ?? null);
|
|
||||||
message(update ? t("发现新版本 {version}", { version: update.version }) : t("当前已是最新版本"));
|
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
message(cause instanceof Error ? cause.message : String(cause));
|
message(cause instanceof Error ? cause.message : String(cause));
|
||||||
} finally {
|
|
||||||
setChecking(false);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateNow = async () => {
|
const updateNow = async () => {
|
||||||
const update = updateRef.current;
|
|
||||||
if (!update) return;
|
|
||||||
try {
|
try {
|
||||||
setInstalling(true);
|
await updateStore.install();
|
||||||
await installUpdate(update);
|
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
setInstalling(false);
|
|
||||||
message(cause instanceof Error ? cause.message : String(cause));
|
message(cause instanceof Error ? cause.message : String(cause));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -107,6 +85,7 @@ export function AppLifecycleSettingsCard() {
|
|||||||
{availableVersion
|
{availableVersion
|
||||||
? <Button size="small" variant="primary" disabled={installing} onClick={() => void updateNow()}>
|
? <Button size="small" variant="primary" disabled={installing} onClick={() => void updateNow()}>
|
||||||
{installing ? t("安装中…") : t("下载并安装")}
|
{installing ? t("安装中…") : t("下载并安装")}
|
||||||
|
<span className={styles.updateDot} aria-hidden="true" />
|
||||||
</Button>
|
</Button>
|
||||||
: <Button size="small" disabled={!native || checking} onClick={() => void checkUpdate()}>
|
: <Button size="small" disabled={!native || checking} onClick={() => void checkUpdate()}>
|
||||||
{checking ? t("检查中…") : t("检查更新")}
|
{checking ? t("检查中…") : t("检查更新")}
|
||||||
|
|||||||
@@ -527,7 +527,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 109,
|
"line": 87,
|
||||||
"column": 27
|
"column": 27
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -740,8 +740,8 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 67,
|
"line": 51,
|
||||||
"column": 24
|
"column": 29
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -754,7 +754,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 105,
|
"line": 83,
|
||||||
"column": 13
|
"column": 13
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -766,7 +766,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 220,
|
"line": 223,
|
||||||
"column": 14
|
"column": 14
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -805,7 +805,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 221,
|
"line": 224,
|
||||||
"column": 19
|
"column": 19
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -956,7 +956,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 222,
|
"line": 225,
|
||||||
"column": 20
|
"column": 20
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1243,18 +1243,6 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"4510b63fdcf7451f": {
|
|
||||||
"source": "Cursor 助手 v0.1.0",
|
|
||||||
"kind": "text",
|
|
||||||
"placeholders": [],
|
|
||||||
"refs": [
|
|
||||||
{
|
|
||||||
"file": "layouts/AppHeader.tsx",
|
|
||||||
"line": 20,
|
|
||||||
"column": 18
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"470049252e54de6a": {
|
"470049252e54de6a": {
|
||||||
"source": "成功占比:{rate}",
|
"source": "成功占比:{rate}",
|
||||||
"kind": "template",
|
"kind": "template",
|
||||||
@@ -1304,7 +1292,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 104,
|
"line": 82,
|
||||||
"column": 13
|
"column": 13
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1328,7 +1316,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 71,
|
"line": 73,
|
||||||
"column": 48
|
"column": 48
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1362,7 +1350,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 194,
|
"line": 196,
|
||||||
"column": 67
|
"column": 67
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1553,6 +1541,20 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"5d59857bf039cac9": {
|
||||||
|
"source": "Cursor 助手 v{version}",
|
||||||
|
"kind": "template",
|
||||||
|
"placeholders": [
|
||||||
|
"version"
|
||||||
|
],
|
||||||
|
"refs": [
|
||||||
|
{
|
||||||
|
"file": "layouts/AppHeader.tsx",
|
||||||
|
"line": 31,
|
||||||
|
"column": 18
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"5f8d556a9c47da3c": {
|
"5f8d556a9c47da3c": {
|
||||||
"source": "已关闭开机启动",
|
"source": "已关闭开机启动",
|
||||||
"kind": "text",
|
"kind": "text",
|
||||||
@@ -1560,7 +1562,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 50,
|
"line": 40,
|
||||||
"column": 40
|
"column": 40
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1572,7 +1574,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 226,
|
"line": 229,
|
||||||
"column": 11
|
"column": 11
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1696,7 +1698,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 102,
|
"line": 80,
|
||||||
"column": 18
|
"column": 18
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1775,7 +1777,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 74,
|
"line": 76,
|
||||||
"column": 47
|
"column": 47
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1838,8 +1840,8 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 67,
|
"line": 51,
|
||||||
"column": 76
|
"column": 78
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -1984,7 +1986,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "App.tsx",
|
"file": "App.tsx",
|
||||||
"line": 53,
|
"line": 52,
|
||||||
"column": 19
|
"column": 19
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -2061,7 +2063,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 112,
|
"line": 91,
|
||||||
"column": 37
|
"column": 37
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -2114,12 +2116,12 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 90,
|
"line": 68,
|
||||||
"column": 18
|
"column": 18
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 96,
|
"line": 74,
|
||||||
"column": 16
|
"column": 16
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -2240,7 +2242,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 228,
|
"line": 231,
|
||||||
"column": 16
|
"column": 16
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -2295,7 +2297,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 69,
|
"line": 71,
|
||||||
"column": 39
|
"column": 39
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -2523,7 +2525,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 87,
|
"line": 65,
|
||||||
"column": 29
|
"column": 29
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -2734,7 +2736,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 50,
|
"line": 40,
|
||||||
"column": 25
|
"column": 25
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -2746,7 +2748,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 109,
|
"line": 87,
|
||||||
"column": 39
|
"column": 39
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -2796,12 +2798,12 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 241,
|
"line": 244,
|
||||||
"column": 64
|
"column": 64
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 241,
|
"line": 244,
|
||||||
"column": 125
|
"column": 125
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -3020,7 +3022,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 233,
|
"line": 236,
|
||||||
"column": 24
|
"column": 24
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -3338,7 +3340,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 91,
|
"line": 69,
|
||||||
"column": 17
|
"column": 17
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -3408,7 +3410,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 180,
|
"line": 182,
|
||||||
"column": 54
|
"column": 54
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -3605,7 +3607,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 70,
|
"line": 72,
|
||||||
"column": 44
|
"column": 44
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -3788,7 +3790,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 75,
|
"line": 77,
|
||||||
"column": 53
|
"column": 53
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -4021,7 +4023,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
"file": "components/settings/AppLifecycleSettingsCard.tsx",
|
||||||
"line": 112,
|
"line": 91,
|
||||||
"column": 25
|
"column": 25
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -4113,7 +4115,7 @@
|
|||||||
"refs": [
|
"refs": [
|
||||||
{
|
{
|
||||||
"file": "layouts/AppLayout.tsx",
|
"file": "layouts/AppLayout.tsx",
|
||||||
"line": 72,
|
"line": 74,
|
||||||
"column": 48
|
"column": 48
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -83,7 +83,6 @@
|
|||||||
"42a1d9e5b037c210": "Bytes",
|
"42a1d9e5b037c210": "Bytes",
|
||||||
"42aa8e01e98c0d8c": "Total duration",
|
"42aa8e01e98c0d8c": "Total duration",
|
||||||
"43cb41d62de2d179": "Proxy requires authentication",
|
"43cb41d62de2d179": "Proxy requires authentication",
|
||||||
"4510b63fdcf7451f": "Cursor Assistant v0.1.0",
|
|
||||||
"470049252e54de6a": "Success rate: {rate}",
|
"470049252e54de6a": "Success rate: {rate}",
|
||||||
"48b970b568a7f8f9": "Proxy settings",
|
"48b970b568a7f8f9": "Proxy settings",
|
||||||
"48d8db17bae06246": "{count} total",
|
"48d8db17bae06246": "{count} total",
|
||||||
@@ -105,6 +104,7 @@
|
|||||||
"5a3bd99fa69a40c1": "Use public service",
|
"5a3bd99fa69a40c1": "Use public service",
|
||||||
"5ae715656ffbc35d": "Merge into the request body for every model from this provider.",
|
"5ae715656ffbc35d": "Merge into the request body for every model from this provider.",
|
||||||
"5c55a67935af8f45": "All",
|
"5c55a67935af8f45": "All",
|
||||||
|
"5d59857bf039cac9": "Cursor Assistant v{version}",
|
||||||
"5f8d556a9c47da3c": "Launch at login disabled",
|
"5f8d556a9c47da3c": "Launch at login disabled",
|
||||||
"5f9acfb945229062": "Are you sure you no longer want to see this ad?",
|
"5f9acfb945229062": "Are you sure you no longer want to see this ad?",
|
||||||
"5fd2ec5a6e9b654c": "Total: {cost}",
|
"5fd2ec5a6e9b654c": "Total: {cost}",
|
||||||
|
|||||||
@@ -83,7 +83,6 @@
|
|||||||
"42a1d9e5b037c210": "字节数",
|
"42a1d9e5b037c210": "字节数",
|
||||||
"42aa8e01e98c0d8c": "总耗时",
|
"42aa8e01e98c0d8c": "总耗时",
|
||||||
"43cb41d62de2d179": "代理需要认证",
|
"43cb41d62de2d179": "代理需要认证",
|
||||||
"4510b63fdcf7451f": "Cursor 助手 v0.1.0",
|
|
||||||
"470049252e54de6a": "成功占比:{rate}",
|
"470049252e54de6a": "成功占比:{rate}",
|
||||||
"48b970b568a7f8f9": "代理设置",
|
"48b970b568a7f8f9": "代理设置",
|
||||||
"48d8db17bae06246": "共 {count} 条",
|
"48d8db17bae06246": "共 {count} 条",
|
||||||
@@ -105,6 +104,7 @@
|
|||||||
"5a3bd99fa69a40c1": "使用公益服务",
|
"5a3bd99fa69a40c1": "使用公益服务",
|
||||||
"5ae715656ffbc35d": "合并到该上游所有模型的请求体。",
|
"5ae715656ffbc35d": "合并到该上游所有模型的请求体。",
|
||||||
"5c55a67935af8f45": "全部",
|
"5c55a67935af8f45": "全部",
|
||||||
|
"5d59857bf039cac9": "Cursor 助手 v{version}",
|
||||||
"5f8d556a9c47da3c": "已关闭开机启动",
|
"5f8d556a9c47da3c": "已关闭开机启动",
|
||||||
"5f9acfb945229062": "你确认不想再看到此广告吗?",
|
"5f9acfb945229062": "你确认不想再看到此广告吗?",
|
||||||
"5fd2ec5a6e9b654c": "合计:{cost}",
|
"5fd2ec5a6e9b654c": "合计:{cost}",
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
import appIcon from "../../src-tauri/icons/32x32.png";
|
import appIcon from "../../src-tauri/icons/32x32.png";
|
||||||
|
import { currentAppVersion } from "../native/appLifecycle";
|
||||||
import type { DesktopPlatform } from "./AppFrame";
|
import type { DesktopPlatform } from "./AppFrame";
|
||||||
import { WindowControls } from "./WindowControls";
|
import { WindowControls } from "./WindowControls";
|
||||||
import styles from "./AppHeader.module.scss";
|
import styles from "./AppHeader.module.scss";
|
||||||
@@ -10,6 +12,15 @@ type AppHeaderProps = {
|
|||||||
|
|
||||||
export function AppHeader({ platform, nativeDesktop }: AppHeaderProps) {
|
export function AppHeader({ platform, nativeDesktop }: AppHeaderProps) {
|
||||||
const showNativeUi = nativeDesktop && platform !== "macos";
|
const showNativeUi = nativeDesktop && platform !== "macos";
|
||||||
|
const [version, setVersion] = useState("…");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let disposed = false;
|
||||||
|
void currentAppVersion().then((next) => {
|
||||||
|
if (!disposed) setVersion(next);
|
||||||
|
});
|
||||||
|
return () => { disposed = true; };
|
||||||
|
}, []);
|
||||||
|
|
||||||
return <header className={styles.root}>
|
return <header className={styles.root}>
|
||||||
<div className={styles.dragLayer} data-tauri-drag-region aria-hidden="true" />
|
<div className={styles.dragLayer} data-tauri-drag-region aria-hidden="true" />
|
||||||
@@ -17,7 +28,7 @@ export function AppHeader({ platform, nativeDesktop }: AppHeaderProps) {
|
|||||||
{showNativeUi && <>
|
{showNativeUi && <>
|
||||||
<div className={styles.identity} aria-label="Cursor BYOK">
|
<div className={styles.identity} aria-label="Cursor BYOK">
|
||||||
<img src={appIcon} alt="" />
|
<img src={appIcon} alt="" />
|
||||||
<span>{t("Cursor 助手 v0.1.0")}</span>
|
<span>{t("Cursor 助手 v{version}", { version })}</span>
|
||||||
</div>
|
</div>
|
||||||
<WindowControls />
|
<WindowControls />
|
||||||
</>}
|
</>}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.menuUnreadDot {
|
.menuIndicatorDot {
|
||||||
width: 7px;
|
width: 7px;
|
||||||
height: 7px;
|
height: 7px;
|
||||||
flex: 0 0 7px;
|
flex: 0 0 7px;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { useMessage } from "../components/ui/message";
|
|||||||
import { VirtualList } from "../components/virtual/VirtualList";
|
import { VirtualList } from "../components/virtual/VirtualList";
|
||||||
import { useI18n } from "../i18n/store";
|
import { useI18n } from "../i18n/store";
|
||||||
import { appStore, useAppStore } from "../store/appStore";
|
import { appStore, useAppStore } from "../store/appStore";
|
||||||
|
import { useUpdateStore } from "../store/updateStore";
|
||||||
import styles from "./AppLayout.module.scss";
|
import styles from "./AppLayout.module.scss";
|
||||||
import { PageActionsTarget } from "./PageActions";
|
import { PageActionsTarget } from "./PageActions";
|
||||||
|
|
||||||
@@ -43,6 +44,7 @@ function loadStoredAdIds(key: string): Set<string> {
|
|||||||
|
|
||||||
export function AppLayout() {
|
export function AppLayout() {
|
||||||
const { busy } = useAppStore();
|
const { busy } = useAppStore();
|
||||||
|
const { availableVersion } = useUpdateStore();
|
||||||
const { locale } = useI18n();
|
const { locale } = useI18n();
|
||||||
const message = useMessage();
|
const message = useMessage();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
@@ -198,7 +200,7 @@ export function AppLayout() {
|
|||||||
? <Icon src={item.icon} size="1.3em" />
|
? <Icon src={item.icon} size="1.3em" />
|
||||||
: <Icon icon={item.icon} size="1.3em" />}
|
: <Icon icon={item.icon} size="1.3em" />}
|
||||||
<span>{item.label}</span>
|
<span>{item.label}</span>
|
||||||
{!tutorialRead && <span className={styles.menuUnreadDot} aria-hidden="true" />}
|
{!tutorialRead && <span className={styles.menuIndicatorDot} aria-hidden="true" />}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
: <div className={styles.navigationRow} key={item.path}>
|
: <div className={styles.navigationRow} key={item.path}>
|
||||||
@@ -207,6 +209,7 @@ export function AppLayout() {
|
|||||||
? <Icon src={item.icon} size="1.3em" />
|
? <Icon src={item.icon} size="1.3em" />
|
||||||
: <Icon icon={item.icon} size="1.3em" />}
|
: <Icon icon={item.icon} size="1.3em" />}
|
||||||
<span>{item.label}</span>
|
<span>{item.label}</span>
|
||||||
|
{item.path === "/settings" && availableVersion && <span className={styles.menuIndicatorDot} aria-hidden="true" />}
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>}
|
</div>}
|
||||||
</VirtualList>
|
</VirtualList>
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import { useSyncExternalStore } from "react";
|
||||||
|
import type { Update } from "@tauri-apps/plugin-updater";
|
||||||
|
import {
|
||||||
|
checkForUpdate,
|
||||||
|
hasNativeAppLifecycle,
|
||||||
|
installUpdate,
|
||||||
|
} from "../native/appLifecycle";
|
||||||
|
|
||||||
|
export type UpdateSnapshot = {
|
||||||
|
availableVersion: string | null;
|
||||||
|
checking: boolean;
|
||||||
|
installing: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
let snapshot: UpdateSnapshot = {
|
||||||
|
availableVersion: null,
|
||||||
|
checking: false,
|
||||||
|
installing: false,
|
||||||
|
};
|
||||||
|
let availableUpdate: Update | null = null;
|
||||||
|
let pendingCheck: Promise<string | null> | null = null;
|
||||||
|
const listeners = new Set<() => void>();
|
||||||
|
|
||||||
|
function update(patch: Partial<UpdateSnapshot>) {
|
||||||
|
snapshot = { ...snapshot, ...patch };
|
||||||
|
listeners.forEach((listener) => listener());
|
||||||
|
}
|
||||||
|
|
||||||
|
async function replaceAvailableUpdate(next: Update | null) {
|
||||||
|
const previous = availableUpdate;
|
||||||
|
availableUpdate = next;
|
||||||
|
update({ availableVersion: next?.version ?? null });
|
||||||
|
if (previous && previous !== next) await previous.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updateStore = {
|
||||||
|
subscribe(listener: () => void) {
|
||||||
|
listeners.add(listener);
|
||||||
|
return () => listeners.delete(listener);
|
||||||
|
},
|
||||||
|
getSnapshot: () => snapshot,
|
||||||
|
|
||||||
|
async check(): Promise<string | null> {
|
||||||
|
if (!hasNativeAppLifecycle()) return null;
|
||||||
|
if (pendingCheck) return pendingCheck;
|
||||||
|
update({ checking: true });
|
||||||
|
pendingCheck = (async () => {
|
||||||
|
const next = await checkForUpdate();
|
||||||
|
await replaceAvailableUpdate(next);
|
||||||
|
return next?.version ?? null;
|
||||||
|
})();
|
||||||
|
try {
|
||||||
|
return await pendingCheck;
|
||||||
|
} finally {
|
||||||
|
pendingCheck = null;
|
||||||
|
update({ checking: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async install(): Promise<void> {
|
||||||
|
const current = availableUpdate;
|
||||||
|
if (!current) return;
|
||||||
|
update({ installing: true });
|
||||||
|
try {
|
||||||
|
await installUpdate(current);
|
||||||
|
} finally {
|
||||||
|
update({ installing: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useUpdateStore(): UpdateSnapshot {
|
||||||
|
return useSyncExternalStore(updateStore.subscribe, updateStore.getSnapshot);
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ use crate::{
|
|||||||
blob_sync::BlobSynchronizer,
|
blob_sync::BlobSynchronizer,
|
||||||
checkpoint::CheckpointBuilder,
|
checkpoint::CheckpointBuilder,
|
||||||
context_sync::RequestContextSynchronizer,
|
context_sync::RequestContextSynchronizer,
|
||||||
|
interaction,
|
||||||
proto::agent::v1 as pb,
|
proto::agent::v1 as pb,
|
||||||
request,
|
request,
|
||||||
session::CursorSession,
|
session::CursorSession,
|
||||||
@@ -272,6 +273,9 @@ impl CursorActor {
|
|||||||
)) => {
|
)) => {
|
||||||
let _ = blob_sync.handle_client(message).await;
|
let _ = blob_sync.handle_client(message).await;
|
||||||
}
|
}
|
||||||
|
Some(pb::agent_client_message::Message::ClientHeartbeat(_)) => {
|
||||||
|
let _ = handle.emit(&interaction::heartbeat());
|
||||||
|
}
|
||||||
// TODO: ConversationAction has two different delivery paths that
|
// TODO: ConversationAction has two different delivery paths that
|
||||||
// must not be conflated:
|
// must not be conflated:
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ pub fn thinking_completed(elapsed: Duration) -> pb::AgentServerMessage {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn heartbeat() -> pb::AgentServerMessage {
|
||||||
|
server_interaction(pb::interaction_update::Message::Heartbeat(
|
||||||
|
pb::HeartbeatUpdate {},
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn arguments_delta(call: &ToolCall, delta: &str) -> Result<pb::AgentServerMessage> {
|
pub fn arguments_delta(call: &ToolCall, delta: &str) -> Result<pb::AgentServerMessage> {
|
||||||
Ok(server_interaction(
|
Ok(server_interaction(
|
||||||
pb::interaction_update::Message::PartialToolCall(pb::PartialToolCallUpdate {
|
pb::interaction_update::Message::PartialToolCall(pb::PartialToolCallUpdate {
|
||||||
|
|||||||
+102
-11
@@ -3,29 +3,24 @@ use axum::{
|
|||||||
http::{header, HeaderValue, Response, StatusCode},
|
http::{header, HeaderValue, Response, StatusCode},
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use std::convert::Infallible;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tokio_stream::StreamExt;
|
use tokio_stream::StreamExt;
|
||||||
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cursor::{observability::CursorTraceRecorder, CursorSessionRegistry},
|
cursor::{connect::END_STREAM_FLAG, observability::CursorTraceRecorder, CursorSessionRegistry},
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn stream(registry: &CursorSessionRegistry, request_id: &str) -> Result<Response<Body>> {
|
pub async fn stream(registry: &CursorSessionRegistry, request_id: &str) -> Result<Response<Body>> {
|
||||||
let handle = registry.get_or_create(request_id).await?;
|
let handle = registry.get_or_create(request_id).await?;
|
||||||
let mut receiver = handle.subscribe();
|
let receiver = handle.subscribe();
|
||||||
let trace = handle.trace().cloned();
|
let trace = handle.trace().cloned();
|
||||||
if let Some(trace) = &trace {
|
if let Some(trace) = &trace {
|
||||||
trace.response_started(StatusCode::OK.as_u16()).await;
|
trace.response_started(StatusCode::OK.as_u16()).await;
|
||||||
}
|
}
|
||||||
let body_stream = async_stream::stream! {
|
let body_stream = local_body_stream(receiver, handle.cancellation(), trace);
|
||||||
let mut trace = TraceStreamSink::new(trace, "byok_server");
|
|
||||||
while let Some(chunk) = receiver.recv().await {
|
|
||||||
trace.chunk(&chunk);
|
|
||||||
yield Ok::<Bytes, std::convert::Infallible>(chunk);
|
|
||||||
}
|
|
||||||
trace.finish(None);
|
|
||||||
};
|
|
||||||
let mut response = Response::new(Body::from_stream(body_stream));
|
let mut response = Response::new(Body::from_stream(body_stream));
|
||||||
*response.status_mut() = StatusCode::OK;
|
*response.status_mut() = StatusCode::OK;
|
||||||
response.headers_mut().insert(
|
response.headers_mut().insert(
|
||||||
@@ -41,6 +36,63 @@ pub async fn stream(registry: &CursorSessionRegistry, request_id: &str) -> Resul
|
|||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn local_body_stream(
|
||||||
|
mut receiver: mpsc::UnboundedReceiver<Bytes>,
|
||||||
|
cancellation: CancellationToken,
|
||||||
|
trace: Option<CursorTraceRecorder>,
|
||||||
|
) -> impl tokio_stream::Stream<Item = std::result::Result<Bytes, Infallible>> {
|
||||||
|
async_stream::stream! {
|
||||||
|
let mut guard = LocalRunGuard::new(cancellation);
|
||||||
|
let mut trace = TraceStreamSink::new(trace, "byok_server");
|
||||||
|
while let Some(chunk) = receiver.recv().await {
|
||||||
|
let terminal = is_end_stream_frame(&chunk);
|
||||||
|
trace.chunk(&chunk);
|
||||||
|
if terminal {
|
||||||
|
guard.complete();
|
||||||
|
trace.finish(None);
|
||||||
|
}
|
||||||
|
yield Ok::<Bytes, Infallible>(chunk);
|
||||||
|
if terminal {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
guard.complete();
|
||||||
|
trace.finish(None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_end_stream_frame(frame: &Bytes) -> bool {
|
||||||
|
frame
|
||||||
|
.first()
|
||||||
|
.is_some_and(|flags| flags & END_STREAM_FLAG != 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
struct LocalRunGuard {
|
||||||
|
cancellation: CancellationToken,
|
||||||
|
completed: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LocalRunGuard {
|
||||||
|
fn new(cancellation: CancellationToken) -> Self {
|
||||||
|
Self {
|
||||||
|
cancellation,
|
||||||
|
completed: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn complete(&mut self) {
|
||||||
|
self.completed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for LocalRunGuard {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
if !self.completed {
|
||||||
|
self.cancellation.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn upstream(
|
pub async fn upstream(
|
||||||
registry: CursorSessionRegistry,
|
registry: CursorSessionRegistry,
|
||||||
request_id: String,
|
request_id: String,
|
||||||
@@ -127,7 +179,11 @@ impl TraceStreamSink {
|
|||||||
|
|
||||||
impl Drop for TraceStreamSink {
|
impl Drop for TraceStreamSink {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.finish(None);
|
if self.sender.is_some() {
|
||||||
|
self.finish(Some(
|
||||||
|
"response stream dropped before completion".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,3 +199,38 @@ impl Drop for UpstreamRunGuard {
|
|||||||
.finish_upstream(self.request_id.clone(), self.generation);
|
.finish_upstream(self.request_id.clone(), self.generation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::cursor::{connect, proto::agent::v1 as pb};
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn local_stream_cancels_when_the_client_disconnects() {
|
||||||
|
let (sender, receiver) = mpsc::unbounded_channel();
|
||||||
|
let cancellation = CancellationToken::new();
|
||||||
|
sender
|
||||||
|
.send(connect::encode_message(&pb::AgentServerMessage::default()).unwrap())
|
||||||
|
.unwrap();
|
||||||
|
let mut stream = Box::pin(local_body_stream(receiver, cancellation.clone(), None));
|
||||||
|
|
||||||
|
stream.next().await.unwrap().unwrap();
|
||||||
|
|
||||||
|
drop(sender);
|
||||||
|
drop(stream);
|
||||||
|
assert!(cancellation.is_cancelled());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn terminal_frame_does_not_cancel_a_completed_local_run() {
|
||||||
|
let (sender, receiver) = mpsc::unbounded_channel();
|
||||||
|
let cancellation = CancellationToken::new();
|
||||||
|
sender.send(connect::encode_end_stream()).unwrap();
|
||||||
|
let mut stream = Box::pin(local_body_stream(receiver, cancellation.clone(), None));
|
||||||
|
|
||||||
|
let terminal = stream.next().await.unwrap().unwrap();
|
||||||
|
assert!(is_end_stream_frame(&terminal));
|
||||||
|
drop(stream);
|
||||||
|
assert!(!cancellation.is_cancelled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -140,11 +140,11 @@ impl Provider for OpenAiResponsesProvider {
|
|||||||
}
|
}
|
||||||
if text_open { text_open = false; yield ModelEvent::TextEnd; }
|
if text_open { text_open = false; yield ModelEvent::TextEnd; }
|
||||||
}
|
}
|
||||||
"response.reasoning_summary_text.delta" => {
|
"response.reasoning_summary_text.delta" | "response.reasoning_text.delta" => {
|
||||||
if !thinking_open { thinking_open = true; yield ModelEvent::ThinkingStart; }
|
if !thinking_open { thinking_open = true; yield ModelEvent::ThinkingStart; }
|
||||||
if let Some(delta) = value.get("delta").and_then(Value::as_str) { yield ModelEvent::ThinkingDelta(delta.into()); }
|
if let Some(delta) = value.get("delta").and_then(Value::as_str) { yield ModelEvent::ThinkingDelta(delta.into()); }
|
||||||
}
|
}
|
||||||
"response.reasoning_summary_text.done" => {
|
"response.reasoning_summary_text.done" | "response.reasoning_text.done" => {
|
||||||
if thinking_open { thinking_open = false; yield ModelEvent::ThinkingEnd; }
|
if thinking_open { thinking_open = false; yield ModelEvent::ThinkingEnd; }
|
||||||
}
|
}
|
||||||
"response.output_item.added" => {
|
"response.output_item.added" => {
|
||||||
|
|||||||
@@ -146,6 +146,54 @@ async fn registry_shutdown_cancels_runs_and_closes_run_sse_outputs() {
|
|||||||
assert_eq!(output.recv().await, None);
|
assert_eq!(output.recv().await, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn client_heartbeat_returns_a_server_protocol_heartbeat() {
|
||||||
|
let (_directory, store) = fixtures::temp_store().await;
|
||||||
|
let assets = PromptAssets::load(
|
||||||
|
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
.join("prompt/cursor")
|
||||||
|
.as_path(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let registry = CursorSessionRegistry::new(
|
||||||
|
store,
|
||||||
|
Arc::new(fake_provider::FakeProvider::default()),
|
||||||
|
PromptCompiler::new(assets),
|
||||||
|
Default::default(),
|
||||||
|
);
|
||||||
|
let handle = registry.get_or_create("heartbeat-run").await.unwrap();
|
||||||
|
let mut output = handle.subscribe();
|
||||||
|
|
||||||
|
handle
|
||||||
|
.command(CursorCommand::Append {
|
||||||
|
seqno: 0,
|
||||||
|
message: Box::new(pb::AgentClientMessage {
|
||||||
|
message: Some(pb::agent_client_message::Message::ClientHeartbeat(
|
||||||
|
pb::ClientHeartbeat {},
|
||||||
|
)),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let frame = tokio::time::timeout(std::time::Duration::from_secs(1), output.recv())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let (_, payload) = connect::decode_frames(&frame).unwrap().pop().unwrap();
|
||||||
|
let message = pb::AgentServerMessage::decode(payload).unwrap();
|
||||||
|
assert!(matches!(
|
||||||
|
message.message,
|
||||||
|
Some(pb::agent_server_message::Message::InteractionUpdate(
|
||||||
|
pb::InteractionUpdate {
|
||||||
|
message: Some(pb::interaction_update::Message::Heartbeat(_)),
|
||||||
|
}
|
||||||
|
))
|
||||||
|
));
|
||||||
|
|
||||||
|
registry.shutdown().await;
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn runtime_user_message_action_aborts_active_exec_before_canceled_end_stream() {
|
async fn runtime_user_message_action_aborts_active_exec_before_canceled_end_stream() {
|
||||||
let (_directory, store) = fixtures::temp_store().await;
|
let (_directory, store) = fixtures::temp_store().await;
|
||||||
|
|||||||
@@ -329,6 +329,37 @@ async fn openai_responses_raw_stream_does_not_invent_reasoning_effort() {
|
|||||||
assert_eq!(replayed, ["opaque-1", "opaque-2"]);
|
assert_eq!(replayed, ["opaque-1", "opaque-2"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn openai_responses_streams_openrouter_reasoning_text_events() {
|
||||||
|
let (base_url, _requests, server) = fixture_server(
|
||||||
|
"/v1/responses",
|
||||||
|
concat!(
|
||||||
|
"data: {\"type\":\"response.reasoning_text.delta\",\"delta\":\"still working\"}\n\n",
|
||||||
|
"data: {\"type\":\"response.reasoning_text.done\"}\n\n",
|
||||||
|
"data: {\"type\":\"response.completed\",\"response\":{}}\n\n",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let provider = OpenAiResponsesProvider::new(
|
||||||
|
reqwest::Client::new(),
|
||||||
|
config(ProviderKind::OpenAiResponses, base_url, None),
|
||||||
|
);
|
||||||
|
|
||||||
|
let events = collect(provider.stream(invocation(), CancellationToken::new())).await;
|
||||||
|
server.abort();
|
||||||
|
|
||||||
|
assert!(events
|
||||||
|
.iter()
|
||||||
|
.any(|event| matches!(event, ModelEvent::ThinkingStart)));
|
||||||
|
assert!(events.iter().any(
|
||||||
|
|event| matches!(event, ModelEvent::ThinkingDelta(delta) if delta == "still working")
|
||||||
|
));
|
||||||
|
assert!(events
|
||||||
|
.iter()
|
||||||
|
.any(|event| matches!(event, ModelEvent::ThinkingEnd)));
|
||||||
|
assert_eq!(events.last(), Some(&ModelEvent::Done(FinishReason::Stop)));
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn openai_responses_reasoning_item_done_closes_an_open_summary() {
|
async fn openai_responses_reasoning_item_done_closes_an_open_summary() {
|
||||||
let (base_url, _requests, server) = fixture_server(
|
let (base_url, _requests, server) = fixture_server(
|
||||||
|
|||||||
Reference in New Issue
Block a user