@things-factory/integration-label-studio 9.1.19

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 (152) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/EXTERNAL_DATA_SOURCING.md +484 -0
  3. package/IMPLEMENTATION_GUIDE.md +469 -0
  4. package/INTEGRATION.md +279 -0
  5. package/README.md +1014 -0
  6. package/SETUP_GUIDE.md +577 -0
  7. package/TEST_GUIDE.md +387 -0
  8. package/UI_CUSTOMIZATION.md +395 -0
  9. package/USER_SYNC_GUIDE.md +514 -0
  10. package/client/bootstrap.ts +1 -0
  11. package/client/index.ts +1 -0
  12. package/client/label-studio-label-page.ts +52 -0
  13. package/client/label-studio-project-create.ts +216 -0
  14. package/client/label-studio-project-list.ts +214 -0
  15. package/client/label-studio-wrapper.ts +294 -0
  16. package/client/route.ts +15 -0
  17. package/client/tsconfig.json +13 -0
  18. package/config/config.development.js +124 -0
  19. package/config/config.production.js +182 -0
  20. package/dist-client/bootstrap.d.ts +1 -0
  21. package/dist-client/bootstrap.js +2 -0
  22. package/dist-client/bootstrap.js.map +1 -0
  23. package/dist-client/index.d.ts +1 -0
  24. package/dist-client/index.js +2 -0
  25. package/dist-client/index.js.map +1 -0
  26. package/dist-client/label-studio-label-page.d.ts +8 -0
  27. package/dist-client/label-studio-label-page.js +54 -0
  28. package/dist-client/label-studio-label-page.js.map +1 -0
  29. package/dist-client/label-studio-project-create.d.ts +16 -0
  30. package/dist-client/label-studio-project-create.js +235 -0
  31. package/dist-client/label-studio-project-create.js.map +1 -0
  32. package/dist-client/label-studio-project-list.d.ts +16 -0
  33. package/dist-client/label-studio-project-list.js +222 -0
  34. package/dist-client/label-studio-project-list.js.map +1 -0
  35. package/dist-client/label-studio-wrapper.d.ts +57 -0
  36. package/dist-client/label-studio-wrapper.js +304 -0
  37. package/dist-client/label-studio-wrapper.js.map +1 -0
  38. package/dist-client/route.d.ts +1 -0
  39. package/dist-client/route.js +14 -0
  40. package/dist-client/route.js.map +1 -0
  41. package/dist-client/tsconfig.tsbuildinfo +1 -0
  42. package/dist-server/controller/label-studio-role-mapper.d.ts +35 -0
  43. package/dist-server/controller/label-studio-role-mapper.js +65 -0
  44. package/dist-server/controller/label-studio-role-mapper.js.map +1 -0
  45. package/dist-server/controller/user-provisioning-service.d.ts +66 -0
  46. package/dist-server/controller/user-provisioning-service.js +264 -0
  47. package/dist-server/controller/user-provisioning-service.js.map +1 -0
  48. package/dist-server/index.d.ts +7 -0
  49. package/dist-server/index.js +19 -0
  50. package/dist-server/index.js.map +1 -0
  51. package/dist-server/route/label-studio-sso.d.ts +2 -0
  52. package/dist-server/route/label-studio-sso.js +156 -0
  53. package/dist-server/route/label-studio-sso.js.map +1 -0
  54. package/dist-server/route/webhook.d.ts +65 -0
  55. package/dist-server/route/webhook.js +248 -0
  56. package/dist-server/route/webhook.js.map +1 -0
  57. package/dist-server/route.d.ts +1 -0
  58. package/dist-server/route.js +21 -0
  59. package/dist-server/route.js.map +1 -0
  60. package/dist-server/service/ai-prediction-service.d.ts +27 -0
  61. package/dist-server/service/ai-prediction-service.js +222 -0
  62. package/dist-server/service/ai-prediction-service.js.map +1 -0
  63. package/dist-server/service/dataset-labeling-integration.d.ts +44 -0
  64. package/dist-server/service/dataset-labeling-integration.js +512 -0
  65. package/dist-server/service/dataset-labeling-integration.js.map +1 -0
  66. package/dist-server/service/external-data-source-service.d.ts +78 -0
  67. package/dist-server/service/external-data-source-service.js +415 -0
  68. package/dist-server/service/external-data-source-service.js.map +1 -0
  69. package/dist-server/service/index.d.ts +12 -0
  70. package/dist-server/service/index.js +27 -0
  71. package/dist-server/service/index.js.map +1 -0
  72. package/dist-server/service/label-studio-sso-service.d.ts +38 -0
  73. package/dist-server/service/label-studio-sso-service.js +98 -0
  74. package/dist-server/service/label-studio-sso-service.js.map +1 -0
  75. package/dist-server/service/ml/ml-backend-service.d.ts +23 -0
  76. package/dist-server/service/ml/ml-backend-service.js +153 -0
  77. package/dist-server/service/ml/ml-backend-service.js.map +1 -0
  78. package/dist-server/service/prediction/prediction-management.d.ts +32 -0
  79. package/dist-server/service/prediction/prediction-management.js +299 -0
  80. package/dist-server/service/prediction/prediction-management.js.map +1 -0
  81. package/dist-server/service/project/project-management.d.ts +36 -0
  82. package/dist-server/service/project/project-management.js +309 -0
  83. package/dist-server/service/project/project-management.js.map +1 -0
  84. package/dist-server/service/task/task-management.d.ts +42 -0
  85. package/dist-server/service/task/task-management.js +372 -0
  86. package/dist-server/service/task/task-management.js.map +1 -0
  87. package/dist-server/service/user-provisioning/user-sync-mutation.d.ts +28 -0
  88. package/dist-server/service/user-provisioning/user-sync-mutation.js +111 -0
  89. package/dist-server/service/user-provisioning/user-sync-mutation.js.map +1 -0
  90. package/dist-server/service/webhook/webhook-management.d.ts +21 -0
  91. package/dist-server/service/webhook/webhook-management.js +134 -0
  92. package/dist-server/service/webhook/webhook-management.js.map +1 -0
  93. package/dist-server/tsconfig.tsbuildinfo +1 -0
  94. package/dist-server/types/dataset-labeling-types.d.ts +71 -0
  95. package/dist-server/types/dataset-labeling-types.js +259 -0
  96. package/dist-server/types/dataset-labeling-types.js.map +1 -0
  97. package/dist-server/types/label-studio-types.d.ts +128 -0
  98. package/dist-server/types/label-studio-types.js +494 -0
  99. package/dist-server/types/label-studio-types.js.map +1 -0
  100. package/dist-server/types/prediction-types.d.ts +39 -0
  101. package/dist-server/types/prediction-types.js +121 -0
  102. package/dist-server/types/prediction-types.js.map +1 -0
  103. package/dist-server/utils/annotation-exporter.d.ts +104 -0
  104. package/dist-server/utils/annotation-exporter.js +261 -0
  105. package/dist-server/utils/annotation-exporter.js.map +1 -0
  106. package/dist-server/utils/label-config-builder.d.ts +117 -0
  107. package/dist-server/utils/label-config-builder.js +286 -0
  108. package/dist-server/utils/label-config-builder.js.map +1 -0
  109. package/dist-server/utils/label-studio-api-client.d.ts +180 -0
  110. package/dist-server/utils/label-studio-api-client.js +401 -0
  111. package/dist-server/utils/label-studio-api-client.js.map +1 -0
  112. package/dist-server/utils/media-url-extractor.d.ts +45 -0
  113. package/dist-server/utils/media-url-extractor.js +152 -0
  114. package/dist-server/utils/media-url-extractor.js.map +1 -0
  115. package/dist-server/utils/task-transformer.d.ts +108 -0
  116. package/dist-server/utils/task-transformer.js +260 -0
  117. package/dist-server/utils/task-transformer.js.map +1 -0
  118. package/package.json +47 -0
  119. package/server/SERVER_STRUCTURE.md +351 -0
  120. package/server/controller/label-studio-role-mapper.ts +76 -0
  121. package/server/controller/user-provisioning-service.ts +340 -0
  122. package/server/index.ts +19 -0
  123. package/server/route/label-studio-sso.ts +194 -0
  124. package/server/route/webhook.ts +304 -0
  125. package/server/route.ts +35 -0
  126. package/server/service/ai-prediction-service.ts +239 -0
  127. package/server/service/dataset-labeling-integration.ts +590 -0
  128. package/server/service/external-data-source-service.ts +438 -0
  129. package/server/service/index.ts +24 -0
  130. package/server/service/label-studio-sso-service.ts +108 -0
  131. package/server/service/labeling-scenario-service.ts.deprecated +566 -0
  132. package/server/service/ml/ml-backend-service.ts +127 -0
  133. package/server/service/prediction/prediction-management.ts +281 -0
  134. package/server/service/project/project-management.ts +284 -0
  135. package/server/service/task/task-management.ts +363 -0
  136. package/server/service/user-provisioning/user-sync-mutation.ts +80 -0
  137. package/server/service/webhook/webhook-management.ts +109 -0
  138. package/server/tsconfig.json +11 -0
  139. package/server/types/dataset-labeling-types.ts +181 -0
  140. package/server/types/global.d.ts +23 -0
  141. package/server/types/label-studio-types.ts +346 -0
  142. package/server/types/prediction-types.ts +86 -0
  143. package/server/types/scenario-types.ts.deprecated +362 -0
  144. package/server/utils/annotation-exporter.ts +340 -0
  145. package/server/utils/label-config-builder.ts +340 -0
  146. package/server/utils/label-studio-api-client.ts +487 -0
  147. package/server/utils/media-url-extractor.ts +193 -0
  148. package/server/utils/task-transformer.ts +342 -0
  149. package/test-ai-prediction.js +268 -0
  150. package/test-dataset-integration.js +449 -0
  151. package/test-simple.js +89 -0
  152. package/things-factory.config.js +12 -0
