@sanctuary-framework/mcp-server 1.1.1 → 1.1.2

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.cjs CHANGED
@@ -11887,6 +11887,20 @@ async function handleRequest(deps, req, res) {
11887
11887
  const url = new URL(req.url ?? "/", `http://${host}`);
11888
11888
  const method = (req.method ?? "GET").toUpperCase();
11889
11889
  const path = url.pathname;
11890
+ if (deps.v11Bindings) {
11891
+ const handled = await dispatchV11Request(
11892
+ {
11893
+ bindings: deps.v11Bindings,
11894
+ ...deps.authToken !== void 0 ? { authToken: deps.authToken } : {},
11895
+ loopbackAutoAuth: deps.loopbackAutoAuth ?? false
11896
+ },
11897
+ req,
11898
+ res,
11899
+ url,
11900
+ method
11901
+ );
11902
+ if (handled) return true;
11903
+ }
11890
11904
  if (!isAuthorized(deps, req, url)) {
11891
11905
  writeJSON(res, 401, { error: "unauthorized" });
11892
11906
  return true;
@@ -12067,6 +12081,7 @@ var init_api = __esm({
12067
12081
  init_registry();
12068
12082
  init_init();
12069
12083
  init_discovery();
12084
+ init_dispatch();
12070
12085
  }
12071
12086
  });
12072
12087
 
@@ -13602,6 +13617,53 @@ var init_v1_1 = __esm({
13602
13617
  init_client();
13603
13618
  }
13604
13619
  });
