@neuralnomads/codenomad 0.13.1 → 0.14.0
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/auth/manager.js +5 -1
- package/dist/background-processes/manager.js +164 -25
- package/dist/clients/connection-manager.js +93 -0
- package/dist/config/schema.js +1 -0
- package/dist/events/bus.js +4 -0
- package/dist/filesystem/browser.js +7 -0
- package/dist/index.js +56 -5
- package/dist/opencode-config/package.json +1 -1
- package/dist/opencode-config/plugin/codenomad.ts +30 -0
- package/dist/opencode-config/plugin/lib/background-process.ts +14 -2
- package/dist/plugins/voice-mode.js +78 -0
- package/dist/server/__tests__/network-addresses.test.js +68 -0
- package/dist/server/http-server.js +294 -3
- package/dist/server/network-addresses.js +43 -1
- package/dist/server/routes/background-processes.js +19 -1
- package/dist/server/routes/events.js +24 -1
- package/dist/server/routes/meta.js +0 -3
- package/dist/server/routes/plugin.js +22 -4
- package/dist/server/routes/remote-servers.js +142 -0
- package/dist/server/routes/sidecars.js +46 -0
- package/dist/server/routes/workspaces.js +14 -0
- package/dist/settings/migrate.js +5 -0
- package/dist/settings/service.js +64 -4
- package/dist/sidecars/manager.js +193 -0
- package/dist/speech/providers/openai-compatible.js +32 -11
- package/dist/ui/__tests__/remote-ui.test.js +21 -0
- package/dist/ui/remote-ui.js +2 -2
- package/dist/workspaces/manager.js +7 -0
- package/dist/workspaces/runtime.js +2 -1
- package/package.json +1 -1
- package/public/assets/ChangesTab-CFkk3tAp.js +2 -0
- package/public/assets/DiffToolbar-CQQLR1mp.js +1 -0
- package/public/assets/FilesTab-CXgucPtN.js +2 -0
- package/public/assets/GitChangesTab-BidSb28_.js +2 -0
- package/public/assets/{SplitFilePanel-DbTPpm8n.js → SplitFilePanel-CupweEA5.js} +1 -1
- package/public/assets/StatusTab-C2Pl_Vce.js +1 -0
- package/public/assets/{bundle-full-UinVq7HP.js → bundle-full-B-5u6Iv3.js} +1 -1
- package/public/assets/diff-viewer-_ehhYA-Z.js +1 -0
- package/public/assets/git-diff-vendor-CSgooKT_.js +52 -0
- package/public/assets/index-BnfDkr8C.js +1 -0
- package/public/assets/index-BntAaLZs.js +1 -0
- package/public/assets/index-BqiNjV6R.js +1 -0
- package/public/assets/index-BwCEJ4BE.css +1 -0
- package/public/assets/{index-CdoHjzfy.js → index-CxQr-wOF.js} +1 -1
- package/public/assets/index-DXaitXVC.js +1 -0
- package/public/assets/index-DzRzoTK8.js +2 -0
- package/public/assets/index-ShHad48G.js +1 -0
- package/public/assets/index-_EaXFUIj.js +1 -0
- package/public/assets/index-mMh5TJvW.js +1 -0
- package/public/assets/{loading-D8mHQfQ7.js → loading-Dck2H3XH.js} +1 -1
- package/public/assets/main-BsIf5lOY.js +50 -0
- package/public/assets/{markdown-pqPmydDQ.js → markdown-CFV9kR80.js} +20 -20
- package/public/assets/monaco-viewer-CMM6n0T3.js +25 -0
- package/public/assets/{todo-BbZMcvOc.js → todo-Ghwirj-b.js} +1 -1
- package/public/assets/tool-call-BC2Pv3uG.js +60 -0
- package/public/assets/unified-picker-Dw0kTXoT.js +1 -0
- package/public/assets/wrap-text-D2MJk2ad.js +1 -0
- package/public/index.html +5 -5
- package/public/loading.html +5 -5
- package/public/sw.js +1 -1
- package/public/ui-version.json +1 -1
- package/public/assets/ChangesTab-DdswQ3Ok.js +0 -2
- package/public/assets/DiffToolbar-Yldqxvj8.js +0 -1
- package/public/assets/FilesTab-7agluNpw.js +0 -2
- package/public/assets/GitChangesTab-BZ5PaHzK.js +0 -2
- package/public/assets/StatusTab-CKBp3O9-.js +0 -1
- package/public/assets/diff-viewer-D9gxUZHP.js +0 -1
- package/public/assets/git-diff-vendor-CAv-4upN.js +0 -52
- package/public/assets/index-0Gk1-9Cd.js +0 -1
- package/public/assets/index-BEO8r15M.js +0 -1
- package/public/assets/index-BH7b9sVx.js +0 -1
- package/public/assets/index-CHPcUby9.js +0 -2
- package/public/assets/index-Cjpfqqyq.js +0 -1
- package/public/assets/index-D7Ta2Qha.js +0 -1
- package/public/assets/index-DxTSRG2o.js +0 -1
- package/public/assets/index-ENvu-xYE.css +0 -1
- package/public/assets/index-YR_aK97-.js +0 -1
- package/public/assets/main-DnH_qzWG.js +0 -56
- package/public/assets/monaco-viewer-BSBw02bx.js +0 -15
- package/public/assets/tool-call-BBzW7Hvr.js +0 -60
- package/public/assets/unified-picker-DcafxZRV.js +0 -1
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { PluginChannelManager } from "../../plugins/channel";
|
|
3
2
|
import { buildPingEvent, handlePluginEvent } from "../../plugins/handlers";
|
|
4
3
|
const PluginEventSchema = z.object({
|
|
5
4
|
type: z.string().min(1),
|
|
6
5
|
properties: z.record(z.unknown()).optional(),
|
|
7
6
|
});
|
|
7
|
+
const VoiceModeStateSchema = z.object({
|
|
8
|
+
enabled: z.boolean(),
|
|
9
|
+
clientId: z.string().trim().min(1),
|
|
10
|
+
connectionId: z.string().trim().min(1),
|
|
11
|
+
});
|
|
8
12
|
export function registerPluginRoutes(app, deps) {
|
|
9
|
-
const channel = new PluginChannelManager(deps.logger.child({ component: "plugin-channel" }));
|
|
10
13
|
app.get("/workspaces/:id/plugin/events", (request, reply) => {
|
|
11
14
|
const workspace = deps.workspaceManager.get(request.params.id);
|
|
12
15
|
if (!workspace) {
|
|
@@ -18,9 +21,10 @@ export function registerPluginRoutes(app, deps) {
|
|
|
18
21
|
reply.raw.setHeader("Connection", "keep-alive");
|
|
19
22
|
reply.raw.flushHeaders?.();
|
|
20
23
|
reply.hijack();
|
|
21
|
-
const registration = channel.register(request.params.id, reply);
|
|
24
|
+
const registration = deps.channel.register(request.params.id, reply);
|
|
25
|
+
deps.voiceModeManager.syncInstance(request.params.id);
|
|
22
26
|
const heartbeat = setInterval(() => {
|
|
23
|
-
channel.send(request.params.id, buildPingEvent());
|
|
27
|
+
deps.channel.send(request.params.id, buildPingEvent());
|
|
24
28
|
}, 15000);
|
|
25
29
|
const close = () => {
|
|
26
30
|
clearInterval(heartbeat);
|
|
@@ -30,6 +34,20 @@ export function registerPluginRoutes(app, deps) {
|
|
|
30
34
|
request.raw.on("close", close);
|
|
31
35
|
request.raw.on("error", close);
|
|
32
36
|
});
|
|
37
|
+
app.post("/workspaces/:id/plugin/voice-mode", (request, reply) => {
|
|
38
|
+
const workspace = deps.workspaceManager.get(request.params.id);
|
|
39
|
+
if (!workspace) {
|
|
40
|
+
reply.code(404).send({ error: "Workspace not found" });
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const payload = VoiceModeStateSchema.parse(request.body ?? {});
|
|
44
|
+
const applied = deps.voiceModeManager.setEnabled(request.params.id, { clientId: payload.clientId, connectionId: payload.connectionId }, payload.enabled);
|
|
45
|
+
if (payload.enabled && !applied) {
|
|
46
|
+
reply.code(409).send({ error: "Client connection not active for voice mode enable" });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
return { enabled: payload.enabled };
|
|
50
|
+
});
|
|
33
51
|
const handleWildcard = async (request, reply) => {
|
|
34
52
|
const workspaceId = request.params.id;
|
|
35
53
|
const workspace = deps.workspaceManager.get(workspaceId);
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Agent, fetch } from "undici";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const ProbeSchema = z.object({
|
|
4
|
+
baseUrl: z.string().min(1),
|
|
5
|
+
skipTlsVerify: z.boolean().optional(),
|
|
6
|
+
});
|
|
7
|
+
const PROBE_TIMEOUT_MS = 8000;
|
|
8
|
+
export function registerRemoteServerRoutes(app, deps) {
|
|
9
|
+
app.post("/api/remote-servers/probe", async (request, reply) => {
|
|
10
|
+
try {
|
|
11
|
+
const body = ProbeSchema.parse(request.body ?? {});
|
|
12
|
+
return await probeRemoteServer(body.baseUrl, Boolean(body.skipTlsVerify));
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
deps.logger.warn({ err: error }, "Failed to probe remote server");
|
|
16
|
+
reply.code(400);
|
|
17
|
+
return { error: error instanceof Error ? error.message : "Invalid request" };
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async function probeRemoteServer(baseUrl, skipTlsVerify) {
|
|
22
|
+
const normalizedUrl = normalizeBaseUrl(baseUrl);
|
|
23
|
+
const probeUrl = new URL("./api/auth/status", `${normalizedUrl}/`);
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
const timeout = setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS);
|
|
26
|
+
const dispatcher = skipTlsVerify ? new Agent({ connect: { rejectUnauthorized: false } }) : undefined;
|
|
27
|
+
try {
|
|
28
|
+
const response = await fetch(probeUrl, {
|
|
29
|
+
method: "GET",
|
|
30
|
+
dispatcher,
|
|
31
|
+
signal: controller.signal,
|
|
32
|
+
headers: {
|
|
33
|
+
Accept: "application/json",
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
return {
|
|
38
|
+
ok: false,
|
|
39
|
+
reachable: true,
|
|
40
|
+
normalizedUrl,
|
|
41
|
+
skipTlsVerify,
|
|
42
|
+
requiresAuth: false,
|
|
43
|
+
authenticated: false,
|
|
44
|
+
error: `Remote server returned HTTP ${response.status}`,
|
|
45
|
+
errorCode: "http_error",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const payload = (await response.json());
|
|
49
|
+
if (typeof payload?.authenticated !== "boolean") {
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
reachable: true,
|
|
53
|
+
normalizedUrl,
|
|
54
|
+
skipTlsVerify,
|
|
55
|
+
requiresAuth: false,
|
|
56
|
+
authenticated: false,
|
|
57
|
+
error: "Remote server did not return a valid CodeNomad auth response",
|
|
58
|
+
errorCode: "invalid_server",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
ok: true,
|
|
63
|
+
reachable: true,
|
|
64
|
+
normalizedUrl,
|
|
65
|
+
skipTlsVerify,
|
|
66
|
+
requiresAuth: !payload.authenticated,
|
|
67
|
+
authenticated: payload.authenticated,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const message = describeProbeError(error);
|
|
72
|
+
return {
|
|
73
|
+
ok: false,
|
|
74
|
+
reachable: false,
|
|
75
|
+
normalizedUrl,
|
|
76
|
+
skipTlsVerify,
|
|
77
|
+
requiresAuth: false,
|
|
78
|
+
authenticated: false,
|
|
79
|
+
error: message.message,
|
|
80
|
+
errorCode: message.code,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
clearTimeout(timeout);
|
|
85
|
+
await dispatcher?.close().catch(() => { });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function normalizeBaseUrl(input) {
|
|
89
|
+
const parsed = new URL(input.trim());
|
|
90
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
91
|
+
throw new Error("Server URL must use http:// or https://");
|
|
92
|
+
}
|
|
93
|
+
parsed.hash = "";
|
|
94
|
+
parsed.search = "";
|
|
95
|
+
parsed.pathname = parsed.pathname === "/" ? "/" : parsed.pathname.replace(/\/+$/, "") || "/";
|
|
96
|
+
const value = parsed.toString();
|
|
97
|
+
return parsed.pathname === "/" ? value.replace(/\/$/, "") : value.replace(/\/$/, "");
|
|
98
|
+
}
|
|
99
|
+
function describeProbeError(error) {
|
|
100
|
+
const chain = unwrapErrorChain(error);
|
|
101
|
+
const detailed = chain.find((entry) => {
|
|
102
|
+
const code = (entry?.code ?? "").toString();
|
|
103
|
+
return Boolean(code) && code !== "UND_ERR_RESPONSE_STATUS_CODE";
|
|
104
|
+
}) ?? chain[0];
|
|
105
|
+
const code = (detailed?.code ?? "").toString();
|
|
106
|
+
const exactMessage = detailed?.message?.trim() || chain.find((entry) => entry.message?.trim())?.message?.trim();
|
|
107
|
+
if (code === "DEPTH_ZERO_SELF_SIGNED_CERT" || code === "SELF_SIGNED_CERT_IN_CHAIN" || code === "CERT_HAS_EXPIRED") {
|
|
108
|
+
return {
|
|
109
|
+
code: "tls_error",
|
|
110
|
+
message: "Certificate check failed while connecting to the remote server.",
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
code: code === "ERR_INVALID_URL"
|
|
115
|
+
? "invalid_url"
|
|
116
|
+
: code === "ECONNREFUSED"
|
|
117
|
+
? "connection_refused"
|
|
118
|
+
: code === "ENOTFOUND"
|
|
119
|
+
? "dns_error"
|
|
120
|
+
: code === "UND_ERR_CONNECT_TIMEOUT" || code === "ABORT_ERR"
|
|
121
|
+
? "timeout"
|
|
122
|
+
: code
|
|
123
|
+
? code.toLowerCase()
|
|
124
|
+
: "probe_failed",
|
|
125
|
+
message: exactMessage || "Failed to connect to the remote server.",
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function unwrapErrorChain(error) {
|
|
129
|
+
const results = [];
|
|
130
|
+
let current = error;
|
|
131
|
+
const seen = new Set();
|
|
132
|
+
while (current && typeof current === "object" && !seen.has(current)) {
|
|
133
|
+
seen.add(current);
|
|
134
|
+
const entry = current;
|
|
135
|
+
results.push({ code: entry.code, message: entry.message });
|
|
136
|
+
current = entry.cause;
|
|
137
|
+
}
|
|
138
|
+
if (results.length === 0 && error instanceof Error) {
|
|
139
|
+
results.push({ message: error.message });
|
|
140
|
+
}
|
|
141
|
+
return results;
|
|
142
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const SideCarCreateSchema = z.object({
|
|
3
|
+
kind: z.literal("port").default("port"),
|
|
4
|
+
name: z.string().trim().min(1),
|
|
5
|
+
port: z.number().int().min(1).max(65535),
|
|
6
|
+
insecure: z.boolean().default(false),
|
|
7
|
+
prefixMode: z.enum(["strip", "preserve"]).default("strip"),
|
|
8
|
+
});
|
|
9
|
+
const SideCarUpdateSchema = SideCarCreateSchema.omit({ kind: true }).partial().refine((value) => Object.keys(value).length > 0, {
|
|
10
|
+
message: "At least one field is required",
|
|
11
|
+
});
|
|
12
|
+
export function registerSideCarRoutes(app, deps) {
|
|
13
|
+
app.get("/api/sidecars", async () => {
|
|
14
|
+
return { sidecars: await deps.sidecarManager.list() };
|
|
15
|
+
});
|
|
16
|
+
app.post("/api/sidecars", async (request, reply) => {
|
|
17
|
+
try {
|
|
18
|
+
const body = SideCarCreateSchema.parse(request.body ?? {});
|
|
19
|
+
const sidecar = await deps.sidecarManager.create(body);
|
|
20
|
+
reply.code(201);
|
|
21
|
+
return sidecar;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
reply.code(400);
|
|
25
|
+
return { error: error instanceof Error ? error.message : "Failed to create SideCar" };
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
app.put("/api/sidecars/:id", async (request, reply) => {
|
|
29
|
+
try {
|
|
30
|
+
const body = SideCarUpdateSchema.parse(request.body ?? {});
|
|
31
|
+
return await deps.sidecarManager.update(request.params.id, body);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
reply.code(400);
|
|
35
|
+
return { error: error instanceof Error ? error.message : "Failed to update SideCar" };
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
app.delete("/api/sidecars/:id", async (request, reply) => {
|
|
39
|
+
const removed = await deps.sidecarManager.delete(request.params.id);
|
|
40
|
+
if (!removed) {
|
|
41
|
+
reply.code(404);
|
|
42
|
+
return { error: "SideCar not found" };
|
|
43
|
+
}
|
|
44
|
+
reply.code(204);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -9,6 +9,9 @@ const WorkspaceFilesQuerySchema = z.object({
|
|
|
9
9
|
const WorkspaceFileContentQuerySchema = z.object({
|
|
10
10
|
path: z.string(),
|
|
11
11
|
});
|
|
12
|
+
const WorkspaceFileContentBodySchema = z.object({
|
|
13
|
+
contents: z.string(),
|
|
14
|
+
});
|
|
12
15
|
const WorkspaceFileSearchQuerySchema = z.object({
|
|
13
16
|
q: z.string().trim().min(1, "Query is required"),
|
|
14
17
|
limit: z.coerce.number().int().positive().max(200).optional(),
|
|
@@ -78,6 +81,17 @@ export function registerWorkspaceRoutes(app, deps) {
|
|
|
78
81
|
return handleWorkspaceError(error, reply);
|
|
79
82
|
}
|
|
80
83
|
});
|
|
84
|
+
app.put("/api/workspaces/:id/files/content", async (request, reply) => {
|
|
85
|
+
try {
|
|
86
|
+
const query = WorkspaceFileContentQuerySchema.parse(request.query ?? {});
|
|
87
|
+
const body = WorkspaceFileContentBodySchema.parse(request.body ?? {});
|
|
88
|
+
deps.workspaceManager.writeFile(request.params.id, query.path, body.contents);
|
|
89
|
+
reply.code(204);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
return handleWorkspaceError(error, reply);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
81
95
|
}
|
|
82
96
|
function handleWorkspaceError(error, reply) {
|
|
83
97
|
if (error instanceof Error && error.message === "Workspace not found") {
|
package/dist/settings/migrate.js
CHANGED
|
@@ -93,6 +93,10 @@ function mapLegacyToOwnerDocs(legacyConfig, legacyState) {
|
|
|
93
93
|
if (typeof listeningMode === "string") {
|
|
94
94
|
serverConfig.listeningMode = listeningMode;
|
|
95
95
|
}
|
|
96
|
+
const logLevel = preferences.logLevel;
|
|
97
|
+
if (typeof logLevel === "string") {
|
|
98
|
+
serverConfig.logLevel = logLevel;
|
|
99
|
+
}
|
|
96
100
|
const lastUsedBinary = preferences.lastUsedBinary;
|
|
97
101
|
if (typeof lastUsedBinary === "string") {
|
|
98
102
|
serverConfig.opencodeBinary = lastUsedBinary;
|
|
@@ -118,6 +122,7 @@ function mapLegacyToOwnerDocs(legacyConfig, legacyState) {
|
|
|
118
122
|
const moved = new Set([
|
|
119
123
|
"environmentVariables",
|
|
120
124
|
"listeningMode",
|
|
125
|
+
"logLevel",
|
|
121
126
|
"lastUsedBinary",
|
|
122
127
|
"modelRecents",
|
|
123
128
|
"modelFavorites",
|
package/dist/settings/service.js
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { YamlDocStore } from "./yaml-doc-store";
|
|
2
3
|
import { migrateSettingsLayout } from "./migrate";
|
|
3
4
|
import { sanitizeConfigOwner } from "./public-config";
|
|
5
|
+
const CanonicalLogLevelSchema = z.preprocess((value) => (typeof value === "string" ? value.trim().toUpperCase() : value), z.enum(["DEBUG", "INFO", "WARN", "ERROR"]));
|
|
6
|
+
function isPlainObject(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
function isDeepEqual(a, b) {
|
|
10
|
+
if (a === b)
|
|
11
|
+
return true;
|
|
12
|
+
try {
|
|
13
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function normalizeServerConfigOwner(value) {
|
|
20
|
+
if (!isPlainObject(value)) {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
const next = { ...value };
|
|
24
|
+
const parsedLogLevel = CanonicalLogLevelSchema.safeParse(next.logLevel);
|
|
25
|
+
if (parsedLogLevel.success) {
|
|
26
|
+
next.logLevel = parsedLogLevel.data;
|
|
27
|
+
}
|
|
28
|
+
else if (next.logLevel !== undefined) {
|
|
29
|
+
next.logLevel = "DEBUG";
|
|
30
|
+
}
|
|
31
|
+
return next;
|
|
32
|
+
}
|
|
33
|
+
function normalizeConfigDoc(doc) {
|
|
34
|
+
if (!isPlainObject(doc)) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
if (!isPlainObject(doc.server)) {
|
|
38
|
+
return doc;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
...doc,
|
|
42
|
+
server: normalizeServerConfigOwner(doc.server),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
4
45
|
export class SettingsService {
|
|
5
46
|
constructor(location, eventBus, logger) {
|
|
6
47
|
this.location = location;
|
|
@@ -11,18 +52,37 @@ export class SettingsService {
|
|
|
11
52
|
this.stateStore = new YamlDocStore(location.stateYamlPath, logger.child({ component: "settings-state" }));
|
|
12
53
|
}
|
|
13
54
|
getDoc(kind) {
|
|
14
|
-
|
|
55
|
+
if (kind !== "config") {
|
|
56
|
+
return this.stateStore.get();
|
|
57
|
+
}
|
|
58
|
+
const current = this.configStore.get();
|
|
59
|
+
const normalized = normalizeConfigDoc(current);
|
|
60
|
+
if (!isDeepEqual(current, normalized)) {
|
|
61
|
+
this.configStore.replace(normalized);
|
|
62
|
+
}
|
|
63
|
+
return normalized;
|
|
15
64
|
}
|
|
16
65
|
mergePatchDoc(kind, patch) {
|
|
17
|
-
const updated = kind === "config"
|
|
66
|
+
const updated = kind === "config"
|
|
67
|
+
? this.configStore.replace(normalizeConfigDoc(this.configStore.mergePatch(patch)))
|
|
68
|
+
: this.stateStore.mergePatch(patch);
|
|
18
69
|
this.publish(kind, "*");
|
|
19
70
|
return updated;
|
|
20
71
|
}
|
|
21
72
|
getOwner(kind, owner) {
|
|
22
|
-
|
|
73
|
+
if (kind !== "config") {
|
|
74
|
+
return this.stateStore.getOwner(owner);
|
|
75
|
+
}
|
|
76
|
+
return owner === "server"
|
|
77
|
+
? normalizeServerConfigOwner(this.getDoc("config").server)
|
|
78
|
+
: this.getDoc("config")[owner];
|
|
23
79
|
}
|
|
24
80
|
mergePatchOwner(kind, owner, patch) {
|
|
25
|
-
const updated = kind === "config"
|
|
81
|
+
const updated = kind === "config"
|
|
82
|
+
? owner === "server"
|
|
83
|
+
? this.configStore.replaceOwner(owner, normalizeServerConfigOwner(this.configStore.mergePatchOwner(owner, patch)))
|
|
84
|
+
: this.configStore.mergePatchOwner(owner, patch)
|
|
85
|
+
: this.stateStore.mergePatchOwner(owner, patch);
|
|
26
86
|
this.publish(kind, owner, updated);
|
|
27
87
|
return updated;
|
|
28
88
|
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { connect } from "net";
|
|
2
|
+
export class SideCarManager {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
this.options = options;
|
|
5
|
+
this.configs = new Map();
|
|
6
|
+
this.runtime = new Map();
|
|
7
|
+
for (const record of this.loadConfiguredSideCars()) {
|
|
8
|
+
this.configs.set(record.id, record);
|
|
9
|
+
this.runtime.set(record.id, { status: "stopped" });
|
|
10
|
+
}
|
|
11
|
+
queueMicrotask(() => {
|
|
12
|
+
for (const record of this.configs.values()) {
|
|
13
|
+
void this.refreshPortSideCar(record.id).catch((error) => {
|
|
14
|
+
this.options.logger.warn({ sidecarId: record.id, err: error }, "Failed to probe sidecar port");
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async list() {
|
|
20
|
+
await this.refreshPortStatuses();
|
|
21
|
+
return Array.from(this.configs.values()).map((record) => this.toSideCar(record));
|
|
22
|
+
}
|
|
23
|
+
async get(id) {
|
|
24
|
+
if (!this.configs.has(id))
|
|
25
|
+
return undefined;
|
|
26
|
+
await this.refreshPortSideCar(id);
|
|
27
|
+
return this.toSideCar(this.requireConfig(id));
|
|
28
|
+
}
|
|
29
|
+
async create(input) {
|
|
30
|
+
const normalizedName = input.name.trim();
|
|
31
|
+
const id = this.buildSideCarId(normalizedName);
|
|
32
|
+
if (this.configs.has(id)) {
|
|
33
|
+
throw new Error(`SideCar '${id}' already exists`);
|
|
34
|
+
}
|
|
35
|
+
const now = new Date().toISOString();
|
|
36
|
+
const record = {
|
|
37
|
+
id,
|
|
38
|
+
kind: input.kind,
|
|
39
|
+
name: normalizedName,
|
|
40
|
+
port: input.port,
|
|
41
|
+
insecure: input.insecure,
|
|
42
|
+
prefixMode: input.prefixMode,
|
|
43
|
+
createdAt: now,
|
|
44
|
+
updatedAt: now,
|
|
45
|
+
};
|
|
46
|
+
this.configs.set(record.id, record);
|
|
47
|
+
this.runtime.set(record.id, { status: "stopped" });
|
|
48
|
+
this.persistConfigs();
|
|
49
|
+
await this.refreshPortSideCar(record.id);
|
|
50
|
+
return this.toSideCar(record);
|
|
51
|
+
}
|
|
52
|
+
async update(id, input) {
|
|
53
|
+
const record = this.requireConfig(id);
|
|
54
|
+
record.name = typeof input.name === "string" ? input.name.trim() : record.name;
|
|
55
|
+
record.port = typeof input.port === "number" ? input.port : record.port;
|
|
56
|
+
record.insecure = typeof input.insecure === "boolean" ? input.insecure : record.insecure;
|
|
57
|
+
record.prefixMode = typeof input.prefixMode === "string" ? input.prefixMode : record.prefixMode;
|
|
58
|
+
record.updatedAt = new Date().toISOString();
|
|
59
|
+
this.persistConfigs();
|
|
60
|
+
await this.refreshPortSideCar(id);
|
|
61
|
+
return this.toSideCar(record);
|
|
62
|
+
}
|
|
63
|
+
async delete(id) {
|
|
64
|
+
const record = this.configs.get(id);
|
|
65
|
+
if (!record)
|
|
66
|
+
return false;
|
|
67
|
+
this.configs.delete(id);
|
|
68
|
+
this.runtime.delete(id);
|
|
69
|
+
this.persistConfigs();
|
|
70
|
+
this.options.eventBus.publish({ type: "sidecar.removed", sidecarId: id });
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
async shutdown() {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
buildTargetOrigin(sidecar) {
|
|
77
|
+
const protocol = sidecar.insecure ? "http" : "https";
|
|
78
|
+
return `${protocol}://127.0.0.1:${sidecar.port}`;
|
|
79
|
+
}
|
|
80
|
+
buildProxyBasePath(id) {
|
|
81
|
+
return `/sidecars/${encodeURIComponent(id)}`;
|
|
82
|
+
}
|
|
83
|
+
buildTargetPath(id, incomingPath, search = "") {
|
|
84
|
+
const record = this.requireConfig(id);
|
|
85
|
+
const publicBase = this.buildProxyBasePath(id);
|
|
86
|
+
const normalizedPath = incomingPath || publicBase;
|
|
87
|
+
if (record.prefixMode === "preserve") {
|
|
88
|
+
return `${normalizedPath}${search}`;
|
|
89
|
+
}
|
|
90
|
+
let stripped = normalizedPath.startsWith(publicBase) ? normalizedPath.slice(publicBase.length) : normalizedPath;
|
|
91
|
+
if (!stripped || stripped === "/") {
|
|
92
|
+
stripped = "/";
|
|
93
|
+
}
|
|
94
|
+
else if (!stripped.startsWith("/")) {
|
|
95
|
+
stripped = `/${stripped}`;
|
|
96
|
+
}
|
|
97
|
+
return `${stripped}${search}`;
|
|
98
|
+
}
|
|
99
|
+
async refreshPortStatuses() {
|
|
100
|
+
await Promise.all(Array.from(this.configs.values()).map((record) => this.refreshPortSideCar(record.id)));
|
|
101
|
+
}
|
|
102
|
+
async refreshPortSideCar(id) {
|
|
103
|
+
const record = this.configs.get(id);
|
|
104
|
+
if (!record)
|
|
105
|
+
return;
|
|
106
|
+
const isAvailable = await this.isPortAvailable(record.port);
|
|
107
|
+
const current = this.runtime.get(id);
|
|
108
|
+
const nextStatus = isAvailable ? "running" : "stopped";
|
|
109
|
+
if (current?.status === nextStatus) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.runtime.set(id, { status: nextStatus });
|
|
113
|
+
record.updatedAt = new Date().toISOString();
|
|
114
|
+
this.publish(id);
|
|
115
|
+
}
|
|
116
|
+
publish(id) {
|
|
117
|
+
const record = this.configs.get(id);
|
|
118
|
+
if (!record)
|
|
119
|
+
return;
|
|
120
|
+
this.options.eventBus.publish({ type: "sidecar.updated", sidecar: this.toSideCar(record) });
|
|
121
|
+
}
|
|
122
|
+
toSideCar(record) {
|
|
123
|
+
const runtime = this.runtime.get(record.id);
|
|
124
|
+
return {
|
|
125
|
+
id: record.id,
|
|
126
|
+
kind: record.kind,
|
|
127
|
+
name: record.name,
|
|
128
|
+
port: record.port,
|
|
129
|
+
insecure: record.insecure,
|
|
130
|
+
prefixMode: record.prefixMode,
|
|
131
|
+
status: runtime?.status ?? "stopped",
|
|
132
|
+
createdAt: record.createdAt,
|
|
133
|
+
updatedAt: record.updatedAt,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
requireConfig(id) {
|
|
137
|
+
const record = this.configs.get(id);
|
|
138
|
+
if (!record) {
|
|
139
|
+
throw new Error("SideCar not found");
|
|
140
|
+
}
|
|
141
|
+
return record;
|
|
142
|
+
}
|
|
143
|
+
persistConfigs() {
|
|
144
|
+
const sidecars = Array.from(this.configs.values()).map((record) => ({ ...record }));
|
|
145
|
+
this.options.settings.mergePatchOwner("config", "server", { sidecars });
|
|
146
|
+
}
|
|
147
|
+
loadConfiguredSideCars() {
|
|
148
|
+
const serverConfig = this.options.settings.getOwner("config", "server");
|
|
149
|
+
const list = Array.isArray(serverConfig?.sidecars) ? serverConfig.sidecars : [];
|
|
150
|
+
const records = [];
|
|
151
|
+
for (const item of list) {
|
|
152
|
+
if (!item || typeof item !== "object")
|
|
153
|
+
continue;
|
|
154
|
+
const record = item;
|
|
155
|
+
const kind = record.kind === "port" ? "port" : null;
|
|
156
|
+
const id = typeof record.id === "string" && record.id.trim() ? record.id.trim() : null;
|
|
157
|
+
const name = typeof record.name === "string" && record.name.trim() ? record.name.trim() : null;
|
|
158
|
+
const port = typeof record.port === "number" && Number.isInteger(record.port) ? record.port : null;
|
|
159
|
+
if (!kind || !id || !name || !port)
|
|
160
|
+
continue;
|
|
161
|
+
const insecure = record.insecure === true;
|
|
162
|
+
const prefixMode = record.prefixMode === "preserve" ? "preserve" : "strip";
|
|
163
|
+
const createdAt = typeof record.createdAt === "string" && record.createdAt ? record.createdAt : new Date().toISOString();
|
|
164
|
+
const updatedAt = typeof record.updatedAt === "string" && record.updatedAt ? record.updatedAt : createdAt;
|
|
165
|
+
records.push({ id, kind, name, port, insecure, prefixMode, createdAt, updatedAt });
|
|
166
|
+
}
|
|
167
|
+
return records;
|
|
168
|
+
}
|
|
169
|
+
isPortAvailable(port) {
|
|
170
|
+
return new Promise((resolve) => {
|
|
171
|
+
const socket = connect({ port, host: "127.0.0.1" }, () => {
|
|
172
|
+
socket.end();
|
|
173
|
+
resolve(true);
|
|
174
|
+
});
|
|
175
|
+
socket.once("error", () => {
|
|
176
|
+
socket.destroy();
|
|
177
|
+
resolve(false);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
buildSideCarId(name) {
|
|
182
|
+
const normalized = name
|
|
183
|
+
.trim()
|
|
184
|
+
.toLowerCase()
|
|
185
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
186
|
+
.replace(/-{2,}/g, "-")
|
|
187
|
+
.replace(/^-|-$/g, "");
|
|
188
|
+
if (!normalized) {
|
|
189
|
+
throw new Error("SideCar name must include letters or numbers");
|
|
190
|
+
}
|
|
191
|
+
return normalized;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -110,19 +110,40 @@ export class OpenAICompatibleSpeechProvider {
|
|
|
110
110
|
throw new Error("Speech provider is not configured. Add an API key in Speech settings.");
|
|
111
111
|
}
|
|
112
112
|
const endpoint = new URL("audio/speech", ensureTrailingSlash(settings.baseUrl ?? "https://api.openai.com/v1"));
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
113
|
+
let response;
|
|
114
|
+
try {
|
|
115
|
+
response = await fetch(endpoint, {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers: {
|
|
118
|
+
Authorization: `Bearer ${settings.apiKey}`,
|
|
119
|
+
"Content-Type": "application/json",
|
|
120
|
+
},
|
|
121
|
+
body: JSON.stringify({
|
|
122
|
+
model: settings.ttsModel,
|
|
123
|
+
voice: settings.ttsVoice,
|
|
124
|
+
input: text,
|
|
125
|
+
response_format: format,
|
|
126
|
+
}),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
const detailedError = error;
|
|
131
|
+
this.options.logger.error({
|
|
132
|
+
err: error,
|
|
133
|
+
endpoint: endpoint.toString(),
|
|
134
|
+
baseUrl: settings.baseUrl,
|
|
120
135
|
model: settings.ttsModel,
|
|
121
136
|
voice: settings.ttsVoice,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
137
|
+
format,
|
|
138
|
+
cause: detailedError.cause,
|
|
139
|
+
code: detailedError.code,
|
|
140
|
+
errno: detailedError.errno,
|
|
141
|
+
syscall: detailedError.syscall,
|
|
142
|
+
address: detailedError.address,
|
|
143
|
+
port: detailedError.port,
|
|
144
|
+
}, "speech.synthesize fetch failed");
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
126
147
|
if (!response.ok) {
|
|
127
148
|
const detail = await response.text();
|
|
128
149
|
throw new Error(detail || `Speech synthesis failed with ${response.status}`);
|
|
@@ -43,4 +43,25 @@ describe("resolveUi local version preference", () => {
|
|
|
43
43
|
assert.equal(result.uiStaticDir, bundledDir);
|
|
44
44
|
assert.equal(result.uiVersion, "0.8.1");
|
|
45
45
|
});
|
|
46
|
+
it("prefers bundled when bundled and downloaded versions are equal", async () => {
|
|
47
|
+
const bundledDir = path.join(tempRoot, "bundled");
|
|
48
|
+
const configDir = path.join(tempRoot, "config");
|
|
49
|
+
const currentDir = path.join(configDir, "ui", "current");
|
|
50
|
+
await mkdir(bundledDir, { recursive: true });
|
|
51
|
+
await mkdir(currentDir, { recursive: true });
|
|
52
|
+
writeFileSync(path.join(bundledDir, "index.html"), "<html>bundled</html>");
|
|
53
|
+
writeFileSync(path.join(bundledDir, "ui-version.json"), JSON.stringify({ uiVersion: "0.8.1" }));
|
|
54
|
+
writeFileSync(path.join(currentDir, "index.html"), "<html>current</html>");
|
|
55
|
+
writeFileSync(path.join(currentDir, "ui-version.json"), JSON.stringify({ uiVersion: "0.8.1" }));
|
|
56
|
+
const result = await resolveUi({
|
|
57
|
+
serverVersion: "0.8.1",
|
|
58
|
+
bundledUiDir: bundledDir,
|
|
59
|
+
autoUpdate: false,
|
|
60
|
+
configDir,
|
|
61
|
+
logger: noopLogger,
|
|
62
|
+
});
|
|
63
|
+
assert.equal(result.source, "bundled");
|
|
64
|
+
assert.equal(result.uiStaticDir, bundledDir);
|
|
65
|
+
assert.equal(result.uiVersion, "0.8.1");
|
|
66
|
+
});
|
|
46
67
|
});
|
package/dist/ui/remote-ui.js
CHANGED
|
@@ -179,7 +179,7 @@ async function pickBestLocalUi(args) {
|
|
|
179
179
|
uiStaticDir: currentResolved,
|
|
180
180
|
source: "downloaded",
|
|
181
181
|
uiVersion: await readUiVersion(currentResolved),
|
|
182
|
-
priority:
|
|
182
|
+
priority: 1,
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
185
|
const bundledResolved = await resolveStaticUiDir(args.bundledUiDir);
|
|
@@ -188,7 +188,7 @@ async function pickBestLocalUi(args) {
|
|
|
188
188
|
uiStaticDir: bundledResolved,
|
|
189
189
|
source: "bundled",
|
|
190
190
|
uiVersion: await readUiVersion(bundledResolved),
|
|
191
|
-
priority:
|
|
191
|
+
priority: 2,
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
194
|
const previousResolved = await resolveStaticUiDir(args.previousDir);
|