@inworld/cli 2.0.0 → 2.1.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
@@ -3374,7 +3374,7 @@ var init_retryify_async = __esm({
3374
3374
  throw error2;
3375
3375
  const delay = Math.round(interval * Math.random());
3376
3376
  if (delay > 0) {
3377
- const delayPromise = new Promise((resolve5) => setTimeout(resolve5, delay));
3377
+ const delayPromise = new Promise((resolve6) => setTimeout(resolve6, delay));
3378
3378
  return delayPromise.then(() => attempt.apply(void 0, args));
3379
3379
  } else {
3380
3380
  return attempt.apply(void 0, args);
@@ -6766,7 +6766,7 @@ var require_compile = __commonJS({
6766
6766
  const schOrFunc = root.refs[ref];
6767
6767
  if (schOrFunc)
6768
6768
  return schOrFunc;
6769
- let _sch = resolve5.call(this, root, ref);
6769
+ let _sch = resolve6.call(this, root, ref);
6770
6770
  if (_sch === void 0) {
6771
6771
  const schema = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
6772
6772
  const { schemaId } = this.opts;
@@ -6793,7 +6793,7 @@ var require_compile = __commonJS({
6793
6793
  function sameSchemaEnv(s1, s2) {
6794
6794
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
6795
6795
  }
6796
- function resolve5(root, ref) {
6796
+ function resolve6(root, ref) {
6797
6797
  let sch;
6798
6798
  while (typeof (sch = this.refs[ref]) == "string")
6799
6799
  ref = sch;
@@ -7368,7 +7368,7 @@ var require_fast_uri = __commonJS({
7368
7368
  }
7369
7369
  return uri;
7370
7370
  }
7371
- function resolve5(baseURI, relativeURI, options) {
7371
+ function resolve6(baseURI, relativeURI, options) {
7372
7372
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
7373
7373
  const resolved = resolveComponent(parse3(baseURI, schemelessOptions), parse3(relativeURI, schemelessOptions), schemelessOptions, true);
7374
7374
  schemelessOptions.skipEscape = true;
@@ -7595,7 +7595,7 @@ var require_fast_uri = __commonJS({
7595
7595
  var fastUri = {
7596
7596
  SCHEMES,
7597
7597
  normalize,
7598
- resolve: resolve5,
7598
+ resolve: resolve6,
7599
7599
  resolveComponent,
7600
7600
  equal,
7601
7601
  serialize: serialize2,
@@ -13961,7 +13961,7 @@ var require_compile2 = __commonJS({
13961
13961
  const schOrFunc = root.refs[ref];
13962
13962
  if (schOrFunc)
13963
13963
  return schOrFunc;
13964
- let _sch = resolve5.call(this, root, ref);
13964
+ let _sch = resolve6.call(this, root, ref);
13965
13965
  if (_sch === void 0) {
13966
13966
  const schema = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
13967
13967
  const { schemaId } = this.opts;
@@ -13988,7 +13988,7 @@ var require_compile2 = __commonJS({
13988
13988
  function sameSchemaEnv(s1, s2) {
13989
13989
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
13990
13990
  }
13991
- function resolve5(root, ref) {
13991
+ function resolve6(root, ref) {
13992
13992
  let sch;
13993
13993
  while (typeof (sch = this.refs[ref]) == "string")
13994
13994
  ref = sch;
@@ -19583,7 +19583,7 @@ async function withCredentialsLock(work) {
19583
19583
  `The credential store is busy: another Inworld process holds ${lockPath}. Try again.`
19584
19584
  );
19585
19585
  }
19586
- await new Promise((resolve5) => setTimeout(resolve5, LOCK_RETRY_MS));
19586
+ await new Promise((resolve6) => setTimeout(resolve6, LOCK_RETRY_MS));
19587
19587
  }
19588
19588
  try {
19589
19589
  return await work();
@@ -19724,7 +19724,7 @@ var init_package = __esm({
19724
19724
  "package.json"() {
19725
19725
  package_default = {
19726
19726
  name: "@inworld/cli",
19727
- version: "2.0.0",
19727
+ version: "2.1.0",
19728
19728
  type: "module",
19729
19729
  main: "dist/index.js",
19730
19730
  bin: {
@@ -19957,7 +19957,7 @@ function gotrueErrorMessage(data, fallback) {
19957
19957
  }
19958
19958
  return fallback;
19959
19959
  }
19960
- async function gotrueToken(authUrl, grantType, body) {
19960
+ async function gotrueToken(authUrl, grantType, body, signal) {
19961
19961
  const url = `${authUrl}/token?grant_type=${grantType}`;
19962
19962
  const res = await fetch(url, {
19963
19963
  method: "POST",
@@ -19965,7 +19965,8 @@ async function gotrueToken(authUrl, grantType, body) {
19965
19965
  "Content-Type": "application/json",
19966
19966
  [CLIENT_INFO_HEADER]: CLIENT_INFO
19967
19967
  },
19968
- body: JSON.stringify(body)
19968
+ body: JSON.stringify(body),
19969
+ signal
19969
19970
  });
19970
19971
  const text = await res.text();
19971
19972
  let data = {};
@@ -20042,7 +20043,7 @@ function sameSecret(a2, b) {
20042
20043
  return x.length === y.length && timingSafeEqual(x, y);
20043
20044
  }
20044
20045
  function readForm(req) {
20045
- return new Promise((resolve5, reject) => {
20046
+ return new Promise((resolve6, reject) => {
20046
20047
  let size = 0;
20047
20048
  const chunks = [];
20048
20049
  req.on("data", (chunk) => {
@@ -20056,7 +20057,7 @@ function readForm(req) {
20056
20057
  });
20057
20058
  req.on(
20058
20059
  "end",
20059
- () => resolve5(new URLSearchParams(Buffer.concat(chunks).toString("utf8")))
20060
+ () => resolve6(new URLSearchParams(Buffer.concat(chunks).toString("utf8")))
20060
20061
  );
20061
20062
  req.on("error", reject);
20062
20063
  });
@@ -20076,27 +20077,59 @@ async function startLoopbackReceiver(options) {
20076
20077
  const state = base64url(randomBytes(32));
20077
20078
  const pageOrigin = new URL(options.pageUrl).origin;
20078
20079
  let settle;
20079
- const done = new Promise((resolve5, reject) => {
20080
- settle = { resolve: resolve5, reject };
20080
+ const done = new Promise((resolve6, reject) => {
20081
+ settle = { resolve: resolve6, reject };
20081
20082
  });
20082
20083
  let claimed = false;
20083
- const finish = (res, status, redeem) => {
20084
+ let ended = false;
20085
+ let failure;
20086
+ const redemption = new AbortController();
20087
+ const end = (outcome) => {
20088
+ if (ended) return false;
20089
+ ended = true;
20084
20090
  claimed = true;
20085
- redeem().then(
20091
+ if (outcome instanceof Error) {
20092
+ failure = outcome;
20093
+ redemption.abort();
20094
+ settle.reject(outcome);
20095
+ } else {
20096
+ settle.resolve(outcome);
20097
+ }
20098
+ return true;
20099
+ };
20100
+ const finish = (redeem, answer = () => {
20101
+ }) => {
20102
+ claimed = true;
20103
+ redeem(redemption.signal).then(
20104
+ // A result after cancel or the timeout is dropped. Ending closes the
20105
+ // listener first, so a browser still waiting gets no result page: its
20106
+ // connection is reset, and `answer` finds it gone.
20086
20107
  (tokens) => {
20087
- res.writeHead(status, { Location: signInResultUrl(options.pageUrl) });
20088
- res.end();
20089
- settle.resolve(tokens);
20108
+ end(tokens);
20109
+ answer(signInResultUrl(options.pageUrl, failure?.message));
20090
20110
  },
20091
20111
  (error2) => {
20092
- res.writeHead(status, {
20093
- Location: signInResultUrl(options.pageUrl, error2.message)
20094
- });
20095
- res.end();
20096
- settle.reject(error2);
20112
+ end(error2);
20113
+ answer(signInResultUrl(options.pageUrl, failure?.message));
20097
20114
  }
20098
20115
  );
20099
20116
  };
20117
+ const answerWith = (res, status) => {
20118
+ return (location) => {
20119
+ if (res.headersSent || res.destroyed) return;
20120
+ res.writeHead(status, { Location: location });
20121
+ res.end();
20122
+ };
20123
+ };
20124
+ const redeemRedirect = (params) => {
20125
+ const error2 = params.get("error_description") ?? params.get("error");
20126
+ const code = params.get("code");
20127
+ if (error2 || !code) {
20128
+ const msg = error2 ?? "No authorization code in the redirect.";
20129
+ return () => Promise.reject(new Error(msg));
20130
+ }
20131
+ return (signal) => options.redeemCode(code, signal);
20132
+ };
20100
20133
  const handler = (req, res) => {
20101
20134
  const url = new URL(req.url ?? "/", "http://127.0.0.1");
20102
20135
  if (url.pathname !== "/") {
@@ -20112,14 +20145,7 @@ async function startLoopbackReceiver(options) {
20112
20145
  res.writeHead(400).end("Unknown sign-in.");
20113
20146
  return;
20114
20147
  }
20115
- const error2 = url.searchParams.get("error_description") ?? url.searchParams.get("error");
20116
- const code = url.searchParams.get("code");
20117
- if (error2 || !code) {
20118
- const msg = error2 ?? "No authorization code in the redirect.";
20119
- finish(res, 302, () => Promise.reject(new Error(msg)));
20120
- return;
20121
- }
20122
- finish(res, 302, () => options.redeemCode(code));
20148
+ finish(redeemRedirect(url.searchParams), answerWith(res, 302));
20123
20149
  return;
20124
20150
  }
20125
20151
  if (req.method === "POST") {
@@ -20142,7 +20168,10 @@ async function startLoopbackReceiver(options) {
20142
20168
  res.writeHead(400).end("Missing refresh_token.");
20143
20169
  return;
20144
20170
  }
20145
- finish(res, 303, () => options.redeemRefreshToken(refreshToken));
20171
+ finish(
20172
+ (signal) => options.redeemRefreshToken(refreshToken, signal),
20173
+ answerWith(res, 303)
20174
+ );
20146
20175
  },
20147
20176
  () => {
20148
20177
  if (!res.headersSent) res.writeHead(413).end();
@@ -20153,28 +20182,47 @@ async function startLoopbackReceiver(options) {
20153
20182
  res.writeHead(405).end();
20154
20183
  };
20155
20184
  const server = http.createServer({ keepAlive: false }, handler);
20156
- await new Promise((resolve5, reject) => {
20185
+ await new Promise((resolve6, reject) => {
20157
20186
  server.once("error", reject);
20158
- server.listen(options.port, "127.0.0.1", () => resolve5());
20187
+ server.listen(options.port, "127.0.0.1", () => resolve6());
20159
20188
  });
20160
20189
  const { port } = server.address();
20161
- const timer = setTimeout(
20162
- () => settle.reject(
20190
+ const timer = setTimeout(() => {
20191
+ end(
20163
20192
  new Error(
20164
20193
  `Sign-in timed out after ${OAUTH_SIGN_IN_TIMEOUT_MS / 6e4} minutes. Run the login again.`
20165
20194
  )
20166
- ),
20167
- OAUTH_SIGN_IN_TIMEOUT_MS
20168
- );
20195
+ );
20196
+ }, OAUTH_SIGN_IN_TIMEOUT_MS);
20169
20197
  timer.unref();
20170
- const redirectTo = new URL(`http://127.0.0.1:${port}/`);
20171
- redirectTo.searchParams.set("state", state);
20198
+ const loopback = new URL(`http://127.0.0.1:${port}/`);
20199
+ loopback.searchParams.set("state", state);
20200
+ const pasteRedirect = (address) => {
20201
+ if (claimed) return false;
20202
+ let url;
20203
+ try {
20204
+ url = new URL(address.trim());
20205
+ } catch {
20206
+ return false;
20207
+ }
20208
+ if (url.origin !== loopback.origin || url.pathname !== loopback.pathname || !sameSecret(url.searchParams.get("state"), state) || !(url.searchParams.get("code") || url.searchParams.get("error") || url.searchParams.get("error_description"))) {
20209
+ return false;
20210
+ }
20211
+ finish(redeemRedirect(url.searchParams));
20212
+ return true;
20213
+ };
20214
+ const cancel = () => {
20215
+ end(new Error("Sign-in cancelled."));
20216
+ };
20172
20217
  return {
20173
20218
  state,
20174
20219
  port,
20175
- redirectTo: redirectTo.toString(),
20220
+ redirectTo: loopback.toString(),
20176
20221
  done,
20222
+ pasteRedirect,
20223
+ cancel,
20177
20224
  close: () => {
20225
+ claimed = true;
20178
20226
  clearTimeout(timer);
20179
20227
  server.close();
20180
20228
  server.closeAllConnections?.();
@@ -20186,13 +20234,18 @@ async function startBrowserSignIn(options) {
20186
20234
  const receiver = await startLoopbackReceiver({
20187
20235
  port: options.port ?? gotrueCallbackPort(),
20188
20236
  pageUrl: options.pageUrl,
20189
- redeemCode: (code) => gotrueToken(options.authUrl, "pkce", {
20190
- auth_code: code,
20191
- code_verifier: verifier
20192
- }),
20193
- redeemRefreshToken: (refreshToken) => gotrueToken(options.authUrl, "refresh_token", {
20194
- refresh_token: refreshToken
20195
- })
20237
+ redeemCode: (code, signal) => gotrueToken(
20238
+ options.authUrl,
20239
+ "pkce",
20240
+ { auth_code: code, code_verifier: verifier },
20241
+ signal
20242
+ ),
20243
+ redeemRefreshToken: (refreshToken, signal) => gotrueToken(
20244
+ options.authUrl,
20245
+ "refresh_token",
20246
+ { refresh_token: refreshToken },
20247
+ signal
20248
+ )
20196
20249
  });
20197
20250
  let url;
20198
20251
  if (options.oauthProvider) {
@@ -20210,7 +20263,12 @@ async function startBrowserSignIn(options) {
20210
20263
  page.searchParams.set("state", receiver.state);
20211
20264
  url = page.toString();
20212
20265
  }
20213
- return { url, done: receiver.done.finally(receiver.close) };
20266
+ return {
20267
+ url,
20268
+ done: receiver.done.finally(receiver.close),
20269
+ pasteRedirect: receiver.pasteRedirect,
20270
+ cancel: receiver.cancel
20271
+ };
20214
20272
  }
20215
20273
  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;
20216
20274
  var init_identity = __esm({
@@ -23063,10 +23121,10 @@ var require_adm_zip = __commonJS({
23063
23121
  * @param {function|string} [props.namefix] - optional function to help fix filename
23064
23122
  */
23065
23123
  addLocalFolderPromise: function(localPath2, props) {
23066
- return new Promise((resolve5, reject) => {
23124
+ return new Promise((resolve6, reject) => {
23067
23125
  this.addLocalFolderAsync2(Object.assign({ localPath: localPath2 }, props), (err, done) => {
23068
23126
  if (err) reject(err);
23069
- if (done) resolve5(this);
23127
+ if (done) resolve6(this);
23070
23128
  });
23071
23129
  });
23072
23130
  },
@@ -23253,12 +23311,12 @@ var require_adm_zip = __commonJS({
23253
23311
  keepOriginalPermission = get_Bool(false, keepOriginalPermission);
23254
23312
  overwrite = get_Bool(false, overwrite);
23255
23313
  if (!callback) {
23256
- return new Promise((resolve5, reject) => {
23314
+ return new Promise((resolve6, reject) => {
23257
23315
  this.extractAllToAsync(targetPath, overwrite, keepOriginalPermission, function(err) {
23258
23316
  if (err) {
23259
23317
  reject(err);
23260
23318
  } else {
23261
- resolve5(this);
23319
+ resolve6(this);
23262
23320
  }
23263
23321
  });
23264
23322
  });
@@ -23356,11 +23414,11 @@ var require_adm_zip = __commonJS({
23356
23414
  */
23357
23415
  writeZipPromise: function(targetFileName, props) {
23358
23416
  const { overwrite, perm } = Object.assign({ overwrite: true }, props);
23359
- return new Promise((resolve5, reject) => {
23417
+ return new Promise((resolve6, reject) => {
23360
23418
  if (!targetFileName && opts.filename) targetFileName = opts.filename;
23361
23419
  if (!targetFileName) reject("ADM-ZIP: ZIP File Name Missing");
23362
23420
  this.toBufferPromise().then((zipData) => {
23363
- const ret = (done) => done ? resolve5(done) : reject("ADM-ZIP: Wasn't able to write zip file");
23421
+ const ret = (done) => done ? resolve6(done) : reject("ADM-ZIP: Wasn't able to write zip file");
23364
23422
  filetools.writeFileToAsync(targetFileName, zipData, overwrite, perm, ret);
23365
23423
  }, reject);
23366
23424
  });
@@ -23369,8 +23427,8 @@ var require_adm_zip = __commonJS({
23369
23427
  * @returns {Promise<Buffer>} A promise to the Buffer.
23370
23428
  */
23371
23429
  toBufferPromise: function() {
23372
- return new Promise((resolve5, reject) => {
23373
- _zip.toAsyncBuffer(resolve5, reject);
23430
+ return new Promise((resolve6, reject) => {
23431
+ _zip.toAsyncBuffer(resolve6, reject);
23374
23432
  });
23375
23433
  },
23376
23434
  /**
@@ -23488,12 +23546,12 @@ var require_isexe = __commonJS({
23488
23546
  if (typeof Promise !== "function") {
23489
23547
  throw new TypeError("callback not provided");
23490
23548
  }
23491
- return new Promise(function(resolve5, reject) {
23549
+ return new Promise(function(resolve6, reject) {
23492
23550
  isexe(path13, options || {}, function(er, is) {
23493
23551
  if (er) {
23494
23552
  reject(er);
23495
23553
  } else {
23496
- resolve5(is);
23554
+ resolve6(is);
23497
23555
  }
23498
23556
  });
23499
23557
  });
@@ -23559,27 +23617,27 @@ var require_which = __commonJS({
23559
23617
  opt = {};
23560
23618
  const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
23561
23619
  const found = [];
23562
- const step = (i2) => new Promise((resolve5, reject) => {
23620
+ const step = (i2) => new Promise((resolve6, reject) => {
23563
23621
  if (i2 === pathEnv.length)
23564
- return opt.all && found.length ? resolve5(found) : reject(getNotFoundError(cmd));
23622
+ return opt.all && found.length ? resolve6(found) : reject(getNotFoundError(cmd));
23565
23623
  const ppRaw = pathEnv[i2];
23566
23624
  const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
23567
23625
  const pCmd = path13.join(pathPart, cmd);
23568
23626
  const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
23569
- resolve5(subStep(p, i2, 0));
23627
+ resolve6(subStep(p, i2, 0));
23570
23628
  });
23571
- const subStep = (p, i2, ii) => new Promise((resolve5, reject) => {
23629
+ const subStep = (p, i2, ii) => new Promise((resolve6, reject) => {
23572
23630
  if (ii === pathExt.length)
23573
- return resolve5(step(i2 + 1));
23631
+ return resolve6(step(i2 + 1));
23574
23632
  const ext = pathExt[ii];
23575
23633
  isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
23576
23634
  if (!er && is) {
23577
23635
  if (opt.all)
23578
23636
  found.push(p + ext);
23579
23637
  else
23580
- return resolve5(p + ext);
23638
+ return resolve6(p + ext);
23581
23639
  }
23582
- return resolve5(subStep(p, i2, ii + 1));
23640
+ return resolve6(subStep(p, i2, ii + 1));
23583
23641
  });
23584
23642
  });
23585
23643
  return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
@@ -23911,6 +23969,78 @@ var init_browser = __esm({
23911
23969
  }
23912
23970
  });
23913
23971
 
23972
+ // src/mcp/auth/sign_in_prompt.ts
23973
+ import * as readline2 from "node:readline";
23974
+ async function promptForSignIn(signIn2, out) {
23975
+ const { url, done, pasteRedirect, cancel } = signIn2;
23976
+ const printLink2 = out.printLink ?? out.print;
23977
+ const printError2 = out.printError ?? out.print;
23978
+ out.print("Please visit the following URL to authenticate:");
23979
+ printLink2(url);
23980
+ out.print("");
23981
+ out.print(
23982
+ "Browser on another machine? Sign in there with Google, GitHub, Microsoft or SSO. It then fails to load an http://127.0.0.1 address: copy that address and paste it here. Email sign-in needs a browser on this machine."
23983
+ );
23984
+ out.print("");
23985
+ const terminal = readline2.createInterface({
23986
+ input: process.stdin,
23987
+ output: out.output
23988
+ });
23989
+ let closed = false;
23990
+ let opened = false;
23991
+ terminal.on("close", () => {
23992
+ closed = true;
23993
+ });
23994
+ terminal.on("SIGINT", () => {
23995
+ cancel();
23996
+ terminal.close();
23997
+ });
23998
+ const ask = (prompt) => {
23999
+ if (closed) return;
24000
+ terminal.setPrompt(prompt);
24001
+ terminal.prompt();
24002
+ };
24003
+ terminal.on("line", async (line) => {
24004
+ const address = line.trim();
24005
+ if (!address) {
24006
+ if (!opened) {
24007
+ opened = true;
24008
+ try {
24009
+ await openInBrowser(url);
24010
+ out.print("\u2713 Browser opened");
24011
+ } catch {
24012
+ out.print(
24013
+ "\u26A0 Could not open browser automatically. Please open the URL manually."
24014
+ );
24015
+ }
24016
+ out.print("");
24017
+ out.print("Waiting for authentication...");
24018
+ }
24019
+ ask("Paste the address here if the browser could not load it: ");
24020
+ return;
24021
+ }
24022
+ if (pasteRedirect(address)) {
24023
+ out.print("Finishing sign-in...");
24024
+ terminal.close();
24025
+ return;
24026
+ }
24027
+ printError2(
24028
+ "That is not this sign-in's address. Paste the whole address from the browser's address bar; it starts with http://127.0.0.1:"
24029
+ );
24030
+ ask("Paste the address: ");
24031
+ });
24032
+ ask("Press Enter to open your browser, or paste the address: ");
24033
+ await done.catch(() => {
24034
+ });
24035
+ terminal.close();
24036
+ }
24037
+ var init_sign_in_prompt = __esm({
24038
+ "src/mcp/auth/sign_in_prompt.ts"() {
24039
+ "use strict";
24040
+ init_browser();
24041
+ }
24042
+ });
24043
+
23914
24044
  // ../../node_modules/ms/index.js
23915
24045
  var require_ms = __commonJS({
23916
24046
  "../../node_modules/ms/index.js"(exports, module) {
@@ -24681,12 +24811,12 @@ var require_promisify = __commonJS({
24681
24811
  Object.defineProperty(exports, "__esModule", { value: true });
24682
24812
  function promisify5(fn) {
24683
24813
  return function(req, opts) {
24684
- return new Promise((resolve5, reject) => {
24814
+ return new Promise((resolve6, reject) => {
24685
24815
  fn.call(this, req, opts, (err, rtn) => {
24686
24816
  if (err) {
24687
24817
  reject(err);
24688
24818
  } else {
24689
- resolve5(rtn);
24819
+ resolve6(rtn);
24690
24820
  }
24691
24821
  });
24692
24822
  });
@@ -24890,7 +25020,7 @@ var require_parse_proxy_response = __commonJS({
24890
25020
  var debug_1 = __importDefault(require_src());
24891
25021
  var debug = debug_1.default("https-proxy-agent:parse-proxy-response");
24892
25022
  function parseProxyResponse(socket) {
24893
- return new Promise((resolve5, reject) => {
25023
+ return new Promise((resolve6, reject) => {
24894
25024
  let buffersLength = 0;
24895
25025
  const buffers = [];
24896
25026
  function read() {
@@ -24930,7 +25060,7 @@ var require_parse_proxy_response = __commonJS({
24930
25060
  const firstLine = buffered.toString("ascii", 0, buffered.indexOf("\r\n"));
24931
25061
  const statusCode = +firstLine.split(" ")[1];
24932
25062
  debug("got proxy server response: %o", firstLine);
24933
- resolve5({
25063
+ resolve6({
24934
25064
  statusCode,
24935
25065
  buffered
24936
25066
  });
@@ -24951,11 +25081,11 @@ var require_agent = __commonJS({
24951
25081
  "use strict";
24952
25082
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
24953
25083
  function adopt(value) {
24954
- return value instanceof P ? value : new P(function(resolve5) {
24955
- resolve5(value);
25084
+ return value instanceof P ? value : new P(function(resolve6) {
25085
+ resolve6(value);
24956
25086
  });
24957
25087
  }
24958
- return new (P || (P = Promise))(function(resolve5, reject) {
25088
+ return new (P || (P = Promise))(function(resolve6, reject) {
24959
25089
  function fulfilled(value) {
24960
25090
  try {
24961
25091
  step(generator.next(value));
@@ -24971,7 +25101,7 @@ var require_agent = __commonJS({
24971
25101
  }
24972
25102
  }
24973
25103
  function step(result) {
24974
- result.done ? resolve5(result.value) : adopt(result.value).then(fulfilled, rejected);
25104
+ result.done ? resolve6(result.value) : adopt(result.value).then(fulfilled, rejected);
24975
25105
  }
24976
25106
  step((generator = generator.apply(thisArg, _arguments || [])).next());
24977
25107
  });
@@ -30735,10 +30865,10 @@ var require_raw_body = __commonJS({
30735
30865
  if (done) {
30736
30866
  return readStream(stream, encoding, length, limit, wrap(done));
30737
30867
  }
30738
- return new Promise(function executor(resolve5, reject) {
30868
+ return new Promise(function executor(resolve6, reject) {
30739
30869
  readStream(stream, encoding, length, limit, function onRead2(err, buf) {
30740
30870
  if (err) return reject(err);
30741
- resolve5(buf);
30871
+ resolve6(buf);
30742
30872
  });
30743
30873
  });
30744
30874
  }
@@ -44073,7 +44203,7 @@ var require_view = __commonJS({
44073
44203
  var basename2 = path13.basename;
44074
44204
  var extname2 = path13.extname;
44075
44205
  var join6 = path13.join;
44076
- var resolve5 = path13.resolve;
44206
+ var resolve6 = path13.resolve;
44077
44207
  module.exports = View;
44078
44208
  function View(name, options) {
44079
44209
  var opts = options || {};
@@ -44107,7 +44237,7 @@ var require_view = __commonJS({
44107
44237
  debug('lookup "%s"', name);
44108
44238
  for (var i2 = 0; i2 < roots.length && !path14; i2++) {
44109
44239
  var root = roots[i2];
44110
- var loc = resolve5(root, name);
44240
+ var loc = resolve6(root, name);
44111
44241
  var dir = dirname3(loc);
44112
44242
  var file = basename2(loc);
44113
44243
  path14 = this.resolve(dir, file);
@@ -44132,7 +44262,7 @@ var require_view = __commonJS({
44132
44262
  });
44133
44263
  sync = false;
44134
44264
  };
44135
- View.prototype.resolve = function resolve6(dir, file) {
44265
+ View.prototype.resolve = function resolve7(dir, file) {
44136
44266
  var ext = this.ext;
44137
44267
  var path14 = join6(dir, file);
44138
44268
  var stat2 = tryStat(path14);
@@ -46287,7 +46417,7 @@ var require_application = __commonJS({
46287
46417
  var compileETag = require_utils6().compileETag;
46288
46418
  var compileQueryParser = require_utils6().compileQueryParser;
46289
46419
  var compileTrust = require_utils6().compileTrust;
46290
- var resolve5 = __require("node:path").resolve;
46420
+ var resolve6 = __require("node:path").resolve;
46291
46421
  var once9 = require_once();
46292
46422
  var Router = require_router();
46293
46423
  var slice = Array.prototype.slice;
@@ -46341,7 +46471,7 @@ var require_application = __commonJS({
46341
46471
  this.mountpath = "/";
46342
46472
  this.locals.settings = this.settings;
46343
46473
  this.set("view", View);
46344
- this.set("views", resolve5("views"));
46474
+ this.set("views", resolve6("views"));
46345
46475
  this.set("jsonp callback name", "callback");
46346
46476
  if (env3 === "production") {
46347
46477
  this.enable("view cache");
@@ -47846,7 +47976,7 @@ var require_send = __commonJS({
47846
47976
  var extname2 = path13.extname;
47847
47977
  var join6 = path13.join;
47848
47978
  var normalize = path13.normalize;
47849
- var resolve5 = path13.resolve;
47979
+ var resolve6 = path13.resolve;
47850
47980
  var sep = path13.sep;
47851
47981
  var BYTES_RANGE_REGEXP = /^ *bytes=/;
47852
47982
  var MAX_MAXAGE = 60 * 60 * 24 * 365 * 1e3;
@@ -47875,7 +48005,7 @@ var require_send = __commonJS({
47875
48005
  this._maxage = opts.maxAge || opts.maxage;
47876
48006
  this._maxage = typeof this._maxage === "string" ? ms(this._maxage) : Number(this._maxage);
47877
48007
  this._maxage = !isNaN(this._maxage) ? Math.min(Math.max(0, this._maxage), MAX_MAXAGE) : 0;
47878
- this._root = opts.root ? resolve5(opts.root) : null;
48008
+ this._root = opts.root ? resolve6(opts.root) : null;
47879
48009
  }
47880
48010
  util2.inherits(SendStream, Stream);
47881
48011
  SendStream.prototype.error = function error2(status, err) {
@@ -48024,7 +48154,7 @@ var require_send = __commonJS({
48024
48154
  return res;
48025
48155
  }
48026
48156
  parts = normalize(path14).split(sep);
48027
- path14 = resolve5(path14);
48157
+ path14 = resolve6(path14);
48028
48158
  }
48029
48159
  if (containsDotFile(parts)) {
48030
48160
  debug('%s dotfile "%s"', this._dotfiles, path14);
@@ -48402,7 +48532,7 @@ var require_response = __commonJS({
48402
48532
  var cookie = require_cookie();
48403
48533
  var send = require_send();
48404
48534
  var extname2 = path13.extname;
48405
- var resolve5 = path13.resolve;
48535
+ var resolve6 = path13.resolve;
48406
48536
  var vary = require_vary();
48407
48537
  var { Buffer: Buffer5 } = __require("node:buffer");
48408
48538
  var res = Object.create(http2.ServerResponse.prototype);
@@ -48608,7 +48738,7 @@ var require_response = __commonJS({
48608
48738
  }
48609
48739
  opts = Object.create(opts);
48610
48740
  opts.headers = headers;
48611
- var fullPath = !opts.root ? resolve5(path14) : path14;
48741
+ var fullPath = !opts.root ? resolve6(path14) : path14;
48612
48742
  return this.sendFile(fullPath, opts, done);
48613
48743
  };
48614
48744
  res.contentType = res.type = function contentType(type) {
@@ -48857,7 +48987,7 @@ var require_serve_static = __commonJS({
48857
48987
  var encodeUrl = require_encodeurl();
48858
48988
  var escapeHtml = require_escape_html();
48859
48989
  var parseUrl = require_parseurl();
48860
- var resolve5 = __require("path").resolve;
48990
+ var resolve6 = __require("path").resolve;
48861
48991
  var send = require_send();
48862
48992
  var url = __require("url");
48863
48993
  module.exports = serveStatic;
@@ -48876,7 +49006,7 @@ var require_serve_static = __commonJS({
48876
49006
  throw new TypeError("option setHeaders must be function");
48877
49007
  }
48878
49008
  opts.maxage = opts.maxage || opts.maxAge || 0;
48879
- opts.root = resolve5(root);
49009
+ opts.root = resolve6(root);
48880
49010
  var onDirectory = redirect ? createRedirectDirectoryListener() : createNotFoundDirectoryListener();
48881
49011
  return function serveStatic2(req, res, next) {
48882
49012
  if (req.method !== "GET" && req.method !== "HEAD") {
@@ -61839,7 +61969,7 @@ var init_protocol = __esm({
61839
61969
  return;
61840
61970
  }
61841
61971
  const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
61842
- await new Promise((resolve5) => setTimeout(resolve5, pollInterval));
61972
+ await new Promise((resolve6) => setTimeout(resolve6, pollInterval));
61843
61973
  options?.signal?.throwIfAborted();
61844
61974
  }
61845
61975
  } catch (error2) {
@@ -61856,7 +61986,7 @@ var init_protocol = __esm({
61856
61986
  */
61857
61987
  request(request, resultSchema, options) {
61858
61988
  const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
61859
- return new Promise((resolve5, reject) => {
61989
+ return new Promise((resolve6, reject) => {
61860
61990
  const earlyReject = (error2) => {
61861
61991
  reject(error2);
61862
61992
  };
@@ -61934,7 +62064,7 @@ var init_protocol = __esm({
61934
62064
  if (!parseResult.success) {
61935
62065
  reject(parseResult.error);
61936
62066
  } else {
61937
- resolve5(parseResult.data);
62067
+ resolve6(parseResult.data);
61938
62068
  }
61939
62069
  } catch (error2) {
61940
62070
  reject(error2);
@@ -62195,12 +62325,12 @@ var init_protocol = __esm({
62195
62325
  }
62196
62326
  } catch {
62197
62327
  }
62198
- return new Promise((resolve5, reject) => {
62328
+ return new Promise((resolve6, reject) => {
62199
62329
  if (signal.aborted) {
62200
62330
  reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
62201
62331
  return;
62202
62332
  }
62203
- const timeoutId = setTimeout(resolve5, interval);
62333
+ const timeoutId = setTimeout(resolve6, interval);
62204
62334
  signal.addEventListener("abort", () => {
62205
62335
  clearTimeout(timeoutId);
62206
62336
  reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
@@ -65192,7 +65322,7 @@ var require_compile3 = __commonJS({
65192
65322
  const schOrFunc = root.refs[ref];
65193
65323
  if (schOrFunc)
65194
65324
  return schOrFunc;
65195
- let _sch = resolve5.call(this, root, ref);
65325
+ let _sch = resolve6.call(this, root, ref);
65196
65326
  if (_sch === void 0) {
65197
65327
  const schema = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
65198
65328
  const { schemaId } = this.opts;
@@ -65219,7 +65349,7 @@ var require_compile3 = __commonJS({
65219
65349
  function sameSchemaEnv(s1, s2) {
65220
65350
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
65221
65351
  }
65222
- function resolve5(root, ref) {
65352
+ function resolve6(root, ref) {
65223
65353
  let sch;
65224
65354
  while (typeof (sch = this.refs[ref]) == "string")
65225
65355
  ref = sch;
@@ -69109,7 +69239,7 @@ var init_mcp = __esm({
69109
69239
  let task = createTaskResult.task;
69110
69240
  const pollInterval = task.pollInterval ?? 5e3;
69111
69241
  while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
69112
- await new Promise((resolve5) => setTimeout(resolve5, pollInterval));
69242
+ await new Promise((resolve6) => setTimeout(resolve6, pollInterval));
69113
69243
  const updatedTask = await extra.taskStore.getTask(taskId);
69114
69244
  if (!updatedTask) {
69115
69245
  throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
@@ -69703,12 +69833,12 @@ var init_stdio2 = __esm({
69703
69833
  this.onclose?.();
69704
69834
  }
69705
69835
  send(message) {
69706
- return new Promise((resolve5) => {
69836
+ return new Promise((resolve6) => {
69707
69837
  const json = serializeMessage(message);
69708
69838
  if (this._stdout.write(json)) {
69709
- resolve5();
69839
+ resolve6();
69710
69840
  } else {
69711
- this._stdout.once("drain", resolve5);
69841
+ this._stdout.once("drain", resolve6);
69712
69842
  }
69713
69843
  });
69714
69844
  }
@@ -70212,7 +70342,7 @@ var init_dist5 = __esm({
70212
70342
  });
70213
70343
  if (!chunk) {
70214
70344
  if (i2 === 1) {
70215
- await new Promise((resolve5) => setTimeout(resolve5));
70345
+ await new Promise((resolve6) => setTimeout(resolve6));
70216
70346
  maxReadCount = 3;
70217
70347
  continue;
70218
70348
  }
@@ -70718,9 +70848,9 @@ data:
70718
70848
  const initRequest = messages.find((m) => isInitializeRequest(m));
70719
70849
  const clientProtocolVersion = initRequest ? initRequest.params.protocolVersion : req.headers.get("mcp-protocol-version") ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
70720
70850
  if (this._enableJsonResponse) {
70721
- return new Promise((resolve5) => {
70851
+ return new Promise((resolve6) => {
70722
70852
  this._streamMapping.set(streamId, {
70723
- resolveJson: resolve5,
70853
+ resolveJson: resolve6,
70724
70854
  cleanup: () => {
70725
70855
  this._streamMapping.delete(streamId);
70726
70856
  }
@@ -71940,7 +72070,7 @@ var init_api2 = __esm({
71940
72070
 
71941
72071
  // src/mcp/runtime/register.ts
71942
72072
  import { mkdir as mkdir2, readFile as readFile4, writeFile as writeFile4 } from "node:fs/promises";
71943
- import { dirname as dirname2, resolve as resolve2 } from "node:path";
72073
+ import { dirname as dirname2, resolve as resolve3 } from "node:path";
71944
72074
  function extensionForEncoding(encoding) {
71945
72075
  const map = {
71946
72076
  MP3: ".mp3",
@@ -72089,7 +72219,7 @@ function registerRuntimeTools(server) {
72089
72219
  method: "POST",
72090
72220
  body: JSON.stringify(body)
72091
72221
  });
72092
- let filePath = resolve2(output_file);
72222
+ let filePath = resolve3(output_file);
72093
72223
  if (!filePath.match(/\.\w{2,5}$/)) {
72094
72224
  filePath += extensionForEncoding(audio_encoding);
72095
72225
  }
@@ -72154,7 +72284,7 @@ function registerRuntimeTools(server) {
72154
72284
  prompts
72155
72285
  }) => {
72156
72286
  try {
72157
- const filePath = resolve2(input_file);
72287
+ const filePath = resolve3(input_file);
72158
72288
  const audioBytes = await readFile4(filePath);
72159
72289
  const audioBase64 = audioBytes.toString("base64");
72160
72290
  const transcribeConfig = {
@@ -72251,7 +72381,7 @@ function registerRuntimeTools(server) {
72251
72381
  try {
72252
72382
  const voiceSamples = await Promise.all(
72253
72383
  audio_files.map(async (filePath, i2) => {
72254
- const audioBytes = await readFile4(resolve2(filePath));
72384
+ const audioBytes = await readFile4(resolve3(filePath));
72255
72385
  const sample = {
72256
72386
  audioData: audioBytes.toString("base64")
72257
72387
  };
@@ -72339,7 +72469,7 @@ function registerRuntimeTools(server) {
72339
72469
  previewText: v.previewText
72340
72470
  };
72341
72471
  if (preview_output_dir) {
72342
- const dir = resolve2(preview_output_dir);
72472
+ const dir = resolve3(preview_output_dir);
72343
72473
  await mkdir2(dir, { recursive: true });
72344
72474
  const filePath = `${dir}/${v.voiceId}.mp3`;
72345
72475
  await writeFile4(filePath, Buffer.from(v.previewAudio, "base64"));
@@ -72472,7 +72602,7 @@ function registerRuntimeTools(server) {
72472
72602
  "No audio in response. Provider/router may not support audio output, or 'voice' is not a valid id."
72473
72603
  );
72474
72604
  }
72475
- const filePath = resolve2(output_file);
72605
+ const filePath = resolve3(output_file);
72476
72606
  await mkdir2(dirname2(filePath), { recursive: true });
72477
72607
  await writeFile4(filePath, Buffer.from(audio.data, "base64"));
72478
72608
  return textResult({
@@ -72903,39 +73033,6 @@ var init_schemas4 = __esm({
72903
73033
  });
72904
73034
 
72905
73035
  // src/mcp/cli/login.ts
72906
- import * as readline5 from "node:readline";
72907
- async function offerBrowser2(url, done) {
72908
- console.error("Please visit the following URL to authenticate:");
72909
- console.error(url);
72910
- console.error();
72911
- const readlineInterface = readline5.createInterface({
72912
- input: process.stdin,
72913
- output: process.stdout
72914
- });
72915
- const enter = new Promise((resolve5) => {
72916
- readlineInterface.question(
72917
- "Press Enter to open your browser...",
72918
- () => resolve5("enter")
72919
- );
72920
- });
72921
- const settled = done.then(
72922
- () => "done",
72923
- () => "done"
72924
- );
72925
- const first = await Promise.race([enter, settled]);
72926
- readlineInterface.close();
72927
- if (first === "done") return;
72928
- try {
72929
- await openInBrowser(url);
72930
- console.error("Browser opened.");
72931
- } catch {
72932
- console.error(
72933
- "Could not open browser automatically. Open the URL manually."
72934
- );
72935
- }
72936
- console.error();
72937
- console.error("Waiting for authentication...");
72938
- }
72939
73036
  async function runLogin() {
72940
73037
  const source = await resolveIdentitySource(PLATFORM_URL2);
72941
73038
  const oauthProvider = process.env.INWORLD_AUTH_OAUTH_PROVIDER || void 0;
@@ -72944,14 +73041,17 @@ async function runLogin() {
72944
73041
  `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).`
72945
73042
  );
72946
73043
  }
72947
- const { url, done } = await startBrowserSignIn({
73044
+ const signIn2 = await startBrowserSignIn({
72948
73045
  authUrl: source.authUrl,
72949
73046
  pageUrl: INWORLD_CLI_AUTH_URL2,
72950
73047
  version: CLI_VERSION,
72951
73048
  oauthProvider
72952
73049
  });
72953
- await offerBrowser2(url, done);
72954
- const tokens = await done;
73050
+ await promptForSignIn(signIn2, {
73051
+ print: (line) => console.error(line),
73052
+ output: process.stdout
73053
+ });
73054
+ const tokens = await signIn2.done;
72955
73055
  console.error();
72956
73056
  console.error("Exchanging for Inworld session...");
72957
73057
  const exchanged = await exchangeIdentityToken(tokens.idToken);
@@ -72988,12 +73088,12 @@ var init_login = __esm({
72988
73088
  "use strict";
72989
73089
  init_dist4();
72990
73090
  init_constants5();
72991
- init_browser();
72992
73091
  init_constants6();
72993
73092
  init_exchange();
72994
73093
  init_identity();
72995
73094
  init_paths();
72996
73095
  init_session();
73096
+ init_sign_in_prompt();
72997
73097
  }
72998
73098
  });
72999
73099
 
@@ -73982,7 +74082,7 @@ async function runHttp() {
73982
74082
  })
73983
74083
  );
73984
74084
  });
73985
- await new Promise((resolve5, reject) => {
74085
+ await new Promise((resolve6, reject) => {
73986
74086
  const httpServer = app.listen(port, host, () => {
73987
74087
  console.error(
73988
74088
  `inworld (Streamable HTTP) at http://${host}:${port}${MCP_PATH}`
@@ -73992,7 +74092,7 @@ async function runHttp() {
73992
74092
  "Listening on all interfaces \u2014 use this machine\u2019s LAN or Tailscale IP from other hosts."
73993
74093
  );
73994
74094
  }
73995
- resolve5();
74095
+ resolve6();
73996
74096
  });
73997
74097
  httpServer.on("error", reject);
73998
74098
  });
@@ -74374,14 +74474,14 @@ __export(audio_player_exports, {
74374
74474
  cleanupTempFile: () => cleanupTempFile,
74375
74475
  playFile: () => playFile
74376
74476
  });
74377
- import { unlink } from "fs/promises";
74477
+ import { unlink as unlink2 } from "fs/promises";
74378
74478
  async function playFile(filePath) {
74379
74479
  try {
74380
74480
  const player = (await Promise.resolve().then(() => __toESM(require_play_sound(), 1))).default();
74381
- await new Promise((resolve5, reject) => {
74481
+ await new Promise((resolve6, reject) => {
74382
74482
  player.play(filePath, (err) => {
74383
74483
  if (err) reject(err);
74384
- else resolve5();
74484
+ else resolve6();
74385
74485
  });
74386
74486
  });
74387
74487
  return true;
@@ -74391,7 +74491,7 @@ async function playFile(filePath) {
74391
74491
  }
74392
74492
  async function cleanupTempFile(filepath) {
74393
74493
  try {
74394
- await unlink(filepath);
74494
+ await unlink2(filepath);
74395
74495
  } catch {
74396
74496
  }
74397
74497
  }
@@ -74844,18 +74944,18 @@ var proto = Object.defineProperties(() => {
74844
74944
  }
74845
74945
  }
74846
74946
  });
74847
- var createStyler = (open2, close, parent) => {
74947
+ var createStyler = (open3, close, parent) => {
74848
74948
  let openAll;
74849
74949
  let closeAll;
74850
74950
  if (parent === void 0) {
74851
- openAll = open2;
74951
+ openAll = open3;
74852
74952
  closeAll = close;
74853
74953
  } else {
74854
- openAll = parent.openAll + open2;
74954
+ openAll = parent.openAll + open3;
74855
74955
  closeAll = close + parent.closeAll;
74856
74956
  }
74857
74957
  return {
74858
- open: open2,
74958
+ open: open3,
74859
74959
  close,
74860
74960
  openAll,
74861
74961
  closeAll,
@@ -75813,7 +75913,7 @@ var TtsSession = class _TtsSession {
75813
75913
  });
75814
75914
  const sampleRateHertz = opts.sampleRateHertz ?? 48e3;
75815
75915
  try {
75816
- await new Promise((resolve5, reject) => {
75916
+ await new Promise((resolve6, reject) => {
75817
75917
  const cleanup = () => {
75818
75918
  clearTimeout(timer);
75819
75919
  ws.removeEventListener("open", onOpen);
@@ -75822,7 +75922,7 @@ var TtsSession = class _TtsSession {
75822
75922
  };
75823
75923
  const onOpen = () => {
75824
75924
  cleanup();
75825
- resolve5();
75925
+ resolve6();
75826
75926
  };
75827
75927
  const onError = (event) => {
75828
75928
  cleanup();
@@ -75992,7 +76092,7 @@ function maskCred(s) {
75992
76092
  return `${s.slice(0, 4)}\u2026${s.slice(-2)} (len=${s.length})`;
75993
76093
  }
75994
76094
  function waitForFrame(ws, predicate, send, idleMs = IDLE_TIMEOUT_MS, deadlineMs = SEGMENT_TIMEOUT_MS) {
75995
- return new Promise((resolve5, reject) => {
76095
+ return new Promise((resolve6, reject) => {
75996
76096
  const cleanup = () => {
75997
76097
  clearTimeout(idle);
75998
76098
  clearTimeout(deadline);
@@ -76012,7 +76112,7 @@ function waitForFrame(ws, predicate, send, idleMs = IDLE_TIMEOUT_MS, deadlineMs
76012
76112
  const r = predicate(frame);
76013
76113
  if (r.done) {
76014
76114
  cleanup();
76015
- resolve5();
76115
+ resolve6();
76016
76116
  } else if (frame.result?.audioChunk?.audioContent) {
76017
76117
  idle.refresh();
76018
76118
  }
@@ -76158,10 +76258,10 @@ function promptInput(prompt, defaultValue) {
76158
76258
  output: process.stdout
76159
76259
  });
76160
76260
  const displayPrompt = defaultValue ? `${prompt} [${defaultValue}]: ` : `${prompt}: `;
76161
- return new Promise((resolve5) => {
76261
+ return new Promise((resolve6) => {
76162
76262
  rl.question(displayPrompt, (answer) => {
76163
76263
  rl.close();
76164
- resolve5(answer.trim() || defaultValue || "");
76264
+ resolve6(answer.trim() || defaultValue || "");
76165
76265
  });
76166
76266
  });
76167
76267
  }
@@ -77163,11 +77263,11 @@ var replacements = Object.entries(specialMainSymbols);
77163
77263
  // ../../node_modules/yoctocolors/base.js
77164
77264
  import tty2 from "node:tty";
77165
77265
  var hasColors = tty2?.WriteStream?.prototype?.hasColors?.() ?? false;
77166
- var format = (open2, close) => {
77266
+ var format = (open3, close) => {
77167
77267
  if (!hasColors) {
77168
77268
  return (input) => input;
77169
77269
  }
77170
- const openCode = `\x1B[${open2}m`;
77270
+ const openCode = `\x1B[${open3}m`;
77171
77271
  const closeCode = `\x1B[${close}m`;
77172
77272
  return (input) => {
77173
77273
  const string3 = input + "";
@@ -78085,8 +78185,8 @@ var disconnect = (anyProcess) => {
78085
78185
  // node_modules/execa/lib/utils/deferred.js
78086
78186
  var createDeferred = () => {
78087
78187
  const methods = {};
78088
- const promise = new Promise((resolve5, reject) => {
78089
- Object.assign(methods, { resolve: resolve5, reject });
78188
+ const promise = new Promise((resolve6, reject) => {
78189
+ Object.assign(methods, { resolve: resolve6, reject });
78090
78190
  });
78091
78191
  return Object.assign(promise, methods);
78092
78192
  };
@@ -82728,11 +82828,11 @@ var addConcurrentStream = (concurrentStreams, stream, waitName) => {
82728
82828
  const promises = weakMap.get(stream);
82729
82829
  const promise = createDeferred();
82730
82830
  promises.push(promise);
82731
- const resolve5 = promise.resolve.bind(promise);
82732
- return { resolve: resolve5, promises };
82831
+ const resolve6 = promise.resolve.bind(promise);
82832
+ return { resolve: resolve6, promises };
82733
82833
  };
82734
- var waitForConcurrentStreams = async ({ resolve: resolve5, promises }, subprocess) => {
82735
- resolve5();
82834
+ var waitForConcurrentStreams = async ({ resolve: resolve6, promises }, subprocess) => {
82835
+ resolve6();
82736
82836
  const [isSubprocessExit] = await Promise.race([
82737
82837
  Promise.allSettled([true, subprocess]),
82738
82838
  Promise.all([false, ...promises])
@@ -84134,12 +84234,13 @@ var audiobookCommand = new Command("audiobook").description("Audiobook generatio
84134
84234
  });
84135
84235
 
84136
84236
  // src/commands/auth/login_command.ts
84137
- import * as readline3 from "readline";
84138
84237
  init_constants5();
84139
- init_browser();
84140
84238
  init_identity();
84239
+ init_sign_in_prompt();
84141
84240
 
84142
84241
  // src/services/workspace_service.ts
84242
+ import { open as open2, unlink } from "node:fs/promises";
84243
+ import { resolve as resolve2 } from "node:path";
84143
84244
  init_constants5();
84144
84245
 
84145
84246
  // proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.ts
@@ -84270,7 +84371,7 @@ var Workspaces = class {
84270
84371
  };
84271
84372
 
84272
84373
  // src/utils/selector.ts
84273
- import * as readline2 from "readline";
84374
+ import * as readline3 from "readline";
84274
84375
  async function selectItem(options) {
84275
84376
  const {
84276
84377
  items,
@@ -84295,11 +84396,11 @@ async function selectItem(options) {
84295
84396
  const displayName = getDisplayName(item);
84296
84397
  printListItem(`${idx + 1}. ${bright(displayName)}`);
84297
84398
  });
84298
- const rl = readline2.createInterface({
84399
+ const rl = readline3.createInterface({
84299
84400
  input: process.stdin,
84300
84401
  output: process.stdout
84301
84402
  });
84302
- const question = (query) => new Promise((resolve5) => rl.question(query, resolve5));
84403
+ const question = (query) => new Promise((resolve6) => rl.question(query, resolve6));
84303
84404
  let selectedItem = null;
84304
84405
  try {
84305
84406
  while (!selectedItem) {
@@ -84409,15 +84510,27 @@ Selecting workspace: ${source_default.whiteBright(workspaceId)}`);
84409
84510
  success("\nWorkspace selected.");
84410
84511
  }
84411
84512
  /**
84412
- * Creates an API key in the active workspace and prints it. The platform
84413
- * returns the secret only here, so it is shown once and never stored.
84513
+ * Creates an API key in the active workspace and prints it, or writes it to
84514
+ * `outputPath` as `INWORLD_API_KEY=<key>`. The platform returns the secret
84515
+ * only here, so it is shown once and never stored.
84516
+ *
84517
+ * The output file is created, readable by its owner only, before the key
84518
+ * exists, and an existing file is refused: a key whose secret cannot be
84519
+ * saved would be lost. Any failure removes the file.
84414
84520
  *
84415
- * @throws when no workspace is selected or no key comes back: the command
84416
- * must exit non-zero, or a script would take a failed creation for success.
84521
+ * @throws when no workspace is selected, the file cannot be created, no key
84522
+ * comes back or the write fails: the command must exit non-zero, or a
84523
+ * script would take a failed creation for success.
84417
84524
  * @param mode 'read' for read-only, 'write' for read/write voices & router
84418
84525
  * @param displayName Optional display name for the key
84526
+ * @param outputPath Optional new file to write the key to instead of printing it
84419
84527
  */
84420
- static async createApiKey(mode, displayName) {
84528
+ static async createApiKey(mode, displayName, outputPath) {
84529
+ if (outputPath !== void 0 && !outputPath.trim()) {
84530
+ throw new Error(
84531
+ "--output needs a file name, and the one given is empty. No key was created."
84532
+ );
84533
+ }
84421
84534
  const credentials = await authManager.getCredentials();
84422
84535
  if (!credentials?.workspace) {
84423
84536
  throw new Error(
@@ -84428,22 +84541,41 @@ Selecting workspace: ${source_default.whiteBright(workspaceId)}`);
84428
84541
  const baseScopes = ["api.rt::x", "api.ml::x", "api.ops::x"];
84429
84542
  const scopes = mode === "write" ? [...baseScopes, "api.dsgnt.voices::rw", "api.dsgnt.router::rw"] : [...baseScopes, "api.dsgnt.voices::r", "api.dsgnt.router::r"];
84430
84543
  const label = mode === "write" ? "read/write" : "read-only";
84431
- print(`Creating ${label} API key...`);
84432
- const created = await authenticatedInworldRequest(ApiKeys.GenerateApiKey, {
84433
- parent,
84434
- scopes,
84435
- displayName,
84436
- authTypes: [
84437
- "API_KEY_AUTHORIZATION_TYPE_BASIC" /* API_KEY_AUTHORIZATION_TYPE_BASIC */,
84438
- "API_KEY_AUTHORIZATION_TYPE_JWT" /* API_KEY_AUTHORIZATION_TYPE_JWT */
84439
- ]
84440
- });
84441
- if (!created?.key || !created.secret) {
84442
- throw new Error("The platform returned no key to print.");
84544
+ const file = outputPath === void 0 ? void 0 : await createKeyFile(outputPath);
84545
+ let created;
84546
+ try {
84547
+ print(`Creating ${label} API key...`);
84548
+ created = await authenticatedInworldRequest(ApiKeys.GenerateApiKey, {
84549
+ parent,
84550
+ scopes,
84551
+ displayName,
84552
+ authTypes: [
84553
+ "API_KEY_AUTHORIZATION_TYPE_BASIC" /* API_KEY_AUTHORIZATION_TYPE_BASIC */,
84554
+ "API_KEY_AUTHORIZATION_TYPE_JWT" /* API_KEY_AUTHORIZATION_TYPE_JWT */
84555
+ ]
84556
+ });
84557
+ if (!created?.key || !created.secret) {
84558
+ throw new Error("The platform returned no key.");
84559
+ }
84560
+ } catch (error2) {
84561
+ const leftover = file ? await file.discard() : "";
84562
+ if (!leftover) throw error2;
84563
+ throw new Error(`${error2?.message || error2}${leftover}`);
84443
84564
  }
84444
84565
  const credential = Buffer.from(`${created.key}:${created.secret}`).toString(
84445
84566
  "base64"
84446
84567
  );
84568
+ if (file) {
84569
+ try {
84570
+ await file.write(`INWORLD_API_KEY=${credential}
84571
+ `);
84572
+ } catch (error2) {
84573
+ const leftover = await file.discard();
84574
+ throw new Error(
84575
+ `Key ${created.key} was created, but writing it to ${file.path} failed (${error2.message || error2}). Delete that key and try again.${leftover}`
84576
+ );
84577
+ }
84578
+ }
84447
84579
  const permissions = formatApiKeyScopes(created.scopes);
84448
84580
  success("\nAPI key created.");
84449
84581
  console.log();
@@ -84452,6 +84584,14 @@ Selecting workspace: ${source_default.whiteBright(workspaceId)}`);
84452
84584
  printListItem(`Display Name: ${displayName}`);
84453
84585
  }
84454
84586
  printListItem(`Permissions: ${permissions || label}`);
84587
+ if (file) {
84588
+ printListItem(`Saved to: ${file.path}`);
84589
+ console.log();
84590
+ print(
84591
+ `The file sets ${cyan("INWORLD_API_KEY")}; load it into your environment to use the key instead of your sign-in. The CLI does not keep it.`
84592
+ );
84593
+ return;
84594
+ }
84455
84595
  printListItem(`Key: ${credential}`);
84456
84596
  console.log();
84457
84597
  print(
@@ -84462,48 +84602,57 @@ Selecting workspace: ${source_default.whiteBright(workspaceId)}`);
84462
84602
  );
84463
84603
  }
84464
84604
  };
84465
-
84466
- // src/commands/auth/login_command.ts
84467
- var offerBrowser = async (url, done) => {
84468
- print("Please visit the following URL to authenticate:");
84469
- printLink(`${url}
84470
- `);
84471
- const readlineInterface = readline3.createInterface({
84472
- input: process.stdin,
84473
- output: process.stdout
84474
- });
84475
- const enterPromise = new Promise((resolve5) => {
84476
- readlineInterface.question("Press Enter to open your browser...", () => {
84477
- resolve5("enter");
84478
- });
84479
- });
84480
- const settled = done.then(
84481
- () => "done",
84482
- () => "done"
84483
- );
84484
- const first = await Promise.race([enterPromise, settled]);
84485
- readlineInterface.close();
84486
- if (first === "done") return;
84605
+ async function createKeyFile(path13) {
84606
+ const fullPath = resolve2(path13);
84607
+ let handle;
84487
84608
  try {
84488
- await openInBrowser(url);
84489
- success("\u2713 Browser opened");
84490
- } catch (_error) {
84491
- print(
84492
- "\u26A0 Could not open browser automatically. Please open the URL manually."
84493
- );
84609
+ handle = await open2(fullPath, "wx", 384);
84610
+ } catch (error2) {
84611
+ if (error2?.code === "EEXIST") {
84612
+ throw new Error(
84613
+ `${fullPath} already exists. Name a new file: the key is written only to a file the CLI creates.`
84614
+ );
84615
+ }
84616
+ throw new Error(`Cannot create ${fullPath}: ${error2.message || error2}`);
84494
84617
  }
84495
- console.log();
84496
- print("Waiting for authentication...");
84497
- };
84618
+ return {
84619
+ path: fullPath,
84620
+ async write(text) {
84621
+ try {
84622
+ await handle.writeFile(text);
84623
+ } finally {
84624
+ await handle.close();
84625
+ }
84626
+ },
84627
+ async discard() {
84628
+ await handle.close().catch(() => {
84629
+ });
84630
+ try {
84631
+ await unlink(fullPath);
84632
+ return "";
84633
+ } catch (error2) {
84634
+ if (error2?.code === "ENOENT") return "";
84635
+ return ` ${fullPath} could not be removed (${error2?.message || error2}); delete it.`;
84636
+ }
84637
+ }
84638
+ };
84639
+ }
84640
+
84641
+ // src/commands/auth/login_command.ts
84498
84642
  var signIn = async (source, provider) => {
84499
- const { url, done } = await startBrowserSignIn({
84643
+ const browserSignIn = await startBrowserSignIn({
84500
84644
  authUrl: source.authUrl,
84501
84645
  pageUrl: INWORLD_CLI_AUTH_URL,
84502
84646
  version: CLI_VERSION,
84503
84647
  oauthProvider: provider === "email" ? void 0 : provider
84504
84648
  });
84505
- await offerBrowser(url, done);
84506
- return done;
84649
+ await promptForSignIn(browserSignIn, {
84650
+ print,
84651
+ printLink,
84652
+ printError,
84653
+ output: process.stdout
84654
+ });
84655
+ return browserSignIn.done;
84507
84656
  };
84508
84657
  var loginAction = async (options) => {
84509
84658
  try {
@@ -84610,23 +84759,23 @@ async function confirm(options) {
84610
84759
  input: process.stdin,
84611
84760
  output: process.stdout
84612
84761
  });
84613
- return new Promise((resolve5) => {
84762
+ return new Promise((resolve6) => {
84614
84763
  rl.question(message, (answer) => {
84615
84764
  rl.close();
84616
84765
  const trimmedAnswer = answer.trim().toLowerCase();
84617
84766
  if (trimmedAnswer === "y" || trimmedAnswer === "yes") {
84618
- resolve5(true);
84767
+ resolve6(true);
84619
84768
  return;
84620
84769
  }
84621
84770
  if (trimmedAnswer === "n" || trimmedAnswer === "no") {
84622
- resolve5(false);
84771
+ resolve6(false);
84623
84772
  return;
84624
84773
  }
84625
84774
  if (trimmedAnswer === "") {
84626
- resolve5(defaultValue);
84775
+ resolve6(defaultValue);
84627
84776
  return;
84628
84777
  }
84629
- resolve5(false);
84778
+ resolve6(false);
84630
84779
  });
84631
84780
  });
84632
84781
  }
@@ -84885,15 +85034,15 @@ var Analytics = class _Analytics {
84885
85034
  * Should be called before the CLI exits
84886
85035
  */
84887
85036
  flush() {
84888
- return new Promise((resolve5) => {
85037
+ return new Promise((resolve6) => {
84889
85038
  if (!this.initialized || !this.mixpanel) {
84890
- resolve5();
85039
+ resolve6();
84891
85040
  return;
84892
85041
  }
84893
- const timeout = setTimeout(() => resolve5(), 500);
85042
+ const timeout = setTimeout(() => resolve6(), 500);
84894
85043
  setTimeout(() => {
84895
85044
  clearTimeout(timeout);
84896
- resolve5();
85045
+ resolve6();
84897
85046
  }, 100);
84898
85047
  });
84899
85048
  }
@@ -85356,10 +85505,10 @@ var sttCommand = new Command("stt").description("Speech-to-text functionality").
85356
85505
 
85357
85506
  // src/commands/tts/tts_clone_command.ts
85358
85507
  import { readFile as readFile6 } from "fs/promises";
85359
- import { resolve as resolve3 } from "path";
85508
+ import { resolve as resolve4 } from "path";
85360
85509
  var cloneCommand = new Command("clone").description("Clone a voice from an audio file (5-15 seconds, max 4MB)").argument("<audioFile>", "Path to audio file (wav, mp3, webm)").requiredOption("-n, --name <name>", "Display name for the cloned voice").option("-l, --lang <code>", "Language code (e.g., EN_US)", "EN_US").option("-t, --transcription <text>", "Transcription of the audio").option("-d, --description <text>", "Description of the voice").option("--tags <tags>", "Comma-separated tags").option("--remove-noise", "Remove background noise from audio").option("-j, --json", "Output response as JSON").action(async (audioFile, options) => {
85361
85510
  try {
85362
- const filePath = resolve3(audioFile);
85511
+ const filePath = resolve4(audioFile);
85363
85512
  const audioData = await readFile6(filePath);
85364
85513
  if (audioData.length > 4 * 1024 * 1024) {
85365
85514
  console.error(source_default.red("Error: Audio file exceeds 4MB limit"));
@@ -85424,7 +85573,7 @@ Use this voice: inworld tts synthesize "Hello" -v ${voice.voiceId}`
85424
85573
  import { writeFile as writeFile5 } from "fs/promises";
85425
85574
  import { tmpdir as tmpdir3 } from "os";
85426
85575
  import { join as join5 } from "path";
85427
- import * as readline6 from "readline";
85576
+ import * as readline5 from "readline";
85428
85577
  init_audio_player();
85429
85578
  async function savePreviewsToTemp(previews) {
85430
85579
  const paths = [];
@@ -85533,11 +85682,11 @@ Generated ${previews.length} voice preview(s):
85533
85682
  Actions: [1-${previews.length}] play a preview, [p] publish, [r] regenerate, [q] quit`
85534
85683
  )
85535
85684
  );
85536
- const rl = readline6.createInterface({
85685
+ const rl = readline5.createInterface({
85537
85686
  input: process.stdin,
85538
85687
  output: process.stdout
85539
85688
  });
85540
- const ask = (q) => new Promise((resolve5) => rl.question(q, resolve5));
85689
+ const ask = (q) => new Promise((resolve6) => rl.question(q, resolve6));
85541
85690
  let action = null;
85542
85691
  while (true) {
85543
85692
  const answer = (await ask("> ")).trim().toLowerCase();
@@ -85820,7 +85969,7 @@ var previewCommand = new Command("preview").description(
85820
85969
 
85821
85970
  // src/commands/tts/tts_synthesize_command.ts
85822
85971
  import { writeFile as writeFile6 } from "fs/promises";
85823
- import { resolve as resolve4 } from "path";
85972
+ import { resolve as resolve5 } from "path";
85824
85973
  init_audio_player();
85825
85974
  var synthesizeCommand = addGenerationOptions(new Command("synthesize")).description(
85826
85975
  'Synthesize text to speech\n\nAudio markups supported in text:\n SSML breaks: <break time="1s" /> or <break time="500ms" />\n Emotions: [happy] [sad] [angry] [surprised] [fearful] [disgusted]\n Delivery: [laughing] [whispering]\n Vocalizations: [breathe] [clear_throat] [cough] [laugh] [sigh] [yawn]\n Pronunciation: /kri\u02D0t/ (IPA in forward slashes)'
@@ -85864,7 +86013,7 @@ var synthesizeCommand = addGenerationOptions(new Command("synthesize")).descript
85864
86013
  /[^a-zA-Z0-9_-]/g,
85865
86014
  "_"
85866
86015
  );
85867
- const outputPath = resolve4(
86016
+ const outputPath = resolve5(
85868
86017
  options.output || `${safeVoice}_${Date.now()}${fileExtension}`
85869
86018
  );
85870
86019
  let response;
@@ -86224,15 +86373,18 @@ var selectWorkspaceCommand = new Command("select").description("Select a workspa
86224
86373
  }
86225
86374
  });
86226
86375
  var addKeyCommand = new Command("add-key").description(
86227
- "Create a new API key and print it once (read-only by default, --write for read/write)"
86376
+ "Create a new API key and print it once, or write it to a file with --output (read-only by default, --write for read/write)"
86228
86377
  ).option(
86229
86378
  "-w, --write",
86230
86379
  "Create with read/write permissions for voices and router"
86231
- ).option("-n, --name <name>", "Display name for the API key").action(async (options) => {
86380
+ ).option("-n, --name <name>", "Display name for the API key").option(
86381
+ "-o, --output <file>",
86382
+ "Write the key to a new file as INWORLD_API_KEY=<key> instead of printing it (on macOS and Linux, readable only by you)"
86383
+ ).action(async (options) => {
86232
86384
  await requireAuth();
86233
86385
  try {
86234
86386
  const mode = options.write ? "write" : "read";
86235
- await WorkspaceService.createApiKey(mode, options.name);
86387
+ await WorkspaceService.createApiKey(mode, options.name, options.output);
86236
86388
  process.exit(0);
86237
86389
  } catch (error2) {
86238
86390
  printError(`
@@ -86468,7 +86620,7 @@ var InworldCLI = class {
86468
86620
  })
86469
86621
  ]);
86470
86622
  const timeoutPromise = new Promise(
86471
- (resolve5) => setTimeout(resolve5, 1e3)
86623
+ (resolve6) => setTimeout(resolve6, 1e3)
86472
86624
  );
86473
86625
  await Promise.race([initPromise, timeoutPromise]);
86474
86626
  }