MCPcopy Create free account
hub / github.com/IgorWarzocha/howcode / setComposerModel

Function setComposerModel

desktop/runtime-host/live-runtime-service.ts:277–319  ·  view source on GitHub ↗
(
  request: ComposerStateRequest,
  provider: string,
  modelId: string,
)

Source from the content-addressed store, hash-verified

275}
276
277export async function setComposerModel(
278 request: ComposerStateRequest,
279 provider: string,
280 modelId: string,
281) {
282 const persistedSessionPath = getPersistedSessionPath(request.sessionPath)
283 if (!persistedSessionPath) {
284 const { AuthStorage, ModelRegistry, SettingsManager, getAgentDir } = await getPiModule()
285 const cwd = request.projectId ?? getDesktopWorkingDirectory()
286 const agentDir = getAgentDir()
287 const authStorage = AuthStorage.create()
288 const modelRegistry = normalizeModelRegistryContextWindows(
289 ModelRegistry.create(authStorage, `${agentDir}/models.json`),
290 )
291 const model = modelRegistry.find(provider, modelId)
292 if (!model) throw new Error(`Unknown Pi model: ${provider}/${modelId}`)
293 const currentComposer = await buildComposerStateSnapshot({ projectId: cwd, sessionPath: null })
294 const settingsManager = SettingsManager.create(cwd, agentDir)
295 settingsManager.setDefaultModelAndProvider(provider, modelId)
296 settingsManager.setDefaultThinkingLevel(
297 clampThinkingLevel(
298 currentComposer.currentThinkingLevel,
299 getAvailableThinkingLevelsForModel(model),
300 ),
301 )
302 await emitComposerUpdate({ ...request, sessionPath: null })
303 return { ok: true as const }
304 }
305 await withRuntimeMutationLock(persistedSessionPath, async () => {
306 await reloadRuntimeSettingsIfSafe(persistedSessionPath, { useMutationLock: false })
307 const runtime = await getOrCreateRuntimeForSessionPath(persistedSessionPath, {
308 suspendDisposal: true,
309 settingsCwd: request.composerSessionDir ?? null,
310 chatGroupId: request.chatGroupId ?? null,
311 })
312 const model = runtime.session.modelRegistry.find(provider, modelId)
313 if (!model) throw new Error(`Unknown Pi model: ${provider}/${modelId}`)
314 await runtime.session.setModel(model)
315 scheduleRuntimeDisposal(persistedSessionPath)
316 await emitComposerUpdate({ ...request, sessionPath: persistedSessionPath })
317 })
318 return { ok: true as const }
319}
320
321export async function setComposerThinkingLevel(
322 request: ComposerStateRequest,

Callers 1

handleRequestFunction · 0.90

Calls 12

getPersistedSessionPathFunction · 0.90
getPiModuleFunction · 0.90
clampThinkingLevelFunction · 0.90
withRuntimeMutationLockFunction · 0.90
scheduleRuntimeDisposalFunction · 0.90
emitComposerUpdateFunction · 0.70

Tested by

no test coverage detected