@sjawhar/pi-legion-envoy 5.5.11 → 5.7.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/envoy.js CHANGED
@@ -34379,6 +34379,39 @@ function subscriptionRemovedTopics(raw, sessionID) {
34379
34379
  return parsedPayload.data.topics ?? [];
34380
34380
  }
34381
34381
 
34382
+ // ../envoy-client/src/nats-auth.ts
34383
+ var import_nats = __toESM(require_mod4(), 1);
34384
+ var seedKeys = import_nats.nkeys;
34385
+ function natsAuthOptions(env) {
34386
+ const { NATS_NKEY_SEED_FILE: file2, NATS_NKEY_SEED: plain } = env;
34387
+ let seed;
34388
+ let source;
34389
+ if (file2 !== undefined) {
34390
+ if (file2 === "")
34391
+ throw new Error("NATS_NKEY_SEED_FILE is set but empty");
34392
+ seed = readSecretFile("NATS_NKEY_SEED_FILE", file2);
34393
+ source = `NATS_NKEY_SEED_FILE (${file2})`;
34394
+ } else if (plain !== undefined) {
34395
+ seed = plain.trim();
34396
+ if (seed.length === 0)
34397
+ throw new Error("NATS_NKEY_SEED is set but empty");
34398
+ source = "NATS_NKEY_SEED";
34399
+ } else {
34400
+ return {};
34401
+ }
34402
+ const bytes = new TextEncoder().encode(seed);
34403
+ let publicKey;
34404
+ try {
34405
+ publicKey = seedKeys.fromSeed(bytes).getPublicKey();
34406
+ } catch (error48) {
34407
+ throw new Error(`${source} does not hold a valid nkey seed: ${messageFor(error48)}`);
34408
+ }
34409
+ if (!publicKey.startsWith("U")) {
34410
+ throw new Error(`${source} holds an nkey seed that is not a user's (public key ${publicKey})`);
34411
+ }
34412
+ return { authenticator: import_nats.nkeyAuthenticator(bytes) };
34413
+ }
34414
+
34382
34415
  // ../envoy-client/src/tool-contract.ts
34383
34416
  var DELIVERY_CONTRACT = "Delivery is at-least-once, possibly out of order across topics; use id for dedupe and at for freshness.";
34384
34417
  var TOPIC_GUIDE = "Topic guide (all are under notifications.): agent.<session_id> (subscribe: own inbox); role.<role> " + "(publish-to; holders claim via envoy_role_set). > matches one or more trailing tokens and does not " + "match the base subject. Envoy registers the concrete base when you subscribe to <subject>.>, so " + "the recommended default remains github.<owner>.<repo>.pr.<n>.>. <owner> and <repo> are one token " + "each, with every dot in the name written _ (sjawhar/.github is github.sjawhar._github; " + "acme/site.io is github.acme.site_io), and a topic spelled with the dot receives nothing. " + "Default PR subscription: " + "github.<owner>.<repo>.pr.<n>.> (it receives the quiet PR family): pr.<n> (lifecycle: " + "opened/synchronize/closed; closed carries merged, merge_commit_sha, merged_by, head_sha), " + "pr.<n>.comment, pr.<n>.review, pr.<n>.mention, pr.<n>.checks (one head-checks settlement event: " + 'passed/failed/cancelled/skipped with failing names and URLs; re-fires with superseded_settlement: "true" ' + "when new runs appear for the same head). Other GitHub: issue.<n>, issue.<n>.comment, " + "issue.<n>.mention, mention, push.branch.<name>, push.tag.<name>, workflow.<file>.<action> (only " + "runs without an associated PR); slack.<team>.<channel>.message|mention and " + "slack.<team>.<channel>.thread.<ts>.message|mention; ghostwispr.<session>.<kind>; " + "whatsapp.<phone>.<jid>.<kind>; envoy.exceptions.<original-topic>.";
