@inworld/cli 1.5.0 → 2.0.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/cli/inworld-mcp.js +552 -95
- package/dist/index.js +850 -685
- package/package.json +1 -1
package/dist/cli/inworld-mcp.js
CHANGED
|
@@ -14323,8 +14323,8 @@ var require_semver = __commonJS({
|
|
|
14323
14323
|
}
|
|
14324
14324
|
// preminor will bump the version up to the next minor release, and immediately
|
|
14325
14325
|
// down to pre-release. premajor and prepatch work the same way.
|
|
14326
|
-
inc(
|
|
14327
|
-
if (
|
|
14326
|
+
inc(release2, identifier, identifierBase) {
|
|
14327
|
+
if (release2.startsWith("pre")) {
|
|
14328
14328
|
if (!identifier && identifierBase === false) {
|
|
14329
14329
|
throw new Error("invalid increment argument: identifier is empty");
|
|
14330
14330
|
}
|
|
@@ -14335,7 +14335,7 @@ var require_semver = __commonJS({
|
|
|
14335
14335
|
}
|
|
14336
14336
|
}
|
|
14337
14337
|
}
|
|
14338
|
-
switch (
|
|
14338
|
+
switch (release2) {
|
|
14339
14339
|
case "premajor":
|
|
14340
14340
|
this.prerelease.length = 0;
|
|
14341
14341
|
this.patch = 0;
|
|
@@ -14426,7 +14426,7 @@ var require_semver = __commonJS({
|
|
|
14426
14426
|
break;
|
|
14427
14427
|
}
|
|
14428
14428
|
default:
|
|
14429
|
-
throw new Error(`invalid increment argument: ${
|
|
14429
|
+
throw new Error(`invalid increment argument: ${release2}`);
|
|
14430
14430
|
}
|
|
14431
14431
|
this.raw = this.format();
|
|
14432
14432
|
if (this.build.length) {
|
|
@@ -14492,7 +14492,7 @@ var require_inc = __commonJS({
|
|
|
14492
14492
|
"../../node_modules/semver/functions/inc.js"(exports, module) {
|
|
14493
14493
|
"use strict";
|
|
14494
14494
|
var SemVer = require_semver();
|
|
14495
|
-
var inc = (version2,
|
|
14495
|
+
var inc = (version2, release2, options, identifier, identifierBase) => {
|
|
14496
14496
|
if (typeof options === "string") {
|
|
14497
14497
|
identifierBase = identifier;
|
|
14498
14498
|
identifier = options;
|
|
@@ -14502,7 +14502,7 @@ var require_inc = __commonJS({
|
|
|
14502
14502
|
return new SemVer(
|
|
14503
14503
|
version2 instanceof SemVer ? version2.version : version2,
|
|
14504
14504
|
options
|
|
14505
|
-
).inc(
|
|
14505
|
+
).inc(release2, identifier, identifierBase).version;
|
|
14506
14506
|
} catch (er) {
|
|
14507
14507
|
return null;
|
|
14508
14508
|
}
|
|
@@ -16408,20 +16408,22 @@ var init_source = __esm({
|
|
|
16408
16408
|
});
|
|
16409
16409
|
|
|
16410
16410
|
// ../inworld-auth-store/dist/index.js
|
|
16411
|
-
import { createHash } from "node:crypto";
|
|
16412
|
-
|
|
16413
|
-
|
|
16414
|
-
|
|
16415
|
-
|
|
16416
|
-
|
|
16417
|
-
|
|
16418
|
-
|
|
16419
|
-
|
|
16420
|
-
|
|
16421
|
-
|
|
16422
|
-
|
|
16423
|
-
|
|
16424
|
-
|
|
16411
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
16412
|
+
import {
|
|
16413
|
+
linkSync,
|
|
16414
|
+
mkdirSync,
|
|
16415
|
+
readFileSync,
|
|
16416
|
+
unlinkSync,
|
|
16417
|
+
writeFileSync as writeFileSync2
|
|
16418
|
+
} from "node:fs";
|
|
16419
|
+
import { homedir as homedir2 } from "node:os";
|
|
16420
|
+
import { dirname, join } from "node:path";
|
|
16421
|
+
function getKeyring() {
|
|
16422
|
+
keyringLoad ??= import("@zowe/secrets-for-zowe-sdk").then(
|
|
16423
|
+
(module) => module.keyring,
|
|
16424
|
+
() => null
|
|
16425
|
+
);
|
|
16426
|
+
return keyringLoad;
|
|
16425
16427
|
}
|
|
16426
16428
|
async function generateEncryptionKey() {
|
|
16427
16429
|
const platform = process.platform;
|
|
@@ -16446,7 +16448,6 @@ async function getConf() {
|
|
|
16446
16448
|
inworldToken: { type: "string" },
|
|
16447
16449
|
expiresAt: { type: "number" },
|
|
16448
16450
|
workspace: { type: "string" },
|
|
16449
|
-
apiKey: { type: "string" },
|
|
16450
16451
|
env: { type: "string" },
|
|
16451
16452
|
authProvider: { type: "string" },
|
|
16452
16453
|
authUrl: { type: "string" }
|
|
@@ -16457,6 +16458,30 @@ async function getConf() {
|
|
|
16457
16458
|
}
|
|
16458
16459
|
return confSingleton;
|
|
16459
16460
|
}
|
|
16461
|
+
async function getRuntimeTokenConf() {
|
|
16462
|
+
if (!runtimeTokenConfSingleton) {
|
|
16463
|
+
const encryptionKey = await generateEncryptionKey();
|
|
16464
|
+
runtimeTokenConfSingleton = new Conf({
|
|
16465
|
+
projectName: "inworld-cli",
|
|
16466
|
+
configName: "runtime-token",
|
|
16467
|
+
encryptionKey,
|
|
16468
|
+
schema: {
|
|
16469
|
+
runtimeToken: {
|
|
16470
|
+
type: "object",
|
|
16471
|
+
properties: {
|
|
16472
|
+
user: { type: "string" },
|
|
16473
|
+
deployment: { type: "string" },
|
|
16474
|
+
workspace: { type: "string" },
|
|
16475
|
+
platformUrl: { type: "string" },
|
|
16476
|
+
token: { type: "string" },
|
|
16477
|
+
expiresAt: { type: "number" }
|
|
16478
|
+
}
|
|
16479
|
+
}
|
|
16480
|
+
}
|
|
16481
|
+
});
|
|
16482
|
+
}
|
|
16483
|
+
return runtimeTokenConfSingleton;
|
|
16484
|
+
}
|
|
16460
16485
|
async function readStoredCredentials() {
|
|
16461
16486
|
try {
|
|
16462
16487
|
const keyring = await getKeyring();
|
|
@@ -16479,8 +16504,115 @@ async function readStoredCredentials() {
|
|
|
16479
16504
|
throw new Error(`Failed to retrieve credentials: ${error2}`);
|
|
16480
16505
|
}
|
|
16481
16506
|
}
|
|
16507
|
+
function credentialsLockPath() {
|
|
16508
|
+
return join(homedir2(), ".config", "inworld-cli", "credentials.lock");
|
|
16509
|
+
}
|
|
16510
|
+
function lockText(path7) {
|
|
16511
|
+
try {
|
|
16512
|
+
return readFileSync(path7, "utf8");
|
|
16513
|
+
} catch {
|
|
16514
|
+
return null;
|
|
16515
|
+
}
|
|
16516
|
+
}
|
|
16517
|
+
function lockOwner(text) {
|
|
16518
|
+
try {
|
|
16519
|
+
const owner = JSON.parse(text ?? "");
|
|
16520
|
+
return typeof owner.pid === "number" && typeof owner.token === "string" ? { pid: owner.pid, token: owner.token } : null;
|
|
16521
|
+
} catch {
|
|
16522
|
+
return null;
|
|
16523
|
+
}
|
|
16524
|
+
}
|
|
16525
|
+
function isRunning(pid) {
|
|
16526
|
+
try {
|
|
16527
|
+
process.kill(pid, 0);
|
|
16528
|
+
return true;
|
|
16529
|
+
} catch (error2) {
|
|
16530
|
+
return error2.code === "EPERM";
|
|
16531
|
+
}
|
|
16532
|
+
}
|
|
16533
|
+
function isAbandoned(text) {
|
|
16534
|
+
const owner = lockOwner(text);
|
|
16535
|
+
return !owner || !isRunning(owner.pid);
|
|
16536
|
+
}
|
|
16537
|
+
function remove(path7) {
|
|
16538
|
+
try {
|
|
16539
|
+
unlinkSync(path7);
|
|
16540
|
+
} catch {
|
|
16541
|
+
}
|
|
16542
|
+
}
|
|
16543
|
+
function claim(path7, owner) {
|
|
16544
|
+
const draft = `${path7}.${owner.token}`;
|
|
16545
|
+
writeFileSync2(draft, JSON.stringify(owner));
|
|
16546
|
+
try {
|
|
16547
|
+
linkSync(draft, path7);
|
|
16548
|
+
return true;
|
|
16549
|
+
} catch (error2) {
|
|
16550
|
+
if (error2.code !== "EEXIST") throw error2;
|
|
16551
|
+
return false;
|
|
16552
|
+
} finally {
|
|
16553
|
+
remove(draft);
|
|
16554
|
+
}
|
|
16555
|
+
}
|
|
16556
|
+
function release(path7, owner) {
|
|
16557
|
+
if (lockOwner(lockText(path7))?.token === owner.token) remove(path7);
|
|
16558
|
+
}
|
|
16559
|
+
function clearAbandoned(path7, text, me) {
|
|
16560
|
+
const name = createHash("sha256").update(text).digest("hex").slice(0, 32);
|
|
16561
|
+
const arbiterPath = `${path7}.takeover.${name}`;
|
|
16562
|
+
if (!claim(arbiterPath, me)) {
|
|
16563
|
+
const arbiter = lockText(arbiterPath);
|
|
16564
|
+
if (arbiter !== null && isAbandoned(arbiter)) {
|
|
16565
|
+
clearAbandoned(arbiterPath, arbiter, me);
|
|
16566
|
+
}
|
|
16567
|
+
return;
|
|
16568
|
+
}
|
|
16569
|
+
try {
|
|
16570
|
+
if (lockText(path7) === text) remove(path7);
|
|
16571
|
+
} finally {
|
|
16572
|
+
release(arbiterPath, me);
|
|
16573
|
+
}
|
|
16574
|
+
}
|
|
16575
|
+
function tryLock(lockPath, me) {
|
|
16576
|
+
const text = lockText(lockPath);
|
|
16577
|
+
if (text === null) return claim(lockPath, me);
|
|
16578
|
+
if (!isAbandoned(text)) return false;
|
|
16579
|
+
clearAbandoned(lockPath, text, me);
|
|
16580
|
+
return claim(lockPath, me);
|
|
16581
|
+
}
|
|
16582
|
+
async function withCredentialsLock(work) {
|
|
16583
|
+
const lockPath = credentialsLockPath();
|
|
16584
|
+
mkdirSync(dirname(lockPath), { recursive: true });
|
|
16585
|
+
const me = { pid: process.pid, token: randomUUID() };
|
|
16586
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
16587
|
+
while (!tryLock(lockPath, me)) {
|
|
16588
|
+
if (Date.now() > deadline) {
|
|
16589
|
+
throw new Error(
|
|
16590
|
+
`The credential store is busy: another Inworld process holds ${lockPath}. Try again.`
|
|
16591
|
+
);
|
|
16592
|
+
}
|
|
16593
|
+
await new Promise((resolve2) => setTimeout(resolve2, LOCK_RETRY_MS));
|
|
16594
|
+
}
|
|
16595
|
+
try {
|
|
16596
|
+
return await work();
|
|
16597
|
+
} finally {
|
|
16598
|
+
release(lockPath, me);
|
|
16599
|
+
}
|
|
16600
|
+
}
|
|
16482
16601
|
async function writeStoredCredentials(credentials, options) {
|
|
16602
|
+
return withCredentialsLock(() => writeCredentials(credentials, options));
|
|
16603
|
+
}
|
|
16604
|
+
async function updateStoredCredentials(change, options) {
|
|
16605
|
+
return withCredentialsLock(async () => {
|
|
16606
|
+
const current = await readStoredCredentials();
|
|
16607
|
+
const next = change(current);
|
|
16608
|
+
if (next === void 0) return { credentials: current };
|
|
16609
|
+
const { saved } = await writeCredentials(next, options);
|
|
16610
|
+
return { credentials: withoutLegacyApiKey(next), saved };
|
|
16611
|
+
});
|
|
16612
|
+
}
|
|
16613
|
+
async function writeCredentials(credentials, options) {
|
|
16483
16614
|
try {
|
|
16615
|
+
credentials = withoutLegacyApiKey(credentials);
|
|
16484
16616
|
const keyring = await getKeyring();
|
|
16485
16617
|
if (keyring) {
|
|
16486
16618
|
try {
|
|
@@ -16502,7 +16634,62 @@ async function writeStoredCredentials(credentials, options) {
|
|
|
16502
16634
|
throw new Error(`Failed to save credentials: ${error2}`);
|
|
16503
16635
|
}
|
|
16504
16636
|
}
|
|
16505
|
-
|
|
16637
|
+
function withoutLegacyApiKey(credentials) {
|
|
16638
|
+
const { apiKey: _dropped, ...kept } = credentials;
|
|
16639
|
+
return kept;
|
|
16640
|
+
}
|
|
16641
|
+
async function readStoredRuntimeToken() {
|
|
16642
|
+
try {
|
|
16643
|
+
const keyring = await getKeyring();
|
|
16644
|
+
if (keyring) {
|
|
16645
|
+
try {
|
|
16646
|
+
const json = await keyring.getPassword(
|
|
16647
|
+
SERVICE_NAME,
|
|
16648
|
+
RUNTIME_TOKEN_ACCOUNT_NAME
|
|
16649
|
+
);
|
|
16650
|
+
if (json) {
|
|
16651
|
+
return JSON.parse(json);
|
|
16652
|
+
}
|
|
16653
|
+
} catch {
|
|
16654
|
+
}
|
|
16655
|
+
}
|
|
16656
|
+
const conf = await getRuntimeTokenConf();
|
|
16657
|
+
return conf.get(RUNTIME_TOKEN_CONFIG_KEY) ?? null;
|
|
16658
|
+
} catch {
|
|
16659
|
+
return null;
|
|
16660
|
+
}
|
|
16661
|
+
}
|
|
16662
|
+
async function writeStoredRuntimeToken(token) {
|
|
16663
|
+
const keyring = await getKeyring();
|
|
16664
|
+
if (keyring) {
|
|
16665
|
+
try {
|
|
16666
|
+
await keyring.setPassword(
|
|
16667
|
+
SERVICE_NAME,
|
|
16668
|
+
RUNTIME_TOKEN_ACCOUNT_NAME,
|
|
16669
|
+
JSON.stringify(token)
|
|
16670
|
+
);
|
|
16671
|
+
return;
|
|
16672
|
+
} catch {
|
|
16673
|
+
}
|
|
16674
|
+
}
|
|
16675
|
+
const conf = await getRuntimeTokenConf();
|
|
16676
|
+
conf.set(RUNTIME_TOKEN_CONFIG_KEY, token);
|
|
16677
|
+
}
|
|
16678
|
+
async function clearStoredRuntimeToken() {
|
|
16679
|
+
const keyring = await getKeyring();
|
|
16680
|
+
if (keyring) {
|
|
16681
|
+
try {
|
|
16682
|
+
await keyring.deletePassword(SERVICE_NAME, RUNTIME_TOKEN_ACCOUNT_NAME);
|
|
16683
|
+
} catch {
|
|
16684
|
+
}
|
|
16685
|
+
}
|
|
16686
|
+
try {
|
|
16687
|
+
const conf = await getRuntimeTokenConf();
|
|
16688
|
+
conf.delete(RUNTIME_TOKEN_CONFIG_KEY);
|
|
16689
|
+
} catch {
|
|
16690
|
+
}
|
|
16691
|
+
}
|
|
16692
|
+
var SERVICE_NAME, ACCOUNT_NAME, CONFIG_KEY, RUNTIME_TOKEN_ACCOUNT_NAME, RUNTIME_TOKEN_CONFIG_KEY, LOCK_RETRY_MS, LOCK_WAIT_MS, confSingleton, runtimeTokenConfSingleton, keyringLoad;
|
|
16506
16693
|
var init_dist4 = __esm({
|
|
16507
16694
|
"../inworld-auth-store/dist/index.js"() {
|
|
16508
16695
|
"use strict";
|
|
@@ -16510,9 +16697,13 @@ var init_dist4 = __esm({
|
|
|
16510
16697
|
SERVICE_NAME = "InworldCLI";
|
|
16511
16698
|
ACCOUNT_NAME = "default";
|
|
16512
16699
|
CONFIG_KEY = "credentials";
|
|
16700
|
+
RUNTIME_TOKEN_ACCOUNT_NAME = "runtime-token";
|
|
16701
|
+
RUNTIME_TOKEN_CONFIG_KEY = "runtimeToken";
|
|
16702
|
+
LOCK_RETRY_MS = 20;
|
|
16703
|
+
LOCK_WAIT_MS = 1e4;
|
|
16513
16704
|
confSingleton = null;
|
|
16514
|
-
|
|
16515
|
-
|
|
16705
|
+
runtimeTokenConfSingleton = null;
|
|
16706
|
+
keyringLoad = null;
|
|
16516
16707
|
}
|
|
16517
16708
|
});
|
|
16518
16709
|
|
|
@@ -35265,10 +35456,10 @@ var require_view = __commonJS({
|
|
|
35265
35456
|
var debug = require_src()("express:view");
|
|
35266
35457
|
var path7 = __require("node:path");
|
|
35267
35458
|
var fs5 = __require("node:fs");
|
|
35268
|
-
var
|
|
35459
|
+
var dirname3 = path7.dirname;
|
|
35269
35460
|
var basename = path7.basename;
|
|
35270
35461
|
var extname = path7.extname;
|
|
35271
|
-
var
|
|
35462
|
+
var join2 = path7.join;
|
|
35272
35463
|
var resolve2 = path7.resolve;
|
|
35273
35464
|
module.exports = View;
|
|
35274
35465
|
function View(name, options) {
|
|
@@ -35304,7 +35495,7 @@ var require_view = __commonJS({
|
|
|
35304
35495
|
for (var i = 0; i < roots.length && !path8; i++) {
|
|
35305
35496
|
var root = roots[i];
|
|
35306
35497
|
var loc = resolve2(root, name);
|
|
35307
|
-
var dir =
|
|
35498
|
+
var dir = dirname3(loc);
|
|
35308
35499
|
var file = basename(loc);
|
|
35309
35500
|
path8 = this.resolve(dir, file);
|
|
35310
35501
|
}
|
|
@@ -35330,12 +35521,12 @@ var require_view = __commonJS({
|
|
|
35330
35521
|
};
|
|
35331
35522
|
View.prototype.resolve = function resolve3(dir, file) {
|
|
35332
35523
|
var ext = this.ext;
|
|
35333
|
-
var path8 =
|
|
35524
|
+
var path8 = join2(dir, file);
|
|
35334
35525
|
var stat = tryStat(path8);
|
|
35335
35526
|
if (stat && stat.isFile()) {
|
|
35336
35527
|
return path8;
|
|
35337
35528
|
}
|
|
35338
|
-
path8 =
|
|
35529
|
+
path8 = join2(dir, basename(file, ext), "index" + ext);
|
|
35339
35530
|
stat = tryStat(path8);
|
|
35340
35531
|
if (stat && stat.isFile()) {
|
|
35341
35532
|
return path8;
|
|
@@ -39040,7 +39231,7 @@ var require_send = __commonJS({
|
|
|
39040
39231
|
var Stream = __require("stream");
|
|
39041
39232
|
var util2 = __require("util");
|
|
39042
39233
|
var extname = path7.extname;
|
|
39043
|
-
var
|
|
39234
|
+
var join2 = path7.join;
|
|
39044
39235
|
var normalize = path7.normalize;
|
|
39045
39236
|
var resolve2 = path7.resolve;
|
|
39046
39237
|
var sep = path7.sep;
|
|
@@ -39212,7 +39403,7 @@ var require_send = __commonJS({
|
|
|
39212
39403
|
return res;
|
|
39213
39404
|
}
|
|
39214
39405
|
parts = path8.split(sep);
|
|
39215
|
-
path8 = normalize(
|
|
39406
|
+
path8 = normalize(join2(root, path8));
|
|
39216
39407
|
} else {
|
|
39217
39408
|
if (UP_PATH_REGEXP.test(path8)) {
|
|
39218
39409
|
debug('malicious path "%s"', path8);
|
|
@@ -39345,7 +39536,7 @@ var require_send = __commonJS({
|
|
|
39345
39536
|
if (err) return self.onStatError(err);
|
|
39346
39537
|
return self.error(404);
|
|
39347
39538
|
}
|
|
39348
|
-
var p =
|
|
39539
|
+
var p = join2(path8, self._index[i]);
|
|
39349
39540
|
debug('stat "%s"', p);
|
|
39350
39541
|
fs5.stat(p, function(err2, stat) {
|
|
39351
39542
|
if (err2) return next(err2);
|
|
@@ -39703,9 +39894,9 @@ var require_response = __commonJS({
|
|
|
39703
39894
|
res.json = function json(obj) {
|
|
39704
39895
|
var app = this.app;
|
|
39705
39896
|
var escape2 = app.get("json escape");
|
|
39706
|
-
var
|
|
39897
|
+
var replacer2 = app.get("json replacer");
|
|
39707
39898
|
var spaces = app.get("json spaces");
|
|
39708
|
-
var body = stringify(obj,
|
|
39899
|
+
var body = stringify(obj, replacer2, spaces, escape2);
|
|
39709
39900
|
if (!this.get("Content-Type")) {
|
|
39710
39901
|
this.set("Content-Type", "application/json");
|
|
39711
39902
|
}
|
|
@@ -39714,9 +39905,9 @@ var require_response = __commonJS({
|
|
|
39714
39905
|
res.jsonp = function jsonp(obj) {
|
|
39715
39906
|
var app = this.app;
|
|
39716
39907
|
var escape2 = app.get("json escape");
|
|
39717
|
-
var
|
|
39908
|
+
var replacer2 = app.get("json replacer");
|
|
39718
39909
|
var spaces = app.get("json spaces");
|
|
39719
|
-
var body = stringify(obj,
|
|
39910
|
+
var body = stringify(obj, replacer2, spaces, escape2);
|
|
39720
39911
|
var callback = this.req.query[app.get("jsonp callback name")];
|
|
39721
39912
|
if (!this.get("Content-Type")) {
|
|
39722
39913
|
this.set("X-Content-Type-Options", "nosniff");
|
|
@@ -40024,8 +40215,8 @@ var require_response = __commonJS({
|
|
|
40024
40215
|
}
|
|
40025
40216
|
file.pipe(res2);
|
|
40026
40217
|
}
|
|
40027
|
-
function stringify(value,
|
|
40028
|
-
var json =
|
|
40218
|
+
function stringify(value, replacer2, spaces, escape2) {
|
|
40219
|
+
var json = replacer2 || spaces ? JSON.stringify(value, replacer2, spaces) : JSON.stringify(value);
|
|
40029
40220
|
if (escape2 && typeof json === "string") {
|
|
40030
40221
|
json = json.replace(/[<>&]/g, function(c) {
|
|
40031
40222
|
switch (c.charCodeAt(0)) {
|
|
@@ -62334,7 +62525,7 @@ var init_package = __esm({
|
|
|
62334
62525
|
"package.json"() {
|
|
62335
62526
|
package_default = {
|
|
62336
62527
|
name: "@inworld/cli",
|
|
62337
|
-
version: "
|
|
62528
|
+
version: "2.0.0",
|
|
62338
62529
|
type: "module",
|
|
62339
62530
|
main: "dist/index.js",
|
|
62340
62531
|
bin: {
|
|
@@ -62487,9 +62678,9 @@ import * as http from "node:http";
|
|
|
62487
62678
|
function decodeJwtPayload(jwt) {
|
|
62488
62679
|
const parts = jwt.split(".");
|
|
62489
62680
|
if (parts.length < 2) return null;
|
|
62490
|
-
const
|
|
62681
|
+
const b642 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
62491
62682
|
try {
|
|
62492
|
-
const json = Buffer.from(
|
|
62683
|
+
const json = Buffer.from(b642, "base64").toString("utf8");
|
|
62493
62684
|
return JSON.parse(json);
|
|
62494
62685
|
} catch {
|
|
62495
62686
|
return null;
|
|
@@ -62856,7 +63047,6 @@ async function hasUsableAuthCredentials() {
|
|
|
62856
63047
|
try {
|
|
62857
63048
|
const c = await readStoredCredentials();
|
|
62858
63049
|
if (c?.refreshToken?.trim() && identitySourceOfStore(c)) return true;
|
|
62859
|
-
if (c?.apiKey?.trim()) return true;
|
|
62860
63050
|
} catch {
|
|
62861
63051
|
}
|
|
62862
63052
|
return false;
|
|
@@ -62954,12 +63144,13 @@ var init_exchange = __esm({
|
|
|
62954
63144
|
|
|
62955
63145
|
// src/mcp/auth/cli-store-bridge.ts
|
|
62956
63146
|
async function persistRotatedRefreshToken(used, next) {
|
|
62957
|
-
|
|
62958
|
-
|
|
62959
|
-
|
|
62960
|
-
|
|
62961
|
-
|
|
62962
|
-
|
|
63147
|
+
let signedIn = false;
|
|
63148
|
+
await updateStoredCredentials((c) => {
|
|
63149
|
+
if (!c?.refreshToken) return void 0;
|
|
63150
|
+
signedIn = true;
|
|
63151
|
+
return used !== next && c.refreshToken === used ? { ...c, refreshToken: next } : void 0;
|
|
63152
|
+
});
|
|
63153
|
+
return signedIn;
|
|
62963
63154
|
}
|
|
62964
63155
|
async function saveSessionUnlessLoggedOut(session) {
|
|
62965
63156
|
saveSession(session);
|
|
@@ -63022,11 +63213,12 @@ async function currentRefreshToken(s, source) {
|
|
|
63022
63213
|
const c = await readStoredCredentials();
|
|
63023
63214
|
const stored = c ? identitySourceOfStore(c) : null;
|
|
63024
63215
|
if (c?.refreshToken && stored?.authUrl === source.authUrl) {
|
|
63025
|
-
return c.refreshToken.trim();
|
|
63216
|
+
return { token: c.refreshToken.trim(), email: c.email };
|
|
63026
63217
|
}
|
|
63027
63218
|
} catch {
|
|
63028
63219
|
}
|
|
63029
|
-
|
|
63220
|
+
const own = s.identityRefreshToken?.trim();
|
|
63221
|
+
return own ? { token: own, email: s.email } : void 0;
|
|
63030
63222
|
}
|
|
63031
63223
|
async function getValidSession() {
|
|
63032
63224
|
const fromReq = getRequestSession();
|
|
@@ -63050,8 +63242,8 @@ async function getValidSession() {
|
|
|
63050
63242
|
return isSessionActive(s) ? s : null;
|
|
63051
63243
|
}
|
|
63052
63244
|
try {
|
|
63053
|
-
const rt = await refreshIdentityToken(source, refresh);
|
|
63054
|
-
if (!await persistRotatedRefreshToken(refresh, rt.refreshToken)) {
|
|
63245
|
+
const rt = await refreshIdentityToken(source, refresh.token);
|
|
63246
|
+
if (!await persistRotatedRefreshToken(refresh.token, rt.refreshToken)) {
|
|
63055
63247
|
return null;
|
|
63056
63248
|
}
|
|
63057
63249
|
const exchanged = await exchangeIdentityToken(rt.idToken);
|
|
@@ -63061,7 +63253,9 @@ async function getValidSession() {
|
|
|
63061
63253
|
identityRefreshToken: rt.refreshToken,
|
|
63062
63254
|
authProvider: "supabase",
|
|
63063
63255
|
authUrl: source.authUrl,
|
|
63064
|
-
|
|
63256
|
+
// Whose the redeemed refresh token was, which is not always the user of
|
|
63257
|
+
// the session being replaced.
|
|
63258
|
+
email: refresh.email || rt.email
|
|
63065
63259
|
};
|
|
63066
63260
|
if (!await saveSessionUnlessLoggedOut(merged)) return null;
|
|
63067
63261
|
const next = loadSession();
|
|
@@ -63320,24 +63514,289 @@ var init_studio_config = __esm({
|
|
|
63320
63514
|
}
|
|
63321
63515
|
});
|
|
63322
63516
|
|
|
63323
|
-
//
|
|
63324
|
-
|
|
63325
|
-
|
|
63326
|
-
|
|
63517
|
+
// proto/generated/portal/fetch.pb.ts
|
|
63518
|
+
function b64Encode(buffer, start, end) {
|
|
63519
|
+
let parts = null;
|
|
63520
|
+
const chunk = [];
|
|
63521
|
+
let i = 0, j = 0, t;
|
|
63522
|
+
while (start < end) {
|
|
63523
|
+
const b = buffer[start++];
|
|
63524
|
+
switch (j) {
|
|
63525
|
+
case 0:
|
|
63526
|
+
chunk[i++] = b64[b >> 2];
|
|
63527
|
+
t = (b & 3) << 4;
|
|
63528
|
+
j = 1;
|
|
63529
|
+
break;
|
|
63530
|
+
case 1:
|
|
63531
|
+
chunk[i++] = b64[t | b >> 4];
|
|
63532
|
+
t = (b & 15) << 2;
|
|
63533
|
+
j = 2;
|
|
63534
|
+
break;
|
|
63535
|
+
case 2:
|
|
63536
|
+
chunk[i++] = b64[t | b >> 6];
|
|
63537
|
+
chunk[i++] = b64[b & 63];
|
|
63538
|
+
j = 0;
|
|
63539
|
+
break;
|
|
63540
|
+
}
|
|
63541
|
+
if (i > 8191) {
|
|
63542
|
+
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
63543
|
+
i = 0;
|
|
63544
|
+
}
|
|
63545
|
+
}
|
|
63546
|
+
if (j) {
|
|
63547
|
+
chunk[i++] = b64[t];
|
|
63548
|
+
chunk[i++] = 61;
|
|
63549
|
+
if (j === 1) chunk[i++] = 61;
|
|
63550
|
+
}
|
|
63551
|
+
if (parts) {
|
|
63552
|
+
if (i) parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
63553
|
+
return parts.join("");
|
|
63554
|
+
}
|
|
63555
|
+
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
63556
|
+
}
|
|
63557
|
+
function replacer(key, value) {
|
|
63558
|
+
if (value && value.constructor === Uint8Array) {
|
|
63559
|
+
return b64Encode(value, 0, value.length);
|
|
63560
|
+
}
|
|
63561
|
+
return value;
|
|
63562
|
+
}
|
|
63563
|
+
function fetchReq(path7, init) {
|
|
63564
|
+
const { pathPrefix, ...req } = init || {};
|
|
63565
|
+
const url = pathPrefix ? `${pathPrefix}${path7}` : path7;
|
|
63566
|
+
return fetch(url, req).then(
|
|
63567
|
+
(r) => r.json().then((body) => {
|
|
63568
|
+
if (!r.ok) {
|
|
63569
|
+
throw body;
|
|
63570
|
+
}
|
|
63571
|
+
return body;
|
|
63572
|
+
})
|
|
63573
|
+
);
|
|
63574
|
+
}
|
|
63575
|
+
var b64, s64;
|
|
63576
|
+
var init_fetch_pb = __esm({
|
|
63577
|
+
"proto/generated/portal/fetch.pb.ts"() {
|
|
63578
|
+
"use strict";
|
|
63579
|
+
b64 = new Array(64);
|
|
63580
|
+
s64 = new Array(123);
|
|
63581
|
+
for (let i = 0; i < 64; )
|
|
63582
|
+
s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
|
|
63583
|
+
}
|
|
63584
|
+
});
|
|
63585
|
+
|
|
63586
|
+
// proto/generated/portal/ai/inworld/studio/v1alpha/tokens.pb.ts
|
|
63587
|
+
var Tokens;
|
|
63588
|
+
var init_tokens_pb = __esm({
|
|
63589
|
+
"proto/generated/portal/ai/inworld/studio/v1alpha/tokens.pb.ts"() {
|
|
63590
|
+
"use strict";
|
|
63591
|
+
init_fetch_pb();
|
|
63592
|
+
Tokens = class {
|
|
63593
|
+
static GenerateSessionToken(req, initReq) {
|
|
63594
|
+
return fetchReq(
|
|
63595
|
+
`/v1alpha/tokens/sessionToken:generate`,
|
|
63596
|
+
{ ...initReq, method: "POST", body: JSON.stringify(req, replacer) }
|
|
63597
|
+
);
|
|
63598
|
+
}
|
|
63599
|
+
static GenerateDefaultSessionToken(req, initReq) {
|
|
63600
|
+
return fetchReq(
|
|
63601
|
+
`/v1alpha/${req["parent"]}/token:generate`,
|
|
63602
|
+
{ ...initReq, method: "POST", body: JSON.stringify(req, replacer) }
|
|
63603
|
+
);
|
|
63604
|
+
}
|
|
63605
|
+
};
|
|
63606
|
+
}
|
|
63607
|
+
});
|
|
63608
|
+
|
|
63609
|
+
// src/auth/runtime_credential.ts
|
|
63610
|
+
async function resolveRuntimeCredential(session) {
|
|
63611
|
+
const apiKey = apiKeyFromEnvironment();
|
|
63612
|
+
if (apiKey) return { scheme: "Basic", token: apiKey };
|
|
63613
|
+
return resolveSessionCredential(session);
|
|
63614
|
+
}
|
|
63615
|
+
function accountOf(platformToken) {
|
|
63327
63616
|
try {
|
|
63328
|
-
const
|
|
63329
|
-
|
|
63617
|
+
const payload = platformToken?.split(".")[1] ?? "";
|
|
63618
|
+
const subject = JSON.parse(
|
|
63619
|
+
Buffer.from(payload, "base64url").toString("utf8")
|
|
63620
|
+
).sub;
|
|
63621
|
+
return typeof subject === "string" && subject ? subject : null;
|
|
63330
63622
|
} catch {
|
|
63331
|
-
return
|
|
63623
|
+
return null;
|
|
63332
63624
|
}
|
|
63333
63625
|
}
|
|
63334
|
-
|
|
63335
|
-
|
|
63336
|
-
|
|
63337
|
-
|
|
63338
|
-
|
|
63626
|
+
function apiKeyFromEnvironment() {
|
|
63627
|
+
return process.env.INWORLD_API_KEY?.trim() || void 0;
|
|
63628
|
+
}
|
|
63629
|
+
async function resolveSessionCredential(session) {
|
|
63630
|
+
return { scheme: "Bearer", token: await sessionToken(session) };
|
|
63631
|
+
}
|
|
63632
|
+
async function forgetSessionToken() {
|
|
63633
|
+
await clearStoredRuntimeToken().catch(() => {
|
|
63634
|
+
});
|
|
63635
|
+
}
|
|
63636
|
+
async function fetchWithRuntimeCredential(session, url, init = {}) {
|
|
63637
|
+
const send = (credential2) => fetch(url, {
|
|
63638
|
+
...init,
|
|
63639
|
+
headers: {
|
|
63640
|
+
...plainHeaders(init.headers),
|
|
63641
|
+
Authorization: `${credential2.scheme} ${credential2.token}`
|
|
63642
|
+
}
|
|
63643
|
+
});
|
|
63644
|
+
const credential = await resolveRuntimeCredential(session);
|
|
63645
|
+
const response = await send(credential);
|
|
63646
|
+
if (response.status !== 401 || credential.scheme !== "Bearer") {
|
|
63647
|
+
return response;
|
|
63648
|
+
}
|
|
63649
|
+
await forgetSessionToken();
|
|
63650
|
+
return send(await resolveRuntimeCredential(session));
|
|
63651
|
+
}
|
|
63652
|
+
function plainHeaders(headers) {
|
|
63653
|
+
if (!headers) return {};
|
|
63654
|
+
if (headers instanceof Headers) return Object.fromEntries(headers.entries());
|
|
63655
|
+
if (Array.isArray(headers)) return Object.fromEntries(headers);
|
|
63656
|
+
return headers;
|
|
63657
|
+
}
|
|
63658
|
+
async function sessionToken(session) {
|
|
63659
|
+
for (let reading = 1; reading <= 2; reading++) {
|
|
63660
|
+
const current = await session.current();
|
|
63661
|
+
if (!current) throw new RuntimeCredentialError(SIGNED_OUT);
|
|
63662
|
+
const workspace = current.workspace?.replace(/^workspaces\//, "");
|
|
63663
|
+
if (!workspace) throw new RuntimeCredentialError(NO_WORKSPACE);
|
|
63664
|
+
const owner = {
|
|
63665
|
+
user: current.user ?? "",
|
|
63666
|
+
deployment: current.deployment,
|
|
63667
|
+
workspace,
|
|
63668
|
+
platformUrl: PLATFORM_URL2
|
|
63669
|
+
};
|
|
63670
|
+
if (current.user !== null) {
|
|
63671
|
+
const stored = await readStoredRuntimeToken();
|
|
63672
|
+
if (stored && isUsable(stored, owner)) return stored.token;
|
|
63673
|
+
}
|
|
63674
|
+
const auth = await session.platformAuth();
|
|
63675
|
+
if (!auth) throw new RuntimeCredentialError(SIGNED_OUT);
|
|
63676
|
+
const accountsKnown = current.user !== null && auth.user !== null;
|
|
63677
|
+
const sameSignIn = accountsKnown && auth.user === current.user && auth.deployment === current.deployment;
|
|
63678
|
+
if (accountsKnown && !sameSignIn) continue;
|
|
63679
|
+
const minted = await mint(owner, auth.headers);
|
|
63680
|
+
if (sameSignIn && isUsable(minted, owner)) {
|
|
63681
|
+
await writeStoredRuntimeToken(minted).catch(() => {
|
|
63682
|
+
});
|
|
63683
|
+
}
|
|
63684
|
+
return minted.token;
|
|
63685
|
+
}
|
|
63686
|
+
throw new RuntimeCredentialError(SIGN_IN_CHANGED);
|
|
63687
|
+
}
|
|
63688
|
+
function isUsable(token, owner) {
|
|
63689
|
+
return token.user === owner.user && token.deployment === owner.deployment && token.workspace === owner.workspace && token.platformUrl === owner.platformUrl && token.expiresAt - Date.now() > RENEW_MARGIN_MS;
|
|
63690
|
+
}
|
|
63691
|
+
async function mint(owner, userHeaders) {
|
|
63692
|
+
const refused = (reason) => new RuntimeCredentialError(
|
|
63693
|
+
`Could not get a session token for workspace ${owner.workspace}: ${reason}. Run \`inworld login\` if the sign-in has expired, or set INWORLD_API_KEY to use an API key.`
|
|
63339
63694
|
);
|
|
63695
|
+
let response;
|
|
63696
|
+
try {
|
|
63697
|
+
response = await Tokens.GenerateDefaultSessionToken(
|
|
63698
|
+
{ parent: `workspaces/${owner.workspace}` },
|
|
63699
|
+
{
|
|
63700
|
+
headers: { ...userHeaders, [CLIENT_INFO_HEADER]: CLIENT_INFO },
|
|
63701
|
+
pathPrefix: owner.platformUrl
|
|
63702
|
+
}
|
|
63703
|
+
);
|
|
63704
|
+
} catch (cause) {
|
|
63705
|
+
const message = cause?.message;
|
|
63706
|
+
throw refused(typeof message === "string" ? message : "request failed");
|
|
63707
|
+
}
|
|
63708
|
+
if (!response?.token) throw refused("the response carried no token");
|
|
63709
|
+
const expiresAt = Date.parse(String(response.expirationTime));
|
|
63710
|
+
return {
|
|
63711
|
+
...owner,
|
|
63712
|
+
token: response.token,
|
|
63713
|
+
expiresAt: Number.isNaN(expiresAt) ? 0 : expiresAt
|
|
63714
|
+
};
|
|
63340
63715
|
}
|
|
63716
|
+
var RuntimeCredentialError, RENEW_MARGIN_MS, SIGNED_OUT, NO_WORKSPACE, SIGN_IN_CHANGED;
|
|
63717
|
+
var init_runtime_credential = __esm({
|
|
63718
|
+
"src/auth/runtime_credential.ts"() {
|
|
63719
|
+
"use strict";
|
|
63720
|
+
init_dist4();
|
|
63721
|
+
init_constants6();
|
|
63722
|
+
init_client_info();
|
|
63723
|
+
init_tokens_pb();
|
|
63724
|
+
RuntimeCredentialError = class extends Error {
|
|
63725
|
+
};
|
|
63726
|
+
RENEW_MARGIN_MS = 2 * 60 * 1e3;
|
|
63727
|
+
SIGNED_OUT = "Not signed in. Run `inworld login`, or set INWORLD_API_KEY to use an API key.";
|
|
63728
|
+
NO_WORKSPACE = "No workspace selected. Run `inworld workspace select`, or set INWORLD_API_KEY to use an API key.";
|
|
63729
|
+
SIGN_IN_CHANGED = "The sign-in changed while this command was starting. Run it again.";
|
|
63730
|
+
}
|
|
63731
|
+
});
|
|
63732
|
+
|
|
63733
|
+
// src/mcp/runtime/credential.ts
|
|
63734
|
+
function runtimeApiFetch(url, init) {
|
|
63735
|
+
return fetchWithRuntimeCredential(mcpSession, url, init);
|
|
63736
|
+
}
|
|
63737
|
+
async function hasRuntimeCredential() {
|
|
63738
|
+
if (process.env.INWORLD_API_KEY?.trim()) return true;
|
|
63739
|
+
const current = await mcpSession.current().catch(() => null);
|
|
63740
|
+
return Boolean(current?.workspace);
|
|
63741
|
+
}
|
|
63742
|
+
var PER_REQUEST_SIGN_IN, DIFFERENT_DEPLOYMENTS, mcpSession;
|
|
63743
|
+
var init_credential = __esm({
|
|
63744
|
+
"src/mcp/runtime/credential.ts"() {
|
|
63745
|
+
"use strict";
|
|
63746
|
+
init_dist4();
|
|
63747
|
+
init_runtime_credential();
|
|
63748
|
+
init_cli_store_bridge();
|
|
63749
|
+
init_identity();
|
|
63750
|
+
init_inworld_headers();
|
|
63751
|
+
init_request_session();
|
|
63752
|
+
init_session();
|
|
63753
|
+
init_session_refresh();
|
|
63754
|
+
PER_REQUEST_SIGN_IN = "This server signs in each request separately, and such a sign-in has no workspace for runtime tools. Set INWORLD_API_KEY on the server.";
|
|
63755
|
+
DIFFERENT_DEPLOYMENTS = "The MCP session and the CLI sign-in belong to different Inworld deployments, so runtime tools have no workspace to run in. Sign in to one deployment with `inworld login`, or set INWORLD_API_KEY.";
|
|
63756
|
+
mcpSession = {
|
|
63757
|
+
async current() {
|
|
63758
|
+
if (getRequestSession()) {
|
|
63759
|
+
throw new RuntimeCredentialError(PER_REQUEST_SIGN_IN);
|
|
63760
|
+
}
|
|
63761
|
+
const stored = await readStoredCredentials().catch(() => null);
|
|
63762
|
+
const signIn = stored ? identitySourceOfStore(stored) : null;
|
|
63763
|
+
if (!stored?.refreshToken?.trim() || !signIn) return null;
|
|
63764
|
+
return {
|
|
63765
|
+
user: accountOf(stored.inworldToken),
|
|
63766
|
+
deployment: signIn.authUrl,
|
|
63767
|
+
workspace: stored.workspace ?? null
|
|
63768
|
+
};
|
|
63769
|
+
},
|
|
63770
|
+
async platformAuth() {
|
|
63771
|
+
const stored = await readStoredCredentials().catch(() => null);
|
|
63772
|
+
const signIn = stored ? identitySourceOfStore(stored) : null;
|
|
63773
|
+
if (!stored || !signIn) return null;
|
|
63774
|
+
const onDisk = loadSession();
|
|
63775
|
+
if (onDisk && identitySourceOfStore(onDisk)?.authUrl !== signIn.authUrl) {
|
|
63776
|
+
throw new RuntimeCredentialError(DIFFERENT_DEPLOYMENTS);
|
|
63777
|
+
}
|
|
63778
|
+
let session = await getValidSession();
|
|
63779
|
+
if (!session) return null;
|
|
63780
|
+
if (identitySourceOfStore(session)?.authUrl !== signIn.authUrl) {
|
|
63781
|
+
throw new RuntimeCredentialError(DIFFERENT_DEPLOYMENTS);
|
|
63782
|
+
}
|
|
63783
|
+
const signedInAccount = accountOf(stored.inworldToken);
|
|
63784
|
+
const sessionAccount = accountOf(session.token);
|
|
63785
|
+
if (signedInAccount !== null && sessionAccount !== null && sessionAccount !== signedInAccount) {
|
|
63786
|
+
session = await hydrateMcpSessionFromCliStore();
|
|
63787
|
+
if (!session) return null;
|
|
63788
|
+
}
|
|
63789
|
+
return {
|
|
63790
|
+
user: accountOf(session.token),
|
|
63791
|
+
deployment: signIn.authUrl,
|
|
63792
|
+
headers: headersForInworldSession(session)
|
|
63793
|
+
};
|
|
63794
|
+
}
|
|
63795
|
+
};
|
|
63796
|
+
}
|
|
63797
|
+
});
|
|
63798
|
+
|
|
63799
|
+
// src/mcp/inworld/studio-api.ts
|
|
63341
63800
|
function studioBase() {
|
|
63342
63801
|
return getStudioApiUrl().replace(/\/$/, "");
|
|
63343
63802
|
}
|
|
@@ -63363,13 +63822,11 @@ function extractMessage(data, fallbackStatus) {
|
|
|
63363
63822
|
return `HTTP ${fallbackStatus}`;
|
|
63364
63823
|
}
|
|
63365
63824
|
async function studioApiGet(pathAndQuery, label = "Studio API") {
|
|
63366
|
-
const apiKey = await requireApiKey();
|
|
63367
63825
|
const path7 = pathAndQuery.startsWith("/") ? pathAndQuery : `/${pathAndQuery}`;
|
|
63368
|
-
const res = await
|
|
63826
|
+
const res = await runtimeApiFetch(`${studioBase()}${path7}`, {
|
|
63369
63827
|
method: "GET",
|
|
63370
63828
|
headers: {
|
|
63371
63829
|
[CLIENT_INFO_HEADER]: CLIENT_INFO,
|
|
63372
|
-
Authorization: `Basic ${apiKey}`,
|
|
63373
63830
|
Accept: "application/json"
|
|
63374
63831
|
}
|
|
63375
63832
|
});
|
|
@@ -63381,13 +63838,11 @@ async function studioApiGet(pathAndQuery, label = "Studio API") {
|
|
|
63381
63838
|
return data;
|
|
63382
63839
|
}
|
|
63383
63840
|
async function studioApiPostJson(path7, body, label = "Studio API") {
|
|
63384
|
-
const apiKey = await requireApiKey();
|
|
63385
63841
|
const p = path7.startsWith("/") ? path7 : `/${path7}`;
|
|
63386
|
-
const res = await
|
|
63842
|
+
const res = await runtimeApiFetch(`${studioBase()}${p}`, {
|
|
63387
63843
|
method: "POST",
|
|
63388
63844
|
headers: {
|
|
63389
63845
|
[CLIENT_INFO_HEADER]: CLIENT_INFO,
|
|
63390
|
-
Authorization: `Basic ${apiKey}`,
|
|
63391
63846
|
"Content-Type": "application/json",
|
|
63392
63847
|
Accept: "application/json"
|
|
63393
63848
|
},
|
|
@@ -63403,9 +63858,9 @@ async function studioApiPostJson(path7, body, label = "Studio API") {
|
|
|
63403
63858
|
var init_studio_api = __esm({
|
|
63404
63859
|
"src/mcp/inworld/studio-api.ts"() {
|
|
63405
63860
|
"use strict";
|
|
63406
|
-
init_dist4();
|
|
63407
63861
|
init_client_info();
|
|
63408
63862
|
init_studio_config();
|
|
63863
|
+
init_credential();
|
|
63409
63864
|
}
|
|
63410
63865
|
});
|
|
63411
63866
|
|
|
@@ -63765,17 +64220,12 @@ function runtimeSearchBase() {
|
|
|
63765
64220
|
if (override) return override.replace(/\/+$/, "");
|
|
63766
64221
|
return `${runtimeApiBase()}/api/v1/inworld-assistant`;
|
|
63767
64222
|
}
|
|
63768
|
-
async function hasApiKeyCredential() {
|
|
63769
|
-
return Boolean(await readApiKey());
|
|
63770
|
-
}
|
|
63771
64223
|
async function runtimeFetch(path7, options = {}) {
|
|
63772
|
-
const apiKey = await requireApiKey();
|
|
63773
64224
|
const url = `${runtimeApiBase()}${path7}`;
|
|
63774
|
-
const res = await
|
|
64225
|
+
const res = await runtimeApiFetch(url, {
|
|
63775
64226
|
...options,
|
|
63776
64227
|
headers: {
|
|
63777
64228
|
[CLIENT_INFO_HEADER]: CLIENT_INFO,
|
|
63778
|
-
Authorization: `Basic ${apiKey}`,
|
|
63779
64229
|
"Content-Type": "application/json",
|
|
63780
64230
|
...options.headers
|
|
63781
64231
|
}
|
|
@@ -63796,13 +64246,13 @@ var init_api2 = __esm({
|
|
|
63796
64246
|
"use strict";
|
|
63797
64247
|
init_client_info();
|
|
63798
64248
|
init_studio_config();
|
|
63799
|
-
|
|
64249
|
+
init_credential();
|
|
63800
64250
|
}
|
|
63801
64251
|
});
|
|
63802
64252
|
|
|
63803
64253
|
// src/mcp/runtime/register.ts
|
|
63804
64254
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
63805
|
-
import { dirname, resolve } from "node:path";
|
|
64255
|
+
import { dirname as dirname2, resolve } from "node:path";
|
|
63806
64256
|
function extensionForEncoding(encoding) {
|
|
63807
64257
|
const map = {
|
|
63808
64258
|
MP3: ".mp3",
|
|
@@ -63956,7 +64406,7 @@ function registerRuntimeTools(server) {
|
|
|
63956
64406
|
filePath += extensionForEncoding(audio_encoding);
|
|
63957
64407
|
}
|
|
63958
64408
|
const audioBuffer = Buffer.from(data.audioContent, "base64");
|
|
63959
|
-
await mkdir(
|
|
64409
|
+
await mkdir(dirname2(filePath), { recursive: true });
|
|
63960
64410
|
await writeFile(filePath, audioBuffer);
|
|
63961
64411
|
const result = {
|
|
63962
64412
|
file: filePath,
|
|
@@ -64335,7 +64785,7 @@ function registerRuntimeTools(server) {
|
|
|
64335
64785
|
);
|
|
64336
64786
|
}
|
|
64337
64787
|
const filePath = resolve(output_file);
|
|
64338
|
-
await mkdir(
|
|
64788
|
+
await mkdir(dirname2(filePath), { recursive: true });
|
|
64339
64789
|
await writeFile(filePath, Buffer.from(audio.data, "base64"));
|
|
64340
64790
|
return textResult({
|
|
64341
64791
|
file: filePath,
|
|
@@ -64393,7 +64843,7 @@ function registerSearchDocsTool(server) {
|
|
|
64393
64843
|
params.set("indexes", indexes.join(","));
|
|
64394
64844
|
if (top_k !== void 0) params.set("topK", String(top_k));
|
|
64395
64845
|
const url = `${runtimeSearchBase()}/search?${params.toString()}`;
|
|
64396
|
-
const apiKey =
|
|
64846
|
+
const apiKey = process.env.INWORLD_API_KEY?.trim();
|
|
64397
64847
|
const res = await fetch(url, {
|
|
64398
64848
|
headers: {
|
|
64399
64849
|
[CLIENT_INFO_HEADER]: CLIENT_INFO,
|
|
@@ -64407,7 +64857,7 @@ function registerSearchDocsTool(server) {
|
|
|
64407
64857
|
}
|
|
64408
64858
|
if (res.status === 401 || res.status === 403) {
|
|
64409
64859
|
throw new Error(
|
|
64410
|
-
apiKey ? "Inworld search rejected the API key. Check INWORLD_API_KEY
|
|
64860
|
+
apiKey ? "Inworld search rejected the API key. Check INWORLD_API_KEY." : "Inworld search requires an API key. Set INWORLD_API_KEY in the environment."
|
|
64411
64861
|
);
|
|
64412
64862
|
}
|
|
64413
64863
|
if (!res.ok) {
|
|
@@ -64438,7 +64888,6 @@ var init_register = __esm({
|
|
|
64438
64888
|
"use strict";
|
|
64439
64889
|
init_zod();
|
|
64440
64890
|
init_client_info();
|
|
64441
|
-
init_studio_api();
|
|
64442
64891
|
init_api2();
|
|
64443
64892
|
VALID_ENCODINGS = [
|
|
64444
64893
|
"MP3",
|
|
@@ -64866,6 +65315,7 @@ async function runLogin() {
|
|
|
64866
65315
|
authProvider: "supabase",
|
|
64867
65316
|
authUrl: source.authUrl
|
|
64868
65317
|
});
|
|
65318
|
+
await clearStoredRuntimeToken();
|
|
64869
65319
|
console.error();
|
|
64870
65320
|
console.error("Signed in.");
|
|
64871
65321
|
console.error(`Email: ${tokens.email}`);
|
|
@@ -64907,13 +65357,19 @@ async function hasSessionCapableCredentials() {
|
|
|
64907
65357
|
return false;
|
|
64908
65358
|
}
|
|
64909
65359
|
}
|
|
64910
|
-
async function detectToolModes() {
|
|
65360
|
+
async function detectToolModes(options = {}) {
|
|
64911
65361
|
if (process.env.INWORLD_MCP_TOOLSET === "runtime") {
|
|
64912
65362
|
return { runtime: true, session: false, runtimeOnly: true };
|
|
64913
65363
|
}
|
|
64914
65364
|
if (skipAuth()) return { runtime: true, session: true };
|
|
65365
|
+
if (options.perRequestSignIn) {
|
|
65366
|
+
return {
|
|
65367
|
+
runtime: Boolean(process.env.INWORLD_API_KEY?.trim()),
|
|
65368
|
+
session: true
|
|
65369
|
+
};
|
|
65370
|
+
}
|
|
64915
65371
|
const [runtime, session] = await Promise.all([
|
|
64916
|
-
|
|
65372
|
+
hasRuntimeCredential(),
|
|
64917
65373
|
hasSessionCapableCredentials()
|
|
64918
65374
|
]);
|
|
64919
65375
|
return { runtime, session };
|
|
@@ -65174,7 +65630,7 @@ function createMcpServer(modes) {
|
|
|
65174
65630
|
server.registerTool(
|
|
65175
65631
|
"inworld_tts_voice_preview",
|
|
65176
65632
|
{
|
|
65177
|
-
description: "Fetch a short, server-side audio preview for an existing voice (GET /tts/v1/voice:preview). Not metered or billed \u2014 ideal for catalog browsing. Returns base64 MP3 audio.
|
|
65633
|
+
description: "Fetch a short, server-side audio preview for an existing voice (GET /tts/v1/voice:preview). Not metered or billed \u2014 ideal for catalog browsing. Returns base64 MP3 audio. Authenticates with INWORLD_API_KEY, or as the signed-in user.",
|
|
65178
65634
|
inputSchema: external_exports.object({
|
|
65179
65635
|
voiceId: external_exports.string().min(1).describe(
|
|
65180
65636
|
"Voice ID (e.g. Ashley, Dennis). See inworld_voice_catalog_list."
|
|
@@ -65200,7 +65656,7 @@ function createMcpServer(modes) {
|
|
|
65200
65656
|
server.registerTool(
|
|
65201
65657
|
"inworld_voice_get",
|
|
65202
65658
|
{
|
|
65203
|
-
description: "Get a single voice's metadata by ID (GET /voices/v1/voices/{voiceId}). Read-only.
|
|
65659
|
+
description: "Get a single voice's metadata by ID (GET /voices/v1/voices/{voiceId}). Read-only. Authenticates with INWORLD_API_KEY, or as the signed-in user.",
|
|
65204
65660
|
inputSchema: external_exports.object({
|
|
65205
65661
|
voiceId: external_exports.string().min(1).describe("Voice ID (e.g. Dennis or workspace_id__voice_name).")
|
|
65206
65662
|
})
|
|
@@ -65223,7 +65679,7 @@ function createMcpServer(modes) {
|
|
|
65223
65679
|
server.registerTool(
|
|
65224
65680
|
"inworld_stt_transcribe",
|
|
65225
65681
|
{
|
|
65226
|
-
description: "Transcribe an audio clip via the Inworld Speech-to-Text API (POST /stt/v1/transcribe). The whole audio must fit in one request; for long files, chunk client-side. Pass base64-encoded audio bytes (no `data:` prefix).
|
|
65682
|
+
description: "Transcribe an audio clip via the Inworld Speech-to-Text API (POST /stt/v1/transcribe). The whole audio must fit in one request; for long files, chunk client-side. Pass base64-encoded audio bytes (no `data:` prefix). Authenticates with INWORLD_API_KEY, or as the signed-in user.",
|
|
65227
65683
|
inputSchema: external_exports.object({
|
|
65228
65684
|
audioBase64: external_exports.string().min(1).describe("Base64-encoded audio bytes (raw \u2014 no data: prefix)."),
|
|
65229
65685
|
language: external_exports.string().optional().describe("BCP-47 language code, e.g. en-US"),
|
|
@@ -65251,7 +65707,7 @@ function createMcpServer(modes) {
|
|
|
65251
65707
|
server.registerTool(
|
|
65252
65708
|
"inworld_llm_chat",
|
|
65253
65709
|
{
|
|
65254
|
-
description: "Generate a chat completion via the Inworld LLM Router (POST /llm/v1alpha/completions:completeChat). Non-streaming. Pass model id + service provider + a list of role/content messages.
|
|
65710
|
+
description: "Generate a chat completion via the Inworld LLM Router (POST /llm/v1alpha/completions:completeChat). Non-streaming. Pass model id + service provider + a list of role/content messages. Authenticates with INWORLD_API_KEY, or as the signed-in user.",
|
|
65255
65711
|
inputSchema: external_exports.object({
|
|
65256
65712
|
model: external_exports.string().min(1).describe("Model id (e.g. gpt-4o-mini, gemini-2.5-flash)"),
|
|
65257
65713
|
serviceProvider: external_exports.string().optional().describe(
|
|
@@ -65292,7 +65748,7 @@ function createMcpServer(modes) {
|
|
|
65292
65748
|
server.registerTool(
|
|
65293
65749
|
"inworld_llm_list_models",
|
|
65294
65750
|
{
|
|
65295
|
-
description: "List LLM models available to your account, with capabilities and pricing (GET /llm/v1alpha/models). Read-only.
|
|
65751
|
+
description: "List LLM models available to your account, with capabilities and pricing (GET /llm/v1alpha/models). Read-only. Authenticates with INWORLD_API_KEY, or as the signed-in user.",
|
|
65296
65752
|
inputSchema: external_exports.object({})
|
|
65297
65753
|
},
|
|
65298
65754
|
async () => {
|
|
@@ -65781,8 +66237,9 @@ async function runStdio() {
|
|
|
65781
66237
|
async function runHttp() {
|
|
65782
66238
|
const port = Number(process.env.PORT) || 3333;
|
|
65783
66239
|
const host = process.env.HOST ?? "127.0.0.1";
|
|
65784
|
-
const
|
|
65785
|
-
|
|
66240
|
+
const modes = await detectToolModes({
|
|
66241
|
+
perRequestSignIn: getMcpHttpAuthMode() === "bearer"
|
|
66242
|
+
});
|
|
65786
66243
|
const app = createMcpExpressApp({ host });
|
|
65787
66244
|
const handleMcpRequest = async (req, res) => {
|
|
65788
66245
|
const server = createMcpServer(modes);
|
|
@@ -65908,7 +66365,7 @@ var init_mcp2 = __esm({
|
|
|
65908
66365
|
init_chat();
|
|
65909
66366
|
init_models();
|
|
65910
66367
|
init_gateway2();
|
|
65911
|
-
|
|
66368
|
+
init_credential();
|
|
65912
66369
|
init_register();
|
|
65913
66370
|
init_transcribe();
|
|
65914
66371
|
init_preview();
|