@camstack/agent 1.0.1 → 1.0.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/index.js CHANGED
@@ -107,7 +107,7 @@ var os2 = __toESM(require("os"));
107
107
  var fs2 = __toESM(require("fs"));
108
108
  var path2 = __toESM(require("path"));
109
109
  var import_moleculer = require("moleculer");
110
- var import_kernel = require("@camstack/kernel");
110
+ var import_system = require("@camstack/system");
111
111
  function getLocalIps() {
112
112
  const interfaces = os2.networkInterfaces();
113
113
  const ips = [];
@@ -390,11 +390,11 @@ function createAgentService(deps) {
390
390
  registerNode: {
391
391
  handler(ctx) {
392
392
  const { params } = ctx;
393
- if (!(0, import_kernel.clusterSecretMatches)(deps.expectedClusterSecretHash, params.clusterSecretHash)) {
393
+ if (!(0, import_system.clusterSecretMatches)(deps.expectedClusterSecretHash, params.clusterSecretHash)) {
394
394
  throw new import_moleculer.Errors.MoleculerError(
395
395
  `cluster secret mismatch \u2014 node "${params.nodeId}" rejected`,
396
396
  403,
397
- import_kernel.CLUSTER_SECRET_MISMATCH_TYPE
397
+ import_system.CLUSTER_SECRET_MISMATCH_TYPE
398
398
  );
399
399
  }
400
400
  deps.onChildRegistered?.(params);
@@ -597,12 +597,12 @@ async function startAgentHttpServer(getBroker, config) {
597
597
  }
598
598
 
599
599
  // src/agent-bootstrap.ts
600
- var import_kernel3 = require("@camstack/kernel");
600
+ var import_system3 = require("@camstack/system");
601
601
  var import_types = require("@camstack/types");
602
602
  var import_types2 = require("@camstack/types");
603
603
 
604
604
  // src/agent-cap-dispatch-service.ts
605
- var import_kernel2 = require("@camstack/kernel");
605
+ var import_system2 = require("@camstack/system");
606
606
  function narrowParams(raw) {
607
607
  if (raw === null || typeof raw !== "object") {
608
608
  throw new Error(
@@ -628,7 +628,7 @@ function narrowParams(raw) {
628
628
  }
629
629
  function createAgentCapDispatchService(agentNodeId, agentUdsRegistry, logger) {
630
630
  return {
631
- name: import_kernel2.AGENT_CAP_FWD_SERVICE,
631
+ name: import_system2.AGENT_CAP_FWD_SERVICE,
632
632
  actions: {
633
633
  forward: {
634
634
  handler: async (ctx) => {
@@ -663,8 +663,8 @@ function registerAgentCapDispatch(registrar, agentUdsRegistry, logger) {
663
663
  }
664
664
 
665
665
  // src/agent-bootstrap.ts
666
- var import_core = require("@camstack/core");
667
- var agentLogManager = new import_core.LogManager(5e3);
666
+ var import_system4 = require("@camstack/system");
667
+ var agentLogManager = new import_system4.LogManager(5e3);
668
668
  async function startAgent(configPath) {
669
669
  const config = loadAgentConfig(configPath);
670
670
  if (config.hubAddress) {
@@ -687,16 +687,16 @@ async function startAgent(configPath) {
687
687
  resolvedSource = "local";
688
688
  console.log(`[Agent] Using bundled addons from ${bundledDir}`);
689
689
  } else if (explicitSource === "local") {
690
- workspaceDir = (0, import_kernel3.detectWorkspacePackagesDir)(config.dataDir);
690
+ workspaceDir = (0, import_system3.detectWorkspacePackagesDir)(config.dataDir);
691
691
  }
692
- const installer = new import_kernel3.AddonInstaller({
692
+ const installer = new import_system3.AddonInstaller({
693
693
  addonsDir: config.addonsDir,
694
694
  workspacePackagesDir: workspaceDir ?? void 0,
695
695
  installSource: resolvedSource
696
696
  });
697
- await installer.ensureRequiredPackages(import_kernel3.AddonInstaller.AGENT_PACKAGES);
697
+ await installer.ensureRequiredPackages(import_system3.AddonInstaller.AGENT_PACKAGES);
698
698
  console.log(`[Agent] Addon packages ready in ${config.addonsDir}`);
699
- let broker = (0, import_kernel3.createBroker)({
699
+ let broker = (0, import_system3.createBroker)({
700
700
  nodeID: config.nodeId,
701
701
  mode: "agent",
702
702
  hubAddress: config.hubAddress,
@@ -713,7 +713,7 @@ async function startAgent(configPath) {
713
713
  console.log(
714
714
  `[Agent] New config: hub=${fresh.hubAddress ?? "discovery"}, secret=${fresh.secret ? "yes" : "none"}`
715
715
  );
716
- broker = (0, import_kernel3.createBroker)({
716
+ broker = (0, import_system3.createBroker)({
717
717
  nodeID: config.nodeId,
718
718
  mode: "agent",
719
719
  hubAddress: fresh.hubAddress,
@@ -724,7 +724,7 @@ async function startAgent(configPath) {
724
724
  console.log("[Agent] Reconnected successfully");
725
725
  };
726
726
  const loadedAddons = /* @__PURE__ */ new Map();
727
- const subtree = new import_kernel3.HubNodeRegistry();
727
+ const subtree = new import_system3.HubNodeRegistry();
728
728
  const registerAbortController = new AbortController();
729
729
  function buildAgentOwnManifest() {
730
730
  const addonCapMap = /* @__PURE__ */ new Map();
@@ -766,15 +766,15 @@ async function startAgent(configPath) {
766
766
  allNativeCaps.push(...childNativeCaps);
767
767
  }
768
768
  }
769
- return (0, import_kernel3.buildNodeManifest)(
769
+ return (0, import_system3.buildNodeManifest)(
770
770
  config.nodeId,
771
771
  allAddons,
772
772
  allNativeCaps.length > 0 ? allNativeCaps : void 0,
773
- config.secret ? (0, import_kernel3.hashClusterSecret)(config.secret) : void 0
773
+ config.secret ? (0, import_system3.hashClusterSecret)(config.secret) : void 0
774
774
  );
775
775
  }
776
776
  function triggerUpwardRegistration() {
777
- (0, import_kernel3.callRegisterNodeWithRetry)(
777
+ (0, import_system3.callRegisterNodeWithRetry)(
778
778
  broker,
779
779
  aggregateManifest(),
780
780
  {
@@ -783,7 +783,7 @@ async function startAgent(configPath) {
783
783
  log: (msg) => console.log(`[Agent] ${msg}`)
784
784
  }
785
785
  ).catch((err) => {
786
- if ((0, import_kernel3.isClusterSecretMismatchError)(err)) {
786
+ if ((0, import_system3.isClusterSecretMismatchError)(err)) {
787
787
  consoleLogger.error(
788
788
  "hub registration rejected: cluster secret mismatch \u2014 correct CAMSTACK_CLUSTER_SECRET and restart the agent"
789
789
  );
@@ -799,7 +799,7 @@ async function startAgent(configPath) {
799
799
  child: () => consoleLogger,
800
800
  withTags: () => consoleLogger
801
801
  };
802
- const capabilityRegistry = new import_kernel3.CapabilityRegistry(consoleLogger);
802
+ const capabilityRegistry = new import_system3.CapabilityRegistry(consoleLogger);
803
803
  const agentCapabilities = [
804
804
  import_types2.storageCapability,
805
805
  import_types2.storageProviderCapability,
@@ -857,15 +857,15 @@ async function startAgent(configPath) {
857
857
  subtree.registerNode(params);
858
858
  triggerUpwardRegistration();
859
859
  },
860
- expectedClusterSecretHash: config.secret ? (0, import_kernel3.hashClusterSecret)(config.secret) : void 0
860
+ expectedClusterSecretHash: config.secret ? (0, import_system3.hashClusterSecret)(config.secret) : void 0
861
861
  });
862
862
  broker.createService(agentServiceSchema);
863
- const agentTcpPort = (0, import_kernel3.deriveAgentListenPort)(broker.nodeID);
863
+ const agentTcpPort = (0, import_system3.deriveAgentListenPort)(broker.nodeID);
864
864
  let agentParentUdsPath;
865
865
  let agentUdsRegistry;
866
866
  try {
867
867
  const agentNodeId = broker.nodeID;
868
- const onUnownedCall = (0, import_kernel3.createParentUnownedCallHandler)({
868
+ const onUnownedCall = (0, import_system3.createParentUnownedCallHandler)({
869
869
  getResolver: () => null,
870
870
  broker,
871
871
  // The agent's subtree registry — lets the broker fallback pin a
@@ -878,8 +878,8 @@ async function startAgent(configPath) {
878
878
  getLocalDispatcher: () => agentUdsRegistry ?? null,
879
879
  logger: { warn: (msg) => consoleLogger.warn(`[uds-fallback] ${msg}`) }
880
880
  });
881
- agentUdsRegistry = new import_kernel3.LocalChildRegistry({
882
- server: (0, import_kernel3.createLocalTransport)().createServer(agentNodeId),
881
+ agentUdsRegistry = new import_system3.LocalChildRegistry({
882
+ server: (0, import_system3.createLocalTransport)().createServer(agentNodeId),
883
883
  onUnownedCall
884
884
  });
885
885
  await agentUdsRegistry.start();
@@ -897,18 +897,18 @@ async function startAgent(configPath) {
897
897
  consoleLogger.info(`UDS child gone \u2014 subtree updated: ${childNodeId}`);
898
898
  });
899
899
  agentUdsRegistry.onChildLog((childId, entry) => {
900
- const workerEntry = (0, import_kernel3.udsChildLogToWorkerEntry)(childId, entry);
900
+ const workerEntry = (0, import_system3.udsChildLogToWorkerEntry)(childId, entry);
901
901
  broker.call("log-receiver.ingest", workerEntry).catch(() => {
902
902
  });
903
903
  });
904
- agentParentUdsPath = (0, import_kernel3.localEndpointPath)(agentNodeId);
904
+ agentParentUdsPath = (0, import_system3.localEndpointPath)(agentNodeId);
905
905
  consoleLogger.info(`UDS child registry listening on ${agentParentUdsPath}`);
906
906
  } catch (err) {
907
907
  consoleLogger.warn(
908
908
  `UDS child registry failed to start; children stay broker-only: ${err instanceof Error ? err.message : String(err)}`
909
909
  );
910
910
  }
911
- const processServiceSchema = (0, import_kernel3.createProcessService)(
911
+ const processServiceSchema = (0, import_system3.createProcessService)(
912
912
  broker.nodeID,
913
913
  config.dataDir,
914
914
  void 0,
@@ -917,18 +917,18 @@ async function startAgent(configPath) {
917
917
  );
918
918
  broker.createService(processServiceSchema);
919
919
  registerAgentCapDispatch(broker, agentUdsRegistry, consoleLogger);
920
- (0, import_kernel3.registerEventBusService)(broker);
921
- broker.createService((0, import_kernel3.createHwAccelService)((0, import_kernel3.createKernelHwAccel)()));
920
+ (0, import_system3.registerEventBusService)(broker);
921
+ broker.createService((0, import_system3.createHwAccelService)((0, import_system3.createKernelHwAccel)()));
922
922
  await broker.start();
923
923
  let udsEventBridgeDispose = null;
924
924
  if (agentUdsRegistry !== void 0) {
925
- const agentBrokerEventBus = (0, import_kernel3.getBrokerEventBus)(broker);
926
- udsEventBridgeDispose = (0, import_kernel3.createUdsEventBridge)({
925
+ const agentBrokerEventBus = (0, import_system3.getBrokerEventBus)(broker);
926
+ udsEventBridgeDispose = (0, import_system3.createUdsEventBridge)({
927
927
  registry: agentUdsRegistry,
928
928
  parentBus: agentBrokerEventBus,
929
929
  parentNodeId: broker.nodeID
930
930
  });
931
- const agentReadinessRegistry = (0, import_kernel3.getOrInitReadinessRegistry)(
931
+ const agentReadinessRegistry = (0, import_system3.getOrInitReadinessRegistry)(
932
932
  broker,
933
933
  agentBrokerEventBus,
934
934
  consoleLogger
@@ -997,7 +997,7 @@ async function startAgent(configPath) {
997
997
  process.on("SIGTERM", shutdown);
998
998
  process.on("SIGINT", shutdown);
999
999
  }
1000
- var AGENT_INFRA = import_kernel3.INFRA_CAPABILITIES;
1000
+ var AGENT_INFRA = import_system3.INFRA_CAPABILITIES;
1001
1001
  async function bootCoreAddons(broker, config, registry, loadedAddons, loggerFactory) {
1002
1002
  const packageDirs = resolveAddonPackageDirs(config.addonsDir);
1003
1003
  if (packageDirs.length === 0) {
@@ -1005,7 +1005,7 @@ async function bootCoreAddons(broker, config, registry, loadedAddons, loggerFact
1005
1005
  return;
1006
1006
  }
1007
1007
  console.log(`[Agent] Scanning ${packageDirs.length} addon package(s) for infra providers`);
1008
- const loader = new import_kernel3.AddonLoader();
1008
+ const loader = new import_system3.AddonLoader();
1009
1009
  for (const dir of packageDirs) {
1010
1010
  try {
1011
1011
  await loader.loadFromAddonDir(dir);
@@ -1031,7 +1031,7 @@ async function bootCoreAddons(broker, config, registry, loadedAddons, loggerFact
1031
1031
  try {
1032
1032
  const instance = new addon.addonClass();
1033
1033
  const storageProvider = registry.getSingleton("storage") ?? void 0;
1034
- const context = await (0, import_kernel3.createAddonContext)(
1034
+ const context = await (0, import_system3.createAddonContext)(
1035
1035
  broker,
1036
1036
  addon.declaration,
1037
1037
  config.dataDir,
@@ -1071,7 +1071,7 @@ async function loadClusterCapableAddons(broker, config, capabilityRegistry, load
1071
1071
  const allGroupCandidates = [];
1072
1072
  const dirToLoader = /* @__PURE__ */ new Map();
1073
1073
  for (const dir of addonPackageDirs) {
1074
- const loader = new import_kernel3.AddonLoader();
1074
+ const loader = new import_system3.AddonLoader();
1075
1075
  try {
1076
1076
  await loader.loadFromAddonDir(dir);
1077
1077
  } catch (err) {
@@ -1155,7 +1155,7 @@ async function loadClusterCapableAddons(broker, config, capabilityRegistry, load
1155
1155
  }
1156
1156
  async function loadDeployedAddons(broker, addonsDir, dataDir, loadedAddons, storageProvider, loggerFactory, capabilityRegistry) {
1157
1157
  if (!fs4.existsSync(addonsDir)) return;
1158
- const loader = new import_kernel3.AddonLoader();
1158
+ const loader = new import_system3.AddonLoader();
1159
1159
  await loader.loadFromDirectory(addonsDir);
1160
1160
  const modelsDir = storageProvider ? await storageProvider.resolve({ location: "models", relativePath: "" }).catch(() => void 0) : void 0;
1161
1161
  const contextOptions = {
@@ -1170,14 +1170,14 @@ async function loadDeployedAddons(broker, addonsDir, dataDir, loadedAddons, stor
1170
1170
  if (!(0, import_types.isDeployableToAgent)(registered.declaration)) continue;
1171
1171
  try {
1172
1172
  const instance = new registered.addonClass();
1173
- const context = await (0, import_kernel3.createAddonContext)(
1173
+ const context = await (0, import_system3.createAddonContext)(
1174
1174
  broker,
1175
1175
  registered.declaration,
1176
1176
  dataDir,
1177
1177
  contextOptions
1178
1178
  );
1179
1179
  await instance.initialize(context);
1180
- const serviceSchema = (0, import_kernel3.createAddonService)(instance, registered.declaration);
1180
+ const serviceSchema = (0, import_system3.createAddonService)(instance, registered.declaration);
1181
1181
  broker.createService(serviceSchema);
1182
1182
  loadedAddons.set(addonId, {
1183
1183
  id: addonId,