@semiont/backend 0.4.3 → 0.4.4
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.
- package/dist/index.js +391 -218
- package/dist/index.js.map +1 -1
- package/dist/openapi.json +6221 -0
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import winston from 'winston';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import jwt from 'jsonwebtoken';
|
|
5
|
-
import { email, userId, accessToken, googleCredential, annotationId, resourceId, EventBus, jobId, entityType, assembleAnnotation, userToAgent } from '@semiont/core';
|
|
5
|
+
import { email, userId, accessToken, googleCredential, annotationId, resourceId, userToDid, EventBus, jobId, entityType, assembleAnnotation, userToAgent } from '@semiont/core';
|
|
6
6
|
import { cors } from 'hono/cors';
|
|
7
7
|
import { serve } from '@hono/node-server';
|
|
8
8
|
import { Hono } from 'hono';
|
|
@@ -613,7 +613,7 @@ var require_timeoutProvider = __commonJS({
|
|
|
613
613
|
});
|
|
614
614
|
exports$1.timeoutProvider = void 0;
|
|
615
615
|
exports$1.timeoutProvider = {
|
|
616
|
-
setTimeout: /* @__PURE__ */ __name(function(handler,
|
|
616
|
+
setTimeout: /* @__PURE__ */ __name(function(handler, timeout2) {
|
|
617
617
|
var args = [];
|
|
618
618
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
619
619
|
args[_i - 2] = arguments[_i];
|
|
@@ -622,12 +622,12 @@ var require_timeoutProvider = __commonJS({
|
|
|
622
622
|
if (delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) {
|
|
623
623
|
return delegate.setTimeout.apply(delegate, __spreadArray([
|
|
624
624
|
handler,
|
|
625
|
-
|
|
625
|
+
timeout2
|
|
626
626
|
], __read(args)));
|
|
627
627
|
}
|
|
628
628
|
return setTimeout.apply(void 0, __spreadArray([
|
|
629
629
|
handler,
|
|
630
|
-
|
|
630
|
+
timeout2
|
|
631
631
|
], __read(args)));
|
|
632
632
|
}, "setTimeout"),
|
|
633
633
|
clearTimeout: /* @__PURE__ */ __name(function(handle) {
|
|
@@ -2061,7 +2061,7 @@ var require_intervalProvider = __commonJS({
|
|
|
2061
2061
|
});
|
|
2062
2062
|
exports$1.intervalProvider = void 0;
|
|
2063
2063
|
exports$1.intervalProvider = {
|
|
2064
|
-
setInterval: /* @__PURE__ */ __name(function(handler,
|
|
2064
|
+
setInterval: /* @__PURE__ */ __name(function(handler, timeout2) {
|
|
2065
2065
|
var args = [];
|
|
2066
2066
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
2067
2067
|
args[_i - 2] = arguments[_i];
|
|
@@ -2070,12 +2070,12 @@ var require_intervalProvider = __commonJS({
|
|
|
2070
2070
|
if (delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) {
|
|
2071
2071
|
return delegate.setInterval.apply(delegate, __spreadArray([
|
|
2072
2072
|
handler,
|
|
2073
|
-
|
|
2073
|
+
timeout2
|
|
2074
2074
|
], __read(args)));
|
|
2075
2075
|
}
|
|
2076
2076
|
return setInterval.apply(void 0, __spreadArray([
|
|
2077
2077
|
handler,
|
|
2078
|
-
|
|
2078
|
+
timeout2
|
|
2079
2079
|
], __read(args)));
|
|
2080
2080
|
}, "setInterval"),
|
|
2081
2081
|
clearInterval: /* @__PURE__ */ __name(function(handle) {
|
|
@@ -4283,7 +4283,7 @@ var require_firstValueFrom = __commonJS({
|
|
|
4283
4283
|
exports$1.firstValueFrom = void 0;
|
|
4284
4284
|
var EmptyError_1 = require_EmptyError();
|
|
4285
4285
|
var Subscriber_1 = require_Subscriber();
|
|
4286
|
-
function
|
|
4286
|
+
function firstValueFrom2(source, config2) {
|
|
4287
4287
|
var hasConfig = typeof config2 === "object";
|
|
4288
4288
|
return new Promise(function(resolve, reject) {
|
|
4289
4289
|
var subscriber = new Subscriber_1.SafeSubscriber({
|
|
@@ -4303,8 +4303,8 @@ var require_firstValueFrom = __commonJS({
|
|
|
4303
4303
|
source.subscribe(subscriber);
|
|
4304
4304
|
});
|
|
4305
4305
|
}
|
|
4306
|
-
__name(
|
|
4307
|
-
exports$1.firstValueFrom =
|
|
4306
|
+
__name(firstValueFrom2, "firstValueFrom");
|
|
4307
|
+
exports$1.firstValueFrom = firstValueFrom2;
|
|
4308
4308
|
}
|
|
4309
4309
|
});
|
|
4310
4310
|
|
|
@@ -4402,7 +4402,7 @@ var require_timeout = __commonJS({
|
|
|
4402
4402
|
this.info = info;
|
|
4403
4403
|
}, "TimeoutErrorImpl");
|
|
4404
4404
|
});
|
|
4405
|
-
function
|
|
4405
|
+
function timeout2(config2, schedulerArg) {
|
|
4406
4406
|
var _a = isDate_1.isValidDate(config2) ? {
|
|
4407
4407
|
first: config2
|
|
4408
4408
|
} : typeof config2 === "number" ? {
|
|
@@ -4444,8 +4444,8 @@ var require_timeout = __commonJS({
|
|
|
4444
4444
|
!seen && startTimer(first != null ? typeof first === "number" ? first : +first - scheduler.now() : each);
|
|
4445
4445
|
});
|
|
4446
4446
|
}
|
|
4447
|
-
__name(
|
|
4448
|
-
exports$1.timeout =
|
|
4447
|
+
__name(timeout2, "timeout");
|
|
4448
|
+
exports$1.timeout = timeout2;
|
|
4449
4449
|
function timeoutErrorFactory(info) {
|
|
4450
4450
|
throw new exports$1.TimeoutError(info);
|
|
4451
4451
|
}
|
|
@@ -4462,7 +4462,7 @@ var require_map = __commonJS({
|
|
|
4462
4462
|
exports$1.map = void 0;
|
|
4463
4463
|
var lift_1 = require_lift();
|
|
4464
4464
|
var OperatorSubscriber_1 = require_OperatorSubscriber();
|
|
4465
|
-
function
|
|
4465
|
+
function map2(project, thisArg) {
|
|
4466
4466
|
return lift_1.operate(function(source, subscriber) {
|
|
4467
4467
|
var index = 0;
|
|
4468
4468
|
source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function(value) {
|
|
@@ -4470,8 +4470,8 @@ var require_map = __commonJS({
|
|
|
4470
4470
|
}));
|
|
4471
4471
|
});
|
|
4472
4472
|
}
|
|
4473
|
-
__name(
|
|
4474
|
-
exports$1.map =
|
|
4473
|
+
__name(map2, "map");
|
|
4474
|
+
exports$1.map = map2;
|
|
4475
4475
|
}
|
|
4476
4476
|
});
|
|
4477
4477
|
|
|
@@ -5501,7 +5501,7 @@ var require_merge = __commonJS({
|
|
|
5501
5501
|
var empty_1 = require_empty();
|
|
5502
5502
|
var args_1 = require_args();
|
|
5503
5503
|
var from_1 = require_from();
|
|
5504
|
-
function
|
|
5504
|
+
function merge2() {
|
|
5505
5505
|
var args = [];
|
|
5506
5506
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
5507
5507
|
args[_i] = arguments[_i];
|
|
@@ -5511,8 +5511,8 @@ var require_merge = __commonJS({
|
|
|
5511
5511
|
var sources = args;
|
|
5512
5512
|
return !sources.length ? empty_1.EMPTY : sources.length === 1 ? innerFrom_1.innerFrom(sources[0]) : mergeAll_1.mergeAll(concurrent)(from_1.from(sources, scheduler));
|
|
5513
5513
|
}
|
|
5514
|
-
__name(
|
|
5515
|
-
exports$1.merge =
|
|
5514
|
+
__name(merge2, "merge");
|
|
5515
|
+
exports$1.merge = merge2;
|
|
5516
5516
|
}
|
|
5517
5517
|
});
|
|
5518
5518
|
|
|
@@ -5636,7 +5636,7 @@ var require_filter = __commonJS({
|
|
|
5636
5636
|
exports$1.filter = void 0;
|
|
5637
5637
|
var lift_1 = require_lift();
|
|
5638
5638
|
var OperatorSubscriber_1 = require_OperatorSubscriber();
|
|
5639
|
-
function
|
|
5639
|
+
function filter2(predicate, thisArg) {
|
|
5640
5640
|
return lift_1.operate(function(source, subscriber) {
|
|
5641
5641
|
var index = 0;
|
|
5642
5642
|
source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function(value) {
|
|
@@ -5644,8 +5644,8 @@ var require_filter = __commonJS({
|
|
|
5644
5644
|
}));
|
|
5645
5645
|
});
|
|
5646
5646
|
}
|
|
5647
|
-
__name(
|
|
5648
|
-
exports$1.filter =
|
|
5647
|
+
__name(filter2, "filter");
|
|
5648
|
+
exports$1.filter = filter2;
|
|
5649
5649
|
}
|
|
5650
5650
|
});
|
|
5651
5651
|
|
|
@@ -6901,7 +6901,7 @@ var require_take = __commonJS({
|
|
|
6901
6901
|
var empty_1 = require_empty();
|
|
6902
6902
|
var lift_1 = require_lift();
|
|
6903
6903
|
var OperatorSubscriber_1 = require_OperatorSubscriber();
|
|
6904
|
-
function
|
|
6904
|
+
function take2(count) {
|
|
6905
6905
|
return count <= 0 ? function() {
|
|
6906
6906
|
return empty_1.EMPTY;
|
|
6907
6907
|
} : lift_1.operate(function(source, subscriber) {
|
|
@@ -6916,8 +6916,8 @@ var require_take = __commonJS({
|
|
|
6916
6916
|
}));
|
|
6917
6917
|
});
|
|
6918
6918
|
}
|
|
6919
|
-
__name(
|
|
6920
|
-
exports$1.take =
|
|
6919
|
+
__name(take2, "take");
|
|
6920
|
+
exports$1.take = take2;
|
|
6921
6921
|
}
|
|
6922
6922
|
});
|
|
6923
6923
|
|
|
@@ -7807,7 +7807,7 @@ var require_merge2 = __commonJS({
|
|
|
7807
7807
|
var mergeAll_1 = require_mergeAll();
|
|
7808
7808
|
var args_1 = require_args();
|
|
7809
7809
|
var from_1 = require_from();
|
|
7810
|
-
function
|
|
7810
|
+
function merge2() {
|
|
7811
7811
|
var args = [];
|
|
7812
7812
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
7813
7813
|
args[_i] = arguments[_i];
|
|
@@ -7820,8 +7820,8 @@ var require_merge2 = __commonJS({
|
|
|
7820
7820
|
], __read(args)), scheduler)).subscribe(subscriber);
|
|
7821
7821
|
});
|
|
7822
7822
|
}
|
|
7823
|
-
__name(
|
|
7824
|
-
exports$1.merge =
|
|
7823
|
+
__name(merge2, "merge");
|
|
7824
|
+
exports$1.merge = merge2;
|
|
7825
7825
|
}
|
|
7826
7826
|
});
|
|
7827
7827
|
|
|
@@ -12760,6 +12760,127 @@ var openapi_default = {
|
|
|
12760
12760
|
"isNewUser"
|
|
12761
12761
|
]
|
|
12762
12762
|
},
|
|
12763
|
+
BrowseFilesResponse: {
|
|
12764
|
+
type: "object",
|
|
12765
|
+
required: [
|
|
12766
|
+
"path",
|
|
12767
|
+
"entries"
|
|
12768
|
+
],
|
|
12769
|
+
properties: {
|
|
12770
|
+
path: {
|
|
12771
|
+
type: "string",
|
|
12772
|
+
description: "The directory path that was listed, relative to project root"
|
|
12773
|
+
},
|
|
12774
|
+
entries: {
|
|
12775
|
+
type: "array",
|
|
12776
|
+
items: {
|
|
12777
|
+
$ref: "#/components/schemas/DirectoryEntry"
|
|
12778
|
+
}
|
|
12779
|
+
}
|
|
12780
|
+
},
|
|
12781
|
+
additionalProperties: false
|
|
12782
|
+
},
|
|
12783
|
+
DirectoryEntry: {
|
|
12784
|
+
oneOf: [
|
|
12785
|
+
{
|
|
12786
|
+
$ref: "#/components/schemas/FileEntry"
|
|
12787
|
+
},
|
|
12788
|
+
{
|
|
12789
|
+
$ref: "#/components/schemas/DirEntry"
|
|
12790
|
+
}
|
|
12791
|
+
]
|
|
12792
|
+
},
|
|
12793
|
+
FileEntry: {
|
|
12794
|
+
type: "object",
|
|
12795
|
+
required: [
|
|
12796
|
+
"type",
|
|
12797
|
+
"name",
|
|
12798
|
+
"path",
|
|
12799
|
+
"size",
|
|
12800
|
+
"mtime",
|
|
12801
|
+
"tracked"
|
|
12802
|
+
],
|
|
12803
|
+
properties: {
|
|
12804
|
+
type: {
|
|
12805
|
+
type: "string",
|
|
12806
|
+
enum: [
|
|
12807
|
+
"file"
|
|
12808
|
+
]
|
|
12809
|
+
},
|
|
12810
|
+
name: {
|
|
12811
|
+
type: "string",
|
|
12812
|
+
description: "Entry name (basename)"
|
|
12813
|
+
},
|
|
12814
|
+
path: {
|
|
12815
|
+
type: "string",
|
|
12816
|
+
description: "Path relative to project root"
|
|
12817
|
+
},
|
|
12818
|
+
size: {
|
|
12819
|
+
type: "integer",
|
|
12820
|
+
description: "File size in bytes"
|
|
12821
|
+
},
|
|
12822
|
+
mtime: {
|
|
12823
|
+
type: "string",
|
|
12824
|
+
format: "date-time",
|
|
12825
|
+
description: "Last modified time (ISO 8601)"
|
|
12826
|
+
},
|
|
12827
|
+
tracked: {
|
|
12828
|
+
type: "boolean",
|
|
12829
|
+
description: "True if this file is a tracked resource in the Knowledge Base"
|
|
12830
|
+
},
|
|
12831
|
+
resourceId: {
|
|
12832
|
+
type: "string",
|
|
12833
|
+
description: "Resource ID (only when tracked is true)"
|
|
12834
|
+
},
|
|
12835
|
+
entityTypes: {
|
|
12836
|
+
type: "array",
|
|
12837
|
+
items: {
|
|
12838
|
+
type: "string"
|
|
12839
|
+
},
|
|
12840
|
+
description: "Entity types assigned to this resource (only when tracked is true)"
|
|
12841
|
+
},
|
|
12842
|
+
annotationCount: {
|
|
12843
|
+
type: "integer",
|
|
12844
|
+
description: "Number of annotations on this resource (only when tracked is true)"
|
|
12845
|
+
},
|
|
12846
|
+
creator: {
|
|
12847
|
+
type: "string",
|
|
12848
|
+
description: "DID of the user who created the resource (only when tracked is true)"
|
|
12849
|
+
}
|
|
12850
|
+
},
|
|
12851
|
+
additionalProperties: false
|
|
12852
|
+
},
|
|
12853
|
+
DirEntry: {
|
|
12854
|
+
type: "object",
|
|
12855
|
+
required: [
|
|
12856
|
+
"type",
|
|
12857
|
+
"name",
|
|
12858
|
+
"path",
|
|
12859
|
+
"mtime"
|
|
12860
|
+
],
|
|
12861
|
+
properties: {
|
|
12862
|
+
type: {
|
|
12863
|
+
type: "string",
|
|
12864
|
+
enum: [
|
|
12865
|
+
"dir"
|
|
12866
|
+
]
|
|
12867
|
+
},
|
|
12868
|
+
name: {
|
|
12869
|
+
type: "string",
|
|
12870
|
+
description: "Entry name (basename)"
|
|
12871
|
+
},
|
|
12872
|
+
path: {
|
|
12873
|
+
type: "string",
|
|
12874
|
+
description: "Path relative to project root"
|
|
12875
|
+
},
|
|
12876
|
+
mtime: {
|
|
12877
|
+
type: "string",
|
|
12878
|
+
format: "date-time",
|
|
12879
|
+
description: "Last modified time (ISO 8601)"
|
|
12880
|
+
}
|
|
12881
|
+
},
|
|
12882
|
+
additionalProperties: false
|
|
12883
|
+
},
|
|
12763
12884
|
BodyOperationAdd: {
|
|
12764
12885
|
type: "object",
|
|
12765
12886
|
properties: {
|
|
@@ -13479,6 +13600,10 @@ var openapi_default = {
|
|
|
13479
13600
|
minimum: 1,
|
|
13480
13601
|
maximum: 10,
|
|
13481
13602
|
description: "Optional density: desired number of assessments per 2000 words of text (1-10)"
|
|
13603
|
+
},
|
|
13604
|
+
language: {
|
|
13605
|
+
type: "string",
|
|
13606
|
+
description: 'BCP 47 language tag for the generated assessment text (e.g. "en", "fr", "de")'
|
|
13482
13607
|
}
|
|
13483
13608
|
}
|
|
13484
13609
|
},
|
|
@@ -13504,6 +13629,10 @@ var openapi_default = {
|
|
|
13504
13629
|
minimum: 2,
|
|
13505
13630
|
maximum: 12,
|
|
13506
13631
|
description: "Optional density: desired number of comments per 2000 words of text (2-12)"
|
|
13632
|
+
},
|
|
13633
|
+
language: {
|
|
13634
|
+
type: "string",
|
|
13635
|
+
description: "BCP 47 language tag for the generated comment text (e.g. 'en', 'fr', 'de')"
|
|
13507
13636
|
}
|
|
13508
13637
|
}
|
|
13509
13638
|
},
|
|
@@ -14694,6 +14823,20 @@ var openapi_default = {
|
|
|
14694
14823
|
}
|
|
14695
14824
|
]
|
|
14696
14825
|
},
|
|
14826
|
+
generator: {
|
|
14827
|
+
description: "Software agent that produced or processed this resource (W3C Web Annotation model)",
|
|
14828
|
+
oneOf: [
|
|
14829
|
+
{
|
|
14830
|
+
$ref: "#/components/schemas/Agent"
|
|
14831
|
+
},
|
|
14832
|
+
{
|
|
14833
|
+
type: "array",
|
|
14834
|
+
items: {
|
|
14835
|
+
$ref: "#/components/schemas/Agent"
|
|
14836
|
+
}
|
|
14837
|
+
}
|
|
14838
|
+
]
|
|
14839
|
+
},
|
|
14697
14840
|
conformsTo: {
|
|
14698
14841
|
description: "Profile/shape URI this resource description conforms to.",
|
|
14699
14842
|
oneOf: [
|
|
@@ -16375,8 +16518,8 @@ exchangeRouter.post("/api/admin/exchange/backup", async (c) => {
|
|
|
16375
16518
|
(async () => {
|
|
16376
16519
|
try {
|
|
16377
16520
|
await exportBackup({
|
|
16378
|
-
eventStore: mm.kb.eventStore,
|
|
16379
|
-
content: mm.kb.content,
|
|
16521
|
+
eventStore: mm.knowledgeSystem.kb.eventStore,
|
|
16522
|
+
content: mm.knowledgeSystem.kb.content,
|
|
16380
16523
|
sourceUrl
|
|
16381
16524
|
}, nodeWritable);
|
|
16382
16525
|
} catch (err) {
|
|
@@ -16475,8 +16618,8 @@ exchangeRouter.post("/api/moderate/exchange/export", async (c) => {
|
|
|
16475
16618
|
(async () => {
|
|
16476
16619
|
try {
|
|
16477
16620
|
await exportLinkedData({
|
|
16478
|
-
views: mm.kb.views,
|
|
16479
|
-
content: mm.kb.content,
|
|
16621
|
+
views: mm.knowledgeSystem.kb.views,
|
|
16622
|
+
content: mm.knowledgeSystem.kb.content,
|
|
16480
16623
|
sourceUrl,
|
|
16481
16624
|
entityTypes,
|
|
16482
16625
|
includeArchived
|
|
@@ -16587,7 +16730,7 @@ function registerCreateResource(router) {
|
|
|
16587
16730
|
const arrayBuffer = await file.arrayBuffer();
|
|
16588
16731
|
const contentBuffer = Buffer.from(arrayBuffer);
|
|
16589
16732
|
const eventBus2 = c.get("eventBus");
|
|
16590
|
-
const
|
|
16733
|
+
const resourceId20 = await ResourceOperations.createResource({
|
|
16591
16734
|
name,
|
|
16592
16735
|
content: contentBuffer,
|
|
16593
16736
|
format,
|
|
@@ -16595,9 +16738,9 @@ function registerCreateResource(router) {
|
|
|
16595
16738
|
entityTypes,
|
|
16596
16739
|
creationMethod: creationMethod || void 0,
|
|
16597
16740
|
storageUri: storageUri || void 0
|
|
16598
|
-
}, userId(user
|
|
16741
|
+
}, userId(userToDid(user)), eventBus2);
|
|
16599
16742
|
return c.json({
|
|
16600
|
-
resourceId:
|
|
16743
|
+
resourceId: resourceId20
|
|
16601
16744
|
}, 202);
|
|
16602
16745
|
});
|
|
16603
16746
|
}
|
|
@@ -16912,7 +17055,7 @@ function registerGetResourceUri(router) {
|
|
|
16912
17055
|
}
|
|
16913
17056
|
const acceptHeader = c.req.header("Accept") || "application/ld+json";
|
|
16914
17057
|
if (acceptHeader.includes("text/") || acceptHeader.includes("image/") || acceptHeader.includes("application/pdf")) {
|
|
16915
|
-
const { kb } = c.get("makeMeaning");
|
|
17058
|
+
const { knowledgeSystem: { kb } } = c.get("makeMeaning");
|
|
16916
17059
|
let resource;
|
|
16917
17060
|
try {
|
|
16918
17061
|
resource = await ResourceContext.getResourceMetadata(resourceId(id), kb);
|
|
@@ -17026,7 +17169,7 @@ function registerUpdateResource(router) {
|
|
|
17026
17169
|
const body = c.get("validatedBody");
|
|
17027
17170
|
const user = c.get("user");
|
|
17028
17171
|
const eventBus2 = c.get("eventBus");
|
|
17029
|
-
const { kb } = c.get("makeMeaning");
|
|
17172
|
+
const { knowledgeSystem: { kb } } = c.get("makeMeaning");
|
|
17030
17173
|
const doc = await ResourceContext.getResourceMetadata(resourceId(id), kb);
|
|
17031
17174
|
if (!doc) {
|
|
17032
17175
|
throw new HTTPException(404, {
|
|
@@ -17035,7 +17178,7 @@ function registerUpdateResource(router) {
|
|
|
17035
17178
|
}
|
|
17036
17179
|
await ResourceOperations.updateResource({
|
|
17037
17180
|
resourceId: resourceId(id),
|
|
17038
|
-
userId: userId(user
|
|
17181
|
+
userId: userId(userToDid(user)),
|
|
17039
17182
|
currentArchived: doc.archived,
|
|
17040
17183
|
updatedArchived: body.archived,
|
|
17041
17184
|
currentEntityTypes: doc.entityTypes,
|
|
@@ -17105,7 +17248,7 @@ function registerAnnotateReferencesStream(router, jobQueue) {
|
|
|
17105
17248
|
});
|
|
17106
17249
|
}
|
|
17107
17250
|
const eventBus2 = c.get("eventBus");
|
|
17108
|
-
const { kb } = c.get("makeMeaning");
|
|
17251
|
+
const { knowledgeSystem: { kb } } = c.get("makeMeaning");
|
|
17109
17252
|
const resource = await ResourceContext.getResourceMetadata(resourceId(id), kb);
|
|
17110
17253
|
if (!resource) {
|
|
17111
17254
|
throw new HTTPException(404, {
|
|
@@ -17117,7 +17260,7 @@ function registerAnnotateReferencesStream(router, jobQueue) {
|
|
|
17117
17260
|
metadata: {
|
|
17118
17261
|
id: jobId(`job-${nanoid()}`),
|
|
17119
17262
|
type: "reference-annotation",
|
|
17120
|
-
userId: userId(user
|
|
17263
|
+
userId: userId(userToDid(user)),
|
|
17121
17264
|
userName: user.name || user.email,
|
|
17122
17265
|
userEmail: user.email,
|
|
17123
17266
|
userDomain: user.domain,
|
|
@@ -17307,7 +17450,7 @@ function registerAnnotateHighlightsStream(router, jobQueue) {
|
|
|
17307
17450
|
});
|
|
17308
17451
|
}
|
|
17309
17452
|
const eventBus2 = c.get("eventBus");
|
|
17310
|
-
const { kb } = c.get("makeMeaning");
|
|
17453
|
+
const { knowledgeSystem: { kb } } = c.get("makeMeaning");
|
|
17311
17454
|
const resource = await ResourceContext.getResourceMetadata(resourceId(id), kb);
|
|
17312
17455
|
if (!resource) {
|
|
17313
17456
|
throw new HTTPException(404, {
|
|
@@ -17319,7 +17462,7 @@ function registerAnnotateHighlightsStream(router, jobQueue) {
|
|
|
17319
17462
|
metadata: {
|
|
17320
17463
|
id: jobId(`job-${nanoid()}`),
|
|
17321
17464
|
type: "highlight-annotation",
|
|
17322
|
-
userId: userId(user
|
|
17465
|
+
userId: userId(userToDid(user)),
|
|
17323
17466
|
userName: user.name || user.email,
|
|
17324
17467
|
userEmail: user.email,
|
|
17325
17468
|
userDomain: user.domain,
|
|
@@ -17495,7 +17638,7 @@ function registerAnnotateAssessmentsStream(router, jobQueue) {
|
|
|
17495
17638
|
router.post("/resources/:id/annotate-assessments-stream", validateRequestBody("AnnotateAssessmentsStreamRequest"), async (c) => {
|
|
17496
17639
|
const { id } = c.req.param();
|
|
17497
17640
|
const body = c.get("validatedBody");
|
|
17498
|
-
const { instructions, tone, density } = body;
|
|
17641
|
+
const { instructions, tone, density, language } = body;
|
|
17499
17642
|
if (density !== void 0 && (typeof density !== "number" || density < 1 || density > 10)) {
|
|
17500
17643
|
throw new HTTPException(400, {
|
|
17501
17644
|
message: "Invalid density. Must be a number between 1 and 10."
|
|
@@ -17517,7 +17660,7 @@ function registerAnnotateAssessmentsStream(router, jobQueue) {
|
|
|
17517
17660
|
});
|
|
17518
17661
|
}
|
|
17519
17662
|
const eventBus2 = c.get("eventBus");
|
|
17520
|
-
const { kb } = c.get("makeMeaning");
|
|
17663
|
+
const { knowledgeSystem: { kb } } = c.get("makeMeaning");
|
|
17521
17664
|
const resource = await ResourceContext.getResourceMetadata(resourceId(id), kb);
|
|
17522
17665
|
if (!resource) {
|
|
17523
17666
|
throw new HTTPException(404, {
|
|
@@ -17529,7 +17672,7 @@ function registerAnnotateAssessmentsStream(router, jobQueue) {
|
|
|
17529
17672
|
metadata: {
|
|
17530
17673
|
id: jobId(`job-${nanoid()}`),
|
|
17531
17674
|
type: "assessment-annotation",
|
|
17532
|
-
userId: userId(user
|
|
17675
|
+
userId: userId(userToDid(user)),
|
|
17533
17676
|
userName: user.name || user.email,
|
|
17534
17677
|
userEmail: user.email,
|
|
17535
17678
|
userDomain: user.domain,
|
|
@@ -17541,7 +17684,8 @@ function registerAnnotateAssessmentsStream(router, jobQueue) {
|
|
|
17541
17684
|
resourceId: resourceId(id),
|
|
17542
17685
|
instructions,
|
|
17543
17686
|
tone,
|
|
17544
|
-
density
|
|
17687
|
+
density,
|
|
17688
|
+
language
|
|
17545
17689
|
}
|
|
17546
17690
|
};
|
|
17547
17691
|
await jobQueue.createJob(job);
|
|
@@ -17716,7 +17860,7 @@ function registerAnnotateCommentsStream(router, jobQueue) {
|
|
|
17716
17860
|
router.post("/resources/:id/annotate-comments-stream", validateRequestBody("AnnotateCommentsStreamRequest"), async (c) => {
|
|
17717
17861
|
const { id } = c.req.param();
|
|
17718
17862
|
const body = c.get("validatedBody");
|
|
17719
|
-
const { instructions, tone, density } = body;
|
|
17863
|
+
const { instructions, tone, density, language } = body;
|
|
17720
17864
|
if (density !== void 0 && (typeof density !== "number" || density < 2 || density > 12)) {
|
|
17721
17865
|
throw new HTTPException(400, {
|
|
17722
17866
|
message: "Invalid density. Must be a number between 2 and 12."
|
|
@@ -17738,7 +17882,7 @@ function registerAnnotateCommentsStream(router, jobQueue) {
|
|
|
17738
17882
|
});
|
|
17739
17883
|
}
|
|
17740
17884
|
const eventBus2 = c.get("eventBus");
|
|
17741
|
-
const { kb } = c.get("makeMeaning");
|
|
17885
|
+
const { knowledgeSystem: { kb } } = c.get("makeMeaning");
|
|
17742
17886
|
const resource = await ResourceContext.getResourceMetadata(resourceId(id), kb);
|
|
17743
17887
|
if (!resource) {
|
|
17744
17888
|
throw new HTTPException(404, {
|
|
@@ -17750,7 +17894,7 @@ function registerAnnotateCommentsStream(router, jobQueue) {
|
|
|
17750
17894
|
metadata: {
|
|
17751
17895
|
id: jobId(`job-${nanoid()}`),
|
|
17752
17896
|
type: "comment-annotation",
|
|
17753
|
-
userId: userId(user
|
|
17897
|
+
userId: userId(userToDid(user)),
|
|
17754
17898
|
userName: user.name || user.email,
|
|
17755
17899
|
userEmail: user.email,
|
|
17756
17900
|
userDomain: user.domain,
|
|
@@ -17762,7 +17906,8 @@ function registerAnnotateCommentsStream(router, jobQueue) {
|
|
|
17762
17906
|
resourceId: resourceId(id),
|
|
17763
17907
|
instructions,
|
|
17764
17908
|
tone,
|
|
17765
|
-
density
|
|
17909
|
+
density,
|
|
17910
|
+
language
|
|
17766
17911
|
}
|
|
17767
17912
|
};
|
|
17768
17913
|
await jobQueue.createJob(job);
|
|
@@ -18130,7 +18275,7 @@ function registerAnnotateTagsStream(router, jobQueue) {
|
|
|
18130
18275
|
});
|
|
18131
18276
|
}
|
|
18132
18277
|
const eventBus2 = c.get("eventBus");
|
|
18133
|
-
const { kb } = c.get("makeMeaning");
|
|
18278
|
+
const { knowledgeSystem: { kb } } = c.get("makeMeaning");
|
|
18134
18279
|
const resource = await ResourceContext.getResourceMetadata(resourceId(id), kb);
|
|
18135
18280
|
if (!resource) {
|
|
18136
18281
|
throw new HTTPException(404, {
|
|
@@ -18142,7 +18287,7 @@ function registerAnnotateTagsStream(router, jobQueue) {
|
|
|
18142
18287
|
metadata: {
|
|
18143
18288
|
id: jobId(`job-${nanoid()}`),
|
|
18144
18289
|
type: "tag-annotation",
|
|
18145
|
-
userId: userId(user
|
|
18290
|
+
userId: userId(userToDid(user)),
|
|
18146
18291
|
userName: user.name || user.email,
|
|
18147
18292
|
userEmail: user.email,
|
|
18148
18293
|
userDomain: user.domain,
|
|
@@ -18318,134 +18463,6 @@ function registerAnnotateTagsStream(router, jobQueue) {
|
|
|
18318
18463
|
});
|
|
18319
18464
|
}
|
|
18320
18465
|
__name(registerAnnotateTagsStream, "registerAnnotateTagsStream");
|
|
18321
|
-
|
|
18322
|
-
// src/routes/resources/routes/llm-context.ts
|
|
18323
|
-
var import_rxjs2 = __toESM(require_cjs());
|
|
18324
|
-
var import_operators2 = __toESM(require_operators());
|
|
18325
|
-
function registerGetResourceLLMContext(router) {
|
|
18326
|
-
router.get("/resources/:id/llm-context", async (c) => {
|
|
18327
|
-
const { id } = c.req.param();
|
|
18328
|
-
const query = c.req.query();
|
|
18329
|
-
const eventBus2 = c.get("eventBus");
|
|
18330
|
-
const depth = query.depth ? Number(query.depth) : 2;
|
|
18331
|
-
const maxResources = query.maxResources ? Number(query.maxResources) : 10;
|
|
18332
|
-
const includeContent = query.includeContent === "false" ? false : true;
|
|
18333
|
-
const includeSummary = query.includeSummary === "true" ? true : false;
|
|
18334
|
-
if (depth < 1 || depth > 3) {
|
|
18335
|
-
throw new HTTPException(400, {
|
|
18336
|
-
message: 'Query parameter "depth" must be between 1 and 3'
|
|
18337
|
-
});
|
|
18338
|
-
}
|
|
18339
|
-
if (maxResources < 1 || maxResources > 20) {
|
|
18340
|
-
throw new HTTPException(400, {
|
|
18341
|
-
message: 'Query parameter "maxResources" must be between 1 and 20'
|
|
18342
|
-
});
|
|
18343
|
-
}
|
|
18344
|
-
eventBus2.get("gather:resource-requested").next({
|
|
18345
|
-
resourceId: resourceId(id),
|
|
18346
|
-
options: {
|
|
18347
|
-
depth,
|
|
18348
|
-
maxResources,
|
|
18349
|
-
includeContent,
|
|
18350
|
-
includeSummary
|
|
18351
|
-
}
|
|
18352
|
-
});
|
|
18353
|
-
try {
|
|
18354
|
-
const result = await (0, import_rxjs2.firstValueFrom)((0, import_rxjs2.merge)(eventBus2.get("gather:resource-complete").pipe((0, import_operators2.filter)((e) => e.resourceId === id), (0, import_operators2.map)((e) => ({
|
|
18355
|
-
ok: true,
|
|
18356
|
-
context: e.context
|
|
18357
|
-
}))), eventBus2.get("gather:resource-failed").pipe((0, import_operators2.filter)((e) => e.resourceId === id), (0, import_operators2.map)((e) => ({
|
|
18358
|
-
ok: false,
|
|
18359
|
-
error: e.error
|
|
18360
|
-
})))).pipe((0, import_operators2.take)(1), (0, import_operators2.timeout)(3e4)));
|
|
18361
|
-
if (!result.ok) {
|
|
18362
|
-
throw result.error;
|
|
18363
|
-
}
|
|
18364
|
-
return c.json(result.context);
|
|
18365
|
-
} catch (error) {
|
|
18366
|
-
if (error instanceof Error) {
|
|
18367
|
-
if (error.message === "Resource not found") {
|
|
18368
|
-
throw new HTTPException(404, {
|
|
18369
|
-
message: "Resource not found"
|
|
18370
|
-
});
|
|
18371
|
-
}
|
|
18372
|
-
if (error.name === "TimeoutError") {
|
|
18373
|
-
throw new HTTPException(504, {
|
|
18374
|
-
message: "Context gathering timed out"
|
|
18375
|
-
});
|
|
18376
|
-
}
|
|
18377
|
-
}
|
|
18378
|
-
throw error;
|
|
18379
|
-
}
|
|
18380
|
-
});
|
|
18381
|
-
}
|
|
18382
|
-
__name(registerGetResourceLLMContext, "registerGetResourceLLMContext");
|
|
18383
|
-
|
|
18384
|
-
// src/routes/resources/routes/annotation-llm-context.ts
|
|
18385
|
-
var import_rxjs3 = __toESM(require_cjs());
|
|
18386
|
-
var import_operators3 = __toESM(require_operators());
|
|
18387
|
-
function registerGetAnnotationLLMContext(router) {
|
|
18388
|
-
router.get("/resources/:resourceId/annotations/:annotationId/llm-context", async (c) => {
|
|
18389
|
-
const { resourceId: resourceIdParam, annotationId: annotationIdParam } = c.req.param();
|
|
18390
|
-
const query = c.req.query();
|
|
18391
|
-
const eventBus2 = c.get("eventBus");
|
|
18392
|
-
const includeSourceContext = query.includeSourceContext === "false" ? false : true;
|
|
18393
|
-
const includeTargetContext = query.includeTargetContext === "false" ? false : true;
|
|
18394
|
-
const contextWindow = query.contextWindow ? Number(query.contextWindow) : 1e3;
|
|
18395
|
-
if (contextWindow < 100 || contextWindow > 5e3) {
|
|
18396
|
-
throw new HTTPException(400, {
|
|
18397
|
-
message: 'Query parameter "contextWindow" must be between 100 and 5000'
|
|
18398
|
-
});
|
|
18399
|
-
}
|
|
18400
|
-
eventBus2.get("gather:requested").next({
|
|
18401
|
-
annotationId: annotationId(annotationIdParam),
|
|
18402
|
-
resourceId: resourceId(resourceIdParam),
|
|
18403
|
-
options: {
|
|
18404
|
-
includeSourceContext,
|
|
18405
|
-
includeTargetContext,
|
|
18406
|
-
contextWindow
|
|
18407
|
-
}
|
|
18408
|
-
});
|
|
18409
|
-
try {
|
|
18410
|
-
const result = await (0, import_rxjs3.firstValueFrom)((0, import_rxjs3.merge)(eventBus2.get("gather:complete").pipe((0, import_operators3.filter)((e) => e.annotationId === annotationIdParam), (0, import_operators3.map)((e) => ({
|
|
18411
|
-
ok: true,
|
|
18412
|
-
response: e.response
|
|
18413
|
-
}))), eventBus2.get("gather:failed").pipe((0, import_operators3.filter)((e) => e.annotationId === annotationIdParam), (0, import_operators3.map)((e) => ({
|
|
18414
|
-
ok: false,
|
|
18415
|
-
error: e.error
|
|
18416
|
-
})))).pipe((0, import_operators3.take)(1), (0, import_operators3.timeout)(3e4)));
|
|
18417
|
-
if (!result.ok) {
|
|
18418
|
-
throw result.error;
|
|
18419
|
-
}
|
|
18420
|
-
return c.json(result.response);
|
|
18421
|
-
} catch (error) {
|
|
18422
|
-
if (error instanceof Error) {
|
|
18423
|
-
if (error.message === "Annotation not found") {
|
|
18424
|
-
throw new HTTPException(404, {
|
|
18425
|
-
message: "Annotation not found"
|
|
18426
|
-
});
|
|
18427
|
-
}
|
|
18428
|
-
if (error.message === "Source resource not found") {
|
|
18429
|
-
throw new HTTPException(404, {
|
|
18430
|
-
message: "Source resource not found"
|
|
18431
|
-
});
|
|
18432
|
-
}
|
|
18433
|
-
if (error.message === "Source content not found") {
|
|
18434
|
-
throw new HTTPException(404, {
|
|
18435
|
-
message: "Source content not found"
|
|
18436
|
-
});
|
|
18437
|
-
}
|
|
18438
|
-
if (error.name === "TimeoutError") {
|
|
18439
|
-
throw new HTTPException(504, {
|
|
18440
|
-
message: "Context gathering timed out"
|
|
18441
|
-
});
|
|
18442
|
-
}
|
|
18443
|
-
}
|
|
18444
|
-
throw error;
|
|
18445
|
-
}
|
|
18446
|
-
});
|
|
18447
|
-
}
|
|
18448
|
-
__name(registerGetAnnotationLLMContext, "registerGetAnnotationLLMContext");
|
|
18449
18466
|
function registerGetReferencedBy(router) {
|
|
18450
18467
|
router.get("/resources/:id/referenced-by", async (c) => {
|
|
18451
18468
|
const { id } = c.req.param();
|
|
@@ -18453,11 +18470,11 @@ function registerGetReferencedBy(router) {
|
|
|
18453
18470
|
const eventBus2 = c.get("eventBus");
|
|
18454
18471
|
const correlationId = crypto.randomUUID();
|
|
18455
18472
|
try {
|
|
18456
|
-
const response = await eventBusRequest(eventBus2, "
|
|
18473
|
+
const response = await eventBusRequest(eventBus2, "browse:referenced-by-requested", {
|
|
18457
18474
|
correlationId,
|
|
18458
18475
|
resourceId: resourceId(id),
|
|
18459
18476
|
motivation
|
|
18460
|
-
}, "
|
|
18477
|
+
}, "browse:referenced-by-result", "browse:referenced-by-failed");
|
|
18461
18478
|
return c.json(response);
|
|
18462
18479
|
} catch (error) {
|
|
18463
18480
|
if (error instanceof Error && error.name === "TimeoutError") {
|
|
@@ -18492,7 +18509,7 @@ function registerBindSearchStream(router) {
|
|
|
18492
18509
|
});
|
|
18493
18510
|
}
|
|
18494
18511
|
const eventBus2 = c.get("eventBus");
|
|
18495
|
-
const { kb } = c.get("makeMeaning");
|
|
18512
|
+
const { knowledgeSystem: { kb } } = c.get("makeMeaning");
|
|
18496
18513
|
const resource = await ResourceContext.getResourceMetadata(resourceId(id), kb);
|
|
18497
18514
|
if (!resource) {
|
|
18498
18515
|
throw new HTTPException(404, {
|
|
@@ -18520,7 +18537,7 @@ function registerBindSearchStream(router) {
|
|
|
18520
18537
|
if (closeStreamCallback) closeStreamCallback();
|
|
18521
18538
|
}, "cleanup");
|
|
18522
18539
|
try {
|
|
18523
|
-
subscriptions.push(eventBus2.get("
|
|
18540
|
+
subscriptions.push(eventBus2.get("match:search-results").subscribe(async (event) => {
|
|
18524
18541
|
if (event.correlationId !== correlationId) return;
|
|
18525
18542
|
if (isStreamClosed) return;
|
|
18526
18543
|
logger2.info("Bind search completed", {
|
|
@@ -18533,7 +18550,7 @@ function registerBindSearchStream(router) {
|
|
|
18533
18550
|
referenceId: event.referenceId,
|
|
18534
18551
|
results: event.results
|
|
18535
18552
|
}),
|
|
18536
|
-
event: "
|
|
18553
|
+
event: "match:search-results",
|
|
18537
18554
|
id: String(Date.now())
|
|
18538
18555
|
});
|
|
18539
18556
|
} catch (error) {
|
|
@@ -18541,7 +18558,7 @@ function registerBindSearchStream(router) {
|
|
|
18541
18558
|
}
|
|
18542
18559
|
cleanup();
|
|
18543
18560
|
}));
|
|
18544
|
-
subscriptions.push(eventBus2.get("
|
|
18561
|
+
subscriptions.push(eventBus2.get("match:search-failed").subscribe(async (event) => {
|
|
18545
18562
|
if (event.correlationId !== correlationId) return;
|
|
18546
18563
|
if (isStreamClosed) return;
|
|
18547
18564
|
logger2.error("Bind search failed", {
|
|
@@ -18554,7 +18571,7 @@ function registerBindSearchStream(router) {
|
|
|
18554
18571
|
referenceId: event.referenceId,
|
|
18555
18572
|
error: event.error.message
|
|
18556
18573
|
}),
|
|
18557
|
-
event: "
|
|
18574
|
+
event: "match:search-failed",
|
|
18558
18575
|
id: String(Date.now())
|
|
18559
18576
|
});
|
|
18560
18577
|
} catch (error) {
|
|
@@ -18562,7 +18579,7 @@ function registerBindSearchStream(router) {
|
|
|
18562
18579
|
}
|
|
18563
18580
|
cleanup();
|
|
18564
18581
|
}));
|
|
18565
|
-
eventBus2.get("
|
|
18582
|
+
eventBus2.get("match:search-requested").next({
|
|
18566
18583
|
correlationId,
|
|
18567
18584
|
referenceId,
|
|
18568
18585
|
context,
|
|
@@ -18580,7 +18597,7 @@ function registerBindSearchStream(router) {
|
|
|
18580
18597
|
referenceId,
|
|
18581
18598
|
error: error instanceof Error ? error.message : "Search failed"
|
|
18582
18599
|
}),
|
|
18583
|
-
event: "
|
|
18600
|
+
event: "match:search-failed",
|
|
18584
18601
|
id: String(Date.now())
|
|
18585
18602
|
});
|
|
18586
18603
|
} catch (sseError) {
|
|
@@ -18636,7 +18653,7 @@ function registerTokenRoutes(router) {
|
|
|
18636
18653
|
token: body.token,
|
|
18637
18654
|
name: body.name,
|
|
18638
18655
|
content: body.content,
|
|
18639
|
-
userId: userId(user
|
|
18656
|
+
userId: userId(userToDid(user)),
|
|
18640
18657
|
archiveOriginal: body.archiveOriginal
|
|
18641
18658
|
}, "yield:clone-created", "yield:clone-create-failed");
|
|
18642
18659
|
return c.json({
|
|
@@ -18779,7 +18796,7 @@ function registerGetEventStream(router) {
|
|
|
18779
18796
|
logger2.info("Client connecting to resource events stream", {
|
|
18780
18797
|
resourceId: rId
|
|
18781
18798
|
});
|
|
18782
|
-
const { eventStore } = c.get("makeMeaning");
|
|
18799
|
+
const { knowledgeSystem: { kb: { eventStore } } } = c.get("makeMeaning");
|
|
18783
18800
|
const query = new EventQuery(eventStore.log.storage);
|
|
18784
18801
|
const events = await query.getResourceEvents(rId);
|
|
18785
18802
|
if (events.length === 0) {
|
|
@@ -18928,7 +18945,7 @@ function registerCreateAnnotation(router) {
|
|
|
18928
18945
|
const eventBus2 = c.get("eventBus");
|
|
18929
18946
|
eventBus2.get("mark:create").next({
|
|
18930
18947
|
annotation,
|
|
18931
|
-
userId: userId(user
|
|
18948
|
+
userId: userId(userToDid(user)),
|
|
18932
18949
|
resourceId: resourceId(id)
|
|
18933
18950
|
});
|
|
18934
18951
|
return c.json({
|
|
@@ -18974,7 +18991,7 @@ function registerDeleteAnnotation(router) {
|
|
|
18974
18991
|
const eventBus2 = c.get("eventBus");
|
|
18975
18992
|
eventBus2.get("mark:delete").next({
|
|
18976
18993
|
annotationId: annotationId(annotationIdParam),
|
|
18977
|
-
userId: userId(user
|
|
18994
|
+
userId: userId(userToDid(user)),
|
|
18978
18995
|
resourceId: resourceId(resourceIdParam)
|
|
18979
18996
|
});
|
|
18980
18997
|
return c.body(null, 202);
|
|
@@ -18990,7 +19007,7 @@ function registerUpdateAnnotationBody(router) {
|
|
|
18990
19007
|
eventBus2.get("mark:update-body").next({
|
|
18991
19008
|
annotationId: annotationId(annotationIdParam),
|
|
18992
19009
|
resourceId: resourceId(resourceIdParam),
|
|
18993
|
-
userId: userId(user
|
|
19010
|
+
userId: userId(userToDid(user)),
|
|
18994
19011
|
operations: request.operations
|
|
18995
19012
|
});
|
|
18996
19013
|
return c.body(null, 202);
|
|
@@ -19017,7 +19034,7 @@ function registerYieldResourceStream(router, jobQueue) {
|
|
|
19017
19034
|
});
|
|
19018
19035
|
}
|
|
19019
19036
|
const eventBus2 = c.get("eventBus");
|
|
19020
|
-
const { kb } = c.get("makeMeaning");
|
|
19037
|
+
const { knowledgeSystem: { kb } } = c.get("makeMeaning");
|
|
19021
19038
|
logger2.info("Starting resource generation", {
|
|
19022
19039
|
language: body.language
|
|
19023
19040
|
});
|
|
@@ -19053,7 +19070,7 @@ function registerYieldResourceStream(router, jobQueue) {
|
|
|
19053
19070
|
metadata: {
|
|
19054
19071
|
id: jobId(`job-${nanoid()}`),
|
|
19055
19072
|
type: "generation",
|
|
19056
|
-
userId: userId(user
|
|
19073
|
+
userId: userId(userToDid(user)),
|
|
19057
19074
|
userName: user.name || user.email,
|
|
19058
19075
|
userEmail: user.email,
|
|
19059
19076
|
userDomain: user.domain,
|
|
@@ -19214,15 +19231,130 @@ function registerYieldResourceStream(router, jobQueue) {
|
|
|
19214
19231
|
});
|
|
19215
19232
|
}
|
|
19216
19233
|
__name(registerYieldResourceStream, "registerYieldResourceStream");
|
|
19234
|
+
init_logger();
|
|
19235
|
+
function registerGatherAnnotationStream(router) {
|
|
19236
|
+
router.post("/resources/:resourceId/annotations/:annotationId/gather-annotation-stream", validateRequestBody("GatherAnnotationStreamRequest"), async (c) => {
|
|
19237
|
+
const { resourceId: resourceIdParam, annotationId: annotationIdParam } = c.req.param();
|
|
19238
|
+
const body = c.get("validatedBody");
|
|
19239
|
+
const contextWindow = body.contextWindow ?? 1e3;
|
|
19240
|
+
const eventBus2 = c.get("eventBus");
|
|
19241
|
+
const logger2 = getLogger().child({
|
|
19242
|
+
component: "gather-annotation-stream",
|
|
19243
|
+
resourceId: resourceIdParam,
|
|
19244
|
+
annotationId: annotationIdParam
|
|
19245
|
+
});
|
|
19246
|
+
const user = c.get("user");
|
|
19247
|
+
if (!user) {
|
|
19248
|
+
throw new HTTPException(401, {
|
|
19249
|
+
message: "Authentication required"
|
|
19250
|
+
});
|
|
19251
|
+
}
|
|
19252
|
+
eventBus2.get("gather:requested").next({
|
|
19253
|
+
annotationId: annotationId(annotationIdParam),
|
|
19254
|
+
resourceId: resourceId(resourceIdParam),
|
|
19255
|
+
options: {
|
|
19256
|
+
includeSourceContext: true,
|
|
19257
|
+
includeTargetContext: true,
|
|
19258
|
+
contextWindow
|
|
19259
|
+
}
|
|
19260
|
+
});
|
|
19261
|
+
logger2.info("Emitted gather:requested", {
|
|
19262
|
+
annotationId: annotationIdParam,
|
|
19263
|
+
contextWindow
|
|
19264
|
+
});
|
|
19265
|
+
c.header("X-Accel-Buffering", "no");
|
|
19266
|
+
c.header("Cache-Control", "no-cache, no-transform");
|
|
19267
|
+
return streamSSE(c, async (stream) => {
|
|
19268
|
+
let isStreamClosed = false;
|
|
19269
|
+
const subscriptions = [];
|
|
19270
|
+
let keepAliveInterval = null;
|
|
19271
|
+
const streamPromise = new Promise((resolve) => {
|
|
19272
|
+
const cleanup = /* @__PURE__ */ __name(() => {
|
|
19273
|
+
if (isStreamClosed) return;
|
|
19274
|
+
isStreamClosed = true;
|
|
19275
|
+
if (keepAliveInterval) clearInterval(keepAliveInterval);
|
|
19276
|
+
subscriptions.forEach((sub) => sub.unsubscribe());
|
|
19277
|
+
resolve();
|
|
19278
|
+
}, "cleanup");
|
|
19279
|
+
subscriptions.push(eventBus2.get("gather:annotation-progress").subscribe(async (event) => {
|
|
19280
|
+
if (isStreamClosed) return;
|
|
19281
|
+
try {
|
|
19282
|
+
await writeTypedSSE(stream, {
|
|
19283
|
+
data: JSON.stringify({
|
|
19284
|
+
message: event.message,
|
|
19285
|
+
percentage: event.percentage
|
|
19286
|
+
}),
|
|
19287
|
+
event: "gather:annotation-progress",
|
|
19288
|
+
id: String(Date.now())
|
|
19289
|
+
});
|
|
19290
|
+
} catch {
|
|
19291
|
+
cleanup();
|
|
19292
|
+
}
|
|
19293
|
+
}));
|
|
19294
|
+
subscriptions.push(eventBus2.get("gather:complete").subscribe(async (event) => {
|
|
19295
|
+
if (event.annotationId !== annotationIdParam) return;
|
|
19296
|
+
if (isStreamClosed) return;
|
|
19297
|
+
try {
|
|
19298
|
+
await writeTypedSSE(stream, {
|
|
19299
|
+
data: JSON.stringify({
|
|
19300
|
+
annotationId: event.annotationId,
|
|
19301
|
+
response: event.response
|
|
19302
|
+
}),
|
|
19303
|
+
event: "gather:annotation-finished",
|
|
19304
|
+
id: String(Date.now())
|
|
19305
|
+
});
|
|
19306
|
+
} catch {
|
|
19307
|
+
}
|
|
19308
|
+
cleanup();
|
|
19309
|
+
}));
|
|
19310
|
+
subscriptions.push(eventBus2.get("gather:failed").subscribe(async (event) => {
|
|
19311
|
+
if (event.annotationId !== annotationIdParam) return;
|
|
19312
|
+
if (isStreamClosed) return;
|
|
19313
|
+
try {
|
|
19314
|
+
await writeTypedSSE(stream, {
|
|
19315
|
+
data: JSON.stringify({
|
|
19316
|
+
annotationId: event.annotationId,
|
|
19317
|
+
error: event.error
|
|
19318
|
+
}),
|
|
19319
|
+
event: "gather:failed",
|
|
19320
|
+
id: String(Date.now())
|
|
19321
|
+
});
|
|
19322
|
+
} catch {
|
|
19323
|
+
}
|
|
19324
|
+
cleanup();
|
|
19325
|
+
}));
|
|
19326
|
+
keepAliveInterval = setInterval(async () => {
|
|
19327
|
+
if (isStreamClosed) {
|
|
19328
|
+
clearInterval(keepAliveInterval);
|
|
19329
|
+
return;
|
|
19330
|
+
}
|
|
19331
|
+
try {
|
|
19332
|
+
await stream.writeSSE({
|
|
19333
|
+
data: ":keep-alive"
|
|
19334
|
+
});
|
|
19335
|
+
} catch {
|
|
19336
|
+
cleanup();
|
|
19337
|
+
}
|
|
19338
|
+
}, 3e4);
|
|
19339
|
+
c.req.raw.signal.addEventListener("abort", () => {
|
|
19340
|
+
logger2.info("Client disconnected from gather stream");
|
|
19341
|
+
cleanup();
|
|
19342
|
+
});
|
|
19343
|
+
});
|
|
19344
|
+
return streamPromise;
|
|
19345
|
+
});
|
|
19346
|
+
});
|
|
19347
|
+
}
|
|
19348
|
+
__name(registerGatherAnnotationStream, "registerGatherAnnotationStream");
|
|
19217
19349
|
function registerGetAnnotationHistory(router) {
|
|
19218
19350
|
router.get("/resources/:resourceId/annotations/:annotationId/history", async (c) => {
|
|
19219
|
-
const { resourceId:
|
|
19351
|
+
const { resourceId: resourceId20, annotationId: annotationId6 } = c.req.param();
|
|
19220
19352
|
const eventBus2 = c.get("eventBus");
|
|
19221
19353
|
const correlationId = crypto.randomUUID();
|
|
19222
19354
|
try {
|
|
19223
19355
|
const response = await eventBusRequest(eventBus2, "browse:annotation-history-requested", {
|
|
19224
19356
|
correlationId,
|
|
19225
|
-
resourceId: resourceId(
|
|
19357
|
+
resourceId: resourceId(resourceId20),
|
|
19226
19358
|
annotationId: annotationId(annotationId6)
|
|
19227
19359
|
}, "browse:annotation-history-result", "browse:annotation-history-failed");
|
|
19228
19360
|
return c.json(response);
|
|
@@ -19261,8 +19393,6 @@ function createResourcesRouter(jobQueue) {
|
|
|
19261
19393
|
registerAnnotateAssessmentsStream(resourcesRouter2, jobQueue);
|
|
19262
19394
|
registerAnnotateCommentsStream(resourcesRouter2, jobQueue);
|
|
19263
19395
|
registerAnnotateTagsStream(resourcesRouter2, jobQueue);
|
|
19264
|
-
registerGetResourceLLMContext(resourcesRouter2);
|
|
19265
|
-
registerGetAnnotationLLMContext(resourcesRouter2);
|
|
19266
19396
|
registerGetReferencedBy(resourcesRouter2);
|
|
19267
19397
|
registerBindSearchStream(resourcesRouter2);
|
|
19268
19398
|
registerGetResourceAnnotations(resourcesRouter2);
|
|
@@ -19270,6 +19400,7 @@ function createResourcesRouter(jobQueue) {
|
|
|
19270
19400
|
registerGetAnnotation(resourcesRouter2);
|
|
19271
19401
|
registerUpdateAnnotationBody(resourcesRouter2);
|
|
19272
19402
|
registerYieldResourceStream(resourcesRouter2, jobQueue);
|
|
19403
|
+
registerGatherAnnotationStream(resourcesRouter2);
|
|
19273
19404
|
registerGetAnnotationHistory(resourcesRouter2);
|
|
19274
19405
|
registerDeleteAnnotation(resourcesRouter2);
|
|
19275
19406
|
registerGetEvents(resourcesRouter2);
|
|
@@ -19290,7 +19421,7 @@ function registerGetAnnotationUri(router) {
|
|
|
19290
19421
|
router.get("/annotations/:id", async (c) => {
|
|
19291
19422
|
const { id } = c.req.param();
|
|
19292
19423
|
const query = c.req.query();
|
|
19293
|
-
const { kb } = c.get("makeMeaning");
|
|
19424
|
+
const { knowledgeSystem: { kb } } = c.get("makeMeaning");
|
|
19294
19425
|
const resourceIdParam = query.resourceId;
|
|
19295
19426
|
if (!resourceIdParam) {
|
|
19296
19427
|
throw new HTTPException(400, {
|
|
@@ -19330,9 +19461,9 @@ var operationsRouter = createAnnotationRouter();
|
|
|
19330
19461
|
operationsRouter.get("/api/annotations/:id/context", async (c) => {
|
|
19331
19462
|
const { id } = c.req.param();
|
|
19332
19463
|
const query = c.req.query();
|
|
19333
|
-
const { kb } = c.get("makeMeaning");
|
|
19334
|
-
const
|
|
19335
|
-
if (!
|
|
19464
|
+
const { knowledgeSystem: { kb } } = c.get("makeMeaning");
|
|
19465
|
+
const resourceId20 = query.resourceId;
|
|
19466
|
+
if (!resourceId20) {
|
|
19336
19467
|
throw new HTTPException(400, {
|
|
19337
19468
|
message: "resourceId query parameter is required"
|
|
19338
19469
|
});
|
|
@@ -19350,7 +19481,7 @@ operationsRouter.get("/api/annotations/:id/context", async (c) => {
|
|
|
19350
19481
|
});
|
|
19351
19482
|
}
|
|
19352
19483
|
try {
|
|
19353
|
-
const response = await AnnotationContext.getAnnotationContext(annotationId(id), resourceId(
|
|
19484
|
+
const response = await AnnotationContext.getAnnotationContext(annotationId(id), resourceId(resourceId20), contextBefore, contextAfter, kb);
|
|
19354
19485
|
return c.json(response);
|
|
19355
19486
|
} catch (error) {
|
|
19356
19487
|
if (error instanceof Error && error.message === "Annotation not found") {
|
|
@@ -19379,15 +19510,15 @@ operationsRouter.get("/api/annotations/:id/context", async (c) => {
|
|
|
19379
19510
|
operationsRouter.get("/api/annotations/:id/summary", async (c) => {
|
|
19380
19511
|
const { id } = c.req.param();
|
|
19381
19512
|
const query = c.req.query();
|
|
19382
|
-
const {
|
|
19383
|
-
const
|
|
19384
|
-
if (!
|
|
19513
|
+
const { knowledgeSystem: { gatherer } } = c.get("makeMeaning");
|
|
19514
|
+
const resourceId20 = query.resourceId;
|
|
19515
|
+
if (!resourceId20) {
|
|
19385
19516
|
throw new HTTPException(400, {
|
|
19386
19517
|
message: "resourceId query parameter is required"
|
|
19387
19518
|
});
|
|
19388
19519
|
}
|
|
19389
19520
|
try {
|
|
19390
|
-
const response = await
|
|
19521
|
+
const response = await gatherer.generateAnnotationSummary(annotationId(id), resourceId(resourceId20));
|
|
19391
19522
|
return c.json(response);
|
|
19392
19523
|
} catch (error) {
|
|
19393
19524
|
if (error instanceof Error && error.message === "Annotation not found") {
|
|
@@ -19420,9 +19551,9 @@ entityTypesRouter.use("/api/entity-types/*", authMiddleware);
|
|
|
19420
19551
|
entityTypesRouter.get("/api/entity-types", async (c) => {
|
|
19421
19552
|
const eventBus2 = c.get("eventBus");
|
|
19422
19553
|
const correlationId = crypto.randomUUID();
|
|
19423
|
-
const response = await eventBusRequest(eventBus2, "
|
|
19554
|
+
const response = await eventBusRequest(eventBus2, "browse:entity-types-requested", {
|
|
19424
19555
|
correlationId
|
|
19425
|
-
}, "
|
|
19556
|
+
}, "browse:entity-types-result", "browse:entity-types-failed");
|
|
19426
19557
|
return c.json(response, 200);
|
|
19427
19558
|
});
|
|
19428
19559
|
entityTypesRouter.post("/api/entity-types", validateRequestBody("AddEntityTypeRequest"), async (c) => {
|
|
@@ -19436,7 +19567,7 @@ entityTypesRouter.post("/api/entity-types", validateRequestBody("AddEntityTypeRe
|
|
|
19436
19567
|
const eventBus2 = c.get("eventBus");
|
|
19437
19568
|
eventBus2.get("mark:add-entity-type").next({
|
|
19438
19569
|
tag: body.tag,
|
|
19439
|
-
userId: userId(user
|
|
19570
|
+
userId: userId(userToDid(user))
|
|
19440
19571
|
});
|
|
19441
19572
|
return c.body(null, 202);
|
|
19442
19573
|
});
|
|
@@ -19452,7 +19583,7 @@ entityTypesRouter.post("/api/entity-types/bulk", validateRequestBody("BulkAddEnt
|
|
|
19452
19583
|
for (const tag of body.tags) {
|
|
19453
19584
|
eventBus2.get("mark:add-entity-type").next({
|
|
19454
19585
|
tag,
|
|
19455
|
-
userId: userId(user
|
|
19586
|
+
userId: userId(userToDid(user))
|
|
19456
19587
|
});
|
|
19457
19588
|
}
|
|
19458
19589
|
return c.body(null, 202);
|
|
@@ -19466,7 +19597,7 @@ globalEventsRouter.use("/api/events/stream", authMiddleware);
|
|
|
19466
19597
|
globalEventsRouter.get("/api/events/stream", async (c) => {
|
|
19467
19598
|
const logger2 = getRouteLogger4();
|
|
19468
19599
|
logger2.info("Client connecting to global events stream");
|
|
19469
|
-
const { eventStore } = c.get("makeMeaning");
|
|
19600
|
+
const { knowledgeSystem: { kb: { eventStore } } } = c.get("makeMeaning");
|
|
19470
19601
|
return streamSSE(c, async (stream) => {
|
|
19471
19602
|
await stream.writeSSE({
|
|
19472
19603
|
data: JSON.stringify({
|
|
@@ -19593,11 +19724,11 @@ function createJobsRouter(_jobQueue, authMiddleware2) {
|
|
|
19593
19724
|
__name(createJobsRouter, "createJobsRouter");
|
|
19594
19725
|
|
|
19595
19726
|
// src/routes/participants/attention-channels.ts
|
|
19596
|
-
var
|
|
19727
|
+
var import_rxjs2 = __toESM(require_cjs());
|
|
19597
19728
|
var channels = /* @__PURE__ */ new Map();
|
|
19598
19729
|
function getOrCreateChannel(participantId) {
|
|
19599
19730
|
if (!channels.has(participantId)) {
|
|
19600
|
-
channels.set(participantId, new
|
|
19731
|
+
channels.set(participantId, new import_rxjs2.Subject());
|
|
19601
19732
|
}
|
|
19602
19733
|
return channels.get(participantId);
|
|
19603
19734
|
}
|
|
@@ -19707,6 +19838,46 @@ var participantsRouter = new Hono();
|
|
|
19707
19838
|
participantsRouter.use("/api/participants/*", authMiddleware);
|
|
19708
19839
|
registerBeckon(participantsRouter);
|
|
19709
19840
|
registerAttentionStream(participantsRouter);
|
|
19841
|
+
var browseRouter = new Hono();
|
|
19842
|
+
browseRouter.use("/api/browse/*", authMiddleware);
|
|
19843
|
+
browseRouter.get("/api/browse/files", async (c) => {
|
|
19844
|
+
const reqPath = c.req.query("path") ?? "";
|
|
19845
|
+
const sort = c.req.query("sort");
|
|
19846
|
+
if (sort !== void 0 && sort !== "name" && sort !== "mtime" && sort !== "annotationCount") {
|
|
19847
|
+
throw new HTTPException(400, {
|
|
19848
|
+
message: 'Invalid sort value. Must be "name", "mtime", or "annotationCount".'
|
|
19849
|
+
});
|
|
19850
|
+
}
|
|
19851
|
+
const eventBus2 = c.get("eventBus");
|
|
19852
|
+
const correlationId = crypto.randomUUID();
|
|
19853
|
+
try {
|
|
19854
|
+
const response = await eventBusRequest(eventBus2, "browse:directory-requested", {
|
|
19855
|
+
correlationId,
|
|
19856
|
+
path: reqPath,
|
|
19857
|
+
sort
|
|
19858
|
+
}, "browse:directory-result", "browse:directory-failed");
|
|
19859
|
+
return c.json(response);
|
|
19860
|
+
} catch (error) {
|
|
19861
|
+
if (error instanceof Error) {
|
|
19862
|
+
if (error.name === "TimeoutError") {
|
|
19863
|
+
throw new HTTPException(504, {
|
|
19864
|
+
message: "Request timed out"
|
|
19865
|
+
});
|
|
19866
|
+
}
|
|
19867
|
+
if (error.message === "path not found") {
|
|
19868
|
+
throw new HTTPException(404, {
|
|
19869
|
+
message: error.message
|
|
19870
|
+
});
|
|
19871
|
+
}
|
|
19872
|
+
if (error.message === "path escapes project root") {
|
|
19873
|
+
throw new HTTPException(400, {
|
|
19874
|
+
message: error.message
|
|
19875
|
+
});
|
|
19876
|
+
}
|
|
19877
|
+
}
|
|
19878
|
+
throw error;
|
|
19879
|
+
}
|
|
19880
|
+
});
|
|
19710
19881
|
|
|
19711
19882
|
// src/middleware/security-headers.ts
|
|
19712
19883
|
var securityHeaders = /* @__PURE__ */ __name(() => {
|
|
@@ -19873,6 +20044,7 @@ app.route("/", globalEventsRouter);
|
|
|
19873
20044
|
var jobsRouter = createJobsRouter(makeMeaning.jobQueue, authMiddleware);
|
|
19874
20045
|
app.route("/", jobsRouter);
|
|
19875
20046
|
app.route("/", participantsRouter);
|
|
20047
|
+
app.route("/", browseRouter);
|
|
19876
20048
|
app.get("/api", (c) => {
|
|
19877
20049
|
const acceptHeader = c.req.header("Accept") || "";
|
|
19878
20050
|
const userAgent = c.req.header("User-Agent") || "";
|
|
@@ -19885,7 +20057,8 @@ app.get("/api", (c) => {
|
|
|
19885
20057
|
return c.redirect(redirectUrl);
|
|
19886
20058
|
});
|
|
19887
20059
|
app.get("/api/openapi.json", (c) => {
|
|
19888
|
-
const
|
|
20060
|
+
const distPath = path.join(__dirname$1, "openapi.json");
|
|
20061
|
+
const openApiPath = fs.existsSync(distPath) ? distPath : path.join(__dirname$1, "../../../specs/openapi.json");
|
|
19889
20062
|
const openApiContent = fs.readFileSync(openApiPath, "utf-8");
|
|
19890
20063
|
const openApiSpec = JSON.parse(openApiContent);
|
|
19891
20064
|
const port2 = backendService.port || 4e3;
|
|
@@ -19952,7 +20125,7 @@ if (config.env?.NODE_ENV !== "test") {
|
|
|
19952
20125
|
});
|
|
19953
20126
|
}
|
|
19954
20127
|
try {
|
|
19955
|
-
const entityTypes = await makeMeaning.
|
|
20128
|
+
const entityTypes = await makeMeaning.knowledgeSystem.kb.graph.getEntityTypes();
|
|
19956
20129
|
logger.info("Loaded entity types from graph database", {
|
|
19957
20130
|
count: entityTypes.length
|
|
19958
20131
|
});
|