@agentcomms/events-daemon 0.24.0 → 0.25.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-ByO1DTgr.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,4 +1,30 @@
|
|
|
1
|
+
import { h as isLayaTemplateId } from "./worker-boundary-probe-CFN6EsyK.mjs";
|
|
1
2
|
import { canonicalJson, sha256Hex } from "@agentcomms/core";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
//#region src/domain/lifecycle.ts
|
|
5
|
+
/** A content-free domain refusal. No caller should substitute an arbitrary Error message at a control boundary. */
|
|
6
|
+
var EventDomainError = class extends Error {
|
|
7
|
+
code;
|
|
8
|
+
constructor(code, message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "EventDomainError";
|
|
11
|
+
this.code = code;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const JUDGE_KIND_TYPESAFE = "typesafe";
|
|
15
|
+
const JUDGE_KIND_LAYA = "laya";
|
|
16
|
+
const JUDGE_KIND_LOCAL_ENDPOINT = "local-endpoint";
|
|
17
|
+
const JUDGE_KINDS = [
|
|
18
|
+
JUDGE_KIND_TYPESAFE,
|
|
19
|
+
JUDGE_KIND_LAYA,
|
|
20
|
+
JUDGE_KIND_LOCAL_ENDPOINT
|
|
21
|
+
];
|
|
22
|
+
function isJudgeKind(value) {
|
|
23
|
+
return typeof value === "string" && JUDGE_KINDS.includes(value);
|
|
24
|
+
}
|
|
25
|
+
function assertJudgeKindEnabled(kind, enabled) {
|
|
26
|
+
if (!enabled) throw new EventDomainError("JUDGE_KIND_DISABLED", `the ${kind} judge kind is disabled`);
|
|
27
|
+
}
|
|
2
28
|
//#endregion
|
|
3
29
|
//#region src/network/iana-special-purpose.ts
|
|
4
30
|
/** Checked-in IANA policy; network code must never refresh or consult it at runtime. */
|
|
@@ -504,29 +530,537 @@ function validateLocalEndpoint(input, approvedAddressSet) {
|
|
|
504
530
|
};
|
|
505
531
|
}
|
|
506
532
|
//#endregion
|
|
507
|
-
//#region src/
|
|
508
|
-
|
|
509
|
-
|
|
533
|
+
//#region src/runtime/laya/contracts.ts
|
|
534
|
+
const LAYA_KIND = JUDGE_KINDS[1];
|
|
535
|
+
const PLATFORM_PREFIX = "darwin-";
|
|
536
|
+
const SANDBOX_TRIVIAL_PROGRAM = "/usr/bin/true";
|
|
537
|
+
const SANDBOX_PROBE_TIMEOUT_MS = 250;
|
|
538
|
+
const SYSCTL = "/usr/sbin/sysctl";
|
|
539
|
+
const ROSETTA_QUERY = ["-in", "sysctl.proc_translated"];
|
|
540
|
+
const LAYA_MODEL_FAILURE_CODES = [
|
|
541
|
+
"boundary-failed",
|
|
542
|
+
"download-failed",
|
|
543
|
+
"integrity",
|
|
544
|
+
"runtime-failed"
|
|
545
|
+
];
|
|
546
|
+
var LayaContractError = class extends Error {
|
|
510
547
|
code;
|
|
511
548
|
constructor(code, message) {
|
|
512
549
|
super(message);
|
|
513
|
-
this.name = "
|
|
550
|
+
this.name = "LayaContractError";
|
|
514
551
|
this.code = code;
|
|
515
552
|
}
|
|
516
553
|
};
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const JUDGE_KIND_LOCAL_ENDPOINT = "local-endpoint";
|
|
520
|
-
const JUDGE_KINDS = [
|
|
521
|
-
JUDGE_KIND_TYPESAFE,
|
|
522
|
-
JUDGE_KIND_LAYA,
|
|
523
|
-
JUDGE_KIND_LOCAL_ENDPOINT
|
|
524
|
-
];
|
|
525
|
-
function isJudgeKind(value) {
|
|
526
|
-
return typeof value === "string" && JUDGE_KINDS.includes(value);
|
|
554
|
+
function fail$1(code, message) {
|
|
555
|
+
throw new LayaContractError(code, message);
|
|
527
556
|
}
|
|
528
|
-
function
|
|
529
|
-
if (
|
|
557
|
+
function object(value, name) {
|
|
558
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return fail$1("LAYA_ASSET_INVALID", `${name} is an object`);
|
|
559
|
+
return value;
|
|
560
|
+
}
|
|
561
|
+
function exactKeys(value, keys, name) {
|
|
562
|
+
const found = Object.keys(value).sort();
|
|
563
|
+
const expected = [...keys].sort();
|
|
564
|
+
if (found.length !== expected.length || found.some((key, index) => key !== expected[index])) fail$1("LAYA_ASSET_INVALID", `${name} has exact reviewed fields`);
|
|
565
|
+
}
|
|
566
|
+
function text$1(value, name) {
|
|
567
|
+
if (typeof value !== "string" || value.length === 0) fail$1("LAYA_ASSET_INVALID", `${name} is a non-empty string`);
|
|
568
|
+
return value;
|
|
569
|
+
}
|
|
570
|
+
function positive(value, name) {
|
|
571
|
+
if (!Number.isSafeInteger(value) || value < 1) fail$1("LAYA_ASSET_INVALID", `${name} is a positive integer`);
|
|
572
|
+
return value;
|
|
573
|
+
}
|
|
574
|
+
function safePath(value, name) {
|
|
575
|
+
const path = text$1(value, name);
|
|
576
|
+
if (path.includes("\\") || path.includes("\0") || path.startsWith("/") || path.split("/").some((part) => part === "" || part === "." || part === "..")) fail$1("LAYA_ASSET_INVALID", `${name} is a safe relative path`);
|
|
577
|
+
return path;
|
|
578
|
+
}
|
|
579
|
+
function sha256(value, name) {
|
|
580
|
+
const digest = text$1(value, name);
|
|
581
|
+
if (!/^[a-f0-9]{64}$/.test(digest)) fail$1("LAYA_ASSET_INVALID", `${name} is lowercase SHA-256`);
|
|
582
|
+
return digest;
|
|
583
|
+
}
|
|
584
|
+
function ordered(values, key, name) {
|
|
585
|
+
for (let index = 1; index < values.length; index += 1) if (key(values[index - 1]) >= key(values[index])) fail$1("LAYA_ASSET_INVALID", `${name} is sorted and duplicate-free`);
|
|
586
|
+
return values;
|
|
587
|
+
}
|
|
588
|
+
function manifest(value) {
|
|
589
|
+
const candidate = object(value, "the Laya manifest");
|
|
590
|
+
exactKeys(candidate, [
|
|
591
|
+
"manifestVersion",
|
|
592
|
+
"manifestId",
|
|
593
|
+
"source",
|
|
594
|
+
"weights",
|
|
595
|
+
"files",
|
|
596
|
+
"runtime",
|
|
597
|
+
"context",
|
|
598
|
+
"promptTemplates"
|
|
599
|
+
], "the Laya manifest");
|
|
600
|
+
if (candidate.manifestVersion !== 1) fail$1("LAYA_ASSET_INVALID", "the Laya manifest has version 1");
|
|
601
|
+
const source = object(candidate.source, "the Laya source");
|
|
602
|
+
exactKeys(source, [
|
|
603
|
+
"host",
|
|
604
|
+
"repo",
|
|
605
|
+
"revision"
|
|
606
|
+
], "the Laya source");
|
|
607
|
+
if (source.host !== "huggingface.co") fail$1("LAYA_ASSET_INVALID", "the Laya source has its reviewed host");
|
|
608
|
+
const revision = text$1(source.revision, "the Laya revision");
|
|
609
|
+
if (!/^[a-f0-9]{40}$/.test(revision)) fail$1("LAYA_ASSET_INVALID", "the Laya revision is a full lowercase commit");
|
|
610
|
+
const weights = object(candidate.weights, "the Laya weights");
|
|
611
|
+
exactKeys(weights, [
|
|
612
|
+
"publisher",
|
|
613
|
+
"origin",
|
|
614
|
+
"originSha256",
|
|
615
|
+
"licence"
|
|
616
|
+
], "the Laya weights");
|
|
617
|
+
if (!Array.isArray(candidate.files) || candidate.files.length === 0) fail$1("LAYA_ASSET_INVALID", "the Laya files are non-empty");
|
|
618
|
+
const files = ordered(candidate.files.map((entry) => {
|
|
619
|
+
const file = object(entry, "a Laya manifest file");
|
|
620
|
+
exactKeys(file, [
|
|
621
|
+
"path",
|
|
622
|
+
"size",
|
|
623
|
+
"sha256"
|
|
624
|
+
], "a Laya manifest file");
|
|
625
|
+
return {
|
|
626
|
+
path: safePath(file.path, "a Laya manifest path"),
|
|
627
|
+
size: positive(file.size, "a Laya manifest size"),
|
|
628
|
+
sha256: sha256(file.sha256, "a Laya manifest SHA-256")
|
|
629
|
+
};
|
|
630
|
+
}), (file) => Buffer.from(file.path, "utf8").toString("hex"), "the Laya manifest files");
|
|
631
|
+
const runtime = object(candidate.runtime, "the Laya runtime preview");
|
|
632
|
+
const runtimeEntries = Object.entries(runtime);
|
|
633
|
+
if (runtimeEntries.length === 0 || runtimeEntries.some(([name, version]) => name.length === 0 || typeof version !== "string" || version.length === 0)) fail$1("LAYA_ASSET_INVALID", "the Laya runtime preview is reviewed");
|
|
634
|
+
const context = object(candidate.context, "the Laya context");
|
|
635
|
+
exactKeys(context, ["maxTokens", "language"], "the Laya context");
|
|
636
|
+
if (context.maxTokens !== 512 || context.language !== "en") fail$1("LAYA_ASSET_INVALID", "the Laya context is English and bounded to 512 tokens");
|
|
637
|
+
if (!Array.isArray(candidate.promptTemplates) || candidate.promptTemplates.length === 0 || !candidate.promptTemplates.every((entry) => isLayaTemplateId(entry))) fail$1("LAYA_ASSET_INVALID", "the Laya prompt templates are reviewed templates the worker implements");
|
|
638
|
+
const promptTemplates = ordered(candidate.promptTemplates.map((entry) => text$1(entry, "a Laya prompt template")), (entry) => entry, "the Laya prompt templates");
|
|
639
|
+
return {
|
|
640
|
+
manifestVersion: 1,
|
|
641
|
+
manifestId: text$1(candidate.manifestId, "the Laya manifest id"),
|
|
642
|
+
source: {
|
|
643
|
+
host: "huggingface.co",
|
|
644
|
+
repo: text$1(source.repo, "the Laya repository"),
|
|
645
|
+
revision
|
|
646
|
+
},
|
|
647
|
+
weights: {
|
|
648
|
+
publisher: text$1(weights.publisher, "the Laya weights publisher"),
|
|
649
|
+
origin: text$1(weights.origin, "the Laya weights origin"),
|
|
650
|
+
originSha256: sha256(weights.originSha256, "the Laya weights origin SHA-256"),
|
|
651
|
+
licence: text$1(weights.licence, "the Laya weights licence")
|
|
652
|
+
},
|
|
653
|
+
files,
|
|
654
|
+
runtime: Object.fromEntries(runtimeEntries.map(([name, version]) => [name, version])),
|
|
655
|
+
context: {
|
|
656
|
+
maxTokens: 512,
|
|
657
|
+
language: "en"
|
|
658
|
+
},
|
|
659
|
+
promptTemplates
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
function runtimeLock(value) {
|
|
663
|
+
const candidate = object(value, "the Laya runtime lock");
|
|
664
|
+
if (candidate.schemaVersion === 1 && candidate.blocked === "E2_EXTERNAL_REFERENCE_BLOCKED") {
|
|
665
|
+
exactKeys(candidate, ["schemaVersion", "blocked"], "the blocked Laya runtime lock");
|
|
666
|
+
return { blocked: "E2_EXTERNAL_REFERENCE_BLOCKED" };
|
|
667
|
+
}
|
|
668
|
+
exactKeys(candidate, ["schemaVersion", "packages"], "the Laya runtime lock");
|
|
669
|
+
if (candidate.schemaVersion !== 1 || !Array.isArray(candidate.packages) || candidate.packages.length === 0) fail$1("LAYA_ASSET_INVALID", "the Laya runtime lock is complete");
|
|
670
|
+
return {
|
|
671
|
+
schemaVersion: 1,
|
|
672
|
+
packages: ordered(candidate.packages.map((entry) => {
|
|
673
|
+
const pkg = object(entry, "a Laya runtime package");
|
|
674
|
+
exactKeys(pkg, [
|
|
675
|
+
"name",
|
|
676
|
+
"version",
|
|
677
|
+
"url",
|
|
678
|
+
"integrity",
|
|
679
|
+
"files"
|
|
680
|
+
], "a Laya runtime package");
|
|
681
|
+
const filesByPlatform = object(pkg.files, "a Laya runtime package file list");
|
|
682
|
+
const files = Object.fromEntries(Object.entries(filesByPlatform).map(([platform, entries]) => {
|
|
683
|
+
if (!platform.startsWith(PLATFORM_PREFIX) || !Array.isArray(entries)) fail$1("LAYA_ASSET_INVALID", "a Laya runtime package has macOS file lists");
|
|
684
|
+
return [platform, ordered(entries.map((file) => {
|
|
685
|
+
const parsed = object(file, "a Laya runtime file");
|
|
686
|
+
exactKeys(parsed, [
|
|
687
|
+
"path",
|
|
688
|
+
"size",
|
|
689
|
+
"sha256",
|
|
690
|
+
"executable"
|
|
691
|
+
], "a Laya runtime file");
|
|
692
|
+
if (typeof parsed.executable !== "boolean") fail$1("LAYA_ASSET_INVALID", "a Laya runtime executable bit is boolean");
|
|
693
|
+
return {
|
|
694
|
+
path: safePath(parsed.path, "a Laya runtime path"),
|
|
695
|
+
size: positive(parsed.size, "a Laya runtime size"),
|
|
696
|
+
sha256: sha256(parsed.sha256, "a Laya runtime SHA-256"),
|
|
697
|
+
executable: parsed.executable
|
|
698
|
+
};
|
|
699
|
+
}), (file) => Buffer.from(file.path, "utf8").toString("hex"), "a Laya runtime package file list")];
|
|
700
|
+
}));
|
|
701
|
+
const url = text$1(pkg.url, "a Laya runtime URL");
|
|
702
|
+
if (!url.startsWith("https://registry.npmjs.org/") || /[?#]/.test(url)) fail$1("LAYA_ASSET_INVALID", "a Laya runtime URL is its reviewed registry URL");
|
|
703
|
+
const integrity = text$1(pkg.integrity, "a Laya runtime SRI");
|
|
704
|
+
if (!/^sha512-[A-Za-z0-9+/]+={0,2}$/.test(integrity)) fail$1("LAYA_ASSET_INVALID", "a Laya runtime SRI is exact SHA-512");
|
|
705
|
+
return {
|
|
706
|
+
name: text$1(pkg.name, "a Laya runtime package name"),
|
|
707
|
+
version: text$1(pkg.version, "a Laya runtime package version"),
|
|
708
|
+
url,
|
|
709
|
+
integrity,
|
|
710
|
+
files
|
|
711
|
+
};
|
|
712
|
+
}), (pkg) => pkg.name, "the Laya runtime packages")
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
function rawByteCompare(left, right) {
|
|
716
|
+
return Buffer.compare(Buffer.from(left, "utf8"), Buffer.from(right, "utf8"));
|
|
717
|
+
}
|
|
718
|
+
function sourceText(bytes, name) {
|
|
719
|
+
const source = Buffer.from(bytes).toString("utf8");
|
|
720
|
+
if (!Buffer.from(source, "utf8").equals(Buffer.from(bytes))) fail$1("LAYA_ASSET_INVALID", `${name} is strict UTF-8`);
|
|
721
|
+
return source;
|
|
722
|
+
}
|
|
723
|
+
function jsonSource(bytes, name) {
|
|
724
|
+
const source = sourceText(bytes, name);
|
|
725
|
+
try {
|
|
726
|
+
return JSON.parse(source);
|
|
727
|
+
} catch {
|
|
728
|
+
return fail$1("LAYA_ASSET_INVALID", `${name} is strict JSON`);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
function canonicalManifestSource(value) {
|
|
732
|
+
const runtime = {
|
|
733
|
+
"@receptron/laya": value.runtime["@receptron/laya"],
|
|
734
|
+
"onnxruntime-node": value.runtime["onnxruntime-node"],
|
|
735
|
+
"@huggingface/tokenizers": value.runtime["@huggingface/tokenizers"]
|
|
736
|
+
};
|
|
737
|
+
const source = `${JSON.stringify({
|
|
738
|
+
manifestVersion: value.manifestVersion,
|
|
739
|
+
manifestId: value.manifestId,
|
|
740
|
+
source: value.source,
|
|
741
|
+
weights: value.weights,
|
|
742
|
+
files: value.files,
|
|
743
|
+
runtime,
|
|
744
|
+
context: value.context,
|
|
745
|
+
promptTemplates: value.promptTemplates
|
|
746
|
+
}, null, 2)}\n`;
|
|
747
|
+
const multilineTemplates = ` "promptTemplates": [\n${value.promptTemplates.map((id) => ` ${JSON.stringify(id)}`).join(",\n")}\n ]`;
|
|
748
|
+
return source.replace(multilineTemplates, ` "promptTemplates": [${value.promptTemplates.map((id) => JSON.stringify(id)).join(", ")}]`);
|
|
749
|
+
}
|
|
750
|
+
function canonicalRuntimeLockSource(value) {
|
|
751
|
+
if ("blocked" in value) return `${JSON.stringify({
|
|
752
|
+
schemaVersion: 1,
|
|
753
|
+
blocked: value.blocked
|
|
754
|
+
}, null, 2)}\n`;
|
|
755
|
+
return `${JSON.stringify({
|
|
756
|
+
schemaVersion: 1,
|
|
757
|
+
packages: value.packages.map((pkg) => ({
|
|
758
|
+
name: pkg.name,
|
|
759
|
+
version: pkg.version,
|
|
760
|
+
url: pkg.url,
|
|
761
|
+
integrity: pkg.integrity,
|
|
762
|
+
files: Object.fromEntries(Object.entries(pkg.files).sort(([left], [right]) => rawByteCompare(left, right)).map(([platform, files]) => [platform, files]))
|
|
763
|
+
}))
|
|
764
|
+
}, null, 2)}\n`;
|
|
765
|
+
}
|
|
766
|
+
const REQUIRED_PREVIEW_LIMITATIONS = ["sandboxDeprecation", "englishAccuracy"];
|
|
767
|
+
function disclosureText(value) {
|
|
768
|
+
const candidate = object(value, "the Laya enablement disclosures");
|
|
769
|
+
exactKeys(candidate, [
|
|
770
|
+
"schemaVersion",
|
|
771
|
+
"runtimeLicences",
|
|
772
|
+
"workerMemory",
|
|
773
|
+
"facts",
|
|
774
|
+
"limitations"
|
|
775
|
+
], "the Laya enablement disclosures");
|
|
776
|
+
if (candidate.schemaVersion !== 1) fail$1("LAYA_ASSET_INVALID", "the Laya enablement disclosures have version 1");
|
|
777
|
+
if (!Array.isArray(candidate.runtimeLicences) || candidate.runtimeLicences.length === 0) fail$1("LAYA_ASSET_INVALID", "the Laya runtime licences are reviewed");
|
|
778
|
+
const runtimeLicences = candidate.runtimeLicences.map((licence) => text$1(licence, "a Laya runtime licence"));
|
|
779
|
+
if (runtimeLicences.some((licence, index) => index > 0 && runtimeLicences[index - 1] >= licence)) fail$1("LAYA_ASSET_INVALID", "the Laya runtime licences are sorted and duplicate-free");
|
|
780
|
+
const facts = object(candidate.facts, "the Laya disclosure facts");
|
|
781
|
+
exactKeys(facts, [
|
|
782
|
+
"englishCpu",
|
|
783
|
+
"macosBoundary",
|
|
784
|
+
"linuxUnavailable",
|
|
785
|
+
"windowsUnavailable",
|
|
786
|
+
"downloadAfterApproval",
|
|
787
|
+
"oneAtATime"
|
|
788
|
+
], "the Laya disclosure facts");
|
|
789
|
+
const limitations = object(candidate.limitations, "the Laya disclosure limitations");
|
|
790
|
+
const reviewed = { limitations: Object.keys(limitations) };
|
|
791
|
+
if (!REQUIRED_PREVIEW_LIMITATIONS.every((fact) => reviewed.limitations.includes(fact))) fail$1("LAYA_ASSET_INVALID", "the Laya disclosure limitations are complete");
|
|
792
|
+
if (reviewed.limitations.length > REQUIRED_PREVIEW_LIMITATIONS.length) fail$1("LAYA_ASSET_INVALID", "the Laya disclosure limitations have no unreviewed fields");
|
|
793
|
+
for (const [name, disclosure] of Object.entries(limitations)) text$1(disclosure, `the ${name} Laya limitation`);
|
|
794
|
+
return {
|
|
795
|
+
runtimeLicences,
|
|
796
|
+
workerMemory: text$1(candidate.workerMemory, "the Laya worker memory disclosure"),
|
|
797
|
+
facts: {
|
|
798
|
+
englishCpu: text$1(facts.englishCpu, "the English Laya disclosure"),
|
|
799
|
+
macosBoundary: text$1(facts.macosBoundary, "the macOS Laya disclosure"),
|
|
800
|
+
linuxUnavailable: text$1(facts.linuxUnavailable, "the Linux Laya disclosure"),
|
|
801
|
+
windowsUnavailable: text$1(facts.windowsUnavailable, "the Windows Laya disclosure"),
|
|
802
|
+
downloadAfterApproval: text$1(facts.downloadAfterApproval, "the Laya download disclosure"),
|
|
803
|
+
oneAtATime: text$1(facts.oneAtATime, "the Laya concurrency disclosure")
|
|
804
|
+
},
|
|
805
|
+
limitations
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
function canonicalDisclosureSource(value) {
|
|
809
|
+
const source = `${JSON.stringify({
|
|
810
|
+
schemaVersion: 1,
|
|
811
|
+
runtimeLicences: value.runtimeLicences,
|
|
812
|
+
workerMemory: value.workerMemory,
|
|
813
|
+
facts: value.facts,
|
|
814
|
+
limitations: value.limitations
|
|
815
|
+
}, null, 2)}\n`;
|
|
816
|
+
const multilineRuntimeLicences = `${JSON.stringify(value.runtimeLicences, null, 2).split("\n").map((line, index) => index === 0 ? ` "runtimeLicences": ${line}` : ` ${line}`).join("\n")},`;
|
|
817
|
+
return source.replace(multilineRuntimeLicences, ` "runtimeLicences": ${JSON.stringify(value.runtimeLicences)},`);
|
|
818
|
+
}
|
|
819
|
+
function parseReviewedAssets(source) {
|
|
820
|
+
const manifestSource = sourceText(source.manifestBytes, "the Laya manifest");
|
|
821
|
+
const parsedManifest = manifest(jsonSource(source.manifestBytes, "the Laya manifest"));
|
|
822
|
+
if (canonicalManifestSource(parsedManifest) !== manifestSource) fail$1("LAYA_ASSET_INVALID", "the Laya manifest bytes are canonical");
|
|
823
|
+
const runtimeSource = sourceText(source.runtimeLockBytes, "the Laya runtime lock");
|
|
824
|
+
const parsedRuntimeLock = runtimeLock(jsonSource(source.runtimeLockBytes, "the Laya runtime lock"));
|
|
825
|
+
if (canonicalRuntimeLockSource(parsedRuntimeLock) !== runtimeSource) fail$1("LAYA_ASSET_INVALID", "the Laya runtime lock bytes are canonical");
|
|
826
|
+
const disclosuresSource = sourceText(source.disclosuresBytes, "the Laya enablement disclosures");
|
|
827
|
+
const disclosures = disclosureText(jsonSource(source.disclosuresBytes, "the Laya enablement disclosures"));
|
|
828
|
+
if (canonicalDisclosureSource(disclosures) !== disclosuresSource) fail$1("LAYA_ASSET_INVALID", "the Laya enablement disclosure bytes are canonical");
|
|
829
|
+
return {
|
|
830
|
+
manifest: parsedManifest,
|
|
831
|
+
runtimeLock: parsedRuntimeLock,
|
|
832
|
+
disclosures
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
function selectedPlatform(lock, probe) {
|
|
836
|
+
const id = `${PLATFORM_PREFIX}${probe.architecture}`;
|
|
837
|
+
const files = lock.packages.flatMap((pkg) => (pkg.files[id] ?? []).map((file) => ({
|
|
838
|
+
package: pkg.name,
|
|
839
|
+
...file
|
|
840
|
+
})));
|
|
841
|
+
if (files.length === 0) fail$1("LAYA_ASSET_INVALID", "the reviewed runtime lock has this macOS architecture");
|
|
842
|
+
return {
|
|
843
|
+
id,
|
|
844
|
+
files,
|
|
845
|
+
digest: sha256Hex(canonicalJson(files))
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
function completeRuntimeLock(lock, probe) {
|
|
849
|
+
const platform = selectedPlatform(lock, probe);
|
|
850
|
+
const packages = lock.packages.map(({ name, version, url, integrity }) => ({
|
|
851
|
+
name,
|
|
852
|
+
version,
|
|
853
|
+
url,
|
|
854
|
+
integrity
|
|
855
|
+
}));
|
|
856
|
+
return {
|
|
857
|
+
schemaVersion: 1,
|
|
858
|
+
packages,
|
|
859
|
+
platform,
|
|
860
|
+
digest: sha256Hex(canonicalJson({
|
|
861
|
+
schemaVersion: 1,
|
|
862
|
+
packages,
|
|
863
|
+
platform
|
|
864
|
+
}))
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* E2 review round 1 (A5): whether this process runs under Rosetta. `sysctl.proc_translated` is 1 there (a translated
|
|
869
|
+
* process's children run translated, `sysctl` among them), 0 natively, and absent on an Intel Mac whose macOS predates
|
|
870
|
+
* it, which `-i` prints as nothing. Anything but a clean 0 or nothing counts as translated: no evidence covers a
|
|
871
|
+
* translated worker, so Rosetta is never offered the Intel lock.
|
|
872
|
+
*/
|
|
873
|
+
function translatedByRosetta(probe) {
|
|
874
|
+
if (probe.platform !== "darwin") return false;
|
|
875
|
+
const options = {
|
|
876
|
+
cwd: "/",
|
|
877
|
+
env: { PATH: "/usr/bin:/bin" },
|
|
878
|
+
shell: false,
|
|
879
|
+
stdio: [
|
|
880
|
+
"ignore",
|
|
881
|
+
"pipe",
|
|
882
|
+
"ignore"
|
|
883
|
+
],
|
|
884
|
+
encoding: "utf8",
|
|
885
|
+
timeout: SANDBOX_PROBE_TIMEOUT_MS,
|
|
886
|
+
killSignal: "SIGKILL"
|
|
887
|
+
};
|
|
888
|
+
try {
|
|
889
|
+
const result = probe.spawnSync?.(SYSCTL, ROSETTA_QUERY, options) ?? spawnSync(SYSCTL, ROSETTA_QUERY, {
|
|
890
|
+
...options,
|
|
891
|
+
stdio: [...options.stdio]
|
|
892
|
+
});
|
|
893
|
+
if (result.status !== 0 || result.signal !== null || result.error !== void 0) return true;
|
|
894
|
+
const answer = String(result.stdout ?? "").trim();
|
|
895
|
+
return answer !== "0" && answer !== "";
|
|
896
|
+
} catch {
|
|
897
|
+
return true;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
/** The Task 1 availability probe is separate from Task 7's per-child proof and intentionally content-free. */
|
|
901
|
+
function sandboxExecAvailable(probe) {
|
|
902
|
+
if (probe.platform !== "darwin") return false;
|
|
903
|
+
const options = {
|
|
904
|
+
cwd: "/",
|
|
905
|
+
env: { PATH: "/usr/bin:/bin" },
|
|
906
|
+
shell: false,
|
|
907
|
+
stdio: "ignore",
|
|
908
|
+
timeout: SANDBOX_PROBE_TIMEOUT_MS,
|
|
909
|
+
killSignal: "SIGKILL"
|
|
910
|
+
};
|
|
911
|
+
try {
|
|
912
|
+
const result = probe.spawnSync?.("/usr/bin/sandbox-exec", [
|
|
913
|
+
"-p",
|
|
914
|
+
"(version 1) (allow default) (deny network*)",
|
|
915
|
+
SANDBOX_TRIVIAL_PROGRAM
|
|
916
|
+
], options) ?? spawnSync("/usr/bin/sandbox-exec", [
|
|
917
|
+
"-p",
|
|
918
|
+
"(version 1) (allow default) (deny network*)",
|
|
919
|
+
SANDBOX_TRIVIAL_PROGRAM
|
|
920
|
+
], options);
|
|
921
|
+
return result.status === 0 && result.signal === null && result.error === void 0;
|
|
922
|
+
} catch {
|
|
923
|
+
return false;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
function available(assets, probe) {
|
|
927
|
+
const lock = assets.runtimeLock;
|
|
928
|
+
if ("blocked" in lock) return {
|
|
929
|
+
available: false,
|
|
930
|
+
code: lock.blocked
|
|
931
|
+
};
|
|
932
|
+
if (probe.platform !== "darwin") return {
|
|
933
|
+
available: false,
|
|
934
|
+
code: "LAYA_PLATFORM_UNAVAILABLE"
|
|
935
|
+
};
|
|
936
|
+
if (translatedByRosetta(probe)) return {
|
|
937
|
+
available: false,
|
|
938
|
+
code: "LAYA_PLATFORM_UNAVAILABLE"
|
|
939
|
+
};
|
|
940
|
+
if (!sandboxExecAvailable(probe)) return {
|
|
941
|
+
available: false,
|
|
942
|
+
code: "LAYA_SANDBOX_UNAVAILABLE"
|
|
943
|
+
};
|
|
944
|
+
try {
|
|
945
|
+
selectedPlatform(lock, probe);
|
|
946
|
+
} catch {
|
|
947
|
+
return {
|
|
948
|
+
available: false,
|
|
949
|
+
code: "LAYA_PLATFORM_UNAVAILABLE"
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
return { available: true };
|
|
953
|
+
}
|
|
954
|
+
function assertAvailable(assets, probe) {
|
|
955
|
+
const state = available(assets, probe);
|
|
956
|
+
if (!state.available) fail$1(state.code, "the reviewed Laya runtime is unavailable before enablement preparation");
|
|
957
|
+
const lock = assets.runtimeLock;
|
|
958
|
+
if ("blocked" in lock) fail$1(lock.blocked, "the reviewed Laya runtime lock is blocked");
|
|
959
|
+
return lock;
|
|
960
|
+
}
|
|
961
|
+
function disclosures(reviewedDisclosure, runtime, parsedManifest) {
|
|
962
|
+
const modelBytes = parsedManifest.files.reduce((sum, file) => sum + file.size, 0);
|
|
963
|
+
const runtimeBytes = runtime.platform.files.reduce((sum, file) => sum + file.size, 0);
|
|
964
|
+
const facts = [...{ facts: [
|
|
965
|
+
reviewedDisclosure.facts.englishCpu,
|
|
966
|
+
reviewedDisclosure.facts.macosBoundary,
|
|
967
|
+
reviewedDisclosure.facts.linuxUnavailable,
|
|
968
|
+
reviewedDisclosure.facts.windowsUnavailable,
|
|
969
|
+
reviewedDisclosure.facts.downloadAfterApproval,
|
|
970
|
+
reviewedDisclosure.facts.oneAtATime
|
|
971
|
+
] }.facts];
|
|
972
|
+
return {
|
|
973
|
+
modelBytes,
|
|
974
|
+
runtimeBytes,
|
|
975
|
+
runtimeLicences: reviewedDisclosure.runtimeLicences,
|
|
976
|
+
workerMemory: reviewedDisclosure.workerMemory,
|
|
977
|
+
facts: {
|
|
978
|
+
englishCpu: facts[0],
|
|
979
|
+
macosBoundary: facts[1],
|
|
980
|
+
linuxUnavailable: facts[2],
|
|
981
|
+
windowsUnavailable: facts[3],
|
|
982
|
+
downloadAfterApproval: facts[4],
|
|
983
|
+
oneAtATime: facts[5]
|
|
984
|
+
},
|
|
985
|
+
limitations: reviewedDisclosure.limitations
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* The concrete E2 replacement for Phase E's opaque slot. Tests may inject only canonical synthetic asset bytes and
|
|
990
|
+
* the sandbox spawn; production supplies the shipped bytes and never accepts a caller path, manifest, lock, template
|
|
991
|
+
* or prebuilt definition.
|
|
992
|
+
*/
|
|
993
|
+
function createLayaJudgeKindDefinition(input) {
|
|
994
|
+
const assets = parseReviewedAssets(input.assets);
|
|
995
|
+
const parsedManifest = assets.manifest;
|
|
996
|
+
const status = () => available(assets, input.platform);
|
|
997
|
+
const modelBytes = parsedManifest.files.reduce((sum, file) => sum + file.size, 0);
|
|
998
|
+
const unavailableStatus = () => {
|
|
999
|
+
const availability = status();
|
|
1000
|
+
return {
|
|
1001
|
+
state: "unavailable",
|
|
1002
|
+
manifestId: parsedManifest.manifestId,
|
|
1003
|
+
runtimeLockDigest: null,
|
|
1004
|
+
bytesVerified: 0,
|
|
1005
|
+
totalBytes: modelBytes,
|
|
1006
|
+
failureCode: null,
|
|
1007
|
+
reason: availability.available ? "E2_EXTERNAL_REFERENCE_BLOCKED" : availability.code,
|
|
1008
|
+
updatedAt: null
|
|
1009
|
+
};
|
|
1010
|
+
};
|
|
1011
|
+
const preview = ({ version }) => {
|
|
1012
|
+
if (!Number.isSafeInteger(version) || version < 1) fail$1("LAYA_ENABLEMENT_EXACT", "a Laya enablement version is positive");
|
|
1013
|
+
const lock = assets.runtimeLock;
|
|
1014
|
+
if ("blocked" in lock) fail$1(lock.blocked, "the reviewed Laya runtime lock is blocked");
|
|
1015
|
+
const complete = completeRuntimeLock(lock, input.platform);
|
|
1016
|
+
return {
|
|
1017
|
+
id: `judge-kind:${LAYA_KIND}`,
|
|
1018
|
+
kind: LAYA_KIND,
|
|
1019
|
+
version,
|
|
1020
|
+
manifest: parsedManifest,
|
|
1021
|
+
runtimeLock: complete,
|
|
1022
|
+
disclosures: disclosures(assets.disclosures, complete, parsedManifest)
|
|
1023
|
+
};
|
|
1024
|
+
};
|
|
1025
|
+
const prepareEnablement = ({ version }) => {
|
|
1026
|
+
assertAvailable(assets, input.platform);
|
|
1027
|
+
return preview({ version });
|
|
1028
|
+
};
|
|
1029
|
+
return {
|
|
1030
|
+
kind: LAYA_KIND,
|
|
1031
|
+
availability: status,
|
|
1032
|
+
judgeTerms: () => ({
|
|
1033
|
+
manifestId: parsedManifest.manifestId,
|
|
1034
|
+
promptTemplates: parsedManifest.promptTemplates,
|
|
1035
|
+
facts: assets.disclosures.facts,
|
|
1036
|
+
limitations: assets.disclosures.limitations
|
|
1037
|
+
}),
|
|
1038
|
+
prepareEnablement,
|
|
1039
|
+
canonicalEnablement(value) {
|
|
1040
|
+
const candidate = object(value, "the Laya enablement");
|
|
1041
|
+
const { manifestPath, modelPath, template, ...reviewed } = candidate;
|
|
1042
|
+
if (manifestPath !== void 0 || modelPath !== void 0 || template !== void 0) fail$1("LAYA_ENABLEMENT_EXACT", "a Laya enablement cannot select a manifest, path or template");
|
|
1043
|
+
const version = positive(candidate.version, "the Laya enablement version");
|
|
1044
|
+
const expected = preview({ version });
|
|
1045
|
+
if (canonicalJson(reviewed) !== canonicalJson(expected)) fail$1("LAYA_ENABLEMENT_EXACT", "a Laya enablement must embed exactly the reviewed assets and disclosures");
|
|
1046
|
+
return expected;
|
|
1047
|
+
},
|
|
1048
|
+
preview,
|
|
1049
|
+
async onEnabled(_enablement, _activation) {
|
|
1050
|
+
return unavailableStatus();
|
|
1051
|
+
},
|
|
1052
|
+
async execute(_request, _reservation) {
|
|
1053
|
+
return fail$1("E2_EXTERNAL_REFERENCE_BLOCKED", "the Laya worker adapter is not installed");
|
|
1054
|
+
},
|
|
1055
|
+
async onWorkPurged(_scope) {},
|
|
1056
|
+
async onDisabled() {},
|
|
1057
|
+
status() {
|
|
1058
|
+
return unavailableStatus();
|
|
1059
|
+
},
|
|
1060
|
+
async removeWhenDisabled() {
|
|
1061
|
+
return unavailableStatus();
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
530
1064
|
}
|
|
531
1065
|
//#endregion
|
|
532
1066
|
//#region src/domain/webhook-target.ts
|
|
@@ -670,4 +1204,4 @@ function webhookDeliveryTarget(document) {
|
|
|
670
1204
|
};
|
|
671
1205
|
}
|
|
672
1206
|
//#endregion
|
|
673
|
-
export {
|
|
1207
|
+
export { JUDGE_KIND_TYPESAFE as _, LAYA_MODEL_FAILURE_CODES as a, validateLocalEndpoint as c, assertApprovedAddressSet as d, parseIpLiteral as f, JUDGE_KIND_LOCAL_ENDPOINT as g, JUDGE_KIND_LAYA as h, webhookDeliveryTarget as i, AddressPolicyError as l, JUDGE_KINDS as m, canonicalWebhookTarget as n, LayaContractError as o, EventDomainError as p, secretWebhookUrlDescriptor as r, createLayaJudgeKindDefinition as s, canonicalSecretWebhookUrl as t, assertAddressAllowed as u, assertJudgeKindEnabled as v, isJudgeKind as y };
|