| 42 | } |
| 43 | |
| 44 | export class KimiHarness { |
| 45 | readonly homeDir: string; |
| 46 | readonly configPath: string; |
| 47 | readonly auth: KimiAuthFacade; |
| 48 | |
| 49 | private readonly identity: KimiHostIdentity | undefined; |
| 50 | private readonly uiMode: string; |
| 51 | private readonly telemetry: TelemetryClient; |
| 52 | private readonly activeSessions = new Map<string, Session>(); |
| 53 | private readonly ensureConfigFileImpl: () => Promise<void>; |
| 54 | private readonly closeImpl: () => void | Promise<void>; |
| 55 | private readonly sessionStartedProperties: TelemetryProperties; |
| 56 | |
| 57 | constructor( |
| 58 | private readonly rpc: SDKRpcClientBase, |
| 59 | options: KimiHarnessRuntimeOptions, |
| 60 | ) { |
| 61 | this.identity = options.identity; |
| 62 | this.uiMode = options.uiMode ?? DEFAULT_SESSION_STARTED_UI_MODE; |
| 63 | this.homeDir = options.homeDir; |
| 64 | this.configPath = options.configPath; |
| 65 | this.telemetry = options.telemetry; |
| 66 | this.auth = options.auth; |
| 67 | this.ensureConfigFileImpl = options.ensureConfigFile; |
| 68 | this.closeImpl = options.onClose; |
| 69 | this.sessionStartedProperties = options.sessionStartedProperties ?? {}; |
| 70 | } |
| 71 | |
| 72 | get sessions(): ReadonlyMap<string, Session> { |
| 73 | return this.activeSessions; |
| 74 | } |
| 75 | |
| 76 | get interactiveAgentId(): string { |
| 77 | return this.rpc.interactiveAgentId; |
| 78 | } |
| 79 | |
| 80 | withInteractiveAgent<T>(agentId: string, fn: () => T): T { |
| 81 | return this.rpc.withInteractiveAgent(agentId, fn); |
| 82 | } |
| 83 | |
| 84 | track(event: string, properties?: TelemetryProperties): void { |
| 85 | this.telemetry.track(event, properties); |
| 86 | } |
| 87 | |
| 88 | setTelemetryContext(patch: TelemetryContextPatch): void { |
| 89 | this.telemetry.setContext?.(patch); |
| 90 | } |
| 91 | |
| 92 | async createSession(options: CreateSessionOptions): Promise<Session> { |
| 93 | const { planMode, kaos, persistenceKaos, sessionStartedProperties, ...coreOptions } = options; |
| 94 | const summary = |
| 95 | kaos === undefined && persistenceKaos === undefined |
| 96 | ? await this.rpc.createSession(coreOptions) |
| 97 | : await this.rpc.createSessionWithKaos(coreOptions, kaos ?? persistenceKaos as Kaos, persistenceKaos); |
| 98 | const session = new Session({ |
| 99 | id: summary.id, |
| 100 | workDir: summary.workDir, |
| 101 | summary, |
nothing calls this directly
no outgoing calls
no test coverage detected