@arke-institute/sdk 0.1.1 → 0.1.3

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 +591 -0
  2. package/dist/content/index.cjs.map +1 -0
  3. package/dist/content/index.d.cts +516 -0
  4. package/dist/content/index.d.ts +516 -0
  5. package/dist/content/index.js +558 -0
  6. package/dist/content/index.js.map +1 -0
  7. package/dist/edit/index.cjs +1503 -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 +1447 -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-CCyp5KCg.d.ts → errors-BTe8GKRQ.d.ts} +3 -0
  15. package/dist/errors-CT7yzKkU.d.cts +874 -0
  16. package/dist/errors-CT7yzKkU.d.ts +874 -0
  17. package/dist/graph/index.cjs +427 -0
  18. package/dist/graph/index.cjs.map +1 -0
  19. package/dist/graph/index.d.cts +485 -0
  20. package/dist/graph/index.d.ts +485 -0
  21. package/dist/graph/index.js +396 -0
  22. package/dist/graph/index.js.map +1 -0
  23. package/dist/index.cjs +2726 -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 +2708 -14
  28. package/dist/index.js.map +1 -1
  29. package/dist/query/index.cjs +356 -0
  30. package/dist/query/index.cjs.map +1 -0
  31. package/dist/query/index.d.cts +636 -0
  32. package/dist/query/index.d.ts +636 -0
  33. package/dist/query/index.js +328 -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,328 @@
