| 522 | } |
| 523 | |
| 524 | function getOrCreatePythonReplManager( |
| 525 | toolUseContext: ToolUseContext, |
| 526 | toolName: string, |
| 527 | ): PythonReplManager { |
| 528 | const existing = toolUseContext.getAppState().pythonReplContexts?.get(toolName) |
| 529 | if (existing) { |
| 530 | return existing |
| 531 | } |
| 532 | |
| 533 | const created = new PythonReplManager() |
| 534 | toolUseContext.setAppState(prev => { |
| 535 | const contexts = new Map(prev.pythonReplContexts ?? []) |
| 536 | contexts.set(toolName, created) |
| 537 | return { |
| 538 | ...prev, |
| 539 | pythonReplContexts: contexts, |
| 540 | } |
| 541 | }) |
| 542 | return created |
| 543 | } |
| 544 | |
| 545 | export async function clearPythonReplContext( |
| 546 | toolUseContext: ToolUseContext, |