(options: {
cwd: string
sessionDir?: string | undefined | null | undefined
settingsCwd?: string | undefined | null | undefined
chatGroupId?: string | undefined | null | undefined
sessionManager?: PiRuntime['session']['sessionManager']
})
| 213 | } |
| 214 | |
| 215 | async function createRuntime(options: { |
| 216 | cwd: string |
| 217 | sessionDir?: string | undefined | null | undefined |
| 218 | settingsCwd?: string | undefined | null | undefined |
| 219 | chatGroupId?: string | undefined | null | undefined |
| 220 | sessionManager?: PiRuntime['session']['sessionManager'] |
| 221 | }): Promise<PiRuntime> { |
| 222 | const { |
| 223 | AuthStorage, |
| 224 | ModelRegistry, |
| 225 | SessionManager, |
| 226 | SettingsManager, |
| 227 | DefaultResourceLoader, |
| 228 | createAgentSession, |
| 229 | getAgentDir, |
| 230 | } = await getPiModule() |
| 231 | const agentDir = getAgentDir() |
| 232 | const authStorage = AuthStorage.create() |
| 233 | const modelRegistry = normalizeModelRegistryContextWindows( |
| 234 | ModelRegistry.create(authStorage, `${agentDir}/models.json`), |
| 235 | ) |
| 236 | const settingsManager = createRuntimeSettingsManager({ |
| 237 | SettingsManager, |
| 238 | cwd: options.cwd, |
| 239 | agentDir, |
| 240 | settingsCwd: options.settingsCwd, |
| 241 | }) |
| 242 | const sessionDir = options.sessionDir ?? settingsManager.getSessionDir() ?? undefined |
| 243 | const resourceLoader = await createIsolatedRuntimeResourceLoader({ |
| 244 | DefaultResourceLoader, |
| 245 | cwd: options.cwd, |
| 246 | agentDir, |
| 247 | settingsCwd: options.settingsCwd, |
| 248 | settingsManager, |
| 249 | systemPrompt: getRuntimeSystemPrompt({ settingsCwd: options.settingsCwd }), |
| 250 | }) |
| 251 | const attachmentFileTools = options.settingsCwd |
| 252 | ? createAttachmentFileTools({ |
| 253 | cwd: options.cwd, |
| 254 | autoResizeImages: settingsManager.getImageAutoResize(), |
| 255 | }) |
| 256 | : null |
| 257 | const { session } = await createAgentSession({ |
| 258 | cwd: options.cwd, |
| 259 | agentDir, |
| 260 | authStorage, |
| 261 | modelRegistry, |
| 262 | settingsManager, |
| 263 | ...(resourceLoader ? { resourceLoader } : {}), |
| 264 | sessionManager: options.sessionManager ?? SessionManager.create(options.cwd, sessionDir), |
| 265 | ...(options.settingsCwd |
| 266 | ? { |
| 267 | noTools: 'builtin' as const, |
| 268 | customTools: [ |
| 269 | ...(attachmentFileTools?.tools ?? []), |
| 270 | ...createArtifactTools({ |
| 271 | createArtifact, |
| 272 | editArtifact, |
no test coverage detected