@@ -34764,7 +34797,7 @@ function sourceSession(sessionID) {
34764
34797
 
34765
34798
  // extensions/envoy.ts
34766
34799
  import { logger } from "@oh-my-pi/pi-utils";
34767
- var import_nats = __toESM(require_mod4(), 1);
34800
+ var import_nats2 = __toESM(require_mod4(), 1);
34768
34801
 
34769
34802
  // src/envoy-session.ts
34770
34803
  import path2 from "path";
@@ -34996,7 +35029,7 @@ async function copySessionID(copyToClipboard2, sessionID) {
34996
35029
  }
34997
35030
 
34998
35031
  // extensions/envoy.ts
34999
- var codec2 = import_nats.StringCodec();
35032
+ var codec2 = import_nats2.StringCodec();
35000
35033
  var NATS_RETRY_INTERVAL_MS = 15000;
35001
35034
  var CAPABILITIES_WITHOUT_BTW = DELIVERY_CAPABILITIES.filter((capability) => capability !== "btw");
35002
35035
  var ROLE_CLAIM_ENTRY = "envoy-role-claim";
@@ -35201,9 +35234,10 @@ function envoyExtension(pi) {
35201
35234
  const ensureConnection = async () => {
35202
35235
  if (connection?.isClosed() === false)
35203
35236
  return connection;
35204
- connection = await import_nats.connect({
35237
+ connection = await import_nats2.connect({
35205
35238
  servers: [...defaults.natsUrls],
35206
35239
  name: `omp-${sessionID || "unknown"}`,
35240
+ ...natsAuthOptions(process.env),
35207
35241
  reconnect: true,
35208
35242
  maxReconnectAttempts: -1,
35209
35243
  reconnectTimeWait: 2000
package/dist/legion.js CHANGED
@@ -16136,13 +16136,63 @@ function messageFor(error) {
16136
16136
  return error instanceof Error ? error.message : String(error);
16137
16137
  }
16138
16138
 
16139
- // extensions/legion.ts
16139
+ // ../envoy-client/src/nats-auth.ts
16140
16140
  var import_nats = __toESM(require_mod4(), 1);
16141
+
16142
+ // ../envoy-client/src/secret-file.ts
16143
+ import { readFileSync } from "fs";
16144
+ function readSecretFile(variable, filePath) {
16145
+ let contents;
16146
+ try {
16147
+ contents = readFileSync(filePath, "utf8");
16148
+ } catch (error) {
16149
+ throw new Error(`${variable} names ${filePath}, which could not be read: ${messageFor(error)}`);
16150
+ }
16151
+ const value = contents.trim();
16152
+ if (value.length === 0)
16153
+ throw new Error(`${variable} names ${filePath}, which is empty`);
16154
+ return value;
16155
+ }
16156
+
16157
+ // ../envoy-client/src/nats-auth.ts
16158
+ var seedKeys = import_nats.nkeys;
16159
+ function natsAuthOptions(env) {
16160
+ const { NATS_NKEY_SEED_FILE: file, NATS_NKEY_SEED: plain } = env;
16161
+ let seed;
16162
+ let source;
16163
+ if (file !== undefined) {
16164
+ if (file === "")
16165
+ throw new Error("NATS_NKEY_SEED_FILE is set but empty");
16166
+ seed = readSecretFile("NATS_NKEY_SEED_FILE", file);
16167
+ source = `NATS_NKEY_SEED_FILE (${file})`;
16168
+ } else if (plain !== undefined) {
16169
+ seed = plain.trim();
16170
+ if (seed.length === 0)
16171
+ throw new Error("NATS_NKEY_SEED is set but empty");
16172
+ source = "NATS_NKEY_SEED";
16173
+ } else {
16174
+ return {};
16175
+ }
16176
+ const bytes = new TextEncoder().encode(seed);
16177
+ let publicKey;
16178
+ try {
16179
+ publicKey = seedKeys.fromSeed(bytes).getPublicKey();
16180
+ } catch (error) {
16181
+ throw new Error(`${source} does not hold a valid nkey seed: ${messageFor(error)}`);
16182
+ }
16183
+ if (!publicKey.startsWith("U")) {
16184
+ throw new Error(`${source} holds an nkey seed that is not a user's (public key ${publicKey})`);
16185
+ }
16186
+ return { authenticator: import_nats.nkeyAuthenticator(bytes) };
16187
+ }
16188
+
16189
+ // extensions/legion.ts
16190
+ var import_nats2 = __toESM(require_mod4(), 1);
16141
16191
  import { logger } from "@oh-my-pi/pi-utils";
16142
16192
  // package.json
16143
16193
  var package_default = {
16144
16194
  name: "@sjawhar/pi-legion-envoy",
16145
- version: "5.5.11",
16195
+ version: "5.7.0",
16146
16196
  type: "module",
16147
16197
  omp: {
16148
16198
  extensions: [
@@ -16154,7 +16204,7 @@ var package_default = {
16154
16204
  ]
16155
16205
  },
16156
16206
  legion: {
16157
- daemonApiVersion: 8,
16207
+ daemonApiVersion: 9,
16158
16208
  goDaemonApiVersion: 7
16159
16209
  },
16160
16210
  repository: {
@@ -30957,21 +31007,6 @@ function zodSchemaApi(zod) {
30957
31007
  }
30958
31008
  };
30959
31009
  }
30960
- // ../envoy-client/src/secret-file.ts
30961
- import { readFileSync } from "fs";
30962
- function readSecretFile(variable, filePath) {
30963
- let contents;
30964
- try {
30965
- contents = readFileSync(filePath, "utf8");
30966
- } catch (error48) {
30967
- throw new Error(`${variable} names ${filePath}, which could not be read: ${messageFor(error48)}`);
30968
- }
30969
- const value = contents.trim();
30970
- if (value.length === 0)
30971
- throw new Error(`${variable} names ${filePath}, which is empty`);
30972
- return value;
30973
- }
30974
-
30975
31010
  // src/legion/classify.ts
30976
31011
  function classifySession(env) {
30977
31012
  if (env.LEGION_CONTROLLER !== undefined && env.LEGION_TREE !== undefined) {
@@ -32701,7 +32736,7 @@ function legionExtension(pi) {
32701
32736
  const defaults = envoyDefaultsFromEnvironment(process.env);
32702
32737
  let controlConnection;
32703
32738
  let controlSubscription;
32704
- const controlCodec = import_nats.StringCodec();
32739
+ const controlCodec = import_nats2.StringCodec();
32705
32740
  let capability;
32706
32741
  let bootstrap;
32707
32742
  const checkSubagentSession = subagentSessionCheck();
@@ -32770,9 +32805,10 @@ function legionExtension(pi) {
32770
32805
  if (defaults.natsUrls.length === 0) {
32771
32806
  throw new Error("ENVOY_NATS_URL is required for Legion control directives");
32772
32807
  }
32773
- const connection = await import_nats.connect({
32808
+ const connection = await import_nats2.connect({
32774
32809
  servers: [...defaults.natsUrls],
32775
32810
  name: `legion-control-${sessionID}`,
32811
+ ...natsAuthOptions(process.env),
32776
32812
  reconnect: true,
32777
32813
  maxReconnectAttempts: -1,
32778
32814
  reconnectTimeWait: 2000
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/pi-legion-envoy",
3
- "version": "5.5.11",
3
+ "version": "5.7.0",
4
4
  "type": "module",
5
5
  "omp": {
6
6
  "extensions": [
@@ -12,7 +12,7 @@
12
12
  ]
13
13
  },
14
14
  "legion": {
15
- "daemonApiVersion": 8,
15
+ "daemonApiVersion": 9,
16
16
  "goDaemonApiVersion": 7
17
17
  },
18
18
  "repository": {