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
根据检视意见修改
yt2026a4d6d493240b
diff --git a/jiuwenswarm/channels/web/frontend/src/EnterpriseEntry.tsx b/jiuwenswarm/channels/web/frontend/src/EnterpriseEntry.tsxindex 5717714c60..2463be60f7 100644--- a/jiuwenswarm/channels/web/frontend/src/EnterpriseEntry.tsx+++ b/jiuwenswarm/channels/web/frontend/src/EnterpriseEntry.tsx@@ -13,6 +13,7 @@ import {} from './services/enterpriseContext';import {requestExtEntries,+ getRuntimeScope,parseRuntimeScope,setRuntimeScope,type RuntimeScope,@@ -350,7 +351,9 @@ export function EnterpriseEntry({ children }: { children: ReactNode }) {void (async () => {try {const clusterChanged = await ensureActiveCluster(provider, selected.jiuwenclaw_id);- activateContext(selected, true, false, clusterChanged);+ // 透传字段是宿主注入的会话级参数:切换上下文必须随 launchScope 写回+ // 刷新后的 URL(activateContext 的 navigate 路径整页 reload),否则静默丢失。+ activateContext(selected, true, false, clusterChanged, { ext: getRuntimeScope().ext });} catch (switchError) {setContextSwitching(false);setContextError(errorText(switchError));@@ -386,6 +389,7 @@ export function EnterpriseEntry({ children }: { children: ReactNode }) {true,true,clusterChanged,+ { ext: getRuntimeScope().ext },);} catch (switchError) {setContextSwitching(false);diff --git a/jiuwenswarm/channels/web/frontend/src/services/webHttpClient.ts b/jiuwenswarm/channels/web/frontend/src/services/webHttpClient.tsindex 47737b5de7..bea80350bb 100644--- a/jiuwenswarm/channels/web/frontend/src/services/webHttpClient.ts+++ b/jiuwenswarm/channels/web/frontend/src/services/webHttpClient.ts@@ -1001,6 +1001,9 @@ export class WebHttpClient {private authenticatedFetch(input: RequestInfo | URL, init: RequestInit): Promise<Response> {if (isEnterprise() && hasManagerSessionCredentials()) {// 保留外部透传的 Authorization;只有 Manager 自己的 token 才走刷新包装器。+ // 该分支仅在部署通过 REQUEST_EXT_FIELDS 启用 Authorization 透传时触达+ // (宿主 token 经 ext.Authorization 进入请求头);出厂空注册表下走不到,+ // 属部署契约休眠路径,勿当死代码删除。const headers = new Headers(init.headers);const authorization = headers.get('Authorization');const managerAccessToken = getManagerAccessToken();diff --git a/jiuwenswarm/channels/web/frontend/tests/runtimeScope.test.mjs b/jiuwenswarm/channels/web/frontend/tests/runtimeScope.test.mjsindex a659adf209..35713aa9cc 100644--- a/jiuwenswarm/channels/web/frontend/tests/runtimeScope.test.mjs+++ b/jiuwenswarm/channels/web/frontend/tests/runtimeScope.test.mjs@@ -2,6 +2,7 @@ import assert from 'node:assert/strict';import test from 'node:test';import {+ REQUEST_EXT_FIELDS,appendRuntimeScopeQuery,buildRuntimeIdentityHeaders,parseRuntimeScope,@@ -11,8 +12,13 @@ test('runtime scope is parsed and added to websocket query', () => {const scope = parseRuntimeScope('?user_id=%20u1%20&group_id=g1&bot_id=b1&gateway_id=gw1&ignored=x');- // 用户面忽略 URL 中的 gateway_id(遗留参数)。- assert.deepEqual(scope, { userId: 'u1', groupId: 'g1', botId: 'b1' });+ // 用户面忽略 URL 中的 gateway_id(遗留参数);出厂注册表为空,ext 恒为 {}。+ assert.deepEqual(scope, {+ userId: 'u1',+ groupId: 'g1',+ botId: 'b1',+ ext: {},+ });const query = appendRuntimeScopeQuery(new URLSearchParams('provider=p'), scope);assert.equal(query.toString(), 'provider=p&user_id=u1&group_id=g1&bot_id=b1');});@@ -27,7 +33,7 @@ test('runtime scope takes precedence in HTTP identity headers', () => {bot_id: 'payload-bot',session_id: 'session-1',},- { userId: 'u1', groupId: 'g1', botId: 'b1' }+ { userId: 'u1', groupId: 'g1', botId: 'b1', ext: {} }),{'X-Request-Id': 'req-1',@@ -35,6 +41,11 @@ test('runtime scope takes precedence in HTTP identity headers', () => {'X-Group-Id': 'g1','X-Bot-Id': 'b1','X-Session-Id': 'session-1',+ // 路由字段按原始名镜像发一份:request_ext 白名单按头名整名(小写)匹配,+ // X-User-Id 匹配不到白名单里的 user_id,镜像头是 ext 透传路由字段的载体。+ user_id: 'u1',+ group_id: 'g1',+ bot_id: 'b1',});});@@ -44,13 +55,64 @@ test('missing runtime scope keeps legacy payload fallback', () => {buildRuntimeIdentityHeaders('req-2',{ user_id: 'u2', group_id: 'g2', bot_id: 'b2' },- {}+ { ext: {} }),{'X-Request-Id': 'req-2','X-User-Id': 'u2','X-Group-Id': 'g2','X-Bot-Id': 'b2',+ user_id: 'u2',+ group_id: 'g2',+ bot_id: 'b2',});});++test('registered request ext fields flow into query and headers', () => {+ // 模拟接入方按 JSDoc 示例启用字段:注册表追加一行(服务端白名单同步为部署动作)。+ REQUEST_EXT_FIELDS.push({ name: 'orgCode' });+ try {+ // URLSearchParams.get 自动解码:内存里存原始值,出站时才编码。+ const scope = parseRuntimeScope('?user_id=u1&orgCode=%E5%8C%97%E4%BA%AC');+ assert.deepEqual(scope.ext, { orgCode: '北京' });++ const query = appendRuntimeScopeQuery(new URLSearchParams(), scope);+ assert.equal(query.get('orgCode'), '北京');++ // 非 ASCII 值经 encodeURIComponent 编码后放入 header,不进 URL query。+ const headers = buildRuntimeIdentityHeaders('req-3', {}, scope);+ assert.equal(headers.orgCode, encodeURIComponent('北京'));++ // scope 缺失时回退业务参数。+ const payloadHeaders = buildRuntimeIdentityHeaders(+ 'req-4',+ { orgCode: 'SH002' },+ { userId: 'u1', ext: {} }+ );+ assert.equal(payloadHeaders.orgCode, 'SH002');++ // 未注册字段不透传(白名单外键值在 pickExt 处丢弃)。+ const unregistered = buildRuntimeIdentityHeaders(+ 'req-5',+ {},+ { userId: 'u1', ext: { orgCode: 'x', hacker: 'y' } }+ );+ assert.equal(unregistered.hacker, undefined);+ assert.deepEqual(+ { ...runtimeScopeExt(unregistered) },+ { orgCode: 'x' }+ );+ } finally {+ REQUEST_EXT_FIELDS.pop();+ }+});++function runtimeScopeExt(headers) {+ const { user_id, group_id, bot_id, ...rest } = headers;+ delete rest['X-Request-Id'];+ delete rest['X-User-Id'];+ delete rest['X-Group-Id'];+ delete rest['X-Bot-Id'];+ return rest;+}