@qaecy/cue-sdk 0.0.33 → 0.0.35
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/assets/wasm/dir_scanner_wasm.mjs +461 -0
- package/assets/wasm/dir_scanner_wasm_bg.wasm +0 -0
- package/document-filter-Dr_-QbaZ.js +10187 -0
- package/index.d.ts +14 -3
- package/index.js +33 -24
- package/lib/api.d.ts +79 -0
- package/lib/app-data.d.ts +21 -0
- package/lib/apps.d.ts +24 -0
- package/lib/auth.d.ts +77 -0
- package/lib/cache.d.ts +26 -0
- package/lib/contexts.d.ts +17 -0
- package/lib/cue-node.d.ts +19 -0
- package/lib/cue.d.ts +129 -0
- package/lib/currency.d.ts +34 -0
- package/lib/document-filter.d.ts +76 -0
- package/lib/documents.d.ts +223 -0
- package/lib/entities.d.ts +211 -0
- package/lib/extraction.d.ts +48 -0
- package/lib/gis.d.ts +89 -0
- package/lib/index-api.d.ts +39 -0
- package/lib/mcp.d.ts +61 -0
- package/lib/models.d.ts +662 -0
- package/lib/privileges.d.ts +76 -0
- package/lib/processing.d.ts +25 -0
- package/lib/profile.d.ts +128 -0
- package/lib/project-view.d.ts +112 -0
- package/lib/project.d.ts +56 -0
- package/lib/schema.d.ts +84 -0
- package/lib/signal.d.ts +38 -0
- package/lib/signup.d.ts +73 -0
- package/lib/storage.d.ts +52 -0
- package/lib/sync.d.ts +153 -0
- package/lib/tables.d.ts +14 -0
- package/lib/user-settings.d.ts +22 -0
- package/node.js +33 -24
- package/package.json +5 -6
- package/variables.d.ts +71 -0
- package/browser.js +0 -37970
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { CueApi } from './api';
|
|
2
|
+
import { ReadonlySignal } from './signal';
|
|
3
|
+
import { FileType } from 'js/models';
|
|
4
|
+
import { DocumentInfo, ProjectDocumentsData } from './models';
|
|
5
|
+
/**
|
|
6
|
+
* Manages document data for a single project.
|
|
7
|
+
*
|
|
8
|
+
* ### Data model
|
|
9
|
+
* - **`documentInfoMap`** — lazily populated per-document detail signal.
|
|
10
|
+
* Call `requestDocumentData(uuids)` to load entries; already-cached UUIDs
|
|
11
|
+
* are skipped. Data is merged incrementally.
|
|
12
|
+
* - **`projectDocumentsData`** — project-level overview (documents grouped by
|
|
13
|
+
* suffix and content category, plus duplicate count). Auto-fetched on
|
|
14
|
+
* construction via three parallel SPARQL queries that resolve as a single
|
|
15
|
+
* atomic update.
|
|
16
|
+
*
|
|
17
|
+
* ### Language
|
|
18
|
+
* `subject` and `summary` fields on documents are language-tagged in the
|
|
19
|
+
* triplestore. Pass the active language to `requestDocumentData()` and call
|
|
20
|
+
* `setLanguage()` when it changes (which clears and re-fetches the info map
|
|
21
|
+
* so labels re-resolve in the new language).
|
|
22
|
+
*
|
|
23
|
+
* ### Lifecycle
|
|
24
|
+
* Call `reset()` when the project changes. The Angular adapter's project-change
|
|
25
|
+
* effect should call this, followed by `fetchOverview()` once the triplestore
|
|
26
|
+
* is ready.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const docs = new CueProjectDocuments(cue.api, projectId, 'en');
|
|
31
|
+
* await docs.fetchOverview();
|
|
32
|
+
* docs.requestDocumentData(['uuid1', 'uuid2']);
|
|
33
|
+
* const info = docs.documentInfoMap.get()['uuid1'];
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class CueProjectDocuments {
|
|
37
|
+
private readonly _api;
|
|
38
|
+
private readonly _projectId;
|
|
39
|
+
private readonly _graphType?;
|
|
40
|
+
private readonly _verbose;
|
|
41
|
+
/** Full RDF base URL for this project, e.g. `https://cue.qaecy.com/r/{pid}/` */
|
|
42
|
+
readonly baseURL: string;
|
|
43
|
+
/** Tracks the language for which `_documentInfoMap` is currently populated. */
|
|
44
|
+
private _currentLang;
|
|
45
|
+
private readonly _documentInfoMap;
|
|
46
|
+
/** Cumulative unique document UUIDs ever passed to request methods (survives cache hits). */
|
|
47
|
+
private readonly _seenIds;
|
|
48
|
+
private readonly _projectDocumentsData;
|
|
49
|
+
/** Lazily populated per-document detail map. */
|
|
50
|
+
readonly documentInfoMap: ReadonlySignal<Record<string, DocumentInfo>>;
|
|
51
|
+
/** Project-level document overview (grouped counts + sizes). */
|
|
52
|
+
readonly projectDocumentsData: ReadonlySignal<ProjectDocumentsData>;
|
|
53
|
+
constructor(_api: CueApi, _projectId: string, language?: string,
|
|
54
|
+
/** Override the RDF resource base URL. Defaults to `https://cue.qaecy.com/r/`. */
|
|
55
|
+
rdfBase?: string, _graphType?: string | undefined, _verbose?: boolean);
|
|
56
|
+
/**
|
|
57
|
+
* Resets all document state. Call when the active project changes.
|
|
58
|
+
* Follow with `fetchOverview()` once the triplestore is ready.
|
|
59
|
+
*/
|
|
60
|
+
reset(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Updates the active language and clears the document info map so that
|
|
63
|
+
* language-sensitive fields (subject, summary) are re-fetched on the next
|
|
64
|
+
* `requestDocumentData()` call.
|
|
65
|
+
*/
|
|
66
|
+
setLanguage(lang: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* Fetches the three-part project overview (by suffix, by content category,
|
|
69
|
+
* duplicate count) in parallel and writes them as a single atomic update to
|
|
70
|
+
* `projectDocumentsData`. Safe to call again to refresh.
|
|
71
|
+
*/
|
|
72
|
+
fetchOverview(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Lazily batch-fetches core metadata for the given document UUIDs.
|
|
75
|
+
* Already-cached UUIDs are skipped. Data is merged into `documentInfoMap`
|
|
76
|
+
* once the SPARQL response arrives.
|
|
77
|
+
*/
|
|
78
|
+
requestDocumentData(uuids: string[]): void;
|
|
79
|
+
/**
|
|
80
|
+
* Promise-based alternative to {@link requestDocumentData} for non-reactive contexts.
|
|
81
|
+
*
|
|
82
|
+
* Resolves with the `DocumentInfo` entries for every requested UUID once the
|
|
83
|
+
* SPARQL response arrives. UUIDs already present in the cache are returned
|
|
84
|
+
* immediately without a network request. The result is also written into
|
|
85
|
+
* `documentInfoMap` so reactive consumers stay in sync.
|
|
86
|
+
*
|
|
87
|
+
* UUIDs not found in the triplestore are omitted from the returned map.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* const docs = await cueProjectDocs.fetchDocumentData(['uuid1', 'uuid2']);
|
|
92
|
+
* console.log(docs['uuid1'].subject);
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
fetchDocumentData(uuids: string[]): Promise<Record<string, DocumentInfo>>;
|
|
96
|
+
/**
|
|
97
|
+
* Fetches a lightweight document metadata shape (id/path/suffix/size) for
|
|
98
|
+
* the given UUIDs and merges the results into `documentInfoMap`.
|
|
99
|
+
*
|
|
100
|
+
* This is useful for list/table contexts that do not need language-tagged
|
|
101
|
+
* fields (`subject`, `summary`) or category/tag enrichment.
|
|
102
|
+
*
|
|
103
|
+
* UUIDs already present in `documentInfoMap` are skipped.
|
|
104
|
+
*/
|
|
105
|
+
fetchDocumentDataSimple(uuids: string[]): Promise<Record<string, DocumentInfo>>;
|
|
106
|
+
/**
|
|
107
|
+
* Returns the alternative representations of the given document UUID.
|
|
108
|
+
*
|
|
109
|
+
* Alternative representations are derived artefacts stored under
|
|
110
|
+
* `qcy:alternativeRepresentation` in the triplestore — for example a
|
|
111
|
+
* `.fragments` BIM tile derived from an `.ifc` source file.
|
|
112
|
+
*
|
|
113
|
+
* The returned `DocumentInfo` entries are also merged into
|
|
114
|
+
* `documentInfoMap` so reactive consumers stay in sync.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* const alts = await docs.fetchAlternativeRepresentations('abc-123');
|
|
119
|
+
* // alts[0].suffix => '.fragments'
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
fetchAlternativeRepresentations(uuid: string): Promise<DocumentInfo[]>;
|
|
123
|
+
/**
|
|
124
|
+
* Returns a single arbitrary file path from the project's triplestore.
|
|
125
|
+
* Useful for pre-filling path-based query inputs with a realistic example.
|
|
126
|
+
*/
|
|
127
|
+
randomFilePath(): Promise<string | null>;
|
|
128
|
+
/**
|
|
129
|
+
* Fetches all `qcy:FileContent` documents whose file suffix matches one of
|
|
130
|
+
* the given extensions (e.g. `'.ifc'`, `'.pdf'`).
|
|
131
|
+
*
|
|
132
|
+
* By default returns only `{ iri, uuid }` — pass `includeMetadata: true` to
|
|
133
|
+
* also get `path`, `suffix`, and `size`. Use the default form when you intend
|
|
134
|
+
* to lazy-load full details via `requestDocumentData`.
|
|
135
|
+
*
|
|
136
|
+
* Suffixes are matched case-insensitively and the leading dot is optional
|
|
137
|
+
* (both `'ifc'` and `'.ifc'` are accepted).
|
|
138
|
+
*/
|
|
139
|
+
documentsBySuffix(suffixes: string[], includeMetadata?: false): Promise<Array<{
|
|
140
|
+
iri: string;
|
|
141
|
+
uuid: string;
|
|
142
|
+
}>>;
|
|
143
|
+
documentsBySuffix(suffixes: string[], includeMetadata: true): Promise<Array<{
|
|
144
|
+
iri: string;
|
|
145
|
+
uuid: string;
|
|
146
|
+
path: string;
|
|
147
|
+
suffix: string;
|
|
148
|
+
size: number;
|
|
149
|
+
}>>;
|
|
150
|
+
/**
|
|
151
|
+
* Fetches documents whose file suffix maps to one of the given `FileType`
|
|
152
|
+
* values (e.g. `FileType.BIM`, `FileType.CAD`).
|
|
153
|
+
*
|
|
154
|
+
* Resolves matching suffixes from `fileExtensionsInfo` and delegates to
|
|
155
|
+
* `documentsBySuffix`. Accepts the same `includeMetadata` flag.
|
|
156
|
+
*/
|
|
157
|
+
documentsByFileType(fileTypes: FileType[], includeMetadata?: false): Promise<Array<{
|
|
158
|
+
iri: string;
|
|
159
|
+
uuid: string;
|
|
160
|
+
}>>;
|
|
161
|
+
documentsByFileType(fileTypes: FileType[], includeMetadata: true): Promise<Array<{
|
|
162
|
+
iri: string;
|
|
163
|
+
uuid: string;
|
|
164
|
+
path: string;
|
|
165
|
+
suffix: string;
|
|
166
|
+
size: number;
|
|
167
|
+
}>>;
|
|
168
|
+
/**
|
|
169
|
+
* Fetches all `qcy:FileContent` documents that carry one of the given
|
|
170
|
+
* content-category IRIs (e.g. as returned by `projectDocumentsData.documentsByContentCategory`).
|
|
171
|
+
*
|
|
172
|
+
* By default returns only `{ iri, uuid }` — pass `includeMetadata: true` to
|
|
173
|
+
* also get `path`, `suffix`, and `size`. Use the default form when you intend
|
|
174
|
+
* to lazy-load full details via `requestDocumentData`.
|
|
175
|
+
*/
|
|
176
|
+
documentsByContentCategory(categoryIRIs: string[], includeMetadata?: false): Promise<Array<{
|
|
177
|
+
iri: string;
|
|
178
|
+
uuid: string;
|
|
179
|
+
}>>;
|
|
180
|
+
documentsByContentCategory(categoryIRIs: string[], includeMetadata: true): Promise<Array<{
|
|
181
|
+
iri: string;
|
|
182
|
+
uuid: string;
|
|
183
|
+
path: string;
|
|
184
|
+
suffix: string;
|
|
185
|
+
size: number;
|
|
186
|
+
}>>;
|
|
187
|
+
/**
|
|
188
|
+
* Fetches documents whose MIME type matches one of the given strings
|
|
189
|
+
* (e.g. `'application/x-step'`, `'application/pdf'`).
|
|
190
|
+
*
|
|
191
|
+
* Resolves matching suffixes from `fileExtensionsInfo` and delegates to
|
|
192
|
+
* `documentsBySuffix`. Accepts the same `includeMetadata` flag.
|
|
193
|
+
*/
|
|
194
|
+
documentsByMime(mimeTypes: string[], includeMetadata?: false): Promise<Array<{
|
|
195
|
+
iri: string;
|
|
196
|
+
uuid: string;
|
|
197
|
+
}>>;
|
|
198
|
+
documentsByMime(mimeTypes: string[], includeMetadata: true): Promise<Array<{
|
|
199
|
+
iri: string;
|
|
200
|
+
uuid: string;
|
|
201
|
+
path: string;
|
|
202
|
+
suffix: string;
|
|
203
|
+
size: number;
|
|
204
|
+
}>>;
|
|
205
|
+
/** Builds a full resource IRI from a UUID without a SPARQL round-trip. */
|
|
206
|
+
private _resourceIri;
|
|
207
|
+
private _log;
|
|
208
|
+
/** Executes the document-info SPARQL query for the given UUIDs, merges results
|
|
209
|
+
* into `documentInfoMap`, and returns the newly fetched entries. */
|
|
210
|
+
private _fetchDocumentInfoBatch;
|
|
211
|
+
/** Executes a reduced document-info query (id/path/suffix/size only), merges
|
|
212
|
+
* into `documentInfoMap`, and returns newly fetched entries. */
|
|
213
|
+
private _fetchSimpleDocumentInfoBatch;
|
|
214
|
+
private _fetchDocumentsBySuffix;
|
|
215
|
+
private _buildDocumentsBySuffixQuery;
|
|
216
|
+
private _runDocumentsBySuffixQuery;
|
|
217
|
+
private _fetchDocumentsByContentCategory;
|
|
218
|
+
private _buildDocumentsByContentCategoryQuery;
|
|
219
|
+
private _runDocumentsByContentCategoryQuery;
|
|
220
|
+
private _fetchDuplicateCount;
|
|
221
|
+
private _buildDuplicateCountQuery;
|
|
222
|
+
private _runDuplicateCountQuery;
|
|
223
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { CueApi } from './api';
|
|
2
|
+
import { ReadonlySignal } from './signal';
|
|
3
|
+
import { EntityDetailedData, EntityRelationships, ProjectEntitiesData, SummaryGraphData } from './models';
|
|
4
|
+
/**
|
|
5
|
+
* Manages entity data for a single project.
|
|
6
|
+
*
|
|
7
|
+
* ### Data model
|
|
8
|
+
* - **`entityInfoMap`** — merged per-entity signal. Recomputes reactively as
|
|
9
|
+
* any of the five underlying slices (core data, documents, relationships,
|
|
10
|
+
* OSM map, OSM WKT) change.
|
|
11
|
+
* - **`entityGraph`** — project-level category-to-category relationship graph,
|
|
12
|
+
* fetched once on construction.
|
|
13
|
+
*
|
|
14
|
+
* ### Lazy loading
|
|
15
|
+
* All public `request*` / `fetch*` methods are no-ops for UUIDs / IRIs already
|
|
16
|
+
* in the cache. Only the delta is fetched. Data is merged into the
|
|
17
|
+
* `entityInfoMap` signal incrementally — callers just react to the signal.
|
|
18
|
+
*
|
|
19
|
+
* ### Language
|
|
20
|
+
* Entity labels (`qcy:value`) are not language-tagged in the triplestore, so
|
|
21
|
+
* entity data itself is language-independent. The `language` parameter is
|
|
22
|
+
* carried here for future-proofing and forwards to the schema-level queries
|
|
23
|
+
* where language filtering does apply.
|
|
24
|
+
*
|
|
25
|
+
* ### Lifecycle
|
|
26
|
+
* Call `reset()` when the project changes. The Angular adapter calls this from
|
|
27
|
+
* the effect that watches `projectId`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const entities = new CueProjectEntities(cue.api, projectId);
|
|
32
|
+
* entities.requestEntityData(['uuid1', 'uuid2']);
|
|
33
|
+
* const info = entities.entityInfoMap.get()['uuid1'];
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class CueProjectEntities {
|
|
37
|
+
private readonly _api;
|
|
38
|
+
private readonly _projectId;
|
|
39
|
+
private readonly _graphType?;
|
|
40
|
+
private readonly _verbose;
|
|
41
|
+
/** Full RDF base URL for this project, e.g. `https://cue.qaecy.com/r/{pid}/` */
|
|
42
|
+
readonly baseURL: string;
|
|
43
|
+
private readonly _entityDetails;
|
|
44
|
+
private readonly _entityDocuments;
|
|
45
|
+
private readonly _entityRelationships;
|
|
46
|
+
private readonly _entityOSMMap;
|
|
47
|
+
private readonly _osmWKTMap;
|
|
48
|
+
private readonly _fetchingOSMIds;
|
|
49
|
+
/** Cumulative unique entity UUIDs ever passed to request methods (survives cache hits). */
|
|
50
|
+
private readonly _seenIds;
|
|
51
|
+
private readonly _entityGraph;
|
|
52
|
+
/**
|
|
53
|
+
* Memoizes the raw category-summary rows per neighbourhood (keyed by the
|
|
54
|
+
* expanded `entityIRI`, or `''` for the full graph) so that repeat/concurrent
|
|
55
|
+
* `buildSummaryGraph` calls for the same neighbourhood — e.g. re-rendering a
|
|
56
|
+
* view, or requesting both `'graph'` and `'md'` formats — share one fetch
|
|
57
|
+
* instead of re-querying. Cleared on `reset()`.
|
|
58
|
+
*/
|
|
59
|
+
private readonly _summaryGraphCache;
|
|
60
|
+
/**
|
|
61
|
+
* Memoizes per-category entity counts (project-wide, not neighbourhood-scoped
|
|
62
|
+
* — unlike `_summaryGraphCache` there's only ever one of these per project).
|
|
63
|
+
* Cleared on `reset()`.
|
|
64
|
+
*/
|
|
65
|
+
private _categoryCountsCache;
|
|
66
|
+
private readonly _entityInfoMapComputed;
|
|
67
|
+
/** Merged per-entity detail map. Updated reactively as data arrives. */
|
|
68
|
+
readonly entityInfoMap: ReadonlySignal<Record<string, EntityDetailedData>>;
|
|
69
|
+
/** Project-level category graph (fetched once per project). */
|
|
70
|
+
readonly entityGraph: ReadonlySignal<ProjectEntitiesData | undefined>;
|
|
71
|
+
constructor(_api: CueApi, _projectId: string,
|
|
72
|
+
/** Override the RDF resource base URL. Defaults to `https://cue.qaecy.com/r/`. */
|
|
73
|
+
rdfBase?: string, _graphType?: string | undefined, _verbose?: boolean);
|
|
74
|
+
/**
|
|
75
|
+
* Constructs the full RDF IRI for the given entity UUID.
|
|
76
|
+
* Use this to bridge the UUID-based batch APIs and the IRI-based per-entity APIs.
|
|
77
|
+
*/
|
|
78
|
+
entityIri(uuid: string): string;
|
|
79
|
+
/** @internal Builds a full resource IRI from a UUID without a SPARQL round-trip. */
|
|
80
|
+
private _resourceIri;
|
|
81
|
+
private _log;
|
|
82
|
+
/**
|
|
83
|
+
* Resets all entity state and re-fetches the entity graph.
|
|
84
|
+
* Call when the active project changes.
|
|
85
|
+
*/
|
|
86
|
+
reset(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Lazily batch-fetches core data (label + categories) for the given entity
|
|
89
|
+
* UUIDs. Already-fetched UUIDs are skipped.
|
|
90
|
+
*
|
|
91
|
+
* Data is merged into `entityInfoMap` once the SPARQL response arrives.
|
|
92
|
+
*/
|
|
93
|
+
requestEntityData(uuids: string[], includeMentionCount?: boolean): void;
|
|
94
|
+
/**
|
|
95
|
+
* Lazily fetches OSM location data for the given entity UUIDs.
|
|
96
|
+
* Already-fetched UUIDs are skipped.
|
|
97
|
+
*
|
|
98
|
+
* OSM WKT geometry is fetched in a second pass via a federated SPARQL SERVICE
|
|
99
|
+
* query and merged into `entityInfoMap` reactively once it arrives.
|
|
100
|
+
*/
|
|
101
|
+
requestEntityLocations(uuids: string[]): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Fetches incoming and outgoing relationships for a single entity IRI.
|
|
104
|
+
* Neighbouring entity core data is opportunistically populated into
|
|
105
|
+
* `entityInfoMap` as a side-effect.
|
|
106
|
+
*
|
|
107
|
+
* The result is stored in `entityInfoMap[uuid].relationshipData` and also
|
|
108
|
+
* returned directly for callers that need an immediate value.
|
|
109
|
+
*/
|
|
110
|
+
fetchEntityRelationships(iri: string): Promise<EntityRelationships>;
|
|
111
|
+
/**
|
|
112
|
+
* Fetches UUIDs of documents that reference the given entity IRI.
|
|
113
|
+
* Also triggers a core-data fetch for the entity itself if not yet loaded.
|
|
114
|
+
*
|
|
115
|
+
* Returns document UUIDs. Full document data will be populated by the
|
|
116
|
+
* document service (future `CueProjectDocuments`).
|
|
117
|
+
*/
|
|
118
|
+
fetchEntityDocuments(iri: string): Promise<string[]>;
|
|
119
|
+
/**
|
|
120
|
+
* Fetches all `qcy:EntityCategory` IRIs and their preferred labels for this
|
|
121
|
+
* project. Uses `api.language` (default `'en'`);
|
|
122
|
+
* falls back to an untagged label when no match is found.
|
|
123
|
+
*/
|
|
124
|
+
contentCategoriesInProject(orderByOccurences?: boolean): Promise<{
|
|
125
|
+
iri: string;
|
|
126
|
+
label: string;
|
|
127
|
+
}[]>;
|
|
128
|
+
/**
|
|
129
|
+
* Fetches all `qcy:CanonicalEntity` instances that belong to at least one of
|
|
130
|
+
* the given category IRIs.
|
|
131
|
+
*
|
|
132
|
+
* Accepts both full HTTP IRIs and prefixed forms, e.g.:
|
|
133
|
+
* - `"qcy:Building"`
|
|
134
|
+
* - `"https://cue.qaecy.com/ontology#Building"`
|
|
135
|
+
*
|
|
136
|
+
* By default returns `{ iri, uuid }[]` — the IRI is built locally from the
|
|
137
|
+
* project base URL so no extra data is fetched from the endpoint.
|
|
138
|
+
* Pass `includeMetadata: true` to also get `value` and `categories`.
|
|
139
|
+
* Use the default form when you intend to lazy-load details via `requestEntityData`.
|
|
140
|
+
*/
|
|
141
|
+
entitiesByCategory(categoryIris: string[], includeMetadata?: false): Promise<Array<{
|
|
142
|
+
iri: string;
|
|
143
|
+
uuid: string;
|
|
144
|
+
}>>;
|
|
145
|
+
entitiesByCategory(categoryIris: string[], includeMetadata: true): Promise<Array<{
|
|
146
|
+
iri: string;
|
|
147
|
+
uuid: string;
|
|
148
|
+
value: string;
|
|
149
|
+
categories: string[];
|
|
150
|
+
}>>;
|
|
151
|
+
/**
|
|
152
|
+
* Fetches a summary graph of entity category relationships for the project.
|
|
153
|
+
*
|
|
154
|
+
* Each row describes how many times entities of `sourceCat` point to
|
|
155
|
+
* entities of `targetCat` via a given `predicate`, ordered by descending
|
|
156
|
+
* occurrence count.
|
|
157
|
+
*
|
|
158
|
+
* @param format
|
|
159
|
+
* - `undefined` — raw SPARQL JSON result
|
|
160
|
+
* - `'graph'` — structured `{ entities, relations }` with predicates and weights
|
|
161
|
+
* - `'md'` — compact aligned text table
|
|
162
|
+
*
|
|
163
|
+
* @param entityIRI Optional category IRI (prefixed, e.g. `qcy:Building`, or
|
|
164
|
+
* full, e.g. `https://…Building`). When supplied, only edges where either
|
|
165
|
+
* the source or target category equals this IRI are returned — i.e. the
|
|
166
|
+
* one-hop neighbourhood of that category.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* // Structured graph (nodes + edges)
|
|
171
|
+
* const g = await entities.buildSummaryGraph('graph');
|
|
172
|
+
* // g.entities → [{ iri: 'https://…FloorPlanDrawing' }, …]
|
|
173
|
+
* // g.relations → [{ sourceID, predicate, targetID, weight }, …]
|
|
174
|
+
*
|
|
175
|
+
* // Neighbourhood of a single category (prefixed IRI)
|
|
176
|
+
* const g2 = await entities.buildSummaryGraph('graph', 'qcy:Building');
|
|
177
|
+
*
|
|
178
|
+
* // Markdown table
|
|
179
|
+
* const md = await entities.buildSummaryGraph('md');
|
|
180
|
+
* // qcy:FloorPlanDrawing -> qcy:includesBuildingEntity -> qcy:BuildingZone (5652)
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
buildSummaryGraph(format: 'graph', entityIRI?: string): Promise<SummaryGraphData>;
|
|
184
|
+
buildSummaryGraph(format: 'md', entityIRI?: string): Promise<string>;
|
|
185
|
+
buildSummaryGraph(format?: undefined, entityIRI?: string): Promise<unknown>;
|
|
186
|
+
/**
|
|
187
|
+
* Fetches the category-summary rows. On QLever the pre-computed
|
|
188
|
+
* `entity-summary` materialized view is tried first; if it yields no rows we
|
|
189
|
+
* warn and fall back to the live aggregation query. Fuseki always uses the
|
|
190
|
+
* live query.
|
|
191
|
+
*/
|
|
192
|
+
private _fetchSummaryData;
|
|
193
|
+
/**
|
|
194
|
+
* Fetches per-category entity counts (project-wide — there's no neighbourhood
|
|
195
|
+
* scoping for this one). Cached for the lifetime of this instance since it's
|
|
196
|
+
* a cheap, single-aggregate view that doesn't vary per `buildSummaryGraph` call.
|
|
197
|
+
*/
|
|
198
|
+
private _fetchCategoryCounts;
|
|
199
|
+
/**
|
|
200
|
+
* Tries the named materialized view first (QLever only); falls back to the
|
|
201
|
+
* live query if the view yields no rows, or on Fuseki (which has no views).
|
|
202
|
+
*/
|
|
203
|
+
private _fetchViewBacked;
|
|
204
|
+
private _computeEntityInfoMap;
|
|
205
|
+
private _fetchOutgoingRelationships;
|
|
206
|
+
private _fetchIncomingRelationships;
|
|
207
|
+
private _fetchEntityGraph;
|
|
208
|
+
/** Detects new OSM IRIs in the OSM map that don't yet have WKT and fetches them. */
|
|
209
|
+
private _checkPendingOSMFetches;
|
|
210
|
+
private _fetchOSMLocations;
|
|
211
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CueAuth } from './auth';
|
|
2
|
+
export declare const ENDPOINT_EXTRACTION = "/semantic-extraction/extract";
|
|
3
|
+
export interface ExtractionRequest {
|
|
4
|
+
/** PNG (or other image) blob of the document page to extract from. */
|
|
5
|
+
image: Blob;
|
|
6
|
+
/** SemanticTemplate JSON object. */
|
|
7
|
+
template: object;
|
|
8
|
+
/** Project / space ID used by the extraction service. */
|
|
9
|
+
projectId: string;
|
|
10
|
+
/** IRI of the pre-selected content category; omit to let the model classify. */
|
|
11
|
+
category?: string | null;
|
|
12
|
+
/** Plain text of the page, used as additional context. */
|
|
13
|
+
text?: string | null;
|
|
14
|
+
/** Desired RDF serialisation — defaults to `'json-ld'`. */
|
|
15
|
+
rdfFormat?: 'json-ld' | 'turtle' | 'ntriples' | 'xml';
|
|
16
|
+
}
|
|
17
|
+
export interface ExtractionResponse {
|
|
18
|
+
/** Parsed JSON-LD document ready for `cue-rdf-graph`. */
|
|
19
|
+
jsonld: object;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Client for the Cue semantic-extraction endpoint.
|
|
23
|
+
*
|
|
24
|
+
* Exposed as `cue.api.extraction`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const result = await cue.api.extraction.extract({
|
|
29
|
+
* image: pngBlob,
|
|
30
|
+
* template: myTemplate,
|
|
31
|
+
* projectId: 'my-project',
|
|
32
|
+
* });
|
|
33
|
+
* // result.jsonld is a JSON-LD document for cue-rdf-graph
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class CueExtraction {
|
|
37
|
+
private readonly _auth;
|
|
38
|
+
private readonly _gatewayUrl;
|
|
39
|
+
constructor(_auth: CueAuth, _gatewayUrl: string);
|
|
40
|
+
/**
|
|
41
|
+
* Run semantic extraction on a document page image.
|
|
42
|
+
*
|
|
43
|
+
* Sends a multipart/form-data POST to `/semantic-extraction/extract`.
|
|
44
|
+
* Always requests JSON-LD so the result can be displayed directly in
|
|
45
|
+
* `cue-rdf-graph` without any further parsing.
|
|
46
|
+
*/
|
|
47
|
+
extract(request: ExtractionRequest): Promise<ExtractionResponse>;
|
|
48
|
+
}
|
package/lib/gis.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { BBox, FeatureCategory, FeatureCategoryDescriptor, GisFeature } from 'js/cue-gis';
|
|
2
|
+
export type GisBBox = BBox;
|
|
3
|
+
export type { FeatureCategory };
|
|
4
|
+
export type GisCategoryDescriptor = FeatureCategoryDescriptor;
|
|
5
|
+
export type { GisFeature };
|
|
6
|
+
export type GisFeaturesMap = Map<FeatureCategory, GisFeature[]>;
|
|
7
|
+
type Listener<T> = (value: T) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Reactive GIS service, exposed lazily as `cue.gis`.
|
|
10
|
+
*
|
|
11
|
+
* Push-based: consumers set the active bbox and selected categories; results are
|
|
12
|
+
* delivered via subscription callbacks. All debouncing and request cancellation
|
|
13
|
+
* are handled internally.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* cue.gis.setProjectId('my-project-id');
|
|
18
|
+
* cue.gis.onAvailableCategories(cats => console.log(cats));
|
|
19
|
+
*
|
|
20
|
+
* // On every map pan/zoom:
|
|
21
|
+
* cue.gis.setBbox([west, south, east, north]);
|
|
22
|
+
*
|
|
23
|
+
* // When the user toggles a category:
|
|
24
|
+
* cue.gis.setSelectedCategories(new Set(['cadastre', 'building']));
|
|
25
|
+
*
|
|
26
|
+
* // Cleanup:
|
|
27
|
+
* cue.gis.destroy();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare class CueGis {
|
|
31
|
+
private readonly _getAuthHeaders;
|
|
32
|
+
private readonly _gatewayUrl;
|
|
33
|
+
private _bbox;
|
|
34
|
+
private _projectId;
|
|
35
|
+
private _selectedCategories;
|
|
36
|
+
private _queryToken;
|
|
37
|
+
private _categoryTokens;
|
|
38
|
+
private _debounceTimer;
|
|
39
|
+
private _availableCategories;
|
|
40
|
+
private _features;
|
|
41
|
+
private readonly _catListeners;
|
|
42
|
+
private readonly _featListeners;
|
|
43
|
+
private readonly _loadListeners;
|
|
44
|
+
private _gatewayCache;
|
|
45
|
+
private _gatewayProjectId;
|
|
46
|
+
/** @internal — construct via `cue.gis`, not directly. */
|
|
47
|
+
constructor(_getAuthHeaders: () => Promise<Record<string, string>>, _gatewayUrl: string);
|
|
48
|
+
/**
|
|
49
|
+
* Update the current map viewport.
|
|
50
|
+
* Triggers a debounced query for available categories and reloads selected ones.
|
|
51
|
+
*/
|
|
52
|
+
setBbox(bbox: BBox): void;
|
|
53
|
+
/**
|
|
54
|
+
* Set or clear the active project.
|
|
55
|
+
* Rebuilds the authenticated adapter so subsequent requests carry the new project header.
|
|
56
|
+
*/
|
|
57
|
+
setProjectId(projectId: string | null): void;
|
|
58
|
+
/**
|
|
59
|
+
* Replace the full set of selected categories.
|
|
60
|
+
* Newly added categories begin loading immediately; removed categories are cleared.
|
|
61
|
+
*/
|
|
62
|
+
setSelectedCategories(categories: Set<FeatureCategory>): void;
|
|
63
|
+
/**
|
|
64
|
+
* Subscribe to available-category updates.
|
|
65
|
+
* Replays the current value immediately, then fires on every bbox change.
|
|
66
|
+
* @returns An unsubscribe function.
|
|
67
|
+
*/
|
|
68
|
+
onAvailableCategories(cb: Listener<GisCategoryDescriptor[]>): () => void;
|
|
69
|
+
/**
|
|
70
|
+
* Subscribe to the feature map (category → GisFeature[]).
|
|
71
|
+
* Replays the current value immediately, then fires whenever features change.
|
|
72
|
+
* @returns An unsubscribe function.
|
|
73
|
+
*/
|
|
74
|
+
onFeaturesChange(cb: Listener<GisFeaturesMap>): () => void;
|
|
75
|
+
/**
|
|
76
|
+
* Subscribe to the global loading state.
|
|
77
|
+
* Fires `true` while the category list is being queried, `false` when done.
|
|
78
|
+
* @returns An unsubscribe function.
|
|
79
|
+
*/
|
|
80
|
+
onLoadingChange(cb: Listener<boolean>): () => void;
|
|
81
|
+
/** Cancel all pending requests and clear all listeners. */
|
|
82
|
+
destroy(): void;
|
|
83
|
+
private _scheduleDebouncedQuery;
|
|
84
|
+
private _getGateway;
|
|
85
|
+
private _queryLayers;
|
|
86
|
+
private _loadCategory;
|
|
87
|
+
private _emitFeatures;
|
|
88
|
+
private _emitLoading;
|
|
89
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CueAuth } from './auth';
|
|
2
|
+
import { AvailableFiltersResponse, IndexAppliedFilters, IndexSearchRequest, IndexSearchResponse } from './models';
|
|
3
|
+
export declare class CueIndexApi {
|
|
4
|
+
private readonly _auth;
|
|
5
|
+
private readonly _gatewayUrl;
|
|
6
|
+
constructor(_auth: CueAuth, _gatewayUrl: string);
|
|
7
|
+
search(input: string, projectId: string, opts?: Omit<IndexSearchRequest, 'input'>): Promise<IndexSearchResponse>;
|
|
8
|
+
lookup(input: string, projectId: string, opts?: {
|
|
9
|
+
aggregate?: boolean;
|
|
10
|
+
}): Promise<IndexSearchResponse>;
|
|
11
|
+
/**
|
|
12
|
+
* Discover which filter options are available in the document set that survives
|
|
13
|
+
* the provided `applied` filters. Call with no `applied` argument (or an empty
|
|
14
|
+
* object) to retrieve all options for the project.
|
|
15
|
+
*
|
|
16
|
+
* Drives adaptive filter UIs: after the user sets filter N, pass the active
|
|
17
|
+
* filters to this method and use the response to constrain the options shown
|
|
18
|
+
* for filter N+1.
|
|
19
|
+
*
|
|
20
|
+
* Requires the `/index/available-filters` gateway endpoint.
|
|
21
|
+
*/
|
|
22
|
+
availableFilters(projectId: string, applied?: IndexAppliedFilters): Promise<AvailableFiltersResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Forces a full binary rebuild of the project's QLever index. Super-admin only
|
|
25
|
+
* (the gateway/accessor rejects non-superadmin callers). Streams NDJSON
|
|
26
|
+
* progress lines from the backend; `onProgress` (if given) is called with
|
|
27
|
+
* each intermediate message. Resolves with the final message once the
|
|
28
|
+
* rebuild finishes, or rejects if it fails.
|
|
29
|
+
*/
|
|
30
|
+
rebuild(projectId: string, onProgress?: (message: string) => void): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Forces a full re-scan of every project's QLever stats (materialized views,
|
|
33
|
+
* index size, cue-meta) and persists the result, bypassing the normal cache
|
|
34
|
+
* TTL. Super-admin only. This refreshes the shared stats aggregate for ALL
|
|
35
|
+
* projects, not just the current one — there's no per-project variant since
|
|
36
|
+
* the aggregate is written as a single file. Resolves with a summary message.
|
|
37
|
+
*/
|
|
38
|
+
refreshStats(): Promise<string>;
|
|
39
|
+
}
|
package/lib/mcp.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CueAuth } from './auth';
|
|
2
|
+
import { McpContext } from './models';
|
|
3
|
+
/**
|
|
4
|
+
* Minimal view of an MCP `tools/call` result — only the fields the response
|
|
5
|
+
* handling reads. Declared locally instead of imported from the SDK on
|
|
6
|
+
* purpose: the SDK ships its types only behind an `exports` map, which this
|
|
7
|
+
* project's `moduleResolution: "node"` cannot follow, so the imported result
|
|
8
|
+
* type collapses to its `unknown` index signature.
|
|
9
|
+
*/
|
|
10
|
+
type McpTextBlock = {
|
|
11
|
+
type: 'text';
|
|
12
|
+
text: string;
|
|
13
|
+
};
|
|
14
|
+
interface McpCallResult {
|
|
15
|
+
content: Array<McpTextBlock | {
|
|
16
|
+
type: string;
|
|
17
|
+
}>;
|
|
18
|
+
structuredContent?: Record<string, unknown> | null;
|
|
19
|
+
isError?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface McpCallOptions {
|
|
22
|
+
/** Abort signal forwarded to the underlying MCP request. */
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
/** Flatten any `HeadersInit` (Headers instance, tuples, or record) into a plain record. */
|
|
26
|
+
export declare function toHeaderRecord(init: HeadersInit | undefined): Record<string, string>;
|
|
27
|
+
/** Join every text content block into one string, mirroring the Python probe's `extract_payload`. */
|
|
28
|
+
export declare function extractText(content: McpCallResult['content']): string;
|
|
29
|
+
/**
|
|
30
|
+
* A data tool that catches an exception returns `{ error }` (see the backend's
|
|
31
|
+
* `tool_error`) — a soft failure with no `id`, distinct from a real context.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isToolError(payload: unknown): payload is {
|
|
34
|
+
error: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Resolve a tool result to its payload the same way the Python probe does:
|
|
38
|
+
* prefer the structured content the tool returned, otherwise fall back to the
|
|
39
|
+
* text content (parsed as JSON when possible, raw string otherwise).
|
|
40
|
+
*/
|
|
41
|
+
export declare function extractPayload<T>(result: McpCallResult): T;
|
|
42
|
+
/**
|
|
43
|
+
* Generic caller for the Cue Index MCP *data tools*.
|
|
44
|
+
*
|
|
45
|
+
* Speaks the FastMCP streamable-HTTP protocol against the gateway `/mcp` route
|
|
46
|
+
* (the same protocol the `probe_mcp.py` reference uses via `fastmcp.Client`):
|
|
47
|
+
* it performs the `initialize` handshake, invokes `tools/call`, and returns the
|
|
48
|
+
* tool's Context result ({@link McpContext} — `{ id, text }`) proxied through
|
|
49
|
+
* unchanged, with no endpoint-specific logic or re-templating.
|
|
50
|
+
*
|
|
51
|
+
* Type the call per endpoint via the generic parameters, e.g.
|
|
52
|
+
* `callTool<{ input: string; space_id: string }>('search', { input, space_id })`.
|
|
53
|
+
* New endpoints need no change to this class.
|
|
54
|
+
*/
|
|
55
|
+
export declare class CueMcp {
|
|
56
|
+
private readonly _auth;
|
|
57
|
+
private readonly _gatewayUrl;
|
|
58
|
+
constructor(_auth: CueAuth, _gatewayUrl: string);
|
|
59
|
+
callTool<TParams extends Record<string, unknown> = Record<string, unknown>, TResult = McpContext>(tool: string, params: TParams, options?: McpCallOptions): Promise<TResult>;
|
|
60
|
+
}
|
|
61
|
+
export {};
|