negotium 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-helpers.js +183 -200
- package/dist/agent-helpers.js.map +8 -8
- package/dist/cron.js +231 -220
- package/dist/cron.js.map +10 -10
- package/dist/hosted-agent.js +233 -250
- package/dist/hosted-agent.js.map +9 -9
- package/dist/main.js +391 -395
- package/dist/main.js.map +12 -12
- package/dist/runtime/scripts/browser-webauthn-policy.mjs +37 -0
- package/dist/runtime/scripts/mcp-patchright-http.mjs +8 -3
- package/dist/runtime/src/agents/vault-tool-policy.ts +13 -4
- package/dist/runtime/src/platform/mcp-config.ts +2 -1
- package/dist/runtime/src/platform/playwright/manager.ts +18 -0
- package/dist/runtime/src/prompts/sessions/channel-system.md +1 -1
- package/dist/runtime/src/prompts/sessions/topic-system.md +1 -1
- package/dist/runtime/src/version.ts +1 -1
- package/dist/types/packages/core/src/agents/vault-tool-policy.d.ts +1 -1
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/agent-helpers.js
CHANGED
|
@@ -1787,197 +1787,6 @@ function isSensitivePath(filePath) {
|
|
|
1787
1787
|
return false;
|
|
1788
1788
|
}
|
|
1789
1789
|
|
|
1790
|
-
// ../../packages/core/src/storage/vault.ts
|
|
1791
|
-
import { chmodSync as chmodSync2, mkdirSync as mkdirSync7 } from "fs";
|
|
1792
|
-
import { join as join10 } from "path";
|
|
1793
|
-
|
|
1794
|
-
// ../../packages/core/src/storage/vault-crypto.ts
|
|
1795
|
-
import { createCipheriv, createDecipheriv, createHash, randomBytes as randomBytes3 } from "crypto";
|
|
1796
|
-
var ENVELOPE_PREFIX = "otium-vault:v1:";
|
|
1797
|
-
var IV_BYTES = 12;
|
|
1798
|
-
var KEY_BYTES = 32;
|
|
1799
|
-
function encryptionKey(masterKey = VAULT_MASTER_KEY) {
|
|
1800
|
-
return createHash("sha256").update("otium-vault-value-v1\x00", "utf8").update(masterKey, "utf8").digest().subarray(0, KEY_BYTES);
|
|
1801
|
-
}
|
|
1802
|
-
function aad(userId, key) {
|
|
1803
|
-
return Buffer.from(`${userId}\x00${key.toUpperCase()}`, "utf8");
|
|
1804
|
-
}
|
|
1805
|
-
function isEncryptedVaultValue(value) {
|
|
1806
|
-
return value.startsWith(ENVELOPE_PREFIX);
|
|
1807
|
-
}
|
|
1808
|
-
function encryptVaultValue(userId, key, value, masterKey = VAULT_MASTER_KEY) {
|
|
1809
|
-
const iv = randomBytes3(IV_BYTES);
|
|
1810
|
-
const cipher = createCipheriv("aes-256-gcm", encryptionKey(masterKey), iv);
|
|
1811
|
-
cipher.setAAD(aad(userId, key));
|
|
1812
|
-
const ciphertext = Buffer.concat([cipher.update(value, "utf8"), cipher.final()]);
|
|
1813
|
-
const tag = cipher.getAuthTag();
|
|
1814
|
-
return `${ENVELOPE_PREFIX}${iv.toString("base64url")}.${ciphertext.toString("base64url")}.${tag.toString("base64url")}`;
|
|
1815
|
-
}
|
|
1816
|
-
function decryptVaultValue(userId, key, storedValue, masterKey = VAULT_MASTER_KEY) {
|
|
1817
|
-
if (!isEncryptedVaultValue(storedValue)) {
|
|
1818
|
-
return { value: storedValue, legacyPlaintext: true };
|
|
1819
|
-
}
|
|
1820
|
-
const encoded = storedValue.slice(ENVELOPE_PREFIX.length);
|
|
1821
|
-
const [ivPart, ciphertextPart, tagPart, ...extra] = encoded.split(".");
|
|
1822
|
-
if (!ivPart || ciphertextPart === undefined || !tagPart || extra.length > 0) {
|
|
1823
|
-
throw new Error("Invalid encrypted vault value");
|
|
1824
|
-
}
|
|
1825
|
-
const iv = Buffer.from(ivPart, "base64url");
|
|
1826
|
-
const ciphertext = Buffer.from(ciphertextPart, "base64url");
|
|
1827
|
-
const tag = Buffer.from(tagPart, "base64url");
|
|
1828
|
-
if (iv.length !== IV_BYTES || tag.length !== 16) {
|
|
1829
|
-
throw new Error("Invalid encrypted vault value");
|
|
1830
|
-
}
|
|
1831
|
-
const decipher = createDecipheriv("aes-256-gcm", encryptionKey(masterKey), iv);
|
|
1832
|
-
decipher.setAAD(aad(userId, key));
|
|
1833
|
-
decipher.setAuthTag(tag);
|
|
1834
|
-
const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
1835
|
-
return { value: plaintext.toString("utf8"), legacyPlaintext: false };
|
|
1836
|
-
}
|
|
1837
|
-
|
|
1838
|
-
// ../../packages/core/src/storage/vault.ts
|
|
1839
|
-
var vaultDb;
|
|
1840
|
-
var vaultMasterKey = VAULT_MASTER_KEY;
|
|
1841
|
-
function initializeVaultDatabase(database) {
|
|
1842
|
-
database.exec("PRAGMA journal_mode = WAL");
|
|
1843
|
-
database.exec("PRAGMA busy_timeout = 5000");
|
|
1844
|
-
database.exec(`
|
|
1845
|
-
CREATE TABLE IF NOT EXISTS vault (
|
|
1846
|
-
user_id TEXT NOT NULL,
|
|
1847
|
-
key TEXT NOT NULL,
|
|
1848
|
-
value TEXT NOT NULL,
|
|
1849
|
-
description TEXT NOT NULL DEFAULT '',
|
|
1850
|
-
PRIMARY KEY (user_id, key)
|
|
1851
|
-
)
|
|
1852
|
-
`);
|
|
1853
|
-
{
|
|
1854
|
-
const cols = database.prepare("PRAGMA table_info(vault)").all();
|
|
1855
|
-
const uid = cols.find((c) => c.name === "user_id");
|
|
1856
|
-
if (uid && uid.type.toUpperCase() === "INTEGER") {
|
|
1857
|
-
database.exec("BEGIN");
|
|
1858
|
-
database.exec(`
|
|
1859
|
-
CREATE TABLE vault_migrated (
|
|
1860
|
-
user_id TEXT NOT NULL,
|
|
1861
|
-
key TEXT NOT NULL,
|
|
1862
|
-
value TEXT NOT NULL,
|
|
1863
|
-
description TEXT NOT NULL DEFAULT '',
|
|
1864
|
-
PRIMARY KEY (user_id, key)
|
|
1865
|
-
)
|
|
1866
|
-
`);
|
|
1867
|
-
database.exec("INSERT INTO vault_migrated SELECT CAST(user_id AS TEXT), key, value, description FROM vault");
|
|
1868
|
-
database.exec("DROP TABLE vault");
|
|
1869
|
-
database.exec("ALTER TABLE vault_migrated RENAME TO vault");
|
|
1870
|
-
database.exec("COMMIT");
|
|
1871
|
-
}
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
function openVaultDatabase(dataDir) {
|
|
1875
|
-
const path = join10(dataDir, "vault.db");
|
|
1876
|
-
mkdirSync7(dataDir, { recursive: true });
|
|
1877
|
-
const database = new Database(path, { create: true });
|
|
1878
|
-
chmodSync2(path, 384);
|
|
1879
|
-
initializeVaultDatabase(database);
|
|
1880
|
-
return database;
|
|
1881
|
-
}
|
|
1882
|
-
function activeVaultDatabase() {
|
|
1883
|
-
if (!vaultDb)
|
|
1884
|
-
vaultDb = openVaultDatabase(DATA_DIR);
|
|
1885
|
-
return vaultDb;
|
|
1886
|
-
}
|
|
1887
|
-
var VAULT_VALUE_MAX_BYTES = 64 * 1024;
|
|
1888
|
-
function normalizeVaultKey(key) {
|
|
1889
|
-
return key.trim().toUpperCase();
|
|
1890
|
-
}
|
|
1891
|
-
function decryptRow(userId, key, storedValue) {
|
|
1892
|
-
const database = activeVaultDatabase();
|
|
1893
|
-
const decoded = decryptVaultValue(userId, key, storedValue, vaultMasterKey);
|
|
1894
|
-
if (decoded.legacyPlaintext) {
|
|
1895
|
-
database.prepare("UPDATE vault SET value = ? WHERE user_id = ? AND key = ? AND value = ?").run(encryptVaultValue(userId, key, decoded.value, vaultMasterKey), userId, key, storedValue);
|
|
1896
|
-
}
|
|
1897
|
-
return decoded.value;
|
|
1898
|
-
}
|
|
1899
|
-
function vaultListWithValues(userId) {
|
|
1900
|
-
const rows = activeVaultDatabase().prepare("SELECT key, description, value FROM vault WHERE user_id = ? ORDER BY key").all(userId);
|
|
1901
|
-
return rows.map((row) => ({
|
|
1902
|
-
key: row.key,
|
|
1903
|
-
description: row.description,
|
|
1904
|
-
value: decryptRow(userId, row.key, row.value)
|
|
1905
|
-
}));
|
|
1906
|
-
}
|
|
1907
|
-
function vaultList(userId) {
|
|
1908
|
-
return activeVaultDatabase().prepare("SELECT key, description FROM vault WHERE user_id = ? ORDER BY key").all(userId);
|
|
1909
|
-
}
|
|
1910
|
-
function vaultSubstituteDetailed(userId, text) {
|
|
1911
|
-
const entries = new Map(vaultListWithValues(userId).map((entry) => [entry.key, entry.value]));
|
|
1912
|
-
const usedKeys = new Set;
|
|
1913
|
-
const substituted = text.replace(/\{\{([^}]+)\}\}/g, (match, rawKey) => {
|
|
1914
|
-
const key = normalizeVaultKey(rawKey);
|
|
1915
|
-
const value = entries.get(key);
|
|
1916
|
-
if (value === undefined)
|
|
1917
|
-
return match;
|
|
1918
|
-
usedKeys.add(key);
|
|
1919
|
-
return value;
|
|
1920
|
-
});
|
|
1921
|
-
return { text: substituted, usedKeys: [...usedKeys] };
|
|
1922
|
-
}
|
|
1923
|
-
function valueReferencesVaultKey(userId, value) {
|
|
1924
|
-
const keys = new Set(vaultList(userId).map((entry) => entry.key));
|
|
1925
|
-
const visit = (candidate) => {
|
|
1926
|
-
if (typeof candidate === "string") {
|
|
1927
|
-
for (const match of candidate.matchAll(/\{\{([^}]+)\}\}/g)) {
|
|
1928
|
-
if (keys.has(normalizeVaultKey(match[1] ?? "")))
|
|
1929
|
-
return true;
|
|
1930
|
-
}
|
|
1931
|
-
return false;
|
|
1932
|
-
}
|
|
1933
|
-
if (Array.isArray(candidate))
|
|
1934
|
-
return candidate.some(visit);
|
|
1935
|
-
if (candidate && typeof candidate === "object") {
|
|
1936
|
-
return Object.values(candidate).some(visit);
|
|
1937
|
-
}
|
|
1938
|
-
return false;
|
|
1939
|
-
};
|
|
1940
|
-
return visit(value);
|
|
1941
|
-
}
|
|
1942
|
-
function encodedSecretForms(value) {
|
|
1943
|
-
const forms = new Set([
|
|
1944
|
-
value,
|
|
1945
|
-
encodeURIComponent(value),
|
|
1946
|
-
Buffer.from(value, "utf8").toString("base64"),
|
|
1947
|
-
Buffer.from(value, "utf8").toString("base64url"),
|
|
1948
|
-
Buffer.from(value, "utf8").toString("hex")
|
|
1949
|
-
]);
|
|
1950
|
-
forms.delete("");
|
|
1951
|
-
return [...forms].sort((a, b) => b.length - a.length);
|
|
1952
|
-
}
|
|
1953
|
-
function redactVaultSecrets(userId, text) {
|
|
1954
|
-
const candidates = vaultListWithValues(userId).flatMap((entry) => encodedSecretForms(entry.value).map((form) => ({ form, key: entry.key }))).sort((a, b) => b.form.length - a.form.length || a.key.localeCompare(b.key));
|
|
1955
|
-
if (candidates.length === 0)
|
|
1956
|
-
return text;
|
|
1957
|
-
const candidatesByFirstCharacter = new Map;
|
|
1958
|
-
for (const candidate of candidates) {
|
|
1959
|
-
const first = candidate.form[0];
|
|
1960
|
-
if (!first)
|
|
1961
|
-
continue;
|
|
1962
|
-
const bucket = candidatesByFirstCharacter.get(first) ?? [];
|
|
1963
|
-
bucket.push(candidate);
|
|
1964
|
-
candidatesByFirstCharacter.set(first, bucket);
|
|
1965
|
-
}
|
|
1966
|
-
let redacted = "";
|
|
1967
|
-
let offset = 0;
|
|
1968
|
-
while (offset < text.length) {
|
|
1969
|
-
const match = candidatesByFirstCharacter.get(text[offset] ?? "")?.find((candidate) => text.startsWith(candidate.form, offset));
|
|
1970
|
-
if (!match) {
|
|
1971
|
-
redacted += text[offset];
|
|
1972
|
-
offset += 1;
|
|
1973
|
-
continue;
|
|
1974
|
-
}
|
|
1975
|
-
redacted += `[REDACTED:${match.key}]`;
|
|
1976
|
-
offset += match.form.length;
|
|
1977
|
-
}
|
|
1978
|
-
return redacted;
|
|
1979
|
-
}
|
|
1980
|
-
|
|
1981
1790
|
// ../../packages/core/src/agents/vault-tool-policy.ts
|
|
1982
1791
|
var SENSITIVE_RUNTIME_NAMES = [
|
|
1983
1792
|
"vault.db",
|
|
@@ -1985,7 +1794,7 @@ var SENSITIVE_RUNTIME_NAMES = [
|
|
|
1985
1794
|
"runtime-mcp-secret",
|
|
1986
1795
|
"sessions.db"
|
|
1987
1796
|
];
|
|
1988
|
-
var VAULT_BROKER_REDIRECT_ERROR = "Vault
|
|
1797
|
+
var VAULT_BROKER_REDIRECT_ERROR = "Vault broker redirection is disabled; use {{KEY}} directly in normal tool inputs.";
|
|
1989
1798
|
function createVaultToolPolicy(host) {
|
|
1990
1799
|
function isVaultBrokerTool(toolName) {
|
|
1991
1800
|
return toolName.includes("vault_run") || toolName.includes("vault_http_request");
|
|
@@ -2005,11 +1814,14 @@ function createVaultToolPolicy(host) {
|
|
|
2005
1814
|
return false;
|
|
2006
1815
|
}
|
|
2007
1816
|
function shouldRedirectVaultTool(userId, toolName, input) {
|
|
2008
|
-
return
|
|
1817
|
+
return false;
|
|
2009
1818
|
}
|
|
2010
1819
|
return { isVaultBrokerTool, referencesRuntimeSecretStorage, shouldRedirectVaultTool };
|
|
2011
1820
|
}
|
|
2012
|
-
var defaultVaultToolPolicy = createVaultToolPolicy({
|
|
1821
|
+
var defaultVaultToolPolicy = createVaultToolPolicy({
|
|
1822
|
+
isSensitivePath,
|
|
1823
|
+
valueReferencesVaultKey: () => false
|
|
1824
|
+
});
|
|
2013
1825
|
var isVaultBrokerTool = defaultVaultToolPolicy.isVaultBrokerTool;
|
|
2014
1826
|
var referencesRuntimeSecretStorage = defaultVaultToolPolicy.referencesRuntimeSecretStorage;
|
|
2015
1827
|
var shouldRedirectVaultTool = defaultVaultToolPolicy.shouldRedirectVaultTool;
|
|
@@ -2089,7 +1901,7 @@ function peerSessionBridgeIpcEnv() {
|
|
|
2089
1901
|
|
|
2090
1902
|
// ../../packages/core/src/platform/background-bash/manager.ts
|
|
2091
1903
|
import { execFileSync as execFileSync3, spawn } from "child_process";
|
|
2092
|
-
import { randomBytes as
|
|
1904
|
+
import { randomBytes as randomBytes3 } from "crypto";
|
|
2093
1905
|
|
|
2094
1906
|
// ../../packages/core/src/platform/delay.ts
|
|
2095
1907
|
var delay = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -2117,8 +1929,8 @@ function createBackgroundBashManager(options = {}) {
|
|
|
2117
1929
|
const usedPorts = new Set;
|
|
2118
1930
|
const spawning = new Map;
|
|
2119
1931
|
const knownContexts = new Map;
|
|
2120
|
-
const runtimeCapability = options.capability ??
|
|
2121
|
-
const runtimeServerId = options.serverId ??
|
|
1932
|
+
const runtimeCapability = options.capability ?? randomBytes3(32).toString("hex");
|
|
1933
|
+
const runtimeServerId = options.serverId ?? randomBytes3(16).toString("hex");
|
|
2122
1934
|
const serverFile = options.serverFile ?? BACKGROUND_BASH_SERVER;
|
|
2123
1935
|
const basePort = options.basePort ?? BG_BASH_BASE_PORT;
|
|
2124
1936
|
const maxPort = options.maxPort ?? BG_BASH_MAX_PORT;
|
|
@@ -2546,7 +2358,9 @@ var MCP_CATALOG = {
|
|
|
2546
2358
|
vault: {
|
|
2547
2359
|
...commonRuntimeMcpPolicy("vault"),
|
|
2548
2360
|
build({ userId, agent }) {
|
|
2549
|
-
const args = [`--user-id=${userId}
|
|
2361
|
+
const args = [`--user-id=${userId}`];
|
|
2362
|
+
if (agent !== "codex")
|
|
2363
|
+
args.push("--list-only=true");
|
|
2550
2364
|
return buildStdioMcpServer(agent, VAULT_SERVER, args);
|
|
2551
2365
|
}
|
|
2552
2366
|
}
|
|
@@ -2764,6 +2578,175 @@ function getMcpServersForQuery(opts) {
|
|
|
2764
2578
|
});
|
|
2765
2579
|
}
|
|
2766
2580
|
|
|
2581
|
+
// ../../packages/core/src/storage/vault.ts
|
|
2582
|
+
import { chmodSync as chmodSync2, mkdirSync as mkdirSync7 } from "fs";
|
|
2583
|
+
import { join as join10 } from "path";
|
|
2584
|
+
|
|
2585
|
+
// ../../packages/core/src/storage/vault-crypto.ts
|
|
2586
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes as randomBytes4 } from "crypto";
|
|
2587
|
+
var ENVELOPE_PREFIX = "otium-vault:v1:";
|
|
2588
|
+
var IV_BYTES = 12;
|
|
2589
|
+
var KEY_BYTES = 32;
|
|
2590
|
+
function encryptionKey(masterKey = VAULT_MASTER_KEY) {
|
|
2591
|
+
return createHash("sha256").update("otium-vault-value-v1\x00", "utf8").update(masterKey, "utf8").digest().subarray(0, KEY_BYTES);
|
|
2592
|
+
}
|
|
2593
|
+
function aad(userId, key) {
|
|
2594
|
+
return Buffer.from(`${userId}\x00${key.toUpperCase()}`, "utf8");
|
|
2595
|
+
}
|
|
2596
|
+
function isEncryptedVaultValue(value) {
|
|
2597
|
+
return value.startsWith(ENVELOPE_PREFIX);
|
|
2598
|
+
}
|
|
2599
|
+
function encryptVaultValue(userId, key, value, masterKey = VAULT_MASTER_KEY) {
|
|
2600
|
+
const iv = randomBytes4(IV_BYTES);
|
|
2601
|
+
const cipher = createCipheriv("aes-256-gcm", encryptionKey(masterKey), iv);
|
|
2602
|
+
cipher.setAAD(aad(userId, key));
|
|
2603
|
+
const ciphertext = Buffer.concat([cipher.update(value, "utf8"), cipher.final()]);
|
|
2604
|
+
const tag = cipher.getAuthTag();
|
|
2605
|
+
return `${ENVELOPE_PREFIX}${iv.toString("base64url")}.${ciphertext.toString("base64url")}.${tag.toString("base64url")}`;
|
|
2606
|
+
}
|
|
2607
|
+
function decryptVaultValue(userId, key, storedValue, masterKey = VAULT_MASTER_KEY) {
|
|
2608
|
+
if (!isEncryptedVaultValue(storedValue)) {
|
|
2609
|
+
return { value: storedValue, legacyPlaintext: true };
|
|
2610
|
+
}
|
|
2611
|
+
const encoded = storedValue.slice(ENVELOPE_PREFIX.length);
|
|
2612
|
+
const [ivPart, ciphertextPart, tagPart, ...extra] = encoded.split(".");
|
|
2613
|
+
if (!ivPart || ciphertextPart === undefined || !tagPart || extra.length > 0) {
|
|
2614
|
+
throw new Error("Invalid encrypted vault value");
|
|
2615
|
+
}
|
|
2616
|
+
const iv = Buffer.from(ivPart, "base64url");
|
|
2617
|
+
const ciphertext = Buffer.from(ciphertextPart, "base64url");
|
|
2618
|
+
const tag = Buffer.from(tagPart, "base64url");
|
|
2619
|
+
if (iv.length !== IV_BYTES || tag.length !== 16) {
|
|
2620
|
+
throw new Error("Invalid encrypted vault value");
|
|
2621
|
+
}
|
|
2622
|
+
const decipher = createDecipheriv("aes-256-gcm", encryptionKey(masterKey), iv);
|
|
2623
|
+
decipher.setAAD(aad(userId, key));
|
|
2624
|
+
decipher.setAuthTag(tag);
|
|
2625
|
+
const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
2626
|
+
return { value: plaintext.toString("utf8"), legacyPlaintext: false };
|
|
2627
|
+
}
|
|
2628
|
+
|
|
2629
|
+
// ../../packages/core/src/storage/vault.ts
|
|
2630
|
+
var vaultDb;
|
|
2631
|
+
var vaultMasterKey = VAULT_MASTER_KEY;
|
|
2632
|
+
function initializeVaultDatabase(database) {
|
|
2633
|
+
database.exec("PRAGMA journal_mode = WAL");
|
|
2634
|
+
database.exec("PRAGMA busy_timeout = 5000");
|
|
2635
|
+
database.exec(`
|
|
2636
|
+
CREATE TABLE IF NOT EXISTS vault (
|
|
2637
|
+
user_id TEXT NOT NULL,
|
|
2638
|
+
key TEXT NOT NULL,
|
|
2639
|
+
value TEXT NOT NULL,
|
|
2640
|
+
description TEXT NOT NULL DEFAULT '',
|
|
2641
|
+
PRIMARY KEY (user_id, key)
|
|
2642
|
+
)
|
|
2643
|
+
`);
|
|
2644
|
+
{
|
|
2645
|
+
const cols = database.prepare("PRAGMA table_info(vault)").all();
|
|
2646
|
+
const uid = cols.find((c) => c.name === "user_id");
|
|
2647
|
+
if (uid && uid.type.toUpperCase() === "INTEGER") {
|
|
2648
|
+
database.exec("BEGIN");
|
|
2649
|
+
database.exec(`
|
|
2650
|
+
CREATE TABLE vault_migrated (
|
|
2651
|
+
user_id TEXT NOT NULL,
|
|
2652
|
+
key TEXT NOT NULL,
|
|
2653
|
+
value TEXT NOT NULL,
|
|
2654
|
+
description TEXT NOT NULL DEFAULT '',
|
|
2655
|
+
PRIMARY KEY (user_id, key)
|
|
2656
|
+
)
|
|
2657
|
+
`);
|
|
2658
|
+
database.exec("INSERT INTO vault_migrated SELECT CAST(user_id AS TEXT), key, value, description FROM vault");
|
|
2659
|
+
database.exec("DROP TABLE vault");
|
|
2660
|
+
database.exec("ALTER TABLE vault_migrated RENAME TO vault");
|
|
2661
|
+
database.exec("COMMIT");
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
function openVaultDatabase(dataDir) {
|
|
2666
|
+
const path = join10(dataDir, "vault.db");
|
|
2667
|
+
mkdirSync7(dataDir, { recursive: true });
|
|
2668
|
+
const database = new Database(path, { create: true });
|
|
2669
|
+
chmodSync2(path, 384);
|
|
2670
|
+
initializeVaultDatabase(database);
|
|
2671
|
+
return database;
|
|
2672
|
+
}
|
|
2673
|
+
function activeVaultDatabase() {
|
|
2674
|
+
if (!vaultDb)
|
|
2675
|
+
vaultDb = openVaultDatabase(DATA_DIR);
|
|
2676
|
+
return vaultDb;
|
|
2677
|
+
}
|
|
2678
|
+
var VAULT_VALUE_MAX_BYTES = 64 * 1024;
|
|
2679
|
+
function normalizeVaultKey(key) {
|
|
2680
|
+
return key.trim().toUpperCase();
|
|
2681
|
+
}
|
|
2682
|
+
function decryptRow(userId, key, storedValue) {
|
|
2683
|
+
const database = activeVaultDatabase();
|
|
2684
|
+
const decoded = decryptVaultValue(userId, key, storedValue, vaultMasterKey);
|
|
2685
|
+
if (decoded.legacyPlaintext) {
|
|
2686
|
+
database.prepare("UPDATE vault SET value = ? WHERE user_id = ? AND key = ? AND value = ?").run(encryptVaultValue(userId, key, decoded.value, vaultMasterKey), userId, key, storedValue);
|
|
2687
|
+
}
|
|
2688
|
+
return decoded.value;
|
|
2689
|
+
}
|
|
2690
|
+
function vaultListWithValues(userId) {
|
|
2691
|
+
const rows = activeVaultDatabase().prepare("SELECT key, description, value FROM vault WHERE user_id = ? ORDER BY key").all(userId);
|
|
2692
|
+
return rows.map((row) => ({
|
|
2693
|
+
key: row.key,
|
|
2694
|
+
description: row.description,
|
|
2695
|
+
value: decryptRow(userId, row.key, row.value)
|
|
2696
|
+
}));
|
|
2697
|
+
}
|
|
2698
|
+
function vaultSubstituteDetailed(userId, text) {
|
|
2699
|
+
const entries = new Map(vaultListWithValues(userId).map((entry) => [entry.key, entry.value]));
|
|
2700
|
+
const usedKeys = new Set;
|
|
2701
|
+
const substituted = text.replace(/\{\{([^}]+)\}\}/g, (match, rawKey) => {
|
|
2702
|
+
const key = normalizeVaultKey(rawKey);
|
|
2703
|
+
const value = entries.get(key);
|
|
2704
|
+
if (value === undefined)
|
|
2705
|
+
return match;
|
|
2706
|
+
usedKeys.add(key);
|
|
2707
|
+
return value;
|
|
2708
|
+
});
|
|
2709
|
+
return { text: substituted, usedKeys: [...usedKeys] };
|
|
2710
|
+
}
|
|
2711
|
+
function encodedSecretForms(value) {
|
|
2712
|
+
const forms = new Set([
|
|
2713
|
+
value,
|
|
2714
|
+
encodeURIComponent(value),
|
|
2715
|
+
Buffer.from(value, "utf8").toString("base64"),
|
|
2716
|
+
Buffer.from(value, "utf8").toString("base64url"),
|
|
2717
|
+
Buffer.from(value, "utf8").toString("hex")
|
|
2718
|
+
]);
|
|
2719
|
+
forms.delete("");
|
|
2720
|
+
return [...forms].sort((a, b) => b.length - a.length);
|
|
2721
|
+
}
|
|
2722
|
+
function redactVaultSecrets(userId, text) {
|
|
2723
|
+
const candidates = vaultListWithValues(userId).flatMap((entry) => encodedSecretForms(entry.value).map((form) => ({ form, key: entry.key }))).sort((a, b) => b.form.length - a.form.length || a.key.localeCompare(b.key));
|
|
2724
|
+
if (candidates.length === 0)
|
|
2725
|
+
return text;
|
|
2726
|
+
const candidatesByFirstCharacter = new Map;
|
|
2727
|
+
for (const candidate of candidates) {
|
|
2728
|
+
const first = candidate.form[0];
|
|
2729
|
+
if (!first)
|
|
2730
|
+
continue;
|
|
2731
|
+
const bucket = candidatesByFirstCharacter.get(first) ?? [];
|
|
2732
|
+
bucket.push(candidate);
|
|
2733
|
+
candidatesByFirstCharacter.set(first, bucket);
|
|
2734
|
+
}
|
|
2735
|
+
let redacted = "";
|
|
2736
|
+
let offset = 0;
|
|
2737
|
+
while (offset < text.length) {
|
|
2738
|
+
const match = candidatesByFirstCharacter.get(text[offset] ?? "")?.find((candidate) => text.startsWith(candidate.form, offset));
|
|
2739
|
+
if (!match) {
|
|
2740
|
+
redacted += text[offset];
|
|
2741
|
+
offset += 1;
|
|
2742
|
+
continue;
|
|
2743
|
+
}
|
|
2744
|
+
redacted += `[REDACTED:${match.key}]`;
|
|
2745
|
+
offset += match.form.length;
|
|
2746
|
+
}
|
|
2747
|
+
return redacted;
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2767
2750
|
// ../../packages/core/src/agents/execution-host.ts
|
|
2768
2751
|
var defaultHost = {
|
|
2769
2752
|
getMcpServersForQuery,
|
|
@@ -3321,7 +3304,7 @@ import { createRequire } from "module";
|
|
|
3321
3304
|
import { dirname as dirname6, join as join11 } from "path";
|
|
3322
3305
|
|
|
3323
3306
|
// ../../packages/core/src/version.ts
|
|
3324
|
-
var NEGOTIUM_VERSION = "0.1.
|
|
3307
|
+
var NEGOTIUM_VERSION = "0.1.22";
|
|
3325
3308
|
|
|
3326
3309
|
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
3327
3310
|
var NEGOTIUM_MODEL_CATALOG = "negotium-model-catalog.json";
|
|
@@ -6365,4 +6348,4 @@ export {
|
|
|
6365
6348
|
VAULT_BROKER_REDIRECT_ERROR
|
|
6366
6349
|
};
|
|
6367
6350
|
|
|
6368
|
-
//# debugId=
|
|
6351
|
+
//# debugId=386290251F1B5ABD64756E2164756E21
|