| 30 | }; |
| 31 | |
| 32 | export class AgentSessionBase<Mode> { |
| 33 | readonly path: string; |
| 34 | readonly logPath: string; |
| 35 | readonly api: ApiClient; |
| 36 | readonly client: ApiSessionClient; |
| 37 | readonly queue: MessageQueue2<Mode>; |
| 38 | protected readonly _onModeChange: (mode: 'local' | 'remote') => void; |
| 39 | |
| 40 | sessionId: string | null; |
| 41 | mode: 'local' | 'remote' = 'local'; |
| 42 | thinking: boolean = false; |
| 43 | |
| 44 | private sessionFoundCallbacks: ((sessionId: string) => void)[] = []; |
| 45 | private readonly applySessionIdToMetadata: (metadata: Metadata, sessionId: string, extras?: Partial<Metadata>) => Metadata; |
| 46 | private readonly sessionLabel: string; |
| 47 | private readonly sessionIdLabel: string; |
| 48 | private keepAliveInterval: NodeJS.Timeout | null = null; |
| 49 | protected permissionMode?: SessionPermissionMode; |
| 50 | protected model?: SessionModel; |
| 51 | protected modelReasoningEffort?: SessionModelReasoningEffort; |
| 52 | protected effort?: SessionEffort; |
| 53 | protected collaborationMode?: SessionCollaborationMode; |
| 54 | |
| 55 | constructor(opts: AgentSessionBaseOptions<Mode>) { |
| 56 | this.path = opts.path; |
| 57 | this.api = opts.api; |
| 58 | this.client = opts.client; |
| 59 | this.logPath = opts.logPath; |
| 60 | this.sessionId = opts.sessionId; |
| 61 | this.queue = opts.messageQueue; |
| 62 | this._onModeChange = opts.onModeChange; |
| 63 | this.applySessionIdToMetadata = opts.applySessionIdToMetadata; |
| 64 | this.sessionLabel = opts.sessionLabel; |
| 65 | this.sessionIdLabel = opts.sessionIdLabel; |
| 66 | this.mode = opts.mode ?? 'local'; |
| 67 | this.permissionMode = opts.permissionMode; |
| 68 | this.model = opts.model; |
| 69 | this.modelReasoningEffort = opts.modelReasoningEffort; |
| 70 | this.effort = opts.effort; |
| 71 | this.collaborationMode = opts.collaborationMode; |
| 72 | |
| 73 | this.queue.onBatchConsumed = (localIds) => this.client.emitMessagesConsumed(localIds); |
| 74 | |
| 75 | this.client.keepAlive(this.thinking, this.mode, this.getKeepAliveRuntime()); |
| 76 | this.keepAliveInterval = setInterval(() => { |
| 77 | this.client.keepAlive(this.thinking, this.mode, this.getKeepAliveRuntime()); |
| 78 | }, 2000); |
| 79 | |
| 80 | } |
| 81 | |
| 82 | onThinkingChange = (thinking: boolean) => { |
| 83 | this.thinking = thinking; |
| 84 | this.client.keepAlive(thinking, this.mode, this.getKeepAliveRuntime()); |
| 85 | }; |
| 86 | |
| 87 | pushKeepAlive = () => { |
| 88 | this.client.keepAlive(this.thinking, this.mode, this.getKeepAliveRuntime()); |
| 89 | }; |
nothing calls this directly
no test coverage detected