MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / KimiHarness

Class KimiHarness

packages/node-sdk/src/kimi-harness.ts:44–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44export 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,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected