@arke-institute/sdk 0.1.3 → 2.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.
Files changed (66) hide show
  1. package/README.md +222 -176
  2. package/dist/crypto-CQnwqWQn.d.ts +459 -0
  3. package/dist/crypto-iYgzUi77.d.cts +459 -0
  4. package/dist/generated/index.cjs +19 -0
  5. package/dist/generated/index.cjs.map +1 -0
  6. package/dist/generated/index.d.cts +6545 -0
  7. package/dist/generated/index.d.ts +6545 -0
  8. package/dist/generated/index.js +1 -0
  9. package/dist/generated/index.js.map +1 -0
  10. package/dist/index.cjs +725 -4248
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +62 -7
  13. package/dist/index.d.ts +62 -7
  14. package/dist/index.js +706 -4221
  15. package/dist/index.js.map +1 -1
  16. package/dist/operations/index.cjs +806 -0
  17. package/dist/operations/index.cjs.map +1 -0
  18. package/dist/operations/index.d.cts +157 -0
  19. package/dist/operations/index.d.ts +157 -0
  20. package/dist/operations/index.js +759 -0
  21. package/dist/operations/index.js.map +1 -0
  22. package/openapi/spec.json +8648 -0
  23. package/openapi/version.json +7 -0
  24. package/package.json +51 -52
  25. package/dist/client-dAk3E64p.d.cts +0 -183
  26. package/dist/client-dAk3E64p.d.ts +0 -183
  27. package/dist/collections/index.cjs +0 -233
  28. package/dist/collections/index.cjs.map +0 -1
  29. package/dist/collections/index.d.cts +0 -9
  30. package/dist/collections/index.d.ts +0 -9
  31. package/dist/collections/index.js +0 -205
  32. package/dist/collections/index.js.map +0 -1
  33. package/dist/content/index.cjs +0 -591
  34. package/dist/content/index.cjs.map +0 -1
  35. package/dist/content/index.d.cts +0 -516
  36. package/dist/content/index.d.ts +0 -516
  37. package/dist/content/index.js +0 -558
  38. package/dist/content/index.js.map +0 -1
  39. package/dist/edit/index.cjs +0 -1503
  40. package/dist/edit/index.cjs.map +0 -1
  41. package/dist/edit/index.d.cts +0 -78
  42. package/dist/edit/index.d.ts +0 -78
  43. package/dist/edit/index.js +0 -1447
  44. package/dist/edit/index.js.map +0 -1
  45. package/dist/errors-3L7IiHcr.d.cts +0 -480
  46. package/dist/errors-BTe8GKRQ.d.ts +0 -480
  47. package/dist/errors-CT7yzKkU.d.cts +0 -874
  48. package/dist/errors-CT7yzKkU.d.ts +0 -874
  49. package/dist/graph/index.cjs +0 -427
  50. package/dist/graph/index.cjs.map +0 -1
  51. package/dist/graph/index.d.cts +0 -485
  52. package/dist/graph/index.d.ts +0 -485
  53. package/dist/graph/index.js +0 -396
  54. package/dist/graph/index.js.map +0 -1
  55. package/dist/query/index.cjs +0 -356
  56. package/dist/query/index.cjs.map +0 -1
  57. package/dist/query/index.d.cts +0 -636
  58. package/dist/query/index.d.ts +0 -636
  59. package/dist/query/index.js +0 -328
  60. package/dist/query/index.js.map +0 -1
  61. package/dist/upload/index.cjs +0 -1634
  62. package/dist/upload/index.cjs.map +0 -1
  63. package/dist/upload/index.d.cts +0 -150
  64. package/dist/upload/index.d.ts +0 -150
  65. package/dist/upload/index.js +0 -1597
  66. package/dist/upload/index.js.map +0 -1
package/README.md CHANGED
@@ -1,258 +1,304 @@
1
- # Arke SDK
1
+ # @arke-institute/sdk
2
2
 
3
- TypeScript SDK for building applications on the Arke platform.
3
+ TypeScript SDK for the Arke API - auto-generated from OpenAPI spec.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @arke/sdk
8
+ npm install @arke-institute/sdk
9
9
  ```
10
10
 
11
11
  ## Quick Start
12
12
 
13
13
  ```typescript
