@auroraflow/code 0.0.6 → 0.0.8
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/README.md +67 -189
- package/bin/aurora-claude.js +4 -0
- package/bin/aurora-codex.js +4 -0
- package/bin/aurora-postinstall.js +24 -0
- package/bin/aurora-sidecar.js +4 -0
- package/bin/aurora.js +2 -382
- package/lib/aurora-api.js +100 -0
- package/lib/commands.js +27 -0
- package/lib/launcher.js +9 -0
- package/lib/pickers.js +137 -0
- package/lib/prompt.js +136 -0
- package/lib/sidecar-client.js +10 -0
- package/lib/sidecar.js +1 -0
- package/lib/state.js +1 -0
- package/package.json +20 -24
- package/packages/cli/package.json +9 -0
- package/packages/cli/src/index.js +135 -0
- package/packages/clients/package.json +9 -0
- package/packages/clients/src/index.js +299 -0
- package/packages/protocol/package.json +9 -0
- package/packages/protocol/src/index.js +170 -0
- package/packages/protocol/src/index.test.js +180 -0
- package/packages/sidecar/package.json +9 -0
- package/packages/sidecar/src/index.js +177 -0
- package/packages/state/package.json +9 -0
- package/packages/state/src/index.js +57 -0
- package/scripts/install_posix_launcher.js +0 -106
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { AURORA_LOCALHOST, AURORA_SIDECAR_PORT, isRuntimePath, rewriteRuntimeModel, selectedKeyHeaders, toClientModelItem, toCodexModelInfo, trimSlash } from "../../protocol/src/index.js";
|
|
5
|
+
import { CODEX_HOME, readState, writeSidecarInfo } from "../../state/src/index.js";
|
|
6
|
+
|
|
7
|
+
const CODEX_MODEL_CAPABILITIES_PATH = join(CODEX_HOME, "model_capabilities.json");
|
|
8
|
+
|
|
9
|
+
export async function startSidecar(options = {}) {
|
|
10
|
+
const token = options.token || readArg("--token") || process.env.AURORA_SIDECAR_TOKEN || "aurora-local-dev";
|
|
11
|
+
const port = Number(options.port || readArg("--port") || process.env.AURORA_SIDECAR_PORT || AURORA_SIDECAR_PORT);
|
|
12
|
+
const server = createServer((request, response) => {
|
|
13
|
+
handle(request, response, token).catch(error => {
|
|
14
|
+
response.writeHead(500, { "content-type": "application/json" });
|
|
15
|
+
response.end(JSON.stringify({ error: { type: "sidecar_error", message: error.message } }));
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
server.listen(port, AURORA_LOCALHOST, async () => {
|
|
19
|
+
await writeSidecarInfo({ port, token, baseURL: `http://${AURORA_LOCALHOST}:${port}` });
|
|
20
|
+
console.error(`Aurora sidecar listening on http://${AURORA_LOCALHOST}:${port}`);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function handle(request, response, token) {
|
|
25
|
+
if (!isAuthorized(request, token)) {
|
|
26
|
+
writeJSON(response, 401, { error: { type: "unauthorized", message: "sidecar token required" } });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const url = new URL(request.url, `http://${AURORA_LOCALHOST}`);
|
|
30
|
+
if (request.method === "GET" && url.pathname === "/aurora/status") {
|
|
31
|
+
const state = await readState();
|
|
32
|
+
writeJSON(response, 200, {
|
|
33
|
+
ok: true,
|
|
34
|
+
selectedKey: Boolean(state.selectedKey?.presentedKey),
|
|
35
|
+
selectedModel: state.selectedModel ?? null
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (request.method === "GET" && url.pathname === "/v1/models") {
|
|
40
|
+
await proxyModels(response, url);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (request.method === "POST" && isRuntimePath(url.pathname)) {
|
|
44
|
+
await proxyRuntime(request, response, url.pathname + url.search);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
writeJSON(response, 404, { error: { type: "not_found", message: "unknown sidecar route" } });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function proxyModels(response, incomingURL) {
|
|
51
|
+
const state = await readState();
|
|
52
|
+
const gatewayURL = trimSlash(state.gatewayURL ?? "https://auroramos.com");
|
|
53
|
+
const clientVersion = incomingURL.searchParams.get("client_version");
|
|
54
|
+
const upstreamURL = clientVersion
|
|
55
|
+
? `${gatewayURL}/v1/aurora-cli/models?client_version=${encodeURIComponent(clientVersion)}`
|
|
56
|
+
: `${gatewayURL}/v1/aurora-cli/models`;
|
|
57
|
+
const upstream = await fetch(upstreamURL, {
|
|
58
|
+
headers: {
|
|
59
|
+
...selectedKeyHeaders(state),
|
|
60
|
+
"accept-encoding": "identity"
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const payload = await upstream.json().catch(() => ({ object: "list", data: [] }));
|
|
64
|
+
const sourceModels = Array.isArray(payload.data) ? payload.data : [];
|
|
65
|
+
if (clientVersion) {
|
|
66
|
+
await writeCodexModelCapabilities(sourceModels);
|
|
67
|
+
const models = sourceModels.map((item, index) => toCodexModelInfo(item, index));
|
|
68
|
+
writeJSON(response, upstream.ok ? 200 : upstream.status, { models });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const data = sourceModels.map(toClientModelItem);
|
|
72
|
+
writeJSON(response, upstream.ok ? 200 : upstream.status, { object: "list", data });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function proxyRuntime(request, response, path) {
|
|
76
|
+
const state = await readState();
|
|
77
|
+
const body = await readBody(request);
|
|
78
|
+
const capabilitiesByAlias = await readCodexModelCapabilities();
|
|
79
|
+
const gatewayURL = trimSlash(state.gatewayURL ?? "https://auroramos.com");
|
|
80
|
+
const upstream = await fetch(`${gatewayURL}${path}`, {
|
|
81
|
+
method: request.method,
|
|
82
|
+
headers: {
|
|
83
|
+
...copyForwardHeaders(request.headers),
|
|
84
|
+
...selectedKeyHeaders(state),
|
|
85
|
+
"content-type": request.headers["content-type"] ?? "application/json",
|
|
86
|
+
"accept-encoding": "identity"
|
|
87
|
+
},
|
|
88
|
+
body: rewriteRuntimeModel(body, state.selectedModel?.alias, capabilitiesByAlias)
|
|
89
|
+
});
|
|
90
|
+
response.writeHead(upstream.status, responseHeaders(upstream.headers));
|
|
91
|
+
if (upstream.body) {
|
|
92
|
+
for await (const chunk of upstream.body) response.write(chunk);
|
|
93
|
+
}
|
|
94
|
+
response.end();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function writeCodexModelCapabilities(sourceModels) {
|
|
98
|
+
const models = {};
|
|
99
|
+
for (const item of sourceModels) {
|
|
100
|
+
const alias = String(item.alias ?? item.id ?? item.model_id ?? "");
|
|
101
|
+
if (!alias) continue;
|
|
102
|
+
models[alias] = {
|
|
103
|
+
supports_web_search: item.supports_web_search === true,
|
|
104
|
+
web_search_tool_type: item.web_search_tool_type ?? null
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
await writeFile(CODEX_MODEL_CAPABILITIES_PATH, `${JSON.stringify({
|
|
108
|
+
generated_at: new Date().toISOString(),
|
|
109
|
+
models
|
|
110
|
+
}, null, 2)}\n`, { mode: 0o600 });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function readCodexModelCapabilities() {
|
|
114
|
+
try {
|
|
115
|
+
const payload = JSON.parse(await readFile(CODEX_MODEL_CAPABILITIES_PATH, "utf8"));
|
|
116
|
+
return payload && typeof payload.models === "object" && payload.models !== null ? payload.models : {};
|
|
117
|
+
} catch {
|
|
118
|
+
return {};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function isAuthorized(request, token) {
|
|
123
|
+
const auth = String(request.headers.authorization ?? "");
|
|
124
|
+
const xKey = String(request.headers["x-api-key"] ?? "");
|
|
125
|
+
return auth === `Bearer ${token}` || xKey === token;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function copyForwardHeaders(headers) {
|
|
129
|
+
const out = {};
|
|
130
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
131
|
+
if (["host", "authorization", "x-api-key", "content-length", "accept-encoding"].includes(key.toLowerCase())) continue;
|
|
132
|
+
if (value !== undefined) out[key] = Array.isArray(value) ? value.join(", ") : value;
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function responseHeaders(headers) {
|
|
138
|
+
const out = {};
|
|
139
|
+
for (const [key, value] of headers.entries()) {
|
|
140
|
+
const normalized = key.toLowerCase();
|
|
141
|
+
if ([
|
|
142
|
+
"connection",
|
|
143
|
+
"content-encoding",
|
|
144
|
+
"content-length",
|
|
145
|
+
"keep-alive",
|
|
146
|
+
"proxy-authenticate",
|
|
147
|
+
"proxy-authorization",
|
|
148
|
+
"te",
|
|
149
|
+
"trailer",
|
|
150
|
+
"transfer-encoding",
|
|
151
|
+
"upgrade"
|
|
152
|
+
].includes(normalized)) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
out[key] = value;
|
|
156
|
+
}
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function readBody(request) {
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
const chunks = [];
|
|
163
|
+
request.on("data", chunk => chunks.push(chunk));
|
|
164
|
+
request.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
|
165
|
+
request.on("error", reject);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function writeJSON(response, status, payload) {
|
|
170
|
+
response.writeHead(status, { "content-type": "application/json" });
|
|
171
|
+
response.end(JSON.stringify(payload));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function readArg(name) {
|
|
175
|
+
const index = process.argv.indexOf(name);
|
|
176
|
+
return index >= 0 ? process.argv[index + 1] : "";
|
|
177
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
export const AURORA_HOME = process.env.AURORA_HOME || join(homedir(), ".aurora");
|
|
6
|
+
export const STATE_PATH = join(AURORA_HOME, "agent-state.json");
|
|
7
|
+
export const ACCOUNT_PATH = join(AURORA_HOME, "account.json");
|
|
8
|
+
export const SIDECAR_PATH = join(AURORA_HOME, "sidecar.json");
|
|
9
|
+
export const CLAUDE_HOME = join(AURORA_HOME, "clients", "claude");
|
|
10
|
+
export const CODEX_HOME = join(AURORA_HOME, "clients", "codex");
|
|
11
|
+
|
|
12
|
+
export async function ensureLayout() {
|
|
13
|
+
await mkdir(AURORA_HOME, { recursive: true });
|
|
14
|
+
await mkdir(CLAUDE_HOME, { recursive: true });
|
|
15
|
+
await mkdir(CODEX_HOME, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function readState() {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(await readFile(STATE_PATH, "utf8"));
|
|
21
|
+
} catch {
|
|
22
|
+
return {
|
|
23
|
+
gatewayURL: "https://auroramos.com",
|
|
24
|
+
controlPlaneURL: "https://auroramos.com/api/v1"
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function writeState(next) {
|
|
30
|
+
await ensureLayout();
|
|
31
|
+
await writeFile(STATE_PATH, JSON.stringify(next, null, 2) + "\n", { mode: 0o600 });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function readAccount() {
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(await readFile(ACCOUNT_PATH, "utf8"));
|
|
37
|
+
} catch {
|
|
38
|
+
return {
|
|
39
|
+
controlPlaneURL: "https://auroramos.com/api/v1",
|
|
40
|
+
gatewayURL: "https://auroramos.com"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function writeAccount(next) {
|
|
46
|
+
await ensureLayout();
|
|
47
|
+
await writeFile(ACCOUNT_PATH, JSON.stringify(next, null, 2) + "\n", { mode: 0o600 });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function writeSidecarInfo(info) {
|
|
51
|
+
await ensureLayout();
|
|
52
|
+
await writeFile(SIDECAR_PATH, JSON.stringify(info, null, 2) + "\n", { mode: 0o600 });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function readSidecarInfo() {
|
|
56
|
+
return JSON.parse(await readFile(SIDECAR_PATH, "utf8"));
|
|
57
|
+
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Replaces the installed Unix npm shim with a launcher that execs the native binary.
|
|
3
|
-
|
|
4
|
-
import { chmodSync, existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
|
|
8
|
-
if (process.platform === "win32") {
|
|
9
|
-
process.exit(0);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
-
const packageRoot = path.resolve(path.dirname(__filename), "..");
|
|
14
|
-
const binDir = path.join(packageRoot, "bin");
|
|
15
|
-
const entryPath = path.join(binDir, "aurora.js");
|
|
16
|
-
const nodeEntryPath = path.join(binDir, "aurora-node.js");
|
|
17
|
-
|
|
18
|
-
if (!existsSync(entryPath)) {
|
|
19
|
-
process.exit(0);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!existsSync(nodeEntryPath)) {
|
|
23
|
-
writeFileSync(nodeEntryPath, readFileSync(entryPath));
|
|
24
|
-
chmodSync(nodeEntryPath, 0o755);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const launcher = `#!/bin/sh
|
|
28
|
-
# Aurora Code POSIX launcher. Generated at npm install time.
|
|
29
|
-
|
|
30
|
-
set -e
|
|
31
|
-
|
|
32
|
-
resolve_dir() {
|
|
33
|
-
CDPATH= cd -- "$1" 2>/dev/null && pwd -P
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
SELF=$0
|
|
37
|
-
while [ -L "$SELF" ]; do
|
|
38
|
-
LINK=$(readlink "$SELF")
|
|
39
|
-
case "$LINK" in
|
|
40
|
-
/*) SELF=$LINK ;;
|
|
41
|
-
*) SELF=$(dirname -- "$SELF")/$LINK ;;
|
|
42
|
-
esac
|
|
43
|
-
done
|
|
44
|
-
|
|
45
|
-
BIN_DIR=$(resolve_dir "$(dirname -- "$SELF")")
|
|
46
|
-
PACKAGE_ROOT=$(resolve_dir "$BIN_DIR/..")
|
|
47
|
-
|
|
48
|
-
case "$(uname -s)" in
|
|
49
|
-
Darwin) OS=apple-darwin ;;
|
|
50
|
-
Linux) OS=unknown-linux-gnu ;;
|
|
51
|
-
*) exec node "$BIN_DIR/aurora-node.js" "$@" ;;
|
|
52
|
-
esac
|
|
53
|
-
|
|
54
|
-
case "$(uname -m)" in
|
|
55
|
-
arm64|aarch64) ARCH=aarch64 ;;
|
|
56
|
-
x86_64|amd64) ARCH=x86_64 ;;
|
|
57
|
-
*) exec node "$BIN_DIR/aurora-node.js" "$@" ;;
|
|
58
|
-
esac
|
|
59
|
-
|
|
60
|
-
TARGET="$ARCH-$OS"
|
|
61
|
-
case "$TARGET" in
|
|
62
|
-
aarch64-apple-darwin) NATIVE_PACKAGE="@auroraflow/code-darwin-arm64" ;;
|
|
63
|
-
x86_64-apple-darwin) NATIVE_PACKAGE="@auroraflow/code-darwin-x64" ;;
|
|
64
|
-
aarch64-unknown-linux-gnu) NATIVE_PACKAGE="@auroraflow/code-linux-arm64" ;;
|
|
65
|
-
x86_64-unknown-linux-gnu) NATIVE_PACKAGE="@auroraflow/code-linux-x64" ;;
|
|
66
|
-
*) exec node "$BIN_DIR/aurora-node.js" "$@" ;;
|
|
67
|
-
esac
|
|
68
|
-
|
|
69
|
-
NATIVE_ROOT="$PACKAGE_ROOT/node_modules/$NATIVE_PACKAGE/vendor/$TARGET"
|
|
70
|
-
BINARY="$NATIVE_ROOT/bin/aurora"
|
|
71
|
-
if [ ! -x "$BINARY" ]; then
|
|
72
|
-
NATIVE_ROOT="$PACKAGE_ROOT/vendor/$TARGET"
|
|
73
|
-
BINARY="$NATIVE_ROOT/bin/aurora"
|
|
74
|
-
fi
|
|
75
|
-
|
|
76
|
-
if [ ! -x "$BINARY" ]; then
|
|
77
|
-
exec node "$BIN_DIR/aurora-node.js" "$@"
|
|
78
|
-
fi
|
|
79
|
-
|
|
80
|
-
if [ -z "\${AURORA_HOME+x}" ] || [ -z "$AURORA_HOME" ]; then
|
|
81
|
-
AURORA_HOME="$HOME/.aurora"
|
|
82
|
-
fi
|
|
83
|
-
|
|
84
|
-
export AURORA_HOME
|
|
85
|
-
export CODEX_HOME="$AURORA_HOME"
|
|
86
|
-
export AURORA_MANAGED_BY_NPM=1
|
|
87
|
-
export CODEX_MANAGED_BY_NPM=1
|
|
88
|
-
export AURORA_MANAGED_PACKAGE_ROOT="$PACKAGE_ROOT"
|
|
89
|
-
export CODEX_MANAGED_PACKAGE_ROOT="$PACKAGE_ROOT"
|
|
90
|
-
|
|
91
|
-
if [ -d "$NATIVE_ROOT/aurora-path" ]; then
|
|
92
|
-
PATH="$NATIVE_ROOT/aurora-path:$PATH"
|
|
93
|
-
elif [ -d "$NATIVE_ROOT/path" ]; then
|
|
94
|
-
PATH="$NATIVE_ROOT/path:$PATH"
|
|
95
|
-
fi
|
|
96
|
-
export PATH
|
|
97
|
-
|
|
98
|
-
if [ -t 1 ]; then
|
|
99
|
-
printf '\\033]0;aurora\\007'
|
|
100
|
-
fi
|
|
101
|
-
|
|
102
|
-
exec "$BINARY" "$@"
|
|
103
|
-
`;
|
|
104
|
-
|
|
105
|
-
writeFileSync(entryPath, launcher);
|
|
106
|
-
chmodSync(entryPath, 0o755);
|