@axiom-lattice/core 13.1.0 → 13.3.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.mjs CHANGED
@@ -3319,11 +3319,13 @@ var InMemoryUserStore = class {
3319
3319
  if (updates.email !== void 0) {
3320
3320
  this.assertEmailAvailable(updates.email, id);
3321
3321
  }
3322
+ const authEpoch = updates.authEpoch !== void 0 ? updates.authEpoch : existing.authEpoch;
3322
3323
  const updated = {
3323
3324
  id: existing.id,
3324
3325
  email: updates.email ?? existing.email,
3325
3326
  name: updates.name ?? existing.name,
3326
3327
  status: updates.status ?? existing.status,
3328
+ ...authEpoch !== void 0 ? { authEpoch } : {},
3327
3329
  metadata: updates.metadata ?? existing.metadata,
3328
3330
  createdAt: existing.createdAt,
3329
3331
  updatedAt: /* @__PURE__ */ new Date()
@@ -3532,6 +3534,7 @@ import { createCipheriv, createDecipheriv, randomBytes, pbkdf2Sync } from "crypt
3532
3534
  var ALGORITHM = "aes-256-gcm";
3533
3535
  var IV_LENGTH = 16;
3534
3536
  var SALT_LENGTH = 32;
3537
+ var AUTH_TAG_LENGTH = 16;
3535
3538
  var ITERATIONS = 1e5;
3536
3539
  var DEFAULT_ENCRYPTION_KEY = "lattice-default-encryption-key-dev-only-32b!";
3537
3540
  var cachedKey = null;
@@ -3553,7 +3556,7 @@ function encrypt(plaintext, key6) {
3553
3556
  const salt = randomBytes(SALT_LENGTH);
3554
3557
  const iv = randomBytes(IV_LENGTH);
3555
3558
  const derivedKey = pbkdf2Sync(actualKey, salt, ITERATIONS, 32, "sha256");
3556
- const cipher = createCipheriv(ALGORITHM, derivedKey, iv);
3559
+ const cipher = createCipheriv(ALGORITHM, derivedKey, iv, { authTagLength: AUTH_TAG_LENGTH });
3557
3560
  const encrypted = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
3558
3561
  const authTag = cipher.getAuthTag();
3559
3562
  return Buffer.concat([salt, iv, encrypted, authTag]).toString("base64");
@@ -3563,10 +3566,10 @@ function decrypt(encrypted, key6) {
3563
3566
  const data = Buffer.from(encrypted, "base64");
3564
3567
  const salt = data.subarray(0, SALT_LENGTH);
3565
3568
  const iv = data.subarray(SALT_LENGTH, SALT_LENGTH + IV_LENGTH);
3566
- const authTag = data.subarray(-16);
3567
- const ciphertext = data.subarray(SALT_LENGTH + IV_LENGTH, -16);
3569
+ const authTag = data.subarray(-AUTH_TAG_LENGTH);
3570
+ const ciphertext = data.subarray(SALT_LENGTH + IV_LENGTH, -AUTH_TAG_LENGTH);
3568
3571
  const derivedKey = pbkdf2Sync(actualKey, salt, ITERATIONS, 32, "sha256");
3569
- const decipher = createDecipheriv(ALGORITHM, derivedKey, iv);
3572
+ const decipher = createDecipheriv(ALGORITHM, derivedKey, iv, { authTagLength: AUTH_TAG_LENGTH });
3570
3573
  decipher.setAuthTag(authTag);
3571
3574
  return Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString("utf8");
3572
3575
  }
@@ -7685,7 +7688,7 @@ function serializePluginMeta(plugin) {
7685
7688
  }
7686
7689
 
7687
7690
  // src/sandbox_lattice/sandboxPaths.ts
7688
- var NONROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.2.0";
7691
+ var NONROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.2.1";
7689
7692
  var LEGACY_ROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.1.0";
7690
7693
  function normalizeSandboxHome(value) {
7691
7694
  const trimmed = value.trim();
@@ -9122,11 +9125,62 @@ var InMemoryChannelReplyJobStore = class {
9122
9125
  }
9123
9126
  };
9124
9127
 
9128
+ // src/store_lattice/InMemorySessionStore.ts
9129
+ var InMemorySessionStore = class {
9130
+ constructor() {
9131
+ this.byId = /* @__PURE__ */ new Map();
9132
+ this.byHash = /* @__PURE__ */ new Map();
9133
+ }
9134
+ async create(record) {
9135
+ this.byId.set(record.id, { ...record });
9136
+ this.byHash.set(record.refreshTokenHash, record.id);
9137
+ }
9138
+ async findByRefreshTokenHash(hash) {
9139
+ const id = this.byHash.get(hash);
9140
+ return id ? { ...this.byId.get(id) } : null;
9141
+ }
9142
+ async findByFamilyId(familyId) {
9143
+ const rows = [...this.byId.values()].filter((row) => row.familyId === familyId);
9144
+ const active = rows.filter((row) => !row.replacedBy && !row.revokedAt);
9145
+ const pool = active.length > 0 ? active : rows;
9146
+ pool.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
9147
+ return pool[0] ? { ...pool[0] } : null;
9148
+ }
9149
+ async rotate(oldId, next) {
9150
+ const old = this.byId.get(oldId);
9151
+ if (!old) return;
9152
+ old.replacedBy = next.id;
9153
+ old.lastUsedAt = next.createdAt;
9154
+ this.byId.set(oldId, old);
9155
+ await this.create(next);
9156
+ }
9157
+ async revokeFamily(familyId, _reason) {
9158
+ const now = /* @__PURE__ */ new Date();
9159
+ for (const row of this.byId.values()) {
9160
+ if (row.familyId === familyId && !row.revokedAt) row.revokedAt = now;
9161
+ }
9162
+ }
9163
+ async revokeAllForUser(userId, _reason) {
9164
+ const now = /* @__PURE__ */ new Date();
9165
+ for (const row of this.byId.values()) {
9166
+ if (row.userId === userId && !row.revokedAt) row.revokedAt = now;
9167
+ }
9168
+ }
9169
+ async touch(id, lastUsedAt) {
9170
+ const row = this.byId.get(id);
9171
+ if (row) row.lastUsedAt = lastUsedAt;
9172
+ }
9173
+ async listForUser(userId) {
9174
+ return [...this.byId.values()].filter((row) => row.userId === userId).map((row) => ({ ...row }));
9175
+ }
9176
+ };
9177
+
9125
9178
  // src/store_lattice/configureStores.ts
9126
9179
  var _disposables = [];
9127
9180
  var _cleanupRegistered = false;
9128
9181
  var _inMemoryAgentRunWarningEmitted = false;
9129
9182
  var _inMemoryChannelReplyJobWarningEmitted = false;
9183
+ var _inMemorySessionWarningEmitted = false;
9130
9184
  function registerSignalCleanup() {
9131
9185
  if (_cleanupRegistered) return;
9132
9186
  _cleanupRegistered = true;
@@ -9186,6 +9240,20 @@ async function configureStores(stores, options = {}) {
9186
9240
  }
9187
9241
  storeLatticeManager.registerLattice("default", "channelReplyJob", channelReplyJob);
9188
9242
  }
9243
+ if (stores.session === void 0 && options.customStores?.session === void 0) {
9244
+ if (!_inMemorySessionWarningEmitted) {
9245
+ _inMemorySessionWarningEmitted = true;
9246
+ console.warn(
9247
+ "[configureStores] session is using InMemorySessionStore: sessions are non-durable and lost on restart. Configure a PostgreSQL session store for production."
9248
+ );
9249
+ }
9250
+ const session = new InMemorySessionStore();
9251
+ await initAndRegister(session, localDisposables);
9252
+ if (storeLatticeManager.hasLattice("default", "session")) {
9253
+ storeLatticeManager.removeLattice("default", "session");
9254
+ }
9255
+ storeLatticeManager.registerLattice("default", "session", session);
9256
+ }
9189
9257
  if (storeLatticeManager.hasLattice("default", "connection")) {
9190
9258
  const connectionStore = storeLatticeManager.getStoreLattice("default", "connection").store;
9191
9259
  ConnectionRegistry.setStore(connectionStore);
@@ -14653,6 +14721,7 @@ function getBindingRegistry() {
14653
14721
  }
14654
14722
 
14655
14723
  // src/tool_lattice/manage_binding/index.ts
14724
+ import { maskChannelInstallationSecrets } from "@axiom-lattice/protocols";
14656
14725
  function getInstallationStore() {
14657
14726
  return getStoreLattice("default", "channelInstallation").store;
14658
14727
  }
@@ -14689,6 +14758,8 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
14689
14758
  const tenantId2 = getTenantId(config);
14690
14759
  if (!tenantId2) return failure("manage_binding requires tenant execution context");
14691
14760
  if (input.channel === "room") return failure("Internal room bindings cannot be managed");
14761
+ const personalAssistantId = await resolvePersonalAssistantId(tenantId2, config);
14762
+ const personalInstallationIds = personalAssistantId ? await listPersonalInstallationIds(registry4, tenantId2, personalAssistantId) : null;
14692
14763
  switch (input.action) {
14693
14764
  case "list_installations": {
14694
14765
  const store2 = getInstallationStore();
@@ -14696,27 +14767,42 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
14696
14767
  tenantId2,
14697
14768
  input.channel
14698
14769
  );
14699
- return JSON.stringify({ success: true, data: installations.filter(isPublicInstallation) });
14770
+ return JSON.stringify({
14771
+ success: true,
14772
+ data: installations.filter(isPublicInstallation).filter((installation) => !personalInstallationIds || personalInstallationIds.has(installation.id)).map(maskChannelInstallationSecrets)
14773
+ });
14700
14774
  }
14701
14775
  case "create": {
14702
- if (!input.channel || !input.senderId || !input.agentId) {
14776
+ if (!input.channel || !input.senderId) {
14703
14777
  return JSON.stringify({ success: false, error: "create requires channel, senderId, and agentId" });
14704
14778
  }
14705
- const installId = input.channelInstallationId || await resolveInstallationId(input.channel, tenantId2);
14779
+ if (personalAssistantId && input.agentId && input.agentId !== personalAssistantId) {
14780
+ return failure("A personal assistant can only bind senders to itself");
14781
+ }
14782
+ const agentId = personalAssistantId ?? input.agentId;
14783
+ if (!agentId) {
14784
+ return JSON.stringify({ success: false, error: "create requires channel, senderId, and agentId" });
14785
+ }
14786
+ const installId = input.channelInstallationId || await resolveInstallationId(input.channel, tenantId2, personalInstallationIds);
14706
14787
  if (!installId) {
14707
14788
  return JSON.stringify({
14708
14789
  success: false,
14709
14790
  error: `No channelInstallationId provided and unable to auto-detect. Use action=list_installations to find available installations for channel "${input.channel}".`
14710
14791
  });
14711
14792
  }
14712
- const validation = await validatePublicInstallation(installId, tenantId2, input.channel);
14793
+ const validation = await validatePublicInstallation(
14794
+ installId,
14795
+ tenantId2,
14796
+ input.channel,
14797
+ personalInstallationIds
14798
+ );
14713
14799
  if (validation) return failure(validation);
14714
14800
  const binding = await registry4.create({
14715
14801
  channel: input.channel,
14716
14802
  channelInstallationId: installId,
14717
14803
  tenantId: tenantId2,
14718
14804
  senderId: input.senderId,
14719
- agentId: input.agentId,
14805
+ agentId,
14720
14806
  threadMode: input.threadMode,
14721
14807
  senderDisplayName: input.senderDisplayName
14722
14808
  });
@@ -14726,14 +14812,22 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
14726
14812
  if (!input.channel || !input.senderId) {
14727
14813
  return JSON.stringify({ success: false, error: "update requires channel and senderId" });
14728
14814
  }
14729
- const installId = input.channelInstallationId || await resolveInstallationId(input.channel, tenantId2);
14815
+ if (personalAssistantId && input.agentId && input.agentId !== personalAssistantId) {
14816
+ return failure("A personal assistant can only bind senders to itself");
14817
+ }
14818
+ const installId = input.channelInstallationId || await resolveInstallationId(input.channel, tenantId2, personalInstallationIds);
14730
14819
  if (!installId) {
14731
14820
  return JSON.stringify({
14732
14821
  success: false,
14733
14822
  error: `No channelInstallationId provided and unable to auto-detect. Use action=list_installations first.`
14734
14823
  });
14735
14824
  }
14736
- const validation = await validatePublicInstallation(installId, tenantId2, input.channel);
14825
+ const validation = await validatePublicInstallation(
14826
+ installId,
14827
+ tenantId2,
14828
+ input.channel,
14829
+ personalInstallationIds
14830
+ );
14737
14831
  if (validation) return failure(validation);
14738
14832
  const existing = await registry4.findBySubject({
14739
14833
  channel: input.channel,
@@ -14747,8 +14841,11 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
14747
14841
  if (existing.channel === "room") {
14748
14842
  return failure("Internal room bindings cannot be managed");
14749
14843
  }
14844
+ if (personalAssistantId && existing.agentId !== personalAssistantId) {
14845
+ return JSON.stringify({ success: false, error: "Binding not found" });
14846
+ }
14750
14847
  const updated = await registry4.update(tenantId2, existing.id, {
14751
- agentId: input.agentId,
14848
+ agentId: personalAssistantId ?? input.agentId,
14752
14849
  threadMode: input.threadMode,
14753
14850
  senderDisplayName: input.senderDisplayName
14754
14851
  });
@@ -14758,14 +14855,19 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
14758
14855
  if (!input.channel || !input.senderId) {
14759
14856
  return JSON.stringify({ success: false, error: "delete requires channel and senderId" });
14760
14857
  }
14761
- const installId = input.channelInstallationId || await resolveInstallationId(input.channel, tenantId2);
14858
+ const installId = input.channelInstallationId || await resolveInstallationId(input.channel, tenantId2, personalInstallationIds);
14762
14859
  if (!installId) {
14763
14860
  return JSON.stringify({
14764
14861
  success: false,
14765
14862
  error: `No channelInstallationId provided and unable to auto-detect.`
14766
14863
  });
14767
14864
  }
14768
- const validation = await validatePublicInstallation(installId, tenantId2, input.channel);
14865
+ const validation = await validatePublicInstallation(
14866
+ installId,
14867
+ tenantId2,
14868
+ input.channel,
14869
+ personalInstallationIds
14870
+ );
14769
14871
  if (validation) return failure(validation);
14770
14872
  const existing = await registry4.findBySubject({
14771
14873
  channel: input.channel,
@@ -14779,17 +14881,25 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
14779
14881
  if (existing.channel === "room") {
14780
14882
  return failure("Internal room bindings cannot be managed");
14781
14883
  }
14884
+ if (personalAssistantId && existing.agentId !== personalAssistantId) {
14885
+ return JSON.stringify({ success: false, error: "Binding not found" });
14886
+ }
14782
14887
  await registry4.delete(tenantId2, existing.id);
14783
14888
  return JSON.stringify({ success: true, message: "Binding deleted" });
14784
14889
  }
14785
14890
  case "list": {
14786
- const bindings = await registry4.list({
14891
+ if (personalAssistantId && input.agentId && input.agentId !== personalAssistantId) {
14892
+ return failure("A personal assistant can only list its own bindings");
14893
+ }
14894
+ const listed = await registry4.list({
14787
14895
  channel: input.channel,
14788
- agentId: input.agentId,
14896
+ agentId: personalAssistantId ?? input.agentId,
14789
14897
  tenantId: tenantId2,
14790
14898
  channelInstallationId: input.channelInstallationId,
14791
- excludeChannels: ["room"]
14899
+ excludeChannels: ["room"],
14900
+ ...personalAssistantId ? { limit: 500 } : {}
14792
14901
  });
14902
+ const bindings = personalInstallationIds ? listed.filter((binding) => personalInstallationIds.has(binding.channelInstallationId)) : listed;
14793
14903
  return JSON.stringify({ success: true, data: bindings });
14794
14904
  }
14795
14905
  default:
@@ -14797,33 +14907,83 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
14797
14907
  }
14798
14908
  }
14799
14909
  );
14800
- async function resolveInstallationId(channel, tenantId2) {
14910
+ async function resolveInstallationId(channel, tenantId2, allowedIds) {
14801
14911
  const store2 = getInstallationStore();
14802
14912
  const installations = await store2.getInstallationsByTenant(tenantId2, channel);
14803
- const publicInstallations = installations.filter(isPublicInstallation);
14913
+ const publicInstallations = installations.filter(isPublicInstallation).filter((installation) => !allowedIds || allowedIds.has(installation.id));
14804
14914
  if (publicInstallations.length === 1) {
14805
14915
  return publicInstallations[0].id;
14806
14916
  }
14807
14917
  return null;
14808
14918
  }
14809
- function getTenantId(config) {
14919
+ function getRunConfig(config) {
14810
14920
  if (typeof config !== "object" || config === null) return null;
14811
14921
  const configurable = config.configurable;
14812
14922
  if (typeof configurable !== "object" || configurable === null) return null;
14813
14923
  const runConfig = configurable.runConfig;
14814
14924
  if (typeof runConfig !== "object" || runConfig === null) return null;
14815
- const tenantId2 = runConfig.tenantId;
14816
- return typeof tenantId2 === "string" && tenantId2 ? tenantId2 : null;
14925
+ return runConfig;
14926
+ }
14927
+ function getString(record, key6) {
14928
+ const value = record?.[key6];
14929
+ return typeof value === "string" && value.length > 0 ? value : null;
14930
+ }
14931
+ function getTenantId(config) {
14932
+ return getString(getRunConfig(config), "tenantId");
14933
+ }
14934
+ async function resolvePersonalAssistantId(tenantId2, config) {
14935
+ const runConfig = getRunConfig(config);
14936
+ const assistantId = getString(runConfig, "assistant_id") ?? getString(runConfig, "assistantId");
14937
+ if (!assistantId) return null;
14938
+ try {
14939
+ const assistant = await getStoreLattice("default", "assistant").store.getAssistantById(tenantId2, assistantId);
14940
+ return assistant?.ownerUserId ? assistantId : null;
14941
+ } catch {
14942
+ return null;
14943
+ }
14817
14944
  }
14818
14945
  function isPublicInstallation(installation) {
14819
14946
  return installation.channel !== "room";
14820
14947
  }
14821
- async function validatePublicInstallation(installationId, tenantId2, channel) {
14948
+ function installationReferencesAssistant(installation, assistantId) {
14949
+ if (installation.fallbackAgentId === assistantId) return true;
14950
+ const config = installation.config;
14951
+ return Boolean(
14952
+ config && typeof config === "object" && !Array.isArray(config) && config.assistantId === assistantId
14953
+ );
14954
+ }
14955
+ async function listPersonalInstallationIds(registry4, tenantId2, assistantId) {
14956
+ const ids = /* @__PURE__ */ new Set();
14957
+ const installations = await getInstallationStore().getInstallationsByTenant(tenantId2);
14958
+ for (const installation of installations) {
14959
+ if (isPublicInstallation(installation) && installationReferencesAssistant(installation, assistantId)) {
14960
+ ids.add(installation.id);
14961
+ }
14962
+ }
14963
+ for (let offset = 0; ; offset += 500) {
14964
+ const bindings = await registry4.list({
14965
+ tenantId: tenantId2,
14966
+ agentId: assistantId,
14967
+ excludeChannels: ["room"],
14968
+ limit: 500,
14969
+ offset
14970
+ });
14971
+ for (const binding of bindings) {
14972
+ if (binding.channelInstallationId) ids.add(binding.channelInstallationId);
14973
+ }
14974
+ if (bindings.length < 500) break;
14975
+ }
14976
+ return ids;
14977
+ }
14978
+ async function validatePublicInstallation(installationId, tenantId2, channel, allowedIds) {
14822
14979
  try {
14823
14980
  const installation = await getInstallationStore().getInstallationById(installationId);
14824
14981
  if (!installation || !isPublicInstallation(installation) || installation.tenantId !== tenantId2 || installation.channel !== channel) {
14825
14982
  return "Invalid public channel installation";
14826
14983
  }
14984
+ if (allowedIds && !allowedIds.has(installationId)) {
14985
+ return "Invalid public channel installation";
14986
+ }
14827
14987
  return null;
14828
14988
  } catch {
14829
14989
  return "Unable to validate public channel installation";
@@ -14833,6 +14993,60 @@ function failure(error) {
14833
14993
  return JSON.stringify({ success: false, error });
14834
14994
  }
14835
14995
 
14996
+ // src/capability/CapabilityRuntimeAccessor.ts
14997
+ function getRuntimeCapabilityConfig(executionConfig, capabilityType) {
14998
+ return readRecordProperty(getRuntimeCapabilityPolicy(executionConfig, capabilityType), "config");
14999
+ }
15000
+ function hasRuntimeCapabilityPolicy(executionConfig, capabilityType) {
15001
+ return getRuntimeCapabilityPolicy(executionConfig, capabilityType) !== void 0;
15002
+ }
15003
+ function getRuntimeCapabilityPolicy(executionConfig, capabilityType) {
15004
+ const configurable = readRecordProperty(executionConfig, "configurable");
15005
+ const context = readRecordProperty(executionConfig, "context");
15006
+ const runConfig = readRecordProperty(configurable, "runConfig") ?? readRecordProperty(context, "runConfig");
15007
+ const runtime = readRecordProperty(runConfig, "capabilityRuntime");
15008
+ const middleware = readRecordProperty(runtime, "middleware");
15009
+ return readRecordProperty(middleware, capabilityType);
15010
+ }
15011
+ function getRuntimeSkillSelection(executionConfig) {
15012
+ const policy = getRuntimeCapabilityPolicy(executionConfig, "skill");
15013
+ if (!policy) return { hasPolicy: false, enabled: true, readAll: false };
15014
+ const config = readRecordProperty(policy, "config") ?? {};
15015
+ const skills = config.skills;
15016
+ return {
15017
+ hasPolicy: true,
15018
+ enabled: policy.enabled !== false,
15019
+ ...Array.isArray(skills) && skills.every((skill) => typeof skill === "string") ? { skills: [...skills] } : {},
15020
+ readAll: config.readAll === true
15021
+ };
15022
+ }
15023
+ function readRecordProperty(value, property) {
15024
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
15025
+ const propertyValue = value[property];
15026
+ return typeof propertyValue === "object" && propertyValue !== null && !Array.isArray(propertyValue) ? propertyValue : void 0;
15027
+ }
15028
+
15029
+ // src/tool_lattice/sql/utils.ts
15030
+ function getEffectiveDatabaseKeys(exeConfig, staticDatabaseKeys) {
15031
+ const runtimeConfig = getRuntimeCapabilityConfig(exeConfig, "sql");
15032
+ if (runtimeConfig && Object.prototype.hasOwnProperty.call(runtimeConfig, "databaseKeys")) {
15033
+ const databaseKeys = runtimeConfig.databaseKeys;
15034
+ if (Array.isArray(databaseKeys) && databaseKeys.every((key6) => typeof key6 === "string")) {
15035
+ return databaseKeys;
15036
+ }
15037
+ return [];
15038
+ }
15039
+ return staticDatabaseKeys;
15040
+ }
15041
+ function getTenantIdFromConfig(exeConfig, getTenantId3) {
15042
+ const runConfig = exeConfig?.configurable?.runConfig || {};
15043
+ return runConfig.tenantId || (getTenantId3 ? getTenantId3() : "default");
15044
+ }
15045
+ function buildSslConfig(ssl, rejectUnauthorized) {
15046
+ if (!ssl) return void 0;
15047
+ return { rejectUnauthorized: rejectUnauthorized !== false };
15048
+ }
15049
+
14836
15050
  // src/tool_lattice/sql/SqlDatabaseManager.ts
14837
15051
  function splitQualifiedTableName(qualifiedName) {
14838
15052
  const parts = [];
@@ -14886,7 +15100,7 @@ var PostgresDatabase = class {
14886
15100
  database: this.config.database,
14887
15101
  user: this.config.user,
14888
15102
  password: this.config.password,
14889
- ssl: this.config.ssl ? { rejectUnauthorized: false } : void 0
15103
+ ssl: buildSslConfig(this.config.ssl, this.config.sslRejectUnauthorized)
14890
15104
  };
14891
15105
  this.pool = new Pool(poolConfig);
14892
15106
  const client = await this.pool.connect();
@@ -15046,7 +15260,7 @@ var MysqlDatabase = class {
15046
15260
  database: this.config.database,
15047
15261
  user: this.config.user,
15048
15262
  password: this.config.password,
15049
- ssl: this.config.ssl ? { rejectUnauthorized: false } : void 0
15263
+ ssl: buildSslConfig(this.config.ssl, this.config.sslRejectUnauthorized)
15050
15264
  };
15051
15265
  this.pool = mysql.createPool({
15052
15266
  ...poolConfig,
@@ -15410,58 +15624,6 @@ var sqlDatabaseManager = SqlDatabaseManager.getInstance();
15410
15624
  // src/tool_lattice/sql/list_tables_sql.ts
15411
15625
  import z4 from "zod";
15412
15626
  import { tool as tool2 } from "langchain";
15413
-
15414
- // src/capability/CapabilityRuntimeAccessor.ts
15415
- function getRuntimeCapabilityConfig(executionConfig, capabilityType) {
15416
- return readRecordProperty(getRuntimeCapabilityPolicy(executionConfig, capabilityType), "config");
15417
- }
15418
- function hasRuntimeCapabilityPolicy(executionConfig, capabilityType) {
15419
- return getRuntimeCapabilityPolicy(executionConfig, capabilityType) !== void 0;
15420
- }
15421
- function getRuntimeCapabilityPolicy(executionConfig, capabilityType) {
15422
- const configurable = readRecordProperty(executionConfig, "configurable");
15423
- const context = readRecordProperty(executionConfig, "context");
15424
- const runConfig = readRecordProperty(configurable, "runConfig") ?? readRecordProperty(context, "runConfig");
15425
- const runtime = readRecordProperty(runConfig, "capabilityRuntime");
15426
- const middleware = readRecordProperty(runtime, "middleware");
15427
- return readRecordProperty(middleware, capabilityType);
15428
- }
15429
- function getRuntimeSkillSelection(executionConfig) {
15430
- const policy = getRuntimeCapabilityPolicy(executionConfig, "skill");
15431
- if (!policy) return { hasPolicy: false, enabled: true, readAll: false };
15432
- const config = readRecordProperty(policy, "config") ?? {};
15433
- const skills = config.skills;
15434
- return {
15435
- hasPolicy: true,
15436
- enabled: policy.enabled !== false,
15437
- ...Array.isArray(skills) && skills.every((skill) => typeof skill === "string") ? { skills: [...skills] } : {},
15438
- readAll: config.readAll === true
15439
- };
15440
- }
15441
- function readRecordProperty(value, property) {
15442
- if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
15443
- const propertyValue = value[property];
15444
- return typeof propertyValue === "object" && propertyValue !== null && !Array.isArray(propertyValue) ? propertyValue : void 0;
15445
- }
15446
-
15447
- // src/tool_lattice/sql/utils.ts
15448
- function getEffectiveDatabaseKeys(exeConfig, staticDatabaseKeys) {
15449
- const runtimeConfig = getRuntimeCapabilityConfig(exeConfig, "sql");
15450
- if (runtimeConfig && Object.prototype.hasOwnProperty.call(runtimeConfig, "databaseKeys")) {
15451
- const databaseKeys = runtimeConfig.databaseKeys;
15452
- if (Array.isArray(databaseKeys) && databaseKeys.every((key6) => typeof key6 === "string")) {
15453
- return databaseKeys;
15454
- }
15455
- return [];
15456
- }
15457
- return staticDatabaseKeys;
15458
- }
15459
- function getTenantIdFromConfig(exeConfig, getTenantId3) {
15460
- const runConfig = exeConfig?.configurable?.runConfig || {};
15461
- return runConfig.tenantId || (getTenantId3 ? getTenantId3() : "default");
15462
- }
15463
-
15464
- // src/tool_lattice/sql/list_tables_sql.ts
15465
15627
  var LIST_TABLES_SQL_DESCRIPTION = `List all tables in the connected SQL database. Returns a comma-separated list of table names. Use this tool first to understand what tables are available before querying the database.`;
15466
15628
  var SIMPLE_IDENTIFIER = /^[a-z_][a-z0-9_]*$/;
15467
15629
  function formatIdentifier(identifier) {
@@ -32858,7 +33020,7 @@ import { v4 as uuidv44 } from "uuid";
32858
33020
  import { ScheduledTaskStatus as ScheduledTaskStatus3, ScheduleExecutionType as ScheduleExecutionType3 } from "@axiom-lattice/protocols";
32859
33021
  var SCHEDULE_LATTICE_KEY = "default";
32860
33022
  var AGENT_ADD_MESSAGE_TASK_TYPE = "agent.add_message";
32861
- function getRunConfig(config) {
33023
+ function getRunConfig2(config) {
32862
33024
  const configurable = config;
32863
33025
  return configurable?.configurable?.runConfig ?? {};
32864
33026
  }
@@ -32939,7 +33101,7 @@ function createSchedulerMiddleware(options = {}) {
32939
33101
  tools: [
32940
33102
  tool43(
32941
33103
  async (input, config) => {
32942
- const runConfig = getRunConfig(config);
33104
+ const runConfig = getRunConfig2(config);
32943
33105
  const scheduleLattice = getScheduleLattice(SCHEDULE_LATTICE_KEY);
32944
33106
  const taskId = uuidv44();
32945
33107
  const executeAt = input.executeAt;
@@ -32974,7 +33136,7 @@ function createSchedulerMiddleware(options = {}) {
32974
33136
  ),
32975
33137
  tool43(
32976
33138
  async (input, config) => {
32977
- const runConfig = getRunConfig(config);
33139
+ const runConfig = getRunConfig2(config);
32978
33140
  const scheduleLattice = getScheduleLattice(SCHEDULE_LATTICE_KEY);
32979
33141
  const taskId = uuidv44();
32980
33142
  const executeAt = Date.now() + input.delayMs;
@@ -33009,7 +33171,7 @@ function createSchedulerMiddleware(options = {}) {
33009
33171
  ),
33010
33172
  tool43(
33011
33173
  async (input, config) => {
33012
- const runConfig = getRunConfig(config);
33174
+ const runConfig = getRunConfig2(config);
33013
33175
  const scheduleLattice = getScheduleLattice(SCHEDULE_LATTICE_KEY);
33014
33176
  const taskId = uuidv44();
33015
33177
  const success = await scheduleLattice.client.scheduleCron(
@@ -33067,7 +33229,7 @@ function createSchedulerMiddleware(options = {}) {
33067
33229
  ),
33068
33230
  tool43(
33069
33231
  async (input, config) => {
33070
- const runConfig = getRunConfig(config);
33232
+ const runConfig = getRunConfig2(config);
33071
33233
  const scheduleLattice = getScheduleLattice(SCHEDULE_LATTICE_KEY);
33072
33234
  const storage = scheduleLattice.client.getStorage();
33073
33235
  if (!storage) {
@@ -36345,7 +36507,9 @@ function getPersonalMcpMaxServers() {
36345
36507
  return Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : PERSONAL_MCP_MAX_SERVERS;
36346
36508
  }
36347
36509
  function getPersonalMcpSyncBudgetMs() {
36348
- const raw = Number(process.env.PERSONAL_MCP_SYNC_BUDGET_MS);
36510
+ const value = process.env.PERSONAL_MCP_SYNC_BUDGET_MS;
36511
+ if (value === void 0 || value.trim() === "") return PERSONAL_MCP_SYNC_BUDGET_MS;
36512
+ const raw = Number(value);
36349
36513
  return Number.isFinite(raw) && raw >= 0 ? raw : PERSONAL_MCP_SYNC_BUDGET_MS;
36350
36514
  }
36351
36515
  var syncCache = /* @__PURE__ */ new Map();
@@ -36773,6 +36937,14 @@ function getTenantId2(exeConfig) {
36773
36937
  const runConfig = exeConfig?.configurable?.runConfig || {};
36774
36938
  return runConfig.tenantId || "default";
36775
36939
  }
36940
+ function getRuntimeUserId(exeConfig) {
36941
+ const runConfig = exeConfig?.configurable?.runConfig || {};
36942
+ const value = runConfig.user_id ?? runConfig.userId;
36943
+ return typeof value === "string" && value.length > 0 ? value : null;
36944
+ }
36945
+ function canAccessAssistant(assistant, userId) {
36946
+ return !assistant.ownerUserId || userId !== null && assistant.ownerUserId === userId;
36947
+ }
36776
36948
  function getAssistStore() {
36777
36949
  return getStoreLattice("default", "assistant").store;
36778
36950
  }
@@ -36865,17 +37037,21 @@ async function validateAgentReferences(input, tenantId2) {
36865
37037
  function slugify(name) {
36866
37038
  return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").replace(/-+/g, "-") || "agent";
36867
37039
  }
37040
+ var MAX_AGENT_ID_ALLOCATION_ATTEMPTS = 1e3;
36868
37041
  async function generateAgentId(tenantId2, name) {
36869
37042
  const store2 = getAssistStore();
36870
37043
  const base = slugify(name);
36871
37044
  let id = base;
36872
37045
  let counter = 2;
36873
- while (true) {
37046
+ for (let attempt = 0; attempt < MAX_AGENT_ID_ALLOCATION_ATTEMPTS; attempt += 1) {
36874
37047
  const existing = await store2.getAssistantById(tenantId2, id);
36875
37048
  if (!existing) return id;
36876
37049
  id = `${base}-${counter}`;
36877
- counter++;
37050
+ counter += 1;
36878
37051
  }
37052
+ throw new Error(
37053
+ `Unable to allocate a unique agent id for "${name}" after ${MAX_AGENT_ID_ALLOCATION_ATTEMPTS} attempts`
37054
+ );
36879
37055
  }
36880
37056
  registerToolLattice(
36881
37057
  "list_agents",
@@ -36887,8 +37063,9 @@ registerToolLattice(
36887
37063
  async (_input, exeConfig) => {
36888
37064
  try {
36889
37065
  const tenantId2 = getTenantId2(exeConfig);
37066
+ const userId = getRuntimeUserId(exeConfig);
36890
37067
  const store2 = getAssistStore();
36891
- const agents = await store2.getAllAssistants(tenantId2);
37068
+ const agents = (await store2.getAllAssistants(tenantId2)).filter((agent) => canAccessAssistant(agent, userId));
36892
37069
  return JSON.stringify({
36893
37070
  agents: agents.map((a) => ({
36894
37071
  id: a.id,
@@ -36918,7 +37095,7 @@ registerToolLattice(
36918
37095
  const tenantId2 = getTenantId2(exeConfig);
36919
37096
  const store2 = getAssistStore();
36920
37097
  const agent = await store2.getAssistantById(tenantId2, input.id);
36921
- if (!agent) {
37098
+ if (!agent || !canAccessAssistant(agent, getRuntimeUserId(exeConfig))) {
36922
37099
  return JSON.stringify({ error: `Agent '${input.id}' not found` });
36923
37100
  }
36924
37101
  return JSON.stringify(agent.graphDefinition);
@@ -37294,7 +37471,7 @@ registerToolLattice(
37294
37471
  const tenantId2 = getTenantId2(exeConfig);
37295
37472
  const store2 = getAssistStore();
37296
37473
  const existing = await store2.getAssistantById(tenantId2, input.id);
37297
- if (!existing) {
37474
+ if (!existing || !canAccessAssistant(existing, getRuntimeUserId(exeConfig))) {
37298
37475
  return JSON.stringify({ error: `Agent '${input.id}' not found` });
37299
37476
  }
37300
37477
  const existingConfig = existing.graphDefinition || {};
@@ -37408,9 +37585,16 @@ registerToolLattice(
37408
37585
  const tenantId2 = getTenantId2(exeConfig);
37409
37586
  const store2 = getAssistStore();
37410
37587
  const existing = await store2.getAssistantById(tenantId2, input.id);
37411
- if (!existing) {
37588
+ if (!existing || !canAccessAssistant(existing, getRuntimeUserId(exeConfig))) {
37412
37589
  return JSON.stringify({ error: `Agent '${input.id}' not found`, success: false });
37413
37590
  }
37591
+ if (existing.ownerUserId) {
37592
+ return JSON.stringify({
37593
+ success: false,
37594
+ code: "PERSONAL_ASSISTANT_DELETE_UNSUPPORTED",
37595
+ error: "Personal assistants must be deleted from the Personal Assistant page"
37596
+ });
37597
+ }
37414
37598
  const success = await store2.deleteAssistant(tenantId2, input.id);
37415
37599
  if (success) {
37416
37600
  try {
@@ -50796,7 +50980,7 @@ async function postProcessTaskMutationResponse(input) {
50796
50980
  }
50797
50981
 
50798
50982
  // src/middlewares/taskMiddleware.ts
50799
- function getRunConfig2(config) {
50983
+ function getRunConfig3(config) {
50800
50984
  const c = config;
50801
50985
  return c?.configurable?.runConfig ?? {};
50802
50986
  }
@@ -51522,7 +51706,7 @@ function updateValuesEqual(field, requested, persisted) {
51522
51706
  }
51523
51707
  function createTaskMiddleware(options = {}) {
51524
51708
  const handleManageTaskAction = async (input, config, validateExecutionResult, markMutation) => {
51525
- const rc = getRunConfig2(config);
51709
+ const rc = getRunConfig3(config);
51526
51710
  const authority = classifyTaskAuthority(rc);
51527
51711
  if (authority.kind === "invalid") return trustedContextError();
51528
51712
  const delegatedTaskId = authority.kind === "delegated" ? authority.taskId : void 0;
@@ -52650,7 +52834,7 @@ function createTaskMiddleware(options = {}) {
52650
52834
  };
52651
52835
  const reconcileExplicitExecutionResult = async (input, config, response, validationError, didMutate) => {
52652
52836
  if (input.action !== "update" && input.action !== "set_status" && input.action !== "add_activity" || !input.id) return response;
52653
- const authority = classifyTaskAuthority(getRunConfig2(config));
52837
+ const authority = classifyTaskAuthority(getRunConfig3(config));
52654
52838
  if (authority.kind === "projectRoom" || authority.kind === "projectTask" || authority.kind === "invalid") {
52655
52839
  return response;
52656
52840
  }
@@ -52663,7 +52847,7 @@ function createTaskMiddleware(options = {}) {
52663
52847
  mutationCommitted: didMutate,
52664
52848
  validationError,
52665
52849
  reconcile: async (parsed) => {
52666
- const rc = getRunConfig2(config);
52850
+ const rc = getRunConfig3(config);
52667
52851
  const tenantId2 = rc.tenantId || "default";
52668
52852
  const workItemStore = getTaskWorkItemStore();
52669
52853
  const task = await getTaskStore().getById(tenantId2, taskId);
@@ -52692,11 +52876,11 @@ function createTaskMiddleware(options = {}) {
52692
52876
  let didMutate = false;
52693
52877
  const validateExecutionResult = async () => {
52694
52878
  if (!input.executionResultId || validationAttempted) return;
52695
- const authority = classifyTaskAuthority(getRunConfig2(config));
52879
+ const authority = classifyTaskAuthority(getRunConfig3(config));
52696
52880
  if (authority.kind === "projectRoom" || authority.kind === "projectTask" || authority.kind === "invalid") return;
52697
52881
  validationAttempted = true;
52698
52882
  try {
52699
- const rc = getRunConfig2(config);
52883
+ const rc = getRunConfig3(config);
52700
52884
  const tenantId2 = rc.tenantId || "default";
52701
52885
  const workItemStore = getTaskWorkItemStore();
52702
52886
  const executionResult = await workItemStore.findByEventKey(
@@ -52746,7 +52930,7 @@ function createTaskMiddleware(options = {}) {
52746
52930
  );
52747
52931
  };
52748
52932
  const handleStartTask = async (input, config) => {
52749
- const rc = getRunConfig2(config);
52933
+ const rc = getRunConfig3(config);
52750
52934
  const authority = classifyTaskAuthority(rc);
52751
52935
  if (authority.kind === "invalid") return trustedContextError();
52752
52936
  if (authority.kind === "delegated") {
@@ -58557,6 +58741,9 @@ var DEFAULT_CONFIG = {
58557
58741
  type: "skill",
58558
58742
  name: "Skills",
58559
58743
  description: "Skill system for specialized instructions and workflows",
58744
+ // Temporary default until skills have a per-PA resource/collection model:
58745
+ // keep dynamic discovery by reading all. Do NOT set `skills: []` here —
58746
+ // load_skills treats an explicit empty list as "no static access".
58560
58747
  enabled: true,
58561
58748
  config: {
58562
58749
  readAll: true
@@ -58601,17 +58788,12 @@ var DEFAULT_CONFIG = {
58601
58788
  description: "Persistent task system for human-agent coordination",
58602
58789
  enabled: true,
58603
58790
  config: {}
58604
- },
58605
- {
58606
- id: "document-parser",
58607
- type: "document-parser",
58608
- name: "Document Parser",
58609
- description: "Parse docx/pdf files into markdown via document service",
58610
- enabled: true,
58611
- config: { connectAll: true }
58612
58791
  }
58613
58792
  ],
58614
- tools: ["list_agents", "list_tools", "get_agent", "create_agent", "invoke_agent", "manage_binding"]
58793
+ // The PA is a user-facing assistant, not a tenant agent builder. It may
58794
+ // discover available agents and dispatch work via `task`, but must not read,
58795
+ // create, or invoke agents directly.
58796
+ tools: ["list_agents", "manage_binding"]
58615
58797
  };
58616
58798
  var PersonalAssistantConfig = class {
58617
58799
  /**
@@ -59007,6 +59189,7 @@ export {
59007
59189
  InMemoryProjectRoomReadStateStore,
59008
59190
  InMemoryProjectRoomStore,
59009
59191
  InMemoryProjectStore,
59192
+ InMemorySessionStore,
59010
59193
  InMemorySharedResourceStore,
59011
59194
  InMemoryStore,
59012
59195
  InMemoryTaskStore,