@remnic/core 1.1.22 → 1.1.24
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/access-cli.js +15 -15
- package/dist/access-http.d.ts +9 -1
- package/dist/access-http.js +9 -9
- package/dist/access-mcp.d.ts +1 -1
- package/dist/access-mcp.js +8 -8
- package/dist/access-schema.js +3 -3
- package/dist/{access-service-DT9L2DW4.d.ts → access-service-CEyV8XJ5.d.ts} +19 -2
- package/dist/access-service.d.ts +1 -1
- package/dist/access-service.js +6 -6
- package/dist/briefing.js +3 -3
- package/dist/causal-consolidation.js +4 -4
- package/dist/{chunk-YO3AZEE5.js → chunk-25YQM6XW.js} +3 -3
- package/dist/{chunk-LDJANWTK.js → chunk-2DM72JF3.js} +12 -12
- package/dist/{chunk-TLM762GT.js → chunk-2WIPXV3Y.js} +2 -2
- package/dist/{chunk-QOHBYVZG.js → chunk-3F24QTRI.js} +2 -2
- package/dist/{chunk-5IQC4OG6.js → chunk-4H6DURG6.js} +2 -2
- package/dist/{chunk-26OQECWH.js → chunk-6CB4E7ZV.js} +4 -4
- package/dist/{chunk-NOQ74SJN.js → chunk-7D6O46PF.js} +2 -2
- package/dist/{chunk-FF46Q3SN.js → chunk-AMVN77EU.js} +360 -32
- package/dist/chunk-AMVN77EU.js.map +1 -0
- package/dist/{chunk-7Q2P774N.js → chunk-F33CJ5CH.js} +13 -3
- package/dist/chunk-F33CJ5CH.js.map +1 -0
- package/dist/{chunk-FSODDMR2.js → chunk-IANK6Y5W.js} +2 -2
- package/dist/{chunk-UA6OCL6S.js → chunk-JUYT2J3K.js} +106 -11
- package/dist/chunk-JUYT2J3K.js.map +1 -0
- package/dist/{chunk-NGPO6S3M.js → chunk-LCTP7YRU.js} +42 -5
- package/dist/chunk-LCTP7YRU.js.map +1 -0
- package/dist/{chunk-GGCJ253V.js → chunk-MVAOT247.js} +8 -8
- package/dist/{chunk-SH5S7XYD.js → chunk-MXFBBHJU.js} +72 -2
- package/dist/chunk-MXFBBHJU.js.map +1 -0
- package/dist/{chunk-VMQRBXJ5.js → chunk-NW7JW5GA.js} +2 -2
- package/dist/{chunk-SZKCBLS5.js → chunk-PUXCIHRL.js} +2 -2
- package/dist/{chunk-2IRT26RZ.js → chunk-QYHQ2JHL.js} +2 -2
- package/dist/{chunk-CN4P6SVA.js → chunk-RCZRL5BE.js} +2 -2
- package/dist/{chunk-SGIXDVSF.js → chunk-S27EXIHY.js} +2 -2
- package/dist/{chunk-5ML4TH3E.js → chunk-TFORLO3O.js} +4 -4
- package/dist/{chunk-TOFUTKQN.js → chunk-TR4DK5OH.js} +2 -2
- package/dist/{chunk-6ORWKANA.js → chunk-VYU7PXUS.js} +2 -2
- package/dist/{chunk-FFU4GMST.js → chunk-WNARATI3.js} +2 -2
- package/dist/{chunk-KSFBM6TV.js → chunk-YITUHONZ.js} +2 -2
- package/dist/{cli-BN0CkYzI.d.ts → cli-BguVmIwO.d.ts} +1 -1
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +18 -18
- package/dist/compounding/engine.js +3 -3
- package/dist/connectors/codex-materialize-runner.js +3 -3
- package/dist/connectors/index.js +3 -3
- package/dist/entity-retrieval.js +3 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.js +30 -24
- package/dist/index.js.map +1 -1
- package/dist/maintenance/memory-governance.js +3 -3
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +3 -3
- package/dist/maintenance/rebuild-memory-projection.js +4 -4
- package/dist/mcp-memory-inspector-app.d.ts +1 -1
- package/dist/namespaces/migrate.js +4 -4
- package/dist/namespaces/storage.js +3 -3
- package/dist/offline-sync.d.ts +38 -1
- package/dist/offline-sync.js +8 -2
- package/dist/operator-toolkit.js +6 -6
- package/dist/orchestrator.js +11 -11
- package/dist/schemas.d.ts +22 -22
- package/dist/secure-store/index.js +2 -2
- package/dist/semantic-consolidation.js +4 -4
- package/dist/semantic-rule-promotion.js +3 -3
- package/dist/semantic-rule-verifier.js +3 -3
- package/dist/storage.d.ts +2 -0
- package/dist/storage.js +2 -2
- package/dist/transfer/types.d.ts +12 -12
- package/dist/verified-recall.js +3 -3
- package/package.json +1 -1
- package/src/access-http.test.ts +239 -0
- package/src/access-http.ts +128 -7
- package/src/access-service-offline-file-content.test.ts +37 -0
- package/src/access-service.ts +70 -0
- package/src/index.ts +4 -0
- package/src/offline-sync.test.ts +395 -79
- package/src/offline-sync.ts +473 -32
- package/src/secure-store/secure-fs.ts +84 -3
- package/src/storage.ts +12 -0
- package/dist/chunk-7Q2P774N.js.map +0 -1
- package/dist/chunk-FF46Q3SN.js.map +0 -1
- package/dist/chunk-NGPO6S3M.js.map +0 -1
- package/dist/chunk-SH5S7XYD.js.map +0 -1
- package/dist/chunk-UA6OCL6S.js.map +0 -1
- /package/dist/{chunk-YO3AZEE5.js.map → chunk-25YQM6XW.js.map} +0 -0
- /package/dist/{chunk-LDJANWTK.js.map → chunk-2DM72JF3.js.map} +0 -0
- /package/dist/{chunk-TLM762GT.js.map → chunk-2WIPXV3Y.js.map} +0 -0
- /package/dist/{chunk-QOHBYVZG.js.map → chunk-3F24QTRI.js.map} +0 -0
- /package/dist/{chunk-5IQC4OG6.js.map → chunk-4H6DURG6.js.map} +0 -0
- /package/dist/{chunk-26OQECWH.js.map → chunk-6CB4E7ZV.js.map} +0 -0
- /package/dist/{chunk-NOQ74SJN.js.map → chunk-7D6O46PF.js.map} +0 -0
- /package/dist/{chunk-FSODDMR2.js.map → chunk-IANK6Y5W.js.map} +0 -0
- /package/dist/{chunk-GGCJ253V.js.map → chunk-MVAOT247.js.map} +0 -0
- /package/dist/{chunk-VMQRBXJ5.js.map → chunk-NW7JW5GA.js.map} +0 -0
- /package/dist/{chunk-SZKCBLS5.js.map → chunk-PUXCIHRL.js.map} +0 -0
- /package/dist/{chunk-2IRT26RZ.js.map → chunk-QYHQ2JHL.js.map} +0 -0
- /package/dist/{chunk-CN4P6SVA.js.map → chunk-RCZRL5BE.js.map} +0 -0
- /package/dist/{chunk-SGIXDVSF.js.map → chunk-S27EXIHY.js.map} +0 -0
- /package/dist/{chunk-5ML4TH3E.js.map → chunk-TFORLO3O.js.map} +0 -0
- /package/dist/{chunk-TOFUTKQN.js.map → chunk-TR4DK5OH.js.map} +0 -0
- /package/dist/{chunk-6ORWKANA.js.map → chunk-VYU7PXUS.js.map} +0 -0
- /package/dist/{chunk-FFU4GMST.js.map → chunk-WNARATI3.js.map} +0 -0
- /package/dist/{chunk-KSFBM6TV.js.map → chunk-YITUHONZ.js.map} +0 -0
package/dist/transfer/types.d.ts
CHANGED
|
@@ -313,13 +313,13 @@ declare const CapsuleBlockSchema: z.ZodObject<{
|
|
|
313
313
|
peerProfiles: boolean;
|
|
314
314
|
}>;
|
|
315
315
|
}, "strip", z.ZodTypeAny, {
|
|
316
|
-
schemaVersion: string;
|
|
317
316
|
includes: {
|
|
318
317
|
procedural: boolean;
|
|
319
318
|
taxonomy: boolean;
|
|
320
319
|
identityAnchors: boolean;
|
|
321
320
|
peerProfiles: boolean;
|
|
322
321
|
};
|
|
322
|
+
schemaVersion: string;
|
|
323
323
|
id: string;
|
|
324
324
|
description: string;
|
|
325
325
|
version: string;
|
|
@@ -334,13 +334,13 @@ declare const CapsuleBlockSchema: z.ZodObject<{
|
|
|
334
334
|
directAnswerEnabled: boolean;
|
|
335
335
|
};
|
|
336
336
|
}, {
|
|
337
|
-
schemaVersion: string;
|
|
338
337
|
includes: {
|
|
339
338
|
procedural: boolean;
|
|
340
339
|
taxonomy: boolean;
|
|
341
340
|
identityAnchors: boolean;
|
|
342
341
|
peerProfiles: boolean;
|
|
343
342
|
};
|
|
343
|
+
schemaVersion: string;
|
|
344
344
|
id: string;
|
|
345
345
|
description: string;
|
|
346
346
|
version: string;
|
|
@@ -464,13 +464,13 @@ declare const ExportManifestV2Schema: z.ZodObject<{
|
|
|
464
464
|
peerProfiles: boolean;
|
|
465
465
|
}>;
|
|
466
466
|
}, "strip", z.ZodTypeAny, {
|
|
467
|
-
schemaVersion: string;
|
|
468
467
|
includes: {
|
|
469
468
|
procedural: boolean;
|
|
470
469
|
taxonomy: boolean;
|
|
471
470
|
identityAnchors: boolean;
|
|
472
471
|
peerProfiles: boolean;
|
|
473
472
|
};
|
|
473
|
+
schemaVersion: string;
|
|
474
474
|
id: string;
|
|
475
475
|
description: string;
|
|
476
476
|
version: string;
|
|
@@ -485,13 +485,13 @@ declare const ExportManifestV2Schema: z.ZodObject<{
|
|
|
485
485
|
directAnswerEnabled: boolean;
|
|
486
486
|
};
|
|
487
487
|
}, {
|
|
488
|
-
schemaVersion: string;
|
|
489
488
|
includes: {
|
|
490
489
|
procedural: boolean;
|
|
491
490
|
taxonomy: boolean;
|
|
492
491
|
identityAnchors: boolean;
|
|
493
492
|
peerProfiles: boolean;
|
|
494
493
|
};
|
|
494
|
+
schemaVersion: string;
|
|
495
495
|
id: string;
|
|
496
496
|
description: string;
|
|
497
497
|
version: string;
|
|
@@ -518,13 +518,13 @@ declare const ExportManifestV2Schema: z.ZodObject<{
|
|
|
518
518
|
pluginVersion: string;
|
|
519
519
|
includesTranscripts: boolean;
|
|
520
520
|
capsule: {
|
|
521
|
-
schemaVersion: string;
|
|
522
521
|
includes: {
|
|
523
522
|
procedural: boolean;
|
|
524
523
|
taxonomy: boolean;
|
|
525
524
|
identityAnchors: boolean;
|
|
526
525
|
peerProfiles: boolean;
|
|
527
526
|
};
|
|
527
|
+
schemaVersion: string;
|
|
528
528
|
id: string;
|
|
529
529
|
description: string;
|
|
530
530
|
version: string;
|
|
@@ -551,13 +551,13 @@ declare const ExportManifestV2Schema: z.ZodObject<{
|
|
|
551
551
|
pluginVersion: string;
|
|
552
552
|
includesTranscripts: boolean;
|
|
553
553
|
capsule: {
|
|
554
|
-
schemaVersion: string;
|
|
555
554
|
includes: {
|
|
556
555
|
procedural: boolean;
|
|
557
556
|
taxonomy: boolean;
|
|
558
557
|
identityAnchors: boolean;
|
|
559
558
|
peerProfiles: boolean;
|
|
560
559
|
};
|
|
560
|
+
schemaVersion: string;
|
|
561
561
|
id: string;
|
|
562
562
|
description: string;
|
|
563
563
|
version: string;
|
|
@@ -683,13 +683,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
|
|
|
683
683
|
peerProfiles: boolean;
|
|
684
684
|
}>;
|
|
685
685
|
}, "strip", z.ZodTypeAny, {
|
|
686
|
-
schemaVersion: string;
|
|
687
686
|
includes: {
|
|
688
687
|
procedural: boolean;
|
|
689
688
|
taxonomy: boolean;
|
|
690
689
|
identityAnchors: boolean;
|
|
691
690
|
peerProfiles: boolean;
|
|
692
691
|
};
|
|
692
|
+
schemaVersion: string;
|
|
693
693
|
id: string;
|
|
694
694
|
description: string;
|
|
695
695
|
version: string;
|
|
@@ -704,13 +704,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
|
|
|
704
704
|
directAnswerEnabled: boolean;
|
|
705
705
|
};
|
|
706
706
|
}, {
|
|
707
|
-
schemaVersion: string;
|
|
708
707
|
includes: {
|
|
709
708
|
procedural: boolean;
|
|
710
709
|
taxonomy: boolean;
|
|
711
710
|
identityAnchors: boolean;
|
|
712
711
|
peerProfiles: boolean;
|
|
713
712
|
};
|
|
713
|
+
schemaVersion: string;
|
|
714
714
|
id: string;
|
|
715
715
|
description: string;
|
|
716
716
|
version: string;
|
|
@@ -737,13 +737,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
|
|
|
737
737
|
pluginVersion: string;
|
|
738
738
|
includesTranscripts: boolean;
|
|
739
739
|
capsule: {
|
|
740
|
-
schemaVersion: string;
|
|
741
740
|
includes: {
|
|
742
741
|
procedural: boolean;
|
|
743
742
|
taxonomy: boolean;
|
|
744
743
|
identityAnchors: boolean;
|
|
745
744
|
peerProfiles: boolean;
|
|
746
745
|
};
|
|
746
|
+
schemaVersion: string;
|
|
747
747
|
id: string;
|
|
748
748
|
description: string;
|
|
749
749
|
version: string;
|
|
@@ -770,13 +770,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
|
|
|
770
770
|
pluginVersion: string;
|
|
771
771
|
includesTranscripts: boolean;
|
|
772
772
|
capsule: {
|
|
773
|
-
schemaVersion: string;
|
|
774
773
|
includes: {
|
|
775
774
|
procedural: boolean;
|
|
776
775
|
taxonomy: boolean;
|
|
777
776
|
identityAnchors: boolean;
|
|
778
777
|
peerProfiles: boolean;
|
|
779
778
|
};
|
|
779
|
+
schemaVersion: string;
|
|
780
780
|
id: string;
|
|
781
781
|
description: string;
|
|
782
782
|
version: string;
|
|
@@ -815,13 +815,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
|
|
|
815
815
|
pluginVersion: string;
|
|
816
816
|
includesTranscripts: boolean;
|
|
817
817
|
capsule: {
|
|
818
|
-
schemaVersion: string;
|
|
819
818
|
includes: {
|
|
820
819
|
procedural: boolean;
|
|
821
820
|
taxonomy: boolean;
|
|
822
821
|
identityAnchors: boolean;
|
|
823
822
|
peerProfiles: boolean;
|
|
824
823
|
};
|
|
824
|
+
schemaVersion: string;
|
|
825
825
|
id: string;
|
|
826
826
|
description: string;
|
|
827
827
|
version: string;
|
|
@@ -854,13 +854,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
|
|
|
854
854
|
pluginVersion: string;
|
|
855
855
|
includesTranscripts: boolean;
|
|
856
856
|
capsule: {
|
|
857
|
-
schemaVersion: string;
|
|
858
857
|
includes: {
|
|
859
858
|
procedural: boolean;
|
|
860
859
|
taxonomy: boolean;
|
|
861
860
|
identityAnchors: boolean;
|
|
862
861
|
peerProfiles: boolean;
|
|
863
862
|
};
|
|
863
|
+
schemaVersion: string;
|
|
864
864
|
id: string;
|
|
865
865
|
description: string;
|
|
866
866
|
version: string;
|
package/dist/verified-recall.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
searchVerifiedEpisodes
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4H6DURG6.js";
|
|
4
4
|
import "./chunk-NZL6GGQE.js";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-F33CJ5CH.js";
|
|
6
6
|
import "./chunk-5UZXUTVO.js";
|
|
7
7
|
import "./chunk-NN2DKE4T.js";
|
|
8
8
|
import "./chunk-Q7P4WJDP.js";
|
|
@@ -19,7 +19,7 @@ import "./chunk-FAAFWE4G.js";
|
|
|
19
19
|
import "./chunk-DT5TVLJE.js";
|
|
20
20
|
import "./chunk-4DJQYKMN.js";
|
|
21
21
|
import "./chunk-2ODBA7MQ.js";
|
|
22
|
-
import "./chunk-
|
|
22
|
+
import "./chunk-MXFBBHJU.js";
|
|
23
23
|
import "./chunk-A6XUJE5D.js";
|
|
24
24
|
import "./chunk-P7FMDTKL.js";
|
|
25
25
|
import "./chunk-PZ5AY32C.js";
|
package/package.json
CHANGED
package/src/access-http.test.ts
CHANGED
|
@@ -449,6 +449,182 @@ test("HTTP offline file-content forwards range options and returns binary metada
|
|
|
449
449
|
}
|
|
450
450
|
});
|
|
451
451
|
|
|
452
|
+
test("HTTP offline apply-file-content forwards binary chunks and metadata", async () => {
|
|
453
|
+
const calls: Array<{
|
|
454
|
+
namespace: string | undefined;
|
|
455
|
+
principal: string | undefined;
|
|
456
|
+
includeTranscripts: boolean | undefined;
|
|
457
|
+
sourceId: string;
|
|
458
|
+
path: string;
|
|
459
|
+
sha256: string;
|
|
460
|
+
bytes: number;
|
|
461
|
+
mtimeMs: number;
|
|
462
|
+
offset: number | undefined;
|
|
463
|
+
baseSha256: string | undefined;
|
|
464
|
+
content: string;
|
|
465
|
+
}> = [];
|
|
466
|
+
const service = {
|
|
467
|
+
offlineSyncApplyFileContent: async (options: {
|
|
468
|
+
namespace?: string;
|
|
469
|
+
principal?: string;
|
|
470
|
+
includeTranscripts?: boolean;
|
|
471
|
+
sourceId: string;
|
|
472
|
+
path: string;
|
|
473
|
+
sha256: string;
|
|
474
|
+
bytes: number;
|
|
475
|
+
mtimeMs: number;
|
|
476
|
+
offset?: number;
|
|
477
|
+
baseSha256?: string;
|
|
478
|
+
content: Buffer;
|
|
479
|
+
}) => {
|
|
480
|
+
calls.push({
|
|
481
|
+
namespace: options.namespace,
|
|
482
|
+
principal: options.principal,
|
|
483
|
+
includeTranscripts: options.includeTranscripts,
|
|
484
|
+
sourceId: options.sourceId,
|
|
485
|
+
path: options.path,
|
|
486
|
+
sha256: options.sha256,
|
|
487
|
+
bytes: options.bytes,
|
|
488
|
+
mtimeMs: options.mtimeMs,
|
|
489
|
+
offset: options.offset,
|
|
490
|
+
baseSha256: options.baseSha256,
|
|
491
|
+
content: options.content.toString("utf-8"),
|
|
492
|
+
});
|
|
493
|
+
return {
|
|
494
|
+
namespace: options.namespace ?? "default",
|
|
495
|
+
path: options.path,
|
|
496
|
+
sha256: options.sha256,
|
|
497
|
+
bytes: options.bytes,
|
|
498
|
+
mtimeMs: options.mtimeMs,
|
|
499
|
+
offset: options.offset ?? 0,
|
|
500
|
+
chunkBytes: options.content.length,
|
|
501
|
+
done: true,
|
|
502
|
+
applied: true,
|
|
503
|
+
skipped: false,
|
|
504
|
+
};
|
|
505
|
+
},
|
|
506
|
+
} as unknown as EngramAccessService;
|
|
507
|
+
const server = new EngramAccessHttpServer({
|
|
508
|
+
service,
|
|
509
|
+
port: 0,
|
|
510
|
+
authToken: "test-token",
|
|
511
|
+
principal: "writer",
|
|
512
|
+
adminConsoleEnabled: false,
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
const status = await server.start();
|
|
516
|
+
try {
|
|
517
|
+
const response = await fetch(
|
|
518
|
+
`http://127.0.0.1:${status.port}/remnic/v1/offline-sync/apply-file-content?namespace=team`,
|
|
519
|
+
{
|
|
520
|
+
method: "POST",
|
|
521
|
+
headers: {
|
|
522
|
+
authorization: "Bearer test-token",
|
|
523
|
+
"content-type": "application/octet-stream",
|
|
524
|
+
"x-remnic-include-transcripts": "false",
|
|
525
|
+
"x-remnic-source-id": encodeURIComponent("laptop:test"),
|
|
526
|
+
"x-remnic-file-path": encodeURIComponent("state/lcm.sqlite"),
|
|
527
|
+
"x-remnic-file-sha256": "b".repeat(64),
|
|
528
|
+
"x-remnic-file-bytes": "5",
|
|
529
|
+
"x-remnic-file-mtime-ms": "1234",
|
|
530
|
+
"x-remnic-chunk-offset": "8",
|
|
531
|
+
"x-remnic-base-sha256": "a".repeat(64),
|
|
532
|
+
},
|
|
533
|
+
body: Buffer.from("hello"),
|
|
534
|
+
},
|
|
535
|
+
);
|
|
536
|
+
const body = await response.json() as { namespace?: string; applied?: boolean; chunkBytes?: number };
|
|
537
|
+
|
|
538
|
+
assert.equal(response.status, 200);
|
|
539
|
+
assert.equal(body.namespace, "team");
|
|
540
|
+
assert.equal(body.applied, true);
|
|
541
|
+
assert.equal(body.chunkBytes, 5);
|
|
542
|
+
assert.deepEqual(calls, [{
|
|
543
|
+
namespace: "team",
|
|
544
|
+
principal: "writer",
|
|
545
|
+
includeTranscripts: false,
|
|
546
|
+
sourceId: "laptop:test",
|
|
547
|
+
path: "state/lcm.sqlite",
|
|
548
|
+
sha256: "b".repeat(64),
|
|
549
|
+
bytes: 5,
|
|
550
|
+
mtimeMs: 1234,
|
|
551
|
+
offset: 8,
|
|
552
|
+
baseSha256: "a".repeat(64),
|
|
553
|
+
content: "hello",
|
|
554
|
+
}]);
|
|
555
|
+
} finally {
|
|
556
|
+
await server.stop();
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
test("HTTP offline apply-file-content allows bulk sync chunks outside the generic write throttle", async () => {
|
|
561
|
+
let calls = 0;
|
|
562
|
+
const service = {
|
|
563
|
+
offlineSyncApplyFileContent: async (options: {
|
|
564
|
+
namespace?: string;
|
|
565
|
+
path: string;
|
|
566
|
+
sha256: string;
|
|
567
|
+
bytes: number;
|
|
568
|
+
mtimeMs: number;
|
|
569
|
+
offset?: number;
|
|
570
|
+
content: Buffer;
|
|
571
|
+
}) => {
|
|
572
|
+
calls += 1;
|
|
573
|
+
return {
|
|
574
|
+
namespace: options.namespace ?? "default",
|
|
575
|
+
path: options.path,
|
|
576
|
+
sha256: options.sha256,
|
|
577
|
+
bytes: options.bytes,
|
|
578
|
+
mtimeMs: options.mtimeMs,
|
|
579
|
+
offset: options.offset ?? 0,
|
|
580
|
+
chunkBytes: options.content.length,
|
|
581
|
+
done: true,
|
|
582
|
+
applied: true,
|
|
583
|
+
skipped: false,
|
|
584
|
+
};
|
|
585
|
+
},
|
|
586
|
+
} as unknown as EngramAccessService;
|
|
587
|
+
const server = new EngramAccessHttpServer({
|
|
588
|
+
service,
|
|
589
|
+
port: 0,
|
|
590
|
+
authToken: "test-token",
|
|
591
|
+
principal: "writer",
|
|
592
|
+
adminConsoleEnabled: false,
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
const status = await server.start();
|
|
596
|
+
try {
|
|
597
|
+
let lastStatus = 0;
|
|
598
|
+
for (let i = 0; i < 31; i += 1) {
|
|
599
|
+
const response = await fetch(
|
|
600
|
+
`http://127.0.0.1:${status.port}/remnic/v1/offline-sync/apply-file-content?namespace=team`,
|
|
601
|
+
{
|
|
602
|
+
method: "POST",
|
|
603
|
+
headers: {
|
|
604
|
+
authorization: "Bearer test-token",
|
|
605
|
+
"content-type": "application/octet-stream",
|
|
606
|
+
"x-remnic-source-id": encodeURIComponent("laptop:test"),
|
|
607
|
+
"x-remnic-file-path": encodeURIComponent(`state/file-${i}.bin`),
|
|
608
|
+
"x-remnic-file-sha256": "b".repeat(64),
|
|
609
|
+
"x-remnic-file-bytes": "5",
|
|
610
|
+
"x-remnic-file-mtime-ms": "1234",
|
|
611
|
+
"x-remnic-chunk-offset": "0",
|
|
612
|
+
},
|
|
613
|
+
body: new Blob([new Uint8Array(Buffer.from("hello"))]),
|
|
614
|
+
},
|
|
615
|
+
);
|
|
616
|
+
lastStatus = response.status;
|
|
617
|
+
if (!response.ok) break;
|
|
618
|
+
await response.arrayBuffer();
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
assert.equal(lastStatus, 200);
|
|
622
|
+
assert.equal(calls, 31);
|
|
623
|
+
} finally {
|
|
624
|
+
await server.stop();
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
|
|
452
628
|
test("HTTP offline snapshot rejects invalid boolean query values", async () => {
|
|
453
629
|
let calls = 0;
|
|
454
630
|
const service = {
|
|
@@ -550,6 +726,69 @@ test("HTTP offline apply validates and forwards changesets", async () => {
|
|
|
550
726
|
}
|
|
551
727
|
});
|
|
552
728
|
|
|
729
|
+
test("HTTP offline apply accepts bulk changesets above the generic JSON body limit", async () => {
|
|
730
|
+
let calls = 0;
|
|
731
|
+
const largeContent = Buffer.alloc(256 * 1024, 7).toString("base64");
|
|
732
|
+
const changeset = {
|
|
733
|
+
format: "remnic.offline-sync.changeset.v1",
|
|
734
|
+
schemaVersion: 1,
|
|
735
|
+
createdAt: new Date("2026-05-21T00:00:00Z").toISOString(),
|
|
736
|
+
sourceId: "laptop:test",
|
|
737
|
+
includeTranscripts: true,
|
|
738
|
+
changes: [{
|
|
739
|
+
type: "upsert",
|
|
740
|
+
path: "facts/large.md",
|
|
741
|
+
file: {
|
|
742
|
+
path: "facts/large.md",
|
|
743
|
+
sha256: "b".repeat(64),
|
|
744
|
+
bytes: 256 * 1024,
|
|
745
|
+
mtimeMs: 1,
|
|
746
|
+
contentBase64: largeContent,
|
|
747
|
+
},
|
|
748
|
+
}],
|
|
749
|
+
};
|
|
750
|
+
const service = {
|
|
751
|
+
offlineSyncApply: async () => {
|
|
752
|
+
calls += 1;
|
|
753
|
+
return {
|
|
754
|
+
namespace: "team",
|
|
755
|
+
appliedUpserts: 1,
|
|
756
|
+
appliedDeletes: 0,
|
|
757
|
+
skipped: 0,
|
|
758
|
+
conflicts: [],
|
|
759
|
+
currentFiles: [],
|
|
760
|
+
};
|
|
761
|
+
},
|
|
762
|
+
} as unknown as EngramAccessService;
|
|
763
|
+
const server = new EngramAccessHttpServer({
|
|
764
|
+
service,
|
|
765
|
+
port: 0,
|
|
766
|
+
authToken: "test-token",
|
|
767
|
+
principal: "writer",
|
|
768
|
+
maxBodyBytes: 1024,
|
|
769
|
+
adminConsoleEnabled: false,
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
const status = await server.start();
|
|
773
|
+
try {
|
|
774
|
+
const response = await fetch(`http://127.0.0.1:${status.port}/remnic/v1/offline-sync/apply`, {
|
|
775
|
+
method: "POST",
|
|
776
|
+
headers: {
|
|
777
|
+
authorization: "Bearer test-token",
|
|
778
|
+
"content-type": "application/json",
|
|
779
|
+
},
|
|
780
|
+
body: JSON.stringify({ namespace: "team", changeset }),
|
|
781
|
+
});
|
|
782
|
+
const body = await response.json() as { appliedUpserts?: number };
|
|
783
|
+
|
|
784
|
+
assert.equal(response.status, 200);
|
|
785
|
+
assert.equal(body.appliedUpserts, 1);
|
|
786
|
+
assert.equal(calls, 1);
|
|
787
|
+
} finally {
|
|
788
|
+
await server.stop();
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
|
|
553
792
|
test("HTTP offline apply requires a changeset", async () => {
|
|
554
793
|
let calls = 0;
|
|
555
794
|
const service = {
|
package/src/access-http.ts
CHANGED
|
@@ -9,6 +9,10 @@ import { log } from "./logger.js";
|
|
|
9
9
|
import { EngramAccessInputError, type EngramAccessService } from "./access-service.js";
|
|
10
10
|
import { EngramMcpServer } from "./access-mcp.js";
|
|
11
11
|
import { validateRequest, type SchemaName, type SchemaTypeFor } from "./access-schema.js";
|
|
12
|
+
import {
|
|
13
|
+
OFFLINE_SYNC_APPLY_MAX_BODY_BYTES,
|
|
14
|
+
OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES,
|
|
15
|
+
} from "./offline-sync.js";
|
|
12
16
|
import type { RecallDisclosure, RecallPlanMode } from "./types.js";
|
|
13
17
|
import { isRecallDisclosure } from "./types.js";
|
|
14
18
|
import { isTrustZoneName, type TrustZoneName, type TrustZoneRecordKind, type TrustZoneSourceClass } from "./trust-zones.js";
|
|
@@ -669,18 +673,51 @@ export class EngramAccessHttpServer {
|
|
|
669
673
|
return;
|
|
670
674
|
}
|
|
671
675
|
|
|
676
|
+
if (
|
|
677
|
+
req.method === "POST" &&
|
|
678
|
+
(
|
|
679
|
+
pathname === "/engram/v1/offline-sync/apply-file-content" ||
|
|
680
|
+
pathname === "/remnic/v1/offline-sync/apply-file-content"
|
|
681
|
+
)
|
|
682
|
+
) {
|
|
683
|
+
const namespaceParam = parsed.searchParams.get("namespace");
|
|
684
|
+
const bytes = this.readRequiredIntegerHeader(req, "x-remnic-file-bytes");
|
|
685
|
+
const offset = this.readOptionalIntegerHeader(req, "x-remnic-chunk-offset") ?? 0;
|
|
686
|
+
const content = await this.readBinaryBody(req, OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES);
|
|
687
|
+
const result = await this.service.offlineSyncApplyFileContent({
|
|
688
|
+
namespace: this.resolveNamespace(
|
|
689
|
+
req,
|
|
690
|
+
namespaceParam && namespaceParam.length > 0 ? namespaceParam : undefined,
|
|
691
|
+
),
|
|
692
|
+
principal: this.resolveRequestPrincipal(req),
|
|
693
|
+
includeTranscripts: this.parseOptionalBooleanHeader(
|
|
694
|
+
req,
|
|
695
|
+
"x-remnic-include-transcripts",
|
|
696
|
+
true,
|
|
697
|
+
),
|
|
698
|
+
sourceId: this.readRequiredDecodedHeader(req, "x-remnic-source-id"),
|
|
699
|
+
path: this.readRequiredDecodedHeader(req, "x-remnic-file-path"),
|
|
700
|
+
sha256: this.readRequiredHeader(req, "x-remnic-file-sha256"),
|
|
701
|
+
bytes,
|
|
702
|
+
mtimeMs: this.readRequiredNumberHeader(req, "x-remnic-file-mtime-ms"),
|
|
703
|
+
offset,
|
|
704
|
+
baseSha256: this.readOptionalHeader(req, "x-remnic-base-sha256"),
|
|
705
|
+
content,
|
|
706
|
+
});
|
|
707
|
+
this.respondJson(res, 200, result);
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
|
|
672
711
|
if (
|
|
673
712
|
req.method === "POST" &&
|
|
674
713
|
(pathname === "/engram/v1/offline-sync/apply" || pathname === "/remnic/v1/offline-sync/apply")
|
|
675
714
|
) {
|
|
676
|
-
const body = await this.readValidatedBody(req, "offlineSyncApply");
|
|
677
|
-
this.ensureWriteRateLimitAvailable();
|
|
715
|
+
const body = await this.readValidatedBody(req, "offlineSyncApply", OFFLINE_SYNC_APPLY_MAX_BODY_BYTES);
|
|
678
716
|
const result = await this.service.offlineSyncApply({
|
|
679
717
|
namespace: this.resolveNamespace(req, body.namespace),
|
|
680
718
|
principal: this.resolveRequestPrincipal(req),
|
|
681
719
|
changeset: body.changeset,
|
|
682
720
|
});
|
|
683
|
-
this.recordWriteRateLimitHit();
|
|
684
721
|
this.respondJson(res, 200, result);
|
|
685
722
|
return;
|
|
686
723
|
}
|
|
@@ -1885,13 +1922,16 @@ export class EngramAccessHttpServer {
|
|
|
1885
1922
|
}
|
|
1886
1923
|
}
|
|
1887
1924
|
|
|
1888
|
-
private async readJsonBody(
|
|
1925
|
+
private async readJsonBody(
|
|
1926
|
+
req: IncomingMessage,
|
|
1927
|
+
maxBodyBytes = this.maxBodyBytes,
|
|
1928
|
+
): Promise<Record<string, unknown>> {
|
|
1889
1929
|
const chunks: Buffer[] = [];
|
|
1890
1930
|
let total = 0;
|
|
1891
1931
|
for await (const chunk of req) {
|
|
1892
1932
|
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
1893
1933
|
total += buffer.length;
|
|
1894
|
-
if (total >
|
|
1934
|
+
if (total > maxBodyBytes) {
|
|
1895
1935
|
throw new HttpError(413, "request_body_too_large", "request_body_too_large");
|
|
1896
1936
|
}
|
|
1897
1937
|
chunks.push(buffer);
|
|
@@ -1911,8 +1951,89 @@ export class EngramAccessHttpServer {
|
|
|
1911
1951
|
return parsed as Record<string, unknown>;
|
|
1912
1952
|
}
|
|
1913
1953
|
|
|
1914
|
-
private async
|
|
1915
|
-
const
|
|
1954
|
+
private async readBinaryBody(req: IncomingMessage, maxBytes: number): Promise<Buffer> {
|
|
1955
|
+
const chunks: Buffer[] = [];
|
|
1956
|
+
let total = 0;
|
|
1957
|
+
for await (const chunk of req) {
|
|
1958
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
1959
|
+
total += buffer.length;
|
|
1960
|
+
if (total > maxBytes) {
|
|
1961
|
+
throw new HttpError(413, "request_body_too_large", "request_body_too_large");
|
|
1962
|
+
}
|
|
1963
|
+
chunks.push(buffer);
|
|
1964
|
+
}
|
|
1965
|
+
return Buffer.concat(chunks, total);
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
private readRequiredHeader(req: IncomingMessage, name: string): string {
|
|
1969
|
+
const value = this.readOptionalHeader(req, name);
|
|
1970
|
+
if (value === undefined || value.length === 0) {
|
|
1971
|
+
throw new EngramAccessInputError(`${name} header is required`);
|
|
1972
|
+
}
|
|
1973
|
+
return value;
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
private readOptionalHeader(req: IncomingMessage, name: string): string | undefined {
|
|
1977
|
+
const raw = req.headers[name.toLowerCase()];
|
|
1978
|
+
if (Array.isArray(raw)) return raw[0]?.trim() || undefined;
|
|
1979
|
+
return raw?.trim() || undefined;
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
private readRequiredDecodedHeader(req: IncomingMessage, name: string): string {
|
|
1983
|
+
const raw = this.readRequiredHeader(req, name);
|
|
1984
|
+
try {
|
|
1985
|
+
return decodeURIComponent(raw);
|
|
1986
|
+
} catch {
|
|
1987
|
+
throw new EngramAccessInputError(`${name} header is not valid percent-encoded input`);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
private readRequiredIntegerHeader(req: IncomingMessage, name: string): number {
|
|
1992
|
+
const raw = this.readRequiredHeader(req, name);
|
|
1993
|
+
const parsed = Number(raw);
|
|
1994
|
+
if (!Number.isInteger(parsed) || parsed < 0) {
|
|
1995
|
+
throw new EngramAccessInputError(`${name} header must be a non-negative integer`);
|
|
1996
|
+
}
|
|
1997
|
+
return parsed;
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
private readOptionalIntegerHeader(req: IncomingMessage, name: string): number | undefined {
|
|
2001
|
+
const raw = this.readOptionalHeader(req, name);
|
|
2002
|
+
if (raw === undefined) return undefined;
|
|
2003
|
+
const parsed = Number(raw);
|
|
2004
|
+
if (!Number.isInteger(parsed) || parsed < 0) {
|
|
2005
|
+
throw new EngramAccessInputError(`${name} header must be a non-negative integer`);
|
|
2006
|
+
}
|
|
2007
|
+
return parsed;
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
private readRequiredNumberHeader(req: IncomingMessage, name: string): number {
|
|
2011
|
+
const raw = this.readRequiredHeader(req, name);
|
|
2012
|
+
const parsed = Number(raw);
|
|
2013
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
2014
|
+
throw new EngramAccessInputError(`${name} header must be a non-negative finite number`);
|
|
2015
|
+
}
|
|
2016
|
+
return parsed;
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
private parseOptionalBooleanHeader(
|
|
2020
|
+
req: IncomingMessage,
|
|
2021
|
+
name: string,
|
|
2022
|
+
defaultValue: boolean,
|
|
2023
|
+
): boolean {
|
|
2024
|
+
const raw = this.readOptionalHeader(req, name);
|
|
2025
|
+
if (raw === undefined) return defaultValue;
|
|
2026
|
+
if (raw === "true") return true;
|
|
2027
|
+
if (raw === "false") return false;
|
|
2028
|
+
throw new EngramAccessInputError(`${name} header must be one of: true, false`);
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
private async readValidatedBody<S extends SchemaName>(
|
|
2032
|
+
req: IncomingMessage,
|
|
2033
|
+
schemaName: S,
|
|
2034
|
+
maxBodyBytes?: number,
|
|
2035
|
+
): Promise<SchemaTypeFor<S>> {
|
|
2036
|
+
const raw = await this.readJsonBody(req, maxBodyBytes);
|
|
1916
2037
|
const result = validateRequest(schemaName, raw);
|
|
1917
2038
|
if (!result.success) {
|
|
1918
2039
|
throw new HttpError(400, result.error.error, "validation_error", result.error.details);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { EngramAccessInputError, EngramAccessService } from "./access-service.js";
|
|
5
|
+
|
|
6
|
+
function createOfflineService(): EngramAccessService {
|
|
7
|
+
return new EngramAccessService({
|
|
8
|
+
config: {
|
|
9
|
+
memoryDir: "/tmp/remnic-access-service-offline-file-content-test",
|
|
10
|
+
namespacesEnabled: false,
|
|
11
|
+
defaultNamespace: "global",
|
|
12
|
+
sharedNamespace: "shared",
|
|
13
|
+
},
|
|
14
|
+
getStorage: async () => ({
|
|
15
|
+
dir: "/tmp/remnic-access-service-offline-file-content-test",
|
|
16
|
+
}),
|
|
17
|
+
} as any);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
test("offline apply-file-content reports invalid metadata as input errors", async () => {
|
|
21
|
+
const service = createOfflineService();
|
|
22
|
+
await assert.rejects(
|
|
23
|
+
() => service.offlineSyncApplyFileContent({
|
|
24
|
+
includeTranscripts: true,
|
|
25
|
+
sourceId: "laptop",
|
|
26
|
+
path: "state/lcm.sqlite",
|
|
27
|
+
sha256: "not-a-sha",
|
|
28
|
+
bytes: 0,
|
|
29
|
+
mtimeMs: 0,
|
|
30
|
+
offset: 0,
|
|
31
|
+
content: Buffer.alloc(0),
|
|
32
|
+
}),
|
|
33
|
+
(error) =>
|
|
34
|
+
error instanceof EngramAccessInputError &&
|
|
35
|
+
/sha256 must be a 64-character sha256/.test(error.message),
|
|
36
|
+
);
|
|
37
|
+
});
|