(options: {
cwd: string
sessionDir?: string | undefined | null | undefined
settingsCwd?: string | undefined | null | undefined
chatGroupId?: string | undefined | null | undefined
sessionManager?: PiRuntime['session']['sessionManager']
})
| 222 | } |
| 223 | |
| 224 | async function createRuntime(options: { |
| 225 | cwd: string |
| 226 | sessionDir?: string | undefined | null | undefined |
| 227 | settingsCwd?: string | undefined | null | undefined |
| 228 | chatGroupId?: string | undefined | null | undefined |
| 229 | sessionManager?: PiRuntime['session']['sessionManager'] |
| 230 | }): Promise<PiRuntime> { |
| 231 | const { |
| 232 | AuthStorage, |
| 233 | ModelRegistry, |
| 234 | SessionManager, |
| 235 | SettingsManager, |
| 236 | DefaultResourceLoader, |
| 237 | createAgentSession, |
| 238 | defineTool, |
| 239 | getAgentDir, |
| 240 | } = await getPiModule() |
| 241 | const agentDir = getAgentDir() |
| 242 | const authStorage = AuthStorage.create() |
| 243 | const modelRegistry = normalizeModelRegistryContextWindows( |
| 244 | ModelRegistry.create(authStorage, `${agentDir}/models.json`), |
| 245 | ) |
| 246 | const settingsManager = createRuntimeSettingsManager({ |
| 247 | SettingsManager, |
| 248 | cwd: options.cwd, |
| 249 | agentDir, |
| 250 | settingsCwd: options.settingsCwd, |
| 251 | }) |
| 252 | const sessionDir = options.sessionDir ?? settingsManager.getSessionDir() ?? undefined |
| 253 | const resourceLoader = await createIsolatedRuntimeResourceLoader({ |
| 254 | DefaultResourceLoader, |
| 255 | cwd: options.cwd, |
| 256 | agentDir, |
| 257 | settingsCwd: options.settingsCwd, |
| 258 | settingsManager, |
| 259 | systemPrompt: getRuntimeSystemPrompt({ settingsCwd: options.settingsCwd }), |
| 260 | }) |
| 261 | let runtime: PiRuntime | null = null |
| 262 | const enabledNativeExtensions = await getEnabledNativeExtensionsForRuntime( |
| 263 | options.sessionManager ? { sessionManager: options.sessionManager } : {}, |
| 264 | ) |
| 265 | const nativeAskQuestionTools = enabledNativeExtensions.includes('askQuestions') |
| 266 | ? await createNativeAskQuestionsTools({ |
| 267 | defineTool, |
| 268 | extensionPath: ensureAskQuestionsExtensionRuntimePath() ?? '', |
| 269 | getRuntime: () => runtime, |
| 270 | onStateChange: () => { |
| 271 | if (!runtime) return |
| 272 | const activeRuntime = runtime |
| 273 | void buildComposerState(activeRuntime).then((composer) => { |
| 274 | publishComposerUpdate(composer, { |
| 275 | projectId: activeRuntime.cwd, |
| 276 | sessionPath: activeRuntime.session.sessionFile, |
| 277 | }) |
| 278 | }) |
| 279 | }, |
| 280 | }) |
| 281 | : [] |
no test coverage detected