@arke-institute/sdk 0.1.1 → 0.1.2

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.
Files changed (41) hide show
  1. package/dist/content/index.cjs +506 -0
  2. package/dist/content/index.cjs.map +1 -0
  3. package/dist/content/index.d.cts +403 -0
  4. package/dist/content/index.d.ts +403 -0
  5. package/dist/content/index.js +473 -0
  6. package/dist/content/index.js.map +1 -0
  7. package/dist/edit/index.cjs +1029 -0
  8. package/dist/edit/index.cjs.map +1 -0
  9. package/dist/edit/index.d.cts +78 -0
  10. package/dist/edit/index.d.ts +78 -0
  11. package/dist/edit/index.js +983 -0
  12. package/dist/edit/index.js.map +1 -0
  13. package/dist/{errors-BrNZWPE7.d.cts → errors-3L7IiHcr.d.cts} +3 -0
  14. package/dist/errors-B82BMmRP.d.cts +343 -0
  15. package/dist/errors-B82BMmRP.d.ts +343 -0
  16. package/dist/{errors-CCyp5KCg.d.ts → errors-BTe8GKRQ.d.ts} +3 -0
  17. package/dist/graph/index.cjs +433 -0
  18. package/dist/graph/index.cjs.map +1 -0
  19. package/dist/graph/index.d.cts +456 -0
  20. package/dist/graph/index.d.ts +456 -0
  21. package/dist/graph/index.js +402 -0
  22. package/dist/graph/index.js.map +1 -0
  23. package/dist/index.cjs +2126 -14
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +5 -1
  26. package/dist/index.d.ts +5 -1
  27. package/dist/index.js +2108 -14
  28. package/dist/index.js.map +1 -1
  29. package/dist/query/index.cjs +289 -0
  30. package/dist/query/index.cjs.map +1 -0
  31. package/dist/query/index.d.cts +541 -0
  32. package/dist/query/index.d.ts +541 -0
  33. package/dist/query/index.js +261 -0
  34. package/dist/query/index.js.map +1 -0
  35. package/dist/upload/index.cjs +3 -14
  36. package/dist/upload/index.cjs.map +1 -1
  37. package/dist/upload/index.d.cts +2 -2
  38. package/dist/upload/index.d.ts +2 -2
  39. package/dist/upload/index.js +3 -14
  40. package/dist/upload/index.js.map +1 -1
  41. package/package.json +26 -1
