@agent-relay/utils 2.0.29 → 2.0.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/dist/cjs/command-resolver.js +89 -0
- package/dist/cjs/error-tracking.js +106 -0
- package/dist/cjs/git-remote.js +120 -0
- package/dist/cjs/index.js +38 -0
- package/dist/cjs/logger.js +105 -0
- package/dist/cjs/model-mapping.js +54 -0
- package/dist/cjs/name-generator.js +179 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/precompiled-patterns.js +271 -0
- package/dist/cjs/relay-pty-path.js +143 -0
- package/dist/cjs/update-checker.js +185 -0
- package/dist/relay-pty-path.d.ts +11 -5
- package/dist/relay-pty-path.d.ts.map +1 -1
- package/dist/relay-pty-path.js +60 -5
- package/dist/relay-pty-path.js.map +1 -1
- package/package.json +30 -14
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var command_resolver_exports = {};
|
|
30
|
+
__export(command_resolver_exports, {
|
|
31
|
+
commandExists: () => commandExists,
|
|
32
|
+
resolveCommand: () => resolveCommand
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(command_resolver_exports);
|
|
35
|
+
var import_node_child_process = require("node:child_process");
|
|
36
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
37
|
+
function resolveCommand(command) {
|
|
38
|
+
if (command.startsWith("/")) {
|
|
39
|
+
return resolveSymlinks(command);
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const output = (0, import_node_child_process.execSync)(`which ${command}`, {
|
|
43
|
+
encoding: "utf-8",
|
|
44
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
45
|
+
// Ensure we have a reasonable PATH
|
|
46
|
+
env: {
|
|
47
|
+
...process.env,
|
|
48
|
+
PATH: process.env.PATH || "/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin"
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const resolvedPath = output.trim();
|
|
52
|
+
if (resolvedPath) {
|
|
53
|
+
return resolveSymlinks(resolvedPath);
|
|
54
|
+
}
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.warn(`[command-resolver] 'which ${command}' failed:`, err.message?.split("\n")[0] || "unknown error");
|
|
57
|
+
}
|
|
58
|
+
return command;
|
|
59
|
+
}
|
|
60
|
+
function resolveSymlinks(filePath) {
|
|
61
|
+
try {
|
|
62
|
+
const resolved = import_node_fs.default.realpathSync(filePath);
|
|
63
|
+
if (resolved !== filePath && process.env.DEBUG_SPAWN === "1") {
|
|
64
|
+
console.log(`[command-resolver] Resolved symlink: ${filePath} -> ${resolved}`);
|
|
65
|
+
}
|
|
66
|
+
return resolved;
|
|
67
|
+
} catch (err) {
|
|
68
|
+
if (process.env.DEBUG_SPAWN === "1") {
|
|
69
|
+
console.warn(`[command-resolver] realpath failed for ${filePath}:`, err.message);
|
|
70
|
+
}
|
|
71
|
+
return filePath;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function commandExists(command) {
|
|
75
|
+
try {
|
|
76
|
+
(0, import_node_child_process.execSync)(`which ${command}`, {
|
|
77
|
+
encoding: "utf-8",
|
|
78
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
79
|
+
});
|
|
80
|
+
return true;
|
|
81
|
+
} catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
commandExists,
|
|
88
|
+
resolveCommand
|
|
89
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var error_tracking_exports = {};
|
|
20
|
+
__export(error_tracking_exports, {
|
|
21
|
+
ERROR_SEARCH_HINT: () => ERROR_SEARCH_HINT,
|
|
22
|
+
TracedError: () => TracedError,
|
|
23
|
+
createTraceableError: () => createTraceableError,
|
|
24
|
+
generateErrorId: () => generateErrorId,
|
|
25
|
+
logAndTraceError: () => logAndTraceError,
|
|
26
|
+
withErrorTracing: () => withErrorTracing
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(error_tracking_exports);
|
|
29
|
+
var import_node_crypto = require("node:crypto");
|
|
30
|
+
function generateErrorId() {
|
|
31
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
32
|
+
const random = (0, import_node_crypto.randomBytes)(2).toString("hex");
|
|
33
|
+
return `ERR-${timestamp}-${random}`;
|
|
34
|
+
}
|
|
35
|
+
function createTraceableError(message, context = {}, originalError) {
|
|
36
|
+
const errorId = generateErrorId();
|
|
37
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
38
|
+
const contextPairs = Object.entries(context).filter(([, v]) => v !== void 0 && v !== null).map(([k, v]) => `${k}=${typeof v === "object" ? JSON.stringify(v) : v}`).join(" ");
|
|
39
|
+
const stackInfo = originalError?.stack ? `
|
|
40
|
+
Original error: ${originalError.message}
|
|
41
|
+
Stack: ${originalError.stack}` : "";
|
|
42
|
+
const logMessage = `[${errorId}] ${message}${contextPairs ? ` | ${contextPairs}` : ""}${stackInfo}`;
|
|
43
|
+
const userMessage = `${message} (Error ID: ${errorId} - share this with support)`;
|
|
44
|
+
return {
|
|
45
|
+
errorId,
|
|
46
|
+
userMessage,
|
|
47
|
+
logMessage,
|
|
48
|
+
timestamp,
|
|
49
|
+
message,
|
|
50
|
+
context: {
|
|
51
|
+
...context,
|
|
52
|
+
originalError: originalError?.message
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function logAndTraceError(message, context = {}, originalError) {
|
|
57
|
+
const error = createTraceableError(message, context, originalError);
|
|
58
|
+
console.error(error.logMessage);
|
|
59
|
+
return error;
|
|
60
|
+
}
|
|
61
|
+
function withErrorTracing(fn, baseContext = {}) {
|
|
62
|
+
return (async (...args) => {
|
|
63
|
+
try {
|
|
64
|
+
return await fn(...args);
|
|
65
|
+
} catch (err) {
|
|
66
|
+
const error = logAndTraceError(
|
|
67
|
+
err instanceof Error ? err.message : "Unknown error",
|
|
68
|
+
baseContext,
|
|
69
|
+
err instanceof Error ? err : void 0
|
|
70
|
+
);
|
|
71
|
+
throw new TracedError(error);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
class TracedError extends Error {
|
|
76
|
+
errorId;
|
|
77
|
+
userMessage;
|
|
78
|
+
context;
|
|
79
|
+
constructor(traced) {
|
|
80
|
+
super(traced.message);
|
|
81
|
+
this.name = "TracedError";
|
|
82
|
+
this.errorId = traced.errorId;
|
|
83
|
+
this.userMessage = traced.userMessage;
|
|
84
|
+
this.context = traced.context;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const ERROR_SEARCH_HINT = `
|
|
88
|
+
To find error details in logs, search for the error ID:
|
|
89
|
+
|
|
90
|
+
grep "ERR-1706012345-a7f3" /var/log/agent-relay/*.log
|
|
91
|
+
|
|
92
|
+
Or in cloud logging:
|
|
93
|
+
|
|
94
|
+
fly logs -a agent-relay-cloud | grep "ERR-1706012345-a7f3"
|
|
95
|
+
|
|
96
|
+
The log entry will include full context: user ID, workspace ID, agent name, etc.
|
|
97
|
+
`;
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
ERROR_SEARCH_HINT,
|
|
101
|
+
TracedError,
|
|
102
|
+
createTraceableError,
|
|
103
|
+
generateErrorId,
|
|
104
|
+
logAndTraceError,
|
|
105
|
+
withErrorTracing
|
|
106
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var git_remote_exports = {};
|
|
30
|
+
__export(git_remote_exports, {
|
|
31
|
+
findGitRoot: () => findGitRoot,
|
|
32
|
+
getGitRemoteUrl: () => getGitRemoteUrl,
|
|
33
|
+
getRepoFullName: () => getRepoFullName,
|
|
34
|
+
getRepoFullNameFromPath: () => getRepoFullNameFromPath,
|
|
35
|
+
parseGitRemoteUrl: () => parseGitRemoteUrl
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(git_remote_exports);
|
|
38
|
+
var fs = __toESM(require("node:fs"), 1);
|
|
39
|
+
var path = __toESM(require("node:path"), 1);
|
|
40
|
+
var import_node_child_process = require("node:child_process");
|
|
41
|
+
function parseGitRemoteUrl(url) {
|
|
42
|
+
if (!url) return null;
|
|
43
|
+
const sshMatch = url.match(/git@[^:]+:([^/]+\/[^/]+?)(?:\.git)?$/);
|
|
44
|
+
if (sshMatch) {
|
|
45
|
+
return sshMatch[1];
|
|
46
|
+
}
|
|
47
|
+
const httpsMatch = url.match(/(?:https?|git):\/\/[^/]+\/([^/]+\/[^/]+?)(?:\.git)?$/);
|
|
48
|
+
if (httpsMatch) {
|
|
49
|
+
return httpsMatch[1];
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function getGitRemoteUrl(workingDirectory, remoteName = "origin") {
|
|
54
|
+
try {
|
|
55
|
+
const gitDir = path.join(workingDirectory, ".git");
|
|
56
|
+
if (!fs.existsSync(gitDir)) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const result = (0, import_node_child_process.execSync)(`git remote get-url ${remoteName}`, {
|
|
60
|
+
cwd: workingDirectory,
|
|
61
|
+
encoding: "utf-8",
|
|
62
|
+
timeout: 5e3,
|
|
63
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
64
|
+
});
|
|
65
|
+
return result.trim() || null;
|
|
66
|
+
} catch {
|
|
67
|
+
try {
|
|
68
|
+
const configPath = path.join(workingDirectory, ".git", "config");
|
|
69
|
+
if (!fs.existsSync(configPath)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const config = fs.readFileSync(configPath, "utf-8");
|
|
73
|
+
const remoteSection = new RegExp(
|
|
74
|
+
`\\[remote\\s+"${remoteName}"\\][^\\[]*url\\s*=\\s*([^\\n]+)`,
|
|
75
|
+
"i"
|
|
76
|
+
);
|
|
77
|
+
const match = config.match(remoteSection);
|
|
78
|
+
return match?.[1]?.trim() || null;
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function getRepoFullName(workingDirectory) {
|
|
85
|
+
const remoteUrl = getGitRemoteUrl(workingDirectory);
|
|
86
|
+
if (!remoteUrl) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
return parseGitRemoteUrl(remoteUrl);
|
|
90
|
+
}
|
|
91
|
+
function findGitRoot(startPath) {
|
|
92
|
+
let currentPath = path.resolve(startPath);
|
|
93
|
+
const root = path.parse(currentPath).root;
|
|
94
|
+
while (currentPath !== root) {
|
|
95
|
+
if (fs.existsSync(path.join(currentPath, ".git"))) {
|
|
96
|
+
return currentPath;
|
|
97
|
+
}
|
|
98
|
+
currentPath = path.dirname(currentPath);
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
function getRepoFullNameFromPath(workingDirectory) {
|
|
103
|
+
let repoName = getRepoFullName(workingDirectory);
|
|
104
|
+
if (repoName) {
|
|
105
|
+
return repoName;
|
|
106
|
+
}
|
|
107
|
+
const gitRoot = findGitRoot(workingDirectory);
|
|
108
|
+
if (gitRoot && gitRoot !== workingDirectory) {
|
|
109
|
+
repoName = getRepoFullName(gitRoot);
|
|
110
|
+
}
|
|
111
|
+
return repoName;
|
|
112
|
+
}
|
|
113
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
114
|
+
0 && (module.exports = {
|
|
115
|
+
findGitRoot,
|
|
116
|
+
getGitRemoteUrl,
|
|
117
|
+
getRepoFullName,
|
|
118
|
+
getRepoFullNameFromPath,
|
|
119
|
+
parseGitRemoteUrl
|
|
120
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./name-generator.js"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("./logger.js"), module.exports);
|
|
20
|
+
__reExport(index_exports, require("./precompiled-patterns.js"), module.exports);
|
|
21
|
+
__reExport(index_exports, require("./command-resolver.js"), module.exports);
|
|
22
|
+
__reExport(index_exports, require("./git-remote.js"), module.exports);
|
|
23
|
+
__reExport(index_exports, require("./update-checker.js"), module.exports);
|
|
24
|
+
__reExport(index_exports, require("./error-tracking.js"), module.exports);
|
|
25
|
+
__reExport(index_exports, require("./model-mapping.js"), module.exports);
|
|
26
|
+
__reExport(index_exports, require("./relay-pty-path.js"), module.exports);
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
...require("./name-generator.js"),
|
|
30
|
+
...require("./logger.js"),
|
|
31
|
+
...require("./precompiled-patterns.js"),
|
|
32
|
+
...require("./command-resolver.js"),
|
|
33
|
+
...require("./git-remote.js"),
|
|
34
|
+
...require("./update-checker.js"),
|
|
35
|
+
...require("./error-tracking.js"),
|
|
36
|
+
...require("./model-mapping.js"),
|
|
37
|
+
...require("./relay-pty-path.js")
|
|
38
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var logger_exports = {};
|
|
30
|
+
__export(logger_exports, {
|
|
31
|
+
connectionLog: () => connectionLog,
|
|
32
|
+
createLogger: () => createLogger,
|
|
33
|
+
daemonLog: () => daemonLog,
|
|
34
|
+
default: () => logger_default,
|
|
35
|
+
routerLog: () => routerLog
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(logger_exports);
|
|
38
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
39
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
40
|
+
const LOG_FILE = process.env.AGENT_RELAY_LOG_FILE;
|
|
41
|
+
const LOG_LEVEL = (process.env.AGENT_RELAY_LOG_LEVEL ?? "INFO").toUpperCase();
|
|
42
|
+
const LOG_JSON = process.env.AGENT_RELAY_LOG_JSON === "1";
|
|
43
|
+
const _DEBUG = process.env.DEBUG === "1" || LOG_LEVEL === "DEBUG";
|
|
44
|
+
const LEVEL_PRIORITY = {
|
|
45
|
+
DEBUG: 0,
|
|
46
|
+
INFO: 1,
|
|
47
|
+
WARN: 2,
|
|
48
|
+
ERROR: 3
|
|
49
|
+
};
|
|
50
|
+
if (LOG_FILE) {
|
|
51
|
+
const logDir = import_node_path.default.dirname(LOG_FILE);
|
|
52
|
+
if (!import_node_fs.default.existsSync(logDir)) {
|
|
53
|
+
import_node_fs.default.mkdirSync(logDir, { recursive: true });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function shouldLog(level) {
|
|
57
|
+
return LEVEL_PRIORITY[level] >= LEVEL_PRIORITY[LOG_LEVEL];
|
|
58
|
+
}
|
|
59
|
+
function formatMessage(entry) {
|
|
60
|
+
if (LOG_JSON) {
|
|
61
|
+
return JSON.stringify(entry);
|
|
62
|
+
}
|
|
63
|
+
const { ts, level, component, msg, ...extra } = entry;
|
|
64
|
+
const extraStr = Object.keys(extra).length > 0 ? " " + Object.entries(extra).map(([k, v]) => `${k}=${v}`).join(" ") : "";
|
|
65
|
+
return `${ts} [${level}] [${component}] ${msg}${extraStr}`;
|
|
66
|
+
}
|
|
67
|
+
function log(level, component, msg, extra) {
|
|
68
|
+
if (!shouldLog(level)) return;
|
|
69
|
+
const entry = {
|
|
70
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
71
|
+
level,
|
|
72
|
+
component,
|
|
73
|
+
msg,
|
|
74
|
+
...extra
|
|
75
|
+
};
|
|
76
|
+
const formatted = formatMessage(entry);
|
|
77
|
+
if (LOG_FILE) {
|
|
78
|
+
import_node_fs.default.appendFileSync(LOG_FILE, formatted + "\n");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (level === "ERROR" || level === "WARN") {
|
|
82
|
+
console.error(formatted);
|
|
83
|
+
} else {
|
|
84
|
+
console.log(formatted);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function createLogger(component) {
|
|
88
|
+
return {
|
|
89
|
+
debug: (msg, extra) => log("DEBUG", component, msg, extra),
|
|
90
|
+
info: (msg, extra) => log("INFO", component, msg, extra),
|
|
91
|
+
warn: (msg, extra) => log("WARN", component, msg, extra),
|
|
92
|
+
error: (msg, extra) => log("ERROR", component, msg, extra)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const daemonLog = createLogger("daemon");
|
|
96
|
+
const routerLog = createLogger("router");
|
|
97
|
+
const connectionLog = createLogger("connection");
|
|
98
|
+
var logger_default = createLogger;
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
connectionLog,
|
|
102
|
+
createLogger,
|
|
103
|
+
daemonLog,
|
|
104
|
+
routerLog
|
|
105
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var model_mapping_exports = {};
|
|
20
|
+
__export(model_mapping_exports, {
|
|
21
|
+
getBaseCli: () => getBaseCli,
|
|
22
|
+
mapModelToCli: () => mapModelToCli
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(model_mapping_exports);
|
|
25
|
+
const MODEL_TO_CLI = {
|
|
26
|
+
// Claude models
|
|
27
|
+
"claude-sonnet-4": "claude:sonnet",
|
|
28
|
+
"claude-opus-4": "claude:opus",
|
|
29
|
+
"claude-opus-4.5": "claude:opus",
|
|
30
|
+
"sonnet": "claude:sonnet",
|
|
31
|
+
"opus": "claude:opus",
|
|
32
|
+
"haiku": "claude:haiku",
|
|
33
|
+
// Codex (OpenAI)
|
|
34
|
+
"codex": "codex",
|
|
35
|
+
"gpt-4o": "codex",
|
|
36
|
+
// Gemini (Google)
|
|
37
|
+
"gemini": "gemini",
|
|
38
|
+
"gemini-2.0-flash": "gemini"
|
|
39
|
+
};
|
|
40
|
+
function mapModelToCli(model) {
|
|
41
|
+
if (!model) {
|
|
42
|
+
return "claude:sonnet";
|
|
43
|
+
}
|
|
44
|
+
const normalized = model.trim().toLowerCase();
|
|
45
|
+
return MODEL_TO_CLI[normalized] ?? "claude:sonnet";
|
|
46
|
+
}
|
|
47
|
+
function getBaseCli(cliVariant) {
|
|
48
|
+
return cliVariant.split(":")[0];
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
getBaseCli,
|
|
53
|
+
mapModelToCli
|
|
54
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var name_generator_exports = {};
|
|
20
|
+
__export(name_generator_exports, {
|
|
21
|
+
generateAgentName: () => generateAgentName,
|
|
22
|
+
generateUniqueAgentName: () => generateUniqueAgentName,
|
|
23
|
+
isValidAgentName: () => isValidAgentName
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(name_generator_exports);
|
|
26
|
+
const ADJECTIVES = [
|
|
27
|
+
"Blue",
|
|
28
|
+
"Green",
|
|
29
|
+
"Red",
|
|
30
|
+
"Purple",
|
|
31
|
+
"Golden",
|
|
32
|
+
"Silver",
|
|
33
|
+
"Crystal",
|
|
34
|
+
"Amber",
|
|
35
|
+
"Coral",
|
|
36
|
+
"Jade",
|
|
37
|
+
"Ruby",
|
|
38
|
+
"Sapphire",
|
|
39
|
+
"Emerald",
|
|
40
|
+
"Onyx",
|
|
41
|
+
"Pearl",
|
|
42
|
+
"Copper",
|
|
43
|
+
"Bronze",
|
|
44
|
+
"Iron",
|
|
45
|
+
"Steel",
|
|
46
|
+
"Velvet",
|
|
47
|
+
"Silk",
|
|
48
|
+
"Cotton",
|
|
49
|
+
"Linen",
|
|
50
|
+
"Marble",
|
|
51
|
+
"Granite",
|
|
52
|
+
"Cobalt",
|
|
53
|
+
"Crimson",
|
|
54
|
+
"Azure",
|
|
55
|
+
"Indigo",
|
|
56
|
+
"Scarlet",
|
|
57
|
+
"Violet",
|
|
58
|
+
"Olive",
|
|
59
|
+
"Teal",
|
|
60
|
+
"Cyan",
|
|
61
|
+
"Magenta",
|
|
62
|
+
"Ochre",
|
|
63
|
+
"Rustic",
|
|
64
|
+
"Misty",
|
|
65
|
+
"Stormy",
|
|
66
|
+
"Sunny",
|
|
67
|
+
"Frosty",
|
|
68
|
+
"Dusty",
|
|
69
|
+
"Mossy",
|
|
70
|
+
"Rocky",
|
|
71
|
+
"Sandy",
|
|
72
|
+
"Snowy",
|
|
73
|
+
"Windy",
|
|
74
|
+
"Swift",
|
|
75
|
+
"Calm",
|
|
76
|
+
"Bold",
|
|
77
|
+
"Brave",
|
|
78
|
+
"Clever",
|
|
79
|
+
"Eager",
|
|
80
|
+
"Gentle",
|
|
81
|
+
"Happy",
|
|
82
|
+
"Jolly",
|
|
83
|
+
"Kind",
|
|
84
|
+
"Lively",
|
|
85
|
+
"Merry",
|
|
86
|
+
"Noble",
|
|
87
|
+
"Proud",
|
|
88
|
+
"Quick",
|
|
89
|
+
"Quiet"
|
|
90
|
+
];
|
|
91
|
+
const NOUNS = [
|
|
92
|
+
"Mountain",
|
|
93
|
+
"River",
|
|
94
|
+
"Forest",
|
|
95
|
+
"Ocean",
|
|
96
|
+
"Valley",
|
|
97
|
+
"Canyon",
|
|
98
|
+
"Desert",
|
|
99
|
+
"Island",
|
|
100
|
+
"Lake",
|
|
101
|
+
"Meadow",
|
|
102
|
+
"Prairie",
|
|
103
|
+
"Glacier",
|
|
104
|
+
"Volcano",
|
|
105
|
+
"Waterfall",
|
|
106
|
+
"Creek",
|
|
107
|
+
"Pond",
|
|
108
|
+
"Hill",
|
|
109
|
+
"Peak",
|
|
110
|
+
"Ridge",
|
|
111
|
+
"Cliff",
|
|
112
|
+
"Cave",
|
|
113
|
+
"Reef",
|
|
114
|
+
"Marsh",
|
|
115
|
+
"Grove",
|
|
116
|
+
"Fox",
|
|
117
|
+
"Wolf",
|
|
118
|
+
"Bear",
|
|
119
|
+
"Eagle",
|
|
120
|
+
"Hawk",
|
|
121
|
+
"Owl",
|
|
122
|
+
"Deer",
|
|
123
|
+
"Elk",
|
|
124
|
+
"Falcon",
|
|
125
|
+
"Raven",
|
|
126
|
+
"Swan",
|
|
127
|
+
"Crane",
|
|
128
|
+
"Heron",
|
|
129
|
+
"Otter",
|
|
130
|
+
"Beaver",
|
|
131
|
+
"Badger",
|
|
132
|
+
"Castle",
|
|
133
|
+
"Tower",
|
|
134
|
+
"Bridge",
|
|
135
|
+
"Harbor",
|
|
136
|
+
"Haven",
|
|
137
|
+
"Shelter",
|
|
138
|
+
"Beacon",
|
|
139
|
+
"Anchor",
|
|
140
|
+
"Stone",
|
|
141
|
+
"Pebble",
|
|
142
|
+
"Boulder",
|
|
143
|
+
"Crystal",
|
|
144
|
+
"Gem",
|
|
145
|
+
"Prism",
|
|
146
|
+
"Spark",
|
|
147
|
+
"Ember",
|
|
148
|
+
"Star",
|
|
149
|
+
"Moon",
|
|
150
|
+
"Sun",
|
|
151
|
+
"Comet",
|
|
152
|
+
"Cloud",
|
|
153
|
+
"Storm",
|
|
154
|
+
"Thunder",
|
|
155
|
+
"Lightning"
|
|
156
|
+
];
|
|
157
|
+
function generateAgentName() {
|
|
158
|
+
const adjective = ADJECTIVES[Math.floor(Math.random() * ADJECTIVES.length)];
|
|
159
|
+
const noun = NOUNS[Math.floor(Math.random() * NOUNS.length)];
|
|
160
|
+
return `${adjective}${noun}`;
|
|
161
|
+
}
|
|
162
|
+
function generateUniqueAgentName(existingNames, maxAttempts = 100) {
|
|
163
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
164
|
+
const name = generateAgentName();
|
|
165
|
+
if (!existingNames.has(name)) {
|
|
166
|
+
return name;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return `${generateAgentName()}${Math.floor(Math.random() * 1e3)}`;
|
|
170
|
+
}
|
|
171
|
+
function isValidAgentName(name) {
|
|
172
|
+
return /^[a-zA-Z][a-zA-Z0-9_-]{1,31}$/.test(name);
|
|
173
|
+
}
|
|
174
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
175
|
+
0 && (module.exports = {
|
|
176
|
+
generateAgentName,
|
|
177
|
+
generateUniqueAgentName,
|
|
178
|
+
isValidAgentName
|
|
179
|
+
});
|