@essentialai/cogent-bridge
Version:
Cogent Bridge — cross-agent comms for Claude Code, OpenAI Codex and Slack. Codex users: install with `curl -fsSL https://cogent.tools/install.sh | sh`, then start with `cogent-codex` for real-time peer wake.
63 lines • 2.66 kB
JavaScript
export var BridgeErrorCode;
(function (BridgeErrorCode) {
BridgeErrorCode["CLI_NOT_FOUND"] = "CLI_NOT_FOUND";
BridgeErrorCode["CLI_TIMEOUT"] = "CLI_TIMEOUT";
BridgeErrorCode["CLI_EXEC_FAILED"] = "CLI_EXEC_FAILED";
BridgeErrorCode["STATE_CORRUPT"] = "STATE_CORRUPT";
BridgeErrorCode["STATE_WRITE_FAILED"] = "STATE_WRITE_FAILED";
BridgeErrorCode["LOCK_TIMEOUT"] = "LOCK_TIMEOUT";
BridgeErrorCode["LOCK_STALE"] = "LOCK_STALE";
BridgeErrorCode["PEER_NOT_FOUND"] = "PEER_NOT_FOUND";
BridgeErrorCode["INVALID_INPUT"] = "INVALID_INPUT";
BridgeErrorCode["STARTUP_FAILED"] = "STARTUP_FAILED";
BridgeErrorCode["DIR_NOT_WRITABLE"] = "DIR_NOT_WRITABLE";
BridgeErrorCode["NETWORK_TIMEOUT"] = "NETWORK_TIMEOUT";
BridgeErrorCode["JOIN_NOT_CONFIRMED"] = "JOIN_NOT_CONFIRMED";
/** cogent_join_session: the relay answered 404 to the name resolve (COG-81). Never any other status. */
BridgeErrorCode["CHANNEL_NOT_FOUND"] = "CHANNEL_NOT_FOUND";
/** The relay refused a peerId held by another connection (AUD-003). Never a reason to rename. */
BridgeErrorCode["PEER_NOT_YOURS"] = "PEER_NOT_YOURS";
/** COG-85: another live bridge in this folder holds the peerId (not this agent's own). Retry later, never rename. */
BridgeErrorCode["PEER_HELD_IN_FOLDER"] = "PEER_HELD_IN_FOLDER";
})(BridgeErrorCode || (BridgeErrorCode = {}));
export class BridgeError extends Error {
code;
suggestion;
/** Relay hint: ms until a refused peerId can be reclaimed (PEER_NOT_YOURS only). */
retryAfterMs;
constructor(code, message, suggestion) {
const fullMessage = suggestion
? `${code}: ${message}. ${suggestion}`
: `${code}: ${message}`;
super(fullMessage);
this.name = "BridgeError";
this.code = code;
this.suggestion = suggestion;
}
}
export function toolResult(text, isError) {
return {
content: [{ type: "text", text }],
...(isError ? { isError: true } : {}),
};
}
export function errorResult(error) {
if (error instanceof BridgeError) {
return toolResult(JSON.stringify({
success: false,
error: error.code,
message: error.message,
suggestion: error.suggestion,
}, null, 2), true);
}
const message = error instanceof Error ? error.message : String(error);
return toolResult(JSON.stringify({
success: false,
error: "INTERNAL_ERROR",
message,
}, null, 2), true);
}
export function successResult(data) {
return toolResult(JSON.stringify(data, null, 2), false);
}
//# sourceMappingURL=errors.js.map