@kortexya/reasoninglayer 0.11.0 → 0.12.1
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.
- package/dist/index.cjs +309 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +610 -168
- package/dist/index.d.ts +610 -168
- package/dist/index.js +308 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/config.ts
|
|
4
|
-
var SDK_VERSION = "0.
|
|
4
|
+
var SDK_VERSION = "0.12.1";
|
|
5
5
|
function resolveConfig(config) {
|
|
6
6
|
if (!config.baseUrl) {
|
|
7
7
|
throw new Error("ClientConfig.baseUrl is required");
|
|
@@ -13401,46 +13401,269 @@ function ResumeDocumentIngestionResponseFromApiToFront(dto) {
|
|
|
13401
13401
|
success: dto.success
|
|
13402
13402
|
};
|
|
13403
13403
|
}
|
|
13404
|
+
function AsyncIngestionResponseFromApiToFront(dto) {
|
|
13405
|
+
return {
|
|
13406
|
+
sessionId: dto.session_id,
|
|
13407
|
+
documentId: dto.document_id,
|
|
13408
|
+
status: dto.status,
|
|
13409
|
+
statusUrl: dto.status_url
|
|
13410
|
+
};
|
|
13411
|
+
}
|
|
13412
|
+
function StepLogEntryDtoFromApiToFront(dto) {
|
|
13413
|
+
return {
|
|
13414
|
+
message: dto.message,
|
|
13415
|
+
step: dto.step,
|
|
13416
|
+
timestamp: dto.timestamp
|
|
13417
|
+
};
|
|
13418
|
+
}
|
|
13419
|
+
function DocumentProgressDtoFromApiToFront(dto) {
|
|
13420
|
+
return {
|
|
13421
|
+
chunksFailed: dto.chunks_failed,
|
|
13422
|
+
chunksProcessed: dto.chunks_processed,
|
|
13423
|
+
currentChunk: dto.current_chunk,
|
|
13424
|
+
currentChunkPreview: dto.current_chunk_preview,
|
|
13425
|
+
currentStep: dto.current_step,
|
|
13426
|
+
currentStepLabel: dto.current_step_label,
|
|
13427
|
+
discoveredEntityTypes: dto.discovered_entity_types,
|
|
13428
|
+
discoveredRelationTypes: dto.discovered_relation_types,
|
|
13429
|
+
documentId: dto.document_id,
|
|
13430
|
+
domainSummary: dto.domain_summary,
|
|
13431
|
+
elapsedSeconds: dto.elapsed_seconds,
|
|
13432
|
+
entitiesCreated: dto.entities_created,
|
|
13433
|
+
entitiesExtracted: dto.entities_extracted,
|
|
13434
|
+
entitiesFiltered: dto.entities_filtered,
|
|
13435
|
+
entitiesMerged: dto.entities_merged,
|
|
13436
|
+
entitiesPendingReview: dto.entities_pending_review,
|
|
13437
|
+
estimatedCostUsd: dto.estimated_cost_usd,
|
|
13438
|
+
extractionStrategy: dto.extraction_strategy,
|
|
13439
|
+
inferenceRulesApplied: dto.inference_rules_applied,
|
|
13440
|
+
modelName: dto.model_name,
|
|
13441
|
+
osfResiduationsCreated: dto.osf_residuations_created,
|
|
13442
|
+
osfResiduationsResumed: dto.osf_residuations_resumed,
|
|
13443
|
+
referencesResolved: dto.references_resolved,
|
|
13444
|
+
referencesUnresolved: dto.references_unresolved,
|
|
13445
|
+
relationsExtracted: dto.relations_extracted,
|
|
13446
|
+
relationsFromInference: dto.relations_from_inference,
|
|
13447
|
+
relationsIntegrated: dto.relations_integrated,
|
|
13448
|
+
reviewsPersisted: dto.reviews_persisted,
|
|
13449
|
+
sortNames: dto.sort_names,
|
|
13450
|
+
sortsCreated: dto.sorts_created,
|
|
13451
|
+
sortsReused: dto.sorts_reused,
|
|
13452
|
+
sortsReusedGlb: dto.sorts_reused_glb,
|
|
13453
|
+
sortsReusedSemantic: dto.sorts_reused_semantic,
|
|
13454
|
+
startedAt: dto.started_at,
|
|
13455
|
+
stepLog: dto.step_log.map(StepLogEntryDtoFromApiToFront),
|
|
13456
|
+
tokensInput: dto.tokens_input,
|
|
13457
|
+
tokensOutput: dto.tokens_output,
|
|
13458
|
+
totalChunks: dto.total_chunks,
|
|
13459
|
+
updatedAt: dto.updated_at
|
|
13460
|
+
};
|
|
13461
|
+
}
|
|
13462
|
+
function SessionProgressResponseFromApiToFront(dto) {
|
|
13463
|
+
return {
|
|
13464
|
+
documents: dto.documents.map(DocumentProgressDtoFromApiToFront),
|
|
13465
|
+
sessionId: dto.session_id
|
|
13466
|
+
};
|
|
13467
|
+
}
|
|
13468
|
+
function DocumentStatsDtoFromApiToFront(dto) {
|
|
13469
|
+
return {
|
|
13470
|
+
chunksProcessed: dto.chunks_processed,
|
|
13471
|
+
completedAt: dto.completed_at,
|
|
13472
|
+
documentId: dto.document_id,
|
|
13473
|
+
entitiesExtracted: dto.entities_extracted,
|
|
13474
|
+
processingTimeMs: dto.processing_time_ms,
|
|
13475
|
+
relationsExtracted: dto.relations_extracted,
|
|
13476
|
+
sortNames: dto.sort_names,
|
|
13477
|
+
termIds: dto.term_ids,
|
|
13478
|
+
totalTokens: dto.total_tokens
|
|
13479
|
+
};
|
|
13480
|
+
}
|
|
13481
|
+
function SessionStatsResponseFromApiToFront(dto) {
|
|
13482
|
+
return {
|
|
13483
|
+
documents: dto.documents.map(DocumentStatsDtoFromApiToFront),
|
|
13484
|
+
sessionId: dto.session_id,
|
|
13485
|
+
total: dto.total
|
|
13486
|
+
};
|
|
13487
|
+
}
|
|
13404
13488
|
|
|
13405
|
-
// src/resources/ingestion.ts
|
|
13406
|
-
var
|
|
13489
|
+
// src/resources/ingestion-session.ts
|
|
13490
|
+
var IngestionFailedError = class extends ReasoningLayerError {
|
|
13491
|
+
name = "IngestionFailedError";
|
|
13492
|
+
/** The session ID that failed. */
|
|
13493
|
+
sessionId;
|
|
13494
|
+
/** The last known session state. */
|
|
13495
|
+
session;
|
|
13496
|
+
constructor(session) {
|
|
13497
|
+
super(`Ingestion session ${session.sessionId} failed`);
|
|
13498
|
+
this.sessionId = session.sessionId;
|
|
13499
|
+
this.session = session;
|
|
13500
|
+
}
|
|
13501
|
+
};
|
|
13502
|
+
var IngestionSession = class {
|
|
13503
|
+
/** The session ID (UUID). */
|
|
13504
|
+
sessionId;
|
|
13505
|
+
/** The document ID (UUID). */
|
|
13506
|
+
documentId;
|
|
13507
|
+
/** The initial status (always `"pending"` on creation). */
|
|
13508
|
+
status;
|
|
13509
|
+
/** URL path to check session status. */
|
|
13510
|
+
statusUrl;
|
|
13407
13511
|
/** @internal */
|
|
13408
13512
|
api;
|
|
13409
13513
|
/** @internal */
|
|
13410
|
-
constructor(api) {
|
|
13514
|
+
constructor(api, response) {
|
|
13411
13515
|
this.api = api;
|
|
13516
|
+
this.sessionId = response.sessionId;
|
|
13517
|
+
this.documentId = response.documentId;
|
|
13518
|
+
this.status = response.status;
|
|
13519
|
+
this.statusUrl = response.statusUrl;
|
|
13412
13520
|
}
|
|
13413
13521
|
/**
|
|
13414
|
-
*
|
|
13522
|
+
* Get the current session details (status, document counts).
|
|
13523
|
+
*
|
|
13524
|
+
* @returns The session information.
|
|
13415
13525
|
*
|
|
13416
|
-
* @
|
|
13417
|
-
*
|
|
13526
|
+
* @remarks
|
|
13527
|
+
* Maps to `GET /api/v1/ingest/sessions/{session_id}`.
|
|
13418
13528
|
*/
|
|
13419
|
-
async
|
|
13420
|
-
const response = await this.api.
|
|
13421
|
-
return
|
|
13529
|
+
async getSession() {
|
|
13530
|
+
const response = await this.api.getIngestionSession(this.sessionId);
|
|
13531
|
+
return IngestionSessionResponseFromApiToFront(response.data);
|
|
13422
13532
|
}
|
|
13423
13533
|
/**
|
|
13424
|
-
*
|
|
13534
|
+
* Get live pipeline progress for all documents in the session.
|
|
13425
13535
|
*
|
|
13426
|
-
* @
|
|
13427
|
-
*
|
|
13536
|
+
* @returns Progress snapshots for each document being processed.
|
|
13537
|
+
*
|
|
13538
|
+
* @remarks
|
|
13539
|
+
* Maps to `GET /api/v1/ingest/sessions/{session_id}/progress`.
|
|
13540
|
+
* Returns real-time counters, current pipeline step, and step log.
|
|
13428
13541
|
*/
|
|
13429
|
-
async
|
|
13430
|
-
const response = await this.api.
|
|
13431
|
-
return
|
|
13542
|
+
async getProgress() {
|
|
13543
|
+
const response = await this.api.getIngestionProgress(this.sessionId);
|
|
13544
|
+
return SessionProgressResponseFromApiToFront(response.data);
|
|
13432
13545
|
}
|
|
13433
13546
|
/**
|
|
13434
|
-
*
|
|
13547
|
+
* Get stats for all completed documents in the session.
|
|
13435
13548
|
*
|
|
13436
|
-
* @
|
|
13437
|
-
* @returns Ingestion statistics and review items.
|
|
13549
|
+
* @returns Per-document stats (term IDs, sort names, token usage, etc.).
|
|
13438
13550
|
*
|
|
13439
13551
|
* @remarks
|
|
13440
|
-
*
|
|
13441
|
-
*
|
|
13552
|
+
* Maps to `GET /api/v1/ingest/sessions/{session_id}/stats`.
|
|
13553
|
+
* May be empty if no documents have completed yet.
|
|
13442
13554
|
*/
|
|
13443
|
-
async
|
|
13555
|
+
async getStats() {
|
|
13556
|
+
const response = await this.api.getIngestionSessionStats(this.sessionId);
|
|
13557
|
+
return SessionStatsResponseFromApiToFront(response.data);
|
|
13558
|
+
}
|
|
13559
|
+
/**
|
|
13560
|
+
* Poll the session until it completes or fails, then return final stats.
|
|
13561
|
+
*
|
|
13562
|
+
* @param options - Polling configuration (interval, timeout, progress callback, abort signal).
|
|
13563
|
+
* @returns Final session stats once all documents are complete.
|
|
13564
|
+
* @throws {@link IngestionFailedError} If the session status becomes `"failed"`.
|
|
13565
|
+
* @throws {@link TimeoutError} If `timeoutMs` is exceeded.
|
|
13566
|
+
* @throws {@link ReasoningLayerError} If the abort signal is triggered.
|
|
13567
|
+
*
|
|
13568
|
+
* @example
|
|
13569
|
+
* ```ts
|
|
13570
|
+
* const stats = await session.waitForCompletion({
|
|
13571
|
+
* pollIntervalMs: 2000,
|
|
13572
|
+
* timeoutMs: 300_000,
|
|
13573
|
+
* onProgress: (p) => {
|
|
13574
|
+
* const doc = p.documents[0];
|
|
13575
|
+
* if (doc) console.log(`${doc.currentStepLabel} — chunk ${doc.chunksProcessed}/${doc.totalChunks}`);
|
|
13576
|
+
* },
|
|
13577
|
+
* });
|
|
13578
|
+
* console.log(`Created ${stats.documents[0]?.termIds.length} terms`);
|
|
13579
|
+
* ```
|
|
13580
|
+
*
|
|
13581
|
+
* @remarks
|
|
13582
|
+
* Polls `getSession()` to check status, and calls `onProgress` with live
|
|
13583
|
+
* progress data between checks. Terminal states are `"complete"` and `"failed"`.
|
|
13584
|
+
*/
|
|
13585
|
+
async waitForCompletion(options) {
|
|
13586
|
+
const pollIntervalMs = options?.pollIntervalMs ?? 2e3;
|
|
13587
|
+
const timeoutMs = options?.timeoutMs ?? 3e5;
|
|
13588
|
+
const onProgress = options?.onProgress;
|
|
13589
|
+
const signal = options?.signal;
|
|
13590
|
+
const deadline = Date.now() + timeoutMs;
|
|
13591
|
+
for (; ; ) {
|
|
13592
|
+
if (signal?.aborted) {
|
|
13593
|
+
throw new ReasoningLayerError("Ingestion polling was aborted", {
|
|
13594
|
+
cause: signal.reason
|
|
13595
|
+
});
|
|
13596
|
+
}
|
|
13597
|
+
if (Date.now() > deadline) {
|
|
13598
|
+
throw new TimeoutError(timeoutMs);
|
|
13599
|
+
}
|
|
13600
|
+
const session = await this.getSession();
|
|
13601
|
+
if (session.status === "complete") {
|
|
13602
|
+
return this.getStats();
|
|
13603
|
+
}
|
|
13604
|
+
if (session.status === "failed") {
|
|
13605
|
+
throw new IngestionFailedError(session);
|
|
13606
|
+
}
|
|
13607
|
+
if (onProgress) {
|
|
13608
|
+
try {
|
|
13609
|
+
const progress = await this.getProgress();
|
|
13610
|
+
onProgress(progress);
|
|
13611
|
+
} catch {
|
|
13612
|
+
}
|
|
13613
|
+
}
|
|
13614
|
+
await this.sleep(pollIntervalMs, signal);
|
|
13615
|
+
}
|
|
13616
|
+
}
|
|
13617
|
+
/** @internal */
|
|
13618
|
+
sleep(ms, signal) {
|
|
13619
|
+
return new Promise((resolve, reject) => {
|
|
13620
|
+
if (signal?.aborted) {
|
|
13621
|
+
reject(new ReasoningLayerError("Ingestion polling was aborted", {
|
|
13622
|
+
cause: signal.reason
|
|
13623
|
+
}));
|
|
13624
|
+
return;
|
|
13625
|
+
}
|
|
13626
|
+
const timer = setTimeout(resolve, ms);
|
|
13627
|
+
if (signal) {
|
|
13628
|
+
const onAbort = () => {
|
|
13629
|
+
clearTimeout(timer);
|
|
13630
|
+
reject(new ReasoningLayerError("Ingestion polling was aborted", {
|
|
13631
|
+
cause: signal.reason
|
|
13632
|
+
}));
|
|
13633
|
+
};
|
|
13634
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
13635
|
+
const originalResolve = resolve;
|
|
13636
|
+
resolve = () => {
|
|
13637
|
+
signal.removeEventListener("abort", onAbort);
|
|
13638
|
+
originalResolve();
|
|
13639
|
+
};
|
|
13640
|
+
}
|
|
13641
|
+
});
|
|
13642
|
+
}
|
|
13643
|
+
};
|
|
13644
|
+
|
|
13645
|
+
// src/resources/ingestion.ts
|
|
13646
|
+
var IngestionClient = class {
|
|
13647
|
+
/** @internal */
|
|
13648
|
+
api;
|
|
13649
|
+
/** @internal */
|
|
13650
|
+
constructor(api) {
|
|
13651
|
+
this.api = api;
|
|
13652
|
+
}
|
|
13653
|
+
async ingestMarkdown(request, options) {
|
|
13654
|
+
const sync = options?.sync ?? true;
|
|
13655
|
+
if (!sync) {
|
|
13656
|
+
const response2 = await this.api.http.request({
|
|
13657
|
+
path: `/api/v1/ingest/markdown`,
|
|
13658
|
+
method: "POST",
|
|
13659
|
+
query: { sync: false },
|
|
13660
|
+
body: IngestMarkdownRequestFromFrontToApi(request),
|
|
13661
|
+
type: "application/json" /* Json */,
|
|
13662
|
+
format: "json"
|
|
13663
|
+
});
|
|
13664
|
+
const asyncResponse = AsyncIngestionResponseFromApiToFront(response2.data);
|
|
13665
|
+
return new IngestionSession(this.api, asyncResponse);
|
|
13666
|
+
}
|
|
13444
13667
|
const response = await this.api.http.request({
|
|
13445
13668
|
path: `/api/v1/ingest/markdown`,
|
|
13446
13669
|
method: "POST",
|
|
@@ -13470,6 +13693,40 @@ var IngestionClient = class {
|
|
|
13470
13693
|
});
|
|
13471
13694
|
return response.data;
|
|
13472
13695
|
}
|
|
13696
|
+
async ingestDocument(request, options) {
|
|
13697
|
+
const sync = options?.sync ?? true;
|
|
13698
|
+
if (!sync) {
|
|
13699
|
+
const response2 = await this.api.http.request({
|
|
13700
|
+
path: `/api/v1/ingest/document`,
|
|
13701
|
+
method: "POST",
|
|
13702
|
+
query: { sync: false },
|
|
13703
|
+
body: IngestDocumentRequestFromFrontToApi(request),
|
|
13704
|
+
type: "application/json" /* Json */,
|
|
13705
|
+
format: "json"
|
|
13706
|
+
});
|
|
13707
|
+
const asyncResponse = AsyncIngestionResponseFromApiToFront(response2.data);
|
|
13708
|
+
return new IngestionSession(this.api, asyncResponse);
|
|
13709
|
+
}
|
|
13710
|
+
const response = await this.api.ingestDocument(IngestDocumentRequestFromFrontToApi(request));
|
|
13711
|
+
return IngestDocumentResponseFromApiToFront(response.data);
|
|
13712
|
+
}
|
|
13713
|
+
async ingestDocumentBatch(request, options) {
|
|
13714
|
+
const sync = options?.sync ?? true;
|
|
13715
|
+
if (!sync) {
|
|
13716
|
+
const response2 = await this.api.http.request({
|
|
13717
|
+
path: `/api/v1/ingest/document/batch`,
|
|
13718
|
+
method: "POST",
|
|
13719
|
+
query: { sync: false },
|
|
13720
|
+
body: IngestDocumentBatchRequestFromFrontToApi(request),
|
|
13721
|
+
type: "application/json" /* Json */,
|
|
13722
|
+
format: "json"
|
|
13723
|
+
});
|
|
13724
|
+
const asyncResponse = AsyncIngestionResponseFromApiToFront(response2.data);
|
|
13725
|
+
return new IngestionSession(this.api, asyncResponse);
|
|
13726
|
+
}
|
|
13727
|
+
const response = await this.api.ingestDocumentBatch(IngestDocumentBatchRequestFromFrontToApi(request));
|
|
13728
|
+
return IngestDocumentBatchResponseFromApiToFront(response.data);
|
|
13729
|
+
}
|
|
13473
13730
|
/**
|
|
13474
13731
|
* Ingest RDF content (Turtle, N-Triples, RDF/XML, or JSON-LD).
|
|
13475
13732
|
*
|
|
@@ -13517,6 +13774,34 @@ var IngestionClient = class {
|
|
|
13517
13774
|
async deleteSession(sessionId) {
|
|
13518
13775
|
await this.api.deleteIngestionSession(sessionId);
|
|
13519
13776
|
}
|
|
13777
|
+
/**
|
|
13778
|
+
* Get live pipeline progress for all documents in a session.
|
|
13779
|
+
*
|
|
13780
|
+
* @param sessionId - Session UUID.
|
|
13781
|
+
* @returns Progress snapshots for each document being processed.
|
|
13782
|
+
*
|
|
13783
|
+
* @remarks
|
|
13784
|
+
* Maps to `GET /api/v1/ingest/sessions/{session_id}/progress`.
|
|
13785
|
+
* Returns real-time counters, current pipeline step, and step log.
|
|
13786
|
+
*/
|
|
13787
|
+
async getSessionProgress(sessionId) {
|
|
13788
|
+
const response = await this.api.getIngestionProgress(sessionId);
|
|
13789
|
+
return SessionProgressResponseFromApiToFront(response.data);
|
|
13790
|
+
}
|
|
13791
|
+
/**
|
|
13792
|
+
* Get stats for all completed documents in a session.
|
|
13793
|
+
*
|
|
13794
|
+
* @param sessionId - Session UUID.
|
|
13795
|
+
* @returns Per-document stats (term IDs, sort names, token usage, etc.).
|
|
13796
|
+
*
|
|
13797
|
+
* @remarks
|
|
13798
|
+
* Maps to `GET /api/v1/ingest/sessions/{session_id}/stats`.
|
|
13799
|
+
* May be empty if no documents have completed yet.
|
|
13800
|
+
*/
|
|
13801
|
+
async getSessionStats(sessionId) {
|
|
13802
|
+
const response = await this.api.getIngestionSessionStats(sessionId);
|
|
13803
|
+
return SessionStatsResponseFromApiToFront(response.data);
|
|
13804
|
+
}
|
|
13520
13805
|
/**
|
|
13521
13806
|
* List incomplete documents in a session that can be resumed.
|
|
13522
13807
|
*
|
|
@@ -22262,6 +22547,8 @@ exports.ILP = ilp_exports;
|
|
|
22262
22547
|
exports.ImageExtraction = image_extraction_exports;
|
|
22263
22548
|
exports.Inference = inference_exports;
|
|
22264
22549
|
exports.Ingestion = ingestion_exports;
|
|
22550
|
+
exports.IngestionFailedError = IngestionFailedError;
|
|
22551
|
+
exports.IngestionSession = IngestionSession;
|
|
22265
22552
|
exports.InternalServerError = InternalServerError;
|
|
22266
22553
|
exports.LP = LP;
|
|
22267
22554
|
exports.Namespaces = namespaces_exports;
|