From 38a4bbc75f55fe91727b1ada2e9986bbd57c373a Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sat, 14 Feb 2026 14:30:09 +0900 Subject: [PATCH] feat: add session-tools-store for tracking tool restrictions per session In-memory Map-based store that records tool restriction objects (e.g., question: false) by sessionID when prompts are sent. This enables retrieving the original session's tool parameters when background tasks complete and need to notify the parent session. --- src/shared/session-tools-store.test.ts | 72 ++++++++++++++++++++++++++ src/shared/session-tools-store.ts | 14 +++++ 2 files changed, 86 insertions(+) create mode 100644 src/shared/session-tools-store.test.ts create mode 100644 src/shared/session-tools-store.ts diff --git a/src/shared/session-tools-store.test.ts b/src/shared/session-tools-store.test.ts new file mode 100644 index 000000000..1e6f8c1ba --- /dev/null +++ b/src/shared/session-tools-store.test.ts @@ -0,0 +1,72 @@ +import { describe, test, expect, beforeEach } from "bun:test" +import { setSessionTools, getSessionTools, clearSessionTools } from "./session-tools-store" + +describe("session-tools-store", () => { + beforeEach(() => { + clearSessionTools() + }) + + test("returns undefined for unknown session", () => { + //#given + const sessionID = "ses_unknown" + + //#when + const result = getSessionTools(sessionID) + + //#then + expect(result).toBeUndefined() + }) + + test("stores and retrieves tools for a session", () => { + //#given + const sessionID = "ses_abc123" + const tools = { question: false, task: true, call_omo_agent: true } + + //#when + setSessionTools(sessionID, tools) + const result = getSessionTools(sessionID) + + //#then + expect(result).toEqual({ question: false, task: true, call_omo_agent: true }) + }) + + test("overwrites existing tools for same session", () => { + //#given + const sessionID = "ses_abc123" + setSessionTools(sessionID, { question: false }) + + //#when + setSessionTools(sessionID, { question: true, task: false }) + const result = getSessionTools(sessionID) + + //#then + expect(result).toEqual({ question: true, task: false }) + }) + + test("clearSessionTools removes all entries", () => { + //#given + setSessionTools("ses_1", { question: false }) + setSessionTools("ses_2", { task: true }) + + //#when + clearSessionTools() + + //#then + expect(getSessionTools("ses_1")).toBeUndefined() + expect(getSessionTools("ses_2")).toBeUndefined() + }) + + test("returns a copy, not a reference", () => { + //#given + const sessionID = "ses_abc123" + const tools = { question: false } + setSessionTools(sessionID, tools) + + //#when + const result = getSessionTools(sessionID)! + result.question = true + + //#then + expect(getSessionTools(sessionID)).toEqual({ question: false }) + }) +}) diff --git a/src/shared/session-tools-store.ts b/src/shared/session-tools-store.ts new file mode 100644 index 000000000..f717488e6 --- /dev/null +++ b/src/shared/session-tools-store.ts @@ -0,0 +1,14 @@ +const store = new Map>() + +export function setSessionTools(sessionID: string, tools: Record): void { + store.set(sessionID, { ...tools }) +} + +export function getSessionTools(sessionID: string): Record | undefined { + const tools = store.get(sessionID) + return tools ? { ...tools } : undefined +} + +export function clearSessionTools(): void { + store.clear() +}