package/TEST_GUIDE.md ADDED
@@ -0,0 +1,387 @@
1
+ # Test Guide for Label Studio Integration
2
+
3
+ This guide explains how to run the test scripts for the Label Studio integration.
4
+
5
+ ## Test Scripts Overview
6
+
7
+ The integration includes three test scripts:
8
+
9
+ 1. **test-simple.js** - Tests AI inference without Label Studio
10
+ 2. **test-ai-prediction.js** - Tests complete AI prediction flow with Label Studio
11
+ 3. **test-dataset-integration.js** - Tests full dataset-to-Label Studio integration
12
+
13
+ ## Prerequisites
14
+
15
+ ### 1. Environment Setup
16
+
17
+ Both Things Factory and Label Studio must be running on subdomain pattern:
18
+
19
+ ```bash
20
+ # Things Factory
21
+ http://app.dataset.localhost:3000
22
+
23
+ # Label Studio
24
+ http://label.dataset.localhost:8080
25
+ ```
26
+
27
+ **Note:** Modern browsers automatically resolve `*.localhost` to `127.0.0.1`, so no `/etc/hosts` modification is needed.
28
+
29
+ ### 2. Label Studio Configuration
30
+
31
+ Ensure Label Studio is configured with JWT SSO:
32
+
33
+ ```bash
34
+ # In Label Studio .env file
35
+ JWT_SSO_SECRET=your-secret-key
36
+ JWT_SSO_COOKIE_NAME=ls_auth_token
37
+ CSRF_TRUSTED_ORIGINS=http://app.dataset.localhost:3000,http://label.dataset.localhost:8080
38
+ ALLOWED_HOSTS=localhost,label.dataset.localhost,*.dataset.localhost
39
+ ```
40
+
41
+ ### 3. Get API Token
42
+
43
+ 1. Login to Label Studio: http://label.dataset.localhost:8080
44
+ 2. Navigate to Account Settings → Access Token
45
+ 3. Create new token and copy it
46
+
47
+ ## Test 1: Simple AI Inference
48
+
49
+ Tests AI detection functionality without Label Studio integration.
50
+
51
+ ### Run Test
52
+
53
+ ```bash
54
+ cd /path/to/things-factory/packages/integration-label-studio
55
+
56
+ # Run with default settings
57
+ node test-simple.js
58
+
59
+ # Or with custom GraphQL endpoint
60
+ THINGS_FACTORY_GRAPHQL=http://app.dataset.localhost:3000/graphql node test-simple.js
61
+ ```
62
+
63
+ ### Expected Output
64
+
65
+ ```
66
+ 🤖 Testing AI Object Detection
67
+
68
+ ============================================================
69
+ GraphQL: http://app.dataset.localhost:3000/graphql
70
+ Test Image: https://example.com/test.jpg
71
+ ============================================================
72
+
73
+ 📤 Sending GraphQL request...
74
+
75
+ ✅ AI Detection successful!
76
+
77
+ 🎯 Detected 3 objects:
78
+
79
+ 1. person
80
+ Confidence: 95.2%
81
+ BBox: x=100, y=150, w=200, h=300
82
+
83
+ 2. car
84
+ Confidence: 87.5%
85
+ BBox: x=300, y=200, w=250, h=180
86
+
87
+ ✨ Mock AI is working correctly!
88
+ ```
89
+
90
+ ## Test 2: AI Prediction with Label Studio
91
+
92
+ Tests the complete flow from AI inference to Label Studio prediction creation.
93
+
94
+ ### Setup
95
+
96
+ ```bash
97
+ # Set environment variables
98
+ export LABEL_STUDIO_URL=http://label.dataset.localhost:8080
99
+ export LABEL_STUDIO_API_TOKEN=your-api-token-here
100
+ export THINGS_FACTORY_GRAPHQL=http://app.dataset.localhost:3000/graphql
101
+ export TEST_PROJECT_ID=2 # Your Label Studio project ID
102
+ ```
103
+
104
+ ### Run Test
105
+
106
+ ```bash
107
+ cd /path/to/things-factory/packages/integration-label-studio
108
+
109
+ node test-ai-prediction.js
110
+ ```
111
+
112
+ ### Expected Output
113
+
114
+ ```
115
+ 🚀 Starting AI Prediction Integration Test
116
+
117
+ ============================================================
118
+
119
+ 🔍 Testing Label Studio connection...
120
+ URL: http://label.dataset.localhost:8080
121
+ ✅ Label Studio connected successfully
122
+ Found 5 projects
123
+
124
+ 🔍 Getting test task from project 2...
125
+ ✅ Found task 42
126
+ Image: http://example.com/test.jpg
127
+ Annotations: 0
128
+ Predictions: 0
129
+
130
+ 🤖 Testing AI inference...
131
+ Image: http://example.com/test.jpg
132
+ ✅ AI detected 3 objects:
133
+ 1. person (95.2%)
134
+ 2. car (87.5%)
135
+ 3. bicycle (72.3%)
136
+
137
+ 🎯 Testing prediction generation for task 42...
138
+ ✅ Prediction created successfully!
139
+ Prediction ID: 123
140
+ Objects detected: 3
141
+ Avg confidence: 85.0%
142
+
143
+ ✓ Verifying prediction in Label Studio...
144
+ ✅ Task has 1 prediction(s)
145
+ Latest prediction:
146
+ - ID: 123
147
+ - Model: yolov8-nano-v1.0
148
+ - Score: 85.0%
149
+ - Objects: 3
150
+
151
+ ============================================================
152
+ ✨ Test completed successfully!
153
+
154
+ 📝 Next steps:
155
+ 1. Open Label Studio: http://label.dataset.localhost:8080/projects/2
156
+ 2. Open task 42 to see the AI-generated prediction
157
+ 3. The prediction should appear as pre-labeled regions
158
+ ```
159
+
160
+ ## Test 3: Dataset Integration
161
+
162
+ Tests the complete integration between Things Factory Datasets and Label Studio.
163
+
164
+ ### Setup
165
+
166
+ ```bash
167
+ # Set environment variables
168
+ export THINGS_FACTORY_GRAPHQL=http://app.dataset.localhost:3000/graphql
169
+ export LABEL_STUDIO_URL=http://label.dataset.localhost:8080
170
+ export LABEL_STUDIO_PROJECT_ID=2
171
+ ```
172
+
173
+ ### Run Test
174
+
175
+ ```bash
176
+ cd /path/to/things-factory/packages/integration-label-studio
177
+
178
+ node test-dataset-integration.js
179
+ ```
180
+
181
+ ### Expected Output
182
+
183
+ ```
184
+ 🚀 Dataset-Label Studio Integration Test
185
+
186
+ ============================================================
187
+ Things Factory GraphQL: http://app.dataset.localhost:3000/graphql
188
+ Label Studio URL: http://label.dataset.localhost:8080
189
+ Label Studio Project ID: 2
190
+ ============================================================
191
+
192
+ 📊 Step 1: Querying DataSets...
193
+ ============================================================
194
+ ✅ Found 3 DataSet(s)
195
+
196
+ Available DataSets:
197
+ 1. Product Images (ds-001)
198
+ Active: true
199
+ Description: Product catalog images
200
+
201
+ 📦 Step 2: Querying DataSamples from DataSet ds-001...
202
+ ============================================================
203
+ ✅ Found 10 DataSample(s)
204
+
205
+ DataSample details:
206
+ 1. Sample-001
207
+ ID: sample-001
208
+ Collected: 2025-10-18T10:00:00Z
209
+ Image: http://example.com/product1.jpg
210
+
211
+ 🏷️ Step 3: Creating Label Studio tasks from DataSet ds-001...
212
+ ============================================================
213
+ ✅ Task creation completed!
214
+
215
+ 📊 Results:
216
+ Total samples processed: 10
217
+ Tasks created: 10
218
+ Tasks failed: 0
219
+ Tasks skipped: 0
220
+ AI predictions created: 10
221
+
222
+ 🎯 Created task IDs:
223
+ - Task 101
224
+ - Task 102
225
+ ...
226
+
227
+ 📈 Step 4: Querying labeling status for DataSet ds-001...
228
+ ============================================================
229
+ ✅ Labeling status retrieved!
230
+
231
+ 📊 Status for "Product Images":
232
+ Total samples: 10
233
+ Tasks created: 10
234
+ With AI predictions: 10
235
+ With annotations: 0
236
+ Annotations completed: 0
237
+ Not yet processed: 0
238
+ Completion rate: 0.0%
239
+
240
+ 🤖 Step 5: Generating AI predictions for DataSet ds-001...
241
+ ============================================================
242
+ ✅ Prediction generation completed!
243
+
244
+ 📊 Results:
245
+ Total tasks: 10
246
+ Succeeded: 10
247
+ Failed: 0
248
+ Model version: yolov8-nano-v1.0
249
+
250
+ 🔄 Step 6: Syncing annotations back to DataSet ds-001...
251
+ ============================================================
252
+ ✅ Annotation sync completed!
253
+
254
+ 📊 Results:
255
+ Total annotations processed: 0
256
+ DataSamples updated: 0
257
+ Updates failed: 0
258
+ Skipped: 0
259
+
260
+ ============================================================
261
+ ✨ Integration test completed successfully!
262
+
263
+ 📝 Next steps:
264
+ 1. Open Label Studio: http://label.dataset.localhost:8080/projects/2
265
+ 2. Review AI-generated predictions
266
+ 3. Complete annotations
267
+ 4. Run syncAnnotations again to update DataSamples
268
+ ============================================================
269
+ ```
270
+
271
+ ## Troubleshooting
272
+
273
+ ### Connection Errors
274
+
275
+ **Symptom:** Cannot connect to Label Studio or Things Factory
276
+
277
+ **Solutions:**
278
+ 1. Verify services are running:
279
+ ```bash
280
+ # Check Things Factory
281
+ curl http://app.dataset.localhost:3000/graphql
282
+
283
+ # Check Label Studio
284
+ curl http://label.dataset.localhost:8080/api/projects
285
+ ```
286
+
287
+ 2. Check subdomain resolution:
288
+ ```bash
289
+ # Should resolve to 127.0.0.1
290
+ ping app.dataset.localhost
291
+ ping label.dataset.localhost
292
+ ```
293
+
294
+ ### API Token Errors
295
+
296
+ **Symptom:** 401 Unauthorized from Label Studio
297
+
298
+ **Solutions:**
299
+ 1. Verify API token is correct and not expired
300
+ 2. Check token has admin/staff permissions
301
+ 3. Regenerate token if necessary
302
+
303
+ ### GraphQL Errors
304
+
305
+ **Symptom:** GraphQL query fails
306
+
307
+ **Solutions:**
308
+ 1. Check Things Factory is running and GraphQL endpoint is accessible
309
+ 2. Verify user is authenticated (for authenticated queries)
310
+ 3. Check GraphQL schema is up to date:
311
+ ```bash
312
+ curl -X POST http://app.dataset.localhost:3000/graphql \
313
+ -H "Content-Type: application/json" \
314
+ -d '{"query": "{ __schema { types { name } } }"}'
315
+ ```
316
+
317
+ ### No Tasks Found
318
+
319
+ **Symptom:** Test cannot find tasks in Label Studio project
320
+
321
+ **Solutions:**
322
+ 1. Create a project in Label Studio
323
+ 2. Add tasks manually or via API
324
+ 3. Ensure tasks have image data field
325
+ 4. Update `TEST_PROJECT_ID` environment variable
326
+
327
+ ## Advanced Usage
328
+
329
+ ### Custom Configuration
330
+
331
+ All test scripts support environment variables:
332
+
333
+ ```bash
334
+ # Full configuration example
335
+ export THINGS_FACTORY_GRAPHQL=http://app.dataset.localhost:3000/graphql
336
+ export LABEL_STUDIO_URL=http://label.dataset.localhost:8080
337
+ export LABEL_STUDIO_API_TOKEN=your-token
338
+ export LABEL_STUDIO_PROJECT_ID=2
339
+ export TEST_PROJECT_ID=2
340
+
341
+ # Run all tests
342
+ node test-simple.js
343
+ node test-ai-prediction.js
344
+ node test-dataset-integration.js
345
+ ```
346
+
347
+ ### Continuous Integration
348
+
349
+ For CI/CD pipelines:
350
+
351
+ ```bash
352
+ #!/bin/bash
353
+
354
+ # Start services
355
+ docker-compose up -d things-factory label-studio
356
+
357
+ # Wait for services to be ready
358
+ sleep 10
359
+
360
+ # Run tests
361
+ export THINGS_FACTORY_GRAPHQL=http://app.dataset.localhost:3000/graphql
362
+ export LABEL_STUDIO_URL=http://label.dataset.localhost:8080
363
+ export LABEL_STUDIO_API_TOKEN=$CI_LABEL_STUDIO_TOKEN
364
+
365
+ node test-simple.js || exit 1
366
+ node test-ai-prediction.js || exit 1
367
+ node test-dataset-integration.js || exit 1
368
+
369
+ # Cleanup
370
+ docker-compose down
371
+ ```
372
+
373
+ ## Next Steps
374
+
375
+ After successful testing:
376
+
377
+ 1. Review the INTEGRATION.md guide for deployment configuration
378
+ 2. Configure production environment with proper subdomain setup
379
+ 3. Set up SSL certificates for HTTPS
380
+ 4. Configure cookie domain for production
381
+ 5. Set up monitoring and logging
382
+
383
+ ## References
384
+
385
+ - [INTEGRATION.md](./INTEGRATION.md) - Full integration guide
386
+ - [README.md](./README.md) - Module overview
387
+ - [Label Studio Documentation](https://labelstud.io/guide/)