diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index f2637eb152..2c4a6b3e5c 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -6,15 +6,16 @@ name: Docker Publish # # 架构:ubuntu-latest 打 linux/amd64,ubuntu-24.04-arm 打 linux/arm64。 # 每个架构先在本机启动镜像并跑 live 启动测试,通过后才推送该架构 tag, -# 再合并为 :{version} / :latest 多架构清单。精简版同样打 :{version}-lite / :lite, -# 不含桌面、本地向量和 OCR。飞牛 Docker 版 FPK 各用一个标签, +# 再合并为 :{version} / :latest(精简版,不含桌面、本地向量和 OCR)。 +# 完整版打 :{version}-full / :full。飞牛 Docker 版 FPK 各用一个标签, # NAS 按本机架构拉取对应镜像层。某一架构启动失败(例如 ARM 上 Illegal # instruction / 退出码 132)只丢掉该架构,不挡住另一架构和后续 FPK。 # # 触发路径: # 1. 人工推送 v* tag → on.push.tags # 2. Auto Tag 用 GITHUB_TOKEN 推 tag 后显式 workflow_dispatch(token push 不会触发 push 工作流) -# 3. 在任意分支 Run workflow,填 tag=vX.Y.Z(用该分支的 workflow 文件,checkout 指定 tag) +# 3. 在修复分支 Run workflow,填 tag=vX.Y.Z。workflow_dispatch 检出所选 ref, +# 补构建能带上 Dockerfile 修复;tag 只决定镜像版本。tag push 仍检出该 tag。 # # 注意:workflow_dispatch 下 metadata-action 的 type=semver 不可靠, # 必须从 tag / 输入显式解析版本号。 @@ -26,7 +27,7 @@ name: Docker Publish # 拉取示例: # docker pull ghcr.io/tencentcloud/octop:latest # docker pull ghcr.io/tencentcloud/octop:0.9.28 -# docker pull ghcr.io/tencentcloud/octop:0.9.28-lite +# docker pull ghcr.io/tencentcloud/octop:0.9.28-full on: push: tags: @@ -112,7 +113,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - ref: ${{ needs.prepare.outputs.tag }} + ref: ${{ github.event_name == 'workflow_dispatch' && github.sha || needs.prepare.outputs.tag }} fetch-depth: 0 - name: Set up Docker Buildx @@ -139,9 +140,9 @@ jobs: images: | ${{ env.DOCKERHUB_USER != '' && format('{0}/octop', env.DOCKERHUB_USER) || '' }} ${{ needs.prepare.outputs.ghcr }} - # 单架构中间 tag。full → :{version}-{arch};lite → :{version}-lite-{arch}。 + # 单架构中间 tag。lite → :{version}-{arch};full → :{version}-full-{arch}。 tags: | - type=raw,value=${{ needs.prepare.outputs.version }}${{ matrix.variant == 'lite' && '-lite' || '' }}-${{ matrix.arch }} + type=raw,value=${{ needs.prepare.outputs.version }}${{ matrix.variant == 'full' && '-full' || '' }}-${{ matrix.arch }} # load 与 registry 导出不能同时开。先载入本机做启动测试,通过后再 docker push。 # docker 导出不支持 provenance,这里关掉,避免 --load 失败。 @@ -181,9 +182,10 @@ jobs: set -euo pipefail uv venv /tmp/octop-docker-test uv pip install --python /tmp/octop-docker-test/bin/python pytest pytest-asyncio + # 启动测试只调 docker。--noconftest 避免加载 integration conftest(需要 httpx / octop)。 /tmp/octop-docker-test/bin/pytest \ tests/integration/test_docker_image_boot.py::test_docker_image_runs_on_this_cpu_and_stays_disabled \ - -q --tb=short + -q --tb=short --noconftest - name: Push image env: @@ -254,7 +256,7 @@ jobs: fi if [ "${#sources[@]}" -lt 2 ]; then echo "::warning:::${tag_a} is not multi-arch. A package on the missing CPU will not run." - # 精简版对外是一份 x86/ARM 通用标签。缺任一架构就不要发,避免装上后拉取失败。 + # 完整版对外是一份 x86/ARM 通用标签。缺任一架构就不要发,避免装上后拉取失败。 if [ "$required" != "yes" ]; then echo "::warning::skip ${reg}:${tag_a} until both amd64 and arm64 exist" continue @@ -268,5 +270,6 @@ jobs: docker buildx imagetools inspect "${reg}:${tag_a}" done } + # 默认标签是精简版。完整版必须显式带 -full,且两个架构都在才发布。 publish_variant "" "$VER" latest yes - publish_variant "-lite" "${VER}-lite" lite no + publish_variant "-full" "${VER}-full" full no diff --git a/.github/workflows/fnos-build-fpk.yml b/.github/workflows/fnos-build-fpk.yml index 5e0dc241fc..91c55cae7b 100644 --- a/.github/workflows/fnos-build-fpk.yml +++ b/.github/workflows/fnos-build-fpk.yml @@ -78,7 +78,7 @@ jobs: needs: version runs-on: ubuntu-latest outputs: - lite: ${{ steps.wait.outputs.lite }} + full: ${{ steps.wait.outputs.full }} steps: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -97,40 +97,40 @@ jobs: VER: ${{ needs.version.outputs.version }} run: | set -euo pipefail - full="${IMAGE}:${VER}" - lite="${IMAGE}:${VER}-lite" - echo "Waiting for ${full}. ${lite} is optional and must already be multi-arch." - # 完整版清单要等两个架构 merge。精简版在完整版出现后再等几轮;缺了就只打完整包。 - lite_wait=0 + lite="${IMAGE}:${VER}" + full="${IMAGE}:${VER}-full" + echo "Waiting for ${lite}. ${full} is optional and must already be multi-arch." + # 默认标签是精简版。完整版在精简版出现后再等几轮;缺了就只打精简包。 + full_wait=0 for i in $(seq 1 120); do - full_ok=0 lite_ok=0 - if docker buildx imagetools inspect "$full" >/dev/null 2>&1; then - full_ok=1 - fi + full_ok=0 if docker buildx imagetools inspect "$lite" >/dev/null 2>&1; then lite_ok=1 fi - if [ "$full_ok" -eq 1 ] && [ "$lite_ok" -eq 1 ]; then - echo "lite=true" >> "$GITHUB_OUTPUT" - echo "Images ready: ${full} and ${lite}" - docker buildx imagetools inspect "$full" | head -20 + if docker buildx imagetools inspect "$full" >/dev/null 2>&1; then + full_ok=1 + fi + if [ "$lite_ok" -eq 1 ] && [ "$full_ok" -eq 1 ]; then + echo "full=true" >> "$GITHUB_OUTPUT" + echo "Images ready: ${lite} and ${full}" docker buildx imagetools inspect "$lite" | head -20 + docker buildx imagetools inspect "$full" | head -20 exit 0 fi - if [ "$full_ok" -eq 1 ]; then - lite_wait=$((lite_wait + 1)) - if [ "$lite_wait" -ge 6 ]; then - echo "lite=false" >> "$GITHUB_OUTPUT" - echo "::warning::${lite} was not published. The full FnOS package will still be built." - docker buildx imagetools inspect "$full" | head -20 + if [ "$lite_ok" -eq 1 ]; then + full_wait=$((full_wait + 1)) + if [ "$full_wait" -ge 6 ]; then + echo "full=false" >> "$GITHUB_OUTPUT" + echo "::warning::${full} was not published. The lite FnOS package will still be built." + docker buildx imagetools inspect "$lite" | head -20 exit 0 fi fi - echo "[$i/120] full=${full_ok} lite=${lite_ok}" + echo "[$i/120] lite=${lite_ok} full=${full_ok}" sleep 20 done - echo "::error::Timed out waiting for ${full}. Ensure Docker Publish finished for v${VER}." + echo "::error::Timed out waiting for ${lite}. Ensure Docker Publish finished for v${VER}." exit 1 fpk: @@ -151,13 +151,13 @@ jobs: - name: Build Docker FPKs env: FPK_NAME_PREFIX: Octop-fnos - LITE: ${{ needs.ensure-image.outputs.lite }} + FULL: ${{ needs.ensure-image.outputs.full }} run: | - bash scripts/build-fpk.sh docker - if [ "$LITE" = "true" ]; then - bash scripts/build-fpk.sh docker-lite + bash scripts/build-fpk.sh docker-lite + if [ "$FULL" = "true" ]; then + bash scripts/build-fpk.sh docker else - echo "::warning::Skipping the lite FnOS package because its image tag was not published." + echo "::warning::Skipping the full FnOS package because its image tag was not published." fi - name: Upload docker fpk artifact diff --git a/CHANGELOG.md b/CHANGELOG.md index 39332b7edd..1b01a8c67f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,25 @@ ## [Unreleased] +## [1.0.3b4] - 2026-11-06 + +### 新增 +- 工作台增加云主机页:授权后查看腾讯云 CVM,并由常驻运维专家巡检和变更 +- 后台标签页的定时提醒改为系统通知 +- 启动时同步新的预置模型,腾讯云通道支持 HY4 + +### 修复 +- 共享专家能用查看者的自定义 MCP 名称 +- 编辑团队会保存示例头像 +- Docker 精简镜像在编译器已移除后仍能发布 + +### 变更 +- 多实例部署时,腾讯云授权改存在控制面;单机仍用本地文件 +- 云服务器页移到工作台末尾,并注明目前只支持腾讯云 CVM +- 默认 Docker 标签改为精简版,完整版使用 `:-full` 和 `:full` +- 连接器可按类别筛选,大额 token 用量会缩写 +- 升级 octop-harness 至 1.0.8 + ## [1.0.3b3] - 2026-11-04 ### 新增 diff --git a/README.md b/README.md index 6c35a4c43f..4e98889a6a 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@

