UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

43 lines • 1.9 kB
import { loadClaudeAgentSdk, loadedClaudeAgentSdk } from "./sdk-boundary.lazy.js"; import { requireAnthropicSubscriptionCwd } from "./session-cwd.js"; export { loadClaudeAgentSdk } from "./sdk-boundary.lazy.js"; /** * Reads the deferred SDK module for a synchronous boundary member. * * `query` and `createSdkMcpServer` are synchronous SDK functions, so the * default boundary cannot await here. Every caller reaches these through an * async entry point that awaits `loadClaudeAgentSdk()` first, which makes an * unloaded module a wiring defect rather than a runtime condition — and this * names it at the exact call that skipped the preload. */ function requireLoadedSdk(member) { const sdk = loadedClaudeAgentSdk(); if (!sdk) { throw new Error(`Claude Agent SDK was not preloaded before '${member}'. ` + `Await loadClaudeAgentSdk() on the entry path before reaching the SDK boundary.`); } return sdk; } const defaultSdkBoundary = { query: (input) => { const cwd = requireAnthropicSubscriptionCwd(input.options?.cwd); return requireLoadedSdk("query").query({ ...input, options: { ...input.options, cwd } }); }, createSdkMcpServer: (options) => requireLoadedSdk("createSdkMcpServer").createSdkMcpServer(options), getSessionMessages: async (sessionId, options) => { const dir = requireAnthropicSubscriptionCwd(options?.dir); return (await loadClaudeAgentSdk()).getSessionMessages(sessionId, { ...options, dir }); }, }; let activeSdkBoundary = defaultSdkBoundary; export function getSdkBoundary() { return activeSdkBoundary; } export function overrideSdkBoundary(override) { activeSdkBoundary = { ...defaultSdkBoundary, ...override }; } export function resetSdkBoundary() { activeSdkBoundary = defaultSdkBoundary; } export default defaultSdkBoundary; //# sourceMappingURL=sdk-boundary.js.map