MCPcopy Create free account
hub / github.com/21st-dev/21st-sdk / buildSdkOptions

Function buildSdkOptions

packages/agent-runtime/src/runtime.ts:298–350  ·  view source on GitHub ↗
(config: AgentConfig, params: {
  sessionId?: string
  requestOptions?: AgentRequestOptions
})

Source from the content-addressed store, hash-verified

296// --- SDK options ---
297
298function buildSdkOptions(config: AgentConfig, params: {
299 sessionId?: string
300 requestOptions?: AgentRequestOptions
301}): Options {
302 const hooks = buildHooks(config)
303 const opts = params.requestOptions
304 const useMoat = isMoatEnabled()
305 const cleanEnv = getCleanEnv(opts)
306
307 // Shallow merge: request options override bundle config per-field
308 const effectiveModel = opts?.model ?? config.model
309 const effectiveSystemPrompt = opts?.systemPrompt ?? config.systemPrompt
310 const effectiveMaxTurns = opts?.maxTurns ?? config.maxTurns
311 const effectiveMaxBudgetUsd = opts?.maxBudgetUsd ?? config.maxBudgetUsd
312
313 let directMcpServers: ReturnType<typeof buildClaudeMcpServers> | undefined
314 if (!useMoat) {
315 directMcpServers = buildClaudeMcpServers({
316 host: "127.0.0.1",
317 env: cleanEnv,
318 })
319 writeDirectClaudeConfig(directMcpServers)
320 cleanEnv.HOME = DIRECT_CLAUDE_HOME
321 }
322
323 return {
324 executable: "node",
325 cwd: useMoat ? MOAT_WORKDIR : DIRECT_CLAUDE_WORKDIR,
326 ...(useMoat ? { pathToClaudeCodeExecutable: "claude" } : {}),
327 model: effectiveModel,
328 systemPrompt: effectiveSystemPrompt,
329 // Load filesystem-backed settings so Skills can be discovered from
330 // ~/.claude/skills and .claude/skills relative to cwd.
331 settingSources: ["user", "project"],
332 permissionMode: "bypassPermissions",
333 maxTurns: effectiveMaxTurns,
334 ...(effectiveMaxBudgetUsd && { maxBudgetUsd: effectiveMaxBudgetUsd }),
335 ...(opts?.disallowedTools && opts.disallowedTools.length > 0 && { disallowedTools: opts.disallowedTools }),
336 ...(directMcpServers ? { mcpServers: directMcpServers } : {}),
337 hooks,
338 ...(params.sessionId && { resume: params.sessionId, continue: true }),
339 includePartialMessages: true,
340 env: cleanEnv,
341 ...(useMoat
342 ? {
343 spawnClaudeCodeProcess: (options: SpawnOptions): SpawnedProcess =>
344 spawnMoatProcess(options),
345 }
346 : {}),
347 allowDangerouslySkipPermissions: true,
348 sandbox: { enabled: true, autoAllowBashIfSandboxed: true },
349 }
350}
351
352function writeDirectClaudeConfig(mcpServers: ReturnType<typeof buildClaudeMcpServers>) {
353 let config: Record<string, unknown> = {}

Callers 1

executeAgentFunction · 0.85

Calls 6

buildHooksFunction · 0.85
getCleanEnvFunction · 0.85
buildClaudeMcpServersFunction · 0.85
writeDirectClaudeConfigFunction · 0.85
spawnMoatProcessFunction · 0.85
isMoatEnabledFunction · 0.70

Tested by

no test coverage detected