anpord 0.1.13 → 0.1.16
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/api-context.cjs +18 -0
- package/dist/api-context.d.cts +8 -0
- package/dist/api-context.d.mts +8 -0
- package/dist/api-context.mjs +17 -0
- package/dist/api-mocks-B3qngoqS.cjs +68 -0
- package/dist/api-mocks-BfKw_hXc.mjs +33 -0
- package/dist/api-mocks-Bz3G00ve.d.cts +101 -0
- package/dist/api-mocks-Bz3G00ve.d.mts +101 -0
- package/dist/api-runtime.cjs +4 -0
- package/dist/api-runtime.d.cts +13 -0
- package/dist/api-runtime.d.mts +13 -0
- package/dist/api-runtime.mjs +2 -0
- package/dist/api.cjs +5 -0
- package/dist/api.d.cts +4 -0
- package/dist/api.d.mts +4 -0
- package/dist/api.mjs +2 -0
- package/dist/bin.cjs +8 -8
- package/dist/bin.mjs +6 -6
- package/dist/cli-runtime.cjs +1 -1
- package/dist/cli-runtime.mjs +1 -1
- package/dist/{client-BgRs8JvW.d.mts → client-C8tBcLYs.d.mts} +17 -17
- package/dist/{client-BirFO3jz.d.cts → client-CMkx-LKC.d.cts} +16 -16
- package/dist/{client-C-P2I00z.cjs → client-CfYNoI3L.cjs} +4 -91
- package/dist/{client-BfdjFtlV.mjs → client-YWKJd3f-.mjs} +3 -90
- package/dist/{compiler-uwb1pkdK.cjs → compiler-4FKsNxZ-.cjs} +89 -33
- package/dist/{compiler-D96wI7UP.mjs → compiler-Dsltkkj5.mjs} +77 -21
- package/dist/config.cjs +1 -1
- package/dist/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +1 -1
- package/dist/define-NZvmQuIv.d.cts +34 -0
- package/dist/define-NZvmQuIv.d.mts +34 -0
- package/dist/{eval-judges-DPPUftbh.d.cts → eval-judges-JiC8cUCE.d.cts} +1 -1
- package/dist/{eval-judges-DPPUftbh.d.mts → eval-judges-JiC8cUCE.d.mts} +1 -1
- package/dist/{eval-validations-BRdoZrTQ.mjs → eval-validations-Bmagd2y7.mjs} +2 -2
- package/dist/{eval-validations-_MlnQ_uv.cjs → eval-validations-CqMUt5ra.cjs} +7 -1
- package/dist/eval.cjs +1 -1
- package/dist/eval.d.cts +42 -21
- package/dist/eval.d.mts +42 -21
- package/dist/eval.mjs +1 -1
- package/dist/{evals-B6aT3xgH.d.cts → evals-B2UuSop0.d.cts} +136 -136
- package/dist/{evals-B6aT3xgH.d.mts → evals-B2UuSop0.d.mts} +136 -136
- package/dist/{types-Codjaq-o.d.mts → evals-api-CfAA3cew.d.mts} +12 -112
- package/dist/{types-ISsteq95.d.cts → evals-api-Clbj_nEN.d.cts} +11 -111
- package/dist/{evals-Dcc_x6jW.mjs → evals-api-DDv4gXU1.mjs} +95 -4
- package/dist/{evals-DouMsrsM.cjs → evals-api-kOuyIqvB.cjs} +103 -72
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +6 -6
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +2 -2
- package/dist/mcp-runtime.cjs +1 -1
- package/dist/mcp-runtime.mjs +1 -1
- package/dist/runtime-C0_JPkef.mjs +269 -0
- package/dist/runtime-YVJP5P2r.cjs +292 -0
- package/dist/source.d.cts +1 -1
- package/dist/source.d.mts +1 -1
- package/dist/types-BHokRQpg.d.mts +112 -0
- package/dist/types-UKEi5CCa.d.cts +112 -0
- package/dist/validator-runtime.cjs +6 -1
- package/dist/validator-runtime.d.cts +1 -1
- package/dist/validator-runtime.d.mts +1 -1
- package/dist/validator-runtime.mjs +6 -1
- package/dist/validators.d.cts +1 -1
- package/dist/validators.d.mts +1 -1
- package/package.json +21 -1
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
const require_eval_judges = require("./eval-judges-BkmiVLLq.cjs");
|
|
2
|
-
const require_eval_validations = require("./eval-validations-
|
|
2
|
+
const require_eval_validations = require("./eval-validations-CqMUt5ra.cjs");
|
|
3
3
|
let effect = require("effect");
|
|
4
|
+
let _effect_platform = require("@effect/platform");
|
|
5
|
+
//#region ../schema/src/domain/errors.ts
|
|
6
|
+
var NotFound = class extends effect.Schema.TaggedError()("NotFound", { message: effect.Schema.String }, _effect_platform.HttpApiSchema.annotations({ status: 404 })) {};
|
|
7
|
+
var Conflict = class extends effect.Schema.TaggedError()("Conflict", { message: effect.Schema.String }, _effect_platform.HttpApiSchema.annotations({ status: 409 })) {};
|
|
8
|
+
var BadRequest = class extends effect.Schema.TaggedError()("BadRequest", { message: effect.Schema.String }, _effect_platform.HttpApiSchema.annotations({ status: 400 })) {};
|
|
9
|
+
var Unauthorized = class extends effect.Schema.TaggedError()("Unauthorized", { message: effect.Schema.String }, _effect_platform.HttpApiSchema.annotations({ status: 401 })) {};
|
|
10
|
+
var Forbidden = class extends effect.Schema.TaggedError()("Forbidden", { message: effect.Schema.String }, _effect_platform.HttpApiSchema.annotations({ status: 403 })) {};
|
|
11
|
+
effect.Schema.TaggedError()("InternalError", { message: effect.Schema.String }, _effect_platform.HttpApiSchema.annotations({ status: 500 }));
|
|
12
|
+
//#endregion
|
|
4
13
|
//#region ../schema/src/domain/eval-limits.ts
|
|
5
14
|
const PROMPT_LIMIT = 16384;
|
|
6
15
|
const VERIFY_LIMIT = 8192;
|
|
@@ -232,7 +241,10 @@ const EvalVariables = effect.Schema.Record({
|
|
|
232
241
|
});
|
|
233
242
|
const CaseCache = effect.Schema.Struct({
|
|
234
243
|
key: effect.Schema.String.pipe(effect.Schema.minLength(1)),
|
|
235
|
-
path: effect.Schema.String.pipe(effect.Schema.minLength(1), effect.Schema.filter((value) => !(value.startsWith("/") || value.split("/").includes("..")), { message: () => "a cache path must stay inside the workspace" }))
|
|
244
|
+
path: effect.Schema.String.pipe(effect.Schema.minLength(1), effect.Schema.filter((value) => !(value.startsWith("/") || value.split("/").includes("..")), { message: () => "a cache path must stay inside the workspace" }), effect.Schema.filter((value) => {
|
|
245
|
+
const directory = value.split("/").find((part) => part !== "" && part !== ".");
|
|
246
|
+
return directory !== void 0 && directory !== ".anpord";
|
|
247
|
+
}, { message: () => "a cache must name a subdirectory outside the reserved .anpord runtime" }))
|
|
236
248
|
}).annotations({ identifier: "CaseCache" });
|
|
237
249
|
const EvalCase = effect.Schema.Struct({
|
|
238
250
|
cache: effect.Schema.optional(CaseCache),
|
|
@@ -579,82 +591,113 @@ const ModelCatalogue = effect.Schema.Struct({
|
|
|
579
591
|
identifier: "ModelCatalogue"
|
|
580
592
|
});
|
|
581
593
|
//#endregion
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
594
|
+
//#region ../schema/src/internal/authentication.ts
|
|
595
|
+
var CurrentActor = class extends effect.Context.Tag("@anpord/schema/CurrentActor")() {};
|
|
596
|
+
_effect_platform.HttpApiMiddleware.Tag()("@anpord/schema/Authentication", {
|
|
597
|
+
failure: Unauthorized,
|
|
598
|
+
provides: CurrentActor,
|
|
599
|
+
security: { session: _effect_platform.HttpApiSecurity.apiKey({
|
|
600
|
+
in: "cookie",
|
|
601
|
+
key: "anpord.session_token"
|
|
602
|
+
}) }
|
|
587
603
|
});
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
604
|
+
//#endregion
|
|
605
|
+
//#region ../schema/src/public/authentication.ts
|
|
606
|
+
var ApiKeyAuthentication = class extends _effect_platform.HttpApiMiddleware.Tag()("@anpord/schema/ApiKeyAuthentication", {
|
|
607
|
+
failure: Unauthorized,
|
|
608
|
+
provides: CurrentActor,
|
|
609
|
+
security: { bearer: _effect_platform.HttpApiSecurity.bearer }
|
|
610
|
+
}) {};
|
|
611
|
+
//#endregion
|
|
612
|
+
//#region ../schema/src/public/evals-api.ts
|
|
613
|
+
const EvalRunRequest = effect.Schema.Struct({ id: effect.Schema.String }).annotations({
|
|
614
|
+
description: "Select an eval run by id.",
|
|
615
|
+
identifier: "EvalRunRequest"
|
|
593
616
|
});
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
return EvalCaseName;
|
|
598
|
-
}
|
|
617
|
+
const EvalCellRequest = effect.Schema.Struct({ cellKey: effect.Schema.String }).annotations({
|
|
618
|
+
description: "Select an eval cell by its stable key.",
|
|
619
|
+
identifier: "EvalCellRequest"
|
|
599
620
|
});
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
621
|
+
const EvalModelsRequest = effect.Schema.Struct({
|
|
622
|
+
harness: EvalHarness,
|
|
623
|
+
q: effect.Schema.optional(effect.Schema.String)
|
|
624
|
+
}).annotations({
|
|
625
|
+
description: "Select a harness whose available models should be listed.",
|
|
626
|
+
identifier: "EvalModelsRequest"
|
|
605
627
|
});
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
return EvalHarness;
|
|
610
|
-
}
|
|
628
|
+
const PublicEvalSandbox = EvalSandbox.annotations({
|
|
629
|
+
description: "The hosted sandbox a task runs in.",
|
|
630
|
+
identifier: "PublicEvalSandbox"
|
|
611
631
|
});
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
632
|
+
const ListEvalsRequest = effect.Schema.Struct({
|
|
633
|
+
cursor: effect.Schema.optional(effect.Schema.NullOr(EvalPageCursor)),
|
|
634
|
+
limit: effect.Schema.optional(effect.Schema.Int)
|
|
635
|
+
}).annotations({
|
|
636
|
+
description: "Where to read from, and how much.",
|
|
637
|
+
identifier: "ListEvalsRequest"
|
|
617
638
|
});
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
639
|
+
const PublicEvalCase = effect.Schema.Struct({
|
|
640
|
+
cache: effect.Schema.optional(CaseCache),
|
|
641
|
+
name: EvalCaseName,
|
|
642
|
+
prepare: effect.Schema.optional(effect.Schema.NullOr(EvalPrepare)),
|
|
643
|
+
source: effect.Schema.optional(EvalSource),
|
|
644
|
+
validator: effect.Schema.optional(effect.Schema.NullOr(EvalValidator)),
|
|
645
|
+
variables: effect.Schema.optional(EvalVariables),
|
|
646
|
+
verify: effect.Schema.NullOr(EvalVerify)
|
|
647
|
+
}).pipe(effect.Schema.filter(({ validator, verify }) => !(validator !== void 0 && validator !== null && verify !== null), { message: () => "Use either validator or verify, not both." })).annotations({
|
|
648
|
+
description: "A task, workspace source, setup command, and verifier.",
|
|
649
|
+
identifier: "StartEvalCase"
|
|
623
650
|
});
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
651
|
+
const PublicEvalTask = effect.Schema.Struct({
|
|
652
|
+
harness: EvalHarness,
|
|
653
|
+
model: effect.Schema.String.pipe(effect.Schema.minLength(1)),
|
|
654
|
+
profile: effect.Schema.optional(HarnessProfile),
|
|
655
|
+
sandbox: effect.Schema.optional(PublicEvalSandbox)
|
|
656
|
+
}).pipe(effect.Schema.filter(profileFitsHarness, { message: () => PROFILE_HARNESS_RULE })).annotations({
|
|
657
|
+
description: `A harness and model, with an optional sandbox and an optional profile layered on the harness. Omit the sandbox to use the default. ${PROFILE_HARNESS_RULE}`,
|
|
658
|
+
identifier: "StartEvalTask"
|
|
629
659
|
});
|
|
630
|
-
|
|
660
|
+
const PublicStartEvalRequest = effect.Schema.Struct({
|
|
661
|
+
trigger: effect.Schema.optional(EvalTrigger),
|
|
662
|
+
cases: effect.Schema.Array(PublicEvalCase).pipe(effect.Schema.minItems(1), effect.Schema.maxItems(100)),
|
|
663
|
+
name: effect.Schema.optional(EvalName),
|
|
664
|
+
prompt: EvalPrompt,
|
|
665
|
+
tasks: effect.Schema.Array(PublicEvalTask).pipe(effect.Schema.minItems(1), effect.Schema.maxItems(20)),
|
|
666
|
+
trials: effect.Schema.Int.pipe(effect.Schema.between(1, 10))
|
|
667
|
+
}).annotations({
|
|
668
|
+
description: `Start a grid with at most 100 total case, task, and trial combinations.`,
|
|
669
|
+
identifier: "StartEvalRequest"
|
|
670
|
+
});
|
|
671
|
+
var PublicEvalsGroup = class extends _effect_platform.HttpApiGroup.make("evals").add(_effect_platform.HttpApiEndpoint.post("list", "/evals.list").setPayload(ListEvalsRequest).addSuccess(EvalRunPage).annotate(_effect_platform.OpenApi.Summary, "List eval runs").annotate(_effect_platform.OpenApi.Description, "Newest first. Pass the `next` cursor from a response to read the page after it; a null `next` means there are no more.")).add(_effect_platform.HttpApiEndpoint.post("start", "/evals.start").setPayload(PublicStartEvalRequest).addSuccess(StartedEval).annotate(_effect_platform.OpenApi.Summary, "Start an eval run").annotate(_effect_platform.OpenApi.Description, `Starts the grid and returns its id while trials continue in the background. ${PROFILE_HARNESS_RULE}`)).add(_effect_platform.HttpApiEndpoint.post("get", "/evals.get").setPayload(EvalRunRequest).addSuccess(EvalRun).annotate(_effect_platform.OpenApi.Summary, "Get an eval run")).add(_effect_platform.HttpApiEndpoint.post("cellHistory", "/evals.cellHistory").setPayload(EvalCellRequest).addSuccess(effect.Schema.Array(EvalCellHistoryEntry)).annotate(_effect_platform.OpenApi.Summary, "List a cell's history").annotate(_effect_platform.OpenApi.Description, "Returns the 20 most recent results.")).add(_effect_platform.HttpApiEndpoint.post("rerunCell", "/evals.rerunCell").setPayload(effect.Schema.extend(EvalRunRequest, effect.Schema.extend(EvalCellRequest, RerunCellRequest))).addSuccess(StartedEval).annotate(_effect_platform.OpenApi.Summary, "Rerun one cell")).add(_effect_platform.HttpApiEndpoint.post("models", "/evals.models").setPayload(EvalModelsRequest).addSuccess(ModelCatalogue).annotate(_effect_platform.OpenApi.Summary, "List models available to the harness").annotate(_effect_platform.OpenApi.Description, "The command harness has no catalogue of its own, so its list is empty: the model is whatever the profile's run command reads from ANPORD_MODEL.")).addError(BadRequest).addError(Conflict).addError(Forbidden).addError(NotFound).middleware(ApiKeyAuthentication).annotate(_effect_platform.OpenApi.Title, "Evals").annotate(_effect_platform.OpenApi.Description, "Run cases across harness, model, and sandbox combinations and compare the results with their baselines.") {};
|
|
672
|
+
//#endregion
|
|
673
|
+
Object.defineProperty(exports, "ApiKeyAuthentication", {
|
|
631
674
|
enumerable: true,
|
|
632
675
|
get: function() {
|
|
633
|
-
return
|
|
676
|
+
return ApiKeyAuthentication;
|
|
634
677
|
}
|
|
635
678
|
});
|
|
636
|
-
Object.defineProperty(exports, "
|
|
679
|
+
Object.defineProperty(exports, "BadRequest", {
|
|
637
680
|
enumerable: true,
|
|
638
681
|
get: function() {
|
|
639
|
-
return
|
|
682
|
+
return BadRequest;
|
|
640
683
|
}
|
|
641
684
|
});
|
|
642
|
-
Object.defineProperty(exports, "
|
|
685
|
+
Object.defineProperty(exports, "Conflict", {
|
|
643
686
|
enumerable: true,
|
|
644
687
|
get: function() {
|
|
645
|
-
return
|
|
688
|
+
return Conflict;
|
|
646
689
|
}
|
|
647
690
|
});
|
|
648
|
-
Object.defineProperty(exports, "
|
|
691
|
+
Object.defineProperty(exports, "EnvName", {
|
|
649
692
|
enumerable: true,
|
|
650
693
|
get: function() {
|
|
651
|
-
return
|
|
694
|
+
return EnvName;
|
|
652
695
|
}
|
|
653
696
|
});
|
|
654
|
-
Object.defineProperty(exports, "
|
|
697
|
+
Object.defineProperty(exports, "EvalRun", {
|
|
655
698
|
enumerable: true,
|
|
656
699
|
get: function() {
|
|
657
|
-
return
|
|
700
|
+
return EvalRun;
|
|
658
701
|
}
|
|
659
702
|
});
|
|
660
703
|
Object.defineProperty(exports, "EvalSourceFiles", {
|
|
@@ -675,16 +718,10 @@ Object.defineProperty(exports, "EvalValidator", {
|
|
|
675
718
|
return EvalValidator;
|
|
676
719
|
}
|
|
677
720
|
});
|
|
678
|
-
Object.defineProperty(exports, "
|
|
679
|
-
enumerable: true,
|
|
680
|
-
get: function() {
|
|
681
|
-
return EvalVariables;
|
|
682
|
-
}
|
|
683
|
-
});
|
|
684
|
-
Object.defineProperty(exports, "EvalVerify", {
|
|
721
|
+
Object.defineProperty(exports, "Forbidden", {
|
|
685
722
|
enumerable: true,
|
|
686
723
|
get: function() {
|
|
687
|
-
return
|
|
724
|
+
return Forbidden;
|
|
688
725
|
}
|
|
689
726
|
});
|
|
690
727
|
Object.defineProperty(exports, "HarnessProfile", {
|
|
@@ -693,16 +730,10 @@ Object.defineProperty(exports, "HarnessProfile", {
|
|
|
693
730
|
return HarnessProfile;
|
|
694
731
|
}
|
|
695
732
|
});
|
|
696
|
-
Object.defineProperty(exports, "
|
|
697
|
-
enumerable: true,
|
|
698
|
-
get: function() {
|
|
699
|
-
return ModelCatalogue;
|
|
700
|
-
}
|
|
701
|
-
});
|
|
702
|
-
Object.defineProperty(exports, "PROFILE_HARNESS_RULE", {
|
|
733
|
+
Object.defineProperty(exports, "NotFound", {
|
|
703
734
|
enumerable: true,
|
|
704
735
|
get: function() {
|
|
705
|
-
return
|
|
736
|
+
return NotFound;
|
|
706
737
|
}
|
|
707
738
|
});
|
|
708
739
|
Object.defineProperty(exports, "PROFILE_LIMITS", {
|
|
@@ -717,16 +748,16 @@ Object.defineProperty(exports, "ProfilePath", {
|
|
|
717
748
|
return ProfilePath;
|
|
718
749
|
}
|
|
719
750
|
});
|
|
720
|
-
Object.defineProperty(exports, "
|
|
751
|
+
Object.defineProperty(exports, "PublicEvalsGroup", {
|
|
721
752
|
enumerable: true,
|
|
722
753
|
get: function() {
|
|
723
|
-
return
|
|
754
|
+
return PublicEvalsGroup;
|
|
724
755
|
}
|
|
725
756
|
});
|
|
726
|
-
Object.defineProperty(exports, "
|
|
757
|
+
Object.defineProperty(exports, "PublicStartEvalRequest", {
|
|
727
758
|
enumerable: true,
|
|
728
759
|
get: function() {
|
|
729
|
-
return
|
|
760
|
+
return PublicStartEvalRequest;
|
|
730
761
|
}
|
|
731
762
|
});
|
|
732
763
|
Object.defineProperty(exports, "profileFitsHarness", {
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_client = require("./client-
|
|
2
|
+
const require_client = require("./client-CfYNoI3L.cjs");
|
|
3
3
|
const require_errors = require("./errors-BX1wry8K.cjs");
|
|
4
4
|
const require_source = require("./source-DvlGawEw.cjs");
|
|
5
|
-
let _effect_platform = require("@effect/platform");
|
|
6
5
|
let effect = require("effect");
|
|
6
|
+
let _effect_platform = require("@effect/platform");
|
|
7
7
|
//#region ../template/src/errors.ts
|
|
8
8
|
/** Plain `Error`: crosses the published SDK boundary, where callers use
|
|
9
9
|
* `instanceof`. */
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as layer, i as DEFAULT_BASE_URL, n as AnpordClient, o as make, r as ClientOptions, t as AnpordApi } from "./client-
|
|
2
|
-
import { _ as EvalVerdict, a as EvalDistribution, b as StartedEval, c as EvalRun, d as EvalSandbox, f as EvalSource, g as EvalUsage, h as EvalTrialStatus, i as EvalComparison, l as EvalRunStatus, m as EvalTrial, n as EvalCell, o as EvalHarness, p as EvalTask, r as EvalCellHistoryEntry, s as EvalJournalEntry, t as CatalogueModel, u as EvalRunSummary, v as ModelCatalogue, y as RerunCellRequest } from "./evals-
|
|
3
|
-
import {
|
|
1
|
+
import { a as layer, i as DEFAULT_BASE_URL, n as AnpordClient, o as make, r as ClientOptions, t as AnpordApi } from "./client-CMkx-LKC.cjs";
|
|
2
|
+
import { _ as EvalVerdict, a as EvalDistribution, b as StartedEval, c as EvalRun, d as EvalSandbox, f as EvalSource, g as EvalUsage, h as EvalTrialStatus, i as EvalComparison, l as EvalRunStatus, m as EvalTrial, n as EvalCell, o as EvalHarness, p as EvalTask, r as EvalCellHistoryEntry, s as EvalJournalEntry, t as CatalogueModel, u as EvalRunSummary, v as ModelCatalogue, y as RerunCellRequest } from "./evals-B2UuSop0.cjs";
|
|
3
|
+
import { empty, files, repo } from "./source.cjs";
|
|
4
4
|
import { t as McpCall } from "./calls-DYqBi5FA.cjs";
|
|
5
5
|
import { t as CliCall } from "./calls-Drj_dZpu.cjs";
|
|
6
|
-
import {
|
|
6
|
+
import { a as EvalTaskDefinition, c as Prepare, d as ProfileRef, f as Validator, i as EvalDefinition, l as PrepareContext, m as ValidatorResult, n as CommandResult, o as ExecOptions, p as ValidatorContext, r as EvalCaseDefinition, s as HarnessRef, t as CaseCache, u as PrepareValue } from "./types-UKEi5CCa.cjs";
|
|
7
7
|
import { Brand, Effect, Schema } from "effect";
|
|
8
8
|
import { HttpClientResponse } from "@effect/platform";
|
|
9
9
|
//#region ../template/src/render.d.ts
|
|
@@ -145,7 +145,7 @@ declare const ValidationValue: Schema.Struct<{
|
|
|
145
145
|
type ValidationValue = typeof ValidationValue.Type;
|
|
146
146
|
declare const ValidationCall: Schema.Struct<{
|
|
147
147
|
index: Schema.refine<number, typeof Schema.NonNegative>;
|
|
148
|
-
method: Schema.Literal<["answer", "transcript", "readText", "exists", "exec", "cli.calls", "mcp.calls"]>;
|
|
148
|
+
method: Schema.Literal<["answer", "transcript", "readText", "exists", "exec", "cli.calls", "api.calls", "api.url", "mcp.calls"]>;
|
|
149
149
|
startedAt: typeof Schema.Number;
|
|
150
150
|
durationMs: Schema.NullOr<Schema.refine<number, typeof Schema.NonNegative>>;
|
|
151
151
|
input: Schema.Struct<{
|
|
@@ -216,7 +216,7 @@ declare const EvalValidation: Schema.Struct<{
|
|
|
216
216
|
}>>;
|
|
217
217
|
calls: Schema.filter<Schema.Array$<Schema.Struct<{
|
|
218
218
|
index: Schema.refine<number, typeof Schema.NonNegative>;
|
|
219
|
-
method: Schema.Literal<["answer", "transcript", "readText", "exists", "exec", "cli.calls", "mcp.calls"]>;
|
|
219
|
+
method: Schema.Literal<["answer", "transcript", "readText", "exists", "exec", "cli.calls", "api.calls", "api.url", "mcp.calls"]>;
|
|
220
220
|
startedAt: typeof Schema.Number;
|
|
221
221
|
durationMs: Schema.NullOr<Schema.refine<number, typeof Schema.NonNegative>>;
|
|
222
222
|
input: Schema.Struct<{
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { a as layer, i as DEFAULT_BASE_URL, n as AnpordClient, o as make, r as ClientOptions, t as AnpordApi } from "./client-
|
|
2
|
-
import { _ as EvalVerdict, a as EvalDistribution, b as StartedEval, c as EvalRun, d as EvalSandbox, f as EvalSource, g as EvalUsage, h as EvalTrialStatus, i as EvalComparison, l as EvalRunStatus, m as EvalTrial, n as EvalCell, o as EvalHarness, p as EvalTask, r as EvalCellHistoryEntry, s as EvalJournalEntry, t as CatalogueModel, u as EvalRunSummary, v as ModelCatalogue, y as RerunCellRequest } from "./evals-
|
|
3
|
-
import {
|
|
1
|
+
import { a as layer, i as DEFAULT_BASE_URL, n as AnpordClient, o as make, r as ClientOptions, t as AnpordApi } from "./client-C8tBcLYs.mjs";
|
|
2
|
+
import { _ as EvalVerdict, a as EvalDistribution, b as StartedEval, c as EvalRun, d as EvalSandbox, f as EvalSource, g as EvalUsage, h as EvalTrialStatus, i as EvalComparison, l as EvalRunStatus, m as EvalTrial, n as EvalCell, o as EvalHarness, p as EvalTask, r as EvalCellHistoryEntry, s as EvalJournalEntry, t as CatalogueModel, u as EvalRunSummary, v as ModelCatalogue, y as RerunCellRequest } from "./evals-B2UuSop0.mjs";
|
|
3
|
+
import { empty, files, repo } from "./source.mjs";
|
|
4
4
|
import { t as McpCall } from "./calls-DYqBi5FA.mjs";
|
|
5
5
|
import { t as CliCall } from "./calls-Drj_dZpu.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import { HttpClientResponse } from "@effect/platform";
|
|
6
|
+
import { a as EvalTaskDefinition, c as Prepare, d as ProfileRef, f as Validator, i as EvalDefinition, l as PrepareContext, m as ValidatorResult, n as CommandResult, o as ExecOptions, p as ValidatorContext, r as EvalCaseDefinition, s as HarnessRef, t as CaseCache, u as PrepareValue } from "./types-BHokRQpg.mjs";
|
|
8
7
|
import { Brand, Effect, Schema } from "effect";
|
|
8
|
+
import { HttpClientResponse } from "@effect/platform";
|
|
9
9
|
//#region ../template/src/render.d.ts
|
|
10
10
|
/** Objects are rejected: `[object Object]` is a bug and `JSON.stringify` a
|
|
11
11
|
* guess, so the caller decides. */
|
|
@@ -145,7 +145,7 @@ declare const ValidationValue: Schema.Struct<{
|
|
|
145
145
|
type ValidationValue = typeof ValidationValue.Type;
|
|
146
146
|
declare const ValidationCall: Schema.Struct<{
|
|
147
147
|
index: Schema.refine<number, typeof Schema.NonNegative>;
|
|
148
|
-
method: Schema.Literal<["answer", "transcript", "readText", "exists", "exec", "cli.calls", "mcp.calls"]>;
|
|
148
|
+
method: Schema.Literal<["answer", "transcript", "readText", "exists", "exec", "cli.calls", "api.calls", "api.url", "mcp.calls"]>;
|
|
149
149
|
startedAt: typeof Schema.Number;
|
|
150
150
|
durationMs: Schema.NullOr<Schema.refine<number, typeof Schema.NonNegative>>;
|
|
151
151
|
input: Schema.Struct<{
|
|
@@ -216,7 +216,7 @@ declare const EvalValidation: Schema.Struct<{
|
|
|
216
216
|
}>>;
|
|
217
217
|
calls: Schema.filter<Schema.Array$<Schema.Struct<{
|
|
218
218
|
index: Schema.refine<number, typeof Schema.NonNegative>;
|
|
219
|
-
method: Schema.Literal<["answer", "transcript", "readText", "exists", "exec", "cli.calls", "mcp.calls"]>;
|
|
219
|
+
method: Schema.Literal<["answer", "transcript", "readText", "exists", "exec", "cli.calls", "api.calls", "api.url", "mcp.calls"]>;
|
|
220
220
|
startedAt: typeof Schema.Number;
|
|
221
221
|
durationMs: Schema.NullOr<Schema.refine<number, typeof Schema.NonNegative>>;
|
|
222
222
|
input: Schema.Struct<{
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { i as make, n as DEFAULT_BASE_URL, r as layer, t as AnpordApi } from "./client-
|
|
1
|
+
import { i as make, n as DEFAULT_BASE_URL, r as layer, t as AnpordApi } from "./client-YWKJd3f-.mjs";
|
|
2
2
|
import { i as tokenMatcher, n as MissingApiKey, r as asAnpordError, t as AnpordError } from "./errors-B0YknR5V.mjs";
|
|
3
3
|
import { n as files, r as repo, t as empty } from "./source-Fg1h2VNn.mjs";
|
|
4
|
-
import { FetchHttpClient } from "@effect/platform";
|
|
5
4
|
import { Cache, Cause, Clock, Context, Data, DateTime, Duration, Effect, Exit, Layer, ManagedRuntime, Option, Redacted } from "effect";
|
|
5
|
+
import { FetchHttpClient } from "@effect/platform";
|
|
6
6
|
//#region ../template/src/errors.ts
|
|
7
7
|
/** Plain `Error`: crosses the published SDK boundary, where callers use
|
|
8
8
|
* `instanceof`. */
|
package/dist/mcp-runtime.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let effect = require("effect");
|
|
3
|
-
let node_path = require("node:path");
|
|
4
3
|
let node_fs_promises = require("node:fs/promises");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
5
|
let _modelcontextprotocol_server = require("@modelcontextprotocol/server");
|
|
6
6
|
let _modelcontextprotocol_server_stdio = require("@modelcontextprotocol/server/stdio");
|
|
7
7
|
//#region src/mcp/runtime.ts
|
package/dist/mcp-runtime.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { dirname } from "node:path";
|
|
3
2
|
import { appendFile, mkdir } from "node:fs/promises";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
4
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
5
5
|
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
6
6
|
//#region src/mcp/runtime.ts
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { a as validationCapture, i as unavailableValue } from "./eval-validations-Bmagd2y7.mjs";
|
|
2
|
+
import { i as API_READY, n as API_MANIFEST, t as API_JOURNAL } from "./api-mocks-BfKw_hXc.mjs";
|
|
3
|
+
import { Clock, Data, Deferred, Effect, Option, Ref, Schema } from "effect";
|
|
4
|
+
import { FileSystem, HttpRouter, HttpServerRequest, HttpServerResponse } from "@effect/platform";
|
|
5
|
+
import { layer } from "@effect/platform-node/NodeFileSystem";
|
|
6
|
+
import { runMain } from "@effect/platform-node/NodeRuntime";
|
|
7
|
+
import { createServer } from "node:http";
|
|
8
|
+
import { make } from "@effect/platform-node/NodeHttpServer";
|
|
9
|
+
//#region src/mock-api/define.ts
|
|
10
|
+
const endpoint = (definition) => definition;
|
|
11
|
+
const Name = Schema.String.pipe(Schema.pattern(/^[a-z][a-z0-9-]{0,63}$/));
|
|
12
|
+
const Path = Schema.String.pipe(Schema.pattern(/^\/(?:[A-Za-z0-9._~-]+|:[A-Za-z][A-Za-z0-9_]*)(?:\/(?:[A-Za-z0-9._~-]+|:[A-Za-z][A-Za-z0-9_]*))*\/?$|^\/$/));
|
|
13
|
+
const PARAMETER = /:[A-Za-z][A-Za-z0-9_]*/g;
|
|
14
|
+
const api = (definition) => {
|
|
15
|
+
Schema.decodeUnknownSync(Name)(definition.name);
|
|
16
|
+
const routes = /* @__PURE__ */ new Set();
|
|
17
|
+
for (const route of definition.endpoints) {
|
|
18
|
+
Schema.decodeUnknownSync(Path)(route.path);
|
|
19
|
+
const key = `${route.method} ${route.path.replace(PARAMETER, ":parameter")}`;
|
|
20
|
+
if (routes.has(key)) throw new Error(`Duplicate API endpoint: ${key}`);
|
|
21
|
+
routes.add(key);
|
|
22
|
+
if (Object.keys(route.responses).length === 0) throw new Error(`API endpoint needs response schemas: ${key}`);
|
|
23
|
+
for (const status of Object.keys(route.responses)) Schema.decodeUnknownSync(Schema.Int.pipe(Schema.between(200, 599)))(Number(status));
|
|
24
|
+
}
|
|
25
|
+
return definition;
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/mock-api/errors.ts
|
|
29
|
+
var ApiMockError = class extends Data.TaggedError("ApiMockError") {};
|
|
30
|
+
var ApiRequestError = class extends Data.TaggedError("ApiRequestError") {};
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/mock-api/capture.ts
|
|
33
|
+
const SECRET_KEYS = [
|
|
34
|
+
"authorization",
|
|
35
|
+
"proxy-authorization",
|
|
36
|
+
"cookie",
|
|
37
|
+
"set-cookie",
|
|
38
|
+
"api-key",
|
|
39
|
+
"x-api-key",
|
|
40
|
+
"token",
|
|
41
|
+
"password",
|
|
42
|
+
"secret"
|
|
43
|
+
];
|
|
44
|
+
const apiCapture = (keys = []) => {
|
|
45
|
+
const sensitive = new Set([...SECRET_KEYS, ...keys].map((key) => key.toLowerCase()));
|
|
46
|
+
const capture = validationCapture();
|
|
47
|
+
return (value) => {
|
|
48
|
+
try {
|
|
49
|
+
const text = JSON.stringify(value, (key, current) => sensitive.has(key.toLowerCase()) ? "[redacted]" : current);
|
|
50
|
+
return capture(text === void 0 ? null : JSON.parse(text));
|
|
51
|
+
} catch {
|
|
52
|
+
return unavailableValue;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/mock-api/standard-schema.ts
|
|
58
|
+
const decodeStandard = (schema, value) => Effect.tryPromise({
|
|
59
|
+
try: async () => {
|
|
60
|
+
const result = await schema["~standard"].validate(value);
|
|
61
|
+
if (result.issues !== void 0) throw new Error(result.issues.map(({ message }) => message).join("; "));
|
|
62
|
+
return result.value;
|
|
63
|
+
},
|
|
64
|
+
catch: () => new ApiMockError({ message: "Value does not match the declared schema" })
|
|
65
|
+
});
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/mock-api/response.ts
|
|
68
|
+
const HeaderName = Schema.String.pipe(Schema.pattern(/^[!#$%&'*+.^_`|~A-Za-z0-9-]+$/), Schema.filter((name) => ![
|
|
69
|
+
"content-length",
|
|
70
|
+
"transfer-encoding",
|
|
71
|
+
"content-type"
|
|
72
|
+
].includes(name.toLowerCase())));
|
|
73
|
+
const Response = Schema.Struct({
|
|
74
|
+
status: Schema.Int,
|
|
75
|
+
body: Schema.Unknown,
|
|
76
|
+
headers: Schema.optional(Schema.Record({
|
|
77
|
+
key: HeaderName,
|
|
78
|
+
value: Schema.String.pipe(Schema.pattern(/^[\t\x20-\x7e\x80-\xff]*$/))
|
|
79
|
+
}))
|
|
80
|
+
});
|
|
81
|
+
const bodyless = (status) => [
|
|
82
|
+
204,
|
|
83
|
+
205,
|
|
84
|
+
304
|
|
85
|
+
].includes(status);
|
|
86
|
+
const endpointResponse = (route, input, log) => Effect.gen(function* () {
|
|
87
|
+
const decoded = yield* decodeStandard(route.inputSchema, input).pipe(Effect.mapError(() => new ApiRequestError({
|
|
88
|
+
status: 400,
|
|
89
|
+
message: "Request does not match the endpoint schema"
|
|
90
|
+
})));
|
|
91
|
+
const returned = yield* Effect.tryPromise({
|
|
92
|
+
try: (signal) => Promise.resolve(route.handler(decoded, {
|
|
93
|
+
signal,
|
|
94
|
+
log
|
|
95
|
+
})),
|
|
96
|
+
catch: () => new ApiMockError({ message: "Endpoint handler threw" })
|
|
97
|
+
}).pipe(Effect.timeoutFail({
|
|
98
|
+
duration: "30 seconds",
|
|
99
|
+
onTimeout: () => new ApiMockError({ message: "Endpoint handler timed out" })
|
|
100
|
+
}));
|
|
101
|
+
const response = yield* Schema.decodeUnknown(Response)(returned).pipe(Effect.mapError(() => new ApiMockError({ message: "Invalid endpoint response" })));
|
|
102
|
+
const schema = route.responses[response.status];
|
|
103
|
+
if (schema === void 0) return yield* new ApiMockError({ message: "Endpoint returned an undeclared status" });
|
|
104
|
+
const output = yield* decodeStandard(schema, response.body);
|
|
105
|
+
if (bodyless(response.status) && output !== null) return yield* new ApiMockError({ message: "This HTTP status cannot carry a response body" });
|
|
106
|
+
const body = yield* Effect.try({
|
|
107
|
+
try: () => {
|
|
108
|
+
const text = JSON.stringify(output);
|
|
109
|
+
if (text === void 0) throw new Error("Response body is undefined");
|
|
110
|
+
return text;
|
|
111
|
+
},
|
|
112
|
+
catch: () => new ApiMockError({ message: "Response is not JSON serializable" })
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
...response,
|
|
116
|
+
body,
|
|
117
|
+
error: null
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/mock-api/handler.ts
|
|
122
|
+
const Json = Schema.parseJson(Schema.Unknown);
|
|
123
|
+
const JSON_CONTENT_TYPE = /^application\/(?:[a-z0-9!#$&^_.+-]+\+)?json$/i;
|
|
124
|
+
const requestHandler = (definition, route, sequence, record) => Effect.gen(function* () {
|
|
125
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
126
|
+
const routeContext = yield* Effect.serviceOption(HttpRouter.RouteContext);
|
|
127
|
+
const params = Option.isSome(routeContext) ? routeContext.value.params : {};
|
|
128
|
+
const index = yield* Ref.getAndUpdate(sequence, (value) => value + 1);
|
|
129
|
+
const startedAt = yield* Clock.currentTimeMillis;
|
|
130
|
+
const url = new URL(request.url, "http://localhost");
|
|
131
|
+
const capture = apiCapture(definition.redact);
|
|
132
|
+
const captureLog = apiCapture(definition.redact);
|
|
133
|
+
const logs = [];
|
|
134
|
+
const fields = {
|
|
135
|
+
params,
|
|
136
|
+
query: HttpServerRequest.searchParamsFromURL(url),
|
|
137
|
+
headers: request.headers
|
|
138
|
+
};
|
|
139
|
+
let input = fields;
|
|
140
|
+
const save = (status, output, error) => Effect.gen(function* () {
|
|
141
|
+
const finishedAt = yield* Clock.currentTimeMillis;
|
|
142
|
+
yield* record({
|
|
143
|
+
api: definition.name,
|
|
144
|
+
index,
|
|
145
|
+
method: request.method,
|
|
146
|
+
path: url.pathname,
|
|
147
|
+
matched: route !== void 0,
|
|
148
|
+
startedAt,
|
|
149
|
+
durationMs: Math.max(0, Math.round(finishedAt - startedAt)),
|
|
150
|
+
input: capture(input),
|
|
151
|
+
output: capture(output),
|
|
152
|
+
status,
|
|
153
|
+
error,
|
|
154
|
+
logs
|
|
155
|
+
});
|
|
156
|
+
}).pipe(Effect.uninterruptible);
|
|
157
|
+
const { status, headers, body, error } = yield* Effect.gen(function* () {
|
|
158
|
+
if (route === void 0) return yield* new ApiRequestError({
|
|
159
|
+
status: 404,
|
|
160
|
+
message: "No mock endpoint matches this request"
|
|
161
|
+
});
|
|
162
|
+
const text = yield* request.text.pipe(Effect.mapError(() => new ApiRequestError({
|
|
163
|
+
status: 413,
|
|
164
|
+
message: "Request body could not be read within the size limit"
|
|
165
|
+
})));
|
|
166
|
+
if (text && !JSON_CONTENT_TYPE.test(request.headers["content-type"]?.split(";")[0]?.trim() ?? "")) return yield* new ApiRequestError({
|
|
167
|
+
status: 415,
|
|
168
|
+
message: "Expected a JSON request body"
|
|
169
|
+
});
|
|
170
|
+
const body = text === "" ? null : yield* Schema.decodeUnknown(Json)(text).pipe(Effect.mapError(() => new ApiRequestError({
|
|
171
|
+
status: 400,
|
|
172
|
+
message: "Invalid JSON request body"
|
|
173
|
+
})));
|
|
174
|
+
input = {
|
|
175
|
+
...fields,
|
|
176
|
+
body
|
|
177
|
+
};
|
|
178
|
+
return yield* endpointResponse(route, input, (value) => {
|
|
179
|
+
if (logs.length < 64) logs.push(captureLog(value));
|
|
180
|
+
});
|
|
181
|
+
}).pipe(Effect.catchTags({
|
|
182
|
+
ApiRequestError: ({ status, message }) => Effect.succeed({
|
|
183
|
+
status,
|
|
184
|
+
body: JSON.stringify({ message }),
|
|
185
|
+
headers: void 0,
|
|
186
|
+
error: null
|
|
187
|
+
}),
|
|
188
|
+
ApiMockError: ({ message }) => Effect.succeed({
|
|
189
|
+
status: 500,
|
|
190
|
+
body: JSON.stringify({ message }),
|
|
191
|
+
headers: void 0,
|
|
192
|
+
error: message
|
|
193
|
+
})
|
|
194
|
+
}), Effect.onInterrupt(() => save(499, null, "Request cancelled").pipe(Effect.orDie)));
|
|
195
|
+
const empty = request.method === "HEAD" || bodyless(status);
|
|
196
|
+
yield* save(status, {
|
|
197
|
+
status,
|
|
198
|
+
headers,
|
|
199
|
+
body: empty ? null : JSON.parse(body)
|
|
200
|
+
}, error);
|
|
201
|
+
return empty ? HttpServerResponse.empty({
|
|
202
|
+
status,
|
|
203
|
+
headers
|
|
204
|
+
}) : HttpServerResponse.text(body, {
|
|
205
|
+
status,
|
|
206
|
+
headers,
|
|
207
|
+
contentType: "application/json"
|
|
208
|
+
});
|
|
209
|
+
}).pipe(HttpServerRequest.withMaxBodySize(Option.some(1048576)), Effect.withSpan("ApiMock.request"));
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/mock-api/server.ts
|
|
212
|
+
const startApi = (definition, record) => Effect.gen(function* () {
|
|
213
|
+
yield* Effect.try({
|
|
214
|
+
try: () => api(definition),
|
|
215
|
+
catch: () => new ApiMockError({ message: "Invalid API definition" })
|
|
216
|
+
});
|
|
217
|
+
const sequence = yield* Ref.make(0);
|
|
218
|
+
let router = HttpRouter.empty;
|
|
219
|
+
for (const route of definition.endpoints) router = HttpRouter.route(route.method)(router, route.path, requestHandler(definition, route, sequence, record));
|
|
220
|
+
const server = yield* make(createServer, {
|
|
221
|
+
host: "127.0.0.1",
|
|
222
|
+
port: 0
|
|
223
|
+
}).pipe(Effect.mapError(() => new ApiMockError({ message: "Could not start local API server" })));
|
|
224
|
+
yield* server.serve(router.pipe(Effect.catchTag("RouteNotFound", () => requestHandler(definition, void 0, sequence, record))));
|
|
225
|
+
if (server.address._tag !== "TcpAddress") return yield* new ApiMockError({ message: "API server did not bind TCP" });
|
|
226
|
+
return {
|
|
227
|
+
name: definition.name,
|
|
228
|
+
url: `http://127.0.0.1:${server.address.port}`,
|
|
229
|
+
endpoints: definition.endpoints.map(({ method, path, description }) => ({
|
|
230
|
+
method,
|
|
231
|
+
path,
|
|
232
|
+
...description ? { description } : {}
|
|
233
|
+
}))
|
|
234
|
+
};
|
|
235
|
+
}).pipe(Effect.withSpan("ApiMock.start"));
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/mock-api/runtime.ts
|
|
238
|
+
const withApi = ({ api, run }) => Effect.gen(function* () {
|
|
239
|
+
const calls = yield* Ref.make([]);
|
|
240
|
+
const fatal = yield* Deferred.make();
|
|
241
|
+
const server = yield* startApi(api, (call) => Ref.modify(calls, (values) => [values.length < 256, values.length < 256 ? [...values, call] : values]).pipe(Effect.flatMap((recorded) => recorded ? Effect.void : Deferred.fail(fatal, new ApiMockError({ message: "API request limit exceeded" })).pipe(Effect.asVoid))));
|
|
242
|
+
const result = yield* Effect.tryPromise({
|
|
243
|
+
try: () => run({
|
|
244
|
+
url: server.url,
|
|
245
|
+
calls: () => Effect.runPromise(Ref.get(calls))
|
|
246
|
+
}),
|
|
247
|
+
catch: (cause) => cause
|
|
248
|
+
}).pipe(Effect.raceFirst(Deferred.await(fatal)));
|
|
249
|
+
if ((yield* Ref.get(calls)).some((call) => call.error !== null)) return yield* new ApiMockError({ message: "An API endpoint failed during execution" });
|
|
250
|
+
return result;
|
|
251
|
+
}).pipe(Effect.scoped, Effect.withSpan("ApiMock.withApi"), Effect.runPromise);
|
|
252
|
+
const runApiServers = (definitions) => Effect.gen(function* () {
|
|
253
|
+
const fs = yield* FileSystem.FileSystem;
|
|
254
|
+
const fatal = yield* Deferred.make();
|
|
255
|
+
yield* fs.makeDirectory(".anpord/api", { recursive: true });
|
|
256
|
+
yield* fs.writeFileString(API_JOURNAL, "");
|
|
257
|
+
const lock = yield* Effect.makeSemaphore(1);
|
|
258
|
+
const count = yield* Ref.make(0);
|
|
259
|
+
const record = (call) => Effect.gen(function* () {
|
|
260
|
+
if ((yield* Ref.getAndUpdate(count, (value) => value + 1)) >= 256) return yield* new ApiMockError({ message: "API request limit exceeded" });
|
|
261
|
+
yield* fs.writeFileString(API_JOURNAL, `${JSON.stringify(call)}\n`, { flag: "a" });
|
|
262
|
+
}).pipe(Effect.mapError(() => new ApiMockError({ message: "API request evidence could not be written" })), Effect.tapError((cause) => Deferred.fail(fatal, cause)), lock.withPermits(1));
|
|
263
|
+
const manifest = yield* Effect.forEach(definitions, (definition) => startApi(definition, record));
|
|
264
|
+
yield* fs.writeFileString(API_MANIFEST, JSON.stringify(manifest));
|
|
265
|
+
yield* Effect.sync(() => process.stdout.write(`${API_READY}${JSON.stringify(manifest)}\n`));
|
|
266
|
+
yield* Deferred.await(fatal);
|
|
267
|
+
}).pipe(Effect.scoped, Effect.provide(layer), Effect.withSpan("ApiMock.serve"), runMain);
|
|
268
|
+
//#endregion
|
|
269
|
+
export { endpoint as i, withApi as n, api as r, runApiServers as t };
|