conversation-session-model-config.test.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. import { clearAppData } from "#e2e/helpers/desktop-app";
  2. import {
  3. assertUpstreamRequestCapture,
  4. assertUpstreamThoughtLevelCapture,
  5. waitForUpstreamNetworkCapture,
  6. } from "#e2e/helpers/upstream-capture";
  7. import {
  8. UPSTREAM_MODEL,
  9. UPSTREAM_ALTERNATE_MODEL,
  10. UPSTREAM_ALTERNATE_PROVIDER_ID,
  11. UPSTREAM_ALTERNATE_PROVIDER_NAME,
  12. UPSTREAM_PROVIDER_ID,
  13. UPSTREAM_SECONDARY_MODEL,
  14. UPSTREAM_SECONDARY_THOUGHT_LEVEL,
  15. UPSTREAM_THOUGHT_LEVEL,
  16. ensureUpstreamModelForE2E,
  17. getUpstreamProviderModelValues,
  18. getSelectedUpstreamModelLabel,
  19. getSelectedUpstreamThoughtLevelLabel,
  20. getUpstreamThoughtLevelLabels,
  21. selectUpstreamModelById,
  22. selectUpstreamProviderModelById,
  23. selectUpstreamThoughtLevelValue,
  24. } from "#e2e/helpers/upstream-provider";
  25. import {
  26. E2E_REPLY_TOKEN,
  27. getV4ConversationState,
  28. prepareV4ConversationE2E,
  29. selectV4TaskById,
  30. sendV4Prompt,
  31. startNewV4Draft,
  32. waitForV4ConversationState,
  33. waitForV4UserMessageContaining,
  34. } from "#e2e/helpers/v4-conversation";
  35. import { getTaskStoreSnapshot } from "#e2e/helpers/conversation-session-store";
  36. import { waitForQueueContaining, waitForQueueCount } from "#e2e/helpers/conversation-session-queue";
  37. describe("会话区模型配置隔离 E2E", () => {
  38. after(async () => {
  39. await browser.electron.restoreAllMocks();
  40. await clearAppData();
  41. });
  42. it("模型/思考深度应按 session 隔离,并在 queue 消费时使用当前 session 最新配置", async function () {
  43. this.timeout(340000);
  44. await prepareV4ConversationE2E();
  45. await ensureUpstreamModelForE2E(UPSTREAM_SECONDARY_MODEL);
  46. const runId = Date.now();
  47. await selectUpstreamModelById(UPSTREAM_MODEL);
  48. await selectUpstreamThoughtLevelValue(UPSTREAM_THOUGHT_LEVEL);
  49. await expectToolbarConfig(UPSTREAM_MODEL, UPSTREAM_THOUGHT_LEVEL);
  50. const promptA = `E2E_MODEL_CONFIG_A_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  51. await sendV4Prompt(promptA);
  52. await waitForV4UserMessageContaining(`E2E_MODEL_CONFIG_A_${runId}`);
  53. const recordA = await waitForUpstreamNetworkCapture(`E2E_MODEL_CONFIG_A_${runId}`);
  54. assertUpstreamConfig(recordA, `E2E_MODEL_CONFIG_A_${runId}`, {
  55. model: UPSTREAM_MODEL,
  56. thoughtLevel: UPSTREAM_THOUGHT_LEVEL,
  57. });
  58. const sessionA = await waitForIdleSession("A 首轮没有完成");
  59. await startNewV4Draft();
  60. await expectToolbarConfig(UPSTREAM_MODEL, UPSTREAM_THOUGHT_LEVEL);
  61. await selectUpstreamModelById(UPSTREAM_SECONDARY_MODEL);
  62. await selectUpstreamThoughtLevelValue(UPSTREAM_SECONDARY_THOUGHT_LEVEL);
  63. await expectToolbarConfig(UPSTREAM_SECONDARY_MODEL, UPSTREAM_SECONDARY_THOUGHT_LEVEL);
  64. const promptB = `E2E_MODEL_CONFIG_B_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  65. await sendV4Prompt(promptB);
  66. await waitForV4UserMessageContaining(`E2E_MODEL_CONFIG_B_${runId}`);
  67. const recordB = await waitForUpstreamNetworkCapture(`E2E_MODEL_CONFIG_B_${runId}`);
  68. assertUpstreamConfig(recordB, `E2E_MODEL_CONFIG_B_${runId}`, {
  69. model: UPSTREAM_SECONDARY_MODEL,
  70. thoughtLevel: UPSTREAM_SECONDARY_THOUGHT_LEVEL,
  71. });
  72. const sessionB = await waitForIdleSession("B 首轮没有完成");
  73. expect(sessionB).not.toBe(sessionA);
  74. await selectV4TaskById(sessionA);
  75. await waitForV4ConversationState(
  76. (snapshot) => snapshot.sessionId === sessionA && snapshot.state === "idle",
  77. "切回 A 后没有恢复到 A session",
  78. 30000,
  79. );
  80. await expectToolbarConfig(UPSTREAM_MODEL, UPSTREAM_THOUGHT_LEVEL);
  81. await selectV4TaskById(sessionB);
  82. await waitForV4ConversationState(
  83. (snapshot) => snapshot.sessionId === sessionB && snapshot.state === "idle",
  84. "切到 B 后没有恢复到 B session",
  85. 30000,
  86. );
  87. await expectToolbarConfig(UPSTREAM_SECONDARY_MODEL, UPSTREAM_SECONDARY_THOUGHT_LEVEL);
  88. await startNewV4Draft();
  89. await expectToolbarConfig(UPSTREAM_SECONDARY_MODEL, UPSTREAM_SECONDARY_THOUGHT_LEVEL);
  90. const promptC = `E2E_MODEL_CONFIG_C_INHERIT_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  91. await sendV4Prompt(promptC);
  92. await waitForV4UserMessageContaining(`E2E_MODEL_CONFIG_C_INHERIT_${runId}`);
  93. const recordC = await waitForUpstreamNetworkCapture(`E2E_MODEL_CONFIG_C_INHERIT_${runId}`);
  94. assertUpstreamConfig(recordC, `E2E_MODEL_CONFIG_C_INHERIT_${runId}`, {
  95. model: UPSTREAM_SECONDARY_MODEL,
  96. thoughtLevel: UPSTREAM_SECONDARY_THOUGHT_LEVEL,
  97. });
  98. await waitForIdleSession("继承配置的新 session 没有完成");
  99. await startNewV4Draft();
  100. await selectUpstreamModelById(UPSTREAM_MODEL);
  101. await selectUpstreamThoughtLevelValue(UPSTREAM_THOUGHT_LEVEL);
  102. const runningLatestConfig = `E2E_MODEL_CONFIG_AUTO_DRAIN_RUNNING_LATEST_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  103. await sendV4Prompt(runningLatestConfig);
  104. await waitForV4ConversationState(
  105. (snapshot) => snapshot.state === "streaming",
  106. "latest config queue 首轮没有进入 streaming",
  107. 30000,
  108. );
  109. const queuedLatestConfig = `E2E_MODEL_CONFIG_QUEUE_LATEST_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  110. await sendV4Prompt(queuedLatestConfig);
  111. await waitForQueueContaining(`E2E_MODEL_CONFIG_QUEUE_LATEST_${runId}`);
  112. await waitForQueueCount(1);
  113. await selectUpstreamModelById(UPSTREAM_SECONDARY_MODEL);
  114. await selectUpstreamThoughtLevelValue(UPSTREAM_SECONDARY_THOUGHT_LEVEL);
  115. await expectToolbarConfig(UPSTREAM_SECONDARY_MODEL, UPSTREAM_SECONDARY_THOUGHT_LEVEL);
  116. const latestQueueRecord = await waitForUpstreamNetworkCapture(
  117. `E2E_MODEL_CONFIG_QUEUE_LATEST_${runId}`,
  118. );
  119. // I04:排队输入冻结提交时选择;后续切换仅影响新的提交。
  120. assertUpstreamConfig(latestQueueRecord, `E2E_MODEL_CONFIG_QUEUE_LATEST_${runId}`, {
  121. model: UPSTREAM_MODEL,
  122. thoughtLevel: UPSTREAM_THOUGHT_LEVEL,
  123. });
  124. await waitForV4ConversationState(
  125. (snapshot) => snapshot.state === "idle" && snapshot.queueCount === 0,
  126. "latest config queue 没有消费完成",
  127. 90000,
  128. );
  129. await startNewV4Draft();
  130. await selectUpstreamModelById(UPSTREAM_MODEL);
  131. await selectUpstreamThoughtLevelValue(UPSTREAM_THOUGHT_LEVEL);
  132. // 修复原因:这里的核心风险是首发真实请求是否使用当前 session 配置。
  133. // toolbar 若被异步恢复覆盖,也要继续走到抓包断言,避免只验证 UI 表象。
  134. const isolatedAPreflightToolbarMismatch = await collectToolbarConfigMismatch(
  135. UPSTREAM_MODEL,
  136. UPSTREAM_THOUGHT_LEVEL,
  137. );
  138. const isolatedABeforeSendRoot = await getV4ConversationState();
  139. const isolatedABeforeSendStore = isolatedABeforeSendRoot.sessionId
  140. ? await getTaskStoreSnapshot(isolatedABeforeSendRoot.sessionId)
  141. : null;
  142. const runningIsolatedA = `E2E_MODEL_CONFIG_AUTO_DRAIN_RUNNING_ISOLATED_A_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  143. await sendV4Prompt(runningIsolatedA);
  144. const sessionIsolatedA = await waitForStreamingSession("隔离 A 没有进入 streaming");
  145. const queuedIsolatedA = `E2E_MODEL_CONFIG_QUEUE_ISOLATED_A_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  146. await sendV4Prompt(queuedIsolatedA);
  147. await waitForQueueContaining(`E2E_MODEL_CONFIG_QUEUE_ISOLATED_A_${runId}`);
  148. await waitForQueueCount(1);
  149. const isolatedAFirstRecord = await waitForUpstreamNetworkCapture(
  150. `E2E_MODEL_CONFIG_AUTO_DRAIN_RUNNING_ISOLATED_A_${runId}`,
  151. );
  152. try {
  153. assertUpstreamConfig(
  154. isolatedAFirstRecord,
  155. `E2E_MODEL_CONFIG_AUTO_DRAIN_RUNNING_ISOLATED_A_${runId}`,
  156. {
  157. model: UPSTREAM_MODEL,
  158. thoughtLevel: UPSTREAM_THOUGHT_LEVEL,
  159. },
  160. );
  161. } catch (error) {
  162. const isolatedAAfterSendRoot = await getV4ConversationState();
  163. const isolatedAAfterSendStore = await getTaskStoreSnapshot(sessionIsolatedA);
  164. throw new Error(
  165. [
  166. "隔离 A 首发请求模型配置不符合工具栏选择",
  167. `captureModel=${readCaptureModel(isolatedAFirstRecord)}`,
  168. `captureThoughtLevel=${readCaptureThoughtLevel(isolatedAFirstRecord)}`,
  169. `preflightToolbarMismatch=${isolatedAPreflightToolbarMismatch ?? "none"}`,
  170. `beforeRoot=${JSON.stringify(isolatedABeforeSendRoot)}`,
  171. `beforeStore=${JSON.stringify(isolatedABeforeSendStore)}`,
  172. `afterRoot=${JSON.stringify(isolatedAAfterSendRoot)}`,
  173. `afterStore=${JSON.stringify(isolatedAAfterSendStore)}`,
  174. ].join("; "),
  175. { cause: error },
  176. );
  177. }
  178. if (isolatedAPreflightToolbarMismatch) {
  179. throw new Error(
  180. [
  181. "隔离 A 首发请求真实配置已校验通过,但发送前 toolbar 未同步到目标配置",
  182. `captureModel=${readCaptureModel(isolatedAFirstRecord)}`,
  183. `captureThoughtLevel=${readCaptureThoughtLevel(isolatedAFirstRecord)}`,
  184. isolatedAPreflightToolbarMismatch,
  185. ].join("; "),
  186. );
  187. }
  188. await startNewV4Draft();
  189. await selectUpstreamModelById(UPSTREAM_SECONDARY_MODEL);
  190. await selectUpstreamThoughtLevelValue(UPSTREAM_SECONDARY_THOUGHT_LEVEL);
  191. await expectToolbarConfig(UPSTREAM_SECONDARY_MODEL, UPSTREAM_SECONDARY_THOUGHT_LEVEL);
  192. const activeDraft = await getV4ConversationState();
  193. expect(activeDraft.sessionId).not.toBe(sessionIsolatedA);
  194. const isolatedARecord = await waitForUpstreamNetworkCaptureWithStoreDebug(
  195. `E2E_MODEL_CONFIG_QUEUE_ISOLATED_A_${runId}`,
  196. sessionIsolatedA,
  197. );
  198. assertUpstreamConfig(isolatedARecord, `E2E_MODEL_CONFIG_QUEUE_ISOLATED_A_${runId}`, {
  199. model: UPSTREAM_MODEL,
  200. thoughtLevel: UPSTREAM_THOUGHT_LEVEL,
  201. });
  202. await expectToolbarConfig(UPSTREAM_SECONDARY_MODEL, UPSTREAM_SECONDARY_THOUGHT_LEVEL);
  203. await selectV4TaskById(sessionIsolatedA);
  204. await waitForV4ConversationState(
  205. (snapshot) => snapshot.sessionId === sessionIsolatedA && snapshot.queueCount === 0,
  206. "隔离 A queue 没有完成消费",
  207. 90000,
  208. );
  209. await expectToolbarConfig(UPSTREAM_MODEL, UPSTREAM_THOUGHT_LEVEL);
  210. await startNewV4Draft();
  211. await selectUpstreamModelById(UPSTREAM_MODEL);
  212. await selectUpstreamThoughtLevelValue(UPSTREAM_THOUGHT_LEVEL);
  213. await expectToolbarConfig(UPSTREAM_MODEL, UPSTREAM_THOUGHT_LEVEL, {
  214. includePlainModelFallback: false,
  215. providerId: UPSTREAM_PROVIDER_ID,
  216. });
  217. const crossProviderA = `E2E_MODEL_CONFIG_PROVIDER_A_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  218. await sendV4Prompt(crossProviderA);
  219. await waitForV4UserMessageContaining(`E2E_MODEL_CONFIG_PROVIDER_A_${runId}`);
  220. const crossProviderARecord = await waitForUpstreamNetworkCapture(
  221. `E2E_MODEL_CONFIG_PROVIDER_A_${runId}`,
  222. );
  223. assertUpstreamConfig(crossProviderARecord, `E2E_MODEL_CONFIG_PROVIDER_A_${runId}`, {
  224. model: UPSTREAM_MODEL,
  225. thoughtLevel: UPSTREAM_THOUGHT_LEVEL,
  226. });
  227. const sessionCrossProviderA = await waitForIdleSession("跨 provider A 首轮没有完成");
  228. await startNewV4Draft();
  229. await selectUpstreamProviderModelById(UPSTREAM_ALTERNATE_MODEL, {
  230. includePlainModelFallback: false,
  231. providerId: UPSTREAM_ALTERNATE_PROVIDER_ID,
  232. providerName: UPSTREAM_ALTERNATE_PROVIDER_NAME,
  233. });
  234. await selectUpstreamThoughtLevelValue(UPSTREAM_THOUGHT_LEVEL);
  235. await expectToolbarConfig(UPSTREAM_ALTERNATE_MODEL, UPSTREAM_THOUGHT_LEVEL, {
  236. includePlainModelFallback: false,
  237. providerId: UPSTREAM_ALTERNATE_PROVIDER_ID,
  238. });
  239. const crossProviderB = `E2E_MODEL_CONFIG_PROVIDER_B_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  240. await sendV4Prompt(crossProviderB);
  241. await waitForV4UserMessageContaining(`E2E_MODEL_CONFIG_PROVIDER_B_${runId}`);
  242. const crossProviderBRecord = await waitForUpstreamNetworkCapture(
  243. `E2E_MODEL_CONFIG_PROVIDER_B_${runId}`,
  244. );
  245. assertUpstreamConfig(crossProviderBRecord, `E2E_MODEL_CONFIG_PROVIDER_B_${runId}`, {
  246. model: UPSTREAM_ALTERNATE_MODEL,
  247. thoughtLevel: UPSTREAM_THOUGHT_LEVEL,
  248. });
  249. const sessionCrossProviderB = await waitForIdleSession("跨 provider B 首轮没有完成");
  250. expect(sessionCrossProviderB).not.toBe(sessionCrossProviderA);
  251. await selectV4TaskById(sessionCrossProviderA);
  252. await waitForV4ConversationState(
  253. (snapshot) => snapshot.sessionId === sessionCrossProviderA && snapshot.state === "idle",
  254. "切回跨 provider A 后没有恢复到 A session",
  255. 30000,
  256. );
  257. await expectToolbarConfig(UPSTREAM_MODEL, UPSTREAM_THOUGHT_LEVEL, {
  258. includePlainModelFallback: false,
  259. providerId: UPSTREAM_PROVIDER_ID,
  260. });
  261. await selectV4TaskById(sessionCrossProviderB);
  262. await waitForV4ConversationState(
  263. (snapshot) => snapshot.sessionId === sessionCrossProviderB && snapshot.state === "idle",
  264. "切回跨 provider B 后没有恢复到 B session",
  265. 30000,
  266. );
  267. await expectToolbarConfig(UPSTREAM_ALTERNATE_MODEL, UPSTREAM_THOUGHT_LEVEL, {
  268. includePlainModelFallback: false,
  269. providerId: UPSTREAM_ALTERNATE_PROVIDER_ID,
  270. });
  271. });
  272. });
  273. async function waitForUpstreamNetworkCaptureWithStoreDebug(expectedText: string, taskId: string) {
  274. try {
  275. return await waitForUpstreamNetworkCapture(expectedText);
  276. } catch (error) {
  277. const activeSnapshot = await getV4ConversationState();
  278. const taskStoreSnapshot = await getTaskStoreSnapshot(taskId);
  279. throw new Error(
  280. [
  281. `没有捕获到 上游 请求: ${expectedText}`,
  282. `active=${JSON.stringify(activeSnapshot)}`,
  283. `taskStore=${JSON.stringify(taskStoreSnapshot)}`,
  284. ].join("; "),
  285. { cause: error },
  286. );
  287. }
  288. }
  289. async function waitForIdleSession(timeoutMsg: string) {
  290. const snapshot = await waitForV4ConversationState(
  291. (current) => current.state === "idle" && Boolean(current.sessionId),
  292. timeoutMsg,
  293. 90000,
  294. );
  295. if (!snapshot.sessionId) {
  296. throw new Error(`${timeoutMsg}: sessionId missing`);
  297. }
  298. return snapshot.sessionId;
  299. }
  300. async function waitForStreamingSession(timeoutMsg: string) {
  301. const snapshot = await waitForV4ConversationState(
  302. (current) => current.state === "streaming" && Boolean(current.sessionId),
  303. timeoutMsg,
  304. 30000,
  305. );
  306. if (!snapshot.sessionId) {
  307. throw new Error(`${timeoutMsg}: sessionId missing`);
  308. }
  309. return snapshot.sessionId;
  310. }
  311. async function expectToolbarConfig(
  312. model: string,
  313. thoughtLevel: string,
  314. {
  315. includePlainModelFallback = true,
  316. providerId = UPSTREAM_PROVIDER_ID,
  317. }: {
  318. includePlainModelFallback?: boolean;
  319. providerId?: string;
  320. } = {},
  321. ) {
  322. const acceptedModelValues = getUpstreamProviderModelValues(model, {
  323. includePlainModelFallback,
  324. providerId,
  325. });
  326. // taskId 先切换,模型随历史 snapshot 异步恢复;以真实工具栏身份就绪作为断言屏障。
  327. await browser.waitUntil(
  328. async () => {
  329. const label = await getSelectedUpstreamModelLabel();
  330. return acceptedModelValues.includes(label.currentValue);
  331. },
  332. { timeout: 30000, timeoutMsg: `工具栏模型没有恢复到 ${providerId}/${model}` },
  333. );
  334. const modelLabel = await getSelectedUpstreamModelLabel();
  335. if (modelLabel.currentValue) {
  336. expect(acceptedModelValues).toContain(modelLabel.currentValue);
  337. } else if (!includePlainModelFallback) {
  338. throw new Error(
  339. `模型未精确暴露 provider 身份 ${providerId}/${model}: ${JSON.stringify({
  340. acceptedModelValues,
  341. modelLabel,
  342. })}`,
  343. );
  344. } else {
  345. expect(Object.values(modelLabel).join("\n")).toContain(model);
  346. }
  347. const thoughtLabel = await getSelectedUpstreamThoughtLevelLabel();
  348. const labelCandidates = Object.values(thoughtLabel)
  349. .map((value) => value.replace(/\s+/g, " ").trim().toLowerCase())
  350. .filter(Boolean);
  351. const expectedLabels = [thoughtLevel, ...getUpstreamThoughtLevelLabels(thoughtLevel)].map(
  352. (label) => label.replace(/\s+/g, " ").trim().toLowerCase(),
  353. );
  354. const matchedThoughtLevel = labelCandidates.some((label) => expectedLabels.includes(label));
  355. if (!matchedThoughtLevel) {
  356. throw new Error(
  357. `思考深度未精确匹配 ${thoughtLevel}: ${JSON.stringify({
  358. expectedLabels,
  359. thoughtLabel,
  360. })}`,
  361. );
  362. }
  363. }
  364. async function collectToolbarConfigMismatch(
  365. model: string,
  366. thoughtLevel: string,
  367. options?: Parameters<typeof expectToolbarConfig>[2],
  368. ) {
  369. try {
  370. await expectToolbarConfig(model, thoughtLevel, options);
  371. return null;
  372. } catch (error) {
  373. const activeSnapshot = await getV4ConversationState();
  374. const taskStoreSnapshot = activeSnapshot.taskId
  375. ? await getTaskStoreSnapshot(activeSnapshot.taskId)
  376. : null;
  377. return [
  378. `toolbarError=${error instanceof Error ? error.message : String(error)}`,
  379. `active=${JSON.stringify(activeSnapshot)}`,
  380. `taskStore=${JSON.stringify(taskStoreSnapshot)}`,
  381. ].join("; ");
  382. }
  383. }
  384. function assertUpstreamConfig(
  385. record: Awaited<ReturnType<typeof waitForUpstreamNetworkCapture>>,
  386. expectedText: string,
  387. {
  388. model,
  389. thoughtLevel,
  390. }: {
  391. model: string;
  392. thoughtLevel: string;
  393. },
  394. ) {
  395. assertUpstreamRequestCapture(record, { expectedText, model });
  396. assertUpstreamThoughtLevelCapture(record, thoughtLevel);
  397. }
  398. function readCaptureModel(record: Awaited<ReturnType<typeof waitForUpstreamNetworkCapture>>) {
  399. const requestJson = record.requestJson;
  400. if (
  401. requestJson &&
  402. typeof requestJson === "object" &&
  403. "model" in requestJson &&
  404. typeof requestJson.model === "string"
  405. ) {
  406. return requestJson.model;
  407. }
  408. return null;
  409. }
  410. function readCaptureThoughtLevel(
  411. record: Awaited<ReturnType<typeof waitForUpstreamNetworkCapture>>,
  412. ) {
  413. const requestJson = record.requestJson;
  414. if (!requestJson || typeof requestJson !== "object") {
  415. return null;
  416. }
  417. const outputConfig = "output_config" in requestJson ? requestJson.output_config : null;
  418. if (
  419. outputConfig &&
  420. typeof outputConfig === "object" &&
  421. "effort" in outputConfig &&
  422. typeof outputConfig.effort === "string"
  423. ) {
  424. return outputConfig.effort;
  425. }
  426. if ("reasoning_effort" in requestJson && typeof requestJson.reasoning_effort === "string") {
  427. return requestJson.reasoning_effort;
  428. }
  429. return null;
  430. }