JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(web): HTTP 环境下 A2A 处理历史复制走 execCommand 回退
NickFuryXXX64bd9dfa0fb4
diff --git a/jiuwenswarm/channels/web/frontend/package.json b/jiuwenswarm/channels/web/frontend/package.jsonindex 7914cc56bd..9a95167bb7 100644--- a/jiuwenswarm/channels/web/frontend/package.json+++ b/jiuwenswarm/channels/web/frontend/package.json@@ -30,6 +30,7 @@"test:editable-combobox": "tsc src/components/SessionSidebar/editableComboboxModel.ts --target ES2020 --module ES2020 --moduleResolution Bundler --rootDir src --outDir node_modules/.cache/editable-combobox --skipLibCheck --noEmitOnError && node --test tests/editableCombobox.test.mjs","test:click-outside": "tsc src/components/SessionSidebar/clickOutside.ts --target ES2020 --module ES2020 --moduleResolution Bundler --rootDir src --outDir node_modules/.cache/click-outside --skipLibCheck --noEmitOnError && node --test tests/clickOutside.test.mjs","test:a2a-ingress-panel": "tsc src/components/A2AIngressPanel/a2aIngressPanelState.ts --target ES2020 --module ES2020 --moduleResolution Bundler --rootDir src --outDir node_modules/.cache/a2a-ingress-panel-state --skipLibCheck --noEmitOnError && node --test tests/a2aIngressPanelState.test.mjs",+ "test:a2a-history-copy": "tsc src/components/A2AIngressPanel/copyHistoryText.ts --target ES2020 --module ES2020 --moduleResolution Bundler --rootDir src --outDir node_modules/.cache/a2a-history-copy --skipLibCheck --noEmitOnError && node --test tests/a2aHistoryCopy.test.mjs","test:a2a-outbound-panel": "tsc src/components/A2AIngressPanel/a2aOutboundPanelState.ts --target ES2020 --module ES2020 --moduleResolution Bundler --rootDir src --outDir node_modules/.cache/a2a-outbound-panel-state --skipLibCheck --noEmitOnError && node --test tests/a2aOutboundPanelState.test.mjs","test:chat-store-streaming": "esbuild src/stores/chatStore.ts --bundle --platform=node --format=esm --outfile=node_modules/.cache/chat-store-streaming/chatStore.mjs --define:import.meta.env.DEV=false && node --test tests/chatStoreStreaming.test.mjs","test:settle-historical-tool-executions": "esbuild src/stores/chatStore.ts --bundle --platform=node --format=esm --outfile=node_modules/.cache/chat-store-streaming/chatStore.mjs --define:import.meta.env.DEV=false && node --test tests/settleHistoricalToolExecutions.test.mjs",diff --git a/jiuwenswarm/channels/web/frontend/src/components/A2AIngressPanel/copyHistoryText.ts b/jiuwenswarm/channels/web/frontend/src/components/A2AIngressPanel/copyHistoryText.tsnew file mode 100644index 0000000000..761899c441--- /dev/null+++ b/jiuwenswarm/channels/web/frontend/src/components/A2AIngressPanel/copyHistoryText.ts@@ -0,0 +1,34 @@+export async function copyHistoryText(value: string): Promise<void> {+ if (navigator.clipboard?.writeText) {+ try {+ await navigator.clipboard.writeText(value);+ return;+ } catch {+ // Some deployments restrict the Clipboard API; try the user-initiated copy command.+ }+ }++ // HTTP deployments do not expose the Clipboard API.+ const previousFocus = document.activeElement;+ const selection = document.getSelection();+ const ranges = selection ? Array.from({ length: selection.rangeCount }, (_, index) => selection.getRangeAt(index).cloneRange()) : [];+ const textarea = document.createElement('textarea');+ textarea.value = value;+ textarea.readOnly = true;+ textarea.style.position = 'fixed';+ textarea.style.opacity = '0';+ textarea.style.pointerEvents = 'none';+ document.body.appendChild(textarea);+ try {+ textarea.focus({ preventScroll: true });+ textarea.select();+ if (!document.execCommand('copy')) throw new Error('Copy command failed');+ } finally {+ textarea.remove();+ if (previousFocus instanceof HTMLElement) previousFocus.focus({ preventScroll: true });+ if (selection) {+ selection.removeAllRanges();+ ranges.forEach(range => selection.addRange(range));+ }+ }+}diff --git a/jiuwenswarm/channels/web/frontend/src/components/A2AIngressPanel/index.tsx b/jiuwenswarm/channels/web/frontend/src/components/A2AIngressPanel/index.tsxindex 3141e714d5..c51a062edd 100644--- a/jiuwenswarm/channels/web/frontend/src/components/A2AIngressPanel/index.tsx+++ b/jiuwenswarm/channels/web/frontend/src/components/A2AIngressPanel/index.tsx@@ -6,6 +6,7 @@ import { RUNTIME_SCOPE_CHANGED_EVENT } from '../../services/runtimeScope';import type { WebError } from '../../types/websocket';import { A2AOutboundPanel } from './A2AOutboundPanel';import { A2AIngressSecurityFields } from './A2AIngressSecurityFields';+import { copyHistoryText } from './copyHistoryText';import {canOperateA2AIngress,draftFromA2AIngressSnapshot,@@ -199,7 +200,7 @@ export function A2AIngressPanel({ isConnected, request }: A2AIngressPanelProps)const copyHistoryValue = useCallback(async (cellKey: string, value: string) => {try {- await navigator.clipboard.writeText(value);+ await copyHistoryText(value);setCopyError(null);setCopiedHistoryCell(cellKey);if (copyFeedbackTimerRef.current !== null) window.clearTimeout(copyFeedbackTimerRef.current);diff --git a/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json b/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.jsonindex 4e329fac8f..49bf82cdec 100644--- a/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json+++ b/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json@@ -707,7 +707,7 @@"tabs": { "ariaLabel": "A2A request history direction", "ingress": "Ingress", "outbound": "Outbound" },"copy": "Click to copy","copied": "Copied",- "copyFailed": "Copy failed. Check the browser clipboard permission.",+ "copyFailed": "Copy failed. Select the text and copy it manually.","ingress": {"title": "Ingress request history","description": "Shows the latest 200 A2A ingress requests in this Gateway process without retaining request bodies.",diff --git a/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json b/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.jsonindex 23a25bac29..11eada82ac 100644--- a/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json+++ b/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json@@ -697,7 +697,7 @@"tabs": { "ariaLabel": "A2A 请求处理历史类型", "ingress": "入站请求", "outbound": "出站请求" },"copy": "点击复制","copied": "已复制",- "copyFailed": "复制失败,请检查浏览器剪贴板权限。",+ "copyFailed": "复制失败,请选中文本后手动复制。","ingress": {"title": "入站请求处理历史","description": "显示当前 Gateway 进程内最近 200 条 A2A 入站请求,不记录请求正文。",diff --git a/jiuwenswarm/channels/web/frontend/tests/a2aHistoryCopy.test.mjs b/jiuwenswarm/channels/web/frontend/tests/a2aHistoryCopy.test.mjsnew file mode 100644index 0000000000..a9697c55aa--- /dev/null+++ b/jiuwenswarm/channels/web/frontend/tests/a2aHistoryCopy.test.mjs@@ -0,0 +1,102 @@+import assert from 'node:assert/strict';+import test from 'node:test';+import { copyHistoryText } from '../node_modules/.cache/a2a-history-copy/components/A2AIngressPanel/copyHistoryText.js';++function setup(t, clipboard, copyResult = true) {+ const state = { copied: null, children: [], focused: null, selected: null };+ class Element {+ style = {};+ focus() {+ state.focused = this;+ }+ select() {+ state.selected = this;+ }+ remove() {+ state.children.splice(state.children.indexOf(this), 1);+ }+ }+ const previousFocus = new Element();+ const range = {+ cloneRange() {+ return this;+ },+ };+ const selection = {+ ranges: [range],+ rangeCount: 1,+ getRangeAt: () => range,+ removeAllRanges() {+ this.ranges = [];+ },+ addRange(value) {+ this.ranges.push(value);+ },+ };+ const globals = {+ navigator: { clipboard },+ HTMLElement: Element,+ document: {+ activeElement: previousFocus,+ getSelection: () => selection,+ createElement: () => new Element(),+ body: { appendChild: element => state.children.push(element) },+ execCommand(command) {+ assert.equal(command, 'copy');+ assert.ok(state.children.includes(state.selected));+ state.copied = state.selected.value;+ selection.removeAllRanges();+ if (copyResult instanceof Error) throw copyResult;+ return copyResult;+ },+ },+ };+ for (const [key, value] of Object.entries(globals)) {+ const original = Object.getOwnPropertyDescriptor(globalThis, key);+ Object.defineProperty(globalThis, key, { configurable: true, value });+ t.after(() => {+ if (original) Object.defineProperty(globalThis, key, original);+ else delete globalThis[key];+ });+ }+ return { state, previousFocus, selection, range };+}++test('uses Clipboard API when available without creating a temporary input', async t => {+ const values = [];+ const { state } = setup(t, { writeText: async value => values.push(value) });+ await copyHistoryText('Agent 名称');+ assert.deepEqual(values, ['Agent 名称']);+ assert.equal(state.copied, null);+ assert.deepEqual(state.children, []);+});++test('copies exact text when Clipboard API is unavailable on HTTP', async t => {+ const { state, previousFocus, selection, range } = setup(t, undefined);+ const value = 'Agent 名称\n disp_123 ';+ await copyHistoryText(value);+ assert.equal(state.copied, value);+ assert.deepEqual(state.children, []);+ assert.equal(state.focused, previousFocus);+ assert.deepEqual(selection.ranges, [range]);+});++test('falls back when Clipboard API rejects', async t => {+ const { state } = setup(t, {+ writeText: async () => {+ throw new Error('NotAllowedError');+ },+ });+ await copyHistoryText('remote-task-id');+ assert.equal(state.copied, 'remote-task-id');+});++for (const result of [false, new Error('Copy unavailable')]) {+ test(`reports failure and restores the page when copy ${result === false ? 'returns false' : 'throws'}`, async t => {+ const { state, previousFocus, selection, range } = setup(t, undefined, result);+ await assert.rejects(copyHistoryText('disp_123'));+ assert.deepEqual(state.children, []);+ assert.equal(state.focused, previousFocus);+ assert.deepEqual(selection.ranges, [range]);+ });+}