@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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/config.ts
2
- var SDK_VERSION = "0.11.0";
2
+ var SDK_VERSION = "0.12.1";
3
3
  function resolveConfig(config) {
4
4
  if (!config.baseUrl) {
5
5
  throw new Error("ClientConfig.baseUrl is required");
@@ -13399,46 +13399,269 @@ function ResumeDocumentIngestionResponseFromApiToFront(dto) {
13399
13399
  success: dto.success
13400
13400
  };
13401
13401
  }
13402
+ function AsyncIngestionResponseFromApiToFront(dto) {
13403
+ return {
13404
+ sessionId: dto.session_id,
13405
+ documentId: dto.document_id,
13406
+ status: dto.status,
13407
+ statusUrl: dto.status_url
13408
+ };
13409
+ }
13410
+ function StepLogEntryDtoFromApiToFront(dto) {
13411
+ return {
13412
+ message: dto.message,
13413
+ step: dto.step,
13414
+ timestamp: dto.timestamp
13415
+ };
13416
+ }
13417
+ function DocumentProgressDtoFromApiToFront(dto) {
13418
+ return {
13419
+ chunksFailed: dto.chunks_failed,
13420
+ chunksProcessed: dto.chunks_processed,
13421
+ currentChunk: dto.current_chunk,
13422
+ currentChunkPreview: dto.current_chunk_preview,
13423
+ currentStep: dto.current_step,
13424
+ currentStepLabel: dto.current_step_label,
13425
+ discoveredEntityTypes: dto.discovered_entity_types,
13426
+ discoveredRelationTypes: dto.discovered_relation_types,
13427
+ documentId: dto.document_id,
13428
+ domainSummary: dto.domain_summary,
13429
+ elapsedSeconds: dto.elapsed_seconds,
13430
+ entitiesCreated: dto.entities_created,
13431
+ entitiesExtracted: dto.entities_extracted,
13432
+ entitiesFiltered: dto.entities_filtered,
13433
+ entitiesMerged: dto.entities_merged,
13434
+ entitiesPendingReview: dto.entities_pending_review,
13435
+ estimatedCostUsd: dto.estimated_cost_usd,
13436
+ extractionStrategy: dto.extraction_strategy,
13437
+ inferenceRulesApplied: dto.inference_rules_applied,
13438
+ modelName: dto.model_name,
13439
+ osfResiduationsCreated: dto.osf_residuations_created,
13440
+ osfResiduationsResumed: dto.osf_residuations_resumed,
13441
+ referencesResolved: dto.references_resolved,
13442
+ referencesUnresolved: dto.references_unresolved,
13443
+ relationsExtracted: dto.relations_extracted,
13444
+ relationsFromInference: dto.relations_from_inference,
13445
+ relationsIntegrated: dto.relations_integrated,
13446
+ reviewsPersisted: dto.reviews_persisted,
13447
+ sortNames: dto.sort_names,
13448
+ sortsCreated: dto.sorts_created,
13449
+ sortsReused: dto.sorts_reused,
13450
+ sortsReusedGlb: dto.sorts_reused_glb,
13451
+ sortsReusedSemantic: dto.sorts_reused_semantic,
13452
+ startedAt: dto.started_at,
13453
+ stepLog: dto.step_log.map(StepLogEntryDtoFromApiToFront),
13454
+ tokensInput: dto.tokens_input,
13455
+ tokensOutput: dto.tokens_output,
13456
+ totalChunks: dto.total_chunks,
13457
+ updatedAt: dto.updated_at
13458
+ };
13459
+ }
13460
+ function SessionProgressResponseFromApiToFront(dto) {
13461
+ return {
13462
+ documents: dto.documents.map(DocumentProgressDtoFromApiToFront),
13463
+ sessionId: dto.session_id
13464
+ };
13465
+ }
13466
+ function DocumentStatsDtoFromApiToFront(dto) {
13467
+ return {
13468
+ chunksProcessed: dto.chunks_processed,
13469
+ completedAt: dto.completed_at,
13470
+ documentId: dto.document_id,
13471
+ entitiesExtracted: dto.entities_extracted,
13472
+ processingTimeMs: dto.processing_time_ms,
13473
+ relationsExtracted: dto.relations_extracted,
13474
+ sortNames: dto.sort_names,
13475
+ termIds: dto.term_ids,
13476
+ totalTokens: dto.total_tokens
13477
+ };
13478
+ }
13479
+ function SessionStatsResponseFromApiToFront(dto) {
13480
+ return {
13481
+ documents: dto.documents.map(DocumentStatsDtoFromApiToFront),
13482
+ sessionId: dto.session_id,
13483
+ total: dto.total
13484
+ };
13485
+ }
13402
13486
 
13403
- // src/resources/ingestion.ts
13404
- var IngestionClient = class {
13487
+ // src/resources/ingestion-session.ts
13488
+ var IngestionFailedError = class extends ReasoningLayerError {
13489
+ name = "IngestionFailedError";
13490
+ /** The session ID that failed. */
13491
+ sessionId;
13492
+ /** The last known session state. */
13493
+ session;
13494
+ constructor(session) {
13495
+ super(`Ingestion session ${session.sessionId} failed`);
13496
+ this.sessionId = session.sessionId;
13497
+ this.session = session;
13498
+ }
13499
+ };
13500
+ var IngestionSession = class {
13501
+ /** The session ID (UUID). */
13502
+ sessionId;
13503
+ /** The document ID (UUID). */
13504
+ documentId;
13505
+ /** The initial status (always `"pending"` on creation). */
13506
+ status;
13507
+ /** URL path to check session status. */
13508
+ statusUrl;
13405
13509
  /** @internal */
13406
13510
  api;
13407
13511
  /** @internal */
13408
- constructor(api) {
13512
+ constructor(api, response) {
13409
13513
  this.api = api;
13514
+ this.sessionId = response.sessionId;
13515
+ this.documentId = response.documentId;
13516
+ this.status = response.status;
13517
+ this.statusUrl = response.statusUrl;
13410
13518
  }
13411
13519
  /**
13412
- * Ingest a single document.
13520
+ * Get the current session details (status, document counts).
13521
+ *
13522
+ * @returns The session information.
13413
13523
  *
13414
- * @param request - Document ingestion request with source, config, and owner.
13415
- * @returns Ingestion result with stats, metadata, and parse info.
13524
+ * @remarks
13525
+ * Maps to `GET /api/v1/ingest/sessions/{session_id}`.
13416
13526
  */
13417
- async ingestDocument(request) {
13418
- const response = await this.api.ingestDocument(IngestDocumentRequestFromFrontToApi(request));
13419
- return IngestDocumentResponseFromApiToFront(response.data);
13527
+ async getSession() {
13528
+ const response = await this.api.getIngestionSession(this.sessionId);
13529
+ return IngestionSessionResponseFromApiToFront(response.data);
13420
13530
  }
13421
13531
  /**
13422
- * Ingest a batch of documents.
13532
+ * Get live pipeline progress for all documents in the session.
13423
13533
  *
13424
- * @param request - Batch ingestion request with documents, config, and owner.
13425
- * @returns Batch results with per-document status.
13534
+ * @returns Progress snapshots for each document being processed.
13535
+ *
13536
+ * @remarks
13537
+ * Maps to `GET /api/v1/ingest/sessions/{session_id}/progress`.
13538
+ * Returns real-time counters, current pipeline step, and step log.
13426
13539
  */
13427
- async ingestDocumentBatch(request) {
13428
- const response = await this.api.ingestDocumentBatch(IngestDocumentBatchRequestFromFrontToApi(request));
13429
- return IngestDocumentBatchResponseFromApiToFront(response.data);
13540
+ async getProgress() {
13541
+ const response = await this.api.getIngestionProgress(this.sessionId);
13542
+ return SessionProgressResponseFromApiToFront(response.data);
13430
13543
  }
13431
13544
  /**
13432
- * Ingest markdown content.
13545
+ * Get stats for all completed documents in the session.
13433
13546
  *
13434
- * @param request - Markdown ingestion request with content and owner.
13435
- * @returns Ingestion statistics and review items.
13547
+ * @returns Per-document stats (term IDs, sort names, token usage, etc.).
13436
13548
  *
13437
13549
  * @remarks
13438
- * Uses synchronous mode (sync=true) by default. The generated endpoint
13439
- * returns void for the response type; we use a fallback to get the typed response.
13550
+ * Maps to `GET /api/v1/ingest/sessions/{session_id}/stats`.
13551
+ * May be empty if no documents have completed yet.
13440
13552
  */
13441
- async ingestMarkdown(request) {
13553
+ async getStats() {
13554
+ const response = await this.api.getIngestionSessionStats(this.sessionId);
13555
+ return SessionStatsResponseFromApiToFront(response.data);
13556
+ }
13557
+ /**
13558
+ * Poll the session until it completes or fails, then return final stats.
13559
+ *
13560
+ * @param options - Polling configuration (interval, timeout, progress callback, abort signal).
13561
+ * @returns Final session stats once all documents are complete.
13562
+ * @throws {@link IngestionFailedError} If the session status becomes `"failed"`.
13563
+ * @throws {@link TimeoutError} If `timeoutMs` is exceeded.
13564
+ * @throws {@link ReasoningLayerError} If the abort signal is triggered.
13565
+ *
13566
+ * @example
13567
+ * ```ts
13568
+ * const stats = await session.waitForCompletion({
13569
+ * pollIntervalMs: 2000,
13570
+ * timeoutMs: 300_000,
13571
+ * onProgress: (p) => {
13572
+ * const doc = p.documents[0];
13573
+ * if (doc) console.log(`${doc.currentStepLabel} — chunk ${doc.chunksProcessed}/${doc.totalChunks}`);
13574
+ * },
13575
+ * });
13576
+ * console.log(`Created ${stats.documents[0]?.termIds.length} terms`);
13577
+ * ```
13578
+ *
13579
+ * @remarks
13580
+ * Polls `getSession()` to check status, and calls `onProgress` with live
13581
+ * progress data between checks. Terminal states are `"complete"` and `"failed"`.
13582
+ */
13583
+ async waitForCompletion(options) {
13584
+ const pollIntervalMs = options?.pollIntervalMs ?? 2e3;
13585
+ const timeoutMs = options?.timeoutMs ?? 3e5;
13586
+ const onProgress = options?.onProgress;
13587
+ const signal = options?.signal;
13588
+ const deadline = Date.now() + timeoutMs;
13589
+ for (; ; ) {
13590
+ if (signal?.aborted) {
13591
+ throw new ReasoningLayerError("Ingestion polling was aborted", {
13592
+ cause: signal.reason
13593
+ });
13594
+ }
13595
+ if (Date.now() > deadline) {
13596
+ throw new TimeoutError(timeoutMs);
13597
+ }
13598
+ const session = await this.getSession();
13599
+ if (session.status === "complete") {
13600
+ return this.getStats();
13601
+ }
13602
+ if (session.status === "failed") {
13603
+ throw new IngestionFailedError(session);
13604
+ }
13605
+ if (onProgress) {
13606
+ try {
13607
+ const progress = await this.getProgress();
13608
+ onProgress(progress);
13609
+ } catch {
13610
+ }
13611
+ }
13612
+ await this.sleep(pollIntervalMs, signal);
13613
+ }
13614
+ }
13615
+ /** @internal */
13616
+ sleep(ms, signal) {
13617
+ return new Promise((resolve, reject) => {
13618
+ if (signal?.aborted) {
13619
+ reject(new ReasoningLayerError("Ingestion polling was aborted", {
13620
+ cause: signal.reason
13621
+ }));
13622
+ return;
13623
+ }
13624
+ const timer = setTimeout(resolve, ms);
13625
+ if (signal) {
13626
+ const onAbort = () => {
13627
+ clearTimeout(timer);
13628
+ reject(new ReasoningLayerError("Ingestion polling was aborted", {
13629
+ cause: signal.reason
13630
+ }));
13631
+ };
13632
+ signal.addEventListener("abort", onAbort, { once: true });
13633
+ const originalResolve = resolve;
13634
+ resolve = () => {
13635
+ signal.removeEventListener("abort", onAbort);
13636
+ originalResolve();
13637
+ };
13638
+ }
13639
+ });
13640
+ }
13641
+ };
13642
+
13643
+ // src/resources/ingestion.ts
13644
+ var IngestionClient = class {
13645
+ /** @internal */
13646
+ api;
13647
+ /** @internal */
13648
+ constructor(api) {
13649
+ this.api = api;
13650
+ }
13651
+ async ingestMarkdown(request, options) {
13652
+ const sync = options?.sync ?? true;
13653
+ if (!sync) {
13654
+ const response2 = await this.api.http.request({
13655
+ path: `/api/v1/ingest/markdown`,
13656
+ method: "POST",
13657
+ query: { sync: false },
13658
+ body: IngestMarkdownRequestFromFrontToApi(request),
13659
+ type: "application/json" /* Json */,
13660
+ format: "json"
13661
+ });
13662
+ const asyncResponse = AsyncIngestionResponseFromApiToFront(response2.data);
13663
+ return new IngestionSession(this.api, asyncResponse);
13664
+ }
13442
13665
  const response = await this.api.http.request({
13443
13666
  path: `/api/v1/ingest/markdown`,
13444
13667
  method: "POST",
@@ -13468,6 +13691,40 @@ var IngestionClient = class {
13468
13691
  });
13469
13692
  return response.data;
13470
13693
  }
13694
+ async ingestDocument(request, options) {
13695
+ const sync = options?.sync ?? true;
13696
+ if (!sync) {
13697
+ const response2 = await this.api.http.request({
13698
+ path: `/api/v1/ingest/document`,
13699
+ method: "POST",
13700
+ query: { sync: false },
13701
+ body: IngestDocumentRequestFromFrontToApi(request),
13702
+ type: "application/json" /* Json */,
13703
+ format: "json"
13704
+ });
13705
+ const asyncResponse = AsyncIngestionResponseFromApiToFront(response2.data);
13706
+ return new IngestionSession(this.api, asyncResponse);
13707
+ }
13708
+ const response = await this.api.ingestDocument(IngestDocumentRequestFromFrontToApi(request));
13709
+ return IngestDocumentResponseFromApiToFront(response.data);
13710
+ }
13711
+ async ingestDocumentBatch(request, options) {
13712
+ const sync = options?.sync ?? true;
13713
+ if (!sync) {
13714
+ const response2 = await this.api.http.request({
13715
+ path: `/api/v1/ingest/document/batch`,
13716
+ method: "POST",
13717
+ query: { sync: false },
13718
+ body: IngestDocumentBatchRequestFromFrontToApi(request),
13719
+ type: "application/json" /* Json */,
13720
+ format: "json"
13721
+ });
13722
+ const asyncResponse = AsyncIngestionResponseFromApiToFront(response2.data);
13723
+ return new IngestionSession(this.api, asyncResponse);
13724
+ }
13725
+ const response = await this.api.ingestDocumentBatch(IngestDocumentBatchRequestFromFrontToApi(request));
13726
+ return IngestDocumentBatchResponseFromApiToFront(response.data);
13727
+ }
13471
13728
  /**
13472
13729
  * Ingest RDF content (Turtle, N-Triples, RDF/XML, or JSON-LD).
13473
13730
  *
@@ -13515,6 +13772,34 @@ var IngestionClient = class {
13515
13772
  async deleteSession(sessionId) {
13516
13773
  await this.api.deleteIngestionSession(sessionId);
13517
13774
  }
13775
+ /**
13776
+ * Get live pipeline progress for all documents in a session.
13777
+ *
13778
+ * @param sessionId - Session UUID.
13779
+ * @returns Progress snapshots for each document being processed.
13780
+ *
13781
+ * @remarks
13782
+ * Maps to `GET /api/v1/ingest/sessions/{session_id}/progress`.
13783
+ * Returns real-time counters, current pipeline step, and step log.
13784
+ */
13785
+ async getSessionProgress(sessionId) {
13786
+ const response = await this.api.getIngestionProgress(sessionId);
13787
+ return SessionProgressResponseFromApiToFront(response.data);
13788
+ }
13789
+ /**
13790
+ * Get stats for all completed documents in a session.
13791
+ *
13792
+ * @param sessionId - Session UUID.
13793
+ * @returns Per-document stats (term IDs, sort names, token usage, etc.).
13794
+ *
13795
+ * @remarks
13796
+ * Maps to `GET /api/v1/ingest/sessions/{session_id}/stats`.
13797
+ * May be empty if no documents have completed yet.
13798
+ */
13799
+ async getSessionStats(sessionId) {
13800
+ const response = await this.api.getIngestionSessionStats(sessionId);
13801
+ return SessionStatsResponseFromApiToFront(response.data);
13802
+ }
13518
13803
  /**
13519
13804
  * List incomplete documents in a session that can be resumed.
13520
13805
  *
@@ -22231,6 +22516,6 @@ function discriminateFeatureValue(value) {
22231
22516
  );
22232
22517
  }
22233
22518
 
22234
- export { action_reviews_exports as ActionReviews, admin_exports as Admin, analysis_exports as Analysis, ApiError, AuthenticationError, BadRequestError, cdl_exports as CDL, causal_exports as Causal, cognitive_exports as Cognitive, collections_exports as Collections, communities_exports as Communities, ConstraintViolationError, constraints_exports as Constraints, control_exports as Control, conversation_exports as Conversation, discovery_exports as Discovery, execution_exports as Execution, extract_exports as Extract, ForbiddenError, functions_exports as Functions, fuzzy_exports as Fuzzy, FuzzyShape, generation_exports as Generation, health_exports as Health, homoiconic_exports as Homoiconic, ilp_exports as ILP, image_extraction_exports as ImageExtraction, inference_exports as Inference, ingestion_exports as Ingestion, InternalServerError, LP, namespaces_exports as Namespaces, NetworkError, neuro_symbolic_exports as NeuroSymbolic, NotFoundError, ontology_exports as Ontology, optimize_exports as Optimize, osfql_exports as Osfql, oversight_exports as Oversight, plain_values_exports as PlainValues, preferences_exports as Preferences, proof_engine_exports as ProofEngine, query_exports as Query, rag_exports as RAG, RateLimitError, reasoning_exports as Reasoning, ReasoningLayerClient, ReasoningLayerError, research_exports as Research, reviews_exports as Reviews, row_exports as Row, SDK_VERSION, scenarios_exports as Scenarios, SortBuilder, sorts_exports as Sorts, sources_exports as Sources, spaces_exports as Spaces, statistical_exports as Statistical, synthetic_exports as Synthetic, terms_exports as Terms, TimeoutError, utilities_exports as Utilities, ValidationError, Value, values_exports as Values, visualization_exports as Visualization, WebSocketClient, WebSocketConnection, webhook_actions_exports as WebhookActions, allen, constrained, discriminateFeatureValue, guard, isConstrainedPlainVar, isPsiTermInput, isTaggedValueDto, isUuid, psi, toTaggedFeatures, toTaggedValue, toTermInputDto, toUntaggedFeatures, toUntaggedValue };
22519
+ export { action_reviews_exports as ActionReviews, admin_exports as Admin, analysis_exports as Analysis, ApiError, AuthenticationError, BadRequestError, cdl_exports as CDL, causal_exports as Causal, cognitive_exports as Cognitive, collections_exports as Collections, communities_exports as Communities, ConstraintViolationError, constraints_exports as Constraints, control_exports as Control, conversation_exports as Conversation, discovery_exports as Discovery, execution_exports as Execution, extract_exports as Extract, ForbiddenError, functions_exports as Functions, fuzzy_exports as Fuzzy, FuzzyShape, generation_exports as Generation, health_exports as Health, homoiconic_exports as Homoiconic, ilp_exports as ILP, image_extraction_exports as ImageExtraction, inference_exports as Inference, ingestion_exports as Ingestion, IngestionFailedError, IngestionSession, InternalServerError, LP, namespaces_exports as Namespaces, NetworkError, neuro_symbolic_exports as NeuroSymbolic, NotFoundError, ontology_exports as Ontology, optimize_exports as Optimize, osfql_exports as Osfql, oversight_exports as Oversight, plain_values_exports as PlainValues, preferences_exports as Preferences, proof_engine_exports as ProofEngine, query_exports as Query, rag_exports as RAG, RateLimitError, reasoning_exports as Reasoning, ReasoningLayerClient, ReasoningLayerError, research_exports as Research, reviews_exports as Reviews, row_exports as Row, SDK_VERSION, scenarios_exports as Scenarios, SortBuilder, sorts_exports as Sorts, sources_exports as Sources, spaces_exports as Spaces, statistical_exports as Statistical, synthetic_exports as Synthetic, terms_exports as Terms, TimeoutError, utilities_exports as Utilities, ValidationError, Value, values_exports as Values, visualization_exports as Visualization, WebSocketClient, WebSocketConnection, webhook_actions_exports as WebhookActions, allen, constrained, discriminateFeatureValue, guard, isConstrainedPlainVar, isPsiTermInput, isTaggedValueDto, isUuid, psi, toTaggedFeatures, toTaggedValue, toTermInputDto, toUntaggedFeatures, toUntaggedValue };
22235
22520
  //# sourceMappingURL=index.js.map
22236
22521
  //# sourceMappingURL=index.js.map