13620
+
13621
+ // src/dashboard/v1_1/dispatch.ts
13622
+ async function dispatchV11Request(inputs, req, res, url, method) {
13623
+ const { bindings, authToken, loopbackAutoAuth } = inputs;
13624
+ if (method === "GET" && (url.pathname === "/v1.1" || url.pathname === "/v1.1/")) {
13625
+ return handleDashboardV11Route(
13626
+ {
13627
+ identityId: bindings.identityId,
13628
+ fortressId: bindings.fortressId,
13629
+ ...authToken !== void 0 ? { authToken } : {}
13630
+ },
13631
+ req,
13632
+ res
13633
+ );
13634
+ }
13635
+ if (url.pathname.startsWith("/api/hub/")) {
13636
+ const authConfig = {
13637
+ loopbackAutoAuth,
13638
+ ...authToken !== void 0 ? { authToken } : {}
13639
+ };
13640
+ return handleHubRoute(
13641
+ { authConfig, service: bindings.hubService },
13642
+ req,
13643
+ res
13644
+ );
13645
+ }
13646
+ if (method === "GET" && url.pathname === "/api/identities") {
13647
+ const authConfig = {
13648
+ loopbackAutoAuth,
13649
+ ...authToken !== void 0 ? { authToken } : {}
13650
+ };
13651
+ const aliasReq = Object.create(req);
13652
+ aliasReq.url = "/api/hub/agents" + url.search;
13653
+ return handleHubRoute(
13654
+ { authConfig, service: bindings.hubService },
13655
+ aliasReq,
13656
+ res
13657
+ );
13658
+ }
13659
+ return false;
13660
+ }
13661
+ var init_dispatch = __esm({
13662
+ "src/dashboard/v1_1/dispatch.ts"() {
13663
+ init_api_router();
13664
+ init_v1_1();
13665
+ }
13666
+ });
13605
13667
  function isDashboardViewRoute(method, path) {
13606
13668
  if (method !== "GET") return false;
13607
13669
  return path === "/" || path === "/dashboard" || path === "/fortress" || path === "/events";
@@ -13614,8 +13676,7 @@ var init_dashboard = __esm({
13614
13676
  init_dashboard_html();
13615
13677
  init_fortress_view();
13616
13678
  init_system_prompt_generator();
13617
- init_api_router();
13618
- init_v1_1();
13679
+ init_dispatch();
13619
13680
  SESSION_TTL_REMOTE_MS = 5 * 60 * 1e3;
13620
13681
  SESSION_TTL_LOCAL_MS = 24 * 60 * 60 * 1e3;
13621
13682
  MAX_SESSIONS = 1e3;
@@ -13737,45 +13798,17 @@ var init_dashboard = __esm({
13737
13798
  */
13738
13799
  async dispatchV11(req, res, url, method) {
13739
13800
  if (!this.v11Bindings) return false;
13740
- if (method === "GET" && (url.pathname === "/v1.1" || url.pathname === "/v1.1/")) {
13741
- const handled = handleDashboardV11Route(
13742
- {
13743
- identityId: this.v11Bindings.identityId,
13744
- fortressId: this.v11Bindings.fortressId,
13745
- ...this.authToken !== void 0 ? { authToken: this.authToken } : {}
13746
- },
13747
- req,
13748
- res
13749
- );
13750
- return handled;
13751
- }
13752
- if (url.pathname.startsWith("/api/hub/")) {
13753
- const authConfig = {
13754
- loopbackAutoAuth: this._autoAuthLocalhost,
13755
- ...this.authToken !== void 0 ? { authToken: this.authToken } : {}
13756
- };
13757
- const handled = await handleHubRoute(
13758
- { authConfig, service: this.v11Bindings.hubService },
13759
- req,
13760
- res
13761
- );
13762
- return handled;
13763
- }
13764
- if (method === "GET" && url.pathname === "/api/identities") {
13765
- const authConfig = {
13766
- loopbackAutoAuth: this._autoAuthLocalhost,
13767
- ...this.authToken !== void 0 ? { authToken: this.authToken } : {}
13768
- };
13769
- const aliasReq = Object.create(req);
13770
- aliasReq.url = "/api/hub/agents" + url.search;
13771
- const handled = await handleHubRoute(
13772
- { authConfig, service: this.v11Bindings.hubService },
13773
- aliasReq,
13774
- res
13775
- );
13776
- return handled;
13777
- }
13778
- return false;
13801
+ return dispatchV11Request(
13802
+ {
13803
+ bindings: this.v11Bindings,
13804
+ ...this.authToken !== void 0 ? { authToken: this.authToken } : {},
13805
+ loopbackAutoAuth: this._autoAuthLocalhost
13806
+ },
13807
+ req,
13808
+ res,
13809
+ url,
13810
+ method
13811
+ );
13779
13812
  }
13780
13813
  /**
13781
13814
  * v0.10.2: enable (or disable) the loopback auto-auth fast path. See
@@ -30023,14 +30056,18 @@ async function startDashboardServer(options) {
30023
30056
  }
30024
30057
  }
30025
30058
  };
30026
- const deps = {
30027
- sources: options.sources,
30028
- authToken: options.authToken,
30029
- approvals: options.approvals,
30030
- onEvent
30031
- };
30059
+ let v11Bindings = null;
30060
+ let v11LoopbackAutoAuth = false;
30032
30061
  const server = http.createServer(async (req, res) => {
30033
30062
  try {
30063
+ const deps = {
30064
+ sources: options.sources,
30065
+ authToken: options.authToken,
30066
+ approvals: options.approvals,
30067
+ onEvent,
30068
+ v11Bindings,
30069
+ loopbackAutoAuth: v11LoopbackAutoAuth
30070
+ };
30034
30071
  const served = await handleRequest(deps, req, res);
30035
30072
  if (!served) {
30036
30073
  res.writeHead(404, { "Content-Type": "application/json" });
@@ -30068,7 +30105,13 @@ async function startDashboardServer(options) {
30068
30105
  publishActivity: (entry) => publish({ type: "activity", data: entry }),
30069
30106
  publishApproval: (approval) => publish({ type: "approval", data: approval }),
30070
30107
  publishInbox: (item) => publish({ type: "inbox", data: item }),
30071
- publishAgentStatus: (snapshot) => publish({ type: "agent_status", data: snapshot })
30108
+ publishAgentStatus: (snapshot) => publish({ type: "agent_status", data: snapshot }),
30109
+ setV11Bindings: (bindings) => {
30110
+ v11Bindings = bindings;
30111
+ },
30112
+ setV11LoopbackAutoAuth: (enabled) => {
30113
+ v11LoopbackAutoAuth = enabled;
30114
+ }
30072
30115
  };
30073
30116
  }
30074
30117
  var DEFAULT_PORT, DEFAULT_HOST;
@@ -31332,12 +31375,14 @@ async function runWrap(options, deps = {}) {
31332
31375
  const storagePath = resolveStoragePath();
31333
31376
  let passphraseLocation;
31334
31377
  let passphraseSource;
31378
+ let passphraseValue;
31335
31379
  if (options.passphrase) {
31336
31380
  try {
31337
31381
  const persist = deps.persistPassphrase ?? ((value) => persistUserProvidedPassphrase(value, { storagePath }));
31338
31382
  const persisted = await persist(options.passphrase);
31339
31383
  passphraseLocation = persisted.location;
31340
31384
  passphraseSource = persisted.source;
31385
+ passphraseValue = options.passphrase;
31341
31386
  console.error(
31342
31387
  `
31343
31388
  \u{1F510} Persisted user-supplied passphrase (${persisted.location}).`
@@ -31355,12 +31400,14 @@ async function runWrap(options, deps = {}) {
31355
31400
  } else if (process.env.SANCTUARY_PASSPHRASE) {
31356
31401
  passphraseLocation = "SANCTUARY_PASSPHRASE";
31357
31402
  passphraseSource = "env";
31403
+ passphraseValue = process.env.SANCTUARY_PASSPHRASE;
31358
31404
  } else {
31359
31405
  try {
31360
31406
  const resolve5 = deps.resolvePassphrase ?? (() => getOrCreatePassphrase({ storagePath }));
31361
31407
  const resolved = await resolve5();
31362
31408
  passphraseLocation = resolved.location;
31363
31409
  passphraseSource = resolved.source;
31410
+ passphraseValue = resolved.value;
31364
31411
  if (resolved.source === "generated") {
31365
31412
  console.error(
31366
31413
  `
@@ -31418,6 +31465,13 @@ async function runWrap(options, deps = {}) {
31418
31465
  if (process.env.SANCTUARY_DASHBOARD_ENABLED) {
31419
31466
  sanctuaryEnv.SANCTUARY_DASHBOARD_ENABLED = process.env.SANCTUARY_DASHBOARD_ENABLED;
31420
31467
  }
31468
+ if (options.fortress) {
31469
+ sanctuaryEnv.SANCTUARY_FORTRESS_PATH = path.resolve(options.fortress);
31470
+ } else if (process.env.SANCTUARY_FORTRESS_PATH) {
31471
+ sanctuaryEnv.SANCTUARY_FORTRESS_PATH = path.resolve(
31472
+ process.env.SANCTUARY_FORTRESS_PATH
31473
+ );
31474
+ }
31421
31475
  const rewrite = deps.rewriteConfig ?? rewriteConfigForCocoon;
31422
31476
  await rewrite(
31423
31477
  agentConfig,
@@ -31445,6 +31499,40 @@ async function runWrap(options, deps = {}) {
31445
31499
  authToken,
31446
31500
  readPackageVersion()
31447
31501
  );
31502
+ if (passphraseValue !== void 0) {
31503
+ try {
31504
+ const v11Storage = new FilesystemStorage(`${storagePath}/state`);
31505
+ let existingParams;
31506
+ try {
31507
+ const raw = await v11Storage.read("_meta", "key-params");
31508
+ if (raw) {
31509
+ existingParams = JSON.parse(bytesToString(raw));
31510
+ }
31511
+ } catch {
31512
+ }
31513
+ const derived = await deriveMasterKey(passphraseValue, existingParams);
31514
+ if (!existingParams) {
31515
+ await v11Storage.write(
31516
+ "_meta",
31517
+ "key-params",
31518
+ stringToBytes(JSON.stringify(derived.params))
31519
+ );
31520
+ }
31521
+ const wrapAuditLog = new AuditLog(v11Storage, derived.key);
31522
+ dashboard.setV11Bindings(
31523
+ buildV11Bindings({
31524
+ identityId: `fortress:${storagePath}`,
31525
+ fortressId: fortressIdFromStoragePath(storagePath),
31526
+ auditLog: wrapAuditLog
31527
+ })
31528
+ );
31529
+ dashboard.setV11LoopbackAutoAuth(true);
31530
+ } catch (err) {
31531
+ console.error(
31532
+ ` Note: v1.1 dashboard surfaces unavailable on wrap URL (${err.message}). Run \`sanctuary dashboard\` to reach them.`
31533
+ );
31534
+ }
31535
+ }
31448
31536
  const dashboardUrl = `${dashboard.url}?token=${authToken}`;
31449
31537
  const webhookCallbackPortRaw = process.env.SANCTUARY_WEBHOOK_CALLBACK_PORT;
31450
31538
  const webhookCallbackPort = webhookCallbackPortRaw ? parseInt(webhookCallbackPortRaw, 10) : void 0;
@@ -31807,6 +31895,11 @@ var init_cli2 = __esm({
31807
31895
  init_config_reader();
31808
31896
  init_passphrase();
31809
31897
  init_dashboard2();
31898
+ init_wiring();
31899
+ init_filesystem();
31900
+ init_key_derivation();
31901
+ init_encoding();
31902
+ init_audit_log();
31810
31903
  init_config();
31811
31904
  init_paths();
31812
31905
  init_runtime();
@@ -35201,10 +35294,10 @@ __export(dashboard_standalone_exports, {
35201
35294
  renderTenantDiscoveryHint: () => renderTenantDiscoveryHint,
35202
35295
  startStandaloneDashboard: () => startStandaloneDashboard
35203
35296
  });
35204
- async function discoverableSubTenants(currentStoragePath) {
35297
+ async function discoverableSubTenants(currentStoragePath, discoveryOptions) {
35205
35298
  let all;
35206
35299
  try {
35207
- all = await discoverTenants();
35300
+ all = await discoverTenants(discoveryOptions);
35208
35301
  } catch {
35209
35302
  return [];
35210
35303
  }
@@ -35607,6 +35700,9 @@ var { version: PKG_VERSION4 } = require4("../package.json");
35607
35700
  async function main() {
35608
35701
  const args = process.argv.slice(2);
35609
35702
  let passphrase = process.env.SANCTUARY_PASSPHRASE;
35703
+ if (process.env.SANCTUARY_FORTRESS_PATH && !process.env.SANCTUARY_STORAGE_PATH) {
35704
+ process.env.SANCTUARY_STORAGE_PATH = process.env.SANCTUARY_FORTRESS_PATH;
35705
+ }
35610
35706
  if (args[0] === "dashboard") {
35611
35707
  await runStandaloneDashboard(args.slice(1));
35612
35708
  return;