@@ -0,0 +1,541 @@
1
+ /**
2
+ * Query package types for the Arke SDK
3
+ */
4
+ /**
5
+ * Lineage filter to scope queries to a PI hierarchy
6
+ */
7
+ interface LineageFilter {
8
+ /** The PI to start lineage resolution from */
9
+ sourcePi: string;
10
+ /** Direction to resolve the lineage */
11
+ direction: 'ancestors' | 'descendants' | 'both';
12
+ }
13
+ /**
14
+ * Options for path query execution
15
+ */
16
+ interface PathQueryOptions {
17
+ /** Number of final results to return (default: 5) */
18
+ k?: number;
19
+ /** Beam width for exploration (default: k * 3) */
20
+ k_explore?: number;
21
+ /** Scope query to PI hierarchy */
22
+ lineage?: LineageFilter;
23
+ /** Fetch content for PI and File entities (default: false) */
24
+ enrich?: boolean;
25
+ /** Max characters per enriched entity (default: 2000) */
26
+ enrich_limit?: number;
27
+ }
28
+ /**
29
+ * Options for natural language query
30
+ */
31
+ interface NaturalQueryOptions extends PathQueryOptions {
32
+ /** Additional instructions for the LLM translator */
33
+ custom_instructions?: string;
34
+ }
35
+ /**
36
+ * Enriched content from File or PI entities
37
+ */
38
+ interface EnrichedContent {
39
+ text?: string;
40
+ data?: unknown;
41
+ format?: string;
42
+ truncated?: boolean;
43
+ }
44
+ /**
45
+ * Entity returned in query results
46
+ */
47
+ interface Entity {
48
+ canonical_id: string;
49
+ code?: string;
50
+ label: string;
51
+ type: string;
52
+ properties: Record<string, unknown>;
53
+ created_by_pi?: string;
54
+ source_pis: string[];
55
+ content?: EnrichedContent;
56
+ }
57
+ /**
58
+ * A step in the traversal path
59
+ */
60
+ interface PathStep {
61
+ /** Entity canonical_id (for entity steps) */
62
+ entity?: string;
63
+ /** Human-readable label */
64
+ label?: string;
65
+ /** Entity type */
66
+ type?: string;
67
+ /** Edge predicate (for edge steps) */
68
+ edge?: string;
69
+ /** Edge direction */
70
+ direction?: 'outgoing' | 'incoming';
71
+ /** Score for this step */
72
+ score?: number;
73
+ }
74
+ /**
75
+ * A single result with entity, path, and score
76
+ */
77
+ interface QueryResultItem {
78
+ entity: Entity;
79
+ path: PathStep[];
80
+ score: number;
81
+ }
82
+ /**
83
+ * Metadata about lineage filtering
84
+ */
85
+ interface LineageMetadata {
86
+ sourcePi: string;
87
+ direction: 'ancestors' | 'descendants' | 'both';
88
+ piCount: number;
89
+ truncated: boolean;
90
+ }
91
+ /**
92
+ * Metadata about query execution
93
+ */
94
+ interface QueryMetadata {
95
+ /** The executed path query */
96
+ query: string;
97
+ /** Number of hops in the query */
98
+ hops: number;
99
+ /** Results requested */
100
+ k: number;
101
+ /** Beam width used */
102
+ k_explore: number;
103
+ /** Total candidates explored */
104
+ total_candidates_explored: number;
105
+ /** Execution time in milliseconds */
106
+ execution_time_ms: number;
107
+ /** Error code if query failed */
108
+ error?: string;
109
+ /** Error reason if query failed */
110
+ reason?: string;
111
+ /** Lineage filter metadata */
112
+ lineage?: LineageMetadata;
113
+ /** Partial path if traversal stopped early */
114
+ partial_path?: PathStep[];
115
+ /** Hop number where traversal stopped */
116
+ stopped_at_hop?: number;
117
+ }
118
+ /**
119
+ * Result from a path query
120
+ */
121
+ interface QueryResult {
122
+ results: QueryResultItem[];
123
+ metadata: QueryMetadata;
124
+ }
125
+ /**
126
+ * Translation details from NL query
127
+ */
128
+ interface TranslationInfo {
129
+ /** Generated path query */
130
+ path: string;
131
+ /** Explanation of what the query does */
132
+ explanation: string;
133
+ /** LLM tokens used */
134
+ tokens_used: number;
135
+ /** Estimated cost in USD */
136
+ cost_usd: number;
137
+ /** Number of translation attempts */
138
+ attempts?: number;
139
+ /** Validation errors encountered */
140
+ validation_errors?: Array<{
141
+ path: string;
142
+ error: string;
143
+ position?: number;
144
+ }>;
145
+ }
146
+ /**
147
+ * Result from a natural language query (includes translation info)
148
+ */
149
+ interface NaturalQueryResult extends QueryResult {
150
+ translation: TranslationInfo;
151
+ }
152
+ /**
153
+ * Result from translate-only endpoint
154
+ */
155
+ interface TranslateResult {
156
+ /** Generated path query */
157
+ path: string;
158
+ /** Explanation of what the query does */
159
+ explanation: string;
160
+ /** LLM tokens used */
161
+ tokens_used: number;
162
+ /** Estimated cost in USD */
163
+ cost_usd: number;
164
+ }
165
+ /**
166
+ * AST node types
167
+ */
168
+ type ASTNodeType = 'semantic_search' | 'exact_entity' | 'type_filter' | 'combined_filter';
169
+ /**
170
+ * Entry point AST node
171
+ */
172
+ interface EntryAST {
173
+ type: ASTNodeType;
174
+ text?: string;
175
+ id?: string;
176
+ values?: string[];
177
+ semantic?: {
178
+ text: string;
179
+ };
180
+ }
181
+ /**
182
+ * Filter AST node
183
+ */
184
+ interface FilterAST {
185
+ type: ASTNodeType;
186
+ text?: string;
187
+ id?: string;
188
+ values?: string[];
189
+ semantic?: {
190
+ text: string;
191
+ };
192
+ }
193
+ /**
194
+ * Hop AST node
195
+ */
196
+ interface HopAST {
197
+ edge: {
198
+ direction: 'outgoing' | 'incoming' | 'bidirectional';
199
+ relation: {
200
+ type: 'wildcard';
201
+ } | {
202
+ type: 'terms';
203
+ terms: string[];
204
+ };
205
+ depth?: {
206
+ min: number;
207
+ max: number;
208
+ };
209
+ };
210
+ filter: FilterAST;
211
+ }
212
+ /**
213
+ * Parsed path query AST
214
+ */
215
+ interface PathAST {
216
+ entry: EntryAST;
217
+ entry_filter?: FilterAST;
218
+ hops: HopAST[];
219
+ }
220
+ /**
221
+ * Result from parse endpoint
222
+ */
223
+ interface ParseResult {
224
+ ast: PathAST;
225
+ }
226
+ /**
227
+ * Parse error response
228
+ */
229
+ interface ParseError {
230
+ error: string;
231
+ message: string;
232
+ position?: number;
233
+ }
234
+ /**
235
+ * Entry point type documentation
236
+ */
237
+ interface EntryPointDoc {
238
+ syntax: string;
239
+ name: string;
240
+ description: string;
241
+ example: string;
242
+ supportsHops: boolean;
243
+ }
244
+ /**
245
+ * Edge type documentation
246
+ */
247
+ interface EdgeTypeDoc {
248
+ syntax: string;
249
+ description: string;
250
+ }
251
+ /**
252
+ * Variable depth syntax documentation
253
+ */
254
+ interface VariableDepthDoc {
255
+ pattern: string;
256
+ description: string;
257
+ }
258
+ /**
259
+ * Filter type documentation
260
+ */
261
+ interface FilterTypeDoc {
262
+ syntax: string;
263
+ description: string;
264
+ example?: string;
265
+ }
266
+ /**
267
+ * Parameter documentation
268
+ */
269
+ interface ParameterDoc {
270
+ name: string;
271
+ type: string;
272
+ required?: boolean;
273
+ default?: unknown;
274
+ description: string;
275
+ enum?: string[];
276
+ }
277
+ /**
278
+ * Example query documentation
279
+ */
280
+ interface ExampleDoc {
281
+ description: string;
282
+ query: string;
283
+ }
284
+ /**
285
+ * Full syntax documentation returned by /query/syntax
286
+ */
287
+ interface SyntaxDocumentation {
288
+ version: string;
289
+ description: string;
290
+ entryPoints: {
291
+ description: string;
292
+ types: EntryPointDoc[];
293
+ };
294
+ edgeTraversal: {
295
+ description: string;
296
+ types: EdgeTypeDoc[];
297
+ variableDepth: {
298
+ description: string;
299
+ syntax: VariableDepthDoc[];
300
+ };
301
+ };
302
+ filters: {
303
+ description: string;
304
+ types: FilterTypeDoc[];
305
+ };
306
+ entityTypes: string[];
307
+ parameters: {
308
+ description: string;
309
+ fields: ParameterDoc[];
310
+ lineage: {
311
+ description: string;
312
+ fields: ParameterDoc[];
313
+ };
314
+ };
315
+ examples: ExampleDoc[];
316
+ constraints: string[];
317
+ errors: Record<string, string>;
318
+ }
319
+ /**
320
+ * Options for collection search
321
+ */
322
+ interface CollectionSearchOptions {
323
+ /** Maximum number of results (default: 10, max: 50) */
324
+ limit?: number;
325
+ /** Filter by visibility ('public' or 'private') */
326
+ visibility?: 'public' | 'private';
327
+ }
328
+ /**
329
+ * A collection result from search
330
+ */
331
+ interface CollectionSearchResult {
332
+ /** Collection UUID */
333
+ id: string;
334
+ /** Semantic similarity score */
335
+ score: number;
336
+ /** Collection title */
337
+ title: string;
338
+ /** Collection slug */
339
+ slug: string;
340
+ /** Root PI of the collection */
341
+ rootPi: string;
342
+ /** Collection visibility */
343
+ visibility: 'public' | 'private';
344
+ }
345
+ /**
346
+ * Response from collection search
347
+ */
348
+ interface CollectionSearchResponse {
349
+ /** Matching collections */
350
+ collections: CollectionSearchResult[];
351
+ /** Number of results returned */
352
+ count: number;
353
+ }
354
+
355
+ /**
356
+ * Configuration for QueryClient
357
+ */
358
+ interface QueryClientConfig {
359
+ /**
360
+ * Gateway base URL (e.g., https://gateway.arke.institute).
361
+ * The client will call /query/* endpoints.
362
+ */
363
+ gatewayUrl: string;
364
+ /**
365
+ * Optional custom fetch implementation (useful for testing).
366
+ */
367
+ fetchImpl?: typeof fetch;
368
+ }
369
+ /**
370
+ * Client for querying the Arke knowledge graph.
371
+ *
372
+ * All query endpoints are public and do not require authentication.
373
+ *
374
+ * @example
375
+ * ```typescript
376
+ * const query = new QueryClient({
377
+ * gatewayUrl: 'https://gateway.arke.institute',
378
+ * });
379
+ *
380
+ * // Direct path query
381
+ * const results = await query.path('"alice austen" -[*]{,4}-> type:person');
382
+ *
383
+ * // Natural language query
384
+ * const nlResults = await query.natural('Find photographers connected to Alice Austen');
385
+ *
386
+ * // Get syntax documentation
387
+ * const syntax = await query.syntax();
388
+ * ```
389
+ */
390
+ declare class QueryClient {
391
+ private baseUrl;
392
+ private fetchImpl;
393
+ constructor(config: QueryClientConfig);
394
+ private buildUrl;
395
+ private request;
396
+ /**
397
+ * Execute a path query against the knowledge graph.
398
+ *
399
+ * @param pathQuery - The path query string (e.g., '"alice austen" -[*]{,4}-> type:person')
400
+ * @param options - Query options (k, k_explore, lineage, enrich, etc.)
401
+ * @returns Query results with entities, paths, and metadata
402
+ *
403
+ * @example
404
+ * ```typescript
405
+ * // Simple semantic search
406
+ * const results = await query.path('"Washington" type:person');
407
+ *
408
+ * // Multi-hop traversal
409
+ * const results = await query.path('"alice austen" -[*]{,4}-> type:person ~ "photographer"');
410
+ *
411
+ * // With lineage filtering (collection scope)
412
+ * const results = await query.path('"letters" type:document', {
413
+ * lineage: { sourcePi: 'arke:my_collection', direction: 'descendants' },
414
+ * k: 10,
415
+ * });
416
+ * ```
417
+ */
418
+ path(pathQuery: string, options?: PathQueryOptions): Promise<QueryResult>;
419
+ /**
420
+ * Execute a natural language query.
421
+ *
422
+ * The query is translated to a path query using an LLM, then executed.
423
+ *
424
+ * @param question - Natural language question
425
+ * @param options - Query options including custom_instructions for the LLM
426
+ * @returns Query results with translation info
427
+ *
428
+ * @example
429
+ * ```typescript
430
+ * const results = await query.natural('Find photographers connected to Alice Austen');
431
+ * console.log('Generated query:', results.translation.path);
432
+ * console.log('Explanation:', results.translation.explanation);
433
+ * ```
434
+ */
435
+ natural(question: string, options?: NaturalQueryOptions): Promise<NaturalQueryResult>;
436
+ /**
437
+ * Translate a natural language question to a path query without executing it.
438
+ *
439
+ * Useful for understanding how questions are translated or for manual execution later.
440
+ *
441
+ * @param question - Natural language question
442
+ * @param customInstructions - Optional additional instructions for the LLM
443
+ * @returns Translation result with path query and explanation
444
+ *
445
+ * @example
446
+ * ```typescript
447
+ * const result = await query.translate('Who wrote letters from Philadelphia?');
448
+ * console.log('Path query:', result.path);
449
+ * // '"letters" <-[authored, wrote]- type:person -[located]-> "Philadelphia"'
450
+ * ```
451
+ */
452
+ translate(question: string, customInstructions?: string): Promise<TranslateResult>;
453
+ /**
454
+ * Parse and validate a path query without executing it.
455
+ *
456
+ * Returns the AST (Abstract Syntax Tree) if valid, or throws an error.
457
+ *
458
+ * @param pathQuery - The path query to parse
459
+ * @returns Parsed AST
460
+ * @throws QueryError if the query has syntax errors
461
+ *
462
+ * @example
463
+ * ```typescript
464
+ * try {
465
+ * const result = await query.parse('"test" -[*]-> type:person');
466
+ * console.log('Valid query, AST:', result.ast);
467
+ * } catch (err) {
468
+ * console.error('Invalid query:', err.message);
469
+ * }
470
+ * ```
471
+ */
472
+ parse(pathQuery: string): Promise<ParseResult>;
473
+ /**
474
+ * Get the path query syntax documentation.
475
+ *
476
+ * Returns comprehensive documentation including entry points, edge traversal,
477
+ * filters, examples, and constraints.
478
+ *
479
+ * @returns Syntax documentation
480
+ *
481
+ * @example
482
+ * ```typescript
483
+ * const syntax = await query.syntax();
484
+ *
485
+ * // List all entry point types
486
+ * syntax.entryPoints.types.forEach(ep => {
487
+ * console.log(`${ep.syntax} - ${ep.description}`);
488
+ * });
489
+ *
490
+ * // Show examples
491
+ * syntax.examples.forEach(ex => {
492
+ * console.log(`${ex.description}: ${ex.query}`);
493
+ * });
494
+ * ```
495
+ */
496
+ syntax(): Promise<SyntaxDocumentation>;
497
+ /**
498
+ * Check the health of the query service.
499
+ *
500
+ * @returns Health status
501
+ */
502
+ health(): Promise<{
503
+ status: string;
504
+ service: string;
505
+ version: string;
506
+ }>;
507
+ /**
508
+ * Search for collections by semantic similarity.
509
+ *
510
+ * Searches the dedicated collections index for fast semantic matching.
511
+ *
512
+ * @param query - Search query text
513
+ * @param options - Search options (limit, visibility filter)
514
+ * @returns Matching collections with similarity scores
515
+ *
516
+ * @example
517
+ * ```typescript
518
+ * // Search for photography-related collections
519
+ * const results = await query.searchCollections('photography');
520
+ * console.log(results.collections[0].title);
521
+ *
522
+ * // Search only public collections
523
+ * const publicResults = await query.searchCollections('history', {
524
+ * visibility: 'public',
525
+ * limit: 20,
526
+ * });
527
+ * ```
528
+ */
529
+ searchCollections(query: string, options?: CollectionSearchOptions): Promise<CollectionSearchResponse>;
530
+ }
531
+
532
+ /**
533
+ * Error class for query operations
534
+ */
535
+ declare class QueryError extends Error {
536
+ code: string;
537
+ details?: unknown | undefined;
538
+ constructor(message: string, code?: string, details?: unknown | undefined);
539
+ }
540
+
541
+ export { type ASTNodeType, type CollectionSearchOptions, type CollectionSearchResponse, type CollectionSearchResult, type EdgeTypeDoc, type EnrichedContent, type Entity, type EntryAST, type EntryPointDoc, type ExampleDoc, type FilterAST, type FilterTypeDoc, type HopAST, type LineageFilter, type LineageMetadata, type NaturalQueryOptions, type NaturalQueryResult, type ParameterDoc, type ParseError, type ParseResult, type PathAST, type PathQueryOptions, type PathStep, QueryClient, type QueryClientConfig, QueryError, type QueryMetadata, type QueryResult, type QueryResultItem, type SyntaxDocumentation, type TranslateResult, type TranslationInfo, type VariableDepthDoc };