(
structuredIO: StructuredIO,
mcpClients: MCPServerConnection[],
commands: Command[],
tools: Tools,
initialMessages: Message[],
canUseTool: CanUseToolFn,
sdkMcpConfigs: Record<string, McpSdkServerConfig>,
getAppState: () => AppState,
setAppState: (f: (prev: AppState) => AppState) => void,
agents: AgentDefinition[],
options: {
verbose: boolean | undefined
jsonSchema: Record<string, unknown> | undefined
permissionPromptToolName: string | undefined
allowedTools: string[] | undefined
thinkingConfig: ThinkingConfig | undefined
maxTurns: number | undefined
maxBudgetUsd: number | undefined
taskBudget: { total: number } | undefined
systemPrompt: string | undefined
appendSystemPrompt: string | undefined
userSpecifiedModel: string | undefined
fallbackModel: string | undefined
replayUserMessages?: boolean | undefined
includePartialMessages?: boolean | undefined
enableAuthStatus?: boolean | undefined
agent?: string | undefined
setSDKStatus?: (status: SDKStatus) => void
promptSuggestions?: boolean | undefined
workload?: string | undefined
},
turnInterruptionState?: TurnInterruptionState,
)
| 998 | } |
| 999 | |
| 1000 | function runHeadlessStreaming( |
| 1001 | structuredIO: StructuredIO, |
| 1002 | mcpClients: MCPServerConnection[], |
| 1003 | commands: Command[], |
| 1004 | tools: Tools, |
| 1005 | initialMessages: Message[], |
| 1006 | canUseTool: CanUseToolFn, |
| 1007 | sdkMcpConfigs: Record<string, McpSdkServerConfig>, |
| 1008 | getAppState: () => AppState, |
| 1009 | setAppState: (f: (prev: AppState) => AppState) => void, |
| 1010 | agents: AgentDefinition[], |
| 1011 | options: { |
| 1012 | verbose: boolean | undefined |
| 1013 | jsonSchema: Record<string, unknown> | undefined |
| 1014 | permissionPromptToolName: string | undefined |
| 1015 | allowedTools: string[] | undefined |
| 1016 | thinkingConfig: ThinkingConfig | undefined |
| 1017 | maxTurns: number | undefined |
| 1018 | maxBudgetUsd: number | undefined |
| 1019 | taskBudget: { total: number } | undefined |
| 1020 | systemPrompt: string | undefined |
| 1021 | appendSystemPrompt: string | undefined |
| 1022 | userSpecifiedModel: string | undefined |
| 1023 | fallbackModel: string | undefined |
| 1024 | replayUserMessages?: boolean | undefined |
| 1025 | includePartialMessages?: boolean | undefined |
| 1026 | enableAuthStatus?: boolean | undefined |
| 1027 | agent?: string | undefined |
| 1028 | setSDKStatus?: (status: SDKStatus) => void |
| 1029 | promptSuggestions?: boolean | undefined |
| 1030 | workload?: string | undefined |
| 1031 | }, |
| 1032 | turnInterruptionState?: TurnInterruptionState, |
| 1033 | ): AsyncIterable<StdoutMessage> { |
| 1034 | let running = false |
| 1035 | let runPhase: |
| 1036 | | 'draining_commands' |
| 1037 | | 'waiting_for_agents' |
| 1038 | | 'finally_flush' |
| 1039 | | 'finally_post_flush' |
| 1040 | | undefined |
| 1041 | let inputClosed = false |
| 1042 | let shutdownPromptInjected = false |
| 1043 | let heldBackResult: StdoutMessage | null = null |
| 1044 | let abortController: AbortController | undefined |
| 1045 | // Same queue sendRequest() enqueues to — one FIFO for everything. |
| 1046 | const output = structuredIO.outbound |
| 1047 | |
| 1048 | // Ctrl+C in -p mode: abort the in-flight query, then shut down gracefully. |
| 1049 | // gracefulShutdown persists session state and flushes analytics, with a |
| 1050 | // failsafe timer that force-exits if cleanup hangs. |
| 1051 | const sigintHandler = () => { |
| 1052 | logForDiagnosticsNoPII('info', 'shutdown_signal', { signal: 'SIGINT' }) |
| 1053 | if (abortController && !abortController.signal.aborted) { |
| 1054 | abortController.abort() |
| 1055 | } |
| 1056 | void gracefulShutdown(0) |
| 1057 | } |
no test coverage detected