@agentcomms/events-daemon 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -5
- package/dist/{b3-contract-C1q5aekF.mjs → b3-contract-CG8Z2OtX.mjs} +320 -67
- package/dist/cli.mjs +3200 -121
- package/dist/index.d.mts +152 -47
- package/dist/index.mjs +1 -1
- package/dist/laya-worker.d.mts +1 -0
- package/dist/laya-worker.mjs +356 -0
- package/dist/{records-DsUxYBwb.mjs → records-D15LoVeb.mjs} +100 -3
- package/dist/records-qtNEBi7g.mjs +2 -0
- package/dist/{webhook-target-DyDTwWhV.mjs → webhook-target-EzLIFpIY.mjs} +551 -17
- package/dist/worker-boundary-probe-CFN6EsyK.mjs +850 -0
- package/laya-enablement-disclosures.json +17 -0
- package/laya-manifest.json +52 -0
- package/laya-runtime.json +4 -0
- package/package.json +12 -9
- package/dist/records-DjE5a4_H.mjs +0 -2
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { a as number, c as unknown, o as strictObject, s as string, t as McpServer } from "./mcp-DIH4cS6P-YuKZfqTg.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { h as isLayaTemplateId, m as LAYA_RUNNABLE_TEMPLATE_IDS, v as installErrorSink } from "./worker-boundary-probe-CFN6EsyK.mjs";
|
|
3
|
+
import { _ as JUDGE_KIND_TYPESAFE, c as validateLocalEndpoint, d as assertApprovedAddressSet, f as parseIpLiteral, g as JUDGE_KIND_LOCAL_ENDPOINT, h as JUDGE_KIND_LAYA, m as JUDGE_KINDS, n as canonicalWebhookTarget, o as LayaContractError, p as EventDomainError, s as createLayaJudgeKindDefinition } from "./webhook-target-EzLIFpIY.mjs";
|
|
3
4
|
import { createHash, randomBytes } from "node:crypto";
|
|
4
5
|
import { chmod, lstat, mkdir, open, readFile, realpath, rm, writeFile } from "node:fs/promises";
|
|
5
6
|
import { createConnection } from "node:net";
|
|
6
7
|
import { CommsError, ERROR_REGISTRY, canonicalDisclosureBinding, canonicalJson, isCommsError, neutralise, resolvePaths, sha256Hex } from "@agentcomms/core";
|
|
7
|
-
import { constants } from "node:fs";
|
|
8
|
-
import { basename, dirname, join } from "node:path";
|
|
8
|
+
import { constants, readFileSync } from "node:fs";
|
|
9
|
+
import { basename, dirname, join, sep } from "node:path";
|
|
9
10
|
import { TEST_CLOUD_EVENT, canonicaliseAgenticCondition, canonicaliseCondition, catalogueEntry, compileMapping, isJsonValue, parsePointer, validateCloudEventType } from "@agentcomms/events";
|
|
10
|
-
//#region src/network/error-sink.ts
|
|
11
|
-
/**
|
|
12
|
-
* Keeps an owned network resource from turning a later transport error into an uncaught exception.
|
|
13
|
-
* Operation-specific listeners still translate errors into their own result while they are active.
|
|
14
|
-
*/
|
|
15
|
-
function installErrorSink(resource) {
|
|
16
|
-
resource.on("error", () => void 0);
|
|
17
|
-
return resource;
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
11
|
//#region src/runtime/paths.ts
|
|
21
12
|
const DIRECTORY_MODE = 448;
|
|
22
13
|
const FILE_MODE = 384;
|
|
@@ -357,15 +348,15 @@ function append(first, second) {
|
|
|
357
348
|
return joined;
|
|
358
349
|
}
|
|
359
350
|
function isControlHello(value) {
|
|
360
|
-
if (!isRecord$
|
|
351
|
+
if (!isRecord$4(value) || !isRecord$4(value.hello)) return false;
|
|
361
352
|
const { supportedVersions, token, client } = value.hello;
|
|
362
|
-
return Array.isArray(supportedVersions) && supportedVersions.length > 0 && supportedVersions.length <= 8 && supportedVersions.every((version) => Number.isSafeInteger(version)) && typeof token === "string" && token.length === 64 && isRecord$
|
|
353
|
+
return Array.isArray(supportedVersions) && supportedVersions.length > 0 && supportedVersions.length <= 8 && supportedVersions.every((version) => Number.isSafeInteger(version)) && typeof token === "string" && token.length === 64 && isRecord$4(client) && typeof client.name === "string" && client.name.length > 0 && client.name.length <= 128;
|
|
363
354
|
}
|
|
364
355
|
function isControlRequest(value) {
|
|
365
|
-
if (!isRecord$
|
|
366
|
-
return Number.isSafeInteger(value.version) && typeof value.requestId === "string" && value.requestId.length > 0 && value.requestId.length <= 128 && typeof value.session === "string" && value.session.length > 0 && value.session.length <= 256 && typeof value.operation === "string" && value.operation.length > 0 && value.operation.length <= 128 && isRecord$
|
|
356
|
+
if (!isRecord$4(value)) return false;
|
|
357
|
+
return Number.isSafeInteger(value.version) && typeof value.requestId === "string" && value.requestId.length > 0 && value.requestId.length <= 128 && typeof value.session === "string" && value.session.length > 0 && value.session.length <= 256 && typeof value.operation === "string" && value.operation.length > 0 && value.operation.length <= 128 && isRecord$4(value.args);
|
|
367
358
|
}
|
|
368
|
-
function isRecord$
|
|
359
|
+
function isRecord$4(value) {
|
|
369
360
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
370
361
|
}
|
|
371
362
|
//#endregion
|
|
@@ -407,7 +398,7 @@ async function probeControl(paths, record, token) {
|
|
|
407
398
|
}
|
|
408
399
|
}
|
|
409
400
|
async function requestControl(record, token, clientName, operation, args) {
|
|
410
|
-
const socket = await connect(record.endpoint);
|
|
401
|
+
const socket = await connect$1(record.endpoint);
|
|
411
402
|
try {
|
|
412
403
|
const hello = await exchange(socket, { hello: {
|
|
413
404
|
supportedVersions: CONTROL_PROTOCOL_VERSIONS,
|
|
@@ -439,7 +430,7 @@ async function readToken(paths, record) {
|
|
|
439
430
|
if (!/^[0-9a-f]{64}$/.test(token) || tokenFingerprint(token) !== record.tokenFingerprint) throw notRunning();
|
|
440
431
|
return token;
|
|
441
432
|
}
|
|
442
|
-
function connect(endpoint) {
|
|
433
|
+
function connect$1(endpoint) {
|
|
443
434
|
return new Promise((resolve, reject) => {
|
|
444
435
|
const socket = createConnection(endpoint);
|
|
445
436
|
installErrorSink(socket);
|
|
@@ -605,6 +596,35 @@ function assertDoctorReportV2(report) {
|
|
|
605
596
|
if (Object.keys(report).some((key) => !DOCTOR_REPORT_V2_KEYS.includes(key))) throw new Error("doctor-v2 report is closed");
|
|
606
597
|
return report;
|
|
607
598
|
}
|
|
599
|
+
const DOCTOR_REPORT_V3_JUDGE_KEYS = [
|
|
600
|
+
"kinds",
|
|
601
|
+
"budget",
|
|
602
|
+
"reservations",
|
|
603
|
+
"holds",
|
|
604
|
+
JUDGE_KIND_LAYA
|
|
605
|
+
];
|
|
606
|
+
const DOCTOR_REPORT_V3_LAYA_KEYS = [
|
|
607
|
+
"state",
|
|
608
|
+
"manifestId",
|
|
609
|
+
"runtimeLockDigest",
|
|
610
|
+
"runtime",
|
|
611
|
+
"model",
|
|
612
|
+
"boundary",
|
|
613
|
+
"failureCode",
|
|
614
|
+
"bytesVerified",
|
|
615
|
+
"totalBytes"
|
|
616
|
+
];
|
|
617
|
+
function exactlyKeys(value, keys) {
|
|
618
|
+
const found = Object.keys(value);
|
|
619
|
+
return found.length === keys.length && keys.every((key) => found.includes(key));
|
|
620
|
+
}
|
|
621
|
+
/** The projection boundary: a v3 report, its judge entry and its Laya entry each have exactly their fields. */
|
|
622
|
+
function assertDoctorReportV3(report) {
|
|
623
|
+
if (Object.keys(report).some((key) => !DOCTOR_REPORT_V2_KEYS.includes(key))) throw new Error("doctor-v3 report is closed");
|
|
624
|
+
if (!exactlyKeys(report.judge, DOCTOR_REPORT_V3_JUDGE_KEYS)) throw new Error("doctor-v3 judge entry is closed");
|
|
625
|
+
if (!exactlyKeys(report.judge.laya, DOCTOR_REPORT_V3_LAYA_KEYS)) throw new Error("doctor-v3 Laya entry is closed");
|
|
626
|
+
return report;
|
|
627
|
+
}
|
|
608
628
|
async function doctor(options = {}) {
|
|
609
629
|
return await new EventControlClient({ stateDir: options.stateDir }).request("doctor");
|
|
610
630
|
}
|
|
@@ -832,7 +852,7 @@ async function removeTarget(targetId, options = {}) {
|
|
|
832
852
|
//#endregion
|
|
833
853
|
//#region src/version.ts
|
|
834
854
|
/** The package version, read from package.json at build time. */
|
|
835
|
-
const VERSION = "0.
|
|
855
|
+
const VERSION = "0.26.0";
|
|
836
856
|
//#endregion
|
|
837
857
|
//#region src/mcp/server.ts
|
|
838
858
|
function reply(data) {
|
|
@@ -970,14 +990,14 @@ async function createEventsMcpServer(options = {}) {
|
|
|
970
990
|
}, (args) => judgeTest(args.judgeId, args.version, options));
|
|
971
991
|
strictControlTool("events_budget_show", "Show budget", "Lists immutable judge budgets and the active singleton.", {}, () => budgetShow(options));
|
|
972
992
|
strictControlTool("events_budget_update", "Update budget", "Creates a pending immutable global budget and prepares its approval.", { document: unknown() }, (args) => b3("updateBudget", { document: args.document }, () => updateBudget(args.document, options)), true);
|
|
973
|
-
strictControlTool("events_judge_kinds_list", "List judge kinds", "Lists
|
|
993
|
+
strictControlTool("events_judge_kinds_list", "List judge kinds", "Lists each judge kind as disabled or enabled, or Laya as unavailable here with its reason.", {}, () => judgeKindsList(options));
|
|
974
994
|
strictControlTool("events_judge_kind_enable", "Enable judge kind", "Prepares, but never approves or claims, judge-kind enablement.", { kind: string().min(1) }, (args) => b3("enableJudgeKind", { kind: args.kind }, () => enableJudgeKind(args.kind, options)), true);
|
|
975
|
-
strictControlTool("events_judge_kind_disable", "Disable judge kind", "Immediately disables one
|
|
995
|
+
strictControlTool("events_judge_kind_disable", "Disable judge kind", "Immediately disables one judge kind; for Laya it also cancels a download and keeps verified files.", { kind: string().min(1) }, (args) => {
|
|
976
996
|
const kind = args.kind;
|
|
977
997
|
return b3("disableJudgeKind", { kind }, () => disableJudgeKind(kind, options));
|
|
978
998
|
}, true);
|
|
979
|
-
strictControlTool("events_judge_model_status", "Judge model status", "
|
|
980
|
-
strictControlTool("events_judge_model_remove", "Remove judge model", "
|
|
999
|
+
strictControlTool("events_judge_model_status", "Judge model status", "Reports the local Laya runtime and model state, byte progress and any failure or unavailable reason.", {}, () => judgeModelStatus(options));
|
|
1000
|
+
strictControlTool("events_judge_model_remove", "Remove judge model", "Deletes the verified Laya model and runtime files, only while Laya is disabled.", {}, () => removeJudgeModel(options), true);
|
|
981
1001
|
strictControlTool("events_deliveries_list", "List deliveries", "Lists content-free delivery metadata.", {}, () => deliveriesList(options));
|
|
982
1002
|
strictControlTool("events_delivery_retry", "Retry delivery", "Retries one exact retryable delivery.", { deliveryId: string().min(1) }, (args) => retryDelivery(args.deliveryId, options), true);
|
|
983
1003
|
strictControlTool("events_delivery_drop", "Drop delivery", "Drops one exact dead-letter delivery and its retained payload.", { deliveryId: string().min(1) }, (args) => dropDelivery(args.deliveryId, options), true);
|
|
@@ -1013,6 +1033,37 @@ const TYPESAFE_SYSTEM_ONE_ENDPOINT = "https://api.typesafe.ai/v1/systemone";
|
|
|
1013
1033
|
const JUDGE_BUDGET_ID = "judge-budget";
|
|
1014
1034
|
/** Provider record: docs/superpowers/plans/2026-10-10-events-phase-e-provider-record.md, read 2026-10-10. */
|
|
1015
1035
|
const APPROVED_TYPESAFE_MODELS = ["jev-1.13.0"];
|
|
1036
|
+
const layaInputsByDatabase = /* @__PURE__ */ new WeakMap();
|
|
1037
|
+
/**
|
|
1038
|
+
* One owner registers the Laya inputs its own activation path validates with, for its database, as it registers E's
|
|
1039
|
+
* purge listener: so E's budget fence, settlement and every other reader of that database's Laya kind document use
|
|
1040
|
+
* the same reviewed bytes. Production's inputs are empty — the shipped assets and this process's platform.
|
|
1041
|
+
*/
|
|
1042
|
+
function registerLayaEnablementInputs(database, inputs) {
|
|
1043
|
+
if (layaInputsByDatabase.has(database)) throw new Error("Laya enablement inputs are already registered");
|
|
1044
|
+
layaInputsByDatabase.set(database, inputs);
|
|
1045
|
+
return () => {
|
|
1046
|
+
if (layaInputsByDatabase.get(database) === inputs) layaInputsByDatabase.delete(database);
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
/** The inputs registered for one database, or none: the shipped assets and this process's platform. */
|
|
1050
|
+
function layaEnablementInputsFor(database) {
|
|
1051
|
+
return layaInputsByDatabase.get(database) ?? {};
|
|
1052
|
+
}
|
|
1053
|
+
const LAYA_JUDGE_KIND_DEFINITION = {
|
|
1054
|
+
kind: JUDGE_KINDS[1],
|
|
1055
|
+
availability: () => shippedLayaDefinition().availability(),
|
|
1056
|
+
judgeTerms: () => shippedLayaDefinition().judgeTerms(),
|
|
1057
|
+
prepareEnablement: (input) => shippedLayaDefinition().prepareEnablement(input),
|
|
1058
|
+
canonicalEnablement: (value) => shippedLayaDefinition().canonicalEnablement(value),
|
|
1059
|
+
preview: (input) => shippedLayaDefinition().preview(input),
|
|
1060
|
+
onEnabled: (enablement, activation) => shippedLayaDefinition().onEnabled(enablement, activation),
|
|
1061
|
+
execute: (request, reservation) => shippedLayaDefinition().execute(request, reservation),
|
|
1062
|
+
onWorkPurged: (scope) => shippedLayaDefinition().onWorkPurged(scope),
|
|
1063
|
+
onDisabled: () => shippedLayaDefinition().onDisabled(),
|
|
1064
|
+
status: () => shippedLayaDefinition().status(),
|
|
1065
|
+
removeWhenDisabled: () => shippedLayaDefinition().removeWhenDisabled()
|
|
1066
|
+
};
|
|
1016
1067
|
/** Phase E's closed registry. The lifecycle module owns the literal vocabulary; this registry owns its availability. */
|
|
1017
1068
|
const JUDGE_KIND_DEFINITIONS = [
|
|
1018
1069
|
{
|
|
@@ -1022,7 +1073,8 @@ const JUDGE_KIND_DEFINITIONS = [
|
|
|
1022
1073
|
{
|
|
1023
1074
|
kind: JUDGE_KINDS[1],
|
|
1024
1075
|
availability: "unavailable",
|
|
1025
|
-
unavailableCode: "E2_REQUIRED"
|
|
1076
|
+
unavailableCode: "E2_REQUIRED",
|
|
1077
|
+
implementation: LAYA_JUDGE_KIND_DEFINITION
|
|
1026
1078
|
},
|
|
1027
1079
|
{
|
|
1028
1080
|
kind: JUDGE_KINDS[2],
|
|
@@ -1032,6 +1084,95 @@ const JUDGE_KIND_DEFINITIONS = [
|
|
|
1032
1084
|
function fail$3(message, code = "VERSION_DOCUMENT_INVALID") {
|
|
1033
1085
|
throw new EventDomainError(code, message);
|
|
1034
1086
|
}
|
|
1087
|
+
/**
|
|
1088
|
+
* The daemon package's root, where its three reviewed Laya assets ship: two levels above this module in the source
|
|
1089
|
+
* tree (`src/domain/`), one above the bundle that carries it (`dist/`), by the same rule as the worker entry.
|
|
1090
|
+
*/
|
|
1091
|
+
const SHIPPED_PACKAGE_ROOT = import.meta.dirname.endsWith(`${sep}dist`) ? join(import.meta.dirname, "..") : join(import.meta.dirname, "..", "..");
|
|
1092
|
+
/** The production assets remain blocked until Task 10's owner-only lock gate replaces the placeholder. */
|
|
1093
|
+
function shippedLayaAssetSource() {
|
|
1094
|
+
return {
|
|
1095
|
+
manifestBytes: readFileSync(join(SHIPPED_PACKAGE_ROOT, "laya-manifest.json")),
|
|
1096
|
+
runtimeLockBytes: readFileSync(join(SHIPPED_PACKAGE_ROOT, "laya-runtime.json")),
|
|
1097
|
+
disclosuresBytes: readFileSync(join(SHIPPED_PACKAGE_ROOT, "laya-enablement-disclosures.json"))
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
function shippedLayaDefinition(inputs = {}) {
|
|
1101
|
+
return createLayaJudgeKindDefinition({
|
|
1102
|
+
assets: inputs.layaAssetSource ?? shippedLayaAssetSource(),
|
|
1103
|
+
platform: inputs.layaPlatformProbe ?? {
|
|
1104
|
+
platform: process.platform,
|
|
1105
|
+
architecture: process.arch
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* The one reviewed Laya definition for exactly the inputs E's activation path validates against: the shipped asset
|
|
1111
|
+
* bytes and this process's platform in production, the same strict-parsed fixture bytes in tests.
|
|
1112
|
+
*/
|
|
1113
|
+
function layaJudgeKindDefinitionFor(inputs = {}) {
|
|
1114
|
+
return shippedLayaDefinition(inputs);
|
|
1115
|
+
}
|
|
1116
|
+
function layaEnablement(value, inputs = {}) {
|
|
1117
|
+
try {
|
|
1118
|
+
const implementation = inputs.layaAssetSource === void 0 && inputs.layaPlatformProbe === void 0 ? judgeKindDefinition(JUDGE_KINDS[1]).implementation : shippedLayaDefinition(inputs);
|
|
1119
|
+
if (implementation === void 0) return fail$3("the Laya registry implementation is absent");
|
|
1120
|
+
return implementation.canonicalEnablement(value);
|
|
1121
|
+
} catch (error) {
|
|
1122
|
+
if (error instanceof LayaContractError) {
|
|
1123
|
+
if (error.code === "E2_EXTERNAL_REFERENCE_BLOCKED") return fail$3("the reviewed Laya runtime lock is blocked", "E2_EXTERNAL_REFERENCE_BLOCKED");
|
|
1124
|
+
if (error.code === "LAYA_PLATFORM_UNAVAILABLE") return fail$3("Laya is unavailable on this platform", "LAYA_PLATFORM_UNAVAILABLE");
|
|
1125
|
+
if (error.code === "LAYA_SANDBOX_UNAVAILABLE") return fail$3("the macOS Laya boundary is unavailable", "LAYA_SANDBOX_UNAVAILABLE");
|
|
1126
|
+
}
|
|
1127
|
+
return fail$3("the Laya enablement is not its exact reviewed document");
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
/** Performs only the content-free availability probe before an activation can create its first intent. */
|
|
1131
|
+
function assertLayaJudgeKindAvailable(inputs = {}) {
|
|
1132
|
+
const implementation = inputs.layaAssetSource === void 0 && inputs.layaPlatformProbe === void 0 ? judgeKindDefinition(JUDGE_KINDS[1]).implementation : shippedLayaDefinition(inputs);
|
|
1133
|
+
if (implementation === void 0) fail$3("the Laya registry implementation is absent");
|
|
1134
|
+
const availability = implementation.availability();
|
|
1135
|
+
if (availability.available) return;
|
|
1136
|
+
if (availability.code === "E2_EXTERNAL_REFERENCE_BLOCKED") fail$3("the reviewed Laya runtime lock is blocked", "E2_EXTERNAL_REFERENCE_BLOCKED");
|
|
1137
|
+
if (availability.code === "LAYA_PLATFORM_UNAVAILABLE") fail$3("Laya is unavailable on this platform", "LAYA_PLATFORM_UNAVAILABLE");
|
|
1138
|
+
fail$3("the macOS Laya boundary is unavailable", "LAYA_SANDBOX_UNAVAILABLE");
|
|
1139
|
+
}
|
|
1140
|
+
/** The reviewed terms a Laya judge is created under, for exactly the inputs E's activation path validates with. */
|
|
1141
|
+
function layaJudgeTermsFor(inputs = {}) {
|
|
1142
|
+
try {
|
|
1143
|
+
const implementation = inputs.layaAssetSource === void 0 && inputs.layaPlatformProbe === void 0 ? judgeKindDefinition(JUDGE_KINDS[1]).implementation : shippedLayaDefinition(inputs);
|
|
1144
|
+
if (implementation === void 0) return fail$3("the Laya registry implementation is absent");
|
|
1145
|
+
return implementation.judgeTerms();
|
|
1146
|
+
} catch (error) {
|
|
1147
|
+
if (error instanceof LayaContractError) return fail$3("the reviewed Laya manifest cannot be read");
|
|
1148
|
+
throw error;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* B3 control v3 (D2, D11): a Laya judge is configuration, kept whatever Laya's state on this machine or in this release,
|
|
1153
|
+
* and it evaluates only once Laya is enabled and ready. It may name only what this release could run: the reviewed
|
|
1154
|
+
* manifest entry, and a template that entry lists and the worker runs. The reason is in each message, because the
|
|
1155
|
+
* message is all the CLI and MCP show.
|
|
1156
|
+
*/
|
|
1157
|
+
function assertCreatableLayaJudge(judge, inputs = {}) {
|
|
1158
|
+
if (judge?.kind !== "laya") return;
|
|
1159
|
+
const terms = layaJudgeTermsFor(inputs);
|
|
1160
|
+
if (judge.model !== terms.manifestId) fail$3(`a Laya judge names this release's reviewed manifest, ${terms.manifestId} (LAYA_MANIFEST_NOT_REVIEWED)`, "LAYA_MANIFEST_NOT_REVIEWED");
|
|
1161
|
+
if (!terms.promptTemplates.includes(judge.promptTemplate) || !LAYA_RUNNABLE_TEMPLATE_IDS.includes(judge.promptTemplate)) fail$3(`a Laya judge uses ${LAYA_RUNNABLE_TEMPLATE_IDS.join(" or ")}; ${judge.promptTemplate} is not offered (LAYA_TEMPLATE_BLOCKED)`, "LAYA_TEMPLATE_BLOCKED");
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* D11: a rule naming a Laya judge is activated only where this release and platform offer Laya. Anywhere else its
|
|
1165
|
+
* judge could never evaluate, so preparing, claiming or finalising the rule is refused with Laya's own closed reason,
|
|
1166
|
+
* before the kind's state: never a rule that silently cannot ask.
|
|
1167
|
+
*/
|
|
1168
|
+
function assertLayaRuleJudgeOffered(inputs = {}) {
|
|
1169
|
+
try {
|
|
1170
|
+
assertLayaJudgeKindAvailable(inputs);
|
|
1171
|
+
} catch (error) {
|
|
1172
|
+
if (error instanceof EventDomainError) throw new EventDomainError(error.code, `this rule's Laya judge cannot evaluate here: Laya is not offered (${error.code})`);
|
|
1173
|
+
throw error;
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1035
1176
|
function record$1(value, name) {
|
|
1036
1177
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return fail$3(`${name} is an object`);
|
|
1037
1178
|
try {
|
|
@@ -1045,7 +1186,7 @@ function exactKeys$1(value, keys, name) {
|
|
|
1045
1186
|
const wanted = [...keys].sort();
|
|
1046
1187
|
if (found.length !== wanted.length || found.some((key, index) => key !== wanted[index])) fail$3(`${name} has exactly its canonical fields`);
|
|
1047
1188
|
}
|
|
1048
|
-
function text$
|
|
1189
|
+
function text$2(value, name) {
|
|
1049
1190
|
if (typeof value !== "string" || value.length === 0) return fail$3(`${name} is a non-empty string`);
|
|
1050
1191
|
return value;
|
|
1051
1192
|
}
|
|
@@ -1060,7 +1201,7 @@ function protocol(value, name) {
|
|
|
1060
1201
|
}
|
|
1061
1202
|
if (value.protocol !== "json-score") return fail$3(`${name} has protocol noul or json-score`);
|
|
1062
1203
|
exactKeys$1(value, ["protocol", "scorePointer"], name);
|
|
1063
|
-
const scorePointer = text$
|
|
1204
|
+
const scorePointer = text$2(value.scorePointer, `${name} scorePointer`);
|
|
1064
1205
|
const parsed = parsePointer(scorePointer);
|
|
1065
1206
|
if (!parsed.ok || parsed.value.includes("*")) return fail$3(`${name} scorePointer is one concrete JSON Pointer`);
|
|
1066
1207
|
return {
|
|
@@ -1070,13 +1211,13 @@ function protocol(value, name) {
|
|
|
1070
1211
|
}
|
|
1071
1212
|
function identity(value, name) {
|
|
1072
1213
|
return {
|
|
1073
|
-
judgeId: text$
|
|
1214
|
+
judgeId: text$2(value.judgeId, `${name} id`),
|
|
1074
1215
|
version: positiveInteger$2(value.version, `${name} version`)
|
|
1075
1216
|
};
|
|
1076
1217
|
}
|
|
1077
1218
|
function localAddress(value) {
|
|
1078
1219
|
if (!Array.isArray(value) || value.length !== 1) return fail$3("a local judge approvedAddressSet has one exact literal");
|
|
1079
|
-
const entry = text$
|
|
1220
|
+
const entry = text$2(value[0], "a local judge approvedAddressSet entry");
|
|
1080
1221
|
try {
|
|
1081
1222
|
assertApprovedAddressSet([entry]);
|
|
1082
1223
|
return [parseIpLiteral(entry).address];
|
|
@@ -1084,12 +1225,30 @@ function localAddress(value) {
|
|
|
1084
1225
|
return fail$3("a local judge approvedAddressSet has one valid literal");
|
|
1085
1226
|
}
|
|
1086
1227
|
}
|
|
1087
|
-
/** The one canonical, immutable judge document form.
|
|
1228
|
+
/** The one canonical, immutable judge document form. Laya's separate reviewed kind document is its activation authority. */
|
|
1088
1229
|
function canonicalJudge(value) {
|
|
1089
1230
|
const judge = record$1(value, "a judge document");
|
|
1090
1231
|
const kind = judge.kind;
|
|
1091
1232
|
if (!JUDGE_KINDS.includes(kind)) return fail$3("a judge document has a known judge kind");
|
|
1092
|
-
if (kind === "laya")
|
|
1233
|
+
if (kind === "laya") {
|
|
1234
|
+
exactKeys$1(judge, [
|
|
1235
|
+
"judgeId",
|
|
1236
|
+
"version",
|
|
1237
|
+
"kind",
|
|
1238
|
+
"provider",
|
|
1239
|
+
"model",
|
|
1240
|
+
"promptTemplate"
|
|
1241
|
+
], "a Laya judge document");
|
|
1242
|
+
if (judge.provider !== "laya") return fail$3("a Laya judge names the canonical Laya provider");
|
|
1243
|
+
if (!isLayaTemplateId(judge.promptTemplate)) return fail$3("a Laya judge names one immutable Laya prompt template");
|
|
1244
|
+
return {
|
|
1245
|
+
...identity(judge, "a Laya judge"),
|
|
1246
|
+
kind: JUDGE_KIND_LAYA,
|
|
1247
|
+
provider: JUDGE_KIND_LAYA,
|
|
1248
|
+
model: text$2(judge.model, "a Laya judge manifest id"),
|
|
1249
|
+
promptTemplate: judge.promptTemplate
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1093
1252
|
if (kind === "typesafe") {
|
|
1094
1253
|
exactKeys$1(judge, [
|
|
1095
1254
|
"judgeId",
|
|
@@ -1111,7 +1270,7 @@ function canonicalJudge(value) {
|
|
|
1111
1270
|
provider: JUDGE_KIND_TYPESAFE,
|
|
1112
1271
|
model: judge.model,
|
|
1113
1272
|
endpoint: TYPESAFE_SYSTEM_ONE_ENDPOINT,
|
|
1114
|
-
promptTemplate: text$
|
|
1273
|
+
promptTemplate: text$2(judge.promptTemplate, "a typesafe judge prompt template"),
|
|
1115
1274
|
protocol: "noul"
|
|
1116
1275
|
};
|
|
1117
1276
|
}
|
|
@@ -1142,18 +1301,18 @@ function canonicalJudge(value) {
|
|
|
1142
1301
|
"protocol"
|
|
1143
1302
|
], "a local judge document");
|
|
1144
1303
|
const approvedAddressSet = localAddress(judge.approvedAddressSet);
|
|
1145
|
-
const endpoint = text$
|
|
1304
|
+
const endpoint = text$2(judge.endpoint, "a local judge endpoint");
|
|
1146
1305
|
try {
|
|
1147
1306
|
const local = validateLocalEndpoint(endpoint, approvedAddressSet);
|
|
1148
1307
|
if (local.url.search !== "") return fail$3("a local judge endpoint has no query");
|
|
1149
1308
|
return {
|
|
1150
1309
|
...identity(judge, "a local judge"),
|
|
1151
1310
|
kind: JUDGE_KIND_LOCAL_ENDPOINT,
|
|
1152
|
-
provider: text$
|
|
1153
|
-
model: text$
|
|
1311
|
+
provider: text$2(judge.provider, "a local judge provider"),
|
|
1312
|
+
model: text$2(judge.model, "a local judge model"),
|
|
1154
1313
|
endpoint: local.url.href,
|
|
1155
1314
|
approvedAddressSet,
|
|
1156
|
-
promptTemplate: text$
|
|
1315
|
+
promptTemplate: text$2(judge.promptTemplate, "a local judge prompt template"),
|
|
1157
1316
|
...localProtocol
|
|
1158
1317
|
};
|
|
1159
1318
|
} catch (error) {
|
|
@@ -1193,12 +1352,14 @@ function canonicalJudgeBudget(value) {
|
|
|
1193
1352
|
"inputTokensPerRolling30Days",
|
|
1194
1353
|
"concurrency"
|
|
1195
1354
|
], "a judge provider budget");
|
|
1196
|
-
|
|
1197
|
-
provider: text$
|
|
1355
|
+
const canonical = {
|
|
1356
|
+
provider: text$2(provider.provider, "a judge provider id"),
|
|
1198
1357
|
callsPerRollingHour: positiveInteger$2(provider.callsPerRollingHour, "a judge provider budget callsPerRollingHour"),
|
|
1199
1358
|
inputTokensPerRolling30Days: positiveInteger$2(provider.inputTokensPerRolling30Days, "a judge provider budget inputTokensPerRolling30Days"),
|
|
1200
1359
|
concurrency: positiveInteger$2(provider.concurrency, "a judge provider budget concurrency")
|
|
1201
1360
|
};
|
|
1361
|
+
if (canonical.provider === JUDGE_KINDS[1] && canonical.concurrency > 1) return fail$3("the Laya provider is one-at-a-time");
|
|
1362
|
+
return canonical;
|
|
1202
1363
|
});
|
|
1203
1364
|
if ([...providers].sort((left, right) => left.provider < right.provider ? -1 : left.provider > right.provider ? 1 : 0).some((entry, index) => entry.provider !== providers[index]?.provider) || new Set(providers.map((entry) => entry.provider)).size !== providers.length) return fail$3("judge budget providers are sorted and duplicate-free");
|
|
1204
1365
|
return {
|
|
@@ -1208,18 +1369,19 @@ function canonicalJudgeBudget(value) {
|
|
|
1208
1369
|
providers
|
|
1209
1370
|
};
|
|
1210
1371
|
}
|
|
1211
|
-
/** The closed kind registry lookup
|
|
1372
|
+
/** The closed kind registry lookup. E2 replaces only Phase E's Laya slot. */
|
|
1212
1373
|
function judgeKindDefinition(kind) {
|
|
1213
1374
|
const definition = JUDGE_KIND_DEFINITIONS.find((candidate) => candidate.kind === kind);
|
|
1214
1375
|
if (definition === void 0) return fail$3("a judge kind has a registry definition");
|
|
1215
1376
|
return definition;
|
|
1216
1377
|
}
|
|
1217
1378
|
/** Canonicalises one inert kind-enablement version; no pointer or availability change happens here. */
|
|
1218
|
-
function canonicalJudgeKindEnablement(value) {
|
|
1379
|
+
function canonicalJudgeKindEnablement(value, inputs = {}) {
|
|
1219
1380
|
const enablement = record$1(value, "a judge-kind document");
|
|
1220
1381
|
if (!JUDGE_KINDS.includes(enablement.kind)) return fail$3("a judge-kind document has a known judge kind");
|
|
1221
1382
|
const kind = enablement.kind;
|
|
1222
|
-
if (
|
|
1383
|
+
if (kind === JUDGE_KINDS[1]) return layaEnablement(enablement, inputs);
|
|
1384
|
+
if (judgeKindDefinition(kind).availability === "unavailable") return fail$3("the judge kind is unavailable", "E2_REQUIRED");
|
|
1223
1385
|
const id = `judge-kind:${kind}`;
|
|
1224
1386
|
if (enablement.id !== id) return fail$3(`a judge-kind document id is ${id}`);
|
|
1225
1387
|
if (kind === "typesafe") {
|
|
@@ -1253,7 +1415,7 @@ function canonicalJudgeKindEnablement(value) {
|
|
|
1253
1415
|
function fail$2(message) {
|
|
1254
1416
|
throw new EventDomainError("VERSION_DOCUMENT_INVALID", message);
|
|
1255
1417
|
}
|
|
1256
|
-
function isRecord$
|
|
1418
|
+
function isRecord$3(value) {
|
|
1257
1419
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1258
1420
|
}
|
|
1259
1421
|
function exactKeys(value, keys, name) {
|
|
@@ -1284,7 +1446,7 @@ function canonicalLabels(value) {
|
|
|
1284
1446
|
}
|
|
1285
1447
|
/** Validates the Gmail source shape without silently reordering an authority-bound label array. */
|
|
1286
1448
|
function normaliseGmailSourceOptions(value) {
|
|
1287
|
-
if (!isRecord$
|
|
1449
|
+
if (!isRecord$3(value) || value.channel !== "gmail") return fail$2("a Gmail source option names the Gmail channel");
|
|
1288
1450
|
exactKeys(value, [
|
|
1289
1451
|
"channel",
|
|
1290
1452
|
"labels",
|
|
@@ -1299,7 +1461,7 @@ function normaliseGmailSourceOptions(value) {
|
|
|
1299
1461
|
}
|
|
1300
1462
|
/** Validates the Phase-D Slack source shape, retaining only canonical conversation ids. */
|
|
1301
1463
|
function normaliseSlackSourceOptions(value) {
|
|
1302
|
-
if (!isRecord$
|
|
1464
|
+
if (!isRecord$3(value) || value.channel !== "slack") return fail$2("a Slack source option names the Slack channel");
|
|
1303
1465
|
exactKeys(value, ["channel", "conversations"], "a Slack source option");
|
|
1304
1466
|
return {
|
|
1305
1467
|
channel: "slack",
|
|
@@ -1308,7 +1470,7 @@ function normaliseSlackSourceOptions(value) {
|
|
|
1308
1470
|
}
|
|
1309
1471
|
/** Validates Resend's fixed-order, non-empty event-kind set. */
|
|
1310
1472
|
function normaliseResendSourceOptions(value) {
|
|
1311
|
-
if (!isRecord$
|
|
1473
|
+
if (!isRecord$3(value) || value.channel !== "resend") return fail$2("a Resend source option names the Resend channel");
|
|
1312
1474
|
exactKeys(value, ["channel", "kinds"], "a Resend source option");
|
|
1313
1475
|
if (!Array.isArray(value.kinds) || value.kinds.length === 0) return fail$2("Resend kinds are a non-empty array");
|
|
1314
1476
|
const kinds = [...value.kinds];
|
|
@@ -1322,7 +1484,7 @@ function normaliseResendSourceOptions(value) {
|
|
|
1322
1484
|
}
|
|
1323
1485
|
/** Validates the raw WhatsApp chat selector; JIDs stay raw authority-bound strings. */
|
|
1324
1486
|
function normaliseWhatsAppSourceOptions(value) {
|
|
1325
|
-
if (!isRecord$
|
|
1487
|
+
if (!isRecord$3(value) || value.channel !== "whatsapp") return fail$2("a WhatsApp source option names the WhatsApp channel");
|
|
1326
1488
|
exactKeys(value, ["channel", "chats"], "a WhatsApp source option");
|
|
1327
1489
|
return {
|
|
1328
1490
|
channel: "whatsapp",
|
|
@@ -1331,7 +1493,7 @@ function normaliseWhatsAppSourceOptions(value) {
|
|
|
1331
1493
|
}
|
|
1332
1494
|
/** D4's closed four-channel source-options union. */
|
|
1333
1495
|
function normaliseSourceOptions(value) {
|
|
1334
|
-
if (!isRecord$
|
|
1496
|
+
if (!isRecord$3(value)) return fail$2("a source option is an object");
|
|
1335
1497
|
switch (value.channel) {
|
|
1336
1498
|
case "gmail": return normaliseGmailSourceOptions(value);
|
|
1337
1499
|
case "slack": return normaliseSlackSourceOptions(value);
|
|
@@ -1403,7 +1565,7 @@ function record(value, name) {
|
|
|
1403
1565
|
return fail$1(`${name} is canonical JSON`);
|
|
1404
1566
|
}
|
|
1405
1567
|
}
|
|
1406
|
-
function text(value, name) {
|
|
1568
|
+
function text$1(value, name) {
|
|
1407
1569
|
if (typeof value !== "string" || value.length === 0) return fail$1(`${name} is a non-empty string`);
|
|
1408
1570
|
return value;
|
|
1409
1571
|
}
|
|
@@ -1412,7 +1574,7 @@ function positiveInteger$1(value, name) {
|
|
|
1412
1574
|
return value;
|
|
1413
1575
|
}
|
|
1414
1576
|
function canonicalOrigin(value) {
|
|
1415
|
-
const origin = text(value, "an SSE allowed Origin");
|
|
1577
|
+
const origin = text$1(value, "an SSE allowed Origin");
|
|
1416
1578
|
let parsed;
|
|
1417
1579
|
try {
|
|
1418
1580
|
parsed = new URL(origin);
|
|
@@ -1427,7 +1589,7 @@ function canonicalSseSubscriber(value) {
|
|
|
1427
1589
|
const subscriber = record(value, "an SSE subscriber document");
|
|
1428
1590
|
if (subscriber.kind !== "sse") return fail$1("an SSE subscriber document has kind sse");
|
|
1429
1591
|
const authority = record(subscriber.authority, "an SSE subscriber authority");
|
|
1430
|
-
const host = text(authority.host, "an SSE subscriber authority host");
|
|
1592
|
+
const host = text$1(authority.host, "an SSE subscriber authority host");
|
|
1431
1593
|
if (host !== "127.0.0.1" && host !== "::1") return fail$1("an SSE subscriber authority host is literal loopback");
|
|
1432
1594
|
const origins = Array.isArray(subscriber.origins) ? subscriber.origins.map(canonicalOrigin) : fail$1("SSE allowed Origins are an array");
|
|
1433
1595
|
if (origins.length === 0 || new Set(origins).size !== origins.length || [...origins].sort().some((origin, index) => origin !== origins[index])) return fail$1("SSE allowed Origins are non-empty, sorted and duplicate-free");
|
|
@@ -1436,7 +1598,7 @@ function canonicalSseSubscriber(value) {
|
|
|
1436
1598
|
const port = positiveInteger$1(authority.port, "an SSE subscriber authority port");
|
|
1437
1599
|
if (port > 65535) return fail$1("an SSE subscriber authority port is at most 65535");
|
|
1438
1600
|
return {
|
|
1439
|
-
subscriberId: text(subscriber.subscriberId, "an SSE subscriber id"),
|
|
1601
|
+
subscriberId: text$1(subscriber.subscriberId, "an SSE subscriber id"),
|
|
1440
1602
|
version: positiveInteger$1(subscriber.version, "an SSE subscriber version"),
|
|
1441
1603
|
kind: "sse",
|
|
1442
1604
|
authority: {
|
|
@@ -1453,10 +1615,10 @@ function canonicalSseTarget(value) {
|
|
|
1453
1615
|
if (target.kind !== "sse") return fail$1("an SSE target document has kind sse");
|
|
1454
1616
|
if (target.representation !== "plain" && target.representation !== "enveloped") return fail$1("an SSE target representation is plain or enveloped");
|
|
1455
1617
|
return {
|
|
1456
|
-
targetId: text(target.targetId, "an SSE target id"),
|
|
1618
|
+
targetId: text$1(target.targetId, "an SSE target id"),
|
|
1457
1619
|
version: positiveInteger$1(target.version, "an SSE target version"),
|
|
1458
1620
|
kind: "sse",
|
|
1459
|
-
subscriberId: text(target.subscriberId, "an SSE target subscriber id"),
|
|
1621
|
+
subscriberId: text$1(target.subscriberId, "an SSE target subscriber id"),
|
|
1460
1622
|
subscriberVersion: positiveInteger$1(target.subscriberVersion, "an SSE target subscriber version"),
|
|
1461
1623
|
representation: target.representation
|
|
1462
1624
|
};
|
|
@@ -1474,7 +1636,7 @@ function sseDeliveryTarget(input) {
|
|
|
1474
1636
|
}
|
|
1475
1637
|
//#endregion
|
|
1476
1638
|
//#region src/domain/activation-documents.ts
|
|
1477
|
-
function isRecord$
|
|
1639
|
+
function isRecord$2(value) {
|
|
1478
1640
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1479
1641
|
}
|
|
1480
1642
|
function fail(message, code = "VERSION_DOCUMENT_INVALID") {
|
|
@@ -1489,7 +1651,7 @@ function positiveInteger(value, name) {
|
|
|
1489
1651
|
return value;
|
|
1490
1652
|
}
|
|
1491
1653
|
function cloneJsonRecord(value, name) {
|
|
1492
|
-
if (!isRecord$
|
|
1654
|
+
if (!isRecord$2(value)) return fail(`${name} is a JSON object`);
|
|
1493
1655
|
try {
|
|
1494
1656
|
return JSON.parse(canonicalJson(value));
|
|
1495
1657
|
} catch {
|
|
@@ -1664,7 +1826,7 @@ function canonicalEnableAll(value) {
|
|
|
1664
1826
|
};
|
|
1665
1827
|
}
|
|
1666
1828
|
/** Validates exactly one v1 activation document and normalises only D2's unordered enable-all list. */
|
|
1667
|
-
function normaliseActivationDocument(value) {
|
|
1829
|
+
function normaliseActivationDocument(value, options = {}) {
|
|
1668
1830
|
const document = cloneJsonRecord(value, "an activation document");
|
|
1669
1831
|
if (document.documentVersion !== 1) return fail("an activation document has documentVersion 1");
|
|
1670
1832
|
if (Object.hasOwn(document, "versions")) return fail("activation-document versions are derived, never supplied");
|
|
@@ -1682,19 +1844,19 @@ function normaliseActivationDocument(value) {
|
|
|
1682
1844
|
case "judge-kind": return {
|
|
1683
1845
|
documentVersion: 1,
|
|
1684
1846
|
kind: "judge-kind",
|
|
1685
|
-
enablement: canonicalJudgeKindEnablement(document.enablement)
|
|
1847
|
+
enablement: canonicalJudgeKindEnablement(document.enablement, options)
|
|
1686
1848
|
};
|
|
1687
1849
|
case "enable-all": return canonicalEnableAll(document);
|
|
1688
1850
|
default: return fail("an activation document has a known kind");
|
|
1689
1851
|
}
|
|
1690
1852
|
}
|
|
1691
1853
|
/** Core's recursively key-sorted canonical JSON for a complete v1 activation document. */
|
|
1692
|
-
function canonicalActivationDocument(document) {
|
|
1693
|
-
return canonicalJson(normaliseActivationDocument(document));
|
|
1854
|
+
function canonicalActivationDocument(document, options = {}) {
|
|
1855
|
+
return canonicalJson(normaliseActivationDocument(document, options));
|
|
1694
1856
|
}
|
|
1695
1857
|
/** The lowercase SHA-256 disclosure digest of one canonical activation document. */
|
|
1696
|
-
function activationDocumentDigest(document) {
|
|
1697
|
-
return sha256Hex(canonicalActivationDocument(document));
|
|
1858
|
+
function activationDocumentDigest(document, options = {}) {
|
|
1859
|
+
return sha256Hex(canonicalActivationDocument(document, options));
|
|
1698
1860
|
}
|
|
1699
1861
|
function compareVersions(left, right) {
|
|
1700
1862
|
return compareText(left.kind, right.kind) || compareText(left.id, right.id) || left.version - right.version;
|
|
@@ -1741,8 +1903,8 @@ function derivedVersions(document) {
|
|
|
1741
1903
|
}
|
|
1742
1904
|
}
|
|
1743
1905
|
/** Derives, rather than accepts, the exact core standing-disclosure binding for an activation intent. */
|
|
1744
|
-
function disclosureBindingFor(activationIntentId, input) {
|
|
1745
|
-
const document = normaliseActivationDocument(input);
|
|
1906
|
+
function disclosureBindingFor(activationIntentId, input, options = {}) {
|
|
1907
|
+
const document = normaliseActivationDocument(input, options);
|
|
1746
1908
|
const versions = derivedVersions(document).sort(compareVersions);
|
|
1747
1909
|
for (let index = 1; index < versions.length; index += 1) if (compareVersions(versions[index - 1], versions[index]) === 0) return fail("an activation document cannot derive duplicate disclosure versions");
|
|
1748
1910
|
return canonicalDisclosureBinding({
|
|
@@ -2131,6 +2293,93 @@ function isOwnerControlWireOperation(value) {
|
|
|
2131
2293
|
function isB3ControlWireOperation(value) {
|
|
2132
2294
|
return B3_CONTROL_WIRE_OPERATION_SET.has(value);
|
|
2133
2295
|
}
|
|
2296
|
+
Object.freeze([
|
|
2297
|
+
"addJudge",
|
|
2298
|
+
"updateJudge",
|
|
2299
|
+
"rule-create",
|
|
2300
|
+
"rule-update",
|
|
2301
|
+
"ruleTest"
|
|
2302
|
+
]);
|
|
2303
|
+
Object.freeze([
|
|
2304
|
+
"judgesList",
|
|
2305
|
+
"addJudge",
|
|
2306
|
+
"updateJudge",
|
|
2307
|
+
"rule-create",
|
|
2308
|
+
"rule-update",
|
|
2309
|
+
"approvalView"
|
|
2310
|
+
]);
|
|
2311
|
+
Object.freeze([
|
|
2312
|
+
"E2_EXTERNAL_REFERENCE_BLOCKED",
|
|
2313
|
+
"LAYA_PLATFORM_UNAVAILABLE",
|
|
2314
|
+
"LAYA_SANDBOX_UNAVAILABLE",
|
|
2315
|
+
"LAYA_MANIFEST_NOT_REVIEWED",
|
|
2316
|
+
"LAYA_TEMPLATE_BLOCKED"
|
|
2317
|
+
]);
|
|
2318
|
+
/**
|
|
2319
|
+
* The Laya limits of one rule activation preview, from the reviewed terms of this database's Laya inputs, or
|
|
2320
|
+
* undefined when the preview is not a rule naming a Laya judge. It reads only ids and reviewed texts.
|
|
2321
|
+
*/
|
|
2322
|
+
function layaJudgePreviewFor(preview, terms) {
|
|
2323
|
+
if (preview.kind !== "rule") return void 0;
|
|
2324
|
+
const judge = preview.rule.agentic?.judge;
|
|
2325
|
+
if (judge?.kind !== "laya") return void 0;
|
|
2326
|
+
return {
|
|
2327
|
+
judgeId: judge.judgeId,
|
|
2328
|
+
version: judge.version,
|
|
2329
|
+
promptTemplate: judge.promptTemplate,
|
|
2330
|
+
manifestId: judge.model,
|
|
2331
|
+
limits: {
|
|
2332
|
+
englishCpu: terms.facts.englishCpu,
|
|
2333
|
+
macosBoundary: terms.facts.macosBoundary,
|
|
2334
|
+
oneAtATime: terms.facts.oneAtATime
|
|
2335
|
+
},
|
|
2336
|
+
limitations: terms.limitations
|
|
2337
|
+
};
|
|
2338
|
+
}
|
|
2339
|
+
function isRecord$1(value) {
|
|
2340
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2341
|
+
}
|
|
2342
|
+
function closed(value, keys, name) {
|
|
2343
|
+
if (!isRecord$1(value) || keys.some((key) => !Object.hasOwn(value, key)) || Object.keys(value).some((key) => !keys.includes(key))) throw new TypeError(`${name} must be a closed object`);
|
|
2344
|
+
}
|
|
2345
|
+
function text(value, name) {
|
|
2346
|
+
if (typeof value !== "string" || value.length === 0) throw new TypeError(`${name} is a non-empty string`);
|
|
2347
|
+
}
|
|
2348
|
+
function positive(value, name) {
|
|
2349
|
+
if (!Number.isSafeInteger(value) || value < 1) throw new TypeError(`${name} is a positive integer`);
|
|
2350
|
+
}
|
|
2351
|
+
/** The runtime companion to the schema's `layaJudgePreview`. */
|
|
2352
|
+
function assertLayaJudgePreviewV3(value) {
|
|
2353
|
+
closed(value, [
|
|
2354
|
+
"judgeId",
|
|
2355
|
+
"version",
|
|
2356
|
+
"promptTemplate",
|
|
2357
|
+
"manifestId",
|
|
2358
|
+
"limits",
|
|
2359
|
+
"limitations"
|
|
2360
|
+
], "a Laya judge preview");
|
|
2361
|
+
text(value.judgeId, "a Laya judge preview id");
|
|
2362
|
+
positive(value.version, "a Laya judge preview version");
|
|
2363
|
+
if (value.promptTemplate !== "laya-noul-v1") throw new TypeError("a Laya judge preview names its template");
|
|
2364
|
+
text(value.manifestId, "a Laya judge preview manifest id");
|
|
2365
|
+
closed(value.limits, [
|
|
2366
|
+
"englishCpu",
|
|
2367
|
+
"macosBoundary",
|
|
2368
|
+
"oneAtATime"
|
|
2369
|
+
], "the Laya judge preview limits");
|
|
2370
|
+
for (const limit of Object.values(value.limits)) text(limit, "a Laya judge preview limit");
|
|
2371
|
+
closed(value.limitations, ["sandboxDeprecation", "englishAccuracy"], "the Laya judge preview limitations");
|
|
2372
|
+
for (const limitation of Object.values(value.limitations)) text(limitation, "a Laya judge preview limitation");
|
|
2373
|
+
}
|
|
2374
|
+
/** The terminal lines that follow a rule preview naming a Laya judge; every line is neutralised like the preview. */
|
|
2375
|
+
function renderLayaJudgePreviewV3(value) {
|
|
2376
|
+
assertLayaJudgePreviewV3(value);
|
|
2377
|
+
return [
|
|
2378
|
+
`Laya judge ${value.judgeId}@${value.version}: template ${value.promptTemplate}, manifest ${value.manifestId}`,
|
|
2379
|
+
`Laya limits: ${value.limits.englishCpu} ${value.limits.macosBoundary} ${value.limits.oneAtATime}`,
|
|
2380
|
+
`Laya limitations: ${value.limitations.sandboxDeprecation} ${value.limitations.englishAccuracy}`
|
|
2381
|
+
].map((line) => neutralise(line).text);
|
|
2382
|
+
}
|
|
2134
2383
|
//#endregion
|
|
2135
2384
|
//#region src/operations/b3-contract.ts
|
|
2136
2385
|
/**
|
|
@@ -2442,7 +2691,8 @@ Object.freeze({
|
|
|
2442
2691
|
});
|
|
2443
2692
|
/**
|
|
2444
2693
|
* The terminal and desktop fixture boundary. This formats only daemon-authored identifiers and a canonical, neutralised
|
|
2445
|
-
* preview representation; it never consumes a secret operation or claims the approval.
|
|
2694
|
+
* preview representation; it never consumes a secret operation or claims the approval. A B3 v3 rule preview naming a
|
|
2695
|
+
* Laya judge also carries D11's Laya limits, rendered after the preview.
|
|
2446
2696
|
*/
|
|
2447
2697
|
function renderB3ApprovalPreviewV1(value) {
|
|
2448
2698
|
if (!isRecord(value) || typeof value.kind !== "string" || !B3_APPROVAL_VIEW_VARIANTS.includes(value.kind)) throw new TypeError("an approval preview has an unknown B3 v1 variant");
|
|
@@ -2453,6 +2703,7 @@ function renderB3ApprovalPreviewV1(value) {
|
|
|
2453
2703
|
};
|
|
2454
2704
|
if (typeof value.approvalId !== "string" || typeof value.digest !== "string" || !isRecord(value.challenge) || typeof value.challenge.approvalId !== "string" || typeof value.challenge.digest !== "string" || typeof value.challenge.challenge !== "string" || typeof value.challenge.expiresAt !== "number") throw new TypeError("a ready approval preview is malformed");
|
|
2455
2705
|
normaliseActivationDocument(value.preview);
|
|
2706
|
+
const laya = Object.hasOwn(value, "layaJudge") ? renderLayaJudgePreviewV3(value.layaJudge) : [];
|
|
2456
2707
|
return {
|
|
2457
2708
|
kind: "READY",
|
|
2458
2709
|
structured: {
|
|
@@ -2464,12 +2715,14 @@ function renderB3ApprovalPreviewV1(value) {
|
|
|
2464
2715
|
digest: value.challenge.digest,
|
|
2465
2716
|
challenge: value.challenge.challenge,
|
|
2466
2717
|
expiresAt: value.challenge.expiresAt
|
|
2467
|
-
}
|
|
2718
|
+
},
|
|
2719
|
+
...Object.hasOwn(value, "layaJudge") ? { layaJudge: value.layaJudge } : {}
|
|
2468
2720
|
},
|
|
2469
2721
|
terminal: [
|
|
2470
2722
|
`Approval ${value.approvalId}`,
|
|
2471
2723
|
`Digest ${value.digest}`,
|
|
2472
2724
|
`Preview ${neutralise(canonicalJson(value.preview)).text}`,
|
|
2725
|
+
...laya,
|
|
2473
2726
|
`Challenge ${value.challenge.challenge}`,
|
|
2474
2727
|
`Expires ${new Date(value.challenge.expiresAt).toISOString()}`
|
|
2475
2728
|
].join("\n")
|
|
@@ -2483,4 +2736,4 @@ const B3_CONTROL_CONTRACT = Object.freeze({
|
|
|
2483
2736
|
judgeUnavailable: B3_JUDGE_UNAVAILABLE_VARIANTS
|
|
2484
2737
|
});
|
|
2485
2738
|
//#endregion
|
|
2486
|
-
export {
|
|
2739
|
+
export { addSubscriber as $, isControlHello as $t, normaliseSourceOptions as A, updateJudge as At, canonicalJudgeKindEnablement as B, deliveriesList as Bt, normaliseActivationDocument as C, judgeKindsList as Ct, normaliseGmailSourceOptions as D, removeJudge as Dt, classifySourceOptionChange as E, judgesList as Et, assertCreatableLayaJudge as F, doctor as Ft, registerLayaEnablementInputs as G, catalogueShow as Gt, layaEnablementInputsFor as H, heldList as Ht, assertLayaJudgeKindAvailable as I, ACTIVATION_FAILURE as It, addTarget as J, probeControl as Jt, createEventsMcpServer as K, approvalView as Kt, assertLayaRuleJudgeOffered as L, isActivationFailureCode as Lt, APPROVED_TYPESAFE_MODELS as M, assertDoctorReportV1 as Mt, JUDGE_BUDGET_ID as N, assertDoctorReportV2 as Nt, normaliseResendSourceOptions as O, removeJudgeModel as Ot, JUDGE_KIND_DEFINITIONS as P, assertDoctorReportV3 as Pt, targetTest as Q, encodeControlFrame as Qt, canonicalJudge as R, disableAll as Rt, disclosureBindingFor as S, enableJudgeKind as St, sseDeliveryTarget as T, judgeTest as Tt, layaJudgeKindDefinitionFor as U, retryDelivery as Ut, judgeKindDefinition as V, dropDelivery as Vt, layaJudgeTermsFor as W, catalogueList as Wt, targetsList as X, ControlFrameReader as Xt, removeTarget as Y, CONTROL_PROTOCOL_VERSIONS as Yt, updateTarget as Z, controlFailure as Zt, isOwnerControlWireOperation as _, pause as _t, B3_CONTROL_V1_OPERATION_SPECS as a, readInstance as an, loadSqlite as at, canonicalSubscriber as b, budgetShow as bt, B3_CONTROL_V1_SUCCESSOR_REQUIREMENT as c, assertControlSupported as cn, createRule as ct, B3_SECRET_TERMINAL_ORIGIN as d, verifyControlSocket as dn, removeRule as dt, isControlRequest as en, removeSubscriber as et, isB3ControlOperation as f, verifyPrivateSocketDirectory as fn, ruleShow as ft, OWNER_CONTROL_WIRES as g, eventPaths as gn, ruleTestRetained as gt, layaJudgePreviewFor as h, ensureOwnerOnlyFile as hn, ruleTest as ht, B3_CONTROL_ERROR_CODES as i, processIsLive as in, status as it, normaliseWhatsAppSourceOptions as j, enableAll as jt, normaliseSlackSourceOptions as k, updateBudget as kt, B3_DESKTOP_CONTROL_OPERATIONS as l, assertSocketPathFits as ln, disableRule as lt, renderB3ApprovalPreviewV1 as m, ensureEventSocketDirectory as mn, updateRule as mt, B3_CAPABILITIES as n, mayRecoverStaleInstance as nn, updateSubscriber as nt, B3_CONTROL_V1_RESULT_OPERATIONS as o, removeInstance as on, sourceShow as ot, isB3SecretOperation as p, ensureEventPaths as pn, rulesList as pt, VERSION as q, EventControlClient as qt, B3_CONTROL_CONTRACT as r, newInstanceRecord as rn, stop as rt, B3_CONTROL_V1_SCHEMA_VERSION as s, writeInstance as sn, sourcesList as st, B3_APPROVAL_VIEW_VARIANTS as t, negotiateVersion as tn, subscribersList as tt, B3_JUDGE_UNAVAILABLE_VARIANTS as u, controlEndpoint as un, enableRule as ut, activationDocumentDigest as v, resume as vt, canonicalSseSubscriber as w, judgeModelStatus as wt, canonicalTarget as x, disableJudgeKind as xt, canonicalFullRuleDocument as y, addJudge as yt, canonicalJudgeBudget as z, decideHeld as zt };
|