1
+ // src/query/errors.ts
2
+ var QueryError = class extends Error {
3
+ constructor(message, code = "UNKNOWN_ERROR", details) {
4
+ super(message);
5
+ this.code = code;
6
+ this.details = details;
7
+ this.name = "QueryError";
8
+ }
9
+ };
10
+
11
+ // src/query/client.ts
12
+ var QueryClient = class {
13
+ constructor(config) {
14
+ this.baseUrl = config.gatewayUrl.replace(/\/$/, "");
15
+ this.fetchImpl = config.fetchImpl ?? fetch;
16
+ }
17
+ // ---------------------------------------------------------------------------
18
+ // Request helpers
19
+ // ---------------------------------------------------------------------------
20
+ buildUrl(path, query) {
21
+ const url = new URL(`${this.baseUrl}${path}`);
22
+ if (query) {
23
+ Object.entries(query).forEach(([key, value]) => {
24
+ if (value !== void 0 && value !== null) {
25
+ url.searchParams.set(key, String(value));
26
+ }
27
+ });
28
+ }
29
+ return url.toString();
30
+ }
31
+ async request(path, options = {}) {
32
+ const url = this.buildUrl(path, options.query);
33
+ const headers = new Headers({ "Content-Type": "application/json" });
34
+ if (options.headers) {
35
+ Object.entries(options.headers).forEach(([k, v]) => {
36
+ if (v !== void 0) headers.set(k, v);
37
+ });
38
+ }
39
+ const response = await this.fetchImpl(url, { ...options, headers });
40
+ if (response.ok) {
41
+ const contentType = response.headers.get("content-type") || "";
42
+ if (contentType.includes("application/json")) {
43
+ return await response.json();
44
+ }
45
+ return await response.text();
46
+ }
47
+ let body;
48
+ const text = await response.text();
49
+ try {
50
+ body = JSON.parse(text);
51
+ } catch {
52
+ body = text;
53
+ }
54
+ const message = body?.error && typeof body.error === "string" ? body.error : body?.message && typeof body.message === "string" ? body.message : `Request failed with status ${response.status}`;
55
+ throw new QueryError(message, "HTTP_ERROR", {
56
+ status: response.status,
57
+ body
58
+ });
59
+ }
60
+ // ---------------------------------------------------------------------------
61
+ // Query methods
62
+ // ---------------------------------------------------------------------------
63
+ /**
64
+ * Execute a path query against the knowledge graph.
65
+ *
66
+ * @param pathQuery - The path query string (e.g., '"alice austen" -[*]{,4}-> type:person')
67
+ * @param options - Query options (k, k_explore, lineage, enrich, etc.)
68
+ * @returns Query results with entities, paths, and metadata
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * // Simple semantic search
73
+ * const results = await query.path('"Washington" type:person');
74
+ *
75
+ * // Multi-hop traversal
76
+ * const results = await query.path('"alice austen" -[*]{,4}-> type:person ~ "photographer"');
77
+ *
78
+ * // With lineage filtering (collection scope)
79
+ * const results = await query.path('"letters" type:document', {
80
+ * lineage: { sourcePi: 'arke:my_collection', direction: 'descendants' },
81
+ * k: 10,
82
+ * });
83
+ * ```
84
+ */
85
+ async path(pathQuery, options = {}) {
86
+ return this.request("/query/path", {
87
+ method: "POST",
88
+ body: JSON.stringify({
89
+ path: pathQuery,
90
+ ...options
91
+ })
92
+ });
93
+ }
94
+ /**
95
+ * Execute a natural language query.
96
+ *
97
+ * The query is translated to a path query using an LLM, then executed.
98
+ *
99
+ * @param question - Natural language question
100
+ * @param options - Query options including custom_instructions for the LLM
101
+ * @returns Query results with translation info
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const results = await query.natural('Find photographers connected to Alice Austen');
106
+ * console.log('Generated query:', results.translation.path);
107
+ * console.log('Explanation:', results.translation.explanation);
108
+ * ```
109
+ */
110
+ async natural(question, options = {}) {
111
+ const { custom_instructions, ...queryOptions } = options;
112
+ return this.request("/query/natural", {
113
+ method: "POST",
114
+ body: JSON.stringify({
115
+ query: question,
116
+ custom_instructions,
117
+ ...queryOptions
118
+ })
119
+ });
120
+ }
121
+ /**
122
+ * Translate a natural language question to a path query without executing it.
123
+ *
124
+ * Useful for understanding how questions are translated or for manual execution later.
125
+ *
126
+ * @param question - Natural language question
127
+ * @param customInstructions - Optional additional instructions for the LLM
128
+ * @returns Translation result with path query and explanation
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const result = await query.translate('Who wrote letters from Philadelphia?');
133
+ * console.log('Path query:', result.path);
134
+ * // '"letters" <-[authored, wrote]- type:person -[located]-> "Philadelphia"'
135
+ * ```
136
+ */
137
+ async translate(question, customInstructions) {
138
+ return this.request("/query/translate", {
139
+ method: "POST",
140
+ body: JSON.stringify({
141
+ query: question,
142
+ custom_instructions: customInstructions
143
+ })
144
+ });
145
+ }
146
+ /**
147
+ * Parse and validate a path query without executing it.
148
+ *
149
+ * Returns the AST (Abstract Syntax Tree) if valid, or throws an error.
150
+ *
151
+ * @param pathQuery - The path query to parse
152
+ * @returns Parsed AST
153
+ * @throws QueryError if the query has syntax errors
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * try {
158
+ * const result = await query.parse('"test" -[*]-> type:person');
159
+ * console.log('Valid query, AST:', result.ast);
160
+ * } catch (err) {
161
+ * console.error('Invalid query:', err.message);
162
+ * }
163
+ * ```
164
+ */
165
+ async parse(pathQuery) {
166
+ const url = this.buildUrl("/query/parse", { path: pathQuery });
167
+ const response = await this.fetchImpl(url, {
168
+ method: "GET",
169
+ headers: { "Content-Type": "application/json" }
170
+ });
171
+ const body = await response.json();
172
+ if ("error" in body && body.error === "Parse error") {
173
+ throw new QueryError(
174
+ body.message,
175
+ "PARSE_ERROR",
176
+ { position: body.position }
177
+ );
178
+ }
179
+ if (!response.ok) {
180
+ throw new QueryError(
181
+ body.error || `Request failed with status ${response.status}`,
182
+ "HTTP_ERROR",
183
+ { status: response.status, body }
184
+ );
185
+ }
186
+ return body;
187
+ }
188
+ /**
189
+ * Get the path query syntax documentation.
190
+ *
191
+ * Returns comprehensive documentation including entry points, edge traversal,
192
+ * filters, examples, and constraints.
193
+ *
194
+ * @returns Syntax documentation
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * const syntax = await query.syntax();
199
+ *
200
+ * // List all entry point types
201
+ * syntax.entryPoints.types.forEach(ep => {
202
+ * console.log(`${ep.syntax} - ${ep.description}`);
203
+ * });
204
+ *
205
+ * // Show examples
206
+ * syntax.examples.forEach(ex => {
207
+ * console.log(`${ex.description}: ${ex.query}`);
208
+ * });
209
+ * ```
210
+ */
211
+ async syntax() {
212
+ return this.request("/query/syntax", {
213
+ method: "GET"
214
+ });
215
+ }
216
+ /**
217
+ * Check the health of the query service.
218
+ *
219
+ * @returns Health status
220
+ */
221
+ async health() {
222
+ return this.request("/query/health", { method: "GET" });
223
+ }
224
+ /**
225
+ * Direct semantic search against the vector index.
226
+ *
227
+ * This bypasses the path query syntax and directly queries Pinecone for
228
+ * semantically similar entities. Useful for:
229
+ * - Simple semantic searches without graph traversal
230
+ * - Scoped searches filtered by source_pi (collection scope)
231
+ * - Type-filtered semantic searches
232
+ *
233
+ * For graph traversal and path-based queries, use `path()` instead.
234
+ *
235
+ * @param text - Search query text
236
+ * @param options - Search options (namespace, filters, top_k)
237
+ * @returns Matching entities with similarity scores
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * // Simple semantic search
242
+ * const results = await query.semanticSearch('photographers from New York');
243
+ *
244
+ * // Scoped to a specific PI (collection)
245
+ * const scoped = await query.semanticSearch('portraits', {
246
+ * filter: { source_pi: '01K75HQQXNTDG7BBP7PS9AWYAN' },
247
+ * top_k: 20,
248
+ * });
249
+ *
250
+ * // Filter by type
251
+ * const people = await query.semanticSearch('artists', {
252
+ * filter: { type: 'person' },
253
+ * });
254
+ *
255
+ * // Search across merged entities from multiple source PIs
256
+ * const merged = await query.semanticSearch('historical documents', {
257
+ * filter: { merged_entities_source_pis: ['pi-1', 'pi-2'] },
258
+ * });
259
+ * ```
260
+ */
261
+ async semanticSearch(text, options = {}) {
262
+ let pineconeFilter;
263
+ if (options.filter) {
264
+ pineconeFilter = {};
265
+ if (options.filter.type) {
266
+ const types = Array.isArray(options.filter.type) ? options.filter.type : [options.filter.type];
267
+ pineconeFilter.type = types.length === 1 ? { $eq: types[0] } : { $in: types };
268
+ }
269
+ if (options.filter.source_pi) {
270
+ const pis = Array.isArray(options.filter.source_pi) ? options.filter.source_pi : [options.filter.source_pi];
271
+ pineconeFilter.source_pi = pis.length === 1 ? { $eq: pis[0] } : { $in: pis };
272
+ }
273
+ if (options.filter.merged_entities_source_pis) {
274
+ const pis = Array.isArray(options.filter.merged_entities_source_pis) ? options.filter.merged_entities_source_pis : [options.filter.merged_entities_source_pis];
275
+ pineconeFilter.merged_entities_source_pis = { $in: pis };
276
+ }
277
+ if (Object.keys(pineconeFilter).length === 0) {
278
+ pineconeFilter = void 0;
279
+ }
280
+ }
281
+ return this.request("/query/search/semantic", {
282
+ method: "POST",
283
+ body: JSON.stringify({
284
+ text,
285
+ namespace: options.namespace,
286
+ filter: pineconeFilter,
287
+ top_k: options.top_k
288
+ })
289
+ });
290
+ }
291
+ /**
292
+ * Search for collections by semantic similarity.
293
+ *
294
+ * Searches the dedicated collections index for fast semantic matching.
295
+ *
296
+ * @param query - Search query text
297
+ * @param options - Search options (limit, visibility filter)
298
+ * @returns Matching collections with similarity scores
299
+ *
300
+ * @example
301
+ * ```typescript
302
+ * // Search for photography-related collections
303
+ * const results = await query.searchCollections('photography');
304
+ * console.log(results.collections[0].title);
305
+ *
306
+ * // Search only public collections
307
+ * const publicResults = await query.searchCollections('history', {
308
+ * visibility: 'public',
309
+ * limit: 20,
310
+ * });
311
+ * ```
312
+ */
313
+ async searchCollections(query, options = {}) {
314
+ return this.request("/query/search/collections", {
315
+ method: "GET",
316
+ query: {
317
+ q: query,
318
+ limit: options.limit?.toString(),
319
+ visibility: options.visibility
320
+ }
321
+ });
322
+ }
323
+ };
324
+ export {
325
+ QueryClient,
326
+ QueryError
327
+ };
328
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/query/errors.ts","../../src/query/client.ts"],"sourcesContent":["/**\n * Error class for query operations\n */\nexport class QueryError extends Error {\n constructor(\n message: string,\n public code: string = 'UNKNOWN_ERROR',\n public details?: unknown\n ) {\n super(message);\n this.name = 'QueryError';\n }\n}\n","import { QueryError } from './errors';\nimport type {\n PathQueryOptions,\n NaturalQueryOptions,\n QueryResult,\n NaturalQueryResult,\n TranslateResult,\n ParseResult,\n ParseError,\n SyntaxDocumentation,\n SemanticSearchOptions,\n SemanticSearchResponse,\n CollectionSearchOptions,\n CollectionSearchResponse,\n} from './types';\n\n/**\n * Configuration for QueryClient\n */\nexport interface QueryClientConfig {\n /**\n * Gateway base URL (e.g., https://gateway.arke.institute).\n * The client will call /query/* endpoints.\n */\n gatewayUrl: string;\n /**\n * Optional custom fetch implementation (useful for testing).\n */\n fetchImpl?: typeof fetch;\n}\n\ntype JsonBody = Record<string, unknown>;\n\n/**\n * Client for querying the Arke knowledge graph.\n *\n * All query endpoints are public and do not require authentication.\n *\n * @example\n * ```typescript\n * const query = new QueryClient({\n * gatewayUrl: 'https://gateway.arke.institute',\n * });\n *\n * // Direct path query\n * const results = await query.path('\"alice austen\" -[*]{,4}-> type:person');\n *\n * // Natural language query\n * const nlResults = await query.natural('Find photographers connected to Alice Austen');\n *\n * // Get syntax documentation\n * const syntax = await query.syntax();\n * ```\n */\nexport class QueryClient {\n private baseUrl: string;\n private fetchImpl: typeof fetch;\n\n constructor(config: QueryClientConfig) {\n this.baseUrl = config.gatewayUrl.replace(/\\/$/, '');\n this.fetchImpl = config.fetchImpl ?? fetch;\n }\n\n // ---------------------------------------------------------------------------\n // Request helpers\n // ---------------------------------------------------------------------------\n\n private buildUrl(path: string, query?: Record<string, string | undefined>) {\n const url = new URL(`${this.baseUrl}${path}`);\n if (query) {\n Object.entries(query).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n });\n }\n return url.toString();\n }\n\n private async request<T>(\n path: string,\n options: RequestInit & {\n query?: Record<string, string | undefined>;\n } = {}\n ): Promise<T> {\n const url = this.buildUrl(path, options.query);\n const headers = new Headers({ 'Content-Type': 'application/json' });\n if (options.headers) {\n Object.entries(options.headers).forEach(([k, v]) => {\n if (v !== undefined) headers.set(k, v as string);\n });\n }\n\n const response = await this.fetchImpl(url, { ...options, headers });\n\n if (response.ok) {\n const contentType = response.headers.get('content-type') || '';\n if (contentType.includes('application/json')) {\n return (await response.json()) as T;\n }\n return (await response.text()) as unknown as T;\n }\n\n let body: unknown;\n const text = await response.text();\n try {\n body = JSON.parse(text);\n } catch {\n body = text;\n }\n\n const message =\n (body as JsonBody)?.error && typeof (body as JsonBody).error === 'string'\n ? ((body as JsonBody).error as string)\n : (body as JsonBody)?.message && typeof (body as JsonBody).message === 'string'\n ? ((body as JsonBody).message as string)\n : `Request failed with status ${response.status}`;\n\n throw new QueryError(message, 'HTTP_ERROR', {\n status: response.status,\n body,\n });\n }\n\n // ---------------------------------------------------------------------------\n // Query methods\n // ---------------------------------------------------------------------------\n\n /**\n * Execute a path query against the knowledge graph.\n *\n * @param pathQuery - The path query string (e.g., '\"alice austen\" -[*]{,4}-> type:person')\n * @param options - Query options (k, k_explore, lineage, enrich, etc.)\n * @returns Query results with entities, paths, and metadata\n *\n * @example\n * ```typescript\n * // Simple semantic search\n * const results = await query.path('\"Washington\" type:person');\n *\n * // Multi-hop traversal\n * const results = await query.path('\"alice austen\" -[*]{,4}-> type:person ~ \"photographer\"');\n *\n * // With lineage filtering (collection scope)\n * const results = await query.path('\"letters\" type:document', {\n * lineage: { sourcePi: 'arke:my_collection', direction: 'descendants' },\n * k: 10,\n * });\n * ```\n */\n async path(pathQuery: string, options: PathQueryOptions = {}): Promise<QueryResult> {\n return this.request<QueryResult>('/query/path', {\n method: 'POST',\n body: JSON.stringify({\n path: pathQuery,\n ...options,\n }),\n });\n }\n\n /**\n * Execute a natural language query.\n *\n * The query is translated to a path query using an LLM, then executed.\n *\n * @param question - Natural language question\n * @param options - Query options including custom_instructions for the LLM\n * @returns Query results with translation info\n *\n * @example\n * ```typescript\n * const results = await query.natural('Find photographers connected to Alice Austen');\n * console.log('Generated query:', results.translation.path);\n * console.log('Explanation:', results.translation.explanation);\n * ```\n */\n async natural(question: string, options: NaturalQueryOptions = {}): Promise<NaturalQueryResult> {\n const { custom_instructions, ...queryOptions } = options;\n return this.request<NaturalQueryResult>('/query/natural', {\n method: 'POST',\n body: JSON.stringify({\n query: question,\n custom_instructions,\n ...queryOptions,\n }),\n });\n }\n\n /**\n * Translate a natural language question to a path query without executing it.\n *\n * Useful for understanding how questions are translated or for manual execution later.\n *\n * @param question - Natural language question\n * @param customInstructions - Optional additional instructions for the LLM\n * @returns Translation result with path query and explanation\n *\n * @example\n * ```typescript\n * const result = await query.translate('Who wrote letters from Philadelphia?');\n * console.log('Path query:', result.path);\n * // '\"letters\" <-[authored, wrote]- type:person -[located]-> \"Philadelphia\"'\n * ```\n */\n async translate(question: string, customInstructions?: string): Promise<TranslateResult> {\n return this.request<TranslateResult>('/query/translate', {\n method: 'POST',\n body: JSON.stringify({\n query: question,\n custom_instructions: customInstructions,\n }),\n });\n }\n\n /**\n * Parse and validate a path query without executing it.\n *\n * Returns the AST (Abstract Syntax Tree) if valid, or throws an error.\n *\n * @param pathQuery - The path query to parse\n * @returns Parsed AST\n * @throws QueryError if the query has syntax errors\n *\n * @example\n * ```typescript\n * try {\n * const result = await query.parse('\"test\" -[*]-> type:person');\n * console.log('Valid query, AST:', result.ast);\n * } catch (err) {\n * console.error('Invalid query:', err.message);\n * }\n * ```\n */\n async parse(pathQuery: string): Promise<ParseResult> {\n const url = this.buildUrl('/query/parse', { path: pathQuery });\n const response = await this.fetchImpl(url, {\n method: 'GET',\n headers: { 'Content-Type': 'application/json' },\n });\n\n const body = await response.json() as ParseResult | ParseError;\n\n // Check if it's an error response (parse errors return 400)\n if ('error' in body && body.error === 'Parse error') {\n throw new QueryError(\n (body as ParseError).message,\n 'PARSE_ERROR',\n { position: (body as ParseError).position }\n );\n }\n\n if (!response.ok) {\n throw new QueryError(\n (body as any).error || `Request failed with status ${response.status}`,\n 'HTTP_ERROR',\n { status: response.status, body }\n );\n }\n\n return body as ParseResult;\n }\n\n /**\n * Get the path query syntax documentation.\n *\n * Returns comprehensive documentation including entry points, edge traversal,\n * filters, examples, and constraints.\n *\n * @returns Syntax documentation\n *\n * @example\n * ```typescript\n * const syntax = await query.syntax();\n *\n * // List all entry point types\n * syntax.entryPoints.types.forEach(ep => {\n * console.log(`${ep.syntax} - ${ep.description}`);\n * });\n *\n * // Show examples\n * syntax.examples.forEach(ex => {\n * console.log(`${ex.description}: ${ex.query}`);\n * });\n * ```\n */\n async syntax(): Promise<SyntaxDocumentation> {\n return this.request<SyntaxDocumentation>('/query/syntax', {\n method: 'GET',\n });\n }\n\n /**\n * Check the health of the query service.\n *\n * @returns Health status\n */\n async health(): Promise<{ status: string; service: string; version: string }> {\n return this.request('/query/health', { method: 'GET' });\n }\n\n /**\n * Direct semantic search against the vector index.\n *\n * This bypasses the path query syntax and directly queries Pinecone for\n * semantically similar entities. Useful for:\n * - Simple semantic searches without graph traversal\n * - Scoped searches filtered by source_pi (collection scope)\n * - Type-filtered semantic searches\n *\n * For graph traversal and path-based queries, use `path()` instead.\n *\n * @param text - Search query text\n * @param options - Search options (namespace, filters, top_k)\n * @returns Matching entities with similarity scores\n *\n * @example\n * ```typescript\n * // Simple semantic search\n * const results = await query.semanticSearch('photographers from New York');\n *\n * // Scoped to a specific PI (collection)\n * const scoped = await query.semanticSearch('portraits', {\n * filter: { source_pi: '01K75HQQXNTDG7BBP7PS9AWYAN' },\n * top_k: 20,\n * });\n *\n * // Filter by type\n * const people = await query.semanticSearch('artists', {\n * filter: { type: 'person' },\n * });\n *\n * // Search across merged entities from multiple source PIs\n * const merged = await query.semanticSearch('historical documents', {\n * filter: { merged_entities_source_pis: ['pi-1', 'pi-2'] },\n * });\n * ```\n */\n async semanticSearch(\n text: string,\n options: SemanticSearchOptions = {}\n ): Promise<SemanticSearchResponse> {\n // Build Pinecone-compatible filter from our typed filter\n let pineconeFilter: Record<string, unknown> | undefined;\n\n if (options.filter) {\n pineconeFilter = {};\n\n if (options.filter.type) {\n const types = Array.isArray(options.filter.type)\n ? options.filter.type\n : [options.filter.type];\n pineconeFilter.type = types.length === 1\n ? { $eq: types[0] }\n : { $in: types };\n }\n\n if (options.filter.source_pi) {\n const pis = Array.isArray(options.filter.source_pi)\n ? options.filter.source_pi\n : [options.filter.source_pi];\n pineconeFilter.source_pi = pis.length === 1\n ? { $eq: pis[0] }\n : { $in: pis };\n }\n\n if (options.filter.merged_entities_source_pis) {\n const pis = Array.isArray(options.filter.merged_entities_source_pis)\n ? options.filter.merged_entities_source_pis\n : [options.filter.merged_entities_source_pis];\n // Use $in for array field matching (any of the provided PIs)\n pineconeFilter.merged_entities_source_pis = { $in: pis };\n }\n\n // If no filters were actually set, clear the object\n if (Object.keys(pineconeFilter).length === 0) {\n pineconeFilter = undefined;\n }\n }\n\n return this.request<SemanticSearchResponse>('/query/search/semantic', {\n method: 'POST',\n body: JSON.stringify({\n text,\n namespace: options.namespace,\n filter: pineconeFilter,\n top_k: options.top_k,\n }),\n });\n }\n\n /**\n * Search for collections by semantic similarity.\n *\n * Searches the dedicated collections index for fast semantic matching.\n *\n * @param query - Search query text\n * @param options - Search options (limit, visibility filter)\n * @returns Matching collections with similarity scores\n *\n * @example\n * ```typescript\n * // Search for photography-related collections\n * const results = await query.searchCollections('photography');\n * console.log(results.collections[0].title);\n *\n * // Search only public collections\n * const publicResults = await query.searchCollections('history', {\n * visibility: 'public',\n * limit: 20,\n * });\n * ```\n */\n async searchCollections(\n query: string,\n options: CollectionSearchOptions = {}\n ): Promise<CollectionSearchResponse> {\n return this.request<CollectionSearchResponse>('/query/search/collections', {\n method: 'GET',\n query: {\n q: query,\n limit: options.limit?.toString(),\n visibility: options.visibility,\n },\n });\n }\n}\n"],"mappings":";AAGO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YACE,SACO,OAAe,iBACf,SACP;AACA,UAAM,OAAO;AAHN;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;;;AC0CO,IAAM,cAAN,MAAkB;AAAA,EAIvB,YAAY,QAA2B;AACrC,SAAK,UAAU,OAAO,WAAW,QAAQ,OAAO,EAAE;AAClD,SAAK,YAAY,OAAO,aAAa;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA,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AO,KAAK,QAAkC,6BAA6B;AAAA,MACzE,QAAQ;AAAA,MACR,OAAO;AAAA,QACL,GAAG;AAAA,QACH,OAAO,QAAQ,OAAO,SAAS;AAAA,QAC/B,YAAY,QAAQ;AAAA,MACtB;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1502,7 +1502,6 @@ var CollectionsClient = class {
1502
1502
  };
