MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / loadMap

Function loadMap

apps/kimi-web/src/composables/useInputHistory.ts:43–59  ·  view source on GitHub ↗

* Read the persisted history map, migrating the legacy global `string[]` format * (pre per-session) into the current session on first sight. Migration is * one-shot: once a sessioned map is written, the array branch never runs again.

(sessionId: string | undefined)

Source from the content-addressed store, hash-verified

41 * one-shot: once a sessioned map is written, the array branch never runs again.
42 */
43function loadMap(sessionId: string | undefined): Record<string, string[]> {
44 const raw = safeGetJson<unknown>(STORAGE_KEYS.inputHistory);
45 if (Array.isArray(raw)) {
46 const list = raw.filter((s): s is string => typeof s === 'string' && s.length > 0);
47 // No session yet (empty-session composer): leave the legacy value in place
48 // so a later docked mount — which has a session id — can migrate it.
49 if (!sessionId || list.length === 0) return {};
50 const capped = list.length > MAX_HISTORY ? list.slice(-MAX_HISTORY) : list;
51 const map = { [sessionId]: capped };
52 safeSetJson(STORAGE_KEYS.inputHistory, map);
53 return map;
54 }
55 if (raw && typeof raw === 'object') {
56 return raw as Record<string, string[]>;
57 }
58 return {};
59}
60
61export function useInputHistory(deps: InputHistoryDeps) {
62 const { text, textareaRef, autosize, sessionId } = deps;

Callers 1

useInputHistoryFunction · 0.85

Calls 2

safeGetJsonFunction · 0.90
safeSetJsonFunction · 0.90

Tested by

no test coverage detected