MCPcopy
hub / github.com/inkeep/open-knowledge / readArmedPaneTarget

Function readArmedPaneTarget

packages/server/src/pane-target.ts:26–47  ·  view source on GitHub ↗
(
  localDir: string,
  nowMs: number = Date.now(),
  ttlMs: number = PANE_TARGET_TTL_MS,
)

Source from the content-addressed store, hash-verified

24}
25
26export function readArmedPaneTarget(
27 localDir: string,
28 nowMs: number = Date.now(),
29 ttlMs: number = PANE_TARGET_TTL_MS,
30): string | null {
31 const path = resolve(localDir, PANE_TARGET_FILE);
32 if (!existsSync(path)) return null;
33 try {
34 const state = JSON.parse(readFileSync(path, 'utf-8')) as Partial<PaneTargetState>;
35 if (typeof state.route !== 'string' || typeof state.armedAtMs !== 'number') return null;
36 if (nowMs - state.armedAtMs > ttlMs) return null;
37 return state.route;
38 } catch (err) {
39 const code = (err as { code?: string }).code;
40 if (code === 'EACCES' || code === 'EPERM' || code === 'EIO') {
41 process.stderr.write(
42 `[pane-target] readArmedPaneTarget failed at ${path}: ${err instanceof Error ? err.message : String(err)}\n`,
43 );
44 }
45 return null;
46 }
47}
48
49export function clearArmedPaneTarget(localDir: string): void {
50 const path = resolve(localDir, PANE_TARGET_FILE);

Callers 5

handleApiConfigFunction · 0.90
requestHandlerFunction · 0.85
ui.test.tsFile · 0.85

Calls 2

parseMethod · 0.80
writeMethod · 0.65

Tested by

no test coverage detected