()
| 363 | } |
| 364 | |
| 365 | function AddonManagerPage() { |
| 366 | const [chunks, setChunks] = useState<Array<any>>([]) |
| 367 | const [input, setInput] = useState('') |
| 368 | |
| 369 | // Initialize add-on state |
| 370 | const [addOnState, setAddOnState] = useState<Record<string, AddOnState>>( |
| 371 | () => { |
| 372 | const initial: Record<string, AddOnState> = {} |
| 373 | for (const addOn of availableAddOns) { |
| 374 | initial[addOn.id] = { selected: false, enabled: true } |
| 375 | } |
| 376 | return initial |
| 377 | }, |
| 378 | ) |
| 379 | |
| 380 | // Toggle add-on selection (for manual UI interaction) |
| 381 | const toggleAddOn = useCallback((id: string) => { |
| 382 | setAddOnState((prev) => ({ |
| 383 | ...prev, |
| 384 | [id]: { |
| 385 | ...prev[id], |
| 386 | selected: !prev[id]?.selected, |
| 387 | }, |
| 388 | })) |
| 389 | }, []) |
| 390 | |
| 391 | // Client tool 1: Returns current add-on state |
| 392 | const getAvailableAddOnsClient = useMemo( |
| 393 | () => |
| 394 | getAvailableAddOnsToolDef.client(() => { |
| 395 | console.log('[Client Tool] getAvailableAddOns called') |
| 396 | return availableAddOns.map((addOn) => ({ |
| 397 | id: addOn.id, |
| 398 | name: addOn.name, |
| 399 | description: addOn.description, |
| 400 | type: addOn.type, |
| 401 | selected: addOnState[addOn.id]?.selected ?? false, |
| 402 | enabled: addOnState[addOn.id]?.enabled ?? true, |
| 403 | })) |
| 404 | }), |
| 405 | [addOnState], |
| 406 | ) |
| 407 | |
| 408 | // Client tool 2: Selects add-ons |
| 409 | const selectAddOnsClient = useMemo( |
| 410 | () => |
| 411 | selectAddOnsToolDef.client((args) => { |
| 412 | console.log('[Client Tool] selectAddOns called with:', args) |
| 413 | |
| 414 | // Calculate what will be selected BEFORE calling setState |
| 415 | // (setState callback is async, so we can't read results from it) |
| 416 | const toSelect: string[] = [] |
| 417 | for (const addOnId of args.addOnIds) { |
| 418 | const state = addOnState[addOnId] |
| 419 | if (state && !state.selected && state.enabled) { |
| 420 | toSelect.push(addOnId) |
| 421 | } |
| 422 | } |
nothing calls this directly
no test coverage detected