Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | 16x 16x 16x 2x 2x 16x 1x 1x 16x 2x 2x 16x 2x 2x 16x 2x 2x 16x 3x 3x 16x 1x 1x 16x 34x 16x 47x 2x 1x 2x 2x 2x 3x 1x 34x | /**
* Handlers for manage_context tool actions
*
* Each handler corresponds to an action in ManageContextSchema.
*/
import { getContextManager } from "./context-manager";
import {
ListPresetsInput,
ListProfilesInput,
ManageContextInput,
ResetContextInput,
SetScopeInput,
ShowContextInput,
SwitchPresetInput,
SwitchProfileInput,
WhoamiInput,
} from "./schema";
import {
PresetInfo,
ProfileInfo,
ResetResult,
SessionContext,
SetScopeResult,
SwitchResult,
WhoamiResult,
} from "./types";
import { executeWhoami } from "./whoami";
/**
* Handle show action - return current context
*/
export async function handleShowContext(_input: ShowContextInput): Promise<SessionContext> {
const manager = getContextManager();
return manager.getContext();
}
/**
* Handle list_presets action - return available presets
*/
export async function handleListPresets(_input: ListPresetsInput): Promise<PresetInfo[]> {
const manager = getContextManager();
return manager.listPresets();
}
/**
* Handle list_profiles action - return available profiles (OAuth only)
*/
export async function handleListProfiles(_input: ListProfilesInput): Promise<ProfileInfo[]> {
const manager = getContextManager();
return manager.listProfiles();
}
/**
* Handle switch_preset action - change active preset
*/
export async function handleSwitchPreset(input: SwitchPresetInput): Promise<SwitchResult> {
const manager = getContextManager();
return manager.switchPreset(input.preset);
}
/**
* Handle switch_profile action - change active profile (OAuth only)
*/
export async function handleSwitchProfile(input: SwitchProfileInput): Promise<SwitchResult> {
const manager = getContextManager();
return manager.switchProfile(input.profile);
}
/**
* Handle set_scope action - set namespace scope with auto-detection
*/
export async function handleSetScope(input: SetScopeInput): Promise<SetScopeResult> {
const manager = getContextManager();
return manager.setScope(input.namespace, input.includeSubgroups);
}
/**
* Handle reset action - restore initial context
*/
export async function handleResetContext(_input: ResetContextInput): Promise<ResetResult> {
const manager = getContextManager();
return manager.reset();
}
/**
* Handle whoami action - return authentication status and capabilities
*/
export async function handleWhoami(_input: WhoamiInput): Promise<WhoamiResult> {
return executeWhoami();
}
/**
* Main handler dispatcher for manage_context tool
*/
export async function handleManageContext(
input: ManageContextInput
): Promise<
| SessionContext
| PresetInfo[]
| ProfileInfo[]
| SwitchResult
| SetScopeResult
| ResetResult
| WhoamiResult
> {
switch (input.action) {
case "show":
return handleShowContext(input);
case "list_presets":
return handleListPresets(input);
case "list_profiles":
return handleListProfiles(input);
case "switch_preset":
return handleSwitchPreset(input);
case "switch_profile":
return handleSwitchProfile(input);
case "set_scope":
return handleSetScope(input);
case "reset":
return handleResetContext(input);
case "whoami":
return handleWhoami(input);
/* istanbul ignore next -- unreachable with Zod discriminatedUnion */
default:
throw new Error(`Unknown action: ${(input as { action: string }).action}`);
}
}
|