@neuralnomads/codenomad 0.17.0 → 0.19.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/README.md +12 -0
- package/THIRD_PARTY_NOTICES.md +26 -0
- package/dist/auth/manager.js +1 -1
- package/dist/background-processes/manager.js +15 -30
- package/dist/background-processes/manager.test.js +123 -0
- package/dist/config/schema.js +2 -1
- package/dist/config/schema.test.js +13 -0
- package/dist/events/bus.js +17 -0
- package/dist/events/bus.test.js +37 -0
- package/dist/filesystem/__tests__/search-cache.test.js +20 -8
- package/dist/filesystem/__tests__/search.test.js +53 -0
- package/dist/filesystem/search-cache.js +6 -10
- package/dist/filesystem/search.js +22 -9
- package/dist/index.js +77 -58
- package/dist/index.test.js +62 -0
- package/dist/opencode-plugin/codenomad-opencode-plugin.tgz +0 -0
- package/dist/opencode-update/service.js +150 -0
- package/dist/opencode-update/service.test.js +107 -0
- package/dist/permissions/auto-accept-manager.js +380 -0
- package/dist/permissions/auto-accept-manager.test.js +736 -0
- package/dist/permissions/auto-accept-store.js +118 -0
- package/dist/permissions/auto-accept-store.test.js +157 -0
- package/dist/permissions/opencode-replier.js +31 -0
- package/dist/permissions/opencode-yolo-metadata.js +81 -0
- package/dist/permissions/opencode-yolo-metadata.test.js +54 -0
- package/dist/server/__tests__/listener-retry.test.js +15 -0
- package/dist/server/__tests__/remote-proxy.test.js +151 -47
- package/dist/server/http-server.js +22 -9
- package/dist/server/remote-proxy.js +91 -34
- package/dist/server/routes/auth-pages/login.html +3 -3
- package/dist/server/routes/auth.js +1 -1
- package/dist/server/routes/auth.test.js +21 -0
- package/dist/server/routes/opencode-update.js +37 -0
- package/dist/server/routes/opencode-update.test.js +34 -0
- package/dist/server/routes/remote-servers.js +1 -1
- package/dist/server/routes/settings.js +48 -2
- package/dist/server/routes/settings.test.js +58 -0
- package/dist/server/routes/usage.js +18 -0
- package/dist/server/routes/usage.test.js +26 -0
- package/dist/server/routes/workspaces.js +34 -2
- package/dist/server/routes/workspaces.test.js +113 -0
- package/dist/server/routes/worktrees.js +19 -0
- package/dist/server/routes/yolo.js +13 -0
- package/dist/server/tls.js +2 -2
- package/dist/settings/binaries.js +4 -1
- package/dist/settings/binaries.test.js +19 -0
- package/dist/settings/public-config.js +14 -0
- package/dist/settings/public-config.test.js +56 -0
- package/dist/settings/service.js +17 -5
- package/dist/settings/service.test.js +51 -0
- package/dist/settings/yaml-doc-store.js +55 -4
- package/dist/settings/yaml-doc-store.test.js +78 -0
- package/dist/shutdown.js +83 -0
- package/dist/shutdown.test.js +148 -0
- package/dist/sidecars/manager.js +26 -3
- package/dist/sidecars/manager.test.js +42 -0
- package/dist/speech/service.js +121 -10
- package/dist/speech/service.test.js +247 -0
- package/dist/ui/remote-ui.js +2 -2
- package/dist/usage/providers/api-key.js +171 -0
- package/dist/usage/providers/google.js +171 -0
- package/dist/usage/providers/minimax.js +109 -0
- package/dist/usage/providers/oauth.js +76 -0
- package/dist/usage/providers/special.js +148 -0
- package/dist/usage/service.js +83 -0
- package/dist/usage/service.test.js +61 -0
- package/dist/usage/shared.js +130 -0
- package/dist/usage/shared.test.js +33 -0
- package/dist/usage/types.js +1 -0
- package/dist/workspaces/__tests__/spawn.test.js +64 -7
- package/dist/workspaces/__tests__/workspace-identity.test.js +163 -0
- package/dist/workspaces/binary-path.test.js +10 -0
- package/dist/workspaces/instance-client.js +42 -0
- package/dist/workspaces/instance-client.test.js +149 -0
- package/dist/workspaces/instance-events.js +2 -2
- package/dist/workspaces/launch-cleanup.test.js +29 -0
- package/dist/workspaces/loopback.js +8 -0
- package/dist/workspaces/manager.js +473 -128
- package/dist/workspaces/manager.test.js +335 -0
- package/dist/workspaces/process-identity.darwin.test.js +88 -0
- package/dist/workspaces/process-identity.js +449 -0
- package/dist/workspaces/process-identity.test.js +140 -0
- package/dist/workspaces/runtime.js +471 -138
- package/dist/workspaces/runtime.test.js +286 -0
- package/dist/workspaces/spawn.js +86 -15
- package/dist/workspaces/workspace-identity.js +27 -0
- package/package.json +2 -1
- package/public/assets/FilesTab-Cbs7b7y9.js +2 -0
- package/public/assets/{GitChangesTab-BksCi53d.js → GitChangesTab-D3H4cqJJ.js} +2 -2
- package/public/assets/{SplitFilePanel-CrSfR22r.js → SplitFilePanel-C_Bcle0r.js} +1 -1
- package/public/assets/StatusTab-D1-tfkgN.js +1 -0
- package/public/assets/{align-justify-hRtBz8xe.js → align-justify-B5HUL_LR.js} +1 -1
- package/public/assets/{bundle-full-BVDA-a9Y.js → bundle-full-CEFzES5w.js} +1 -1
- package/public/assets/{diff-viewer-BCAI0Cw8.js → diff-viewer-BBC2_yI1.js} +1 -1
- package/public/assets/{git-diff-vendor-CSgooKT_.js → git-diff-vendor-CYS3ApzA.js} +1 -1
- package/public/assets/{index-DnCBfFB3.js → index-B81f0aWL.js} +1 -1
- package/public/assets/index-BHlYVddm.js +1 -0
- package/public/assets/index-Best16ZB.js +2 -0
- package/public/assets/index-Boq37ErX.js +1 -0
- package/public/assets/index-By9pgzQk.css +1 -0
- package/public/assets/index-C0caoeJg.js +1 -0
- package/public/assets/index-Dqg2UVvS.js +1 -0
- package/public/assets/index-it6EGJV6.js +1 -0
- package/public/assets/{index-Ddsv8Uc0.js → index-lORR8OnW.js} +1 -1
- package/public/assets/index-ppe6yWaU.js +1 -0
- package/public/assets/index-wEqeBwqT.js +1 -0
- package/public/assets/index-yEcajWX_.js +1 -0
- package/public/assets/{loading-bD3ppK2l.js → loading-CbUWFqQ_.js} +1 -1
- package/public/assets/main-DfSREDgt.js +69 -0
- package/public/assets/{markdown-DJuaMC5H.js → markdown-CEtfpKK-.js} +60 -47
- package/public/assets/monaco-viewer-NKl8kwH2.js +26 -0
- package/public/assets/terminal-square-q-by1uT7.js +1 -0
- package/public/assets/tool-call-CZL2uqIM.js +59 -0
- package/public/assets/unified-picker-CvJXD-j8.js +1 -0
- package/public/assets/{wrap-text-BkcW_eTA.js → wrap-text-Bo7xr74P.js} +1 -1
- 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/FilesTab-B5ysoRLh.js +0 -2
- package/public/assets/StatusTab-Dgqekgjn.js +0 -1
- package/public/assets/index-B2Qd6xQq.css +0 -1
- package/public/assets/index-BQpEhdk5.js +0 -1
- package/public/assets/index-BXIEm2zT.js +0 -1
- package/public/assets/index-CWjU9mAF.js +0 -1
- package/public/assets/index-Cvtlo58a.js +0 -1
- package/public/assets/index-DFlxnvHT.js +0 -2
- package/public/assets/index-Dn7woJnK.js +0 -1
- package/public/assets/index-DnXT1F8T.js +0 -1
- package/public/assets/index-Kv-3BRTi.js +0 -1
- package/public/assets/index-g-G1RiME.js +0 -1
- package/public/assets/main-BsbMOeQg.js +0 -65
- package/public/assets/monaco-viewer-BFNhPQX7.js +0 -26
- package/public/assets/tool-call-BSJluZRW.js +0 -59
- package/public/assets/unified-picker-DmFyrIis.js +0 -1
package/dist/speech/service.js
CHANGED
|
@@ -10,6 +10,21 @@ const ServerSpeechSettingsSchema = z.object({
|
|
|
10
10
|
ttsModel: z.string().optional(),
|
|
11
11
|
ttsVoice: z.string().optional(),
|
|
12
12
|
ttsFormat: z.enum(["mp3", "wav", "opus", "aac"]).optional(),
|
|
13
|
+
separateProviders: z.boolean().optional(),
|
|
14
|
+
stt: z
|
|
15
|
+
.object({
|
|
16
|
+
apiKey: z.string().nullish(),
|
|
17
|
+
baseUrl: z.string().nullish(),
|
|
18
|
+
model: z.string().nullish(),
|
|
19
|
+
})
|
|
20
|
+
.optional(),
|
|
21
|
+
tts: z
|
|
22
|
+
.object({
|
|
23
|
+
apiKey: z.string().nullish(),
|
|
24
|
+
baseUrl: z.string().nullish(),
|
|
25
|
+
model: z.string().nullish(),
|
|
26
|
+
})
|
|
27
|
+
.optional(),
|
|
13
28
|
})
|
|
14
29
|
.optional(),
|
|
15
30
|
});
|
|
@@ -24,27 +39,65 @@ export class SpeechService {
|
|
|
24
39
|
this.logger = logger;
|
|
25
40
|
}
|
|
26
41
|
getCapabilities() {
|
|
27
|
-
|
|
42
|
+
const parsed = this.parseConfig();
|
|
43
|
+
const speech = parsed.speech ?? {};
|
|
44
|
+
const separate = speech.separateProviders === true;
|
|
45
|
+
const sttSettings = this.resolveSttSettingsFrom(speech);
|
|
46
|
+
const ttsSettings = this.resolveTtsSettingsFrom(speech);
|
|
47
|
+
const sttConfigured = Boolean(sttSettings.apiKey);
|
|
48
|
+
const ttsConfigured = Boolean(ttsSettings.apiKey);
|
|
49
|
+
return {
|
|
50
|
+
available: true,
|
|
51
|
+
configured: separate ? (sttConfigured && ttsConfigured) : (sttConfigured || ttsConfigured),
|
|
52
|
+
provider: sttSettings.provider,
|
|
53
|
+
supportsStt: true,
|
|
54
|
+
supportsTts: true,
|
|
55
|
+
supportsStreamingTts: true,
|
|
56
|
+
baseUrl: separate ? undefined : (speech.baseUrl?.trim() || process.env.OPENAI_BASE_URL || undefined),
|
|
57
|
+
sttModel: sttSettings.sttModel,
|
|
58
|
+
ttsModel: ttsSettings.ttsModel,
|
|
59
|
+
ttsVoice: ttsSettings.ttsVoice,
|
|
60
|
+
ttsFormats: ["mp3", "wav", "opus", "aac"],
|
|
61
|
+
streamingTtsFormats: ["mp3", "wav", "opus", "aac"],
|
|
62
|
+
separateProviders: separate,
|
|
63
|
+
sttConfigured,
|
|
64
|
+
ttsConfigured,
|
|
65
|
+
...(separate ? { sttBaseUrl: sttSettings.baseUrl, ttsBaseUrl: ttsSettings.baseUrl } : {}),
|
|
66
|
+
};
|
|
28
67
|
}
|
|
29
68
|
async transcribe(input) {
|
|
30
|
-
return this.
|
|
69
|
+
return this.createSttProvider().transcribe(input);
|
|
31
70
|
}
|
|
32
71
|
async synthesize(input) {
|
|
33
|
-
return this.
|
|
72
|
+
return this.createTtsProvider().synthesize(input);
|
|
34
73
|
}
|
|
35
74
|
async synthesizeStream(input) {
|
|
36
|
-
return this.
|
|
75
|
+
return this.createTtsProvider().synthesizeStream(input);
|
|
76
|
+
}
|
|
77
|
+
parseConfig() {
|
|
78
|
+
return ServerSpeechSettingsSchema.parse(this.settings.getOwner("config", "server") ?? {});
|
|
37
79
|
}
|
|
38
|
-
|
|
39
|
-
const settings = this.
|
|
80
|
+
createSttProvider() {
|
|
81
|
+
const settings = this.resolveSttSettings();
|
|
40
82
|
return new OpenAICompatibleSpeechProvider({
|
|
41
83
|
settings,
|
|
42
|
-
logger: this.logger.child({ provider: settings.provider }),
|
|
84
|
+
logger: this.logger.child({ provider: settings.provider, direction: "stt" }),
|
|
43
85
|
});
|
|
44
86
|
}
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
87
|
+
createTtsProvider() {
|
|
88
|
+
const settings = this.resolveTtsSettings();
|
|
89
|
+
return new OpenAICompatibleSpeechProvider({
|
|
90
|
+
settings,
|
|
91
|
+
logger: this.logger.child({ provider: settings.provider, direction: "tts" }),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
resolveSttSettings() {
|
|
95
|
+
return this.resolveSttSettingsFrom(this.parseConfig().speech ?? {});
|
|
96
|
+
}
|
|
97
|
+
resolveTtsSettings() {
|
|
98
|
+
return this.resolveTtsSettingsFrom(this.parseConfig().speech ?? {});
|
|
99
|
+
}
|
|
100
|
+
resolveShared(speech) {
|
|
48
101
|
return {
|
|
49
102
|
provider: speech.provider?.trim() || DEFAULT_PROVIDER,
|
|
50
103
|
apiKey: speech.apiKey?.trim() || process.env.OPENAI_API_KEY,
|
|
@@ -55,4 +108,62 @@ export class SpeechService {
|
|
|
55
108
|
ttsFormat: speech.ttsFormat ?? DEFAULT_TTS_FORMAT,
|
|
56
109
|
};
|
|
57
110
|
}
|
|
111
|
+
resolveSttSettingsFrom(speech) {
|
|
112
|
+
if (speech.separateProviders !== true) {
|
|
113
|
+
return this.resolveShared(speech);
|
|
114
|
+
}
|
|
115
|
+
const stt = speech.stt ?? {};
|
|
116
|
+
const sharedBaseUrl = speech.baseUrl?.trim() || undefined;
|
|
117
|
+
const rawDirBaseUrl = stt.baseUrl?.trim() || undefined;
|
|
118
|
+
const dirApiKey = stt.apiKey?.trim() || undefined;
|
|
119
|
+
const dirBaseUrl = dirApiKey
|
|
120
|
+
? rawDirBaseUrl
|
|
121
|
+
: (rawDirBaseUrl && rawDirBaseUrl !== sharedBaseUrl ? rawDirBaseUrl : undefined);
|
|
122
|
+
const hasCompleteDirectional = Boolean(dirApiKey) && Boolean(dirBaseUrl);
|
|
123
|
+
const hasNoDirectional = !dirApiKey && !dirBaseUrl;
|
|
124
|
+
return {
|
|
125
|
+
provider: speech.provider?.trim() || DEFAULT_PROVIDER,
|
|
126
|
+
apiKey: hasCompleteDirectional
|
|
127
|
+
? dirApiKey
|
|
128
|
+
: hasNoDirectional
|
|
129
|
+
? speech.apiKey?.trim() || process.env.OPENAI_API_KEY
|
|
130
|
+
: undefined,
|
|
131
|
+
baseUrl: hasCompleteDirectional || hasNoDirectional
|
|
132
|
+
? (dirBaseUrl || sharedBaseUrl || process.env.OPENAI_BASE_URL || undefined)
|
|
133
|
+
: dirBaseUrl || undefined,
|
|
134
|
+
sttModel: stt.model?.trim() || speech.sttModel?.trim() || DEFAULT_STT_MODEL,
|
|
135
|
+
ttsModel: speech.ttsModel?.trim() || DEFAULT_TTS_MODEL,
|
|
136
|
+
ttsVoice: speech.ttsVoice?.trim() || DEFAULT_TTS_VOICE,
|
|
137
|
+
ttsFormat: speech.ttsFormat ?? DEFAULT_TTS_FORMAT,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
resolveTtsSettingsFrom(speech) {
|
|
141
|
+
if (speech.separateProviders !== true) {
|
|
142
|
+
return this.resolveShared(speech);
|
|
143
|
+
}
|
|
144
|
+
const tts = speech.tts ?? {};
|
|
145
|
+
const sharedBaseUrl = speech.baseUrl?.trim() || undefined;
|
|
146
|
+
const rawDirBaseUrl = tts.baseUrl?.trim() || undefined;
|
|
147
|
+
const dirApiKey = tts.apiKey?.trim() || undefined;
|
|
148
|
+
const dirBaseUrl = dirApiKey
|
|
149
|
+
? rawDirBaseUrl
|
|
150
|
+
: (rawDirBaseUrl && rawDirBaseUrl !== sharedBaseUrl ? rawDirBaseUrl : undefined);
|
|
151
|
+
const hasCompleteDirectional = Boolean(dirApiKey) && Boolean(dirBaseUrl);
|
|
152
|
+
const hasNoDirectional = !dirApiKey && !dirBaseUrl;
|
|
153
|
+
return {
|
|
154
|
+
provider: speech.provider?.trim() || DEFAULT_PROVIDER,
|
|
155
|
+
apiKey: hasCompleteDirectional
|
|
156
|
+
? dirApiKey
|
|
157
|
+
: hasNoDirectional
|
|
158
|
+
? speech.apiKey?.trim() || process.env.OPENAI_API_KEY
|
|
159
|
+
: undefined,
|
|
160
|
+
baseUrl: hasCompleteDirectional || hasNoDirectional
|
|
161
|
+
? (dirBaseUrl || sharedBaseUrl || process.env.OPENAI_BASE_URL || undefined)
|
|
162
|
+
: dirBaseUrl || undefined,
|
|
163
|
+
sttModel: speech.sttModel?.trim() || DEFAULT_STT_MODEL,
|
|
164
|
+
ttsModel: tts.model?.trim() || speech.ttsModel?.trim() || DEFAULT_TTS_MODEL,
|
|
165
|
+
ttsVoice: speech.ttsVoice?.trim() || DEFAULT_TTS_VOICE,
|
|
166
|
+
ttsFormat: speech.ttsFormat ?? DEFAULT_TTS_FORMAT,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
58
169
|
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { SpeechService } from "./service";
|
|
4
|
+
function createMockSettings(serverConfig) {
|
|
5
|
+
return {
|
|
6
|
+
getOwner: () => serverConfig,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
const mockLogger = {
|
|
10
|
+
child: () => mockLogger,
|
|
11
|
+
info: () => { },
|
|
12
|
+
warn: () => { },
|
|
13
|
+
error: () => { },
|
|
14
|
+
debug: () => { },
|
|
15
|
+
};
|
|
16
|
+
describe("SpeechService direction resolution", () => {
|
|
17
|
+
describe("separateProviders = false (default)", () => {
|
|
18
|
+
it("uses shared apiKey for both STT and TTS", () => {
|
|
19
|
+
const settings = createMockSettings({
|
|
20
|
+
speech: {
|
|
21
|
+
apiKey: "sk-shared",
|
|
22
|
+
baseUrl: "https://api.openai.com/v1",
|
|
23
|
+
sttModel: "whisper-1",
|
|
24
|
+
ttsModel: "tts-1",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const service = new SpeechService(settings, mockLogger);
|
|
28
|
+
const caps = service.getCapabilities();
|
|
29
|
+
assert.equal(caps.separateProviders, false);
|
|
30
|
+
assert.equal(caps.sttConfigured, true);
|
|
31
|
+
assert.equal(caps.ttsConfigured, true);
|
|
32
|
+
assert.equal(caps.configured, true);
|
|
33
|
+
});
|
|
34
|
+
it("reports unconfigured when no apiKey is set", () => {
|
|
35
|
+
const settings = createMockSettings({
|
|
36
|
+
speech: { sttModel: "whisper-1", ttsModel: "tts-1" },
|
|
37
|
+
});
|
|
38
|
+
const service = new SpeechService(settings, mockLogger);
|
|
39
|
+
const caps = service.getCapabilities();
|
|
40
|
+
assert.equal(caps.sttConfigured, false);
|
|
41
|
+
assert.equal(caps.ttsConfigured, false);
|
|
42
|
+
assert.equal(caps.configured, false);
|
|
43
|
+
});
|
|
44
|
+
it("transcribe throws not-configured when apiKey absent", async () => {
|
|
45
|
+
const service = new SpeechService(createMockSettings({ speech: {} }), mockLogger);
|
|
46
|
+
await assert.rejects(() => service.transcribe({ audioBase64: "", mimeType: "audio/webm" }), /not configured/i);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe("separateProviders = true", () => {
|
|
50
|
+
it("reports per-direction configured status independently", () => {
|
|
51
|
+
const settings = createMockSettings({
|
|
52
|
+
speech: {
|
|
53
|
+
apiKey: "sk-shared",
|
|
54
|
+
separateProviders: true,
|
|
55
|
+
stt: { apiKey: "sk-groq", baseUrl: "https://api.groq.com/openai/v1", model: "whisper-large-v3" },
|
|
56
|
+
tts: { apiKey: "sk-openai", baseUrl: "https://api.openai.com/v1", model: "gpt-4o-mini-tts" },
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const service = new SpeechService(settings, mockLogger);
|
|
60
|
+
const caps = service.getCapabilities();
|
|
61
|
+
assert.equal(caps.separateProviders, true);
|
|
62
|
+
assert.equal(caps.sttConfigured, true);
|
|
63
|
+
assert.equal(caps.ttsConfigured, true);
|
|
64
|
+
assert.equal(caps.configured, true);
|
|
65
|
+
assert.equal(caps.sttBaseUrl, "https://api.groq.com/openai/v1");
|
|
66
|
+
assert.equal(caps.ttsBaseUrl, "https://api.openai.com/v1");
|
|
67
|
+
});
|
|
68
|
+
it("reports partial config when only STT has complete directional pair", () => {
|
|
69
|
+
const settings = createMockSettings({
|
|
70
|
+
speech: {
|
|
71
|
+
separateProviders: true,
|
|
72
|
+
stt: { apiKey: "sk-groq", baseUrl: "https://api.groq.com/openai/v1" },
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
const service = new SpeechService(settings, mockLogger);
|
|
76
|
+
const caps = service.getCapabilities();
|
|
77
|
+
assert.equal(caps.sttConfigured, true);
|
|
78
|
+
assert.equal(caps.ttsConfigured, false);
|
|
79
|
+
assert.equal(caps.configured, false);
|
|
80
|
+
});
|
|
81
|
+
it("does NOT combine directional key with shared URL (incomplete pair)", () => {
|
|
82
|
+
const settings = createMockSettings({
|
|
83
|
+
speech: {
|
|
84
|
+
apiKey: "sk-shared",
|
|
85
|
+
baseUrl: "https://api.openai.com/v1",
|
|
86
|
+
separateProviders: true,
|
|
87
|
+
stt: { apiKey: "sk-groq" },
|
|
88
|
+
tts: { apiKey: "sk-deepseek" },
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
const service = new SpeechService(settings, mockLogger);
|
|
92
|
+
const caps = service.getCapabilities();
|
|
93
|
+
assert.equal(caps.sttConfigured, false, "directional key without directional URL should not be configured");
|
|
94
|
+
assert.equal(caps.ttsConfigured, false);
|
|
95
|
+
});
|
|
96
|
+
it("does NOT combine shared key with foreign directional URL (incomplete pair)", () => {
|
|
97
|
+
const settings = createMockSettings({
|
|
98
|
+
speech: {
|
|
99
|
+
apiKey: "sk-shared",
|
|
100
|
+
baseUrl: "https://api.openai.com/v1",
|
|
101
|
+
separateProviders: true,
|
|
102
|
+
stt: { baseUrl: "https://api.groq.com/openai/v1" },
|
|
103
|
+
tts: { baseUrl: "https://api.deepseek.com/v1" },
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
const service = new SpeechService(settings, mockLogger);
|
|
107
|
+
const caps = service.getCapabilities();
|
|
108
|
+
assert.equal(caps.sttConfigured, false);
|
|
109
|
+
assert.equal(caps.ttsConfigured, false);
|
|
110
|
+
});
|
|
111
|
+
it("treats directional baseUrl matching shared as inherited (no directional key)", () => {
|
|
112
|
+
const sharedUrl = "https://api.openai.com/v1";
|
|
113
|
+
const settings = createMockSettings({
|
|
114
|
+
speech: {
|
|
115
|
+
apiKey: "sk-shared",
|
|
116
|
+
baseUrl: sharedUrl,
|
|
117
|
+
separateProviders: true,
|
|
118
|
+
stt: { baseUrl: sharedUrl },
|
|
119
|
+
tts: { baseUrl: sharedUrl },
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
const service = new SpeechService(settings, mockLogger);
|
|
123
|
+
const caps = service.getCapabilities();
|
|
124
|
+
assert.equal(caps.sttConfigured, true, "directional baseUrl matching shared with no key should inherit shared key");
|
|
125
|
+
assert.equal(caps.ttsConfigured, true);
|
|
126
|
+
});
|
|
127
|
+
it("inherits complete shared pair when neither directional value is set", () => {
|
|
128
|
+
const settings = createMockSettings({
|
|
129
|
+
speech: {
|
|
130
|
+
apiKey: "sk-shared",
|
|
131
|
+
baseUrl: "https://api.openai.com/v1",
|
|
132
|
+
separateProviders: true,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
const service = new SpeechService(settings, mockLogger);
|
|
136
|
+
const caps = service.getCapabilities();
|
|
137
|
+
assert.equal(caps.sttConfigured, true);
|
|
138
|
+
assert.equal(caps.ttsConfigured, true);
|
|
139
|
+
});
|
|
140
|
+
it("uses complete directional pair when both key and URL are set", () => {
|
|
141
|
+
const settings = createMockSettings({
|
|
142
|
+
speech: {
|
|
143
|
+
apiKey: "sk-shared",
|
|
144
|
+
baseUrl: "https://api.openai.com/v1",
|
|
145
|
+
separateProviders: true,
|
|
146
|
+
stt: { apiKey: "sk-groq", baseUrl: "https://api.groq.com/openai/v1" },
|
|
147
|
+
tts: { apiKey: "sk-openai", baseUrl: "https://api.openai.com/v1" },
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
const service = new SpeechService(settings, mockLogger);
|
|
151
|
+
const caps = service.getCapabilities();
|
|
152
|
+
assert.equal(caps.sttConfigured, true);
|
|
153
|
+
assert.equal(caps.ttsConfigured, true);
|
|
154
|
+
assert.equal(caps.sttBaseUrl, "https://api.groq.com/openai/v1");
|
|
155
|
+
});
|
|
156
|
+
it("directional key with matching shared URL forms a complete pair", () => {
|
|
157
|
+
const sharedUrl = "https://api.openai.com/v1";
|
|
158
|
+
const settings = createMockSettings({
|
|
159
|
+
speech: {
|
|
160
|
+
apiKey: "sk-shared",
|
|
161
|
+
baseUrl: sharedUrl,
|
|
162
|
+
separateProviders: true,
|
|
163
|
+
stt: { apiKey: "sk-alt-openai", baseUrl: sharedUrl },
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
const service = new SpeechService(settings, mockLogger);
|
|
167
|
+
const caps = service.getCapabilities();
|
|
168
|
+
assert.equal(caps.sttConfigured, true, "directional key with matching shared URL should be a complete pair");
|
|
169
|
+
});
|
|
170
|
+
it("falls back to shared sttModel/ttsModel when per-direction model is absent", () => {
|
|
171
|
+
const settings = createMockSettings({
|
|
172
|
+
speech: {
|
|
173
|
+
apiKey: "sk-shared",
|
|
174
|
+
baseUrl: "https://api.openai.com/v1",
|
|
175
|
+
sttModel: "shared-stt-model",
|
|
176
|
+
ttsModel: "shared-tts-model",
|
|
177
|
+
separateProviders: true,
|
|
178
|
+
stt: { apiKey: "sk-stt", baseUrl: "https://api.openai.com/v1" },
|
|
179
|
+
tts: { apiKey: "sk-tts", baseUrl: "https://api.openai.com/v1" },
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
const service = new SpeechService(settings, mockLogger);
|
|
183
|
+
const caps = service.getCapabilities();
|
|
184
|
+
assert.equal(caps.sttModel, "shared-stt-model");
|
|
185
|
+
assert.equal(caps.ttsModel, "shared-tts-model");
|
|
186
|
+
});
|
|
187
|
+
it("uses per-direction model when set", () => {
|
|
188
|
+
const settings = createMockSettings({
|
|
189
|
+
speech: {
|
|
190
|
+
apiKey: "sk-shared",
|
|
191
|
+
baseUrl: "https://api.openai.com/v1",
|
|
192
|
+
sttModel: "shared-stt-model",
|
|
193
|
+
ttsModel: "shared-tts-model",
|
|
194
|
+
separateProviders: true,
|
|
195
|
+
stt: { apiKey: "sk-stt", baseUrl: "https://api.openai.com/v1", model: "whisper-large-v3" },
|
|
196
|
+
tts: { apiKey: "sk-tts", baseUrl: "https://api.openai.com/v1", model: "gpt-4o-mini-tts" },
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
const service = new SpeechService(settings, mockLogger);
|
|
200
|
+
const caps = service.getCapabilities();
|
|
201
|
+
assert.equal(caps.sttModel, "whisper-large-v3");
|
|
202
|
+
assert.equal(caps.ttsModel, "gpt-4o-mini-tts");
|
|
203
|
+
});
|
|
204
|
+
it("omits sttBaseUrl/ttsBaseUrl when separateProviders is false", () => {
|
|
205
|
+
const settings = createMockSettings({
|
|
206
|
+
speech: { apiKey: "sk-shared", baseUrl: "https://api.openai.com/v1" },
|
|
207
|
+
});
|
|
208
|
+
const service = new SpeechService(settings, mockLogger);
|
|
209
|
+
const caps = service.getCapabilities();
|
|
210
|
+
assert.equal(caps.sttBaseUrl, undefined);
|
|
211
|
+
assert.equal(caps.ttsBaseUrl, undefined);
|
|
212
|
+
});
|
|
213
|
+
it("transcribe throws not-configured for incomplete pair (key without URL)", async () => {
|
|
214
|
+
const settings = createMockSettings({
|
|
215
|
+
speech: {
|
|
216
|
+
apiKey: "sk-shared",
|
|
217
|
+
baseUrl: "https://api.openai.com/v1",
|
|
218
|
+
separateProviders: true,
|
|
219
|
+
stt: { apiKey: "sk-groq" },
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
const service = new SpeechService(settings, mockLogger);
|
|
223
|
+
await assert.rejects(() => service.transcribe({ audioBase64: "", mimeType: "audio/webm" }), /not configured/i);
|
|
224
|
+
});
|
|
225
|
+
it("configured uses && in separate mode (both required for legacy compat)", () => {
|
|
226
|
+
const settings = createMockSettings({
|
|
227
|
+
speech: {
|
|
228
|
+
separateProviders: true,
|
|
229
|
+
stt: { apiKey: "sk-stt", baseUrl: "https://api.stt.com/v1" },
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
const service = new SpeechService(settings, mockLogger);
|
|
233
|
+
const caps = service.getCapabilities();
|
|
234
|
+
assert.equal(caps.sttConfigured, true);
|
|
235
|
+
assert.equal(caps.ttsConfigured, false);
|
|
236
|
+
assert.equal(caps.configured, false, "configured should be false when only one direction is ready");
|
|
237
|
+
});
|
|
238
|
+
it("configured uses || in shared mode", () => {
|
|
239
|
+
const settings = createMockSettings({
|
|
240
|
+
speech: { apiKey: "sk-shared", baseUrl: "https://api.openai.com/v1" },
|
|
241
|
+
});
|
|
242
|
+
const service = new SpeechService(settings, mockLogger);
|
|
243
|
+
const caps = service.getCapabilities();
|
|
244
|
+
assert.equal(caps.configured, true);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
});
|
package/dist/ui/remote-ui.js
CHANGED
|
@@ -7,8 +7,8 @@ import { Readable } from "stream";
|
|
|
7
7
|
import { fetch } from "undici";
|
|
8
8
|
import yauzl from "yauzl";
|
|
9
9
|
const DEFAULT_MANIFEST_URL = "https://ui.codenomad.neuralnomads.ai/version.json";
|
|
10
|
-
const MANIFEST_TIMEOUT_MS =
|
|
11
|
-
const ZIP_TIMEOUT_MS =
|
|
10
|
+
const MANIFEST_TIMEOUT_MS = 5_000;
|
|
11
|
+
const ZIP_TIMEOUT_MS = 30_000;
|
|
12
12
|
export async function resolveUi(options) {
|
|
13
13
|
const manifestUrl = options.manifestUrl ?? DEFAULT_MANIFEST_URL;
|
|
14
14
|
if (options.uiDevServerUrl) {
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { fetchJson, getCredential, notConfigured, resolveWindowLabel, safeFetch, toNumber, toTimestamp, toUsageWindow, } from "../shared";
|
|
2
|
+
const kimiAliases = ["kimi-for-coding", "kimi"];
|
|
3
|
+
const kimi = {
|
|
4
|
+
id: "kimi-for-coding",
|
|
5
|
+
name: "Kimi for Coding",
|
|
6
|
+
aliases: kimiAliases,
|
|
7
|
+
async fetchQuota() {
|
|
8
|
+
const key = getCredential(kimiAliases, ["key", "token"]);
|
|
9
|
+
if (!key)
|
|
10
|
+
return notConfigured(this.id, this.name);
|
|
11
|
+
return safeFetch(this.id, this.name, async () => {
|
|
12
|
+
const payload = await fetchJson("https://api.kimi.com/coding/v1/usages", {
|
|
13
|
+
headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
|
|
14
|
+
});
|
|
15
|
+
const windows = {};
|
|
16
|
+
const usage = payload?.usage;
|
|
17
|
+
if (usage) {
|
|
18
|
+
const limit = toNumber(usage.limit);
|
|
19
|
+
const remaining = toNumber(usage.remaining);
|
|
20
|
+
windows.weekly = toUsageWindow({
|
|
21
|
+
usedPercent: limit && remaining !== null ? 100 - (remaining / limit) * 100 : null,
|
|
22
|
+
resetAt: toTimestamp(usage.resetTime),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
for (const item of Array.isArray(payload?.limits) ? payload.limits : []) {
|
|
26
|
+
const duration = toNumber(item?.window?.duration);
|
|
27
|
+
const unit = item?.window?.timeUnit;
|
|
28
|
+
const multiplier = unit === "TIME_UNIT_MINUTE" ? 60 : unit === "TIME_UNIT_HOUR" ? 3600 : unit === "TIME_UNIT_DAY" ? 86_400 : null;
|
|
29
|
+
const seconds = duration !== null && multiplier ? duration * multiplier : null;
|
|
30
|
+
const limit = toNumber(item?.detail?.limit);
|
|
31
|
+
const remaining = toNumber(item?.detail?.remaining);
|
|
32
|
+
windows[resolveWindowLabel(seconds)] = toUsageWindow({
|
|
33
|
+
usedPercent: limit && remaining !== null ? 100 - (remaining / limit) * 100 : null,
|
|
34
|
+
windowSeconds: seconds,
|
|
35
|
+
resetAt: toTimestamp(item?.detail?.resetTime),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return { windows };
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const nanoAliases = ["nano-gpt", "nanogpt", "nano_gpt"];
|
|
43
|
+
const nanoGpt = {
|
|
44
|
+
id: "nano-gpt",
|
|
45
|
+
name: "NanoGPT",
|
|
46
|
+
aliases: nanoAliases,
|
|
47
|
+
async fetchQuota() {
|
|
48
|
+
const key = getCredential(nanoAliases, ["key", "token"]);
|
|
49
|
+
if (!key)
|
|
50
|
+
return notConfigured(this.id, this.name);
|
|
51
|
+
return safeFetch(this.id, this.name, async () => {
|
|
52
|
+
const payload = await fetchJson("https://nano-gpt.com/api/subscription/v1/usage", {
|
|
53
|
+
headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
|
|
54
|
+
});
|
|
55
|
+
const windows = {};
|
|
56
|
+
for (const [label, source] of [["daily", payload?.daily], ["monthly", payload?.monthly]]) {
|
|
57
|
+
if (!source)
|
|
58
|
+
continue;
|
|
59
|
+
const fraction = toNumber(source.percentUsed);
|
|
60
|
+
const used = toNumber(source.used);
|
|
61
|
+
const limit = toNumber(source.limit ?? source.limits?.[label]);
|
|
62
|
+
windows[label] = toUsageWindow({
|
|
63
|
+
usedPercent: fraction !== null ? fraction * 100 : used !== null && limit ? (used / limit) * 100 : null,
|
|
64
|
+
windowSeconds: label === "daily" ? 86_400 : null,
|
|
65
|
+
resetAt: toTimestamp(source.resetAt ?? payload?.period?.currentPeriodEnd),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return { windows };
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const openRouterAliases = ["openrouter"];
|
|
73
|
+
const openRouter = {
|
|
74
|
+
id: "openrouter",
|
|
75
|
+
name: "OpenRouter",
|
|
76
|
+
aliases: openRouterAliases,
|
|
77
|
+
async fetchQuota() {
|
|
78
|
+
const key = getCredential(openRouterAliases, ["key", "token"]);
|
|
79
|
+
if (!key)
|
|
80
|
+
return notConfigured(this.id, this.name);
|
|
81
|
+
return safeFetch(this.id, this.name, async () => {
|
|
82
|
+
const payload = await fetchJson("https://openrouter.ai/api/v1/credits", {
|
|
83
|
+
headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
|
|
84
|
+
});
|
|
85
|
+
const total = toNumber(payload?.data?.total_credits);
|
|
86
|
+
const used = toNumber(payload?.data?.total_usage);
|
|
87
|
+
const remaining = total !== null && used !== null ? Math.max(0, total - used) : null;
|
|
88
|
+
return {
|
|
89
|
+
windows: {
|
|
90
|
+
credits: toUsageWindow({
|
|
91
|
+
usedPercent: total && used !== null ? (used / total) * 100 : null,
|
|
92
|
+
valueLabel: remaining !== null && total !== null ? `$${remaining.toFixed(2)} / $${total.toFixed(2)}` : null,
|
|
93
|
+
}),
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
function createTokenLimitProvider(input) {
|
|
100
|
+
return {
|
|
101
|
+
id: input.id,
|
|
102
|
+
name: input.name,
|
|
103
|
+
aliases: input.aliases,
|
|
104
|
+
async fetchQuota() {
|
|
105
|
+
const key = getCredential(input.aliases, ["key", "token"]);
|
|
106
|
+
if (!key)
|
|
107
|
+
return notConfigured(this.id, this.name);
|
|
108
|
+
return safeFetch(this.id, this.name, async () => {
|
|
109
|
+
const payload = await fetchJson(input.url, { headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" } });
|
|
110
|
+
const windows = {};
|
|
111
|
+
for (const limit of Array.isArray(payload?.data?.limits) ? payload.data.limits : []) {
|
|
112
|
+
if (limit?.type !== "TOKENS_LIMIT" && limit?.type !== "TIME_LIMIT")
|
|
113
|
+
continue;
|
|
114
|
+
const duration = toNumber(limit.number);
|
|
115
|
+
const seconds = limit.type === "TIME_LIMIT" ? 30 * 86_400 : limit.unit === 3 && duration ? duration * 3600 : null;
|
|
116
|
+
const label = limit.type === "TIME_LIMIT" ? "mcp-tools" : resolveWindowLabel(seconds);
|
|
117
|
+
windows[label] = toUsageWindow({
|
|
118
|
+
usedPercent: toNumber(limit.percentage),
|
|
119
|
+
windowSeconds: seconds,
|
|
120
|
+
resetAt: toTimestamp(limit.nextResetTime),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return { windows };
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const zai = createTokenLimitProvider({
|
|
129
|
+
id: "zai-coding-plan",
|
|
130
|
+
name: "z.ai",
|
|
131
|
+
aliases: ["zai-coding-plan", "zai", "z.ai"],
|
|
132
|
+
url: "https://api.z.ai/api/monitor/usage/quota/limit",
|
|
133
|
+
});
|
|
134
|
+
const zhipu = createTokenLimitProvider({
|
|
135
|
+
id: "zhipuai-coding-plan",
|
|
136
|
+
name: "Zhipu AI Coding Plan",
|
|
137
|
+
aliases: ["zhipuai-coding-plan", "zhipuai", "zhipu"],
|
|
138
|
+
url: "https://open.bigmodel.cn/api/monitor/usage/quota/limit",
|
|
139
|
+
});
|
|
140
|
+
const waferAliases = ["wafer", "wafer-ai", "wafer_ai", "wafer.ai"];
|
|
141
|
+
const wafer = {
|
|
142
|
+
id: "wafer",
|
|
143
|
+
name: "Wafer.ai",
|
|
144
|
+
aliases: waferAliases,
|
|
145
|
+
async fetchQuota() {
|
|
146
|
+
const key = getCredential(waferAliases, ["key", "token"]);
|
|
147
|
+
if (!key)
|
|
148
|
+
return notConfigured(this.id, this.name);
|
|
149
|
+
return safeFetch(this.id, this.name, async () => {
|
|
150
|
+
const payload = await fetchJson("https://pass.wafer.ai/v1/inference/quota", {
|
|
151
|
+
headers: { Authorization: `Bearer ${key}`, "Accept-Encoding": "identity" },
|
|
152
|
+
});
|
|
153
|
+
const remaining = toNumber(payload?.remaining_included_requests);
|
|
154
|
+
const limit = toNumber(payload?.included_request_limit);
|
|
155
|
+
const startAt = toTimestamp(payload?.window_start);
|
|
156
|
+
const resetAt = toTimestamp(payload?.window_end);
|
|
157
|
+
const seconds = startAt !== null && resetAt !== null ? Math.round((resetAt - startAt) / 1000) : 5 * 3600;
|
|
158
|
+
return {
|
|
159
|
+
windows: {
|
|
160
|
+
[resolveWindowLabel(seconds)]: toUsageWindow({
|
|
161
|
+
usedPercent: toNumber(payload?.current_period_used_percent),
|
|
162
|
+
windowSeconds: seconds,
|
|
163
|
+
resetAt,
|
|
164
|
+
valueLabel: remaining !== null && limit !== null ? `${remaining} / ${limit}` : null,
|
|
165
|
+
}),
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
export const apiKeyProviders = [kimi, nanoGpt, openRouter, zai, zhipu, wafer];
|