@dsmm/dsmm 0.3.28 → 0.3.30
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/agent-presets/dsmm-orchestrator/agent.cordis.yml +1 -1
- package/agent-presets/dsmm-planner/agent.cordis.yml +1 -1
- package/docs/agent-presets.md +2 -2
- package/docs/agent-teams.md +2 -0
- package/docs/compatibility.md +3 -1
- package/docs/maintenance.md +14 -8
- package/docs/model-routing.md +9 -3
- package/docs/testing.md +2 -0
- package/docs/web-fetch-fakeip.md +2 -2
- package/dsh-plugin.json +1 -1
- package/lib/client/children-locales.d.ts +4 -4
- package/lib/client/role-call-observations.js +2 -2
- package/lib/client.js +414 -1288
- package/lib/mode.js +27 -18
- package/lib/model-family.d.ts +5 -3
- package/lib/model-family.js +30 -15
- package/lib/native-subagents.d.ts +8 -1
- package/lib/native-subagents.js +25 -2
- package/lib/permission-schema.d.ts +40 -0
- package/lib/permission-schema.js +13 -0
- package/lib/permission-settings.d.ts +0 -38
- package/lib/permission-settings.js +23 -18
- package/lib/profile-diagnostics.js +1 -11
- package/lib/prompts.js +38 -8
- package/lib/role-subagents.js +10 -7
- package/lib/settings.js +2 -1
- package/lib/skills.js +6 -6
- package/package.json +6 -51
- package/prompts/deepwork.md +4 -4
- package/prompts/source/agents/orchestrator.md +1 -1
- package/prompts/source/agents/planner.md +1 -1
- package/prompts/source/deepwork/claude-fable-5-2.md +3 -0
- package/prompts/source/deepwork/default.md +3 -3
- package/prompts/source/deepwork/gemini.md +1 -1
- package/prompts/source/deepwork/general.md +2 -2
- package/prompts/source/deepwork/glm.md +2 -2
- package/prompts/source/deepwork/gpt.md +1 -1
- package/prompts/source/deepwork/planner.md +1 -1
- package/skills/ast-grep/README.md +3 -3
- package/skills/ast-grep/SKILL.md +9 -6
- package/skills/brainstorming/SKILL.md +1 -1
- package/skills/coding-agent-sessions/SKILL.md +2 -1
- package/skills/dispatching-parallel-agents/SKILL.md +1 -1
- package/skills/frontend/references/perfection/react-perf-tooling.md +24 -26
- package/skills/receiving-code-review/SKILL.md +1 -1
- package/skills/requesting-code-review/SKILL.md +1 -1
- package/skills/subagent-driven-development/SKILL.md +1 -1
- package/skills/writing-plans/SKILL.md +1 -1
package/lib/client.js
CHANGED
|
@@ -8,11 +8,11 @@ var __export = (target, all) => {
|
|
|
8
8
|
for (var name2 in all)
|
|
9
9
|
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
10
10
|
};
|
|
11
|
-
var __copyProps = (to,
|
|
12
|
-
if (
|
|
13
|
-
for (let key of __getOwnPropNames(
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
14
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () =>
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
@@ -1629,1041 +1629,6 @@ function applyEdits(text5, edits) {
|
|
|
1629
1629
|
return text5;
|
|
1630
1630
|
}
|
|
1631
1631
|
|
|
1632
|
-
// node_modules/.pnpm/@deepseek-ai+cosmokit@1.8.6/node_modules/@deepseek-ai/cosmokit/lib/index.js
|
|
1633
|
-
function isNullable(value) {
|
|
1634
|
-
return value === null || value === void 0;
|
|
1635
|
-
}
|
|
1636
|
-
function isPlainObject(data) {
|
|
1637
|
-
return data && typeof data === "object" && !Array.isArray(data);
|
|
1638
|
-
}
|
|
1639
|
-
function filterKeys(object3, filter) {
|
|
1640
|
-
return Object.fromEntries(Object.entries(object3).filter(([key, value]) => filter(key, value)));
|
|
1641
|
-
}
|
|
1642
|
-
function mapValues(object3, transform) {
|
|
1643
|
-
return Object.fromEntries(Object.entries(object3).map(([key, value]) => [key, transform(value, key)]));
|
|
1644
|
-
}
|
|
1645
|
-
function pick(source, keys, forced) {
|
|
1646
|
-
if (!keys) return { ...source };
|
|
1647
|
-
const result = {};
|
|
1648
|
-
for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
|
|
1649
|
-
return result;
|
|
1650
|
-
}
|
|
1651
|
-
var write = Symbol.for("cosmokit.volatile.write");
|
|
1652
|
-
function snapshot(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
1653
|
-
if (typeof value === "function") throw new TypeError("volatile config cannot contain functions");
|
|
1654
|
-
if (value === null || typeof value !== "object") return value;
|
|
1655
|
-
if (ancestors.has(value)) throw new TypeError("volatile config cannot contain cycles");
|
|
1656
|
-
ancestors.add(value);
|
|
1657
|
-
try {
|
|
1658
|
-
if (Array.isArray(value)) return Object.freeze(value.map((item) => snapshot(item, ancestors)));
|
|
1659
|
-
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new TypeError("volatile config objects must be plain objects or arrays");
|
|
1660
|
-
return Object.freeze(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, snapshot(item, ancestors)])));
|
|
1661
|
-
} finally {
|
|
1662
|
-
ancestors.delete(value);
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
function createVolatile(value) {
|
|
1666
|
-
let current = snapshot(value);
|
|
1667
|
-
return Object.freeze({
|
|
1668
|
-
get: () => current,
|
|
1669
|
-
[write]: (value2) => {
|
|
1670
|
-
current = value2;
|
|
1671
|
-
}
|
|
1672
|
-
});
|
|
1673
|
-
}
|
|
1674
|
-
function isVolatile(value) {
|
|
1675
|
-
return typeof value === "object" && value !== null && write in value;
|
|
1676
|
-
}
|
|
1677
|
-
function is(type, value) {
|
|
1678
|
-
if (arguments.length === 1) return (value2) => is(type, value2);
|
|
1679
|
-
return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
|
|
1680
|
-
}
|
|
1681
|
-
function isArrayBufferLike(value) {
|
|
1682
|
-
return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
|
|
1683
|
-
}
|
|
1684
|
-
function isArrayBufferSource(value) {
|
|
1685
|
-
return isArrayBufferLike(value) || ArrayBuffer.isView(value);
|
|
1686
|
-
}
|
|
1687
|
-
var Binary;
|
|
1688
|
-
(function(Binary2) {
|
|
1689
|
-
Binary2.is = isArrayBufferLike;
|
|
1690
|
-
Binary2.isSource = isArrayBufferSource;
|
|
1691
|
-
function fromSource(source) {
|
|
1692
|
-
if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
|
|
1693
|
-
else return source;
|
|
1694
|
-
}
|
|
1695
|
-
Binary2.fromSource = fromSource;
|
|
1696
|
-
function toBase64(source) {
|
|
1697
|
-
source = fromSource(source);
|
|
1698
|
-
if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
|
|
1699
|
-
let binary = "";
|
|
1700
|
-
const bytes = new Uint8Array(source);
|
|
1701
|
-
for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
|
|
1702
|
-
return btoa(binary);
|
|
1703
|
-
}
|
|
1704
|
-
Binary2.toBase64 = toBase64;
|
|
1705
|
-
function fromBase64(source) {
|
|
1706
|
-
if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
|
|
1707
|
-
return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
|
|
1708
|
-
}
|
|
1709
|
-
Binary2.fromBase64 = fromBase64;
|
|
1710
|
-
function toHex(source) {
|
|
1711
|
-
source = fromSource(source);
|
|
1712
|
-
if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
|
|
1713
|
-
return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1714
|
-
}
|
|
1715
|
-
Binary2.toHex = toHex;
|
|
1716
|
-
function fromHex(source) {
|
|
1717
|
-
if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
|
|
1718
|
-
const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
|
|
1719
|
-
const buffer = [];
|
|
1720
|
-
for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
|
|
1721
|
-
return Uint8Array.from(buffer).buffer;
|
|
1722
|
-
}
|
|
1723
|
-
Binary2.fromHex = fromHex;
|
|
1724
|
-
})(Binary || (Binary = {}));
|
|
1725
|
-
var base64ToArrayBuffer = Binary.fromBase64;
|
|
1726
|
-
var arrayBufferToBase64 = Binary.toBase64;
|
|
1727
|
-
var hexToArrayBuffer = Binary.fromHex;
|
|
1728
|
-
var arrayBufferToHex = Binary.toHex;
|
|
1729
|
-
function clone(source, refs = /* @__PURE__ */ new Map()) {
|
|
1730
|
-
if (!source || typeof source !== "object") return source;
|
|
1731
|
-
if (is("Date", source)) return new Date(source.valueOf());
|
|
1732
|
-
if (is("RegExp", source)) return new RegExp(source.source, source.flags);
|
|
1733
|
-
if (isArrayBufferLike(source)) return source.slice(0);
|
|
1734
|
-
if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
|
|
1735
|
-
const cached = refs.get(source);
|
|
1736
|
-
if (cached) return cached;
|
|
1737
|
-
if (Array.isArray(source)) {
|
|
1738
|
-
const result2 = [];
|
|
1739
|
-
refs.set(source, result2);
|
|
1740
|
-
source.forEach((value, index) => {
|
|
1741
|
-
result2[index] = Reflect.apply(clone, null, [value, refs]);
|
|
1742
|
-
});
|
|
1743
|
-
return result2;
|
|
1744
|
-
}
|
|
1745
|
-
const result = Object.create(Object.getPrototypeOf(source));
|
|
1746
|
-
refs.set(source, result);
|
|
1747
|
-
for (const key of Reflect.ownKeys(source)) {
|
|
1748
|
-
const descriptor4 = { ...Reflect.getOwnPropertyDescriptor(source, key) };
|
|
1749
|
-
if ("value" in descriptor4) descriptor4.value = Reflect.apply(clone, null, [descriptor4.value, refs]);
|
|
1750
|
-
Reflect.defineProperty(result, key, descriptor4);
|
|
1751
|
-
}
|
|
1752
|
-
return result;
|
|
1753
|
-
}
|
|
1754
|
-
function deepEqual(a, b, strict) {
|
|
1755
|
-
const ancestors = /* @__PURE__ */ new Set();
|
|
1756
|
-
function compare(a2, b2) {
|
|
1757
|
-
if (a2 === b2) return true;
|
|
1758
|
-
if (isVolatile(a2) || isVolatile(b2)) return isVolatile(a2) && isVolatile(b2);
|
|
1759
|
-
if (!strict && isNullable(a2) && isNullable(b2)) return true;
|
|
1760
|
-
if (typeof a2 !== typeof b2 || typeof a2 !== "object" || !a2 || !b2) return false;
|
|
1761
|
-
if (ancestors.has(a2)) return false;
|
|
1762
|
-
function check(test, then) {
|
|
1763
|
-
return test(a2) ? test(b2) ? then(a2, b2) : false : test(b2) ? false : void 0;
|
|
1764
|
-
}
|
|
1765
|
-
ancestors.add(a2);
|
|
1766
|
-
try {
|
|
1767
|
-
return check(Array.isArray, (a3, b3) => {
|
|
1768
|
-
if (a3.length !== b3.length) return false;
|
|
1769
|
-
for (let index = 0; index < a3.length; index++) if (!compare(a3[index], b3[index])) return false;
|
|
1770
|
-
return true;
|
|
1771
|
-
}) ?? check(is("Date"), (a3, b3) => a3.valueOf() === b3.valueOf()) ?? check(is("URL"), (a3, b3) => a3.href === b3.href) ?? check(is("RegExp"), (a3, b3) => a3.source === b3.source && a3.flags === b3.flags) ?? check(isArrayBufferLike, (a3, b3) => {
|
|
1772
|
-
if (a3.byteLength !== b3.byteLength) return false;
|
|
1773
|
-
const viewA = new Uint8Array(a3);
|
|
1774
|
-
const viewB = new Uint8Array(b3);
|
|
1775
|
-
for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
|
|
1776
|
-
return true;
|
|
1777
|
-
}) ?? ((!strict || [a2, b2].every((value) => Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) && Object.keys({
|
|
1778
|
-
...a2,
|
|
1779
|
-
...b2
|
|
1780
|
-
}).every((key) => compare(a2[key], b2[key])));
|
|
1781
|
-
} finally {
|
|
1782
|
-
ancestors.delete(a2);
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
return compare(a, b);
|
|
1786
|
-
}
|
|
1787
|
-
var Time;
|
|
1788
|
-
(function(Time2) {
|
|
1789
|
-
Time2.millisecond = 1;
|
|
1790
|
-
Time2.second = 1e3;
|
|
1791
|
-
Time2.minute = Time2.second * 60;
|
|
1792
|
-
Time2.hour = Time2.minute * 60;
|
|
1793
|
-
Time2.day = Time2.hour * 24;
|
|
1794
|
-
Time2.week = Time2.day * 7;
|
|
1795
|
-
let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
|
|
1796
|
-
function setTimezoneOffset(offset) {
|
|
1797
|
-
timezoneOffset = offset;
|
|
1798
|
-
}
|
|
1799
|
-
Time2.setTimezoneOffset = setTimezoneOffset;
|
|
1800
|
-
function getTimezoneOffset() {
|
|
1801
|
-
return timezoneOffset;
|
|
1802
|
-
}
|
|
1803
|
-
Time2.getTimezoneOffset = getTimezoneOffset;
|
|
1804
|
-
function getDateNumber(date2 = /* @__PURE__ */ new Date(), offset) {
|
|
1805
|
-
if (typeof date2 === "number") date2 = new Date(date2);
|
|
1806
|
-
if (offset === void 0) offset = timezoneOffset;
|
|
1807
|
-
return Math.floor((date2.valueOf() / Time2.minute - offset) / 1440);
|
|
1808
|
-
}
|
|
1809
|
-
Time2.getDateNumber = getDateNumber;
|
|
1810
|
-
function fromDateNumber(value, offset) {
|
|
1811
|
-
const date2 = new Date(value * Time2.day);
|
|
1812
|
-
if (offset === void 0) offset = timezoneOffset;
|
|
1813
|
-
return new Date(+date2 + offset * Time2.minute);
|
|
1814
|
-
}
|
|
1815
|
-
Time2.fromDateNumber = fromDateNumber;
|
|
1816
|
-
const numeric = /\d+(?:\.\d+)?/.source;
|
|
1817
|
-
const timeRegExp = new RegExp(`^${[
|
|
1818
|
-
"w(?:eek(?:s)?)?",
|
|
1819
|
-
"d(?:ay(?:s)?)?",
|
|
1820
|
-
"h(?:our(?:s)?)?",
|
|
1821
|
-
"m(?:in(?:ute)?(?:s)?)?",
|
|
1822
|
-
"s(?:ec(?:ond)?(?:s)?)?"
|
|
1823
|
-
].map((unit) => `(${numeric}${unit})?`).join("")}$`);
|
|
1824
|
-
function parseTime(source) {
|
|
1825
|
-
const capture = timeRegExp.exec(source);
|
|
1826
|
-
if (!capture) return 0;
|
|
1827
|
-
return (parseFloat(capture[1]) * Time2.week || 0) + (parseFloat(capture[2]) * Time2.day || 0) + (parseFloat(capture[3]) * Time2.hour || 0) + (parseFloat(capture[4]) * Time2.minute || 0) + (parseFloat(capture[5]) * Time2.second || 0);
|
|
1828
|
-
}
|
|
1829
|
-
Time2.parseTime = parseTime;
|
|
1830
|
-
function parseDate(date2) {
|
|
1831
|
-
const parsed = parseTime(date2);
|
|
1832
|
-
if (parsed) date2 = Date.now() + parsed;
|
|
1833
|
-
else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date2)) date2 = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date2}`;
|
|
1834
|
-
else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date2)) date2 = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date2}`;
|
|
1835
|
-
return date2 ? new Date(date2) : /* @__PURE__ */ new Date();
|
|
1836
|
-
}
|
|
1837
|
-
Time2.parseDate = parseDate;
|
|
1838
|
-
function format2(ms) {
|
|
1839
|
-
const abs = Math.abs(ms);
|
|
1840
|
-
if (abs >= Time2.day - Time2.hour / 2) return Math.round(ms / Time2.day) + "d";
|
|
1841
|
-
else if (abs >= Time2.hour - Time2.minute / 2) return Math.round(ms / Time2.hour) + "h";
|
|
1842
|
-
else if (abs >= Time2.minute - Time2.second / 2) return Math.round(ms / Time2.minute) + "m";
|
|
1843
|
-
else if (abs >= Time2.second) return Math.round(ms / Time2.second) + "s";
|
|
1844
|
-
return ms + "ms";
|
|
1845
|
-
}
|
|
1846
|
-
Time2.format = format2;
|
|
1847
|
-
function toDigits(source, length = 2) {
|
|
1848
|
-
return source.toString().padStart(length, "0");
|
|
1849
|
-
}
|
|
1850
|
-
Time2.toDigits = toDigits;
|
|
1851
|
-
function template(template2, time = /* @__PURE__ */ new Date()) {
|
|
1852
|
-
return template2.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3));
|
|
1853
|
-
}
|
|
1854
|
-
Time2.template = template;
|
|
1855
|
-
})(Time || (Time = {}));
|
|
1856
|
-
|
|
1857
|
-
// node_modules/.pnpm/@deepseek-ai+schemastery@3.18.5/node_modules/@deepseek-ai/schemastery/lib/index.mjs
|
|
1858
|
-
var kSchema = Symbol.for("schemastery");
|
|
1859
|
-
var kValidationError = Symbol.for("ValidationError");
|
|
1860
|
-
globalThis.__schemastery_index__ ??= 0;
|
|
1861
|
-
globalThis.__schemastery_refs__ = void 0;
|
|
1862
|
-
var ValidationError = class extends TypeError {
|
|
1863
|
-
options;
|
|
1864
|
-
name = "ValidationError";
|
|
1865
|
-
constructor(message, options) {
|
|
1866
|
-
let prefix = "$";
|
|
1867
|
-
for (const segment of options.path || []) if (typeof segment === "string") prefix += "." + segment;
|
|
1868
|
-
else if (typeof segment === "number") prefix += "[" + segment + "]";
|
|
1869
|
-
else if (typeof segment === "symbol") prefix += `[Symbol(${segment.toString()})]`;
|
|
1870
|
-
if (prefix.startsWith(".")) prefix = prefix.slice(1);
|
|
1871
|
-
super((prefix === "$" ? "" : `${prefix} `) + message);
|
|
1872
|
-
this.options = options;
|
|
1873
|
-
}
|
|
1874
|
-
static is(error) {
|
|
1875
|
-
return !!error?.[kValidationError];
|
|
1876
|
-
}
|
|
1877
|
-
};
|
|
1878
|
-
Object.defineProperty(ValidationError.prototype, kValidationError, { value: true });
|
|
1879
|
-
var Schema = function(options) {
|
|
1880
|
-
const schema = function(data, options2 = {}) {
|
|
1881
|
-
return Schema.resolve(data, schema, options2)[0];
|
|
1882
|
-
};
|
|
1883
|
-
if (options.refs) {
|
|
1884
|
-
const refs = mapValues(options.refs, (options2) => new Schema(options2));
|
|
1885
|
-
const getRef = (uid) => refs[uid];
|
|
1886
|
-
for (const key in refs) {
|
|
1887
|
-
const options2 = refs[key];
|
|
1888
|
-
options2.sKey = getRef(options2.sKey);
|
|
1889
|
-
options2.inner = getRef(options2.inner);
|
|
1890
|
-
options2.list = options2.list && options2.list.map(getRef);
|
|
1891
|
-
options2.dict = options2.dict && mapValues(options2.dict, getRef);
|
|
1892
|
-
}
|
|
1893
|
-
return refs[options.uid];
|
|
1894
|
-
}
|
|
1895
|
-
Object.assign(schema, options);
|
|
1896
|
-
if (typeof schema.callback === "string") try {
|
|
1897
|
-
schema.callback = new Function("return " + schema.callback)();
|
|
1898
|
-
} catch {
|
|
1899
|
-
}
|
|
1900
|
-
Object.defineProperty(schema, "uid", { value: globalThis.__schemastery_index__++ });
|
|
1901
|
-
Object.setPrototypeOf(schema, Schema.prototype);
|
|
1902
|
-
schema.meta ||= {};
|
|
1903
|
-
schema.toString = schema.toString.bind(schema);
|
|
1904
|
-
return schema;
|
|
1905
|
-
};
|
|
1906
|
-
Schema.prototype = Object.create(Function.prototype);
|
|
1907
|
-
Schema.prototype[kSchema] = true;
|
|
1908
|
-
Object.defineProperty(Schema.prototype, "~standard", { get() {
|
|
1909
|
-
return {
|
|
1910
|
-
version: 1,
|
|
1911
|
-
vendor: "schemastery",
|
|
1912
|
-
validate: (value) => {
|
|
1913
|
-
try {
|
|
1914
|
-
return { value: Schema.resolve(value, this, {})[0] };
|
|
1915
|
-
} catch (error) {
|
|
1916
|
-
if (ValidationError.is(error)) return { issues: [{
|
|
1917
|
-
message: error.message,
|
|
1918
|
-
path: error.options.path
|
|
1919
|
-
}] };
|
|
1920
|
-
throw error;
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
};
|
|
1924
|
-
} });
|
|
1925
|
-
Schema.ValidationError = ValidationError;
|
|
1926
|
-
Schema.prototype.toJSON = function toJSON() {
|
|
1927
|
-
if (globalThis.__schemastery_refs__) {
|
|
1928
|
-
globalThis.__schemastery_refs__[this.uid] ??= JSON.parse(JSON.stringify({ ...this }));
|
|
1929
|
-
return this.uid;
|
|
1930
|
-
}
|
|
1931
|
-
globalThis.__schemastery_refs__ = { [this.uid]: { ...this } };
|
|
1932
|
-
globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
|
|
1933
|
-
const result = {
|
|
1934
|
-
uid: this.uid,
|
|
1935
|
-
refs: globalThis.__schemastery_refs__
|
|
1936
|
-
};
|
|
1937
|
-
globalThis.__schemastery_refs__ = void 0;
|
|
1938
|
-
return result;
|
|
1939
|
-
};
|
|
1940
|
-
Schema.prototype.set = function set(key, value) {
|
|
1941
|
-
this.dict[key] = value;
|
|
1942
|
-
return this;
|
|
1943
|
-
};
|
|
1944
|
-
Schema.prototype.push = function push(value) {
|
|
1945
|
-
this.list.push(value);
|
|
1946
|
-
return this;
|
|
1947
|
-
};
|
|
1948
|
-
function mergeDesc(original, messages) {
|
|
1949
|
-
const result = typeof original === "string" ? { "": original } : { ...original };
|
|
1950
|
-
for (const locale in messages) {
|
|
1951
|
-
const value = messages[locale];
|
|
1952
|
-
if (value?.$description || value?.$desc) result[locale] = value.$description || value.$desc;
|
|
1953
|
-
else if (typeof value === "string") result[locale] = value;
|
|
1954
|
-
}
|
|
1955
|
-
return result;
|
|
1956
|
-
}
|
|
1957
|
-
function getInner(value) {
|
|
1958
|
-
return value?.$value ?? value?.$inner;
|
|
1959
|
-
}
|
|
1960
|
-
function extractKeys(data) {
|
|
1961
|
-
return filterKeys(data ?? {}, (key) => !key.startsWith("$"));
|
|
1962
|
-
}
|
|
1963
|
-
Schema.prototype.i18n = function i18n(messages) {
|
|
1964
|
-
const schema = Schema(this);
|
|
1965
|
-
const desc = mergeDesc(schema.meta.description, messages);
|
|
1966
|
-
if (Object.keys(desc).length) schema.meta.description = desc;
|
|
1967
|
-
if (schema.dict) schema.dict = mapValues(schema.dict, (inner, key) => {
|
|
1968
|
-
return inner.i18n(mapValues(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
|
|
1969
|
-
});
|
|
1970
|
-
if (schema.list) schema.list = schema.list.map((inner, index) => {
|
|
1971
|
-
return inner.i18n(mapValues(messages, (data = {}) => {
|
|
1972
|
-
if (Array.isArray(getInner(data))) return getInner(data)[index];
|
|
1973
|
-
if (Array.isArray(data)) return data[index];
|
|
1974
|
-
return extractKeys(data);
|
|
1975
|
-
}));
|
|
1976
|
-
});
|
|
1977
|
-
if (schema.inner) schema.inner = schema.inner.i18n(mapValues(messages, (data) => {
|
|
1978
|
-
if (getInner(data)) return getInner(data);
|
|
1979
|
-
return extractKeys(data);
|
|
1980
|
-
}));
|
|
1981
|
-
if (schema.sKey) schema.sKey = schema.sKey.i18n(mapValues(messages, (data) => data?.$key));
|
|
1982
|
-
return schema;
|
|
1983
|
-
};
|
|
1984
|
-
Schema.prototype.extra = function extra(key, value) {
|
|
1985
|
-
const schema = Schema(this);
|
|
1986
|
-
schema.meta = {
|
|
1987
|
-
...schema.meta,
|
|
1988
|
-
[key]: value
|
|
1989
|
-
};
|
|
1990
|
-
return schema;
|
|
1991
|
-
};
|
|
1992
|
-
for (const key of [
|
|
1993
|
-
"required",
|
|
1994
|
-
"disabled",
|
|
1995
|
-
"collapse",
|
|
1996
|
-
"hidden",
|
|
1997
|
-
"loose"
|
|
1998
|
-
]) Object.assign(Schema.prototype, { [key](value = true) {
|
|
1999
|
-
const schema = Schema(this);
|
|
2000
|
-
schema.meta = {
|
|
2001
|
-
...schema.meta,
|
|
2002
|
-
[key]: value
|
|
2003
|
-
};
|
|
2004
|
-
return schema;
|
|
2005
|
-
} });
|
|
2006
|
-
Schema.prototype.deprecated = function deprecated() {
|
|
2007
|
-
const schema = Schema(this);
|
|
2008
|
-
schema.meta.badges ||= [];
|
|
2009
|
-
schema.meta.badges.push({
|
|
2010
|
-
text: "deprecated",
|
|
2011
|
-
type: "danger"
|
|
2012
|
-
});
|
|
2013
|
-
return schema;
|
|
2014
|
-
};
|
|
2015
|
-
Schema.prototype.experimental = function experimental() {
|
|
2016
|
-
const schema = Schema(this);
|
|
2017
|
-
schema.meta.badges ||= [];
|
|
2018
|
-
schema.meta.badges.push({
|
|
2019
|
-
text: "experimental",
|
|
2020
|
-
type: "warning"
|
|
2021
|
-
});
|
|
2022
|
-
return schema;
|
|
2023
|
-
};
|
|
2024
|
-
Schema.prototype.pattern = function pattern(regexp) {
|
|
2025
|
-
const schema = Schema(this);
|
|
2026
|
-
const pattern2 = pick(regexp, ["source", "flags"]);
|
|
2027
|
-
schema.meta = {
|
|
2028
|
-
...schema.meta,
|
|
2029
|
-
pattern: pattern2
|
|
2030
|
-
};
|
|
2031
|
-
return schema;
|
|
2032
|
-
};
|
|
2033
|
-
Schema.prototype.simplify = function simplify(value) {
|
|
2034
|
-
if (isVolatile(value)) value = value.get();
|
|
2035
|
-
if (deepEqual(value, this.meta.default, this.type === "dict")) return null;
|
|
2036
|
-
if (isNullable(value)) return value;
|
|
2037
|
-
if (this.type === "object" || this.type === "dict") {
|
|
2038
|
-
const result = {};
|
|
2039
|
-
for (const key in value) {
|
|
2040
|
-
const item = (this.type === "object" ? this.dict[key] : this.inner)?.simplify(value[key]);
|
|
2041
|
-
if (this.type === "dict" || !isNullable(item)) result[key] = item;
|
|
2042
|
-
}
|
|
2043
|
-
if (deepEqual(result, this.meta.default, this.type === "dict")) return null;
|
|
2044
|
-
return result;
|
|
2045
|
-
} else if (this.type === "array" || this.type === "tuple") {
|
|
2046
|
-
const result = [];
|
|
2047
|
-
value.forEach((value2, index) => {
|
|
2048
|
-
const schema = this.type === "array" ? this.inner : this.list[index];
|
|
2049
|
-
const item = schema ? schema.simplify(value2) : value2;
|
|
2050
|
-
result.push(item);
|
|
2051
|
-
});
|
|
2052
|
-
return result;
|
|
2053
|
-
} else if (this.type === "intersect") {
|
|
2054
|
-
const result = {};
|
|
2055
|
-
for (const item of this.list) Object.assign(result, item.simplify(value));
|
|
2056
|
-
return result;
|
|
2057
|
-
} else if (this.type === "union") for (const schema of this.list) try {
|
|
2058
|
-
Schema.resolve(value, schema, {});
|
|
2059
|
-
return schema.simplify(value);
|
|
2060
|
-
} catch {
|
|
2061
|
-
}
|
|
2062
|
-
return value;
|
|
2063
|
-
};
|
|
2064
|
-
Schema.prototype.toString = function toString(inline) {
|
|
2065
|
-
return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`;
|
|
2066
|
-
};
|
|
2067
|
-
Schema.prototype.role = function role(role, extra2) {
|
|
2068
|
-
const schema = Schema(this);
|
|
2069
|
-
schema.meta = {
|
|
2070
|
-
...schema.meta,
|
|
2071
|
-
role,
|
|
2072
|
-
extra: extra2
|
|
2073
|
-
};
|
|
2074
|
-
return schema;
|
|
2075
|
-
};
|
|
2076
|
-
for (const key of [
|
|
2077
|
-
"default",
|
|
2078
|
-
"link",
|
|
2079
|
-
"comment",
|
|
2080
|
-
"description",
|
|
2081
|
-
"max",
|
|
2082
|
-
"min",
|
|
2083
|
-
"step"
|
|
2084
|
-
]) Object.assign(Schema.prototype, { [key](value) {
|
|
2085
|
-
const schema = Schema(this);
|
|
2086
|
-
schema.meta = {
|
|
2087
|
-
...schema.meta,
|
|
2088
|
-
[key]: value
|
|
2089
|
-
};
|
|
2090
|
-
return schema;
|
|
2091
|
-
} });
|
|
2092
|
-
Schema.prototype.volatile = function volatile() {
|
|
2093
|
-
if (this.meta.volatile) throw new TypeError("volatile schema is already wrapped");
|
|
2094
|
-
return this.extra("volatile", true);
|
|
2095
|
-
};
|
|
2096
|
-
var resolvers = {};
|
|
2097
|
-
var checkedVolatile = Symbol("checked-volatile-schema");
|
|
2098
|
-
function validateVolatileSchema(schema, path = [], blocked = false, seen = /* @__PURE__ */ new Map()) {
|
|
2099
|
-
const states = seen.get(schema) ?? /* @__PURE__ */ new Set();
|
|
2100
|
-
if (states.has(blocked)) return;
|
|
2101
|
-
states.add(blocked);
|
|
2102
|
-
seen.set(schema, states);
|
|
2103
|
-
if (schema.meta?.volatile && blocked) throw new ValidationError("volatile fields require a fixed object path without an enclosing volatile field", { path });
|
|
2104
|
-
const nested = blocked || !!schema.meta?.volatile;
|
|
2105
|
-
if (schema.dict) for (const [key, child2] of Object.entries(schema.dict)) validateVolatileSchema(child2, [...path, key], nested, seen);
|
|
2106
|
-
if (schema.sKey) validateVolatileSchema(schema.sKey, [...path, "<key>"], true, seen);
|
|
2107
|
-
if (schema.inner && (schema.type !== "lazy" || schema.inner[kSchema])) validateVolatileSchema(schema.inner, [...path, "*"], true, seen);
|
|
2108
|
-
if (schema.list) for (let index = 0; index < schema.list.length; index++) validateVolatileSchema(schema.list[index], [...path, String(index)], true, seen);
|
|
2109
|
-
}
|
|
2110
|
-
Schema.extend = function extend(type, resolve2) {
|
|
2111
|
-
resolvers[type] = resolve2;
|
|
2112
|
-
};
|
|
2113
|
-
Schema.resolve = function resolve(data, schema, options = {}, strict = false) {
|
|
2114
|
-
if (!schema) return [data];
|
|
2115
|
-
if (!options[checkedVolatile]) {
|
|
2116
|
-
validateVolatileSchema(schema, options.path);
|
|
2117
|
-
options = {
|
|
2118
|
-
...options,
|
|
2119
|
-
[checkedVolatile]: true
|
|
2120
|
-
};
|
|
2121
|
-
}
|
|
2122
|
-
if (schema.meta?.volatile) {
|
|
2123
|
-
const inner = Schema(schema);
|
|
2124
|
-
inner.meta = {
|
|
2125
|
-
...schema.meta,
|
|
2126
|
-
volatile: false
|
|
2127
|
-
};
|
|
2128
|
-
const [value, adapted] = Schema.resolve(data, inner, options, strict);
|
|
2129
|
-
try {
|
|
2130
|
-
return [createVolatile(value), adapted];
|
|
2131
|
-
} catch (error) {
|
|
2132
|
-
throw new ValidationError(error instanceof Error ? error.message : String(error), options);
|
|
2133
|
-
}
|
|
2134
|
-
}
|
|
2135
|
-
if (options.ignore?.(data, schema)) return [data];
|
|
2136
|
-
if (isNullable(data) && schema.type !== "lazy") {
|
|
2137
|
-
if (schema.meta.required) throw new ValidationError(`missing required value`, options);
|
|
2138
|
-
let current = schema;
|
|
2139
|
-
let fallback = schema.meta.default;
|
|
2140
|
-
while (current?.type === "intersect" && isNullable(fallback)) {
|
|
2141
|
-
current = current.list[0];
|
|
2142
|
-
fallback = current?.meta.default;
|
|
2143
|
-
}
|
|
2144
|
-
if (isNullable(fallback)) return [data];
|
|
2145
|
-
data = clone(fallback);
|
|
2146
|
-
}
|
|
2147
|
-
const callback = resolvers[schema.type];
|
|
2148
|
-
if (!callback) throw new ValidationError(`unsupported type "${schema.type}"`, options);
|
|
2149
|
-
try {
|
|
2150
|
-
return callback(data, schema, options, strict);
|
|
2151
|
-
} catch (error) {
|
|
2152
|
-
if (!schema.meta.loose) throw error;
|
|
2153
|
-
return [schema.meta.default];
|
|
2154
|
-
}
|
|
2155
|
-
};
|
|
2156
|
-
Schema.from = function from(source) {
|
|
2157
|
-
if (isNullable(source)) return Schema.any();
|
|
2158
|
-
else if ([
|
|
2159
|
-
"string",
|
|
2160
|
-
"number",
|
|
2161
|
-
"boolean"
|
|
2162
|
-
].includes(typeof source)) return Schema.const(source).required();
|
|
2163
|
-
else if (source[kSchema]) return source;
|
|
2164
|
-
else if (typeof source === "function") switch (source) {
|
|
2165
|
-
case String:
|
|
2166
|
-
return Schema.string().required();
|
|
2167
|
-
case Number:
|
|
2168
|
-
return Schema.number().required();
|
|
2169
|
-
case Boolean:
|
|
2170
|
-
return Schema.boolean().required();
|
|
2171
|
-
case Function:
|
|
2172
|
-
return Schema.function().required();
|
|
2173
|
-
default:
|
|
2174
|
-
return Schema.is(source).required();
|
|
2175
|
-
}
|
|
2176
|
-
else throw new TypeError(`cannot infer schema from ${source}`);
|
|
2177
|
-
};
|
|
2178
|
-
Schema.lazy = function lazy(builder) {
|
|
2179
|
-
const toJSON2 = () => {
|
|
2180
|
-
if (!schema.inner[kSchema]) {
|
|
2181
|
-
schema.inner = schema.builder();
|
|
2182
|
-
schema.inner.meta = {
|
|
2183
|
-
...schema.meta,
|
|
2184
|
-
...schema.inner.meta
|
|
2185
|
-
};
|
|
2186
|
-
}
|
|
2187
|
-
return schema.inner.toJSON();
|
|
2188
|
-
};
|
|
2189
|
-
const schema = new Schema({
|
|
2190
|
-
type: "lazy",
|
|
2191
|
-
builder,
|
|
2192
|
-
inner: { toJSON: toJSON2 }
|
|
2193
|
-
});
|
|
2194
|
-
return schema;
|
|
2195
|
-
};
|
|
2196
|
-
Schema.natural = function natural() {
|
|
2197
|
-
return Schema.number().step(1).min(0);
|
|
2198
|
-
};
|
|
2199
|
-
Schema.percent = function percent() {
|
|
2200
|
-
return Schema.number().step(0.01).min(0).max(1).role("slider");
|
|
2201
|
-
};
|
|
2202
|
-
Schema.date = function date() {
|
|
2203
|
-
return Schema.union([Schema.is(Date), Schema.transform(Schema.string().role("datetime"), (value, options) => {
|
|
2204
|
-
const date2 = new Date(value);
|
|
2205
|
-
if (isNaN(+date2)) throw new ValidationError(`invalid date "${value}"`, options);
|
|
2206
|
-
return date2;
|
|
2207
|
-
}, true)]);
|
|
2208
|
-
};
|
|
2209
|
-
Schema.regExp = function regExp(flag = "") {
|
|
2210
|
-
return Schema.union([Schema.is(RegExp), Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
|
|
2211
|
-
try {
|
|
2212
|
-
return new RegExp(value, flag);
|
|
2213
|
-
} catch (e) {
|
|
2214
|
-
throw new ValidationError(e.message, options);
|
|
2215
|
-
}
|
|
2216
|
-
}, true)]);
|
|
2217
|
-
};
|
|
2218
|
-
Schema.arrayBuffer = function arrayBuffer(encoding) {
|
|
2219
|
-
return Schema.union([
|
|
2220
|
-
Schema.is(ArrayBuffer),
|
|
2221
|
-
Schema.is(SharedArrayBuffer),
|
|
2222
|
-
Schema.transform(Schema.any(), (value, options) => {
|
|
2223
|
-
if (Binary.isSource(value)) return Binary.fromSource(value);
|
|
2224
|
-
throw new ValidationError(`expected ArrayBufferSource but got ${value}`, options);
|
|
2225
|
-
}, true),
|
|
2226
|
-
...encoding ? [Schema.transform(Schema.string(), (value, options) => {
|
|
2227
|
-
try {
|
|
2228
|
-
return encoding === "base64" ? Binary.fromBase64(value) : Binary.fromHex(value);
|
|
2229
|
-
} catch (e) {
|
|
2230
|
-
throw new ValidationError(e.message, options);
|
|
2231
|
-
}
|
|
2232
|
-
}, true)] : []
|
|
2233
|
-
]);
|
|
2234
|
-
};
|
|
2235
|
-
Schema.extend("lazy", (data, schema, options, strict) => {
|
|
2236
|
-
if (!schema.inner[kSchema]) {
|
|
2237
|
-
schema.inner = schema.builder();
|
|
2238
|
-
schema.inner.meta = {
|
|
2239
|
-
...schema.meta,
|
|
2240
|
-
...schema.inner.meta
|
|
2241
|
-
};
|
|
2242
|
-
validateVolatileSchema(schema.inner, options.path, true);
|
|
2243
|
-
}
|
|
2244
|
-
return Schema.resolve(data, schema.inner, options, strict);
|
|
2245
|
-
});
|
|
2246
|
-
Schema.extend("any", (data) => {
|
|
2247
|
-
return [data];
|
|
2248
|
-
});
|
|
2249
|
-
Schema.extend("never", (data, _, options) => {
|
|
2250
|
-
throw new ValidationError(`expected nullable but got ${data}`, options);
|
|
2251
|
-
});
|
|
2252
|
-
Schema.extend("const", (data, { value }, options) => {
|
|
2253
|
-
if (deepEqual(data, value)) return [value];
|
|
2254
|
-
throw new ValidationError(`expected ${value} but got ${data}`, options);
|
|
2255
|
-
});
|
|
2256
|
-
function checkWithinRange(data, meta, description, options, skipMin = false) {
|
|
2257
|
-
const { max = Infinity, min = -Infinity } = meta;
|
|
2258
|
-
if (data > max) throw new ValidationError(`expected ${description} <= ${max} but got ${data}`, options);
|
|
2259
|
-
if (data < min && !skipMin) throw new ValidationError(`expected ${description} >= ${min} but got ${data}`, options);
|
|
2260
|
-
}
|
|
2261
|
-
Schema.extend("string", (data, { meta }, options) => {
|
|
2262
|
-
if (typeof data !== "string") throw new ValidationError(`expected string but got ${data}`, options);
|
|
2263
|
-
if (meta.pattern) {
|
|
2264
|
-
const regexp = new RegExp(meta.pattern.source, meta.pattern.flags);
|
|
2265
|
-
if (!regexp.test(data)) throw new ValidationError(`expect string to match regexp ${regexp}`, options);
|
|
2266
|
-
}
|
|
2267
|
-
checkWithinRange(data.length, meta, "string length", options);
|
|
2268
|
-
return [data];
|
|
2269
|
-
});
|
|
2270
|
-
function decimalShift(data, digits) {
|
|
2271
|
-
const str = data.toString();
|
|
2272
|
-
if (str.includes("e")) return data * Math.pow(10, digits);
|
|
2273
|
-
const index = str.indexOf(".");
|
|
2274
|
-
if (index === -1) return data * Math.pow(10, digits);
|
|
2275
|
-
const frac = str.slice(index + 1);
|
|
2276
|
-
const integer3 = str.slice(0, index);
|
|
2277
|
-
if (frac.length <= digits) return +(integer3 + frac.padEnd(digits, "0"));
|
|
2278
|
-
return +(integer3 + frac.slice(0, digits) + "." + frac.slice(digits));
|
|
2279
|
-
}
|
|
2280
|
-
function isMultipleOf(data, min, step) {
|
|
2281
|
-
step = Math.abs(step);
|
|
2282
|
-
if (!/^\d+\.\d+$/.test(step.toString())) return (data - min) % step === 0;
|
|
2283
|
-
const index = step.toString().indexOf(".");
|
|
2284
|
-
const digits = step.toString().slice(index + 1).length;
|
|
2285
|
-
return Math.abs(decimalShift(data, digits) - decimalShift(min, digits)) % decimalShift(step, digits) === 0;
|
|
2286
|
-
}
|
|
2287
|
-
Schema.extend("number", (data, { meta }, options) => {
|
|
2288
|
-
if (typeof data !== "number") throw new ValidationError(`expected number but got ${data}`, options);
|
|
2289
|
-
checkWithinRange(data, meta, "number", options);
|
|
2290
|
-
const { step } = meta;
|
|
2291
|
-
if (step && !isMultipleOf(data, meta.min ?? 0, step)) throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
|
|
2292
|
-
return [data];
|
|
2293
|
-
});
|
|
2294
|
-
Schema.extend("boolean", (data, _, options) => {
|
|
2295
|
-
if (typeof data === "boolean") return [data];
|
|
2296
|
-
throw new ValidationError(`expected boolean but got ${data}`, options);
|
|
2297
|
-
});
|
|
2298
|
-
Schema.extend("bitset", (data, { bits, meta }, options) => {
|
|
2299
|
-
let value = 0, keys = [];
|
|
2300
|
-
if (typeof data === "number") {
|
|
2301
|
-
value = data;
|
|
2302
|
-
for (const key in bits) if (data & bits[key]) keys.push(key);
|
|
2303
|
-
} else if (Array.isArray(data)) {
|
|
2304
|
-
keys = data;
|
|
2305
|
-
for (const key of keys) {
|
|
2306
|
-
if (typeof key !== "string") throw new ValidationError(`expected string but got ${key}`, options);
|
|
2307
|
-
if (key in bits) value |= bits[key];
|
|
2308
|
-
}
|
|
2309
|
-
} else throw new ValidationError(`expected number or array but got ${data}`, options);
|
|
2310
|
-
if (value === meta.default) return [value];
|
|
2311
|
-
return [value, keys];
|
|
2312
|
-
});
|
|
2313
|
-
Schema.extend("function", (data, _, options) => {
|
|
2314
|
-
if (typeof data === "function") return [data];
|
|
2315
|
-
throw new ValidationError(`expected function but got ${data}`, options);
|
|
2316
|
-
});
|
|
2317
|
-
Schema.extend("is", (data, { constructor }, options) => {
|
|
2318
|
-
if (typeof constructor === "function") {
|
|
2319
|
-
if (data instanceof constructor) return [data];
|
|
2320
|
-
throw new ValidationError(`expected ${constructor.name} but got ${data}`, options);
|
|
2321
|
-
} else {
|
|
2322
|
-
if (isNullable(data)) throw new ValidationError(`expected ${constructor} but got ${data}`, options);
|
|
2323
|
-
let prototype = Object.getPrototypeOf(data);
|
|
2324
|
-
while (prototype) {
|
|
2325
|
-
if (prototype.constructor?.name === constructor) return [data];
|
|
2326
|
-
prototype = Object.getPrototypeOf(prototype);
|
|
2327
|
-
}
|
|
2328
|
-
throw new ValidationError(`expected ${constructor} but got ${data}`, options);
|
|
2329
|
-
}
|
|
2330
|
-
});
|
|
2331
|
-
function property(data, key, schema, options) {
|
|
2332
|
-
try {
|
|
2333
|
-
const [value, adapted] = Schema.resolve(data[key], schema, {
|
|
2334
|
-
...options,
|
|
2335
|
-
path: [...options.path || [], key]
|
|
2336
|
-
});
|
|
2337
|
-
if (adapted !== void 0) data[key] = adapted;
|
|
2338
|
-
return value;
|
|
2339
|
-
} catch (e) {
|
|
2340
|
-
if (!options?.autofix) throw e;
|
|
2341
|
-
delete data[key];
|
|
2342
|
-
return schema.meta.volatile ? createVolatile(schema.meta.default) : schema.meta.default;
|
|
2343
|
-
}
|
|
2344
|
-
}
|
|
2345
|
-
Schema.extend("array", (data, { inner, meta }, options) => {
|
|
2346
|
-
if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
|
|
2347
|
-
checkWithinRange(data.length, meta, "array length", options, !isNullable(inner.meta.default));
|
|
2348
|
-
return [data.map((_, index) => property(data, index, inner, options))];
|
|
2349
|
-
});
|
|
2350
|
-
Schema.extend("dict", (data, { inner, sKey }, options, strict) => {
|
|
2351
|
-
if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
|
|
2352
|
-
const result = {};
|
|
2353
|
-
for (const key in data) {
|
|
2354
|
-
let rKey;
|
|
2355
|
-
try {
|
|
2356
|
-
rKey = Schema.resolve(key, sKey, options)[0];
|
|
2357
|
-
} catch (error) {
|
|
2358
|
-
if (strict) continue;
|
|
2359
|
-
throw error;
|
|
2360
|
-
}
|
|
2361
|
-
result[rKey] = property(data, key, inner, options);
|
|
2362
|
-
data[rKey] = data[key];
|
|
2363
|
-
if (key !== rKey) delete data[key];
|
|
2364
|
-
}
|
|
2365
|
-
return [result];
|
|
2366
|
-
});
|
|
2367
|
-
Schema.extend("tuple", (data, { list }, options, strict) => {
|
|
2368
|
-
if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
|
|
2369
|
-
const result = list.map((inner, index) => property(data, index, inner, options));
|
|
2370
|
-
if (strict) return [result];
|
|
2371
|
-
result.push(...data.slice(list.length));
|
|
2372
|
-
return [result];
|
|
2373
|
-
});
|
|
2374
|
-
function merge(result, data) {
|
|
2375
|
-
for (const key in data) {
|
|
2376
|
-
if (key in result) continue;
|
|
2377
|
-
result[key] = data[key];
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
Schema.extend("object", (data, { dict }, options, strict) => {
|
|
2381
|
-
if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
|
|
2382
|
-
const result = {};
|
|
2383
|
-
for (const key in dict) {
|
|
2384
|
-
const value = property(data, key, dict[key], options);
|
|
2385
|
-
if (!isNullable(value) || key in data) result[key] = value;
|
|
2386
|
-
}
|
|
2387
|
-
if (!strict) merge(result, data);
|
|
2388
|
-
return [result];
|
|
2389
|
-
});
|
|
2390
|
-
Schema.extend("union", (data, { list, toString: toString2 }, options, strict) => {
|
|
2391
|
-
const messages = [];
|
|
2392
|
-
for (const inner of list) try {
|
|
2393
|
-
return Schema.resolve(data, inner, options, strict);
|
|
2394
|
-
} catch (error) {
|
|
2395
|
-
messages.push(error);
|
|
2396
|
-
}
|
|
2397
|
-
throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
|
|
2398
|
-
});
|
|
2399
|
-
Schema.extend("intersect", (data, { list, toString: toString2 }, options, strict) => {
|
|
2400
|
-
if (!list.length) return [data];
|
|
2401
|
-
let result;
|
|
2402
|
-
for (const inner of list) {
|
|
2403
|
-
const value = Schema.resolve(data, inner, options, true)[0];
|
|
2404
|
-
if (isNullable(value)) continue;
|
|
2405
|
-
if (isNullable(result)) result = value;
|
|
2406
|
-
else if (typeof result !== typeof value) throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
|
|
2407
|
-
else if (typeof value === "object") merge(result ??= {}, value);
|
|
2408
|
-
else if (result !== value) throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
|
|
2409
|
-
}
|
|
2410
|
-
if (!strict && isPlainObject(data)) merge(result, data);
|
|
2411
|
-
return [result];
|
|
2412
|
-
});
|
|
2413
|
-
Schema.extend("transform", (data, { inner, callback, preserve }, options) => {
|
|
2414
|
-
const [result, adapted = data] = Schema.resolve(data, inner, options, true);
|
|
2415
|
-
if (preserve) return [callback(result)];
|
|
2416
|
-
else return [callback(result), callback(adapted)];
|
|
2417
|
-
});
|
|
2418
|
-
var formatters = {};
|
|
2419
|
-
function defineMethod(name2, keys, format2) {
|
|
2420
|
-
formatters[name2] = format2;
|
|
2421
|
-
Object.assign(Schema, { [name2](...args) {
|
|
2422
|
-
const schema = new Schema({ type: name2 });
|
|
2423
|
-
keys.forEach((key, index) => {
|
|
2424
|
-
switch (key) {
|
|
2425
|
-
case "sKey":
|
|
2426
|
-
schema.sKey = args[index] ?? Schema.string();
|
|
2427
|
-
break;
|
|
2428
|
-
case "inner":
|
|
2429
|
-
schema.inner = Schema.from(args[index]);
|
|
2430
|
-
break;
|
|
2431
|
-
case "list":
|
|
2432
|
-
schema.list = args[index].map(Schema.from);
|
|
2433
|
-
break;
|
|
2434
|
-
case "dict":
|
|
2435
|
-
schema.dict = mapValues(args[index], Schema.from);
|
|
2436
|
-
break;
|
|
2437
|
-
case "bits":
|
|
2438
|
-
schema.bits = {};
|
|
2439
|
-
for (const key2 in args[index]) {
|
|
2440
|
-
if (typeof args[index][key2] !== "number") continue;
|
|
2441
|
-
schema.bits[key2] = args[index][key2];
|
|
2442
|
-
}
|
|
2443
|
-
break;
|
|
2444
|
-
case "callback": {
|
|
2445
|
-
const callback = schema.callback = args[index];
|
|
2446
|
-
callback["toJSON"] ||= () => callback.toString();
|
|
2447
|
-
break;
|
|
2448
|
-
}
|
|
2449
|
-
case "constructor": {
|
|
2450
|
-
const constructor = schema.constructor = args[index];
|
|
2451
|
-
if (typeof constructor === "function") constructor["toJSON"] ||= () => constructor["name"];
|
|
2452
|
-
break;
|
|
2453
|
-
}
|
|
2454
|
-
default:
|
|
2455
|
-
schema[key] = args[index];
|
|
2456
|
-
}
|
|
2457
|
-
});
|
|
2458
|
-
if (name2 === "object" || name2 === "dict") schema.meta.default = {};
|
|
2459
|
-
else if (name2 === "array" || name2 === "tuple") schema.meta.default = [];
|
|
2460
|
-
else if (name2 === "bitset") schema.meta.default = 0;
|
|
2461
|
-
return schema;
|
|
2462
|
-
} });
|
|
2463
|
-
}
|
|
2464
|
-
defineMethod("is", ["constructor"], ({ constructor }) => {
|
|
2465
|
-
if (typeof constructor === "function") return constructor.name;
|
|
2466
|
-
else return constructor;
|
|
2467
|
-
});
|
|
2468
|
-
defineMethod("any", [], () => "any");
|
|
2469
|
-
defineMethod("never", [], () => "never");
|
|
2470
|
-
defineMethod("const", ["value"], ({ value }) => typeof value === "string" ? JSON.stringify(value) : value);
|
|
2471
|
-
defineMethod("string", [], () => "string");
|
|
2472
|
-
defineMethod("number", [], () => "number");
|
|
2473
|
-
defineMethod("boolean", [], () => "boolean");
|
|
2474
|
-
defineMethod("bitset", ["bits"], () => "bitset");
|
|
2475
|
-
defineMethod("function", [], () => "function");
|
|
2476
|
-
defineMethod("array", ["inner"], ({ inner }) => `${inner.toString(true)}[]`);
|
|
2477
|
-
defineMethod("dict", ["inner", "sKey"], ({ inner, sKey }) => `{ [key: ${sKey.toString()}]: ${inner.toString()} }`);
|
|
2478
|
-
defineMethod("tuple", ["list"], ({ list }) => `[${list.map((inner) => inner.toString()).join(", ")}]`);
|
|
2479
|
-
defineMethod("object", ["dict"], ({ dict }) => {
|
|
2480
|
-
if (Object.keys(dict).length === 0) return "{}";
|
|
2481
|
-
return `{ ${Object.entries(dict).map(([key, inner]) => {
|
|
2482
|
-
return `${key}${inner.meta.required ? "" : "?"}: ${inner.toString()}`;
|
|
2483
|
-
}).join(", ")} }`;
|
|
2484
|
-
});
|
|
2485
|
-
defineMethod("union", ["list"], ({ list }, inline) => {
|
|
2486
|
-
const result = list.map(({ toString: format2 }) => format2()).join(" | ");
|
|
2487
|
-
return inline ? `(${result})` : result;
|
|
2488
|
-
});
|
|
2489
|
-
defineMethod("intersect", ["list"], ({ list }) => {
|
|
2490
|
-
return `${list.map((inner) => inner.toString(true)).join(" & ")}`;
|
|
2491
|
-
});
|
|
2492
|
-
defineMethod("transform", [
|
|
2493
|
-
"inner",
|
|
2494
|
-
"callback",
|
|
2495
|
-
"preserve"
|
|
2496
|
-
], ({ inner }, isInner) => inner.toString(isInner));
|
|
2497
|
-
|
|
2498
|
-
// src/permission-errors.ts
|
|
2499
|
-
var PermissionRefusal = class extends Error {
|
|
2500
|
-
constructor(code) {
|
|
2501
|
-
super("The Host refused the permission operation.");
|
|
2502
|
-
this.code = code;
|
|
2503
|
-
}
|
|
2504
|
-
};
|
|
2505
|
-
|
|
2506
|
-
// src/permission-rules.ts
|
|
2507
|
-
function invalid() {
|
|
2508
|
-
throw new PermissionRefusal("validation");
|
|
2509
|
-
}
|
|
2510
|
-
function permissionRuleRow(value, required, optional2 = []) {
|
|
2511
|
-
if (value === null || typeof value !== "object" || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) invalid();
|
|
2512
|
-
const fields = Object.getOwnPropertyDescriptors(value);
|
|
2513
|
-
if (Reflect.ownKeys(value).some((key) => typeof key !== "string" || !required.includes(key) && !optional2.includes(key)) || required.some((key) => !Object.hasOwn(fields, key)) || Object.values(fields).some((field) => !Object.hasOwn(field, "value") || !field.enumerable)) invalid();
|
|
2514
|
-
return value;
|
|
2515
|
-
}
|
|
2516
|
-
function text(value, max = 32768) {
|
|
2517
|
-
if (typeof value !== "string" || value.length === 0 || value.length > max || value.includes("\0")) invalid();
|
|
2518
|
-
return value;
|
|
2519
|
-
}
|
|
2520
|
-
function permissionRevision(value) {
|
|
2521
|
-
return text(value, 4096);
|
|
2522
|
-
}
|
|
2523
|
-
function integer(value) {
|
|
2524
|
-
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) invalid();
|
|
2525
|
-
return value;
|
|
2526
|
-
}
|
|
2527
|
-
function ruleAction(value, inherit = false) {
|
|
2528
|
-
if (typeof value !== "string" || !(inherit ? ["inherit", "allow", "ask", "deny"] : ["allow", "ask", "deny"]).includes(value)) invalid();
|
|
2529
|
-
return value;
|
|
2530
|
-
}
|
|
2531
|
-
function draft(value, persisted = false) {
|
|
2532
|
-
const input = permissionRuleRow(value, ["id", "action", "match", ...persisted ? ["source", "revision", "revoked"] : []]);
|
|
2533
|
-
const kind = permissionRuleRow(input.match, ["kind"], ["path", "scope", "executable", "command", "workingDirectory"]).kind;
|
|
2534
|
-
let match;
|
|
2535
|
-
if (kind === "outside-read") {
|
|
2536
|
-
const row = permissionRuleRow(input.match, ["kind", "path", "scope"]);
|
|
2537
|
-
if (row.scope !== "exact" && row.scope !== "tree") invalid();
|
|
2538
|
-
match = { kind, path: text(row.path), scope: row.scope };
|
|
2539
|
-
} else if (kind === "shell") {
|
|
2540
|
-
const row = permissionRuleRow(input.match, ["kind", "executable", "command", "workingDirectory"]);
|
|
2541
|
-
match = { kind, executable: text(row.executable), command: text(row.command), workingDirectory: text(row.workingDirectory) };
|
|
2542
|
-
} else if (kind === "webSearch" || kind === "webFetch") {
|
|
2543
|
-
permissionRuleRow(input.match, ["kind"]);
|
|
2544
|
-
match = { kind };
|
|
2545
|
-
} else invalid();
|
|
2546
|
-
return Object.freeze({ id: text(input.id, 256), action: ruleAction(input.action), match: Object.freeze(match) });
|
|
2547
|
-
}
|
|
2548
|
-
function parsePermissionRules(value) {
|
|
2549
|
-
if (!Array.isArray(value) || value.length > 1024) invalid();
|
|
2550
|
-
const ids = /* @__PURE__ */ new Set();
|
|
2551
|
-
return Object.freeze(value.map((item) => {
|
|
2552
|
-
const parsed = draft(item, true), row = item;
|
|
2553
|
-
if (ids.has(parsed.id) || typeof row.revoked !== "boolean") invalid();
|
|
2554
|
-
ids.add(parsed.id);
|
|
2555
|
-
const sourceRow = permissionRuleRow(row.source, ["kind"], ["sessionId", "savedAt", "label"]);
|
|
2556
|
-
let source;
|
|
2557
|
-
if (sourceRow.kind === "operator") {
|
|
2558
|
-
permissionRuleRow(row.source, ["kind", "sessionId", "savedAt"]);
|
|
2559
|
-
source = { kind: "operator", sessionId: text(sourceRow.sessionId, 256), savedAt: integer(sourceRow.savedAt) };
|
|
2560
|
-
} else if (sourceRow.kind === "user-import") {
|
|
2561
|
-
permissionRuleRow(row.source, ["kind", "label"]);
|
|
2562
|
-
source = { kind: "user-import", label: text(sourceRow.label, 512) };
|
|
2563
|
-
} else invalid();
|
|
2564
|
-
return Object.freeze({ ...parsed, source: Object.freeze(source), revision: integer(row.revision), revoked: row.revoked });
|
|
2565
|
-
}));
|
|
2566
|
-
}
|
|
2567
|
-
function parsePermissionRulesSave(value) {
|
|
2568
|
-
const row = permissionRuleRow(value, ["expectedRevision"], ["changes", "upsert", "revoke"]);
|
|
2569
|
-
let changes;
|
|
2570
|
-
if (row.changes !== void 0) {
|
|
2571
|
-
const input = permissionRuleRow(row.changes, [], ["outsideReads", "webSearch", "webFetch"]);
|
|
2572
|
-
const web2 = (value2) => {
|
|
2573
|
-
const row2 = permissionRuleRow(value2, ["enabled", "rule"]);
|
|
2574
|
-
if (typeof row2.enabled !== "boolean") invalid();
|
|
2575
|
-
return Object.freeze({ enabled: row2.enabled, rule: ruleAction(row2.rule, true) });
|
|
2576
|
-
};
|
|
2577
|
-
changes = Object.freeze({
|
|
2578
|
-
...input.outsideReads === void 0 ? {} : { outsideReads: ruleAction(input.outsideReads, true) },
|
|
2579
|
-
...input.webSearch === void 0 ? {} : { webSearch: web2(input.webSearch) },
|
|
2580
|
-
...input.webFetch === void 0 ? {} : { webFetch: web2(input.webFetch) }
|
|
2581
|
-
});
|
|
2582
|
-
}
|
|
2583
|
-
if (row.upsert !== void 0 && (!Array.isArray(row.upsert) || row.upsert.length > 1024) || row.revoke !== void 0 && (!Array.isArray(row.revoke) || row.revoke.length > 1024)) invalid();
|
|
2584
|
-
const upsert = row.upsert?.map((item) => draft(item)), revoke = row.revoke?.map((item) => text(item, 256));
|
|
2585
|
-
const ids = [...upsert?.map((item) => item.id) ?? [], ...revoke ?? []];
|
|
2586
|
-
if (ids.length !== new Set(ids).size || ids.length === 0 && (changes === void 0 || Object.keys(changes).length === 0)) invalid();
|
|
2587
|
-
return Object.freeze({
|
|
2588
|
-
expectedRevision: permissionRevision(row.expectedRevision),
|
|
2589
|
-
...changes === void 0 ? {} : { changes },
|
|
2590
|
-
...upsert === void 0 ? {} : { upsert: Object.freeze(upsert) },
|
|
2591
|
-
...revoke === void 0 ? {} : { revoke: Object.freeze(revoke) }
|
|
2592
|
-
});
|
|
2593
|
-
}
|
|
2594
|
-
|
|
2595
|
-
// src/permission-settings.ts
|
|
2596
|
-
function parseNativeCommandPattern(input) {
|
|
2597
|
-
if (typeof input !== "string" || input.length > 32768) throw new PermissionRefusal("validation");
|
|
2598
|
-
const tokens = input.replace(/^[ \t]+|[ \t]+$/gu, "").split(/[ \t]+/u);
|
|
2599
|
-
if (tokens.length !== 2 && (tokens.length !== 3 || tokens[2] !== "*") || tokens[0].length === 0 || /[^\p{L}\p{M}\p{N}_./:=+%\\\-]/u.test(tokens[0])) throw new PermissionRefusal("validation");
|
|
2600
|
-
const subcommands = tokens[1].split("|");
|
|
2601
|
-
if (subcommands.some((value) => value.length === 0 || /[^\p{L}\p{M}\p{N}_./:=+%\-]/u.test(value))) throw new PermissionRefusal("validation");
|
|
2602
|
-
return Object.freeze({ executable: tokens[0], subcommands: Object.freeze(subcommands) });
|
|
2603
|
-
}
|
|
2604
|
-
function parseSimpleCommandPattern(input) {
|
|
2605
|
-
if (typeof input !== "string" || input.length > 32768) throw new PermissionRefusal("validation");
|
|
2606
|
-
const tokens = input.replace(/^[ \t]+|[ \t]+$/gu, "").split(/[ \t]+/u);
|
|
2607
|
-
if (tokens.at(-1) === "*") tokens.pop();
|
|
2608
|
-
if (!tokens.length) throw new PermissionRefusal("validation");
|
|
2609
|
-
return Object.freeze(tokens.map((token, index) => {
|
|
2610
|
-
const values = index === 1 ? token.split("|") : [token];
|
|
2611
|
-
if (values.some((value) => !value.length || /[^\p{L}\p{M}\p{N}_./:=+%\\\-]/u.test(value))) throw new PermissionRefusal("validation");
|
|
2612
|
-
return Object.freeze(values);
|
|
2613
|
-
}));
|
|
2614
|
-
}
|
|
2615
|
-
function parseNativeCommands(input = {}) {
|
|
2616
|
-
const row = permissionRuleRow(input, [], ["enabled", "entries"]);
|
|
2617
|
-
if (row.enabled !== void 0 && typeof row.enabled !== "boolean" || row.entries !== void 0 && (!Array.isArray(row.entries) || row.entries.length > 1024)) throw new PermissionRefusal("validation");
|
|
2618
|
-
const text5 = (value) => {
|
|
2619
|
-
if (typeof value !== "string" || value.trim().length === 0 || value.length > 32768 || value.includes("\0")) throw new PermissionRefusal("validation");
|
|
2620
|
-
return value;
|
|
2621
|
-
};
|
|
2622
|
-
const ids = /* @__PURE__ */ new Set();
|
|
2623
|
-
const entries = (row.entries ?? []).map((value) => {
|
|
2624
|
-
if (typeof value === "string") {
|
|
2625
|
-
parseSimpleCommandPattern(value);
|
|
2626
|
-
return value;
|
|
2627
|
-
}
|
|
2628
|
-
const entry = permissionRuleRow(value, ["id", "mode", "match", "sandboxMode"]);
|
|
2629
|
-
const match = permissionRuleRow(entry.match, ["tool", "workingDirectory", "commandPattern"]);
|
|
2630
|
-
const id2 = text5(entry.id), cwd = text5(match.workingDirectory);
|
|
2631
|
-
if (ids.has(id2) || !["ask", "allow"].includes(entry.mode) || !["bash", "pwsh"].includes(match.tool) || !["workspace-write", "danger-full-access"].includes(entry.sandboxMode) || !/^(?:\/|[a-z]:[\\/]|\\\\[^\\/]+[\\/][^\\/]+(?:[\\/]|$))/iu.test(cwd)) throw new PermissionRefusal("validation");
|
|
2632
|
-
ids.add(id2);
|
|
2633
|
-
parseNativeCommandPattern(match.commandPattern);
|
|
2634
|
-
const parsed = { tool: match.tool, workingDirectory: cwd, commandPattern: match.commandPattern };
|
|
2635
|
-
return Object.freeze({ id: id2, mode: entry.mode, sandboxMode: entry.sandboxMode, match: Object.freeze(parsed) });
|
|
2636
|
-
});
|
|
2637
|
-
return Object.freeze({ enabled: row.enabled ?? false, entries: Object.freeze(entries) });
|
|
2638
|
-
}
|
|
2639
|
-
var nativeCommandMatchSchema = Schema.object({ tool: Schema.union(["bash", "pwsh"]).required(), workingDirectory: Schema.string().required(), commandPattern: Schema.string().required() }).required();
|
|
2640
|
-
var nativeCommandEntrySchema = Schema.object({
|
|
2641
|
-
id: Schema.string().required(),
|
|
2642
|
-
mode: Schema.union(["ask", "allow"]).required(),
|
|
2643
|
-
match: nativeCommandMatchSchema,
|
|
2644
|
-
sandboxMode: Schema.union(["workspace-write", "danger-full-access"]).required()
|
|
2645
|
-
}).required();
|
|
2646
|
-
var nativeCommands = Schema.object({ enabled: Schema.boolean().default(false), entries: Schema.array(Schema.union([Schema.string(), nativeCommandEntrySchema])).default([]) });
|
|
2647
|
-
var webDefault = Object.freeze({ enabled: true, rule: "inherit" });
|
|
2648
|
-
var DEFAULT_PERMISSION_CONTROL = Object.freeze({ enabled: true, outsideReads: "inherit", webSearch: webDefault, webFetch: webDefault, rules: Object.freeze([]), nativeCommands: parseNativeCommands() });
|
|
2649
|
-
var action = () => Schema.union(["inherit", "allow", "ask", "deny"]).default("inherit");
|
|
2650
|
-
var web = () => Schema.object({ enabled: Schema.boolean().default(true), rule: action() }).default({});
|
|
2651
|
-
var permissionControlSchema = Schema.transform(Schema.object({
|
|
2652
|
-
enabled: Schema.boolean().default(true),
|
|
2653
|
-
outsideReads: action(),
|
|
2654
|
-
webSearch: web(),
|
|
2655
|
-
webFetch: web(),
|
|
2656
|
-
nativeCommands,
|
|
2657
|
-
rules: Schema.array(Schema.any()).default([])
|
|
2658
|
-
}), (input) => Object.freeze({ ...input, webSearch: Object.freeze(input.webSearch), webFetch: Object.freeze(input.webFetch), rules: parsePermissionRules(input.rules), nativeCommands: parseNativeCommands(input.nativeCommands) }), true);
|
|
2659
|
-
function resolvePermissionControl(input = {}) {
|
|
2660
|
-
permissionRuleRow(input, [], ["enabled", "outsideReads", "webSearch", "webFetch", "rules", "nativeCommands"]);
|
|
2661
|
-
if (Object.hasOwn(input, "nativeCommands")) parseNativeCommands(input.nativeCommands);
|
|
2662
|
-
for (const web2 of [input.webSearch, input.webFetch]) if (web2 !== void 0) permissionRuleRow(web2, [], ["enabled", "rule"]);
|
|
2663
|
-
const parsed = permissionControlSchema(input);
|
|
2664
|
-
return Object.freeze({ ...parsed, webSearch: Object.freeze(parsed.webSearch), webFetch: Object.freeze(parsed.webFetch), rules: parsePermissionRules(parsed.rules) });
|
|
2665
|
-
}
|
|
2666
|
-
|
|
2667
1632
|
// src/profile-diagnostics.ts
|
|
2668
1633
|
var PROFILE_DIAGNOSTIC_REASONS = {
|
|
2669
1634
|
"invalid-jsonc": "Use one valid document with supported JSON syntax.",
|
|
@@ -2678,19 +1643,13 @@ var PROFILE_DIAGNOSTIC_REASONS = {
|
|
|
2678
1643
|
"deployment-ceiling": "A named profile cannot enable capabilities outside its captured deployment ceiling.",
|
|
2679
1644
|
"blank-label": "The label is blank; the profile ID is used for display."
|
|
2680
1645
|
};
|
|
2681
|
-
function schemaFieldShape(schema) {
|
|
2682
|
-
if (schema.type === "transform") return schemaFieldShape(schema.inner);
|
|
2683
|
-
if (schema.type === "object") return Object.fromEntries(Object.entries(schema.dict ?? {}).map(([key, child2]) => [key, schemaFieldShape(child2)]));
|
|
2684
|
-
if (schema.type === "array") return [schemaFieldShape(schema.inner)];
|
|
2685
|
-
return null;
|
|
2686
|
-
}
|
|
2687
1646
|
var roleId = /^dsmm-(?:orchestrator|planner|plan-critic|builder|reviewer|oracle|oracle-2nd|creative|code-search|doc-search|clarifier|media-reader|frontend|hard-reasoning|research|quick|coding|normal-task|complex|deep|documenting|cross-cutting)$/u;
|
|
2688
1647
|
var skillId = /^(?:brainstorming|writing-plans|requesting-code-review|receiving-code-review|subagent-driven-development|dispatching-parallel-agents|avoid-ai-slop|remove-ai-slops|debugging|frontend|git-master|ast-grep|coding-agent-sessions|init-deep|using-git-worktrees|report-fidelity)$/u;
|
|
2689
1648
|
var route = { provider: null, model: null, reasoningEffort: null };
|
|
2690
1649
|
var rateLimit = Object.fromEntries(Object.keys(DSMM_RATE_LIMIT_BOUNDS).map((key) => [key, null]));
|
|
2691
1650
|
var roleRouting = { primary: route, fallbackRoutes: [route], strategy: null, rateLimit, levels: { low: route, high: route, max: route } };
|
|
2692
1651
|
var configFields = {
|
|
2693
|
-
permissionControl:
|
|
1652
|
+
permissionControl: { enabled: null, outsideReads: null, webSearch: { enabled: null, rule: null }, webFetch: { enabled: null, rule: null }, rules: [null], nativeCommands: { enabled: null, entries: [null] } },
|
|
2694
1653
|
modelParameters: { passthrough: null },
|
|
2695
1654
|
rootModelPolicy: null,
|
|
2696
1655
|
locale: null,
|
|
@@ -2776,12 +1735,12 @@ function inspectJsonDocument(content2, jsonc = true) {
|
|
|
2776
1735
|
}
|
|
2777
1736
|
if (node.type === "object") {
|
|
2778
1737
|
const found = /* @__PURE__ */ new Set();
|
|
2779
|
-
for (const
|
|
2780
|
-
const keyNode =
|
|
1738
|
+
for (const property of node.children ?? []) {
|
|
1739
|
+
const keyNode = property.children[0], key = String(keyNode.value), next = [...path, key];
|
|
2781
1740
|
const code = ["__proto__", "constructor", "prototype"].includes(key) ? "unsafe-field" : found.has(key) ? "duplicate-field" : void 0;
|
|
2782
1741
|
if (code !== void 0) diagnostics.push(diagnostic(code, safeDiagnosticField(next), diagnosticLocation(content2, keyNode.offset, keyNode.length)));
|
|
2783
1742
|
found.add(key);
|
|
2784
|
-
walk(
|
|
1743
|
+
walk(property.children[1], next, depth2 + 1);
|
|
2785
1744
|
}
|
|
2786
1745
|
} else if (node.type === "array") (node.children ?? []).forEach((child2, index) => walk(child2, [...path, index], depth2 + 1));
|
|
2787
1746
|
};
|
|
@@ -2808,17 +1767,17 @@ function isProfileId(value) {
|
|
|
2808
1767
|
function fail2(field) {
|
|
2809
1768
|
throw new TypeError(`Invalid Deepwork profile wire field: ${field}`);
|
|
2810
1769
|
}
|
|
2811
|
-
function
|
|
1770
|
+
function text(value, field, maximum = 1024) {
|
|
2812
1771
|
if (typeof value !== "string" || value.length > maximum) fail2(field);
|
|
2813
1772
|
return value;
|
|
2814
1773
|
}
|
|
2815
1774
|
function id(value) {
|
|
2816
|
-
const result =
|
|
1775
|
+
const result = text(value, "id", 64);
|
|
2817
1776
|
if (!isProfileId(result)) fail2("id");
|
|
2818
1777
|
return result;
|
|
2819
1778
|
}
|
|
2820
1779
|
function revision(value) {
|
|
2821
|
-
const result =
|
|
1780
|
+
const result = text(value, "revision", 128);
|
|
2822
1781
|
if (!isConfigRevision(result)) fail2("revision");
|
|
2823
1782
|
return result;
|
|
2824
1783
|
}
|
|
@@ -2855,7 +1814,7 @@ function boolean(value, field) {
|
|
|
2855
1814
|
if (typeof value !== "boolean") fail2(field);
|
|
2856
1815
|
return value;
|
|
2857
1816
|
}
|
|
2858
|
-
function
|
|
1817
|
+
function integer(value, field, maximum = Number.MAX_SAFE_INTEGER) {
|
|
2859
1818
|
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0 || value > maximum) fail2(field);
|
|
2860
1819
|
return value;
|
|
2861
1820
|
}
|
|
@@ -2863,10 +1822,10 @@ function parseDsmmRoleId(value) {
|
|
|
2863
1822
|
if (typeof value !== "string" || !rolePattern.test(value)) fail2("role");
|
|
2864
1823
|
return value;
|
|
2865
1824
|
}
|
|
2866
|
-
var
|
|
1825
|
+
var role = parseDsmmRoleId;
|
|
2867
1826
|
function object(value, required, optional2 = []) {
|
|
2868
1827
|
if (value === null || typeof value !== "object" || Array.isArray(value)) fail2("object");
|
|
2869
|
-
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null || Object.getOwnPropertySymbols(value).length || Object.values(Object.getOwnPropertyDescriptors(value)).some((
|
|
1828
|
+
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null || Object.getOwnPropertySymbols(value).length || Object.values(Object.getOwnPropertyDescriptors(value)).some((property) => !Object.hasOwn(property, "value") || !property.enumerable)) fail2("object");
|
|
2870
1829
|
const result = value;
|
|
2871
1830
|
if (Object.keys(result).some((key) => !required.includes(key) && !optional2.includes(key)) || required.some((key) => !Object.hasOwn(result, key))) fail2("object keys");
|
|
2872
1831
|
return result;
|
|
@@ -2876,14 +1835,14 @@ function optional(value, key, parse3) {
|
|
|
2876
1835
|
}
|
|
2877
1836
|
function parseProfileErrorInfo(value) {
|
|
2878
1837
|
const item = object(value, ["code", "message"], ["field", "reason", "location"]);
|
|
2879
|
-
const code =
|
|
1838
|
+
const code = text(item.code, "code");
|
|
2880
1839
|
if (!errorCodes.has(code)) fail2("code");
|
|
2881
|
-
const reason = item.reason === void 0 ? void 0 :
|
|
1840
|
+
const reason = item.reason === void 0 ? void 0 : text(item.reason, "reason", 64);
|
|
2882
1841
|
if (reason !== void 0 && (!Object.hasOwn(PROFILE_DIAGNOSTIC_REASONS, reason) || reason === "blank-label")) fail2("reason");
|
|
2883
1842
|
const field = item.field === void 0 ? void 0 : diagnosticField(item.field);
|
|
2884
1843
|
return {
|
|
2885
1844
|
code,
|
|
2886
|
-
message: reason === void 0 ?
|
|
1845
|
+
message: reason === void 0 ? text(item.message, "message", 4096) : `${field ?? "document"}: ${diagnostic(reason, field ?? "document").reason}`,
|
|
2887
1846
|
...field === void 0 ? {} : { field },
|
|
2888
1847
|
...reason === void 0 ? {} : { reason },
|
|
2889
1848
|
...optional(item, "location", diagnosticPosition)
|
|
@@ -2896,7 +1855,7 @@ function diagnosticField(value) {
|
|
|
2896
1855
|
}
|
|
2897
1856
|
function diagnosticPosition(value) {
|
|
2898
1857
|
const item = object(value, ["offset", "length", "line", "column"]);
|
|
2899
|
-
const result = { offset:
|
|
1858
|
+
const result = { offset: integer(item.offset, "offset", 128 * 1024), length: integer(item.length, "length", 128 * 1024), line: integer(item.line, "line", 128 * 1024 + 1), column: integer(item.column, "column", 128 * 1024 + 1) };
|
|
2900
1859
|
if (result.line < 1 || result.column < 1 || result.offset + result.length > 128 * 1024) fail2("location");
|
|
2901
1860
|
return result;
|
|
2902
1861
|
}
|
|
@@ -2921,7 +1880,7 @@ function parseRoleAvailability(value) {
|
|
|
2921
1880
|
if (row.reason !== void 0 && (typeof row.reason !== "string" || !["module-off", "deployment-disabled", "startup-unavailable", "profile-disabled", "required-role", "current-root-disabled"].includes(row.reason))) fail2("role reason");
|
|
2922
1881
|
if (row.requiredReason !== void 0 && (typeof row.requiredReason !== "string" || !["deepwork-planning", "legacy-review"].includes(row.requiredReason))) fail2("requiredReason");
|
|
2923
1882
|
return {
|
|
2924
|
-
id:
|
|
1883
|
+
id: role(row.id),
|
|
2925
1884
|
required: boolean(row.required, "required"),
|
|
2926
1885
|
startupAvailable: boolean(row.startupAvailable, "startupAvailable"),
|
|
2927
1886
|
deploymentEnabled: boolean(row.deploymentEnabled, "deploymentEnabled"),
|
|
@@ -2936,7 +1895,7 @@ function parseRoleAvailability(value) {
|
|
|
2936
1895
|
function roleAvailabilityList(value) {
|
|
2937
1896
|
if (!Array.isArray(value) || value.length > 22) fail2("roles");
|
|
2938
1897
|
const result = value.map(parseRoleAvailability);
|
|
2939
|
-
if (new Set(result.map((
|
|
1898
|
+
if (new Set(result.map((role2) => role2.id)).size !== result.length) fail2("roles");
|
|
2940
1899
|
return result;
|
|
2941
1900
|
}
|
|
2942
1901
|
function parseSubagentRuntimeAdmissionView(value) {
|
|
@@ -2948,20 +1907,20 @@ function parseSubagentRuntimeAdmissionView(value) {
|
|
|
2948
1907
|
}
|
|
2949
1908
|
function readResult(value) {
|
|
2950
1909
|
const item = object(value, ["id", "revision", "content"], ["label", "warnings", "refreshRequired"]);
|
|
2951
|
-
return { id: id(item.id), revision: item.revision === "unavailable" && item.refreshRequired === true ? "unavailable" : revision(item.revision), content: content(item.content), ...optional(item, "refreshRequired", refresh), ...optional(item, "label", (input) =>
|
|
1910
|
+
return { id: id(item.id), revision: item.revision === "unavailable" && item.refreshRequired === true ? "unavailable" : revision(item.revision), content: content(item.content), ...optional(item, "refreshRequired", refresh), ...optional(item, "label", (input) => text(input, "label", 120)), ...optional(item, "warnings", warnings) };
|
|
2952
1911
|
}
|
|
2953
1912
|
function content(value) {
|
|
2954
|
-
const result =
|
|
1913
|
+
const result = text(value, "content", 128 * 1024);
|
|
2955
1914
|
if (new TextEncoder().encode(result).byteLength > 128 * 1024) fail2("content");
|
|
2956
1915
|
return result;
|
|
2957
1916
|
}
|
|
2958
|
-
function
|
|
1917
|
+
function snapshot(value) {
|
|
2959
1918
|
const item = object(value, ["profiles", "selectedId", "appliedRevision", "selectionRevision"], ["selectionError", "roles", "editorDefaults", "origin", "readOnly", "writeRestriction", "selectedWarnings", "sourceRevision", "refreshRequired"]);
|
|
2960
1919
|
if (!Array.isArray(item.profiles) || item.profiles.length > 128) fail2("profiles");
|
|
2961
1920
|
return {
|
|
2962
1921
|
profiles: item.profiles.map((input) => {
|
|
2963
1922
|
const row = object(input, ["id", "revision"], ["label", "error", "warnings"]);
|
|
2964
|
-
return { id:
|
|
1923
|
+
return { id: text(row.id, "id", 64), revision: row.revision === null ? null : revision(row.revision), ...optional(row, "label", (input2) => text(input2, "label", 120)), ...optional(row, "error", errorInfo), ...optional(row, "warnings", warnings) };
|
|
2965
1924
|
}),
|
|
2966
1925
|
selectedId: item.selectedId === null ? null : id(item.selectedId),
|
|
2967
1926
|
appliedRevision: item.appliedRevision === null ? null : reference(item.appliedRevision),
|
|
@@ -2974,7 +1933,7 @@ function snapshot2(value) {
|
|
|
2974
1933
|
if (!Array.isArray(input) || input.length > 22) fail2("roles");
|
|
2975
1934
|
const result = input.map((value2) => {
|
|
2976
1935
|
const row = object(value2, ["id", "label", "enabled"], ["runtimePolicy", "availability"]);
|
|
2977
|
-
return { id:
|
|
1936
|
+
return { id: role(row.id), label: text(row.label, "label", 120), enabled: boolean(row.enabled, "enabled"), ...optional(row, "availability", parseRoleAvailability), ...optional(row, "runtimePolicy", (input2) => {
|
|
2978
1937
|
const policy = object(input2, [], ["strategy", "rateLimit"]);
|
|
2979
1938
|
return { ...optional(policy, "strategy", normalizeRoutingStrategy), ...optional(policy, "rateLimit", normalizeRateLimitOverrides) };
|
|
2980
1939
|
}) };
|
|
@@ -2988,7 +1947,7 @@ function snapshot2(value) {
|
|
|
2988
1947
|
return input;
|
|
2989
1948
|
}),
|
|
2990
1949
|
...optional(item, "readOnly", (input) => boolean(input, "readOnly")),
|
|
2991
|
-
...optional(item, "writeRestriction", (input) =>
|
|
1950
|
+
...optional(item, "writeRestriction", (input) => text(input, "writeRestriction", 1024))
|
|
2992
1951
|
};
|
|
2993
1952
|
}
|
|
2994
1953
|
function rateLimit2(value) {
|
|
@@ -3003,11 +1962,11 @@ function rolePolicy(value) {
|
|
|
3003
1962
|
const item = object(value, ["strategy", "rateLimit", "retries", "rateLimitFailures", "switches", "totalDelayMs"], ["role", "route"]);
|
|
3004
1963
|
return {
|
|
3005
1964
|
...runtimePolicy({ strategy: item.strategy, rateLimit: item.rateLimit }),
|
|
3006
|
-
retries:
|
|
3007
|
-
rateLimitFailures:
|
|
3008
|
-
switches:
|
|
3009
|
-
totalDelayMs:
|
|
3010
|
-
...optional(item, "role",
|
|
1965
|
+
retries: integer(item.retries, "retries", 10),
|
|
1966
|
+
rateLimitFailures: integer(item.rateLimitFailures, "rateLimitFailures"),
|
|
1967
|
+
switches: integer(item.switches, "switches", 10),
|
|
1968
|
+
totalDelayMs: integer(item.totalDelayMs, "totalDelayMs", 12e4),
|
|
1969
|
+
...optional(item, "role", role),
|
|
3011
1970
|
...optional(item, "route", modelRoute)
|
|
3012
1971
|
};
|
|
3013
1972
|
}
|
|
@@ -3044,13 +2003,13 @@ function parseDsmmInvocationView(value) {
|
|
|
3044
2003
|
const row = object(jsonData(value), ["role", "label", "level", "routeSource", "mode"], ["route", "runId", "childId", "jobId", "routeComparison", "delivery", "phase", "stopReason"]);
|
|
3045
2004
|
if (typeof row.level !== "string" || !["normal", "low", "high", "max"].includes(row.level) || !DSMM_ROUTE_SOURCES.includes(row.routeSource) || typeof row.mode !== "string" || !["one-shot", "continuable"].includes(row.mode)) fail2("invocation");
|
|
3046
2005
|
if (Object.hasOwn(row, "delivery") && !["caller", "parent"].includes(row.delivery) || Object.hasOwn(row, "phase") && !["reserved", "active", "settled"].includes(row.phase) || Object.hasOwn(row, "stopReason") && !["completed", "aborted", "error", "max-tokens", "refusal"].includes(row.stopReason) || Object.hasOwn(row, "stopReason") && row.phase !== "settled") fail2("invocation lifecycle");
|
|
3047
|
-
const target =
|
|
2006
|
+
const target = role(row.role);
|
|
3048
2007
|
if (target === "dsmm-orchestrator") fail2("invocation target");
|
|
3049
2008
|
const routeComparison = Object.hasOwn(row, "routeComparison") ? parseDsmmRoleRouteComparison(row.routeComparison) : void 0;
|
|
3050
2009
|
if (routeComparison !== void 0 && (!Object.hasOwn(row, "childId") || routeComparison.childId !== row.childId)) fail2("invocation routeComparison childId");
|
|
3051
2010
|
return {
|
|
3052
2011
|
role: target,
|
|
3053
|
-
label:
|
|
2012
|
+
label: text(row.label, "label", 120),
|
|
3054
2013
|
level: row.level,
|
|
3055
2014
|
routeSource: row.routeSource,
|
|
3056
2015
|
mode: row.mode,
|
|
@@ -3141,9 +2100,9 @@ function jsonData(value, depth2 = 0, active = /* @__PURE__ */ new Set()) {
|
|
|
3141
2100
|
if (Array.isArray(value) ? Object.getPrototypeOf(value) !== Array.prototype : Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) fail2("JSON object");
|
|
3142
2101
|
if (Object.getOwnPropertySymbols(value).length) fail2("JSON symbols");
|
|
3143
2102
|
const properties = Object.getOwnPropertyDescriptors(value);
|
|
3144
|
-
for (const [key,
|
|
2103
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
3145
2104
|
if (Array.isArray(value) && key === "length") continue;
|
|
3146
|
-
if (!Object.hasOwn(
|
|
2105
|
+
if (!Object.hasOwn(property, "value") || !property.enumerable || Array.isArray(value) && !/^(0|[1-9][0-9]*)$/u.test(key)) fail2("JSON property");
|
|
3147
2106
|
}
|
|
3148
2107
|
if (Array.isArray(value) && Object.keys(value).length !== value.length) fail2("JSON array holes");
|
|
3149
2108
|
active.add(value);
|
|
@@ -3166,7 +2125,7 @@ function admissionView(value) {
|
|
|
3166
2125
|
const map = object(row[key], [], Object.keys(row[key]));
|
|
3167
2126
|
for (const [path, value2] of Object.entries(map)) {
|
|
3168
2127
|
if (path.startsWith("lsp.env.")) fail2("private environment field");
|
|
3169
|
-
|
|
2128
|
+
text(value2, key, 128);
|
|
3170
2129
|
}
|
|
3171
2130
|
}
|
|
3172
2131
|
if (!Array.isArray(row.restartRequired) || row.restartRequired.length > 256) fail2("restartRequired");
|
|
@@ -3176,7 +2135,7 @@ function admissionView(value) {
|
|
|
3176
2135
|
settings: readOnlySettingsData(row.settings),
|
|
3177
2136
|
sources: jsonData(row.sources),
|
|
3178
2137
|
captures: jsonData(row.captures),
|
|
3179
|
-
restartRequired: row.restartRequired.map((value2) =>
|
|
2138
|
+
restartRequired: row.restartRequired.map((value2) => text(value2, "field", 256)),
|
|
3180
2139
|
named: named === null ? null : { id: id(named.id), revision: reference(named.revision) }
|
|
3181
2140
|
};
|
|
3182
2141
|
}
|
|
@@ -3207,12 +2166,12 @@ function readOnlySettingsData(value) {
|
|
|
3207
2166
|
function editorSnapshot(value) {
|
|
3208
2167
|
const row = object(value, ["entryId", "namespace", "hostProfileKey", "global", "globalRevision", "profile", "nativeRevision", "nativeFormRevision", "nativeForm", "desired", "sources", "startup", "defaults", "schema", "nextRoot", "modules"], ["startupSources", "nativeSchema", "subagentRuntime"]);
|
|
3209
2168
|
const result = jsonData(row);
|
|
3210
|
-
|
|
3211
|
-
if (row.namespace !== null)
|
|
2169
|
+
text(row.entryId, "entryId", 256);
|
|
2170
|
+
if (row.namespace !== null) text(row.namespace, "namespace", 256);
|
|
3212
2171
|
epoch(row.hostProfileKey);
|
|
3213
2172
|
selectionRevision(row.globalRevision);
|
|
3214
2173
|
if (row.nativeRevision !== "unavailable" && (typeof row.nativeRevision !== "string" || !/^native-v1-\d+$/u.test(row.nativeRevision))) fail2("nativeRevision");
|
|
3215
|
-
if (row.nativeFormRevision !== null)
|
|
2174
|
+
if (row.nativeFormRevision !== null) integer(row.nativeFormRevision, "nativeFormRevision");
|
|
3216
2175
|
for (const key of ["global", "profile", "desired", "sources", "startup", "defaults", "schema"]) object(row[key], [], Object.keys(row[key]));
|
|
3217
2176
|
if (row.nativeForm !== null) object(row.nativeForm, ["base", "user"]);
|
|
3218
2177
|
if (row.nextRoot !== null) result.nextRoot = admissionView(row.nextRoot);
|
|
@@ -3226,7 +2185,7 @@ function editorSnapshot(value) {
|
|
|
3226
2185
|
object(map, [], Object.keys(map));
|
|
3227
2186
|
for (const [path, value2] of Object.entries(map)) {
|
|
3228
2187
|
if (path.startsWith("lsp.env.")) fail2("private environment field");
|
|
3229
|
-
|
|
2188
|
+
text(value2, "source", 128);
|
|
3230
2189
|
}
|
|
3231
2190
|
}
|
|
3232
2191
|
result.modules = moduleStates(row.modules);
|
|
@@ -3261,7 +2220,7 @@ function schemaNode(value) {
|
|
|
3261
2220
|
}
|
|
3262
2221
|
if (row.keys !== void 0) {
|
|
3263
2222
|
if (row.type !== "dict" || !Array.isArray(row.keys) || row.keys.length > 64) fail2("schema keys");
|
|
3264
|
-
node.keys = row.keys.map((key) =>
|
|
2223
|
+
node.keys = row.keys.map((key) => text(key, "schema key", 128));
|
|
3265
2224
|
}
|
|
3266
2225
|
return node;
|
|
3267
2226
|
}
|
|
@@ -3272,7 +2231,7 @@ function globalSaveRequest(value) {
|
|
|
3272
2231
|
const edit = object(value2, ["op", "path"], ["value"]);
|
|
3273
2232
|
if (!Array.isArray(edit.path) || edit.path.length < 1 || edit.path.length > 8) fail2("field path");
|
|
3274
2233
|
const path = edit.path.map((part) => {
|
|
3275
|
-
const key =
|
|
2234
|
+
const key = text(part, "field", 128);
|
|
3276
2235
|
if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/u.test(key) || ["constructor", "prototype", "__proto__"].includes(key)) fail2("field");
|
|
3277
2236
|
return key;
|
|
3278
2237
|
});
|
|
@@ -3329,10 +2288,10 @@ var TYPERT_REMOTE = {
|
|
|
3329
2288
|
{ name: "request", wire: "request", source: "json", codec: codec("SessionModeSelectRequest", modeSelectRequest) }
|
|
3330
2289
|
]
|
|
3331
2290
|
},
|
|
3332
|
-
descriptor("describe", codec("ProfileSnapshot",
|
|
2291
|
+
descriptor("describe", codec("ProfileSnapshot", snapshot)),
|
|
3333
2292
|
descriptor("read", codec("ProfileReadResult", readResult), { name: "id", codec: codec("ProfileId", id) }),
|
|
3334
2293
|
descriptor("save", codec("ProfileReadResult", readResult), { name: "request", codec: codec("ProfileSaveRequest", saveRequest) }),
|
|
3335
|
-
descriptor("select", codec("ProfileSnapshot",
|
|
2294
|
+
descriptor("select", codec("ProfileSnapshot", snapshot), { name: "request", codec: codec("ProfileSelectRequest", selectRequest) }),
|
|
3336
2295
|
{
|
|
3337
2296
|
...descriptor("describeSession", codec("SessionProfileSnapshot", sessionSnapshot)),
|
|
3338
2297
|
parameters: [{ name: "sessionId", wire: "sessionId", source: "json", codec: codec("NativeSessionId", sessionId) }]
|
|
@@ -3459,8 +2418,8 @@ function validTree(node, depth2 = 0) {
|
|
|
3459
2418
|
if (depth2 > 32) return false;
|
|
3460
2419
|
if (node.type === "object") {
|
|
3461
2420
|
const seen = /* @__PURE__ */ new Set();
|
|
3462
|
-
for (const
|
|
3463
|
-
const key =
|
|
2421
|
+
for (const property of node.children ?? []) {
|
|
2422
|
+
const key = property.children?.[0]?.value;
|
|
3464
2423
|
if (typeof key !== "string" || seen.has(key) || ["__proto__", "prototype", "constructor"].includes(key)) return false;
|
|
3465
2424
|
seen.add(key);
|
|
3466
2425
|
}
|
|
@@ -3498,9 +2457,9 @@ function structuredDocument(content2) {
|
|
|
3498
2457
|
if (Object.keys(runtimePolicy2).some((key) => key !== "strategy" && key !== "rateLimit")) return null;
|
|
3499
2458
|
if (runtimePolicy2.strategy !== void 0) normalizeRoutingStrategy(runtimePolicy2.strategy);
|
|
3500
2459
|
if (runtimePolicy2.rateLimit !== void 0) normalizeRateLimitOverrides(runtimePolicy2.rateLimit);
|
|
3501
|
-
for (const [
|
|
2460
|
+
for (const [role2, raw] of Object.entries(policies)) {
|
|
3502
2461
|
if (!record(raw) || Object.keys(raw).some((key) => !["primary", "fallbackRoutes", "strategy", "rateLimit", "levels"].includes(key))) return null;
|
|
3503
|
-
if (raw.levels !== void 0 && (
|
|
2462
|
+
if (raw.levels !== void 0 && (role2 === "dsmm-orchestrator" || !record(raw.levels) || Object.entries(raw.levels).some(([key, value]) => !["low", "high", "max"].includes(key) || !level(value)))) return null;
|
|
3504
2463
|
if (raw.primary !== void 0 && !route2(raw.primary)) return null;
|
|
3505
2464
|
if (raw.fallbackRoutes !== void 0 && (!Array.isArray(raw.fallbackRoutes) || raw.fallbackRoutes.length > 32 || !raw.fallbackRoutes.every(route2))) return null;
|
|
3506
2465
|
if (raw.strategy !== void 0) normalizeRoutingStrategy(raw.strategy);
|
|
@@ -3519,17 +2478,17 @@ function editStructuredPath(content2, path, value) {
|
|
|
3519
2478
|
return null;
|
|
3520
2479
|
}
|
|
3521
2480
|
}
|
|
3522
|
-
function moveFallback(content2,
|
|
2481
|
+
function moveFallback(content2, role2, from, to) {
|
|
3523
2482
|
const document2 = structuredDocument(content2);
|
|
3524
|
-
const chain = document2?.roleRouting[
|
|
3525
|
-
if (chain === void 0 ||
|
|
3526
|
-
const low = Math.min(
|
|
2483
|
+
const chain = document2?.roleRouting[role2]?.fallbackRoutes;
|
|
2484
|
+
if (chain === void 0 || from < 0 || from >= chain.length || to < 0 || to >= chain.length) return null;
|
|
2485
|
+
const low = Math.min(from, to), high = Math.max(from, to);
|
|
3527
2486
|
const tree = parseTree2(content2);
|
|
3528
2487
|
if (tree === void 0) return null;
|
|
3529
|
-
const nodes = chain.map((_, index) => findNodeAtLocation2(tree, ["settings", "roleRouting",
|
|
2488
|
+
const nodes = chain.map((_, index) => findNodeAtLocation2(tree, ["settings", "roleRouting", role2, "fallbackRoutes", index]));
|
|
3530
2489
|
if (nodes.some((node) => node === void 0)) return null;
|
|
3531
2490
|
const order = nodes.map((node) => content2.slice(node.offset, node.offset + node.length));
|
|
3532
|
-
order.splice(to, 0, order.splice(
|
|
2491
|
+
order.splice(to, 0, order.splice(from, 1)[0]);
|
|
3533
2492
|
return applyEdits(content2, nodes.slice(low, high + 1).map((node, offset) => ({ offset: node.offset, length: node.length, content: order[low + offset] })));
|
|
3534
2493
|
}
|
|
3535
2494
|
|
|
@@ -3546,8 +2505,8 @@ function modeIntentWatermark(window2) {
|
|
|
3546
2505
|
}
|
|
3547
2506
|
var NEW_EDITOR = "";
|
|
3548
2507
|
var NEW_PROFILE_CONTENT = '{\n "version": 1,\n "id": "new-profile",\n "label": "New profile",\n "settings": {\n // Runtime overlay only. Omitted fields inherit the deployment baseline.\n "defaultActive": true\n }\n}\n';
|
|
3549
|
-
function canReconcileSelection(
|
|
3550
|
-
return
|
|
2508
|
+
function canReconcileSelection(snapshot3) {
|
|
2509
|
+
return snapshot3 !== null && !snapshot3.refreshRequired && writableSelectionVersion(snapshot3.selectionRevision) && (snapshot3.selectionError === void 0 || snapshot3.selectionError.code === "conflict");
|
|
3551
2510
|
}
|
|
3552
2511
|
var ProfilesController = class {
|
|
3553
2512
|
constructor(remote) {
|
|
@@ -3650,7 +2609,7 @@ var ProfilesController = class {
|
|
|
3650
2609
|
discardAndOpen: () => this.discardAndOpen(),
|
|
3651
2610
|
cancelDiscard: () => this.publish({ pendingEditor: null }),
|
|
3652
2611
|
editPath: (path, value) => this.editPath(path, value),
|
|
3653
|
-
moveFallback: (
|
|
2612
|
+
moveFallback: (role2, from, to) => this.editFallbackOrder(role2, from, to),
|
|
3654
2613
|
editRoute: (path, provider, model) => this.editRoute(path, provider, model),
|
|
3655
2614
|
refreshCatalog: () => this.refreshCatalog(),
|
|
3656
2615
|
refreshSession: () => this.refreshSession(),
|
|
@@ -3801,15 +2760,15 @@ var ProfilesController = class {
|
|
|
3801
2760
|
}
|
|
3802
2761
|
}
|
|
3803
2762
|
async prepareSession(refreshOnly = false) {
|
|
3804
|
-
const { sessionWorkspaceId: workspaceId, sessionChoice: selectedId, snapshot:
|
|
2763
|
+
const { sessionWorkspaceId: workspaceId, sessionChoice: selectedId, snapshot: snapshot3 } = this.current;
|
|
3805
2764
|
const native = this.blankNative;
|
|
3806
|
-
if (this.disposed || !this.connectionCurrent() || native === null || this.composerBlocks === null || this.composerReason === null || this.current.currentSessionId !== null || this.current.sessionBusy !== null || this.current.busy !== null || this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null ||
|
|
2765
|
+
if (this.disposed || !this.connectionCurrent() || native === null || this.composerBlocks === null || this.composerReason === null || this.current.currentSessionId !== null || this.current.sessionBusy !== null || this.current.busy !== null || this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null || snapshot3 === null) return;
|
|
3807
2766
|
if (workspaceId === null) {
|
|
3808
2767
|
if (!refreshOnly) this.publish({ sessionPreparationPending: true });
|
|
3809
2768
|
return;
|
|
3810
2769
|
}
|
|
3811
2770
|
if (this.current.sessionUnconfirmed && !refreshOnly) return;
|
|
3812
|
-
const profile =
|
|
2771
|
+
const profile = snapshot3.profiles.find((item) => item.id === selectedId), revision2 = selectedId === null ? null : profile?.revision;
|
|
3813
2772
|
if (!refreshOnly && selectedId !== null && (!isConfigRevision(revision2) || profile?.error !== void 0)) return;
|
|
3814
2773
|
let task = this.preparation;
|
|
3815
2774
|
const openOnly = !refreshOnly && task?.confirmed === true && task.selectedId === selectedId && task.revision === (revision2 ?? null);
|
|
@@ -4205,14 +3164,14 @@ var ProfilesController = class {
|
|
|
4205
3164
|
}
|
|
4206
3165
|
}
|
|
4207
3166
|
async selectSession(reset, options, modelOnly = false) {
|
|
4208
|
-
const { currentSessionId: id2, session, sessionChoice, snapshot:
|
|
3167
|
+
const { currentSessionId: id2, session, sessionChoice, snapshot: snapshot3 } = this.current;
|
|
4209
3168
|
if (id2 === null && !reset && !modelOnly && options?.useProfileModel !== true) {
|
|
4210
3169
|
await this.prepareSession();
|
|
4211
3170
|
return;
|
|
4212
3171
|
}
|
|
4213
3172
|
if (this.disposed || !this.connectionCurrent() || this.current.sessionUnconfirmed || id2 === null || session === null || session.refreshRequired || session.selection.refreshRequired || !writableSelectionVersion(session.selection.selectionRevision) || (modelOnly ? session.canSelectModel !== true : session.canApplyOverlay !== true || session.applyOverlayUnavailableReason === "new-session-required") || this.current.sessionBusy !== null || this.current.busy !== null || this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null) return;
|
|
4214
3173
|
const selectedId = reset ? null : sessionChoice;
|
|
4215
|
-
const profile =
|
|
3174
|
+
const profile = snapshot3?.profiles.find((profile2) => profile2.id === selectedId), revision2 = profile?.revision;
|
|
4216
3175
|
if (!modelOnly && selectedId !== null && (!isConfigRevision(revision2) || profile?.error !== void 0)) return;
|
|
4217
3176
|
const generation = ++this.sessionGeneration;
|
|
4218
3177
|
const useProfileModel = !reset && options?.useProfileModel === true;
|
|
@@ -4348,8 +3307,8 @@ var ProfilesController = class {
|
|
|
4348
3307
|
async refresh() {
|
|
4349
3308
|
const session = this.refreshSession();
|
|
4350
3309
|
await Promise.all([session, this.perform("refresh", async (live) => {
|
|
4351
|
-
const
|
|
4352
|
-
if (live()) this.publish({ snapshot:
|
|
3310
|
+
const snapshot3 = await this.unwrap(this.remote.describe());
|
|
3311
|
+
if (live()) this.publish({ snapshot: snapshot3 });
|
|
4353
3312
|
})]);
|
|
4354
3313
|
}
|
|
4355
3314
|
async open(id2) {
|
|
@@ -4411,8 +3370,8 @@ var ProfilesController = class {
|
|
|
4411
3370
|
let invalidFields = this.current.invalidFields;
|
|
4412
3371
|
if (document2 !== null) {
|
|
4413
3372
|
invalidFields = invalidFields.filter((field) => !/^settings\.roleRouting\..+\.(?:primary|fallbackRoutes\.\d+|levels\.(?:low|high|max))\.(?:provider|model)$/.test(field));
|
|
4414
|
-
for (const [
|
|
4415
|
-
const prefix = `settings.roleRouting.${
|
|
3373
|
+
for (const [role2, policy] of Object.entries(document2.roleRouting)) {
|
|
3374
|
+
const prefix = `settings.roleRouting.${role2}`;
|
|
4416
3375
|
const routes = [];
|
|
4417
3376
|
if (policy.primary !== void 0) routes.push([`${prefix}.primary`, policy.primary]);
|
|
4418
3377
|
for (const [index, route3] of (policy.fallbackRoutes ?? []).entries()) {
|
|
@@ -4463,10 +3422,10 @@ var ProfilesController = class {
|
|
|
4463
3422
|
}
|
|
4464
3423
|
this.editContent(content2);
|
|
4465
3424
|
}
|
|
4466
|
-
editFallbackOrder(
|
|
3425
|
+
editFallbackOrder(role2, from, to) {
|
|
4467
3426
|
const editor = this.current.editor;
|
|
4468
3427
|
if (editor === null || editor.refreshRequired || this.current.busy !== null || this.current.pendingEditor !== null) return;
|
|
4469
|
-
const content2 = moveFallback(editor.content,
|
|
3428
|
+
const content2 = moveFallback(editor.content, role2, from, to);
|
|
4470
3429
|
if (content2 !== null) this.editContent(content2);
|
|
4471
3430
|
}
|
|
4472
3431
|
async save() {
|
|
@@ -4488,26 +3447,26 @@ var ProfilesController = class {
|
|
|
4488
3447
|
});
|
|
4489
3448
|
}
|
|
4490
3449
|
async apply() {
|
|
4491
|
-
const { editor, snapshot:
|
|
4492
|
-
if (editor?.refreshRequired || !isConfigRevision(editor?.revision) || !canReconcileSelection(
|
|
3450
|
+
const { editor, snapshot: snapshot3, dirty, invalidFields } = this.current;
|
|
3451
|
+
if (editor?.refreshRequired || !isConfigRevision(editor?.revision) || !canReconcileSelection(snapshot3) || dirty || invalidFields.length > 0) return;
|
|
4493
3452
|
await this.perform("apply", async (live) => {
|
|
4494
|
-
const accepted = await this.unwrap(this.remote.select({ id: editor.id, expectedRevision: editor.revision, expectedSelectionRevision:
|
|
3453
|
+
const accepted = await this.unwrap(this.remote.select({ id: editor.id, expectedRevision: editor.revision, expectedSelectionRevision: snapshot3.selectionRevision }));
|
|
4495
3454
|
if (live()) this.acceptSelection(accepted, { key: "applied", id: accepted.selectedId ?? void 0 });
|
|
4496
3455
|
});
|
|
4497
3456
|
}
|
|
4498
3457
|
async reset() {
|
|
4499
|
-
const
|
|
4500
|
-
if (!canReconcileSelection(
|
|
3458
|
+
const snapshot3 = this.current.snapshot;
|
|
3459
|
+
if (!canReconcileSelection(snapshot3)) return;
|
|
4501
3460
|
await this.perform("reset", async (live) => {
|
|
4502
|
-
const accepted = await this.unwrap(this.remote.select({ id: null, expectedSelectionRevision:
|
|
3461
|
+
const accepted = await this.unwrap(this.remote.select({ id: null, expectedSelectionRevision: snapshot3.selectionRevision }));
|
|
4503
3462
|
if (live()) this.acceptSelection(accepted, { key: "reset" });
|
|
4504
3463
|
});
|
|
4505
3464
|
}
|
|
4506
|
-
acceptSelection(
|
|
3465
|
+
acceptSelection(snapshot3, notice) {
|
|
4507
3466
|
this.publish({
|
|
4508
|
-
snapshot:
|
|
4509
|
-
notice:
|
|
4510
|
-
issue:
|
|
3467
|
+
snapshot: snapshot3,
|
|
3468
|
+
notice: snapshot3.selectionError === void 0 ? notice : null,
|
|
3469
|
+
issue: snapshot3.selectionError === void 0 ? null : { ...safeIssue(snapshot3.selectionError), source: "selection" }
|
|
4511
3470
|
});
|
|
4512
3471
|
}
|
|
4513
3472
|
};
|
|
@@ -5749,16 +4708,16 @@ function ProfileModelsDialog({
|
|
|
5749
4708
|
const baseline = state.snapshot?.editorDefaults;
|
|
5750
4709
|
const canSave = canSaveProp ?? (!disabled && !isInvalidProjection && doc !== null && state.dirty && state.snapshot !== null && state.invalidFields.length === 0);
|
|
5751
4710
|
const isSaveLocked = (state.dirty || state.invalidFields.length > 0) && !disabled && doc !== null && state.snapshot !== null && (state.invalidFields.length > 0 || Boolean(isInvalidProjection));
|
|
5752
|
-
const filteredRoles = roles2.filter((
|
|
4711
|
+
const filteredRoles = roles2.filter((role2) => {
|
|
5753
4712
|
if (searchQuery.trim()) {
|
|
5754
4713
|
const q = searchQuery.trim().toLowerCase();
|
|
5755
|
-
const matchesId =
|
|
5756
|
-
const displayLabel = displayRoleLabel(
|
|
5757
|
-
const matchesLabel =
|
|
4714
|
+
const matchesId = role2.id.toLowerCase().includes(q);
|
|
4715
|
+
const displayLabel = displayRoleLabel(role2.label);
|
|
4716
|
+
const matchesLabel = role2.label.toLowerCase().includes(q) || displayLabel.toLowerCase().includes(q);
|
|
5758
4717
|
if (!matchesId && !matchesLabel) return false;
|
|
5759
4718
|
}
|
|
5760
4719
|
if (filterExplicitOnly) {
|
|
5761
|
-
if (!hasExplicitModelOverride(
|
|
4720
|
+
if (!hasExplicitModelOverride(role2.id, doc)) return false;
|
|
5762
4721
|
}
|
|
5763
4722
|
return true;
|
|
5764
4723
|
});
|
|
@@ -5887,12 +4846,12 @@ function ProfileModelsDialog({
|
|
|
5887
4846
|
] }),
|
|
5888
4847
|
doc !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsmm-roles-list dsmm-dialog-roles-list", children: [
|
|
5889
4848
|
filteredRoles.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "dsmm-hint dsmm-no-roles", children: t("noMatchingRoles") }),
|
|
5890
|
-
filteredRoles.map((
|
|
5891
|
-
const roleName = displayRoleLabel(
|
|
5892
|
-
const policy = doc.roleRouting[
|
|
5893
|
-
const rolePath = ["settings", "roleRouting",
|
|
5894
|
-
const isOrchestrator =
|
|
5895
|
-
const explicitOverride = hasExplicitModelOverride(
|
|
4849
|
+
filteredRoles.map((role2) => {
|
|
4850
|
+
const roleName = displayRoleLabel(role2.label);
|
|
4851
|
+
const policy = doc.roleRouting[role2.id] ?? {};
|
|
4852
|
+
const rolePath = ["settings", "roleRouting", role2.id];
|
|
4853
|
+
const isOrchestrator = role2.id === "dsmm-orchestrator";
|
|
4854
|
+
const explicitOverride = hasExplicitModelOverride(role2.id, doc);
|
|
5896
4855
|
let inherited;
|
|
5897
4856
|
try {
|
|
5898
4857
|
if (baseline !== void 0) {
|
|
@@ -5901,41 +4860,41 @@ function ProfileModelsDialog({
|
|
|
5901
4860
|
rateLimit: normalizeRateLimitPolicy(doc.runtimePolicy.rateLimit, baseline.rateLimit)
|
|
5902
4861
|
};
|
|
5903
4862
|
inherited = {
|
|
5904
|
-
strategy:
|
|
5905
|
-
rateLimit: normalizeRateLimitPolicy(
|
|
4863
|
+
strategy: role2.runtimePolicy?.strategy ?? profileDefaults.strategy,
|
|
4864
|
+
rateLimit: normalizeRateLimitPolicy(role2.runtimePolicy?.rateLimit, profileDefaults.rateLimit)
|
|
5906
4865
|
};
|
|
5907
4866
|
}
|
|
5908
4867
|
} catch {
|
|
5909
4868
|
}
|
|
5910
|
-
const availability2 = roleAvailability(
|
|
4869
|
+
const availability2 = roleAvailability(role2.availability);
|
|
5911
4870
|
const namedRoles = doc.settings.roles;
|
|
5912
4871
|
const configuredLevels = ["low", "high", "max"].filter(
|
|
5913
4872
|
(lvl) => policy.levels?.[lvl] !== void 0
|
|
5914
4873
|
);
|
|
5915
4874
|
const levelsSummary = configuredLevels.length > 0 ? t("levelsSummary", { levels: configuredLevels.join(", ") }) : t("levelsInherited");
|
|
5916
4875
|
const fallbackSummary = policy.fallbackRoutes === void 0 ? t("fallbackInherited") : policy.fallbackRoutes.length === 0 ? t("fallbackExplicitEmptySummary") : t("fallbackCountSummary", { count: policy.fallbackRoutes.length });
|
|
5917
|
-
const statusSummary = namedRoles?.[
|
|
4876
|
+
const statusSummary = namedRoles?.[role2.id] !== void 0 ? namedRoles[role2.id] ? t("enabled") : t("disabled") : t("roleSettingsInherited");
|
|
5918
4877
|
const retrySummary = policy.strategy !== void 0 || policy.rateLimit !== void 0 && Object.keys(policy.rateLimit).length > 0 ? t("roleSettingsOverridden") : t("roleSettingsInherited");
|
|
5919
4878
|
const nonModelSummary = t("roleSettingsSummary", { status: statusSummary, retry: retrySummary });
|
|
5920
4879
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
5921
4880
|
"div",
|
|
5922
4881
|
{
|
|
5923
4882
|
className: "dsmm-role-card dsmm-dialog-role-card",
|
|
5924
|
-
"data-dsmm-role":
|
|
4883
|
+
"data-dsmm-role": role2.id,
|
|
5925
4884
|
children: [
|
|
5926
4885
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsmm-role-main-row", children: [
|
|
5927
4886
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsmm-dialog-role-header", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsmm-role-title-group", children: [
|
|
5928
4887
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsmm-role-title", children: roleName }),
|
|
5929
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("code", { className: "dsmm-role-id-badge", children:
|
|
4888
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("code", { className: "dsmm-role-id-badge", children: role2.id }),
|
|
5930
4889
|
explicitOverride && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsmm-override-badge", children: t("roleSettingsOverridden") })
|
|
5931
4890
|
] }) }),
|
|
5932
4891
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsmm-role-primary-route", children: [
|
|
5933
4892
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsmm-field dsmm-primary-mode-field", children: [
|
|
5934
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: `${prefix}-${
|
|
4893
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: `${prefix}-${role2.id}-primary-mode`, children: t("primaryMode", { name: roleName }) }),
|
|
5935
4894
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
5936
4895
|
"select",
|
|
5937
4896
|
{
|
|
5938
|
-
id: `${prefix}-${
|
|
4897
|
+
id: `${prefix}-${role2.id}-primary-mode`,
|
|
5939
4898
|
disabled: effectiveDisabled,
|
|
5940
4899
|
value: policy.primary === void 0 ? "inherit" : "explicit",
|
|
5941
4900
|
onChange: (event) => actions3.editPath(
|
|
@@ -6002,11 +4961,11 @@ function ProfileModelsDialog({
|
|
|
6002
4961
|
] }),
|
|
6003
4962
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsmm-details-content", children: [
|
|
6004
4963
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsmm-field", children: [
|
|
6005
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: `${prefix}-${
|
|
4964
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: `${prefix}-${role2.id}-fallback-mode`, children: t("fallbackMode", { name: roleName }) }),
|
|
6006
4965
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
6007
4966
|
"select",
|
|
6008
4967
|
{
|
|
6009
|
-
id: `${prefix}-${
|
|
4968
|
+
id: `${prefix}-${role2.id}-fallback-mode`,
|
|
6010
4969
|
disabled: effectiveDisabled,
|
|
6011
4970
|
value: policy.fallbackRoutes === void 0 ? "inherit" : "explicit",
|
|
6012
4971
|
onChange: (event) => actions3.editPath(
|
|
@@ -6053,8 +5012,8 @@ function ProfileModelsDialog({
|
|
|
6053
5012
|
"data-dsmm-action": "moveUp",
|
|
6054
5013
|
disabled: effectiveDisabled || index === 0,
|
|
6055
5014
|
onClick: () => {
|
|
6056
|
-
pendingFallbackFocusRef.current = { roleId:
|
|
6057
|
-
actions3.moveFallback(
|
|
5015
|
+
pendingFallbackFocusRef.current = { roleId: role2.id, index: index - 1, action: "moveUp" };
|
|
5016
|
+
actions3.moveFallback(role2.id, index, index - 1);
|
|
6058
5017
|
},
|
|
6059
5018
|
children: t("moveUp", { name: name2 })
|
|
6060
5019
|
}
|
|
@@ -6067,8 +5026,8 @@ function ProfileModelsDialog({
|
|
|
6067
5026
|
"data-dsmm-action": "moveDown",
|
|
6068
5027
|
disabled: effectiveDisabled || index === policy.fallbackRoutes.length - 1,
|
|
6069
5028
|
onClick: () => {
|
|
6070
|
-
pendingFallbackFocusRef.current = { roleId:
|
|
6071
|
-
actions3.moveFallback(
|
|
5029
|
+
pendingFallbackFocusRef.current = { roleId: role2.id, index: index + 1, action: "moveDown" };
|
|
5030
|
+
actions3.moveFallback(role2.id, index, index + 1);
|
|
6072
5031
|
},
|
|
6073
5032
|
children: t("moveDown", { name: name2 })
|
|
6074
5033
|
}
|
|
@@ -6083,7 +5042,7 @@ function ProfileModelsDialog({
|
|
|
6083
5042
|
onClick: () => {
|
|
6084
5043
|
const newLen = policy.fallbackRoutes.length - 1;
|
|
6085
5044
|
const nextIdx = Math.min(index, Math.max(0, newLen - 1));
|
|
6086
|
-
pendingFallbackFocusRef.current = { roleId:
|
|
5045
|
+
pendingFallbackFocusRef.current = { roleId: role2.id, index: nextIdx, action: "remove" };
|
|
6087
5046
|
actions3.editPath([...rolePath, "fallbackRoutes", index], void 0);
|
|
6088
5047
|
},
|
|
6089
5048
|
children: t("removeFallback", { name: name2 })
|
|
@@ -6106,7 +5065,7 @@ function ProfileModelsDialog({
|
|
|
6106
5065
|
const currentDetails = e.currentTarget.closest("details");
|
|
6107
5066
|
if (currentDetails) currentDetails.open = true;
|
|
6108
5067
|
const newIndex = policy.fallbackRoutes?.length ?? 0;
|
|
6109
|
-
pendingFallbackFocusRef.current = { roleId:
|
|
5068
|
+
pendingFallbackFocusRef.current = { roleId: role2.id, index: newIndex, action: "add" };
|
|
6110
5069
|
if (policy.fallbackRoutes === void 0) {
|
|
6111
5070
|
actions3.editPath([...rolePath, "fallbackRoutes"], [{ provider: "", model: "" }]);
|
|
6112
5071
|
} else {
|
|
@@ -6127,18 +5086,18 @@ function ProfileModelsDialog({
|
|
|
6127
5086
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsmm-pill-val", children: nonModelSummary })
|
|
6128
5087
|
] }),
|
|
6129
5088
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsmm-details-content", children: [
|
|
6130
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(RoleAvailability, { value:
|
|
5089
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(RoleAvailability, { value: role2.availability, t }),
|
|
6131
5090
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsmm-field", children: [
|
|
6132
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: `${prefix}-${
|
|
5091
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: `${prefix}-${role2.id}-role-enabled`, children: t("namedRole", { name: roleName }) }),
|
|
6133
5092
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
6134
5093
|
"select",
|
|
6135
5094
|
{
|
|
6136
|
-
id: `${prefix}-${
|
|
6137
|
-
value: namedRoles?.[
|
|
5095
|
+
id: `${prefix}-${role2.id}-role-enabled`,
|
|
5096
|
+
value: namedRoles?.[role2.id] === void 0 ? "" : String(namedRoles[role2.id]),
|
|
6138
5097
|
disabled: effectiveDisabled,
|
|
6139
|
-
"aria-describedby": `${prefix}-${
|
|
5098
|
+
"aria-describedby": `${prefix}-${role2.id}-role-hint`,
|
|
6140
5099
|
onChange: (event) => actions3.editPath(
|
|
6141
|
-
["settings", "roles",
|
|
5100
|
+
["settings", "roles", role2.id],
|
|
6142
5101
|
event.currentTarget.value === "" ? void 0 : event.currentTarget.value === "true"
|
|
6143
5102
|
),
|
|
6144
5103
|
children: [
|
|
@@ -6155,7 +5114,7 @@ function ProfileModelsDialog({
|
|
|
6155
5114
|
]
|
|
6156
5115
|
}
|
|
6157
5116
|
),
|
|
6158
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { id: `${prefix}-${
|
|
5117
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { id: `${prefix}-${role2.id}-role-hint`, className: "dsmm-hint", children: t("namedRoleHint") })
|
|
6159
5118
|
] }),
|
|
6160
5119
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
6161
5120
|
PolicyFields,
|
|
@@ -6174,7 +5133,7 @@ function ProfileModelsDialog({
|
|
|
6174
5133
|
] })
|
|
6175
5134
|
]
|
|
6176
5135
|
},
|
|
6177
|
-
|
|
5136
|
+
role2.id
|
|
6178
5137
|
);
|
|
6179
5138
|
})
|
|
6180
5139
|
] })
|
|
@@ -6314,10 +5273,10 @@ function SessionScope({ state, actions: actions3, t, compact = false, showFeedba
|
|
|
6314
5273
|
] }),
|
|
6315
5274
|
session.roles !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("details", { children: [
|
|
6316
5275
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("summary", { children: t("admittedRoles") }),
|
|
6317
|
-
session.roles.map((
|
|
6318
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children:
|
|
6319
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(RoleAvailability, { value:
|
|
6320
|
-
] },
|
|
5276
|
+
session.roles.map((role2) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dsmm-availability", children: [
|
|
5277
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children: role2.id }),
|
|
5278
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(RoleAvailability, { value: role2, t })
|
|
5279
|
+
] }, role2.id))
|
|
6321
5280
|
] }),
|
|
6322
5281
|
session.rolePolicy !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { "data-dsmm-session-policy": true, children: t("roleState", { route: session.rolePolicy.route === void 0 ? t("inheritRoute") : `${session.rolePolicy.route.provider}/${session.rolePolicy.route.model}${session.rolePolicy.route.reasoningEffort === void 0 ? "" : ` (${session.rolePolicy.route.reasoningEffort})`}`, strategy: session.rolePolicy.strategy, retries: session.rolePolicy.retries, failures: session.rolePolicy.rateLimitFailures, switches: session.rolePolicy.switches, delay: session.rolePolicy.totalDelayMs }) })
|
|
6323
5282
|
] })
|
|
@@ -6339,7 +5298,7 @@ function SessionScope({ state, actions: actions3, t, compact = false, showFeedba
|
|
|
6339
5298
|
}
|
|
6340
5299
|
function SessionProfiles(props) {
|
|
6341
5300
|
const prefix = (0, import_react4.useId)();
|
|
6342
|
-
const state = props.useProfiles((
|
|
5301
|
+
const state = props.useProfiles((snapshot3) => snapshot3);
|
|
6343
5302
|
const id2 = state.currentSessionId;
|
|
6344
5303
|
const [openFor, setOpenFor] = (0, import_react4.useState)(void 0);
|
|
6345
5304
|
(0, import_react4.useEffect)(() => {
|
|
@@ -6462,7 +5421,7 @@ function locateGlobalField(container, field) {
|
|
|
6462
5421
|
}
|
|
6463
5422
|
function ProfilesSection(props) {
|
|
6464
5423
|
const { t } = props;
|
|
6465
|
-
const state = props.useProfiles((
|
|
5424
|
+
const state = props.useProfiles((snapshot4) => snapshot4);
|
|
6466
5425
|
const prefix = (0, import_react5.useId)();
|
|
6467
5426
|
const selectRef = (0, import_react5.useRef)(null);
|
|
6468
5427
|
const inputRef = (0, import_react5.useRef)(null);
|
|
@@ -6487,13 +5446,13 @@ function ProfilesSection(props) {
|
|
|
6487
5446
|
const jsoncOpenRef = (0, import_react5.useRef)(false);
|
|
6488
5447
|
const moreActionsOpenRef = (0, import_react5.useRef)(false);
|
|
6489
5448
|
const disabled = state.busy !== null || state.pendingEditor !== null || state.sessionBusy === "apply" || state.sessionBusy === "reset";
|
|
6490
|
-
const
|
|
6491
|
-
const hasOrchestrator =
|
|
5449
|
+
const snapshot3 = state.snapshot;
|
|
5450
|
+
const hasOrchestrator = snapshot3?.roles?.some((role2) => role2.id === "dsmm-orchestrator") === true;
|
|
6492
5451
|
const editor = state.editor;
|
|
6493
|
-
const readOnly =
|
|
5452
|
+
const readOnly = snapshot3?.readOnly === true;
|
|
6494
5453
|
const editorDisabled = disabled || readOnly || editor?.refreshRequired === true || editor?.revision === "unavailable";
|
|
6495
|
-
const reconcilable = canReconcileSelection(
|
|
6496
|
-
const selectionConflict = reconcilable &&
|
|
5454
|
+
const reconcilable = canReconcileSelection(snapshot3);
|
|
5455
|
+
const selectionConflict = reconcilable && snapshot3?.selectionError?.code === "conflict";
|
|
6497
5456
|
const invalid2 = state.issue?.kind === "domain" && state.issue.code === "validation";
|
|
6498
5457
|
const idInvalid = invalid2 && state.issue?.field === "id" && state.issue.location === void 0 && editor?.revision === null && !editorDisabled;
|
|
6499
5458
|
const structuredDoc = editor === null ? null : structuredDocument(editor.content);
|
|
@@ -6503,7 +5462,7 @@ function ProfilesSection(props) {
|
|
|
6503
5462
|
}
|
|
6504
5463
|
const basicDoc = structuredDoc ?? (lastValidBasicDocRef.current !== null && lastValidBasicDocRef.current.id === editor?.id && lastValidBasicDocRef.current.epoch === state.editorEpoch ? lastValidBasicDocRef.current.doc : null);
|
|
6505
5464
|
const rawInvalid = editor !== null && structuredDoc === null;
|
|
6506
|
-
const canSave = !editorDisabled && state.dirty &&
|
|
5465
|
+
const canSave = !editorDisabled && state.dirty && snapshot3 !== null && state.invalidFields.length === 0 && !rawInvalid;
|
|
6507
5466
|
function focusJsonc(location) {
|
|
6508
5467
|
if (advancedRef.current !== null) {
|
|
6509
5468
|
advancedRef.current.open = true;
|
|
@@ -6582,7 +5541,7 @@ function ProfilesSection(props) {
|
|
|
6582
5541
|
const field = state.issue.field ?? "";
|
|
6583
5542
|
const roleMatch = /^(?:settings\.)?(?:roleRouting|roles)\.([a-zA-Z0-9_-]+)(?:\.|$)/.exec(field);
|
|
6584
5543
|
const roleId2 = roleMatch?.[1];
|
|
6585
|
-
if (roleId2 &&
|
|
5544
|
+
if (roleId2 && snapshot3?.roles?.some((r) => r.id === roleId2)) {
|
|
6586
5545
|
setTargetRole(roleId2);
|
|
6587
5546
|
setTargetRoleField(field);
|
|
6588
5547
|
setModelsDialogOpen(true);
|
|
@@ -6595,12 +5554,12 @@ function ProfilesSection(props) {
|
|
|
6595
5554
|
if (modelsDialogOpen) closeModelsDialog("jsonc");
|
|
6596
5555
|
else if (focusJsonc(state.issue.location)) handledValidation.current = state.validationEpoch;
|
|
6597
5556
|
}
|
|
6598
|
-
}, [state.issue, state.busy, state.validationEpoch,
|
|
6599
|
-
const relationship = editor?.revision != null && editor.id ===
|
|
5557
|
+
}, [state.issue, state.busy, state.validationEpoch, snapshot3?.roles]);
|
|
5558
|
+
const relationship = editor?.revision != null && editor.id === snapshot3?.selectedId ? sourceRelationship(snapshot3, editor.revision) : "changed";
|
|
6600
5559
|
const applied = relationship === "current";
|
|
6601
|
-
let selection = t(
|
|
6602
|
-
if (
|
|
6603
|
-
else if (
|
|
5560
|
+
let selection = t(snapshot3 === null ? "unavailable" : "baseline");
|
|
5561
|
+
if (snapshot3?.selectionError !== void 0 && !selectionConflict) selection = t("appliedInvalid");
|
|
5562
|
+
else if (snapshot3?.selectedId !== null && snapshot3?.selectedId !== void 0) selection = t("appliedProfile", { id: snapshot3.selectedId, revision: t(configurationVersionState(snapshot3.sourceRevision)) });
|
|
6604
5563
|
const notice = state.notice === null ? "" : t(state.notice.key === "reset" ? "resetDone" : state.notice.key, { id: state.notice.id });
|
|
6605
5564
|
(0, import_react5.useEffect)(() => {
|
|
6606
5565
|
const el = saveBarRef.current;
|
|
@@ -6635,14 +5594,14 @@ function ProfilesSection(props) {
|
|
|
6635
5594
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h2", { children: t("title") }),
|
|
6636
5595
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dsmm-hint", children: t("description") }),
|
|
6637
5596
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-browse-row", children: [
|
|
6638
|
-
|
|
5597
|
+
snapshot3 !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-field", children: [
|
|
6639
5598
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("label", { htmlFor: `${prefix}-select`, children: t("editorSelect") }),
|
|
6640
5599
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("select", { ref: selectRef, id: `${prefix}-select`, disabled, value: editor?.revision == null ? "" : editor.id, onChange: (event) => {
|
|
6641
5600
|
initiatorRef.current = event.currentTarget;
|
|
6642
5601
|
if (event.currentTarget.value) void props.open(event.currentTarget.value);
|
|
6643
5602
|
}, children: [
|
|
6644
5603
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: "", children: t(editor?.revision === null ? "newDraft" : "choose") }),
|
|
6645
|
-
|
|
5604
|
+
snapshot3.profiles.map((profile, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("option", { value: profile.id, children: [
|
|
6646
5605
|
profile.label?.trim() ? `${profile.label} (${profile.id})` : profile.id,
|
|
6647
5606
|
profile.error === void 0 ? "" : ` — ${t("invalidProfile", { id: profile.id })}`,
|
|
6648
5607
|
profile.warnings?.length ? ` — ${t("warningProfile")}` : ""
|
|
@@ -6650,7 +5609,7 @@ function ProfilesSection(props) {
|
|
|
6650
5609
|
] })
|
|
6651
5610
|
] }),
|
|
6652
5611
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-actions", children: [
|
|
6653
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives5.Button, { type: "button", variant: "outline", disabled: editorDisabled ||
|
|
5612
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives5.Button, { type: "button", variant: "outline", disabled: editorDisabled || snapshot3 === null, onClick: (event) => {
|
|
6654
5613
|
initiatorRef.current = event.currentTarget;
|
|
6655
5614
|
void props.create();
|
|
6656
5615
|
}, children: t("new") }),
|
|
@@ -6661,8 +5620,8 @@ function ProfilesSection(props) {
|
|
|
6661
5620
|
] }),
|
|
6662
5621
|
editor !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dsmm-badge", "data-dsmm-editor-state": state.invalidFields.length > 0 || invalid2 || rawInvalid ? "invalid" : state.dirty ? "dirty" : readOnly ? "readonly" : "ready", children: t(editor.refreshRequired ? "savedRefreshRequired" : state.invalidFields.length > 0 || invalid2 || rawInvalid ? "validation" : state.dirty ? "dirty" : applied ? "savedApplied" : relationship === "unknown" ? "savedRelationshipUnknown" : "savedNotApplied") })
|
|
6663
5622
|
] }),
|
|
6664
|
-
|
|
6665
|
-
|
|
5623
|
+
snapshot3?.profiles.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dsmm-hint", children: t("empty") }),
|
|
5624
|
+
snapshot3 !== null && snapshot3.profiles.some((profile) => profile.error !== void 0 || profile.warnings?.length) && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "dsmm-profile-list", "aria-label": t("savedInventory"), children: snapshot3.profiles.filter((profile) => profile.error !== void 0 || profile.warnings?.length).map((profile, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { children: [
|
|
6666
5625
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: profile.label?.trim() ? `${profile.label} (${profile.id})` : profile.id }),
|
|
6667
5626
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ProfileWarnings, { warnings: profile.warnings, t }),
|
|
6668
5627
|
profile.error !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IssueDetails, { issue: profile.error, t })
|
|
@@ -6692,14 +5651,14 @@ function ProfilesSection(props) {
|
|
|
6692
5651
|
void props.apply();
|
|
6693
5652
|
}, children: t(state.busy === "apply" ? "applying" : "apply") })
|
|
6694
5653
|
] }),
|
|
6695
|
-
|
|
6696
|
-
|
|
5654
|
+
snapshot3?.refreshRequired && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { role: "status", children: t("savedRefreshRequired") }),
|
|
5655
|
+
snapshot3?.selectedWarnings?.length ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
6697
5656
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: t("futureWarnings") }),
|
|
6698
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ProfileWarnings, { warnings:
|
|
5657
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ProfileWarnings, { warnings: snapshot3.selectedWarnings, t })
|
|
6699
5658
|
] }) : null,
|
|
6700
|
-
|
|
5659
|
+
snapshot3?.selectionError !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-issue", children: [
|
|
6701
5660
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: t(selectionConflict ? "selectionConflict" : "retry") }),
|
|
6702
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IssueDetails, { issue:
|
|
5661
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IssueDetails, { issue: snapshot3.selectionError, t })
|
|
6703
5662
|
] }),
|
|
6704
5663
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-summary-row", children: [
|
|
6705
5664
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
@@ -6723,7 +5682,7 @@ function ProfilesSection(props) {
|
|
|
6723
5682
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("summary", { children: t("moreActions") }),
|
|
6724
5683
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
6725
5684
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
6726
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives5.Button, { type: "button", variant: "outline", disabled: editorDisabled || !reconcilable ||
|
|
5685
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives5.Button, { type: "button", variant: "outline", disabled: editorDisabled || !reconcilable || snapshot3?.selectedId === null && !selectionConflict, onClick: () => {
|
|
6727
5686
|
void props.reset();
|
|
6728
5687
|
}, children: t(state.busy === "reset" ? "resetting" : "reset") }),
|
|
6729
5688
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dsmm-hint", children: t("futureResetHint") })
|
|
@@ -6747,10 +5706,10 @@ function ProfilesSection(props) {
|
|
|
6747
5706
|
initiatorRef.current = event.currentTarget;
|
|
6748
5707
|
void props.reload();
|
|
6749
5708
|
}, children: t("reload") }),
|
|
6750
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.busy === "refresh" &&
|
|
5709
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.busy === "refresh" && snapshot3 === null ? t("loading") : state.busy === "read" ? t("reading") : notice })
|
|
6751
5710
|
] }),
|
|
6752
5711
|
(() => {
|
|
6753
|
-
const isSaveLocked = (state.dirty || state.invalidFields.length > 0) && !editorDisabled &&
|
|
5712
|
+
const isSaveLocked = (state.dirty || state.invalidFields.length > 0) && !editorDisabled && snapshot3 !== null && (state.invalidFields.length > 0 || rawInvalid || invalid2);
|
|
6754
5713
|
if (!isSaveLocked) return null;
|
|
6755
5714
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-save-lock-reason", role: "status", children: [
|
|
6756
5715
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "dsmm-save-lock-text", children: rawInvalid ? t("rawInvalid") : state.invalidFields.length > 0 ? t("saveLockedReason", { count: state.invalidFields.length }) : t("validation") }),
|
|
@@ -6837,7 +5796,7 @@ function ProfilesSection(props) {
|
|
|
6837
5796
|
}
|
|
6838
5797
|
const roleMatch = /^(?:settings\.)?(?:roleRouting|roles)\.([a-zA-Z0-9_-]+)(?:\.|$)/.exec(state.issue?.field ?? "");
|
|
6839
5798
|
const roleId2 = roleMatch?.[1];
|
|
6840
|
-
if (roleId2 &&
|
|
5799
|
+
if (roleId2 && snapshot3?.roles?.some((r) => r.id === roleId2)) {
|
|
6841
5800
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
6842
5801
|
import_dsh_client_ui_primitives5.Button,
|
|
6843
5802
|
{
|
|
@@ -7128,7 +6087,7 @@ function ProfilesSection(props) {
|
|
|
7128
6087
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: t(issueKey(state.issue)) }),
|
|
7129
6088
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IssueDetails, { issue: state.issue, t })
|
|
7130
6089
|
] }),
|
|
7131
|
-
editor === null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.busy === "refresh" &&
|
|
6090
|
+
editor === null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.busy === "refresh" && snapshot3 === null ? t("loading") : state.busy === "read" ? t("reading") : notice })
|
|
7132
6091
|
] });
|
|
7133
6092
|
}
|
|
7134
6093
|
|
|
@@ -7327,8 +6286,8 @@ var PROFILE_STYLES = `
|
|
|
7327
6286
|
function record2(value) {
|
|
7328
6287
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7329
6288
|
}
|
|
7330
|
-
function scopeSchema(
|
|
7331
|
-
return layer === "profile" ?
|
|
6289
|
+
function scopeSchema(snapshot3, layer) {
|
|
6290
|
+
return layer === "profile" ? snapshot3.nativeSchema ?? snapshot3.schema : snapshot3.schema;
|
|
7332
6291
|
}
|
|
7333
6292
|
function at(value, path) {
|
|
7334
6293
|
return path.reduce((node, key) => record2(node) && Object.hasOwn(node, key) ? node[key] : void 0, value);
|
|
@@ -7420,12 +6379,12 @@ function enumValues(schema) {
|
|
|
7420
6379
|
function visibleDeploymentPath(path) {
|
|
7421
6380
|
return !["lsp", "modeName", "section"].includes(path[0]);
|
|
7422
6381
|
}
|
|
7423
|
-
function inspectorPaths(
|
|
6382
|
+
function inspectorPaths(snapshot3, admitted) {
|
|
7424
6383
|
const paths = /* @__PURE__ */ new Set([
|
|
7425
|
-
...Object.keys(
|
|
7426
|
-
...Object.keys(
|
|
7427
|
-
...Object.keys(
|
|
7428
|
-
...Object.keys(
|
|
6384
|
+
...Object.keys(snapshot3.sources),
|
|
6385
|
+
...Object.keys(snapshot3.startupSources ?? {}),
|
|
6386
|
+
...Object.keys(snapshot3.nextRoot?.sources ?? {}),
|
|
6387
|
+
...Object.keys(snapshot3.nextRoot?.captures ?? {}),
|
|
7429
6388
|
...Object.keys(admitted?.sources ?? {}),
|
|
7430
6389
|
...Object.keys(admitted?.captures ?? {})
|
|
7431
6390
|
]);
|
|
@@ -7434,7 +6393,7 @@ function inspectorPaths(snapshot4, admitted) {
|
|
|
7434
6393
|
if (record2(value) && Object.keys(value).length) for (const [key, child2] of Object.entries(value)) visit2(child2, [...path, key]);
|
|
7435
6394
|
else if (path.length) paths.add(path.join("."));
|
|
7436
6395
|
};
|
|
7437
|
-
for (const value of [
|
|
6396
|
+
for (const value of [snapshot3.desired, snapshot3.startup, snapshot3.nextRoot?.settings, admitted?.settings]) if (value !== void 0) visit2(value, []);
|
|
7438
6397
|
return [...paths].filter((path) => visibleDeploymentPath(path.split("."))).sort();
|
|
7439
6398
|
}
|
|
7440
6399
|
|
|
@@ -7556,9 +6515,9 @@ var DeploymentController = class _DeploymentController {
|
|
|
7556
6515
|
pendingPaths() {
|
|
7557
6516
|
return [.../* @__PURE__ */ new Set([...layerDiff(this.baseline, this.state.draft).map((edit) => edit.path.join(".")), ...this.invalid])];
|
|
7558
6517
|
}
|
|
7559
|
-
canWriteProfile(
|
|
6518
|
+
canWriteProfile(snapshot3 = this.state.snapshot) {
|
|
7560
6519
|
const native = this.form?.state;
|
|
7561
|
-
return this.currentConnection() &&
|
|
6520
|
+
return this.currentConnection() && snapshot3 !== null && this.rowNamespace !== null && this.rowNamespace === snapshot3.namespace && native?.status === "ready" && native.writable && native.revision === snapshot3.nativeFormRevision && snapshot3.nativeForm !== null && equal(native.base ?? null, snapshot3.nativeForm.base) && equal(native.user ?? null, snapshot3.nativeForm.user);
|
|
7562
6521
|
}
|
|
7563
6522
|
edit(path, value) {
|
|
7564
6523
|
if (!this.canEdit()) return;
|
|
@@ -7572,19 +6531,19 @@ var DeploymentController = class _DeploymentController {
|
|
|
7572
6531
|
this.publish({ busy: true, saved: false });
|
|
7573
6532
|
try {
|
|
7574
6533
|
if (this.connection !== null && connection === void 0) throw new Refusal("transport");
|
|
7575
|
-
const
|
|
6534
|
+
const snapshot3 = await unwrap(this.remote.describeSettings());
|
|
7576
6535
|
if (this.disposed || generation !== this.generation) return;
|
|
7577
|
-
if (
|
|
6536
|
+
if (snapshot3.globalRevision === "unavailable" || this.layer === "profile" && snapshot3.nativeRevision === "unavailable") throw new Refusal("unavailable");
|
|
7578
6537
|
const old = this.state.snapshot;
|
|
7579
|
-
if (old !== null && (old.entryId !==
|
|
6538
|
+
if (old !== null && (old.entryId !== snapshot3.entryId || old.hostProfileKey !== snapshot3.hostProfileKey)) throw new Refusal("unavailable");
|
|
7580
6539
|
if (this.state.dirty && !discard) {
|
|
7581
|
-
const stale = !this.currentConnection() || (this.layer === "global" ? old?.globalRevision !==
|
|
6540
|
+
const stale = !this.currentConnection() || (this.layer === "global" ? old?.globalRevision !== snapshot3.globalRevision : old?.nativeRevision !== snapshot3.nativeRevision || old?.globalRevision !== snapshot3.globalRevision);
|
|
7582
6541
|
this.publish({ issue: stale ? "conflict" : null });
|
|
7583
6542
|
} else {
|
|
7584
6543
|
this.invalid.clear();
|
|
7585
6544
|
this.connectionBaseline = connection;
|
|
7586
|
-
this.baseline = this.layer === "global" ?
|
|
7587
|
-
this.publish({ snapshot:
|
|
6545
|
+
this.baseline = this.layer === "global" ? snapshot3.global : record2(snapshot3.nativeForm?.user) ? snapshot3.nativeForm.user : {};
|
|
6546
|
+
this.publish({ snapshot: snapshot3, draft: structuredClone(this.baseline), raw: {}, invalidFields: [], dirty: false, issue: null, refreshRequired: false });
|
|
7588
6547
|
}
|
|
7589
6548
|
} catch (error) {
|
|
7590
6549
|
if (!this.disposed && generation === this.generation) this.publish({ issue: error instanceof Refusal ? error.code : "transport" });
|
|
@@ -7593,19 +6552,19 @@ var DeploymentController = class _DeploymentController {
|
|
|
7593
6552
|
}
|
|
7594
6553
|
}
|
|
7595
6554
|
async save() {
|
|
7596
|
-
const { snapshot:
|
|
7597
|
-
if (!this.canSave() ||
|
|
7598
|
-
if (
|
|
6555
|
+
const { snapshot: snapshot3, draft: draft2, dirty, busy, issue } = this.state;
|
|
6556
|
+
if (!this.canSave() || snapshot3 === null || !dirty || busy || issue !== null) return;
|
|
6557
|
+
if (snapshot3.globalRevision === "unavailable" || this.layer === "profile" && snapshot3.nativeRevision === "unavailable") {
|
|
7599
6558
|
this.publish({ issue: "unavailable" });
|
|
7600
6559
|
return;
|
|
7601
6560
|
}
|
|
7602
|
-
const selectedSchema = scopeSchema(
|
|
6561
|
+
const selectedSchema = scopeSchema(snapshot3, this.layer);
|
|
7603
6562
|
const schema = { ...selectedSchema, fields: Object.fromEntries(Object.entries(selectedSchema.fields ?? {}).filter(([key]) => key !== (this.layer === "global" ? "runtime" : "modules"))) };
|
|
7604
|
-
const mergedSchema = { ...
|
|
6563
|
+
const mergedSchema = { ...snapshot3.schema, fields: { ...snapshot3.schema.fields, ...snapshot3.nativeSchema?.fields } };
|
|
7605
6564
|
const editable = { ...draft2 };
|
|
7606
|
-
const lower = this.layer === "global" ?
|
|
6565
|
+
const lower = this.layer === "global" ? snapshot3.defaults : mergeLayer(mergeLayer(snapshot3.defaults, snapshot3.global), snapshot3.nativeForm?.base ?? {});
|
|
7607
6566
|
const candidate = mergeLayer(lower, editable);
|
|
7608
|
-
const merged = this.layer === "global" ? mergeLayer(candidate,
|
|
6567
|
+
const merged = this.layer === "global" ? mergeLayer(candidate, snapshot3.profile) : candidate;
|
|
7609
6568
|
if (!validateEditorValue(editable, schema, true) || !validateEditorValue(merged, mergedSchema)) {
|
|
7610
6569
|
this.publish({ issue: "validation" });
|
|
7611
6570
|
return;
|
|
@@ -7620,15 +6579,15 @@ var DeploymentController = class _DeploymentController {
|
|
|
7620
6579
|
try {
|
|
7621
6580
|
const current = await unwrap(this.remote.describeSettings());
|
|
7622
6581
|
if (this.disposed || generation !== this.generation) return;
|
|
7623
|
-
if (current.entryId !==
|
|
6582
|
+
if (current.entryId !== snapshot3.entryId || current.hostProfileKey !== snapshot3.hostProfileKey || current.globalRevision !== snapshot3.globalRevision) throw new Refusal("conflict");
|
|
7624
6583
|
let acceptedRefreshRequired = false;
|
|
7625
6584
|
if (this.layer === "global") {
|
|
7626
|
-
const accepted = await unwrap(this.remote.save({ expectedRevision:
|
|
6585
|
+
const accepted = await unwrap(this.remote.save({ expectedRevision: snapshot3.globalRevision, edits }));
|
|
7627
6586
|
acceptedRefreshRequired = accepted.refreshRequired === true || accepted.revision === "unavailable";
|
|
7628
6587
|
} else {
|
|
7629
|
-
if (current.nativeRevision !==
|
|
6588
|
+
if (current.nativeRevision !== snapshot3.nativeRevision || !this.canWriteProfile(current)) throw new Refusal("conflict");
|
|
7630
6589
|
const form = this.form;
|
|
7631
|
-
if (!await form.mutate(edits.map(nativePathEdit),
|
|
6590
|
+
if (!await form.mutate(edits.map(nativePathEdit), snapshot3.nativeFormRevision)) throw new Refusal("unconfirmed");
|
|
7632
6591
|
}
|
|
7633
6592
|
if (this.disposed || generation !== this.generation) return;
|
|
7634
6593
|
this.baseline = structuredClone(draft2);
|
|
@@ -7638,7 +6597,7 @@ var DeploymentController = class _DeploymentController {
|
|
|
7638
6597
|
try {
|
|
7639
6598
|
const next = await unwrap(this.remote.describeSettings());
|
|
7640
6599
|
if (!this.disposed && generation === this.generation) {
|
|
7641
|
-
if (next.entryId !==
|
|
6600
|
+
if (next.entryId !== snapshot3.entryId || next.hostProfileKey !== snapshot3.hostProfileKey || next.globalRevision === "unavailable" || this.layer === "profile" && next.nativeRevision === "unavailable") this.publish({ refreshRequired: true });
|
|
7642
6601
|
else {
|
|
7643
6602
|
this.baseline = structuredClone(this.layer === "global" ? next.global : record2(next.nativeForm?.user) ? next.nativeForm.user : {});
|
|
7644
6603
|
this.publish({ snapshot: next, draft: structuredClone(this.baseline), refreshRequired: false });
|
|
@@ -7720,12 +6679,12 @@ var DeploymentWorkspace = class {
|
|
|
7720
6679
|
this.changed();
|
|
7721
6680
|
}
|
|
7722
6681
|
sync() {
|
|
7723
|
-
const
|
|
6682
|
+
const snapshot3 = this.core.getSnapshot().snapshot;
|
|
7724
6683
|
const issue = this.core.getSnapshot().issue, blocked = issue === "unavailable" || issue === "not-owned" || issue === "transport", restored = this.sourceBlocked && !blocked;
|
|
7725
6684
|
this.sourceBlocked = blocked;
|
|
7726
|
-
const key =
|
|
7727
|
-
const changedGlobal =
|
|
7728
|
-
this.globalVersion =
|
|
6685
|
+
const key = snapshot3?.namespace == null ? null : JSON.stringify([snapshot3.hostProfileKey, snapshot3.entryId, snapshot3.namespace]);
|
|
6686
|
+
const changedGlobal = snapshot3?.globalRevision !== this.globalVersion;
|
|
6687
|
+
this.globalVersion = snapshot3?.globalRevision;
|
|
7729
6688
|
if (key === this.identity) {
|
|
7730
6689
|
if (blocked) this.state.native?.attachForm(null);
|
|
7731
6690
|
else if (restored) this.attachCurrentForm?.();
|
|
@@ -7737,12 +6696,12 @@ var DeploymentWorkspace = class {
|
|
|
7737
6696
|
this.stopNative?.();
|
|
7738
6697
|
this.attachCurrentForm = void 0;
|
|
7739
6698
|
let native = null;
|
|
7740
|
-
if (key !== null &&
|
|
7741
|
-
native = this.profiles.get(key) ?? this.core.forProfile(
|
|
6699
|
+
if (key !== null && snapshot3 !== null) {
|
|
6700
|
+
native = this.profiles.get(key) ?? this.core.forProfile(snapshot3.namespace);
|
|
7742
6701
|
this.profiles.set(key, native);
|
|
7743
6702
|
this.stopNative = native.subscribe(() => this.changed());
|
|
7744
6703
|
if (this.forms !== null) {
|
|
7745
|
-
const form = this.forms.get(
|
|
6704
|
+
const form = this.forms.get(snapshot3.namespace);
|
|
7746
6705
|
const attach = () => {
|
|
7747
6706
|
native.attachForm(this.sourceBlocked ? null : { state: form.getSnapshot(), mutate: (ops, revision2) => form.mutate(ops, revision2) });
|
|
7748
6707
|
this.changed();
|
|
@@ -7763,9 +6722,9 @@ var DeploymentWorkspace = class {
|
|
|
7763
6722
|
defaultSection(scope) {
|
|
7764
6723
|
const restored = this.visited[scope];
|
|
7765
6724
|
if (restored !== null) return restored;
|
|
7766
|
-
const
|
|
7767
|
-
if (
|
|
7768
|
-
const schema = scopeSchema(
|
|
6725
|
+
const snapshot3 = this.controller(scope)?.getSnapshot().snapshot;
|
|
6726
|
+
if (snapshot3 !== null && snapshot3 !== void 0) {
|
|
6727
|
+
const schema = scopeSchema(snapshot3, scope);
|
|
7769
6728
|
for (const module2 of CONFIG_MODULES) if (module2 !== "state" && moduleFields(schema, module2, scope).length > 0) return module2;
|
|
7770
6729
|
}
|
|
7771
6730
|
return "state";
|
|
@@ -8446,6 +7405,178 @@ var permissionZh = {
|
|
|
8446
7405
|
// src/client/NativeCommandEntries.tsx
|
|
8447
7406
|
var import_react6 = require("react");
|
|
8448
7407
|
var import_dsh_client_ui_primitives6 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
7408
|
+
|
|
7409
|
+
// src/permission-errors.ts
|
|
7410
|
+
var PermissionRefusal = class extends Error {
|
|
7411
|
+
constructor(code) {
|
|
7412
|
+
super("The Host refused the permission operation.");
|
|
7413
|
+
this.code = code;
|
|
7414
|
+
}
|
|
7415
|
+
};
|
|
7416
|
+
|
|
7417
|
+
// src/permission-rules.ts
|
|
7418
|
+
function invalid() {
|
|
7419
|
+
throw new PermissionRefusal("validation");
|
|
7420
|
+
}
|
|
7421
|
+
function permissionRuleRow(value, required, optional2 = []) {
|
|
7422
|
+
if (value === null || typeof value !== "object" || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) invalid();
|
|
7423
|
+
const fields = Object.getOwnPropertyDescriptors(value);
|
|
7424
|
+
if (Reflect.ownKeys(value).some((key) => typeof key !== "string" || !required.includes(key) && !optional2.includes(key)) || required.some((key) => !Object.hasOwn(fields, key)) || Object.values(fields).some((field) => !Object.hasOwn(field, "value") || !field.enumerable)) invalid();
|
|
7425
|
+
return value;
|
|
7426
|
+
}
|
|
7427
|
+
function text2(value, max = 32768) {
|
|
7428
|
+
if (typeof value !== "string" || value.length === 0 || value.length > max || value.includes("\0")) invalid();
|
|
7429
|
+
return value;
|
|
7430
|
+
}
|
|
7431
|
+
function permissionRevision(value) {
|
|
7432
|
+
return text2(value, 4096);
|
|
7433
|
+
}
|
|
7434
|
+
function integer2(value) {
|
|
7435
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) invalid();
|
|
7436
|
+
return value;
|
|
7437
|
+
}
|
|
7438
|
+
function ruleAction(value, inherit = false) {
|
|
7439
|
+
if (typeof value !== "string" || !(inherit ? ["inherit", "allow", "ask", "deny"] : ["allow", "ask", "deny"]).includes(value)) invalid();
|
|
7440
|
+
return value;
|
|
7441
|
+
}
|
|
7442
|
+
function draft(value, persisted = false) {
|
|
7443
|
+
const input = permissionRuleRow(value, ["id", "action", "match", ...persisted ? ["source", "revision", "revoked"] : []]);
|
|
7444
|
+
const kind = permissionRuleRow(input.match, ["kind"], ["path", "scope", "executable", "command", "workingDirectory"]).kind;
|
|
7445
|
+
let match;
|
|
7446
|
+
if (kind === "outside-read") {
|
|
7447
|
+
const row = permissionRuleRow(input.match, ["kind", "path", "scope"]);
|
|
7448
|
+
if (row.scope !== "exact" && row.scope !== "tree") invalid();
|
|
7449
|
+
match = { kind, path: text2(row.path), scope: row.scope };
|
|
7450
|
+
} else if (kind === "shell") {
|
|
7451
|
+
const row = permissionRuleRow(input.match, ["kind", "executable", "command", "workingDirectory"]);
|
|
7452
|
+
match = { kind, executable: text2(row.executable), command: text2(row.command), workingDirectory: text2(row.workingDirectory) };
|
|
7453
|
+
} else if (kind === "webSearch" || kind === "webFetch") {
|
|
7454
|
+
permissionRuleRow(input.match, ["kind"]);
|
|
7455
|
+
match = { kind };
|
|
7456
|
+
} else invalid();
|
|
7457
|
+
return Object.freeze({ id: text2(input.id, 256), action: ruleAction(input.action), match: Object.freeze(match) });
|
|
7458
|
+
}
|
|
7459
|
+
function parsePermissionRules(value) {
|
|
7460
|
+
if (!Array.isArray(value) || value.length > 1024) invalid();
|
|
7461
|
+
const ids = /* @__PURE__ */ new Set();
|
|
7462
|
+
return Object.freeze(value.map((item) => {
|
|
7463
|
+
const parsed = draft(item, true), row = item;
|
|
7464
|
+
if (ids.has(parsed.id) || typeof row.revoked !== "boolean") invalid();
|
|
7465
|
+
ids.add(parsed.id);
|
|
7466
|
+
const sourceRow = permissionRuleRow(row.source, ["kind"], ["sessionId", "savedAt", "label"]);
|
|
7467
|
+
let source;
|
|
7468
|
+
if (sourceRow.kind === "operator") {
|
|
7469
|
+
permissionRuleRow(row.source, ["kind", "sessionId", "savedAt"]);
|
|
7470
|
+
source = { kind: "operator", sessionId: text2(sourceRow.sessionId, 256), savedAt: integer2(sourceRow.savedAt) };
|
|
7471
|
+
} else if (sourceRow.kind === "user-import") {
|
|
7472
|
+
permissionRuleRow(row.source, ["kind", "label"]);
|
|
7473
|
+
source = { kind: "user-import", label: text2(sourceRow.label, 512) };
|
|
7474
|
+
} else invalid();
|
|
7475
|
+
return Object.freeze({ ...parsed, source: Object.freeze(source), revision: integer2(row.revision), revoked: row.revoked });
|
|
7476
|
+
}));
|
|
7477
|
+
}
|
|
7478
|
+
function parsePermissionRulesSave(value) {
|
|
7479
|
+
const row = permissionRuleRow(value, ["expectedRevision"], ["changes", "upsert", "revoke"]);
|
|
7480
|
+
let changes;
|
|
7481
|
+
if (row.changes !== void 0) {
|
|
7482
|
+
const input = permissionRuleRow(row.changes, [], ["outsideReads", "webSearch", "webFetch"]);
|
|
7483
|
+
const web = (value2) => {
|
|
7484
|
+
const row2 = permissionRuleRow(value2, ["enabled", "rule"]);
|
|
7485
|
+
if (typeof row2.enabled !== "boolean") invalid();
|
|
7486
|
+
return Object.freeze({ enabled: row2.enabled, rule: ruleAction(row2.rule, true) });
|
|
7487
|
+
};
|
|
7488
|
+
changes = Object.freeze({
|
|
7489
|
+
...input.outsideReads === void 0 ? {} : { outsideReads: ruleAction(input.outsideReads, true) },
|
|
7490
|
+
...input.webSearch === void 0 ? {} : { webSearch: web(input.webSearch) },
|
|
7491
|
+
...input.webFetch === void 0 ? {} : { webFetch: web(input.webFetch) }
|
|
7492
|
+
});
|
|
7493
|
+
}
|
|
7494
|
+
if (row.upsert !== void 0 && (!Array.isArray(row.upsert) || row.upsert.length > 1024) || row.revoke !== void 0 && (!Array.isArray(row.revoke) || row.revoke.length > 1024)) invalid();
|
|
7495
|
+
const upsert = row.upsert?.map((item) => draft(item)), revoke = row.revoke?.map((item) => text2(item, 256));
|
|
7496
|
+
const ids = [...upsert?.map((item) => item.id) ?? [], ...revoke ?? []];
|
|
7497
|
+
if (ids.length !== new Set(ids).size || ids.length === 0 && (changes === void 0 || Object.keys(changes).length === 0)) invalid();
|
|
7498
|
+
return Object.freeze({
|
|
7499
|
+
expectedRevision: permissionRevision(row.expectedRevision),
|
|
7500
|
+
...changes === void 0 ? {} : { changes },
|
|
7501
|
+
...upsert === void 0 ? {} : { upsert: Object.freeze(upsert) },
|
|
7502
|
+
...revoke === void 0 ? {} : { revoke: Object.freeze(revoke) }
|
|
7503
|
+
});
|
|
7504
|
+
}
|
|
7505
|
+
|
|
7506
|
+
// src/permission-settings.ts
|
|
7507
|
+
function parseNativeCommandPattern(input) {
|
|
7508
|
+
if (typeof input !== "string" || input.length > 32768) throw new PermissionRefusal("validation");
|
|
7509
|
+
const tokens = input.replace(/^[ \t]+|[ \t]+$/gu, "").split(/[ \t]+/u);
|
|
7510
|
+
if (tokens.length !== 2 && (tokens.length !== 3 || tokens[2] !== "*") || tokens[0].length === 0 || /[^\p{L}\p{M}\p{N}_./:=+%\\\-]/u.test(tokens[0])) throw new PermissionRefusal("validation");
|
|
7511
|
+
const subcommands = tokens[1].split("|");
|
|
7512
|
+
if (subcommands.some((value) => value.length === 0 || /[^\p{L}\p{M}\p{N}_./:=+%\-]/u.test(value))) throw new PermissionRefusal("validation");
|
|
7513
|
+
return Object.freeze({ executable: tokens[0], subcommands: Object.freeze(subcommands) });
|
|
7514
|
+
}
|
|
7515
|
+
function parseSimpleCommandPattern(input) {
|
|
7516
|
+
if (typeof input !== "string" || input.length > 32768) throw new PermissionRefusal("validation");
|
|
7517
|
+
const tokens = input.replace(/^[ \t]+|[ \t]+$/gu, "").split(/[ \t]+/u);
|
|
7518
|
+
if (tokens.at(-1) === "*") tokens.pop();
|
|
7519
|
+
if (!tokens.length) throw new PermissionRefusal("validation");
|
|
7520
|
+
return Object.freeze(tokens.map((token, index) => {
|
|
7521
|
+
const values = index === 1 ? token.split("|") : [token];
|
|
7522
|
+
if (values.some((value) => !value.length || /[^\p{L}\p{M}\p{N}_./:=+%\\\-]/u.test(value))) throw new PermissionRefusal("validation");
|
|
7523
|
+
return Object.freeze(values);
|
|
7524
|
+
}));
|
|
7525
|
+
}
|
|
7526
|
+
function parseNativeCommands(input = {}) {
|
|
7527
|
+
const row = permissionRuleRow(input, [], ["enabled", "entries"]);
|
|
7528
|
+
if (row.enabled !== void 0 && typeof row.enabled !== "boolean" || row.entries !== void 0 && (!Array.isArray(row.entries) || row.entries.length > 1024)) throw new PermissionRefusal("validation");
|
|
7529
|
+
const text5 = (value) => {
|
|
7530
|
+
if (typeof value !== "string" || value.trim().length === 0 || value.length > 32768 || value.includes("\0")) throw new PermissionRefusal("validation");
|
|
7531
|
+
return value;
|
|
7532
|
+
};
|
|
7533
|
+
const ids = /* @__PURE__ */ new Set();
|
|
7534
|
+
const entries = (row.entries ?? []).map((value) => {
|
|
7535
|
+
if (typeof value === "string") {
|
|
7536
|
+
parseSimpleCommandPattern(value);
|
|
7537
|
+
return value;
|
|
7538
|
+
}
|
|
7539
|
+
const entry = permissionRuleRow(value, ["id", "mode", "match", "sandboxMode"]);
|
|
7540
|
+
const match = permissionRuleRow(entry.match, ["tool", "workingDirectory", "commandPattern"]);
|
|
7541
|
+
const id2 = text5(entry.id), cwd = text5(match.workingDirectory);
|
|
7542
|
+
if (ids.has(id2) || !["ask", "allow"].includes(entry.mode) || !["bash", "pwsh"].includes(match.tool) || !["workspace-write", "danger-full-access"].includes(entry.sandboxMode) || !/^(?:\/|[a-z]:[\\/]|\\\\[^\\/]+[\\/][^\\/]+(?:[\\/]|$))/iu.test(cwd)) throw new PermissionRefusal("validation");
|
|
7543
|
+
ids.add(id2);
|
|
7544
|
+
parseNativeCommandPattern(match.commandPattern);
|
|
7545
|
+
const parsed = { tool: match.tool, workingDirectory: cwd, commandPattern: match.commandPattern };
|
|
7546
|
+
return Object.freeze({ id: id2, mode: entry.mode, sandboxMode: entry.sandboxMode, match: Object.freeze(parsed) });
|
|
7547
|
+
});
|
|
7548
|
+
return Object.freeze({ enabled: row.enabled ?? false, entries: Object.freeze(entries) });
|
|
7549
|
+
}
|
|
7550
|
+
var webDefault = Object.freeze({ enabled: true, rule: "inherit" });
|
|
7551
|
+
var DEFAULT_PERMISSION_CONTROL = Object.freeze({ enabled: true, outsideReads: "inherit", webSearch: webDefault, webFetch: webDefault, rules: Object.freeze([]), nativeCommands: parseNativeCommands() });
|
|
7552
|
+
function enabled(value) {
|
|
7553
|
+
if (value == null) return true;
|
|
7554
|
+
if (typeof value === "boolean") return value;
|
|
7555
|
+
throw new PermissionRefusal("validation");
|
|
7556
|
+
}
|
|
7557
|
+
function action(value) {
|
|
7558
|
+
if (value == null) return "inherit";
|
|
7559
|
+
if (value === "inherit" || value === "allow" || value === "ask" || value === "deny") return value;
|
|
7560
|
+
throw new PermissionRefusal("validation");
|
|
7561
|
+
}
|
|
7562
|
+
function webPolicy(input) {
|
|
7563
|
+
if (input === void 0) return webDefault;
|
|
7564
|
+
const row = permissionRuleRow(input, [], ["enabled", "rule"]);
|
|
7565
|
+
return Object.freeze({ enabled: enabled(row.enabled), rule: action(row.rule) });
|
|
7566
|
+
}
|
|
7567
|
+
function resolvePermissionControl(input = {}) {
|
|
7568
|
+
const row = permissionRuleRow(input, [], ["enabled", "outsideReads", "webSearch", "webFetch", "rules", "nativeCommands"]);
|
|
7569
|
+
return Object.freeze({
|
|
7570
|
+
enabled: enabled(row.enabled),
|
|
7571
|
+
outsideReads: action(row.outsideReads),
|
|
7572
|
+
webSearch: webPolicy(row.webSearch),
|
|
7573
|
+
webFetch: webPolicy(row.webFetch),
|
|
7574
|
+
rules: parsePermissionRules(row.rules ?? []),
|
|
7575
|
+
nativeCommands: parseNativeCommands(row.nativeCommands)
|
|
7576
|
+
});
|
|
7577
|
+
}
|
|
7578
|
+
|
|
7579
|
+
// src/client/NativeCommandEntries.tsx
|
|
8449
7580
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
8450
7581
|
var ENTRIES_PATH = "permissionControl.nativeCommands.entries";
|
|
8451
7582
|
function validNativeEntries(entries) {
|
|
@@ -8868,7 +7999,7 @@ function ScalarField({ schema, path, controller, inherited, t }) {
|
|
|
8868
7999
|
}
|
|
8869
8000
|
function Field({ schema, path, controller, initiallyOpen = false, disclosures, t }) {
|
|
8870
8001
|
if (schema.type === "transform" && schema.inner !== void 0) schema = schema.inner;
|
|
8871
|
-
const state = (0, import_react8.useSyncExternalStore)(controller.subscribe, controller.getSnapshot),
|
|
8002
|
+
const state = (0, import_react8.useSyncExternalStore)(controller.subscribe, controller.getSnapshot), snapshot3 = state.snapshot, id2 = (0, import_react8.useId)(), name2 = path.join(".");
|
|
8872
8003
|
const [open, setOpen] = (0, import_react8.useState)(disclosures?.get(name2) ?? initiallyOpen);
|
|
8873
8004
|
const expand = (expanded) => {
|
|
8874
8005
|
disclosures?.set(name2, expanded);
|
|
@@ -8892,7 +8023,7 @@ function Field({ schema, path, controller, initiallyOpen = false, disclosures, t
|
|
|
8892
8023
|
});
|
|
8893
8024
|
}
|
|
8894
8025
|
};
|
|
8895
|
-
const explicit = at(state.draft, path), inherited = controller.layer === "global" ? at(
|
|
8026
|
+
const explicit = at(state.draft, path), inherited = controller.layer === "global" ? at(snapshot3.defaults, path) : at(mergeLayer(mergeLayer(snapshot3.defaults, snapshot3.global), snapshot3.nativeForm?.base ?? {}), path);
|
|
8896
8027
|
const choices = enumValues(schema), disabled = !controller.canEdit();
|
|
8897
8028
|
const choiceLabel = (value) => name2 === "guards.gitWriteScope" && (value === "all-writes" || value === "high-risk") ? t(value === "all-writes" ? "gitWriteAllWrites" : "gitWriteHighRisk") : displayValue(value, t);
|
|
8898
8029
|
if (name2 === "permissionControl.nativeCommands.entries") return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { "data-field": name2, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(NativeCommandEntries, { controller, value: explicit, inherited: inherited ?? [], disabled, onChange: (value) => controller.edit(path, value), setInvalid: (key, bad) => controller.setInvalid(key, bad), t: permissionText(t) }) });
|
|
@@ -8907,7 +8038,7 @@ function Field({ schema, path, controller, initiallyOpen = false, disclosures, t
|
|
|
8907
8038
|
Object.entries(schema.fields).map(([key, node]) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Field, { schema: node, path: [...path, key], controller, disclosures, t }, key))
|
|
8908
8039
|
] })
|
|
8909
8040
|
] });
|
|
8910
|
-
if (!["boolean", "string", "number"].includes(schema.type) && choices === null) return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(AdvancedField, { schema, path, controller, inherited, upper: controller.layer === "global" ? at(
|
|
8041
|
+
if (!["boolean", "string", "number"].includes(schema.type) && choices === null) return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(AdvancedField, { schema, path, controller, inherited, upper: controller.layer === "global" ? at(snapshot3.profile, path) : void 0, expanded: open, onExpandedChange: expand, t });
|
|
8911
8042
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "dsmm-field dsmm-deployment-field", "data-field": name2, children: [
|
|
8912
8043
|
schema.type === "boolean" || choices !== null ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
|
|
8913
8044
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("label", { htmlFor: id2, children: fieldLabel(path, t) }),
|
|
@@ -8967,9 +8098,9 @@ function parseCapabilities(value) {
|
|
|
8967
8098
|
}, runtime: parseRuntime(input.runtime), tools };
|
|
8968
8099
|
}
|
|
8969
8100
|
function parsePermissionRulesResult(value) {
|
|
8970
|
-
const input = permissionRuleRow(value, ["snapshot", "runtime"], ["capabilities"]),
|
|
8101
|
+
const input = permissionRuleRow(value, ["snapshot", "runtime"], ["capabilities"]), snapshot3 = permissionRuleRow(input.snapshot, ["revision", "policy"]);
|
|
8971
8102
|
return {
|
|
8972
|
-
snapshot: { revision: permissionRevision(
|
|
8103
|
+
snapshot: { revision: permissionRevision(snapshot3.revision), policy: resolvePermissionControl(snapshot3.policy) },
|
|
8973
8104
|
runtime: parseRuntime(input.runtime),
|
|
8974
8105
|
...Object.hasOwn(input, "capabilities") ? { capabilities: parseCapabilities(input.capabilities) } : {}
|
|
8975
8106
|
};
|
|
@@ -9600,26 +8731,26 @@ function NativeRuntimeState({ value, t }) {
|
|
|
9600
8731
|
] });
|
|
9601
8732
|
}
|
|
9602
8733
|
function StateInspector({ controller, t }) {
|
|
9603
|
-
const { snapshot:
|
|
9604
|
-
if (
|
|
8734
|
+
const { snapshot: snapshot3, session, dirty, issue } = (0, import_react10.useSyncExternalStore)(controller.subscribe, controller.getSnapshot);
|
|
8735
|
+
if (snapshot3 === null) return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { children: t("unavailable") });
|
|
9605
8736
|
const admitted = session?.configuration ?? null;
|
|
9606
8737
|
const source = (value2) => t(value2 === "profile" ? "profileSource" : value2 === "global" ? "globalSource" : value2 === "defaults" ? "defaultsSource" : value2 === "named-session" ? "namedSource" : value2 === "startup" ? "startupSource" : value2 === "deployment" ? "deploymentCapture" : value2 === "mixed" ? "mixedSource" : "unknown");
|
|
9607
8738
|
const value = (layer, path) => layer === void 0 ? t("unknown") : at(layer, path.split(".")) === void 0 ? t("absent") : displayValue(at(layer, path.split(".")), t);
|
|
9608
|
-
const restart = (
|
|
8739
|
+
const restart = (snapshot3.nextRoot?.restartRequired ?? []).filter((path) => visibleDeploymentPath(path.split(".")));
|
|
9609
8740
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "dsmm-structured", children: [
|
|
9610
8741
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { role: "status", children: session === null ? t("noSession") : admitted === null ? t("sessionUnavailable") : t("sessionObserved") }),
|
|
9611
8742
|
(dirty || issue !== null) && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "dsmm-hint", children: t("inspectorStale") }),
|
|
9612
8743
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("p", { children: [
|
|
9613
8744
|
t("globalSource"),
|
|
9614
8745
|
": ",
|
|
9615
|
-
t(configurationVersionState(
|
|
8746
|
+
t(configurationVersionState(snapshot3.globalRevision)),
|
|
9616
8747
|
" · ",
|
|
9617
8748
|
t("profileSource"),
|
|
9618
8749
|
": ",
|
|
9619
|
-
t(configurationVersionState(
|
|
8750
|
+
t(configurationVersionState(snapshot3.nativeRevision))
|
|
9620
8751
|
] }),
|
|
9621
|
-
|
|
9622
|
-
|
|
8752
|
+
snapshot3.subagentRuntime !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(NativeRuntimeState, { value: snapshot3.subagentRuntime, t }),
|
|
8753
|
+
snapshot3.modules.map((module2) => /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("section", { className: "dsmm-zone", children: [
|
|
9623
8754
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h3", { children: module2.descriptor.label }),
|
|
9624
8755
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("p", { children: [
|
|
9625
8756
|
t("desired"),
|
|
@@ -9640,28 +8771,28 @@ function StateInspector({ controller, t }) {
|
|
|
9640
8771
|
] }),
|
|
9641
8772
|
module2.pending && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { children: t("pending") })
|
|
9642
8773
|
] }, module2.descriptor.id)),
|
|
9643
|
-
inspectorPaths(
|
|
8774
|
+
inspectorPaths(snapshot3, admitted).map((path) => /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("dl", { className: "dsmm-deployment-state", children: [
|
|
9644
8775
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("dt", { children: path }),
|
|
9645
8776
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("dd", { children: [
|
|
9646
8777
|
t("desired"),
|
|
9647
8778
|
": ",
|
|
9648
|
-
value(
|
|
8779
|
+
value(snapshot3.desired, path),
|
|
9649
8780
|
" · ",
|
|
9650
|
-
source(
|
|
8781
|
+
source(snapshot3.sources[path])
|
|
9651
8782
|
] }),
|
|
9652
8783
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("dd", { children: [
|
|
9653
8784
|
t("startup"),
|
|
9654
8785
|
": ",
|
|
9655
|
-
value(
|
|
8786
|
+
value(snapshot3.startup, path),
|
|
9656
8787
|
" · ",
|
|
9657
|
-
source(
|
|
8788
|
+
source(snapshot3.startupSources?.[path])
|
|
9658
8789
|
] }),
|
|
9659
8790
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("dd", { children: [
|
|
9660
8791
|
t("next"),
|
|
9661
8792
|
": ",
|
|
9662
|
-
value(
|
|
8793
|
+
value(snapshot3.nextRoot?.settings, path),
|
|
9663
8794
|
" · ",
|
|
9664
|
-
source(
|
|
8795
|
+
source(snapshot3.nextRoot?.sources[path])
|
|
9665
8796
|
] }),
|
|
9666
8797
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("dd", { children: [
|
|
9667
8798
|
t("session"),
|
|
@@ -9688,7 +8819,7 @@ function DeploymentPage(props) {
|
|
|
9688
8819
|
const scopeControl = (0, import_react10.useRef)(null), confirmation = (0, import_react10.useRef)(null);
|
|
9689
8820
|
const resume = (0, import_react10.useRef)(null);
|
|
9690
8821
|
const disclosures = (0, import_react10.useRef)({ global: /* @__PURE__ */ new Map(), profile: /* @__PURE__ */ new Map() });
|
|
9691
|
-
const { t } = props,
|
|
8822
|
+
const { t } = props, snapshot3 = state.snapshot ?? core.snapshot, active = navigation.module;
|
|
9692
8823
|
(0, import_react10.useEffect)(() => {
|
|
9693
8824
|
if (props.view === "page") void props.core.refresh();
|
|
9694
8825
|
}, [props.core, props.view]);
|
|
@@ -9708,17 +8839,17 @@ function DeploymentPage(props) {
|
|
|
9708
8839
|
resume.current = { element: document.activeElement, scope: navigation.scope, module: active };
|
|
9709
8840
|
confirmation.current?.focus();
|
|
9710
8841
|
} else if (resume.current !== null) {
|
|
9711
|
-
const
|
|
8842
|
+
const from = resume.current;
|
|
9712
8843
|
resume.current = null;
|
|
9713
|
-
if (
|
|
9714
|
-
if (
|
|
8844
|
+
if (from.scope === navigation.scope && from.module === active) {
|
|
8845
|
+
if (from.element.isConnected) from.element.focus();
|
|
9715
8846
|
} else if (active !== null) heading.current?.focus();
|
|
9716
|
-
else if (
|
|
8847
|
+
else if (from.scope !== navigation.scope) scopeControl.current?.focus();
|
|
9717
8848
|
}
|
|
9718
8849
|
}, [navigation.pending, navigation.scope, active]);
|
|
9719
8850
|
if (props.view === "summary") return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { children: t("summary") });
|
|
9720
|
-
const fields =
|
|
9721
|
-
const tabs = NAVIGATION_MODULES.filter((module2) => module2 !== "other" ||
|
|
8851
|
+
const fields = snapshot3 === null || active === null ? [] : moduleFields(scopeSchema(snapshot3, controller.layer), active, controller.layer);
|
|
8852
|
+
const tabs = NAVIGATION_MODULES.filter((module2) => module2 !== "other" || snapshot3 === null || moduleFields(snapshot3.schema, "other", "global").length + moduleFields(scopeSchema(snapshot3, "profile"), "other", "profile").length > 0);
|
|
9722
8853
|
const select = (module2) => workspace.request({ scope: navigation.scope, module: module2 });
|
|
9723
8854
|
const onTabKey = (event, index) => {
|
|
9724
8855
|
const last = tabs.length - 1, move = (target) => {
|
|
@@ -9824,9 +8955,9 @@ function json(value, depth2 = 0, active = /* @__PURE__ */ new Set()) {
|
|
|
9824
8955
|
const isArray = Array.isArray(value);
|
|
9825
8956
|
if (Object.getPrototypeOf(value) !== (isArray ? Array.prototype : Object.prototype) && (isArray || Object.getPrototypeOf(value) !== null)) fail4();
|
|
9826
8957
|
if (Object.getOwnPropertySymbols(value).length) fail4();
|
|
9827
|
-
for (const [key,
|
|
8958
|
+
for (const [key, property] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
|
|
9828
8959
|
if (isArray && key === "length") continue;
|
|
9829
|
-
if (!Object.hasOwn(
|
|
8960
|
+
if (!Object.hasOwn(property, "value") || !property.enumerable || ["__proto__", "prototype", "constructor"].includes(key) || isArray && !/^(0|[1-9][0-9]*)$/u.test(key)) fail4();
|
|
9830
8961
|
}
|
|
9831
8962
|
if (isArray && Object.keys(value).length !== value.length) fail4();
|
|
9832
8963
|
active.add(value);
|
|
@@ -9973,12 +9104,12 @@ function roleCall(value) {
|
|
|
9973
9104
|
};
|
|
9974
9105
|
}
|
|
9975
9106
|
if (Object.hasOwn(row, "kind") && row.kind !== "role") fail4();
|
|
9976
|
-
const
|
|
9977
|
-
if (
|
|
9107
|
+
const role2 = parseDsmmRoleId(row.role);
|
|
9108
|
+
if (role2 === "dsmm-orchestrator") fail4();
|
|
9978
9109
|
return {
|
|
9979
9110
|
...common,
|
|
9980
9111
|
...row.kind === "role" ? { kind: "role" } : {},
|
|
9981
|
-
role:
|
|
9112
|
+
role: role2,
|
|
9982
9113
|
level: choice(row.level, ["normal", "low", "high", "max"]),
|
|
9983
9114
|
routeSource: choice(row.routeSource, DSMM_ROUTE_SOURCES),
|
|
9984
9115
|
initialRoute
|
|
@@ -10002,7 +9133,7 @@ function observationFrame(value) {
|
|
|
10002
9133
|
if (row.type !== "remove") fail4();
|
|
10003
9134
|
return { type: "remove", sessionId: sessionId2, admissionEpoch, callId: callIdentity(row.callId) };
|
|
10004
9135
|
}
|
|
10005
|
-
function
|
|
9136
|
+
function snapshot2(value) {
|
|
10006
9137
|
const row = object2(value, ["sessionId", "admissionEpoch", "children", "capabilities"]);
|
|
10007
9138
|
const sessionId2 = identity(row.sessionId), admissionEpoch = epoch2(row.admissionEpoch), children = array(row.children).map(child);
|
|
10008
9139
|
if (children.some((child2) => child2.parentSessionId !== sessionId2)) fail4();
|
|
@@ -10082,7 +9213,7 @@ function errorInfo2(value) {
|
|
|
10082
9213
|
};
|
|
10083
9214
|
}
|
|
10084
9215
|
var parseRoleControlErrorInfo = (value) => errorInfo2(json(value));
|
|
10085
|
-
var parseChildSessionSnapshot = (value) =>
|
|
9216
|
+
var parseChildSessionSnapshot = (value) => snapshot2(json(value));
|
|
10086
9217
|
var parseRoleControlDescendants = (value) => descendants(json(value));
|
|
10087
9218
|
var parseRoleControlPromptRequest = (value) => promptRequest(json(value));
|
|
10088
9219
|
function codec3(symbol, parse3) {
|
|
@@ -10105,7 +9236,7 @@ function descriptor3(method, result, request, stream = false) {
|
|
|
10105
9236
|
}
|
|
10106
9237
|
var ROLE_CONTROL_REMOTE = { package: "@dsmm/dsmm-children", descriptors: [
|
|
10107
9238
|
descriptor3("observe", codec3("RoleCallObservationFrame", observationFrame), void 0, true),
|
|
10108
|
-
descriptor3("describe", codec3("ChildSessionSnapshot",
|
|
9239
|
+
descriptor3("describe", codec3("ChildSessionSnapshot", snapshot2)),
|
|
10109
9240
|
descriptor3("descendants", codec3("RoleControlDescendantsSnapshot", descendants)),
|
|
10110
9241
|
descriptor3("prompt", codec3("SubagentPromptReceipt", promptReceipt), codec3("SubagentPromptRequest", promptRequest)),
|
|
10111
9242
|
descriptor3("interrupt", codec3("SubagentInterruptReceipt", interruptReceipt), codec3("RoleControlInterruptRequest", interruptRequest))
|
|
@@ -10122,9 +9253,9 @@ function bindPermissionSession(source, sessions, permissions) {
|
|
|
10122
9253
|
observed = binding;
|
|
10123
9254
|
stop = binding?.session.subscribe(update);
|
|
10124
9255
|
}
|
|
10125
|
-
const
|
|
10126
|
-
const child2 =
|
|
10127
|
-
const root = id2 !== void 0 && binding?.sessionId === id2 &&
|
|
9256
|
+
const snapshot3 = binding?.session.getSnapshot(), catalog = sessions.list.getSnapshot(), summary = id2 === void 0 ? void 0 : catalog.byId[id2];
|
|
9257
|
+
const child2 = snapshot3?.subagent != null || summary?.origin === "subagent" || summary?.parentId !== void 0;
|
|
9258
|
+
const root = id2 !== void 0 && binding?.sessionId === id2 && snapshot3?.sessionId === id2 && snapshot3.openState === "open" && !snapshot3.removed && catalog.ids.includes(id2) && summary !== void 0 && !child2;
|
|
10128
9259
|
permissions.bindScope(id2 ?? null, binding ?? null, child2 ? "child" : root ? "root" : "unknown");
|
|
10129
9260
|
};
|
|
10130
9261
|
update();
|
|
@@ -10697,13 +9828,8 @@ function registerRoleToolViews(ctx, observations) {
|
|
|
10697
9828
|
});
|
|
10698
9829
|
}
|
|
10699
9830
|
|
|
10700
|
-
// node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.1-rc.2_@deepseek-ai+cordis@4.0.5/node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
|
|
10701
|
-
function remoteErrorOf(value) {
|
|
10702
|
-
if (typeof value === "object" && value !== null && value.isDSHRemoteError === true && typeof value.code === "string") return value;
|
|
10703
|
-
}
|
|
10704
|
-
var TYPERT_OWNED_VALUE = Symbol.for("dsh.typert.owned-value");
|
|
10705
|
-
|
|
10706
9831
|
// src/client/role-call-observations.ts
|
|
9832
|
+
var import_client = require("@deepseek-ai/dsh-api-gateway/client");
|
|
10707
9833
|
var ObservationProtocolError = class extends Error {
|
|
10708
9834
|
constructor(code) {
|
|
10709
9835
|
super(code);
|
|
@@ -10712,7 +9838,7 @@ var ObservationProtocolError = class extends Error {
|
|
|
10712
9838
|
};
|
|
10713
9839
|
function observationIssue(error) {
|
|
10714
9840
|
if (error instanceof ObservationProtocolError) return { kind: "protocol", code: error.code };
|
|
10715
|
-
const remote =
|
|
9841
|
+
const remote = (0, import_client.isRemoteFailure)(error) ? error : void 0;
|
|
10716
9842
|
if (remote?.code === "dsmm-children/refused") {
|
|
10717
9843
|
try {
|
|
10718
9844
|
return { kind: "domain", ...parseRoleControlErrorInfo(remote.details) };
|
|
@@ -10876,8 +10002,8 @@ var RoleCallObservationSource = class {
|
|
|
10876
10002
|
})]));
|
|
10877
10003
|
this.publish({ ...this.snapshot, status, issue, calls });
|
|
10878
10004
|
}
|
|
10879
|
-
publish(
|
|
10880
|
-
this.snapshot =
|
|
10005
|
+
publish(snapshot3) {
|
|
10006
|
+
this.snapshot = snapshot3;
|
|
10881
10007
|
for (const listener of this.listeners) listener();
|
|
10882
10008
|
}
|
|
10883
10009
|
};
|
|
@@ -10907,7 +10033,7 @@ function profileBlankNative(services) {
|
|
|
10907
10033
|
// src/client/children-controller.ts
|
|
10908
10034
|
var EMPTY_CHILD_DRAFT = { text: "", delivery: "queue", images: [], imageBusy: false, uncertain: false };
|
|
10909
10035
|
var childActionKey = (childId) => `child:${childId}`;
|
|
10910
|
-
function
|
|
10036
|
+
function enabled2(availability2) {
|
|
10911
10037
|
return availability2?.enabled === true;
|
|
10912
10038
|
}
|
|
10913
10039
|
var ControlFailure = class extends Error {
|
|
@@ -11077,12 +10203,12 @@ var ChildrenController = class {
|
|
|
11077
10203
|
this.publish({ reading: false, issue: this.issue(description.reason), descendants: null });
|
|
11078
10204
|
return;
|
|
11079
10205
|
}
|
|
11080
|
-
const
|
|
11081
|
-
if (
|
|
10206
|
+
const snapshot3 = parseChildSessionSnapshot(description.value);
|
|
10207
|
+
if (snapshot3.sessionId !== id2) {
|
|
11082
10208
|
this.publish({ reading: false, issue: { kind: "protocol", code: "not-owned" }, descendants: null });
|
|
11083
10209
|
return;
|
|
11084
10210
|
}
|
|
11085
|
-
if (this.observedAdmission !== null &&
|
|
10211
|
+
if (this.observedAdmission !== null && snapshot3.admissionEpoch !== this.observedAdmission) {
|
|
11086
10212
|
this.publish({ reading: false, issue: { kind: "protocol", code: "conflict" }, descendants: null });
|
|
11087
10213
|
return;
|
|
11088
10214
|
}
|
|
@@ -11090,12 +10216,12 @@ var ChildrenController = class {
|
|
|
11090
10216
|
if (descendants2.status === "rejected") descendantIssue = this.issue(descendants2.reason);
|
|
11091
10217
|
else {
|
|
11092
10218
|
tree = parseRoleControlDescendants(descendants2.value);
|
|
11093
|
-
if (tree.sessionId !== id2 || tree.admissionEpoch !==
|
|
10219
|
+
if (tree.sessionId !== id2 || tree.admissionEpoch !== snapshot3.admissionEpoch) {
|
|
11094
10220
|
tree = null;
|
|
11095
10221
|
descendantIssue = { kind: "protocol", code: "conflict" };
|
|
11096
10222
|
}
|
|
11097
10223
|
}
|
|
11098
|
-
this.publish({ snapshot:
|
|
10224
|
+
this.publish({ snapshot: snapshot3, descendants: tree, descendantIssue, fresh: true, reading: false, generation: generation + 1 });
|
|
11099
10225
|
}
|
|
11100
10226
|
begin(key, kind) {
|
|
11101
10227
|
const pending = new Map(this.current.pending), issues = new Map(this.current.issues), outcomes = new Map(this.current.outcomes);
|
|
@@ -11121,11 +10247,11 @@ var ChildrenController = class {
|
|
|
11121
10247
|
}
|
|
11122
10248
|
canControl(generation, id2, action2) {
|
|
11123
10249
|
const child2 = this.child(id2);
|
|
11124
|
-
return this.available(generation) && !this.current.pending.has(childActionKey(id2)) && child2?.mode === "continuable" && !child2.readonly &&
|
|
10250
|
+
return this.available(generation) && !this.current.pending.has(childActionKey(id2)) && child2?.mode === "continuable" && !child2.readonly && enabled2(child2.controls[action2]) && enabled2(this.current.snapshot?.capabilities[action2]);
|
|
11125
10251
|
}
|
|
11126
10252
|
async prompt(generation, id2) {
|
|
11127
10253
|
const draft2 = this.draft(id2), key = childActionKey(id2);
|
|
11128
|
-
if (!this.canControl(generation, id2, "prompt") || draft2.uncertain || draft2.imageBusy || draft2.text.trim() === "" && draft2.images.length === 0 || draft2.images.length > 0 && !
|
|
10254
|
+
if (!this.canControl(generation, id2, "prompt") || draft2.uncertain || draft2.imageBusy || draft2.text.trim() === "" && draft2.images.length === 0 || draft2.images.length > 0 && !enabled2(this.current.snapshot?.capabilities.images)) return;
|
|
11129
10255
|
this.begin(key, "prompt");
|
|
11130
10256
|
try {
|
|
11131
10257
|
let clientTimeZone;
|
|
@@ -11181,7 +10307,7 @@ var ChildrenController = class {
|
|
|
11181
10307
|
}
|
|
11182
10308
|
}
|
|
11183
10309
|
async addImages(generation, id2, files) {
|
|
11184
|
-
if (!this.canControl(generation, id2, "prompt") || !
|
|
10310
|
+
if (!this.canControl(generation, id2, "prompt") || !enabled2(this.current.snapshot?.capabilities.images) || this.draft(id2).imageBusy || files.length === 0) return;
|
|
11185
10311
|
this.editDraft(generation, id2, { imageBusy: true });
|
|
11186
10312
|
try {
|
|
11187
10313
|
const images = [];
|
|
@@ -11322,9 +10448,9 @@ function ChildComposer({ child: child2, state, actions: actions3, t }) {
|
|
|
11322
10448
|
const prefix = (0, import_react12.useId)(), picker = (0, import_react12.useRef)(null), generation = state.generation, key = childActionKey(child2.id);
|
|
11323
10449
|
const draft2 = state.drafts.get(child2.id) ?? EMPTY_CHILD_DRAFT;
|
|
11324
10450
|
const pending = state.pending.has(key), available = state.fresh && !state.reading && !pending;
|
|
11325
|
-
const canPrompt = available &&
|
|
11326
|
-
const canImages = canPrompt &&
|
|
11327
|
-
const submit = canPrompt && !draft2.uncertain && !draft2.imageBusy && (draft2.text.trim() !== "" || draft2.images.length > 0) && (draft2.images.length === 0 ||
|
|
10451
|
+
const canPrompt = available && enabled2(state.snapshot?.capabilities.prompt) && enabled2(child2.controls.prompt) && !child2.readonly && child2.mode === "continuable";
|
|
10452
|
+
const canImages = canPrompt && enabled2(state.snapshot?.capabilities.images) && !draft2.imageBusy;
|
|
10453
|
+
const submit = canPrompt && !draft2.uncertain && !draft2.imageBusy && (draft2.text.trim() !== "" || draft2.images.length > 0) && (draft2.images.length === 0 || enabled2(state.snapshot?.capabilities.images));
|
|
11328
10454
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("form", { className: "dsmm-child-composer", "aria-label": t("prompt"), onSubmit: (event) => {
|
|
11329
10455
|
event.preventDefault();
|
|
11330
10456
|
if (submit) void actions3.prompt(generation, child2.id);
|
|
@@ -11380,9 +10506,9 @@ function ChildComposer({ child: child2, state, actions: actions3, t }) {
|
|
|
11380
10506
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { id: `${prefix}-unknown`, children: t("unknown") }),
|
|
11381
10507
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_dsh_client_ui_primitives13.Button, { type: "button", variant: "outline", disabled: !state.fresh || state.reading || pending, onClick: () => actions3.acknowledgeUnknown(generation, child2.id), children: t("acknowledge") })
|
|
11382
10508
|
] }),
|
|
11383
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ControlAvailability, { value: !
|
|
10509
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ControlAvailability, { value: !enabled2(state.snapshot?.capabilities.prompt) ? state.snapshot?.capabilities.prompt : child2.controls.prompt, label: "promptAvailability", t }),
|
|
11384
10510
|
draft2.text.trim() === "" && draft2.images.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "dsmm-hint", children: t("emptyMessage") }),
|
|
11385
|
-
draft2.images.length > 0 && !
|
|
10511
|
+
draft2.images.length > 0 && !enabled2(state.snapshot?.capabilities.images) && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "dsmm-hint", children: t("deniedImages") }),
|
|
11386
10512
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "dsmm-actions", children: [
|
|
11387
10513
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_dsh_client_ui_primitives13.Button, { type: "submit", variant: "primary", disabled: !submit, children: t("send") }),
|
|
11388
10514
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
@@ -11390,7 +10516,7 @@ function ChildComposer({ child: child2, state, actions: actions3, t }) {
|
|
|
11390
10516
|
{
|
|
11391
10517
|
type: "button",
|
|
11392
10518
|
variant: "outline",
|
|
11393
|
-
disabled: !available || !
|
|
10519
|
+
disabled: !available || !enabled2(state.snapshot?.capabilities.interrupt) || !enabled2(child2.controls.interrupt) || child2.readonly || child2.mode !== "continuable",
|
|
11394
10520
|
onClick: () => void actions3.interrupt(generation, child2.id),
|
|
11395
10521
|
children: t("interrupt")
|
|
11396
10522
|
}
|
|
@@ -11436,7 +10562,7 @@ function ChildDetails({ child: child2, state, actions: actions3, t, inspection =
|
|
|
11436
10562
|
] });
|
|
11437
10563
|
}
|
|
11438
10564
|
function ChildrenPanel(props) {
|
|
11439
|
-
const state = props.useChildren((
|
|
10565
|
+
const state = props.useChildren((snapshot3) => snapshot3), { t } = props, generation = state.generation;
|
|
11440
10566
|
if (props.sessionId === void 0 || props.sessionId !== state.sessionId) return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("section", { className: "dsmm-profiles dsmm-children", children: [
|
|
11441
10567
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("h2", { children: t("title") }),
|
|
11442
10568
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { children: t(state.sessionId === null ? "noSession" : "foreign") })
|