(
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,
)
| 974 | } |
| 975 | |
| 976 | function runHeadlessStreaming( |
| 977 | structuredIO: StructuredIO, |
| 978 | mcpClients: MCPServerConnection[], |
| 979 | commands: Command[], |
| 980 | tools: Tools, |
| 981 | initialMessages: Message[], |
| 982 | canUseTool: CanUseToolFn, |
| 983 | sdkMcpConfigs: Record<string, McpSdkServerConfig>, |
| 984 | getAppState: () => AppState, |
| 985 | setAppState: (f: (prev: AppState) => AppState) => void, |
| 986 | agents: AgentDefinition[], |
| 987 | options: { |
| 988 | verbose: boolean | undefined |
| 989 | jsonSchema: Record<string, unknown> | undefined |
| 990 | permissionPromptToolName: string | undefined |
| 991 | allowedTools: string[] | undefined |
| 992 | thinkingConfig: ThinkingConfig | undefined |
| 993 | maxTurns: number | undefined |
| 994 | maxBudgetUsd: number | undefined |
| 995 | taskBudget: { total: number } | undefined |
| 996 | systemPrompt: string | undefined |
| 997 | appendSystemPrompt: string | undefined |
| 998 | userSpecifiedModel: string | undefined |
| 999 | fallbackModel: string | undefined |
| 1000 | replayUserMessages?: boolean | undefined |
| 1001 | includePartialMessages?: boolean | undefined |
| 1002 | enableAuthStatus?: boolean | undefined |
| 1003 | agent?: string | undefined |
| 1004 | setSDKStatus?: (status: SDKStatus) => void |
| 1005 | promptSuggestions?: boolean | undefined |
| 1006 | workload?: string | undefined |
| 1007 | }, |
| 1008 | turnInterruptionState?: TurnInterruptionState, |
| 1009 | ): AsyncIterable<StdoutMessage> { |
| 1010 | let running = false |
| 1011 | let runPhase: |
| 1012 | | 'draining_commands' |
| 1013 | | 'waiting_for_agents' |
| 1014 | | 'finally_flush' |
| 1015 | | 'finally_post_flush' |
| 1016 | | undefined |
| 1017 | let inputClosed = false |
| 1018 | let shutdownPromptInjected = false |
| 1019 | let heldBackResult: StdoutMessage | null = null |
| 1020 | let abortController: AbortController | undefined |
| 1021 | // Same queue sendRequest() enqueues to — one FIFO for everything. |
| 1022 | const output = structuredIO.outbound |
| 1023 | |
| 1024 | // Ctrl+C in -p mode: abort the in-flight query, then shut down gracefully. |
| 1025 | // gracefulShutdown persists session state and flushes analytics, with a |
| 1026 | // failsafe timer that force-exits if cleanup hangs. |
| 1027 | const sigintHandler = () => { |
| 1028 | logForDiagnosticsNoPII('info', 'shutdown_signal', { signal: 'SIGINT' }) |
| 1029 | if (abortController && !abortController.signal.aborted) { |
| 1030 | abortController.abort() |
| 1031 | } |
| 1032 | void gracefulShutdown(0) |
| 1033 | } |
no test coverage detected