Skip to content

Commit c360bff

Browse files
yuyutaotaoclaude
andauthored
refactor(core): extract sessionId as Agent class property (#2145)
Instead of reading/writing this.opts.sessionId with non-null assertions everywhere, promote sessionId to a direct class property initialized once in the constructor. https://claude.ai/code/session_01VZbocRoe9k622Hebn3DFSe Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8195b5e commit c360bff

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

packages/core/src/agent/agent.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ export class Agent<
164164

165165
opts: AgentOpt;
166166

167+
sessionId: string;
168+
167169
/**
168170
* If true, the agent will not perform any actions
169171
*/
@@ -356,9 +358,7 @@ export class Agent<
356358
getReportFileName(opts?.testId || this.interface.interfaceType || 'web');
357359

358360
// Every agent always has a sessionId - auto-generate from reportFileName if not provided
359-
if (!this.opts.sessionId) {
360-
this.opts.sessionId = this.reportFileName!;
361-
}
361+
this.sessionId = this.opts.sessionId || this.reportFileName!;
362362

363363
this.syncSessionMetadata();
364364
}
@@ -423,7 +423,7 @@ export class Agent<
423423

424424
private syncSessionMetadata(): void {
425425
this.executionStore.ensureSession({
426-
sessionId: this.opts.sessionId!,
426+
sessionId: this.sessionId,
427427
platform: this.interface.interfaceType,
428428
groupName: this.opts.groupName,
429429
groupDescription: this.opts.groupDescription,
@@ -439,15 +439,12 @@ export class Agent<
439439
): void {
440440
let order = this.sessionExecutionOrders[executionIndex];
441441
if (order === undefined) {
442-
order = this.executionStore.appendExecution(
443-
this.opts.sessionId!,
444-
execution,
445-
);
442+
order = this.executionStore.appendExecution(this.sessionId, execution);
446443
this.sessionExecutionOrders[executionIndex] = order;
447444
return;
448445
}
449446

450-
this.executionStore.updateExecution(this.opts.sessionId!, order, execution);
447+
this.executionStore.updateExecution(this.sessionId, order, execution);
451448
}
452449

453450
appendExecutionDump(execution: ExecutionDump, runner?: TaskRunner): number {
@@ -1308,7 +1305,7 @@ export class Agent<
13081305
if (this.opts.generateReport !== false) {
13091306
try {
13101307
this.reportFile = exportSessionReport(
1311-
this.opts.sessionId!,
1308+
this.sessionId,
13121309
this.executionStore,
13131310
);
13141311
} catch (error) {

0 commit comments

Comments
 (0)