@corenel/sidecar 0.8.0 → 0.8.1

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.
Files changed (2) hide show
  1. package/dist/cli.js +62 -5
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -25280,9 +25280,10 @@ function oauthConfigFromEnv(env = process.env) {
25280
25280
  return { issuer, clientId };
25281
25281
  }
25282
25282
  function openBrowser(url) {
25283
- const cmd = process.platform === "win32" ? "cmd" : process.platform === "darwin" ? "open" : "xdg-open";
25284
- const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
25283
+ const [cmd, args] = process.platform === "win32" ? ["rundll32", ["url.dll,FileProtocolHandler", url]] : process.platform === "darwin" ? ["open", [url]] : ["xdg-open", [url]];
25285
25284
  const child = spawn6(cmd, args, { detached: true, stdio: "ignore" });
25285
+ child.on("error", () => {
25286
+ });
25286
25287
  child.unref();
25287
25288
  }
25288
25289
  async function exchangeCode2(p2) {
@@ -46192,7 +46193,7 @@ var FLAG_TO_KEY = {
46192
46193
  "--default-model": "defaultModel",
46193
46194
  "--name": "name"
46194
46195
  };
46195
- var DEFAULT_GUEST_IMAGE2 = "prompd/corenel-sandbox:0.7.0";
46196
+ var DEFAULT_GUEST_IMAGE2 = "prompd/corenel-sandbox:0.8.1";
46196
46197
  function parseArgsWithProvenance(argv) {
46197
46198
  const explicit = /* @__PURE__ */ new Set();
46198
46199
  for (const a2 of argv) {
@@ -46880,6 +46881,49 @@ async function readMcpCredential(stateDir, server) {
46880
46881
  const cred = section[server];
46881
46882
  return isUsableCredential(cred) ? cred : null;
46882
46883
  }
46884
+ function isUsableClient(v2) {
46885
+ if (typeof v2 !== "object" || v2 === null) return false;
46886
+ const r2 = v2;
46887
+ return typeof r2.clientId === "string" && r2.clientId.length > 0 && typeof r2.authServer === "string" && r2.authServer.length > 0 && (r2.clientSecret === void 0 || typeof r2.clientSecret === "string");
46888
+ }
46889
+ async function readMcpClient(stateDir, server) {
46890
+ const doc = await readAuthJson(stateDir);
46891
+ const section = doc.mcpClients;
46892
+ if (typeof section !== "object" || section === null || Array.isArray(section)) return null;
46893
+ const rec5 = section[server];
46894
+ return isUsableClient(rec5) ? rec5 : null;
46895
+ }
46896
+ async function writeMcpClient(stateDir, server, client) {
46897
+ const doc = await readAuthJson(stateDir);
46898
+ const prev = doc.mcpClients;
46899
+ const section = typeof prev === "object" && prev !== null && !Array.isArray(prev) ? { ...prev } : {};
46900
+ section[server] = client;
46901
+ const next = { ...doc, mcpClients: section };
46902
+ const path = credentialFilePath(stateDir);
46903
+ await mkdir4(credentialDir(stateDir), { recursive: true });
46904
+ await writeFile2(path, `${JSON.stringify(next, null, 2)}
46905
+ `, { mode: 384 });
46906
+ try {
46907
+ await chmod(path, 384);
46908
+ } catch {
46909
+ }
46910
+ }
46911
+ async function clearMcpClient(stateDir, server) {
46912
+ const doc = await readAuthJson(stateDir);
46913
+ const prev = doc.mcpClients;
46914
+ if (typeof prev !== "object" || prev === null || Array.isArray(prev)) return;
46915
+ const section = { ...prev };
46916
+ if (!(server in section)) return;
46917
+ delete section[server];
46918
+ const path = credentialFilePath(stateDir);
46919
+ await mkdir4(credentialDir(stateDir), { recursive: true });
46920
+ await writeFile2(path, `${JSON.stringify({ ...doc, mcpClients: section }, null, 2)}
46921
+ `, { mode: 384 });
46922
+ try {
46923
+ await chmod(path, 384);
46924
+ } catch {
46925
+ }
46926
+ }
46883
46927
  async function writeMcpCredential(stateDir, server, cred) {
46884
46928
  const doc = await readAuthJson(stateDir);
46885
46929
  const section = isMcpAuthSection(doc.mcp) ? { ...doc.mcp } : {};
@@ -47214,11 +47258,19 @@ async function loginToMcpServer(stateDir, server, deps = {}) {
47214
47258
  );
47215
47259
  const port = await getFreePort();
47216
47260
  const redirectUri = `http://localhost:${port}/callback`;
47217
- const registered2 = await registerClient(
47261
+ const cached = await readMcpClient(stateDir, server.name);
47262
+ const registered2 = cached && cached.authServer === discovered.authServer ? { clientId: cached.clientId, ...cached.clientSecret ? { clientSecret: cached.clientSecret } : {} } : await registerClient(
47218
47263
  meta,
47219
47264
  redirectUri,
47220
47265
  fetchImpl
47221
47266
  );
47267
+ if (registered2 && !cached) {
47268
+ await writeMcpClient(stateDir, server.name, {
47269
+ clientId: registered2.clientId,
47270
+ ...registered2.clientSecret ? { clientSecret: registered2.clientSecret } : {},
47271
+ authServer: discovered.authServer
47272
+ });
47273
+ }
47222
47274
  if (!registered2) {
47223
47275
  return {
47224
47276
  ok: false,
@@ -47259,7 +47311,12 @@ async function loginToMcpServer(stateDir, server, deps = {}) {
47259
47311
  await writeMcpCredential(stateDir, server.name, cred);
47260
47312
  return { ok: true };
47261
47313
  } catch (e2) {
47262
- return { ok: false, reason: "failed", message: e2 instanceof Error ? e2.message : String(e2) };
47314
+ const message = e2 instanceof Error ? e2.message : String(e2);
47315
+ if (/invalid_client|unauthorized_client|client.{0,20}not.{0,10}found/i.test(message)) {
47316
+ await clearMcpClient(stateDir, server.name).catch(() => {
47317
+ });
47318
+ }
47319
+ return { ok: false, reason: "failed", message };
47263
47320
  }
47264
47321
  }
47265
47322
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corenel/sidecar",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "license": "Elastic-2.0",
6
6
  "description": "Prompd sidecar — a local capability server. Run it next to Prompd (prompd.app) so the browser app can reach your machine: local LLMs (Ollama/LM Studio/vLLM) without CORS, your filesystem, and (opt-in) shell.",
@@ -36,9 +36,9 @@
36
36
  "esbuild": "^0.21.5",
37
37
  "tsx": "^4.19.2",
38
38
  "typescript": "^5.9.3",
39
- "@corenel/harness": "0.7.0",
40
39
  "@corenel/protocol": "0.7.0",
41
40
  "@corenel/tools-node": "0.3.2",
41
+ "@corenel/harness": "0.7.0",
42
42
  "@corenel/crew": "0.0.0"
43
43
  },
44
44
  "repository": {