Python 3.12+ License: MIT - Version + Version PyPI Code Style: Ruff GitHub stars @@ -451,6 +451,7 @@ After `octop run`, open **http://127.0.0.1:8088**.

- **Chat** — real-time conversation with experts and teams +- **Cloud** — Tencent CVM fleet overview, instance metrics, and a resident ops expert - **Experts** — create experts, pick templates / MBTI personas, share or publish experts, configure providers - **AgentTeams** *(Beta)* — coordinator + member experts for multi-step work - **Connectors** — OAuth apps and MCP gateways diff --git a/README_CN.md b/README_CN.md index fb613b8e40..7f59607b4a 100644 --- a/README_CN.md +++ b/README_CN.md @@ -15,7 +15,7 @@

Python 3.12+ License: MIT - Version + Version PyPI Code Style: Ruff GitHub stars diff --git a/dashboard/package.json b/dashboard/package.json index d1d3e6340c..8320c9ccb0 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -6,6 +6,7 @@ "scripts": { "dev": "vite --host", "build": "tsc -b && vite build", + "build:fast": "BUILD_FAST=1 vite build", "build:docker": "vite build", "build:prod": "tsc -b && vite build --mode production", "build:test": "tsc -b && vite build --mode test", diff --git a/dashboard/public/notify-sw.js b/dashboard/public/notify-sw.js new file mode 100644 index 0000000000..3d8a4f29f7 --- /dev/null +++ b/dashboard/public/notify-sw.js @@ -0,0 +1,41 @@ +/* Dashboard system notifications. + Chrome does not display `new Notification()` from a background tab. + `registration.showNotification()` does, including while this tab is hidden. + + Dev registers this file directly. Production importScripts it into sw.js. + skipWaiting here would override the production worker's update prompt, + so it only runs when this file is the worker itself. +*/ + +self.addEventListener("notificationclick", (event) => { + event.notification.close(); + const path = + event.notification.data && typeof event.notification.data.path === "string" + ? event.notification.data.path + : "/"; + const target = new URL(path, self.location.origin).href; + event.waitUntil( + self.clients + .matchAll({ type: "window", includeUncontrolled: true }) + .then(async (windowClients) => { + const client = windowClients.find((item) => + item.url.startsWith(self.location.origin), + ); + if (client) { + await client.focus(); + client.postMessage({ type: "octop-notify-open", path }); + return; + } + if (self.clients.openWindow) await self.clients.openWindow(target); + }), + ); +}); + +if ((self.location.pathname || "").endsWith("/notify-sw.js")) { + self.addEventListener("install", () => { + self.skipWaiting(); + }); + self.addEventListener("activate", (event) => { + event.waitUntil(self.clients.claim()); + }); +} diff --git a/dashboard/src/api/modules/octopThreads.ts b/dashboard/src/api/modules/octopThreads.ts index 1c7bc33945..75fa014ec7 100644 --- a/dashboard/src/api/modules/octopThreads.ts +++ b/dashboard/src/api/modules/octopThreads.ts @@ -166,9 +166,11 @@ export const octopThreadsApi = { `/agents/${encodeURIComponent(agentId)}/threads?limit=${limit}`, ), - create: (agentId: string) => + create: (agentId: string, options?: { rebind?: boolean }) => request<{ thread_id: string; session_key: string }>( - `/agents/${encodeURIComponent(agentId)}/threads`, + `/agents/${encodeURIComponent(agentId)}/threads${ + options?.rebind === false ? "?rebind=false" : "" + }`, { method: "POST" }, ), diff --git a/dashboard/src/api/modules/terminalAi.ts b/dashboard/src/api/modules/terminalAi.ts index d973e6c22f..8689509f99 100644 --- a/dashboard/src/api/modules/terminalAi.ts +++ b/dashboard/src/api/modules/terminalAi.ts @@ -11,20 +11,28 @@ export interface TerminalContext { agent_name: string; } +/** Bundled terminal expert. Distinct from the Tencent CVM ops expert. */ +export const OPS_ENGINEER_EXPERT_ID = "ops-engineer"; + +export interface CreatedOpsEngineer { + id: number; + agent_id: string; + name: string; + description: string; + state: string; + expert_id: string; +} + export const terminalAiApi = { getContext: (agentId: string) => request(`/agents/${agentId}/terminal/context`), createOpsEngineer: () => - request<{ - id: number; - agent_id: string; - name: string; - description: string; - state: string; - expert_id: string; - }>("/agents/from-expert/ops-engineer", { - method: "POST", - body: JSON.stringify({}), - }), + request( + `/agents/from-expert/${OPS_ENGINEER_EXPERT_ID}`, + { + method: "POST", + body: JSON.stringify({}), + }, + ), }; diff --git a/dashboard/src/assets/storage/tos.svg b/dashboard/src/assets/storage/tos.svg index f93aa75665..50800c96b9 100644 --- a/dashboard/src/assets/storage/tos.svg +++ b/dashboard/src/assets/storage/tos.svg @@ -1,5 +1,9 @@ - - - - + + + + + + + + diff --git a/dashboard/src/components/AgentSelector.tsx b/dashboard/src/components/AgentSelector.tsx index e40f226582..e6412415ce 100644 --- a/dashboard/src/components/AgentSelector.tsx +++ b/dashboard/src/components/AgentSelector.tsx @@ -30,6 +30,12 @@ interface AgentSelectorProps { * expert-only. */ showTeams?: boolean; + /** + * 受控模式:只改这个面板自己的专家,不写入全局当前 Agent。 + * 传入 onChange 即生效。 + */ + value?: string | null; + onChange?: (agentId: string) => void; } function agentAccent(agent: OctopAgent): string { @@ -162,9 +168,17 @@ export default function AgentSelector({ variant = "auto", showLabel = true, showTeams = false, + value, + onChange, }: AgentSelectorProps) { const { t } = useTranslation(); const { agents, activeAgentId, setActiveAgent, loading } = useAgent(); + const controlled = onChange !== undefined; + const chosenId = controlled ? value ?? null : activeAgentId; + const commit = (id: string) => { + if (onChange) onChange(id); + else setActiveAgent(id); + }; const soloSelectable = useMemo(() => ownedSoloExperts(agents), [agents]); const allTeams = useMemo(() => ownedTeamAgents(agents), [agents]); const teamSelectable = useMemo( @@ -204,22 +218,23 @@ export default function AgentSelector({ teamSelectable.length, ); const labeledGroups = [...expertGroups, ...teamGroups]; - const activeAgent = agents.find((agent) => agent.agent_id === activeAgentId); + const activeAgent = agents.find((agent) => agent.agent_id === chosenId); const activeIsHiddenTeam = Boolean( activeAgent && isTeamAgent(activeAgent) && !showTeams, ); const useBar = variant !== "select"; - const currentId = activeAgentId ?? selectable[0]?.agent_id; + const currentId = + chosenId ?? (controlled ? undefined : selectable[0]?.agent_id); const barRef = useRef(null); const measureRef = useRef(null); const [hiddenIds, setHiddenIds] = useState([]); useEffect(() => { - if (loading) return; + if (controlled || loading) return; const next = nextPickerSelection(activeAgentId, agents, selectable); if (next === undefined) return; setActiveAgent(next); - }, [activeAgentId, agents, loading, selectable, setActiveAgent]); + }, [activeAgentId, agents, controlled, loading, selectable, setActiveAgent]); useLayoutEffect(() => { if (!useBar) return; @@ -337,7 +352,7 @@ export default function AgentSelector({ key={agent.agent_id} agent={agent} active={agent.agent_id === currentId} - onSelect={setActiveAgent} + onSelect={commit} measure={measure} groupKey={groupKey} /> @@ -377,7 +392,7 @@ export default function AgentSelector({ menu={{ className: styles.moreMenu, items: moreItems, - onClick: ({ key }) => setActiveAgent(key), + onClick: ({ key }) => commit(key), }} >

+ ))} +
+
+ + {floating ? ( + + ) : null} + {title} + + + {headerExtra} + {placementLocked ? null : placements ? ( + placements.map((item) => ( + +
+
+ {children} +
+
+ + ); + + const frame = floating ? ( +
+ {shell} +
+ ) : dock === "overlay" ? ( +
+ {shell} +
+ ) : ( +
+ {shell} +
+ ); + + // 下拉和选择器默认叠在 1050,会落到浮动窗下面。 + const hosted = ( + + {frame} + + ); + + return overlay ? createPortal(hosted, document.body) : hosted; +} diff --git a/dashboard/src/components/BrowserAiPanel.module.less b/dashboard/src/components/BrowserAiPanel.module.less index 1a88d2c49e..88727b46e9 100644 --- a/dashboard/src/components/BrowserAiPanel.module.less +++ b/dashboard/src/components/BrowserAiPanel.module.less @@ -3,54 +3,24 @@ .panel { display: flex; flex-direction: column; + gap: 10px; + box-sizing: border-box; height: 100%; min-width: 0; + min-height: 0; flex: 1; - background: var(--fn-bg-primary); - border-left: 1px solid var(--fn-border-primary, rgba(0, 0, 0, 0.08)); + padding: 12px 16px 16px; + background: transparent; overflow: hidden; } -.panelBottom { - border-left: none; -} - -// ── Panel header ─────────────────────────────────────────────────────────── - -.header { - display: flex; - align-items: center; - justify-content: space-between; - padding: 8px 12px; - flex-shrink: 0; - border-bottom: 1px solid var(--fn-border-primary, rgba(0, 0, 0, 0.08)); - background: var(--fn-bg-secondary); - gap: 8px; -} - -.headerTitle { - display: flex; - align-items: center; - gap: 6px; - min-width: 0; - font-size: 13px; - font-weight: 600; - color: var(--fn-text-primary); -} - -.headerActions { - display: flex; - align-items: center; - gap: 2px; - flex-shrink: 0; -} - // ── Context section ──────────────────────────────────────────────────────── .contextSection { - padding: 8px 12px; - border-bottom: 1px solid var(--fn-border-primary, rgba(0, 0, 0, 0.08)); flex-shrink: 0; + padding: 9px 10px 10px; + background: var(--fn-bg-secondary); + border-radius: 10px; } .contextGrid { @@ -156,95 +126,34 @@ margin-top: 8px; } -// ── Send bar (bottom of panel — matches Terminal AiPanel style) ────────── - -.sendBar { - padding: 8px 12px; - border-top: 1px solid var(--fn-border-primary, rgba(0, 0, 0, 0.08)); - flex-shrink: 0; +.composer { display: flex; - flex-direction: row; - align-items: flex-end; + flex: 0 0 auto; + flex-direction: column; gap: 6px; + padding-top: 10px; + border-top: 1px solid var(--fn-border-secondary); } -.sendRow { - flex: 1; - min-width: 0; +.composerActions { display: flex; - align-items: flex-end; gap: 8px; + align-items: center; + justify-content: space-between; } -.sendTextarea { +.composerLead { + display: flex; flex: 1; + gap: 8px; + align-items: center; min-width: 0; - min-height: 32px; - max-height: 120px; - padding: 6px 10px; - border: 1px solid var(--fn-border-primary, rgba(0, 0, 0, 0.12)); - border-radius: 10px; - background: var(--fn-bg-primary); - color: var(--fn-text-primary); - font-size: 13px; - line-height: 1.4; - resize: none; - font-family: inherit; - overflow-y: auto; - scrollbar-width: none; /* Firefox */ - - &::-webkit-scrollbar { - display: none; /* Safari & Chrome */ - } - - &::placeholder { - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; - } - - &:focus { - outline: none; - border-color: var(--fn-color-brand, #6366f1); - box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.12); - } - - &:disabled { - opacity: 0.6; - cursor: not-allowed; - } } -.sendBtn { - display: inline-flex; - align-items: center; - justify-content: center; - width: 32px; - height: 32px; - flex-shrink: 0; - border-radius: 10px; - border: none; - background: linear-gradient( - 135deg, - var(--fn-color-brand), - var(--fn-color-brand-soft) - ); - color: #fff; - cursor: pointer; - transition: all 0.2s ease; - - &:hover:not(:disabled) { - transform: scale(1.05); - box-shadow: 0 4px 12px - color-mix(in srgb, var(--fn-color-brand) 35%, transparent); - } - - &:disabled { - opacity: 0.45; - cursor: not-allowed; - transform: none; - box-shadow: none; - } +.hint { + min-width: 0; + font-size: 11px; + opacity: 0.5; } // ── Recording indicator ───────────────────────────────────────────────── diff --git a/dashboard/src/components/BrowserAiPanel.tsx b/dashboard/src/components/BrowserAiPanel.tsx index 231035075b..819858aab7 100644 --- a/dashboard/src/components/BrowserAiPanel.tsx +++ b/dashboard/src/components/BrowserAiPanel.tsx @@ -5,13 +5,16 @@ import React, { useRef, useState, } from "react"; -import { Button, Tooltip, Tag, Spin } from "antd"; +import { Button, Input, Tooltip, Tag, Spin } from "antd"; import { message as antMessage } from "@/utils/antdMessage"; -import { Bot, X, Square, Play, Loader2, Send } from "lucide-react"; +import { Bot, Square, Play, Loader2, Send } from "lucide-react"; +import AssistantFrame, { + type AssistantPlacement, +} from "./AssistantFrame/AssistantFrame"; import { useTranslation } from "react-i18next"; import cx from "classnames"; -import type { OctopAgent } from "../context/AgentContext"; +import { useAgent } from "../context/AgentContext"; import AgentSelector from "../components/AgentSelector"; import { useAgentThreadChat } from "../hooks/useAgentThreadChat"; import { browserApi } from "../api/modules/browser"; @@ -28,13 +31,26 @@ export interface BrowserAiTabContext { active: boolean; } +const BROWSER_AI_AGENT_KEY = "octop:remote-browser:ai-agent"; + +function readBrowserAgentId(): string | null { + try { + return localStorage.getItem(BROWSER_AI_AGENT_KEY); + } catch { + return null; + } +} + interface BrowserAiPanelProps { - activeAgent: OctopAgent | null; tabs: BrowserAiTabContext[]; currentUrl: string; profileId?: string | null; onClose: () => void; - layout?: "right" | "bottom"; + placement: AssistantPlacement; + placementLocked?: boolean; + onPlacementChange: (placement: AssistantPlacement) => void; + /** 工作台切走时收起窗口,会话仍留在这个面板里。 */ + hidden?: boolean; /** Skill recording state from parent (RemoteBrowserPage) */ browserRecording?: boolean; browserRecordingId?: string | null; @@ -67,12 +83,14 @@ type RecordingPhase = | "recording"; export default function BrowserAiPanel({ - activeAgent, tabs, currentUrl, profileId, onClose, - layout = "right", + placement, + placementLocked = false, + onPlacementChange, + hidden = false, browserRecording = false, browserRecordingId = null, browserLastRecordingId = null, @@ -83,10 +101,6 @@ export default function BrowserAiPanel({ onSkillNameSet, }: BrowserAiPanelProps) { const { t } = useTranslation(); - const panelClassName = cx( - styles.panel, - layout === "bottom" && styles.panelBottom, - ); const [inputValue, setInputValue] = useState(""); const [browserReplayBusy, setBrowserReplayBusy] = useState(false); const [pendingSkillContent, setPendingSkillContent] = useState( @@ -95,17 +109,51 @@ export default function BrowserAiPanel({ const [pendingSkillName, setPendingSkillName] = useState(null); const [, setPendingSkillRecordingId] = useState(null); const workflowBusyRef = useRef(false); - const textareaRef = useRef(null); const imeComposingRef = useRef(false); // Recording workflow phase const [recordingPhase, setRecordingPhase] = useState("idle"); + const recordingTag = + browserRecording && recordingPhase !== "idle" ? ( + + ● REC{" "} + {skillName && recordingPhase === "recording" ? `— ${skillName}` : ""} + + ) : null; // Saved skill names for keyword-trigger replay const [savedSkillNames, setSavedSkillNames] = useState([]); + const { agents, activeAgentId } = useAgent(); + const [agentId, setAgentId] = useState(readBrowserAgentId); + const activeAgent = + agents.find((agent) => agent.agent_id === agentId) ?? null; const activeTab = useMemo(() => tabs.find((tab) => tab.active), [tabs]); - const agentId = activeAgent?.agent_id ?? null; + + useEffect(() => { + if (agentId && agents.some((agent) => agent.agent_id === agentId)) return; + if (!agents.length) return; + const fromGlobal = + activeAgentId && agents.some((agent) => agent.agent_id === activeAgentId) + ? activeAgentId + : null; + const next = fromGlobal ?? agents[0].agent_id; + setAgentId(next); + try { + localStorage.setItem(BROWSER_AI_AGENT_KEY, next); + } catch { + /* 忽略写入失败 */ + } + }, [agentId, agents, activeAgentId]); + + const chooseAgent = (id: string) => { + setAgentId(id); + try { + localStorage.setItem(BROWSER_AI_AGENT_KEY, id); + } catch { + /* 忽略写入失败 */ + } + }; // Load saved skill names from API on mount / agent change useEffect(() => { @@ -135,7 +183,7 @@ export default function BrowserAiPanel({ isStreaming, send, cancelStream, - } = useAgentThreadChat(agentId); + } = useAgentThreadChat(agentId, { pinKey: "octop:remote-browser:ai-thread" }); // When browserRecording transitions, sync phase useEffect(() => { @@ -190,7 +238,6 @@ export default function BrowserAiPanel({ const objective = text.trim(); if (!objective) return; setInputValue(""); - if (textareaRef.current) textareaRef.current.style.height = "auto"; setPendingSkillName(objective); if (onSkillNameSet) onSkillNameSet(objective); setRecordingPhase("awaitDescription"); @@ -205,7 +252,6 @@ export default function BrowserAiPanel({ (text: string) => { const description = text.trim(); setInputValue(""); - if (textareaRef.current) textareaRef.current.style.height = "auto"; setRecordingPhase("recording"); send(description); }, @@ -443,7 +489,6 @@ export default function BrowserAiPanel({ const text = inputValue.trim(); if (!text || isStreaming || !activeAgent) return; setInputValue(""); - if (textareaRef.current) textareaRef.current.style.height = "auto"; if (recordingPhase === "awaitObjective") { void handleObjectiveInput(text); @@ -501,16 +546,6 @@ export default function BrowserAiPanel({ [handleSend], ); - const handleTextareaInput = useCallback( - (e: React.ChangeEvent) => { - setInputValue(e.target.value); - const el = e.target; - el.style.height = "auto"; - el.style.height = `${Math.min(el.scrollHeight, 120)}px`; - }, - [], - ); - // When recording is active and agent stream just finished, append reminder const prevStreamingRef = useRef(false); useEffect(() => { @@ -576,75 +611,66 @@ export default function BrowserAiPanel({ ]); // No agent → show empty state + const frame = (content: React.ReactNode) => ( + + ); + if (!activeAgent) { - return ( -
-
-
- - {t("remoteBrowser.ai.title", "AI 助手")} -
- -
-
- -
- {t("remoteBrowser.ai.noAgentTitle", "请选择一个 Agent")} -
-
- {t( - "remoteBrowser.ai.noAgentDesc", - "浏览器右侧助手会复用当前 Agent 的对话能力。", - )} -
-
- -
+ return frame( +
+ +
+ {t("remoteBrowser.ai.noAgentTitle", "请选择一个 Agent")}
-
- ); - } - - return ( -
-
-
- - {t("remoteBrowser.ai.title", "AI 助手")} - {browserRecording && recordingPhase !== "idle" && ( - - ● REC{" "} - {skillName && recordingPhase === "recording" - ? `— ${skillName}` - : ""} - +
+ {t( + "remoteBrowser.ai.noAgentDesc", + "这里的专家和对话只属于浏览器,不会改到其他页签。", )}
-
- -
+
, + ); + } + return frame( + <>
{t("remoteBrowser.ai.expert", "专家")} - +
@@ -679,70 +705,81 @@ export default function BrowserAiPanel({ )}
-
- {/* Recording action buttons before the send row */} - {browserRecording && recordingPhase === "recording" && ( - - + + )} + {!browserRecording && + browserLastRecordingId && + !browserReplayBusy && ( + + + + )} + {browserReplayBusy && ( + + )} + {t("chat.composerHint")} + + {isStreaming ? ( + - - )} - {!browserRecording && browserLastRecordingId && !browserReplayBusy && ( - - - - )} - {browserReplayBusy && } -
-