(config: {
prompt: QueryPrompt
options?: QueryOptions
})
| 184 | } |
| 185 | |
| 186 | export function query(config: { |
| 187 | prompt: QueryPrompt |
| 188 | options?: QueryOptions |
| 189 | }): Query { |
| 190 | const { |
| 191 | prompt, |
| 192 | options: { |
| 193 | allowedTools = [], |
| 194 | appendSystemPrompt, |
| 195 | customSystemPrompt, |
| 196 | cwd, |
| 197 | disallowedTools = [], |
| 198 | executable = 'node', |
| 199 | executableArgs = [], |
| 200 | maxTurns, |
| 201 | mcpServers, |
| 202 | pathToClaudeCodeExecutable = getDefaultClaudeCodePath(), |
| 203 | permissionMode = 'default', |
| 204 | continue: continueConversation, |
| 205 | resume, |
| 206 | model, |
| 207 | fallbackModel, |
| 208 | strictMcpConfig, |
| 209 | canCallTool, |
| 210 | settingsPath |
| 211 | } = {} |
| 212 | } = config |
| 213 | |
| 214 | if (!process.env.CLAUDE_CODE_ENTRYPOINT) { |
| 215 | process.env.CLAUDE_CODE_ENTRYPOINT = 'consortium-relay' |
| 216 | } |
| 217 | |
| 218 | const args = ['--output-format', 'stream-json', '--verbose'] |
| 219 | |
| 220 | if (customSystemPrompt) args.push('--system-prompt', customSystemPrompt) |
| 221 | if (appendSystemPrompt) args.push('--append-system-prompt', appendSystemPrompt) |
| 222 | if (maxTurns) args.push('--max-turns', maxTurns.toString()) |
| 223 | if (model) args.push('--model', model) |
| 224 | if (canCallTool) { |
| 225 | if (typeof prompt === 'string') { |
| 226 | throw new Error('canCallTool callback requires --input-format stream-json') |
| 227 | } |
| 228 | args.push('--permission-prompt-tool', 'stdio') |
| 229 | } |
| 230 | if (continueConversation) args.push('--continue') |
| 231 | if (resume) args.push('--resume', resume) |
| 232 | if (allowedTools.length > 0) args.push('--allowedTools', allowedTools.join(',')) |
| 233 | if (disallowedTools.length > 0) args.push('--disallowedTools', disallowedTools.join(',')) |
| 234 | if (mcpServers && Object.keys(mcpServers).length > 0) { |
| 235 | args.push('--mcp-config', JSON.stringify({ mcpServers })) |
| 236 | } |
| 237 | if (strictMcpConfig) args.push('--strict-mcp-config') |
| 238 | if (permissionMode) args.push('--permission-mode', permissionMode) |
| 239 | if (settingsPath) args.push('--settings', settingsPath) |
| 240 | if (fallbackModel) { |
| 241 | if (model && fallbackModel === model) { |
| 242 | throw new Error('Fallback model cannot be the same as the main model.') |
| 243 | } |
no test coverage detected