T-197: M2.1t (port to master) — Real PostgreSQL executor factory for the MCP copilot stdio host: restore openResearchCopilotExecutor(config) in libs/data/postgres/src/research-copilot-executor.ts from prior branch studio/auto-db2c48b5 (T-189) onto master (no new deps, no DuckDB, no bin)
This commit is contained in:
parent
4315d956ea
commit
9d39380ca8
4 changed files with 360 additions and 62 deletions
|
|
@ -133,7 +133,29 @@ function parseAndNormalizePoolConfig(config: ResearchCopilotExecutorConfig): Poo
|
|||
throw invalidConfigError();
|
||||
}
|
||||
|
||||
if (parsed.hostname.length === 0) {
|
||||
const hostQueryParams = parsed.searchParams.getAll('host');
|
||||
if (hostQueryParams.length > 1) {
|
||||
throw invalidConfigError();
|
||||
}
|
||||
const queryHost = hostQueryParams.length === 1 ? (hostQueryParams[0] as string).trim() : '';
|
||||
if (hostQueryParams.length === 1 && queryHost.length === 0) {
|
||||
throw invalidConfigError();
|
||||
}
|
||||
|
||||
const hasAuthorityHost = parsed.hostname.length > 0;
|
||||
if (hasAuthorityHost) {
|
||||
let decodedHost: string;
|
||||
try {
|
||||
decodedHost = decodeURIComponent(parsed.hostname);
|
||||
} catch {
|
||||
throw invalidConfigError();
|
||||
}
|
||||
if (decodedHost.trim().length === 0) {
|
||||
throw invalidConfigError();
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasAuthorityHost && queryHost.length === 0) {
|
||||
throw invalidConfigError();
|
||||
}
|
||||
|
||||
|
|
@ -190,21 +212,23 @@ function parseAndNormalizePoolConfig(config: ResearchCopilotExecutorConfig): Poo
|
|||
parsed.searchParams.delete(keysToDelete[i] as string);
|
||||
}
|
||||
|
||||
const enforcedOptions = `-c statement_timeout=${RESEARCH_COPILOT_PG_STATEMENT_TIMEOUT_MS} -c lock_timeout=${RESEARCH_COPILOT_PG_LOCK_TIMEOUT_MS}`;
|
||||
const options =
|
||||
existingOptions.length > 0
|
||||
? `${existingOptions.join(' ')} ${enforcedOptions}`
|
||||
: enforcedOptions;
|
||||
const envOptions = typeof process.env.PGOPTIONS === 'string' ? process.env.PGOPTIONS.trim() : '';
|
||||
const baseOptions = existingOptions.length > 0 ? existingOptions.join(' ') : envOptions;
|
||||
|
||||
return {
|
||||
const poolConfig: PoolConfig = {
|
||||
connectionString: parsed.toString(),
|
||||
max: RESEARCH_COPILOT_PG_POOL_MAX,
|
||||
connectionTimeoutMillis: RESEARCH_COPILOT_PG_CONNECT_TIMEOUT_MS,
|
||||
statement_timeout: RESEARCH_COPILOT_PG_STATEMENT_TIMEOUT_MS,
|
||||
query_timeout: RESEARCH_COPILOT_PG_QUERY_TIMEOUT_MS,
|
||||
lock_timeout: RESEARCH_COPILOT_PG_LOCK_TIMEOUT_MS,
|
||||
options,
|
||||
};
|
||||
|
||||
if (baseOptions.length > 0) {
|
||||
poolConfig.options = `${baseOptions} -c statement_timeout=${RESEARCH_COPILOT_PG_STATEMENT_TIMEOUT_MS} -c lock_timeout=${RESEARCH_COPILOT_PG_LOCK_TIMEOUT_MS}`;
|
||||
}
|
||||
|
||||
return poolConfig;
|
||||
}
|
||||
|
||||
function resolveCreatePool(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue