negotium 0.6.3 → 0.6.5
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 +259 -254
- package/dist/agent-helpers.js.map +6 -6
- package/dist/{chunk-cvxe25re.js → chunk-cxtngn3p.js} +120 -313
- package/dist/{chunk-cvxe25re.js.map → chunk-cxtngn3p.js.map} +7 -8
- package/dist/chunk-rzef19v4.js +160 -0
- package/dist/chunk-rzef19v4.js.map +12 -0
- package/dist/chunk-v7tj2vtq.js +205 -0
- package/dist/chunk-v7tj2vtq.js.map +10 -0
- package/dist/hosted-agent.js +2 -2
- package/dist/hosted-agent.js.map +2 -2
- package/dist/main.js +380 -273
- package/dist/main.js.map +13 -12
- package/dist/mcp-factories.js +278 -273
- package/dist/mcp-factories.js.map +6 -6
- package/dist/registry.js +24 -173
- package/dist/registry.js.map +4 -7
- package/dist/rollout.js +7 -5
- package/dist/rollout.js.map +2 -2
- package/dist/runtime/cron/mcp-server.ts +2 -2
- package/dist/runtime/src/agents/codex-registry.ts +4 -1
- package/dist/runtime/src/cron-mcp-host.ts +5 -0
- package/dist/runtime/src/node-host.ts +1 -0
- package/dist/runtime/src/runtime/inbox.ts +6 -0
- package/dist/runtime/src/runtime-gateway.ts +61 -0
- package/dist/runtime/src/version.ts +1 -1
- package/dist/runtime-gateway.js +24 -1
- package/dist/runtime-gateway.js.map +3 -3
- package/dist/types/packages/core/src/runtime-gateway.d.ts +9 -0
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1873,239 +1873,6 @@ var init_claude_registry = __esm(() => {
|
|
|
1873
1873
|
};
|
|
1874
1874
|
});
|
|
1875
1875
|
|
|
1876
|
-
// ../../packages/core/src/version.ts
|
|
1877
|
-
var exports_version = {};
|
|
1878
|
-
__export(exports_version, {
|
|
1879
|
-
NEGOTIUM_VERSION: () => NEGOTIUM_VERSION
|
|
1880
|
-
});
|
|
1881
|
-
var NEGOTIUM_VERSION = "0.6.3";
|
|
1882
|
-
|
|
1883
|
-
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
1884
|
-
import { spawn } from "child_process";
|
|
1885
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
1886
|
-
import {
|
|
1887
|
-
chmodSync as chmodSync3,
|
|
1888
|
-
copyFileSync,
|
|
1889
|
-
existsSync as existsSync5,
|
|
1890
|
-
mkdtempSync,
|
|
1891
|
-
readFileSync as readFileSync4,
|
|
1892
|
-
renameSync as renameSync3,
|
|
1893
|
-
rmSync,
|
|
1894
|
-
unlinkSync as unlinkSync4,
|
|
1895
|
-
writeFileSync as writeFileSync4
|
|
1896
|
-
} from "fs";
|
|
1897
|
-
import { createRequire as createRequire2 } from "module";
|
|
1898
|
-
import { tmpdir } from "os";
|
|
1899
|
-
import { dirname as dirname4, join as join7 } from "path";
|
|
1900
|
-
function readPackageVersion(packageJsonPath) {
|
|
1901
|
-
const parsed = JSON.parse(readFileSync4(packageJsonPath, "utf8"));
|
|
1902
|
-
if (typeof parsed.version !== "string" || !parsed.version.trim()) {
|
|
1903
|
-
throw new Error(`Codex package has no valid version: ${packageJsonPath}`);
|
|
1904
|
-
}
|
|
1905
|
-
return parsed.version;
|
|
1906
|
-
}
|
|
1907
|
-
function codexCliScriptPath() {
|
|
1908
|
-
return join7(dirname4(bundledCodexPackagePath), "bin", "codex.js");
|
|
1909
|
-
}
|
|
1910
|
-
function parseCodexModelCache(contents, sourcePath) {
|
|
1911
|
-
let parsed;
|
|
1912
|
-
try {
|
|
1913
|
-
parsed = JSON.parse(contents);
|
|
1914
|
-
} catch (error) {
|
|
1915
|
-
throw new Error(`Codex model cache is invalid JSON: ${sourcePath}`, { cause: error });
|
|
1916
|
-
}
|
|
1917
|
-
if (!Array.isArray(parsed.models) || parsed.models.length === 0) {
|
|
1918
|
-
throw new Error(`Codex model cache has no models: ${sourcePath}`);
|
|
1919
|
-
}
|
|
1920
|
-
return parsed;
|
|
1921
|
-
}
|
|
1922
|
-
function readCodexModelCache(cachePath) {
|
|
1923
|
-
const contents = readFileSync4(cachePath, "utf8");
|
|
1924
|
-
return { contents, parsed: parseCodexModelCache(contents, cachePath) };
|
|
1925
|
-
}
|
|
1926
|
-
function readCompatibleCodexModelCache(cachePath) {
|
|
1927
|
-
const cache = readCodexModelCache(cachePath);
|
|
1928
|
-
if (cache.parsed.client_version !== BUNDLED_CODEX_VERSION) {
|
|
1929
|
-
const found = typeof cache.parsed.client_version === "string" ? cache.parsed.client_version : "missing or invalid";
|
|
1930
|
-
throw new Error(`Codex model cache version ${found} does not match Negotium's bundled Codex ${BUNDLED_CODEX_VERSION}: ${cachePath}`);
|
|
1931
|
-
}
|
|
1932
|
-
return cache;
|
|
1933
|
-
}
|
|
1934
|
-
function writePrivateFileAtomic(path, contents) {
|
|
1935
|
-
if (existsSync5(path) && readFileSync4(path, "utf8") === contents)
|
|
1936
|
-
return;
|
|
1937
|
-
const tempPath = `${path}.${process.pid}.${randomUUID2()}.tmp`;
|
|
1938
|
-
try {
|
|
1939
|
-
writeFileSync4(tempPath, contents, { encoding: "utf8", mode: 384 });
|
|
1940
|
-
renameSync3(tempPath, path);
|
|
1941
|
-
chmodSync3(path, 384);
|
|
1942
|
-
} finally {
|
|
1943
|
-
try {
|
|
1944
|
-
unlinkSync4(tempPath);
|
|
1945
|
-
} catch {}
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
function bundledCodexModelCachePath(authFilePath) {
|
|
1949
|
-
return join7(dirname4(authFilePath), NEGOTIUM_MODEL_CACHE);
|
|
1950
|
-
}
|
|
1951
|
-
async function bootstrapCodexModelCache(codexHome, cachePath) {
|
|
1952
|
-
const child = spawn(process.execPath, [codexCliScriptPath(), "app-server", "--stdio"], {
|
|
1953
|
-
env: { ...process.env, CODEX_HOME: codexHome },
|
|
1954
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
1955
|
-
});
|
|
1956
|
-
await new Promise((resolve4, reject) => {
|
|
1957
|
-
let settled = false;
|
|
1958
|
-
let stdoutBuffer = "";
|
|
1959
|
-
let stderr = "";
|
|
1960
|
-
const timer = setTimeout(() => finish(new Error("timed out while refreshing the Codex model catalog")), 15000);
|
|
1961
|
-
const finish = (error) => {
|
|
1962
|
-
if (settled)
|
|
1963
|
-
return;
|
|
1964
|
-
settled = true;
|
|
1965
|
-
clearTimeout(timer);
|
|
1966
|
-
try {
|
|
1967
|
-
child.stdin.end();
|
|
1968
|
-
child.kill();
|
|
1969
|
-
} catch {}
|
|
1970
|
-
if (error)
|
|
1971
|
-
reject(error);
|
|
1972
|
-
else if (!existsSync5(cachePath))
|
|
1973
|
-
reject(new Error("Codex did not create its model cache"));
|
|
1974
|
-
else
|
|
1975
|
-
resolve4();
|
|
1976
|
-
};
|
|
1977
|
-
const send = (message) => {
|
|
1978
|
-
child.stdin.write(`${JSON.stringify(message)}
|
|
1979
|
-
`);
|
|
1980
|
-
};
|
|
1981
|
-
child.stderr.on("data", (chunk) => {
|
|
1982
|
-
if (stderr.length < 4096)
|
|
1983
|
-
stderr += String(chunk);
|
|
1984
|
-
});
|
|
1985
|
-
child.on("error", (error) => finish(error));
|
|
1986
|
-
child.on("exit", (code, signal) => {
|
|
1987
|
-
if (!settled) {
|
|
1988
|
-
finish(new Error(`Codex model catalog refresh exited with ${signal ? `signal ${signal}` : `code ${code ?? 1}`}${stderr.trim() ? `: ${stderr.trim()}` : ""}`));
|
|
1989
|
-
}
|
|
1990
|
-
});
|
|
1991
|
-
child.stdout.on("data", (chunk) => {
|
|
1992
|
-
stdoutBuffer += String(chunk);
|
|
1993
|
-
for (;; ) {
|
|
1994
|
-
const newline = stdoutBuffer.indexOf(`
|
|
1995
|
-
`);
|
|
1996
|
-
if (newline < 0)
|
|
1997
|
-
break;
|
|
1998
|
-
const line = stdoutBuffer.slice(0, newline);
|
|
1999
|
-
stdoutBuffer = stdoutBuffer.slice(newline + 1);
|
|
2000
|
-
let message;
|
|
2001
|
-
try {
|
|
2002
|
-
message = JSON.parse(line);
|
|
2003
|
-
} catch {
|
|
2004
|
-
continue;
|
|
2005
|
-
}
|
|
2006
|
-
if (message.id === 1) {
|
|
2007
|
-
if (message.error) {
|
|
2008
|
-
finish(new Error(message.error.message || "Codex initialization failed"));
|
|
2009
|
-
return;
|
|
2010
|
-
}
|
|
2011
|
-
send({ method: "initialized" });
|
|
2012
|
-
send({ id: 2, method: "model/list", params: { includeHidden: true } });
|
|
2013
|
-
} else if (message.id === 2) {
|
|
2014
|
-
if (message.error) {
|
|
2015
|
-
finish(new Error(message.error.message || "Codex model listing failed"));
|
|
2016
|
-
} else {
|
|
2017
|
-
finish();
|
|
2018
|
-
}
|
|
2019
|
-
return;
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
});
|
|
2023
|
-
send({
|
|
2024
|
-
id: 1,
|
|
2025
|
-
method: "initialize",
|
|
2026
|
-
params: {
|
|
2027
|
-
clientInfo: { name: "negotium", version: NEGOTIUM_VERSION },
|
|
2028
|
-
capabilities: { experimentalApi: true }
|
|
2029
|
-
}
|
|
2030
|
-
});
|
|
2031
|
-
});
|
|
2032
|
-
}
|
|
2033
|
-
async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
|
|
2034
|
-
const sourceHome = dirname4(authFilePath);
|
|
2035
|
-
const isolatedHome = mkdtempSync(join7(tmpdir(), "negotium-codex-models-"));
|
|
2036
|
-
const isolatedCachePath = join7(isolatedHome, "models_cache.json");
|
|
2037
|
-
try {
|
|
2038
|
-
const isolatedAuthPath = join7(isolatedHome, "auth.json");
|
|
2039
|
-
copyFileSync(authFilePath, isolatedAuthPath);
|
|
2040
|
-
chmodSync3(isolatedAuthPath, 384);
|
|
2041
|
-
const sourceConfigPath = join7(sourceHome, "config.toml");
|
|
2042
|
-
if (existsSync5(sourceConfigPath)) {
|
|
2043
|
-
const isolatedConfigPath = join7(isolatedHome, "config.toml");
|
|
2044
|
-
copyFileSync(sourceConfigPath, isolatedConfigPath);
|
|
2045
|
-
chmodSync3(isolatedConfigPath, 384);
|
|
2046
|
-
}
|
|
2047
|
-
await bootstrap(isolatedHome, isolatedCachePath);
|
|
2048
|
-
return readCompatibleCodexModelCache(isolatedCachePath).contents;
|
|
2049
|
-
} finally {
|
|
2050
|
-
rmSync(isolatedHome, { recursive: true, force: true });
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexModelCache) {
|
|
2054
|
-
const codexHome = dirname4(authFilePath);
|
|
2055
|
-
const configuredCachePath = process.env.NEGOTIUM_CODEX_MODELS_CACHE_FILE;
|
|
2056
|
-
if (configuredCachePath) {
|
|
2057
|
-
if (!existsSync5(configuredCachePath)) {
|
|
2058
|
-
throw new Error(`Configured Codex model cache does not exist: ${configuredCachePath}`);
|
|
2059
|
-
}
|
|
2060
|
-
readCompatibleCodexModelCache(configuredCachePath);
|
|
2061
|
-
return configuredCachePath;
|
|
2062
|
-
}
|
|
2063
|
-
const bundledCachePath = bundledCodexModelCachePath(authFilePath);
|
|
2064
|
-
const sharedCachePath = join7(codexHome, "models_cache.json");
|
|
2065
|
-
if (existsSync5(sharedCachePath)) {
|
|
2066
|
-
try {
|
|
2067
|
-
const shared = readCompatibleCodexModelCache(sharedCachePath);
|
|
2068
|
-
writePrivateFileAtomic(bundledCachePath, shared.contents);
|
|
2069
|
-
return bundledCachePath;
|
|
2070
|
-
} catch {}
|
|
2071
|
-
}
|
|
2072
|
-
if (existsSync5(bundledCachePath)) {
|
|
2073
|
-
try {
|
|
2074
|
-
readCompatibleCodexModelCache(bundledCachePath);
|
|
2075
|
-
return bundledCachePath;
|
|
2076
|
-
} catch {}
|
|
2077
|
-
}
|
|
2078
|
-
const refreshedContents = await bootstrapIsolatedCodexModelCache(authFilePath, bootstrap);
|
|
2079
|
-
writePrivateFileAtomic(bundledCachePath, refreshedContents);
|
|
2080
|
-
return bundledCachePath;
|
|
2081
|
-
}
|
|
2082
|
-
function writeCodexCatalogWithNativeMultiAgentDisabled(authFilePath, sourcePath) {
|
|
2083
|
-
const codexHome = dirname4(authFilePath);
|
|
2084
|
-
const outputPath = join7(codexHome, NEGOTIUM_MODEL_CATALOG);
|
|
2085
|
-
const parsed = readCodexModelCache(sourcePath).parsed;
|
|
2086
|
-
const models = parsed.models.map((model, index) => {
|
|
2087
|
-
if (!model || typeof model !== "object" || Array.isArray(model)) {
|
|
2088
|
-
throw new Error(`Codex model cache entry ${index} is invalid: ${sourcePath}`);
|
|
2089
|
-
}
|
|
2090
|
-
return { ...model, multi_agent_version: "disabled" };
|
|
2091
|
-
});
|
|
2092
|
-
const contents = `${JSON.stringify({ models }, null, 2)}
|
|
2093
|
-
`;
|
|
2094
|
-
writePrivateFileAtomic(outputPath, contents);
|
|
2095
|
-
return outputPath;
|
|
2096
|
-
}
|
|
2097
|
-
var moduleRequire, codexSdkPackagePath, codexSdkRequire, bundledCodexPackagePath, BUNDLED_CODEX_VERSION, SAFE_BUNDLED_CODEX_VERSION, NEGOTIUM_MODEL_CACHE, NEGOTIUM_MODEL_CATALOG;
|
|
2098
|
-
var init_codex_native_multi_agent = __esm(() => {
|
|
2099
|
-
moduleRequire = createRequire2(import.meta.url);
|
|
2100
|
-
codexSdkPackagePath = moduleRequire.resolve("@openai/codex-sdk/package.json");
|
|
2101
|
-
codexSdkRequire = createRequire2(codexSdkPackagePath);
|
|
2102
|
-
bundledCodexPackagePath = codexSdkRequire.resolve("@openai/codex/package.json");
|
|
2103
|
-
BUNDLED_CODEX_VERSION = readPackageVersion(bundledCodexPackagePath);
|
|
2104
|
-
SAFE_BUNDLED_CODEX_VERSION = BUNDLED_CODEX_VERSION.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
2105
|
-
NEGOTIUM_MODEL_CACHE = `negotium-models-cache-${SAFE_BUNDLED_CODEX_VERSION}.json`;
|
|
2106
|
-
NEGOTIUM_MODEL_CATALOG = `negotium-model-catalog-${SAFE_BUNDLED_CODEX_VERSION}.json`;
|
|
2107
|
-
});
|
|
2108
|
-
|
|
2109
1876
|
// ../../packages/core/src/security/sensitive-path.ts
|
|
2110
1877
|
import { realpathSync } from "fs";
|
|
2111
1878
|
import { resolve as resolve4 } from "path";
|
|
@@ -2437,7 +2204,7 @@ function deriveBgBashContextCapability(runtimeCapability, userId, topic) {
|
|
|
2437
2204
|
var init_context = () => {};
|
|
2438
2205
|
|
|
2439
2206
|
// ../../packages/core/src/platform/background-bash/manager.ts
|
|
2440
|
-
import { execFileSync as execFileSync4, spawn
|
|
2207
|
+
import { execFileSync as execFileSync4, spawn } from "child_process";
|
|
2441
2208
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
2442
2209
|
function makeBgBashKey(_userId, _topic) {
|
|
2443
2210
|
return "runtime";
|
|
@@ -2464,7 +2231,7 @@ function createBackgroundBashManager(options = {}) {
|
|
|
2464
2231
|
const now = options.now ?? Date.now;
|
|
2465
2232
|
const wait = options.delay ?? delay;
|
|
2466
2233
|
const portPids = options.portPids ?? defaultPortPids;
|
|
2467
|
-
const spawnImpl = options.spawn ?? ((command, args, spawnOptions) =>
|
|
2234
|
+
const spawnImpl = options.spawn ?? ((command, args, spawnOptions) => spawn(command, [...args], spawnOptions));
|
|
2468
2235
|
function contextKey(userId, topic) {
|
|
2469
2236
|
return `${userId}\x00${topic}`;
|
|
2470
2237
|
}
|
|
@@ -2706,7 +2473,7 @@ var init_mcp_transport = __esm(() => {
|
|
|
2706
2473
|
// ../../packages/core/src/platform/mcp-config.ts
|
|
2707
2474
|
import { accessSync as accessSync2, constants as fsConstants } from "fs";
|
|
2708
2475
|
import { homedir as homedir6 } from "os";
|
|
2709
|
-
import { join as
|
|
2476
|
+
import { join as join7 } from "path";
|
|
2710
2477
|
function buildStdioMcpServer(agent, serverFile, serverArgs, env) {
|
|
2711
2478
|
if (agent === "codex") {
|
|
2712
2479
|
return {
|
|
@@ -2820,7 +2587,7 @@ function resolveCuaRsBinary(platform2 = process.platform) {
|
|
|
2820
2587
|
return null;
|
|
2821
2588
|
const candidates = [
|
|
2822
2589
|
envText("NEGOTIUM_CUA_RS_BIN"),
|
|
2823
|
-
|
|
2590
|
+
join7(homedir6(), ".local", "bin", "cua-rs"),
|
|
2824
2591
|
"/usr/local/bin/cua-rs"
|
|
2825
2592
|
].filter((p) => Boolean(p));
|
|
2826
2593
|
for (const candidate of candidates) {
|
|
@@ -3313,7 +3080,7 @@ var init_mcp_config = __esm(() => {
|
|
|
3313
3080
|
|
|
3314
3081
|
// ../../packages/core/src/agents/execution-host.ts
|
|
3315
3082
|
import { AsyncLocalStorage } from "async_hooks";
|
|
3316
|
-
import { dirname as
|
|
3083
|
+
import { dirname as dirname4 } from "path";
|
|
3317
3084
|
function activeHost() {
|
|
3318
3085
|
const scoped = scopedHost.getStore();
|
|
3319
3086
|
if (scoped)
|
|
@@ -3348,7 +3115,7 @@ function hostedCodexAuthFilePath() {
|
|
|
3348
3115
|
return activeHost().codexAuthFilePath();
|
|
3349
3116
|
}
|
|
3350
3117
|
function hostedCodexHomePath() {
|
|
3351
|
-
return
|
|
3118
|
+
return dirname4(hostedCodexAuthFilePath());
|
|
3352
3119
|
}
|
|
3353
3120
|
var defaultHost, hostRegistrations, scopedHost;
|
|
3354
3121
|
var init_execution_host = __esm(async () => {
|
|
@@ -3370,15 +3137,15 @@ var init_execution_host = __esm(async () => {
|
|
|
3370
3137
|
|
|
3371
3138
|
// ../../packages/core/src/agents/rollout/codex.ts
|
|
3372
3139
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
3373
|
-
import { existsSync as
|
|
3374
|
-
import { basename, dirname as
|
|
3140
|
+
import { existsSync as existsSync5, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2, unlinkSync as unlinkSync4 } from "fs";
|
|
3141
|
+
import { basename, dirname as dirname5, join as join8, resolve as resolve5 } from "path";
|
|
3375
3142
|
function codexSessionsDir() {
|
|
3376
|
-
return
|
|
3143
|
+
return join8(hostedCodexHomePath(), "sessions");
|
|
3377
3144
|
}
|
|
3378
3145
|
function loadCodexShell() {
|
|
3379
3146
|
if (_shellCache)
|
|
3380
3147
|
return _shellCache;
|
|
3381
|
-
const raw =
|
|
3148
|
+
const raw = readFileSync4(join8(FIXTURES_DIR, "codex-shell.jsonl"), "utf8");
|
|
3382
3149
|
const lines = parseJsonlText(raw);
|
|
3383
3150
|
if (lines.length < 5) {
|
|
3384
3151
|
throw new Error(`loadCodexShell: expected >=5 entries in codex-shell.jsonl, got ${lines.length}`);
|
|
@@ -3445,8 +3212,8 @@ function codexRolloutPath(threadId, fallback) {
|
|
|
3445
3212
|
const hh = String(createdAt.getHours()).padStart(2, "0");
|
|
3446
3213
|
const min = String(createdAt.getMinutes()).padStart(2, "0");
|
|
3447
3214
|
const ss = String(createdAt.getSeconds()).padStart(2, "0");
|
|
3448
|
-
const dir =
|
|
3449
|
-
return
|
|
3215
|
+
const dir = join8(codexSessionsDir(), yyyy, mm, dd);
|
|
3216
|
+
return join8(dir, `rollout-${yyyy}-${mm}-${dd}T${hh}-${min}-${ss}-${threadId}.jsonl`);
|
|
3450
3217
|
}
|
|
3451
3218
|
function canonicalFilePath(path) {
|
|
3452
3219
|
const absolute = resolve5(path);
|
|
@@ -3454,7 +3221,7 @@ function canonicalFilePath(path) {
|
|
|
3454
3221
|
return realpathSync2(absolute);
|
|
3455
3222
|
} catch {
|
|
3456
3223
|
try {
|
|
3457
|
-
return
|
|
3224
|
+
return join8(realpathSync2(dirname5(absolute)), basename(absolute));
|
|
3458
3225
|
} catch {
|
|
3459
3226
|
return absolute;
|
|
3460
3227
|
}
|
|
@@ -3564,7 +3331,7 @@ function readCodexPatchCallIds(threadId) {
|
|
|
3564
3331
|
if (!path)
|
|
3565
3332
|
return [];
|
|
3566
3333
|
try {
|
|
3567
|
-
return extractCodexPatchCallIds(
|
|
3334
|
+
return extractCodexPatchCallIds(readFileSync4(path, "utf8"));
|
|
3568
3335
|
} catch (error) {
|
|
3569
3336
|
logger.debug({ error, threadId }, "codex patch ids: rollout read failed");
|
|
3570
3337
|
return [];
|
|
@@ -3575,7 +3342,7 @@ function readLatestCodexPatchPreview(threadId, expectedPaths, consumedCallIds =
|
|
|
3575
3342
|
if (!path)
|
|
3576
3343
|
return;
|
|
3577
3344
|
try {
|
|
3578
|
-
return extractLatestCodexPatchPreview(
|
|
3345
|
+
return extractLatestCodexPatchPreview(readFileSync4(path, "utf8"), expectedPaths, consumedCallIds, expectedCallId);
|
|
3579
3346
|
} catch (error) {
|
|
3580
3347
|
logger.debug({ error, threadId }, "codex patch preview: rollout read failed");
|
|
3581
3348
|
return;
|
|
@@ -3633,7 +3400,7 @@ function readLatestCodexContextUsage(threadId) {
|
|
|
3633
3400
|
if (!path)
|
|
3634
3401
|
return;
|
|
3635
3402
|
try {
|
|
3636
|
-
return extractLatestCodexContextUsage(
|
|
3403
|
+
return extractLatestCodexContextUsage(readFileSync4(path, "utf8"));
|
|
3637
3404
|
} catch (error) {
|
|
3638
3405
|
logger.debug({ error, threadId }, "codex context usage: rollout read failed");
|
|
3639
3406
|
return;
|
|
@@ -3644,7 +3411,7 @@ function readLatestCodexTokenTotals(threadId) {
|
|
|
3644
3411
|
if (!path)
|
|
3645
3412
|
return;
|
|
3646
3413
|
try {
|
|
3647
|
-
return extractLatestCodexTokenTotals(
|
|
3414
|
+
return extractLatestCodexTokenTotals(readFileSync4(path, "utf8"));
|
|
3648
3415
|
} catch (error) {
|
|
3649
3416
|
logger.debug({ error, threadId }, "codex token totals: rollout read failed");
|
|
3650
3417
|
return;
|
|
@@ -3655,7 +3422,7 @@ function migrateCodexRolloutNativeMultiAgentMetadata(threadId) {
|
|
|
3655
3422
|
if (!path)
|
|
3656
3423
|
return false;
|
|
3657
3424
|
try {
|
|
3658
|
-
const entries = parseJsonlText(
|
|
3425
|
+
const entries = parseJsonlText(readFileSync4(path, "utf8"));
|
|
3659
3426
|
let changed = false;
|
|
3660
3427
|
for (const entry of entries) {
|
|
3661
3428
|
if (entry.type !== "session_meta" && entry.type !== "turn_context")
|
|
@@ -3684,19 +3451,19 @@ function latestCodexRolloutPath(threadId) {
|
|
|
3684
3451
|
try {
|
|
3685
3452
|
if (buckets) {
|
|
3686
3453
|
for (const bucket of buckets) {
|
|
3687
|
-
const dir =
|
|
3688
|
-
if (!
|
|
3454
|
+
const dir = join8(sessionsDir, bucket);
|
|
3455
|
+
if (!existsSync5(dir))
|
|
3689
3456
|
continue;
|
|
3690
3457
|
const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
|
|
3691
3458
|
for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
|
|
3692
|
-
candidates.push(
|
|
3459
|
+
candidates.push(join8(dir, rel));
|
|
3693
3460
|
}
|
|
3694
3461
|
}
|
|
3695
3462
|
}
|
|
3696
3463
|
if (candidates.length === 0) {
|
|
3697
3464
|
const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
|
|
3698
3465
|
for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
|
|
3699
|
-
candidates.push(
|
|
3466
|
+
candidates.push(join8(sessionsDir, rel));
|
|
3700
3467
|
}
|
|
3701
3468
|
}
|
|
3702
3469
|
return candidates.sort((a, b) => statSync2(b).mtimeMs - statSync2(a).mtimeMs)[0];
|
|
@@ -3817,15 +3584,15 @@ function sweepPriorRolloutsForThread(threadId) {
|
|
|
3817
3584
|
return;
|
|
3818
3585
|
}
|
|
3819
3586
|
for (const bucket of buckets) {
|
|
3820
|
-
const dir =
|
|
3821
|
-
if (!
|
|
3587
|
+
const dir = join8(sessionsDir, bucket);
|
|
3588
|
+
if (!existsSync5(dir))
|
|
3822
3589
|
continue;
|
|
3823
3590
|
try {
|
|
3824
3591
|
const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
|
|
3825
3592
|
for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
|
|
3826
|
-
const fullPath =
|
|
3593
|
+
const fullPath = join8(dir, rel);
|
|
3827
3594
|
try {
|
|
3828
|
-
|
|
3595
|
+
unlinkSync4(fullPath);
|
|
3829
3596
|
} catch (e) {
|
|
3830
3597
|
if (e?.code !== "ENOENT") {
|
|
3831
3598
|
logger.warn({ err: e, path: fullPath }, "writeCodexRollout: prior-rollout unlink failed (continuing)");
|
|
@@ -3841,9 +3608,9 @@ function sweepPriorRolloutsFullTree(threadId, sessionsDir) {
|
|
|
3841
3608
|
try {
|
|
3842
3609
|
const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
|
|
3843
3610
|
for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
|
|
3844
|
-
const fullPath =
|
|
3611
|
+
const fullPath = join8(sessionsDir, rel);
|
|
3845
3612
|
try {
|
|
3846
|
-
|
|
3613
|
+
unlinkSync4(fullPath);
|
|
3847
3614
|
} catch (e) {
|
|
3848
3615
|
if (e?.code !== "ENOENT") {
|
|
3849
3616
|
logger.warn({ err: e, path: fullPath }, "writeCodexRollout: prior-rollout unlink failed (continuing)");
|
|
@@ -3902,7 +3669,245 @@ var init_codex = __esm(async () => {
|
|
|
3902
3669
|
init_logger();
|
|
3903
3670
|
});
|
|
3904
3671
|
|
|
3672
|
+
// ../../packages/core/src/version.ts
|
|
3673
|
+
var exports_version = {};
|
|
3674
|
+
__export(exports_version, {
|
|
3675
|
+
NEGOTIUM_VERSION: () => NEGOTIUM_VERSION
|
|
3676
|
+
});
|
|
3677
|
+
var NEGOTIUM_VERSION = "0.6.5";
|
|
3678
|
+
|
|
3679
|
+
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
3680
|
+
import { spawn as spawn2 } from "child_process";
|
|
3681
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
3682
|
+
import {
|
|
3683
|
+
chmodSync as chmodSync3,
|
|
3684
|
+
copyFileSync,
|
|
3685
|
+
existsSync as existsSync6,
|
|
3686
|
+
mkdtempSync,
|
|
3687
|
+
readFileSync as readFileSync5,
|
|
3688
|
+
renameSync as renameSync3,
|
|
3689
|
+
rmSync,
|
|
3690
|
+
unlinkSync as unlinkSync5,
|
|
3691
|
+
writeFileSync as writeFileSync4
|
|
3692
|
+
} from "fs";
|
|
3693
|
+
import { createRequire as createRequire2 } from "module";
|
|
3694
|
+
import { tmpdir } from "os";
|
|
3695
|
+
import { dirname as dirname6, join as join9 } from "path";
|
|
3696
|
+
function readPackageVersion(packageJsonPath) {
|
|
3697
|
+
const parsed = JSON.parse(readFileSync5(packageJsonPath, "utf8"));
|
|
3698
|
+
if (typeof parsed.version !== "string" || !parsed.version.trim()) {
|
|
3699
|
+
throw new Error(`Codex package has no valid version: ${packageJsonPath}`);
|
|
3700
|
+
}
|
|
3701
|
+
return parsed.version;
|
|
3702
|
+
}
|
|
3703
|
+
function codexCliScriptPath() {
|
|
3704
|
+
return join9(dirname6(bundledCodexPackagePath), "bin", "codex.js");
|
|
3705
|
+
}
|
|
3706
|
+
function parseCodexModelCache(contents, sourcePath) {
|
|
3707
|
+
let parsed;
|
|
3708
|
+
try {
|
|
3709
|
+
parsed = JSON.parse(contents);
|
|
3710
|
+
} catch (error) {
|
|
3711
|
+
throw new Error(`Codex model cache is invalid JSON: ${sourcePath}`, { cause: error });
|
|
3712
|
+
}
|
|
3713
|
+
if (!Array.isArray(parsed.models) || parsed.models.length === 0) {
|
|
3714
|
+
throw new Error(`Codex model cache has no models: ${sourcePath}`);
|
|
3715
|
+
}
|
|
3716
|
+
return parsed;
|
|
3717
|
+
}
|
|
3718
|
+
function readCodexModelCache(cachePath) {
|
|
3719
|
+
const contents = readFileSync5(cachePath, "utf8");
|
|
3720
|
+
return { contents, parsed: parseCodexModelCache(contents, cachePath) };
|
|
3721
|
+
}
|
|
3722
|
+
function readCompatibleCodexModelCache(cachePath) {
|
|
3723
|
+
const cache = readCodexModelCache(cachePath);
|
|
3724
|
+
if (cache.parsed.client_version !== BUNDLED_CODEX_VERSION) {
|
|
3725
|
+
const found = typeof cache.parsed.client_version === "string" ? cache.parsed.client_version : "missing or invalid";
|
|
3726
|
+
throw new Error(`Codex model cache version ${found} does not match Negotium's bundled Codex ${BUNDLED_CODEX_VERSION}: ${cachePath}`);
|
|
3727
|
+
}
|
|
3728
|
+
return cache;
|
|
3729
|
+
}
|
|
3730
|
+
function writePrivateFileAtomic(path, contents) {
|
|
3731
|
+
if (existsSync6(path) && readFileSync5(path, "utf8") === contents)
|
|
3732
|
+
return;
|
|
3733
|
+
const tempPath = `${path}.${process.pid}.${randomUUID2()}.tmp`;
|
|
3734
|
+
try {
|
|
3735
|
+
writeFileSync4(tempPath, contents, { encoding: "utf8", mode: 384 });
|
|
3736
|
+
renameSync3(tempPath, path);
|
|
3737
|
+
chmodSync3(path, 384);
|
|
3738
|
+
} finally {
|
|
3739
|
+
try {
|
|
3740
|
+
unlinkSync5(tempPath);
|
|
3741
|
+
} catch {}
|
|
3742
|
+
}
|
|
3743
|
+
}
|
|
3744
|
+
function bundledCodexModelCachePath(authFilePath) {
|
|
3745
|
+
return join9(dirname6(authFilePath), NEGOTIUM_MODEL_CACHE);
|
|
3746
|
+
}
|
|
3747
|
+
async function bootstrapCodexModelCache(codexHome, cachePath) {
|
|
3748
|
+
const child = spawn2(process.execPath, [codexCliScriptPath(), "app-server", "--stdio"], {
|
|
3749
|
+
env: { ...process.env, CODEX_HOME: codexHome },
|
|
3750
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
3751
|
+
});
|
|
3752
|
+
await new Promise((resolve6, reject) => {
|
|
3753
|
+
let settled = false;
|
|
3754
|
+
let stdoutBuffer = "";
|
|
3755
|
+
let stderr = "";
|
|
3756
|
+
const timer = setTimeout(() => finish(new Error("timed out while refreshing the Codex model catalog")), 15000);
|
|
3757
|
+
const finish = (error) => {
|
|
3758
|
+
if (settled)
|
|
3759
|
+
return;
|
|
3760
|
+
settled = true;
|
|
3761
|
+
clearTimeout(timer);
|
|
3762
|
+
try {
|
|
3763
|
+
child.stdin.end();
|
|
3764
|
+
child.kill();
|
|
3765
|
+
} catch {}
|
|
3766
|
+
if (error)
|
|
3767
|
+
reject(error);
|
|
3768
|
+
else if (!existsSync6(cachePath))
|
|
3769
|
+
reject(new Error("Codex did not create its model cache"));
|
|
3770
|
+
else
|
|
3771
|
+
resolve6();
|
|
3772
|
+
};
|
|
3773
|
+
const send = (message) => {
|
|
3774
|
+
child.stdin.write(`${JSON.stringify(message)}
|
|
3775
|
+
`);
|
|
3776
|
+
};
|
|
3777
|
+
child.stderr.on("data", (chunk) => {
|
|
3778
|
+
if (stderr.length < 4096)
|
|
3779
|
+
stderr += String(chunk);
|
|
3780
|
+
});
|
|
3781
|
+
child.on("error", (error) => finish(error));
|
|
3782
|
+
child.on("exit", (code, signal) => {
|
|
3783
|
+
if (!settled) {
|
|
3784
|
+
finish(new Error(`Codex model catalog refresh exited with ${signal ? `signal ${signal}` : `code ${code ?? 1}`}${stderr.trim() ? `: ${stderr.trim()}` : ""}`));
|
|
3785
|
+
}
|
|
3786
|
+
});
|
|
3787
|
+
child.stdout.on("data", (chunk) => {
|
|
3788
|
+
stdoutBuffer += String(chunk);
|
|
3789
|
+
for (;; ) {
|
|
3790
|
+
const newline = stdoutBuffer.indexOf(`
|
|
3791
|
+
`);
|
|
3792
|
+
if (newline < 0)
|
|
3793
|
+
break;
|
|
3794
|
+
const line = stdoutBuffer.slice(0, newline);
|
|
3795
|
+
stdoutBuffer = stdoutBuffer.slice(newline + 1);
|
|
3796
|
+
let message;
|
|
3797
|
+
try {
|
|
3798
|
+
message = JSON.parse(line);
|
|
3799
|
+
} catch {
|
|
3800
|
+
continue;
|
|
3801
|
+
}
|
|
3802
|
+
if (message.id === 1) {
|
|
3803
|
+
if (message.error) {
|
|
3804
|
+
finish(new Error(message.error.message || "Codex initialization failed"));
|
|
3805
|
+
return;
|
|
3806
|
+
}
|
|
3807
|
+
send({ method: "initialized" });
|
|
3808
|
+
send({ id: 2, method: "model/list", params: { includeHidden: true } });
|
|
3809
|
+
} else if (message.id === 2) {
|
|
3810
|
+
if (message.error) {
|
|
3811
|
+
finish(new Error(message.error.message || "Codex model listing failed"));
|
|
3812
|
+
} else {
|
|
3813
|
+
finish();
|
|
3814
|
+
}
|
|
3815
|
+
return;
|
|
3816
|
+
}
|
|
3817
|
+
}
|
|
3818
|
+
});
|
|
3819
|
+
send({
|
|
3820
|
+
id: 1,
|
|
3821
|
+
method: "initialize",
|
|
3822
|
+
params: {
|
|
3823
|
+
clientInfo: { name: "negotium", version: NEGOTIUM_VERSION },
|
|
3824
|
+
capabilities: { experimentalApi: true }
|
|
3825
|
+
}
|
|
3826
|
+
});
|
|
3827
|
+
});
|
|
3828
|
+
}
|
|
3829
|
+
async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
|
|
3830
|
+
const sourceHome = dirname6(authFilePath);
|
|
3831
|
+
const isolatedHome = mkdtempSync(join9(tmpdir(), "negotium-codex-models-"));
|
|
3832
|
+
const isolatedCachePath = join9(isolatedHome, "models_cache.json");
|
|
3833
|
+
try {
|
|
3834
|
+
const isolatedAuthPath = join9(isolatedHome, "auth.json");
|
|
3835
|
+
copyFileSync(authFilePath, isolatedAuthPath);
|
|
3836
|
+
chmodSync3(isolatedAuthPath, 384);
|
|
3837
|
+
const sourceConfigPath = join9(sourceHome, "config.toml");
|
|
3838
|
+
if (existsSync6(sourceConfigPath)) {
|
|
3839
|
+
const isolatedConfigPath = join9(isolatedHome, "config.toml");
|
|
3840
|
+
copyFileSync(sourceConfigPath, isolatedConfigPath);
|
|
3841
|
+
chmodSync3(isolatedConfigPath, 384);
|
|
3842
|
+
}
|
|
3843
|
+
await bootstrap(isolatedHome, isolatedCachePath);
|
|
3844
|
+
return readCompatibleCodexModelCache(isolatedCachePath).contents;
|
|
3845
|
+
} finally {
|
|
3846
|
+
rmSync(isolatedHome, { recursive: true, force: true });
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexModelCache) {
|
|
3850
|
+
const codexHome = dirname6(authFilePath);
|
|
3851
|
+
const configuredCachePath = process.env.NEGOTIUM_CODEX_MODELS_CACHE_FILE;
|
|
3852
|
+
if (configuredCachePath) {
|
|
3853
|
+
if (!existsSync6(configuredCachePath)) {
|
|
3854
|
+
throw new Error(`Configured Codex model cache does not exist: ${configuredCachePath}`);
|
|
3855
|
+
}
|
|
3856
|
+
readCompatibleCodexModelCache(configuredCachePath);
|
|
3857
|
+
return configuredCachePath;
|
|
3858
|
+
}
|
|
3859
|
+
const bundledCachePath = bundledCodexModelCachePath(authFilePath);
|
|
3860
|
+
const sharedCachePath = join9(codexHome, "models_cache.json");
|
|
3861
|
+
if (existsSync6(sharedCachePath)) {
|
|
3862
|
+
try {
|
|
3863
|
+
const shared = readCompatibleCodexModelCache(sharedCachePath);
|
|
3864
|
+
writePrivateFileAtomic(bundledCachePath, shared.contents);
|
|
3865
|
+
return bundledCachePath;
|
|
3866
|
+
} catch {}
|
|
3867
|
+
}
|
|
3868
|
+
if (existsSync6(bundledCachePath)) {
|
|
3869
|
+
try {
|
|
3870
|
+
readCompatibleCodexModelCache(bundledCachePath);
|
|
3871
|
+
return bundledCachePath;
|
|
3872
|
+
} catch {}
|
|
3873
|
+
}
|
|
3874
|
+
const refreshedContents = await bootstrapIsolatedCodexModelCache(authFilePath, bootstrap);
|
|
3875
|
+
writePrivateFileAtomic(bundledCachePath, refreshedContents);
|
|
3876
|
+
return bundledCachePath;
|
|
3877
|
+
}
|
|
3878
|
+
function writeCodexCatalogWithNativeMultiAgentDisabled(authFilePath, sourcePath) {
|
|
3879
|
+
const codexHome = dirname6(authFilePath);
|
|
3880
|
+
const outputPath = join9(codexHome, NEGOTIUM_MODEL_CATALOG);
|
|
3881
|
+
const parsed = readCodexModelCache(sourcePath).parsed;
|
|
3882
|
+
const models = parsed.models.map((model, index) => {
|
|
3883
|
+
if (!model || typeof model !== "object" || Array.isArray(model)) {
|
|
3884
|
+
throw new Error(`Codex model cache entry ${index} is invalid: ${sourcePath}`);
|
|
3885
|
+
}
|
|
3886
|
+
return { ...model, multi_agent_version: "disabled" };
|
|
3887
|
+
});
|
|
3888
|
+
const contents = `${JSON.stringify({ models }, null, 2)}
|
|
3889
|
+
`;
|
|
3890
|
+
writePrivateFileAtomic(outputPath, contents);
|
|
3891
|
+
return outputPath;
|
|
3892
|
+
}
|
|
3893
|
+
var moduleRequire, codexSdkPackagePath, codexSdkRequire, bundledCodexPackagePath, BUNDLED_CODEX_VERSION, SAFE_BUNDLED_CODEX_VERSION, NEGOTIUM_MODEL_CACHE, NEGOTIUM_MODEL_CATALOG;
|
|
3894
|
+
var init_codex_native_multi_agent = __esm(() => {
|
|
3895
|
+
moduleRequire = createRequire2(import.meta.url);
|
|
3896
|
+
codexSdkPackagePath = moduleRequire.resolve("@openai/codex-sdk/package.json");
|
|
3897
|
+
codexSdkRequire = createRequire2(codexSdkPackagePath);
|
|
3898
|
+
bundledCodexPackagePath = codexSdkRequire.resolve("@openai/codex/package.json");
|
|
3899
|
+
BUNDLED_CODEX_VERSION = readPackageVersion(bundledCodexPackagePath);
|
|
3900
|
+
SAFE_BUNDLED_CODEX_VERSION = BUNDLED_CODEX_VERSION.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
3901
|
+
NEGOTIUM_MODEL_CACHE = `negotium-models-cache-${SAFE_BUNDLED_CODEX_VERSION}.json`;
|
|
3902
|
+
NEGOTIUM_MODEL_CATALOG = `negotium-model-catalog-${SAFE_BUNDLED_CODEX_VERSION}.json`;
|
|
3903
|
+
});
|
|
3904
|
+
|
|
3905
3905
|
// ../../packages/core/src/agents/codex-app-server.ts
|
|
3906
|
+
var exports_codex_app_server = {};
|
|
3907
|
+
__export(exports_codex_app_server, {
|
|
3908
|
+
forkCodexSession: () => forkCodexSession,
|
|
3909
|
+
createCodexAppServerForker: () => createCodexAppServerForker
|
|
3910
|
+
});
|
|
3906
3911
|
import { spawn as spawn3 } from "child_process";
|
|
3907
3912
|
function createCodexAppServerForker(host) {
|
|
3908
3913
|
return async (parentThreadId) => {
|
|
@@ -4022,7 +4027,6 @@ import { existsSync as existsSync7, unlinkSync as unlinkSync6 } from "fs";
|
|
|
4022
4027
|
import { join as join10 } from "path";
|
|
4023
4028
|
var VALID_EFFORTS2, codexRegistry, codexRegistryOperations;
|
|
4024
4029
|
var init_codex_registry = __esm(async () => {
|
|
4025
|
-
await init_codex_app_server();
|
|
4026
4030
|
await init_execution_host();
|
|
4027
4031
|
await init_codex();
|
|
4028
4032
|
init_logger();
|
|
@@ -4057,7 +4061,8 @@ var init_codex_registry = __esm(async () => {
|
|
|
4057
4061
|
return { sessionId: threadId, rolloutPath };
|
|
4058
4062
|
},
|
|
4059
4063
|
async forkSession({ parentSessionId }) {
|
|
4060
|
-
|
|
4064
|
+
const { forkCodexSession: forkCodexSession2 } = await init_codex_app_server().then(() => exports_codex_app_server);
|
|
4065
|
+
return await forkCodexSession2(parentSessionId);
|
|
4061
4066
|
},
|
|
4062
4067
|
async cleanupRollouts({ sessionIds }) {
|
|
4063
4068
|
if (sessionIds.length === 0)
|
|
@@ -22796,6 +22801,12 @@ ${schedule.message}`, topic.agent, {
|
|
|
22796
22801
|
depth: 0,
|
|
22797
22802
|
from: fromLabel,
|
|
22798
22803
|
injectAuthorId: "system",
|
|
22804
|
+
injectSourceAdapter: "self-schedule",
|
|
22805
|
+
injectKind: "tell",
|
|
22806
|
+
injectTellCard: {
|
|
22807
|
+
fromLabel,
|
|
22808
|
+
message: schedule.message
|
|
22809
|
+
},
|
|
22799
22810
|
onSettled: (result) => {
|
|
22800
22811
|
settled = true;
|
|
22801
22812
|
stopClaimHeartbeat();
|
|
@@ -24083,6 +24094,7 @@ __export(exports_node_host, {
|
|
|
24083
24094
|
startBashrsCompletionsWorker: () => startBashrsCompletionsWorker,
|
|
24084
24095
|
startAskUserQuestionGateOwner: () => startAskUserQuestionGateOwner,
|
|
24085
24096
|
startAiTurn: () => startAiTurn,
|
|
24097
|
+
softDeleteApiMessage: () => softDeleteApiMessage,
|
|
24086
24098
|
setRuntimeMcpPort: () => setRuntimeMcpPort,
|
|
24087
24099
|
setNodeMcpServers: () => setNodeMcpServers,
|
|
24088
24100
|
setGlobalAiName: () => setGlobalAiName,
|
|
@@ -32517,6 +32529,7 @@ function createNodeControlHandler(options) {
|
|
|
32517
32529
|
"turn-events-sse-resume",
|
|
32518
32530
|
"canonical-topic-read",
|
|
32519
32531
|
"canonical-message-read",
|
|
32532
|
+
"canonical-message-delete",
|
|
32520
32533
|
"canonical-topic-usage",
|
|
32521
32534
|
"canonical-file-read",
|
|
32522
32535
|
"canonical-visual-read",
|
|
@@ -32801,6 +32814,36 @@ function createNodeControlHandler(options) {
|
|
|
32801
32814
|
});
|
|
32802
32815
|
return Response.json({ ok: true, v: NODE_RUNTIME_CONTRACT_VERSION, ...result });
|
|
32803
32816
|
}
|
|
32817
|
+
const runtimeMessageMatch = runtimePath.match(/^\/topics\/([^/]+)\/messages\/([^/]+)$/);
|
|
32818
|
+
if (runtimeMessageMatch && req.method === "DELETE") {
|
|
32819
|
+
const body = await bodyRecord(req);
|
|
32820
|
+
if (body.v !== NODE_RUNTIME_CONTRACT_VERSION)
|
|
32821
|
+
return jsonError(400, "Unsupported v");
|
|
32822
|
+
const topicId = decodeURIComponent(runtimeMessageMatch[1]);
|
|
32823
|
+
const messageId = decodeURIComponent(runtimeMessageMatch[2]);
|
|
32824
|
+
const topic = getTopic(topicId);
|
|
32825
|
+
if (!topic || !topicInRequestScope(req, topic))
|
|
32826
|
+
return jsonError(404, "Topic not found");
|
|
32827
|
+
const actorUserId = requiredText(body.actorUserId, "actorUserId");
|
|
32828
|
+
if (body.allowAdmin !== undefined && typeof body.allowAdmin !== "boolean") {
|
|
32829
|
+
return jsonError(400, "allowAdmin must be boolean");
|
|
32830
|
+
}
|
|
32831
|
+
const existing = getApiMessage(topicId, messageId);
|
|
32832
|
+
if (!existing || existing.deleted)
|
|
32833
|
+
return jsonError(404, "Message not found");
|
|
32834
|
+
if (existing.authorId !== actorUserId && body.allowAdmin !== true) {
|
|
32835
|
+
return jsonError(403, "Not allowed");
|
|
32836
|
+
}
|
|
32837
|
+
const message = softDeleteApiMessage(topicId, messageId);
|
|
32838
|
+
if (!message)
|
|
32839
|
+
return jsonError(404, "Message not found");
|
|
32840
|
+
WsHub.get().broadcastMessageUpdated(topicId, messageId, { deleted: true, text: "" });
|
|
32841
|
+
return Response.json({
|
|
32842
|
+
ok: true,
|
|
32843
|
+
v: NODE_RUNTIME_CONTRACT_VERSION,
|
|
32844
|
+
message
|
|
32845
|
+
});
|
|
32846
|
+
}
|
|
32804
32847
|
if (req.method === "GET" && runtimePath === "/topics") {
|
|
32805
32848
|
const topics = gatewayVisibleTopics(req);
|
|
32806
32849
|
const previews = getLastMessagePreviews(topics.map((topic) => topic.id));
|
|
@@ -35326,6 +35369,56 @@ var init_terminal_width = __esm(() => {
|
|
|
35326
35369
|
widthCache = new Map;
|
|
35327
35370
|
});
|
|
35328
35371
|
|
|
35372
|
+
// ../../adapters/terminal/src/visualization.ts
|
|
35373
|
+
import { basename as basename12, extname as extname5, isAbsolute as isAbsolute7 } from "path";
|
|
35374
|
+
function hasControlCharacter(value) {
|
|
35375
|
+
for (const character of value) {
|
|
35376
|
+
const code = character.codePointAt(0) ?? 0;
|
|
35377
|
+
if (code <= 31 || code === 127)
|
|
35378
|
+
return true;
|
|
35379
|
+
}
|
|
35380
|
+
return false;
|
|
35381
|
+
}
|
|
35382
|
+
function isSupportedVisualizationPath(value) {
|
|
35383
|
+
if (value.length === 0 || value.length > MAX_VISUALIZATION_PATH_LENGTH || !isAbsolute7(value) || hasControlCharacter(value)) {
|
|
35384
|
+
return false;
|
|
35385
|
+
}
|
|
35386
|
+
const extension = extname5(value).toLowerCase();
|
|
35387
|
+
return extension === ".html" || extension === ".htm";
|
|
35388
|
+
}
|
|
35389
|
+
function parseVisualizationReference(value) {
|
|
35390
|
+
const trimmed = value.trim();
|
|
35391
|
+
if (trimmed.length > MAX_VISUALIZATION_REFERENCE_LENGTH || !trimmed.startsWith(VISUALIZE_PREFIX) || !trimmed.endsWith(VISUALIZE_SUFFIX)) {
|
|
35392
|
+
return null;
|
|
35393
|
+
}
|
|
35394
|
+
const encoded = trimmed.slice(VISUALIZE_PREFIX.length, -VISUALIZE_SUFFIX.length);
|
|
35395
|
+
let parsed;
|
|
35396
|
+
try {
|
|
35397
|
+
parsed = JSON.parse(encoded);
|
|
35398
|
+
} catch {
|
|
35399
|
+
return null;
|
|
35400
|
+
}
|
|
35401
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
35402
|
+
return null;
|
|
35403
|
+
const keys = Object.keys(parsed);
|
|
35404
|
+
if (keys.length < 1 || keys.length > 2 || keys.some((key) => key !== "path" && key !== "mode")) {
|
|
35405
|
+
return null;
|
|
35406
|
+
}
|
|
35407
|
+
const candidate = parsed;
|
|
35408
|
+
if (typeof candidate.path !== "string" || !isSupportedVisualizationPath(candidate.path)) {
|
|
35409
|
+
return null;
|
|
35410
|
+
}
|
|
35411
|
+
if (candidate.mode !== undefined && candidate.mode !== "wide")
|
|
35412
|
+
return null;
|
|
35413
|
+
return {
|
|
35414
|
+
path: candidate.path,
|
|
35415
|
+
name: basename12(candidate.path) || candidate.path,
|
|
35416
|
+
...candidate.mode === "wide" ? { mode: "wide" } : {}
|
|
35417
|
+
};
|
|
35418
|
+
}
|
|
35419
|
+
var VISUALIZE_PREFIX = "\uE200visualize\uE202", VISUALIZE_SUFFIX = "\uE201", MAX_VISUALIZATION_REFERENCE_LENGTH = 8192, MAX_VISUALIZATION_PATH_LENGTH = 4096;
|
|
35420
|
+
var init_visualization = () => {};
|
|
35421
|
+
|
|
35329
35422
|
// ../../adapters/terminal/src/render.ts
|
|
35330
35423
|
function workingFrame(frame) {
|
|
35331
35424
|
const index = Math.abs(Math.trunc(frame)) % WORKING_FRAMES.length;
|
|
@@ -35770,6 +35863,17 @@ function renderMarkdown(value, width) {
|
|
|
35770
35863
|
`);
|
|
35771
35864
|
for (let lineIndex = 0;lineIndex < rawLines.length; lineIndex += 1) {
|
|
35772
35865
|
const rawLine = rawLines[lineIndex] ?? "";
|
|
35866
|
+
const visualization = parseVisualizationReference(rawLine);
|
|
35867
|
+
if (visualization) {
|
|
35868
|
+
flushTable();
|
|
35869
|
+
const mode = visualization.mode ? ` \xB7 ${visualization.mode}` : "";
|
|
35870
|
+
result.push(line(` \u25C7 visualization${mode} \xB7 ${visualization.name}`, {
|
|
35871
|
+
fg: theme.cyan,
|
|
35872
|
+
bg: theme.surfaceRaised,
|
|
35873
|
+
bold: true
|
|
35874
|
+
}));
|
|
35875
|
+
continue;
|
|
35876
|
+
}
|
|
35773
35877
|
const fence = rawLine.match(/^\s*```([^`]*)$/);
|
|
35774
35878
|
if (fence) {
|
|
35775
35879
|
flushTable();
|
|
@@ -37064,6 +37168,7 @@ var init_render = __esm(async () => {
|
|
|
37064
37168
|
init_path_suggest();
|
|
37065
37169
|
await init_state2();
|
|
37066
37170
|
init_terminal_width();
|
|
37171
|
+
init_visualization();
|
|
37067
37172
|
init_terminal_width();
|
|
37068
37173
|
theme = {
|
|
37069
37174
|
canvas: [10, 11, 15],
|
|
@@ -42199,7 +42304,7 @@ function renderOutbound(text2, maxLen = 4096) {
|
|
|
42199
42304
|
|
|
42200
42305
|
// ../../adapters/telegram/src/adapter.ts
|
|
42201
42306
|
import { existsSync as existsSync37 } from "fs";
|
|
42202
|
-
import { basename as
|
|
42307
|
+
import { basename as basename13, extname as extname6 } from "path";
|
|
42203
42308
|
function startTelegramAdapter(opts) {
|
|
42204
42309
|
const { client, forumChatId } = opts;
|
|
42205
42310
|
const userId = opts.userId ?? "local";
|
|
@@ -42705,9 +42810,9 @@ function startTelegramAdapter(opts) {
|
|
|
42705
42810
|
error: "file not found on disk"
|
|
42706
42811
|
};
|
|
42707
42812
|
}
|
|
42708
|
-
const ext =
|
|
42813
|
+
const ext = extname6(path).slice(1).toLowerCase();
|
|
42709
42814
|
const fileOptions = {
|
|
42710
|
-
filename:
|
|
42815
|
+
filename: basename13(file.filename) || basename13(path),
|
|
42711
42816
|
...file.mimeType ? { contentType: file.mimeType } : {}
|
|
42712
42817
|
};
|
|
42713
42818
|
try {
|
|
@@ -43442,14 +43547,14 @@ Warning: enable the bot administrator permission "Manage Topics" before creating
|
|
|
43442
43547
|
timer.unref?.();
|
|
43443
43548
|
}
|
|
43444
43549
|
}
|
|
43445
|
-
const tagFiles = msg.text ? extractFileTagPaths(msg.text).map((path) => ({ path, filename:
|
|
43550
|
+
const tagFiles = msg.text ? extractFileTagPaths(msg.text).map((path) => ({ path, filename: basename13(path) })) : [];
|
|
43446
43551
|
const attachmentFiles = hasAttachments ? (msg.attachments ?? []).map((attachment) => {
|
|
43447
43552
|
const path = resolveUploadedFilePathByFileId(attachment.id);
|
|
43448
43553
|
if (!path)
|
|
43449
43554
|
return null;
|
|
43450
43555
|
return {
|
|
43451
43556
|
path,
|
|
43452
|
-
filename:
|
|
43557
|
+
filename: basename13(attachment.filename) || basename13(path),
|
|
43453
43558
|
...attachment.mimeType ? { mimeType: attachment.mimeType } : {}
|
|
43454
43559
|
};
|
|
43455
43560
|
}).filter((file) => file !== null) : [];
|
|
@@ -44579,7 +44684,7 @@ var init_join = __esm(async () => {
|
|
|
44579
44684
|
// ../../adapters/otium/src/peer-files.ts
|
|
44580
44685
|
import { randomUUID as randomUUID30 } from "crypto";
|
|
44581
44686
|
import { copyFileSync as copyFileSync5, mkdirSync as mkdirSync35, rmSync as rmSync12, statSync as statSync21 } from "fs";
|
|
44582
|
-
import { basename as
|
|
44687
|
+
import { basename as basename14, extname as extname7, join as join47 } from "path";
|
|
44583
44688
|
function fileType(mimeType) {
|
|
44584
44689
|
if (mimeType.startsWith("image/"))
|
|
44585
44690
|
return "image";
|
|
@@ -44601,11 +44706,11 @@ function rowFor(fileId) {
|
|
|
44601
44706
|
return db.query("SELECT * FROM otium_peer_files WHERE id = ?").get(fileId) ?? null;
|
|
44602
44707
|
}
|
|
44603
44708
|
function safeFilename(filename) {
|
|
44604
|
-
const value =
|
|
44709
|
+
const value = basename14(filename).replace(/[^A-Za-z0-9._ -]/g, "_").slice(0, 120);
|
|
44605
44710
|
return value || "upload";
|
|
44606
44711
|
}
|
|
44607
44712
|
function mimeFromPath(path) {
|
|
44608
|
-
const extension =
|
|
44713
|
+
const extension = extname7(path).toLowerCase();
|
|
44609
44714
|
const known = {
|
|
44610
44715
|
".png": "image/png",
|
|
44611
44716
|
".jpg": "image/jpeg",
|
|
@@ -44671,7 +44776,7 @@ function installPeerFileHooks() {
|
|
|
44671
44776
|
return existing;
|
|
44672
44777
|
return insertLocalFile({
|
|
44673
44778
|
sourcePath: path,
|
|
44674
|
-
filename:
|
|
44779
|
+
filename: basename14(path),
|
|
44675
44780
|
mimeType: mimeFromPath(path),
|
|
44676
44781
|
topicId: access?.topicId,
|
|
44677
44782
|
ownerUserId: access?.ownerUserId
|
|
@@ -46509,6 +46614,8 @@ function allowedRuntimePath(path, method) {
|
|
|
46509
46614
|
return /^\/topics\/[^/]+\/(abort|session\/(reset|compact))$/.test(path);
|
|
46510
46615
|
}
|
|
46511
46616
|
if (method === "DELETE" || method === "PATCH") {
|
|
46617
|
+
if (method === "DELETE" && /^\/topics\/[^/]+\/messages\/[^/]+$/.test(path))
|
|
46618
|
+
return true;
|
|
46512
46619
|
return /^\/topics\/[^/]+$/.test(path) || /^\/cron\/jobs\/[^/]+$/.test(path);
|
|
46513
46620
|
}
|
|
46514
46621
|
return false;
|
|
@@ -48559,4 +48666,4 @@ switch (command) {
|
|
|
48559
48666
|
}
|
|
48560
48667
|
}
|
|
48561
48668
|
|
|
48562
|
-
//# debugId=
|
|
48669
|
+
//# debugId=0FC049F7BD1544D864756E2164756E21
|