kimi-code / packages /agent-core-v2 /src /runtime /standaloneRuntime.ts
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
4e23b01 verified
Raw History Blame Contribute Delete
1.6 kB
import { createDecorator, type ServiceIdentifier } from '#/_base/di/instantiation';
import { ScopeActivation, registerScopedService } from '#/_base/di/scope';
import { LifecycleScope } from '#/app/scopes';
import { IHostEnvironment } from '#/os/interface/hostEnvironment';
import { IHostFileSystem } from '#/os/interface/hostFileSystem';
import { IHostProcessService } from '#/os/interface/hostProcess';
import { IHostTerminalService } from '#/os/interface/terminal';
import { LocalRuntime } from './localRuntime';
import type { Runtime } from './runtime';
export interface IStandaloneRuntimeFactory {
readonly _serviceBrand: undefined;
createLocalRuntime(workspaceId: string): Runtime;
}
export const IStandaloneRuntimeFactory: ServiceIdentifier<IStandaloneRuntimeFactory> =
createDecorator<IStandaloneRuntimeFactory>('standaloneRuntimeFactory');
export class StandaloneRuntimeFactory implements IStandaloneRuntimeFactory {
declare readonly _serviceBrand: undefined;
constructor(
@IHostEnvironment private readonly environment: IHostEnvironment,
@IHostFileSystem private readonly fs: IHostFileSystem,
@IHostProcessService private readonly process: IHostProcessService,
@IHostTerminalService private readonly terminal: IHostTerminalService,
) {}
createLocalRuntime(workspaceId: string): Runtime {
return new LocalRuntime(workspaceId, this.environment, this.fs, this.process, this.terminal);
}
}
registerScopedService(
LifecycleScope.App,
IStandaloneRuntimeFactory,
StandaloneRuntimeFactory,
ScopeActivation.OnDemand,
'standaloneRuntimeFactory',
);