1503
1503
 
1504
1504
  // src/upload/client.ts
1505
- init_errors();
1506
1505
  function getUserIdFromToken(token) {
1507
1506
  try {
1508
1507
  const parts = token.split(".");
@@ -1587,22 +1586,12 @@ var UploadClient = class {
1587
1586
  *
1588
1587
  * Requires owner or editor role on the collection containing the parent PI.
1589
1588
  * Use this to add a folder or files to an existing collection hierarchy.
1589
+ *
1590
+ * Note: Permission checks are enforced server-side by the ingest worker.
1591
+ * The server will return 403 if the user lacks edit access to the parent PI.
1590
1592
  */
1591
1593
  async addToCollection(options) {
1592
1594
  const { files, parentPi, customPrompts, processing, onProgress, dryRun } = options;
1593
- if (!dryRun) {
1594
- const permissions = await this.collectionsClient.getPiPermissions(parentPi);
1595
- if (!permissions.canEdit) {
1596
- if (!permissions.collection) {
1597
- throw new ValidationError(
1598
- `Cannot add files: PI "${parentPi}" is not part of any collection`
1599
- );
1600
- }
1601
- throw new ValidationError(
1602
- `Cannot add files to collection "${permissions.collection.title}": you need editor or owner role (current role: ${permissions.collection.role || "none"})`
1603
- );
1604
- }
1605
- }
1606
1595
  const uploader = new ArkeUploader({
1607
1596
  gatewayUrl: this.config.gatewayUrl,
1608
1597
  authToken: this.config.authToken,