@layerum-team/rag-sdk 0.1.0

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.
@@ -0,0 +1,282 @@
1
+ type UUID = string;
2
+ type Visibility = "self" | "self_and_descendants";
3
+ type RequestMethod = "GET" | "POST" | "PATCH" | "DELETE";
4
+ type Entity = {
5
+ id: UUID;
6
+ parentId?: UUID | null;
7
+ parent_id?: UUID | null;
8
+ entityTypeId?: UUID | null;
9
+ entity_type_id?: UUID | null;
10
+ name: string;
11
+ description?: string | null;
12
+ metadata?: Record<string, unknown>;
13
+ depth?: number;
14
+ children?: Entity[];
15
+ };
16
+ type EntityType = {
17
+ id: UUID;
18
+ name: string;
19
+ label: string;
20
+ };
21
+ type DataSource = {
22
+ id: UUID;
23
+ entityId: UUID;
24
+ entity_id?: UUID;
25
+ sourceType: "file" | "url" | "text" | "api";
26
+ source_type?: "file" | "url" | "text" | "api";
27
+ displayName: string;
28
+ display_name?: string;
29
+ visibility: Visibility;
30
+ status: "pending" | "processing" | "completed" | "failed";
31
+ mimeType?: string | null;
32
+ mime_type?: string | null;
33
+ fileSize?: number | null;
34
+ file_size?: number | null;
35
+ createdAt: string;
36
+ created_at?: string;
37
+ updatedAt: string;
38
+ updated_at?: string;
39
+ };
40
+ type SourceErrorDetails = {
41
+ sourceId: UUID;
42
+ status: DataSource["status"];
43
+ latestJob: {
44
+ id: UUID;
45
+ status: "pending" | "processing" | "completed" | "failed";
46
+ error_message?: string | null;
47
+ steps_completed?: string[];
48
+ updated_at?: string;
49
+ created_at?: string;
50
+ metadata?: Record<string, unknown> | null;
51
+ };
52
+ };
53
+ type ModelDefinition = {
54
+ id: UUID;
55
+ provider: string;
56
+ provider_key: string;
57
+ display_name: string;
58
+ model_type: "llm" | "embedding" | "reranker" | "speech";
59
+ context_window?: number | null;
60
+ max_output?: number | null;
61
+ capabilities?: string[];
62
+ };
63
+ type ModelConfig = {
64
+ id: UUID;
65
+ entityId?: UUID | null;
66
+ entity_id?: UUID | null;
67
+ name: string;
68
+ };
69
+ type QueryResponse = {
70
+ answer: string;
71
+ citations: Array<{
72
+ index: number;
73
+ documentTitle: string | null;
74
+ document_title?: string | null;
75
+ chunk_id?: UUID;
76
+ document_id?: UUID;
77
+ excerpt: string;
78
+ matchScoreRaw?: number;
79
+ }>;
80
+ meta?: {
81
+ resolvedEntityIds: UUID[];
82
+ topK: number;
83
+ latencyMs: number;
84
+ tokensUsed?: number;
85
+ };
86
+ };
87
+ type LayerumClientOptions = {
88
+ apiKey: string;
89
+ /**
90
+ * @deprecated Workspace is resolved from lyr_wk_* API key.
91
+ */
92
+ workspaceId?: UUID;
93
+ baseUrl?: string;
94
+ timeoutMs?: number;
95
+ maxRetries?: number;
96
+ };
97
+ type UploadFileInput = Blob | File | Buffer | Uint8Array | ArrayBuffer;
98
+ type CreateEntityInput = {
99
+ entityTypeId: UUID;
100
+ name: string;
101
+ description?: string;
102
+ parentId?: UUID;
103
+ metadata?: Record<string, unknown>;
104
+ };
105
+ type CreateEntityTypeInput = {
106
+ name: string;
107
+ label: string;
108
+ };
109
+ type ListSourcesInput = {
110
+ entityId: UUID;
111
+ allInWorkspace?: boolean;
112
+ };
113
+ type UploadDocumentInput = {
114
+ entityId: UUID;
115
+ file: UploadFileInput;
116
+ fileName: string;
117
+ contentType?: string;
118
+ visibility?: Visibility;
119
+ modelConfigId?: UUID;
120
+ };
121
+ type UploadInitInput = {
122
+ entityId: UUID;
123
+ fileName: string;
124
+ fileSizeBytes: number;
125
+ contentType?: string;
126
+ visibility?: Visibility;
127
+ modelConfigId?: UUID;
128
+ };
129
+ type UploadInitResponse = {
130
+ uploadId: UUID;
131
+ objectKey: string;
132
+ uploadUrl: string;
133
+ method: "POST";
134
+ fields: Record<string, string>;
135
+ expiresInSeconds: number;
136
+ };
137
+ type CreateTextDocumentInput = {
138
+ entityId: UUID;
139
+ displayName: string;
140
+ rawText: string;
141
+ visibility?: Visibility;
142
+ modelConfigId?: UUID;
143
+ };
144
+ type CreateUrlDocumentInput = {
145
+ entityId: UUID;
146
+ displayName: string;
147
+ sourceUrl: string;
148
+ visibility?: Visibility;
149
+ modelConfigId?: UUID;
150
+ };
151
+ type DeleteDocumentInput = {
152
+ entityId: UUID;
153
+ sourceId: UUID;
154
+ };
155
+ type WaitUntilReadyInput = {
156
+ entityId: UUID;
157
+ sourceId: UUID;
158
+ timeoutMs?: number;
159
+ intervalMs?: number;
160
+ };
161
+ type QueryInput = {
162
+ entityId: UUID;
163
+ modelConfigId: UUID;
164
+ query: string;
165
+ topK?: number;
166
+ includeParentScopes?: boolean;
167
+ };
168
+ type ListModelDefinitionsInput = {
169
+ type?: string;
170
+ };
171
+
172
+ type HttpClientOptions = {
173
+ baseUrl: string;
174
+ apiKey: string;
175
+ timeoutMs: number;
176
+ maxRetries: number;
177
+ };
178
+ type RequestOptions = {
179
+ method?: RequestMethod;
180
+ body?: unknown;
181
+ isFormData?: boolean;
182
+ };
183
+ declare class HttpClient {
184
+ private readonly baseUrl;
185
+ private readonly apiKey;
186
+ private readonly timeoutMs;
187
+ private readonly maxRetries;
188
+ constructor(options: HttpClientOptions);
189
+ request<T>(path: string, options?: RequestOptions): Promise<T>;
190
+ }
191
+
192
+ declare class EntitiesApi {
193
+ private readonly http;
194
+ constructor(http: HttpClient);
195
+ list(parentId?: UUID): Promise<Entity[]>;
196
+ tree(): Promise<Entity[]>;
197
+ create(input: CreateEntityInput): Promise<Entity>;
198
+ remove(entityId: UUID): Promise<{
199
+ success: boolean;
200
+ }>;
201
+ }
202
+ declare class EntityTypesApi {
203
+ private readonly http;
204
+ constructor(http: HttpClient);
205
+ list(): Promise<EntityType[]>;
206
+ get(entityTypeId: UUID): Promise<EntityType>;
207
+ create(input: CreateEntityTypeInput): Promise<EntityType>;
208
+ remove(entityTypeId: UUID): Promise<{
209
+ success: boolean;
210
+ }>;
211
+ }
212
+ declare class DocumentsApi {
213
+ private readonly http;
214
+ constructor(http: HttpClient);
215
+ list(input: ListSourcesInput): Promise<DataSource[]>;
216
+ get(entityId: UUID, sourceId: UUID): Promise<DataSource>;
217
+ upload(input: UploadDocumentInput): Promise<DataSource>;
218
+ uploadInit(input: UploadInitInput): Promise<UploadInitResponse>;
219
+ uploadComplete(input: {
220
+ entityId: UUID;
221
+ uploadId: UUID;
222
+ displayName?: string;
223
+ visibility?: Visibility;
224
+ modelConfigId?: UUID;
225
+ checksum?: string;
226
+ }): Promise<DataSource>;
227
+ uploadDirect(input: UploadDocumentInput): Promise<DataSource>;
228
+ createText(input: CreateTextDocumentInput): Promise<DataSource>;
229
+ createUrl(input: CreateUrlDocumentInput): Promise<DataSource>;
230
+ remove(input: DeleteDocumentInput): Promise<{
231
+ success: boolean;
232
+ }>;
233
+ }
234
+ declare class IngestionApi {
235
+ private readonly http;
236
+ private readonly documentsApi;
237
+ constructor(http: HttpClient, documentsApi: DocumentsApi);
238
+ retry(input: {
239
+ entityId: UUID;
240
+ sourceId: UUID;
241
+ }): Promise<{
242
+ success: boolean;
243
+ queued: boolean;
244
+ dataSourceId: UUID;
245
+ }>;
246
+ error(input: {
247
+ entityId: UUID;
248
+ sourceId: UUID;
249
+ }): Promise<SourceErrorDetails>;
250
+ waitUntilReady(input: WaitUntilReadyInput): Promise<DataSource>;
251
+ }
252
+ declare class QueryApi {
253
+ private readonly http;
254
+ constructor(http: HttpClient);
255
+ run(input: QueryInput): Promise<QueryResponse>;
256
+ runDebug(input: QueryInput): Promise<QueryResponse>;
257
+ }
258
+ declare class ModelsApi {
259
+ private readonly http;
260
+ constructor(http: HttpClient);
261
+ listConfigs(): Promise<ModelConfig[]>;
262
+ listDefinitions(input?: ListModelDefinitionsInput): Promise<ModelDefinition[]>;
263
+ }
264
+ declare class LayerumClient {
265
+ readonly entities: EntitiesApi;
266
+ readonly entityTypes: EntityTypesApi;
267
+ readonly documents: DocumentsApi;
268
+ readonly ingestion: IngestionApi;
269
+ readonly query: QueryApi;
270
+ readonly models: ModelsApi;
271
+ constructor(options: LayerumClientOptions);
272
+ }
273
+
274
+ declare class LayerumApiError extends Error {
275
+ status: number;
276
+ details?: unknown;
277
+ path?: string;
278
+ method?: string;
279
+ constructor(message: string, status: number, details?: unknown, method?: string, path?: string);
280
+ }
281
+
282
+ export { type CreateEntityInput, type CreateEntityTypeInput, type CreateTextDocumentInput, type CreateUrlDocumentInput, type DataSource, type DeleteDocumentInput, type Entity, type EntityType, LayerumApiError, LayerumClient, type LayerumClientOptions, type ListModelDefinitionsInput, type ListSourcesInput, type ModelConfig, type ModelDefinition, type QueryInput, type QueryResponse, type SourceErrorDetails, type UUID, type UploadDocumentInput, type UploadFileInput, type UploadInitInput, type UploadInitResponse, type Visibility, type WaitUntilReadyInput };
@@ -0,0 +1,282 @@
1
+ type UUID = string;
2
+ type Visibility = "self" | "self_and_descendants";
3
+ type RequestMethod = "GET" | "POST" | "PATCH" | "DELETE";
4
+ type Entity = {
5
+ id: UUID;
6
+ parentId?: UUID | null;
7
+ parent_id?: UUID | null;
8
+ entityTypeId?: UUID | null;
9
+ entity_type_id?: UUID | null;
10
+ name: string;
11
+ description?: string | null;
12
+ metadata?: Record<string, unknown>;
13
+ depth?: number;
14
+ children?: Entity[];
15
+ };
16
+ type EntityType = {
17
+ id: UUID;
18
+ name: string;
19
+ label: string;
20
+ };
21
+ type DataSource = {
22
+ id: UUID;
23
+ entityId: UUID;
24
+ entity_id?: UUID;
25
+ sourceType: "file" | "url" | "text" | "api";
26
+ source_type?: "file" | "url" | "text" | "api";
27
+ displayName: string;
28
+ display_name?: string;
29
+ visibility: Visibility;
30
+ status: "pending" | "processing" | "completed" | "failed";
31
+ mimeType?: string | null;
32
+ mime_type?: string | null;
33
+ fileSize?: number | null;
34
+ file_size?: number | null;
35
+ createdAt: string;
36
+ created_at?: string;
37
+ updatedAt: string;
38
+ updated_at?: string;
39
+ };
40
+ type SourceErrorDetails = {
41
+ sourceId: UUID;
42
+ status: DataSource["status"];
43
+ latestJob: {
44
+ id: UUID;
45
+ status: "pending" | "processing" | "completed" | "failed";
46
+ error_message?: string | null;
47
+ steps_completed?: string[];
48
+ updated_at?: string;
49
+ created_at?: string;
50
+ metadata?: Record<string, unknown> | null;
51
+ };
52
+ };
53
+ type ModelDefinition = {
54
+ id: UUID;
55
+ provider: string;
56
+ provider_key: string;
57
+ display_name: string;
58
+ model_type: "llm" | "embedding" | "reranker" | "speech";
59
+ context_window?: number | null;
60
+ max_output?: number | null;
61
+ capabilities?: string[];
62
+ };
63
+ type ModelConfig = {
64
+ id: UUID;
65
+ entityId?: UUID | null;
66
+ entity_id?: UUID | null;
67
+ name: string;
68
+ };
69
+ type QueryResponse = {
70
+ answer: string;
71
+ citations: Array<{
72
+ index: number;
73
+ documentTitle: string | null;
74
+ document_title?: string | null;
75
+ chunk_id?: UUID;
76
+ document_id?: UUID;
77
+ excerpt: string;
78
+ matchScoreRaw?: number;
79
+ }>;
80
+ meta?: {
81
+ resolvedEntityIds: UUID[];
82
+ topK: number;
83
+ latencyMs: number;
84
+ tokensUsed?: number;
85
+ };
86
+ };
87
+ type LayerumClientOptions = {
88
+ apiKey: string;
89
+ /**
90
+ * @deprecated Workspace is resolved from lyr_wk_* API key.
91
+ */
92
+ workspaceId?: UUID;
93
+ baseUrl?: string;
94
+ timeoutMs?: number;
95
+ maxRetries?: number;
96
+ };
97
+ type UploadFileInput = Blob | File | Buffer | Uint8Array | ArrayBuffer;
98
+ type CreateEntityInput = {
99
+ entityTypeId: UUID;
100
+ name: string;
101
+ description?: string;
102
+ parentId?: UUID;
103
+ metadata?: Record<string, unknown>;
104
+ };
105
+ type CreateEntityTypeInput = {
106
+ name: string;
107
+ label: string;
108
+ };
109
+ type ListSourcesInput = {
110
+ entityId: UUID;
111
+ allInWorkspace?: boolean;
112
+ };
113
+ type UploadDocumentInput = {
114
+ entityId: UUID;
115
+ file: UploadFileInput;
116
+ fileName: string;
117
+ contentType?: string;
118
+ visibility?: Visibility;
119
+ modelConfigId?: UUID;
120
+ };
121
+ type UploadInitInput = {
122
+ entityId: UUID;
123
+ fileName: string;
124
+ fileSizeBytes: number;
125
+ contentType?: string;
126
+ visibility?: Visibility;
127
+ modelConfigId?: UUID;
128
+ };
129
+ type UploadInitResponse = {
130
+ uploadId: UUID;
131
+ objectKey: string;
132
+ uploadUrl: string;
133
+ method: "POST";
134
+ fields: Record<string, string>;
135
+ expiresInSeconds: number;
136
+ };
137
+ type CreateTextDocumentInput = {
138
+ entityId: UUID;
139
+ displayName: string;
140
+ rawText: string;
141
+ visibility?: Visibility;
142
+ modelConfigId?: UUID;
143
+ };
144
+ type CreateUrlDocumentInput = {
145
+ entityId: UUID;
146
+ displayName: string;
147
+ sourceUrl: string;
148
+ visibility?: Visibility;
149
+ modelConfigId?: UUID;
150
+ };
151
+ type DeleteDocumentInput = {
152
+ entityId: UUID;
153
+ sourceId: UUID;
154
+ };
155
+ type WaitUntilReadyInput = {
156
+ entityId: UUID;
157
+ sourceId: UUID;
158
+ timeoutMs?: number;
159
+ intervalMs?: number;
160
+ };
161
+ type QueryInput = {
162
+ entityId: UUID;
163
+ modelConfigId: UUID;
164
+ query: string;
165
+ topK?: number;
166
+ includeParentScopes?: boolean;
167
+ };
168
+ type ListModelDefinitionsInput = {
169
+ type?: string;
170
+ };
171
+
172
+ type HttpClientOptions = {
173
+ baseUrl: string;
174
+ apiKey: string;
175
+ timeoutMs: number;
176
+ maxRetries: number;
177
+ };
178
+ type RequestOptions = {
179
+ method?: RequestMethod;
180
+ body?: unknown;
181
+ isFormData?: boolean;
182
+ };
183
+ declare class HttpClient {
184
+ private readonly baseUrl;
185
+ private readonly apiKey;
186
+ private readonly timeoutMs;
187
+ private readonly maxRetries;
188
+ constructor(options: HttpClientOptions);
189
+ request<T>(path: string, options?: RequestOptions): Promise<T>;
190
+ }
191
+
192
+ declare class EntitiesApi {
193
+ private readonly http;
194
+ constructor(http: HttpClient);
195
+ list(parentId?: UUID): Promise<Entity[]>;
196
+ tree(): Promise<Entity[]>;
197
+ create(input: CreateEntityInput): Promise<Entity>;
198
+ remove(entityId: UUID): Promise<{
199
+ success: boolean;
200
+ }>;
201
+ }
202
+ declare class EntityTypesApi {
203
+ private readonly http;
204
+ constructor(http: HttpClient);
205
+ list(): Promise<EntityType[]>;
206
+ get(entityTypeId: UUID): Promise<EntityType>;
207
+ create(input: CreateEntityTypeInput): Promise<EntityType>;
208
+ remove(entityTypeId: UUID): Promise<{
209
+ success: boolean;
210
+ }>;
211
+ }
212
+ declare class DocumentsApi {
213
+ private readonly http;
214
+ constructor(http: HttpClient);
215
+ list(input: ListSourcesInput): Promise<DataSource[]>;
216
+ get(entityId: UUID, sourceId: UUID): Promise<DataSource>;
217
+ upload(input: UploadDocumentInput): Promise<DataSource>;
218
+ uploadInit(input: UploadInitInput): Promise<UploadInitResponse>;
219
+ uploadComplete(input: {
220
+ entityId: UUID;
221
+ uploadId: UUID;
222
+ displayName?: string;
223
+ visibility?: Visibility;
224
+ modelConfigId?: UUID;
225
+ checksum?: string;
226
+ }): Promise<DataSource>;
227
+ uploadDirect(input: UploadDocumentInput): Promise<DataSource>;
228
+ createText(input: CreateTextDocumentInput): Promise<DataSource>;
229
+ createUrl(input: CreateUrlDocumentInput): Promise<DataSource>;
230
+ remove(input: DeleteDocumentInput): Promise<{
231
+ success: boolean;
232
+ }>;
233
+ }
234
+ declare class IngestionApi {
235
+ private readonly http;
236
+ private readonly documentsApi;
237
+ constructor(http: HttpClient, documentsApi: DocumentsApi);
238
+ retry(input: {
239
+ entityId: UUID;
240
+ sourceId: UUID;
241
+ }): Promise<{
242
+ success: boolean;
243
+ queued: boolean;
244
+ dataSourceId: UUID;
245
+ }>;
246
+ error(input: {
247
+ entityId: UUID;
248
+ sourceId: UUID;
249
+ }): Promise<SourceErrorDetails>;
250
+ waitUntilReady(input: WaitUntilReadyInput): Promise<DataSource>;
251
+ }
252
+ declare class QueryApi {
253
+ private readonly http;
254
+ constructor(http: HttpClient);
255
+ run(input: QueryInput): Promise<QueryResponse>;
256
+ runDebug(input: QueryInput): Promise<QueryResponse>;
257
+ }
258
+ declare class ModelsApi {
259
+ private readonly http;
260
+ constructor(http: HttpClient);
261
+ listConfigs(): Promise<ModelConfig[]>;
262
+ listDefinitions(input?: ListModelDefinitionsInput): Promise<ModelDefinition[]>;
263
+ }
264
+ declare class LayerumClient {
265
+ readonly entities: EntitiesApi;
266
+ readonly entityTypes: EntityTypesApi;
267
+ readonly documents: DocumentsApi;
268
+ readonly ingestion: IngestionApi;
269
+ readonly query: QueryApi;
270
+ readonly models: ModelsApi;
271
+ constructor(options: LayerumClientOptions);
272
+ }
273
+
274
+ declare class LayerumApiError extends Error {
275
+ status: number;
276
+ details?: unknown;
277
+ path?: string;
278
+ method?: string;
279
+ constructor(message: string, status: number, details?: unknown, method?: string, path?: string);
280
+ }
281
+
282
+ export { type CreateEntityInput, type CreateEntityTypeInput, type CreateTextDocumentInput, type CreateUrlDocumentInput, type DataSource, type DeleteDocumentInput, type Entity, type EntityType, LayerumApiError, LayerumClient, type LayerumClientOptions, type ListModelDefinitionsInput, type ListSourcesInput, type ModelConfig, type ModelDefinition, type QueryInput, type QueryResponse, type SourceErrorDetails, type UUID, type UploadDocumentInput, type UploadFileInput, type UploadInitInput, type UploadInitResponse, type Visibility, type WaitUntilReadyInput };