@inworld/cli 1.3.1 → 1.4.0-rc.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/index.js CHANGED
@@ -7268,7 +7268,7 @@ var require_schemes = __commonJS({
7268
7268
  urnComponent.nss = (uuidComponent.uuid || "").toLowerCase();
7269
7269
  return urnComponent;
7270
7270
  }
7271
- var http4 = (
7271
+ var http2 = (
7272
7272
  /** @type {SchemeHandler} */
7273
7273
  {
7274
7274
  scheme: "http",
@@ -7281,7 +7281,7 @@ var require_schemes = __commonJS({
7281
7281
  /** @type {SchemeHandler} */
7282
7282
  {
7283
7283
  scheme: "https",
7284
- domainHost: http4.domainHost,
7284
+ domainHost: http2.domainHost,
7285
7285
  parse: httpParse,
7286
7286
  serialize: httpSerialize
7287
7287
  }
@@ -7325,7 +7325,7 @@ var require_schemes = __commonJS({
7325
7325
  var SCHEMES = (
7326
7326
  /** @type {Record<SchemeName, SchemeHandler>} */
7327
7327
  {
7328
- http: http4,
7328
+ http: http2,
7329
7329
  https,
7330
7330
  ws,
7331
7331
  wss,
@@ -19524,14 +19524,131 @@ var init_dist4 = __esm({
19524
19524
  }
19525
19525
  });
19526
19526
 
19527
+ // package.json
19528
+ var package_default;
19529
+ var init_package = __esm({
19530
+ "package.json"() {
19531
+ package_default = {
19532
+ name: "@inworld/cli",
19533
+ version: "1.4.0-rc.0",
19534
+ type: "module",
19535
+ main: "dist/index.js",
19536
+ bin: {
19537
+ inworld: "dist/index.js",
19538
+ "inworld-mcp": "dist/cli/inworld-mcp.js"
19539
+ },
19540
+ scripts: {
19541
+ postversion: "npm install && git add ../../package-lock.json",
19542
+ "copy:release-it-config": "node ../../scripts/copy-release-it-config.js",
19543
+ clean: "shx rm -rf dist",
19544
+ build: "npm run clean && node esbuild.config.js && npm run copy:release-it-config",
19545
+ "build:tsc": "tsc --project tsconfig.json",
19546
+ "build:types": "tsc --emitDeclarationOnly",
19547
+ "build:all": "npm run build && npm run build:types",
19548
+ prepublishOnly: "npm --prefix ../.. run build:all",
19549
+ test: "vitest run",
19550
+ "test:watch": "vitest",
19551
+ "test:coverage": "vitest run --coverage",
19552
+ start: "node dist/index.js",
19553
+ dev: "tsx src/index.ts"
19554
+ },
19555
+ engines: {
19556
+ node: ">=20.0.0"
19557
+ },
19558
+ files: [
19559
+ "dist/index.js",
19560
+ "dist/cli/inworld-mcp.js"
19561
+ ],
19562
+ author: "Inworld AI",
19563
+ license: "MIT",
19564
+ description: "Inworld CLI: auth, workspace, TTS, and MCP server entry point.",
19565
+ repository: {
19566
+ type: "git",
19567
+ url: "git+https://github.com/inworld-ai/inworld-cli.git",
19568
+ directory: "packages/cli"
19569
+ },
19570
+ devDependencies: {
19571
+ "@inworld/auth-store": "0.1.0",
19572
+ "@modelcontextprotocol/sdk": "^1.29.0",
19573
+ "@tsconfig/node-lts": "^22.0.2",
19574
+ "@types/adm-zip": "^0.5.8",
19575
+ "@types/express": "^5.0.3",
19576
+ "@types/ffmpeg-static": "^3.0.3",
19577
+ "@types/ffprobe-static": "^2.0.3",
19578
+ "@types/keytar": "^4.4.0",
19579
+ "@types/node": "^24.1.0",
19580
+ "@types/ora": "^3.1.0",
19581
+ "@types/semver": "^7.5.8",
19582
+ "@types/ws": "^8.18.1",
19583
+ "@vitest/coverage-v8": "^4.1.0",
19584
+ chalk: "^5.3.0",
19585
+ commander: "^12.0.0",
19586
+ conf: "^14.0.0",
19587
+ esbuild: "^0.25.10",
19588
+ execa: "^9.5.1",
19589
+ "jwt-decode": "^4.0.0",
19590
+ mixpanel: "^0.18.1",
19591
+ ora: "^8.2.0",
19592
+ "play-sound": "^1.1.6",
19593
+ semver: "^7.6.3",
19594
+ tsx: "^4.20.5",
19595
+ typescript: "^5.8.3",
19596
+ vitest: "^4.1.0",
19597
+ zod: "^3.24.2"
19598
+ },
19599
+ dependencies: {
19600
+ "@zowe/secrets-for-zowe-sdk": "^8.27.0",
19601
+ "adm-zip": "^0.5.17",
19602
+ ws: "^8.21.0"
19603
+ },
19604
+ optionalDependencies: {
19605
+ "ffmpeg-static": "^5.3.0",
19606
+ "ffprobe-static": "^3.1.0"
19607
+ }
19608
+ };
19609
+ }
19610
+ });
19611
+
19612
+ // src/constants.ts
19613
+ var DEFAULT_PLATFORM_ENDPOINT, resolvePlatformUrl, INWORLD_ENV, WORKSPACES_LIST_SIZE, PLATFORM_URL, INWORLD_CLI_AUTH_URL, MIXPANEL_TOKEN, CLI_VERSION;
19614
+ var init_constants5 = __esm({
19615
+ "src/constants.ts"() {
19616
+ "use strict";
19617
+ init_package();
19618
+ DEFAULT_PLATFORM_ENDPOINT = "https://platform.inworld.ai";
19619
+ resolvePlatformUrl = () => {
19620
+ if (process.env.INWORLD_PLATFORM_URL) {
19621
+ return process.env.INWORLD_PLATFORM_URL;
19622
+ }
19623
+ const env3 = (process.env.INWORLD_ENV || "").toUpperCase();
19624
+ switch (env3) {
19625
+ case "DEV":
19626
+ return "https://platform.dev.inworld.ai";
19627
+ case "STAGE":
19628
+ return "https://platform.stage.inworld.ai";
19629
+ case "PROD":
19630
+ return "https://platform.inworld.ai";
19631
+ default:
19632
+ return DEFAULT_PLATFORM_ENDPOINT;
19633
+ }
19634
+ };
19635
+ INWORLD_ENV = process.env.INWORLD_ENV || "PROD";
19636
+ WORKSPACES_LIST_SIZE = 100;
19637
+ PLATFORM_URL = resolvePlatformUrl();
19638
+ INWORLD_CLI_AUTH_URL = process.env.INWORLD_CLI_AUTH_URL || `${PLATFORM_URL.replace(/\/$/, "")}/cli-auth/login`;
19639
+ MIXPANEL_TOKEN = process.env.INWORLD_MIXPANEL_TOKEN || "2cf13116e9701343ac27ddc452adfbbc";
19640
+ CLI_VERSION = package_default.version;
19641
+ }
19642
+ });
19643
+
19527
19644
  // src/mcp/auth/constants.ts
19528
19645
  function getMcpHttpAuthMode() {
19529
19646
  const v = (process.env.INWORLD_MCP_HTTP_AUTH || "session").toLowerCase();
19530
19647
  if (v === "bearer") return "bearer";
19531
19648
  return "session";
19532
19649
  }
19533
- var DEFAULT_PLATFORM_ENDPOINT2, resolvePlatformUrl2, INWORLD_ENV2, PLATFORM_URL2, FIREBASE_API_KEY2, INWORLD_CLI_AUTH_URL2, INWORLD_CLI_AUTH_CALLBACK_PORT2;
19534
- var init_constants5 = __esm({
19650
+ var DEFAULT_PLATFORM_ENDPOINT2, resolvePlatformUrl2, INWORLD_ENV2, PLATFORM_URL2, INWORLD_CLI_AUTH_URL2;
19651
+ var init_constants6 = __esm({
19535
19652
  "src/mcp/auth/constants.ts"() {
19536
19653
  "use strict";
19537
19654
  DEFAULT_PLATFORM_ENDPOINT2 = "https://platform.inworld.ai";
@@ -19553,61 +19670,12 @@ var init_constants5 = __esm({
19553
19670
  };
19554
19671
  INWORLD_ENV2 = process.env.INWORLD_ENV || "PROD";
19555
19672
  PLATFORM_URL2 = resolvePlatformUrl2();
19556
- FIREBASE_API_KEY2 = process.env.INWORLD_FIREBASE_API_KEY || process.env.FIREBASE_API_KEY || "AIzaSyAPVBLVid0xPwjuU4Gmn_6_GyqxBq-SwQs";
19557
- INWORLD_CLI_AUTH_URL2 = process.env.INWORLD_CLI_AUTH_URL || "https://cli.inworld.ai/login";
19558
- INWORLD_CLI_AUTH_CALLBACK_PORT2 = parseInt(
19559
- process.env.INWORLD_CLI_AUTH_CALLBACK_PORT || "8085",
19560
- 10
19561
- );
19562
- }
19563
- });
19564
-
19565
- // src/mcp/auth/firebase-refresh.ts
19566
- async function refreshFirebaseWithRefreshToken(refreshToken) {
19567
- const url = `https://securetoken.googleapis.com/v1/token?key=${encodeURIComponent(FIREBASE_API_KEY2)}`;
19568
- const body = new URLSearchParams({
19569
- grant_type: "refresh_token",
19570
- refresh_token: refreshToken
19571
- });
19572
- const res = await fetch(url, {
19573
- method: "POST",
19574
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
19575
- body: body.toString()
19576
- });
19577
- const text = await res.text();
19578
- let data;
19579
- try {
19580
- data = text ? JSON.parse(text) : {};
19581
- } catch {
19582
- throw new Error(
19583
- `Firebase token refresh: expected JSON (${res.status}): ${text.slice(0, 200)}`
19584
- );
19585
- }
19586
- if (!res.ok) {
19587
- const err = data.error;
19588
- const msg = typeof err?.message === "string" ? err.message : typeof data.message === "string" ? data.message : text.slice(0, 300);
19589
- throw new Error(`Firebase token refresh failed: ${msg}`);
19590
- }
19591
- const idToken = data.id_token;
19592
- const newRefresh = data.refresh_token;
19593
- if (typeof idToken !== "string") {
19594
- throw new Error("Firebase token refresh: response missing id_token");
19595
- }
19596
- return {
19597
- idToken,
19598
- refreshToken: typeof newRefresh === "string" ? newRefresh : refreshToken,
19599
- expiresIn: String(data.expires_in ?? "")
19600
- };
19601
- }
19602
- var init_firebase_refresh = __esm({
19603
- "src/mcp/auth/firebase-refresh.ts"() {
19604
- "use strict";
19605
- init_constants5();
19673
+ INWORLD_CLI_AUTH_URL2 = process.env.INWORLD_CLI_AUTH_URL || `${PLATFORM_URL2.replace(/\/$/, "")}/cli-auth/login`;
19606
19674
  }
19607
19675
  });
19608
19676
 
19609
19677
  // src/mcp/auth/identity.ts
19610
- import { createHash as createHash2, randomBytes } from "node:crypto";
19678
+ import { createHash as createHash2, randomBytes, timingSafeEqual } from "node:crypto";
19611
19679
  import * as http from "node:http";
19612
19680
  function decodeJwtPayload(jwt) {
19613
19681
  const parts = jwt.split(".");
@@ -19624,44 +19692,29 @@ function tokenIssuer(idToken) {
19624
19692
  const iss = decodeJwtPayload(idToken)?.iss;
19625
19693
  return typeof iss === "string" ? iss.replace(/\/$/, "") : void 0;
19626
19694
  }
19627
- function providerForToken(idToken) {
19628
- const iss = tokenIssuer(idToken);
19629
- return iss && /\/auth\/v1$/.test(iss) ? "supabase" : "firebase";
19630
- }
19631
19695
  function isIssuedBy(idToken, source) {
19632
- if (providerForToken(idToken) !== source.provider) return false;
19633
- return source.provider !== "supabase" || tokenIssuer(idToken) === source.authUrl;
19696
+ return tokenIssuer(idToken) === source.authUrl;
19634
19697
  }
19635
- function bearerTypeFor(provider) {
19636
- return provider === "supabase" ? "supabase" : "firebase";
19637
- }
19638
- function authTypeFor(provider) {
19639
- return provider === "supabase" ? "AUTH_TYPE_SUPABASE" : "AUTH_TYPE_FIREBASE";
19698
+ function identitySourceOfStore(stored) {
19699
+ return stored.authProvider === "supabase" && stored.authUrl ? { authUrl: stored.authUrl } : null;
19640
19700
  }
19641
19701
  function parseConfigJs(text) {
19642
19702
  const pick2 = (key) => new RegExp(`["']?${key}["']?\\s*:\\s*["']([^"']+)["']`).exec(text)?.[1];
19643
- return {
19644
- authProvider: pick2("AUTH_PROVIDER"),
19645
- supabaseUrl: pick2("SUPABASE_URL")
19646
- };
19703
+ return { supabaseUrl: pick2("SUPABASE_URL") };
19647
19704
  }
19648
19705
  async function resolveIdentitySource(platformUrl) {
19649
19706
  const base = platformUrl.replace(/\/$/, "");
19650
- const override = process.env.INWORLD_AUTH_PROVIDER?.trim().toLowerCase();
19651
- let config2 = {};
19652
- if (override !== "firebase") {
19653
- try {
19654
- const res = await fetch(`${base}/config.js`, {
19655
- signal: AbortSignal.timeout(5e3)
19656
- });
19657
- if (res.ok) config2 = parseConfigJs(await res.text());
19658
- } catch {
19659
- }
19707
+ const override = process.env.INWORLD_AUTH_URL?.trim();
19708
+ if (override) return { authUrl: override.replace(/\/$/, "") };
19709
+ let supabaseUrl;
19710
+ try {
19711
+ const res = await fetch(`${base}/config.js`, {
19712
+ signal: AbortSignal.timeout(5e3)
19713
+ });
19714
+ if (res.ok) supabaseUrl = parseConfigJs(await res.text()).supabaseUrl;
19715
+ } catch {
19660
19716
  }
19661
- const provider = (override || config2.authProvider || "firebase").toLowerCase();
19662
- if (provider !== "supabase") return { provider: "firebase" };
19663
- const authUrl = process.env.INWORLD_AUTH_URL?.trim() || `${(config2.supabaseUrl || base).replace(/\/$/, "")}/auth/v1`;
19664
- return { provider: "supabase", authUrl: authUrl.replace(/\/$/, "") };
19717
+ return { authUrl: `${(supabaseUrl || base).replace(/\/$/, "")}/auth/v1` };
19665
19718
  }
19666
19719
  function gotrueErrorMessage(data, fallback) {
19667
19720
  if (data && typeof data === "object") {
@@ -19705,17 +19758,11 @@ async function gotrueToken(authUrl, grantType, body) {
19705
19758
  };
19706
19759
  }
19707
19760
  async function refreshIdentityToken(source, refreshToken) {
19708
- if (source.provider === "supabase") {
19709
- if (!source.authUrl) throw new Error("Supabase refresh needs an auth URL");
19710
- return gotrueToken(source.authUrl, "refresh_token", {
19711
- refresh_token: refreshToken
19712
- });
19713
- }
19714
- const r = await refreshFirebaseWithRefreshToken(refreshToken);
19715
- return { idToken: r.idToken, refreshToken: r.refreshToken };
19761
+ return gotrueToken(source.authUrl, "refresh_token", {
19762
+ refresh_token: refreshToken
19763
+ });
19716
19764
  }
19717
19765
  async function revokeSession(source, refreshToken) {
19718
- if (source.provider !== "supabase" || !source.authUrl) return false;
19719
19766
  const { idToken } = await refreshIdentityToken(source, refreshToken);
19720
19767
  const res = await fetch(`${source.authUrl}/logout?scope=local`, {
19721
19768
  method: "POST",
@@ -19732,7 +19779,6 @@ async function revokeSession(source, refreshToken) {
19732
19779
  `Supabase logout failed: ${gotrueErrorMessage(data, `HTTP ${res.status}`)}`
19733
19780
  );
19734
19781
  }
19735
- return true;
19736
19782
  }
19737
19783
  function signInWithPassword(authUrl, email2, password) {
19738
19784
  return gotrueToken(authUrl, "password", { email: email2, password });
@@ -19754,42 +19800,129 @@ function gotrueCallbackPort() {
19754
19800
  const fixed = process.env.INWORLD_CLI_AUTH_CALLBACK_PORT?.trim();
19755
19801
  return fixed ? parseInt(fixed, 10) : 0;
19756
19802
  }
19757
- async function startCodeReceiver(port) {
19803
+ function sameSecret(a2, b) {
19804
+ if (!a2) return false;
19805
+ const x = Buffer.from(a2);
19806
+ const y = Buffer.from(b);
19807
+ return x.length === y.length && timingSafeEqual(x, y);
19808
+ }
19809
+ function readForm(req) {
19810
+ return new Promise((resolve5, reject) => {
19811
+ let size = 0;
19812
+ const chunks = [];
19813
+ req.on("data", (chunk) => {
19814
+ size += chunk.length;
19815
+ if (size > MAX_FORM_BYTES) {
19816
+ reject(new Error("Form body too large"));
19817
+ req.destroy();
19818
+ return;
19819
+ }
19820
+ chunks.push(chunk);
19821
+ });
19822
+ req.on(
19823
+ "end",
19824
+ () => resolve5(new URLSearchParams(Buffer.concat(chunks).toString("utf8")))
19825
+ );
19826
+ req.on("error", reject);
19827
+ });
19828
+ }
19829
+ function signInResultUrl(pageUrl, error2) {
19830
+ const u2 = new URL(pageUrl);
19831
+ u2.search = "";
19832
+ if (error2) {
19833
+ u2.searchParams.set("result", "error");
19834
+ u2.searchParams.set("message", error2.slice(0, 300));
19835
+ } else {
19836
+ u2.searchParams.set("result", "success");
19837
+ }
19838
+ return u2.toString();
19839
+ }
19840
+ async function startLoopbackReceiver(options) {
19841
+ const state = base64url(randomBytes(32));
19842
+ const pageOrigin = new URL(options.pageUrl).origin;
19758
19843
  let settle;
19759
- const code = new Promise((resolve5, reject) => {
19844
+ const done = new Promise((resolve5, reject) => {
19760
19845
  settle = { resolve: resolve5, reject };
19761
19846
  });
19847
+ let claimed = false;
19848
+ const finish = (res, status, redeem) => {
19849
+ claimed = true;
19850
+ redeem().then(
19851
+ (tokens) => {
19852
+ res.writeHead(status, { Location: signInResultUrl(options.pageUrl) });
19853
+ res.end();
19854
+ settle.resolve(tokens);
19855
+ },
19856
+ (error2) => {
19857
+ res.writeHead(status, {
19858
+ Location: signInResultUrl(options.pageUrl, error2.message)
19859
+ });
19860
+ res.end();
19861
+ settle.reject(error2);
19862
+ }
19863
+ );
19864
+ };
19762
19865
  const handler = (req, res) => {
19763
19866
  const url = new URL(req.url ?? "/", "http://127.0.0.1");
19764
19867
  if (url.pathname !== "/") {
19765
19868
  res.writeHead(404).end();
19766
19869
  return;
19767
19870
  }
19768
- const error2 = url.searchParams.get("error_description") ?? url.searchParams.get("error");
19769
- const authCode = url.searchParams.get("code");
19770
- res.writeHead(error2 || !authCode ? 400 : 200, {
19771
- "Content-Type": "text/html; charset=utf-8"
19772
- });
19773
- if (error2 || !authCode) {
19774
- const msg = error2 ?? "No authorization code in the redirect.";
19775
- res.end(resultPage("Sign-in failed", escapeHtml(msg)));
19776
- settle.reject(new Error(`Sign-in failed: ${msg}`));
19871
+ if (claimed) {
19872
+ res.writeHead(409).end("Sign-in already completed.");
19777
19873
  return;
19778
19874
  }
19779
- res.end(
19780
- resultPage(
19781
- "Signed in to Inworld CLI",
19782
- "You can close this tab and return to the terminal."
19783
- )
19784
- );
19785
- settle.resolve(authCode);
19875
+ if (req.method === "GET") {
19876
+ if (!sameSecret(url.searchParams.get("state"), state)) {
19877
+ res.writeHead(400).end("Unknown sign-in.");
19878
+ return;
19879
+ }
19880
+ const error2 = url.searchParams.get("error_description") ?? url.searchParams.get("error");
19881
+ const code = url.searchParams.get("code");
19882
+ if (error2 || !code) {
19883
+ const msg = error2 ?? "No authorization code in the redirect.";
19884
+ finish(res, 302, () => Promise.reject(new Error(msg)));
19885
+ return;
19886
+ }
19887
+ finish(res, 302, () => options.redeemCode(code));
19888
+ return;
19889
+ }
19890
+ if (req.method === "POST") {
19891
+ if (req.headers.origin !== pageOrigin) {
19892
+ res.writeHead(403).end("Unknown origin.");
19893
+ return;
19894
+ }
19895
+ readForm(req).then(
19896
+ (form) => {
19897
+ if (claimed) {
19898
+ res.writeHead(409).end("Sign-in already completed.");
19899
+ return;
19900
+ }
19901
+ if (!sameSecret(form.get("state"), state)) {
19902
+ res.writeHead(400).end("Unknown sign-in.");
19903
+ return;
19904
+ }
19905
+ const refreshToken = form.get("refresh_token");
19906
+ if (!refreshToken) {
19907
+ res.writeHead(400).end("Missing refresh_token.");
19908
+ return;
19909
+ }
19910
+ finish(res, 303, () => options.redeemRefreshToken(refreshToken));
19911
+ },
19912
+ () => {
19913
+ if (!res.headersSent) res.writeHead(413).end();
19914
+ }
19915
+ );
19916
+ return;
19917
+ }
19918
+ res.writeHead(405).end();
19786
19919
  };
19787
19920
  const server = http.createServer({ keepAlive: false }, handler);
19788
19921
  await new Promise((resolve5, reject) => {
19789
19922
  server.once("error", reject);
19790
- server.listen(port, "127.0.0.1", () => resolve5());
19923
+ server.listen(options.port, "127.0.0.1", () => resolve5());
19791
19924
  });
19792
- const { port: boundPort } = server.address();
19925
+ const { port } = server.address();
19793
19926
  const timer = setTimeout(
19794
19927
  () => settle.reject(
19795
19928
  new Error(
@@ -19799,9 +19932,13 @@ async function startCodeReceiver(port) {
19799
19932
  OAUTH_SIGN_IN_TIMEOUT_MS
19800
19933
  );
19801
19934
  timer.unref();
19935
+ const redirectTo = new URL(`http://127.0.0.1:${port}/`);
19936
+ redirectTo.searchParams.set("state", state);
19802
19937
  return {
19803
- redirectTo: `http://127.0.0.1:${boundPort}`,
19804
- code,
19938
+ state,
19939
+ port,
19940
+ redirectTo: redirectTo.toString(),
19941
+ done,
19805
19942
  close: () => {
19806
19943
  clearTimeout(timer);
19807
19944
  server.close();
@@ -19809,36 +19946,49 @@ async function startCodeReceiver(port) {
19809
19946
  }
19810
19947
  };
19811
19948
  }
19812
- async function startOAuthSignIn(options) {
19949
+ async function startBrowserSignIn(options) {
19813
19950
  const { verifier, challenge } = createPkcePair();
19814
- const receiver = await startCodeReceiver(
19815
- options.port ?? gotrueCallbackPort()
19816
- );
19817
- const url = gotrueAuthorizeUrl(
19818
- options.authUrl,
19819
- options.oauthProvider,
19820
- receiver.redirectTo,
19821
- challenge
19822
- );
19823
- const done = receiver.code.then(
19824
- (authCode) => gotrueToken(options.authUrl, "pkce", {
19825
- auth_code: authCode,
19951
+ const receiver = await startLoopbackReceiver({
19952
+ port: options.port ?? gotrueCallbackPort(),
19953
+ pageUrl: options.pageUrl,
19954
+ redeemCode: (code) => gotrueToken(options.authUrl, "pkce", {
19955
+ auth_code: code,
19826
19956
  code_verifier: verifier
19957
+ }),
19958
+ redeemRefreshToken: (refreshToken) => gotrueToken(options.authUrl, "refresh_token", {
19959
+ refresh_token: refreshToken
19827
19960
  })
19828
- ).finally(receiver.close);
19829
- return { url, done };
19961
+ });
19962
+ let url;
19963
+ if (options.oauthProvider) {
19964
+ url = gotrueAuthorizeUrl(
19965
+ options.authUrl,
19966
+ options.oauthProvider,
19967
+ receiver.redirectTo,
19968
+ challenge
19969
+ );
19970
+ } else {
19971
+ const page = new URL(options.pageUrl);
19972
+ page.searchParams.set("version", options.version);
19973
+ page.searchParams.set("port", String(receiver.port));
19974
+ page.searchParams.set("code_challenge", challenge);
19975
+ page.searchParams.set("state", receiver.state);
19976
+ url = page.toString();
19977
+ }
19978
+ return { url, done: receiver.done.finally(receiver.close) };
19830
19979
  }
19831
- var BEARER_TYPE_HEADER, GOTRUE_OAUTH_PROVIDERS, base64url, resultPage, escapeHtml, OAUTH_SIGN_IN_TIMEOUT_MS;
19980
+ var BEARER_TYPE_HEADER, IDENTITY_BEARER_TYPE, IDENTITY_AUTH_TYPE, GOTRUE_OAUTH_PROVIDERS, LEGACY_SIGN_IN_MESSAGE, base64url, OAUTH_SIGN_IN_TIMEOUT_MS, MAX_FORM_BYTES;
19832
19981
  var init_identity = __esm({
19833
19982
  "src/mcp/auth/identity.ts"() {
19834
19983
  "use strict";
19835
- init_firebase_refresh();
19836
19984
  BEARER_TYPE_HEADER = "Grpc-Metadata-X-Authorization-Bearer-Type";
19985
+ IDENTITY_BEARER_TYPE = "supabase";
19986
+ IDENTITY_AUTH_TYPE = "AUTH_TYPE_SUPABASE";
19837
19987
  GOTRUE_OAUTH_PROVIDERS = ["google", "github", "azure"];
19988
+ LEGACY_SIGN_IN_MESSAGE = "Your saved sign-in comes from an older Inworld CLI and no longer works. Run `inworld login` to sign in again.";
19838
19989
  base64url = (buf) => buf.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
19839
- resultPage = (title, detail) => `<!doctype html><html><head><meta charset="utf-8"><title>${title}</title></head><body style="font-family:system-ui;margin:4rem auto;max-width:32rem;text-align:center"><h2>${title}</h2><p>${detail}</p></body></html>`;
19840
- escapeHtml = (s) => s.replace(/[&<>"']/g, (c3) => `&#${c3.charCodeAt(0)};`);
19841
19990
  OAUTH_SIGN_IN_TIMEOUT_MS = 5 * 60 * 1e3;
19991
+ MAX_FORM_BYTES = 16 * 1024;
19842
19992
  }
19843
19993
  });
19844
19994
 
@@ -19868,11 +20018,10 @@ function extractGatewayErrorMessage(data, fallback) {
19868
20018
  return fallback;
19869
20019
  }
19870
20020
  async function exchangeIdentityToken(identityToken) {
19871
- const provider = providerForToken(identityToken);
19872
20021
  const base = PLATFORM_URL2.replace(/\/$/, "");
19873
20022
  const url = `${base}/v1alpha/users:generateTokenUser`;
19874
20023
  const body = JSON.stringify({
19875
- type: authTypeFor(provider),
20024
+ type: IDENTITY_AUTH_TYPE,
19876
20025
  token: identityToken
19877
20026
  });
19878
20027
  let res;
@@ -19882,7 +20031,7 @@ async function exchangeIdentityToken(identityToken) {
19882
20031
  headers: {
19883
20032
  "Content-Type": "application/json",
19884
20033
  Authorization: `Bearer ${identityToken}`,
19885
- [BEARER_TYPE_HEADER]: bearerTypeFor(provider)
20034
+ [BEARER_TYPE_HEADER]: IDENTITY_BEARER_TYPE
19886
20035
  },
19887
20036
  body
19888
20037
  });
@@ -19916,7 +20065,7 @@ async function exchangeIdentityToken(identityToken) {
19916
20065
  var init_exchange = __esm({
19917
20066
  "src/mcp/auth/exchange.ts"() {
19918
20067
  "use strict";
19919
- init_constants5();
20068
+ init_constants6();
19920
20069
  init_identity();
19921
20070
  }
19922
20071
  });
@@ -19968,12 +20117,8 @@ function loadSession() {
19968
20117
  const raw = fs4.readFileSync(p, "utf8");
19969
20118
  const data = JSON.parse(raw);
19970
20119
  if (!data?.token || !data?.type) return null;
19971
- const { firebaseIdToken, firebaseRefreshToken, ...rest } = data;
19972
- return {
19973
- ...rest,
19974
- identityToken: rest.identityToken ?? firebaseIdToken,
19975
- identityRefreshToken: rest.identityRefreshToken ?? firebaseRefreshToken
19976
- };
20120
+ if (!identitySourceOfStore(data)) return null;
20121
+ return data;
19977
20122
  } catch {
19978
20123
  return null;
19979
20124
  }
@@ -20005,7 +20150,7 @@ async function hasUsableAuthCredentials() {
20005
20150
  if (hasStoredCredentials()) return true;
20006
20151
  try {
20007
20152
  const c3 = await readStoredCredentials();
20008
- if (c3?.refreshToken?.trim()) return true;
20153
+ if (c3?.refreshToken?.trim() && identitySourceOfStore(c3)) return true;
20009
20154
  if (c3?.apiKey?.trim()) return true;
20010
20155
  } catch {
20011
20156
  }
@@ -20016,15 +20161,13 @@ var init_session = __esm({
20016
20161
  "src/mcp/auth/session.ts"() {
20017
20162
  "use strict";
20018
20163
  init_dist4();
20164
+ init_identity();
20019
20165
  init_paths();
20020
20166
  TIME_DIFF_MS = 120 * 1e3;
20021
20167
  }
20022
20168
  });
20023
20169
 
20024
20170
  // src/mcp/auth/cli-store-bridge.ts
20025
- function identitySourceOfStore(c3) {
20026
- return c3.authProvider === "supabase" ? { provider: "supabase", authUrl: c3.authUrl } : { provider: "firebase" };
20027
- }
20028
20171
  async function persistRotatedRefreshToken(used, next) {
20029
20172
  const c3 = await readStoredCredentials();
20030
20173
  if (!c3?.refreshToken) return false;
@@ -20043,11 +20186,11 @@ async function saveSessionUnlessLoggedOut(session) {
20043
20186
  async function hydrateMcpSessionFromCliStore() {
20044
20187
  const c3 = await readStoredCredentials();
20045
20188
  const refreshToken = c3?.refreshToken?.trim();
20046
- if (!c3 || !refreshToken) {
20189
+ const source = c3 ? identitySourceOfStore(c3) : null;
20190
+ if (!c3 || !refreshToken || !source) {
20047
20191
  return null;
20048
20192
  }
20049
20193
  try {
20050
- const source = identitySourceOfStore(c3);
20051
20194
  const rt = await refreshIdentityToken(source, refreshToken);
20052
20195
  if (!await persistRotatedRefreshToken(refreshToken, rt.refreshToken)) {
20053
20196
  return null;
@@ -20057,7 +20200,7 @@ async function hydrateMcpSessionFromCliStore() {
20057
20200
  ...exchanged,
20058
20201
  identityToken: rt.idToken,
20059
20202
  identityRefreshToken: rt.refreshToken,
20060
- authProvider: source.provider,
20203
+ authProvider: "supabase",
20061
20204
  authUrl: source.authUrl,
20062
20205
  email: c3.email ?? exchanged.email
20063
20206
  };
@@ -25188,7 +25331,7 @@ var require_mixpanel_node = __commonJS({
25188
25331
  "../../node_modules/mixpanel/lib/mixpanel-node.js"(exports, module) {
25189
25332
  var querystring = __require("querystring");
25190
25333
  var Buffer5 = __require("buffer").Buffer;
25191
- var http4 = __require("http");
25334
+ var http2 = __require("http");
25192
25335
  var https = __require("https");
25193
25336
  var HttpsProxyAgent = require_dist2();
25194
25337
  var url = __require("url");
@@ -25219,9 +25362,9 @@ var require_mixpanel_node = __commonJS({
25219
25362
  };
25220
25363
  const { keepAlive } = metrics.config;
25221
25364
  const MAX_BATCH_SIZE = 50;
25222
- const REQUEST_LIBS = { http: http4, https };
25365
+ const REQUEST_LIBS = { http: http2, https };
25223
25366
  const REQUEST_AGENTS = {
25224
- http: new http4.Agent({ keepAlive }),
25367
+ http: new http2.Agent({ keepAlive }),
25225
25368
  https: new https.Agent({ keepAlive })
25226
25369
  };
25227
25370
  const proxyPath = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
@@ -43167,8 +43310,8 @@ var require_escape_html = __commonJS({
43167
43310
  "../../node_modules/escape-html/index.js"(exports, module) {
43168
43311
  "use strict";
43169
43312
  var matchHtmlRegExp = /["'&<>]/;
43170
- module.exports = escapeHtml2;
43171
- function escapeHtml2(string3) {
43313
+ module.exports = escapeHtml;
43314
+ function escapeHtml(string3) {
43172
43315
  var str = "" + string3;
43173
43316
  var match = matchHtmlRegExp.exec(str);
43174
43317
  if (!match) {
@@ -43299,13 +43442,13 @@ var require_finalhandler = __commonJS({
43299
43442
  "use strict";
43300
43443
  var debug = require_src()("finalhandler");
43301
43444
  var encodeUrl = require_encodeurl();
43302
- var escapeHtml2 = require_escape_html();
43445
+ var escapeHtml = require_escape_html();
43303
43446
  var onFinished = require_on_finished();
43304
43447
  var parseUrl = require_parseurl();
43305
43448
  var statuses = require_statuses();
43306
43449
  var isFinished = onFinished.isFinished;
43307
43450
  function createHtmlDocument(message) {
43308
- var body = escapeHtml2(message).replaceAll("\n", "<br>").replaceAll(" ", " &nbsp;");
43451
+ var body = escapeHtml(message).replaceAll("\n", "<br>").replaceAll(" ", " &nbsp;");
43309
43452
  return '<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<title>Error</title>\n</head>\n<body>\n<pre>' + body + "</pre>\n</body>\n</html>\n";
43310
43453
  }
43311
43454
  module.exports = finalhandler;
@@ -45640,7 +45783,7 @@ var require_application = __commonJS({
45640
45783
  var finalhandler = require_finalhandler();
45641
45784
  var debug = require_src()("express:application");
45642
45785
  var View = require_view();
45643
- var http4 = __require("node:http");
45786
+ var http2 = __require("node:http");
45644
45787
  var methods = require_utils6().methods;
45645
45788
  var compileETag = require_utils6().compileETag;
45646
45789
  var compileQueryParser = require_utils6().compileQueryParser;
@@ -45873,7 +46016,7 @@ var require_application = __commonJS({
45873
46016
  tryRender(view, renderOptions, done);
45874
46017
  };
45875
46018
  app.listen = function listen() {
45876
- var server = http4.createServer(this);
46019
+ var server = http2.createServer(this);
45877
46020
  var args = slice.call(arguments);
45878
46021
  if (typeof args[args.length - 1] === "function") {
45879
46022
  var done = args[args.length - 1] = once9(args[args.length - 1]);
@@ -46648,12 +46791,12 @@ var require_request = __commonJS({
46648
46791
  var accepts = require_accepts();
46649
46792
  var isIP = __require("node:net").isIP;
46650
46793
  var typeis = require_type_is();
46651
- var http4 = __require("node:http");
46794
+ var http2 = __require("node:http");
46652
46795
  var fresh = require_fresh();
46653
46796
  var parseRange = require_range_parser();
46654
46797
  var parse3 = require_parseurl();
46655
46798
  var proxyaddr = require_proxy_addr();
46656
- var req = Object.create(http4.IncomingMessage.prototype);
46799
+ var req = Object.create(http2.IncomingMessage.prototype);
46657
46800
  module.exports = req;
46658
46801
  req.get = req.header = function header(name) {
46659
46802
  if (!name) {
@@ -47189,7 +47332,7 @@ var require_send = __commonJS({
47189
47332
  var createError = require_http_errors();
47190
47333
  var debug = require_src()("send");
47191
47334
  var encodeUrl = require_encodeurl();
47192
- var escapeHtml2 = require_escape_html();
47335
+ var escapeHtml = require_escape_html();
47193
47336
  var etag = require_etag();
47194
47337
  var fresh = require_fresh();
47195
47338
  var fs6 = __require("fs");
@@ -47242,7 +47385,7 @@ var require_send = __commonJS({
47242
47385
  }
47243
47386
  var res = this.res;
47244
47387
  var msg = statuses.message[status] || String(status);
47245
- var doc = createHtmlDocument("Error", escapeHtml2(msg));
47388
+ var doc = createHtmlDocument("Error", escapeHtml(msg));
47246
47389
  clearHeaders(res);
47247
47390
  if (err && err.headers) {
47248
47391
  setHeaders(res, err.headers);
@@ -47342,7 +47485,7 @@ var require_send = __commonJS({
47342
47485
  return;
47343
47486
  }
47344
47487
  var loc = encodeUrl(collapseLeadingSlashes(this.path + "/"));
47345
- var doc = createHtmlDocument("Redirecting", "Redirecting to " + escapeHtml2(loc));
47488
+ var doc = createHtmlDocument("Redirecting", "Redirecting to " + escapeHtml(loc));
47346
47489
  res.statusCode = 301;
47347
47490
  res.setHeader("Content-Type", "text/html; charset=UTF-8");
47348
47491
  res.setHeader("Content-Length", Buffer.byteLength(doc));
@@ -47746,8 +47889,8 @@ var require_response = __commonJS({
47746
47889
  var createError = require_http_errors();
47747
47890
  var deprecate = require_depd()("express");
47748
47891
  var encodeUrl = require_encodeurl();
47749
- var escapeHtml2 = require_escape_html();
47750
- var http4 = __require("node:http");
47892
+ var escapeHtml = require_escape_html();
47893
+ var http2 = __require("node:http");
47751
47894
  var onFinished = require_on_finished();
47752
47895
  var mime = require_mime_types();
47753
47896
  var path13 = __require("node:path");
@@ -47763,7 +47906,7 @@ var require_response = __commonJS({
47763
47906
  var resolve5 = path13.resolve;
47764
47907
  var vary = require_vary();
47765
47908
  var { Buffer: Buffer5 } = __require("node:buffer");
47766
- var res = Object.create(http4.ServerResponse.prototype);
47909
+ var res = Object.create(http2.ServerResponse.prototype);
47767
47910
  module.exports = res;
47768
47911
  res.status = function status(code) {
47769
47912
  if (!Number.isInteger(code)) {
@@ -48085,7 +48228,7 @@ var require_response = __commonJS({
48085
48228
  body = statuses.message[status] + ". Redirecting to " + address;
48086
48229
  },
48087
48230
  html: function() {
48088
- var u2 = escapeHtml2(address);
48231
+ var u2 = escapeHtml(address);
48089
48232
  body = "<p>" + statuses.message[status] + ". Redirecting to " + u2 + "</p>";
48090
48233
  },
48091
48234
  default: function() {
@@ -48213,7 +48356,7 @@ var require_serve_static = __commonJS({
48213
48356
  "../../node_modules/serve-static/index.js"(exports, module) {
48214
48357
  "use strict";
48215
48358
  var encodeUrl = require_encodeurl();
48216
- var escapeHtml2 = require_escape_html();
48359
+ var escapeHtml = require_escape_html();
48217
48360
  var parseUrl = require_parseurl();
48218
48361
  var resolve5 = __require("path").resolve;
48219
48362
  var send = require_send();
@@ -48299,7 +48442,7 @@ var require_serve_static = __commonJS({
48299
48442
  originalUrl.path = null;
48300
48443
  originalUrl.pathname = collapseLeadingSlashes(originalUrl.pathname + "/");
48301
48444
  var loc = encodeUrl(url.format(originalUrl));
48302
- var doc = createHtmlDocument("Redirecting", "Redirecting to " + escapeHtml2(loc));
48445
+ var doc = createHtmlDocument("Redirecting", "Redirecting to " + escapeHtml(loc));
48303
48446
  res.statusCode = 301;
48304
48447
  res.setHeader("Content-Type", "text/html; charset=UTF-8");
48305
48448
  res.setHeader("Content-Length", Buffer.byteLength(doc));
@@ -70471,15 +70614,13 @@ function shouldRefreshInworld(s) {
70471
70614
  return exp - Date.now() < INWORLD_RENEW_MARGIN_MS;
70472
70615
  }
70473
70616
  async function currentRefreshToken(s, source) {
70474
- if (source.provider === "supabase") {
70475
- try {
70476
- const c3 = await readStoredCredentials();
70477
- const stored = c3 ? identitySourceOfStore(c3) : void 0;
70478
- if (c3?.refreshToken && stored?.authUrl === source.authUrl) {
70479
- return c3.refreshToken.trim();
70480
- }
70481
- } catch {
70617
+ try {
70618
+ const c3 = await readStoredCredentials();
70619
+ const stored = c3 ? identitySourceOfStore(c3) : null;
70620
+ if (c3?.refreshToken && stored?.authUrl === source.authUrl) {
70621
+ return c3.refreshToken.trim();
70482
70622
  }
70623
+ } catch {
70483
70624
  }
70484
70625
  return s.identityRefreshToken?.trim();
70485
70626
  }
@@ -70498,7 +70639,8 @@ async function getValidSession() {
70498
70639
  if (!needInworldRefresh && !needIdentityRefresh) {
70499
70640
  return s;
70500
70641
  }
70501
- const source = s.authProvider === "supabase" ? { provider: "supabase", authUrl: s.authUrl } : { provider: "firebase" };
70642
+ const source = identitySourceOfStore(s);
70643
+ if (!source) return null;
70502
70644
  const refresh = await currentRefreshToken(s, source);
70503
70645
  if (!refresh) {
70504
70646
  return isSessionActive(s) ? s : null;
@@ -70513,7 +70655,7 @@ async function getValidSession() {
70513
70655
  ...exchanged,
70514
70656
  identityToken: rt.idToken,
70515
70657
  identityRefreshToken: rt.refreshToken,
70516
- authProvider: source.provider,
70658
+ authProvider: "supabase",
70517
70659
  authUrl: source.authUrl,
70518
70660
  email: s.email
70519
70661
  };
@@ -70557,7 +70699,7 @@ function headersForIdentityToken(identityToken) {
70557
70699
  }
70558
70700
  return {
70559
70701
  Authorization: `Bearer ${identityToken}`,
70560
- [GRPC_BEARER_TYPE_METADATA]: bearerTypeFor(providerForToken(identityToken))
70702
+ [GRPC_BEARER_TYPE_METADATA]: IDENTITY_BEARER_TYPE
70561
70703
  };
70562
70704
  }
70563
70705
  var GRPC_BEARER_TYPE_METADATA;
@@ -70666,7 +70808,7 @@ async function inworldGatewayPostJson(path13, body) {
70666
70808
  var init_gateway_http = __esm({
70667
70809
  "src/mcp/inworld/gateway-http.ts"() {
70668
70810
  "use strict";
70669
- init_constants5();
70811
+ init_constants6();
70670
70812
  init_inworld_headers();
70671
70813
  init_session_refresh();
70672
70814
  }
@@ -70981,7 +71123,7 @@ async function fetchWorkspaceEngineSession(workspaceId) {
70981
71123
  const user = await getValidSession();
70982
71124
  if (!user) {
70983
71125
  throw new Error(
70984
- "Not signed in or session expired. Run: inworld-mcp login (bearer mode cannot use voice engine APIs without Firebase ID token)."
71126
+ "Not signed in or session expired. Run: inworld-mcp login (bearer mode cannot use voice engine APIs without an identity token)."
70985
71127
  );
70986
71128
  }
70987
71129
  const identityToken = user.identityToken;
@@ -71016,7 +71158,7 @@ async function fetchWorkspaceEngineSession(workspaceId) {
71016
71158
  if (!res.ok) {
71017
71159
  const msg = typeof data.message === "string" ? data.message : text.slice(0, 400);
71018
71160
  throw new Error(
71019
- `Could not obtain workspace engine session for ${parent} (${res.status}): ${msg}. If unauthorized, run \`inworld-mcp login\` (Firebase token may have expired).`
71161
+ `Could not obtain workspace engine session for ${parent} (${res.status}): ${msg}. If unauthorized, run \`inworld-mcp login\` (the sign-in may have expired).`
71020
71162
  );
71021
71163
  }
71022
71164
  return parseSession(data);
@@ -71024,7 +71166,7 @@ async function fetchWorkspaceEngineSession(workspaceId) {
71024
71166
  var init_engine_session = __esm({
71025
71167
  "src/mcp/voice/engine-session.ts"() {
71026
71168
  "use strict";
71027
- init_constants5();
71169
+ init_constants6();
71028
71170
  init_inworld_headers();
71029
71171
  init_session_refresh();
71030
71172
  init_gateway();
@@ -72201,130 +72343,6 @@ var init_schemas4 = __esm({
72201
72343
  }
72202
72344
  });
72203
72345
 
72204
- // src/mcp/auth/callback-server.ts
72205
- import * as http3 from "http";
72206
- async function createCallbackServer2(options = {}) {
72207
- const {
72208
- port = INWORLD_CLI_AUTH_CALLBACK_PORT2,
72209
- allowedOrigins = ["http://localhost:3001", "https://cli.inworld.ai"],
72210
- firebaseApiKey = FIREBASE_API_KEY2
72211
- } = options;
72212
- return new Promise((resolve5, reject) => {
72213
- const httpServer = http3.createServer({ keepAlive: false }, (req, res) => {
72214
- const origin = req.headers.origin;
72215
- if (origin && allowedOrigins.includes(origin)) {
72216
- res.setHeader("Access-Control-Allow-Origin", origin);
72217
- res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
72218
- res.setHeader("Access-Control-Allow-Headers", "Content-Type");
72219
- res.setHeader("Access-Control-Max-Age", "86400");
72220
- }
72221
- if (req.url?.startsWith("/callback") && req.method === "OPTIONS") {
72222
- res.writeHead(204);
72223
- res.end();
72224
- return;
72225
- }
72226
- if (req.url?.startsWith("/callback") && req.method === "POST") {
72227
- let body = "";
72228
- req.on("data", (chunk) => {
72229
- body += chunk.toString();
72230
- });
72231
- req.on("end", async () => {
72232
- try {
72233
- const data = JSON.parse(body);
72234
- console.error();
72235
- console.error("Received authentication data...");
72236
- const refreshToken = data.refreshToken;
72237
- const email2 = data.email;
72238
- console.error("Exchanging tokens...");
72239
- if (!firebaseApiKey) {
72240
- throw new Error(
72241
- "FIREBASE_API_KEY / INWORLD_FIREBASE_API_KEY is not set"
72242
- );
72243
- }
72244
- const tokenFetchResponse = await fetch(
72245
- `https://securetoken.googleapis.com/v1/token?key=${firebaseApiKey}`,
72246
- {
72247
- method: "POST",
72248
- body: new URLSearchParams({
72249
- grant_type: "refresh_token",
72250
- refresh_token: data.refreshToken
72251
- })
72252
- }
72253
- );
72254
- const tokenResponse = await tokenFetchResponse.json();
72255
- if (tokenResponse.error) {
72256
- throw new Error(
72257
- `Token exchange failed: ${tokenResponse.error.message}`
72258
- );
72259
- }
72260
- if (tokenResponse?.id_token) {
72261
- res.writeHead(200, { "Content-Type": "application/json" });
72262
- res.end(JSON.stringify({ success: true }));
72263
- resolve5({
72264
- server: httpServer,
72265
- token: tokenResponse.id_token,
72266
- refreshToken,
72267
- email: email2
72268
- });
72269
- } else {
72270
- res.writeHead(400, { "Content-Type": "application/json" });
72271
- res.end(JSON.stringify({ error: "No idToken provided" }));
72272
- }
72273
- } catch (error2) {
72274
- console.error("Callback processing error:");
72275
- console.error(error2);
72276
- res.writeHead(400, { "Content-Type": "application/json" });
72277
- res.end(
72278
- JSON.stringify({
72279
- error: error2 instanceof Error ? error2.message : "Invalid request"
72280
- })
72281
- );
72282
- if (error2 instanceof Error && error2.message.includes("JSON")) {
72283
- console.error(
72284
- "Invalid JSON received, waiting for valid callback..."
72285
- );
72286
- } else {
72287
- reject(error2);
72288
- }
72289
- }
72290
- });
72291
- req.on("error", (error2) => {
72292
- res.writeHead(500, { "Content-Type": "application/json" });
72293
- res.end(JSON.stringify({ error: "Server error" }));
72294
- reject(error2);
72295
- });
72296
- } else if (req.url?.startsWith("/callback")) {
72297
- res.writeHead(405, { "Content-Type": "application/json" });
72298
- res.end(JSON.stringify({ error: "Method not allowed. Use POST." }));
72299
- } else {
72300
- res.writeHead(404, { "Content-Type": "application/json" });
72301
- res.end(JSON.stringify({ error: "Not found" }));
72302
- }
72303
- });
72304
- httpServer.on("error", (error2) => {
72305
- reject(error2);
72306
- });
72307
- httpServer.listen(port, "localhost");
72308
- });
72309
- }
72310
- function stopCallbackServer2(server) {
72311
- return new Promise((resolve5, reject) => {
72312
- server.close((err) => {
72313
- if (err) {
72314
- reject(err);
72315
- } else {
72316
- resolve5();
72317
- }
72318
- });
72319
- });
72320
- }
72321
- var init_callback_server = __esm({
72322
- "src/mcp/auth/callback-server.ts"() {
72323
- "use strict";
72324
- init_constants5();
72325
- }
72326
- });
72327
-
72328
72346
  // src/mcp/cli/login.ts
72329
72347
  import * as readline5 from "node:readline";
72330
72348
  async function offerBrowser2(url, done) {
@@ -72359,38 +72377,22 @@ async function offerBrowser2(url, done) {
72359
72377
  console.error();
72360
72378
  console.error("Waiting for authentication...");
72361
72379
  }
72362
- async function signInWithFirebase2() {
72363
- const serverPromise = createCallbackServer2({
72364
- port: INWORLD_CLI_AUTH_CALLBACK_PORT2
72365
- });
72366
- await offerBrowser2(INWORLD_CLI_AUTH_URL2, serverPromise);
72367
- const result = await serverPromise;
72368
- await stopCallbackServer2(result.server);
72369
- return {
72370
- idToken: result.token,
72371
- refreshToken: result.refreshToken,
72372
- email: result.email
72373
- };
72374
- }
72375
72380
  async function runLogin() {
72376
72381
  const source = await resolveIdentitySource(PLATFORM_URL2);
72377
- let tokens;
72378
- if (source.provider === "supabase") {
72379
- const oauthProvider = process.env.INWORLD_AUTH_OAUTH_PROVIDER || "google";
72380
- if (!GOTRUE_OAUTH_PROVIDERS.includes(oauthProvider)) {
72381
- throw new Error(
72382
- `INWORLD_AUTH_OAUTH_PROVIDER=${oauthProvider} is not supported by inworld-mcp login (use ${GOTRUE_OAUTH_PROVIDERS.join(", ")}). ` + (oauthProvider === "email" ? "For email/password, run `inworld login --provider email`; the MCP server reuses that session." : "")
72383
- );
72384
- }
72385
- const { url, done } = await startOAuthSignIn({
72386
- authUrl: source.authUrl,
72387
- oauthProvider
72388
- });
72389
- await offerBrowser2(url, done);
72390
- tokens = await done;
72391
- } else {
72392
- tokens = await signInWithFirebase2();
72382
+ const oauthProvider = process.env.INWORLD_AUTH_OAUTH_PROVIDER || void 0;
72383
+ if (oauthProvider && !GOTRUE_OAUTH_PROVIDERS.includes(oauthProvider)) {
72384
+ throw new Error(
72385
+ `INWORLD_AUTH_OAUTH_PROVIDER=${oauthProvider} is not supported by inworld-mcp login (use ${GOTRUE_OAUTH_PROVIDERS.join(", ")}, or unset it to choose on the sign-in page).`
72386
+ );
72393
72387
  }
72388
+ const { url, done } = await startBrowserSignIn({
72389
+ authUrl: source.authUrl,
72390
+ pageUrl: INWORLD_CLI_AUTH_URL2,
72391
+ version: CLI_VERSION,
72392
+ oauthProvider
72393
+ });
72394
+ await offerBrowser2(url, done);
72395
+ const tokens = await done;
72394
72396
  console.error();
72395
72397
  console.error("Exchanging for Inworld session...");
72396
72398
  const exchanged = await exchangeIdentityToken(tokens.idToken);
@@ -72398,7 +72400,7 @@ async function runLogin() {
72398
72400
  ...exchanged,
72399
72401
  identityToken: tokens.idToken,
72400
72402
  identityRefreshToken: tokens.refreshToken,
72401
- authProvider: source.provider,
72403
+ authProvider: "supabase",
72402
72404
  authUrl: source.authUrl,
72403
72405
  email: tokens.email
72404
72406
  };
@@ -72410,7 +72412,7 @@ async function runLogin() {
72410
72412
  inworldToken: merged.token ?? "",
72411
72413
  expiresAt,
72412
72414
  env: INWORLD_ENV2,
72413
- authProvider: source.provider,
72415
+ authProvider: "supabase",
72414
72416
  authUrl: source.authUrl
72415
72417
  });
72416
72418
  console.error();
@@ -72425,9 +72427,9 @@ var init_login = __esm({
72425
72427
  "src/mcp/cli/login.ts"() {
72426
72428
  "use strict";
72427
72429
  init_dist4();
72428
- init_browser();
72429
- init_callback_server();
72430
72430
  init_constants5();
72431
+ init_browser();
72432
+ init_constants6();
72431
72433
  init_exchange();
72432
72434
  init_identity();
72433
72435
  init_paths();
@@ -72479,7 +72481,7 @@ function createMcpServer(modes) {
72479
72481
  server.registerTool(
72480
72482
  "inworld_auth_status",
72481
72483
  {
72482
- description: "Whether you are signed in to Inworld. Sessions auto-refresh when a Firebase refresh token is stored (re-login once if you only have an old session file).",
72484
+ description: "Whether you are signed in to Inworld. Sessions auto-refresh from the stored refresh token (sign in again if the saved login comes from a CLI before 1.4.0).",
72483
72485
  inputSchema: external_exports.object({})
72484
72486
  },
72485
72487
  async () => {
@@ -73445,7 +73447,7 @@ var init_mcp2 = __esm({
73445
73447
  init_streamableHttp();
73446
73448
  init_zod();
73447
73449
  init_bearer();
73448
- init_constants5();
73450
+ init_constants6();
73449
73451
  init_gate();
73450
73452
  init_request_session();
73451
73453
  init_session();
@@ -74350,122 +74352,12 @@ import { join as join3, resolve } from "path";
74350
74352
 
74351
74353
  // src/auth/manager.ts
74352
74354
  init_dist4();
74353
-
74354
- // package.json
74355
- var package_default = {
74356
- name: "@inworld/cli",
74357
- version: "1.3.1",
74358
- type: "module",
74359
- main: "dist/index.js",
74360
- bin: {
74361
- inworld: "dist/index.js",
74362
- "inworld-mcp": "dist/cli/inworld-mcp.js"
74363
- },
74364
- scripts: {
74365
- postversion: "npm install && git add ../../package-lock.json",
74366
- "copy:release-it-config": "node ../../scripts/copy-release-it-config.js",
74367
- clean: "shx rm -rf dist",
74368
- build: "npm run clean && node esbuild.config.js && npm run copy:release-it-config",
74369
- "build:tsc": "tsc --project tsconfig.json",
74370
- "build:types": "tsc --emitDeclarationOnly",
74371
- "build:all": "npm run build && npm run build:types",
74372
- prepublishOnly: "npm --prefix ../.. run build:all",
74373
- test: "vitest run",
74374
- "test:watch": "vitest",
74375
- "test:coverage": "vitest run --coverage",
74376
- start: "node dist/index.js",
74377
- dev: "tsx src/index.ts"
74378
- },
74379
- engines: {
74380
- node: ">=20.0.0"
74381
- },
74382
- files: [
74383
- "dist/index.js",
74384
- "dist/cli/inworld-mcp.js"
74385
- ],
74386
- author: "Inworld AI",
74387
- license: "MIT",
74388
- description: "Inworld CLI: auth, workspace, TTS, and MCP server entry point.",
74389
- repository: {
74390
- type: "git",
74391
- url: "git+https://github.com/inworld-ai/inworld-cli.git",
74392
- directory: "packages/cli"
74393
- },
74394
- devDependencies: {
74395
- "@inworld/auth-store": "0.1.0",
74396
- "@modelcontextprotocol/sdk": "^1.29.0",
74397
- "@tsconfig/node-lts": "^22.0.2",
74398
- "@types/adm-zip": "^0.5.8",
74399
- "@types/express": "^5.0.3",
74400
- "@types/ffmpeg-static": "^3.0.3",
74401
- "@types/ffprobe-static": "^2.0.3",
74402
- "@types/keytar": "^4.4.0",
74403
- "@types/node": "^24.1.0",
74404
- "@types/ora": "^3.1.0",
74405
- "@types/semver": "^7.5.8",
74406
- "@types/ws": "^8.18.1",
74407
- "@vitest/coverage-v8": "^4.1.0",
74408
- chalk: "^5.3.0",
74409
- commander: "^12.0.0",
74410
- conf: "^14.0.0",
74411
- esbuild: "^0.25.10",
74412
- execa: "^9.5.1",
74413
- "jwt-decode": "^4.0.0",
74414
- mixpanel: "^0.18.1",
74415
- ora: "^8.2.0",
74416
- "play-sound": "^1.1.6",
74417
- semver: "^7.6.3",
74418
- tsx: "^4.20.5",
74419
- typescript: "^5.8.3",
74420
- vitest: "^4.1.0",
74421
- zod: "^3.24.2"
74422
- },
74423
- dependencies: {
74424
- "@zowe/secrets-for-zowe-sdk": "^8.27.0",
74425
- "adm-zip": "^0.5.17",
74426
- ws: "^8.21.0"
74427
- },
74428
- optionalDependencies: {
74429
- "ffmpeg-static": "^5.3.0",
74430
- "ffprobe-static": "^3.1.0"
74431
- }
74432
- };
74433
-
74434
- // src/constants.ts
74435
- var DEFAULT_PLATFORM_ENDPOINT = "https://platform.inworld.ai";
74436
- var resolvePlatformUrl = () => {
74437
- if (process.env.INWORLD_PLATFORM_URL) {
74438
- return process.env.INWORLD_PLATFORM_URL;
74439
- }
74440
- const env3 = (process.env.INWORLD_ENV || "").toUpperCase();
74441
- switch (env3) {
74442
- case "DEV":
74443
- return "https://platform.dev.inworld.ai";
74444
- case "STAGE":
74445
- return "https://platform.stage.inworld.ai";
74446
- case "PROD":
74447
- return "https://platform.inworld.ai";
74448
- default:
74449
- return DEFAULT_PLATFORM_ENDPOINT;
74450
- }
74451
- };
74452
- var INWORLD_ENV = process.env.INWORLD_ENV || "PROD";
74453
- var WORKSPACES_LIST_SIZE = 100;
74454
- var PLATFORM_URL = resolvePlatformUrl();
74455
- var FIREBASE_API_KEY = process.env.INWORLD_FIREBASE_API_KEY || "AIzaSyAPVBLVid0xPwjuU4Gmn_6_GyqxBq-SwQs";
74456
- var INWORLD_CLI_AUTH_URL = process.env.INWORLD_CLI_AUTH_URL || "https://cli.inworld.ai/login";
74457
- var INWORLD_CLI_AUTH_CALLBACK_PORT = parseInt(
74458
- process.env.INWORLD_CLI_AUTH_CALLBACK_PORT || "8085",
74459
- 10
74460
- );
74461
- var MIXPANEL_TOKEN = process.env.INWORLD_MIXPANEL_TOKEN || "2cf13116e9701343ac27ddc452adfbbc";
74462
- var CLI_VERSION = package_default.version;
74463
-
74464
- // src/auth/manager.ts
74355
+ init_constants5();
74465
74356
  init_cli_store_bridge();
74466
74357
  init_identity();
74467
74358
 
74468
74359
  // src/utils/ui.ts
74360
+ init_constants5();
74469
74361
  function printHeader(message) {
74470
74362
  console.log(source_default.bold(message));
74471
74363
  }
@@ -74781,20 +74673,19 @@ var AuthManager = class {
74781
74673
  return true;
74782
74674
  }
74783
74675
  /**
74784
- * Generates an Inworld token from a Firebase ID token or GoTrue access token
74676
+ * Generates an Inworld token from a GoTrue access token
74785
74677
  */
74786
74678
  async generateInworldToken(identityToken) {
74787
- const provider = providerForToken(identityToken);
74788
74679
  try {
74789
74680
  const tokenResponse = await Users.GenerateTokenUser(
74790
74681
  {
74791
- type: AuthType[authTypeFor(provider)],
74682
+ type: AuthType[IDENTITY_AUTH_TYPE],
74792
74683
  token: identityToken
74793
74684
  },
74794
74685
  {
74795
74686
  headers: {
74796
74687
  Authorization: `Bearer ${identityToken}`,
74797
- [BEARER_TYPE_HEADER]: bearerTypeFor(provider)
74688
+ [BEARER_TYPE_HEADER]: IDENTITY_BEARER_TYPE
74798
74689
  },
74799
74690
  pathPrefix: PLATFORM_URL
74800
74691
  }
@@ -74820,9 +74711,14 @@ var AuthManager = class {
74820
74711
  if (!credentials || !credentials.refreshToken) {
74821
74712
  return null;
74822
74713
  }
74714
+ const source = identitySourceOfStore(credentials);
74715
+ if (!source) {
74716
+ printError(LEGACY_SIGN_IN_MESSAGE);
74717
+ return null;
74718
+ }
74823
74719
  try {
74824
74720
  const refreshed = await refreshIdentityToken(
74825
- identitySourceOfStore(credentials),
74721
+ source,
74826
74722
  credentials.refreshToken
74827
74723
  );
74828
74724
  const stillSignedIn = await persistRotatedRefreshToken(
@@ -74858,15 +74754,15 @@ var AuthManager = class {
74858
74754
  return await this.refreshToken();
74859
74755
  }
74860
74756
  /**
74861
- * Authenticates and saves credentials from a Firebase ID token or GoTrue
74862
- * access token. `source` is the configured deployment's identity stack; it,
74863
- * not the token's own unverified issuer, decides where refreshes go.
74757
+ * Authenticates and saves credentials from a GoTrue access token. `source`
74758
+ * is the configured deployment's GoTrue; it, not the token's own unverified
74759
+ * issuer, decides where refreshes go.
74864
74760
  */
74865
74761
  async authenticateAndSaveCredentials(identityToken, refreshToken, email2, source, workspace, env3) {
74866
74762
  try {
74867
74763
  if (!isIssuedBy(identityToken, source)) {
74868
74764
  printError(
74869
- source.provider === "supabase" ? `Token was not issued by this deployment's auth server (${source.authUrl})` : "Token is not a Firebase token, but this deployment uses Firebase auth"
74765
+ `Token was not issued by this deployment's auth server (${source.authUrl})`
74870
74766
  );
74871
74767
  return false;
74872
74768
  }
@@ -74883,7 +74779,7 @@ var AuthManager = class {
74883
74779
  workspace,
74884
74780
  expiresAt,
74885
74781
  env: env3,
74886
- authProvider: source.provider,
74782
+ authProvider: "supabase",
74887
74783
  authUrl: source.authUrl
74888
74784
  };
74889
74785
  await this.saveCredentials(credentials);
@@ -74910,6 +74806,10 @@ var AuthManager = class {
74910
74806
  */
74911
74807
  async isAuthenticated() {
74912
74808
  const credentials = await this.getCredentials();
74809
+ if (credentials?.refreshToken && !identitySourceOfStore(credentials)) {
74810
+ print(LEGACY_SIGN_IN_MESSAGE);
74811
+ return false;
74812
+ }
74913
74813
  if (credentials?.env && credentials?.env !== INWORLD_ENV) {
74914
74814
  print(
74915
74815
  `Warning: Currently saved credentials might not match current Inworld CLI environment.
@@ -74925,6 +74825,28 @@ You can run "inworld login --force" to login with the correct environment.`
74925
74825
  };
74926
74826
  var authManager = new AuthManager();
74927
74827
 
74828
+ // src/auth/utils.ts
74829
+ init_constants5();
74830
+
74831
+ // src/utils/client_info.ts
74832
+ init_constants5();
74833
+ var CLIENT_INFO_HEADER = "x-user-agent";
74834
+ var OS_NAMES = {
74835
+ darwin: "macos",
74836
+ win32: "windows"
74837
+ };
74838
+ var buildClientInfo = ({
74839
+ version: version3 = CLI_VERSION,
74840
+ platform: platform2 = process.platform,
74841
+ nodeVersion = process.versions.node
74842
+ } = {}) => [
74843
+ "sdk/cli",
74844
+ `sdk-version/${version3}`,
74845
+ `os/${OS_NAMES[platform2] ?? platform2}`,
74846
+ `runtime/node-${nodeVersion.split(".")[0]}`
74847
+ ].join(" ");
74848
+ var CLIENT_INFO = buildClientInfo();
74849
+
74928
74850
  // src/auth/utils.ts
74929
74851
  async function requireAuth() {
74930
74852
  const isAuthenticated = await authManager.isAuthenticated();
@@ -74974,7 +74896,8 @@ var authenticatedInworldRequest = async (pb, req, inworldToken, signal) => {
74974
74896
  ...{
74975
74897
  headers: {
74976
74898
  Authorization: `Bearer ${inworldToken}`,
74977
- "Grpc-Metadata-X-Authorization-Bearer-Type": "inworld"
74899
+ "Grpc-Metadata-X-Authorization-Bearer-Type": "inworld",
74900
+ [CLIENT_INFO_HEADER]: CLIENT_INFO
74978
74901
  }
74979
74902
  },
74980
74903
  pathPrefix: PLATFORM_URL,
@@ -74984,6 +74907,9 @@ var authenticatedInworldRequest = async (pb, req, inworldToken, signal) => {
74984
74907
  }
74985
74908
  };
74986
74909
 
74910
+ // src/services/tts_service.ts
74911
+ init_constants5();
74912
+
74987
74913
  // src/utils/resource_name_helper.ts
74988
74914
  var parseWorkspaceResourceName = (resourceName) => {
74989
74915
  const [collection, workspaceId] = resourceName.split("/");
@@ -75045,6 +74971,7 @@ var TTSService = class {
75045
74971
  headers: {
75046
74972
  Authorization: `Basic ${apiKey}`,
75047
74973
  "Content-Type": "application/json",
74974
+ [CLIENT_INFO_HEADER]: CLIENT_INFO,
75048
74975
  ...options.headers
75049
74976
  }
75050
74977
  });
@@ -75153,7 +75080,8 @@ or "inworld ws add-key --write" to create a new one with read/write access.`
75153
75080
  headers: {
75154
75081
  Authorization: `Basic ${apiKey}`,
75155
75082
  "Content-Type": "application/json",
75156
- Connection: "keep-alive"
75083
+ Connection: "keep-alive",
75084
+ [CLIENT_INFO_HEADER]: CLIENT_INFO
75157
75085
  },
75158
75086
  body: JSON.stringify(request)
75159
75087
  });
@@ -75308,6 +75236,7 @@ var ttsService = new TTSService();
75308
75236
 
75309
75237
  // src/services/tts_websocket.ts
75310
75238
  import WebSocket from "ws";
75239
+ init_constants5();
75311
75240
 
75312
75241
  // src/utils/wav.ts
75313
75242
  function wavDataOffset(buf) {
@@ -75391,7 +75320,8 @@ var TtsSession = class _TtsSession {
75391
75320
  const url = `${wsBase}/tts/v1/voice:streamBidirectional`;
75392
75321
  dlog("open", `connecting to ${url} (auth=${credential.scheme})`);
75393
75322
  const headers = {
75394
- authorization: `${credential.scheme} ${credential.token}`
75323
+ authorization: `${credential.scheme} ${credential.token}`,
75324
+ [CLIENT_INFO_HEADER]: CLIENT_INFO
75395
75325
  };
75396
75326
  if (credential.scheme === "Bearer") {
75397
75327
  headers["grpc-metadata-x-authorization-bearer-type"] = "inworld";
@@ -83737,132 +83667,13 @@ var audiobookCommand = new Command("audiobook").description("Audiobook generatio
83737
83667
 
83738
83668
  // src/commands/auth/login_command.ts
83739
83669
  import * as readline4 from "readline";
83740
-
83741
- // src/auth/callback_server.ts
83742
- import * as http2 from "http";
83743
- async function createCallbackServer(options = {}) {
83744
- const {
83745
- port = 8085,
83746
- allowedOrigins = ["http://localhost:3001", "https://cli.inworld.ai"],
83747
- firebaseApiKey = FIREBASE_API_KEY
83748
- } = options;
83749
- return new Promise((resolve5, reject) => {
83750
- const httpServer = http2.createServer(
83751
- {
83752
- keepAlive: false
83753
- },
83754
- (req, res) => {
83755
- const origin = req.headers.origin;
83756
- if (origin && allowedOrigins.includes(origin)) {
83757
- res.setHeader("Access-Control-Allow-Origin", origin);
83758
- res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
83759
- res.setHeader("Access-Control-Allow-Headers", "Content-Type");
83760
- res.setHeader("Access-Control-Max-Age", "86400");
83761
- }
83762
- if (req.url?.startsWith("/callback") && req.method === "OPTIONS") {
83763
- res.writeHead(204);
83764
- res.end();
83765
- return;
83766
- }
83767
- if (req.url?.startsWith("/callback") && req.method === "POST") {
83768
- let body = "";
83769
- req.on("data", (chunk) => {
83770
- body += chunk.toString();
83771
- });
83772
- req.on("end", async () => {
83773
- try {
83774
- const data = JSON.parse(body);
83775
- console.log();
83776
- print("Received authentication data...");
83777
- const refreshToken = data.refreshToken;
83778
- const email2 = data.email;
83779
- print("Exchanging tokens...");
83780
- if (!firebaseApiKey) {
83781
- throw new Error("FIREBASE_API_KEY is not set");
83782
- }
83783
- const tokenFetchResponse = await fetch(
83784
- `https://securetoken.googleapis.com/v1/token?key=${firebaseApiKey}`,
83785
- {
83786
- method: "POST",
83787
- body: new URLSearchParams({
83788
- grant_type: "refresh_token",
83789
- refresh_token: data.refreshToken
83790
- })
83791
- }
83792
- );
83793
- const tokenResponse = await tokenFetchResponse.json();
83794
- if (tokenResponse.error) {
83795
- throw new Error(
83796
- `Token exchange failed: ${tokenResponse.error.message}`
83797
- );
83798
- }
83799
- if (tokenResponse?.id_token) {
83800
- res.writeHead(200, { "Content-Type": "application/json" });
83801
- res.end(JSON.stringify({ success: true }));
83802
- resolve5({
83803
- server: httpServer,
83804
- token: tokenResponse.id_token,
83805
- refreshToken,
83806
- email: email2
83807
- });
83808
- } else {
83809
- res.writeHead(400, { "Content-Type": "application/json" });
83810
- res.end(JSON.stringify({ error: "No idToken provided" }));
83811
- }
83812
- } catch (error2) {
83813
- printError("Callback processing error:");
83814
- console.error(error2);
83815
- res.writeHead(400, { "Content-Type": "application/json" });
83816
- res.end(
83817
- JSON.stringify({
83818
- error: error2 instanceof Error ? error2.message : "Invalid request"
83819
- })
83820
- );
83821
- if (error2 instanceof Error && error2.message.includes("JSON")) {
83822
- print(
83823
- "Invalid JSON received, waiting for valid callback..."
83824
- );
83825
- } else {
83826
- reject(error2);
83827
- }
83828
- }
83829
- });
83830
- req.on("error", (error2) => {
83831
- res.writeHead(500, { "Content-Type": "application/json" });
83832
- res.end(JSON.stringify({ error: "Server error" }));
83833
- reject(error2);
83834
- });
83835
- } else if (req.url?.startsWith("/callback")) {
83836
- res.writeHead(405, { "Content-Type": "application/json" });
83837
- res.end(JSON.stringify({ error: "Method not allowed. Use POST." }));
83838
- } else {
83839
- res.writeHead(404, { "Content-Type": "application/json" });
83840
- res.end(JSON.stringify({ error: "Not found" }));
83841
- }
83842
- }
83843
- );
83844
- httpServer.on("error", (error2) => {
83845
- reject(error2);
83846
- });
83847
- httpServer.listen(port, "localhost");
83848
- });
83849
- }
83850
- function stopCallbackServer(server) {
83851
- return new Promise((resolve5, reject) => {
83852
- server.close((err) => {
83853
- if (err) {
83854
- reject(err);
83855
- } else {
83856
- resolve5();
83857
- }
83858
- });
83859
- });
83860
- }
83861
-
83862
- // src/commands/auth/login_command.ts
83670
+ init_constants5();
83863
83671
  init_browser();
83864
83672
  init_identity();
83865
83673
 
83674
+ // src/services/workspace_service.ts
83675
+ init_constants5();
83676
+
83866
83677
  // proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.ts
83867
83678
  var ApiKeys = class {
83868
83679
  static ListApiKeys(req, initReq) {
@@ -84465,28 +84276,16 @@ var ask = (question, hidden2 = false) => new Promise((resolve5) => {
84465
84276
  resolve5(answer.trim());
84466
84277
  });
84467
84278
  });
84468
- var signInWithFirebase = async () => {
84469
- const serverPromise = createCallbackServer({
84470
- port: INWORLD_CLI_AUTH_CALLBACK_PORT
84471
- });
84472
- await offerBrowser(INWORLD_CLI_AUTH_URL, serverPromise);
84473
- const result = await serverPromise;
84474
- await stopCallbackServer(result.server);
84475
- return {
84476
- idToken: result.token,
84477
- refreshToken: result.refreshToken,
84478
- email: result.email
84479
- };
84480
- };
84481
- var signInWithSupabase = async (source, provider) => {
84482
- const authUrl = source.authUrl;
84279
+ var signIn = async (source, provider) => {
84483
84280
  if (provider === "email") {
84484
84281
  const email2 = await ask("Email: ");
84485
84282
  const password = await ask("Password: ", true);
84486
- return signInWithPassword(authUrl, email2, password);
84283
+ return signInWithPassword(source.authUrl, email2, password);
84487
84284
  }
84488
- const { url, done } = await startOAuthSignIn({
84489
- authUrl,
84285
+ const { url, done } = await startBrowserSignIn({
84286
+ authUrl: source.authUrl,
84287
+ pageUrl: INWORLD_CLI_AUTH_URL,
84288
+ version: CLI_VERSION,
84490
84289
  oauthProvider: provider
84491
84290
  });
84492
84291
  await offerBrowser(url, done);
@@ -84525,7 +84324,7 @@ var loginAction = async (options) => {
84525
84324
  console.log();
84526
84325
  }
84527
84326
  const source = await resolveIdentitySource(PLATFORM_URL);
84528
- const tokens = source.provider === "supabase" ? await signInWithSupabase(source, options.provider) : await signInWithFirebase();
84327
+ const tokens = await signIn(source, options.provider);
84529
84328
  console.log();
84530
84329
  success("\u2713 Authentication successful!");
84531
84330
  console.log();
@@ -84568,8 +84367,8 @@ var makeLoginCommand = (description) => {
84568
84367
  return new Command("login").description(description).option("-f, --force", "Force re-authentication even if already logged in").addOption(
84569
84368
  new Option(
84570
84369
  "-p, --provider <provider>",
84571
- "Sign-in method on Supabase-auth deployments (ignored on Firebase ones)"
84572
- ).choices([...GOTRUE_OAUTH_PROVIDERS, "email"]).default(process.env.INWORLD_AUTH_OAUTH_PROVIDER || "google")
84370
+ "Skip the sign-in page: go straight to one OAuth provider, or sign in with email and password in the terminal"
84371
+ ).choices([...GOTRUE_OAUTH_PROVIDERS, "email"]).default(process.env.INWORLD_AUTH_OAUTH_PROVIDER || void 0)
84573
84372
  ).action(loginAction);
84574
84373
  };
84575
84374
  var loginCommand = makeLoginCommand(
@@ -84580,7 +84379,6 @@ var loginCommandAlias = makeLoginCommand(
84580
84379
  );
84581
84380
 
84582
84381
  // src/commands/auth/logout_command.ts
84583
- init_cli_store_bridge();
84584
84382
  init_identity();
84585
84383
 
84586
84384
  // src/utils/mcp_session_file.ts
@@ -84600,13 +84398,13 @@ function clearMcpSessionFileIfPresent() {
84600
84398
  // src/commands/auth/logout_command.ts
84601
84399
  var logoutAction = async (options) => {
84602
84400
  try {
84603
- const isAuthenticated = await authManager.isAuthenticated();
84604
- if (!isAuthenticated) {
84401
+ const credentials = await authManager.getCredentials();
84402
+ if (!credentials?.refreshToken) {
84605
84403
  print("You are not currently authenticated.");
84606
84404
  process.exit(0);
84607
84405
  }
84608
- const credentials = await authManager.getCredentials();
84609
- const email2 = credentials?.email || "Unknown user";
84406
+ const email2 = credentials.email || "Unknown user";
84407
+ const source = identitySourceOfStore(credentials);
84610
84408
  console.log();
84611
84409
  printHeader("\u{1F3AD} Inworld CLI - Logout");
84612
84410
  print(`Current account: ${email2}`);
@@ -84622,13 +84420,10 @@ var logoutAction = async (options) => {
84622
84420
  }
84623
84421
  }
84624
84422
  console.log();
84625
- if (credentials?.authProvider === "supabase" && credentials.refreshToken) {
84423
+ if (source) {
84626
84424
  print("Ending the session on the server...");
84627
84425
  try {
84628
- await revokeSession(
84629
- identitySourceOfStore(credentials),
84630
- credentials.refreshToken
84631
- );
84426
+ await revokeSession(source, credentials.refreshToken);
84632
84427
  success("\u2713 Session ended.");
84633
84428
  } catch (error2) {
84634
84429
  print(
@@ -84739,6 +84534,7 @@ var statusCommandAlias = makeStatusCommand(
84739
84534
  // src/services/analytics.ts
84740
84535
  init_source();
84741
84536
  var import_mixpanel = __toESM(require_mixpanel_node(), 1);
84537
+ init_constants5();
84742
84538
  var Analytics = class _Analytics {
84743
84539
  static CONF_ENTRY_NAME = "analytics";
84744
84540
  conf;
@@ -84895,6 +84691,7 @@ var enableTelemetryAction = async () => {
84895
84691
  var enableTelemetryCommand = new Command("enable_cli_telemetry").description("Enable anonymous CLI usage analytics").action(enableTelemetryAction);
84896
84692
 
84897
84693
  // src/commands/auth/login_ci_command.ts
84694
+ init_constants5();
84898
84695
  init_identity();
84899
84696
  var loginCiAction = async (options) => {
84900
84697
  try {
@@ -84930,11 +84727,8 @@ var loginCiAction = async (options) => {
84930
84727
  }
84931
84728
  };
84932
84729
  var loginCiCommand = new Command("login-ci").description(
84933
- "Authenticate using a Firebase ID token or Supabase access token (for CI/testing)"
84934
- ).requiredOption(
84935
- "-t, --token <token>",
84936
- "Firebase ID token or Supabase (GoTrue) access token"
84937
- ).requiredOption("-e, --email <email>", "Email address").option(
84730
+ "Authenticate using a Supabase (GoTrue) access token (for CI/testing)"
84731
+ ).requiredOption("-t, --token <token>", "Supabase (GoTrue) access token").requiredOption("-e, --email <email>", "Email address").option(
84938
84732
  "-r, --refresh-token <refreshToken>",
84939
84733
  "Matching refresh token (optional, enables token refresh)"
84940
84734
  ).action(loginCiAction);
@@ -84979,6 +84773,7 @@ var authCommand = new Command("auth").description("Manage Inworld authentication
84979
84773
  });
84980
84774
 
84981
84775
  // src/services/llm_service.ts
84776
+ init_constants5();
84982
84777
  var LLMService = class {
84983
84778
  apiKey = null;
84984
84779
  async ensureApiKey() {
@@ -84995,6 +84790,7 @@ var LLMService = class {
84995
84790
  headers: {
84996
84791
  Authorization: `Basic ${apiKey}`,
84997
84792
  Accept: "application/json",
84793
+ [CLIENT_INFO_HEADER]: CLIENT_INFO,
84998
84794
  ...init.body ? { "Content-Type": "application/json" } : {},
84999
84795
  ...init.headers
85000
84796
  }
@@ -85226,6 +85022,7 @@ var mcpCommand = new Command("mcp").description(
85226
85022
  import { readFile as readFile5 } from "fs/promises";
85227
85023
 
85228
85024
  // src/services/stt_service.ts
85025
+ init_constants5();
85229
85026
  var STT_MODELS = {
85230
85027
  INWORLD_STT_1: "inworld/inworld-stt-1",
85231
85028
  GROQ_WHISPER_LARGE_V3: "groq/whisper-large-v3"
@@ -85259,7 +85056,8 @@ var STTService = class {
85259
85056
  method: "POST",
85260
85057
  headers: {
85261
85058
  Authorization: `Basic ${apiKey}`,
85262
- "Content-Type": "application/json"
85059
+ "Content-Type": "application/json",
85060
+ [CLIENT_INFO_HEADER]: CLIENT_INFO
85263
85061
  },
85264
85062
  body: JSON.stringify(body)
85265
85063
  });
@@ -86233,9 +86031,13 @@ var workspaceCommand = new Command("workspace").description("Manage Inworld work
86233
86031
  workspaceCommand.help();
86234
86032
  });
86235
86033
 
86034
+ // src/index.ts
86035
+ init_constants5();
86036
+
86236
86037
  // src/services/update_checker.ts
86237
86038
  init_source();
86238
86039
  var semver2 = __toESM(require_semver2(), 1);
86040
+ init_constants5();
86239
86041
  var UpdateChecker = class _UpdateChecker {
86240
86042
  static PACKAGE_NAME = "@inworld/cli";
86241
86043
  static CHECK_INTERVAL = 24 * 60 * 60 * 1e3;