14
- import { createClient } from '@arke/sdk';
14
+ import { ArkeClient } from '@arke-institute/sdk';
15
15
 
16
- const arke = createClient({
16
+ const arke = new ArkeClient({
17
17
  authToken: 'your-jwt-token',
18
18
  });
19
19
 
20
- // Create a collection
21
- const collection = await arke.collections.create({
22
- title: 'My Archive',
23
- slug: 'my-archive',
24
- });
25
-
26
- // Upload files to create a new collection
27
- const result = await arke.upload.createCollection({
28
- files: './photos',
29
- collectionMetadata: {
30
- title: 'Photo Archive',
31
- slug: 'photos',
20
+ // Create an entity
21
+ const { data, error } = await arke.api.POST('/entities', {
22
+ body: {
23
+ collection_id: '01ABC...',
24
+ type: 'document',
25
+ properties: { title: 'My Document' },
32
26
  },
33
27
  });
34
28
 
35
- // Query the knowledge graph
36
- const results = await arke.query.natural(
37
- 'Who are the people in photographs from Hawaii?'
38
- );
29
+ if (error) {
30
+ console.error('Failed:', error);
31
+ } else {
32
+ console.log('Created:', data.id);
33
+ }
39
34
  ```
40
35
 
41
- ## Packages
36
+ ## Configuration
42
37
 
43
- The SDK contains five packages:
38
+ ```typescript
39
+ const arke = new ArkeClient({
40
+ // Base URL (default: 'https://arke-v1.arke.institute')
41
+ baseUrl: 'https://arke-v1.arke.institute',
44
42
 
45
- | Package | Purpose | Auth Required |
46
- |---------|---------|---------------|
47
- | **collections** | Create/manage collections, members, invitations | Yes |
48
- | **upload** | Upload files, create/add to collections | Yes |
49
- | **edit** | Edit entities, trigger AI regeneration | Yes |
50
- | **query** | Search and traverse the knowledge graph | No (public) |
51
- | **content** | Read entities, download content | No (public) |
43
+ // JWT or API key
44
+ authToken: 'your-token',
52
45
 
53
- ### Package Dependency Graph
46
+ // Network: 'main' or 'test' (default: 'main')
47
+ network: 'test',
54
48
 
55
- ```
56
- collections (foundational)
57
-
58
-
59
- ┌────┴────┐
60
- │ │
61
- upload edit
62
-
63
- query (independent)
64
- content (independent)
49
+ // Custom headers
50
+ headers: {
51
+ 'X-Custom-Header': 'value',
52
+ },
53
+ });
65
54
  ```
66
55
 
67
- ## Package Details
56
+ ## API Access
68
57
 
69
- ### collections
58
+ All API calls are made through the `arke.api` property, which provides full type safety:
70
59
 
71
60
  ```typescript
72
- // Create collection
73
- await arke.collections.create({ title, slug, description, visibility });
61
+ // GET request
62
+ const { data } = await arke.api.GET('/entities/{id}', {
63
+ params: { path: { id: '01XYZ...' } },
64
+ });
74
65
 
75
- // List collections
76
- const collections = await arke.collections.list({ page: 1 });
66
+ // POST request
67
+ const { data } = await arke.api.POST('/entities', {
68
+ body: { collection_id: '...', type: 'document', properties: {} },
69
+ });
77
70
 
78
- // Manage members
79
- await arke.members.updateRole(collectionId, userId, 'editor');
71
+ // PUT request (update)
72
+ const { data } = await arke.api.PUT('/entities/{id}', {
73
+ params: { path: { id: '01XYZ...' } },
74
+ body: { expect_tip: 'bafyrei...', properties_merge: { status: 'active' } },
75
+ });
80
76
 
81
- // Invitations
82
- await arke.invitations.create(collectionId, { email, role: 'editor' });
83
- await arke.invitations.accept(invitationId);
77
+ // DELETE request
78
+ await arke.api.DELETE('/relationships', {
79
+ body: { source_id: '...', target_id: '...', predicate: 'contains' },
80
+ });
84
81
  ```
85
82
 
86
- ### upload
83
+ ## Available Endpoints
84
+
85
+ The SDK provides typed access to all Arke API endpoints:
86
+
87
+ | Endpoint Group | Description |
88
+ |----------------|-------------|
89
+ | `/auth/*` | Authentication and registration |
90
+ | `/users/*` | User profile and API keys |
91
+ | `/collections/*` | Collection CRUD, roles, members |
92
+ | `/entities/*` | Entity CRUD |
93
+ | `/relationships` | Relationship management |
94
+ | `/files/*` | File storage and downloads |
95
+ | `/folders/*` | Folder hierarchy |
96
+ | `/versions/*` | Version history |
97
+ | `/agents/*` | Agent management |
98
+ | `/permissions/*` | Permission introspection |
99
+
100
+ ## Error Handling
87
101
 
88
102
  ```typescript
89
- // Create new collection from files (anyone authenticated)
90
- await arke.upload.createCollection({
91
- files: './photos',
92
- collectionMetadata: { title: 'My Archive', slug: 'my-archive' },
103
+ import {
104
+ ArkeError,
105
+ CASConflictError,
106
+ NotFoundError,
107
+ parseApiError
108
+ } from '@arke-institute/sdk';
109
+
110
+ const { data, error, response } = await arke.api.GET('/entities/{id}', {
111
+ params: { path: { id: 'invalid-id' } },
93
112
  });
94
113
 
95
- // Add to existing collection (requires membership)
96
- await arke.upload.addToCollection({
97
- files: './more-photos',
98
- parentPi: 'pi:existing-root',
99
- });
114
+ if (error) {
115
+ // Parse into typed error
116
+ const arkeError = parseApiError(response.status, error);
117
+
118
+ if (arkeError instanceof CASConflictError) {
119
+ console.log('Concurrent modification - expected:', arkeError.expectedTip);
120
+ } else if (arkeError instanceof NotFoundError) {
121
+ console.log('Entity not found');
122
+ }
123
+ }
100
124
  ```
101
125
 
102
- ### edit
126
+ ## Authentication Management
103
127
 
104
128
  ```typescript
105
- // Edit entity
106
- const session = await arke.edit.createSession('pi:abc123');
107
- session.setPrompt('Update the description');
108
- const result = await session.submit();
129
+ const arke = new ArkeClient();
130
+
131
+ // Set token after login
132
+ arke.setAuthToken('new-token');
133
+
134
+ // Check auth status
135
+ if (arke.isAuthenticated) {
136
+ // Make authenticated requests
137
+ }
109
138
 
110
- // Trigger AI regeneration
111
- await arke.edit.regenerate('pi:abc123');
139
+ // Clear token on logout
140
+ arke.clearAuthToken();
112
141
  ```
113
142
 
114
- ### query
143
+ ## Test Network
144
+
145
+ Use the test network for development (uses 'II' prefixed IDs):
115
146
 
116
147
  ```typescript
117
- // Direct path query (requires knowing syntax)
118
- await arke.query.path('"Hawaii" -[depicts]-> type:person');
148
+ const arke = new ArkeClient({
149
+ authToken: 'your-token',
150
+ network: 'test',
151
+ });
152
+ ```
153
+
154
+ ## Folder Upload
155
+
156
+ Upload entire folder structures with automatic CID computation and relationship linking:
157
+
158
+ ### Node.js
159
+
160
+ ```typescript
161
+ import { ArkeClient } from '@arke-institute/sdk';
162
+ import { uploadTree, scanDirectory } from '@arke-institute/sdk/operations';
163
+
164
+ const arke = new ArkeClient({ authToken: 'your-token' });
119
165
 
120
- // Natural language (LLM translates to path query)
121
- await arke.query.natural('Who photographed Pearl Harbor?');
166
+ // Scan a local directory
167
+ const tree = await scanDirectory('/path/to/my-folder');
122
168
 
123
- // Collection search
124
- await arke.query.searchCollection(collectionId, 'family portraits');
169
+ // Upload to a new collection
170
+ const result = await uploadTree(arke, tree, {
171
+ target: {
172
+ createCollection: {
173
+ label: 'My Upload',
174
+ description: 'Uploaded folder contents',
175
+ },
176
+ },
177
+ onProgress: (p) => {
178
+ console.log(`${p.phase}: ${p.completedFiles}/${p.totalFiles} files`);
179
+ },
180
+ });
181
+
182
+ console.log('Collection:', result.collection.id);
183
+ console.log('Files:', result.files.length);
184
+ console.log('Folders:', result.folders.length);
125
185
  ```
126
186
 
127
- ### content
187
+ ### Browser (Drag & Drop)
128
188
 
129
189
  ```typescript
130
- // Get entity
131
- const entity = await arke.content.get('pi:abc123');
190
+ import { uploadTree, scanFileSystemEntries } from '@arke-institute/sdk/operations';
191
+
192
+ dropzone.ondrop = async (e) => {
193
+ e.preventDefault();
194
+ const entries = Array.from(e.dataTransfer.items)
195
+ .map(item => item.webkitGetAsEntry())
196
+ .filter(Boolean);
197
+
198
+ const tree = await scanFileSystemEntries(entries);
199
+ const result = await uploadTree(client, tree, {
200
+ target: { collectionId: 'existing-collection-id' },
201
+ });
202
+ };
203
+ ```
132
204
 
133
- // Download content
134
- const blob = await arke.content.download('pi:abc123');
205
+ ### Browser (File Input)
135
206
 
136
- // Get version history
137
- const versions = await arke.content.versions('pi:abc123');
207
+ ```typescript
208
+ import { uploadTree, scanFileList } from '@arke-institute/sdk/operations';
209
+
210
+ // <input type="file" webkitdirectory multiple />
211
+ input.onchange = async (e) => {
212
+ const tree = await scanFileList(e.target.files);
213
+ const result = await uploadTree(client, tree, {
214
+ target: { parentId: 'existing-folder-id', collectionId: 'collection-id' },
215
+ });
216
+ };
138
217
  ```
139
218
 
140
- ## Documentation
219
+ ### Upload Options
141
220
 
142
- - [Architecture Overview](./ARCHITECTURE.md)
143
- - [collections package](./packages/collections/PLAN.md)
144
- - [upload package](./packages/upload/PLAN.md)
145
- - [edit package](./packages/edit/PLAN.md)
146
- - [query package](./packages/query/PLAN.md)
147
- - [content package](./packages/content/PLAN.md)
221
+ ```typescript
222
+ const result = await uploadTree(client, tree, {
223
+ target: {
224
+ // Option 1: Create new collection
225
+ createCollection: { label: 'New Collection' },
148
226
 
149
- ## Project Structure
227
+ // Option 2: Upload to existing collection root
228
+ collectionId: '01ABC...',
150
229
 
230
+ // Option 3: Upload to existing folder
231
+ collectionId: '01ABC...',
232
+ parentId: '01XYZ...',
233
+ },
234
+
235
+ // Progress tracking
236
+ onProgress: (p) => console.log(p.phase, p.completedFiles),
237
+
238
+ // Parallel uploads (default: 5)
239
+ concurrency: 10,
240
+
241
+ // Continue if some files fail
242
+ continueOnError: true,
243
+ });
151
244
  ```
152
- arke-sdk/
153
- ├── src/
154
- │ ├── index.ts # Main entry, createClient()
155
- │ ├── client.ts # Base HTTP client
156
- │ └── types.ts # Shared types
157
- ├── packages/
158
- │ ├── collections/
159
- │ │ ├── index.ts # Package entry
160
- │ │ ├── collections.ts # Collection CRUD
161
- │ │ ├── members.ts # Membership operations
162
- │ │ ├── invitations.ts # Invitation operations
163
- │ │ └── types.ts
164
- │ ├── upload/
165
- │ │ ├── index.ts
166
- │ │ ├── uploader.ts # Main uploader class
167
- │ │ ├── create-collection.ts
168
- │ │ ├── add-to-collection.ts
169
- │ │ └── types.ts
170
- │ ├── edit/
171
- │ │ ├── index.ts
172
- │ │ ├── session.ts # Edit session
173
- │ │ ├── diff.ts # Diff engine
174
- │ │ └── types.ts
175
- │ ├── query/
176
- │ │ ├── index.ts
177
- │ │ ├── path-query.ts # Direct path queries
178
- │ │ ├── natural-query.ts # NL queries
179
- │ │ ├── collection-search.ts
180
- │ │ └── types.ts
181
- │ └── content/
182
- │ ├── index.ts
183
- │ ├── entities.ts # Entity operations
184
- │ ├── download.ts # Content download
185
- │ └── types.ts
186
- ├── package.json
187
- ├── tsconfig.json
188
- └── README.md
245
+
246
+ ### CID Utilities
247
+
248
+ ```typescript
249
+ import { computeCid, verifyCid } from '@arke-institute/sdk/operations';
250
+
251
+ // Compute CIDv1 for any content
252
+ const cid = await computeCid(new TextEncoder().encode('hello'));
253
+ // => "bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e"
254
+
255
+ // Verify content matches CID
256
+ const isValid = await verifyCid(content, expectedCid);
189
257
  ```
190
258
 
191
- ## Distribution
259
+ ## Development
192
260
 
193
- The SDK is published to npm as `@arke/sdk`.
261
+ ### Regenerate Types
194
262
 
195
- ### Building
263
+ When the API changes, regenerate the types:
196
264
 
197
265
  ```bash
198
- npm run build
266
+ # From production API
267
+ npm run generate
268
+
269
+ # From local dev server
270
+ npm run generate:local
199
271
  ```
200
272
 
201
- ### Publishing
273
+ ### Build
202
274
 
203
275
  ```bash
204
- npm version patch|minor|major
205
- npm publish
276
+ npm run build
206
277
  ```
207
278
 
208
- ### Imports
279
+ ### Test
209
280
 
210
- Users can import the full SDK or specific packages:
211
-
212
- ```typescript
213
- // Full SDK
214
- import { createClient } from '@arke/sdk';
215
- const arke = createClient({ authToken });
216
- arke.collections.create(...);
217
-
218
- // Specific packages (tree-shakeable)
219
- import { CollectionsClient } from '@arke/sdk/collections';
220
- import { UploadClient } from '@arke/sdk/upload';
281
+ ```bash
282
+ npm test
221
283
  ```
222
284
 
223
- ## Implementation Order
285
+ ### Publish
224
286
 
225
- ### Backend (Workers)
226
- 1. GraphDB Gateway - Add `is_collection_root` field + update endpoint
227
- 2. Query Links - Add filter support for `is_collection_root`
228
- 3. **Collections Worker** (new) - Manages collections in Supabase
229
-
230
- ### SDK (This Repo)
231
- 4. collections package
232
- 5. content package
233
- 6. upload package (refactor existing)
234
- 7. edit package (refactor existing)
235
- 8. query package
287
+ ```bash
288
+ # Dry run
289
+ npm run publish-all:dry
236
290
 
237
- ### Consumers
238
- 9. CLI (`arke-cli/`)
239
- 10. Web Frontend
291
+ # Actual publish
292
+ npm run publish-all
293
+ ```
240
294
 
241
- ## Backend Architecture
295
+ ## Future Operations
242
296
 
243
- The SDK calls the Arke Gateway (`api.arke.institute`), which routes to workers:
297
+ The SDK includes placeholder modules for additional high-level operations:
244
298
 
245
- | Route | Worker |
246
- |-------|--------|
247
- | `/collections/*`, `/me/*`, `/invitations/*` | Collections Worker |
248
- | `/ingest/*` | Ingest Worker |
249
- | `/api/*` | IPFS Wrapper |
250
- | `/reprocess/*` | Reprocess API |
251
- | `/query/*` | Query Links |
252
- | `/translate/*` | Query Translator |
299
+ - **BatchOperations**: Bulk entity/relationship creation
300
+ - **CryptoOperations**: Ed25519 key generation
253
301
 
254
- ## Related Repositories
302
+ ## License
255
303
 
256
- - **Collections Worker** - Backend for collection management (new)
257
- - **Arke CLI** (`arke-cli/`) - Command-line interface using this SDK
258
- - **Arke Gateway** (`arke-gateway/`) - API gateway routing
304
+ MIT