cograph 0.1.24 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -321,6 +321,41 @@ var Client = class {
321
321
  if (opts.model) body.model = opts.model;
322
322
  return this.request("POST", `${this.base()}/ask`, body, 6e4);
323
323
  }
324
+ /**
325
+ * One turn of the unified Ask-AI agent — the SINGLE conversational surface
326
+ * (`POST /graphs/{tenant}/agent`, COG-118). Mirrors the HTTP contract exactly:
327
+ *
328
+ * - `confirmPlanId` set → the server runs `execute_plan` (the only mutating
329
+ * path) and returns `{kind:"result", steps}`.
330
+ * - otherwise → the server runs `planner.handle(message)` and returns one of
331
+ * `{kind:"answer"}` / `{kind:"clarify"}` / `{kind:"plan"}`.
332
+ *
333
+ * The agent classifies intent server-side and drives the underlying engines
334
+ * through its capability registry — the client never talks to `/ask`,
335
+ * `/enrich/*` etc. for an agent turn. ENTITLEMENT for any paid step a plan
336
+ * contains is enforced server-side at execute time (the same authorization the
337
+ * direct paid routes apply), so confirming a plan here cannot bypass a gate the
338
+ * direct path enforces — the gate lives behind the endpoint, not in this client.
339
+ */
340
+ async agent(opts) {
341
+ const body = {
342
+ message: opts.message ?? "",
343
+ context: {
344
+ kg_name: opts.kgName ?? "",
345
+ type_name: opts.typeName ?? null
346
+ }
347
+ };
348
+ if (opts.sessionId) body.session_id = opts.sessionId;
349
+ if (opts.confirmPlanId) body.confirm = { plan_id: opts.confirmPlanId };
350
+ return this.request(
351
+ "POST",
352
+ `${this.base()}/agent`,
353
+ body,
354
+ // Generous: a confirmed plan can kick off enrichment/dedup work, and a
355
+ // question turn runs an LLM round-trip server-side.
356
+ 12e4
357
+ );
358
+ }
324
359
  /** List the tenants the authenticated user can access (GET /v1/me/tenants).
325
360
  * Keyed by the API key (X-API-Key → user), so it's independent of the active
326
361
  * tenant. Throws CographError with status 501 on deployments without a tenant
@@ -520,4 +555,4 @@ export {
520
555
  CographError,
521
556
  Client
522
557
  };
523
- //# sourceMappingURL=chunk-YFM3KDCO.js.map
558
+ //# sourceMappingURL=chunk-O3L4FCRY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from \"node:fs\";\nimport { extname } from \"node:path\";\nimport { readConfig } from \"./config.js\";\n\nexport class CographError extends Error {\n status?: number;\n body?: string;\n\n constructor(message: string, opts?: { status?: number; body?: string }) {\n super(message);\n this.name = \"CographError\";\n this.status = opts?.status;\n this.body = opts?.body;\n }\n}\n\nexport interface ClientOptions {\n apiKey?: string;\n baseUrl?: string;\n tenant?: string;\n}\n\nexport interface IngestOptions {\n kg?: string;\n contentType?: \"text\" | \"csv\" | \"json\" | string;\n /** Rows per batch for CSV ingest. Default 200. Larger = fewer round-trips\n * but higher per-request memory; 200 is a good balance for typical KGs. */\n batchSize?: number;\n /** Max number of batches in flight at once. Default 4. Higher saturates\n * the backend faster but risks 429s on large ingests. */\n concurrency?: number;\n /** Called after each batch completes during CSV ingest, in batch order.\n * Use for progress UI. Not invoked for text/json ingest. */\n onProgress?: (progress: IngestProgress) => void;\n /** CSV only. Called once after schema inference and BEFORE any rows are\n * written, with the inferred mapping. Return the (possibly edited/approved)\n * mapping to ingest, or `null` to cancel without writing anything. When\n * omitted the inferred mapping is applied as-is (non-interactive). This is\n * the same confirm/override gate the Explorer surfaces in its review step. */\n onSchemaInferred?: (\n mapping: Record<string, unknown>,\n info: { totalRows: number; rowsProfiled: number },\n ) => Promise<Record<string, unknown> | null>;\n}\n\nexport interface IngestProgress {\n rowsProcessed: number;\n totalRows: number;\n entitiesResolved: number;\n triplesInserted: number;\n}\n\n/** Rows sent to schema inference. Profile fidelity = decision quality, so we\n * send the whole file up to this cap, evenly strided across it (never the\n * head — head-of-file bias is exactly what evidence-grounded inference fixes).\n * Matches the Explorer's SCHEMA_SAMPLE_CAP. */\nexport const SCHEMA_SAMPLE_CAP = 5000;\n\nfunction stridedSample<T>(rows: T[], cap: number = SCHEMA_SAMPLE_CAP): T[] {\n if (rows.length <= cap) return rows;\n const out: T[] = [];\n for (let i = 0; i < cap; i++) out.push(rows[Math.floor((i * rows.length) / cap)]!);\n return out;\n}\n\nexport interface AskOptions {\n kg?: string;\n model?: string;\n}\n\nfunction envVar(name: string, fallback?: string): string | undefined {\n // Prefer COGRAPH_, fall back to OMNIX_ so old configs keep working.\n return (\n process.env[`COGRAPH_${name}`] ||\n process.env[`OMNIX_${name}`] ||\n fallback\n );\n}\n\nconst EXT_FORMAT: Record<string, string> = {\n \".csv\": \"csv\",\n \".json\": \"json\",\n \".jsonl\": \"json\",\n \".txt\": \"text\",\n};\n\n/**\n * Parse a CSV string into an array of row objects.\n *\n * Minimal RFC-4180-ish parser: handles quoted fields with commas, escaped\n * quotes (`\"\"`), CRLF/LF line endings. Does not handle BOM stripping or\n * encoding detection — we assume UTF-8 text in.\n */\nexport function parseCsv(content: string): Record<string, string>[] {\n const rows: string[][] = [];\n let cur: string[] = [];\n let field = \"\";\n let inQuotes = false;\n\n for (let i = 0; i < content.length; i++) {\n const ch = content[i];\n if (inQuotes) {\n if (ch === '\"') {\n if (content[i + 1] === '\"') {\n field += '\"';\n i++;\n } else {\n inQuotes = false;\n }\n } else {\n field += ch;\n }\n } else {\n if (ch === '\"') {\n inQuotes = true;\n } else if (ch === \",\") {\n cur.push(field);\n field = \"\";\n } else if (ch === \"\\n\") {\n cur.push(field);\n rows.push(cur);\n cur = [];\n field = \"\";\n } else if (ch === \"\\r\") {\n // swallow; handled by the following \\n in CRLF, or treat lone \\r as line end\n if (content[i + 1] !== \"\\n\") {\n cur.push(field);\n rows.push(cur);\n cur = [];\n field = \"\";\n }\n } else {\n field += ch;\n }\n }\n }\n // flush trailing field/row\n if (field.length > 0 || cur.length > 0) {\n cur.push(field);\n rows.push(cur);\n }\n\n if (rows.length === 0) return [];\n const headers = rows[0]!.map((h) => h.trim());\n const out: Record<string, string>[] = [];\n for (let r = 1; r < rows.length; r++) {\n const row = rows[r]!;\n // skip blank trailing lines\n if (row.length === 1 && row[0] === \"\") continue;\n const obj: Record<string, string> = {};\n for (let c = 0; c < headers.length; c++) {\n obj[headers[c]!] = row[c] ?? \"\";\n }\n out.push(obj);\n }\n return out;\n}\n\nexport class Client {\n apiKey: string | undefined;\n baseUrl: string;\n tenant: string;\n\n constructor(opts: ClientOptions = {}) {\n // Resolution order for each field: explicit opts → env var → ~/.cograph/config.json\n // (written by `cograph login`) → built-in default. Reading the config eagerly\n // is cheap (small JSON file) and lets users skip env vars entirely after login.\n const cfg = readConfig();\n this.apiKey = opts.apiKey ?? envVar(\"API_KEY\") ?? cfg.apiKey;\n const url =\n opts.baseUrl ?? envVar(\"API_URL\") ?? cfg.apiUrl ?? \"https://api.cograph.cloud\";\n this.baseUrl = url.replace(/\\/+$/, \"\");\n this.tenant = opts.tenant ?? envVar(\"TENANT\") ?? cfg.tenant ?? \"demo-tenant\";\n }\n\n private headers(): Record<string, string> {\n const h: Record<string, string> = { \"Content-Type\": \"application/json\" };\n if (this.apiKey) h[\"X-API-Key\"] = this.apiKey;\n return h;\n }\n\n private base(): string {\n return `${this.baseUrl}/graphs/${this.tenant}`;\n }\n\n /**\n * Probe the backend to determine reachability and whether endpoints\n * require an X-API-Key header. Used at shell startup to distinguish\n * cloud (auth required) from self-hosted open-access deployments.\n */\n async healthCheck(): Promise<{\n ok: boolean;\n requiresAuth: boolean;\n url: string;\n }> {\n const healthUrl = `${this.baseUrl}/health`;\n try {\n const res = await fetch(healthUrl, {\n signal: AbortSignal.timeout(5000),\n });\n if (!res.ok) return { ok: false, requiresAuth: false, url: this.baseUrl };\n } catch {\n return { ok: false, requiresAuth: false, url: this.baseUrl };\n }\n // Probe whether endpoints require auth by hitting /kgs without X-API-Key.\n // 401 = requires auth; 200/empty = open access; anything else = treat as\n // auth-required to be safe.\n try {\n const res = await fetch(`${this.base()}/kgs`, {\n headers: { \"Content-Type\": \"application/json\" },\n signal: AbortSignal.timeout(5000),\n });\n return {\n ok: true,\n requiresAuth: res.status === 401,\n url: this.baseUrl,\n };\n } catch {\n return { ok: true, requiresAuth: true, url: this.baseUrl };\n }\n }\n\n private async request<T = unknown>(\n method: string,\n url: string,\n body?: unknown,\n timeoutMs: number = 120_000,\n ): Promise<T> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n let res: Response;\n try {\n res = await fetch(url, {\n method,\n headers: this.headers(),\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: controller.signal,\n });\n } catch (err) {\n clearTimeout(timer);\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new CographError(`Request to ${url} timed out after ${timeoutMs}ms`);\n }\n throw new CographError(\n `Network error contacting ${url}: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n clearTimeout(timer);\n\n if (!res.ok) {\n let text = \"\";\n try {\n text = await res.text();\n } catch {\n // ignore\n }\n throw new CographError(`HTTP ${res.status}: ${text}`, {\n status: res.status,\n body: text,\n });\n }\n\n // 204 No Content\n if (res.status === 204) return undefined as T;\n\n const ct = res.headers.get(\"content-type\") ?? \"\";\n if (ct.includes(\"application/json\")) {\n return (await res.json()) as T;\n }\n // fall back to text\n const text = await res.text();\n try {\n return JSON.parse(text) as T;\n } catch {\n return text as unknown as T;\n }\n }\n\n /**\n * Ingest a file path or raw text into a knowledge graph.\n *\n * If `pathOrText` points to an existing file, its contents are read and the\n * format is inferred from the extension (.csv, .json, .txt) unless\n * `contentType` is given. CSV files use the two-step schema-inference + row\n * mapping flow.\n */\n async ingest(\n pathOrText: string,\n opts: IngestOptions = {},\n ): Promise<Record<string, unknown>> {\n let content: string;\n let fmt: string;\n\n let isFile = false;\n try {\n isFile = existsSync(pathOrText) && statSync(pathOrText).isFile();\n } catch {\n isFile = false;\n }\n\n if (isFile) {\n const ext = extname(pathOrText).toLowerCase();\n if (ext === \".pdf\") {\n throw new CographError(\n \"PDF ingest not yet supported in the Node CLI; use the Python CLI or POST raw bytes to the API.\",\n );\n }\n content = readFileSync(pathOrText, \"utf-8\");\n fmt = opts.contentType ?? EXT_FORMAT[ext] ?? \"text\";\n if (fmt === \"csv\") {\n return this.ingestCsv(content, opts);\n }\n } else {\n content = pathOrText;\n fmt = opts.contentType ?? \"text\";\n }\n\n const body: Record<string, unknown> = {\n content,\n content_type: fmt,\n source: \"client\",\n };\n if (opts.kg) body.kg_name = opts.kg;\n return this.request(\"POST\", `${this.base()}/ingest`, body, 120_000);\n }\n\n private async ingestCsv(\n content: string,\n opts: IngestOptions,\n ): Promise<Record<string, unknown>> {\n const kgName = opts.kg;\n const batchSize = opts.batchSize ?? 200;\n const concurrency = opts.concurrency ?? 4;\n\n const rows = parseCsv(content);\n if (rows.length === 0) throw new CographError(\"CSV is empty\");\n const headers = Object.keys(rows[0]!);\n\n // Send the whole file to the profiler, evenly strided across it (never the\n // head — head-of-file bias, e.g. a key column that goes sparse later, is\n // exactly what evidence-grounded inference fixes). Profile fidelity =\n // decision quality. Mirrors the Explorer's upload flow.\n const sampleRows = stridedSample(rows);\n\n const schemaBody = {\n headers,\n sample_rows: sampleRows,\n total_rows: rows.length,\n };\n const mapping = await this.request<Record<string, unknown>>(\n \"POST\",\n `${this.base()}/ingest/csv/schema`,\n schemaBody,\n 300_000,\n );\n\n // Confirm/override gate (same contract as the Explorer's review step): the\n // caller inspects the inferred mapping and returns what to ingest, or null\n // to cancel before any rows are written. /ingest/csv/rows applies exactly\n // what we post back. When no hook is given, apply the inference as-is.\n let mappingToPost: Record<string, unknown> = mapping;\n if (opts.onSchemaInferred) {\n const reviewed = await opts.onSchemaInferred(mapping, {\n totalRows: rows.length,\n rowsProfiled: sampleRows.length,\n });\n if (reviewed == null) {\n return { cancelled: true, message: \"Ingest cancelled before any rows were written.\" };\n }\n mappingToPost = reviewed;\n }\n\n // Slice rows into batches up front so we can fire them off in a\n // bounded worker pool. Sequential 50-row batches over 891 rows took\n // ~60s end-to-end (18 round-trips); 200-row batches × 4 in flight\n // brings that to ~5s on the same backend.\n const batches: Array<Record<string, string>[]> = [];\n for (let i = 0; i < rows.length; i += batchSize) {\n batches.push(rows.slice(i, i + batchSize));\n }\n\n let totalEntities = 0;\n let totalTriples = 0;\n let rowsProcessed = 0;\n let nextBatch = 0;\n\n const postBatch = async (batch: Record<string, string>[]) => {\n const body: Record<string, unknown> = {\n mapping: mappingToPost,\n rows: batch,\n source: \"client\",\n };\n if (kgName) body.kg_name = kgName;\n const result = await this.request<{\n entities_resolved?: number;\n triples_inserted?: number;\n }>(\"POST\", `${this.base()}/ingest/csv/rows`, body, 300_000);\n return {\n entities: result.entities_resolved ?? 0,\n triples: result.triples_inserted ?? 0,\n size: batch.length,\n };\n };\n\n const worker = async (): Promise<void> => {\n while (true) {\n const idx = nextBatch++;\n if (idx >= batches.length) return;\n const r = await postBatch(batches[idx]!);\n totalEntities += r.entities;\n totalTriples += r.triples;\n rowsProcessed += r.size;\n opts.onProgress?.({\n rowsProcessed,\n totalRows: rows.length,\n entitiesResolved: totalEntities,\n triplesInserted: totalTriples,\n });\n }\n };\n\n const workers: Array<Promise<void>> = [];\n for (let i = 0; i < Math.min(concurrency, batches.length); i++) {\n workers.push(worker());\n }\n await Promise.all(workers);\n\n // All batches are in — kick off a background recompute of the Explorer\n // type-stats for this KG so type-detail views load instantly. The endpoint\n // returns immediately (the scan runs server-side in the background); this\n // is best-effort and never fails the ingest.\n if (kgName) {\n try {\n await this.request(\n \"POST\",\n `${this.base()}/explore/kgs/${encodeURIComponent(kgName)}/recompute-stats`,\n {},\n 15_000,\n );\n } catch {\n // non-fatal — stats fall back to a live scan until the next recompute\n }\n }\n\n return {\n entities_resolved: totalEntities,\n triples_inserted: totalTriples,\n mapping,\n };\n }\n\n /** Ask a natural language question and return the parsed response. */\n async ask(\n question: string,\n opts: AskOptions = {},\n ): Promise<Record<string, unknown>> {\n const body: Record<string, unknown> = { question };\n if (opts.kg) body.kg_name = opts.kg;\n if (opts.model) body.model = opts.model;\n return this.request(\"POST\", `${this.base()}/ask`, body, 60_000);\n }\n\n /**\n * One turn of the unified Ask-AI agent — the SINGLE conversational surface\n * (`POST /graphs/{tenant}/agent`, COG-118). Mirrors the HTTP contract exactly:\n *\n * - `confirmPlanId` set → the server runs `execute_plan` (the only mutating\n * path) and returns `{kind:\"result\", steps}`.\n * - otherwise → the server runs `planner.handle(message)` and returns one of\n * `{kind:\"answer\"}` / `{kind:\"clarify\"}` / `{kind:\"plan\"}`.\n *\n * The agent classifies intent server-side and drives the underlying engines\n * through its capability registry — the client never talks to `/ask`,\n * `/enrich/*` etc. for an agent turn. ENTITLEMENT for any paid step a plan\n * contains is enforced server-side at execute time (the same authorization the\n * direct paid routes apply), so confirming a plan here cannot bypass a gate the\n * direct path enforces — the gate lives behind the endpoint, not in this client.\n */\n async agent(opts: AgentTurnOptions): Promise<AgentResult> {\n const body: Record<string, unknown> = {\n message: opts.message ?? \"\",\n context: {\n kg_name: opts.kgName ?? \"\",\n type_name: opts.typeName ?? null,\n },\n };\n if (opts.sessionId) body.session_id = opts.sessionId;\n // confirm.plan_id present → the server routes to execute_plan (mutating).\n if (opts.confirmPlanId) body.confirm = { plan_id: opts.confirmPlanId };\n return this.request<AgentResult>(\n \"POST\",\n `${this.base()}/agent`,\n body,\n // Generous: a confirmed plan can kick off enrichment/dedup work, and a\n // question turn runs an LLM round-trip server-side.\n 120_000,\n );\n }\n\n /** List the tenants the authenticated user can access (GET /v1/me/tenants).\n * Keyed by the API key (X-API-Key → user), so it's independent of the active\n * tenant. Throws CographError with status 501 on deployments without a tenant\n * provider (e.g. OSS-only). */\n async listTenants(): Promise<Array<{ id: string; label: string }>> {\n return this.request<Array<{ id: string; label: string }>>(\n \"GET\",\n `${this.baseUrl}/v1/me/tenants`,\n undefined,\n 15_000,\n );\n }\n\n /** List all knowledge graphs for the current tenant. */\n async listKgs(): Promise<Array<Record<string, unknown>>> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/kgs`,\n undefined,\n 15_000,\n );\n if (Array.isArray(data)) return data as Array<Record<string, unknown>>;\n if (data && typeof data === \"object\" && \"kgs\" in data) {\n const kgs = (data as { kgs?: unknown }).kgs;\n if (Array.isArray(kgs)) return kgs as Array<Record<string, unknown>>;\n }\n return [];\n }\n\n /** Create a knowledge graph. */\n async createKg(\n name: string,\n description?: string,\n ): Promise<Record<string, unknown>> {\n const body: Record<string, unknown> = { name };\n if (description) body.description = description;\n return this.request(\"POST\", `${this.base()}/kgs`, body, 15_000);\n }\n\n /** Delete a knowledge graph by name. */\n async deleteKg(name: string): Promise<Record<string, unknown>> {\n return this.request(\n \"DELETE\",\n `${this.base()}/kgs/${encodeURIComponent(name)}`,\n undefined,\n 30_000,\n );\n }\n\n /** List ontology types. */\n async ontologyTypes(): Promise<Array<Record<string, unknown>>> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/ontology/types`,\n undefined,\n 15_000,\n );\n return Array.isArray(data) ? (data as Array<Record<string, unknown>>) : [];\n }\n\n /**\n * Resolve a natural-language ontology change against the existing ontology.\n * The caller does not need to know exact type/attribute/relationship names —\n * the server matches the plain-language `ask` to the current schema and\n * returns auto-applied changes plus proposals that need confirmation.\n */\n async ontologyResolve(\n ask: string,\n opts: { knowledge_graph?: string } = {},\n ): Promise<OntologyResolveResult> {\n const body: Record<string, unknown> = { ask };\n if (opts.knowledge_graph) body.knowledge_graph = opts.knowledge_graph;\n return this.request<OntologyResolveResult>(\n \"POST\",\n `${this.base()}/ontology/resolve`,\n body,\n 60_000,\n );\n }\n\n /**\n * Apply a single resolved ontology change — one of the `proposals` returned\n * by {@link ontologyResolve}. Pass the proposal object through unchanged.\n */\n async ontologyApply(\n proposal: ResolvedChange,\n ): Promise<OntologyApplyResult> {\n return this.request<OntologyApplyResult>(\n \"POST\",\n `${this.base()}/ontology/apply`,\n proposal,\n 60_000,\n );\n }\n\n /**\n * Second-pass entity resolution: re-run ER over an already-ingested KG to\n * collapse intra-batch fragments. Synchronous on the server; returns a\n * per-type before/after report. Generous timeout — it rewrites triples.\n */\n async erRebuild(kg: string): Promise<Record<string, unknown>> {\n return this.request<Record<string, unknown>>(\n \"POST\",\n `${this.base()}/explore/kgs/${encodeURIComponent(kg)}/er-rebuild`,\n {},\n 300_000,\n );\n }\n\n /** Per-KG type counts: every type with ≥1 instance, sorted desc. */\n async typeCounts(kg: string): Promise<TypeCount[]> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/kgs/${encodeURIComponent(kg)}/type-counts`,\n undefined,\n 30_000,\n );\n return Array.isArray(data) ? (data as TypeCount[]) : [];\n }\n\n /** Plan + run an enrichment job. Returns immediately with the job id. */\n async enrichRun(req: EnrichRequest): Promise<EnrichJobCreate> {\n return this.request<EnrichJobCreate>(\n \"POST\",\n `${this.base()}/enrich/jobs`,\n req,\n 30_000,\n );\n }\n\n /** List recent enrichment jobs for the current tenant. */\n async enrichJobs(): Promise<JobSummary[]> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/enrich/jobs`,\n undefined,\n 15_000,\n );\n return Array.isArray(data) ? (data as JobSummary[]) : [];\n }\n\n /** Fetch a single enrichment job (with truncated results). */\n async enrichJob(jobId: string): Promise<EnrichJob> {\n return this.request<EnrichJob>(\n \"GET\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}`,\n undefined,\n 15_000,\n );\n }\n\n /** Fetch the conflict review queue for a job. */\n async enrichConflicts(jobId: string): Promise<ConflictReview[]> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}/conflicts`,\n undefined,\n 30_000,\n );\n return Array.isArray(data) ? (data as ConflictReview[]) : [];\n }\n\n /** Apply a set of conflict review decisions to a job. */\n async enrichApply(\n jobId: string,\n decisions: ConflictReview[],\n ): Promise<{ applied: number }> {\n return this.request<{ applied: number }>(\n \"POST\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}/apply`,\n { decisions },\n 60_000,\n );\n }\n\n /** Cancel an enrichment job. */\n async enrichCancel(jobId: string): Promise<void> {\n await this.request<void>(\n \"DELETE\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}`,\n undefined,\n 15_000,\n );\n }\n\n /** Per-type breakdown for one type in one KG: definition + counts + samples.\n *\n * System predicates (rdfs:label, ingested_at, source) are hidden by default\n * — they're attached to every entity at 100% and drown out the columns the\n * user cares about. Pass `includeSystem: true` to see them. */\n async typeUsage(\n kg: string,\n typeName: string,\n opts: { includeSystem?: boolean } = {},\n ): Promise<TypeUsage> {\n const qs = opts.includeSystem ? \"?include_system=true\" : \"\";\n return this.request<TypeUsage>(\n \"GET\",\n `${this.base()}/kgs/${encodeURIComponent(kg)}/types/${encodeURIComponent(typeName)}/usage${qs}`,\n undefined,\n 30_000,\n );\n }\n\n /** Explorer summary for a type — like typeUsage but adds coverage_pct + avg_degree. */\n async typeSummary(kg: string, typeName: string): Promise<TypeSummary> {\n return this.request<TypeSummary>(\n \"GET\",\n `${this.base()}/explore/kgs/${encodeURIComponent(kg)}/types/${encodeURIComponent(typeName)}/summary`,\n undefined,\n 30_000,\n );\n }\n\n /** Search types or attributes by name substring within a KG. */\n async exploreSearch(\n kg: string,\n q: string,\n kind: \"type\" | \"attr\" = \"type\",\n ): Promise<Array<Record<string, unknown>>> {\n const qs = new URLSearchParams({ kg, q, kind }).toString();\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/explore/search?${qs}`,\n undefined,\n 15_000,\n );\n return Array.isArray(data) ? (data as Array<Record<string, unknown>>) : [];\n }\n}\n\n/**\n * A single ontology change resolved against the existing schema. The same\n * shape is returned under `applied`/`proposals` by {@link Client.ontologyResolve}\n * and accepted as the request body by {@link Client.ontologyApply}.\n */\nexport interface ResolvedChange {\n kind: \"attribute\" | \"relationship\";\n subject_type: string;\n name: string;\n datatype_or_target: string;\n action: \"reuse\" | \"extend\" | \"create\";\n confidence: number;\n reason: string;\n}\n\nexport interface OntologyResolveResult {\n applied: ResolvedChange[];\n proposals: ResolvedChange[];\n summary: string;\n}\n\nexport interface OntologyApplyResult {\n applied: ResolvedChange;\n operations: number;\n summary: string;\n}\n\nexport interface TypeCount {\n name: string;\n entity_count: number;\n}\n\nexport interface AttributeUsage {\n name: string;\n datatype: string;\n count: number;\n}\n\nexport interface RelationshipUsage {\n name: string;\n target_type: string | null;\n count: number;\n}\n\nexport interface EntitySample {\n uri: string;\n label: string;\n}\n\nexport interface TypeUsage {\n name: string;\n description: string;\n parent_type: string | null;\n entity_count: number;\n attributes: AttributeUsage[];\n relationships: RelationshipUsage[];\n samples: EntitySample[];\n}\n\nexport interface AttributeSummary {\n name: string;\n predicate_uri: string;\n datatype: string;\n count: number;\n coverage_pct: number;\n}\n\nexport interface RelationshipSummary {\n name: string;\n predicate_uri: string;\n target_type: string | null;\n count: number;\n coverage_pct: number;\n avg_degree: number;\n}\n\nexport interface TypeSummary {\n name: string;\n description: string;\n parent_type: string | null;\n entity_count: number;\n attributes: AttributeSummary[];\n relationships: RelationshipSummary[];\n}\n\nexport type EnrichmentTier = \"lite\" | \"base\" | \"core\" | \"pro\";\nexport type JobStatus =\n | \"queued\"\n | \"running\"\n | \"review\"\n | \"applied\"\n | \"cancelled\"\n | \"failed\";\nexport type ConflictPolicy = \"skip\" | \"verify\" | \"overwrite\" | \"stage\";\nexport type RowAction =\n | \"filled\"\n | \"verified\"\n | \"conflict\"\n | \"skipped\"\n | \"no_match\";\nexport type ReviewDecision = \"accept\" | \"reject\" | \"skip\";\n\nexport interface EnrichRequest {\n type_name: string;\n attributes: string[];\n tier?: EnrichmentTier;\n kg_name: string;\n conflict_policy?: ConflictPolicy;\n confidence_min?: number;\n limit?: number;\n}\n\nexport interface EnrichJobCreate {\n job_id: string;\n status: JobStatus;\n estimated_cost_usd: number;\n total_entities: number;\n}\n\nexport interface Verdict {\n value: string;\n confidence: number;\n source: string;\n source_url?: string | null;\n reasoning?: string | null;\n}\n\nexport interface JobProgress {\n total: number;\n processed: number;\n filled: number;\n verified: number;\n conflicts: number;\n skipped: number;\n cache_hits: number;\n}\n\nexport interface RowResult {\n entity_uri: string;\n attribute: string;\n existing_value: string | null;\n verdict: Verdict | null;\n action: RowAction;\n}\n\nexport interface JobSummary {\n id: string;\n tenant_id: string;\n kg_name: string;\n type_name: string;\n attributes: string[];\n tier: EnrichmentTier;\n status: JobStatus;\n progress: JobProgress;\n created_at: string;\n started_at?: string | null;\n completed_at?: string | null;\n conflict_policy: ConflictPolicy;\n confidence_min: number;\n error?: string | null;\n}\n\nexport interface EnrichJob extends JobSummary {\n results?: RowResult[];\n limit?: number | null;\n}\n\nexport interface ConflictReview {\n entity_uri: string;\n attribute: string;\n existing_value: string;\n proposed: Verdict;\n decision?: ReviewDecision | null;\n}\n\n// --- Unified Ask-AI agent (COG-118 / COG-125) -------------------------------- #\n\n/** Inputs to {@link Client.agent} — mirror the `/agent` HTTP body. */\nexport interface AgentTurnOptions {\n /** The user's natural-language message. Optional when `confirmPlanId` is set\n * (a confirm turn carries no new message). */\n message?: string;\n /** Knowledge graph the turn operates within. */\n kgName?: string;\n /** Optional active type scope (needed for enrich/clean/dedup planning). */\n typeName?: string;\n /** Optional conversation/session id for multi-turn continuity. */\n sessionId?: string;\n /** When set, the server CONFIRMS + EXECUTES this previously-proposed plan\n * (the only mutating path) instead of classifying a new message. */\n confirmPlanId?: string;\n}\n\n/**\n * The kind-tagged result of one agent turn. The server returns exactly one of:\n * - `answer` — a read-only answer (questions; an ontology INSPECT) with SPARQL.\n * - `clarify` — the agent needs more detail; ask the user `question`.\n * - `plan` — a proposed (un-executed) plan with `plan_id` + `steps`; confirm\n * by calling `agent({ confirmPlanId: plan_id })`.\n * - `result` — the outcome of executing a confirmed plan, per-step.\n * - `error` — e.g. an unknown/expired plan_id on confirm.\n * Extra fields vary by kind (answer/sparql/rows; question; plan_id/steps;\n * steps), so this is intentionally open beyond the discriminant.\n */\nexport interface AgentResult {\n kind: \"answer\" | \"clarify\" | \"plan\" | \"result\" | \"error\";\n [key: string]: unknown;\n}\n"],"mappings":";;;;;;AAAA,SAAS,YAAY,cAAc,gBAAgB;AACnD,SAAS,eA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D,EAAE,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,aAAa,OAA8B;AAC/C,UAAM,KAAK;AAAA,MACT;AAAA,MACA,GAAG,KAAK,KAAK,CAAC,gBAAgB,mBAAmB,KAAK,CAAC;AAAA,MACvD;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,UACJ,IACA,UACA,OAAoC,CAAC,GACjB;AACpB,UAAM,KAAK,KAAK,gBAAgB,yBAAyB;AACzD,WAAO,KAAK;AAAA,MACV;AAAA,MACA,GAAG,KAAK,KAAK,CAAC,QAAQ,mBAAmB,EAAE,CAAC,UAAU,mBAAmB,QAAQ,CAAC,SAAS,EAAE;AAAA,MAC7F;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,YAAY,IAAY,UAAwC;AACpE,WAAO,KAAK;AAAA,MACV;AAAA,MACA,GAAG,KAAK,KAAK,CAAC,gBAAgB,mBAAmB,EAAE,CAAC,UAAU,mBAAmB,QAAQ,CAAC;AAAA,MAC1F;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,cACJ,IACA,GACA,OAAwB,QACiB;AACzC,UAAM,KAAK,IAAI,gBAAgB,EAAE,IAAI,GAAG,KAAK,CAAC,EAAE,SAAS;AACzD,UAAM,OAAO,MAAM,KAAK;AAAA,MACtB;AAAA,MACA,GAAG,KAAK,KAAK,CAAC,mBAAmB,EAAE;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AACA,WAAO,MAAM,QAAQ,IAAI,IAAK,OAA0C,CAAC;AAAA,EAC3E;AACF;","names":["text"]}
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  Client,
4
4
  CographError
5
- } from "./chunk-YFM3KDCO.js";
5
+ } from "./chunk-O3L4FCRY.js";
6
6
  import {
7
7
  configPathForDisplay,
8
8
  readConfig,
@@ -191,7 +191,7 @@ program.name("cograph").description("Cograph Knowledge Graph CLI").version(pkgVe
191
191
  "--tenant <id>",
192
192
  "Target a specific tenant for this command (overrides the saved default)"
193
193
  ).action(async (opts) => {
194
- const { runShell } = await import("./shell-2NGJGEKC.js");
194
+ const { runShell } = await import("./shell-ILZ322LT.js");
195
195
  await runShell({
196
196
  local: opts.local,
197
197
  // commander's --no-login inverts: opts.login === false when flag passed.
@@ -642,7 +642,7 @@ program.command("login").description("Sign in via your browser and save an API k
642
642
  program.command("shell").description("Start an interactive REPL").option("--kg <name>", "Knowledge graph to use").option("--local", "Use http://localhost:8000 and skip login (self-hosted)").option("--no-login", "Skip browser login (assume open-access backend)").action(
643
643
  async (opts) => {
644
644
  const parentOpts = program.opts();
645
- const { runShell } = await import("./shell-2NGJGEKC.js");
645
+ const { runShell } = await import("./shell-ILZ322LT.js");
646
646
  await runShell({
647
647
  kg: opts.kg,
648
648
  local: opts.local || parentOpts.local,
package/dist/index.d.ts CHANGED
@@ -73,6 +73,23 @@ declare class Client {
73
73
  private ingestCsv;
74
74
  /** Ask a natural language question and return the parsed response. */
75
75
  ask(question: string, opts?: AskOptions): Promise<Record<string, unknown>>;
76
+ /**
77
+ * One turn of the unified Ask-AI agent — the SINGLE conversational surface
78
+ * (`POST /graphs/{tenant}/agent`, COG-118). Mirrors the HTTP contract exactly:
79
+ *
80
+ * - `confirmPlanId` set → the server runs `execute_plan` (the only mutating
81
+ * path) and returns `{kind:"result", steps}`.
82
+ * - otherwise → the server runs `planner.handle(message)` and returns one of
83
+ * `{kind:"answer"}` / `{kind:"clarify"}` / `{kind:"plan"}`.
84
+ *
85
+ * The agent classifies intent server-side and drives the underlying engines
86
+ * through its capability registry — the client never talks to `/ask`,
87
+ * `/enrich/*` etc. for an agent turn. ENTITLEMENT for any paid step a plan
88
+ * contains is enforced server-side at execute time (the same authorization the
89
+ * direct paid routes apply), so confirming a plan here cannot bypass a gate the
90
+ * direct path enforces — the gate lives behind the endpoint, not in this client.
91
+ */
92
+ agent(opts: AgentTurnOptions): Promise<AgentResult>;
76
93
  /** List the tenants the authenticated user can access (GET /v1/me/tenants).
77
94
  * Keyed by the API key (X-API-Key → user), so it's independent of the active
78
95
  * tenant. Throws CographError with status 501 on deployments without a tenant
@@ -282,5 +299,35 @@ interface ConflictReview {
282
299
  proposed: Verdict;
283
300
  decision?: ReviewDecision | null;
284
301
  }
302
+ /** Inputs to {@link Client.agent} — mirror the `/agent` HTTP body. */
303
+ interface AgentTurnOptions {
304
+ /** The user's natural-language message. Optional when `confirmPlanId` is set
305
+ * (a confirm turn carries no new message). */
306
+ message?: string;
307
+ /** Knowledge graph the turn operates within. */
308
+ kgName?: string;
309
+ /** Optional active type scope (needed for enrich/clean/dedup planning). */
310
+ typeName?: string;
311
+ /** Optional conversation/session id for multi-turn continuity. */
312
+ sessionId?: string;
313
+ /** When set, the server CONFIRMS + EXECUTES this previously-proposed plan
314
+ * (the only mutating path) instead of classifying a new message. */
315
+ confirmPlanId?: string;
316
+ }
317
+ /**
318
+ * The kind-tagged result of one agent turn. The server returns exactly one of:
319
+ * - `answer` — a read-only answer (questions; an ontology INSPECT) with SPARQL.
320
+ * - `clarify` — the agent needs more detail; ask the user `question`.
321
+ * - `plan` — a proposed (un-executed) plan with `plan_id` + `steps`; confirm
322
+ * by calling `agent({ confirmPlanId: plan_id })`.
323
+ * - `result` — the outcome of executing a confirmed plan, per-step.
324
+ * - `error` — e.g. an unknown/expired plan_id on confirm.
325
+ * Extra fields vary by kind (answer/sparql/rows; question; plan_id/steps;
326
+ * steps), so this is intentionally open beyond the discriminant.
327
+ */
328
+ interface AgentResult {
329
+ kind: "answer" | "clarify" | "plan" | "result" | "error";
330
+ [key: string]: unknown;
331
+ }
285
332
 
286
- export { type AskOptions, Client, type ClientOptions, CographError, type ConflictPolicy, type ConflictReview, type EnrichJob, type EnrichJobCreate, type EnrichRequest, type EnrichmentTier, type IngestOptions, type JobProgress, type JobStatus, type JobSummary, type OntologyApplyResult, type OntologyResolveResult, type ResolvedChange, type ReviewDecision, type RowAction, type RowResult, type Verdict };
333
+ export { type AgentResult, type AgentTurnOptions, type AskOptions, Client, type ClientOptions, CographError, type ConflictPolicy, type ConflictReview, type EnrichJob, type EnrichJobCreate, type EnrichRequest, type EnrichmentTier, type IngestOptions, type JobProgress, type JobStatus, type JobSummary, type OntologyApplyResult, type OntologyResolveResult, type ResolvedChange, type ReviewDecision, type RowAction, type RowResult, type Verdict };
package/dist/index.js CHANGED
@@ -342,6 +342,41 @@ var Client = class {
342
342
  if (opts.model) body.model = opts.model;
343
343
  return this.request("POST", `${this.base()}/ask`, body, 6e4);
344
344
  }
345
+ /**
346
+ * One turn of the unified Ask-AI agent — the SINGLE conversational surface
347
+ * (`POST /graphs/{tenant}/agent`, COG-118). Mirrors the HTTP contract exactly:
348
+ *
349
+ * - `confirmPlanId` set → the server runs `execute_plan` (the only mutating
350
+ * path) and returns `{kind:"result", steps}`.
351
+ * - otherwise → the server runs `planner.handle(message)` and returns one of
352
+ * `{kind:"answer"}` / `{kind:"clarify"}` / `{kind:"plan"}`.
353
+ *
354
+ * The agent classifies intent server-side and drives the underlying engines
355
+ * through its capability registry — the client never talks to `/ask`,
356
+ * `/enrich/*` etc. for an agent turn. ENTITLEMENT for any paid step a plan
357
+ * contains is enforced server-side at execute time (the same authorization the
358
+ * direct paid routes apply), so confirming a plan here cannot bypass a gate the
359
+ * direct path enforces — the gate lives behind the endpoint, not in this client.
360
+ */
361
+ async agent(opts) {
362
+ const body = {
363
+ message: opts.message ?? "",
364
+ context: {
365
+ kg_name: opts.kgName ?? "",
366
+ type_name: opts.typeName ?? null
367
+ }
368
+ };
369
+ if (opts.sessionId) body.session_id = opts.sessionId;
370
+ if (opts.confirmPlanId) body.confirm = { plan_id: opts.confirmPlanId };
371
+ return this.request(
372
+ "POST",
373
+ `${this.base()}/agent`,
374
+ body,
375
+ // Generous: a confirmed plan can kick off enrichment/dedup work, and a
376
+ // question turn runs an LLM round-trip server-side.
377
+ 12e4
378
+ );
379
+ }
345
380
  /** List the tenants the authenticated user can access (GET /v1/me/tenants).
346
381
  * Keyed by the API key (X-API-Key → user), so it's independent of the active
347
382
  * tenant. Throws CographError with status 501 on deployments without a tenant
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts","../src/config.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from \"node:fs\";\nimport { extname } from \"node:path\";\nimport { readConfig } from \"./config.js\";\n\nexport class CographError extends Error {\n status?: number;\n body?: string;\n\n constructor(message: string, opts?: { status?: number; body?: string }) {\n super(message);\n this.name = \"CographError\";\n this.status = opts?.status;\n this.body = opts?.body;\n }\n}\n\nexport interface ClientOptions {\n apiKey?: string;\n baseUrl?: string;\n tenant?: string;\n}\n\nexport interface IngestOptions {\n kg?: string;\n contentType?: \"text\" | \"csv\" | \"json\" | string;\n /** Rows per batch for CSV ingest. Default 200. Larger = fewer round-trips\n * but higher per-request memory; 200 is a good balance for typical KGs. */\n batchSize?: number;\n /** Max number of batches in flight at once. Default 4. Higher saturates\n * the backend faster but risks 429s on large ingests. */\n concurrency?: number;\n /** Called after each batch completes during CSV ingest, in batch order.\n * Use for progress UI. Not invoked for text/json ingest. */\n onProgress?: (progress: IngestProgress) => void;\n /** CSV only. Called once after schema inference and BEFORE any rows are\n * written, with the inferred mapping. Return the (possibly edited/approved)\n * mapping to ingest, or `null` to cancel without writing anything. When\n * omitted the inferred mapping is applied as-is (non-interactive). This is\n * the same confirm/override gate the Explorer surfaces in its review step. */\n onSchemaInferred?: (\n mapping: Record<string, unknown>,\n info: { totalRows: number; rowsProfiled: number },\n ) => Promise<Record<string, unknown> | null>;\n}\n\nexport interface IngestProgress {\n rowsProcessed: number;\n totalRows: number;\n entitiesResolved: number;\n triplesInserted: number;\n}\n\n/** Rows sent to schema inference. Profile fidelity = decision quality, so we\n * send the whole file up to this cap, evenly strided across it (never the\n * head — head-of-file bias is exactly what evidence-grounded inference fixes).\n * Matches the Explorer's SCHEMA_SAMPLE_CAP. */\nexport const SCHEMA_SAMPLE_CAP = 5000;\n\nfunction stridedSample<T>(rows: T[], cap: number = SCHEMA_SAMPLE_CAP): T[] {\n if (rows.length <= cap) return rows;\n const out: T[] = [];\n for (let i = 0; i < cap; i++) out.push(rows[Math.floor((i * rows.length) / cap)]!);\n return out;\n}\n\nexport interface AskOptions {\n kg?: string;\n model?: string;\n}\n\nfunction envVar(name: string, fallback?: string): string | undefined {\n // Prefer COGRAPH_, fall back to OMNIX_ so old configs keep working.\n return (\n process.env[`COGRAPH_${name}`] ||\n process.env[`OMNIX_${name}`] ||\n fallback\n );\n}\n\nconst EXT_FORMAT: Record<string, string> = {\n \".csv\": \"csv\",\n \".json\": \"json\",\n \".jsonl\": \"json\",\n \".txt\": \"text\",\n};\n\n/**\n * Parse a CSV string into an array of row objects.\n *\n * Minimal RFC-4180-ish parser: handles quoted fields with commas, escaped\n * quotes (`\"\"`), CRLF/LF line endings. Does not handle BOM stripping or\n * encoding detection — we assume UTF-8 text in.\n */\nexport function parseCsv(content: string): Record<string, string>[] {\n const rows: string[][] = [];\n let cur: string[] = [];\n let field = \"\";\n let inQuotes = false;\n\n for (let i = 0; i < content.length; i++) {\n const ch = content[i];\n if (inQuotes) {\n if (ch === '\"') {\n if (content[i + 1] === '\"') {\n field += '\"';\n i++;\n } else {\n inQuotes = false;\n }\n } else {\n field += ch;\n }\n } else {\n if (ch === '\"') {\n inQuotes = true;\n } else if (ch === \",\") {\n cur.push(field);\n field = \"\";\n } else if (ch === \"\\n\") {\n cur.push(field);\n rows.push(cur);\n cur = [];\n field = \"\";\n } else if (ch === \"\\r\") {\n // swallow; handled by the following \\n in CRLF, or treat lone \\r as line end\n if (content[i + 1] !== \"\\n\") {\n cur.push(field);\n rows.push(cur);\n cur = [];\n field = \"\";\n }\n } else {\n field += ch;\n }\n }\n }\n // flush trailing field/row\n if (field.length > 0 || cur.length > 0) {\n cur.push(field);\n rows.push(cur);\n }\n\n if (rows.length === 0) return [];\n const headers = rows[0]!.map((h) => h.trim());\n const out: Record<string, string>[] = [];\n for (let r = 1; r < rows.length; r++) {\n const row = rows[r]!;\n // skip blank trailing lines\n if (row.length === 1 && row[0] === \"\") continue;\n const obj: Record<string, string> = {};\n for (let c = 0; c < headers.length; c++) {\n obj[headers[c]!] = row[c] ?? \"\";\n }\n out.push(obj);\n }\n return out;\n}\n\nexport class Client {\n apiKey: string | undefined;\n baseUrl: string;\n tenant: string;\n\n constructor(opts: ClientOptions = {}) {\n // Resolution order for each field: explicit opts → env var → ~/.cograph/config.json\n // (written by `cograph login`) → built-in default. Reading the config eagerly\n // is cheap (small JSON file) and lets users skip env vars entirely after login.\n const cfg = readConfig();\n this.apiKey = opts.apiKey ?? envVar(\"API_KEY\") ?? cfg.apiKey;\n const url =\n opts.baseUrl ?? envVar(\"API_URL\") ?? cfg.apiUrl ?? \"https://api.cograph.cloud\";\n this.baseUrl = url.replace(/\\/+$/, \"\");\n this.tenant = opts.tenant ?? envVar(\"TENANT\") ?? cfg.tenant ?? \"demo-tenant\";\n }\n\n private headers(): Record<string, string> {\n const h: Record<string, string> = { \"Content-Type\": \"application/json\" };\n if (this.apiKey) h[\"X-API-Key\"] = this.apiKey;\n return h;\n }\n\n private base(): string {\n return `${this.baseUrl}/graphs/${this.tenant}`;\n }\n\n /**\n * Probe the backend to determine reachability and whether endpoints\n * require an X-API-Key header. Used at shell startup to distinguish\n * cloud (auth required) from self-hosted open-access deployments.\n */\n async healthCheck(): Promise<{\n ok: boolean;\n requiresAuth: boolean;\n url: string;\n }> {\n const healthUrl = `${this.baseUrl}/health`;\n try {\n const res = await fetch(healthUrl, {\n signal: AbortSignal.timeout(5000),\n });\n if (!res.ok) return { ok: false, requiresAuth: false, url: this.baseUrl };\n } catch {\n return { ok: false, requiresAuth: false, url: this.baseUrl };\n }\n // Probe whether endpoints require auth by hitting /kgs without X-API-Key.\n // 401 = requires auth; 200/empty = open access; anything else = treat as\n // auth-required to be safe.\n try {\n const res = await fetch(`${this.base()}/kgs`, {\n headers: { \"Content-Type\": \"application/json\" },\n signal: AbortSignal.timeout(5000),\n });\n return {\n ok: true,\n requiresAuth: res.status === 401,\n url: this.baseUrl,\n };\n } catch {\n return { ok: true, requiresAuth: true, url: this.baseUrl };\n }\n }\n\n private async request<T = unknown>(\n method: string,\n url: string,\n body?: unknown,\n timeoutMs: number = 120_000,\n ): Promise<T> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n let res: Response;\n try {\n res = await fetch(url, {\n method,\n headers: this.headers(),\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: controller.signal,\n });\n } catch (err) {\n clearTimeout(timer);\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new CographError(`Request to ${url} timed out after ${timeoutMs}ms`);\n }\n throw new CographError(\n `Network error contacting ${url}: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n clearTimeout(timer);\n\n if (!res.ok) {\n let text = \"\";\n try {\n text = await res.text();\n } catch {\n // ignore\n }\n throw new CographError(`HTTP ${res.status}: ${text}`, {\n status: res.status,\n body: text,\n });\n }\n\n // 204 No Content\n if (res.status === 204) return undefined as T;\n\n const ct = res.headers.get(\"content-type\") ?? \"\";\n if (ct.includes(\"application/json\")) {\n return (await res.json()) as T;\n }\n // fall back to text\n const text = await res.text();\n try {\n return JSON.parse(text) as T;\n } catch {\n return text as unknown as T;\n }\n }\n\n /**\n * Ingest a file path or raw text into a knowledge graph.\n *\n * If `pathOrText` points to an existing file, its contents are read and the\n * format is inferred from the extension (.csv, .json, .txt) unless\n * `contentType` is given. CSV files use the two-step schema-inference + row\n * mapping flow.\n */\n async ingest(\n pathOrText: string,\n opts: IngestOptions = {},\n ): Promise<Record<string, unknown>> {\n let content: string;\n let fmt: string;\n\n let isFile = false;\n try {\n isFile = existsSync(pathOrText) && statSync(pathOrText).isFile();\n } catch {\n isFile = false;\n }\n\n if (isFile) {\n const ext = extname(pathOrText).toLowerCase();\n if (ext === \".pdf\") {\n throw new CographError(\n \"PDF ingest not yet supported in the Node CLI; use the Python CLI or POST raw bytes to the API.\",\n );\n }\n content = readFileSync(pathOrText, \"utf-8\");\n fmt = opts.contentType ?? EXT_FORMAT[ext] ?? \"text\";\n if (fmt === \"csv\") {\n return this.ingestCsv(content, opts);\n }\n } else {\n content = pathOrText;\n fmt = opts.contentType ?? \"text\";\n }\n\n const body: Record<string, unknown> = {\n content,\n content_type: fmt,\n source: \"client\",\n };\n if (opts.kg) body.kg_name = opts.kg;\n return this.request(\"POST\", `${this.base()}/ingest`, body, 120_000);\n }\n\n private async ingestCsv(\n content: string,\n opts: IngestOptions,\n ): Promise<Record<string, unknown>> {\n const kgName = opts.kg;\n const batchSize = opts.batchSize ?? 200;\n const concurrency = opts.concurrency ?? 4;\n\n const rows = parseCsv(content);\n if (rows.length === 0) throw new CographError(\"CSV is empty\");\n const headers = Object.keys(rows[0]!);\n\n // Send the whole file to the profiler, evenly strided across it (never the\n // head — head-of-file bias, e.g. a key column that goes sparse later, is\n // exactly what evidence-grounded inference fixes). Profile fidelity =\n // decision quality. Mirrors the Explorer's upload flow.\n const sampleRows = stridedSample(rows);\n\n const schemaBody = {\n headers,\n sample_rows: sampleRows,\n total_rows: rows.length,\n };\n const mapping = await this.request<Record<string, unknown>>(\n \"POST\",\n `${this.base()}/ingest/csv/schema`,\n schemaBody,\n 300_000,\n );\n\n // Confirm/override gate (same contract as the Explorer's review step): the\n // caller inspects the inferred mapping and returns what to ingest, or null\n // to cancel before any rows are written. /ingest/csv/rows applies exactly\n // what we post back. When no hook is given, apply the inference as-is.\n let mappingToPost: Record<string, unknown> = mapping;\n if (opts.onSchemaInferred) {\n const reviewed = await opts.onSchemaInferred(mapping, {\n totalRows: rows.length,\n rowsProfiled: sampleRows.length,\n });\n if (reviewed == null) {\n return { cancelled: true, message: \"Ingest cancelled before any rows were written.\" };\n }\n mappingToPost = reviewed;\n }\n\n // Slice rows into batches up front so we can fire them off in a\n // bounded worker pool. Sequential 50-row batches over 891 rows took\n // ~60s end-to-end (18 round-trips); 200-row batches × 4 in flight\n // brings that to ~5s on the same backend.\n const batches: Array<Record<string, string>[]> = [];\n for (let i = 0; i < rows.length; i += batchSize) {\n batches.push(rows.slice(i, i + batchSize));\n }\n\n let totalEntities = 0;\n let totalTriples = 0;\n let rowsProcessed = 0;\n let nextBatch = 0;\n\n const postBatch = async (batch: Record<string, string>[]) => {\n const body: Record<string, unknown> = {\n mapping: mappingToPost,\n rows: batch,\n source: \"client\",\n };\n if (kgName) body.kg_name = kgName;\n const result = await this.request<{\n entities_resolved?: number;\n triples_inserted?: number;\n }>(\"POST\", `${this.base()}/ingest/csv/rows`, body, 300_000);\n return {\n entities: result.entities_resolved ?? 0,\n triples: result.triples_inserted ?? 0,\n size: batch.length,\n };\n };\n\n const worker = async (): Promise<void> => {\n while (true) {\n const idx = nextBatch++;\n if (idx >= batches.length) return;\n const r = await postBatch(batches[idx]!);\n totalEntities += r.entities;\n totalTriples += r.triples;\n rowsProcessed += r.size;\n opts.onProgress?.({\n rowsProcessed,\n totalRows: rows.length,\n entitiesResolved: totalEntities,\n triplesInserted: totalTriples,\n });\n }\n };\n\n const workers: Array<Promise<void>> = [];\n for (let i = 0; i < Math.min(concurrency, batches.length); i++) {\n workers.push(worker());\n }\n await Promise.all(workers);\n\n // All batches are in — kick off a background recompute of the Explorer\n // type-stats for this KG so type-detail views load instantly. The endpoint\n // returns immediately (the scan runs server-side in the background); this\n // is best-effort and never fails the ingest.\n if (kgName) {\n try {\n await this.request(\n \"POST\",\n `${this.base()}/explore/kgs/${encodeURIComponent(kgName)}/recompute-stats`,\n {},\n 15_000,\n );\n } catch {\n // non-fatal — stats fall back to a live scan until the next recompute\n }\n }\n\n return {\n entities_resolved: totalEntities,\n triples_inserted: totalTriples,\n mapping,\n };\n }\n\n /** Ask a natural language question and return the parsed response. */\n async ask(\n question: string,\n opts: AskOptions = {},\n ): Promise<Record<string, unknown>> {\n const body: Record<string, unknown> = { question };\n if (opts.kg) body.kg_name = opts.kg;\n if (opts.model) body.model = opts.model;\n return this.request(\"POST\", `${this.base()}/ask`, body, 60_000);\n }\n\n /** List the tenants the authenticated user can access (GET /v1/me/tenants).\n * Keyed by the API key (X-API-Key → user), so it's independent of the active\n * tenant. Throws CographError with status 501 on deployments without a tenant\n * provider (e.g. OSS-only). */\n async listTenants(): Promise<Array<{ id: string; label: string }>> {\n return this.request<Array<{ id: string; label: string }>>(\n \"GET\",\n `${this.baseUrl}/v1/me/tenants`,\n undefined,\n 15_000,\n );\n }\n\n /** List all knowledge graphs for the current tenant. */\n async listKgs(): Promise<Array<Record<string, unknown>>> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/kgs`,\n undefined,\n 15_000,\n );\n if (Array.isArray(data)) return data as Array<Record<string, unknown>>;\n if (data && typeof data === \"object\" && \"kgs\" in data) {\n const kgs = (data as { kgs?: unknown }).kgs;\n if (Array.isArray(kgs)) return kgs as Array<Record<string, unknown>>;\n }\n return [];\n }\n\n /** Create a knowledge graph. */\n async createKg(\n name: string,\n description?: string,\n ): Promise<Record<string, unknown>> {\n const body: Record<string, unknown> = { name };\n if (description) body.description = description;\n return this.request(\"POST\", `${this.base()}/kgs`, body, 15_000);\n }\n\n /** Delete a knowledge graph by name. */\n async deleteKg(name: string): Promise<Record<string, unknown>> {\n return this.request(\n \"DELETE\",\n `${this.base()}/kgs/${encodeURIComponent(name)}`,\n undefined,\n 30_000,\n );\n }\n\n /** List ontology types. */\n async ontologyTypes(): Promise<Array<Record<string, unknown>>> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/ontology/types`,\n undefined,\n 15_000,\n );\n return Array.isArray(data) ? (data as Array<Record<string, unknown>>) : [];\n }\n\n /**\n * Resolve a natural-language ontology change against the existing ontology.\n * The caller does not need to know exact type/attribute/relationship names —\n * the server matches the plain-language `ask` to the current schema and\n * returns auto-applied changes plus proposals that need confirmation.\n */\n async ontologyResolve(\n ask: string,\n opts: { knowledge_graph?: string } = {},\n ): Promise<OntologyResolveResult> {\n const body: Record<string, unknown> = { ask };\n if (opts.knowledge_graph) body.knowledge_graph = opts.knowledge_graph;\n return this.request<OntologyResolveResult>(\n \"POST\",\n `${this.base()}/ontology/resolve`,\n body,\n 60_000,\n );\n }\n\n /**\n * Apply a single resolved ontology change — one of the `proposals` returned\n * by {@link ontologyResolve}. Pass the proposal object through unchanged.\n */\n async ontologyApply(\n proposal: ResolvedChange,\n ): Promise<OntologyApplyResult> {\n return this.request<OntologyApplyResult>(\n \"POST\",\n `${this.base()}/ontology/apply`,\n proposal,\n 60_000,\n );\n }\n\n /**\n * Second-pass entity resolution: re-run ER over an already-ingested KG to\n * collapse intra-batch fragments. Synchronous on the server; returns a\n * per-type before/after report. Generous timeout — it rewrites triples.\n */\n async erRebuild(kg: string): Promise<Record<string, unknown>> {\n return this.request<Record<string, unknown>>(\n \"POST\",\n `${this.base()}/explore/kgs/${encodeURIComponent(kg)}/er-rebuild`,\n {},\n 300_000,\n );\n }\n\n /** Per-KG type counts: every type with ≥1 instance, sorted desc. */\n async typeCounts(kg: string): Promise<TypeCount[]> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/kgs/${encodeURIComponent(kg)}/type-counts`,\n undefined,\n 30_000,\n );\n return Array.isArray(data) ? (data as TypeCount[]) : [];\n }\n\n /** Plan + run an enrichment job. Returns immediately with the job id. */\n async enrichRun(req: EnrichRequest): Promise<EnrichJobCreate> {\n return this.request<EnrichJobCreate>(\n \"POST\",\n `${this.base()}/enrich/jobs`,\n req,\n 30_000,\n );\n }\n\n /** List recent enrichment jobs for the current tenant. */\n async enrichJobs(): Promise<JobSummary[]> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/enrich/jobs`,\n undefined,\n 15_000,\n );\n return Array.isArray(data) ? (data as JobSummary[]) : [];\n }\n\n /** Fetch a single enrichment job (with truncated results). */\n async enrichJob(jobId: string): Promise<EnrichJob> {\n return this.request<EnrichJob>(\n \"GET\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}`,\n undefined,\n 15_000,\n );\n }\n\n /** Fetch the conflict review queue for a job. */\n async enrichConflicts(jobId: string): Promise<ConflictReview[]> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}/conflicts`,\n undefined,\n 30_000,\n );\n return Array.isArray(data) ? (data as ConflictReview[]) : [];\n }\n\n /** Apply a set of conflict review decisions to a job. */\n async enrichApply(\n jobId: string,\n decisions: ConflictReview[],\n ): Promise<{ applied: number }> {\n return this.request<{ applied: number }>(\n \"POST\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}/apply`,\n { decisions },\n 60_000,\n );\n }\n\n /** Cancel an enrichment job. */\n async enrichCancel(jobId: string): Promise<void> {\n await this.request<void>(\n \"DELETE\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}`,\n undefined,\n 15_000,\n );\n }\n\n /** Per-type breakdown for one type in one KG: definition + counts + samples.\n *\n * System predicates (rdfs:label, ingested_at, source) are hidden by default\n * — they're attached to every entity at 100% and drown out the columns the\n * user cares about. Pass `includeSystem: true` to see them. */\n async typeUsage(\n kg: string,\n typeName: string,\n opts: { includeSystem?: boolean } = {},\n ): Promise<TypeUsage> {\n const qs = opts.includeSystem ? \"?include_system=true\" : \"\";\n return this.request<TypeUsage>(\n \"GET\",\n `${this.base()}/kgs/${encodeURIComponent(kg)}/types/${encodeURIComponent(typeName)}/usage${qs}`,\n undefined,\n 30_000,\n );\n }\n\n /** Explorer summary for a type — like typeUsage but adds coverage_pct + avg_degree. */\n async typeSummary(kg: string, typeName: string): Promise<TypeSummary> {\n return this.request<TypeSummary>(\n \"GET\",\n `${this.base()}/explore/kgs/${encodeURIComponent(kg)}/types/${encodeURIComponent(typeName)}/summary`,\n undefined,\n 30_000,\n );\n }\n\n /** Search types or attributes by name substring within a KG. */\n async exploreSearch(\n kg: string,\n q: string,\n kind: \"type\" | \"attr\" = \"type\",\n ): Promise<Array<Record<string, unknown>>> {\n const qs = new URLSearchParams({ kg, q, kind }).toString();\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/explore/search?${qs}`,\n undefined,\n 15_000,\n );\n return Array.isArray(data) ? (data as Array<Record<string, unknown>>) : [];\n }\n}\n\n/**\n * A single ontology change resolved against the existing schema. The same\n * shape is returned under `applied`/`proposals` by {@link Client.ontologyResolve}\n * and accepted as the request body by {@link Client.ontologyApply}.\n */\nexport interface ResolvedChange {\n kind: \"attribute\" | \"relationship\";\n subject_type: string;\n name: string;\n datatype_or_target: string;\n action: \"reuse\" | \"extend\" | \"create\";\n confidence: number;\n reason: string;\n}\n\nexport interface OntologyResolveResult {\n applied: ResolvedChange[];\n proposals: ResolvedChange[];\n summary: string;\n}\n\nexport interface OntologyApplyResult {\n applied: ResolvedChange;\n operations: number;\n summary: string;\n}\n\nexport interface TypeCount {\n name: string;\n entity_count: number;\n}\n\nexport interface AttributeUsage {\n name: string;\n datatype: string;\n count: number;\n}\n\nexport interface RelationshipUsage {\n name: string;\n target_type: string | null;\n count: number;\n}\n\nexport interface EntitySample {\n uri: string;\n label: string;\n}\n\nexport interface TypeUsage {\n name: string;\n description: string;\n parent_type: string | null;\n entity_count: number;\n attributes: AttributeUsage[];\n relationships: RelationshipUsage[];\n samples: EntitySample[];\n}\n\nexport interface AttributeSummary {\n name: string;\n predicate_uri: string;\n datatype: string;\n count: number;\n coverage_pct: number;\n}\n\nexport interface RelationshipSummary {\n name: string;\n predicate_uri: string;\n target_type: string | null;\n count: number;\n coverage_pct: number;\n avg_degree: number;\n}\n\nexport interface TypeSummary {\n name: string;\n description: string;\n parent_type: string | null;\n entity_count: number;\n attributes: AttributeSummary[];\n relationships: RelationshipSummary[];\n}\n\nexport type EnrichmentTier = \"lite\" | \"base\" | \"core\" | \"pro\";\nexport type JobStatus =\n | \"queued\"\n | \"running\"\n | \"review\"\n | \"applied\"\n | \"cancelled\"\n | \"failed\";\nexport type ConflictPolicy = \"skip\" | \"verify\" | \"overwrite\" | \"stage\";\nexport type RowAction =\n | \"filled\"\n | \"verified\"\n | \"conflict\"\n | \"skipped\"\n | \"no_match\";\nexport type ReviewDecision = \"accept\" | \"reject\" | \"skip\";\n\nexport interface EnrichRequest {\n type_name: string;\n attributes: string[];\n tier?: EnrichmentTier;\n kg_name: string;\n conflict_policy?: ConflictPolicy;\n confidence_min?: number;\n limit?: number;\n}\n\nexport interface EnrichJobCreate {\n job_id: string;\n status: JobStatus;\n estimated_cost_usd: number;\n total_entities: number;\n}\n\nexport interface Verdict {\n value: string;\n confidence: number;\n source: string;\n source_url?: string | null;\n reasoning?: string | null;\n}\n\nexport interface JobProgress {\n total: number;\n processed: number;\n filled: number;\n verified: number;\n conflicts: number;\n skipped: number;\n cache_hits: number;\n}\n\nexport interface RowResult {\n entity_uri: string;\n attribute: string;\n existing_value: string | null;\n verdict: Verdict | null;\n action: RowAction;\n}\n\nexport interface JobSummary {\n id: string;\n tenant_id: string;\n kg_name: string;\n type_name: string;\n attributes: string[];\n tier: EnrichmentTier;\n status: JobStatus;\n progress: JobProgress;\n created_at: string;\n started_at?: string | null;\n completed_at?: string | null;\n conflict_policy: ConflictPolicy;\n confidence_min: number;\n error?: string | null;\n}\n\nexport interface EnrichJob extends JobSummary {\n results?: RowResult[];\n limit?: number | null;\n}\n\nexport interface ConflictReview {\n entity_uri: string;\n attribute: string;\n existing_value: string;\n proposed: Verdict;\n decision?: ReviewDecision | null;\n}\n","import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync } from \"node:fs\";\n\nexport interface CographConfig {\n apiKey?: string;\n apiUrl?: string;\n tenant?: string;\n email?: string;\n}\n\nfunction configDir(): string {\n return join(homedir(), \".cograph\");\n}\n\nfunction configPath(): string {\n return join(configDir(), \"config.json\");\n}\n\n/**\n * Read `~/.cograph/config.json`. Returns an empty object if the file is\n * missing or unreadable — callers should treat fields as optional.\n */\nexport function readConfig(): CographConfig {\n const path = configPath();\n if (!existsSync(path)) return {};\n try {\n const raw = readFileSync(path, \"utf-8\");\n const parsed = JSON.parse(raw) as unknown;\n if (parsed && typeof parsed === \"object\") {\n return parsed as CographConfig;\n }\n } catch {\n // Corrupt or unreadable; behave as if absent so a fresh login can rewrite.\n }\n return {};\n}\n\n/**\n * Write `~/.cograph/config.json` with `chmod 600`. Creates the directory if\n * needed. Merges with the existing config so callers can update one field\n * without clobbering the others.\n */\nexport function writeConfig(patch: CographConfig): void {\n const dir = configDir();\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true, mode: 0o700 });\n }\n const merged = { ...readConfig(), ...patch };\n const path = configPath();\n writeFileSync(path, JSON.stringify(merged, null, 2) + \"\\n\", \"utf-8\");\n try {\n chmodSync(path, 0o600);\n } catch {\n // best-effort; some filesystems (e.g., FAT) don't honor chmod\n }\n}\n\nexport function configPathForDisplay(): string {\n return configPath();\n}\n"],"mappings":";AAAA,SAAS,cAAAA,aAAY,gBAAAC,eAAc,gBAAgB;AACnD,SAAS,eAAe;;;ACDxB,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,YAAY,WAAW,cAAc,eAAe,iBAAiB;AAS9E,SAAS,YAAoB;AAC3B,SAAO,KAAK,QAAQ,GAAG,UAAU;AACnC;AAEA,SAAS,aAAqB;AAC5B,SAAO,KAAK,UAAU,GAAG,aAAa;AACxC;AAMO,SAAS,aAA4B;AAC1C,QAAM,OAAO,WAAW;AACxB,MAAI,CAAC,WAAW,IAAI,EAAG,QAAO,CAAC;AAC/B,MAAI;AACF,UAAM,MAAM,aAAa,MAAM,OAAO;AACtC,UAAM,SAAS,KAAK,MAAM,GAAG;AAC7B,QAAI,UAAU,OAAO,WAAW,UAAU;AACxC,aAAO;AAAA,IACT;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO,CAAC;AACV;;;ADhCO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC;AAAA,EACA;AAAA,EAEA,YAAY,SAAiB,MAA2C;AACtE,UAAM,OAA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GAAG,KAAK,KAAK,CAAC,gBAAgB,mBAAmB,EAAE,CAAC,UAAU,mBAAmB,QAAQ,CAAC;AAAA,MAC1F;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,cACJ,IACA,GACA,OAAwB,QACiB;AACzC,UAAM,KAAK,IAAI,gBAAgB,EAAE,IAAI,GAAG,KAAK,CAAC,EAAE,SAAS;AACzD,UAAM,OAAO,MAAM,KAAK;AAAA,MACtB;AAAA,MACA,GAAG,KAAK,KAAK,CAAC,mBAAmB,EAAE;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AACA,WAAO,MAAM,QAAQ,IAAI,IAAK,OAA0C,CAAC;AAAA,EAC3E;AACF;","names":["existsSync","readFileSync","text","existsSync","readFileSync"]}
1
+ {"version":3,"sources":["../src/client.ts","../src/config.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from \"node:fs\";\nimport { extname } from \"node:path\";\nimport { readConfig } from \"./config.js\";\n\nexport class CographError extends Error {\n status?: number;\n body?: string;\n\n constructor(message: string, opts?: { status?: number; body?: string }) {\n super(message);\n this.name = \"CographError\";\n this.status = opts?.status;\n this.body = opts?.body;\n }\n}\n\nexport interface ClientOptions {\n apiKey?: string;\n baseUrl?: string;\n tenant?: string;\n}\n\nexport interface IngestOptions {\n kg?: string;\n contentType?: \"text\" | \"csv\" | \"json\" | string;\n /** Rows per batch for CSV ingest. Default 200. Larger = fewer round-trips\n * but higher per-request memory; 200 is a good balance for typical KGs. */\n batchSize?: number;\n /** Max number of batches in flight at once. Default 4. Higher saturates\n * the backend faster but risks 429s on large ingests. */\n concurrency?: number;\n /** Called after each batch completes during CSV ingest, in batch order.\n * Use for progress UI. Not invoked for text/json ingest. */\n onProgress?: (progress: IngestProgress) => void;\n /** CSV only. Called once after schema inference and BEFORE any rows are\n * written, with the inferred mapping. Return the (possibly edited/approved)\n * mapping to ingest, or `null` to cancel without writing anything. When\n * omitted the inferred mapping is applied as-is (non-interactive). This is\n * the same confirm/override gate the Explorer surfaces in its review step. */\n onSchemaInferred?: (\n mapping: Record<string, unknown>,\n info: { totalRows: number; rowsProfiled: number },\n ) => Promise<Record<string, unknown> | null>;\n}\n\nexport interface IngestProgress {\n rowsProcessed: number;\n totalRows: number;\n entitiesResolved: number;\n triplesInserted: number;\n}\n\n/** Rows sent to schema inference. Profile fidelity = decision quality, so we\n * send the whole file up to this cap, evenly strided across it (never the\n * head — head-of-file bias is exactly what evidence-grounded inference fixes).\n * Matches the Explorer's SCHEMA_SAMPLE_CAP. */\nexport const SCHEMA_SAMPLE_CAP = 5000;\n\nfunction stridedSample<T>(rows: T[], cap: number = SCHEMA_SAMPLE_CAP): T[] {\n if (rows.length <= cap) return rows;\n const out: T[] = [];\n for (let i = 0; i < cap; i++) out.push(rows[Math.floor((i * rows.length) / cap)]!);\n return out;\n}\n\nexport interface AskOptions {\n kg?: string;\n model?: string;\n}\n\nfunction envVar(name: string, fallback?: string): string | undefined {\n // Prefer COGRAPH_, fall back to OMNIX_ so old configs keep working.\n return (\n process.env[`COGRAPH_${name}`] ||\n process.env[`OMNIX_${name}`] ||\n fallback\n );\n}\n\nconst EXT_FORMAT: Record<string, string> = {\n \".csv\": \"csv\",\n \".json\": \"json\",\n \".jsonl\": \"json\",\n \".txt\": \"text\",\n};\n\n/**\n * Parse a CSV string into an array of row objects.\n *\n * Minimal RFC-4180-ish parser: handles quoted fields with commas, escaped\n * quotes (`\"\"`), CRLF/LF line endings. Does not handle BOM stripping or\n * encoding detection — we assume UTF-8 text in.\n */\nexport function parseCsv(content: string): Record<string, string>[] {\n const rows: string[][] = [];\n let cur: string[] = [];\n let field = \"\";\n let inQuotes = false;\n\n for (let i = 0; i < content.length; i++) {\n const ch = content[i];\n if (inQuotes) {\n if (ch === '\"') {\n if (content[i + 1] === '\"') {\n field += '\"';\n i++;\n } else {\n inQuotes = false;\n }\n } else {\n field += ch;\n }\n } else {\n if (ch === '\"') {\n inQuotes = true;\n } else if (ch === \",\") {\n cur.push(field);\n field = \"\";\n } else if (ch === \"\\n\") {\n cur.push(field);\n rows.push(cur);\n cur = [];\n field = \"\";\n } else if (ch === \"\\r\") {\n // swallow; handled by the following \\n in CRLF, or treat lone \\r as line end\n if (content[i + 1] !== \"\\n\") {\n cur.push(field);\n rows.push(cur);\n cur = [];\n field = \"\";\n }\n } else {\n field += ch;\n }\n }\n }\n // flush trailing field/row\n if (field.length > 0 || cur.length > 0) {\n cur.push(field);\n rows.push(cur);\n }\n\n if (rows.length === 0) return [];\n const headers = rows[0]!.map((h) => h.trim());\n const out: Record<string, string>[] = [];\n for (let r = 1; r < rows.length; r++) {\n const row = rows[r]!;\n // skip blank trailing lines\n if (row.length === 1 && row[0] === \"\") continue;\n const obj: Record<string, string> = {};\n for (let c = 0; c < headers.length; c++) {\n obj[headers[c]!] = row[c] ?? \"\";\n }\n out.push(obj);\n }\n return out;\n}\n\nexport class Client {\n apiKey: string | undefined;\n baseUrl: string;\n tenant: string;\n\n constructor(opts: ClientOptions = {}) {\n // Resolution order for each field: explicit opts → env var → ~/.cograph/config.json\n // (written by `cograph login`) → built-in default. Reading the config eagerly\n // is cheap (small JSON file) and lets users skip env vars entirely after login.\n const cfg = readConfig();\n this.apiKey = opts.apiKey ?? envVar(\"API_KEY\") ?? cfg.apiKey;\n const url =\n opts.baseUrl ?? envVar(\"API_URL\") ?? cfg.apiUrl ?? \"https://api.cograph.cloud\";\n this.baseUrl = url.replace(/\\/+$/, \"\");\n this.tenant = opts.tenant ?? envVar(\"TENANT\") ?? cfg.tenant ?? \"demo-tenant\";\n }\n\n private headers(): Record<string, string> {\n const h: Record<string, string> = { \"Content-Type\": \"application/json\" };\n if (this.apiKey) h[\"X-API-Key\"] = this.apiKey;\n return h;\n }\n\n private base(): string {\n return `${this.baseUrl}/graphs/${this.tenant}`;\n }\n\n /**\n * Probe the backend to determine reachability and whether endpoints\n * require an X-API-Key header. Used at shell startup to distinguish\n * cloud (auth required) from self-hosted open-access deployments.\n */\n async healthCheck(): Promise<{\n ok: boolean;\n requiresAuth: boolean;\n url: string;\n }> {\n const healthUrl = `${this.baseUrl}/health`;\n try {\n const res = await fetch(healthUrl, {\n signal: AbortSignal.timeout(5000),\n });\n if (!res.ok) return { ok: false, requiresAuth: false, url: this.baseUrl };\n } catch {\n return { ok: false, requiresAuth: false, url: this.baseUrl };\n }\n // Probe whether endpoints require auth by hitting /kgs without X-API-Key.\n // 401 = requires auth; 200/empty = open access; anything else = treat as\n // auth-required to be safe.\n try {\n const res = await fetch(`${this.base()}/kgs`, {\n headers: { \"Content-Type\": \"application/json\" },\n signal: AbortSignal.timeout(5000),\n });\n return {\n ok: true,\n requiresAuth: res.status === 401,\n url: this.baseUrl,\n };\n } catch {\n return { ok: true, requiresAuth: true, url: this.baseUrl };\n }\n }\n\n private async request<T = unknown>(\n method: string,\n url: string,\n body?: unknown,\n timeoutMs: number = 120_000,\n ): Promise<T> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n let res: Response;\n try {\n res = await fetch(url, {\n method,\n headers: this.headers(),\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: controller.signal,\n });\n } catch (err) {\n clearTimeout(timer);\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new CographError(`Request to ${url} timed out after ${timeoutMs}ms`);\n }\n throw new CographError(\n `Network error contacting ${url}: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n clearTimeout(timer);\n\n if (!res.ok) {\n let text = \"\";\n try {\n text = await res.text();\n } catch {\n // ignore\n }\n throw new CographError(`HTTP ${res.status}: ${text}`, {\n status: res.status,\n body: text,\n });\n }\n\n // 204 No Content\n if (res.status === 204) return undefined as T;\n\n const ct = res.headers.get(\"content-type\") ?? \"\";\n if (ct.includes(\"application/json\")) {\n return (await res.json()) as T;\n }\n // fall back to text\n const text = await res.text();\n try {\n return JSON.parse(text) as T;\n } catch {\n return text as unknown as T;\n }\n }\n\n /**\n * Ingest a file path or raw text into a knowledge graph.\n *\n * If `pathOrText` points to an existing file, its contents are read and the\n * format is inferred from the extension (.csv, .json, .txt) unless\n * `contentType` is given. CSV files use the two-step schema-inference + row\n * mapping flow.\n */\n async ingest(\n pathOrText: string,\n opts: IngestOptions = {},\n ): Promise<Record<string, unknown>> {\n let content: string;\n let fmt: string;\n\n let isFile = false;\n try {\n isFile = existsSync(pathOrText) && statSync(pathOrText).isFile();\n } catch {\n isFile = false;\n }\n\n if (isFile) {\n const ext = extname(pathOrText).toLowerCase();\n if (ext === \".pdf\") {\n throw new CographError(\n \"PDF ingest not yet supported in the Node CLI; use the Python CLI or POST raw bytes to the API.\",\n );\n }\n content = readFileSync(pathOrText, \"utf-8\");\n fmt = opts.contentType ?? EXT_FORMAT[ext] ?? \"text\";\n if (fmt === \"csv\") {\n return this.ingestCsv(content, opts);\n }\n } else {\n content = pathOrText;\n fmt = opts.contentType ?? \"text\";\n }\n\n const body: Record<string, unknown> = {\n content,\n content_type: fmt,\n source: \"client\",\n };\n if (opts.kg) body.kg_name = opts.kg;\n return this.request(\"POST\", `${this.base()}/ingest`, body, 120_000);\n }\n\n private async ingestCsv(\n content: string,\n opts: IngestOptions,\n ): Promise<Record<string, unknown>> {\n const kgName = opts.kg;\n const batchSize = opts.batchSize ?? 200;\n const concurrency = opts.concurrency ?? 4;\n\n const rows = parseCsv(content);\n if (rows.length === 0) throw new CographError(\"CSV is empty\");\n const headers = Object.keys(rows[0]!);\n\n // Send the whole file to the profiler, evenly strided across it (never the\n // head — head-of-file bias, e.g. a key column that goes sparse later, is\n // exactly what evidence-grounded inference fixes). Profile fidelity =\n // decision quality. Mirrors the Explorer's upload flow.\n const sampleRows = stridedSample(rows);\n\n const schemaBody = {\n headers,\n sample_rows: sampleRows,\n total_rows: rows.length,\n };\n const mapping = await this.request<Record<string, unknown>>(\n \"POST\",\n `${this.base()}/ingest/csv/schema`,\n schemaBody,\n 300_000,\n );\n\n // Confirm/override gate (same contract as the Explorer's review step): the\n // caller inspects the inferred mapping and returns what to ingest, or null\n // to cancel before any rows are written. /ingest/csv/rows applies exactly\n // what we post back. When no hook is given, apply the inference as-is.\n let mappingToPost: Record<string, unknown> = mapping;\n if (opts.onSchemaInferred) {\n const reviewed = await opts.onSchemaInferred(mapping, {\n totalRows: rows.length,\n rowsProfiled: sampleRows.length,\n });\n if (reviewed == null) {\n return { cancelled: true, message: \"Ingest cancelled before any rows were written.\" };\n }\n mappingToPost = reviewed;\n }\n\n // Slice rows into batches up front so we can fire them off in a\n // bounded worker pool. Sequential 50-row batches over 891 rows took\n // ~60s end-to-end (18 round-trips); 200-row batches × 4 in flight\n // brings that to ~5s on the same backend.\n const batches: Array<Record<string, string>[]> = [];\n for (let i = 0; i < rows.length; i += batchSize) {\n batches.push(rows.slice(i, i + batchSize));\n }\n\n let totalEntities = 0;\n let totalTriples = 0;\n let rowsProcessed = 0;\n let nextBatch = 0;\n\n const postBatch = async (batch: Record<string, string>[]) => {\n const body: Record<string, unknown> = {\n mapping: mappingToPost,\n rows: batch,\n source: \"client\",\n };\n if (kgName) body.kg_name = kgName;\n const result = await this.request<{\n entities_resolved?: number;\n triples_inserted?: number;\n }>(\"POST\", `${this.base()}/ingest/csv/rows`, body, 300_000);\n return {\n entities: result.entities_resolved ?? 0,\n triples: result.triples_inserted ?? 0,\n size: batch.length,\n };\n };\n\n const worker = async (): Promise<void> => {\n while (true) {\n const idx = nextBatch++;\n if (idx >= batches.length) return;\n const r = await postBatch(batches[idx]!);\n totalEntities += r.entities;\n totalTriples += r.triples;\n rowsProcessed += r.size;\n opts.onProgress?.({\n rowsProcessed,\n totalRows: rows.length,\n entitiesResolved: totalEntities,\n triplesInserted: totalTriples,\n });\n }\n };\n\n const workers: Array<Promise<void>> = [];\n for (let i = 0; i < Math.min(concurrency, batches.length); i++) {\n workers.push(worker());\n }\n await Promise.all(workers);\n\n // All batches are in — kick off a background recompute of the Explorer\n // type-stats for this KG so type-detail views load instantly. The endpoint\n // returns immediately (the scan runs server-side in the background); this\n // is best-effort and never fails the ingest.\n if (kgName) {\n try {\n await this.request(\n \"POST\",\n `${this.base()}/explore/kgs/${encodeURIComponent(kgName)}/recompute-stats`,\n {},\n 15_000,\n );\n } catch {\n // non-fatal — stats fall back to a live scan until the next recompute\n }\n }\n\n return {\n entities_resolved: totalEntities,\n triples_inserted: totalTriples,\n mapping,\n };\n }\n\n /** Ask a natural language question and return the parsed response. */\n async ask(\n question: string,\n opts: AskOptions = {},\n ): Promise<Record<string, unknown>> {\n const body: Record<string, unknown> = { question };\n if (opts.kg) body.kg_name = opts.kg;\n if (opts.model) body.model = opts.model;\n return this.request(\"POST\", `${this.base()}/ask`, body, 60_000);\n }\n\n /**\n * One turn of the unified Ask-AI agent — the SINGLE conversational surface\n * (`POST /graphs/{tenant}/agent`, COG-118). Mirrors the HTTP contract exactly:\n *\n * - `confirmPlanId` set → the server runs `execute_plan` (the only mutating\n * path) and returns `{kind:\"result\", steps}`.\n * - otherwise → the server runs `planner.handle(message)` and returns one of\n * `{kind:\"answer\"}` / `{kind:\"clarify\"}` / `{kind:\"plan\"}`.\n *\n * The agent classifies intent server-side and drives the underlying engines\n * through its capability registry — the client never talks to `/ask`,\n * `/enrich/*` etc. for an agent turn. ENTITLEMENT for any paid step a plan\n * contains is enforced server-side at execute time (the same authorization the\n * direct paid routes apply), so confirming a plan here cannot bypass a gate the\n * direct path enforces — the gate lives behind the endpoint, not in this client.\n */\n async agent(opts: AgentTurnOptions): Promise<AgentResult> {\n const body: Record<string, unknown> = {\n message: opts.message ?? \"\",\n context: {\n kg_name: opts.kgName ?? \"\",\n type_name: opts.typeName ?? null,\n },\n };\n if (opts.sessionId) body.session_id = opts.sessionId;\n // confirm.plan_id present → the server routes to execute_plan (mutating).\n if (opts.confirmPlanId) body.confirm = { plan_id: opts.confirmPlanId };\n return this.request<AgentResult>(\n \"POST\",\n `${this.base()}/agent`,\n body,\n // Generous: a confirmed plan can kick off enrichment/dedup work, and a\n // question turn runs an LLM round-trip server-side.\n 120_000,\n );\n }\n\n /** List the tenants the authenticated user can access (GET /v1/me/tenants).\n * Keyed by the API key (X-API-Key → user), so it's independent of the active\n * tenant. Throws CographError with status 501 on deployments without a tenant\n * provider (e.g. OSS-only). */\n async listTenants(): Promise<Array<{ id: string; label: string }>> {\n return this.request<Array<{ id: string; label: string }>>(\n \"GET\",\n `${this.baseUrl}/v1/me/tenants`,\n undefined,\n 15_000,\n );\n }\n\n /** List all knowledge graphs for the current tenant. */\n async listKgs(): Promise<Array<Record<string, unknown>>> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/kgs`,\n undefined,\n 15_000,\n );\n if (Array.isArray(data)) return data as Array<Record<string, unknown>>;\n if (data && typeof data === \"object\" && \"kgs\" in data) {\n const kgs = (data as { kgs?: unknown }).kgs;\n if (Array.isArray(kgs)) return kgs as Array<Record<string, unknown>>;\n }\n return [];\n }\n\n /** Create a knowledge graph. */\n async createKg(\n name: string,\n description?: string,\n ): Promise<Record<string, unknown>> {\n const body: Record<string, unknown> = { name };\n if (description) body.description = description;\n return this.request(\"POST\", `${this.base()}/kgs`, body, 15_000);\n }\n\n /** Delete a knowledge graph by name. */\n async deleteKg(name: string): Promise<Record<string, unknown>> {\n return this.request(\n \"DELETE\",\n `${this.base()}/kgs/${encodeURIComponent(name)}`,\n undefined,\n 30_000,\n );\n }\n\n /** List ontology types. */\n async ontologyTypes(): Promise<Array<Record<string, unknown>>> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/ontology/types`,\n undefined,\n 15_000,\n );\n return Array.isArray(data) ? (data as Array<Record<string, unknown>>) : [];\n }\n\n /**\n * Resolve a natural-language ontology change against the existing ontology.\n * The caller does not need to know exact type/attribute/relationship names —\n * the server matches the plain-language `ask` to the current schema and\n * returns auto-applied changes plus proposals that need confirmation.\n */\n async ontologyResolve(\n ask: string,\n opts: { knowledge_graph?: string } = {},\n ): Promise<OntologyResolveResult> {\n const body: Record<string, unknown> = { ask };\n if (opts.knowledge_graph) body.knowledge_graph = opts.knowledge_graph;\n return this.request<OntologyResolveResult>(\n \"POST\",\n `${this.base()}/ontology/resolve`,\n body,\n 60_000,\n );\n }\n\n /**\n * Apply a single resolved ontology change — one of the `proposals` returned\n * by {@link ontologyResolve}. Pass the proposal object through unchanged.\n */\n async ontologyApply(\n proposal: ResolvedChange,\n ): Promise<OntologyApplyResult> {\n return this.request<OntologyApplyResult>(\n \"POST\",\n `${this.base()}/ontology/apply`,\n proposal,\n 60_000,\n );\n }\n\n /**\n * Second-pass entity resolution: re-run ER over an already-ingested KG to\n * collapse intra-batch fragments. Synchronous on the server; returns a\n * per-type before/after report. Generous timeout — it rewrites triples.\n */\n async erRebuild(kg: string): Promise<Record<string, unknown>> {\n return this.request<Record<string, unknown>>(\n \"POST\",\n `${this.base()}/explore/kgs/${encodeURIComponent(kg)}/er-rebuild`,\n {},\n 300_000,\n );\n }\n\n /** Per-KG type counts: every type with ≥1 instance, sorted desc. */\n async typeCounts(kg: string): Promise<TypeCount[]> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/kgs/${encodeURIComponent(kg)}/type-counts`,\n undefined,\n 30_000,\n );\n return Array.isArray(data) ? (data as TypeCount[]) : [];\n }\n\n /** Plan + run an enrichment job. Returns immediately with the job id. */\n async enrichRun(req: EnrichRequest): Promise<EnrichJobCreate> {\n return this.request<EnrichJobCreate>(\n \"POST\",\n `${this.base()}/enrich/jobs`,\n req,\n 30_000,\n );\n }\n\n /** List recent enrichment jobs for the current tenant. */\n async enrichJobs(): Promise<JobSummary[]> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/enrich/jobs`,\n undefined,\n 15_000,\n );\n return Array.isArray(data) ? (data as JobSummary[]) : [];\n }\n\n /** Fetch a single enrichment job (with truncated results). */\n async enrichJob(jobId: string): Promise<EnrichJob> {\n return this.request<EnrichJob>(\n \"GET\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}`,\n undefined,\n 15_000,\n );\n }\n\n /** Fetch the conflict review queue for a job. */\n async enrichConflicts(jobId: string): Promise<ConflictReview[]> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}/conflicts`,\n undefined,\n 30_000,\n );\n return Array.isArray(data) ? (data as ConflictReview[]) : [];\n }\n\n /** Apply a set of conflict review decisions to a job. */\n async enrichApply(\n jobId: string,\n decisions: ConflictReview[],\n ): Promise<{ applied: number }> {\n return this.request<{ applied: number }>(\n \"POST\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}/apply`,\n { decisions },\n 60_000,\n );\n }\n\n /** Cancel an enrichment job. */\n async enrichCancel(jobId: string): Promise<void> {\n await this.request<void>(\n \"DELETE\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}`,\n undefined,\n 15_000,\n );\n }\n\n /** Per-type breakdown for one type in one KG: definition + counts + samples.\n *\n * System predicates (rdfs:label, ingested_at, source) are hidden by default\n * — they're attached to every entity at 100% and drown out the columns the\n * user cares about. Pass `includeSystem: true` to see them. */\n async typeUsage(\n kg: string,\n typeName: string,\n opts: { includeSystem?: boolean } = {},\n ): Promise<TypeUsage> {\n const qs = opts.includeSystem ? \"?include_system=true\" : \"\";\n return this.request<TypeUsage>(\n \"GET\",\n `${this.base()}/kgs/${encodeURIComponent(kg)}/types/${encodeURIComponent(typeName)}/usage${qs}`,\n undefined,\n 30_000,\n );\n }\n\n /** Explorer summary for a type — like typeUsage but adds coverage_pct + avg_degree. */\n async typeSummary(kg: string, typeName: string): Promise<TypeSummary> {\n return this.request<TypeSummary>(\n \"GET\",\n `${this.base()}/explore/kgs/${encodeURIComponent(kg)}/types/${encodeURIComponent(typeName)}/summary`,\n undefined,\n 30_000,\n );\n }\n\n /** Search types or attributes by name substring within a KG. */\n async exploreSearch(\n kg: string,\n q: string,\n kind: \"type\" | \"attr\" = \"type\",\n ): Promise<Array<Record<string, unknown>>> {\n const qs = new URLSearchParams({ kg, q, kind }).toString();\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/explore/search?${qs}`,\n undefined,\n 15_000,\n );\n return Array.isArray(data) ? (data as Array<Record<string, unknown>>) : [];\n }\n}\n\n/**\n * A single ontology change resolved against the existing schema. The same\n * shape is returned under `applied`/`proposals` by {@link Client.ontologyResolve}\n * and accepted as the request body by {@link Client.ontologyApply}.\n */\nexport interface ResolvedChange {\n kind: \"attribute\" | \"relationship\";\n subject_type: string;\n name: string;\n datatype_or_target: string;\n action: \"reuse\" | \"extend\" | \"create\";\n confidence: number;\n reason: string;\n}\n\nexport interface OntologyResolveResult {\n applied: ResolvedChange[];\n proposals: ResolvedChange[];\n summary: string;\n}\n\nexport interface OntologyApplyResult {\n applied: ResolvedChange;\n operations: number;\n summary: string;\n}\n\nexport interface TypeCount {\n name: string;\n entity_count: number;\n}\n\nexport interface AttributeUsage {\n name: string;\n datatype: string;\n count: number;\n}\n\nexport interface RelationshipUsage {\n name: string;\n target_type: string | null;\n count: number;\n}\n\nexport interface EntitySample {\n uri: string;\n label: string;\n}\n\nexport interface TypeUsage {\n name: string;\n description: string;\n parent_type: string | null;\n entity_count: number;\n attributes: AttributeUsage[];\n relationships: RelationshipUsage[];\n samples: EntitySample[];\n}\n\nexport interface AttributeSummary {\n name: string;\n predicate_uri: string;\n datatype: string;\n count: number;\n coverage_pct: number;\n}\n\nexport interface RelationshipSummary {\n name: string;\n predicate_uri: string;\n target_type: string | null;\n count: number;\n coverage_pct: number;\n avg_degree: number;\n}\n\nexport interface TypeSummary {\n name: string;\n description: string;\n parent_type: string | null;\n entity_count: number;\n attributes: AttributeSummary[];\n relationships: RelationshipSummary[];\n}\n\nexport type EnrichmentTier = \"lite\" | \"base\" | \"core\" | \"pro\";\nexport type JobStatus =\n | \"queued\"\n | \"running\"\n | \"review\"\n | \"applied\"\n | \"cancelled\"\n | \"failed\";\nexport type ConflictPolicy = \"skip\" | \"verify\" | \"overwrite\" | \"stage\";\nexport type RowAction =\n | \"filled\"\n | \"verified\"\n | \"conflict\"\n | \"skipped\"\n | \"no_match\";\nexport type ReviewDecision = \"accept\" | \"reject\" | \"skip\";\n\nexport interface EnrichRequest {\n type_name: string;\n attributes: string[];\n tier?: EnrichmentTier;\n kg_name: string;\n conflict_policy?: ConflictPolicy;\n confidence_min?: number;\n limit?: number;\n}\n\nexport interface EnrichJobCreate {\n job_id: string;\n status: JobStatus;\n estimated_cost_usd: number;\n total_entities: number;\n}\n\nexport interface Verdict {\n value: string;\n confidence: number;\n source: string;\n source_url?: string | null;\n reasoning?: string | null;\n}\n\nexport interface JobProgress {\n total: number;\n processed: number;\n filled: number;\n verified: number;\n conflicts: number;\n skipped: number;\n cache_hits: number;\n}\n\nexport interface RowResult {\n entity_uri: string;\n attribute: string;\n existing_value: string | null;\n verdict: Verdict | null;\n action: RowAction;\n}\n\nexport interface JobSummary {\n id: string;\n tenant_id: string;\n kg_name: string;\n type_name: string;\n attributes: string[];\n tier: EnrichmentTier;\n status: JobStatus;\n progress: JobProgress;\n created_at: string;\n started_at?: string | null;\n completed_at?: string | null;\n conflict_policy: ConflictPolicy;\n confidence_min: number;\n error?: string | null;\n}\n\nexport interface EnrichJob extends JobSummary {\n results?: RowResult[];\n limit?: number | null;\n}\n\nexport interface ConflictReview {\n entity_uri: string;\n attribute: string;\n existing_value: string;\n proposed: Verdict;\n decision?: ReviewDecision | null;\n}\n\n// --- Unified Ask-AI agent (COG-118 / COG-125) -------------------------------- #\n\n/** Inputs to {@link Client.agent} — mirror the `/agent` HTTP body. */\nexport interface AgentTurnOptions {\n /** The user's natural-language message. Optional when `confirmPlanId` is set\n * (a confirm turn carries no new message). */\n message?: string;\n /** Knowledge graph the turn operates within. */\n kgName?: string;\n /** Optional active type scope (needed for enrich/clean/dedup planning). */\n typeName?: string;\n /** Optional conversation/session id for multi-turn continuity. */\n sessionId?: string;\n /** When set, the server CONFIRMS + EXECUTES this previously-proposed plan\n * (the only mutating path) instead of classifying a new message. */\n confirmPlanId?: string;\n}\n\n/**\n * The kind-tagged result of one agent turn. The server returns exactly one of:\n * - `answer` — a read-only answer (questions; an ontology INSPECT) with SPARQL.\n * - `clarify` — the agent needs more detail; ask the user `question`.\n * - `plan` — a proposed (un-executed) plan with `plan_id` + `steps`; confirm\n * by calling `agent({ confirmPlanId: plan_id })`.\n * - `result` — the outcome of executing a confirmed plan, per-step.\n * - `error` — e.g. an unknown/expired plan_id on confirm.\n * Extra fields vary by kind (answer/sparql/rows; question; plan_id/steps;\n * steps), so this is intentionally open beyond the discriminant.\n */\nexport interface AgentResult {\n kind: \"answer\" | \"clarify\" | \"plan\" | \"result\" | \"error\";\n [key: string]: unknown;\n}\n","import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync } from \"node:fs\";\n\nexport interface CographConfig {\n apiKey?: string;\n apiUrl?: string;\n tenant?: string;\n email?: string;\n}\n\nfunction configDir(): string {\n return join(homedir(), \".cograph\");\n}\n\nfunction configPath(): string {\n return join(configDir(), \"config.json\");\n}\n\n/**\n * Read `~/.cograph/config.json`. Returns an empty object if the file is\n * missing or unreadable — callers should treat fields as optional.\n */\nexport function readConfig(): CographConfig {\n const path = configPath();\n if (!existsSync(path)) return {};\n try {\n const raw = readFileSync(path, \"utf-8\");\n const parsed = JSON.parse(raw) as unknown;\n if (parsed && typeof parsed === \"object\") {\n return parsed as CographConfig;\n }\n } catch {\n // Corrupt or unreadable; behave as if absent so a fresh login can rewrite.\n }\n return {};\n}\n\n/**\n * Write `~/.cograph/config.json` with `chmod 600`. Creates the directory if\n * needed. Merges with the existing config so callers can update one field\n * without clobbering the others.\n */\nexport function writeConfig(patch: CographConfig): void {\n const dir = configDir();\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true, mode: 0o700 });\n }\n const merged = { ...readConfig(), ...patch };\n const path = configPath();\n writeFileSync(path, JSON.stringify(merged, null, 2) + \"\\n\", \"utf-8\");\n try {\n chmodSync(path, 0o600);\n } catch {\n // best-effort; some filesystems (e.g., FAT) don't honor chmod\n }\n}\n\nexport function configPathForDisplay(): string {\n return config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,EAAE,CAAC,UAAU,mBAAmB,QAAQ,CAAC;AAAA,MAC1F;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,cACJ,IACA,GACA,OAAwB,QACiB;AACzC,UAAM,KAAK,IAAI,gBAAgB,EAAE,IAAI,GAAG,KAAK,CAAC,EAAE,SAAS;AACzD,UAAM,OAAO,MAAM,KAAK;AAAA,MACtB;AAAA,MACA,GAAG,KAAK,KAAK,CAAC,mBAAmB,EAAE;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AACA,WAAO,MAAM,QAAQ,IAAI,IAAK,OAA0C,CAAC;AAAA,EAC3E;AACF;","names":["existsSync","readFileSync","text","existsSync","readFileSync"]}
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  Client,
4
4
  CographError
5
- } from "./chunk-YFM3KDCO.js";
5
+ } from "./chunk-O3L4FCRY.js";
6
6
  import {
7
7
  writeConfig
8
8
  } from "./chunk-7VVBEUZQ.js";
@@ -1159,4 +1159,4 @@ async function runShell(opts) {
1159
1159
  export {
1160
1160
  runShell
1161
1161
  };
1162
- //# sourceMappingURL=shell-2NGJGEKC.js.map
1162
+ //# sourceMappingURL=shell-ILZ322LT.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cograph",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "Cograph SDK and CLI — knowledge graph platform for structured data",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from \"node:fs\";\nimport { extname } from \"node:path\";\nimport { readConfig } from \"./config.js\";\n\nexport class CographError extends Error {\n status?: number;\n body?: string;\n\n constructor(message: string, opts?: { status?: number; body?: string }) {\n super(message);\n this.name = \"CographError\";\n this.status = opts?.status;\n this.body = opts?.body;\n }\n}\n\nexport interface ClientOptions {\n apiKey?: string;\n baseUrl?: string;\n tenant?: string;\n}\n\nexport interface IngestOptions {\n kg?: string;\n contentType?: \"text\" | \"csv\" | \"json\" | string;\n /** Rows per batch for CSV ingest. Default 200. Larger = fewer round-trips\n * but higher per-request memory; 200 is a good balance for typical KGs. */\n batchSize?: number;\n /** Max number of batches in flight at once. Default 4. Higher saturates\n * the backend faster but risks 429s on large ingests. */\n concurrency?: number;\n /** Called after each batch completes during CSV ingest, in batch order.\n * Use for progress UI. Not invoked for text/json ingest. */\n onProgress?: (progress: IngestProgress) => void;\n /** CSV only. Called once after schema inference and BEFORE any rows are\n * written, with the inferred mapping. Return the (possibly edited/approved)\n * mapping to ingest, or `null` to cancel without writing anything. When\n * omitted the inferred mapping is applied as-is (non-interactive). This is\n * the same confirm/override gate the Explorer surfaces in its review step. */\n onSchemaInferred?: (\n mapping: Record<string, unknown>,\n info: { totalRows: number; rowsProfiled: number },\n ) => Promise<Record<string, unknown> | null>;\n}\n\nexport interface IngestProgress {\n rowsProcessed: number;\n totalRows: number;\n entitiesResolved: number;\n triplesInserted: number;\n}\n\n/** Rows sent to schema inference. Profile fidelity = decision quality, so we\n * send the whole file up to this cap, evenly strided across it (never the\n * head — head-of-file bias is exactly what evidence-grounded inference fixes).\n * Matches the Explorer's SCHEMA_SAMPLE_CAP. */\nexport const SCHEMA_SAMPLE_CAP = 5000;\n\nfunction stridedSample<T>(rows: T[], cap: number = SCHEMA_SAMPLE_CAP): T[] {\n if (rows.length <= cap) return rows;\n const out: T[] = [];\n for (let i = 0; i < cap; i++) out.push(rows[Math.floor((i * rows.length) / cap)]!);\n return out;\n}\n\nexport interface AskOptions {\n kg?: string;\n model?: string;\n}\n\nfunction envVar(name: string, fallback?: string): string | undefined {\n // Prefer COGRAPH_, fall back to OMNIX_ so old configs keep working.\n return (\n process.env[`COGRAPH_${name}`] ||\n process.env[`OMNIX_${name}`] ||\n fallback\n );\n}\n\nconst EXT_FORMAT: Record<string, string> = {\n \".csv\": \"csv\",\n \".json\": \"json\",\n \".jsonl\": \"json\",\n \".txt\": \"text\",\n};\n\n/**\n * Parse a CSV string into an array of row objects.\n *\n * Minimal RFC-4180-ish parser: handles quoted fields with commas, escaped\n * quotes (`\"\"`), CRLF/LF line endings. Does not handle BOM stripping or\n * encoding detection — we assume UTF-8 text in.\n */\nexport function parseCsv(content: string): Record<string, string>[] {\n const rows: string[][] = [];\n let cur: string[] = [];\n let field = \"\";\n let inQuotes = false;\n\n for (let i = 0; i < content.length; i++) {\n const ch = content[i];\n if (inQuotes) {\n if (ch === '\"') {\n if (content[i + 1] === '\"') {\n field += '\"';\n i++;\n } else {\n inQuotes = false;\n }\n } else {\n field += ch;\n }\n } else {\n if (ch === '\"') {\n inQuotes = true;\n } else if (ch === \",\") {\n cur.push(field);\n field = \"\";\n } else if (ch === \"\\n\") {\n cur.push(field);\n rows.push(cur);\n cur = [];\n field = \"\";\n } else if (ch === \"\\r\") {\n // swallow; handled by the following \\n in CRLF, or treat lone \\r as line end\n if (content[i + 1] !== \"\\n\") {\n cur.push(field);\n rows.push(cur);\n cur = [];\n field = \"\";\n }\n } else {\n field += ch;\n }\n }\n }\n // flush trailing field/row\n if (field.length > 0 || cur.length > 0) {\n cur.push(field);\n rows.push(cur);\n }\n\n if (rows.length === 0) return [];\n const headers = rows[0]!.map((h) => h.trim());\n const out: Record<string, string>[] = [];\n for (let r = 1; r < rows.length; r++) {\n const row = rows[r]!;\n // skip blank trailing lines\n if (row.length === 1 && row[0] === \"\") continue;\n const obj: Record<string, string> = {};\n for (let c = 0; c < headers.length; c++) {\n obj[headers[c]!] = row[c] ?? \"\";\n }\n out.push(obj);\n }\n return out;\n}\n\nexport class Client {\n apiKey: string | undefined;\n baseUrl: string;\n tenant: string;\n\n constructor(opts: ClientOptions = {}) {\n // Resolution order for each field: explicit opts → env var → ~/.cograph/config.json\n // (written by `cograph login`) → built-in default. Reading the config eagerly\n // is cheap (small JSON file) and lets users skip env vars entirely after login.\n const cfg = readConfig();\n this.apiKey = opts.apiKey ?? envVar(\"API_KEY\") ?? cfg.apiKey;\n const url =\n opts.baseUrl ?? envVar(\"API_URL\") ?? cfg.apiUrl ?? \"https://api.cograph.cloud\";\n this.baseUrl = url.replace(/\\/+$/, \"\");\n this.tenant = opts.tenant ?? envVar(\"TENANT\") ?? cfg.tenant ?? \"demo-tenant\";\n }\n\n private headers(): Record<string, string> {\n const h: Record<string, string> = { \"Content-Type\": \"application/json\" };\n if (this.apiKey) h[\"X-API-Key\"] = this.apiKey;\n return h;\n }\n\n private base(): string {\n return `${this.baseUrl}/graphs/${this.tenant}`;\n }\n\n /**\n * Probe the backend to determine reachability and whether endpoints\n * require an X-API-Key header. Used at shell startup to distinguish\n * cloud (auth required) from self-hosted open-access deployments.\n */\n async healthCheck(): Promise<{\n ok: boolean;\n requiresAuth: boolean;\n url: string;\n }> {\n const healthUrl = `${this.baseUrl}/health`;\n try {\n const res = await fetch(healthUrl, {\n signal: AbortSignal.timeout(5000),\n });\n if (!res.ok) return { ok: false, requiresAuth: false, url: this.baseUrl };\n } catch {\n return { ok: false, requiresAuth: false, url: this.baseUrl };\n }\n // Probe whether endpoints require auth by hitting /kgs without X-API-Key.\n // 401 = requires auth; 200/empty = open access; anything else = treat as\n // auth-required to be safe.\n try {\n const res = await fetch(`${this.base()}/kgs`, {\n headers: { \"Content-Type\": \"application/json\" },\n signal: AbortSignal.timeout(5000),\n });\n return {\n ok: true,\n requiresAuth: res.status === 401,\n url: this.baseUrl,\n };\n } catch {\n return { ok: true, requiresAuth: true, url: this.baseUrl };\n }\n }\n\n private async request<T = unknown>(\n method: string,\n url: string,\n body?: unknown,\n timeoutMs: number = 120_000,\n ): Promise<T> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n let res: Response;\n try {\n res = await fetch(url, {\n method,\n headers: this.headers(),\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: controller.signal,\n });\n } catch (err) {\n clearTimeout(timer);\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new CographError(`Request to ${url} timed out after ${timeoutMs}ms`);\n }\n throw new CographError(\n `Network error contacting ${url}: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n clearTimeout(timer);\n\n if (!res.ok) {\n let text = \"\";\n try {\n text = await res.text();\n } catch {\n // ignore\n }\n throw new CographError(`HTTP ${res.status}: ${text}`, {\n status: res.status,\n body: text,\n });\n }\n\n // 204 No Content\n if (res.status === 204) return undefined as T;\n\n const ct = res.headers.get(\"content-type\") ?? \"\";\n if (ct.includes(\"application/json\")) {\n return (await res.json()) as T;\n }\n // fall back to text\n const text = await res.text();\n try {\n return JSON.parse(text) as T;\n } catch {\n return text as unknown as T;\n }\n }\n\n /**\n * Ingest a file path or raw text into a knowledge graph.\n *\n * If `pathOrText` points to an existing file, its contents are read and the\n * format is inferred from the extension (.csv, .json, .txt) unless\n * `contentType` is given. CSV files use the two-step schema-inference + row\n * mapping flow.\n */\n async ingest(\n pathOrText: string,\n opts: IngestOptions = {},\n ): Promise<Record<string, unknown>> {\n let content: string;\n let fmt: string;\n\n let isFile = false;\n try {\n isFile = existsSync(pathOrText) && statSync(pathOrText).isFile();\n } catch {\n isFile = false;\n }\n\n if (isFile) {\n const ext = extname(pathOrText).toLowerCase();\n if (ext === \".pdf\") {\n throw new CographError(\n \"PDF ingest not yet supported in the Node CLI; use the Python CLI or POST raw bytes to the API.\",\n );\n }\n content = readFileSync(pathOrText, \"utf-8\");\n fmt = opts.contentType ?? EXT_FORMAT[ext] ?? \"text\";\n if (fmt === \"csv\") {\n return this.ingestCsv(content, opts);\n }\n } else {\n content = pathOrText;\n fmt = opts.contentType ?? \"text\";\n }\n\n const body: Record<string, unknown> = {\n content,\n content_type: fmt,\n source: \"client\",\n };\n if (opts.kg) body.kg_name = opts.kg;\n return this.request(\"POST\", `${this.base()}/ingest`, body, 120_000);\n }\n\n private async ingestCsv(\n content: string,\n opts: IngestOptions,\n ): Promise<Record<string, unknown>> {\n const kgName = opts.kg;\n const batchSize = opts.batchSize ?? 200;\n const concurrency = opts.concurrency ?? 4;\n\n const rows = parseCsv(content);\n if (rows.length === 0) throw new CographError(\"CSV is empty\");\n const headers = Object.keys(rows[0]!);\n\n // Send the whole file to the profiler, evenly strided across it (never the\n // head — head-of-file bias, e.g. a key column that goes sparse later, is\n // exactly what evidence-grounded inference fixes). Profile fidelity =\n // decision quality. Mirrors the Explorer's upload flow.\n const sampleRows = stridedSample(rows);\n\n const schemaBody = {\n headers,\n sample_rows: sampleRows,\n total_rows: rows.length,\n };\n const mapping = await this.request<Record<string, unknown>>(\n \"POST\",\n `${this.base()}/ingest/csv/schema`,\n schemaBody,\n 300_000,\n );\n\n // Confirm/override gate (same contract as the Explorer's review step): the\n // caller inspects the inferred mapping and returns what to ingest, or null\n // to cancel before any rows are written. /ingest/csv/rows applies exactly\n // what we post back. When no hook is given, apply the inference as-is.\n let mappingToPost: Record<string, unknown> = mapping;\n if (opts.onSchemaInferred) {\n const reviewed = await opts.onSchemaInferred(mapping, {\n totalRows: rows.length,\n rowsProfiled: sampleRows.length,\n });\n if (reviewed == null) {\n return { cancelled: true, message: \"Ingest cancelled before any rows were written.\" };\n }\n mappingToPost = reviewed;\n }\n\n // Slice rows into batches up front so we can fire them off in a\n // bounded worker pool. Sequential 50-row batches over 891 rows took\n // ~60s end-to-end (18 round-trips); 200-row batches × 4 in flight\n // brings that to ~5s on the same backend.\n const batches: Array<Record<string, string>[]> = [];\n for (let i = 0; i < rows.length; i += batchSize) {\n batches.push(rows.slice(i, i + batchSize));\n }\n\n let totalEntities = 0;\n let totalTriples = 0;\n let rowsProcessed = 0;\n let nextBatch = 0;\n\n const postBatch = async (batch: Record<string, string>[]) => {\n const body: Record<string, unknown> = {\n mapping: mappingToPost,\n rows: batch,\n source: \"client\",\n };\n if (kgName) body.kg_name = kgName;\n const result = await this.request<{\n entities_resolved?: number;\n triples_inserted?: number;\n }>(\"POST\", `${this.base()}/ingest/csv/rows`, body, 300_000);\n return {\n entities: result.entities_resolved ?? 0,\n triples: result.triples_inserted ?? 0,\n size: batch.length,\n };\n };\n\n const worker = async (): Promise<void> => {\n while (true) {\n const idx = nextBatch++;\n if (idx >= batches.length) return;\n const r = await postBatch(batches[idx]!);\n totalEntities += r.entities;\n totalTriples += r.triples;\n rowsProcessed += r.size;\n opts.onProgress?.({\n rowsProcessed,\n totalRows: rows.length,\n entitiesResolved: totalEntities,\n triplesInserted: totalTriples,\n });\n }\n };\n\n const workers: Array<Promise<void>> = [];\n for (let i = 0; i < Math.min(concurrency, batches.length); i++) {\n workers.push(worker());\n }\n await Promise.all(workers);\n\n // All batches are in — kick off a background recompute of the Explorer\n // type-stats for this KG so type-detail views load instantly. The endpoint\n // returns immediately (the scan runs server-side in the background); this\n // is best-effort and never fails the ingest.\n if (kgName) {\n try {\n await this.request(\n \"POST\",\n `${this.base()}/explore/kgs/${encodeURIComponent(kgName)}/recompute-stats`,\n {},\n 15_000,\n );\n } catch {\n // non-fatal — stats fall back to a live scan until the next recompute\n }\n }\n\n return {\n entities_resolved: totalEntities,\n triples_inserted: totalTriples,\n mapping,\n };\n }\n\n /** Ask a natural language question and return the parsed response. */\n async ask(\n question: string,\n opts: AskOptions = {},\n ): Promise<Record<string, unknown>> {\n const body: Record<string, unknown> = { question };\n if (opts.kg) body.kg_name = opts.kg;\n if (opts.model) body.model = opts.model;\n return this.request(\"POST\", `${this.base()}/ask`, body, 60_000);\n }\n\n /** List the tenants the authenticated user can access (GET /v1/me/tenants).\n * Keyed by the API key (X-API-Key → user), so it's independent of the active\n * tenant. Throws CographError with status 501 on deployments without a tenant\n * provider (e.g. OSS-only). */\n async listTenants(): Promise<Array<{ id: string; label: string }>> {\n return this.request<Array<{ id: string; label: string }>>(\n \"GET\",\n `${this.baseUrl}/v1/me/tenants`,\n undefined,\n 15_000,\n );\n }\n\n /** List all knowledge graphs for the current tenant. */\n async listKgs(): Promise<Array<Record<string, unknown>>> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/kgs`,\n undefined,\n 15_000,\n );\n if (Array.isArray(data)) return data as Array<Record<string, unknown>>;\n if (data && typeof data === \"object\" && \"kgs\" in data) {\n const kgs = (data as { kgs?: unknown }).kgs;\n if (Array.isArray(kgs)) return kgs as Array<Record<string, unknown>>;\n }\n return [];\n }\n\n /** Create a knowledge graph. */\n async createKg(\n name: string,\n description?: string,\n ): Promise<Record<string, unknown>> {\n const body: Record<string, unknown> = { name };\n if (description) body.description = description;\n return this.request(\"POST\", `${this.base()}/kgs`, body, 15_000);\n }\n\n /** Delete a knowledge graph by name. */\n async deleteKg(name: string): Promise<Record<string, unknown>> {\n return this.request(\n \"DELETE\",\n `${this.base()}/kgs/${encodeURIComponent(name)}`,\n undefined,\n 30_000,\n );\n }\n\n /** List ontology types. */\n async ontologyTypes(): Promise<Array<Record<string, unknown>>> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/ontology/types`,\n undefined,\n 15_000,\n );\n return Array.isArray(data) ? (data as Array<Record<string, unknown>>) : [];\n }\n\n /**\n * Resolve a natural-language ontology change against the existing ontology.\n * The caller does not need to know exact type/attribute/relationship names —\n * the server matches the plain-language `ask` to the current schema and\n * returns auto-applied changes plus proposals that need confirmation.\n */\n async ontologyResolve(\n ask: string,\n opts: { knowledge_graph?: string } = {},\n ): Promise<OntologyResolveResult> {\n const body: Record<string, unknown> = { ask };\n if (opts.knowledge_graph) body.knowledge_graph = opts.knowledge_graph;\n return this.request<OntologyResolveResult>(\n \"POST\",\n `${this.base()}/ontology/resolve`,\n body,\n 60_000,\n );\n }\n\n /**\n * Apply a single resolved ontology change — one of the `proposals` returned\n * by {@link ontologyResolve}. Pass the proposal object through unchanged.\n */\n async ontologyApply(\n proposal: ResolvedChange,\n ): Promise<OntologyApplyResult> {\n return this.request<OntologyApplyResult>(\n \"POST\",\n `${this.base()}/ontology/apply`,\n proposal,\n 60_000,\n );\n }\n\n /**\n * Second-pass entity resolution: re-run ER over an already-ingested KG to\n * collapse intra-batch fragments. Synchronous on the server; returns a\n * per-type before/after report. Generous timeout — it rewrites triples.\n */\n async erRebuild(kg: string): Promise<Record<string, unknown>> {\n return this.request<Record<string, unknown>>(\n \"POST\",\n `${this.base()}/explore/kgs/${encodeURIComponent(kg)}/er-rebuild`,\n {},\n 300_000,\n );\n }\n\n /** Per-KG type counts: every type with ≥1 instance, sorted desc. */\n async typeCounts(kg: string): Promise<TypeCount[]> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/kgs/${encodeURIComponent(kg)}/type-counts`,\n undefined,\n 30_000,\n );\n return Array.isArray(data) ? (data as TypeCount[]) : [];\n }\n\n /** Plan + run an enrichment job. Returns immediately with the job id. */\n async enrichRun(req: EnrichRequest): Promise<EnrichJobCreate> {\n return this.request<EnrichJobCreate>(\n \"POST\",\n `${this.base()}/enrich/jobs`,\n req,\n 30_000,\n );\n }\n\n /** List recent enrichment jobs for the current tenant. */\n async enrichJobs(): Promise<JobSummary[]> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/enrich/jobs`,\n undefined,\n 15_000,\n );\n return Array.isArray(data) ? (data as JobSummary[]) : [];\n }\n\n /** Fetch a single enrichment job (with truncated results). */\n async enrichJob(jobId: string): Promise<EnrichJob> {\n return this.request<EnrichJob>(\n \"GET\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}`,\n undefined,\n 15_000,\n );\n }\n\n /** Fetch the conflict review queue for a job. */\n async enrichConflicts(jobId: string): Promise<ConflictReview[]> {\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}/conflicts`,\n undefined,\n 30_000,\n );\n return Array.isArray(data) ? (data as ConflictReview[]) : [];\n }\n\n /** Apply a set of conflict review decisions to a job. */\n async enrichApply(\n jobId: string,\n decisions: ConflictReview[],\n ): Promise<{ applied: number }> {\n return this.request<{ applied: number }>(\n \"POST\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}/apply`,\n { decisions },\n 60_000,\n );\n }\n\n /** Cancel an enrichment job. */\n async enrichCancel(jobId: string): Promise<void> {\n await this.request<void>(\n \"DELETE\",\n `${this.base()}/enrich/jobs/${encodeURIComponent(jobId)}`,\n undefined,\n 15_000,\n );\n }\n\n /** Per-type breakdown for one type in one KG: definition + counts + samples.\n *\n * System predicates (rdfs:label, ingested_at, source) are hidden by default\n * — they're attached to every entity at 100% and drown out the columns the\n * user cares about. Pass `includeSystem: true` to see them. */\n async typeUsage(\n kg: string,\n typeName: string,\n opts: { includeSystem?: boolean } = {},\n ): Promise<TypeUsage> {\n const qs = opts.includeSystem ? \"?include_system=true\" : \"\";\n return this.request<TypeUsage>(\n \"GET\",\n `${this.base()}/kgs/${encodeURIComponent(kg)}/types/${encodeURIComponent(typeName)}/usage${qs}`,\n undefined,\n 30_000,\n );\n }\n\n /** Explorer summary for a type — like typeUsage but adds coverage_pct + avg_degree. */\n async typeSummary(kg: string, typeName: string): Promise<TypeSummary> {\n return this.request<TypeSummary>(\n \"GET\",\n `${this.base()}/explore/kgs/${encodeURIComponent(kg)}/types/${encodeURIComponent(typeName)}/summary`,\n undefined,\n 30_000,\n );\n }\n\n /** Search types or attributes by name substring within a KG. */\n async exploreSearch(\n kg: string,\n q: string,\n kind: \"type\" | \"attr\" = \"type\",\n ): Promise<Array<Record<string, unknown>>> {\n const qs = new URLSearchParams({ kg, q, kind }).toString();\n const data = await this.request<unknown>(\n \"GET\",\n `${this.base()}/explore/search?${qs}`,\n undefined,\n 15_000,\n );\n return Array.isArray(data) ? (data as Array<Record<string, unknown>>) : [];\n }\n}\n\n/**\n * A single ontology change resolved against the existing schema. The same\n * shape is returned under `applied`/`proposals` by {@link Client.ontologyResolve}\n * and accepted as the request body by {@link Client.ontologyApply}.\n */\nexport interface ResolvedChange {\n kind: \"attribute\" | \"relationship\";\n subject_type: string;\n name: string;\n datatype_or_target: string;\n action: \"reuse\" | \"extend\" | \"create\";\n confidence: number;\n reason: string;\n}\n\nexport interface OntologyResolveResult {\n applied: ResolvedChange[];\n proposals: ResolvedChange[];\n summary: string;\n}\n\nexport interface OntologyApplyResult {\n applied: ResolvedChange;\n operations: number;\n summary: string;\n}\n\nexport interface TypeCount {\n name: string;\n entity_count: number;\n}\n\nexport interface AttributeUsage {\n name: string;\n datatype: string;\n count: number;\n}\n\nexport interface RelationshipUsage {\n name: string;\n target_type: string | null;\n count: number;\n}\n\nexport interface EntitySample {\n uri: string;\n label: string;\n}\n\nexport interface TypeUsage {\n name: string;\n description: string;\n parent_type: string | null;\n entity_count: number;\n attributes: AttributeUsage[];\n relationships: RelationshipUsage[];\n samples: EntitySample[];\n}\n\nexport interface AttributeSummary {\n name: string;\n predicate_uri: string;\n datatype: string;\n count: number;\n coverage_pct: number;\n}\n\nexport interface RelationshipSummary {\n name: string;\n predicate_uri: string;\n target_type: string | null;\n count: number;\n coverage_pct: number;\n avg_degree: number;\n}\n\nexport interface TypeSummary {\n name: string;\n description: string;\n parent_type: string | null;\n entity_count: number;\n attributes: AttributeSummary[];\n relationships: RelationshipSummary[];\n}\n\nexport type EnrichmentTier = \"lite\" | \"base\" | \"core\" | \"pro\";\nexport type JobStatus =\n | \"queued\"\n | \"running\"\n | \"review\"\n | \"applied\"\n | \"cancelled\"\n | \"failed\";\nexport type ConflictPolicy = \"skip\" | \"verify\" | \"overwrite\" | \"stage\";\nexport type RowAction =\n | \"filled\"\n | \"verified\"\n | \"conflict\"\n | \"skipped\"\n | \"no_match\";\nexport type ReviewDecision = \"accept\" | \"reject\" | \"skip\";\n\nexport interface EnrichRequest {\n type_name: string;\n attributes: string[];\n tier?: EnrichmentTier;\n kg_name: string;\n conflict_policy?: ConflictPolicy;\n confidence_min?: number;\n limit?: number;\n}\n\nexport interface EnrichJobCreate {\n job_id: string;\n status: JobStatus;\n estimated_cost_usd: number;\n total_entities: number;\n}\n\nexport interface Verdict {\n value: string;\n confidence: number;\n source: string;\n source_url?: string | null;\n reasoning?: string | null;\n}\n\nexport interface JobProgress {\n total: number;\n processed: number;\n filled: number;\n verified: number;\n conflicts: number;\n skipped: number;\n cache_hits: number;\n}\n\nexport interface RowResult {\n entity_uri: string;\n attribute: string;\n existing_value: string | null;\n verdict: Verdict | null;\n action: RowAction;\n}\n\nexport interface JobSummary {\n id: string;\n tenant_id: string;\n kg_name: string;\n type_name: string;\n attributes: string[];\n tier: EnrichmentTier;\n status: JobStatus;\n progress: JobProgress;\n created_at: string;\n started_at?: string | null;\n completed_at?: string | null;\n conflict_policy: ConflictPolicy;\n confidence_min: number;\n error?: string | null;\n}\n\nexport interface EnrichJob extends JobSummary {\n results?: RowResult[];\n limit?: number | null;\n}\n\nexport interface ConflictReview {\n entity_uri: string;\n attribute: string;\n existing_value: string;\n proposed: Verdict;\n decision?: ReviewDecision | null;\n}\n"],"mappings":";;;;;;AAAA,SAAS,YAAY,cAAc,gBAAgB;AACnD,SAAS,eAAe;AAGjB,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC;AAAA,EACA;AAAA,EAEA,YAAY,SAAiB,MAA2C;AACtE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS,MAAM;AACpB,SAAK,OAAO,MAAM;AAAA,EACpB;AACF;AA0CO,IAAM,oBAAoB;AAEjC,SAAS,cAAiB,MAAW,MAAc,mBAAwB;AACzE,MAAI,KAAK,UAAU,IAAK,QAAO;AAC/B,QAAM,MAAW,CAAC;AAClB,WAAS,IAAI,GAAG,IAAI,KAAK,IAAK,KAAI,KAAK,KAAK,KAAK,MAAO,IAAI,KAAK,SAAU,GAAG,CAAC,CAAE;AACjF,SAAO;AACT;AAOA,SAAS,OAAO,MAAc,UAAuC;AAEnE,SACE,QAAQ,IAAI,WAAW,IAAI,EAAE,KAC7B,QAAQ,IAAI,SAAS,IAAI,EAAE,KAC3B;AAEJ;AAEA,IAAM,aAAqC;AAAA,EACzC,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AAAA,EACV,QAAQ;AACV;AASO,SAAS,SAAS,SAA2C;AAClE,QAAM,OAAmB,CAAC;AAC1B,MAAI,MAAgB,CAAC;AACrB,MAAI,QAAQ;AACZ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