opencommand-plugin 0.0.13 → 0.0.14
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/index.js +35 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -939,12 +939,15 @@ function writeCachedOpenCommandModels(models) {
|
|
|
939
939
|
function openCommandModelCachePath() {
|
|
940
940
|
return path.join(process.env.HOME || "/tmp", ".opencommand", "model-cache.json");
|
|
941
941
|
}
|
|
942
|
-
function proxyBaseURLForRegistration() {
|
|
942
|
+
async function proxyBaseURLForRegistration() {
|
|
943
943
|
const runtimeConfig = runtimePlugin?.getCurrentProxyConfig();
|
|
944
944
|
if (runtimeConfig)
|
|
945
945
|
return `http://localhost:${runtimeConfig.port}/v1`;
|
|
946
946
|
const persistedBaseURL = readPersistedProxyBaseURL();
|
|
947
|
-
|
|
947
|
+
if (persistedBaseURL && (await isProxyHealthy(persistedBaseURL))) {
|
|
948
|
+
return persistedBaseURL;
|
|
949
|
+
}
|
|
950
|
+
return DEFAULT_PROXY_BASE_URL;
|
|
948
951
|
}
|
|
949
952
|
function readPersistedProxyBaseURL() {
|
|
950
953
|
try {
|
|
@@ -962,6 +965,33 @@ function readPersistedProxyBaseURL() {
|
|
|
962
965
|
}
|
|
963
966
|
return undefined;
|
|
964
967
|
}
|
|
968
|
+
async function isProxyHealthy(baseURL) {
|
|
969
|
+
const controller = new AbortController();
|
|
970
|
+
const timeoutId = setTimeout(() => controller.abort(), 500);
|
|
971
|
+
try {
|
|
972
|
+
const response = await fetch(`${baseURL.replace(/\/v1\/?$/, "")}/healthz`, {
|
|
973
|
+
signal: controller.signal,
|
|
974
|
+
});
|
|
975
|
+
return response.ok;
|
|
976
|
+
}
|
|
977
|
+
catch {
|
|
978
|
+
return false;
|
|
979
|
+
}
|
|
980
|
+
finally {
|
|
981
|
+
clearTimeout(timeoutId);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
async function currentProxyBaseURL(plugin) {
|
|
985
|
+
try {
|
|
986
|
+
const proxyConfig = await plugin.ensureStarted();
|
|
987
|
+
if (proxyConfig)
|
|
988
|
+
return `http://localhost:${proxyConfig.port}/v1`;
|
|
989
|
+
}
|
|
990
|
+
catch (error) {
|
|
991
|
+
debugError("Failed to start OpenCommand proxy for provider registration:", error);
|
|
992
|
+
}
|
|
993
|
+
return proxyBaseURLForRegistration();
|
|
994
|
+
}
|
|
965
995
|
function parseProxyPort(value) {
|
|
966
996
|
const port = Number(value);
|
|
967
997
|
return Number.isInteger(port) && port > 0 && port < 65536 ? port : undefined;
|
|
@@ -972,7 +1002,8 @@ function getRuntimePlugin() {
|
|
|
972
1002
|
return runtimePlugin;
|
|
973
1003
|
}
|
|
974
1004
|
export const OpenCommandOpenCodePlugin = async () => {
|
|
975
|
-
const
|
|
1005
|
+
const plugin = getRuntimePlugin();
|
|
1006
|
+
const baseURL = await currentProxyBaseURL(plugin);
|
|
976
1007
|
return {
|
|
977
1008
|
provider: {
|
|
978
1009
|
[PROVIDER_ID]: {
|
|
@@ -999,12 +1030,8 @@ export const OpenCommandOpenCodePlugin = async () => {
|
|
|
999
1030
|
methods: [],
|
|
1000
1031
|
},
|
|
1001
1032
|
config: async (config) => {
|
|
1002
|
-
const plugin = getRuntimePlugin();
|
|
1003
1033
|
plugin.preloadForOpenCode();
|
|
1004
|
-
const
|
|
1005
|
-
const registrationBaseURL = currentConfig
|
|
1006
|
-
? `http://localhost:${currentConfig.port}/v1`
|
|
1007
|
-
: proxyBaseURLForRegistration();
|
|
1034
|
+
const registrationBaseURL = await currentProxyBaseURL(plugin);
|
|
1008
1035
|
registerOpenCommandProvider(config, registrationBaseURL, readCachedOpenCommandModels() ?? COMMAND_CODE_GO_PLAN_MODELS);
|
|
1009
1036
|
},
|
|
1010
1037
|
};
|