T-184: M2.1s — Real DuckDB store factory for the MCP copilot stdio host: openResearchCopilotStore(config) in libs/data/duckdb/src/research-copilot-store.ts (ResearchCopilotHostConfig → openDuckDbMarketDataStore → ManagedMarketDataStore, single Vault cutoff, real-DuckDB host test; no new deps, no pg, no bin)
This commit is contained in:
parent
b3b9697668
commit
4fe7b0da2b
3 changed files with 590 additions and 1 deletions
|
|
@ -121,7 +121,13 @@ export async function createNodeDuckDbExecutor(
|
|||
): Promise<ClosableDuckDbExecutor> {
|
||||
const databasePath = options.databasePath ?? ':memory:';
|
||||
const instance = await DuckDBInstance.create(databasePath);
|
||||
const connection: DuckDBConnection = await instance.connect();
|
||||
let connection: DuckDBConnection;
|
||||
try {
|
||||
connection = await instance.connect();
|
||||
} catch (err) {
|
||||
instance.closeSync();
|
||||
throw err;
|
||||
}
|
||||
let closed = false;
|
||||
|
||||
const assertOpen = (): void => {
|
||||
|
|
@ -264,3 +270,7 @@ export {
|
|||
type DuckDbParam,
|
||||
type PinnedAdjFactorsArtifact,
|
||||
};
|
||||
export {
|
||||
openResearchCopilotStore,
|
||||
type OpenResearchCopilotStoreOptions,
|
||||
} from './research-copilot-store';
|
||||
|
|
|
|||
49
libs/data/duckdb/src/research-copilot-store.ts
Normal file
49
libs/data/duckdb/src/research-copilot-store.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* Real DuckDB `MarketDataStore` factory for the MCP research copilot stdio host
|
||||
* (`runResearchCopilotStdioHost` in `@stock-bot/research/mcp`).
|
||||
*
|
||||
* - Uses `config.vaultCutoffTs` as the single authoritative Vault cutoff shared
|
||||
* between the host and the underlying DuckDB store, and hardcodes
|
||||
* `vaultOperatorAuthorized: false` so every query remains strictly
|
||||
* `'vault_fenced'`.
|
||||
* - Returns a {@link ManagedMarketDataStore} (`{ store, close }`) whose
|
||||
* `close()` releases the underlying DuckDB connection and instance.
|
||||
* - Any failure during open (native connection creation or store validation)
|
||||
* releases already-acquired DuckDB resources before rejecting.
|
||||
*/
|
||||
|
||||
import type {
|
||||
ManagedMarketDataStore,
|
||||
ResearchCopilotHostConfig,
|
||||
ResearchCopilotStdioHostDeps,
|
||||
} from '@stock-bot/research/mcp';
|
||||
import { openDuckDbMarketDataStore } from './index';
|
||||
|
||||
export interface OpenResearchCopilotStoreOptions {
|
||||
/** Optional DuckDB database path; defaults to `':memory:'`. */
|
||||
readonly databasePath?: string;
|
||||
/** Optional environment overrides for DuckDB connection budget (`STOCK_BOT_DUCKDB_*`). */
|
||||
readonly env?: Readonly<Record<string, string | undefined>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a Vault-fenced DuckDB-backed {@link ManagedMarketDataStore} from a
|
||||
* validated {@link ResearchCopilotHostConfig} for `ResearchCopilotStdioHostDeps.openStore`.
|
||||
*/
|
||||
export const openResearchCopilotStore = (async (
|
||||
config: ResearchCopilotHostConfig,
|
||||
options?: OpenResearchCopilotStoreOptions
|
||||
): Promise<ManagedMarketDataStore> => {
|
||||
const opened = await openDuckDbMarketDataStore({
|
||||
curatedRoot: config.curatedRoot,
|
||||
vaultCutoffTs: config.vaultCutoffTs,
|
||||
vaultOperatorAuthorized: false,
|
||||
...(options?.databasePath !== undefined ? { databasePath: options.databasePath } : {}),
|
||||
...(options?.env !== undefined ? { env: options.env } : {}),
|
||||
});
|
||||
|
||||
return {
|
||||
store: opened.store,
|
||||
close: opened.close,
|
||||
};
|
||||
}) satisfies ResearchCopilotStdioHostDeps['openStore'];
|
||||
Loading…
Add table
Add a link
Reference in a new issue